diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..eb80a0b88 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index f73fe3e7c..55303946b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ tests/*.sam tests/*.fai tests/pysam_data tests/cbcf_data +tests/tabix_data samtools/config.h htslib/config.status @@ -26,20 +27,10 @@ htslib/autom4te.cache htslib/config.cache htslib/deps.mk +# linking tests +BuildRead.c # cython files -pysam/TabProxies.c -pysam/csamtools.c -pysam/ctabix.c -pysam/cvcf.c -pysam/chtslib.c -pysam/cutils.c -pysam/calignedsegment.c -pysam/calignmentfile.c -pysam/cbcf.c -pysam/cfaidx.c -pysam/chtslib.c -pysam/csamfile.c -pysam/ctabixproxies.c +pysam/libc*.c ###### Generic python ignores below ###### @@ -66,6 +57,7 @@ var/ *.egg-info/ .installed.cfg *.egg +doc/_build # Installer logs pip-log.txt diff --git a/.travis.yml b/.travis.yml index bfc5d1ce0..f874a90fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,8 @@ env: - CONDA_PY=3.4 - CONDA_PY=3.5 - CONDA_PY=3.6 + global: + - PYSAM_LINKING_TEST=1 addons: apt: diff --git a/INSTALL b/INSTALL index a1edd454f..963612515 100644 --- a/INSTALL +++ b/INSTALL @@ -1,57 +1,102 @@ -System Requirements -=================== +An online version of the installation instructions can be found here: +http://pysam.readthedocs.io/en/latest/installation.html -SAMtools depends on the zlib library . The latest -version 1.2.3 is preferred and with the latest version you can compile -razip and use it to compress a FASTA file. SAMtools' faidx is able to -index a razip-compressed FASTA file to save diskspace. Older zlib also -works with SAMtools, but razip cannot be compiled. +================ +Installing pysam +================ -The text-based viewer (tview) requires the GNU ncurses library -, which comes with Mac OS X and -most of the modern Linux/Unix distributions. If you do not have this -library installed, you can still compile the rest of SAMtools by -manually modifying one line in Makefile. +Pysam can be installed through conda_, pypi_ and from the repository. +The recommended way to install pysam is through conda/bioconda. -curl +Conda installation +================== -Pysam requires Python (2.7 or greater) and Cython (0.22 or greater). -It has not been tested on many other platforms. +To install pysam in your current conda_ environment, type:: -Windows support does not work yet. + conda config --add channels r + conda config --add channels bioconda + conda install pysam -Compilation -=========== +This will install pysam from the bioconda_ channel and automatically +makes sure that dependencies are installed. Also, compilation flags +will be set automatically, which will potentially save a lot of +trouble on OS X. -Unpack the distribution and enter the pysam directory. Type +Pypi installation +================= -python setup.py build +Pysam provides a python interface to the functionality contained +within the htslib_ C library. There are two ways that these two +can be combined, ``builtin`` and ``external``. -to compile. +Builtin +------- -Installation -============ +The typical installation will be through pypi_:: + + pip install pysam + +This will compile the ``builtin`` htslib source code within pysam. + +htslib_ can be configured at compilation to turn on additional +features such support using encrypted configurations, enable plugins, +and more. See the htslib_ project for more information on these. + +Pysam will attempt to configure htslib_ to turn on some advanced +features. If these fail, for example due to missing library +dependencies (`libcurl`, `libcrypto`), it will fall back to +conservative defaults. + +Options can be passed to the configure script explicitely by +setting the environment variable `HTSLIB_CONFIGURE_OPTIONS`. +For example:: -Type + export HTSLIB_CONFIGURE_OPTIONS=--enable-plugins + pip install pysam - python setup.py install +External +-------- -to install it within the site-packages directory of your python -distribution. Type +pysam can be combined with an externally installed htslib_ +library. This is a good way to avoid duplication of libraries. To link +against an externally installed library, set the environment variables +`HTSLIB_LIBRARY_DIR` and `HTSLIB_INCLUDE_DIR` before installing:: - python setup.py install --help + export HTSLIB_LIBRARY_DIR=/usr/local/lib + export HTSLIB_INCLUDE_DIR=/usr/local/include + pip install pysam -for more options. +Note that the location of the file :file:`libhts.so` needs to be known +to the linker once you run pysam, for example by setting the +environment-varirable `LD_LIBRARY_PATH`. -Build the documentation -======================= +Note that generally the pysam and htslib version need to be compatible. See +the release notes for more information. -Install a version of Sphinx that matches your Python version (2 or 3) and run +Installation from repository +============================ - python setup.py build_sphinx +pysam depends on cython_ to provide the connectivity to the htslib_ C +library. The installation of the source tarball (:file:`.tar.gz`) +contains pre-built C-files and cython needs not be present +during installation. However, when installing from the repository, +cython needs to be installed beforehand. + +To install from repository, type:: + + python setup.py install + +For compilation options, see the section on Pypi installation above. + +Requirements +============ -or +Depending on the installation method, requirements for building pysam differ. - python3 setup.py build_sphinx +When installing through conda_, dependencies will be resolved by the +package manager. The pip_ installation and installation from source +require a C compiler and its standard libraries as well as all +requirements for building htslib. Htslib requirements are listed in +the htslib/INSTALL file. -The documentation will be put into build/sphinx. +Installing from the repository will require cython_ to be installed. diff --git a/MANIFEST.in b/MANIFEST.in index be4369136..531159db0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,70 +5,56 @@ # include MANIFEST.in include COPYING +include NEWS include INSTALL include KNOWN_BUGS include THANKS include cy_build.py include requirements.txt -include pysam/c*.pxd -include pysam/c*.pyx -include pysam/c*.c +include pysam/libc*.pxd +include pysam/libc*.pyx +include pysam/libc*.c include pysam/*.c include pysam/*.h + +# exclude tests from pypi tar-ball - they +# require additional data +prune tests/ + +# samtools include samtools/configure include samtools/config.mk.in include samtools/config.h.in include samtools/*.h +include samtools/*.c exclude samtools/config.h include samtools/*/*.h + +# bcftools +include bcftools/*.h +include bcftools/*.c +exclude bcftools/config.h + +# htslib include htslib/*.c include htslib/*.h +include htslib/INSTALL +include htslib/NEWS exclude htslib/config.h include htslib/Makefile include htslib/htslib_vars.mk include htslib/configure include htslib/config.mk.in include htslib/config.h.in +include htslib/htslib.pc.in include htslib/htslib/*.h include htslib/cram/*.c include htslib/cram/*.h +include htslib/win/*.c +include htslib/win/*.h include cy_build.py include pysam.py include requirements.txt -# pysam tests -include tests/00README.txt -include tests/pysam_data -include tests/tabix_data -include tests/*.py -#ex1.fa -#include tests/ex1.sam.gz -#include tests/ex3.sam -#include tests/ex4.sam -#include tests/ex5.sam -#include tests/ex6.sam -#include tests/ex7.sam -#include tests/ex8.sam -#include tests/ex9_fail.bam -#include tests/ex9_nofail.bam -#include tests/ex10.sam -#include tests/example.py -#include tests/pysam_test.py -#include tests/segfault_tests.py -#include tests/example_*.sam -#include tests/example_btag.bam -#include tests/tag_bug.bam -#include tests/example.vcf40 -#include tests/example_empty_header.bam -#include tests/test_unaligned.bam -#include tests/issue100.bam - -# tabix tests -#include tests/example.gtf.gz -#include tests/example.gtf.gz.tbi -#include tests/example.bed.gz -#include tests/example.bed.gz.tbi -#include tests/vcf-examples/*.vcf - # documentation include doc/* diff --git a/NEWS b/NEWS new file mode 100644 index 000000000..0e2cb71c7 --- /dev/null +++ b/NEWS @@ -0,0 +1,664 @@ +An online version of the installation instructions can be found here: +http://pysam.readthedocs.io/en/latest/release.html + +============= +Release notes +============= + +Release 0.14.1 +============== + +This is mostly a bugfix release, though bcftools has now also been +upgraded to 1.7.0. + +* [#621] Add a warning to count_coverage when an alignment has an + empty QUAL field +* [#635] Speed-up of AlignedSegment.find_intro() +* treat border case of all bases in pileup column below quality score +* [#634] Fix access to pileup reference_sequence + +Release 0.14.0 +============== + +This release wraps htslib/samtools versions 1.7.0. + +* SAM/BAM/CRAM headers are now managed by a separate AlignmentHeader + class. +* AlignmentFile.header.as_dict() returns an ordered dictionary. +* Use "stop" instead of "end" to ensure consistency to + VariantFile. The end designations have been kept for backwards + compatibility. + +* [#611] and [#293] CRAM repeated fetch now works, each iterator + reloads index if multiple_iterators=True +* [#608] pysam now wraps htslib 1.7 and samtools 1.7. +* [#580] reference_name and next_reference_name can now be set to "*" + (will be converted to None to indicate an unmapped location) +* [#302] providing no coordinate to count_coverage will not count from + start/end of contig. +* [#325] @SQ records will be automatically added to header if they are + absent from text section of header. +* [#529] add get_forward_sequence() and get_forward_qualities() + methods +* [#577] add from_string() and to_dict()/from_dict() methods to + AlignedSegment. Rename tostring() to to_string() throughout for + consistency +* [#589] return None from build_alignment_sequence if no MD tag is set +* [#528] add PileupColumn.__len__ method + +Backwards incompatible changes: + +* AlignmentFile.header now returns an AlignmentHeader object. Use + AlignmentFile.header.to_dict() to get the dictionary as + previously. Most dictionary accessor methods (keys(), values(), + __getitem__, ...) have been implemented to ensure some level of + backwards compatibility when only reading. + + The rationale for this change is to have consistency between + AlignmentFile and VariantFile. + +* AlignmentFile and FastaFile now raise IOError instead of OSError + +Medium term we plan to have a 1.0 release. The pysam +interface has grown over the years and the API is cluttered with +deprecated names (Samfile, getrname(), gettid(), ...). To work towards +this, the next release (0.15.0) will yield DeprecationWarnings +for any parts of the API that are considered obsolete and will not be +in 1.0. Once 1.0 has been reached, we will use semantic versioning. + +Release 0.13.0 +=============== + +This release wraps htslib/samtools/bcftools versions 1.6.0 and +contains a series of bugfixes. + +* [#544] reading header from remote TabixFiles now works. +* [#531] add missing tag types H and A. A python float will now be + added as 'f' type instead of 'd' type. +* [#543] use FastaFile instead of Fastafile in pileup. +* [#546] set is_modified flag in setAttribute so updated attributes + are output. +* [#537] allow tabix index files to be created in a custom location. +* [#530] add get_index_statistics() method + +Release 0.12.0.1 +================ + +Bugfix release to solve compilation issue due to missinge +bcftools/config.h file. + +Release 0.12.0 +============== + +This release wraps htslib/samtools/bcftools versions 1.5.0 and +contains a series of bugfixes. + +* [#473] A new FastxRecord class that can be instantiated from class and + modified in-place. Replaces PersistentFastqProxy. +* [#521] In AligmentFile, Simplify file detection logic and allow remote index files + * Removed attempts to guess data and index file names; this is magic left + to htslib. + * Removed file existence check prior to opening files with htslib + * Better error checking after opening files that raise the appropriate + error (IOError for when errno is set, ValueError otherwise for backward + compatibility). + * Report IO errors when loading an index by name. + * Allow remote indices (tested using S3 signed URLs). + * Document filepath_index and make it an alias for index_filename. + * Added a require_index parameter to AlignmentFile +* [#526] handle unset ref when creating new records +* [#513] fix bcf_translate to skip deleted FORMAT fields to avoid + segfaults +* [#516] expose IO errors via IOError exceptions +* [#487] add tabix line_skip, remove 'pileup' preset +* add FastxRecord, replaces PersistentFastqProxy (still present for + backwards compatibility) +* [#496] upgrade to htslib/samtools/bcftools versions 1.5 +* add start/stop to AlignmentFile.fetch() to be consistent with + VariantFile.fetch(). "end" is kept for backwards compatibility. +* [#512] add get_index_statistics() method to AlignmentFile. + +Upcoming changes: + +In the next release we are plannig to separate the header information +from AlignmentFile into a separate class AlignmentHeader. This layout +is similar to VariantFile/VariantHeader. With this change we will +ensure that an AlignedSegment record will be linked to a header so +that chromosome names can be automatically translated from the numeric +representation. As a consequence, the way new AlignedSegment records +are created will need to change as the constructor requires a header:: + + header = pysam.AlignmentHeader( + reference_names=["chr1", "chr2"], + reference_lengths=[1000, 1000]) + + read = pysam.AlignedSegment(header) + +This will affect all code that instantiates AlignedSegment objects +directly. We have not yet merged to allow users to provide feed-back. +The pull-request is here: https://github.com/pysam-developers/pysam/pull/518 +Please comment on github. + +Release 0.11.2.2 +================ + +Bugfix release to address two issues: + +* Changes in 0.11.2.1 broke the GTF/GFF3 parser. Corrected and + more tests have been added. +* [#479] Correct VariantRecord edge cases described in issue + +Release 0.11.2.1 +================ + +Release to fix release tar-ball containing 0.11.1 pre-compiled +C-files. + +Release 0.11.2 +============== + +This release wraps htslib/samtools/bcfools versions 1.4.1 in response +to a security fix in these libraries. Additionaly the following +issues have been fixed: + +* [#452] add GFF3 support for tabix parsers +* [#461] Multiple fixes related to VariantRecordInfo and handling of INFO/END +* [#447] limit query name to 251 characters (only partially addresses issue) + +VariantFile and related object fixes + +* Restore VariantFile.\_\_dealloc\_\_ +* Correct handling of bcf_str_missing in bcf_array_to_object and + bcf_object_to_array +* Added update() and pop() methods to some dict-like proxy objects +* scalar INFO entries could not be set again after being deleted +* VariantRecordInfo.__delitem__ now allows unset flags to be deleted without + raising a KeyError +* Multiple other fixes for VariantRecordInfo methods +* INFO/END is now accessible only via VariantRecord.stop and + VariantRecord.rlen. Even if present behind the scenes, it is no longer + accessible via VariantRecordInfo. +* Add argument to issue a warning instead of an exception if input appears + to be truncated + +Other features and fixes: + +* Make AlignmentFile \_\_dealloc\_\_ and close more + stringent +* Add argument AlignmentFile to issue a warning instead of an + exception if input appears to be truncated + +Release 0.11.1 +============== + +Bugfix release + +* [#440] add deprecated 'always' option to infer_query_length for backwards compatibility. + +Release 0.11.0 +============== + +This release wraps the latest versions of htslib/samtools/bcftools and +implements a few bugfixes. + +* [#413] Wrap HTSlib/Samtools/BCFtools 1.4 +* [#422] Fix missing pysam.sort.usage() message +* [#411] Fix BGZfile initialization bug +* [#412] Add seek support for BGZFile +* [#395] Make BGZfile iterable +* [#433] Correct getQueryEnd +* [#419] Export SAM enums such as pysam.CMATCH +* [#415] Fix access by tid in AlignmentFile.fetch() +* [#405] Writing SAM now outputs a header by default. +* [#332] split infer_query_length(always) into infer_query_length and infer_read_length + +Release 0.10.0 +============== + +This release implements further functionality in the VariantFile API +and includes several bugfixes: + +* treat special case -c option in samtools view outputs to stdout even + if -o given, fixes #315 +* permit reading BAM files with CSI index, closes #370 +* raise Error if query name exceeds maximum length, fixes #373 +* new method to compute hash value for AlignedSegment +* AlignmentFile, VariantFile and TabixFile all inherit from HTSFile +* Avoid segfault by detecting out of range reference_id and + next_reference in AlignedSegment.tostring +* Issue #355: Implement streams using file descriptors for VariantFile +* upgrade to htslib 1.3.2 +* fix compilation with musl libc +* Issue #316, #360: Rename all Cython modules to have lib as a prefix +* Issue #332, hardclipped bases in cigar included by + pysam.AlignedSegment.infer_query_length() +* Added support for Python 3.6 filename encoding protocol +* Issue #371, fix incorrect parsing of scalar INFO and FORMAT fields in VariantRecord +* Issue #331, fix failure in VariantFile.reset() method +* Issue #314, add VariantHeader.new_record(), VariantFile.new_record() and + VariantRecord.copy() methods to create new VariantRecord objects +* Added VariantRecordFilter.add() method to allow setting new VariantRecord filters +* Preliminary (potentially unsafe) support for removing and altering header metadata +* Many minor fixes and improvements to VariantFile and related objects + +Please note that all internal cython extensions now have a lib prefix +to facilitate linking against pysam extension modules. Any user cython +extensions using cimport to import pysam definitions will need +changes, for example:: + + cimport pysam.csamtools + +will become:: + + cimport pysam.libcamtools + +Release 0.9.1 +============= + +This is a bugfix release addressing some installation problems +in pysam 0.9.0, in particular: + +* patch included htslib to work with older libcurl versions, fixes #262. +* do not require cython for python 3 install, fixes #260 +* FastaFile does not accept filepath_index any more, see #270 +* add AlignedSegment.get_cigar_stats method. +* py3 bugfix in VariantFile.subset_samples, fixes #272 +* add missing sysconfig import, fixes #278 +* do not redirect stdout, but instead write to a separately + created file. This should resolve issues when pysam is used + in notebooks or other environments that redirect stdout. +* wrap htslib-1.3.1, samtools-1.3.1 and bcftools-1.3.1 +* use bgzf throughout instead of gzip +* allow specifying a fasta reference for CRAM file when opening + for both read and write, fixes #280 + +Release 0.9.0 +============= + +Overview +-------- + +The 0.9.0 release upgrades htslib to htslib 1.3 and numerous other +enchancements and bugfixes. See below for a detailed list. + +`Htslib 1.3 `_ +comes with additional capabilities for remote file access which depend +on the presence of optional system libraries. As a consequence, the +installation script :file:`setup.py` has become more complex. For an +overview, see :ref:`installation`. We have tested installation on +linux and OS X, but could not capture all variations. It is possible +that a 0.9.1 release might follow soon addressing installation issues. + +The :py:class:`~.pysam.VariantFile` class provides access to +:term:`vcf` and :term:`bcf` formatted files. The class is certainly +usable and interface is reaching completion, but the API and the +functionality is subject to change. + +Detailed release notes +---------------------- + +* upgrade to htslib 1.3 +* python 3 compatibility tested throughout. +* added a first set of bcftools commands in the pysam.bcftools + submodule. +* samtools commands are now in the pysam.samtools module. For + backwards compatibility they are still imported into the pysam + namespace. +* samtools/bcftools return stdout as a single (byte) string. As output + can be binary (VCF.gz, BAM) this is necessary to ensure py2/py3 + compatibility. To replicate the previous behaviour in py2.7, use:: + + pysam.samtools.view(self.filename).splitlines(True) + +* get_tags() returns the tag type as a character, not an integer (#214) +* TabixFile now raises ValueError on indices created by tabix <1.0 (#206) +* improve OSX installation and develop mode +* FastxIterator now handles empty sequences (#204) +* TabixFile.isremote is not TabixFile.is_remote in line with AlignmentFile +* AlignmentFile.count() has extra optional argument read_callback +* setup.py has been changed to: + * install a single builtin htslib library. Previously, each pysam + module contained its own version. This reduces compilation time + and code bloat. + * run configure for the builtin htslib library in order to detect + optional libraries such as libcurl. Configure behaviour can be + controlled by setting the environmet variable + HTSLIB_CONFIGURE_OPTIONS. +* get_reference_sequence() now returns the reference sequence and not + something looking like it. This bug had effects on + get_aligned_pairs(with_seq=True), see #225. If you have relied on on + get_aligned_pairs(with_seq=True) in pysam-0.8.4, please check your + results. +* improved autodetection of file formats in AlignmentFile and VariantFile. + +Release 0.8.4 +============= + +This release contains numerous bugfixes and a first implementation of +a pythonic interface to VCF/BCF files. Note that this code is still +incomplete and preliminary, but does offer a nearly complete immutable +Pythonic interface to VCF/BCF metadata and data with reading and +writing capability. + +Potential isses when upgrading from v0.8.3: + +* binary tags are now returned as python arrays + +* renamed several methods for pep8 compatibility, old names still retained for + backwards compatibility, but should be considered deprecated. + * gettid() is now get_tid() + * getrname() is now get_reference_name() + * parseRegion() is now parse_region() + +* some methods have changed for pep8 compatibility without the old + names being present: + * fromQualityString() is now qualitystring_to_array() + * toQualityString() is now qualities_to_qualitystring() + +* faidx now returns strings and not binary strings in py3. + +* The cython components have been broken up into smaller files with + more specific content. This will affect users using the cython + interfaces. + +Edited list of commit log changes: + +* fixes AlignmentFile.check_index to return True +* add RG/PM header tag - closes #179 +* add with_seq option to get_aligned_pairs +* use char * inside reconsituteReferenceSequence +* add soft clipping for get_reference_sequence +* add get_reference_sequence +* queryEnd now computes length from cigar string if no sequence present, closes #176 +* tolerate missing space at end of gtf files, closes #162 +* do not raise Error when receiving output on stderr +* add docu about fetching without index, closes #170 +* FastaFile and FastxFile now return strings in python3, closes #173 +* py3 compat: relative -> absolute imports. +* add reference_name and next_reference_name attributes to AlignedSegment +* add function signatures to cvcf cython. Added note about other VCF code. +* add context manager functions to FastaFile +* add reference_name and next_reference_name attributes to AlignedSegment +* PileupColumn also gets a reference_name attribute. +* add context manager functions to FastaFile +* TabixFile.header for remote files raises AttributeError, fixes #157 +* add context manager interface to TabixFile, closes #165 +* change ctypedef enum to typedef enum for cython 0.23 +* add function signatures to cvcf cython, also added note about other VCF code +* remove exception for custom upper-case header record tags. +* rename VALID_HEADER_FIELDS to KNOWN_HEADER_FIELDS +* fix header record tag parsing for custom tags. +* use cython.str in count_coverage, fixes #141 +* avoid maketrans (issues with python3) +* refactoring: AlignedSegment now in separate module +* do not execute remote tests if URL not available +* fix the unmapped count, incl reads with no SQ group +* add raw output to tags +* added write access for binary tags +* bugfix in call to resize +* implemented writing of binary tags from arrays +* implemented convert_binary_tag to use arrays +* add special cases for reads that are unmapped or whose mates are unmapped. +* rename TabProxies to ctabixproxies +* remove underscores from utility functions +* move utility methods into cutils +* remove callback argument to fetch - closes #128 +* avoid calling close in dealloc +* add unit tests for File object opening +* change AlignmentFile.open to filepath_or_object +* implement copy.copy, close #65 +* add chaching of array attributes in AlignedSegment, closes #121 +* add export of Fastafile +* remove superfluous pysam_dispatch +* use persist option in FastqFile +* get_tag: expose tag type if requested with `with_value_type` +* fix to allow reading vcf record info via tabix-based vcf reader +* add pFastqProxy and pFastqFile objects to make it possible to work with multiple fastq records per file handle, unlike FastqProxy/FastqFile. +* release GIL around htslib IO operations +* More work on read/write support, API improvements +* add `phased` property on `VariantRecordSample` +* add mutable properties to VariantRecord +* BCF fixes and start of read/write support +* VariantHeaderRecord objects now act like mappings for attributes. +* add VariantHeader.alts dict from alt ID->Record. +* Bug fix to strong representation of structured header records. +* VariantHeader is now mutable + + +Release 0.8.3 +============= + +* samtools command now accept the "catch_stdout" option. + +* get_aligned_pairs now works for soft-clipped reads. + +* query_position is now None when a PileupRead is not aligned + to a particular position. + +* AlignedSegments are now comparable and hashable. + +Release 0.8.2.1 +=============== + +* Installation bugfix release. + +Release 0.8.2 +============= + +* Pysam now wraps htslib 1.2.1 and samtools version 1.2. + +* Added CRAM file support to pysam. + +* New alignment info interface. + * opt() and setTag are deprecated, use get_tag() and set_tag() + instead. + * added has_tag() + * tags is deprecated, use get_tags() and set_tags() instead. + +* FastqFile is now FastxFile to reflect that the latter permits + iteration over both fastq- and fasta-formatted files. + +* A Cython wrapper for htslib VCF/BCF reader/writer. The wrapper + provides a nearly complete Pythonic interface to VCF/BCF metadata + with reading and writing capability. However, the interface is still + incomplete and preliminary and lacks capability to mutate the + resulting data. + +Release 0.8.1 +============= + +* Pysam now wraps htslib and samtools versions 1.1. + +* Bugfixes, most notable: + * issue #43: uncompressed BAM output + * issue #42: skip tests requiring network if none available + * issue #19: multiple iterators can now be made to work on the same tabix file + * issue #24: All strings returned from/passed to the pysam API are now unicode in python 3 + * issue #5: type guessing for lists of integers fixed + +* API changes for consistency. The old API is still present, + but deprecated. + In particular: + + * Tabixfile -> TabixFile + * Fastafile -> FastaFile + * Fastqfile -> FastqFile + * Samfile -> AlignmentFile + * AlignedRead -> AlignedSegment + * qname -> query_name + * tid -> reference_id + * pos -> reference_start + * mapq -> mapping_quality + * rnext -> next_reference_id + * pnext -> next_reference_start + * cigar -> cigartuples + * cigarstring -> cigarstring + * tlen -> template_length + * seq -> query_sequence + * qual -> query_qualities, now returns array + * qqual -> query_alignment_qualities, now returns array + * tags -> tags + * alen -> reference_length, reference is always "alignment", so removed + * aend -> reference_end + * rlen -> query_length + * query -> query_alignment_sequence + * qstart -> query_alignment_start + * qend -> query_alignment_end + * qlen -> query_alignment_length + * mrnm -> next_reference_id + * mpos -> next_reference_start + * rname -> reference_id + * isize -> template_length + * blocks -> get_blocks() + * aligned_pairs -> get_aligned_pairs() + * inferred_length -> infer_query_length() + * positions -> get_reference_positions() + * overlap() -> get_overlap() + + * All strings are now passed to or received from the pysam API + as strings, no more bytes. + +Other changes: + * AlignmentFile.fetch(reopen) option is now multiple_iterators. The + default changed to not reopen a file unless requested by the user. + * FastaFile.getReferenceLength is now FastaFile.get_reference_length + +Backwards incompatible changes + +* Empty cigarstring now returns None (intstead of '') +* Empty cigar now returns None (instead of []) +* When using the extension classes in cython modules, AlignedRead + needs to be substituted with AlignedSegment. +* fancy_str() has been removed +* qual, qqual now return arrays + +Release 0.8.0 +============= + +* Disabled features + * IteratorColumn.setMask() disabled as htslib does not implement + this functionality? + +* Not implemented yet: + * reading SAM files without header + +Tabix files between version 0.7.8 and 0.8.0 are +not compatible and need to be re-indexed. + +While version 0.7.8 and 0.8.0 should be mostly +compatible, there are some notable exceptions: + +* tabix iterators will fail if there are comments + in the middle or the end of a file. + +* tabix raises always ValueError for invalid intervals. + Previously, different types of errors were raised + (KeyError, IndexError, ValueError) depending on + the type of invalid intervals (missing chromosome, + out-of-range, malformatted interval). + + +Release 0.7.8 +============= + +* added AlignedRead.setTag method +* added AlignedRead.blocks +* unsetting CIGAR strings is now possible +* empty CIGAR string returns empty list +* added reopen flag to Samfile.fetch() +* various bugfixes + +Release 0.7.7 +============= + +* added Fastafile.references, .nreferences and .lengths +* tabix_iterator now uses kseq.h for python 2.7 + +Release 0.7.6 +============= + +* added inferred_length property +* issue 122: MACOSX getline missing, now it works? +* seq and qual can be set None +* added Fastqfile + +Release 0.7.5 +============= + +* switch to samtools 0.1.19 +* issue 122: MACOSX getline missing +* issue 130: clean up tempfiles +* various other bugfixes + +Release 0.7.4 +============= + +* further bugfixes to setup.py and package layout + +Release 0.7.3 +============= + +* further bugfixes to setup.py +* upgraded distribute_setup.py to 0.6.34 + +Release 0.7.2 +============= + +* bugfix in installer - failed when cython not present +* changed installation locations of shared libraries + +Release 0.7.1 +============= + +* bugfix: missing PP tag PG records in header +* added pre-built .c files to distribution + +Release 0.7 +=========== + +* switch to tabix 0.2.6 +* added cigarstring field +* python3 compatibility +* added B tag handling +* added check_sq and check_header options to Samfile.__init__ +* added lazy GTF parsing to tabix +* reworked support for VCF format parsing +* bugfixes + +Release 0.6 +=========== + +* switch to samtools 0.1.18 +* various bugfixes +* removed references to deprecated 'samtools pileup' functionality +* AlignedRead.tags now returns an empty list if there are no tags. +* added pnext, rnext and tlen + +Release 0.5 +=========== + +* switch to samtools 0.1.16 and tabix 0.2.5 +* improved tabix parsing, added vcf support +* re-organized code to permit linking against pysam +* various bugfixes +* added Samfile.positions and Samfile.overlap + +Release 0.4 +=========== + +* switch to samtools 0.1.12a and tabix 0.2.3 +* added snp and indel calling. +* switch from pyrex to cython +* changed handling of samtools stderr +* various bugfixes +* added Samfile.count and Samfile.mate +* deprecated AlignedRead.rname, added AlignedRead.tid + +Release 0.3 +=========== + +* switch to samtools 0.1.8 +* added support for tabix files +* numerous bugfixes including +* permit simultaneous iterators on the same file +* working access to remote files diff --git a/README.rst b/README.rst index 1ebe7900c..7ceb4550d 100644 --- a/README.rst +++ b/README.rst @@ -43,14 +43,21 @@ The latest version is available through `pypi pip install pysam If you are using the conda packaging manager (e.g. miniconda or anaconda), -you can install pysam from the `bioconda channel `_: +you can install pysam from the `bioconda channel `_:: conda config --add channels r - conda config --add channels bioconda - conda install pysam +Installation through bioconda is the recommended way to install pysam +as it resolves non-python dependencies and uses pre-configured +compilation options. Especially for OS X this will potentially save a +lot of trouble. + +Pysam is available through `pypi +`_. To install, type:: + + pip install pysam Pysam documentation is available through https://readthedocs.org/ from `here `_ diff --git a/bcftools/HMM.c b/bcftools/HMM.c index 91965449f..70ad8d626 100644 --- a/bcftools/HMM.c +++ b/bcftools/HMM.c @@ -31,6 +31,16 @@ #include #include "HMM.h" +typedef struct +{ + int nstates; // number of hmm's states + uint32_t snap_at_pos; // snapshot at this position, 0 when inactive + double *vit_prob; // viterbi probabilities, NULL for uniform probs + double *fwd_prob; // transition probabilities + double *bwd_prob; // transition probabilities +} +snapshot_t; + struct _hmm_t { int nstates; // number of states @@ -50,7 +60,9 @@ struct _hmm_t set_tprob_f set_tprob; // Optional user function to set / modify transition probabilities // at each site (one step of Viterbi algorithm) void *set_tprob_data; - double *init_probs; // Initial state probabilities, NULL for uniform probs + snapshot_t init, state; // Initial and current state probs. Set state from snapshot if prev_snap_pos!=0 or from init otherwise + snapshot_t *snapshot; // snapshot->snap_at_pos .. request a snapshot at this position + // hmm->state.snap_at_pos .. the current state comes from snapshot made at this position }; uint8_t *hmm_get_viterbi_path(hmm_t *hmm) { return hmm->vpath; } @@ -78,28 +90,100 @@ static inline void multiply_matrix(int n, double *a, double *b, double *dst, dou memcpy(dst,out,sizeof(double)*n*n); } +void hmm_init_states(hmm_t *hmm, double *probs) +{ + hmm->init.snap_at_pos = hmm->state.snap_at_pos = 0; + + if ( !hmm->init.vit_prob ) + hmm->init.vit_prob = (double*) malloc(sizeof(double)*hmm->nstates); + if ( !hmm->init.fwd_prob ) + hmm->init.fwd_prob = (double*) malloc(sizeof(double)*hmm->nstates); + if ( !hmm->init.bwd_prob ) + hmm->init.bwd_prob = (double*) malloc(sizeof(double)*hmm->nstates); + + if ( !hmm->state.vit_prob ) + hmm->state.vit_prob = (double*) malloc(sizeof(double)*hmm->nstates); + if ( !hmm->state.fwd_prob ) + hmm->state.fwd_prob = (double*) malloc(sizeof(double)*hmm->nstates); + if ( !hmm->state.bwd_prob ) + hmm->state.bwd_prob = (double*) malloc(sizeof(double)*hmm->nstates); + + int i; + if ( probs ) + { + memcpy(hmm->init.vit_prob,probs,sizeof(double)*hmm->nstates); + double sum = 0; + for (i=0; instates; i++) sum += hmm->init.vit_prob[i]; + for (i=0; instates; i++) hmm->init.vit_prob[i] /= sum; + } + else + for (i=0; instates; i++) hmm->init.vit_prob[i] = 1./hmm->nstates; + + memcpy(hmm->init.fwd_prob,hmm->init.vit_prob,sizeof(double)*hmm->nstates); // these remain unchanged + memcpy(hmm->init.bwd_prob,hmm->init.vit_prob,sizeof(double)*hmm->nstates); + memcpy(hmm->state.vit_prob,hmm->init.vit_prob,sizeof(double)*hmm->nstates); // can be changed by snapshotting + memcpy(hmm->state.fwd_prob,hmm->init.fwd_prob,sizeof(double)*hmm->nstates); + memcpy(hmm->state.bwd_prob,hmm->init.bwd_prob,sizeof(double)*hmm->nstates); +} hmm_t *hmm_init(int nstates, double *tprob, int ntprob) { hmm_t *hmm = (hmm_t*) calloc(1,sizeof(hmm_t)); hmm->nstates = nstates; hmm->curr_tprob = (double*) malloc(sizeof(double)*nstates*nstates); hmm->tmp = (double*) malloc(sizeof(double)*nstates*nstates); - hmm_set_tprob(hmm, tprob, ntprob); - + hmm_init_states(hmm, NULL); return hmm; } -void hmm_init_states(hmm_t *hmm, double *probs) +void *hmm_snapshot(hmm_t *hmm, void *_snapshot, uint32_t pos) { - if ( !probs ) + snapshot_t *snapshot = (snapshot_t*) _snapshot; + if ( snapshot && snapshot->nstates!=hmm->nstates ) { - free(hmm->init_probs); - hmm->init_probs = NULL; + free(snapshot); + snapshot = NULL; + } + if ( !snapshot ) + { + // Allocate the snapshot as a single memory block so that it can be + // free()-ed by the user. So make sure the arrays are aligned.. + size_t str_size = sizeof(snapshot_t); + size_t dbl_size = sizeof(double); + size_t pad_size = (dbl_size - str_size % dbl_size) % dbl_size; + uint8_t *mem = (uint8_t*) malloc(str_size + pad_size + dbl_size*2*hmm->nstates); + snapshot = (snapshot_t*) mem; + snapshot->nstates = hmm->nstates; + snapshot->vit_prob = (double*) (mem + str_size + pad_size); + snapshot->fwd_prob = snapshot->vit_prob + hmm->nstates; + } + snapshot->snap_at_pos = pos; + hmm->snapshot = snapshot; + return snapshot; +} +void hmm_restore(hmm_t *hmm, void *_snapshot) +{ + snapshot_t *snapshot = (snapshot_t*) _snapshot; + if ( !snapshot || !snapshot->snap_at_pos ) + { + hmm->state.snap_at_pos = 0; + memcpy(hmm->state.vit_prob,hmm->init.vit_prob,sizeof(double)*hmm->nstates); + memcpy(hmm->state.fwd_prob,hmm->init.fwd_prob,sizeof(double)*hmm->nstates); + } + else + { + hmm->state.snap_at_pos = snapshot->snap_at_pos; + memcpy(hmm->state.vit_prob,snapshot->vit_prob,sizeof(double)*hmm->nstates); + memcpy(hmm->state.fwd_prob,snapshot->fwd_prob,sizeof(double)*hmm->nstates); } - - if ( !hmm->init_probs ) hmm->init_probs = (double*) malloc(sizeof(double)*hmm->nstates); - memcpy(hmm->init_probs,probs,sizeof(double)*hmm->nstates); +} +void hmm_reset(hmm_t *hmm, void *_snapshot) +{ + snapshot_t *snapshot = (snapshot_t*) _snapshot; + if ( snapshot ) snapshot->snap_at_pos = 0; + hmm->state.snap_at_pos = 0; + memcpy(hmm->state.vit_prob,hmm->init.vit_prob,sizeof(double)*hmm->nstates); + memcpy(hmm->state.fwd_prob,hmm->init.fwd_prob,sizeof(double)*hmm->nstates); } void hmm_set_tprob(hmm_t *hmm, double *tprob, int ntprob) @@ -154,23 +238,18 @@ void hmm_run_viterbi(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) hmm->vprob_tmp = (double*) malloc(sizeof(double)*hmm->nstates); } - // Init all states with equal likelihood int i,j, nstates = hmm->nstates; - if ( hmm->init_probs ) - for (i=0; ivprob[i] = hmm->init_probs[i]; - else - for (i=0; ivprob[i] = 1./nstates; + memcpy(hmm->vprob, hmm->state.vit_prob, sizeof(*hmm->state.vit_prob)*nstates); + uint32_t prev_pos = hmm->state.snap_at_pos ? hmm->state.snap_at_pos : sites[0]; // Run Viterbi - uint32_t prev_pos = sites[0]; for (i=0; ivpath[i*nstates]; double *eprob = &eprobs[i*nstates]; int pos_diff = sites[i] == prev_pos ? 0 : sites[i] - prev_pos - 1; - _set_tprob(hmm, pos_diff); if ( hmm->set_tprob ) hmm->set_tprob(hmm, prev_pos, sites[i], hmm->set_tprob_data, hmm->curr_tprob); prev_pos = sites[i]; @@ -191,6 +270,9 @@ void hmm_run_viterbi(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) } for (j=0; jvprob_tmp[j] /= vnorm; double *tmp = hmm->vprob; hmm->vprob = hmm->vprob_tmp; hmm->vprob_tmp = tmp; + + if ( hmm->snapshot && sites[i]==hmm->snapshot->snap_at_pos ) + memcpy(hmm->snapshot->vit_prob, hmm->vprob, sizeof(*hmm->vprob)*nstates); } // Find the most likely state @@ -222,21 +304,12 @@ void hmm_run_fwd_bwd(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) } - // Init all states with equal likelihood int i,j,k, nstates = hmm->nstates; - if ( hmm->init_probs ) - { - for (i=0; ifwd[i] = hmm->init_probs[i]; - for (i=0; ibwd[i] = hmm->init_probs[i]; - } - else - { - for (i=0; ifwd[i] = 1./hmm->nstates; - for (i=0; ibwd[i] = 1./hmm->nstates; - } + memcpy(hmm->fwd, hmm->state.fwd_prob, sizeof(*hmm->state.fwd_prob)*nstates); + memcpy(hmm->bwd, hmm->state.bwd_prob, sizeof(*hmm->state.bwd_prob)*nstates); + uint32_t prev_pos = hmm->state.snap_at_pos ? hmm->state.snap_at_pos : sites[0]; // Run fwd - uint32_t prev_pos = sites[0]; for (i=0; ifwd[i*nstates]; @@ -259,6 +332,9 @@ void hmm_run_fwd_bwd(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) norm += fwd[j]; } for (j=0; jsnapshot && sites[i]==hmm->snapshot->snap_at_pos ) + memcpy(hmm->snapshot->fwd_prob, fwd, sizeof(*fwd)*nstates); } // Run bwd @@ -296,7 +372,7 @@ void hmm_run_fwd_bwd(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) } } -void hmm_run_baum_welch(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) +double *hmm_run_baum_welch(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) { // Init arrays when run for the first time if ( hmm->nfwd < n ) @@ -312,16 +388,9 @@ void hmm_run_baum_welch(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) // Init all states with equal likelihood int i,j,k, nstates = hmm->nstates; - if ( hmm->init_probs ) - { - for (i=0; ifwd[i] = hmm->init_probs[i]; - for (i=0; ibwd[i] = hmm->init_probs[i]; - } - else - { - for (i=0; ifwd[i] = 1./hmm->nstates; - for (i=0; ibwd[i] = 1./hmm->nstates; - } + memcpy(hmm->fwd, hmm->state.fwd_prob, sizeof(*hmm->state.fwd_prob)*nstates); + memcpy(hmm->bwd, hmm->state.bwd_prob, sizeof(*hmm->state.bwd_prob)*nstates); + uint32_t prev_pos = hmm->state.snap_at_pos ? hmm->state.snap_at_pos : sites[0]; // New transition matrix: temporary values double *tmp_xi = (double*) calloc(nstates*nstates,sizeof(double)); @@ -329,7 +398,6 @@ void hmm_run_baum_welch(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) double *fwd_bwd = (double*) malloc(sizeof(double)*nstates); // Run fwd - uint32_t prev_pos = sites[0]; for (i=0; ifwd[i*nstates]; @@ -416,11 +484,17 @@ void hmm_run_baum_welch(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) free(tmp_gamma); free(tmp_xi); free(fwd_bwd); + return hmm->curr_tprob; } void hmm_destroy(hmm_t *hmm) { - free(hmm->init_probs); + free(hmm->init.vit_prob); + free(hmm->init.fwd_prob); + free(hmm->init.bwd_prob); + free(hmm->state.vit_prob); + free(hmm->state.fwd_prob); + free(hmm->state.bwd_prob); free(hmm->vprob); free(hmm->vprob_tmp); free(hmm->vpath); diff --git a/bcftools/HMM.c.pysam.c b/bcftools/HMM.c.pysam.c index a3b91ff76..2280c0db7 100644 --- a/bcftools/HMM.c.pysam.c +++ b/bcftools/HMM.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* The MIT License @@ -33,6 +33,16 @@ #include #include "HMM.h" +typedef struct +{ + int nstates; // number of hmm's states + uint32_t snap_at_pos; // snapshot at this position, 0 when inactive + double *vit_prob; // viterbi probabilities, NULL for uniform probs + double *fwd_prob; // transition probabilities + double *bwd_prob; // transition probabilities +} +snapshot_t; + struct _hmm_t { int nstates; // number of states @@ -52,7 +62,9 @@ struct _hmm_t set_tprob_f set_tprob; // Optional user function to set / modify transition probabilities // at each site (one step of Viterbi algorithm) void *set_tprob_data; - double *init_probs; // Initial state probabilities, NULL for uniform probs + snapshot_t init, state; // Initial and current state probs. Set state from snapshot if prev_snap_pos!=0 or from init otherwise + snapshot_t *snapshot; // snapshot->snap_at_pos .. request a snapshot at this position + // hmm->state.snap_at_pos .. the current state comes from snapshot made at this position }; uint8_t *hmm_get_viterbi_path(hmm_t *hmm) { return hmm->vpath; } @@ -80,28 +92,100 @@ static inline void multiply_matrix(int n, double *a, double *b, double *dst, dou memcpy(dst,out,sizeof(double)*n*n); } +void hmm_init_states(hmm_t *hmm, double *probs) +{ + hmm->init.snap_at_pos = hmm->state.snap_at_pos = 0; + + if ( !hmm->init.vit_prob ) + hmm->init.vit_prob = (double*) malloc(sizeof(double)*hmm->nstates); + if ( !hmm->init.fwd_prob ) + hmm->init.fwd_prob = (double*) malloc(sizeof(double)*hmm->nstates); + if ( !hmm->init.bwd_prob ) + hmm->init.bwd_prob = (double*) malloc(sizeof(double)*hmm->nstates); + + if ( !hmm->state.vit_prob ) + hmm->state.vit_prob = (double*) malloc(sizeof(double)*hmm->nstates); + if ( !hmm->state.fwd_prob ) + hmm->state.fwd_prob = (double*) malloc(sizeof(double)*hmm->nstates); + if ( !hmm->state.bwd_prob ) + hmm->state.bwd_prob = (double*) malloc(sizeof(double)*hmm->nstates); + + int i; + if ( probs ) + { + memcpy(hmm->init.vit_prob,probs,sizeof(double)*hmm->nstates); + double sum = 0; + for (i=0; instates; i++) sum += hmm->init.vit_prob[i]; + for (i=0; instates; i++) hmm->init.vit_prob[i] /= sum; + } + else + for (i=0; instates; i++) hmm->init.vit_prob[i] = 1./hmm->nstates; + + memcpy(hmm->init.fwd_prob,hmm->init.vit_prob,sizeof(double)*hmm->nstates); // these remain unchanged + memcpy(hmm->init.bwd_prob,hmm->init.vit_prob,sizeof(double)*hmm->nstates); + memcpy(hmm->state.vit_prob,hmm->init.vit_prob,sizeof(double)*hmm->nstates); // can be changed by snapshotting + memcpy(hmm->state.fwd_prob,hmm->init.fwd_prob,sizeof(double)*hmm->nstates); + memcpy(hmm->state.bwd_prob,hmm->init.bwd_prob,sizeof(double)*hmm->nstates); +} hmm_t *hmm_init(int nstates, double *tprob, int ntprob) { hmm_t *hmm = (hmm_t*) calloc(1,sizeof(hmm_t)); hmm->nstates = nstates; hmm->curr_tprob = (double*) malloc(sizeof(double)*nstates*nstates); hmm->tmp = (double*) malloc(sizeof(double)*nstates*nstates); - hmm_set_tprob(hmm, tprob, ntprob); - + hmm_init_states(hmm, NULL); return hmm; } -void hmm_init_states(hmm_t *hmm, double *probs) +void *hmm_snapshot(hmm_t *hmm, void *_snapshot, uint32_t pos) { - if ( !probs ) + snapshot_t *snapshot = (snapshot_t*) _snapshot; + if ( snapshot && snapshot->nstates!=hmm->nstates ) { - free(hmm->init_probs); - hmm->init_probs = NULL; + free(snapshot); + snapshot = NULL; + } + if ( !snapshot ) + { + // Allocate the snapshot as a single memory block so that it can be + // free()-ed by the user. So make sure the arrays are aligned.. + size_t str_size = sizeof(snapshot_t); + size_t dbl_size = sizeof(double); + size_t pad_size = (dbl_size - str_size % dbl_size) % dbl_size; + uint8_t *mem = (uint8_t*) malloc(str_size + pad_size + dbl_size*2*hmm->nstates); + snapshot = (snapshot_t*) mem; + snapshot->nstates = hmm->nstates; + snapshot->vit_prob = (double*) (mem + str_size + pad_size); + snapshot->fwd_prob = snapshot->vit_prob + hmm->nstates; + } + snapshot->snap_at_pos = pos; + hmm->snapshot = snapshot; + return snapshot; +} +void hmm_restore(hmm_t *hmm, void *_snapshot) +{ + snapshot_t *snapshot = (snapshot_t*) _snapshot; + if ( !snapshot || !snapshot->snap_at_pos ) + { + hmm->state.snap_at_pos = 0; + memcpy(hmm->state.vit_prob,hmm->init.vit_prob,sizeof(double)*hmm->nstates); + memcpy(hmm->state.fwd_prob,hmm->init.fwd_prob,sizeof(double)*hmm->nstates); + } + else + { + hmm->state.snap_at_pos = snapshot->snap_at_pos; + memcpy(hmm->state.vit_prob,snapshot->vit_prob,sizeof(double)*hmm->nstates); + memcpy(hmm->state.fwd_prob,snapshot->fwd_prob,sizeof(double)*hmm->nstates); } - - if ( !hmm->init_probs ) hmm->init_probs = (double*) malloc(sizeof(double)*hmm->nstates); - memcpy(hmm->init_probs,probs,sizeof(double)*hmm->nstates); +} +void hmm_reset(hmm_t *hmm, void *_snapshot) +{ + snapshot_t *snapshot = (snapshot_t*) _snapshot; + if ( snapshot ) snapshot->snap_at_pos = 0; + hmm->state.snap_at_pos = 0; + memcpy(hmm->state.vit_prob,hmm->init.vit_prob,sizeof(double)*hmm->nstates); + memcpy(hmm->state.fwd_prob,hmm->init.fwd_prob,sizeof(double)*hmm->nstates); } void hmm_set_tprob(hmm_t *hmm, double *tprob, int ntprob) @@ -156,23 +240,18 @@ void hmm_run_viterbi(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) hmm->vprob_tmp = (double*) malloc(sizeof(double)*hmm->nstates); } - // Init all states with equal likelihood int i,j, nstates = hmm->nstates; - if ( hmm->init_probs ) - for (i=0; ivprob[i] = hmm->init_probs[i]; - else - for (i=0; ivprob[i] = 1./nstates; + memcpy(hmm->vprob, hmm->state.vit_prob, sizeof(*hmm->state.vit_prob)*nstates); + uint32_t prev_pos = hmm->state.snap_at_pos ? hmm->state.snap_at_pos : sites[0]; // Run Viterbi - uint32_t prev_pos = sites[0]; for (i=0; ivpath[i*nstates]; double *eprob = &eprobs[i*nstates]; int pos_diff = sites[i] == prev_pos ? 0 : sites[i] - prev_pos - 1; - _set_tprob(hmm, pos_diff); if ( hmm->set_tprob ) hmm->set_tprob(hmm, prev_pos, sites[i], hmm->set_tprob_data, hmm->curr_tprob); prev_pos = sites[i]; @@ -193,6 +272,9 @@ void hmm_run_viterbi(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) } for (j=0; jvprob_tmp[j] /= vnorm; double *tmp = hmm->vprob; hmm->vprob = hmm->vprob_tmp; hmm->vprob_tmp = tmp; + + if ( hmm->snapshot && sites[i]==hmm->snapshot->snap_at_pos ) + memcpy(hmm->snapshot->vit_prob, hmm->vprob, sizeof(*hmm->vprob)*nstates); } // Find the most likely state @@ -224,21 +306,12 @@ void hmm_run_fwd_bwd(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) } - // Init all states with equal likelihood int i,j,k, nstates = hmm->nstates; - if ( hmm->init_probs ) - { - for (i=0; ifwd[i] = hmm->init_probs[i]; - for (i=0; ibwd[i] = hmm->init_probs[i]; - } - else - { - for (i=0; ifwd[i] = 1./hmm->nstates; - for (i=0; ibwd[i] = 1./hmm->nstates; - } + memcpy(hmm->fwd, hmm->state.fwd_prob, sizeof(*hmm->state.fwd_prob)*nstates); + memcpy(hmm->bwd, hmm->state.bwd_prob, sizeof(*hmm->state.bwd_prob)*nstates); + uint32_t prev_pos = hmm->state.snap_at_pos ? hmm->state.snap_at_pos : sites[0]; // Run fwd - uint32_t prev_pos = sites[0]; for (i=0; ifwd[i*nstates]; @@ -261,6 +334,9 @@ void hmm_run_fwd_bwd(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) norm += fwd[j]; } for (j=0; jsnapshot && sites[i]==hmm->snapshot->snap_at_pos ) + memcpy(hmm->snapshot->fwd_prob, fwd, sizeof(*fwd)*nstates); } // Run bwd @@ -298,7 +374,7 @@ void hmm_run_fwd_bwd(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) } } -void hmm_run_baum_welch(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) +double *hmm_run_baum_welch(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) { // Init arrays when run for the first time if ( hmm->nfwd < n ) @@ -314,16 +390,9 @@ void hmm_run_baum_welch(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) // Init all states with equal likelihood int i,j,k, nstates = hmm->nstates; - if ( hmm->init_probs ) - { - for (i=0; ifwd[i] = hmm->init_probs[i]; - for (i=0; ibwd[i] = hmm->init_probs[i]; - } - else - { - for (i=0; ifwd[i] = 1./hmm->nstates; - for (i=0; ibwd[i] = 1./hmm->nstates; - } + memcpy(hmm->fwd, hmm->state.fwd_prob, sizeof(*hmm->state.fwd_prob)*nstates); + memcpy(hmm->bwd, hmm->state.bwd_prob, sizeof(*hmm->state.bwd_prob)*nstates); + uint32_t prev_pos = hmm->state.snap_at_pos ? hmm->state.snap_at_pos : sites[0]; // New transition matrix: temporary values double *tmp_xi = (double*) calloc(nstates*nstates,sizeof(double)); @@ -331,7 +400,6 @@ void hmm_run_baum_welch(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) double *fwd_bwd = (double*) malloc(sizeof(double)*nstates); // Run fwd - uint32_t prev_pos = sites[0]; for (i=0; ifwd[i*nstates]; @@ -418,11 +486,17 @@ void hmm_run_baum_welch(hmm_t *hmm, int n, double *eprobs, uint32_t *sites) free(tmp_gamma); free(tmp_xi); free(fwd_bwd); + return hmm->curr_tprob; } void hmm_destroy(hmm_t *hmm) { - free(hmm->init_probs); + free(hmm->init.vit_prob); + free(hmm->init.fwd_prob); + free(hmm->init.bwd_prob); + free(hmm->state.vit_prob); + free(hmm->state.fwd_prob); + free(hmm->state.bwd_prob); free(hmm->vprob); free(hmm->vprob_tmp); free(hmm->vpath); diff --git a/bcftools/HMM.h b/bcftools/HMM.h index 7f01245ed..70c9cb885 100644 --- a/bcftools/HMM.h +++ b/bcftools/HMM.h @@ -44,6 +44,10 @@ typedef void (*set_tprob_f) (hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void * hmm_t *hmm_init(int nstates, double *tprob, int ntprob); void hmm_set_tprob(hmm_t *hmm, double *tprob, int ntprob); +#define HMM_VIT 1 +#define HMM_FWD 2 +#define HMM_BWD 4 + /** * hmm_init_states() - initial state probabilities * @probs: initial state probabilities or NULL to reset to default @@ -52,6 +56,25 @@ void hmm_set_tprob(hmm_t *hmm, double *tprob, int ntprob); */ void hmm_init_states(hmm_t *hmm, double *probs); +/** + * hmm_snapshot() - take the model's snapshot, intended for sliding HMM + * @snapshot: NULL or snapshot returned by previous hmm_snapshot() call, must be free()-ed by the caller + * @pos: take the snapshot at this position + * + * If both restore() and snapshot() are needed, restore() must be called first. + */ +void *hmm_snapshot(hmm_t *hmm, void *snapshot, uint32_t pos); + +/** + * hmm_restore() - restore model's snapshot, intended for sliding HMM + * @snapshot: snapshot returned by hmm_snapshot() call or NULL to reset + * @isite: take the snapshot at i-th step + * + * If both restore() and snapshot() are needed, restore() must be called first. + */ +void hmm_restore(hmm_t *hmm, void *snapshot); +void hmm_reset(hmm_t *hmm, void *snapshot); + /** * hmm_get_tprob() - return the array of transition matrices, precalculated * to ntprob positions. The first matrix is the initial tprob matrix @@ -103,11 +126,11 @@ double *hmm_get_fwd_bwd_prob(hmm_t *hmm); * @eprob: emission probabilities for each site and state (nsites x nstates) * @sites: list of positions * - * Same as hmm_run_fwd_bwd, in addition curr_tprob contains the new - * transition probabilities. In this verison, emission probabilities - * are not updated. + * Same as hmm_run_fwd_bwd, in addition a pointer to a matrix with the new + * transition probabilities is returned. In this verison, emission + * probabilities are not updated. */ -void hmm_run_baum_welch(hmm_t *hmm, int nsites, double *eprob, uint32_t *sites); +double *hmm_run_baum_welch(hmm_t *hmm, int nsites, double *eprob, uint32_t *sites); void hmm_destroy(hmm_t *hmm); diff --git a/bcftools/bam2bcf.c b/bcftools/bam2bcf.c new file mode 100644 index 000000000..c8dc91be4 --- /dev/null +++ b/bcftools/bam2bcf.c @@ -0,0 +1,866 @@ +/* bam2bcf.c -- variant calling. + + Copyright (C) 2010-2012 Broad Institute. + Copyright (C) 2012-2014 Genome Research Ltd. + + Author: Heng Li + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "bam2bcf.h" + +extern void ks_introsort_uint32_t(size_t n, uint32_t a[]); + +#define CALL_DEFTHETA 0.83 +#define DEF_MAPQ 20 + +#define CAP_DIST 25 + +bcf_callaux_t *bcf_call_init(double theta, int min_baseQ) +{ + bcf_callaux_t *bca; + if (theta <= 0.) theta = CALL_DEFTHETA; + bca = (bcf_callaux_t*) calloc(1, sizeof(bcf_callaux_t)); + bca->capQ = 60; + bca->openQ = 40; bca->extQ = 20; bca->tandemQ = 100; + bca->min_baseQ = min_baseQ; + bca->e = errmod_init(1. - theta); + bca->min_frac = 0.002; + bca->min_support = 1; + bca->per_sample_flt = 0; + bca->npos = 100; + bca->ref_pos = (int*) malloc(bca->npos*sizeof(int)); + bca->alt_pos = (int*) malloc(bca->npos*sizeof(int)); + bca->nqual = 60; + bca->ref_mq = (int*) malloc(bca->nqual*sizeof(int)); + bca->alt_mq = (int*) malloc(bca->nqual*sizeof(int)); + bca->ref_bq = (int*) malloc(bca->nqual*sizeof(int)); + bca->alt_bq = (int*) malloc(bca->nqual*sizeof(int)); + bca->fwd_mqs = (int*) malloc(bca->nqual*sizeof(int)); + bca->rev_mqs = (int*) malloc(bca->nqual*sizeof(int)); + return bca; +} + +void bcf_call_destroy(bcf_callaux_t *bca) +{ + if (bca == 0) return; + errmod_destroy(bca->e); + if (bca->npos) { free(bca->ref_pos); free(bca->alt_pos); bca->npos = 0; } + free(bca->ref_mq); free(bca->alt_mq); free(bca->ref_bq); free(bca->alt_bq); + free(bca->fwd_mqs); free(bca->rev_mqs); + bca->nqual = 0; + free(bca->bases); free(bca->inscns); free(bca); +} + +// position in the sequence with respect to the aligned part of the read +static int get_position(const bam_pileup1_t *p, int *len) +{ + int icig, n_tot_bases = 0, iread = 0, edist = p->qpos + 1; + for (icig=0; icigb->core.n_cigar; icig++) + { + int cig = bam_get_cigar(p->b)[icig] & BAM_CIGAR_MASK; + int ncig = bam_get_cigar(p->b)[icig] >> BAM_CIGAR_SHIFT; + if ( cig==BAM_CMATCH || cig==BAM_CEQUAL || cig==BAM_CDIFF ) + { + n_tot_bases += ncig; + iread += ncig; + continue; + } + if ( cig==BAM_CINS ) + { + n_tot_bases += ncig; + iread += ncig; + continue; + } + if ( cig==BAM_CSOFT_CLIP ) + { + iread += ncig; + if ( iread<=p->qpos ) edist -= ncig; + continue; + } + if ( cig==BAM_CDEL ) continue; + if ( cig==BAM_CHARD_CLIP ) continue; + if ( cig==BAM_CPAD ) continue; + if ( cig==BAM_CREF_SKIP ) continue; + fprintf(stderr,"todo: cigar %d\n", cig); + assert(0); + } + *len = n_tot_bases; + return edist; +} + +void bcf_callaux_clean(bcf_callaux_t *bca, bcf_call_t *call) +{ + memset(bca->ref_pos,0,sizeof(int)*bca->npos); + memset(bca->alt_pos,0,sizeof(int)*bca->npos); + memset(bca->ref_mq,0,sizeof(int)*bca->nqual); + memset(bca->alt_mq,0,sizeof(int)*bca->nqual); + memset(bca->ref_bq,0,sizeof(int)*bca->nqual); + memset(bca->alt_bq,0,sizeof(int)*bca->nqual); + memset(bca->fwd_mqs,0,sizeof(int)*bca->nqual); + memset(bca->rev_mqs,0,sizeof(int)*bca->nqual); + if ( call->ADF ) memset(call->ADF,0,sizeof(int32_t)*(call->n+1)*B2B_MAX_ALLELES); + if ( call->ADR ) memset(call->ADR,0,sizeof(int32_t)*(call->n+1)*B2B_MAX_ALLELES); +} + +/* + Notes: + - Called from bam_plcmd.c by mpileup. Amongst other things, sets the bcf_callret1_t.qsum frequencies + which are carried over via bcf_call_combine and bcf_call2bcf to the output BCF as the QS annotation. + Later it's used for multiallelic calling by bcftools -m + - ref_base is the 4-bit representation of the reference base. It is negative if we are looking at an indel. + */ +/* + * This function is called once for each sample. + * _n is number of pilesups pl contributing reads to this sample + * pl is pointer to array of _n pileups (one pileup per read) + * ref_base is the 4-bit representation of the reference base. It is negative if we are looking at an indel. + * bca is the settings to perform calls across all samples + * r is the returned value of the call + */ +int bcf_call_glfgen(int _n, const bam_pileup1_t *pl, int ref_base, bcf_callaux_t *bca, bcf_callret1_t *r) +{ + int i, n, ref4, is_indel, ori_depth = 0; + + // clean from previous run + r->ori_depth = 0; + r->mq0 = 0; + memset(r->qsum,0,sizeof(float)*4); + memset(r->anno,0,sizeof(double)*16); + memset(r->p,0,sizeof(float)*25); + + if (ref_base >= 0) { + ref4 = seq_nt16_int[ref_base]; + is_indel = 0; + } else ref4 = 4, is_indel = 1; + if (_n == 0) return -1; + // enlarge the bases array if necessary + if (bca->max_bases < _n) { + bca->max_bases = _n; + kroundup32(bca->max_bases); + bca->bases = (uint16_t*)realloc(bca->bases, 2 * bca->max_bases); + } + // fill the bases array + for (i = n = 0; i < _n; ++i) { + const bam_pileup1_t *p = pl + i; + int q, b, mapQ, baseQ, is_diff, min_dist, seqQ; + if (p->is_refskip || (p->b->core.flag&BAM_FUNMAP)) continue; + if (p->is_del && !is_indel) continue; + ++ori_depth; + if (is_indel) + { + b = p->aux>>16&0x3f; + baseQ = q = p->aux&0xff; + // This read is not counted as indel. Instead of skipping it, treat it as ref. It is + // still only an approximation, but gives more accurate AD counts and calls correctly + // hets instead of alt-homs in some cases (see test/mpileup/indel-AD.1.sam) + if ( q < bca->min_baseQ ) b = 0, q = (int)bam_get_qual(p->b)[p->qpos]; + seqQ = p->aux>>8&0xff; + is_diff = (b != 0); + } + else + { + b = bam_seqi(bam_get_seq(p->b), p->qpos); // base + b = seq_nt16_int[b? b : ref_base]; // b is the 2-bit base + baseQ = q = (int)bam_get_qual(p->b)[p->qpos]; + if (q < bca->min_baseQ) continue; + seqQ = 99; + is_diff = (ref4 < 4 && b == ref4)? 0 : 1; + } + mapQ = p->b->core.qual < 255? p->b->core.qual : DEF_MAPQ; // special case for mapQ==255 + if ( !mapQ ) r->mq0++; + if (q > seqQ) q = seqQ; + mapQ = mapQ < bca->capQ? mapQ : bca->capQ; + if (q > mapQ) q = mapQ; + if (q > 63) q = 63; + if (q < 4) q = 4; // MQ=0 reads count as BQ=4 + bca->bases[n++] = q<<5 | (int)bam_is_rev(p->b)<<4 | b; + // collect annotations + if (b < 4) + { + r->qsum[b] += q; + if ( r->ADF ) + { + if ( bam_is_rev(p->b) ) + r->ADR[b]++; + else + r->ADF[b]++; + } + } + ++r->anno[0<<2|is_diff<<1|bam_is_rev(p->b)]; + min_dist = p->b->core.l_qseq - 1 - p->qpos; + if (min_dist > p->qpos) min_dist = p->qpos; + if (min_dist > CAP_DIST) min_dist = CAP_DIST; + r->anno[1<<2|is_diff<<1|0] += baseQ; + r->anno[1<<2|is_diff<<1|1] += baseQ * baseQ; + r->anno[2<<2|is_diff<<1|0] += mapQ; + r->anno[2<<2|is_diff<<1|1] += mapQ * mapQ; + r->anno[3<<2|is_diff<<1|0] += min_dist; + r->anno[3<<2|is_diff<<1|1] += min_dist * min_dist; + + // collect for bias tests + if ( baseQ > 59 ) baseQ = 59; + if ( mapQ > 59 ) mapQ = 59; + int len, pos = get_position(p, &len); + int epos = (double)pos/(len+1) * bca->npos; + int ibq = baseQ/60. * bca->nqual; + int imq = mapQ/60. * bca->nqual; + if ( bam_is_rev(p->b) ) bca->rev_mqs[imq]++; + else bca->fwd_mqs[imq]++; + if ( bam_seqi(bam_get_seq(p->b),p->qpos) == ref_base ) + { + bca->ref_pos[epos]++; + bca->ref_bq[ibq]++; + bca->ref_mq[imq]++; + } + else + { + bca->alt_pos[epos]++; + bca->alt_bq[ibq]++; + bca->alt_mq[imq]++; + } + } + r->ori_depth = ori_depth; + // glfgen + errmod_cal(bca->e, n, 5, bca->bases, r->p); // calculate PL of each genotype + return n; +} + + +/* + * calc_vdb() - returns value between zero (most biased) and one (no bias) + * on success, or HUGE_VAL when VDB cannot be calculated because + * of insufficient depth (<2x) + * + * Variant Distance Bias tests if the variant bases are positioned within the + * reads with sufficient randomness. Unlike other tests, it looks only at + * variant reads and therefore gives different kind of information than Read + * Position Bias for instance. VDB was developed for detecting artefacts in + * RNA-seq calls where reads from spliced transcripts span splice site + * boundaries. The current implementation differs somewhat from the original + * version described in supplementary material of PMID:22524474, but the idea + * remains the same. (Here the random variable tested is the average distance + * from the averaged position, not the average pairwise distance.) + * + * For coverage of 2x, the calculation is exact but is approximated for the + * rest. The result is most accurate between 4-200x. For 3x or >200x, the + * reported values are slightly more favourable than those of a true random + * distribution. + */ +double calc_vdb(int *pos, int npos) +{ + // Note well: the parameters were obtained by fitting to simulated data of + // 100bp reads. This assumes rescaling to 100bp in bcf_call_glfgen(). + const int readlen = 100; + assert( npos==readlen ); + + #define nparam 15 + const float param[nparam][3] = { {3,0.079,18}, {4,0.09,19.8}, {5,0.1,20.5}, {6,0.11,21.5}, + {7,0.125,21.6}, {8,0.135,22}, {9,0.14,22.2}, {10,0.153,22.3}, {15,0.19,22.8}, + {20,0.22,23.2}, {30,0.26,23.4}, {40,0.29,23.5}, {50,0.35,23.65}, {100,0.5,23.7}, + {200,0.7,23.7} }; + + int i, dp = 0; + float mean_pos = 0, mean_diff = 0; + for (i=0; i=200 ) + i = nparam; // shortcut for big depths + else + { + for (i=0; i=dp ) break; + } + float pshift, pscale; + if ( i==nparam ) + { + // the depth is too high, go with 200x + pscale = param[nparam-1][1]; + pshift = param[nparam-1][2]; + } + else if ( i>0 && param[i][0]!=dp ) + { + // linear interpolation of parameters + pscale = (param[i-1][1] + param[i][1])*0.5; + pshift = (param[i-1][2] + param[i][2])*0.5; + } + else + { + pscale = param[i][1]; + pshift = param[i][2]; + } + return 0.5*kf_erfc(-(mean_diff-pshift)*pscale); +} + +double calc_chisq_bias(int *a, int *b, int n) +{ + int na = 0, nb = 0, i, ndf = n; + for (i=0; i= 2 && m >= 2); + + return (n < 8 && m < 8 && U < 50) + ? mw[n-2][m-2][U] + : mann_whitney_1947_(n,m,U); +} + +double mann_whitney_1947_cdf(int n, int m, int U) +{ + int i; + double sum = 0; + for (i=0; i<=U; i++) + sum += mann_whitney_1947(n,m,i); + return sum; +} + +double calc_mwu_bias_cdf(int *a, int *b, int n) +{ + int na = 0, nb = 0, i; + double U = 0, ties = 0; + for (i=0; i=8 && nb>=8 and reasonable if na<8 or nb<8 + if ( na>=8 || nb>=8 ) + { + double mean = ((double)na*nb)*0.5; + // Correction for ties: + // double N = na+nb; + // double var2 = (N*N-1)*N-ties; + // if ( var2==0 ) return 1.0; + // var2 *= ((double)na*nb)/N/(N-1)/12.0; + // No correction for ties: + double var2 = ((double)na*nb)*(na+nb+1)/12.0; + double z = (U_min - mean)/sqrt(2*var2); // z is N(0,1) + return 2.0 - kf_erfc(z); // which is 1 + erf(z) + } + + // Exact calculation + double pval = 2*mann_whitney_1947_cdf(na,nb,U_min); + return pval>1 ? 1 : pval; +} + +double calc_mwu_bias(int *a, int *b, int n) +{ + int na = 0, nb = 0, i; + double U = 0, ties = 0; + for (i=0; imean ? (2.0*mean-U)/mean : U/mean; + } + // Correction for ties: + // double N = na+nb; + // double var2 = (N*N-1)*N-ties; + // if ( var2==0 ) return 1.0; + // var2 *= ((double)na*nb)/N/(N-1)/12.0; + // No correction for ties: + double var2 = ((double)na*nb)*(na+nb+1)/12.0; + if ( na>=8 || nb>=8 ) + { + // Normal approximation, very good for na>=8 && nb>=8 and reasonable if na<8 or nb<8 + return exp(-0.5*(U-mean)*(U-mean)/var2); + } + + // Exact calculation + return mann_whitney_1947(na,nb,U) * sqrt(2*M_PI*var2); +} + +static inline double logsumexp2(double a, double b) +{ + if ( a>b ) + return log(1 + exp(b-a)) + a; + else + return log(1 + exp(a-b)) + b; +} + +void calc_SegBias(const bcf_callret1_t *bcr, bcf_call_t *call) +{ + call->seg_bias = HUGE_VAL; + if ( !bcr ) return; + + int nr = call->anno[2] + call->anno[3]; // number of observed non-reference reads + if ( !nr ) return; + + int avg_dp = (call->anno[0] + call->anno[1] + nr) / call->n; // average depth + double M = floor((double)nr / avg_dp + 0.5); // an approximate number of variants samples in the population + if ( M>call->n ) M = call->n; // clamp M at the number of samples + else if ( M==0 ) M = 1; + double f = M / 2. / call->n; // allele frequency + double p = (double) nr / call->n; // number of variant reads per sample expected if variant not real (poisson) + double q = (double) nr / M; // number of variant reads per sample expected if variant is real (poisson) + double sum = 0; + const double log2 = log(2.0); + + // fprintf(stderr,"M=%.1f p=%e q=%e f=%f dp=%d\n",M,p,q,f,avg_dp); + int i; + for (i=0; in; i++) + { + int oi = bcr[i].anno[2] + bcr[i].anno[3]; // observed number of non-ref reads + double tmp; + if ( oi ) + { + // tmp = log(f) + oi*log(q/p) - q + log(2*(1-f) + f*pow(2,oi)*exp(-q)) + p; // this can under/overflow + tmp = logsumexp2(log(2*(1-f)), log(f) + oi*log2 - q); + tmp += log(f) + oi*log(q/p) - q + p; + } + else + tmp = log(2*f*(1-f)*exp(-q) + f*f*exp(-2*q) + (1-f)*(1-f)) + p; + sum += tmp; + // fprintf(stderr,"oi=%d %e\n", oi,tmp); + } + call->seg_bias = sum; +} + +/** + * bcf_call_combine() - sets the PL array and VDB, RPB annotations, finds the top two alleles + * @n: number of samples + * @calls: each sample's calls + * @bca: auxiliary data structure for holding temporary values + * @ref_base: the reference base + * @call: filled with the annotations + * + * Combines calls across the various samples being studied + * 1. For each allele at each base across all samples the quality is summed so + * you end up with a set of quality sums for each allele present 2. The quality + * sums are sorted. + * 3. Using the sorted quality sums we now create the allele ordering array + * A\subN. This is done by doing the following: + * a) If the reference allele is known it always comes first, otherwise N + * comes first. + * b) Then the rest of the alleles are output in descending order of quality + * sum (which we already know the qsum array was sorted). Any allelles with + * qsum 0 will be excluded. + * 4. Using the allele ordering array we create the genotype ordering array. + * In the worst case with an unknown reference this will be: A0/A0 A1/A0 A1/A1 + * A2/A0 A2/A1 A2/A2 A3/A0 A3/A1 A3/A2 A3/A3 A4/A0 A4/A1 A4/A2 A4/A3 A4/A4 + * 5. The genotype ordering array is then used to extract data from the error + * model 5*5 matrix and is used to produce a Phread likelihood array for each + * sample. + */ +int bcf_call_combine(int n, const bcf_callret1_t *calls, bcf_callaux_t *bca, int ref_base /*4-bit*/, bcf_call_t *call) +{ + int ref4, i, j; + float qsum[5] = {0,0,0,0,0}; + if (ref_base >= 0) { + call->ori_ref = ref4 = seq_nt16_int[ref_base]; + if (ref4 > 4) ref4 = 4; + } else call->ori_ref = -1, ref4 = 0; + + // calculate qsum, this is done by summing normalized qsum across all samples, + // to account for differences in coverage + for (i = 0; i < n; ++i) + { + float sum = 0; + for (j = 0; j < 4; ++j) sum += calls[i].qsum[j]; + if ( sum ) + for (j = 0; j < 4; j++) qsum[j] += calls[i].qsum[j] / sum; + } + + // sort qsum in ascending order (insertion sort) + float *ptr[5], *tmp; + for (i=0; i<5; i++) ptr[i] = &qsum[i]; + for (i=1; i<4; i++) + for (j=i; j>0 && *ptr[j] < *ptr[j-1]; j--) + tmp = ptr[j], ptr[j] = ptr[j-1], ptr[j-1] = tmp; + + // Set the reference allele and alternative allele(s) + for (i=0; i<5; i++) call->a[i] = -1; + for (i=0; i<5; i++) call->qsum[i] = 0; + call->unseen = -1; + call->a[0] = ref4; + for (i=3, j=1; i>=0; i--) // i: alleles sorted by QS; j, a[j]: output allele ordering + { + int ipos = ptr[i] - qsum; // position in sorted qsum array + if ( ipos==ref4 ) + call->qsum[0] = qsum[ipos]; // REF's qsum + else + { + if ( !qsum[ipos] ) break; // qsum is 0, this and consequent alleles are not seen in the pileup + call->qsum[j] = qsum[ipos]; + call->a[j++] = ipos; + } + } + if (ref_base >= 0) + { + // for SNPs, find the "unseen" base + if (((ref4 < 4 && j < 4) || (ref4 == 4 && j < 5)) && i >= 0) + call->unseen = j, call->a[j++] = ptr[i] - qsum; + call->n_alleles = j; + } + else + { + call->n_alleles = j; + if (call->n_alleles == 1) return -1; // no reliable supporting read. stop doing anything + } + /* + * Set the phread likelihood array (call->PL) This array is 15 entries long + * for each sample because that is size of an upper or lower triangle of a + * worst case 5x5 matrix of possible genotypes. This worst case matrix will + * occur when all 4 possible alleles are present and the reference allele + * is unknown. The sides of the matrix will correspond to the reference + * allele (if known) followed by the alleles present in descending order of + * quality sum + */ + { + int x, g[15], z; + double sum_min = 0.; + x = call->n_alleles * (call->n_alleles + 1) / 2; + // get the possible genotypes + // this is done by creating an ordered list of locations g for call (allele a, allele b) in the genotype likelihood matrix + for (i = z = 0; i < call->n_alleles; ++i) { + for (j = 0; j <= i; ++j) { + g[z++] = call->a[j] * 5 + call->a[i]; + } + } + // for each sample calculate the PL + for (i = 0; i < n; ++i) + { + int32_t *PL = call->PL + x * i; + const bcf_callret1_t *r = calls + i; + float min = FLT_MAX; + for (j = 0; j < x; ++j) { + if (min > r->p[g[j]]) min = r->p[g[j]]; + } + sum_min += min; + for (j = 0; j < x; ++j) { + int y; + y = (int)(r->p[g[j]] - min + .499); + if (y > 255) y = 255; + PL[j] = y; + } + } + if ( call->DP4 ) + { + for (i=0; iDP4[4*i] = calls[i].anno[0]; + call->DP4[4*i+1] = calls[i].anno[1]; + call->DP4[4*i+2] = calls[i].anno[2]; + call->DP4[4*i+3] = calls[i].anno[3]; + } + } + if ( call->ADF ) + { + assert( call->n_alleles<=B2B_MAX_ALLELES ); // this is always true for SNPs and so far for indels as well + + // reorder ADR,ADF to match the allele ordering at this site + int32_t tmp[B2B_MAX_ALLELES]; + int32_t *adr = call->ADR + B2B_MAX_ALLELES, *adr_out = call->ADR + B2B_MAX_ALLELES; + int32_t *adf = call->ADF + B2B_MAX_ALLELES, *adf_out = call->ADF + B2B_MAX_ALLELES; + int32_t *adr_tot = call->ADR; // the first bin stores total counts per site + int32_t *adf_tot = call->ADF; + for (i=0; in_alleles; j++) + { + tmp[j] = adr[ call->a[j] ]; + adr_tot[j] += tmp[j]; + } + for (j=0; jn_alleles; j++) adr_out[j] = tmp[j]; + for (j=0; jn_alleles; j++) + { + tmp[j] = adf[ call->a[j] ]; + adf_tot[j] += tmp[j]; + } + for (j=0; jn_alleles; j++) adf_out[j] = tmp[j]; + adf_out += call->n_alleles; + adr_out += call->n_alleles; + adr += B2B_MAX_ALLELES; + adf += B2B_MAX_ALLELES; + } + } + +// if (ref_base < 0) fprintf(stderr, "%d,%d,%f,%d\n", call->n_alleles, x, sum_min, call->unseen); + call->shift = (int)(sum_min + .499); + } + // combine annotations + memset(call->anno, 0, 16 * sizeof(double)); + call->ori_depth = 0; + call->depth = 0; + call->mq0 = 0; + for (i = 0; i < n; ++i) { + call->depth += calls[i].anno[0] + calls[i].anno[1] + calls[i].anno[2] + calls[i].anno[3]; + call->ori_depth += calls[i].ori_depth; + call->mq0 += calls[i].mq0; + for (j = 0; j < 16; ++j) call->anno[j] += calls[i].anno[j]; + } + + calc_SegBias(calls, call); + + // calc_chisq_bias("XPOS", call->bcf_hdr->id[BCF_DT_CTG][call->tid].key, call->pos, bca->ref_pos, bca->alt_pos, bca->npos); + // calc_chisq_bias("XMQ", call->bcf_hdr->id[BCF_DT_CTG][call->tid].key, call->pos, bca->ref_mq, bca->alt_mq, bca->nqual); + // calc_chisq_bias("XBQ", call->bcf_hdr->id[BCF_DT_CTG][call->tid].key, call->pos, bca->ref_bq, bca->alt_bq, bca->nqual); + + call->mwu_pos = calc_mwu_bias(bca->ref_pos, bca->alt_pos, bca->npos); + call->mwu_mq = calc_mwu_bias(bca->ref_mq, bca->alt_mq, bca->nqual); + call->mwu_bq = calc_mwu_bias(bca->ref_bq, bca->alt_bq, bca->nqual); + call->mwu_mqs = calc_mwu_bias(bca->fwd_mqs, bca->rev_mqs, bca->nqual); + +#if CDF_MWU_TESTS + call->mwu_pos_cdf = calc_mwu_bias_cdf(bca->ref_pos, bca->alt_pos, bca->npos); + call->mwu_mq_cdf = calc_mwu_bias_cdf(bca->ref_mq, bca->alt_mq, bca->nqual); + call->mwu_bq_cdf = calc_mwu_bias_cdf(bca->ref_bq, bca->alt_bq, bca->nqual); + call->mwu_mqs_cdf = calc_mwu_bias_cdf(bca->fwd_mqs, bca->rev_mqs, bca->nqual); +#endif + + call->vdb = calc_vdb(bca->alt_pos, bca->npos); + + return 0; +} + +int bcf_call2bcf(bcf_call_t *bc, bcf1_t *rec, bcf_callret1_t *bcr, int fmt_flag, const bcf_callaux_t *bca, const char *ref) +{ + extern double kt_fisher_exact(int n11, int n12, int n21, int n22, double *_left, double *_right, double *two); + int i, j, nals = 1; + + bcf_hdr_t *hdr = bc->bcf_hdr; + rec->rid = bc->tid; + rec->pos = bc->pos; + rec->qual = 0; + + bc->tmp.l = 0; + if (bc->ori_ref < 0) // indel + { + // REF + kputc(ref[bc->pos], &bc->tmp); + for (j = 0; j < bca->indelreg; ++j) kputc(ref[bc->pos+1+j], &bc->tmp); + + // ALT + for (i=1; i<4; i++) + { + if (bc->a[i] < 0) break; + kputc(',', &bc->tmp); kputc(ref[bc->pos], &bc->tmp); + + if (bca->indel_types[bc->a[i]] < 0) { // deletion + for (j = -bca->indel_types[bc->a[i]]; j < bca->indelreg; ++j) + kputc(ref[bc->pos+1+j], &bc->tmp); + } else { // insertion; cannot be a reference unless a bug + char *inscns = &bca->inscns[bc->a[i] * bca->maxins]; + for (j = 0; j < bca->indel_types[bc->a[i]]; ++j) + kputc("ACGTN"[(int)inscns[j]], &bc->tmp); + for (j = 0; j < bca->indelreg; ++j) kputc(ref[bc->pos+1+j], &bc->tmp); + } + nals++; + } + } + else // SNP + { + kputc("ACGTN"[bc->ori_ref], &bc->tmp); + for (i=1; i<5; i++) + { + if (bc->a[i] < 0) break; + kputc(',', &bc->tmp); + if ( bc->unseen==i ) kputs("<*>", &bc->tmp); + else kputc("ACGT"[bc->a[i]], &bc->tmp); + nals++; + } + } + bcf_update_alleles_str(hdr, rec, bc->tmp.s); + + bc->tmp.l = 0; + + // INFO + if (bc->ori_ref < 0) + { + bcf_update_info_flag(hdr, rec, "INDEL", NULL, 1); + bcf_update_info_int32(hdr, rec, "IDV", &bca->max_support, 1); + bcf_update_info_float(hdr, rec, "IMF", &bca->max_frac, 1); + } + bcf_update_info_int32(hdr, rec, "DP", &bc->ori_depth, 1); + if ( fmt_flag&B2B_INFO_ADF ) + bcf_update_info_int32(hdr, rec, "ADF", bc->ADF, rec->n_allele); + if ( fmt_flag&B2B_INFO_ADR ) + bcf_update_info_int32(hdr, rec, "ADR", bc->ADR, rec->n_allele); + if ( fmt_flag&(B2B_INFO_AD|B2B_INFO_DPR) ) + { + for (i=0; in_allele; i++) bc->ADF[i] += bc->ADR[i]; + if ( fmt_flag&B2B_INFO_AD ) + bcf_update_info_int32(hdr, rec, "AD", bc->ADF, rec->n_allele); + if ( fmt_flag&B2B_INFO_DPR ) + bcf_update_info_int32(hdr, rec, "DPR", bc->ADF, rec->n_allele); + } + + float tmpf[16]; + for (i=0; i<16; i++) tmpf[i] = bc->anno[i]; + bcf_update_info_float(hdr, rec, "I16", tmpf, 16); + bcf_update_info_float(hdr, rec, "QS", bc->qsum, nals); + + if ( bc->vdb != HUGE_VAL ) bcf_update_info_float(hdr, rec, "VDB", &bc->vdb, 1); + if ( bc->seg_bias != HUGE_VAL ) bcf_update_info_float(hdr, rec, "SGB", &bc->seg_bias, 1); + if ( bc->mwu_pos != HUGE_VAL ) bcf_update_info_float(hdr, rec, "RPB", &bc->mwu_pos, 1); + if ( bc->mwu_mq != HUGE_VAL ) bcf_update_info_float(hdr, rec, "MQB", &bc->mwu_mq, 1); + if ( bc->mwu_mqs != HUGE_VAL ) bcf_update_info_float(hdr, rec, "MQSB", &bc->mwu_mqs, 1); + if ( bc->mwu_bq != HUGE_VAL ) bcf_update_info_float(hdr, rec, "BQB", &bc->mwu_bq, 1); +#if CDF_MWU_TESTS + if ( bc->mwu_pos_cdf != HUGE_VAL ) bcf_update_info_float(hdr, rec, "RPB2", &bc->mwu_pos_cdf, 1); + if ( bc->mwu_mq_cdf != HUGE_VAL ) bcf_update_info_float(hdr, rec, "MQB2", &bc->mwu_mq_cdf, 1); + if ( bc->mwu_mqs_cdf != HUGE_VAL ) bcf_update_info_float(hdr, rec, "MQSB2", &bc->mwu_mqs_cdf, 1); + if ( bc->mwu_bq_cdf != HUGE_VAL ) bcf_update_info_float(hdr, rec, "BQB2", &bc->mwu_bq_cdf, 1); +#endif + tmpf[0] = bc->ori_depth ? (float)bc->mq0/bc->ori_depth : 0; + bcf_update_info_float(hdr, rec, "MQ0F", tmpf, 1); + + // FORMAT + rec->n_sample = bc->n; + bcf_update_format_int32(hdr, rec, "PL", bc->PL, nals*(nals+1)/2 * rec->n_sample); + if ( fmt_flag&B2B_FMT_DP ) + { + int32_t *ptr = (int32_t*) bc->fmt_arr; + for (i=0; in; i++) + ptr[i] = bc->DP4[4*i] + bc->DP4[4*i+1] + bc->DP4[4*i+2] + bc->DP4[4*i+3]; + bcf_update_format_int32(hdr, rec, "DP", bc->fmt_arr, rec->n_sample); + } + if ( fmt_flag&B2B_FMT_DV ) + { + int32_t *ptr = (int32_t*) bc->fmt_arr; + for (i=0; in; i++) + ptr[i] = bc->DP4[4*i+2] + bc->DP4[4*i+3]; + bcf_update_format_int32(hdr, rec, "DV", bc->fmt_arr, rec->n_sample); + } + if ( fmt_flag&B2B_FMT_SP ) + { + int32_t *ptr = (int32_t*) bc->fmt_arr; + for (i=0; in; i++) + { + int fwd_ref = bc->DP4[4*i], rev_ref = bc->DP4[4*i+1], fwd_alt = bc->DP4[4*i+2], rev_alt = bc->DP4[4*i+3]; + if ( fwd_ref+rev_ref<2 || fwd_alt+rev_alt<2 || fwd_ref+fwd_alt<2 || rev_ref+rev_alt<2 ) + ptr[i] = 0; + else + { + double left, right, two; + kt_fisher_exact(fwd_ref, rev_ref, fwd_alt, rev_alt, &left, &right, &two); + int32_t x = (int)(-4.343 * log(two) + .499); + if (x > 255) x = 255; + ptr[i] = x; + } + } + bcf_update_format_int32(hdr, rec, "SP", bc->fmt_arr, rec->n_sample); + } + if ( fmt_flag&B2B_FMT_DP4 ) + bcf_update_format_int32(hdr, rec, "DP4", bc->DP4, rec->n_sample*4); + if ( fmt_flag&B2B_FMT_ADF ) + bcf_update_format_int32(hdr, rec, "ADF", bc->ADF+B2B_MAX_ALLELES, rec->n_sample*rec->n_allele); + if ( fmt_flag&B2B_FMT_ADR ) + bcf_update_format_int32(hdr, rec, "ADR", bc->ADR+B2B_MAX_ALLELES, rec->n_sample*rec->n_allele); + if ( fmt_flag&(B2B_FMT_AD|B2B_FMT_DPR) ) + { + for (i=0; in_sample*rec->n_allele; i++) bc->ADF[B2B_MAX_ALLELES+i] += bc->ADR[B2B_MAX_ALLELES+i]; + if ( fmt_flag&B2B_FMT_AD ) + bcf_update_format_int32(hdr, rec, "AD", bc->ADF+B2B_MAX_ALLELES, rec->n_sample*rec->n_allele); + if ( fmt_flag&B2B_FMT_DPR ) + bcf_update_format_int32(hdr, rec, "DPR", bc->ADF+B2B_MAX_ALLELES, rec->n_sample*rec->n_allele); + } + + return 0; +} diff --git a/bcftools/bam2bcf.c.pysam.c b/bcftools/bam2bcf.c.pysam.c new file mode 100644 index 000000000..e6d72dd33 --- /dev/null +++ b/bcftools/bam2bcf.c.pysam.c @@ -0,0 +1,868 @@ +#include "bcftools.pysam.h" + +/* bam2bcf.c -- variant calling. + + Copyright (C) 2010-2012 Broad Institute. + Copyright (C) 2012-2014 Genome Research Ltd. + + Author: Heng Li + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "bam2bcf.h" + +extern void ks_introsort_uint32_t(size_t n, uint32_t a[]); + +#define CALL_DEFTHETA 0.83 +#define DEF_MAPQ 20 + +#define CAP_DIST 25 + +bcf_callaux_t *bcf_call_init(double theta, int min_baseQ) +{ + bcf_callaux_t *bca; + if (theta <= 0.) theta = CALL_DEFTHETA; + bca = (bcf_callaux_t*) calloc(1, sizeof(bcf_callaux_t)); + bca->capQ = 60; + bca->openQ = 40; bca->extQ = 20; bca->tandemQ = 100; + bca->min_baseQ = min_baseQ; + bca->e = errmod_init(1. - theta); + bca->min_frac = 0.002; + bca->min_support = 1; + bca->per_sample_flt = 0; + bca->npos = 100; + bca->ref_pos = (int*) malloc(bca->npos*sizeof(int)); + bca->alt_pos = (int*) malloc(bca->npos*sizeof(int)); + bca->nqual = 60; + bca->ref_mq = (int*) malloc(bca->nqual*sizeof(int)); + bca->alt_mq = (int*) malloc(bca->nqual*sizeof(int)); + bca->ref_bq = (int*) malloc(bca->nqual*sizeof(int)); + bca->alt_bq = (int*) malloc(bca->nqual*sizeof(int)); + bca->fwd_mqs = (int*) malloc(bca->nqual*sizeof(int)); + bca->rev_mqs = (int*) malloc(bca->nqual*sizeof(int)); + return bca; +} + +void bcf_call_destroy(bcf_callaux_t *bca) +{ + if (bca == 0) return; + errmod_destroy(bca->e); + if (bca->npos) { free(bca->ref_pos); free(bca->alt_pos); bca->npos = 0; } + free(bca->ref_mq); free(bca->alt_mq); free(bca->ref_bq); free(bca->alt_bq); + free(bca->fwd_mqs); free(bca->rev_mqs); + bca->nqual = 0; + free(bca->bases); free(bca->inscns); free(bca); +} + +// position in the sequence with respect to the aligned part of the read +static int get_position(const bam_pileup1_t *p, int *len) +{ + int icig, n_tot_bases = 0, iread = 0, edist = p->qpos + 1; + for (icig=0; icigb->core.n_cigar; icig++) + { + int cig = bam_get_cigar(p->b)[icig] & BAM_CIGAR_MASK; + int ncig = bam_get_cigar(p->b)[icig] >> BAM_CIGAR_SHIFT; + if ( cig==BAM_CMATCH || cig==BAM_CEQUAL || cig==BAM_CDIFF ) + { + n_tot_bases += ncig; + iread += ncig; + continue; + } + if ( cig==BAM_CINS ) + { + n_tot_bases += ncig; + iread += ncig; + continue; + } + if ( cig==BAM_CSOFT_CLIP ) + { + iread += ncig; + if ( iread<=p->qpos ) edist -= ncig; + continue; + } + if ( cig==BAM_CDEL ) continue; + if ( cig==BAM_CHARD_CLIP ) continue; + if ( cig==BAM_CPAD ) continue; + if ( cig==BAM_CREF_SKIP ) continue; + fprintf(bcftools_stderr,"todo: cigar %d\n", cig); + assert(0); + } + *len = n_tot_bases; + return edist; +} + +void bcf_callaux_clean(bcf_callaux_t *bca, bcf_call_t *call) +{ + memset(bca->ref_pos,0,sizeof(int)*bca->npos); + memset(bca->alt_pos,0,sizeof(int)*bca->npos); + memset(bca->ref_mq,0,sizeof(int)*bca->nqual); + memset(bca->alt_mq,0,sizeof(int)*bca->nqual); + memset(bca->ref_bq,0,sizeof(int)*bca->nqual); + memset(bca->alt_bq,0,sizeof(int)*bca->nqual); + memset(bca->fwd_mqs,0,sizeof(int)*bca->nqual); + memset(bca->rev_mqs,0,sizeof(int)*bca->nqual); + if ( call->ADF ) memset(call->ADF,0,sizeof(int32_t)*(call->n+1)*B2B_MAX_ALLELES); + if ( call->ADR ) memset(call->ADR,0,sizeof(int32_t)*(call->n+1)*B2B_MAX_ALLELES); +} + +/* + Notes: + - Called from bam_plcmd.c by mpileup. Amongst other things, sets the bcf_callret1_t.qsum frequencies + which are carried over via bcf_call_combine and bcf_call2bcf to the output BCF as the QS annotation. + Later it's used for multiallelic calling by bcftools -m + - ref_base is the 4-bit representation of the reference base. It is negative if we are looking at an indel. + */ +/* + * This function is called once for each sample. + * _n is number of pilesups pl contributing reads to this sample + * pl is pointer to array of _n pileups (one pileup per read) + * ref_base is the 4-bit representation of the reference base. It is negative if we are looking at an indel. + * bca is the settings to perform calls across all samples + * r is the returned value of the call + */ +int bcf_call_glfgen(int _n, const bam_pileup1_t *pl, int ref_base, bcf_callaux_t *bca, bcf_callret1_t *r) +{ + int i, n, ref4, is_indel, ori_depth = 0; + + // clean from previous run + r->ori_depth = 0; + r->mq0 = 0; + memset(r->qsum,0,sizeof(float)*4); + memset(r->anno,0,sizeof(double)*16); + memset(r->p,0,sizeof(float)*25); + + if (ref_base >= 0) { + ref4 = seq_nt16_int[ref_base]; + is_indel = 0; + } else ref4 = 4, is_indel = 1; + if (_n == 0) return -1; + // enlarge the bases array if necessary + if (bca->max_bases < _n) { + bca->max_bases = _n; + kroundup32(bca->max_bases); + bca->bases = (uint16_t*)realloc(bca->bases, 2 * bca->max_bases); + } + // fill the bases array + for (i = n = 0; i < _n; ++i) { + const bam_pileup1_t *p = pl + i; + int q, b, mapQ, baseQ, is_diff, min_dist, seqQ; + if (p->is_refskip || (p->b->core.flag&BAM_FUNMAP)) continue; + if (p->is_del && !is_indel) continue; + ++ori_depth; + if (is_indel) + { + b = p->aux>>16&0x3f; + baseQ = q = p->aux&0xff; + // This read is not counted as indel. Instead of skipping it, treat it as ref. It is + // still only an approximation, but gives more accurate AD counts and calls correctly + // hets instead of alt-homs in some cases (see test/mpileup/indel-AD.1.sam) + if ( q < bca->min_baseQ ) b = 0, q = (int)bam_get_qual(p->b)[p->qpos]; + seqQ = p->aux>>8&0xff; + is_diff = (b != 0); + } + else + { + b = bam_seqi(bam_get_seq(p->b), p->qpos); // base + b = seq_nt16_int[b? b : ref_base]; // b is the 2-bit base + baseQ = q = (int)bam_get_qual(p->b)[p->qpos]; + if (q < bca->min_baseQ) continue; + seqQ = 99; + is_diff = (ref4 < 4 && b == ref4)? 0 : 1; + } + mapQ = p->b->core.qual < 255? p->b->core.qual : DEF_MAPQ; // special case for mapQ==255 + if ( !mapQ ) r->mq0++; + if (q > seqQ) q = seqQ; + mapQ = mapQ < bca->capQ? mapQ : bca->capQ; + if (q > mapQ) q = mapQ; + if (q > 63) q = 63; + if (q < 4) q = 4; // MQ=0 reads count as BQ=4 + bca->bases[n++] = q<<5 | (int)bam_is_rev(p->b)<<4 | b; + // collect annotations + if (b < 4) + { + r->qsum[b] += q; + if ( r->ADF ) + { + if ( bam_is_rev(p->b) ) + r->ADR[b]++; + else + r->ADF[b]++; + } + } + ++r->anno[0<<2|is_diff<<1|bam_is_rev(p->b)]; + min_dist = p->b->core.l_qseq - 1 - p->qpos; + if (min_dist > p->qpos) min_dist = p->qpos; + if (min_dist > CAP_DIST) min_dist = CAP_DIST; + r->anno[1<<2|is_diff<<1|0] += baseQ; + r->anno[1<<2|is_diff<<1|1] += baseQ * baseQ; + r->anno[2<<2|is_diff<<1|0] += mapQ; + r->anno[2<<2|is_diff<<1|1] += mapQ * mapQ; + r->anno[3<<2|is_diff<<1|0] += min_dist; + r->anno[3<<2|is_diff<<1|1] += min_dist * min_dist; + + // collect for bias tests + if ( baseQ > 59 ) baseQ = 59; + if ( mapQ > 59 ) mapQ = 59; + int len, pos = get_position(p, &len); + int epos = (double)pos/(len+1) * bca->npos; + int ibq = baseQ/60. * bca->nqual; + int imq = mapQ/60. * bca->nqual; + if ( bam_is_rev(p->b) ) bca->rev_mqs[imq]++; + else bca->fwd_mqs[imq]++; + if ( bam_seqi(bam_get_seq(p->b),p->qpos) == ref_base ) + { + bca->ref_pos[epos]++; + bca->ref_bq[ibq]++; + bca->ref_mq[imq]++; + } + else + { + bca->alt_pos[epos]++; + bca->alt_bq[ibq]++; + bca->alt_mq[imq]++; + } + } + r->ori_depth = ori_depth; + // glfgen + errmod_cal(bca->e, n, 5, bca->bases, r->p); // calculate PL of each genotype + return n; +} + + +/* + * calc_vdb() - returns value between zero (most biased) and one (no bias) + * on success, or HUGE_VAL when VDB cannot be calculated because + * of insufficient depth (<2x) + * + * Variant Distance Bias tests if the variant bases are positioned within the + * reads with sufficient randomness. Unlike other tests, it looks only at + * variant reads and therefore gives different kind of information than Read + * Position Bias for instance. VDB was developed for detecting artefacts in + * RNA-seq calls where reads from spliced transcripts span splice site + * boundaries. The current implementation differs somewhat from the original + * version described in supplementary material of PMID:22524474, but the idea + * remains the same. (Here the random variable tested is the average distance + * from the averaged position, not the average pairwise distance.) + * + * For coverage of 2x, the calculation is exact but is approximated for the + * rest. The result is most accurate between 4-200x. For 3x or >200x, the + * reported values are slightly more favourable than those of a true random + * distribution. + */ +double calc_vdb(int *pos, int npos) +{ + // Note well: the parameters were obtained by fitting to simulated data of + // 100bp reads. This assumes rescaling to 100bp in bcf_call_glfgen(). + const int readlen = 100; + assert( npos==readlen ); + + #define nparam 15 + const float param[nparam][3] = { {3,0.079,18}, {4,0.09,19.8}, {5,0.1,20.5}, {6,0.11,21.5}, + {7,0.125,21.6}, {8,0.135,22}, {9,0.14,22.2}, {10,0.153,22.3}, {15,0.19,22.8}, + {20,0.22,23.2}, {30,0.26,23.4}, {40,0.29,23.5}, {50,0.35,23.65}, {100,0.5,23.7}, + {200,0.7,23.7} }; + + int i, dp = 0; + float mean_pos = 0, mean_diff = 0; + for (i=0; i=200 ) + i = nparam; // shortcut for big depths + else + { + for (i=0; i=dp ) break; + } + float pshift, pscale; + if ( i==nparam ) + { + // the depth is too high, go with 200x + pscale = param[nparam-1][1]; + pshift = param[nparam-1][2]; + } + else if ( i>0 && param[i][0]!=dp ) + { + // linear interpolation of parameters + pscale = (param[i-1][1] + param[i][1])*0.5; + pshift = (param[i-1][2] + param[i][2])*0.5; + } + else + { + pscale = param[i][1]; + pshift = param[i][2]; + } + return 0.5*kf_erfc(-(mean_diff-pshift)*pscale); +} + +double calc_chisq_bias(int *a, int *b, int n) +{ + int na = 0, nb = 0, i, ndf = n; + for (i=0; i= 2 && m >= 2); + + return (n < 8 && m < 8 && U < 50) + ? mw[n-2][m-2][U] + : mann_whitney_1947_(n,m,U); +} + +double mann_whitney_1947_cdf(int n, int m, int U) +{ + int i; + double sum = 0; + for (i=0; i<=U; i++) + sum += mann_whitney_1947(n,m,i); + return sum; +} + +double calc_mwu_bias_cdf(int *a, int *b, int n) +{ + int na = 0, nb = 0, i; + double U = 0, ties = 0; + for (i=0; i=8 && nb>=8 and reasonable if na<8 or nb<8 + if ( na>=8 || nb>=8 ) + { + double mean = ((double)na*nb)*0.5; + // Correction for ties: + // double N = na+nb; + // double var2 = (N*N-1)*N-ties; + // if ( var2==0 ) return 1.0; + // var2 *= ((double)na*nb)/N/(N-1)/12.0; + // No correction for ties: + double var2 = ((double)na*nb)*(na+nb+1)/12.0; + double z = (U_min - mean)/sqrt(2*var2); // z is N(0,1) + return 2.0 - kf_erfc(z); // which is 1 + erf(z) + } + + // Exact calculation + double pval = 2*mann_whitney_1947_cdf(na,nb,U_min); + return pval>1 ? 1 : pval; +} + +double calc_mwu_bias(int *a, int *b, int n) +{ + int na = 0, nb = 0, i; + double U = 0, ties = 0; + for (i=0; imean ? (2.0*mean-U)/mean : U/mean; + } + // Correction for ties: + // double N = na+nb; + // double var2 = (N*N-1)*N-ties; + // if ( var2==0 ) return 1.0; + // var2 *= ((double)na*nb)/N/(N-1)/12.0; + // No correction for ties: + double var2 = ((double)na*nb)*(na+nb+1)/12.0; + if ( na>=8 || nb>=8 ) + { + // Normal approximation, very good for na>=8 && nb>=8 and reasonable if na<8 or nb<8 + return exp(-0.5*(U-mean)*(U-mean)/var2); + } + + // Exact calculation + return mann_whitney_1947(na,nb,U) * sqrt(2*M_PI*var2); +} + +static inline double logsumexp2(double a, double b) +{ + if ( a>b ) + return log(1 + exp(b-a)) + a; + else + return log(1 + exp(a-b)) + b; +} + +void calc_SegBias(const bcf_callret1_t *bcr, bcf_call_t *call) +{ + call->seg_bias = HUGE_VAL; + if ( !bcr ) return; + + int nr = call->anno[2] + call->anno[3]; // number of observed non-reference reads + if ( !nr ) return; + + int avg_dp = (call->anno[0] + call->anno[1] + nr) / call->n; // average depth + double M = floor((double)nr / avg_dp + 0.5); // an approximate number of variants samples in the population + if ( M>call->n ) M = call->n; // clamp M at the number of samples + else if ( M==0 ) M = 1; + double f = M / 2. / call->n; // allele frequency + double p = (double) nr / call->n; // number of variant reads per sample expected if variant not real (poisson) + double q = (double) nr / M; // number of variant reads per sample expected if variant is real (poisson) + double sum = 0; + const double log2 = log(2.0); + + // fprintf(bcftools_stderr,"M=%.1f p=%e q=%e f=%f dp=%d\n",M,p,q,f,avg_dp); + int i; + for (i=0; in; i++) + { + int oi = bcr[i].anno[2] + bcr[i].anno[3]; // observed number of non-ref reads + double tmp; + if ( oi ) + { + // tmp = log(f) + oi*log(q/p) - q + log(2*(1-f) + f*pow(2,oi)*exp(-q)) + p; // this can under/overflow + tmp = logsumexp2(log(2*(1-f)), log(f) + oi*log2 - q); + tmp += log(f) + oi*log(q/p) - q + p; + } + else + tmp = log(2*f*(1-f)*exp(-q) + f*f*exp(-2*q) + (1-f)*(1-f)) + p; + sum += tmp; + // fprintf(bcftools_stderr,"oi=%d %e\n", oi,tmp); + } + call->seg_bias = sum; +} + +/** + * bcf_call_combine() - sets the PL array and VDB, RPB annotations, finds the top two alleles + * @n: number of samples + * @calls: each sample's calls + * @bca: auxiliary data structure for holding temporary values + * @ref_base: the reference base + * @call: filled with the annotations + * + * Combines calls across the various samples being studied + * 1. For each allele at each base across all samples the quality is summed so + * you end up with a set of quality sums for each allele present 2. The quality + * sums are sorted. + * 3. Using the sorted quality sums we now create the allele ordering array + * A\subN. This is done by doing the following: + * a) If the reference allele is known it always comes first, otherwise N + * comes first. + * b) Then the rest of the alleles are output in descending order of quality + * sum (which we already know the qsum array was sorted). Any allelles with + * qsum 0 will be excluded. + * 4. Using the allele ordering array we create the genotype ordering array. + * In the worst case with an unknown reference this will be: A0/A0 A1/A0 A1/A1 + * A2/A0 A2/A1 A2/A2 A3/A0 A3/A1 A3/A2 A3/A3 A4/A0 A4/A1 A4/A2 A4/A3 A4/A4 + * 5. The genotype ordering array is then used to extract data from the error + * model 5*5 matrix and is used to produce a Phread likelihood array for each + * sample. + */ +int bcf_call_combine(int n, const bcf_callret1_t *calls, bcf_callaux_t *bca, int ref_base /*4-bit*/, bcf_call_t *call) +{ + int ref4, i, j; + float qsum[5] = {0,0,0,0,0}; + if (ref_base >= 0) { + call->ori_ref = ref4 = seq_nt16_int[ref_base]; + if (ref4 > 4) ref4 = 4; + } else call->ori_ref = -1, ref4 = 0; + + // calculate qsum, this is done by summing normalized qsum across all samples, + // to account for differences in coverage + for (i = 0; i < n; ++i) + { + float sum = 0; + for (j = 0; j < 4; ++j) sum += calls[i].qsum[j]; + if ( sum ) + for (j = 0; j < 4; j++) qsum[j] += calls[i].qsum[j] / sum; + } + + // sort qsum in ascending order (insertion sort) + float *ptr[5], *tmp; + for (i=0; i<5; i++) ptr[i] = &qsum[i]; + for (i=1; i<4; i++) + for (j=i; j>0 && *ptr[j] < *ptr[j-1]; j--) + tmp = ptr[j], ptr[j] = ptr[j-1], ptr[j-1] = tmp; + + // Set the reference allele and alternative allele(s) + for (i=0; i<5; i++) call->a[i] = -1; + for (i=0; i<5; i++) call->qsum[i] = 0; + call->unseen = -1; + call->a[0] = ref4; + for (i=3, j=1; i>=0; i--) // i: alleles sorted by QS; j, a[j]: output allele ordering + { + int ipos = ptr[i] - qsum; // position in sorted qsum array + if ( ipos==ref4 ) + call->qsum[0] = qsum[ipos]; // REF's qsum + else + { + if ( !qsum[ipos] ) break; // qsum is 0, this and consequent alleles are not seen in the pileup + call->qsum[j] = qsum[ipos]; + call->a[j++] = ipos; + } + } + if (ref_base >= 0) + { + // for SNPs, find the "unseen" base + if (((ref4 < 4 && j < 4) || (ref4 == 4 && j < 5)) && i >= 0) + call->unseen = j, call->a[j++] = ptr[i] - qsum; + call->n_alleles = j; + } + else + { + call->n_alleles = j; + if (call->n_alleles == 1) return -1; // no reliable supporting read. stop doing anything + } + /* + * Set the phread likelihood array (call->PL) This array is 15 entries long + * for each sample because that is size of an upper or lower triangle of a + * worst case 5x5 matrix of possible genotypes. This worst case matrix will + * occur when all 4 possible alleles are present and the reference allele + * is unknown. The sides of the matrix will correspond to the reference + * allele (if known) followed by the alleles present in descending order of + * quality sum + */ + { + int x, g[15], z; + double sum_min = 0.; + x = call->n_alleles * (call->n_alleles + 1) / 2; + // get the possible genotypes + // this is done by creating an ordered list of locations g for call (allele a, allele b) in the genotype likelihood matrix + for (i = z = 0; i < call->n_alleles; ++i) { + for (j = 0; j <= i; ++j) { + g[z++] = call->a[j] * 5 + call->a[i]; + } + } + // for each sample calculate the PL + for (i = 0; i < n; ++i) + { + int32_t *PL = call->PL + x * i; + const bcf_callret1_t *r = calls + i; + float min = FLT_MAX; + for (j = 0; j < x; ++j) { + if (min > r->p[g[j]]) min = r->p[g[j]]; + } + sum_min += min; + for (j = 0; j < x; ++j) { + int y; + y = (int)(r->p[g[j]] - min + .499); + if (y > 255) y = 255; + PL[j] = y; + } + } + if ( call->DP4 ) + { + for (i=0; iDP4[4*i] = calls[i].anno[0]; + call->DP4[4*i+1] = calls[i].anno[1]; + call->DP4[4*i+2] = calls[i].anno[2]; + call->DP4[4*i+3] = calls[i].anno[3]; + } + } + if ( call->ADF ) + { + assert( call->n_alleles<=B2B_MAX_ALLELES ); // this is always true for SNPs and so far for indels as well + + // reorder ADR,ADF to match the allele ordering at this site + int32_t tmp[B2B_MAX_ALLELES]; + int32_t *adr = call->ADR + B2B_MAX_ALLELES, *adr_out = call->ADR + B2B_MAX_ALLELES; + int32_t *adf = call->ADF + B2B_MAX_ALLELES, *adf_out = call->ADF + B2B_MAX_ALLELES; + int32_t *adr_tot = call->ADR; // the first bin stores total counts per site + int32_t *adf_tot = call->ADF; + for (i=0; in_alleles; j++) + { + tmp[j] = adr[ call->a[j] ]; + adr_tot[j] += tmp[j]; + } + for (j=0; jn_alleles; j++) adr_out[j] = tmp[j]; + for (j=0; jn_alleles; j++) + { + tmp[j] = adf[ call->a[j] ]; + adf_tot[j] += tmp[j]; + } + for (j=0; jn_alleles; j++) adf_out[j] = tmp[j]; + adf_out += call->n_alleles; + adr_out += call->n_alleles; + adr += B2B_MAX_ALLELES; + adf += B2B_MAX_ALLELES; + } + } + +// if (ref_base < 0) fprintf(bcftools_stderr, "%d,%d,%f,%d\n", call->n_alleles, x, sum_min, call->unseen); + call->shift = (int)(sum_min + .499); + } + // combine annotations + memset(call->anno, 0, 16 * sizeof(double)); + call->ori_depth = 0; + call->depth = 0; + call->mq0 = 0; + for (i = 0; i < n; ++i) { + call->depth += calls[i].anno[0] + calls[i].anno[1] + calls[i].anno[2] + calls[i].anno[3]; + call->ori_depth += calls[i].ori_depth; + call->mq0 += calls[i].mq0; + for (j = 0; j < 16; ++j) call->anno[j] += calls[i].anno[j]; + } + + calc_SegBias(calls, call); + + // calc_chisq_bias("XPOS", call->bcf_hdr->id[BCF_DT_CTG][call->tid].key, call->pos, bca->ref_pos, bca->alt_pos, bca->npos); + // calc_chisq_bias("XMQ", call->bcf_hdr->id[BCF_DT_CTG][call->tid].key, call->pos, bca->ref_mq, bca->alt_mq, bca->nqual); + // calc_chisq_bias("XBQ", call->bcf_hdr->id[BCF_DT_CTG][call->tid].key, call->pos, bca->ref_bq, bca->alt_bq, bca->nqual); + + call->mwu_pos = calc_mwu_bias(bca->ref_pos, bca->alt_pos, bca->npos); + call->mwu_mq = calc_mwu_bias(bca->ref_mq, bca->alt_mq, bca->nqual); + call->mwu_bq = calc_mwu_bias(bca->ref_bq, bca->alt_bq, bca->nqual); + call->mwu_mqs = calc_mwu_bias(bca->fwd_mqs, bca->rev_mqs, bca->nqual); + +#if CDF_MWU_TESTS + call->mwu_pos_cdf = calc_mwu_bias_cdf(bca->ref_pos, bca->alt_pos, bca->npos); + call->mwu_mq_cdf = calc_mwu_bias_cdf(bca->ref_mq, bca->alt_mq, bca->nqual); + call->mwu_bq_cdf = calc_mwu_bias_cdf(bca->ref_bq, bca->alt_bq, bca->nqual); + call->mwu_mqs_cdf = calc_mwu_bias_cdf(bca->fwd_mqs, bca->rev_mqs, bca->nqual); +#endif + + call->vdb = calc_vdb(bca->alt_pos, bca->npos); + + return 0; +} + +int bcf_call2bcf(bcf_call_t *bc, bcf1_t *rec, bcf_callret1_t *bcr, int fmt_flag, const bcf_callaux_t *bca, const char *ref) +{ + extern double kt_fisher_exact(int n11, int n12, int n21, int n22, double *_left, double *_right, double *two); + int i, j, nals = 1; + + bcf_hdr_t *hdr = bc->bcf_hdr; + rec->rid = bc->tid; + rec->pos = bc->pos; + rec->qual = 0; + + bc->tmp.l = 0; + if (bc->ori_ref < 0) // indel + { + // REF + kputc(ref[bc->pos], &bc->tmp); + for (j = 0; j < bca->indelreg; ++j) kputc(ref[bc->pos+1+j], &bc->tmp); + + // ALT + for (i=1; i<4; i++) + { + if (bc->a[i] < 0) break; + kputc(',', &bc->tmp); kputc(ref[bc->pos], &bc->tmp); + + if (bca->indel_types[bc->a[i]] < 0) { // deletion + for (j = -bca->indel_types[bc->a[i]]; j < bca->indelreg; ++j) + kputc(ref[bc->pos+1+j], &bc->tmp); + } else { // insertion; cannot be a reference unless a bug + char *inscns = &bca->inscns[bc->a[i] * bca->maxins]; + for (j = 0; j < bca->indel_types[bc->a[i]]; ++j) + kputc("ACGTN"[(int)inscns[j]], &bc->tmp); + for (j = 0; j < bca->indelreg; ++j) kputc(ref[bc->pos+1+j], &bc->tmp); + } + nals++; + } + } + else // SNP + { + kputc("ACGTN"[bc->ori_ref], &bc->tmp); + for (i=1; i<5; i++) + { + if (bc->a[i] < 0) break; + kputc(',', &bc->tmp); + if ( bc->unseen==i ) kputs("<*>", &bc->tmp); + else kputc("ACGT"[bc->a[i]], &bc->tmp); + nals++; + } + } + bcf_update_alleles_str(hdr, rec, bc->tmp.s); + + bc->tmp.l = 0; + + // INFO + if (bc->ori_ref < 0) + { + bcf_update_info_flag(hdr, rec, "INDEL", NULL, 1); + bcf_update_info_int32(hdr, rec, "IDV", &bca->max_support, 1); + bcf_update_info_float(hdr, rec, "IMF", &bca->max_frac, 1); + } + bcf_update_info_int32(hdr, rec, "DP", &bc->ori_depth, 1); + if ( fmt_flag&B2B_INFO_ADF ) + bcf_update_info_int32(hdr, rec, "ADF", bc->ADF, rec->n_allele); + if ( fmt_flag&B2B_INFO_ADR ) + bcf_update_info_int32(hdr, rec, "ADR", bc->ADR, rec->n_allele); + if ( fmt_flag&(B2B_INFO_AD|B2B_INFO_DPR) ) + { + for (i=0; in_allele; i++) bc->ADF[i] += bc->ADR[i]; + if ( fmt_flag&B2B_INFO_AD ) + bcf_update_info_int32(hdr, rec, "AD", bc->ADF, rec->n_allele); + if ( fmt_flag&B2B_INFO_DPR ) + bcf_update_info_int32(hdr, rec, "DPR", bc->ADF, rec->n_allele); + } + + float tmpf[16]; + for (i=0; i<16; i++) tmpf[i] = bc->anno[i]; + bcf_update_info_float(hdr, rec, "I16", tmpf, 16); + bcf_update_info_float(hdr, rec, "QS", bc->qsum, nals); + + if ( bc->vdb != HUGE_VAL ) bcf_update_info_float(hdr, rec, "VDB", &bc->vdb, 1); + if ( bc->seg_bias != HUGE_VAL ) bcf_update_info_float(hdr, rec, "SGB", &bc->seg_bias, 1); + if ( bc->mwu_pos != HUGE_VAL ) bcf_update_info_float(hdr, rec, "RPB", &bc->mwu_pos, 1); + if ( bc->mwu_mq != HUGE_VAL ) bcf_update_info_float(hdr, rec, "MQB", &bc->mwu_mq, 1); + if ( bc->mwu_mqs != HUGE_VAL ) bcf_update_info_float(hdr, rec, "MQSB", &bc->mwu_mqs, 1); + if ( bc->mwu_bq != HUGE_VAL ) bcf_update_info_float(hdr, rec, "BQB", &bc->mwu_bq, 1); +#if CDF_MWU_TESTS + if ( bc->mwu_pos_cdf != HUGE_VAL ) bcf_update_info_float(hdr, rec, "RPB2", &bc->mwu_pos_cdf, 1); + if ( bc->mwu_mq_cdf != HUGE_VAL ) bcf_update_info_float(hdr, rec, "MQB2", &bc->mwu_mq_cdf, 1); + if ( bc->mwu_mqs_cdf != HUGE_VAL ) bcf_update_info_float(hdr, rec, "MQSB2", &bc->mwu_mqs_cdf, 1); + if ( bc->mwu_bq_cdf != HUGE_VAL ) bcf_update_info_float(hdr, rec, "BQB2", &bc->mwu_bq_cdf, 1); +#endif + tmpf[0] = bc->ori_depth ? (float)bc->mq0/bc->ori_depth : 0; + bcf_update_info_float(hdr, rec, "MQ0F", tmpf, 1); + + // FORMAT + rec->n_sample = bc->n; + bcf_update_format_int32(hdr, rec, "PL", bc->PL, nals*(nals+1)/2 * rec->n_sample); + if ( fmt_flag&B2B_FMT_DP ) + { + int32_t *ptr = (int32_t*) bc->fmt_arr; + for (i=0; in; i++) + ptr[i] = bc->DP4[4*i] + bc->DP4[4*i+1] + bc->DP4[4*i+2] + bc->DP4[4*i+3]; + bcf_update_format_int32(hdr, rec, "DP", bc->fmt_arr, rec->n_sample); + } + if ( fmt_flag&B2B_FMT_DV ) + { + int32_t *ptr = (int32_t*) bc->fmt_arr; + for (i=0; in; i++) + ptr[i] = bc->DP4[4*i+2] + bc->DP4[4*i+3]; + bcf_update_format_int32(hdr, rec, "DV", bc->fmt_arr, rec->n_sample); + } + if ( fmt_flag&B2B_FMT_SP ) + { + int32_t *ptr = (int32_t*) bc->fmt_arr; + for (i=0; in; i++) + { + int fwd_ref = bc->DP4[4*i], rev_ref = bc->DP4[4*i+1], fwd_alt = bc->DP4[4*i+2], rev_alt = bc->DP4[4*i+3]; + if ( fwd_ref+rev_ref<2 || fwd_alt+rev_alt<2 || fwd_ref+fwd_alt<2 || rev_ref+rev_alt<2 ) + ptr[i] = 0; + else + { + double left, right, two; + kt_fisher_exact(fwd_ref, rev_ref, fwd_alt, rev_alt, &left, &right, &two); + int32_t x = (int)(-4.343 * log(two) + .499); + if (x > 255) x = 255; + ptr[i] = x; + } + } + bcf_update_format_int32(hdr, rec, "SP", bc->fmt_arr, rec->n_sample); + } + if ( fmt_flag&B2B_FMT_DP4 ) + bcf_update_format_int32(hdr, rec, "DP4", bc->DP4, rec->n_sample*4); + if ( fmt_flag&B2B_FMT_ADF ) + bcf_update_format_int32(hdr, rec, "ADF", bc->ADF+B2B_MAX_ALLELES, rec->n_sample*rec->n_allele); + if ( fmt_flag&B2B_FMT_ADR ) + bcf_update_format_int32(hdr, rec, "ADR", bc->ADR+B2B_MAX_ALLELES, rec->n_sample*rec->n_allele); + if ( fmt_flag&(B2B_FMT_AD|B2B_FMT_DPR) ) + { + for (i=0; in_sample*rec->n_allele; i++) bc->ADF[B2B_MAX_ALLELES+i] += bc->ADR[B2B_MAX_ALLELES+i]; + if ( fmt_flag&B2B_FMT_AD ) + bcf_update_format_int32(hdr, rec, "AD", bc->ADF+B2B_MAX_ALLELES, rec->n_sample*rec->n_allele); + if ( fmt_flag&B2B_FMT_DPR ) + bcf_update_format_int32(hdr, rec, "DPR", bc->ADF+B2B_MAX_ALLELES, rec->n_sample*rec->n_allele); + } + + return 0; +} diff --git a/bcftools/bam2bcf.h b/bcftools/bam2bcf.h new file mode 100644 index 000000000..f81f9cf02 --- /dev/null +++ b/bcftools/bam2bcf.h @@ -0,0 +1,138 @@ +/* bam2bcf.h -- variant calling. + + Copyright (C) 2010-2012 Broad Institute. + Copyright (C) 2012-2014,2016 Genome Research Ltd. + + Author: Heng Li + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#ifndef BAM2BCF_H +#define BAM2BCF_H + +#include +#include +#include + +/** + * A simplified version of Mann-Whitney U-test is calculated + * by default (no CDF) because it is faster and seems to work + * better in machine learning filtering. When enabled by setting + * CDF_MWU_TESTS, additional annotations will appear on mpileup's + * output (RPB2 in addition to RPB, etc.). + */ +#ifndef CDF_MWU_TESTS +#define CDF_MWU_TESTS 0 +#endif + +#define B2B_INDEL_NULL 10000 + +#define B2B_FMT_DP (1<<0) +#define B2B_FMT_SP (1<<1) +#define B2B_FMT_DV (1<<2) +#define B2B_FMT_DP4 (1<<3) +#define B2B_FMT_DPR (1<<4) +#define B2B_INFO_DPR (1<<5) +#define B2B_FMT_AD (1<<6) +#define B2B_FMT_ADF (1<<7) +#define B2B_FMT_ADR (1<<8) +#define B2B_INFO_AD (1<<9) +#define B2B_INFO_ADF (1<<10) +#define B2B_INFO_ADR (1<<11) + +#define B2B_MAX_ALLELES 5 + +typedef struct __bcf_callaux_t { + int capQ, min_baseQ; + int openQ, extQ, tandemQ; // for indels + uint32_t min_support, max_support; // for collecting indel candidates + double min_frac; // for collecting indel candidates + float max_frac; // for collecting indel candidates + int per_sample_flt; // indel filtering strategy + int *ref_pos, *alt_pos, npos, *ref_mq, *alt_mq, *ref_bq, *alt_bq, *fwd_mqs, *rev_mqs, nqual; // for bias tests + // for internal uses + int max_bases; + int indel_types[4]; // indel lengths + int maxins, indelreg; + int read_len; + char *inscns; + uint16_t *bases; // 5bit: unused, 6:quality, 1:is_rev, 4:2-bit base or indel allele (index to bcf_callaux_t.indel_types) + errmod_t *e; + void *rghash; +} bcf_callaux_t; + +typedef struct { + uint32_t ori_depth; + unsigned int mq0; + int32_t *ADF, *ADR; + float qsum[4]; + // The fields are: + // depth fwd .. ref (0) and non-ref (2) + // depth rev .. ref (1) and non-ref (3) + // baseQ .. ref (4) and non-ref (6) + // baseQ^2 .. ref (5) and non-ref (7) + // mapQ .. ref (8) and non-ref (10) + // mapQ^2 .. ref (9) and non-ref (11) + // minDist .. ref (12) and non-ref (14) + // minDist^2 .. ref (13) and non-ref (15) + // Note that this probably needs a more thorough fix: int types in + // bcf_call_t do overflow with high-coverage data, such as exomes, and + // BCFv2 supports only floats which may not suffice. + double anno[16]; + float p[25]; // phred-scaled likelihood of each genotype +} bcf_callret1_t; + +typedef struct { + int tid, pos; + bcf_hdr_t *bcf_hdr; + int a[5]; // alleles: ref, alt, alt2, alt3 + float qsum[5]; // for the QS tag + int n, n_alleles, shift, ori_ref, unseen; + int n_supp; // number of supporting non-reference reads + double anno[16]; + unsigned int depth, ori_depth, mq0; + int32_t *PL, *DP4, *ADR, *ADF; + uint8_t *fmt_arr; + float vdb; // variant distance bias + float mwu_pos, mwu_mq, mwu_bq, mwu_mqs; +#if CDF_MWU_TESTS + float mwu_pos_cdf, mwu_mq_cdf, mwu_bq_cdf, mwu_mqs_cdf; +#endif + float seg_bias; + kstring_t tmp; +} bcf_call_t; + +#ifdef __cplusplus +extern "C" { +#endif + + bcf_callaux_t *bcf_call_init(double theta, int min_baseQ); + void bcf_call_destroy(bcf_callaux_t *bca); + int bcf_call_glfgen(int _n, const bam_pileup1_t *pl, int ref_base, bcf_callaux_t *bca, bcf_callret1_t *r); + int bcf_call_combine(int n, const bcf_callret1_t *calls, bcf_callaux_t *bca, int ref_base /*4-bit*/, bcf_call_t *call); + int bcf_call2bcf(bcf_call_t *bc, bcf1_t *b, bcf_callret1_t *bcr, int fmt_flag, + const bcf_callaux_t *bca, const char *ref); + int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_callaux_t *bca, const char *ref); + void bcf_callaux_clean(bcf_callaux_t *bca, bcf_call_t *call); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/bcftools/bam2bcf_indel.c b/bcftools/bam2bcf_indel.c new file mode 100644 index 000000000..6c367da73 --- /dev/null +++ b/bcftools/bam2bcf_indel.c @@ -0,0 +1,470 @@ +/* bam2bcf_indel.c -- indel caller. + + Copyright (C) 2010, 2011 Broad Institute. + Copyright (C) 2012-2014,2016 Genome Research Ltd. + + Author: Heng Li + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include +#include +#include +#include +#include +#include +#include "bam2bcf.h" + +#include +KSORT_INIT_GENERIC(uint32_t) + +#define MINUS_CONST 0x10000000 +#define INDEL_WINDOW_SIZE 50 + +static int tpos2qpos(const bam1_core_t *c, const uint32_t *cigar, int32_t tpos, int is_left, int32_t *_tpos) +{ + int k, x = c->pos, y = 0, last_y = 0; + *_tpos = c->pos; + for (k = 0; k < c->n_cigar; ++k) { + int op = cigar[k] & BAM_CIGAR_MASK; + int l = cigar[k] >> BAM_CIGAR_SHIFT; + if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { + if (c->pos > tpos) return y; + if (x + l > tpos) { + *_tpos = tpos; + return y + (tpos - x); + } + x += l; y += l; + last_y = y; + } else if (op == BAM_CINS || op == BAM_CSOFT_CLIP) y += l; + else if (op == BAM_CDEL || op == BAM_CREF_SKIP) { + if (x + l > tpos) { + *_tpos = is_left? x : x + l; + return y; + } + x += l; + } + } + *_tpos = x; + return last_y; +} +// FIXME: check if the inserted sequence is consistent with the homopolymer run +// l is the relative gap length and l_run is the length of the homopolymer on the reference +static inline int est_seqQ(const bcf_callaux_t *bca, int l, int l_run) +{ + int q, qh; + q = bca->openQ + bca->extQ * (abs(l) - 1); + qh = l_run >= 3? (int)(bca->tandemQ * (double)abs(l) / l_run + .499) : 1000; + return q < qh? q : qh; +} + +static inline int est_indelreg(int pos, const char *ref, int l, char *ins4) +{ + int i, j, max = 0, max_i = pos, score = 0; + l = abs(l); + for (i = pos + 1, j = 0; ref[i]; ++i, ++j) { + if (ins4) score += (toupper(ref[i]) != "ACGTN"[(int)ins4[j%l]])? -10 : 1; + else score += (toupper(ref[i]) != toupper(ref[pos+1+j%l]))? -10 : 1; + if (score < 0) break; + if (max < score) max = score, max_i = i; + } + return max_i - pos; +} + +/* + notes: + - n .. number of samples + - the routine sets bam_pileup1_t.aux of each read as follows: + - 6: unused + - 6: the call; index to bcf_callaux_t.indel_types .. (aux>>16)&0x3f + - 8: estimated sequence quality .. (aux>>8)&0xff + - 8: indel quality .. aux&0xff + */ +int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_callaux_t *bca, const char *ref) +{ + int i, s, j, k, t, n_types, *types, max_rd_len, left, right, max_ins, *score1, *score2, max_ref2; + int N, K, l_run, ref_type, n_alt; + char *inscns = 0, *ref2, *query, **ref_sample; + if (ref == 0 || bca == 0) return -1; + + // determine if there is a gap + for (s = N = 0; s < n; ++s) { + for (i = 0; i < n_plp[s]; ++i) + if (plp[s][i].indel != 0) break; + if (i < n_plp[s]) break; + } + if (s == n) return -1; // there is no indel at this position. + for (s = N = 0; s < n; ++s) N += n_plp[s]; // N is the total number of reads + { // find out how many types of indels are present + bca->max_support = bca->max_frac = 0; + int m, n_alt = 0, n_tot = 0, indel_support_ok = 0; + uint32_t *aux; + aux = (uint32_t*) calloc(N + 1, 4); + m = max_rd_len = 0; + aux[m++] = MINUS_CONST; // zero indel is always a type + for (s = 0; s < n; ++s) { + int na = 0, nt = 0; + for (i = 0; i < n_plp[s]; ++i) { + const bam_pileup1_t *p = plp[s] + i; + ++nt; + if (p->indel != 0) { + ++na; + aux[m++] = MINUS_CONST + p->indel; + } + j = bam_cigar2qlen(p->b->core.n_cigar, bam_get_cigar(p->b)); + if (j > max_rd_len) max_rd_len = j; + } + double frac = (double)na/nt; + if ( !indel_support_ok && na >= bca->min_support && frac >= bca->min_frac ) + indel_support_ok = 1; + if ( na > bca->max_support && frac > 0 ) bca->max_support = na, bca->max_frac = frac; + n_alt += na; + n_tot += nt; + } + // To prevent long stretches of N's to be mistaken for indels (sometimes thousands of bases), + // check the number of N's in the sequence and skip places where half or more reference bases are Ns. + int nN=0; for (i=pos; i-pos(i-pos) ) { free(aux); return -1; } + + ks_introsort(uint32_t, m, aux); + // squeeze out identical types + for (i = 1, n_types = 1; i < m; ++i) + if (aux[i] != aux[i-1]) ++n_types; + // Taking totals makes it hard to call rare indels + if ( !bca->per_sample_flt ) + indel_support_ok = ( (double)n_alt / n_tot < bca->min_frac || n_alt < bca->min_support ) ? 0 : 1; + if ( n_types == 1 || !indel_support_ok ) { // then skip + free(aux); return -1; + } + if (n_types >= 64) { + free(aux); + // TODO revisit how/whether to control printing this warning + if (hts_verbose >= 2) + fprintf(stderr, "[%s] excessive INDEL alleles at position %d. Skip the position.\n", __func__, pos + 1); + return -1; + } + types = (int*)calloc(n_types, sizeof(int)); + t = 0; + types[t++] = aux[0] - MINUS_CONST; + for (i = 1; i < m; ++i) + if (aux[i] != aux[i-1]) + types[t++] = aux[i] - MINUS_CONST; + free(aux); + for (t = 0; t < n_types; ++t) + if (types[t] == 0) break; + ref_type = t; // the index of the reference type (0) + } + { // calculate left and right boundary + left = pos > INDEL_WINDOW_SIZE? pos - INDEL_WINDOW_SIZE : 0; + right = pos + INDEL_WINDOW_SIZE; + if (types[0] < 0) right -= types[0]; + // in case the alignments stand out the reference + for (i = pos; i < right; ++i) + if (ref[i] == 0) break; + right = i; + } + /* The following block fixes a long-existing flaw in the INDEL + * calling model: the interference of nearby SNPs. However, it also + * reduces the power because sometimes, substitutions caused by + * indels are not distinguishable from true mutations. Multiple + * sequence realignment helps to increase the power. + * + * Masks mismatches present in at least 70% of the reads with 'N'. + */ + { // construct per-sample consensus + int L = right - left + 1, max_i, max2_i; + uint32_t *cns, max, max2; + char *ref0, *r; + ref_sample = (char**) calloc(n, sizeof(char*)); + cns = (uint32_t*) calloc(L, 4); + ref0 = (char*) calloc(L, 1); + for (i = 0; i < right - left; ++i) + ref0[i] = seq_nt16_table[(int)ref[i+left]]; + for (s = 0; s < n; ++s) { + r = ref_sample[s] = (char*) calloc(L, 1); + memset(cns, 0, sizeof(int) * L); + // collect ref and non-ref counts + for (i = 0; i < n_plp[s]; ++i) { + bam_pileup1_t *p = plp[s] + i; + bam1_t *b = p->b; + uint32_t *cigar = bam_get_cigar(b); + uint8_t *seq = bam_get_seq(b); + int x = b->core.pos, y = 0; + for (k = 0; k < b->core.n_cigar; ++k) { + int op = cigar[k]&0xf; + int j, l = cigar[k]>>4; + if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { + for (j = 0; j < l; ++j) + if (x + j >= left && x + j < right) + cns[x+j-left] += (bam_seqi(seq, y+j) == ref0[x+j-left])? 1 : 0x10000; + x += l; y += l; + } else if (op == BAM_CDEL || op == BAM_CREF_SKIP) x += l; + else if (op == BAM_CINS || op == BAM_CSOFT_CLIP) y += l; + } + } + // determine the consensus + for (i = 0; i < right - left; ++i) r[i] = ref0[i]; + max = max2 = 0; max_i = max2_i = -1; + for (i = 0; i < right - left; ++i) { + if (cns[i]>>16 >= max>>16) max2 = max, max2_i = max_i, max = cns[i], max_i = i; + else if (cns[i]>>16 >= max2>>16) max2 = cns[i], max2_i = i; + } + if ((double)(max&0xffff) / ((max&0xffff) + (max>>16)) >= 0.7) max_i = -1; + if ((double)(max2&0xffff) / ((max2&0xffff) + (max2>>16)) >= 0.7) max2_i = -1; + if (max_i >= 0) r[max_i] = 15; + if (max2_i >= 0) r[max2_i] = 15; + //for (i = 0; i < right - left; ++i) fputc("=ACMGRSVTWYHKDBN"[(int)r[i]], stderr); fputc('\n', stderr); + } + free(ref0); free(cns); + } + { // the length of the homopolymer run around the current position + int c = seq_nt16_table[(int)ref[pos + 1]]; + if (c == 15) l_run = 1; + else { + for (i = pos + 2; ref[i]; ++i) + if (seq_nt16_table[(int)ref[i]] != c) break; + l_run = i; + for (i = pos; i >= 0; --i) + if (seq_nt16_table[(int)ref[i]] != c) break; + l_run -= i + 1; + } + } + // construct the consensus sequence + max_ins = types[n_types - 1]; // max_ins is at least 0 + if (max_ins > 0) { + int *inscns_aux = (int*) calloc(5 * n_types * max_ins, sizeof(int)); + // count the number of occurrences of each base at each position for each type of insertion + for (t = 0; t < n_types; ++t) { + if (types[t] > 0) { + for (s = 0; s < n; ++s) { + for (i = 0; i < n_plp[s]; ++i) { + bam_pileup1_t *p = plp[s] + i; + if (p->indel == types[t]) { + uint8_t *seq = bam_get_seq(p->b); + for (k = 1; k <= p->indel; ++k) { + int c = seq_nt16_int[bam_seqi(seq, p->qpos + k)]; + assert(c<5); + ++inscns_aux[(t*max_ins+(k-1))*5 + c]; + } + } + } + } + } + } + // use the majority rule to construct the consensus + inscns = (char*) calloc(n_types * max_ins, 1); + for (t = 0; t < n_types; ++t) { + for (j = 0; j < types[t]; ++j) { + int max = 0, max_k = -1, *ia = &inscns_aux[(t*max_ins+j)*5]; + for (k = 0; k < 5; ++k) + if (ia[k] > max) + max = ia[k], max_k = k; + inscns[t*max_ins + j] = max? max_k : 4; + if ( max_k==4 ) { types[t] = 0; break; } // discard insertions which contain N's + } + } + free(inscns_aux); + } + // compute the likelihood given each type of indel for each read + max_ref2 = right - left + 2 + 2 * (max_ins > -types[0]? max_ins : -types[0]); + ref2 = (char*) calloc(max_ref2, 1); + query = (char*) calloc(right - left + max_rd_len + max_ins + 2, 1); + score1 = (int*) calloc(N * n_types, sizeof(int)); + score2 = (int*) calloc(N * n_types, sizeof(int)); + bca->indelreg = 0; + for (t = 0; t < n_types; ++t) { + int l, ir; + probaln_par_t apf1 = { 1e-4, 1e-2, 10 }, apf2 = { 1e-6, 1e-3, 10 }; + apf1.bw = apf2.bw = abs(types[t]) + 3; + // compute indelreg + if (types[t] == 0) ir = 0; + else if (types[t] > 0) ir = est_indelreg(pos, ref, types[t], &inscns[t*max_ins]); + else ir = est_indelreg(pos, ref, -types[t], 0); + if (ir > bca->indelreg) bca->indelreg = ir; +// fprintf(stderr, "%d, %d, %d\n", pos, types[t], ir); + // realignment + for (s = K = 0; s < n; ++s) { + // write ref2 + for (k = 0, j = left; j <= pos; ++j) + ref2[k++] = seq_nt16_int[(int)ref_sample[s][j-left]]; + if (types[t] <= 0) j += -types[t]; + else for (l = 0; l < types[t]; ++l) + ref2[k++] = inscns[t*max_ins + l]; + for (; j < right && ref[j]; ++j) + ref2[k++] = seq_nt16_int[(int)ref_sample[s][j-left]]; + for (; k < max_ref2; ++k) ref2[k] = 4; + if (j < right) right = j; + // align each read to ref2 + for (i = 0; i < n_plp[s]; ++i, ++K) { + bam_pileup1_t *p = plp[s] + i; + int qbeg, qend, tbeg, tend, sc, kk; + uint8_t *seq = bam_get_seq(p->b); + uint32_t *cigar = bam_get_cigar(p->b); + if (p->b->core.flag&4) continue; // unmapped reads + // FIXME: the following loop should be better moved outside; nonetheless, realignment should be much slower anyway. + for (kk = 0; kk < p->b->core.n_cigar; ++kk) + if ((cigar[kk]&BAM_CIGAR_MASK) == BAM_CREF_SKIP) break; + if (kk < p->b->core.n_cigar) continue; + // FIXME: the following skips soft clips, but using them may be more sensitive. + // determine the start and end of sequences for alignment + qbeg = tpos2qpos(&p->b->core, bam_get_cigar(p->b), left, 0, &tbeg); + qend = tpos2qpos(&p->b->core, bam_get_cigar(p->b), right, 1, &tend); + if (types[t] < 0) { + int l = -types[t]; + tbeg = tbeg - l > left? tbeg - l : left; + } + // write the query sequence + for (l = qbeg; l < qend; ++l) + query[l - qbeg] = seq_nt16_int[bam_seqi(seq, l)]; + { // do realignment; this is the bottleneck + const uint8_t *qual = bam_get_qual(p->b), *bq; + uint8_t *qq; + qq = (uint8_t*) calloc(qend - qbeg, 1); + bq = (uint8_t*)bam_aux_get(p->b, "ZQ"); + if (bq) ++bq; // skip type + for (l = qbeg; l < qend; ++l) { + qq[l - qbeg] = bq? qual[l] + (bq[l] - 64) : qual[l]; + if (qq[l - qbeg] > 30) qq[l - qbeg] = 30; + if (qq[l - qbeg] < 7) qq[l - qbeg] = 7; + } + sc = probaln_glocal((uint8_t*)ref2 + tbeg - left, tend - tbeg + abs(types[t]), + (uint8_t*)query, qend - qbeg, qq, &apf1, 0, 0); + l = (int)(100. * sc / (qend - qbeg) + .499); // used for adjusting indelQ below + if (l > 255) l = 255; + score1[K*n_types + t] = score2[K*n_types + t] = sc<<8 | l; + if (sc > 5) { + sc = probaln_glocal((uint8_t*)ref2 + tbeg - left, tend - tbeg + abs(types[t]), + (uint8_t*)query, qend - qbeg, qq, &apf2, 0, 0); + l = (int)(100. * sc / (qend - qbeg) + .499); + if (l > 255) l = 255; + score2[K*n_types + t] = sc<<8 | l; + } + free(qq); + } +#if 0 + for (l = 0; l < tend - tbeg + abs(types[t]); ++l) + fputc("ACGTN"[(int)ref2[tbeg-left+l]], stderr); + fputc('\n', stderr); + for (l = 0; l < qend - qbeg; ++l) fputc("ACGTN"[(int)query[l]], stderr); + fputc('\n', stderr); + fprintf(stderr, "pos=%d type=%d read=%d:%d name=%s qbeg=%d tbeg=%d score=%d\n", pos, types[t], s, i, bam_get_qname(p->b), qbeg, tbeg, sc); +#endif + } + } + } + free(ref2); free(query); + { // compute indelQ + int sc_a[16], sumq_a[16]; + int tmp, *sc = sc_a, *sumq = sumq_a; + if (n_types > 16) { + sc = (int *)malloc(n_types * sizeof(int)); + sumq = (int *)malloc(n_types * sizeof(int)); + } + memset(sumq, 0, n_types * sizeof(int)); + for (s = K = 0; s < n; ++s) { + for (i = 0; i < n_plp[s]; ++i, ++K) { + bam_pileup1_t *p = plp[s] + i; + int *sct = &score1[K*n_types], indelQ1, indelQ2, seqQ, indelQ; + for (t = 0; t < n_types; ++t) sc[t] = sct[t]<<6 | t; + for (t = 1; t < n_types; ++t) // insertion sort + for (j = t; j > 0 && sc[j] < sc[j-1]; --j) + tmp = sc[j], sc[j] = sc[j-1], sc[j-1] = tmp; + /* errmod_cal() assumes that if the call is wrong, the + * likelihoods of other events are equal. This is about + * right for substitutions, but is not desired for + * indels. To reuse errmod_cal(), I have to make + * compromise for multi-allelic indels. + */ + if ((sc[0]&0x3f) == ref_type) { + indelQ1 = (sc[1]>>14) - (sc[0]>>14); + seqQ = est_seqQ(bca, types[sc[1]&0x3f], l_run); + } else { + for (t = 0; t < n_types; ++t) // look for the reference type + if ((sc[t]&0x3f) == ref_type) break; + indelQ1 = (sc[t]>>14) - (sc[0]>>14); + seqQ = est_seqQ(bca, types[sc[0]&0x3f], l_run); + } + tmp = sc[0]>>6 & 0xff; + indelQ1 = tmp > 111? 0 : (int)((1. - tmp/111.) * indelQ1 + .499); // reduce indelQ + sct = &score2[K*n_types]; + for (t = 0; t < n_types; ++t) sc[t] = sct[t]<<6 | t; + for (t = 1; t < n_types; ++t) // insertion sort + for (j = t; j > 0 && sc[j] < sc[j-1]; --j) + tmp = sc[j], sc[j] = sc[j-1], sc[j-1] = tmp; + if ((sc[0]&0x3f) == ref_type) { + indelQ2 = (sc[1]>>14) - (sc[0]>>14); + } else { + for (t = 0; t < n_types; ++t) // look for the reference type + if ((sc[t]&0x3f) == ref_type) break; + indelQ2 = (sc[t]>>14) - (sc[0]>>14); + } + tmp = sc[0]>>6 & 0xff; + indelQ2 = tmp > 111? 0 : (int)((1. - tmp/111.) * indelQ2 + .499); + // pick the smaller between indelQ1 and indelQ2 + indelQ = indelQ1 < indelQ2? indelQ1 : indelQ2; + if (indelQ > 255) indelQ = 255; + if (seqQ > 255) seqQ = 255; + p->aux = (sc[0]&0x3f)<<16 | seqQ<<8 | indelQ; // use 22 bits in total + sumq[sc[0]&0x3f] += indelQ < seqQ? indelQ : seqQ; +// fprintf(stderr, "pos=%d read=%d:%d name=%s call=%d indelQ=%d seqQ=%d\n", pos, s, i, bam1_qname(p->b), types[sc[0]&0x3f], indelQ, seqQ); + } + } + // determine bca->indel_types[] and bca->inscns + bca->maxins = max_ins; + bca->inscns = (char*) realloc(bca->inscns, bca->maxins * 4); + for (t = 0; t < n_types; ++t) + sumq[t] = sumq[t]<<6 | t; + for (t = 1; t < n_types; ++t) // insertion sort + for (j = t; j > 0 && sumq[j] > sumq[j-1]; --j) + tmp = sumq[j], sumq[j] = sumq[j-1], sumq[j-1] = tmp; + for (t = 0; t < n_types; ++t) // look for the reference type + if ((sumq[t]&0x3f) == ref_type) break; + if (t) { // then move the reference type to the first + tmp = sumq[t]; + for (; t > 0; --t) sumq[t] = sumq[t-1]; + sumq[0] = tmp; + } + for (t = 0; t < 4; ++t) bca->indel_types[t] = B2B_INDEL_NULL; + for (t = 0; t < 4 && t < n_types; ++t) { + bca->indel_types[t] = types[sumq[t]&0x3f]; + memcpy(&bca->inscns[t * bca->maxins], &inscns[(sumq[t]&0x3f) * max_ins], bca->maxins); + } + // update p->aux + for (s = n_alt = 0; s < n; ++s) { + for (i = 0; i < n_plp[s]; ++i) { + bam_pileup1_t *p = plp[s] + i; + int x = types[p->aux>>16&0x3f]; + for (j = 0; j < 4; ++j) + if (x == bca->indel_types[j]) break; + p->aux = j<<16 | (j == 4? 0 : (p->aux&0xffff)); + if ((p->aux>>16&0x3f) > 0) ++n_alt; + //fprintf(stderr, "X pos=%d read=%d:%d name=%s call=%d type=%d seqQ=%d indelQ=%d\n", pos, s, i, bam_get_qname(p->b), (p->aux>>16)&0x3f, bca->indel_types[(p->aux>>16)&0x3f], (p->aux>>8)&0xff, p->aux&0xff); + } + } + + if (sc != sc_a) free(sc); + if (sumq != sumq_a) free(sumq); + } + free(score1); free(score2); + // free + for (i = 0; i < n; ++i) free(ref_sample[i]); + free(ref_sample); + free(types); free(inscns); + return n_alt > 0? 0 : -1; +} diff --git a/bcftools/bam2bcf_indel.c.pysam.c b/bcftools/bam2bcf_indel.c.pysam.c new file mode 100644 index 000000000..67fff2186 --- /dev/null +++ b/bcftools/bam2bcf_indel.c.pysam.c @@ -0,0 +1,472 @@ +#include "bcftools.pysam.h" + +/* bam2bcf_indel.c -- indel caller. + + Copyright (C) 2010, 2011 Broad Institute. + Copyright (C) 2012-2014,2016 Genome Research Ltd. + + Author: Heng Li + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include +#include +#include +#include +#include +#include +#include "bam2bcf.h" + +#include +KSORT_INIT_GENERIC(uint32_t) + +#define MINUS_CONST 0x10000000 +#define INDEL_WINDOW_SIZE 50 + +static int tpos2qpos(const bam1_core_t *c, const uint32_t *cigar, int32_t tpos, int is_left, int32_t *_tpos) +{ + int k, x = c->pos, y = 0, last_y = 0; + *_tpos = c->pos; + for (k = 0; k < c->n_cigar; ++k) { + int op = cigar[k] & BAM_CIGAR_MASK; + int l = cigar[k] >> BAM_CIGAR_SHIFT; + if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { + if (c->pos > tpos) return y; + if (x + l > tpos) { + *_tpos = tpos; + return y + (tpos - x); + } + x += l; y += l; + last_y = y; + } else if (op == BAM_CINS || op == BAM_CSOFT_CLIP) y += l; + else if (op == BAM_CDEL || op == BAM_CREF_SKIP) { + if (x + l > tpos) { + *_tpos = is_left? x : x + l; + return y; + } + x += l; + } + } + *_tpos = x; + return last_y; +} +// FIXME: check if the inserted sequence is consistent with the homopolymer run +// l is the relative gap length and l_run is the length of the homopolymer on the reference +static inline int est_seqQ(const bcf_callaux_t *bca, int l, int l_run) +{ + int q, qh; + q = bca->openQ + bca->extQ * (abs(l) - 1); + qh = l_run >= 3? (int)(bca->tandemQ * (double)abs(l) / l_run + .499) : 1000; + return q < qh? q : qh; +} + +static inline int est_indelreg(int pos, const char *ref, int l, char *ins4) +{ + int i, j, max = 0, max_i = pos, score = 0; + l = abs(l); + for (i = pos + 1, j = 0; ref[i]; ++i, ++j) { + if (ins4) score += (toupper(ref[i]) != "ACGTN"[(int)ins4[j%l]])? -10 : 1; + else score += (toupper(ref[i]) != toupper(ref[pos+1+j%l]))? -10 : 1; + if (score < 0) break; + if (max < score) max = score, max_i = i; + } + return max_i - pos; +} + +/* + notes: + - n .. number of samples + - the routine sets bam_pileup1_t.aux of each read as follows: + - 6: unused + - 6: the call; index to bcf_callaux_t.indel_types .. (aux>>16)&0x3f + - 8: estimated sequence quality .. (aux>>8)&0xff + - 8: indel quality .. aux&0xff + */ +int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_callaux_t *bca, const char *ref) +{ + int i, s, j, k, t, n_types, *types, max_rd_len, left, right, max_ins, *score1, *score2, max_ref2; + int N, K, l_run, ref_type, n_alt; + char *inscns = 0, *ref2, *query, **ref_sample; + if (ref == 0 || bca == 0) return -1; + + // determine if there is a gap + for (s = N = 0; s < n; ++s) { + for (i = 0; i < n_plp[s]; ++i) + if (plp[s][i].indel != 0) break; + if (i < n_plp[s]) break; + } + if (s == n) return -1; // there is no indel at this position. + for (s = N = 0; s < n; ++s) N += n_plp[s]; // N is the total number of reads + { // find out how many types of indels are present + bca->max_support = bca->max_frac = 0; + int m, n_alt = 0, n_tot = 0, indel_support_ok = 0; + uint32_t *aux; + aux = (uint32_t*) calloc(N + 1, 4); + m = max_rd_len = 0; + aux[m++] = MINUS_CONST; // zero indel is always a type + for (s = 0; s < n; ++s) { + int na = 0, nt = 0; + for (i = 0; i < n_plp[s]; ++i) { + const bam_pileup1_t *p = plp[s] + i; + ++nt; + if (p->indel != 0) { + ++na; + aux[m++] = MINUS_CONST + p->indel; + } + j = bam_cigar2qlen(p->b->core.n_cigar, bam_get_cigar(p->b)); + if (j > max_rd_len) max_rd_len = j; + } + double frac = (double)na/nt; + if ( !indel_support_ok && na >= bca->min_support && frac >= bca->min_frac ) + indel_support_ok = 1; + if ( na > bca->max_support && frac > 0 ) bca->max_support = na, bca->max_frac = frac; + n_alt += na; + n_tot += nt; + } + // To prevent long stretches of N's to be mistaken for indels (sometimes thousands of bases), + // check the number of N's in the sequence and skip places where half or more reference bases are Ns. + int nN=0; for (i=pos; i-pos(i-pos) ) { free(aux); return -1; } + + ks_introsort(uint32_t, m, aux); + // squeeze out identical types + for (i = 1, n_types = 1; i < m; ++i) + if (aux[i] != aux[i-1]) ++n_types; + // Taking totals makes it hard to call rare indels + if ( !bca->per_sample_flt ) + indel_support_ok = ( (double)n_alt / n_tot < bca->min_frac || n_alt < bca->min_support ) ? 0 : 1; + if ( n_types == 1 || !indel_support_ok ) { // then skip + free(aux); return -1; + } + if (n_types >= 64) { + free(aux); + // TODO revisit how/whether to control printing this warning + if (hts_verbose >= 2) + fprintf(bcftools_stderr, "[%s] excessive INDEL alleles at position %d. Skip the position.\n", __func__, pos + 1); + return -1; + } + types = (int*)calloc(n_types, sizeof(int)); + t = 0; + types[t++] = aux[0] - MINUS_CONST; + for (i = 1; i < m; ++i) + if (aux[i] != aux[i-1]) + types[t++] = aux[i] - MINUS_CONST; + free(aux); + for (t = 0; t < n_types; ++t) + if (types[t] == 0) break; + ref_type = t; // the index of the reference type (0) + } + { // calculate left and right boundary + left = pos > INDEL_WINDOW_SIZE? pos - INDEL_WINDOW_SIZE : 0; + right = pos + INDEL_WINDOW_SIZE; + if (types[0] < 0) right -= types[0]; + // in case the alignments stand out the reference + for (i = pos; i < right; ++i) + if (ref[i] == 0) break; + right = i; + } + /* The following block fixes a long-existing flaw in the INDEL + * calling model: the interference of nearby SNPs. However, it also + * reduces the power because sometimes, substitutions caused by + * indels are not distinguishable from true mutations. Multiple + * sequence realignment helps to increase the power. + * + * Masks mismatches present in at least 70% of the reads with 'N'. + */ + { // construct per-sample consensus + int L = right - left + 1, max_i, max2_i; + uint32_t *cns, max, max2; + char *ref0, *r; + ref_sample = (char**) calloc(n, sizeof(char*)); + cns = (uint32_t*) calloc(L, 4); + ref0 = (char*) calloc(L, 1); + for (i = 0; i < right - left; ++i) + ref0[i] = seq_nt16_table[(int)ref[i+left]]; + for (s = 0; s < n; ++s) { + r = ref_sample[s] = (char*) calloc(L, 1); + memset(cns, 0, sizeof(int) * L); + // collect ref and non-ref counts + for (i = 0; i < n_plp[s]; ++i) { + bam_pileup1_t *p = plp[s] + i; + bam1_t *b = p->b; + uint32_t *cigar = bam_get_cigar(b); + uint8_t *seq = bam_get_seq(b); + int x = b->core.pos, y = 0; + for (k = 0; k < b->core.n_cigar; ++k) { + int op = cigar[k]&0xf; + int j, l = cigar[k]>>4; + if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { + for (j = 0; j < l; ++j) + if (x + j >= left && x + j < right) + cns[x+j-left] += (bam_seqi(seq, y+j) == ref0[x+j-left])? 1 : 0x10000; + x += l; y += l; + } else if (op == BAM_CDEL || op == BAM_CREF_SKIP) x += l; + else if (op == BAM_CINS || op == BAM_CSOFT_CLIP) y += l; + } + } + // determine the consensus + for (i = 0; i < right - left; ++i) r[i] = ref0[i]; + max = max2 = 0; max_i = max2_i = -1; + for (i = 0; i < right - left; ++i) { + if (cns[i]>>16 >= max>>16) max2 = max, max2_i = max_i, max = cns[i], max_i = i; + else if (cns[i]>>16 >= max2>>16) max2 = cns[i], max2_i = i; + } + if ((double)(max&0xffff) / ((max&0xffff) + (max>>16)) >= 0.7) max_i = -1; + if ((double)(max2&0xffff) / ((max2&0xffff) + (max2>>16)) >= 0.7) max2_i = -1; + if (max_i >= 0) r[max_i] = 15; + if (max2_i >= 0) r[max2_i] = 15; + //for (i = 0; i < right - left; ++i) fputc("=ACMGRSVTWYHKDBN"[(int)r[i]], bcftools_stderr); fputc('\n', bcftools_stderr); + } + free(ref0); free(cns); + } + { // the length of the homopolymer run around the current position + int c = seq_nt16_table[(int)ref[pos + 1]]; + if (c == 15) l_run = 1; + else { + for (i = pos + 2; ref[i]; ++i) + if (seq_nt16_table[(int)ref[i]] != c) break; + l_run = i; + for (i = pos; i >= 0; --i) + if (seq_nt16_table[(int)ref[i]] != c) break; + l_run -= i + 1; + } + } + // construct the consensus sequence + max_ins = types[n_types - 1]; // max_ins is at least 0 + if (max_ins > 0) { + int *inscns_aux = (int*) calloc(5 * n_types * max_ins, sizeof(int)); + // count the number of occurrences of each base at each position for each type of insertion + for (t = 0; t < n_types; ++t) { + if (types[t] > 0) { + for (s = 0; s < n; ++s) { + for (i = 0; i < n_plp[s]; ++i) { + bam_pileup1_t *p = plp[s] + i; + if (p->indel == types[t]) { + uint8_t *seq = bam_get_seq(p->b); + for (k = 1; k <= p->indel; ++k) { + int c = seq_nt16_int[bam_seqi(seq, p->qpos + k)]; + assert(c<5); + ++inscns_aux[(t*max_ins+(k-1))*5 + c]; + } + } + } + } + } + } + // use the majority rule to construct the consensus + inscns = (char*) calloc(n_types * max_ins, 1); + for (t = 0; t < n_types; ++t) { + for (j = 0; j < types[t]; ++j) { + int max = 0, max_k = -1, *ia = &inscns_aux[(t*max_ins+j)*5]; + for (k = 0; k < 5; ++k) + if (ia[k] > max) + max = ia[k], max_k = k; + inscns[t*max_ins + j] = max? max_k : 4; + if ( max_k==4 ) { types[t] = 0; break; } // discard insertions which contain N's + } + } + free(inscns_aux); + } + // compute the likelihood given each type of indel for each read + max_ref2 = right - left + 2 + 2 * (max_ins > -types[0]? max_ins : -types[0]); + ref2 = (char*) calloc(max_ref2, 1); + query = (char*) calloc(right - left + max_rd_len + max_ins + 2, 1); + score1 = (int*) calloc(N * n_types, sizeof(int)); + score2 = (int*) calloc(N * n_types, sizeof(int)); + bca->indelreg = 0; + for (t = 0; t < n_types; ++t) { + int l, ir; + probaln_par_t apf1 = { 1e-4, 1e-2, 10 }, apf2 = { 1e-6, 1e-3, 10 }; + apf1.bw = apf2.bw = abs(types[t]) + 3; + // compute indelreg + if (types[t] == 0) ir = 0; + else if (types[t] > 0) ir = est_indelreg(pos, ref, types[t], &inscns[t*max_ins]); + else ir = est_indelreg(pos, ref, -types[t], 0); + if (ir > bca->indelreg) bca->indelreg = ir; +// fprintf(bcftools_stderr, "%d, %d, %d\n", pos, types[t], ir); + // realignment + for (s = K = 0; s < n; ++s) { + // write ref2 + for (k = 0, j = left; j <= pos; ++j) + ref2[k++] = seq_nt16_int[(int)ref_sample[s][j-left]]; + if (types[t] <= 0) j += -types[t]; + else for (l = 0; l < types[t]; ++l) + ref2[k++] = inscns[t*max_ins + l]; + for (; j < right && ref[j]; ++j) + ref2[k++] = seq_nt16_int[(int)ref_sample[s][j-left]]; + for (; k < max_ref2; ++k) ref2[k] = 4; + if (j < right) right = j; + // align each read to ref2 + for (i = 0; i < n_plp[s]; ++i, ++K) { + bam_pileup1_t *p = plp[s] + i; + int qbeg, qend, tbeg, tend, sc, kk; + uint8_t *seq = bam_get_seq(p->b); + uint32_t *cigar = bam_get_cigar(p->b); + if (p->b->core.flag&4) continue; // unmapped reads + // FIXME: the following loop should be better moved outside; nonetheless, realignment should be much slower anyway. + for (kk = 0; kk < p->b->core.n_cigar; ++kk) + if ((cigar[kk]&BAM_CIGAR_MASK) == BAM_CREF_SKIP) break; + if (kk < p->b->core.n_cigar) continue; + // FIXME: the following skips soft clips, but using them may be more sensitive. + // determine the start and end of sequences for alignment + qbeg = tpos2qpos(&p->b->core, bam_get_cigar(p->b), left, 0, &tbeg); + qend = tpos2qpos(&p->b->core, bam_get_cigar(p->b), right, 1, &tend); + if (types[t] < 0) { + int l = -types[t]; + tbeg = tbeg - l > left? tbeg - l : left; + } + // write the query sequence + for (l = qbeg; l < qend; ++l) + query[l - qbeg] = seq_nt16_int[bam_seqi(seq, l)]; + { // do realignment; this is the bottleneck + const uint8_t *qual = bam_get_qual(p->b), *bq; + uint8_t *qq; + qq = (uint8_t*) calloc(qend - qbeg, 1); + bq = (uint8_t*)bam_aux_get(p->b, "ZQ"); + if (bq) ++bq; // skip type + for (l = qbeg; l < qend; ++l) { + qq[l - qbeg] = bq? qual[l] + (bq[l] - 64) : qual[l]; + if (qq[l - qbeg] > 30) qq[l - qbeg] = 30; + if (qq[l - qbeg] < 7) qq[l - qbeg] = 7; + } + sc = probaln_glocal((uint8_t*)ref2 + tbeg - left, tend - tbeg + abs(types[t]), + (uint8_t*)query, qend - qbeg, qq, &apf1, 0, 0); + l = (int)(100. * sc / (qend - qbeg) + .499); // used for adjusting indelQ below + if (l > 255) l = 255; + score1[K*n_types + t] = score2[K*n_types + t] = sc<<8 | l; + if (sc > 5) { + sc = probaln_glocal((uint8_t*)ref2 + tbeg - left, tend - tbeg + abs(types[t]), + (uint8_t*)query, qend - qbeg, qq, &apf2, 0, 0); + l = (int)(100. * sc / (qend - qbeg) + .499); + if (l > 255) l = 255; + score2[K*n_types + t] = sc<<8 | l; + } + free(qq); + } +#if 0 + for (l = 0; l < tend - tbeg + abs(types[t]); ++l) + fputc("ACGTN"[(int)ref2[tbeg-left+l]], bcftools_stderr); + fputc('\n', bcftools_stderr); + for (l = 0; l < qend - qbeg; ++l) fputc("ACGTN"[(int)query[l]], bcftools_stderr); + fputc('\n', bcftools_stderr); + fprintf(bcftools_stderr, "pos=%d type=%d read=%d:%d name=%s qbeg=%d tbeg=%d score=%d\n", pos, types[t], s, i, bam_get_qname(p->b), qbeg, tbeg, sc); +#endif + } + } + } + free(ref2); free(query); + { // compute indelQ + int sc_a[16], sumq_a[16]; + int tmp, *sc = sc_a, *sumq = sumq_a; + if (n_types > 16) { + sc = (int *)malloc(n_types * sizeof(int)); + sumq = (int *)malloc(n_types * sizeof(int)); + } + memset(sumq, 0, n_types * sizeof(int)); + for (s = K = 0; s < n; ++s) { + for (i = 0; i < n_plp[s]; ++i, ++K) { + bam_pileup1_t *p = plp[s] + i; + int *sct = &score1[K*n_types], indelQ1, indelQ2, seqQ, indelQ; + for (t = 0; t < n_types; ++t) sc[t] = sct[t]<<6 | t; + for (t = 1; t < n_types; ++t) // insertion sort + for (j = t; j > 0 && sc[j] < sc[j-1]; --j) + tmp = sc[j], sc[j] = sc[j-1], sc[j-1] = tmp; + /* errmod_cal() assumes that if the call is wrong, the + * likelihoods of other events are equal. This is about + * right for substitutions, but is not desired for + * indels. To reuse errmod_cal(), I have to make + * compromise for multi-allelic indels. + */ + if ((sc[0]&0x3f) == ref_type) { + indelQ1 = (sc[1]>>14) - (sc[0]>>14); + seqQ = est_seqQ(bca, types[sc[1]&0x3f], l_run); + } else { + for (t = 0; t < n_types; ++t) // look for the reference type + if ((sc[t]&0x3f) == ref_type) break; + indelQ1 = (sc[t]>>14) - (sc[0]>>14); + seqQ = est_seqQ(bca, types[sc[0]&0x3f], l_run); + } + tmp = sc[0]>>6 & 0xff; + indelQ1 = tmp > 111? 0 : (int)((1. - tmp/111.) * indelQ1 + .499); // reduce indelQ + sct = &score2[K*n_types]; + for (t = 0; t < n_types; ++t) sc[t] = sct[t]<<6 | t; + for (t = 1; t < n_types; ++t) // insertion sort + for (j = t; j > 0 && sc[j] < sc[j-1]; --j) + tmp = sc[j], sc[j] = sc[j-1], sc[j-1] = tmp; + if ((sc[0]&0x3f) == ref_type) { + indelQ2 = (sc[1]>>14) - (sc[0]>>14); + } else { + for (t = 0; t < n_types; ++t) // look for the reference type + if ((sc[t]&0x3f) == ref_type) break; + indelQ2 = (sc[t]>>14) - (sc[0]>>14); + } + tmp = sc[0]>>6 & 0xff; + indelQ2 = tmp > 111? 0 : (int)((1. - tmp/111.) * indelQ2 + .499); + // pick the smaller between indelQ1 and indelQ2 + indelQ = indelQ1 < indelQ2? indelQ1 : indelQ2; + if (indelQ > 255) indelQ = 255; + if (seqQ > 255) seqQ = 255; + p->aux = (sc[0]&0x3f)<<16 | seqQ<<8 | indelQ; // use 22 bits in total + sumq[sc[0]&0x3f] += indelQ < seqQ? indelQ : seqQ; +// fprintf(bcftools_stderr, "pos=%d read=%d:%d name=%s call=%d indelQ=%d seqQ=%d\n", pos, s, i, bam1_qname(p->b), types[sc[0]&0x3f], indelQ, seqQ); + } + } + // determine bca->indel_types[] and bca->inscns + bca->maxins = max_ins; + bca->inscns = (char*) realloc(bca->inscns, bca->maxins * 4); + for (t = 0; t < n_types; ++t) + sumq[t] = sumq[t]<<6 | t; + for (t = 1; t < n_types; ++t) // insertion sort + for (j = t; j > 0 && sumq[j] > sumq[j-1]; --j) + tmp = sumq[j], sumq[j] = sumq[j-1], sumq[j-1] = tmp; + for (t = 0; t < n_types; ++t) // look for the reference type + if ((sumq[t]&0x3f) == ref_type) break; + if (t) { // then move the reference type to the first + tmp = sumq[t]; + for (; t > 0; --t) sumq[t] = sumq[t-1]; + sumq[0] = tmp; + } + for (t = 0; t < 4; ++t) bca->indel_types[t] = B2B_INDEL_NULL; + for (t = 0; t < 4 && t < n_types; ++t) { + bca->indel_types[t] = types[sumq[t]&0x3f]; + memcpy(&bca->inscns[t * bca->maxins], &inscns[(sumq[t]&0x3f) * max_ins], bca->maxins); + } + // update p->aux + for (s = n_alt = 0; s < n; ++s) { + for (i = 0; i < n_plp[s]; ++i) { + bam_pileup1_t *p = plp[s] + i; + int x = types[p->aux>>16&0x3f]; + for (j = 0; j < 4; ++j) + if (x == bca->indel_types[j]) break; + p->aux = j<<16 | (j == 4? 0 : (p->aux&0xffff)); + if ((p->aux>>16&0x3f) > 0) ++n_alt; + //fprintf(bcftools_stderr, "X pos=%d read=%d:%d name=%s call=%d type=%d seqQ=%d indelQ=%d\n", pos, s, i, bam_get_qname(p->b), (p->aux>>16)&0x3f, bca->indel_types[(p->aux>>16)&0x3f], (p->aux>>8)&0xff, p->aux&0xff); + } + } + + if (sc != sc_a) free(sc); + if (sumq != sumq_a) free(sumq); + } + free(score1); free(score2); + // free + for (i = 0; i < n; ++i) free(ref_sample[i]); + free(ref_sample); + free(types); free(inscns); + return n_alt > 0? 0 : -1; +} diff --git a/bcftools/bam_sample.c b/bcftools/bam_sample.c new file mode 100644 index 000000000..66f572948 --- /dev/null +++ b/bcftools/bam_sample.c @@ -0,0 +1,393 @@ +/* bam_sample.c -- group data by sample. + + Copyright (C) 2010, 2011 Broad Institute. + Copyright (C) 2013, 2016 Genome Research Ltd. + + Author: Heng Li , Petr Danecek + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include +#include +#include +#include +#include +#include +#include +#include "bam_sample.h" +#include "bcftools.h" + + +typedef struct +{ + char *fname; + void *rg2idx; // hash: read group name to BCF output sample index. Maintained by bsmpl_add_readgroup + int default_idx; // default BCF output sample index, set only when all readgroups are treated as one sample +} +file_t; + +struct _bam_smpl_t +{ + kstring_t tmp; + file_t *files; + int ignore_rg, nsmpl, nfiles; + char **smpl; // list of BCF output sample names. Maintained by bsmpl_add_readgroup + void *sample_list; // hash: BAM input sample name to BCF output sample name. This is the -s/-S list + int sample_logic; // the -s/-S logic, 1: include, 0: exclude + void *rg_list; // hash: BAM/rg_id to sample name or */rg_id for global ids. This is the -G list + int rg_logic; // the -G logic, 1: include, 0: exclude + void *name2idx; // hash: BCF output sample name to BCF output sample index. Maintained by bsmpl_add_readgroup +}; + +bam_smpl_t *bam_smpl_init(void) +{ + bam_smpl_t *bsmpl; + bsmpl = (bam_smpl_t*) calloc(1, sizeof(bam_smpl_t)); + bsmpl->name2idx = khash_str2int_init(); + return bsmpl; +} + +void bam_smpl_destroy(bam_smpl_t *bsmpl) +{ + if ( !bsmpl ) return; + if ( bsmpl->name2idx ) khash_str2int_destroy_free(bsmpl->name2idx); + if ( bsmpl->sample_list ) khash_str2str_destroy_free_all(bsmpl->sample_list); + if ( bsmpl->rg_list ) khash_str2str_destroy_free_all(bsmpl->rg_list); + int i; + for (i=0; infiles; i++) + { + file_t *file = &bsmpl->files[i]; + if ( file->rg2idx ) khash_str2int_destroy_free(file->rg2idx); + free(file->fname); + } + free(bsmpl->smpl); + free(bsmpl->files); + free(bsmpl->tmp.s); + free(bsmpl); +} + +void bam_smpl_ignore_readgroups(bam_smpl_t* bsmpl) +{ + bsmpl->ignore_rg = 1; +} + +static void bsmpl_add_readgroup(bam_smpl_t *bsmpl, file_t *file, const char *rg_id, const char *smpl_name) +{ + int ismpl = -1; + if ( smpl_name ) + { + if ( khash_str2int_get(bsmpl->name2idx,smpl_name,&ismpl) < 0 ) + { + // new sample + bsmpl->nsmpl++; + bsmpl->smpl = (char**) realloc(bsmpl->smpl,sizeof(char*)*bsmpl->nsmpl); + bsmpl->smpl[bsmpl->nsmpl-1] = strdup(smpl_name); + ismpl = khash_str2int_inc(bsmpl->name2idx,bsmpl->smpl[bsmpl->nsmpl-1]); + } + } + if ( !strcmp("*",rg_id) ) + { + // all read groups in the bam treated as the same sample + file->default_idx = ismpl; + return; + } + if ( !file->rg2idx ) file->rg2idx = khash_str2int_init(); + if ( khash_str2int_has_key(file->rg2idx,rg_id) ) return; // duplicate @RG:ID + khash_str2int_set(file->rg2idx, strdup(rg_id), ismpl); +} +static int bsmpl_keep_readgroup(bam_smpl_t *bsmpl, file_t *file, const char *rg_id, const char **smpl_name) +{ + char *rg_smpl = khash_str2str_get(bsmpl->rg_list,rg_id); // unique read group present in one bam only + if ( !rg_smpl ) + { + // read group specific to this bam + bsmpl->tmp.l = 0; + ksprintf(&bsmpl->tmp,"%s\t%s",rg_id,file->fname); + rg_smpl = khash_str2str_get(bsmpl->rg_list,bsmpl->tmp.s); + } + if ( !rg_smpl ) + { + // any read group in this file? + bsmpl->tmp.l = 0; + ksprintf(&bsmpl->tmp,"*\t%s",file->fname); + rg_smpl = khash_str2str_get(bsmpl->rg_list,bsmpl->tmp.s); + } + if ( !rg_smpl && bsmpl->rg_logic ) return 0; + if ( rg_smpl && !bsmpl->rg_logic ) return 0; + + if ( rg_smpl && rg_smpl[0]!='\t' ) *smpl_name = rg_smpl; // rename the sample + return 1; +} + +/* + The logic of this function is a bit complicated because we want to work + also with broken bams containing read groups that are not listed in the + header. The desired behavior is as follows: + - when -G is given, read groups which are not listed in the header must + be given explicitly using the "?" symbol in -G. + Otherwise: + - if the bam has no header, all reads in the file are assigned to a + single sample named after the file + - if there is at least one sample defined in the header, reads with no + read group id or with a read group id not listed in the header are + assigned to the first sample encountered in the header +*/ +int bam_smpl_add_bam(bam_smpl_t *bsmpl, char *bam_hdr, const char *fname) +{ + bsmpl->nfiles++; + bsmpl->files = (file_t*) realloc(bsmpl->files,bsmpl->nfiles*sizeof(file_t)); + file_t *file = &bsmpl->files[bsmpl->nfiles-1]; + memset(file,0,sizeof(file_t)); + file->fname = strdup(fname); + file->default_idx = -1; + + if ( bsmpl->ignore_rg || !bam_hdr ) + { + // The option --ignore-RG is set or there is no BAM header: use the file name as the sample name + bsmpl_add_readgroup(bsmpl,file,"*",file->fname); + return bsmpl->nfiles-1; + } + + void *bam_smpls = khash_str2int_init(); + int first_smpl = -1, nskipped = 0; + const char *p = bam_hdr, *q, *r; + while ((q = strstr(p, "@RG")) != 0) + { + p = q + 3; + r = q = 0; + if ((q = strstr(p, "\tID:")) != 0) q += 4; + if ((r = strstr(p, "\tSM:")) != 0) r += 4; + if (r && q) + { + char *u, *v; + int ioq, ior; + for (u = (char*)q; *u && *u != '\t' && *u != '\n'; ++u); + for (v = (char*)r; *v && *v != '\t' && *v != '\n'; ++v); + ioq = *u; ior = *v; *u = *v = '\0'; + + // q now points to a null terminated read group id + // r points to a null terminated sample name + if ( !strcmp("*",q) || !strcmp("?",q) ) + error("Error: the read group IDs \"*\" and \"?\" have a special meaning in the mpileup code. Please fix the code or the bam: %s\n", fname); + + int accept_rg = 1; + if ( bsmpl->sample_list ) + { + // restrict samples based on the -s/-S options + char *name = khash_str2str_get(bsmpl->sample_list,r); + if ( bsmpl->sample_logic==0 ) + accept_rg = name ? 0 : 1; + else if ( !name ) + accept_rg = 0; + else + r = name; + } + if ( accept_rg && bsmpl->rg_list ) + { + // restrict readgroups based on the -G option, possibly renaming the sample + accept_rg = bsmpl_keep_readgroup(bsmpl,file,q,&r); + } + if ( accept_rg ) + bsmpl_add_readgroup(bsmpl,file,q,r); + else + { + bsmpl_add_readgroup(bsmpl,file,q,NULL); // ignore this RG but note that it was seen in the header + nskipped++; + } + + if ( first_smpl<0 ) + khash_str2int_get(bsmpl->name2idx,r,&first_smpl); + if ( !khash_str2int_has_key(bam_smpls,r) ) + khash_str2int_inc(bam_smpls,strdup(r)); + + *u = ioq; *v = ior; + } + else + break; + p = q > r ? q : r; + } + int nsmpls = khash_str2int_size(bam_smpls); + khash_str2int_destroy_free(bam_smpls); + + const char *smpl_name = NULL; + int accept_null_rg = 1; + if ( bsmpl->rg_list && !bsmpl_keep_readgroup(bsmpl,file,"?",&smpl_name) ) accept_null_rg = 0; + if ( bsmpl->sample_list && first_smpl==-1 ) accept_null_rg = 0; + + if ( !accept_null_rg && first_smpl==-1 ) + { + // no suitable read group is available in this bam: ignore the whole file. + free(file->fname); + bsmpl->nfiles--; + return -1; + } + if ( !accept_null_rg ) return bsmpl->nfiles-1; + if ( nsmpls==1 && !nskipped ) + { + file->default_idx = first_smpl; + return bsmpl->nfiles-1; + } + if ( !smpl_name ) smpl_name = first_smpl==-1 ? file->fname : bsmpl->smpl[first_smpl]; + + bsmpl_add_readgroup(bsmpl,file,"?",smpl_name); + return bsmpl->nfiles-1; +} + +const char **bam_smpl_get_samples(bam_smpl_t *bsmpl, int *nsmpl) +{ + *nsmpl = bsmpl->nsmpl; + return (const char**)bsmpl->smpl; +} + +int bam_smpl_get_sample_id(bam_smpl_t *bsmpl, int bam_id, bam1_t *bam_rec) +{ + file_t *file = &bsmpl->files[bam_id]; + if ( file->default_idx >= 0 ) return file->default_idx; + + char *aux_rg = (char*) bam_aux_get(bam_rec, "RG"); + aux_rg = aux_rg ? aux_rg+1 : "?"; + + int rg_id; + if ( khash_str2int_get(file->rg2idx, aux_rg, &rg_id)==0 ) return rg_id; + if ( khash_str2int_get(file->rg2idx, "?", &rg_id)==0 ) return rg_id; + return -1; +} + +int bam_smpl_add_samples(bam_smpl_t *bsmpl, char *list, int is_file) +{ + if ( list[0]!='^' ) bsmpl->sample_logic = 1; + else list++; + + int i, nsamples = 0; + char **samples = hts_readlist(list, is_file, &nsamples); + if ( !nsamples ) return 0; + + kstring_t ori = {0,0,0}; + kstring_t ren = {0,0,0}; + + bsmpl->sample_list = khash_str2str_init(); + for (i=0; isample_list,strdup(ori.s),strdup(ren.l?ren.s:ori.s)); + free(samples[i]); + } + free(samples); + free(ori.s); + free(ren.s); + return nsamples; +} + +int bam_smpl_add_readgroups(bam_smpl_t *bsmpl, char *list, int is_file) +{ + if ( list[0]!='^' ) bsmpl->rg_logic = 1; + else list++; + + int i, nrows = 0; + char **rows = hts_readlist(list, is_file, &nrows); + if ( !nrows ) return 0; + + kstring_t fld1 = {0,0,0}; + kstring_t fld2 = {0,0,0}; + kstring_t fld3 = {0,0,0}; + + bsmpl->rg_list = khash_str2str_init(); + for (i=0; irg_list,fld1.s); + if ( !value ) + khash_str2str_set(bsmpl->rg_list,strdup(fld1.s),strdup(fld2.l?fld2.s:"\t")); + else if ( strcmp(value,fld2.l?fld2.s:"\t") ) + error("Error: The read group \"%s\" was assigned to two different samples: \"%s\" and \"%s\"\n", fld1.s,value,fld2.l?fld2.s:"\t"); + free(rows[i]); + } + free(rows); + free(fld1.s); + free(fld2.s); + free(fld3.s); + return nrows; +} + + diff --git a/bcftools/bam_sample.c.pysam.c b/bcftools/bam_sample.c.pysam.c new file mode 100644 index 000000000..c25358fe4 --- /dev/null +++ b/bcftools/bam_sample.c.pysam.c @@ -0,0 +1,395 @@ +#include "bcftools.pysam.h" + +/* bam_sample.c -- group data by sample. + + Copyright (C) 2010, 2011 Broad Institute. + Copyright (C) 2013, 2016 Genome Research Ltd. + + Author: Heng Li , Petr Danecek + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include +#include +#include +#include +#include +#include +#include +#include "bam_sample.h" +#include "bcftools.h" + + +typedef struct +{ + char *fname; + void *rg2idx; // hash: read group name to BCF output sample index. Maintained by bsmpl_add_readgroup + int default_idx; // default BCF output sample index, set only when all readgroups are treated as one sample +} +file_t; + +struct _bam_smpl_t +{ + kstring_t tmp; + file_t *files; + int ignore_rg, nsmpl, nfiles; + char **smpl; // list of BCF output sample names. Maintained by bsmpl_add_readgroup + void *sample_list; // hash: BAM input sample name to BCF output sample name. This is the -s/-S list + int sample_logic; // the -s/-S logic, 1: include, 0: exclude + void *rg_list; // hash: BAM/rg_id to sample name or */rg_id for global ids. This is the -G list + int rg_logic; // the -G logic, 1: include, 0: exclude + void *name2idx; // hash: BCF output sample name to BCF output sample index. Maintained by bsmpl_add_readgroup +}; + +bam_smpl_t *bam_smpl_init(void) +{ + bam_smpl_t *bsmpl; + bsmpl = (bam_smpl_t*) calloc(1, sizeof(bam_smpl_t)); + bsmpl->name2idx = khash_str2int_init(); + return bsmpl; +} + +void bam_smpl_destroy(bam_smpl_t *bsmpl) +{ + if ( !bsmpl ) return; + if ( bsmpl->name2idx ) khash_str2int_destroy_free(bsmpl->name2idx); + if ( bsmpl->sample_list ) khash_str2str_destroy_free_all(bsmpl->sample_list); + if ( bsmpl->rg_list ) khash_str2str_destroy_free_all(bsmpl->rg_list); + int i; + for (i=0; infiles; i++) + { + file_t *file = &bsmpl->files[i]; + if ( file->rg2idx ) khash_str2int_destroy_free(file->rg2idx); + free(file->fname); + } + free(bsmpl->smpl); + free(bsmpl->files); + free(bsmpl->tmp.s); + free(bsmpl); +} + +void bam_smpl_ignore_readgroups(bam_smpl_t* bsmpl) +{ + bsmpl->ignore_rg = 1; +} + +static void bsmpl_add_readgroup(bam_smpl_t *bsmpl, file_t *file, const char *rg_id, const char *smpl_name) +{ + int ismpl = -1; + if ( smpl_name ) + { + if ( khash_str2int_get(bsmpl->name2idx,smpl_name,&ismpl) < 0 ) + { + // new sample + bsmpl->nsmpl++; + bsmpl->smpl = (char**) realloc(bsmpl->smpl,sizeof(char*)*bsmpl->nsmpl); + bsmpl->smpl[bsmpl->nsmpl-1] = strdup(smpl_name); + ismpl = khash_str2int_inc(bsmpl->name2idx,bsmpl->smpl[bsmpl->nsmpl-1]); + } + } + if ( !strcmp("*",rg_id) ) + { + // all read groups in the bam treated as the same sample + file->default_idx = ismpl; + return; + } + if ( !file->rg2idx ) file->rg2idx = khash_str2int_init(); + if ( khash_str2int_has_key(file->rg2idx,rg_id) ) return; // duplicate @RG:ID + khash_str2int_set(file->rg2idx, strdup(rg_id), ismpl); +} +static int bsmpl_keep_readgroup(bam_smpl_t *bsmpl, file_t *file, const char *rg_id, const char **smpl_name) +{ + char *rg_smpl = khash_str2str_get(bsmpl->rg_list,rg_id); // unique read group present in one bam only + if ( !rg_smpl ) + { + // read group specific to this bam + bsmpl->tmp.l = 0; + ksprintf(&bsmpl->tmp,"%s\t%s",rg_id,file->fname); + rg_smpl = khash_str2str_get(bsmpl->rg_list,bsmpl->tmp.s); + } + if ( !rg_smpl ) + { + // any read group in this file? + bsmpl->tmp.l = 0; + ksprintf(&bsmpl->tmp,"*\t%s",file->fname); + rg_smpl = khash_str2str_get(bsmpl->rg_list,bsmpl->tmp.s); + } + if ( !rg_smpl && bsmpl->rg_logic ) return 0; + if ( rg_smpl && !bsmpl->rg_logic ) return 0; + + if ( rg_smpl && rg_smpl[0]!='\t' ) *smpl_name = rg_smpl; // rename the sample + return 1; +} + +/* + The logic of this function is a bit complicated because we want to work + also with broken bams containing read groups that are not listed in the + header. The desired behavior is as follows: + - when -G is given, read groups which are not listed in the header must + be given explicitly using the "?" symbol in -G. + Otherwise: + - if the bam has no header, all reads in the file are assigned to a + single sample named after the file + - if there is at least one sample defined in the header, reads with no + read group id or with a read group id not listed in the header are + assigned to the first sample encountered in the header +*/ +int bam_smpl_add_bam(bam_smpl_t *bsmpl, char *bam_hdr, const char *fname) +{ + bsmpl->nfiles++; + bsmpl->files = (file_t*) realloc(bsmpl->files,bsmpl->nfiles*sizeof(file_t)); + file_t *file = &bsmpl->files[bsmpl->nfiles-1]; + memset(file,0,sizeof(file_t)); + file->fname = strdup(fname); + file->default_idx = -1; + + if ( bsmpl->ignore_rg || !bam_hdr ) + { + // The option --ignore-RG is set or there is no BAM header: use the file name as the sample name + bsmpl_add_readgroup(bsmpl,file,"*",file->fname); + return bsmpl->nfiles-1; + } + + void *bam_smpls = khash_str2int_init(); + int first_smpl = -1, nskipped = 0; + const char *p = bam_hdr, *q, *r; + while ((q = strstr(p, "@RG")) != 0) + { + p = q + 3; + r = q = 0; + if ((q = strstr(p, "\tID:")) != 0) q += 4; + if ((r = strstr(p, "\tSM:")) != 0) r += 4; + if (r && q) + { + char *u, *v; + int ioq, ior; + for (u = (char*)q; *u && *u != '\t' && *u != '\n'; ++u); + for (v = (char*)r; *v && *v != '\t' && *v != '\n'; ++v); + ioq = *u; ior = *v; *u = *v = '\0'; + + // q now points to a null terminated read group id + // r points to a null terminated sample name + if ( !strcmp("*",q) || !strcmp("?",q) ) + error("Error: the read group IDs \"*\" and \"?\" have a special meaning in the mpileup code. Please fix the code or the bam: %s\n", fname); + + int accept_rg = 1; + if ( bsmpl->sample_list ) + { + // restrict samples based on the -s/-S options + char *name = khash_str2str_get(bsmpl->sample_list,r); + if ( bsmpl->sample_logic==0 ) + accept_rg = name ? 0 : 1; + else if ( !name ) + accept_rg = 0; + else + r = name; + } + if ( accept_rg && bsmpl->rg_list ) + { + // restrict readgroups based on the -G option, possibly renaming the sample + accept_rg = bsmpl_keep_readgroup(bsmpl,file,q,&r); + } + if ( accept_rg ) + bsmpl_add_readgroup(bsmpl,file,q,r); + else + { + bsmpl_add_readgroup(bsmpl,file,q,NULL); // ignore this RG but note that it was seen in the header + nskipped++; + } + + if ( first_smpl<0 ) + khash_str2int_get(bsmpl->name2idx,r,&first_smpl); + if ( !khash_str2int_has_key(bam_smpls,r) ) + khash_str2int_inc(bam_smpls,strdup(r)); + + *u = ioq; *v = ior; + } + else + break; + p = q > r ? q : r; + } + int nsmpls = khash_str2int_size(bam_smpls); + khash_str2int_destroy_free(bam_smpls); + + const char *smpl_name = NULL; + int accept_null_rg = 1; + if ( bsmpl->rg_list && !bsmpl_keep_readgroup(bsmpl,file,"?",&smpl_name) ) accept_null_rg = 0; + if ( bsmpl->sample_list && first_smpl==-1 ) accept_null_rg = 0; + + if ( !accept_null_rg && first_smpl==-1 ) + { + // no suitable read group is available in this bam: ignore the whole file. + free(file->fname); + bsmpl->nfiles--; + return -1; + } + if ( !accept_null_rg ) return bsmpl->nfiles-1; + if ( nsmpls==1 && !nskipped ) + { + file->default_idx = first_smpl; + return bsmpl->nfiles-1; + } + if ( !smpl_name ) smpl_name = first_smpl==-1 ? file->fname : bsmpl->smpl[first_smpl]; + + bsmpl_add_readgroup(bsmpl,file,"?",smpl_name); + return bsmpl->nfiles-1; +} + +const char **bam_smpl_get_samples(bam_smpl_t *bsmpl, int *nsmpl) +{ + *nsmpl = bsmpl->nsmpl; + return (const char**)bsmpl->smpl; +} + +int bam_smpl_get_sample_id(bam_smpl_t *bsmpl, int bam_id, bam1_t *bam_rec) +{ + file_t *file = &bsmpl->files[bam_id]; + if ( file->default_idx >= 0 ) return file->default_idx; + + char *aux_rg = (char*) bam_aux_get(bam_rec, "RG"); + aux_rg = aux_rg ? aux_rg+1 : "?"; + + int rg_id; + if ( khash_str2int_get(file->rg2idx, aux_rg, &rg_id)==0 ) return rg_id; + if ( khash_str2int_get(file->rg2idx, "?", &rg_id)==0 ) return rg_id; + return -1; +} + +int bam_smpl_add_samples(bam_smpl_t *bsmpl, char *list, int is_file) +{ + if ( list[0]!='^' ) bsmpl->sample_logic = 1; + else list++; + + int i, nsamples = 0; + char **samples = hts_readlist(list, is_file, &nsamples); + if ( !nsamples ) return 0; + + kstring_t ori = {0,0,0}; + kstring_t ren = {0,0,0}; + + bsmpl->sample_list = khash_str2str_init(); + for (i=0; isample_list,strdup(ori.s),strdup(ren.l?ren.s:ori.s)); + free(samples[i]); + } + free(samples); + free(ori.s); + free(ren.s); + return nsamples; +} + +int bam_smpl_add_readgroups(bam_smpl_t *bsmpl, char *list, int is_file) +{ + if ( list[0]!='^' ) bsmpl->rg_logic = 1; + else list++; + + int i, nrows = 0; + char **rows = hts_readlist(list, is_file, &nrows); + if ( !nrows ) return 0; + + kstring_t fld1 = {0,0,0}; + kstring_t fld2 = {0,0,0}; + kstring_t fld3 = {0,0,0}; + + bsmpl->rg_list = khash_str2str_init(); + for (i=0; irg_list,fld1.s); + if ( !value ) + khash_str2str_set(bsmpl->rg_list,strdup(fld1.s),strdup(fld2.l?fld2.s:"\t")); + else if ( strcmp(value,fld2.l?fld2.s:"\t") ) + error("Error: The read group \"%s\" was assigned to two different samples: \"%s\" and \"%s\"\n", fld1.s,value,fld2.l?fld2.s:"\t"); + free(rows[i]); + } + free(rows); + free(fld1.s); + free(fld2.s); + free(fld3.s); + return nrows; +} + + diff --git a/bcftools/bam_sample.h b/bcftools/bam_sample.h new file mode 100644 index 000000000..5cbcc3917 --- /dev/null +++ b/bcftools/bam_sample.h @@ -0,0 +1,50 @@ +/* bam_sample.h -- group data by sample. + + Copyright (C) 2010 Broad Institute. + Copyright (C) 2016 Genome Research Ltd. + + Author: Heng Li , Petr Danecek + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#ifndef BAM_SAMPLE_H +#define BAM_SAMPLE_H + +#include + +typedef struct _bam_smpl_t bam_smpl_t; + +bam_smpl_t *bam_smpl_init(void); + +int bam_smpl_add_samples(bam_smpl_t *bsmpl, char *list, int is_file); +int bam_smpl_add_readgroups(bam_smpl_t *bsmpl, char *list, int is_file); +void bam_smpl_ignore_readgroups(bam_smpl_t* bsmpl); + +// The above should be called only before bams are added. Returns the BAM id +// to be passed to bam_smpl_get_sample_id() later. It is safe to assume +// sequential numbering, starting from 0. +// +int bam_smpl_add_bam(bam_smpl_t *bsmpl, char *bam_hdr, const char *fname); + +const char **bam_smpl_get_samples(bam_smpl_t *bsmpl, int *nsmpl); +int bam_smpl_get_sample_id(bam_smpl_t *bsmpl, int bam_id, bam1_t *bam_rec); + +void bam_smpl_destroy(bam_smpl_t *bsmpl); + +#endif diff --git a/bcftools/bcftools.h b/bcftools/bcftools.h index d4e856da7..d3ba81419 100644 --- a/bcftools/bcftools.h +++ b/bcftools/bcftools.h @@ -30,6 +30,7 @@ THE SOFTWARE. */ #include #include +#define FT_TAB_TEXT 0 // custom tab-delimited text file #define FT_GZ 1 #define FT_VCF 2 #define FT_VCF_GZ (FT_GZ|FT_VCF) @@ -62,6 +63,29 @@ static inline char gt2iupac(char a, char b) return iupac[(int)a][(int)b]; } +static inline int iupac_consistent(char iupac, char nt) +{ + static const char iupac_mask[90] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,14,2, + 13,0,0,4,11,0,0,12,0,3,15,0,0,0,5,6,8,0,7,9,0,10 + }; + if ( iupac > 89 ) return 0; + if ( nt > 90 ) nt -= 32; // lowercase + if ( nt=='A' ) nt = 1; + else if ( nt=='C' ) nt = 2; + else if ( nt=='G' ) nt = 4; + else if ( nt=='T' ) nt = 8; + return iupac_mask[(int)iupac] & nt ? 1 : 0; +} + +static inline char nt_to_upper(char nt) +{ + if ( nt < 97 ) return nt; + return nt - 32; +} + static inline double phred_score(double prob) { if ( prob==0 ) return 99; diff --git a/bcftools/bcftools.pysam.c b/bcftools/bcftools.pysam.c new file mode 100644 index 000000000..63dfed5be --- /dev/null +++ b/bcftools/bcftools.pysam.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include +#include + +#include "bcftools.pysam.h" + +FILE * bcftools_stderr = NULL; +FILE * bcftools_stdout = NULL; +const char * bcftools_stdout_fn = NULL; +int bcftools_stdout_fileno = STDOUT_FILENO; + + +FILE * bcftools_set_stderr(int fd) +{ + if (bcftools_stderr != NULL) + fclose(bcftools_stderr); + bcftools_stderr = fdopen(fd, "w"); + return bcftools_stderr; +} + +void bcftools_unset_stderr(void) +{ + if (bcftools_stderr != NULL) + fclose(bcftools_stderr); + bcftools_stderr = fopen("/dev/null", "w"); +} + +FILE * bcftools_set_stdout(int fd) +{ + if (bcftools_stdout != NULL) + fclose(bcftools_stdout); + bcftools_stdout = fdopen(fd, "w"); + if (bcftools_stdout == NULL) + { + fprintf(bcftools_stderr, "could not set stdout to fd %i", fd); + } + bcftools_stdout_fileno = fd; + return bcftools_stdout; +} + +void bcftools_set_stdout_fn(const char *fn) +{ + bcftools_stdout_fn = fn; +} + +void bcftools_unset_stdout(void) +{ + if (bcftools_stdout != NULL) + fclose(bcftools_stdout); + bcftools_stdout = fopen("/dev/null", "w"); + bcftools_stdout_fileno = STDOUT_FILENO; +} + +void bcftools_set_optind(int val) +{ + // setting this in cython via + // "from posix.unistd cimport optind" + // did not work. + // + // setting to 0 forces a complete re-initialization + optind = val; +} + + + diff --git a/bcftools/bcftools.pysam.h b/bcftools/bcftools.pysam.h new file mode 100644 index 000000000..4c3806ccf --- /dev/null +++ b/bcftools/bcftools.pysam.h @@ -0,0 +1,47 @@ +#ifndef BCFTOOLS_PYSAM_H +#define BCFTOOLS_PYSAM_H + +#include "stdio.h" + +extern FILE * bcftools_stderr; + +extern FILE * bcftools_stdout; + +extern const char * bcftools_stdout_fn; + +/*! set pysam standard error to point to file descriptor + + Setting the stderr will close the previous stderr. + */ +FILE * bcftools_set_stderr(int fd); + +/*! set pysam standard output to point to file descriptor + + Setting the stderr will close the previous stdout. + */ +FILE * bcftools_set_stdout(int fd); + +/*! set pysam standard output to point to filename + + */ +void bcftools_set_stdout_fn(const char * fn); + +/*! set pysam standard error to /dev/null. + + Unsetting the stderr will close the previous stderr. + */ +void bcftools_unset_stderr(void); + +/*! set pysam standard error to /dev/null. + + Unsetting the stderr will close the previous stderr. + */ +void bcftools_unset_stdout(void); + +int bcftools_dispatch(int argc, char *argv[]); + +void bcftools_set_optind(int); + +extern int bcftools_main(int argc, char *argv[]); + +#endif diff --git a/bcftools/bin.c b/bcftools/bin.c new file mode 100644 index 000000000..b558b208a --- /dev/null +++ b/bcftools/bin.c @@ -0,0 +1,104 @@ +/* The MIT License + + Copyright (c) 2016 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#include +#include "bcftools.h" +#include "bin.h" + +struct _bin_t +{ + float *bins; + int nbins; +}; + +bin_t *bin_init(const char *list_def, float min, float max) +{ + bin_t *bin = (bin_t*) calloc(1,sizeof(bin_t)); + + // a comma indicates a list, otherwise a file + int is_file = strchr(list_def,',') ? 0 : 1; + int i, nlist; + char **list = hts_readlist(list_def, is_file, &nlist); + bin->nbins = nlist; + bin->bins = (float*) malloc(sizeof(float)*nlist); + for (i=0; ibins[i] = strtod(list[i],&tmp); + if ( !tmp ) error("Could not parse %s: %s\n", list_def, list[i]); + if ( min!=max && (bin->bins[i]bins[i]>max) ) + error("Expected values from the interval [%f,%f], found %s\n", list[i]); + free(list[i]); + } + free(list); + + if ( min!=max ) + { + // make sure we've got both boundaries: min,max. + assert( nlist>1 ); + float max_err = (bin->bins[1] - bin->bins[0])*1e-6; + if ( fabs(bin->bins[0] - min) > max_err ) + { + bin->bins = (float*) realloc(bin->bins, (++bin->nbins)*sizeof(float)); + memmove(bin->bins+1, bin->bins, sizeof(float)*(bin->nbins-1)); + bin->bins[0] = min; + } + if ( fabs(bin->bins[bin->nbins-1] - max) > max_err ) + { + bin->bins = (float*) realloc(bin->bins, (++bin->nbins)*sizeof(float)); + bin->bins[bin->nbins-1] = max; + } + } + return bin; +} + +void bin_destroy(bin_t *bin) +{ + free(bin->bins); + free(bin); +} + +int bin_get_size(bin_t *bin) { return bin->nbins; } + +float bin_get_value(bin_t *bin, int idx) { return bin->bins[idx]; } + +int bin_get_idx(bin_t *bin, float value) +{ + if ( bin->bins[bin->nbins-1] < value ) return bin->nbins-1; + + // Binary search in half-closed,half-open intervals [) + int imin = 0, imax = bin->nbins - 2; + while ( iminbins[i] ) imax = i - 1; + else if ( value > bin->bins[i] ) imin = i + 1; + else return i; + } + if ( bin->bins[imax] <= value ) return imax; + return imin - 1; +} + diff --git a/bcftools/bin.c.pysam.c b/bcftools/bin.c.pysam.c new file mode 100644 index 000000000..4880231b6 --- /dev/null +++ b/bcftools/bin.c.pysam.c @@ -0,0 +1,106 @@ +#include "bcftools.pysam.h" + +/* The MIT License + + Copyright (c) 2016 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#include +#include "bcftools.h" +#include "bin.h" + +struct _bin_t +{ + float *bins; + int nbins; +}; + +bin_t *bin_init(const char *list_def, float min, float max) +{ + bin_t *bin = (bin_t*) calloc(1,sizeof(bin_t)); + + // a comma indicates a list, otherwise a file + int is_file = strchr(list_def,',') ? 0 : 1; + int i, nlist; + char **list = hts_readlist(list_def, is_file, &nlist); + bin->nbins = nlist; + bin->bins = (float*) malloc(sizeof(float)*nlist); + for (i=0; ibins[i] = strtod(list[i],&tmp); + if ( !tmp ) error("Could not parse %s: %s\n", list_def, list[i]); + if ( min!=max && (bin->bins[i]bins[i]>max) ) + error("Expected values from the interval [%f,%f], found %s\n", list[i]); + free(list[i]); + } + free(list); + + if ( min!=max ) + { + // make sure we've got both boundaries: min,max. + assert( nlist>1 ); + float max_err = (bin->bins[1] - bin->bins[0])*1e-6; + if ( fabs(bin->bins[0] - min) > max_err ) + { + bin->bins = (float*) realloc(bin->bins, (++bin->nbins)*sizeof(float)); + memmove(bin->bins+1, bin->bins, sizeof(float)*(bin->nbins-1)); + bin->bins[0] = min; + } + if ( fabs(bin->bins[bin->nbins-1] - max) > max_err ) + { + bin->bins = (float*) realloc(bin->bins, (++bin->nbins)*sizeof(float)); + bin->bins[bin->nbins-1] = max; + } + } + return bin; +} + +void bin_destroy(bin_t *bin) +{ + free(bin->bins); + free(bin); +} + +int bin_get_size(bin_t *bin) { return bin->nbins; } + +float bin_get_value(bin_t *bin, int idx) { return bin->bins[idx]; } + +int bin_get_idx(bin_t *bin, float value) +{ + if ( bin->bins[bin->nbins-1] < value ) return bin->nbins-1; + + // Binary search in half-closed,half-open intervals [) + int imin = 0, imax = bin->nbins - 2; + while ( iminbins[i] ) imax = i - 1; + else if ( value > bin->bins[i] ) imin = i + 1; + else return i; + } + if ( bin->bins[imax] <= value ) return imax; + return imin - 1; +} + diff --git a/bcftools/bin.h b/bcftools/bin.h new file mode 100644 index 000000000..ab9e5b1b6 --- /dev/null +++ b/bcftools/bin.h @@ -0,0 +1,65 @@ +/* The MIT License + + Copyright (c) 2016 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +/* + Simple binning of float values into predefined bins +*/ + +#ifndef __BIN_H__ +#define __BIN_H__ + +#include + +typedef struct _bin_t bin_t; + +/* + * bin_init() - init bins + * @list: list of half-open intervals [). If the list does not contain commas, + * it is interpreted as a file name. + * @min,max: extreme values. This is for user convenience so that well-known + * extremes can be left out from the list. Ignored if min=max + */ +bin_t *bin_init(const char *list, float min, float max); +void bin_destroy(bin_t *bin); + +/* + * bin_get_size() - number of boundaries, subtract 1 to get the number of bins + */ +int bin_get_size(bin_t *bin); + +/* + bin_get_idx() - find the bin index which corresponds to the value (binary search) + Returns the bin index 0 <= idx <= size-2 or -1,size-1 for out of range values. + */ +int bin_get_idx(bin_t *bin, float value); + +/* + bin_get_value() - get the i-th boundary value, i=0,..,size-1 + */ +float bin_get_value(bin_t *bin, int ith); + +#endif + diff --git a/bcftools/call.h b/bcftools/call.h index bbf0a52b4..0d707a05c 100644 --- a/bcftools/call.h +++ b/bcftools/call.h @@ -72,6 +72,7 @@ typedef struct double trio_Pm_SNPs, trio_Pm_del, trio_Pm_ins; // P(mendelian) for trio calling, see mcall_call_trio_genotypes() int32_t *ugts, *cgts; // unconstraind and constrained GTs uint32_t output_tags; + char *prior_AN, *prior_AC; // reference panel AF tags (AF=AC/AN) // ccall only double indel_frac, min_perm_p, min_lrt; @@ -102,7 +103,7 @@ call_t; void error(const char *format, ...); /* - * *call() - return negative value on error or the number of non-reference + * call() - return -1 value on critical error; -2 to skip the site; or the number of non-reference * alleles on success. */ int mcall(call_t *call, bcf1_t *rec); // multiallic and rare-variant calling model diff --git a/bcftools/ccall.c b/bcftools/ccall.c index bb43d6138..9f6958ac4 100644 --- a/bcftools/ccall.c +++ b/bcftools/ccall.c @@ -189,8 +189,6 @@ static int update_bcf1(call_t *call, bcf1_t *rec, const bcf_p1rst_t *pr, double bcf_update_info_string(call->hdr, rec, "CGT", tmp); } } - if (pr == 0) return 1; - is_var = (pr->p_ref < call->pref); r = is_var? pr->p_ref : pr->p_var; @@ -232,11 +230,7 @@ static int update_bcf1(call_t *call, bcf1_t *rec, const bcf_p1rst_t *pr, double // Remove unused alleles int nals_ori = rec->n_allele, nals = !is_var && !(call->flag & CALL_KEEPALT) ? 1 : pr->rank0 < 2? 2 : pr->rank0+1; - if ( call->flag & CALL_KEEPALT && call->unseen>0 ) - { - assert( call->unseen==nals-1 ); - nals--; - } + if ( call->flag & CALL_KEEPALT && call->unseen==nals-1 ) nals--; if ( nalsn_allele ) { @@ -272,7 +266,7 @@ static int update_bcf1(call_t *call, bcf1_t *rec, const bcf_p1rst_t *pr, double int i; for (i=0; in_sample; i++) { - int x = ( is_var || call->output_tags & CALL_FMT_GQ ) ? bcf_p1_call_gt(p1, pr->f_exp, i) : 2; + int x = ( is_var || call->output_tags & CALL_FMT_GQ ) ? bcf_p1_call_gt(p1, pr->f_exp, i, is_var) : 2; int gt = x&3; if ( !call->ploidy || call->ploidy[i]==2 ) { diff --git a/bcftools/ccall.c.pysam.c b/bcftools/ccall.c.pysam.c index d4ceb017b..696b455db 100644 --- a/bcftools/ccall.c.pysam.c +++ b/bcftools/ccall.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* ccall.c -- consensus variant calling. @@ -191,8 +191,6 @@ static int update_bcf1(call_t *call, bcf1_t *rec, const bcf_p1rst_t *pr, double bcf_update_info_string(call->hdr, rec, "CGT", tmp); } } - if (pr == 0) return 1; - is_var = (pr->p_ref < call->pref); r = is_var? pr->p_ref : pr->p_var; @@ -234,11 +232,7 @@ static int update_bcf1(call_t *call, bcf1_t *rec, const bcf_p1rst_t *pr, double // Remove unused alleles int nals_ori = rec->n_allele, nals = !is_var && !(call->flag & CALL_KEEPALT) ? 1 : pr->rank0 < 2? 2 : pr->rank0+1; - if ( call->flag & CALL_KEEPALT && call->unseen>0 ) - { - assert( call->unseen==nals-1 ); - nals--; - } + if ( call->flag & CALL_KEEPALT && call->unseen==nals-1 ) nals--; if ( nalsn_allele ) { @@ -274,7 +268,7 @@ static int update_bcf1(call_t *call, bcf1_t *rec, const bcf_p1rst_t *pr, double int i; for (i=0; in_sample; i++) { - int x = ( is_var || call->output_tags & CALL_FMT_GQ ) ? bcf_p1_call_gt(p1, pr->f_exp, i) : 2; + int x = ( is_var || call->output_tags & CALL_FMT_GQ ) ? bcf_p1_call_gt(p1, pr->f_exp, i, is_var) : 2; int gt = x&3; if ( !call->ploidy || call->ploidy[i]==2 ) { diff --git a/bcftools/config.h b/bcftools/config.h new file mode 100644 index 000000000..f8fff5931 --- /dev/null +++ b/bcftools/config.h @@ -0,0 +1,2 @@ +/* empty config.h created by pysam */ +/* conservative compilation options */ diff --git a/bcftools/consensus.c b/bcftools/consensus.c index 051f3536c..d67a05219 100644 --- a/bcftools/consensus.c +++ b/bcftools/consensus.c @@ -1,6 +1,6 @@ /* The MIT License - Copyright (c) 2014 Genome Research Ltd. + Copyright (c) 2014-2017 Genome Research Ltd. Author: Petr Danecek @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -35,9 +36,19 @@ #include #include #include -#include +#include "regidx.h" #include "bcftools.h" #include "rbuf.h" +#include "filter.h" + +// Logic of the filters: include or exclude sites which match the filters? +#define FLT_INCLUDE 1 +#define FLT_EXCLUDE 2 + +#define PICK_REF 1 +#define PICK_ALT 2 +#define PICK_LONG 4 +#define PICK_SHORT 8 typedef struct { @@ -66,19 +77,25 @@ typedef struct rbuf_t vcf_rbuf; bcf1_t **vcf_buf; int nvcf_buf, rid; + char *chr; regidx_t *mask; + regitr_t *itr; int chain_id; // chain_id, to provide a unique ID to each chain in the chain output chain_t *chain; // chain structure to store the sequence of ungapped blocks between the ref and alt sequences // Note that the chain is re-initialised for each chromosome/seq_region + filter_t *filter; + char *filter_str; + int filter_logic; // include or exclude sites which match the filters? One of FLT_INCLUDE/FLT_EXCLUDE + bcf_srs_t *files; bcf_hdr_t *hdr; FILE *fp_out; FILE *fp_chain; char **argv; - int argc, output_iupac, haplotype, isample; + int argc, output_iupac, haplotype, allele, isample; char *fname, *ref_fname, *sample, *output_fname, *mask_fname, *chain_fname; } args_t; @@ -105,6 +122,8 @@ static void destroy_chain(args_t *args) free(chain->block_lengths); free(chain); chain = NULL; + free(args->chr); + args->chr = NULL; } static void print_chain(args_t *args) @@ -146,7 +165,7 @@ static void print_chain(args_t *args) score += chain->block_lengths[n]; } score += last_block_size; - fprintf(args->fp_chain, "chain %d %s %d + %d %d %s %d + %d %d %d\n", score, bcf_hdr_id2name(args->hdr,args->rid), ref_end_pos, chain->ori_pos, ref_end_pos, bcf_hdr_id2name(args->hdr,args->rid), alt_end_pos, chain->ori_pos, alt_end_pos, ++args->chain_id); + fprintf(args->fp_chain, "chain %d %s %d + %d %d %s %d + %d %d %d\n", score, args->chr, ref_end_pos, chain->ori_pos, ref_end_pos, args->chr, alt_end_pos, chain->ori_pos, alt_end_pos, ++args->chain_id); for (n=0; nnum; n++) { fprintf(args->fp_chain, "%d %d %d\n", chain->block_lengths[n], chain->ref_gaps[n], chain->alt_gaps[n]); } @@ -193,7 +212,7 @@ static void init_data(args_t *args) args->isample = bcf_hdr_id2int(args->hdr,BCF_DT_SAMPLE,args->sample); if ( args->isample<0 ) error("No such sample: %s\n", args->sample); } - if ( args->haplotype && args->isample<0 ) + if ( (args->haplotype || args->allele) && args->isample<0 ) { if ( bcf_hdr_nsamples(args->hdr) > 1 ) error("The --sample option is expected with --haplotype\n"); args->isample = 0; @@ -202,6 +221,7 @@ static void init_data(args_t *args) { args->mask = regidx_init(args->mask_fname,NULL,NULL,0,NULL); if ( !args->mask ) error("Failed to initialize mask regions\n"); + args->itr = regitr_init(args->mask); } // In case we want to store the chains if ( args->chain_fname ) @@ -217,17 +237,23 @@ static void init_data(args_t *args) if ( ! args->fp_out ) error("Failed to create %s: %s\n", args->output_fname, strerror(errno)); } else args->fp_out = stdout; + if ( args->isample<0 ) fprintf(stderr,"Note: the --sample option not given, applying all records\n"); + if ( args->filter_str ) + args->filter = filter_init(args->hdr, args->filter_str); } static void destroy_data(args_t *args) { + if (args->filter) filter_destroy(args->filter); bcf_sr_destroy(args->files); int i; for (i=0; ivcf_rbuf.m; i++) if ( args->vcf_buf[i] ) bcf_destroy1(args->vcf_buf[i]); free(args->vcf_buf); free(args->fa_buf.s); + free(args->chr); if ( args->mask ) regidx_destroy(args->mask); + if ( args->itr ) regitr_destroy(args->itr); if ( args->chain_fname ) if ( fclose(args->fp_chain) ) error("Close failed: %s\n", args->chain_fname); if ( fclose(args->fp_out) ) error("Close failed: %s\n", args->output_fname); @@ -254,6 +280,7 @@ static void init_region(args_t *args, char *line) else to--; } } + args->chr = strdup(line); args->rid = bcf_hdr_name2id(args->hdr,line); if ( args->rid<0 ) fprintf(stderr,"Warning: Sequence \"%s\" not in %s\n", line,args->fname); args->fa_buf.l = 0; @@ -283,9 +310,16 @@ static bcf1_t **next_vcf_line(args_t *args) int i = rbuf_shift(&args->vcf_rbuf); return &args->vcf_buf[i]; } - else if ( bcf_sr_next_line(args->files) ) + while ( bcf_sr_next_line(args->files) ) + { + if ( args->filter ) + { + int is_ok = filter_test(args->filter, bcf_sr_get_line(args->files,0), NULL); + if ( args->filter_logic & FLT_EXCLUDE ) is_ok = is_ok ? 0 : 1; + if ( !is_ok ) continue; + } return &args->files->readers[0].buffer[0]; - + } return NULL; } static void unread_vcf_line(args_t *args, bcf1_t **rec_ptr) @@ -351,52 +385,83 @@ static void apply_variant(args_t *args, bcf1_t *rec) if ( regidx_overlap(args->mask, chr,start,end,NULL) ) return; } - int i, ialt = 1; + int i, ialt = 1; // the alternate allele if ( args->isample >= 0 ) { + bcf_unpack(rec, BCF_UN_FMT); bcf_fmt_t *fmt = bcf_get_fmt(args->hdr, rec, "GT"); if ( !fmt ) return; + + if ( fmt->type!=BCF_BT_INT8 ) + error("Todo: GT field represented with BCF_BT_INT8, too many alleles at %s:%d?\n",bcf_seqname(args->hdr,rec),rec->pos+1); + uint8_t *ptr = fmt->p + fmt->size*args->isample; + if ( args->haplotype ) { if ( args->haplotype > fmt->n ) error("Can't apply %d-th haplotype at %s:%d\n", args->haplotype,bcf_seqname(args->hdr,rec),rec->pos+1); - uint8_t *ignore, *ptr = fmt->p + fmt->size*args->isample + args->haplotype - 1; - ialt = bcf_dec_int1(ptr, fmt->type, &ignore); + ialt = ptr[args->haplotype-1]; if ( bcf_gt_is_missing(ialt) || ialt==bcf_int32_vector_end ) return; ialt = bcf_gt_allele(ialt); } else if ( args->output_iupac ) { - uint8_t *ignore, *ptr = fmt->p + fmt->size*args->isample; - ialt = bcf_dec_int1(ptr, fmt->type, &ignore); + ialt = ptr[0]; if ( bcf_gt_is_missing(ialt) || ialt==bcf_int32_vector_end ) return; ialt = bcf_gt_allele(ialt); int jalt; if ( fmt->n>1 ) { - ptr = fmt->p + fmt->size*args->isample + 1; - jalt = bcf_dec_int1(ptr, fmt->type, &ignore); + jalt = ptr[1]; if ( bcf_gt_is_missing(jalt) || jalt==bcf_int32_vector_end ) jalt = ialt; else jalt = bcf_gt_allele(jalt); } else jalt = ialt; - if ( rec->n_allele <= ialt || rec->n_allele <= jalt ) error("Broken VCF, too few alts at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1); + if ( rec->n_allele <= ialt || rec->n_allele <= jalt ) error("Invalid VCF, too few ALT alleles at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1); if ( ialt!=jalt && !rec->d.allele[ialt][1] && !rec->d.allele[jalt][1] ) // is this a het snp? { char ial = rec->d.allele[ialt][0]; char jal = rec->d.allele[jalt][0]; + if ( !ialt ) ialt = jalt; // only ialt is used, make sure 0/1 is not ignored rec->d.allele[ialt][0] = gt2iupac(ial,jal); } } else { + int is_hom = 1; for (i=0; in; i++) { - uint8_t *ignore, *ptr = fmt->p + fmt->size*args->isample + i; - ialt = bcf_dec_int1(ptr, fmt->type, &ignore); - if ( bcf_gt_is_missing(ialt) || ialt==bcf_int32_vector_end ) return; - ialt = bcf_gt_allele(ialt); - if ( ialt ) break; + if ( bcf_gt_is_missing(ptr[i]) ) return; // ignore missing or half-missing genotypes + if ( ptr[i]==bcf_int32_vector_end ) break; + ialt = bcf_gt_allele(ptr[i]); + if ( i>0 && ialt!=bcf_gt_allele(ptr[i-1]) ) { is_hom = 0; break; } + } + if ( !is_hom ) + { + int prev_len = 0, jalt; + for (i=0; in; i++) + { + if ( ptr[i]==bcf_int32_vector_end ) break; + jalt = bcf_gt_allele(ptr[i]); + if ( rec->n_allele <= jalt ) error("Broken VCF, too few alts at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1); + if ( args->allele & (PICK_LONG|PICK_SHORT) ) + { + int len = jalt==0 ? rec->rlen : strlen(rec->d.allele[jalt]); + if ( i==0 ) ialt = jalt, prev_len = len; + else if ( len == prev_len ) + { + if ( args->allele & PICK_REF && jalt==0 ) ialt = jalt, prev_len = len; + else if ( args->allele & PICK_ALT && ialt==0 ) ialt = jalt, prev_len = len; + } + else if ( args->allele & PICK_LONG && len > prev_len ) ialt = jalt, prev_len = len; + else if ( args->allele & PICK_SHORT && len < prev_len ) ialt = jalt, prev_len = len; + } + else + { + if ( args->allele & PICK_REF && jalt==0 ) ialt = jalt; + else if ( args->allele & PICK_ALT && ialt==0 ) ialt = jalt; + } + } } } if ( !ialt ) return; // ref allele @@ -409,12 +474,27 @@ static void apply_variant(args_t *args, bcf1_t *rec) rec->d.allele[1][0] = gt2iupac(ial,jal); } + int len_diff = 0, alen = 0; int idx = rec->pos - args->fa_ori_pos + args->fa_mod_off; - if ( idx<0 || idx>=args->fa_buf.l ) + if ( idx<0 ) + { + fprintf(stderr,"Warning: ignoring overlapping variant starting at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1); + return; + } + if ( rec->rlen > args->fa_buf.l - idx ) + { + rec->rlen = args->fa_buf.l - idx; + alen = strlen(rec->d.allele[ialt]); + if ( alen > rec->rlen ) + { + rec->d.allele[ialt][rec->rlen] = 0; + fprintf(stderr,"Warning: trimming variant starting at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1); + } + } + if ( idx>=args->fa_buf.l ) error("FIXME: %s:%d .. idx=%d, ori_pos=%d, len=%d, off=%d\n",bcf_seqname(args->hdr,rec),rec->pos+1,idx,args->fa_ori_pos,args->fa_buf.l,args->fa_mod_off); // sanity check the reference base - int len_diff = 0, alen = 0; if ( rec->d.allele[ialt][0]=='<' ) { if ( strcasecmp(rec->d.allele[ialt], "") ) @@ -491,22 +571,19 @@ static void apply_variant(args_t *args, bcf1_t *rec) static void mask_region(args_t *args, char *seq, int len) { - char *chr = (char*)bcf_hdr_id2name(args->hdr,args->rid); int start = args->fa_src_pos - len; int end = args->fa_src_pos; - regitr_t itr; - if ( !regidx_overlap(args->mask, chr,start,end, &itr) ) return; + if ( !regidx_overlap(args->mask, args->chr,start,end, args->itr) ) return; int idx_start, idx_end, i; - while ( REGITR_OVERLAP(itr,start,end) ) + while ( regitr_overlap(args->itr) ) { - idx_start = REGITR_START(itr) - start; - idx_end = REGITR_END(itr) - start; + idx_start = args->itr->beg - start; + idx_end = args->itr->end - start; if ( idx_start < 0 ) idx_start = 0; if ( idx_end >= len ) idx_end = len - 1; for (i=idx_start; i<=idx_end; i++) seq[i] = 'N'; - itr.i++; } } @@ -519,13 +596,14 @@ static void consensus(args_t *args) { if ( str.s[0]=='>' ) { - // new sequence encountered, apply all chached variants + // new sequence encountered + if (args->chain) { + print_chain(args); + destroy_chain(args); + } + // apply all cached variants while ( args->vcf_rbuf.n ) { - if (args->chain) { - print_chain(args); - destroy_chain(args); - } bcf1_t *rec = args->vcf_buf[args->vcf_rbuf.f]; if ( rec->rid!=args->rid || ( args->fa_end_pos && rec->pos > args->fa_end_pos ) ) break; int i = rbuf_shift(&args->vcf_rbuf); @@ -576,7 +654,17 @@ static void consensus(args_t *args) } if ( !rec_ptr ) flush_fa_buffer(args, 60); } - if (args->chain) { + bcf1_t **rec_ptr = NULL; + while ( args->rid>=0 && (rec_ptr = next_vcf_line(args)) ) + { + bcf1_t *rec = *rec_ptr; + if ( rec->rid!=args->rid ) break; + if ( args->fa_end_pos && rec->pos > args->fa_end_pos ) break; + if ( args->fa_ori_pos + args->fa_buf.l - args->fa_mod_off <= rec->pos ) break; + apply_variant(args, rec); + } + if (args->chain) + { print_chain(args); destroy_chain(args); } @@ -588,16 +676,28 @@ static void consensus(args_t *args) static void usage(args_t *args) { fprintf(stderr, "\n"); - fprintf(stderr, "About: Create consensus sequence by applying VCF variants to a reference\n"); - fprintf(stderr, " fasta file.\n"); + fprintf(stderr, "About: Create consensus sequence by applying VCF variants to a reference fasta\n"); + fprintf(stderr, " file. By default, the program will apply all ALT variants. Using the\n"); + fprintf(stderr, " --sample (and, optionally, --haplotype) option will apply genotype\n"); + fprintf(stderr, " (or haplotype) calls from FORMAT/GT. The program ignores allelic depth\n"); + fprintf(stderr, " information, such as INFO/AD or FORMAT/AD.\n"); fprintf(stderr, "Usage: bcftools consensus [OPTIONS] \n"); fprintf(stderr, "Options:\n"); + fprintf(stderr, " -c, --chain write a chain file for liftover\n"); + fprintf(stderr, " -e, --exclude exclude sites for which the expression is true (see man page for details)\n"); fprintf(stderr, " -f, --fasta-ref reference sequence in fasta format\n"); - fprintf(stderr, " -H, --haplotype <1|2> apply variants for the given haplotype\n"); - fprintf(stderr, " -i, --iupac-codes output variants in the form of IUPAC ambiguity codes\n"); + fprintf(stderr, " -H, --haplotype choose which allele to use from the FORMAT/GT field, note\n"); + fprintf(stderr, " the codes are case-insensitive:\n"); + fprintf(stderr, " 1: first allele from GT\n"); + fprintf(stderr, " 2: second allele\n"); + fprintf(stderr, " R: REF allele in het genotypes\n"); + fprintf(stderr, " A: ALT allele\n"); + fprintf(stderr, " LR,LA: longer allele and REF/ALT if equal length\n"); + fprintf(stderr, " SR,SA: shorter allele and REF/ALT if equal length\n"); + fprintf(stderr, " -i, --include select sites for which the expression is true (see man page for details)\n"); + fprintf(stderr, " -I, --iupac-codes output variants in the form of IUPAC ambiguity codes\n"); fprintf(stderr, " -m, --mask replace regions with N\n"); fprintf(stderr, " -o, --output write output to a file [standard output]\n"); - fprintf(stderr, " -c, --chain write a chain file for liftover\n"); fprintf(stderr, " -s, --sample apply variants of the given sample\n"); fprintf(stderr, "Examples:\n"); fprintf(stderr, " # Get the consensus for one region. The fasta header lines are then expected\n"); @@ -614,8 +714,10 @@ int main_consensus(int argc, char *argv[]) static struct option loptions[] = { + {"exclude",required_argument,NULL,'e'}, + {"include",required_argument,NULL,'i'}, {"sample",1,0,'s'}, - {"iupac-codes",0,0,'i'}, + {"iupac-codes",0,0,'I'}, {"haplotype",1,0,'H'}, {"output",1,0,'o'}, {"fasta-ref",1,0,'f'}, @@ -624,19 +726,32 @@ int main_consensus(int argc, char *argv[]) {0,0,0,0} }; int c; - while ((c = getopt_long(argc, argv, "h?s:1iH:f:o:m:c:",loptions,NULL)) >= 0) + while ((c = getopt_long(argc, argv, "h?s:1Ii:e:H:f:o:m:c:",loptions,NULL)) >= 0) { switch (c) { case 's': args->sample = optarg; break; case 'o': args->output_fname = optarg; break; - case 'i': args->output_iupac = 1; break; + case 'I': args->output_iupac = 1; break; + case 'e': args->filter_str = optarg; args->filter_logic |= FLT_EXCLUDE; break; + case 'i': args->filter_str = optarg; args->filter_logic |= FLT_INCLUDE; break; case 'f': args->ref_fname = optarg; break; case 'm': args->mask_fname = optarg; break; case 'c': args->chain_fname = optarg; break; case 'H': - args->haplotype = optarg[0] - '0'; - if ( args->haplotype <=0 ) error("Expected positive integer with --haplotype\n"); + if ( !strcasecmp(optarg,"R") ) args->allele |= PICK_REF; + else if ( !strcasecmp(optarg,"A") ) args->allele |= PICK_ALT; + else if ( !strcasecmp(optarg,"L") ) args->allele |= PICK_LONG|PICK_REF; + else if ( !strcasecmp(optarg,"S") ) args->allele |= PICK_SHORT|PICK_REF; + else if ( !strcasecmp(optarg,"LR") ) args->allele |= PICK_LONG|PICK_REF; + else if ( !strcasecmp(optarg,"LA") ) args->allele |= PICK_LONG|PICK_ALT; + else if ( !strcasecmp(optarg,"SR") ) args->allele |= PICK_SHORT|PICK_REF; + else if ( !strcasecmp(optarg,"SA") ) args->allele |= PICK_SHORT|PICK_ALT; + else + { + args->haplotype = optarg[0] - '0'; + if ( args->haplotype <=0 ) error("Expected positive integer with --haplotype\n"); + } break; default: usage(args); break; } diff --git a/bcftools/consensus.c.pysam.c b/bcftools/consensus.c.pysam.c index 91aa5ae0d..901560181 100644 --- a/bcftools/consensus.c.pysam.c +++ b/bcftools/consensus.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* The MIT License - Copyright (c) 2014 Genome Research Ltd. + Copyright (c) 2014-2017 Genome Research Ltd. Author: Petr Danecek @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -37,9 +38,19 @@ #include #include #include -#include +#include "regidx.h" #include "bcftools.h" #include "rbuf.h" +#include "filter.h" + +// Logic of the filters: include or exclude sites which match the filters? +#define FLT_INCLUDE 1 +#define FLT_EXCLUDE 2 + +#define PICK_REF 1 +#define PICK_ALT 2 +#define PICK_LONG 4 +#define PICK_SHORT 8 typedef struct { @@ -68,26 +79,32 @@ typedef struct rbuf_t vcf_rbuf; bcf1_t **vcf_buf; int nvcf_buf, rid; + char *chr; regidx_t *mask; + regitr_t *itr; int chain_id; // chain_id, to provide a unique ID to each chain in the chain output chain_t *chain; // chain structure to store the sequence of ungapped blocks between the ref and alt sequences // Note that the chain is re-initialised for each chromosome/seq_region + filter_t *filter; + char *filter_str; + int filter_logic; // include or exclude sites which match the filters? One of FLT_INCLUDE/FLT_EXCLUDE + bcf_srs_t *files; bcf_hdr_t *hdr; FILE *fp_out; FILE *fp_chain; char **argv; - int argc, output_iupac, haplotype, isample; + int argc, output_iupac, haplotype, allele, isample; char *fname, *ref_fname, *sample, *output_fname, *mask_fname, *chain_fname; } args_t; static chain_t* init_chain(chain_t *chain, int ref_ori_pos) { -// fprintf(pysam_stderr, "init_chain(*chain, ref_ori_pos=%d)\n", ref_ori_pos); +// fprintf(bcftools_stderr, "init_chain(*chain, ref_ori_pos=%d)\n", ref_ori_pos); chain = (chain_t*) calloc(1,sizeof(chain_t)); chain->num = 0; chain->block_lengths = NULL; @@ -107,6 +124,8 @@ static void destroy_chain(args_t *args) free(chain->block_lengths); free(chain); chain = NULL; + free(args->chr); + args->chr = NULL; } static void print_chain(args_t *args) @@ -148,7 +167,7 @@ static void print_chain(args_t *args) score += chain->block_lengths[n]; } score += last_block_size; - fprintf(args->fp_chain, "chain %d %s %d + %d %d %s %d + %d %d %d\n", score, bcf_hdr_id2name(args->hdr,args->rid), ref_end_pos, chain->ori_pos, ref_end_pos, bcf_hdr_id2name(args->hdr,args->rid), alt_end_pos, chain->ori_pos, alt_end_pos, ++args->chain_id); + fprintf(args->fp_chain, "chain %d %s %d + %d %d %s %d + %d %d %d\n", score, args->chr, ref_end_pos, chain->ori_pos, ref_end_pos, args->chr, alt_end_pos, chain->ori_pos, alt_end_pos, ++args->chain_id); for (n=0; nnum; n++) { fprintf(args->fp_chain, "%d %d %d\n", chain->block_lengths[n], chain->ref_gaps[n], chain->alt_gaps[n]); } @@ -157,7 +176,7 @@ static void print_chain(args_t *args) static void push_chain_gap(chain_t *chain, int ref_start, int ref_len, int alt_start, int alt_len) { -// fprintf(pysam_stderr, "push_chain_gap(*chain, ref_start=%d, ref_len=%d, alt_start=%d, alt_len=%d)\n", ref_start, ref_len, alt_start, alt_len); +// fprintf(bcftools_stderr, "push_chain_gap(*chain, ref_start=%d, ref_len=%d, alt_start=%d, alt_len=%d)\n", ref_start, ref_len, alt_start, alt_len); int num = chain->num; if (ref_start <= chain->ref_last_block_ori) { @@ -195,7 +214,7 @@ static void init_data(args_t *args) args->isample = bcf_hdr_id2int(args->hdr,BCF_DT_SAMPLE,args->sample); if ( args->isample<0 ) error("No such sample: %s\n", args->sample); } - if ( args->haplotype && args->isample<0 ) + if ( (args->haplotype || args->allele) && args->isample<0 ) { if ( bcf_hdr_nsamples(args->hdr) > 1 ) error("The --sample option is expected with --haplotype\n"); args->isample = 0; @@ -204,6 +223,7 @@ static void init_data(args_t *args) { args->mask = regidx_init(args->mask_fname,NULL,NULL,0,NULL); if ( !args->mask ) error("Failed to initialize mask regions\n"); + args->itr = regitr_init(args->mask); } // In case we want to store the chains if ( args->chain_fname ) @@ -218,18 +238,24 @@ static void init_data(args_t *args) args->fp_out = fopen(args->output_fname,"w"); if ( ! args->fp_out ) error("Failed to create %s: %s\n", args->output_fname, strerror(errno)); } - else args->fp_out = pysam_stdout; + else args->fp_out = bcftools_stdout; + if ( args->isample<0 ) fprintf(bcftools_stderr,"Note: the --sample option not given, applying all records\n"); + if ( args->filter_str ) + args->filter = filter_init(args->hdr, args->filter_str); } static void destroy_data(args_t *args) { + if (args->filter) filter_destroy(args->filter); bcf_sr_destroy(args->files); int i; for (i=0; ivcf_rbuf.m; i++) if ( args->vcf_buf[i] ) bcf_destroy1(args->vcf_buf[i]); free(args->vcf_buf); free(args->fa_buf.s); + free(args->chr); if ( args->mask ) regidx_destroy(args->mask); + if ( args->itr ) regitr_destroy(args->itr); if ( args->chain_fname ) if ( fclose(args->fp_chain) ) error("Close failed: %s\n", args->chain_fname); if ( fclose(args->fp_out) ) error("Close failed: %s\n", args->output_fname); @@ -256,8 +282,9 @@ static void init_region(args_t *args, char *line) else to--; } } + args->chr = strdup(line); args->rid = bcf_hdr_name2id(args->hdr,line); - if ( args->rid<0 ) fprintf(pysam_stderr,"Warning: Sequence \"%s\" not in %s\n", line,args->fname); + if ( args->rid<0 ) fprintf(bcftools_stderr,"Warning: Sequence \"%s\" not in %s\n", line,args->fname); args->fa_buf.l = 0; args->fa_length = 0; args->fa_end_pos = to; @@ -285,9 +312,16 @@ static bcf1_t **next_vcf_line(args_t *args) int i = rbuf_shift(&args->vcf_rbuf); return &args->vcf_buf[i]; } - else if ( bcf_sr_next_line(args->files) ) + while ( bcf_sr_next_line(args->files) ) + { + if ( args->filter ) + { + int is_ok = filter_test(args->filter, bcf_sr_get_line(args->files,0), NULL); + if ( args->filter_logic & FLT_EXCLUDE ) is_ok = is_ok ? 0 : 1; + if ( !is_ok ) continue; + } return &args->files->readers[0].buffer[0]; - + } return NULL; } static void unread_vcf_line(args_t *args, bcf1_t **rec_ptr) @@ -342,7 +376,7 @@ static void apply_variant(args_t *args, bcf1_t *rec) if ( rec->pos <= args->fa_frz_pos ) { - fprintf(pysam_stderr,"The site %s:%d overlaps with another variant, skipping...\n", bcf_seqname(args->hdr,rec),rec->pos+1); + fprintf(bcftools_stderr,"The site %s:%d overlaps with another variant, skipping...\n", bcf_seqname(args->hdr,rec),rec->pos+1); return; } if ( args->mask ) @@ -353,52 +387,83 @@ static void apply_variant(args_t *args, bcf1_t *rec) if ( regidx_overlap(args->mask, chr,start,end,NULL) ) return; } - int i, ialt = 1; + int i, ialt = 1; // the alternate allele if ( args->isample >= 0 ) { + bcf_unpack(rec, BCF_UN_FMT); bcf_fmt_t *fmt = bcf_get_fmt(args->hdr, rec, "GT"); if ( !fmt ) return; + + if ( fmt->type!=BCF_BT_INT8 ) + error("Todo: GT field represented with BCF_BT_INT8, too many alleles at %s:%d?\n",bcf_seqname(args->hdr,rec),rec->pos+1); + uint8_t *ptr = fmt->p + fmt->size*args->isample; + if ( args->haplotype ) { if ( args->haplotype > fmt->n ) error("Can't apply %d-th haplotype at %s:%d\n", args->haplotype,bcf_seqname(args->hdr,rec),rec->pos+1); - uint8_t *ignore, *ptr = fmt->p + fmt->size*args->isample + args->haplotype - 1; - ialt = bcf_dec_int1(ptr, fmt->type, &ignore); + ialt = ptr[args->haplotype-1]; if ( bcf_gt_is_missing(ialt) || ialt==bcf_int32_vector_end ) return; ialt = bcf_gt_allele(ialt); } else if ( args->output_iupac ) { - uint8_t *ignore, *ptr = fmt->p + fmt->size*args->isample; - ialt = bcf_dec_int1(ptr, fmt->type, &ignore); + ialt = ptr[0]; if ( bcf_gt_is_missing(ialt) || ialt==bcf_int32_vector_end ) return; ialt = bcf_gt_allele(ialt); int jalt; if ( fmt->n>1 ) { - ptr = fmt->p + fmt->size*args->isample + 1; - jalt = bcf_dec_int1(ptr, fmt->type, &ignore); + jalt = ptr[1]; if ( bcf_gt_is_missing(jalt) || jalt==bcf_int32_vector_end ) jalt = ialt; else jalt = bcf_gt_allele(jalt); } else jalt = ialt; - if ( rec->n_allele <= ialt || rec->n_allele <= jalt ) error("Broken VCF, too few alts at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1); + if ( rec->n_allele <= ialt || rec->n_allele <= jalt ) error("Invalid VCF, too few ALT alleles at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1); if ( ialt!=jalt && !rec->d.allele[ialt][1] && !rec->d.allele[jalt][1] ) // is this a het snp? { char ial = rec->d.allele[ialt][0]; char jal = rec->d.allele[jalt][0]; + if ( !ialt ) ialt = jalt; // only ialt is used, make sure 0/1 is not ignored rec->d.allele[ialt][0] = gt2iupac(ial,jal); } } else { + int is_hom = 1; for (i=0; in; i++) { - uint8_t *ignore, *ptr = fmt->p + fmt->size*args->isample + i; - ialt = bcf_dec_int1(ptr, fmt->type, &ignore); - if ( bcf_gt_is_missing(ialt) || ialt==bcf_int32_vector_end ) return; - ialt = bcf_gt_allele(ialt); - if ( ialt ) break; + if ( bcf_gt_is_missing(ptr[i]) ) return; // ignore missing or half-missing genotypes + if ( ptr[i]==bcf_int32_vector_end ) break; + ialt = bcf_gt_allele(ptr[i]); + if ( i>0 && ialt!=bcf_gt_allele(ptr[i-1]) ) { is_hom = 0; break; } + } + if ( !is_hom ) + { + int prev_len = 0, jalt; + for (i=0; in; i++) + { + if ( ptr[i]==bcf_int32_vector_end ) break; + jalt = bcf_gt_allele(ptr[i]); + if ( rec->n_allele <= jalt ) error("Broken VCF, too few alts at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1); + if ( args->allele & (PICK_LONG|PICK_SHORT) ) + { + int len = jalt==0 ? rec->rlen : strlen(rec->d.allele[jalt]); + if ( i==0 ) ialt = jalt, prev_len = len; + else if ( len == prev_len ) + { + if ( args->allele & PICK_REF && jalt==0 ) ialt = jalt, prev_len = len; + else if ( args->allele & PICK_ALT && ialt==0 ) ialt = jalt, prev_len = len; + } + else if ( args->allele & PICK_LONG && len > prev_len ) ialt = jalt, prev_len = len; + else if ( args->allele & PICK_SHORT && len < prev_len ) ialt = jalt, prev_len = len; + } + else + { + if ( args->allele & PICK_REF && jalt==0 ) ialt = jalt; + else if ( args->allele & PICK_ALT && ialt==0 ) ialt = jalt; + } + } } } if ( !ialt ) return; // ref allele @@ -411,12 +476,27 @@ static void apply_variant(args_t *args, bcf1_t *rec) rec->d.allele[1][0] = gt2iupac(ial,jal); } + int len_diff = 0, alen = 0; int idx = rec->pos - args->fa_ori_pos + args->fa_mod_off; - if ( idx<0 || idx>=args->fa_buf.l ) + if ( idx<0 ) + { + fprintf(bcftools_stderr,"Warning: ignoring overlapping variant starting at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1); + return; + } + if ( rec->rlen > args->fa_buf.l - idx ) + { + rec->rlen = args->fa_buf.l - idx; + alen = strlen(rec->d.allele[ialt]); + if ( alen > rec->rlen ) + { + rec->d.allele[ialt][rec->rlen] = 0; + fprintf(bcftools_stderr,"Warning: trimming variant starting at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1); + } + } + if ( idx>=args->fa_buf.l ) error("FIXME: %s:%d .. idx=%d, ori_pos=%d, len=%d, off=%d\n",bcf_seqname(args->hdr,rec),rec->pos+1,idx,args->fa_ori_pos,args->fa_buf.l,args->fa_mod_off); // sanity check the reference base - int len_diff = 0, alen = 0; if ( rec->d.allele[ialt][0]=='<' ) { if ( strcasecmp(rec->d.allele[ialt], "") ) @@ -428,7 +508,7 @@ static void apply_variant(args_t *args, bcf1_t *rec) } else if ( strncasecmp(rec->d.allele[0],args->fa_buf.s+idx,rec->rlen) ) { - // fprintf(pysam_stderr,"%d .. [%s], idx=%d ori=%d off=%d\n",args->fa_ori_pos,args->fa_buf.s,idx,args->fa_ori_pos,args->fa_mod_off); + // fprintf(bcftools_stderr,"%d .. [%s], idx=%d ori=%d off=%d\n",args->fa_ori_pos,args->fa_buf.s,idx,args->fa_ori_pos,args->fa_mod_off); char tmp = 0; if ( args->fa_buf.l - idx > rec->rlen ) { @@ -493,22 +573,19 @@ static void apply_variant(args_t *args, bcf1_t *rec) static void mask_region(args_t *args, char *seq, int len) { - char *chr = (char*)bcf_hdr_id2name(args->hdr,args->rid); int start = args->fa_src_pos - len; int end = args->fa_src_pos; - regitr_t itr; - if ( !regidx_overlap(args->mask, chr,start,end, &itr) ) return; + if ( !regidx_overlap(args->mask, args->chr,start,end, args->itr) ) return; int idx_start, idx_end, i; - while ( REGITR_OVERLAP(itr,start,end) ) + while ( regitr_overlap(args->itr) ) { - idx_start = REGITR_START(itr) - start; - idx_end = REGITR_END(itr) - start; + idx_start = args->itr->beg - start; + idx_end = args->itr->end - start; if ( idx_start < 0 ) idx_start = 0; if ( idx_end >= len ) idx_end = len - 1; for (i=idx_start; i<=idx_end; i++) seq[i] = 'N'; - itr.i++; } } @@ -521,13 +598,14 @@ static void consensus(args_t *args) { if ( str.s[0]=='>' ) { - // new sequence encountered, apply all chached variants + // new sequence encountered + if (args->chain) { + print_chain(args); + destroy_chain(args); + } + // apply all cached variants while ( args->vcf_rbuf.n ) { - if (args->chain) { - print_chain(args); - destroy_chain(args); - } bcf1_t *rec = args->vcf_buf[args->vcf_rbuf.f]; if ( rec->rid!=args->rid || ( args->fa_end_pos && rec->pos > args->fa_end_pos ) ) break; int i = rbuf_shift(&args->vcf_rbuf); @@ -578,7 +656,17 @@ static void consensus(args_t *args) } if ( !rec_ptr ) flush_fa_buffer(args, 60); } - if (args->chain) { + bcf1_t **rec_ptr = NULL; + while ( args->rid>=0 && (rec_ptr = next_vcf_line(args)) ) + { + bcf1_t *rec = *rec_ptr; + if ( rec->rid!=args->rid ) break; + if ( args->fa_end_pos && rec->pos > args->fa_end_pos ) break; + if ( args->fa_ori_pos + args->fa_buf.l - args->fa_mod_off <= rec->pos ) break; + apply_variant(args, rec); + } + if (args->chain) + { print_chain(args); destroy_chain(args); } @@ -589,23 +677,35 @@ static void consensus(args_t *args) static void usage(args_t *args) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Create consensus sequence by applying VCF variants to a reference\n"); - fprintf(pysam_stderr, " fasta file.\n"); - fprintf(pysam_stderr, "Usage: bcftools consensus [OPTIONS] \n"); - fprintf(pysam_stderr, "Options:\n"); - fprintf(pysam_stderr, " -f, --fasta-ref reference sequence in fasta format\n"); - fprintf(pysam_stderr, " -H, --haplotype <1|2> apply variants for the given haplotype\n"); - fprintf(pysam_stderr, " -i, --iupac-codes output variants in the form of IUPAC ambiguity codes\n"); - fprintf(pysam_stderr, " -m, --mask replace regions with N\n"); - fprintf(pysam_stderr, " -o, --output write output to a file [standard output]\n"); - fprintf(pysam_stderr, " -c, --chain write a chain file for liftover\n"); - fprintf(pysam_stderr, " -s, --sample apply variants of the given sample\n"); - fprintf(pysam_stderr, "Examples:\n"); - fprintf(pysam_stderr, " # Get the consensus for one region. The fasta header lines are then expected\n"); - fprintf(pysam_stderr, " # in the form \">chr:from-to\".\n"); - fprintf(pysam_stderr, " samtools faidx ref.fa 8:11870-11890 | bcftools consensus in.vcf.gz > out.fa\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Create consensus sequence by applying VCF variants to a reference fasta\n"); + fprintf(bcftools_stderr, " file. By default, the program will apply all ALT variants. Using the\n"); + fprintf(bcftools_stderr, " --sample (and, optionally, --haplotype) option will apply genotype\n"); + fprintf(bcftools_stderr, " (or haplotype) calls from FORMAT/GT. The program ignores allelic depth\n"); + fprintf(bcftools_stderr, " information, such as INFO/AD or FORMAT/AD.\n"); + fprintf(bcftools_stderr, "Usage: bcftools consensus [OPTIONS] \n"); + fprintf(bcftools_stderr, "Options:\n"); + fprintf(bcftools_stderr, " -c, --chain write a chain file for liftover\n"); + fprintf(bcftools_stderr, " -e, --exclude exclude sites for which the expression is true (see man page for details)\n"); + fprintf(bcftools_stderr, " -f, --fasta-ref reference sequence in fasta format\n"); + fprintf(bcftools_stderr, " -H, --haplotype choose which allele to use from the FORMAT/GT field, note\n"); + fprintf(bcftools_stderr, " the codes are case-insensitive:\n"); + fprintf(bcftools_stderr, " 1: first allele from GT\n"); + fprintf(bcftools_stderr, " 2: second allele\n"); + fprintf(bcftools_stderr, " R: REF allele in het genotypes\n"); + fprintf(bcftools_stderr, " A: ALT allele\n"); + fprintf(bcftools_stderr, " LR,LA: longer allele and REF/ALT if equal length\n"); + fprintf(bcftools_stderr, " SR,SA: shorter allele and REF/ALT if equal length\n"); + fprintf(bcftools_stderr, " -i, --include select sites for which the expression is true (see man page for details)\n"); + fprintf(bcftools_stderr, " -I, --iupac-codes output variants in the form of IUPAC ambiguity codes\n"); + fprintf(bcftools_stderr, " -m, --mask replace regions with N\n"); + fprintf(bcftools_stderr, " -o, --output write output to a file [standard output]\n"); + fprintf(bcftools_stderr, " -s, --sample apply variants of the given sample\n"); + fprintf(bcftools_stderr, "Examples:\n"); + fprintf(bcftools_stderr, " # Get the consensus for one region. The fasta header lines are then expected\n"); + fprintf(bcftools_stderr, " # in the form \">chr:from-to\".\n"); + fprintf(bcftools_stderr, " samtools faidx ref.fa 8:11870-11890 | bcftools consensus in.vcf.gz > out.fa\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } @@ -616,8 +716,10 @@ int main_consensus(int argc, char *argv[]) static struct option loptions[] = { + {"exclude",required_argument,NULL,'e'}, + {"include",required_argument,NULL,'i'}, {"sample",1,0,'s'}, - {"iupac-codes",0,0,'i'}, + {"iupac-codes",0,0,'I'}, {"haplotype",1,0,'H'}, {"output",1,0,'o'}, {"fasta-ref",1,0,'f'}, @@ -626,19 +728,32 @@ int main_consensus(int argc, char *argv[]) {0,0,0,0} }; int c; - while ((c = getopt_long(argc, argv, "h?s:1iH:f:o:m:c:",loptions,NULL)) >= 0) + while ((c = getopt_long(argc, argv, "h?s:1Ii:e:H:f:o:m:c:",loptions,NULL)) >= 0) { switch (c) { case 's': args->sample = optarg; break; case 'o': args->output_fname = optarg; break; - case 'i': args->output_iupac = 1; break; + case 'I': args->output_iupac = 1; break; + case 'e': args->filter_str = optarg; args->filter_logic |= FLT_EXCLUDE; break; + case 'i': args->filter_str = optarg; args->filter_logic |= FLT_INCLUDE; break; case 'f': args->ref_fname = optarg; break; case 'm': args->mask_fname = optarg; break; case 'c': args->chain_fname = optarg; break; case 'H': - args->haplotype = optarg[0] - '0'; - if ( args->haplotype <=0 ) error("Expected positive integer with --haplotype\n"); + if ( !strcasecmp(optarg,"R") ) args->allele |= PICK_REF; + else if ( !strcasecmp(optarg,"A") ) args->allele |= PICK_ALT; + else if ( !strcasecmp(optarg,"L") ) args->allele |= PICK_LONG|PICK_REF; + else if ( !strcasecmp(optarg,"S") ) args->allele |= PICK_SHORT|PICK_REF; + else if ( !strcasecmp(optarg,"LR") ) args->allele |= PICK_LONG|PICK_REF; + else if ( !strcasecmp(optarg,"LA") ) args->allele |= PICK_LONG|PICK_ALT; + else if ( !strcasecmp(optarg,"SR") ) args->allele |= PICK_SHORT|PICK_REF; + else if ( !strcasecmp(optarg,"SA") ) args->allele |= PICK_SHORT|PICK_ALT; + else + { + args->haplotype = optarg[0] - '0'; + if ( args->haplotype <=0 ) error("Expected positive integer with --haplotype\n"); + } break; default: usage(args); break; } diff --git a/bcftools/convert.c b/bcftools/convert.c index 3e289f025..d7ed0abc1 100644 --- a/bcftools/convert.c +++ b/bcftools/convert.c @@ -1,6 +1,6 @@ /* convert.c -- functions for converting between VCF/BCF and related formats. - Copyright (C) 2013-2014 Genome Research Ltd. + Copyright (C) 2013-2018 Genome Research Ltd. Author: Petr Danecek @@ -62,13 +62,19 @@ THE SOFTWARE. */ #define T_IUPAC_GT 23 #define T_GT_TO_HAP 24 // not publicly advertised #define T_GT_TO_HAP2 25 // not publicly advertised +#define T_TBCSQ 26 +#define T_END 27 +#define T_POS0 28 +#define T_END0 29 typedef struct _fmt_t { int type, id, is_gt_field, ready, subscript; char *key; bcf_fmt_t *fmt; + void *usr; // user data (optional) void (*handler)(convert_t *, bcf1_t *, struct _fmt_t *, int, kstring_t *); + void (*destroy)(void*); // clean user data (optional) } fmt_t; @@ -86,11 +92,22 @@ struct _convert_t int ndat; char *undef_info_tag; int allow_undef_tags; + uint8_t **subset_samples; }; +typedef struct +{ + kstring_t hap1,hap2; + char **str; + int n, m; +} +bcsq_t; static void process_chrom(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputs(convert->header->id[BCF_DT_CTG][line->rid].key, str); } static void process_pos(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputw(line->pos+1, str); } +static void process_pos0(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputw(line->pos, str); } +static void process_end(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputw(line->pos+line->rlen, str); } +static void process_end0(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputw(line->pos+line->rlen-1, str); } static void process_id(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputs(line->d.id, str); } static void process_ref(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputs(line->d.allele[0], str); } static void process_alt(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) @@ -125,7 +142,7 @@ static void process_first_alt(convert_t *convert, bcf1_t *line, fmt_t *fmt, int static void process_qual(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { if ( bcf_float_is_missing(line->qual) ) kputc('.', str); - else ksprintf(str, "%g", line->qual); + else kputd(line->qual, str); } static void process_filter(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { @@ -158,6 +175,24 @@ static inline int32_t bcf_array_ivalue(void *bcf_array, int type, int idx) } return ((int32_t*)bcf_array)[idx]; } +static inline void _copy_field(char *src, uint32_t len, int idx, kstring_t *str) +{ + int n = 0, ibeg = 0; + while ( src[ibeg] && ibegibeg ) + kputsn(src+ibeg, iend-ibeg, str); + else + kputc('.', str); +} static void process_info(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { if ( fmt->id<0 ) @@ -193,7 +228,7 @@ static void process_info(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isamp case BCF_BT_INT8: if ( info->v1.i==bcf_int8_missing ) kputc('.', str); else kputw(info->v1.i, str); break; case BCF_BT_INT16: if ( info->v1.i==bcf_int16_missing ) kputc('.', str); else kputw(info->v1.i, str); break; case BCF_BT_INT32: if ( info->v1.i==bcf_int32_missing ) kputc('.', str); else kputw(info->v1.i, str); break; - case BCF_BT_FLOAT: if ( bcf_float_is_missing(info->v1.f) ) kputc('.', str); else ksprintf(str, "%g", info->v1.f); break; + case BCF_BT_FLOAT: if ( bcf_float_is_missing(info->v1.f) ) kputc('.', str); else kputd(info->v1.f, str); break; case BCF_BT_CHAR: kputc(info->v1.i, str); break; default: fprintf(stderr,"todo: type %d\n", info->type); exit(1); break; } @@ -215,7 +250,8 @@ static void process_info(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isamp case BCF_BT_INT8: BRANCH(int8_t, val==bcf_int8_missing, val==bcf_int8_vector_end, kputw(val, str)); break; case BCF_BT_INT16: BRANCH(int16_t, val==bcf_int16_missing, val==bcf_int16_vector_end, kputw(val, str)); break; case BCF_BT_INT32: BRANCH(int32_t, val==bcf_int32_missing, val==bcf_int32_vector_end, kputw(val, str)); break; - case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(val), bcf_float_is_vector_end(val), ksprintf(str, "%g", val)); break; + case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(val), bcf_float_is_vector_end(val), kputd(val, str)); break; + case BCF_BT_CHAR: _copy_field((char*)info->vptr, info->vptr_len, fmt->subscript, str); break; default: fprintf(stderr,"todo: type %d\n", info->type); exit(1); break; } #undef BRANCH @@ -226,6 +262,7 @@ static void process_info(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isamp static void init_format(convert_t *convert, bcf1_t *line, fmt_t *fmt) { fmt->id = bcf_hdr_id2int(convert->header, BCF_DT_ID, fmt->key); + if ( !bcf_hdr_idinfo_exists(convert->header,BCF_HL_FMT,fmt->id) ) fmt->id = -1; fmt->fmt = NULL; if ( fmt->id >= 0 ) { @@ -261,7 +298,7 @@ static void process_format(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isa if ( bcf_float_is_missing(ptr[fmt->subscript]) || bcf_float_is_vector_end(ptr[fmt->subscript]) ) kputc('.', str); else - ksprintf(str, "%g", ptr[fmt->subscript]); + kputd(ptr[fmt->subscript], str); } else if ( fmt->fmt->type != BCF_BT_CHAR ) { @@ -271,6 +308,8 @@ static void process_format(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isa else kputw(ival, str); } + else if ( fmt->fmt->type == BCF_BT_CHAR ) + _copy_field((char*)(fmt->fmt->p + isample*fmt->fmt->size), fmt->fmt->size, fmt->subscript, str); else error("TODO: %s:%d .. fmt->type=%d\n", __FILE__,__LINE__, fmt->fmt->type); } else @@ -316,6 +355,111 @@ static void process_tgt(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isampl } if (l == 0) kputc('.', str); } +static void destroy_tbcsq(void *usr) +{ + if ( !usr ) return; + bcsq_t *csq = (bcsq_t*) usr; + free(csq->hap1.s); + free(csq->hap2.s); + if ( csq->n ) + free(csq->str[0]); + free(csq->str); + free(csq); +} +static void process_tbcsq(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) +{ + if ( !fmt->ready ) + { + init_format(convert, line, fmt); + + bcsq_t *csq; + if ( fmt->usr ) + { + csq = (bcsq_t*) fmt->usr; + if ( csq->n ) + free(csq->str[0]); + csq->n = 0; + } + else + csq = (bcsq_t*) calloc(1,sizeof(bcsq_t)); + fmt->usr = csq; + + int i=0, len = 0; + char *tmp = NULL; + if ( bcf_get_info_string(convert->header,line,fmt->key,&tmp,&len)<0 ) + { + csq->n = 0; + return; + } + do + { + csq->n++; + hts_expand(char*, csq->n, csq->m, csq->str); + csq->str[ csq->n-1 ] = tmp + i; + while ( iusr; + + if ( fmt->fmt==NULL || !csq->n ) return; + + csq->hap1.l = 0; + csq->hap2.l = 0; + + int mask = fmt->subscript==0 ? 3 : 1; // merge both haplotypes if subscript==0 + + #define BRANCH(type_t, nbits) { \ + type_t *x = (type_t*)(fmt->fmt->p + isample*fmt->fmt->size); \ + int i,j; \ + if ( fmt->subscript<=0 || fmt->subscript==1 ) \ + { \ + for (j=0; j < fmt->fmt->n; j++) \ + { \ + type_t val = x[j]; \ + if ( !val ) continue; \ + for (i=0; istr[(j*32+i)/2], &csq->hap1); kputc_(',', &csq->hap1); } \ + } \ + } \ + if ( fmt->subscript<0 || fmt->subscript==2 ) \ + { \ + for (j=0; j < fmt->fmt->n; j++) \ + { \ + type_t val = x[j]; \ + if ( !val ) continue; \ + for (i=1; istr[(j*32+i)/2], &csq->hap2); kputc_(',', &csq->hap2); } \ + } \ + } \ + } + switch (fmt->fmt->type) + { + case BCF_BT_INT8: BRANCH(uint8_t, 8); break; + case BCF_BT_INT16: BRANCH(uint16_t,16); break; + case BCF_BT_INT32: BRANCH(uint32_t,32); break; + default: error("Unexpected type: %d\n", fmt->fmt->type); exit(1); break; + } + #undef BRANCH + + if ( !csq->hap1.l && !csq->hap2.l ) return; + + if ( csq->hap1.l ) csq->hap1.s[--csq->hap1.l] = 0; + if ( csq->hap2.l ) csq->hap2.s[--csq->hap2.l] = 0; + + if ( fmt->subscript<0 ) + { + kputs(csq->hap1.l?csq->hap1.s:".", str); + kputc_('\t', str); + kputs(csq->hap2.l?csq->hap2.s:".", str); + } + else if ( fmt->subscript<2 ) + kputs(csq->hap1.l?csq->hap1.s:".", str); + else + kputs(csq->hap2.l?csq->hap2.s:".", str); +} static void init_format_iupac(convert_t *convert, bcf1_t *line, fmt_t *fmt) { init_format(convert, line, fmt); @@ -409,6 +553,7 @@ static void process_type(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isamp if ( line_type & VCF_MNP ) { if (i) kputc(',',str); kputs("MNP", str); i++; } if ( line_type & VCF_INDEL ) { if (i) kputc(',',str); kputs("INDEL", str); i++; } if ( line_type & VCF_OTHER ) { if (i) kputc(',',str); kputs("OTHER", str); i++; } + if ( line_type & VCF_BND ) { if (i) kputc(',',str); kputs("BND", str); i++; } } static void process_line(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { @@ -597,103 +742,260 @@ static void process_gt_to_hap(convert_t *convert, bcf1_t *line, fmt_t *fmt, int // the allele (0/1) and the asterisk (*); e.g., "0* 1*" for a // heterozygous genotype of unknown phase. - int m, n, i; - - m = convert->ndat / sizeof(int32_t); - n = bcf_get_genotypes(convert->header, line, &convert->dat, &m); - convert->ndat = m * sizeof(int32_t); - - if ( n<=0 ) - { - // Throw an error or silently proceed? - // - // for (i=0; insamples; i++) kputs(" ...", str); - // return; - - error("Error parsing GT tag at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1); - } - - n /= convert->nsamples; + int i, gt_id = bcf_hdr_id2int(convert->header, BCF_DT_ID, "GT"); + if ( !bcf_hdr_idinfo_exists(convert->header,BCF_HL_FMT,gt_id) ) + error("FORMAT/GT tag not present at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1); + if ( !(line->unpacked & BCF_UN_FMT) ) bcf_unpack(line, BCF_UN_FMT); + bcf_fmt_t *fmt_gt = NULL; + for (i=0; in_fmt; i++) + if ( line->d.fmt[i].id==gt_id ) { fmt_gt = &line->d.fmt[i]; break; } + if ( !fmt_gt ) + error("FORMAT/GT tag not present at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1); + + // Alloc all memory in advance to avoid kput routines. The biggest allowed allele index is 99 + if ( line->n_allele > 100 ) + error("Too many alleles (%d) at %s:%d\n", line->n_allele, bcf_seqname(convert->header, line), line->pos+1); + if ( ks_resize(str, str->l+convert->nsamples*8) != 0 ) + error("Could not alloc %d bytes\n", str->l + convert->nsamples*8); + + if ( fmt_gt->type!=BCF_BT_INT8 ) // todo: use BRANCH_INT if the VCF is valid + error("Uh, too many alleles (%d) or redundant BCF representation at %s:%d\n", line->n_allele, bcf_seqname(convert->header, line), line->pos+1); + + int8_t *ptr = ((int8_t*) fmt_gt->p) - fmt_gt->n; for (i=0; insamples; i++) { - int32_t *ptr = (int32_t*)convert->dat + i*n; - int j; - for (j=0; j0) kputs(" ", str); // no space separation for first column - if ( j==2 ) + ptr += fmt_gt->n; + if ( ptr[0]==2 ) { - // diploid - if ( bcf_gt_is_missing(ptr[0]) || bcf_gt_is_missing(ptr[1]) ) { - kputs("? ?", str); + if ( ptr[1]==3 ) /* 0|0 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = ' '; } - else if ( bcf_gt_is_phased(ptr[1])) { - ksprintf(str, "%d %d", bcf_gt_allele(ptr[0]), bcf_gt_allele(ptr[1])); + else if ( ptr[1]==5 ) /* 0|1 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = ' '; } - else { - ksprintf(str, "%d* %d*", bcf_gt_allele(ptr[0]), bcf_gt_allele(ptr[1])); + else if ( ptr[1]==bcf_int8_vector_end ) /* 0 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '-'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==2 ) /* 0/0 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==4 ) /* 0/1 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_missing(ptr[1]) ) /* 0/. */ + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_phased(ptr[1]) ) /* 0|x */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = ' '; + } + else /* 0/x */ + { + str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = '*'; str->s[str->l++] = ' '; } } - else if ( j==1 ) + else if ( ptr[0]==4 ) { - // haploid - if ( bcf_gt_is_missing(ptr[0]) ) - kputs("? -", str); - else if ( bcf_gt_allele(ptr[0])==1 ) - kputs("1 -", str); // first ALT allele - else - kputs("0 -", str); // REF or something else than first ALT + if ( ptr[1]==3 ) /* 1|0 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==5 ) /* 1|1 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==bcf_int8_vector_end ) /* 1 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '-'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==2 ) /* 1/0 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==4 ) /* 1/1 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_missing(ptr[1]) ) /* 1/. */ + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_phased(ptr[1]) ) /* 1|x */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = ' '; + } + else /* 1/x */ + { + str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + } + else if ( bcf_gt_is_missing(ptr[0]) ) + { + if ( ptr[1]==bcf_int8_vector_end ) + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '-'; str->s[str->l++] = ' '; + } + else + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; + } + } + else if ( ptr[1]==bcf_int8_vector_end ) + { + /* use REF for something else than first ALT */ + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '-'; str->s[str->l++] = ' '; + } + else + { + kputw(bcf_gt_allele(ptr[0]),str); + if ( bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*'; + str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + if ( bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*'; + str->s[str->l++] = ' '; } - else error("FIXME: not ready for ploidy %d\n", j); } + str->s[--str->l] = 0; // delete the last space } static void process_gt_to_hap2(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { // same as process_gt_to_hap but converts haploid genotypes into diploid - int m, n, i; - - m = convert->ndat / sizeof(int32_t); - n = bcf_get_genotypes(convert->header, line, &convert->dat, &m); - convert->ndat = m * sizeof(int32_t); - - if ( n<=0 ) - error("Error parsing GT tag at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1); - n /= convert->nsamples; + int i, gt_id = bcf_hdr_id2int(convert->header, BCF_DT_ID, "GT"); + if ( !bcf_hdr_idinfo_exists(convert->header,BCF_HL_FMT,gt_id) ) + error("FORMAT/GT tag not present at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1); + if ( !(line->unpacked & BCF_UN_FMT) ) bcf_unpack(line, BCF_UN_FMT); + bcf_fmt_t *fmt_gt = NULL; + for (i=0; in_fmt; i++) + if ( line->d.fmt[i].id==gt_id ) { fmt_gt = &line->d.fmt[i]; break; } + if ( !fmt_gt ) + error("FORMAT/GT tag not present at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1); + + // Alloc all memory in advance to avoid kput routines. The biggest allowed allele index is 99 + if ( line->n_allele > 100 ) + error("Too many alleles (%d) at %s:%d\n", line->n_allele, bcf_seqname(convert->header, line), line->pos+1); + if ( ks_resize(str, str->l+convert->nsamples*8) != 0 ) + error("Could not alloc %d bytes\n", str->l + convert->nsamples*8); + + if ( fmt_gt->type!=BCF_BT_INT8 ) // todo: use BRANCH_INT if the VCF is valid + error("Uh, too many alleles (%d) or redundant BCF representation at %s:%d\n", line->n_allele, bcf_seqname(convert->header, line), line->pos+1); + + int8_t *ptr = ((int8_t*) fmt_gt->p) - fmt_gt->n; for (i=0; insamples; i++) { - int32_t *ptr = (int32_t*)convert->dat + i*n; - int j; - for (j=0; j0) kputs(" ", str); // no space separation for first column - if ( j==2 ) + ptr += fmt_gt->n; + if ( ptr[0]==2 ) { - // diploid - if ( bcf_gt_is_missing(ptr[0]) || bcf_gt_is_missing(ptr[1]) ) { - kputs("? ?", str); + if ( ptr[1]==3 ) /* 0|0 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = ' '; } - else if ( bcf_gt_is_phased(ptr[1])) { - ksprintf(str, "%d %d", bcf_gt_allele(ptr[0]), bcf_gt_allele(ptr[1])); + else if ( ptr[1]==5 ) /* 0|1 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = ' '; } - else { - ksprintf(str, "%d* %d*", bcf_gt_allele(ptr[0]), bcf_gt_allele(ptr[1])); + else if ( ptr[1]==bcf_int8_vector_end ) /* 0 -> 0|0 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==2 ) /* 0/0 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==4 ) /* 0/1 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_missing(ptr[1]) ) /* 0/. */ + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_phased(ptr[1]) ) /* 0|x */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = ' '; + } + else /* 0/x */ + { + str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = '*'; str->s[str->l++] = ' '; } } - else if ( j==1 ) + else if ( ptr[0]==4 ) { - // haploid - if ( bcf_gt_is_missing(ptr[0]) ) - kputs("? ?", str); - else if ( bcf_gt_allele(ptr[0])==1 ) - kputs("1 1", str); // first ALT allele - else - kputs("0 0", str); // REF or something else than first ALT + if ( ptr[1]==3 ) /* 1|0 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==5 ) /* 1|1 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==bcf_int8_vector_end ) /* 1 -> 1|1 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==2 ) /* 1/0 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==4 ) /* 1/1 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_missing(ptr[1]) ) /* 1/. */ + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_phased(ptr[1]) ) /* 1|x */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = ' '; + } + else /* 1/x */ + { + str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + } + else if ( bcf_gt_is_missing(ptr[0]) ) + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==bcf_int8_vector_end ) + { + /* use REF for something else than first ALT */ + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = ' '; + } + else + { + kputw(bcf_gt_allele(ptr[0]),str); + if ( bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*'; + str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + if ( bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*'; + str->s[str->l++] = ' '; } - else error("FIXME: not ready for ploidy %d\n", j); } + str->s[--str->l] = 0; // delete the last space } static fmt_t *register_tag(convert_t *convert, int type, char *key, int is_gtf) @@ -709,6 +1011,8 @@ static fmt_t *register_tag(convert_t *convert, int type, char *key, int is_gtf) fmt->key = key ? strdup(key) : NULL; fmt->is_gt_field = is_gtf; fmt->subscript = -1; + fmt->usr = NULL; + fmt->destroy = NULL; // Allow non-format tags, such as CHROM, INFO, etc., to appear amongst the format tags. if ( key ) @@ -718,6 +1022,9 @@ static fmt_t *register_tag(convert_t *convert, int type, char *key, int is_gtf) { if ( !strcmp("CHROM",key) ) { fmt->type = T_CHROM; } else if ( !strcmp("POS",key) ) { fmt->type = T_POS; } + else if ( !strcmp("POS0",key) ) { fmt->type = T_POS0; } + else if ( !strcmp("END",key) ) { fmt->type = T_END; } + else if ( !strcmp("END0",key) ) { fmt->type = T_END0; } else if ( !strcmp("ID",key) ) { fmt->type = T_ID; } else if ( !strcmp("REF",key) ) { fmt->type = T_REF; } else if ( !strcmp("ALT",key) ) { fmt->type = T_ALT; } @@ -742,6 +1049,9 @@ static fmt_t *register_tag(convert_t *convert, int type, char *key, int is_gtf) case T_GP_TO_PROB3: fmt->handler = &process_gp_to_prob3; break; case T_CHROM: fmt->handler = &process_chrom; break; case T_POS: fmt->handler = &process_pos; break; + case T_POS0: fmt->handler = &process_pos0; break; + case T_END: fmt->handler = &process_end; break; + case T_END0: fmt->handler = &process_end0; break; case T_ID: fmt->handler = &process_id; break; case T_REF: fmt->handler = &process_ref; break; case T_ALT: fmt->handler = &process_alt; break; @@ -759,15 +1069,17 @@ static fmt_t *register_tag(convert_t *convert, int type, char *key, int is_gtf) case T_IUPAC_GT: fmt->handler = &process_iupac_gt; convert->max_unpack |= BCF_UN_FMT; break; case T_GT_TO_HAP: fmt->handler = &process_gt_to_hap; convert->max_unpack |= BCF_UN_FMT; break; case T_GT_TO_HAP2: fmt->handler = &process_gt_to_hap2; convert->max_unpack |= BCF_UN_FMT; break; - case T_LINE: fmt->handler = &process_line; break; + case T_TBCSQ: fmt->handler = &process_tbcsq; fmt->destroy = &destroy_tbcsq; convert->max_unpack |= BCF_UN_FMT; break; + case T_LINE: fmt->handler = &process_line; convert->max_unpack |= BCF_UN_FMT; break; default: error("TODO: handler for type %d\n", fmt->type); } - if ( key ) + if ( key && fmt->type==T_INFO ) { - if ( fmt->type==T_INFO ) + fmt->id = bcf_hdr_id2int(convert->header, BCF_DT_ID, key); + if ( !bcf_hdr_idinfo_exists(convert->header,BCF_HL_INFO,fmt->id) ) { - fmt->id = bcf_hdr_id2int(convert->header, BCF_DT_ID, key); - if ( fmt->id==-1 ) convert->undef_info_tag = strdup(key); + fmt->id = -1; + convert->undef_info_tag = strdup(key); } } return fmt; @@ -797,6 +1109,16 @@ static char *parse_tag(convert_t *convert, char *p, int is_gtf) if ( !strcmp(str.s, "SAMPLE") ) register_tag(convert, T_SAMPLE, "SAMPLE", is_gtf); else if ( !strcmp(str.s, "GT") ) register_tag(convert, T_GT, "GT", is_gtf); else if ( !strcmp(str.s, "TGT") ) register_tag(convert, T_TGT, "GT", is_gtf); + else if ( !strcmp(str.s, "TBCSQ") ) + { + fmt_t *fmt = register_tag(convert, T_TBCSQ, "BCSQ", is_gtf); + fmt->subscript = parse_subscript(&q); + if ( fmt->subscript==-1 ) + { + if ( !strncmp(q,"{*}",3) ) { fmt->subscript = 0; q += 3; } + } + else fmt->subscript++; + } else if ( !strcmp(str.s, "IUPACGT") ) register_tag(convert, T_IUPAC_GT, "GT", is_gtf); else if ( !strcmp(str.s, "INFO") ) { @@ -819,6 +1141,9 @@ static char *parse_tag(convert_t *convert, char *p, int is_gtf) { if ( !strcmp(str.s, "CHROM") ) register_tag(convert, T_CHROM, str.s, is_gtf); else if ( !strcmp(str.s, "POS") ) register_tag(convert, T_POS, str.s, is_gtf); + else if ( !strcmp(str.s, "POS0") ) register_tag(convert, T_POS0, str.s, is_gtf); + else if ( !strcmp(str.s, "END") ) register_tag(convert, T_END, str.s, is_gtf); + else if ( !strcmp(str.s, "END0") ) register_tag(convert, T_END0, str.s, is_gtf); else if ( !strcmp(str.s, "ID") ) register_tag(convert, T_ID, str.s, is_gtf); else if ( !strcmp(str.s, "REF") ) register_tag(convert, T_REF, str.s, is_gtf); else if ( !strcmp(str.s, "ALT") ) @@ -903,6 +1228,8 @@ convert_t *convert_init(bcf_hdr_t *hdr, int *samples, int nsamples, const char * default: p = parse_sep(convert, p, is_gtf); break; } } + if ( is_gtf ) + error("Could not parse the format string, missing the square bracket \"]\": %s\n", convert->format_str); if ( nsamples ) { @@ -923,7 +1250,10 @@ void convert_destroy(convert_t *convert) { int i; for (i=0; infmt; i++) + { + if ( convert->fmt[i].destroy ) convert->fmt[i].destroy(convert->fmt[i].usr); free(convert->fmt[i].key); + } free(convert->fmt); free(convert->undef_info_tag); free(convert->dat); @@ -984,7 +1314,7 @@ int convert_header(convert_t *convert, kstring_t *str) int convert_line(convert_t *convert, bcf1_t *line, kstring_t *str) { if ( !convert->allow_undef_tags && convert->undef_info_tag ) - error("Error: no such tag defined in the VCF header: INFO/%s\n", convert->undef_info_tag); + error("Error: no such tag defined in the VCF header: INFO/%s. FORMAT fields must be in square brackets, e.g. \"[ %s]\"\n", convert->undef_info_tag,convert->undef_info_tag); int l_ori = str->l; bcf_unpack(line, convert->max_unpack); @@ -993,17 +1323,27 @@ int convert_line(convert_t *convert, bcf1_t *line, kstring_t *str) str->l = 0; for (i=0; infmt; i++) { - // Genotype fields + // Genotype fields. if ( convert->fmt[i].is_gt_field ) { int j = i, js, k; - while ( convert->fmt[j].is_gt_field ) + while ( jnfmt && convert->fmt[j].is_gt_field ) { convert->fmt[j].ready = 0; j++; } for (js=0; jsnsamples; js++) { + // Skip samples when filtering was requested + if ( *convert->subset_samples && !(*convert->subset_samples)[js] ) continue; + + // Here comes a hack designed for TBCSQ. When running on large files, + // such as 1000GP, there are too many empty fields in the output and + // it's very very slow. Therefore in case the handler does not add + // anything to the string, we trim all genotype fields enclosed in square + // brackets here. This may be changed in future, time will show... + size_t l_start = str->l; + int ks = convert->samples[js]; for (k=i; kreaders,ir)?'1':'0', str); } else if ( convert->fmt[k].handler ) + { + size_t l = str->l; convert->fmt[k].handler(convert, line, &convert->fmt[k], ks, str); + if ( l==str->l ) { str->l = l_start; break; } // only TBCSQ does this + } } } i = j-1; @@ -1027,6 +1371,7 @@ int convert_line(convert_t *convert, bcf1_t *line, kstring_t *str) } else if ( convert->fmt[i].handler ) convert->fmt[i].handler(convert, line, &convert->fmt[i], -1, str); + } return str->l - l_ori; } @@ -1042,6 +1387,9 @@ int convert_set_option(convert_t *convert, enum convert_option opt, ...) case allow_undef_tags: convert->allow_undef_tags = va_arg(args, int); break; + case subset_samples: + convert->subset_samples = va_arg(args, uint8_t**); + break; default: ret = -1; } diff --git a/bcftools/convert.c.pysam.c b/bcftools/convert.c.pysam.c index 084ef50ca..66373bcda 100644 --- a/bcftools/convert.c.pysam.c +++ b/bcftools/convert.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* convert.c -- functions for converting between VCF/BCF and related formats. - Copyright (C) 2013-2014 Genome Research Ltd. + Copyright (C) 2013-2018 Genome Research Ltd. Author: Petr Danecek @@ -64,13 +64,19 @@ THE SOFTWARE. */ #define T_IUPAC_GT 23 #define T_GT_TO_HAP 24 // not publicly advertised #define T_GT_TO_HAP2 25 // not publicly advertised +#define T_TBCSQ 26 +#define T_END 27 +#define T_POS0 28 +#define T_END0 29 typedef struct _fmt_t { int type, id, is_gt_field, ready, subscript; char *key; bcf_fmt_t *fmt; + void *usr; // user data (optional) void (*handler)(convert_t *, bcf1_t *, struct _fmt_t *, int, kstring_t *); + void (*destroy)(void*); // clean user data (optional) } fmt_t; @@ -88,11 +94,22 @@ struct _convert_t int ndat; char *undef_info_tag; int allow_undef_tags; + uint8_t **subset_samples; }; +typedef struct +{ + kstring_t hap1,hap2; + char **str; + int n, m; +} +bcsq_t; static void process_chrom(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputs(convert->header->id[BCF_DT_CTG][line->rid].key, str); } static void process_pos(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputw(line->pos+1, str); } +static void process_pos0(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputw(line->pos, str); } +static void process_end(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputw(line->pos+line->rlen, str); } +static void process_end0(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputw(line->pos+line->rlen-1, str); } static void process_id(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputs(line->d.id, str); } static void process_ref(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { kputs(line->d.allele[0], str); } static void process_alt(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) @@ -127,7 +144,7 @@ static void process_first_alt(convert_t *convert, bcf1_t *line, fmt_t *fmt, int static void process_qual(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { if ( bcf_float_is_missing(line->qual) ) kputc('.', str); - else ksprintf(str, "%g", line->qual); + else kputd(line->qual, str); } static void process_filter(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { @@ -160,6 +177,24 @@ static inline int32_t bcf_array_ivalue(void *bcf_array, int type, int idx) } return ((int32_t*)bcf_array)[idx]; } +static inline void _copy_field(char *src, uint32_t len, int idx, kstring_t *str) +{ + int n = 0, ibeg = 0; + while ( src[ibeg] && ibegibeg ) + kputsn(src+ibeg, iend-ibeg, str); + else + kputc('.', str); +} static void process_info(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { if ( fmt->id<0 ) @@ -195,9 +230,9 @@ static void process_info(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isamp case BCF_BT_INT8: if ( info->v1.i==bcf_int8_missing ) kputc('.', str); else kputw(info->v1.i, str); break; case BCF_BT_INT16: if ( info->v1.i==bcf_int16_missing ) kputc('.', str); else kputw(info->v1.i, str); break; case BCF_BT_INT32: if ( info->v1.i==bcf_int32_missing ) kputc('.', str); else kputw(info->v1.i, str); break; - case BCF_BT_FLOAT: if ( bcf_float_is_missing(info->v1.f) ) kputc('.', str); else ksprintf(str, "%g", info->v1.f); break; + case BCF_BT_FLOAT: if ( bcf_float_is_missing(info->v1.f) ) kputc('.', str); else kputd(info->v1.f, str); break; case BCF_BT_CHAR: kputc(info->v1.i, str); break; - default: fprintf(pysam_stderr,"todo: type %d\n", info->type); exit(1); break; + default: fprintf(bcftools_stderr,"todo: type %d\n", info->type); exit(1); break; } } else if ( fmt->subscript >=0 ) @@ -217,8 +252,9 @@ static void process_info(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isamp case BCF_BT_INT8: BRANCH(int8_t, val==bcf_int8_missing, val==bcf_int8_vector_end, kputw(val, str)); break; case BCF_BT_INT16: BRANCH(int16_t, val==bcf_int16_missing, val==bcf_int16_vector_end, kputw(val, str)); break; case BCF_BT_INT32: BRANCH(int32_t, val==bcf_int32_missing, val==bcf_int32_vector_end, kputw(val, str)); break; - case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(val), bcf_float_is_vector_end(val), ksprintf(str, "%g", val)); break; - default: fprintf(pysam_stderr,"todo: type %d\n", info->type); exit(1); break; + case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(val), bcf_float_is_vector_end(val), kputd(val, str)); break; + case BCF_BT_CHAR: _copy_field((char*)info->vptr, info->vptr_len, fmt->subscript, str); break; + default: fprintf(bcftools_stderr,"todo: type %d\n", info->type); exit(1); break; } #undef BRANCH } @@ -228,6 +264,7 @@ static void process_info(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isamp static void init_format(convert_t *convert, bcf1_t *line, fmt_t *fmt) { fmt->id = bcf_hdr_id2int(convert->header, BCF_DT_ID, fmt->key); + if ( !bcf_hdr_idinfo_exists(convert->header,BCF_HL_FMT,fmt->id) ) fmt->id = -1; fmt->fmt = NULL; if ( fmt->id >= 0 ) { @@ -263,7 +300,7 @@ static void process_format(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isa if ( bcf_float_is_missing(ptr[fmt->subscript]) || bcf_float_is_vector_end(ptr[fmt->subscript]) ) kputc('.', str); else - ksprintf(str, "%g", ptr[fmt->subscript]); + kputd(ptr[fmt->subscript], str); } else if ( fmt->fmt->type != BCF_BT_CHAR ) { @@ -273,6 +310,8 @@ static void process_format(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isa else kputw(ival, str); } + else if ( fmt->fmt->type == BCF_BT_CHAR ) + _copy_field((char*)(fmt->fmt->p + isample*fmt->fmt->size), fmt->fmt->size, fmt->subscript, str); else error("TODO: %s:%d .. fmt->type=%d\n", __FILE__,__LINE__, fmt->fmt->type); } else @@ -318,6 +357,111 @@ static void process_tgt(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isampl } if (l == 0) kputc('.', str); } +static void destroy_tbcsq(void *usr) +{ + if ( !usr ) return; + bcsq_t *csq = (bcsq_t*) usr; + free(csq->hap1.s); + free(csq->hap2.s); + if ( csq->n ) + free(csq->str[0]); + free(csq->str); + free(csq); +} +static void process_tbcsq(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) +{ + if ( !fmt->ready ) + { + init_format(convert, line, fmt); + + bcsq_t *csq; + if ( fmt->usr ) + { + csq = (bcsq_t*) fmt->usr; + if ( csq->n ) + free(csq->str[0]); + csq->n = 0; + } + else + csq = (bcsq_t*) calloc(1,sizeof(bcsq_t)); + fmt->usr = csq; + + int i=0, len = 0; + char *tmp = NULL; + if ( bcf_get_info_string(convert->header,line,fmt->key,&tmp,&len)<0 ) + { + csq->n = 0; + return; + } + do + { + csq->n++; + hts_expand(char*, csq->n, csq->m, csq->str); + csq->str[ csq->n-1 ] = tmp + i; + while ( iusr; + + if ( fmt->fmt==NULL || !csq->n ) return; + + csq->hap1.l = 0; + csq->hap2.l = 0; + + int mask = fmt->subscript==0 ? 3 : 1; // merge both haplotypes if subscript==0 + + #define BRANCH(type_t, nbits) { \ + type_t *x = (type_t*)(fmt->fmt->p + isample*fmt->fmt->size); \ + int i,j; \ + if ( fmt->subscript<=0 || fmt->subscript==1 ) \ + { \ + for (j=0; j < fmt->fmt->n; j++) \ + { \ + type_t val = x[j]; \ + if ( !val ) continue; \ + for (i=0; istr[(j*32+i)/2], &csq->hap1); kputc_(',', &csq->hap1); } \ + } \ + } \ + if ( fmt->subscript<0 || fmt->subscript==2 ) \ + { \ + for (j=0; j < fmt->fmt->n; j++) \ + { \ + type_t val = x[j]; \ + if ( !val ) continue; \ + for (i=1; istr[(j*32+i)/2], &csq->hap2); kputc_(',', &csq->hap2); } \ + } \ + } \ + } + switch (fmt->fmt->type) + { + case BCF_BT_INT8: BRANCH(uint8_t, 8); break; + case BCF_BT_INT16: BRANCH(uint16_t,16); break; + case BCF_BT_INT32: BRANCH(uint32_t,32); break; + default: error("Unexpected type: %d\n", fmt->fmt->type); exit(1); break; + } + #undef BRANCH + + if ( !csq->hap1.l && !csq->hap2.l ) return; + + if ( csq->hap1.l ) csq->hap1.s[--csq->hap1.l] = 0; + if ( csq->hap2.l ) csq->hap2.s[--csq->hap2.l] = 0; + + if ( fmt->subscript<0 ) + { + kputs(csq->hap1.l?csq->hap1.s:".", str); + kputc_('\t', str); + kputs(csq->hap2.l?csq->hap2.s:".", str); + } + else if ( fmt->subscript<2 ) + kputs(csq->hap1.l?csq->hap1.s:".", str); + else + kputs(csq->hap2.l?csq->hap2.s:".", str); +} static void init_format_iupac(convert_t *convert, bcf1_t *line, fmt_t *fmt) { init_format(convert, line, fmt); @@ -411,6 +555,7 @@ static void process_type(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isamp if ( line_type & VCF_MNP ) { if (i) kputc(',',str); kputs("MNP", str); i++; } if ( line_type & VCF_INDEL ) { if (i) kputc(',',str); kputs("INDEL", str); i++; } if ( line_type & VCF_OTHER ) { if (i) kputc(',',str); kputs("OTHER", str); i++; } + if ( line_type & VCF_BND ) { if (i) kputc(',',str); kputs("BND", str); i++; } } static void process_line(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { @@ -599,103 +744,260 @@ static void process_gt_to_hap(convert_t *convert, bcf1_t *line, fmt_t *fmt, int // the allele (0/1) and the asterisk (*); e.g., "0* 1*" for a // heterozygous genotype of unknown phase. - int m, n, i; - - m = convert->ndat / sizeof(int32_t); - n = bcf_get_genotypes(convert->header, line, &convert->dat, &m); - convert->ndat = m * sizeof(int32_t); - - if ( n<=0 ) - { - // Throw an error or silently proceed? - // - // for (i=0; insamples; i++) kputs(" ...", str); - // return; - - error("Error parsing GT tag at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1); - } - - n /= convert->nsamples; + int i, gt_id = bcf_hdr_id2int(convert->header, BCF_DT_ID, "GT"); + if ( !bcf_hdr_idinfo_exists(convert->header,BCF_HL_FMT,gt_id) ) + error("FORMAT/GT tag not present at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1); + if ( !(line->unpacked & BCF_UN_FMT) ) bcf_unpack(line, BCF_UN_FMT); + bcf_fmt_t *fmt_gt = NULL; + for (i=0; in_fmt; i++) + if ( line->d.fmt[i].id==gt_id ) { fmt_gt = &line->d.fmt[i]; break; } + if ( !fmt_gt ) + error("FORMAT/GT tag not present at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1); + + // Alloc all memory in advance to avoid kput routines. The biggest allowed allele index is 99 + if ( line->n_allele > 100 ) + error("Too many alleles (%d) at %s:%d\n", line->n_allele, bcf_seqname(convert->header, line), line->pos+1); + if ( ks_resize(str, str->l+convert->nsamples*8) != 0 ) + error("Could not alloc %d bytes\n", str->l + convert->nsamples*8); + + if ( fmt_gt->type!=BCF_BT_INT8 ) // todo: use BRANCH_INT if the VCF is valid + error("Uh, too many alleles (%d) or redundant BCF representation at %s:%d\n", line->n_allele, bcf_seqname(convert->header, line), line->pos+1); + + int8_t *ptr = ((int8_t*) fmt_gt->p) - fmt_gt->n; for (i=0; insamples; i++) { - int32_t *ptr = (int32_t*)convert->dat + i*n; - int j; - for (j=0; j0) kputs(" ", str); // no space separation for first column - if ( j==2 ) + ptr += fmt_gt->n; + if ( ptr[0]==2 ) { - // diploid - if ( bcf_gt_is_missing(ptr[0]) || bcf_gt_is_missing(ptr[1]) ) { - kputs("? ?", str); + if ( ptr[1]==3 ) /* 0|0 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = ' '; } - else if ( bcf_gt_is_phased(ptr[1])) { - ksprintf(str, "%d %d", bcf_gt_allele(ptr[0]), bcf_gt_allele(ptr[1])); + else if ( ptr[1]==5 ) /* 0|1 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = ' '; } - else { - ksprintf(str, "%d* %d*", bcf_gt_allele(ptr[0]), bcf_gt_allele(ptr[1])); + else if ( ptr[1]==bcf_int8_vector_end ) /* 0 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '-'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==2 ) /* 0/0 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==4 ) /* 0/1 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_missing(ptr[1]) ) /* 0/. */ + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_phased(ptr[1]) ) /* 0|x */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = ' '; + } + else /* 0/x */ + { + str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = '*'; str->s[str->l++] = ' '; } } - else if ( j==1 ) + else if ( ptr[0]==4 ) { - // haploid - if ( bcf_gt_is_missing(ptr[0]) ) - kputs("? -", str); - else if ( bcf_gt_allele(ptr[0])==1 ) - kputs("1 -", str); // first ALT allele - else - kputs("0 -", str); // REF or something else than first ALT + if ( ptr[1]==3 ) /* 1|0 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==5 ) /* 1|1 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==bcf_int8_vector_end ) /* 1 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '-'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==2 ) /* 1/0 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==4 ) /* 1/1 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_missing(ptr[1]) ) /* 1/. */ + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_phased(ptr[1]) ) /* 1|x */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = ' '; + } + else /* 1/x */ + { + str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + } + else if ( bcf_gt_is_missing(ptr[0]) ) + { + if ( ptr[1]==bcf_int8_vector_end ) + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '-'; str->s[str->l++] = ' '; + } + else + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; + } + } + else if ( ptr[1]==bcf_int8_vector_end ) + { + /* use REF for something else than first ALT */ + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '-'; str->s[str->l++] = ' '; + } + else + { + kputw(bcf_gt_allele(ptr[0]),str); + if ( bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*'; + str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + if ( bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*'; + str->s[str->l++] = ' '; } - else error("FIXME: not ready for ploidy %d\n", j); } + str->s[--str->l] = 0; // delete the last space } static void process_gt_to_hap2(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isample, kstring_t *str) { // same as process_gt_to_hap but converts haploid genotypes into diploid - int m, n, i; - - m = convert->ndat / sizeof(int32_t); - n = bcf_get_genotypes(convert->header, line, &convert->dat, &m); - convert->ndat = m * sizeof(int32_t); - - if ( n<=0 ) - error("Error parsing GT tag at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1); - n /= convert->nsamples; + int i, gt_id = bcf_hdr_id2int(convert->header, BCF_DT_ID, "GT"); + if ( !bcf_hdr_idinfo_exists(convert->header,BCF_HL_FMT,gt_id) ) + error("FORMAT/GT tag not present at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1); + if ( !(line->unpacked & BCF_UN_FMT) ) bcf_unpack(line, BCF_UN_FMT); + bcf_fmt_t *fmt_gt = NULL; + for (i=0; in_fmt; i++) + if ( line->d.fmt[i].id==gt_id ) { fmt_gt = &line->d.fmt[i]; break; } + if ( !fmt_gt ) + error("FORMAT/GT tag not present at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1); + + // Alloc all memory in advance to avoid kput routines. The biggest allowed allele index is 99 + if ( line->n_allele > 100 ) + error("Too many alleles (%d) at %s:%d\n", line->n_allele, bcf_seqname(convert->header, line), line->pos+1); + if ( ks_resize(str, str->l+convert->nsamples*8) != 0 ) + error("Could not alloc %d bytes\n", str->l + convert->nsamples*8); + + if ( fmt_gt->type!=BCF_BT_INT8 ) // todo: use BRANCH_INT if the VCF is valid + error("Uh, too many alleles (%d) or redundant BCF representation at %s:%d\n", line->n_allele, bcf_seqname(convert->header, line), line->pos+1); + + int8_t *ptr = ((int8_t*) fmt_gt->p) - fmt_gt->n; for (i=0; insamples; i++) { - int32_t *ptr = (int32_t*)convert->dat + i*n; - int j; - for (j=0; j0) kputs(" ", str); // no space separation for first column - if ( j==2 ) + ptr += fmt_gt->n; + if ( ptr[0]==2 ) { - // diploid - if ( bcf_gt_is_missing(ptr[0]) || bcf_gt_is_missing(ptr[1]) ) { - kputs("? ?", str); + if ( ptr[1]==3 ) /* 0|0 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = ' '; } - else if ( bcf_gt_is_phased(ptr[1])) { - ksprintf(str, "%d %d", bcf_gt_allele(ptr[0]), bcf_gt_allele(ptr[1])); + else if ( ptr[1]==5 ) /* 0|1 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = ' '; } - else { - ksprintf(str, "%d* %d*", bcf_gt_allele(ptr[0]), bcf_gt_allele(ptr[1])); + else if ( ptr[1]==bcf_int8_vector_end ) /* 0 -> 0|0 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==2 ) /* 0/0 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==4 ) /* 0/1 */ + { + str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_missing(ptr[1]) ) /* 0/. */ + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_phased(ptr[1]) ) /* 0|x */ + { + str->s[str->l++] = '0'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = ' '; + } + else /* 0/x */ + { + str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = '*'; str->s[str->l++] = ' '; } } - else if ( j==1 ) + else if ( ptr[0]==4 ) { - // haploid - if ( bcf_gt_is_missing(ptr[0]) ) - kputs("? ?", str); - else if ( bcf_gt_allele(ptr[0])==1 ) - kputs("1 1", str); // first ALT allele - else - kputs("0 0", str); // REF or something else than first ALT + if ( ptr[1]==3 ) /* 1|0 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==5 ) /* 1|1 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==bcf_int8_vector_end ) /* 1 -> 1|1 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==2 ) /* 1/0 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==4 ) /* 1/1 */ + { + str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_missing(ptr[1]) ) /* 1/. */ + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; + } + else if ( bcf_gt_is_phased(ptr[1]) ) /* 1|x */ + { + str->s[str->l++] = '1'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = ' '; + } + else /* 1/x */ + { + str->s[str->l++] = '1'; str->s[str->l++] = '*'; str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + str->s[str->l++] = '*'; str->s[str->l++] = ' '; + } + } + else if ( bcf_gt_is_missing(ptr[0]) ) + { + str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; + } + else if ( ptr[1]==bcf_int8_vector_end ) + { + /* use REF for something else than first ALT */ + str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '0'; str->s[str->l++] = ' '; + } + else + { + kputw(bcf_gt_allele(ptr[0]),str); + if ( bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*'; + str->s[str->l++] = ' '; + kputw(bcf_gt_allele(ptr[1]),str); + if ( bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*'; + str->s[str->l++] = ' '; } - else error("FIXME: not ready for ploidy %d\n", j); } + str->s[--str->l] = 0; // delete the last space } static fmt_t *register_tag(convert_t *convert, int type, char *key, int is_gtf) @@ -711,6 +1013,8 @@ static fmt_t *register_tag(convert_t *convert, int type, char *key, int is_gtf) fmt->key = key ? strdup(key) : NULL; fmt->is_gt_field = is_gtf; fmt->subscript = -1; + fmt->usr = NULL; + fmt->destroy = NULL; // Allow non-format tags, such as CHROM, INFO, etc., to appear amongst the format tags. if ( key ) @@ -720,6 +1024,9 @@ static fmt_t *register_tag(convert_t *convert, int type, char *key, int is_gtf) { if ( !strcmp("CHROM",key) ) { fmt->type = T_CHROM; } else if ( !strcmp("POS",key) ) { fmt->type = T_POS; } + else if ( !strcmp("POS0",key) ) { fmt->type = T_POS0; } + else if ( !strcmp("END",key) ) { fmt->type = T_END; } + else if ( !strcmp("END0",key) ) { fmt->type = T_END0; } else if ( !strcmp("ID",key) ) { fmt->type = T_ID; } else if ( !strcmp("REF",key) ) { fmt->type = T_REF; } else if ( !strcmp("ALT",key) ) { fmt->type = T_ALT; } @@ -730,7 +1037,7 @@ static fmt_t *register_tag(convert_t *convert, int type, char *key, int is_gtf) else if ( id>=0 && bcf_hdr_idinfo_exists(convert->header,BCF_HL_INFO,id) ) { fmt->type = T_INFO; - fprintf(pysam_stderr,"Warning: Assuming INFO/%s\n", key); + fprintf(bcftools_stderr,"Warning: Assuming INFO/%s\n", key); } } } @@ -744,6 +1051,9 @@ static fmt_t *register_tag(convert_t *convert, int type, char *key, int is_gtf) case T_GP_TO_PROB3: fmt->handler = &process_gp_to_prob3; break; case T_CHROM: fmt->handler = &process_chrom; break; case T_POS: fmt->handler = &process_pos; break; + case T_POS0: fmt->handler = &process_pos0; break; + case T_END: fmt->handler = &process_end; break; + case T_END0: fmt->handler = &process_end0; break; case T_ID: fmt->handler = &process_id; break; case T_REF: fmt->handler = &process_ref; break; case T_ALT: fmt->handler = &process_alt; break; @@ -761,15 +1071,17 @@ static fmt_t *register_tag(convert_t *convert, int type, char *key, int is_gtf) case T_IUPAC_GT: fmt->handler = &process_iupac_gt; convert->max_unpack |= BCF_UN_FMT; break; case T_GT_TO_HAP: fmt->handler = &process_gt_to_hap; convert->max_unpack |= BCF_UN_FMT; break; case T_GT_TO_HAP2: fmt->handler = &process_gt_to_hap2; convert->max_unpack |= BCF_UN_FMT; break; - case T_LINE: fmt->handler = &process_line; break; + case T_TBCSQ: fmt->handler = &process_tbcsq; fmt->destroy = &destroy_tbcsq; convert->max_unpack |= BCF_UN_FMT; break; + case T_LINE: fmt->handler = &process_line; convert->max_unpack |= BCF_UN_FMT; break; default: error("TODO: handler for type %d\n", fmt->type); } - if ( key ) + if ( key && fmt->type==T_INFO ) { - if ( fmt->type==T_INFO ) + fmt->id = bcf_hdr_id2int(convert->header, BCF_DT_ID, key); + if ( !bcf_hdr_idinfo_exists(convert->header,BCF_HL_INFO,fmt->id) ) { - fmt->id = bcf_hdr_id2int(convert->header, BCF_DT_ID, key); - if ( fmt->id==-1 ) convert->undef_info_tag = strdup(key); + fmt->id = -1; + convert->undef_info_tag = strdup(key); } } return fmt; @@ -799,6 +1111,16 @@ static char *parse_tag(convert_t *convert, char *p, int is_gtf) if ( !strcmp(str.s, "SAMPLE") ) register_tag(convert, T_SAMPLE, "SAMPLE", is_gtf); else if ( !strcmp(str.s, "GT") ) register_tag(convert, T_GT, "GT", is_gtf); else if ( !strcmp(str.s, "TGT") ) register_tag(convert, T_TGT, "GT", is_gtf); + else if ( !strcmp(str.s, "TBCSQ") ) + { + fmt_t *fmt = register_tag(convert, T_TBCSQ, "BCSQ", is_gtf); + fmt->subscript = parse_subscript(&q); + if ( fmt->subscript==-1 ) + { + if ( !strncmp(q,"{*}",3) ) { fmt->subscript = 0; q += 3; } + } + else fmt->subscript++; + } else if ( !strcmp(str.s, "IUPACGT") ) register_tag(convert, T_IUPAC_GT, "GT", is_gtf); else if ( !strcmp(str.s, "INFO") ) { @@ -821,6 +1143,9 @@ static char *parse_tag(convert_t *convert, char *p, int is_gtf) { if ( !strcmp(str.s, "CHROM") ) register_tag(convert, T_CHROM, str.s, is_gtf); else if ( !strcmp(str.s, "POS") ) register_tag(convert, T_POS, str.s, is_gtf); + else if ( !strcmp(str.s, "POS0") ) register_tag(convert, T_POS0, str.s, is_gtf); + else if ( !strcmp(str.s, "END") ) register_tag(convert, T_END, str.s, is_gtf); + else if ( !strcmp(str.s, "END0") ) register_tag(convert, T_END0, str.s, is_gtf); else if ( !strcmp(str.s, "ID") ) register_tag(convert, T_ID, str.s, is_gtf); else if ( !strcmp(str.s, "REF") ) register_tag(convert, T_REF, str.s, is_gtf); else if ( !strcmp(str.s, "ALT") ) @@ -896,7 +1221,7 @@ convert_t *convert_init(bcf_hdr_t *hdr, int *samples, int nsamples, const char * char *p = convert->format_str; while ( *p ) { - //fprintf(pysam_stderr,"<%s>\n", p); + //fprintf(bcftools_stderr,"<%s>\n", p); switch (*p) { case '[': is_gtf = 1; p++; break; @@ -905,6 +1230,8 @@ convert_t *convert_init(bcf_hdr_t *hdr, int *samples, int nsamples, const char * default: p = parse_sep(convert, p, is_gtf); break; } } + if ( is_gtf ) + error("Could not parse the format string, missing the square bracket \"]\": %s\n", convert->format_str); if ( nsamples ) { @@ -925,7 +1252,10 @@ void convert_destroy(convert_t *convert) { int i; for (i=0; infmt; i++) + { + if ( convert->fmt[i].destroy ) convert->fmt[i].destroy(convert->fmt[i].usr); free(convert->fmt[i].key); + } free(convert->fmt); free(convert->undef_info_tag); free(convert->dat); @@ -986,7 +1316,7 @@ int convert_header(convert_t *convert, kstring_t *str) int convert_line(convert_t *convert, bcf1_t *line, kstring_t *str) { if ( !convert->allow_undef_tags && convert->undef_info_tag ) - error("Error: no such tag defined in the VCF header: INFO/%s\n", convert->undef_info_tag); + error("Error: no such tag defined in the VCF header: INFO/%s. FORMAT fields must be in square brackets, e.g. \"[ %s]\"\n", convert->undef_info_tag,convert->undef_info_tag); int l_ori = str->l; bcf_unpack(line, convert->max_unpack); @@ -995,17 +1325,27 @@ int convert_line(convert_t *convert, bcf1_t *line, kstring_t *str) str->l = 0; for (i=0; infmt; i++) { - // Genotype fields + // Genotype fields. if ( convert->fmt[i].is_gt_field ) { int j = i, js, k; - while ( convert->fmt[j].is_gt_field ) + while ( jnfmt && convert->fmt[j].is_gt_field ) { convert->fmt[j].ready = 0; j++; } for (js=0; jsnsamples; js++) { + // Skip samples when filtering was requested + if ( *convert->subset_samples && !(*convert->subset_samples)[js] ) continue; + + // Here comes a hack designed for TBCSQ. When running on large files, + // such as 1000GP, there are too many empty fields in the output and + // it's very very slow. Therefore in case the handler does not add + // anything to the string, we trim all genotype fields enclosed in square + // brackets here. This may be changed in future, time will show... + size_t l_start = str->l; + int ks = convert->samples[js]; for (k=i; kreaders,ir)?'1':'0', str); } else if ( convert->fmt[k].handler ) + { + size_t l = str->l; convert->fmt[k].handler(convert, line, &convert->fmt[k], ks, str); + if ( l==str->l ) { str->l = l_start; break; } // only TBCSQ does this + } } } i = j-1; @@ -1029,6 +1373,7 @@ int convert_line(convert_t *convert, bcf1_t *line, kstring_t *str) } else if ( convert->fmt[i].handler ) convert->fmt[i].handler(convert, line, &convert->fmt[i], -1, str); + } return str->l - l_ori; } @@ -1044,6 +1389,9 @@ int convert_set_option(convert_t *convert, enum convert_option opt, ...) case allow_undef_tags: convert->allow_undef_tags = va_arg(args, int); break; + case subset_samples: + convert->subset_samples = va_arg(args, uint8_t**); + break; default: ret = -1; } diff --git a/bcftools/convert.h b/bcftools/convert.h index 37123388d..11e892de3 100644 --- a/bcftools/convert.h +++ b/bcftools/convert.h @@ -30,7 +30,8 @@ THE SOFTWARE. */ typedef struct _convert_t convert_t; enum convert_option { - allow_undef_tags + allow_undef_tags, + subset_samples, }; convert_t *convert_init(bcf_hdr_t *hdr, int *samples, int nsamples, const char *str); diff --git a/bcftools/csq.c b/bcftools/csq.c new file mode 100644 index 000000000..b36ebc32d --- /dev/null +++ b/bcftools/csq.c @@ -0,0 +1,3844 @@ +/* The MIT License + + Copyright (c) 2016-2018 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ +/* + Things that would be nice to have + - for stop-lost events (also in frameshifts) report the number of truncated aa's + - memory could be greatly reduced by indexing gff (but it is quite compact already) + - deletions that go beyond transcript boundaries are not checked at sequence level + - alloc tscript->ref in hap_finalize, introduce fa_off_beg:16,fa_off_end:16 + - see test/csq/ENST00000573314/insertion-overlap.vcf #1476288882 + + Read about transcript types here + http://vega.sanger.ac.uk/info/about/gene_and_transcript_types.html + http://www.ensembl.org/info/genome/variation/predicted_data.html + http://www.gencodegenes.org/gencode_biotypes.html + + List of supported biotypes + antisense + IG_C_gene + IG_D_gene + IG_J_gene + IG_LV_gene + IG_V_gene + lincRNA + macro_lncRNA + miRNA + misc_RNA + Mt_rRNA + Mt_tRNA + polymorphic_pseudogene + processed_transcript + protein_coding + ribozyme + rRNA + sRNA + scRNA + scaRNA + sense_intronic + sense_overlapping + snRNA + snoRNA + TR_C_gene + TR_D_gene + TR_J_gene + TR_V_gene + + The gff parsing logic + We collect features such by combining gff lines A,B,C as follows: + A .. gene line with a supported biotype + A.ID=~/^gene:/ + + B .. transcript line referencing A + B.ID=~/^transcript:/ && B.Parent=~/^gene:A.ID/ + + C .. corresponding CDS, exon, and UTR lines: + C[3] in {"CDS","exon","three_prime_UTR","five_prime_UTR"} && C.Parent=~/^transcript:B.ID/ + + For coding biotypes ("protein_coding" or "polymorphic_pseudogene") the + complete chain link C -> B -> A is required. For the rest, link B -> A suffices. + + + The supported consequence types, sorted by impact: + splice_acceptor_variant .. end region of an intron changed (2bp at the 3' end of an intron) + splice_donor_variant .. start region of an intron changed (2bp at the 5' end of an intron) + stop_gained .. DNA sequence variant resulting in a stop codon + frameshift_variant .. number of inserted/deleted bases not a multiple of three, disrupted translational frame + stop_lost .. elongated transcript, stop codon changed + start_lost .. the first codon changed + inframe_altering .. combination of indels leading to unchanged reading frame and length + inframe_insertion .. inserted coding sequence, unchanged reading frame + inframe_deletion .. deleted coding sequence, unchanged reading frame + missense_variant .. amino acid (aa) change, unchanged length + splice_region_variant .. change within 1-3 bases of the exon or 3-8 bases of the intron + synonymous_variant .. DNA sequence variant resulting in no amino acid change + stop_retained_variant .. different stop codon + non_coding_variant .. variant in non-coding sequence, such as RNA gene + 5_prime_UTR_variant + 3_prime_UTR_variant + intron_variant .. reported only if none of the above + intergenic_variant .. reported only if none of the above + + + The annotation algorithm. + The algorithm checks if the variant falls in a region of a supported type. The + search is performed in the following order, until a match is found: + 1. idx_cds(gf_cds_t) - lookup CDS by position, create haplotypes, call consequences + 2. idx_utr(gf_utr_t) - check UTR hits + 3. idx_exon(gf_exon_t) - check for splice variants + 4. idx_tscript(tscript_t) - check for intronic variants, RNAs, etc. + + These regidx indexes are created by parsing a gff3 file as follows: + 1. create the array "ftr" of all UTR, CDS, exons. This will be + processed later and pruned based on transcript types we want to keep. + In the same go, create the hash "id2tr" of transcripts to keep + (based on biotype) which maps from transcript_id to a transcript. At + the same time also build the hash "gid2gene" which maps from gene_id to + gf_gene_t pointer. + + 2. build "idx_cds", "idx_tscript", "idx_utr" and "idx_exon" indexes. + Use only features from "ftr" which are present in "id2tr". + + 3. clean data that won't be needed anymore: ftr, id2tr, gid2gene. + + Data structures. + idx_cds, idx_utr, idx_exon, idx_tscript: + as described above, regidx structures for fast lookup of exons/transcripts + overlapping a region, the payload is a pointer to tscript.cds +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "bcftools.h" +#include "filter.h" +#include "regidx.h" +#include "kheap.h" +#include "smpl_ilist.h" +#include "rbuf.h" + +#ifndef __FUNCTION__ +# define __FUNCTION__ __func__ +#endif + +// Logic of the filters: include or exclude sites which match the filters? +#define FLT_INCLUDE 1 +#define FLT_EXCLUDE 2 + +// Definition of splice_region, splice_acceptor and splice_donor +#define N_SPLICE_DONOR 2 +#define N_SPLICE_REGION_EXON 3 +#define N_SPLICE_REGION_INTRON 8 + +#define N_REF_PAD 10 // number of bases to avoid boundary effects + +#define STRAND_REV 0 +#define STRAND_FWD 1 + +#define TRIM_NONE 0 +#define TRIM_5PRIME 1 +#define TRIM_3PRIME 2 + +// How to treat phased/unphased genotypes +#define PHASE_REQUIRE 0 // --phase r +#define PHASE_MERGE 1 // --phase m +#define PHASE_AS_IS 2 // --phase a +#define PHASE_SKIP 3 // --phase s +#define PHASE_NON_REF 4 // --phase R +#define PHASE_DROP_GT 5 // --samples - + +// Node types in the haplotype tree +#define HAP_CDS 0 +#define HAP_ROOT 1 +#define HAP_SSS 2 // start/stop/splice + +#define CSQ_PRINTED_UPSTREAM (1<<0) +#define CSQ_SYNONYMOUS_VARIANT (1<<1) +#define CSQ_MISSENSE_VARIANT (1<<2) +#define CSQ_STOP_LOST (1<<3) +#define CSQ_STOP_GAINED (1<<4) +#define CSQ_INFRAME_DELETION (1<<5) +#define CSQ_INFRAME_INSERTION (1<<6) +#define CSQ_FRAMESHIFT_VARIANT (1<<7) +#define CSQ_SPLICE_ACCEPTOR (1<<8) +#define CSQ_SPLICE_DONOR (1<<9) +#define CSQ_START_LOST (1<<10) +#define CSQ_SPLICE_REGION (1<<11) +#define CSQ_STOP_RETAINED (1<<12) +#define CSQ_UTR5 (1<<13) +#define CSQ_UTR3 (1<<14) +#define CSQ_NON_CODING (1<<15) +#define CSQ_INTRON (1<<16) +//#define CSQ_INTERGENIC (1<<17) +#define CSQ_INFRAME_ALTERING (1<<18) +#define CSQ_UPSTREAM_STOP (1<<19) // adds * in front of the csq string +#define CSQ_INCOMPLETE_CDS (1<<20) // to remove START/STOP in incomplete CDS, see ENSG00000173376/synon.vcf +#define CSQ_CODING_SEQUENCE (1<<21) // cannot tell exactly what it is, but it does affect the coding sequence + +// Haplotype-aware consequences, printed in one vcf record only, the rest has a reference @12345 +#define CSQ_COMPOUND (CSQ_SYNONYMOUS_VARIANT|CSQ_MISSENSE_VARIANT|CSQ_STOP_LOST|CSQ_STOP_GAINED| \ + CSQ_INFRAME_DELETION|CSQ_INFRAME_INSERTION|CSQ_FRAMESHIFT_VARIANT| \ + CSQ_START_LOST|CSQ_STOP_RETAINED|CSQ_INFRAME_ALTERING|CSQ_INCOMPLETE_CDS| \ + CSQ_UPSTREAM_STOP) +#define CSQ_START_STOP (CSQ_STOP_LOST|CSQ_STOP_GAINED|CSQ_STOP_RETAINED|CSQ_START_LOST) + +#define CSQ_PRN_STRAND(csq) ((csq)&CSQ_COMPOUND && !((csq)&(CSQ_SPLICE_ACCEPTOR|CSQ_SPLICE_DONOR|CSQ_SPLICE_REGION))) +#define CSQ_PRN_TSCRIPT (~(CSQ_INTRON|CSQ_NON_CODING)) +#define CSQ_PRN_BIOTYPE CSQ_NON_CODING + +// see kput_vcsq() +const char *csq_strings[] = +{ + NULL, + "synonymous", + "missense", + "stop_lost", + "stop_gained", + "inframe_deletion", + "inframe_insertion", + "frameshift", + "splice_acceptor", + "splice_donor", + "start_lost", + "splice_region", + "stop_retained", + "5_prime_utr", + "3_prime_utr", + "non_coding", + "intron", + "intergenic", + "inframe_altering", + NULL, + NULL, + "coding_sequence" +}; + + +// GFF line types +#define GFF_TSCRIPT_LINE 1 +#define GFF_GENE_LINE 2 + + +/* + Genomic features, for fast lookup by position to overlapping features +*/ +#define GF_coding_bit 6 +#define GF_is_coding(x) ((x) & (1<5I|121ACG>A+124TA>T" + + vcrec_t + single VCF record and csq tied to this record. (Haplotype can have multiple + consequences in several VCF records. Each record can have multiple consequences + from multiple haplotypes.) + + csq_t + a top-level consequence tied to a haplotype + + vbuf_t + pos2vbuf + VCF records with the same position clustered together for a fast lookup via pos2vbuf +*/ +typedef struct _vbuf_t vbuf_t; +typedef struct _vcsq_t vcsq_t; +struct _vcsq_t +{ + uint32_t strand:1, + type:31; // one of CSQ_* types + uint32_t trid; + uint32_t biotype; // one of GF_* types + char *gene; // gene name + bcf1_t *ref; // if type&CSQ_PRINTED_UPSTREAM, ref consequence "@1234" + kstring_t vstr; // variant string, eg 5TY>5I|121ACG>A+124TA>T +}; +typedef struct +{ + bcf1_t *line; + uint32_t *smpl; // bitmask of sample consequences with first/second haplotype interleaved + uint32_t nfmt:4, nvcsq:28, mvcsq; + vcsq_t *vcsq; // there can be multiple consequences for a single VCF record +} +vrec_t; +typedef struct +{ + uint32_t pos; + vrec_t *vrec; // vcf line that this csq is tied to; needed when printing haplotypes (hap_stage_vcf) + int idx; // 0-based index of the csq at the VCF line, for FMT/BCSQ + vcsq_t type; +} +csq_t; +struct _vbuf_t +{ + vrec_t **vrec; // buffer of VCF lines with the same position + int n, m; +}; +KHASH_MAP_INIT_INT(pos2vbuf, vbuf_t*) + + +/* + Structures related to haplotype-aware consequences in coding regions + + hap_node_t + node of a haplotype tree. Each transcript has one tree + + tscript_t + despite its general name, it is intended for coding transcripts only + + hap_t + hstack_t + for traversal of the haplotype tree and braking combined + consequences into independent parts +*/ +typedef struct _hap_node_t hap_node_t; +struct _hap_node_t +{ + char *seq; // cds segment [parent_node,this_node) + char *var; // variant "ref>alt" + uint32_t type:2, // HAP_ROOT or HAP_CDS + csq:30; // this node's consequence + int dlen; // alt minus ref length: <0 del, >0 ins, 0 substitution + uint32_t rbeg; // variant's VCF position (0-based, inclusive) + int32_t rlen; // variant's rlen; alen=rlen+dlen; fake for non CDS types + uint32_t sbeg; // variant's position on the spliced reference transcript (0-based, inclusive, N_REF_PAD not included) + uint32_t icds; // which exon does this node's variant overlaps + hap_node_t **child, *prev; // children haplotypes and previous coding node + int nchild, mchild; + bcf1_t *cur_rec, *rec; // current VCF record and node's VCF record + uint32_t nend; // number of haplotypes ending in this node + int *cur_child, mcur_child; // mapping from the allele to the currently active child + csq_t *csq_list; // list of haplotype's consequences, broken by position + int ncsq_list, mcsq_list; +}; +struct _tscript_t +{ + uint32_t id; // transcript id + uint32_t beg,end; // transcript's beg and end coordinate (ref strand, 0-based, inclusive) + uint32_t strand:1, // STRAND_REV or STRAND_FWD + ncds:31, // number of exons + mcds; + gf_cds_t **cds; // ordered list of exons + char *ref; // reference sequence, padded with N_REF_PAD bases on both ends + char *sref; // spliced reference sequence, padded with N_REF_PAD bases on both ends + hap_node_t *root; // root of the haplotype tree + hap_node_t **hap; // pointer to haplotype leaves, two for each sample + int nhap, nsref; // number of haplotypes and length of sref, including 2*N_REF_PAD + uint32_t trim:2, // complete, 5' or 3' trimmed, see TRIM_* types + type:30; // one of GF_* types + gf_gene_t *gene; +}; +static inline int cmp_tscript(tscript_t **a, tscript_t **b) +{ + return ( (*a)->end < (*b)->end ) ? 1 : 0; +} +KHEAP_INIT(trhp, tscript_t*, cmp_tscript) +typedef khp_trhp_t tr_heap_t; +typedef struct +{ + hap_node_t *node; // current node + int ichild; // current child in the active node + int dlen; // total dlen, from the root to the active node + size_t slen; // total sequence length, from the root to the active node +} +hstack_t; +typedef struct +{ + int mstack; + hstack_t *stack; + tscript_t *tr; // tr->ref: spliced transcript on ref strand + kstring_t sseq; // spliced haplotype sequence on ref strand + kstring_t tseq; // the variable part of translated haplotype transcript, coding strand + kstring_t tref; // the variable part of translated reference transcript, coding strand + uint32_t sbeg; // stack's sbeg, for cases first node's type is HAP_SSS + int upstream_stop; +} +hap_t; + + +/* + Helper structures, only for initialization + + ftr_t + temporary list of all exons, CDS, UTRs +*/ +KHASH_MAP_INIT_INT(int2tscript, tscript_t*) +KHASH_MAP_INIT_INT(int2gene, gf_gene_t*) +typedef struct +{ + int type; // GF_CDS, GF_EXON, GF_5UTR, GF_3UTR + uint32_t beg; + uint32_t end; + uint32_t trid; + uint32_t strand:1; // STRAND_REV,STRAND_FWD + uint32_t phase:2; // 0, 1 or 2 + uint32_t iseq:29; +} +ftr_t; +/* + Mapping from GFF ID string (such as ENST00000450305 or Zm00001d027230_P001) + to integer id. To keep the memory requirements low, the original version + relied on IDs in the form of a string prefix and a numerical id. However, + it turns out that this assumption is not valid for some ensembl GFFs, see + for example Zea_mays.AGPv4.36.gff3.gz + */ +typedef struct +{ + void *str2id; // khash_str2int + int nstr, mstr; + char **str; // numeric id to string +} +id_tbl_t; +typedef struct +{ + // all exons, CDS, UTRs + ftr_t *ftr; + int nftr, mftr; + + // mapping from gene id to gf_gene_t + kh_int2gene_t *gid2gene; + + // mapping from transcript id to tscript, for quick CDS anchoring + kh_int2tscript_t *id2tr; + + // sequences + void *seq2int; // str2int hash + char **seq; + int nseq, mseq; + + // ignored biotypes + void *ignored_biotypes; + + id_tbl_t gene_ids; // temporary table for mapping between gene id (eg. Zm00001d027245) and a numeric idx +} +aux_t; + +typedef struct _args_t +{ + // the main regidx lookups, from chr:beg-end to overlapping features and + // index iterator + regidx_t *idx_cds, *idx_utr, *idx_exon, *idx_tscript; + regitr_t *itr; + + // temporary structures, deleted after initializtion + aux_t init; + + // text tab-delimited output (out) or vcf/bcf output (out_fh) + FILE *out; + htsFile *out_fh; + + // vcf + bcf_srs_t *sr; + bcf_hdr_t *hdr; + int hdr_nsmpl; // actual number of samples in the vcf, for bcf_update_format_values() + + // include or exclude sites which match the filters + filter_t *filter; + char *filter_str; + int filter_logic; // FLT_INCLUDE or FLT_EXCLUDE + + // samples to process + int sample_is_file; + char *sample_list; + smpl_ilist_t *smpl; + + char *outdir, **argv, *fa_fname, *gff_fname, *output_fname; + char *bcsq_tag; + int argc, output_type; + int phase, quiet, local_csq; + int ncsq_max, nfmt_bcsq; // maximum number of csq per site that can be accessed from FORMAT/BCSQ + int ncsq_small_warned; + + int rid; // current chromosome + tr_heap_t *active_tr; // heap of active transcripts for quick flushing + hap_t *hap; // transcript haplotype recursion + vbuf_t **vcf_buf; // buffered VCF lines to annotate with CSQ and flush + rbuf_t vcf_rbuf; // round buffer indexes to vcf_buf + kh_pos2vbuf_t *pos2vbuf; // fast lookup of buffered lines by position + tscript_t **rm_tr; // buffer of transcripts to clean + int nrm_tr, mrm_tr; + csq_t *csq_buf; // pool of csq not managed by hap_node_t, i.e. non-CDS csqs + int ncsq_buf, mcsq_buf; + id_tbl_t tscript_ids; // mapping between transcript id (eg. Zm00001d027245_T001) and a numeric idx + + faidx_t *fai; + kstring_t str, str2; + int32_t *gt_arr, mgt_arr; +} +args_t; + +// AAA, AAC, ... +const char *gencode = "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSS*CWCLFLF"; +const uint8_t nt4[] = +{ + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,0,4,1, 4,4,4,2, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 3,4,4,4, 4,4,4,4, 4,4,4,4, + 4,0,4,1, 4,4,4,2, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 3 +}; +const uint8_t cnt4[] = +{ + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,3,4,2, 4,4,4,1, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 0,4,4,4, 4,4,4,4, 4,4,4,4, + 4,3,4,2, 4,4,4,1, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 0 +}; +#define dna2aa(x) gencode[ nt4[(uint8_t)(x)[0]]<<4 | nt4[(uint8_t)(x)[1]]<<2 | nt4[(uint8_t)(x)[2]] ] +#define cdna2aa(x) gencode[ cnt4[(uint8_t)(x)[2]]<<4 | cnt4[(uint8_t)(x)[1]]<<2 | cnt4[(uint8_t)(x)[0]] ] + +static const char *gf_strings_noncoding[] = +{ + "MT_rRNA", "MT_tRNA", "lincRNA", "miRNA", "misc_RNA", "rRNA", "snRNA", "snoRNA", "processed_transcript", + "antisense", "macro_lncRNA", "ribozyme", "sRNA", "scRNA", "scaRNA", "sense_intronic", "sense_overlapping", + "pseudogene", "processed_pseudogene", "artifact", "IG_pseudogene", "IG_C_pseudogene", "IG_J_pseudogene", + "IG_V_pseudogene", "TR_V_pseudogene", "TR_J_pseudogene", "MT_tRNA_pseudogene", "misc_RNA_pseudogene", + "miRNA_pseudogene", "ribozyme", "retained_intron", "retrotransposed", "Trna_pseudogene", "transcribed_processed_pseudogene", + "transcribed_unprocessed_pseudogene", "transcribed_unitary_pseudogene", "translated_unprocessed_pseudogene", + "translated_processed_pseudogene", "known_ncRNA", "unitary_pseudogene", "unprocessed_pseudogene", + "LRG_gene", "3_prime_overlapping_ncRNA", "disrupted_domain", "vaultRNA", "bidirectional_promoter_lncRNA", "ambiguous_orf" +}; +static const char *gf_strings_coding[] = { "protein_coding", "polymorphic_pseudogene", "IG_C", "IG_D", "IG_J", "IG_LV", "IG_V", "TR_C", "TR_D", "TR_J", "TR_V", "NMD", "non_stop_decay"}; +static const char *gf_strings_special[] = { "CDS", "exon", "3_prime_UTR", "5_prime_UTR" }; + +const char *gf_type2gff_string(int type) +{ + if ( !GF_is_coding(type) ) + { + if ( type < (1<init; + char c = chr_end[1]; + chr_end[1] = 0; + int iseq; + if ( khash_str2int_get(aux->seq2int, chr_beg, &iseq)!=0 ) + { + hts_expand(char*, aux->nseq+1, aux->mseq, aux->seq); + aux->seq[aux->nseq] = strdup(chr_beg); + iseq = khash_str2int_inc(aux->seq2int, aux->seq[aux->nseq]); + aux->nseq++; + assert( aux->nseq < 256 ); // see gf_gene_t.iseq + } + chr_end[1] = c; + return iseq; +} +static inline char *gff_skip(const char *line, char *ss) +{ + while ( *ss && *ss!='\t' ) ss++; + if ( !*ss ) error("[%s:%d %s] Could not parse the line: %s\n",__FILE__,__LINE__,__FUNCTION__,line); + return ss+1; +} +static inline void gff_parse_chr(const char *line, char **chr_beg, char **chr_end) +{ + char *se = (char*) line; + while ( *se && *se!='\t' ) se++; + if ( !*se ) error("[%s:%d %s] Could not parse the line: %s\n",__FILE__,__LINE__,__FUNCTION__,line); + *chr_beg = (char*) line; + *chr_end = se-1; +} +static inline char *gff_parse_beg_end(const char *line, char *ss, uint32_t *beg, uint32_t *end) +{ + char *se = ss; + *beg = strtol(ss, &se, 10) - 1; + if ( ss==se ) error("[%s:%d %s] Could not parse the line:\n\t%s\n\t%s\n",__FILE__,__LINE__,__FUNCTION__,line,ss); + ss = se+1; + *end = strtol(ss, &se, 10) - 1; + if ( ss==se ) error("[%s:%d %s] Could not parse the line: %s\n",__FILE__,__LINE__,__FUNCTION__,line); + return se+1; +} +static void gff_id_init(id_tbl_t *tbl) +{ + memset(tbl, 0, sizeof(*tbl)); + tbl->str2id = khash_str2int_init(); +} +static void gff_id_destroy(id_tbl_t *tbl) +{ + khash_str2int_destroy_free(tbl->str2id); + free(tbl->str); +} +static inline uint32_t gff_id_parse(id_tbl_t *tbl, const char *line, const char *needle, char *ss) +{ + ss = strstr(ss,needle); // e.g. "ID=transcript:" + if ( !ss ) error("[%s:%d %s] Could not parse the line, \"%s\" not present: %s\n",__FILE__,__LINE__,__FUNCTION__,needle,line); + ss += strlen(needle); + + char *se = ss; + while ( *se && *se!=';' && !isspace(*se) ) se++; + char tmp = *se; + *se = 0; + + int id; + if ( khash_str2int_get(tbl->str2id, ss, &id) < 0 ) + { + id = tbl->nstr++; + hts_expand(char*, tbl->nstr, tbl->mstr, tbl->str); + tbl->str[id] = strdup(ss); + khash_str2int_set(tbl->str2id, tbl->str[id], id); + } + *se = tmp; + + return id; +} +static inline int gff_parse_type(char *line) +{ + line = strstr(line,"ID="); + if ( !line ) return -1; + line += 3; + if ( !strncmp(line,"transcript:",11) ) return GFF_TSCRIPT_LINE; + else if ( !strncmp(line,"gene:",5) ) return GFF_GENE_LINE; + return -1; +} +static inline int gff_parse_biotype(char *_line) +{ + char *line = strstr(_line,"biotype="); + if ( !line ) return -1; + + line += 8; + switch (*line) + { + case 'p': + if ( !strncmp(line,"protein_coding",14) ) return GF_PROTEIN_CODING; + else if ( !strncmp(line,"pseudogene",10) ) return GF_PSEUDOGENE; + else if ( !strncmp(line,"processed_transcript",20) ) return GF_PROCESSED_TRANSCRIPT; + else if ( !strncmp(line,"processed_pseudogene",20) ) return GF_PROCESSED_PSEUDOGENE; + else if ( !strncmp(line,"polymorphic_pseudogene",22) ) return GF_POLYMORPHIC_PSEUDOGENE; + break; + case 'a': + if ( !strncmp(line,"artifact",8) ) return GF_ARTIFACT; + else if ( !strncmp(line,"antisense",9) ) return GF_ANTISENSE; + else if ( !strncmp(line,"ambiguous_orf",13) ) return GF_AMBIGUOUS_ORF; + break; + case 'I': + if ( !strncmp(line,"IG_C_gene",9) ) return GF_IG_C; + else if ( !strncmp(line,"IG_D_gene",9) ) return GF_IG_D; + else if ( !strncmp(line,"IG_J_gene",9) ) return GF_IG_J; + else if ( !strncmp(line,"IG_LV_gene",10) ) return GF_IG_LV; + else if ( !strncmp(line,"IG_V_gene",9) ) return GF_IG_V; + else if ( !strncmp(line,"IG_pseudogene",13) ) return GF_IG_PSEUDOGENE; + else if ( !strncmp(line,"IG_C_pseudogene",15) ) return GF_IG_C_PSEUDOGENE; + else if ( !strncmp(line,"IG_J_pseudogene",15) ) return GF_IG_J_PSEUDOGENE; + else if ( !strncmp(line,"IG_V_pseudogene",15) ) return GF_IG_V_PSEUDOGENE; + break; + case 'T': + if ( !strncmp(line,"TR_C_gene",9) ) return GF_TR_C; + else if ( !strncmp(line,"TR_D_gene",9) ) return GF_TR_D; + else if ( !strncmp(line,"TR_J_gene",9) ) return GF_TR_J; + else if ( !strncmp(line,"TR_V_gene",9) ) return GF_TR_V; + else if ( !strncmp(line,"TR_V_pseudogene",15) ) return GF_TR_V_PSEUDOGENE; + else if ( !strncmp(line,"TR_J_pseudogene",15) ) return GF_TR_J_PSEUDOGENE; + break; + case 'M': + if ( !strncmp(line,"Mt_tRNA_pseudogene",18) ) return GF_MT_tRNA_PSEUDOGENE; + else if ( !strncmp(line,"Mt_tRNA",7) ) return GF_MT_tRNA; + else if ( !strncmp(line,"Mt_rRNA",7) ) return GF_MT_tRNA; + break; + case 'l': + if ( !strncmp(line,"lincRNA",7) ) return GF_lincRNA; + break; + case 'm': + if ( !strncmp(line,"macro_lncRNA",12) ) return GF_macro_lncRNA; + else if ( !strncmp(line,"misc_RNA_pseudogene",19) ) return GF_misc_RNA_PSEUDOGENE; + else if ( !strncmp(line,"miRNA_pseudogene",16) ) return GF_miRNA_PSEUDOGENE; + else if ( !strncmp(line,"miRNA",5) ) return GF_miRNA; + else if ( !strncmp(line,"misc_RNA",8) ) return GF_MISC_RNA; + break; + case 'r': + if ( !strncmp(line,"rRNA",4) ) return GF_rRNA; + else if ( !strncmp(line,"ribozyme",8) ) return GF_RIBOZYME; + else if ( !strncmp(line,"retained_intron",15) ) return GF_RETAINED_INTRON; + else if ( !strncmp(line,"retrotransposed",15) ) return GF_RETROTRANSPOSED; + break; + case 's': + if ( !strncmp(line,"snRNA",5) ) return GF_snRNA; + else if ( !strncmp(line,"sRNA",4) ) return GF_sRNA; + else if ( !strncmp(line,"scRNA",5) ) return GF_scRNA; + else if ( !strncmp(line,"scaRNA",6) ) return GF_scaRNA; + else if ( !strncmp(line,"snoRNA",6) ) return GF_snoRNA; + else if ( !strncmp(line,"sense_intronic",14) ) return GF_SENSE_INTRONIC; + else if ( !strncmp(line,"sense_overlapping",17) ) return GF_SENSE_OVERLAPPING; + break; + case 't': + if ( !strncmp(line,"tRNA_pseudogene",15) ) return GF_tRNA_PSEUDOGENE; + else if ( !strncmp(line,"transcribed_processed_pseudogene",32) ) return GF_TRANSCRIBED_PROCESSED_PSEUDOGENE; + else if ( !strncmp(line,"transcribed_unprocessed_pseudogene",34) ) return GF_TRANSCRIBED_UNPROCESSED_PSEUDOGENE; + else if ( !strncmp(line,"transcribed_unitary_pseudogene",30) ) return GF_TRANSCRIBED_UNITARY_PSEUDOGENE; + else if ( !strncmp(line,"translated_unprocessed_pseudogene",33) ) return GF_TRANSLATED_UNPROCESSED_PSEUDOGENE; + else if ( !strncmp(line,"translated_processed_pseudogene",31) ) return GF_TRANSLATED_PROCESSED_PSEUDOGENE; + break; + case 'n': + if ( !strncmp(line,"nonsense_mediated_decay",23) ) return GF_NMD; + else if ( !strncmp(line,"non_stop_decay",14) ) return GF_NON_STOP_DECAY; + break; + case 'k': + if ( !strncmp(line,"known_ncrna",11) ) return GF_KNOWN_NCRNA; + break; + case 'u': + if ( !strncmp(line,"unitary_pseudogene",18) ) return GF_UNITARY_PSEUDOGENE; + else if ( !strncmp(line,"unprocessed_pseudogene",22) ) return GF_UNPROCESSED_PSEUDOGENE; + break; + case 'L': + if ( !strncmp(line,"LRG_gene",8) ) return GF_LRG_GENE; + break; + case '3': + if ( !strncmp(line,"3prime_overlapping_ncRNA",24) ) return GF_3PRIME_OVERLAPPING_ncRNA; + break; + case 'd': + if ( !strncmp(line,"disrupted_domain",16) ) return GF_DISRUPTED_DOMAIN; + break; + case 'v': + if ( !strncmp(line,"vaultRNA",8) ) return GF_vaultRNA; + break; + case 'b': + if ( !strncmp(line,"bidirectional_promoter_lncRNA",29) ) return GF_BIDIRECTIONAL_PROMOTER_lncRNA; + break; + } + return 0; +} +static inline int gff_ignored_biotype(args_t *args, char *ss) +{ + ss = strstr(ss,"biotype="); + if ( !ss ) return 0; + + ss += 8; + char *se = ss, tmp; + while ( *se && *se!=';' ) se++; + tmp = *se; + *se = 0; + + char *key = ss; + int n = 0; + if ( khash_str2int_get(args->init.ignored_biotypes, ss, &n)!=0 ) key = strdup(ss); + khash_str2int_set(args->init.ignored_biotypes, key, n+1); + + *se = tmp; + return 1; +} +gf_gene_t *gene_init(aux_t *aux, uint32_t gene_id) +{ + khint_t k = kh_get(int2gene, aux->gid2gene, (int)gene_id); + gf_gene_t *gene = (k == kh_end(aux->gid2gene)) ? NULL : kh_val(aux->gid2gene, k); + if ( !gene ) + { + gene = (gf_gene_t*) calloc(1,sizeof(gf_gene_t)); + int ret; + k = kh_put(int2gene, aux->gid2gene, (int)gene_id, &ret); + kh_val(aux->gid2gene,k) = gene; + } + return gene; +} +void gff_parse_transcript(args_t *args, const char *line, char *ss, ftr_t *ftr) +{ + aux_t *aux = &args->init; + int biotype = gff_parse_biotype(ss); + if ( biotype <= 0 ) + { + if ( !gff_ignored_biotype(args, ss) && args->quiet<2 ) fprintf(stderr,"ignored transcript: %s\n",line); + return; + } + + // create a mapping from transcript_id to gene_id + uint32_t trid = gff_id_parse(&args->tscript_ids, line, "ID=transcript:", ss); + uint32_t gene_id = gff_id_parse(&args->init.gene_ids, line, "Parent=gene:", ss); + + tscript_t *tr = (tscript_t*) calloc(1,sizeof(tscript_t)); + tr->id = trid; + tr->strand = ftr->strand; + tr->gene = gene_init(aux, gene_id); + tr->type = biotype; + tr->beg = ftr->beg; + tr->end = ftr->end; + + khint_t k; + int ret; + k = kh_put(int2tscript, aux->id2tr, (int)trid, &ret); + kh_val(aux->id2tr,k) = tr; +} +void gff_parse_gene(args_t *args, const char *line, char *ss, char *chr_beg, char *chr_end, ftr_t *ftr) +{ + int biotype = gff_parse_biotype(ss); + if ( biotype <= 0 ) + { + if ( !gff_ignored_biotype(args, ss) && args->quiet<2 ) fprintf(stderr,"ignored gene: %s\n",line); + return; + } + + aux_t *aux = &args->init; + + // substring search for "ID=gene:ENSG00000437963" + uint32_t gene_id = gff_id_parse(&aux->gene_ids, line, "ID=gene:", ss); + gf_gene_t *gene = gene_init(aux, gene_id); + assert( !gene->name ); // the gene_id should be unique + + gene->iseq = feature_set_seq(args, chr_beg,chr_end); + + // substring search for "Name=OR4F5" + ss = strstr(chr_end+2,"Name="); + if ( ss ) + { + ss += 5; + char *se = ss; + while ( *se && *se!=';' && !isspace(*se) ) se++; + gene->name = (char*) malloc(se-ss+1); + memcpy(gene->name,ss,se-ss); + gene->name[se-ss] = 0; + } + else + gene->name = strdup(aux->gene_ids.str[gene_id]); // Name= field is not present, use the gene ID instead +} +int gff_parse(args_t *args, char *line, ftr_t *ftr) +{ + // - skip empty lines and commented lines + // - columns + // 1. chr + // 2. + // 3. CDS, transcript, gene, ... + // 4-5. beg,end + // 6. + // 7. strand + // 8. phase + // 9. Parent=transcript:ENST(\d+);ID=... etc + + char *ss = line; + if ( !*ss ) return -1; // skip blank lines + if ( *ss=='#' ) return -1; // skip comments + + char *chr_beg, *chr_end; + gff_parse_chr(line, &chr_beg, &chr_end); + ss = gff_skip(line, chr_end + 2); + + // 3. column: is this a CDS, transcript, gene, etc. + if ( !strncmp("exon\t",ss,5) ) { ftr->type = GF_EXON; ss += 5; } + else if ( !strncmp("CDS\t",ss,4) ) { ftr->type = GF_CDS; ss += 4; } + else if ( !strncmp("three_prime_UTR\t",ss,16) ) { ftr->type = GF_UTR3; ss += 16; } + else if ( !strncmp("five_prime_UTR\t",ss,15) ) { ftr->type = GF_UTR5; ss += 15; } + else + { + ss = gff_skip(line, ss); + ss = gff_parse_beg_end(line, ss, &ftr->beg,&ftr->end); + ss = gff_skip(line, ss); + int type = gff_parse_type(ss); + if ( type!=GFF_TSCRIPT_LINE && type!=GFF_GENE_LINE ) + { + // we ignore these, debug print to see new types: + ss = strstr(ss,"ID="); + if ( !ss ) return -1; // no ID, ignore the line + if ( !strncmp("chromosome",ss+3,10) ) return -1; + if ( !strncmp("supercontig",ss+3,11) ) return -1; + if ( args->quiet<2 ) fprintf(stderr,"ignored: %s\n", line); + return -1; + } + + // 7. column: strand + if ( *ss == '+' ) ftr->strand = STRAND_FWD; + else if ( *ss == '-' ) ftr->strand = STRAND_REV; + else error("Unknown strand: %c .. %s\n", *ss,ss); + + if ( type==GFF_TSCRIPT_LINE ) + gff_parse_transcript(args, line, ss, ftr); + else + gff_parse_gene(args, line, ss, chr_beg, chr_end, ftr); + + return -1; + } + ss = gff_parse_beg_end(line, ss, &ftr->beg,&ftr->end); + ss = gff_skip(line, ss); + + // 7. column: strand + if ( *ss == '+' ) ftr->strand = STRAND_FWD; + else if ( *ss == '-' ) ftr->strand = STRAND_REV; + else { if ( args->quiet<2 ) fprintf(stderr,"Skipping unknown strand: %c\n", *ss); return -1; } + ss += 2; + + // 8. column: phase (codon offset) + if ( *ss == '0' ) ftr->phase = 0; + else if ( *ss == '1' ) ftr->phase = 1; + else if ( *ss == '2' ) ftr->phase = 2; + else if ( *ss == '.' ) ftr->phase = 0; // exons do not have phase + else { if ( args->quiet<2 ) fprintf(stderr,"Skipping unknown phase: %c, %s\n", *ss, line); return -1; } + ss += 2; + + // substring search for "Parent=transcript:ENST00000437963" + ftr->trid = gff_id_parse(&args->tscript_ids, line, "Parent=transcript:", ss); + ftr->iseq = feature_set_seq(args, chr_beg,chr_end); + return 0; +} + +static int cmp_cds_ptr(const void *a, const void *b) +{ + // comparison function for qsort of transcripts's CDS + if ( (*((gf_cds_t**)a))->beg < (*((gf_cds_t**)b))->beg ) return -1; + if ( (*((gf_cds_t**)a))->beg > (*((gf_cds_t**)b))->beg ) return 1; + return 0; +} + +static inline void chr_beg_end(aux_t *aux, int iseq, char **chr_beg, char **chr_end) +{ + *chr_beg = *chr_end = aux->seq[iseq]; + while ( (*chr_end)[1] ) (*chr_end)++; +} +tscript_t *tscript_init(aux_t *aux, uint32_t trid) +{ + khint_t k = kh_get(int2tscript, aux->id2tr, (int)trid); + tscript_t *tr = (k == kh_end(aux->id2tr)) ? NULL : kh_val(aux->id2tr, k); + assert( tr ); + return tr; +} +void register_cds(args_t *args, ftr_t *ftr) +{ + // Make the CDS searchable via idx_cds. Note we do not malloc tr->cds just yet. + // ftr is the result of parsing a gff CDS line + aux_t *aux = &args->init; + + tscript_t *tr = tscript_init(aux, ftr->trid); + if ( tr->strand != ftr->strand ) error("Conflicting strand in transcript %"PRIu32" .. %d vs %d\n",ftr->trid,tr->strand,ftr->strand); + + gf_cds_t *cds = (gf_cds_t*) malloc(sizeof(gf_cds_t)); + cds->tr = tr; + cds->beg = ftr->beg; + cds->len = ftr->end - ftr->beg + 1; + cds->icds = 0; // to keep valgrind on mac happy + cds->phase = ftr->phase; + + hts_expand(gf_cds_t*,tr->ncds+1,tr->mcds,tr->cds); + tr->cds[tr->ncds++] = cds; +} +void register_utr(args_t *args, ftr_t *ftr) +{ + aux_t *aux = &args->init; + gf_utr_t *utr = (gf_utr_t*) malloc(sizeof(gf_utr_t)); + utr->which = ftr->type==GF_UTR3 ? prime3 : prime5; + utr->beg = ftr->beg; + utr->end = ftr->end; + utr->tr = tscript_init(aux, ftr->trid); + + char *chr_beg, *chr_end; + chr_beg_end(&args->init, utr->tr->gene->iseq, &chr_beg, &chr_end); + regidx_push(args->idx_utr, chr_beg,chr_end, utr->beg,utr->end, &utr); +} +void register_exon(args_t *args, ftr_t *ftr) +{ + aux_t *aux = &args->init; + gf_exon_t *exon = (gf_exon_t*) malloc(sizeof(gf_exon_t)); + exon->beg = ftr->beg; + exon->end = ftr->end; + exon->tr = tscript_init(aux, ftr->trid); + + char *chr_beg, *chr_end; + chr_beg_end(&args->init, exon->tr->gene->iseq, &chr_beg, &chr_end); + regidx_push(args->idx_exon, chr_beg,chr_end, exon->beg - N_SPLICE_REGION_INTRON, exon->end + N_SPLICE_REGION_INTRON, &exon); +} + +void tscript_init_cds(args_t *args) +{ + aux_t *aux = &args->init; + + // Sort CDS in all transcripts, set offsets, check their phase, length, create index (idx_cds) + khint_t k; + for (k=0; kid2tr); k++) + { + if ( !kh_exist(aux->id2tr, k) ) continue; + tscript_t *tr = (tscript_t*) kh_val(aux->id2tr, k); + + // position-to-tscript lookup + char *chr_beg, *chr_end; + chr_beg_end(aux, tr->gene->iseq, &chr_beg, &chr_end); + regidx_push(args->idx_tscript, chr_beg, chr_end, tr->beg, tr->end, &tr); + + if ( !tr->ncds ) continue; // transcript with no CDS + + // sort CDs + qsort(tr->cds, tr->ncds, sizeof(gf_cds_t*), cmp_cds_ptr); + + // trim non-coding start + int i, len = 0; + if ( tr->strand==STRAND_FWD ) + { + if ( tr->cds[0]->phase ) tr->trim |= TRIM_5PRIME; + tr->cds[0]->beg += tr->cds[0]->phase; + tr->cds[0]->len -= tr->cds[0]->phase; + tr->cds[0]->phase = 0; + + // sanity check phase + for (i=0; incds; i++) + { + int phase = tr->cds[i]->phase ? 3 - tr->cds[i]->phase : 0; + if ( phase!=len%3) + error("GFF3 assumption failed for transcript %s, CDS=%d: phase!=len%%3 (phase=%d, len=%d)\n",args->tscript_ids.str[tr->id],tr->cds[i]->beg+1,phase,len); + assert( phase == len%3 ); + len += tr->cds[i]->len; + } + } + else + { + // Check that the phase is not bigger than CDS length. Curiously, this can really happen, + // see Mus_musculus.GRCm38.85.gff3.gz, transcript:ENSMUST00000163141 + // todo: the same for the fwd strand + i = tr->ncds - 1; + int phase = tr->cds[i]->phase; + if ( phase ) tr->trim |= TRIM_5PRIME; + while ( i>=0 && phase > tr->cds[i]->len ) + { + phase -= tr->cds[i]->len; + tr->cds[i]->phase = 0; + tr->cds[i]->len = 0; + i--; + } + tr->cds[i]->len -= tr->cds[i]->phase; + tr->cds[i]->phase = 0; + + // sanity check phase + for (i=tr->ncds-1; i>=0; i--) + { + int phase = tr->cds[i]->phase ? 3 - tr->cds[i]->phase : 0; + if ( phase!=len%3) + error("GFF3 assumption failed for transcript %s, CDS=%d: phase!=len%%3 (phase=%d, len=%d)\n",args->tscript_ids.str[tr->id],tr->cds[i]->beg+1,phase,len); + len += tr->cds[i]->len; + } + } + + // set len. At the same check that CDS within a transcript do not overlap + len = 0; + for (i=0; incds; i++) + { + tr->cds[i]->icds = i; + len += tr->cds[i]->len; + if ( !i ) continue; + + gf_cds_t *a = tr->cds[i-1]; + gf_cds_t *b = tr->cds[i]; + if ( a->beg + a->len - 1 >= b->beg ) + error("Error: CDS overlap in the transcript %"PRIu32": %"PRIu32"-%"PRIu32" and %"PRIu32"-%"PRIu32"\n", + kh_key(aux->id2tr, k), a->beg+1,a->beg+a->len, b->beg+1,b->beg+b->len); + } + if ( len%3 != 0 ) + { + // There are 13k transcripts with incomplete 3' CDS. See for example ENST00000524289 + // http://sep2015.archive.ensembl.org/Homo_sapiens/Transcript/Sequence_cDNA?db=core;g=ENSG00000155868;r=5:157138846-157159019;t=ENST00000524289 + // Also, the incomplete CDS can be too short (1 or 2bp), so it is not enough to trim the last one. + + tr->trim |= TRIM_3PRIME; + if ( tr->strand==STRAND_FWD ) + { + i = tr->ncds - 1; + while ( i>=0 && len%3 ) + { + int dlen = tr->cds[i]->len >= len%3 ? len%3 : tr->cds[i]->len; + tr->cds[i]->len -= dlen; + len -= dlen; + i--; + } + } + else + { + i = 0; + while ( incds && len%3 ) + { + int dlen = tr->cds[i]->len >= len%3 ? len%3 : tr->cds[i]->len; + tr->cds[i]->len -= dlen; + tr->cds[i]->beg += dlen; + len -= dlen; + i++; + } + } + } + + // set CDS offsets and insert into regidx + len=0; + for (i=0; incds; i++) + { + tr->cds[i]->pos = len; + len += tr->cds[i]->len; + regidx_push(args->idx_cds, chr_beg,chr_end, tr->cds[i]->beg,tr->cds[i]->beg+tr->cds[i]->len-1, &tr->cds[i]); + } + } +} + +void regidx_free_gf(void *payload) { free(*((gf_cds_t**)payload)); } +void regidx_free_tscript(void *payload) { tscript_t *tr = *((tscript_t**)payload); free(tr->cds); free(tr); } + +void init_gff(args_t *args) +{ + aux_t *aux = &args->init; + aux->seq2int = khash_str2int_init(); // chrom's numeric id + aux->gid2gene = kh_init(int2gene); // gene id to gf_gene_t, for idx_gene + aux->id2tr = kh_init(int2tscript); // transcript id to tscript_t + args->idx_tscript = regidx_init(NULL, NULL, regidx_free_tscript, sizeof(tscript_t*), NULL); + aux->ignored_biotypes = khash_str2int_init(); + gff_id_init(&aux->gene_ids); + gff_id_init(&args->tscript_ids); + + // parse gff + kstring_t str = {0,0,0}; + htsFile *fp = hts_open(args->gff_fname,"r"); + if ( !fp ) error("Failed to read %s\n", args->gff_fname); + while ( hts_getline(fp, KS_SEP_LINE, &str) > 0 ) + { + hts_expand(ftr_t, aux->nftr+1, aux->mftr, aux->ftr); + int ret = gff_parse(args, str.s, aux->ftr + aux->nftr); + if ( !ret ) aux->nftr++; + } + free(str.s); + if ( hts_close(fp)!=0 ) error("Close failed: %s\n", args->gff_fname); + + + // process gff information: connect CDS and exons to transcripts + args->idx_cds = regidx_init(NULL, NULL, regidx_free_gf, sizeof(gf_cds_t*), NULL); + args->idx_utr = regidx_init(NULL, NULL, regidx_free_gf, sizeof(gf_utr_t*), NULL); + args->idx_exon = regidx_init(NULL, NULL, regidx_free_gf, sizeof(gf_exon_t*), NULL); + args->itr = regitr_init(NULL); + + int i; + for (i=0; inftr; i++) + { + ftr_t *ftr = &aux->ftr[i]; + + // check whether to keep this feature: is there a mapping trid -> gene_id -> gene? + khint_t k = kh_get(int2tscript, aux->id2tr, (int)ftr->trid); + if ( k==kh_end(aux->id2tr) ) continue; // no such transcript + + tscript_t *tr = kh_val(aux->id2tr,k); + if ( !tr->gene->name ) + { + // not a supported biotype (e.g. gene:pseudogene, transcript:processed_transcript) + regidx_free_tscript(&tr); + kh_del(int2tscript, aux->id2tr,k); + continue; + } + + // populate regidx by category: + // ftr->type .. GF_CDS, GF_EXON, GF_UTR3, GF_UTR5 + // gene->type .. GF_PROTEIN_CODING, GF_MT_rRNA, GF_IG_C, ... + if ( ftr->type==GF_CDS ) register_cds(args, ftr); + else if ( ftr->type==GF_EXON ) register_exon(args, ftr); + else if ( ftr->type==GF_UTR5 ) register_utr(args, ftr); + else if ( ftr->type==GF_UTR3 ) register_utr(args, ftr); + else + error("something: %s\t%d\t%d\t%s\t%s\n", aux->seq[ftr->iseq],ftr->beg+1,ftr->end+1,args->tscript_ids.str[ftr->trid],gf_type2gff_string(ftr->type)); + } + tscript_init_cds(args); + + if ( !args->quiet ) + { + fprintf(stderr,"Indexed %d transcripts, %d exons, %d CDSs, %d UTRs\n", + regidx_nregs(args->idx_tscript), + regidx_nregs(args->idx_exon), + regidx_nregs(args->idx_cds), + regidx_nregs(args->idx_utr)); + } + + free(aux->ftr); + khash_str2int_destroy_free(aux->seq2int); + // keeping only to destroy the genes at the end: kh_destroy(int2gene,aux->gid2gene); + kh_destroy(int2tscript,aux->id2tr); + free(aux->seq); + gff_id_destroy(&aux->gene_ids); + + if ( args->quiet<2 && khash_str2int_size(aux->ignored_biotypes) ) + { + khash_t(str2int) *ign = (khash_t(str2int)*)aux->ignored_biotypes; + fprintf(stderr,"Ignored the following biotypes:\n"); + for (i = kh_begin(ign); i < kh_end(ign); i++) + { + if ( !kh_exist(ign,i)) continue; + fprintf(stderr,"\t%dx\t.. %s\n", kh_value(ign,i), kh_key(ign,i)); + } + } + khash_str2int_destroy_free(aux->ignored_biotypes); +} + +void init_data(args_t *args) +{ + args->nfmt_bcsq = 1 + (args->ncsq_max - 1) / 32; + + if ( !args->quiet ) fprintf(stderr,"Parsing %s ...\n", args->gff_fname); + init_gff(args); + + args->rid = -1; + + if ( args->filter_str ) + args->filter = filter_init(args->hdr, args->filter_str); + + args->fai = fai_load(args->fa_fname); + if ( !args->fai ) error("Failed to load the fai index: %s\n", args->fa_fname); + + args->pos2vbuf = kh_init(pos2vbuf); + args->active_tr = khp_init(trhp); + args->hap = (hap_t*) calloc(1,sizeof(hap_t)); + + // init samples + if ( !bcf_hdr_nsamples(args->hdr) ) args->phase = PHASE_DROP_GT; + if ( args->sample_list && !strcmp("-",args->sample_list) ) + { + // ignore all samples + if ( args->output_type==FT_TAB_TEXT ) + { + // significant speedup for plain VCFs + bcf_hdr_set_samples(args->hdr,NULL,0); + } + args->phase = PHASE_DROP_GT; + } + else + args->smpl = smpl_ilist_init(args->hdr, args->sample_list, args->sample_is_file, SMPL_STRICT); + args->hdr_nsmpl = args->phase==PHASE_DROP_GT ? 0 : bcf_hdr_nsamples(args->hdr); + + if ( args->output_type==FT_TAB_TEXT ) + { + args->out = args->output_fname ? fopen(args->output_fname,"w") : stdout; + if ( !args->out ) error("Failed to open %s: %s\n", args->output_fname,strerror(errno)); + + fprintf(args->out,"# This file was produced by: bcftools +csq(%s+htslib-%s)\n", bcftools_version(),hts_version()); + fprintf(args->out,"# The command line was:\tbcftools +%s", args->argv[0]); + int i; + for (i=1; iargc; i++) + fprintf(args->out," %s",args->argv[i]); + fprintf(args->out,"\n"); + fprintf(args->out,"# LOG\t[2]Message\n"); + fprintf(args->out,"# CSQ"); i = 1; + fprintf(args->out,"\t[%d]Sample", ++i); + fprintf(args->out,"\t[%d]Haplotype", ++i); + fprintf(args->out,"\t[%d]Chromosome", ++i); + fprintf(args->out,"\t[%d]Position", ++i); + fprintf(args->out,"\t[%d]Consequence", ++i); + fprintf(args->out,"\n"); + } + else + { + args->out_fh = hts_open(args->output_fname? args->output_fname : "-",hts_bcf_wmode(args->output_type)); + if ( args->out_fh == NULL ) error("Can't write to %s: %s\n", args->output_fname? args->output_fname : "standard output", strerror(errno)); + bcf_hdr_append_version(args->hdr,args->argc,args->argv,"bcftools/csq"); + bcf_hdr_printf(args->hdr,"##INFO=",args->bcsq_tag, args->local_csq ? "Local" : "Haplotype-aware"); + if ( args->hdr_nsmpl ) + bcf_hdr_printf(args->hdr,"##FORMAT=",args->bcsq_tag); + bcf_hdr_write(args->out_fh, args->hdr); + } + if ( !args->quiet ) fprintf(stderr,"Calling...\n"); +} + +void destroy_data(args_t *args) +{ + regidx_destroy(args->idx_cds); + regidx_destroy(args->idx_utr); + regidx_destroy(args->idx_exon); + regidx_destroy(args->idx_tscript); + regitr_destroy(args->itr); + + khint_t k,i,j; + for (k=0; kinit.gid2gene); k++) + { + if ( !kh_exist(args->init.gid2gene, k) ) continue; + gf_gene_t *gene = (gf_gene_t*) kh_val(args->init.gid2gene, k); + free(gene->name); + free(gene); + } + kh_destroy(int2gene,args->init.gid2gene); + + if ( args->filter ) + filter_destroy(args->filter); + + khp_destroy(trhp,args->active_tr); + kh_destroy(pos2vbuf,args->pos2vbuf); + if ( args->smpl ) smpl_ilist_destroy(args->smpl); + int ret; + if ( args->out_fh ) + ret = hts_close(args->out_fh); + else + ret = fclose(args->out); + if ( ret ) error("Error: close failed .. %s\n", args->output_fname?args->output_fname:"stdout"); + for (i=0; ivcf_rbuf.m; i++) + { + vbuf_t *vbuf = args->vcf_buf[i]; + if ( !vbuf ) continue; + for (j=0; jm; j++) + { + if ( !vbuf->vrec[j] ) continue; + if ( vbuf->vrec[j]->line ) bcf_destroy(vbuf->vrec[j]->line); + free(vbuf->vrec[j]->smpl); + free(vbuf->vrec[j]->vcsq); + free(vbuf->vrec[j]); + } + free(vbuf->vrec); + free(vbuf); + } + free(args->vcf_buf); + free(args->rm_tr); + free(args->csq_buf); + free(args->hap->stack); + free(args->hap->sseq.s); + free(args->hap->tseq.s); + free(args->hap->tref.s); + free(args->hap); + fai_destroy(args->fai); + free(args->gt_arr); + free(args->str.s); + free(args->str2.s); + gff_id_destroy(&args->tscript_ids); +} + +/* + The splice_* functions are for consquences around splice sites: start,stop,splice_* + */ +#define SPLICE_VAR_REF 0 // ref: ACGT>ACGT, csq not applicable, skip completely +#define SPLICE_OUTSIDE 1 // splice acceptor or similar; csq set and is done, does not overlap the region +#define SPLICE_INSIDE 2 // overlaps coding region; csq can be set but coding prediction is needed +#define SPLICE_OVERLAP 3 // indel overlaps region boundary, csq set but could not determine csq +typedef struct +{ + tscript_t *tr; + struct { + int32_t pos, rlen, alen; + char *ref, *alt; + bcf1_t *rec; + } vcf; + uint16_t check_acceptor:1, // check distance from exon start (fwd) or end (rev) + check_start:1, // this is the first coding exon (relative to transcript orientation), check first (fwd) or last (rev) codon + check_stop:1, // this is the last coding exon (relative to transcript orientation), check last (fwd) or first (rev) codon + check_donor:1, // as with check_acceptor + check_region_beg:1, // do/don't check for splices at this end, eg. in the first or last exon + check_region_end:1, // + check_utr:1, // check splice sites (acceptor/donor/region_*) only if not in utr + set_refalt:1; // set kref,kalt, if set, check also for synonymous events + uint32_t csq; + int tbeg, tend; // number of trimmed bases from beg and end of ref,alt allele + uint32_t ref_beg, // ref coordinates with spurious bases removed, ACC>AC can become AC>A or CC>C, whichever gives + ref_end; // a more conservative csq (the first and last base in kref.s) + kstring_t kref, kalt; // trimmed alleles, set only with SPLICE_OLAP +} +splice_t; +void splice_init(splice_t *splice, bcf1_t *rec) +{ + memset(splice,0,sizeof(*splice)); + splice->vcf.rec = rec; + splice->vcf.pos = rec->pos; + splice->vcf.rlen = rec->rlen; + splice->vcf.ref = rec->d.allele[0]; +} +static inline void splice_build_hap(splice_t *splice, uint32_t beg, int len) +{ + // len>0 .. beg is the first base, del filled from right + // len<0 .. beg is the last base, del filled from left + + int rlen, alen, rbeg, abeg; // first base to include (ref coordinates) + if ( len<0 ) + { + rlen = alen = -len; + rbeg = beg - rlen + 1; + int dlen = splice->vcf.alen - splice->vcf.rlen; + if ( dlen<0 && beg < splice->ref_end ) // incomplete del, beg is in the middle + dlen += splice->ref_end - beg; + abeg = rbeg + dlen; + } + else + { + rbeg = abeg = beg; + rlen = alen = len; + // check for incomplete del as above?? + } + +#define XDBG 0 +#if XDBG +fprintf(stderr,"build_hap: rbeg=%d + %d abeg=%d \n",rbeg,rlen,abeg); +#endif + splice->kref.l = 0; + splice->kalt.l = 0; + + // add the part before vcf.ref, in the vcf.ref and after vcf.ref + int roff; // how many vcf.ref bases already used + if ( rbeg < splice->vcf.pos ) + { + assert( splice->tr->beg <= rbeg ); // this can be extended thanks to N_REF_PAD + kputsn(splice->tr->ref + N_REF_PAD + rbeg - splice->tr->beg, splice->vcf.pos - rbeg, &splice->kref); + roff = 0; + } + else + roff = rbeg - splice->vcf.pos; +#if XDBG +fprintf(stderr,"r1: %s roff=%d\n",splice->kref.s,roff); +#endif + + if ( roff < splice->vcf.rlen && splice->kref.l < rlen ) + { + int len = splice->vcf.rlen - roff; // len still available in vcf.ref + if ( len > rlen - splice->kref.l ) len = rlen - splice->kref.l; // how much of ref allele is still needed + kputsn(splice->vcf.ref + roff, len, &splice->kref); + } +#if XDBG +fprintf(stderr,"r2: %s\n",splice->kref.s); +#endif + + uint32_t end = splice->vcf.pos + splice->vcf.rlen; // position just after the ref allele + if ( splice->kref.l < rlen ) + { + if ( end + rlen - splice->kref.l - 1 > splice->tr->end ) // trim, the requested sequence is too long (could be extended, see N_REF_PAD) + rlen -= end + rlen - splice->kref.l - 1 - splice->tr->end; + if ( splice->kref.l < rlen ) + kputsn(splice->tr->ref + N_REF_PAD + end - splice->tr->beg, rlen - splice->kref.l, &splice->kref); + } +#if XDBG +fprintf(stderr,"r3: %s\n",splice->kref.s); +#endif + + + int aoff; + if ( abeg < splice->vcf.pos ) + { + assert( splice->tr->beg <= abeg ); + kputsn(splice->tr->ref + N_REF_PAD + abeg - splice->tr->beg, splice->vcf.pos - abeg, &splice->kalt); + aoff = 0; + } + else + aoff = abeg - splice->vcf.pos; +#if XDBG +fprintf(stderr,"a1: %s aoff=%d\n",splice->kalt.s,aoff); +#endif + + if ( aoff < splice->vcf.alen && splice->kalt.l < alen ) + { + int len = splice->vcf.alen - aoff; // len still available in vcf.alt + if ( len > alen - splice->kalt.l ) len = alen - splice->kalt.l; // how much of alt allele is still needed + kputsn(splice->vcf.alt + aoff, len, &splice->kalt); + aoff -= len; + } + if ( aoff < 0 ) aoff = 0; + else aoff--; +#if XDBG +fprintf(stderr,"a2: %s aoff=%d\n",splice->kalt.s,aoff); +#endif + + end = splice->vcf.pos + splice->vcf.rlen; // position just after the ref allele + if ( splice->kalt.l < alen ) + { + if ( end + alen + aoff - splice->kalt.l - 1 > splice->tr->end ) // trim, the requested sequence is too long + alen -= end + alen + aoff - splice->kalt.l - 1 - splice->tr->end; + if ( alen > 0 && alen > splice->kalt.l ) + kputsn(splice->tr->ref + aoff + N_REF_PAD + end - splice->tr->beg, alen - splice->kalt.l, &splice->kalt); + } +#if XDBG +fprintf(stderr,"a3: %s\n",splice->kalt.s); +fprintf(stderr," [%s]\n [%s]\n\n",splice->kref.s,splice->kalt.s); +#endif +} +void csq_stage(args_t *args, csq_t *csq, bcf1_t *rec); +static inline int csq_stage_utr(args_t *args, regitr_t *itr, bcf1_t *rec, uint32_t trid) +{ + while ( regitr_overlap(itr) ) + { + gf_utr_t *utr = regitr_payload(itr, gf_utr_t*); + tscript_t *tr = utr->tr; + if ( tr->id != trid ) continue; + csq_t csq; + memset(&csq, 0, sizeof(csq_t)); + csq.pos = rec->pos; + csq.type.type = utr->which==prime5 ? CSQ_UTR5 : CSQ_UTR3; + csq.type.biotype = tr->type; + csq.type.strand = tr->strand; + csq.type.trid = tr->id; + csq.type.gene = tr->gene->name; + csq_stage(args, &csq, rec); + return csq.type.type; + } + return 0; +} +static inline void csq_stage_splice(args_t *args, bcf1_t *rec, tscript_t *tr, uint32_t type) +{ +#if XDBG +fprintf(stderr,"csq_stage_splice %d: type=%d\n",rec->pos+1,type); +#endif + if ( !type ) return; + csq_t csq; + memset(&csq, 0, sizeof(csq_t)); + csq.pos = rec->pos; + csq.type.type = type; + csq.type.biotype = tr->type; + csq.type.strand = tr->strand; + csq.type.trid = tr->id; + csq.type.gene = tr->gene->name; + csq_stage(args, &csq, rec); +} +static inline int splice_csq_ins(args_t *args, splice_t *splice, uint32_t ex_beg, uint32_t ex_end) +{ + // coordinates that matter for consequences, eg AC>ACG trimmed to C>CG, 1bp + // before and after the inserted bases + if ( splice->tbeg || splice->vcf.ref[0]!=splice->vcf.alt[0] ) + { + splice->ref_beg = splice->vcf.pos + splice->tbeg - 1; + splice->ref_end = splice->vcf.pos + splice->vcf.rlen - splice->tend; + } + else + { + if ( splice->tend ) splice->tend--; + splice->ref_beg = splice->vcf.pos; + splice->ref_end = splice->vcf.pos + splice->vcf.rlen - splice->tend; + } +#if XDBG +fprintf(stderr,"ins: %s>%s .. ex=%d,%d beg,end=%d,%d tbeg,tend=%d,%d check_utr=%d start,stop,beg,end=%d,%d,%d,%d\n", splice->vcf.ref,splice->vcf.alt,ex_beg,ex_end,splice->ref_beg,splice->ref_end,splice->tbeg,splice->tend,splice->check_utr,splice->check_start,splice->check_stop,splice->check_region_beg,splice->check_region_end); +#endif + + int ret; + if ( splice->ref_beg >= ex_end ) // fully outside, beyond the exon + { + if ( splice->check_utr ) + { + regitr_t *itr = regitr_init(NULL); + const char *chr = bcf_seqname(args->hdr,splice->vcf.rec); + if ( regidx_overlap(args->idx_utr,chr,splice->ref_beg+1,splice->ref_beg+1, itr) ) // adjacent utr + { + ret = csq_stage_utr(args, itr, splice->vcf.rec, splice->tr->id); + if ( ret!=0 ) + { + regitr_destroy(itr); + return SPLICE_OUTSIDE; // overlaps utr + } + } + regitr_destroy(itr); + } + if ( !splice->check_region_end ) return SPLICE_OUTSIDE; + char *ref = NULL, *alt = NULL; + if ( splice->set_refalt ) // seq identity is checked only when tr->ref is available + { + splice_build_hap(splice, ex_end+1, N_SPLICE_REGION_INTRON); + ref = splice->kref.s, alt = splice->kalt.s; + } + if ( splice->ref_beg < ex_end + N_SPLICE_REGION_INTRON && splice->ref_end > ex_end + N_SPLICE_DONOR ) + { + splice->csq |= CSQ_SPLICE_REGION; + if ( ref && !strncmp(ref,alt,N_SPLICE_REGION_INTRON) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + if ( splice->ref_beg < ex_end + N_SPLICE_DONOR ) + { + if ( splice->check_donor && splice->tr->strand==STRAND_FWD ) splice->csq |= CSQ_SPLICE_DONOR; + if ( splice->check_acceptor && splice->tr->strand==STRAND_REV ) splice->csq |= CSQ_SPLICE_ACCEPTOR; + if ( ref && !strncmp(ref,alt,N_SPLICE_DONOR) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_OUTSIDE; + } + if ( splice->ref_end < ex_beg || (splice->ref_end == ex_beg && !splice->check_region_beg) ) // fully outside, before the exon + { + if ( splice->check_utr ) + { + regitr_t *itr = regitr_init(NULL); + const char *chr = bcf_seqname(args->hdr,splice->vcf.rec); + if ( regidx_overlap(args->idx_utr,chr,splice->ref_end-1,splice->ref_end-1, itr) ) // adjacent utr + { + ret = csq_stage_utr(args, itr, splice->vcf.rec, splice->tr->id); + if ( ret!=0 ) + { + regitr_destroy(itr); + return SPLICE_OUTSIDE; // overlaps utr + } + } + regitr_destroy(itr); + } + if ( !splice->check_region_beg ) return SPLICE_OUTSIDE; + char *ref = NULL, *alt = NULL; + if ( splice->set_refalt ) // seq identity is checked only when tr->ref is available + { + splice_build_hap(splice, ex_beg - N_SPLICE_REGION_INTRON, N_SPLICE_REGION_INTRON); + ref = splice->kref.s, alt = splice->kalt.s; + } + if ( splice->ref_end > ex_beg - N_SPLICE_REGION_INTRON && splice->ref_beg < ex_beg - N_SPLICE_DONOR ) + { + splice->csq |= CSQ_SPLICE_REGION; + if ( ref && !strncmp(ref,alt,N_SPLICE_REGION_INTRON) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + if ( splice->ref_end > ex_beg - N_SPLICE_DONOR ) + { + if ( splice->check_donor && splice->tr->strand==STRAND_REV ) splice->csq |= CSQ_SPLICE_DONOR; + if ( splice->check_acceptor && splice->tr->strand==STRAND_FWD ) splice->csq |= CSQ_SPLICE_ACCEPTOR; + if ( ref && !strncmp(ref+N_SPLICE_REGION_INTRON-N_SPLICE_DONOR,alt+N_SPLICE_REGION_INTRON-N_SPLICE_DONOR,N_SPLICE_DONOR) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_OUTSIDE; + } + // overlaps the exon or inside the exon + // possible todo: find better alignment for frameshifting variants? + if ( splice->ref_beg <= ex_beg + 2 ) // in the first 3bp + { + if ( splice->check_region_beg ) splice->csq |= CSQ_SPLICE_REGION; + if ( splice->tr->strand==STRAND_FWD ) { if ( splice->check_start ) splice->csq |= CSQ_START_LOST; } + else { if ( splice->check_stop ) splice->csq |= CSQ_STOP_LOST; } + } + if ( splice->ref_end > ex_end - 2 ) + { + if ( splice->check_region_end ) splice->csq |= CSQ_SPLICE_REGION; + if ( splice->tr->strand==STRAND_REV ) { if ( splice->check_start ) splice->csq |= CSQ_START_LOST; } + else { if ( splice->check_stop ) splice->csq |= CSQ_STOP_LOST; } + } + if ( splice->set_refalt ) + { + // Make sure the variant will not end up left aligned to avoid overlapping vcf records + // splice_build_hap(splice, splice->ref_beg, splice->vcf.alen - splice->tend - splice->tbeg + 1); + // splice->vcf.rlen -= splice->tbeg + splice->tend - 1; + // if ( splice->kref.l > splice->vcf.rlen ) { splice->kref.l = splice->vcf.rlen; splice->kref.s[splice->kref.l] = 0; } + if ( splice->ref_beg < splice->vcf.pos ) // this must have been caused by too much trimming from right + { + int dlen = splice->vcf.pos - splice->ref_beg; + assert( dlen==1 ); + splice->tbeg += dlen; + if ( splice->tbeg + splice->tend == splice->vcf.rlen ) splice->tend -= dlen; + splice->ref_beg = splice->vcf.pos; + } + if ( splice->ref_end==ex_beg ) splice->tend--; // prevent zero-length ref allele + splice_build_hap(splice, splice->ref_beg, splice->vcf.alen - splice->tend - splice->tbeg + 1); + splice->vcf.rlen -= splice->tbeg + splice->tend - 1; + if ( splice->kref.l > splice->vcf.rlen ) { splice->kref.l = splice->vcf.rlen; splice->kref.s[splice->kref.l] = 0; } + } + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_INSIDE; +} + +static inline int splice_csq_del(args_t *args, splice_t *splice, uint32_t ex_beg, uint32_t ex_end) +{ + // coordinates that matter for consequences, eg AC>ACG trimmed to C>CG + splice->ref_beg = splice->vcf.pos + splice->tbeg - 1; // 1b before the deleted base + splice->ref_end = splice->vcf.pos + splice->vcf.rlen - splice->tend - 1; // the last deleted base + +#if XDBG +fprintf(stderr,"del: %s>%s .. ex=%d,%d beg,end=%d,%d tbeg,tend=%d,%d check_utr=%d start,stop,beg,end=%d,%d,%d,%d\n", splice->vcf.ref,splice->vcf.alt,ex_beg,ex_end,splice->ref_beg,splice->ref_end,splice->tbeg,splice->tend,splice->check_utr,splice->check_start,splice->check_stop,splice->check_region_beg,splice->check_region_end); +#endif + + if ( splice->ref_beg + 1 < ex_beg ) // the part before the exon; ref_beg is off by -1 + { + if ( splice->check_region_beg ) + { + int csq = 0; + if ( splice->check_utr ) + { + regitr_t *itr = regitr_init(NULL); + const char *chr = bcf_seqname(args->hdr,splice->vcf.rec); + if ( regidx_overlap(args->idx_utr,chr,splice->ref_beg,ex_beg-1, itr) ) // adjacent utr + csq = csq_stage_utr(args, itr, splice->vcf.rec, splice->tr->id); + regitr_destroy(itr); + } + if ( !csq ) + { + char *ref = NULL, *alt = NULL; + if ( splice->set_refalt ) // seq identity is checked only when tr->ref is available + { + // filling from the left does not work for ENST00000341065/frame3.vcf + // CAG.GTGGCCAG CAG.GTGGCCAG + // CA-.--GGCCAG vs CAG.---GCCAG + // splice_build_hap(splice, ex_beg-1, -N_SPLICE_REGION_INTRON); + // + // filling from the right: + splice_build_hap(splice, ex_beg - N_SPLICE_REGION_INTRON, N_SPLICE_REGION_INTRON); + ref = splice->kref.s, alt = splice->kalt.s; + } + if ( splice->ref_end >= ex_beg - N_SPLICE_REGION_INTRON && splice->ref_beg < ex_beg - N_SPLICE_DONOR ) + { + splice->csq |= CSQ_SPLICE_REGION; + if ( ref && alt && !strncmp(ref,alt,N_SPLICE_REGION_INTRON) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + if ( splice->ref_end >= ex_beg - N_SPLICE_DONOR ) + { + if ( splice->check_donor && splice->tr->strand==STRAND_REV ) splice->csq |= CSQ_SPLICE_DONOR; + if ( splice->check_acceptor && splice->tr->strand==STRAND_FWD ) splice->csq |= CSQ_SPLICE_ACCEPTOR; + if ( ref && alt && !strncmp(ref+N_SPLICE_REGION_INTRON-N_SPLICE_DONOR,alt+N_SPLICE_REGION_INTRON-N_SPLICE_DONOR,N_SPLICE_DONOR) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + } + } + if ( splice->ref_end >= ex_beg ) + { + splice->tbeg = splice->ref_beg - splice->vcf.pos + 1; + splice->ref_beg = ex_beg - 1; + if ( splice->tbeg + splice->tend == splice->vcf.alen ) + { + // the deletion overlaps ex_beg and cannot be easily realigned to the right + if ( !splice->tend ) + { + splice->csq |= CSQ_CODING_SEQUENCE; + return SPLICE_OVERLAP; + } + splice->tend--; + } + } + } + if ( ex_end < splice->ref_end ) // the part after the exon + { + if ( splice->check_region_end ) + { + int csq = 0; + if ( splice->check_utr ) + { + regitr_t *itr = regitr_init(NULL); + const char *chr = bcf_seqname(args->hdr,splice->vcf.rec); + if ( regidx_overlap(args->idx_utr,chr,ex_end+1,splice->ref_end, itr) ) // adjacent utr + csq = csq_stage_utr(args, itr, splice->vcf.rec, splice->tr->id); + regitr_destroy(itr); + } + if ( !csq ) + { + char *ref = NULL, *alt = NULL; + if ( splice->set_refalt ) // seq identity is checked only when tr->ref is available + { + splice_build_hap(splice, ex_end+1, N_SPLICE_REGION_INTRON); // ref,alt positioned at the first intron base + ref = splice->kref.s, alt = splice->kalt.s; + } + if ( splice->ref_beg < ex_end + N_SPLICE_REGION_INTRON && splice->ref_end > ex_end + N_SPLICE_DONOR ) + { + splice->csq |= CSQ_SPLICE_REGION; + if ( ref && alt && !strncmp(ref,alt,N_SPLICE_REGION_INTRON) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + if ( splice->ref_beg < ex_end + N_SPLICE_DONOR ) + { + if ( splice->check_donor && splice->tr->strand==STRAND_FWD ) splice->csq |= CSQ_SPLICE_DONOR; + if ( splice->check_acceptor && splice->tr->strand==STRAND_REV ) splice->csq |= CSQ_SPLICE_ACCEPTOR; + if ( ref && alt && !strncmp(ref+N_SPLICE_REGION_INTRON-N_SPLICE_DONOR,alt+N_SPLICE_REGION_INTRON-N_SPLICE_DONOR,N_SPLICE_DONOR) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + } + } + if ( splice->ref_beg < ex_end ) + { + splice->tend = splice->vcf.rlen - (splice->ref_end - splice->vcf.pos + 1); + splice->ref_end = ex_end; + } + } + if ( splice->ref_end < ex_beg || splice->ref_beg >= ex_end ) + { + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_OUTSIDE; + } + + if ( splice->ref_beg < ex_beg + 2 ) // ref_beg is off by -1 + { + if ( splice->check_region_beg ) splice->csq |= CSQ_SPLICE_REGION; + if ( splice->tr->strand==STRAND_FWD ) { if ( splice->check_start ) splice->csq |= CSQ_START_LOST; } + else { if ( splice->check_stop ) splice->csq |= CSQ_STOP_LOST; } + } + if ( splice->ref_end > ex_end - 3 ) + { + if ( splice->check_region_end ) splice->csq |= CSQ_SPLICE_REGION; + if ( splice->tr->strand==STRAND_REV ) { if ( splice->check_start ) splice->csq |= CSQ_START_LOST; } + else { if ( splice->check_stop ) splice->csq |= CSQ_STOP_LOST; } + } + if ( splice->set_refalt ) + { + if ( splice->tbeg>0 ) splice->tbeg--; //why is this? + if ( splice->vcf.rlen > splice->tbeg + splice->tend && splice->vcf.alen > splice->tbeg + splice->tend ) + { + splice->vcf.rlen -= splice->tbeg + splice->tend; + splice->vcf.alen -= splice->tbeg + splice->tend; + } + splice->kref.l = 0; kputsn(splice->vcf.ref + splice->tbeg, splice->vcf.rlen, &splice->kref); + splice->kalt.l = 0; kputsn(splice->vcf.alt + splice->tbeg, splice->vcf.alen, &splice->kalt); + if ( (splice->ref_beg+1 < ex_beg && splice->ref_end >= ex_beg) || (splice->ref_beg+1 < ex_end && splice->ref_end >= ex_end) ) // ouch, ugly ENST00000409523/long-overlapping-del.vcf + { + splice->csq |= (splice->ref_end - splice->ref_beg + 1)%3 ? CSQ_FRAMESHIFT_VARIANT : CSQ_INFRAME_DELETION; + return SPLICE_OVERLAP; + } + } + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_INSIDE; +} + +static inline int splice_csq_mnp(args_t *args, splice_t *splice, uint32_t ex_beg, uint32_t ex_end) +{ + // not a real variant, can be ignored: eg ACGT>ACGT + if ( splice->tbeg + splice->tend == splice->vcf.rlen ) return SPLICE_VAR_REF; + + splice->ref_beg = splice->vcf.pos + splice->tbeg; + splice->ref_end = splice->vcf.pos + splice->vcf.rlen - splice->tend - 1; + +#if XDBG +fprintf(stderr,"mnp: %s>%s .. ex=%d,%d beg,end=%d,%d tbeg,tend=%d,%d check_utr=%d start,stop,beg,end=%d,%d,%d,%d\n", splice->vcf.ref,splice->vcf.alt,ex_beg,ex_end,splice->ref_beg,splice->ref_end,splice->tbeg,splice->tend,splice->check_utr,splice->check_start,splice->check_stop,splice->check_region_beg,splice->check_region_end); +#endif + + if ( splice->ref_beg < ex_beg ) // the part before the exon + { + if ( splice->check_region_beg ) + { + int csq = 0; + if ( splice->check_utr ) + { + regitr_t *itr = regitr_init(NULL); + const char *chr = bcf_seqname(args->hdr,splice->vcf.rec); + if ( regidx_overlap(args->idx_utr,chr,splice->ref_beg,ex_beg-1, itr) ) // adjacent utr + csq = csq_stage_utr(args, itr, splice->vcf.rec, splice->tr->id); + regitr_destroy(itr); + } + if ( !csq ) + { + if ( splice->ref_end >= ex_beg - N_SPLICE_REGION_INTRON && splice->ref_beg < ex_beg - N_SPLICE_DONOR ) + splice->csq |= CSQ_SPLICE_REGION; + if ( splice->ref_end >= ex_beg - N_SPLICE_DONOR ) + { + if ( splice->check_donor && splice->tr->strand==STRAND_REV ) splice->csq |= CSQ_SPLICE_DONOR; + if ( splice->check_acceptor && splice->tr->strand==STRAND_FWD ) splice->csq |= CSQ_SPLICE_ACCEPTOR; + } + } + } + if ( splice->ref_end >= ex_beg ) + { + splice->tbeg = splice->ref_beg - splice->vcf.pos; + splice->ref_beg = ex_beg; + } + } + if ( ex_end < splice->ref_end ) // the part after the exon + { + if ( splice->check_region_end ) + { + int csq = 0; + if ( splice->check_utr ) + { + regitr_t *itr = regitr_init(NULL); + const char *chr = bcf_seqname(args->hdr,splice->vcf.rec); + if ( regidx_overlap(args->idx_utr,chr,ex_end+1,splice->ref_end, itr) ) // adjacent utr + csq = csq_stage_utr(args, itr, splice->vcf.rec, splice->tr->id); + regitr_destroy(itr); + } + if ( !csq ) + { + if ( splice->ref_beg <= ex_end + N_SPLICE_REGION_INTRON && splice->ref_end > ex_end + N_SPLICE_DONOR ) + splice->csq |= CSQ_SPLICE_REGION; + if ( splice->ref_beg <= ex_end + N_SPLICE_DONOR ) + { + if ( splice->check_donor && splice->tr->strand==STRAND_FWD ) splice->csq |= CSQ_SPLICE_DONOR; + if ( splice->check_acceptor && splice->tr->strand==STRAND_REV ) splice->csq |= CSQ_SPLICE_ACCEPTOR; + } + } + } + if ( splice->ref_beg <= ex_end ) + { + splice->tend = splice->vcf.rlen - (splice->ref_end - splice->vcf.pos + 1); + splice->ref_end = ex_end; + } + } + if ( splice->ref_end < ex_beg || splice->ref_beg > ex_end ) + { + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_OUTSIDE; + } + + if ( splice->ref_beg < ex_beg + 3 ) + { + if ( splice->check_region_beg ) splice->csq |= CSQ_SPLICE_REGION; + if ( splice->tr->strand==STRAND_FWD ) { if ( splice->check_start ) splice->csq |= CSQ_START_LOST; } + else { if ( splice->check_stop ) splice->csq |= CSQ_STOP_LOST; } + } + if ( splice->ref_end > ex_end - 3 ) + { + if ( splice->check_region_end ) splice->csq |= CSQ_SPLICE_REGION; + if ( splice->tr->strand==STRAND_REV ) { if ( splice->check_start ) splice->csq |= CSQ_START_LOST; } + else { if ( splice->check_stop ) splice->csq |= CSQ_STOP_LOST; } + } + if ( splice->set_refalt ) + { + splice->vcf.rlen -= splice->tbeg + splice->tend; + splice->kref.l = 0; kputsn(splice->vcf.ref + splice->tbeg, splice->vcf.rlen, &splice->kref); + splice->kalt.l = 0; kputsn(splice->vcf.alt + splice->tbeg, splice->vcf.rlen, &splice->kalt); + } + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_INSIDE; +} +static inline int splice_csq(args_t *args, splice_t *splice, uint32_t ex_beg, uint32_t ex_end) +{ + splice->csq = 0; + splice->vcf.alen = strlen(splice->vcf.alt); + + int rlen1 = splice->vcf.rlen - 1, alen1 = splice->vcf.alen - 1, i = 0; + splice->tbeg = 0, splice->tend = 0; + + // trim from the right, then from the left + while ( i<=rlen1 && i<=alen1 ) + { + if ( splice->vcf.ref[rlen1-i] != splice->vcf.alt[alen1-i] ) break; + i++; + } + splice->tend = i; + rlen1 -= i, alen1 -= i, i = 0; + while ( i<=rlen1 && i<=alen1 ) + { + if ( splice->vcf.ref[i] != splice->vcf.alt[i] ) break; + i++; + } + splice->tbeg = i; + + // The mnp, ins and del code was split into near-identical functions for clarity and debugging; + // possible todo: generalize once stable + if ( splice->vcf.rlen==splice->vcf.alen ) return splice_csq_mnp(args, splice, ex_beg, ex_end); + if ( splice->vcf.rlen < splice->vcf.alen ) return splice_csq_ins(args, splice, ex_beg, ex_end); + if ( splice->vcf.rlen > splice->vcf.alen ) return splice_csq_del(args, splice, ex_beg, ex_end); + + return 0; +} + +// return value: 0 added, 1 overlapping variant, 2 silent discard (intronic,alt=ref) +int hap_init(args_t *args, hap_node_t *parent, hap_node_t *child, gf_cds_t *cds, bcf1_t *rec, int ial) +{ + int i; + kstring_t str = {0,0,0}; + tscript_t *tr = cds->tr; + child->icds = cds->icds; // index of cds in the tscript's list of exons + + splice_t splice; + splice_init(&splice, rec); + splice.tr = tr; + splice.vcf.alt = rec->d.allele[ial]; + splice.check_acceptor = splice.check_donor = splice.set_refalt = splice.check_utr = 1; + if ( !(tr->trim & TRIM_5PRIME) ) + { + if ( tr->strand==STRAND_FWD ) { if ( child->icds==0 ) splice.check_start = 1; } + else { if ( child->icds==tr->ncds-1 ) splice.check_start = 1; } + } + if ( !(tr->trim & TRIM_3PRIME) ) + { + if ( tr->strand==STRAND_FWD ) { if ( child->icds==tr->ncds-1 ) splice.check_stop = 1; } + else { if ( child->icds==0 ) splice.check_stop = 1; } + } + if ( splice.check_start ) // do not check starts in incomplete CDS, defined as not starting with M + { + if ( tr->strand==STRAND_FWD ) { if ( dna2aa(tr->ref+N_REF_PAD+cds->beg-tr->beg) != 'M' ) splice.check_start = 0; } + else { if ( cdna2aa(tr->ref+N_REF_PAD+cds->beg-tr->beg+cds->len-3) != 'M' ) splice.check_start = 0; } + } + if ( child->icds!=0 ) splice.check_region_beg = 1; + if ( child->icds!=tr->ncds-1 ) splice.check_region_end = 1; + +#if XDBG +fprintf(stderr,"\n%d [%s][%s] check start:%d,stop:%d\n",splice.vcf.pos+1,splice.vcf.ref,splice.vcf.alt,splice.check_start,splice.check_stop); +#endif + int ret = splice_csq(args, &splice, cds->beg, cds->beg + cds->len - 1); +#if XDBG +fprintf(stderr,"cds splice_csq: %d [%s][%s] .. beg,end=%d %d, ret=%d, csq=%d\n\n",splice.vcf.pos+1,splice.kref.s,splice.kalt.s,splice.ref_beg+1,splice.ref_end+1,ret,splice.csq); +#endif + + if ( ret==SPLICE_VAR_REF ) return 2; // not a variant, eg REF=CA ALT=CA + if ( ret==SPLICE_OUTSIDE || ret==SPLICE_OVERLAP ) // not a coding csq + { + free(splice.kref.s); + free(splice.kalt.s); + + if ( !splice.csq ) return 2; // fully intronic, no csq + + // splice_region/acceptor/donor + child->seq = NULL; + child->sbeg = 0; + child->rbeg = rec->pos; + child->rlen = 0; + child->dlen = 0; + kputs(rec->d.allele[0],&str); + kputc('>',&str); + kputs(rec->d.allele[ial],&str); + child->var = str.s; + child->type = HAP_SSS; + child->csq = splice.csq; + child->prev = parent->type==HAP_SSS ? parent->prev : parent; + child->rec = rec; + return 0; + } + if ( splice.csq & CSQ_SYNONYMOUS_VARIANT ) splice.csq &= ~CSQ_SYNONYMOUS_VARIANT; // synonymous&splice,frame could become synonymous&frame,splice + + int dbeg = 0; + if ( splice.ref_beg < cds->beg ) + { + // The vcf record overlaps the exon boundary, but the variant itself + // should fit inside since we are here. This will need more work. + // #1475227917 + dbeg = cds->beg - splice.ref_beg; + splice.kref.l -= dbeg; + splice.ref_beg = cds->beg; + assert( dbeg <= splice.kalt.l ); + } + + if ( parent->type==HAP_SSS ) parent = parent->prev; + if ( parent->type==HAP_CDS ) + { + i = parent->icds; + if ( i!=cds->icds ) + { + // the variant is on a new exon, finish up the previous + int len = tr->cds[i]->len - parent->rbeg - parent->rlen + tr->cds[i]->beg; + if ( len > 0 ) + kputsn_(tr->ref + N_REF_PAD + parent->rbeg + parent->rlen - tr->beg, len, &str); + } + + // append any skipped non-variant exons + while ( ++i < cds->icds ) + kputsn_(tr->ref + N_REF_PAD + tr->cds[i]->beg - tr->beg, tr->cds[i]->len, &str); + + if ( parent->icds==child->icds ) + { + int len = splice.ref_beg - parent->rbeg - parent->rlen; + if ( len < 0 ) // overlapping variants + { + free(str.s); + return 1; + } + kputsn_(tr->ref + N_REF_PAD + parent->rbeg + parent->rlen - tr->beg, len, &str); + } + else + kputsn_(tr->ref + N_REF_PAD + cds->beg - tr->beg, splice.ref_beg - cds->beg, &str); + } + kputs(splice.kalt.s + dbeg, &str); + + child->seq = str.s; + child->sbeg = cds->pos + (splice.ref_beg - cds->beg); + child->rbeg = splice.ref_beg; + child->rlen = splice.kref.l; + child->type = HAP_CDS; + child->prev = parent; + child->rec = rec; + child->csq = splice.csq; + + // set vlen and the "ref>alt" string + { + int rlen = strlen(rec->d.allele[0]); + int alen = strlen(rec->d.allele[ial]); + child->dlen = alen - rlen; + child->var = (char*) malloc(rlen+alen+2); + memcpy(child->var,rec->d.allele[0],rlen); + child->var[rlen] = '>'; + memcpy(child->var+rlen+1,rec->d.allele[ial],alen); + child->var[rlen+alen+1] = 0; + } + + // yuck, the whole CDS is modified/deleted, not ready for this, todo. + if ( child->rbeg + child->rlen > cds->beg + cds->len ) + { + child->type = HAP_SSS; + if ( !child->csq ) child->csq |= CSQ_CODING_SEQUENCE; // hack, specifically for ENST00000390520/deletion-overlap.vcf + } + + free(splice.kref.s); + free(splice.kalt.s); + return 0; +} +void hap_destroy(hap_node_t *hap) +{ + int i; + for (i=0; inchild; i++) + if ( hap->child[i] ) hap_destroy(hap->child[i]); + for (i=0; imcsq_list; i++) free(hap->csq_list[i].type.vstr.s); + free(hap->csq_list); + free(hap->child); + free(hap->cur_child); + free(hap->seq); + free(hap->var); + free(hap); +} + + +/* + ref: spliced reference and its length (ref.l) + seq: part of the spliced query transcript on the reference strand to translate, its + length (seq.l) and the total length of the complete transcript (seq.m) + sbeg: seq offset within the spliced query transcript + rbeg: seq offset within ref, 0-based + rend: last base of seq within ref, plus one. If seq does not contain indels, it is rend=rbeg+seq->l + strand: coding strand - 0:rev, 1:fwd + tseq: translated sequence (aa) + fill: frameshift, fill until the end (strand=fwd) or from the start (strand=rev) + */ +void cds_translate(kstring_t *_ref, kstring_t *_seq, uint32_t sbeg, uint32_t rbeg, uint32_t rend, int strand, kstring_t *tseq, int fill) +{ +#if XDBG +fprintf(stderr,"translate: %d %d %d fill=%d seq.l=%d\n",sbeg,rbeg,rend,fill,(int)_seq->l); +#endif + char tmp[3], *codon, *end; + int i, len, npad; + + kstring_t ref = *_ref; + kstring_t seq = *_seq; + + tseq->l = 0; + if ( !seq.l ) + { + kputc('?', tseq); + return; + } + +#define DBG 0 +#if DBG + fprintf(stderr,"translate: sbeg,rbeg,rend=%d %d %d fill=%d seq.l=%d\n",sbeg,rbeg,rend,fill,(int)_seq->l); + fprintf(stderr," ref: l=%d %s\n", (int)ref.l,ref.s); + fprintf(stderr," seq: l=%d m=%d ", (int)seq.l,(int)seq.m); + for (i=0; i1 + fprintf(stderr," npad: %d\n",npad); +#endif + assert( npad<=rbeg ); + + for (i=0; i1 + fprintf(stderr,"\t i=%d\n", i); +#endif + if ( i==3 ) + { + kputc_(dna2aa(tmp), tseq); +#if DBG>1 + fprintf(stderr,"[1]%c%c%c\n",tmp[0],tmp[1],tmp[2]); +#endif + codon = seq.s + 3 - npad; // next codon + end = codon + len - 1 - (len % 3); // last position of a valid codon + while ( codon < end ) + { + kputc_(dna2aa(codon), tseq); +#if DBG>1 + fprintf(stderr,"[2]%c%c%c\n",codon[0],codon[1],codon[2]); +#endif + codon += 3; + } + end = seq.s + seq.l - 1; + for (i=0; codon+i<=end; i++) tmp[i] = codon[i]; + } + + // right padding + codon = ref.s + rend + N_REF_PAD; + if ( i>0 ) + { +#if DBG>1 + if(i==1)fprintf(stderr,"[3]%c\n",tmp[0]); + if(i==2)fprintf(stderr,"[3]%c%c\n",tmp[0],tmp[1]); +#endif + for (; i<3; i++) + { + tmp[i] = *codon; + codon++; + } + kputc_(dna2aa(tmp), tseq); +#if DBG>1 + fprintf(stderr,"[4]%c%c%c\n",tmp[0],tmp[1],tmp[2]); +#endif + } + if ( fill!=0 ) + { + end = ref.s + ref.l - N_REF_PAD; + while ( codon+3 <= end ) + { + kputc_(dna2aa(codon), tseq); +#if DBG>1 + fprintf(stderr,"[5]%c%c%c\t%c\n",codon[0],codon[1],codon[2],dna2aa(codon)); +#endif + codon += 3; + } + } + } + else // STRAND_REV + { + // right padding - number of bases to take from ref + npad = (seq.m - (sbeg + seq.l)) % 3; +#if DBG>1 + fprintf(stderr," npad: %d\n",npad); +#endif +if ( !(npad>=0 && sbeg+seq.l+npad<=seq.m) ) fprintf(stderr,"sbeg=%d seq.l=%d seq.m=%d\n",sbeg,(int)seq.l,(int)seq.m); + assert( npad>=0 && sbeg+seq.l+npad<=seq.m ); // todo: first codon on the rev strand + + if ( npad==2 ) + { + tmp[1] = ref.s[rend+N_REF_PAD]; + tmp[2] = ref.s[rend+N_REF_PAD+1]; + i = 0; + } + else if ( npad==1 ) + { + tmp[2] = ref.s[rend+N_REF_PAD]; + i = 1; + } + else + i = 2; + + end = seq.s + seq.l; + for (; i>=0 && end>seq.s; i--) tmp[i] = *(--end); +#if DBG>1 + fprintf(stderr,"\t i=%d\n", i); + if(i==1)fprintf(stderr,"[0] %c\n",tmp[2]); + if(i==0)fprintf(stderr,"[0] %c%c\n",tmp[1],tmp[2]); +#endif + if ( i==-1 ) + { +#if DBG>1 + fprintf(stderr,"[1]%c%c%c\t%c\n",tmp[0],tmp[1],tmp[2], cdna2aa(tmp)); +#endif + kputc_(cdna2aa(tmp), tseq); + codon = end - 3; + while ( codon >= seq.s ) + { + kputc_(cdna2aa(codon), tseq); +#if DBG>1 + fprintf(stderr,"[2]%c%c%c\t%c\n",codon[0],codon[1],codon[2], cdna2aa(codon)); +#endif + codon -= 3; + } + if ( seq.s-codon==2 ) + { + tmp[2] = seq.s[0]; + i = 1; + } + else if ( seq.s-codon==1 ) + { + tmp[1] = seq.s[0]; + tmp[2] = seq.s[1]; + i = 0; + } + else + i = -1; +#if DBG>1 + if(i==1)fprintf(stderr,"[3] %c\n",tmp[2]); + if(i==0)fprintf(stderr,"[3] %c%c\n",tmp[1],tmp[2]); +#endif + } + // left padding + end = ref.s + N_REF_PAD + rbeg; + if ( i>=0 ) + { + for (; i>=0 && end>=ref.s; i--) tmp[i] = *(--end); + kputc_(cdna2aa(tmp), tseq); +#if DBG>1 + fprintf(stderr,"[4]%c%c%c\t%c\n",tmp[0],tmp[1],tmp[2],cdna2aa(tmp)); +#endif + } + if ( fill!=0 ) + { + codon = end - 3; + while ( codon >= ref.s + N_REF_PAD ) + { + kputc_(cdna2aa(codon), tseq); +#if DBG>1 + fprintf(stderr,"[5]%c%c%c\t%c\n",codon[0],codon[1],codon[2],cdna2aa(codon)); +#endif + codon -= 3; + } + } + } + kputc_(0,tseq); tseq->l--; +#if DBG + fprintf(stderr," tseq: %s\n", tseq->s); +#endif +} + +void tscript_splice_ref(tscript_t *tr) +{ + int i, len = 0; + for (i=0; incds; i++) + len += tr->cds[i]->len; + + tr->nsref = len + 2*N_REF_PAD; + tr->sref = (char*) malloc(len + 1 + 2*N_REF_PAD); + len = 0; + + memcpy(tr->sref, tr->ref + tr->cds[0]->beg - tr->beg, N_REF_PAD); + len += N_REF_PAD; + + for (i=0; incds; i++) + { + memcpy(tr->sref + len, tr->ref + N_REF_PAD + tr->cds[i]->beg - tr->beg, tr->cds[i]->len); + len += tr->cds[i]->len; + } + memcpy(tr->sref + len, tr->ref + N_REF_PAD + tr->cds[tr->ncds-1]->beg - tr->beg, N_REF_PAD); + len += N_REF_PAD; + + tr->sref[len] = 0; +} + +// returns: 0 if consequence was added, 1 if it already exists or could not be added +int csq_push(args_t *args, csq_t *csq, bcf1_t *rec) +{ +#if XDBG +fprintf(stderr,"csq_push: %d .. %d\n",rec->pos+1,csq->type.type); +#endif + khint_t k = kh_get(pos2vbuf, args->pos2vbuf, (int)csq->pos); + vbuf_t *vbuf = (k == kh_end(args->pos2vbuf)) ? NULL : kh_val(args->pos2vbuf, k); + if ( !vbuf ) error("This should not happen. %s:%d %s\n",bcf_seqname(args->hdr,rec),csq->pos+1,csq->type.vstr); + + int i; + for (i=0; in; i++) + if ( vbuf->vrec[i]->line==rec ) break; + if ( i==vbuf->n ) error("This should not happen.. %s:%d %s\n", bcf_seqname(args->hdr,rec),csq->pos+1,csq->type.vstr); + vrec_t *vrec = vbuf->vrec[i]; + + // if the variant overlaps donor/acceptor and also splice region, report only donor/acceptor + if ( csq->type.type & CSQ_SPLICE_REGION && csq->type.type & (CSQ_SPLICE_DONOR|CSQ_SPLICE_ACCEPTOR) ) + csq->type.type &= ~CSQ_SPLICE_REGION; + + if ( csq->type.type & CSQ_PRINTED_UPSTREAM ) + { + for (i=0; invcsq; i++) + { + // Same as below, to avoid records like + // 3630 .. @3632,stop_lost|AL627309.1|ENST00000423372|protein_coding|- + // 3632 .. stop_lost|AL627309.1|ENST00000423372|protein_coding|-|260*>260G|3630T>A+3632A>C + if ( csq->type.type&CSQ_START_STOP && vrec->vcsq[i].type&CSQ_START_STOP ) + { + vrec->vcsq[i] = csq->type; + goto exit_duplicate; + } + if ( !(vrec->vcsq[i].type & CSQ_PRINTED_UPSTREAM) ) continue; + if ( csq->type.ref != vrec->vcsq[i].ref ) continue; + goto exit_duplicate; + } + } + else if ( csq->type.type & CSQ_COMPOUND ) + { + for (i=0; invcsq; i++) + { + if ( csq->type.trid != vrec->vcsq[i].trid && (csq->type.type|vrec->vcsq[i].type)&CSQ_PRN_TSCRIPT ) continue; + if ( csq->type.biotype != vrec->vcsq[i].biotype ) continue; + if ( csq->type.gene != vrec->vcsq[i].gene ) continue; + if ( csq->type.vstr.s || vrec->vcsq[i].vstr.s ) + { + // This is a bit hacky, but we want a simpler and more predictable output. The splice_csq() function + // can trigger stop/start events based on indel overlap, then another stop/start event can be triggered + // from add_csq() or test_cds_local() based on sequence comparison, and on output we could find two + // consequences: + // stop_lost|AL627309.1|ENST00000423372|protein_coding|- + // stop_lost&inframe_insertion|AL627309.1|ENST00000423372|protein_coding|-|260*>260CL|3630T>TAAA + if ( !csq->type.vstr.s || !vrec->vcsq[i].vstr.s ) + { + if ( csq->type.type&CSQ_START_STOP && vrec->vcsq[i].type&CSQ_START_STOP ) + { + vrec->vcsq[i].type |= csq->type.type; + + // remove stop_lost&synonymous if stop_retained set + if ( vrec->vcsq[i].type&CSQ_STOP_RETAINED ) + vrec->vcsq[i].type &= ~(CSQ_STOP_LOST|CSQ_SYNONYMOUS_VARIANT); + + if ( !vrec->vcsq[i].vstr.s ) vrec->vcsq[i].vstr = csq->type.vstr; + goto exit_duplicate; + } + continue; + } + if ( strcmp(csq->type.vstr.s,vrec->vcsq[i].vstr.s) ) continue; + } + vrec->vcsq[i].type |= csq->type.type; + goto exit_duplicate; + } + } + else + { + for (i=0; invcsq; i++) + { + if ( csq->type.trid != vrec->vcsq[i].trid && (csq->type.type|vrec->vcsq[i].type)&CSQ_PRN_TSCRIPT) continue; + if ( csq->type.biotype != vrec->vcsq[i].biotype ) continue; + if ( !(vrec->vcsq[i].type & CSQ_COMPOUND) ) + { + vrec->vcsq[i].type |= csq->type.type; + goto exit_duplicate; + } + if ( vrec->vcsq[i].type==(vrec->vcsq[i].type|csq->type.type) ) goto exit_duplicate; + } + } + // no such csq yet in this vcf record + csq->vrec = vrec; + csq->idx = i; + vrec->nvcsq++; + hts_expand0(vcsq_t, vrec->nvcsq, vrec->mvcsq, vrec->vcsq); + vrec->vcsq[i] = csq->type; + return 0; + +exit_duplicate: + csq->vrec = vrec; + csq->idx = i; + return 1; +} + +// soff .. position of the variant within the trimmed query transcript +// sbeg .. position of the variant within the query transcript +// rbeg .. position on the reference transcript (if there are no indels, then rbeg=send) +// rpos .. VCF position +#define node2soff(i) (hap->stack[i].slen - (hap->stack[i].node->rlen + hap->stack[i].node->dlen)) +#define node2sbeg(i) (hap->sbeg + node2soff(i)) +#define node2send(i) (hap->sbeg + hap->stack[i].slen) +#define node2rbeg(i) (hap->stack[i].node->sbeg) +#define node2rend(i) (hap->stack[i].node->sbeg + hap->stack[i].node->rlen) +#define node2rpos(i) (hap->stack[i].node->rec->pos) + +void kput_vcsq(args_t *args, vcsq_t *csq, kstring_t *str) +{ + // Remove start/stop from incomplete CDS, but only if there is another + // consequence as something must be reported + if ( csq->type & CSQ_INCOMPLETE_CDS && (csq->type & ~(CSQ_START_STOP|CSQ_INCOMPLETE_CDS|CSQ_UPSTREAM_STOP)) ) csq->type &= ~(CSQ_START_STOP|CSQ_INCOMPLETE_CDS); + + // Remove missense from start/stops + if ( csq->type & CSQ_START_STOP && csq->type & CSQ_MISSENSE_VARIANT ) csq->type &= ~CSQ_MISSENSE_VARIANT; + + if ( csq->type & CSQ_PRINTED_UPSTREAM && csq->ref ) + { + kputc_('@',str); + kputw(csq->ref->pos+1, str); + return; + } + if ( csq->type & CSQ_UPSTREAM_STOP ) + kputc_('*',str); + + int i, n = sizeof(csq_strings)/sizeof(char*); + for (i=1; itype&(1<type&(1<gene ) kputs(csq->gene , str); + + kputc_('|', str); + if ( csq->type & CSQ_PRN_TSCRIPT ) kputs(args->tscript_ids.str[csq->trid], str); + + kputc_('|', str); + kputs(gf_type2gff_string(csq->biotype), str); + + if ( CSQ_PRN_STRAND(csq->type) || csq->vstr.l ) + kputs(csq->strand==STRAND_FWD ? "|+" : "|-", str); + + if ( csq->vstr.l ) + kputs(csq->vstr.s, str); +} + +void hap_add_csq(args_t *args, hap_t *hap, hap_node_t *node, int tlen, int ibeg, int iend, int dlen, int indel) +{ + int i; + tscript_t *tr = hap->tr; + int ref_node = tr->strand==STRAND_FWD ? ibeg : iend; + + int icsq = node->ncsq_list++; + hts_expand0(csq_t,node->ncsq_list,node->mcsq_list,node->csq_list); + csq_t *csq = &node->csq_list[icsq]; + csq->pos = hap->stack[ref_node].node->rec->pos; + csq->type.trid = tr->id; + csq->type.gene = tr->gene->name; + csq->type.strand = tr->strand; + csq->type.biotype = tr->type; + + // only now we see the translated sequence and can determine if the stop/start changes are real + int rm_csq = 0; + csq->type.type = 0; + for (i=ibeg; i<=iend; i++) + csq->type.type |= hap->stack[i].node->csq & CSQ_COMPOUND; + if ( dlen==0 && indel ) csq->type.type |= CSQ_INFRAME_ALTERING; + + int has_upstream_stop = hap->upstream_stop; + if ( hap->stack[ibeg].node->type != HAP_SSS ) + { + // check for truncating stops + for (i=0; itref.l; i++) + if ( hap->tref.s[i]=='*' ) break; + if ( i!=hap->tref.l ) + { + hap->tref.l = i+1; + hap->tref.s[i+1] = 0; + } + for (i=0; itseq.l; i++) + if ( hap->tseq.s[i]=='*' ) break; + if ( i!=hap->tseq.l ) + { + hap->tseq.l = i+1; + hap->tseq.s[i+1] = 0; + hap->upstream_stop = 1; + } + if ( csq->type.type & CSQ_STOP_LOST ) + { + if ( hap->tref.s[hap->tref.l-1]=='*' && hap->tref.s[hap->tref.l-1] == hap->tseq.s[hap->tseq.l-1] ) + { + rm_csq |= CSQ_STOP_LOST; + csq->type.type |= CSQ_STOP_RETAINED; + } + else if ( hap->tref.s[hap->tref.l-1]!='*' ) + { + // This is CDS 3' incomplete ENSG00000173376/synon.vcf, can also be missense + // We observe in real data a change to a stop, ENST00000528237/retained-stop-incomplete-cds.vcf + if ( hap->tseq.s[hap->tseq.l-1] == '*' ) + { + rm_csq |= CSQ_STOP_GAINED; + csq->type.type |= CSQ_STOP_RETAINED; + } + else + csq->type.type |= CSQ_INCOMPLETE_CDS; + } + } + if ( csq->type.type & CSQ_START_LOST && hap->tref.s[0]!='M' ) + { + rm_csq |= CSQ_START_LOST; + csq->type.type &= ~CSQ_START_LOST; + } + if ( dlen!=0 ) + { + if ( dlen%3 ) + csq->type.type |= CSQ_FRAMESHIFT_VARIANT; + else if ( dlen<0 ) + csq->type.type |= CSQ_INFRAME_DELETION; + else + csq->type.type |= CSQ_INFRAME_INSERTION; + } + else + { + for (i=0; itref.l; i++) + if ( hap->tref.s[i] != hap->tseq.s[i] ) break; + if ( i==hap->tref.l ) + csq->type.type |= CSQ_SYNONYMOUS_VARIANT; + else if ( hap->tref.s[i] == '*' ) + csq->type.type |= CSQ_STOP_LOST; + else if ( hap->tseq.s[i] == '*' ) + csq->type.type |= CSQ_STOP_GAINED; + else + csq->type.type |= CSQ_MISSENSE_VARIANT; + } + } + if ( has_upstream_stop ) csq->type.type |= CSQ_UPSTREAM_STOP; + csq->type.type &= ~rm_csq; + + if ( hap->stack[ibeg].node->type == HAP_SSS ) + { + node->csq_list[icsq].type.type |= hap->stack[ibeg].node->csq & ~rm_csq; + node->csq_list[icsq].type.ref = hap->stack[ibeg].node->rec; + node->csq_list[icsq].type.biotype = tr->type; + csq_push(args, node->csq_list+icsq, hap->stack[ibeg].node->rec); + return; + } + + kstring_t str = node->csq_list[icsq].type.vstr; + str.l = 0; + + // create the aa variant string + int aa_rbeg = tr->strand==STRAND_FWD ? node2rbeg(ibeg)/3+1 : (hap->tr->nsref - 2*N_REF_PAD - node2rend(iend))/3+1; + int aa_sbeg = tr->strand==STRAND_FWD ? node2sbeg(ibeg)/3+1 : (tlen - node2send(iend))/3+1; + kputc_('|', &str); + kputw(aa_rbeg, &str); + kputs(hap->tref.s, &str); + if ( !(csq->type.type & CSQ_SYNONYMOUS_VARIANT) ) + { + kputc_('>', &str); + kputw(aa_sbeg, &str); + kputs(hap->tseq.s, &str); + } + kputc_('|', &str); + + // create the dna variant string and, in case of combined variants, + // insert silent CSQ_PRINTED_UPSTREAM variants + for (i=ibeg; i<=iend; i++) + { + if ( i>ibeg ) kputc_('+', &str); + kputw(node2rpos(i)+1, &str); + kputs(hap->stack[i].node->var, &str); + } + node->csq_list[icsq].type.vstr = str; + csq_push(args, node->csq_list+icsq, hap->stack[ref_node].node->rec); + + for (i=ibeg; i<=iend; i++) + { + // csq are printed at one position only for combined variants, the rest is + // silent and references the first + if ( hap->stack[i].node->csq & ~CSQ_COMPOUND ) + { + node->ncsq_list++; + hts_expand0(csq_t,node->ncsq_list,node->mcsq_list,node->csq_list); + csq_t *tmp_csq = &node->csq_list[node->ncsq_list - 1]; + tmp_csq->pos = hap->stack[i].node->rec->pos; + tmp_csq->type.trid = tr->id; + tmp_csq->type.gene = tr->gene->name; + tmp_csq->type.strand = tr->strand; + tmp_csq->type.type = hap->stack[i].node->csq & ~CSQ_COMPOUND & ~rm_csq; + tmp_csq->type.biotype = tr->type; + tmp_csq->type.vstr.l = 0; + kputs(str.s,&tmp_csq->type.vstr); + csq_push(args, tmp_csq, hap->stack[i].node->rec); + } + if ( i!=ref_node && (node->csq_list[icsq].type.type & CSQ_COMPOUND || !(hap->stack[i].node->csq & ~CSQ_COMPOUND)) ) + { + node->ncsq_list++; + hts_expand0(csq_t,node->ncsq_list,node->mcsq_list,node->csq_list); + csq_t *tmp_csq = &node->csq_list[node->ncsq_list - 1]; + tmp_csq->pos = hap->stack[i].node->rec->pos; + tmp_csq->type.trid = tr->id; + tmp_csq->type.gene = tr->gene->name; + tmp_csq->type.strand = tr->strand; + tmp_csq->type.type = CSQ_PRINTED_UPSTREAM | hap->stack[i].node->csq; + tmp_csq->type.biotype = tr->type; + tmp_csq->type.ref = hap->stack[ref_node].node->rec; + tmp_csq->type.vstr.l = 0; + csq_push(args, tmp_csq, hap->stack[i].node->rec); + } + } +} + + +void hap_finalize(args_t *args, hap_t *hap) +{ + tscript_t *tr = hap->tr; + if ( !tr->sref ) + tscript_splice_ref(tr); + + kstring_t sref; + sref.s = tr->sref; + sref.l = tr->nsref; + sref.m = sref.l; + + int istack = 0; + hts_expand(hstack_t,1,hap->mstack,hap->stack); + + hap->sseq.l = 0; + hap->tseq.l = 0; + hap->stack[0].node = tr->root; + hap->stack[0].ichild = -1; + hap->stack[0].slen = 0; + hap->stack[0].dlen = 0; + + while ( istack>=0 ) + { + hstack_t *stack = &hap->stack[istack]; + hap_node_t *node = hap->stack[istack].node; + while ( ++hap->stack[istack].ichild < node->nchild ) + { + if ( node->child[stack->ichild] ) break; + } + if ( stack->ichild == node->nchild ) { istack--; continue; } + + node = node->child[stack->ichild]; + + istack++; + hts_expand(hstack_t,istack+1,hap->mstack,hap->stack); + stack = &hap->stack[istack-1]; + + hap->stack[istack].node = node; + hap->stack[istack].ichild = -1; + + hap->sseq.l = stack->slen; + if ( node->type==HAP_CDS ) kputs(node->seq, &hap->sseq); + hap->stack[istack].slen = hap->sseq.l; + hap->stack[istack].dlen = hap->stack[istack-1].dlen + node->dlen; + + if ( !node->nend ) continue; // not a leaf node + + // The spliced sequence has been built for the current haplotype and stored + // in hap->sseq. Now we break it and output as independent parts + + kstring_t sseq; + sseq.m = sref.m - 2*N_REF_PAD + hap->stack[istack].dlen; // total length of the spliced query transcript + hap->upstream_stop = 0; + + int i = 1, dlen = 0, ibeg, indel = 0; + while ( istack[i].node->type == HAP_SSS ) i++; + hap->sbeg = hap->stack[i].node->sbeg; + + if ( tr->strand==STRAND_FWD ) + { + i = 0, ibeg = -1; + while ( ++i <= istack ) + { + if ( hap->stack[i].node->type == HAP_SSS ) + { + // start/stop/splice site overlap: don't know how to build the haplotypes correctly, skipping + hap_add_csq(args,hap,node,0,i,i,0,0); + continue; + } + dlen += hap->stack[i].node->dlen; + if ( hap->stack[i].node->dlen ) indel = 1; + + // This condition extends compound variants. Note that s/s/s sites are forced out to always break + // a compound block. See ENST00000271583/splice-acceptor.vcf for motivation. + if ( istack[i+1].node->type != HAP_SSS ) + { + if ( dlen%3 ) // frameshift + { + if ( ibeg==-1 ) ibeg = i; + continue; + } + int icur = node2sbeg(i); + int inext = node2sbeg(i+1); + if ( icur/3 == inext/3 ) // in the same codon, can't be flushed yet + { + if ( ibeg==-1 ) ibeg = i; + continue; + } + } + if ( ibeg<0 ) ibeg = i; + + int ioff = node2soff(ibeg); + int icur = node2sbeg(ibeg); + int rbeg = node2rbeg(ibeg); + int rend = node2rend(i); + int fill = dlen%3; + + // alt + if ( hap->sseq.l ) + { + sseq.l = hap->stack[i].slen - ioff; + sseq.s = hap->sseq.s + ioff; + } + else // splice site overlap, see #1475227917 + sseq.l = fill = 0; + cds_translate(&sref, &sseq, icur,rbeg,rend, tr->strand, &hap->tseq, fill); + + // ref + sseq.l = node2rend(i) - rbeg; + sseq.s = sref.s + N_REF_PAD + rbeg; + sseq.m = sref.m - 2*N_REF_PAD; + cds_translate(&sref, &sseq, rbeg,rbeg,rend, tr->strand, &hap->tref, fill); + sseq.m = sref.m - 2*N_REF_PAD + hap->stack[istack].dlen; + + hap_add_csq(args,hap,node,0, ibeg,i,dlen,indel); + ibeg = -1; + dlen = 0; + indel = 0; + } + } + else + { + i = istack + 1, ibeg = -1; + while ( --i > 0 ) + { + if ( hap->stack[i].node->type == HAP_SSS ) + { + hap_add_csq(args,hap,node,0,i,i,0,0); + continue; + } + dlen += hap->stack[i].node->dlen; + if ( hap->stack[i].node->dlen ) indel = 1; + if ( i>1 && hap->stack[i-1].node->type != HAP_SSS ) + { + if ( dlen%3 ) + { + if ( ibeg==-1 ) ibeg = i; + continue; + } + int icur = sseq.m - 1 - node2sbeg(i); + int inext = sseq.m - 1 - node2sbeg(i-1); + if ( icur/3 == inext/3 ) + { + if ( ibeg==-1 ) ibeg = i; + continue; + } + } + if ( ibeg<0 ) ibeg = i; + int ioff = node2soff(i); + int icur = node2sbeg(i); + int rbeg = node2rbeg(i); + int rend = node2rend(ibeg); + int fill = dlen%3; + + // alt + if ( hap->sseq.l ) + { + sseq.l = hap->stack[ibeg].slen - ioff; + sseq.s = hap->sseq.s + ioff; + } + else // splice site overlap, see #1475227917 + sseq.l = fill = 0; + cds_translate(&sref, &sseq, icur,rbeg,rend, tr->strand, &hap->tseq, fill); + + // ref + sseq.l = node2rend(ibeg) - rbeg; + sseq.s = sref.s + N_REF_PAD + rbeg; + sseq.m = sref.m - 2*N_REF_PAD; + cds_translate(&sref, &sseq, rbeg,rbeg,rend, tr->strand, &hap->tref, fill); + sseq.m = sref.m - 2*N_REF_PAD + hap->stack[istack].dlen; + + hap_add_csq(args,hap,node,sseq.m, i,ibeg,dlen,indel); + ibeg = -1; + dlen = 0; + indel = 0; + } + } + } +} + +static inline void csq_print_text(args_t *args, csq_t *csq, int ismpl, int ihap) +{ + if ( csq->type.type & CSQ_PRINTED_UPSTREAM ) return; + + char *smpl = ismpl >= 0 ? args->hdr->samples[ismpl] : "-"; + const char *chr = bcf_hdr_id2name(args->hdr,args->rid); + + fprintf(args->out,"CSQ\t%s\t", smpl); + if ( ihap>0 ) + fprintf(args->out,"%d", ihap); + else + fprintf(args->out,"-"); + + args->str.l = 0; + kput_vcsq(args, &csq->type, &args->str); + fprintf(args->out,"\t%s\t%d\t%s\n",chr,csq->pos+1,args->str.s); +} +static inline void hap_print_text(args_t *args, tscript_t *tr, int ismpl, int ihap, hap_node_t *node) +{ + if ( !node || !node->ncsq_list ) return; + + char *smpl = ismpl >= 0 ? args->hdr->samples[ismpl] : "-"; + const char *chr = bcf_hdr_id2name(args->hdr,args->rid); + + int i; + for (i=0; incsq_list; i++) + { + csq_t *csq = node->csq_list + i; + if ( csq->type.type & CSQ_PRINTED_UPSTREAM ) continue; + assert( csq->type.vstr.l ); + + fprintf(args->out,"CSQ\t%s\t", smpl); + if ( ihap>0 ) + fprintf(args->out,"%d", ihap); + else + fprintf(args->out,"-"); + + args->str.l = 0; + kput_vcsq(args, &csq->type, &args->str); + fprintf(args->out,"\t%s\t%d\t%s\n",chr,csq->pos+1,args->str.s); + } +} + +static inline void hap_stage_vcf(args_t *args, tscript_t *tr, int ismpl, int ihap, hap_node_t *node) +{ + if ( !node || !node->ncsq_list || ismpl<0 ) return; + + int i; + for (i=0; incsq_list; i++) + { + csq_t *csq = node->csq_list + i; + vrec_t *vrec = csq->vrec; + int icsq = 2*csq->idx + ihap; + if ( icsq >= args->ncsq_max ) // more than ncsq_max consequences, so can't fit it in FMT + { + int print_warning = 1; + if ( args->quiet ) + { + if ( args->quiet > 1 || args->ncsq_small_warned ) print_warning = 0; + args->ncsq_small_warned = 1; + } + if ( print_warning ) + { + fprintf(stderr,"Warning: --ncsq %d is too small to annotate %s at %s:%d with %d-th csq\n", + args->ncsq_max/2,args->hdr->samples[ismpl],bcf_hdr_id2name(args->hdr,args->rid),vrec->line->pos+1,csq->idx+1); + if ( args->quiet ) fprintf(stderr,"(This warning is printed only once)\n"); + } + break; + } + if ( vrec->nfmt < 1 + icsq/32 ) vrec->nfmt = 1 + icsq/32; + vrec->smpl[ismpl*args->nfmt_bcsq + icsq/32] |= 1 << (icsq % 32); + } +} + +void hap_flush(args_t *args, uint32_t pos) +{ + int i,j; + tr_heap_t *heap = args->active_tr; + + while ( heap->ndat && heap->dat[0]->end<=pos ) + { + tscript_t *tr = heap->dat[0]; + khp_delete(trhp, heap); + + args->hap->tr = tr; + if ( tr->root && tr->root->nchild ) // normal, non-localized calling + { + hap_finalize(args, args->hap); + + if ( args->output_type==FT_TAB_TEXT ) // plain text output, not a vcf + { + if ( args->phase==PHASE_DROP_GT ) + hap_print_text(args, tr, -1,0, tr->hap[0]); + else + { + for (i=0; ismpl->n; i++) + { + for (j=0; j<2; j++) + hap_print_text(args, tr, args->smpl->idx[i],j+1, tr->hap[i*2+j]); + } + } + } + else if ( args->phase!=PHASE_DROP_GT ) + { + for (i=0; ismpl->n; i++) + { + for (j=0; j<2; j++) + hap_stage_vcf(args, tr, args->smpl->idx[i],j, tr->hap[i*2+j]); + } + } + } + + // mark the transcript for deletion. Cannot delete it immediately because + // by-position VCF output will need them when flushed by vcf_buf_push + args->nrm_tr++; + hts_expand(tscript_t*,args->nrm_tr,args->mrm_tr,args->rm_tr); + args->rm_tr[args->nrm_tr-1] = tr; + } +} + +#define SWAP(type_t, a, b) { type_t t = a; a = b; b = t; } + +void vbuf_push(args_t *args, bcf1_t **rec_ptr) +{ + int i; + + assert(rec_ptr); + bcf1_t *rec = *rec_ptr; + + // check for duplicate records + i = args->vcf_rbuf.n ? rbuf_last(&args->vcf_rbuf) : -1; + if ( i<0 || args->vcf_buf[i]->vrec[0]->line->pos!=rec->pos ) + { + // vcf record with a new pos + rbuf_expand0(&args->vcf_rbuf, vbuf_t*, args->vcf_rbuf.n+1, args->vcf_buf); + i = rbuf_append(&args->vcf_rbuf); + if ( !args->vcf_buf[i] ) args->vcf_buf[i] = (vbuf_t*) calloc(1,sizeof(vbuf_t)); + args->vcf_buf[i]->n = 0; + } + vbuf_t *vbuf = args->vcf_buf[i]; + vbuf->n++; + hts_expand0(vrec_t*, vbuf->n, vbuf->m, vbuf->vrec); + if ( !vbuf->vrec[vbuf->n - 1] ) + vbuf->vrec[vbuf->n - 1] = (vrec_t*) calloc(1,sizeof(vrec_t)); + + vrec_t *vrec = vbuf->vrec[vbuf->n - 1]; + if ( args->phase!=PHASE_DROP_GT && args->smpl->n ) + { + if ( !vrec->smpl ) vrec->smpl = (uint32_t*) calloc(args->hdr_nsmpl,sizeof(*vrec->smpl) * args->nfmt_bcsq); + else memset(vrec->smpl,0,args->hdr_nsmpl*sizeof(*vrec->smpl) * args->nfmt_bcsq); + } + if ( !vrec->line ) vrec->line = bcf_init1(); + SWAP(bcf1_t*, (*rec_ptr), vrec->line); + + int ret; + khint_t k = kh_put(pos2vbuf, args->pos2vbuf, (int)rec->pos, &ret); + kh_val(args->pos2vbuf,k) = vbuf; +} + +void vbuf_flush(args_t *args) +{ + if ( args->active_tr->ndat ) return; // cannot output buffered VCF lines (args.vbuf) until all active transcripts are gone + + int i,j; + while ( (i=rbuf_shift(&args->vcf_rbuf))>=0 ) + { + vbuf_t *vbuf = args->vcf_buf[i]; + for (i=0; in; i++) + { + vrec_t *vrec = vbuf->vrec[i]; + if ( !args->out_fh ) // not a VCF output + { + vrec->nvcsq = 0; + continue; + } + if ( !vrec->nvcsq ) + { + bcf_write(args->out_fh, args->hdr, vrec->line); + continue; + } + + args->str.l = 0; + kput_vcsq(args, &vrec->vcsq[0], &args->str); + for (j=1; jnvcsq; j++) + { + kputc_(',', &args->str); + kput_vcsq(args, &vrec->vcsq[j], &args->str); + } + bcf_update_info_string(args->hdr, vrec->line, args->bcsq_tag, args->str.s); + if ( args->hdr_nsmpl ) + { + if ( vrec->nfmt < args->nfmt_bcsq ) + for (j=1; jhdr_nsmpl; j++) memcpy(vrec->smpl+j*vrec->nfmt, vrec->smpl+j*args->nfmt_bcsq, vrec->nfmt*sizeof(*vrec->smpl)); + bcf_update_format_int32(args->hdr, vrec->line, args->bcsq_tag, vrec->smpl, args->hdr_nsmpl*vrec->nfmt); + } + vrec->nvcsq = 0; + bcf_write(args->out_fh, args->hdr, vrec->line); + } + if ( vbuf->n ) + { + khint_t k = kh_get(pos2vbuf, args->pos2vbuf, vbuf->vrec[0]->line->pos); + if ( k != kh_end(args->pos2vbuf) ) kh_del(pos2vbuf, args->pos2vbuf, k); + } + vbuf->n = 0; + } + + for (i=0; inrm_tr; i++) + { + tscript_t *tr = args->rm_tr[i]; + if ( tr->root ) hap_destroy(tr->root); + tr->root = NULL; + free(tr->hap); + free(tr->ref); + free(tr->sref); + } + args->nrm_tr = 0; + args->ncsq_buf = 0; +} + +void tscript_init_ref(args_t *args, tscript_t *tr, const char *chr) +{ + int i, len; + int pad_beg = tr->beg >= N_REF_PAD ? N_REF_PAD : tr->beg; + + tr->ref = faidx_fetch_seq(args->fai, chr, tr->beg - pad_beg, tr->end + N_REF_PAD, &len); + if ( !tr->ref ) + error("faidx_fetch_seq failed %s:%d-%d\n", chr,tr->beg+1,tr->end+1); + + int pad_end = len - (tr->end - tr->beg + 1 + pad_beg); + if ( pad_beg + pad_end != 2*N_REF_PAD ) + { + char *ref = (char*) malloc(tr->end - tr->beg + 1 + 2*N_REF_PAD); + for (i=0; i < N_REF_PAD - pad_beg; i++) ref[i] = 'N'; + memcpy(ref+i, tr->ref, len); + for (i=0; i < N_REF_PAD - pad_end; i++) ref[i+len] = 'N'; + free(tr->ref); + tr->ref = ref; + } +} + +static void sanity_check_ref(args_t *args, tscript_t *tr, bcf1_t *rec) +{ + char *ref = tr->ref + (rec->pos + N_REF_PAD >= tr->beg ? rec->pos - tr->beg + N_REF_PAD : 0); + char *vcf = rec->d.allele[0] + (rec->pos + N_REF_PAD >= tr->beg ? 0 : tr->beg - N_REF_PAD - rec->pos); + assert( vcf - rec->d.allele[0] < strlen(rec->d.allele[0]) ); + while ( *ref && *vcf ) + { + if ( *ref!=*vcf && toupper(*ref)!=toupper(*vcf) ) + error("Error: the fasta reference does not match the VCF REF allele at %s:%d .. %s\n", bcf_seqname(args->hdr,rec),rec->pos+1,rec->d.allele[0]); + ref++; + vcf++; + } +} + +int test_cds_local(args_t *args, bcf1_t *rec) +{ + int i,j, ret = 0; + const char *chr = bcf_seqname(args->hdr,rec); + // note that the off-by-one extension of rlen is deliberate to account for insertions + if ( !regidx_overlap(args->idx_cds,chr,rec->pos,rec->pos+rec->rlen, args->itr) ) return 0; + + // structures to fake the normal test_cds machinery + hap_node_t root, node; + root.type = HAP_ROOT; + kstring_t *tref = &args->hap->tref, *tseq = &args->hap->tseq; + + while ( regitr_overlap(args->itr) ) + { + gf_cds_t *cds = regitr_payload(args->itr,gf_cds_t*); + tscript_t *tr = cds->tr; + if ( !GF_is_coding(tr->type) ) continue; + ret = 1; + + if ( !tr->ref ) + { + tscript_init_ref(args, tr, chr); + tscript_splice_ref(tr); + khp_insert(trhp, args->active_tr, &tr); // only to clean the reference afterwards + } + + sanity_check_ref(args, tr, rec); + + kstring_t sref; + sref.s = tr->sref; + sref.l = tr->nsref; + sref.m = sref.l; + + for (i=1; in_allele; i++) + { + if ( hap_init(args, &root, &node, cds, rec, i)!=0 ) continue; + + csq_t csq; + memset(&csq, 0, sizeof(csq_t)); + csq.pos = rec->pos; + csq.type.biotype = tr->type; + csq.type.strand = tr->strand; + csq.type.trid = tr->id; + csq.type.gene = tr->gene->name; + + int csq_type = node.csq; + + // code repetition: it would be nice to reuse the code from hap_add_csq, needs have refactoring though + if ( node.type == HAP_SSS ) + { + csq.type.type = csq_type; + csq_stage(args, &csq, rec); + } + else + { + kstring_t sseq; + sseq.m = sref.m - 2*N_REF_PAD + node.dlen; + sseq.s = node.seq; + int alen = sseq.l = strlen(sseq.s); + int fill = node.dlen%3 && alen ? 1 : 0; // see #1475227917 + cds_translate(&sref, &sseq, node.sbeg,node.sbeg,node.sbeg+node.rlen, tr->strand, tseq, fill); + + sseq.m = sref.m - 2*N_REF_PAD; + sseq.s = sref.s + N_REF_PAD + node.sbeg; + sseq.l = node.rlen; + cds_translate(&sref, &sseq, node.sbeg,node.sbeg,node.sbeg+node.rlen, tr->strand, tref, fill); + + // check for truncating stops + for (j=0; jl; j++) + if ( tref->s[j]=='*' ) break; + if ( j!=tref->l ) + { + tref->l = j+1; + tref->s[j+1] = 0; + } + for (j=0; jl; j++) + if ( tseq->s[j]=='*' ) break; + if ( j!=tseq->l ) + { + tseq->l = j+1; + tseq->s[j+1] = 0; + } + if ( csq_type & CSQ_STOP_LOST ) + { + if ( tref->s[tref->l-1]=='*' && tref->s[tref->l-1] == tseq->s[tseq->l-1] ) + { + csq_type &= ~CSQ_STOP_LOST; + csq_type |= CSQ_STOP_RETAINED; + } + else if (tref->s[tref->l-1]!='*' ) + { + // This is CDS 3' incomplete ENSG00000173376/synon.vcf, can also be missense + // We observe in real data a change to a stop, ENST00000528237/retained-stop-incomplete-cds.vcf + if ( tseq->s[tseq->l-1] == '*' ) + { + csq_type &= ~CSQ_STOP_GAINED; + csq_type |= CSQ_STOP_RETAINED; + } + else + csq_type |= CSQ_INCOMPLETE_CDS; + } + } + if ( csq_type & CSQ_START_LOST && tref->s[0]!='M' ) + csq_type &= ~CSQ_START_LOST; + if ( node.dlen!=0 ) + { + if ( node.dlen%3 ) + csq_type |= CSQ_FRAMESHIFT_VARIANT; + else if ( node.dlen<0 ) + csq_type |= CSQ_INFRAME_DELETION; + else + csq_type |= CSQ_INFRAME_INSERTION; + } + else + { + for (j=0; jl; j++) + if ( tref->s[j] != tseq->s[j] ) break; + if ( j==tref->l ) + csq_type |= CSQ_SYNONYMOUS_VARIANT; + else if ( tref->s[j] == '*' ) + csq_type |= CSQ_STOP_LOST; + else if ( tseq->s[j] == '*' ) + csq_type |= CSQ_STOP_GAINED; + else + csq_type |= CSQ_MISSENSE_VARIANT; + } + if ( csq_type & CSQ_COMPOUND ) + { + // create the aa variant string + kstring_t str = {0,0,0}; + int aa_rbeg = tr->strand==STRAND_FWD ? node.sbeg/3+1 : (tr->nsref - 2*N_REF_PAD - node.sbeg - node.rlen)/3+1; + int aa_sbeg = tr->strand==STRAND_FWD ? node.sbeg/3+1 : (tr->nsref - 2*N_REF_PAD + node.dlen - node.sbeg - alen)/3+1; + kputc_('|', &str); + kputw(aa_rbeg, &str); + kputs(tref->s, &str); + if ( !(csq_type & CSQ_SYNONYMOUS_VARIANT) ) + { + kputc_('>', &str); + kputw(aa_sbeg, &str); + kputs(tseq->s, &str); + } + kputc_('|', &str); + kputw(rec->pos+1, &str); + kputs(node.var, &str); + csq.type.vstr = str; + csq.type.type = csq_type & CSQ_COMPOUND; + csq_stage(args, &csq, rec); + + // all this only to clean vstr when vrec is flushed + if ( !tr->root ) + tr->root = (hap_node_t*) calloc(1,sizeof(hap_node_t)); + tr->root->ncsq_list++; + hts_expand0(csq_t,tr->root->ncsq_list,tr->root->mcsq_list,tr->root->csq_list); + csq_t *rm_csq = tr->root->csq_list + tr->root->ncsq_list - 1; + rm_csq->type.vstr = str; + } + if ( csq_type & ~CSQ_COMPOUND ) + { + csq.type.type = csq_type & ~CSQ_COMPOUND; + csq.type.vstr.l = 0; + csq_stage(args, &csq, rec); + } + } + free(node.seq); + free(node.var); + } + } + return ret; +} + +int test_cds(args_t *args, bcf1_t *rec) +{ + int i, ret = 0, hap_ret; + const char *chr = bcf_seqname(args->hdr,rec); + // note that the off-by-one extension of rlen is deliberate to account for insertions + if ( !regidx_overlap(args->idx_cds,chr,rec->pos,rec->pos+rec->rlen, args->itr) ) return 0; + while ( regitr_overlap(args->itr) ) + { + gf_cds_t *cds = regitr_payload(args->itr,gf_cds_t*); + tscript_t *tr = cds->tr; + if ( !GF_is_coding(tr->type) ) continue; + ret = 1; + if ( !tr->root ) + { + // initialize the transcript and its haplotype tree, fetch the reference sequence + tscript_init_ref(args, tr, chr); + + tr->root = (hap_node_t*) calloc(1,sizeof(hap_node_t)); + tr->nhap = args->phase==PHASE_DROP_GT ? 1 : 2*args->smpl->n; // maximum ploidy = diploid + tr->hap = (hap_node_t**) malloc(tr->nhap*sizeof(hap_node_t*)); + for (i=0; inhap; i++) tr->hap[i] = NULL; + tr->root->nend = tr->nhap; + tr->root->type = HAP_ROOT; + + khp_insert(trhp, args->active_tr, &tr); + } + + sanity_check_ref(args, tr, rec); + + if ( args->phase==PHASE_DROP_GT ) + { + if ( rec->d.allele[1][0]=='<' || rec->d.allele[1][0]=='*' ) { continue; } + hap_node_t *parent = tr->hap[0] ? tr->hap[0] : tr->root; + hap_node_t *child = (hap_node_t*)calloc(1,sizeof(hap_node_t)); + if ( (hap_ret=hap_init(args, parent, child, cds, rec, 1))!=0 ) + { + // overlapping or intron variant, cannot apply + if ( hap_ret==1 ) + { + if ( !args->quiet ) + fprintf(stderr,"Warning: Skipping overlapping variants at %s:%d\t%s>%s\n", chr,rec->pos+1,rec->d.allele[0],rec->d.allele[1]); + if ( args->out ) + fprintf(args->out,"LOG\tWarning: Skipping overlapping variants at %s:%d\t%s>%s\n", chr,rec->pos+1,rec->d.allele[0],rec->d.allele[1]); + } + else ret = 1; // prevent reporting as intron in test_tscript + free(child); + continue; + } + parent->nend--; + parent->nchild = 1; + parent->mchild = 1; + parent->child = (hap_node_t**) malloc(sizeof(hap_node_t*)); + parent->child[0] = child; + tr->hap[0] = child; + tr->hap[0]->nend = 1; + continue; + } + + // apply the VCF variants and extend the haplotype tree + int j, ismpl, ihap, ngts = bcf_get_genotypes(args->hdr, rec, &args->gt_arr, &args->mgt_arr); + ngts /= bcf_hdr_nsamples(args->hdr); + if ( ngts!=1 && ngts!=2 ) + { + if ( !args->quiet ) + fprintf(stderr,"Warning: Skipping site with non-diploid/non-haploid genotypes at %s:%d\t%s>%s\n", chr,rec->pos+1,rec->d.allele[0],rec->d.allele[1]); + if ( args->out ) + fprintf(args->out,"LOG\tWarning: Skipping site with non-diploid/non-haploid genotypes at %s:%d\t%s>%s\n", chr,rec->pos+1,rec->d.allele[0],rec->d.allele[1]); + continue; + } + for (ismpl=0; ismplsmpl->n; ismpl++) + { + int32_t *gt = args->gt_arr + args->smpl->idx[ismpl]*ngts; + if ( gt[0]==bcf_gt_missing ) continue; + + if ( ngts>1 && gt[1]!=bcf_gt_missing && gt[1]!=bcf_int32_vector_end && bcf_gt_allele(gt[0])!=bcf_gt_allele(gt[1]) ) + { + if ( args->phase==PHASE_MERGE ) + { + if ( !bcf_gt_allele(gt[0]) ) gt[0] = gt[1]; + } + if ( !bcf_gt_is_phased(gt[0]) && !bcf_gt_is_phased(gt[1]) ) + { + if ( args->phase==PHASE_REQUIRE ) + error("Unphased heterozygous genotype at %s:%d, sample %s. See the --phase option.\n", chr,rec->pos+1,args->hdr->samples[args->smpl->idx[ismpl]]); + if ( args->phase==PHASE_SKIP ) + continue; + if ( args->phase==PHASE_NON_REF ) + { + if ( !bcf_gt_allele(gt[0]) ) gt[0] = gt[1]; + else if ( !bcf_gt_allele(gt[1]) ) gt[1] = gt[0]; + } + } + } + + for (ihap=0; ihapn_allele ); + if ( rec->d.allele[ial][0]=='<' || rec->d.allele[ial][0]=='*' ) { continue; } + + hap_node_t *parent = tr->hap[i] ? tr->hap[i] : tr->root; + if ( parent->cur_rec==rec && parent->cur_child[ial]>=0 ) + { + // this haplotype has been seen in another sample + tr->hap[i] = parent->child[ parent->cur_child[ial] ]; + tr->hap[i]->nend++; + parent->nend--; + continue; + } + + hap_node_t *child = (hap_node_t*)calloc(1,sizeof(hap_node_t)); + if ( (hap_ret=hap_init(args, parent, child, cds, rec, ial))!=0 ) + { + // overlapping or intron variant, cannot apply + if ( hap_ret==1 ) + { + if ( !args->quiet ) + fprintf(stderr,"Warning: Skipping overlapping variants at %s:%d, sample %s\t%s>%s\n", + chr,rec->pos+1,args->hdr->samples[args->smpl->idx[ismpl]],rec->d.allele[0],rec->d.allele[ial]); + if ( args->out ) + fprintf(args->out,"LOG\tWarning: Skipping overlapping variants at %s:%d, sample %s\t%s>%s\n", + chr,rec->pos+1,args->hdr->samples[args->smpl->idx[ismpl]],rec->d.allele[0],rec->d.allele[ial]); + } + free(child); + continue; + } + + if ( parent->cur_rec!=rec ) + { + hts_expand(int,rec->n_allele,parent->mcur_child,parent->cur_child); + for (j=0; jn_allele; j++) parent->cur_child[j] = -1; + parent->cur_rec = rec; + } + + j = parent->nchild++; + hts_expand0(hap_node_t*,parent->nchild,parent->mchild,parent->child); + parent->cur_child[ial] = j; + parent->child[j] = child; + tr->hap[i] = child; + tr->hap[i]->nend++; + parent->nend--; + } + } + } + return ret; +} + +void csq_stage(args_t *args, csq_t *csq, bcf1_t *rec) +{ + // known issues: tab output leads to unsorted output. This is because + // coding haplotypes are printed in one go and buffering is not used + // with tab output. VCF output is OK though. + if ( csq_push(args, csq, rec)!=0 ) return; // the consequence already exists + + int i,j,ngt = 0; + if ( args->phase!=PHASE_DROP_GT ) + { + ngt = bcf_get_genotypes(args->hdr, rec, &args->gt_arr, &args->mgt_arr); + if ( ngt>0 ) ngt /= bcf_hdr_nsamples(args->hdr); + } + if ( ngt<=0 ) + { + if ( args->output_type==FT_TAB_TEXT ) + csq_print_text(args, csq, -1,0); + return; + } + assert( ngt<=2 ); + + if ( args->output_type==FT_TAB_TEXT ) + { + for (i=0; ismpl->n; i++) + { + int32_t *gt = args->gt_arr + args->smpl->idx[i]*ngt; + for (j=0; jsmpl->idx[i],j+1); + } + } + return; + } + + vrec_t *vrec = csq->vrec; + for (i=0; ismpl->n; i++) + { + int32_t *gt = args->gt_arr + args->smpl->idx[i]*ngt; + for (j=0; jidx + j; + if ( icsq >= args->ncsq_max ) // more than ncsq_max consequences, so can't fit it in FMT + { + int ismpl = args->smpl->idx[i]; + int print_warning = 1; + if ( args->quiet ) + { + if ( args->quiet > 1 || args->ncsq_small_warned ) print_warning = 0; + args->ncsq_small_warned = 1; + } + if ( print_warning ) + { + fprintf(stderr,"Warning: --ncsq %d is too small to annotate %s at %s:%d with %d-th csq\n", + args->ncsq_max/2,args->hdr->samples[ismpl],bcf_hdr_id2name(args->hdr,args->rid),vrec->line->pos+1,csq->idx+1); + if ( args->quiet ) fprintf(stderr,"(This warning is printed only once)\n"); + } + break; + } + if ( vrec->nfmt < 1 + icsq/32 ) vrec->nfmt = 1 + icsq/32; + vrec->smpl[i*args->nfmt_bcsq + icsq/32] |= 1 << (icsq % 32); + } + } +} +int test_utr(args_t *args, bcf1_t *rec) +{ + const char *chr = bcf_seqname(args->hdr,rec); + // note that the off-by-one extension of rlen is deliberate to account for insertions + if ( !regidx_overlap(args->idx_utr,chr,rec->pos,rec->pos+rec->rlen, args->itr) ) return 0; + + splice_t splice; + splice_init(&splice, rec); + + int i, ret = 0; + while ( regitr_overlap(args->itr) ) + { + gf_utr_t *utr = regitr_payload(args->itr, gf_utr_t*); + tscript_t *tr = splice.tr = utr->tr; + for (i=1; in_allele; i++) + { + if ( rec->d.allele[1][0]=='<' || rec->d.allele[1][0]=='*' ) { continue; } + splice.vcf.alt = rec->d.allele[i]; + int splice_ret = splice_csq(args, &splice, utr->beg, utr->end); + if ( splice_ret!=SPLICE_INSIDE && splice_ret!=SPLICE_OVERLAP ) continue; + csq_t csq; + memset(&csq, 0, sizeof(csq_t)); + csq.pos = rec->pos; + csq.type.type = utr->which==prime5 ? CSQ_UTR5 : CSQ_UTR3; + csq.type.biotype = tr->type; + csq.type.strand = tr->strand; + csq.type.trid = tr->id; + csq.type.gene = tr->gene->name; + csq_stage(args, &csq, rec); + ret = 1; + } + } + assert(!splice.kref.s); + assert(!splice.kalt.s); + return ret; +} +int test_splice(args_t *args, bcf1_t *rec) +{ + const char *chr = bcf_seqname(args->hdr,rec); + if ( !regidx_overlap(args->idx_exon,chr,rec->pos,rec->pos + rec->rlen, args->itr) ) return 0; + + splice_t splice; + splice_init(&splice, rec); + splice.check_acceptor = splice.check_donor = 1; + + int i, ret = 0; + while ( regitr_overlap(args->itr) ) + { + gf_exon_t *exon = regitr_payload(args->itr, gf_exon_t*); + splice.tr = exon->tr; + if ( !splice.tr->ncds ) continue; // not a coding transcript, no interest in splice sites + + splice.check_region_beg = splice.tr->beg==exon->beg ? 0 : 1; + splice.check_region_end = splice.tr->end==exon->end ? 0 : 1; + + for (i=1; in_allele; i++) + { + if ( rec->d.allele[1][0]=='<' || rec->d.allele[1][0]=='*' ) { continue; } + splice.vcf.alt = rec->d.allele[i]; + splice_csq(args, &splice, exon->beg, exon->end); + if ( splice.csq ) ret = 1; + } + } + free(splice.kref.s); + free(splice.kalt.s); + return ret; +} +int test_tscript(args_t *args, bcf1_t *rec) +{ + const char *chr = bcf_seqname(args->hdr,rec); + if ( !regidx_overlap(args->idx_tscript,chr,rec->pos,rec->pos+rec->rlen, args->itr) ) return 0; + + splice_t splice; + splice_init(&splice, rec); + + int i, ret = 0; + while ( regitr_overlap(args->itr) ) + { + tscript_t *tr = splice.tr = regitr_payload(args->itr, tscript_t*); + for (i=1; in_allele; i++) + { + if ( rec->d.allele[1][0]=='<' || rec->d.allele[1][0]=='*' ) { continue; } + splice.vcf.alt = rec->d.allele[i]; + int splice_ret = splice_csq(args, &splice, tr->beg, tr->end); + if ( splice_ret!=SPLICE_INSIDE && splice_ret!=SPLICE_OVERLAP ) continue; // SPLICE_OUTSIDE or SPLICE_REF + csq_t csq; + memset(&csq, 0, sizeof(csq_t)); + csq.pos = rec->pos; + csq.type.type = GF_is_coding(tr->type) ? CSQ_INTRON : CSQ_NON_CODING; + csq.type.biotype = tr->type; + csq.type.strand = tr->strand; + csq.type.trid = tr->id; + csq.type.gene = tr->gene->name; + csq_stage(args, &csq, rec); + ret = 1; + } + } + assert(!splice.kref.s); + assert(!splice.kalt.s); + return ret; +} + +void process(args_t *args, bcf1_t **rec_ptr) +{ + if ( !rec_ptr ) + { + hap_flush(args, REGIDX_MAX); + vbuf_flush(args); + return; + } + + bcf1_t *rec = *rec_ptr; + + int call_csq = 1; + if ( !rec->n_allele ) call_csq = 0; // no alternate allele + else if ( rec->n_allele==2 && (rec->d.allele[1][0]=='<' || rec->d.allele[1][0]=='*') ) call_csq = 0; // gVCF, no alt allele + else if ( rec->d.allele[1][0]=='<' && rec->d.allele[1][0]!='*') call_csq = 0; // a symbolic allele, not ready for CNVs etc + else if ( args->filter ) + { + call_csq = filter_test(args->filter, rec, NULL); + if ( args->filter_logic==FLT_EXCLUDE ) call_csq = call_csq ? 0 : 1; + } + if ( !call_csq ) + { + if ( !args->out_fh ) return; // not a VCF output + vbuf_push(args, rec_ptr); + vbuf_flush(args); + return; + } + + if ( args->rid != rec->rid ) + { + hap_flush(args, REGIDX_MAX); + vbuf_flush(args); + } + args->rid = rec->rid; + vbuf_push(args, rec_ptr); + + int hit = args->local_csq ? test_cds_local(args, rec) : test_cds(args, rec); + hit += test_utr(args, rec); + hit += test_splice(args, rec); + if ( !hit ) test_tscript(args, rec); + + hap_flush(args, rec->pos-1); + vbuf_flush(args); + + return; +} + +static const char *usage(void) +{ + return + "\n" + "About: Haplotype-aware consequence caller.\n" + "Usage: bcftools csq [options] in.vcf\n" + "\n" + "Required options:\n" + " -f, --fasta-ref reference file in fasta format\n" + " -g, --gff-annot gff3 annotation file\n" + "\n" + "CSQ options:\n" + " -c, --custom-tag use this tag instead of the default BCSQ\n" + " -l, --local-csq localized predictions, consider only one VCF record at a time\n" + " -n, --ncsq maximum number of consequences to consider per site [16]\n" + " -p, --phase how to handle unphased heterozygous genotypes: [r]\n" + " a: take GTs as is, create haplotypes regardless of phase (0/1 -> 0|1)\n" + " m: merge *all* GTs into a single haplotype (0/1 -> 1, 1/2 -> 1)\n" + " r: require phased GTs, throw an error on unphased het GTs\n" + " R: create non-reference haplotypes if possible (0/1 -> 1|1, 1/2 -> 1|2)\n" + " s: skip unphased hets\n" + "Options:\n" + " -e, --exclude exclude sites for which the expression is true\n" + " -i, --include select sites for which the expression is true\n" + " -o, --output write output to a file [standard output]\n" + " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF\n" + " v: uncompressed VCF, t: plain tab-delimited text output [v]\n" + " -q, --quiet suppress warning messages. Can be given two times for even less messages\n" + " -r, --regions restrict to comma-separated list of regions\n" + " -R, --regions-file restrict to regions listed in a file\n" + " -s, --samples <-|list> samples to include or \"-\" to apply all variants and ignore samples\n" + " -S, --samples-file samples to include\n" + " -t, --targets similar to -r but streams rather than index-jumps\n" + " -T, --targets-file similar to -R but streams rather than index-jumps\n" + "\n" + "Example:\n" + " bcftools csq -f hs37d5.fa -g Homo_sapiens.GRCh37.82.gff3.gz in.vcf\n" + "\n" + " # GFF3 annotation files can be downloaded from Ensembl. e.g. for human:\n" + " ftp://ftp.ensembl.org/pub/current_gff3/homo_sapiens/\n" + " ftp://ftp.ensembl.org/pub/grch37/release-84/gff3/homo_sapiens/\n" + "\n"; +} + +int main_csq(int argc, char *argv[]) +{ + args_t *args = (args_t*) calloc(1,sizeof(args_t)); + args->argc = argc; args->argv = argv; + args->output_type = FT_VCF; + args->bcsq_tag = "BCSQ"; + args->ncsq_max = 2*16; + + static struct option loptions[] = + { + {"help",0,0,'h'}, + {"ncsq",1,0,'n'}, + {"custom-tag",1,0,'c'}, + {"local-csq",0,0,'l'}, + {"gff-annot",1,0,'g'}, + {"fasta-ref",1,0,'f'}, + {"include",1,0,'i'}, + {"exclude",1,0,'e'}, + {"output",1,0,'o'}, + {"output-type",1,NULL,'O'}, + {"phase",1,0,'p'}, + {"quiet",0,0,'q'}, + {"regions",1,0,'r'}, + {"regions-file",1,0,'R'}, + {"samples",1,0,'s'}, + {"samples-file",1,0,'S'}, + {"targets",1,0,'t'}, + {"targets-file",1,0,'T'}, + {0,0,0,0} + }; + int c, targets_is_file = 0, regions_is_file = 0; + char *targets_list = NULL, *regions_list = NULL; + while ((c = getopt_long(argc, argv, "?hr:R:t:T:i:e:f:o:O:g:s:S:p:qc:ln:",loptions,NULL)) >= 0) + { + switch (c) + { + case 'l': args->local_csq = 1; break; + case 'c': args->bcsq_tag = optarg; break; + case 'q': args->quiet++; break; + case 'p': + switch (optarg[0]) + { + case 'a': args->phase = PHASE_AS_IS; break; + case 'm': args->phase = PHASE_MERGE; break; + case 'r': args->phase = PHASE_REQUIRE; break; + case 'R': args->phase = PHASE_NON_REF; break; + case 's': args->phase = PHASE_SKIP; break; + default: error("The -p code \"%s\" not recognised\n", optarg); + } + break; + case 'f': args->fa_fname = optarg; break; + case 'g': args->gff_fname = optarg; break; + case 'n': + args->ncsq_max = 2 * atoi(optarg); + if ( args->ncsq_max <=0 ) error("Expected positive integer with -n, got %s\n", optarg); + break; + case 'o': args->output_fname = optarg; break; + case 'O': + switch (optarg[0]) { + case 't': args->output_type = FT_TAB_TEXT; break; + case 'b': args->output_type = FT_BCF_GZ; break; + case 'u': args->output_type = FT_BCF; break; + case 'z': args->output_type = FT_VCF_GZ; break; + case 'v': args->output_type = FT_VCF; break; + default: error("The output type \"%s\" not recognised\n", optarg); + } + break; + case 'e': args->filter_str = optarg; args->filter_logic |= FLT_EXCLUDE; break; + case 'i': args->filter_str = optarg; args->filter_logic |= FLT_INCLUDE; break; + case 'r': regions_list = optarg; break; + case 'R': regions_list = optarg; regions_is_file = 1; break; + case 's': args->sample_list = optarg; break; + case 'S': args->sample_list = optarg; args->sample_is_file = 1; break; + case 't': targets_list = optarg; break; + case 'T': targets_list = optarg; targets_is_file = 1; break; + case 'h': + case '?': error("%s",usage()); + default: error("The option not recognised: %s\n\n", optarg); break; + } + } + char *fname = NULL; + if ( optind==argc ) + { + if ( !isatty(fileno((FILE *)stdin)) ) fname = "-"; // reading from stdin + else error("%s", usage()); + } + else fname = argv[optind]; + if ( argc - optind>1 ) error("%s", usage()); + if ( !args->fa_fname ) error("Missing the --fa-ref option\n"); + if ( !args->gff_fname ) error("Missing the --gff option\n"); + args->sr = bcf_sr_init(); + if ( targets_list && bcf_sr_set_targets(args->sr, targets_list, targets_is_file, 0)<0 ) + error("Failed to read the targets: %s\n", targets_list); + if ( regions_list && bcf_sr_set_regions(args->sr, regions_list, regions_is_file)<0 ) + error("Failed to read the regions: %s\n", regions_list); + if ( !bcf_sr_add_reader(args->sr, fname) ) + error("Failed to open %s: %s\n", fname,bcf_sr_strerror(args->sr->errnum)); + args->hdr = bcf_sr_get_header(args->sr,0); + + init_data(args); + while ( bcf_sr_next_line(args->sr) ) + { + process(args, &args->sr->readers[0].buffer[0]); + } + process(args,NULL); + + destroy_data(args); + bcf_sr_destroy(args->sr); + free(args); + + return 0; +} + diff --git a/bcftools/csq.c.pysam.c b/bcftools/csq.c.pysam.c new file mode 100644 index 000000000..e4afa8ea3 --- /dev/null +++ b/bcftools/csq.c.pysam.c @@ -0,0 +1,3846 @@ +#include "bcftools.pysam.h" + +/* The MIT License + + Copyright (c) 2016-2018 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ +/* + Things that would be nice to have + - for stop-lost events (also in frameshifts) report the number of truncated aa's + - memory could be greatly reduced by indexing gff (but it is quite compact already) + - deletions that go beyond transcript boundaries are not checked at sequence level + - alloc tscript->ref in hap_finalize, introduce fa_off_beg:16,fa_off_end:16 + - see test/csq/ENST00000573314/insertion-overlap.vcf #1476288882 + + Read about transcript types here + http://vega.sanger.ac.uk/info/about/gene_and_transcript_types.html + http://www.ensembl.org/info/genome/variation/predicted_data.html + http://www.gencodegenes.org/gencode_biotypes.html + + List of supported biotypes + antisense + IG_C_gene + IG_D_gene + IG_J_gene + IG_LV_gene + IG_V_gene + lincRNA + macro_lncRNA + miRNA + misc_RNA + Mt_rRNA + Mt_tRNA + polymorphic_pseudogene + processed_transcript + protein_coding + ribozyme + rRNA + sRNA + scRNA + scaRNA + sense_intronic + sense_overlapping + snRNA + snoRNA + TR_C_gene + TR_D_gene + TR_J_gene + TR_V_gene + + The gff parsing logic + We collect features such by combining gff lines A,B,C as follows: + A .. gene line with a supported biotype + A.ID=~/^gene:/ + + B .. transcript line referencing A + B.ID=~/^transcript:/ && B.Parent=~/^gene:A.ID/ + + C .. corresponding CDS, exon, and UTR lines: + C[3] in {"CDS","exon","three_prime_UTR","five_prime_UTR"} && C.Parent=~/^transcript:B.ID/ + + For coding biotypes ("protein_coding" or "polymorphic_pseudogene") the + complete chain link C -> B -> A is required. For the rest, link B -> A suffices. + + + The supported consequence types, sorted by impact: + splice_acceptor_variant .. end region of an intron changed (2bp at the 3' end of an intron) + splice_donor_variant .. start region of an intron changed (2bp at the 5' end of an intron) + stop_gained .. DNA sequence variant resulting in a stop codon + frameshift_variant .. number of inserted/deleted bases not a multiple of three, disrupted translational frame + stop_lost .. elongated transcript, stop codon changed + start_lost .. the first codon changed + inframe_altering .. combination of indels leading to unchanged reading frame and length + inframe_insertion .. inserted coding sequence, unchanged reading frame + inframe_deletion .. deleted coding sequence, unchanged reading frame + missense_variant .. amino acid (aa) change, unchanged length + splice_region_variant .. change within 1-3 bases of the exon or 3-8 bases of the intron + synonymous_variant .. DNA sequence variant resulting in no amino acid change + stop_retained_variant .. different stop codon + non_coding_variant .. variant in non-coding sequence, such as RNA gene + 5_prime_UTR_variant + 3_prime_UTR_variant + intron_variant .. reported only if none of the above + intergenic_variant .. reported only if none of the above + + + The annotation algorithm. + The algorithm checks if the variant falls in a region of a supported type. The + search is performed in the following order, until a match is found: + 1. idx_cds(gf_cds_t) - lookup CDS by position, create haplotypes, call consequences + 2. idx_utr(gf_utr_t) - check UTR hits + 3. idx_exon(gf_exon_t) - check for splice variants + 4. idx_tscript(tscript_t) - check for intronic variants, RNAs, etc. + + These regidx indexes are created by parsing a gff3 file as follows: + 1. create the array "ftr" of all UTR, CDS, exons. This will be + processed later and pruned based on transcript types we want to keep. + In the same go, create the hash "id2tr" of transcripts to keep + (based on biotype) which maps from transcript_id to a transcript. At + the same time also build the hash "gid2gene" which maps from gene_id to + gf_gene_t pointer. + + 2. build "idx_cds", "idx_tscript", "idx_utr" and "idx_exon" indexes. + Use only features from "ftr" which are present in "id2tr". + + 3. clean data that won't be needed anymore: ftr, id2tr, gid2gene. + + Data structures. + idx_cds, idx_utr, idx_exon, idx_tscript: + as described above, regidx structures for fast lookup of exons/transcripts + overlapping a region, the payload is a pointer to tscript.cds +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "bcftools.h" +#include "filter.h" +#include "regidx.h" +#include "kheap.h" +#include "smpl_ilist.h" +#include "rbuf.h" + +#ifndef __FUNCTION__ +# define __FUNCTION__ __func__ +#endif + +// Logic of the filters: include or exclude sites which match the filters? +#define FLT_INCLUDE 1 +#define FLT_EXCLUDE 2 + +// Definition of splice_region, splice_acceptor and splice_donor +#define N_SPLICE_DONOR 2 +#define N_SPLICE_REGION_EXON 3 +#define N_SPLICE_REGION_INTRON 8 + +#define N_REF_PAD 10 // number of bases to avoid boundary effects + +#define STRAND_REV 0 +#define STRAND_FWD 1 + +#define TRIM_NONE 0 +#define TRIM_5PRIME 1 +#define TRIM_3PRIME 2 + +// How to treat phased/unphased genotypes +#define PHASE_REQUIRE 0 // --phase r +#define PHASE_MERGE 1 // --phase m +#define PHASE_AS_IS 2 // --phase a +#define PHASE_SKIP 3 // --phase s +#define PHASE_NON_REF 4 // --phase R +#define PHASE_DROP_GT 5 // --samples - + +// Node types in the haplotype tree +#define HAP_CDS 0 +#define HAP_ROOT 1 +#define HAP_SSS 2 // start/stop/splice + +#define CSQ_PRINTED_UPSTREAM (1<<0) +#define CSQ_SYNONYMOUS_VARIANT (1<<1) +#define CSQ_MISSENSE_VARIANT (1<<2) +#define CSQ_STOP_LOST (1<<3) +#define CSQ_STOP_GAINED (1<<4) +#define CSQ_INFRAME_DELETION (1<<5) +#define CSQ_INFRAME_INSERTION (1<<6) +#define CSQ_FRAMESHIFT_VARIANT (1<<7) +#define CSQ_SPLICE_ACCEPTOR (1<<8) +#define CSQ_SPLICE_DONOR (1<<9) +#define CSQ_START_LOST (1<<10) +#define CSQ_SPLICE_REGION (1<<11) +#define CSQ_STOP_RETAINED (1<<12) +#define CSQ_UTR5 (1<<13) +#define CSQ_UTR3 (1<<14) +#define CSQ_NON_CODING (1<<15) +#define CSQ_INTRON (1<<16) +//#define CSQ_INTERGENIC (1<<17) +#define CSQ_INFRAME_ALTERING (1<<18) +#define CSQ_UPSTREAM_STOP (1<<19) // adds * in front of the csq string +#define CSQ_INCOMPLETE_CDS (1<<20) // to remove START/STOP in incomplete CDS, see ENSG00000173376/synon.vcf +#define CSQ_CODING_SEQUENCE (1<<21) // cannot tell exactly what it is, but it does affect the coding sequence + +// Haplotype-aware consequences, printed in one vcf record only, the rest has a reference @12345 +#define CSQ_COMPOUND (CSQ_SYNONYMOUS_VARIANT|CSQ_MISSENSE_VARIANT|CSQ_STOP_LOST|CSQ_STOP_GAINED| \ + CSQ_INFRAME_DELETION|CSQ_INFRAME_INSERTION|CSQ_FRAMESHIFT_VARIANT| \ + CSQ_START_LOST|CSQ_STOP_RETAINED|CSQ_INFRAME_ALTERING|CSQ_INCOMPLETE_CDS| \ + CSQ_UPSTREAM_STOP) +#define CSQ_START_STOP (CSQ_STOP_LOST|CSQ_STOP_GAINED|CSQ_STOP_RETAINED|CSQ_START_LOST) + +#define CSQ_PRN_STRAND(csq) ((csq)&CSQ_COMPOUND && !((csq)&(CSQ_SPLICE_ACCEPTOR|CSQ_SPLICE_DONOR|CSQ_SPLICE_REGION))) +#define CSQ_PRN_TSCRIPT (~(CSQ_INTRON|CSQ_NON_CODING)) +#define CSQ_PRN_BIOTYPE CSQ_NON_CODING + +// see kput_vcsq() +const char *csq_strings[] = +{ + NULL, + "synonymous", + "missense", + "stop_lost", + "stop_gained", + "inframe_deletion", + "inframe_insertion", + "frameshift", + "splice_acceptor", + "splice_donor", + "start_lost", + "splice_region", + "stop_retained", + "5_prime_utr", + "3_prime_utr", + "non_coding", + "intron", + "intergenic", + "inframe_altering", + NULL, + NULL, + "coding_sequence" +}; + + +// GFF line types +#define GFF_TSCRIPT_LINE 1 +#define GFF_GENE_LINE 2 + + +/* + Genomic features, for fast lookup by position to overlapping features +*/ +#define GF_coding_bit 6 +#define GF_is_coding(x) ((x) & (1<5I|121ACG>A+124TA>T" + + vcrec_t + single VCF record and csq tied to this record. (Haplotype can have multiple + consequences in several VCF records. Each record can have multiple consequences + from multiple haplotypes.) + + csq_t + a top-level consequence tied to a haplotype + + vbuf_t + pos2vbuf + VCF records with the same position clustered together for a fast lookup via pos2vbuf +*/ +typedef struct _vbuf_t vbuf_t; +typedef struct _vcsq_t vcsq_t; +struct _vcsq_t +{ + uint32_t strand:1, + type:31; // one of CSQ_* types + uint32_t trid; + uint32_t biotype; // one of GF_* types + char *gene; // gene name + bcf1_t *ref; // if type&CSQ_PRINTED_UPSTREAM, ref consequence "@1234" + kstring_t vstr; // variant string, eg 5TY>5I|121ACG>A+124TA>T +}; +typedef struct +{ + bcf1_t *line; + uint32_t *smpl; // bitmask of sample consequences with first/second haplotype interleaved + uint32_t nfmt:4, nvcsq:28, mvcsq; + vcsq_t *vcsq; // there can be multiple consequences for a single VCF record +} +vrec_t; +typedef struct +{ + uint32_t pos; + vrec_t *vrec; // vcf line that this csq is tied to; needed when printing haplotypes (hap_stage_vcf) + int idx; // 0-based index of the csq at the VCF line, for FMT/BCSQ + vcsq_t type; +} +csq_t; +struct _vbuf_t +{ + vrec_t **vrec; // buffer of VCF lines with the same position + int n, m; +}; +KHASH_MAP_INIT_INT(pos2vbuf, vbuf_t*) + + +/* + Structures related to haplotype-aware consequences in coding regions + + hap_node_t + node of a haplotype tree. Each transcript has one tree + + tscript_t + despite its general name, it is intended for coding transcripts only + + hap_t + hstack_t + for traversal of the haplotype tree and braking combined + consequences into independent parts +*/ +typedef struct _hap_node_t hap_node_t; +struct _hap_node_t +{ + char *seq; // cds segment [parent_node,this_node) + char *var; // variant "ref>alt" + uint32_t type:2, // HAP_ROOT or HAP_CDS + csq:30; // this node's consequence + int dlen; // alt minus ref length: <0 del, >0 ins, 0 substitution + uint32_t rbeg; // variant's VCF position (0-based, inclusive) + int32_t rlen; // variant's rlen; alen=rlen+dlen; fake for non CDS types + uint32_t sbeg; // variant's position on the spliced reference transcript (0-based, inclusive, N_REF_PAD not included) + uint32_t icds; // which exon does this node's variant overlaps + hap_node_t **child, *prev; // children haplotypes and previous coding node + int nchild, mchild; + bcf1_t *cur_rec, *rec; // current VCF record and node's VCF record + uint32_t nend; // number of haplotypes ending in this node + int *cur_child, mcur_child; // mapping from the allele to the currently active child + csq_t *csq_list; // list of haplotype's consequences, broken by position + int ncsq_list, mcsq_list; +}; +struct _tscript_t +{ + uint32_t id; // transcript id + uint32_t beg,end; // transcript's beg and end coordinate (ref strand, 0-based, inclusive) + uint32_t strand:1, // STRAND_REV or STRAND_FWD + ncds:31, // number of exons + mcds; + gf_cds_t **cds; // ordered list of exons + char *ref; // reference sequence, padded with N_REF_PAD bases on both ends + char *sref; // spliced reference sequence, padded with N_REF_PAD bases on both ends + hap_node_t *root; // root of the haplotype tree + hap_node_t **hap; // pointer to haplotype leaves, two for each sample + int nhap, nsref; // number of haplotypes and length of sref, including 2*N_REF_PAD + uint32_t trim:2, // complete, 5' or 3' trimmed, see TRIM_* types + type:30; // one of GF_* types + gf_gene_t *gene; +}; +static inline int cmp_tscript(tscript_t **a, tscript_t **b) +{ + return ( (*a)->end < (*b)->end ) ? 1 : 0; +} +KHEAP_INIT(trhp, tscript_t*, cmp_tscript) +typedef khp_trhp_t tr_heap_t; +typedef struct +{ + hap_node_t *node; // current node + int ichild; // current child in the active node + int dlen; // total dlen, from the root to the active node + size_t slen; // total sequence length, from the root to the active node +} +hstack_t; +typedef struct +{ + int mstack; + hstack_t *stack; + tscript_t *tr; // tr->ref: spliced transcript on ref strand + kstring_t sseq; // spliced haplotype sequence on ref strand + kstring_t tseq; // the variable part of translated haplotype transcript, coding strand + kstring_t tref; // the variable part of translated reference transcript, coding strand + uint32_t sbeg; // stack's sbeg, for cases first node's type is HAP_SSS + int upstream_stop; +} +hap_t; + + +/* + Helper structures, only for initialization + + ftr_t + temporary list of all exons, CDS, UTRs +*/ +KHASH_MAP_INIT_INT(int2tscript, tscript_t*) +KHASH_MAP_INIT_INT(int2gene, gf_gene_t*) +typedef struct +{ + int type; // GF_CDS, GF_EXON, GF_5UTR, GF_3UTR + uint32_t beg; + uint32_t end; + uint32_t trid; + uint32_t strand:1; // STRAND_REV,STRAND_FWD + uint32_t phase:2; // 0, 1 or 2 + uint32_t iseq:29; +} +ftr_t; +/* + Mapping from GFF ID string (such as ENST00000450305 or Zm00001d027230_P001) + to integer id. To keep the memory requirements low, the original version + relied on IDs in the form of a string prefix and a numerical id. However, + it turns out that this assumption is not valid for some ensembl GFFs, see + for example Zea_mays.AGPv4.36.gff3.gz + */ +typedef struct +{ + void *str2id; // khash_str2int + int nstr, mstr; + char **str; // numeric id to string +} +id_tbl_t; +typedef struct +{ + // all exons, CDS, UTRs + ftr_t *ftr; + int nftr, mftr; + + // mapping from gene id to gf_gene_t + kh_int2gene_t *gid2gene; + + // mapping from transcript id to tscript, for quick CDS anchoring + kh_int2tscript_t *id2tr; + + // sequences + void *seq2int; // str2int hash + char **seq; + int nseq, mseq; + + // ignored biotypes + void *ignored_biotypes; + + id_tbl_t gene_ids; // temporary table for mapping between gene id (eg. Zm00001d027245) and a numeric idx +} +aux_t; + +typedef struct _args_t +{ + // the main regidx lookups, from chr:beg-end to overlapping features and + // index iterator + regidx_t *idx_cds, *idx_utr, *idx_exon, *idx_tscript; + regitr_t *itr; + + // temporary structures, deleted after initializtion + aux_t init; + + // text tab-delimited output (out) or vcf/bcf output (out_fh) + FILE *out; + htsFile *out_fh; + + // vcf + bcf_srs_t *sr; + bcf_hdr_t *hdr; + int hdr_nsmpl; // actual number of samples in the vcf, for bcf_update_format_values() + + // include or exclude sites which match the filters + filter_t *filter; + char *filter_str; + int filter_logic; // FLT_INCLUDE or FLT_EXCLUDE + + // samples to process + int sample_is_file; + char *sample_list; + smpl_ilist_t *smpl; + + char *outdir, **argv, *fa_fname, *gff_fname, *output_fname; + char *bcsq_tag; + int argc, output_type; + int phase, quiet, local_csq; + int ncsq_max, nfmt_bcsq; // maximum number of csq per site that can be accessed from FORMAT/BCSQ + int ncsq_small_warned; + + int rid; // current chromosome + tr_heap_t *active_tr; // heap of active transcripts for quick flushing + hap_t *hap; // transcript haplotype recursion + vbuf_t **vcf_buf; // buffered VCF lines to annotate with CSQ and flush + rbuf_t vcf_rbuf; // round buffer indexes to vcf_buf + kh_pos2vbuf_t *pos2vbuf; // fast lookup of buffered lines by position + tscript_t **rm_tr; // buffer of transcripts to clean + int nrm_tr, mrm_tr; + csq_t *csq_buf; // pool of csq not managed by hap_node_t, i.e. non-CDS csqs + int ncsq_buf, mcsq_buf; + id_tbl_t tscript_ids; // mapping between transcript id (eg. Zm00001d027245_T001) and a numeric idx + + faidx_t *fai; + kstring_t str, str2; + int32_t *gt_arr, mgt_arr; +} +args_t; + +// AAA, AAC, ... +const char *gencode = "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSS*CWCLFLF"; +const uint8_t nt4[] = +{ + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,0,4,1, 4,4,4,2, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 3,4,4,4, 4,4,4,4, 4,4,4,4, + 4,0,4,1, 4,4,4,2, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 3 +}; +const uint8_t cnt4[] = +{ + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 4,4,4,4, 4,4,4,4, 4,4,4,4, + 4,3,4,2, 4,4,4,1, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 0,4,4,4, 4,4,4,4, 4,4,4,4, + 4,3,4,2, 4,4,4,1, 4,4,4,4, 4,4,4,4, + 4,4,4,4, 0 +}; +#define dna2aa(x) gencode[ nt4[(uint8_t)(x)[0]]<<4 | nt4[(uint8_t)(x)[1]]<<2 | nt4[(uint8_t)(x)[2]] ] +#define cdna2aa(x) gencode[ cnt4[(uint8_t)(x)[2]]<<4 | cnt4[(uint8_t)(x)[1]]<<2 | cnt4[(uint8_t)(x)[0]] ] + +static const char *gf_strings_noncoding[] = +{ + "MT_rRNA", "MT_tRNA", "lincRNA", "miRNA", "misc_RNA", "rRNA", "snRNA", "snoRNA", "processed_transcript", + "antisense", "macro_lncRNA", "ribozyme", "sRNA", "scRNA", "scaRNA", "sense_intronic", "sense_overlapping", + "pseudogene", "processed_pseudogene", "artifact", "IG_pseudogene", "IG_C_pseudogene", "IG_J_pseudogene", + "IG_V_pseudogene", "TR_V_pseudogene", "TR_J_pseudogene", "MT_tRNA_pseudogene", "misc_RNA_pseudogene", + "miRNA_pseudogene", "ribozyme", "retained_intron", "retrotransposed", "Trna_pseudogene", "transcribed_processed_pseudogene", + "transcribed_unprocessed_pseudogene", "transcribed_unitary_pseudogene", "translated_unprocessed_pseudogene", + "translated_processed_pseudogene", "known_ncRNA", "unitary_pseudogene", "unprocessed_pseudogene", + "LRG_gene", "3_prime_overlapping_ncRNA", "disrupted_domain", "vaultRNA", "bidirectional_promoter_lncRNA", "ambiguous_orf" +}; +static const char *gf_strings_coding[] = { "protein_coding", "polymorphic_pseudogene", "IG_C", "IG_D", "IG_J", "IG_LV", "IG_V", "TR_C", "TR_D", "TR_J", "TR_V", "NMD", "non_stop_decay"}; +static const char *gf_strings_special[] = { "CDS", "exon", "3_prime_UTR", "5_prime_UTR" }; + +const char *gf_type2gff_string(int type) +{ + if ( !GF_is_coding(type) ) + { + if ( type < (1<init; + char c = chr_end[1]; + chr_end[1] = 0; + int iseq; + if ( khash_str2int_get(aux->seq2int, chr_beg, &iseq)!=0 ) + { + hts_expand(char*, aux->nseq+1, aux->mseq, aux->seq); + aux->seq[aux->nseq] = strdup(chr_beg); + iseq = khash_str2int_inc(aux->seq2int, aux->seq[aux->nseq]); + aux->nseq++; + assert( aux->nseq < 256 ); // see gf_gene_t.iseq + } + chr_end[1] = c; + return iseq; +} +static inline char *gff_skip(const char *line, char *ss) +{ + while ( *ss && *ss!='\t' ) ss++; + if ( !*ss ) error("[%s:%d %s] Could not parse the line: %s\n",__FILE__,__LINE__,__FUNCTION__,line); + return ss+1; +} +static inline void gff_parse_chr(const char *line, char **chr_beg, char **chr_end) +{ + char *se = (char*) line; + while ( *se && *se!='\t' ) se++; + if ( !*se ) error("[%s:%d %s] Could not parse the line: %s\n",__FILE__,__LINE__,__FUNCTION__,line); + *chr_beg = (char*) line; + *chr_end = se-1; +} +static inline char *gff_parse_beg_end(const char *line, char *ss, uint32_t *beg, uint32_t *end) +{ + char *se = ss; + *beg = strtol(ss, &se, 10) - 1; + if ( ss==se ) error("[%s:%d %s] Could not parse the line:\n\t%s\n\t%s\n",__FILE__,__LINE__,__FUNCTION__,line,ss); + ss = se+1; + *end = strtol(ss, &se, 10) - 1; + if ( ss==se ) error("[%s:%d %s] Could not parse the line: %s\n",__FILE__,__LINE__,__FUNCTION__,line); + return se+1; +} +static void gff_id_init(id_tbl_t *tbl) +{ + memset(tbl, 0, sizeof(*tbl)); + tbl->str2id = khash_str2int_init(); +} +static void gff_id_destroy(id_tbl_t *tbl) +{ + khash_str2int_destroy_free(tbl->str2id); + free(tbl->str); +} +static inline uint32_t gff_id_parse(id_tbl_t *tbl, const char *line, const char *needle, char *ss) +{ + ss = strstr(ss,needle); // e.g. "ID=transcript:" + if ( !ss ) error("[%s:%d %s] Could not parse the line, \"%s\" not present: %s\n",__FILE__,__LINE__,__FUNCTION__,needle,line); + ss += strlen(needle); + + char *se = ss; + while ( *se && *se!=';' && !isspace(*se) ) se++; + char tmp = *se; + *se = 0; + + int id; + if ( khash_str2int_get(tbl->str2id, ss, &id) < 0 ) + { + id = tbl->nstr++; + hts_expand(char*, tbl->nstr, tbl->mstr, tbl->str); + tbl->str[id] = strdup(ss); + khash_str2int_set(tbl->str2id, tbl->str[id], id); + } + *se = tmp; + + return id; +} +static inline int gff_parse_type(char *line) +{ + line = strstr(line,"ID="); + if ( !line ) return -1; + line += 3; + if ( !strncmp(line,"transcript:",11) ) return GFF_TSCRIPT_LINE; + else if ( !strncmp(line,"gene:",5) ) return GFF_GENE_LINE; + return -1; +} +static inline int gff_parse_biotype(char *_line) +{ + char *line = strstr(_line,"biotype="); + if ( !line ) return -1; + + line += 8; + switch (*line) + { + case 'p': + if ( !strncmp(line,"protein_coding",14) ) return GF_PROTEIN_CODING; + else if ( !strncmp(line,"pseudogene",10) ) return GF_PSEUDOGENE; + else if ( !strncmp(line,"processed_transcript",20) ) return GF_PROCESSED_TRANSCRIPT; + else if ( !strncmp(line,"processed_pseudogene",20) ) return GF_PROCESSED_PSEUDOGENE; + else if ( !strncmp(line,"polymorphic_pseudogene",22) ) return GF_POLYMORPHIC_PSEUDOGENE; + break; + case 'a': + if ( !strncmp(line,"artifact",8) ) return GF_ARTIFACT; + else if ( !strncmp(line,"antisense",9) ) return GF_ANTISENSE; + else if ( !strncmp(line,"ambiguous_orf",13) ) return GF_AMBIGUOUS_ORF; + break; + case 'I': + if ( !strncmp(line,"IG_C_gene",9) ) return GF_IG_C; + else if ( !strncmp(line,"IG_D_gene",9) ) return GF_IG_D; + else if ( !strncmp(line,"IG_J_gene",9) ) return GF_IG_J; + else if ( !strncmp(line,"IG_LV_gene",10) ) return GF_IG_LV; + else if ( !strncmp(line,"IG_V_gene",9) ) return GF_IG_V; + else if ( !strncmp(line,"IG_pseudogene",13) ) return GF_IG_PSEUDOGENE; + else if ( !strncmp(line,"IG_C_pseudogene",15) ) return GF_IG_C_PSEUDOGENE; + else if ( !strncmp(line,"IG_J_pseudogene",15) ) return GF_IG_J_PSEUDOGENE; + else if ( !strncmp(line,"IG_V_pseudogene",15) ) return GF_IG_V_PSEUDOGENE; + break; + case 'T': + if ( !strncmp(line,"TR_C_gene",9) ) return GF_TR_C; + else if ( !strncmp(line,"TR_D_gene",9) ) return GF_TR_D; + else if ( !strncmp(line,"TR_J_gene",9) ) return GF_TR_J; + else if ( !strncmp(line,"TR_V_gene",9) ) return GF_TR_V; + else if ( !strncmp(line,"TR_V_pseudogene",15) ) return GF_TR_V_PSEUDOGENE; + else if ( !strncmp(line,"TR_J_pseudogene",15) ) return GF_TR_J_PSEUDOGENE; + break; + case 'M': + if ( !strncmp(line,"Mt_tRNA_pseudogene",18) ) return GF_MT_tRNA_PSEUDOGENE; + else if ( !strncmp(line,"Mt_tRNA",7) ) return GF_MT_tRNA; + else if ( !strncmp(line,"Mt_rRNA",7) ) return GF_MT_tRNA; + break; + case 'l': + if ( !strncmp(line,"lincRNA",7) ) return GF_lincRNA; + break; + case 'm': + if ( !strncmp(line,"macro_lncRNA",12) ) return GF_macro_lncRNA; + else if ( !strncmp(line,"misc_RNA_pseudogene",19) ) return GF_misc_RNA_PSEUDOGENE; + else if ( !strncmp(line,"miRNA_pseudogene",16) ) return GF_miRNA_PSEUDOGENE; + else if ( !strncmp(line,"miRNA",5) ) return GF_miRNA; + else if ( !strncmp(line,"misc_RNA",8) ) return GF_MISC_RNA; + break; + case 'r': + if ( !strncmp(line,"rRNA",4) ) return GF_rRNA; + else if ( !strncmp(line,"ribozyme",8) ) return GF_RIBOZYME; + else if ( !strncmp(line,"retained_intron",15) ) return GF_RETAINED_INTRON; + else if ( !strncmp(line,"retrotransposed",15) ) return GF_RETROTRANSPOSED; + break; + case 's': + if ( !strncmp(line,"snRNA",5) ) return GF_snRNA; + else if ( !strncmp(line,"sRNA",4) ) return GF_sRNA; + else if ( !strncmp(line,"scRNA",5) ) return GF_scRNA; + else if ( !strncmp(line,"scaRNA",6) ) return GF_scaRNA; + else if ( !strncmp(line,"snoRNA",6) ) return GF_snoRNA; + else if ( !strncmp(line,"sense_intronic",14) ) return GF_SENSE_INTRONIC; + else if ( !strncmp(line,"sense_overlapping",17) ) return GF_SENSE_OVERLAPPING; + break; + case 't': + if ( !strncmp(line,"tRNA_pseudogene",15) ) return GF_tRNA_PSEUDOGENE; + else if ( !strncmp(line,"transcribed_processed_pseudogene",32) ) return GF_TRANSCRIBED_PROCESSED_PSEUDOGENE; + else if ( !strncmp(line,"transcribed_unprocessed_pseudogene",34) ) return GF_TRANSCRIBED_UNPROCESSED_PSEUDOGENE; + else if ( !strncmp(line,"transcribed_unitary_pseudogene",30) ) return GF_TRANSCRIBED_UNITARY_PSEUDOGENE; + else if ( !strncmp(line,"translated_unprocessed_pseudogene",33) ) return GF_TRANSLATED_UNPROCESSED_PSEUDOGENE; + else if ( !strncmp(line,"translated_processed_pseudogene",31) ) return GF_TRANSLATED_PROCESSED_PSEUDOGENE; + break; + case 'n': + if ( !strncmp(line,"nonsense_mediated_decay",23) ) return GF_NMD; + else if ( !strncmp(line,"non_stop_decay",14) ) return GF_NON_STOP_DECAY; + break; + case 'k': + if ( !strncmp(line,"known_ncrna",11) ) return GF_KNOWN_NCRNA; + break; + case 'u': + if ( !strncmp(line,"unitary_pseudogene",18) ) return GF_UNITARY_PSEUDOGENE; + else if ( !strncmp(line,"unprocessed_pseudogene",22) ) return GF_UNPROCESSED_PSEUDOGENE; + break; + case 'L': + if ( !strncmp(line,"LRG_gene",8) ) return GF_LRG_GENE; + break; + case '3': + if ( !strncmp(line,"3prime_overlapping_ncRNA",24) ) return GF_3PRIME_OVERLAPPING_ncRNA; + break; + case 'd': + if ( !strncmp(line,"disrupted_domain",16) ) return GF_DISRUPTED_DOMAIN; + break; + case 'v': + if ( !strncmp(line,"vaultRNA",8) ) return GF_vaultRNA; + break; + case 'b': + if ( !strncmp(line,"bidirectional_promoter_lncRNA",29) ) return GF_BIDIRECTIONAL_PROMOTER_lncRNA; + break; + } + return 0; +} +static inline int gff_ignored_biotype(args_t *args, char *ss) +{ + ss = strstr(ss,"biotype="); + if ( !ss ) return 0; + + ss += 8; + char *se = ss, tmp; + while ( *se && *se!=';' ) se++; + tmp = *se; + *se = 0; + + char *key = ss; + int n = 0; + if ( khash_str2int_get(args->init.ignored_biotypes, ss, &n)!=0 ) key = strdup(ss); + khash_str2int_set(args->init.ignored_biotypes, key, n+1); + + *se = tmp; + return 1; +} +gf_gene_t *gene_init(aux_t *aux, uint32_t gene_id) +{ + khint_t k = kh_get(int2gene, aux->gid2gene, (int)gene_id); + gf_gene_t *gene = (k == kh_end(aux->gid2gene)) ? NULL : kh_val(aux->gid2gene, k); + if ( !gene ) + { + gene = (gf_gene_t*) calloc(1,sizeof(gf_gene_t)); + int ret; + k = kh_put(int2gene, aux->gid2gene, (int)gene_id, &ret); + kh_val(aux->gid2gene,k) = gene; + } + return gene; +} +void gff_parse_transcript(args_t *args, const char *line, char *ss, ftr_t *ftr) +{ + aux_t *aux = &args->init; + int biotype = gff_parse_biotype(ss); + if ( biotype <= 0 ) + { + if ( !gff_ignored_biotype(args, ss) && args->quiet<2 ) fprintf(bcftools_stderr,"ignored transcript: %s\n",line); + return; + } + + // create a mapping from transcript_id to gene_id + uint32_t trid = gff_id_parse(&args->tscript_ids, line, "ID=transcript:", ss); + uint32_t gene_id = gff_id_parse(&args->init.gene_ids, line, "Parent=gene:", ss); + + tscript_t *tr = (tscript_t*) calloc(1,sizeof(tscript_t)); + tr->id = trid; + tr->strand = ftr->strand; + tr->gene = gene_init(aux, gene_id); + tr->type = biotype; + tr->beg = ftr->beg; + tr->end = ftr->end; + + khint_t k; + int ret; + k = kh_put(int2tscript, aux->id2tr, (int)trid, &ret); + kh_val(aux->id2tr,k) = tr; +} +void gff_parse_gene(args_t *args, const char *line, char *ss, char *chr_beg, char *chr_end, ftr_t *ftr) +{ + int biotype = gff_parse_biotype(ss); + if ( biotype <= 0 ) + { + if ( !gff_ignored_biotype(args, ss) && args->quiet<2 ) fprintf(bcftools_stderr,"ignored gene: %s\n",line); + return; + } + + aux_t *aux = &args->init; + + // substring search for "ID=gene:ENSG00000437963" + uint32_t gene_id = gff_id_parse(&aux->gene_ids, line, "ID=gene:", ss); + gf_gene_t *gene = gene_init(aux, gene_id); + assert( !gene->name ); // the gene_id should be unique + + gene->iseq = feature_set_seq(args, chr_beg,chr_end); + + // substring search for "Name=OR4F5" + ss = strstr(chr_end+2,"Name="); + if ( ss ) + { + ss += 5; + char *se = ss; + while ( *se && *se!=';' && !isspace(*se) ) se++; + gene->name = (char*) malloc(se-ss+1); + memcpy(gene->name,ss,se-ss); + gene->name[se-ss] = 0; + } + else + gene->name = strdup(aux->gene_ids.str[gene_id]); // Name= field is not present, use the gene ID instead +} +int gff_parse(args_t *args, char *line, ftr_t *ftr) +{ + // - skip empty lines and commented lines + // - columns + // 1. chr + // 2. + // 3. CDS, transcript, gene, ... + // 4-5. beg,end + // 6. + // 7. strand + // 8. phase + // 9. Parent=transcript:ENST(\d+);ID=... etc + + char *ss = line; + if ( !*ss ) return -1; // skip blank lines + if ( *ss=='#' ) return -1; // skip comments + + char *chr_beg, *chr_end; + gff_parse_chr(line, &chr_beg, &chr_end); + ss = gff_skip(line, chr_end + 2); + + // 3. column: is this a CDS, transcript, gene, etc. + if ( !strncmp("exon\t",ss,5) ) { ftr->type = GF_EXON; ss += 5; } + else if ( !strncmp("CDS\t",ss,4) ) { ftr->type = GF_CDS; ss += 4; } + else if ( !strncmp("three_prime_UTR\t",ss,16) ) { ftr->type = GF_UTR3; ss += 16; } + else if ( !strncmp("five_prime_UTR\t",ss,15) ) { ftr->type = GF_UTR5; ss += 15; } + else + { + ss = gff_skip(line, ss); + ss = gff_parse_beg_end(line, ss, &ftr->beg,&ftr->end); + ss = gff_skip(line, ss); + int type = gff_parse_type(ss); + if ( type!=GFF_TSCRIPT_LINE && type!=GFF_GENE_LINE ) + { + // we ignore these, debug print to see new types: + ss = strstr(ss,"ID="); + if ( !ss ) return -1; // no ID, ignore the line + if ( !strncmp("chromosome",ss+3,10) ) return -1; + if ( !strncmp("supercontig",ss+3,11) ) return -1; + if ( args->quiet<2 ) fprintf(bcftools_stderr,"ignored: %s\n", line); + return -1; + } + + // 7. column: strand + if ( *ss == '+' ) ftr->strand = STRAND_FWD; + else if ( *ss == '-' ) ftr->strand = STRAND_REV; + else error("Unknown strand: %c .. %s\n", *ss,ss); + + if ( type==GFF_TSCRIPT_LINE ) + gff_parse_transcript(args, line, ss, ftr); + else + gff_parse_gene(args, line, ss, chr_beg, chr_end, ftr); + + return -1; + } + ss = gff_parse_beg_end(line, ss, &ftr->beg,&ftr->end); + ss = gff_skip(line, ss); + + // 7. column: strand + if ( *ss == '+' ) ftr->strand = STRAND_FWD; + else if ( *ss == '-' ) ftr->strand = STRAND_REV; + else { if ( args->quiet<2 ) fprintf(bcftools_stderr,"Skipping unknown strand: %c\n", *ss); return -1; } + ss += 2; + + // 8. column: phase (codon offset) + if ( *ss == '0' ) ftr->phase = 0; + else if ( *ss == '1' ) ftr->phase = 1; + else if ( *ss == '2' ) ftr->phase = 2; + else if ( *ss == '.' ) ftr->phase = 0; // exons do not have phase + else { if ( args->quiet<2 ) fprintf(bcftools_stderr,"Skipping unknown phase: %c, %s\n", *ss, line); return -1; } + ss += 2; + + // substring search for "Parent=transcript:ENST00000437963" + ftr->trid = gff_id_parse(&args->tscript_ids, line, "Parent=transcript:", ss); + ftr->iseq = feature_set_seq(args, chr_beg,chr_end); + return 0; +} + +static int cmp_cds_ptr(const void *a, const void *b) +{ + // comparison function for qsort of transcripts's CDS + if ( (*((gf_cds_t**)a))->beg < (*((gf_cds_t**)b))->beg ) return -1; + if ( (*((gf_cds_t**)a))->beg > (*((gf_cds_t**)b))->beg ) return 1; + return 0; +} + +static inline void chr_beg_end(aux_t *aux, int iseq, char **chr_beg, char **chr_end) +{ + *chr_beg = *chr_end = aux->seq[iseq]; + while ( (*chr_end)[1] ) (*chr_end)++; +} +tscript_t *tscript_init(aux_t *aux, uint32_t trid) +{ + khint_t k = kh_get(int2tscript, aux->id2tr, (int)trid); + tscript_t *tr = (k == kh_end(aux->id2tr)) ? NULL : kh_val(aux->id2tr, k); + assert( tr ); + return tr; +} +void register_cds(args_t *args, ftr_t *ftr) +{ + // Make the CDS searchable via idx_cds. Note we do not malloc tr->cds just yet. + // ftr is the result of parsing a gff CDS line + aux_t *aux = &args->init; + + tscript_t *tr = tscript_init(aux, ftr->trid); + if ( tr->strand != ftr->strand ) error("Conflicting strand in transcript %"PRIu32" .. %d vs %d\n",ftr->trid,tr->strand,ftr->strand); + + gf_cds_t *cds = (gf_cds_t*) malloc(sizeof(gf_cds_t)); + cds->tr = tr; + cds->beg = ftr->beg; + cds->len = ftr->end - ftr->beg + 1; + cds->icds = 0; // to keep valgrind on mac happy + cds->phase = ftr->phase; + + hts_expand(gf_cds_t*,tr->ncds+1,tr->mcds,tr->cds); + tr->cds[tr->ncds++] = cds; +} +void register_utr(args_t *args, ftr_t *ftr) +{ + aux_t *aux = &args->init; + gf_utr_t *utr = (gf_utr_t*) malloc(sizeof(gf_utr_t)); + utr->which = ftr->type==GF_UTR3 ? prime3 : prime5; + utr->beg = ftr->beg; + utr->end = ftr->end; + utr->tr = tscript_init(aux, ftr->trid); + + char *chr_beg, *chr_end; + chr_beg_end(&args->init, utr->tr->gene->iseq, &chr_beg, &chr_end); + regidx_push(args->idx_utr, chr_beg,chr_end, utr->beg,utr->end, &utr); +} +void register_exon(args_t *args, ftr_t *ftr) +{ + aux_t *aux = &args->init; + gf_exon_t *exon = (gf_exon_t*) malloc(sizeof(gf_exon_t)); + exon->beg = ftr->beg; + exon->end = ftr->end; + exon->tr = tscript_init(aux, ftr->trid); + + char *chr_beg, *chr_end; + chr_beg_end(&args->init, exon->tr->gene->iseq, &chr_beg, &chr_end); + regidx_push(args->idx_exon, chr_beg,chr_end, exon->beg - N_SPLICE_REGION_INTRON, exon->end + N_SPLICE_REGION_INTRON, &exon); +} + +void tscript_init_cds(args_t *args) +{ + aux_t *aux = &args->init; + + // Sort CDS in all transcripts, set offsets, check their phase, length, create index (idx_cds) + khint_t k; + for (k=0; kid2tr); k++) + { + if ( !kh_exist(aux->id2tr, k) ) continue; + tscript_t *tr = (tscript_t*) kh_val(aux->id2tr, k); + + // position-to-tscript lookup + char *chr_beg, *chr_end; + chr_beg_end(aux, tr->gene->iseq, &chr_beg, &chr_end); + regidx_push(args->idx_tscript, chr_beg, chr_end, tr->beg, tr->end, &tr); + + if ( !tr->ncds ) continue; // transcript with no CDS + + // sort CDs + qsort(tr->cds, tr->ncds, sizeof(gf_cds_t*), cmp_cds_ptr); + + // trim non-coding start + int i, len = 0; + if ( tr->strand==STRAND_FWD ) + { + if ( tr->cds[0]->phase ) tr->trim |= TRIM_5PRIME; + tr->cds[0]->beg += tr->cds[0]->phase; + tr->cds[0]->len -= tr->cds[0]->phase; + tr->cds[0]->phase = 0; + + // sanity check phase + for (i=0; incds; i++) + { + int phase = tr->cds[i]->phase ? 3 - tr->cds[i]->phase : 0; + if ( phase!=len%3) + error("GFF3 assumption failed for transcript %s, CDS=%d: phase!=len%%3 (phase=%d, len=%d)\n",args->tscript_ids.str[tr->id],tr->cds[i]->beg+1,phase,len); + assert( phase == len%3 ); + len += tr->cds[i]->len; + } + } + else + { + // Check that the phase is not bigger than CDS length. Curiously, this can really happen, + // see Mus_musculus.GRCm38.85.gff3.gz, transcript:ENSMUST00000163141 + // todo: the same for the fwd strand + i = tr->ncds - 1; + int phase = tr->cds[i]->phase; + if ( phase ) tr->trim |= TRIM_5PRIME; + while ( i>=0 && phase > tr->cds[i]->len ) + { + phase -= tr->cds[i]->len; + tr->cds[i]->phase = 0; + tr->cds[i]->len = 0; + i--; + } + tr->cds[i]->len -= tr->cds[i]->phase; + tr->cds[i]->phase = 0; + + // sanity check phase + for (i=tr->ncds-1; i>=0; i--) + { + int phase = tr->cds[i]->phase ? 3 - tr->cds[i]->phase : 0; + if ( phase!=len%3) + error("GFF3 assumption failed for transcript %s, CDS=%d: phase!=len%%3 (phase=%d, len=%d)\n",args->tscript_ids.str[tr->id],tr->cds[i]->beg+1,phase,len); + len += tr->cds[i]->len; + } + } + + // set len. At the same check that CDS within a transcript do not overlap + len = 0; + for (i=0; incds; i++) + { + tr->cds[i]->icds = i; + len += tr->cds[i]->len; + if ( !i ) continue; + + gf_cds_t *a = tr->cds[i-1]; + gf_cds_t *b = tr->cds[i]; + if ( a->beg + a->len - 1 >= b->beg ) + error("Error: CDS overlap in the transcript %"PRIu32": %"PRIu32"-%"PRIu32" and %"PRIu32"-%"PRIu32"\n", + kh_key(aux->id2tr, k), a->beg+1,a->beg+a->len, b->beg+1,b->beg+b->len); + } + if ( len%3 != 0 ) + { + // There are 13k transcripts with incomplete 3' CDS. See for example ENST00000524289 + // http://sep2015.archive.ensembl.org/Homo_sapiens/Transcript/Sequence_cDNA?db=core;g=ENSG00000155868;r=5:157138846-157159019;t=ENST00000524289 + // Also, the incomplete CDS can be too short (1 or 2bp), so it is not enough to trim the last one. + + tr->trim |= TRIM_3PRIME; + if ( tr->strand==STRAND_FWD ) + { + i = tr->ncds - 1; + while ( i>=0 && len%3 ) + { + int dlen = tr->cds[i]->len >= len%3 ? len%3 : tr->cds[i]->len; + tr->cds[i]->len -= dlen; + len -= dlen; + i--; + } + } + else + { + i = 0; + while ( incds && len%3 ) + { + int dlen = tr->cds[i]->len >= len%3 ? len%3 : tr->cds[i]->len; + tr->cds[i]->len -= dlen; + tr->cds[i]->beg += dlen; + len -= dlen; + i++; + } + } + } + + // set CDS offsets and insert into regidx + len=0; + for (i=0; incds; i++) + { + tr->cds[i]->pos = len; + len += tr->cds[i]->len; + regidx_push(args->idx_cds, chr_beg,chr_end, tr->cds[i]->beg,tr->cds[i]->beg+tr->cds[i]->len-1, &tr->cds[i]); + } + } +} + +void regidx_free_gf(void *payload) { free(*((gf_cds_t**)payload)); } +void regidx_free_tscript(void *payload) { tscript_t *tr = *((tscript_t**)payload); free(tr->cds); free(tr); } + +void init_gff(args_t *args) +{ + aux_t *aux = &args->init; + aux->seq2int = khash_str2int_init(); // chrom's numeric id + aux->gid2gene = kh_init(int2gene); // gene id to gf_gene_t, for idx_gene + aux->id2tr = kh_init(int2tscript); // transcript id to tscript_t + args->idx_tscript = regidx_init(NULL, NULL, regidx_free_tscript, sizeof(tscript_t*), NULL); + aux->ignored_biotypes = khash_str2int_init(); + gff_id_init(&aux->gene_ids); + gff_id_init(&args->tscript_ids); + + // parse gff + kstring_t str = {0,0,0}; + htsFile *fp = hts_open(args->gff_fname,"r"); + if ( !fp ) error("Failed to read %s\n", args->gff_fname); + while ( hts_getline(fp, KS_SEP_LINE, &str) > 0 ) + { + hts_expand(ftr_t, aux->nftr+1, aux->mftr, aux->ftr); + int ret = gff_parse(args, str.s, aux->ftr + aux->nftr); + if ( !ret ) aux->nftr++; + } + free(str.s); + if ( hts_close(fp)!=0 ) error("Close failed: %s\n", args->gff_fname); + + + // process gff information: connect CDS and exons to transcripts + args->idx_cds = regidx_init(NULL, NULL, regidx_free_gf, sizeof(gf_cds_t*), NULL); + args->idx_utr = regidx_init(NULL, NULL, regidx_free_gf, sizeof(gf_utr_t*), NULL); + args->idx_exon = regidx_init(NULL, NULL, regidx_free_gf, sizeof(gf_exon_t*), NULL); + args->itr = regitr_init(NULL); + + int i; + for (i=0; inftr; i++) + { + ftr_t *ftr = &aux->ftr[i]; + + // check whether to keep this feature: is there a mapping trid -> gene_id -> gene? + khint_t k = kh_get(int2tscript, aux->id2tr, (int)ftr->trid); + if ( k==kh_end(aux->id2tr) ) continue; // no such transcript + + tscript_t *tr = kh_val(aux->id2tr,k); + if ( !tr->gene->name ) + { + // not a supported biotype (e.g. gene:pseudogene, transcript:processed_transcript) + regidx_free_tscript(&tr); + kh_del(int2tscript, aux->id2tr,k); + continue; + } + + // populate regidx by category: + // ftr->type .. GF_CDS, GF_EXON, GF_UTR3, GF_UTR5 + // gene->type .. GF_PROTEIN_CODING, GF_MT_rRNA, GF_IG_C, ... + if ( ftr->type==GF_CDS ) register_cds(args, ftr); + else if ( ftr->type==GF_EXON ) register_exon(args, ftr); + else if ( ftr->type==GF_UTR5 ) register_utr(args, ftr); + else if ( ftr->type==GF_UTR3 ) register_utr(args, ftr); + else + error("something: %s\t%d\t%d\t%s\t%s\n", aux->seq[ftr->iseq],ftr->beg+1,ftr->end+1,args->tscript_ids.str[ftr->trid],gf_type2gff_string(ftr->type)); + } + tscript_init_cds(args); + + if ( !args->quiet ) + { + fprintf(bcftools_stderr,"Indexed %d transcripts, %d exons, %d CDSs, %d UTRs\n", + regidx_nregs(args->idx_tscript), + regidx_nregs(args->idx_exon), + regidx_nregs(args->idx_cds), + regidx_nregs(args->idx_utr)); + } + + free(aux->ftr); + khash_str2int_destroy_free(aux->seq2int); + // keeping only to destroy the genes at the end: kh_destroy(int2gene,aux->gid2gene); + kh_destroy(int2tscript,aux->id2tr); + free(aux->seq); + gff_id_destroy(&aux->gene_ids); + + if ( args->quiet<2 && khash_str2int_size(aux->ignored_biotypes) ) + { + khash_t(str2int) *ign = (khash_t(str2int)*)aux->ignored_biotypes; + fprintf(bcftools_stderr,"Ignored the following biotypes:\n"); + for (i = kh_begin(ign); i < kh_end(ign); i++) + { + if ( !kh_exist(ign,i)) continue; + fprintf(bcftools_stderr,"\t%dx\t.. %s\n", kh_value(ign,i), kh_key(ign,i)); + } + } + khash_str2int_destroy_free(aux->ignored_biotypes); +} + +void init_data(args_t *args) +{ + args->nfmt_bcsq = 1 + (args->ncsq_max - 1) / 32; + + if ( !args->quiet ) fprintf(bcftools_stderr,"Parsing %s ...\n", args->gff_fname); + init_gff(args); + + args->rid = -1; + + if ( args->filter_str ) + args->filter = filter_init(args->hdr, args->filter_str); + + args->fai = fai_load(args->fa_fname); + if ( !args->fai ) error("Failed to load the fai index: %s\n", args->fa_fname); + + args->pos2vbuf = kh_init(pos2vbuf); + args->active_tr = khp_init(trhp); + args->hap = (hap_t*) calloc(1,sizeof(hap_t)); + + // init samples + if ( !bcf_hdr_nsamples(args->hdr) ) args->phase = PHASE_DROP_GT; + if ( args->sample_list && !strcmp("-",args->sample_list) ) + { + // ignore all samples + if ( args->output_type==FT_TAB_TEXT ) + { + // significant speedup for plain VCFs + bcf_hdr_set_samples(args->hdr,NULL,0); + } + args->phase = PHASE_DROP_GT; + } + else + args->smpl = smpl_ilist_init(args->hdr, args->sample_list, args->sample_is_file, SMPL_STRICT); + args->hdr_nsmpl = args->phase==PHASE_DROP_GT ? 0 : bcf_hdr_nsamples(args->hdr); + + if ( args->output_type==FT_TAB_TEXT ) + { + args->out = args->output_fname ? fopen(args->output_fname,"w") : bcftools_stdout; + if ( !args->out ) error("Failed to open %s: %s\n", args->output_fname,strerror(errno)); + + fprintf(args->out,"# This file was produced by: bcftools +csq(%s+htslib-%s)\n", bcftools_version(),hts_version()); + fprintf(args->out,"# The command line was:\tbcftools +%s", args->argv[0]); + int i; + for (i=1; iargc; i++) + fprintf(args->out," %s",args->argv[i]); + fprintf(args->out,"\n"); + fprintf(args->out,"# LOG\t[2]Message\n"); + fprintf(args->out,"# CSQ"); i = 1; + fprintf(args->out,"\t[%d]Sample", ++i); + fprintf(args->out,"\t[%d]Haplotype", ++i); + fprintf(args->out,"\t[%d]Chromosome", ++i); + fprintf(args->out,"\t[%d]Position", ++i); + fprintf(args->out,"\t[%d]Consequence", ++i); + fprintf(args->out,"\n"); + } + else + { + args->out_fh = hts_open(args->output_fname? args->output_fname : "-",hts_bcf_wmode(args->output_type)); + if ( args->out_fh == NULL ) error("Can't write to %s: %s\n", args->output_fname? args->output_fname : "standard output", strerror(errno)); + bcf_hdr_append_version(args->hdr,args->argc,args->argv,"bcftools/csq"); + bcf_hdr_printf(args->hdr,"##INFO=",args->bcsq_tag, args->local_csq ? "Local" : "Haplotype-aware"); + if ( args->hdr_nsmpl ) + bcf_hdr_printf(args->hdr,"##FORMAT=",args->bcsq_tag); + bcf_hdr_write(args->out_fh, args->hdr); + } + if ( !args->quiet ) fprintf(bcftools_stderr,"Calling...\n"); +} + +void destroy_data(args_t *args) +{ + regidx_destroy(args->idx_cds); + regidx_destroy(args->idx_utr); + regidx_destroy(args->idx_exon); + regidx_destroy(args->idx_tscript); + regitr_destroy(args->itr); + + khint_t k,i,j; + for (k=0; kinit.gid2gene); k++) + { + if ( !kh_exist(args->init.gid2gene, k) ) continue; + gf_gene_t *gene = (gf_gene_t*) kh_val(args->init.gid2gene, k); + free(gene->name); + free(gene); + } + kh_destroy(int2gene,args->init.gid2gene); + + if ( args->filter ) + filter_destroy(args->filter); + + khp_destroy(trhp,args->active_tr); + kh_destroy(pos2vbuf,args->pos2vbuf); + if ( args->smpl ) smpl_ilist_destroy(args->smpl); + int ret; + if ( args->out_fh ) + ret = hts_close(args->out_fh); + else + ret = fclose(args->out); + if ( ret ) error("Error: close failed .. %s\n", args->output_fname?args->output_fname:"bcftools_stdout"); + for (i=0; ivcf_rbuf.m; i++) + { + vbuf_t *vbuf = args->vcf_buf[i]; + if ( !vbuf ) continue; + for (j=0; jm; j++) + { + if ( !vbuf->vrec[j] ) continue; + if ( vbuf->vrec[j]->line ) bcf_destroy(vbuf->vrec[j]->line); + free(vbuf->vrec[j]->smpl); + free(vbuf->vrec[j]->vcsq); + free(vbuf->vrec[j]); + } + free(vbuf->vrec); + free(vbuf); + } + free(args->vcf_buf); + free(args->rm_tr); + free(args->csq_buf); + free(args->hap->stack); + free(args->hap->sseq.s); + free(args->hap->tseq.s); + free(args->hap->tref.s); + free(args->hap); + fai_destroy(args->fai); + free(args->gt_arr); + free(args->str.s); + free(args->str2.s); + gff_id_destroy(&args->tscript_ids); +} + +/* + The splice_* functions are for consquences around splice sites: start,stop,splice_* + */ +#define SPLICE_VAR_REF 0 // ref: ACGT>ACGT, csq not applicable, skip completely +#define SPLICE_OUTSIDE 1 // splice acceptor or similar; csq set and is done, does not overlap the region +#define SPLICE_INSIDE 2 // overlaps coding region; csq can be set but coding prediction is needed +#define SPLICE_OVERLAP 3 // indel overlaps region boundary, csq set but could not determine csq +typedef struct +{ + tscript_t *tr; + struct { + int32_t pos, rlen, alen; + char *ref, *alt; + bcf1_t *rec; + } vcf; + uint16_t check_acceptor:1, // check distance from exon start (fwd) or end (rev) + check_start:1, // this is the first coding exon (relative to transcript orientation), check first (fwd) or last (rev) codon + check_stop:1, // this is the last coding exon (relative to transcript orientation), check last (fwd) or first (rev) codon + check_donor:1, // as with check_acceptor + check_region_beg:1, // do/don't check for splices at this end, eg. in the first or last exon + check_region_end:1, // + check_utr:1, // check splice sites (acceptor/donor/region_*) only if not in utr + set_refalt:1; // set kref,kalt, if set, check also for synonymous events + uint32_t csq; + int tbeg, tend; // number of trimmed bases from beg and end of ref,alt allele + uint32_t ref_beg, // ref coordinates with spurious bases removed, ACC>AC can become AC>A or CC>C, whichever gives + ref_end; // a more conservative csq (the first and last base in kref.s) + kstring_t kref, kalt; // trimmed alleles, set only with SPLICE_OLAP +} +splice_t; +void splice_init(splice_t *splice, bcf1_t *rec) +{ + memset(splice,0,sizeof(*splice)); + splice->vcf.rec = rec; + splice->vcf.pos = rec->pos; + splice->vcf.rlen = rec->rlen; + splice->vcf.ref = rec->d.allele[0]; +} +static inline void splice_build_hap(splice_t *splice, uint32_t beg, int len) +{ + // len>0 .. beg is the first base, del filled from right + // len<0 .. beg is the last base, del filled from left + + int rlen, alen, rbeg, abeg; // first base to include (ref coordinates) + if ( len<0 ) + { + rlen = alen = -len; + rbeg = beg - rlen + 1; + int dlen = splice->vcf.alen - splice->vcf.rlen; + if ( dlen<0 && beg < splice->ref_end ) // incomplete del, beg is in the middle + dlen += splice->ref_end - beg; + abeg = rbeg + dlen; + } + else + { + rbeg = abeg = beg; + rlen = alen = len; + // check for incomplete del as above?? + } + +#define XDBG 0 +#if XDBG +fprintf(bcftools_stderr,"build_hap: rbeg=%d + %d abeg=%d \n",rbeg,rlen,abeg); +#endif + splice->kref.l = 0; + splice->kalt.l = 0; + + // add the part before vcf.ref, in the vcf.ref and after vcf.ref + int roff; // how many vcf.ref bases already used + if ( rbeg < splice->vcf.pos ) + { + assert( splice->tr->beg <= rbeg ); // this can be extended thanks to N_REF_PAD + kputsn(splice->tr->ref + N_REF_PAD + rbeg - splice->tr->beg, splice->vcf.pos - rbeg, &splice->kref); + roff = 0; + } + else + roff = rbeg - splice->vcf.pos; +#if XDBG +fprintf(bcftools_stderr,"r1: %s roff=%d\n",splice->kref.s,roff); +#endif + + if ( roff < splice->vcf.rlen && splice->kref.l < rlen ) + { + int len = splice->vcf.rlen - roff; // len still available in vcf.ref + if ( len > rlen - splice->kref.l ) len = rlen - splice->kref.l; // how much of ref allele is still needed + kputsn(splice->vcf.ref + roff, len, &splice->kref); + } +#if XDBG +fprintf(bcftools_stderr,"r2: %s\n",splice->kref.s); +#endif + + uint32_t end = splice->vcf.pos + splice->vcf.rlen; // position just after the ref allele + if ( splice->kref.l < rlen ) + { + if ( end + rlen - splice->kref.l - 1 > splice->tr->end ) // trim, the requested sequence is too long (could be extended, see N_REF_PAD) + rlen -= end + rlen - splice->kref.l - 1 - splice->tr->end; + if ( splice->kref.l < rlen ) + kputsn(splice->tr->ref + N_REF_PAD + end - splice->tr->beg, rlen - splice->kref.l, &splice->kref); + } +#if XDBG +fprintf(bcftools_stderr,"r3: %s\n",splice->kref.s); +#endif + + + int aoff; + if ( abeg < splice->vcf.pos ) + { + assert( splice->tr->beg <= abeg ); + kputsn(splice->tr->ref + N_REF_PAD + abeg - splice->tr->beg, splice->vcf.pos - abeg, &splice->kalt); + aoff = 0; + } + else + aoff = abeg - splice->vcf.pos; +#if XDBG +fprintf(bcftools_stderr,"a1: %s aoff=%d\n",splice->kalt.s,aoff); +#endif + + if ( aoff < splice->vcf.alen && splice->kalt.l < alen ) + { + int len = splice->vcf.alen - aoff; // len still available in vcf.alt + if ( len > alen - splice->kalt.l ) len = alen - splice->kalt.l; // how much of alt allele is still needed + kputsn(splice->vcf.alt + aoff, len, &splice->kalt); + aoff -= len; + } + if ( aoff < 0 ) aoff = 0; + else aoff--; +#if XDBG +fprintf(bcftools_stderr,"a2: %s aoff=%d\n",splice->kalt.s,aoff); +#endif + + end = splice->vcf.pos + splice->vcf.rlen; // position just after the ref allele + if ( splice->kalt.l < alen ) + { + if ( end + alen + aoff - splice->kalt.l - 1 > splice->tr->end ) // trim, the requested sequence is too long + alen -= end + alen + aoff - splice->kalt.l - 1 - splice->tr->end; + if ( alen > 0 && alen > splice->kalt.l ) + kputsn(splice->tr->ref + aoff + N_REF_PAD + end - splice->tr->beg, alen - splice->kalt.l, &splice->kalt); + } +#if XDBG +fprintf(bcftools_stderr,"a3: %s\n",splice->kalt.s); +fprintf(bcftools_stderr," [%s]\n [%s]\n\n",splice->kref.s,splice->kalt.s); +#endif +} +void csq_stage(args_t *args, csq_t *csq, bcf1_t *rec); +static inline int csq_stage_utr(args_t *args, regitr_t *itr, bcf1_t *rec, uint32_t trid) +{ + while ( regitr_overlap(itr) ) + { + gf_utr_t *utr = regitr_payload(itr, gf_utr_t*); + tscript_t *tr = utr->tr; + if ( tr->id != trid ) continue; + csq_t csq; + memset(&csq, 0, sizeof(csq_t)); + csq.pos = rec->pos; + csq.type.type = utr->which==prime5 ? CSQ_UTR5 : CSQ_UTR3; + csq.type.biotype = tr->type; + csq.type.strand = tr->strand; + csq.type.trid = tr->id; + csq.type.gene = tr->gene->name; + csq_stage(args, &csq, rec); + return csq.type.type; + } + return 0; +} +static inline void csq_stage_splice(args_t *args, bcf1_t *rec, tscript_t *tr, uint32_t type) +{ +#if XDBG +fprintf(bcftools_stderr,"csq_stage_splice %d: type=%d\n",rec->pos+1,type); +#endif + if ( !type ) return; + csq_t csq; + memset(&csq, 0, sizeof(csq_t)); + csq.pos = rec->pos; + csq.type.type = type; + csq.type.biotype = tr->type; + csq.type.strand = tr->strand; + csq.type.trid = tr->id; + csq.type.gene = tr->gene->name; + csq_stage(args, &csq, rec); +} +static inline int splice_csq_ins(args_t *args, splice_t *splice, uint32_t ex_beg, uint32_t ex_end) +{ + // coordinates that matter for consequences, eg AC>ACG trimmed to C>CG, 1bp + // before and after the inserted bases + if ( splice->tbeg || splice->vcf.ref[0]!=splice->vcf.alt[0] ) + { + splice->ref_beg = splice->vcf.pos + splice->tbeg - 1; + splice->ref_end = splice->vcf.pos + splice->vcf.rlen - splice->tend; + } + else + { + if ( splice->tend ) splice->tend--; + splice->ref_beg = splice->vcf.pos; + splice->ref_end = splice->vcf.pos + splice->vcf.rlen - splice->tend; + } +#if XDBG +fprintf(bcftools_stderr,"ins: %s>%s .. ex=%d,%d beg,end=%d,%d tbeg,tend=%d,%d check_utr=%d start,stop,beg,end=%d,%d,%d,%d\n", splice->vcf.ref,splice->vcf.alt,ex_beg,ex_end,splice->ref_beg,splice->ref_end,splice->tbeg,splice->tend,splice->check_utr,splice->check_start,splice->check_stop,splice->check_region_beg,splice->check_region_end); +#endif + + int ret; + if ( splice->ref_beg >= ex_end ) // fully outside, beyond the exon + { + if ( splice->check_utr ) + { + regitr_t *itr = regitr_init(NULL); + const char *chr = bcf_seqname(args->hdr,splice->vcf.rec); + if ( regidx_overlap(args->idx_utr,chr,splice->ref_beg+1,splice->ref_beg+1, itr) ) // adjacent utr + { + ret = csq_stage_utr(args, itr, splice->vcf.rec, splice->tr->id); + if ( ret!=0 ) + { + regitr_destroy(itr); + return SPLICE_OUTSIDE; // overlaps utr + } + } + regitr_destroy(itr); + } + if ( !splice->check_region_end ) return SPLICE_OUTSIDE; + char *ref = NULL, *alt = NULL; + if ( splice->set_refalt ) // seq identity is checked only when tr->ref is available + { + splice_build_hap(splice, ex_end+1, N_SPLICE_REGION_INTRON); + ref = splice->kref.s, alt = splice->kalt.s; + } + if ( splice->ref_beg < ex_end + N_SPLICE_REGION_INTRON && splice->ref_end > ex_end + N_SPLICE_DONOR ) + { + splice->csq |= CSQ_SPLICE_REGION; + if ( ref && !strncmp(ref,alt,N_SPLICE_REGION_INTRON) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + if ( splice->ref_beg < ex_end + N_SPLICE_DONOR ) + { + if ( splice->check_donor && splice->tr->strand==STRAND_FWD ) splice->csq |= CSQ_SPLICE_DONOR; + if ( splice->check_acceptor && splice->tr->strand==STRAND_REV ) splice->csq |= CSQ_SPLICE_ACCEPTOR; + if ( ref && !strncmp(ref,alt,N_SPLICE_DONOR) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_OUTSIDE; + } + if ( splice->ref_end < ex_beg || (splice->ref_end == ex_beg && !splice->check_region_beg) ) // fully outside, before the exon + { + if ( splice->check_utr ) + { + regitr_t *itr = regitr_init(NULL); + const char *chr = bcf_seqname(args->hdr,splice->vcf.rec); + if ( regidx_overlap(args->idx_utr,chr,splice->ref_end-1,splice->ref_end-1, itr) ) // adjacent utr + { + ret = csq_stage_utr(args, itr, splice->vcf.rec, splice->tr->id); + if ( ret!=0 ) + { + regitr_destroy(itr); + return SPLICE_OUTSIDE; // overlaps utr + } + } + regitr_destroy(itr); + } + if ( !splice->check_region_beg ) return SPLICE_OUTSIDE; + char *ref = NULL, *alt = NULL; + if ( splice->set_refalt ) // seq identity is checked only when tr->ref is available + { + splice_build_hap(splice, ex_beg - N_SPLICE_REGION_INTRON, N_SPLICE_REGION_INTRON); + ref = splice->kref.s, alt = splice->kalt.s; + } + if ( splice->ref_end > ex_beg - N_SPLICE_REGION_INTRON && splice->ref_beg < ex_beg - N_SPLICE_DONOR ) + { + splice->csq |= CSQ_SPLICE_REGION; + if ( ref && !strncmp(ref,alt,N_SPLICE_REGION_INTRON) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + if ( splice->ref_end > ex_beg - N_SPLICE_DONOR ) + { + if ( splice->check_donor && splice->tr->strand==STRAND_REV ) splice->csq |= CSQ_SPLICE_DONOR; + if ( splice->check_acceptor && splice->tr->strand==STRAND_FWD ) splice->csq |= CSQ_SPLICE_ACCEPTOR; + if ( ref && !strncmp(ref+N_SPLICE_REGION_INTRON-N_SPLICE_DONOR,alt+N_SPLICE_REGION_INTRON-N_SPLICE_DONOR,N_SPLICE_DONOR) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_OUTSIDE; + } + // overlaps the exon or inside the exon + // possible todo: find better alignment for frameshifting variants? + if ( splice->ref_beg <= ex_beg + 2 ) // in the first 3bp + { + if ( splice->check_region_beg ) splice->csq |= CSQ_SPLICE_REGION; + if ( splice->tr->strand==STRAND_FWD ) { if ( splice->check_start ) splice->csq |= CSQ_START_LOST; } + else { if ( splice->check_stop ) splice->csq |= CSQ_STOP_LOST; } + } + if ( splice->ref_end > ex_end - 2 ) + { + if ( splice->check_region_end ) splice->csq |= CSQ_SPLICE_REGION; + if ( splice->tr->strand==STRAND_REV ) { if ( splice->check_start ) splice->csq |= CSQ_START_LOST; } + else { if ( splice->check_stop ) splice->csq |= CSQ_STOP_LOST; } + } + if ( splice->set_refalt ) + { + // Make sure the variant will not end up left aligned to avoid overlapping vcf records + // splice_build_hap(splice, splice->ref_beg, splice->vcf.alen - splice->tend - splice->tbeg + 1); + // splice->vcf.rlen -= splice->tbeg + splice->tend - 1; + // if ( splice->kref.l > splice->vcf.rlen ) { splice->kref.l = splice->vcf.rlen; splice->kref.s[splice->kref.l] = 0; } + if ( splice->ref_beg < splice->vcf.pos ) // this must have been caused by too much trimming from right + { + int dlen = splice->vcf.pos - splice->ref_beg; + assert( dlen==1 ); + splice->tbeg += dlen; + if ( splice->tbeg + splice->tend == splice->vcf.rlen ) splice->tend -= dlen; + splice->ref_beg = splice->vcf.pos; + } + if ( splice->ref_end==ex_beg ) splice->tend--; // prevent zero-length ref allele + splice_build_hap(splice, splice->ref_beg, splice->vcf.alen - splice->tend - splice->tbeg + 1); + splice->vcf.rlen -= splice->tbeg + splice->tend - 1; + if ( splice->kref.l > splice->vcf.rlen ) { splice->kref.l = splice->vcf.rlen; splice->kref.s[splice->kref.l] = 0; } + } + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_INSIDE; +} + +static inline int splice_csq_del(args_t *args, splice_t *splice, uint32_t ex_beg, uint32_t ex_end) +{ + // coordinates that matter for consequences, eg AC>ACG trimmed to C>CG + splice->ref_beg = splice->vcf.pos + splice->tbeg - 1; // 1b before the deleted base + splice->ref_end = splice->vcf.pos + splice->vcf.rlen - splice->tend - 1; // the last deleted base + +#if XDBG +fprintf(bcftools_stderr,"del: %s>%s .. ex=%d,%d beg,end=%d,%d tbeg,tend=%d,%d check_utr=%d start,stop,beg,end=%d,%d,%d,%d\n", splice->vcf.ref,splice->vcf.alt,ex_beg,ex_end,splice->ref_beg,splice->ref_end,splice->tbeg,splice->tend,splice->check_utr,splice->check_start,splice->check_stop,splice->check_region_beg,splice->check_region_end); +#endif + + if ( splice->ref_beg + 1 < ex_beg ) // the part before the exon; ref_beg is off by -1 + { + if ( splice->check_region_beg ) + { + int csq = 0; + if ( splice->check_utr ) + { + regitr_t *itr = regitr_init(NULL); + const char *chr = bcf_seqname(args->hdr,splice->vcf.rec); + if ( regidx_overlap(args->idx_utr,chr,splice->ref_beg,ex_beg-1, itr) ) // adjacent utr + csq = csq_stage_utr(args, itr, splice->vcf.rec, splice->tr->id); + regitr_destroy(itr); + } + if ( !csq ) + { + char *ref = NULL, *alt = NULL; + if ( splice->set_refalt ) // seq identity is checked only when tr->ref is available + { + // filling from the left does not work for ENST00000341065/frame3.vcf + // CAG.GTGGCCAG CAG.GTGGCCAG + // CA-.--GGCCAG vs CAG.---GCCAG + // splice_build_hap(splice, ex_beg-1, -N_SPLICE_REGION_INTRON); + // + // filling from the right: + splice_build_hap(splice, ex_beg - N_SPLICE_REGION_INTRON, N_SPLICE_REGION_INTRON); + ref = splice->kref.s, alt = splice->kalt.s; + } + if ( splice->ref_end >= ex_beg - N_SPLICE_REGION_INTRON && splice->ref_beg < ex_beg - N_SPLICE_DONOR ) + { + splice->csq |= CSQ_SPLICE_REGION; + if ( ref && alt && !strncmp(ref,alt,N_SPLICE_REGION_INTRON) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + if ( splice->ref_end >= ex_beg - N_SPLICE_DONOR ) + { + if ( splice->check_donor && splice->tr->strand==STRAND_REV ) splice->csq |= CSQ_SPLICE_DONOR; + if ( splice->check_acceptor && splice->tr->strand==STRAND_FWD ) splice->csq |= CSQ_SPLICE_ACCEPTOR; + if ( ref && alt && !strncmp(ref+N_SPLICE_REGION_INTRON-N_SPLICE_DONOR,alt+N_SPLICE_REGION_INTRON-N_SPLICE_DONOR,N_SPLICE_DONOR) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + } + } + if ( splice->ref_end >= ex_beg ) + { + splice->tbeg = splice->ref_beg - splice->vcf.pos + 1; + splice->ref_beg = ex_beg - 1; + if ( splice->tbeg + splice->tend == splice->vcf.alen ) + { + // the deletion overlaps ex_beg and cannot be easily realigned to the right + if ( !splice->tend ) + { + splice->csq |= CSQ_CODING_SEQUENCE; + return SPLICE_OVERLAP; + } + splice->tend--; + } + } + } + if ( ex_end < splice->ref_end ) // the part after the exon + { + if ( splice->check_region_end ) + { + int csq = 0; + if ( splice->check_utr ) + { + regitr_t *itr = regitr_init(NULL); + const char *chr = bcf_seqname(args->hdr,splice->vcf.rec); + if ( regidx_overlap(args->idx_utr,chr,ex_end+1,splice->ref_end, itr) ) // adjacent utr + csq = csq_stage_utr(args, itr, splice->vcf.rec, splice->tr->id); + regitr_destroy(itr); + } + if ( !csq ) + { + char *ref = NULL, *alt = NULL; + if ( splice->set_refalt ) // seq identity is checked only when tr->ref is available + { + splice_build_hap(splice, ex_end+1, N_SPLICE_REGION_INTRON); // ref,alt positioned at the first intron base + ref = splice->kref.s, alt = splice->kalt.s; + } + if ( splice->ref_beg < ex_end + N_SPLICE_REGION_INTRON && splice->ref_end > ex_end + N_SPLICE_DONOR ) + { + splice->csq |= CSQ_SPLICE_REGION; + if ( ref && alt && !strncmp(ref,alt,N_SPLICE_REGION_INTRON) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + if ( splice->ref_beg < ex_end + N_SPLICE_DONOR ) + { + if ( splice->check_donor && splice->tr->strand==STRAND_FWD ) splice->csq |= CSQ_SPLICE_DONOR; + if ( splice->check_acceptor && splice->tr->strand==STRAND_REV ) splice->csq |= CSQ_SPLICE_ACCEPTOR; + if ( ref && alt && !strncmp(ref+N_SPLICE_REGION_INTRON-N_SPLICE_DONOR,alt+N_SPLICE_REGION_INTRON-N_SPLICE_DONOR,N_SPLICE_DONOR) ) splice->csq |= CSQ_SYNONYMOUS_VARIANT; + } + } + } + if ( splice->ref_beg < ex_end ) + { + splice->tend = splice->vcf.rlen - (splice->ref_end - splice->vcf.pos + 1); + splice->ref_end = ex_end; + } + } + if ( splice->ref_end < ex_beg || splice->ref_beg >= ex_end ) + { + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_OUTSIDE; + } + + if ( splice->ref_beg < ex_beg + 2 ) // ref_beg is off by -1 + { + if ( splice->check_region_beg ) splice->csq |= CSQ_SPLICE_REGION; + if ( splice->tr->strand==STRAND_FWD ) { if ( splice->check_start ) splice->csq |= CSQ_START_LOST; } + else { if ( splice->check_stop ) splice->csq |= CSQ_STOP_LOST; } + } + if ( splice->ref_end > ex_end - 3 ) + { + if ( splice->check_region_end ) splice->csq |= CSQ_SPLICE_REGION; + if ( splice->tr->strand==STRAND_REV ) { if ( splice->check_start ) splice->csq |= CSQ_START_LOST; } + else { if ( splice->check_stop ) splice->csq |= CSQ_STOP_LOST; } + } + if ( splice->set_refalt ) + { + if ( splice->tbeg>0 ) splice->tbeg--; //why is this? + if ( splice->vcf.rlen > splice->tbeg + splice->tend && splice->vcf.alen > splice->tbeg + splice->tend ) + { + splice->vcf.rlen -= splice->tbeg + splice->tend; + splice->vcf.alen -= splice->tbeg + splice->tend; + } + splice->kref.l = 0; kputsn(splice->vcf.ref + splice->tbeg, splice->vcf.rlen, &splice->kref); + splice->kalt.l = 0; kputsn(splice->vcf.alt + splice->tbeg, splice->vcf.alen, &splice->kalt); + if ( (splice->ref_beg+1 < ex_beg && splice->ref_end >= ex_beg) || (splice->ref_beg+1 < ex_end && splice->ref_end >= ex_end) ) // ouch, ugly ENST00000409523/long-overlapping-del.vcf + { + splice->csq |= (splice->ref_end - splice->ref_beg + 1)%3 ? CSQ_FRAMESHIFT_VARIANT : CSQ_INFRAME_DELETION; + return SPLICE_OVERLAP; + } + } + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_INSIDE; +} + +static inline int splice_csq_mnp(args_t *args, splice_t *splice, uint32_t ex_beg, uint32_t ex_end) +{ + // not a real variant, can be ignored: eg ACGT>ACGT + if ( splice->tbeg + splice->tend == splice->vcf.rlen ) return SPLICE_VAR_REF; + + splice->ref_beg = splice->vcf.pos + splice->tbeg; + splice->ref_end = splice->vcf.pos + splice->vcf.rlen - splice->tend - 1; + +#if XDBG +fprintf(bcftools_stderr,"mnp: %s>%s .. ex=%d,%d beg,end=%d,%d tbeg,tend=%d,%d check_utr=%d start,stop,beg,end=%d,%d,%d,%d\n", splice->vcf.ref,splice->vcf.alt,ex_beg,ex_end,splice->ref_beg,splice->ref_end,splice->tbeg,splice->tend,splice->check_utr,splice->check_start,splice->check_stop,splice->check_region_beg,splice->check_region_end); +#endif + + if ( splice->ref_beg < ex_beg ) // the part before the exon + { + if ( splice->check_region_beg ) + { + int csq = 0; + if ( splice->check_utr ) + { + regitr_t *itr = regitr_init(NULL); + const char *chr = bcf_seqname(args->hdr,splice->vcf.rec); + if ( regidx_overlap(args->idx_utr,chr,splice->ref_beg,ex_beg-1, itr) ) // adjacent utr + csq = csq_stage_utr(args, itr, splice->vcf.rec, splice->tr->id); + regitr_destroy(itr); + } + if ( !csq ) + { + if ( splice->ref_end >= ex_beg - N_SPLICE_REGION_INTRON && splice->ref_beg < ex_beg - N_SPLICE_DONOR ) + splice->csq |= CSQ_SPLICE_REGION; + if ( splice->ref_end >= ex_beg - N_SPLICE_DONOR ) + { + if ( splice->check_donor && splice->tr->strand==STRAND_REV ) splice->csq |= CSQ_SPLICE_DONOR; + if ( splice->check_acceptor && splice->tr->strand==STRAND_FWD ) splice->csq |= CSQ_SPLICE_ACCEPTOR; + } + } + } + if ( splice->ref_end >= ex_beg ) + { + splice->tbeg = splice->ref_beg - splice->vcf.pos; + splice->ref_beg = ex_beg; + } + } + if ( ex_end < splice->ref_end ) // the part after the exon + { + if ( splice->check_region_end ) + { + int csq = 0; + if ( splice->check_utr ) + { + regitr_t *itr = regitr_init(NULL); + const char *chr = bcf_seqname(args->hdr,splice->vcf.rec); + if ( regidx_overlap(args->idx_utr,chr,ex_end+1,splice->ref_end, itr) ) // adjacent utr + csq = csq_stage_utr(args, itr, splice->vcf.rec, splice->tr->id); + regitr_destroy(itr); + } + if ( !csq ) + { + if ( splice->ref_beg <= ex_end + N_SPLICE_REGION_INTRON && splice->ref_end > ex_end + N_SPLICE_DONOR ) + splice->csq |= CSQ_SPLICE_REGION; + if ( splice->ref_beg <= ex_end + N_SPLICE_DONOR ) + { + if ( splice->check_donor && splice->tr->strand==STRAND_FWD ) splice->csq |= CSQ_SPLICE_DONOR; + if ( splice->check_acceptor && splice->tr->strand==STRAND_REV ) splice->csq |= CSQ_SPLICE_ACCEPTOR; + } + } + } + if ( splice->ref_beg <= ex_end ) + { + splice->tend = splice->vcf.rlen - (splice->ref_end - splice->vcf.pos + 1); + splice->ref_end = ex_end; + } + } + if ( splice->ref_end < ex_beg || splice->ref_beg > ex_end ) + { + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_OUTSIDE; + } + + if ( splice->ref_beg < ex_beg + 3 ) + { + if ( splice->check_region_beg ) splice->csq |= CSQ_SPLICE_REGION; + if ( splice->tr->strand==STRAND_FWD ) { if ( splice->check_start ) splice->csq |= CSQ_START_LOST; } + else { if ( splice->check_stop ) splice->csq |= CSQ_STOP_LOST; } + } + if ( splice->ref_end > ex_end - 3 ) + { + if ( splice->check_region_end ) splice->csq |= CSQ_SPLICE_REGION; + if ( splice->tr->strand==STRAND_REV ) { if ( splice->check_start ) splice->csq |= CSQ_START_LOST; } + else { if ( splice->check_stop ) splice->csq |= CSQ_STOP_LOST; } + } + if ( splice->set_refalt ) + { + splice->vcf.rlen -= splice->tbeg + splice->tend; + splice->kref.l = 0; kputsn(splice->vcf.ref + splice->tbeg, splice->vcf.rlen, &splice->kref); + splice->kalt.l = 0; kputsn(splice->vcf.alt + splice->tbeg, splice->vcf.rlen, &splice->kalt); + } + csq_stage_splice(args, splice->vcf.rec, splice->tr, splice->csq); + return SPLICE_INSIDE; +} +static inline int splice_csq(args_t *args, splice_t *splice, uint32_t ex_beg, uint32_t ex_end) +{ + splice->csq = 0; + splice->vcf.alen = strlen(splice->vcf.alt); + + int rlen1 = splice->vcf.rlen - 1, alen1 = splice->vcf.alen - 1, i = 0; + splice->tbeg = 0, splice->tend = 0; + + // trim from the right, then from the left + while ( i<=rlen1 && i<=alen1 ) + { + if ( splice->vcf.ref[rlen1-i] != splice->vcf.alt[alen1-i] ) break; + i++; + } + splice->tend = i; + rlen1 -= i, alen1 -= i, i = 0; + while ( i<=rlen1 && i<=alen1 ) + { + if ( splice->vcf.ref[i] != splice->vcf.alt[i] ) break; + i++; + } + splice->tbeg = i; + + // The mnp, ins and del code was split into near-identical functions for clarity and debugging; + // possible todo: generalize once stable + if ( splice->vcf.rlen==splice->vcf.alen ) return splice_csq_mnp(args, splice, ex_beg, ex_end); + if ( splice->vcf.rlen < splice->vcf.alen ) return splice_csq_ins(args, splice, ex_beg, ex_end); + if ( splice->vcf.rlen > splice->vcf.alen ) return splice_csq_del(args, splice, ex_beg, ex_end); + + return 0; +} + +// return value: 0 added, 1 overlapping variant, 2 silent discard (intronic,alt=ref) +int hap_init(args_t *args, hap_node_t *parent, hap_node_t *child, gf_cds_t *cds, bcf1_t *rec, int ial) +{ + int i; + kstring_t str = {0,0,0}; + tscript_t *tr = cds->tr; + child->icds = cds->icds; // index of cds in the tscript's list of exons + + splice_t splice; + splice_init(&splice, rec); + splice.tr = tr; + splice.vcf.alt = rec->d.allele[ial]; + splice.check_acceptor = splice.check_donor = splice.set_refalt = splice.check_utr = 1; + if ( !(tr->trim & TRIM_5PRIME) ) + { + if ( tr->strand==STRAND_FWD ) { if ( child->icds==0 ) splice.check_start = 1; } + else { if ( child->icds==tr->ncds-1 ) splice.check_start = 1; } + } + if ( !(tr->trim & TRIM_3PRIME) ) + { + if ( tr->strand==STRAND_FWD ) { if ( child->icds==tr->ncds-1 ) splice.check_stop = 1; } + else { if ( child->icds==0 ) splice.check_stop = 1; } + } + if ( splice.check_start ) // do not check starts in incomplete CDS, defined as not starting with M + { + if ( tr->strand==STRAND_FWD ) { if ( dna2aa(tr->ref+N_REF_PAD+cds->beg-tr->beg) != 'M' ) splice.check_start = 0; } + else { if ( cdna2aa(tr->ref+N_REF_PAD+cds->beg-tr->beg+cds->len-3) != 'M' ) splice.check_start = 0; } + } + if ( child->icds!=0 ) splice.check_region_beg = 1; + if ( child->icds!=tr->ncds-1 ) splice.check_region_end = 1; + +#if XDBG +fprintf(bcftools_stderr,"\n%d [%s][%s] check start:%d,stop:%d\n",splice.vcf.pos+1,splice.vcf.ref,splice.vcf.alt,splice.check_start,splice.check_stop); +#endif + int ret = splice_csq(args, &splice, cds->beg, cds->beg + cds->len - 1); +#if XDBG +fprintf(bcftools_stderr,"cds splice_csq: %d [%s][%s] .. beg,end=%d %d, ret=%d, csq=%d\n\n",splice.vcf.pos+1,splice.kref.s,splice.kalt.s,splice.ref_beg+1,splice.ref_end+1,ret,splice.csq); +#endif + + if ( ret==SPLICE_VAR_REF ) return 2; // not a variant, eg REF=CA ALT=CA + if ( ret==SPLICE_OUTSIDE || ret==SPLICE_OVERLAP ) // not a coding csq + { + free(splice.kref.s); + free(splice.kalt.s); + + if ( !splice.csq ) return 2; // fully intronic, no csq + + // splice_region/acceptor/donor + child->seq = NULL; + child->sbeg = 0; + child->rbeg = rec->pos; + child->rlen = 0; + child->dlen = 0; + kputs(rec->d.allele[0],&str); + kputc('>',&str); + kputs(rec->d.allele[ial],&str); + child->var = str.s; + child->type = HAP_SSS; + child->csq = splice.csq; + child->prev = parent->type==HAP_SSS ? parent->prev : parent; + child->rec = rec; + return 0; + } + if ( splice.csq & CSQ_SYNONYMOUS_VARIANT ) splice.csq &= ~CSQ_SYNONYMOUS_VARIANT; // synonymous&splice,frame could become synonymous&frame,splice + + int dbeg = 0; + if ( splice.ref_beg < cds->beg ) + { + // The vcf record overlaps the exon boundary, but the variant itself + // should fit inside since we are here. This will need more work. + // #1475227917 + dbeg = cds->beg - splice.ref_beg; + splice.kref.l -= dbeg; + splice.ref_beg = cds->beg; + assert( dbeg <= splice.kalt.l ); + } + + if ( parent->type==HAP_SSS ) parent = parent->prev; + if ( parent->type==HAP_CDS ) + { + i = parent->icds; + if ( i!=cds->icds ) + { + // the variant is on a new exon, finish up the previous + int len = tr->cds[i]->len - parent->rbeg - parent->rlen + tr->cds[i]->beg; + if ( len > 0 ) + kputsn_(tr->ref + N_REF_PAD + parent->rbeg + parent->rlen - tr->beg, len, &str); + } + + // append any skipped non-variant exons + while ( ++i < cds->icds ) + kputsn_(tr->ref + N_REF_PAD + tr->cds[i]->beg - tr->beg, tr->cds[i]->len, &str); + + if ( parent->icds==child->icds ) + { + int len = splice.ref_beg - parent->rbeg - parent->rlen; + if ( len < 0 ) // overlapping variants + { + free(str.s); + return 1; + } + kputsn_(tr->ref + N_REF_PAD + parent->rbeg + parent->rlen - tr->beg, len, &str); + } + else + kputsn_(tr->ref + N_REF_PAD + cds->beg - tr->beg, splice.ref_beg - cds->beg, &str); + } + kputs(splice.kalt.s + dbeg, &str); + + child->seq = str.s; + child->sbeg = cds->pos + (splice.ref_beg - cds->beg); + child->rbeg = splice.ref_beg; + child->rlen = splice.kref.l; + child->type = HAP_CDS; + child->prev = parent; + child->rec = rec; + child->csq = splice.csq; + + // set vlen and the "ref>alt" string + { + int rlen = strlen(rec->d.allele[0]); + int alen = strlen(rec->d.allele[ial]); + child->dlen = alen - rlen; + child->var = (char*) malloc(rlen+alen+2); + memcpy(child->var,rec->d.allele[0],rlen); + child->var[rlen] = '>'; + memcpy(child->var+rlen+1,rec->d.allele[ial],alen); + child->var[rlen+alen+1] = 0; + } + + // yuck, the whole CDS is modified/deleted, not ready for this, todo. + if ( child->rbeg + child->rlen > cds->beg + cds->len ) + { + child->type = HAP_SSS; + if ( !child->csq ) child->csq |= CSQ_CODING_SEQUENCE; // hack, specifically for ENST00000390520/deletion-overlap.vcf + } + + free(splice.kref.s); + free(splice.kalt.s); + return 0; +} +void hap_destroy(hap_node_t *hap) +{ + int i; + for (i=0; inchild; i++) + if ( hap->child[i] ) hap_destroy(hap->child[i]); + for (i=0; imcsq_list; i++) free(hap->csq_list[i].type.vstr.s); + free(hap->csq_list); + free(hap->child); + free(hap->cur_child); + free(hap->seq); + free(hap->var); + free(hap); +} + + +/* + ref: spliced reference and its length (ref.l) + seq: part of the spliced query transcript on the reference strand to translate, its + length (seq.l) and the total length of the complete transcript (seq.m) + sbeg: seq offset within the spliced query transcript + rbeg: seq offset within ref, 0-based + rend: last base of seq within ref, plus one. If seq does not contain indels, it is rend=rbeg+seq->l + strand: coding strand - 0:rev, 1:fwd + tseq: translated sequence (aa) + fill: frameshift, fill until the end (strand=fwd) or from the start (strand=rev) + */ +void cds_translate(kstring_t *_ref, kstring_t *_seq, uint32_t sbeg, uint32_t rbeg, uint32_t rend, int strand, kstring_t *tseq, int fill) +{ +#if XDBG +fprintf(bcftools_stderr,"translate: %d %d %d fill=%d seq.l=%d\n",sbeg,rbeg,rend,fill,(int)_seq->l); +#endif + char tmp[3], *codon, *end; + int i, len, npad; + + kstring_t ref = *_ref; + kstring_t seq = *_seq; + + tseq->l = 0; + if ( !seq.l ) + { + kputc('?', tseq); + return; + } + +#define DBG 0 +#if DBG + fprintf(bcftools_stderr,"translate: sbeg,rbeg,rend=%d %d %d fill=%d seq.l=%d\n",sbeg,rbeg,rend,fill,(int)_seq->l); + fprintf(bcftools_stderr," ref: l=%d %s\n", (int)ref.l,ref.s); + fprintf(bcftools_stderr," seq: l=%d m=%d ", (int)seq.l,(int)seq.m); + for (i=0; i1 + fprintf(bcftools_stderr," npad: %d\n",npad); +#endif + assert( npad<=rbeg ); + + for (i=0; i1 + fprintf(bcftools_stderr,"\t i=%d\n", i); +#endif + if ( i==3 ) + { + kputc_(dna2aa(tmp), tseq); +#if DBG>1 + fprintf(bcftools_stderr,"[1]%c%c%c\n",tmp[0],tmp[1],tmp[2]); +#endif + codon = seq.s + 3 - npad; // next codon + end = codon + len - 1 - (len % 3); // last position of a valid codon + while ( codon < end ) + { + kputc_(dna2aa(codon), tseq); +#if DBG>1 + fprintf(bcftools_stderr,"[2]%c%c%c\n",codon[0],codon[1],codon[2]); +#endif + codon += 3; + } + end = seq.s + seq.l - 1; + for (i=0; codon+i<=end; i++) tmp[i] = codon[i]; + } + + // right padding + codon = ref.s + rend + N_REF_PAD; + if ( i>0 ) + { +#if DBG>1 + if(i==1)fprintf(bcftools_stderr,"[3]%c\n",tmp[0]); + if(i==2)fprintf(bcftools_stderr,"[3]%c%c\n",tmp[0],tmp[1]); +#endif + for (; i<3; i++) + { + tmp[i] = *codon; + codon++; + } + kputc_(dna2aa(tmp), tseq); +#if DBG>1 + fprintf(bcftools_stderr,"[4]%c%c%c\n",tmp[0],tmp[1],tmp[2]); +#endif + } + if ( fill!=0 ) + { + end = ref.s + ref.l - N_REF_PAD; + while ( codon+3 <= end ) + { + kputc_(dna2aa(codon), tseq); +#if DBG>1 + fprintf(bcftools_stderr,"[5]%c%c%c\t%c\n",codon[0],codon[1],codon[2],dna2aa(codon)); +#endif + codon += 3; + } + } + } + else // STRAND_REV + { + // right padding - number of bases to take from ref + npad = (seq.m - (sbeg + seq.l)) % 3; +#if DBG>1 + fprintf(bcftools_stderr," npad: %d\n",npad); +#endif +if ( !(npad>=0 && sbeg+seq.l+npad<=seq.m) ) fprintf(bcftools_stderr,"sbeg=%d seq.l=%d seq.m=%d\n",sbeg,(int)seq.l,(int)seq.m); + assert( npad>=0 && sbeg+seq.l+npad<=seq.m ); // todo: first codon on the rev strand + + if ( npad==2 ) + { + tmp[1] = ref.s[rend+N_REF_PAD]; + tmp[2] = ref.s[rend+N_REF_PAD+1]; + i = 0; + } + else if ( npad==1 ) + { + tmp[2] = ref.s[rend+N_REF_PAD]; + i = 1; + } + else + i = 2; + + end = seq.s + seq.l; + for (; i>=0 && end>seq.s; i--) tmp[i] = *(--end); +#if DBG>1 + fprintf(bcftools_stderr,"\t i=%d\n", i); + if(i==1)fprintf(bcftools_stderr,"[0] %c\n",tmp[2]); + if(i==0)fprintf(bcftools_stderr,"[0] %c%c\n",tmp[1],tmp[2]); +#endif + if ( i==-1 ) + { +#if DBG>1 + fprintf(bcftools_stderr,"[1]%c%c%c\t%c\n",tmp[0],tmp[1],tmp[2], cdna2aa(tmp)); +#endif + kputc_(cdna2aa(tmp), tseq); + codon = end - 3; + while ( codon >= seq.s ) + { + kputc_(cdna2aa(codon), tseq); +#if DBG>1 + fprintf(bcftools_stderr,"[2]%c%c%c\t%c\n",codon[0],codon[1],codon[2], cdna2aa(codon)); +#endif + codon -= 3; + } + if ( seq.s-codon==2 ) + { + tmp[2] = seq.s[0]; + i = 1; + } + else if ( seq.s-codon==1 ) + { + tmp[1] = seq.s[0]; + tmp[2] = seq.s[1]; + i = 0; + } + else + i = -1; +#if DBG>1 + if(i==1)fprintf(bcftools_stderr,"[3] %c\n",tmp[2]); + if(i==0)fprintf(bcftools_stderr,"[3] %c%c\n",tmp[1],tmp[2]); +#endif + } + // left padding + end = ref.s + N_REF_PAD + rbeg; + if ( i>=0 ) + { + for (; i>=0 && end>=ref.s; i--) tmp[i] = *(--end); + kputc_(cdna2aa(tmp), tseq); +#if DBG>1 + fprintf(bcftools_stderr,"[4]%c%c%c\t%c\n",tmp[0],tmp[1],tmp[2],cdna2aa(tmp)); +#endif + } + if ( fill!=0 ) + { + codon = end - 3; + while ( codon >= ref.s + N_REF_PAD ) + { + kputc_(cdna2aa(codon), tseq); +#if DBG>1 + fprintf(bcftools_stderr,"[5]%c%c%c\t%c\n",codon[0],codon[1],codon[2],cdna2aa(codon)); +#endif + codon -= 3; + } + } + } + kputc_(0,tseq); tseq->l--; +#if DBG + fprintf(bcftools_stderr," tseq: %s\n", tseq->s); +#endif +} + +void tscript_splice_ref(tscript_t *tr) +{ + int i, len = 0; + for (i=0; incds; i++) + len += tr->cds[i]->len; + + tr->nsref = len + 2*N_REF_PAD; + tr->sref = (char*) malloc(len + 1 + 2*N_REF_PAD); + len = 0; + + memcpy(tr->sref, tr->ref + tr->cds[0]->beg - tr->beg, N_REF_PAD); + len += N_REF_PAD; + + for (i=0; incds; i++) + { + memcpy(tr->sref + len, tr->ref + N_REF_PAD + tr->cds[i]->beg - tr->beg, tr->cds[i]->len); + len += tr->cds[i]->len; + } + memcpy(tr->sref + len, tr->ref + N_REF_PAD + tr->cds[tr->ncds-1]->beg - tr->beg, N_REF_PAD); + len += N_REF_PAD; + + tr->sref[len] = 0; +} + +// returns: 0 if consequence was added, 1 if it already exists or could not be added +int csq_push(args_t *args, csq_t *csq, bcf1_t *rec) +{ +#if XDBG +fprintf(bcftools_stderr,"csq_push: %d .. %d\n",rec->pos+1,csq->type.type); +#endif + khint_t k = kh_get(pos2vbuf, args->pos2vbuf, (int)csq->pos); + vbuf_t *vbuf = (k == kh_end(args->pos2vbuf)) ? NULL : kh_val(args->pos2vbuf, k); + if ( !vbuf ) error("This should not happen. %s:%d %s\n",bcf_seqname(args->hdr,rec),csq->pos+1,csq->type.vstr); + + int i; + for (i=0; in; i++) + if ( vbuf->vrec[i]->line==rec ) break; + if ( i==vbuf->n ) error("This should not happen.. %s:%d %s\n", bcf_seqname(args->hdr,rec),csq->pos+1,csq->type.vstr); + vrec_t *vrec = vbuf->vrec[i]; + + // if the variant overlaps donor/acceptor and also splice region, report only donor/acceptor + if ( csq->type.type & CSQ_SPLICE_REGION && csq->type.type & (CSQ_SPLICE_DONOR|CSQ_SPLICE_ACCEPTOR) ) + csq->type.type &= ~CSQ_SPLICE_REGION; + + if ( csq->type.type & CSQ_PRINTED_UPSTREAM ) + { + for (i=0; invcsq; i++) + { + // Same as below, to avoid records like + // 3630 .. @3632,stop_lost|AL627309.1|ENST00000423372|protein_coding|- + // 3632 .. stop_lost|AL627309.1|ENST00000423372|protein_coding|-|260*>260G|3630T>A+3632A>C + if ( csq->type.type&CSQ_START_STOP && vrec->vcsq[i].type&CSQ_START_STOP ) + { + vrec->vcsq[i] = csq->type; + goto exit_duplicate; + } + if ( !(vrec->vcsq[i].type & CSQ_PRINTED_UPSTREAM) ) continue; + if ( csq->type.ref != vrec->vcsq[i].ref ) continue; + goto exit_duplicate; + } + } + else if ( csq->type.type & CSQ_COMPOUND ) + { + for (i=0; invcsq; i++) + { + if ( csq->type.trid != vrec->vcsq[i].trid && (csq->type.type|vrec->vcsq[i].type)&CSQ_PRN_TSCRIPT ) continue; + if ( csq->type.biotype != vrec->vcsq[i].biotype ) continue; + if ( csq->type.gene != vrec->vcsq[i].gene ) continue; + if ( csq->type.vstr.s || vrec->vcsq[i].vstr.s ) + { + // This is a bit hacky, but we want a simpler and more predictable output. The splice_csq() function + // can trigger stop/start events based on indel overlap, then another stop/start event can be triggered + // from add_csq() or test_cds_local() based on sequence comparison, and on output we could find two + // consequences: + // stop_lost|AL627309.1|ENST00000423372|protein_coding|- + // stop_lost&inframe_insertion|AL627309.1|ENST00000423372|protein_coding|-|260*>260CL|3630T>TAAA + if ( !csq->type.vstr.s || !vrec->vcsq[i].vstr.s ) + { + if ( csq->type.type&CSQ_START_STOP && vrec->vcsq[i].type&CSQ_START_STOP ) + { + vrec->vcsq[i].type |= csq->type.type; + + // remove stop_lost&synonymous if stop_retained set + if ( vrec->vcsq[i].type&CSQ_STOP_RETAINED ) + vrec->vcsq[i].type &= ~(CSQ_STOP_LOST|CSQ_SYNONYMOUS_VARIANT); + + if ( !vrec->vcsq[i].vstr.s ) vrec->vcsq[i].vstr = csq->type.vstr; + goto exit_duplicate; + } + continue; + } + if ( strcmp(csq->type.vstr.s,vrec->vcsq[i].vstr.s) ) continue; + } + vrec->vcsq[i].type |= csq->type.type; + goto exit_duplicate; + } + } + else + { + for (i=0; invcsq; i++) + { + if ( csq->type.trid != vrec->vcsq[i].trid && (csq->type.type|vrec->vcsq[i].type)&CSQ_PRN_TSCRIPT) continue; + if ( csq->type.biotype != vrec->vcsq[i].biotype ) continue; + if ( !(vrec->vcsq[i].type & CSQ_COMPOUND) ) + { + vrec->vcsq[i].type |= csq->type.type; + goto exit_duplicate; + } + if ( vrec->vcsq[i].type==(vrec->vcsq[i].type|csq->type.type) ) goto exit_duplicate; + } + } + // no such csq yet in this vcf record + csq->vrec = vrec; + csq->idx = i; + vrec->nvcsq++; + hts_expand0(vcsq_t, vrec->nvcsq, vrec->mvcsq, vrec->vcsq); + vrec->vcsq[i] = csq->type; + return 0; + +exit_duplicate: + csq->vrec = vrec; + csq->idx = i; + return 1; +} + +// soff .. position of the variant within the trimmed query transcript +// sbeg .. position of the variant within the query transcript +// rbeg .. position on the reference transcript (if there are no indels, then rbeg=send) +// rpos .. VCF position +#define node2soff(i) (hap->stack[i].slen - (hap->stack[i].node->rlen + hap->stack[i].node->dlen)) +#define node2sbeg(i) (hap->sbeg + node2soff(i)) +#define node2send(i) (hap->sbeg + hap->stack[i].slen) +#define node2rbeg(i) (hap->stack[i].node->sbeg) +#define node2rend(i) (hap->stack[i].node->sbeg + hap->stack[i].node->rlen) +#define node2rpos(i) (hap->stack[i].node->rec->pos) + +void kput_vcsq(args_t *args, vcsq_t *csq, kstring_t *str) +{ + // Remove start/stop from incomplete CDS, but only if there is another + // consequence as something must be reported + if ( csq->type & CSQ_INCOMPLETE_CDS && (csq->type & ~(CSQ_START_STOP|CSQ_INCOMPLETE_CDS|CSQ_UPSTREAM_STOP)) ) csq->type &= ~(CSQ_START_STOP|CSQ_INCOMPLETE_CDS); + + // Remove missense from start/stops + if ( csq->type & CSQ_START_STOP && csq->type & CSQ_MISSENSE_VARIANT ) csq->type &= ~CSQ_MISSENSE_VARIANT; + + if ( csq->type & CSQ_PRINTED_UPSTREAM && csq->ref ) + { + kputc_('@',str); + kputw(csq->ref->pos+1, str); + return; + } + if ( csq->type & CSQ_UPSTREAM_STOP ) + kputc_('*',str); + + int i, n = sizeof(csq_strings)/sizeof(char*); + for (i=1; itype&(1<type&(1<gene ) kputs(csq->gene , str); + + kputc_('|', str); + if ( csq->type & CSQ_PRN_TSCRIPT ) kputs(args->tscript_ids.str[csq->trid], str); + + kputc_('|', str); + kputs(gf_type2gff_string(csq->biotype), str); + + if ( CSQ_PRN_STRAND(csq->type) || csq->vstr.l ) + kputs(csq->strand==STRAND_FWD ? "|+" : "|-", str); + + if ( csq->vstr.l ) + kputs(csq->vstr.s, str); +} + +void hap_add_csq(args_t *args, hap_t *hap, hap_node_t *node, int tlen, int ibeg, int iend, int dlen, int indel) +{ + int i; + tscript_t *tr = hap->tr; + int ref_node = tr->strand==STRAND_FWD ? ibeg : iend; + + int icsq = node->ncsq_list++; + hts_expand0(csq_t,node->ncsq_list,node->mcsq_list,node->csq_list); + csq_t *csq = &node->csq_list[icsq]; + csq->pos = hap->stack[ref_node].node->rec->pos; + csq->type.trid = tr->id; + csq->type.gene = tr->gene->name; + csq->type.strand = tr->strand; + csq->type.biotype = tr->type; + + // only now we see the translated sequence and can determine if the stop/start changes are real + int rm_csq = 0; + csq->type.type = 0; + for (i=ibeg; i<=iend; i++) + csq->type.type |= hap->stack[i].node->csq & CSQ_COMPOUND; + if ( dlen==0 && indel ) csq->type.type |= CSQ_INFRAME_ALTERING; + + int has_upstream_stop = hap->upstream_stop; + if ( hap->stack[ibeg].node->type != HAP_SSS ) + { + // check for truncating stops + for (i=0; itref.l; i++) + if ( hap->tref.s[i]=='*' ) break; + if ( i!=hap->tref.l ) + { + hap->tref.l = i+1; + hap->tref.s[i+1] = 0; + } + for (i=0; itseq.l; i++) + if ( hap->tseq.s[i]=='*' ) break; + if ( i!=hap->tseq.l ) + { + hap->tseq.l = i+1; + hap->tseq.s[i+1] = 0; + hap->upstream_stop = 1; + } + if ( csq->type.type & CSQ_STOP_LOST ) + { + if ( hap->tref.s[hap->tref.l-1]=='*' && hap->tref.s[hap->tref.l-1] == hap->tseq.s[hap->tseq.l-1] ) + { + rm_csq |= CSQ_STOP_LOST; + csq->type.type |= CSQ_STOP_RETAINED; + } + else if ( hap->tref.s[hap->tref.l-1]!='*' ) + { + // This is CDS 3' incomplete ENSG00000173376/synon.vcf, can also be missense + // We observe in real data a change to a stop, ENST00000528237/retained-stop-incomplete-cds.vcf + if ( hap->tseq.s[hap->tseq.l-1] == '*' ) + { + rm_csq |= CSQ_STOP_GAINED; + csq->type.type |= CSQ_STOP_RETAINED; + } + else + csq->type.type |= CSQ_INCOMPLETE_CDS; + } + } + if ( csq->type.type & CSQ_START_LOST && hap->tref.s[0]!='M' ) + { + rm_csq |= CSQ_START_LOST; + csq->type.type &= ~CSQ_START_LOST; + } + if ( dlen!=0 ) + { + if ( dlen%3 ) + csq->type.type |= CSQ_FRAMESHIFT_VARIANT; + else if ( dlen<0 ) + csq->type.type |= CSQ_INFRAME_DELETION; + else + csq->type.type |= CSQ_INFRAME_INSERTION; + } + else + { + for (i=0; itref.l; i++) + if ( hap->tref.s[i] != hap->tseq.s[i] ) break; + if ( i==hap->tref.l ) + csq->type.type |= CSQ_SYNONYMOUS_VARIANT; + else if ( hap->tref.s[i] == '*' ) + csq->type.type |= CSQ_STOP_LOST; + else if ( hap->tseq.s[i] == '*' ) + csq->type.type |= CSQ_STOP_GAINED; + else + csq->type.type |= CSQ_MISSENSE_VARIANT; + } + } + if ( has_upstream_stop ) csq->type.type |= CSQ_UPSTREAM_STOP; + csq->type.type &= ~rm_csq; + + if ( hap->stack[ibeg].node->type == HAP_SSS ) + { + node->csq_list[icsq].type.type |= hap->stack[ibeg].node->csq & ~rm_csq; + node->csq_list[icsq].type.ref = hap->stack[ibeg].node->rec; + node->csq_list[icsq].type.biotype = tr->type; + csq_push(args, node->csq_list+icsq, hap->stack[ibeg].node->rec); + return; + } + + kstring_t str = node->csq_list[icsq].type.vstr; + str.l = 0; + + // create the aa variant string + int aa_rbeg = tr->strand==STRAND_FWD ? node2rbeg(ibeg)/3+1 : (hap->tr->nsref - 2*N_REF_PAD - node2rend(iend))/3+1; + int aa_sbeg = tr->strand==STRAND_FWD ? node2sbeg(ibeg)/3+1 : (tlen - node2send(iend))/3+1; + kputc_('|', &str); + kputw(aa_rbeg, &str); + kputs(hap->tref.s, &str); + if ( !(csq->type.type & CSQ_SYNONYMOUS_VARIANT) ) + { + kputc_('>', &str); + kputw(aa_sbeg, &str); + kputs(hap->tseq.s, &str); + } + kputc_('|', &str); + + // create the dna variant string and, in case of combined variants, + // insert silent CSQ_PRINTED_UPSTREAM variants + for (i=ibeg; i<=iend; i++) + { + if ( i>ibeg ) kputc_('+', &str); + kputw(node2rpos(i)+1, &str); + kputs(hap->stack[i].node->var, &str); + } + node->csq_list[icsq].type.vstr = str; + csq_push(args, node->csq_list+icsq, hap->stack[ref_node].node->rec); + + for (i=ibeg; i<=iend; i++) + { + // csq are printed at one position only for combined variants, the rest is + // silent and references the first + if ( hap->stack[i].node->csq & ~CSQ_COMPOUND ) + { + node->ncsq_list++; + hts_expand0(csq_t,node->ncsq_list,node->mcsq_list,node->csq_list); + csq_t *tmp_csq = &node->csq_list[node->ncsq_list - 1]; + tmp_csq->pos = hap->stack[i].node->rec->pos; + tmp_csq->type.trid = tr->id; + tmp_csq->type.gene = tr->gene->name; + tmp_csq->type.strand = tr->strand; + tmp_csq->type.type = hap->stack[i].node->csq & ~CSQ_COMPOUND & ~rm_csq; + tmp_csq->type.biotype = tr->type; + tmp_csq->type.vstr.l = 0; + kputs(str.s,&tmp_csq->type.vstr); + csq_push(args, tmp_csq, hap->stack[i].node->rec); + } + if ( i!=ref_node && (node->csq_list[icsq].type.type & CSQ_COMPOUND || !(hap->stack[i].node->csq & ~CSQ_COMPOUND)) ) + { + node->ncsq_list++; + hts_expand0(csq_t,node->ncsq_list,node->mcsq_list,node->csq_list); + csq_t *tmp_csq = &node->csq_list[node->ncsq_list - 1]; + tmp_csq->pos = hap->stack[i].node->rec->pos; + tmp_csq->type.trid = tr->id; + tmp_csq->type.gene = tr->gene->name; + tmp_csq->type.strand = tr->strand; + tmp_csq->type.type = CSQ_PRINTED_UPSTREAM | hap->stack[i].node->csq; + tmp_csq->type.biotype = tr->type; + tmp_csq->type.ref = hap->stack[ref_node].node->rec; + tmp_csq->type.vstr.l = 0; + csq_push(args, tmp_csq, hap->stack[i].node->rec); + } + } +} + + +void hap_finalize(args_t *args, hap_t *hap) +{ + tscript_t *tr = hap->tr; + if ( !tr->sref ) + tscript_splice_ref(tr); + + kstring_t sref; + sref.s = tr->sref; + sref.l = tr->nsref; + sref.m = sref.l; + + int istack = 0; + hts_expand(hstack_t,1,hap->mstack,hap->stack); + + hap->sseq.l = 0; + hap->tseq.l = 0; + hap->stack[0].node = tr->root; + hap->stack[0].ichild = -1; + hap->stack[0].slen = 0; + hap->stack[0].dlen = 0; + + while ( istack>=0 ) + { + hstack_t *stack = &hap->stack[istack]; + hap_node_t *node = hap->stack[istack].node; + while ( ++hap->stack[istack].ichild < node->nchild ) + { + if ( node->child[stack->ichild] ) break; + } + if ( stack->ichild == node->nchild ) { istack--; continue; } + + node = node->child[stack->ichild]; + + istack++; + hts_expand(hstack_t,istack+1,hap->mstack,hap->stack); + stack = &hap->stack[istack-1]; + + hap->stack[istack].node = node; + hap->stack[istack].ichild = -1; + + hap->sseq.l = stack->slen; + if ( node->type==HAP_CDS ) kputs(node->seq, &hap->sseq); + hap->stack[istack].slen = hap->sseq.l; + hap->stack[istack].dlen = hap->stack[istack-1].dlen + node->dlen; + + if ( !node->nend ) continue; // not a leaf node + + // The spliced sequence has been built for the current haplotype and stored + // in hap->sseq. Now we break it and output as independent parts + + kstring_t sseq; + sseq.m = sref.m - 2*N_REF_PAD + hap->stack[istack].dlen; // total length of the spliced query transcript + hap->upstream_stop = 0; + + int i = 1, dlen = 0, ibeg, indel = 0; + while ( istack[i].node->type == HAP_SSS ) i++; + hap->sbeg = hap->stack[i].node->sbeg; + + if ( tr->strand==STRAND_FWD ) + { + i = 0, ibeg = -1; + while ( ++i <= istack ) + { + if ( hap->stack[i].node->type == HAP_SSS ) + { + // start/stop/splice site overlap: don't know how to build the haplotypes correctly, skipping + hap_add_csq(args,hap,node,0,i,i,0,0); + continue; + } + dlen += hap->stack[i].node->dlen; + if ( hap->stack[i].node->dlen ) indel = 1; + + // This condition extends compound variants. Note that s/s/s sites are forced out to always break + // a compound block. See ENST00000271583/splice-acceptor.vcf for motivation. + if ( istack[i+1].node->type != HAP_SSS ) + { + if ( dlen%3 ) // frameshift + { + if ( ibeg==-1 ) ibeg = i; + continue; + } + int icur = node2sbeg(i); + int inext = node2sbeg(i+1); + if ( icur/3 == inext/3 ) // in the same codon, can't be flushed yet + { + if ( ibeg==-1 ) ibeg = i; + continue; + } + } + if ( ibeg<0 ) ibeg = i; + + int ioff = node2soff(ibeg); + int icur = node2sbeg(ibeg); + int rbeg = node2rbeg(ibeg); + int rend = node2rend(i); + int fill = dlen%3; + + // alt + if ( hap->sseq.l ) + { + sseq.l = hap->stack[i].slen - ioff; + sseq.s = hap->sseq.s + ioff; + } + else // splice site overlap, see #1475227917 + sseq.l = fill = 0; + cds_translate(&sref, &sseq, icur,rbeg,rend, tr->strand, &hap->tseq, fill); + + // ref + sseq.l = node2rend(i) - rbeg; + sseq.s = sref.s + N_REF_PAD + rbeg; + sseq.m = sref.m - 2*N_REF_PAD; + cds_translate(&sref, &sseq, rbeg,rbeg,rend, tr->strand, &hap->tref, fill); + sseq.m = sref.m - 2*N_REF_PAD + hap->stack[istack].dlen; + + hap_add_csq(args,hap,node,0, ibeg,i,dlen,indel); + ibeg = -1; + dlen = 0; + indel = 0; + } + } + else + { + i = istack + 1, ibeg = -1; + while ( --i > 0 ) + { + if ( hap->stack[i].node->type == HAP_SSS ) + { + hap_add_csq(args,hap,node,0,i,i,0,0); + continue; + } + dlen += hap->stack[i].node->dlen; + if ( hap->stack[i].node->dlen ) indel = 1; + if ( i>1 && hap->stack[i-1].node->type != HAP_SSS ) + { + if ( dlen%3 ) + { + if ( ibeg==-1 ) ibeg = i; + continue; + } + int icur = sseq.m - 1 - node2sbeg(i); + int inext = sseq.m - 1 - node2sbeg(i-1); + if ( icur/3 == inext/3 ) + { + if ( ibeg==-1 ) ibeg = i; + continue; + } + } + if ( ibeg<0 ) ibeg = i; + int ioff = node2soff(i); + int icur = node2sbeg(i); + int rbeg = node2rbeg(i); + int rend = node2rend(ibeg); + int fill = dlen%3; + + // alt + if ( hap->sseq.l ) + { + sseq.l = hap->stack[ibeg].slen - ioff; + sseq.s = hap->sseq.s + ioff; + } + else // splice site overlap, see #1475227917 + sseq.l = fill = 0; + cds_translate(&sref, &sseq, icur,rbeg,rend, tr->strand, &hap->tseq, fill); + + // ref + sseq.l = node2rend(ibeg) - rbeg; + sseq.s = sref.s + N_REF_PAD + rbeg; + sseq.m = sref.m - 2*N_REF_PAD; + cds_translate(&sref, &sseq, rbeg,rbeg,rend, tr->strand, &hap->tref, fill); + sseq.m = sref.m - 2*N_REF_PAD + hap->stack[istack].dlen; + + hap_add_csq(args,hap,node,sseq.m, i,ibeg,dlen,indel); + ibeg = -1; + dlen = 0; + indel = 0; + } + } + } +} + +static inline void csq_print_text(args_t *args, csq_t *csq, int ismpl, int ihap) +{ + if ( csq->type.type & CSQ_PRINTED_UPSTREAM ) return; + + char *smpl = ismpl >= 0 ? args->hdr->samples[ismpl] : "-"; + const char *chr = bcf_hdr_id2name(args->hdr,args->rid); + + fprintf(args->out,"CSQ\t%s\t", smpl); + if ( ihap>0 ) + fprintf(args->out,"%d", ihap); + else + fprintf(args->out,"-"); + + args->str.l = 0; + kput_vcsq(args, &csq->type, &args->str); + fprintf(args->out,"\t%s\t%d\t%s\n",chr,csq->pos+1,args->str.s); +} +static inline void hap_print_text(args_t *args, tscript_t *tr, int ismpl, int ihap, hap_node_t *node) +{ + if ( !node || !node->ncsq_list ) return; + + char *smpl = ismpl >= 0 ? args->hdr->samples[ismpl] : "-"; + const char *chr = bcf_hdr_id2name(args->hdr,args->rid); + + int i; + for (i=0; incsq_list; i++) + { + csq_t *csq = node->csq_list + i; + if ( csq->type.type & CSQ_PRINTED_UPSTREAM ) continue; + assert( csq->type.vstr.l ); + + fprintf(args->out,"CSQ\t%s\t", smpl); + if ( ihap>0 ) + fprintf(args->out,"%d", ihap); + else + fprintf(args->out,"-"); + + args->str.l = 0; + kput_vcsq(args, &csq->type, &args->str); + fprintf(args->out,"\t%s\t%d\t%s\n",chr,csq->pos+1,args->str.s); + } +} + +static inline void hap_stage_vcf(args_t *args, tscript_t *tr, int ismpl, int ihap, hap_node_t *node) +{ + if ( !node || !node->ncsq_list || ismpl<0 ) return; + + int i; + for (i=0; incsq_list; i++) + { + csq_t *csq = node->csq_list + i; + vrec_t *vrec = csq->vrec; + int icsq = 2*csq->idx + ihap; + if ( icsq >= args->ncsq_max ) // more than ncsq_max consequences, so can't fit it in FMT + { + int print_warning = 1; + if ( args->quiet ) + { + if ( args->quiet > 1 || args->ncsq_small_warned ) print_warning = 0; + args->ncsq_small_warned = 1; + } + if ( print_warning ) + { + fprintf(bcftools_stderr,"Warning: --ncsq %d is too small to annotate %s at %s:%d with %d-th csq\n", + args->ncsq_max/2,args->hdr->samples[ismpl],bcf_hdr_id2name(args->hdr,args->rid),vrec->line->pos+1,csq->idx+1); + if ( args->quiet ) fprintf(bcftools_stderr,"(This warning is printed only once)\n"); + } + break; + } + if ( vrec->nfmt < 1 + icsq/32 ) vrec->nfmt = 1 + icsq/32; + vrec->smpl[ismpl*args->nfmt_bcsq + icsq/32] |= 1 << (icsq % 32); + } +} + +void hap_flush(args_t *args, uint32_t pos) +{ + int i,j; + tr_heap_t *heap = args->active_tr; + + while ( heap->ndat && heap->dat[0]->end<=pos ) + { + tscript_t *tr = heap->dat[0]; + khp_delete(trhp, heap); + + args->hap->tr = tr; + if ( tr->root && tr->root->nchild ) // normal, non-localized calling + { + hap_finalize(args, args->hap); + + if ( args->output_type==FT_TAB_TEXT ) // plain text output, not a vcf + { + if ( args->phase==PHASE_DROP_GT ) + hap_print_text(args, tr, -1,0, tr->hap[0]); + else + { + for (i=0; ismpl->n; i++) + { + for (j=0; j<2; j++) + hap_print_text(args, tr, args->smpl->idx[i],j+1, tr->hap[i*2+j]); + } + } + } + else if ( args->phase!=PHASE_DROP_GT ) + { + for (i=0; ismpl->n; i++) + { + for (j=0; j<2; j++) + hap_stage_vcf(args, tr, args->smpl->idx[i],j, tr->hap[i*2+j]); + } + } + } + + // mark the transcript for deletion. Cannot delete it immediately because + // by-position VCF output will need them when flushed by vcf_buf_push + args->nrm_tr++; + hts_expand(tscript_t*,args->nrm_tr,args->mrm_tr,args->rm_tr); + args->rm_tr[args->nrm_tr-1] = tr; + } +} + +#define SWAP(type_t, a, b) { type_t t = a; a = b; b = t; } + +void vbuf_push(args_t *args, bcf1_t **rec_ptr) +{ + int i; + + assert(rec_ptr); + bcf1_t *rec = *rec_ptr; + + // check for duplicate records + i = args->vcf_rbuf.n ? rbuf_last(&args->vcf_rbuf) : -1; + if ( i<0 || args->vcf_buf[i]->vrec[0]->line->pos!=rec->pos ) + { + // vcf record with a new pos + rbuf_expand0(&args->vcf_rbuf, vbuf_t*, args->vcf_rbuf.n+1, args->vcf_buf); + i = rbuf_append(&args->vcf_rbuf); + if ( !args->vcf_buf[i] ) args->vcf_buf[i] = (vbuf_t*) calloc(1,sizeof(vbuf_t)); + args->vcf_buf[i]->n = 0; + } + vbuf_t *vbuf = args->vcf_buf[i]; + vbuf->n++; + hts_expand0(vrec_t*, vbuf->n, vbuf->m, vbuf->vrec); + if ( !vbuf->vrec[vbuf->n - 1] ) + vbuf->vrec[vbuf->n - 1] = (vrec_t*) calloc(1,sizeof(vrec_t)); + + vrec_t *vrec = vbuf->vrec[vbuf->n - 1]; + if ( args->phase!=PHASE_DROP_GT && args->smpl->n ) + { + if ( !vrec->smpl ) vrec->smpl = (uint32_t*) calloc(args->hdr_nsmpl,sizeof(*vrec->smpl) * args->nfmt_bcsq); + else memset(vrec->smpl,0,args->hdr_nsmpl*sizeof(*vrec->smpl) * args->nfmt_bcsq); + } + if ( !vrec->line ) vrec->line = bcf_init1(); + SWAP(bcf1_t*, (*rec_ptr), vrec->line); + + int ret; + khint_t k = kh_put(pos2vbuf, args->pos2vbuf, (int)rec->pos, &ret); + kh_val(args->pos2vbuf,k) = vbuf; +} + +void vbuf_flush(args_t *args) +{ + if ( args->active_tr->ndat ) return; // cannot output buffered VCF lines (args.vbuf) until all active transcripts are gone + + int i,j; + while ( (i=rbuf_shift(&args->vcf_rbuf))>=0 ) + { + vbuf_t *vbuf = args->vcf_buf[i]; + for (i=0; in; i++) + { + vrec_t *vrec = vbuf->vrec[i]; + if ( !args->out_fh ) // not a VCF output + { + vrec->nvcsq = 0; + continue; + } + if ( !vrec->nvcsq ) + { + bcf_write(args->out_fh, args->hdr, vrec->line); + continue; + } + + args->str.l = 0; + kput_vcsq(args, &vrec->vcsq[0], &args->str); + for (j=1; jnvcsq; j++) + { + kputc_(',', &args->str); + kput_vcsq(args, &vrec->vcsq[j], &args->str); + } + bcf_update_info_string(args->hdr, vrec->line, args->bcsq_tag, args->str.s); + if ( args->hdr_nsmpl ) + { + if ( vrec->nfmt < args->nfmt_bcsq ) + for (j=1; jhdr_nsmpl; j++) memcpy(vrec->smpl+j*vrec->nfmt, vrec->smpl+j*args->nfmt_bcsq, vrec->nfmt*sizeof(*vrec->smpl)); + bcf_update_format_int32(args->hdr, vrec->line, args->bcsq_tag, vrec->smpl, args->hdr_nsmpl*vrec->nfmt); + } + vrec->nvcsq = 0; + bcf_write(args->out_fh, args->hdr, vrec->line); + } + if ( vbuf->n ) + { + khint_t k = kh_get(pos2vbuf, args->pos2vbuf, vbuf->vrec[0]->line->pos); + if ( k != kh_end(args->pos2vbuf) ) kh_del(pos2vbuf, args->pos2vbuf, k); + } + vbuf->n = 0; + } + + for (i=0; inrm_tr; i++) + { + tscript_t *tr = args->rm_tr[i]; + if ( tr->root ) hap_destroy(tr->root); + tr->root = NULL; + free(tr->hap); + free(tr->ref); + free(tr->sref); + } + args->nrm_tr = 0; + args->ncsq_buf = 0; +} + +void tscript_init_ref(args_t *args, tscript_t *tr, const char *chr) +{ + int i, len; + int pad_beg = tr->beg >= N_REF_PAD ? N_REF_PAD : tr->beg; + + tr->ref = faidx_fetch_seq(args->fai, chr, tr->beg - pad_beg, tr->end + N_REF_PAD, &len); + if ( !tr->ref ) + error("faidx_fetch_seq failed %s:%d-%d\n", chr,tr->beg+1,tr->end+1); + + int pad_end = len - (tr->end - tr->beg + 1 + pad_beg); + if ( pad_beg + pad_end != 2*N_REF_PAD ) + { + char *ref = (char*) malloc(tr->end - tr->beg + 1 + 2*N_REF_PAD); + for (i=0; i < N_REF_PAD - pad_beg; i++) ref[i] = 'N'; + memcpy(ref+i, tr->ref, len); + for (i=0; i < N_REF_PAD - pad_end; i++) ref[i+len] = 'N'; + free(tr->ref); + tr->ref = ref; + } +} + +static void sanity_check_ref(args_t *args, tscript_t *tr, bcf1_t *rec) +{ + char *ref = tr->ref + (rec->pos + N_REF_PAD >= tr->beg ? rec->pos - tr->beg + N_REF_PAD : 0); + char *vcf = rec->d.allele[0] + (rec->pos + N_REF_PAD >= tr->beg ? 0 : tr->beg - N_REF_PAD - rec->pos); + assert( vcf - rec->d.allele[0] < strlen(rec->d.allele[0]) ); + while ( *ref && *vcf ) + { + if ( *ref!=*vcf && toupper(*ref)!=toupper(*vcf) ) + error("Error: the fasta reference does not match the VCF REF allele at %s:%d .. %s\n", bcf_seqname(args->hdr,rec),rec->pos+1,rec->d.allele[0]); + ref++; + vcf++; + } +} + +int test_cds_local(args_t *args, bcf1_t *rec) +{ + int i,j, ret = 0; + const char *chr = bcf_seqname(args->hdr,rec); + // note that the off-by-one extension of rlen is deliberate to account for insertions + if ( !regidx_overlap(args->idx_cds,chr,rec->pos,rec->pos+rec->rlen, args->itr) ) return 0; + + // structures to fake the normal test_cds machinery + hap_node_t root, node; + root.type = HAP_ROOT; + kstring_t *tref = &args->hap->tref, *tseq = &args->hap->tseq; + + while ( regitr_overlap(args->itr) ) + { + gf_cds_t *cds = regitr_payload(args->itr,gf_cds_t*); + tscript_t *tr = cds->tr; + if ( !GF_is_coding(tr->type) ) continue; + ret = 1; + + if ( !tr->ref ) + { + tscript_init_ref(args, tr, chr); + tscript_splice_ref(tr); + khp_insert(trhp, args->active_tr, &tr); // only to clean the reference afterwards + } + + sanity_check_ref(args, tr, rec); + + kstring_t sref; + sref.s = tr->sref; + sref.l = tr->nsref; + sref.m = sref.l; + + for (i=1; in_allele; i++) + { + if ( hap_init(args, &root, &node, cds, rec, i)!=0 ) continue; + + csq_t csq; + memset(&csq, 0, sizeof(csq_t)); + csq.pos = rec->pos; + csq.type.biotype = tr->type; + csq.type.strand = tr->strand; + csq.type.trid = tr->id; + csq.type.gene = tr->gene->name; + + int csq_type = node.csq; + + // code repetition: it would be nice to reuse the code from hap_add_csq, needs have refactoring though + if ( node.type == HAP_SSS ) + { + csq.type.type = csq_type; + csq_stage(args, &csq, rec); + } + else + { + kstring_t sseq; + sseq.m = sref.m - 2*N_REF_PAD + node.dlen; + sseq.s = node.seq; + int alen = sseq.l = strlen(sseq.s); + int fill = node.dlen%3 && alen ? 1 : 0; // see #1475227917 + cds_translate(&sref, &sseq, node.sbeg,node.sbeg,node.sbeg+node.rlen, tr->strand, tseq, fill); + + sseq.m = sref.m - 2*N_REF_PAD; + sseq.s = sref.s + N_REF_PAD + node.sbeg; + sseq.l = node.rlen; + cds_translate(&sref, &sseq, node.sbeg,node.sbeg,node.sbeg+node.rlen, tr->strand, tref, fill); + + // check for truncating stops + for (j=0; jl; j++) + if ( tref->s[j]=='*' ) break; + if ( j!=tref->l ) + { + tref->l = j+1; + tref->s[j+1] = 0; + } + for (j=0; jl; j++) + if ( tseq->s[j]=='*' ) break; + if ( j!=tseq->l ) + { + tseq->l = j+1; + tseq->s[j+1] = 0; + } + if ( csq_type & CSQ_STOP_LOST ) + { + if ( tref->s[tref->l-1]=='*' && tref->s[tref->l-1] == tseq->s[tseq->l-1] ) + { + csq_type &= ~CSQ_STOP_LOST; + csq_type |= CSQ_STOP_RETAINED; + } + else if (tref->s[tref->l-1]!='*' ) + { + // This is CDS 3' incomplete ENSG00000173376/synon.vcf, can also be missense + // We observe in real data a change to a stop, ENST00000528237/retained-stop-incomplete-cds.vcf + if ( tseq->s[tseq->l-1] == '*' ) + { + csq_type &= ~CSQ_STOP_GAINED; + csq_type |= CSQ_STOP_RETAINED; + } + else + csq_type |= CSQ_INCOMPLETE_CDS; + } + } + if ( csq_type & CSQ_START_LOST && tref->s[0]!='M' ) + csq_type &= ~CSQ_START_LOST; + if ( node.dlen!=0 ) + { + if ( node.dlen%3 ) + csq_type |= CSQ_FRAMESHIFT_VARIANT; + else if ( node.dlen<0 ) + csq_type |= CSQ_INFRAME_DELETION; + else + csq_type |= CSQ_INFRAME_INSERTION; + } + else + { + for (j=0; jl; j++) + if ( tref->s[j] != tseq->s[j] ) break; + if ( j==tref->l ) + csq_type |= CSQ_SYNONYMOUS_VARIANT; + else if ( tref->s[j] == '*' ) + csq_type |= CSQ_STOP_LOST; + else if ( tseq->s[j] == '*' ) + csq_type |= CSQ_STOP_GAINED; + else + csq_type |= CSQ_MISSENSE_VARIANT; + } + if ( csq_type & CSQ_COMPOUND ) + { + // create the aa variant string + kstring_t str = {0,0,0}; + int aa_rbeg = tr->strand==STRAND_FWD ? node.sbeg/3+1 : (tr->nsref - 2*N_REF_PAD - node.sbeg - node.rlen)/3+1; + int aa_sbeg = tr->strand==STRAND_FWD ? node.sbeg/3+1 : (tr->nsref - 2*N_REF_PAD + node.dlen - node.sbeg - alen)/3+1; + kputc_('|', &str); + kputw(aa_rbeg, &str); + kputs(tref->s, &str); + if ( !(csq_type & CSQ_SYNONYMOUS_VARIANT) ) + { + kputc_('>', &str); + kputw(aa_sbeg, &str); + kputs(tseq->s, &str); + } + kputc_('|', &str); + kputw(rec->pos+1, &str); + kputs(node.var, &str); + csq.type.vstr = str; + csq.type.type = csq_type & CSQ_COMPOUND; + csq_stage(args, &csq, rec); + + // all this only to clean vstr when vrec is flushed + if ( !tr->root ) + tr->root = (hap_node_t*) calloc(1,sizeof(hap_node_t)); + tr->root->ncsq_list++; + hts_expand0(csq_t,tr->root->ncsq_list,tr->root->mcsq_list,tr->root->csq_list); + csq_t *rm_csq = tr->root->csq_list + tr->root->ncsq_list - 1; + rm_csq->type.vstr = str; + } + if ( csq_type & ~CSQ_COMPOUND ) + { + csq.type.type = csq_type & ~CSQ_COMPOUND; + csq.type.vstr.l = 0; + csq_stage(args, &csq, rec); + } + } + free(node.seq); + free(node.var); + } + } + return ret; +} + +int test_cds(args_t *args, bcf1_t *rec) +{ + int i, ret = 0, hap_ret; + const char *chr = bcf_seqname(args->hdr,rec); + // note that the off-by-one extension of rlen is deliberate to account for insertions + if ( !regidx_overlap(args->idx_cds,chr,rec->pos,rec->pos+rec->rlen, args->itr) ) return 0; + while ( regitr_overlap(args->itr) ) + { + gf_cds_t *cds = regitr_payload(args->itr,gf_cds_t*); + tscript_t *tr = cds->tr; + if ( !GF_is_coding(tr->type) ) continue; + ret = 1; + if ( !tr->root ) + { + // initialize the transcript and its haplotype tree, fetch the reference sequence + tscript_init_ref(args, tr, chr); + + tr->root = (hap_node_t*) calloc(1,sizeof(hap_node_t)); + tr->nhap = args->phase==PHASE_DROP_GT ? 1 : 2*args->smpl->n; // maximum ploidy = diploid + tr->hap = (hap_node_t**) malloc(tr->nhap*sizeof(hap_node_t*)); + for (i=0; inhap; i++) tr->hap[i] = NULL; + tr->root->nend = tr->nhap; + tr->root->type = HAP_ROOT; + + khp_insert(trhp, args->active_tr, &tr); + } + + sanity_check_ref(args, tr, rec); + + if ( args->phase==PHASE_DROP_GT ) + { + if ( rec->d.allele[1][0]=='<' || rec->d.allele[1][0]=='*' ) { continue; } + hap_node_t *parent = tr->hap[0] ? tr->hap[0] : tr->root; + hap_node_t *child = (hap_node_t*)calloc(1,sizeof(hap_node_t)); + if ( (hap_ret=hap_init(args, parent, child, cds, rec, 1))!=0 ) + { + // overlapping or intron variant, cannot apply + if ( hap_ret==1 ) + { + if ( !args->quiet ) + fprintf(bcftools_stderr,"Warning: Skipping overlapping variants at %s:%d\t%s>%s\n", chr,rec->pos+1,rec->d.allele[0],rec->d.allele[1]); + if ( args->out ) + fprintf(args->out,"LOG\tWarning: Skipping overlapping variants at %s:%d\t%s>%s\n", chr,rec->pos+1,rec->d.allele[0],rec->d.allele[1]); + } + else ret = 1; // prevent reporting as intron in test_tscript + free(child); + continue; + } + parent->nend--; + parent->nchild = 1; + parent->mchild = 1; + parent->child = (hap_node_t**) malloc(sizeof(hap_node_t*)); + parent->child[0] = child; + tr->hap[0] = child; + tr->hap[0]->nend = 1; + continue; + } + + // apply the VCF variants and extend the haplotype tree + int j, ismpl, ihap, ngts = bcf_get_genotypes(args->hdr, rec, &args->gt_arr, &args->mgt_arr); + ngts /= bcf_hdr_nsamples(args->hdr); + if ( ngts!=1 && ngts!=2 ) + { + if ( !args->quiet ) + fprintf(bcftools_stderr,"Warning: Skipping site with non-diploid/non-haploid genotypes at %s:%d\t%s>%s\n", chr,rec->pos+1,rec->d.allele[0],rec->d.allele[1]); + if ( args->out ) + fprintf(args->out,"LOG\tWarning: Skipping site with non-diploid/non-haploid genotypes at %s:%d\t%s>%s\n", chr,rec->pos+1,rec->d.allele[0],rec->d.allele[1]); + continue; + } + for (ismpl=0; ismplsmpl->n; ismpl++) + { + int32_t *gt = args->gt_arr + args->smpl->idx[ismpl]*ngts; + if ( gt[0]==bcf_gt_missing ) continue; + + if ( ngts>1 && gt[1]!=bcf_gt_missing && gt[1]!=bcf_int32_vector_end && bcf_gt_allele(gt[0])!=bcf_gt_allele(gt[1]) ) + { + if ( args->phase==PHASE_MERGE ) + { + if ( !bcf_gt_allele(gt[0]) ) gt[0] = gt[1]; + } + if ( !bcf_gt_is_phased(gt[0]) && !bcf_gt_is_phased(gt[1]) ) + { + if ( args->phase==PHASE_REQUIRE ) + error("Unphased heterozygous genotype at %s:%d, sample %s. See the --phase option.\n", chr,rec->pos+1,args->hdr->samples[args->smpl->idx[ismpl]]); + if ( args->phase==PHASE_SKIP ) + continue; + if ( args->phase==PHASE_NON_REF ) + { + if ( !bcf_gt_allele(gt[0]) ) gt[0] = gt[1]; + else if ( !bcf_gt_allele(gt[1]) ) gt[1] = gt[0]; + } + } + } + + for (ihap=0; ihapn_allele ); + if ( rec->d.allele[ial][0]=='<' || rec->d.allele[ial][0]=='*' ) { continue; } + + hap_node_t *parent = tr->hap[i] ? tr->hap[i] : tr->root; + if ( parent->cur_rec==rec && parent->cur_child[ial]>=0 ) + { + // this haplotype has been seen in another sample + tr->hap[i] = parent->child[ parent->cur_child[ial] ]; + tr->hap[i]->nend++; + parent->nend--; + continue; + } + + hap_node_t *child = (hap_node_t*)calloc(1,sizeof(hap_node_t)); + if ( (hap_ret=hap_init(args, parent, child, cds, rec, ial))!=0 ) + { + // overlapping or intron variant, cannot apply + if ( hap_ret==1 ) + { + if ( !args->quiet ) + fprintf(bcftools_stderr,"Warning: Skipping overlapping variants at %s:%d, sample %s\t%s>%s\n", + chr,rec->pos+1,args->hdr->samples[args->smpl->idx[ismpl]],rec->d.allele[0],rec->d.allele[ial]); + if ( args->out ) + fprintf(args->out,"LOG\tWarning: Skipping overlapping variants at %s:%d, sample %s\t%s>%s\n", + chr,rec->pos+1,args->hdr->samples[args->smpl->idx[ismpl]],rec->d.allele[0],rec->d.allele[ial]); + } + free(child); + continue; + } + + if ( parent->cur_rec!=rec ) + { + hts_expand(int,rec->n_allele,parent->mcur_child,parent->cur_child); + for (j=0; jn_allele; j++) parent->cur_child[j] = -1; + parent->cur_rec = rec; + } + + j = parent->nchild++; + hts_expand0(hap_node_t*,parent->nchild,parent->mchild,parent->child); + parent->cur_child[ial] = j; + parent->child[j] = child; + tr->hap[i] = child; + tr->hap[i]->nend++; + parent->nend--; + } + } + } + return ret; +} + +void csq_stage(args_t *args, csq_t *csq, bcf1_t *rec) +{ + // known issues: tab output leads to unsorted output. This is because + // coding haplotypes are printed in one go and buffering is not used + // with tab output. VCF output is OK though. + if ( csq_push(args, csq, rec)!=0 ) return; // the consequence already exists + + int i,j,ngt = 0; + if ( args->phase!=PHASE_DROP_GT ) + { + ngt = bcf_get_genotypes(args->hdr, rec, &args->gt_arr, &args->mgt_arr); + if ( ngt>0 ) ngt /= bcf_hdr_nsamples(args->hdr); + } + if ( ngt<=0 ) + { + if ( args->output_type==FT_TAB_TEXT ) + csq_print_text(args, csq, -1,0); + return; + } + assert( ngt<=2 ); + + if ( args->output_type==FT_TAB_TEXT ) + { + for (i=0; ismpl->n; i++) + { + int32_t *gt = args->gt_arr + args->smpl->idx[i]*ngt; + for (j=0; jsmpl->idx[i],j+1); + } + } + return; + } + + vrec_t *vrec = csq->vrec; + for (i=0; ismpl->n; i++) + { + int32_t *gt = args->gt_arr + args->smpl->idx[i]*ngt; + for (j=0; jidx + j; + if ( icsq >= args->ncsq_max ) // more than ncsq_max consequences, so can't fit it in FMT + { + int ismpl = args->smpl->idx[i]; + int print_warning = 1; + if ( args->quiet ) + { + if ( args->quiet > 1 || args->ncsq_small_warned ) print_warning = 0; + args->ncsq_small_warned = 1; + } + if ( print_warning ) + { + fprintf(bcftools_stderr,"Warning: --ncsq %d is too small to annotate %s at %s:%d with %d-th csq\n", + args->ncsq_max/2,args->hdr->samples[ismpl],bcf_hdr_id2name(args->hdr,args->rid),vrec->line->pos+1,csq->idx+1); + if ( args->quiet ) fprintf(bcftools_stderr,"(This warning is printed only once)\n"); + } + break; + } + if ( vrec->nfmt < 1 + icsq/32 ) vrec->nfmt = 1 + icsq/32; + vrec->smpl[i*args->nfmt_bcsq + icsq/32] |= 1 << (icsq % 32); + } + } +} +int test_utr(args_t *args, bcf1_t *rec) +{ + const char *chr = bcf_seqname(args->hdr,rec); + // note that the off-by-one extension of rlen is deliberate to account for insertions + if ( !regidx_overlap(args->idx_utr,chr,rec->pos,rec->pos+rec->rlen, args->itr) ) return 0; + + splice_t splice; + splice_init(&splice, rec); + + int i, ret = 0; + while ( regitr_overlap(args->itr) ) + { + gf_utr_t *utr = regitr_payload(args->itr, gf_utr_t*); + tscript_t *tr = splice.tr = utr->tr; + for (i=1; in_allele; i++) + { + if ( rec->d.allele[1][0]=='<' || rec->d.allele[1][0]=='*' ) { continue; } + splice.vcf.alt = rec->d.allele[i]; + int splice_ret = splice_csq(args, &splice, utr->beg, utr->end); + if ( splice_ret!=SPLICE_INSIDE && splice_ret!=SPLICE_OVERLAP ) continue; + csq_t csq; + memset(&csq, 0, sizeof(csq_t)); + csq.pos = rec->pos; + csq.type.type = utr->which==prime5 ? CSQ_UTR5 : CSQ_UTR3; + csq.type.biotype = tr->type; + csq.type.strand = tr->strand; + csq.type.trid = tr->id; + csq.type.gene = tr->gene->name; + csq_stage(args, &csq, rec); + ret = 1; + } + } + assert(!splice.kref.s); + assert(!splice.kalt.s); + return ret; +} +int test_splice(args_t *args, bcf1_t *rec) +{ + const char *chr = bcf_seqname(args->hdr,rec); + if ( !regidx_overlap(args->idx_exon,chr,rec->pos,rec->pos + rec->rlen, args->itr) ) return 0; + + splice_t splice; + splice_init(&splice, rec); + splice.check_acceptor = splice.check_donor = 1; + + int i, ret = 0; + while ( regitr_overlap(args->itr) ) + { + gf_exon_t *exon = regitr_payload(args->itr, gf_exon_t*); + splice.tr = exon->tr; + if ( !splice.tr->ncds ) continue; // not a coding transcript, no interest in splice sites + + splice.check_region_beg = splice.tr->beg==exon->beg ? 0 : 1; + splice.check_region_end = splice.tr->end==exon->end ? 0 : 1; + + for (i=1; in_allele; i++) + { + if ( rec->d.allele[1][0]=='<' || rec->d.allele[1][0]=='*' ) { continue; } + splice.vcf.alt = rec->d.allele[i]; + splice_csq(args, &splice, exon->beg, exon->end); + if ( splice.csq ) ret = 1; + } + } + free(splice.kref.s); + free(splice.kalt.s); + return ret; +} +int test_tscript(args_t *args, bcf1_t *rec) +{ + const char *chr = bcf_seqname(args->hdr,rec); + if ( !regidx_overlap(args->idx_tscript,chr,rec->pos,rec->pos+rec->rlen, args->itr) ) return 0; + + splice_t splice; + splice_init(&splice, rec); + + int i, ret = 0; + while ( regitr_overlap(args->itr) ) + { + tscript_t *tr = splice.tr = regitr_payload(args->itr, tscript_t*); + for (i=1; in_allele; i++) + { + if ( rec->d.allele[1][0]=='<' || rec->d.allele[1][0]=='*' ) { continue; } + splice.vcf.alt = rec->d.allele[i]; + int splice_ret = splice_csq(args, &splice, tr->beg, tr->end); + if ( splice_ret!=SPLICE_INSIDE && splice_ret!=SPLICE_OVERLAP ) continue; // SPLICE_OUTSIDE or SPLICE_REF + csq_t csq; + memset(&csq, 0, sizeof(csq_t)); + csq.pos = rec->pos; + csq.type.type = GF_is_coding(tr->type) ? CSQ_INTRON : CSQ_NON_CODING; + csq.type.biotype = tr->type; + csq.type.strand = tr->strand; + csq.type.trid = tr->id; + csq.type.gene = tr->gene->name; + csq_stage(args, &csq, rec); + ret = 1; + } + } + assert(!splice.kref.s); + assert(!splice.kalt.s); + return ret; +} + +void process(args_t *args, bcf1_t **rec_ptr) +{ + if ( !rec_ptr ) + { + hap_flush(args, REGIDX_MAX); + vbuf_flush(args); + return; + } + + bcf1_t *rec = *rec_ptr; + + int call_csq = 1; + if ( !rec->n_allele ) call_csq = 0; // no alternate allele + else if ( rec->n_allele==2 && (rec->d.allele[1][0]=='<' || rec->d.allele[1][0]=='*') ) call_csq = 0; // gVCF, no alt allele + else if ( rec->d.allele[1][0]=='<' && rec->d.allele[1][0]!='*') call_csq = 0; // a symbolic allele, not ready for CNVs etc + else if ( args->filter ) + { + call_csq = filter_test(args->filter, rec, NULL); + if ( args->filter_logic==FLT_EXCLUDE ) call_csq = call_csq ? 0 : 1; + } + if ( !call_csq ) + { + if ( !args->out_fh ) return; // not a VCF output + vbuf_push(args, rec_ptr); + vbuf_flush(args); + return; + } + + if ( args->rid != rec->rid ) + { + hap_flush(args, REGIDX_MAX); + vbuf_flush(args); + } + args->rid = rec->rid; + vbuf_push(args, rec_ptr); + + int hit = args->local_csq ? test_cds_local(args, rec) : test_cds(args, rec); + hit += test_utr(args, rec); + hit += test_splice(args, rec); + if ( !hit ) test_tscript(args, rec); + + hap_flush(args, rec->pos-1); + vbuf_flush(args); + + return; +} + +static const char *usage(void) +{ + return + "\n" + "About: Haplotype-aware consequence caller.\n" + "Usage: bcftools csq [options] in.vcf\n" + "\n" + "Required options:\n" + " -f, --fasta-ref reference file in fasta format\n" + " -g, --gff-annot gff3 annotation file\n" + "\n" + "CSQ options:\n" + " -c, --custom-tag use this tag instead of the default BCSQ\n" + " -l, --local-csq localized predictions, consider only one VCF record at a time\n" + " -n, --ncsq maximum number of consequences to consider per site [16]\n" + " -p, --phase how to handle unphased heterozygous genotypes: [r]\n" + " a: take GTs as is, create haplotypes regardless of phase (0/1 -> 0|1)\n" + " m: merge *all* GTs into a single haplotype (0/1 -> 1, 1/2 -> 1)\n" + " r: require phased GTs, throw an error on unphased het GTs\n" + " R: create non-reference haplotypes if possible (0/1 -> 1|1, 1/2 -> 1|2)\n" + " s: skip unphased hets\n" + "Options:\n" + " -e, --exclude exclude sites for which the expression is true\n" + " -i, --include select sites for which the expression is true\n" + " -o, --output write output to a file [standard output]\n" + " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF\n" + " v: uncompressed VCF, t: plain tab-delimited text output [v]\n" + " -q, --quiet suppress warning messages. Can be given two times for even less messages\n" + " -r, --regions restrict to comma-separated list of regions\n" + " -R, --regions-file restrict to regions listed in a file\n" + " -s, --samples <-|list> samples to include or \"-\" to apply all variants and ignore samples\n" + " -S, --samples-file samples to include\n" + " -t, --targets similar to -r but streams rather than index-jumps\n" + " -T, --targets-file similar to -R but streams rather than index-jumps\n" + "\n" + "Example:\n" + " bcftools csq -f hs37d5.fa -g Homo_sapiens.GRCh37.82.gff3.gz in.vcf\n" + "\n" + " # GFF3 annotation files can be downloaded from Ensembl. e.g. for human:\n" + " ftp://ftp.ensembl.org/pub/current_gff3/homo_sapiens/\n" + " ftp://ftp.ensembl.org/pub/grch37/release-84/gff3/homo_sapiens/\n" + "\n"; +} + +int main_csq(int argc, char *argv[]) +{ + args_t *args = (args_t*) calloc(1,sizeof(args_t)); + args->argc = argc; args->argv = argv; + args->output_type = FT_VCF; + args->bcsq_tag = "BCSQ"; + args->ncsq_max = 2*16; + + static struct option loptions[] = + { + {"help",0,0,'h'}, + {"ncsq",1,0,'n'}, + {"custom-tag",1,0,'c'}, + {"local-csq",0,0,'l'}, + {"gff-annot",1,0,'g'}, + {"fasta-ref",1,0,'f'}, + {"include",1,0,'i'}, + {"exclude",1,0,'e'}, + {"output",1,0,'o'}, + {"output-type",1,NULL,'O'}, + {"phase",1,0,'p'}, + {"quiet",0,0,'q'}, + {"regions",1,0,'r'}, + {"regions-file",1,0,'R'}, + {"samples",1,0,'s'}, + {"samples-file",1,0,'S'}, + {"targets",1,0,'t'}, + {"targets-file",1,0,'T'}, + {0,0,0,0} + }; + int c, targets_is_file = 0, regions_is_file = 0; + char *targets_list = NULL, *regions_list = NULL; + while ((c = getopt_long(argc, argv, "?hr:R:t:T:i:e:f:o:O:g:s:S:p:qc:ln:",loptions,NULL)) >= 0) + { + switch (c) + { + case 'l': args->local_csq = 1; break; + case 'c': args->bcsq_tag = optarg; break; + case 'q': args->quiet++; break; + case 'p': + switch (optarg[0]) + { + case 'a': args->phase = PHASE_AS_IS; break; + case 'm': args->phase = PHASE_MERGE; break; + case 'r': args->phase = PHASE_REQUIRE; break; + case 'R': args->phase = PHASE_NON_REF; break; + case 's': args->phase = PHASE_SKIP; break; + default: error("The -p code \"%s\" not recognised\n", optarg); + } + break; + case 'f': args->fa_fname = optarg; break; + case 'g': args->gff_fname = optarg; break; + case 'n': + args->ncsq_max = 2 * atoi(optarg); + if ( args->ncsq_max <=0 ) error("Expected positive integer with -n, got %s\n", optarg); + break; + case 'o': args->output_fname = optarg; break; + case 'O': + switch (optarg[0]) { + case 't': args->output_type = FT_TAB_TEXT; break; + case 'b': args->output_type = FT_BCF_GZ; break; + case 'u': args->output_type = FT_BCF; break; + case 'z': args->output_type = FT_VCF_GZ; break; + case 'v': args->output_type = FT_VCF; break; + default: error("The output type \"%s\" not recognised\n", optarg); + } + break; + case 'e': args->filter_str = optarg; args->filter_logic |= FLT_EXCLUDE; break; + case 'i': args->filter_str = optarg; args->filter_logic |= FLT_INCLUDE; break; + case 'r': regions_list = optarg; break; + case 'R': regions_list = optarg; regions_is_file = 1; break; + case 's': args->sample_list = optarg; break; + case 'S': args->sample_list = optarg; args->sample_is_file = 1; break; + case 't': targets_list = optarg; break; + case 'T': targets_list = optarg; targets_is_file = 1; break; + case 'h': + case '?': error("%s",usage()); + default: error("The option not recognised: %s\n\n", optarg); break; + } + } + char *fname = NULL; + if ( optind==argc ) + { + if ( !isatty(fileno((FILE *)stdin)) ) fname = "-"; // reading from stdin + else error("%s", usage()); + } + else fname = argv[optind]; + if ( argc - optind>1 ) error("%s", usage()); + if ( !args->fa_fname ) error("Missing the --fa-ref option\n"); + if ( !args->gff_fname ) error("Missing the --gff option\n"); + args->sr = bcf_sr_init(); + if ( targets_list && bcf_sr_set_targets(args->sr, targets_list, targets_is_file, 0)<0 ) + error("Failed to read the targets: %s\n", targets_list); + if ( regions_list && bcf_sr_set_regions(args->sr, regions_list, regions_is_file)<0 ) + error("Failed to read the regions: %s\n", regions_list); + if ( !bcf_sr_add_reader(args->sr, fname) ) + error("Failed to open %s: %s\n", fname,bcf_sr_strerror(args->sr->errnum)); + args->hdr = bcf_sr_get_header(args->sr,0); + + init_data(args); + while ( bcf_sr_next_line(args->sr) ) + { + process(args, &args->sr->readers[0].buffer[0]); + } + process(args,NULL); + + destroy_data(args); + bcf_sr_destroy(args->sr); + free(args); + + return 0; +} + diff --git a/bcftools/em.c.pysam.c b/bcftools/em.c.pysam.c index 81091528e..db27d065e 100644 --- a/bcftools/em.c.pysam.c +++ b/bcftools/em.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* em.c -- mathematical functions. @@ -74,7 +74,7 @@ static double prob1(double f, void *data) minaux1_t *a = (minaux1_t*)data; double p = 1., l = 0., f3[3]; int i; -// fprintf(pysam_stdout, "brent %lg\n", f); +// fprintf(bcftools_stdout, "brent %lg\n", f); if (f < 0 || f > 1) return 1e300; f3[0] = (1.-f)*(1.-f); f3[1] = 2.*f*(1.-f); f3[2] = f*f; for (i = a->beg; i < a->end; ++i) { @@ -90,7 +90,7 @@ static double freq_iter(double *f, const double *_pdg, int beg, int end) { double f0 = *f, f3[3], err; int i; -// fprintf(pysam_stdout, "em %lg\n", *f); +// fprintf(bcftools_stdout, "em %lg\n", *f); f3[0] = (1.-f0)*(1.-f0); f3[1] = 2.*f0*(1.-f0); f3[2] = f0*f0; for (i = beg, f0 = 0.; i < end; ++i) { const double *pdg = _pdg + i * 3; @@ -128,7 +128,7 @@ static double g3_iter(double g[3], const double *_pdg, int beg, int end) double err, gg[3]; int i; gg[0] = gg[1] = gg[2] = 0.; -// fprintf(pysam_stdout, "%lg,%lg,%lg\n", g[0], g[1], g[2]); +// fprintf(bcftools_stdout, "%lg,%lg,%lg\n", g[0], g[1], g[2]); for (i = beg; i < end; ++i) { double sum, tmp[3]; const double *pdg = _pdg + i * 3; @@ -237,7 +237,7 @@ static int pair_freq_iter(int n, double *pdg[2], double f[4]) { double ff[4]; int i, k, h; -// fprintf(pysam_stdout, "%lf,%lf,%lf,%lf\n", f[0], f[1], f[2], f[3]); +// fprintf(bcftools_stdout, "%lf,%lf,%lf,%lf\n", f[0], f[1], f[2], f[3]); memset(ff, 0, 4 * sizeof(double)); for (i = 0; i < n; ++i) { double *p[2], sum, tmp; diff --git a/bcftools/filter.c b/bcftools/filter.c index c56ae6d12..53e8dc774 100644 --- a/bcftools/filter.c +++ b/bcftools/filter.c @@ -1,6 +1,6 @@ /* filter.c -- filter expressions. - Copyright (C) 2013-2015 Genome Research Ltd. + Copyright (C) 2013-2018 Genome Research Ltd. Author: Petr Danecek @@ -24,6 +24,7 @@ THE SOFTWARE. */ #include #include +#include #include #include #include @@ -34,29 +35,58 @@ THE SOFTWARE. */ #include #include +#ifndef __FUNCTION__ +# define __FUNCTION__ __func__ +#endif + +uint64_t bcf_double_missing = 0x7ff0000000000001; +uint64_t bcf_double_vector_end = 0x7ff0000000000002; +static inline void bcf_double_set(double *ptr, uint64_t value) +{ + union { uint64_t i; double d; } u; + u.i = value; + *ptr = u.d; +} +static inline int bcf_double_test(double d, uint64_t value) +{ + union { uint64_t i; double d; } u; + u.d = d; + return u.i==value ? 1 : 0; +} +#define bcf_double_set_vector_end(x) bcf_double_set(&(x),bcf_double_vector_end) +#define bcf_double_set_missing(x) bcf_double_set(&(x),bcf_double_missing) +#define bcf_double_is_vector_end(x) bcf_double_test((x),bcf_double_vector_end) +#define bcf_double_is_missing(x) bcf_double_test((x),bcf_double_missing) + + typedef struct _token_t { // read-only values, same for all VCF lines int tok_type; // one of the TOK_* keys below char *key; // set only for string constants, otherwise NULL char *tag; // for debugging and printout only, VCF tag name - float threshold; // filtering threshold + double threshold; // filtering threshold int hdr_id, type; // BCF header lookup ID and one of BCF_HT_* types - int idx; // 0-based index to VCF vectors, -1: not a vector, -2: any field ([*]) + int idx; // 0-based index to VCF vectors, + // -2: list (e.g. [0,1,2] or [1..3] or [1..] or any field[*], which is equivalent to [0..]) + int *idxs; // set indexes to 0 to exclude, to 1 to include, and last element negative if unlimited + int nidxs, nuidxs; // size of idxs array and the number of elements set to 1 + uint8_t *usmpl; // bitmask of used samples as set by idx + int nsamples; // number of samples for format fields, 0 for info and other fields void (*setter)(filter_t *, bcf1_t *, struct _token_t *); - int (*comparator)(struct _token_t *, struct _token_t *, int op_type, bcf1_t *); + int (*func)(filter_t *, bcf1_t *, struct _token_t *rtok, struct _token_t **stack, int nstack); + void (*comparator)(struct _token_t *, struct _token_t *, struct _token_t *rtok, bcf1_t *); void *hash; // test presence of str value in the hash via comparator regex_t *regex; // precompiled regex for string comparison // modified on filter evaluation at each VCF line - float *values; // In case str_value is set, values[0] is one sample's string length - char *str_value; // and values[0]*nsamples gives the total length; + double *values; + kstring_t str_value; int is_str, is_missing; // is_missing is set only for constants, variables are controled via nvalues int pass_site; // -1 not applicable, 0 fails, >0 pass uint8_t *pass_samples; // status of individual samples - int nsamples; // number of samples - int nvalues, mvalues; // number of used values, n=0 for missing values, n=1 for scalars - // for strings, total length of str_value + int nvalues, mvalues; // number of used values: n=0 for missing values, n=1 for scalars, for strings n=str_value.l + int nval1; // number of per-sample fields or string length } token_t; @@ -67,7 +97,9 @@ struct _filter_t int nfilters; token_t *filters, **flt_stack; // filtering input tokens (in RPN) and evaluation stack int32_t *tmpi; - int max_unpack, mtmpi, nsamples; + float *tmpf; + kstring_t tmps; + int max_unpack, mtmpi, mtmpf, nsamples; }; @@ -97,10 +129,11 @@ struct _filter_t #define TOK_ABS 23 #define TOK_LEN 24 #define TOK_FUNC 25 +#define TOK_CNT 26 -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 -// ( ) [ < = > ] ! | & + - * / M m a A O ~ ^ S . l -static int op_prec[] = {0,1,1,5,5,5,5,5,5,2,3, 6, 6, 7, 7, 8, 8, 8, 3, 2, 5, 5, 8, 8, 8}; +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 +// ( ) [ < = > ] ! | & + - * / M m a A O ~ ^ S . l +static int op_prec[] = {0,1,1,5,5,5,5,5,5,2,3, 6, 6, 7, 7, 8, 8, 8, 3, 2, 5, 5, 8, 8, 8, 8, 8}; #define TOKEN_STRING "x()[<=>]!|&+-*/MmaAO~^f" static int filters_next_token(char **str, int *len) @@ -127,6 +160,7 @@ static int filters_next_token(char **str, int *len) if ( !strncasecmp(tmp,"AVG(",4) ) { (*str) += 3; return TOK_AVG; } if ( !strncasecmp(tmp,"SUM(",4) ) { (*str) += 3; return TOK_SUM; } if ( !strncasecmp(tmp,"ABS(",4) ) { (*str) += 3; return TOK_ABS; } + if ( !strncasecmp(tmp,"COUNT(",4) ) { (*str) += 5; return TOK_CNT; } if ( !strncasecmp(tmp,"STRLEN(",7) ) { (*str) += 6; return TOK_LEN; } if ( !strncasecmp(tmp,"%MAX(",5) ) { (*str) += 4; return TOK_MAX; } // for backward compatibility if ( !strncasecmp(tmp,"%MIN(",5) ) { (*str) += 4; return TOK_MIN; } // for backward compatibility @@ -143,6 +177,7 @@ static int filters_next_token(char **str, int *len) return TOK_VAL; } + int square_brackets = 0; while ( tmp[0] ) { if ( tmp[0]=='"' ) break; @@ -157,11 +192,12 @@ static int filters_next_token(char **str, int *len) if ( tmp[0]=='(' ) break; if ( tmp[0]==')' ) break; if ( tmp[0]=='+' ) break; - // hacky: so that [*] is not split, the tokenizer does not recognise square brackets [] - if ( tmp[0]=='*' && (tmp==*str || tmp[-1]!='[') ) break; - if ( tmp[0]=='-' ) break; + if ( tmp[0]=='*' && !square_brackets ) break; + if ( tmp[0]=='-' && !square_brackets ) break; if ( tmp[0]=='/' ) break; if ( tmp[0]=='~' ) break; + if ( tmp[0]==']' ) { if (square_brackets) tmp++; break; } + if ( tmp[0]=='[' ) square_brackets++; tmp++; } if ( tmp > *str ) @@ -218,16 +254,16 @@ static void filters_set_qual(filter_t *flt, bcf1_t *line, token_t *tok) { float *ptr = &line->qual; if ( bcf_float_is_missing(*ptr) ) - tok->nvalues = 0; + bcf_double_set_missing(tok->values[0]); else - { - tok->values[0] = line->qual; - tok->nvalues = 1; - } + tok->values[0] = (double)line->qual; + tok->nvalues = 1; } static void filters_set_type(filter_t *flt, bcf1_t *line, token_t *tok) { tok->values[0] = bcf_get_variant_types(line); + if ( !tok->values[0] ) tok->values[0] = 1; // mistake in htslib: VCF_* should start with 1 + else tok->values[0] = ((int)tok->values[0]) << 1; tok->nvalues = 1; } static void filters_set_info(filter_t *flt, bcf1_t *line, token_t *tok) @@ -238,16 +274,19 @@ static void filters_set_info(filter_t *flt, bcf1_t *line, token_t *tok) if ( line->d.info[i].key == tok->hdr_id ) break; if ( i==line->n_info ) - tok->nvalues = 0; + tok->nvalues = tok->str_value.l = 0; else if ( line->d.info[i].type==BCF_BT_CHAR ) { int n = line->d.info[i].len; - int m = (int)tok->values[0]; - hts_expand(char,n+1,m,tok->str_value); - memcpy(tok->str_value,line->d.info[i].vptr,n); - tok->str_value[n] = 0; - tok->values[0] = m; - tok->nvalues = n; + if ( n >= tok->str_value.m ) + { + tok->str_value.m = n + 1; + tok->str_value.s = (char*) realloc(tok->str_value.s, tok->str_value.m); + if ( !tok->str_value.s ) error("Failed to alloc %d bytes\n", (int)tok->str_value.m); + } + memcpy(tok->str_value.s, line->d.info[i].vptr, n); + tok->str_value.s[n] = 0; + tok->nvalues = tok->str_value.l = n; } else if ( line->d.info[i].type==BCF_BT_FLOAT ) { @@ -257,10 +296,11 @@ static void filters_set_info(filter_t *flt, bcf1_t *line, token_t *tok) tok->values[0] = line->d.info[i].v1.f; tok->nvalues = 1; } - tok->str_value = NULL; + tok->str_value.l = 0; } else { + tok->str_value.l = 0; if ( line->d.info[i].type==BCF_BT_INT8 && line->d.info[i].v1.i==bcf_int8_missing ) tok->nvalues = 0; else if ( line->d.info[i].type==BCF_BT_INT16 && line->d.info[i].v1.i==bcf_int16_missing ) tok->nvalues = 0; else if ( line->d.info[i].type==BCF_BT_INT32 && line->d.info[i].v1.i==bcf_int32_missing ) tok->nvalues = 0; @@ -269,36 +309,53 @@ static void filters_set_info(filter_t *flt, bcf1_t *line, token_t *tok) tok->values[0] = line->d.info[i].v1.i; tok->nvalues = 1; } - tok->str_value = NULL; } } -static int filters_cmp_filter(token_t *atok, token_t *btok, int op_type, bcf1_t *line) +static void filters_cmp_bit_and(token_t *atok, token_t *btok, token_t *rtok, bcf1_t *line) +{ + int a = (int)(atok->nvalues?atok->values[0]:atok->threshold); + int b = (int)(btok->nvalues?btok->values[0]:btok->threshold); + if ( rtok->tok_type==TOK_LIKE ) + rtok->pass_site = a&b ? 1 : 0; + else + rtok->pass_site = a&b ? 0 : 1; +} +static void filters_cmp_filter(token_t *atok, token_t *btok, token_t *rtok, bcf1_t *line) { int i; - if ( op_type==TOK_NE ) // AND logic: none of the filters can match + if ( rtok->tok_type==TOK_NE ) // AND logic: none of the filters can match { if ( !line->d.n_flt ) { - if ( atok->hdr_id==-1 ) return 0; // missing value - return 1; // no filter present, eval to true + if ( atok->hdr_id==-1 ) return; // missing value + rtok->pass_site = 1; + return; // no filter present, eval to true } for (i=0; id.n_flt; i++) - if ( atok->hdr_id==line->d.flt[i] ) return 0; - return 1; + if ( atok->hdr_id==line->d.flt[i] ) return; + rtok->pass_site = 1; + return; } - // TOK_EQ with OR logic: at least one of the filters must match - if ( !line->d.n_flt ) + else if ( rtok->tok_type==TOK_EQ ) // OR logic: at least one of the filters must match { - if ( atok->hdr_id==-1 ) return 1; - return 0; // no filter present, eval to false + if ( !line->d.n_flt ) + { + if ( atok->hdr_id==-1 ) { rtok->pass_site = 1; return; } + return; // no filter present, eval to false + } + for (i=0; id.n_flt; i++) + if ( atok->hdr_id==line->d.flt[i] ) { rtok->pass_site = 1; return; } + return; } - for (i=0; id.n_flt; i++) - if ( atok->hdr_id==line->d.flt[i] ) return 1; - return 0; + else + error("Only == and != operators are supported for FILTER\n"); + return; } -static int filters_cmp_id(token_t *atok, token_t *btok, int op_type, bcf1_t *line) +static void filters_cmp_id(token_t *atok, token_t *btok, token_t *rtok, bcf1_t *line) { // multiple IDs not supported yet (easy to add though) + if ( rtok->tok_type!=TOK_EQ && rtok->tok_type!=TOK_NE ) + error("Only == and != operators are supported for ID\n"); if ( btok->hash ) { @@ -307,16 +364,19 @@ static int filters_cmp_id(token_t *atok, token_t *btok, int op_type, bcf1_t *lin if ( atok->hash ) { int ret = khash_str2int_has_key(atok->hash, line->d.id); - if ( op_type==TOK_EQ ) return ret; - return ret ? 0 : 1; + if ( rtok->tok_type==TOK_NE ) ret = ret ? 0 : 1; + rtok->pass_site = ret; + return; } - if ( op_type==TOK_EQ ) return strcmp(btok->str_value,line->d.id) ? 0 : 1; - return strcmp(btok->str_value,line->d.id) ? 1 : 0; + if ( rtok->tok_type==TOK_EQ ) + rtok->pass_site = strcmp(btok->str_value.s,line->d.id) ? 0 : 1; + else + rtok->pass_site = strcmp(btok->str_value.s,line->d.id) ? 1 : 0; } /** - * bcf_get_info_value() - get single INFO value, int or float + * bcf_get_info_value() - get single INFO value, int64_t or double * @line: BCF line * @info_id: tag ID, as returned by bcf_hdr_id2int * @ivec: 0-based index to retrieve, -1 when single value is expected @@ -336,8 +396,8 @@ static int bcf_get_info_value(bcf1_t *line, int info_id, int ivec, void *value) bcf_info_t *info = &line->d.info[j]; if ( info->len == 1 ) { - if ( info->type==BCF_BT_FLOAT ) *((float*)value) = info->v1.f; - else if ( info->type==BCF_BT_INT8 || info->type==BCF_BT_INT16 || info->type==BCF_BT_INT32 ) *((int*)value) = info->v1.i; + if ( info->type==BCF_BT_FLOAT ) *((double*)value) = info->v1.f; + else if ( info->type==BCF_BT_INT8 || info->type==BCF_BT_INT16 || info->type==BCF_BT_INT32 ) *((int64_t*)value) = info->v1.i; return 1; } @@ -354,10 +414,10 @@ static int bcf_get_info_value(bcf1_t *line, int info_id, int ivec, void *value) return 1; \ } switch (info->type) { - case BCF_BT_INT8: BRANCH(int8_t, p[j]==bcf_int8_missing, p[j]==bcf_int8_vector_end, int); break; - case BCF_BT_INT16: BRANCH(int16_t, p[j]==bcf_int16_missing, p[j]==bcf_int16_vector_end, int); break; - case BCF_BT_INT32: BRANCH(int32_t, p[j]==bcf_int32_missing, p[j]==bcf_int32_vector_end, int); break; - case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(p[j]), bcf_float_is_vector_end(p[j]), float); break; + case BCF_BT_INT8: BRANCH(int8_t, p[j]==bcf_int8_missing, p[j]==bcf_int8_vector_end, int64_t); break; + case BCF_BT_INT16: BRANCH(int16_t, p[j]==bcf_int16_missing, p[j]==bcf_int16_vector_end, int64_t); break; + case BCF_BT_INT32: BRANCH(int32_t, p[j]==bcf_int32_missing, p[j]==bcf_int32_vector_end, int64_t); break; + case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(p[j]), bcf_float_is_vector_end(p[j]), double); break; default: fprintf(stderr,"todo: type %d\n", info->type); exit(1); break; } #undef BRANCH @@ -374,14 +434,21 @@ static void filters_set_info_int(filter_t *flt, bcf1_t *line, token_t *tok) { if ( tok->idx==-2 ) { - int i, n = bcf_get_info_int32(flt->hdr,line,tok->tag,&flt->tmpi,&flt->mtmpi); - tok->nvalues = n; - hts_expand(float,n,tok->mvalues,tok->values); - for (i=0; ivalues[i] = flt->tmpi[i]; + tok->nvalues = bcf_get_info_int32(flt->hdr,line,tok->tag,&flt->tmpi,&flt->mtmpi); + if ( tok->nvalues<=0 ) tok->nvalues = 0; + else + { + hts_expand(double,tok->nvalues,tok->mvalues,tok->values); + int i, j = 0, end = tok->idxs[tok->nidxs-1] < 0 ? tok->nvalues - 1 : tok->nidxs - 1; + if ( end >= tok->nvalues ) end = tok->nvalues - 1; + for (i=0; i<=end; i++) + if ( i>=tok->nidxs || tok->idxs[i] ) tok->values[j++] = flt->tmpi[i]; + tok->nvalues = j; + } } else { - int32_t value; + int64_t value = 0; if ( bcf_get_info_value(line,tok->hdr_id,tok->idx,&value) <= 0 ) tok->nvalues = 0; else @@ -396,12 +463,26 @@ static void filters_set_info_float(filter_t *flt, bcf1_t *line, token_t *tok) { if ( tok->idx==-2 ) { - tok->nvalues = bcf_get_info_float(flt->hdr,line,tok->tag,&tok->values,&tok->mvalues); - if ( tok->nvalues<0 ) tok->nvalues = 0; + tok->nvalues = bcf_get_info_float(flt->hdr,line,tok->tag,&flt->tmpf,&flt->mtmpf); + if ( tok->nvalues<=0 ) tok->nvalues = 0; + else + { + hts_expand(double,tok->nvalues,tok->mvalues,tok->values); + int i, j = 0, end = tok->idxs[tok->nidxs-1] < 0 ? tok->nvalues - 1 : tok->nidxs - 1; + if ( end >= tok->nvalues ) end = tok->nvalues - 1; + for (i=0; i<=end; i++) + if ( i>=tok->nidxs || tok->idxs[i] ) + { + if ( bcf_float_is_missing(flt->tmpf[i]) ) bcf_double_set_missing(tok->values[j]); + else tok->values[j] = flt->tmpf[i]; + j++; + } + tok->nvalues = j; + } } else { - float value; + double value; if ( bcf_get_info_value(line,tok->hdr_id,tok->idx,&value) <= 0 ) tok->nvalues = 0; else @@ -414,33 +495,62 @@ static void filters_set_info_float(filter_t *flt, bcf1_t *line, token_t *tok) static void filters_set_info_string(filter_t *flt, bcf1_t *line, token_t *tok) { - int m = (int)tok->values[0]; - int n = bcf_get_info_string(flt->hdr,line,tok->tag,&tok->str_value,&m); - if ( n<0 ) { tok->nvalues = 0; return; } - tok->values[0] = m; // allocated length + int32_t m = tok->str_value.m; + int n = bcf_get_info_string(flt->hdr,line,tok->tag,&tok->str_value.s,&m); + tok->str_value.m = m; + if ( n<0 ) { tok->nvalues = tok->str_value.l = 0; return; } if ( tok->idx>=0 ) { // get ith field (i=tok->idx) int i = 0; - char *ss = tok->str_value, *se = tok->str_value + n; + char *ss = tok->str_value.s, *se = tok->str_value.s + n; while ( ssidx ) { if ( *ss==',' ) i++; ss++; } - if ( ss==se || i!=tok->idx ) { tok->nvalues = 0; return; } + if ( ss==se || i!=tok->idx ) { tok->nvalues = tok->str_value.l = 0; return; } se = ss; - while ( se-tok->str_valuestr_value ) *se = 0; + while ( se - tok->str_value.s < n && *se!=',' ) se++; + if ( ss==tok->str_value.s ) *se = 0; else { - memmove(tok->str_value,ss,se-ss); - tok->str_value[se-ss] = 0; + memmove(tok->str_value.s, ss, se-ss); + tok->str_value.s[se-ss] = 0; + } + tok->str_value.l = se - ss; + } + else if ( tok->idx==-2 && tok->idxs[0]==-1 ) // keep all values, TAG[*] + tok->str_value.l = n; + else if ( tok->idx==-2 ) + { + flt->tmps.l = 0; + ks_resize(&flt->tmps, n); + int i, iend = tok->idxs[tok->nidxs-1] < 0 ? n - 1 : tok->nidxs - 1; + if ( iend >= n ) iend = n - 1; + char *beg = tok->str_value.s, *dst = flt->tmps.s; + for (i=0; i<=iend; i++) + { + char *end = beg; + while ( *end && *end!=',' ) end++; + if ( i>=tok->nidxs || tok->idxs[i] ) + { + memcpy(dst, beg, end - beg); + dst += end - beg; + dst[0] = ','; + dst++; + } + beg = end+1; } - tok->nvalues = se-ss; + dst[0] = 0; + tok->str_value.l = dst - flt->tmps.s; + + #define SWAP(type_t, a, b) { type_t t = a; a = b; b = t; } + SWAP(char *, flt->tmps.s, tok->str_value.s); + SWAP(size_t, flt->tmps.m, tok->str_value.m); } - else if ( tok->idx==-2 ) tok->nvalues = n; + tok->nvalues = tok->str_value.l; } static void filters_set_info_flag(filter_t *flt, bcf1_t *line, token_t *tok) @@ -454,198 +564,358 @@ static void filters_set_info_flag(filter_t *flt, bcf1_t *line, token_t *tok) static void filters_set_format_int(filter_t *flt, bcf1_t *line, token_t *tok) { - int i; - if ( (tok->nvalues=bcf_get_format_int32(flt->hdr,line,tok->tag,&flt->tmpi,&flt->mtmpi))<0 ) + if ( line->n_sample != tok->nsamples ) + error("Incorrect number of FORMAT fields at %s:%d .. %s, %d vs %d\n", bcf_seqname(flt->hdr,line),line->pos+1,tok->tag,line->n_sample,tok->nsamples); + + int nvals; + if ( (nvals=bcf_get_format_int32(flt->hdr,line,tok->tag,&flt->tmpi,&flt->mtmpi))<0 ) + { tok->nvalues = 0; - else + return; + } + int i, nsrc1 = nvals / tok->nsamples; + tok->nval1 = tok->idx >= 0 ? 1 : (tok->nuidxs ? tok->nuidxs : nsrc1); + tok->nvalues = tok->nval1*tok->nsamples; + hts_expand(double, tok->nvalues, tok->mvalues, tok->values); + + if ( tok->idx >= 0 ) // scalar or vector index { - int is_missing = 1; - hts_expand(float,tok->nvalues,tok->mvalues,tok->values); - for (i=0; invalues; i++) + for (i=0; insamples; i++) { - if ( flt->tmpi[i]==bcf_int32_missing || flt->tmpi[i]==bcf_int32_vector_end ) - bcf_float_set_missing(tok->values[i]); + if ( !tok->usmpl[i] ) continue; + int32_t *ptr = flt->tmpi + i*nsrc1; + if ( tok->idx>=nsrc1 || ptr[tok->idx]==bcf_int32_missing || ptr[tok->idx]==bcf_int32_vector_end ) + bcf_double_set_missing(tok->values[i]); else - { - tok->values[i] = flt->tmpi[i]; - is_missing = 0; - } + tok->values[i] = ptr[tok->idx]; } - if ( is_missing ) tok->nvalues = 0; - else if ( tok->idx >= 0 ) + } + else + { + int kend = tok->idxs[tok->nidxs-1] < 0 ? tok->nval1 : tok->nidxs; + for (i=0; insamples; i++) { - int nsmpl = bcf_hdr_nsamples(flt->hdr); - int nvals = tok->nvalues / nsmpl; - if ( tok->idx >= nvals ) - tok->nvalues = 0; // the index is too big - else + if ( !tok->usmpl[i] ) continue; + int32_t *src = flt->tmpi + i*nsrc1; + double *dst = tok->values + i*tok->nval1; + int k, j = 0; + for (k=0; kvalues[i] = tok->values[i*nvals+tok->idx]; - tok->nvalues = nsmpl; + if ( knidxs && !tok->idxs[k] ) continue; + if ( src[k]==bcf_int32_missing || src[k]==bcf_int32_vector_end ) + bcf_double_set_missing(dst[j]); + else + dst[j] = src[k]; + j++; + } + while (j < tok->nval1) + { + bcf_double_set_missing(dst[j]); + j++; } } } - tok->nsamples = tok->nvalues; } static void filters_set_format_float(filter_t *flt, bcf1_t *line, token_t *tok) { - if ( (tok->nvalues=bcf_get_format_float(flt->hdr,line,tok->tag,&tok->values,&tok->mvalues))<=0 ) - tok->nvalues = tok->nsamples = 0; // missing values - else if ( tok->idx >= 0 ) - { - int i, nsmpl, nvals; - nsmpl = bcf_hdr_nsamples(flt->hdr); - nvals = tok->nvalues / nsmpl; - if ( tok->idx >= nvals ) - tok->nsamples = tok->nvalues = 0; // the index is too big - else - { - for (i=0; ivalues[i] = tok->values[i*nvals+tok->idx]; - tok->nsamples = tok->nvalues = nsmpl; - } - } - tok->nsamples = tok->nvalues; -} -static void filters_set_format_string(filter_t *flt, bcf1_t *line, token_t *tok) -{ - int ndim = tok->nsamples * (int)tok->values[0]; - int ret = bcf_get_format_char(flt->hdr,line,tok->tag,&tok->str_value,&ndim); + if ( line->n_sample != tok->nsamples ) + error("Incorrect number of FORMAT fields at %s:%d .. %s, %d vs %d\n", bcf_seqname(flt->hdr,line),line->pos+1,tok->tag,line->n_sample,tok->nsamples); - int nsmpl = bcf_hdr_nsamples(flt->hdr); - ndim /= nsmpl; - tok->values[0] = ndim; - - if ( ret<=0 ) + int nvals; + if ( (nvals=bcf_get_format_float(flt->hdr,line,tok->tag,&flt->tmpf,&flt->mtmpf))<0 ) { tok->nvalues = 0; return; } + int i, nsrc1 = nvals / tok->nsamples; + tok->nval1 = tok->idx >= 0 ? 1 : (tok->nuidxs ? tok->nuidxs : nsrc1); + tok->nvalues = tok->nval1*tok->nsamples; + hts_expand(double, tok->nvalues, tok->mvalues, tok->values); - if ( tok->idx < 0 ) // scalar + if ( tok->idx >= 0 ) // scalar or vector index { - tok->nvalues = tok->nsamples = nsmpl; - return; + for (i=0; insamples; i++) + { + if ( !tok->usmpl[i] ) continue; + float *ptr = flt->tmpf + i*nsrc1; + if ( tok->idx>=nsrc1 || bcf_float_is_missing(ptr[tok->idx]) || bcf_float_is_vector_end(ptr[tok->idx]) ) + bcf_double_set_missing(tok->values[i]); + else + tok->values[i] = ptr[tok->idx]; + } } - - // vector - int i; - for (i=0; istr_value + i*ndim; - int is = 0, ivec = 0; - while ( ivecidx && isidxs[tok->nidxs-1] < 0 ? tok->nval1 : tok->nidxs; + for (i=0; insamples; i++) { - if ( ss[is]==',' ) ivec++; - is++; + if ( !tok->usmpl[i] ) continue; + float *src = flt->tmpf + i*nsrc1; + double *dst = tok->values + i*tok->nval1; + int k, j = 0; + for (k=0; knidxs && !tok->idxs[k] ) continue; + if ( bcf_float_is_missing(src[k]) || bcf_float_is_vector_end(src[k]) ) + bcf_double_set_missing(dst[j]); + else + dst[j] = src[k]; + j++; + } + while (j < tok->nval1) + { + bcf_double_set_missing(dst[j]); + j++; + } } - if ( ivec!=tok->idx || is==ndim || !ss[is] ) + } +} +static void filters_set_format_string(filter_t *flt, bcf1_t *line, token_t *tok) +{ + if ( line->n_sample != tok->nsamples ) + error("Incorrect number of FORMAT fields at %s:%d .. %s, %d vs %d\n", bcf_seqname(flt->hdr,line),line->pos+1,tok->tag,line->n_sample,tok->nsamples); + + int i, ndim = tok->str_value.m; + int nstr = bcf_get_format_char(flt->hdr, line, tok->tag, &tok->str_value.s, &ndim); + tok->str_value.m = ndim; + tok->str_value.l = tok->nvalues = 0; + + if ( nstr<0 ) return; + + tok->nvalues = tok->str_value.l = nstr; + tok->nval1 = nstr / tok->nsamples; + for (i=0; insamples; i++) + { + if ( !tok->usmpl[i] ) continue; + char *src = tok->str_value.s + i*tok->nval1, *dst = src; + int ibeg = 0, idx = 0; + while ( ibeg < tok->nval1 ) { - ss[0] = '.'; - ss[1] = 0; - continue; + int iend = ibeg; + while ( iend < tok->nval1 && src[iend] && src[iend]!=',' ) iend++; + + int keep = 0; + if ( tok->idx >= 0 ) + { + if ( tok->idx==idx ) keep = 1; + } + else if ( idx < tok->nidxs ) + { + if ( tok->idxs[idx] != 0 ) keep = 1; + } + else if ( tok->idxs[tok->nidxs-1] < 0 ) + keep = 1; + + if ( keep ) + { + if ( ibeg!=0 ) memmove(dst, src+ibeg, iend-ibeg+1); + dst += iend - ibeg + 1; + if ( tok->idx>=0 ) break; + } + if ( !src[iend] ) break; + ibeg = iend + 1; + idx++; } - int ie = is; - while ( ienval1 ) memset(dst-1, 0, tok->nval1 - (dst - src)); } - if ( !ndim ) +} +static void _filters_set_genotype(filter_t *flt, bcf1_t *line, token_t *tok, int type) +{ + bcf_fmt_t *fmt = bcf_get_fmt(flt->hdr, line, "GT"); + if ( !fmt ) { - tok->nvalues = 0; + tok->nvalues = tok->str_value.l = 0; return; } - tok->nvalues = ret; - tok->nsamples = nsmpl; + + int i,j, nsmpl = bcf_hdr_nsamples(flt->hdr), nvals1 = type==2 ? 3 : 4; + if ( tok->str_value.m <= nvals1*nsmpl ) + { + tok->str_value.m = nvals1*nsmpl + 1; + tok->str_value.s = (char*)realloc(tok->str_value.s, tok->str_value.m); + } + +#define BRANCH_INT(type_t,vector_end) \ + { \ + for (i=0; in_sample; i++) \ + { \ + type_t *ptr = (type_t*) (fmt->p + i*fmt->size); \ + int is_het = 0, has_ref = 0, missing = 0; \ + for (j=0; jn; j++) \ + { \ + if ( ptr[j]==vector_end ) break; /* smaller ploidy */ \ + if ( bcf_gt_is_missing(ptr[j]) ) { missing=1; break; } /* missing allele */ \ + int ial = ptr[j]; \ + if ( bcf_gt_allele(ial)==0 ) has_ref = 1; \ + if ( j>0 ) \ + { \ + int jal = ptr[j-1]; \ + if ( bcf_gt_allele(ial)!=bcf_gt_allele(jal) ) is_het = 1; \ + } \ + } \ + char *dst = &tok->str_value.s[nvals1*i]; \ + if ( type==4 ) \ + { \ + if ( !j || missing ) dst[0]='m', dst[1]='i', dst[2]='s', dst[3] = 0; /* mis, missing genotype */ \ + else if ( !has_ref ) dst[0]='a', dst[1]='l', dst[2]='t', dst[3] = 0; /* alt, no ref, must have alt allele */ \ + else if ( !is_het ) dst[0]='r', dst[1]='e', dst[2]='f', dst[3] = 0; /* ref, must be ref-only, no alt alelle */ \ + else dst[0]='a', dst[1]='l', dst[2]='t', dst[3] = 0; /* alt, is het, has alt allele */ \ + } \ + else if ( !j || missing ) dst[0]='.', dst[1]=0; /* ., missing genotype */ \ + else if ( type==3 ) \ + { \ + if ( j==1 ) dst[0]='h', dst[1]='a', dst[2]='p', dst[3] = 0; /* hap, haploid */ \ + else if ( !is_het ) dst[0]='h', dst[1]='o', dst[2]='m', dst[3] = 0; /* hom */ \ + else dst[0]='h', dst[1]='e', dst[2]='t', dst[3] = 0; /* het */ \ + } \ + else \ + { \ + if ( j==1 ) \ + { \ + if ( has_ref ) dst[0]='r', dst[1]=0; /* r, haploid */ \ + else dst[0]='a', dst[1]=0; /* a, haploid */ \ + } \ + else if ( !is_het ) \ + { \ + if ( has_ref ) dst[0]='r', dst[1]='r', dst[2] = 0; /* rr */ \ + else dst[0]='a', dst[1]='a', dst[2] = 0; /* aa */ \ + } \ + else \ + { \ + if ( has_ref ) dst[0]='r', dst[1]='a', dst[2] = 0; /* ra */ \ + else dst[0]='a', dst[1]='A', dst[2] = 0; /* aA */ \ + } \ + } \ + } \ + } + switch (fmt->type) { + case BCF_BT_INT8: BRANCH_INT(int8_t, bcf_int8_vector_end); break; + case BCF_BT_INT16: BRANCH_INT(int16_t, bcf_int16_vector_end); break; + case BCF_BT_INT32: BRANCH_INT(int32_t, bcf_int32_vector_end); break; + default: error("The GT type is not lineognised: %d at %s:%d\n",fmt->type, bcf_seqname(flt->hdr,line),line->pos+1); break; + } +#undef BRANCH_INT + assert( tok->nsamples == nsmpl ); + tok->nvalues = tok->str_value.l = nvals1*nsmpl; + tok->str_value.s[tok->str_value.l] = 0; + tok->nval1 = nvals1; } +static void filters_set_genotype2(filter_t *flt, bcf1_t *line, token_t *tok) { _filters_set_genotype(flt, line, tok, 2); } +static void filters_set_genotype3(filter_t *flt, bcf1_t *line, token_t *tok) { _filters_set_genotype(flt, line, tok, 3); } +static void filters_set_genotype4(filter_t *flt, bcf1_t *line, token_t *tok) { _filters_set_genotype(flt, line, tok, 4); } + static void filters_set_genotype_string(filter_t *flt, bcf1_t *line, token_t *tok) { bcf_fmt_t *fmt = bcf_get_fmt(flt->hdr, line, "GT"); if ( !fmt ) { - tok->nvalues = tok->nsamples = 0; + tok->nvalues = 0; return; } - int i, blen = 3, nsmpl = bcf_hdr_nsamples(flt->hdr); - kstring_t str; + int i, blen = 4, nsmpl = line->n_sample; gt_length_too_big: - str.s = tok->str_value; str.m = tok->values[0] * nsmpl; str.l = 0; + tok->str_value.l = 0; for (i=0; ip + i*fmt->size); \ - if ( !(ptr[0]>>1) ) kputc('.',&str); \ - } - switch (fmt->type) { - case BCF_BT_INT8: BRANCH(int8_t); break; - case BCF_BT_INT16: BRANCH(int16_t); break; - case BCF_BT_INT32: BRANCH(int32_t); break; - default: fprintf(stderr,"FIXME: type %d in bcf_format_gt?\n", fmt->type); abort(); break; - } - #undef BRANCH - - if ( plen==str.l ) + size_t plen = tok->str_value.l; + bcf_format_gt(fmt, i, &tok->str_value); + kputc_(0, &tok->str_value); + if ( tok->str_value.l - plen > blen ) { - bcf_format_gt(fmt, i, &str); - if ( str.l - plen > blen ) - { - // too many alternate alleles or ploidy is too large, the genotype does not fit - // three characters ("0/0" vs "10/10"). - tok->str_value = str.s; - blen *= 2; - goto gt_length_too_big; - } + // too many alternate alleles or ploidy is too large, the genotype does not fit + // three characters ("0/0" vs "10/10"). + blen *= 2; + goto gt_length_too_big; } - plen = str.l - plen; - while ( plenstr_value.l - plen; + while ( plen < blen ) { - kputc_(0, &str); + kputc_(0, &tok->str_value); plen++; } } - tok->nvalues = str.l; - tok->nsamples = nsmpl; - tok->values[0] = blen; - tok->str_value = str.s; + assert( tok->nsamples == nsmpl ); + tok->nvalues = tok->str_value.l; + tok->nval1 = blen; } static void filters_set_ref_string(filter_t *flt, bcf1_t *line, token_t *tok) { - kstring_t str; str.s = tok->str_value; str.m = tok->values[0]; str.l = 0; - kputs(line->d.allele[0], &str); - tok->nvalues = str.l; - tok->values[0] = str.m; - tok->str_value = str.s; + tok->str_value.l = 0; + kputs(line->d.allele[0], &tok->str_value); + tok->nvalues = tok->str_value.l; } static void filters_set_alt_string(filter_t *flt, bcf1_t *line, token_t *tok) { - kstring_t str; str.s = tok->str_value; str.m = tok->values[0]; str.l = 0; + tok->str_value.l = 0; if ( tok->idx>=0 ) { - if ( line->n_allele >= tok->idx ) - kputs(line->d.allele[tok->idx], &str); + if ( line->n_allele > tok->idx + 1 ) + kputs(line->d.allele[tok->idx + 1], &tok->str_value); else - kputc('.', &str); + kputc('.', &tok->str_value); + tok->idx = 0; + } + else if ( tok->idx==-2 ) + { + int i, end = tok->nuidxs ? tok->nuidxs : line->n_allele - 1; + if ( end >= line->n_allele - 1 ) end = line->n_allele - 2; + for (i=0; i<=end; i++) + if ( i>=tok->nidxs || tok->idxs[i] ) + { + if ( tok->str_value.l ) kputc(',', &tok->str_value); + kputs(line->d.allele[i+1], &tok->str_value); + } } else if ( line->n_allele>1 ) { - kputs(line->d.allele[1], &str); + kputs(line->d.allele[1], &tok->str_value); int i; for (i=2; in_allele; i++) { - kputc(',', &str); - kputs(line->d.allele[i], &str); + kputc(',', &tok->str_value); + kputs(line->d.allele[i], &tok->str_value); } } else if ( line->n_allele==1 ) - kputc('.', &str); - tok->nvalues = str.l; - tok->values[0] = str.m; - tok->str_value = str.s; + kputc('.', &tok->str_value); + tok->nvalues = tok->str_value.l; +} +static void filters_set_nmissing(filter_t *flt, bcf1_t *line, token_t *tok) +{ + bcf_unpack(line, BCF_UN_FMT); + if ( !line->n_sample ) + { + tok->nvalues = 1; + tok->values[0] = 0; + return; + } + + int i,igt = bcf_hdr_id2int(flt->hdr, BCF_DT_ID, "GT"); + bcf_fmt_t *fmt = NULL; + for (i=0; in_fmt; i++) + if ( line->d.fmt[i].id==igt ) { fmt = &line->d.fmt[i]; break; } + if ( !fmt ) + { + tok->nvalues = 0; + return; + } + if ( fmt->type!=BCF_BT_INT8 ) error("TODO: the GT fmt_type is not int8\n"); + + int j,nmissing = 0; + for (i=0; in_sample; i++) + { + int8_t *ptr = (int8_t*) (fmt->p + i*fmt->size); + for (j=0; jn; j++) + { + if ( ptr[j]==bcf_int8_vector_end ) break; + if ( ptr[j]==bcf_gt_missing ) { nmissing++; break; } + } + } + tok->nvalues = 1; + tok->values[0] = tok->tag[0]=='N' ? nmissing : (double)nmissing / line->n_sample; } static void filters_set_nalt(filter_t *flt, bcf1_t *line, token_t *tok) { @@ -680,7 +950,7 @@ static void filters_set_ac(filter_t *flt, bcf1_t *line, token_t *tok) } else { - hts_expand(float,line->n_allele,tok->mvalues,tok->values); + hts_expand(double,line->n_allele,tok->mvalues,tok->values); for (i=1; in_allele; i++) tok->values[i-1] = flt->tmpi[i]; tok->nvalues = line->n_allele - 1; @@ -706,7 +976,7 @@ static void filters_set_af(filter_t *flt, bcf1_t *line, token_t *tok) if ( !tok->nvalues ) return; int i, an = flt->tmpi[0]; for (i=0; invalues; i++) - tok->values[i] /= (float)an; + tok->values[i] /= (double)an; } static void filters_set_maf(filter_t *flt, bcf1_t *line, token_t *tok) { @@ -715,262 +985,311 @@ static void filters_set_maf(filter_t *flt, bcf1_t *line, token_t *tok) int i, an = flt->tmpi[0]; for (i=0; invalues; i++) { - tok->values[i] /= (float)an; + tok->values[i] /= (double)an; if ( tok->values[i] > 0.5 ) tok->values[i] = 1 - tok->values[i]; } } -static void set_max(filter_t *flt, bcf1_t *line, token_t *tok) +static int func_max(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - float val = -HUGE_VAL; - int i; + token_t *tok = stack[nstack - 1]; + rtok->nvalues = 0; + if ( !tok->nvalues ) return 1; + double val = -HUGE_VAL; + int i, has_value = 0; for (i=0; invalues; i++) { - if ( !bcf_float_is_missing(tok->values[i]) && val < tok->values[i] ) val = tok->values[i]; + if ( bcf_double_is_missing(tok->values[i]) || bcf_double_is_vector_end(tok->values[i]) ) continue; + has_value = 1; + if ( val < tok->values[i] ) val = tok->values[i]; } - tok->values[0] = val; - tok->nvalues = 1; - tok->nsamples = 0; + if ( has_value ) + { + rtok->values[0] = val; + rtok->nvalues = has_value; + } + return 1; } -static void set_min(filter_t *flt, bcf1_t *line, token_t *tok) +static int func_min(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - float val = HUGE_VAL; - int i; + token_t *tok = stack[nstack - 1]; + rtok->nvalues = 0; + if ( !tok->nvalues ) return 1; + double val = HUGE_VAL; + int i, has_value = 0; for (i=0; invalues; i++) - if ( !bcf_float_is_missing(tok->values[i]) && val > tok->values[i] ) val = tok->values[i]; - tok->values[0] = val; - tok->nvalues = 1; - tok->nsamples = 0; + { + if ( bcf_double_is_missing(tok->values[i]) || bcf_double_is_vector_end(tok->values[i]) ) continue; + has_value = 1; + if ( val > tok->values[i] ) val = tok->values[i]; + } + if ( has_value ) + { + rtok->values[0] = val; + rtok->nvalues = has_value; + } + return 1; } -static void set_avg(filter_t *flt, bcf1_t *line, token_t *tok) +static int func_avg(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - float val = 0; + token_t *tok = stack[nstack - 1]; + rtok->nvalues = 0; + if ( !tok->nvalues ) return 1; + double val = 0; int i, n = 0; for (i=0; invalues; i++) - if ( !bcf_float_is_missing(tok->values[i]) ) { val += tok->values[i]; n++; } - tok->values[0] = n ? val / n : 0; - tok->nvalues = 1; - tok->nsamples = 0; + if ( !bcf_double_is_missing(tok->values[i]) ) { val += tok->values[i]; n++; } + if ( n ) + { + rtok->values[0] = val / n; + rtok->nvalues = 1; + } + return 1; } -static void set_sum(filter_t *flt, bcf1_t *line, token_t *tok) +static int func_sum(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - float val = 0; + rtok->nvalues = 0; + token_t *tok = stack[nstack - 1]; + if ( !tok->nvalues ) return 1; + double val = 0; int i, n = 0; for (i=0; invalues; i++) - if ( !bcf_float_is_missing(tok->values[i]) ) { val += tok->values[i]; n++; } - tok->values[0] = val; - tok->nvalues = 1; - tok->nsamples = 0; + if ( !bcf_double_is_missing(tok->values[i]) ) { val += tok->values[i]; n++; } + if ( n ) + { + rtok->values[0] = val; + rtok->nvalues = 1; + } + return 1; } -static void set_abs(filter_t *flt, bcf1_t *line, token_t *tok) +static int func_abs(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { + token_t *tok = stack[nstack - 1]; if ( tok->is_str ) error("ABS() can be applied only on numeric values\n"); + + rtok->nvalues = tok->nvalues; + if ( !tok->nvalues ) return 1; + hts_expand(double, rtok->nvalues, rtok->mvalues, rtok->values); int i; for (i=0; invalues; i++) - tok->values[i] = fabs(tok->values[i]); + if ( bcf_double_is_missing(tok->values[i]) ) bcf_double_set_missing(rtok->values[i]); + else rtok->values[i] = fabs(tok->values[i]); + return 1; } -static void set_strlen(filter_t *flt, bcf1_t *line, token_t *tok) +static int func_count(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - tok->is_str = 0; - if ( !tok->nvalues ) return; + token_t *tok = stack[nstack - 1]; + if ( !tok->nsamples ) error("COUNT() can be applied only on FORMAT fields\n"); + + int i, cnt = 0; + for (i=0; insamples; i++) + if ( tok->pass_samples[i] ) cnt++; + + rtok->nvalues = 1; + rtok->values[0] = cnt; + return 1; +} +static int func_strlen(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) +{ + token_t *tok = stack[nstack - 1]; + rtok->nvalues = rtok->str_value.l = 0; + if ( !tok->str_value.l ) return 1; + if ( tok->idx==-2 ) { int i = 0; - char *ss = tok->str_value; + char *ss = tok->str_value.s; while ( *ss ) { char *se = ss; while ( *se && *se!=',' ) se++; - if ( !*se ) tok->values[i] = strlen(ss); + hts_expand(double, i+1, rtok->mvalues, rtok->values); + if ( !*se ) rtok->values[i] = strlen(ss); else { *se = 0; - tok->values[i] = strlen(ss); + rtok->values[i] = strlen(ss); *se = ','; } ss = *se ? se + 1 : se; i++; } - tok->nvalues = i; + rtok->nvalues = i; } else { - tok->values[0] = strlen(tok->str_value); - tok->nvalues = 1; + rtok->values[0] = strlen(tok->str_value.s); + rtok->nvalues = 1; } + return 1; +} +inline static void tok_init_values(token_t *atok, token_t *btok, token_t *rtok) +{ + token_t *tok = atok->nvalues > btok->nvalues ? atok : btok; + rtok->nvalues = tok->nvalues; + rtok->nval1 = tok->nval1; + hts_expand(double*, rtok->nvalues, rtok->mvalues, rtok->values); } -#define VECTOR_ARITHMETICS(atok,btok,AOP) \ +inline static void tok_init_samples(token_t *atok, token_t *btok, token_t *rtok) +{ + if ( (atok->nsamples || btok->nsamples) && !rtok->nsamples ) + { + rtok->nsamples = atok->nsamples ? atok->nsamples : btok->nsamples; + rtok->usmpl = (uint8_t*) calloc(rtok->nsamples,1); + int i; + for (i=0; insamples; i++) rtok->usmpl[i] |= atok->usmpl[i]; + for (i=0; insamples; i++) rtok->usmpl[i] |= btok->usmpl[i]; + } + memset(rtok->pass_samples, 0, rtok->nsamples); +} + +#define VECTOR_ARITHMETICS(atok,btok,_rtok,AOP) \ { \ + token_t *rtok = _rtok; \ int i, has_values = 0; \ - if ( !(atok)->nvalues || !(btok)->nvalues ) /* missing values */ \ - { \ - (atok)->nvalues = 0; (atok)->nsamples = 0; \ - } \ - else \ + if ( atok->nvalues && btok->nvalues ) \ { \ - if ( ((atok)->nsamples && (btok)->nsamples) || (!(atok)->nsamples && !(btok)->nsamples)) \ + tok_init_values(atok, btok, rtok); \ + tok_init_samples(atok, btok, rtok); \ + if ( (atok->nsamples && btok->nsamples) || (!atok->nsamples && !btok->nsamples)) \ { \ - for (i=0; i<(atok)->nvalues; i++) \ + assert( atok->nsamples==btok->nsamples ); \ + for (i=0; invalues; i++) \ { \ - if ( bcf_float_is_missing((atok)->values[i]) ) continue; \ - if ( bcf_float_is_missing((btok)->values[i]) ) { bcf_float_set_missing((atok)->values[i]); continue; } \ - has_values = 1; \ - (atok)->values[i] = (atok)->values[i] AOP (btok)->values[i]; \ - } \ - } \ - else if ( (btok)->nsamples ) \ - { \ - hts_expand(float,(btok)->nvalues,(atok)->mvalues,(atok)->values); \ - for (i=0; i<(btok)->nvalues; i++) \ - { \ - if ( bcf_float_is_missing((atok)->values[0]) || bcf_float_is_missing((btok)->values[i]) ) \ + if ( bcf_double_is_missing(atok->values[i]) || bcf_double_is_missing(btok->values[i]) ) \ { \ - bcf_float_set_missing((atok)->values[i]); \ + bcf_double_set_missing(rtok->values[i]); \ continue; \ } \ has_values = 1; \ - (atok)->values[i] = (atok)->values[0] AOP (btok)->values[i]; \ + rtok->values[i] = atok->values[i] AOP btok->values[i]; \ } \ - (atok)->nvalues = (btok)->nvalues; \ - (atok)->nsamples = (btok)->nsamples; \ } \ - else if ( (atok)->nsamples ) \ + else \ { \ - for (i=0; i<(atok)->nvalues; i++) \ + token_t *xtok = atok->nsamples ? atok : btok; \ + token_t *ytok = atok->nsamples ? btok : atok; \ + assert( ytok->nvalues==1 ); \ + if ( !bcf_double_is_missing(ytok->values[0]) ) \ { \ - if ( bcf_float_is_missing((atok)->values[i]) || bcf_float_is_missing((btok)->values[0]) ) \ + for (i=0; invalues; i++) \ { \ - bcf_float_set_missing((atok)->values[i]); \ - continue; \ + if ( bcf_double_is_missing(xtok->values[i]) ) \ + { \ + bcf_double_set_missing(rtok->values[i]); \ + continue; \ + } \ + has_values = 1; \ + rtok->values[i] = xtok->values[i] AOP ytok->values[0]; \ } \ - has_values = 1; \ - (atok)->values[i] = (atok)->values[i] AOP (btok)->values[0]; \ } \ } \ } \ - if ( !has_values ) { (atok)->nvalues = 0; (atok)->nsamples = 0; } \ + if ( !has_values ) rtok->nvalues = 0; \ } -static int vector_logic_and(token_t *atok, token_t *btok, int and_type) +static int vector_logic_or(filter_t *filter, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - // We are comparing either two scalars (result of INFO tag vs a threshold), two vectors (two FORMAT fields), - // or a vector and a scalar (FORMAT field vs threshold) - int i, pass_site = 0; - if ( !atok->nvalues || !btok->nvalues ) - { - atok->nvalues = atok->nsamples = 0; - return 0; - } - if ( !atok->nsamples && !btok->nsamples ) return atok->pass_site && btok->pass_site; - if ( atok->nsamples && btok->nsamples ) + token_t *atok = stack[nstack-2]; + token_t *btok = stack[nstack-1]; + tok_init_samples(atok, btok, rtok); + + if ( !atok->pass_site && !btok->pass_site ) return 2; + + rtok->pass_site = 1; + if ( !atok->nsamples && !btok->nsamples ) return 2; + + int i; + if ( rtok->tok_type==TOK_OR_VEC ) // ||, select all samples if one is true { - if ( and_type==TOK_AND ) + if ( (!atok->nsamples && !atok->pass_site) || (!btok->nsamples && !btok->pass_site) ) { - // perform AND within a sample - for (i=0; insamples; i++) + // These two conditions are to ensure the following does not set all samples + // at sites with QUAL<=30: + // QUAL>30 || FMT/GQ>30 + + token_t *tok = atok->nsamples ? atok : btok; + for (i=0; insamples; i++) { - atok->pass_samples[i] = atok->pass_samples[i] && btok->pass_samples[i]; - if ( !pass_site && atok->pass_samples[i] ) pass_site = 1; + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = tok->pass_samples[i]; } } else { - // perform AND across samples - int pass_a = 0, pass_b = 0; - for (i=0; insamples; i++) + for (i=0; insamples; i++) { - if ( atok->pass_samples[i] ) pass_a = 1; - atok->pass_samples[i] = atok->pass_samples[i] && btok->pass_samples[i]; + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = 1; } - for (i=0; insamples; i++) - { - if ( btok->pass_samples[i] ) { pass_b = 1; break; } - } - pass_site = pass_a && pass_b; } - return pass_site; + return 2; } - if ( btok->nsamples ) + + // |, only select samples which are actually true + + if ( !atok->nsamples || !btok->nsamples ) { - for (i=0; insamples; i++) + token_t *tok = atok->nsamples ? atok : btok; + for (i=0; insamples; i++) { - atok->pass_samples[i] = atok->pass_site && btok->pass_samples[i]; - if ( !pass_site && atok->pass_samples[i] ) pass_site = 1; + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = tok->pass_samples[i]; } - atok->nsamples = btok->nsamples; - return pass_site; + return 2; } - /* atok->nsamples!=0 */ - for (i=0; insamples; i++) + + assert( atok->nsamples==btok->nsamples ); + + for (i=0; insamples; i++) { - atok->pass_samples[i] = atok->pass_samples[i] && btok->pass_site; - if ( !pass_site && atok->pass_samples[i] ) pass_site = 1; + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = atok->pass_samples[i] | btok->pass_samples[i]; } - return pass_site; + return 2; } -static int vector_logic_or(token_t *atok, token_t *btok, int or_type) +static int vector_logic_and(filter_t *filter, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - int i, pass_site = 0; - if ( !atok->nvalues && !btok->nvalues ) // missing sites in both - { - atok->nvalues = atok->nsamples = 0; - return 0; - } - if ( !atok->nvalues ) // missing value in a - { - for (i=0; insamples; i++) - atok->pass_samples[i] = btok->pass_samples[i]; - atok->nsamples = btok->nsamples; - return btok->pass_site; - } - if ( !btok->nvalues ) // missing value in b - return atok->pass_site; + token_t *atok = stack[nstack-2]; + token_t *btok = stack[nstack-1]; + tok_init_samples(atok, btok, rtok); + + if ( !atok->pass_site || !btok->pass_site ) return 2; + if ( !atok->nsamples && !btok->nsamples ) { rtok->pass_site = 1; return 2; } - if ( !atok->nsamples && !btok->nsamples ) return atok->pass_site || btok->pass_site; - if ( !atok->nsamples ) + int i; + if ( !atok->nsamples || !btok->nsamples ) { - if ( or_type==TOK_OR ) + token_t *tok = atok->nsamples ? atok : btok; + for (i=0; insamples; i++) { - for (i=0; insamples; i++) - { - atok->pass_samples[i] = btok->pass_samples[i]; - if ( atok->pass_site || atok->pass_samples[i] ) pass_site = 1; - } - } - else - { - for (i=0; insamples; i++) - { - atok->pass_samples[i] = atok->pass_site || btok->pass_samples[i]; - if ( atok->pass_samples[i] ) pass_site = 1; - } + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = tok->pass_samples[i]; } - atok->nsamples = btok->nsamples; - return pass_site; + rtok->pass_site = 1; + return 2; } - if ( !btok->nsamples ) // vector vs site + + assert( atok->nsamples==btok->nsamples ); + if ( rtok->tok_type==TOK_AND_VEC ) // &&, can be true in different samples { - if ( or_type==TOK_OR ) - { - for (i=0; insamples; i++) - if ( btok->pass_site || atok->pass_samples[i] ) pass_site = 1; - } - else + for (i=0; insamples; i++) { - for (i=0; insamples; i++) - { - atok->pass_samples[i] = atok->pass_samples[i] || btok->pass_site; - if ( atok->pass_samples[i] ) pass_site = 1; - } + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = atok->pass_samples[i] | btok->pass_samples[i]; } - return pass_site; + rtok->pass_site = 1; } - for (i=0; insamples; i++) + else // &, must be true within one sample { - atok->pass_samples[i] = atok->pass_samples[i] || btok->pass_samples[i]; - if ( !pass_site && atok->pass_samples[i] ) pass_site = 1; + for (i=0; insamples; i++) + { + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = atok->pass_samples[i] & btok->pass_samples[i]; + if ( rtok->pass_samples[i] ) rtok->pass_site = 1; + } } - return pass_site; + return 2; } #define CMP_MISSING(atok,btok,CMP_OP,ret) \ @@ -978,164 +1297,397 @@ static int vector_logic_or(token_t *atok, token_t *btok, int or_type) if ( (atok)->nsamples || (btok)->nsamples ) error("todo: Querying of missing values in FORMAT\n"); \ token_t *tok = (atok)->is_missing ? (btok) : (atok); \ (ret) = ( tok->nvalues CMP_OP 1 ) ? 0 : 1; \ + tok->nvalues = 1; \ } -#define CMP_VECTORS(atok,btok,CMP_OP,ret) \ +#define CMP_VECTORS(atok,btok,_rtok,CMP_OP,missing_logic) \ { \ - int i, j, has_values = 0, pass_site = 0; \ - if ( !(atok)->nvalues || !(btok)->nvalues ) { (atok)->nvalues = 0; (atok)->nsamples = 0; (ret) = 0; } \ - else \ + token_t *rtok = _rtok; \ + int i, j, k; \ + assert( !atok->nsamples || !btok->nsamples ); \ + tok_init_samples(atok, btok, rtok); \ + if ( !atok->nsamples && !btok->nsamples ) \ { \ - if ( (atok)->nsamples && (btok)->nsamples ) \ + if ( !atok->nvalues && !btok->nvalues ) { rtok->pass_site = missing_logic[2]; } \ + else if ( !atok->nvalues || !btok->nvalues ) \ { \ - for (i=0; i<(atok)->nsamples; i++) \ + token_t *tok = atok->nvalues ? atok : btok; \ + for (j=0; jnvalues; j++) \ { \ - if ( bcf_float_is_missing((atok)->values[i]) ) { (atok)->pass_samples[i] = 0; continue; } \ - if ( bcf_float_is_missing((btok)->values[i]) ) { (atok)->pass_samples[i] = 0; continue; } \ - has_values = 1; \ - if ( (atok)->values[i] CMP_OP (btok)->values[i] ) { (atok)->pass_samples[i] = 1; pass_site = 1; } \ - else (atok)->pass_samples[i] = 0; \ + if ( bcf_double_is_missing(tok->values[j]) ) \ + { \ + if ( missing_logic[2] ) { rtok->pass_site = 1; break; } \ + } \ + else if ( missing_logic[1] ) { rtok->pass_site = 1; break; } \ } \ - if ( !has_values ) (atok)->nvalues = 0; \ } \ - else if ( (atok)->nsamples ) \ + else \ { \ - if ( bcf_float_is_missing((btok)->values[0]) ) { (atok)->nvalues = 0; (atok)->nsamples = 0; (ret) = 0; } \ - else \ + for (i=0; invalues; i++) \ { \ - for (i=0; i<(atok)->nsamples; i++) \ + int amiss = bcf_double_is_missing(atok->values[i]) ? 1 : 0; \ + for (j=0; jnvalues; j++) \ { \ - if ( bcf_float_is_missing((atok)->values[i]) ) { (atok)->pass_samples[i] = 0; continue; } \ - has_values = 1; \ - if ( (atok)->values[i] CMP_OP (btok)->values[0] ) { (atok)->pass_samples[i] = 1; pass_site = 1; } \ - else (atok)->pass_samples[i] = 0; \ + int nmiss = amiss + (bcf_double_is_missing(btok->values[j]) ? 1 : 0); \ + if ( nmiss ) \ + { \ + if ( missing_logic[nmiss] ) { rtok->pass_site = 1; i = atok->nvalues; break; } \ + } \ + else if ( atok->values[i] CMP_OP btok->values[j] ) { rtok->pass_site = 1; i = atok->nvalues; break; } \ } \ } \ - if ( !has_values ) (atok)->nvalues = 0; \ } \ - else if ( (btok)->nsamples ) \ + } \ + else \ + { \ + if ( !atok->nvalues && !btok->nvalues ) \ { \ - if ( bcf_float_is_missing((atok)->values[0]) ) { (atok)->nvalues = 0; (atok)->nsamples = 0; (ret) = 0; } \ - else \ + if ( missing_logic[2] ) \ { \ - for (i=0; i<(btok)->nsamples; i++) \ - { \ - if ( bcf_float_is_missing((btok)->values[i]) ) { (atok)->pass_samples[i] = 0; continue; } \ - has_values = 1; \ - if ( (atok)->values[0] CMP_OP (btok)->values[i] ) { (atok)->pass_samples[i] = 1; pass_site = 1; } \ - else (atok)->pass_samples[i] = 0; \ - } \ - (atok)->nvalues = (btok)->nvalues; \ - (atok)->nsamples = (btok)->nsamples; \ + for (i=0; insamples; i++) \ + if ( rtok->usmpl[i] ) { rtok->pass_samples[i] = missing_logic[2]; rtok->pass_site = 1; } \ } \ - if ( !has_values ) (atok)->nvalues = 0; \ } \ - else if ( (atok)->idx==-2 || (btok)->idx==-2 ) \ + else if ( !atok->nvalues || !btok->nvalues ) \ { \ - /* any field can match: [*] */ \ - for (i=0; i<(atok)->nvalues; i++) \ + token_t *tok = atok->nvalues ? atok : btok; \ + if ( !tok->nsamples ) \ { \ - for (j=0; j<(btok)->nvalues; j++) \ - if ( (atok)->values[i] CMP_OP (btok)->values[j] ) { pass_site = 1; i = (atok)->nvalues; break; } \ + int miss = 0; \ + for (j=0; jnvalues; j++) \ + miss |= bcf_double_is_missing(tok->values[j]) ? 1 : 0; \ + if ( missing_logic[++miss] ) \ + { \ + for (i=0; insamples; i++) \ + if ( rtok->usmpl[i] ) { rtok->pass_samples[i] = missing_logic[miss]; rtok->pass_site = 1; } \ + } \ } \ + else \ + for (i=0; insamples; i++) \ + { \ + if ( !rtok->usmpl[i] ) continue; \ + double *ptr = tok->values + i*tok->nval1; \ + int miss = 0; \ + for (j=0; jnval1; j++) \ + miss |= bcf_double_is_missing(ptr[j]) ? 1 : 0; \ + if ( missing_logic[++miss] ) { rtok->pass_samples[i] = missing_logic[miss]; rtok->pass_site = 1; } \ + } \ } \ else \ { \ - if ( (atok)->values[0] CMP_OP (btok)->values[0] ) { pass_site = 1; } \ + token_t *xtok = atok->nsamples ? atok : btok; \ + token_t *ytok = atok->nsamples ? btok : atok; \ + for (i=0; insamples; i++) \ + { \ + if ( !rtok->usmpl[i] ) continue; \ + double *xptr = xtok->values + i*xtok->nval1; \ + double *yptr = ytok->values + i*ytok->nval1; \ + for (j=0; jnval1; j++) \ + { \ + int miss = bcf_double_is_missing(xptr[j]) ? 1 : 0; \ + if ( miss && !missing_logic[0] ) continue; /* any is missing => result is false */ \ + for (k=0; knvalues; k++) \ + { \ + int nmiss = miss + (bcf_double_is_missing(yptr[k]) ? 1 : 0); \ + if ( nmiss ) \ + { \ + if ( missing_logic[nmiss] ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; j = xtok->nval1; break; } \ + } \ + else if ( xptr[j] CMP_OP yptr[k] ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; j = xtok->nval1; break; } \ + } \ + } \ + } \ } \ - /*fprintf(stderr,"pass=%d\n", pass_site);*/ \ - (ret) = pass_site; \ } \ } -static int cmp_vector_strings(token_t *atok, token_t *btok, int logic) // logic: TOK_EQ or TOK_NE +static int _regex_vector_strings(regex_t *regex, char *str, size_t len, int logic, int *missing_logic) { - if ( !atok->nvalues ) { return 0; } - if ( !btok->nvalues ) { atok->nvalues = 0; return 0; } - int i, pass_site = 0; - if ( atok->nsamples && atok->nsamples==btok->nsamples ) - { - for (i=0; insamples; i++) - { - char *astr = atok->str_value + i*(int)atok->values[0]; - char *bstr = btok->str_value + i*(int)btok->values[0]; - char *aend = astr + (int)atok->values[0], *a = astr; - while ( avalues[0], *b = bstr; - while ( bpass_samples[i] = 0; - else atok->pass_samples[i] = strncmp(astr,bstr,a-astr)==0 ? 1 : 0; - if ( logic!=TOK_EQ ) - atok->pass_samples[i] = atok->pass_samples[i] ? 0 : 1; - pass_site |= atok->pass_samples[i]; - } - if ( !atok->nsamples ) atok->nsamples = btok->nsamples; - } - else if ( !atok->nsamples && !btok->nsamples ) - { - if ( atok->idx==-2 || btok->idx==-2 ) - { - // any field can match: [*] - if ( atok->idx==-2 && btok->idx==-2 ) - error("fixme: Expected at least one scalar value [%s %s %s]\n", atok->tag ? atok->tag : btok->tag, atok->str_value,btok->str_value); - token_t *xtok, *ytok; // xtok is scalar, ytok array - if ( btok->idx==-2 ) { xtok = atok; ytok = btok; } - else { xtok = btok; ytok = atok; } - char *xstr = xtok->str_value, *xend = xstr + xtok->nvalues; - char *ystr = ytok->str_value, *yend = ystr + ytok->nvalues, *y = ystr; - while ( y<=yend ) + char *end = str + len; + while ( str < end && *str ) + { + char *mid = str; + while ( mid < end && *mid && *mid!=',' ) mid++; + int miss = mid - str == 1 && str[0]=='.' ? 1 : 0; + if ( miss && missing_logic[miss] ) return 1; + char tmp = *mid; *mid = 0; + int match = regexec(regex, str, 0,NULL,0) ? 0 : 1; + *mid = tmp; + if ( logic==TOK_NLIKE ) match = match ? 0 : 1; + if ( match ) return 1; + if ( !*mid ) break; + str = mid + 1; + } + return 0; +} +static inline int _has_missing_string(char *beg) +{ + while ( *beg ) + { + char *end = beg; + while ( *end && *end!=',' ) end++; + if ( end-beg==1 && beg[0]=='.' ) return 1; + if ( !*end ) break; + beg = end + 1; + } + return 0; +} + +// Compare two strings with multiple fields, for example "A,B,.,C"=="X,Y,A". +// Returns 1 if any field matches, otherwise returns 0 +static inline int _match_vector_strings(char *abeg, size_t alen, char *bstr, size_t blen, int logic, int *missing_logic) +{ + char *aend = abeg + alen; + char *bend = bstr + blen; + while ( abeg < aend && *abeg ) + { + char *amid = abeg; + while ( amid < aend && *amid && *amid!=',' ) amid++; + int miss = amid - abeg == 1 && abeg[0]=='.' ? 1 : 0; + char *bbeg = bstr; + while ( bbeg < bend && *bbeg ) + { + char *bmid = bbeg; + while ( bmid < bend && *bmid && *bmid!=',' ) bmid++; + int nmiss = miss + (bmid - bbeg == 1 && bbeg[0]=='.' ? 1 : 0); + if ( nmiss ) { - if ( y==yend || *y==',' ) - { - if ( y-ystr==xend-xstr && !strncmp(xstr,ystr,xend-xstr) ) - { - pass_site = 1; - break; - } - ystr = y+1; - } - y++; + if ( missing_logic[nmiss] ) return 1; } + else + { + int match = amid-abeg==bmid-bbeg && !strncmp(abeg,bbeg,amid-abeg) ? 1 : 0; + if ( logic==TOK_NE ) match = match==1 ? 0 : 1; + if ( match ) return 1; + } + if ( !*bmid ) break; + bbeg = bmid + 1; } + if ( !*amid ) break; + abeg = amid + 1; + } + return 0; +} +static void cmp_vector_strings(token_t *atok, token_t *btok, token_t *rtok) +{ + tok_init_samples(atok, btok, rtok); + + int i, logic = rtok->tok_type; // TOK_EQ, TOK_NE, TOK_LIKE, TOK_NLIKE + regex_t *regex = atok->regex ? atok->regex : (btok->regex ? btok->regex : NULL); + + assert( atok->nvalues==atok->str_value.l && btok->nvalues==btok->str_value.l ); + assert( !atok->nsamples || !btok->nsamples ); + assert( (!regex && (logic==TOK_EQ || logic==TOK_NE)) || (regex && (logic==TOK_LIKE || logic==TOK_NLIKE)) ); + + int missing_logic[] = {0,0,0}; + if ( logic==TOK_EQ || logic==TOK_LIKE ) missing_logic[0] = missing_logic[2] = 1; + else if ( logic==TOK_NE || logic==TOK_NLIKE ) missing_logic[0] = missing_logic[1] = 1; + + if ( !atok->nsamples && !btok->nsamples ) + { + if ( !atok->nvalues && !btok->nvalues ) { rtok->pass_site = missing_logic[2]; return; } + if ( !atok->nvalues || !btok->nvalues ) + { + int miss = _has_missing_string(atok->nvalues ? atok->str_value.s : btok->str_value.s); + if ( missing_logic[miss+1] ) rtok->pass_site = 1; + return; + } + if ( !regex ) + rtok->pass_site = _match_vector_strings(atok->str_value.s, atok->str_value.l, btok->str_value.s, btok->str_value.l, logic, missing_logic); else - pass_site = strcmp(atok->str_value,btok->str_value) ? 0 : 1; - if ( logic!=TOK_EQ ) pass_site = pass_site ? 0 : 1; + { + token_t *tok = atok->regex ? btok : atok; + rtok->pass_site = _regex_vector_strings(regex, tok->str_value.s, tok->str_value.l, logic, missing_logic); + } + return; } - else + + // The case of (!atok->nsamples || !btok->nsamples) + + if ( !atok->nvalues && !btok->nvalues ) + { + if ( missing_logic[2] ) + { + for (i=0; insamples; i++) + if ( rtok->usmpl[i] ) { rtok->pass_samples[i] = missing_logic[2]; rtok->pass_site = 1; } + } + return; + } + if ( !atok->nvalues || !btok->nvalues ) { - token_t *xtok, *ytok; - if ( !atok->nsamples ) { xtok = atok; ytok = btok; } - else { xtok = btok; ytok = atok; } - char *xstr = xtok->str_value; - char *xend = xstr + (int)xtok->values[0], *x = xstr; - while ( xnsamples; i++) - { - char *ystr = ytok->str_value + i*(int)ytok->values[0]; - char *yend = ystr + (int)ytok->values[0], *y = ystr; - while ( ypass_samples[i] = 0; - else atok->pass_samples[i] = strncmp(xstr,ystr,x-xstr)==0 ? 1 : 0; - if ( logic!=TOK_EQ ) - atok->pass_samples[i] = atok->pass_samples[i] ? 0 : 1; - pass_site |= atok->pass_samples[i]; - } - if ( !atok->nsamples ) - atok->nvalues = atok->nsamples = btok->nsamples; // is it a bug? not sure if atok->nvalues should be set - } - return pass_site; + token_t *tok = atok->nvalues ? atok : btok; + if ( !tok->nsamples ) + { + int miss = _has_missing_string(tok->str_value.s); + if ( !missing_logic[miss+1] ) return; + for (i=0; insamples; i++) + if ( rtok->usmpl[i] ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; } + } + else + for (i=0; insamples; i++) + { + if ( !rtok->usmpl[i] ) continue; + int miss = _has_missing_string(tok->str_value.s + i*tok->nval1); + if ( missing_logic[miss+1] ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; } + } + return; + } + + // The case of (!atok->nsamples || !btok->nsamples) && (atok->nvalues && btok->nvalues) + token_t *xtok = atok->nsamples ? atok : btok; + token_t *ytok = atok->nsamples ? btok : atok; + assert( regex==ytok->regex ); + for (i=0; insamples; i++) + { + if ( !rtok->usmpl[i] ) continue; + int match; + if ( regex ) + match = _regex_vector_strings(regex, xtok->str_value.s + i*xtok->nval1, xtok->nval1, logic, missing_logic); + else + match = _match_vector_strings(xtok->str_value.s + i*xtok->nval1, xtok->nval1, ytok->str_value.s, ytok->str_value.l, logic, missing_logic); + if ( match ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; } + } } -static int regex_vector_strings(token_t *atok, token_t *btok) + +static int parse_idxs(char *tag_idx, int **idxs, int *nidxs, int *idx) { - int ret = regexec(btok->regex, atok->str_value, 0,NULL,0); - return ret==0 ? 1 : 0; + // TAG[], TAG[*] .. any field; sets idx=-2, idxs[0]=-1 + if ( *tag_idx==0 || !strcmp("*", tag_idx) ) + { + *idxs = (int*) malloc(sizeof(int)); + (*idxs)[0] = -1; + *nidxs = 1; + *idx = -2; + return 0; + } + + // TAG[integer] .. one field; idx positive + char *end, *beg = tag_idx; + *idx = strtol(tag_idx, &end, 10); + if ( *idx >= 0 && *end==0 ) return 0; + + // TAG[0,1] or TAG[0-2] or [1-] etc; idx=-2, idxs[...]=0,0,1,1,.. + int i, ibeg = -1; + while ( *beg ) + { + int num = strtol(beg, &end, 10); + if ( end[0]==',' ) beg = end + 1; + else if ( end[0]==0 ) beg = end; + else if ( end[0]=='-' ) { beg = end + 1; ibeg = num; continue; } + else return -1; + if ( num >= *nidxs ) + { + *idxs = (int*) realloc(*idxs, sizeof(int)*(num+1)); + memset(*idxs + *nidxs, 0, sizeof(int)*(num - *nidxs + 1)); + *nidxs = num + 1; + } + if ( ibeg>=0 ) + { + for (i=ibeg; i<=num; i++) (*idxs)[i] = 1; + ibeg = -1; + } + (*idxs)[num] = 1; + } + if ( ibeg >=0 ) + { + if ( ibeg >= *nidxs ) + { + *idxs = (int*) realloc(*idxs, sizeof(int)*(ibeg+1)); + memset(*idxs + *nidxs, 0, sizeof(int)*(ibeg - *nidxs + 1)); + *nidxs = ibeg + 1; + } + (*idxs)[ibeg] = -1; + } + *idx = -2; + return 0; } +static void parse_tag_idx(bcf_hdr_t *hdr, int is_fmt, char *tag, char *tag_idx, token_t *tok) // tag_idx points just after "TAG[" +{ + int i, len = strlen(tag_idx); + if ( tag_idx[len-1] == ']' ) tag_idx[len-1] = 0; + char *ori = strdup(tag_idx); + + assert( !tok->idxs && !tok->usmpl ); + int *idxs1 = NULL, nidxs1 = 0, idx1 = 0; + int *idxs2 = NULL, nidxs2 = 0, idx2 = 0; + + int set_samples = 0; + char *colon = index(tag_idx, ':'); + if ( colon ) + { + *colon = 0; + if ( parse_idxs(tag_idx, &idxs1, &nidxs1, &idx1) != 0 ) error("Could not parse the index: %s\n", ori); + if ( parse_idxs(colon+1, &idxs2, &nidxs2, &idx2) != 0 ) error("Could not parse the index: %s\n", ori); + tok->idxs = idxs2; + tok->nidxs = nidxs2; + tok->idx = idx2; + set_samples = 1; + } + else + { + if ( parse_idxs(tag_idx, &idxs1, &nidxs1, &idx1) != 0 ) error("Could not parse the index: %s\n", ori); + if ( is_fmt ) + { + if ( nidxs1==1 && idxs1[0]==-1 ) + { + tok->idxs = (int*) malloc(sizeof(int)); + tok->idxs[0] = -1; + tok->nidxs = 1; + tok->idx = -2; + } + else if ( bcf_hdr_id2number(hdr,BCF_HL_FMT,tok->hdr_id)!=1 ) + error("The FORMAT tag %s can have multiple subfields, run as %s[sample:subfield]\n", tag,tag); + else + tok->idx = 0; + set_samples = 1; + } + else + { + tok->idxs = idxs1; + tok->nidxs = nidxs1; + tok->idx = idx1; + } + } + + if ( set_samples ) + { + tok->nsamples = bcf_hdr_nsamples(hdr); + tok->usmpl = (uint8_t*) calloc(tok->nsamples,1); + if ( idx1>=0 ) + { + if ( idx1 >= bcf_hdr_nsamples(hdr) ) error("The sample index is too large: %s\n", ori); + tok->usmpl[idx1] = 1; + } + else if ( idx1==-2 ) + { + for (i=0; i= bcf_hdr_nsamples(hdr) ) error("The sample index is too large: %s\n", ori); + tok->usmpl[i] = 1; + } + if ( nidxs1 && idxs1[nidxs1-1]==-1 ) // open range, such as "7-" + { + for (; insamples; i++) tok->usmpl[i] = 1; + } + } + else error("todo: %s:%d .. %d\n", __FILE__,__LINE__, idx2); + free(idxs1); + } + free(ori); + + if ( tok->nidxs && tok->idxs[tok->nidxs-1]!=-1 ) + { + for (i=0; inidxs; i++) if ( tok->idxs[i] ) tok->nuidxs++; + } +} static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) { tok->tok_type = TOK_VAL; tok->hdr_id = -1; tok->pass_site = -1; - tok->idx = -1; + tok->idx = 0; // is this a string constant? if ( str[0]=='"' || str[0]=='\'' ) @@ -1143,7 +1695,7 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) int quote = str[0]; if ( str[len-1] != quote ) error("TODO: [%s]\n", filter->str); tok->key = (char*) calloc(len-1,sizeof(char)); - hts_expand(float,1,tok->mvalues,tok->values); + hts_expand(double,1,tok->mvalues,tok->values); tok->values[0] = len-2; memcpy(tok->key,str+1,len-2); tok->key[len-2] = 0; @@ -1230,6 +1782,10 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) tok->setter = &filters_set_alt_string; tok->is_str = 1; tok->tag = strdup("ALT"); + tok->idxs = (int*) malloc(sizeof(int)); + tok->idxs[0] = -1; + tok->nidxs = 1; + tok->idx = -2; return 0; } else if ( !strncasecmp(str,"N_ALT",len) ) @@ -1244,6 +1800,18 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) tok->threshold = bcf_hdr_nsamples(filter->hdr); return 0; } + else if ( !strncasecmp(str,"N_MISSING",len) ) + { + tok->setter = &filters_set_nmissing; + tok->tag = strdup("N_MISSING"); + return 0; + } + else if ( !strncasecmp(str,"F_MISSING",len) ) + { + tok->setter = &filters_set_nmissing; + tok->tag = strdup("F_MISSING"); + return 0; + } } // does it have array subscript? @@ -1255,17 +1823,6 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) int i; for (i=0; iidx = -2; // tag[*] .. any field - else - { - char *end; - tok->idx = strtol(tmp.s+is_array, &end, 10); - if ( *end!=']' ) error("Could not parse the index: %s[%s\n", tmp.s,tmp.s+is_array); - } - } } tok->hdr_id = bcf_hdr_id2int(filter->hdr,BCF_DT_ID,tmp.s); if ( is_fmt==-1 ) @@ -1277,6 +1834,16 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) } if ( is_fmt==-1 ) is_fmt = 0; } + if ( is_array ) + parse_tag_idx(filter->hdr, is_fmt, tmp.s, tmp.s+is_array, tok); + else if ( is_fmt && !tok->nsamples ) + { + int i; + tok->nsamples = bcf_hdr_nsamples(filter->hdr); + tok->usmpl = (uint8_t*) malloc(tok->nsamples); + for (i=0; insamples; i++) tok->usmpl[i] = 1; + } + tok->type = is_fmt ? BCF_HL_FMT : BCF_HL_INFO; if ( is_fmt ) filter->max_unpack |= BCF_UN_FMT; if ( tok->hdr_id>=0 ) @@ -1290,7 +1857,12 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) if ( !bcf_hdr_idinfo_exists(filter->hdr,BCF_HL_FMT,tok->hdr_id) ) error("No such FORMAT field: %s\n", tmp.s); if ( bcf_hdr_id2number(filter->hdr,BCF_HL_FMT,tok->hdr_id)!=1 && !is_array ) - error("Error: FORMAT vectors must be subscripted, e.g. %s[0] or %s[*]\n", tmp.s, tmp.s); + { + tok->idxs = (int*) malloc(sizeof(int)); + tok->idxs[0] = -1; + tok->nidxs = 1; + tok->idx = -2; + } switch ( bcf_hdr_id2type(filter->hdr,BCF_HL_FMT,tok->hdr_id) ) { case BCF_HT_INT: tok->setter = &filters_set_format_int; break; @@ -1319,7 +1891,13 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) case BCF_HT_STR: tok->setter = &filters_set_info_string; tok->is_str = 1; break; default: error("[%s:%d %s] FIXME\n", __FILE__,__LINE__,__FUNCTION__); } - if(!is_array) tok->idx = -2; + if (!is_array) + { + tok->idx = -2; + tok->idxs = (int*) malloc(sizeof(int)); + tok->idxs[0] = -1; + tok->nidxs = 1; + } } } filter->max_unpack |= BCF_UN_INFO; @@ -1372,11 +1950,18 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) return 0; } - // is it a value? + // is it a value? Here we parse as integer/float separately and use strtof + // rather than strtod, because the more accurate double representation + // would invalidate floating point comparisons like QUAL=59.2, obtained via + // htslib/vcf parser char *end; - errno = 0; - tok->threshold = strtod(tmp.s, &end); - if ( errno!=0 || end!=tmp.s+len ) error("[%s:%d %s] Error: the tag \"INFO/%s\" is not defined in the VCF header\n", __FILE__,__LINE__,__FUNCTION__,tmp.s); + tok->threshold = strtol(tmp.s, &end, 10); // integer? + if ( end - tmp.s != strlen(tmp.s) ) + { + errno = 0; + tok->threshold = strtof(tmp.s, &end); // float? + if ( errno!=0 || end!=tmp.s+len ) error("[%s:%d %s] Error: the tag \"%s\" is not defined in the VCF header\n", __FILE__,__LINE__,__FUNCTION__,tmp.s); + } if ( tmp.s ) free(tmp.s); return 0; @@ -1405,6 +1990,11 @@ static void filter_debug_print(token_t *toks, token_t **tok_ptrs, int ntoks) } } +static void str_to_lower(char *str) +{ + while ( *str ) { *str = tolower(*str); str++; } +} + // Parse filter expression and convert to reverse polish notation. Dijkstra's shunting-yard algorithm filter_t *filter_init(bcf_hdr_t *hdr, const char *str) @@ -1425,8 +2015,8 @@ filter_t *filter_init(bcf_hdr_t *hdr, const char *str) ret = filters_next_token(&tmp, &len); if ( ret==-1 ) error("Missing quotes in: %s\n", str); - //fprintf(stderr,"token=[%c] .. [%s] %d\n", TOKEN_STRING[ret], tmp, len); - //int i; for (i=0; i0 && out[j].is_str && !strcmp(".",out[j].key) ) + if ( out[j].is_str && out[j].key && !strcmp(".",out[j].key) ) { - int type = bcf_hdr_id2type(filter->hdr,out[k].type,out[k].hdr_id); - if ( type==BCF_HT_INT ) { out[j].is_str = 0; out[j].is_missing = 1; bcf_float_set_missing(out[j].values[0]); } - if ( type==BCF_HT_REAL ) { out[j].is_str = 0; out[j].is_missing = 1; bcf_float_set_missing(out[j].values[0]); } + int set_missing = 0; + if ( out[k].hdr_id>0 ) + { + int type = bcf_hdr_id2type(filter->hdr,out[k].type,out[k].hdr_id); + if ( type==BCF_HT_INT ) set_missing = 1; + else if ( type==BCF_HT_REAL ) set_missing = 1; + } + else if ( !strcmp("QUAL",out[k].tag) ) set_missing = 1; + if ( set_missing ) { out[j].is_str = 0; out[j].is_missing = 1; bcf_double_set_missing(out[j].values[0]); } } } if ( out[i].tok_type==TOK_LIKE || out[i].tok_type==TOK_NLIKE ) @@ -1524,7 +2124,14 @@ filter_t *filter_init(bcf_hdr_t *hdr, const char *str) if ( !out[j].key ) error("Could not parse the expression, wrong value for regex operator: %s\n", filter->str); out[j].regex = (regex_t *) malloc(sizeof(regex_t)); - if ( regcomp(out[j].regex, out[j].key, REG_ICASE|REG_NOSUB) ) + int cflags = REG_NOSUB; + int len = strlen(out[j].key); + if ( len>2 && out[j].key[len-1]=='i' && out[j].key[len-2]=='/' && out[j].key[len-3]!='\\' ) + { + out[j].key[len-2] = 0; + cflags |= REG_ICASE; + } + if ( regcomp(out[j].regex, out[j].key, cflags) ) error("Could not compile the regex expression \"%s\": %s\n", out[j].key,filter->str); } if ( out[i].tok_type!=TOK_VAL ) continue; @@ -1532,59 +2139,93 @@ filter_t *filter_init(bcf_hdr_t *hdr, const char *str) if ( !strcmp(out[i].tag,"TYPE") ) { if ( i+1==nout ) error("Could not parse the expression: %s\n", filter->str); - int j = i+1; - if ( out[j].tok_type==TOK_EQ || out[j].tok_type==TOK_NE ) j = i - 1; - if ( out[j].tok_type!=TOK_VAL || !out[j].key ) error("[%s:%d %s] Could not parse the expression: %s\n", __FILE__,__LINE__,__FUNCTION__, filter->str); - if ( !strcasecmp(out[j].key,"snp") || !strcasecmp(out[j].key,"snps") ) { out[j].threshold = VCF_SNP; out[j].is_str = 0; } - else if ( !strcasecmp(out[j].key,"indel") || !strcasecmp(out[j].key,"indels") ) { out[j].threshold = VCF_INDEL; out[j].is_str = 0; } - else if ( !strcasecmp(out[j].key,"mnp") || !strcasecmp(out[j].key,"mnps") ) { out[j].threshold = VCF_MNP; out[j].is_str = 0; } - else if ( !strcasecmp(out[j].key,"other") ) { out[j].threshold = VCF_OTHER; out[j].is_str = 0; } - else if ( !strcasecmp(out[j].key,"ref") ) { out[j].threshold = VCF_REF; out[j].is_str = 0; } - else error("The type \"%s\" not recognised: %s\n", out[j].key, filter->str); - out[j].tag = out[j].key; out[j].key = NULL; - i = j; + int itok, ival; + if ( out[i+1].tok_type==TOK_EQ || out[i+1].tok_type==TOK_NE ) ival = i - 1, itok = i + 1; + else if ( out[i+1].tok_type==TOK_LIKE || out[i+1].tok_type==TOK_NLIKE ) ival = i - 1, itok = i + 1; + else if ( out[i+2].tok_type==TOK_EQ || out[i+2].tok_type==TOK_NE ) itok = i + 2, ival = i + 1; + else if ( out[i+2].tok_type==TOK_LIKE || out[i+2].tok_type==TOK_NLIKE ) itok = i + 2, ival = i + 1; + else error("[%s:%d %s] Could not parse the expression: %s\n", __FILE__,__LINE__,__FUNCTION__, filter->str); + if ( !strcasecmp(out[ival].key,"snp") || !strcasecmp(out[ival].key,"snps") ) { out[ival].threshold = VCF_SNP<<1; out[ival].is_str = 0; } + else if ( !strcasecmp(out[ival].key,"indel") || !strcasecmp(out[ival].key,"indels") ) { out[ival].threshold = VCF_INDEL<<1; out[ival].is_str = 0; } + else if ( !strcasecmp(out[ival].key,"mnp") || !strcasecmp(out[ival].key,"mnps") ) { out[ival].threshold = VCF_MNP<<1; out[ival].is_str = 0; } + else if ( !strcasecmp(out[ival].key,"other") ) { out[ival].threshold = VCF_OTHER<<1; out[ival].is_str = 0; } + else if ( !strcasecmp(out[ival].key,"bnd") ) { out[ival].threshold = VCF_BND<<1; out[ival].is_str = 0; } + else if ( !strcasecmp(out[ival].key,"ref") ) { out[ival].threshold = 1; out[ival].is_str = 0; } + else error("The type \"%s\" not recognised: %s\n", out[ival].key, filter->str); + if ( out[itok].tok_type==TOK_LIKE || out[itok].tok_type==TOK_NLIKE ) out[itok].comparator = filters_cmp_bit_and; + out[ival].tag = out[ival].key; out[ival].key = NULL; + i = itok; + continue; + } + if ( !strcmp(out[i].tag,"GT") ) + { + if ( i+1==nout ) error("Could not parse the expression: %s\n", filter->str); + int ival; + if ( out[i+1].tok_type==TOK_EQ || out[i+1].tok_type==TOK_NE ) ival = i - 1; + else if ( out[i+1].tok_type==TOK_LIKE || out[i+1].tok_type==TOK_NLIKE ) ival = i - 1; + else if ( out[i+2].tok_type==TOK_EQ || out[i+2].tok_type==TOK_NE ) ival = i + 1; + else if ( out[i+2].tok_type==TOK_LIKE || out[i+2].tok_type==TOK_NLIKE ) ival = i + 1; + else error("[%s:%d %s] Could not parse the expression: %s\n", __FILE__,__LINE__,__FUNCTION__, filter->str); + + if ( !out[ival].key ) error("Comparison between samples is not supported, sorry!\n"); + + // assign correct setters and unify expressions, eg ar->ra, HOM->hom, etc + if ( !strcasecmp(out[ival].key,"hom") ) { out[i].setter = filters_set_genotype3; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"het") ) { out[i].setter = filters_set_genotype3; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"hap") ) { out[i].setter = filters_set_genotype3; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"mis") ) { out[i].setter = filters_set_genotype4; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"ref") ) { out[i].setter = filters_set_genotype4; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"alt") ) { out[i].setter = filters_set_genotype4; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"rr") ) { out[i].setter = filters_set_genotype2; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"ra") || !strcasecmp(out[ival].key,"ar") ) { out[i].setter = filters_set_genotype2; out[ival].key[0]='r'; out[ival].key[1]='a'; } // ra + else if ( !strcmp(out[ival].key,"aA") || !strcmp(out[ival].key,"Aa") ) { out[i].setter = filters_set_genotype2; out[ival].key[0]='a'; out[ival].key[1]='A'; } // aA + else if ( !strcasecmp(out[ival].key,"aa") ) { out[i].setter = filters_set_genotype2; out[ival].key[0]='a'; out[ival].key[1]='a'; } // aa + else if ( !strcasecmp(out[ival].key,"a") ) { out[i].setter = filters_set_genotype2; out[ival].key[0]='a'; out[ival].key[1]=0; } // a + else if ( !strcasecmp(out[ival].key,"r") ) { out[i].setter = filters_set_genotype2; out[ival].key[0]='r'; out[ival].key[1]=0; } // r continue; } if ( !strcmp(out[i].tag,"FILTER") ) { if ( i+1==nout ) error("Could not parse the expression: %s\n", filter->str); - int j = i+1; - if ( out[j].tok_type==TOK_EQ || out[j].tok_type==TOK_NE ) j = i - 1; // the expression has "value"=FILTER rather than FILTER="value" - if ( out[j].tok_type==TOK_LIKE ) out[j].tok_type = TOK_EQ; // for FILTER, ~ and !~ work the same way as = and != - if ( out[j].tok_type==TOK_NLIKE ) out[j].tok_type = TOK_NE; - if ( out[j+1].tok_type==TOK_LIKE ) out[j+1].tok_type = TOK_EQ; - if ( out[j+1].tok_type==TOK_NLIKE ) out[j+1].tok_type = TOK_NE; - if ( out[j].tok_type!=TOK_VAL || !out[j].key ) + int itok = i, ival; + if ( out[i+1].tok_type==TOK_EQ || out[i+1].tok_type==TOK_NE ) ival = i - 1; + else if ( out[i+1].tok_type==TOK_LIKE ) out[i+1].tok_type = TOK_EQ, ival = i - 1; + else if ( out[i+1].tok_type==TOK_NLIKE ) out[i+1].tok_type = TOK_NE, ival = i - 1; + else if ( out[i+2].tok_type==TOK_EQ || out[i+2].tok_type==TOK_NE ) ival = ++i; + else if ( out[i+2].tok_type==TOK_LIKE ) out[i+2].tok_type = TOK_EQ, ival = ++i; + else if ( out[i+2].tok_type==TOK_NLIKE ) out[i+2].tok_type = TOK_NE, ival = ++i; + else error("[%s:%d %s] Could not parse the expression: %s\n", __FILE__,__LINE__,__FUNCTION__, filter->str); + if ( out[ival].tok_type!=TOK_VAL || !out[ival].key ) error("[%s:%d %s] Could not parse the expression, an unquoted string value perhaps? %s\n", __FILE__,__LINE__,__FUNCTION__, filter->str); - if ( strcmp(".",out[j].key) ) + if ( strcmp(".",out[ival].key) ) { - out[j].hdr_id = bcf_hdr_id2int(filter->hdr, BCF_DT_ID, out[j].key); - if ( !bcf_hdr_idinfo_exists(filter->hdr,BCF_HL_FLT,out[j].hdr_id) ) - error("The filter \"%s\" not present in the VCF header\n", out[j].key); + out[ival].hdr_id = bcf_hdr_id2int(filter->hdr, BCF_DT_ID, out[ival].key); + if ( !bcf_hdr_idinfo_exists(filter->hdr,BCF_HL_FLT,out[ival].hdr_id) ) + error("The filter \"%s\" not present in the VCF header\n", out[ival].key); } else - out[j].hdr_id = -1; - out[j].tag = out[j].key; out[j].key = NULL; - out[i].hdr_id = out[j].hdr_id; - i = j; + out[ival].hdr_id = -1; + out[ival].tag = out[ival].key; out[ival].key = NULL; + out[itok].hdr_id = out[ival].hdr_id; continue; } } filter->nsamples = filter->max_unpack&BCF_UN_FMT ? bcf_hdr_nsamples(filter->hdr) : 0; for (i=0; insamples ) { out[i].pass_samples = (uint8_t*)malloc(filter->nsamples); int j; - for (j=0; jnsamples; j++) out[i].pass_samples[j] = 1; + for (j=0; jnsamples; j++) out[i].pass_samples[j] = 0; } } @@ -1602,9 +2243,11 @@ void filter_destroy(filter_t *filter) int i; for (i=0; infilters; i++) { - //if ( filter->filters[i].key ) free(filter->filters[i].key); - free(filter->filters[i].str_value); + if ( filter->filters[i].key ) free(filter->filters[i].key); + free(filter->filters[i].str_value.s); free(filter->filters[i].tag); + free(filter->filters[i].idxs); + free(filter->filters[i].usmpl); free(filter->filters[i].values); free(filter->filters[i].pass_samples); if (filter->filters[i].hash) khash_str2int_destroy_free(filter->filters[i].hash); @@ -1618,6 +2261,8 @@ void filter_destroy(filter_t *filter) free(filter->flt_stack); free(filter->str); free(filter->tmpi); + free(filter->tmpf); + free(filter->tmps.s); free(filter); } @@ -1628,9 +2273,7 @@ int filter_test(filter_t *filter, bcf1_t *line, const uint8_t **samples) int i, nstack = 0; for (i=0; infilters; i++) { - filter->filters[i].nsamples = 0; - filter->filters[i].nvalues = 0; - filter->filters[i].pass_site = -1; + filter->filters[i].pass_site = 0; if ( filter->filters[i].tok_type == TOK_VAL ) { @@ -1638,22 +2281,23 @@ int filter_test(filter_t *filter, bcf1_t *line, const uint8_t **samples) filter->filters[i].setter(filter, line, &filter->filters[i]); else if ( filter->filters[i].key ) // string constant { - filter->filters[i].str_value = filter->filters[i].key; - filter->filters[i].values[0] = filter->filters[i].values[0]; - filter->filters[i].nvalues = strlen(filter->filters[i].key); + filter->filters[i].str_value.l = 0; + kputs(filter->filters[i].key, &filter->filters[i].str_value); + filter->filters[i].nvalues = filter->filters[i].str_value.l; } else // numeric constant { filter->filters[i].values[0] = filter->filters[i].threshold; filter->filters[i].nvalues = 1; } - filter->flt_stack[nstack++] = &filter->filters[i]; continue; } - else if ( filter->filters[i].tok_type == TOK_FUNC ) // all functions take only one argument + else if ( filter->filters[i].func ) { - filter->filters[i].setter(filter, line, filter->flt_stack[nstack-1]); + int nargs = filter->filters[i].func(filter, line, &filter->filters[i], filter->flt_stack, nstack); + filter->flt_stack[nstack-nargs] = &filter->filters[i]; + if ( --nargs > 0 ) nstack -= nargs; continue; } if ( nstack<2 ) @@ -1661,112 +2305,76 @@ int filter_test(filter_t *filter, bcf1_t *line, const uint8_t **samples) int is_str = filter->flt_stack[nstack-1]->is_str + filter->flt_stack[nstack-2]->is_str; - if ( filter->filters[i].tok_type == TOK_OR || filter->filters[i].tok_type == TOK_OR_VEC ) - { - if ( filter->flt_stack[nstack-1]->pass_site<0 || filter->flt_stack[nstack-2]->pass_site<0 ) - error("Error occurred while processing the filter \"%s\" (%d %d OR)\n", filter->str,filter->flt_stack[nstack-2]->pass_site,filter->flt_stack[nstack-1]->pass_site); - filter->flt_stack[nstack-2]->pass_site = vector_logic_or(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1], filter->filters[i].tok_type); - nstack--; - continue; - } - if ( filter->filters[i].tok_type == TOK_AND || filter->filters[i].tok_type == TOK_AND_VEC ) - { - if ( filter->flt_stack[nstack-1]->pass_site<0 || filter->flt_stack[nstack-2]->pass_site<0 ) - error("Error occurred while processing the filter \"%s\" (%d %d AND)\n", filter->str,filter->flt_stack[nstack-2]->pass_site,filter->flt_stack[nstack-1]->pass_site); - filter->flt_stack[nstack-2]->pass_site = vector_logic_and(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1], filter->filters[i].tok_type); - nstack--; - continue; - } - if ( filter->filters[i].tok_type == TOK_ADD ) { - VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],+); + VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],+); + filter->flt_stack[nstack-2] = &filter->filters[i]; nstack--; continue; } else if ( filter->filters[i].tok_type == TOK_SUB ) { - VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],-); + VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],-); + filter->flt_stack[nstack-2] = &filter->filters[i]; nstack--; continue; } else if ( filter->filters[i].tok_type == TOK_MULT ) { - VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],*); + VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],*); + filter->flt_stack[nstack-2] = &filter->filters[i]; nstack--; continue; } else if ( filter->filters[i].tok_type == TOK_DIV ) { - VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],/); + VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],/); + filter->flt_stack[nstack-2] = &filter->filters[i]; nstack--; continue; } - int is_true = 0; - if ( !filter->flt_stack[nstack-1]->nvalues || !filter->flt_stack[nstack-2]->nvalues ) + // ideally, these comparators would become func, but this would require more work in init1() + if ( filter->filters[i].comparator ) { - int skip = 0; - if ( !filter->flt_stack[nstack-2]->is_missing && !filter->flt_stack[nstack-1]->is_missing ) skip = 1; - if ( filter->filters[i].tok_type != TOK_EQ && filter->filters[i].tok_type != TOK_NE ) skip = 1; - - if ( skip ) - filter->flt_stack[nstack-2]->nvalues = filter->flt_stack[nstack-2]->nsamples = 0; - else if ( filter->filters[i].tok_type == TOK_EQ ) - CMP_MISSING(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],==,is_true) - else if ( filter->filters[i].tok_type == TOK_NE ) - CMP_MISSING(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],!=,is_true) - } - else if ( filter->filters[i].tok_type == TOK_EQ ) - { - if ( filter->flt_stack[nstack-1]->comparator ) - is_true = filter->flt_stack[nstack-1]->comparator(filter->flt_stack[nstack-1],filter->flt_stack[nstack-2],TOK_EQ,line); - else if ( filter->flt_stack[nstack-2]->comparator ) - is_true = filter->flt_stack[nstack-2]->comparator(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],TOK_EQ,line); - else if ( is_str==2 ) // both are strings - is_true = cmp_vector_strings(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],TOK_EQ); - else if ( is_str==1 ) - error("Comparing string to numeric value: %s\n", filter->str); - else - CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],==,is_true); - } - else if ( filter->filters[i].tok_type == TOK_NE ) - { - if ( filter->flt_stack[nstack-1]->comparator ) - is_true = filter->flt_stack[nstack-1]->comparator(filter->flt_stack[nstack-1],filter->flt_stack[nstack-2],TOK_NE,line); - else if ( filter->flt_stack[nstack-2]->comparator ) - is_true = filter->flt_stack[nstack-2]->comparator(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],TOK_NE,line); - else if ( is_str==2 ) - is_true = cmp_vector_strings(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],TOK_NE); - else if ( is_str==1 ) - error("Comparing string to numeric value: %s\n", filter->str); - else - CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],!=,is_true); + filter->filters[i].comparator(filter->flt_stack[nstack-1],filter->flt_stack[nstack-2],&filter->filters[i],line); } - else if ( filter->filters[i].tok_type == TOK_LIKE || filter->filters[i].tok_type == TOK_NLIKE ) + else if ( filter->flt_stack[nstack-1]->comparator ) { - if ( is_str==2 ) - { - is_true = regex_vector_strings(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1]); - if ( filter->filters[i].tok_type == TOK_NLIKE ) is_true = is_true ? 0 : 1; - } - else - error("The regex operator can be used on strings only: %s\n", filter->str); - } - else if ( is_str>0 ) - error("Wrong operator in string comparison: %s [%s,%s]\n", filter->str, filter->flt_stack[nstack-1]->str_value, filter->flt_stack[nstack-2]->str_value); - else if ( filter->filters[i].tok_type == TOK_LE ) - CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],<=,is_true) - else if ( filter->filters[i].tok_type == TOK_LT ) - CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],<,is_true) - else if ( filter->filters[i].tok_type == TOK_BT ) - CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],>,is_true) - else if ( filter->filters[i].tok_type == TOK_BE ) - CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],>=,is_true) + filter->flt_stack[nstack-1]->comparator(filter->flt_stack[nstack-1],filter->flt_stack[nstack-2],&filter->filters[i],line); + } + else if ( filter->flt_stack[nstack-2]->comparator ) + { + filter->flt_stack[nstack-2]->comparator(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],line); + } + else if ( is_str==2 ) + { + cmp_vector_strings(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i]); + } else - error("FIXME: did not expect this .. tok_type %d = %d\n", i, filter->filters[i].tok_type); + { + // Determine what to do with one [1] or both [2] sides missing. The first field [0] gives [1]|[2] + int missing_logic[] = {0,0,0}; + if ( filter->filters[i].tok_type == TOK_EQ ) { missing_logic[0] = missing_logic[2] = 1; } + if ( filter->filters[i].tok_type == TOK_NE ) { missing_logic[0] = missing_logic[1] = 1; } + + if ( filter->filters[i].tok_type == TOK_EQ ) + CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],==,missing_logic) + else if ( filter->filters[i].tok_type == TOK_NE ) + CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],!=,missing_logic) + else if ( filter->filters[i].tok_type == TOK_LE ) + CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],<=,missing_logic) + else if ( filter->filters[i].tok_type == TOK_LT ) + CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],<,missing_logic) + else if ( filter->filters[i].tok_type == TOK_BT ) + CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],>,missing_logic) + else if ( filter->filters[i].tok_type == TOK_BE ) + CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],>=,missing_logic) + else + error("todo: %s:%d .. type=%d\n", __FILE__,__LINE__,filter->filters[i].tok_type); - filter->flt_stack[nstack-2]->pass_site = is_true; + } + filter->flt_stack[nstack-2] = &filter->filters[i]; nstack--; } if ( nstack>1 ) error("Error occurred while processing the filter \"%s\" (2:%d)\n", filter->str,nstack); // too few values left on the stack diff --git a/bcftools/filter.c.pysam.c b/bcftools/filter.c.pysam.c index 531339e22..83f49e0f6 100644 --- a/bcftools/filter.c.pysam.c +++ b/bcftools/filter.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* filter.c -- filter expressions. - Copyright (C) 2013-2015 Genome Research Ltd. + Copyright (C) 2013-2018 Genome Research Ltd. Author: Petr Danecek @@ -26,6 +26,7 @@ THE SOFTWARE. */ #include #include +#include #include #include #include @@ -36,29 +37,58 @@ THE SOFTWARE. */ #include #include +#ifndef __FUNCTION__ +# define __FUNCTION__ __func__ +#endif + +uint64_t bcf_double_missing = 0x7ff0000000000001; +uint64_t bcf_double_vector_end = 0x7ff0000000000002; +static inline void bcf_double_set(double *ptr, uint64_t value) +{ + union { uint64_t i; double d; } u; + u.i = value; + *ptr = u.d; +} +static inline int bcf_double_test(double d, uint64_t value) +{ + union { uint64_t i; double d; } u; + u.d = d; + return u.i==value ? 1 : 0; +} +#define bcf_double_set_vector_end(x) bcf_double_set(&(x),bcf_double_vector_end) +#define bcf_double_set_missing(x) bcf_double_set(&(x),bcf_double_missing) +#define bcf_double_is_vector_end(x) bcf_double_test((x),bcf_double_vector_end) +#define bcf_double_is_missing(x) bcf_double_test((x),bcf_double_missing) + + typedef struct _token_t { // read-only values, same for all VCF lines int tok_type; // one of the TOK_* keys below char *key; // set only for string constants, otherwise NULL char *tag; // for debugging and printout only, VCF tag name - float threshold; // filtering threshold + double threshold; // filtering threshold int hdr_id, type; // BCF header lookup ID and one of BCF_HT_* types - int idx; // 0-based index to VCF vectors, -1: not a vector, -2: any field ([*]) + int idx; // 0-based index to VCF vectors, + // -2: list (e.g. [0,1,2] or [1..3] or [1..] or any field[*], which is equivalent to [0..]) + int *idxs; // set indexes to 0 to exclude, to 1 to include, and last element negative if unlimited + int nidxs, nuidxs; // size of idxs array and the number of elements set to 1 + uint8_t *usmpl; // bitmask of used samples as set by idx + int nsamples; // number of samples for format fields, 0 for info and other fields void (*setter)(filter_t *, bcf1_t *, struct _token_t *); - int (*comparator)(struct _token_t *, struct _token_t *, int op_type, bcf1_t *); + int (*func)(filter_t *, bcf1_t *, struct _token_t *rtok, struct _token_t **stack, int nstack); + void (*comparator)(struct _token_t *, struct _token_t *, struct _token_t *rtok, bcf1_t *); void *hash; // test presence of str value in the hash via comparator regex_t *regex; // precompiled regex for string comparison // modified on filter evaluation at each VCF line - float *values; // In case str_value is set, values[0] is one sample's string length - char *str_value; // and values[0]*nsamples gives the total length; + double *values; + kstring_t str_value; int is_str, is_missing; // is_missing is set only for constants, variables are controled via nvalues int pass_site; // -1 not applicable, 0 fails, >0 pass uint8_t *pass_samples; // status of individual samples - int nsamples; // number of samples - int nvalues, mvalues; // number of used values, n=0 for missing values, n=1 for scalars - // for strings, total length of str_value + int nvalues, mvalues; // number of used values: n=0 for missing values, n=1 for scalars, for strings n=str_value.l + int nval1; // number of per-sample fields or string length } token_t; @@ -69,7 +99,9 @@ struct _filter_t int nfilters; token_t *filters, **flt_stack; // filtering input tokens (in RPN) and evaluation stack int32_t *tmpi; - int max_unpack, mtmpi, nsamples; + float *tmpf; + kstring_t tmps; + int max_unpack, mtmpi, mtmpf, nsamples; }; @@ -99,10 +131,11 @@ struct _filter_t #define TOK_ABS 23 #define TOK_LEN 24 #define TOK_FUNC 25 +#define TOK_CNT 26 -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 -// ( ) [ < = > ] ! | & + - * / M m a A O ~ ^ S . l -static int op_prec[] = {0,1,1,5,5,5,5,5,5,2,3, 6, 6, 7, 7, 8, 8, 8, 3, 2, 5, 5, 8, 8, 8}; +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 +// ( ) [ < = > ] ! | & + - * / M m a A O ~ ^ S . l +static int op_prec[] = {0,1,1,5,5,5,5,5,5,2,3, 6, 6, 7, 7, 8, 8, 8, 3, 2, 5, 5, 8, 8, 8, 8, 8}; #define TOKEN_STRING "x()[<=>]!|&+-*/MmaAO~^f" static int filters_next_token(char **str, int *len) @@ -129,6 +162,7 @@ static int filters_next_token(char **str, int *len) if ( !strncasecmp(tmp,"AVG(",4) ) { (*str) += 3; return TOK_AVG; } if ( !strncasecmp(tmp,"SUM(",4) ) { (*str) += 3; return TOK_SUM; } if ( !strncasecmp(tmp,"ABS(",4) ) { (*str) += 3; return TOK_ABS; } + if ( !strncasecmp(tmp,"COUNT(",4) ) { (*str) += 5; return TOK_CNT; } if ( !strncasecmp(tmp,"STRLEN(",7) ) { (*str) += 6; return TOK_LEN; } if ( !strncasecmp(tmp,"%MAX(",5) ) { (*str) += 4; return TOK_MAX; } // for backward compatibility if ( !strncasecmp(tmp,"%MIN(",5) ) { (*str) += 4; return TOK_MIN; } // for backward compatibility @@ -145,6 +179,7 @@ static int filters_next_token(char **str, int *len) return TOK_VAL; } + int square_brackets = 0; while ( tmp[0] ) { if ( tmp[0]=='"' ) break; @@ -159,11 +194,12 @@ static int filters_next_token(char **str, int *len) if ( tmp[0]=='(' ) break; if ( tmp[0]==')' ) break; if ( tmp[0]=='+' ) break; - // hacky: so that [*] is not split, the tokenizer does not recognise square brackets [] - if ( tmp[0]=='*' && (tmp==*str || tmp[-1]!='[') ) break; - if ( tmp[0]=='-' ) break; + if ( tmp[0]=='*' && !square_brackets ) break; + if ( tmp[0]=='-' && !square_brackets ) break; if ( tmp[0]=='/' ) break; if ( tmp[0]=='~' ) break; + if ( tmp[0]==']' ) { if (square_brackets) tmp++; break; } + if ( tmp[0]=='[' ) square_brackets++; tmp++; } if ( tmp > *str ) @@ -220,16 +256,16 @@ static void filters_set_qual(filter_t *flt, bcf1_t *line, token_t *tok) { float *ptr = &line->qual; if ( bcf_float_is_missing(*ptr) ) - tok->nvalues = 0; + bcf_double_set_missing(tok->values[0]); else - { - tok->values[0] = line->qual; - tok->nvalues = 1; - } + tok->values[0] = (double)line->qual; + tok->nvalues = 1; } static void filters_set_type(filter_t *flt, bcf1_t *line, token_t *tok) { tok->values[0] = bcf_get_variant_types(line); + if ( !tok->values[0] ) tok->values[0] = 1; // mistake in htslib: VCF_* should start with 1 + else tok->values[0] = ((int)tok->values[0]) << 1; tok->nvalues = 1; } static void filters_set_info(filter_t *flt, bcf1_t *line, token_t *tok) @@ -240,16 +276,19 @@ static void filters_set_info(filter_t *flt, bcf1_t *line, token_t *tok) if ( line->d.info[i].key == tok->hdr_id ) break; if ( i==line->n_info ) - tok->nvalues = 0; + tok->nvalues = tok->str_value.l = 0; else if ( line->d.info[i].type==BCF_BT_CHAR ) { int n = line->d.info[i].len; - int m = (int)tok->values[0]; - hts_expand(char,n+1,m,tok->str_value); - memcpy(tok->str_value,line->d.info[i].vptr,n); - tok->str_value[n] = 0; - tok->values[0] = m; - tok->nvalues = n; + if ( n >= tok->str_value.m ) + { + tok->str_value.m = n + 1; + tok->str_value.s = (char*) realloc(tok->str_value.s, tok->str_value.m); + if ( !tok->str_value.s ) error("Failed to alloc %d bytes\n", (int)tok->str_value.m); + } + memcpy(tok->str_value.s, line->d.info[i].vptr, n); + tok->str_value.s[n] = 0; + tok->nvalues = tok->str_value.l = n; } else if ( line->d.info[i].type==BCF_BT_FLOAT ) { @@ -259,10 +298,11 @@ static void filters_set_info(filter_t *flt, bcf1_t *line, token_t *tok) tok->values[0] = line->d.info[i].v1.f; tok->nvalues = 1; } - tok->str_value = NULL; + tok->str_value.l = 0; } else { + tok->str_value.l = 0; if ( line->d.info[i].type==BCF_BT_INT8 && line->d.info[i].v1.i==bcf_int8_missing ) tok->nvalues = 0; else if ( line->d.info[i].type==BCF_BT_INT16 && line->d.info[i].v1.i==bcf_int16_missing ) tok->nvalues = 0; else if ( line->d.info[i].type==BCF_BT_INT32 && line->d.info[i].v1.i==bcf_int32_missing ) tok->nvalues = 0; @@ -271,36 +311,53 @@ static void filters_set_info(filter_t *flt, bcf1_t *line, token_t *tok) tok->values[0] = line->d.info[i].v1.i; tok->nvalues = 1; } - tok->str_value = NULL; } } -static int filters_cmp_filter(token_t *atok, token_t *btok, int op_type, bcf1_t *line) +static void filters_cmp_bit_and(token_t *atok, token_t *btok, token_t *rtok, bcf1_t *line) +{ + int a = (int)(atok->nvalues?atok->values[0]:atok->threshold); + int b = (int)(btok->nvalues?btok->values[0]:btok->threshold); + if ( rtok->tok_type==TOK_LIKE ) + rtok->pass_site = a&b ? 1 : 0; + else + rtok->pass_site = a&b ? 0 : 1; +} +static void filters_cmp_filter(token_t *atok, token_t *btok, token_t *rtok, bcf1_t *line) { int i; - if ( op_type==TOK_NE ) // AND logic: none of the filters can match + if ( rtok->tok_type==TOK_NE ) // AND logic: none of the filters can match { if ( !line->d.n_flt ) { - if ( atok->hdr_id==-1 ) return 0; // missing value - return 1; // no filter present, eval to true + if ( atok->hdr_id==-1 ) return; // missing value + rtok->pass_site = 1; + return; // no filter present, eval to true } for (i=0; id.n_flt; i++) - if ( atok->hdr_id==line->d.flt[i] ) return 0; - return 1; + if ( atok->hdr_id==line->d.flt[i] ) return; + rtok->pass_site = 1; + return; } - // TOK_EQ with OR logic: at least one of the filters must match - if ( !line->d.n_flt ) + else if ( rtok->tok_type==TOK_EQ ) // OR logic: at least one of the filters must match { - if ( atok->hdr_id==-1 ) return 1; - return 0; // no filter present, eval to false + if ( !line->d.n_flt ) + { + if ( atok->hdr_id==-1 ) { rtok->pass_site = 1; return; } + return; // no filter present, eval to false + } + for (i=0; id.n_flt; i++) + if ( atok->hdr_id==line->d.flt[i] ) { rtok->pass_site = 1; return; } + return; } - for (i=0; id.n_flt; i++) - if ( atok->hdr_id==line->d.flt[i] ) return 1; - return 0; + else + error("Only == and != operators are supported for FILTER\n"); + return; } -static int filters_cmp_id(token_t *atok, token_t *btok, int op_type, bcf1_t *line) +static void filters_cmp_id(token_t *atok, token_t *btok, token_t *rtok, bcf1_t *line) { // multiple IDs not supported yet (easy to add though) + if ( rtok->tok_type!=TOK_EQ && rtok->tok_type!=TOK_NE ) + error("Only == and != operators are supported for ID\n"); if ( btok->hash ) { @@ -309,16 +366,19 @@ static int filters_cmp_id(token_t *atok, token_t *btok, int op_type, bcf1_t *lin if ( atok->hash ) { int ret = khash_str2int_has_key(atok->hash, line->d.id); - if ( op_type==TOK_EQ ) return ret; - return ret ? 0 : 1; + if ( rtok->tok_type==TOK_NE ) ret = ret ? 0 : 1; + rtok->pass_site = ret; + return; } - if ( op_type==TOK_EQ ) return strcmp(btok->str_value,line->d.id) ? 0 : 1; - return strcmp(btok->str_value,line->d.id) ? 1 : 0; + if ( rtok->tok_type==TOK_EQ ) + rtok->pass_site = strcmp(btok->str_value.s,line->d.id) ? 0 : 1; + else + rtok->pass_site = strcmp(btok->str_value.s,line->d.id) ? 1 : 0; } /** - * bcf_get_info_value() - get single INFO value, int or float + * bcf_get_info_value() - get single INFO value, int64_t or double * @line: BCF line * @info_id: tag ID, as returned by bcf_hdr_id2int * @ivec: 0-based index to retrieve, -1 when single value is expected @@ -338,8 +398,8 @@ static int bcf_get_info_value(bcf1_t *line, int info_id, int ivec, void *value) bcf_info_t *info = &line->d.info[j]; if ( info->len == 1 ) { - if ( info->type==BCF_BT_FLOAT ) *((float*)value) = info->v1.f; - else if ( info->type==BCF_BT_INT8 || info->type==BCF_BT_INT16 || info->type==BCF_BT_INT32 ) *((int*)value) = info->v1.i; + if ( info->type==BCF_BT_FLOAT ) *((double*)value) = info->v1.f; + else if ( info->type==BCF_BT_INT8 || info->type==BCF_BT_INT16 || info->type==BCF_BT_INT32 ) *((int64_t*)value) = info->v1.i; return 1; } @@ -356,11 +416,11 @@ static int bcf_get_info_value(bcf1_t *line, int info_id, int ivec, void *value) return 1; \ } switch (info->type) { - case BCF_BT_INT8: BRANCH(int8_t, p[j]==bcf_int8_missing, p[j]==bcf_int8_vector_end, int); break; - case BCF_BT_INT16: BRANCH(int16_t, p[j]==bcf_int16_missing, p[j]==bcf_int16_vector_end, int); break; - case BCF_BT_INT32: BRANCH(int32_t, p[j]==bcf_int32_missing, p[j]==bcf_int32_vector_end, int); break; - case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(p[j]), bcf_float_is_vector_end(p[j]), float); break; - default: fprintf(pysam_stderr,"todo: type %d\n", info->type); exit(1); break; + case BCF_BT_INT8: BRANCH(int8_t, p[j]==bcf_int8_missing, p[j]==bcf_int8_vector_end, int64_t); break; + case BCF_BT_INT16: BRANCH(int16_t, p[j]==bcf_int16_missing, p[j]==bcf_int16_vector_end, int64_t); break; + case BCF_BT_INT32: BRANCH(int32_t, p[j]==bcf_int32_missing, p[j]==bcf_int32_vector_end, int64_t); break; + case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(p[j]), bcf_float_is_vector_end(p[j]), double); break; + default: fprintf(bcftools_stderr,"todo: type %d\n", info->type); exit(1); break; } #undef BRANCH return -1; // this shouldn't happen @@ -376,14 +436,21 @@ static void filters_set_info_int(filter_t *flt, bcf1_t *line, token_t *tok) { if ( tok->idx==-2 ) { - int i, n = bcf_get_info_int32(flt->hdr,line,tok->tag,&flt->tmpi,&flt->mtmpi); - tok->nvalues = n; - hts_expand(float,n,tok->mvalues,tok->values); - for (i=0; ivalues[i] = flt->tmpi[i]; + tok->nvalues = bcf_get_info_int32(flt->hdr,line,tok->tag,&flt->tmpi,&flt->mtmpi); + if ( tok->nvalues<=0 ) tok->nvalues = 0; + else + { + hts_expand(double,tok->nvalues,tok->mvalues,tok->values); + int i, j = 0, end = tok->idxs[tok->nidxs-1] < 0 ? tok->nvalues - 1 : tok->nidxs - 1; + if ( end >= tok->nvalues ) end = tok->nvalues - 1; + for (i=0; i<=end; i++) + if ( i>=tok->nidxs || tok->idxs[i] ) tok->values[j++] = flt->tmpi[i]; + tok->nvalues = j; + } } else { - int32_t value; + int64_t value = 0; if ( bcf_get_info_value(line,tok->hdr_id,tok->idx,&value) <= 0 ) tok->nvalues = 0; else @@ -398,12 +465,26 @@ static void filters_set_info_float(filter_t *flt, bcf1_t *line, token_t *tok) { if ( tok->idx==-2 ) { - tok->nvalues = bcf_get_info_float(flt->hdr,line,tok->tag,&tok->values,&tok->mvalues); - if ( tok->nvalues<0 ) tok->nvalues = 0; + tok->nvalues = bcf_get_info_float(flt->hdr,line,tok->tag,&flt->tmpf,&flt->mtmpf); + if ( tok->nvalues<=0 ) tok->nvalues = 0; + else + { + hts_expand(double,tok->nvalues,tok->mvalues,tok->values); + int i, j = 0, end = tok->idxs[tok->nidxs-1] < 0 ? tok->nvalues - 1 : tok->nidxs - 1; + if ( end >= tok->nvalues ) end = tok->nvalues - 1; + for (i=0; i<=end; i++) + if ( i>=tok->nidxs || tok->idxs[i] ) + { + if ( bcf_float_is_missing(flt->tmpf[i]) ) bcf_double_set_missing(tok->values[j]); + else tok->values[j] = flt->tmpf[i]; + j++; + } + tok->nvalues = j; + } } else { - float value; + double value; if ( bcf_get_info_value(line,tok->hdr_id,tok->idx,&value) <= 0 ) tok->nvalues = 0; else @@ -416,33 +497,62 @@ static void filters_set_info_float(filter_t *flt, bcf1_t *line, token_t *tok) static void filters_set_info_string(filter_t *flt, bcf1_t *line, token_t *tok) { - int m = (int)tok->values[0]; - int n = bcf_get_info_string(flt->hdr,line,tok->tag,&tok->str_value,&m); - if ( n<0 ) { tok->nvalues = 0; return; } - tok->values[0] = m; // allocated length + int32_t m = tok->str_value.m; + int n = bcf_get_info_string(flt->hdr,line,tok->tag,&tok->str_value.s,&m); + tok->str_value.m = m; + if ( n<0 ) { tok->nvalues = tok->str_value.l = 0; return; } if ( tok->idx>=0 ) { // get ith field (i=tok->idx) int i = 0; - char *ss = tok->str_value, *se = tok->str_value + n; + char *ss = tok->str_value.s, *se = tok->str_value.s + n; while ( ssidx ) { if ( *ss==',' ) i++; ss++; } - if ( ss==se || i!=tok->idx ) { tok->nvalues = 0; return; } + if ( ss==se || i!=tok->idx ) { tok->nvalues = tok->str_value.l = 0; return; } se = ss; - while ( se-tok->str_valuestr_value ) *se = 0; + while ( se - tok->str_value.s < n && *se!=',' ) se++; + if ( ss==tok->str_value.s ) *se = 0; else { - memmove(tok->str_value,ss,se-ss); - tok->str_value[se-ss] = 0; + memmove(tok->str_value.s, ss, se-ss); + tok->str_value.s[se-ss] = 0; + } + tok->str_value.l = se - ss; + } + else if ( tok->idx==-2 && tok->idxs[0]==-1 ) // keep all values, TAG[*] + tok->str_value.l = n; + else if ( tok->idx==-2 ) + { + flt->tmps.l = 0; + ks_resize(&flt->tmps, n); + int i, iend = tok->idxs[tok->nidxs-1] < 0 ? n - 1 : tok->nidxs - 1; + if ( iend >= n ) iend = n - 1; + char *beg = tok->str_value.s, *dst = flt->tmps.s; + for (i=0; i<=iend; i++) + { + char *end = beg; + while ( *end && *end!=',' ) end++; + if ( i>=tok->nidxs || tok->idxs[i] ) + { + memcpy(dst, beg, end - beg); + dst += end - beg; + dst[0] = ','; + dst++; + } + beg = end+1; } - tok->nvalues = se-ss; + dst[0] = 0; + tok->str_value.l = dst - flt->tmps.s; + + #define SWAP(type_t, a, b) { type_t t = a; a = b; b = t; } + SWAP(char *, flt->tmps.s, tok->str_value.s); + SWAP(size_t, flt->tmps.m, tok->str_value.m); } - else if ( tok->idx==-2 ) tok->nvalues = n; + tok->nvalues = tok->str_value.l; } static void filters_set_info_flag(filter_t *flt, bcf1_t *line, token_t *tok) @@ -456,198 +566,358 @@ static void filters_set_info_flag(filter_t *flt, bcf1_t *line, token_t *tok) static void filters_set_format_int(filter_t *flt, bcf1_t *line, token_t *tok) { - int i; - if ( (tok->nvalues=bcf_get_format_int32(flt->hdr,line,tok->tag,&flt->tmpi,&flt->mtmpi))<0 ) + if ( line->n_sample != tok->nsamples ) + error("Incorrect number of FORMAT fields at %s:%d .. %s, %d vs %d\n", bcf_seqname(flt->hdr,line),line->pos+1,tok->tag,line->n_sample,tok->nsamples); + + int nvals; + if ( (nvals=bcf_get_format_int32(flt->hdr,line,tok->tag,&flt->tmpi,&flt->mtmpi))<0 ) + { tok->nvalues = 0; - else + return; + } + int i, nsrc1 = nvals / tok->nsamples; + tok->nval1 = tok->idx >= 0 ? 1 : (tok->nuidxs ? tok->nuidxs : nsrc1); + tok->nvalues = tok->nval1*tok->nsamples; + hts_expand(double, tok->nvalues, tok->mvalues, tok->values); + + if ( tok->idx >= 0 ) // scalar or vector index { - int is_missing = 1; - hts_expand(float,tok->nvalues,tok->mvalues,tok->values); - for (i=0; invalues; i++) + for (i=0; insamples; i++) { - if ( flt->tmpi[i]==bcf_int32_missing || flt->tmpi[i]==bcf_int32_vector_end ) - bcf_float_set_missing(tok->values[i]); + if ( !tok->usmpl[i] ) continue; + int32_t *ptr = flt->tmpi + i*nsrc1; + if ( tok->idx>=nsrc1 || ptr[tok->idx]==bcf_int32_missing || ptr[tok->idx]==bcf_int32_vector_end ) + bcf_double_set_missing(tok->values[i]); else - { - tok->values[i] = flt->tmpi[i]; - is_missing = 0; - } + tok->values[i] = ptr[tok->idx]; } - if ( is_missing ) tok->nvalues = 0; - else if ( tok->idx >= 0 ) + } + else + { + int kend = tok->idxs[tok->nidxs-1] < 0 ? tok->nval1 : tok->nidxs; + for (i=0; insamples; i++) { - int nsmpl = bcf_hdr_nsamples(flt->hdr); - int nvals = tok->nvalues / nsmpl; - if ( tok->idx >= nvals ) - tok->nvalues = 0; // the index is too big - else + if ( !tok->usmpl[i] ) continue; + int32_t *src = flt->tmpi + i*nsrc1; + double *dst = tok->values + i*tok->nval1; + int k, j = 0; + for (k=0; kvalues[i] = tok->values[i*nvals+tok->idx]; - tok->nvalues = nsmpl; + if ( knidxs && !tok->idxs[k] ) continue; + if ( src[k]==bcf_int32_missing || src[k]==bcf_int32_vector_end ) + bcf_double_set_missing(dst[j]); + else + dst[j] = src[k]; + j++; + } + while (j < tok->nval1) + { + bcf_double_set_missing(dst[j]); + j++; } } } - tok->nsamples = tok->nvalues; } static void filters_set_format_float(filter_t *flt, bcf1_t *line, token_t *tok) { - if ( (tok->nvalues=bcf_get_format_float(flt->hdr,line,tok->tag,&tok->values,&tok->mvalues))<=0 ) - tok->nvalues = tok->nsamples = 0; // missing values - else if ( tok->idx >= 0 ) - { - int i, nsmpl, nvals; - nsmpl = bcf_hdr_nsamples(flt->hdr); - nvals = tok->nvalues / nsmpl; - if ( tok->idx >= nvals ) - tok->nsamples = tok->nvalues = 0; // the index is too big - else - { - for (i=0; ivalues[i] = tok->values[i*nvals+tok->idx]; - tok->nsamples = tok->nvalues = nsmpl; - } - } - tok->nsamples = tok->nvalues; -} -static void filters_set_format_string(filter_t *flt, bcf1_t *line, token_t *tok) -{ - int ndim = tok->nsamples * (int)tok->values[0]; - int ret = bcf_get_format_char(flt->hdr,line,tok->tag,&tok->str_value,&ndim); + if ( line->n_sample != tok->nsamples ) + error("Incorrect number of FORMAT fields at %s:%d .. %s, %d vs %d\n", bcf_seqname(flt->hdr,line),line->pos+1,tok->tag,line->n_sample,tok->nsamples); - int nsmpl = bcf_hdr_nsamples(flt->hdr); - ndim /= nsmpl; - tok->values[0] = ndim; - - if ( ret<=0 ) + int nvals; + if ( (nvals=bcf_get_format_float(flt->hdr,line,tok->tag,&flt->tmpf,&flt->mtmpf))<0 ) { tok->nvalues = 0; return; } + int i, nsrc1 = nvals / tok->nsamples; + tok->nval1 = tok->idx >= 0 ? 1 : (tok->nuidxs ? tok->nuidxs : nsrc1); + tok->nvalues = tok->nval1*tok->nsamples; + hts_expand(double, tok->nvalues, tok->mvalues, tok->values); - if ( tok->idx < 0 ) // scalar + if ( tok->idx >= 0 ) // scalar or vector index { - tok->nvalues = tok->nsamples = nsmpl; - return; + for (i=0; insamples; i++) + { + if ( !tok->usmpl[i] ) continue; + float *ptr = flt->tmpf + i*nsrc1; + if ( tok->idx>=nsrc1 || bcf_float_is_missing(ptr[tok->idx]) || bcf_float_is_vector_end(ptr[tok->idx]) ) + bcf_double_set_missing(tok->values[i]); + else + tok->values[i] = ptr[tok->idx]; + } } - - // vector - int i; - for (i=0; istr_value + i*ndim; - int is = 0, ivec = 0; - while ( ivecidx && isidxs[tok->nidxs-1] < 0 ? tok->nval1 : tok->nidxs; + for (i=0; insamples; i++) { - if ( ss[is]==',' ) ivec++; - is++; + if ( !tok->usmpl[i] ) continue; + float *src = flt->tmpf + i*nsrc1; + double *dst = tok->values + i*tok->nval1; + int k, j = 0; + for (k=0; knidxs && !tok->idxs[k] ) continue; + if ( bcf_float_is_missing(src[k]) || bcf_float_is_vector_end(src[k]) ) + bcf_double_set_missing(dst[j]); + else + dst[j] = src[k]; + j++; + } + while (j < tok->nval1) + { + bcf_double_set_missing(dst[j]); + j++; + } } - if ( ivec!=tok->idx || is==ndim || !ss[is] ) + } +} +static void filters_set_format_string(filter_t *flt, bcf1_t *line, token_t *tok) +{ + if ( line->n_sample != tok->nsamples ) + error("Incorrect number of FORMAT fields at %s:%d .. %s, %d vs %d\n", bcf_seqname(flt->hdr,line),line->pos+1,tok->tag,line->n_sample,tok->nsamples); + + int i, ndim = tok->str_value.m; + int nstr = bcf_get_format_char(flt->hdr, line, tok->tag, &tok->str_value.s, &ndim); + tok->str_value.m = ndim; + tok->str_value.l = tok->nvalues = 0; + + if ( nstr<0 ) return; + + tok->nvalues = tok->str_value.l = nstr; + tok->nval1 = nstr / tok->nsamples; + for (i=0; insamples; i++) + { + if ( !tok->usmpl[i] ) continue; + char *src = tok->str_value.s + i*tok->nval1, *dst = src; + int ibeg = 0, idx = 0; + while ( ibeg < tok->nval1 ) { - ss[0] = '.'; - ss[1] = 0; - continue; + int iend = ibeg; + while ( iend < tok->nval1 && src[iend] && src[iend]!=',' ) iend++; + + int keep = 0; + if ( tok->idx >= 0 ) + { + if ( tok->idx==idx ) keep = 1; + } + else if ( idx < tok->nidxs ) + { + if ( tok->idxs[idx] != 0 ) keep = 1; + } + else if ( tok->idxs[tok->nidxs-1] < 0 ) + keep = 1; + + if ( keep ) + { + if ( ibeg!=0 ) memmove(dst, src+ibeg, iend-ibeg+1); + dst += iend - ibeg + 1; + if ( tok->idx>=0 ) break; + } + if ( !src[iend] ) break; + ibeg = iend + 1; + idx++; } - int ie = is; - while ( ienval1 ) memset(dst-1, 0, tok->nval1 - (dst - src)); } - if ( !ndim ) +} +static void _filters_set_genotype(filter_t *flt, bcf1_t *line, token_t *tok, int type) +{ + bcf_fmt_t *fmt = bcf_get_fmt(flt->hdr, line, "GT"); + if ( !fmt ) { - tok->nvalues = 0; + tok->nvalues = tok->str_value.l = 0; return; } - tok->nvalues = ret; - tok->nsamples = nsmpl; + + int i,j, nsmpl = bcf_hdr_nsamples(flt->hdr), nvals1 = type==2 ? 3 : 4; + if ( tok->str_value.m <= nvals1*nsmpl ) + { + tok->str_value.m = nvals1*nsmpl + 1; + tok->str_value.s = (char*)realloc(tok->str_value.s, tok->str_value.m); + } + +#define BRANCH_INT(type_t,vector_end) \ + { \ + for (i=0; in_sample; i++) \ + { \ + type_t *ptr = (type_t*) (fmt->p + i*fmt->size); \ + int is_het = 0, has_ref = 0, missing = 0; \ + for (j=0; jn; j++) \ + { \ + if ( ptr[j]==vector_end ) break; /* smaller ploidy */ \ + if ( bcf_gt_is_missing(ptr[j]) ) { missing=1; break; } /* missing allele */ \ + int ial = ptr[j]; \ + if ( bcf_gt_allele(ial)==0 ) has_ref = 1; \ + if ( j>0 ) \ + { \ + int jal = ptr[j-1]; \ + if ( bcf_gt_allele(ial)!=bcf_gt_allele(jal) ) is_het = 1; \ + } \ + } \ + char *dst = &tok->str_value.s[nvals1*i]; \ + if ( type==4 ) \ + { \ + if ( !j || missing ) dst[0]='m', dst[1]='i', dst[2]='s', dst[3] = 0; /* mis, missing genotype */ \ + else if ( !has_ref ) dst[0]='a', dst[1]='l', dst[2]='t', dst[3] = 0; /* alt, no ref, must have alt allele */ \ + else if ( !is_het ) dst[0]='r', dst[1]='e', dst[2]='f', dst[3] = 0; /* ref, must be ref-only, no alt alelle */ \ + else dst[0]='a', dst[1]='l', dst[2]='t', dst[3] = 0; /* alt, is het, has alt allele */ \ + } \ + else if ( !j || missing ) dst[0]='.', dst[1]=0; /* ., missing genotype */ \ + else if ( type==3 ) \ + { \ + if ( j==1 ) dst[0]='h', dst[1]='a', dst[2]='p', dst[3] = 0; /* hap, haploid */ \ + else if ( !is_het ) dst[0]='h', dst[1]='o', dst[2]='m', dst[3] = 0; /* hom */ \ + else dst[0]='h', dst[1]='e', dst[2]='t', dst[3] = 0; /* het */ \ + } \ + else \ + { \ + if ( j==1 ) \ + { \ + if ( has_ref ) dst[0]='r', dst[1]=0; /* r, haploid */ \ + else dst[0]='a', dst[1]=0; /* a, haploid */ \ + } \ + else if ( !is_het ) \ + { \ + if ( has_ref ) dst[0]='r', dst[1]='r', dst[2] = 0; /* rr */ \ + else dst[0]='a', dst[1]='a', dst[2] = 0; /* aa */ \ + } \ + else \ + { \ + if ( has_ref ) dst[0]='r', dst[1]='a', dst[2] = 0; /* ra */ \ + else dst[0]='a', dst[1]='A', dst[2] = 0; /* aA */ \ + } \ + } \ + } \ + } + switch (fmt->type) { + case BCF_BT_INT8: BRANCH_INT(int8_t, bcf_int8_vector_end); break; + case BCF_BT_INT16: BRANCH_INT(int16_t, bcf_int16_vector_end); break; + case BCF_BT_INT32: BRANCH_INT(int32_t, bcf_int32_vector_end); break; + default: error("The GT type is not lineognised: %d at %s:%d\n",fmt->type, bcf_seqname(flt->hdr,line),line->pos+1); break; + } +#undef BRANCH_INT + assert( tok->nsamples == nsmpl ); + tok->nvalues = tok->str_value.l = nvals1*nsmpl; + tok->str_value.s[tok->str_value.l] = 0; + tok->nval1 = nvals1; } +static void filters_set_genotype2(filter_t *flt, bcf1_t *line, token_t *tok) { _filters_set_genotype(flt, line, tok, 2); } +static void filters_set_genotype3(filter_t *flt, bcf1_t *line, token_t *tok) { _filters_set_genotype(flt, line, tok, 3); } +static void filters_set_genotype4(filter_t *flt, bcf1_t *line, token_t *tok) { _filters_set_genotype(flt, line, tok, 4); } + static void filters_set_genotype_string(filter_t *flt, bcf1_t *line, token_t *tok) { bcf_fmt_t *fmt = bcf_get_fmt(flt->hdr, line, "GT"); if ( !fmt ) { - tok->nvalues = tok->nsamples = 0; + tok->nvalues = 0; return; } - int i, blen = 3, nsmpl = bcf_hdr_nsamples(flt->hdr); - kstring_t str; + int i, blen = 4, nsmpl = line->n_sample; gt_length_too_big: - str.s = tok->str_value; str.m = tok->values[0] * nsmpl; str.l = 0; + tok->str_value.l = 0; for (i=0; ip + i*fmt->size); \ - if ( !(ptr[0]>>1) ) kputc('.',&str); \ - } - switch (fmt->type) { - case BCF_BT_INT8: BRANCH(int8_t); break; - case BCF_BT_INT16: BRANCH(int16_t); break; - case BCF_BT_INT32: BRANCH(int32_t); break; - default: fprintf(pysam_stderr,"FIXME: type %d in bcf_format_gt?\n", fmt->type); abort(); break; - } - #undef BRANCH - - if ( plen==str.l ) + size_t plen = tok->str_value.l; + bcf_format_gt(fmt, i, &tok->str_value); + kputc_(0, &tok->str_value); + if ( tok->str_value.l - plen > blen ) { - bcf_format_gt(fmt, i, &str); - if ( str.l - plen > blen ) - { - // too many alternate alleles or ploidy is too large, the genotype does not fit - // three characters ("0/0" vs "10/10"). - tok->str_value = str.s; - blen *= 2; - goto gt_length_too_big; - } + // too many alternate alleles or ploidy is too large, the genotype does not fit + // three characters ("0/0" vs "10/10"). + blen *= 2; + goto gt_length_too_big; } - plen = str.l - plen; - while ( plenstr_value.l - plen; + while ( plen < blen ) { - kputc_(0, &str); + kputc_(0, &tok->str_value); plen++; } } - tok->nvalues = str.l; - tok->nsamples = nsmpl; - tok->values[0] = blen; - tok->str_value = str.s; + assert( tok->nsamples == nsmpl ); + tok->nvalues = tok->str_value.l; + tok->nval1 = blen; } static void filters_set_ref_string(filter_t *flt, bcf1_t *line, token_t *tok) { - kstring_t str; str.s = tok->str_value; str.m = tok->values[0]; str.l = 0; - kputs(line->d.allele[0], &str); - tok->nvalues = str.l; - tok->values[0] = str.m; - tok->str_value = str.s; + tok->str_value.l = 0; + kputs(line->d.allele[0], &tok->str_value); + tok->nvalues = tok->str_value.l; } static void filters_set_alt_string(filter_t *flt, bcf1_t *line, token_t *tok) { - kstring_t str; str.s = tok->str_value; str.m = tok->values[0]; str.l = 0; + tok->str_value.l = 0; if ( tok->idx>=0 ) { - if ( line->n_allele >= tok->idx ) - kputs(line->d.allele[tok->idx], &str); + if ( line->n_allele > tok->idx + 1 ) + kputs(line->d.allele[tok->idx + 1], &tok->str_value); else - kputc('.', &str); + kputc('.', &tok->str_value); + tok->idx = 0; + } + else if ( tok->idx==-2 ) + { + int i, end = tok->nuidxs ? tok->nuidxs : line->n_allele - 1; + if ( end >= line->n_allele - 1 ) end = line->n_allele - 2; + for (i=0; i<=end; i++) + if ( i>=tok->nidxs || tok->idxs[i] ) + { + if ( tok->str_value.l ) kputc(',', &tok->str_value); + kputs(line->d.allele[i+1], &tok->str_value); + } } else if ( line->n_allele>1 ) { - kputs(line->d.allele[1], &str); + kputs(line->d.allele[1], &tok->str_value); int i; for (i=2; in_allele; i++) { - kputc(',', &str); - kputs(line->d.allele[i], &str); + kputc(',', &tok->str_value); + kputs(line->d.allele[i], &tok->str_value); } } else if ( line->n_allele==1 ) - kputc('.', &str); - tok->nvalues = str.l; - tok->values[0] = str.m; - tok->str_value = str.s; + kputc('.', &tok->str_value); + tok->nvalues = tok->str_value.l; +} +static void filters_set_nmissing(filter_t *flt, bcf1_t *line, token_t *tok) +{ + bcf_unpack(line, BCF_UN_FMT); + if ( !line->n_sample ) + { + tok->nvalues = 1; + tok->values[0] = 0; + return; + } + + int i,igt = bcf_hdr_id2int(flt->hdr, BCF_DT_ID, "GT"); + bcf_fmt_t *fmt = NULL; + for (i=0; in_fmt; i++) + if ( line->d.fmt[i].id==igt ) { fmt = &line->d.fmt[i]; break; } + if ( !fmt ) + { + tok->nvalues = 0; + return; + } + if ( fmt->type!=BCF_BT_INT8 ) error("TODO: the GT fmt_type is not int8\n"); + + int j,nmissing = 0; + for (i=0; in_sample; i++) + { + int8_t *ptr = (int8_t*) (fmt->p + i*fmt->size); + for (j=0; jn; j++) + { + if ( ptr[j]==bcf_int8_vector_end ) break; + if ( ptr[j]==bcf_gt_missing ) { nmissing++; break; } + } + } + tok->nvalues = 1; + tok->values[0] = tok->tag[0]=='N' ? nmissing : (double)nmissing / line->n_sample; } static void filters_set_nalt(filter_t *flt, bcf1_t *line, token_t *tok) { @@ -682,7 +952,7 @@ static void filters_set_ac(filter_t *flt, bcf1_t *line, token_t *tok) } else { - hts_expand(float,line->n_allele,tok->mvalues,tok->values); + hts_expand(double,line->n_allele,tok->mvalues,tok->values); for (i=1; in_allele; i++) tok->values[i-1] = flt->tmpi[i]; tok->nvalues = line->n_allele - 1; @@ -708,7 +978,7 @@ static void filters_set_af(filter_t *flt, bcf1_t *line, token_t *tok) if ( !tok->nvalues ) return; int i, an = flt->tmpi[0]; for (i=0; invalues; i++) - tok->values[i] /= (float)an; + tok->values[i] /= (double)an; } static void filters_set_maf(filter_t *flt, bcf1_t *line, token_t *tok) { @@ -717,262 +987,311 @@ static void filters_set_maf(filter_t *flt, bcf1_t *line, token_t *tok) int i, an = flt->tmpi[0]; for (i=0; invalues; i++) { - tok->values[i] /= (float)an; + tok->values[i] /= (double)an; if ( tok->values[i] > 0.5 ) tok->values[i] = 1 - tok->values[i]; } } -static void set_max(filter_t *flt, bcf1_t *line, token_t *tok) +static int func_max(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - float val = -HUGE_VAL; - int i; + token_t *tok = stack[nstack - 1]; + rtok->nvalues = 0; + if ( !tok->nvalues ) return 1; + double val = -HUGE_VAL; + int i, has_value = 0; for (i=0; invalues; i++) { - if ( !bcf_float_is_missing(tok->values[i]) && val < tok->values[i] ) val = tok->values[i]; + if ( bcf_double_is_missing(tok->values[i]) || bcf_double_is_vector_end(tok->values[i]) ) continue; + has_value = 1; + if ( val < tok->values[i] ) val = tok->values[i]; } - tok->values[0] = val; - tok->nvalues = 1; - tok->nsamples = 0; + if ( has_value ) + { + rtok->values[0] = val; + rtok->nvalues = has_value; + } + return 1; } -static void set_min(filter_t *flt, bcf1_t *line, token_t *tok) +static int func_min(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - float val = HUGE_VAL; - int i; + token_t *tok = stack[nstack - 1]; + rtok->nvalues = 0; + if ( !tok->nvalues ) return 1; + double val = HUGE_VAL; + int i, has_value = 0; for (i=0; invalues; i++) - if ( !bcf_float_is_missing(tok->values[i]) && val > tok->values[i] ) val = tok->values[i]; - tok->values[0] = val; - tok->nvalues = 1; - tok->nsamples = 0; + { + if ( bcf_double_is_missing(tok->values[i]) || bcf_double_is_vector_end(tok->values[i]) ) continue; + has_value = 1; + if ( val > tok->values[i] ) val = tok->values[i]; + } + if ( has_value ) + { + rtok->values[0] = val; + rtok->nvalues = has_value; + } + return 1; } -static void set_avg(filter_t *flt, bcf1_t *line, token_t *tok) +static int func_avg(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - float val = 0; + token_t *tok = stack[nstack - 1]; + rtok->nvalues = 0; + if ( !tok->nvalues ) return 1; + double val = 0; int i, n = 0; for (i=0; invalues; i++) - if ( !bcf_float_is_missing(tok->values[i]) ) { val += tok->values[i]; n++; } - tok->values[0] = n ? val / n : 0; - tok->nvalues = 1; - tok->nsamples = 0; + if ( !bcf_double_is_missing(tok->values[i]) ) { val += tok->values[i]; n++; } + if ( n ) + { + rtok->values[0] = val / n; + rtok->nvalues = 1; + } + return 1; } -static void set_sum(filter_t *flt, bcf1_t *line, token_t *tok) +static int func_sum(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - float val = 0; + rtok->nvalues = 0; + token_t *tok = stack[nstack - 1]; + if ( !tok->nvalues ) return 1; + double val = 0; int i, n = 0; for (i=0; invalues; i++) - if ( !bcf_float_is_missing(tok->values[i]) ) { val += tok->values[i]; n++; } - tok->values[0] = val; - tok->nvalues = 1; - tok->nsamples = 0; + if ( !bcf_double_is_missing(tok->values[i]) ) { val += tok->values[i]; n++; } + if ( n ) + { + rtok->values[0] = val; + rtok->nvalues = 1; + } + return 1; } -static void set_abs(filter_t *flt, bcf1_t *line, token_t *tok) +static int func_abs(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { + token_t *tok = stack[nstack - 1]; if ( tok->is_str ) error("ABS() can be applied only on numeric values\n"); + + rtok->nvalues = tok->nvalues; + if ( !tok->nvalues ) return 1; + hts_expand(double, rtok->nvalues, rtok->mvalues, rtok->values); int i; for (i=0; invalues; i++) - tok->values[i] = fabs(tok->values[i]); + if ( bcf_double_is_missing(tok->values[i]) ) bcf_double_set_missing(rtok->values[i]); + else rtok->values[i] = fabs(tok->values[i]); + return 1; } -static void set_strlen(filter_t *flt, bcf1_t *line, token_t *tok) +static int func_count(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - tok->is_str = 0; - if ( !tok->nvalues ) return; + token_t *tok = stack[nstack - 1]; + if ( !tok->nsamples ) error("COUNT() can be applied only on FORMAT fields\n"); + + int i, cnt = 0; + for (i=0; insamples; i++) + if ( tok->pass_samples[i] ) cnt++; + + rtok->nvalues = 1; + rtok->values[0] = cnt; + return 1; +} +static int func_strlen(filter_t *flt, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) +{ + token_t *tok = stack[nstack - 1]; + rtok->nvalues = rtok->str_value.l = 0; + if ( !tok->str_value.l ) return 1; + if ( tok->idx==-2 ) { int i = 0; - char *ss = tok->str_value; + char *ss = tok->str_value.s; while ( *ss ) { char *se = ss; while ( *se && *se!=',' ) se++; - if ( !*se ) tok->values[i] = strlen(ss); + hts_expand(double, i+1, rtok->mvalues, rtok->values); + if ( !*se ) rtok->values[i] = strlen(ss); else { *se = 0; - tok->values[i] = strlen(ss); + rtok->values[i] = strlen(ss); *se = ','; } ss = *se ? se + 1 : se; i++; } - tok->nvalues = i; + rtok->nvalues = i; } else { - tok->values[0] = strlen(tok->str_value); - tok->nvalues = 1; + rtok->values[0] = strlen(tok->str_value.s); + rtok->nvalues = 1; } + return 1; +} +inline static void tok_init_values(token_t *atok, token_t *btok, token_t *rtok) +{ + token_t *tok = atok->nvalues > btok->nvalues ? atok : btok; + rtok->nvalues = tok->nvalues; + rtok->nval1 = tok->nval1; + hts_expand(double*, rtok->nvalues, rtok->mvalues, rtok->values); } -#define VECTOR_ARITHMETICS(atok,btok,AOP) \ +inline static void tok_init_samples(token_t *atok, token_t *btok, token_t *rtok) +{ + if ( (atok->nsamples || btok->nsamples) && !rtok->nsamples ) + { + rtok->nsamples = atok->nsamples ? atok->nsamples : btok->nsamples; + rtok->usmpl = (uint8_t*) calloc(rtok->nsamples,1); + int i; + for (i=0; insamples; i++) rtok->usmpl[i] |= atok->usmpl[i]; + for (i=0; insamples; i++) rtok->usmpl[i] |= btok->usmpl[i]; + } + memset(rtok->pass_samples, 0, rtok->nsamples); +} + +#define VECTOR_ARITHMETICS(atok,btok,_rtok,AOP) \ { \ + token_t *rtok = _rtok; \ int i, has_values = 0; \ - if ( !(atok)->nvalues || !(btok)->nvalues ) /* missing values */ \ - { \ - (atok)->nvalues = 0; (atok)->nsamples = 0; \ - } \ - else \ + if ( atok->nvalues && btok->nvalues ) \ { \ - if ( ((atok)->nsamples && (btok)->nsamples) || (!(atok)->nsamples && !(btok)->nsamples)) \ + tok_init_values(atok, btok, rtok); \ + tok_init_samples(atok, btok, rtok); \ + if ( (atok->nsamples && btok->nsamples) || (!atok->nsamples && !btok->nsamples)) \ { \ - for (i=0; i<(atok)->nvalues; i++) \ + assert( atok->nsamples==btok->nsamples ); \ + for (i=0; invalues; i++) \ { \ - if ( bcf_float_is_missing((atok)->values[i]) ) continue; \ - if ( bcf_float_is_missing((btok)->values[i]) ) { bcf_float_set_missing((atok)->values[i]); continue; } \ - has_values = 1; \ - (atok)->values[i] = (atok)->values[i] AOP (btok)->values[i]; \ - } \ - } \ - else if ( (btok)->nsamples ) \ - { \ - hts_expand(float,(btok)->nvalues,(atok)->mvalues,(atok)->values); \ - for (i=0; i<(btok)->nvalues; i++) \ - { \ - if ( bcf_float_is_missing((atok)->values[0]) || bcf_float_is_missing((btok)->values[i]) ) \ + if ( bcf_double_is_missing(atok->values[i]) || bcf_double_is_missing(btok->values[i]) ) \ { \ - bcf_float_set_missing((atok)->values[i]); \ + bcf_double_set_missing(rtok->values[i]); \ continue; \ } \ has_values = 1; \ - (atok)->values[i] = (atok)->values[0] AOP (btok)->values[i]; \ + rtok->values[i] = atok->values[i] AOP btok->values[i]; \ } \ - (atok)->nvalues = (btok)->nvalues; \ - (atok)->nsamples = (btok)->nsamples; \ } \ - else if ( (atok)->nsamples ) \ + else \ { \ - for (i=0; i<(atok)->nvalues; i++) \ + token_t *xtok = atok->nsamples ? atok : btok; \ + token_t *ytok = atok->nsamples ? btok : atok; \ + assert( ytok->nvalues==1 ); \ + if ( !bcf_double_is_missing(ytok->values[0]) ) \ { \ - if ( bcf_float_is_missing((atok)->values[i]) || bcf_float_is_missing((btok)->values[0]) ) \ + for (i=0; invalues; i++) \ { \ - bcf_float_set_missing((atok)->values[i]); \ - continue; \ + if ( bcf_double_is_missing(xtok->values[i]) ) \ + { \ + bcf_double_set_missing(rtok->values[i]); \ + continue; \ + } \ + has_values = 1; \ + rtok->values[i] = xtok->values[i] AOP ytok->values[0]; \ } \ - has_values = 1; \ - (atok)->values[i] = (atok)->values[i] AOP (btok)->values[0]; \ } \ } \ } \ - if ( !has_values ) { (atok)->nvalues = 0; (atok)->nsamples = 0; } \ + if ( !has_values ) rtok->nvalues = 0; \ } -static int vector_logic_and(token_t *atok, token_t *btok, int and_type) +static int vector_logic_or(filter_t *filter, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - // We are comparing either two scalars (result of INFO tag vs a threshold), two vectors (two FORMAT fields), - // or a vector and a scalar (FORMAT field vs threshold) - int i, pass_site = 0; - if ( !atok->nvalues || !btok->nvalues ) - { - atok->nvalues = atok->nsamples = 0; - return 0; - } - if ( !atok->nsamples && !btok->nsamples ) return atok->pass_site && btok->pass_site; - if ( atok->nsamples && btok->nsamples ) + token_t *atok = stack[nstack-2]; + token_t *btok = stack[nstack-1]; + tok_init_samples(atok, btok, rtok); + + if ( !atok->pass_site && !btok->pass_site ) return 2; + + rtok->pass_site = 1; + if ( !atok->nsamples && !btok->nsamples ) return 2; + + int i; + if ( rtok->tok_type==TOK_OR_VEC ) // ||, select all samples if one is true { - if ( and_type==TOK_AND ) + if ( (!atok->nsamples && !atok->pass_site) || (!btok->nsamples && !btok->pass_site) ) { - // perform AND within a sample - for (i=0; insamples; i++) + // These two conditions are to ensure the following does not set all samples + // at sites with QUAL<=30: + // QUAL>30 || FMT/GQ>30 + + token_t *tok = atok->nsamples ? atok : btok; + for (i=0; insamples; i++) { - atok->pass_samples[i] = atok->pass_samples[i] && btok->pass_samples[i]; - if ( !pass_site && atok->pass_samples[i] ) pass_site = 1; + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = tok->pass_samples[i]; } } else { - // perform AND across samples - int pass_a = 0, pass_b = 0; - for (i=0; insamples; i++) + for (i=0; insamples; i++) { - if ( atok->pass_samples[i] ) pass_a = 1; - atok->pass_samples[i] = atok->pass_samples[i] && btok->pass_samples[i]; + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = 1; } - for (i=0; insamples; i++) - { - if ( btok->pass_samples[i] ) { pass_b = 1; break; } - } - pass_site = pass_a && pass_b; } - return pass_site; + return 2; } - if ( btok->nsamples ) + + // |, only select samples which are actually true + + if ( !atok->nsamples || !btok->nsamples ) { - for (i=0; insamples; i++) + token_t *tok = atok->nsamples ? atok : btok; + for (i=0; insamples; i++) { - atok->pass_samples[i] = atok->pass_site && btok->pass_samples[i]; - if ( !pass_site && atok->pass_samples[i] ) pass_site = 1; + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = tok->pass_samples[i]; } - atok->nsamples = btok->nsamples; - return pass_site; + return 2; } - /* atok->nsamples!=0 */ - for (i=0; insamples; i++) + + assert( atok->nsamples==btok->nsamples ); + + for (i=0; insamples; i++) { - atok->pass_samples[i] = atok->pass_samples[i] && btok->pass_site; - if ( !pass_site && atok->pass_samples[i] ) pass_site = 1; + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = atok->pass_samples[i] | btok->pass_samples[i]; } - return pass_site; + return 2; } -static int vector_logic_or(token_t *atok, token_t *btok, int or_type) +static int vector_logic_and(filter_t *filter, bcf1_t *line, token_t *rtok, token_t **stack, int nstack) { - int i, pass_site = 0; - if ( !atok->nvalues && !btok->nvalues ) // missing sites in both - { - atok->nvalues = atok->nsamples = 0; - return 0; - } - if ( !atok->nvalues ) // missing value in a - { - for (i=0; insamples; i++) - atok->pass_samples[i] = btok->pass_samples[i]; - atok->nsamples = btok->nsamples; - return btok->pass_site; - } - if ( !btok->nvalues ) // missing value in b - return atok->pass_site; + token_t *atok = stack[nstack-2]; + token_t *btok = stack[nstack-1]; + tok_init_samples(atok, btok, rtok); + + if ( !atok->pass_site || !btok->pass_site ) return 2; + if ( !atok->nsamples && !btok->nsamples ) { rtok->pass_site = 1; return 2; } - if ( !atok->nsamples && !btok->nsamples ) return atok->pass_site || btok->pass_site; - if ( !atok->nsamples ) + int i; + if ( !atok->nsamples || !btok->nsamples ) { - if ( or_type==TOK_OR ) + token_t *tok = atok->nsamples ? atok : btok; + for (i=0; insamples; i++) { - for (i=0; insamples; i++) - { - atok->pass_samples[i] = btok->pass_samples[i]; - if ( atok->pass_site || atok->pass_samples[i] ) pass_site = 1; - } - } - else - { - for (i=0; insamples; i++) - { - atok->pass_samples[i] = atok->pass_site || btok->pass_samples[i]; - if ( atok->pass_samples[i] ) pass_site = 1; - } + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = tok->pass_samples[i]; } - atok->nsamples = btok->nsamples; - return pass_site; + rtok->pass_site = 1; + return 2; } - if ( !btok->nsamples ) // vector vs site + + assert( atok->nsamples==btok->nsamples ); + if ( rtok->tok_type==TOK_AND_VEC ) // &&, can be true in different samples { - if ( or_type==TOK_OR ) - { - for (i=0; insamples; i++) - if ( btok->pass_site || atok->pass_samples[i] ) pass_site = 1; - } - else + for (i=0; insamples; i++) { - for (i=0; insamples; i++) - { - atok->pass_samples[i] = atok->pass_samples[i] || btok->pass_site; - if ( atok->pass_samples[i] ) pass_site = 1; - } + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = atok->pass_samples[i] | btok->pass_samples[i]; } - return pass_site; + rtok->pass_site = 1; } - for (i=0; insamples; i++) + else // &, must be true within one sample { - atok->pass_samples[i] = atok->pass_samples[i] || btok->pass_samples[i]; - if ( !pass_site && atok->pass_samples[i] ) pass_site = 1; + for (i=0; insamples; i++) + { + if ( !rtok->usmpl[i] ) continue; + rtok->pass_samples[i] = atok->pass_samples[i] & btok->pass_samples[i]; + if ( rtok->pass_samples[i] ) rtok->pass_site = 1; + } } - return pass_site; + return 2; } #define CMP_MISSING(atok,btok,CMP_OP,ret) \ @@ -980,164 +1299,397 @@ static int vector_logic_or(token_t *atok, token_t *btok, int or_type) if ( (atok)->nsamples || (btok)->nsamples ) error("todo: Querying of missing values in FORMAT\n"); \ token_t *tok = (atok)->is_missing ? (btok) : (atok); \ (ret) = ( tok->nvalues CMP_OP 1 ) ? 0 : 1; \ + tok->nvalues = 1; \ } -#define CMP_VECTORS(atok,btok,CMP_OP,ret) \ +#define CMP_VECTORS(atok,btok,_rtok,CMP_OP,missing_logic) \ { \ - int i, j, has_values = 0, pass_site = 0; \ - if ( !(atok)->nvalues || !(btok)->nvalues ) { (atok)->nvalues = 0; (atok)->nsamples = 0; (ret) = 0; } \ - else \ + token_t *rtok = _rtok; \ + int i, j, k; \ + assert( !atok->nsamples || !btok->nsamples ); \ + tok_init_samples(atok, btok, rtok); \ + if ( !atok->nsamples && !btok->nsamples ) \ { \ - if ( (atok)->nsamples && (btok)->nsamples ) \ + if ( !atok->nvalues && !btok->nvalues ) { rtok->pass_site = missing_logic[2]; } \ + else if ( !atok->nvalues || !btok->nvalues ) \ { \ - for (i=0; i<(atok)->nsamples; i++) \ + token_t *tok = atok->nvalues ? atok : btok; \ + for (j=0; jnvalues; j++) \ { \ - if ( bcf_float_is_missing((atok)->values[i]) ) { (atok)->pass_samples[i] = 0; continue; } \ - if ( bcf_float_is_missing((btok)->values[i]) ) { (atok)->pass_samples[i] = 0; continue; } \ - has_values = 1; \ - if ( (atok)->values[i] CMP_OP (btok)->values[i] ) { (atok)->pass_samples[i] = 1; pass_site = 1; } \ - else (atok)->pass_samples[i] = 0; \ + if ( bcf_double_is_missing(tok->values[j]) ) \ + { \ + if ( missing_logic[2] ) { rtok->pass_site = 1; break; } \ + } \ + else if ( missing_logic[1] ) { rtok->pass_site = 1; break; } \ } \ - if ( !has_values ) (atok)->nvalues = 0; \ } \ - else if ( (atok)->nsamples ) \ + else \ { \ - if ( bcf_float_is_missing((btok)->values[0]) ) { (atok)->nvalues = 0; (atok)->nsamples = 0; (ret) = 0; } \ - else \ + for (i=0; invalues; i++) \ { \ - for (i=0; i<(atok)->nsamples; i++) \ + int amiss = bcf_double_is_missing(atok->values[i]) ? 1 : 0; \ + for (j=0; jnvalues; j++) \ { \ - if ( bcf_float_is_missing((atok)->values[i]) ) { (atok)->pass_samples[i] = 0; continue; } \ - has_values = 1; \ - if ( (atok)->values[i] CMP_OP (btok)->values[0] ) { (atok)->pass_samples[i] = 1; pass_site = 1; } \ - else (atok)->pass_samples[i] = 0; \ + int nmiss = amiss + (bcf_double_is_missing(btok->values[j]) ? 1 : 0); \ + if ( nmiss ) \ + { \ + if ( missing_logic[nmiss] ) { rtok->pass_site = 1; i = atok->nvalues; break; } \ + } \ + else if ( atok->values[i] CMP_OP btok->values[j] ) { rtok->pass_site = 1; i = atok->nvalues; break; } \ } \ } \ - if ( !has_values ) (atok)->nvalues = 0; \ } \ - else if ( (btok)->nsamples ) \ + } \ + else \ + { \ + if ( !atok->nvalues && !btok->nvalues ) \ { \ - if ( bcf_float_is_missing((atok)->values[0]) ) { (atok)->nvalues = 0; (atok)->nsamples = 0; (ret) = 0; } \ - else \ + if ( missing_logic[2] ) \ { \ - for (i=0; i<(btok)->nsamples; i++) \ - { \ - if ( bcf_float_is_missing((btok)->values[i]) ) { (atok)->pass_samples[i] = 0; continue; } \ - has_values = 1; \ - if ( (atok)->values[0] CMP_OP (btok)->values[i] ) { (atok)->pass_samples[i] = 1; pass_site = 1; } \ - else (atok)->pass_samples[i] = 0; \ - } \ - (atok)->nvalues = (btok)->nvalues; \ - (atok)->nsamples = (btok)->nsamples; \ + for (i=0; insamples; i++) \ + if ( rtok->usmpl[i] ) { rtok->pass_samples[i] = missing_logic[2]; rtok->pass_site = 1; } \ } \ - if ( !has_values ) (atok)->nvalues = 0; \ } \ - else if ( (atok)->idx==-2 || (btok)->idx==-2 ) \ + else if ( !atok->nvalues || !btok->nvalues ) \ { \ - /* any field can match: [*] */ \ - for (i=0; i<(atok)->nvalues; i++) \ + token_t *tok = atok->nvalues ? atok : btok; \ + if ( !tok->nsamples ) \ { \ - for (j=0; j<(btok)->nvalues; j++) \ - if ( (atok)->values[i] CMP_OP (btok)->values[j] ) { pass_site = 1; i = (atok)->nvalues; break; } \ + int miss = 0; \ + for (j=0; jnvalues; j++) \ + miss |= bcf_double_is_missing(tok->values[j]) ? 1 : 0; \ + if ( missing_logic[++miss] ) \ + { \ + for (i=0; insamples; i++) \ + if ( rtok->usmpl[i] ) { rtok->pass_samples[i] = missing_logic[miss]; rtok->pass_site = 1; } \ + } \ } \ + else \ + for (i=0; insamples; i++) \ + { \ + if ( !rtok->usmpl[i] ) continue; \ + double *ptr = tok->values + i*tok->nval1; \ + int miss = 0; \ + for (j=0; jnval1; j++) \ + miss |= bcf_double_is_missing(ptr[j]) ? 1 : 0; \ + if ( missing_logic[++miss] ) { rtok->pass_samples[i] = missing_logic[miss]; rtok->pass_site = 1; } \ + } \ } \ else \ { \ - if ( (atok)->values[0] CMP_OP (btok)->values[0] ) { pass_site = 1; } \ + token_t *xtok = atok->nsamples ? atok : btok; \ + token_t *ytok = atok->nsamples ? btok : atok; \ + for (i=0; insamples; i++) \ + { \ + if ( !rtok->usmpl[i] ) continue; \ + double *xptr = xtok->values + i*xtok->nval1; \ + double *yptr = ytok->values + i*ytok->nval1; \ + for (j=0; jnval1; j++) \ + { \ + int miss = bcf_double_is_missing(xptr[j]) ? 1 : 0; \ + if ( miss && !missing_logic[0] ) continue; /* any is missing => result is false */ \ + for (k=0; knvalues; k++) \ + { \ + int nmiss = miss + (bcf_double_is_missing(yptr[k]) ? 1 : 0); \ + if ( nmiss ) \ + { \ + if ( missing_logic[nmiss] ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; j = xtok->nval1; break; } \ + } \ + else if ( xptr[j] CMP_OP yptr[k] ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; j = xtok->nval1; break; } \ + } \ + } \ + } \ } \ - /*fprintf(pysam_stderr,"pass=%d\n", pass_site);*/ \ - (ret) = pass_site; \ } \ } -static int cmp_vector_strings(token_t *atok, token_t *btok, int logic) // logic: TOK_EQ or TOK_NE +static int _regex_vector_strings(regex_t *regex, char *str, size_t len, int logic, int *missing_logic) { - if ( !atok->nvalues ) { return 0; } - if ( !btok->nvalues ) { atok->nvalues = 0; return 0; } - int i, pass_site = 0; - if ( atok->nsamples && atok->nsamples==btok->nsamples ) - { - for (i=0; insamples; i++) - { - char *astr = atok->str_value + i*(int)atok->values[0]; - char *bstr = btok->str_value + i*(int)btok->values[0]; - char *aend = astr + (int)atok->values[0], *a = astr; - while ( avalues[0], *b = bstr; - while ( bpass_samples[i] = 0; - else atok->pass_samples[i] = strncmp(astr,bstr,a-astr)==0 ? 1 : 0; - if ( logic!=TOK_EQ ) - atok->pass_samples[i] = atok->pass_samples[i] ? 0 : 1; - pass_site |= atok->pass_samples[i]; - } - if ( !atok->nsamples ) atok->nsamples = btok->nsamples; - } - else if ( !atok->nsamples && !btok->nsamples ) - { - if ( atok->idx==-2 || btok->idx==-2 ) - { - // any field can match: [*] - if ( atok->idx==-2 && btok->idx==-2 ) - error("fixme: Expected at least one scalar value [%s %s %s]\n", atok->tag ? atok->tag : btok->tag, atok->str_value,btok->str_value); - token_t *xtok, *ytok; // xtok is scalar, ytok array - if ( btok->idx==-2 ) { xtok = atok; ytok = btok; } - else { xtok = btok; ytok = atok; } - char *xstr = xtok->str_value, *xend = xstr + xtok->nvalues; - char *ystr = ytok->str_value, *yend = ystr + ytok->nvalues, *y = ystr; - while ( y<=yend ) + char *end = str + len; + while ( str < end && *str ) + { + char *mid = str; + while ( mid < end && *mid && *mid!=',' ) mid++; + int miss = mid - str == 1 && str[0]=='.' ? 1 : 0; + if ( miss && missing_logic[miss] ) return 1; + char tmp = *mid; *mid = 0; + int match = regexec(regex, str, 0,NULL,0) ? 0 : 1; + *mid = tmp; + if ( logic==TOK_NLIKE ) match = match ? 0 : 1; + if ( match ) return 1; + if ( !*mid ) break; + str = mid + 1; + } + return 0; +} +static inline int _has_missing_string(char *beg) +{ + while ( *beg ) + { + char *end = beg; + while ( *end && *end!=',' ) end++; + if ( end-beg==1 && beg[0]=='.' ) return 1; + if ( !*end ) break; + beg = end + 1; + } + return 0; +} + +// Compare two strings with multiple fields, for example "A,B,.,C"=="X,Y,A". +// Returns 1 if any field matches, otherwise returns 0 +static inline int _match_vector_strings(char *abeg, size_t alen, char *bstr, size_t blen, int logic, int *missing_logic) +{ + char *aend = abeg + alen; + char *bend = bstr + blen; + while ( abeg < aend && *abeg ) + { + char *amid = abeg; + while ( amid < aend && *amid && *amid!=',' ) amid++; + int miss = amid - abeg == 1 && abeg[0]=='.' ? 1 : 0; + char *bbeg = bstr; + while ( bbeg < bend && *bbeg ) + { + char *bmid = bbeg; + while ( bmid < bend && *bmid && *bmid!=',' ) bmid++; + int nmiss = miss + (bmid - bbeg == 1 && bbeg[0]=='.' ? 1 : 0); + if ( nmiss ) { - if ( y==yend || *y==',' ) - { - if ( y-ystr==xend-xstr && !strncmp(xstr,ystr,xend-xstr) ) - { - pass_site = 1; - break; - } - ystr = y+1; - } - y++; + if ( missing_logic[nmiss] ) return 1; } + else + { + int match = amid-abeg==bmid-bbeg && !strncmp(abeg,bbeg,amid-abeg) ? 1 : 0; + if ( logic==TOK_NE ) match = match==1 ? 0 : 1; + if ( match ) return 1; + } + if ( !*bmid ) break; + bbeg = bmid + 1; } + if ( !*amid ) break; + abeg = amid + 1; + } + return 0; +} +static void cmp_vector_strings(token_t *atok, token_t *btok, token_t *rtok) +{ + tok_init_samples(atok, btok, rtok); + + int i, logic = rtok->tok_type; // TOK_EQ, TOK_NE, TOK_LIKE, TOK_NLIKE + regex_t *regex = atok->regex ? atok->regex : (btok->regex ? btok->regex : NULL); + + assert( atok->nvalues==atok->str_value.l && btok->nvalues==btok->str_value.l ); + assert( !atok->nsamples || !btok->nsamples ); + assert( (!regex && (logic==TOK_EQ || logic==TOK_NE)) || (regex && (logic==TOK_LIKE || logic==TOK_NLIKE)) ); + + int missing_logic[] = {0,0,0}; + if ( logic==TOK_EQ || logic==TOK_LIKE ) missing_logic[0] = missing_logic[2] = 1; + else if ( logic==TOK_NE || logic==TOK_NLIKE ) missing_logic[0] = missing_logic[1] = 1; + + if ( !atok->nsamples && !btok->nsamples ) + { + if ( !atok->nvalues && !btok->nvalues ) { rtok->pass_site = missing_logic[2]; return; } + if ( !atok->nvalues || !btok->nvalues ) + { + int miss = _has_missing_string(atok->nvalues ? atok->str_value.s : btok->str_value.s); + if ( missing_logic[miss+1] ) rtok->pass_site = 1; + return; + } + if ( !regex ) + rtok->pass_site = _match_vector_strings(atok->str_value.s, atok->str_value.l, btok->str_value.s, btok->str_value.l, logic, missing_logic); else - pass_site = strcmp(atok->str_value,btok->str_value) ? 0 : 1; - if ( logic!=TOK_EQ ) pass_site = pass_site ? 0 : 1; + { + token_t *tok = atok->regex ? btok : atok; + rtok->pass_site = _regex_vector_strings(regex, tok->str_value.s, tok->str_value.l, logic, missing_logic); + } + return; } - else + + // The case of (!atok->nsamples || !btok->nsamples) + + if ( !atok->nvalues && !btok->nvalues ) + { + if ( missing_logic[2] ) + { + for (i=0; insamples; i++) + if ( rtok->usmpl[i] ) { rtok->pass_samples[i] = missing_logic[2]; rtok->pass_site = 1; } + } + return; + } + if ( !atok->nvalues || !btok->nvalues ) { - token_t *xtok, *ytok; - if ( !atok->nsamples ) { xtok = atok; ytok = btok; } - else { xtok = btok; ytok = atok; } - char *xstr = xtok->str_value; - char *xend = xstr + (int)xtok->values[0], *x = xstr; - while ( xnsamples; i++) - { - char *ystr = ytok->str_value + i*(int)ytok->values[0]; - char *yend = ystr + (int)ytok->values[0], *y = ystr; - while ( ypass_samples[i] = 0; - else atok->pass_samples[i] = strncmp(xstr,ystr,x-xstr)==0 ? 1 : 0; - if ( logic!=TOK_EQ ) - atok->pass_samples[i] = atok->pass_samples[i] ? 0 : 1; - pass_site |= atok->pass_samples[i]; - } - if ( !atok->nsamples ) - atok->nvalues = atok->nsamples = btok->nsamples; // is it a bug? not sure if atok->nvalues should be set - } - return pass_site; + token_t *tok = atok->nvalues ? atok : btok; + if ( !tok->nsamples ) + { + int miss = _has_missing_string(tok->str_value.s); + if ( !missing_logic[miss+1] ) return; + for (i=0; insamples; i++) + if ( rtok->usmpl[i] ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; } + } + else + for (i=0; insamples; i++) + { + if ( !rtok->usmpl[i] ) continue; + int miss = _has_missing_string(tok->str_value.s + i*tok->nval1); + if ( missing_logic[miss+1] ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; } + } + return; + } + + // The case of (!atok->nsamples || !btok->nsamples) && (atok->nvalues && btok->nvalues) + token_t *xtok = atok->nsamples ? atok : btok; + token_t *ytok = atok->nsamples ? btok : atok; + assert( regex==ytok->regex ); + for (i=0; insamples; i++) + { + if ( !rtok->usmpl[i] ) continue; + int match; + if ( regex ) + match = _regex_vector_strings(regex, xtok->str_value.s + i*xtok->nval1, xtok->nval1, logic, missing_logic); + else + match = _match_vector_strings(xtok->str_value.s + i*xtok->nval1, xtok->nval1, ytok->str_value.s, ytok->str_value.l, logic, missing_logic); + if ( match ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; } + } } -static int regex_vector_strings(token_t *atok, token_t *btok) + +static int parse_idxs(char *tag_idx, int **idxs, int *nidxs, int *idx) { - int ret = regexec(btok->regex, atok->str_value, 0,NULL,0); - return ret==0 ? 1 : 0; + // TAG[], TAG[*] .. any field; sets idx=-2, idxs[0]=-1 + if ( *tag_idx==0 || !strcmp("*", tag_idx) ) + { + *idxs = (int*) malloc(sizeof(int)); + (*idxs)[0] = -1; + *nidxs = 1; + *idx = -2; + return 0; + } + + // TAG[integer] .. one field; idx positive + char *end, *beg = tag_idx; + *idx = strtol(tag_idx, &end, 10); + if ( *idx >= 0 && *end==0 ) return 0; + + // TAG[0,1] or TAG[0-2] or [1-] etc; idx=-2, idxs[...]=0,0,1,1,.. + int i, ibeg = -1; + while ( *beg ) + { + int num = strtol(beg, &end, 10); + if ( end[0]==',' ) beg = end + 1; + else if ( end[0]==0 ) beg = end; + else if ( end[0]=='-' ) { beg = end + 1; ibeg = num; continue; } + else return -1; + if ( num >= *nidxs ) + { + *idxs = (int*) realloc(*idxs, sizeof(int)*(num+1)); + memset(*idxs + *nidxs, 0, sizeof(int)*(num - *nidxs + 1)); + *nidxs = num + 1; + } + if ( ibeg>=0 ) + { + for (i=ibeg; i<=num; i++) (*idxs)[i] = 1; + ibeg = -1; + } + (*idxs)[num] = 1; + } + if ( ibeg >=0 ) + { + if ( ibeg >= *nidxs ) + { + *idxs = (int*) realloc(*idxs, sizeof(int)*(ibeg+1)); + memset(*idxs + *nidxs, 0, sizeof(int)*(ibeg - *nidxs + 1)); + *nidxs = ibeg + 1; + } + (*idxs)[ibeg] = -1; + } + *idx = -2; + return 0; } +static void parse_tag_idx(bcf_hdr_t *hdr, int is_fmt, char *tag, char *tag_idx, token_t *tok) // tag_idx points just after "TAG[" +{ + int i, len = strlen(tag_idx); + if ( tag_idx[len-1] == ']' ) tag_idx[len-1] = 0; + char *ori = strdup(tag_idx); + + assert( !tok->idxs && !tok->usmpl ); + int *idxs1 = NULL, nidxs1 = 0, idx1 = 0; + int *idxs2 = NULL, nidxs2 = 0, idx2 = 0; + + int set_samples = 0; + char *colon = index(tag_idx, ':'); + if ( colon ) + { + *colon = 0; + if ( parse_idxs(tag_idx, &idxs1, &nidxs1, &idx1) != 0 ) error("Could not parse the index: %s\n", ori); + if ( parse_idxs(colon+1, &idxs2, &nidxs2, &idx2) != 0 ) error("Could not parse the index: %s\n", ori); + tok->idxs = idxs2; + tok->nidxs = nidxs2; + tok->idx = idx2; + set_samples = 1; + } + else + { + if ( parse_idxs(tag_idx, &idxs1, &nidxs1, &idx1) != 0 ) error("Could not parse the index: %s\n", ori); + if ( is_fmt ) + { + if ( nidxs1==1 && idxs1[0]==-1 ) + { + tok->idxs = (int*) malloc(sizeof(int)); + tok->idxs[0] = -1; + tok->nidxs = 1; + tok->idx = -2; + } + else if ( bcf_hdr_id2number(hdr,BCF_HL_FMT,tok->hdr_id)!=1 ) + error("The FORMAT tag %s can have multiple subfields, run as %s[sample:subfield]\n", tag,tag); + else + tok->idx = 0; + set_samples = 1; + } + else + { + tok->idxs = idxs1; + tok->nidxs = nidxs1; + tok->idx = idx1; + } + } + + if ( set_samples ) + { + tok->nsamples = bcf_hdr_nsamples(hdr); + tok->usmpl = (uint8_t*) calloc(tok->nsamples,1); + if ( idx1>=0 ) + { + if ( idx1 >= bcf_hdr_nsamples(hdr) ) error("The sample index is too large: %s\n", ori); + tok->usmpl[idx1] = 1; + } + else if ( idx1==-2 ) + { + for (i=0; i= bcf_hdr_nsamples(hdr) ) error("The sample index is too large: %s\n", ori); + tok->usmpl[i] = 1; + } + if ( nidxs1 && idxs1[nidxs1-1]==-1 ) // open range, such as "7-" + { + for (; insamples; i++) tok->usmpl[i] = 1; + } + } + else error("todo: %s:%d .. %d\n", __FILE__,__LINE__, idx2); + free(idxs1); + } + free(ori); + + if ( tok->nidxs && tok->idxs[tok->nidxs-1]!=-1 ) + { + for (i=0; inidxs; i++) if ( tok->idxs[i] ) tok->nuidxs++; + } +} static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) { tok->tok_type = TOK_VAL; tok->hdr_id = -1; tok->pass_site = -1; - tok->idx = -1; + tok->idx = 0; // is this a string constant? if ( str[0]=='"' || str[0]=='\'' ) @@ -1145,7 +1697,7 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) int quote = str[0]; if ( str[len-1] != quote ) error("TODO: [%s]\n", filter->str); tok->key = (char*) calloc(len-1,sizeof(char)); - hts_expand(float,1,tok->mvalues,tok->values); + hts_expand(double,1,tok->mvalues,tok->values); tok->values[0] = len-2; memcpy(tok->key,str+1,len-2); tok->key[len-2] = 0; @@ -1232,6 +1784,10 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) tok->setter = &filters_set_alt_string; tok->is_str = 1; tok->tag = strdup("ALT"); + tok->idxs = (int*) malloc(sizeof(int)); + tok->idxs[0] = -1; + tok->nidxs = 1; + tok->idx = -2; return 0; } else if ( !strncasecmp(str,"N_ALT",len) ) @@ -1246,6 +1802,18 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) tok->threshold = bcf_hdr_nsamples(filter->hdr); return 0; } + else if ( !strncasecmp(str,"N_MISSING",len) ) + { + tok->setter = &filters_set_nmissing; + tok->tag = strdup("N_MISSING"); + return 0; + } + else if ( !strncasecmp(str,"F_MISSING",len) ) + { + tok->setter = &filters_set_nmissing; + tok->tag = strdup("F_MISSING"); + return 0; + } } // does it have array subscript? @@ -1257,17 +1825,6 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) int i; for (i=0; iidx = -2; // tag[*] .. any field - else - { - char *end; - tok->idx = strtol(tmp.s+is_array, &end, 10); - if ( *end!=']' ) error("Could not parse the index: %s[%s\n", tmp.s,tmp.s+is_array); - } - } } tok->hdr_id = bcf_hdr_id2int(filter->hdr,BCF_DT_ID,tmp.s); if ( is_fmt==-1 ) @@ -1279,6 +1836,16 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) } if ( is_fmt==-1 ) is_fmt = 0; } + if ( is_array ) + parse_tag_idx(filter->hdr, is_fmt, tmp.s, tmp.s+is_array, tok); + else if ( is_fmt && !tok->nsamples ) + { + int i; + tok->nsamples = bcf_hdr_nsamples(filter->hdr); + tok->usmpl = (uint8_t*) malloc(tok->nsamples); + for (i=0; insamples; i++) tok->usmpl[i] = 1; + } + tok->type = is_fmt ? BCF_HL_FMT : BCF_HL_INFO; if ( is_fmt ) filter->max_unpack |= BCF_UN_FMT; if ( tok->hdr_id>=0 ) @@ -1292,7 +1859,12 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) if ( !bcf_hdr_idinfo_exists(filter->hdr,BCF_HL_FMT,tok->hdr_id) ) error("No such FORMAT field: %s\n", tmp.s); if ( bcf_hdr_id2number(filter->hdr,BCF_HL_FMT,tok->hdr_id)!=1 && !is_array ) - error("Error: FORMAT vectors must be subscripted, e.g. %s[0] or %s[*]\n", tmp.s, tmp.s); + { + tok->idxs = (int*) malloc(sizeof(int)); + tok->idxs[0] = -1; + tok->nidxs = 1; + tok->idx = -2; + } switch ( bcf_hdr_id2type(filter->hdr,BCF_HL_FMT,tok->hdr_id) ) { case BCF_HT_INT: tok->setter = &filters_set_format_int; break; @@ -1321,7 +1893,13 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) case BCF_HT_STR: tok->setter = &filters_set_info_string; tok->is_str = 1; break; default: error("[%s:%d %s] FIXME\n", __FILE__,__LINE__,__FUNCTION__); } - if(!is_array) tok->idx = -2; + if (!is_array) + { + tok->idx = -2; + tok->idxs = (int*) malloc(sizeof(int)); + tok->idxs[0] = -1; + tok->nidxs = 1; + } } } filter->max_unpack |= BCF_UN_INFO; @@ -1374,11 +1952,18 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok) return 0; } - // is it a value? + // is it a value? Here we parse as integer/float separately and use strtof + // rather than strtod, because the more accurate double representation + // would invalidate floating point comparisons like QUAL=59.2, obtained via + // htslib/vcf parser char *end; - errno = 0; - tok->threshold = strtod(tmp.s, &end); - if ( errno!=0 || end!=tmp.s+len ) error("[%s:%d %s] Error: the tag \"INFO/%s\" is not defined in the VCF header\n", __FILE__,__LINE__,__FUNCTION__,tmp.s); + tok->threshold = strtol(tmp.s, &end, 10); // integer? + if ( end - tmp.s != strlen(tmp.s) ) + { + errno = 0; + tok->threshold = strtof(tmp.s, &end); // float? + if ( errno!=0 || end!=tmp.s+len ) error("[%s:%d %s] Error: the tag \"%s\" is not defined in the VCF header\n", __FILE__,__LINE__,__FUNCTION__,tmp.s); + } if ( tmp.s ) free(tmp.s); return 0; @@ -1394,19 +1979,24 @@ static void filter_debug_print(token_t *toks, token_t **tok_ptrs, int ntoks) if ( tok->tok_type==TOK_VAL ) { if ( tok->key ) - fprintf(pysam_stderr,"%s", tok->key); + fprintf(bcftools_stderr,"%s", tok->key); else if ( tok->tag ) - fprintf(pysam_stderr,"%s", tok->tag); + fprintf(bcftools_stderr,"%s", tok->tag); else - fprintf(pysam_stderr,"%e", tok->threshold); + fprintf(bcftools_stderr,"%e", tok->threshold); } else - fprintf(pysam_stderr,"%c", TOKEN_STRING[tok->tok_type]); - if ( tok->setter ) fprintf(pysam_stderr,"\t[setter %p]", tok->setter); - fprintf(pysam_stderr,"\n"); + fprintf(bcftools_stderr,"%c", TOKEN_STRING[tok->tok_type]); + if ( tok->setter ) fprintf(bcftools_stderr,"\t[setter %p]", tok->setter); + fprintf(bcftools_stderr,"\n"); } } +static void str_to_lower(char *str) +{ + while ( *str ) { *str = tolower(*str); str++; } +} + // Parse filter expression and convert to reverse polish notation. Dijkstra's shunting-yard algorithm filter_t *filter_init(bcf_hdr_t *hdr, const char *str) @@ -1427,8 +2017,8 @@ filter_t *filter_init(bcf_hdr_t *hdr, const char *str) ret = filters_next_token(&tmp, &len); if ( ret==-1 ) error("Missing quotes in: %s\n", str); - //fprintf(pysam_stderr,"token=[%c] .. [%s] %d\n", TOKEN_STRING[ret], tmp, len); - //int i; for (i=0; i0 && out[j].is_str && !strcmp(".",out[j].key) ) + if ( out[j].is_str && out[j].key && !strcmp(".",out[j].key) ) { - int type = bcf_hdr_id2type(filter->hdr,out[k].type,out[k].hdr_id); - if ( type==BCF_HT_INT ) { out[j].is_str = 0; out[j].is_missing = 1; bcf_float_set_missing(out[j].values[0]); } - if ( type==BCF_HT_REAL ) { out[j].is_str = 0; out[j].is_missing = 1; bcf_float_set_missing(out[j].values[0]); } + int set_missing = 0; + if ( out[k].hdr_id>0 ) + { + int type = bcf_hdr_id2type(filter->hdr,out[k].type,out[k].hdr_id); + if ( type==BCF_HT_INT ) set_missing = 1; + else if ( type==BCF_HT_REAL ) set_missing = 1; + } + else if ( !strcmp("QUAL",out[k].tag) ) set_missing = 1; + if ( set_missing ) { out[j].is_str = 0; out[j].is_missing = 1; bcf_double_set_missing(out[j].values[0]); } } } if ( out[i].tok_type==TOK_LIKE || out[i].tok_type==TOK_NLIKE ) @@ -1526,7 +2126,14 @@ filter_t *filter_init(bcf_hdr_t *hdr, const char *str) if ( !out[j].key ) error("Could not parse the expression, wrong value for regex operator: %s\n", filter->str); out[j].regex = (regex_t *) malloc(sizeof(regex_t)); - if ( regcomp(out[j].regex, out[j].key, REG_ICASE|REG_NOSUB) ) + int cflags = REG_NOSUB; + int len = strlen(out[j].key); + if ( len>2 && out[j].key[len-1]=='i' && out[j].key[len-2]=='/' && out[j].key[len-3]!='\\' ) + { + out[j].key[len-2] = 0; + cflags |= REG_ICASE; + } + if ( regcomp(out[j].regex, out[j].key, cflags) ) error("Could not compile the regex expression \"%s\": %s\n", out[j].key,filter->str); } if ( out[i].tok_type!=TOK_VAL ) continue; @@ -1534,59 +2141,93 @@ filter_t *filter_init(bcf_hdr_t *hdr, const char *str) if ( !strcmp(out[i].tag,"TYPE") ) { if ( i+1==nout ) error("Could not parse the expression: %s\n", filter->str); - int j = i+1; - if ( out[j].tok_type==TOK_EQ || out[j].tok_type==TOK_NE ) j = i - 1; - if ( out[j].tok_type!=TOK_VAL || !out[j].key ) error("[%s:%d %s] Could not parse the expression: %s\n", __FILE__,__LINE__,__FUNCTION__, filter->str); - if ( !strcasecmp(out[j].key,"snp") || !strcasecmp(out[j].key,"snps") ) { out[j].threshold = VCF_SNP; out[j].is_str = 0; } - else if ( !strcasecmp(out[j].key,"indel") || !strcasecmp(out[j].key,"indels") ) { out[j].threshold = VCF_INDEL; out[j].is_str = 0; } - else if ( !strcasecmp(out[j].key,"mnp") || !strcasecmp(out[j].key,"mnps") ) { out[j].threshold = VCF_MNP; out[j].is_str = 0; } - else if ( !strcasecmp(out[j].key,"other") ) { out[j].threshold = VCF_OTHER; out[j].is_str = 0; } - else if ( !strcasecmp(out[j].key,"ref") ) { out[j].threshold = VCF_REF; out[j].is_str = 0; } - else error("The type \"%s\" not recognised: %s\n", out[j].key, filter->str); - out[j].tag = out[j].key; out[j].key = NULL; - i = j; + int itok, ival; + if ( out[i+1].tok_type==TOK_EQ || out[i+1].tok_type==TOK_NE ) ival = i - 1, itok = i + 1; + else if ( out[i+1].tok_type==TOK_LIKE || out[i+1].tok_type==TOK_NLIKE ) ival = i - 1, itok = i + 1; + else if ( out[i+2].tok_type==TOK_EQ || out[i+2].tok_type==TOK_NE ) itok = i + 2, ival = i + 1; + else if ( out[i+2].tok_type==TOK_LIKE || out[i+2].tok_type==TOK_NLIKE ) itok = i + 2, ival = i + 1; + else error("[%s:%d %s] Could not parse the expression: %s\n", __FILE__,__LINE__,__FUNCTION__, filter->str); + if ( !strcasecmp(out[ival].key,"snp") || !strcasecmp(out[ival].key,"snps") ) { out[ival].threshold = VCF_SNP<<1; out[ival].is_str = 0; } + else if ( !strcasecmp(out[ival].key,"indel") || !strcasecmp(out[ival].key,"indels") ) { out[ival].threshold = VCF_INDEL<<1; out[ival].is_str = 0; } + else if ( !strcasecmp(out[ival].key,"mnp") || !strcasecmp(out[ival].key,"mnps") ) { out[ival].threshold = VCF_MNP<<1; out[ival].is_str = 0; } + else if ( !strcasecmp(out[ival].key,"other") ) { out[ival].threshold = VCF_OTHER<<1; out[ival].is_str = 0; } + else if ( !strcasecmp(out[ival].key,"bnd") ) { out[ival].threshold = VCF_BND<<1; out[ival].is_str = 0; } + else if ( !strcasecmp(out[ival].key,"ref") ) { out[ival].threshold = 1; out[ival].is_str = 0; } + else error("The type \"%s\" not recognised: %s\n", out[ival].key, filter->str); + if ( out[itok].tok_type==TOK_LIKE || out[itok].tok_type==TOK_NLIKE ) out[itok].comparator = filters_cmp_bit_and; + out[ival].tag = out[ival].key; out[ival].key = NULL; + i = itok; + continue; + } + if ( !strcmp(out[i].tag,"GT") ) + { + if ( i+1==nout ) error("Could not parse the expression: %s\n", filter->str); + int ival; + if ( out[i+1].tok_type==TOK_EQ || out[i+1].tok_type==TOK_NE ) ival = i - 1; + else if ( out[i+1].tok_type==TOK_LIKE || out[i+1].tok_type==TOK_NLIKE ) ival = i - 1; + else if ( out[i+2].tok_type==TOK_EQ || out[i+2].tok_type==TOK_NE ) ival = i + 1; + else if ( out[i+2].tok_type==TOK_LIKE || out[i+2].tok_type==TOK_NLIKE ) ival = i + 1; + else error("[%s:%d %s] Could not parse the expression: %s\n", __FILE__,__LINE__,__FUNCTION__, filter->str); + + if ( !out[ival].key ) error("Comparison between samples is not supported, sorry!\n"); + + // assign correct setters and unify expressions, eg ar->ra, HOM->hom, etc + if ( !strcasecmp(out[ival].key,"hom") ) { out[i].setter = filters_set_genotype3; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"het") ) { out[i].setter = filters_set_genotype3; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"hap") ) { out[i].setter = filters_set_genotype3; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"mis") ) { out[i].setter = filters_set_genotype4; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"ref") ) { out[i].setter = filters_set_genotype4; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"alt") ) { out[i].setter = filters_set_genotype4; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"rr") ) { out[i].setter = filters_set_genotype2; str_to_lower(out[ival].key); } + else if ( !strcasecmp(out[ival].key,"ra") || !strcasecmp(out[ival].key,"ar") ) { out[i].setter = filters_set_genotype2; out[ival].key[0]='r'; out[ival].key[1]='a'; } // ra + else if ( !strcmp(out[ival].key,"aA") || !strcmp(out[ival].key,"Aa") ) { out[i].setter = filters_set_genotype2; out[ival].key[0]='a'; out[ival].key[1]='A'; } // aA + else if ( !strcasecmp(out[ival].key,"aa") ) { out[i].setter = filters_set_genotype2; out[ival].key[0]='a'; out[ival].key[1]='a'; } // aa + else if ( !strcasecmp(out[ival].key,"a") ) { out[i].setter = filters_set_genotype2; out[ival].key[0]='a'; out[ival].key[1]=0; } // a + else if ( !strcasecmp(out[ival].key,"r") ) { out[i].setter = filters_set_genotype2; out[ival].key[0]='r'; out[ival].key[1]=0; } // r continue; } if ( !strcmp(out[i].tag,"FILTER") ) { if ( i+1==nout ) error("Could not parse the expression: %s\n", filter->str); - int j = i+1; - if ( out[j].tok_type==TOK_EQ || out[j].tok_type==TOK_NE ) j = i - 1; // the expression has "value"=FILTER rather than FILTER="value" - if ( out[j].tok_type==TOK_LIKE ) out[j].tok_type = TOK_EQ; // for FILTER, ~ and !~ work the same way as = and != - if ( out[j].tok_type==TOK_NLIKE ) out[j].tok_type = TOK_NE; - if ( out[j+1].tok_type==TOK_LIKE ) out[j+1].tok_type = TOK_EQ; - if ( out[j+1].tok_type==TOK_NLIKE ) out[j+1].tok_type = TOK_NE; - if ( out[j].tok_type!=TOK_VAL || !out[j].key ) + int itok = i, ival; + if ( out[i+1].tok_type==TOK_EQ || out[i+1].tok_type==TOK_NE ) ival = i - 1; + else if ( out[i+1].tok_type==TOK_LIKE ) out[i+1].tok_type = TOK_EQ, ival = i - 1; + else if ( out[i+1].tok_type==TOK_NLIKE ) out[i+1].tok_type = TOK_NE, ival = i - 1; + else if ( out[i+2].tok_type==TOK_EQ || out[i+2].tok_type==TOK_NE ) ival = ++i; + else if ( out[i+2].tok_type==TOK_LIKE ) out[i+2].tok_type = TOK_EQ, ival = ++i; + else if ( out[i+2].tok_type==TOK_NLIKE ) out[i+2].tok_type = TOK_NE, ival = ++i; + else error("[%s:%d %s] Could not parse the expression: %s\n", __FILE__,__LINE__,__FUNCTION__, filter->str); + if ( out[ival].tok_type!=TOK_VAL || !out[ival].key ) error("[%s:%d %s] Could not parse the expression, an unquoted string value perhaps? %s\n", __FILE__,__LINE__,__FUNCTION__, filter->str); - if ( strcmp(".",out[j].key) ) + if ( strcmp(".",out[ival].key) ) { - out[j].hdr_id = bcf_hdr_id2int(filter->hdr, BCF_DT_ID, out[j].key); - if ( !bcf_hdr_idinfo_exists(filter->hdr,BCF_HL_FLT,out[j].hdr_id) ) - error("The filter \"%s\" not present in the VCF header\n", out[j].key); + out[ival].hdr_id = bcf_hdr_id2int(filter->hdr, BCF_DT_ID, out[ival].key); + if ( !bcf_hdr_idinfo_exists(filter->hdr,BCF_HL_FLT,out[ival].hdr_id) ) + error("The filter \"%s\" not present in the VCF header\n", out[ival].key); } else - out[j].hdr_id = -1; - out[j].tag = out[j].key; out[j].key = NULL; - out[i].hdr_id = out[j].hdr_id; - i = j; + out[ival].hdr_id = -1; + out[ival].tag = out[ival].key; out[ival].key = NULL; + out[itok].hdr_id = out[ival].hdr_id; continue; } } filter->nsamples = filter->max_unpack&BCF_UN_FMT ? bcf_hdr_nsamples(filter->hdr) : 0; for (i=0; insamples ) { out[i].pass_samples = (uint8_t*)malloc(filter->nsamples); int j; - for (j=0; jnsamples; j++) out[i].pass_samples[j] = 1; + for (j=0; jnsamples; j++) out[i].pass_samples[j] = 0; } } @@ -1604,9 +2245,11 @@ void filter_destroy(filter_t *filter) int i; for (i=0; infilters; i++) { - //if ( filter->filters[i].key ) free(filter->filters[i].key); - free(filter->filters[i].str_value); + if ( filter->filters[i].key ) free(filter->filters[i].key); + free(filter->filters[i].str_value.s); free(filter->filters[i].tag); + free(filter->filters[i].idxs); + free(filter->filters[i].usmpl); free(filter->filters[i].values); free(filter->filters[i].pass_samples); if (filter->filters[i].hash) khash_str2int_destroy_free(filter->filters[i].hash); @@ -1620,6 +2263,8 @@ void filter_destroy(filter_t *filter) free(filter->flt_stack); free(filter->str); free(filter->tmpi); + free(filter->tmpf); + free(filter->tmps.s); free(filter); } @@ -1630,9 +2275,7 @@ int filter_test(filter_t *filter, bcf1_t *line, const uint8_t **samples) int i, nstack = 0; for (i=0; infilters; i++) { - filter->filters[i].nsamples = 0; - filter->filters[i].nvalues = 0; - filter->filters[i].pass_site = -1; + filter->filters[i].pass_site = 0; if ( filter->filters[i].tok_type == TOK_VAL ) { @@ -1640,22 +2283,23 @@ int filter_test(filter_t *filter, bcf1_t *line, const uint8_t **samples) filter->filters[i].setter(filter, line, &filter->filters[i]); else if ( filter->filters[i].key ) // string constant { - filter->filters[i].str_value = filter->filters[i].key; - filter->filters[i].values[0] = filter->filters[i].values[0]; - filter->filters[i].nvalues = strlen(filter->filters[i].key); + filter->filters[i].str_value.l = 0; + kputs(filter->filters[i].key, &filter->filters[i].str_value); + filter->filters[i].nvalues = filter->filters[i].str_value.l; } else // numeric constant { filter->filters[i].values[0] = filter->filters[i].threshold; filter->filters[i].nvalues = 1; } - filter->flt_stack[nstack++] = &filter->filters[i]; continue; } - else if ( filter->filters[i].tok_type == TOK_FUNC ) // all functions take only one argument + else if ( filter->filters[i].func ) { - filter->filters[i].setter(filter, line, filter->flt_stack[nstack-1]); + int nargs = filter->filters[i].func(filter, line, &filter->filters[i], filter->flt_stack, nstack); + filter->flt_stack[nstack-nargs] = &filter->filters[i]; + if ( --nargs > 0 ) nstack -= nargs; continue; } if ( nstack<2 ) @@ -1663,112 +2307,76 @@ int filter_test(filter_t *filter, bcf1_t *line, const uint8_t **samples) int is_str = filter->flt_stack[nstack-1]->is_str + filter->flt_stack[nstack-2]->is_str; - if ( filter->filters[i].tok_type == TOK_OR || filter->filters[i].tok_type == TOK_OR_VEC ) - { - if ( filter->flt_stack[nstack-1]->pass_site<0 || filter->flt_stack[nstack-2]->pass_site<0 ) - error("Error occurred while processing the filter \"%s\" (%d %d OR)\n", filter->str,filter->flt_stack[nstack-2]->pass_site,filter->flt_stack[nstack-1]->pass_site); - filter->flt_stack[nstack-2]->pass_site = vector_logic_or(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1], filter->filters[i].tok_type); - nstack--; - continue; - } - if ( filter->filters[i].tok_type == TOK_AND || filter->filters[i].tok_type == TOK_AND_VEC ) - { - if ( filter->flt_stack[nstack-1]->pass_site<0 || filter->flt_stack[nstack-2]->pass_site<0 ) - error("Error occurred while processing the filter \"%s\" (%d %d AND)\n", filter->str,filter->flt_stack[nstack-2]->pass_site,filter->flt_stack[nstack-1]->pass_site); - filter->flt_stack[nstack-2]->pass_site = vector_logic_and(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1], filter->filters[i].tok_type); - nstack--; - continue; - } - if ( filter->filters[i].tok_type == TOK_ADD ) { - VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],+); + VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],+); + filter->flt_stack[nstack-2] = &filter->filters[i]; nstack--; continue; } else if ( filter->filters[i].tok_type == TOK_SUB ) { - VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],-); + VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],-); + filter->flt_stack[nstack-2] = &filter->filters[i]; nstack--; continue; } else if ( filter->filters[i].tok_type == TOK_MULT ) { - VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],*); + VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],*); + filter->flt_stack[nstack-2] = &filter->filters[i]; nstack--; continue; } else if ( filter->filters[i].tok_type == TOK_DIV ) { - VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],/); + VECTOR_ARITHMETICS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],/); + filter->flt_stack[nstack-2] = &filter->filters[i]; nstack--; continue; } - int is_true = 0; - if ( !filter->flt_stack[nstack-1]->nvalues || !filter->flt_stack[nstack-2]->nvalues ) + // ideally, these comparators would become func, but this would require more work in init1() + if ( filter->filters[i].comparator ) { - int skip = 0; - if ( !filter->flt_stack[nstack-2]->is_missing && !filter->flt_stack[nstack-1]->is_missing ) skip = 1; - if ( filter->filters[i].tok_type != TOK_EQ && filter->filters[i].tok_type != TOK_NE ) skip = 1; - - if ( skip ) - filter->flt_stack[nstack-2]->nvalues = filter->flt_stack[nstack-2]->nsamples = 0; - else if ( filter->filters[i].tok_type == TOK_EQ ) - CMP_MISSING(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],==,is_true) - else if ( filter->filters[i].tok_type == TOK_NE ) - CMP_MISSING(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],!=,is_true) - } - else if ( filter->filters[i].tok_type == TOK_EQ ) - { - if ( filter->flt_stack[nstack-1]->comparator ) - is_true = filter->flt_stack[nstack-1]->comparator(filter->flt_stack[nstack-1],filter->flt_stack[nstack-2],TOK_EQ,line); - else if ( filter->flt_stack[nstack-2]->comparator ) - is_true = filter->flt_stack[nstack-2]->comparator(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],TOK_EQ,line); - else if ( is_str==2 ) // both are strings - is_true = cmp_vector_strings(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],TOK_EQ); - else if ( is_str==1 ) - error("Comparing string to numeric value: %s\n", filter->str); - else - CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],==,is_true); - } - else if ( filter->filters[i].tok_type == TOK_NE ) - { - if ( filter->flt_stack[nstack-1]->comparator ) - is_true = filter->flt_stack[nstack-1]->comparator(filter->flt_stack[nstack-1],filter->flt_stack[nstack-2],TOK_NE,line); - else if ( filter->flt_stack[nstack-2]->comparator ) - is_true = filter->flt_stack[nstack-2]->comparator(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],TOK_NE,line); - else if ( is_str==2 ) - is_true = cmp_vector_strings(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],TOK_NE); - else if ( is_str==1 ) - error("Comparing string to numeric value: %s\n", filter->str); - else - CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],!=,is_true); + filter->filters[i].comparator(filter->flt_stack[nstack-1],filter->flt_stack[nstack-2],&filter->filters[i],line); } - else if ( filter->filters[i].tok_type == TOK_LIKE || filter->filters[i].tok_type == TOK_NLIKE ) + else if ( filter->flt_stack[nstack-1]->comparator ) { - if ( is_str==2 ) - { - is_true = regex_vector_strings(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1]); - if ( filter->filters[i].tok_type == TOK_NLIKE ) is_true = is_true ? 0 : 1; - } - else - error("The regex operator can be used on strings only: %s\n", filter->str); - } - else if ( is_str>0 ) - error("Wrong operator in string comparison: %s [%s,%s]\n", filter->str, filter->flt_stack[nstack-1]->str_value, filter->flt_stack[nstack-2]->str_value); - else if ( filter->filters[i].tok_type == TOK_LE ) - CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],<=,is_true) - else if ( filter->filters[i].tok_type == TOK_LT ) - CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],<,is_true) - else if ( filter->filters[i].tok_type == TOK_BT ) - CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],>,is_true) - else if ( filter->filters[i].tok_type == TOK_BE ) - CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],>=,is_true) + filter->flt_stack[nstack-1]->comparator(filter->flt_stack[nstack-1],filter->flt_stack[nstack-2],&filter->filters[i],line); + } + else if ( filter->flt_stack[nstack-2]->comparator ) + { + filter->flt_stack[nstack-2]->comparator(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],line); + } + else if ( is_str==2 ) + { + cmp_vector_strings(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i]); + } else - error("FIXME: did not expect this .. tok_type %d = %d\n", i, filter->filters[i].tok_type); + { + // Determine what to do with one [1] or both [2] sides missing. The first field [0] gives [1]|[2] + int missing_logic[] = {0,0,0}; + if ( filter->filters[i].tok_type == TOK_EQ ) { missing_logic[0] = missing_logic[2] = 1; } + if ( filter->filters[i].tok_type == TOK_NE ) { missing_logic[0] = missing_logic[1] = 1; } + + if ( filter->filters[i].tok_type == TOK_EQ ) + CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],==,missing_logic) + else if ( filter->filters[i].tok_type == TOK_NE ) + CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],!=,missing_logic) + else if ( filter->filters[i].tok_type == TOK_LE ) + CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],<=,missing_logic) + else if ( filter->filters[i].tok_type == TOK_LT ) + CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],<,missing_logic) + else if ( filter->filters[i].tok_type == TOK_BT ) + CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],>,missing_logic) + else if ( filter->filters[i].tok_type == TOK_BE ) + CMP_VECTORS(filter->flt_stack[nstack-2],filter->flt_stack[nstack-1],&filter->filters[i],>=,missing_logic) + else + error("todo: %s:%d .. type=%d\n", __FILE__,__LINE__,filter->filters[i].tok_type); - filter->flt_stack[nstack-2]->pass_site = is_true; + } + filter->flt_stack[nstack-2] = &filter->filters[i]; nstack--; } if ( nstack>1 ) error("Error occurred while processing the filter \"%s\" (2:%d)\n", filter->str,nstack); // too few values left on the stack diff --git a/bcftools/gvcf.c.pysam.c b/bcftools/gvcf.c.pysam.c index b269b21ff..8fbfe3cda 100644 --- a/bcftools/gvcf.c.pysam.c +++ b/bcftools/gvcf.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* gvcf.c -- support for gVCF files. diff --git a/bcftools/hclust.c b/bcftools/hclust.c new file mode 100644 index 000000000..692fa54a5 --- /dev/null +++ b/bcftools/hclust.c @@ -0,0 +1,400 @@ +/* The MIT License + + Copyright (c) 2016 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#include +#include +#include +#include "bcftools.h" +#include "hclust.h" + +typedef struct _node_t +{ + struct _node_t *akid, *bkid, *next, *prev, *parent; + int id, idx; // id: unique node id; idx: current index to pdist + float value; // max pairwise dist of elements within the node +} +node_t; + +struct _hclust_t +{ + int ndat, nclust; // ndat: number of elements (pdist matrix size); nclust: current number of clusters + float *pdist; // pairwise cluster distances, diagonal matrix accessed via the PDIST macro + node_t *first, *last; // clusters are maintained in a double-linked list + node_t **rmme; // convenience array to remove all allocated nodes at the end + int nrmme; + kstring_t str; // (for debugging) pointer to str.s is returned by create_dot() + char **dbg; // (for debugging) created by create_list() via set_threshold() and returned by explain() + int ndbg, mdbg; +}; + +node_t *append_node(hclust_t *clust, int idx) +{ + node_t *node = (node_t*) calloc(1,sizeof(node_t)); + + clust->nclust++; + node->id = clust->nrmme; + node->idx = idx; + if ( !clust->first ) + { + clust->first = node; + clust->last = node; + } + else + { + node->prev = clust->last; + clust->last->next = node; + clust->last = node; + } + + if ( clust->nrmme >= clust->ndat*2 ) error("hclust fixme: %d vs %d\n",clust->nrmme,clust->ndat); + clust->rmme[clust->nrmme++] = node; + + return node; +} +void remove_node(hclust_t *clust, node_t *node) +{ + if ( node==clust->first ) clust->first = node->next; + if ( node==clust->last ) clust->last = node->prev; + if ( node->next ) node->next->prev = node->prev; + if ( node->prev ) node->prev->next = node->next; + clust->nclust--; +} + +#if DEBUG +void hclust_debug(hclust_t *clust) +{ + int i; + fprintf(stderr,"nrmme=%d nclust=%d\n", clust->nrmme,clust->nclust); + for (i=0; inrmme; i++) + { + node_t *node = clust->rmme[i]; + int akid = node->akid ? node->akid->id : -1; + int bkid = node->bkid ? node->bkid->id : -1; + int akidx = node->akid ? node->akid->idx : -1; + int bkidx = node->bkid ? node->bkid->idx : -1; + fprintf(stderr,"\t%d\t%d\t%f\t%d %d\t%d %d\n",node->id,node->idx,node->value,akid,bkid,akidx,bkidx); + } + + int j; + for (i=1; indat; i++) + { + int active = 0; + node_t *node = clust->first; + while (node) + { + if ( node->idx==i ) { active=1; break; } + node = node->next; + } + fprintf(stderr,"%2d%c ",i,active?'*':' '); + for (j=0; jpdist,i,j)==9 ) + fprintf(stderr," ----- "); + else + fprintf(stderr," %f", PDIST(clust->pdist,i,j)); + } + fprintf(stderr,"\n"); + } + for (j=0; jndat-1; j++) fprintf(stderr," %6d ",j); fprintf(stderr,"\n"); +} +#endif + +hclust_t *hclust_init(int n, float *pdist) +{ + hclust_t *clust = (hclust_t*) calloc(1,sizeof(hclust_t)); + clust->ndat = n; + clust->pdist = pdist; + clust->rmme = (node_t**) calloc(n*2,sizeof(node_t*)); + + // init clusters + int i; + for (i=0; indat; i++) append_node(clust,i); + + // build the tree + while ( clust->nclust>1 ) + { + // find two clusters with minimum distance + float min_value = HUGE_VAL; + node_t *iclust = clust->first->next; + node_t *min_iclust = NULL, *min_jclust = NULL; + while ( iclust ) + { + node_t *jclust = clust->first; + while ( jclust!=iclust ) + { + float value = PDIST(clust->pdist,iclust->idx,jclust->idx); + if ( value < min_value ) + { + min_value = value; + min_iclust = iclust; + min_jclust = jclust; + } + jclust = jclust->next; + } + iclust = iclust->next; + } + assert( min_iclust && min_jclust ); // pdist contains inf or nan, fix the caller + remove_node(clust,min_iclust); + remove_node(clust,min_jclust); + + // update the pairwise distances. We keep the matrix and as we are moving up the + // tree, we use fewer columns/rows as the number of clusters decreases: we reuse + // i-th and leave j-th unused. Inter-cluster distance is defined as maximum distance + // between pairwise distances of elements within the cluster. + iclust = clust->first; + while ( iclust ) + { + if ( PDIST(clust->pdist,iclust->idx,min_iclust->idx) < PDIST(clust->pdist,iclust->idx,min_jclust->idx) ) + PDIST(clust->pdist,iclust->idx,min_iclust->idx) = PDIST(clust->pdist,iclust->idx,min_jclust->idx); + iclust = iclust->next; + } + + node_t *node = append_node(clust,min_iclust->idx); + node->akid = min_iclust; + node->bkid = min_jclust; + node->value = min_value; + node->akid->parent = node; + node->bkid->parent = node; + } + + return clust; +} +void hclust_destroy(hclust_t *clust) +{ + int i; + for (i=0; inrmme; i++) free(clust->rmme[i]); + free(clust->rmme); + free(clust->dbg); + free(clust->str.s); + free(clust); +} + +char *hclust_create_dot(hclust_t *clust, char **labels, float th) +{ + clust->str.l = 0; + ksprintf(&clust->str,"digraph myGraph {"); + + int i; + for (i=0; inrmme; i++) + { + node_t *node = clust->rmme[i]; + if ( node->value ) + ksprintf(&clust->str,"\"%d\" [label=\"%f\"];", node->id,node->value); + else + ksprintf(&clust->str,"\"%d\" [label=\"%s\"];", node->id,labels[node->idx]); + } + for (i=0; inrmme; i++) + { + node_t *node = clust->rmme[i]; + if ( node->akid ) + { + if ( node->value >= th && node->akid && node->akid->value < th ) + ksprintf(&clust->str,"\"%d\" -> \"%d\" [color=\"#D43F3A\" penwidth=3];", node->id,node->akid->id); + else + ksprintf(&clust->str,"\"%d\" -> \"%d\";", node->id,node->akid->id); + } + + if ( node->bkid ) + { + if ( node->value >= th && node->bkid && node->bkid->value < th ) + ksprintf(&clust->str,"\"%d\" -> \"%d\" [color=\"#D43F3A\" penwidth=3];", node->id,node->bkid->id); + else + ksprintf(&clust->str,"\"%d\" -> \"%d\";", node->id,node->bkid->id); + } + } + ksprintf(&clust->str,"};"); + return clust->str.s; +} +char **hclust_explain(hclust_t *clust, int *nlines) +{ + clust->ndbg = 0; + char *beg = clust->str.s; + while ( *beg ) + { + char *end = beg; + while ( *end && *end!='\n' ) end++; + clust->ndbg++; + hts_expand(char*,clust->ndbg,clust->mdbg,clust->dbg); + clust->dbg[clust->ndbg-1] = beg; + if ( !*end ) break; + *end = 0; + beg = end + 1; + } + + *nlines = clust->ndbg; + return clust->dbg; +} + +cluster_t *append_cluster(node_t *node, cluster_t *cluster, int *nclust, node_t **stack) +{ + (*nclust)++; + cluster = (cluster_t*) realloc(cluster,sizeof(cluster_t)*(*nclust)); + cluster_t *clust = &cluster[*nclust-1]; + clust->nmemb = 0; + clust->memb = NULL; + clust->dist = node->value; + + int nstack = 1; + stack[0] = node; + + while ( nstack ) + { + node_t *node = stack[--nstack]; + node_t *akid = node->akid; + node_t *bkid = node->bkid; + if ( node->akid ) + { + stack[nstack++] = akid; + stack[nstack++] = bkid; + } + else + { + clust->nmemb++; + clust->memb = (int*) realloc(clust->memb,sizeof(int)*clust->nmemb); + clust->memb[clust->nmemb-1] = node->id; + } + } + return cluster; +} + +int cmp_nodes(const void *a, const void *b) +{ + const node_t *an = *((const node_t**) a); + const node_t *bn = *((const node_t**) b); + if ( an->value < bn->value ) return -1; + if ( an->value > bn->value ) return 1; + return 0; +} + +float calc_dev(node_t **dat, int n) +{ + float avg = 0, dev = 0; + int i; + for (i=0; ivalue; + avg /= n; + for (i=0; ivalue - avg)*(dat[i]->value - avg); + return sqrt(dev/n); +} + +/* + Heuristics to determine clustering cutoff: sort nodes by distance and + split into two groups by minimizing the standard deviation. + This works best when two elements from a single different sample are + included in the mix. + - min_inter_dist .. smaller values are always considered identical + - max_intra_dist .. larger values are always considered different + */ +float hclust_set_threshold(hclust_t *clust, float min_inter_dist, float max_intra_dist) +{ + node_t **dat = clust->rmme + clust->ndat; + int i, ndat = clust->nrmme - clust->ndat; + + qsort(dat, ndat, sizeof(dat), cmp_nodes); + + clust->str.l = 0; + float th, min_dev = HUGE_VAL; + int imin = -1; + for (i=0; i0 ) dev += calc_dev(dat,i); + if ( i+1value; + ksprintf(&clust->str,"DEV\t%f\t%f\n",th,dev); + if ( min_dev > dev && th >= min_inter_dist ) { min_dev = dev; imin = i; } + } + if ( max_intra_dist > 0 ) + th = max_intra_dist; // use fixed cutoff, the above was only for debugging output + else + { + // dynamic cutoff + max_intra_dist = fabs(max_intra_dist); + th = imin==-1 ? max_intra_dist : dat[imin]->value; + if ( th > max_intra_dist ) th = max_intra_dist; + } + ksprintf(&clust->str,"TH\t%f\n", th); + ksprintf(&clust->str,"MAX_DIST\t%f\n", dat[ndat-1]->value); + ksprintf(&clust->str,"MIN_INTER\t%f\n", min_inter_dist); + ksprintf(&clust->str,"MAX_INTRA\t%f\n", max_intra_dist); + return th; +} + +cluster_t *hclust_create_list(hclust_t *clust, float min_inter_dist, float *max_intra_dist, int *nclust) +{ + float cutoff = *max_intra_dist = hclust_set_threshold(clust, min_inter_dist, *max_intra_dist); + + node_t **stack = (node_t**) malloc(sizeof(node_t*)*clust->ndat); + node_t **tmp = (node_t**) malloc(sizeof(node_t*)*clust->ndat); + stack[0] = clust->first; + int nstack = 1; + + cluster_t *cluster = NULL; + int ncluster = 0; + + if ( stack[0]->value < cutoff ) + { + // all values are within the limits - create a single cluster + cluster = append_cluster(stack[0], cluster, &ncluster, tmp); + nstack = 0; + } + + while ( nstack ) + { + node_t *node = stack[--nstack]; + node_t *akid = node->akid; + node_t *bkid = node->bkid; + if ( !akid ) + { + cluster = append_cluster(node, cluster, &ncluster, tmp); + continue; + } + + if ( node->value >= cutoff && akid->value < cutoff ) + cluster = append_cluster(akid, cluster, &ncluster, tmp); + else + stack[nstack++] = akid; + + if ( node->value >= cutoff && bkid->value < cutoff ) + cluster = append_cluster(bkid, cluster, &ncluster, tmp); + else + stack[nstack++] = bkid; + } + + free(tmp); + free(stack); + + *nclust = ncluster; + return cluster; +} + +void hclust_destroy_list(cluster_t *clust, int nclust) +{ + int i; + for (i=0; i + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#include +#include +#include +#include "bcftools.h" +#include "hclust.h" + +typedef struct _node_t +{ + struct _node_t *akid, *bkid, *next, *prev, *parent; + int id, idx; // id: unique node id; idx: current index to pdist + float value; // max pairwise dist of elements within the node +} +node_t; + +struct _hclust_t +{ + int ndat, nclust; // ndat: number of elements (pdist matrix size); nclust: current number of clusters + float *pdist; // pairwise cluster distances, diagonal matrix accessed via the PDIST macro + node_t *first, *last; // clusters are maintained in a double-linked list + node_t **rmme; // convenience array to remove all allocated nodes at the end + int nrmme; + kstring_t str; // (for debugging) pointer to str.s is returned by create_dot() + char **dbg; // (for debugging) created by create_list() via set_threshold() and returned by explain() + int ndbg, mdbg; +}; + +node_t *append_node(hclust_t *clust, int idx) +{ + node_t *node = (node_t*) calloc(1,sizeof(node_t)); + + clust->nclust++; + node->id = clust->nrmme; + node->idx = idx; + if ( !clust->first ) + { + clust->first = node; + clust->last = node; + } + else + { + node->prev = clust->last; + clust->last->next = node; + clust->last = node; + } + + if ( clust->nrmme >= clust->ndat*2 ) error("hclust fixme: %d vs %d\n",clust->nrmme,clust->ndat); + clust->rmme[clust->nrmme++] = node; + + return node; +} +void remove_node(hclust_t *clust, node_t *node) +{ + if ( node==clust->first ) clust->first = node->next; + if ( node==clust->last ) clust->last = node->prev; + if ( node->next ) node->next->prev = node->prev; + if ( node->prev ) node->prev->next = node->next; + clust->nclust--; +} + +#if DEBUG +void hclust_debug(hclust_t *clust) +{ + int i; + fprintf(bcftools_stderr,"nrmme=%d nclust=%d\n", clust->nrmme,clust->nclust); + for (i=0; inrmme; i++) + { + node_t *node = clust->rmme[i]; + int akid = node->akid ? node->akid->id : -1; + int bkid = node->bkid ? node->bkid->id : -1; + int akidx = node->akid ? node->akid->idx : -1; + int bkidx = node->bkid ? node->bkid->idx : -1; + fprintf(bcftools_stderr,"\t%d\t%d\t%f\t%d %d\t%d %d\n",node->id,node->idx,node->value,akid,bkid,akidx,bkidx); + } + + int j; + for (i=1; indat; i++) + { + int active = 0; + node_t *node = clust->first; + while (node) + { + if ( node->idx==i ) { active=1; break; } + node = node->next; + } + fprintf(bcftools_stderr,"%2d%c ",i,active?'*':' '); + for (j=0; jpdist,i,j)==9 ) + fprintf(bcftools_stderr," ----- "); + else + fprintf(bcftools_stderr," %f", PDIST(clust->pdist,i,j)); + } + fprintf(bcftools_stderr,"\n"); + } + for (j=0; jndat-1; j++) fprintf(bcftools_stderr," %6d ",j); fprintf(bcftools_stderr,"\n"); +} +#endif + +hclust_t *hclust_init(int n, float *pdist) +{ + hclust_t *clust = (hclust_t*) calloc(1,sizeof(hclust_t)); + clust->ndat = n; + clust->pdist = pdist; + clust->rmme = (node_t**) calloc(n*2,sizeof(node_t*)); + + // init clusters + int i; + for (i=0; indat; i++) append_node(clust,i); + + // build the tree + while ( clust->nclust>1 ) + { + // find two clusters with minimum distance + float min_value = HUGE_VAL; + node_t *iclust = clust->first->next; + node_t *min_iclust = NULL, *min_jclust = NULL; + while ( iclust ) + { + node_t *jclust = clust->first; + while ( jclust!=iclust ) + { + float value = PDIST(clust->pdist,iclust->idx,jclust->idx); + if ( value < min_value ) + { + min_value = value; + min_iclust = iclust; + min_jclust = jclust; + } + jclust = jclust->next; + } + iclust = iclust->next; + } + assert( min_iclust && min_jclust ); // pdist contains inf or nan, fix the caller + remove_node(clust,min_iclust); + remove_node(clust,min_jclust); + + // update the pairwise distances. We keep the matrix and as we are moving up the + // tree, we use fewer columns/rows as the number of clusters decreases: we reuse + // i-th and leave j-th unused. Inter-cluster distance is defined as maximum distance + // between pairwise distances of elements within the cluster. + iclust = clust->first; + while ( iclust ) + { + if ( PDIST(clust->pdist,iclust->idx,min_iclust->idx) < PDIST(clust->pdist,iclust->idx,min_jclust->idx) ) + PDIST(clust->pdist,iclust->idx,min_iclust->idx) = PDIST(clust->pdist,iclust->idx,min_jclust->idx); + iclust = iclust->next; + } + + node_t *node = append_node(clust,min_iclust->idx); + node->akid = min_iclust; + node->bkid = min_jclust; + node->value = min_value; + node->akid->parent = node; + node->bkid->parent = node; + } + + return clust; +} +void hclust_destroy(hclust_t *clust) +{ + int i; + for (i=0; inrmme; i++) free(clust->rmme[i]); + free(clust->rmme); + free(clust->dbg); + free(clust->str.s); + free(clust); +} + +char *hclust_create_dot(hclust_t *clust, char **labels, float th) +{ + clust->str.l = 0; + ksprintf(&clust->str,"digraph myGraph {"); + + int i; + for (i=0; inrmme; i++) + { + node_t *node = clust->rmme[i]; + if ( node->value ) + ksprintf(&clust->str,"\"%d\" [label=\"%f\"];", node->id,node->value); + else + ksprintf(&clust->str,"\"%d\" [label=\"%s\"];", node->id,labels[node->idx]); + } + for (i=0; inrmme; i++) + { + node_t *node = clust->rmme[i]; + if ( node->akid ) + { + if ( node->value >= th && node->akid && node->akid->value < th ) + ksprintf(&clust->str,"\"%d\" -> \"%d\" [color=\"#D43F3A\" penwidth=3];", node->id,node->akid->id); + else + ksprintf(&clust->str,"\"%d\" -> \"%d\";", node->id,node->akid->id); + } + + if ( node->bkid ) + { + if ( node->value >= th && node->bkid && node->bkid->value < th ) + ksprintf(&clust->str,"\"%d\" -> \"%d\" [color=\"#D43F3A\" penwidth=3];", node->id,node->bkid->id); + else + ksprintf(&clust->str,"\"%d\" -> \"%d\";", node->id,node->bkid->id); + } + } + ksprintf(&clust->str,"};"); + return clust->str.s; +} +char **hclust_explain(hclust_t *clust, int *nlines) +{ + clust->ndbg = 0; + char *beg = clust->str.s; + while ( *beg ) + { + char *end = beg; + while ( *end && *end!='\n' ) end++; + clust->ndbg++; + hts_expand(char*,clust->ndbg,clust->mdbg,clust->dbg); + clust->dbg[clust->ndbg-1] = beg; + if ( !*end ) break; + *end = 0; + beg = end + 1; + } + + *nlines = clust->ndbg; + return clust->dbg; +} + +cluster_t *append_cluster(node_t *node, cluster_t *cluster, int *nclust, node_t **stack) +{ + (*nclust)++; + cluster = (cluster_t*) realloc(cluster,sizeof(cluster_t)*(*nclust)); + cluster_t *clust = &cluster[*nclust-1]; + clust->nmemb = 0; + clust->memb = NULL; + clust->dist = node->value; + + int nstack = 1; + stack[0] = node; + + while ( nstack ) + { + node_t *node = stack[--nstack]; + node_t *akid = node->akid; + node_t *bkid = node->bkid; + if ( node->akid ) + { + stack[nstack++] = akid; + stack[nstack++] = bkid; + } + else + { + clust->nmemb++; + clust->memb = (int*) realloc(clust->memb,sizeof(int)*clust->nmemb); + clust->memb[clust->nmemb-1] = node->id; + } + } + return cluster; +} + +int cmp_nodes(const void *a, const void *b) +{ + const node_t *an = *((const node_t**) a); + const node_t *bn = *((const node_t**) b); + if ( an->value < bn->value ) return -1; + if ( an->value > bn->value ) return 1; + return 0; +} + +float calc_dev(node_t **dat, int n) +{ + float avg = 0, dev = 0; + int i; + for (i=0; ivalue; + avg /= n; + for (i=0; ivalue - avg)*(dat[i]->value - avg); + return sqrt(dev/n); +} + +/* + Heuristics to determine clustering cutoff: sort nodes by distance and + split into two groups by minimizing the standard deviation. + This works best when two elements from a single different sample are + included in the mix. + - min_inter_dist .. smaller values are always considered identical + - max_intra_dist .. larger values are always considered different + */ +float hclust_set_threshold(hclust_t *clust, float min_inter_dist, float max_intra_dist) +{ + node_t **dat = clust->rmme + clust->ndat; + int i, ndat = clust->nrmme - clust->ndat; + + qsort(dat, ndat, sizeof(dat), cmp_nodes); + + clust->str.l = 0; + float th, min_dev = HUGE_VAL; + int imin = -1; + for (i=0; i0 ) dev += calc_dev(dat,i); + if ( i+1value; + ksprintf(&clust->str,"DEV\t%f\t%f\n",th,dev); + if ( min_dev > dev && th >= min_inter_dist ) { min_dev = dev; imin = i; } + } + if ( max_intra_dist > 0 ) + th = max_intra_dist; // use fixed cutoff, the above was only for debugging output + else + { + // dynamic cutoff + max_intra_dist = fabs(max_intra_dist); + th = imin==-1 ? max_intra_dist : dat[imin]->value; + if ( th > max_intra_dist ) th = max_intra_dist; + } + ksprintf(&clust->str,"TH\t%f\n", th); + ksprintf(&clust->str,"MAX_DIST\t%f\n", dat[ndat-1]->value); + ksprintf(&clust->str,"MIN_INTER\t%f\n", min_inter_dist); + ksprintf(&clust->str,"MAX_INTRA\t%f\n", max_intra_dist); + return th; +} + +cluster_t *hclust_create_list(hclust_t *clust, float min_inter_dist, float *max_intra_dist, int *nclust) +{ + float cutoff = *max_intra_dist = hclust_set_threshold(clust, min_inter_dist, *max_intra_dist); + + node_t **stack = (node_t**) malloc(sizeof(node_t*)*clust->ndat); + node_t **tmp = (node_t**) malloc(sizeof(node_t*)*clust->ndat); + stack[0] = clust->first; + int nstack = 1; + + cluster_t *cluster = NULL; + int ncluster = 0; + + if ( stack[0]->value < cutoff ) + { + // all values are within the limits - create a single cluster + cluster = append_cluster(stack[0], cluster, &ncluster, tmp); + nstack = 0; + } + + while ( nstack ) + { + node_t *node = stack[--nstack]; + node_t *akid = node->akid; + node_t *bkid = node->bkid; + if ( !akid ) + { + cluster = append_cluster(node, cluster, &ncluster, tmp); + continue; + } + + if ( node->value >= cutoff && akid->value < cutoff ) + cluster = append_cluster(akid, cluster, &ncluster, tmp); + else + stack[nstack++] = akid; + + if ( node->value >= cutoff && bkid->value < cutoff ) + cluster = append_cluster(bkid, cluster, &ncluster, tmp); + else + stack[nstack++] = bkid; + } + + free(tmp); + free(stack); + + *nclust = ncluster; + return cluster; +} + +void hclust_destroy_list(cluster_t *clust, int nclust) +{ + int i; + for (i=0; i + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +/* + Simple hierarchical clustering +*/ + +#ifndef __HCLUST_H__ +#define __HCLUST_H__ + +#include + +typedef struct _hclust_t hclust_t; + +typedef struct +{ + float dist; + int nmemb, *memb; +} +cluster_t; + +#define PDIST(mat,a,b) (mat)[((a)>(b)?((a)*((a)-1)/2+(b)):((b)*((b)-1)/2+(a)))] + +/* + * hclust_init() - init and run clustering + * @n: number of elements + * @pdist: pairwise distances. The array will be modified by hclust and + * must exist until hclust_destroy() is called + */ +hclust_t *hclust_init(int n, float *pdist); +void hclust_destroy(hclust_t *clust); + +/* + * hclust_create_list() - returns a list of clusters + * @min_inter_dist: minimum inter-cluster distance. If smaller, elements are considered + * homogenous, belonging to the same cluster. + * @max_intra_dist: maximum intra-cluster distance allowed. If smaller than 0, + * the threshold can be heuristically lowered, otherwise considered + * a fixed cutoff. The pointer will be filled to the cutoff actually used. + */ +cluster_t *hclust_create_list(hclust_t *clust, float min_inter_dist, float *max_intra_dist, int *nclust); +void hclust_destroy_list(cluster_t *clust, int nclust); + +/* + * Access debugging data used in the decision making process. Note that this + * must be called immediately after hclust_create_list because other calls, + * such as hclust_create_dot(), invalidate the temporary data structures. + */ +char **hclust_explain(hclust_t *clust, int *nlines); + +char *hclust_create_dot(hclust_t *clust, char **labels, float th); + +#endif + diff --git a/bcftools/kheap.h b/bcftools/kheap.h new file mode 100644 index 000000000..cb5dda40c --- /dev/null +++ b/bcftools/kheap.h @@ -0,0 +1,174 @@ +/* The MIT License + + Copyright (C) 2016 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ +/* + Usage example: + + #include "kheap.h" + + // First we prepare the user data to store, in this example it is a + // struct with a single element "key", and a comparator function + // "is_smaller". In this example the comparator defines a min heap (as + // opposed to a max heap). + typedef struct + { + uint32_t key; + } + data_t; + static inline int is_smaller(data_t *a, data_t *b) + { + return a->key < b->key ? 1 : 0; + } + data_t data[3] = { {3}, {2}, {1} }; + + + // Heap declaration, "mh" is an arbitrary string. The typedef is not + // required, it is just a convenience shortcut so that we can use + // "heap_t" instead of the generic "khp_mh_t" automatically created by + // the KHEAP_INIT macro. + KHEAP_INIT(mh, data_t, is_smaller) + typedef khp_mh_t heap_t; + + // Initialize the heap, insert the test data, then retrieve them back, + // sorted. Multiple heaps with the same name "mh" can be created and + // used simultaneously, as long as they all use the same data type + // "data_t". + heap_t *heap = khp_init(mh); + + // When inserting a new element, the heap stores a copy of the memory + // area pointed to by the third argument. + for (int i=0; i<3; i++) + khp_insert(mh, heap, &data[i]); + + while (heap->ndat) + { + printf("%d\n", heap->dat[0].pos); + khp_delete(mh, heap); + } + + // Clean up + khp_destroy(mh, heap); + +*/ + +#ifndef __KHEAP_H__ +#define __KHEAP_H__ + +#include + +#ifndef kroundup32 +#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x)) +#endif + +#ifndef kh_inline +#ifdef _MSC_VER +#define kh_inline __inline +#else +#define kh_inline inline +#endif +#endif /* kh_inline */ + +#ifndef klib_unused +#if (defined __clang__ && __clang_major__ >= 3) || (defined __GNUC__ && __GNUC__ >= 3) +#define klib_unused __attribute__ ((__unused__)) +#else +#define klib_unused +#endif +#endif /* klib_unused */ + + +#define __KHEAP_TYPE(name, kheap_t) \ + typedef struct { \ + int ndat, mdat; \ + kheap_t *dat; \ + kheap_t tmp; \ + } khp_##name##_t; + +#define khp_parent(i) (((i)-1)/2) +#define khp_lchild(i) (2*(i)+1) +#define khp_rchild(i) (2*(i)+2) +#define khp_swap(hp,i,j) { \ + ((hp)->tmp) = ((hp)->dat[i]); \ + ((hp)->dat[i]) = ((hp)->dat[j]); \ + ((hp)->dat[j]) = ((hp)->tmp); \ + } + +#define __KHEAP_IMPL(name, SCOPE, kheap_t, __cmp) \ + SCOPE khp_##name##_t *khp_init_##name(void) \ + { \ + return (khp_##name##_t*)calloc(1, sizeof(khp_##name##_t)); \ + } \ + SCOPE void khp_destroy_##name(khp_##name##_t *heap) \ + { \ + if (heap) free(heap->dat); \ + free(heap); \ + } \ + SCOPE int khp_insert_##name(khp_##name##_t *heap, kheap_t *dat) \ + { \ + heap->ndat++; \ + if ( heap->ndat > heap->mdat ) \ + { \ + heap->mdat = heap->ndat; \ + kroundup32(heap->mdat); \ + heap->dat = (kheap_t*)realloc(heap->dat, heap->mdat*sizeof(kheap_t)); \ + memset(heap->dat + heap->ndat, 0, (heap->mdat - heap->ndat)*sizeof(kheap_t)); \ + } \ + int i = heap->ndat - 1; \ + while ( i && __cmp(dat,&heap->dat[khp_parent(i)]) ) \ + { \ + heap->dat[i] = heap->dat[khp_parent(i)]; \ + i = khp_parent(i); \ + } \ + heap->dat[i] = *dat; \ + return i; \ + } \ + SCOPE void khp_heapify_##name(khp_##name##_t *heap, int i) \ + { \ +/*todo: loop instead of a recursive function? */ \ + int extreme = khp_lchild(i) < heap->ndat && __cmp(&heap->dat[khp_lchild(i)],&heap->dat[i]) ? khp_lchild(i) : i; \ + if ( khp_rchild(i) < heap->ndat && __cmp(&heap->dat[khp_rchild(i)],&heap->dat[extreme]) ) extreme = khp_rchild(i); \ + if ( extreme != i ) \ + { \ + khp_swap(heap,i,extreme); \ + khp_heapify_##name(heap,extreme); \ + } \ + } \ + SCOPE void khp_delete_##name(khp_##name##_t *heap) \ + { \ + if ( !heap || !heap->ndat ) return; \ + heap->dat[0] = heap->dat[--heap->ndat]; \ + khp_heapify_##name(heap, 0); \ + } \ + +#define KHEAP_INIT(name, kheap_t, __cmp) \ + __KHEAP_TYPE(name, kheap_t) \ + __KHEAP_IMPL(name, static kh_inline klib_unused, kheap_t, __cmp) + +#define khp_init(name) khp_init_##name() +#define khp_destroy(name, heap) khp_destroy_##name(heap) +#define khp_insert(name, heap, dat) khp_insert_##name(heap, dat) +#define khp_delete(name, heap) khp_delete_##name(heap) + +#endif diff --git a/bcftools/kmin.c.pysam.c b/bcftools/kmin.c.pysam.c index ee7b51297..f0ccb98c4 100644 --- a/bcftools/kmin.c.pysam.c +++ b/bcftools/kmin.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* The MIT License diff --git a/bcftools/main.c b/bcftools/main.c index 1892c1de5..03fa6a7c1 100644 --- a/bcftools/main.c +++ b/bcftools/main.c @@ -22,6 +22,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "config.h" #include #include #include @@ -54,6 +55,9 @@ int main_polysomy(int argc, char *argv[]); #endif int main_plugin(int argc, char *argv[]); int main_consensus(int argc, char *argv[]); +int main_csq(int argc, char *argv[]); +int bam_mpileup(int argc, char *argv[]); +int main_sort(int argc, char *argv[]); typedef struct { @@ -108,7 +112,12 @@ static cmd_t cmds[] = }, { .func = main_plugin, .alias = "plugin", +#ifdef ENABLE_BCF_PLUGINS .help = "user-defined plugins" +#else + /* Do not advertise when plugins disabled. */ + .help = "-user-defined plugins" +#endif }, { .func = main_vcfquery, .alias = "query", @@ -118,6 +127,10 @@ static cmd_t cmds[] = .alias = "reheader", .help = "modify VCF/BCF header, change sample names" }, + { .func = main_sort, + .alias = "sort", + .help = "sort VCF/BCF file" + }, { .func = main_vcfview, .alias = "view", .help = "VCF/BCF conversion, view, subset and filter VCF/BCF files" @@ -140,6 +153,10 @@ static cmd_t cmds[] = .alias = "cnv", .help = "HMM CNV calling" }, + { .func = main_csq, + .alias = "csq", + .help = "call variation consequences" + }, { .func = main_vcffilter, .alias = "filter", .help = "filter VCF/BCF files using fixed thresholds" @@ -148,6 +165,10 @@ static cmd_t cmds[] = .alias = "gtcheck", .help = "check sample concordance, detect sample swaps and contamination" }, + { .func = bam_mpileup, + .alias = "mpileup", + .help = "multi-way pileup producing genotype likelihoods" + }, #if USE_GPL { .func = main_polysomy, .alias = "polysomy", diff --git a/bcftools/main.c.pysam.c b/bcftools/main.c.pysam.c index f57844272..d6b51a04c 100644 --- a/bcftools/main.c.pysam.c +++ b/bcftools/main.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* main.c -- main bcftools command front-end. @@ -24,6 +24,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "config.h" #include #include #include @@ -56,6 +57,9 @@ int main_polysomy(int argc, char *argv[]); #endif int main_plugin(int argc, char *argv[]); int main_consensus(int argc, char *argv[]); +int main_csq(int argc, char *argv[]); +int bam_mpileup(int argc, char *argv[]); +int main_sort(int argc, char *argv[]); typedef struct { @@ -110,7 +114,12 @@ static cmd_t cmds[] = }, { .func = main_plugin, .alias = "plugin", +#ifdef ENABLE_BCF_PLUGINS .help = "user-defined plugins" +#else + /* Do not advertise when plugins disabled. */ + .help = "-user-defined plugins" +#endif }, { .func = main_vcfquery, .alias = "query", @@ -120,6 +129,10 @@ static cmd_t cmds[] = .alias = "reheader", .help = "modify VCF/BCF header, change sample names" }, + { .func = main_sort, + .alias = "sort", + .help = "sort VCF/BCF file" + }, { .func = main_vcfview, .alias = "view", .help = "VCF/BCF conversion, view, subset and filter VCF/BCF files" @@ -142,6 +155,10 @@ static cmd_t cmds[] = .alias = "cnv", .help = "HMM CNV calling" }, + { .func = main_csq, + .alias = "csq", + .help = "call variation consequences" + }, { .func = main_vcffilter, .alias = "filter", .help = "filter VCF/BCF files using fixed thresholds" @@ -150,6 +167,10 @@ static cmd_t cmds[] = .alias = "gtcheck", .help = "check sample concordance, detect sample swaps and contamination" }, + { .func = bam_mpileup, + .alias = "mpileup", + .help = "multi-way pileup producing genotype likelihoods" + }, #if USE_GPL { .func = main_polysomy, .alias = "polysomy", @@ -218,24 +239,24 @@ static void usage(FILE *fp) int bcftools_main(int argc, char *argv[]) { - if (argc < 2) { usage(pysam_stderr); return 1; } + if (argc < 2) { usage(bcftools_stderr); return 1; } if (strcmp(argv[1], "version") == 0 || strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-v") == 0) { - fprintf(pysam_stdout, "bcftools %s\nUsing htslib %s\nCopyright (C) 2016 Genome Research Ltd.\n", bcftools_version(), hts_version()); + fprintf(bcftools_stdout, "bcftools %s\nUsing htslib %s\nCopyright (C) 2016 Genome Research Ltd.\n", bcftools_version(), hts_version()); #if USE_GPL - fprintf(pysam_stdout, "License GPLv3+: GNU GPL version 3 or later \n"); + fprintf(bcftools_stdout, "License GPLv3+: GNU GPL version 3 or later \n"); #else - fprintf(pysam_stdout, "License Expat: The MIT/Expat license\n"); + fprintf(bcftools_stdout, "License Expat: The MIT/Expat license\n"); #endif - fprintf(pysam_stdout, "This is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n"); + fprintf(bcftools_stdout, "This is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n"); return 0; } else if (strcmp(argv[1], "--version-only") == 0) { - fprintf(pysam_stdout, "%s+htslib-%s\n", bcftools_version(), hts_version()); + fprintf(bcftools_stdout, "%s+htslib-%s\n", bcftools_version(), hts_version()); return 0; } else if (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) { - if (argc == 2) { usage(pysam_stdout); return 0; } + if (argc == 2) { usage(bcftools_stdout); return 0; } // Otherwise change "bcftools help COMMAND [...]" to "bcftools COMMAND"; // main_xyz() functions by convention display the subcommand's usage // when invoked without any arguments. @@ -260,7 +281,7 @@ int bcftools_main(int argc, char *argv[]) } i++; } - fprintf(pysam_stderr, "[E::%s] unrecognized command '%s'\n", __func__, argv[1]); + fprintf(bcftools_stderr, "[E::%s] unrecognized command '%s'\n", __func__, argv[1]); return 1; } diff --git a/bcftools/mcall.c b/bcftools/mcall.c index 495f849a8..7f7515fda 100644 --- a/bcftools/mcall.c +++ b/bcftools/mcall.c @@ -1,6 +1,6 @@ /* mcall.c -- multiallelic and rare variant calling. - Copyright (C) 2012-2014 Genome Research Ltd. + Copyright (C) 2012-2016 Genome Research Ltd. Author: Petr Danecek @@ -107,6 +107,16 @@ int calc_Pkij(int fals, int mals, int kals, int fpl, int mpl, int kpl) // static void mcall_init_trios(call_t *call) { + if ( call->prior_AN ) + { + int id = bcf_hdr_id2int(call->hdr,BCF_DT_ID,call->prior_AN); + if ( id==-1 ) error("No such tag \"%s\"\n", call->prior_AN); + if ( !bcf_hdr_idinfo_exists(call->hdr,BCF_HL_FMT,id) ) error("No such FORMAT tag \"%s\"\n", call->prior_AN); + id = bcf_hdr_id2int(call->hdr,BCF_DT_ID,call->prior_AC); + if ( id==-1 ) error("No such tag \"%s\"\n", call->prior_AC); + if ( !bcf_hdr_idinfo_exists(call->hdr,BCF_HL_FMT,id) ) error("No such FORMAT tag \"%s\"\n", call->prior_AC); + } + // 23, 138, 478 possible diploid trio genotypes with 2, 3, 4 alleles call->ntrio[FTYPE_222][2] = 15; call->ntrio[FTYPE_222][3] = 78; call->ntrio[FTYPE_222][4] = 250; call->ntrio[FTYPE_121][2] = 8; call->ntrio[FTYPE_121][3] = 27; call->ntrio[FTYPE_121][4] = 64; @@ -347,8 +357,7 @@ void set_pdg(double *pl2p, int *PLs, double *pdg, int n_smpl, int n_gt, int unse break; } if ( PLs[j]==bcf_int32_missing ) break; - assert( PLs[j]<256 ); - pdg[j] = pl2p[ PLs[j] ]; + pdg[j] = PLs[j] < 256 ? pl2p[PLs[j]] : pow(10., -PLs[j]/10.); sum += pdg[j]; } @@ -367,8 +376,7 @@ void set_pdg(double *pl2p, int *PLs, double *pdg, int n_smpl, int n_gt, int unse { assert( PLs[j]!=bcf_int32_vector_end ); if ( PLs[j]==bcf_int32_missing ) PLs[j] = 255; - assert( PLs[j]<256 ); - pdg[j] = pl2p[ PLs[j] ]; + pdg[j] = PLs[j] < 256 ? pl2p[PLs[j]] : pow(10., -PLs[j]/10.); sum += pdg[j]; } } @@ -539,19 +547,19 @@ float calc_HOB(int nref, int nalt, int nhets, int ndiploid) /** * log(sum_i exp(a_i)) */ -static inline double logsumexp(double *vals, int nvals) -{ - int i; - double max_exp = vals[0]; - for (i=1; itheta; // the prior - UPDATE_MAX_LKs(1<0 && lk_tot_set); } // Two alleles @@ -612,14 +620,16 @@ static int mcall_find_best_alleles(call_t *call, int nals, int *out_als) int lk_tot_set = 0; double fa = call->qsum[ia]/(call->qsum[ia]+call->qsum[ib]); double fb = call->qsum[ib]/(call->qsum[ia]+call->qsum[ib]); - double fab = 2*fa*fb; fa *= fa; fb *= fb; + double fa2 = fa*fa; + double fb2 = fb*fb; + double fab = 2*fa*fb; int isample, ibb = (ib+1)*(ib+2)/2-1, iab = iaa - ia + ib; double *pdg = call->pdg; for (isample=0; isampleploidy || call->ploidy[isample]==2 ) - val = fa*pdg[iaa] + fb*pdg[ibb] + fab*pdg[iab]; + val = fa2*pdg[iaa] + fb2*pdg[ibb] + fab*pdg[iab]; else if ( call->ploidy && call->ploidy[isample]==1 ) val = fa*pdg[iaa] + fb*pdg[ibb]; if ( val ) { lk_tot += log(val); lk_tot_set = 1; } @@ -627,7 +637,7 @@ static int mcall_find_best_alleles(call_t *call, int nals, int *out_als) } if ( ia!=0 ) lk_tot += call->theta; // the prior if ( ib!=0 ) lk_tot += call->theta; - UPDATE_MAX_LKs(1<qsum[ia]/(call->qsum[ia]+call->qsum[ib]+call->qsum[ic]); double fb = call->qsum[ib]/(call->qsum[ia]+call->qsum[ib]+call->qsum[ic]); double fc = call->qsum[ic]/(call->qsum[ia]+call->qsum[ib]+call->qsum[ic]); - double fab = 2*fa*fb, fac = 2*fa*fc, fbc = 2*fb*fc; fa *= fa; fb *= fb; fc *= fc; + double fa2 = fa*fa; + double fb2 = fb*fb; + double fc2 = fc*fc; + double fab = 2*fa*fb, fac = 2*fa*fc, fbc = 2*fb*fc; int isample, icc = (ic+1)*(ic+2)/2-1; int iac = iaa - ia + ic, ibc = ibb - ib + ic; double *pdg = call->pdg; @@ -660,7 +673,7 @@ static int mcall_find_best_alleles(call_t *call, int nals, int *out_als) { double val = 0; if ( !call->ploidy || call->ploidy[isample]==2 ) - val = fa*pdg[iaa] + fb*pdg[ibb] + fc*pdg[icc] + fab*pdg[iab] + fac*pdg[iac] + fbc*pdg[ibc]; + val = fa2*pdg[iaa] + fb2*pdg[ibb] + fc2*pdg[icc] + fab*pdg[iab] + fac*pdg[iac] + fbc*pdg[ibc]; else if ( call->ploidy && call->ploidy[isample]==1 ) val = fa*pdg[iaa] + fb*pdg[ibb] + fc*pdg[icc]; if ( val ) { lk_tot += log(val); lk_tot_set = 1; } @@ -669,7 +682,7 @@ static int mcall_find_best_alleles(call_t *call, int nals, int *out_als) if ( ia!=0 ) lk_tot += call->theta; // the prior if ( ib!=0 ) lk_tot += call->theta; // the prior if ( ic!=0 ) lk_tot += call->theta; // the prior - UPDATE_MAX_LKs(1<qsum[ia]*call->qsum[ia]; + double lk = ploidy==2 ? pdg[iaa]*call->qsum[ia]*call->qsum[ia] : pdg[iaa]*call->qsum[ia]; #if USE_PRIOR_FOR_GTS if ( ia!=0 ) lk *= prior; #endif @@ -934,7 +947,7 @@ static void mcall_call_trio_genotypes(call_t *call, bcf1_t *rec, int nals, int n if ( !(out_als & 1<als_map[ia],call->als_map[ia]); - double lk = pdg[iaa]*call->qsum[ia]*call->qsum[ia]; + double lk = ploidy==2 ? pdg[iaa]*call->qsum[ia]*call->qsum[ia] : pdg[iaa]*call->qsum[ia]; sum_lk += lk; gls[idx] = lk; if ( best_lk < lk ) @@ -1184,82 +1197,80 @@ static void mcall_trim_PLs(call_t *call, bcf1_t *rec, int nals, int nout_als, in void mcall_trim_numberR(call_t *call, bcf1_t *rec, int nals, int nout_als, int out_als) { - int i, ret; + if ( nals==nout_als ) return; + + int i,j, nret, size = sizeof(float); + + void *tmp_ori = call->itmp, *tmp_new = call->PLs; // reusing PLs storage which is not used at this point + int ntmp_ori = call->n_itmp, ntmp_new = call->mPLs; - // at the moment we have DPR,AD,ADF,ADR all Number=R,Type=Integer, - // so only dealing with these cases at the moment + // INFO fields for (i=0; in_info; i++) { bcf_info_t *info = &rec->d.info[i]; int vlen = bcf_hdr_id2length(call->hdr,BCF_HL_INFO,info->key); - if ( vlen!=BCF_VL_R ) continue; - int type = bcf_hdr_id2type(call->hdr,BCF_HL_INFO,info->key); - if ( type!=BCF_HT_INT ) continue; + if ( vlen!=BCF_VL_R ) continue; // not a Number=R tag - ret = bcf_get_info_int32(call->hdr, rec, bcf_hdr_int2id(call->hdr,BCF_DT_ID,info->key), &call->itmp, &call->n_itmp); - if ( ret>0 ) + int type = bcf_hdr_id2type(call->hdr,BCF_HL_INFO,info->key); + const char *key = bcf_hdr_int2id(call->hdr,BCF_DT_ID,info->key); + nret = bcf_get_info_values(call->hdr, rec, key, &tmp_ori, &ntmp_ori, type); + if ( nret<=0 ) continue; + + if ( nout_als==1 ) + bcf_update_info_int32(call->hdr, rec, key, tmp_ori, 1); // has to be the REF, the order could not change + else { - assert( ret==nals ); - if ( out_als==1 ) - bcf_update_info_int32(call->hdr, rec, bcf_hdr_int2id(call->hdr,BCF_DT_ID,info->key), call->itmp, 1); - else + for (j=0; jals_map[j]==-1 ) continue; // to be dropped - call->PLs[ call->als_map[j] ] = call->itmp[j]; // reusing PLs storage which is not used at this point - } - bcf_update_info_int32(call->hdr, rec, bcf_hdr_int2id(call->hdr,BCF_DT_ID,info->key), call->PLs, nout_als); + int k = call->als_map[j]; + if ( k==-1 ) continue; // to be dropped + memcpy((char *)tmp_new+size*k, (char *)tmp_ori+size*j, size); } + bcf_update_info_int32(call->hdr, rec, key, tmp_new, nout_als); } } + // FORMAT fields for (i=0; in_fmt; i++) { bcf_fmt_t *fmt = &rec->d.fmt[i]; int vlen = bcf_hdr_id2length(call->hdr,BCF_HL_FMT,fmt->id); - if ( vlen!=BCF_VL_R ) continue; + if ( vlen!=BCF_VL_R ) continue; // not a Number=R tag + int type = bcf_hdr_id2type(call->hdr,BCF_HL_FMT,fmt->id); - if ( type!=BCF_HT_INT ) continue; + const char *key = bcf_hdr_int2id(call->hdr,BCF_DT_ID,fmt->id); + nret = bcf_get_format_values(call->hdr, rec, key, &tmp_ori, &ntmp_ori, type); + if (nret<=0) continue; + int nsmpl = bcf_hdr_nsamples(call->hdr); - ret = bcf_get_format_int32(call->hdr, rec, bcf_hdr_int2id(call->hdr,BCF_DT_ID,fmt->id), &call->itmp, &call->n_itmp); - if ( ret>0 ) - { - int j, nsmpl = bcf_hdr_nsamples(call->hdr); - int ndp = ret / nsmpl; - assert( ndp==nals ); - if ( out_als==1 ) - { - for (j=0; jPLs[j] = call->itmp[j*ndp]; + assert( nret==nals*nsmpl ); - bcf_update_format_int32(call->hdr, rec, bcf_hdr_int2id(call->hdr,BCF_DT_ID,fmt->id), call->PLs, nsmpl); - } - else + for (j=0; jPLs + j*nout_als; - int32_t *dp_src = call->itmp + j*ndp; - for (k=0; kals_map[k]==-1 ) continue; // to be dropped - dp_dst[ call->als_map[k] ] = dp_src[k]; // reusing PLs storage which is not used at this point - } - } - bcf_update_format_int32(call->hdr, rec, bcf_hdr_int2id(call->hdr,BCF_DT_ID,fmt->id), call->PLs, nsmpl*nout_als); + int l = call->als_map[k]; + if ( l==-1 ) continue; // to be dropped + memcpy(ptr_dst+size*l, ptr_src+size*k, size); } } + bcf_update_format_int32(call->hdr, rec, key, tmp_new, nout_als*nsmpl); } + + call->PLs = (int32_t*) tmp_new; + call->mPLs = ntmp_new; + call->itmp = (int32_t*) tmp_ori; + call->n_itmp = ntmp_ori; } // NB: in this function we temporarily use calls->als_map for a different // purpose to store mapping from new (target) alleles to original alleles. // -static void mcall_constrain_alleles(call_t *call, bcf1_t *rec, int *unseen) +static int mcall_constrain_alleles(call_t *call, bcf1_t *rec, int *unseen) { bcf_sr_regions_t *tgt = call->srs->targets; if ( tgt->nals>5 ) error("Maximum accepted number of alleles is 5, got %d\n", tgt->nals); @@ -1282,7 +1293,7 @@ static void mcall_constrain_alleles(call_t *call, bcf1_t *rec, int *unseen) call->als[nals] = tgt->als[i]; j = vcmp_find_allele(call->vcmp, rec->d.allele+1, rec->n_allele - 1, tgt->als[i]); - if ( j+1==*unseen ) error("Cannot constrain to %s\n",tgt->als[i]); + if ( j+1==*unseen ) { fprintf(stderr,"fixme? Cannot constrain to %s\n",tgt->als[i]); return -1; } if ( j>=0 ) { @@ -1308,7 +1319,7 @@ static void mcall_constrain_alleles(call_t *call, bcf1_t *rec, int *unseen) nals++; } - if ( !has_new && nals==rec->n_allele ) return; + if ( !has_new && nals==rec->n_allele ) return 0; bcf_update_alleles(call->hdr, rec, (const char**)call->als, nals); // create mapping from new PL to old PL @@ -1360,6 +1371,7 @@ static void mcall_constrain_alleles(call_t *call, bcf1_t *rec, int *unseen) bcf_update_info_float(call->hdr, rec, "QS", qsum, nals); if ( *unseen ) *unseen = nals-1; + return 0; } @@ -1374,7 +1386,7 @@ int mcall(call_t *call, bcf1_t *rec) int i, unseen = call->unseen; // Force alleles when calling genotypes given alleles was requested - if ( call->flag & CALL_CONSTR_ALLELES ) mcall_constrain_alleles(call, rec, &unseen); + if ( call->flag & CALL_CONSTR_ALLELES && mcall_constrain_alleles(call, rec, &unseen)!=0 ) return -2; int nsmpl = bcf_hdr_nsamples(call->hdr); int nals = rec->n_allele; @@ -1395,7 +1407,7 @@ int mcall(call_t *call, bcf1_t *rec) #if QS_FROM_PDG estimate_qsum(call, rec); #else - // Get sum of qualities + // Get sum of qualities, serves as an AF estimate, f_x = QS/N in Eq. 1 in call-m math notes. int nqs = bcf_get_info_float(call->hdr, rec, "QS", &call->qsum, &call->nqsum); if ( nqs<=0 ) error("The QS annotation not present at %s:%d\n", bcf_seqname(call->hdr,rec),rec->pos+1); if ( nqs < nals ) @@ -1406,23 +1418,50 @@ int mcall(call_t *call, bcf1_t *rec) hts_expand(float,nals,call->nqsum,call->qsum); for (i=nqs; iqsum[i] = 0; } - float qsum_tot = 0; - for (i=0; iqsum[i]; - if ( !call->qsum[0] ) + + // If available, take into account reference panel AFs + if ( call->prior_AN && bcf_get_info_int32(call->hdr, rec, call->prior_AN ,&call->ac, &call->nac)==1 ) { - // As P(RR)!=0 even for QS(ref)=0, we set QS(ref) to a small value, - // an equivalent of a single reference read. - if ( bcf_get_info_int32(call->hdr, rec, "DP", &call->itmp, &call->n_itmp)!=1 ) - error("Could not read DP at %s:%d\n", call->hdr->id[BCF_DT_CTG][rec->rid].key,rec->pos+1); - if ( call->itmp[0] ) + int an = call->ac[0]; + if ( bcf_get_info_int32(call->hdr, rec, call->prior_AC ,&call->ac, &call->nac)==nals-1 ) { - call->qsum[0] = 1.0 / call->itmp[0] / nsmpl; - qsum_tot += call->qsum[0]; + int ac0 = an; // number of alleles in the reference population + for (i=0; iac[i]==bcf_int32_vector_end ) break; + if ( call->ac[i]==bcf_int32_missing ) continue; + ac0 -= call->ac[i]; + call->qsum[i+1] += call->ac[i]*0.5; + } + if ( ac0<0 ) error("Incorrect %s,%s values at %s:%d\n", call->prior_AN,call->prior_AC,bcf_seqname(call->hdr,rec),rec->pos+1); + call->qsum[0] += ac0*0.5; + for (i=0; iqsum[i] /= nsmpl + 0.5*an; } } + + float qsum_tot = 0; + for (i=0; iqsum[i]; + + // Is this still necessary?? + // + // if (0&& !call->qsum[0] ) + // { + // // As P(RR)!=0 even for QS(ref)=0, we set QS(ref) to a small value, + // // an equivalent of a single reference read. + // if ( bcf_get_info_int32(call->hdr, rec, "DP", &call->itmp, &call->n_itmp)!=1 ) + // error("Could not read DP at %s:%d\n", call->hdr->id[BCF_DT_CTG][rec->rid].key,rec->pos+1); + // if ( call->itmp[0] ) + // { + // call->qsum[0] = 1.0 / call->itmp[0] / nsmpl; + // qsum_tot += call->qsum[0]; + // } + // } + if ( qsum_tot ) for (i=0; iqsum[i] /= qsum_tot; #endif + bcf_update_info_int32(call->hdr, rec, "QS", NULL, 0); // remove QS tag + // Find the best combination of alleles int out_als, nout; if ( nals > 8*sizeof(out_als) ) @@ -1497,13 +1536,17 @@ int mcall(call_t *call, bcf1_t *rec) if ( hob != HUGE_VAL ) bcf_update_info_float(call->hdr, rec, "HOB", &hob, 1); // Quality of a variant site. fabs() to avoid negative zeros in VCF output when CALL_KEEPALT is set - rec->qual = call->lk_sum==-HUGE_VAL || call->ref_lk==0 ? 0 : fabs(-4.343*(call->ref_lk - call->lk_sum)); + rec->qual = -4.343*(call->ref_lk - logsumexp2(call->lk_sum,call->ref_lk)); } else { // Set the quality of a REF site - rec->qual = call->lk_sum==-HUGE_VAL || call->ref_lk==0 ? 0 : -4.343*log(1 - exp(call->ref_lk - call->lk_sum)); + if ( call->lk_sum==-HUGE_VAL ) // no support from (high quality) reads, so QUAL=1-prior + rec->qual = call->theta ? -4.343*call->theta : 0; + else + rec->qual = -4.343*(call->lk_sum - logsumexp2(call->lk_sum,call->ref_lk)); } + if ( rec->qual>999 ) rec->qual = 999; if ( rec->qual>50 ) rec->qual = rint(rec->qual); @@ -1530,7 +1573,6 @@ int mcall(call_t *call, bcf1_t *rec) } bcf_update_info_int32(call->hdr, rec, "I16", NULL, 0); // remove I16 tag - bcf_update_info_int32(call->hdr, rec, "QS", NULL, 0); // remove QS tag return nout; } diff --git a/bcftools/mcall.c.pysam.c b/bcftools/mcall.c.pysam.c index 29ed79976..f05bed22f 100644 --- a/bcftools/mcall.c.pysam.c +++ b/bcftools/mcall.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* mcall.c -- multiallelic and rare variant calling. - Copyright (C) 2012-2014 Genome Research Ltd. + Copyright (C) 2012-2016 Genome Research Ltd. Author: Petr Danecek @@ -109,6 +109,16 @@ int calc_Pkij(int fals, int mals, int kals, int fpl, int mpl, int kpl) // static void mcall_init_trios(call_t *call) { + if ( call->prior_AN ) + { + int id = bcf_hdr_id2int(call->hdr,BCF_DT_ID,call->prior_AN); + if ( id==-1 ) error("No such tag \"%s\"\n", call->prior_AN); + if ( !bcf_hdr_idinfo_exists(call->hdr,BCF_HL_FMT,id) ) error("No such FORMAT tag \"%s\"\n", call->prior_AN); + id = bcf_hdr_id2int(call->hdr,BCF_DT_ID,call->prior_AC); + if ( id==-1 ) error("No such tag \"%s\"\n", call->prior_AC); + if ( !bcf_hdr_idinfo_exists(call->hdr,BCF_HL_FMT,id) ) error("No such FORMAT tag \"%s\"\n", call->prior_AC); + } + // 23, 138, 478 possible diploid trio genotypes with 2, 3, 4 alleles call->ntrio[FTYPE_222][2] = 15; call->ntrio[FTYPE_222][3] = 78; call->ntrio[FTYPE_222][4] = 250; call->ntrio[FTYPE_121][2] = 8; call->ntrio[FTYPE_121][3] = 27; call->ntrio[FTYPE_121][4] = 64; @@ -288,7 +298,7 @@ void mcall_init(call_t *call) call->theta *= aM; if ( call->theta >= 1 ) { - fprintf(pysam_stderr,"The prior is too big (theta*aM=%.2f), going with 0.99\n", call->theta); + fprintf(bcftools_stderr,"The prior is too big (theta*aM=%.2f), going with 0.99\n", call->theta); call->theta = 0.99; } call->theta = log(call->theta); @@ -349,8 +359,7 @@ void set_pdg(double *pl2p, int *PLs, double *pdg, int n_smpl, int n_gt, int unse break; } if ( PLs[j]==bcf_int32_missing ) break; - assert( PLs[j]<256 ); - pdg[j] = pl2p[ PLs[j] ]; + pdg[j] = PLs[j] < 256 ? pl2p[PLs[j]] : pow(10., -PLs[j]/10.); sum += pdg[j]; } @@ -369,8 +378,7 @@ void set_pdg(double *pl2p, int *PLs, double *pdg, int n_smpl, int n_gt, int unse { assert( PLs[j]!=bcf_int32_vector_end ); if ( PLs[j]==bcf_int32_missing ) PLs[j] = 255; - assert( PLs[j]<256 ); - pdg[j] = pl2p[ PLs[j] ]; + pdg[j] = PLs[j] < 256 ? pl2p[PLs[j]] : pow(10., -PLs[j]/10.); sum += pdg[j]; } } @@ -516,13 +524,13 @@ float calc_ICB(int nref, int nalt, int nhets, int ndiploid) double q = 2*fref*falt; // probability of a het, assuming HWE double mean = q*ndiploid; - //fprintf(pysam_stderr,"\np=%e N=%d k=%d .. nref=%d nalt=%d nhets=%d ndiploid=%d\n", q,ndiploid,nhets, nref,nalt,nhets,ndiploid); + //fprintf(bcftools_stderr,"\np=%e N=%d k=%d .. nref=%d nalt=%d nhets=%d ndiploid=%d\n", q,ndiploid,nhets, nref,nalt,nhets,ndiploid); // Can we use normal approximation? The second condition is for performance only // and is not well justified. if ( (mean>10 && (1-q)*ndiploid>10 ) || ndiploid>200 ) { - //fprintf(pysam_stderr,"out: mean=%e p=%e\n", mean,exp(-0.5*(nhets-mean)*(nhets-mean)/(mean*(1-q)))); + //fprintf(bcftools_stderr,"out: mean=%e p=%e\n", mean,exp(-0.5*(nhets-mean)*(nhets-mean)/(mean*(1-q)))); return exp(-0.5*(nhets-mean)*(nhets-mean)/(mean*(1-q))); } @@ -541,19 +549,19 @@ float calc_HOB(int nref, int nalt, int nhets, int ndiploid) /** * log(sum_i exp(a_i)) */ -static inline double logsumexp(double *vals, int nvals) -{ - int i; - double max_exp = vals[0]; - for (i=1; itheta; // the prior - UPDATE_MAX_LKs(1<0 && lk_tot_set); } // Two alleles @@ -614,14 +622,16 @@ static int mcall_find_best_alleles(call_t *call, int nals, int *out_als) int lk_tot_set = 0; double fa = call->qsum[ia]/(call->qsum[ia]+call->qsum[ib]); double fb = call->qsum[ib]/(call->qsum[ia]+call->qsum[ib]); - double fab = 2*fa*fb; fa *= fa; fb *= fb; + double fa2 = fa*fa; + double fb2 = fb*fb; + double fab = 2*fa*fb; int isample, ibb = (ib+1)*(ib+2)/2-1, iab = iaa - ia + ib; double *pdg = call->pdg; for (isample=0; isampleploidy || call->ploidy[isample]==2 ) - val = fa*pdg[iaa] + fb*pdg[ibb] + fab*pdg[iab]; + val = fa2*pdg[iaa] + fb2*pdg[ibb] + fab*pdg[iab]; else if ( call->ploidy && call->ploidy[isample]==1 ) val = fa*pdg[iaa] + fb*pdg[ibb]; if ( val ) { lk_tot += log(val); lk_tot_set = 1; } @@ -629,7 +639,7 @@ static int mcall_find_best_alleles(call_t *call, int nals, int *out_als) } if ( ia!=0 ) lk_tot += call->theta; // the prior if ( ib!=0 ) lk_tot += call->theta; - UPDATE_MAX_LKs(1<qsum[ia]/(call->qsum[ia]+call->qsum[ib]+call->qsum[ic]); double fb = call->qsum[ib]/(call->qsum[ia]+call->qsum[ib]+call->qsum[ic]); double fc = call->qsum[ic]/(call->qsum[ia]+call->qsum[ib]+call->qsum[ic]); - double fab = 2*fa*fb, fac = 2*fa*fc, fbc = 2*fb*fc; fa *= fa; fb *= fb; fc *= fc; + double fa2 = fa*fa; + double fb2 = fb*fb; + double fc2 = fc*fc; + double fab = 2*fa*fb, fac = 2*fa*fc, fbc = 2*fb*fc; int isample, icc = (ic+1)*(ic+2)/2-1; int iac = iaa - ia + ic, ibc = ibb - ib + ic; double *pdg = call->pdg; @@ -662,7 +675,7 @@ static int mcall_find_best_alleles(call_t *call, int nals, int *out_als) { double val = 0; if ( !call->ploidy || call->ploidy[isample]==2 ) - val = fa*pdg[iaa] + fb*pdg[ibb] + fc*pdg[icc] + fab*pdg[iab] + fac*pdg[iac] + fbc*pdg[ibc]; + val = fa2*pdg[iaa] + fb2*pdg[ibb] + fc2*pdg[icc] + fab*pdg[iab] + fac*pdg[iac] + fbc*pdg[ibc]; else if ( call->ploidy && call->ploidy[isample]==1 ) val = fa*pdg[iaa] + fb*pdg[ibb] + fc*pdg[icc]; if ( val ) { lk_tot += log(val); lk_tot_set = 1; } @@ -671,7 +684,7 @@ static int mcall_find_best_alleles(call_t *call, int nals, int *out_als) if ( ia!=0 ) lk_tot += call->theta; // the prior if ( ib!=0 ) lk_tot += call->theta; // the prior if ( ic!=0 ) lk_tot += call->theta; // the prior - UPDATE_MAX_LKs(1<qsum[ia]*call->qsum[ia]; + double lk = ploidy==2 ? pdg[iaa]*call->qsum[ia]*call->qsum[ia] : pdg[iaa]*call->qsum[ia]; #if USE_PRIOR_FOR_GTS if ( ia!=0 ) lk *= prior; #endif @@ -936,7 +949,7 @@ static void mcall_call_trio_genotypes(call_t *call, bcf1_t *rec, int nals, int n if ( !(out_als & 1<als_map[ia],call->als_map[ia]); - double lk = pdg[iaa]*call->qsum[ia]*call->qsum[ia]; + double lk = ploidy==2 ? pdg[iaa]*call->qsum[ia]*call->qsum[ia] : pdg[iaa]*call->qsum[ia]; sum_lk += lk; gls[idx] = lk; if ( best_lk < lk ) @@ -1032,12 +1045,12 @@ static void mcall_call_trio_genotypes(call_t *call, bcf1_t *rec, int nals, int n if ( igt==GT_SKIP ) continue; lk += gl[igt]; npresent++; - // fprintf(pysam_stderr," %e", gl[igt]); + // fprintf(bcftools_stderr," %e", gl[igt]); } - // fprintf(pysam_stderr,"\t\t"); + // fprintf(bcftools_stderr,"\t\t"); double Pkij = npresent==3 ? (double)2/(trio[itr]>>12) : 1; // with missing genotypes Pkij's are different lk += log(1 - trio_Pm * (1 - Pkij)); - // fprintf(pysam_stderr,"%d%d%d\t%e\t%.2f\n", trio[itr]>>8&0xf,trio[itr]>>4&0xf,trio[itr]&0xf, lk, Pkij); + // fprintf(bcftools_stderr,"%d%d%d\t%e\t%.2f\n", trio[itr]>>8&0xf,trio[itr]>>4&0xf,trio[itr]&0xf, lk, Pkij); if ( c_lk < lk ) { c_lk = lk; c_itr = trio[itr]; } if ( uc_itr==trio[itr] ) uc_is_mendelian = 1; } @@ -1045,10 +1058,10 @@ static void mcall_call_trio_genotypes(call_t *call, bcf1_t *rec, int nals, int n if ( !uc_is_mendelian ) { uc_lk += log(1 - trio_Pm); - // fprintf(pysam_stderr,"c_lk=%e uc_lk=%e c_itr=%d%d%d uc_itr=%d%d%d\n", c_lk,uc_lk,c_itr>>8&0xf,c_itr>>4&0xf,c_itr&0xf,uc_itr>>8&0xf,uc_itr>>4&0xf,uc_itr&0xf); + // fprintf(bcftools_stderr,"c_lk=%e uc_lk=%e c_itr=%d%d%d uc_itr=%d%d%d\n", c_lk,uc_lk,c_itr>>8&0xf,c_itr>>4&0xf,c_itr&0xf,uc_itr>>8&0xf,uc_itr>>4&0xf,uc_itr&0xf); if ( c_lk < uc_lk ) { c_lk = uc_lk; c_itr = uc_itr; } } - // fprintf(pysam_stderr,"best_lk=%e best_itr=%d%d%d uc_itr=%d%d%d\n", c_lk,c_itr>>8&0xf,c_itr>>4&0xf,c_itr&0xf,uc_itr>>8&0xf,uc_itr>>4&0xf,uc_itr&0xf); + // fprintf(bcftools_stderr,"best_lk=%e best_itr=%d%d%d uc_itr=%d%d%d\n", c_lk,c_itr>>8&0xf,c_itr>>4&0xf,c_itr&0xf,uc_itr>>8&0xf,uc_itr>>4&0xf,uc_itr&0xf); // Set genotypes for father, mother, child and calculate genotype qualities for (i=0; i<3; i++) @@ -1186,82 +1199,80 @@ static void mcall_trim_PLs(call_t *call, bcf1_t *rec, int nals, int nout_als, in void mcall_trim_numberR(call_t *call, bcf1_t *rec, int nals, int nout_als, int out_als) { - int i, ret; + if ( nals==nout_als ) return; + + int i,j, nret, size = sizeof(float); + + void *tmp_ori = call->itmp, *tmp_new = call->PLs; // reusing PLs storage which is not used at this point + int ntmp_ori = call->n_itmp, ntmp_new = call->mPLs; - // at the moment we have DPR,AD,ADF,ADR all Number=R,Type=Integer, - // so only dealing with these cases at the moment + // INFO fields for (i=0; in_info; i++) { bcf_info_t *info = &rec->d.info[i]; int vlen = bcf_hdr_id2length(call->hdr,BCF_HL_INFO,info->key); - if ( vlen!=BCF_VL_R ) continue; - int type = bcf_hdr_id2type(call->hdr,BCF_HL_INFO,info->key); - if ( type!=BCF_HT_INT ) continue; + if ( vlen!=BCF_VL_R ) continue; // not a Number=R tag - ret = bcf_get_info_int32(call->hdr, rec, bcf_hdr_int2id(call->hdr,BCF_DT_ID,info->key), &call->itmp, &call->n_itmp); - if ( ret>0 ) + int type = bcf_hdr_id2type(call->hdr,BCF_HL_INFO,info->key); + const char *key = bcf_hdr_int2id(call->hdr,BCF_DT_ID,info->key); + nret = bcf_get_info_values(call->hdr, rec, key, &tmp_ori, &ntmp_ori, type); + if ( nret<=0 ) continue; + + if ( nout_als==1 ) + bcf_update_info_int32(call->hdr, rec, key, tmp_ori, 1); // has to be the REF, the order could not change + else { - assert( ret==nals ); - if ( out_als==1 ) - bcf_update_info_int32(call->hdr, rec, bcf_hdr_int2id(call->hdr,BCF_DT_ID,info->key), call->itmp, 1); - else + for (j=0; jals_map[j]==-1 ) continue; // to be dropped - call->PLs[ call->als_map[j] ] = call->itmp[j]; // reusing PLs storage which is not used at this point - } - bcf_update_info_int32(call->hdr, rec, bcf_hdr_int2id(call->hdr,BCF_DT_ID,info->key), call->PLs, nout_als); + int k = call->als_map[j]; + if ( k==-1 ) continue; // to be dropped + memcpy((char *)tmp_new+size*k, (char *)tmp_ori+size*j, size); } + bcf_update_info_int32(call->hdr, rec, key, tmp_new, nout_als); } } + // FORMAT fields for (i=0; in_fmt; i++) { bcf_fmt_t *fmt = &rec->d.fmt[i]; int vlen = bcf_hdr_id2length(call->hdr,BCF_HL_FMT,fmt->id); - if ( vlen!=BCF_VL_R ) continue; + if ( vlen!=BCF_VL_R ) continue; // not a Number=R tag + int type = bcf_hdr_id2type(call->hdr,BCF_HL_FMT,fmt->id); - if ( type!=BCF_HT_INT ) continue; + const char *key = bcf_hdr_int2id(call->hdr,BCF_DT_ID,fmt->id); + nret = bcf_get_format_values(call->hdr, rec, key, &tmp_ori, &ntmp_ori, type); + if (nret<=0) continue; + int nsmpl = bcf_hdr_nsamples(call->hdr); - ret = bcf_get_format_int32(call->hdr, rec, bcf_hdr_int2id(call->hdr,BCF_DT_ID,fmt->id), &call->itmp, &call->n_itmp); - if ( ret>0 ) - { - int j, nsmpl = bcf_hdr_nsamples(call->hdr); - int ndp = ret / nsmpl; - assert( ndp==nals ); - if ( out_als==1 ) - { - for (j=0; jPLs[j] = call->itmp[j*ndp]; + assert( nret==nals*nsmpl ); - bcf_update_format_int32(call->hdr, rec, bcf_hdr_int2id(call->hdr,BCF_DT_ID,fmt->id), call->PLs, nsmpl); - } - else + for (j=0; jPLs + j*nout_als; - int32_t *dp_src = call->itmp + j*ndp; - for (k=0; kals_map[k]==-1 ) continue; // to be dropped - dp_dst[ call->als_map[k] ] = dp_src[k]; // reusing PLs storage which is not used at this point - } - } - bcf_update_format_int32(call->hdr, rec, bcf_hdr_int2id(call->hdr,BCF_DT_ID,fmt->id), call->PLs, nsmpl*nout_als); + int l = call->als_map[k]; + if ( l==-1 ) continue; // to be dropped + memcpy(ptr_dst+size*l, ptr_src+size*k, size); } } + bcf_update_format_int32(call->hdr, rec, key, tmp_new, nout_als*nsmpl); } + + call->PLs = (int32_t*) tmp_new; + call->mPLs = ntmp_new; + call->itmp = (int32_t*) tmp_ori; + call->n_itmp = ntmp_ori; } // NB: in this function we temporarily use calls->als_map for a different // purpose to store mapping from new (target) alleles to original alleles. // -static void mcall_constrain_alleles(call_t *call, bcf1_t *rec, int *unseen) +static int mcall_constrain_alleles(call_t *call, bcf1_t *rec, int *unseen) { bcf_sr_regions_t *tgt = call->srs->targets; if ( tgt->nals>5 ) error("Maximum accepted number of alleles is 5, got %d\n", tgt->nals); @@ -1284,7 +1295,7 @@ static void mcall_constrain_alleles(call_t *call, bcf1_t *rec, int *unseen) call->als[nals] = tgt->als[i]; j = vcmp_find_allele(call->vcmp, rec->d.allele+1, rec->n_allele - 1, tgt->als[i]); - if ( j+1==*unseen ) error("Cannot constrain to %s\n",tgt->als[i]); + if ( j+1==*unseen ) { fprintf(bcftools_stderr,"fixme? Cannot constrain to %s\n",tgt->als[i]); return -1; } if ( j>=0 ) { @@ -1310,7 +1321,7 @@ static void mcall_constrain_alleles(call_t *call, bcf1_t *rec, int *unseen) nals++; } - if ( !has_new && nals==rec->n_allele ) return; + if ( !has_new && nals==rec->n_allele ) return 0; bcf_update_alleles(call->hdr, rec, (const char**)call->als, nals); // create mapping from new PL to old PL @@ -1362,6 +1373,7 @@ static void mcall_constrain_alleles(call_t *call, bcf1_t *rec, int *unseen) bcf_update_info_float(call->hdr, rec, "QS", qsum, nals); if ( *unseen ) *unseen = nals-1; + return 0; } @@ -1376,7 +1388,7 @@ int mcall(call_t *call, bcf1_t *rec) int i, unseen = call->unseen; // Force alleles when calling genotypes given alleles was requested - if ( call->flag & CALL_CONSTR_ALLELES ) mcall_constrain_alleles(call, rec, &unseen); + if ( call->flag & CALL_CONSTR_ALLELES && mcall_constrain_alleles(call, rec, &unseen)!=0 ) return -2; int nsmpl = bcf_hdr_nsamples(call->hdr); int nals = rec->n_allele; @@ -1397,7 +1409,7 @@ int mcall(call_t *call, bcf1_t *rec) #if QS_FROM_PDG estimate_qsum(call, rec); #else - // Get sum of qualities + // Get sum of qualities, serves as an AF estimate, f_x = QS/N in Eq. 1 in call-m math notes. int nqs = bcf_get_info_float(call->hdr, rec, "QS", &call->qsum, &call->nqsum); if ( nqs<=0 ) error("The QS annotation not present at %s:%d\n", bcf_seqname(call->hdr,rec),rec->pos+1); if ( nqs < nals ) @@ -1408,28 +1420,55 @@ int mcall(call_t *call, bcf1_t *rec) hts_expand(float,nals,call->nqsum,call->qsum); for (i=nqs; iqsum[i] = 0; } - float qsum_tot = 0; - for (i=0; iqsum[i]; - if ( !call->qsum[0] ) + + // If available, take into account reference panel AFs + if ( call->prior_AN && bcf_get_info_int32(call->hdr, rec, call->prior_AN ,&call->ac, &call->nac)==1 ) { - // As P(RR)!=0 even for QS(ref)=0, we set QS(ref) to a small value, - // an equivalent of a single reference read. - if ( bcf_get_info_int32(call->hdr, rec, "DP", &call->itmp, &call->n_itmp)!=1 ) - error("Could not read DP at %s:%d\n", call->hdr->id[BCF_DT_CTG][rec->rid].key,rec->pos+1); - if ( call->itmp[0] ) + int an = call->ac[0]; + if ( bcf_get_info_int32(call->hdr, rec, call->prior_AC ,&call->ac, &call->nac)==nals-1 ) { - call->qsum[0] = 1.0 / call->itmp[0] / nsmpl; - qsum_tot += call->qsum[0]; + int ac0 = an; // number of alleles in the reference population + for (i=0; iac[i]==bcf_int32_vector_end ) break; + if ( call->ac[i]==bcf_int32_missing ) continue; + ac0 -= call->ac[i]; + call->qsum[i+1] += call->ac[i]*0.5; + } + if ( ac0<0 ) error("Incorrect %s,%s values at %s:%d\n", call->prior_AN,call->prior_AC,bcf_seqname(call->hdr,rec),rec->pos+1); + call->qsum[0] += ac0*0.5; + for (i=0; iqsum[i] /= nsmpl + 0.5*an; } } + + float qsum_tot = 0; + for (i=0; iqsum[i]; + + // Is this still necessary?? + // + // if (0&& !call->qsum[0] ) + // { + // // As P(RR)!=0 even for QS(ref)=0, we set QS(ref) to a small value, + // // an equivalent of a single reference read. + // if ( bcf_get_info_int32(call->hdr, rec, "DP", &call->itmp, &call->n_itmp)!=1 ) + // error("Could not read DP at %s:%d\n", call->hdr->id[BCF_DT_CTG][rec->rid].key,rec->pos+1); + // if ( call->itmp[0] ) + // { + // call->qsum[0] = 1.0 / call->itmp[0] / nsmpl; + // qsum_tot += call->qsum[0]; + // } + // } + if ( qsum_tot ) for (i=0; iqsum[i] /= qsum_tot; #endif + bcf_update_info_int32(call->hdr, rec, "QS", NULL, 0); // remove QS tag + // Find the best combination of alleles int out_als, nout; if ( nals > 8*sizeof(out_als) ) { - fprintf(pysam_stderr,"Too many alleles at %s:%d, skipping.\n", bcf_seqname(call->hdr,rec),rec->pos+1); + fprintf(bcftools_stderr,"Too many alleles at %s:%d, skipping.\n", bcf_seqname(call->hdr,rec),rec->pos+1); return 0; } nout = mcall_find_best_alleles(call, nals, &out_als); @@ -1473,7 +1512,7 @@ int mcall(call_t *call, bcf1_t *rec) { if ( nout>4 ) { - fprintf(pysam_stderr,"Too many alleles at %s:%d, skipping.\n", bcf_seqname(call->hdr,rec),rec->pos+1); + fprintf(bcftools_stderr,"Too many alleles at %s:%d, skipping.\n", bcf_seqname(call->hdr,rec),rec->pos+1); return 0; } mcall_call_trio_genotypes(call, rec, nals,nout,out_als); @@ -1499,13 +1538,17 @@ int mcall(call_t *call, bcf1_t *rec) if ( hob != HUGE_VAL ) bcf_update_info_float(call->hdr, rec, "HOB", &hob, 1); // Quality of a variant site. fabs() to avoid negative zeros in VCF output when CALL_KEEPALT is set - rec->qual = call->lk_sum==-HUGE_VAL || call->ref_lk==0 ? 0 : fabs(-4.343*(call->ref_lk - call->lk_sum)); + rec->qual = -4.343*(call->ref_lk - logsumexp2(call->lk_sum,call->ref_lk)); } else { // Set the quality of a REF site - rec->qual = call->lk_sum==-HUGE_VAL || call->ref_lk==0 ? 0 : -4.343*log(1 - exp(call->ref_lk - call->lk_sum)); + if ( call->lk_sum==-HUGE_VAL ) // no support from (high quality) reads, so QUAL=1-prior + rec->qual = call->theta ? -4.343*call->theta : 0; + else + rec->qual = -4.343*(call->lk_sum - logsumexp2(call->lk_sum,call->ref_lk)); } + if ( rec->qual>999 ) rec->qual = 999; if ( rec->qual>50 ) rec->qual = rint(rec->qual); @@ -1532,7 +1575,6 @@ int mcall(call_t *call, bcf1_t *rec) } bcf_update_info_int32(call->hdr, rec, "I16", NULL, 0); // remove I16 tag - bcf_update_info_int32(call->hdr, rec, "QS", NULL, 0); // remove QS tag return nout; } diff --git a/bcftools/mpileup.c b/bcftools/mpileup.c new file mode 100644 index 000000000..9b6c6ebb6 --- /dev/null +++ b/bcftools/mpileup.c @@ -0,0 +1,1107 @@ +/* mpileup.c -- mpileup subcommand. Previously bam_plcmd.c from samtools + + Copyright (C) 2008-2017 Genome Research Ltd. + Portions copyright (C) 2009-2012 Broad Institute. + + Author: Heng Li + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "regidx.h" +#include "bcftools.h" +#include "bam2bcf.h" +#include "bam_sample.h" +#include "gvcf.h" + +#define MPLP_BCF 1 +#define MPLP_VCF (1<<1) +#define MPLP_NO_COMP (1<<2) +#define MPLP_NO_ORPHAN (1<<3) +#define MPLP_REALN (1<<4) +#define MPLP_NO_INDEL (1<<5) +#define MPLP_REDO_BAQ (1<<6) +#define MPLP_ILLUMINA13 (1<<7) +#define MPLP_IGNORE_RG (1<<8) +#define MPLP_PRINT_POS (1<<9) +#define MPLP_PRINT_MAPQ (1<<10) +#define MPLP_PER_SAMPLE (1<<11) +#define MPLP_SMART_OVERLAPS (1<<12) + +typedef struct _mplp_aux_t mplp_aux_t; +typedef struct _mplp_pileup_t mplp_pileup_t; + +// Data shared by all bam files +typedef struct { + int min_mq, flag, min_baseQ, capQ_thres, max_depth, max_indel_depth, fmt_flag; + int rflag_require, rflag_filter, output_type; + int openQ, extQ, tandemQ, min_support; // for indels + double min_frac; // for indels + char *reg_fname, *pl_list, *fai_fname, *output_fname; + int reg_is_file, record_cmd_line, n_threads; + faidx_t *fai; + regidx_t *bed, *reg; // bed: skipping regions, reg: index-jump to regions + regitr_t *bed_itr, *reg_itr; + int bed_logic; // 1: include region, 0: exclude region + gvcf_t *gvcf; + + // auxiliary structures for calling + bcf_callaux_t *bca; + bcf_callret1_t *bcr; + bcf_call_t bc; + bam_mplp_t iter; + mplp_aux_t **mplp_data; + int nfiles; + char **files; + mplp_pileup_t *gplp; + int *n_plp; + const bam_pileup1_t **plp; + bam_smpl_t *bsmpl; + kstring_t buf; + bcf1_t *bcf_rec; + htsFile *bcf_fp; + bcf_hdr_t *bcf_hdr; + int argc; + char **argv; +} mplp_conf_t; + +typedef struct { + char *ref[2]; + int ref_id[2]; + int ref_len[2]; +} mplp_ref_t; + +#define MPLP_REF_INIT {{NULL,NULL},{-1,-1},{0,0}} + +// Data specific to each bam file +struct _mplp_aux_t { + samFile *fp; + hts_itr_t *iter; + bam_hdr_t *h; + mplp_ref_t *ref; + const mplp_conf_t *conf; + int bam_id; + hts_idx_t *idx; // maintained only with more than one -r regions +}; + +// Data passed to htslib/mpileup +struct _mplp_pileup_t { + int n; + int *n_plp, *m_plp; + bam_pileup1_t **plp; +}; + +static int mplp_get_ref(mplp_aux_t *ma, int tid, char **ref, int *ref_len) { + mplp_ref_t *r = ma->ref; + + //printf("get ref %d {%d/%p, %d/%p}\n", tid, r->ref_id[0], r->ref[0], r->ref_id[1], r->ref[1]); + + if (!r || !ma->conf->fai) { + *ref = NULL; + return 0; + } + + // Do we need to reference count this so multiple mplp_aux_t can + // track which references are in use? + // For now we just cache the last two. Sufficient? + if (tid == r->ref_id[0]) { + *ref = r->ref[0]; + *ref_len = r->ref_len[0]; + return 1; + } + if (tid == r->ref_id[1]) { + // Last, swap over + int tmp; + tmp = r->ref_id[0]; r->ref_id[0] = r->ref_id[1]; r->ref_id[1] = tmp; + tmp = r->ref_len[0]; r->ref_len[0] = r->ref_len[1]; r->ref_len[1] = tmp; + + char *tc; + tc = r->ref[0]; r->ref[0] = r->ref[1]; r->ref[1] = tc; + *ref = r->ref[0]; + *ref_len = r->ref_len[0]; + return 1; + } + + // New, so migrate to old and load new + free(r->ref[1]); + r->ref[1] = r->ref[0]; + r->ref_id[1] = r->ref_id[0]; + r->ref_len[1] = r->ref_len[0]; + + r->ref_id[0] = tid; + r->ref[0] = faidx_fetch_seq(ma->conf->fai, + ma->h->target_name[r->ref_id[0]], + 0, + INT_MAX, + &r->ref_len[0]); + + if (!r->ref[0]) { + r->ref[0] = NULL; + r->ref_id[0] = -1; + r->ref_len[0] = 0; + *ref = NULL; + return 0; + } + + *ref = r->ref[0]; + *ref_len = r->ref_len[0]; + return 1; +} + +static int mplp_func(void *data, bam1_t *b) +{ + char *ref; + mplp_aux_t *ma = (mplp_aux_t*)data; + int ret, ref_len; + while (1) + { + int has_ref; + ret = ma->iter? sam_itr_next(ma->fp, ma->iter, b) : sam_read1(ma->fp, ma->h, b); + if (ret < 0) break; + // The 'B' cigar operation is not part of the specification, considering as obsolete. + // bam_remove_B(b); + if (b->core.tid < 0 || (b->core.flag&BAM_FUNMAP)) continue; // exclude unmapped reads + if (ma->conf->rflag_require && !(ma->conf->rflag_require&b->core.flag)) continue; + if (ma->conf->rflag_filter && ma->conf->rflag_filter&b->core.flag) continue; + if (ma->conf->bed) + { + // test overlap + regitr_t *itr = ma->conf->bed_itr; + int beg = b->core.pos, end = bam_endpos(b)-1; + int overlap = regidx_overlap(ma->conf->bed, ma->h->target_name[b->core.tid],beg,end, itr); + if ( !ma->conf->bed_logic && !overlap ) + { + // exclude only reads which are fully contained in the region + while ( regitr_overlap(itr) ) + { + if ( beg < itr->beg ) { overlap = 1; break; } + if ( end > itr->end ) { overlap = 1; break; } + } + } + if ( !overlap ) continue; + } + if ( bam_smpl_get_sample_id(ma->conf->bsmpl,ma->bam_id,b)<0 ) continue; + if (ma->conf->flag & MPLP_ILLUMINA13) { + int i; + uint8_t *qual = bam_get_qual(b); + for (i = 0; i < b->core.l_qseq; ++i) + qual[i] = qual[i] > 31? qual[i] - 31 : 0; + } + + if (ma->conf->fai && b->core.tid >= 0) { + has_ref = mplp_get_ref(ma, b->core.tid, &ref, &ref_len); + if (has_ref && ref_len <= b->core.pos) { // exclude reads outside of the reference sequence + fprintf(stderr,"[%s] Skipping because %d is outside of %d [ref:%d]\n", + __func__, b->core.pos, ref_len, b->core.tid); + continue; + } + } else { + has_ref = 0; + } + + if (has_ref && (ma->conf->flag&MPLP_REALN)) sam_prob_realn(b, ref, ref_len, (ma->conf->flag & MPLP_REDO_BAQ)? 7 : 3); + if (has_ref && ma->conf->capQ_thres > 10) { + int q = sam_cap_mapq(b, ref, ref_len, ma->conf->capQ_thres); + if (q < 0) continue; // skip + else if (b->core.qual > q) b->core.qual = q; + } + if (b->core.qual < ma->conf->min_mq) continue; + else if ((ma->conf->flag&MPLP_NO_ORPHAN) && (b->core.flag&BAM_FPAIRED) && !(b->core.flag&BAM_FPROPER_PAIR)) continue; + + return ret; + }; + return ret; +} + +// Called once per new bam added to the pileup. +// We cache sample information here so we don't have to keep recomputing this +// on each and every pileup column. +// +// Cd is an arbitrary block of data we can write into, which ends up in +// the pileup structures. We stash the sample ID there. +static int pileup_constructor(void *data, const bam1_t *b, bam_pileup_cd *cd) { + mplp_aux_t *ma = (mplp_aux_t *)data; + cd->i = bam_smpl_get_sample_id(ma->conf->bsmpl, ma->bam_id, (bam1_t *)b); + return 0; +} + +static void group_smpl(mplp_pileup_t *m, bam_smpl_t *bsmpl, int n, int *n_plp, const bam_pileup1_t **plp) +{ + int i, j; + memset(m->n_plp, 0, m->n * sizeof(int)); + for (i = 0; i < n; ++i) // iterate over all bams + { + for (j = 0; j < n_plp[i]; ++j) // iterate over all reads available at this position + { + const bam_pileup1_t *p = plp[i] + j; + int id = p->cd.i; + if (m->n_plp[id] == m->m_plp[id]) + { + m->m_plp[id] = m->m_plp[id]? m->m_plp[id]<<1 : 8; + m->plp[id] = (bam_pileup1_t*) realloc(m->plp[id], sizeof(bam_pileup1_t) * m->m_plp[id]); + } + m->plp[id][m->n_plp[id]++] = *p; + } + } +} + +static void flush_bcf_records(mplp_conf_t *conf, htsFile *fp, bcf_hdr_t *hdr, bcf1_t *rec) +{ + if ( !conf->gvcf ) + { + if ( rec ) bcf_write1(fp, hdr, rec); + return; + } + + if ( !rec ) + { + gvcf_write(conf->gvcf, fp, hdr, NULL, 0); + return; + } + + int is_ref = 0; + if ( rec->n_allele==1 ) is_ref = 1; + else if ( rec->n_allele==2 ) + { + // second allele is mpileup's X, not a variant + if ( rec->d.allele[1][0]=='<' && rec->d.allele[1][1]=='*' && rec->d.allele[1][2]=='>' ) is_ref = 1; + } + rec = gvcf_write(conf->gvcf, fp, hdr, rec, is_ref); + if ( rec ) bcf_write1(fp,hdr,rec); +} + +static int mpileup_reg(mplp_conf_t *conf, uint32_t beg, uint32_t end) +{ + bam_hdr_t *hdr = conf->mplp_data[0]->h; // header of first file in input list + + int ret, i, tid, pos, ref_len; + char *ref; + + while ( (ret=bam_mplp_auto(conf->iter, &tid, &pos, conf->n_plp, conf->plp)) > 0) + { + if ( end && (posend) ) continue; + if ( conf->bed && tid >= 0 ) + { + int overlap = regidx_overlap(conf->bed, hdr->target_name[tid], pos, pos, NULL); + if ( !conf->bed_logic ) overlap = overlap ? 0 : 1; + if ( !overlap ) continue; + } + mplp_get_ref(conf->mplp_data[0], tid, &ref, &ref_len); + + int total_depth, _ref0, ref16; + for (i = total_depth = 0; i < conf->nfiles; ++i) total_depth += conf->n_plp[i]; + group_smpl(conf->gplp, conf->bsmpl, conf->nfiles, conf->n_plp, conf->plp); + _ref0 = (ref && pos < ref_len)? ref[pos] : 'N'; + ref16 = seq_nt16_table[_ref0]; + bcf_callaux_clean(conf->bca, &conf->bc); + for (i = 0; i < conf->gplp->n; ++i) + bcf_call_glfgen(conf->gplp->n_plp[i], conf->gplp->plp[i], ref16, conf->bca, conf->bcr + i); + conf->bc.tid = tid; conf->bc.pos = pos; + bcf_call_combine(conf->gplp->n, conf->bcr, conf->bca, ref16, &conf->bc); + bcf_clear1(conf->bcf_rec); + bcf_call2bcf(&conf->bc, conf->bcf_rec, conf->bcr, conf->fmt_flag, 0, 0); + flush_bcf_records(conf, conf->bcf_fp, conf->bcf_hdr, conf->bcf_rec); + + // call indels; todo: subsampling with total_depth>max_indel_depth instead of ignoring? + // check me: rghash in bcf_call_gap_prep() should have no effect, reads mplp_func already excludes them + if (!(conf->flag&MPLP_NO_INDEL) && total_depth < conf->max_indel_depth + && bcf_call_gap_prep(conf->gplp->n, conf->gplp->n_plp, conf->gplp->plp, pos, conf->bca, ref) >= 0) + { + bcf_callaux_clean(conf->bca, &conf->bc); + for (i = 0; i < conf->gplp->n; ++i) + bcf_call_glfgen(conf->gplp->n_plp[i], conf->gplp->plp[i], -1, conf->bca, conf->bcr + i); + if (bcf_call_combine(conf->gplp->n, conf->bcr, conf->bca, -1, &conf->bc) >= 0) + { + bcf_clear1(conf->bcf_rec); + bcf_call2bcf(&conf->bc, conf->bcf_rec, conf->bcr, conf->fmt_flag, conf->bca, ref); + flush_bcf_records(conf, conf->bcf_fp, conf->bcf_hdr, conf->bcf_rec); + } + } + } + return 0; +} + +static int mpileup(mplp_conf_t *conf) +{ + if (conf->nfiles == 0) { + fprintf(stderr,"[%s] no input file/data given\n", __func__); + exit(EXIT_FAILURE); + } + + mplp_ref_t mp_ref = MPLP_REF_INIT; + conf->gplp = (mplp_pileup_t *) calloc(1,sizeof(mplp_pileup_t)); + conf->mplp_data = (mplp_aux_t**) calloc(conf->nfiles, sizeof(mplp_aux_t*)); + conf->plp = (const bam_pileup1_t**) calloc(conf->nfiles, sizeof(bam_pileup1_t*)); + conf->n_plp = (int*) calloc(conf->nfiles, sizeof(int)); + + // Allow to run mpileup on multiple regions in one go. This comes at cost: the bai index + // must be kept in the memory for the whole time which can be a problem with many bams. + // Therefore if none or only one region is requested, we initialize the bam iterator as + // before and free the index. Only when multiple regions are queried, we keep the index. + int nregs = 0; + if ( conf->reg_fname ) + { + if ( conf->reg_is_file ) + { + conf->reg = regidx_init(conf->reg_fname,NULL,NULL,0,NULL); + if ( !conf->reg ) { + fprintf(stderr,"Could not parse the regions: %s\n", conf->reg_fname); + exit(EXIT_FAILURE); + } + } + else + { + conf->reg = regidx_init(NULL,regidx_parse_reg,NULL,sizeof(char*),NULL); + if ( regidx_insert_list(conf->reg,conf->reg_fname,',') !=0 ) { + fprintf(stderr,"Could not parse the regions: %s\n", conf->reg_fname); + exit(EXIT_FAILURE); + } + } + nregs = regidx_nregs(conf->reg); + conf->reg_itr = regitr_init(conf->reg); + regitr_loop(conf->reg_itr); // region iterator now positioned at the first region + } + + // read the header of each file in the list and initialize data + // beware: mpileup has always assumed that tid's are consistent in the headers, add sanity check at least! + bam_hdr_t *hdr = NULL; // header of first file in input list + int i; + for (i = 0; i < conf->nfiles; ++i) { + bam_hdr_t *h_tmp; + conf->mplp_data[i] = (mplp_aux_t*) calloc(1, sizeof(mplp_aux_t)); + conf->mplp_data[i]->fp = sam_open(conf->files[i], "rb"); + if ( !conf->mplp_data[i]->fp ) + { + fprintf(stderr, "[%s] failed to open %s: %s\n", __func__, conf->files[i], strerror(errno)); + exit(EXIT_FAILURE); + } + if (hts_set_opt(conf->mplp_data[i]->fp, CRAM_OPT_DECODE_MD, 0)) { + fprintf(stderr, "Failed to set CRAM_OPT_DECODE_MD value\n"); + exit(EXIT_FAILURE); + } + if (conf->fai_fname && hts_set_fai_filename(conf->mplp_data[i]->fp, conf->fai_fname) != 0) { + fprintf(stderr, "[%s] failed to process %s: %s\n", + __func__, conf->fai_fname, strerror(errno)); + exit(EXIT_FAILURE); + } + conf->mplp_data[i]->conf = conf; + conf->mplp_data[i]->ref = &mp_ref; + h_tmp = sam_hdr_read(conf->mplp_data[i]->fp); + if ( !h_tmp ) { + fprintf(stderr,"[%s] fail to read the header of %s\n", __func__, conf->files[i]); + exit(EXIT_FAILURE); + } + conf->mplp_data[i]->h = i ? hdr : h_tmp; // for j==0, "h" has not been set yet + conf->mplp_data[i]->bam_id = bam_smpl_add_bam(conf->bsmpl,h_tmp->text,conf->files[i]); + if ( conf->mplp_data[i]->bam_id<0 ) + { + // no usable readgroups in this bam, it can be skipped + sam_close(conf->mplp_data[i]->fp); + free(conf->mplp_data[i]); + bam_hdr_destroy(h_tmp); + free(conf->files[i]); + if ( i+1nfiles ) memmove(&conf->files[i],&conf->files[i+1],sizeof(*conf->files)*(conf->nfiles-i-1)); + conf->nfiles--; + i--; + continue; + } + if (conf->reg) { + hts_idx_t *idx = sam_index_load(conf->mplp_data[i]->fp, conf->files[i]); + if (idx == NULL) { + fprintf(stderr, "[%s] fail to load index for %s\n", __func__, conf->files[i]); + exit(EXIT_FAILURE); + } + conf->buf.l = 0; + ksprintf(&conf->buf,"%s:%u-%u",conf->reg_itr->seq,conf->reg_itr->beg+1,conf->reg_itr->end+1); + conf->mplp_data[i]->iter = sam_itr_querys(idx, conf->mplp_data[i]->h, conf->buf.s); + if ( !conf->mplp_data[i]->iter ) + { + conf->mplp_data[i]->iter = sam_itr_querys(idx, conf->mplp_data[i]->h, conf->reg_itr->seq); + if ( conf->mplp_data[i]->iter ) { + fprintf(stderr,"[E::%s] fail to parse region '%s'\n", __func__, conf->buf.s); + exit(EXIT_FAILURE); + } + fprintf(stderr,"[E::%s] the sequence \"%s\" not found: %s\n",__func__,conf->reg_itr->seq,conf->files[i]); + exit(EXIT_FAILURE); + } + if ( nregs==1 ) // no need to keep the index in memory + hts_idx_destroy(idx); + else + conf->mplp_data[i]->idx = idx; + } + + if ( !hdr ) hdr = h_tmp; /* save the header of first file in list */ + else { + // FIXME: check consistency between h and h_tmp + bam_hdr_destroy(h_tmp); + + // we store only the first file's header; it's (alleged to be) + // compatible with the i-th file's target_name lookup needs + conf->mplp_data[i]->h = hdr; + } + } + // allocate data storage proportionate to number of samples being studied sm->n + bam_smpl_get_samples(conf->bsmpl, &conf->gplp->n); + conf->gplp->n_plp = (int*) calloc(conf->gplp->n, sizeof(int)); + conf->gplp->m_plp = (int*) calloc(conf->gplp->n, sizeof(int)); + conf->gplp->plp = (bam_pileup1_t**) calloc(conf->gplp->n, sizeof(bam_pileup1_t*)); + + fprintf(stderr, "[%s] %d samples in %d input files\n", __func__, conf->gplp->n, conf->nfiles); + // write the VCF header + conf->bcf_fp = hts_open(conf->output_fname?conf->output_fname:"-", hts_bcf_wmode(conf->output_type)); + if (conf->bcf_fp == NULL) { + fprintf(stderr, "[%s] failed to write to %s: %s\n", __func__, conf->output_fname? conf->output_fname : "standard output", strerror(errno)); + exit(EXIT_FAILURE); + } + if ( conf->n_threads ) hts_set_threads(conf->bcf_fp, conf->n_threads); + + // BCF header creation + conf->bcf_hdr = bcf_hdr_init("w"); + conf->buf.l = 0; + + if (conf->record_cmd_line) + { + ksprintf(&conf->buf, "##bcftoolsVersion=%s+htslib-%s\n",bcftools_version(),hts_version()); + bcf_hdr_append(conf->bcf_hdr, conf->buf.s); + + conf->buf.l = 0; + ksprintf(&conf->buf, "##bcftoolsCommand=mpileup"); + for (i=1; iargc; i++) ksprintf(&conf->buf, " %s", conf->argv[i]); + kputc('\n', &conf->buf); + bcf_hdr_append(conf->bcf_hdr, conf->buf.s); + } + + if (conf->fai_fname) + { + conf->buf.l = 0; + ksprintf(&conf->buf, "##reference=file://%s\n", conf->fai_fname); + bcf_hdr_append(conf->bcf_hdr, conf->buf.s); + } + + // Translate BAM @SQ tags to BCF ##contig tags + // todo: use/write new BAM header manipulation routines, fill also UR, M5 + for (i=0; in_targets; i++) + { + conf->buf.l = 0; + ksprintf(&conf->buf, "##contig=", hdr->target_name[i], hdr->target_len[i]); + bcf_hdr_append(conf->bcf_hdr, conf->buf.s); + } + conf->buf.l = 0; + + bcf_hdr_append(conf->bcf_hdr,"##ALT="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); +#if CDF_MWU_TESTS + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); +#endif + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_DP ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_DV ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_DPR ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_INFO_DPR ) + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + if ( conf->fmt_flag&B2B_FMT_DP4 ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_SP ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_AD ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_ADF ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_ADR ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_INFO_AD ) + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + if ( conf->fmt_flag&B2B_INFO_ADF ) + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + if ( conf->fmt_flag&B2B_INFO_ADR ) + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + if ( conf->gvcf ) + gvcf_update_header(conf->gvcf, conf->bcf_hdr); + + int nsmpl; + const char **smpl = bam_smpl_get_samples(conf->bsmpl, &nsmpl); + for (i=0; ibcf_hdr, smpl[i]); + bcf_hdr_write(conf->bcf_fp, conf->bcf_hdr); + + conf->bca = bcf_call_init(-1., conf->min_baseQ); + conf->bcr = (bcf_callret1_t*) calloc(nsmpl, sizeof(bcf_callret1_t)); + conf->bca->openQ = conf->openQ, conf->bca->extQ = conf->extQ, conf->bca->tandemQ = conf->tandemQ; + conf->bca->min_frac = conf->min_frac; + conf->bca->min_support = conf->min_support; + conf->bca->per_sample_flt = conf->flag & MPLP_PER_SAMPLE; + + conf->bc.bcf_hdr = conf->bcf_hdr; + conf->bc.n = nsmpl; + conf->bc.PL = (int32_t*) malloc(15 * nsmpl * sizeof(*conf->bc.PL)); + if (conf->fmt_flag) + { + assert( sizeof(float)==sizeof(int32_t) ); + conf->bc.DP4 = (int32_t*) malloc(nsmpl * sizeof(int32_t) * 4); + conf->bc.fmt_arr = (uint8_t*) malloc(nsmpl * sizeof(float)); // all fmt_flag fields, float and int32 + if ( conf->fmt_flag&(B2B_INFO_DPR|B2B_FMT_DPR|B2B_INFO_AD|B2B_INFO_ADF|B2B_INFO_ADR|B2B_FMT_AD|B2B_FMT_ADF|B2B_FMT_ADR) ) + { + // first B2B_MAX_ALLELES fields for total numbers, the rest per-sample + conf->bc.ADR = (int32_t*) malloc((nsmpl+1)*B2B_MAX_ALLELES*sizeof(int32_t)); + conf->bc.ADF = (int32_t*) malloc((nsmpl+1)*B2B_MAX_ALLELES*sizeof(int32_t)); + for (i=0; ibcr[i].ADR = conf->bc.ADR + (i+1)*B2B_MAX_ALLELES; + conf->bcr[i].ADF = conf->bc.ADF + (i+1)*B2B_MAX_ALLELES; + } + } + } + + // init mpileup + conf->iter = bam_mplp_init(conf->nfiles, mplp_func, (void**)conf->mplp_data); + if ( conf->flag & MPLP_SMART_OVERLAPS ) bam_mplp_init_overlaps(conf->iter); + if ( (double)conf->max_depth * conf->nfiles > 1<<20) + fprintf(stderr, "Warning: Potential memory hog, up to %.0fM reads in the pileup!\n", (double)conf->max_depth*conf->nfiles); + if ( (double)conf->max_depth * conf->nfiles / nsmpl < 250 ) + fprintf(stderr, "Note: The maximum per-sample depth with -d %d is %.1fx\n", conf->max_depth,(double)conf->max_depth * conf->nfiles / nsmpl); + bam_mplp_set_maxcnt(conf->iter, conf->max_depth); + conf->max_indel_depth = conf->max_indel_depth * nsmpl; + conf->bcf_rec = bcf_init1(); + bam_mplp_constructor(conf->iter, pileup_constructor); + + // Run mpileup for multiple regions + if ( nregs ) + { + int ireg = 0; + do + { + // first region is already positioned + if ( ireg++ > 0 ) + { + conf->buf.l = 0; + ksprintf(&conf->buf,"%s:%u-%u",conf->reg_itr->seq,conf->reg_itr->beg,conf->reg_itr->end); + + for (i=0; infiles; i++) + { + hts_itr_destroy(conf->mplp_data[i]->iter); + conf->mplp_data[i]->iter = sam_itr_querys(conf->mplp_data[i]->idx, conf->mplp_data[i]->h, conf->buf.s); + if ( !conf->mplp_data[i]->iter ) + { + conf->mplp_data[i]->iter = sam_itr_querys(conf->mplp_data[i]->idx, conf->mplp_data[i]->h, conf->reg_itr->seq); + if ( conf->mplp_data[i]->iter ) { + fprintf(stderr,"[E::%s] fail to parse region '%s'\n", __func__, conf->buf.s); + exit(EXIT_FAILURE); + } + fprintf(stderr,"[E::%s] the sequence \"%s\" not found: %s\n",__func__,conf->reg_itr->seq,conf->files[i]); + exit(EXIT_FAILURE); + } + bam_mplp_reset(conf->iter); + } + } + mpileup_reg(conf,conf->reg_itr->beg,conf->reg_itr->end); + } + while ( regitr_loop(conf->reg_itr) ); + } + else + mpileup_reg(conf,0,0); + + flush_bcf_records(conf, conf->bcf_fp, conf->bcf_hdr, NULL); + + // clean up + free(conf->bc.tmp.s); + bcf_destroy1(conf->bcf_rec); + if (conf->bcf_fp) + { + hts_close(conf->bcf_fp); + bcf_hdr_destroy(conf->bcf_hdr); + bcf_call_destroy(conf->bca); + free(conf->bc.PL); + free(conf->bc.DP4); + free(conf->bc.ADR); + free(conf->bc.ADF); + free(conf->bc.fmt_arr); + free(conf->bcr); + } + if ( conf->gvcf ) gvcf_destroy(conf->gvcf); + free(conf->buf.s); + for (i = 0; i < conf->gplp->n; ++i) free(conf->gplp->plp[i]); + free(conf->gplp->plp); free(conf->gplp->n_plp); free(conf->gplp->m_plp); free(conf->gplp); + bam_mplp_destroy(conf->iter); + bam_hdr_destroy(hdr); + for (i = 0; i < conf->nfiles; ++i) { + if ( nregs>1 ) hts_idx_destroy(conf->mplp_data[i]->idx); + sam_close(conf->mplp_data[i]->fp); + if ( conf->mplp_data[i]->iter) hts_itr_destroy(conf->mplp_data[i]->iter); + free(conf->mplp_data[i]); + } + if ( conf->reg_itr ) regitr_destroy(conf->reg_itr); + free(conf->mplp_data); free(conf->plp); free(conf->n_plp); + free(mp_ref.ref[0]); + free(mp_ref.ref[1]); + return 0; +} + +static int is_url(const char *s) +{ + static const char uri_scheme_chars[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+.-"; + return s[strspn(s, uri_scheme_chars)] == ':'; +} + +#define MAX_PATH_LEN 1024 +int read_file_list(const char *file_list,int *n,char **argv[]) +{ + char buf[MAX_PATH_LEN]; + int len, nfiles = 0; + char **files = NULL; + struct stat sb; + + *n = 0; + *argv = NULL; + + FILE *fh = fopen(file_list,"r"); + if ( !fh ) + { + fprintf(stderr,"%s: %s\n", file_list,strerror(errno)); + return 1; + } + + files = (char**) calloc(nfiles,sizeof(char*)); + nfiles = 0; + while ( fgets(buf,MAX_PATH_LEN,fh) ) + { + // allow empty lines and trailing spaces + len = strlen(buf); + while ( len>0 && isspace(buf[len-1]) ) len--; + if ( !len ) continue; + + // check sanity of the file list + buf[len] = 0; + if (! (is_url(buf) || stat(buf, &sb) == 0)) + { + // no such file, check if it is safe to print its name + int i, safe_to_print = 1; + for (i=0; irflag_require); + char *tmp_filter = bam_flag2str(mplp->rflag_filter); + + // Display usage information, formatted for the standard 80 columns. + // (The unusual string formatting here aids the readability of this + // source code in 80 columns, to the extent that's possible.) + + fprintf(fp, +"\n" +"Usage: bcftools mpileup [options] in1.bam [in2.bam [...]]\n" +"\n" +"Input options:\n" +" -6, --illumina1.3+ quality is in the Illumina-1.3+ encoding\n" +" -A, --count-orphans do not discard anomalous read pairs\n" +" -b, --bam-list FILE list of input BAM filenames, one per line\n" +" -B, --no-BAQ disable BAQ (per-Base Alignment Quality)\n" +" -C, --adjust-MQ INT adjust mapping quality; recommended:50, disable:0 [0]\n" +" -d, --max-depth INT max per-file depth; avoids excessive memory usage [%d]\n", mplp->max_depth); + fprintf(fp, +" -E, --redo-BAQ recalculate BAQ on the fly, ignore existing BQs\n" +" -f, --fasta-ref FILE faidx indexed reference sequence file\n" +" --no-reference do not require fasta reference file\n" +" -G, --read-groups FILE select or exclude read groups listed in the file\n" +" -q, --min-MQ INT skip alignments with mapQ smaller than INT [%d]\n", mplp->min_mq); + fprintf(fp, +" -Q, --min-BQ INT skip bases with baseQ/BAQ smaller than INT [%d]\n", mplp->min_baseQ); + fprintf(fp, +" -r, --regions REG[,...] comma separated list of regions in which pileup is generated\n" +" -R, --regions-file FILE restrict to regions listed in a file\n" +" --ignore-RG ignore RG tags (one BAM = one sample)\n" +" --rf, --incl-flags STR|INT required flags: skip reads with mask bits unset [%s]\n", tmp_require); + fprintf(fp, +" --ff, --excl-flags STR|INT filter flags: skip reads with mask bits set\n" +" [%s]\n", tmp_filter); + fprintf(fp, +" -s, --samples LIST comma separated list of samples to include\n" +" -S, --samples-file FILE file of samples to include\n" +" -t, --targets REG[,...] similar to -r but streams rather than index-jumps\n" +" -T, --targets-file FILE similar to -R but streams rather than index-jumps\n" +" -x, --ignore-overlaps disable read-pair overlap detection\n" +"\n" +"Output options:\n" +" -a, --annotate LIST optional tags to output; '?' to list []\n" +" -g, --gvcf INT[,...] group non-variant sites into gVCF blocks according\n" +" to minimum per-sample DP\n" +" --no-version do not append version and command line to the header\n" +" -o, --output FILE write output to FILE [standard output]\n" +" -O, --output-type TYPE 'b' compressed BCF; 'u' uncompressed BCF;\n" +" 'z' compressed VCF; 'v' uncompressed VCF [v]\n" +" --threads INT number of extra output compression threads [0]\n" +"\n" +"SNP/INDEL genotype likelihoods options:\n" +" -e, --ext-prob INT Phred-scaled gap extension seq error probability [%d]\n", mplp->extQ); + fprintf(fp, +" -F, --gap-frac FLOAT minimum fraction of gapped reads [%g]\n", mplp->min_frac); + fprintf(fp, +" -h, --tandem-qual INT coefficient for homopolymer errors [%d]\n", mplp->tandemQ); + fprintf(fp, +" -I, --skip-indels do not perform indel calling\n" +" -L, --max-idepth INT maximum per-file depth for INDEL calling [%d]\n", mplp->max_indel_depth); + fprintf(fp, +" -m, --min-ireads INT minimum number gapped reads for indel candidates [%d]\n", mplp->min_support); + fprintf(fp, +" -o, --open-prob INT Phred-scaled gap open seq error probability [%d]\n", mplp->openQ); + fprintf(fp, +" -p, --per-sample-mF apply -m and -F per-sample for increased sensitivity\n" +" -P, --platforms STR comma separated list of platforms for indels [all]\n" +"\n" +"Notes: Assuming diploid individuals.\n" +"\n"); + + free(tmp_require); + free(tmp_filter); +} + +int bam_mpileup(int argc, char *argv[]) +{ + int c; + const char *file_list = NULL; + char **fn = NULL; + int nfiles = 0, use_orphan = 0, noref = 0; + mplp_conf_t mplp; + memset(&mplp, 0, sizeof(mplp_conf_t)); + mplp.min_baseQ = 13; + mplp.capQ_thres = 0; + mplp.max_depth = 250; mplp.max_indel_depth = 250; + mplp.openQ = 40; mplp.extQ = 20; mplp.tandemQ = 100; + mplp.min_frac = 0.002; mplp.min_support = 1; + mplp.flag = MPLP_NO_ORPHAN | MPLP_REALN | MPLP_SMART_OVERLAPS; + mplp.argc = argc; mplp.argv = argv; + mplp.rflag_filter = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP; + mplp.output_fname = NULL; + mplp.output_type = FT_VCF; + mplp.record_cmd_line = 1; + mplp.n_threads = 0; + mplp.bsmpl = bam_smpl_init(); + + static const struct option lopts[] = + { + {"rf", required_argument, NULL, 1}, // require flag + {"ff", required_argument, NULL, 2}, // filter flag + {"incl-flags", required_argument, NULL, 1}, + {"excl-flags", required_argument, NULL, 2}, + {"output", required_argument, NULL, 3}, + {"open-prob", required_argument, NULL, 4}, + {"ignore-RG", no_argument, NULL, 5}, + {"ignore-rg", no_argument, NULL, 5}, + {"gvcf", required_argument, NULL, 'g'}, + {"no-reference", no_argument, NULL, 7}, + {"no-version", no_argument, NULL, 8}, + {"threads",required_argument,NULL,9}, + {"illumina1.3+", no_argument, NULL, '6'}, + {"count-orphans", no_argument, NULL, 'A'}, + {"bam-list", required_argument, NULL, 'b'}, + {"no-BAQ", no_argument, NULL, 'B'}, + {"no-baq", no_argument, NULL, 'B'}, + {"adjust-MQ", required_argument, NULL, 'C'}, + {"adjust-mq", required_argument, NULL, 'C'}, + {"max-depth", required_argument, NULL, 'd'}, + {"redo-BAQ", no_argument, NULL, 'E'}, + {"redo-baq", no_argument, NULL, 'E'}, + {"fasta-ref", required_argument, NULL, 'f'}, + {"read-groups", required_argument, NULL, 'G'}, + {"region", required_argument, NULL, 'r'}, + {"regions", required_argument, NULL, 'r'}, + {"regions-file", required_argument, NULL, 'R'}, + {"targets", required_argument, NULL, 't'}, + {"targets-file", required_argument, NULL, 'T'}, + {"min-MQ", required_argument, NULL, 'q'}, + {"min-mq", required_argument, NULL, 'q'}, + {"min-BQ", required_argument, NULL, 'Q'}, + {"min-bq", required_argument, NULL, 'Q'}, + {"ignore-overlaps", no_argument, NULL, 'x'}, + {"output-type", required_argument, NULL, 'O'}, + {"samples", required_argument, NULL, 's'}, + {"samples-file", required_argument, NULL, 'S'}, + {"annotate", required_argument, NULL, 'a'}, + {"ext-prob", required_argument, NULL, 'e'}, + {"gap-frac", required_argument, NULL, 'F'}, + {"tandem-qual", required_argument, NULL, 'h'}, + {"skip-indels", no_argument, NULL, 'I'}, + {"max-idepth", required_argument, NULL, 'L'}, + {"min-ireads ", required_argument, NULL, 'm'}, + {"per-sample-mF", no_argument, NULL, 'p'}, + {"per-sample-mf", no_argument, NULL, 'p'}, + {"platforms", required_argument, NULL, 'P'}, + {NULL, 0, NULL, 0} + }; + while ((c = getopt_long(argc, argv, "Ag:f:r:R:q:Q:C:Bd:L:b:P:po:e:h:Im:F:EG:6O:xa:s:S:t:T:",lopts,NULL)) >= 0) { + switch (c) { + case 'x': mplp.flag &= ~MPLP_SMART_OVERLAPS; break; + case 1 : + mplp.rflag_require = bam_str2flag(optarg); + if ( mplp.rflag_require<0 ) { fprintf(stderr,"Could not parse --rf %s\n", optarg); return 1; } + break; + case 2 : + mplp.rflag_filter = bam_str2flag(optarg); + if ( mplp.rflag_filter<0 ) { fprintf(stderr,"Could not parse --ff %s\n", optarg); return 1; } + break; + case 3 : mplp.output_fname = optarg; break; + case 4 : mplp.openQ = atoi(optarg); break; + case 5 : bam_smpl_ignore_readgroups(mplp.bsmpl); break; + case 'g': + mplp.gvcf = gvcf_init(optarg); + if ( !mplp.gvcf ) error("Could not parse: --gvcf %s\n", optarg); + break; + case 'f': + mplp.fai = fai_load(optarg); + if (mplp.fai == NULL) return 1; + mplp.fai_fname = optarg; + break; + case 7 : noref = 1; break; + case 8 : mplp.record_cmd_line = 0; break; + case 9 : mplp.n_threads = strtol(optarg, 0, 0); break; + case 'd': mplp.max_depth = atoi(optarg); break; + case 'r': mplp.reg_fname = strdup(optarg); break; + case 'R': mplp.reg_fname = strdup(optarg); mplp.reg_is_file = 1; break; + case 't': + // In the original version the whole BAM was streamed which is inefficient + // with few BED intervals and big BAMs. Todo: devise a heuristic to determine + // best strategy, that is streaming or jumping. + if ( optarg[0]=='^' ) optarg++; + else mplp.bed_logic = 1; + mplp.bed = regidx_init(NULL,regidx_parse_reg,NULL,0,NULL); + mplp.bed_itr = regitr_init(mplp.bed); + if ( regidx_insert_list(mplp.bed,optarg,',') !=0 ) + { + fprintf(stderr,"Could not parse the targets: %s\n", optarg); + exit(EXIT_FAILURE); + } + break; + case 'T': + if ( optarg[0]=='^' ) optarg++; + else mplp.bed_logic = 1; + mplp.bed = regidx_init(optarg,NULL,NULL,0,NULL); + if (!mplp.bed) { fprintf(stderr, "bcftools mpileup: Could not read file \"%s\"", optarg); return 1; } + break; + case 'P': mplp.pl_list = strdup(optarg); break; + case 'p': mplp.flag |= MPLP_PER_SAMPLE; break; + case 'B': mplp.flag &= ~MPLP_REALN; break; + case 'I': mplp.flag |= MPLP_NO_INDEL; break; + case 'E': mplp.flag |= MPLP_REDO_BAQ; break; + case '6': mplp.flag |= MPLP_ILLUMINA13; break; + case 's': if ( bam_smpl_add_samples(mplp.bsmpl,optarg,0)<0 ) error("Could not read samples: %s\n",optarg); break; + case 'S': if ( bam_smpl_add_samples(mplp.bsmpl,optarg,1)<0 ) error("Could not read samples: %s\n",optarg); break; + case 'O': + switch (optarg[0]) { + case 'b': mplp.output_type = FT_BCF_GZ; break; + case 'u': mplp.output_type = FT_BCF; break; + case 'z': mplp.output_type = FT_VCF_GZ; break; + case 'v': mplp.output_type = FT_VCF; break; + default: error("[error] The option \"-O\" changed meaning when mpileup moved to bcftools. Did you mean: \"bcftools mpileup --output-type\" or \"samtools mpileup --output-BP\"?\n", optarg); + } + break; + case 'C': mplp.capQ_thres = atoi(optarg); break; + case 'q': mplp.min_mq = atoi(optarg); break; + case 'Q': mplp.min_baseQ = atoi(optarg); break; + case 'b': file_list = optarg; break; + case 'o': { + char *end; + long value = strtol(optarg, &end, 10); + // Distinguish between -o INT and -o FILE (a bit of a hack!) + if (*end == '\0') mplp.openQ = value; + else mplp.output_fname = optarg; + } + break; + case 'e': mplp.extQ = atoi(optarg); break; + case 'h': mplp.tandemQ = atoi(optarg); break; + case 'A': use_orphan = 1; break; + case 'F': mplp.min_frac = atof(optarg); break; + case 'm': mplp.min_support = atoi(optarg); break; + case 'L': mplp.max_indel_depth = atoi(optarg); break; + case 'G': bam_smpl_add_readgroups(mplp.bsmpl, optarg, 1); break; + case 'a': + if (optarg[0]=='?') { + list_annotations(stderr); + return 1; + } + mplp.fmt_flag |= parse_format_flag(optarg); + break; + default: + fprintf(stderr,"Invalid option: '%c'\n", c); + return 1; + } + } + + if ( mplp.gvcf && !(mplp.fmt_flag&B2B_FMT_DP) ) + { + fprintf(stderr,"[warning] The -t DP option is required with --gvcf, switching on.\n"); + mplp.fmt_flag |= B2B_FMT_DP; + } + if ( mplp.flag&(MPLP_BCF|MPLP_VCF|MPLP_NO_COMP) ) + { + if ( mplp.flag&MPLP_VCF ) + { + if ( mplp.flag&MPLP_NO_COMP ) mplp.output_type = FT_VCF; + else mplp.output_type = FT_VCF_GZ; + } + else if ( mplp.flag&MPLP_BCF ) + { + if ( mplp.flag&MPLP_NO_COMP ) mplp.output_type = FT_BCF; + else mplp.output_type = FT_BCF_GZ; + } + } + if ( !(mplp.flag&MPLP_REALN) && mplp.flag&MPLP_REDO_BAQ ) + { + fprintf(stderr,"Error: The -B option cannot be combined with -E\n"); + return 1; + } + if (use_orphan) mplp.flag &= ~MPLP_NO_ORPHAN; + if (argc == 1) + { + print_usage(stderr, &mplp); + return 1; + } + if (!mplp.fai && !noref) { + fprintf(stderr,"Error: mpileup requires the --fasta-ref option by default; use --no-reference to run without a fasta reference\n"); + return 1; + } + int ret,i; + if (file_list) + { + if ( read_file_list(file_list,&nfiles,&fn) ) return 1; + mplp.files = fn; + mplp.nfiles = nfiles; + } + else + { + mplp.nfiles = argc - optind; + mplp.files = (char**) malloc(mplp.nfiles*sizeof(char*)); + for (i=0; i + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "regidx.h" +#include "bcftools.h" +#include "bam2bcf.h" +#include "bam_sample.h" +#include "gvcf.h" + +#define MPLP_BCF 1 +#define MPLP_VCF (1<<1) +#define MPLP_NO_COMP (1<<2) +#define MPLP_NO_ORPHAN (1<<3) +#define MPLP_REALN (1<<4) +#define MPLP_NO_INDEL (1<<5) +#define MPLP_REDO_BAQ (1<<6) +#define MPLP_ILLUMINA13 (1<<7) +#define MPLP_IGNORE_RG (1<<8) +#define MPLP_PRINT_POS (1<<9) +#define MPLP_PRINT_MAPQ (1<<10) +#define MPLP_PER_SAMPLE (1<<11) +#define MPLP_SMART_OVERLAPS (1<<12) + +typedef struct _mplp_aux_t mplp_aux_t; +typedef struct _mplp_pileup_t mplp_pileup_t; + +// Data shared by all bam files +typedef struct { + int min_mq, flag, min_baseQ, capQ_thres, max_depth, max_indel_depth, fmt_flag; + int rflag_require, rflag_filter, output_type; + int openQ, extQ, tandemQ, min_support; // for indels + double min_frac; // for indels + char *reg_fname, *pl_list, *fai_fname, *output_fname; + int reg_is_file, record_cmd_line, n_threads; + faidx_t *fai; + regidx_t *bed, *reg; // bed: skipping regions, reg: index-jump to regions + regitr_t *bed_itr, *reg_itr; + int bed_logic; // 1: include region, 0: exclude region + gvcf_t *gvcf; + + // auxiliary structures for calling + bcf_callaux_t *bca; + bcf_callret1_t *bcr; + bcf_call_t bc; + bam_mplp_t iter; + mplp_aux_t **mplp_data; + int nfiles; + char **files; + mplp_pileup_t *gplp; + int *n_plp; + const bam_pileup1_t **plp; + bam_smpl_t *bsmpl; + kstring_t buf; + bcf1_t *bcf_rec; + htsFile *bcf_fp; + bcf_hdr_t *bcf_hdr; + int argc; + char **argv; +} mplp_conf_t; + +typedef struct { + char *ref[2]; + int ref_id[2]; + int ref_len[2]; +} mplp_ref_t; + +#define MPLP_REF_INIT {{NULL,NULL},{-1,-1},{0,0}} + +// Data specific to each bam file +struct _mplp_aux_t { + samFile *fp; + hts_itr_t *iter; + bam_hdr_t *h; + mplp_ref_t *ref; + const mplp_conf_t *conf; + int bam_id; + hts_idx_t *idx; // maintained only with more than one -r regions +}; + +// Data passed to htslib/mpileup +struct _mplp_pileup_t { + int n; + int *n_plp, *m_plp; + bam_pileup1_t **plp; +}; + +static int mplp_get_ref(mplp_aux_t *ma, int tid, char **ref, int *ref_len) { + mplp_ref_t *r = ma->ref; + + //printf("get ref %d {%d/%p, %d/%p}\n", tid, r->ref_id[0], r->ref[0], r->ref_id[1], r->ref[1]); + + if (!r || !ma->conf->fai) { + *ref = NULL; + return 0; + } + + // Do we need to reference count this so multiple mplp_aux_t can + // track which references are in use? + // For now we just cache the last two. Sufficient? + if (tid == r->ref_id[0]) { + *ref = r->ref[0]; + *ref_len = r->ref_len[0]; + return 1; + } + if (tid == r->ref_id[1]) { + // Last, swap over + int tmp; + tmp = r->ref_id[0]; r->ref_id[0] = r->ref_id[1]; r->ref_id[1] = tmp; + tmp = r->ref_len[0]; r->ref_len[0] = r->ref_len[1]; r->ref_len[1] = tmp; + + char *tc; + tc = r->ref[0]; r->ref[0] = r->ref[1]; r->ref[1] = tc; + *ref = r->ref[0]; + *ref_len = r->ref_len[0]; + return 1; + } + + // New, so migrate to old and load new + free(r->ref[1]); + r->ref[1] = r->ref[0]; + r->ref_id[1] = r->ref_id[0]; + r->ref_len[1] = r->ref_len[0]; + + r->ref_id[0] = tid; + r->ref[0] = faidx_fetch_seq(ma->conf->fai, + ma->h->target_name[r->ref_id[0]], + 0, + INT_MAX, + &r->ref_len[0]); + + if (!r->ref[0]) { + r->ref[0] = NULL; + r->ref_id[0] = -1; + r->ref_len[0] = 0; + *ref = NULL; + return 0; + } + + *ref = r->ref[0]; + *ref_len = r->ref_len[0]; + return 1; +} + +static int mplp_func(void *data, bam1_t *b) +{ + char *ref; + mplp_aux_t *ma = (mplp_aux_t*)data; + int ret, ref_len; + while (1) + { + int has_ref; + ret = ma->iter? sam_itr_next(ma->fp, ma->iter, b) : sam_read1(ma->fp, ma->h, b); + if (ret < 0) break; + // The 'B' cigar operation is not part of the specification, considering as obsolete. + // bam_remove_B(b); + if (b->core.tid < 0 || (b->core.flag&BAM_FUNMAP)) continue; // exclude unmapped reads + if (ma->conf->rflag_require && !(ma->conf->rflag_require&b->core.flag)) continue; + if (ma->conf->rflag_filter && ma->conf->rflag_filter&b->core.flag) continue; + if (ma->conf->bed) + { + // test overlap + regitr_t *itr = ma->conf->bed_itr; + int beg = b->core.pos, end = bam_endpos(b)-1; + int overlap = regidx_overlap(ma->conf->bed, ma->h->target_name[b->core.tid],beg,end, itr); + if ( !ma->conf->bed_logic && !overlap ) + { + // exclude only reads which are fully contained in the region + while ( regitr_overlap(itr) ) + { + if ( beg < itr->beg ) { overlap = 1; break; } + if ( end > itr->end ) { overlap = 1; break; } + } + } + if ( !overlap ) continue; + } + if ( bam_smpl_get_sample_id(ma->conf->bsmpl,ma->bam_id,b)<0 ) continue; + if (ma->conf->flag & MPLP_ILLUMINA13) { + int i; + uint8_t *qual = bam_get_qual(b); + for (i = 0; i < b->core.l_qseq; ++i) + qual[i] = qual[i] > 31? qual[i] - 31 : 0; + } + + if (ma->conf->fai && b->core.tid >= 0) { + has_ref = mplp_get_ref(ma, b->core.tid, &ref, &ref_len); + if (has_ref && ref_len <= b->core.pos) { // exclude reads outside of the reference sequence + fprintf(bcftools_stderr,"[%s] Skipping because %d is outside of %d [ref:%d]\n", + __func__, b->core.pos, ref_len, b->core.tid); + continue; + } + } else { + has_ref = 0; + } + + if (has_ref && (ma->conf->flag&MPLP_REALN)) sam_prob_realn(b, ref, ref_len, (ma->conf->flag & MPLP_REDO_BAQ)? 7 : 3); + if (has_ref && ma->conf->capQ_thres > 10) { + int q = sam_cap_mapq(b, ref, ref_len, ma->conf->capQ_thres); + if (q < 0) continue; // skip + else if (b->core.qual > q) b->core.qual = q; + } + if (b->core.qual < ma->conf->min_mq) continue; + else if ((ma->conf->flag&MPLP_NO_ORPHAN) && (b->core.flag&BAM_FPAIRED) && !(b->core.flag&BAM_FPROPER_PAIR)) continue; + + return ret; + }; + return ret; +} + +// Called once per new bam added to the pileup. +// We cache sample information here so we don't have to keep recomputing this +// on each and every pileup column. +// +// Cd is an arbitrary block of data we can write into, which ends up in +// the pileup structures. We stash the sample ID there. +static int pileup_constructor(void *data, const bam1_t *b, bam_pileup_cd *cd) { + mplp_aux_t *ma = (mplp_aux_t *)data; + cd->i = bam_smpl_get_sample_id(ma->conf->bsmpl, ma->bam_id, (bam1_t *)b); + return 0; +} + +static void group_smpl(mplp_pileup_t *m, bam_smpl_t *bsmpl, int n, int *n_plp, const bam_pileup1_t **plp) +{ + int i, j; + memset(m->n_plp, 0, m->n * sizeof(int)); + for (i = 0; i < n; ++i) // iterate over all bams + { + for (j = 0; j < n_plp[i]; ++j) // iterate over all reads available at this position + { + const bam_pileup1_t *p = plp[i] + j; + int id = p->cd.i; + if (m->n_plp[id] == m->m_plp[id]) + { + m->m_plp[id] = m->m_plp[id]? m->m_plp[id]<<1 : 8; + m->plp[id] = (bam_pileup1_t*) realloc(m->plp[id], sizeof(bam_pileup1_t) * m->m_plp[id]); + } + m->plp[id][m->n_plp[id]++] = *p; + } + } +} + +static void flush_bcf_records(mplp_conf_t *conf, htsFile *fp, bcf_hdr_t *hdr, bcf1_t *rec) +{ + if ( !conf->gvcf ) + { + if ( rec ) bcf_write1(fp, hdr, rec); + return; + } + + if ( !rec ) + { + gvcf_write(conf->gvcf, fp, hdr, NULL, 0); + return; + } + + int is_ref = 0; + if ( rec->n_allele==1 ) is_ref = 1; + else if ( rec->n_allele==2 ) + { + // second allele is mpileup's X, not a variant + if ( rec->d.allele[1][0]=='<' && rec->d.allele[1][1]=='*' && rec->d.allele[1][2]=='>' ) is_ref = 1; + } + rec = gvcf_write(conf->gvcf, fp, hdr, rec, is_ref); + if ( rec ) bcf_write1(fp,hdr,rec); +} + +static int mpileup_reg(mplp_conf_t *conf, uint32_t beg, uint32_t end) +{ + bam_hdr_t *hdr = conf->mplp_data[0]->h; // header of first file in input list + + int ret, i, tid, pos, ref_len; + char *ref; + + while ( (ret=bam_mplp_auto(conf->iter, &tid, &pos, conf->n_plp, conf->plp)) > 0) + { + if ( end && (posend) ) continue; + if ( conf->bed && tid >= 0 ) + { + int overlap = regidx_overlap(conf->bed, hdr->target_name[tid], pos, pos, NULL); + if ( !conf->bed_logic ) overlap = overlap ? 0 : 1; + if ( !overlap ) continue; + } + mplp_get_ref(conf->mplp_data[0], tid, &ref, &ref_len); + + int total_depth, _ref0, ref16; + for (i = total_depth = 0; i < conf->nfiles; ++i) total_depth += conf->n_plp[i]; + group_smpl(conf->gplp, conf->bsmpl, conf->nfiles, conf->n_plp, conf->plp); + _ref0 = (ref && pos < ref_len)? ref[pos] : 'N'; + ref16 = seq_nt16_table[_ref0]; + bcf_callaux_clean(conf->bca, &conf->bc); + for (i = 0; i < conf->gplp->n; ++i) + bcf_call_glfgen(conf->gplp->n_plp[i], conf->gplp->plp[i], ref16, conf->bca, conf->bcr + i); + conf->bc.tid = tid; conf->bc.pos = pos; + bcf_call_combine(conf->gplp->n, conf->bcr, conf->bca, ref16, &conf->bc); + bcf_clear1(conf->bcf_rec); + bcf_call2bcf(&conf->bc, conf->bcf_rec, conf->bcr, conf->fmt_flag, 0, 0); + flush_bcf_records(conf, conf->bcf_fp, conf->bcf_hdr, conf->bcf_rec); + + // call indels; todo: subsampling with total_depth>max_indel_depth instead of ignoring? + // check me: rghash in bcf_call_gap_prep() should have no effect, reads mplp_func already excludes them + if (!(conf->flag&MPLP_NO_INDEL) && total_depth < conf->max_indel_depth + && bcf_call_gap_prep(conf->gplp->n, conf->gplp->n_plp, conf->gplp->plp, pos, conf->bca, ref) >= 0) + { + bcf_callaux_clean(conf->bca, &conf->bc); + for (i = 0; i < conf->gplp->n; ++i) + bcf_call_glfgen(conf->gplp->n_plp[i], conf->gplp->plp[i], -1, conf->bca, conf->bcr + i); + if (bcf_call_combine(conf->gplp->n, conf->bcr, conf->bca, -1, &conf->bc) >= 0) + { + bcf_clear1(conf->bcf_rec); + bcf_call2bcf(&conf->bc, conf->bcf_rec, conf->bcr, conf->fmt_flag, conf->bca, ref); + flush_bcf_records(conf, conf->bcf_fp, conf->bcf_hdr, conf->bcf_rec); + } + } + } + return 0; +} + +static int mpileup(mplp_conf_t *conf) +{ + if (conf->nfiles == 0) { + fprintf(bcftools_stderr,"[%s] no input file/data given\n", __func__); + exit(EXIT_FAILURE); + } + + mplp_ref_t mp_ref = MPLP_REF_INIT; + conf->gplp = (mplp_pileup_t *) calloc(1,sizeof(mplp_pileup_t)); + conf->mplp_data = (mplp_aux_t**) calloc(conf->nfiles, sizeof(mplp_aux_t*)); + conf->plp = (const bam_pileup1_t**) calloc(conf->nfiles, sizeof(bam_pileup1_t*)); + conf->n_plp = (int*) calloc(conf->nfiles, sizeof(int)); + + // Allow to run mpileup on multiple regions in one go. This comes at cost: the bai index + // must be kept in the memory for the whole time which can be a problem with many bams. + // Therefore if none or only one region is requested, we initialize the bam iterator as + // before and free the index. Only when multiple regions are queried, we keep the index. + int nregs = 0; + if ( conf->reg_fname ) + { + if ( conf->reg_is_file ) + { + conf->reg = regidx_init(conf->reg_fname,NULL,NULL,0,NULL); + if ( !conf->reg ) { + fprintf(bcftools_stderr,"Could not parse the regions: %s\n", conf->reg_fname); + exit(EXIT_FAILURE); + } + } + else + { + conf->reg = regidx_init(NULL,regidx_parse_reg,NULL,sizeof(char*),NULL); + if ( regidx_insert_list(conf->reg,conf->reg_fname,',') !=0 ) { + fprintf(bcftools_stderr,"Could not parse the regions: %s\n", conf->reg_fname); + exit(EXIT_FAILURE); + } + } + nregs = regidx_nregs(conf->reg); + conf->reg_itr = regitr_init(conf->reg); + regitr_loop(conf->reg_itr); // region iterator now positioned at the first region + } + + // read the header of each file in the list and initialize data + // beware: mpileup has always assumed that tid's are consistent in the headers, add sanity check at least! + bam_hdr_t *hdr = NULL; // header of first file in input list + int i; + for (i = 0; i < conf->nfiles; ++i) { + bam_hdr_t *h_tmp; + conf->mplp_data[i] = (mplp_aux_t*) calloc(1, sizeof(mplp_aux_t)); + conf->mplp_data[i]->fp = sam_open(conf->files[i], "rb"); + if ( !conf->mplp_data[i]->fp ) + { + fprintf(bcftools_stderr, "[%s] failed to open %s: %s\n", __func__, conf->files[i], strerror(errno)); + exit(EXIT_FAILURE); + } + if (hts_set_opt(conf->mplp_data[i]->fp, CRAM_OPT_DECODE_MD, 0)) { + fprintf(bcftools_stderr, "Failed to set CRAM_OPT_DECODE_MD value\n"); + exit(EXIT_FAILURE); + } + if (conf->fai_fname && hts_set_fai_filename(conf->mplp_data[i]->fp, conf->fai_fname) != 0) { + fprintf(bcftools_stderr, "[%s] failed to process %s: %s\n", + __func__, conf->fai_fname, strerror(errno)); + exit(EXIT_FAILURE); + } + conf->mplp_data[i]->conf = conf; + conf->mplp_data[i]->ref = &mp_ref; + h_tmp = sam_hdr_read(conf->mplp_data[i]->fp); + if ( !h_tmp ) { + fprintf(bcftools_stderr,"[%s] fail to read the header of %s\n", __func__, conf->files[i]); + exit(EXIT_FAILURE); + } + conf->mplp_data[i]->h = i ? hdr : h_tmp; // for j==0, "h" has not been set yet + conf->mplp_data[i]->bam_id = bam_smpl_add_bam(conf->bsmpl,h_tmp->text,conf->files[i]); + if ( conf->mplp_data[i]->bam_id<0 ) + { + // no usable readgroups in this bam, it can be skipped + sam_close(conf->mplp_data[i]->fp); + free(conf->mplp_data[i]); + bam_hdr_destroy(h_tmp); + free(conf->files[i]); + if ( i+1nfiles ) memmove(&conf->files[i],&conf->files[i+1],sizeof(*conf->files)*(conf->nfiles-i-1)); + conf->nfiles--; + i--; + continue; + } + if (conf->reg) { + hts_idx_t *idx = sam_index_load(conf->mplp_data[i]->fp, conf->files[i]); + if (idx == NULL) { + fprintf(bcftools_stderr, "[%s] fail to load index for %s\n", __func__, conf->files[i]); + exit(EXIT_FAILURE); + } + conf->buf.l = 0; + ksprintf(&conf->buf,"%s:%u-%u",conf->reg_itr->seq,conf->reg_itr->beg+1,conf->reg_itr->end+1); + conf->mplp_data[i]->iter = sam_itr_querys(idx, conf->mplp_data[i]->h, conf->buf.s); + if ( !conf->mplp_data[i]->iter ) + { + conf->mplp_data[i]->iter = sam_itr_querys(idx, conf->mplp_data[i]->h, conf->reg_itr->seq); + if ( conf->mplp_data[i]->iter ) { + fprintf(bcftools_stderr,"[E::%s] fail to parse region '%s'\n", __func__, conf->buf.s); + exit(EXIT_FAILURE); + } + fprintf(bcftools_stderr,"[E::%s] the sequence \"%s\" not found: %s\n",__func__,conf->reg_itr->seq,conf->files[i]); + exit(EXIT_FAILURE); + } + if ( nregs==1 ) // no need to keep the index in memory + hts_idx_destroy(idx); + else + conf->mplp_data[i]->idx = idx; + } + + if ( !hdr ) hdr = h_tmp; /* save the header of first file in list */ + else { + // FIXME: check consistency between h and h_tmp + bam_hdr_destroy(h_tmp); + + // we store only the first file's header; it's (alleged to be) + // compatible with the i-th file's target_name lookup needs + conf->mplp_data[i]->h = hdr; + } + } + // allocate data storage proportionate to number of samples being studied sm->n + bam_smpl_get_samples(conf->bsmpl, &conf->gplp->n); + conf->gplp->n_plp = (int*) calloc(conf->gplp->n, sizeof(int)); + conf->gplp->m_plp = (int*) calloc(conf->gplp->n, sizeof(int)); + conf->gplp->plp = (bam_pileup1_t**) calloc(conf->gplp->n, sizeof(bam_pileup1_t*)); + + fprintf(bcftools_stderr, "[%s] %d samples in %d input files\n", __func__, conf->gplp->n, conf->nfiles); + // write the VCF header + conf->bcf_fp = hts_open(conf->output_fname?conf->output_fname:"-", hts_bcf_wmode(conf->output_type)); + if (conf->bcf_fp == NULL) { + fprintf(bcftools_stderr, "[%s] failed to write to %s: %s\n", __func__, conf->output_fname? conf->output_fname : "standard output", strerror(errno)); + exit(EXIT_FAILURE); + } + if ( conf->n_threads ) hts_set_threads(conf->bcf_fp, conf->n_threads); + + // BCF header creation + conf->bcf_hdr = bcf_hdr_init("w"); + conf->buf.l = 0; + + if (conf->record_cmd_line) + { + ksprintf(&conf->buf, "##bcftoolsVersion=%s+htslib-%s\n",bcftools_version(),hts_version()); + bcf_hdr_append(conf->bcf_hdr, conf->buf.s); + + conf->buf.l = 0; + ksprintf(&conf->buf, "##bcftoolsCommand=mpileup"); + for (i=1; iargc; i++) ksprintf(&conf->buf, " %s", conf->argv[i]); + kputc('\n', &conf->buf); + bcf_hdr_append(conf->bcf_hdr, conf->buf.s); + } + + if (conf->fai_fname) + { + conf->buf.l = 0; + ksprintf(&conf->buf, "##reference=file://%s\n", conf->fai_fname); + bcf_hdr_append(conf->bcf_hdr, conf->buf.s); + } + + // Translate BAM @SQ tags to BCF ##contig tags + // todo: use/write new BAM header manipulation routines, fill also UR, M5 + for (i=0; in_targets; i++) + { + conf->buf.l = 0; + ksprintf(&conf->buf, "##contig=", hdr->target_name[i], hdr->target_len[i]); + bcf_hdr_append(conf->bcf_hdr, conf->buf.s); + } + conf->buf.l = 0; + + bcf_hdr_append(conf->bcf_hdr,"##ALT="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); +#if CDF_MWU_TESTS + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); +#endif + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_DP ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_DV ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_DPR ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_INFO_DPR ) + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + if ( conf->fmt_flag&B2B_FMT_DP4 ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_SP ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_AD ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_ADF ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_FMT_ADR ) + bcf_hdr_append(conf->bcf_hdr,"##FORMAT="); + if ( conf->fmt_flag&B2B_INFO_AD ) + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + if ( conf->fmt_flag&B2B_INFO_ADF ) + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + if ( conf->fmt_flag&B2B_INFO_ADR ) + bcf_hdr_append(conf->bcf_hdr,"##INFO="); + if ( conf->gvcf ) + gvcf_update_header(conf->gvcf, conf->bcf_hdr); + + int nsmpl; + const char **smpl = bam_smpl_get_samples(conf->bsmpl, &nsmpl); + for (i=0; ibcf_hdr, smpl[i]); + bcf_hdr_write(conf->bcf_fp, conf->bcf_hdr); + + conf->bca = bcf_call_init(-1., conf->min_baseQ); + conf->bcr = (bcf_callret1_t*) calloc(nsmpl, sizeof(bcf_callret1_t)); + conf->bca->openQ = conf->openQ, conf->bca->extQ = conf->extQ, conf->bca->tandemQ = conf->tandemQ; + conf->bca->min_frac = conf->min_frac; + conf->bca->min_support = conf->min_support; + conf->bca->per_sample_flt = conf->flag & MPLP_PER_SAMPLE; + + conf->bc.bcf_hdr = conf->bcf_hdr; + conf->bc.n = nsmpl; + conf->bc.PL = (int32_t*) malloc(15 * nsmpl * sizeof(*conf->bc.PL)); + if (conf->fmt_flag) + { + assert( sizeof(float)==sizeof(int32_t) ); + conf->bc.DP4 = (int32_t*) malloc(nsmpl * sizeof(int32_t) * 4); + conf->bc.fmt_arr = (uint8_t*) malloc(nsmpl * sizeof(float)); // all fmt_flag fields, float and int32 + if ( conf->fmt_flag&(B2B_INFO_DPR|B2B_FMT_DPR|B2B_INFO_AD|B2B_INFO_ADF|B2B_INFO_ADR|B2B_FMT_AD|B2B_FMT_ADF|B2B_FMT_ADR) ) + { + // first B2B_MAX_ALLELES fields for total numbers, the rest per-sample + conf->bc.ADR = (int32_t*) malloc((nsmpl+1)*B2B_MAX_ALLELES*sizeof(int32_t)); + conf->bc.ADF = (int32_t*) malloc((nsmpl+1)*B2B_MAX_ALLELES*sizeof(int32_t)); + for (i=0; ibcr[i].ADR = conf->bc.ADR + (i+1)*B2B_MAX_ALLELES; + conf->bcr[i].ADF = conf->bc.ADF + (i+1)*B2B_MAX_ALLELES; + } + } + } + + // init mpileup + conf->iter = bam_mplp_init(conf->nfiles, mplp_func, (void**)conf->mplp_data); + if ( conf->flag & MPLP_SMART_OVERLAPS ) bam_mplp_init_overlaps(conf->iter); + if ( (double)conf->max_depth * conf->nfiles > 1<<20) + fprintf(bcftools_stderr, "Warning: Potential memory hog, up to %.0fM reads in the pileup!\n", (double)conf->max_depth*conf->nfiles); + if ( (double)conf->max_depth * conf->nfiles / nsmpl < 250 ) + fprintf(bcftools_stderr, "Note: The maximum per-sample depth with -d %d is %.1fx\n", conf->max_depth,(double)conf->max_depth * conf->nfiles / nsmpl); + bam_mplp_set_maxcnt(conf->iter, conf->max_depth); + conf->max_indel_depth = conf->max_indel_depth * nsmpl; + conf->bcf_rec = bcf_init1(); + bam_mplp_constructor(conf->iter, pileup_constructor); + + // Run mpileup for multiple regions + if ( nregs ) + { + int ireg = 0; + do + { + // first region is already positioned + if ( ireg++ > 0 ) + { + conf->buf.l = 0; + ksprintf(&conf->buf,"%s:%u-%u",conf->reg_itr->seq,conf->reg_itr->beg,conf->reg_itr->end); + + for (i=0; infiles; i++) + { + hts_itr_destroy(conf->mplp_data[i]->iter); + conf->mplp_data[i]->iter = sam_itr_querys(conf->mplp_data[i]->idx, conf->mplp_data[i]->h, conf->buf.s); + if ( !conf->mplp_data[i]->iter ) + { + conf->mplp_data[i]->iter = sam_itr_querys(conf->mplp_data[i]->idx, conf->mplp_data[i]->h, conf->reg_itr->seq); + if ( conf->mplp_data[i]->iter ) { + fprintf(bcftools_stderr,"[E::%s] fail to parse region '%s'\n", __func__, conf->buf.s); + exit(EXIT_FAILURE); + } + fprintf(bcftools_stderr,"[E::%s] the sequence \"%s\" not found: %s\n",__func__,conf->reg_itr->seq,conf->files[i]); + exit(EXIT_FAILURE); + } + bam_mplp_reset(conf->iter); + } + } + mpileup_reg(conf,conf->reg_itr->beg,conf->reg_itr->end); + } + while ( regitr_loop(conf->reg_itr) ); + } + else + mpileup_reg(conf,0,0); + + flush_bcf_records(conf, conf->bcf_fp, conf->bcf_hdr, NULL); + + // clean up + free(conf->bc.tmp.s); + bcf_destroy1(conf->bcf_rec); + if (conf->bcf_fp) + { + hts_close(conf->bcf_fp); + bcf_hdr_destroy(conf->bcf_hdr); + bcf_call_destroy(conf->bca); + free(conf->bc.PL); + free(conf->bc.DP4); + free(conf->bc.ADR); + free(conf->bc.ADF); + free(conf->bc.fmt_arr); + free(conf->bcr); + } + if ( conf->gvcf ) gvcf_destroy(conf->gvcf); + free(conf->buf.s); + for (i = 0; i < conf->gplp->n; ++i) free(conf->gplp->plp[i]); + free(conf->gplp->plp); free(conf->gplp->n_plp); free(conf->gplp->m_plp); free(conf->gplp); + bam_mplp_destroy(conf->iter); + bam_hdr_destroy(hdr); + for (i = 0; i < conf->nfiles; ++i) { + if ( nregs>1 ) hts_idx_destroy(conf->mplp_data[i]->idx); + sam_close(conf->mplp_data[i]->fp); + if ( conf->mplp_data[i]->iter) hts_itr_destroy(conf->mplp_data[i]->iter); + free(conf->mplp_data[i]); + } + if ( conf->reg_itr ) regitr_destroy(conf->reg_itr); + free(conf->mplp_data); free(conf->plp); free(conf->n_plp); + free(mp_ref.ref[0]); + free(mp_ref.ref[1]); + return 0; +} + +static int is_url(const char *s) +{ + static const char uri_scheme_chars[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+.-"; + return s[strspn(s, uri_scheme_chars)] == ':'; +} + +#define MAX_PATH_LEN 1024 +int read_file_list(const char *file_list,int *n,char **argv[]) +{ + char buf[MAX_PATH_LEN]; + int len, nfiles = 0; + char **files = NULL; + struct stat sb; + + *n = 0; + *argv = NULL; + + FILE *fh = fopen(file_list,"r"); + if ( !fh ) + { + fprintf(bcftools_stderr,"%s: %s\n", file_list,strerror(errno)); + return 1; + } + + files = (char**) calloc(nfiles,sizeof(char*)); + nfiles = 0; + while ( fgets(buf,MAX_PATH_LEN,fh) ) + { + // allow empty lines and trailing spaces + len = strlen(buf); + while ( len>0 && isspace(buf[len-1]) ) len--; + if ( !len ) continue; + + // check sanity of the file list + buf[len] = 0; + if (! (is_url(buf) || stat(buf, &sb) == 0)) + { + // no such file, check if it is safe to print its name + int i, safe_to_print = 1; + for (i=0; irflag_require); + char *tmp_filter = bam_flag2str(mplp->rflag_filter); + + // Display usage information, formatted for the standard 80 columns. + // (The unusual string formatting here aids the readability of this + // source code in 80 columns, to the extent that's possible.) + + fprintf(fp, +"\n" +"Usage: bcftools mpileup [options] in1.bam [in2.bam [...]]\n" +"\n" +"Input options:\n" +" -6, --illumina1.3+ quality is in the Illumina-1.3+ encoding\n" +" -A, --count-orphans do not discard anomalous read pairs\n" +" -b, --bam-list FILE list of input BAM filenames, one per line\n" +" -B, --no-BAQ disable BAQ (per-Base Alignment Quality)\n" +" -C, --adjust-MQ INT adjust mapping quality; recommended:50, disable:0 [0]\n" +" -d, --max-depth INT max per-file depth; avoids excessive memory usage [%d]\n", mplp->max_depth); + fprintf(fp, +" -E, --redo-BAQ recalculate BAQ on the fly, ignore existing BQs\n" +" -f, --fasta-ref FILE faidx indexed reference sequence file\n" +" --no-reference do not require fasta reference file\n" +" -G, --read-groups FILE select or exclude read groups listed in the file\n" +" -q, --min-MQ INT skip alignments with mapQ smaller than INT [%d]\n", mplp->min_mq); + fprintf(fp, +" -Q, --min-BQ INT skip bases with baseQ/BAQ smaller than INT [%d]\n", mplp->min_baseQ); + fprintf(fp, +" -r, --regions REG[,...] comma separated list of regions in which pileup is generated\n" +" -R, --regions-file FILE restrict to regions listed in a file\n" +" --ignore-RG ignore RG tags (one BAM = one sample)\n" +" --rf, --incl-flags STR|INT required flags: skip reads with mask bits unset [%s]\n", tmp_require); + fprintf(fp, +" --ff, --excl-flags STR|INT filter flags: skip reads with mask bits set\n" +" [%s]\n", tmp_filter); + fprintf(fp, +" -s, --samples LIST comma separated list of samples to include\n" +" -S, --samples-file FILE file of samples to include\n" +" -t, --targets REG[,...] similar to -r but streams rather than index-jumps\n" +" -T, --targets-file FILE similar to -R but streams rather than index-jumps\n" +" -x, --ignore-overlaps disable read-pair overlap detection\n" +"\n" +"Output options:\n" +" -a, --annotate LIST optional tags to output; '?' to list []\n" +" -g, --gvcf INT[,...] group non-variant sites into gVCF blocks according\n" +" to minimum per-sample DP\n" +" --no-version do not append version and command line to the header\n" +" -o, --output FILE write output to FILE [standard output]\n" +" -O, --output-type TYPE 'b' compressed BCF; 'u' uncompressed BCF;\n" +" 'z' compressed VCF; 'v' uncompressed VCF [v]\n" +" --threads INT number of extra output compression threads [0]\n" +"\n" +"SNP/INDEL genotype likelihoods options:\n" +" -e, --ext-prob INT Phred-scaled gap extension seq error probability [%d]\n", mplp->extQ); + fprintf(fp, +" -F, --gap-frac FLOAT minimum fraction of gapped reads [%g]\n", mplp->min_frac); + fprintf(fp, +" -h, --tandem-qual INT coefficient for homopolymer errors [%d]\n", mplp->tandemQ); + fprintf(fp, +" -I, --skip-indels do not perform indel calling\n" +" -L, --max-idepth INT maximum per-file depth for INDEL calling [%d]\n", mplp->max_indel_depth); + fprintf(fp, +" -m, --min-ireads INT minimum number gapped reads for indel candidates [%d]\n", mplp->min_support); + fprintf(fp, +" -o, --open-prob INT Phred-scaled gap open seq error probability [%d]\n", mplp->openQ); + fprintf(fp, +" -p, --per-sample-mF apply -m and -F per-sample for increased sensitivity\n" +" -P, --platforms STR comma separated list of platforms for indels [all]\n" +"\n" +"Notes: Assuming diploid individuals.\n" +"\n"); + + free(tmp_require); + free(tmp_filter); +} + +int bam_mpileup(int argc, char *argv[]) +{ + int c; + const char *file_list = NULL; + char **fn = NULL; + int nfiles = 0, use_orphan = 0, noref = 0; + mplp_conf_t mplp; + memset(&mplp, 0, sizeof(mplp_conf_t)); + mplp.min_baseQ = 13; + mplp.capQ_thres = 0; + mplp.max_depth = 250; mplp.max_indel_depth = 250; + mplp.openQ = 40; mplp.extQ = 20; mplp.tandemQ = 100; + mplp.min_frac = 0.002; mplp.min_support = 1; + mplp.flag = MPLP_NO_ORPHAN | MPLP_REALN | MPLP_SMART_OVERLAPS; + mplp.argc = argc; mplp.argv = argv; + mplp.rflag_filter = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP; + mplp.output_fname = NULL; + mplp.output_type = FT_VCF; + mplp.record_cmd_line = 1; + mplp.n_threads = 0; + mplp.bsmpl = bam_smpl_init(); + + static const struct option lopts[] = + { + {"rf", required_argument, NULL, 1}, // require flag + {"ff", required_argument, NULL, 2}, // filter flag + {"incl-flags", required_argument, NULL, 1}, + {"excl-flags", required_argument, NULL, 2}, + {"output", required_argument, NULL, 3}, + {"open-prob", required_argument, NULL, 4}, + {"ignore-RG", no_argument, NULL, 5}, + {"ignore-rg", no_argument, NULL, 5}, + {"gvcf", required_argument, NULL, 'g'}, + {"no-reference", no_argument, NULL, 7}, + {"no-version", no_argument, NULL, 8}, + {"threads",required_argument,NULL,9}, + {"illumina1.3+", no_argument, NULL, '6'}, + {"count-orphans", no_argument, NULL, 'A'}, + {"bam-list", required_argument, NULL, 'b'}, + {"no-BAQ", no_argument, NULL, 'B'}, + {"no-baq", no_argument, NULL, 'B'}, + {"adjust-MQ", required_argument, NULL, 'C'}, + {"adjust-mq", required_argument, NULL, 'C'}, + {"max-depth", required_argument, NULL, 'd'}, + {"redo-BAQ", no_argument, NULL, 'E'}, + {"redo-baq", no_argument, NULL, 'E'}, + {"fasta-ref", required_argument, NULL, 'f'}, + {"read-groups", required_argument, NULL, 'G'}, + {"region", required_argument, NULL, 'r'}, + {"regions", required_argument, NULL, 'r'}, + {"regions-file", required_argument, NULL, 'R'}, + {"targets", required_argument, NULL, 't'}, + {"targets-file", required_argument, NULL, 'T'}, + {"min-MQ", required_argument, NULL, 'q'}, + {"min-mq", required_argument, NULL, 'q'}, + {"min-BQ", required_argument, NULL, 'Q'}, + {"min-bq", required_argument, NULL, 'Q'}, + {"ignore-overlaps", no_argument, NULL, 'x'}, + {"output-type", required_argument, NULL, 'O'}, + {"samples", required_argument, NULL, 's'}, + {"samples-file", required_argument, NULL, 'S'}, + {"annotate", required_argument, NULL, 'a'}, + {"ext-prob", required_argument, NULL, 'e'}, + {"gap-frac", required_argument, NULL, 'F'}, + {"tandem-qual", required_argument, NULL, 'h'}, + {"skip-indels", no_argument, NULL, 'I'}, + {"max-idepth", required_argument, NULL, 'L'}, + {"min-ireads ", required_argument, NULL, 'm'}, + {"per-sample-mF", no_argument, NULL, 'p'}, + {"per-sample-mf", no_argument, NULL, 'p'}, + {"platforms", required_argument, NULL, 'P'}, + {NULL, 0, NULL, 0} + }; + while ((c = getopt_long(argc, argv, "Ag:f:r:R:q:Q:C:Bd:L:b:P:po:e:h:Im:F:EG:6O:xa:s:S:t:T:",lopts,NULL)) >= 0) { + switch (c) { + case 'x': mplp.flag &= ~MPLP_SMART_OVERLAPS; break; + case 1 : + mplp.rflag_require = bam_str2flag(optarg); + if ( mplp.rflag_require<0 ) { fprintf(bcftools_stderr,"Could not parse --rf %s\n", optarg); return 1; } + break; + case 2 : + mplp.rflag_filter = bam_str2flag(optarg); + if ( mplp.rflag_filter<0 ) { fprintf(bcftools_stderr,"Could not parse --ff %s\n", optarg); return 1; } + break; + case 3 : mplp.output_fname = optarg; break; + case 4 : mplp.openQ = atoi(optarg); break; + case 5 : bam_smpl_ignore_readgroups(mplp.bsmpl); break; + case 'g': + mplp.gvcf = gvcf_init(optarg); + if ( !mplp.gvcf ) error("Could not parse: --gvcf %s\n", optarg); + break; + case 'f': + mplp.fai = fai_load(optarg); + if (mplp.fai == NULL) return 1; + mplp.fai_fname = optarg; + break; + case 7 : noref = 1; break; + case 8 : mplp.record_cmd_line = 0; break; + case 9 : mplp.n_threads = strtol(optarg, 0, 0); break; + case 'd': mplp.max_depth = atoi(optarg); break; + case 'r': mplp.reg_fname = strdup(optarg); break; + case 'R': mplp.reg_fname = strdup(optarg); mplp.reg_is_file = 1; break; + case 't': + // In the original version the whole BAM was streamed which is inefficient + // with few BED intervals and big BAMs. Todo: devise a heuristic to determine + // best strategy, that is streaming or jumping. + if ( optarg[0]=='^' ) optarg++; + else mplp.bed_logic = 1; + mplp.bed = regidx_init(NULL,regidx_parse_reg,NULL,0,NULL); + mplp.bed_itr = regitr_init(mplp.bed); + if ( regidx_insert_list(mplp.bed,optarg,',') !=0 ) + { + fprintf(bcftools_stderr,"Could not parse the targets: %s\n", optarg); + exit(EXIT_FAILURE); + } + break; + case 'T': + if ( optarg[0]=='^' ) optarg++; + else mplp.bed_logic = 1; + mplp.bed = regidx_init(optarg,NULL,NULL,0,NULL); + if (!mplp.bed) { fprintf(bcftools_stderr, "bcftools mpileup: Could not read file \"%s\"", optarg); return 1; } + break; + case 'P': mplp.pl_list = strdup(optarg); break; + case 'p': mplp.flag |= MPLP_PER_SAMPLE; break; + case 'B': mplp.flag &= ~MPLP_REALN; break; + case 'I': mplp.flag |= MPLP_NO_INDEL; break; + case 'E': mplp.flag |= MPLP_REDO_BAQ; break; + case '6': mplp.flag |= MPLP_ILLUMINA13; break; + case 's': if ( bam_smpl_add_samples(mplp.bsmpl,optarg,0)<0 ) error("Could not read samples: %s\n",optarg); break; + case 'S': if ( bam_smpl_add_samples(mplp.bsmpl,optarg,1)<0 ) error("Could not read samples: %s\n",optarg); break; + case 'O': + switch (optarg[0]) { + case 'b': mplp.output_type = FT_BCF_GZ; break; + case 'u': mplp.output_type = FT_BCF; break; + case 'z': mplp.output_type = FT_VCF_GZ; break; + case 'v': mplp.output_type = FT_VCF; break; + default: error("[error] The option \"-O\" changed meaning when mpileup moved to bcftools. Did you mean: \"bcftools mpileup --output-type\" or \"samtools mpileup --output-BP\"?\n", optarg); + } + break; + case 'C': mplp.capQ_thres = atoi(optarg); break; + case 'q': mplp.min_mq = atoi(optarg); break; + case 'Q': mplp.min_baseQ = atoi(optarg); break; + case 'b': file_list = optarg; break; + case 'o': { + char *end; + long value = strtol(optarg, &end, 10); + // Distinguish between -o INT and -o FILE (a bit of a hack!) + if (*end == '\0') mplp.openQ = value; + else mplp.output_fname = optarg; + } + break; + case 'e': mplp.extQ = atoi(optarg); break; + case 'h': mplp.tandemQ = atoi(optarg); break; + case 'A': use_orphan = 1; break; + case 'F': mplp.min_frac = atof(optarg); break; + case 'm': mplp.min_support = atoi(optarg); break; + case 'L': mplp.max_indel_depth = atoi(optarg); break; + case 'G': bam_smpl_add_readgroups(mplp.bsmpl, optarg, 1); break; + case 'a': + if (optarg[0]=='?') { + list_annotations(bcftools_stderr); + return 1; + } + mplp.fmt_flag |= parse_format_flag(optarg); + break; + default: + fprintf(bcftools_stderr,"Invalid option: '%c'\n", c); + return 1; + } + } + + if ( mplp.gvcf && !(mplp.fmt_flag&B2B_FMT_DP) ) + { + fprintf(bcftools_stderr,"[warning] The -t DP option is required with --gvcf, switching on.\n"); + mplp.fmt_flag |= B2B_FMT_DP; + } + if ( mplp.flag&(MPLP_BCF|MPLP_VCF|MPLP_NO_COMP) ) + { + if ( mplp.flag&MPLP_VCF ) + { + if ( mplp.flag&MPLP_NO_COMP ) mplp.output_type = FT_VCF; + else mplp.output_type = FT_VCF_GZ; + } + else if ( mplp.flag&MPLP_BCF ) + { + if ( mplp.flag&MPLP_NO_COMP ) mplp.output_type = FT_BCF; + else mplp.output_type = FT_BCF_GZ; + } + } + if ( !(mplp.flag&MPLP_REALN) && mplp.flag&MPLP_REDO_BAQ ) + { + fprintf(bcftools_stderr,"Error: The -B option cannot be combined with -E\n"); + return 1; + } + if (use_orphan) mplp.flag &= ~MPLP_NO_ORPHAN; + if (argc == 1) + { + print_usage(bcftools_stderr, &mplp); + return 1; + } + if (!mplp.fai && !noref) { + fprintf(bcftools_stderr,"Error: mpileup requires the --fasta-ref option by default; use --no-reference to run without a fasta reference\n"); + return 1; + } + int ret,i; + if (file_list) + { + if ( read_file_list(file_list,&nfiles,&fn) ) return 1; + mplp.files = fn; + mplp.nfiles = nfiles; + } + else + { + mplp.nfiles = argc - optind; + mplp.files = (char**) malloc(mplp.nfiles*sizeof(char*)); + for (i=0; i + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +// Code to build this table is below +#ifdef BUILD_MW +#include + +double mann_whitney_1947(int n, int m, int U) +{ + if (U<0) return 0; + if (n==0||m==0) return U==0 ? 1 : 0; + return (double)n/(n+m)*mann_whitney_1947(n-1,m,U-m) + (double)m/(n+m)*mann_whitney_1947(n,m-1,U); +} + +int main(void) { + int i, j, k; + printf("static double mw[6][6][50] = // [2-7][2-7][0-49]\n{\n"); + for (i = 2; i < 8; i++) { + printf(" {\n"); + for (j = 2; j < 8; j++) { + printf(" {\n"); + for (k = 0; k < 50; k++) { + printf(" %.17f,\n", mann_whitney_1947(i,j,k)); + } + printf(" },\n"); + } + printf(" },\n"); + } + printf("};\n"); + return 0; +} +#endif + +static double mw[6][6][50] = // [2-7][2-7][0-49] +{ + { + { + 0.16666666666666666, + 0.16666666666666666, + 0.33333333333333331, + 0.16666666666666666, + 0.16666666666666666, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.09999999999999999, + 0.09999999999999999, + 0.19999999999999998, + 0.20000000000000001, + 0.20000000000000001, + 0.10000000000000001, + 0.10000000000000001, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.06666666666666665, + 0.06666666666666665, + 0.13333333333333330, + 0.13333333333333333, + 0.20000000000000001, + 0.13333333333333333, + 0.13333333333333333, + 0.06666666666666667, + 0.06666666666666667, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.04761904761904761, + 0.04761904761904761, + 0.09523809523809522, + 0.09523809523809523, + 0.14285714285714288, + 0.14285714285714285, + 0.14285714285714285, + 0.09523809523809523, + 0.09523809523809523, + 0.04761904761904762, + 0.04761904761904762, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.03571428571428571, + 0.03571428571428571, + 0.07142857142857141, + 0.07142857142857142, + 0.10714285714285715, + 0.10714285714285714, + 0.14285714285714285, + 0.10714285714285715, + 0.10714285714285715, + 0.07142857142857144, + 0.07142857142857142, + 0.03571428571428571, + 0.03571428571428571, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.02777777777777777, + 0.02777777777777777, + 0.05555555555555555, + 0.05555555555555555, + 0.08333333333333334, + 0.08333333333333333, + 0.11111111111111110, + 0.11111111111111113, + 0.11111111111111113, + 0.08333333333333334, + 0.08333333333333334, + 0.05555555555555556, + 0.05555555555555555, + 0.02777777777777778, + 0.02777777777777778, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + }, + { + { + 0.10000000000000001, + 0.10000000000000001, + 0.20000000000000001, + 0.20000000000000001, + 0.19999999999999998, + 0.09999999999999999, + 0.09999999999999999, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.05000000000000000, + 0.05000000000000000, + 0.10000000000000001, + 0.14999999999999999, + 0.14999999999999999, + 0.14999999999999999, + 0.14999999999999999, + 0.10000000000000001, + 0.05000000000000000, + 0.05000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.02857142857142857, + 0.02857142857142857, + 0.05714285714285714, + 0.08571428571428570, + 0.11428571428571427, + 0.11428571428571427, + 0.14285714285714282, + 0.11428571428571428, + 0.11428571428571428, + 0.08571428571428572, + 0.05714285714285714, + 0.02857142857142857, + 0.02857142857142857, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.01785714285714286, + 0.01785714285714286, + 0.03571428571428571, + 0.05357142857142856, + 0.07142857142857142, + 0.08928571428571427, + 0.10714285714285711, + 0.10714285714285712, + 0.10714285714285714, + 0.10714285714285715, + 0.08928571428571427, + 0.07142857142857142, + 0.05357142857142857, + 0.03571428571428571, + 0.01785714285714286, + 0.01785714285714286, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.01190476190476190, + 0.01190476190476190, + 0.02380952380952381, + 0.03571428571428571, + 0.04761904761904762, + 0.05952380952380951, + 0.08333333333333330, + 0.08333333333333331, + 0.09523809523809523, + 0.09523809523809523, + 0.09523809523809523, + 0.08333333333333333, + 0.08333333333333333, + 0.05952380952380952, + 0.04761904761904762, + 0.03571428571428571, + 0.02380952380952381, + 0.01190476190476190, + 0.01190476190476190, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00833333333333333, + 0.00833333333333333, + 0.01666666666666666, + 0.02499999999999999, + 0.03333333333333333, + 0.04166666666666666, + 0.05833333333333331, + 0.06666666666666665, + 0.07499999999999998, + 0.08333333333333331, + 0.08333333333333331, + 0.08333333333333333, + 0.08333333333333333, + 0.07500000000000000, + 0.06666666666666667, + 0.05833333333333333, + 0.04166666666666666, + 0.03333333333333333, + 0.02500000000000000, + 0.01666666666666667, + 0.00833333333333333, + 0.00833333333333333, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + }, + { + { + 0.06666666666666667, + 0.06666666666666667, + 0.13333333333333333, + 0.13333333333333333, + 0.20000000000000001, + 0.13333333333333333, + 0.13333333333333330, + 0.06666666666666665, + 0.06666666666666665, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.02857142857142857, + 0.02857142857142857, + 0.05714285714285714, + 0.08571428571428572, + 0.11428571428571428, + 0.11428571428571428, + 0.14285714285714282, + 0.11428571428571427, + 0.11428571428571427, + 0.08571428571428570, + 0.05714285714285714, + 0.02857142857142857, + 0.02857142857142857, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.01428571428571429, + 0.01428571428571429, + 0.02857142857142857, + 0.04285714285714286, + 0.07142857142857142, + 0.07142857142857142, + 0.09999999999999998, + 0.09999999999999998, + 0.11428571428571427, + 0.09999999999999998, + 0.09999999999999998, + 0.07142857142857142, + 0.07142857142857142, + 0.04285714285714286, + 0.02857142857142857, + 0.01428571428571429, + 0.01428571428571429, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00793650793650794, + 0.00793650793650794, + 0.01587301587301587, + 0.02380952380952381, + 0.03968253968253968, + 0.04761904761904762, + 0.06349206349206349, + 0.07142857142857142, + 0.08730158730158730, + 0.08730158730158730, + 0.09523809523809522, + 0.08730158730158728, + 0.08730158730158730, + 0.07142857142857142, + 0.06349206349206349, + 0.04761904761904761, + 0.03968253968253968, + 0.02380952380952381, + 0.01587301587301587, + 0.00793650793650794, + 0.00793650793650794, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00476190476190476, + 0.00476190476190476, + 0.00952380952380952, + 0.01428571428571429, + 0.02380952380952381, + 0.02857142857142857, + 0.04285714285714286, + 0.04761904761904762, + 0.06190476190476190, + 0.06666666666666665, + 0.07619047619047617, + 0.07619047619047617, + 0.08571428571428569, + 0.07619047619047617, + 0.07619047619047620, + 0.06666666666666667, + 0.06190476190476191, + 0.04761904761904762, + 0.04285714285714286, + 0.02857142857142857, + 0.02380952380952381, + 0.01428571428571429, + 0.00952380952380952, + 0.00476190476190476, + 0.00476190476190476, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00303030303030303, + 0.00303030303030303, + 0.00606060606060606, + 0.00909090909090909, + 0.01515151515151515, + 0.01818181818181818, + 0.02727272727272727, + 0.03333333333333333, + 0.04242424242424242, + 0.04848484848484847, + 0.05757575757575756, + 0.06060606060606059, + 0.06969696969696967, + 0.06969696969696967, + 0.07272727272727272, + 0.06969696969696969, + 0.06969696969696970, + 0.06060606060606059, + 0.05757575757575757, + 0.04848484848484848, + 0.04242424242424242, + 0.03333333333333333, + 0.02727272727272727, + 0.01818181818181818, + 0.01515151515151515, + 0.00909090909090909, + 0.00606060606060606, + 0.00303030303030303, + 0.00303030303030303, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + }, + { + { + 0.04761904761904762, + 0.04761904761904762, + 0.09523809523809523, + 0.09523809523809523, + 0.14285714285714285, + 0.14285714285714285, + 0.14285714285714288, + 0.09523809523809523, + 0.09523809523809522, + 0.04761904761904761, + 0.04761904761904761, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.01785714285714286, + 0.01785714285714286, + 0.03571428571428571, + 0.05357142857142857, + 0.07142857142857142, + 0.08928571428571427, + 0.10714285714285715, + 0.10714285714285714, + 0.10714285714285712, + 0.10714285714285711, + 0.08928571428571427, + 0.07142857142857142, + 0.05357142857142856, + 0.03571428571428571, + 0.01785714285714286, + 0.01785714285714286, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00793650793650794, + 0.00793650793650794, + 0.01587301587301587, + 0.02380952380952381, + 0.03968253968253968, + 0.04761904761904761, + 0.06349206349206349, + 0.07142857142857142, + 0.08730158730158730, + 0.08730158730158728, + 0.09523809523809522, + 0.08730158730158730, + 0.08730158730158730, + 0.07142857142857142, + 0.06349206349206349, + 0.04761904761904762, + 0.03968253968253968, + 0.02380952380952381, + 0.01587301587301587, + 0.00793650793650794, + 0.00793650793650794, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00396825396825397, + 0.00396825396825397, + 0.00793650793650794, + 0.01190476190476190, + 0.01984126984126984, + 0.02777777777777777, + 0.03571428571428571, + 0.04365079365079365, + 0.05555555555555555, + 0.06349206349206349, + 0.07142857142857142, + 0.07539682539682539, + 0.07936507936507936, + 0.07936507936507936, + 0.07539682539682539, + 0.07142857142857142, + 0.06349206349206349, + 0.05555555555555555, + 0.04365079365079365, + 0.03571428571428571, + 0.02777777777777777, + 0.01984126984126984, + 0.01190476190476190, + 0.00793650793650794, + 0.00396825396825397, + 0.00396825396825397, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00216450216450216, + 0.00216450216450216, + 0.00432900432900433, + 0.00649350649350649, + 0.01082251082251082, + 0.01515151515151515, + 0.02164502164502164, + 0.02597402597402597, + 0.03463203463203463, + 0.04112554112554112, + 0.04978354978354978, + 0.05411255411255411, + 0.06277056277056275, + 0.06493506493506493, + 0.06926406926406925, + 0.06926406926406925, + 0.06926406926406925, + 0.06493506493506492, + 0.06277056277056275, + 0.05411255411255410, + 0.04978354978354978, + 0.04112554112554112, + 0.03463203463203463, + 0.02597402597402597, + 0.02164502164502164, + 0.01515151515151515, + 0.01082251082251082, + 0.00649350649350649, + 0.00432900432900433, + 0.00216450216450216, + 0.00216450216450216, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00126262626262626, + 0.00126262626262626, + 0.00252525252525253, + 0.00378787878787879, + 0.00631313131313131, + 0.00883838383838384, + 0.01262626262626262, + 0.01641414141414141, + 0.02146464646464646, + 0.02651515151515151, + 0.03282828282828283, + 0.03787878787878787, + 0.04419191919191919, + 0.04924242424242424, + 0.05429292929292929, + 0.05808080808080808, + 0.06060606060606059, + 0.06186868686868686, + 0.06186868686868686, + 0.06060606060606059, + 0.05808080808080807, + 0.05429292929292930, + 0.04924242424242424, + 0.04419191919191920, + 0.03787878787878787, + 0.03282828282828282, + 0.02651515151515152, + 0.02146464646464646, + 0.01641414141414142, + 0.01262626262626263, + 0.00883838383838384, + 0.00631313131313131, + 0.00378787878787879, + 0.00252525252525253, + 0.00126262626262626, + 0.00126262626262626, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + }, + { + { + 0.03571428571428571, + 0.03571428571428571, + 0.07142857142857142, + 0.07142857142857144, + 0.10714285714285715, + 0.10714285714285715, + 0.14285714285714285, + 0.10714285714285714, + 0.10714285714285715, + 0.07142857142857142, + 0.07142857142857141, + 0.03571428571428571, + 0.03571428571428571, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.01190476190476190, + 0.01190476190476190, + 0.02380952380952381, + 0.03571428571428571, + 0.04761904761904762, + 0.05952380952380952, + 0.08333333333333333, + 0.08333333333333333, + 0.09523809523809523, + 0.09523809523809523, + 0.09523809523809523, + 0.08333333333333331, + 0.08333333333333330, + 0.05952380952380951, + 0.04761904761904762, + 0.03571428571428571, + 0.02380952380952381, + 0.01190476190476190, + 0.01190476190476190, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00476190476190476, + 0.00476190476190476, + 0.00952380952380952, + 0.01428571428571429, + 0.02380952380952381, + 0.02857142857142857, + 0.04285714285714286, + 0.04761904761904762, + 0.06190476190476191, + 0.06666666666666667, + 0.07619047619047620, + 0.07619047619047617, + 0.08571428571428569, + 0.07619047619047617, + 0.07619047619047617, + 0.06666666666666665, + 0.06190476190476190, + 0.04761904761904762, + 0.04285714285714286, + 0.02857142857142857, + 0.02380952380952381, + 0.01428571428571429, + 0.00952380952380952, + 0.00476190476190476, + 0.00476190476190476, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00216450216450216, + 0.00216450216450216, + 0.00432900432900433, + 0.00649350649350649, + 0.01082251082251082, + 0.01515151515151515, + 0.02164502164502164, + 0.02597402597402597, + 0.03463203463203463, + 0.04112554112554112, + 0.04978354978354978, + 0.05411255411255410, + 0.06277056277056275, + 0.06493506493506492, + 0.06926406926406925, + 0.06926406926406925, + 0.06926406926406925, + 0.06493506493506493, + 0.06277056277056275, + 0.05411255411255411, + 0.04978354978354978, + 0.04112554112554112, + 0.03463203463203463, + 0.02597402597402597, + 0.02164502164502164, + 0.01515151515151515, + 0.01082251082251082, + 0.00649350649350649, + 0.00432900432900433, + 0.00216450216450216, + 0.00216450216450216, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00108225108225108, + 0.00108225108225108, + 0.00216450216450216, + 0.00324675324675325, + 0.00541125541125541, + 0.00757575757575758, + 0.01190476190476190, + 0.01406926406926407, + 0.01948051948051948, + 0.02380952380952381, + 0.03030303030303030, + 0.03463203463203463, + 0.04220779220779219, + 0.04545454545454544, + 0.05194805194805194, + 0.05519480519480519, + 0.05952380952380951, + 0.05952380952380952, + 0.06277056277056275, + 0.05952380952380952, + 0.05952380952380951, + 0.05519480519480519, + 0.05194805194805194, + 0.04545454545454544, + 0.04220779220779219, + 0.03463203463203463, + 0.03030303030303030, + 0.02380952380952381, + 0.01948051948051948, + 0.01406926406926407, + 0.01190476190476190, + 0.00757575757575758, + 0.00541125541125541, + 0.00324675324675325, + 0.00216450216450216, + 0.00108225108225108, + 0.00108225108225108, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00058275058275058, + 0.00058275058275058, + 0.00116550116550117, + 0.00174825174825175, + 0.00291375291375291, + 0.00407925407925408, + 0.00641025641025641, + 0.00815850815850816, + 0.01107226107226107, + 0.01398601398601398, + 0.01806526806526806, + 0.02156177156177156, + 0.02680652680652679, + 0.03030303030303030, + 0.03554778554778554, + 0.03962703962703962, + 0.04428904428904428, + 0.04720279720279720, + 0.05128205128205127, + 0.05244755244755244, + 0.05477855477855477, + 0.05477855477855477, + 0.05477855477855477, + 0.05244755244755243, + 0.05128205128205127, + 0.04720279720279720, + 0.04428904428904428, + 0.03962703962703962, + 0.03554778554778555, + 0.03030303030303030, + 0.02680652680652681, + 0.02156177156177156, + 0.01806526806526806, + 0.01398601398601399, + 0.01107226107226107, + 0.00815850815850816, + 0.00641025641025641, + 0.00407925407925408, + 0.00291375291375291, + 0.00174825174825175, + 0.00116550116550117, + 0.00058275058275058, + 0.00058275058275058, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + }, + { + { + 0.02777777777777778, + 0.02777777777777778, + 0.05555555555555555, + 0.05555555555555556, + 0.08333333333333334, + 0.08333333333333334, + 0.11111111111111113, + 0.11111111111111113, + 0.11111111111111110, + 0.08333333333333333, + 0.08333333333333334, + 0.05555555555555555, + 0.05555555555555555, + 0.02777777777777777, + 0.02777777777777777, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00833333333333333, + 0.00833333333333333, + 0.01666666666666667, + 0.02500000000000000, + 0.03333333333333333, + 0.04166666666666666, + 0.05833333333333333, + 0.06666666666666667, + 0.07500000000000000, + 0.08333333333333333, + 0.08333333333333333, + 0.08333333333333331, + 0.08333333333333331, + 0.07499999999999998, + 0.06666666666666665, + 0.05833333333333331, + 0.04166666666666666, + 0.03333333333333333, + 0.02499999999999999, + 0.01666666666666666, + 0.00833333333333333, + 0.00833333333333333, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00303030303030303, + 0.00303030303030303, + 0.00606060606060606, + 0.00909090909090909, + 0.01515151515151515, + 0.01818181818181818, + 0.02727272727272727, + 0.03333333333333333, + 0.04242424242424242, + 0.04848484848484848, + 0.05757575757575757, + 0.06060606060606059, + 0.06969696969696970, + 0.06969696969696969, + 0.07272727272727272, + 0.06969696969696967, + 0.06969696969696967, + 0.06060606060606059, + 0.05757575757575756, + 0.04848484848484847, + 0.04242424242424242, + 0.03333333333333333, + 0.02727272727272727, + 0.01818181818181818, + 0.01515151515151515, + 0.00909090909090909, + 0.00606060606060606, + 0.00303030303030303, + 0.00303030303030303, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00126262626262626, + 0.00126262626262626, + 0.00252525252525253, + 0.00378787878787879, + 0.00631313131313131, + 0.00883838383838384, + 0.01262626262626263, + 0.01641414141414142, + 0.02146464646464646, + 0.02651515151515152, + 0.03282828282828282, + 0.03787878787878787, + 0.04419191919191920, + 0.04924242424242424, + 0.05429292929292930, + 0.05808080808080807, + 0.06060606060606059, + 0.06186868686868686, + 0.06186868686868686, + 0.06060606060606059, + 0.05808080808080808, + 0.05429292929292929, + 0.04924242424242424, + 0.04419191919191919, + 0.03787878787878787, + 0.03282828282828283, + 0.02651515151515151, + 0.02146464646464646, + 0.01641414141414141, + 0.01262626262626262, + 0.00883838383838384, + 0.00631313131313131, + 0.00378787878787879, + 0.00252525252525253, + 0.00126262626262626, + 0.00126262626262626, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00058275058275058, + 0.00058275058275058, + 0.00116550116550117, + 0.00174825174825175, + 0.00291375291375291, + 0.00407925407925408, + 0.00641025641025641, + 0.00815850815850816, + 0.01107226107226107, + 0.01398601398601399, + 0.01806526806526806, + 0.02156177156177156, + 0.02680652680652681, + 0.03030303030303030, + 0.03554778554778555, + 0.03962703962703962, + 0.04428904428904428, + 0.04720279720279720, + 0.05128205128205127, + 0.05244755244755243, + 0.05477855477855477, + 0.05477855477855477, + 0.05477855477855477, + 0.05244755244755244, + 0.05128205128205127, + 0.04720279720279720, + 0.04428904428904428, + 0.03962703962703962, + 0.03554778554778554, + 0.03030303030303030, + 0.02680652680652679, + 0.02156177156177156, + 0.01806526806526806, + 0.01398601398601398, + 0.01107226107226107, + 0.00815850815850816, + 0.00641025641025641, + 0.00407925407925408, + 0.00291375291375291, + 0.00174825174825175, + 0.00116550116550117, + 0.00058275058275058, + 0.00058275058275058, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + 0.00000000000000000, + }, + { + 0.00029137529137529, + 0.00029137529137529, + 0.00058275058275058, + 0.00087412587412587, + 0.00145687645687646, + 0.00203962703962704, + 0.00320512820512821, + 0.00437062937062937, + 0.00582750582750583, + 0.00757575757575758, + 0.00990675990675991, + 0.01223776223776224, + 0.01544289044289044, + 0.01835664335664336, + 0.02185314685314686, + 0.02534965034965035, + 0.02913752913752913, + 0.03263403263403263, + 0.03642191142191141, + 0.03962703962703962, + 0.04254079254079253, + 0.04516317016317015, + 0.04720279720279719, + 0.04836829836829836, + 0.04924242424242423, + 0.04924242424242423, + 0.04836829836829836, + 0.04720279720279719, + 0.04516317016317015, + 0.04254079254079253, + 0.03962703962703962, + 0.03642191142191141, + 0.03263403263403263, + 0.02913752913752913, + 0.02534965034965035, + 0.02185314685314686, + 0.01835664335664336, + 0.01544289044289044, + 0.01223776223776224, + 0.00990675990675991, + 0.00757575757575758, + 0.00582750582750583, + 0.00437062937062937, + 0.00320512820512821, + 0.00203962703962704, + 0.00145687645687646, + 0.00087412587412587, + 0.00058275058275058, + 0.00029137529137529, + 0.00029137529137529, + }, + }, +}; diff --git a/bcftools/ploidy.c b/bcftools/ploidy.c index 719e1753c..550ba876c 100644 --- a/bcftools/ploidy.c +++ b/bcftools/ploidy.c @@ -1,4 +1,4 @@ -/* +/* Copyright (C) 2014-2016 Genome Research Ltd. Author: Petr Danecek @@ -22,7 +22,6 @@ THE SOFTWARE. */ -#include #include #include #include @@ -35,6 +34,7 @@ struct _ploidy_t int dflt, min, max; // ploidy: default, min and max (only explicitly listed) int *sex2dflt; regidx_t *idx; + regitr_t *itr; void *sex2id; char **id2sex; kstring_t tmp_str; @@ -52,7 +52,7 @@ regidx_t *ploidy_regions(ploidy_t *ploidy) return ploidy->idx; } -int ploidy_parse(const char *line, char **chr_beg, char **chr_end, reg_t *reg, void *payload, void *usr) +int ploidy_parse(const char *line, char **chr_beg, char **chr_end, uint32_t *beg, uint32_t *end, void *payload, void *usr) { int i, ret; ploidy_t *ploidy = (ploidy_t*) usr; @@ -68,7 +68,7 @@ int ploidy_parse(const char *line, char **chr_beg, char **chr_end, reg_t *reg, v else { // Fill CHR,FROM,TO - ret = regidx_parse_tab(line,chr_beg,chr_end,reg,NULL,NULL); + ret = regidx_parse_tab(line,chr_beg,chr_end,beg,end,NULL,NULL); if ( ret!=0 ) return ret; } @@ -144,6 +144,7 @@ ploidy_t *ploidy_init(const char *fname, int dflt) ploidy_destroy(pld); return NULL; } + pld->itr = regitr_init(pld->idx); _set_defaults(pld,dflt); return pld; } @@ -156,6 +157,7 @@ ploidy_t *ploidy_init_string(const char *str, int dflt) pld->min = pld->max = -1; pld->sex2id = khash_str2int_init(); pld->idx = regidx_init(NULL,ploidy_parse,NULL,sizeof(sex_ploidy_t),pld); + pld->itr = regitr_init(pld->idx); kstring_t tmp = {0,0,0}; const char *ss = str; @@ -170,7 +172,6 @@ ploidy_t *ploidy_init_string(const char *str, int dflt) while ( *se && isspace(*se) ) se++; ss = se; } - regidx_insert(pld->idx,NULL); free(tmp.s); _set_defaults(pld,dflt); @@ -180,6 +181,7 @@ ploidy_t *ploidy_init_string(const char *str, int dflt) void ploidy_destroy(ploidy_t *ploidy) { if ( ploidy->sex2id ) khash_str2int_destroy_free(ploidy->sex2id); + if ( ploidy->itr ) regitr_destroy(ploidy->itr); if ( ploidy->idx ) regidx_destroy(ploidy->idx); free(ploidy->id2sex); free(ploidy->tmp_str.s); @@ -189,8 +191,7 @@ void ploidy_destroy(ploidy_t *ploidy) int ploidy_query(ploidy_t *ploidy, char *seq, int pos, int *sex2ploidy, int *min, int *max) { - regitr_t itr; - int i, ret = regidx_overlap(ploidy->idx, seq,pos,pos, &itr); + int i, ret = regidx_overlap(ploidy->idx, seq,pos,pos, ploidy->itr); if ( !sex2ploidy && !min && !max ) return ret; @@ -207,17 +208,16 @@ int ploidy_query(ploidy_t *ploidy, char *seq, int pos, int *sex2ploidy, int *min int _min = INT_MAX, _max = -1; if ( sex2ploidy ) for (i=0; insex; i++) sex2ploidy[i] = ploidy->dflt; - while ( REGITR_OVERLAP(itr,pos,pos) ) + while ( regitr_overlap(ploidy->itr) ) { - int sex = REGITR_PAYLOAD(itr,sex_ploidy_t).sex; - int pld = REGITR_PAYLOAD(itr,sex_ploidy_t).ploidy; + int sex = regitr_payload(ploidy->itr,sex_ploidy_t).sex; + int pld = regitr_payload(ploidy->itr,sex_ploidy_t).ploidy; if ( pld!=ploidy->dflt ) { if ( sex2ploidy ) sex2ploidy[ sex ] = pld; if ( _min > pld ) _min = pld; if ( _max < pld ) _max = pld; } - itr.i++; } if ( _max==-1 ) _max = _min = ploidy->dflt; if ( max ) *max = _max; diff --git a/bcftools/ploidy.c.pysam.c b/bcftools/ploidy.c.pysam.c index d0468b9f9..aee0c5675 100644 --- a/bcftools/ploidy.c.pysam.c +++ b/bcftools/ploidy.c.pysam.c @@ -1,6 +1,6 @@ -#include "pysam.h" +#include "bcftools.pysam.h" -/* +/* Copyright (C) 2014-2016 Genome Research Ltd. Author: Petr Danecek @@ -24,7 +24,6 @@ THE SOFTWARE. */ -#include #include #include #include @@ -37,6 +36,7 @@ struct _ploidy_t int dflt, min, max; // ploidy: default, min and max (only explicitly listed) int *sex2dflt; regidx_t *idx; + regitr_t *itr; void *sex2id; char **id2sex; kstring_t tmp_str; @@ -54,7 +54,7 @@ regidx_t *ploidy_regions(ploidy_t *ploidy) return ploidy->idx; } -int ploidy_parse(const char *line, char **chr_beg, char **chr_end, reg_t *reg, void *payload, void *usr) +int ploidy_parse(const char *line, char **chr_beg, char **chr_end, uint32_t *beg, uint32_t *end, void *payload, void *usr) { int i, ret; ploidy_t *ploidy = (ploidy_t*) usr; @@ -70,7 +70,7 @@ int ploidy_parse(const char *line, char **chr_beg, char **chr_end, reg_t *reg, v else { // Fill CHR,FROM,TO - ret = regidx_parse_tab(line,chr_beg,chr_end,reg,NULL,NULL); + ret = regidx_parse_tab(line,chr_beg,chr_end,beg,end,NULL,NULL); if ( ret!=0 ) return ret; } @@ -146,6 +146,7 @@ ploidy_t *ploidy_init(const char *fname, int dflt) ploidy_destroy(pld); return NULL; } + pld->itr = regitr_init(pld->idx); _set_defaults(pld,dflt); return pld; } @@ -158,6 +159,7 @@ ploidy_t *ploidy_init_string(const char *str, int dflt) pld->min = pld->max = -1; pld->sex2id = khash_str2int_init(); pld->idx = regidx_init(NULL,ploidy_parse,NULL,sizeof(sex_ploidy_t),pld); + pld->itr = regitr_init(pld->idx); kstring_t tmp = {0,0,0}; const char *ss = str; @@ -172,7 +174,6 @@ ploidy_t *ploidy_init_string(const char *str, int dflt) while ( *se && isspace(*se) ) se++; ss = se; } - regidx_insert(pld->idx,NULL); free(tmp.s); _set_defaults(pld,dflt); @@ -182,6 +183,7 @@ ploidy_t *ploidy_init_string(const char *str, int dflt) void ploidy_destroy(ploidy_t *ploidy) { if ( ploidy->sex2id ) khash_str2int_destroy_free(ploidy->sex2id); + if ( ploidy->itr ) regitr_destroy(ploidy->itr); if ( ploidy->idx ) regidx_destroy(ploidy->idx); free(ploidy->id2sex); free(ploidy->tmp_str.s); @@ -191,8 +193,7 @@ void ploidy_destroy(ploidy_t *ploidy) int ploidy_query(ploidy_t *ploidy, char *seq, int pos, int *sex2ploidy, int *min, int *max) { - regitr_t itr; - int i, ret = regidx_overlap(ploidy->idx, seq,pos,pos, &itr); + int i, ret = regidx_overlap(ploidy->idx, seq,pos,pos, ploidy->itr); if ( !sex2ploidy && !min && !max ) return ret; @@ -209,17 +210,16 @@ int ploidy_query(ploidy_t *ploidy, char *seq, int pos, int *sex2ploidy, int *min int _min = INT_MAX, _max = -1; if ( sex2ploidy ) for (i=0; insex; i++) sex2ploidy[i] = ploidy->dflt; - while ( REGITR_OVERLAP(itr,pos,pos) ) + while ( regitr_overlap(ploidy->itr) ) { - int sex = REGITR_PAYLOAD(itr,sex_ploidy_t).sex; - int pld = REGITR_PAYLOAD(itr,sex_ploidy_t).ploidy; + int sex = regitr_payload(ploidy->itr,sex_ploidy_t).sex; + int pld = regitr_payload(ploidy->itr,sex_ploidy_t).ploidy; if ( pld!=ploidy->dflt ) { if ( sex2ploidy ) sex2ploidy[ sex ] = pld; if ( _min > pld ) _min = pld; if ( _max < pld ) _max = pld; } - itr.i++; } if ( _max==-1 ) _max = _min = ploidy->dflt; if ( max ) *max = _max; diff --git a/bcftools/ploidy.h b/bcftools/ploidy.h index 6deef737f..1e7d2f78f 100644 --- a/bcftools/ploidy.h +++ b/bcftools/ploidy.h @@ -55,7 +55,7 @@ #ifndef __PLOIDY_H__ #define __PLOIDY_H__ -#include +#include "regidx.h" typedef struct _ploidy_t ploidy_t; diff --git a/bcftools/prob1.c b/bcftools/prob1.c index 8f4463ff5..954d43cf7 100644 --- a/bcftools/prob1.c +++ b/bcftools/prob1.c @@ -157,8 +157,9 @@ int test16(bcf1_t *b, anno16_t *a); static int cal_pdg(const bcf1_t *b, bcf_p1aux_t *ma) { int i, j; - long *p, tmp; - p = (long*) alloca(b->n_allele * sizeof(long)); + long p_a[16], *p=p_a, tmp; + if (b->n_allele > 16) + p = (long*) malloc(b->n_allele * sizeof(long)); memset(p, 0, sizeof(long) * b->n_allele); // Set P(D|g) for each sample and sum phread likelihoods across all samples to create lk @@ -177,12 +178,14 @@ static int cal_pdg(const bcf1_t *b, bcf_p1aux_t *ma) tmp = p[j], p[j] = p[j-1], p[j-1] = tmp; for (i = b->n_allele - 1; i >= 0; --i) if ((p[i]&0xf) == 0) break; + if (p != p_a) + free(p); return i; } -/* f0 is minor allele fraction */ -int bcf_p1_call_gt(const bcf_p1aux_t *ma, double f0, int k) +/* f0 is freq of the ref allele */ +int bcf_p1_call_gt(const bcf_p1aux_t *ma, double f0, int k, int is_var) { double sum, g[3]; double max, f3[3], *pdg = ma->pdg + k * 3; @@ -203,6 +206,7 @@ int bcf_p1_call_gt(const bcf_p1aux_t *ma, double f0, int k) g[i] /= sum; if (g[i] > max) max = g[i], max_i = i; } + if ( !is_var ) { max_i = 2; max = g[2]; } // force 0/0 genotype if the site is non-variant max = 1. - max; if (max < 1e-308) max = 1e-308; q = (int)(-4.343 * log(max) + .499); diff --git a/bcftools/prob1.c.pysam.c b/bcftools/prob1.c.pysam.c index a59ec44c3..bd73e1d5b 100644 --- a/bcftools/prob1.c.pysam.c +++ b/bcftools/prob1.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* prob1.c -- mathematical utility functions. @@ -128,7 +128,7 @@ int bcf_p1_set_n1(bcf_p1aux_t *b, int n1) { if (n1 == 0 || n1 >= b->n) return -1; if (b->M != b->n * 2) { - fprintf(pysam_stderr, "[%s] unable to set `n1' when there are haploid samples.\n", __func__); + fprintf(bcftools_stderr, "[%s] unable to set `n1' when there are haploid samples.\n", __func__); return -1; } b->n1 = n1; @@ -159,8 +159,9 @@ int test16(bcf1_t *b, anno16_t *a); static int cal_pdg(const bcf1_t *b, bcf_p1aux_t *ma) { int i, j; - long *p, tmp; - p = (long*) alloca(b->n_allele * sizeof(long)); + long p_a[16], *p=p_a, tmp; + if (b->n_allele > 16) + p = (long*) malloc(b->n_allele * sizeof(long)); memset(p, 0, sizeof(long) * b->n_allele); // Set P(D|g) for each sample and sum phread likelihoods across all samples to create lk @@ -179,12 +180,14 @@ static int cal_pdg(const bcf1_t *b, bcf_p1aux_t *ma) tmp = p[j], p[j] = p[j-1], p[j-1] = tmp; for (i = b->n_allele - 1; i >= 0; --i) if ((p[i]&0xf) == 0) break; + if (p != p_a) + free(p); return i; } -/* f0 is minor allele fraction */ -int bcf_p1_call_gt(const bcf_p1aux_t *ma, double f0, int k) +/* f0 is freq of the ref allele */ +int bcf_p1_call_gt(const bcf_p1aux_t *ma, double f0, int k, int is_var) { double sum, g[3]; double max, f3[3], *pdg = ma->pdg + k * 3; @@ -205,6 +208,7 @@ int bcf_p1_call_gt(const bcf_p1aux_t *ma, double f0, int k) g[i] /= sum; if (g[i] > max) max = g[i], max_i = i; } + if ( !is_var ) { max_i = 2; max = g[2]; } // force 0/0 genotype if the site is non-variant max = 1. - max; if (max < 1e-308) max = 1e-308; q = (int)(-4.343 * log(max) + .499); @@ -523,9 +527,9 @@ int bcf_p1_cal(call_t *call, bcf1_t *b, int do_contrast, bcf_p1aux_t *ma, bcf_p1 void bcf_p1_dump_afs(bcf_p1aux_t *ma) { int k; - fprintf(pysam_stderr, "[afs]"); + fprintf(bcftools_stderr, "[afs]"); for (k = 0; k <= ma->M; ++k) - fprintf(pysam_stderr, " %d:%.3lf", k, ma->afs[ma->M - k]); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, " %d:%.3lf", k, ma->afs[ma->M - k]); + fprintf(bcftools_stderr, "\n"); memset(ma->afs, 0, sizeof(double) * (ma->M + 1)); } diff --git a/bcftools/prob1.h b/bcftools/prob1.h index 1594d3f34..a3d4b0d7b 100644 --- a/bcftools/prob1.h +++ b/bcftools/prob1.h @@ -78,7 +78,7 @@ extern "C" { void bcf_p1_destroy(bcf_p1aux_t *ma); void bcf_p1_set_ploidy(bcf1_t *b, bcf_p1aux_t *ma); int bcf_p1_cal(call_t *call, bcf1_t *b, int do_contrast, bcf_p1aux_t *ma, bcf_p1rst_t *rst); - int bcf_p1_call_gt(const bcf_p1aux_t *ma, double f0, int k); + int bcf_p1_call_gt(const bcf_p1aux_t *ma, double f0, int k, int is_var); void bcf_p1_dump_afs(bcf_p1aux_t *ma); int bcf_p1_read_prior(bcf_p1aux_t *ma, const char *fn); int bcf_p1_set_n1(bcf_p1aux_t *b, int n1); diff --git a/bcftools/pysam.h b/bcftools/pysam.h deleted file mode 100644 index b0fc4fb56..000000000 --- a/bcftools/pysam.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef PYSAM_H -#define PYSAM_H -#include "stdio.h" -extern FILE * pysam_stderr; -extern FILE * pysam_stdout; -extern const char * pysam_stdout_fn; -#endif diff --git a/bcftools/rbuf.h b/bcftools/rbuf.h index 3d2805c77..2c0e5b1f7 100644 --- a/bcftools/rbuf.h +++ b/bcftools/rbuf.h @@ -46,11 +46,16 @@ static inline void rbuf_init(rbuf_t *rbuf, int size) /** * rbuf_kth() - get index of the k-th element of the round buffer * @rbuf: the rbuf_t holder - * @k: 0-based index + * @k: 0-based index. If negative, return k-th element from the end, 1-based */ static inline int rbuf_kth(rbuf_t *rbuf, int k) { - if ( k >= rbuf->n || k<0 ) return -1; + if ( k >= rbuf->n ) return -1; + if ( k < 0 ) + { + k = rbuf->n + k; + if ( k < 0 ) return -1; + } int i = k + rbuf->f; if ( i >= rbuf->m ) i -= rbuf->m; return i; @@ -58,9 +63,29 @@ static inline int rbuf_kth(rbuf_t *rbuf, int k) /** * rbuf_last() - get index of the last element of the round buffer * @rbuf: the rbuf_t holder + */ +#define rbuf_last(rbuf) rbuf_kth(rbuf, -1) + +/** + * rbuf_l2ridx() - get 0-based rbuf index which corresponds to i-th linear index + * @rbuf: the rbuf_t holder + * @idx: 0-based linear index * + * Returns 0-based circular index or -1 if out of bounds */ -#define rbuf_last(rbuf) rbuf_kth(rbuf, (rbuf)->n - 1) +static inline int rbuf_l2ridx(rbuf_t *rbuf, int idx) +{ + if ( idx < 0 || idx >= rbuf->n ) return -1; + if ( idx >= rbuf->f ) + { + int i = idx - rbuf->f; + if ( i >= rbuf->n ) return -1; + return i; + } + int i = rbuf->m - rbuf->f + idx; + if ( i >= rbuf->n ) return -1; + return i; +} /** * rbuf_next() - get index of the next element in the round buffer @@ -198,4 +223,39 @@ static inline void rbuf_shift_n(rbuf_t *rbuf, int n) } \ } +/** + * rbuf_remove_kth() - remove k-th rbuf element (0-based) and memmove the data block + * @rbuf: the rbuf holder + * @type_t: data type + * @k: k-th element to remove + * @data: data array to be modified + */ +#define rbuf_remove_kth(rbuf, type_t, kth, data) \ +{ \ + int k = rbuf_kth(rbuf, kth); \ + if ( k < (rbuf)->f ) /* shrink from back */ \ + { \ + int l = rbuf_kth(rbuf, -1); \ + if ( k < l ) \ + { \ + type_t tmp = (data)[k]; \ + memmove(data+k, data+k+1, (l - k)*sizeof(type_t)); \ + (data)[l] = tmp; \ + } \ + (rbuf)->n--; \ + } \ + else /* shrink from front */ \ + { \ + if ( k > (rbuf)->f ) \ + { \ + type_t tmp = (data)[k]; \ + memmove(&data[(rbuf)->f+1], &data[(rbuf)->f], (k - (rbuf)->f)*sizeof(type_t)); \ + (data)[(rbuf)->f] = tmp; \ + } \ + (rbuf)->f++; \ + (rbuf)->n--; \ + if ( (rbuf)->f == (rbuf)->m ) (rbuf)->f = 0; \ + } \ +} + #endif diff --git a/bcftools/regidx.c b/bcftools/regidx.c new file mode 100644 index 000000000..9b2c66d71 --- /dev/null +++ b/bcftools/regidx.c @@ -0,0 +1,636 @@ +/* + Copyright (C) 2014-2017 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include +#include +#include +#include +#include +#include "regidx.h" + +#define MAX_COOR_0 REGIDX_MAX // CSI and hts_itr_query limit, 0-based + +#define iBIN(x) ((x)>>13) + +typedef struct +{ + uint32_t beg, end; +} +reg_t; + +typedef struct +{ + uint32_t pos, ireg; // y-coordinate and a pointer to reglist.reg and reglist.dat +} +pos_t; + +typedef struct _reglist_t reglist_t; + +typedef struct +{ + uint32_t beg, end, ireg; // query coordinates and the active region + regidx_t *ridx; + reglist_t *list; + int active; +} +_itr_t; + +// List of regions for one chromosome. +struct _reglist_t +{ + uint32_t *idx, nidx; // index to list.reg+1 + uint32_t nreg, mreg; // n:used, m:allocated + reg_t *reg; // regions + void *dat; // payload data + char *seq; // sequence name + int unsorted; + +}; + +// Container of all sequences +struct _regidx_t +{ + int nseq, mseq; // n:used, m:alloced + reglist_t *seq; // regions for each sequence + void *seq2regs; // hash for fast lookup from chr name to regions + char **seq_names; + regidx_free_f free; // function to free any data allocated by regidx_parse_f + regidx_parse_f parse; // parse one input line + void *usr; // user data to pass to regidx_parse_f + int payload_size; + void *payload; // temporary payload data set by regidx_parse_f (sequence is not known beforehand) + kstring_t str; +}; + +int regidx_seq_nregs(regidx_t *idx, const char *seq) +{ + int iseq; + if ( khash_str2int_get(idx->seq2regs, seq, &iseq)!=0 ) return 0; // no such sequence + return idx->seq[iseq].nreg; +} + +int regidx_nregs(regidx_t *idx) +{ + int i, nreg = 0; + for (i=0; inseq; i++) nreg += idx->seq[i].nreg; + return nreg; +} + +char **regidx_seq_names(regidx_t *idx, int *n) +{ + *n = idx->nseq; + return idx->seq_names; +} + +int regidx_insert_list(regidx_t *idx, char *line, char delim) +{ + kstring_t tmp = {0,0,0}; + char *ss = line; + while ( *ss ) + { + char *se = ss; + while ( *se && *se!=delim ) se++; + tmp.l = 0; + kputsn(ss, se-ss, &tmp); + if ( regidx_insert(idx,tmp.s) < 0 ) + { + free(tmp.s); + return -1; + } + if ( !*se ) break; + ss = se+1; + } + free(tmp.s); + return 0; +} + +static inline int cmp_regs(reg_t *a, reg_t *b) +{ + if ( a->beg < b->beg ) return -1; + if ( a->beg > b->beg ) return 1; + if ( a->end < b->end ) return 1; // longer intervals come first + if ( a->end > b->end ) return -1; + return 0; +} +static int cmp_reg_ptrs(const void *a, const void *b) +{ + return cmp_regs((reg_t*)a,(reg_t*)b); +} +static int cmp_reg_ptrs2(const void *a, const void *b) +{ + return cmp_regs(*((reg_t**)a),*((reg_t**)b)); +} + +inline int regidx_push(regidx_t *idx, char *chr_beg, char *chr_end, uint32_t beg, uint32_t end, void *payload) +{ + if ( beg > MAX_COOR_0 ) beg = MAX_COOR_0; + if ( end > MAX_COOR_0 ) end = MAX_COOR_0; + + int rid; + idx->str.l = 0; + kputsn(chr_beg, chr_end-chr_beg+1, &idx->str); + if ( khash_str2int_get(idx->seq2regs, idx->str.s, &rid)!=0 ) + { + // new chromosome + idx->nseq++; + int m_prev = idx->mseq; + hts_expand0(reglist_t,idx->nseq,idx->mseq,idx->seq); + hts_expand0(char*,idx->nseq,m_prev,idx->seq_names); + idx->seq_names[idx->nseq-1] = strdup(idx->str.s); + rid = khash_str2int_inc(idx->seq2regs, idx->seq_names[idx->nseq-1]); + } + + reglist_t *list = &idx->seq[rid]; + list->seq = idx->seq_names[rid]; + list->nreg++; + int mreg = list->mreg; + hts_expand(reg_t,list->nreg,list->mreg,list->reg); + list->reg[list->nreg-1].beg = beg; + list->reg[list->nreg-1].end = end; + if ( idx->payload_size ) + { + if ( mreg != list->mreg ) list->dat = realloc(list->dat,idx->payload_size*list->mreg); + memcpy((char *)list->dat + idx->payload_size*(list->nreg-1), payload, idx->payload_size); + } + if ( !list->unsorted && list->nreg>1 && cmp_regs(&list->reg[list->nreg-2],&list->reg[list->nreg-1])>0 ) list->unsorted = 1; + return 0; +} + +int regidx_insert(regidx_t *idx, char *line) +{ + if ( !line ) return 0; + char *chr_from, *chr_to; + uint32_t beg,end; + int ret = idx->parse(line,&chr_from,&chr_to,&beg,&end,idx->payload,idx->usr); + if ( ret==-2 ) return -1; // error + if ( ret==-1 ) return 0; // skip the line + regidx_push(idx, chr_from,chr_to,beg,end,idx->payload); + return 0; +} + +regidx_t *regidx_init_string(const char *str, regidx_parse_f parser, regidx_free_f free_f, size_t payload_size, void *usr_dat) +{ + regidx_t *idx = (regidx_t*) calloc(1,sizeof(regidx_t)); + if ( !idx ) return NULL; + + idx->free = free_f; + idx->parse = parser ? parser : regidx_parse_tab; + idx->usr = usr_dat; + idx->seq2regs = khash_str2int_init(); + idx->payload_size = payload_size; + if ( payload_size ) idx->payload = malloc(payload_size); + + kstring_t tmp = {0,0,0}; + const char *ss = str; + while ( *ss ) + { + while ( *ss && isspace(*ss) ) ss++; + const char *se = ss; + while ( *se && *se!='\r' && *se!='\n' ) se++; + tmp.l = 0; + kputsn(ss, se-ss, &tmp); + regidx_insert(idx,tmp.s); + while ( *se && isspace(*se) ) se++; + ss = se; + } + free(tmp.s); + return idx; +} + +regidx_t *regidx_init(const char *fname, regidx_parse_f parser, regidx_free_f free_f, size_t payload_size, void *usr_dat) +{ + if ( !parser ) + { + if ( !fname ) parser = regidx_parse_tab; + else + { + int len = strlen(fname); + if ( len>=7 && !strcasecmp(".bed.gz",fname+len-7) ) + parser = regidx_parse_bed; + else if ( len>=8 && !strcasecmp(".bed.bgz",fname+len-8) ) + parser = regidx_parse_bed; + else if ( len>=4 && !strcasecmp(".bed",fname+len-4) ) + parser = regidx_parse_bed; + else + parser = regidx_parse_tab; + } + } + + regidx_t *idx = (regidx_t*) calloc(1,sizeof(regidx_t)); + idx->free = free_f; + idx->parse = parser; + idx->usr = usr_dat; + idx->seq2regs = khash_str2int_init(); + idx->payload_size = payload_size; + if ( payload_size ) idx->payload = malloc(payload_size); + + if ( !fname ) return idx; + + kstring_t str = {0,0,0}; + + htsFile *fp = hts_open(fname,"r"); + if ( !fp ) goto error; + + while ( hts_getline(fp, KS_SEP_LINE, &str) > 0 ) + { + if ( regidx_insert(idx, str.s) ) goto error; + } + + free(str.s); + hts_close(fp); + return idx; + +error: + free(str.s); + if ( fp ) hts_close(fp); + regidx_destroy(idx); + return NULL; +} + +void regidx_destroy(regidx_t *idx) +{ + int i, j; + for (i=0; inseq; i++) + { + reglist_t *list = &idx->seq[i]; + if ( idx->free ) + { + for (j=0; jnreg; j++) + idx->free((char *)list->dat + idx->payload_size*j); + } + free(list->dat); + free(list->reg); + free(list->idx); + } + free(idx->seq_names); + free(idx->seq); + free(idx->str.s); + free(idx->payload); + khash_str2int_destroy_free(idx->seq2regs); + free(idx); +} + +int _reglist_build_index(regidx_t *regidx, reglist_t *list) +{ + int i; + if ( list->unsorted ) + { + if ( !regidx->payload_size ) + qsort(list->reg,list->nreg,sizeof(reg_t),cmp_reg_ptrs); + else + { + reg_t **ptr = (reg_t**) malloc(sizeof(reg_t*)*list->nreg); + for (i=0; inreg; i++) ptr[i] = list->reg + i; + qsort(ptr,list->nreg,sizeof(*ptr),cmp_reg_ptrs2); + + void *tmp_dat = malloc(regidx->payload_size*list->nreg); + for (i=0; inreg; i++) + { + size_t iori = ptr[i] - list->reg; + memcpy((char *)tmp_dat+i*regidx->payload_size, + (char *)list->dat+iori*regidx->payload_size, + regidx->payload_size); + } + free(list->dat); + list->dat = tmp_dat; + + reg_t *tmp_reg = (reg_t*) malloc(sizeof(reg_t)*list->nreg); + for (i=0; inreg; i++) + { + size_t iori = ptr[i] - list->reg; + tmp_reg[i] = list->reg[iori]; + } + free(ptr); + free(list->reg); + list->reg = tmp_reg; + list->mreg = list->nreg; + } + list->unsorted = 0; + } + + list->nidx = 0; + int j,k, midx = 0; + for (j=0; jnreg; j++) + { + int ibeg = iBIN(list->reg[j].beg); + int iend = iBIN(list->reg[j].end); + if ( midx <= iend ) + { + int old_midx = midx; + midx = iend + 1; + kroundup32(midx); + list->idx = (uint32_t*) realloc(list->idx, midx*sizeof(uint32_t)); + memset(list->idx+old_midx, 0, sizeof(uint32_t)*(midx-old_midx)); + } + if ( ibeg==iend ) + { + if ( !list->idx[ibeg] ) list->idx[ibeg] = j + 1; + } + else + { + for (k=ibeg; k<=iend; k++) + if ( !list->idx[k] ) list->idx[k] = j + 1; + } + if ( list->nidx < iend+1 ) list->nidx = iend+1; + } + + return 0; +} + +int regidx_overlap(regidx_t *regidx, const char *chr, uint32_t beg, uint32_t end, regitr_t *regitr) +{ + if ( regitr ) regitr->seq = NULL; + + int iseq, ireg; + if ( khash_str2int_get(regidx->seq2regs, chr, &iseq)!=0 ) return 0; // no such sequence + + reglist_t *list = ®idx->seq[iseq]; + if ( !list->nreg ) return 0; + + if ( list->nreg==1 ) + { + if ( beg > list->reg[0].end ) return 0; + if ( end < list->reg[0].beg ) return 0; + ireg = 0; + } + else + { + if ( !list->idx ) + _reglist_build_index(regidx,list); + + int ibeg = iBIN(beg); + if ( ibeg >= list->nidx ) return 0; // beg is too big + + // find a matching region + uint32_t i = list->idx[ibeg]; + if ( !i ) + { + int iend = iBIN(end); + if ( iend > list->nidx ) iend = list->nidx; + for (i=ibeg; iidx[i] ) break; + if ( i==iend ) return 0; + i = list->idx[i]; + } + + for (ireg=i-1; iregnreg; ireg++) + { + if ( list->reg[ireg].beg > end ) return 0; // no match, past the query region + if ( list->reg[ireg].end >= beg && list->reg[ireg].beg <= end ) break; // found + } + + if ( ireg >= list->nreg ) return 0; // no match + } + + if ( !regitr ) return 1; // match, but no more info to save + + // may need to iterate over the matching regions later + _itr_t *itr = (_itr_t*)regitr->itr; + itr->ridx = regidx; + itr->list = list; + itr->beg = beg; + itr->end = end; + itr->ireg = ireg; + itr->active = 0; + + regitr->seq = list->seq; + regitr->beg = list->reg[ireg].beg; + regitr->end = list->reg[ireg].end; + if ( regidx->payload_size ) + regitr->payload = (char *)list->dat + regidx->payload_size*ireg; + + return 1; +} + +int regidx_parse_bed(const char *line, char **chr_beg, char **chr_end, uint32_t *beg, uint32_t *end, void *payload, void *usr) +{ + char *ss = (char*) line; + while ( *ss && isspace(*ss) ) ss++; + if ( !*ss ) return -1; // skip blank lines + if ( *ss=='#' ) return -1; // skip comments + + char *se = ss; + while ( *se && !isspace(*se) ) se++; + + *chr_beg = ss; + *chr_end = se-1; + + if ( !*se ) + { + // just the chromosome name + *beg = 0; + *end = MAX_COOR_0; + return 0; + } + + ss = se+1; + *beg = strtod(ss, &se); + if ( ss==se ) { fprintf(stderr,"Could not parse bed line: %s\n", line); return -2; } + + ss = se+1; + *end = strtod(ss, &se) - 1; + if ( ss==se ) { fprintf(stderr,"Could not parse bed line: %s\n", line); return -2; } + + return 0; +} + +int regidx_parse_tab(const char *line, char **chr_beg, char **chr_end, uint32_t *beg, uint32_t *end, void *payload, void *usr) +{ + char *ss = (char*) line; + while ( *ss && isspace(*ss) ) ss++; + if ( !*ss ) return -1; // skip blank lines + if ( *ss=='#' ) return -1; // skip comments + + char *se = ss; + while ( *se && !isspace(*se) ) se++; + + *chr_beg = ss; + *chr_end = se-1; + + if ( !*se ) + { + // just the chromosome name + *beg = 0; + *end = MAX_COOR_0; + return 0; + } + + ss = se+1; + *beg = strtod(ss, &se); + if ( ss==se ) { fprintf(stderr,"Could not parse tab line: %s\n", line); return -2; } + if ( *beg==0 ) { fprintf(stderr,"Could not parse tab line, expected 1-based coordinate: %s\n", line); return -2; } + (*beg)--; + + if ( !se[0] || !se[1] ) + *end = *beg; + else + { + ss = se+1; + *end = strtod(ss, &se); + if ( ss==se ) *end = *beg; + else if ( *end==0 ) { fprintf(stderr,"Could not parse tab line, expected 1-based coordinate: %s\n", line); return -2; } + else (*end)--; + } + return 0; +} + +int regidx_parse_reg(const char *line, char **chr_beg, char **chr_end, uint32_t *beg, uint32_t *end, void *payload, void *usr) +{ + char *ss = (char*) line; + while ( *ss && isspace(*ss) ) ss++; + if ( !*ss ) return -1; // skip blank lines + if ( *ss=='#' ) return -1; // skip comments + + char *se = ss; + while ( *se && *se!=':' ) se++; + + *chr_beg = ss; + *chr_end = se-1; + + if ( !*se ) + { + *beg = 0; + *end = MAX_COOR_0; + return 0; + } + + ss = se+1; + *beg = strtod(ss, &se); + if ( ss==se ) { fprintf(stderr,"Could not parse reg line: %s\n", line); return -2; } + if ( *beg==0 ) { fprintf(stderr,"Could not parse reg line, expected 1-based coordinate: %s\n", line); return -2; } + (*beg)--; + + if ( !se[0] || !se[1] ) + *end = se[0]=='-' ? MAX_COOR_0 : *beg; + else + { + ss = se+1; + *end = strtod(ss, &se); + if ( ss==se ) *end = *beg; + else if ( *end==0 ) { fprintf(stderr,"Could not parse reg line, expected 1-based coordinate: %s\n", line); return -2; } + else (*end)--; + } + return 0; +} + +regitr_t *regitr_init(regidx_t *regidx) +{ + regitr_t *regitr = (regitr_t*) calloc(1,sizeof(regitr_t)); + regitr->itr = (_itr_t*) calloc(1,sizeof(_itr_t)); + _itr_t *itr = (_itr_t*) regitr->itr; + itr->ridx = regidx; + itr->list = NULL; + return regitr; +} + +void regitr_reset(regidx_t *regidx, regitr_t *regitr) +{ + _itr_t *itr = (_itr_t*) regitr->itr; + memset(itr,0,sizeof(_itr_t)); + itr->ridx = regidx; +} + +void regitr_destroy(regitr_t *regitr) +{ + free(regitr->itr); + free(regitr); +} + +int regitr_overlap(regitr_t *regitr) +{ + if ( !regitr->seq ) return 0; + + _itr_t *itr = (_itr_t*) regitr->itr; + if ( !itr->active ) + { + // is this the first call after regidx_overlap? + itr->active = 1; + itr->ireg++; + return 1; + } + + reglist_t *list = itr->list; + + int i; + for (i=itr->ireg; inreg; i++) + { + if ( list->reg[i].beg > itr->end ) return 0; // no match, past the query region + if ( list->reg[i].end >= itr->beg && list->reg[i].beg <= itr->end ) break; // found + } + + if ( i >= list->nreg ) return 0; // no match + + itr->ireg = i + 1; + regitr->seq = list->seq; + regitr->beg = list->reg[i].beg; + regitr->end = list->reg[i].end; + if ( itr->ridx->payload_size ) + regitr->payload = (char *)list->dat + itr->ridx->payload_size*i; + + return 1; +} + +int regitr_loop(regitr_t *regitr) +{ + _itr_t *itr = (_itr_t*) regitr->itr; + regidx_t *regidx = itr->ridx; + + if ( !itr->list ) // first time here + { + itr->list = regidx->seq; + itr->ireg = 0; + } + + size_t iseq = itr->list - regidx->seq; + if ( iseq >= regidx->nseq ) return 0; + + if ( itr->ireg >= itr->list->nreg ) + { + iseq++; + if ( iseq >= regidx->nseq ) return 0; // no more sequences, done + itr->ireg = 0; + itr->list = ®idx->seq[iseq]; + } + + regitr->seq = itr->list->seq; + regitr->beg = itr->list->reg[itr->ireg].beg; + regitr->end = itr->list->reg[itr->ireg].end; + if ( regidx->payload_size ) + regitr->payload = (char *)itr->list->dat + regidx->payload_size*itr->ireg; + itr->ireg++; + + return 1; +} + + +void regitr_copy(regitr_t *dst, regitr_t *src) +{ + _itr_t *dst_itr = (_itr_t*) dst->itr; + _itr_t *src_itr = (_itr_t*) src->itr; + *dst_itr = *src_itr; + *dst = *src; + dst->itr = dst_itr; +} + + diff --git a/bcftools/regidx.c.pysam.c b/bcftools/regidx.c.pysam.c new file mode 100644 index 000000000..1082e4aa9 --- /dev/null +++ b/bcftools/regidx.c.pysam.c @@ -0,0 +1,638 @@ +#include "bcftools.pysam.h" + +/* + Copyright (C) 2014-2017 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include +#include +#include +#include +#include +#include "regidx.h" + +#define MAX_COOR_0 REGIDX_MAX // CSI and hts_itr_query limit, 0-based + +#define iBIN(x) ((x)>>13) + +typedef struct +{ + uint32_t beg, end; +} +reg_t; + +typedef struct +{ + uint32_t pos, ireg; // y-coordinate and a pointer to reglist.reg and reglist.dat +} +pos_t; + +typedef struct _reglist_t reglist_t; + +typedef struct +{ + uint32_t beg, end, ireg; // query coordinates and the active region + regidx_t *ridx; + reglist_t *list; + int active; +} +_itr_t; + +// List of regions for one chromosome. +struct _reglist_t +{ + uint32_t *idx, nidx; // index to list.reg+1 + uint32_t nreg, mreg; // n:used, m:allocated + reg_t *reg; // regions + void *dat; // payload data + char *seq; // sequence name + int unsorted; + +}; + +// Container of all sequences +struct _regidx_t +{ + int nseq, mseq; // n:used, m:alloced + reglist_t *seq; // regions for each sequence + void *seq2regs; // hash for fast lookup from chr name to regions + char **seq_names; + regidx_free_f free; // function to free any data allocated by regidx_parse_f + regidx_parse_f parse; // parse one input line + void *usr; // user data to pass to regidx_parse_f + int payload_size; + void *payload; // temporary payload data set by regidx_parse_f (sequence is not known beforehand) + kstring_t str; +}; + +int regidx_seq_nregs(regidx_t *idx, const char *seq) +{ + int iseq; + if ( khash_str2int_get(idx->seq2regs, seq, &iseq)!=0 ) return 0; // no such sequence + return idx->seq[iseq].nreg; +} + +int regidx_nregs(regidx_t *idx) +{ + int i, nreg = 0; + for (i=0; inseq; i++) nreg += idx->seq[i].nreg; + return nreg; +} + +char **regidx_seq_names(regidx_t *idx, int *n) +{ + *n = idx->nseq; + return idx->seq_names; +} + +int regidx_insert_list(regidx_t *idx, char *line, char delim) +{ + kstring_t tmp = {0,0,0}; + char *ss = line; + while ( *ss ) + { + char *se = ss; + while ( *se && *se!=delim ) se++; + tmp.l = 0; + kputsn(ss, se-ss, &tmp); + if ( regidx_insert(idx,tmp.s) < 0 ) + { + free(tmp.s); + return -1; + } + if ( !*se ) break; + ss = se+1; + } + free(tmp.s); + return 0; +} + +static inline int cmp_regs(reg_t *a, reg_t *b) +{ + if ( a->beg < b->beg ) return -1; + if ( a->beg > b->beg ) return 1; + if ( a->end < b->end ) return 1; // longer intervals come first + if ( a->end > b->end ) return -1; + return 0; +} +static int cmp_reg_ptrs(const void *a, const void *b) +{ + return cmp_regs((reg_t*)a,(reg_t*)b); +} +static int cmp_reg_ptrs2(const void *a, const void *b) +{ + return cmp_regs(*((reg_t**)a),*((reg_t**)b)); +} + +inline int regidx_push(regidx_t *idx, char *chr_beg, char *chr_end, uint32_t beg, uint32_t end, void *payload) +{ + if ( beg > MAX_COOR_0 ) beg = MAX_COOR_0; + if ( end > MAX_COOR_0 ) end = MAX_COOR_0; + + int rid; + idx->str.l = 0; + kputsn(chr_beg, chr_end-chr_beg+1, &idx->str); + if ( khash_str2int_get(idx->seq2regs, idx->str.s, &rid)!=0 ) + { + // new chromosome + idx->nseq++; + int m_prev = idx->mseq; + hts_expand0(reglist_t,idx->nseq,idx->mseq,idx->seq); + hts_expand0(char*,idx->nseq,m_prev,idx->seq_names); + idx->seq_names[idx->nseq-1] = strdup(idx->str.s); + rid = khash_str2int_inc(idx->seq2regs, idx->seq_names[idx->nseq-1]); + } + + reglist_t *list = &idx->seq[rid]; + list->seq = idx->seq_names[rid]; + list->nreg++; + int mreg = list->mreg; + hts_expand(reg_t,list->nreg,list->mreg,list->reg); + list->reg[list->nreg-1].beg = beg; + list->reg[list->nreg-1].end = end; + if ( idx->payload_size ) + { + if ( mreg != list->mreg ) list->dat = realloc(list->dat,idx->payload_size*list->mreg); + memcpy((char *)list->dat + idx->payload_size*(list->nreg-1), payload, idx->payload_size); + } + if ( !list->unsorted && list->nreg>1 && cmp_regs(&list->reg[list->nreg-2],&list->reg[list->nreg-1])>0 ) list->unsorted = 1; + return 0; +} + +int regidx_insert(regidx_t *idx, char *line) +{ + if ( !line ) return 0; + char *chr_from, *chr_to; + uint32_t beg,end; + int ret = idx->parse(line,&chr_from,&chr_to,&beg,&end,idx->payload,idx->usr); + if ( ret==-2 ) return -1; // error + if ( ret==-1 ) return 0; // skip the line + regidx_push(idx, chr_from,chr_to,beg,end,idx->payload); + return 0; +} + +regidx_t *regidx_init_string(const char *str, regidx_parse_f parser, regidx_free_f free_f, size_t payload_size, void *usr_dat) +{ + regidx_t *idx = (regidx_t*) calloc(1,sizeof(regidx_t)); + if ( !idx ) return NULL; + + idx->free = free_f; + idx->parse = parser ? parser : regidx_parse_tab; + idx->usr = usr_dat; + idx->seq2regs = khash_str2int_init(); + idx->payload_size = payload_size; + if ( payload_size ) idx->payload = malloc(payload_size); + + kstring_t tmp = {0,0,0}; + const char *ss = str; + while ( *ss ) + { + while ( *ss && isspace(*ss) ) ss++; + const char *se = ss; + while ( *se && *se!='\r' && *se!='\n' ) se++; + tmp.l = 0; + kputsn(ss, se-ss, &tmp); + regidx_insert(idx,tmp.s); + while ( *se && isspace(*se) ) se++; + ss = se; + } + free(tmp.s); + return idx; +} + +regidx_t *regidx_init(const char *fname, regidx_parse_f parser, regidx_free_f free_f, size_t payload_size, void *usr_dat) +{ + if ( !parser ) + { + if ( !fname ) parser = regidx_parse_tab; + else + { + int len = strlen(fname); + if ( len>=7 && !strcasecmp(".bed.gz",fname+len-7) ) + parser = regidx_parse_bed; + else if ( len>=8 && !strcasecmp(".bed.bgz",fname+len-8) ) + parser = regidx_parse_bed; + else if ( len>=4 && !strcasecmp(".bed",fname+len-4) ) + parser = regidx_parse_bed; + else + parser = regidx_parse_tab; + } + } + + regidx_t *idx = (regidx_t*) calloc(1,sizeof(regidx_t)); + idx->free = free_f; + idx->parse = parser; + idx->usr = usr_dat; + idx->seq2regs = khash_str2int_init(); + idx->payload_size = payload_size; + if ( payload_size ) idx->payload = malloc(payload_size); + + if ( !fname ) return idx; + + kstring_t str = {0,0,0}; + + htsFile *fp = hts_open(fname,"r"); + if ( !fp ) goto error; + + while ( hts_getline(fp, KS_SEP_LINE, &str) > 0 ) + { + if ( regidx_insert(idx, str.s) ) goto error; + } + + free(str.s); + hts_close(fp); + return idx; + +error: + free(str.s); + if ( fp ) hts_close(fp); + regidx_destroy(idx); + return NULL; +} + +void regidx_destroy(regidx_t *idx) +{ + int i, j; + for (i=0; inseq; i++) + { + reglist_t *list = &idx->seq[i]; + if ( idx->free ) + { + for (j=0; jnreg; j++) + idx->free((char *)list->dat + idx->payload_size*j); + } + free(list->dat); + free(list->reg); + free(list->idx); + } + free(idx->seq_names); + free(idx->seq); + free(idx->str.s); + free(idx->payload); + khash_str2int_destroy_free(idx->seq2regs); + free(idx); +} + +int _reglist_build_index(regidx_t *regidx, reglist_t *list) +{ + int i; + if ( list->unsorted ) + { + if ( !regidx->payload_size ) + qsort(list->reg,list->nreg,sizeof(reg_t),cmp_reg_ptrs); + else + { + reg_t **ptr = (reg_t**) malloc(sizeof(reg_t*)*list->nreg); + for (i=0; inreg; i++) ptr[i] = list->reg + i; + qsort(ptr,list->nreg,sizeof(*ptr),cmp_reg_ptrs2); + + void *tmp_dat = malloc(regidx->payload_size*list->nreg); + for (i=0; inreg; i++) + { + size_t iori = ptr[i] - list->reg; + memcpy((char *)tmp_dat+i*regidx->payload_size, + (char *)list->dat+iori*regidx->payload_size, + regidx->payload_size); + } + free(list->dat); + list->dat = tmp_dat; + + reg_t *tmp_reg = (reg_t*) malloc(sizeof(reg_t)*list->nreg); + for (i=0; inreg; i++) + { + size_t iori = ptr[i] - list->reg; + tmp_reg[i] = list->reg[iori]; + } + free(ptr); + free(list->reg); + list->reg = tmp_reg; + list->mreg = list->nreg; + } + list->unsorted = 0; + } + + list->nidx = 0; + int j,k, midx = 0; + for (j=0; jnreg; j++) + { + int ibeg = iBIN(list->reg[j].beg); + int iend = iBIN(list->reg[j].end); + if ( midx <= iend ) + { + int old_midx = midx; + midx = iend + 1; + kroundup32(midx); + list->idx = (uint32_t*) realloc(list->idx, midx*sizeof(uint32_t)); + memset(list->idx+old_midx, 0, sizeof(uint32_t)*(midx-old_midx)); + } + if ( ibeg==iend ) + { + if ( !list->idx[ibeg] ) list->idx[ibeg] = j + 1; + } + else + { + for (k=ibeg; k<=iend; k++) + if ( !list->idx[k] ) list->idx[k] = j + 1; + } + if ( list->nidx < iend+1 ) list->nidx = iend+1; + } + + return 0; +} + +int regidx_overlap(regidx_t *regidx, const char *chr, uint32_t beg, uint32_t end, regitr_t *regitr) +{ + if ( regitr ) regitr->seq = NULL; + + int iseq, ireg; + if ( khash_str2int_get(regidx->seq2regs, chr, &iseq)!=0 ) return 0; // no such sequence + + reglist_t *list = ®idx->seq[iseq]; + if ( !list->nreg ) return 0; + + if ( list->nreg==1 ) + { + if ( beg > list->reg[0].end ) return 0; + if ( end < list->reg[0].beg ) return 0; + ireg = 0; + } + else + { + if ( !list->idx ) + _reglist_build_index(regidx,list); + + int ibeg = iBIN(beg); + if ( ibeg >= list->nidx ) return 0; // beg is too big + + // find a matching region + uint32_t i = list->idx[ibeg]; + if ( !i ) + { + int iend = iBIN(end); + if ( iend > list->nidx ) iend = list->nidx; + for (i=ibeg; iidx[i] ) break; + if ( i==iend ) return 0; + i = list->idx[i]; + } + + for (ireg=i-1; iregnreg; ireg++) + { + if ( list->reg[ireg].beg > end ) return 0; // no match, past the query region + if ( list->reg[ireg].end >= beg && list->reg[ireg].beg <= end ) break; // found + } + + if ( ireg >= list->nreg ) return 0; // no match + } + + if ( !regitr ) return 1; // match, but no more info to save + + // may need to iterate over the matching regions later + _itr_t *itr = (_itr_t*)regitr->itr; + itr->ridx = regidx; + itr->list = list; + itr->beg = beg; + itr->end = end; + itr->ireg = ireg; + itr->active = 0; + + regitr->seq = list->seq; + regitr->beg = list->reg[ireg].beg; + regitr->end = list->reg[ireg].end; + if ( regidx->payload_size ) + regitr->payload = (char *)list->dat + regidx->payload_size*ireg; + + return 1; +} + +int regidx_parse_bed(const char *line, char **chr_beg, char **chr_end, uint32_t *beg, uint32_t *end, void *payload, void *usr) +{ + char *ss = (char*) line; + while ( *ss && isspace(*ss) ) ss++; + if ( !*ss ) return -1; // skip blank lines + if ( *ss=='#' ) return -1; // skip comments + + char *se = ss; + while ( *se && !isspace(*se) ) se++; + + *chr_beg = ss; + *chr_end = se-1; + + if ( !*se ) + { + // just the chromosome name + *beg = 0; + *end = MAX_COOR_0; + return 0; + } + + ss = se+1; + *beg = strtod(ss, &se); + if ( ss==se ) { fprintf(bcftools_stderr,"Could not parse bed line: %s\n", line); return -2; } + + ss = se+1; + *end = strtod(ss, &se) - 1; + if ( ss==se ) { fprintf(bcftools_stderr,"Could not parse bed line: %s\n", line); return -2; } + + return 0; +} + +int regidx_parse_tab(const char *line, char **chr_beg, char **chr_end, uint32_t *beg, uint32_t *end, void *payload, void *usr) +{ + char *ss = (char*) line; + while ( *ss && isspace(*ss) ) ss++; + if ( !*ss ) return -1; // skip blank lines + if ( *ss=='#' ) return -1; // skip comments + + char *se = ss; + while ( *se && !isspace(*se) ) se++; + + *chr_beg = ss; + *chr_end = se-1; + + if ( !*se ) + { + // just the chromosome name + *beg = 0; + *end = MAX_COOR_0; + return 0; + } + + ss = se+1; + *beg = strtod(ss, &se); + if ( ss==se ) { fprintf(bcftools_stderr,"Could not parse tab line: %s\n", line); return -2; } + if ( *beg==0 ) { fprintf(bcftools_stderr,"Could not parse tab line, expected 1-based coordinate: %s\n", line); return -2; } + (*beg)--; + + if ( !se[0] || !se[1] ) + *end = *beg; + else + { + ss = se+1; + *end = strtod(ss, &se); + if ( ss==se ) *end = *beg; + else if ( *end==0 ) { fprintf(bcftools_stderr,"Could not parse tab line, expected 1-based coordinate: %s\n", line); return -2; } + else (*end)--; + } + return 0; +} + +int regidx_parse_reg(const char *line, char **chr_beg, char **chr_end, uint32_t *beg, uint32_t *end, void *payload, void *usr) +{ + char *ss = (char*) line; + while ( *ss && isspace(*ss) ) ss++; + if ( !*ss ) return -1; // skip blank lines + if ( *ss=='#' ) return -1; // skip comments + + char *se = ss; + while ( *se && *se!=':' ) se++; + + *chr_beg = ss; + *chr_end = se-1; + + if ( !*se ) + { + *beg = 0; + *end = MAX_COOR_0; + return 0; + } + + ss = se+1; + *beg = strtod(ss, &se); + if ( ss==se ) { fprintf(bcftools_stderr,"Could not parse reg line: %s\n", line); return -2; } + if ( *beg==0 ) { fprintf(bcftools_stderr,"Could not parse reg line, expected 1-based coordinate: %s\n", line); return -2; } + (*beg)--; + + if ( !se[0] || !se[1] ) + *end = se[0]=='-' ? MAX_COOR_0 : *beg; + else + { + ss = se+1; + *end = strtod(ss, &se); + if ( ss==se ) *end = *beg; + else if ( *end==0 ) { fprintf(bcftools_stderr,"Could not parse reg line, expected 1-based coordinate: %s\n", line); return -2; } + else (*end)--; + } + return 0; +} + +regitr_t *regitr_init(regidx_t *regidx) +{ + regitr_t *regitr = (regitr_t*) calloc(1,sizeof(regitr_t)); + regitr->itr = (_itr_t*) calloc(1,sizeof(_itr_t)); + _itr_t *itr = (_itr_t*) regitr->itr; + itr->ridx = regidx; + itr->list = NULL; + return regitr; +} + +void regitr_reset(regidx_t *regidx, regitr_t *regitr) +{ + _itr_t *itr = (_itr_t*) regitr->itr; + memset(itr,0,sizeof(_itr_t)); + itr->ridx = regidx; +} + +void regitr_destroy(regitr_t *regitr) +{ + free(regitr->itr); + free(regitr); +} + +int regitr_overlap(regitr_t *regitr) +{ + if ( !regitr->seq ) return 0; + + _itr_t *itr = (_itr_t*) regitr->itr; + if ( !itr->active ) + { + // is this the first call after regidx_overlap? + itr->active = 1; + itr->ireg++; + return 1; + } + + reglist_t *list = itr->list; + + int i; + for (i=itr->ireg; inreg; i++) + { + if ( list->reg[i].beg > itr->end ) return 0; // no match, past the query region + if ( list->reg[i].end >= itr->beg && list->reg[i].beg <= itr->end ) break; // found + } + + if ( i >= list->nreg ) return 0; // no match + + itr->ireg = i + 1; + regitr->seq = list->seq; + regitr->beg = list->reg[i].beg; + regitr->end = list->reg[i].end; + if ( itr->ridx->payload_size ) + regitr->payload = (char *)list->dat + itr->ridx->payload_size*i; + + return 1; +} + +int regitr_loop(regitr_t *regitr) +{ + _itr_t *itr = (_itr_t*) regitr->itr; + regidx_t *regidx = itr->ridx; + + if ( !itr->list ) // first time here + { + itr->list = regidx->seq; + itr->ireg = 0; + } + + size_t iseq = itr->list - regidx->seq; + if ( iseq >= regidx->nseq ) return 0; + + if ( itr->ireg >= itr->list->nreg ) + { + iseq++; + if ( iseq >= regidx->nseq ) return 0; // no more sequences, done + itr->ireg = 0; + itr->list = ®idx->seq[iseq]; + } + + regitr->seq = itr->list->seq; + regitr->beg = itr->list->reg[itr->ireg].beg; + regitr->end = itr->list->reg[itr->ireg].end; + if ( regidx->payload_size ) + regitr->payload = (char *)itr->list->dat + regidx->payload_size*itr->ireg; + itr->ireg++; + + return 1; +} + + +void regitr_copy(regitr_t *dst, regitr_t *src) +{ + _itr_t *dst_itr = (_itr_t*) dst->itr; + _itr_t *src_itr = (_itr_t*) src->itr; + *dst_itr = *src_itr; + *dst = *src; + dst->itr = dst_itr; +} + + diff --git a/bcftools/regidx.h b/bcftools/regidx.h new file mode 100644 index 000000000..fe0a897e4 --- /dev/null +++ b/bcftools/regidx.h @@ -0,0 +1,199 @@ +/* + Copyright (C) 2014-2016 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +/* + Region indexing with an optional payload. + + Example of usage: + + // Init the parser and print regions. In this example the payload is a + // pointer to a string. For the description of parse_custom and + // free_custom functions, see regidx_parse_f and regidx_free_f below, + // and for working example see test/test-regidx.c. + regidx_t *idx = regidx_init(in_fname,parse_custom,free_custom,sizeof(char*),NULL); + + // Query overlap with chr:from-to + regitr_t *itr = regitr_init(idx); + if ( regidx_overlap(idx, chr,from,to, itr) ) printf("There is an overlap!\n"); + + while ( regitr_overlap(itr) ) + { + printf("[%d,%d] overlaps with [%d,%d], payload=%s\n", from,to, + itr->beg, itr->end, regitr_payload(itr,char*)); + } + + regidx_destroy(idx); + regitr_destroy(itr); + + + Another example, loop over all regions: + + regidx_t *idx = regidx_init(in_fname,NULL,NULL,0,NULL); + regitr_t *itr = regitr_init(idx); + + while ( regitr_loop(itr) ) + printf("chr=%s beg=%d end=%d\n", itr->seq, itr->beg, itr->end); + + regidx_destroy(idx); + regitr_destroy(itr); +*/ + +#ifndef __REGIDX_H__ +#define __REGIDX_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define REGIDX_MAX 2147483646 // maximum regidx coordinate (0-based) + +typedef struct _regidx_t regidx_t; +typedef struct +{ + uint32_t beg,end; + void *payload; + char *seq; + void *itr; +} +regitr_t; + +#define regitr_payload(itr,type_t) (*((type_t*)(itr)->payload)) + +/* + * regidx_parse_f - Function to parse one input line, such as regidx_parse_bed + * or regidx_parse_tab below. The function is expected to set `chr_from` and + * `chr_to` to point to first and last character of chromosome name and set + * coordinates `beg` and `end` (0-based, inclusive). If regidx_init() was + * called with non-zero payload_size, the `payload` points to a memory + * location of the payload_size and `usr` is the data passed to regidx_init(). + * Any memory allocated by the function will be freed by regidx_free_f called + * by regidx_destroy(). + * + * Return value: 0 on success, -1 to skip a record, -2 on fatal error. + */ +typedef int (*regidx_parse_f)(const char *line, char **chr_beg, char **chr_end, uint32_t *beg, uint32_t *end, void *payload, void *usr); +typedef void (*regidx_free_f)(void *payload); + +/* + * A note about the parsers: + * - leading spaces are ignored + * - lines starting with "#" are ignored + */ +int regidx_parse_bed(const char*,char**,char**,uint32_t*,uint32_t*,void*,void*); // CHROM or whitespace-sepatated CHROM,FROM,TO (0-based,right-open) +int regidx_parse_tab(const char*,char**,char**,uint32_t*,uint32_t*,void*,void*); // CHROM or whitespace-separated CHROM,POS (1-based, inclusive) +int regidx_parse_reg(const char*,char**,char**,uint32_t*,uint32_t*,void*,void*); // CHROM, CHROM:POS, CHROM:FROM-TO, CHROM:FROM- (1-based, inclusive) + +/* + * regidx_init() - creates new index + * regidx_init_string() - creates new index, from a string rather than from a file + * + * @param fname: input file name or NULL if regions will be added one-by-one via regidx_insert() + * @param parsef: regidx_parse_bed, regidx_parse_tab or see description of regidx_parse_f. If NULL, + * the format will be autodected, currently either regidx_parse_tab (the default) or + * regidx_parse_bed (file must be named 'bed' or 'bed.gz') will be used. Note that + * the exact autodetection algorithm will change. + * @param freef: NULL or see description of regidx_parse_f + * @param payload_size: 0 with regidx_parse_bed, regidx_parse_tab or see regidx_parse_f + * @param usr: optional user data passed to regidx_parse_f + * + * Returns index on success or NULL on error. + */ +regidx_t *regidx_init(const char *fname, regidx_parse_f parsef, regidx_free_f freef, size_t payload_size, void *usr); +regidx_t *regidx_init_string(const char *string, regidx_parse_f parsef, regidx_free_f freef, size_t payload_size, void *usr); + +/* + * regidx_destroy() - free memory allocated by regidx_init + */ +void regidx_destroy(regidx_t *idx); + +/* + * regidx_overlap() - check overlap of the location chr:from-to with regions + * @param beg,end: 0-based start, end coordinate (inclusive) + * @param itr: pointer to iterator, can be NULL if regidx_loop not needed + * + * Returns 0 if there is no overlap or 1 if overlap is found. The overlapping + * regions can be iterated as shown in the example above. + */ +int regidx_overlap(regidx_t *idx, const char *chr, uint32_t beg, uint32_t end, regitr_t *itr); + +/* + * regidx_insert() - add a new region. + * regidx_insert_list() - add new regions from a list + * regidx_push() - low level insertion of a new region + * + * Returns 0 on success or -1 on error. + */ +int regidx_insert(regidx_t *idx, char *line); +int regidx_insert_list(regidx_t *idx, char *line, char delim); +int regidx_push(regidx_t *idx, char *chr_beg, char *chr_end, uint32_t beg, uint32_t end, void *payload); + +/* + * regidx_seq_names() - return list of all sequence names + */ +char **regidx_seq_names(regidx_t *idx, int *n); + +/* + * regidx_seq_nregs() - number of regions + * regidx_nregs() - total number of regions + */ +int regidx_seq_nregs(regidx_t *idx, const char *seq); +int regidx_nregs(regidx_t *idx); + +/* + * regitr_init() - initialize an iterator. The idx parameter is required only + * with regitr_loop. If only regitr_overlap is called, NULL + * can be given. + * + * regitr_reset() - initialize an iterator for a repeated regitr_loop cycle. + * Not required with regitr_overlap. + */ +regitr_t *regitr_init(regidx_t *idx); +void regitr_destroy(regitr_t *itr); +void regitr_reset(regidx_t *idx, regitr_t *itr); + +/* + * regitr_overlap() - next overlapping region + * Returns 0 when done or 1 when itr is set to next region + */ +int regitr_overlap(regitr_t *itr); + +/* + * regitr_loop() - loop over all regions + * Returns 0 when done or 1 when itr is set to next region + */ +int regitr_loop(regitr_t *itr); + +/* + * regitr_copy() - create a copy of an iterator for a repeated iteration with regitr_loop + */ +void regitr_copy(regitr_t *dst, regitr_t *src); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/bcftools/reheader.c b/bcftools/reheader.c new file mode 100644 index 000000000..277606900 --- /dev/null +++ b/bcftools/reheader.c @@ -0,0 +1,521 @@ +/* reheader.c -- reheader subcommand. + + Copyright (C) 2014-2017 Genome Research Ltd. + + Author: Petr Danecek + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // for hts_get_bgzfp() +#include +#include "bcftools.h" +#include "khash_str2str.h" + +typedef struct _args_t +{ + char **argv, *fname, *samples_fname, *header_fname, *output_fname; + htsFile *fp; + htsFormat type; + int argc; +} +args_t; + +static void read_header_file(char *fname, kstring_t *hdr) +{ + kstring_t tmp = {0,0,0}; + hdr->l = 0; + + htsFile *fp = hts_open(fname, "r"); + if ( !fp ) error("Could not read: %s\n", fname); + while ( hts_getline(fp, KS_SEP_LINE, &tmp) > 0 ) + { + kputsn(tmp.s,tmp.l,hdr); + kputc('\n',hdr); + } + if ( hts_close(fp) ) error("Close failed: %s\n", fname); + free(tmp.s); + + while ( hdr->l>0 && isspace(hdr->s[hdr->l-1]) ) hdr->l--; // remove trailing newlines + kputc('\n',hdr); +} + +static int set_sample_pairs(char **samples, int nsamples, kstring_t *hdr, int idx) +{ + int i, j, n; + kstring_t key = {0,0,0}; + kstring_t val = {0,0,0}; + + // Are these samples "old-name new-name" pairs? + void *hash = khash_str2str_init(); + for (i=0; il>0 && isspace(hdr->s[hdr->l-1]) ) hdr->l--; // remove trailing newlines + hdr->s[hdr->l] = 0; + + kstring_t tmp = {0,0,0}; + i = j = n = 0; + while ( hdr->s[idx+i] && hdr->s[idx+i]) + { + if ( hdr->s[idx+i]=='\t' ) + { + hdr->s[idx+i] = 0; + + if ( ++n>9 ) + { + char *ori = khash_str2str_get(hash,hdr->s+idx+j); + kputs(ori ? ori : hdr->s+idx+j, &tmp); + } + else + kputs(hdr->s+idx+j, &tmp); + + kputc('\t',&tmp); + + j = ++i; + continue; + } + i++; + } + char *ori = khash_str2str_get(hash,hdr->s+idx+j); + kputs(ori ? ori : hdr->s+idx+j, &tmp); + + khash_str2str_destroy_free_all(hash); + + hdr->l = idx; + kputs(tmp.s, hdr); + kputc('\n', hdr); + free(tmp.s); + + return 1; +} + +static void set_samples(char **samples, int nsamples, kstring_t *hdr) +{ + // Find the beginning of the #CHROM line + int i = hdr->l - 2, ncols = 0; + while ( i>=0 && hdr->s[i]!='\n' ) + { + if ( hdr->s[i]=='\t' ) ncols++; + i--; + } + if ( i<0 || strncmp(hdr->s+i+1,"#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT",45) ) error("Could not parse the header: %s\n", hdr->s); + + // Are the samples "old-sample new-sample" pairs? + if ( set_sample_pairs(samples,nsamples,hdr, i+1) ) return; + + // Replace all samples + if ( ncols!=nsamples+8 ) + fprintf(stderr, "Warning: different number of samples: %d vs %d\n", nsamples,ncols-8); + + ncols = 0; + while ( ncols!=9 ) + { + i++; + if ( hdr->s[i]=='\t' ) ncols++; + } + hdr->l = i; + + for (i=0; ifp); + if ( !fp || bgzf_read_block(fp) != 0 || !fp->block_length ) + error("Failed to read %s: %s\n", args->fname, strerror(errno)); + + kstring_t hdr = {0,0,0}; + char *buffer = (char*) fp->uncompressed_block; + + // Read the header and find the position of the data block + if ( buffer[0]!='#' ) error("Could not parse the header, expected '#', found '%c'\n", buffer[0]); + + int skip_until = 1; // end of the header in the current uncompressed block + while (1) + { + if ( buffer[skip_until]=='\n' ) + { + skip_until++; + if ( skip_until>=fp->block_length ) + { + kputsn(buffer,skip_until,&hdr); + if ( bgzf_read_block(fp) != 0 ) error("Error reading %s\n", args->fname); + if ( !fp->block_length ) break; + skip_until = 0; + } + // The header has finished + if ( buffer[skip_until]!='#' ) + { + kputsn(buffer,skip_until,&hdr); + break; + } + } + skip_until++; + if ( skip_until>=fp->block_length ) + { + kputsn(buffer,fp->block_length,&hdr); + if ( bgzf_read_block(fp) != 0 ) error("Error reading %s\n", args->fname); + if ( !fp->block_length ) break; + skip_until = 0; + } + } + + int nsamples = 0; + char **samples = NULL; + if ( args->samples_fname ) + samples = hts_readlines(args->samples_fname, &nsamples); + if ( args->header_fname ) + { + free(hdr.s); hdr.s = NULL; hdr.l = hdr.m = 0; + read_header_file(args->header_fname, &hdr); + } + if ( samples ) + { + set_samples(samples, nsamples, &hdr); + int i; + for (i=0; ioutput_fname ? args->output_fname : "-","w");; + if ( bgzf_write(bgzf_out, hdr.s, hdr.l) < 0 ) error("Can't write BGZF header (code %d)\n", bgzf_out->errcode); + free(hdr.s); + + // Output all remainig data read with the header block + if ( fp->block_length - skip_until > 0 ) + { + if ( bgzf_write(bgzf_out, buffer+skip_until, fp->block_length-skip_until)<0 ) error("Error: %d\n",fp->errcode); + } + if ( bgzf_flush(bgzf_out)<0 ) error("Error: %d\n",bgzf_out->errcode); + + // Stream the rest of the file without as it is, without decompressing + ssize_t nread; + const size_t page_size = 32768; + char *buf = (char*) malloc(page_size); + while (1) + { + nread = bgzf_raw_read(fp, buf, page_size); + if ( nread<=0 ) break; + + int count = bgzf_raw_write(bgzf_out, buf, nread); + if (count != nread) error("Write failed, wrote %d instead of %d bytes.\n", count,(int)nread); + } + if (bgzf_close(bgzf_out) < 0) error("Error closing %s: %d\n",args->output_fname ? args->output_fname : "-",bgzf_out->errcode); + if (hts_close(args->fp)) error("Error closing %s: %d\n",args->fname,fp->errcode); + free(buf); +} +static void reheader_vcf(args_t *args) +{ + kstring_t hdr = {0,0,0}; + htsFile *fp = args->fp; + while ( hts_getline(fp, KS_SEP_LINE, &fp->line) >=0 ) + { + kputc('\n',&fp->line); // hts_getline eats the newline character + if ( fp->line.s[0]!='#' ) break; + kputsn(fp->line.s,fp->line.l,&hdr); + } + + int nsamples = 0; + char **samples = NULL; + if ( args->samples_fname ) + samples = hts_readlines(args->samples_fname, &nsamples); + if ( args->header_fname ) + { + free(hdr.s); hdr.s = NULL; hdr.l = hdr.m = 0; + read_header_file(args->header_fname, &hdr); + } + if ( samples ) + { + set_samples(samples, nsamples, &hdr); + int i; + for (i=0; ioutput_fname ? open(args->output_fname, O_WRONLY|O_CREAT|O_TRUNC, 0666) : STDOUT_FILENO; + if ( out==-1 ) error("%s: %s\n", args->output_fname,strerror(errno)); + if ( write(out, hdr.s, hdr.l)!=hdr.l ) error("Failed to write %d bytes\n", hdr.l); + free(hdr.s); + if ( fp->line.l ) + { + if ( write(out, fp->line.s, fp->line.l)!=fp->line.l ) error("Failed to write %d bytes\n", fp->line.l); + } + while ( hts_getline(fp, KS_SEP_LINE, &fp->line) >=0 ) // uncompressed file implies small size, we don't worry about speed + { + kputc('\n',&fp->line); + if ( write(out, fp->line.s, fp->line.l)!=fp->line.l ) error("Failed to write %d bytes\n", fp->line.l); + } + hts_close(fp); + close(out); +} + +static bcf_hdr_t *strip_header(bcf_hdr_t *src, bcf_hdr_t *dst) +{ + bcf_hrec_t *src_hrec, *dst_hrec, *tmp; + bcf_hdr_t *out = bcf_hdr_init("r"); + int i; + for (i=0; inhrec; i++) + { + // first insert lines which do not code BCF ids, their order does not matter + dst_hrec = dst->hrec[i]; + if ( dst_hrec->type==BCF_HL_FLT || dst_hrec->type==BCF_HL_INFO || dst_hrec->type==BCF_HL_FMT || dst_hrec->type== BCF_HL_CTG ) continue; + bcf_hdr_add_hrec(out, bcf_hrec_dup(dst_hrec)); + } + for (i=0; inhrec; i++) + { + // now transfer header lines which define BCF ids + src_hrec = src->hrec[i]; + + if ( src_hrec->type==BCF_HL_FLT || src_hrec->type==BCF_HL_INFO || src_hrec->type==BCF_HL_FMT || src_hrec->type== BCF_HL_CTG ) + { + int j = bcf_hrec_find_key(src_hrec, "ID"); + dst_hrec = bcf_hdr_get_hrec(dst, src_hrec->type, "ID", src_hrec->vals[j], NULL); + if ( !dst_hrec ) continue; + + tmp = bcf_hrec_dup(dst_hrec); + + j = bcf_hrec_find_key(src_hrec, "IDX"); + if ( j>=0 ) + { + j = atoi(src_hrec->vals[j]); + hrec_add_idx(tmp, j); + } + bcf_hdr_add_hrec(out, tmp); + } + } + bcf_hdr_sync(out); + for (i=0; inhrec; i++) + { + // finally add new structured fields + dst_hrec = dst->hrec[i]; + if ( dst_hrec->type==BCF_HL_FLT || dst_hrec->type==BCF_HL_INFO || dst_hrec->type==BCF_HL_FMT || dst_hrec->type== BCF_HL_CTG ) + { + int j = bcf_hrec_find_key(dst_hrec, "ID"); + tmp = bcf_hdr_get_hrec(out, dst_hrec->type, "ID", dst_hrec->vals[j], NULL); + if ( !tmp ) + bcf_hdr_add_hrec(out, bcf_hrec_dup(dst_hrec)); + } + } + for (i=0; in[BCF_DT_SAMPLE]; i++) bcf_hdr_add_sample(out, dst->samples[i]); + bcf_hdr_destroy(dst); + return out; +} + +static void reheader_bcf(args_t *args, int is_compressed) +{ + htsFile *fp = args->fp; + bcf_hdr_t *hdr = bcf_hdr_read(fp); if ( !hdr ) error("Failed to read the header: %s\n", args->fname); + kstring_t htxt = {0,0,0}; + bcf_hdr_format(hdr, 1, &htxt); + + int i, nsamples = 0; + char **samples = NULL; + if ( args->samples_fname ) + samples = hts_readlines(args->samples_fname, &nsamples); + if ( args->header_fname ) + { + free(htxt.s); htxt.s = NULL; htxt.l = htxt.m = 0; + read_header_file(args->header_fname, &htxt); + } + if ( samples ) + { + set_samples(samples, nsamples, &htxt); + for (i=0; iheader_fname ) hdr_out = strip_header(hdr, hdr_out); + + // write the header and the body + htsFile *fp_out = hts_open(args->output_fname ? args->output_fname : "-",is_compressed ? "wb" : "wbu"); + if ( !fp_out ) error("%s: %s\n", args->output_fname ? args->output_fname : "-", strerror(errno)); + bcf_hdr_write(fp_out, hdr_out); + + bcf1_t *rec = bcf_init(); + while ( bcf_read(fp, hdr, rec)==0 ) + { + // sanity checking, this slows things down. Make it optional? + bcf_unpack(rec, BCF_UN_ALL); + if ( rec->rid >= hdr_out->n[BCF_DT_CTG] || strcmp(bcf_hdr_int2id(hdr,BCF_DT_CTG,rec->rid),bcf_hdr_int2id(hdr_out,BCF_DT_CTG,rec->rid)) ) + error("The CHROM is not defined: \"%s\"\n", bcf_hdr_int2id(hdr,BCF_DT_CTG,rec->rid)); + + for (i=0; id.n_flt; i++) + { + int id = rec->d.flt[i]; + if ( id >= hdr_out->n[BCF_DT_ID] ) break; + if ( !bcf_hdr_idinfo_exists(hdr_out,BCF_HL_FLT,id) ) break; + if ( strcmp(hdr->id[BCF_DT_ID][id].key,hdr_out->id[BCF_DT_ID][id].key) ) + error("FIXME: Broken FILTER ids: %s vs %s\n", hdr->id[BCF_DT_ID][id].key,hdr_out->id[BCF_DT_ID][id].key); + } + if ( i!=rec->d.n_flt ) + error("The FILTER is not defined: \"%s\"\n", bcf_hdr_int2id(hdr,BCF_DT_ID,rec->d.flt[i])); + + for (i=0; in_info; i++) + { + int id = rec->d.info[i].key; + if ( id >= hdr_out->n[BCF_DT_ID] ) break; + if ( !hdr_out->id[BCF_DT_ID][id].key ) break; + if ( !bcf_hdr_idinfo_exists(hdr_out,BCF_HL_INFO,id) ) break; + if ( strcmp(hdr->id[BCF_DT_ID][id].key,hdr_out->id[BCF_DT_ID][id].key) ) + error("FIXME: Broken INFO ids: %s vs %s\n", hdr->id[BCF_DT_ID][id].key,hdr_out->id[BCF_DT_ID][id].key); + } + if ( i!=rec->n_info ) + error("The INFO tag is not defined: \"%s\"\n", bcf_hdr_int2id(hdr,BCF_DT_ID,rec->d.info[i].key)); + + for (i=0; in_fmt; i++) + { + int id = rec->d.fmt[i].id; + if ( id >= hdr_out->n[BCF_DT_ID] ) break; + if ( !hdr_out->id[BCF_DT_ID][id].key ) break; + if ( !bcf_hdr_idinfo_exists(hdr_out,BCF_HL_FMT,id) ) break; + if ( strcmp(hdr->id[BCF_DT_ID][id].key,hdr_out->id[BCF_DT_ID][id].key) ) + error("FIXME: Broken FORMAT ids: %s vs %s\n", hdr->id[BCF_DT_ID][id].key,hdr_out->id[BCF_DT_ID][id].key); + } + if ( i!=rec->n_fmt ) + error("The FORMAT tag is not defined: \"%s\"\n", bcf_hdr_int2id(hdr,BCF_DT_ID,rec->d.fmt[i].id)); + + bcf_write(fp_out,hdr_out,rec); + } + bcf_destroy(rec); + + free(htxt.s); + hts_close(fp_out); + hts_close(fp); + bcf_hdr_destroy(hdr_out); + bcf_hdr_destroy(hdr); +} + + +static void usage(args_t *args) +{ + fprintf(stderr, "\n"); + fprintf(stderr, "About: Modify header of VCF/BCF files, change sample names.\n"); + fprintf(stderr, "Usage: bcftools reheader [OPTIONS] \n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Options:\n"); + fprintf(stderr, " -h, --header new header\n"); + fprintf(stderr, " -o, --output write output to a file [standard output]\n"); + fprintf(stderr, " -s, --samples new sample names\n"); + fprintf(stderr, "\n"); + exit(1); +} + +int main_reheader(int argc, char *argv[]) +{ + int c; + args_t *args = (args_t*) calloc(1,sizeof(args_t)); + args->argc = argc; args->argv = argv; + + static struct option loptions[] = + { + {"output",1,0,'o'}, + {"header",1,0,'h'}, + {"samples",1,0,'s'}, + {0,0,0,0} + }; + while ((c = getopt_long(argc, argv, "s:h:o:",loptions,NULL)) >= 0) + { + switch (c) + { + case 'o': args->output_fname = optarg; break; + case 's': args->samples_fname = optarg; break; + case 'h': args->header_fname = optarg; break; + case '?': usage(args); + default: error("Unknown argument: %s\n", optarg); + } + } + + if ( optind>=argc ) + { + if ( !isatty(fileno((FILE *)stdin)) ) args->fname = "-"; // reading from stdin + else usage(args); + } + else args->fname = argv[optind]; + + if ( !args->samples_fname && !args->header_fname ) usage(args); + if ( !args->fname ) usage(args); + + args->fp = hts_open(args->fname,"r"); + if ( !args->fp ) error("Failed to open: %s\n", args->fname); + args->type = *hts_get_format(args->fp); + + if ( args->type.format==vcf ) + { + if ( args->type.compression==bgzf || args->type.compression==gzip ) + reheader_vcf_gz(args); + else + reheader_vcf(args); + } + else + reheader_bcf(args, args->type.compression==bgzf || args->type.compression==gzip); + + free(args); + return 0; +} diff --git a/bcftools/reheader.c.pysam.c b/bcftools/reheader.c.pysam.c new file mode 100644 index 000000000..11c0870a9 --- /dev/null +++ b/bcftools/reheader.c.pysam.c @@ -0,0 +1,523 @@ +#include "bcftools.pysam.h" + +/* reheader.c -- reheader subcommand. + + Copyright (C) 2014-2017 Genome Research Ltd. + + Author: Petr Danecek + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // for hts_get_bgzfp() +#include +#include "bcftools.h" +#include "khash_str2str.h" + +typedef struct _args_t +{ + char **argv, *fname, *samples_fname, *header_fname, *output_fname; + htsFile *fp; + htsFormat type; + int argc; +} +args_t; + +static void read_header_file(char *fname, kstring_t *hdr) +{ + kstring_t tmp = {0,0,0}; + hdr->l = 0; + + htsFile *fp = hts_open(fname, "r"); + if ( !fp ) error("Could not read: %s\n", fname); + while ( hts_getline(fp, KS_SEP_LINE, &tmp) > 0 ) + { + kputsn(tmp.s,tmp.l,hdr); + kputc('\n',hdr); + } + if ( hts_close(fp) ) error("Close failed: %s\n", fname); + free(tmp.s); + + while ( hdr->l>0 && isspace(hdr->s[hdr->l-1]) ) hdr->l--; // remove trailing newlines + kputc('\n',hdr); +} + +static int set_sample_pairs(char **samples, int nsamples, kstring_t *hdr, int idx) +{ + int i, j, n; + kstring_t key = {0,0,0}; + kstring_t val = {0,0,0}; + + // Are these samples "old-name new-name" pairs? + void *hash = khash_str2str_init(); + for (i=0; il>0 && isspace(hdr->s[hdr->l-1]) ) hdr->l--; // remove trailing newlines + hdr->s[hdr->l] = 0; + + kstring_t tmp = {0,0,0}; + i = j = n = 0; + while ( hdr->s[idx+i] && hdr->s[idx+i]) + { + if ( hdr->s[idx+i]=='\t' ) + { + hdr->s[idx+i] = 0; + + if ( ++n>9 ) + { + char *ori = khash_str2str_get(hash,hdr->s+idx+j); + kputs(ori ? ori : hdr->s+idx+j, &tmp); + } + else + kputs(hdr->s+idx+j, &tmp); + + kputc('\t',&tmp); + + j = ++i; + continue; + } + i++; + } + char *ori = khash_str2str_get(hash,hdr->s+idx+j); + kputs(ori ? ori : hdr->s+idx+j, &tmp); + + khash_str2str_destroy_free_all(hash); + + hdr->l = idx; + kputs(tmp.s, hdr); + kputc('\n', hdr); + free(tmp.s); + + return 1; +} + +static void set_samples(char **samples, int nsamples, kstring_t *hdr) +{ + // Find the beginning of the #CHROM line + int i = hdr->l - 2, ncols = 0; + while ( i>=0 && hdr->s[i]!='\n' ) + { + if ( hdr->s[i]=='\t' ) ncols++; + i--; + } + if ( i<0 || strncmp(hdr->s+i+1,"#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT",45) ) error("Could not parse the header: %s\n", hdr->s); + + // Are the samples "old-sample new-sample" pairs? + if ( set_sample_pairs(samples,nsamples,hdr, i+1) ) return; + + // Replace all samples + if ( ncols!=nsamples+8 ) + fprintf(bcftools_stderr, "Warning: different number of samples: %d vs %d\n", nsamples,ncols-8); + + ncols = 0; + while ( ncols!=9 ) + { + i++; + if ( hdr->s[i]=='\t' ) ncols++; + } + hdr->l = i; + + for (i=0; ifp); + if ( !fp || bgzf_read_block(fp) != 0 || !fp->block_length ) + error("Failed to read %s: %s\n", args->fname, strerror(errno)); + + kstring_t hdr = {0,0,0}; + char *buffer = (char*) fp->uncompressed_block; + + // Read the header and find the position of the data block + if ( buffer[0]!='#' ) error("Could not parse the header, expected '#', found '%c'\n", buffer[0]); + + int skip_until = 1; // end of the header in the current uncompressed block + while (1) + { + if ( buffer[skip_until]=='\n' ) + { + skip_until++; + if ( skip_until>=fp->block_length ) + { + kputsn(buffer,skip_until,&hdr); + if ( bgzf_read_block(fp) != 0 ) error("Error reading %s\n", args->fname); + if ( !fp->block_length ) break; + skip_until = 0; + } + // The header has finished + if ( buffer[skip_until]!='#' ) + { + kputsn(buffer,skip_until,&hdr); + break; + } + } + skip_until++; + if ( skip_until>=fp->block_length ) + { + kputsn(buffer,fp->block_length,&hdr); + if ( bgzf_read_block(fp) != 0 ) error("Error reading %s\n", args->fname); + if ( !fp->block_length ) break; + skip_until = 0; + } + } + + int nsamples = 0; + char **samples = NULL; + if ( args->samples_fname ) + samples = hts_readlines(args->samples_fname, &nsamples); + if ( args->header_fname ) + { + free(hdr.s); hdr.s = NULL; hdr.l = hdr.m = 0; + read_header_file(args->header_fname, &hdr); + } + if ( samples ) + { + set_samples(samples, nsamples, &hdr); + int i; + for (i=0; ioutput_fname ? args->output_fname : "-","w");; + if ( bgzf_write(bgzf_out, hdr.s, hdr.l) < 0 ) error("Can't write BGZF header (code %d)\n", bgzf_out->errcode); + free(hdr.s); + + // Output all remainig data read with the header block + if ( fp->block_length - skip_until > 0 ) + { + if ( bgzf_write(bgzf_out, buffer+skip_until, fp->block_length-skip_until)<0 ) error("Error: %d\n",fp->errcode); + } + if ( bgzf_flush(bgzf_out)<0 ) error("Error: %d\n",bgzf_out->errcode); + + // Stream the rest of the file without as it is, without decompressing + ssize_t nread; + const size_t page_size = 32768; + char *buf = (char*) malloc(page_size); + while (1) + { + nread = bgzf_raw_read(fp, buf, page_size); + if ( nread<=0 ) break; + + int count = bgzf_raw_write(bgzf_out, buf, nread); + if (count != nread) error("Write failed, wrote %d instead of %d bytes.\n", count,(int)nread); + } + if (bgzf_close(bgzf_out) < 0) error("Error closing %s: %d\n",args->output_fname ? args->output_fname : "-",bgzf_out->errcode); + if (hts_close(args->fp)) error("Error closing %s: %d\n",args->fname,fp->errcode); + free(buf); +} +static void reheader_vcf(args_t *args) +{ + kstring_t hdr = {0,0,0}; + htsFile *fp = args->fp; + while ( hts_getline(fp, KS_SEP_LINE, &fp->line) >=0 ) + { + kputc('\n',&fp->line); // hts_getline eats the newline character + if ( fp->line.s[0]!='#' ) break; + kputsn(fp->line.s,fp->line.l,&hdr); + } + + int nsamples = 0; + char **samples = NULL; + if ( args->samples_fname ) + samples = hts_readlines(args->samples_fname, &nsamples); + if ( args->header_fname ) + { + free(hdr.s); hdr.s = NULL; hdr.l = hdr.m = 0; + read_header_file(args->header_fname, &hdr); + } + if ( samples ) + { + set_samples(samples, nsamples, &hdr); + int i; + for (i=0; ioutput_fname ? open(args->output_fname, O_WRONLY|O_CREAT|O_TRUNC, 0666) : STDOUT_FILENO; + if ( out==-1 ) error("%s: %s\n", args->output_fname,strerror(errno)); + if ( write(out, hdr.s, hdr.l)!=hdr.l ) error("Failed to write %d bytes\n", hdr.l); + free(hdr.s); + if ( fp->line.l ) + { + if ( write(out, fp->line.s, fp->line.l)!=fp->line.l ) error("Failed to write %d bytes\n", fp->line.l); + } + while ( hts_getline(fp, KS_SEP_LINE, &fp->line) >=0 ) // uncompressed file implies small size, we don't worry about speed + { + kputc('\n',&fp->line); + if ( write(out, fp->line.s, fp->line.l)!=fp->line.l ) error("Failed to write %d bytes\n", fp->line.l); + } + hts_close(fp); + close(out); +} + +static bcf_hdr_t *strip_header(bcf_hdr_t *src, bcf_hdr_t *dst) +{ + bcf_hrec_t *src_hrec, *dst_hrec, *tmp; + bcf_hdr_t *out = bcf_hdr_init("r"); + int i; + for (i=0; inhrec; i++) + { + // first insert lines which do not code BCF ids, their order does not matter + dst_hrec = dst->hrec[i]; + if ( dst_hrec->type==BCF_HL_FLT || dst_hrec->type==BCF_HL_INFO || dst_hrec->type==BCF_HL_FMT || dst_hrec->type== BCF_HL_CTG ) continue; + bcf_hdr_add_hrec(out, bcf_hrec_dup(dst_hrec)); + } + for (i=0; inhrec; i++) + { + // now transfer header lines which define BCF ids + src_hrec = src->hrec[i]; + + if ( src_hrec->type==BCF_HL_FLT || src_hrec->type==BCF_HL_INFO || src_hrec->type==BCF_HL_FMT || src_hrec->type== BCF_HL_CTG ) + { + int j = bcf_hrec_find_key(src_hrec, "ID"); + dst_hrec = bcf_hdr_get_hrec(dst, src_hrec->type, "ID", src_hrec->vals[j], NULL); + if ( !dst_hrec ) continue; + + tmp = bcf_hrec_dup(dst_hrec); + + j = bcf_hrec_find_key(src_hrec, "IDX"); + if ( j>=0 ) + { + j = atoi(src_hrec->vals[j]); + hrec_add_idx(tmp, j); + } + bcf_hdr_add_hrec(out, tmp); + } + } + bcf_hdr_sync(out); + for (i=0; inhrec; i++) + { + // finally add new structured fields + dst_hrec = dst->hrec[i]; + if ( dst_hrec->type==BCF_HL_FLT || dst_hrec->type==BCF_HL_INFO || dst_hrec->type==BCF_HL_FMT || dst_hrec->type== BCF_HL_CTG ) + { + int j = bcf_hrec_find_key(dst_hrec, "ID"); + tmp = bcf_hdr_get_hrec(out, dst_hrec->type, "ID", dst_hrec->vals[j], NULL); + if ( !tmp ) + bcf_hdr_add_hrec(out, bcf_hrec_dup(dst_hrec)); + } + } + for (i=0; in[BCF_DT_SAMPLE]; i++) bcf_hdr_add_sample(out, dst->samples[i]); + bcf_hdr_destroy(dst); + return out; +} + +static void reheader_bcf(args_t *args, int is_compressed) +{ + htsFile *fp = args->fp; + bcf_hdr_t *hdr = bcf_hdr_read(fp); if ( !hdr ) error("Failed to read the header: %s\n", args->fname); + kstring_t htxt = {0,0,0}; + bcf_hdr_format(hdr, 1, &htxt); + + int i, nsamples = 0; + char **samples = NULL; + if ( args->samples_fname ) + samples = hts_readlines(args->samples_fname, &nsamples); + if ( args->header_fname ) + { + free(htxt.s); htxt.s = NULL; htxt.l = htxt.m = 0; + read_header_file(args->header_fname, &htxt); + } + if ( samples ) + { + set_samples(samples, nsamples, &htxt); + for (i=0; iheader_fname ) hdr_out = strip_header(hdr, hdr_out); + + // write the header and the body + htsFile *fp_out = hts_open(args->output_fname ? args->output_fname : "-",is_compressed ? "wb" : "wbu"); + if ( !fp_out ) error("%s: %s\n", args->output_fname ? args->output_fname : "-", strerror(errno)); + bcf_hdr_write(fp_out, hdr_out); + + bcf1_t *rec = bcf_init(); + while ( bcf_read(fp, hdr, rec)==0 ) + { + // sanity checking, this slows things down. Make it optional? + bcf_unpack(rec, BCF_UN_ALL); + if ( rec->rid >= hdr_out->n[BCF_DT_CTG] || strcmp(bcf_hdr_int2id(hdr,BCF_DT_CTG,rec->rid),bcf_hdr_int2id(hdr_out,BCF_DT_CTG,rec->rid)) ) + error("The CHROM is not defined: \"%s\"\n", bcf_hdr_int2id(hdr,BCF_DT_CTG,rec->rid)); + + for (i=0; id.n_flt; i++) + { + int id = rec->d.flt[i]; + if ( id >= hdr_out->n[BCF_DT_ID] ) break; + if ( !bcf_hdr_idinfo_exists(hdr_out,BCF_HL_FLT,id) ) break; + if ( strcmp(hdr->id[BCF_DT_ID][id].key,hdr_out->id[BCF_DT_ID][id].key) ) + error("FIXME: Broken FILTER ids: %s vs %s\n", hdr->id[BCF_DT_ID][id].key,hdr_out->id[BCF_DT_ID][id].key); + } + if ( i!=rec->d.n_flt ) + error("The FILTER is not defined: \"%s\"\n", bcf_hdr_int2id(hdr,BCF_DT_ID,rec->d.flt[i])); + + for (i=0; in_info; i++) + { + int id = rec->d.info[i].key; + if ( id >= hdr_out->n[BCF_DT_ID] ) break; + if ( !hdr_out->id[BCF_DT_ID][id].key ) break; + if ( !bcf_hdr_idinfo_exists(hdr_out,BCF_HL_INFO,id) ) break; + if ( strcmp(hdr->id[BCF_DT_ID][id].key,hdr_out->id[BCF_DT_ID][id].key) ) + error("FIXME: Broken INFO ids: %s vs %s\n", hdr->id[BCF_DT_ID][id].key,hdr_out->id[BCF_DT_ID][id].key); + } + if ( i!=rec->n_info ) + error("The INFO tag is not defined: \"%s\"\n", bcf_hdr_int2id(hdr,BCF_DT_ID,rec->d.info[i].key)); + + for (i=0; in_fmt; i++) + { + int id = rec->d.fmt[i].id; + if ( id >= hdr_out->n[BCF_DT_ID] ) break; + if ( !hdr_out->id[BCF_DT_ID][id].key ) break; + if ( !bcf_hdr_idinfo_exists(hdr_out,BCF_HL_FMT,id) ) break; + if ( strcmp(hdr->id[BCF_DT_ID][id].key,hdr_out->id[BCF_DT_ID][id].key) ) + error("FIXME: Broken FORMAT ids: %s vs %s\n", hdr->id[BCF_DT_ID][id].key,hdr_out->id[BCF_DT_ID][id].key); + } + if ( i!=rec->n_fmt ) + error("The FORMAT tag is not defined: \"%s\"\n", bcf_hdr_int2id(hdr,BCF_DT_ID,rec->d.fmt[i].id)); + + bcf_write(fp_out,hdr_out,rec); + } + bcf_destroy(rec); + + free(htxt.s); + hts_close(fp_out); + hts_close(fp); + bcf_hdr_destroy(hdr_out); + bcf_hdr_destroy(hdr); +} + + +static void usage(args_t *args) +{ + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Modify header of VCF/BCF files, change sample names.\n"); + fprintf(bcftools_stderr, "Usage: bcftools reheader [OPTIONS] \n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Options:\n"); + fprintf(bcftools_stderr, " -h, --header new header\n"); + fprintf(bcftools_stderr, " -o, --output write output to a file [standard output]\n"); + fprintf(bcftools_stderr, " -s, --samples new sample names\n"); + fprintf(bcftools_stderr, "\n"); + exit(1); +} + +int main_reheader(int argc, char *argv[]) +{ + int c; + args_t *args = (args_t*) calloc(1,sizeof(args_t)); + args->argc = argc; args->argv = argv; + + static struct option loptions[] = + { + {"output",1,0,'o'}, + {"header",1,0,'h'}, + {"samples",1,0,'s'}, + {0,0,0,0} + }; + while ((c = getopt_long(argc, argv, "s:h:o:",loptions,NULL)) >= 0) + { + switch (c) + { + case 'o': args->output_fname = optarg; break; + case 's': args->samples_fname = optarg; break; + case 'h': args->header_fname = optarg; break; + case '?': usage(args); + default: error("Unknown argument: %s\n", optarg); + } + } + + if ( optind>=argc ) + { + if ( !isatty(fileno((FILE *)stdin)) ) args->fname = "-"; // reading from stdin + else usage(args); + } + else args->fname = argv[optind]; + + if ( !args->samples_fname && !args->header_fname ) usage(args); + if ( !args->fname ) usage(args); + + args->fp = hts_open(args->fname,"r"); + if ( !args->fp ) error("Failed to open: %s\n", args->fname); + args->type = *hts_get_format(args->fp); + + if ( args->type.format==vcf ) + { + if ( args->type.compression==bgzf || args->type.compression==gzip ) + reheader_vcf_gz(args); + else + reheader_vcf(args); + } + else + reheader_bcf(args, args->type.compression==bgzf || args->type.compression==gzip); + + free(args); + return 0; +} diff --git a/bcftools/smpl_ilist.c b/bcftools/smpl_ilist.c new file mode 100644 index 000000000..c7fa913c1 --- /dev/null +++ b/bcftools/smpl_ilist.c @@ -0,0 +1,106 @@ +/* + Copyright (C) 2016 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "bcftools.h" +#include "smpl_ilist.h" + +void smpl_ilist_destroy(smpl_ilist_t *smpl) +{ + free(smpl->idx); + free(smpl); +} + +smpl_ilist_t *smpl_ilist_init(bcf_hdr_t *hdr, char *sample_list, int is_file, int flags) +{ + smpl_ilist_t *smpl = (smpl_ilist_t*) calloc(1,sizeof(smpl_ilist_t)); + + int i; + if ( !sample_list ) + { + smpl->n = bcf_hdr_nsamples(hdr); + smpl->idx = (int*) malloc(sizeof(int)*smpl->n); + for (i=0; in; i++) smpl->idx[i] = i; + return smpl; + } + + int nlist; + char **list = hts_readlist(sample_list[0]=='^'?sample_list+1:sample_list, is_file, &nlist); + if ( !list ) error("Could not parse %s\n", sample_list); + + // preserve the VCF order + int *tmp = (int*)calloc(bcf_hdr_nsamples(hdr),sizeof(int)); + for (i=0; i=0 ) + { + tmp[idx] = 1; + smpl->n++; + } + else if ( flags&SMPL_STRICT ) + error("No such sample: %s\n", list[i]); + } + + if ( sample_list[0]=='^' ) smpl->n = bcf_hdr_nsamples(hdr) - smpl->n; + smpl->idx = (int*) malloc(sizeof(int)*smpl->n); + + int j = 0; + if ( sample_list[0]!='^' ) + { + for (i=0; iidx[j++] = i; + } + else + { + for (i=0; iidx[j++] = i; + } + + free(tmp); + for (i=0; in = bcf_hdr_nsamples(hdr_a); + smpl->idx = (int*) malloc(sizeof(int)*smpl->n); + for (i=0; in; i++) + { + const char *name = bcf_hdr_int2id(hdr_a, BCF_DT_SAMPLE, i); + smpl->idx[i] = bcf_hdr_id2int(hdr_b, BCF_DT_SAMPLE, name); + if ( flags&SMPL_STRICT && smpl->idx[i]<0 ) + error("The sample %s is not present in the second file\n", name); + } + return smpl; +} + diff --git a/bcftools/smpl_ilist.c.pysam.c b/bcftools/smpl_ilist.c.pysam.c new file mode 100644 index 000000000..36f22a668 --- /dev/null +++ b/bcftools/smpl_ilist.c.pysam.c @@ -0,0 +1,108 @@ +#include "bcftools.pysam.h" + +/* + Copyright (C) 2016 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "bcftools.h" +#include "smpl_ilist.h" + +void smpl_ilist_destroy(smpl_ilist_t *smpl) +{ + free(smpl->idx); + free(smpl); +} + +smpl_ilist_t *smpl_ilist_init(bcf_hdr_t *hdr, char *sample_list, int is_file, int flags) +{ + smpl_ilist_t *smpl = (smpl_ilist_t*) calloc(1,sizeof(smpl_ilist_t)); + + int i; + if ( !sample_list ) + { + smpl->n = bcf_hdr_nsamples(hdr); + smpl->idx = (int*) malloc(sizeof(int)*smpl->n); + for (i=0; in; i++) smpl->idx[i] = i; + return smpl; + } + + int nlist; + char **list = hts_readlist(sample_list[0]=='^'?sample_list+1:sample_list, is_file, &nlist); + if ( !list ) error("Could not parse %s\n", sample_list); + + // preserve the VCF order + int *tmp = (int*)calloc(bcf_hdr_nsamples(hdr),sizeof(int)); + for (i=0; i=0 ) + { + tmp[idx] = 1; + smpl->n++; + } + else if ( flags&SMPL_STRICT ) + error("No such sample: %s\n", list[i]); + } + + if ( sample_list[0]=='^' ) smpl->n = bcf_hdr_nsamples(hdr) - smpl->n; + smpl->idx = (int*) malloc(sizeof(int)*smpl->n); + + int j = 0; + if ( sample_list[0]!='^' ) + { + for (i=0; iidx[j++] = i; + } + else + { + for (i=0; iidx[j++] = i; + } + + free(tmp); + for (i=0; in = bcf_hdr_nsamples(hdr_a); + smpl->idx = (int*) malloc(sizeof(int)*smpl->n); + for (i=0; in; i++) + { + const char *name = bcf_hdr_int2id(hdr_a, BCF_DT_SAMPLE, i); + smpl->idx[i] = bcf_hdr_id2int(hdr_b, BCF_DT_SAMPLE, name); + if ( flags&SMPL_STRICT && smpl->idx[i]<0 ) + error("The sample %s is not present in the second file\n", name); + } + return smpl; +} + diff --git a/bcftools/smpl_ilist.h b/bcftools/smpl_ilist.h new file mode 100644 index 000000000..7083cf2ae --- /dev/null +++ b/bcftools/smpl_ilist.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2016 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ +/* + Parse --samples and --samples-file +*/ + +#ifndef __SMPL_ILIST_H__ +#define __SMPL_ILIST_H__ + +#include + +#define SMPL_NONE 0 // flexible error recovery +#define SMPL_STRICT 1 // samples must exist + +typedef struct +{ + int *idx; // index to bcf_hdr_t.samples + int n; +} +smpl_ilist_t; + +smpl_ilist_t *smpl_ilist_init(bcf_hdr_t *hdr, char *sample_list, int is_file, int flags); +smpl_ilist_t *smpl_ilist_map(bcf_hdr_t *hdr_a, bcf_hdr_t *hdr_b, int flags); +void smpl_ilist_destroy(smpl_ilist_t *smpl); + +#endif diff --git a/bcftools/tabix.c b/bcftools/tabix.c index 2f24b92d2..c1874c22b 100644 --- a/bcftools/tabix.c +++ b/bcftools/tabix.c @@ -1,7 +1,7 @@ /* tabix.c -- tabix subcommand. Copyright (C) 2012 Broad Institute. - Copyright (C) 2013 Genome Research Ltd. + Copyright (C) 2013, 2016 Genome Research Ltd. Author: Heng Li @@ -32,8 +32,8 @@ THE SOFTWARE. */ int main_tabix(int argc, char *argv[]) { - int c, min_shift = -1, is_force = 0, is_all = 0; - tbx_conf_t conf = tbx_conf_gff, *conf_ptr = NULL; + int c, min_shift = -1, is_force = 0, is_all = 0, detect = 1; + tbx_conf_t conf = tbx_conf_gff; while ((c = getopt(argc, argv, "0fap:s:b:e:S:c:m:")) >= 0) if (c == '0') conf.preset |= TBX_UCSC; else if (c == 'f') is_force = 1; @@ -45,13 +45,14 @@ int main_tabix(int argc, char *argv[]) else if (c == 'c') conf.meta_char = *optarg; else if (c == 'S') conf.line_skip = atoi(optarg); else if (c == 'p') { - if (strcmp(optarg, "gff") == 0) conf_ptr = &tbx_conf_gff; - else if (strcmp(optarg, "bed") == 0) conf_ptr = &tbx_conf_bed; - else if (strcmp(optarg, "sam") == 0) conf_ptr = &tbx_conf_sam; - else if (strcmp(optarg, "vcf") == 0) conf_ptr = &tbx_conf_vcf; + if (strcmp(optarg, "gff") == 0) conf = tbx_conf_gff; + else if (strcmp(optarg, "bed") == 0) conf = tbx_conf_bed; + else if (strcmp(optarg, "sam") == 0) conf = tbx_conf_sam; + else if (strcmp(optarg, "vcf") == 0) conf = tbx_conf_vcf; else { fprintf(stderr, "The type '%s' not recognised\n", optarg); return 1; + detect = 0; } } @@ -79,28 +80,29 @@ int main_tabix(int argc, char *argv[]) bgzf_close(fp); free(s.s); } else if (optind + 2 > argc) { // create index - if ( !conf_ptr ) + if ( detect ) { // auto-detect file type by file name int l = strlen(argv[optind]); int strcasecmp(const char *s1, const char *s2); - if (l>=7 && strcasecmp(argv[optind]+l-7, ".gff.gz") == 0) conf_ptr = &tbx_conf_gff; - else if (l>=7 && strcasecmp(argv[optind]+l-7, ".bed.gz") == 0) conf_ptr = &tbx_conf_bed; - else if (l>=7 && strcasecmp(argv[optind]+l-7, ".sam.gz") == 0) conf_ptr = &tbx_conf_sam; - else if (l>=7 && strcasecmp(argv[optind]+l-7, ".vcf.gz") == 0) conf_ptr = &tbx_conf_vcf; + if (l>=7 && strcasecmp(argv[optind]+l-7, ".gff.gz") == 0) conf = tbx_conf_gff; + else if (l>=7 && strcasecmp(argv[optind]+l-7, ".bed.gz") == 0) conf = tbx_conf_bed; + else if (l>=7 && strcasecmp(argv[optind]+l-7, ".sam.gz") == 0) conf = tbx_conf_sam; + else if (l>=7 && strcasecmp(argv[optind]+l-7, ".vcf.gz") == 0) conf = tbx_conf_vcf; } - if ( conf_ptr ) conf = *conf_ptr; if (!is_force) { char *fn; FILE *fp; - fn = (char*)alloca(strlen(argv[optind]) + 5); + fn = (char*)malloc(strlen(argv[optind]) + 5); strcat(strcpy(fn, argv[optind]), min_shift <= 0? ".tbi" : ".csi"); if ((fp = fopen(fn, "rb")) != 0) { fclose(fp); + free(fn); fprintf(stderr, "[E::%s] the index file exists; use option '-f' to overwrite\n", __func__); return 1; } + free(fn); } if ( tbx_index_build(argv[optind], min_shift, &conf) ) { diff --git a/bcftools/tabix.c.pysam.c b/bcftools/tabix.c.pysam.c index afa361920..ba9e1b31f 100644 --- a/bcftools/tabix.c.pysam.c +++ b/bcftools/tabix.c.pysam.c @@ -1,9 +1,9 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* tabix.c -- tabix subcommand. Copyright (C) 2012 Broad Institute. - Copyright (C) 2013 Genome Research Ltd. + Copyright (C) 2013, 2016 Genome Research Ltd. Author: Heng Li @@ -34,8 +34,8 @@ THE SOFTWARE. */ int main_tabix(int argc, char *argv[]) { - int c, min_shift = -1, is_force = 0, is_all = 0; - tbx_conf_t conf = tbx_conf_gff, *conf_ptr = NULL; + int c, min_shift = -1, is_force = 0, is_all = 0, detect = 1; + tbx_conf_t conf = tbx_conf_gff; while ((c = getopt(argc, argv, "0fap:s:b:e:S:c:m:")) >= 0) if (c == '0') conf.preset |= TBX_UCSC; else if (c == 'f') is_force = 1; @@ -47,29 +47,30 @@ int main_tabix(int argc, char *argv[]) else if (c == 'c') conf.meta_char = *optarg; else if (c == 'S') conf.line_skip = atoi(optarg); else if (c == 'p') { - if (strcmp(optarg, "gff") == 0) conf_ptr = &tbx_conf_gff; - else if (strcmp(optarg, "bed") == 0) conf_ptr = &tbx_conf_bed; - else if (strcmp(optarg, "sam") == 0) conf_ptr = &tbx_conf_sam; - else if (strcmp(optarg, "vcf") == 0) conf_ptr = &tbx_conf_vcf; + if (strcmp(optarg, "gff") == 0) conf = tbx_conf_gff; + else if (strcmp(optarg, "bed") == 0) conf = tbx_conf_bed; + else if (strcmp(optarg, "sam") == 0) conf = tbx_conf_sam; + else if (strcmp(optarg, "vcf") == 0) conf = tbx_conf_vcf; else { - fprintf(pysam_stderr, "The type '%s' not recognised\n", optarg); + fprintf(bcftools_stderr, "The type '%s' not recognised\n", optarg); return 1; + detect = 0; } } if (optind == argc) { - fprintf(pysam_stderr, "\nUsage: bcftools tabix [options] [reg1 [...]]\n\n"); - fprintf(pysam_stderr, "Options: -p STR preset: gff, bed, sam or vcf [gff]\n"); - fprintf(pysam_stderr, " -s INT column number for sequence names (suppressed by -p) [1]\n"); - fprintf(pysam_stderr, " -b INT column number for region start [4]\n"); - fprintf(pysam_stderr, " -e INT column number for region end (if no end, set INT to -b) [5]\n"); - fprintf(pysam_stderr, " -0 specify coordinates are zero-based\n"); - fprintf(pysam_stderr, " -S INT skip first INT lines [0]\n"); - fprintf(pysam_stderr, " -c CHAR skip lines starting with CHAR [null]\n"); - fprintf(pysam_stderr, " -a print all records\n"); - fprintf(pysam_stderr, " -f force to overwrite existing index\n"); - fprintf(pysam_stderr, " -m INT set the minimal interval size to 1< [reg1 [...]]\n\n"); + fprintf(bcftools_stderr, "Options: -p STR preset: gff, bed, sam or vcf [gff]\n"); + fprintf(bcftools_stderr, " -s INT column number for sequence names (suppressed by -p) [1]\n"); + fprintf(bcftools_stderr, " -b INT column number for region start [4]\n"); + fprintf(bcftools_stderr, " -e INT column number for region end (if no end, set INT to -b) [5]\n"); + fprintf(bcftools_stderr, " -0 specify coordinates are zero-based\n"); + fprintf(bcftools_stderr, " -S INT skip first INT lines [0]\n"); + fprintf(bcftools_stderr, " -c CHAR skip lines starting with CHAR [null]\n"); + fprintf(bcftools_stderr, " -a print all records\n"); + fprintf(bcftools_stderr, " -f force to overwrite existing index\n"); + fprintf(bcftools_stderr, " -m INT set the minimal interval size to 1<= 0) fputs(s.s, pysam_stdout) & fputc('\n', pysam_stdout); + while (bgzf_getline(fp, '\n', &s) >= 0) fputs(s.s, bcftools_stdout) & fputc('\n', bcftools_stdout); bgzf_close(fp); free(s.s); } else if (optind + 2 > argc) { // create index - if ( !conf_ptr ) + if ( detect ) { // auto-detect file type by file name int l = strlen(argv[optind]); int strcasecmp(const char *s1, const char *s2); - if (l>=7 && strcasecmp(argv[optind]+l-7, ".gff.gz") == 0) conf_ptr = &tbx_conf_gff; - else if (l>=7 && strcasecmp(argv[optind]+l-7, ".bed.gz") == 0) conf_ptr = &tbx_conf_bed; - else if (l>=7 && strcasecmp(argv[optind]+l-7, ".sam.gz") == 0) conf_ptr = &tbx_conf_sam; - else if (l>=7 && strcasecmp(argv[optind]+l-7, ".vcf.gz") == 0) conf_ptr = &tbx_conf_vcf; + if (l>=7 && strcasecmp(argv[optind]+l-7, ".gff.gz") == 0) conf = tbx_conf_gff; + else if (l>=7 && strcasecmp(argv[optind]+l-7, ".bed.gz") == 0) conf = tbx_conf_bed; + else if (l>=7 && strcasecmp(argv[optind]+l-7, ".sam.gz") == 0) conf = tbx_conf_sam; + else if (l>=7 && strcasecmp(argv[optind]+l-7, ".vcf.gz") == 0) conf = tbx_conf_vcf; } - if ( conf_ptr ) conf = *conf_ptr; if (!is_force) { char *fn; FILE *fp; - fn = (char*)alloca(strlen(argv[optind]) + 5); + fn = (char*)malloc(strlen(argv[optind]) + 5); strcat(strcpy(fn, argv[optind]), min_shift <= 0? ".tbi" : ".csi"); if ((fp = fopen(fn, "rb")) != 0) { fclose(fp); - fprintf(pysam_stderr, "[E::%s] the index file exists; use option '-f' to overwrite\n", __func__); + free(fn); + fprintf(bcftools_stderr, "[E::%s] the index file exists; use option '-f' to overwrite\n", __func__); return 1; } + free(fn); } if ( tbx_index_build(argv[optind], min_shift, &conf) ) { - fprintf(pysam_stderr,"tbx_index_build failed: Is the file bgzip-compressed? Was wrong -p [type] option used?\n"); + fprintf(bcftools_stderr,"tbx_index_build failed: Is the file bgzip-compressed? Was wrong -p [type] option used?\n"); return 1; } } else { // read with random access @@ -120,7 +122,7 @@ int main_tabix(int argc, char *argv[]) for (i = optind + 1; i < argc; ++i) { hts_itr_t *itr; if ((itr = tbx_itr_querys(tbx, argv[i])) == 0) continue; - while (tbx_bgzf_itr_next(fp, tbx, itr, &s) >= 0) fputs(s.s, pysam_stdout) & fputc('\n', pysam_stdout); + while (tbx_bgzf_itr_next(fp, tbx, itr, &s) >= 0) fputs(s.s, bcftools_stdout) & fputc('\n', bcftools_stdout); tbx_itr_destroy(itr); } free(s.s); diff --git a/bcftools/tsv2vcf.c b/bcftools/tsv2vcf.c index 8826f186e..2e1aa529f 100644 --- a/bcftools/tsv2vcf.c +++ b/bcftools/tsv2vcf.c @@ -24,6 +24,7 @@ */ #include +#include #include "tsv2vcf.h" tsv_t *tsv_init(const char *str) diff --git a/bcftools/tsv2vcf.c.pysam.c b/bcftools/tsv2vcf.c.pysam.c index 1da48d5af..f6aabf543 100644 --- a/bcftools/tsv2vcf.c.pysam.c +++ b/bcftools/tsv2vcf.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* tsv2vcf.c -- convert from whitespace-separated fields to VCF @@ -26,6 +26,7 @@ */ #include +#include #include "tsv2vcf.h" tsv_t *tsv_init(const char *str) diff --git a/bcftools/vcfannotate.c b/bcftools/vcfannotate.c index d5164f333..abea98f90 100644 --- a/bcftools/vcfannotate.c +++ b/bcftools/vcfannotate.c @@ -1,6 +1,6 @@ /* vcfannotate.c -- Annotate and edit VCF/BCF files. - Copyright (C) 2013-2016 Genome Research Ltd. + Copyright (C) 2013-2018 Genome Research Ltd. Author: Petr Danecek @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#include #include #include #include @@ -41,6 +42,7 @@ THE SOFTWARE. */ #include "vcmp.h" #include "filter.h" #include "convert.h" +#include "smpl_ilist.h" struct _args_t; @@ -65,12 +67,12 @@ annot_line_t; #define REPLACE_MISSING 0 // replace only missing values #define REPLACE_ALL 1 // replace both missing and existing values -#define REPLACE_EXISTING 2 // replace only if tgt is not missing +#define REPLACE_NON_MISSING 2 // replace only if tgt is not missing #define SET_OR_APPEND 3 // set new value if missing or non-existent, append otherwise typedef struct _annot_col_t { int icol, replace, number; // number: one of BCF_VL_* types - char *hdr_key; + char *hdr_key_src, *hdr_key_dst; int (*setter)(struct _args_t *, bcf1_t *, struct _annot_col_t *, void*); } annot_col_t; @@ -93,6 +95,7 @@ typedef struct _args_t filter_t *filter; char *filter_str; int filter_logic; // include or exclude sites which match the filters? One of FLT_INCLUDE/FLT_EXCLUDE + int keep_sites; rm_tag_t *rm; // tags scheduled for removal int nrm; @@ -109,6 +112,7 @@ typedef struct _args_t convert_t *set_ids; int set_ids_replace; + int nsmpl_annot; int *sample_map, nsample_map, sample_is_file; // map[idst] -> isrc int mtmpi, mtmpf, mtmps; int mtmpi2, mtmpf2, mtmps2; @@ -155,6 +159,7 @@ void remove_info(args_t *args, bcf1_t *line, rm_tag_t *tag) } line->d.shared_dirty |= BCF1_DIRTY_INF; inf->vptr = NULL; + inf->vptr_off = inf->vptr_len = 0; } } void remove_info_tag(args_t *args, bcf1_t *line, rm_tag_t *tag) @@ -187,6 +192,10 @@ void remove_format(args_t *args, bcf1_t *line, rm_tag_t *tag) } } +#include "htslib/khash.h" +KHASH_MAP_INIT_STR(vdict, bcf_idinfo_t) +typedef khash_t(vdict) vdict_t; + static void remove_hdr_lines(bcf_hdr_t *hdr, int type) { int i = 0, nrm = 0; @@ -194,11 +203,18 @@ static void remove_hdr_lines(bcf_hdr_t *hdr, int type) { if ( hdr->hrec[i]->type!=type ) { i++; continue; } bcf_hrec_t *hrec = hdr->hrec[i]; - if ( type==BCF_HL_FMT ) + if ( type==BCF_HL_FMT || type==BCF_HL_INFO || type==BCF_HL_FMT || type== BCF_HL_CTG ) { // everything except FORMAT/GT int id = bcf_hrec_find_key(hrec, "ID"); - if ( id>=0 && !strcmp(hrec->vals[id],"GT") ) { i++; continue; } + if ( id>=0 ) + { + if ( type==BCF_HL_FMT && !strcmp(hrec->vals[id],"GT") ) { i++; continue; } + vdict_t *d = type==BCF_HL_CTG ? (vdict_t*)hdr->dict[BCF_DT_CTG] : (vdict_t*)hdr->dict[BCF_DT_ID]; + khint_t k = kh_get(vdict, d, hdr->hrec[i]->vals[id]); + kh_val(d, k).hrec[type==BCF_HL_CTG?0:type] = NULL; + kh_val(d, k).info[type] |= 0xf; + } } nrm++; hdr->nhrec--; @@ -248,7 +264,7 @@ static void init_remove_annots(args_t *args) tag->key = strdup(str.s); tag->hdr_id = bcf_hdr_id2int(args->hdr, BCF_DT_ID, tag->key); if ( !bcf_hdr_idinfo_exists(args->hdr,BCF_HL_FLT,tag->hdr_id) ) error("Cannot remove %s, not defined in the header.\n", str.s); - bcf_hdr_remove(args->hdr_out,BCF_HL_FLT,tag->key); + if ( !args->keep_sites ) bcf_hdr_remove(args->hdr_out,BCF_HL_FLT,tag->key); } else { @@ -278,32 +294,35 @@ static void init_remove_annots(args_t *args) tag->key = strdup(str.s); if ( type==BCF_HL_INFO ) tag->handler = remove_info_tag; else if ( type==BCF_HL_FMT ) tag->handler = remove_format_tag; - bcf_hdr_remove(args->hdr_out,type,tag->key); + if ( !args->keep_sites ) bcf_hdr_remove(args->hdr_out,type,tag->key); } } else if ( !strcasecmp("ID",str.s) ) tag->handler = remove_id; else if ( !strcasecmp("FILTER",str.s) ) { tag->handler = remove_filter; - remove_hdr_lines(args->hdr_out,BCF_HL_FLT); + if ( !args->keep_sites ) remove_hdr_lines(args->hdr_out,BCF_HL_FLT); } else if ( !strcasecmp("QUAL",str.s) ) tag->handler = remove_qual; else if ( !strcasecmp("INFO",str.s) ) { tag->handler = remove_info; - remove_hdr_lines(args->hdr_out,BCF_HL_INFO); + if ( !args->keep_sites ) remove_hdr_lines(args->hdr_out,BCF_HL_INFO); } else if ( !strcasecmp("FMT",str.s) || !strcasecmp("FORMAT",str.s) ) { tag->handler = remove_format; - remove_hdr_lines(args->hdr_out,BCF_HL_FMT); + if ( !args->keep_sites ) remove_hdr_lines(args->hdr_out,BCF_HL_FMT); } else if ( str.l ) { - if ( str.s[0]=='#' && str.s[1]=='#' ) - bcf_hdr_remove(args->hdr_out,BCF_HL_GEN,str.s+2); - else - bcf_hdr_remove(args->hdr_out,BCF_HL_STR,str.s); + if ( !args->keep_sites ) + { + if ( str.s[0]=='#' && str.s[1]=='#' ) + bcf_hdr_remove(args->hdr_out,BCF_HL_GEN,str.s+2); + else + bcf_hdr_remove(args->hdr_out,BCF_HL_STR,str.s); + } args->nrm--; } @@ -339,7 +358,7 @@ static void init_remove_annots(args_t *args) tag->hdr_id = bcf_hdr_id2int(args->hdr, BCF_DT_ID, hrec->vals[k]); } tag->key = strdup(hrec->vals[k]); - bcf_hdr_remove(args->hdr_out,hrec->type,tag->key); + if ( !args->keep_sites ) bcf_hdr_remove(args->hdr_out,hrec->type,tag->key); } } khash_str2int_destroy_free(keep); @@ -453,7 +472,7 @@ static int setter_qual(args_t *args, bcf1_t *line, annot_col_t *col, void *data) line->qual = strtod(str, &str); if ( str == tab->cols[col->icol] ) - error("Could not parse %s at %s:%d .. [%s]\n", col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); + error("Could not parse %s at %s:%d .. [%s]\n", col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); return 0; } static int vcf_setter_qual(args_t *args, bcf1_t *line, annot_col_t *col, void *data) @@ -470,31 +489,31 @@ static int setter_info_flag(args_t *args, bcf1_t *line, annot_col_t *col, void * char *str = tab->cols[col->icol]; if ( str[0]=='.' && str[1]==0 ) return 0; - if ( str[0]=='1' && str[1]==0 ) return bcf_update_info_flag(args->hdr_out,line,col->hdr_key,NULL,1); - if ( str[0]=='0' && str[1]==0 ) return bcf_update_info_flag(args->hdr_out,line,col->hdr_key,NULL,0); + if ( str[0]=='1' && str[1]==0 ) return bcf_update_info_flag(args->hdr_out,line,col->hdr_key_dst,NULL,1); + if ( str[0]=='0' && str[1]==0 ) return bcf_update_info_flag(args->hdr_out,line,col->hdr_key_dst,NULL,0); error("Could not parse %s at %s:%d .. [%s]\n", bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); return -1; } static int vcf_setter_info_flag(args_t *args, bcf1_t *line, annot_col_t *col, void *data) { bcf1_t *rec = (bcf1_t*) data; - int flag = bcf_get_info_flag(args->files->readers[1].header,rec,col->hdr_key,NULL,NULL); - bcf_update_info_flag(args->hdr_out,line,col->hdr_key,NULL,flag); + int flag = bcf_get_info_flag(args->files->readers[1].header,rec,col->hdr_key_src,NULL,NULL); + bcf_update_info_flag(args->hdr_out,line,col->hdr_key_dst,NULL,flag); return 0; } static int setter_ARinfo_int32(args_t *args, bcf1_t *line, annot_col_t *col, int nals, char **als, int ntmpi) { if ( col->number==BCF_VL_A && ntmpi!=nals-1 && (ntmpi!=1 || args->tmpi[0]!=bcf_int32_missing || args->tmpi[1]!=bcf_int32_vector_end) ) - error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpi,col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpi,col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); else if ( col->number==BCF_VL_R && ntmpi!=nals && (ntmpi!=1 || args->tmpi[0]!=bcf_int32_missing || args->tmpi[1]!=bcf_int32_vector_end) ) - error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpi,col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpi,col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); int ndst = col->number==BCF_VL_A ? line->n_allele - 1 : line->n_allele; int *map = vcmp_map_ARvalues(args->vcmp,ndst,nals,als,line->n_allele,line->d.allele); if ( !map ) error("REF alleles not compatible at %s:%d\n"); // fill in any missing values in the target VCF (or all, if not present) - int ntmpi2 = bcf_get_info_float(args->hdr, line, col->hdr_key, &args->tmpi2, &args->mtmpi2); + int ntmpi2 = bcf_get_info_float(args->hdr, line, col->hdr_key_dst, &args->tmpi2, &args->mtmpi2); if ( ntmpi2 < ndst ) hts_expand(int32_t,ndst,args->mtmpi2,args->tmpi2); int i; @@ -511,7 +530,7 @@ static int setter_ARinfo_int32(args_t *args, bcf1_t *line, annot_col_t *col, int args->tmpi2[i] = args->tmpi[ map[i] ]; } - bcf_update_info_int32(args->hdr_out,line,col->hdr_key,args->tmpi2,ndst); + bcf_update_info_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi2,ndst); return 0; } static int setter_info_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data) @@ -537,17 +556,17 @@ static int setter_info_int(args_t *args, bcf1_t *line, annot_col_t *col, void *d if ( col->replace==REPLACE_MISSING ) { - int ret = bcf_get_info_int32(args->hdr, line, col->hdr_key, &args->tmpi2, &args->mtmpi2); + int ret = bcf_get_info_int32(args->hdr, line, col->hdr_key_dst, &args->tmpi2, &args->mtmpi2); if ( ret>0 && args->tmpi2[0]!=bcf_int32_missing ) return 0; } - bcf_update_info_int32(args->hdr_out,line,col->hdr_key,args->tmpi,ntmpi); + bcf_update_info_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi,ntmpi); return 0; } static int vcf_setter_info_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data) { bcf1_t *rec = (bcf1_t*) data; - int ntmpi = bcf_get_info_int32(args->files->readers[1].header,rec,col->hdr_key,&args->tmpi,&args->mtmpi); + int ntmpi = bcf_get_info_int32(args->files->readers[1].header,rec,col->hdr_key_src,&args->tmpi,&args->mtmpi); if ( ntmpi < 0 ) return 0; // nothing to add if ( col->number==BCF_VL_A || col->number==BCF_VL_R ) @@ -555,26 +574,26 @@ static int vcf_setter_info_int(args_t *args, bcf1_t *line, annot_col_t *col, voi if ( col->replace==REPLACE_MISSING ) { - int ret = bcf_get_info_int32(args->hdr, line, col->hdr_key, &args->tmpi2, &args->mtmpi2); + int ret = bcf_get_info_int32(args->hdr, line, col->hdr_key_dst, &args->tmpi2, &args->mtmpi2); if ( ret>0 && args->tmpi2[0]!=bcf_int32_missing ) return 0; } - bcf_update_info_int32(args->hdr_out,line,col->hdr_key,args->tmpi,ntmpi); + bcf_update_info_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi,ntmpi); return 0; } static int setter_ARinfo_real(args_t *args, bcf1_t *line, annot_col_t *col, int nals, char **als, int ntmpf) { if ( col->number==BCF_VL_A && ntmpf!=nals-1 && (ntmpf!=1 || !bcf_float_is_missing(args->tmpf[0]) || !bcf_float_is_vector_end(args->tmpf[0])) ) - error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpf,col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpf,col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); else if ( col->number==BCF_VL_R && ntmpf!=nals && (ntmpf!=1 || !bcf_float_is_missing(args->tmpf[0]) || !bcf_float_is_vector_end(args->tmpf[0])) ) - error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpf,col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpf,col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); int ndst = col->number==BCF_VL_A ? line->n_allele - 1 : line->n_allele; int *map = vcmp_map_ARvalues(args->vcmp,ndst,nals,als,line->n_allele,line->d.allele); if ( !map ) error("REF alleles not compatible at %s:%d\n"); // fill in any missing values in the target VCF (or all, if not present) - int ntmpf2 = bcf_get_info_float(args->hdr, line, col->hdr_key, &args->tmpf2, &args->mtmpf2); + int ntmpf2 = bcf_get_info_float(args->hdr, line, col->hdr_key_dst, &args->tmpf2, &args->mtmpf2); if ( ntmpf2 < ndst ) hts_expand(float,ndst,args->mtmpf2,args->tmpf2); int i; @@ -591,7 +610,7 @@ static int setter_ARinfo_real(args_t *args, bcf1_t *line, annot_col_t *col, int args->tmpf2[i] = args->tmpf[ map[i] ]; } - bcf_update_info_float(args->hdr_out,line,col->hdr_key,args->tmpf2,ndst); + bcf_update_info_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf2,ndst); return 0; } static int setter_info_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data) @@ -617,17 +636,17 @@ static int setter_info_real(args_t *args, bcf1_t *line, annot_col_t *col, void * if ( col->replace==REPLACE_MISSING ) { - int ret = bcf_get_info_float(args->hdr, line, col->hdr_key, &args->tmpf2, &args->mtmpf2); + int ret = bcf_get_info_float(args->hdr, line, col->hdr_key_dst, &args->tmpf2, &args->mtmpf2); if ( ret>0 && !bcf_float_is_missing(args->tmpf2[0]) ) return 0; } - bcf_update_info_float(args->hdr_out,line,col->hdr_key,args->tmpf,ntmpf); + bcf_update_info_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf,ntmpf); return 0; } static int vcf_setter_info_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data) { bcf1_t *rec = (bcf1_t*) data; - int ntmpf = bcf_get_info_float(args->files->readers[1].header,rec,col->hdr_key,&args->tmpf,&args->mtmpf); + int ntmpf = bcf_get_info_float(args->files->readers[1].header,rec,col->hdr_key_src,&args->tmpf,&args->mtmpf); if ( ntmpf < 0 ) return 0; // nothing to add if ( col->number==BCF_VL_A || col->number==BCF_VL_R ) @@ -635,11 +654,11 @@ static int vcf_setter_info_real(args_t *args, bcf1_t *line, annot_col_t *col, vo if ( col->replace==REPLACE_MISSING ) { - int ret = bcf_get_info_float(args->hdr, line, col->hdr_key, &args->tmpf2, &args->mtmpf2); + int ret = bcf_get_info_float(args->hdr, line, col->hdr_key_dst, &args->tmpf2, &args->mtmpf2); if ( ret>0 && !bcf_float_is_missing(args->tmpf2[0]) ) return 0; } - bcf_update_info_float(args->hdr_out,line,col->hdr_key,args->tmpf,ntmpf); + bcf_update_info_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf,ntmpf); return 0; } int copy_string_field(char *src, int isrc, int src_len, kstring_t *dst, int idst); // see vcfmerge.c @@ -652,9 +671,9 @@ static int setter_ARinfo_string(args_t *args, bcf1_t *line, annot_col_t *col, in lsrc++; } if ( col->number==BCF_VL_A && nsrc!=nals-1 && (nsrc!=1 || args->tmps[0]!='.' || args->tmps[1]!=0 ) ) - error("Incorrect number of values (%d) for the %s tag at %s:%d\n", nsrc,col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("Incorrect number of values (%d) for the %s tag at %s:%d\n", nsrc,col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); else if ( col->number==BCF_VL_R && nsrc!=nals && (nsrc!=1 || args->tmps[0]!='.' || args->tmps[1]!=0 ) ) - error("Incorrect number of values (%d) for the %s tag at %s:%d\n", nsrc,col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("Incorrect number of values (%d) for the %s tag at %s:%d\n", nsrc,col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); int ndst = col->number==BCF_VL_A ? line->n_allele - 1 : line->n_allele; int *map = vcmp_map_ARvalues(args->vcmp,ndst,nals,als,line->n_allele,line->d.allele); @@ -662,7 +681,7 @@ static int setter_ARinfo_string(args_t *args, bcf1_t *line, annot_col_t *col, in // fill in any missing values in the target VCF (or all, if not present) int i, empty = 0, nstr, mstr = args->tmpks.m; - nstr = bcf_get_info_string(args->hdr, line, col->hdr_key, &args->tmpks.s, &mstr); + nstr = bcf_get_info_string(args->hdr, line, col->hdr_key_dst, &args->tmpks.s, &mstr); args->tmpks.m = mstr; if ( nstr<0 || (nstr==1 && args->tmpks.s[0]=='.' && args->tmpks.s[1]==0) ) { @@ -695,7 +714,7 @@ static int setter_ARinfo_string(args_t *args, bcf1_t *line, annot_col_t *col, in int ret = copy_string_field(args->tmps,map[i],lsrc,&args->tmpks,i); assert( ret==0 ); } - bcf_update_info_string(args->hdr_out,line,col->hdr_key,args->tmpks.s); + bcf_update_info_string(args->hdr_out,line,col->hdr_key_dst,args->tmpks.s); return 0; } static int setter_info_str(args_t *args, bcf1_t *line, annot_col_t *col, void *data) @@ -712,17 +731,17 @@ static int setter_info_str(args_t *args, bcf1_t *line, annot_col_t *col, void *d if ( col->replace==REPLACE_MISSING ) { - int ret = bcf_get_info_string(args->hdr, line, col->hdr_key, &args->tmps2, &args->mtmps2); + int ret = bcf_get_info_string(args->hdr, line, col->hdr_key_dst, &args->tmps2, &args->mtmps2); if ( ret>0 && (args->tmps2[0]!='.' || args->tmps2[1]!=0) ) return 0; } - bcf_update_info_string(args->hdr_out,line,col->hdr_key,args->tmps); + bcf_update_info_string(args->hdr_out,line,col->hdr_key_dst,args->tmps); return 0; } static int vcf_setter_info_str(args_t *args, bcf1_t *line, annot_col_t *col, void *data) { bcf1_t *rec = (bcf1_t*) data; - int ntmps = bcf_get_info_string(args->files->readers[1].header,rec,col->hdr_key,&args->tmps,&args->mtmps); + int ntmps = bcf_get_info_string(args->files->readers[1].header,rec,col->hdr_key_src,&args->tmps,&args->mtmps); if ( ntmps < 0 ) return 0; // nothing to add if ( col->number==BCF_VL_A || col->number==BCF_VL_R ) @@ -730,11 +749,11 @@ static int vcf_setter_info_str(args_t *args, bcf1_t *line, annot_col_t *col, voi if ( col->replace==REPLACE_MISSING ) { - int ret = bcf_get_info_string(args->hdr, line, col->hdr_key, &args->tmps2, &args->mtmps2); + int ret = bcf_get_info_string(args->hdr, line, col->hdr_key_dst, &args->tmps2, &args->mtmps2); if ( ret>0 && (args->tmps2[0]!='.' || args->tmps2[1]!=0) ) return 0; } - bcf_update_info_string(args->hdr_out,line,col->hdr_key,args->tmps); + bcf_update_info_string(args->hdr_out,line,col->hdr_key_dst,args->tmps); return 0; } static int vcf_setter_format_gt(args_t *args, bcf1_t *line, annot_col_t *col, void *data) @@ -752,7 +771,7 @@ static int vcf_setter_format_gt(args_t *args, bcf1_t *line, annot_col_t *col, vo nsrc /= bcf_hdr_nsamples(args->files->readers[1].header); if ( ndst<=0 ) // field not present in dst file { - if ( col->replace==REPLACE_EXISTING ) return 0; + if ( col->replace==REPLACE_NON_MISSING ) return 0; hts_expand(int32_t, nsrc*bcf_hdr_nsamples(args->hdr_out), args->mtmpi2, args->tmpi2); for (i=0; ihdr_out); i++) { @@ -777,7 +796,7 @@ static int vcf_setter_format_gt(args_t *args, bcf1_t *line, annot_col_t *col, vo if ( args->sample_map[i]==-1 ) continue; int32_t *src = args->tmpi + nsrc*args->sample_map[i]; int32_t *dst = args->tmpi2 + ndst*i; - if ( col->replace==REPLACE_EXISTING && bcf_gt_is_missing(dst[0]) ) continue; + if ( col->replace==REPLACE_NON_MISSING && bcf_gt_is_missing(dst[0]) ) continue; if ( col->replace==REPLACE_MISSING && !bcf_gt_is_missing(dst[0]) ) continue; for (j=0; jtmpi3 + nsrc*i; int keep_ori = 0; if ( args->sample_map[i]==-1 ) keep_ori = 1; - else if ( col->replace==REPLACE_EXISTING && bcf_gt_is_missing(ori[0]) ) keep_ori = 1; + else if ( col->replace==REPLACE_NON_MISSING && bcf_gt_is_missing(ori[0]) ) keep_ori = 1; else if ( col->replace==REPLACE_MISSING && !bcf_gt_is_missing(ori[0]) ) keep_ori = 1; if ( keep_ori ) { @@ -811,7 +830,7 @@ static int vcf_setter_format_gt(args_t *args, bcf1_t *line, annot_col_t *col, vo } static int count_vals(annot_line_t *tab, int icol_beg, int icol_end) { - int i, nmax = 0; + int i, nmax = 1; for (i=icol_beg; icols[i], *end = str; @@ -831,298 +850,306 @@ static int count_vals(annot_line_t *tab, int icol_beg, int icol_end) } return nmax; } -static int setter_format_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data) -{ - annot_line_t *tab = (annot_line_t*) data; - int nsmpl = bcf_hdr_nsamples(args->hdr_out); - assert( col->icol+nsmpl <= tab->ncols ); - int nvals = count_vals(tab,col->icol,col->icol+nsmpl); - assert( nvals>0 ); - hts_expand(int32_t,nvals*nsmpl,args->mtmpi,args->tmpi); - - int icol = col->icol, ismpl; - for (ismpl=0; ismpltmpi + ismpl*nvals; - int ival = 0; - - char *str = tab->cols[icol]; - while ( *str ) - { - if ( str[0]=='.' && (!str[1] || str[1]==',') ) // missing value - { - ptr[ival++] = bcf_int32_missing; - str += str[1] ? 2 : 1; - continue; - } - - char *end = str; - ptr[ival] = strtol(str, &end, 10); - if ( end==str ) - error("Could not parse %s at %s:%d .. [%s]\n", col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); - - ival++; - str = *end ? end+1 : end; - } - while ( ivalhdr_out,line,col->hdr_key,args->tmpi,nsmpl*nvals); -} -static int setter_format_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +static int core_setter_format_int(args_t *args, bcf1_t *line, annot_col_t *col, int32_t *vals, int nvals) { - annot_line_t *tab = (annot_line_t*) data; - int nsmpl = bcf_hdr_nsamples(args->hdr_out); - assert( col->icol+nsmpl <= tab->ncols ); - int nvals = count_vals(tab,col->icol,col->icol+nsmpl); - assert( nvals>0 ); - hts_expand(float,nvals*nsmpl,args->mtmpf,args->tmpf); - - int icol = col->icol, ismpl; - for (ismpl=0; ismpltmpf + ismpl*nvals; - int ival = 0; - - char *str = tab->cols[icol]; - while ( *str ) - { - if ( str[0]=='.' && (!str[1] || str[1]==',') ) // missing value - { - bcf_float_set_missing(ptr[ival]); - ival++; - str += str[1] ? 2 : 1; - continue; - } - - char *end = str; - ptr[ival] = strtod(str, &end); - if ( end==str ) - error("Could not parse %s at %s:%d .. [%s]\n", col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); - - ival++; - str = *end ? end+1 : end; - } - while ( ivalhdr_out,line,col->hdr_key,args->tmpf,nsmpl*nvals); -} -static int setter_format_str(args_t *args, bcf1_t *line, annot_col_t *col, void *data) -{ - annot_line_t *tab = (annot_line_t*) data; - int nsmpl = bcf_hdr_nsamples(args->hdr_out); - assert( col->icol+nsmpl <= tab->ncols ); - - int i, max_len = 0; - for (i=col->icol; iicol+nsmpl; i++) - { - int len = strlen(tab->cols[i]); - if ( max_len < len ) max_len = len; - } - hts_expand(char,max_len*nsmpl,args->mtmps,args->tmps); - - int icol = col->icol, ismpl; - for (ismpl=0; ismpltmps + ismpl*max_len; - char *str = tab->cols[icol]; - i = 0; - while ( str[i] ) - { - ptr[i] = str[i]; - i++; - } - while ( ihdr_out,line,col->hdr_key,args->tmps,nsmpl*max_len); -} -static int vcf_setter_format_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data) -{ - bcf1_t *rec = (bcf1_t*) data; - int nsrc = bcf_get_format_int32(args->files->readers[1].header,rec,col->hdr_key,&args->tmpi,&args->mtmpi); - if ( nsrc==-3 ) return 0; // the tag is not present - if ( nsrc<=0 ) return 1; // error - if ( !args->sample_map ) - return bcf_update_format_int32(args->hdr_out,line,col->hdr_key,args->tmpi,nsrc); + return bcf_update_format_int32(args->hdr_out,line,col->hdr_key_dst,vals,nvals*args->nsmpl_annot); - int i, j, ndst = bcf_get_format_int32(args->hdr,line,col->hdr_key,&args->tmpi2,&args->mtmpi2); + int i, j, ndst = bcf_get_format_int32(args->hdr,line,col->hdr_key_dst,&args->tmpi2,&args->mtmpi2); if ( ndst > 0 ) ndst /= bcf_hdr_nsamples(args->hdr_out); - nsrc /= bcf_hdr_nsamples(args->files->readers[1].header); if ( ndst<=0 ) { - if ( col->replace==REPLACE_EXISTING ) return 0; // overwrite only if present - hts_expand(int32_t, nsrc*bcf_hdr_nsamples(args->hdr_out), args->mtmpi2, args->tmpi2); + if ( col->replace==REPLACE_NON_MISSING ) return 0; // overwrite only if present + hts_expand(int32_t, nvals*bcf_hdr_nsamples(args->hdr_out), args->mtmpi2, args->tmpi2); for (i=0; ihdr_out); i++) { - int32_t *dst = args->tmpi2 + nsrc*i; + int32_t *dst = args->tmpi2 + nvals*i; if ( args->sample_map[i]==-1 ) { dst[0] = bcf_int32_missing; - for (j=1; jtmpi + nsrc*args->sample_map[i]; - for (j=0; jsample_map[i]; + for (j=0; jhdr_out,line,col->hdr_key,args->tmpi2,nsrc*bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi2,nvals*bcf_hdr_nsamples(args->hdr_out)); } - else if ( ndst >= nsrc ) + else if ( ndst >= nvals ) { for (i=0; ihdr_out); i++) { if ( args->sample_map[i]==-1 ) continue; - int32_t *src = args->tmpi + nsrc*args->sample_map[i]; + int32_t *src = vals + nvals*args->sample_map[i]; int32_t *dst = args->tmpi2 + ndst*i; - if ( col->replace==REPLACE_EXISTING && dst[0]==bcf_int32_missing ) continue; - if ( col->replace==REPLACE_MISSING && dst[0]!=bcf_int32_missing ) continue; - for (j=0; jreplace==REPLACE_NON_MISSING ) { if ( dst[0]==bcf_int32_missing ) continue; } + else if ( col->replace==REPLACE_MISSING ) { if ( dst[0]!=bcf_int32_missing ) continue; } + else if ( col->replace==REPLACE_ALL ) { if ( src[0]==bcf_int32_missing ) continue; } + for (j=0; jhdr_out,line,col->hdr_key,args->tmpi2,ndst*bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi2,ndst*bcf_hdr_nsamples(args->hdr_out)); } - else // ndst < nsrc + else // ndst < nvals { - hts_expand(int32_t, nsrc*bcf_hdr_nsamples(args->hdr_out), args->mtmpi3, args->tmpi3); + hts_expand(int32_t, nvals*bcf_hdr_nsamples(args->hdr_out), args->mtmpi3, args->tmpi3); for (i=0; ihdr_out); i++) { - int32_t *ori = args->tmpi2 + ndst*i; - int32_t *dst = args->tmpi3 + nsrc*i; - int keep_ori = 0; - if ( args->sample_map[i]==-1 ) keep_ori = 1; - else if ( col->replace==REPLACE_EXISTING && ori[0]==bcf_int32_missing ) keep_ori = 1; - else if ( col->replace==REPLACE_MISSING && ori[0]!=bcf_int32_missing ) keep_ori = 1; - if ( keep_ori ) + int32_t *ann = vals + nvals*args->sample_map[i]; + int32_t *ori = args->tmpi2 + ndst*i; // ori vcf line + int32_t *dst = args->tmpi3 + nvals*i; // expanded buffer + int use_new_ann = 1; + if ( args->sample_map[i]==-1 ) use_new_ann = 0; + else if ( col->replace==REPLACE_NON_MISSING ) { if ( ori[0]==bcf_int32_missing ) use_new_ann = 0; } + else if ( col->replace==REPLACE_MISSING ) { if ( ori[0]!=bcf_int32_missing ) use_new_ann = 0; } + else if ( col->replace==REPLACE_ALL ) { if ( ann[0]==bcf_int32_missing ) use_new_ann = 0; } + if ( !use_new_ann ) { for (j=0; jtmpi + nsrc*args->sample_map[i]; - for (j=0; jhdr_out,line,col->hdr_key,args->tmpi3,nsrc*bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi3,nvals*bcf_hdr_nsamples(args->hdr_out)); } } -static int vcf_setter_format_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +static int core_setter_format_real(args_t *args, bcf1_t *line, annot_col_t *col, float *vals, int nvals) { - bcf1_t *rec = (bcf1_t*) data; - int nsrc = bcf_get_format_float(args->files->readers[1].header,rec,col->hdr_key,&args->tmpf,&args->mtmpf); - if ( nsrc==-3 ) return 0; // the tag is not present - if ( nsrc<=0 ) return 1; // error - if ( !args->sample_map ) - return bcf_update_format_float(args->hdr_out,line,col->hdr_key,args->tmpf,nsrc); + return bcf_update_format_float(args->hdr_out,line,col->hdr_key_dst,vals,nvals*args->nsmpl_annot); - int i, j, ndst = bcf_get_format_float(args->hdr,line,col->hdr_key,&args->tmpf2,&args->mtmpf2); + int i, j, ndst = bcf_get_format_float(args->hdr,line,col->hdr_key_dst,&args->tmpf2,&args->mtmpf2); if ( ndst > 0 ) ndst /= bcf_hdr_nsamples(args->hdr_out); - nsrc /= bcf_hdr_nsamples(args->files->readers[1].header); if ( ndst<=0 ) { - if ( col->replace==REPLACE_EXISTING ) return 0; // overwrite only if present - hts_expand(float, nsrc*bcf_hdr_nsamples(args->hdr_out), args->mtmpf2, args->tmpf2); + if ( col->replace==REPLACE_NON_MISSING ) return 0; // overwrite only if present + hts_expand(float, nvals*bcf_hdr_nsamples(args->hdr_out), args->mtmpf2, args->tmpf2); for (i=0; ihdr_out); i++) { - float *dst = args->tmpf2 + nsrc*i; + float *dst = args->tmpf2 + nvals*i; if ( args->sample_map[i]==-1 ) { bcf_float_set_missing(dst[0]); - for (j=1; jtmpf + nsrc*args->sample_map[i]; - for (j=0; jsample_map[i]; + for (j=0; jhdr_out,line,col->hdr_key,args->tmpf2,nsrc*bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf2,nvals*bcf_hdr_nsamples(args->hdr_out)); } - else if ( ndst >= nsrc ) + else if ( ndst >= nvals ) { for (i=0; ihdr_out); i++) { if ( args->sample_map[i]==-1 ) continue; - float *src = args->tmpf + nsrc*args->sample_map[i]; + float *src = vals + nvals*args->sample_map[i]; float *dst = args->tmpf2 + ndst*i; - if ( col->replace==REPLACE_EXISTING && bcf_float_is_missing(dst[0]) ) continue; - if ( col->replace==REPLACE_MISSING && !bcf_float_is_missing(dst[0]) ) continue; - for (j=0; jreplace==REPLACE_NON_MISSING ) { if ( bcf_float_is_missing(dst[0]) ) continue; } + else if ( col->replace==REPLACE_MISSING ) { if ( !bcf_float_is_missing(dst[0]) ) continue; } + else if ( col->replace==REPLACE_ALL ) { if ( bcf_float_is_missing(src[0]) ) continue; } + for (j=0; jhdr_out,line,col->hdr_key,args->tmpf2,ndst*bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf2,ndst*bcf_hdr_nsamples(args->hdr_out)); } - else // ndst < nsrc + else // ndst < nvals { - hts_expand(float, nsrc*bcf_hdr_nsamples(args->hdr_out), args->mtmpf3, args->tmpf3); + hts_expand(float, nvals*bcf_hdr_nsamples(args->hdr_out), args->mtmpf3, args->tmpf3); for (i=0; ihdr_out); i++) { - float *ori = args->tmpf2 + ndst*i; - float *dst = args->tmpf3 + nsrc*i; - int keep_ori = 0; - if ( args->sample_map[i]==-1 ) keep_ori = 1; - else if ( col->replace==REPLACE_EXISTING && bcf_float_is_missing(ori[0]) ) keep_ori = 1; - else if ( col->replace==REPLACE_MISSING && !bcf_float_is_missing(ori[0]) ) keep_ori = 1; - if ( keep_ori ) + float *ann = vals + nvals*args->sample_map[i]; + float *ori = args->tmpf2 + ndst*i; // ori vcf line + float *dst = args->tmpf3 + nvals*i; // expanded buffer + int use_new_ann = 1; + if ( args->sample_map[i]==-1 ) use_new_ann = 0; + else if ( col->replace==REPLACE_NON_MISSING ) { if ( bcf_float_is_missing(ori[0]) ) use_new_ann = 0; } + else if ( col->replace==REPLACE_MISSING ) { if ( !bcf_float_is_missing(ori[0]) ) use_new_ann = 0; } + else if ( col->replace==REPLACE_ALL ) { if ( bcf_float_is_missing(ann[0]) ) use_new_ann = 0; } + if ( !use_new_ann ) { for (j=0; jtmpf + nsrc*args->sample_map[i]; - for (j=0; jhdr_out,line,col->hdr_key,args->tmpf3,nsrc*bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf3,nvals*bcf_hdr_nsamples(args->hdr_out)); } } -static int vcf_setter_format_str(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +static int core_setter_format_str(args_t *args, bcf1_t *line, annot_col_t *col, char **vals) { - bcf1_t *rec = (bcf1_t*) data; - args->tmpp[0] = args->tmps; - int ret = bcf_get_format_string(args->files->readers[1].header,rec,col->hdr_key,&args->tmpp,&args->mtmps); - args->tmps = args->tmpp[0]; // tmps might be realloced - if ( ret==-3 ) return 0; // the tag is not present - if ( ret<=0 ) return 1; // error - if ( !args->sample_map ) - return bcf_update_format_string(args->hdr_out,line,col->hdr_key,(const char**)args->tmpp,bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_string(args->hdr_out,line,col->hdr_key_dst,(const char**)vals,args->nsmpl_annot); int i; args->tmpp2[0] = args->tmps2; - ret = bcf_get_format_string(args->hdr,line,col->hdr_key,&args->tmpp2,&args->mtmps2); + int ret = bcf_get_format_string(args->hdr,line,col->hdr_key_dst,&args->tmpp2,&args->mtmps2); args->tmps2 = args->tmpp2[0]; // tmps2 might be realloced + int nsmpl = bcf_hdr_nsamples(args->hdr_out); if ( ret<=0 ) // not present in dst { hts_expand(char,bcf_hdr_nsamples(args->hdr_out)*2,args->mtmps2,args->tmps2); - for (i=0; ihdr_out); i++) + char *tmp = args->tmps2; + for (i=0; itmpp2[i] = tmp; + tmp += 2; + } + } + for (i=0; isample_map[i]==-1 ) continue; + char **src = vals + args->sample_map[i]; + char **dst = args->tmpp2 + i; + + if ( col->replace==REPLACE_NON_MISSING ) { if ( (*dst)[0]=='.' && (*dst)[1]==0 ) continue; } + else if ( col->replace==REPLACE_MISSING ) { if ( (*dst)[0]!='.' || (*dst)[1]!=0 ) continue; } + else if ( col->replace==REPLACE_ALL ) { if ( (*src)[0]=='.' && (*src)[1]==0 ) continue; } + *dst = *src; + } + return bcf_update_format_string(args->hdr_out,line,col->hdr_key_dst,(const char**)args->tmpp2,nsmpl); +} +static int setter_format_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +{ + annot_line_t *tab = (annot_line_t*) data; + if ( col->icol+args->nsmpl_annot > tab->ncols ) + error("Incorrect number of values for %s at %s:%d\n",col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); + int nvals = count_vals(tab,col->icol,col->icol+args->nsmpl_annot); + hts_expand(int32_t,nvals*args->nsmpl_annot,args->mtmpi,args->tmpi); + + int icol = col->icol, ismpl; + for (ismpl=0; ismplnsmpl_annot; ismpl++) + { + int32_t *ptr = args->tmpi + ismpl*nvals; + int ival = 0; + + char *str = tab->cols[icol]; + while ( *str ) { - args->tmps2[2*i] = '.'; - args->tmps2[2*i+1] = 0; - args->tmpp2[i] = args->tmps2+2*i; + if ( str[0]=='.' && (!str[1] || str[1]==',') ) // missing value + { + ptr[ival++] = bcf_int32_missing; + str += str[1] ? 2 : 1; + continue; + } + + char *end = str; + ptr[ival] = strtol(str, &end, 10); + if ( end==str ) + error("Could not parse %s at %s:%d .. [%s]\n", col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); + + ival++; + str = *end ? end+1 : end; } + while ( ivaltmpi,nvals); +} +static int setter_format_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +{ + annot_line_t *tab = (annot_line_t*) data; + if ( col->icol+args->nsmpl_annot > tab->ncols ) + error("Incorrect number of values for %s at %s:%d\n",col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); + int nvals = count_vals(tab,col->icol,col->icol+args->nsmpl_annot); + hts_expand(float,nvals*args->nsmpl_annot,args->mtmpf,args->tmpf); - for (i=0; ihdr_out); i++) + int icol = col->icol, ismpl; + for (ismpl=0; ismplnsmpl_annot; ismpl++) { - int isrc = args->sample_map[i]; - if ( isrc==-1 ) continue; - args->tmpp2[i] = args->tmpp[isrc]; + float *ptr = args->tmpf + ismpl*nvals; + int ival = 0; + + char *str = tab->cols[icol]; + while ( *str ) + { + if ( str[0]=='.' && (!str[1] || str[1]==',') ) // missing value + { + bcf_float_set_missing(ptr[ival]); + ival++; + str += str[1] ? 2 : 1; + continue; + } + + char *end = str; + ptr[ival] = strtod(str, &end); + if ( end==str ) + error("Could not parse %s at %s:%d .. [%s]\n", col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); + + ival++; + str = *end ? end+1 : end; + } + while ( ivalhdr_out,line,col->hdr_key,(const char**)args->tmpp2,bcf_hdr_nsamples(args->hdr_out)); + return core_setter_format_real(args,line,col,args->tmpf,nvals); } -static void set_samples(args_t *args, bcf_hdr_t *src, bcf_hdr_t *dst, int need_samples) +static int setter_format_str(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +{ + annot_line_t *tab = (annot_line_t*) data; + if ( col->icol+args->nsmpl_annot > tab->ncols ) + error("Incorrect number of values for %s at %s:%d\n",col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); + + int ismpl; + for (ismpl=0; ismplnsmpl_annot; ismpl++) + args->tmpp[ismpl] = tab->cols[col->icol + ismpl]; + + return core_setter_format_str(args,line,col,args->tmpp); +} +static int vcf_setter_format_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +{ + bcf1_t *rec = (bcf1_t*) data; + int nsrc = bcf_get_format_int32(args->files->readers[1].header,rec,col->hdr_key_src,&args->tmpi,&args->mtmpi); + if ( nsrc==-3 ) return 0; // the tag is not present + if ( nsrc<=0 ) return 1; // error + return core_setter_format_int(args,line,col,args->tmpi,nsrc/bcf_hdr_nsamples(args->files->readers[1].header)); +} +static int vcf_setter_format_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +{ + bcf1_t *rec = (bcf1_t*) data; + int nsrc = bcf_get_format_float(args->files->readers[1].header,rec,col->hdr_key_src,&args->tmpf,&args->mtmpf); + if ( nsrc==-3 ) return 0; // the tag is not present + if ( nsrc<=0 ) return 1; // error + return core_setter_format_real(args,line,col,args->tmpf,nsrc/bcf_hdr_nsamples(args->files->readers[1].header)); +} + +static int vcf_setter_format_str(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +{ + bcf1_t *rec = (bcf1_t*) data; + args->tmpp[0] = args->tmps; + int ret = bcf_get_format_string(args->files->readers[1].header,rec,col->hdr_key_src,&args->tmpp,&args->mtmps); + args->tmps = args->tmpp[0]; // tmps might be realloced + if ( ret==-3 ) return 0; // the tag is not present + if ( ret<=0 ) return 1; // error + return core_setter_format_str(args,line,col,args->tmpp); +} +static int init_sample_map(args_t *args, bcf_hdr_t *src, bcf_hdr_t *dst) { int i; if ( !args->sample_names ) { + args->nsmpl_annot = bcf_hdr_nsamples(dst); + + // tab annotation file, expecting that all samples are present: sample map not needed + if ( !src ) return 0; + int nmatch = 0, order_ok = 1; for (i=0; insample_map = bcf_hdr_nsamples(dst); args->sample_map = (int*) malloc(sizeof(int)*args->nsample_map); @@ -1146,46 +1170,70 @@ static void set_samples(args_t *args, bcf_hdr_t *src, bcf_hdr_t *dst, int need_s int id = bcf_hdr_id2int(src, BCF_DT_SAMPLE, dst->samples[i]); args->sample_map[i] = id; // idst -> isrc, -1 if not present } - return; + return 1; } args->nsample_map = bcf_hdr_nsamples(dst); args->sample_map = (int*) malloc(sizeof(int)*args->nsample_map); for (i=0; insample_map; i++) args->sample_map[i] = -1; - int nsamples = 0; - char **samples = hts_readlist(args->sample_names, args->sample_is_file, &nsamples); - for (i=0; isample_names, args->sample_is_file, SMPL_STRICT); + if ( !ilist || !ilist->n ) error("Could not parse: %s\n", args->sample_names); + char **samples = (char**) malloc(sizeof(char*)*ilist->n); + for (i=0; in; i++) samples[i] = strdup(dst->samples[i]); + args->nsmpl_annot = ilist->n; + smpl_ilist_destroy(ilist); + int need_sample_map = args->nsmpl_annot==bcf_hdr_nsamples(dst) ? 0 : 1; + if ( !src ) { - int isrc, idst; - char *ss = samples[i], *se = samples[i]; - while ( *se && !isspace(*se) ) se++; - if ( !*se ) + // tab annotation file + for (i=0; insmpl_annot; i++) { - // only one sample name + int idst = bcf_hdr_id2int(dst, BCF_DT_SAMPLE, samples[i]); + if ( idst==-1 ) error("Sample \"%s\" not found in the destination file\n", samples[i]); + args->sample_map[idst] = i; + if ( idst!=i ) need_sample_map = 1; + } + } + else + { + // vcf annotation file + for (i=0; insmpl_annot; i++) + { + int isrc, idst; + char *ss = samples[i], *se = samples[i]; + while ( *se && !isspace(*se) ) se++; + if ( !*se ) + { + // only one sample name + isrc = bcf_hdr_id2int(src, BCF_DT_SAMPLE,ss); + if ( isrc==-1 ) error("Sample \"%s\" not found in the source file\n", ss); + idst = bcf_hdr_id2int(dst, BCF_DT_SAMPLE,ss); + if ( idst==-1 ) error("Sample \"%s\" not found in the destination file\n", ss); + args->sample_map[idst] = isrc; + if ( idst!=isrc ) need_sample_map = 1; + continue; + } + *se = 0; isrc = bcf_hdr_id2int(src, BCF_DT_SAMPLE,ss); if ( isrc==-1 ) error("Sample \"%s\" not found in the source file\n", ss); + + ss = se+1; + while ( isspace(*ss) ) ss++; + se = ss; + while ( *se && !isspace(*se) ) se++; + idst = bcf_hdr_id2int(dst, BCF_DT_SAMPLE,ss); if ( idst==-1 ) error("Sample \"%s\" not found in the destination file\n", ss); + args->sample_map[idst] = isrc; - continue; + if ( idst!=isrc ) need_sample_map = 1; } - *se = 0; - isrc = bcf_hdr_id2int(src, BCF_DT_SAMPLE,ss); - if ( isrc==-1 ) error("Sample \"%s\" not found in the source file\n", ss); - - ss = se+1; - while ( isspace(*ss) ) ss++; - se = ss; - while ( *se && !isspace(*se) ) se++; - - idst = bcf_hdr_id2int(dst, BCF_DT_SAMPLE,ss); - if ( idst==-1 ) error("Sample \"%s\" not found in the destination file\n", ss); - - args->sample_map[idst] = isrc; } - for (i=0; insmpl_annot; i++) free(samples[i]); free(samples); + return need_sample_map; } static char *columns_complement(char *columns, void **skip_info, void **skip_fmt) { @@ -1247,8 +1295,27 @@ static char *columns_complement(char *columns, void **skip_info, void **skip_fmt free(columns); return str.s; } +static void bcf_hrec_format_rename(bcf_hrec_t *hrec, char *tag, kstring_t *str) +{ + int j, nout = 0; + ksprintf(str, "##%s=<", hrec->key); + for (j=0; jnkeys; j++) + { + if ( !strcmp("IDX",hrec->keys[j]) ) continue; + if ( nout ) kputc(',',str); + if ( !strcmp("ID", hrec->keys[j]) ) + ksprintf(str,"%s=%s", hrec->keys[j], tag); + else + ksprintf(str,"%s=%s", hrec->keys[j], hrec->vals[j]); + nout++; + } + ksprintf(str,">\n"); +} static void init_columns(args_t *args) { + int need_sample_map = 0; + int sample_map_ok = init_sample_map(args, args->tgts_is_vcf?args->files->readers[1].header:NULL, args->hdr); + void *skip_fmt = NULL, *skip_info = NULL; if ( args->tgts_is_vcf ) args->columns = columns_complement(args->columns, &skip_info, &skip_fmt); @@ -1256,13 +1323,13 @@ static void init_columns(args_t *args) kstring_t str = {0,0,0}, tmp = {0,0,0}; char *ss = args->columns, *se = ss; args->ncols = 0; - int icol = -1, has_fmt_str = 0, force_samples = -1; + int icol = -1, has_fmt_str = 0; while ( *ss ) { if ( *se && *se!=',' ) { se++; continue; } int replace = REPLACE_ALL; if ( *ss=='+' ) { replace = REPLACE_MISSING; ss++; } - else if ( *ss=='-' ) { replace = REPLACE_EXISTING; ss++; } + else if ( *ss=='-' ) { replace = REPLACE_NON_MISSING; ss++; } else if ( *ss=='=' ) { replace = SET_OR_APPEND; ss++; } icol++; str.l = 0; @@ -1276,23 +1343,25 @@ static void init_columns(args_t *args) else if ( !strcasecmp("ALT",str.s) ) args->alt_idx = icol; else if ( !strcasecmp("ID",str.s) ) { - if ( replace==REPLACE_EXISTING ) error("Apologies, the -ID feature has not been implemented yet.\n"); + if ( replace==REPLACE_NON_MISSING ) error("Apologies, the -ID feature has not been implemented yet.\n"); args->ncols++; args->cols = (annot_col_t*) realloc(args->cols,sizeof(annot_col_t)*args->ncols); annot_col_t *col = &args->cols[args->ncols-1]; col->icol = icol; col->replace = replace; col->setter = args->tgts_is_vcf ? vcf_setter_id : setter_id; - col->hdr_key = strdup(str.s); + col->hdr_key_src = strdup(str.s); + col->hdr_key_dst = strdup(str.s); } else if ( !strcasecmp("FILTER",str.s) ) { - if ( replace==REPLACE_EXISTING ) error("Apologies, the -FILTER feature has not been implemented yet.\n"); + if ( replace==REPLACE_NON_MISSING ) error("Apologies, the -FILTER feature has not been implemented yet.\n"); args->ncols++; args->cols = (annot_col_t*) realloc(args->cols,sizeof(annot_col_t)*args->ncols); annot_col_t *col = &args->cols[args->ncols-1]; col->icol = icol; col->replace = replace; col->setter = args->tgts_is_vcf ? vcf_setter_filter : setter_filter; - col->hdr_key = strdup(str.s); + col->hdr_key_src = strdup(str.s); + col->hdr_key_dst = strdup(str.s); if ( args->tgts_is_vcf ) { bcf_hdr_t *tgts_hdr = args->files->readers[1].header; @@ -1312,18 +1381,19 @@ static void init_columns(args_t *args) } else if ( !strcasecmp("QUAL",str.s) ) { - if ( replace==REPLACE_EXISTING ) error("Apologies, the -QUAL feature has not been implemented yet.\n"); + if ( replace==REPLACE_NON_MISSING ) error("Apologies, the -QUAL feature has not been implemented yet.\n"); if ( replace==SET_OR_APPEND ) error("Apologies, the =QUAL feature has not been implemented yet.\n"); args->ncols++; args->cols = (annot_col_t*) realloc(args->cols,sizeof(annot_col_t)*args->ncols); annot_col_t *col = &args->cols[args->ncols-1]; col->icol = icol; col->replace = replace; col->setter = args->tgts_is_vcf ? vcf_setter_qual : setter_qual; - col->hdr_key = strdup(str.s); + col->hdr_key_src = strdup(str.s); + col->hdr_key_dst = strdup(str.s); } else if ( args->tgts_is_vcf && !strcasecmp("INFO",str.s) ) // All INFO fields { - if ( replace==REPLACE_EXISTING ) error("Apologies, the -INFO/TAG feature has not been implemented yet.\n"); + if ( replace==REPLACE_NON_MISSING ) error("Apologies, the -INFO/TAG feature has not been implemented yet.\n"); if ( replace==SET_OR_APPEND ) error("Apologies, the =INFO/TAG feature has not been implemented yet.\n"); bcf_hdr_t *tgts_hdr = args->files->readers[1].header; int j; @@ -1343,7 +1413,8 @@ static void init_columns(args_t *args) annot_col_t *col = &args->cols[args->ncols-1]; col->icol = -1; col->replace = replace; - col->hdr_key = strdup(hrec->vals[k]); + col->hdr_key_src = strdup(hrec->vals[k]); + col->hdr_key_dst = strdup(hrec->vals[k]); col->number = bcf_hdr_id2length(args->hdr_out,BCF_HL_INFO,hdr_id); switch ( bcf_hdr_id2type(args->hdr_out,BCF_HL_INFO,hdr_id) ) { @@ -1358,8 +1429,7 @@ static void init_columns(args_t *args) else if ( args->tgts_is_vcf && (!strcasecmp("FORMAT",str.s) || !strcasecmp("FMT",str.s)) ) // All FORMAT fields { bcf_hdr_t *tgts_hdr = args->files->readers[1].header; - if ( force_samples<0 ) force_samples = replace; - if ( force_samples>=0 && replace!=REPLACE_ALL ) force_samples = replace; + need_sample_map = 1; int j; for (j=0; jnhrec; j++) { @@ -1377,8 +1447,9 @@ static void init_columns(args_t *args) annot_col_t *col = &args->cols[args->ncols-1]; col->icol = -1; col->replace = replace; - col->hdr_key = strdup(hrec->vals[k]); - if ( !strcasecmp("GT",col->hdr_key) ) col->setter = vcf_setter_format_gt; + col->hdr_key_src = strdup(hrec->vals[k]); + col->hdr_key_dst = strdup(hrec->vals[k]); + if ( !strcasecmp("GT",col->hdr_key_src) ) col->setter = vcf_setter_format_gt; else switch ( bcf_hdr_id2type(args->hdr_out,BCF_HL_FMT,hdr_id) ) { @@ -1391,18 +1462,27 @@ static void init_columns(args_t *args) } else if ( !strncasecmp("FORMAT/",str.s, 7) || !strncasecmp("FMT/",str.s,4) ) { - char *key = str.s + (!strncasecmp("FMT/",str.s,4) ? 4 : 7); - if ( force_samples<0 ) force_samples = replace; - if ( force_samples>=0 && replace!=REPLACE_ALL ) force_samples = replace; + char *key_dst = str.s + (!strncasecmp("FMT/",str.s,4) ? 4 : 7); + char *key_src = strstr(key_dst,":="); + if ( key_src ) + { + *key_src = 0; + key_src += 2; + if ( !strncasecmp("FORMAT/",key_src,7) ) key_src += 7; + else if ( !strncasecmp("FMT/",key_src,4) ) key_src += 4; + } + else + key_src = key_dst; + need_sample_map = 1; if ( args->tgts_is_vcf ) { - bcf_hrec_t *hrec = bcf_hdr_get_hrec(args->files->readers[1].header, BCF_HL_FMT, "ID", key, NULL); + bcf_hrec_t *hrec = bcf_hdr_get_hrec(args->files->readers[1].header, BCF_HL_FMT, "ID", key_src, NULL); tmp.l = 0; - bcf_hrec_format(hrec, &tmp); + bcf_hrec_format_rename(hrec, key_dst, &tmp); bcf_hdr_append(args->hdr_out, tmp.s); bcf_hdr_sync(args->hdr_out); } - int hdr_id = bcf_hdr_id2int(args->hdr_out, BCF_DT_ID, key); + int hdr_id = bcf_hdr_id2int(args->hdr_out, BCF_DT_ID, key_dst); if ( !bcf_hdr_idinfo_exists(args->hdr_out,BCF_HL_FMT,hdr_id) ) error("The tag \"%s\" is not defined in %s\n", str.s, args->targets_fname); args->ncols++; args->cols = (annot_col_t*) realloc(args->cols,sizeof(annot_col_t)*args->ncols); @@ -1410,13 +1490,14 @@ static void init_columns(args_t *args) if ( !args->tgts_is_vcf ) { col->icol = icol; - icol += bcf_hdr_nsamples(args->hdr_out) - 1; + icol += args->nsmpl_annot - 1; } else col->icol = -1; col->replace = replace; - col->hdr_key = strdup(key); - if ( !strcasecmp("GT",key) ) col->setter = vcf_setter_format_gt; + col->hdr_key_src = strdup(key_src); + col->hdr_key_dst = strdup(key_dst); + if ( !strcasecmp("GT",key_src) ) col->setter = vcf_setter_format_gt; else switch ( bcf_hdr_id2type(args->hdr_out,BCF_HL_FMT,hdr_id) ) { @@ -1428,24 +1509,33 @@ static void init_columns(args_t *args) } else { - if ( replace==REPLACE_EXISTING ) error("Apologies, the -INFO/TAG feature has not been implemented yet.\n"); + if ( replace==REPLACE_NON_MISSING ) error("Apologies, the -INFO/TAG feature has not been implemented yet.\n"); if ( replace==SET_OR_APPEND ) error("Apologies, the =INFO/TAG feature has not been implemented yet.\n"); - if ( !strncasecmp("INFO/",str.s,5) ) { memmove(str.s,str.s+5,str.l-4); } - int hdr_id = bcf_hdr_id2int(args->hdr_out, BCF_DT_ID, str.s); + char *key_dst = !strncasecmp("INFO/",str.s,5) ? str.s + 5 : str.s; + char *key_src = strstr(key_dst,":="); + if ( key_src ) + { + *key_src = 0; + key_src += 2; + if ( !strncasecmp("INFO/",key_src,5) ) key_src += 5; + } + else + key_src = key_dst; + int hdr_id = bcf_hdr_id2int(args->hdr_out, BCF_DT_ID, key_dst); if ( !bcf_hdr_idinfo_exists(args->hdr_out,BCF_HL_INFO,hdr_id) ) { if ( args->tgts_is_vcf ) // reading annotations from a VCF, add a new header line { - bcf_hrec_t *hrec = bcf_hdr_get_hrec(args->files->readers[1].header, BCF_HL_INFO, "ID", str.s, NULL); + bcf_hrec_t *hrec = bcf_hdr_get_hrec(args->files->readers[1].header, BCF_HL_INFO, "ID", key_src, NULL); if ( !hrec ) error("The tag \"%s\" is not defined in %s\n", str.s,args->files->readers[1].fname); tmp.l = 0; - bcf_hrec_format(hrec, &tmp); + bcf_hrec_format_rename(hrec, key_dst, &tmp); bcf_hdr_append(args->hdr_out, tmp.s); bcf_hdr_sync(args->hdr_out); - hdr_id = bcf_hdr_id2int(args->hdr_out, BCF_DT_ID, str.s); + hdr_id = bcf_hdr_id2int(args->hdr_out, BCF_DT_ID, key_dst); } else - error("The tag \"%s\" is not defined in %s\n", str.s, args->targets_fname); + error("The tag \"%s\" is not defined in %s\n", key_src, args->targets_fname); assert( bcf_hdr_idinfo_exists(args->hdr_out,BCF_HL_INFO,hdr_id) ); } @@ -1453,7 +1543,8 @@ static void init_columns(args_t *args) annot_col_t *col = &args->cols[args->ncols-1]; col->icol = icol; col->replace = replace; - col->hdr_key = strdup(str.s); + col->hdr_key_src = strdup(key_src); + col->hdr_key_dst = strdup(key_dst); col->number = bcf_hdr_id2length(args->hdr_out,BCF_HL_INFO,hdr_id); switch ( bcf_hdr_id2type(args->hdr_out,BCF_HL_INFO,hdr_id) ) { @@ -1480,8 +1571,13 @@ static void init_columns(args_t *args) args->tmpp = (char**)malloc(sizeof(char*)*n); args->tmpp2 = (char**)malloc(sizeof(char*)*n); } - if ( force_samples>=0 && args->tgts_is_vcf ) - set_samples(args, args->files->readers[1].header, args->hdr, force_samples==REPLACE_ALL ? 0 : 1); + if ( !need_sample_map ) + { + free(args->sample_map); + args->sample_map = NULL; + } + else if ( sample_map_ok<0 ) + error("No matching samples in source and destination file?\n"); } static void rename_chrs(args_t *args, char *fname) @@ -1552,7 +1648,6 @@ static void init_data(args_t *args) if ( args->mark_sites ) { if ( !args->targets_fname ) error("The -a option not given\n"); - if ( args->tgts_is_vcf ) error("Apologies, this has not been implemented yet: -a is a VCF\n"); // very easy to add.. bcf_hdr_printf(args->hdr_out,"##INFO=", args->mark_sites,args->mark_sites_logic==MARK_LISTED?"":"not ",args->mark_sites); } @@ -1564,7 +1659,8 @@ static void init_data(args_t *args) args->out_fh = hts_open(args->output_fname,hts_bcf_wmode(args->output_type)); if ( args->out_fh == NULL ) error("Can't write to \"%s\": %s\n", args->output_fname, strerror(errno)); - if ( args->n_threads ) hts_set_threads(args->out_fh, args->n_threads); + if ( args->n_threads ) + hts_set_opt(args->out_fh, HTS_OPT_THREAD_POOL, args->files->p); bcf_hdr_write(args->out_fh, args->hdr_out); } } @@ -1577,7 +1673,10 @@ static void destroy_data(args_t *args) if ( args->hdr_out ) bcf_hdr_destroy(args->hdr_out); if (args->vcmp) vcmp_destroy(args->vcmp); for (i=0; incols; i++) - free(args->cols[i].hdr_key); + { + free(args->cols[i].hdr_key_src); + free(args->cols[i].hdr_key_dst); + } free(args->cols); for (i=0; imalines; i++) { @@ -1718,7 +1817,7 @@ static void annotate(args_t *args, bcf1_t *line) // there is a matching line for (j=0; jncols; j++) if ( args->cols[j].setter(args,line,&args->cols[j],&args->alines[i]) ) - error("fixme: Could not set %s at %s:%d\n", args->cols[j].hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("fixme: Could not set %s at %s:%d\n", args->cols[j].hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); } @@ -1731,12 +1830,20 @@ static void annotate(args_t *args, bcf1_t *line) bcf_update_info_flag(args->hdr_out,line,args->mark_sites,NULL,inalines?0:1); } } - else if ( args->files->nreaders == 2 && bcf_sr_has_line(args->files,1) ) + else if ( args->files->nreaders == 2 ) { - bcf1_t *aline = bcf_sr_get_line(args->files,1); - for (j=0; jncols; j++) - if ( args->cols[j].setter(args,line,&args->cols[j],aline) ) - error("fixme: Could not set %s at %s:%d\n", args->cols[j].hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + if ( bcf_sr_has_line(args->files,1) ) + { + bcf1_t *aline = bcf_sr_get_line(args->files,1); + for (j=0; jncols; j++) + if ( args->cols[j].setter(args,line,&args->cols[j],aline) ) + error("fixme: Could not set %s at %s:%d\n", args->cols[j].hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); + + if ( args->mark_sites ) + bcf_update_info_flag(args->hdr_out,line,args->mark_sites,NULL,args->mark_sites_logic==MARK_LISTED ? 1 : 0); + } + else if ( args->mark_sites ) + bcf_update_info_flag(args->hdr_out,line,args->mark_sites,NULL, args->mark_sites_logic==MARK_UNLISTED ? 1 : 0); } if ( args->set_ids ) { @@ -1761,11 +1868,13 @@ static void usage(args_t *args) fprintf(stderr, "\n"); fprintf(stderr, "Options:\n"); fprintf(stderr, " -a, --annotations VCF file or tabix-indexed file with annotations: CHR\\tPOS[\\tVALUE]+\n"); + fprintf(stderr, " --collapse matching records by , see man page for details [some]\n"); fprintf(stderr, " -c, --columns list of columns in the annotation file, e.g. CHROM,POS,REF,ALT,-,INFO/TAG. See man page for details\n"); fprintf(stderr, " -e, --exclude exclude sites for which the expression is true (see man page for details)\n"); fprintf(stderr, " -h, --header-lines lines which should be appended to the VCF header\n"); fprintf(stderr, " -I, --set-id [+] set ID column, see man page for details\n"); fprintf(stderr, " -i, --include select sites for which the expression is true (see man page for details)\n"); + fprintf(stderr, " -k, --keep-sites leave -i/-e sites unchanged instead of discarding them\n"); fprintf(stderr, " -m, --mark-sites [+-] add INFO/tag flag to sites which are (\"+\") or are not (\"-\") listed in the -a file\n"); fprintf(stderr, " --no-version do not append version and command line to the header\n"); fprintf(stderr, " -o, --output write output to a file [standard output]\n"); @@ -1775,7 +1884,7 @@ static void usage(args_t *args) fprintf(stderr, " --rename-chrs rename sequences according to map file: from\\tto\n"); fprintf(stderr, " -s, --samples [^] comma separated list of samples to annotate (or exclude with \"^\" prefix)\n"); fprintf(stderr, " -S, --samples-file [^] file of samples to annotate (or exclude with \"^\" prefix)\n"); - fprintf(stderr, " -x, --remove list of annotations to remove (e.g. ID,INFO/DP,FORMAT/DP,FILTER). See man page for details\n"); + fprintf(stderr, " -x, --remove list of annotations (e.g. ID,INFO/DP,FORMAT/DP,FILTER) to remove (or keep with \"^\" prefix). See man page for details\n"); fprintf(stderr, " --threads number of extra output compression threads [0]\n"); fprintf(stderr, "\n"); exit(1); @@ -1793,16 +1902,18 @@ int main_vcfannotate(int argc, char *argv[]) args->record_cmd_line = 1; args->ref_idx = args->alt_idx = args->chr_idx = args->from_idx = args->to_idx = -1; args->set_ids_replace = 1; - int regions_is_file = 0; + int regions_is_file = 0, collapse = 0; static struct option loptions[] = { + {"keep-sites",required_argument,NULL,'k'}, {"mark-sites",required_argument,NULL,'m'}, {"set-id",required_argument,NULL,'I'}, {"output",required_argument,NULL,'o'}, {"output-type",required_argument,NULL,'O'}, {"threads",required_argument,NULL,9}, {"annotations",required_argument,NULL,'a'}, + {"collapse",required_argument,NULL,2}, {"include",required_argument,NULL,'i'}, {"exclude",required_argument,NULL,'e'}, {"regions",required_argument,NULL,'r'}, @@ -1816,9 +1927,10 @@ int main_vcfannotate(int argc, char *argv[]) {"no-version",no_argument,NULL,8}, {NULL,0,NULL,0} }; - while ((c = getopt_long(argc, argv, "h:?o:O:r:R:a:x:c:i:e:S:s:I:m:",loptions,NULL)) >= 0) + while ((c = getopt_long(argc, argv, "h:?o:O:r:R:a:x:c:i:e:S:s:I:m:k",loptions,NULL)) >= 0) { switch (c) { + case 'k': args->keep_sites = 1; break; case 'm': args->mark_sites_logic = MARK_LISTED; if ( optarg[0]=='+' ) args->mark_sites = optarg+1; @@ -1847,6 +1959,16 @@ int main_vcfannotate(int argc, char *argv[]) case 'R': args->regions_list = optarg; regions_is_file = 1; break; case 'h': args->header_fname = optarg; break; case 1 : args->rename_chrs = optarg; break; + case 2 : + if ( !strcmp(optarg,"snps") ) collapse |= COLLAPSE_SNPS; + else if ( !strcmp(optarg,"indels") ) collapse |= COLLAPSE_INDELS; + else if ( !strcmp(optarg,"both") ) collapse |= COLLAPSE_SNPS | COLLAPSE_INDELS; + else if ( !strcmp(optarg,"any") ) collapse |= COLLAPSE_ANY; + else if ( !strcmp(optarg,"all") ) collapse |= COLLAPSE_ANY; + else if ( !strcmp(optarg,"some") ) collapse |= COLLAPSE_SOME; + else if ( !strcmp(optarg,"none") ) collapse = COLLAPSE_NONE; + else error("The --collapse string \"%s\" not recognised.\n", optarg); + break; case 9 : args->n_threads = strtol(optarg, 0, 0); break; case 8 : args->record_cmd_line = 0; break; case '?': usage(args); break; @@ -1877,9 +1999,10 @@ int main_vcfannotate(int argc, char *argv[]) { args->tgts_is_vcf = 1; args->files->require_index = 1; - args->files->collapse |= COLLAPSE_SOME; + args->files->collapse = collapse ? collapse : COLLAPSE_SOME; } } + if ( bcf_sr_set_threads(args->files, args->n_threads)<0 ) error("Failed to create threads\n"); if ( !bcf_sr_add_reader(args->files, fname) ) error("Failed to open %s: %s\n", fname,bcf_sr_strerror(args->files->errnum)); init_data(args); @@ -1892,7 +2015,11 @@ int main_vcfannotate(int argc, char *argv[]) { int pass = filter_test(args->filter, line, NULL); if ( args->filter_logic & FLT_EXCLUDE ) pass = pass ? 0 : 1; - if ( !pass ) continue; + if ( !pass ) + { + if ( args->keep_sites ) bcf_write1(args->out_fh, args->hdr_out, line); + continue; + } } annotate(args, line); bcf_write1(args->out_fh, args->hdr_out, line); diff --git a/bcftools/vcfannotate.c.pysam.c b/bcftools/vcfannotate.c.pysam.c index ea8398c6f..87a6cc4ef 100644 --- a/bcftools/vcfannotate.c.pysam.c +++ b/bcftools/vcfannotate.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfannotate.c -- Annotate and edit VCF/BCF files. - Copyright (C) 2013-2016 Genome Research Ltd. + Copyright (C) 2013-2018 Genome Research Ltd. Author: Petr Danecek @@ -25,6 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#include #include #include #include @@ -43,6 +44,7 @@ THE SOFTWARE. */ #include "vcmp.h" #include "filter.h" #include "convert.h" +#include "smpl_ilist.h" struct _args_t; @@ -67,12 +69,12 @@ annot_line_t; #define REPLACE_MISSING 0 // replace only missing values #define REPLACE_ALL 1 // replace both missing and existing values -#define REPLACE_EXISTING 2 // replace only if tgt is not missing +#define REPLACE_NON_MISSING 2 // replace only if tgt is not missing #define SET_OR_APPEND 3 // set new value if missing or non-existent, append otherwise typedef struct _annot_col_t { int icol, replace, number; // number: one of BCF_VL_* types - char *hdr_key; + char *hdr_key_src, *hdr_key_dst; int (*setter)(struct _args_t *, bcf1_t *, struct _annot_col_t *, void*); } annot_col_t; @@ -95,6 +97,7 @@ typedef struct _args_t filter_t *filter; char *filter_str; int filter_logic; // include or exclude sites which match the filters? One of FLT_INCLUDE/FLT_EXCLUDE + int keep_sites; rm_tag_t *rm; // tags scheduled for removal int nrm; @@ -111,6 +114,7 @@ typedef struct _args_t convert_t *set_ids; int set_ids_replace; + int nsmpl_annot; int *sample_map, nsample_map, sample_is_file; // map[idst] -> isrc int mtmpi, mtmpf, mtmps; int mtmpi2, mtmpf2, mtmps2; @@ -157,6 +161,7 @@ void remove_info(args_t *args, bcf1_t *line, rm_tag_t *tag) } line->d.shared_dirty |= BCF1_DIRTY_INF; inf->vptr = NULL; + inf->vptr_off = inf->vptr_len = 0; } } void remove_info_tag(args_t *args, bcf1_t *line, rm_tag_t *tag) @@ -189,6 +194,10 @@ void remove_format(args_t *args, bcf1_t *line, rm_tag_t *tag) } } +#include "htslib/khash.h" +KHASH_MAP_INIT_STR(vdict, bcf_idinfo_t) +typedef khash_t(vdict) vdict_t; + static void remove_hdr_lines(bcf_hdr_t *hdr, int type) { int i = 0, nrm = 0; @@ -196,11 +205,18 @@ static void remove_hdr_lines(bcf_hdr_t *hdr, int type) { if ( hdr->hrec[i]->type!=type ) { i++; continue; } bcf_hrec_t *hrec = hdr->hrec[i]; - if ( type==BCF_HL_FMT ) + if ( type==BCF_HL_FMT || type==BCF_HL_INFO || type==BCF_HL_FMT || type== BCF_HL_CTG ) { // everything except FORMAT/GT int id = bcf_hrec_find_key(hrec, "ID"); - if ( id>=0 && !strcmp(hrec->vals[id],"GT") ) { i++; continue; } + if ( id>=0 ) + { + if ( type==BCF_HL_FMT && !strcmp(hrec->vals[id],"GT") ) { i++; continue; } + vdict_t *d = type==BCF_HL_CTG ? (vdict_t*)hdr->dict[BCF_DT_CTG] : (vdict_t*)hdr->dict[BCF_DT_ID]; + khint_t k = kh_get(vdict, d, hdr->hrec[i]->vals[id]); + kh_val(d, k).hrec[type==BCF_HL_CTG?0:type] = NULL; + kh_val(d, k).info[type] |= 0xf; + } } nrm++; hdr->nhrec--; @@ -250,7 +266,7 @@ static void init_remove_annots(args_t *args) tag->key = strdup(str.s); tag->hdr_id = bcf_hdr_id2int(args->hdr, BCF_DT_ID, tag->key); if ( !bcf_hdr_idinfo_exists(args->hdr,BCF_HL_FLT,tag->hdr_id) ) error("Cannot remove %s, not defined in the header.\n", str.s); - bcf_hdr_remove(args->hdr_out,BCF_HL_FLT,tag->key); + if ( !args->keep_sites ) bcf_hdr_remove(args->hdr_out,BCF_HL_FLT,tag->key); } else { @@ -265,7 +281,7 @@ static void init_remove_annots(args_t *args) int id = bcf_hdr_id2int(args->hdr,BCF_DT_ID,str.s); if ( !bcf_hdr_idinfo_exists(args->hdr,type,id) ) { - fprintf(pysam_stderr,"Warning: The tag \"%s\" not defined in the header\n", str.s); + fprintf(bcftools_stderr,"Warning: The tag \"%s\" not defined in the header\n", str.s); args->nrm--; } else if ( (type==BCF_HL_FMT && keep_fmt) || (type==BCF_HL_INFO && keep_info) ) @@ -280,32 +296,35 @@ static void init_remove_annots(args_t *args) tag->key = strdup(str.s); if ( type==BCF_HL_INFO ) tag->handler = remove_info_tag; else if ( type==BCF_HL_FMT ) tag->handler = remove_format_tag; - bcf_hdr_remove(args->hdr_out,type,tag->key); + if ( !args->keep_sites ) bcf_hdr_remove(args->hdr_out,type,tag->key); } } else if ( !strcasecmp("ID",str.s) ) tag->handler = remove_id; else if ( !strcasecmp("FILTER",str.s) ) { tag->handler = remove_filter; - remove_hdr_lines(args->hdr_out,BCF_HL_FLT); + if ( !args->keep_sites ) remove_hdr_lines(args->hdr_out,BCF_HL_FLT); } else if ( !strcasecmp("QUAL",str.s) ) tag->handler = remove_qual; else if ( !strcasecmp("INFO",str.s) ) { tag->handler = remove_info; - remove_hdr_lines(args->hdr_out,BCF_HL_INFO); + if ( !args->keep_sites ) remove_hdr_lines(args->hdr_out,BCF_HL_INFO); } else if ( !strcasecmp("FMT",str.s) || !strcasecmp("FORMAT",str.s) ) { tag->handler = remove_format; - remove_hdr_lines(args->hdr_out,BCF_HL_FMT); + if ( !args->keep_sites ) remove_hdr_lines(args->hdr_out,BCF_HL_FMT); } else if ( str.l ) { - if ( str.s[0]=='#' && str.s[1]=='#' ) - bcf_hdr_remove(args->hdr_out,BCF_HL_GEN,str.s+2); - else - bcf_hdr_remove(args->hdr_out,BCF_HL_STR,str.s); + if ( !args->keep_sites ) + { + if ( str.s[0]=='#' && str.s[1]=='#' ) + bcf_hdr_remove(args->hdr_out,BCF_HL_GEN,str.s+2); + else + bcf_hdr_remove(args->hdr_out,BCF_HL_STR,str.s); + } args->nrm--; } @@ -341,7 +360,7 @@ static void init_remove_annots(args_t *args) tag->hdr_id = bcf_hdr_id2int(args->hdr, BCF_DT_ID, hrec->vals[k]); } tag->key = strdup(hrec->vals[k]); - bcf_hdr_remove(args->hdr_out,hrec->type,tag->key); + if ( !args->keep_sites ) bcf_hdr_remove(args->hdr_out,hrec->type,tag->key); } } khash_str2int_destroy_free(keep); @@ -455,7 +474,7 @@ static int setter_qual(args_t *args, bcf1_t *line, annot_col_t *col, void *data) line->qual = strtod(str, &str); if ( str == tab->cols[col->icol] ) - error("Could not parse %s at %s:%d .. [%s]\n", col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); + error("Could not parse %s at %s:%d .. [%s]\n", col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); return 0; } static int vcf_setter_qual(args_t *args, bcf1_t *line, annot_col_t *col, void *data) @@ -472,31 +491,31 @@ static int setter_info_flag(args_t *args, bcf1_t *line, annot_col_t *col, void * char *str = tab->cols[col->icol]; if ( str[0]=='.' && str[1]==0 ) return 0; - if ( str[0]=='1' && str[1]==0 ) return bcf_update_info_flag(args->hdr_out,line,col->hdr_key,NULL,1); - if ( str[0]=='0' && str[1]==0 ) return bcf_update_info_flag(args->hdr_out,line,col->hdr_key,NULL,0); + if ( str[0]=='1' && str[1]==0 ) return bcf_update_info_flag(args->hdr_out,line,col->hdr_key_dst,NULL,1); + if ( str[0]=='0' && str[1]==0 ) return bcf_update_info_flag(args->hdr_out,line,col->hdr_key_dst,NULL,0); error("Could not parse %s at %s:%d .. [%s]\n", bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); return -1; } static int vcf_setter_info_flag(args_t *args, bcf1_t *line, annot_col_t *col, void *data) { bcf1_t *rec = (bcf1_t*) data; - int flag = bcf_get_info_flag(args->files->readers[1].header,rec,col->hdr_key,NULL,NULL); - bcf_update_info_flag(args->hdr_out,line,col->hdr_key,NULL,flag); + int flag = bcf_get_info_flag(args->files->readers[1].header,rec,col->hdr_key_src,NULL,NULL); + bcf_update_info_flag(args->hdr_out,line,col->hdr_key_dst,NULL,flag); return 0; } static int setter_ARinfo_int32(args_t *args, bcf1_t *line, annot_col_t *col, int nals, char **als, int ntmpi) { if ( col->number==BCF_VL_A && ntmpi!=nals-1 && (ntmpi!=1 || args->tmpi[0]!=bcf_int32_missing || args->tmpi[1]!=bcf_int32_vector_end) ) - error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpi,col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpi,col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); else if ( col->number==BCF_VL_R && ntmpi!=nals && (ntmpi!=1 || args->tmpi[0]!=bcf_int32_missing || args->tmpi[1]!=bcf_int32_vector_end) ) - error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpi,col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpi,col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); int ndst = col->number==BCF_VL_A ? line->n_allele - 1 : line->n_allele; int *map = vcmp_map_ARvalues(args->vcmp,ndst,nals,als,line->n_allele,line->d.allele); if ( !map ) error("REF alleles not compatible at %s:%d\n"); // fill in any missing values in the target VCF (or all, if not present) - int ntmpi2 = bcf_get_info_float(args->hdr, line, col->hdr_key, &args->tmpi2, &args->mtmpi2); + int ntmpi2 = bcf_get_info_float(args->hdr, line, col->hdr_key_dst, &args->tmpi2, &args->mtmpi2); if ( ntmpi2 < ndst ) hts_expand(int32_t,ndst,args->mtmpi2,args->tmpi2); int i; @@ -513,7 +532,7 @@ static int setter_ARinfo_int32(args_t *args, bcf1_t *line, annot_col_t *col, int args->tmpi2[i] = args->tmpi[ map[i] ]; } - bcf_update_info_int32(args->hdr_out,line,col->hdr_key,args->tmpi2,ndst); + bcf_update_info_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi2,ndst); return 0; } static int setter_info_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data) @@ -539,17 +558,17 @@ static int setter_info_int(args_t *args, bcf1_t *line, annot_col_t *col, void *d if ( col->replace==REPLACE_MISSING ) { - int ret = bcf_get_info_int32(args->hdr, line, col->hdr_key, &args->tmpi2, &args->mtmpi2); + int ret = bcf_get_info_int32(args->hdr, line, col->hdr_key_dst, &args->tmpi2, &args->mtmpi2); if ( ret>0 && args->tmpi2[0]!=bcf_int32_missing ) return 0; } - bcf_update_info_int32(args->hdr_out,line,col->hdr_key,args->tmpi,ntmpi); + bcf_update_info_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi,ntmpi); return 0; } static int vcf_setter_info_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data) { bcf1_t *rec = (bcf1_t*) data; - int ntmpi = bcf_get_info_int32(args->files->readers[1].header,rec,col->hdr_key,&args->tmpi,&args->mtmpi); + int ntmpi = bcf_get_info_int32(args->files->readers[1].header,rec,col->hdr_key_src,&args->tmpi,&args->mtmpi); if ( ntmpi < 0 ) return 0; // nothing to add if ( col->number==BCF_VL_A || col->number==BCF_VL_R ) @@ -557,26 +576,26 @@ static int vcf_setter_info_int(args_t *args, bcf1_t *line, annot_col_t *col, voi if ( col->replace==REPLACE_MISSING ) { - int ret = bcf_get_info_int32(args->hdr, line, col->hdr_key, &args->tmpi2, &args->mtmpi2); + int ret = bcf_get_info_int32(args->hdr, line, col->hdr_key_dst, &args->tmpi2, &args->mtmpi2); if ( ret>0 && args->tmpi2[0]!=bcf_int32_missing ) return 0; } - bcf_update_info_int32(args->hdr_out,line,col->hdr_key,args->tmpi,ntmpi); + bcf_update_info_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi,ntmpi); return 0; } static int setter_ARinfo_real(args_t *args, bcf1_t *line, annot_col_t *col, int nals, char **als, int ntmpf) { if ( col->number==BCF_VL_A && ntmpf!=nals-1 && (ntmpf!=1 || !bcf_float_is_missing(args->tmpf[0]) || !bcf_float_is_vector_end(args->tmpf[0])) ) - error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpf,col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpf,col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); else if ( col->number==BCF_VL_R && ntmpf!=nals && (ntmpf!=1 || !bcf_float_is_missing(args->tmpf[0]) || !bcf_float_is_vector_end(args->tmpf[0])) ) - error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpf,col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("Incorrect number of values (%d) for the %s tag at %s:%d\n", ntmpf,col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); int ndst = col->number==BCF_VL_A ? line->n_allele - 1 : line->n_allele; int *map = vcmp_map_ARvalues(args->vcmp,ndst,nals,als,line->n_allele,line->d.allele); if ( !map ) error("REF alleles not compatible at %s:%d\n"); // fill in any missing values in the target VCF (or all, if not present) - int ntmpf2 = bcf_get_info_float(args->hdr, line, col->hdr_key, &args->tmpf2, &args->mtmpf2); + int ntmpf2 = bcf_get_info_float(args->hdr, line, col->hdr_key_dst, &args->tmpf2, &args->mtmpf2); if ( ntmpf2 < ndst ) hts_expand(float,ndst,args->mtmpf2,args->tmpf2); int i; @@ -593,7 +612,7 @@ static int setter_ARinfo_real(args_t *args, bcf1_t *line, annot_col_t *col, int args->tmpf2[i] = args->tmpf[ map[i] ]; } - bcf_update_info_float(args->hdr_out,line,col->hdr_key,args->tmpf2,ndst); + bcf_update_info_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf2,ndst); return 0; } static int setter_info_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data) @@ -619,17 +638,17 @@ static int setter_info_real(args_t *args, bcf1_t *line, annot_col_t *col, void * if ( col->replace==REPLACE_MISSING ) { - int ret = bcf_get_info_float(args->hdr, line, col->hdr_key, &args->tmpf2, &args->mtmpf2); + int ret = bcf_get_info_float(args->hdr, line, col->hdr_key_dst, &args->tmpf2, &args->mtmpf2); if ( ret>0 && !bcf_float_is_missing(args->tmpf2[0]) ) return 0; } - bcf_update_info_float(args->hdr_out,line,col->hdr_key,args->tmpf,ntmpf); + bcf_update_info_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf,ntmpf); return 0; } static int vcf_setter_info_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data) { bcf1_t *rec = (bcf1_t*) data; - int ntmpf = bcf_get_info_float(args->files->readers[1].header,rec,col->hdr_key,&args->tmpf,&args->mtmpf); + int ntmpf = bcf_get_info_float(args->files->readers[1].header,rec,col->hdr_key_src,&args->tmpf,&args->mtmpf); if ( ntmpf < 0 ) return 0; // nothing to add if ( col->number==BCF_VL_A || col->number==BCF_VL_R ) @@ -637,11 +656,11 @@ static int vcf_setter_info_real(args_t *args, bcf1_t *line, annot_col_t *col, vo if ( col->replace==REPLACE_MISSING ) { - int ret = bcf_get_info_float(args->hdr, line, col->hdr_key, &args->tmpf2, &args->mtmpf2); + int ret = bcf_get_info_float(args->hdr, line, col->hdr_key_dst, &args->tmpf2, &args->mtmpf2); if ( ret>0 && !bcf_float_is_missing(args->tmpf2[0]) ) return 0; } - bcf_update_info_float(args->hdr_out,line,col->hdr_key,args->tmpf,ntmpf); + bcf_update_info_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf,ntmpf); return 0; } int copy_string_field(char *src, int isrc, int src_len, kstring_t *dst, int idst); // see vcfmerge.c @@ -654,9 +673,9 @@ static int setter_ARinfo_string(args_t *args, bcf1_t *line, annot_col_t *col, in lsrc++; } if ( col->number==BCF_VL_A && nsrc!=nals-1 && (nsrc!=1 || args->tmps[0]!='.' || args->tmps[1]!=0 ) ) - error("Incorrect number of values (%d) for the %s tag at %s:%d\n", nsrc,col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("Incorrect number of values (%d) for the %s tag at %s:%d\n", nsrc,col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); else if ( col->number==BCF_VL_R && nsrc!=nals && (nsrc!=1 || args->tmps[0]!='.' || args->tmps[1]!=0 ) ) - error("Incorrect number of values (%d) for the %s tag at %s:%d\n", nsrc,col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("Incorrect number of values (%d) for the %s tag at %s:%d\n", nsrc,col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); int ndst = col->number==BCF_VL_A ? line->n_allele - 1 : line->n_allele; int *map = vcmp_map_ARvalues(args->vcmp,ndst,nals,als,line->n_allele,line->d.allele); @@ -664,7 +683,7 @@ static int setter_ARinfo_string(args_t *args, bcf1_t *line, annot_col_t *col, in // fill in any missing values in the target VCF (or all, if not present) int i, empty = 0, nstr, mstr = args->tmpks.m; - nstr = bcf_get_info_string(args->hdr, line, col->hdr_key, &args->tmpks.s, &mstr); + nstr = bcf_get_info_string(args->hdr, line, col->hdr_key_dst, &args->tmpks.s, &mstr); args->tmpks.m = mstr; if ( nstr<0 || (nstr==1 && args->tmpks.s[0]=='.' && args->tmpks.s[1]==0) ) { @@ -697,7 +716,7 @@ static int setter_ARinfo_string(args_t *args, bcf1_t *line, annot_col_t *col, in int ret = copy_string_field(args->tmps,map[i],lsrc,&args->tmpks,i); assert( ret==0 ); } - bcf_update_info_string(args->hdr_out,line,col->hdr_key,args->tmpks.s); + bcf_update_info_string(args->hdr_out,line,col->hdr_key_dst,args->tmpks.s); return 0; } static int setter_info_str(args_t *args, bcf1_t *line, annot_col_t *col, void *data) @@ -714,17 +733,17 @@ static int setter_info_str(args_t *args, bcf1_t *line, annot_col_t *col, void *d if ( col->replace==REPLACE_MISSING ) { - int ret = bcf_get_info_string(args->hdr, line, col->hdr_key, &args->tmps2, &args->mtmps2); + int ret = bcf_get_info_string(args->hdr, line, col->hdr_key_dst, &args->tmps2, &args->mtmps2); if ( ret>0 && (args->tmps2[0]!='.' || args->tmps2[1]!=0) ) return 0; } - bcf_update_info_string(args->hdr_out,line,col->hdr_key,args->tmps); + bcf_update_info_string(args->hdr_out,line,col->hdr_key_dst,args->tmps); return 0; } static int vcf_setter_info_str(args_t *args, bcf1_t *line, annot_col_t *col, void *data) { bcf1_t *rec = (bcf1_t*) data; - int ntmps = bcf_get_info_string(args->files->readers[1].header,rec,col->hdr_key,&args->tmps,&args->mtmps); + int ntmps = bcf_get_info_string(args->files->readers[1].header,rec,col->hdr_key_src,&args->tmps,&args->mtmps); if ( ntmps < 0 ) return 0; // nothing to add if ( col->number==BCF_VL_A || col->number==BCF_VL_R ) @@ -732,11 +751,11 @@ static int vcf_setter_info_str(args_t *args, bcf1_t *line, annot_col_t *col, voi if ( col->replace==REPLACE_MISSING ) { - int ret = bcf_get_info_string(args->hdr, line, col->hdr_key, &args->tmps2, &args->mtmps2); + int ret = bcf_get_info_string(args->hdr, line, col->hdr_key_dst, &args->tmps2, &args->mtmps2); if ( ret>0 && (args->tmps2[0]!='.' || args->tmps2[1]!=0) ) return 0; } - bcf_update_info_string(args->hdr_out,line,col->hdr_key,args->tmps); + bcf_update_info_string(args->hdr_out,line,col->hdr_key_dst,args->tmps); return 0; } static int vcf_setter_format_gt(args_t *args, bcf1_t *line, annot_col_t *col, void *data) @@ -754,7 +773,7 @@ static int vcf_setter_format_gt(args_t *args, bcf1_t *line, annot_col_t *col, vo nsrc /= bcf_hdr_nsamples(args->files->readers[1].header); if ( ndst<=0 ) // field not present in dst file { - if ( col->replace==REPLACE_EXISTING ) return 0; + if ( col->replace==REPLACE_NON_MISSING ) return 0; hts_expand(int32_t, nsrc*bcf_hdr_nsamples(args->hdr_out), args->mtmpi2, args->tmpi2); for (i=0; ihdr_out); i++) { @@ -779,7 +798,7 @@ static int vcf_setter_format_gt(args_t *args, bcf1_t *line, annot_col_t *col, vo if ( args->sample_map[i]==-1 ) continue; int32_t *src = args->tmpi + nsrc*args->sample_map[i]; int32_t *dst = args->tmpi2 + ndst*i; - if ( col->replace==REPLACE_EXISTING && bcf_gt_is_missing(dst[0]) ) continue; + if ( col->replace==REPLACE_NON_MISSING && bcf_gt_is_missing(dst[0]) ) continue; if ( col->replace==REPLACE_MISSING && !bcf_gt_is_missing(dst[0]) ) continue; for (j=0; jtmpi3 + nsrc*i; int keep_ori = 0; if ( args->sample_map[i]==-1 ) keep_ori = 1; - else if ( col->replace==REPLACE_EXISTING && bcf_gt_is_missing(ori[0]) ) keep_ori = 1; + else if ( col->replace==REPLACE_NON_MISSING && bcf_gt_is_missing(ori[0]) ) keep_ori = 1; else if ( col->replace==REPLACE_MISSING && !bcf_gt_is_missing(ori[0]) ) keep_ori = 1; if ( keep_ori ) { @@ -813,7 +832,7 @@ static int vcf_setter_format_gt(args_t *args, bcf1_t *line, annot_col_t *col, vo } static int count_vals(annot_line_t *tab, int icol_beg, int icol_end) { - int i, nmax = 0; + int i, nmax = 1; for (i=icol_beg; icols[i], *end = str; @@ -833,298 +852,306 @@ static int count_vals(annot_line_t *tab, int icol_beg, int icol_end) } return nmax; } -static int setter_format_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data) -{ - annot_line_t *tab = (annot_line_t*) data; - int nsmpl = bcf_hdr_nsamples(args->hdr_out); - assert( col->icol+nsmpl <= tab->ncols ); - int nvals = count_vals(tab,col->icol,col->icol+nsmpl); - assert( nvals>0 ); - hts_expand(int32_t,nvals*nsmpl,args->mtmpi,args->tmpi); - - int icol = col->icol, ismpl; - for (ismpl=0; ismpltmpi + ismpl*nvals; - int ival = 0; - - char *str = tab->cols[icol]; - while ( *str ) - { - if ( str[0]=='.' && (!str[1] || str[1]==',') ) // missing value - { - ptr[ival++] = bcf_int32_missing; - str += str[1] ? 2 : 1; - continue; - } - - char *end = str; - ptr[ival] = strtol(str, &end, 10); - if ( end==str ) - error("Could not parse %s at %s:%d .. [%s]\n", col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); - - ival++; - str = *end ? end+1 : end; - } - while ( ivalhdr_out,line,col->hdr_key,args->tmpi,nsmpl*nvals); -} -static int setter_format_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +static int core_setter_format_int(args_t *args, bcf1_t *line, annot_col_t *col, int32_t *vals, int nvals) { - annot_line_t *tab = (annot_line_t*) data; - int nsmpl = bcf_hdr_nsamples(args->hdr_out); - assert( col->icol+nsmpl <= tab->ncols ); - int nvals = count_vals(tab,col->icol,col->icol+nsmpl); - assert( nvals>0 ); - hts_expand(float,nvals*nsmpl,args->mtmpf,args->tmpf); - - int icol = col->icol, ismpl; - for (ismpl=0; ismpltmpf + ismpl*nvals; - int ival = 0; - - char *str = tab->cols[icol]; - while ( *str ) - { - if ( str[0]=='.' && (!str[1] || str[1]==',') ) // missing value - { - bcf_float_set_missing(ptr[ival]); - ival++; - str += str[1] ? 2 : 1; - continue; - } - - char *end = str; - ptr[ival] = strtod(str, &end); - if ( end==str ) - error("Could not parse %s at %s:%d .. [%s]\n", col->hdr_key,bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); - - ival++; - str = *end ? end+1 : end; - } - while ( ivalhdr_out,line,col->hdr_key,args->tmpf,nsmpl*nvals); -} -static int setter_format_str(args_t *args, bcf1_t *line, annot_col_t *col, void *data) -{ - annot_line_t *tab = (annot_line_t*) data; - int nsmpl = bcf_hdr_nsamples(args->hdr_out); - assert( col->icol+nsmpl <= tab->ncols ); - - int i, max_len = 0; - for (i=col->icol; iicol+nsmpl; i++) - { - int len = strlen(tab->cols[i]); - if ( max_len < len ) max_len = len; - } - hts_expand(char,max_len*nsmpl,args->mtmps,args->tmps); - - int icol = col->icol, ismpl; - for (ismpl=0; ismpltmps + ismpl*max_len; - char *str = tab->cols[icol]; - i = 0; - while ( str[i] ) - { - ptr[i] = str[i]; - i++; - } - while ( ihdr_out,line,col->hdr_key,args->tmps,nsmpl*max_len); -} -static int vcf_setter_format_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data) -{ - bcf1_t *rec = (bcf1_t*) data; - int nsrc = bcf_get_format_int32(args->files->readers[1].header,rec,col->hdr_key,&args->tmpi,&args->mtmpi); - if ( nsrc==-3 ) return 0; // the tag is not present - if ( nsrc<=0 ) return 1; // error - if ( !args->sample_map ) - return bcf_update_format_int32(args->hdr_out,line,col->hdr_key,args->tmpi,nsrc); + return bcf_update_format_int32(args->hdr_out,line,col->hdr_key_dst,vals,nvals*args->nsmpl_annot); - int i, j, ndst = bcf_get_format_int32(args->hdr,line,col->hdr_key,&args->tmpi2,&args->mtmpi2); + int i, j, ndst = bcf_get_format_int32(args->hdr,line,col->hdr_key_dst,&args->tmpi2,&args->mtmpi2); if ( ndst > 0 ) ndst /= bcf_hdr_nsamples(args->hdr_out); - nsrc /= bcf_hdr_nsamples(args->files->readers[1].header); if ( ndst<=0 ) { - if ( col->replace==REPLACE_EXISTING ) return 0; // overwrite only if present - hts_expand(int32_t, nsrc*bcf_hdr_nsamples(args->hdr_out), args->mtmpi2, args->tmpi2); + if ( col->replace==REPLACE_NON_MISSING ) return 0; // overwrite only if present + hts_expand(int32_t, nvals*bcf_hdr_nsamples(args->hdr_out), args->mtmpi2, args->tmpi2); for (i=0; ihdr_out); i++) { - int32_t *dst = args->tmpi2 + nsrc*i; + int32_t *dst = args->tmpi2 + nvals*i; if ( args->sample_map[i]==-1 ) { dst[0] = bcf_int32_missing; - for (j=1; jtmpi + nsrc*args->sample_map[i]; - for (j=0; jsample_map[i]; + for (j=0; jhdr_out,line,col->hdr_key,args->tmpi2,nsrc*bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi2,nvals*bcf_hdr_nsamples(args->hdr_out)); } - else if ( ndst >= nsrc ) + else if ( ndst >= nvals ) { for (i=0; ihdr_out); i++) { if ( args->sample_map[i]==-1 ) continue; - int32_t *src = args->tmpi + nsrc*args->sample_map[i]; + int32_t *src = vals + nvals*args->sample_map[i]; int32_t *dst = args->tmpi2 + ndst*i; - if ( col->replace==REPLACE_EXISTING && dst[0]==bcf_int32_missing ) continue; - if ( col->replace==REPLACE_MISSING && dst[0]!=bcf_int32_missing ) continue; - for (j=0; jreplace==REPLACE_NON_MISSING ) { if ( dst[0]==bcf_int32_missing ) continue; } + else if ( col->replace==REPLACE_MISSING ) { if ( dst[0]!=bcf_int32_missing ) continue; } + else if ( col->replace==REPLACE_ALL ) { if ( src[0]==bcf_int32_missing ) continue; } + for (j=0; jhdr_out,line,col->hdr_key,args->tmpi2,ndst*bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi2,ndst*bcf_hdr_nsamples(args->hdr_out)); } - else // ndst < nsrc + else // ndst < nvals { - hts_expand(int32_t, nsrc*bcf_hdr_nsamples(args->hdr_out), args->mtmpi3, args->tmpi3); + hts_expand(int32_t, nvals*bcf_hdr_nsamples(args->hdr_out), args->mtmpi3, args->tmpi3); for (i=0; ihdr_out); i++) { - int32_t *ori = args->tmpi2 + ndst*i; - int32_t *dst = args->tmpi3 + nsrc*i; - int keep_ori = 0; - if ( args->sample_map[i]==-1 ) keep_ori = 1; - else if ( col->replace==REPLACE_EXISTING && ori[0]==bcf_int32_missing ) keep_ori = 1; - else if ( col->replace==REPLACE_MISSING && ori[0]!=bcf_int32_missing ) keep_ori = 1; - if ( keep_ori ) + int32_t *ann = vals + nvals*args->sample_map[i]; + int32_t *ori = args->tmpi2 + ndst*i; // ori vcf line + int32_t *dst = args->tmpi3 + nvals*i; // expanded buffer + int use_new_ann = 1; + if ( args->sample_map[i]==-1 ) use_new_ann = 0; + else if ( col->replace==REPLACE_NON_MISSING ) { if ( ori[0]==bcf_int32_missing ) use_new_ann = 0; } + else if ( col->replace==REPLACE_MISSING ) { if ( ori[0]!=bcf_int32_missing ) use_new_ann = 0; } + else if ( col->replace==REPLACE_ALL ) { if ( ann[0]==bcf_int32_missing ) use_new_ann = 0; } + if ( !use_new_ann ) { for (j=0; jtmpi + nsrc*args->sample_map[i]; - for (j=0; jhdr_out,line,col->hdr_key,args->tmpi3,nsrc*bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_int32(args->hdr_out,line,col->hdr_key_dst,args->tmpi3,nvals*bcf_hdr_nsamples(args->hdr_out)); } } -static int vcf_setter_format_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +static int core_setter_format_real(args_t *args, bcf1_t *line, annot_col_t *col, float *vals, int nvals) { - bcf1_t *rec = (bcf1_t*) data; - int nsrc = bcf_get_format_float(args->files->readers[1].header,rec,col->hdr_key,&args->tmpf,&args->mtmpf); - if ( nsrc==-3 ) return 0; // the tag is not present - if ( nsrc<=0 ) return 1; // error - if ( !args->sample_map ) - return bcf_update_format_float(args->hdr_out,line,col->hdr_key,args->tmpf,nsrc); + return bcf_update_format_float(args->hdr_out,line,col->hdr_key_dst,vals,nvals*args->nsmpl_annot); - int i, j, ndst = bcf_get_format_float(args->hdr,line,col->hdr_key,&args->tmpf2,&args->mtmpf2); + int i, j, ndst = bcf_get_format_float(args->hdr,line,col->hdr_key_dst,&args->tmpf2,&args->mtmpf2); if ( ndst > 0 ) ndst /= bcf_hdr_nsamples(args->hdr_out); - nsrc /= bcf_hdr_nsamples(args->files->readers[1].header); if ( ndst<=0 ) { - if ( col->replace==REPLACE_EXISTING ) return 0; // overwrite only if present - hts_expand(float, nsrc*bcf_hdr_nsamples(args->hdr_out), args->mtmpf2, args->tmpf2); + if ( col->replace==REPLACE_NON_MISSING ) return 0; // overwrite only if present + hts_expand(float, nvals*bcf_hdr_nsamples(args->hdr_out), args->mtmpf2, args->tmpf2); for (i=0; ihdr_out); i++) { - float *dst = args->tmpf2 + nsrc*i; + float *dst = args->tmpf2 + nvals*i; if ( args->sample_map[i]==-1 ) { bcf_float_set_missing(dst[0]); - for (j=1; jtmpf + nsrc*args->sample_map[i]; - for (j=0; jsample_map[i]; + for (j=0; jhdr_out,line,col->hdr_key,args->tmpf2,nsrc*bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf2,nvals*bcf_hdr_nsamples(args->hdr_out)); } - else if ( ndst >= nsrc ) + else if ( ndst >= nvals ) { for (i=0; ihdr_out); i++) { if ( args->sample_map[i]==-1 ) continue; - float *src = args->tmpf + nsrc*args->sample_map[i]; + float *src = vals + nvals*args->sample_map[i]; float *dst = args->tmpf2 + ndst*i; - if ( col->replace==REPLACE_EXISTING && bcf_float_is_missing(dst[0]) ) continue; - if ( col->replace==REPLACE_MISSING && !bcf_float_is_missing(dst[0]) ) continue; - for (j=0; jreplace==REPLACE_NON_MISSING ) { if ( bcf_float_is_missing(dst[0]) ) continue; } + else if ( col->replace==REPLACE_MISSING ) { if ( !bcf_float_is_missing(dst[0]) ) continue; } + else if ( col->replace==REPLACE_ALL ) { if ( bcf_float_is_missing(src[0]) ) continue; } + for (j=0; jhdr_out,line,col->hdr_key,args->tmpf2,ndst*bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf2,ndst*bcf_hdr_nsamples(args->hdr_out)); } - else // ndst < nsrc + else // ndst < nvals { - hts_expand(float, nsrc*bcf_hdr_nsamples(args->hdr_out), args->mtmpf3, args->tmpf3); + hts_expand(float, nvals*bcf_hdr_nsamples(args->hdr_out), args->mtmpf3, args->tmpf3); for (i=0; ihdr_out); i++) { - float *ori = args->tmpf2 + ndst*i; - float *dst = args->tmpf3 + nsrc*i; - int keep_ori = 0; - if ( args->sample_map[i]==-1 ) keep_ori = 1; - else if ( col->replace==REPLACE_EXISTING && bcf_float_is_missing(ori[0]) ) keep_ori = 1; - else if ( col->replace==REPLACE_MISSING && !bcf_float_is_missing(ori[0]) ) keep_ori = 1; - if ( keep_ori ) + float *ann = vals + nvals*args->sample_map[i]; + float *ori = args->tmpf2 + ndst*i; // ori vcf line + float *dst = args->tmpf3 + nvals*i; // expanded buffer + int use_new_ann = 1; + if ( args->sample_map[i]==-1 ) use_new_ann = 0; + else if ( col->replace==REPLACE_NON_MISSING ) { if ( bcf_float_is_missing(ori[0]) ) use_new_ann = 0; } + else if ( col->replace==REPLACE_MISSING ) { if ( !bcf_float_is_missing(ori[0]) ) use_new_ann = 0; } + else if ( col->replace==REPLACE_ALL ) { if ( bcf_float_is_missing(ann[0]) ) use_new_ann = 0; } + if ( !use_new_ann ) { for (j=0; jtmpf + nsrc*args->sample_map[i]; - for (j=0; jhdr_out,line,col->hdr_key,args->tmpf3,nsrc*bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_float(args->hdr_out,line,col->hdr_key_dst,args->tmpf3,nvals*bcf_hdr_nsamples(args->hdr_out)); } } -static int vcf_setter_format_str(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +static int core_setter_format_str(args_t *args, bcf1_t *line, annot_col_t *col, char **vals) { - bcf1_t *rec = (bcf1_t*) data; - args->tmpp[0] = args->tmps; - int ret = bcf_get_format_string(args->files->readers[1].header,rec,col->hdr_key,&args->tmpp,&args->mtmps); - args->tmps = args->tmpp[0]; // tmps might be realloced - if ( ret==-3 ) return 0; // the tag is not present - if ( ret<=0 ) return 1; // error - if ( !args->sample_map ) - return bcf_update_format_string(args->hdr_out,line,col->hdr_key,(const char**)args->tmpp,bcf_hdr_nsamples(args->hdr_out)); + return bcf_update_format_string(args->hdr_out,line,col->hdr_key_dst,(const char**)vals,args->nsmpl_annot); int i; args->tmpp2[0] = args->tmps2; - ret = bcf_get_format_string(args->hdr,line,col->hdr_key,&args->tmpp2,&args->mtmps2); + int ret = bcf_get_format_string(args->hdr,line,col->hdr_key_dst,&args->tmpp2,&args->mtmps2); args->tmps2 = args->tmpp2[0]; // tmps2 might be realloced + int nsmpl = bcf_hdr_nsamples(args->hdr_out); if ( ret<=0 ) // not present in dst { hts_expand(char,bcf_hdr_nsamples(args->hdr_out)*2,args->mtmps2,args->tmps2); - for (i=0; ihdr_out); i++) + char *tmp = args->tmps2; + for (i=0; itmpp2[i] = tmp; + tmp += 2; + } + } + for (i=0; isample_map[i]==-1 ) continue; + char **src = vals + args->sample_map[i]; + char **dst = args->tmpp2 + i; + + if ( col->replace==REPLACE_NON_MISSING ) { if ( (*dst)[0]=='.' && (*dst)[1]==0 ) continue; } + else if ( col->replace==REPLACE_MISSING ) { if ( (*dst)[0]!='.' || (*dst)[1]!=0 ) continue; } + else if ( col->replace==REPLACE_ALL ) { if ( (*src)[0]=='.' && (*src)[1]==0 ) continue; } + *dst = *src; + } + return bcf_update_format_string(args->hdr_out,line,col->hdr_key_dst,(const char**)args->tmpp2,nsmpl); +} +static int setter_format_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +{ + annot_line_t *tab = (annot_line_t*) data; + if ( col->icol+args->nsmpl_annot > tab->ncols ) + error("Incorrect number of values for %s at %s:%d\n",col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); + int nvals = count_vals(tab,col->icol,col->icol+args->nsmpl_annot); + hts_expand(int32_t,nvals*args->nsmpl_annot,args->mtmpi,args->tmpi); + + int icol = col->icol, ismpl; + for (ismpl=0; ismplnsmpl_annot; ismpl++) + { + int32_t *ptr = args->tmpi + ismpl*nvals; + int ival = 0; + + char *str = tab->cols[icol]; + while ( *str ) { - args->tmps2[2*i] = '.'; - args->tmps2[2*i+1] = 0; - args->tmpp2[i] = args->tmps2+2*i; + if ( str[0]=='.' && (!str[1] || str[1]==',') ) // missing value + { + ptr[ival++] = bcf_int32_missing; + str += str[1] ? 2 : 1; + continue; + } + + char *end = str; + ptr[ival] = strtol(str, &end, 10); + if ( end==str ) + error("Could not parse %s at %s:%d .. [%s]\n", col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); + + ival++; + str = *end ? end+1 : end; } + while ( ivaltmpi,nvals); +} +static int setter_format_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +{ + annot_line_t *tab = (annot_line_t*) data; + if ( col->icol+args->nsmpl_annot > tab->ncols ) + error("Incorrect number of values for %s at %s:%d\n",col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); + int nvals = count_vals(tab,col->icol,col->icol+args->nsmpl_annot); + hts_expand(float,nvals*args->nsmpl_annot,args->mtmpf,args->tmpf); - for (i=0; ihdr_out); i++) + int icol = col->icol, ismpl; + for (ismpl=0; ismplnsmpl_annot; ismpl++) { - int isrc = args->sample_map[i]; - if ( isrc==-1 ) continue; - args->tmpp2[i] = args->tmpp[isrc]; + float *ptr = args->tmpf + ismpl*nvals; + int ival = 0; + + char *str = tab->cols[icol]; + while ( *str ) + { + if ( str[0]=='.' && (!str[1] || str[1]==',') ) // missing value + { + bcf_float_set_missing(ptr[ival]); + ival++; + str += str[1] ? 2 : 1; + continue; + } + + char *end = str; + ptr[ival] = strtod(str, &end); + if ( end==str ) + error("Could not parse %s at %s:%d .. [%s]\n", col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1,tab->cols[col->icol]); + + ival++; + str = *end ? end+1 : end; + } + while ( ivalhdr_out,line,col->hdr_key,(const char**)args->tmpp2,bcf_hdr_nsamples(args->hdr_out)); + return core_setter_format_real(args,line,col,args->tmpf,nvals); } -static void set_samples(args_t *args, bcf_hdr_t *src, bcf_hdr_t *dst, int need_samples) +static int setter_format_str(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +{ + annot_line_t *tab = (annot_line_t*) data; + if ( col->icol+args->nsmpl_annot > tab->ncols ) + error("Incorrect number of values for %s at %s:%d\n",col->hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); + + int ismpl; + for (ismpl=0; ismplnsmpl_annot; ismpl++) + args->tmpp[ismpl] = tab->cols[col->icol + ismpl]; + + return core_setter_format_str(args,line,col,args->tmpp); +} +static int vcf_setter_format_int(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +{ + bcf1_t *rec = (bcf1_t*) data; + int nsrc = bcf_get_format_int32(args->files->readers[1].header,rec,col->hdr_key_src,&args->tmpi,&args->mtmpi); + if ( nsrc==-3 ) return 0; // the tag is not present + if ( nsrc<=0 ) return 1; // error + return core_setter_format_int(args,line,col,args->tmpi,nsrc/bcf_hdr_nsamples(args->files->readers[1].header)); +} +static int vcf_setter_format_real(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +{ + bcf1_t *rec = (bcf1_t*) data; + int nsrc = bcf_get_format_float(args->files->readers[1].header,rec,col->hdr_key_src,&args->tmpf,&args->mtmpf); + if ( nsrc==-3 ) return 0; // the tag is not present + if ( nsrc<=0 ) return 1; // error + return core_setter_format_real(args,line,col,args->tmpf,nsrc/bcf_hdr_nsamples(args->files->readers[1].header)); +} + +static int vcf_setter_format_str(args_t *args, bcf1_t *line, annot_col_t *col, void *data) +{ + bcf1_t *rec = (bcf1_t*) data; + args->tmpp[0] = args->tmps; + int ret = bcf_get_format_string(args->files->readers[1].header,rec,col->hdr_key_src,&args->tmpp,&args->mtmps); + args->tmps = args->tmpp[0]; // tmps might be realloced + if ( ret==-3 ) return 0; // the tag is not present + if ( ret<=0 ) return 1; // error + return core_setter_format_str(args,line,col,args->tmpp); +} +static int init_sample_map(args_t *args, bcf_hdr_t *src, bcf_hdr_t *dst) { int i; if ( !args->sample_names ) { + args->nsmpl_annot = bcf_hdr_nsamples(dst); + + // tab annotation file, expecting that all samples are present: sample map not needed + if ( !src ) return 0; + int nmatch = 0, order_ok = 1; for (i=0; insample_map = bcf_hdr_nsamples(dst); args->sample_map = (int*) malloc(sizeof(int)*args->nsample_map); @@ -1148,46 +1172,70 @@ static void set_samples(args_t *args, bcf_hdr_t *src, bcf_hdr_t *dst, int need_s int id = bcf_hdr_id2int(src, BCF_DT_SAMPLE, dst->samples[i]); args->sample_map[i] = id; // idst -> isrc, -1 if not present } - return; + return 1; } args->nsample_map = bcf_hdr_nsamples(dst); args->sample_map = (int*) malloc(sizeof(int)*args->nsample_map); for (i=0; insample_map; i++) args->sample_map[i] = -1; - int nsamples = 0; - char **samples = hts_readlist(args->sample_names, args->sample_is_file, &nsamples); - for (i=0; isample_names, args->sample_is_file, SMPL_STRICT); + if ( !ilist || !ilist->n ) error("Could not parse: %s\n", args->sample_names); + char **samples = (char**) malloc(sizeof(char*)*ilist->n); + for (i=0; in; i++) samples[i] = strdup(dst->samples[i]); + args->nsmpl_annot = ilist->n; + smpl_ilist_destroy(ilist); + int need_sample_map = args->nsmpl_annot==bcf_hdr_nsamples(dst) ? 0 : 1; + if ( !src ) { - int isrc, idst; - char *ss = samples[i], *se = samples[i]; - while ( *se && !isspace(*se) ) se++; - if ( !*se ) + // tab annotation file + for (i=0; insmpl_annot; i++) { - // only one sample name + int idst = bcf_hdr_id2int(dst, BCF_DT_SAMPLE, samples[i]); + if ( idst==-1 ) error("Sample \"%s\" not found in the destination file\n", samples[i]); + args->sample_map[idst] = i; + if ( idst!=i ) need_sample_map = 1; + } + } + else + { + // vcf annotation file + for (i=0; insmpl_annot; i++) + { + int isrc, idst; + char *ss = samples[i], *se = samples[i]; + while ( *se && !isspace(*se) ) se++; + if ( !*se ) + { + // only one sample name + isrc = bcf_hdr_id2int(src, BCF_DT_SAMPLE,ss); + if ( isrc==-1 ) error("Sample \"%s\" not found in the source file\n", ss); + idst = bcf_hdr_id2int(dst, BCF_DT_SAMPLE,ss); + if ( idst==-1 ) error("Sample \"%s\" not found in the destination file\n", ss); + args->sample_map[idst] = isrc; + if ( idst!=isrc ) need_sample_map = 1; + continue; + } + *se = 0; isrc = bcf_hdr_id2int(src, BCF_DT_SAMPLE,ss); if ( isrc==-1 ) error("Sample \"%s\" not found in the source file\n", ss); + + ss = se+1; + while ( isspace(*ss) ) ss++; + se = ss; + while ( *se && !isspace(*se) ) se++; + idst = bcf_hdr_id2int(dst, BCF_DT_SAMPLE,ss); if ( idst==-1 ) error("Sample \"%s\" not found in the destination file\n", ss); + args->sample_map[idst] = isrc; - continue; + if ( idst!=isrc ) need_sample_map = 1; } - *se = 0; - isrc = bcf_hdr_id2int(src, BCF_DT_SAMPLE,ss); - if ( isrc==-1 ) error("Sample \"%s\" not found in the source file\n", ss); - - ss = se+1; - while ( isspace(*ss) ) ss++; - se = ss; - while ( *se && !isspace(*se) ) se++; - - idst = bcf_hdr_id2int(dst, BCF_DT_SAMPLE,ss); - if ( idst==-1 ) error("Sample \"%s\" not found in the destination file\n", ss); - - args->sample_map[idst] = isrc; } - for (i=0; insmpl_annot; i++) free(samples[i]); free(samples); + return need_sample_map; } static char *columns_complement(char *columns, void **skip_info, void **skip_fmt) { @@ -1249,8 +1297,27 @@ static char *columns_complement(char *columns, void **skip_info, void **skip_fmt free(columns); return str.s; } +static void bcf_hrec_format_rename(bcf_hrec_t *hrec, char *tag, kstring_t *str) +{ + int j, nout = 0; + ksprintf(str, "##%s=<", hrec->key); + for (j=0; jnkeys; j++) + { + if ( !strcmp("IDX",hrec->keys[j]) ) continue; + if ( nout ) kputc(',',str); + if ( !strcmp("ID", hrec->keys[j]) ) + ksprintf(str,"%s=%s", hrec->keys[j], tag); + else + ksprintf(str,"%s=%s", hrec->keys[j], hrec->vals[j]); + nout++; + } + ksprintf(str,">\n"); +} static void init_columns(args_t *args) { + int need_sample_map = 0; + int sample_map_ok = init_sample_map(args, args->tgts_is_vcf?args->files->readers[1].header:NULL, args->hdr); + void *skip_fmt = NULL, *skip_info = NULL; if ( args->tgts_is_vcf ) args->columns = columns_complement(args->columns, &skip_info, &skip_fmt); @@ -1258,13 +1325,13 @@ static void init_columns(args_t *args) kstring_t str = {0,0,0}, tmp = {0,0,0}; char *ss = args->columns, *se = ss; args->ncols = 0; - int icol = -1, has_fmt_str = 0, force_samples = -1; + int icol = -1, has_fmt_str = 0; while ( *ss ) { if ( *se && *se!=',' ) { se++; continue; } int replace = REPLACE_ALL; if ( *ss=='+' ) { replace = REPLACE_MISSING; ss++; } - else if ( *ss=='-' ) { replace = REPLACE_EXISTING; ss++; } + else if ( *ss=='-' ) { replace = REPLACE_NON_MISSING; ss++; } else if ( *ss=='=' ) { replace = SET_OR_APPEND; ss++; } icol++; str.l = 0; @@ -1278,23 +1345,25 @@ static void init_columns(args_t *args) else if ( !strcasecmp("ALT",str.s) ) args->alt_idx = icol; else if ( !strcasecmp("ID",str.s) ) { - if ( replace==REPLACE_EXISTING ) error("Apologies, the -ID feature has not been implemented yet.\n"); + if ( replace==REPLACE_NON_MISSING ) error("Apologies, the -ID feature has not been implemented yet.\n"); args->ncols++; args->cols = (annot_col_t*) realloc(args->cols,sizeof(annot_col_t)*args->ncols); annot_col_t *col = &args->cols[args->ncols-1]; col->icol = icol; col->replace = replace; col->setter = args->tgts_is_vcf ? vcf_setter_id : setter_id; - col->hdr_key = strdup(str.s); + col->hdr_key_src = strdup(str.s); + col->hdr_key_dst = strdup(str.s); } else if ( !strcasecmp("FILTER",str.s) ) { - if ( replace==REPLACE_EXISTING ) error("Apologies, the -FILTER feature has not been implemented yet.\n"); + if ( replace==REPLACE_NON_MISSING ) error("Apologies, the -FILTER feature has not been implemented yet.\n"); args->ncols++; args->cols = (annot_col_t*) realloc(args->cols,sizeof(annot_col_t)*args->ncols); annot_col_t *col = &args->cols[args->ncols-1]; col->icol = icol; col->replace = replace; col->setter = args->tgts_is_vcf ? vcf_setter_filter : setter_filter; - col->hdr_key = strdup(str.s); + col->hdr_key_src = strdup(str.s); + col->hdr_key_dst = strdup(str.s); if ( args->tgts_is_vcf ) { bcf_hdr_t *tgts_hdr = args->files->readers[1].header; @@ -1314,18 +1383,19 @@ static void init_columns(args_t *args) } else if ( !strcasecmp("QUAL",str.s) ) { - if ( replace==REPLACE_EXISTING ) error("Apologies, the -QUAL feature has not been implemented yet.\n"); + if ( replace==REPLACE_NON_MISSING ) error("Apologies, the -QUAL feature has not been implemented yet.\n"); if ( replace==SET_OR_APPEND ) error("Apologies, the =QUAL feature has not been implemented yet.\n"); args->ncols++; args->cols = (annot_col_t*) realloc(args->cols,sizeof(annot_col_t)*args->ncols); annot_col_t *col = &args->cols[args->ncols-1]; col->icol = icol; col->replace = replace; col->setter = args->tgts_is_vcf ? vcf_setter_qual : setter_qual; - col->hdr_key = strdup(str.s); + col->hdr_key_src = strdup(str.s); + col->hdr_key_dst = strdup(str.s); } else if ( args->tgts_is_vcf && !strcasecmp("INFO",str.s) ) // All INFO fields { - if ( replace==REPLACE_EXISTING ) error("Apologies, the -INFO/TAG feature has not been implemented yet.\n"); + if ( replace==REPLACE_NON_MISSING ) error("Apologies, the -INFO/TAG feature has not been implemented yet.\n"); if ( replace==SET_OR_APPEND ) error("Apologies, the =INFO/TAG feature has not been implemented yet.\n"); bcf_hdr_t *tgts_hdr = args->files->readers[1].header; int j; @@ -1345,7 +1415,8 @@ static void init_columns(args_t *args) annot_col_t *col = &args->cols[args->ncols-1]; col->icol = -1; col->replace = replace; - col->hdr_key = strdup(hrec->vals[k]); + col->hdr_key_src = strdup(hrec->vals[k]); + col->hdr_key_dst = strdup(hrec->vals[k]); col->number = bcf_hdr_id2length(args->hdr_out,BCF_HL_INFO,hdr_id); switch ( bcf_hdr_id2type(args->hdr_out,BCF_HL_INFO,hdr_id) ) { @@ -1360,8 +1431,7 @@ static void init_columns(args_t *args) else if ( args->tgts_is_vcf && (!strcasecmp("FORMAT",str.s) || !strcasecmp("FMT",str.s)) ) // All FORMAT fields { bcf_hdr_t *tgts_hdr = args->files->readers[1].header; - if ( force_samples<0 ) force_samples = replace; - if ( force_samples>=0 && replace!=REPLACE_ALL ) force_samples = replace; + need_sample_map = 1; int j; for (j=0; jnhrec; j++) { @@ -1379,8 +1449,9 @@ static void init_columns(args_t *args) annot_col_t *col = &args->cols[args->ncols-1]; col->icol = -1; col->replace = replace; - col->hdr_key = strdup(hrec->vals[k]); - if ( !strcasecmp("GT",col->hdr_key) ) col->setter = vcf_setter_format_gt; + col->hdr_key_src = strdup(hrec->vals[k]); + col->hdr_key_dst = strdup(hrec->vals[k]); + if ( !strcasecmp("GT",col->hdr_key_src) ) col->setter = vcf_setter_format_gt; else switch ( bcf_hdr_id2type(args->hdr_out,BCF_HL_FMT,hdr_id) ) { @@ -1393,18 +1464,27 @@ static void init_columns(args_t *args) } else if ( !strncasecmp("FORMAT/",str.s, 7) || !strncasecmp("FMT/",str.s,4) ) { - char *key = str.s + (!strncasecmp("FMT/",str.s,4) ? 4 : 7); - if ( force_samples<0 ) force_samples = replace; - if ( force_samples>=0 && replace!=REPLACE_ALL ) force_samples = replace; + char *key_dst = str.s + (!strncasecmp("FMT/",str.s,4) ? 4 : 7); + char *key_src = strstr(key_dst,":="); + if ( key_src ) + { + *key_src = 0; + key_src += 2; + if ( !strncasecmp("FORMAT/",key_src,7) ) key_src += 7; + else if ( !strncasecmp("FMT/",key_src,4) ) key_src += 4; + } + else + key_src = key_dst; + need_sample_map = 1; if ( args->tgts_is_vcf ) { - bcf_hrec_t *hrec = bcf_hdr_get_hrec(args->files->readers[1].header, BCF_HL_FMT, "ID", key, NULL); + bcf_hrec_t *hrec = bcf_hdr_get_hrec(args->files->readers[1].header, BCF_HL_FMT, "ID", key_src, NULL); tmp.l = 0; - bcf_hrec_format(hrec, &tmp); + bcf_hrec_format_rename(hrec, key_dst, &tmp); bcf_hdr_append(args->hdr_out, tmp.s); bcf_hdr_sync(args->hdr_out); } - int hdr_id = bcf_hdr_id2int(args->hdr_out, BCF_DT_ID, key); + int hdr_id = bcf_hdr_id2int(args->hdr_out, BCF_DT_ID, key_dst); if ( !bcf_hdr_idinfo_exists(args->hdr_out,BCF_HL_FMT,hdr_id) ) error("The tag \"%s\" is not defined in %s\n", str.s, args->targets_fname); args->ncols++; args->cols = (annot_col_t*) realloc(args->cols,sizeof(annot_col_t)*args->ncols); @@ -1412,13 +1492,14 @@ static void init_columns(args_t *args) if ( !args->tgts_is_vcf ) { col->icol = icol; - icol += bcf_hdr_nsamples(args->hdr_out) - 1; + icol += args->nsmpl_annot - 1; } else col->icol = -1; col->replace = replace; - col->hdr_key = strdup(key); - if ( !strcasecmp("GT",key) ) col->setter = vcf_setter_format_gt; + col->hdr_key_src = strdup(key_src); + col->hdr_key_dst = strdup(key_dst); + if ( !strcasecmp("GT",key_src) ) col->setter = vcf_setter_format_gt; else switch ( bcf_hdr_id2type(args->hdr_out,BCF_HL_FMT,hdr_id) ) { @@ -1430,24 +1511,33 @@ static void init_columns(args_t *args) } else { - if ( replace==REPLACE_EXISTING ) error("Apologies, the -INFO/TAG feature has not been implemented yet.\n"); + if ( replace==REPLACE_NON_MISSING ) error("Apologies, the -INFO/TAG feature has not been implemented yet.\n"); if ( replace==SET_OR_APPEND ) error("Apologies, the =INFO/TAG feature has not been implemented yet.\n"); - if ( !strncasecmp("INFO/",str.s,5) ) { memmove(str.s,str.s+5,str.l-4); } - int hdr_id = bcf_hdr_id2int(args->hdr_out, BCF_DT_ID, str.s); + char *key_dst = !strncasecmp("INFO/",str.s,5) ? str.s + 5 : str.s; + char *key_src = strstr(key_dst,":="); + if ( key_src ) + { + *key_src = 0; + key_src += 2; + if ( !strncasecmp("INFO/",key_src,5) ) key_src += 5; + } + else + key_src = key_dst; + int hdr_id = bcf_hdr_id2int(args->hdr_out, BCF_DT_ID, key_dst); if ( !bcf_hdr_idinfo_exists(args->hdr_out,BCF_HL_INFO,hdr_id) ) { if ( args->tgts_is_vcf ) // reading annotations from a VCF, add a new header line { - bcf_hrec_t *hrec = bcf_hdr_get_hrec(args->files->readers[1].header, BCF_HL_INFO, "ID", str.s, NULL); + bcf_hrec_t *hrec = bcf_hdr_get_hrec(args->files->readers[1].header, BCF_HL_INFO, "ID", key_src, NULL); if ( !hrec ) error("The tag \"%s\" is not defined in %s\n", str.s,args->files->readers[1].fname); tmp.l = 0; - bcf_hrec_format(hrec, &tmp); + bcf_hrec_format_rename(hrec, key_dst, &tmp); bcf_hdr_append(args->hdr_out, tmp.s); bcf_hdr_sync(args->hdr_out); - hdr_id = bcf_hdr_id2int(args->hdr_out, BCF_DT_ID, str.s); + hdr_id = bcf_hdr_id2int(args->hdr_out, BCF_DT_ID, key_dst); } else - error("The tag \"%s\" is not defined in %s\n", str.s, args->targets_fname); + error("The tag \"%s\" is not defined in %s\n", key_src, args->targets_fname); assert( bcf_hdr_idinfo_exists(args->hdr_out,BCF_HL_INFO,hdr_id) ); } @@ -1455,7 +1545,8 @@ static void init_columns(args_t *args) annot_col_t *col = &args->cols[args->ncols-1]; col->icol = icol; col->replace = replace; - col->hdr_key = strdup(str.s); + col->hdr_key_src = strdup(key_src); + col->hdr_key_dst = strdup(key_dst); col->number = bcf_hdr_id2length(args->hdr_out,BCF_HL_INFO,hdr_id); switch ( bcf_hdr_id2type(args->hdr_out,BCF_HL_INFO,hdr_id) ) { @@ -1482,8 +1573,13 @@ static void init_columns(args_t *args) args->tmpp = (char**)malloc(sizeof(char*)*n); args->tmpp2 = (char**)malloc(sizeof(char*)*n); } - if ( force_samples>=0 && args->tgts_is_vcf ) - set_samples(args, args->files->readers[1].header, args->hdr, force_samples==REPLACE_ALL ? 0 : 1); + if ( !need_sample_map ) + { + free(args->sample_map); + args->sample_map = NULL; + } + else if ( sample_map_ok<0 ) + error("No matching samples in source and destination file?\n"); } static void rename_chrs(args_t *args, char *fname) @@ -1554,7 +1650,6 @@ static void init_data(args_t *args) if ( args->mark_sites ) { if ( !args->targets_fname ) error("The -a option not given\n"); - if ( args->tgts_is_vcf ) error("Apologies, this has not been implemented yet: -a is a VCF\n"); // very easy to add.. bcf_hdr_printf(args->hdr_out,"##INFO=", args->mark_sites,args->mark_sites_logic==MARK_LISTED?"":"not ",args->mark_sites); } @@ -1566,7 +1661,8 @@ static void init_data(args_t *args) args->out_fh = hts_open(args->output_fname,hts_bcf_wmode(args->output_type)); if ( args->out_fh == NULL ) error("Can't write to \"%s\": %s\n", args->output_fname, strerror(errno)); - if ( args->n_threads ) hts_set_threads(args->out_fh, args->n_threads); + if ( args->n_threads ) + hts_set_opt(args->out_fh, HTS_OPT_THREAD_POOL, args->files->p); bcf_hdr_write(args->out_fh, args->hdr_out); } } @@ -1579,7 +1675,10 @@ static void destroy_data(args_t *args) if ( args->hdr_out ) bcf_hdr_destroy(args->hdr_out); if (args->vcmp) vcmp_destroy(args->vcmp); for (i=0; incols; i++) - free(args->cols[i].hdr_key); + { + free(args->cols[i].hdr_key_src); + free(args->cols[i].hdr_key_dst); + } free(args->cols); for (i=0; imalines; i++) { @@ -1720,7 +1819,7 @@ static void annotate(args_t *args, bcf1_t *line) // there is a matching line for (j=0; jncols; j++) if ( args->cols[j].setter(args,line,&args->cols[j],&args->alines[i]) ) - error("fixme: Could not set %s at %s:%d\n", args->cols[j].hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + error("fixme: Could not set %s at %s:%d\n", args->cols[j].hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); } @@ -1733,12 +1832,20 @@ static void annotate(args_t *args, bcf1_t *line) bcf_update_info_flag(args->hdr_out,line,args->mark_sites,NULL,inalines?0:1); } } - else if ( args->files->nreaders == 2 && bcf_sr_has_line(args->files,1) ) + else if ( args->files->nreaders == 2 ) { - bcf1_t *aline = bcf_sr_get_line(args->files,1); - for (j=0; jncols; j++) - if ( args->cols[j].setter(args,line,&args->cols[j],aline) ) - error("fixme: Could not set %s at %s:%d\n", args->cols[j].hdr_key,bcf_seqname(args->hdr,line),line->pos+1); + if ( bcf_sr_has_line(args->files,1) ) + { + bcf1_t *aline = bcf_sr_get_line(args->files,1); + for (j=0; jncols; j++) + if ( args->cols[j].setter(args,line,&args->cols[j],aline) ) + error("fixme: Could not set %s at %s:%d\n", args->cols[j].hdr_key_src,bcf_seqname(args->hdr,line),line->pos+1); + + if ( args->mark_sites ) + bcf_update_info_flag(args->hdr_out,line,args->mark_sites,NULL,args->mark_sites_logic==MARK_LISTED ? 1 : 0); + } + else if ( args->mark_sites ) + bcf_update_info_flag(args->hdr_out,line,args->mark_sites,NULL, args->mark_sites_logic==MARK_UNLISTED ? 1 : 0); } if ( args->set_ids ) { @@ -1757,29 +1864,31 @@ static void annotate(args_t *args, bcf1_t *line) static void usage(args_t *args) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Annotate and edit VCF/BCF files.\n"); - fprintf(pysam_stderr, "Usage: bcftools annotate [options] \n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Options:\n"); - fprintf(pysam_stderr, " -a, --annotations VCF file or tabix-indexed file with annotations: CHR\\tPOS[\\tVALUE]+\n"); - fprintf(pysam_stderr, " -c, --columns list of columns in the annotation file, e.g. CHROM,POS,REF,ALT,-,INFO/TAG. See man page for details\n"); - fprintf(pysam_stderr, " -e, --exclude exclude sites for which the expression is true (see man page for details)\n"); - fprintf(pysam_stderr, " -h, --header-lines lines which should be appended to the VCF header\n"); - fprintf(pysam_stderr, " -I, --set-id [+] set ID column, see man page for details\n"); - fprintf(pysam_stderr, " -i, --include select sites for which the expression is true (see man page for details)\n"); - fprintf(pysam_stderr, " -m, --mark-sites [+-] add INFO/tag flag to sites which are (\"+\") or are not (\"-\") listed in the -a file\n"); - fprintf(pysam_stderr, " --no-version do not append version and command line to the header\n"); - fprintf(pysam_stderr, " -o, --output write output to a file [standard output]\n"); - fprintf(pysam_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " --rename-chrs rename sequences according to map file: from\\tto\n"); - fprintf(pysam_stderr, " -s, --samples [^] comma separated list of samples to annotate (or exclude with \"^\" prefix)\n"); - fprintf(pysam_stderr, " -S, --samples-file [^] file of samples to annotate (or exclude with \"^\" prefix)\n"); - fprintf(pysam_stderr, " -x, --remove list of annotations to remove (e.g. ID,INFO/DP,FORMAT/DP,FILTER). See man page for details\n"); - fprintf(pysam_stderr, " --threads number of extra output compression threads [0]\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Annotate and edit VCF/BCF files.\n"); + fprintf(bcftools_stderr, "Usage: bcftools annotate [options] \n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Options:\n"); + fprintf(bcftools_stderr, " -a, --annotations VCF file or tabix-indexed file with annotations: CHR\\tPOS[\\tVALUE]+\n"); + fprintf(bcftools_stderr, " --collapse matching records by , see man page for details [some]\n"); + fprintf(bcftools_stderr, " -c, --columns list of columns in the annotation file, e.g. CHROM,POS,REF,ALT,-,INFO/TAG. See man page for details\n"); + fprintf(bcftools_stderr, " -e, --exclude exclude sites for which the expression is true (see man page for details)\n"); + fprintf(bcftools_stderr, " -h, --header-lines lines which should be appended to the VCF header\n"); + fprintf(bcftools_stderr, " -I, --set-id [+] set ID column, see man page for details\n"); + fprintf(bcftools_stderr, " -i, --include select sites for which the expression is true (see man page for details)\n"); + fprintf(bcftools_stderr, " -k, --keep-sites leave -i/-e sites unchanged instead of discarding them\n"); + fprintf(bcftools_stderr, " -m, --mark-sites [+-] add INFO/tag flag to sites which are (\"+\") or are not (\"-\") listed in the -a file\n"); + fprintf(bcftools_stderr, " --no-version do not append version and command line to the header\n"); + fprintf(bcftools_stderr, " -o, --output write output to a file [standard output]\n"); + fprintf(bcftools_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " --rename-chrs rename sequences according to map file: from\\tto\n"); + fprintf(bcftools_stderr, " -s, --samples [^] comma separated list of samples to annotate (or exclude with \"^\" prefix)\n"); + fprintf(bcftools_stderr, " -S, --samples-file [^] file of samples to annotate (or exclude with \"^\" prefix)\n"); + fprintf(bcftools_stderr, " -x, --remove list of annotations (e.g. ID,INFO/DP,FORMAT/DP,FILTER) to remove (or keep with \"^\" prefix). See man page for details\n"); + fprintf(bcftools_stderr, " --threads number of extra output compression threads [0]\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } @@ -1795,16 +1904,18 @@ int main_vcfannotate(int argc, char *argv[]) args->record_cmd_line = 1; args->ref_idx = args->alt_idx = args->chr_idx = args->from_idx = args->to_idx = -1; args->set_ids_replace = 1; - int regions_is_file = 0; + int regions_is_file = 0, collapse = 0; static struct option loptions[] = { + {"keep-sites",required_argument,NULL,'k'}, {"mark-sites",required_argument,NULL,'m'}, {"set-id",required_argument,NULL,'I'}, {"output",required_argument,NULL,'o'}, {"output-type",required_argument,NULL,'O'}, {"threads",required_argument,NULL,9}, {"annotations",required_argument,NULL,'a'}, + {"collapse",required_argument,NULL,2}, {"include",required_argument,NULL,'i'}, {"exclude",required_argument,NULL,'e'}, {"regions",required_argument,NULL,'r'}, @@ -1818,9 +1929,10 @@ int main_vcfannotate(int argc, char *argv[]) {"no-version",no_argument,NULL,8}, {NULL,0,NULL,0} }; - while ((c = getopt_long(argc, argv, "h:?o:O:r:R:a:x:c:i:e:S:s:I:m:",loptions,NULL)) >= 0) + while ((c = getopt_long(argc, argv, "h:?o:O:r:R:a:x:c:i:e:S:s:I:m:k",loptions,NULL)) >= 0) { switch (c) { + case 'k': args->keep_sites = 1; break; case 'm': args->mark_sites_logic = MARK_LISTED; if ( optarg[0]=='+' ) args->mark_sites = optarg+1; @@ -1849,6 +1961,16 @@ int main_vcfannotate(int argc, char *argv[]) case 'R': args->regions_list = optarg; regions_is_file = 1; break; case 'h': args->header_fname = optarg; break; case 1 : args->rename_chrs = optarg; break; + case 2 : + if ( !strcmp(optarg,"snps") ) collapse |= COLLAPSE_SNPS; + else if ( !strcmp(optarg,"indels") ) collapse |= COLLAPSE_INDELS; + else if ( !strcmp(optarg,"both") ) collapse |= COLLAPSE_SNPS | COLLAPSE_INDELS; + else if ( !strcmp(optarg,"any") ) collapse |= COLLAPSE_ANY; + else if ( !strcmp(optarg,"all") ) collapse |= COLLAPSE_ANY; + else if ( !strcmp(optarg,"some") ) collapse |= COLLAPSE_SOME; + else if ( !strcmp(optarg,"none") ) collapse = COLLAPSE_NONE; + else error("The --collapse string \"%s\" not recognised.\n", optarg); + break; case 9 : args->n_threads = strtol(optarg, 0, 0); break; case 8 : args->record_cmd_line = 0; break; case '?': usage(args); break; @@ -1879,9 +2001,10 @@ int main_vcfannotate(int argc, char *argv[]) { args->tgts_is_vcf = 1; args->files->require_index = 1; - args->files->collapse |= COLLAPSE_SOME; + args->files->collapse = collapse ? collapse : COLLAPSE_SOME; } } + if ( bcf_sr_set_threads(args->files, args->n_threads)<0 ) error("Failed to create threads\n"); if ( !bcf_sr_add_reader(args->files, fname) ) error("Failed to open %s: %s\n", fname,bcf_sr_strerror(args->files->errnum)); init_data(args); @@ -1894,7 +2017,11 @@ int main_vcfannotate(int argc, char *argv[]) { int pass = filter_test(args->filter, line, NULL); if ( args->filter_logic & FLT_EXCLUDE ) pass = pass ? 0 : 1; - if ( !pass ) continue; + if ( !pass ) + { + if ( args->keep_sites ) bcf_write1(args->out_fh, args->hdr_out, line); + continue; + } } annotate(args, line); bcf_write1(args->out_fh, args->hdr_out, line); diff --git a/bcftools/vcfbuf.c b/bcftools/vcfbuf.c new file mode 100644 index 000000000..d896d3adf --- /dev/null +++ b/bcftools/vcfbuf.c @@ -0,0 +1,442 @@ +/* The MIT License + + Copyright (c) 2016 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#include +#include +#include "bcftools.h" +#include "vcfbuf.h" +#include "rbuf.h" + +typedef struct +{ + double max; + int rand_missing, skip_filter; +} +ld_t; + +typedef struct +{ + bcf1_t *rec; + double af; + int af_set:1, idx:31; +} +vcfrec_t; + +typedef struct +{ + int max_sites, mvrec, mac, mfarr; + int *ac, *idx; + float *farr; + char *af_tag; + vcfrec_t **vrec; +} +prune_t; + +typedef struct +{ + int active, rid, end; +} +overlap_t; + +struct _vcfbuf_t +{ + int win; + bcf_hdr_t *hdr; + vcfrec_t *vcf; + rbuf_t rbuf; + ld_t ld; + prune_t prune; + overlap_t overlap; +}; + +vcfbuf_t *vcfbuf_init(bcf_hdr_t *hdr, int win) +{ + vcfbuf_t *buf = (vcfbuf_t*) calloc(1,sizeof(vcfbuf_t)); + buf->hdr = hdr; + buf->win = win; + buf->overlap.rid = -1; + rbuf_init(&buf->rbuf, 0); + return buf; +} + +void vcfbuf_destroy(vcfbuf_t *buf) +{ + int i; + for (i=0; irbuf.m; i++) + if ( buf->vcf[i].rec ) bcf_destroy(buf->vcf[i].rec); + free(buf->vcf); + free(buf->prune.farr); + free(buf->prune.vrec); + free(buf->prune.ac); + free(buf->prune.idx); + free(buf); +} + +void vcfbuf_set(vcfbuf_t *buf, vcfbuf_opt_t key, void *value) +{ + if ( key==VCFBUF_LD_MAX ) { buf->ld.max = *((double*)value); return; } + if ( key==VCFBUF_RAND_MISSING ) { buf->ld.rand_missing = *((int*)value); return; } + if ( key==VCFBUF_SKIP_FILTER ) { buf->ld.skip_filter = *((int*)value); return; } + if ( key==VCFBUF_NSITES ) { buf->prune.max_sites = *((int*)value); return; } + if ( key==VCFBUF_AF_TAG ) { buf->prune.af_tag = *((char**)value); return; } + if ( key==VCFBUF_OVERLAP_WIN ) { buf->overlap.active = *((int*)value); return; } +} + +int vcfbuf_nsites(vcfbuf_t *buf) +{ + return buf->rbuf.n; +} + +bcf1_t *vcfbuf_push(vcfbuf_t *buf, bcf1_t *rec, int swap) +{ + if ( !swap ) error("todo: swap=%d\n", swap); + + rbuf_expand0(&buf->rbuf, vcfrec_t, buf->rbuf.n+1, buf->vcf); + + int i = rbuf_append(&buf->rbuf); + if ( !buf->vcf[i].rec ) buf->vcf[i].rec = bcf_init1(); + + bcf1_t *ret = buf->vcf[i].rec; + buf->vcf[i].rec = rec; + buf->vcf[i].af_set = 0; + + return ret; +} + +static int cmpvrec(const void *_a, const void *_b) +{ + vcfrec_t *a = *((vcfrec_t**) _a); + vcfrec_t *b = *((vcfrec_t**) _b); + if ( a->af < b->af ) return -1; + if ( a->af == b->af ) return 0; + return 1; +} +static int cmpint_desc(const void *_a, const void *_b) +{ + int a = *((int*)_a); + int b = *((int*)_b); + if ( a < b ) return 1; + if ( a == b ) return 0; + return -1; +} + +static void _prune_sites(vcfbuf_t *buf, int flush_all) +{ + int nbuf = flush_all ? buf->rbuf.n : buf->rbuf.n - 1; + + if ( nbuf > buf->prune.mvrec ) + { + buf->prune.idx = (int*) realloc(buf->prune.idx, nbuf*sizeof(int)); + buf->prune.vrec = (vcfrec_t**) realloc(buf->prune.vrec, nbuf*sizeof(vcfrec_t*)); + buf->prune.mvrec = nbuf; + } + + // set allele frequency and prepare buffer for sorting + int i,k,irec = 0; + for (i=-1; rbuf_next(&buf->rbuf,&i) && irecvcf[i].rec; + if ( line->n_allele > buf->prune.mac ) + { + buf->prune.ac = (int*) realloc(buf->prune.ac, line->n_allele*sizeof(*buf->prune.ac)); + buf->prune.mac = line->n_allele; + } + if ( !buf->vcf[i].af_set ) + { + buf->vcf[i].af = 0; + if ( buf->prune.af_tag ) + { + if ( bcf_get_info_float(buf->hdr,line,buf->prune.af_tag,&buf->prune.farr, &buf->prune.mfarr) > 0 ) buf->vcf[i].af = buf->prune.farr[0]; + } + else if ( bcf_calc_ac(buf->hdr, line, buf->prune.ac, BCF_UN_INFO|BCF_UN_FMT) ) + { + int ntot = buf->prune.ac[0], nalt = 0; + for (k=1; kn_allele; k++) nalt += buf->prune.ac[k]; + buf->vcf[i].af = ntot ? (float)nalt/ntot : 0; + } + buf->vcf[i].af_set = 1; + } + buf->vcf[i].idx = irec; + buf->prune.vrec[irec++] = &buf->vcf[i]; + } + + // sort by allele frequency, low AF will be removed preferentially + qsort(buf->prune.vrec, nbuf, sizeof(*buf->prune.vrec), cmpvrec); + + // sort the rbuf indexes to be pruned descendently so that j-th rbuf index + // is removed before i-th index if iprune.max_sites; + for (i=0; iprune.idx[i] = buf->prune.vrec[i]->idx; + + qsort(buf->prune.idx, nprune, sizeof(int), cmpint_desc); + + for (i=0; irbuf, vcfrec_t, buf->prune.idx[i], buf->vcf); +} + +static int _overlap_can_flush(vcfbuf_t *buf, int flush_all) +{ + if ( flush_all ) { buf->overlap.rid = -1; return 1; } + + int i = rbuf_last(&buf->rbuf); + vcfrec_t *last = &buf->vcf[i]; + if ( buf->overlap.rid != last->rec->rid ) buf->overlap.end = 0; + + int beg_pos = last->rec->pos; + int end_pos = last->rec->pos + last->rec->rlen - 1; + + // Assuming left-aligned indels. In case it is a deletion, the real variant + // starts one base after. If an insertion, the overlap with previous zero length. + int imin = last->rec->rlen; + for (i=0; irec->n_allele; i++) + { + char *ref = last->rec->d.allele[0]; + char *alt = last->rec->d.allele[i]; + if ( *alt == '<' ) continue; // ignore symbolic alleles + while ( *ref && *alt && nt_to_upper(*ref)==nt_to_upper(*alt) ) { ref++; alt++; } + if ( imin > ref - last->rec->d.allele[0] ) imin = ref - last->rec->d.allele[0]; + } + + if ( beg_pos <= buf->overlap.end ) + { + beg_pos += imin; + if ( beg_pos > end_pos ) end_pos = beg_pos; + } + + if ( buf->rbuf.n==1 ) + { + buf->overlap.rid = last->rec->rid; + buf->overlap.end = end_pos; + return 0; + } + if ( beg_pos <= buf->overlap.end ) + { + if ( buf->overlap.end < end_pos ) buf->overlap.end = end_pos; + return 0; + } + return 1; +} + +bcf1_t *vcfbuf_flush(vcfbuf_t *buf, int flush_all) +{ + int i,j; + + if ( buf->rbuf.n==0 ) return NULL; + if ( flush_all ) goto ret; + + i = rbuf_kth(&buf->rbuf, 0); // first + j = rbuf_last(&buf->rbuf); // last + + if ( buf->vcf[i].rec->rid != buf->vcf[j].rec->rid ) goto ret; + if ( buf->overlap.active ) + { + int ret = _overlap_can_flush(buf, flush_all); + //printf("can_flush: %d %d - %d\n", ret, buf->vcf[i].rec->pos+1, buf->vcf[j].rec->pos+1); + if ( ret ) goto ret; + } + //if ( buf->overlap.active && _overlap_can_flush(buf, flush_all) ) goto ret; + + if ( buf->win > 0 ) + { + if ( buf->rbuf.n <= buf->win ) return NULL; + goto ret; + } + else if ( buf->win < 0 ) + { + if ( buf->vcf[i].rec->pos - buf->vcf[j].rec->pos > buf->win ) return NULL; + } + else return NULL; + +ret: + if ( buf->prune.max_sites && buf->prune.max_sites < buf->rbuf.n ) _prune_sites(buf, flush_all); + + i = rbuf_shift(&buf->rbuf); + return buf->vcf[i].rec; +} + +static double _estimate_af(int8_t *ptr, int size, int nvals, int nsamples) +{ + int i,j, nref = 0, nalt = 0; + for (i=0; in_sample!=brec->n_sample ) error("Different number of samples: %d vs %d\n",arec->n_sample,brec->n_sample); + assert( arec->n_sample ); + + int i,j,igt = bcf_hdr_id2int(buf->hdr, BCF_DT_ID, "GT"); + bcf_unpack(arec, BCF_UN_FMT); + bcf_unpack(brec, BCF_UN_FMT); + bcf_fmt_t *afmt = NULL, *bfmt = NULL; + for (i=0; in_fmt; i++) + if ( arec->d.fmt[i].id==igt ) { afmt = &arec->d.fmt[i]; break; } + if ( !afmt ) return -1; // no GT tag + for (i=0; in_fmt; i++) + if ( brec->d.fmt[i].id==igt ) { bfmt = &brec->d.fmt[i]; break; } + if ( !bfmt ) return -1; // no GT tag + + if ( afmt->n==0 ) return -1; // empty?! + if ( bfmt->n==0 ) return -1; // empty?! + if ( afmt->type!=BCF_BT_INT8 ) error("TODO: the GT fmt_type is not int8!\n"); + if ( bfmt->type!=BCF_BT_INT8 ) error("TODO: the GT fmt_type is not int8!\n"); + + // Determine allele frequencies, this is to sample randomly missing genotypes + double aaf = 0, baf = 0; + if ( buf->ld.rand_missing ) + { + aaf = _estimate_af((int8_t*)afmt->p, afmt->size, afmt->n, arec->n_sample); + baf = _estimate_af((int8_t*)bfmt->p, bfmt->size, bfmt->n, brec->n_sample); + } + + // Calculate correlation + double ab = 0, aa = 0, bb = 0, a = 0, b = 0; + int nab = 0, na = 0, nb = 0, ndiff = 0; + for (i=0; in_sample; i++) + { + int8_t *aptr = (int8_t*) (afmt->p + i*afmt->size); + int8_t *bptr = (int8_t*) (bfmt->p + i*bfmt->size); + int adsg = 0, bdsg = 0, an = 0, bn = 0; + for (j=0; jn; j++) + { + if ( aptr[j]==bcf_int8_vector_end ) break; + if ( aptr[j]==bcf_gt_missing ) + { + if ( !buf->ld.rand_missing ) break; + if ( rand()/RAND_MAX >= aaf ) adsg += 1; + } + else if ( bcf_gt_allele(aptr[j]) ) adsg += 1; + an++; + } + for (j=0; jn; j++) + { + if ( bptr[j]==bcf_int8_vector_end ) break; + if ( bptr[j]==bcf_gt_missing ) + { + if ( !buf->ld.rand_missing ) break; + if ( rand()/RAND_MAX >= baf ) bdsg += 1; + } + else if ( bcf_gt_allele(bptr[j]) ) bdsg += 1; + bn++; + } + if ( an ) + { + aa += adsg*adsg; + a += adsg; + na++; + } + if ( bn ) + { + bb += bdsg*bdsg; + b += bdsg; + nb++; + } + if ( an && bn ) + { + if ( adsg!=bdsg ) ndiff++; + ab += adsg*bdsg; + nab++; + } + } + if ( !nab ) return -1; + + double cor; + if ( !ndiff ) cor = 1; + else + { + // Don't know how to deal with zero variance. Since this the purpose is filtering, + // it is not enough to say the value is undefined. Therefore an artificial noise is + // added to make the denominator non-zero. + if ( aa == a*a/na || bb == b*b/nb ) + { + aa += 3*3; + bb += 3*3; + ab += 3*3; + a += 3; + b += 3; + na++; + nb++; + nab++; + } + cor = (ab/nab - a/na*b/nb) / sqrt(aa/na - a/na*a/na) / sqrt(bb/nb - b/nb*b/nb); + } + return cor*cor; +} + +bcf1_t *vcfbuf_max_ld(vcfbuf_t *buf, bcf1_t *rec, double *ld) +{ + *ld = -1; + if ( !buf->rbuf.n ) return NULL; + + int i = buf->rbuf.f; + + // Relying on vcfbuf being properly flushed - all sites in the buffer + // must come from the same chromosome + if ( buf->vcf[i].rec->rid != rec->rid ) return NULL; + + int imax = 0; + double max = 0; + for (i=-1; rbuf_next(&buf->rbuf,&i); ) + { + if ( buf->ld.skip_filter ) + { + if ( buf->vcf[i].rec->d.n_flt > 1 ) continue; // multiple filters are set + if ( buf->vcf[i].rec->d.n_flt==1 && buf->vcf[i].rec->d.flt[0]!=0 ) continue; // not PASS + } + double val = _calc_ld(buf, buf->vcf[i].rec, rec); + if ( buf->ld.max && buf->ld.max < val ) + { + *ld = val; + return buf->vcf[i].rec; + } + if ( val > max ) + { + max = val; + imax = i; + } + } + *ld = max; + return buf->vcf[imax].rec; +} + + diff --git a/bcftools/vcfbuf.c.pysam.c b/bcftools/vcfbuf.c.pysam.c new file mode 100644 index 000000000..85a207487 --- /dev/null +++ b/bcftools/vcfbuf.c.pysam.c @@ -0,0 +1,444 @@ +#include "bcftools.pysam.h" + +/* The MIT License + + Copyright (c) 2016 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#include +#include +#include "bcftools.h" +#include "vcfbuf.h" +#include "rbuf.h" + +typedef struct +{ + double max; + int rand_missing, skip_filter; +} +ld_t; + +typedef struct +{ + bcf1_t *rec; + double af; + int af_set:1, idx:31; +} +vcfrec_t; + +typedef struct +{ + int max_sites, mvrec, mac, mfarr; + int *ac, *idx; + float *farr; + char *af_tag; + vcfrec_t **vrec; +} +prune_t; + +typedef struct +{ + int active, rid, end; +} +overlap_t; + +struct _vcfbuf_t +{ + int win; + bcf_hdr_t *hdr; + vcfrec_t *vcf; + rbuf_t rbuf; + ld_t ld; + prune_t prune; + overlap_t overlap; +}; + +vcfbuf_t *vcfbuf_init(bcf_hdr_t *hdr, int win) +{ + vcfbuf_t *buf = (vcfbuf_t*) calloc(1,sizeof(vcfbuf_t)); + buf->hdr = hdr; + buf->win = win; + buf->overlap.rid = -1; + rbuf_init(&buf->rbuf, 0); + return buf; +} + +void vcfbuf_destroy(vcfbuf_t *buf) +{ + int i; + for (i=0; irbuf.m; i++) + if ( buf->vcf[i].rec ) bcf_destroy(buf->vcf[i].rec); + free(buf->vcf); + free(buf->prune.farr); + free(buf->prune.vrec); + free(buf->prune.ac); + free(buf->prune.idx); + free(buf); +} + +void vcfbuf_set(vcfbuf_t *buf, vcfbuf_opt_t key, void *value) +{ + if ( key==VCFBUF_LD_MAX ) { buf->ld.max = *((double*)value); return; } + if ( key==VCFBUF_RAND_MISSING ) { buf->ld.rand_missing = *((int*)value); return; } + if ( key==VCFBUF_SKIP_FILTER ) { buf->ld.skip_filter = *((int*)value); return; } + if ( key==VCFBUF_NSITES ) { buf->prune.max_sites = *((int*)value); return; } + if ( key==VCFBUF_AF_TAG ) { buf->prune.af_tag = *((char**)value); return; } + if ( key==VCFBUF_OVERLAP_WIN ) { buf->overlap.active = *((int*)value); return; } +} + +int vcfbuf_nsites(vcfbuf_t *buf) +{ + return buf->rbuf.n; +} + +bcf1_t *vcfbuf_push(vcfbuf_t *buf, bcf1_t *rec, int swap) +{ + if ( !swap ) error("todo: swap=%d\n", swap); + + rbuf_expand0(&buf->rbuf, vcfrec_t, buf->rbuf.n+1, buf->vcf); + + int i = rbuf_append(&buf->rbuf); + if ( !buf->vcf[i].rec ) buf->vcf[i].rec = bcf_init1(); + + bcf1_t *ret = buf->vcf[i].rec; + buf->vcf[i].rec = rec; + buf->vcf[i].af_set = 0; + + return ret; +} + +static int cmpvrec(const void *_a, const void *_b) +{ + vcfrec_t *a = *((vcfrec_t**) _a); + vcfrec_t *b = *((vcfrec_t**) _b); + if ( a->af < b->af ) return -1; + if ( a->af == b->af ) return 0; + return 1; +} +static int cmpint_desc(const void *_a, const void *_b) +{ + int a = *((int*)_a); + int b = *((int*)_b); + if ( a < b ) return 1; + if ( a == b ) return 0; + return -1; +} + +static void _prune_sites(vcfbuf_t *buf, int flush_all) +{ + int nbuf = flush_all ? buf->rbuf.n : buf->rbuf.n - 1; + + if ( nbuf > buf->prune.mvrec ) + { + buf->prune.idx = (int*) realloc(buf->prune.idx, nbuf*sizeof(int)); + buf->prune.vrec = (vcfrec_t**) realloc(buf->prune.vrec, nbuf*sizeof(vcfrec_t*)); + buf->prune.mvrec = nbuf; + } + + // set allele frequency and prepare buffer for sorting + int i,k,irec = 0; + for (i=-1; rbuf_next(&buf->rbuf,&i) && irecvcf[i].rec; + if ( line->n_allele > buf->prune.mac ) + { + buf->prune.ac = (int*) realloc(buf->prune.ac, line->n_allele*sizeof(*buf->prune.ac)); + buf->prune.mac = line->n_allele; + } + if ( !buf->vcf[i].af_set ) + { + buf->vcf[i].af = 0; + if ( buf->prune.af_tag ) + { + if ( bcf_get_info_float(buf->hdr,line,buf->prune.af_tag,&buf->prune.farr, &buf->prune.mfarr) > 0 ) buf->vcf[i].af = buf->prune.farr[0]; + } + else if ( bcf_calc_ac(buf->hdr, line, buf->prune.ac, BCF_UN_INFO|BCF_UN_FMT) ) + { + int ntot = buf->prune.ac[0], nalt = 0; + for (k=1; kn_allele; k++) nalt += buf->prune.ac[k]; + buf->vcf[i].af = ntot ? (float)nalt/ntot : 0; + } + buf->vcf[i].af_set = 1; + } + buf->vcf[i].idx = irec; + buf->prune.vrec[irec++] = &buf->vcf[i]; + } + + // sort by allele frequency, low AF will be removed preferentially + qsort(buf->prune.vrec, nbuf, sizeof(*buf->prune.vrec), cmpvrec); + + // sort the rbuf indexes to be pruned descendently so that j-th rbuf index + // is removed before i-th index if iprune.max_sites; + for (i=0; iprune.idx[i] = buf->prune.vrec[i]->idx; + + qsort(buf->prune.idx, nprune, sizeof(int), cmpint_desc); + + for (i=0; irbuf, vcfrec_t, buf->prune.idx[i], buf->vcf); +} + +static int _overlap_can_flush(vcfbuf_t *buf, int flush_all) +{ + if ( flush_all ) { buf->overlap.rid = -1; return 1; } + + int i = rbuf_last(&buf->rbuf); + vcfrec_t *last = &buf->vcf[i]; + if ( buf->overlap.rid != last->rec->rid ) buf->overlap.end = 0; + + int beg_pos = last->rec->pos; + int end_pos = last->rec->pos + last->rec->rlen - 1; + + // Assuming left-aligned indels. In case it is a deletion, the real variant + // starts one base after. If an insertion, the overlap with previous zero length. + int imin = last->rec->rlen; + for (i=0; irec->n_allele; i++) + { + char *ref = last->rec->d.allele[0]; + char *alt = last->rec->d.allele[i]; + if ( *alt == '<' ) continue; // ignore symbolic alleles + while ( *ref && *alt && nt_to_upper(*ref)==nt_to_upper(*alt) ) { ref++; alt++; } + if ( imin > ref - last->rec->d.allele[0] ) imin = ref - last->rec->d.allele[0]; + } + + if ( beg_pos <= buf->overlap.end ) + { + beg_pos += imin; + if ( beg_pos > end_pos ) end_pos = beg_pos; + } + + if ( buf->rbuf.n==1 ) + { + buf->overlap.rid = last->rec->rid; + buf->overlap.end = end_pos; + return 0; + } + if ( beg_pos <= buf->overlap.end ) + { + if ( buf->overlap.end < end_pos ) buf->overlap.end = end_pos; + return 0; + } + return 1; +} + +bcf1_t *vcfbuf_flush(vcfbuf_t *buf, int flush_all) +{ + int i,j; + + if ( buf->rbuf.n==0 ) return NULL; + if ( flush_all ) goto ret; + + i = rbuf_kth(&buf->rbuf, 0); // first + j = rbuf_last(&buf->rbuf); // last + + if ( buf->vcf[i].rec->rid != buf->vcf[j].rec->rid ) goto ret; + if ( buf->overlap.active ) + { + int ret = _overlap_can_flush(buf, flush_all); + //printf("can_flush: %d %d - %d\n", ret, buf->vcf[i].rec->pos+1, buf->vcf[j].rec->pos+1); + if ( ret ) goto ret; + } + //if ( buf->overlap.active && _overlap_can_flush(buf, flush_all) ) goto ret; + + if ( buf->win > 0 ) + { + if ( buf->rbuf.n <= buf->win ) return NULL; + goto ret; + } + else if ( buf->win < 0 ) + { + if ( buf->vcf[i].rec->pos - buf->vcf[j].rec->pos > buf->win ) return NULL; + } + else return NULL; + +ret: + if ( buf->prune.max_sites && buf->prune.max_sites < buf->rbuf.n ) _prune_sites(buf, flush_all); + + i = rbuf_shift(&buf->rbuf); + return buf->vcf[i].rec; +} + +static double _estimate_af(int8_t *ptr, int size, int nvals, int nsamples) +{ + int i,j, nref = 0, nalt = 0; + for (i=0; in_sample!=brec->n_sample ) error("Different number of samples: %d vs %d\n",arec->n_sample,brec->n_sample); + assert( arec->n_sample ); + + int i,j,igt = bcf_hdr_id2int(buf->hdr, BCF_DT_ID, "GT"); + bcf_unpack(arec, BCF_UN_FMT); + bcf_unpack(brec, BCF_UN_FMT); + bcf_fmt_t *afmt = NULL, *bfmt = NULL; + for (i=0; in_fmt; i++) + if ( arec->d.fmt[i].id==igt ) { afmt = &arec->d.fmt[i]; break; } + if ( !afmt ) return -1; // no GT tag + for (i=0; in_fmt; i++) + if ( brec->d.fmt[i].id==igt ) { bfmt = &brec->d.fmt[i]; break; } + if ( !bfmt ) return -1; // no GT tag + + if ( afmt->n==0 ) return -1; // empty?! + if ( bfmt->n==0 ) return -1; // empty?! + if ( afmt->type!=BCF_BT_INT8 ) error("TODO: the GT fmt_type is not int8!\n"); + if ( bfmt->type!=BCF_BT_INT8 ) error("TODO: the GT fmt_type is not int8!\n"); + + // Determine allele frequencies, this is to sample randomly missing genotypes + double aaf = 0, baf = 0; + if ( buf->ld.rand_missing ) + { + aaf = _estimate_af((int8_t*)afmt->p, afmt->size, afmt->n, arec->n_sample); + baf = _estimate_af((int8_t*)bfmt->p, bfmt->size, bfmt->n, brec->n_sample); + } + + // Calculate correlation + double ab = 0, aa = 0, bb = 0, a = 0, b = 0; + int nab = 0, na = 0, nb = 0, ndiff = 0; + for (i=0; in_sample; i++) + { + int8_t *aptr = (int8_t*) (afmt->p + i*afmt->size); + int8_t *bptr = (int8_t*) (bfmt->p + i*bfmt->size); + int adsg = 0, bdsg = 0, an = 0, bn = 0; + for (j=0; jn; j++) + { + if ( aptr[j]==bcf_int8_vector_end ) break; + if ( aptr[j]==bcf_gt_missing ) + { + if ( !buf->ld.rand_missing ) break; + if ( rand()/RAND_MAX >= aaf ) adsg += 1; + } + else if ( bcf_gt_allele(aptr[j]) ) adsg += 1; + an++; + } + for (j=0; jn; j++) + { + if ( bptr[j]==bcf_int8_vector_end ) break; + if ( bptr[j]==bcf_gt_missing ) + { + if ( !buf->ld.rand_missing ) break; + if ( rand()/RAND_MAX >= baf ) bdsg += 1; + } + else if ( bcf_gt_allele(bptr[j]) ) bdsg += 1; + bn++; + } + if ( an ) + { + aa += adsg*adsg; + a += adsg; + na++; + } + if ( bn ) + { + bb += bdsg*bdsg; + b += bdsg; + nb++; + } + if ( an && bn ) + { + if ( adsg!=bdsg ) ndiff++; + ab += adsg*bdsg; + nab++; + } + } + if ( !nab ) return -1; + + double cor; + if ( !ndiff ) cor = 1; + else + { + // Don't know how to deal with zero variance. Since this the purpose is filtering, + // it is not enough to say the value is undefined. Therefore an artificial noise is + // added to make the denominator non-zero. + if ( aa == a*a/na || bb == b*b/nb ) + { + aa += 3*3; + bb += 3*3; + ab += 3*3; + a += 3; + b += 3; + na++; + nb++; + nab++; + } + cor = (ab/nab - a/na*b/nb) / sqrt(aa/na - a/na*a/na) / sqrt(bb/nb - b/nb*b/nb); + } + return cor*cor; +} + +bcf1_t *vcfbuf_max_ld(vcfbuf_t *buf, bcf1_t *rec, double *ld) +{ + *ld = -1; + if ( !buf->rbuf.n ) return NULL; + + int i = buf->rbuf.f; + + // Relying on vcfbuf being properly flushed - all sites in the buffer + // must come from the same chromosome + if ( buf->vcf[i].rec->rid != rec->rid ) return NULL; + + int imax = 0; + double max = 0; + for (i=-1; rbuf_next(&buf->rbuf,&i); ) + { + if ( buf->ld.skip_filter ) + { + if ( buf->vcf[i].rec->d.n_flt > 1 ) continue; // multiple filters are set + if ( buf->vcf[i].rec->d.n_flt==1 && buf->vcf[i].rec->d.flt[0]!=0 ) continue; // not PASS + } + double val = _calc_ld(buf, buf->vcf[i].rec, rec); + if ( buf->ld.max && buf->ld.max < val ) + { + *ld = val; + return buf->vcf[i].rec; + } + if ( val > max ) + { + max = val; + imax = i; + } + } + *ld = max; + return buf->vcf[imax].rec; +} + + diff --git a/bcftools/vcfbuf.h b/bcftools/vcfbuf.h new file mode 100644 index 000000000..5494323df --- /dev/null +++ b/bcftools/vcfbuf.h @@ -0,0 +1,81 @@ +/* The MIT License + + Copyright (c) 2017 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +/* + Buffer VCF records and perform operations on the buffer +*/ + +#ifndef __VCFBUF_H__ +#define __VCFBUF_H__ + +#include + +typedef struct _vcfbuf_t vcfbuf_t; + +// Modes of operation +typedef enum +{ + VCFBUF_LD_MAX, // vcfbuf_max_ld() stops at the first record that exceeds the threshold + VCFBUF_RAND_MISSING, // randomize rather than ignore missing genotypes + VCFBUF_SKIP_FILTER, // skip sites with FILTER diferent from "PASS" or "." + VCFBUF_NSITES, // leave at max this many sites in the window + VCFBUF_AF_TAG, // use this INFO tag with LD_NSITES + VCFBUF_OVERLAP_WIN, // keep only overlapping variants in the window +} +vcfbuf_opt_t; + +#define vcfbuf_set_opt(buf,type,key,value) { type tmp = value; vcfbuf_set(buf, key, (void*)&tmp); } +void vcfbuf_set(vcfbuf_t *buf, vcfbuf_opt_t key, void *value); + + +/* + * vcfbuf_init() - init buffer + * @win: number of sites (>0) or bp (<0) + */ +vcfbuf_t *vcfbuf_init(bcf_hdr_t *hdr, int win); +void vcfbuf_destroy(vcfbuf_t *buf); + +/* + * vcfbuf_push() - push a new site for analysis + * @swap: if set, do not create a copy, but return a substitute + */ +bcf1_t *vcfbuf_push(vcfbuf_t *buf, bcf1_t *rec, int swap); + +bcf1_t *vcfbuf_flush(vcfbuf_t *buf, int flush_all); + +/* + * vcfbuf_nsites() - return the number of sites in the buffer + */ +int vcfbuf_nsites(vcfbuf_t *buf); + +/* + * vcfbuf_max_ld() - return a record that has maximum D or first record exceeding the threshold + * @ld: will be filled with the maximum D found + */ +bcf1_t *vcfbuf_max_ld(vcfbuf_t *buf, bcf1_t *rec, double *ld); + +#endif + diff --git a/bcftools/vcfcall.c b/bcftools/vcfcall.c index e5bbf1167..00771f73c 100644 --- a/bcftools/vcfcall.c +++ b/bcftools/vcfcall.c @@ -24,6 +24,7 @@ THE SOFTWARE. */ #include #include +#include #include #include #include @@ -146,7 +147,7 @@ static ploidy_predef_t ploidy_predefs[] = "* * * F 2\n" }, { .alias = "GRCh38", - .about = "Human Genome reference assembly GRCh38 / hg38, plain chromosome naming (1,2,3,..)", + .about = "Human Genome reference assembly GRCh38 / hg38", .ploidy = "X 1 9999 M 1\n" "X 2781480 155701381 M 1\n" @@ -275,7 +276,7 @@ static void set_samples(args_t *args, const char *fn, int is_file) args->samples_map = (int*) malloc(sizeof(int)*bcf_hdr_nsamples(args->aux.hdr)); // for subsetting args->sample2sex = (int*) malloc(sizeof(int)*bcf_hdr_nsamples(args->aux.hdr)); - int dflt_sex_id = ploidy_add_sex(args->ploidy, "F"); + int dflt_sex_id = ploidy_nsex(args->ploidy) - 1; for (i=0; iaux.hdr); i++) args->sample2sex[i] = dflt_sex_id; int *old2new = (int*) malloc(sizeof(int)*bcf_hdr_nsamples(args->aux.hdr)); @@ -294,6 +295,7 @@ static void set_samples(args_t *args, const char *fn, int is_file) int ismpl = bcf_hdr_id2int(args->aux.hdr, BCF_DT_SAMPLE, ss); if ( ismpl < 0 ) { fprintf(stderr,"Warning: No such sample in the VCF: %s\n",ss); continue; } + if ( old2new[ismpl] != -1 ) { fprintf(stderr,"Warning: The sample is listed multiple times: %s\n",ss); continue; } ss = se+1; while ( *ss && isspace(*ss) ) ss++; @@ -411,18 +413,24 @@ static void init_data(args_t *args) { args->nsamples = bcf_hdr_nsamples(args->aux.hdr); args->sample2sex = (int*) malloc(sizeof(int)*args->nsamples); - for (i=0; insamples; i++) args->sample2sex[i] = 0; + for (i=0; insamples; i++) args->sample2sex[i] = args->nsex - 1; } } if ( args->nsamples ) { args->aux.ploidy = (uint8_t*) malloc(args->nsamples); - for (i=0; insamples; i++) args->aux.ploidy[i] = 2; - for (i=0; insex; i++) args->sex2ploidy_prev[i] = 2; + for (i=0; insamples; i++) args->aux.ploidy[i] = ploidy_max(args->ploidy); + for (i=0; insex; i++) args->sex2ploidy_prev[i] = ploidy_max(args->ploidy); + for (i=0; insamples; i++) + if ( args->sample2sex[i] >= args->nsex ) args->sample2sex[i] = args->nsex - 1; } - if ( args->gvcf ) + if ( args->gvcf ) + { + int id = bcf_hdr_id2int(args->aux.hdr,BCF_DT_ID,"DP"); + if ( id<0 || !bcf_hdr_idinfo_exists(args->aux.hdr,BCF_HL_FMT,id) ) error("--gvcf output mode requires FORMAT/DP tag, which is not present in the input header\n"); gvcf_update_header(args->gvcf, args->aux.hdr); + } if ( args->samples_map ) { @@ -554,7 +562,6 @@ static void set_ploidy(args_t *args, bcf1_t *rec) else args->aux.ploidy[i] = args->sex2ploidy[args->sample2sex[i]]; } - int *tmp = args->sex2ploidy; args->sex2ploidy = args->sex2ploidy_prev; args->sex2ploidy_prev = tmp; } @@ -569,7 +576,10 @@ ploidy_t *init_ploidy(char *alias) if ( !pld->alias ) { - fprintf(stderr,"Predefined ploidies:\n"); + fprintf(stderr,"\nPRE-DEFINED PLOIDY FILES\n\n"); + fprintf(stderr," * Columns are: CHROM,FROM,TO,SEX,PLOIDY\n"); + fprintf(stderr," * Coordinates are 1-based inclusive.\n"); + fprintf(stderr," * A '*' means any value not otherwise defined.\n\n"); pld = ploidy_predefs; while ( pld->alias ) { @@ -618,6 +628,7 @@ static void usage(args_t *args) fprintf(stderr, "Input/output options:\n"); fprintf(stderr, " -A, --keep-alts keep all possible alternate alleles at variant sites\n"); fprintf(stderr, " -f, --format-fields output format fields: GQ,GP (lowercase allowed) []\n"); + fprintf(stderr, " -F, --prior-freqs use prior allele frequencies\n"); fprintf(stderr, " -g, --gvcf ,[...] group non-variant sites into gVCF blocks by minimum per-sample DP\n"); fprintf(stderr, " -i, --insert-missed output also sites missed by mpileup but present in -T\n"); fprintf(stderr, " -M, --keep-masked-ref keep sites with masked reference allele (REF=N)\n"); @@ -630,7 +641,7 @@ static void usage(args_t *args) fprintf(stderr, " -m, --multiallelic-caller alternative model for multiallelic and rare-variant calling (conflicts with -c)\n"); fprintf(stderr, " -n, --novel-rate ,[...] likelihood of novel mutation for constrained trio calling, see man page for details [1e-8,1e-9,1e-9]\n"); fprintf(stderr, " -p, --pval-threshold variant if P(ref|D) mutation rate (use bigger for greater sensitivity) [1.1e-3]\n"); + fprintf(stderr, " -P, --prior mutation rate (use bigger for greater sensitivity), use with -m [1.1e-3]\n"); // todo (and more) // fprintf(stderr, "\nContrast calling and association test options:\n"); @@ -667,6 +678,7 @@ int main_vcfcall(int argc, char *argv[]) { {"help",no_argument,NULL,'h'}, {"format-fields",required_argument,NULL,'f'}, + {"prior-freqs",required_argument,NULL,'F'}, {"gvcf",required_argument,NULL,'g'}, {"output",required_argument,NULL,'o'}, {"output-type",required_argument,NULL,'O'}, @@ -698,7 +710,7 @@ int main_vcfcall(int argc, char *argv[]) }; char *tmp = NULL; - while ((c = getopt_long(argc, argv, "h?o:O:r:R:s:S:t:T:ANMV:vcmp:C:n:P:f:ig:XY", loptions, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "h?o:O:r:R:s:S:t:T:ANMV:vcmp:C:n:P:f:ig:XYF:", loptions, NULL)) >= 0) { switch (c) { @@ -713,6 +725,13 @@ int main_vcfcall(int argc, char *argv[]) case 'c': args.flag |= CF_CCALL; break; // the original EM based calling method case 'i': args.flag |= CF_INS_MISSED; break; case 'v': args.aux.flag |= CALL_VARONLY; break; + case 'F': + args.aux.prior_AN = optarg; + args.aux.prior_AC = strchr(optarg,','); + if ( !args.aux.prior_AC ) error("Expected two tags with -F (e.g. AN,AC), got \"%s\"\n",optarg); + *args.aux.prior_AC = 0; + args.aux.prior_AC++; + break; case 'g': args.gvcf = gvcf_init(optarg); if ( !args.gvcf ) error("Could not parse: --gvcf %s\n", optarg); @@ -770,8 +789,8 @@ int main_vcfcall(int argc, char *argv[]) if ( !ploidy_fname && !ploidy ) { - fprintf(stderr,"Note: Neither --ploidy nor --ploidy-file given, assuming all sites are diploid\n"); - args.ploidy = ploidy_init_string("",2); + if ( !args.samples_is_file ) fprintf(stderr,"Note: none of --samples-file, --ploidy or --ploidy-file given, assuming all sites are diploid\n"); + args.ploidy = ploidy_init_string("* * * 0 0\n* * * 1 1\n* * * 2 2\n",2); } if ( !args.ploidy ) error("Could not initialize ploidy\n"); @@ -833,6 +852,7 @@ int main_vcfcall(int argc, char *argv[]) else ret = ccall(&args.aux, bcf_rec); if ( ret==-1 ) error("Something is wrong\n"); + else if ( ret==-2 ) continue; // skip the site // Normal output if ( (args.aux.flag & CALL_VARONLY) && ret==0 && !args.gvcf ) continue; // not a variant diff --git a/bcftools/vcfcall.c.pysam.c b/bcftools/vcfcall.c.pysam.c index 8e59fd985..f4a0ce9d2 100644 --- a/bcftools/vcfcall.c.pysam.c +++ b/bcftools/vcfcall.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfcall.c -- SNP/indel variant calling from VCF/BCF. @@ -26,6 +26,7 @@ THE SOFTWARE. */ #include #include +#include #include #include #include @@ -148,7 +149,7 @@ static ploidy_predef_t ploidy_predefs[] = "* * * F 2\n" }, { .alias = "GRCh38", - .about = "Human Genome reference assembly GRCh38 / hg38, plain chromosome naming (1,2,3,..)", + .about = "Human Genome reference assembly GRCh38 / hg38", .ploidy = "X 1 9999 M 1\n" "X 2781480 155701381 M 1\n" @@ -277,7 +278,7 @@ static void set_samples(args_t *args, const char *fn, int is_file) args->samples_map = (int*) malloc(sizeof(int)*bcf_hdr_nsamples(args->aux.hdr)); // for subsetting args->sample2sex = (int*) malloc(sizeof(int)*bcf_hdr_nsamples(args->aux.hdr)); - int dflt_sex_id = ploidy_add_sex(args->ploidy, "F"); + int dflt_sex_id = ploidy_nsex(args->ploidy) - 1; for (i=0; iaux.hdr); i++) args->sample2sex[i] = dflt_sex_id; int *old2new = (int*) malloc(sizeof(int)*bcf_hdr_nsamples(args->aux.hdr)); @@ -295,7 +296,8 @@ static void set_samples(args_t *args, const char *fn, int is_file) char x = *se, *xptr = se; *se = 0; int ismpl = bcf_hdr_id2int(args->aux.hdr, BCF_DT_SAMPLE, ss); - if ( ismpl < 0 ) { fprintf(pysam_stderr,"Warning: No such sample in the VCF: %s\n",ss); continue; } + if ( ismpl < 0 ) { fprintf(bcftools_stderr,"Warning: No such sample in the VCF: %s\n",ss); continue; } + if ( old2new[ismpl] != -1 ) { fprintf(bcftools_stderr,"Warning: The sample is listed multiple times: %s\n",ss); continue; } ss = se+1; while ( *ss && isspace(*ss) ) ss++; @@ -401,7 +403,7 @@ static void init_data(args_t *args) if ( args->aux.flag&CALL_CONSTR_TRIO ) { if ( 3*args->aux.nfams!=args->nsamples ) error("Expected only trios in %s, sorry!\n", args->samples_fname); - fprintf(pysam_stderr,"Detected %d samples in %d trio families\n", args->nsamples,args->aux.nfams); + fprintf(bcftools_stderr,"Detected %d samples in %d trio families\n", args->nsamples,args->aux.nfams); } } if ( args->ploidy ) @@ -413,18 +415,24 @@ static void init_data(args_t *args) { args->nsamples = bcf_hdr_nsamples(args->aux.hdr); args->sample2sex = (int*) malloc(sizeof(int)*args->nsamples); - for (i=0; insamples; i++) args->sample2sex[i] = 0; + for (i=0; insamples; i++) args->sample2sex[i] = args->nsex - 1; } } if ( args->nsamples ) { args->aux.ploidy = (uint8_t*) malloc(args->nsamples); - for (i=0; insamples; i++) args->aux.ploidy[i] = 2; - for (i=0; insex; i++) args->sex2ploidy_prev[i] = 2; + for (i=0; insamples; i++) args->aux.ploidy[i] = ploidy_max(args->ploidy); + for (i=0; insex; i++) args->sex2ploidy_prev[i] = ploidy_max(args->ploidy); + for (i=0; insamples; i++) + if ( args->sample2sex[i] >= args->nsex ) args->sample2sex[i] = args->nsex - 1; } - if ( args->gvcf ) + if ( args->gvcf ) + { + int id = bcf_hdr_id2int(args->aux.hdr,BCF_DT_ID,"DP"); + if ( id<0 || !bcf_hdr_idinfo_exists(args->aux.hdr,BCF_HL_FMT,id) ) error("--gvcf output mode requires FORMAT/DP tag, which is not present in the input header\n"); gvcf_update_header(args->gvcf, args->aux.hdr); + } if ( args->samples_map ) { @@ -530,7 +538,7 @@ static int parse_format_flag(const char *str) else if ( !strncasecmp(ss,"GP",se-ss) ) flag |= CALL_FMT_GP; else { - fprintf(pysam_stderr,"Could not parse \"%s\"\n", str); + fprintf(bcftools_stderr,"Could not parse \"%s\"\n", str); exit(1); } if ( !*se ) break; @@ -556,7 +564,6 @@ static void set_ploidy(args_t *args, bcf1_t *rec) else args->aux.ploidy[i] = args->sex2ploidy[args->sample2sex[i]]; } - int *tmp = args->sex2ploidy; args->sex2ploidy = args->sex2ploidy_prev; args->sex2ploidy_prev = tmp; } @@ -571,23 +578,26 @@ ploidy_t *init_ploidy(char *alias) if ( !pld->alias ) { - fprintf(pysam_stderr,"Predefined ploidies:\n"); + fprintf(bcftools_stderr,"\nPRE-DEFINED PLOIDY FILES\n\n"); + fprintf(bcftools_stderr," * Columns are: CHROM,FROM,TO,SEX,PLOIDY\n"); + fprintf(bcftools_stderr," * Coordinates are 1-based inclusive.\n"); + fprintf(bcftools_stderr," * A '*' means any value not otherwise defined.\n\n"); pld = ploidy_predefs; while ( pld->alias ) { - fprintf(pysam_stderr,"%s\n .. %s\n\n", pld->alias,pld->about); + fprintf(bcftools_stderr,"%s\n .. %s\n\n", pld->alias,pld->about); if ( detailed ) - fprintf(pysam_stderr,"%s\n", pld->ploidy); + fprintf(bcftools_stderr,"%s\n", pld->ploidy); pld++; } - fprintf(pysam_stderr,"Run as --ploidy (e.g. --ploidy GRCh37).\n"); - fprintf(pysam_stderr,"To see the detailed ploidy definition, append a question mark (e.g. --ploidy GRCh37?).\n"); - fprintf(pysam_stderr,"\n"); + fprintf(bcftools_stderr,"Run as --ploidy (e.g. --ploidy GRCh37).\n"); + fprintf(bcftools_stderr,"To see the detailed ploidy definition, append a question mark (e.g. --ploidy GRCh37?).\n"); + fprintf(bcftools_stderr,"\n"); exit(-1); } else if ( detailed ) { - fprintf(pysam_stderr,"%s", pld->ploidy); + fprintf(bcftools_stderr,"%s", pld->ploidy); exit(-1); } return ploidy_init_string(pld->ploidy,2); @@ -595,52 +605,53 @@ ploidy_t *init_ploidy(char *alias) static void usage(args_t *args) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: SNP/indel variant calling from VCF/BCF. To be used in conjunction with samtools mpileup.\n"); - fprintf(pysam_stderr, " This command replaces the former \"bcftools view\" caller. Some of the original\n"); - fprintf(pysam_stderr, " functionality has been temporarily lost in the process of transition to htslib,\n"); - fprintf(pysam_stderr, " but will be added back on popular demand. The original calling model can be\n"); - fprintf(pysam_stderr, " invoked with the -c option.\n"); - fprintf(pysam_stderr, "Usage: bcftools call [options] \n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "File format options:\n"); - fprintf(pysam_stderr, " --no-version do not append version and command line to the header\n"); - fprintf(pysam_stderr, " -o, --output write output to a file [standard output]\n"); - fprintf(pysam_stderr, " -O, --output-type output type: 'b' compressed BCF; 'u' uncompressed BCF; 'z' compressed VCF; 'v' uncompressed VCF [v]\n"); - fprintf(pysam_stderr, " --ploidy [?] predefined ploidy, 'list' to print available settings, append '?' for details\n"); - fprintf(pysam_stderr, " --ploidy-file space/tab-delimited list of CHROM,FROM,TO,SEX,PLOIDY\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " -s, --samples list of samples to include [all samples]\n"); - fprintf(pysam_stderr, " -S, --samples-file PED file or a file with an optional column with sex (see man page for details) [all samples]\n"); - fprintf(pysam_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " --threads number of extra output compression threads [0]\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Input/output options:\n"); - fprintf(pysam_stderr, " -A, --keep-alts keep all possible alternate alleles at variant sites\n"); - fprintf(pysam_stderr, " -f, --format-fields output format fields: GQ,GP (lowercase allowed) []\n"); - fprintf(pysam_stderr, " -g, --gvcf ,[...] group non-variant sites into gVCF blocks by minimum per-sample DP\n"); - fprintf(pysam_stderr, " -i, --insert-missed output also sites missed by mpileup but present in -T\n"); - fprintf(pysam_stderr, " -M, --keep-masked-ref keep sites with masked reference allele (REF=N)\n"); - fprintf(pysam_stderr, " -V, --skip-variants skip indels/snps\n"); - fprintf(pysam_stderr, " -v, --variants-only output variant sites only\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Consensus/variant calling options:\n"); - fprintf(pysam_stderr, " -c, --consensus-caller the original calling method (conflicts with -m)\n"); - fprintf(pysam_stderr, " -C, --constrain one of: alleles, trio (see manual)\n"); - fprintf(pysam_stderr, " -m, --multiallelic-caller alternative model for multiallelic and rare-variant calling (conflicts with -c)\n"); - fprintf(pysam_stderr, " -n, --novel-rate ,[...] likelihood of novel mutation for constrained trio calling, see man page for details [1e-8,1e-9,1e-9]\n"); - fprintf(pysam_stderr, " -p, --pval-threshold variant if P(ref|D) mutation rate (use bigger for greater sensitivity) [1.1e-3]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: SNP/indel variant calling from VCF/BCF. To be used in conjunction with samtools mpileup.\n"); + fprintf(bcftools_stderr, " This command replaces the former \"bcftools view\" caller. Some of the original\n"); + fprintf(bcftools_stderr, " functionality has been temporarily lost in the process of transition to htslib,\n"); + fprintf(bcftools_stderr, " but will be added back on popular demand. The original calling model can be\n"); + fprintf(bcftools_stderr, " invoked with the -c option.\n"); + fprintf(bcftools_stderr, "Usage: bcftools call [options] \n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "File format options:\n"); + fprintf(bcftools_stderr, " --no-version do not append version and command line to the header\n"); + fprintf(bcftools_stderr, " -o, --output write output to a file [standard output]\n"); + fprintf(bcftools_stderr, " -O, --output-type output type: 'b' compressed BCF; 'u' uncompressed BCF; 'z' compressed VCF; 'v' uncompressed VCF [v]\n"); + fprintf(bcftools_stderr, " --ploidy [?] predefined ploidy, 'list' to print available settings, append '?' for details\n"); + fprintf(bcftools_stderr, " --ploidy-file space/tab-delimited list of CHROM,FROM,TO,SEX,PLOIDY\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " -s, --samples list of samples to include [all samples]\n"); + fprintf(bcftools_stderr, " -S, --samples-file PED file or a file with an optional column with sex (see man page for details) [all samples]\n"); + fprintf(bcftools_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " --threads number of extra output compression threads [0]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Input/output options:\n"); + fprintf(bcftools_stderr, " -A, --keep-alts keep all possible alternate alleles at variant sites\n"); + fprintf(bcftools_stderr, " -f, --format-fields output format fields: GQ,GP (lowercase allowed) []\n"); + fprintf(bcftools_stderr, " -F, --prior-freqs use prior allele frequencies\n"); + fprintf(bcftools_stderr, " -g, --gvcf ,[...] group non-variant sites into gVCF blocks by minimum per-sample DP\n"); + fprintf(bcftools_stderr, " -i, --insert-missed output also sites missed by mpileup but present in -T\n"); + fprintf(bcftools_stderr, " -M, --keep-masked-ref keep sites with masked reference allele (REF=N)\n"); + fprintf(bcftools_stderr, " -V, --skip-variants skip indels/snps\n"); + fprintf(bcftools_stderr, " -v, --variants-only output variant sites only\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Consensus/variant calling options:\n"); + fprintf(bcftools_stderr, " -c, --consensus-caller the original calling method (conflicts with -m)\n"); + fprintf(bcftools_stderr, " -C, --constrain one of: alleles, trio (see manual)\n"); + fprintf(bcftools_stderr, " -m, --multiallelic-caller alternative model for multiallelic and rare-variant calling (conflicts with -c)\n"); + fprintf(bcftools_stderr, " -n, --novel-rate ,[...] likelihood of novel mutation for constrained trio calling, see man page for details [1e-8,1e-9,1e-9]\n"); + fprintf(bcftools_stderr, " -p, --pval-threshold variant if P(ref|D) mutation rate (use bigger for greater sensitivity), use with -m [1.1e-3]\n"); // todo (and more) - // fprintf(pysam_stderr, "\nContrast calling and association test options:\n"); - // fprintf(pysam_stderr, " -1 INT number of group-1 samples [0]\n"); - // fprintf(pysam_stderr, " -C FLOAT posterior constrast for LRTaux.min_lrt); - // fprintf(pysam_stderr, " -U INT number of permutations for association testing (effective with -1) [0]\n"); - // fprintf(pysam_stderr, " -X FLOAT only perform permutations for P(chi^2)aux.min_perm_p); - fprintf(pysam_stderr, "\n"); + // fprintf(bcftools_stderr, "\nContrast calling and association test options:\n"); + // fprintf(bcftools_stderr, " -1 INT number of group-1 samples [0]\n"); + // fprintf(bcftools_stderr, " -C FLOAT posterior constrast for LRTaux.min_lrt); + // fprintf(bcftools_stderr, " -U INT number of permutations for association testing (effective with -1) [0]\n"); + // fprintf(bcftools_stderr, " -X FLOAT only perform permutations for P(chi^2)aux.min_perm_p); + fprintf(bcftools_stderr, "\n"); exit(-1); } @@ -669,6 +680,7 @@ int main_vcfcall(int argc, char *argv[]) { {"help",no_argument,NULL,'h'}, {"format-fields",required_argument,NULL,'f'}, + {"prior-freqs",required_argument,NULL,'F'}, {"gvcf",required_argument,NULL,'g'}, {"output",required_argument,NULL,'o'}, {"output-type",required_argument,NULL,'O'}, @@ -700,14 +712,14 @@ int main_vcfcall(int argc, char *argv[]) }; char *tmp = NULL; - while ((c = getopt_long(argc, argv, "h?o:O:r:R:s:S:t:T:ANMV:vcmp:C:n:P:f:ig:XY", loptions, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "h?o:O:r:R:s:S:t:T:ANMV:vcmp:C:n:P:f:ig:XYF:", loptions, NULL)) >= 0) { switch (c) { case 2 : ploidy_fname = optarg; break; case 1 : ploidy = optarg; break; - case 'X': ploidy = "X"; fprintf(pysam_stderr,"Warning: -X will be deprecated, please use --ploidy instead.\n"); break; - case 'Y': ploidy = "Y"; fprintf(pysam_stderr,"Warning: -Y will be deprecated, please use --ploidy instead.\n"); break; + case 'X': ploidy = "X"; fprintf(bcftools_stderr,"Warning: -X will be deprecated, please use --ploidy instead.\n"); break; + case 'Y': ploidy = "Y"; fprintf(bcftools_stderr,"Warning: -Y will be deprecated, please use --ploidy instead.\n"); break; case 'f': args.aux.output_tags |= parse_format_flag(optarg); break; case 'M': args.flag &= ~CF_ACGT_ONLY; break; // keep sites where REF is N case 'N': args.flag |= CF_ACGT_ONLY; break; // omit sites where first base in REF is N (the new default) @@ -715,6 +727,13 @@ int main_vcfcall(int argc, char *argv[]) case 'c': args.flag |= CF_CCALL; break; // the original EM based calling method case 'i': args.flag |= CF_INS_MISSED; break; case 'v': args.aux.flag |= CALL_VARONLY; break; + case 'F': + args.aux.prior_AN = optarg; + args.aux.prior_AC = strchr(optarg,','); + if ( !args.aux.prior_AC ) error("Expected two tags with -F (e.g. AN,AC), got \"%s\"\n",optarg); + *args.aux.prior_AC = 0; + args.aux.prior_AC++; + break; case 'g': args.gvcf = gvcf_init(optarg); if ( !args.gvcf ) error("Could not parse: --gvcf %s\n", optarg); @@ -772,8 +791,8 @@ int main_vcfcall(int argc, char *argv[]) if ( !ploidy_fname && !ploidy ) { - fprintf(pysam_stderr,"Note: Neither --ploidy nor --ploidy-file given, assuming all sites are diploid\n"); - args.ploidy = ploidy_init_string("",2); + if ( !args.samples_is_file ) fprintf(bcftools_stderr,"Note: none of --samples-file, --ploidy or --ploidy-file given, assuming all sites are diploid\n"); + args.ploidy = ploidy_init_string("* * * 0 0\n* * * 1 1\n* * * 2 2\n",2); } if ( !args.ploidy ) error("Could not initialize ploidy\n"); @@ -835,6 +854,7 @@ int main_vcfcall(int argc, char *argv[]) else ret = ccall(&args.aux, bcf_rec); if ( ret==-1 ) error("Something is wrong\n"); + else if ( ret==-2 ) continue; // skip the site // Normal output if ( (args.aux.flag & CALL_VARONLY) && ret==0 && !args.gvcf ) continue; // not a variant diff --git a/bcftools/vcfcnv.c b/bcftools/vcfcnv.c index e4b9372c9..abfef5401 100644 --- a/bcftools/vcfcnv.c +++ b/bcftools/vcfcnv.c @@ -1,6 +1,6 @@ /* The MIT License - Copyright (c) 2014-2015 Genome Research Ltd. + Copyright (c) 2014-2018 Genome Research Ltd. Author: Petr Danecek @@ -212,8 +212,14 @@ static double *init_iprobs(int ndim, double same_prob) static void init_sample_files(sample_t *smpl, char *dir) { smpl->dat_fh = open_file(&smpl->dat_fname,"w","%s/dat.%s.tab",dir,smpl->name); + if ( !smpl->dat_fh ) error("Error opening file: %s/dat.%s.tab\n",dir,smpl->name); + smpl->cn_fh = open_file(&smpl->cn_fname,"w","%s/cn.%s.tab",dir,smpl->name); + if ( !smpl->cn_fh ) error("Error opening file: %s/cn.%s.tab\n",dir,smpl->name); + smpl->summary_fh = open_file(&smpl->summary_fname,"w","%s/summary.%s.tab",dir,smpl->name); + if ( !smpl->summary_fh ) error("Error opening file: %s/summary.%s.tab\n",dir,smpl->name); + fprintf(smpl->dat_fh,"# [1]Chromosome\t[2]Position\t[3]BAF\t[4]LRR\n"); fprintf(smpl->cn_fh,"# [1]Chromosome\t[2]Position\t[3]CN\t[4]P(CN0)\t[5]P(CN1)\t[6]P(CN2)\t[7]P(CN3)\n"); fprintf(smpl->summary_fh,"# RG, Regions [2]Chromosome\t[3]Start\t[4]End\t[5]Copy Number state\t[6]Quality\t[7]nSites\t[8]nHETs\n"); @@ -266,17 +272,15 @@ static void init_data(args_t *args) hmm_init_states(args->hmm, args->iprobs); args->summary_fh = stdout; - if ( args->output_dir ) + init_sample_files(&args->query_sample, args->output_dir); + if ( args->control_sample.name ) { - init_sample_files(&args->query_sample, args->output_dir); - if ( args->control_sample.name ) - { - init_sample_files(&args->control_sample, args->output_dir); - args->summary_fh = open_file(&args->summary_fname,"w","%s/summary.tab",args->output_dir); - } - else - args->summary_fh = NULL; // one sample only, no two-file summary + init_sample_files(&args->control_sample, args->output_dir); + args->summary_fh = open_file(&args->summary_fname,"w","%s/summary.tab",args->output_dir); } + else + args->summary_fh = NULL; // one sample only, no two-file summary + int i; FILE *fh = args->summary_fh ? args->summary_fh : args->query_sample.summary_fh; @@ -295,6 +299,19 @@ static void init_data(args_t *args) "# RG, Regions\t[2]Chromosome\t[3]Start\t[4]End\t[5]Copy number:%s\t[6]Quality\t[7]nSites\t[8]nHETs\n", args->query_sample.name ); + if ( args->optimize_frac ) + { + fprintf(args->query_sample.summary_fh, "# CF, cell fraction estimate\t[2]Chromosome\t[3]Start\t[4]End\t[5]Cell fraction\t[6]BAF deviation\n"); + if ( args->control_sample.name ) + { + fprintf(args->control_sample.summary_fh, "# CF, cell fraction estimate\t[2]Chromosome\t[3]Start\t[4]End\t[5]Cell fraction\t[6]BAF deviation\n"); + fprintf(args->summary_fh, "# CF, cell fraction estimate\t[2]Chromosome\t[3]Start\t[4]End\t" + "[5]Cell fraction:%s\t[6]Cell fraction:%s\t[7]BAF deviation:%s\t[8]BAF deviation:%s\n", + args->query_sample.name,args->control_sample.name, + args->query_sample.name,args->control_sample.name + ); + } + } } char *msprintf(const char *fmt, ...); @@ -321,7 +338,7 @@ static void plot_sample(args_t *args, sample_t *smpl) "csv.register_dialect('tab', delimiter='\\t', quoting=csv.QUOTE_NONE)\n" "\n" "dat = {}\n" - "with open('%s', 'rb') as f:\n" + "with open('%s', 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " for row in reader:\n" " chr = row[0]\n" @@ -330,7 +347,7 @@ static void plot_sample(args_t *args, sample_t *smpl) " dat[chr].append([row[1], float(row[2]), float(row[3])])\n" "\n" "cnv = {}\n" - "with open('%s', 'rb') as f:\n" + "with open('%s', 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " for row in reader:\n" " chr = row[0]\n" @@ -412,7 +429,7 @@ static void create_plots(args_t *args) "\n" "def chroms_to_plot(th):\n" " dat = {}\n" - " with open('%s/summary.tab', 'rb') as f:\n" + " with open('%s/summary.tab', 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " for row in reader:\n" " if row[0]!='RG': continue\n" @@ -434,14 +451,14 @@ static void create_plots(args_t *args) " plot_chroms = chroms_to_plot(args.plot_threshold)\n" "\n" "def read_dat(file,dat,plot_chr):\n" - " with open(file, 'rb') as f:\n" + " with open(file, 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " for row in reader:\n" " chr = row[0]\n" " if chr != plot_chr: continue\n" " dat.append([row[1], float(row[2]), float(row[3])])\n" "def read_cnv(file,cnv,plot_chr):\n" - " with open(file, 'rb') as f:\n" + " with open(file, 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " for row in reader:\n" " chr = row[0]\n" @@ -556,6 +573,7 @@ static void destroy_data(args_t *args) free(args->sites); free(args->eprob); free(args->tprob); + free(args->iprobs); free(args->summary_fname); free(args->nonref_afs); free(args->query_sample.baf); @@ -960,6 +978,20 @@ static void cnv_flush_viterbi(args_t *args) if ( args->control_sample.name ) fprintf(stderr,"\t.. %f %f", args->control_sample.cell_frac,args->control_sample.baf_dev2); fprintf(stderr,"\n"); + + fprintf(args->query_sample.summary_fh,"CF\t%s\t%d\t%d\t%.2f\t%f\n", + bcf_hdr_id2name(args->hdr,args->prev_rid),args->sites[0]+1,args->sites[args->nsites-1]+1, + args->query_sample.cell_frac,sqrt(args->query_sample.baf_dev2)); + if ( args->control_sample.name ) + { + fprintf(args->control_sample.summary_fh,"CF\t%s\t%d\t%d\t%.2f\t%f\n", + bcf_hdr_id2name(args->hdr,args->prev_rid),args->sites[0]+1,args->sites[args->nsites-1]+1, + args->control_sample.cell_frac,sqrt(args->control_sample.baf_dev2)); + fprintf(args->summary_fh,"CF\t%s\t%d\t%d\t%.2f\t%.2f\t%f\t%f\n", + bcf_hdr_id2name(args->hdr,args->prev_rid),args->sites[0]+1,args->sites[args->nsites-1]+1, + args->query_sample.cell_frac, args->control_sample.cell_frac, + sqrt(args->query_sample.baf_dev2), sqrt(args->control_sample.baf_dev2)); + } } set_emission_probs(args); @@ -1351,7 +1383,7 @@ int main_vcfcnv(int argc, char *argv[]) else fname = argv[optind]; if ( !fname ) usage(args); - if ( args->plot_th<=100 && !args->output_dir ) error("Expected -o option with -p\n"); + if ( !args->output_dir ) error("Expected -o option\n"); if ( args->regions_list ) { if ( bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 ) diff --git a/bcftools/vcfcnv.c.pysam.c b/bcftools/vcfcnv.c.pysam.c index 10a00b9b9..29b0cb5f1 100644 --- a/bcftools/vcfcnv.c.pysam.c +++ b/bcftools/vcfcnv.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* The MIT License - Copyright (c) 2014-2015 Genome Research Ltd. + Copyright (c) 2014-2018 Genome Research Ltd. Author: Petr Danecek @@ -214,8 +214,14 @@ static double *init_iprobs(int ndim, double same_prob) static void init_sample_files(sample_t *smpl, char *dir) { smpl->dat_fh = open_file(&smpl->dat_fname,"w","%s/dat.%s.tab",dir,smpl->name); + if ( !smpl->dat_fh ) error("Error opening file: %s/dat.%s.tab\n",dir,smpl->name); + smpl->cn_fh = open_file(&smpl->cn_fname,"w","%s/cn.%s.tab",dir,smpl->name); + if ( !smpl->cn_fh ) error("Error opening file: %s/cn.%s.tab\n",dir,smpl->name); + smpl->summary_fh = open_file(&smpl->summary_fname,"w","%s/summary.%s.tab",dir,smpl->name); + if ( !smpl->summary_fh ) error("Error opening file: %s/summary.%s.tab\n",dir,smpl->name); + fprintf(smpl->dat_fh,"# [1]Chromosome\t[2]Position\t[3]BAF\t[4]LRR\n"); fprintf(smpl->cn_fh,"# [1]Chromosome\t[2]Position\t[3]CN\t[4]P(CN0)\t[5]P(CN1)\t[6]P(CN2)\t[7]P(CN3)\n"); fprintf(smpl->summary_fh,"# RG, Regions [2]Chromosome\t[3]Start\t[4]End\t[5]Copy Number state\t[6]Quality\t[7]nSites\t[8]nHETs\n"); @@ -267,18 +273,16 @@ static void init_data(args_t *args) args->hmm = hmm_init(args->nstates, args->tprob, 10000); hmm_init_states(args->hmm, args->iprobs); - args->summary_fh = pysam_stdout; - if ( args->output_dir ) + args->summary_fh = bcftools_stdout; + init_sample_files(&args->query_sample, args->output_dir); + if ( args->control_sample.name ) { - init_sample_files(&args->query_sample, args->output_dir); - if ( args->control_sample.name ) - { - init_sample_files(&args->control_sample, args->output_dir); - args->summary_fh = open_file(&args->summary_fname,"w","%s/summary.tab",args->output_dir); - } - else - args->summary_fh = NULL; // one sample only, no two-file summary + init_sample_files(&args->control_sample, args->output_dir); + args->summary_fh = open_file(&args->summary_fname,"w","%s/summary.tab",args->output_dir); } + else + args->summary_fh = NULL; // one sample only, no two-file summary + int i; FILE *fh = args->summary_fh ? args->summary_fh : args->query_sample.summary_fh; @@ -297,6 +301,19 @@ static void init_data(args_t *args) "# RG, Regions\t[2]Chromosome\t[3]Start\t[4]End\t[5]Copy number:%s\t[6]Quality\t[7]nSites\t[8]nHETs\n", args->query_sample.name ); + if ( args->optimize_frac ) + { + fprintf(args->query_sample.summary_fh, "# CF, cell fraction estimate\t[2]Chromosome\t[3]Start\t[4]End\t[5]Cell fraction\t[6]BAF deviation\n"); + if ( args->control_sample.name ) + { + fprintf(args->control_sample.summary_fh, "# CF, cell fraction estimate\t[2]Chromosome\t[3]Start\t[4]End\t[5]Cell fraction\t[6]BAF deviation\n"); + fprintf(args->summary_fh, "# CF, cell fraction estimate\t[2]Chromosome\t[3]Start\t[4]End\t" + "[5]Cell fraction:%s\t[6]Cell fraction:%s\t[7]BAF deviation:%s\t[8]BAF deviation:%s\n", + args->query_sample.name,args->control_sample.name, + args->query_sample.name,args->control_sample.name + ); + } + } } char *msprintf(const char *fmt, ...); @@ -306,7 +323,7 @@ static void py_plot_cnv(char *script, float th) char *cmd = msprintf("python %s -p %f", script, th); int ret = system(cmd); - if ( ret) fprintf(pysam_stderr, "The command returned non-zero status %d: %s\n", ret, cmd); + if ( ret) fprintf(bcftools_stderr, "The command returned non-zero status %d: %s\n", ret, cmd); free(cmd); } @@ -323,7 +340,7 @@ static void plot_sample(args_t *args, sample_t *smpl) "csv.register_dialect('tab', delimiter='\\t', quoting=csv.QUOTE_NONE)\n" "\n" "dat = {}\n" - "with open('%s', 'rb') as f:\n" + "with open('%s', 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " for row in reader:\n" " chr = row[0]\n" @@ -332,7 +349,7 @@ static void plot_sample(args_t *args, sample_t *smpl) " dat[chr].append([row[1], float(row[2]), float(row[3])])\n" "\n" "cnv = {}\n" - "with open('%s', 'rb') as f:\n" + "with open('%s', 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " for row in reader:\n" " chr = row[0]\n" @@ -414,7 +431,7 @@ static void create_plots(args_t *args) "\n" "def chroms_to_plot(th):\n" " dat = {}\n" - " with open('%s/summary.tab', 'rb') as f:\n" + " with open('%s/summary.tab', 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " for row in reader:\n" " if row[0]!='RG': continue\n" @@ -436,14 +453,14 @@ static void create_plots(args_t *args) " plot_chroms = chroms_to_plot(args.plot_threshold)\n" "\n" "def read_dat(file,dat,plot_chr):\n" - " with open(file, 'rb') as f:\n" + " with open(file, 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " for row in reader:\n" " chr = row[0]\n" " if chr != plot_chr: continue\n" " dat.append([row[1], float(row[2]), float(row[3])])\n" "def read_cnv(file,cnv,plot_chr):\n" - " with open(file, 'rb') as f:\n" + " with open(file, 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " for row in reader:\n" " chr = row[0]\n" @@ -558,6 +575,7 @@ static void destroy_data(args_t *args) free(args->sites); free(args->eprob); free(args->tprob); + free(args->iprobs); free(args->summary_fname); free(args->nonref_afs); free(args->query_sample.baf); @@ -641,7 +659,7 @@ static int set_observed_prob(args_t *args, sample_t *smpl, int isite) cn3_baf /= norm; #if DBG0 - if ( args->verbose ) fprintf(pysam_stderr,"%f\t%f %f %f\n", baf,cn1_baf,cn2_baf,cn3_baf); + if ( args->verbose ) fprintf(bcftools_stderr,"%f\t%f %f %f\n", baf,cn1_baf,cn2_baf,cn3_baf); #endif double cn1_lrr = exp(-(lrr + 0.45)*(lrr + 0.45)/smpl->lrr_dev2); @@ -866,7 +884,7 @@ static int update_sample_args(args_t *args, sample_t *smpl, int ismpl) baf_AA_dev2 /= norm_baf_AA_dev2; if ( baf_dev2 < baf_AA_dev2 ) baf_dev2 = baf_AA_dev2; double max_mean_cn3 = 0.5 - sqrt(baf_dev2)*1.644854; // R: qnorm(0.95)=1.644854 - //fprintf(pysam_stderr,"dev=%f AA_dev=%f max_mean_cn3=%f mean_cn3=%f\n", baf_dev2,baf_AA_dev2,max_mean_cn3,mean_cn3); + //fprintf(bcftools_stderr,"dev=%f AA_dev=%f max_mean_cn3=%f mean_cn3=%f\n", baf_dev2,baf_AA_dev2,max_mean_cn3,mean_cn3); assert( max_mean_cn3>0 ); double new_frac = 1./mean_cn3 - 2; @@ -936,13 +954,13 @@ static void cnv_flush_viterbi(args_t *args) if ( args->optimize_frac ) { int niter = 0; - fprintf(pysam_stderr,"Attempting to estimate the fraction of aberrant cells (chr %s):\n", bcf_hdr_id2name(args->hdr,args->prev_rid)); + fprintf(bcftools_stderr,"Attempting to estimate the fraction of aberrant cells (chr %s):\n", bcf_hdr_id2name(args->hdr,args->prev_rid)); do { - fprintf(pysam_stderr,"\t.. %f %f", args->query_sample.cell_frac,args->query_sample.baf_dev2); + fprintf(bcftools_stderr,"\t.. %f %f", args->query_sample.cell_frac,args->query_sample.baf_dev2); if ( args->control_sample.name ) - fprintf(pysam_stderr,"\t.. %f %f", args->control_sample.cell_frac,args->control_sample.baf_dev2); - fprintf(pysam_stderr,"\n"); + fprintf(bcftools_stderr,"\t.. %f %f", args->control_sample.cell_frac,args->control_sample.baf_dev2); + fprintf(bcftools_stderr,"\n"); set_emission_probs(args); hmm_run_fwd_bwd(hmm, args->nsites, args->eprob, args->sites); } @@ -958,10 +976,24 @@ static void cnv_flush_viterbi(args_t *args) if ( args->control_sample.name ) set_gauss_params(args, &args->control_sample); } - fprintf(pysam_stderr,"\t.. %f %f", args->query_sample.cell_frac,args->query_sample.baf_dev2); + fprintf(bcftools_stderr,"\t.. %f %f", args->query_sample.cell_frac,args->query_sample.baf_dev2); + if ( args->control_sample.name ) + fprintf(bcftools_stderr,"\t.. %f %f", args->control_sample.cell_frac,args->control_sample.baf_dev2); + fprintf(bcftools_stderr,"\n"); + + fprintf(args->query_sample.summary_fh,"CF\t%s\t%d\t%d\t%.2f\t%f\n", + bcf_hdr_id2name(args->hdr,args->prev_rid),args->sites[0]+1,args->sites[args->nsites-1]+1, + args->query_sample.cell_frac,sqrt(args->query_sample.baf_dev2)); if ( args->control_sample.name ) - fprintf(pysam_stderr,"\t.. %f %f", args->control_sample.cell_frac,args->control_sample.baf_dev2); - fprintf(pysam_stderr,"\n"); + { + fprintf(args->control_sample.summary_fh,"CF\t%s\t%d\t%d\t%.2f\t%f\n", + bcf_hdr_id2name(args->hdr,args->prev_rid),args->sites[0]+1,args->sites[args->nsites-1]+1, + args->control_sample.cell_frac,sqrt(args->control_sample.baf_dev2)); + fprintf(args->summary_fh,"CF\t%s\t%d\t%d\t%.2f\t%.2f\t%f\t%f\n", + bcf_hdr_id2name(args->hdr,args->prev_rid),args->sites[0]+1,args->sites[args->nsites-1]+1, + args->query_sample.cell_frac, args->control_sample.cell_frac, + sqrt(args->query_sample.baf_dev2), sqrt(args->control_sample.baf_dev2)); + } } set_emission_probs(args); @@ -971,7 +1003,7 @@ static void cnv_flush_viterbi(args_t *args) double ori_ii = avg_ii_prob(nstates,hmm_get_tprob(hmm)); hmm_run_baum_welch(hmm, args->nsites, args->eprob, args->sites); double new_ii = avg_ii_prob(nstates,hmm_get_tprob(hmm)); - fprintf(pysam_stderr,"%e\t%e\t%e\n", ori_ii,new_ii,new_ii-ori_ii); + fprintf(bcftools_stderr,"%e\t%e\t%e\n", ori_ii,new_ii,new_ii-ori_ii); double *tprob = init_tprob_matrix(nstates, 1-new_ii, args->same_prob); hmm_set_tprob(args->hmm, tprob, 10000); double *tprob_arr = hmm_get_tprob(hmm); @@ -983,9 +1015,9 @@ static void cnv_flush_viterbi(args_t *args) { for (j=0; j\n"); - fprintf(pysam_stderr, "General Options:\n"); - fprintf(pysam_stderr, " -c, --control-sample optional control sample name to highlight differences\n"); - fprintf(pysam_stderr, " -f, --AF-file read allele frequencies from file (CHR\\tPOS\\tREF,ALT\\tAF)\n"); - fprintf(pysam_stderr, " -o, --output-dir \n"); - fprintf(pysam_stderr, " -p, --plot-threshold plot aberrant chromosomes with quality at least 'float'\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " -s, --query-sample query samply name\n"); - fprintf(pysam_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); - fprintf(pysam_stderr, "HMM Options:\n"); - fprintf(pysam_stderr, " -a, --aberrant fraction of aberrant cells in query and control [1.0,1.0]\n"); - fprintf(pysam_stderr, " -b, --BAF-weight relative contribution from BAF [1]\n"); - fprintf(pysam_stderr, " -d, --BAF-dev expected BAF deviation in query and control [0.04,0.04]\n"); // experimental - fprintf(pysam_stderr, " -e, --err-prob uniform error probability [1e-4]\n"); - fprintf(pysam_stderr, " -k, --LRR-dev expected LRR deviation [0.2,0.2]\n"); // experimental - fprintf(pysam_stderr, " -l, --LRR-weight relative contribution from LRR [0.2]\n"); - fprintf(pysam_stderr, " -L, --LRR-smooth-win window of LRR moving average smoothing [10]\n"); - fprintf(pysam_stderr, " -O, --optimize estimate fraction of aberrant cells down to [1.0]\n"); - fprintf(pysam_stderr, " -P, --same-prob prior probability of -s/-c being the same [0.5]\n"); - fprintf(pysam_stderr, " -x, --xy-prob P(x|y) transition probability [1e-9]\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Copy number variation caller, requires Illumina's B-allele frequency (BAF) and Log R\n"); + fprintf(bcftools_stderr, " Ratio intensity (LRR). The HMM considers the following copy number states: CN 2\n"); + fprintf(bcftools_stderr, " (normal), 1 (single-copy loss), 0 (complete loss), 3 (single-copy gain)\n"); + fprintf(bcftools_stderr, "Usage: bcftools cnv [OPTIONS] \n"); + fprintf(bcftools_stderr, "General Options:\n"); + fprintf(bcftools_stderr, " -c, --control-sample optional control sample name to highlight differences\n"); + fprintf(bcftools_stderr, " -f, --AF-file read allele frequencies from file (CHR\\tPOS\\tREF,ALT\\tAF)\n"); + fprintf(bcftools_stderr, " -o, --output-dir \n"); + fprintf(bcftools_stderr, " -p, --plot-threshold plot aberrant chromosomes with quality at least 'float'\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " -s, --query-sample query samply name\n"); + fprintf(bcftools_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, "HMM Options:\n"); + fprintf(bcftools_stderr, " -a, --aberrant fraction of aberrant cells in query and control [1.0,1.0]\n"); + fprintf(bcftools_stderr, " -b, --BAF-weight relative contribution from BAF [1]\n"); + fprintf(bcftools_stderr, " -d, --BAF-dev expected BAF deviation in query and control [0.04,0.04]\n"); // experimental + fprintf(bcftools_stderr, " -e, --err-prob uniform error probability [1e-4]\n"); + fprintf(bcftools_stderr, " -k, --LRR-dev expected LRR deviation [0.2,0.2]\n"); // experimental + fprintf(bcftools_stderr, " -l, --LRR-weight relative contribution from LRR [0.2]\n"); + fprintf(bcftools_stderr, " -L, --LRR-smooth-win window of LRR moving average smoothing [10]\n"); + fprintf(bcftools_stderr, " -O, --optimize estimate fraction of aberrant cells down to [1.0]\n"); + fprintf(bcftools_stderr, " -P, --same-prob prior probability of -s/-c being the same [0.5]\n"); + fprintf(bcftools_stderr, " -x, --xy-prob P(x|y) transition probability [1e-9]\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } @@ -1353,7 +1385,7 @@ int main_vcfcnv(int argc, char *argv[]) else fname = argv[optind]; if ( !fname ) usage(args); - if ( args->plot_th<=100 && !args->output_dir ) error("Expected -o option with -p\n"); + if ( !args->output_dir ) error("Expected -o option\n"); if ( args->regions_list ) { if ( bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 ) @@ -1379,7 +1411,7 @@ int main_vcfcnv(int argc, char *argv[]) } cnv_next_line(args, NULL); create_plots(args); - fprintf(pysam_stderr,"Number of lines: total/processed: %d/%d\n", args->ntot,args->nused); + fprintf(bcftools_stderr,"Number of lines: total/processed: %d/%d\n", args->ntot,args->nused); destroy_data(args); free(args); return 0; diff --git a/bcftools/vcfconcat.c b/bcftools/vcfconcat.c index bd6a00a25..3345c2031 100644 --- a/bcftools/vcfconcat.c +++ b/bcftools/vcfconcat.c @@ -555,100 +555,138 @@ static void concat(args_t *args) } } +int print_vcf_gz_header(BGZF *fp, BGZF *bgzf_out, int print_header, kstring_t *tmp) +{ + char *buffer = (char*) fp->uncompressed_block; + + // Read the header and find the position of the data block + if ( buffer[0]!='#' ) error("Could not parse the header, expected '#', found '%c'\n", buffer[0]); + + int nskip = 1; // end of the header in the current uncompressed block + while (1) + { + if ( buffer[nskip]=='\n' ) + { + nskip++; + if ( nskip>=fp->block_length ) + { + kputsn(buffer,nskip,tmp); + if ( bgzf_read_block(fp) != 0 ) return -1; + if ( !fp->block_length ) break; + nskip = 0; + } + // The header has finished + if ( buffer[nskip]!='#' ) + { + kputsn(buffer,nskip,tmp); + break; + } + } + nskip++; + if ( nskip>=fp->block_length ) + { + kputsn(buffer,fp->block_length,tmp); + if ( bgzf_read_block(fp) != 0 ) return -1; + if ( !fp->block_length ) break; + nskip = 0; + } + } + if ( print_header ) + { + if ( bgzf_write(bgzf_out,tmp->s,tmp->l) != tmp->l ) error("Failed to write %d bytes\n", tmp->l); + tmp->l = 0; + } + return nskip; +} + +static inline int unpackInt16(const uint8_t *buffer) +{ + return buffer[0] | buffer[1] << 8; +} +static int check_header(const uint8_t *header) +{ + if ( header[0] != 31 || header[1] != 139 || header[2] != 8 ) return -2; + return ((header[3] & 4) != 0 + && unpackInt16((uint8_t*)&header[10]) == 6 + && header[12] == 'B' && header[13] == 'C' + && unpackInt16((uint8_t*)&header[14]) == 2) ? 0 : -1; +} static void naive_concat(args_t *args) { // only compressed BCF atm BGZF *bgzf_out = bgzf_open(args->output_fname,"w");; - const size_t page_size = 32768; - char *buf = (char*) malloc(page_size); + const size_t page_size = BGZF_MAX_BLOCK_SIZE; + uint8_t *buf = (uint8_t*) malloc(page_size); kstring_t tmp = {0,0,0}; - int i; + int i, file_types = 0; for (i=0; infnames; i++) { htsFile *hts_fp = hts_open(args->fnames[i],"r"); if ( !hts_fp ) error("Failed to open: %s\n", args->fnames[i]); htsFormat type = *hts_get_format(hts_fp); - if ( type.format==vcf ) error("The --naive option currently works only for compressed BCFs, sorry :-/\n"); - if ( type.compression!=bgzf ) error("The --naive option currently works only for compressed BCFs, sorry :-/\n"); + if ( type.compression!=bgzf ) + error("The --naive option works only for compressed BCFs or VCFs, sorry :-/\n"); + file_types |= type.format==vcf ? 1 : 2; + if ( file_types==3 ) + error("The --naive option works only for compressed files of the same type, all BCFs or all VCFs :-/\n"); BGZF *fp = hts_get_bgzfp(hts_fp); if ( !fp || bgzf_read_block(fp) != 0 || !fp->block_length ) error("Failed to read %s: %s\n", args->fnames[i], strerror(errno)); - uint8_t magic[5]; - if ( bgzf_read(fp, magic, 5) != 5 ) error("Failed to read the BCF header in %s\n", args->fnames[i]); - if (strncmp((char*)magic, "BCF\2\2", 5) != 0) error("Invalid BCF magic string in %s\n", args->fnames[i]); + int nskip; + if ( type.format==bcf ) + { + uint8_t magic[5]; + if ( bgzf_read(fp, magic, 5) != 5 ) error("Failed to read the BCF header in %s\n", args->fnames[i]); + if (strncmp((char*)magic, "BCF\2\2", 5) != 0) error("Invalid BCF magic string in %s\n", args->fnames[i]); - if ( bgzf_read(fp, &tmp.l, 4) != 4 ) error("Failed to read the BCF header in %s\n", args->fnames[i]); - hts_expand(char,tmp.l,tmp.m,tmp.s); - if ( bgzf_read(fp, tmp.s, tmp.l) != tmp.l ) error("Failed to read the BCF header in %s\n", args->fnames[i]); + if ( bgzf_read(fp, &tmp.l, 4) != 4 ) error("Failed to read the BCF header in %s\n", args->fnames[i]); + hts_expand(char,tmp.l,tmp.m,tmp.s); + if ( bgzf_read(fp, tmp.s, tmp.l) != tmp.l ) error("Failed to read the BCF header in %s\n", args->fnames[i]); - // write only the first header - if ( i==0 ) + // write only the first header + if ( i==0 ) + { + if ( bgzf_write(bgzf_out, "BCF\2\2", 5) !=5 ) error("Failed to write %d bytes to %s\n", 5,args->output_fname); + if ( bgzf_write(bgzf_out, &tmp.l, 4) !=4 ) error("Failed to write %d bytes to %s\n", 4,args->output_fname); + if ( bgzf_write(bgzf_out, tmp.s, tmp.l) != tmp.l) error("Failed to write %d bytes to %s\n", tmp.l,args->output_fname); + } + nskip = fp->block_offset; + } + else { - if ( bgzf_write(bgzf_out, "BCF\2\2", 5) !=5 ) error("Failed to write %d bytes to %s\n", 5,args->output_fname); - if ( bgzf_write(bgzf_out, &tmp.l, 4) !=4 ) error("Failed to write %d bytes to %s\n", 4,args->output_fname); - if ( bgzf_write(bgzf_out, tmp.s, tmp.l) != tmp.l) error("Failed to write %d bytes to %s\n", tmp.l,args->output_fname); + nskip = print_vcf_gz_header(fp, bgzf_out, i==0?1:0, &tmp); + if ( nskip==-1 ) error("Error reading %s\n", args->fnames[i]); } // Output all non-header data that were read together with the header block - int nskip = fp->block_offset; if ( fp->block_length - nskip > 0 ) { - if ( bgzf_write(bgzf_out, fp->uncompressed_block+nskip, fp->block_length-nskip)<0 ) error("Error: %d\n",fp->errcode); + if ( bgzf_write(bgzf_out, (char *)fp->uncompressed_block+nskip, fp->block_length-nskip)<0 ) error("Error: %d\n",fp->errcode); } if ( bgzf_flush(bgzf_out)<0 ) error("Error: %d\n",bgzf_out->errcode); // Stream the rest of the file as it is, without recompressing, but remove BGZF EOF blocks - ssize_t nread, ncached = 0, nwr; - const int neof = 28; - char cached[neof]; + // The final bgzf eof block will be added by bgzf_close. + ssize_t nread, nblock, nwr; + const int nheader = 18, neof = 28; + const uint8_t *eof = (uint8_t*) "\037\213\010\4\0\0\0\0\0\377\6\0\102\103\2\0\033\0\3\0\0\0\0\0\0\0\0\0"; while (1) { - nread = bgzf_raw_read(fp, buf, page_size); - - // page_size boundary may occur in the middle of the EOF block, so we need to cache the blocks' ends - if ( nread<=0 ) break; - if ( nread<=neof ) // last block - { - if ( ncached ) - { - // flush the part of the cache that won't be needed - nwr = bgzf_raw_write(bgzf_out, cached, nread); - if (nwr != nread) error("Write failed, wrote %d instead of %d bytes.\n", nwr,(int)nread); - - // make space in the cache so that we can append to the end - if ( nread!=neof ) memmove(cached,cached+nread,neof-nread); - } - - // fill the cache and check for eof outside this loop - memcpy(cached+neof-nread,buf,nread); - break; - } - - // not the last block, flush the cache if full - if ( ncached ) - { - nwr = bgzf_raw_write(bgzf_out, cached, ncached); - if (nwr != ncached) error("Write failed, wrote %d instead of %d bytes.\n", nwr,(int)ncached); - ncached = 0; - } - - // fill the cache - nread -= neof; - memcpy(cached,buf+nread,neof); - ncached = neof; - + nread = bgzf_raw_read(fp, buf, nheader); + if ( !nread ) break; + if ( nread != nheader || check_header(buf)!=0 ) error("Could not parse the header of a bgzf block: %s\n",args->fnames[i]); + nblock = unpackInt16(buf+16) + 1; + assert( nblock <= page_size && nblock >= nheader ); + nread += bgzf_raw_read(fp, buf+nheader, nblock - nheader); + if ( nread!=nblock ) error("Could not read %d bytes: %s\n",nblock,args->fnames[i]); + if ( nread==neof && !memcmp(buf,eof,neof) ) continue; nwr = bgzf_raw_write(bgzf_out, buf, nread); - if (nwr != nread) error("Write failed, wrote %d instead of %d bytes.\n", nwr,(int)nread); - } - if ( ncached && memcmp(cached,"\037\213\010\4\0\0\0\0\0\377\6\0\102\103\2\0\033\0\3\0\0\0\0\0\0\0\0\0",neof) ) - { - nwr = bgzf_raw_write(bgzf_out, cached, neof); - if (nwr != neof) error("Write failed, wrote %d instead of %d bytes.\n", nwr,(int)neof); + if ( nwr != nread ) error("Write failed, wrote %d instead of %d bytes.\n", nwr,(int)nread); } if (hts_close(hts_fp)) error("Close failed: %s\n",args->fnames[i]); } @@ -677,8 +715,8 @@ static void usage(args_t *args) fprintf(stderr, " -D, --remove-duplicates Alias for -d none\n"); fprintf(stderr, " -f, --file-list Read the list of files from a file.\n"); fprintf(stderr, " -l, --ligate Ligate phased VCFs by matching phase at overlapping haplotypes\n"); - fprintf(stderr, " --no-version do not append version and command line to the header\n"); - fprintf(stderr, " -n, --naive Concatenate BCF files without recompression (dangerous, use with caution)\n"); + fprintf(stderr, " --no-version Do not append version and command line to the header\n"); + fprintf(stderr, " -n, --naive Concatenate files without recompression (dangerous, use with caution)\n"); fprintf(stderr, " -o, --output Write output to a file [standard output]\n"); fprintf(stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); fprintf(stderr, " -q, --min-PQ Break phase set if phasing quality is lower than [30]\n"); diff --git a/bcftools/vcfconcat.c.pysam.c b/bcftools/vcfconcat.c.pysam.c index be2d6a2e7..1a67b8647 100644 --- a/bcftools/vcfconcat.c.pysam.c +++ b/bcftools/vcfconcat.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfconcat.c -- Concatenate or combine VCF/BCF files. @@ -236,7 +236,7 @@ static void phased_flush(args_t *args) { if ( !gt_absent_warned ) { - fprintf(pysam_stderr,"GT is not present at %s:%d. (This warning is printed only once.)\n", bcf_seqname(ahdr,arec), arec->pos+1); + fprintf(bcftools_stderr,"GT is not present at %s:%d. (This warning is printed only once.)\n", bcf_seqname(ahdr,arec), arec->pos+1); gt_absent_warned = 1; } continue; @@ -247,7 +247,7 @@ static void phased_flush(args_t *args) { if ( !gt_absent_warned ) { - fprintf(pysam_stderr,"GT is not present at %s:%d. (This warning is printed only once.)\n", bcf_seqname(bhdr,brec), brec->pos+1); + fprintf(bcftools_stderr,"GT is not present at %s:%d. (This warning is printed only once.)\n", bcf_seqname(bhdr,brec), brec->pos+1); gt_absent_warned = 1; } continue; @@ -557,100 +557,138 @@ static void concat(args_t *args) } } +int print_vcf_gz_header(BGZF *fp, BGZF *bgzf_out, int print_header, kstring_t *tmp) +{ + char *buffer = (char*) fp->uncompressed_block; + + // Read the header and find the position of the data block + if ( buffer[0]!='#' ) error("Could not parse the header, expected '#', found '%c'\n", buffer[0]); + + int nskip = 1; // end of the header in the current uncompressed block + while (1) + { + if ( buffer[nskip]=='\n' ) + { + nskip++; + if ( nskip>=fp->block_length ) + { + kputsn(buffer,nskip,tmp); + if ( bgzf_read_block(fp) != 0 ) return -1; + if ( !fp->block_length ) break; + nskip = 0; + } + // The header has finished + if ( buffer[nskip]!='#' ) + { + kputsn(buffer,nskip,tmp); + break; + } + } + nskip++; + if ( nskip>=fp->block_length ) + { + kputsn(buffer,fp->block_length,tmp); + if ( bgzf_read_block(fp) != 0 ) return -1; + if ( !fp->block_length ) break; + nskip = 0; + } + } + if ( print_header ) + { + if ( bgzf_write(bgzf_out,tmp->s,tmp->l) != tmp->l ) error("Failed to write %d bytes\n", tmp->l); + tmp->l = 0; + } + return nskip; +} + +static inline int unpackInt16(const uint8_t *buffer) +{ + return buffer[0] | buffer[1] << 8; +} +static int check_header(const uint8_t *header) +{ + if ( header[0] != 31 || header[1] != 139 || header[2] != 8 ) return -2; + return ((header[3] & 4) != 0 + && unpackInt16((uint8_t*)&header[10]) == 6 + && header[12] == 'B' && header[13] == 'C' + && unpackInt16((uint8_t*)&header[14]) == 2) ? 0 : -1; +} static void naive_concat(args_t *args) { // only compressed BCF atm BGZF *bgzf_out = bgzf_open(args->output_fname,"w");; - const size_t page_size = 32768; - char *buf = (char*) malloc(page_size); + const size_t page_size = BGZF_MAX_BLOCK_SIZE; + uint8_t *buf = (uint8_t*) malloc(page_size); kstring_t tmp = {0,0,0}; - int i; + int i, file_types = 0; for (i=0; infnames; i++) { htsFile *hts_fp = hts_open(args->fnames[i],"r"); if ( !hts_fp ) error("Failed to open: %s\n", args->fnames[i]); htsFormat type = *hts_get_format(hts_fp); - if ( type.format==vcf ) error("The --naive option currently works only for compressed BCFs, sorry :-/\n"); - if ( type.compression!=bgzf ) error("The --naive option currently works only for compressed BCFs, sorry :-/\n"); + if ( type.compression!=bgzf ) + error("The --naive option works only for compressed BCFs or VCFs, sorry :-/\n"); + file_types |= type.format==vcf ? 1 : 2; + if ( file_types==3 ) + error("The --naive option works only for compressed files of the same type, all BCFs or all VCFs :-/\n"); BGZF *fp = hts_get_bgzfp(hts_fp); if ( !fp || bgzf_read_block(fp) != 0 || !fp->block_length ) error("Failed to read %s: %s\n", args->fnames[i], strerror(errno)); - uint8_t magic[5]; - if ( bgzf_read(fp, magic, 5) != 5 ) error("Failed to read the BCF header in %s\n", args->fnames[i]); - if (strncmp((char*)magic, "BCF\2\2", 5) != 0) error("Invalid BCF magic string in %s\n", args->fnames[i]); + int nskip; + if ( type.format==bcf ) + { + uint8_t magic[5]; + if ( bgzf_read(fp, magic, 5) != 5 ) error("Failed to read the BCF header in %s\n", args->fnames[i]); + if (strncmp((char*)magic, "BCF\2\2", 5) != 0) error("Invalid BCF magic string in %s\n", args->fnames[i]); - if ( bgzf_read(fp, &tmp.l, 4) != 4 ) error("Failed to read the BCF header in %s\n", args->fnames[i]); - hts_expand(char,tmp.l,tmp.m,tmp.s); - if ( bgzf_read(fp, tmp.s, tmp.l) != tmp.l ) error("Failed to read the BCF header in %s\n", args->fnames[i]); + if ( bgzf_read(fp, &tmp.l, 4) != 4 ) error("Failed to read the BCF header in %s\n", args->fnames[i]); + hts_expand(char,tmp.l,tmp.m,tmp.s); + if ( bgzf_read(fp, tmp.s, tmp.l) != tmp.l ) error("Failed to read the BCF header in %s\n", args->fnames[i]); - // write only the first header - if ( i==0 ) + // write only the first header + if ( i==0 ) + { + if ( bgzf_write(bgzf_out, "BCF\2\2", 5) !=5 ) error("Failed to write %d bytes to %s\n", 5,args->output_fname); + if ( bgzf_write(bgzf_out, &tmp.l, 4) !=4 ) error("Failed to write %d bytes to %s\n", 4,args->output_fname); + if ( bgzf_write(bgzf_out, tmp.s, tmp.l) != tmp.l) error("Failed to write %d bytes to %s\n", tmp.l,args->output_fname); + } + nskip = fp->block_offset; + } + else { - if ( bgzf_write(bgzf_out, "BCF\2\2", 5) !=5 ) error("Failed to write %d bytes to %s\n", 5,args->output_fname); - if ( bgzf_write(bgzf_out, &tmp.l, 4) !=4 ) error("Failed to write %d bytes to %s\n", 4,args->output_fname); - if ( bgzf_write(bgzf_out, tmp.s, tmp.l) != tmp.l) error("Failed to write %d bytes to %s\n", tmp.l,args->output_fname); + nskip = print_vcf_gz_header(fp, bgzf_out, i==0?1:0, &tmp); + if ( nskip==-1 ) error("Error reading %s\n", args->fnames[i]); } // Output all non-header data that were read together with the header block - int nskip = fp->block_offset; if ( fp->block_length - nskip > 0 ) { - if ( bgzf_write(bgzf_out, fp->uncompressed_block+nskip, fp->block_length-nskip)<0 ) error("Error: %d\n",fp->errcode); + if ( bgzf_write(bgzf_out, (char *)fp->uncompressed_block+nskip, fp->block_length-nskip)<0 ) error("Error: %d\n",fp->errcode); } if ( bgzf_flush(bgzf_out)<0 ) error("Error: %d\n",bgzf_out->errcode); // Stream the rest of the file as it is, without recompressing, but remove BGZF EOF blocks - ssize_t nread, ncached = 0, nwr; - const int neof = 28; - char cached[neof]; + // The final bgzf eof block will be added by bgzf_close. + ssize_t nread, nblock, nwr; + const int nheader = 18, neof = 28; + const uint8_t *eof = (uint8_t*) "\037\213\010\4\0\0\0\0\0\377\6\0\102\103\2\0\033\0\3\0\0\0\0\0\0\0\0\0"; while (1) { - nread = bgzf_raw_read(fp, buf, page_size); - - // page_size boundary may occur in the middle of the EOF block, so we need to cache the blocks' ends - if ( nread<=0 ) break; - if ( nread<=neof ) // last block - { - if ( ncached ) - { - // flush the part of the cache that won't be needed - nwr = bgzf_raw_write(bgzf_out, cached, nread); - if (nwr != nread) error("Write failed, wrote %d instead of %d bytes.\n", nwr,(int)nread); - - // make space in the cache so that we can append to the end - if ( nread!=neof ) memmove(cached,cached+nread,neof-nread); - } - - // fill the cache and check for eof outside this loop - memcpy(cached+neof-nread,buf,nread); - break; - } - - // not the last block, flush the cache if full - if ( ncached ) - { - nwr = bgzf_raw_write(bgzf_out, cached, ncached); - if (nwr != ncached) error("Write failed, wrote %d instead of %d bytes.\n", nwr,(int)ncached); - ncached = 0; - } - - // fill the cache - nread -= neof; - memcpy(cached,buf+nread,neof); - ncached = neof; - + nread = bgzf_raw_read(fp, buf, nheader); + if ( !nread ) break; + if ( nread != nheader || check_header(buf)!=0 ) error("Could not parse the header of a bgzf block: %s\n",args->fnames[i]); + nblock = unpackInt16(buf+16) + 1; + assert( nblock <= page_size && nblock >= nheader ); + nread += bgzf_raw_read(fp, buf+nheader, nblock - nheader); + if ( nread!=nblock ) error("Could not read %d bytes: %s\n",nblock,args->fnames[i]); + if ( nread==neof && !memcmp(buf,eof,neof) ) continue; nwr = bgzf_raw_write(bgzf_out, buf, nread); - if (nwr != nread) error("Write failed, wrote %d instead of %d bytes.\n", nwr,(int)nread); - } - if ( ncached && memcmp(cached,"\037\213\010\4\0\0\0\0\0\377\6\0\102\103\2\0\033\0\3\0\0\0\0\0\0\0\0\0",neof) ) - { - nwr = bgzf_raw_write(bgzf_out, cached, neof); - if (nwr != neof) error("Write failed, wrote %d instead of %d bytes.\n", nwr,(int)neof); + if ( nwr != nread ) error("Write failed, wrote %d instead of %d bytes.\n", nwr,(int)nread); } if (hts_close(hts_fp)) error("Close failed: %s\n",args->fnames[i]); } @@ -661,33 +699,33 @@ static void naive_concat(args_t *args) static void usage(args_t *args) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Concatenate or combine VCF/BCF files. All source files must have the same sample\n"); - fprintf(pysam_stderr, " columns appearing in the same order. The program can be used, for example, to\n"); - fprintf(pysam_stderr, " concatenate chromosome VCFs into one VCF, or combine a SNP VCF and an indel\n"); - fprintf(pysam_stderr, " VCF into one. The input files must be sorted by chr and position. The files\n"); - fprintf(pysam_stderr, " must be given in the correct order to produce sorted VCF on output unless\n"); - fprintf(pysam_stderr, " the -a, --allow-overlaps option is specified. With the --naive option, the files\n"); - fprintf(pysam_stderr, " are concatenated without being recompressed, which is very fast but dangerous\n"); - fprintf(pysam_stderr, " if the BCF headers differ.\n"); - fprintf(pysam_stderr, "Usage: bcftools concat [options] [ [...]]\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Options:\n"); - fprintf(pysam_stderr, " -a, --allow-overlaps First coordinate of the next file can precede last record of the current file.\n"); - fprintf(pysam_stderr, " -c, --compact-PS Do not output PS tag at each site, only at the start of a new phase set block.\n"); - fprintf(pysam_stderr, " -d, --rm-dups Output duplicate records present in multiple files only once: \n"); - fprintf(pysam_stderr, " -D, --remove-duplicates Alias for -d none\n"); - fprintf(pysam_stderr, " -f, --file-list Read the list of files from a file.\n"); - fprintf(pysam_stderr, " -l, --ligate Ligate phased VCFs by matching phase at overlapping haplotypes\n"); - fprintf(pysam_stderr, " --no-version do not append version and command line to the header\n"); - fprintf(pysam_stderr, " -n, --naive Concatenate BCF files without recompression (dangerous, use with caution)\n"); - fprintf(pysam_stderr, " -o, --output Write output to a file [standard output]\n"); - fprintf(pysam_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); - fprintf(pysam_stderr, " -q, --min-PQ Break phase set if phasing quality is lower than [30]\n"); - fprintf(pysam_stderr, " -r, --regions Restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file Restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " --threads Number of extra output compression threads [0]\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Concatenate or combine VCF/BCF files. All source files must have the same sample\n"); + fprintf(bcftools_stderr, " columns appearing in the same order. The program can be used, for example, to\n"); + fprintf(bcftools_stderr, " concatenate chromosome VCFs into one VCF, or combine a SNP VCF and an indel\n"); + fprintf(bcftools_stderr, " VCF into one. The input files must be sorted by chr and position. The files\n"); + fprintf(bcftools_stderr, " must be given in the correct order to produce sorted VCF on output unless\n"); + fprintf(bcftools_stderr, " the -a, --allow-overlaps option is specified. With the --naive option, the files\n"); + fprintf(bcftools_stderr, " are concatenated without being recompressed, which is very fast but dangerous\n"); + fprintf(bcftools_stderr, " if the BCF headers differ.\n"); + fprintf(bcftools_stderr, "Usage: bcftools concat [options] [ [...]]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Options:\n"); + fprintf(bcftools_stderr, " -a, --allow-overlaps First coordinate of the next file can precede last record of the current file.\n"); + fprintf(bcftools_stderr, " -c, --compact-PS Do not output PS tag at each site, only at the start of a new phase set block.\n"); + fprintf(bcftools_stderr, " -d, --rm-dups Output duplicate records present in multiple files only once: \n"); + fprintf(bcftools_stderr, " -D, --remove-duplicates Alias for -d none\n"); + fprintf(bcftools_stderr, " -f, --file-list Read the list of files from a file.\n"); + fprintf(bcftools_stderr, " -l, --ligate Ligate phased VCFs by matching phase at overlapping haplotypes\n"); + fprintf(bcftools_stderr, " --no-version Do not append version and command line to the header\n"); + fprintf(bcftools_stderr, " -n, --naive Concatenate files without recompression (dangerous, use with caution)\n"); + fprintf(bcftools_stderr, " -o, --output Write output to a file [standard output]\n"); + fprintf(bcftools_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); + fprintf(bcftools_stderr, " -q, --min-PQ Break phase set if phasing quality is lower than [30]\n"); + fprintf(bcftools_stderr, " -r, --regions Restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file Restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " --threads Number of extra output compression threads [0]\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } diff --git a/bcftools/vcfconvert.c b/bcftools/vcfconvert.c index 1e60d30a9..f815e25cb 100644 --- a/bcftools/vcfconvert.c +++ b/bcftools/vcfconvert.c @@ -1,6 +1,6 @@ /* vcfconvert.c -- convert between VCF/BCF and related formats. - Copyright (C) 2013-2014 Genome Research Ltd. + Copyright (C) 2013-2017 Genome Research Ltd. Author: Petr Danecek @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#include #include #include #include @@ -65,7 +66,7 @@ struct _args_t int rev_als, output_vcf_ids, hap2dip, output_chrom_first_col; int nsamples, *samples, sample_is_file, targets_is_file, regions_is_file, output_type; char **argv, *sample_list, *targets_list, *regions_list, *tag, *columns; - char *outfname, *infname, *ref_fname; + char *outfname, *infname, *ref_fname, *sex_fname; int argc, n_threads, record_cmd_line; }; @@ -81,6 +82,9 @@ static void destroy_data(args_t *args) static void open_vcf(args_t *args, const char *format_str) { args->files = bcf_sr_init(); + if ( args->n_threads && bcf_sr_set_threads(args->files, args->n_threads)!=0 ) + error("Could not initialize --threads %d\n", args->n_threads); + if ( args->regions_list ) { if ( bcf_sr_set_regions(args->files, args->regions_list, args->regions_is_file)<0 ) @@ -129,9 +133,6 @@ static void open_vcf(args_t *args, const char *format_str) } if ( format_str ) args->convert = convert_init(args->header, samples, nsamples, format_str); free(samples); - - if ( args->filter_str ) - args->filter = filter_init(args->header, args->filter_str); } static int tsv_setter_chrom_pos_ref_alt(tsv_t *tsv, bcf1_t *rec, void *usr) @@ -373,6 +374,7 @@ static void gensample_to_vcf(args_t *args) int i, nsamples; char **samples = hts_readlist(sample_fname, 1, &nsamples); + if ( !samples ) error("Could not read %s\n", sample_fname); for (i=2; in.total); } +char *init_sample2sex(bcf_hdr_t *hdr, char *sex_fname) +{ + int i, nlines; + char *sample2sex = (char*) calloc(bcf_hdr_nsamples(hdr),1); + char **lines = hts_readlist(sex_fname, 1, &nlines); + if ( !lines ) error("Could not read %s\n", sex_fname); + for (i=0; ioutfname,&str); - int n_files, i; + int n_files = 0, i; char **files = hts_readlist(str.s, 0, &n_files); if ( n_files==1 ) { @@ -712,22 +742,30 @@ static void vcf_to_gensample(args_t *args) if (sample_fname) fprintf(stderr, "Sample file: %s\n", sample_fname); // write samples file - if (sample_fname) { + if (sample_fname) + { + char *sample2sex = NULL; + if ( args->sex_fname ) sample2sex = init_sample2sex(args->header,args->sex_fname); + int i; BGZF *sout = bgzf_open(sample_fname, sample_compressed ? "wg" : "wu"); str.l = 0; - kputs("ID_1 ID_2 missing\n0 0 0\n", &str); + kputs(sample2sex ? "ID_1 ID_2 missing sex\n0 0 0 0\n" : "ID_1 ID_2 missing\n0 0 0\n", &str); ret = bgzf_write(sout, str.s, str.l); if ( ret != str.l ) error("Error writing %s: %s\n", sample_fname, strerror(errno)); for (i=0; iheader); i++) { str.l = 0; - ksprintf(&str, "%s %s 0\n", args->header->samples[i],args->header->samples[i]); + if ( sample2sex ) + ksprintf(&str, "%s %s 0 %c\n", args->header->samples[i],args->header->samples[i],sample2sex[i]); + else + ksprintf(&str, "%s %s 0\n", args->header->samples[i],args->header->samples[i]); ret = bgzf_write(sout, str.s, str.l); if ( ret != str.l ) error("Error writing %s: %s\n", sample_fname, strerror(errno)); } if ( bgzf_close(sout)!=0 ) error("Error closing %s: %s\n", sample_fname, strerror(errno)); free(sample_fname); + free(sample2sex); } if (!gen_fname) { if ( str.m ) free(str.s); @@ -793,7 +831,7 @@ static void vcf_to_haplegendsample(args_t *args) char *hap_fname = NULL, *legend_fname = NULL, *sample_fname = NULL; str.l = 0; kputs(args->outfname,&str); - int n_files, i; + int n_files = 0, i; char **files = hts_readlist(str.s, 0, &n_files); if ( n_files==1 ) { @@ -824,12 +862,16 @@ static void vcf_to_haplegendsample(args_t *args) if ( legend_fname && (strlen(legend_fname)<3 || strcasecmp(".gz",legend_fname+strlen(legend_fname)-3)) ) legend_compressed = 0; if ( sample_fname && strlen(sample_fname)>3 && strcasecmp(".gz",sample_fname+strlen(sample_fname)-3)==0 ) sample_compressed = 0; - if (hap_fname) fprintf(stderr, "Haps file: %s\n", hap_fname); + if (hap_fname) fprintf(stderr, "Hap file: %s\n", hap_fname); if (legend_fname) fprintf(stderr, "Legend file: %s\n", legend_fname); if (sample_fname) fprintf(stderr, "Sample file: %s\n", sample_fname); // write samples file - if (sample_fname) { + if (sample_fname) + { + char *sample2sex = NULL; + if ( args->sex_fname ) sample2sex = init_sample2sex(args->header,args->sex_fname); + int i; BGZF *sout = bgzf_open(sample_fname, sample_compressed ? "wg" : "wu"); str.l = 0; @@ -839,12 +881,13 @@ static void vcf_to_haplegendsample(args_t *args) for (i=0; iheader); i++) { str.l = 0; - ksprintf(&str, "%s %s %s 2\n", args->header->samples[i], args->header->samples[i], args->header->samples[i]); + ksprintf(&str, "%s %s %s %c\n", args->header->samples[i], args->header->samples[i], args->header->samples[i], sample2sex ? sample2sex[i] : '2'); ret = bgzf_write(sout, str.s, str.l); if ( ret != str.l ) error("Error writing %s: %s\n", sample_fname, strerror(errno)); } if ( bgzf_close(sout)!=0 ) error("Error closing %s: %s\n", sample_fname, strerror(errno)); free(sample_fname); + free(sample2sex); } if (!hap_fname && !legend_fname) { if ( str.m ) free(str.s); @@ -853,6 +896,7 @@ static void vcf_to_haplegendsample(args_t *args) // open haps and legend outputs BGZF *hout = hap_fname ? bgzf_open(hap_fname, hap_compressed ? "wg" : "wu") : NULL; + if ( hap_compressed && args->n_threads ) bgzf_thread_pool(hout, args->files->p->pool, args->files->p->qsize); BGZF *lout = legend_fname ? bgzf_open(legend_fname, legend_compressed ? "wg" : "wu") : NULL; if (legend_fname) { str.l = 0; @@ -940,7 +984,7 @@ static void vcf_to_hapsample(args_t *args) char *hap_fname = NULL, *sample_fname = NULL; str.l = 0; kputs(args->outfname,&str); - int n_files, i; + int n_files = 0, i; char **files = hts_readlist(str.s, 0, &n_files); if ( n_files==1 ) { @@ -966,26 +1010,34 @@ static void vcf_to_hapsample(args_t *args) if ( hap_fname && (strlen(hap_fname)<3 || strcasecmp(".gz",hap_fname+strlen(hap_fname)-3)) ) hap_compressed = 0; if ( sample_fname && strlen(sample_fname)>3 && strcasecmp(".gz",sample_fname+strlen(sample_fname)-3)==0 ) sample_compressed = 0; - if (hap_fname) fprintf(stderr, "Haps file: %s\n", hap_fname); + if (hap_fname) fprintf(stderr, "Hap file: %s\n", hap_fname); if (sample_fname) fprintf(stderr, "Sample file: %s\n", sample_fname); // write samples file - if (sample_fname) { + if (sample_fname) + { + char *sample2sex = NULL; + if ( args->sex_fname ) sample2sex = init_sample2sex(args->header,args->sex_fname); + int i; BGZF *sout = bgzf_open(sample_fname, sample_compressed ? "wg" : "wu"); str.l = 0; - kputs("ID_1 ID_2 missing\n0 0 0\n", &str); + kputs(sample2sex ? "ID_1 ID_2 missing sex\n0 0 0 0\n" : "ID_1 ID_2 missing\n0 0 0\n", &str); ret = bgzf_write(sout, str.s, str.l); if ( ret != str.l ) error("Error writing %s: %s\n", sample_fname, strerror(errno)); for (i=0; iheader); i++) { str.l = 0; - ksprintf(&str, "%s %s 0\n", args->header->samples[i], args->header->samples[i]); + if ( sample2sex ) + ksprintf(&str, "%s %s 0 %c\n", args->header->samples[i],args->header->samples[i],sample2sex[i]); + else + ksprintf(&str, "%s %s 0\n", args->header->samples[i],args->header->samples[i]); ret = bgzf_write(sout, str.s, str.l); if ( ret != str.l ) error("Error writing %s: %s\n", sample_fname, strerror(errno)); } if ( bgzf_close(sout)!=0 ) error("Error closing %s: %s\n", sample_fname, strerror(errno)); free(sample_fname); + free(sample2sex); } if (!hap_fname) { if ( str.m ) free(str.s); @@ -994,6 +1046,7 @@ static void vcf_to_hapsample(args_t *args) // open haps output BGZF *hout = hap_fname ? bgzf_open(hap_fname, hap_compressed ? "wg" : "wu") : NULL; + if ( hap_compressed && args->n_threads ) bgzf_thread_pool(hout, args->files->p->pool, args->files->p->qsize); int no_alt = 0, non_biallelic = 0, filtered = 0, nok = 0; while ( bcf_sr_next_line(args->files) ) @@ -1256,9 +1309,31 @@ static void gvcf_to_vcf(args_t *args) if ( !pass ) continue; } - if ( line->n_allele!=1 || !bcf_has_filter(hdr,line,"PASS") ) + if (!bcf_has_filter(hdr,line,"PASS")) + { + bcf_write(out_fh,hdr,line); + continue; + } + + // check if alleles compatible with being a gVCF record + // ALT must be one of ., <*>, , + // check for INFO/END is below + int i, gallele = -1; + if (line->n_allele==1) + gallele = 0; // illumina/bcftools-call gvcf (if INFO/END present) + else if ( line->d.allele[1][0]=='<' ) + { + for (i=1; in_allele; i++) + { + if ( line->d.allele[i][1]=='*' && line->d.allele[i][2]=='>' && line->d.allele[i][3]=='\0' ) { gallele = i; break; } // mpileup/spec compliant gVCF + if ( line->d.allele[i][1]=='X' && line->d.allele[i][2]=='>' && line->d.allele[i][3]=='\0' ) { gallele = i; break; } // old mpileup gVCF + if ( strcmp(line->d.allele[i],"")==0 ) { gallele = i; break; } // GATK gVCF + } + } + + // no gVCF compatible alleles + if (gallele<0) { - // Assuming that only ALT=. sites can be blocks and skipping sites which don't PASS bcf_write(out_fh,hdr,line); continue; } @@ -1266,7 +1341,7 @@ static void gvcf_to_vcf(args_t *args) int nend = bcf_get_info_int32(hdr,line,"END",&itmp,&nitmp); if ( nend!=1 ) { - // No END lineord + // No INFO/END => not gVCF record bcf_write(out_fh,hdr,line); continue; } @@ -1277,10 +1352,9 @@ static void gvcf_to_vcf(args_t *args) line->pos = pos; char *ref = faidx_fetch_seq(args->ref, (char*)bcf_hdr_id2name(hdr,line->rid), line->pos, line->pos, &len); if ( !ref ) error("faidx_fetch_seq failed at %s:%d\n", bcf_hdr_id2name(hdr,line->rid), line->pos+1); - // we have already checked above that there is only one allele, - // so fine to just update alleles with the ref allele from the fasta - bcf_update_alleles_str(hdr, line, &ref[0]); + strncpy(line->d.allele[0],ref,len); bcf_write(out_fh,hdr,line); + free(ref); } } free(itmp); @@ -1316,6 +1390,7 @@ static void usage(void) fprintf(stderr, " -g, --gensample <...> |,\n"); fprintf(stderr, " --tag tag to take values for .gen file: GT,PL,GL,GP [GT]\n"); fprintf(stderr, " --chrom output chromosome in first column instead of CHROM:POS_REF_ALT\n"); + fprintf(stderr, " --sex output sex column in the sample-file, input format is: Sample\\t[MF]\n"); fprintf(stderr, " --vcf-ids output VCF IDs in second column instead of CHROM:POS_REF_ALT\n"); fprintf(stderr, "\n"); fprintf(stderr, "gVCF conversion:\n"); @@ -1323,15 +1398,17 @@ static void usage(void) fprintf(stderr, " -f, --fasta-ref reference sequence in fasta format\n"); fprintf(stderr, "\n"); fprintf(stderr, "HAP/SAMPLE conversion (output from SHAPEIT):\n"); - fprintf(stderr, " --hapsample2vcf <...> |,\n"); - fprintf(stderr, " --hapsample <...> |,\n"); + fprintf(stderr, " --hapsample2vcf <...> |,\n"); + fprintf(stderr, " --hapsample <...> |,\n"); fprintf(stderr, " --haploid2diploid convert haploid genotypes to diploid homozygotes\n"); + fprintf(stderr, " --sex output sex column in the sample-file, input format is: Sample\\t[MF]\n"); fprintf(stderr, " --vcf-ids output VCF IDs instead of CHROM:POS_REF_ALT\n"); fprintf(stderr, "\n"); fprintf(stderr, "HAP/LEGEND/SAMPLE conversion:\n"); fprintf(stderr, " -H, --haplegendsample2vcf <...> |,,\n"); fprintf(stderr, " -h, --haplegendsample <...> |,,\n"); fprintf(stderr, " --haploid2diploid convert haploid genotypes to diploid homozygotes\n"); + fprintf(stderr, " --sex output sex column in the sample-file, input format is: Sample\\t[MF]\n"); fprintf(stderr, " --vcf-ids output VCF IDs instead of CHROM:POS_REF_ALT\n"); fprintf(stderr, "\n"); fprintf(stderr, "TSV conversion:\n"); @@ -1375,6 +1452,7 @@ int main_vcfconvert(int argc, char *argv[]) {"targets-file",required_argument,NULL,'T'}, {"samples",required_argument,NULL,'s'}, {"samples-file",required_argument,NULL,'S'}, + {"sex",required_argument,NULL,11}, {"gensample",required_argument,NULL,'g'}, {"gensample2vcf",required_argument,NULL,'G'}, {"tag",required_argument,NULL,1}, @@ -1428,6 +1506,7 @@ int main_vcfconvert(int argc, char *argv[]) case 'h': args->convert_func = vcf_to_haplegendsample; args->outfname = optarg; break; case 9 : args->n_threads = strtol(optarg, 0, 0); break; case 10 : args->record_cmd_line = 0; break; + case 11 : args->sex_fname = optarg; break; case '?': usage(); default: error("Unknown argument: %s\n", optarg); } diff --git a/bcftools/vcfconvert.c.pysam.c b/bcftools/vcfconvert.c.pysam.c index 12333cc5e..a0ec8b9a5 100644 --- a/bcftools/vcfconvert.c.pysam.c +++ b/bcftools/vcfconvert.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfconvert.c -- convert between VCF/BCF and related formats. - Copyright (C) 2013-2014 Genome Research Ltd. + Copyright (C) 2013-2017 Genome Research Ltd. Author: Petr Danecek @@ -25,6 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#include #include #include #include @@ -67,7 +68,7 @@ struct _args_t int rev_als, output_vcf_ids, hap2dip, output_chrom_first_col; int nsamples, *samples, sample_is_file, targets_is_file, regions_is_file, output_type; char **argv, *sample_list, *targets_list, *regions_list, *tag, *columns; - char *outfname, *infname, *ref_fname; + char *outfname, *infname, *ref_fname, *sex_fname; int argc, n_threads, record_cmd_line; }; @@ -83,6 +84,9 @@ static void destroy_data(args_t *args) static void open_vcf(args_t *args, const char *format_str) { args->files = bcf_sr_init(); + if ( args->n_threads && bcf_sr_set_threads(args->files, args->n_threads)!=0 ) + error("Could not initialize --threads %d\n", args->n_threads); + if ( args->regions_list ) { if ( bcf_sr_set_regions(args->files, args->regions_list, args->regions_is_file)<0 ) @@ -131,9 +135,6 @@ static void open_vcf(args_t *args, const char *format_str) } if ( format_str ) args->convert = convert_init(args->header, samples, nsamples, format_str); free(samples); - - if ( args->filter_str ) - args->filter = filter_init(args->header, args->filter_str); } static int tsv_setter_chrom_pos_ref_alt(tsv_t *tsv, bcf1_t *rec, void *usr) @@ -211,13 +212,13 @@ static int tsv_setter_gt_gp(tsv_t *tsv, bcf1_t *rec, void *usr) { float aa,ab,bb; aa = strtod(tsv->ss, &tsv->se); - if ( tsv->ss==tsv->se ) { fprintf(pysam_stderr,"Could not parse first value of %d-th sample\n", i+1); return -1; } + if ( tsv->ss==tsv->se ) { fprintf(bcftools_stderr,"Could not parse first value of %d-th sample\n", i+1); return -1; } tsv->ss = tsv->se+1; ab = strtod(tsv->ss, &tsv->se); - if ( tsv->ss==tsv->se ) { fprintf(pysam_stderr,"Could not parse second value of %d-th sample\n", i+1); return -1; } + if ( tsv->ss==tsv->se ) { fprintf(bcftools_stderr,"Could not parse second value of %d-th sample\n", i+1); return -1; } tsv->ss = tsv->se+1; bb = strtod(tsv->ss, &tsv->se); - if ( tsv->ss==tsv->se ) { fprintf(pysam_stderr,"Could not parse third value of %d-th sample\n", i+1); return -1; } + if ( tsv->ss==tsv->se ) { fprintf(bcftools_stderr,"Could not parse third value of %d-th sample\n", i+1); return -1; } tsv->ss = tsv->se+1; if ( args->rev_als ) { float tmp = bb; bb = aa; aa = tmp; } @@ -263,7 +264,7 @@ static int tsv_setter_haps(tsv_t *tsv, bcf1_t *rec, void *usr) if ( !ss[0] || !ss[1] || !ss[2] || (up && (!ss[3] || !ss[4]) ) ) { - fprintf(pysam_stderr,"Wrong number of fields at %d-th sample ([%c][%c][%c]). ",i+1,ss[0],ss[1],ss[2]); + fprintf(bcftools_stderr,"Wrong number of fields at %d-th sample ([%c][%c][%c]). ",i+1,ss[0],ss[1],ss[2]); return -1; } @@ -282,7 +283,7 @@ static int tsv_setter_haps(tsv_t *tsv, bcf1_t *rec, void *usr) args->gts[2*i+all] = bcf_int32_vector_end; break; default : - fprintf(pysam_stderr,"Could not parse: [%c][%s]\n", ss[all*2+up],tsv->ss); + fprintf(bcftools_stderr,"Could not parse: [%c][%s]\n", ss[all*2+up],tsv->ss); return -1; } if( ss[all*2+up+1]=='*' ) up = up + 1; @@ -290,7 +291,7 @@ static int tsv_setter_haps(tsv_t *tsv, bcf1_t *rec, void *usr) if(up && up != 2) { - fprintf(pysam_stderr,"Missing unphased marker '*': [%c][%s]", ss[2+up], tsv->ss); + fprintf(bcftools_stderr,"Missing unphased marker '*': [%c][%s]", ss[2+up], tsv->ss); return -1; } @@ -304,8 +305,8 @@ static int tsv_setter_haps(tsv_t *tsv, bcf1_t *rec, void *usr) } if ( tsv->ss[(nsamples-1)*4+3+nup] ) { - fprintf(pysam_stderr,"nup: %d", nup); - fprintf(pysam_stderr,"Wrong number of fields (%d-th column = [%c]). ", nsamples*2,tsv->ss[(nsamples-1)*4+nup]); + fprintf(bcftools_stderr,"nup: %d", nup); + fprintf(bcftools_stderr,"Wrong number of fields (%d-th column = [%c]). ", nsamples*2,tsv->ss[(nsamples-1)*4+nup]); return -1; } @@ -375,6 +376,7 @@ static void gensample_to_vcf(args_t *args) int i, nsamples; char **samples = hts_readlist(sample_fname, 1, &nsamples); + if ( !samples ) error("Could not read %s\n", sample_fname); for (i=2; iflt); tsv_destroy(tsv); - fprintf(pysam_stderr,"Number of processed rows: \t%d\n", args->n.total); + fprintf(bcftools_stderr,"Number of processed rows: \t%d\n", args->n.total); } static void haplegendsample_to_vcf(args_t *args) @@ -495,6 +497,7 @@ static void haplegendsample_to_vcf(args_t *args) int i, nrows, nsamples; char **samples = hts_readlist(sample_fname, 1, &nrows); + if ( !samples ) error("Could not read %s\n", sample_fname); nsamples = nrows - 1; // sample_fname should contain a header line, so need to ignore first row @@ -554,7 +557,7 @@ static void haplegendsample_to_vcf(args_t *args) tsv_destroy(hap_tsv); tsv_destroy(leg_tsv); - fprintf(pysam_stderr,"Number of processed rows: \t%d\n", args->n.total); + fprintf(bcftools_stderr,"Number of processed rows: \t%d\n", args->n.total); } static void hapsample_to_vcf(args_t *args) @@ -612,6 +615,7 @@ static void hapsample_to_vcf(args_t *args) int i, nsamples; char **samples = hts_readlist(sample_fname, 1, &nsamples); + if ( !samples ) error("Could not read %s\n", sample_fname); for (i=2; igts); tsv_destroy(tsv); - fprintf(pysam_stderr,"Number of processed rows: \t%d\n", args->n.total); + fprintf(bcftools_stderr,"Number of processed rows: \t%d\n", args->n.total); +} + +char *init_sample2sex(bcf_hdr_t *hdr, char *sex_fname) +{ + int i, nlines; + char *sample2sex = (char*) calloc(bcf_hdr_nsamples(hdr),1); + char **lines = hts_readlist(sex_fname, 1, &nlines); + if ( !lines ) error("Could not read %s\n", sex_fname); + for (i=0; ioutfname,&str); - int n_files, i; + int n_files = 0, i; char **files = hts_readlist(str.s, 0, &n_files); if ( n_files==1 ) { @@ -710,26 +740,34 @@ static void vcf_to_gensample(args_t *args) if ( gen_fname && (strlen(gen_fname)<3 || strcasecmp(".gz",gen_fname+strlen(gen_fname)-3)) ) gen_compressed = 0; if ( sample_fname && strlen(sample_fname)>3 && strcasecmp(".gz",sample_fname+strlen(sample_fname)-3)==0 ) sample_compressed = 0; - if (gen_fname) fprintf(pysam_stderr, "Gen file: %s\n", gen_fname); - if (sample_fname) fprintf(pysam_stderr, "Sample file: %s\n", sample_fname); + if (gen_fname) fprintf(bcftools_stderr, "Gen file: %s\n", gen_fname); + if (sample_fname) fprintf(bcftools_stderr, "Sample file: %s\n", sample_fname); // write samples file - if (sample_fname) { + if (sample_fname) + { + char *sample2sex = NULL; + if ( args->sex_fname ) sample2sex = init_sample2sex(args->header,args->sex_fname); + int i; BGZF *sout = bgzf_open(sample_fname, sample_compressed ? "wg" : "wu"); str.l = 0; - kputs("ID_1 ID_2 missing\n0 0 0\n", &str); + kputs(sample2sex ? "ID_1 ID_2 missing sex\n0 0 0 0\n" : "ID_1 ID_2 missing\n0 0 0\n", &str); ret = bgzf_write(sout, str.s, str.l); if ( ret != str.l ) error("Error writing %s: %s\n", sample_fname, strerror(errno)); for (i=0; iheader); i++) { str.l = 0; - ksprintf(&str, "%s %s 0\n", args->header->samples[i],args->header->samples[i]); + if ( sample2sex ) + ksprintf(&str, "%s %s 0 %c\n", args->header->samples[i],args->header->samples[i],sample2sex[i]); + else + ksprintf(&str, "%s %s 0\n", args->header->samples[i],args->header->samples[i]); ret = bgzf_write(sout, str.s, str.l); if ( ret != str.l ) error("Error writing %s: %s\n", sample_fname, strerror(errno)); } if ( bgzf_close(sout)!=0 ) error("Error closing %s: %s\n", sample_fname, strerror(errno)); free(sample_fname); + free(sample2sex); } if (!gen_fname) { if ( str.m ) free(str.s); @@ -755,7 +793,7 @@ static void vcf_to_gensample(args_t *args) // biallelic required if ( line->n_allele>2 ) { if (!non_biallelic) - fprintf(pysam_stderr, "Warning: non-biallelic records are skipped. Consider splitting multi-allelic records into biallelic records using 'bcftools norm -m-'.\n"); + fprintf(bcftools_stderr, "Warning: non-biallelic records are skipped. Consider splitting multi-allelic records into biallelic records using 'bcftools norm -m-'.\n"); non_biallelic++; continue; } @@ -774,7 +812,7 @@ static void vcf_to_gensample(args_t *args) nok++; } } - fprintf(pysam_stderr, "%d records written, %d skipped: %d/%d/%d/%d no-ALT/non-biallelic/filtered/duplicated\n", + fprintf(bcftools_stderr, "%d records written, %d skipped: %d/%d/%d/%d no-ALT/non-biallelic/filtered/duplicated\n", nok, no_alt+non_biallelic+filtered+ndup, no_alt, non_biallelic, filtered, ndup); if ( str.m ) free(str.s); @@ -795,7 +833,7 @@ static void vcf_to_haplegendsample(args_t *args) char *hap_fname = NULL, *legend_fname = NULL, *sample_fname = NULL; str.l = 0; kputs(args->outfname,&str); - int n_files, i; + int n_files = 0, i; char **files = hts_readlist(str.s, 0, &n_files); if ( n_files==1 ) { @@ -826,12 +864,16 @@ static void vcf_to_haplegendsample(args_t *args) if ( legend_fname && (strlen(legend_fname)<3 || strcasecmp(".gz",legend_fname+strlen(legend_fname)-3)) ) legend_compressed = 0; if ( sample_fname && strlen(sample_fname)>3 && strcasecmp(".gz",sample_fname+strlen(sample_fname)-3)==0 ) sample_compressed = 0; - if (hap_fname) fprintf(pysam_stderr, "Haps file: %s\n", hap_fname); - if (legend_fname) fprintf(pysam_stderr, "Legend file: %s\n", legend_fname); - if (sample_fname) fprintf(pysam_stderr, "Sample file: %s\n", sample_fname); + if (hap_fname) fprintf(bcftools_stderr, "Hap file: %s\n", hap_fname); + if (legend_fname) fprintf(bcftools_stderr, "Legend file: %s\n", legend_fname); + if (sample_fname) fprintf(bcftools_stderr, "Sample file: %s\n", sample_fname); // write samples file - if (sample_fname) { + if (sample_fname) + { + char *sample2sex = NULL; + if ( args->sex_fname ) sample2sex = init_sample2sex(args->header,args->sex_fname); + int i; BGZF *sout = bgzf_open(sample_fname, sample_compressed ? "wg" : "wu"); str.l = 0; @@ -841,12 +883,13 @@ static void vcf_to_haplegendsample(args_t *args) for (i=0; iheader); i++) { str.l = 0; - ksprintf(&str, "%s %s %s 2\n", args->header->samples[i], args->header->samples[i], args->header->samples[i]); + ksprintf(&str, "%s %s %s %c\n", args->header->samples[i], args->header->samples[i], args->header->samples[i], sample2sex ? sample2sex[i] : '2'); ret = bgzf_write(sout, str.s, str.l); if ( ret != str.l ) error("Error writing %s: %s\n", sample_fname, strerror(errno)); } if ( bgzf_close(sout)!=0 ) error("Error closing %s: %s\n", sample_fname, strerror(errno)); free(sample_fname); + free(sample2sex); } if (!hap_fname && !legend_fname) { if ( str.m ) free(str.s); @@ -855,6 +898,7 @@ static void vcf_to_haplegendsample(args_t *args) // open haps and legend outputs BGZF *hout = hap_fname ? bgzf_open(hap_fname, hap_compressed ? "wg" : "wu") : NULL; + if ( hap_compressed && args->n_threads ) bgzf_thread_pool(hout, args->files->p->pool, args->files->p->qsize); BGZF *lout = legend_fname ? bgzf_open(legend_fname, legend_compressed ? "wg" : "wu") : NULL; if (legend_fname) { str.l = 0; @@ -879,7 +923,7 @@ static void vcf_to_haplegendsample(args_t *args) // biallelic required if ( line->n_allele>2 ) { if (!non_biallelic) - fprintf(pysam_stderr, "Warning: non-biallelic records are skipped. Consider splitting multi-allelic records into biallelic records using 'bcftools norm -m-'.\n"); + fprintf(bcftools_stderr, "Warning: non-biallelic records are skipped. Consider splitting multi-allelic records into biallelic records using 'bcftools norm -m-'.\n"); non_biallelic++; continue; } @@ -906,7 +950,7 @@ static void vcf_to_haplegendsample(args_t *args) } nok++; } - fprintf(pysam_stderr, "%d records written, %d skipped: %d/%d/%d no-ALT/non-biallelic/filtered\n", nok,no_alt+non_biallelic+filtered, no_alt, non_biallelic, filtered); + fprintf(bcftools_stderr, "%d records written, %d skipped: %d/%d/%d no-ALT/non-biallelic/filtered\n", nok,no_alt+non_biallelic+filtered, no_alt, non_biallelic, filtered); if ( str.m ) free(str.s); if ( hout && bgzf_close(hout)!=0 ) error("Error closing %s: %s\n", hap_fname, strerror(errno)); if ( lout && bgzf_close(lout)!=0 ) error("Error closing %s: %s\n", legend_fname, strerror(errno)); @@ -942,7 +986,7 @@ static void vcf_to_hapsample(args_t *args) char *hap_fname = NULL, *sample_fname = NULL; str.l = 0; kputs(args->outfname,&str); - int n_files, i; + int n_files = 0, i; char **files = hts_readlist(str.s, 0, &n_files); if ( n_files==1 ) { @@ -968,26 +1012,34 @@ static void vcf_to_hapsample(args_t *args) if ( hap_fname && (strlen(hap_fname)<3 || strcasecmp(".gz",hap_fname+strlen(hap_fname)-3)) ) hap_compressed = 0; if ( sample_fname && strlen(sample_fname)>3 && strcasecmp(".gz",sample_fname+strlen(sample_fname)-3)==0 ) sample_compressed = 0; - if (hap_fname) fprintf(pysam_stderr, "Haps file: %s\n", hap_fname); - if (sample_fname) fprintf(pysam_stderr, "Sample file: %s\n", sample_fname); + if (hap_fname) fprintf(bcftools_stderr, "Hap file: %s\n", hap_fname); + if (sample_fname) fprintf(bcftools_stderr, "Sample file: %s\n", sample_fname); // write samples file - if (sample_fname) { + if (sample_fname) + { + char *sample2sex = NULL; + if ( args->sex_fname ) sample2sex = init_sample2sex(args->header,args->sex_fname); + int i; BGZF *sout = bgzf_open(sample_fname, sample_compressed ? "wg" : "wu"); str.l = 0; - kputs("ID_1 ID_2 missing\n0 0 0\n", &str); + kputs(sample2sex ? "ID_1 ID_2 missing sex\n0 0 0 0\n" : "ID_1 ID_2 missing\n0 0 0\n", &str); ret = bgzf_write(sout, str.s, str.l); if ( ret != str.l ) error("Error writing %s: %s\n", sample_fname, strerror(errno)); for (i=0; iheader); i++) { str.l = 0; - ksprintf(&str, "%s %s 0\n", args->header->samples[i], args->header->samples[i]); + if ( sample2sex ) + ksprintf(&str, "%s %s 0 %c\n", args->header->samples[i],args->header->samples[i],sample2sex[i]); + else + ksprintf(&str, "%s %s 0\n", args->header->samples[i],args->header->samples[i]); ret = bgzf_write(sout, str.s, str.l); if ( ret != str.l ) error("Error writing %s: %s\n", sample_fname, strerror(errno)); } if ( bgzf_close(sout)!=0 ) error("Error closing %s: %s\n", sample_fname, strerror(errno)); free(sample_fname); + free(sample2sex); } if (!hap_fname) { if ( str.m ) free(str.s); @@ -996,6 +1048,7 @@ static void vcf_to_hapsample(args_t *args) // open haps output BGZF *hout = hap_fname ? bgzf_open(hap_fname, hap_compressed ? "wg" : "wu") : NULL; + if ( hap_compressed && args->n_threads ) bgzf_thread_pool(hout, args->files->p->pool, args->files->p->qsize); int no_alt = 0, non_biallelic = 0, filtered = 0, nok = 0; while ( bcf_sr_next_line(args->files) ) @@ -1013,7 +1066,7 @@ static void vcf_to_hapsample(args_t *args) // biallelic required if ( line->n_allele>2 ) { if (!non_biallelic) - fprintf(pysam_stderr, "Warning: non-biallelic records are skipped. Consider splitting multi-allelic records into biallelic records using 'bcftools norm -m-'.\n"); + fprintf(bcftools_stderr, "Warning: non-biallelic records are skipped. Consider splitting multi-allelic records into biallelic records using 'bcftools norm -m-'.\n"); non_biallelic++; continue; } @@ -1029,7 +1082,7 @@ static void vcf_to_hapsample(args_t *args) } nok++; } - fprintf(pysam_stderr, "%d records written, %d skipped: %d/%d/%d no-ALT/non-biallelic/filtered\n", nok, no_alt+non_biallelic+filtered, no_alt, non_biallelic, filtered); + fprintf(bcftools_stderr, "%d records written, %d skipped: %d/%d/%d no-ALT/non-biallelic/filtered\n", nok, no_alt+non_biallelic+filtered, no_alt, non_biallelic, filtered); if ( str.m ) free(str.s); if ( hout && bgzf_close(hout)!=0 ) error("Error closing %s: %s\n", hap_fname, strerror(errno)); if (hap_fname) free(hap_fname); @@ -1197,13 +1250,13 @@ static void tsv_to_vcf(args_t *args) free(args->str.s); free(args->gts); - fprintf(pysam_stderr,"Rows total: \t%d\n", args->n.total); - fprintf(pysam_stderr,"Rows skipped: \t%d\n", args->n.skipped); - fprintf(pysam_stderr,"Missing GTs: \t%d\n", args->n.missing); - fprintf(pysam_stderr,"Hom RR: \t%d\n", args->n.hom_rr); - fprintf(pysam_stderr,"Het RA: \t%d\n", args->n.het_ra); - fprintf(pysam_stderr,"Hom AA: \t%d\n", args->n.hom_aa); - fprintf(pysam_stderr,"Het AA: \t%d\n", args->n.het_aa); + fprintf(bcftools_stderr,"Rows total: \t%d\n", args->n.total); + fprintf(bcftools_stderr,"Rows skipped: \t%d\n", args->n.skipped); + fprintf(bcftools_stderr,"Missing GTs: \t%d\n", args->n.missing); + fprintf(bcftools_stderr,"Hom RR: \t%d\n", args->n.hom_rr); + fprintf(bcftools_stderr,"Het RA: \t%d\n", args->n.het_ra); + fprintf(bcftools_stderr,"Hom AA: \t%d\n", args->n.hom_aa); + fprintf(bcftools_stderr,"Het AA: \t%d\n", args->n.het_aa); } static void vcf_to_vcf(args_t *args) @@ -1258,9 +1311,31 @@ static void gvcf_to_vcf(args_t *args) if ( !pass ) continue; } - if ( line->n_allele!=1 || !bcf_has_filter(hdr,line,"PASS") ) + if (!bcf_has_filter(hdr,line,"PASS")) + { + bcf_write(out_fh,hdr,line); + continue; + } + + // check if alleles compatible with being a gVCF record + // ALT must be one of ., <*>, , + // check for INFO/END is below + int i, gallele = -1; + if (line->n_allele==1) + gallele = 0; // illumina/bcftools-call gvcf (if INFO/END present) + else if ( line->d.allele[1][0]=='<' ) + { + for (i=1; in_allele; i++) + { + if ( line->d.allele[i][1]=='*' && line->d.allele[i][2]=='>' && line->d.allele[i][3]=='\0' ) { gallele = i; break; } // mpileup/spec compliant gVCF + if ( line->d.allele[i][1]=='X' && line->d.allele[i][2]=='>' && line->d.allele[i][3]=='\0' ) { gallele = i; break; } // old mpileup gVCF + if ( strcmp(line->d.allele[i],"")==0 ) { gallele = i; break; } // GATK gVCF + } + } + + // no gVCF compatible alleles + if (gallele<0) { - // Assuming that only ALT=. sites can be blocks and skipping sites which don't PASS bcf_write(out_fh,hdr,line); continue; } @@ -1268,7 +1343,7 @@ static void gvcf_to_vcf(args_t *args) int nend = bcf_get_info_int32(hdr,line,"END",&itmp,&nitmp); if ( nend!=1 ) { - // No END lineord + // No INFO/END => not gVCF record bcf_write(out_fh,hdr,line); continue; } @@ -1279,10 +1354,9 @@ static void gvcf_to_vcf(args_t *args) line->pos = pos; char *ref = faidx_fetch_seq(args->ref, (char*)bcf_hdr_id2name(hdr,line->rid), line->pos, line->pos, &len); if ( !ref ) error("faidx_fetch_seq failed at %s:%d\n", bcf_hdr_id2name(hdr,line->rid), line->pos+1); - // we have already checked above that there is only one allele, - // so fine to just update alleles with the ref allele from the fasta - bcf_update_alleles_str(hdr, line, &ref[0]); + strncpy(line->d.allele[0],ref,len); bcf_write(out_fh,hdr,line); + free(ref); } } free(itmp); @@ -1291,66 +1365,69 @@ static void gvcf_to_vcf(args_t *args) static void usage(void) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Converts VCF/BCF to other formats and back. See man page for file\n"); - fprintf(pysam_stderr, " formats details. When specifying output files explicitly instead\n"); - fprintf(pysam_stderr, " of with , one can use '-' for pysam_stdout and '.' to suppress.\n"); - fprintf(pysam_stderr, "Usage: bcftools convert [OPTIONS] \n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "VCF input options:\n"); - fprintf(pysam_stderr, " -e, --exclude exclude sites for which the expression is true\n"); - fprintf(pysam_stderr, " -i, --include select sites for which the expression is true\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " -s, --samples list of samples to include\n"); - fprintf(pysam_stderr, " -S, --samples-file file of samples to include\n"); - fprintf(pysam_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "VCF output options:\n"); - fprintf(pysam_stderr, " --no-version do not append version and command line to the header\n"); - fprintf(pysam_stderr, " -o, --output output file name [pysam_stdout]\n"); - fprintf(pysam_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); - fprintf(pysam_stderr, " --threads number of extra output compression threads [0]\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "GEN/SAMPLE conversion (input/output from IMPUTE2):\n"); - fprintf(pysam_stderr, " -G, --gensample2vcf <...> |,\n"); - fprintf(pysam_stderr, " -g, --gensample <...> |,\n"); - fprintf(pysam_stderr, " --tag tag to take values for .gen file: GT,PL,GL,GP [GT]\n"); - fprintf(pysam_stderr, " --chrom output chromosome in first column instead of CHROM:POS_REF_ALT\n"); - fprintf(pysam_stderr, " --vcf-ids output VCF IDs in second column instead of CHROM:POS_REF_ALT\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "gVCF conversion:\n"); - fprintf(pysam_stderr, " --gvcf2vcf expand gVCF reference blocks\n"); - fprintf(pysam_stderr, " -f, --fasta-ref reference sequence in fasta format\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "HAP/SAMPLE conversion (output from SHAPEIT):\n"); - fprintf(pysam_stderr, " --hapsample2vcf <...> |,\n"); - fprintf(pysam_stderr, " --hapsample <...> |,\n"); - fprintf(pysam_stderr, " --haploid2diploid convert haploid genotypes to diploid homozygotes\n"); - fprintf(pysam_stderr, " --vcf-ids output VCF IDs instead of CHROM:POS_REF_ALT\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "HAP/LEGEND/SAMPLE conversion:\n"); - fprintf(pysam_stderr, " -H, --haplegendsample2vcf <...> |,,\n"); - fprintf(pysam_stderr, " -h, --haplegendsample <...> |,,\n"); - fprintf(pysam_stderr, " --haploid2diploid convert haploid genotypes to diploid homozygotes\n"); - fprintf(pysam_stderr, " --vcf-ids output VCF IDs instead of CHROM:POS_REF_ALT\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "TSV conversion:\n"); - fprintf(pysam_stderr, " --tsv2vcf \n"); - fprintf(pysam_stderr, " -c, --columns columns of the input tsv file [ID,CHROM,POS,AA]\n"); - fprintf(pysam_stderr, " -f, --fasta-ref reference sequence in fasta format\n"); - fprintf(pysam_stderr, " -s, --samples list of sample names\n"); - fprintf(pysam_stderr, " -S, --samples-file file of sample names\n"); - fprintf(pysam_stderr, "\n"); - // fprintf(pysam_stderr, "PLINK options:\n"); - // fprintf(pysam_stderr, " -p, --plink |,,|,,|,\n"); - // fprintf(pysam_stderr, " --tped make tped file instead\n"); - // fprintf(pysam_stderr, " --bin make binary bed/fam/bim files\n"); - // fprintf(pysam_stderr, "\n"); - // fprintf(pysam_stderr, "PBWT options:\n"); - // fprintf(pysam_stderr, " -b, --pbwt or ,,,\n"); - // fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Converts VCF/BCF to other formats and back. See man page for file\n"); + fprintf(bcftools_stderr, " formats details. When specifying output files explicitly instead\n"); + fprintf(bcftools_stderr, " of with , one can use '-' for bcftools_stdout and '.' to suppress.\n"); + fprintf(bcftools_stderr, "Usage: bcftools convert [OPTIONS] \n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "VCF input options:\n"); + fprintf(bcftools_stderr, " -e, --exclude exclude sites for which the expression is true\n"); + fprintf(bcftools_stderr, " -i, --include select sites for which the expression is true\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " -s, --samples list of samples to include\n"); + fprintf(bcftools_stderr, " -S, --samples-file file of samples to include\n"); + fprintf(bcftools_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "VCF output options:\n"); + fprintf(bcftools_stderr, " --no-version do not append version and command line to the header\n"); + fprintf(bcftools_stderr, " -o, --output output file name [bcftools_stdout]\n"); + fprintf(bcftools_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); + fprintf(bcftools_stderr, " --threads number of extra output compression threads [0]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "GEN/SAMPLE conversion (input/output from IMPUTE2):\n"); + fprintf(bcftools_stderr, " -G, --gensample2vcf <...> |,\n"); + fprintf(bcftools_stderr, " -g, --gensample <...> |,\n"); + fprintf(bcftools_stderr, " --tag tag to take values for .gen file: GT,PL,GL,GP [GT]\n"); + fprintf(bcftools_stderr, " --chrom output chromosome in first column instead of CHROM:POS_REF_ALT\n"); + fprintf(bcftools_stderr, " --sex output sex column in the sample-file, input format is: Sample\\t[MF]\n"); + fprintf(bcftools_stderr, " --vcf-ids output VCF IDs in second column instead of CHROM:POS_REF_ALT\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "gVCF conversion:\n"); + fprintf(bcftools_stderr, " --gvcf2vcf expand gVCF reference blocks\n"); + fprintf(bcftools_stderr, " -f, --fasta-ref reference sequence in fasta format\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "HAP/SAMPLE conversion (output from SHAPEIT):\n"); + fprintf(bcftools_stderr, " --hapsample2vcf <...> |,\n"); + fprintf(bcftools_stderr, " --hapsample <...> |,\n"); + fprintf(bcftools_stderr, " --haploid2diploid convert haploid genotypes to diploid homozygotes\n"); + fprintf(bcftools_stderr, " --sex output sex column in the sample-file, input format is: Sample\\t[MF]\n"); + fprintf(bcftools_stderr, " --vcf-ids output VCF IDs instead of CHROM:POS_REF_ALT\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "HAP/LEGEND/SAMPLE conversion:\n"); + fprintf(bcftools_stderr, " -H, --haplegendsample2vcf <...> |,,\n"); + fprintf(bcftools_stderr, " -h, --haplegendsample <...> |,,\n"); + fprintf(bcftools_stderr, " --haploid2diploid convert haploid genotypes to diploid homozygotes\n"); + fprintf(bcftools_stderr, " --sex output sex column in the sample-file, input format is: Sample\\t[MF]\n"); + fprintf(bcftools_stderr, " --vcf-ids output VCF IDs instead of CHROM:POS_REF_ALT\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "TSV conversion:\n"); + fprintf(bcftools_stderr, " --tsv2vcf \n"); + fprintf(bcftools_stderr, " -c, --columns columns of the input tsv file [ID,CHROM,POS,AA]\n"); + fprintf(bcftools_stderr, " -f, --fasta-ref reference sequence in fasta format\n"); + fprintf(bcftools_stderr, " -s, --samples list of sample names\n"); + fprintf(bcftools_stderr, " -S, --samples-file file of sample names\n"); + fprintf(bcftools_stderr, "\n"); + // fprintf(bcftools_stderr, "PLINK options:\n"); + // fprintf(bcftools_stderr, " -p, --plink |,,|,,|,\n"); + // fprintf(bcftools_stderr, " --tped make tped file instead\n"); + // fprintf(bcftools_stderr, " --bin make binary bed/fam/bim files\n"); + // fprintf(bcftools_stderr, "\n"); + // fprintf(bcftools_stderr, "PBWT options:\n"); + // fprintf(bcftools_stderr, " -b, --pbwt or ,,,\n"); + // fprintf(bcftools_stderr, "\n"); exit(1); } @@ -1377,6 +1454,7 @@ int main_vcfconvert(int argc, char *argv[]) {"targets-file",required_argument,NULL,'T'}, {"samples",required_argument,NULL,'s'}, {"samples-file",required_argument,NULL,'S'}, + {"sex",required_argument,NULL,11}, {"gensample",required_argument,NULL,'g'}, {"gensample2vcf",required_argument,NULL,'G'}, {"tag",required_argument,NULL,1}, @@ -1430,6 +1508,7 @@ int main_vcfconvert(int argc, char *argv[]) case 'h': args->convert_func = vcf_to_haplegendsample; args->outfname = optarg; break; case 9 : args->n_threads = strtol(optarg, 0, 0); break; case 10 : args->record_cmd_line = 0; break; + case 11 : args->sex_fname = optarg; break; case '?': usage(); default: error("Unknown argument: %s\n", optarg); } diff --git a/bcftools/vcffilter.c b/bcftools/vcffilter.c index f979d77f3..c1b41f293 100644 --- a/bcftools/vcffilter.c +++ b/bcftools/vcffilter.c @@ -129,7 +129,8 @@ static void init_data(args_t *args) if ( tmp.s ) kputs(" and ", &tmp); kputs("\"IndelGap\"", &tmp); } - fprintf(stderr,"Warning: using %s filter name instead of \"%s\"\n", tmp.s,args->soft_filter); + if ( strncmp(tmp.s+1,args->soft_filter,tmp.l-2) ) + fprintf(stderr,"Warning: using %s filter name instead of \"%s\"\n", tmp.s,args->soft_filter); free(tmp.s); } diff --git a/bcftools/vcffilter.c.pysam.c b/bcftools/vcffilter.c.pysam.c index 58193daf1..f7d0a4765 100644 --- a/bcftools/vcffilter.c.pysam.c +++ b/bcftools/vcffilter.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcffilter.c -- Apply fixed-threshold filters. @@ -131,7 +131,8 @@ static void init_data(args_t *args) if ( tmp.s ) kputs(" and ", &tmp); kputs("\"IndelGap\"", &tmp); } - fprintf(pysam_stderr,"Warning: using %s filter name instead of \"%s\"\n", tmp.s,args->soft_filter); + if ( strncmp(tmp.s+1,args->soft_filter,tmp.l-2) ) + fprintf(bcftools_stderr,"Warning: using %s filter name instead of \"%s\"\n", tmp.s,args->soft_filter); free(tmp.s); } @@ -400,27 +401,27 @@ static void set_genotypes(args_t *args, bcf1_t *line, int pass_site) static void usage(args_t *args) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Apply fixed-threshold filters.\n"); - fprintf(pysam_stderr, "Usage: bcftools filter [options] \n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Options:\n"); - fprintf(pysam_stderr, " -e, --exclude exclude sites for which the expression is true (see man page for details)\n"); - fprintf(pysam_stderr, " -g, --SnpGap filter SNPs within base pairs of an indel\n"); - fprintf(pysam_stderr, " -G, --IndelGap filter clusters of indels separated by or fewer base pairs allowing only one to pass\n"); - fprintf(pysam_stderr, " -i, --include include only sites for which the expression is true (see man page for details\n"); - fprintf(pysam_stderr, " -m, --mode [+x] \"+\": do not replace but add to existing FILTER; \"x\": reset filters at sites which pass\n"); - fprintf(pysam_stderr, " --no-version do not append version and command line to the header\n"); - fprintf(pysam_stderr, " -o, --output write output to a file [standard output]\n"); - fprintf(pysam_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " -s, --soft-filter annotate FILTER column with or unique filter name (\"Filter%%d\") made up by the program (\"+\")\n"); - fprintf(pysam_stderr, " -S, --set-GTs <.|0> set genotypes of failed samples to missing (.) or ref (0)\n"); - fprintf(pysam_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " --threads number of extra output compression threads [0]\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Apply fixed-threshold filters.\n"); + fprintf(bcftools_stderr, "Usage: bcftools filter [options] \n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Options:\n"); + fprintf(bcftools_stderr, " -e, --exclude exclude sites for which the expression is true (see man page for details)\n"); + fprintf(bcftools_stderr, " -g, --SnpGap filter SNPs within base pairs of an indel\n"); + fprintf(bcftools_stderr, " -G, --IndelGap filter clusters of indels separated by or fewer base pairs allowing only one to pass\n"); + fprintf(bcftools_stderr, " -i, --include include only sites for which the expression is true (see man page for details\n"); + fprintf(bcftools_stderr, " -m, --mode [+x] \"+\": do not replace but add to existing FILTER; \"x\": reset filters at sites which pass\n"); + fprintf(bcftools_stderr, " --no-version do not append version and command line to the header\n"); + fprintf(bcftools_stderr, " -o, --output write output to a file [standard output]\n"); + fprintf(bcftools_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " -s, --soft-filter annotate FILTER column with or unique filter name (\"Filter%%d\") made up by the program (\"+\")\n"); + fprintf(bcftools_stderr, " -S, --set-GTs <.|0> set genotypes of failed samples to missing (.) or ref (0)\n"); + fprintf(bcftools_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " --threads number of extra output compression threads [0]\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } diff --git a/bcftools/vcfgtcheck.c b/bcftools/vcfgtcheck.c index b741ef6be..c4d77e19c 100644 --- a/bcftools/vcfgtcheck.c +++ b/bcftools/vcfgtcheck.c @@ -1,6 +1,6 @@ /* vcfgtcheck.c -- Check sample identity. - Copyright (C) 2013-2014 Genome Research Ltd. + Copyright (C) 2013-2018 Genome Research Ltd. Author: Petr Danecek @@ -35,7 +35,9 @@ THE SOFTWARE. */ #include #include #include +#include #include "bcftools.h" +#include "hclust.h" typedef struct { @@ -43,10 +45,10 @@ typedef struct bcf_hdr_t *gt_hdr, *sm_hdr; // VCF with genotypes to compare against and the query VCF int ntmp_arr, npl_arr; int32_t *tmp_arr, *pl_arr; - double *lks, *sites; + double *lks, *sites, min_inter_err, max_intra_err; int *cnts, *dps, hom_only, cross_check, all_sites; char *cwd, **argv, *gt_fname, *plot, *query_sample, *target_sample; - int argc, no_PLs; + int argc, no_PLs, narr, nsmpl; } args_t; @@ -79,7 +81,7 @@ static void plot_check(args_t *args, char *target_sample, char *query_sample) "sample_ids = False\n" "\n" "dat = []\n" - "with open('%s.tab', 'rb') as f:\n" + "with open('%s.tab', 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " for row in reader:\n" " if row[0][0]=='#': continue\n" @@ -133,6 +135,7 @@ static void plot_check(args_t *args, char *target_sample, char *query_sample) free(fname); } +#if 0 static void plot_cross_check(args_t *args) { char *fname; @@ -150,7 +153,7 @@ static void plot_cross_check(args_t *args) "dat = None\n" "min = None\n" "max = None\n" - "with open('%s.tab', 'rb') as f:\n" + "with open('%s.tab', 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " i = 0\n" " for row in reader:\n" @@ -214,6 +217,7 @@ static void plot_cross_check(args_t *args) py_plot(fname); free(fname); } +#endif static void init_data(args_t *args) { @@ -230,14 +234,6 @@ static void init_data(args_t *args) args->sites = (double*) calloc(nsamples,sizeof(double)); args->dps = (int*) calloc(nsamples,sizeof(int)); } - else - { - int nsamples = bcf_hdr_nsamples(args->sm_hdr); - int narr = (nsamples-1)*nsamples/2; - args->lks = (double*) calloc(narr,sizeof(double)); - args->cnts = (int*) calloc(narr,sizeof(int)); - args->dps = (int*) calloc(narr,sizeof(int)); - } } static void destroy_data(args_t *args) @@ -524,177 +520,181 @@ static void check_gt(args_t *args) } } -static inline int is_hom_most_likely(int nals, int *pls) +// static inline int is_hom_most_likely(int nals, int *pls) +// { +// int ia, ib, idx = 1, min_is_hom = 1, min_pl = pls[0]; +// for (ia=1; iasm_hdr, line, &args->tmp_arr, &args->ntmp_arr); + + if ( ngt<=0 ) return 1; // GT not present + if ( ngt!=args->nsmpl*2 ) return 2; // not diploid + ngt /= args->nsmpl; + + int i,j, idx = 0; + for (i=1; insmpl; i++) + { + int32_t *a = args->tmp_arr + i*ngt; + if ( bcf_gt_is_missing(a[0]) || bcf_gt_is_missing(a[1]) || a[1]==bcf_int32_vector_end ) { idx+=i; continue; } + int agt = 1<tmp_arr + j*ngt; + if ( bcf_gt_is_missing(b[0]) || bcf_gt_is_missing(b[1]) || b[1]==bcf_int32_vector_end ) { idx++; continue; } + int bgt = 1<sm_hdr, line, "PL", &args->tmp_arr, &args->ntmp_arr); + + if ( npl<=0 ) return 1; // PL not present + npl /= args->nsmpl; + + int i,j,k, idx = 0; + for (i=1; insmpl; i++) { - for (ib=0; ibtmp_arr + i*npl; + int imin = -1; + for (k=0; k a[k] ) imin = k; + } + if ( imin<0 ) { idx+=i; continue; } + + for (j=0; jtmp_arr + j*npl; + int jmin = -1; + for (k=0; k b[k] ) jmin = k; + } + if ( jmin<0 ) { idx++; continue; } + + ntot[idx]++; + if ( imin!=jmin ) ndif[idx]++; idx++; } - if ( pls[idx] < min_pl ) { min_pl = pls[idx]; min_is_hom = 1; } - idx++; } - return min_is_hom; + return 0; } static void cross_check_gts(args_t *args) { - int nsamples = bcf_hdr_nsamples(args->sm_hdr), ndp_arr = 0; - unsigned int *dp = (unsigned int*) calloc(nsamples,sizeof(unsigned int)), *ndp = (unsigned int*) calloc(nsamples,sizeof(unsigned int)); // this will overflow one day... - int fake_pls = args->no_PLs, ignore_dp = 0; - - int i,j,k,idx, pl_warned = 0, dp_warned = 0; - int32_t *dp_arr = NULL; - int *is_hom = args->hom_only ? (int*) malloc(sizeof(int)*nsamples) : NULL; + // Initialize things: check which tags are defined in the header, sample names etc. if ( bcf_hdr_id2int(args->sm_hdr, BCF_DT_ID, "PL")<0 ) { if ( bcf_hdr_id2int(args->sm_hdr, BCF_DT_ID, "GT")<0 ) error("[E::%s] Neither PL nor GT present in the header of %s\n", __func__, args->files->readers[0].fname); - if ( !args->no_PLs ) + if ( !args->no_PLs ) { fprintf(stderr,"Warning: PL not present in the header of %s, using GT instead\n", args->files->readers[0].fname); - fake_pls = 1; + args->no_PLs = 99; + } } - if ( bcf_hdr_id2int(args->sm_hdr, BCF_DT_ID, "DP")<0 ) ignore_dp = 1; - FILE *fp = args->plot ? open_file(NULL, "w", "%s.tab", args->plot) : stdout; - print_header(args, fp); - if ( args->all_sites ) fprintf(fp,"# [1]SD, Average Site Discordance\t[2]Chromosome\t[3]Position\t[4]Number of available pairs\t[5]Average discordance\n"); + args->nsmpl = bcf_hdr_nsamples(args->sm_hdr); + args->narr = (args->nsmpl-1)*args->nsmpl/2; + + uint32_t *ndif = (uint32_t*) calloc(args->narr,4); + uint32_t *ntot = (uint32_t*) calloc(args->narr,4); while ( bcf_sr_next_line(args->files) ) { - bcf1_t *line = args->files->readers[0].buffer[0]; - bcf_unpack(line, BCF_UN_FMT); - - int npl; - if ( !fake_pls ) - { - npl = bcf_get_format_int32(args->sm_hdr, line, "PL", &args->pl_arr, &args->npl_arr); - if ( npl<=0 ) { pl_warned++; continue; } - npl /= nsamples; - } - else - npl = fake_PLs(args, args->sm_hdr, line); - int mdp = 0; - if ( !ignore_dp && (mdp=bcf_get_format_int32(args->sm_hdr, line, "DP", &dp_arr, &ndp_arr)) <= 0 ) dp_warned++; + bcf1_t *line = bcf_sr_get_line(args->files,0); - if ( args->hom_only ) + // use PLs unless no_PLs is set and GT exists + if ( args->no_PLs ) { - for (i=0; in_allele, args->pl_arr+i*npl); + if ( process_GT(args,line,ntot,ndif)==0 ) continue; } - - double sum = 0; int nsum = 0; - idx = 0; - for (i=0; ipl_arr[i*npl]; - if ( *ipl==-1 ) { idx += i; continue; } // missing genotype - if ( mdp>0 && (dp_arr[i]==bcf_int32_missing || !dp_arr[i]) ) { idx += i; continue; } - if ( args->hom_only && !is_hom[i] ) { idx += i; continue; } - - for (j=0; jpl_arr[j*npl]; - if ( *jpl==-1 ) { idx++; continue; } // missing genotype - if ( mdp>0 && (dp_arr[j]==bcf_int32_missing || !dp_arr[j]) ) { idx++; continue; } - if ( args->hom_only && !is_hom[j] ) { idx++; continue; } - - int min_pl = INT_MAX; - for (k=0; k ipl[k]+jpl[k] ) min_pl = ipl[k]+jpl[k]; - } - if ( k!=npl ) { idx++; continue; } - - if ( args->all_sites ) { sum += min_pl; nsum++; } - args->lks[idx] += min_pl; - args->cnts[idx]++; - - if ( mdp>0 ) - { - args->dps[idx] += dp_arr[i] < dp_arr[j] ? dp_arr[i] : dp_arr[j]; - dp[i] += dp_arr[i]; ndp[i]++; - dp[j] += dp_arr[j]; ndp[j]++; - } - else - { - args->dps[idx]++; - dp[i]++; ndp[i]++; - dp[j]++; ndp[j]++; - } - idx++; - } - } - if ( args->all_sites ) - fprintf(fp,"SD\t%s\t%d\t%d\t%.0f\n", args->sm_hdr->id[BCF_DT_CTG][line->rid].key, line->pos+1, nsum, nsum?sum/nsum:0); + process_PL(args,line,ntot,ndif); } - if ( dp_arr ) free(dp_arr); - if ( args->pl_arr ) free(args->pl_arr); - if ( args->tmp_arr ) free(args->tmp_arr); - if ( is_hom ) free(is_hom); + + FILE *fp = stdout; + print_header(args, fp); - if ( pl_warned ) fprintf(stderr, "[W::%s] PL was not found at %d site(s)\n", __func__, pl_warned); - if ( dp_warned ) fprintf(stderr, "[W::%s] DP was not found at %d site(s)\n", __func__, dp_warned); + float *tmp = (float*)malloc(sizeof(float)*args->nsmpl*(args->nsmpl-1)/2); - // Output samples sorted by average discordance - double *score = (double*) calloc(nsamples,sizeof(double)); - args->sites = (double*) calloc(nsamples,sizeof(double)); - idx = 0; - for (i=0; insmpl; i++) { for (j=0; jlks[idx]; - score[j] += args->lks[idx]; - args->sites[i] += args->cnts[idx]; - args->sites[j] += args->cnts[idx]; + float err = ntot[idx] ? (float)ndif[idx]/ntot[idx] : 1e-10; + fprintf(fp, "ERR\t%f\t%"PRId32"\t%s\t%s\n", err, ntot[idx],args->sm_hdr->samples[i],args->sm_hdr->samples[j]); + PDIST(tmp,i,j) = err; idx++; } } - for (i=0; isites[i] ) score[i] /= args->sites[i]; - double **p = (double**) malloc(sizeof(double*)*nsamples), avg_score = 0; - for (i=0; imax_intra_err; + hclust_t *clust = hclust_init(args->nsmpl,tmp); + cluster_t *list = hclust_create_list(clust,args->min_inter_err,&clust_max_err,&nlist); + fprintf(fp, "# CLUSTER\t[2]Maximum inter-cluster ERR\t[3-]List of samples\n"); + for (i=0; isites[idx]/(nsamples-1); - avg_score += score[idx]; - fprintf(fp, "SM\t%f\t%.2lf\t%.0lf\t%s\t%d\n", score[idx]*100., adp, nsites, args->sm_hdr->samples[idx],i); + fprintf(fp,"CLUSTER\t%f", list[i].dist); + for (j=0; jsm_hdr->samples[list[i].memb[j]]); + fprintf(fp,"\n"); } - - // // Overall score: maximum absolute deviation from the average score - // fprintf(fp, "# [1] MD\t[2]Maximum deviation\t[3]The culprit\n"); - // fprintf(fp, "MD\t%f\t%s\n", (score[idx] - avg_score/nsamples)*100., args->sm_hdr->samples[idx]); // idx still set - free(p); - free(score); - free(dp); - free(ndp); - - // Pairwise discordances + hclust_destroy_list(list,nlist); + // Debugging output: the cluster graph and data used for deciding + char **dbg = hclust_explain(clust,&nlist); + for (i=0; ism_hdr->samples,clust_max_err)); + hclust_destroy(clust); + free(tmp); + + + // Deprecated output for temporary backward compatibility + fprintf(fp, "# Warning: The CN block is deprecated and will be removed in future releases. Use ERR instead.\n"); fprintf(fp, "# [1]CN\t[2]Discordance\t[3]Number of sites\t[4]Average minimum depth\t[5]Sample i\t[6]Sample j\n"); idx = 0; - for (i=0; insmpl; i++) { for (j=0; jlks[idx], args->cnts[idx], args->cnts[idx]?(double)args->dps[idx]/args->cnts[idx]:0.0, - args->sm_hdr->samples[i],args->sm_hdr->samples[j]); + fprintf(fp, "CN\t%"PRId32"\t%"PRId32"\t0\t%s\t%s\n", ndif[idx], ntot[idx],args->sm_hdr->samples[i],args->sm_hdr->samples[j]); idx++; } } - fclose(fp); - if ( args->plot ) - plot_cross_check(args); + + free(ndif); + free(ntot); + free(args->tmp_arr); } static char *init_prefix(char *prefix) @@ -713,6 +713,7 @@ static void usage(void) fprintf(stderr, "\n"); fprintf(stderr, "Options:\n"); fprintf(stderr, " -a, --all-sites output comparison for all sites\n"); + fprintf(stderr, " -c, --cluster min inter- and max intra-sample error [0.23,-0.3]\n"); fprintf(stderr, " -g, --genotypes genotypes to compare against\n"); fprintf(stderr, " -G, --GTs-only use GTs, ignore PLs, using for unseen genotypes [99]\n"); fprintf(stderr, " -H, --homs-only homozygous genotypes only (useful for low coverage data)\n"); @@ -736,8 +737,16 @@ int main_vcfgtcheck(int argc, char *argv[]) char *regions = NULL, *targets = NULL; int regions_is_file = 0, targets_is_file = 0; + // In simulated sample swaps the minimum error was 0.3 and maximum intra-sample error was 0.23 + // - min_inter: pairs with smaller err value will be considered identical + // - max_intra: pairs with err value bigger than abs(max_intra_err) will be considered + // different. If negative, the cutoff may be heuristically lowered + args->min_inter_err = 0.23; + args->max_intra_err = -0.3; + static struct option loptions[] = { + {"cluster",1,0,'c'}, {"GTs-only",1,0,'G'}, {"all-sites",0,0,'a'}, {"homs-only",0,0,'H'}, @@ -753,8 +762,17 @@ int main_vcfgtcheck(int argc, char *argv[]) {0,0,0,0} }; char *tmp; - while ((c = getopt_long(argc, argv, "hg:p:s:S:Hr:R:at:T:G:",loptions,NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hg:p:s:S:Hr:R:at:T:G:c:",loptions,NULL)) >= 0) { switch (c) { + case 'c': + args->min_inter_err = strtod(optarg,&tmp); + if ( *tmp ) + { + if ( *tmp!=',') error("Could not parse: -c %s\n", optarg); + args->max_intra_err = strtod(tmp+1,&tmp); + if ( *tmp ) error("Could not parse: -c %s\n", optarg); + } + break; case 'G': args->no_PLs = strtol(optarg,&tmp,10); if ( *tmp ) error("Could not parse argument: --GTs-only %s\n", optarg); diff --git a/bcftools/vcfgtcheck.c.pysam.c b/bcftools/vcfgtcheck.c.pysam.c index 2f0a28847..462e4041d 100644 --- a/bcftools/vcfgtcheck.c.pysam.c +++ b/bcftools/vcfgtcheck.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfgtcheck.c -- Check sample identity. - Copyright (C) 2013-2014 Genome Research Ltd. + Copyright (C) 2013-2018 Genome Research Ltd. Author: Petr Danecek @@ -37,7 +37,9 @@ THE SOFTWARE. */ #include #include #include +#include #include "bcftools.h" +#include "hclust.h" typedef struct { @@ -45,10 +47,10 @@ typedef struct bcf_hdr_t *gt_hdr, *sm_hdr; // VCF with genotypes to compare against and the query VCF int ntmp_arr, npl_arr; int32_t *tmp_arr, *pl_arr; - double *lks, *sites; + double *lks, *sites, min_inter_err, max_intra_err; int *cnts, *dps, hom_only, cross_check, all_sites; char *cwd, **argv, *gt_fname, *plot, *query_sample, *target_sample; - int argc, no_PLs; + int argc, no_PLs, narr, nsmpl; } args_t; @@ -62,7 +64,7 @@ void py_plot(char *script) int len = strlen(script); char *cmd = !strcmp(".py",script+len-3) ? msprintf("python %s", script) : msprintf("python %s.py", script); int ret = system(cmd); - if ( ret ) fprintf(pysam_stderr, "The command returned non-zero status %d: %s\n", ret, cmd); + if ( ret ) fprintf(bcftools_stderr, "The command returned non-zero status %d: %s\n", ret, cmd); free(cmd); } @@ -81,7 +83,7 @@ static void plot_check(args_t *args, char *target_sample, char *query_sample) "sample_ids = False\n" "\n" "dat = []\n" - "with open('%s.tab', 'rb') as f:\n" + "with open('%s.tab', 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " for row in reader:\n" " if row[0][0]=='#': continue\n" @@ -135,6 +137,7 @@ static void plot_check(args_t *args, char *target_sample, char *query_sample) free(fname); } +#if 0 static void plot_cross_check(args_t *args) { char *fname; @@ -152,7 +155,7 @@ static void plot_cross_check(args_t *args) "dat = None\n" "min = None\n" "max = None\n" - "with open('%s.tab', 'rb') as f:\n" + "with open('%s.tab', 'r') as f:\n" " reader = csv.reader(f, 'tab')\n" " i = 0\n" " for row in reader:\n" @@ -216,6 +219,7 @@ static void plot_cross_check(args_t *args) py_plot(fname); free(fname); } +#endif static void init_data(args_t *args) { @@ -232,14 +236,6 @@ static void init_data(args_t *args) args->sites = (double*) calloc(nsamples,sizeof(double)); args->dps = (int*) calloc(nsamples,sizeof(int)); } - else - { - int nsamples = bcf_hdr_nsamples(args->sm_hdr); - int narr = (nsamples-1)*nsamples/2; - args->lks = (double*) calloc(narr,sizeof(double)); - args->cnts = (int*) calloc(narr,sizeof(int)); - args->dps = (int*) calloc(narr,sizeof(int)); - } } static void destroy_data(args_t *args) @@ -272,7 +268,7 @@ static int init_gt2ipl(args_t *args, bcf1_t *gt_line, bcf1_t *sm_line, int *gt2i gt2ipl[ bcf_ij2G(j,i) ] = k<=l ? bcf_ij2G(k,l) : bcf_ij2G(l,k); } } - //for (i=0; ism_hdr, BCF_DT_ID, "GT")<0 ) error("[E::%s] Neither PL nor GT present in the header of %s\n", __func__, args->files->readers[0].fname); if ( !args->no_PLs ) - fprintf(pysam_stderr,"Warning: PL not present in the header of %s, using GT instead\n", args->files->readers[0].fname); + fprintf(bcftools_stderr,"Warning: PL not present in the header of %s, using GT instead\n", args->files->readers[0].fname); fake_pls = 1; } - FILE *fp = args->plot ? open_file(NULL, "w", "%s.tab", args->plot) : pysam_stdout; + FILE *fp = args->plot ? open_file(NULL, "w", "%s.tab", args->plot) : bcftools_stdout; print_header(args, fp); int tgt_isample = -1, query_isample = 0; @@ -370,7 +366,7 @@ static void check_gt(args_t *args) { if ( tgt_isample==-1 ) { - fprintf(pysam_stderr,"No target sample selected for comparison, using the first sample in %s: %s\n", args->gt_fname,args->gt_hdr->samples[0]); + fprintf(bcftools_stderr,"No target sample selected for comparison, using the first sample in %s: %s\n", args->gt_fname,args->gt_hdr->samples[0]); tgt_isample = 0; } } @@ -526,177 +522,181 @@ static void check_gt(args_t *args) } } -static inline int is_hom_most_likely(int nals, int *pls) +// static inline int is_hom_most_likely(int nals, int *pls) +// { +// int ia, ib, idx = 1, min_is_hom = 1, min_pl = pls[0]; +// for (ia=1; iasm_hdr, line, &args->tmp_arr, &args->ntmp_arr); + + if ( ngt<=0 ) return 1; // GT not present + if ( ngt!=args->nsmpl*2 ) return 2; // not diploid + ngt /= args->nsmpl; + + int i,j, idx = 0; + for (i=1; insmpl; i++) { - for (ib=0; ibtmp_arr + i*ngt; + if ( bcf_gt_is_missing(a[0]) || bcf_gt_is_missing(a[1]) || a[1]==bcf_int32_vector_end ) { idx+=i; continue; } + int agt = 1<tmp_arr + j*ngt; + if ( bcf_gt_is_missing(b[0]) || bcf_gt_is_missing(b[1]) || b[1]==bcf_int32_vector_end ) { idx++; continue; } + int bgt = 1<sm_hdr, line, "PL", &args->tmp_arr, &args->ntmp_arr); + + if ( npl<=0 ) return 1; // PL not present + npl /= args->nsmpl; + + int i,j,k, idx = 0; + for (i=1; insmpl; i++) + { + int32_t *a = args->tmp_arr + i*npl; + int imin = -1; + for (k=0; k a[k] ) imin = k; + } + if ( imin<0 ) { idx+=i; continue; } + + for (j=0; jtmp_arr + j*npl; + int jmin = -1; + for (k=0; k b[k] ) jmin = k; + } + if ( jmin<0 ) { idx++; continue; } + + ntot[idx]++; + if ( imin!=jmin ) ndif[idx]++; + idx++; + } + } + return 0; } static void cross_check_gts(args_t *args) { - int nsamples = bcf_hdr_nsamples(args->sm_hdr), ndp_arr = 0; - unsigned int *dp = (unsigned int*) calloc(nsamples,sizeof(unsigned int)), *ndp = (unsigned int*) calloc(nsamples,sizeof(unsigned int)); // this will overflow one day... - int fake_pls = args->no_PLs, ignore_dp = 0; - - int i,j,k,idx, pl_warned = 0, dp_warned = 0; - int32_t *dp_arr = NULL; - int *is_hom = args->hom_only ? (int*) malloc(sizeof(int)*nsamples) : NULL; + // Initialize things: check which tags are defined in the header, sample names etc. if ( bcf_hdr_id2int(args->sm_hdr, BCF_DT_ID, "PL")<0 ) { if ( bcf_hdr_id2int(args->sm_hdr, BCF_DT_ID, "GT")<0 ) error("[E::%s] Neither PL nor GT present in the header of %s\n", __func__, args->files->readers[0].fname); - if ( !args->no_PLs ) - fprintf(pysam_stderr,"Warning: PL not present in the header of %s, using GT instead\n", args->files->readers[0].fname); - fake_pls = 1; + if ( !args->no_PLs ) { + fprintf(bcftools_stderr,"Warning: PL not present in the header of %s, using GT instead\n", args->files->readers[0].fname); + args->no_PLs = 99; + } } - if ( bcf_hdr_id2int(args->sm_hdr, BCF_DT_ID, "DP")<0 ) ignore_dp = 1; - FILE *fp = args->plot ? open_file(NULL, "w", "%s.tab", args->plot) : pysam_stdout; - print_header(args, fp); - if ( args->all_sites ) fprintf(fp,"# [1]SD, Average Site Discordance\t[2]Chromosome\t[3]Position\t[4]Number of available pairs\t[5]Average discordance\n"); + args->nsmpl = bcf_hdr_nsamples(args->sm_hdr); + args->narr = (args->nsmpl-1)*args->nsmpl/2; + + uint32_t *ndif = (uint32_t*) calloc(args->narr,4); + uint32_t *ntot = (uint32_t*) calloc(args->narr,4); while ( bcf_sr_next_line(args->files) ) { - bcf1_t *line = args->files->readers[0].buffer[0]; - bcf_unpack(line, BCF_UN_FMT); - - int npl; - if ( !fake_pls ) - { - npl = bcf_get_format_int32(args->sm_hdr, line, "PL", &args->pl_arr, &args->npl_arr); - if ( npl<=0 ) { pl_warned++; continue; } - npl /= nsamples; - } - else - npl = fake_PLs(args, args->sm_hdr, line); - int mdp = 0; - if ( !ignore_dp && (mdp=bcf_get_format_int32(args->sm_hdr, line, "DP", &dp_arr, &ndp_arr)) <= 0 ) dp_warned++; + bcf1_t *line = bcf_sr_get_line(args->files,0); - if ( args->hom_only ) + // use PLs unless no_PLs is set and GT exists + if ( args->no_PLs ) { - for (i=0; in_allele, args->pl_arr+i*npl); + if ( process_GT(args,line,ntot,ndif)==0 ) continue; } - - double sum = 0; int nsum = 0; - idx = 0; - for (i=0; ipl_arr[i*npl]; - if ( *ipl==-1 ) { idx += i; continue; } // missing genotype - if ( mdp>0 && (dp_arr[i]==bcf_int32_missing || !dp_arr[i]) ) { idx += i; continue; } - if ( args->hom_only && !is_hom[i] ) { idx += i; continue; } - - for (j=0; jpl_arr[j*npl]; - if ( *jpl==-1 ) { idx++; continue; } // missing genotype - if ( mdp>0 && (dp_arr[j]==bcf_int32_missing || !dp_arr[j]) ) { idx++; continue; } - if ( args->hom_only && !is_hom[j] ) { idx++; continue; } - - int min_pl = INT_MAX; - for (k=0; k ipl[k]+jpl[k] ) min_pl = ipl[k]+jpl[k]; - } - if ( k!=npl ) { idx++; continue; } - - if ( args->all_sites ) { sum += min_pl; nsum++; } - args->lks[idx] += min_pl; - args->cnts[idx]++; - - if ( mdp>0 ) - { - args->dps[idx] += dp_arr[i] < dp_arr[j] ? dp_arr[i] : dp_arr[j]; - dp[i] += dp_arr[i]; ndp[i]++; - dp[j] += dp_arr[j]; ndp[j]++; - } - else - { - args->dps[idx]++; - dp[i]++; ndp[i]++; - dp[j]++; ndp[j]++; - } - idx++; - } - } - if ( args->all_sites ) - fprintf(fp,"SD\t%s\t%d\t%d\t%.0f\n", args->sm_hdr->id[BCF_DT_CTG][line->rid].key, line->pos+1, nsum, nsum?sum/nsum:0); + process_PL(args,line,ntot,ndif); } - if ( dp_arr ) free(dp_arr); - if ( args->pl_arr ) free(args->pl_arr); - if ( args->tmp_arr ) free(args->tmp_arr); - if ( is_hom ) free(is_hom); + + FILE *fp = bcftools_stdout; + print_header(args, fp); - if ( pl_warned ) fprintf(pysam_stderr, "[W::%s] PL was not found at %d site(s)\n", __func__, pl_warned); - if ( dp_warned ) fprintf(pysam_stderr, "[W::%s] DP was not found at %d site(s)\n", __func__, dp_warned); + float *tmp = (float*)malloc(sizeof(float)*args->nsmpl*(args->nsmpl-1)/2); - // Output samples sorted by average discordance - double *score = (double*) calloc(nsamples,sizeof(double)); - args->sites = (double*) calloc(nsamples,sizeof(double)); - idx = 0; - for (i=0; insmpl; i++) { for (j=0; jlks[idx]; - score[j] += args->lks[idx]; - args->sites[i] += args->cnts[idx]; - args->sites[j] += args->cnts[idx]; + float err = ntot[idx] ? (float)ndif[idx]/ntot[idx] : 1e-10; + fprintf(fp, "ERR\t%f\t%"PRId32"\t%s\t%s\n", err, ntot[idx],args->sm_hdr->samples[i],args->sm_hdr->samples[j]); + PDIST(tmp,i,j) = err; idx++; } } - for (i=0; isites[i] ) score[i] /= args->sites[i]; - double **p = (double**) malloc(sizeof(double*)*nsamples), avg_score = 0; - for (i=0; imax_intra_err; + hclust_t *clust = hclust_init(args->nsmpl,tmp); + cluster_t *list = hclust_create_list(clust,args->min_inter_err,&clust_max_err,&nlist); + fprintf(fp, "# CLUSTER\t[2]Maximum inter-cluster ERR\t[3-]List of samples\n"); + for (i=0; isites[idx]/(nsamples-1); - avg_score += score[idx]; - fprintf(fp, "SM\t%f\t%.2lf\t%.0lf\t%s\t%d\n", score[idx]*100., adp, nsites, args->sm_hdr->samples[idx],i); + fprintf(fp,"CLUSTER\t%f", list[i].dist); + for (j=0; jsm_hdr->samples[list[i].memb[j]]); + fprintf(fp,"\n"); } - - // // Overall score: maximum absolute deviation from the average score - // fprintf(fp, "# [1] MD\t[2]Maximum deviation\t[3]The culprit\n"); - // fprintf(fp, "MD\t%f\t%s\n", (score[idx] - avg_score/nsamples)*100., args->sm_hdr->samples[idx]); // idx still set - free(p); - free(score); - free(dp); - free(ndp); - - // Pairwise discordances + hclust_destroy_list(list,nlist); + // Debugging output: the cluster graph and data used for deciding + char **dbg = hclust_explain(clust,&nlist); + for (i=0; ism_hdr->samples,clust_max_err)); + hclust_destroy(clust); + free(tmp); + + + // Deprecated output for temporary backward compatibility + fprintf(fp, "# Warning: The CN block is deprecated and will be removed in future releases. Use ERR instead.\n"); fprintf(fp, "# [1]CN\t[2]Discordance\t[3]Number of sites\t[4]Average minimum depth\t[5]Sample i\t[6]Sample j\n"); idx = 0; - for (i=0; insmpl; i++) { for (j=0; jlks[idx], args->cnts[idx], args->cnts[idx]?(double)args->dps[idx]/args->cnts[idx]:0.0, - args->sm_hdr->samples[i],args->sm_hdr->samples[j]); + fprintf(fp, "CN\t%"PRId32"\t%"PRId32"\t0\t%s\t%s\n", ndif[idx], ntot[idx],args->sm_hdr->samples[i],args->sm_hdr->samples[j]); idx++; } } - fclose(fp); - if ( args->plot ) - plot_cross_check(args); + + free(ndif); + free(ntot); + free(args->tmp_arr); } static char *init_prefix(char *prefix) @@ -709,23 +709,24 @@ static char *init_prefix(char *prefix) static void usage(void) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Check sample identity. With no -g BCF given, multi-sample cross-check is performed.\n"); - fprintf(pysam_stderr, "Usage: bcftools gtcheck [options] [-g ] \n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Options:\n"); - fprintf(pysam_stderr, " -a, --all-sites output comparison for all sites\n"); - fprintf(pysam_stderr, " -g, --genotypes genotypes to compare against\n"); - fprintf(pysam_stderr, " -G, --GTs-only use GTs, ignore PLs, using for unseen genotypes [99]\n"); - fprintf(pysam_stderr, " -H, --homs-only homozygous genotypes only (useful for low coverage data)\n"); - fprintf(pysam_stderr, " -p, --plot plot\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " -s, --query-sample query sample (by default the first sample is checked)\n"); - fprintf(pysam_stderr, " -S, --target-sample target sample in the -g file (used only for plotting)\n"); - fprintf(pysam_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Check sample identity. With no -g BCF given, multi-sample cross-check is performed.\n"); + fprintf(bcftools_stderr, "Usage: bcftools gtcheck [options] [-g ] \n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Options:\n"); + fprintf(bcftools_stderr, " -a, --all-sites output comparison for all sites\n"); + fprintf(bcftools_stderr, " -c, --cluster min inter- and max intra-sample error [0.23,-0.3]\n"); + fprintf(bcftools_stderr, " -g, --genotypes genotypes to compare against\n"); + fprintf(bcftools_stderr, " -G, --GTs-only use GTs, ignore PLs, using for unseen genotypes [99]\n"); + fprintf(bcftools_stderr, " -H, --homs-only homozygous genotypes only (useful for low coverage data)\n"); + fprintf(bcftools_stderr, " -p, --plot plot\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " -s, --query-sample query sample (by default the first sample is checked)\n"); + fprintf(bcftools_stderr, " -S, --target-sample target sample in the -g file (used only for plotting)\n"); + fprintf(bcftools_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } @@ -738,8 +739,16 @@ int main_vcfgtcheck(int argc, char *argv[]) char *regions = NULL, *targets = NULL; int regions_is_file = 0, targets_is_file = 0; + // In simulated sample swaps the minimum error was 0.3 and maximum intra-sample error was 0.23 + // - min_inter: pairs with smaller err value will be considered identical + // - max_intra: pairs with err value bigger than abs(max_intra_err) will be considered + // different. If negative, the cutoff may be heuristically lowered + args->min_inter_err = 0.23; + args->max_intra_err = -0.3; + static struct option loptions[] = { + {"cluster",1,0,'c'}, {"GTs-only",1,0,'G'}, {"all-sites",0,0,'a'}, {"homs-only",0,0,'H'}, @@ -755,8 +764,17 @@ int main_vcfgtcheck(int argc, char *argv[]) {0,0,0,0} }; char *tmp; - while ((c = getopt_long(argc, argv, "hg:p:s:S:Hr:R:at:T:G:",loptions,NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hg:p:s:S:Hr:R:at:T:G:c:",loptions,NULL)) >= 0) { switch (c) { + case 'c': + args->min_inter_err = strtod(optarg,&tmp); + if ( *tmp ) + { + if ( *tmp!=',') error("Could not parse: -c %s\n", optarg); + args->max_intra_err = strtod(tmp+1,&tmp); + if ( *tmp ) error("Could not parse: -c %s\n", optarg); + } + break; case 'G': args->no_PLs = strtol(optarg,&tmp,10); if ( *tmp ) error("Could not parse argument: --GTs-only %s\n", optarg); diff --git a/bcftools/vcfindex.c b/bcftools/vcfindex.c index d1e9179e4..807fedd5f 100644 --- a/bcftools/vcfindex.c +++ b/bcftools/vcfindex.c @@ -1,4 +1,3 @@ - /* vcfindex.c -- Index bgzip compressed VCF/BCF files for random access. Copyright (C) 2014-2016 Genome Research Ltd. @@ -32,6 +31,8 @@ DEALINGS IN THE SOFTWARE. */ #include #define __STDC_FORMAT_MACROS #include +#include +#include #include "bcftools.h" #define BCF_LIDX_SHIFT 14 @@ -43,24 +44,22 @@ static void usage(void) fprintf(stderr, "Usage: bcftools index [options] |\n"); fprintf(stderr, "\n"); fprintf(stderr, "Indexing options:\n"); - fprintf(stderr, " -c, --csi generate CSI-format index for VCF/BCF files [default]\n"); - fprintf(stderr, " -f, --force overwrite index if it already exists\n"); - fprintf(stderr, " -m, --min-shift INT set minimal interval size for CSI indices to 2^INT [14]\n"); - fprintf(stderr, " -t, --tbi generate TBI-format index for VCF files\n"); + fprintf(stderr, " -c, --csi generate CSI-format index for VCF/BCF files [default]\n"); + fprintf(stderr, " -f, --force overwrite index if it already exists\n"); + fprintf(stderr, " -m, --min-shift INT set minimal interval size for CSI indices to 2^INT [14]\n"); + fprintf(stderr, " -o, --output-file FILE optional output index file name\n"); + fprintf(stderr, " -t, --tbi generate TBI-format index for VCF files\n"); + fprintf(stderr, " --threads sets the number of threads [0]\n"); fprintf(stderr, "\n"); fprintf(stderr, "Stats options:\n"); fprintf(stderr, " -n, --nrecords print number of records based on existing index file\n"); - fprintf(stderr, " -s, --stats print per contig stats based on existing index file\n"); + fprintf(stderr, " -s, --stats print per contig stats based on existing index file\n"); fprintf(stderr, "\n"); exit(1); } int vcf_index_stats(char *fname, int stats) { - char *fn_out = NULL; - FILE *out; - out = fn_out ? fopen(fn_out, "w") : stdout; - const char **seq; int i, nseq; tbx_t *tbx = NULL; @@ -74,12 +73,12 @@ int vcf_index_stats(char *fname, int stats) if ( hts_get_format(fp)->format==vcf ) { tbx = tbx_index_load(fname); - if ( !tbx ) { fprintf(stderr,"Could not load TBI index: %s\n", fname); return 1; } + if ( !tbx ) { fprintf(stderr,"Could not load index for VCF: %s\n", fname); return 1; } } else if ( hts_get_format(fp)->format==bcf ) { idx = bcf_index_load(fname); - if ( !idx ) { fprintf(stderr,"Could not load CSI index: %s\n", fname); return 1; } + if ( !idx ) { fprintf(stderr,"Could not load index for BCF file: %s\n", fname); return 1; } } else { @@ -97,7 +96,7 @@ int vcf_index_stats(char *fname, int stats) if (stats&2 || !records) continue; bcf_hrec_t *hrec = bcf_hdr_get_hrec(hdr, BCF_HL_CTG, "ID", seq[i], NULL); int hkey = hrec ? bcf_hrec_find_key(hrec, "length") : -1; - fprintf(out,"%s\t%s\t%" PRIu64 "\n", seq[i], hkey<0?".":hrec->vals[hkey], records); + printf("%s\t%s\t%" PRIu64 "\n", seq[i], hkey<0?".":hrec->vals[hkey], records); } if (!sum) { @@ -106,14 +105,13 @@ int vcf_index_stats(char *fname, int stats) bcf1_t *rec = bcf_init1(); if (bcf_read1(fp, hdr, rec) >= 0) { - fprintf(stderr,"%s index of %s does not contain any count metadata. Please re-index with a newer version of bcftools or tabix.\n", tbx ? "TBI" : "CSI", fname); + fprintf(stderr,"index of %s does not contain any count metadata. Please re-index with a newer version of bcftools or tabix.\n", fname); return 1; } bcf_destroy1(rec); } - if (stats&2) fprintf(out, "%" PRIu64 "\n", sum); + if (stats&2) printf("%" PRIu64 "\n", sum); free(seq); - fclose(out); hts_close(fp); bcf_hdr_destroy(hdr); if (tbx) @@ -125,8 +123,9 @@ int vcf_index_stats(char *fname, int stats) int main_vcfindex(int argc, char *argv[]) { - int c, force = 0, tbi = 0, stats = 0; + int c, force = 0, tbi = 0, stats = 0, n_threads = 0; int min_shift = BCF_LIDX_SHIFT; + char *outfn = NULL; static struct option loptions[] = { @@ -136,27 +135,33 @@ int main_vcfindex(int argc, char *argv[]) {"min-shift",required_argument,NULL,'m'}, {"stats",no_argument,NULL,'s'}, {"nrecords",no_argument,NULL,'n'}, + {"threads",required_argument,NULL,9}, + {"output-file",required_argument,NULL,'o'}, {NULL, 0, NULL, 0} }; char *tmp; - while ((c = getopt_long(argc, argv, "ctfm:sn", loptions, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "ctfm:sno:", loptions, NULL)) >= 0) { switch (c) { case 'c': tbi = 0; break; case 't': tbi = 1; min_shift = 0; break; case 'f': force = 1; break; - case 'm': + case 'm': min_shift = strtol(optarg,&tmp,10); if ( *tmp ) error("Could not parse argument: --min-shift %s\n", optarg); break; case 's': stats |= 1; break; case 'n': stats |= 2; break; + case 9: + n_threads = strtol(optarg,&tmp,10); + if ( *tmp ) error("Could not parse argument: --threads %s\n", optarg); + break; + case 'o': outfn = optarg; break; default: usage(); } } - if ( optind==argc ) usage(); if (stats>2) { fprintf(stderr, "[E::%s] expected only one of --stats or --nrecords options\n", __func__); @@ -173,69 +178,54 @@ int main_vcfindex(int argc, char *argv[]) return 1; } - char *fname = argv[optind]; - if (stats) return vcf_index_stats(fname, stats); - - htsFile *fp = hts_open(fname,"r"); - if ( !fp ) error("Failed to read %s\n", fname); - htsFormat type = *hts_get_format(fp); - hts_close(fp); - - if ( (type.format!=bcf && type.format!=vcf) || type.compression!=bgzf ) + char *fname = NULL; + if ( optind>=argc ) { - fprintf(stderr, "[E::%s] unknown filetype; expected bgzip compressed VCF or BCF\n", __func__); - if ( type.compression!=bgzf ) - fprintf(stderr, "[E::%s] was the VCF/BCF compressed with bgzip?\n", __func__); - return 1; - } - if (tbi && type.format==bcf) - { - fprintf(stderr, "[Warning] TBI-index does not work for BCF files. Generating CSI instead.\n"); - tbi = 0; min_shift = BCF_LIDX_SHIFT; + if ( !isatty(fileno((FILE *)stdin)) ) fname = "-"; // reading from stdin + else usage(); } - if (min_shift == 0 && type.format==bcf) - { - fprintf(stderr, "[E::%s] Require min_shift>0 for BCF files.\n", __func__); - return 1; - } - if (!tbi && type.format==vcf && min_shift == 0) + else fname = argv[optind]; + if (stats) return vcf_index_stats(fname, stats); + + kstring_t idx_fname = {0,0,0}; + if (outfn) + kputs(outfn,&idx_fname); + else { - fprintf(stderr, "[Warning] min-shift set to 0 for VCF file. Generating TBI file.\n"); - tbi = 1; + if (!strcmp(fname, "-")) { fprintf(stderr, "[E::%s] must specify an output path for index file when reading VCF/BCF from stdin\n", __func__); return 1; } + ksprintf(&idx_fname, "%s.%s", fname, tbi ? "tbi" : "csi"); } - if (!force) { // Before complaining about existing index, check if the VCF file isn't newer. - char *idx_fname = (char*)alloca(strlen(fname) + 5); - strcat(strcpy(idx_fname, fname), tbi ? ".tbi" : ".csi"); struct stat stat_tbi, stat_file; - if ( stat(idx_fname, &stat_tbi)==0 ) + if ( stat(idx_fname.s, &stat_tbi)==0 ) { stat(fname, &stat_file); if ( stat_file.st_mtime <= stat_tbi.st_mtime ) { - fprintf(stderr,"[E::%s] the index file exists. Please use '-f' to overwrite.\n", __func__); + fprintf(stderr,"[E::%s] the index file exists. Please use '-f' to overwrite %s\n", __func__, idx_fname.s); + free(idx_fname.s); return 1; } } - } - if (type.format==bcf) - { - if ( bcf_index_build(fname, min_shift) != 0 ) - { - fprintf(stderr,"[E::%s] bcf_index_build failed for %s\n", __func__, fname); - return 1; - } - } - else - { - if ( tbx_index_build(fname, min_shift, &tbx_conf_vcf) != 0 ) - { - fprintf(stderr,"[E::%s] tbx_index_build failed for %s\n", __func__, fname); - return 1; - } + // check for truncated files, allow only with -f + BGZF *fp = bgzf_open(fname, "r"); + if ( !fp ) error("index: failed to open %s\n", fname); + if ( bgzf_check_EOF(fp)!=1 ) error("index: the input is probably truncated, use -f to index anyway: %s\n", fname); + if ( bgzf_close(fp)!=0 ) error("index: close failed: %s\n", fname); + } + + int ret = bcf_index_build3(fname, idx_fname.s, min_shift, n_threads); + free(idx_fname.s); + if (ret != 0) { + if (ret == -2) + error("index: failed to open \"%s\"\n", fname); + else if (ret == -3) + error("index: \"%s\" is in a format that cannot be usefully indexed\n", fname); + else + error("index: failed to create index for \"%s\"\n", fname); } return 0; } diff --git a/bcftools/vcfindex.c.pysam.c b/bcftools/vcfindex.c.pysam.c index 479fc575f..1e7578c0f 100644 --- a/bcftools/vcfindex.c.pysam.c +++ b/bcftools/vcfindex.c.pysam.c @@ -1,5 +1,4 @@ -#include "pysam.h" - +#include "bcftools.pysam.h" /* vcfindex.c -- Index bgzip compressed VCF/BCF files for random access. @@ -34,58 +33,58 @@ DEALINGS IN THE SOFTWARE. */ #include #define __STDC_FORMAT_MACROS #include +#include +#include #include "bcftools.h" #define BCF_LIDX_SHIFT 14 static void usage(void) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Index bgzip compressed VCF/BCF files for random access.\n"); - fprintf(pysam_stderr, "Usage: bcftools index [options] |\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Indexing options:\n"); - fprintf(pysam_stderr, " -c, --csi generate CSI-format index for VCF/BCF files [default]\n"); - fprintf(pysam_stderr, " -f, --force overwrite index if it already exists\n"); - fprintf(pysam_stderr, " -m, --min-shift INT set minimal interval size for CSI indices to 2^INT [14]\n"); - fprintf(pysam_stderr, " -t, --tbi generate TBI-format index for VCF files\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Stats options:\n"); - fprintf(pysam_stderr, " -n, --nrecords print number of records based on existing index file\n"); - fprintf(pysam_stderr, " -s, --stats print per contig stats based on existing index file\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Index bgzip compressed VCF/BCF files for random access.\n"); + fprintf(bcftools_stderr, "Usage: bcftools index [options] |\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Indexing options:\n"); + fprintf(bcftools_stderr, " -c, --csi generate CSI-format index for VCF/BCF files [default]\n"); + fprintf(bcftools_stderr, " -f, --force overwrite index if it already exists\n"); + fprintf(bcftools_stderr, " -m, --min-shift INT set minimal interval size for CSI indices to 2^INT [14]\n"); + fprintf(bcftools_stderr, " -o, --output-file FILE optional output index file name\n"); + fprintf(bcftools_stderr, " -t, --tbi generate TBI-format index for VCF files\n"); + fprintf(bcftools_stderr, " --threads sets the number of threads [0]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Stats options:\n"); + fprintf(bcftools_stderr, " -n, --nrecords print number of records based on existing index file\n"); + fprintf(bcftools_stderr, " -s, --stats print per contig stats based on existing index file\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } int vcf_index_stats(char *fname, int stats) { - char *fn_out = NULL; - FILE *out; - out = fn_out ? fopen(fn_out, "w") : pysam_stdout; - const char **seq; int i, nseq; tbx_t *tbx = NULL; hts_idx_t *idx = NULL; htsFile *fp = hts_open(fname,"r"); - if ( !fp ) { fprintf(pysam_stderr,"Could not read %s\n", fname); return 1; } + if ( !fp ) { fprintf(bcftools_stderr,"Could not read %s\n", fname); return 1; } bcf_hdr_t *hdr = bcf_hdr_read(fp); - if ( !hdr ) { fprintf(pysam_stderr,"Could not read the header: %s\n", fname); return 1; } + if ( !hdr ) { fprintf(bcftools_stderr,"Could not read the header: %s\n", fname); return 1; } if ( hts_get_format(fp)->format==vcf ) { tbx = tbx_index_load(fname); - if ( !tbx ) { fprintf(pysam_stderr,"Could not load TBI index: %s\n", fname); return 1; } + if ( !tbx ) { fprintf(bcftools_stderr,"Could not load index for VCF: %s\n", fname); return 1; } } else if ( hts_get_format(fp)->format==bcf ) { idx = bcf_index_load(fname); - if ( !idx ) { fprintf(pysam_stderr,"Could not load CSI index: %s\n", fname); return 1; } + if ( !idx ) { fprintf(bcftools_stderr,"Could not load index for BCF file: %s\n", fname); return 1; } } else { - fprintf(pysam_stderr,"Could not detect the file type as VCF or BCF: %s\n", fname); + fprintf(bcftools_stderr,"Could not detect the file type as VCF or BCF: %s\n", fname); return 1; } @@ -99,7 +98,7 @@ int vcf_index_stats(char *fname, int stats) if (stats&2 || !records) continue; bcf_hrec_t *hrec = bcf_hdr_get_hrec(hdr, BCF_HL_CTG, "ID", seq[i], NULL); int hkey = hrec ? bcf_hrec_find_key(hrec, "length") : -1; - fprintf(out,"%s\t%s\t%" PRIu64 "\n", seq[i], hkey<0?".":hrec->vals[hkey], records); + fprintf(bcftools_stdout, "%s\t%s\t%" PRIu64 "\n", seq[i], hkey<0?".":hrec->vals[hkey], records); } if (!sum) { @@ -108,14 +107,13 @@ int vcf_index_stats(char *fname, int stats) bcf1_t *rec = bcf_init1(); if (bcf_read1(fp, hdr, rec) >= 0) { - fprintf(pysam_stderr,"%s index of %s does not contain any count metadata. Please re-index with a newer version of bcftools or tabix.\n", tbx ? "TBI" : "CSI", fname); + fprintf(bcftools_stderr,"index of %s does not contain any count metadata. Please re-index with a newer version of bcftools or tabix.\n", fname); return 1; } bcf_destroy1(rec); } - if (stats&2) fprintf(out, "%" PRIu64 "\n", sum); + if (stats&2) fprintf(bcftools_stdout, "%" PRIu64 "\n", sum); free(seq); - fclose(out); hts_close(fp); bcf_hdr_destroy(hdr); if (tbx) @@ -127,8 +125,9 @@ int vcf_index_stats(char *fname, int stats) int main_vcfindex(int argc, char *argv[]) { - int c, force = 0, tbi = 0, stats = 0; + int c, force = 0, tbi = 0, stats = 0, n_threads = 0; int min_shift = BCF_LIDX_SHIFT; + char *outfn = NULL; static struct option loptions[] = { @@ -138,106 +137,97 @@ int main_vcfindex(int argc, char *argv[]) {"min-shift",required_argument,NULL,'m'}, {"stats",no_argument,NULL,'s'}, {"nrecords",no_argument,NULL,'n'}, + {"threads",required_argument,NULL,9}, + {"output-file",required_argument,NULL,'o'}, {NULL, 0, NULL, 0} }; char *tmp; - while ((c = getopt_long(argc, argv, "ctfm:sn", loptions, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "ctfm:sno:", loptions, NULL)) >= 0) { switch (c) { case 'c': tbi = 0; break; case 't': tbi = 1; min_shift = 0; break; case 'f': force = 1; break; - case 'm': + case 'm': min_shift = strtol(optarg,&tmp,10); if ( *tmp ) error("Could not parse argument: --min-shift %s\n", optarg); break; case 's': stats |= 1; break; case 'n': stats |= 2; break; + case 9: + n_threads = strtol(optarg,&tmp,10); + if ( *tmp ) error("Could not parse argument: --threads %s\n", optarg); + break; + case 'o': outfn = optarg; break; default: usage(); } } - if ( optind==argc ) usage(); if (stats>2) { - fprintf(pysam_stderr, "[E::%s] expected only one of --stats or --nrecords options\n", __func__); + fprintf(bcftools_stderr, "[E::%s] expected only one of --stats or --nrecords options\n", __func__); return 1; } if (tbi && min_shift>0) { - fprintf(pysam_stderr, "[E::%s] min-shift option only expected for CSI indices \n", __func__); + fprintf(bcftools_stderr, "[E::%s] min-shift option only expected for CSI indices \n", __func__); return 1; } if (min_shift < 0 || min_shift > 30) { - fprintf(pysam_stderr, "[E::%s] expected min_shift in range [0,30] (%d)\n", __func__, min_shift); + fprintf(bcftools_stderr, "[E::%s] expected min_shift in range [0,30] (%d)\n", __func__, min_shift); return 1; } - char *fname = argv[optind]; - if (stats) return vcf_index_stats(fname, stats); - - htsFile *fp = hts_open(fname,"r"); - if ( !fp ) error("Failed to read %s\n", fname); - htsFormat type = *hts_get_format(fp); - hts_close(fp); - - if ( (type.format!=bcf && type.format!=vcf) || type.compression!=bgzf ) + char *fname = NULL; + if ( optind>=argc ) { - fprintf(pysam_stderr, "[E::%s] unknown filetype; expected bgzip compressed VCF or BCF\n", __func__); - if ( type.compression!=bgzf ) - fprintf(pysam_stderr, "[E::%s] was the VCF/BCF compressed with bgzip?\n", __func__); - return 1; - } - if (tbi && type.format==bcf) - { - fprintf(pysam_stderr, "[Warning] TBI-index does not work for BCF files. Generating CSI instead.\n"); - tbi = 0; min_shift = BCF_LIDX_SHIFT; + if ( !isatty(fileno((FILE *)stdin)) ) fname = "-"; // reading from stdin + else usage(); } - if (min_shift == 0 && type.format==bcf) - { - fprintf(pysam_stderr, "[E::%s] Require min_shift>0 for BCF files.\n", __func__); - return 1; - } - if (!tbi && type.format==vcf && min_shift == 0) + else fname = argv[optind]; + if (stats) return vcf_index_stats(fname, stats); + + kstring_t idx_fname = {0,0,0}; + if (outfn) + kputs(outfn,&idx_fname); + else { - fprintf(pysam_stderr, "[Warning] min-shift set to 0 for VCF file. Generating TBI file.\n"); - tbi = 1; + if (!strcmp(fname, "-")) { fprintf(bcftools_stderr, "[E::%s] must specify an output path for index file when reading VCF/BCF from stdin\n", __func__); return 1; } + ksprintf(&idx_fname, "%s.%s", fname, tbi ? "tbi" : "csi"); } - if (!force) { // Before complaining about existing index, check if the VCF file isn't newer. - char *idx_fname = (char*)alloca(strlen(fname) + 5); - strcat(strcpy(idx_fname, fname), tbi ? ".tbi" : ".csi"); struct stat stat_tbi, stat_file; - if ( stat(idx_fname, &stat_tbi)==0 ) + if ( stat(idx_fname.s, &stat_tbi)==0 ) { stat(fname, &stat_file); if ( stat_file.st_mtime <= stat_tbi.st_mtime ) { - fprintf(pysam_stderr,"[E::%s] the index file exists. Please use '-f' to overwrite.\n", __func__); + fprintf(bcftools_stderr,"[E::%s] the index file exists. Please use '-f' to overwrite %s\n", __func__, idx_fname.s); + free(idx_fname.s); return 1; } } - } - if (type.format==bcf) - { - if ( bcf_index_build(fname, min_shift) != 0 ) - { - fprintf(pysam_stderr,"[E::%s] bcf_index_build failed for %s\n", __func__, fname); - return 1; - } - } - else - { - if ( tbx_index_build(fname, min_shift, &tbx_conf_vcf) != 0 ) - { - fprintf(pysam_stderr,"[E::%s] tbx_index_build failed for %s\n", __func__, fname); - return 1; - } + // check for truncated files, allow only with -f + BGZF *fp = bgzf_open(fname, "r"); + if ( !fp ) error("index: failed to open %s\n", fname); + if ( bgzf_check_EOF(fp)!=1 ) error("index: the input is probably truncated, use -f to index anyway: %s\n", fname); + if ( bgzf_close(fp)!=0 ) error("index: close failed: %s\n", fname); + } + + int ret = bcf_index_build3(fname, idx_fname.s, min_shift, n_threads); + free(idx_fname.s); + if (ret != 0) { + if (ret == -2) + error("index: failed to open \"%s\"\n", fname); + else if (ret == -3) + error("index: \"%s\" is in a format that cannot be usefully indexed\n", fname); + else + error("index: failed to create index for \"%s\"\n", fname); } return 0; } diff --git a/bcftools/vcfisec.c b/bcftools/vcfisec.c index 9eb3a7c6a..3e0e1e534 100644 --- a/bcftools/vcfisec.c +++ b/bcftools/vcfisec.c @@ -82,13 +82,13 @@ void mkdir_p(const char *fmt, ...) while (*p) { while (*p && *p!='/') p++; - if ( *p ) - { - *p = 0; - mkdir(tmp,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - *p = '/'; - p++; - } + if ( !*p ) break; + char ctmp = *p; + *p = 0; + int ret = mkdir(tmp,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + if ( ret!=0 && errno!=EEXIST ) error("Error creating directory %s: %s\n", path,strerror(errno)); + *p = ctmp; + while ( *p && *p=='/' ) p++; } free(tmp); free(path); diff --git a/bcftools/vcfisec.c.pysam.c b/bcftools/vcfisec.c.pysam.c index e3890d5ad..d16845799 100644 --- a/bcftools/vcfisec.c.pysam.c +++ b/bcftools/vcfisec.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfisec.c -- Create intersections, unions and complements of VCF files. @@ -84,13 +84,13 @@ void mkdir_p(const char *fmt, ...) while (*p) { while (*p && *p!='/') p++; - if ( *p ) - { - *p = 0; - mkdir(tmp,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - *p = '/'; - p++; - } + if ( !*p ) break; + char ctmp = *p; + *p = 0; + int ret = mkdir(tmp,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + if ( ret!=0 && errno!=EEXIST ) error("Error creating directory %s: %s\n", path,strerror(errno)); + *p = ctmp; + while ( *p && *p=='/' ) p++; } free(tmp); free(path); @@ -136,7 +136,7 @@ void isec_vcf(args_t *args) kstring_t str = {0,0,0}; htsFile *out_fh = NULL; - // When only one VCF is output, print VCF to pysam_stdout or -o file + // When only one VCF is output, print VCF to bcftools_stdout or -o file int out_std = 0; if ( args->nwrite==1 && !args->prefix ) out_std = 1; if ( args->targets_list && files->nreaders==1 ) out_std = 1; @@ -149,7 +149,7 @@ void isec_vcf(args_t *args) bcf_hdr_write(out_fh, files->readers[args->iwrite].header); } if ( !args->nwrite && !out_std && !args->prefix ) - fprintf(pysam_stderr,"Note: -w option not given, printing list of sites...\n"); + fprintf(bcftools_stderr,"Note: -w option not given, printing list of sites...\n"); int n; while ( (n=bcf_sr_next_line(files)) ) @@ -402,7 +402,7 @@ static void init_data(args_t *args) if ( args->fh_sites == NULL ) error("Can't write to \"%s\": %s\n", args->output_fname, strerror(errno)); } else - args->fh_sites = pysam_stdout; + args->fh_sites = bcftools_stdout; } } @@ -448,41 +448,41 @@ static void destroy_data(args_t *args) static void usage(void) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Create intersections, unions and complements of VCF files.\n"); - fprintf(pysam_stderr, "Usage: bcftools isec [options] [...]\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Options:\n"); - fprintf(pysam_stderr, " -c, --collapse treat as identical records with , see man page for details [none]\n"); - fprintf(pysam_stderr, " -C, --complement output positions present only in the first file but missing in the others\n"); - fprintf(pysam_stderr, " -e, --exclude exclude sites for which the expression is true\n"); - fprintf(pysam_stderr, " -f, --apply-filters require at least one of the listed FILTER strings (e.g. \"PASS,.\")\n"); - fprintf(pysam_stderr, " -i, --include include only sites for which the expression is true\n"); - fprintf(pysam_stderr, " --no-version do not append version and command line to the header\n"); - fprintf(pysam_stderr, " -n, --nfiles [+-=~] output positions present in this many (=), this many or more (+), this many or fewer (-), the exact (~) files\n"); - fprintf(pysam_stderr, " -o, --output write output to a file [standard output]\n"); - fprintf(pysam_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); - fprintf(pysam_stderr, " -p, --prefix if given, subset each of the input files accordingly, see also -w\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " --threads number of extra output compression threads [0]\n"); - fprintf(pysam_stderr, " -w, --write list of files to write with -p given as 1-based indexes. By default, all files are written\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Examples:\n"); - fprintf(pysam_stderr, " # Create intersection and complements of two sets saving the output in dir/*\n"); - fprintf(pysam_stderr, " bcftools isec A.vcf.gz B.vcf.gz -p dir\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, " # Filter sites in A and B (but not in C) and create intersection\n"); - fprintf(pysam_stderr, " bcftools isec -e'MAF<0.01' -i'dbSNP=1' -e - A.vcf.gz B.vcf.gz C.vcf.gz -p dir\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, " # Extract and write records from A shared by both A and B using exact allele match\n"); - fprintf(pysam_stderr, " bcftools isec A.vcf.gz B.vcf.gz -p dir -n =2 -w 1\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, " # Extract records private to A or B comparing by position only\n"); - fprintf(pysam_stderr, " bcftools isec A.vcf.gz B.vcf.gz -p dir -n -1 -c all\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Create intersections, unions and complements of VCF files.\n"); + fprintf(bcftools_stderr, "Usage: bcftools isec [options] [...]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Options:\n"); + fprintf(bcftools_stderr, " -c, --collapse treat as identical records with , see man page for details [none]\n"); + fprintf(bcftools_stderr, " -C, --complement output positions present only in the first file but missing in the others\n"); + fprintf(bcftools_stderr, " -e, --exclude exclude sites for which the expression is true\n"); + fprintf(bcftools_stderr, " -f, --apply-filters require at least one of the listed FILTER strings (e.g. \"PASS,.\")\n"); + fprintf(bcftools_stderr, " -i, --include include only sites for which the expression is true\n"); + fprintf(bcftools_stderr, " --no-version do not append version and command line to the header\n"); + fprintf(bcftools_stderr, " -n, --nfiles [+-=~] output positions present in this many (=), this many or more (+), this many or fewer (-), the exact (~) files\n"); + fprintf(bcftools_stderr, " -o, --output write output to a file [standard output]\n"); + fprintf(bcftools_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); + fprintf(bcftools_stderr, " -p, --prefix if given, subset each of the input files accordingly, see also -w\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " --threads number of extra output compression threads [0]\n"); + fprintf(bcftools_stderr, " -w, --write list of files to write with -p given as 1-based indexes. By default, all files are written\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Examples:\n"); + fprintf(bcftools_stderr, " # Create intersection and complements of two sets saving the output in dir/*\n"); + fprintf(bcftools_stderr, " bcftools isec A.vcf.gz B.vcf.gz -p dir\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, " # Filter sites in A and B (but not in C) and create intersection\n"); + fprintf(bcftools_stderr, " bcftools isec -e'MAF<0.01' -i'dbSNP=1' -e - A.vcf.gz B.vcf.gz C.vcf.gz -p dir\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, " # Extract and write records from A shared by both A and B using exact allele match\n"); + fprintf(bcftools_stderr, " bcftools isec A.vcf.gz B.vcf.gz -p dir -n =2 -w 1\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, " # Extract records private to A or B comparing by position only\n"); + fprintf(bcftools_stderr, " bcftools isec A.vcf.gz B.vcf.gz -p dir -n -1 -c all\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } diff --git a/bcftools/vcfmerge.c b/bcftools/vcfmerge.c index 02fac6bcc..31f5dad51 100644 --- a/bcftools/vcfmerge.c +++ b/bcftools/vcfmerge.c @@ -1,6 +1,6 @@ /* vcfmerge.c -- Merge multiple VCF/BCF files to create one multi-sample file. - Copyright (C) 2012-2014 Genome Research Ltd. + Copyright (C) 2012-2016 Genome Research Ltd. Author: Petr Danecek @@ -24,28 +24,39 @@ THE SOFTWARE. */ #include #include +#include #include #include #include #include #include #include +#include #include #include +#include #include "bcftools.h" +#include "regidx.h" #include "vcmp.h" +#define DBG 0 + #include KHASH_MAP_INIT_STR(strdict, int) typedef khash_t(strdict) strdict_t; -#define SKIP_DONE 1 -#define SKIP_DIFF 2 +#define FLT_LOGIC_ADD 0 +#define FLT_LOGIC_REMOVE 1 + +#define SKIP_DONE 1 // the record was processed +#define SKIP_DIFF 2 // not compatible, merge later #define IS_VL_G(hdr,id) (bcf_hdr_id2length(hdr,BCF_HL_FMT,id) == BCF_VL_G) #define IS_VL_A(hdr,id) (bcf_hdr_id2length(hdr,BCF_HL_FMT,id) == BCF_VL_A) #define IS_VL_R(hdr,id) (bcf_hdr_id2length(hdr,BCF_HL_FMT,id) == BCF_VL_R) +#define SWAP(type_t,a,b) { type_t tmp = (a); (a) = (b); (b) = tmp; } + // For merging INFO Number=A,G,R tags typedef struct { @@ -63,43 +74,60 @@ typedef struct _info_rule_t void (*merger)(bcf_hdr_t *hdr, bcf1_t *line, struct _info_rule_t *rule); int type; // one of BCF_HT_* int block_size; // number of values in a block + int type_size; // size of the corresponding BCF_HT_* type int nblocks; // number of blocks in nvals (the number of merged files) int nvals, mvals; // used and total size of vals array void *vals; // the info tag values } info_rule_t; +typedef struct +{ + bcf1_t *line; + int end, active; +} +gvcf_aux_t; + // Auxiliary merge data for selecting the right combination // of buffered records across multiple readers. maux1_t // corresponds to one buffered line. typedef struct { int skip; - int *map; // mapping from input alleles to the output array + int *map; // mapping from input alleles to the array of output alleles (set by merge_alleles) int mmap; // size of map array (only buffer[i].n_allele is actually used) int als_differ; } maux1_t; typedef struct { - int n; // number of readers + int rid; // current rid + int beg,end; // valid ranges in reader's buffer [beg,end). Maintained by maux_reset and gvcf_flush. + int cur; // current line or -1 if none + int mrec; // allocated size of buf + maux1_t *rec; // buffer to keep reader's lines + bcf1_t **lines; // source buffer: either gvcf or readers' buffer +} +buffer_t; +typedef struct +{ + int n, pos, var_types; // number of readers, current position, currently available variant types + char *chr; // current chromosome char **als, **out_als; // merged alleles (temp, may contain empty records) and merged alleles ready for output int nals, mals, nout_als, mout_als; // size of the output array int *cnt, ncnt; // number of records that refer to the alleles - int *nbuf; // readers have buffers of varying lengths int *smpl_ploidy, *smpl_nGsize; // ploidy and derived number of values in Number=G tags, updated for each line (todo: cache for missing cases) - int *flt, mflt, minf; - bcf_info_t *inf;// out_line's INFO fields bcf_fmt_t **fmt_map; // i-th output FORMAT field corresponds in j-th reader to i*nreader+j, first row is reserved for GT int nfmt_map; // number of rows in the fmt_map array int *agr_map, nagr_map, magr_map; // mapping between Number=AGR element indexes void *tmp_arr; int ntmp_arr; - maux1_t **d; // d[i][j] i-th reader, j-th buffer line + buffer_t *buf; AGR_info_t *AGR_info; int nAGR_info, mAGR_info; bcf_srs_t *files; - int *has_line; // which files are being merged + int gvcf_min, gvcf_break; // min buffered gvcf END position (NB: gvcf_min is 1-based) or 0 if no active lines are present + gvcf_aux_t *gvcf; // buffer of gVCF lines } maux_t; @@ -107,8 +135,11 @@ typedef struct { vcmp_t *vcmp; maux_t *maux; - int header_only, collapse, output_type, force_samples, merge_by_id; + regidx_t *regs; // apply regions only after the blocks are expanded + regitr_t *regs_itr; + int header_only, collapse, output_type, force_samples, merge_by_id, do_gvcf, filter_logic, missing_to_ref; char *header_fname, *output_fname, *regions_list, *info_rules, *file_list; + faidx_t *gvcf_fai; info_rule_t *rules; int nrules; strdict_t *tmph; @@ -122,6 +153,14 @@ typedef struct } args_t; +static bcf1_t *maux_get_line(args_t *args, int i) +{ + maux_t *ma = args->maux; + int ibuf = ma->buf[i].cur; + if ( ibuf >= 0 ) return ma->buf[i].lines[ibuf]; + return NULL; +} + static void info_rules_merge_sum(bcf_hdr_t *hdr, bcf1_t *line, info_rule_t *rule) { if ( !rule->nvals ) return; @@ -247,6 +286,32 @@ static void info_rules_init(args_t *args) if ( str.l ) kputc(',',&str); kputs("DP4:sum",&str); } + if ( args->do_gvcf && bcf_hdr_idinfo_exists(args->out_hdr,BCF_HL_INFO,bcf_hdr_id2int(args->out_hdr, BCF_DT_ID, "QS")) ) + { + if ( str.l ) kputc(',',&str); + kputs("QS:sum",&str); + } + if ( args->do_gvcf && bcf_hdr_idinfo_exists(args->out_hdr,BCF_HL_INFO,bcf_hdr_id2int(args->out_hdr, BCF_DT_ID, "MinDP")) ) + { + if ( str.l ) kputc(',',&str); + kputs("MinDP:min",&str); + } + if ( args->do_gvcf && bcf_hdr_idinfo_exists(args->out_hdr,BCF_HL_INFO,bcf_hdr_id2int(args->out_hdr, BCF_DT_ID, "I16")) ) + { + if ( str.l ) kputc(',',&str); + kputs("I16:sum",&str); + } + if ( args->do_gvcf && bcf_hdr_idinfo_exists(args->out_hdr,BCF_HL_INFO,bcf_hdr_id2int(args->out_hdr, BCF_DT_ID, "IDV")) ) + { + if ( str.l ) kputc(',',&str); + kputs("IDV:max",&str); + } + if ( args->do_gvcf && bcf_hdr_idinfo_exists(args->out_hdr,BCF_HL_INFO,bcf_hdr_id2int(args->out_hdr, BCF_DT_ID, "IMF")) ) + { + if ( str.l ) kputc(',',&str); + kputs("IMF:max",&str); + } + if ( !str.l ) return; args->info_rules = str.s; } @@ -272,9 +337,12 @@ static void info_rules_init(args_t *args) int id = bcf_hdr_id2int(args->out_hdr, BCF_DT_ID, rule->hdr_tag); if ( !bcf_hdr_idinfo_exists(args->out_hdr,BCF_HL_INFO,id) ) error("The tag is not defined in the header: \"%s\"\n", rule->hdr_tag); rule->type = bcf_hdr_id2type(args->out_hdr,BCF_HL_INFO,id); - if ( rule->type!=BCF_HT_INT && rule->type!=BCF_HT_REAL && rule->type!=BCF_HT_STR ) error("The type is not supported: \"%s\"\n", rule->hdr_tag); + if ( rule->type==BCF_HT_INT ) rule->type_size = sizeof(int32_t); + else if ( rule->type==BCF_HT_REAL ) rule->type_size = sizeof(float); + else if ( rule->type==BCF_HT_STR ) rule->type_size = sizeof(char); + else error("The type is not supported: \"%s\"\n", rule->hdr_tag); - while ( *ss ) ss++; ss++; + ss = strchr(ss, '\0'); ss++; if ( !*ss ) error("Could not parse INFO rules, missing logic of \"%s\"\n", rule->hdr_tag); int is_join = 0; @@ -300,7 +368,8 @@ static void info_rules_init(args_t *args) error("Only fixed-length vectors are supported with -i %s:%s\n", ss, rule->hdr_tag); } - while ( *ss ) ss++; ss++; n++; + ss = strchr(ss, '\0'); ss++; + n++; } free(str.s); free(tmp); @@ -326,8 +395,10 @@ static void info_rules_reset(args_t *args) } static int info_rules_add_values(args_t *args, bcf_hdr_t *hdr, bcf1_t *line, info_rule_t *rule, maux1_t *als, int var_len) { - int ret = bcf_get_info_values(hdr, line, rule->hdr_tag, &args->maux->tmp_arr, &args->maux->ntmp_arr, rule->type); + int msize = args->maux->ntmp_arr / rule->type_size; + int ret = bcf_get_info_values(hdr, line, rule->hdr_tag, &args->maux->tmp_arr, &msize, rule->type); if ( ret<=0 ) error("FIXME: error parsing %s at %s:%d .. %d\n", rule->hdr_tag,bcf_seqname(hdr,line),line->pos+1,ret); + args->maux->ntmp_arr = msize * rule->type_size; rule->nblocks++; @@ -345,7 +416,7 @@ static int info_rules_add_values(args_t *args, bcf_hdr_t *hdr, bcf1_t *line, inf int i, j; if ( var_len==BCF_VL_A ) { - assert( ret==line->n_allele-1 ); + if ( ret!=line->n_allele-1 ) error("Wrong number of %s fields at %s:%d\n",rule->hdr_tag,bcf_seqname(hdr,line),line->pos+1); args->maux->nagr_map = ret; hts_expand(int,args->maux->nagr_map,args->maux->magr_map,args->maux->agr_map); // create mapping from source file ALT indexes to dst file indexes @@ -354,7 +425,7 @@ static int info_rules_add_values(args_t *args, bcf_hdr_t *hdr, bcf1_t *line, inf } else if ( var_len==BCF_VL_R ) { - assert( ret==line->n_allele ); + if ( ret!=line->n_allele ) error("Wrong number of %s fields at %s:%d\n",rule->hdr_tag,bcf_seqname(hdr,line),line->pos+1); args->maux->nagr_map = ret; hts_expand(int,args->maux->nagr_map,args->maux->magr_map,args->maux->agr_map); for (i=0; imaux->agr_map[i] = als->map[i]; @@ -556,6 +627,8 @@ char **merge_alleles(char **a, int na, int *map, char **b, int *nb, int *mb) { for (i=0; i<*nb; i++) { + if ( b[i][0]=='<' ) continue; // symbolic allele, do not modify + if ( b[i][0]=='*' ) continue; // overlapping deletion (*), do not modify int l = strlen(b[i]); b[i] = (char*) realloc(b[i],l+rla-rlb+1); memcpy(b[i]+l,a[0]+rlb,rla-rlb+1); @@ -565,13 +638,15 @@ char **merge_alleles(char **a, int na, int *map, char **b, int *nb, int *mb) // now check if the $a alleles are present and if not add them for (i=1; irla ) // $a alleles need expanding + if ( rlb>rla && a[i][0]!='<' && a[i][0]!='*' ) // $a alleles need expanding and not a symbolic allele or * { int l = strlen(a[i]); ai = (char*) malloc(l+rlb-rla+1); memcpy(ai,a[i],l); memcpy(ai+l,b[0]+rla,rlb-rla+1); + const_ai = 0; } else ai = a[i]; @@ -582,42 +657,58 @@ char **merge_alleles(char **a, int na, int *map, char **b, int *nb, int *mb) if ( j<*nb ) // $b already has the same allele { map[i] = j; - if ( rlb>rla ) free(ai); + if ( !const_ai ) free(ai); continue; } // new allele map[i] = *nb; - b[*nb] = rlb>rla ? ai : strdup(ai); + b[*nb] = const_ai ? strdup(ai) : ai; (*nb)++; } return b; } -maux_t *maux_init(bcf_srs_t *files) +maux_t *maux_init(args_t *args) { + bcf_srs_t *files = args->files; maux_t *ma = (maux_t*) calloc(1,sizeof(maux_t)); ma->n = files->nreaders; - ma->nbuf = (int *) calloc(ma->n,sizeof(int)); - ma->d = (maux1_t**) calloc(ma->n,sizeof(maux1_t*)); ma->files = files; int i, n_smpl = 0; for (i=0; in; i++) n_smpl += bcf_hdr_nsamples(files->readers[i].header); + if ( args->do_gvcf ) + { + ma->gvcf = (gvcf_aux_t*) calloc(ma->n,sizeof(gvcf_aux_t)); + for (i=0; in; i++) + ma->gvcf[i].line = bcf_init1(); + } ma->smpl_ploidy = (int*) calloc(n_smpl,sizeof(int)); ma->smpl_nGsize = (int*) malloc(n_smpl*sizeof(int)); - ma->has_line = (int*) malloc(ma->n*sizeof(int)); + ma->buf = (buffer_t*) calloc(ma->n,sizeof(buffer_t)); + for (i=0; in; i++) + ma->buf[i].rid = -1; return ma; } void maux_destroy(maux_t *ma) { - int i; + int i,j; + for (i=0; imals; i++) + { + free(ma->als[i]); + ma->als[i] = NULL; + } for (i=0; in; i++) // for each reader { - if ( !ma->d[i] ) continue; - int j; - for (j=0; jnbuf[i]; j++) // for each buffered line - if ( ma->d[i][j].map ) free(ma->d[i][j].map); - free(ma->d[i]); + for (j=0; jbuf[i].mrec; j++) // for each buffered line + free(ma->buf[i].rec[j].map); + free(ma->buf[i].rec); + } + free(ma->buf); + if ( ma->gvcf ) + { + for (i=0; in; i++) bcf_destroy(ma->gvcf[i].line); + free(ma->gvcf); } for (i=0; imAGR_info; i++) free(ma->AGR_info[i].buf); @@ -626,32 +717,72 @@ void maux_destroy(maux_t *ma) if (ma->ntmp_arr) free(ma->tmp_arr); if (ma->nfmt_map) free(ma->fmt_map); // ma->inf freed in bcf_destroy1 - free(ma->d); - free(ma->nbuf); for (i=0; imals; i++) free(ma->als[i]); if (ma->mout_als) free(ma->out_als); free(ma->als); free(ma->cnt); free(ma->smpl_ploidy); free(ma->smpl_nGsize); - free(ma->has_line); + free(ma->chr); free(ma); } -void maux_expand1(maux_t *ma, int i) +void maux_expand1(buffer_t *buf, int size) { - if ( ma->nbuf[i] <= ma->files->readers[i].nbuffer ) + if ( buf->mrec < size ) { - int n = ma->files->readers[i].nbuffer + 1; - ma->d[i] = (maux1_t*) realloc(ma->d[i], sizeof(maux1_t)*n); - memset(ma->d[i]+ma->nbuf[i],0,sizeof(maux1_t)*(n-ma->nbuf[i])); - ma->nbuf[i] = n; + hts_expand0(maux1_t,size,buf->mrec,buf->rec); + buf->mrec = size; } } void maux_reset(maux_t *ma) { - int i; - for (i=0; in; i++) maux_expand1(ma, i); - for (i=1; incnt; i++) ma->cnt[i] = 0; + int i,j; + for (i=0; in; i++) maux_expand1(&ma->buf[i],ma->files->readers[i].nbuffer+1); + for (i=0; incnt; i++) ma->cnt[i] = 0; + for (i=0; imals; i++) + { + free(ma->als[i]); + ma->als[i] = NULL; + } + const char *chr = NULL; + ma->nals = 0; + ma->pos = -1; + for (i=0; in; i++) + { + if ( !bcf_sr_has_line(ma->files,i) ) continue; + bcf1_t *line = bcf_sr_get_line(ma->files,i); + bcf_hdr_t *hdr = bcf_sr_get_header(ma->files,i); + chr = bcf_seqname(hdr,line); + ma->pos = line->pos; + break; + } + int new_chr = 0; + if ( chr && (!ma->chr || strcmp(ma->chr,chr)) ) + { + free(ma->chr); + ma->chr = strdup(chr); + new_chr = 1; + } + for (i=0; in; i++) + { + bcf_hdr_t *hdr = bcf_sr_get_header(ma->files,i); + ma->buf[i].rid = bcf_hdr_name2id(hdr,chr); + ma->buf[i].beg = bcf_sr_has_line(ma->files,i) ? 0 : 1; + for (j=ma->buf[i].beg; j<=ma->files->readers[i].nbuffer; j++) + { + ma->buf[i].rec[j].skip = 0; + bcf1_t *line = ma->files->readers[i].buffer[j]; + if ( line->rid!=ma->buf[i].rid || line->pos!=ma->pos ) break; + } + ma->buf[i].end = j; + ma->buf[i].cur = -1; + if ( ma->buf[i].beg < ma->buf[i].end ) + { + ma->buf[i].lines = ma->files->readers[i].buffer; + if ( ma->gvcf ) ma->gvcf[i].active = 0; // gvcf block cannot overlap with the next record + } + if ( new_chr && ma->gvcf ) ma->gvcf[i].active = 0; // make sure to close active gvcf block on new chr + } } void maux_debug(maux_t *ma, int ir, int ib) { @@ -684,16 +815,20 @@ void merge_chrom2qual(args_t *args, bcf1_t *out) out->pos = -1; for (i=0; inreaders; i++) { - if ( !ma->has_line[i] ) continue; + bcf1_t *line = maux_get_line(args, i); + if ( !line ) continue; + bcf_unpack(line, BCF_UN_ALL); bcf_sr_t *reader = &files->readers[i]; - bcf1_t *line = reader->buffer[0]; bcf_hdr_t *hdr = reader->header; - // alleles + // not all maux alleles are always used, mark the ones we'll need int j; for (j=1; jn_allele; j++) - al_idxs[ ma->d[i][0].map[j] ] = 1; + { + int irec = ma->buf[i].cur; + al_idxs[ ma->buf[i].rec[irec].map[j] ] = 1; + } // position if ( out->pos==-1 ) @@ -717,16 +852,15 @@ void merge_chrom2qual(args_t *args, bcf1_t *out) } // set QUAL to the max qual value. Not exactly correct, but good enough for now - if ( !bcf_float_is_missing(files->readers[i].buffer[0]->qual) ) + if ( !bcf_float_is_missing(line->qual) ) { - if ( bcf_float_is_missing(out->qual) || out->qual < files->readers[i].buffer[0]->qual ) out->qual = files->readers[i].buffer[0]->qual; + if ( bcf_float_is_missing(out->qual) || out->qual < line->qual ) out->qual = line->qual; } } // set ID if ( !tmps->l ) kputs(".", tmps); - if ( out->d.id ) free(out->d.id); - out->d.id = strdup(tmps->s); + bcf_update_id(out_hdr, out, tmps->s); // set alleles ma->nout_als = 0; @@ -740,10 +874,13 @@ void merge_chrom2qual(args_t *args, bcf1_t *out) int ir, j; for (ir=0; irnreaders; ir++) { - if ( !ma->has_line[ir] ) continue; - bcf1_t *line = files->readers[ir].buffer[0]; + bcf1_t *line = maux_get_line(args,ir); + if ( !line ) continue; for (j=1; jn_allele; j++) - if ( ma->d[ir][0].map[j]==i ) ma->d[ir][0].map[j] = ma->nout_als; + { + int irec = ma->buf[ir].cur; + if ( ma->buf[ir].rec[irec].map[j]==i ) ma->buf[ir].rec[irec].map[j] = ma->nout_als; + } } } // Expand the arrays and realloc the alleles string. Note that all alleles are in a single allocated block. @@ -765,20 +902,36 @@ void merge_filter(args_t *args, bcf1_t *out) bcf_hdr_t *out_hdr = args->out_hdr; int i, ret; + if ( args->filter_logic == FLT_LOGIC_REMOVE ) + { + for (i=0; inreaders; i++) + { + bcf1_t *line = maux_get_line(args, i); + if ( !line ) continue; + bcf_sr_t *reader = &files->readers[i]; + bcf_hdr_t *hdr = reader->header; + if ( bcf_has_filter(hdr, line, "PASS") ) break; + } + if ( inreaders ) + { + int flt_id = bcf_hdr_id2int(out_hdr, BCF_DT_ID, "PASS"); + bcf_add_filter(out_hdr, out, flt_id); + return; + } + } + khiter_t kitr; strdict_t *tmph = args->tmph; kh_clear(strdict, tmph); - maux_t *ma = args->maux; out->d.n_flt = 0; for (i=0; inreaders; i++) { - if ( !ma->has_line[i]) continue; + bcf1_t *line = maux_get_line(args, i); + if ( !line ) continue; bcf_sr_t *reader = &files->readers[i]; - bcf1_t *line = reader->buffer[0]; bcf_hdr_t *hdr = reader->header; - bcf_unpack(line, BCF_UN_ALL); int k; for (k=0; kd.n_flt; k++) @@ -789,8 +942,8 @@ void merge_filter(args_t *args, bcf1_t *out) { int id = bcf_hdr_id2int(out_hdr, BCF_DT_ID, flt); if ( id==-1 ) error("Error: The filter is not defined in the header: %s\n", flt); - hts_expand(int,out->d.n_flt+1,ma->mflt,ma->flt); - ma->flt[out->d.n_flt] = id; + hts_expand(int,out->d.n_flt+1,out->d.m_flt,out->d.flt); + out->d.flt[out->d.n_flt] = id; out->d.n_flt++; kh_put(strdict, tmph, flt, &ret); } @@ -801,20 +954,17 @@ void merge_filter(args_t *args, bcf1_t *out) { int id = bcf_hdr_id2int(out_hdr, BCF_DT_ID, "PASS"); for (i=0; id.n_flt; i++) - if ( ma->flt[i]==id ) break; + if ( out->d.flt[i]==id ) break; if ( id.n_flt ) { out->d.n_flt--; - for (; id.n_flt; i++) ma->flt[i] = ma->flt[i+1]; + for (; id.n_flt; i++) out->d.flt[i] = out->d.flt[i+1]; } } - out->d.flt = ma->flt; } static void bcf_info_set_id(bcf1_t *line, bcf_info_t *info, int id, kstring_t *tmp_str) { - assert( !info->vptr_free ); - uint8_t *ptr = info->vptr - info->vptr_off; bcf_dec_typed_int1(ptr, &ptr); @@ -833,8 +983,6 @@ static void bcf_info_set_id(bcf1_t *line, bcf_info_t *info, int id, kstring_t *t kputsn_(info->vptr, info->len << bcf_type_shift[info->type], tmp_str); info->vptr = (uint8_t*) tmp_str->s + info->vptr_off; - info->vptr_free = 1; - line->d.shared_dirty |= BCF1_DIRTY_INF; tmp_str->s = NULL; tmp_str->m = 0; tmp_str->l = 0; @@ -1029,9 +1177,10 @@ void merge_info(args_t *args, bcf1_t *out) info_rules_reset(args); for (i=0; inreaders; i++) { - if ( !ma->has_line[i] ) continue; + bcf1_t *line = maux_get_line(args,i); + if ( !line ) continue; + int irec = ma->buf[i].cur; bcf_sr_t *reader = &files->readers[i]; - bcf1_t *line = reader->buffer[0]; bcf_hdr_t *hdr = reader->header; for (j=0; jn_info; j++) { @@ -1050,7 +1199,7 @@ void merge_info(args_t *args, bcf1_t *out) info_rule_t *rule = (info_rule_t*) bsearch(key, args->rules, args->nrules, sizeof(*args->rules), info_rules_comp_key); if ( rule ) { - maux1_t *als = ( len==BCF_VL_A || len==BCF_VL_G || len==BCF_VL_R ) ? &ma->d[i][0] : NULL; + maux1_t *als = ( len==BCF_VL_A || len==BCF_VL_G || len==BCF_VL_R ) ? &ma->buf[i].rec[irec] : NULL; if ( info_rules_add_values(args, hdr, line, rule, als, len) ) continue; } } @@ -1061,7 +1210,7 @@ void merge_info(args_t *args, bcf1_t *out) { if ( kitr == kh_end(tmph) ) { - // first occurance in this reader, alloc arrays + // seeing this key for the first time ma->nAGR_info++; hts_expand0(AGR_info_t,ma->nAGR_info,ma->mAGR_info,ma->AGR_info); kitr = kh_put(strdict, tmph, key, &ret); @@ -1079,37 +1228,36 @@ void merge_info(args_t *args, bcf1_t *out) kitr = kh_get(strdict, tmph, key); int idx = kh_val(tmph, kitr); if ( idx<0 ) error("Error occurred while processing INFO tag \"%s\" at %s:%d\n", key,bcf_seqname(hdr,line),line->pos+1); - merge_AGR_info_tag(hdr, line,inf,len,&ma->d[i][0],&ma->AGR_info[idx]); + merge_AGR_info_tag(hdr, line,inf,len,&ma->buf[i].rec[irec],&ma->AGR_info[idx]); continue; } if ( kitr == kh_end(tmph) ) { - hts_expand0(bcf_info_t,out->n_info+1,ma->minf,ma->inf); - ma->inf[out->n_info].key = id; - ma->inf[out->n_info].type = inf->type; - ma->inf[out->n_info].len = inf->len; - ma->inf[out->n_info].vptr = inf->vptr; - ma->inf[out->n_info].v1.i = inf->v1.i; - ma->inf[out->n_info].v1.f = inf->v1.f; - ma->inf[out->n_info].vptr_off = inf->vptr_off; - ma->inf[out->n_info].vptr_len = inf->vptr_len; - ma->inf[out->n_info].vptr_free = inf->vptr_free; + // Seeing this key for the first time. Although quite hacky, + // this is faster than anything else given the data structures.. + + hts_expand0(bcf_info_t,out->n_info+1,out->d.m_info,out->d.info); + out->d.info[out->n_info].key = id; + out->d.info[out->n_info].type = inf->type; + out->d.info[out->n_info].len = inf->len; + out->d.info[out->n_info].v1.i = inf->v1.i; + out->d.info[out->n_info].v1.f = inf->v1.f; + out->d.info[out->n_info].vptr_off = inf->vptr_off; + out->d.info[out->n_info].vptr_len = inf->vptr_len; + out->d.info[out->n_info].vptr_free = 1; + out->d.info[out->n_info].vptr = (uint8_t*) malloc(inf->vptr_len+inf->vptr_off); + memcpy(out->d.info[out->n_info].vptr,inf->vptr-inf->vptr_off, inf->vptr_len+inf->vptr_off); + out->d.info[out->n_info].vptr += inf->vptr_off; if ( (args->output_type & FT_BCF) && id!=bcf_hdr_id2int(hdr, BCF_DT_ID, key) ) - { - // The existing packed info cannot be reused. Change the id. - // Although quite hacky, it's faster than anything else given - // the data structures - bcf_info_set_id(out, &ma->inf[out->n_info], id, &args->tmps); - } + bcf_info_set_id(out, &out->d.info[out->n_info], id, &args->tmps); + out->d.shared_dirty |= BCF1_DIRTY_INF; out->n_info++; kitr = kh_put(strdict, tmph, key, &ret); kh_val(tmph,kitr) = -(out->n_info-1); // arbitrary negative value } } } - out->d.info = ma->inf; - out->d.m_info = ma->minf; for (i=0; inrules; i++) args->rules[i].merger(args->out_hdr, out, &args->rules[i]); for (i=0; inAGR_info; i++) @@ -1154,12 +1302,14 @@ void merge_GT(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) } memset(ma->smpl_ploidy,0,nsamples*sizeof(int)); + int default_gt = args->missing_to_ref ? bcf_gt_unphased(0) : bcf_gt_missing; for (i=0; inreaders; i++) { bcf_sr_t *reader = &files->readers[i]; bcf_hdr_t *hdr = reader->header; bcf_fmt_t *fmt_ori = fmt_map[i]; int32_t *tmp = (int32_t *) ma->tmp_arr + ismpl*nsize; + int irec = ma->buf[i].cur; int j, k; if ( !fmt_ori ) @@ -1167,7 +1317,7 @@ void merge_GT(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) // missing values: assume maximum ploidy for (j=0; jsmpl_ploidy[ismpl+j]++; } + for (k=0; ksmpl_ploidy[ismpl+j]++; } tmp += nsize; } ismpl += bcf_hdr_nsamples(hdr); @@ -1176,7 +1326,7 @@ void merge_GT(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) #define BRANCH(type_t, vector_end) { \ type_t *p_ori = (type_t*) fmt_ori->p; \ - if ( !ma->d[i][0].als_differ ) \ + if ( !ma->buf[i].rec[irec].als_differ ) \ { \ /* the allele numbering is unchanged */ \ for (j=0; j>1) - 1; \ - al = al<=0 ? al + 1 : ma->d[i][0].map[al] + 1; \ + al = al<=0 ? al + 1 : ma->buf[i].rec[irec].map[al] + 1; \ tmp[k] = (al << 1) | ((p_ori[k])&1); \ } \ } \ @@ -1239,7 +1389,7 @@ void merge_format_field(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) int nsize = 0, length = BCF_VL_FIXED, type = -1; for (i=0; inreaders; i++) { - if ( !ma->has_line[i] ) continue; + if ( !maux_get_line(args,i) ) continue; if ( !fmt_map[i] ) continue; if ( !key ) key = files->readers[i].header->id[BCF_DT_ID][fmt_map[i]->id].key; type = fmt_map[i]->type; @@ -1277,10 +1427,12 @@ void merge_format_field(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) bcf_sr_t *reader = &files->readers[i]; bcf_hdr_t *hdr = reader->header; bcf_fmt_t *fmt_ori = fmt_map[i]; + bcf1_t *line = maux_get_line(args, i); + int irec = ma->buf[i].cur; if ( fmt_ori ) { type = fmt_ori->type; - int nals_ori = reader->buffer[0]->n_allele; + int nals_ori = line->n_allele; if ( length==BCF_VL_G ) { // if all fields are missing then n==1 is valid @@ -1313,10 +1465,8 @@ void merge_format_field(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) ismpl += bcf_hdr_nsamples(hdr); \ continue; \ } \ - assert( ma->has_line[i] ); \ - bcf1_t *line = reader->buffer[0]; \ src_type_t *src = (src_type_t*) fmt_ori->p; \ - if ( (length!=BCF_VL_G && length!=BCF_VL_A && length!=BCF_VL_R) || (line->n_allele==out->n_allele && !ma->d[i][0].als_differ) ) \ + if ( (length!=BCF_VL_G && length!=BCF_VL_A && length!=BCF_VL_R) || (line->n_allele==out->n_allele && !ma->buf[i].rec[irec].als_differ) ) \ { \ /* alleles unchanged, copy over */ \ for (j=0; jn_allele; iori++) \ { \ - inew = ma->d[i][0].map[iori]; \ + inew = ma->buf[i].rec[irec].map[iori]; \ src = (src_type_t*) fmt_ori->p + j*fmt_ori->n + iori; \ tgt = (tgt_type_t *) ma->tmp_arr + (ismpl+j)*nsize + inew; \ if ( src_is_vector_end ) break; \ @@ -1372,10 +1522,10 @@ void merge_format_field(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) int iori,jori, inew,jnew; \ for (iori=0; iorin_allele; iori++) \ { \ - inew = ma->d[i][0].map[iori]; \ + inew = ma->buf[i].rec[irec].map[iori]; \ for (jori=0; jori<=iori; jori++) \ { \ - jnew = ma->d[i][0].map[jori]; \ + jnew = ma->buf[i].rec[irec].map[jori]; \ int kori = iori*(iori+1)/2 + jori; \ int knew = inew>jnew ? inew*(inew+1)/2 + jnew : jnew*(jnew+1)/2 + inew; \ src = (src_type_t*) fmt_ori->p + j*fmt_ori->n + kori; \ @@ -1412,7 +1562,7 @@ void merge_format_field(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) int iori,inew; \ for (iori=ifrom; iorin_allele; iori++) \ { \ - inew = ma->d[i][0].map[iori] - ifrom; \ + inew = ma->buf[i].rec[irec].map[iori] - ifrom; \ tgt = (tgt_type_t *) ma->tmp_arr + (ismpl+j)*nsize + inew; \ if ( src_is_vector_end ) break; \ if ( src_is_missing ) tgt_set_missing; \ @@ -1461,9 +1611,9 @@ void merge_format(args_t *args, bcf1_t *out) int i, j, ret, has_GT = 0, max_ifmt = 0; // max fmt index for (i=0; inreaders; i++) { - if ( !ma->has_line[i] ) continue; + bcf1_t *line = maux_get_line(args,i); + if ( !line ) continue; bcf_sr_t *reader = &files->readers[i]; - bcf1_t *line = reader->buffer[0]; bcf_hdr_t *hdr = reader->header; for (j=0; jn_fmt; j++) { @@ -1495,9 +1645,10 @@ void merge_format(args_t *args, bcf1_t *out) ma->fmt_map[ifmt*files->nreaders+i] = fmt; } // Check if the allele numbering must be changed - for (j=1; jbuffer[0]->n_allele; j++) - if ( ma->d[i][0].map[j]!=j ) break; - ma->d[i][0].als_differ = j==reader->buffer[0]->n_allele ? 0 : 1; + int irec = ma->buf[i].cur; + for (j=1; jn_allele; j++) + if ( ma->buf[i].rec[irec].map[j]!=j ) break; + ma->buf[i].rec[irec].als_differ = j==line->n_allele ? 0 : 1; } out->n_sample = bcf_hdr_nsamples(out_hdr); @@ -1505,203 +1656,419 @@ void merge_format(args_t *args, bcf1_t *out) merge_GT(args, ma->fmt_map, out); update_AN_AC(out_hdr, out); - if ( out->d.info!=ma->inf ) - { - // hacky, we rely on htslib internals: bcf_update_info() reallocated the info - ma->inf = out->d.info; - ma->minf = out->d.m_info; - } - for (i=1; i<=max_ifmt; i++) merge_format_field(args, &ma->fmt_map[i*files->nreaders], out); out->d.indiv_dirty = 1; } -// The core merging function, one or none line from each reader -void merge_line(args_t *args) +void gvcf_set_alleles(args_t *args) +{ + int i,k; + bcf_srs_t *files = args->files; + maux_t *maux = args->maux; + gvcf_aux_t *gaux = maux->gvcf; + for (i=0; inals; i++) + { + free(maux->als[i]); + maux->als[i] = NULL; + } + maux->nals = 0; + + for (i=0; inreaders; i++) + { + if ( !gaux[i].active ) continue; + bcf1_t *line = maux_get_line(args, i); + int irec = maux->buf[i].cur; + + hts_expand(int, line->n_allele, maux->buf[i].rec[irec].mmap, maux->buf[i].rec[irec].map); + if ( !maux->nals ) // first record, copy the alleles to the output + { + maux->nals = line->n_allele; + hts_expand0(char*, maux->nals, maux->mals, maux->als); + hts_expand0(int, maux->nals, maux->ncnt, maux->cnt); + for (k=0; knals; k++) + { + if ( maux->als[k] ) free(maux->als[k]); + maux->als[k] = strdup(line->d.allele[k]); + maux->buf[i].rec[irec].map[k] = k; + } + } + else + { + maux->als = merge_alleles(line->d.allele, line->n_allele, maux->buf[i].rec[irec].map, maux->als, &maux->nals, &maux->mals); + if ( !maux->als ) + { + bcf_hdr_t *hdr = bcf_sr_get_header(args->files,i); + error("Failed to merge alleles at %s:%d\n",bcf_seqname(hdr,line),line->pos+1); + } + } + } +} + +/* + Output staged gVCF blocks, end is the last position of the block. Assuming + gaux[i].active flags are set and maux_get_line returns correct lines. +*/ +void gvcf_write_block(args_t *args, int start, int end) { + int i; + maux_t *maux = args->maux; + gvcf_aux_t *gaux = maux->gvcf; + assert(gaux); + + // Update POS + int min = INT_MAX; + char ref = 'N'; + for (i=0; ifiles->nreaders; i++) + { + if ( !gaux[i].active ) continue; + if ( ref=='N' && gaux[i].line->pos==start ) ref = gaux[i].line->d.allele[0][0]; + gaux[i].line->pos = start; + } + for (i=0; ifiles->nreaders; i++) + { + if ( !gaux[i].active ) continue; + if ( gaux[i].end < start ) + { + gaux[i].active = 0; + maux->buf[i].cur = -1; + continue; + } + gaux[i].line->d.allele[0][0] = ref; + if ( min > gaux[i].end ) min = gaux[i].end; + } + // Check for valid gVCF blocks in this region + if ( min==INT_MAX ) + { + assert(0); + maux->gvcf_min = 0; + return; + } + bcf1_t *out = args->out_line; - bcf_clear1(out); - out->unpacked = BCF_UN_ALL; + gvcf_set_alleles(args); + + // Merge the staged lines merge_chrom2qual(args, out); merge_filter(args, out); merge_info(args, out); merge_format(args, out); - bcf_write1(args->out_fh, args->out_hdr, out); -} + if ( args->gvcf_fai && out->d.allele[0][0]=='N' ) + { + int slen = 0; + char *seq = faidx_fetch_seq(args->gvcf_fai,maux->chr,out->pos,out->pos,&slen); + if (slen) + { + out->d.allele[0][0] = seq[0]; + free(seq); + } + } + // Update END boundary + if ( end > start ) + { + end++; + bcf_update_info_int32(args->out_hdr, out, "END", &end, 1); + } + else + bcf_update_info_int32(args->out_hdr, out, "END", NULL, 0); + bcf_write1(args->out_fh, args->out_hdr, out); + bcf_clear1(out); -void debug_buffers(FILE *fp, bcf_srs_t *files); -void debug_buffer(FILE *fp, bcf_sr_t *reader); -#define SWAP(type_t,a,b) { type_t tmp = (a); (a) = (b); (b) = tmp; } + // Inactivate blocks which do not extend beyond END and find new gvcf_min + min = INT_MAX; + for (i=0; ifiles->nreaders; i++) + { + if ( !gaux[i].active ) continue; + if ( gaux[i].end < end ) + { + gaux[i].active = 0; + maux->buf[i].cur = -1; + continue; + } + // next min END position bigger than the current one + if ( maux->gvcf_min < gaux[i].end+1 && min > gaux[i].end+1 ) min = gaux[i].end + 1; + } + maux->gvcf_min = min==INT_MAX ? 0 : min; +} -// Clean the reader's buffer to and make it ready for the next next_line() call. -// Moves finished records (SKIP_DONE flag set) at the end of the buffer and put -// the rest to the beggining. Then shorten the buffer so that the last element -// points to the last unfinished record. There are two special cases: the last -// line of the buffer typically has a different position and must stay at the -// end; next, the first record of the buffer must be one of those already -// printed, as it will be discarded by next_line(). -// -void shake_buffer(maux_t *maux, int ir, int pos) +/* + Flush staged gVCF blocks. Flush everything if there are no more lines + (done=1) or if there is a new chromosome. If still on the same chromosome, + all hanging blocks must be ended by creating new records: + A + 1 END=10 + B + 3 END=7 + C + 3 END=5 + out + 1 END=2 A . . + 3 END=5 A B C + 6 END=7 A B . + 8 END=10 A . . + +*/ +void gvcf_flush(args_t *args, int done) { - bcf_sr_t *reader = &maux->files->readers[ir]; - maux1_t *m = maux->d[ir]; - - if ( !reader->buffer ) return; - int i; - // FILE *fp = stdout; - // fprintf(fp," nbuf=%d\t", reader->nbuffer); for (i=0; inbuffer; i++) fprintf(fp," %d", skip[i]); fprintf(fp,"\n"); - // debug_buffer(fp,reader); - // fprintf(fp,"--\n"); + maux_t *maux = args->maux; - int a = 1, b = reader->nbuffer; - if ( reader->buffer[b]->pos != pos ) b--; // move the last line separately afterwards + if ( !maux->chr ) return; // first time here, nothing to flush - while ( abuffer[a], reader->buffer[b]); - SWAP(maux1_t, m[a], m[b]); - a++; - b--; - } + // Get current position and chromosome + for (i=0; in; i++) + if ( bcf_sr_has_line(maux->files,i) ) break; + bcf1_t *line = bcf_sr_get_line(maux->files,i); + bcf_hdr_t *hdr = bcf_sr_get_header(maux->files,i); - // position $a to the after the first unfinished record - while ( a<=reader->nbuffer && !(m[a].skip&SKIP_DONE) ) a++; + if ( !strcmp(maux->chr,bcf_seqname(hdr,line)) ) flush_until = line->pos; // still on the same chr + } - if ( anbuffer ) + // When called on a region, trim the blocks accordingly + int start = maux->gvcf_break>=0 ? maux->gvcf_break + 1 : maux->pos; + if ( args->regs ) { - // there is a gap between the unfinished lines at the beggining and the - // last line. The last line must be brought forward to fill the gap - if ( reader->buffer[reader->nbuffer]->pos != pos ) + int rstart = -1, rend = -1; + if ( regidx_overlap(args->regs,maux->chr,start,flush_until,args->regs_itr) ) { - SWAP(bcf1_t*, reader->buffer[a], reader->buffer[reader->nbuffer]); - SWAP(maux1_t, m[a], m[reader->nbuffer]); - reader->nbuffer = a; + // In case there are multiple regions, we treat them as one + rstart = args->regs_itr->beg; + while ( regitr_overlap(args->regs_itr) ) rend = args->regs_itr->end; } + if ( rstart > start ) start = rstart; + if ( rend < flush_until ) flush_until = rend+1; } - if ( !(m[0].skip&SKIP_DONE) && reader->buffer[0]->pos==pos ) + // output all finished blocks + while ( maux->gvcf_min && start < flush_until ) + { + // does the block end before the new line or is it interrupted? + int tmp = maux->gvcf_min < flush_until ? maux->gvcf_min : flush_until; + if ( start > tmp-1 ) break; + gvcf_write_block(args,start,tmp-1); // gvcf_min is 1-based + start = tmp; + } +} + +/* + Check incoming lines for new gVCF blocks, set pointer to the current source + buffer (gvcf or readers). In contrast to gvcf_flush, this function can be + called only after maux_reset as it relies on updated maux buffers. +*/ +void gvcf_stage(args_t *args, int pos) +{ + maux_t *maux = args->maux; + gvcf_aux_t *gaux = maux->gvcf; + bcf_srs_t *files = args->files; + int32_t *end = (int32_t*) maux->tmp_arr; + int i, nend = maux->ntmp_arr / sizeof(int32_t); + + maux->gvcf_break = -1; + maux->gvcf_min = INT_MAX; + for (i=0; inreaders; i++) { - // the first record is unfinished, replace it with an empty line - // from the end of the buffer or else next_line will remove it - if ( reader->nbuffer + 1 >= maux->nbuf[ir] ) + if ( gaux[i].active ) { - reader->nbuffer++; - maux_expand1(maux, ir); - reader->nbuffer--; - m = maux->d[ir]; + // gvcf block should not overlap with another record + if ( maux->gvcf_min > gaux[i].end+1 ) maux->gvcf_min = gaux[i].end + 1; + maux->buf[i].beg = 0; + maux->buf[i].end = 1; + maux->buf[i].cur = 0; + continue; } - if ( reader->nbuffer+1 >= reader->mbuffer ) - error("Uh, did not expect this: %d vs %d\n", reader->nbuffer,reader->mbuffer); - if ( reader->buffer[reader->nbuffer]->pos!=pos ) + // Does any of the lines have END set? It is enough to check only the + // first line, there should be no duplicate records with END in gVCF + + if ( maux->buf[i].beg==maux->buf[i].end ) continue; // no new record + + int irec = maux->buf[i].beg; + bcf_hdr_t *hdr = bcf_sr_get_header(files, i); + bcf1_t *line = args->files->readers[i].buffer[irec]; + int ret = bcf_get_info_int32(hdr,line,"END",&end,&nend); + if ( ret==1 ) { - // 4way swap - bcf1_t *tmp = reader->buffer[0]; - reader->buffer[0] = reader->buffer[reader->nbuffer+1]; - reader->buffer[reader->nbuffer+1] = reader->buffer[reader->nbuffer]; - reader->buffer[reader->nbuffer] = tmp; - m[reader->nbuffer].skip = m[0].skip; - m[reader->nbuffer+1].skip = SKIP_DIFF; - reader->nbuffer++; + // END is set, this is a new gVCF block. Cache this line in gaux[i] and swap with + // an empty record: the gaux line must be kept until we reach its END. + gaux[i].active = 1; + gaux[i].end = end[0] - 1; + SWAP(bcf1_t*,args->files->readers[i].buffer[irec],gaux[i].line); + gaux[i].line->pos = pos; + + maux->buf[i].lines = &gaux[i].line; + maux->buf[i].beg = 0; + maux->buf[i].end = 1; + maux->buf[i].cur = 0; + + // Set the rid,pos of the swapped line in the buffer or else the + // synced reader will have a problem with the next line + // + args->files->readers[i].buffer[irec]->rid = maux->buf[i].rid; + args->files->readers[i].buffer[irec]->pos = maux->pos; + + // Update block offsets + if ( maux->gvcf_min > gaux[i].end+1 ) maux->gvcf_min = gaux[i].end + 1; } else - { - SWAP(bcf1_t*, reader->buffer[0], reader->buffer[reader->nbuffer+1]); - SWAP(maux1_t, m[0], m[reader->nbuffer+1]); - } + maux->gvcf_break = line->pos; // must break the gvcf block } + maux->ntmp_arr = nend * sizeof(int32_t); + maux->tmp_arr = end; + if ( maux->gvcf_min==INT_MAX ) maux->gvcf_min = 0; +} - // debug_buffer(fp,reader); - // fprintf(fp,"\t"); for (i=0; inbuffer; i++) fprintf(fp," %d", skip[i]); - // fprintf(fp,"\n\n"); - // set position of finished buffer[0] line to -1, otherwise swapping may - // bring it back after next_line() - reader->buffer[0]->pos = -1; +void debug_buffers(FILE *fp, bcf_srs_t *files); +void debug_buffer(FILE *fp, bcf_srs_t *files, int reader); - // trim the buffer, remove finished lines from the end - i = reader->nbuffer; - while ( i>=1 && m[i--].skip&SKIP_DONE ) - reader->nbuffer--; +/* + Flush all buffered and processed records with the same coordinate. + Note that synced reader discards buffer[0], so that needs to stay + untouched. +*/ +void clean_buffer(args_t *args) +{ + maux_t *ma = args->maux; + + int ir; + for (ir=0; irn; ir++) + { + // Invalidate pointer to reader's buffer or else gvcf_flush will attempt + // to use the old lines via maux_get_line() + if ( ma->gvcf && !ma->gvcf[ir].active ) ma->buf[ir].cur = -1; + + bcf_sr_t *reader = bcf_sr_get_reader(args->files,ir); + if ( !reader->nbuffer ) continue; // nothing to clean + + bcf1_t **buf = reader->buffer; + if ( buf[1]->rid!=ma->buf[ir].rid || buf[1]->pos!=ma->pos ) continue; // nothing to flush + + int a = 1, b = 2; + while ( b<=reader->nbuffer && buf[b]->rid==ma->buf[ir].rid && buf[b]->pos==ma->pos ) b++; + // b now points to the first line we want to preserve + while ( b<=reader->nbuffer ) + { + SWAP(bcf1_t*, buf[a], buf[b]); + a++; b++; + } + reader->nbuffer -= b-a; + } } -void debug_maux(args_t *args, int pos, int var_type) +void debug_maux(args_t *args) { bcf_srs_t *files = args->files; maux_t *maux = args->maux; int j,k,l; - fprintf(stderr,"Alleles to merge at %d\n", pos+1); + fprintf(stderr,"Alleles to merge at %d, nals=%d\n", maux->pos+1,maux->nals); for (j=0; jnreaders; j++) { bcf_sr_t *reader = &files->readers[j]; + buffer_t *buf = &maux->buf[j]; fprintf(stderr," reader %d: ", j); - for (k=0; k<=reader->nbuffer; k++) + for (k=buf->beg; kend; k++) { - if ( maux->d[j][k].skip==SKIP_DONE ) continue; + if ( buf->rec[k].skip & SKIP_DONE ) continue; bcf1_t *line = reader->buffer[k]; - if ( line->pos!=pos ) continue; fprintf(stderr,"\t"); - if ( maux->d[j][k].skip ) fprintf(stderr,"["); // this record will not be merged in this round + if ( buf->rec[k].skip ) fprintf(stderr,"["); // this record will not be merged in this round for (l=0; ln_allele; l++) fprintf(stderr,"%s%s", l==0?"":",", line->d.allele[l]); - if ( maux->d[j][k].skip ) fprintf(stderr,"]"); + if ( buf->rec[k].skip ) fprintf(stderr,"]"); } fprintf(stderr,"\n"); } fprintf(stderr," counts: "); - for (j=0; jnals; j++) fprintf(stderr,"%s %dx %s", j==0?"":",",maux->cnt[j], maux->als[j]); fprintf(stderr,"\n"); - for (j=0; jnreaders; j++) + for (j=0; jnals; j++) fprintf(stderr,"%s %dx %s", j==0?"":",",maux->cnt[j], maux->als[j]); + fprintf(stderr,"\n\n"); +} + +void debug_state(args_t *args) +{ + maux_t *maux = args->maux; + int i,j; + for (i=0; ifiles->nreaders; i++) { - bcf_sr_t *reader = &files->readers[j]; - fprintf(stderr," out %d: ", j); - for (k=0; k<=reader->nbuffer; k++) + fprintf(stderr,"reader %d:\tcur,beg,end=% d,%d,%d", i,maux->buf[i].cur,maux->buf[i].beg,maux->buf[i].end); + if ( maux->buf[i].cur >=0 ) { - if ( maux->d[j][k].skip==SKIP_DONE ) continue; - bcf1_t *line = reader->buffer[k]; - if ( line->pos!=pos ) continue; - if ( maux->d[j][k].skip ) continue; + bcf_hdr_t *hdr = bcf_sr_get_header(args->files,i); + const char *chr = bcf_hdr_id2name(hdr, maux->buf[i].rid); fprintf(stderr,"\t"); - for (l=0; ln_allele; l++) - fprintf(stderr,"%s%s", l==0?"":",", maux->als[maux->d[j][k].map[l]]); + for (j=maux->buf[i].beg; jbuf[i].end; j++) fprintf(stderr," %s:%d",chr,maux->buf[i].lines[j]->pos+1); } fprintf(stderr,"\n"); } + for (i=0; ifiles->nreaders; i++) + { + fprintf(stderr,"reader %d:\tgvcf_active=%d", i,maux->gvcf[i].active); + if ( maux->gvcf[i].active ) fprintf(stderr,"\tpos,end=%d,%d", maux->gvcf[i].line->pos+1,maux->gvcf[i].end+1); + fprintf(stderr,"\n"); + } fprintf(stderr,"\n"); } -// Determine which line should be merged from which reader: go through all -// readers and all buffered lines, expand REF,ALT and try to match lines with -// the same ALTs. A step towards output independent on input ordering of the -// lines. -void merge_buffer(args_t *args) + +/* + Determine which line should be merged from which reader: go through all + readers and all buffered lines, expand REF,ALT and try to match lines with + the same ALTs. + */ +int can_merge(args_t *args) { bcf_srs_t *files = args->files; - int i, pos = -1, var_type = 0; - char *id = NULL; + int snp_mask = (VCF_SNP<<1)|(VCF_MNP<<1), indel_mask = VCF_INDEL<<1, ref_mask = 1; maux_t *maux = args->maux; - maux_reset(maux); + gvcf_aux_t *gaux = maux->gvcf; + char *id = NULL, ref = 'N'; + int i,j,k, ntodo = 0; + + for (i=0; inals; i++) + { + free(maux->als[i]); + maux->als[i] = NULL; + } + maux->var_types = maux->nals = 0; - // set the current position for (i=0; inreaders; i++) { - if ( bcf_sr_has_line(files,i) ) + buffer_t *buf = &maux->buf[i]; + + if ( gaux && gaux[i].active ) { - bcf1_t *line = bcf_sr_get_line(files,i); - pos = line->pos; - var_type = bcf_get_variant_types(line); - id = line->d.id; - break; + // skip readers with active gvcf blocks + buf->rec[buf->beg].skip = SKIP_DIFF; + continue; } + for (j=buf->beg; jend; j++) + { + if ( buf->rec[j].skip & SKIP_DONE ) continue; + + buf->rec[j].skip = SKIP_DIFF; + ntodo++; + + if ( args->merge_by_id ) + id = buf->lines[j]->d.id; + else + { + int var_type = bcf_get_variant_types(buf->lines[j]); + maux->var_types |= var_type ? var_type<<1 : 1; + } + } + + // for gvcf: find out REF at this position + if ( buf->beg < buf->end && ref=='N' ) + ref = buf->lines[buf->beg]->d.allele[0][0]; } + if ( !ntodo ) return 0; // In this loop we select from each reader compatible candidate lines. // (i.e. SNPs or indels). Go through all files and all lines at this @@ -1710,19 +2077,24 @@ void merge_buffer(args_t *args) for (i=0; inreaders; i++) { bcf_sr_t *reader = &files->readers[i]; - if ( !reader->buffer ) continue; - int j, k; - for (j=0; j<=reader->nbuffer; j++) + buffer_t *buf = &maux->buf[i]; + + if ( gaux && gaux[i].active ) { - bcf1_t *line = reader->buffer[j]; + gaux[i].line->d.allele[0][0] = ref; + gaux[i].line->pos = maux->pos; + } + + for (j=buf->beg; jend; j++) + { + if ( buf->rec[j].skip & SKIP_DONE ) continue; + + bcf1_t *line = buf->lines[j]; // ptr to reader's buffer or gvcf buffer + int line_type = bcf_get_variant_types(line); + line_type = line_type ? line_type<<1 : 1; + // select relevant lines - maux->d[i][j].skip = SKIP_DIFF; - if ( pos!=line->pos ) - { - if ( j==0 ) maux->d[i][j].skip |= SKIP_DONE; // left from previous run, force to ignore - continue; - } if ( args->merge_by_id ) { if ( strcmp(id,line->d.id) ) continue; @@ -1733,30 +2105,30 @@ void merge_buffer(args_t *args) { // All alleles of the tested record must be present in the // selected maux record plus variant types must be the same - if ( var_type!=line->d.var_type ) continue; + if ( (maux->var_types & line_type) != line_type ) continue; if ( vcmp_set_ref(args->vcmp,maux->als[0],line->d.allele[0]) < 0 ) continue; // refs not compatible for (k=1; kn_allele; k++) { if ( vcmp_find_allele(args->vcmp,maux->als+1,maux->nals-1,line->d.allele[k])>=0 ) break; } - if ( k==line->n_allele ) continue; // no matching allele + if ( !(line_type&ref_mask) && k==line->n_allele ) continue; // not a REF-only site and there is no matching allele } if ( !(args->collapse&COLLAPSE_ANY) ) { - int compatible = 0; - if ( line_type==var_type ) compatible = 1; - else if ( line_type==VCF_REF ) compatible = 1; // REF can go with anything - else if ( var_type&VCF_SNP && line_type&VCF_SNP ) compatible = 1; - else if ( var_type&VCF_INDEL && line_type&VCF_INDEL ) compatible = 1; - else if ( var_type&VCF_MNP && line_type&VCF_MNP ) compatible = 1; - else if ( var_type&VCF_SNP && line_type&VCF_MNP ) compatible = 1; - else if ( var_type&VCF_MNP && line_type&VCF_SNP ) compatible = 1; - if ( !compatible ) continue; + // Merge: + // - SNPs+SNPs+MNPs+REF if -m both,snps + // - indels+indels+REF if -m both,indels, REF only if SNPs are not present + // - SNPs come first + if ( line_type & indel_mask ) + { + if ( !(line_type&snp_mask) && maux->var_types&snp_mask ) continue; // SNPs come first + if ( args->do_gvcf && maux->var_types&ref_mask ) continue; // never merge indels with gVCF blocks + } } } - maux->d[i][j].skip = 0; + buf->rec[j].skip = 0; - hts_expand(int, line->n_allele, maux->d[i][j].mmap, maux->d[i][j].map); + hts_expand(int, line->n_allele, buf->rec[j].mmap, buf->rec[j].map); if ( !maux->nals ) // first record, copy the alleles to the output { maux->nals = line->n_allele; @@ -1764,111 +2136,118 @@ void merge_buffer(args_t *args) hts_expand0(int, maux->nals, maux->ncnt, maux->cnt); for (k=0; knals; k++) { + free(maux->als[k]); maux->als[k] = strdup(line->d.allele[k]); - maux->d[i][j].map[k] = k; + buf->rec[j].map[k] = k; maux->cnt[k] = 1; } - pos = line->pos; continue; } - // normalize alleles - maux->als = merge_alleles(line->d.allele, line->n_allele, maux->d[i][j].map, maux->als, &maux->nals, &maux->mals); - if ( !maux->als ) error("Failed to merge alleles at %s:%d in %s\n",bcf_seqname(bcf_sr_get_header(args->files,j),line),line->pos+1,reader->fname); + maux->als = merge_alleles(line->d.allele, line->n_allele, buf->rec[j].map, maux->als, &maux->nals, &maux->mals); + if ( !maux->als ) error("Failed to merge alleles at %s:%d in %s\n",bcf_seqname(args->out_hdr,line),line->pos+1,reader->fname); hts_expand0(int, maux->nals, maux->ncnt, maux->cnt); for (k=1; kn_allele; k++) - maux->cnt[ maux->d[i][j].map[k] ]++; // how many times an allele appears in the files + maux->cnt[ buf->rec[j].map[k] ]++; // how many times an allele appears in the files maux->cnt[0]++; } } + return 1; +} + +/* + Select records that have the same alleles; the input ordering of indels + must not matter. Multiple VCF lines can be emitted from this loop. + We expect only very few alleles and not many records with the same + position in the buffers, therefore the nested loops should not slow us + much. +*/ +void stage_line(args_t *args) +{ + int snp_mask = (VCF_SNP<<1)|(VCF_MNP<<1), indel_mask = VCF_INDEL<<1, ref_mask = 1; + bcf_srs_t *files = args->files; + maux_t *maux = args->maux; - // debug_maux(args, pos, var_type); + // debug_maux(args); - // Select records that have the same alleles; the input ordering of indels - // must not matter. Multiple VCF lines can be emitted from this loop. - // We expect only very few alleles and not many records with the same - // position in the buffers, therefore the nested loops should not slow us - // much. - while (1) + // take the most frequent allele present in multiple files, REF is skipped + int i,j,k,icnt = 1; + for (i=2; inals; i++) + if ( maux->cnt[i] > maux->cnt[icnt] ) icnt = i; + + int nout = 0; + for (i=0; inreaders; i++) { - // take the most frequent allele present in multiple files - int icnt = 0; - for (i=1; inals; i++) - if ( maux->cnt[i] > maux->cnt[icnt] ) icnt = i; - if ( maux->cnt[icnt]<0 ) break; + buffer_t *buf = &maux->buf[i]; + buf->cur = -1; + if ( buf->beg >= buf->end ) continue; // no lines in the buffer - int nmask = 0; - for (i=0; inreaders; i++) + // find lines with the same allele + for (j=buf->beg; jend; j++) { - maux->has_line[i] = 0; + if ( buf->rec[j].skip ) continue; // done or not compatible + if ( args->merge_by_id ) break; + if ( maux->nals==1 && buf->lines[j]->n_allele==1 ) break; // REF-only record - bcf_sr_t *reader = &files->readers[i]; - if ( !reader->buffer ) continue; + for (k=0; klines[j]->n_allele; k++) + if ( icnt==buf->rec[j].map[k] ) break; - // find lines with the same allele - int j; - for (j=0; j<=reader->nbuffer; j++) - { - if ( maux->d[i][j].skip ) continue; - int k; - for (k=0; kbuffer[j]->n_allele; k++) - if ( icnt==maux->d[i][j].map[k] ) break; - if ( kbuffer[j]->n_allele ) break; - } - if ( j>reader->nbuffer ) - { - // no matching allele found in this file - if ( args->collapse==COLLAPSE_NONE ) continue; + if ( klines[j]->n_allele ) break; + } + if ( j>=buf->end ) + { + // no matching allele found in this file + if ( args->collapse==COLLAPSE_NONE ) continue; - for (j=0; j<=reader->nbuffer; j++) + for (j=buf->beg; jend; j++) + { + if ( buf->rec[j].skip ) continue; // done or not compatible + if ( args->collapse&COLLAPSE_ANY ) break; // anything can be merged + int line_type = bcf_get_variant_types(buf->lines[j]); + if ( maux->var_types&snp_mask && line_type&VCF_SNP && (args->collapse&COLLAPSE_SNPS) ) break; + if ( maux->var_types&indel_mask && line_type&VCF_INDEL && (args->collapse&COLLAPSE_INDELS) ) break; + if ( line_type==VCF_REF ) { - if ( maux->d[i][j].skip ) continue; - if ( args->collapse&COLLAPSE_ANY ) break; - int line_type = bcf_get_variant_types(reader->buffer[j]); - if ( var_type&VCF_SNP && line_type&VCF_SNP && (args->collapse&COLLAPSE_SNPS) ) break; - if ( var_type&VCF_INDEL && line_type&VCF_INDEL && (args->collapse&COLLAPSE_INDELS) ) break; - if ( line_type==VCF_REF ) - { - if ( var_type&VCF_SNP && (args->collapse&COLLAPSE_SNPS) ) break; - if ( var_type&VCF_INDEL && (args->collapse&COLLAPSE_INDELS) ) break; - } - else if ( var_type==VCF_REF ) - { - if ( line_type&VCF_SNP && (args->collapse&COLLAPSE_SNPS) ) break; - if ( line_type&VCF_INDEL && (args->collapse&COLLAPSE_INDELS) ) break; - } + if ( maux->var_types&snp_mask && (args->collapse&COLLAPSE_SNPS) ) break; + if ( maux->var_types&indel_mask && (args->collapse&COLLAPSE_INDELS) ) break; + if ( maux->var_types&ref_mask ) break; } - } - if ( j<=reader->nbuffer ) - { - // found a suitable line for merging, place it at the beggining - if ( j>0 ) + else if ( maux->var_types&ref_mask ) { - SWAP(bcf1_t*, reader->buffer[0], reader->buffer[j]); - SWAP(maux1_t, maux->d[i][0], maux->d[i][j]); + if ( line_type&snp_mask && (args->collapse&COLLAPSE_SNPS) ) break; + if ( line_type&indel_mask && (args->collapse&COLLAPSE_INDELS) ) break; } - // mark as finished so that it's ignored next time - maux->d[i][0].skip |= SKIP_DONE; - maux->has_line[i] = 1; - nmask++; } } - if ( !nmask ) break; // done, no more lines suitable for merging found - merge_line(args); // merge and output the line - maux->cnt[icnt] = -1; // do not pick this allele again, mark it as finished + if ( jend ) + { + // found a suitable line for merging + buf->cur = j; + + // mark as finished so that it's ignored next time + buf->rec[j].skip = SKIP_DONE; + nout++; + } } + assert( nout ); +} - // clean the alleles - for (i=0; inals; i++) +void merge_line(args_t *args) +{ + if ( args->regs ) { - free(maux->als[i]); - maux->als[i] = 0; + if ( !regidx_overlap(args->regs,args->maux->chr,args->maux->pos,args->maux->pos,NULL) ) return; } - maux->nals = 0; - // get the buffers ready for the next next_line() call - for (i=0; inreaders; i++) - shake_buffer(maux, i, pos); + bcf1_t *out = args->out_line; + merge_chrom2qual(args, out); + merge_filter(args, out); + merge_info(args, out); + if ( args->do_gvcf ) + bcf_update_info_int32(args->out_hdr, out, "END", NULL, 0); + merge_format(args, out); + bcf_write1(args->out_fh, args->out_hdr, out); + bcf_clear1(out); } void bcf_hdr_append_version(bcf_hdr_t *hdr, int argc, char **argv, const char *cmd) @@ -1887,6 +2266,8 @@ void bcf_hdr_append_version(bcf_hdr_t *hdr, int argc, char **argv, const char *c else ksprintf(&str, " %s", argv[i]); } + kputs("; Date=", &str); + time_t tm; time(&tm); kputs(ctime(&tm), &str); kputc('\n', &str); bcf_hdr_append(hdr,str.s); free(str.s); @@ -1898,7 +2279,7 @@ void merge_vcf(args_t *args) { args->out_fh = hts_open(args->output_fname, hts_bcf_wmode(args->output_type)); if ( args->out_fh == NULL ) error("Can't write to \"%s\": %s\n", args->output_fname, strerror(errno)); - if ( args->n_threads ) hts_set_threads(args->out_fh, args->n_threads); + if ( args->n_threads ) hts_set_opt(args->out_fh, HTS_OPT_THREAD_POOL, args->files->p); //hts_set_threads(args->out_fh, args->n_threads); args->out_hdr = bcf_hdr_init("w"); if ( args->header_fname ) @@ -1928,14 +2309,33 @@ void merge_vcf(args_t *args) } if ( args->collapse==COLLAPSE_NONE ) args->vcmp = vcmp_init(); - args->maux = maux_init(args->files); + args->maux = maux_init(args); args->out_line = bcf_init1(); args->tmph = kh_init(strdict); - int ret; - while ( (ret=bcf_sr_next_line(args->files)) ) + + while ( bcf_sr_next_line(args->files) ) { - merge_buffer(args); + // output cached gVCF blocks which end before the new record + if ( args->do_gvcf ) + gvcf_flush(args,0); + + maux_reset(args->maux); + + // determine which of the new records are gvcf blocks + if ( args->do_gvcf ) + gvcf_stage(args, args->maux->pos); + + while ( can_merge(args) ) + { + stage_line(args); + merge_line(args); + } + clean_buffer(args); + // debug_state(args); } + if ( args->do_gvcf ) + gvcf_flush(args,1); + info_rules_destroy(args); maux_destroy(args->maux); bcf_hdr_destroy(args->out_hdr); @@ -1958,7 +2358,10 @@ static void usage(void) fprintf(stderr, " --force-samples resolve duplicate sample names\n"); fprintf(stderr, " --print-header print only the merged header and exit\n"); fprintf(stderr, " --use-header use the provided header\n"); + fprintf(stderr, " -0 --missing-to-ref assume genotypes at missing sites are 0/0\n"); fprintf(stderr, " -f, --apply-filters require at least one of the listed FILTER strings (e.g. \"PASS,.\")\n"); + fprintf(stderr, " -F, --filter-logic remove filters if some input is PASS (\"x\"), or apply all filters (\"+\") [+]\n"); + fprintf(stderr, " -g, --gvcf <-|ref.fa> merge gVCF blocks, INFO/END tag is expected. Implies -i QS:sum,MinDP:min,I16:sum,IDV:max,IMF:max\n"); fprintf(stderr, " -i, --info-rules rules for merging INFO fields (method is one of sum,avg,min,max,join) or \"-\" to turn off the default [DP:sum,DP4:sum]\n"); fprintf(stderr, " -l, --file-list read file names from the file\n"); fprintf(stderr, " -m, --merge allow multiallelic records for , see man page for details [both]\n"); @@ -1989,7 +2392,9 @@ int main_vcfmerge(int argc, char *argv[]) { {"help",no_argument,NULL,'h'}, {"merge",required_argument,NULL,'m'}, + {"gvcf",required_argument,NULL,'g'}, {"file-list",required_argument,NULL,'l'}, + {"missing-to-ref",no_argument,NULL,'0'}, {"apply-filters",required_argument,NULL,'f'}, {"use-header",required_argument,NULL,1}, {"print-header",no_argument,NULL,2}, @@ -2001,10 +2406,25 @@ int main_vcfmerge(int argc, char *argv[]) {"regions-file",required_argument,NULL,'R'}, {"info-rules",required_argument,NULL,'i'}, {"no-version",no_argument,NULL,8}, + {"filter-logic",required_argument,NULL,'F'}, {NULL,0,NULL,0} }; - while ((c = getopt_long(argc, argv, "hm:f:r:R:o:O:i:l:",loptions,NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hm:f:r:R:o:O:i:l:g:F:0",loptions,NULL)) >= 0) { switch (c) { + case 'F': + if ( !strcmp(optarg,"+") ) args->filter_logic = FLT_LOGIC_ADD; + else if ( !strcmp(optarg,"x") ) args->filter_logic = FLT_LOGIC_REMOVE; + else error("Filter logic not recognised: %s\n", optarg); + break; + case '0': args->missing_to_ref = 1; break; + case 'g': + args->do_gvcf = 1; + if ( strcmp("-",optarg) ) + { + args->gvcf_fai = fai_load(optarg); + if ( !args->gvcf_fai ) error("Failed to load the fai index: %s\n", optarg); + } + break; case 'l': args->file_list = optarg; break; case 'i': args->info_rules = optarg; break; case 'o': args->output_fname = optarg; break; @@ -2045,9 +2465,23 @@ int main_vcfmerge(int argc, char *argv[]) if ( argc-optind<2 && !args->file_list ) usage(); args->files->require_index = 1; - if ( args->regions_list && bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 ) - error("Failed to read the regions: %s\n", args->regions_list); + if ( args->regions_list ) + { + if ( bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 ) + error("Failed to read the regions: %s\n", args->regions_list); + if ( regions_is_file ) + args->regs = regidx_init(args->regions_list,NULL,NULL,sizeof(char*),NULL); + else + { + args->regs = regidx_init(NULL,regidx_parse_reg,NULL,sizeof(char*),NULL); + if ( regidx_insert_list(args->regs,args->regions_list,',') !=0 ) error("Could not parse the regions: %s\n", args->regions_list); + regidx_insert(args->regs,NULL); + } + if ( !args->regs ) error("Could not parse the regions: %s\n", args->regions_list); + args->regs_itr = regitr_init(args->regs); + } + if ( bcf_sr_set_threads(args->files, args->n_threads)<0 ) error("Failed to create threads\n"); while (optindfiles, argv[optind]) ) error("Failed to open %s: %s\n", argv[optind],bcf_sr_strerror(args->files->errnum)); @@ -2065,6 +2499,9 @@ int main_vcfmerge(int argc, char *argv[]) } merge_vcf(args); bcf_sr_destroy(args->files); + if ( args->regs ) regidx_destroy(args->regs); + if ( args->regs_itr ) regitr_destroy(args->regs_itr); + if ( args->gvcf_fai ) fai_destroy(args->gvcf_fai); free(args); return 0; } diff --git a/bcftools/vcfmerge.c.pysam.c b/bcftools/vcfmerge.c.pysam.c index daac45838..e1047aeb6 100644 --- a/bcftools/vcfmerge.c.pysam.c +++ b/bcftools/vcfmerge.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfmerge.c -- Merge multiple VCF/BCF files to create one multi-sample file. - Copyright (C) 2012-2014 Genome Research Ltd. + Copyright (C) 2012-2016 Genome Research Ltd. Author: Petr Danecek @@ -26,28 +26,39 @@ THE SOFTWARE. */ #include #include +#include #include #include #include #include #include #include +#include #include #include +#include #include "bcftools.h" +#include "regidx.h" #include "vcmp.h" +#define DBG 0 + #include KHASH_MAP_INIT_STR(strdict, int) typedef khash_t(strdict) strdict_t; -#define SKIP_DONE 1 -#define SKIP_DIFF 2 +#define FLT_LOGIC_ADD 0 +#define FLT_LOGIC_REMOVE 1 + +#define SKIP_DONE 1 // the record was processed +#define SKIP_DIFF 2 // not compatible, merge later #define IS_VL_G(hdr,id) (bcf_hdr_id2length(hdr,BCF_HL_FMT,id) == BCF_VL_G) #define IS_VL_A(hdr,id) (bcf_hdr_id2length(hdr,BCF_HL_FMT,id) == BCF_VL_A) #define IS_VL_R(hdr,id) (bcf_hdr_id2length(hdr,BCF_HL_FMT,id) == BCF_VL_R) +#define SWAP(type_t,a,b) { type_t tmp = (a); (a) = (b); (b) = tmp; } + // For merging INFO Number=A,G,R tags typedef struct { @@ -65,43 +76,60 @@ typedef struct _info_rule_t void (*merger)(bcf_hdr_t *hdr, bcf1_t *line, struct _info_rule_t *rule); int type; // one of BCF_HT_* int block_size; // number of values in a block + int type_size; // size of the corresponding BCF_HT_* type int nblocks; // number of blocks in nvals (the number of merged files) int nvals, mvals; // used and total size of vals array void *vals; // the info tag values } info_rule_t; +typedef struct +{ + bcf1_t *line; + int end, active; +} +gvcf_aux_t; + // Auxiliary merge data for selecting the right combination // of buffered records across multiple readers. maux1_t // corresponds to one buffered line. typedef struct { int skip; - int *map; // mapping from input alleles to the output array + int *map; // mapping from input alleles to the array of output alleles (set by merge_alleles) int mmap; // size of map array (only buffer[i].n_allele is actually used) int als_differ; } maux1_t; typedef struct { - int n; // number of readers + int rid; // current rid + int beg,end; // valid ranges in reader's buffer [beg,end). Maintained by maux_reset and gvcf_flush. + int cur; // current line or -1 if none + int mrec; // allocated size of buf + maux1_t *rec; // buffer to keep reader's lines + bcf1_t **lines; // source buffer: either gvcf or readers' buffer +} +buffer_t; +typedef struct +{ + int n, pos, var_types; // number of readers, current position, currently available variant types + char *chr; // current chromosome char **als, **out_als; // merged alleles (temp, may contain empty records) and merged alleles ready for output int nals, mals, nout_als, mout_als; // size of the output array int *cnt, ncnt; // number of records that refer to the alleles - int *nbuf; // readers have buffers of varying lengths int *smpl_ploidy, *smpl_nGsize; // ploidy and derived number of values in Number=G tags, updated for each line (todo: cache for missing cases) - int *flt, mflt, minf; - bcf_info_t *inf;// out_line's INFO fields bcf_fmt_t **fmt_map; // i-th output FORMAT field corresponds in j-th reader to i*nreader+j, first row is reserved for GT int nfmt_map; // number of rows in the fmt_map array int *agr_map, nagr_map, magr_map; // mapping between Number=AGR element indexes void *tmp_arr; int ntmp_arr; - maux1_t **d; // d[i][j] i-th reader, j-th buffer line + buffer_t *buf; AGR_info_t *AGR_info; int nAGR_info, mAGR_info; bcf_srs_t *files; - int *has_line; // which files are being merged + int gvcf_min, gvcf_break; // min buffered gvcf END position (NB: gvcf_min is 1-based) or 0 if no active lines are present + gvcf_aux_t *gvcf; // buffer of gVCF lines } maux_t; @@ -109,8 +137,11 @@ typedef struct { vcmp_t *vcmp; maux_t *maux; - int header_only, collapse, output_type, force_samples, merge_by_id; + regidx_t *regs; // apply regions only after the blocks are expanded + regitr_t *regs_itr; + int header_only, collapse, output_type, force_samples, merge_by_id, do_gvcf, filter_logic, missing_to_ref; char *header_fname, *output_fname, *regions_list, *info_rules, *file_list; + faidx_t *gvcf_fai; info_rule_t *rules; int nrules; strdict_t *tmph; @@ -124,6 +155,14 @@ typedef struct } args_t; +static bcf1_t *maux_get_line(args_t *args, int i) +{ + maux_t *ma = args->maux; + int ibuf = ma->buf[i].cur; + if ( ibuf >= 0 ) return ma->buf[i].lines[ibuf]; + return NULL; +} + static void info_rules_merge_sum(bcf_hdr_t *hdr, bcf1_t *line, info_rule_t *rule) { if ( !rule->nvals ) return; @@ -249,6 +288,32 @@ static void info_rules_init(args_t *args) if ( str.l ) kputc(',',&str); kputs("DP4:sum",&str); } + if ( args->do_gvcf && bcf_hdr_idinfo_exists(args->out_hdr,BCF_HL_INFO,bcf_hdr_id2int(args->out_hdr, BCF_DT_ID, "QS")) ) + { + if ( str.l ) kputc(',',&str); + kputs("QS:sum",&str); + } + if ( args->do_gvcf && bcf_hdr_idinfo_exists(args->out_hdr,BCF_HL_INFO,bcf_hdr_id2int(args->out_hdr, BCF_DT_ID, "MinDP")) ) + { + if ( str.l ) kputc(',',&str); + kputs("MinDP:min",&str); + } + if ( args->do_gvcf && bcf_hdr_idinfo_exists(args->out_hdr,BCF_HL_INFO,bcf_hdr_id2int(args->out_hdr, BCF_DT_ID, "I16")) ) + { + if ( str.l ) kputc(',',&str); + kputs("I16:sum",&str); + } + if ( args->do_gvcf && bcf_hdr_idinfo_exists(args->out_hdr,BCF_HL_INFO,bcf_hdr_id2int(args->out_hdr, BCF_DT_ID, "IDV")) ) + { + if ( str.l ) kputc(',',&str); + kputs("IDV:max",&str); + } + if ( args->do_gvcf && bcf_hdr_idinfo_exists(args->out_hdr,BCF_HL_INFO,bcf_hdr_id2int(args->out_hdr, BCF_DT_ID, "IMF")) ) + { + if ( str.l ) kputc(',',&str); + kputs("IMF:max",&str); + } + if ( !str.l ) return; args->info_rules = str.s; } @@ -274,9 +339,12 @@ static void info_rules_init(args_t *args) int id = bcf_hdr_id2int(args->out_hdr, BCF_DT_ID, rule->hdr_tag); if ( !bcf_hdr_idinfo_exists(args->out_hdr,BCF_HL_INFO,id) ) error("The tag is not defined in the header: \"%s\"\n", rule->hdr_tag); rule->type = bcf_hdr_id2type(args->out_hdr,BCF_HL_INFO,id); - if ( rule->type!=BCF_HT_INT && rule->type!=BCF_HT_REAL && rule->type!=BCF_HT_STR ) error("The type is not supported: \"%s\"\n", rule->hdr_tag); + if ( rule->type==BCF_HT_INT ) rule->type_size = sizeof(int32_t); + else if ( rule->type==BCF_HT_REAL ) rule->type_size = sizeof(float); + else if ( rule->type==BCF_HT_STR ) rule->type_size = sizeof(char); + else error("The type is not supported: \"%s\"\n", rule->hdr_tag); - while ( *ss ) ss++; ss++; + ss = strchr(ss, '\0'); ss++; if ( !*ss ) error("Could not parse INFO rules, missing logic of \"%s\"\n", rule->hdr_tag); int is_join = 0; @@ -302,7 +370,8 @@ static void info_rules_init(args_t *args) error("Only fixed-length vectors are supported with -i %s:%s\n", ss, rule->hdr_tag); } - while ( *ss ) ss++; ss++; n++; + ss = strchr(ss, '\0'); ss++; + n++; } free(str.s); free(tmp); @@ -328,8 +397,10 @@ static void info_rules_reset(args_t *args) } static int info_rules_add_values(args_t *args, bcf_hdr_t *hdr, bcf1_t *line, info_rule_t *rule, maux1_t *als, int var_len) { - int ret = bcf_get_info_values(hdr, line, rule->hdr_tag, &args->maux->tmp_arr, &args->maux->ntmp_arr, rule->type); + int msize = args->maux->ntmp_arr / rule->type_size; + int ret = bcf_get_info_values(hdr, line, rule->hdr_tag, &args->maux->tmp_arr, &msize, rule->type); if ( ret<=0 ) error("FIXME: error parsing %s at %s:%d .. %d\n", rule->hdr_tag,bcf_seqname(hdr,line),line->pos+1,ret); + args->maux->ntmp_arr = msize * rule->type_size; rule->nblocks++; @@ -347,7 +418,7 @@ static int info_rules_add_values(args_t *args, bcf_hdr_t *hdr, bcf1_t *line, inf int i, j; if ( var_len==BCF_VL_A ) { - assert( ret==line->n_allele-1 ); + if ( ret!=line->n_allele-1 ) error("Wrong number of %s fields at %s:%d\n",rule->hdr_tag,bcf_seqname(hdr,line),line->pos+1); args->maux->nagr_map = ret; hts_expand(int,args->maux->nagr_map,args->maux->magr_map,args->maux->agr_map); // create mapping from source file ALT indexes to dst file indexes @@ -356,7 +427,7 @@ static int info_rules_add_values(args_t *args, bcf_hdr_t *hdr, bcf1_t *line, inf } else if ( var_len==BCF_VL_R ) { - assert( ret==line->n_allele ); + if ( ret!=line->n_allele ) error("Wrong number of %s fields at %s:%d\n",rule->hdr_tag,bcf_seqname(hdr,line),line->pos+1); args->maux->nagr_map = ret; hts_expand(int,args->maux->nagr_map,args->maux->magr_map,args->maux->agr_map); for (i=0; imaux->agr_map[i] = als->map[i]; @@ -451,8 +522,8 @@ void merge_headers(bcf_hdr_t *hw, const bcf_hdr_t *hr, const char *clash_prefix, void debug_als(char **als, int nals) { - int k; for (k=0; krla ) // $a alleles need expanding + if ( rlb>rla && a[i][0]!='<' && a[i][0]!='*' ) // $a alleles need expanding and not a symbolic allele or * { int l = strlen(a[i]); ai = (char*) malloc(l+rlb-rla+1); memcpy(ai,a[i],l); memcpy(ai+l,b[0]+rla,rlb-rla+1); + const_ai = 0; } else ai = a[i]; @@ -584,42 +659,58 @@ char **merge_alleles(char **a, int na, int *map, char **b, int *nb, int *mb) if ( j<*nb ) // $b already has the same allele { map[i] = j; - if ( rlb>rla ) free(ai); + if ( !const_ai ) free(ai); continue; } // new allele map[i] = *nb; - b[*nb] = rlb>rla ? ai : strdup(ai); + b[*nb] = const_ai ? strdup(ai) : ai; (*nb)++; } return b; } -maux_t *maux_init(bcf_srs_t *files) +maux_t *maux_init(args_t *args) { + bcf_srs_t *files = args->files; maux_t *ma = (maux_t*) calloc(1,sizeof(maux_t)); ma->n = files->nreaders; - ma->nbuf = (int *) calloc(ma->n,sizeof(int)); - ma->d = (maux1_t**) calloc(ma->n,sizeof(maux1_t*)); ma->files = files; int i, n_smpl = 0; for (i=0; in; i++) n_smpl += bcf_hdr_nsamples(files->readers[i].header); + if ( args->do_gvcf ) + { + ma->gvcf = (gvcf_aux_t*) calloc(ma->n,sizeof(gvcf_aux_t)); + for (i=0; in; i++) + ma->gvcf[i].line = bcf_init1(); + } ma->smpl_ploidy = (int*) calloc(n_smpl,sizeof(int)); ma->smpl_nGsize = (int*) malloc(n_smpl*sizeof(int)); - ma->has_line = (int*) malloc(ma->n*sizeof(int)); + ma->buf = (buffer_t*) calloc(ma->n,sizeof(buffer_t)); + for (i=0; in; i++) + ma->buf[i].rid = -1; return ma; } void maux_destroy(maux_t *ma) { - int i; + int i,j; + for (i=0; imals; i++) + { + free(ma->als[i]); + ma->als[i] = NULL; + } for (i=0; in; i++) // for each reader { - if ( !ma->d[i] ) continue; - int j; - for (j=0; jnbuf[i]; j++) // for each buffered line - if ( ma->d[i][j].map ) free(ma->d[i][j].map); - free(ma->d[i]); + for (j=0; jbuf[i].mrec; j++) // for each buffered line + free(ma->buf[i].rec[j].map); + free(ma->buf[i].rec); + } + free(ma->buf); + if ( ma->gvcf ) + { + for (i=0; in; i++) bcf_destroy(ma->gvcf[i].line); + free(ma->gvcf); } for (i=0; imAGR_info; i++) free(ma->AGR_info[i].buf); @@ -628,42 +719,82 @@ void maux_destroy(maux_t *ma) if (ma->ntmp_arr) free(ma->tmp_arr); if (ma->nfmt_map) free(ma->fmt_map); // ma->inf freed in bcf_destroy1 - free(ma->d); - free(ma->nbuf); for (i=0; imals; i++) free(ma->als[i]); if (ma->mout_als) free(ma->out_als); free(ma->als); free(ma->cnt); free(ma->smpl_ploidy); free(ma->smpl_nGsize); - free(ma->has_line); + free(ma->chr); free(ma); } -void maux_expand1(maux_t *ma, int i) +void maux_expand1(buffer_t *buf, int size) { - if ( ma->nbuf[i] <= ma->files->readers[i].nbuffer ) + if ( buf->mrec < size ) { - int n = ma->files->readers[i].nbuffer + 1; - ma->d[i] = (maux1_t*) realloc(ma->d[i], sizeof(maux1_t)*n); - memset(ma->d[i]+ma->nbuf[i],0,sizeof(maux1_t)*(n-ma->nbuf[i])); - ma->nbuf[i] = n; + hts_expand0(maux1_t,size,buf->mrec,buf->rec); + buf->mrec = size; } } void maux_reset(maux_t *ma) { - int i; - for (i=0; in; i++) maux_expand1(ma, i); - for (i=1; incnt; i++) ma->cnt[i] = 0; + int i,j; + for (i=0; in; i++) maux_expand1(&ma->buf[i],ma->files->readers[i].nbuffer+1); + for (i=0; incnt; i++) ma->cnt[i] = 0; + for (i=0; imals; i++) + { + free(ma->als[i]); + ma->als[i] = NULL; + } + const char *chr = NULL; + ma->nals = 0; + ma->pos = -1; + for (i=0; in; i++) + { + if ( !bcf_sr_has_line(ma->files,i) ) continue; + bcf1_t *line = bcf_sr_get_line(ma->files,i); + bcf_hdr_t *hdr = bcf_sr_get_header(ma->files,i); + chr = bcf_seqname(hdr,line); + ma->pos = line->pos; + break; + } + int new_chr = 0; + if ( chr && (!ma->chr || strcmp(ma->chr,chr)) ) + { + free(ma->chr); + ma->chr = strdup(chr); + new_chr = 1; + } + for (i=0; in; i++) + { + bcf_hdr_t *hdr = bcf_sr_get_header(ma->files,i); + ma->buf[i].rid = bcf_hdr_name2id(hdr,chr); + ma->buf[i].beg = bcf_sr_has_line(ma->files,i) ? 0 : 1; + for (j=ma->buf[i].beg; j<=ma->files->readers[i].nbuffer; j++) + { + ma->buf[i].rec[j].skip = 0; + bcf1_t *line = ma->files->readers[i].buffer[j]; + if ( line->rid!=ma->buf[i].rid || line->pos!=ma->pos ) break; + } + ma->buf[i].end = j; + ma->buf[i].cur = -1; + if ( ma->buf[i].beg < ma->buf[i].end ) + { + ma->buf[i].lines = ma->files->readers[i].buffer; + if ( ma->gvcf ) ma->gvcf[i].active = 0; // gvcf block cannot overlap with the next record + } + if ( new_chr && ma->gvcf ) ma->gvcf[i].active = 0; // make sure to close active gvcf block on new chr + } } void maux_debug(maux_t *ma, int ir, int ib) { - fprintf(pysam_stdout, "[%d,%d]\t", ir,ib); + fprintf(bcftools_stdout, "[%d,%d]\t", ir,ib); int i; for (i=0; inals; i++) { - fprintf(pysam_stdout, " %s [%d]", ma->als[i], ma->cnt[i]); + fprintf(bcftools_stdout, " %s [%d]", ma->als[i], ma->cnt[i]); } - fprintf(pysam_stdout, "\n"); + fprintf(bcftools_stdout, "\n"); } void merge_chrom2qual(args_t *args, bcf1_t *out) @@ -686,16 +817,20 @@ void merge_chrom2qual(args_t *args, bcf1_t *out) out->pos = -1; for (i=0; inreaders; i++) { - if ( !ma->has_line[i] ) continue; + bcf1_t *line = maux_get_line(args, i); + if ( !line ) continue; + bcf_unpack(line, BCF_UN_ALL); bcf_sr_t *reader = &files->readers[i]; - bcf1_t *line = reader->buffer[0]; bcf_hdr_t *hdr = reader->header; - // alleles + // not all maux alleles are always used, mark the ones we'll need int j; for (j=1; jn_allele; j++) - al_idxs[ ma->d[i][0].map[j] ] = 1; + { + int irec = ma->buf[i].cur; + al_idxs[ ma->buf[i].rec[irec].map[j] ] = 1; + } // position if ( out->pos==-1 ) @@ -719,16 +854,15 @@ void merge_chrom2qual(args_t *args, bcf1_t *out) } // set QUAL to the max qual value. Not exactly correct, but good enough for now - if ( !bcf_float_is_missing(files->readers[i].buffer[0]->qual) ) + if ( !bcf_float_is_missing(line->qual) ) { - if ( bcf_float_is_missing(out->qual) || out->qual < files->readers[i].buffer[0]->qual ) out->qual = files->readers[i].buffer[0]->qual; + if ( bcf_float_is_missing(out->qual) || out->qual < line->qual ) out->qual = line->qual; } } // set ID if ( !tmps->l ) kputs(".", tmps); - if ( out->d.id ) free(out->d.id); - out->d.id = strdup(tmps->s); + bcf_update_id(out_hdr, out, tmps->s); // set alleles ma->nout_als = 0; @@ -742,10 +876,13 @@ void merge_chrom2qual(args_t *args, bcf1_t *out) int ir, j; for (ir=0; irnreaders; ir++) { - if ( !ma->has_line[ir] ) continue; - bcf1_t *line = files->readers[ir].buffer[0]; + bcf1_t *line = maux_get_line(args,ir); + if ( !line ) continue; for (j=1; jn_allele; j++) - if ( ma->d[ir][0].map[j]==i ) ma->d[ir][0].map[j] = ma->nout_als; + { + int irec = ma->buf[ir].cur; + if ( ma->buf[ir].rec[irec].map[j]==i ) ma->buf[ir].rec[irec].map[j] = ma->nout_als; + } } } // Expand the arrays and realloc the alleles string. Note that all alleles are in a single allocated block. @@ -767,20 +904,36 @@ void merge_filter(args_t *args, bcf1_t *out) bcf_hdr_t *out_hdr = args->out_hdr; int i, ret; + if ( args->filter_logic == FLT_LOGIC_REMOVE ) + { + for (i=0; inreaders; i++) + { + bcf1_t *line = maux_get_line(args, i); + if ( !line ) continue; + bcf_sr_t *reader = &files->readers[i]; + bcf_hdr_t *hdr = reader->header; + if ( bcf_has_filter(hdr, line, "PASS") ) break; + } + if ( inreaders ) + { + int flt_id = bcf_hdr_id2int(out_hdr, BCF_DT_ID, "PASS"); + bcf_add_filter(out_hdr, out, flt_id); + return; + } + } + khiter_t kitr; strdict_t *tmph = args->tmph; kh_clear(strdict, tmph); - maux_t *ma = args->maux; out->d.n_flt = 0; for (i=0; inreaders; i++) { - if ( !ma->has_line[i]) continue; + bcf1_t *line = maux_get_line(args, i); + if ( !line ) continue; bcf_sr_t *reader = &files->readers[i]; - bcf1_t *line = reader->buffer[0]; bcf_hdr_t *hdr = reader->header; - bcf_unpack(line, BCF_UN_ALL); int k; for (k=0; kd.n_flt; k++) @@ -791,8 +944,8 @@ void merge_filter(args_t *args, bcf1_t *out) { int id = bcf_hdr_id2int(out_hdr, BCF_DT_ID, flt); if ( id==-1 ) error("Error: The filter is not defined in the header: %s\n", flt); - hts_expand(int,out->d.n_flt+1,ma->mflt,ma->flt); - ma->flt[out->d.n_flt] = id; + hts_expand(int,out->d.n_flt+1,out->d.m_flt,out->d.flt); + out->d.flt[out->d.n_flt] = id; out->d.n_flt++; kh_put(strdict, tmph, flt, &ret); } @@ -803,20 +956,17 @@ void merge_filter(args_t *args, bcf1_t *out) { int id = bcf_hdr_id2int(out_hdr, BCF_DT_ID, "PASS"); for (i=0; id.n_flt; i++) - if ( ma->flt[i]==id ) break; + if ( out->d.flt[i]==id ) break; if ( id.n_flt ) { out->d.n_flt--; - for (; id.n_flt; i++) ma->flt[i] = ma->flt[i+1]; + for (; id.n_flt; i++) out->d.flt[i] = out->d.flt[i+1]; } } - out->d.flt = ma->flt; } static void bcf_info_set_id(bcf1_t *line, bcf_info_t *info, int id, kstring_t *tmp_str) { - assert( !info->vptr_free ); - uint8_t *ptr = info->vptr - info->vptr_off; bcf_dec_typed_int1(ptr, &ptr); @@ -835,8 +985,6 @@ static void bcf_info_set_id(bcf1_t *line, bcf_info_t *info, int id, kstring_t *t kputsn_(info->vptr, info->len << bcf_type_shift[info->type], tmp_str); info->vptr = (uint8_t*) tmp_str->s + info->vptr_off; - info->vptr_free = 1; - line->d.shared_dirty |= BCF1_DIRTY_INF; tmp_str->s = NULL; tmp_str->m = 0; tmp_str->l = 0; @@ -946,7 +1094,7 @@ static void merge_AGR_info_tag(bcf_hdr_t *hdr, bcf1_t *line, bcf_info_t *info, i case BCF_BT_INT16: BRANCH(int16_t, *src==bcf_int16_missing, *src==bcf_int16_vector_end, int); break; case BCF_BT_INT32: BRANCH(int32_t, *src==bcf_int32_missing, *src==bcf_int32_vector_end, int); break; case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(*src), bcf_float_is_vector_end(*src), float); break; - default: fprintf(pysam_stderr,"TODO: %s:%d .. info->type=%d\n", __FILE__,__LINE__, info->type); exit(1); + default: fprintf(bcftools_stderr,"TODO: %s:%d .. info->type=%d\n", __FILE__,__LINE__, info->type); exit(1); } #undef BRANCH } @@ -976,7 +1124,7 @@ static void merge_AGR_info_tag(bcf_hdr_t *hdr, bcf1_t *line, bcf_info_t *info, i case BCF_BT_INT16: BRANCH(int16_t, src[kori]==bcf_int16_missing, src[kori]==bcf_int16_vector_end, int); break; case BCF_BT_INT32: BRANCH(int32_t, src[kori]==bcf_int32_missing, src[kori]==bcf_int32_vector_end, int); break; case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(src[kori]), bcf_float_is_vector_end(src[kori]), float); break; - default: fprintf(pysam_stderr,"TODO: %s:%d .. info->type=%d\n", __FILE__,__LINE__, info->type); exit(1); + default: fprintf(bcftools_stderr,"TODO: %s:%d .. info->type=%d\n", __FILE__,__LINE__, info->type); exit(1); } #undef BRANCH } @@ -1031,9 +1179,10 @@ void merge_info(args_t *args, bcf1_t *out) info_rules_reset(args); for (i=0; inreaders; i++) { - if ( !ma->has_line[i] ) continue; + bcf1_t *line = maux_get_line(args,i); + if ( !line ) continue; + int irec = ma->buf[i].cur; bcf_sr_t *reader = &files->readers[i]; - bcf1_t *line = reader->buffer[0]; bcf_hdr_t *hdr = reader->header; for (j=0; jn_info; j++) { @@ -1052,7 +1201,7 @@ void merge_info(args_t *args, bcf1_t *out) info_rule_t *rule = (info_rule_t*) bsearch(key, args->rules, args->nrules, sizeof(*args->rules), info_rules_comp_key); if ( rule ) { - maux1_t *als = ( len==BCF_VL_A || len==BCF_VL_G || len==BCF_VL_R ) ? &ma->d[i][0] : NULL; + maux1_t *als = ( len==BCF_VL_A || len==BCF_VL_G || len==BCF_VL_R ) ? &ma->buf[i].rec[irec] : NULL; if ( info_rules_add_values(args, hdr, line, rule, als, len) ) continue; } } @@ -1063,7 +1212,7 @@ void merge_info(args_t *args, bcf1_t *out) { if ( kitr == kh_end(tmph) ) { - // first occurance in this reader, alloc arrays + // seeing this key for the first time ma->nAGR_info++; hts_expand0(AGR_info_t,ma->nAGR_info,ma->mAGR_info,ma->AGR_info); kitr = kh_put(strdict, tmph, key, &ret); @@ -1081,37 +1230,36 @@ void merge_info(args_t *args, bcf1_t *out) kitr = kh_get(strdict, tmph, key); int idx = kh_val(tmph, kitr); if ( idx<0 ) error("Error occurred while processing INFO tag \"%s\" at %s:%d\n", key,bcf_seqname(hdr,line),line->pos+1); - merge_AGR_info_tag(hdr, line,inf,len,&ma->d[i][0],&ma->AGR_info[idx]); + merge_AGR_info_tag(hdr, line,inf,len,&ma->buf[i].rec[irec],&ma->AGR_info[idx]); continue; } if ( kitr == kh_end(tmph) ) { - hts_expand0(bcf_info_t,out->n_info+1,ma->minf,ma->inf); - ma->inf[out->n_info].key = id; - ma->inf[out->n_info].type = inf->type; - ma->inf[out->n_info].len = inf->len; - ma->inf[out->n_info].vptr = inf->vptr; - ma->inf[out->n_info].v1.i = inf->v1.i; - ma->inf[out->n_info].v1.f = inf->v1.f; - ma->inf[out->n_info].vptr_off = inf->vptr_off; - ma->inf[out->n_info].vptr_len = inf->vptr_len; - ma->inf[out->n_info].vptr_free = inf->vptr_free; + // Seeing this key for the first time. Although quite hacky, + // this is faster than anything else given the data structures.. + + hts_expand0(bcf_info_t,out->n_info+1,out->d.m_info,out->d.info); + out->d.info[out->n_info].key = id; + out->d.info[out->n_info].type = inf->type; + out->d.info[out->n_info].len = inf->len; + out->d.info[out->n_info].v1.i = inf->v1.i; + out->d.info[out->n_info].v1.f = inf->v1.f; + out->d.info[out->n_info].vptr_off = inf->vptr_off; + out->d.info[out->n_info].vptr_len = inf->vptr_len; + out->d.info[out->n_info].vptr_free = 1; + out->d.info[out->n_info].vptr = (uint8_t*) malloc(inf->vptr_len+inf->vptr_off); + memcpy(out->d.info[out->n_info].vptr,inf->vptr-inf->vptr_off, inf->vptr_len+inf->vptr_off); + out->d.info[out->n_info].vptr += inf->vptr_off; if ( (args->output_type & FT_BCF) && id!=bcf_hdr_id2int(hdr, BCF_DT_ID, key) ) - { - // The existing packed info cannot be reused. Change the id. - // Although quite hacky, it's faster than anything else given - // the data structures - bcf_info_set_id(out, &ma->inf[out->n_info], id, &args->tmps); - } + bcf_info_set_id(out, &out->d.info[out->n_info], id, &args->tmps); + out->d.shared_dirty |= BCF1_DIRTY_INF; out->n_info++; kitr = kh_put(strdict, tmph, key, &ret); kh_val(tmph,kitr) = -(out->n_info-1); // arbitrary negative value } } } - out->d.info = ma->inf; - out->d.m_info = ma->minf; for (i=0; inrules; i++) args->rules[i].merger(args->out_hdr, out, &args->rules[i]); for (i=0; inAGR_info; i++) @@ -1156,12 +1304,14 @@ void merge_GT(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) } memset(ma->smpl_ploidy,0,nsamples*sizeof(int)); + int default_gt = args->missing_to_ref ? bcf_gt_unphased(0) : bcf_gt_missing; for (i=0; inreaders; i++) { bcf_sr_t *reader = &files->readers[i]; bcf_hdr_t *hdr = reader->header; bcf_fmt_t *fmt_ori = fmt_map[i]; int32_t *tmp = (int32_t *) ma->tmp_arr + ismpl*nsize; + int irec = ma->buf[i].cur; int j, k; if ( !fmt_ori ) @@ -1169,7 +1319,7 @@ void merge_GT(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) // missing values: assume maximum ploidy for (j=0; jsmpl_ploidy[ismpl+j]++; } + for (k=0; ksmpl_ploidy[ismpl+j]++; } tmp += nsize; } ismpl += bcf_hdr_nsamples(hdr); @@ -1178,7 +1328,7 @@ void merge_GT(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) #define BRANCH(type_t, vector_end) { \ type_t *p_ori = (type_t*) fmt_ori->p; \ - if ( !ma->d[i][0].als_differ ) \ + if ( !ma->buf[i].rec[irec].als_differ ) \ { \ /* the allele numbering is unchanged */ \ for (j=0; j>1) - 1; \ - al = al<=0 ? al + 1 : ma->d[i][0].map[al] + 1; \ + al = al<=0 ? al + 1 : ma->buf[i].rec[irec].map[al] + 1; \ tmp[k] = (al << 1) | ((p_ori[k])&1); \ } \ } \ @@ -1241,7 +1391,7 @@ void merge_format_field(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) int nsize = 0, length = BCF_VL_FIXED, type = -1; for (i=0; inreaders; i++) { - if ( !ma->has_line[i] ) continue; + if ( !maux_get_line(args,i) ) continue; if ( !fmt_map[i] ) continue; if ( !key ) key = files->readers[i].header->id[BCF_DT_ID][fmt_map[i]->id].key; type = fmt_map[i]->type; @@ -1279,10 +1429,12 @@ void merge_format_field(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) bcf_sr_t *reader = &files->readers[i]; bcf_hdr_t *hdr = reader->header; bcf_fmt_t *fmt_ori = fmt_map[i]; + bcf1_t *line = maux_get_line(args, i); + int irec = ma->buf[i].cur; if ( fmt_ori ) { type = fmt_ori->type; - int nals_ori = reader->buffer[0]->n_allele; + int nals_ori = line->n_allele; if ( length==BCF_VL_G ) { // if all fields are missing then n==1 is valid @@ -1315,10 +1467,8 @@ void merge_format_field(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) ismpl += bcf_hdr_nsamples(hdr); \ continue; \ } \ - assert( ma->has_line[i] ); \ - bcf1_t *line = reader->buffer[0]; \ src_type_t *src = (src_type_t*) fmt_ori->p; \ - if ( (length!=BCF_VL_G && length!=BCF_VL_A && length!=BCF_VL_R) || (line->n_allele==out->n_allele && !ma->d[i][0].als_differ) ) \ + if ( (length!=BCF_VL_G && length!=BCF_VL_A && length!=BCF_VL_R) || (line->n_allele==out->n_allele && !ma->buf[i].rec[irec].als_differ) ) \ { \ /* alleles unchanged, copy over */ \ for (j=0; jn_allele; iori++) \ { \ - inew = ma->d[i][0].map[iori]; \ + inew = ma->buf[i].rec[irec].map[iori]; \ src = (src_type_t*) fmt_ori->p + j*fmt_ori->n + iori; \ tgt = (tgt_type_t *) ma->tmp_arr + (ismpl+j)*nsize + inew; \ if ( src_is_vector_end ) break; \ @@ -1374,10 +1524,10 @@ void merge_format_field(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) int iori,jori, inew,jnew; \ for (iori=0; iorin_allele; iori++) \ { \ - inew = ma->d[i][0].map[iori]; \ + inew = ma->buf[i].rec[irec].map[iori]; \ for (jori=0; jori<=iori; jori++) \ { \ - jnew = ma->d[i][0].map[jori]; \ + jnew = ma->buf[i].rec[irec].map[jori]; \ int kori = iori*(iori+1)/2 + jori; \ int knew = inew>jnew ? inew*(inew+1)/2 + jnew : jnew*(jnew+1)/2 + inew; \ src = (src_type_t*) fmt_ori->p + j*fmt_ori->n + kori; \ @@ -1414,7 +1564,7 @@ void merge_format_field(args_t *args, bcf_fmt_t **fmt_map, bcf1_t *out) int iori,inew; \ for (iori=ifrom; iorin_allele; iori++) \ { \ - inew = ma->d[i][0].map[iori] - ifrom; \ + inew = ma->buf[i].rec[irec].map[iori] - ifrom; \ tgt = (tgt_type_t *) ma->tmp_arr + (ismpl+j)*nsize + inew; \ if ( src_is_vector_end ) break; \ if ( src_is_missing ) tgt_set_missing; \ @@ -1463,9 +1613,9 @@ void merge_format(args_t *args, bcf1_t *out) int i, j, ret, has_GT = 0, max_ifmt = 0; // max fmt index for (i=0; inreaders; i++) { - if ( !ma->has_line[i] ) continue; + bcf1_t *line = maux_get_line(args,i); + if ( !line ) continue; bcf_sr_t *reader = &files->readers[i]; - bcf1_t *line = reader->buffer[0]; bcf_hdr_t *hdr = reader->header; for (j=0; jn_fmt; j++) { @@ -1497,9 +1647,10 @@ void merge_format(args_t *args, bcf1_t *out) ma->fmt_map[ifmt*files->nreaders+i] = fmt; } // Check if the allele numbering must be changed - for (j=1; jbuffer[0]->n_allele; j++) - if ( ma->d[i][0].map[j]!=j ) break; - ma->d[i][0].als_differ = j==reader->buffer[0]->n_allele ? 0 : 1; + int irec = ma->buf[i].cur; + for (j=1; jn_allele; j++) + if ( ma->buf[i].rec[irec].map[j]!=j ) break; + ma->buf[i].rec[irec].als_differ = j==line->n_allele ? 0 : 1; } out->n_sample = bcf_hdr_nsamples(out_hdr); @@ -1507,203 +1658,419 @@ void merge_format(args_t *args, bcf1_t *out) merge_GT(args, ma->fmt_map, out); update_AN_AC(out_hdr, out); - if ( out->d.info!=ma->inf ) - { - // hacky, we rely on htslib internals: bcf_update_info() reallocated the info - ma->inf = out->d.info; - ma->minf = out->d.m_info; - } - for (i=1; i<=max_ifmt; i++) merge_format_field(args, &ma->fmt_map[i*files->nreaders], out); out->d.indiv_dirty = 1; } -// The core merging function, one or none line from each reader -void merge_line(args_t *args) +void gvcf_set_alleles(args_t *args) +{ + int i,k; + bcf_srs_t *files = args->files; + maux_t *maux = args->maux; + gvcf_aux_t *gaux = maux->gvcf; + for (i=0; inals; i++) + { + free(maux->als[i]); + maux->als[i] = NULL; + } + maux->nals = 0; + + for (i=0; inreaders; i++) + { + if ( !gaux[i].active ) continue; + bcf1_t *line = maux_get_line(args, i); + int irec = maux->buf[i].cur; + + hts_expand(int, line->n_allele, maux->buf[i].rec[irec].mmap, maux->buf[i].rec[irec].map); + if ( !maux->nals ) // first record, copy the alleles to the output + { + maux->nals = line->n_allele; + hts_expand0(char*, maux->nals, maux->mals, maux->als); + hts_expand0(int, maux->nals, maux->ncnt, maux->cnt); + for (k=0; knals; k++) + { + if ( maux->als[k] ) free(maux->als[k]); + maux->als[k] = strdup(line->d.allele[k]); + maux->buf[i].rec[irec].map[k] = k; + } + } + else + { + maux->als = merge_alleles(line->d.allele, line->n_allele, maux->buf[i].rec[irec].map, maux->als, &maux->nals, &maux->mals); + if ( !maux->als ) + { + bcf_hdr_t *hdr = bcf_sr_get_header(args->files,i); + error("Failed to merge alleles at %s:%d\n",bcf_seqname(hdr,line),line->pos+1); + } + } + } +} + +/* + Output staged gVCF blocks, end is the last position of the block. Assuming + gaux[i].active flags are set and maux_get_line returns correct lines. +*/ +void gvcf_write_block(args_t *args, int start, int end) { + int i; + maux_t *maux = args->maux; + gvcf_aux_t *gaux = maux->gvcf; + assert(gaux); + + // Update POS + int min = INT_MAX; + char ref = 'N'; + for (i=0; ifiles->nreaders; i++) + { + if ( !gaux[i].active ) continue; + if ( ref=='N' && gaux[i].line->pos==start ) ref = gaux[i].line->d.allele[0][0]; + gaux[i].line->pos = start; + } + for (i=0; ifiles->nreaders; i++) + { + if ( !gaux[i].active ) continue; + if ( gaux[i].end < start ) + { + gaux[i].active = 0; + maux->buf[i].cur = -1; + continue; + } + gaux[i].line->d.allele[0][0] = ref; + if ( min > gaux[i].end ) min = gaux[i].end; + } + // Check for valid gVCF blocks in this region + if ( min==INT_MAX ) + { + assert(0); + maux->gvcf_min = 0; + return; + } + bcf1_t *out = args->out_line; - bcf_clear1(out); - out->unpacked = BCF_UN_ALL; + gvcf_set_alleles(args); + + // Merge the staged lines merge_chrom2qual(args, out); merge_filter(args, out); merge_info(args, out); merge_format(args, out); - bcf_write1(args->out_fh, args->out_hdr, out); -} + if ( args->gvcf_fai && out->d.allele[0][0]=='N' ) + { + int slen = 0; + char *seq = faidx_fetch_seq(args->gvcf_fai,maux->chr,out->pos,out->pos,&slen); + if (slen) + { + out->d.allele[0][0] = seq[0]; + free(seq); + } + } + // Update END boundary + if ( end > start ) + { + end++; + bcf_update_info_int32(args->out_hdr, out, "END", &end, 1); + } + else + bcf_update_info_int32(args->out_hdr, out, "END", NULL, 0); + bcf_write1(args->out_fh, args->out_hdr, out); + bcf_clear1(out); -void debug_buffers(FILE *fp, bcf_srs_t *files); -void debug_buffer(FILE *fp, bcf_sr_t *reader); -#define SWAP(type_t,a,b) { type_t tmp = (a); (a) = (b); (b) = tmp; } + // Inactivate blocks which do not extend beyond END and find new gvcf_min + min = INT_MAX; + for (i=0; ifiles->nreaders; i++) + { + if ( !gaux[i].active ) continue; + if ( gaux[i].end < end ) + { + gaux[i].active = 0; + maux->buf[i].cur = -1; + continue; + } + // next min END position bigger than the current one + if ( maux->gvcf_min < gaux[i].end+1 && min > gaux[i].end+1 ) min = gaux[i].end + 1; + } + maux->gvcf_min = min==INT_MAX ? 0 : min; +} -// Clean the reader's buffer to and make it ready for the next next_line() call. -// Moves finished records (SKIP_DONE flag set) at the end of the buffer and put -// the rest to the beggining. Then shorten the buffer so that the last element -// points to the last unfinished record. There are two special cases: the last -// line of the buffer typically has a different position and must stay at the -// end; next, the first record of the buffer must be one of those already -// printed, as it will be discarded by next_line(). -// -void shake_buffer(maux_t *maux, int ir, int pos) +/* + Flush staged gVCF blocks. Flush everything if there are no more lines + (done=1) or if there is a new chromosome. If still on the same chromosome, + all hanging blocks must be ended by creating new records: + A + 1 END=10 + B + 3 END=7 + C + 3 END=5 + out + 1 END=2 A . . + 3 END=5 A B C + 6 END=7 A B . + 8 END=10 A . . + +*/ +void gvcf_flush(args_t *args, int done) { - bcf_sr_t *reader = &maux->files->readers[ir]; - maux1_t *m = maux->d[ir]; - - if ( !reader->buffer ) return; - int i; - // FILE *fp = pysam_stdout; - // fprintf(fp," nbuf=%d\t", reader->nbuffer); for (i=0; inbuffer; i++) fprintf(fp," %d", skip[i]); fprintf(fp,"\n"); - // debug_buffer(fp,reader); - // fprintf(fp,"--\n"); + maux_t *maux = args->maux; - int a = 1, b = reader->nbuffer; - if ( reader->buffer[b]->pos != pos ) b--; // move the last line separately afterwards + if ( !maux->chr ) return; // first time here, nothing to flush - while ( abuffer[a], reader->buffer[b]); - SWAP(maux1_t, m[a], m[b]); - a++; - b--; - } + // Get current position and chromosome + for (i=0; in; i++) + if ( bcf_sr_has_line(maux->files,i) ) break; + bcf1_t *line = bcf_sr_get_line(maux->files,i); + bcf_hdr_t *hdr = bcf_sr_get_header(maux->files,i); - // position $a to the after the first unfinished record - while ( a<=reader->nbuffer && !(m[a].skip&SKIP_DONE) ) a++; + if ( !strcmp(maux->chr,bcf_seqname(hdr,line)) ) flush_until = line->pos; // still on the same chr + } - if ( anbuffer ) + // When called on a region, trim the blocks accordingly + int start = maux->gvcf_break>=0 ? maux->gvcf_break + 1 : maux->pos; + if ( args->regs ) { - // there is a gap between the unfinished lines at the beggining and the - // last line. The last line must be brought forward to fill the gap - if ( reader->buffer[reader->nbuffer]->pos != pos ) + int rstart = -1, rend = -1; + if ( regidx_overlap(args->regs,maux->chr,start,flush_until,args->regs_itr) ) { - SWAP(bcf1_t*, reader->buffer[a], reader->buffer[reader->nbuffer]); - SWAP(maux1_t, m[a], m[reader->nbuffer]); - reader->nbuffer = a; + // In case there are multiple regions, we treat them as one + rstart = args->regs_itr->beg; + while ( regitr_overlap(args->regs_itr) ) rend = args->regs_itr->end; } + if ( rstart > start ) start = rstart; + if ( rend < flush_until ) flush_until = rend+1; } - if ( !(m[0].skip&SKIP_DONE) && reader->buffer[0]->pos==pos ) + // output all finished blocks + while ( maux->gvcf_min && start < flush_until ) + { + // does the block end before the new line or is it interrupted? + int tmp = maux->gvcf_min < flush_until ? maux->gvcf_min : flush_until; + if ( start > tmp-1 ) break; + gvcf_write_block(args,start,tmp-1); // gvcf_min is 1-based + start = tmp; + } +} + +/* + Check incoming lines for new gVCF blocks, set pointer to the current source + buffer (gvcf or readers). In contrast to gvcf_flush, this function can be + called only after maux_reset as it relies on updated maux buffers. +*/ +void gvcf_stage(args_t *args, int pos) +{ + maux_t *maux = args->maux; + gvcf_aux_t *gaux = maux->gvcf; + bcf_srs_t *files = args->files; + int32_t *end = (int32_t*) maux->tmp_arr; + int i, nend = maux->ntmp_arr / sizeof(int32_t); + + maux->gvcf_break = -1; + maux->gvcf_min = INT_MAX; + for (i=0; inreaders; i++) { - // the first record is unfinished, replace it with an empty line - // from the end of the buffer or else next_line will remove it - if ( reader->nbuffer + 1 >= maux->nbuf[ir] ) + if ( gaux[i].active ) { - reader->nbuffer++; - maux_expand1(maux, ir); - reader->nbuffer--; - m = maux->d[ir]; + // gvcf block should not overlap with another record + if ( maux->gvcf_min > gaux[i].end+1 ) maux->gvcf_min = gaux[i].end + 1; + maux->buf[i].beg = 0; + maux->buf[i].end = 1; + maux->buf[i].cur = 0; + continue; } - if ( reader->nbuffer+1 >= reader->mbuffer ) - error("Uh, did not expect this: %d vs %d\n", reader->nbuffer,reader->mbuffer); - if ( reader->buffer[reader->nbuffer]->pos!=pos ) + // Does any of the lines have END set? It is enough to check only the + // first line, there should be no duplicate records with END in gVCF + + if ( maux->buf[i].beg==maux->buf[i].end ) continue; // no new record + + int irec = maux->buf[i].beg; + bcf_hdr_t *hdr = bcf_sr_get_header(files, i); + bcf1_t *line = args->files->readers[i].buffer[irec]; + int ret = bcf_get_info_int32(hdr,line,"END",&end,&nend); + if ( ret==1 ) { - // 4way swap - bcf1_t *tmp = reader->buffer[0]; - reader->buffer[0] = reader->buffer[reader->nbuffer+1]; - reader->buffer[reader->nbuffer+1] = reader->buffer[reader->nbuffer]; - reader->buffer[reader->nbuffer] = tmp; - m[reader->nbuffer].skip = m[0].skip; - m[reader->nbuffer+1].skip = SKIP_DIFF; - reader->nbuffer++; + // END is set, this is a new gVCF block. Cache this line in gaux[i] and swap with + // an empty record: the gaux line must be kept until we reach its END. + gaux[i].active = 1; + gaux[i].end = end[0] - 1; + SWAP(bcf1_t*,args->files->readers[i].buffer[irec],gaux[i].line); + gaux[i].line->pos = pos; + + maux->buf[i].lines = &gaux[i].line; + maux->buf[i].beg = 0; + maux->buf[i].end = 1; + maux->buf[i].cur = 0; + + // Set the rid,pos of the swapped line in the buffer or else the + // synced reader will have a problem with the next line + // + args->files->readers[i].buffer[irec]->rid = maux->buf[i].rid; + args->files->readers[i].buffer[irec]->pos = maux->pos; + + // Update block offsets + if ( maux->gvcf_min > gaux[i].end+1 ) maux->gvcf_min = gaux[i].end + 1; } else - { - SWAP(bcf1_t*, reader->buffer[0], reader->buffer[reader->nbuffer+1]); - SWAP(maux1_t, m[0], m[reader->nbuffer+1]); - } + maux->gvcf_break = line->pos; // must break the gvcf block } + maux->ntmp_arr = nend * sizeof(int32_t); + maux->tmp_arr = end; + if ( maux->gvcf_min==INT_MAX ) maux->gvcf_min = 0; +} - // debug_buffer(fp,reader); - // fprintf(fp,"\t"); for (i=0; inbuffer; i++) fprintf(fp," %d", skip[i]); - // fprintf(fp,"\n\n"); - // set position of finished buffer[0] line to -1, otherwise swapping may - // bring it back after next_line() - reader->buffer[0]->pos = -1; +void debug_buffers(FILE *fp, bcf_srs_t *files); +void debug_buffer(FILE *fp, bcf_srs_t *files, int reader); - // trim the buffer, remove finished lines from the end - i = reader->nbuffer; - while ( i>=1 && m[i--].skip&SKIP_DONE ) - reader->nbuffer--; +/* + Flush all buffered and processed records with the same coordinate. + Note that synced reader discards buffer[0], so that needs to stay + untouched. +*/ +void clean_buffer(args_t *args) +{ + maux_t *ma = args->maux; + + int ir; + for (ir=0; irn; ir++) + { + // Invalidate pointer to reader's buffer or else gvcf_flush will attempt + // to use the old lines via maux_get_line() + if ( ma->gvcf && !ma->gvcf[ir].active ) ma->buf[ir].cur = -1; + + bcf_sr_t *reader = bcf_sr_get_reader(args->files,ir); + if ( !reader->nbuffer ) continue; // nothing to clean + + bcf1_t **buf = reader->buffer; + if ( buf[1]->rid!=ma->buf[ir].rid || buf[1]->pos!=ma->pos ) continue; // nothing to flush + + int a = 1, b = 2; + while ( b<=reader->nbuffer && buf[b]->rid==ma->buf[ir].rid && buf[b]->pos==ma->pos ) b++; + // b now points to the first line we want to preserve + while ( b<=reader->nbuffer ) + { + SWAP(bcf1_t*, buf[a], buf[b]); + a++; b++; + } + reader->nbuffer -= b-a; + } } -void debug_maux(args_t *args, int pos, int var_type) +void debug_maux(args_t *args) { bcf_srs_t *files = args->files; maux_t *maux = args->maux; int j,k,l; - fprintf(pysam_stderr,"Alleles to merge at %d\n", pos+1); + fprintf(bcftools_stderr,"Alleles to merge at %d, nals=%d\n", maux->pos+1,maux->nals); for (j=0; jnreaders; j++) { bcf_sr_t *reader = &files->readers[j]; - fprintf(pysam_stderr," reader %d: ", j); - for (k=0; k<=reader->nbuffer; k++) + buffer_t *buf = &maux->buf[j]; + fprintf(bcftools_stderr," reader %d: ", j); + for (k=buf->beg; kend; k++) { - if ( maux->d[j][k].skip==SKIP_DONE ) continue; + if ( buf->rec[k].skip & SKIP_DONE ) continue; bcf1_t *line = reader->buffer[k]; - if ( line->pos!=pos ) continue; - fprintf(pysam_stderr,"\t"); - if ( maux->d[j][k].skip ) fprintf(pysam_stderr,"["); // this record will not be merged in this round + fprintf(bcftools_stderr,"\t"); + if ( buf->rec[k].skip ) fprintf(bcftools_stderr,"["); // this record will not be merged in this round for (l=0; ln_allele; l++) - fprintf(pysam_stderr,"%s%s", l==0?"":",", line->d.allele[l]); - if ( maux->d[j][k].skip ) fprintf(pysam_stderr,"]"); + fprintf(bcftools_stderr,"%s%s", l==0?"":",", line->d.allele[l]); + if ( buf->rec[k].skip ) fprintf(bcftools_stderr,"]"); } - fprintf(pysam_stderr,"\n"); + fprintf(bcftools_stderr,"\n"); } - fprintf(pysam_stderr," counts: "); - for (j=0; jnals; j++) fprintf(pysam_stderr,"%s %dx %s", j==0?"":",",maux->cnt[j], maux->als[j]); fprintf(pysam_stderr,"\n"); - for (j=0; jnreaders; j++) + fprintf(bcftools_stderr," counts: "); + for (j=0; jnals; j++) fprintf(bcftools_stderr,"%s %dx %s", j==0?"":",",maux->cnt[j], maux->als[j]); + fprintf(bcftools_stderr,"\n\n"); +} + +void debug_state(args_t *args) +{ + maux_t *maux = args->maux; + int i,j; + for (i=0; ifiles->nreaders; i++) { - bcf_sr_t *reader = &files->readers[j]; - fprintf(pysam_stderr," out %d: ", j); - for (k=0; k<=reader->nbuffer; k++) + fprintf(bcftools_stderr,"reader %d:\tcur,beg,end=% d,%d,%d", i,maux->buf[i].cur,maux->buf[i].beg,maux->buf[i].end); + if ( maux->buf[i].cur >=0 ) { - if ( maux->d[j][k].skip==SKIP_DONE ) continue; - bcf1_t *line = reader->buffer[k]; - if ( line->pos!=pos ) continue; - if ( maux->d[j][k].skip ) continue; - fprintf(pysam_stderr,"\t"); - for (l=0; ln_allele; l++) - fprintf(pysam_stderr,"%s%s", l==0?"":",", maux->als[maux->d[j][k].map[l]]); + bcf_hdr_t *hdr = bcf_sr_get_header(args->files,i); + const char *chr = bcf_hdr_id2name(hdr, maux->buf[i].rid); + fprintf(bcftools_stderr,"\t"); + for (j=maux->buf[i].beg; jbuf[i].end; j++) fprintf(bcftools_stderr," %s:%d",chr,maux->buf[i].lines[j]->pos+1); } - fprintf(pysam_stderr,"\n"); + fprintf(bcftools_stderr,"\n"); + } + for (i=0; ifiles->nreaders; i++) + { + fprintf(bcftools_stderr,"reader %d:\tgvcf_active=%d", i,maux->gvcf[i].active); + if ( maux->gvcf[i].active ) fprintf(bcftools_stderr,"\tpos,end=%d,%d", maux->gvcf[i].line->pos+1,maux->gvcf[i].end+1); + fprintf(bcftools_stderr,"\n"); } - fprintf(pysam_stderr,"\n"); + fprintf(bcftools_stderr,"\n"); } -// Determine which line should be merged from which reader: go through all -// readers and all buffered lines, expand REF,ALT and try to match lines with -// the same ALTs. A step towards output independent on input ordering of the -// lines. -void merge_buffer(args_t *args) + +/* + Determine which line should be merged from which reader: go through all + readers and all buffered lines, expand REF,ALT and try to match lines with + the same ALTs. + */ +int can_merge(args_t *args) { bcf_srs_t *files = args->files; - int i, pos = -1, var_type = 0; - char *id = NULL; + int snp_mask = (VCF_SNP<<1)|(VCF_MNP<<1), indel_mask = VCF_INDEL<<1, ref_mask = 1; maux_t *maux = args->maux; - maux_reset(maux); + gvcf_aux_t *gaux = maux->gvcf; + char *id = NULL, ref = 'N'; + int i,j,k, ntodo = 0; + + for (i=0; inals; i++) + { + free(maux->als[i]); + maux->als[i] = NULL; + } + maux->var_types = maux->nals = 0; - // set the current position for (i=0; inreaders; i++) { - if ( bcf_sr_has_line(files,i) ) + buffer_t *buf = &maux->buf[i]; + + if ( gaux && gaux[i].active ) { - bcf1_t *line = bcf_sr_get_line(files,i); - pos = line->pos; - var_type = bcf_get_variant_types(line); - id = line->d.id; - break; + // skip readers with active gvcf blocks + buf->rec[buf->beg].skip = SKIP_DIFF; + continue; } + for (j=buf->beg; jend; j++) + { + if ( buf->rec[j].skip & SKIP_DONE ) continue; + + buf->rec[j].skip = SKIP_DIFF; + ntodo++; + + if ( args->merge_by_id ) + id = buf->lines[j]->d.id; + else + { + int var_type = bcf_get_variant_types(buf->lines[j]); + maux->var_types |= var_type ? var_type<<1 : 1; + } + } + + // for gvcf: find out REF at this position + if ( buf->beg < buf->end && ref=='N' ) + ref = buf->lines[buf->beg]->d.allele[0][0]; } + if ( !ntodo ) return 0; // In this loop we select from each reader compatible candidate lines. // (i.e. SNPs or indels). Go through all files and all lines at this @@ -1712,19 +2079,24 @@ void merge_buffer(args_t *args) for (i=0; inreaders; i++) { bcf_sr_t *reader = &files->readers[i]; - if ( !reader->buffer ) continue; - int j, k; - for (j=0; j<=reader->nbuffer; j++) + buffer_t *buf = &maux->buf[i]; + + if ( gaux && gaux[i].active ) { - bcf1_t *line = reader->buffer[j]; + gaux[i].line->d.allele[0][0] = ref; + gaux[i].line->pos = maux->pos; + } + + for (j=buf->beg; jend; j++) + { + if ( buf->rec[j].skip & SKIP_DONE ) continue; + + bcf1_t *line = buf->lines[j]; // ptr to reader's buffer or gvcf buffer + int line_type = bcf_get_variant_types(line); + line_type = line_type ? line_type<<1 : 1; + // select relevant lines - maux->d[i][j].skip = SKIP_DIFF; - if ( pos!=line->pos ) - { - if ( j==0 ) maux->d[i][j].skip |= SKIP_DONE; // left from previous run, force to ignore - continue; - } if ( args->merge_by_id ) { if ( strcmp(id,line->d.id) ) continue; @@ -1735,30 +2107,30 @@ void merge_buffer(args_t *args) { // All alleles of the tested record must be present in the // selected maux record plus variant types must be the same - if ( var_type!=line->d.var_type ) continue; + if ( (maux->var_types & line_type) != line_type ) continue; if ( vcmp_set_ref(args->vcmp,maux->als[0],line->d.allele[0]) < 0 ) continue; // refs not compatible for (k=1; kn_allele; k++) { if ( vcmp_find_allele(args->vcmp,maux->als+1,maux->nals-1,line->d.allele[k])>=0 ) break; } - if ( k==line->n_allele ) continue; // no matching allele + if ( !(line_type&ref_mask) && k==line->n_allele ) continue; // not a REF-only site and there is no matching allele } if ( !(args->collapse&COLLAPSE_ANY) ) { - int compatible = 0; - if ( line_type==var_type ) compatible = 1; - else if ( line_type==VCF_REF ) compatible = 1; // REF can go with anything - else if ( var_type&VCF_SNP && line_type&VCF_SNP ) compatible = 1; - else if ( var_type&VCF_INDEL && line_type&VCF_INDEL ) compatible = 1; - else if ( var_type&VCF_MNP && line_type&VCF_MNP ) compatible = 1; - else if ( var_type&VCF_SNP && line_type&VCF_MNP ) compatible = 1; - else if ( var_type&VCF_MNP && line_type&VCF_SNP ) compatible = 1; - if ( !compatible ) continue; + // Merge: + // - SNPs+SNPs+MNPs+REF if -m both,snps + // - indels+indels+REF if -m both,indels, REF only if SNPs are not present + // - SNPs come first + if ( line_type & indel_mask ) + { + if ( !(line_type&snp_mask) && maux->var_types&snp_mask ) continue; // SNPs come first + if ( args->do_gvcf && maux->var_types&ref_mask ) continue; // never merge indels with gVCF blocks + } } } - maux->d[i][j].skip = 0; + buf->rec[j].skip = 0; - hts_expand(int, line->n_allele, maux->d[i][j].mmap, maux->d[i][j].map); + hts_expand(int, line->n_allele, buf->rec[j].mmap, buf->rec[j].map); if ( !maux->nals ) // first record, copy the alleles to the output { maux->nals = line->n_allele; @@ -1766,111 +2138,118 @@ void merge_buffer(args_t *args) hts_expand0(int, maux->nals, maux->ncnt, maux->cnt); for (k=0; knals; k++) { + free(maux->als[k]); maux->als[k] = strdup(line->d.allele[k]); - maux->d[i][j].map[k] = k; + buf->rec[j].map[k] = k; maux->cnt[k] = 1; } - pos = line->pos; continue; } - // normalize alleles - maux->als = merge_alleles(line->d.allele, line->n_allele, maux->d[i][j].map, maux->als, &maux->nals, &maux->mals); - if ( !maux->als ) error("Failed to merge alleles at %s:%d in %s\n",bcf_seqname(bcf_sr_get_header(args->files,j),line),line->pos+1,reader->fname); + maux->als = merge_alleles(line->d.allele, line->n_allele, buf->rec[j].map, maux->als, &maux->nals, &maux->mals); + if ( !maux->als ) error("Failed to merge alleles at %s:%d in %s\n",bcf_seqname(args->out_hdr,line),line->pos+1,reader->fname); hts_expand0(int, maux->nals, maux->ncnt, maux->cnt); for (k=1; kn_allele; k++) - maux->cnt[ maux->d[i][j].map[k] ]++; // how many times an allele appears in the files + maux->cnt[ buf->rec[j].map[k] ]++; // how many times an allele appears in the files maux->cnt[0]++; } } + return 1; +} + +/* + Select records that have the same alleles; the input ordering of indels + must not matter. Multiple VCF lines can be emitted from this loop. + We expect only very few alleles and not many records with the same + position in the buffers, therefore the nested loops should not slow us + much. +*/ +void stage_line(args_t *args) +{ + int snp_mask = (VCF_SNP<<1)|(VCF_MNP<<1), indel_mask = VCF_INDEL<<1, ref_mask = 1; + bcf_srs_t *files = args->files; + maux_t *maux = args->maux; + + // debug_maux(args); - // debug_maux(args, pos, var_type); + // take the most frequent allele present in multiple files, REF is skipped + int i,j,k,icnt = 1; + for (i=2; inals; i++) + if ( maux->cnt[i] > maux->cnt[icnt] ) icnt = i; - // Select records that have the same alleles; the input ordering of indels - // must not matter. Multiple VCF lines can be emitted from this loop. - // We expect only very few alleles and not many records with the same - // position in the buffers, therefore the nested loops should not slow us - // much. - while (1) + int nout = 0; + for (i=0; inreaders; i++) { - // take the most frequent allele present in multiple files - int icnt = 0; - for (i=1; inals; i++) - if ( maux->cnt[i] > maux->cnt[icnt] ) icnt = i; - if ( maux->cnt[icnt]<0 ) break; + buffer_t *buf = &maux->buf[i]; + buf->cur = -1; + if ( buf->beg >= buf->end ) continue; // no lines in the buffer - int nmask = 0; - for (i=0; inreaders; i++) + // find lines with the same allele + for (j=buf->beg; jend; j++) { - maux->has_line[i] = 0; + if ( buf->rec[j].skip ) continue; // done or not compatible + if ( args->merge_by_id ) break; + if ( maux->nals==1 && buf->lines[j]->n_allele==1 ) break; // REF-only record - bcf_sr_t *reader = &files->readers[i]; - if ( !reader->buffer ) continue; + for (k=0; klines[j]->n_allele; k++) + if ( icnt==buf->rec[j].map[k] ) break; - // find lines with the same allele - int j; - for (j=0; j<=reader->nbuffer; j++) - { - if ( maux->d[i][j].skip ) continue; - int k; - for (k=0; kbuffer[j]->n_allele; k++) - if ( icnt==maux->d[i][j].map[k] ) break; - if ( kbuffer[j]->n_allele ) break; - } - if ( j>reader->nbuffer ) - { - // no matching allele found in this file - if ( args->collapse==COLLAPSE_NONE ) continue; + if ( klines[j]->n_allele ) break; + } + if ( j>=buf->end ) + { + // no matching allele found in this file + if ( args->collapse==COLLAPSE_NONE ) continue; - for (j=0; j<=reader->nbuffer; j++) + for (j=buf->beg; jend; j++) + { + if ( buf->rec[j].skip ) continue; // done or not compatible + if ( args->collapse&COLLAPSE_ANY ) break; // anything can be merged + int line_type = bcf_get_variant_types(buf->lines[j]); + if ( maux->var_types&snp_mask && line_type&VCF_SNP && (args->collapse&COLLAPSE_SNPS) ) break; + if ( maux->var_types&indel_mask && line_type&VCF_INDEL && (args->collapse&COLLAPSE_INDELS) ) break; + if ( line_type==VCF_REF ) { - if ( maux->d[i][j].skip ) continue; - if ( args->collapse&COLLAPSE_ANY ) break; - int line_type = bcf_get_variant_types(reader->buffer[j]); - if ( var_type&VCF_SNP && line_type&VCF_SNP && (args->collapse&COLLAPSE_SNPS) ) break; - if ( var_type&VCF_INDEL && line_type&VCF_INDEL && (args->collapse&COLLAPSE_INDELS) ) break; - if ( line_type==VCF_REF ) - { - if ( var_type&VCF_SNP && (args->collapse&COLLAPSE_SNPS) ) break; - if ( var_type&VCF_INDEL && (args->collapse&COLLAPSE_INDELS) ) break; - } - else if ( var_type==VCF_REF ) - { - if ( line_type&VCF_SNP && (args->collapse&COLLAPSE_SNPS) ) break; - if ( line_type&VCF_INDEL && (args->collapse&COLLAPSE_INDELS) ) break; - } + if ( maux->var_types&snp_mask && (args->collapse&COLLAPSE_SNPS) ) break; + if ( maux->var_types&indel_mask && (args->collapse&COLLAPSE_INDELS) ) break; + if ( maux->var_types&ref_mask ) break; } - } - if ( j<=reader->nbuffer ) - { - // found a suitable line for merging, place it at the beggining - if ( j>0 ) + else if ( maux->var_types&ref_mask ) { - SWAP(bcf1_t*, reader->buffer[0], reader->buffer[j]); - SWAP(maux1_t, maux->d[i][0], maux->d[i][j]); + if ( line_type&snp_mask && (args->collapse&COLLAPSE_SNPS) ) break; + if ( line_type&indel_mask && (args->collapse&COLLAPSE_INDELS) ) break; } - // mark as finished so that it's ignored next time - maux->d[i][0].skip |= SKIP_DONE; - maux->has_line[i] = 1; - nmask++; } } - if ( !nmask ) break; // done, no more lines suitable for merging found - merge_line(args); // merge and output the line - maux->cnt[icnt] = -1; // do not pick this allele again, mark it as finished + if ( jend ) + { + // found a suitable line for merging + buf->cur = j; + + // mark as finished so that it's ignored next time + buf->rec[j].skip = SKIP_DONE; + nout++; + } } + assert( nout ); +} - // clean the alleles - for (i=0; inals; i++) +void merge_line(args_t *args) +{ + if ( args->regs ) { - free(maux->als[i]); - maux->als[i] = 0; + if ( !regidx_overlap(args->regs,args->maux->chr,args->maux->pos,args->maux->pos,NULL) ) return; } - maux->nals = 0; - // get the buffers ready for the next next_line() call - for (i=0; inreaders; i++) - shake_buffer(maux, i, pos); + bcf1_t *out = args->out_line; + merge_chrom2qual(args, out); + merge_filter(args, out); + merge_info(args, out); + if ( args->do_gvcf ) + bcf_update_info_int32(args->out_hdr, out, "END", NULL, 0); + merge_format(args, out); + bcf_write1(args->out_fh, args->out_hdr, out); + bcf_clear1(out); } void bcf_hdr_append_version(bcf_hdr_t *hdr, int argc, char **argv, const char *cmd) @@ -1889,6 +2268,8 @@ void bcf_hdr_append_version(bcf_hdr_t *hdr, int argc, char **argv, const char *c else ksprintf(&str, " %s", argv[i]); } + kputs("; Date=", &str); + time_t tm; time(&tm); kputs(ctime(&tm), &str); kputc('\n', &str); bcf_hdr_append(hdr,str.s); free(str.s); @@ -1900,7 +2281,7 @@ void merge_vcf(args_t *args) { args->out_fh = hts_open(args->output_fname, hts_bcf_wmode(args->output_type)); if ( args->out_fh == NULL ) error("Can't write to \"%s\": %s\n", args->output_fname, strerror(errno)); - if ( args->n_threads ) hts_set_threads(args->out_fh, args->n_threads); + if ( args->n_threads ) hts_set_opt(args->out_fh, HTS_OPT_THREAD_POOL, args->files->p); //hts_set_threads(args->out_fh, args->n_threads); args->out_hdr = bcf_hdr_init("w"); if ( args->header_fname ) @@ -1930,14 +2311,33 @@ void merge_vcf(args_t *args) } if ( args->collapse==COLLAPSE_NONE ) args->vcmp = vcmp_init(); - args->maux = maux_init(args->files); + args->maux = maux_init(args); args->out_line = bcf_init1(); args->tmph = kh_init(strdict); - int ret; - while ( (ret=bcf_sr_next_line(args->files)) ) + + while ( bcf_sr_next_line(args->files) ) { - merge_buffer(args); + // output cached gVCF blocks which end before the new record + if ( args->do_gvcf ) + gvcf_flush(args,0); + + maux_reset(args->maux); + + // determine which of the new records are gvcf blocks + if ( args->do_gvcf ) + gvcf_stage(args, args->maux->pos); + + while ( can_merge(args) ) + { + stage_line(args); + merge_line(args); + } + clean_buffer(args); + // debug_state(args); } + if ( args->do_gvcf ) + gvcf_flush(args,1); + info_rules_destroy(args); maux_destroy(args->maux); bcf_hdr_destroy(args->out_hdr); @@ -1950,27 +2350,30 @@ void merge_vcf(args_t *args) static void usage(void) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Merge multiple VCF/BCF files from non-overlapping sample sets to create one multi-sample file.\n"); - fprintf(pysam_stderr, " Note that only records from different files can be merged, never from the same file. For\n"); - fprintf(pysam_stderr, " \"vertical\" merge take a look at \"bcftools norm\" instead.\n"); - fprintf(pysam_stderr, "Usage: bcftools merge [options] [...]\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Options:\n"); - fprintf(pysam_stderr, " --force-samples resolve duplicate sample names\n"); - fprintf(pysam_stderr, " --print-header print only the merged header and exit\n"); - fprintf(pysam_stderr, " --use-header use the provided header\n"); - fprintf(pysam_stderr, " -f, --apply-filters require at least one of the listed FILTER strings (e.g. \"PASS,.\")\n"); - fprintf(pysam_stderr, " -i, --info-rules rules for merging INFO fields (method is one of sum,avg,min,max,join) or \"-\" to turn off the default [DP:sum,DP4:sum]\n"); - fprintf(pysam_stderr, " -l, --file-list read file names from the file\n"); - fprintf(pysam_stderr, " -m, --merge allow multiallelic records for , see man page for details [both]\n"); - fprintf(pysam_stderr, " --no-version do not append version and command line to the header\n"); - fprintf(pysam_stderr, " -o, --output write output to a file [standard output]\n"); - fprintf(pysam_stderr, " -O, --output-type 'b' compressed BCF; 'u' uncompressed BCF; 'z' compressed VCF; 'v' uncompressed VCF [v]\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " --threads number of extra output compression threads [0]\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Merge multiple VCF/BCF files from non-overlapping sample sets to create one multi-sample file.\n"); + fprintf(bcftools_stderr, " Note that only records from different files can be merged, never from the same file. For\n"); + fprintf(bcftools_stderr, " \"vertical\" merge take a look at \"bcftools norm\" instead.\n"); + fprintf(bcftools_stderr, "Usage: bcftools merge [options] [...]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Options:\n"); + fprintf(bcftools_stderr, " --force-samples resolve duplicate sample names\n"); + fprintf(bcftools_stderr, " --print-header print only the merged header and exit\n"); + fprintf(bcftools_stderr, " --use-header use the provided header\n"); + fprintf(bcftools_stderr, " -0 --missing-to-ref assume genotypes at missing sites are 0/0\n"); + fprintf(bcftools_stderr, " -f, --apply-filters require at least one of the listed FILTER strings (e.g. \"PASS,.\")\n"); + fprintf(bcftools_stderr, " -F, --filter-logic remove filters if some input is PASS (\"x\"), or apply all filters (\"+\") [+]\n"); + fprintf(bcftools_stderr, " -g, --gvcf <-|ref.fa> merge gVCF blocks, INFO/END tag is expected. Implies -i QS:sum,MinDP:min,I16:sum,IDV:max,IMF:max\n"); + fprintf(bcftools_stderr, " -i, --info-rules rules for merging INFO fields (method is one of sum,avg,min,max,join) or \"-\" to turn off the default [DP:sum,DP4:sum]\n"); + fprintf(bcftools_stderr, " -l, --file-list read file names from the file\n"); + fprintf(bcftools_stderr, " -m, --merge allow multiallelic records for , see man page for details [both]\n"); + fprintf(bcftools_stderr, " --no-version do not append version and command line to the header\n"); + fprintf(bcftools_stderr, " -o, --output write output to a file [standard output]\n"); + fprintf(bcftools_stderr, " -O, --output-type 'b' compressed BCF; 'u' uncompressed BCF; 'z' compressed VCF; 'v' uncompressed VCF [v]\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " --threads number of extra output compression threads [0]\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } @@ -1991,7 +2394,9 @@ int main_vcfmerge(int argc, char *argv[]) { {"help",no_argument,NULL,'h'}, {"merge",required_argument,NULL,'m'}, + {"gvcf",required_argument,NULL,'g'}, {"file-list",required_argument,NULL,'l'}, + {"missing-to-ref",no_argument,NULL,'0'}, {"apply-filters",required_argument,NULL,'f'}, {"use-header",required_argument,NULL,1}, {"print-header",no_argument,NULL,2}, @@ -2003,10 +2408,25 @@ int main_vcfmerge(int argc, char *argv[]) {"regions-file",required_argument,NULL,'R'}, {"info-rules",required_argument,NULL,'i'}, {"no-version",no_argument,NULL,8}, + {"filter-logic",required_argument,NULL,'F'}, {NULL,0,NULL,0} }; - while ((c = getopt_long(argc, argv, "hm:f:r:R:o:O:i:l:",loptions,NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hm:f:r:R:o:O:i:l:g:F:0",loptions,NULL)) >= 0) { switch (c) { + case 'F': + if ( !strcmp(optarg,"+") ) args->filter_logic = FLT_LOGIC_ADD; + else if ( !strcmp(optarg,"x") ) args->filter_logic = FLT_LOGIC_REMOVE; + else error("Filter logic not recognised: %s\n", optarg); + break; + case '0': args->missing_to_ref = 1; break; + case 'g': + args->do_gvcf = 1; + if ( strcmp("-",optarg) ) + { + args->gvcf_fai = fai_load(optarg); + if ( !args->gvcf_fai ) error("Failed to load the fai index: %s\n", optarg); + } + break; case 'l': args->file_list = optarg; break; case 'i': args->info_rules = optarg; break; case 'o': args->output_fname = optarg; break; @@ -2047,9 +2467,23 @@ int main_vcfmerge(int argc, char *argv[]) if ( argc-optind<2 && !args->file_list ) usage(); args->files->require_index = 1; - if ( args->regions_list && bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 ) - error("Failed to read the regions: %s\n", args->regions_list); + if ( args->regions_list ) + { + if ( bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 ) + error("Failed to read the regions: %s\n", args->regions_list); + if ( regions_is_file ) + args->regs = regidx_init(args->regions_list,NULL,NULL,sizeof(char*),NULL); + else + { + args->regs = regidx_init(NULL,regidx_parse_reg,NULL,sizeof(char*),NULL); + if ( regidx_insert_list(args->regs,args->regions_list,',') !=0 ) error("Could not parse the regions: %s\n", args->regions_list); + regidx_insert(args->regs,NULL); + } + if ( !args->regs ) error("Could not parse the regions: %s\n", args->regions_list); + args->regs_itr = regitr_init(args->regs); + } + if ( bcf_sr_set_threads(args->files, args->n_threads)<0 ) error("Failed to create threads\n"); while (optindfiles, argv[optind]) ) error("Failed to open %s: %s\n", argv[optind],bcf_sr_strerror(args->files->errnum)); @@ -2067,6 +2501,9 @@ int main_vcfmerge(int argc, char *argv[]) } merge_vcf(args); bcf_sr_destroy(args->files); + if ( args->regs ) regidx_destroy(args->regs); + if ( args->regs_itr ) regitr_destroy(args->regs_itr); + if ( args->gvcf_fai ) fai_destroy(args->gvcf_fai); free(args); return 0; } diff --git a/bcftools/vcfnorm.c b/bcftools/vcfnorm.c index 781833ceb..ead1e8951 100644 --- a/bcftools/vcfnorm.c +++ b/bcftools/vcfnorm.c @@ -1,6 +1,6 @@ /* vcfnorm.c -- Left-align and normalize indels. - Copyright (C) 2013-2016 Genome Research Ltd. + Copyright (C) 2013-2017 Genome Research Ltd. Author: Petr Danecek @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#include #include #include #include @@ -33,6 +34,7 @@ THE SOFTWARE. */ #include #include #include +#include #include "bcftools.h" #include "rbuf.h" @@ -52,6 +54,15 @@ typedef struct } map_t; +// primitive comparison of two records' alleles via hashes; normalized alleles assumed +typedef struct +{ + int n; // number of alleles + char *ref, *alt; + void *hash; +} +cmpals_t; + typedef struct { char *tseq, *seq; @@ -71,6 +82,8 @@ typedef struct int aln_win; // the realignment window size (maximum repeat size) bcf_srs_t *files; // using the synced reader only for -r option bcf_hdr_t *hdr; + cmpals_t *cmpals; + int ncmpals, mcmpals; faidx_t *fai; struct { int tot, set, swap; } nref; char **argv, *output_fname, *ref_fname, *vcf_fname, *region, *targets; @@ -87,10 +100,30 @@ static inline int replace_iupac_codes(char *seq, int nseq) for (i=0; ihdr,line,gts,ngts); } -#define ERR_DUP_ALLELE -2 -#define ERR_REF_MISMATCH -1 -#define ERR_OK 0 -#define ERR_SYMBOLIC 1 +#define ERR_DUP_ALLELE -2 +#define ERR_REF_MISMATCH -1 +#define ERR_OK 0 +#define ERR_SYMBOLIC 1 +#define ERR_SPANNING_DELETION 2 static int realign(args_t *args, bcf1_t *line) { @@ -261,13 +295,18 @@ static int realign(args_t *args, bcf1_t *line) int i, nref, reflen = strlen(line->d.allele[0]); char *ref = faidx_fetch_seq(args->fai, (char*)args->hdr->id[BCF_DT_CTG][line->rid].key, line->pos, line->pos+reflen-1, &nref); if ( !ref ) error("faidx_fetch_seq failed at %s:%d\n", args->hdr->id[BCF_DT_CTG][line->rid].key, line->pos+1); - replace_iupac_codes(ref,nref); + seq_to_upper(ref,0); + replace_iupac_codes(ref,nref); // any non-ACGT character in fasta ref is replaced with N - // does REF contain non-standard bases? - if ( replace_iupac_codes(line->d.allele[0],reflen) ) + // does VCF REF contain non-standard bases? + if ( has_non_acgtn(line->d.allele[0],reflen) ) { - args->nchanged++; - bcf_update_alleles(args->hdr,line,(const char**)line->d.allele,line->n_allele); + if ( args->check_ref==CHECK_REF_EXIT ) + error("Non-ACGTN reference allele at %s:%d .. REF_SEQ:'%s' vs VCF:'%s'\n", bcf_seqname(args->hdr,line),line->pos+1,ref,line->d.allele[0]); + if ( args->check_ref & CHECK_REF_WARN ) + fprintf(stderr,"NON_ACGTN_REF\t%s\t%d\t%s\n", bcf_seqname(args->hdr,line),line->pos+1,line->d.allele[0]); + free(ref); + return ERR_REF_MISMATCH; } if ( strcasecmp(ref,line->d.allele[0]) ) { @@ -281,7 +320,16 @@ static int realign(args_t *args, bcf1_t *line) free(ref); ref = NULL; - if ( line->n_allele == 1 ) return ERR_OK; // a REF + if ( line->n_allele == 1 ) // a REF + { + if ( line->rlen > 1 ) + { + line->d.allele[0][1] = 0; + bcf_update_alleles(args->hdr,line,(const char**)line->d.allele,line->n_allele); + } + return ERR_OK; + } + if ( bcf_get_variant_types(line)==VCF_BND ) return ERR_SYMBOLIC; // breakend, not an error // make a copy of each allele for trimming hts_expand0(kstring_t,line->n_allele,args->ntmp_als,args->tmp_als); @@ -289,11 +337,21 @@ static int realign(args_t *args, bcf1_t *line) for (i=0; in_allele; i++) { if ( line->d.allele[i][0]=='<' ) return ERR_SYMBOLIC; // symbolic allele + if ( line->d.allele[i][0]=='*' ) return ERR_SPANNING_DELETION; // spanning deletion + if ( has_non_acgtn(line->d.allele[i],line->shared.l) ) + { + if ( args->check_ref==CHECK_REF_EXIT ) + error("Non-ACGTN alternate allele at %s:%d .. REF_SEQ:'%s' vs VCF:'%s'\n", bcf_seqname(args->hdr,line),line->pos+1,ref,line->d.allele[i]); + if ( args->check_ref & CHECK_REF_WARN ) + fprintf(stderr,"NON_ACGTN_ALT\t%s\t%d\t%s\n", bcf_seqname(args->hdr,line),line->pos+1,line->d.allele[i]); + return ERR_REF_MISMATCH; + } als[i].l = 0; kputs(line->d.allele[i], &als[i]); + seq_to_upper(als[i].s,0); - if ( i>0 && als[i].l==als[0].l && !strcasecmp(als[0].s,als[i].s) ) return ERR_DUP_ALLELE; + if ( i>0 && als[i].l==als[0].l && !strcmp(als[0].s,als[i].s) ) return ERR_DUP_ALLELE; } // trim from right @@ -361,7 +419,7 @@ static int realign(args_t *args, bcf1_t *line) // Have the alleles changed? als[0].s[ als[0].l ] = 0; // in order for strcmp to work - if ( ori_pos==line->pos && !strcasecmp(line->d.allele[0],als[0].s) ) return ERR_OK; + if ( ori_pos==line->pos && !strcmp(line->d.allele[0],als[0].s) ) return ERR_OK; // Create new block of alleles and update args->tmp_als_str.l = 0; @@ -390,18 +448,24 @@ static void split_info_numeric(args_t *args, bcf1_t *src, bcf_info_t *info, int int len = bcf_hdr_id2length(args->hdr,BCF_HL_INFO,info->key); \ if ( len==BCF_VL_A ) \ { \ - assert( ret==src->n_allele-1); \ + if ( ret!=src->n_allele-1 ) \ + error("Error: wrong number of fields in INFO/%s at %s:%d, expected %d, found %d\n", \ + tag,bcf_seqname(args->hdr,src),src->pos+1,src->n_allele-1,ret); \ bcf_update_info_##type(args->hdr,dst,tag,vals+ialt,1); \ } \ else if ( len==BCF_VL_R ) \ { \ - assert( ret==src->n_allele); \ + if ( ret!=src->n_allele ) \ + error("Error: wrong number of fields in INFO/%s at %s:%d, expected %d, found %d\n", \ + tag,bcf_seqname(args->hdr,src),src->pos+1,src->n_allele,ret); \ if ( ialt!=0 ) vals[1] = vals[ialt+1]; \ bcf_update_info_##type(args->hdr,dst,tag,vals,2); \ } \ else if ( len==BCF_VL_G ) \ { \ - assert( ret==src->n_allele*(src->n_allele+1)/2 ); \ + if ( ret!=src->n_allele*(src->n_allele+1)/2 ) \ + error("Error: wrong number of fields in INFO/%s at %s:%d, expected %d, found %d\n", \ + tag,bcf_seqname(args->hdr,src),src->pos+1,src->n_allele*(src->n_allele+1)/2,ret); \ if ( ialt!=0 ) \ { \ vals[1] = vals[bcf_alleles2gt(0,ialt+1)]; \ @@ -545,7 +609,9 @@ static void split_format_numeric(args_t *args, bcf1_t *src, bcf_fmt_t *fmt, int } \ if ( len==BCF_VL_A ) \ { \ - assert( nvals==(src->n_allele-1)*nsmpl); \ + if ( nvals!=(src->n_allele-1)*nsmpl ) \ + error("Error: wrong number of fields in FMT/%s at %s:%d, expected %d, found %d\n", \ + tag,bcf_seqname(args->hdr,src),src->pos+1,(src->n_allele-1)*nsmpl,nvals); \ nvals /= nsmpl; \ type_t *src_vals = vals, *dst_vals = vals; \ for (i=0; in_allele*nsmpl); \ + if ( nvals!=src->n_allele*nsmpl ) \ + error("Error: wrong number of fields in FMT/%s at %s:%d, expected %d, found %d\n", \ + tag,bcf_seqname(args->hdr,src),src->pos+1,src->n_allele*nsmpl,nvals); \ nvals /= nsmpl; \ type_t *src_vals = vals, *dst_vals = vals; \ for (i=0; in_allele*(src->n_allele+1)/2 || nfields==src->n_allele ); + if ( nfields!=src->n_allele*(src->n_allele+1)/2 && nfields!=src->n_allele ) + error("Error: wrong number of fields in FMT/%s at %s:%d, expected %d or %d, found %d\n", + tag,bcf_seqname(args->hdr,src),src->pos+1,src->n_allele*(src->n_allele+1)/2,src->n_allele,nfields); + int len = 0; if ( nfields==src->n_allele ) // haploid { @@ -994,7 +1065,7 @@ static void merge_format_genotype(args_t *args, bcf1_t **lines, int nlines, bcf_ else { int ial = bcf_gt_allele(gt2[k]); - assert( ialmaps[i].nals ); + if ( ial>=args->maps[i].nals ) error("Error at %s:%d: incorrect allele index %d\n",bcf_seqname(args->hdr,lines[i]),lines[i]->pos+1,ial); gt[k] = bcf_gt_unphased( args->maps[i].map[ial] ) | bcf_gt_is_phased(gt[k]); } } @@ -1451,10 +1522,74 @@ static bcf1_t *mrows_flush(args_t *args) } return NULL; } +static void cmpals_add(args_t *args, bcf1_t *rec) +{ + args->ncmpals++; + hts_expand0(cmpals_t, args->ncmpals, args->mcmpals, args->cmpals); + cmpals_t *cmpals = args->cmpals + args->ncmpals - 1; + free(cmpals->ref); + cmpals->ref = strdup(rec->d.allele[0]); + cmpals->n = rec->n_allele; + if ( rec->n_allele==2 ) + { + free(cmpals->alt); + cmpals->alt = strdup(rec->d.allele[1]); + } + else + { + if ( cmpals->hash ) khash_str2int_destroy_free(cmpals->hash); + cmpals->hash = khash_str2int_init(); + int i; + for (i=1; in_allele; i++) + khash_str2int_inc(cmpals->hash, strdup(rec->d.allele[i])); + } +} +static int cmpals_match(args_t *args, bcf1_t *rec) +{ + int i, j; + for (i=0; incmpals; i++) + { + cmpals_t *cmpals = args->cmpals + i; + if ( rec->n_allele != cmpals->n ) continue; + + // NB. assuming both are normalized + if ( strcmp(rec->d.allele[0], cmpals->ref) ) continue; + + // the most frequent case + if ( rec->n_allele==2 ) + { + if ( strcmp(rec->d.allele[1], cmpals->alt) ) continue; + return 1; + } + + khash_t(str2int) *hash = (khash_t(str2int)*) cmpals->hash; + for (j=1; jn_allele; j++) + if ( !khash_str2int_has_key(hash, rec->d.allele[j]) ) break; + if ( jn_allele ) continue; + return 1; + } + cmpals_add(args, rec); + return 0; +} +static void cmpals_reset(args_t *args) { args->ncmpals = 0; } +static void cmpals_destroy(args_t *args) +{ + int i; + for (i=0; imcmpals; i++) + { + cmpals_t *cmpals = args->cmpals + i; + free(cmpals->ref); + free(cmpals->alt); + if ( cmpals->hash ) khash_str2int_destroy_free(cmpals->hash); + } + free(args->cmpals); +} + static void flush_buffer(args_t *args, htsFile *file, int n) { bcf1_t *line; int i, k; + int prev_rid = -1, prev_pos = -1, prev_type = 0; for (i=0; irbuf); @@ -1475,6 +1610,26 @@ static void flush_buffer(args_t *args, htsFile *file, int n) continue; } } + else if ( args->rmdup ) + { + int line_type = bcf_get_variant_types(args->lines[k]); + if ( prev_rid>=0 && prev_rid==args->lines[k]->rid && prev_pos==args->lines[k]->pos ) + { + if ( args->rmdup & BCF_SR_PAIR_ANY ) continue; // rmdup by position only + if ( args->rmdup & BCF_SR_PAIR_SNPS && line_type&(VCF_SNP|VCF_MNP) && prev_type&(VCF_SNP|VCF_MNP) ) continue; + if ( args->rmdup & BCF_SR_PAIR_INDELS && line_type&(VCF_INDEL) && prev_type&(VCF_INDEL) ) continue; + if ( args->rmdup & BCF_SR_PAIR_EXACT && cmpals_match(args, args->lines[k]) ) continue; + } + else + { + prev_rid = args->lines[k]->rid; + prev_pos = args->lines[k]->pos; + prev_type = 0; + if ( args->rmdup & BCF_SR_PAIR_EXACT ) cmpals_reset(args); + } + prev_type |= line_type; + if ( args->rmdup & BCF_SR_PAIR_EXACT ) cmpals_add(args, args->lines[k]); + } bcf_write1(file, args->hdr, args->lines[k]); } if ( args->mrows_op==MROWS_MERGE && !args->rbuf.n ) @@ -1503,6 +1658,7 @@ static void init_data(args_t *args) static void destroy_data(args_t *args) { + cmpals_destroy(args); int i; for (i=0; irbuf.m; i++) if ( args->lines[i] ) bcf_destroy1(args->lines[i]); @@ -1583,7 +1739,8 @@ static void normalize_vcf(args_t *args) { htsFile *out = hts_open(args->output_fname, hts_bcf_wmode(args->output_type)); if ( out == NULL ) error("Can't write to \"%s\": %s\n", args->output_fname, strerror(errno)); - if ( args->n_threads ) hts_set_threads(out, args->n_threads); + if ( args->n_threads ) + hts_set_opt(out, HTS_OPT_THREAD_POOL, args->files->p); if (args->record_cmd_line) bcf_hdr_append_version(args->hdr, args->argc, args->argv, "bcftools_norm"); bcf_hdr_write(out, args->hdr); @@ -1598,17 +1755,20 @@ static void normalize_vcf(args_t *args) int line_type = bcf_get_variant_types(line); if ( prev_rid>=0 && prev_rid==line->rid && prev_pos==line->pos ) { - if ( (args->rmdup>>1)&COLLAPSE_ANY ) continue; - if ( (args->rmdup>>1)&COLLAPSE_SNPS && line_type&(VCF_SNP|VCF_MNP) && prev_type&(VCF_SNP|VCF_MNP) ) continue; - if ( (args->rmdup>>1)&COLLAPSE_INDELS && line_type&(VCF_INDEL) && prev_type&(VCF_INDEL) ) continue; + if ( args->rmdup & BCF_SR_PAIR_ANY ) continue; // rmdup by position only + if ( args->rmdup & BCF_SR_PAIR_SNPS && line_type&(VCF_SNP|VCF_MNP) && prev_type&(VCF_SNP|VCF_MNP) ) continue; + if ( args->rmdup & BCF_SR_PAIR_INDELS && line_type&(VCF_INDEL) && prev_type&(VCF_INDEL) ) continue; + if ( args->rmdup & BCF_SR_PAIR_EXACT && cmpals_match(args, line) ) continue; } else { prev_rid = line->rid; prev_pos = line->pos; prev_type = 0; + if ( args->rmdup & BCF_SR_PAIR_EXACT ) cmpals_reset(args); } prev_type |= line_type; + if ( args->rmdup & BCF_SR_PAIR_EXACT ) cmpals_add(args, line); } // still on the same chromosome? @@ -1665,8 +1825,8 @@ static void usage(void) fprintf(stderr, "Options:\n"); fprintf(stderr, " -c, --check-ref check REF alleles and exit (e), warn (w), exclude (x), or set (s) bad sites [e]\n"); fprintf(stderr, " -D, --remove-duplicates remove duplicate lines of the same type.\n"); - fprintf(stderr, " -d, --rm-dup remove duplicate snps|indels|both|any\n"); - fprintf(stderr, " -f, --fasta-ref reference sequence\n"); + fprintf(stderr, " -d, --rm-dup remove duplicate snps|indels|both|all|none\n"); + fprintf(stderr, " -f, --fasta-ref reference sequence (MANDATORY)\n"); fprintf(stderr, " -m, --multiallelics <-|+>[type] split multiallelics (-) or join biallelics (+), type: snps|indels|both|any [both]\n"); fprintf(stderr, " --no-version do not append version and command line to the header\n"); fprintf(stderr, " -N, --do-not-normalize do not normalize indels (with -m or -c s)\n"); @@ -1677,7 +1837,7 @@ static void usage(void) fprintf(stderr, " -s, --strict-filter when merging (-m+), merged site is PASS only if all sites being merged PASS\n"); fprintf(stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); fprintf(stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); - fprintf(stderr, " --threads number of extra output compression threads [0]\n"); + fprintf(stderr, " --threads number of extra (de)compression threads [0]\n"); fprintf(stderr, " -w, --site-win buffer for sorting lines which changed position during realignment [1000]\n"); fprintf(stderr, "\n"); exit(1); @@ -1726,10 +1886,12 @@ int main_vcfnorm(int argc, char *argv[]) switch (c) { case 'N': args->do_indels = 0; break; case 'd': - if ( !strcmp("snps",optarg) ) args->rmdup = COLLAPSE_SNPS<<1; - else if ( !strcmp("indels",optarg) ) args->rmdup = COLLAPSE_INDELS<<1; - else if ( !strcmp("both",optarg) ) args->rmdup = COLLAPSE_BOTH<<1; - else if ( !strcmp("any",optarg) ) args->rmdup = COLLAPSE_ANY<<1; + if ( !strcmp("snps",optarg) ) args->rmdup = BCF_SR_PAIR_SNPS; + else if ( !strcmp("indels",optarg) ) args->rmdup = BCF_SR_PAIR_INDELS; + else if ( !strcmp("both",optarg) ) args->rmdup = BCF_SR_PAIR_BOTH; + else if ( !strcmp("all",optarg) ) args->rmdup = BCF_SR_PAIR_ANY; + else if ( !strcmp("any",optarg) ) args->rmdup = BCF_SR_PAIR_ANY; + else if ( !strcmp("none",optarg) ) args->rmdup = BCF_SR_PAIR_EXACT; else error("The argument to -d not recognised: %s\n", optarg); break; case 'm': @@ -1763,7 +1925,7 @@ int main_vcfnorm(int argc, char *argv[]) case 'o': args->output_fname = optarg; break; case 'D': fprintf(stderr,"Warning: `-D` is functional but deprecated, replaced by `-d both`.\n"); - args->rmdup = COLLAPSE_NONE<<1; + args->rmdup = BCF_SR_PAIR_EXACT; break; case 's': args->strict_filter = 1; break; case 'f': args->ref_fname = optarg; break; @@ -1804,6 +1966,7 @@ int main_vcfnorm(int argc, char *argv[]) error("Failed to read the targets: %s\n", args->targets); } + if ( bcf_sr_set_threads(args->files, args->n_threads)<0 ) error("Failed to create threads\n"); if ( !bcf_sr_add_reader(args->files, fname) ) error("Failed to open %s: %s\n", fname,bcf_sr_strerror(args->files->errnum)); if ( args->mrows_op&MROWS_SPLIT && args->rmdup ) error("Cannot combine -D and -m-\n"); init_data(args); diff --git a/bcftools/vcfnorm.c.pysam.c b/bcftools/vcfnorm.c.pysam.c index 200ce7993..d204de4fb 100644 --- a/bcftools/vcfnorm.c.pysam.c +++ b/bcftools/vcfnorm.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfnorm.c -- Left-align and normalize indels. - Copyright (C) 2013-2016 Genome Research Ltd. + Copyright (C) 2013-2017 Genome Research Ltd. Author: Petr Danecek @@ -25,6 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#include #include #include #include @@ -35,6 +36,7 @@ THE SOFTWARE. */ #include #include #include +#include #include "bcftools.h" #include "rbuf.h" @@ -54,6 +56,15 @@ typedef struct } map_t; +// primitive comparison of two records' alleles via hashes; normalized alleles assumed +typedef struct +{ + int n; // number of alleles + char *ref, *alt; + void *hash; +} +cmpals_t; + typedef struct { char *tseq, *seq; @@ -73,6 +84,8 @@ typedef struct int aln_win; // the realignment window size (maximum repeat size) bcf_srs_t *files; // using the synced reader only for -r option bcf_hdr_t *hdr; + cmpals_t *cmpals; + int ncmpals, mcmpals; faidx_t *fai; struct { int tot, set, swap; } nref; char **argv, *output_fname, *ref_fname, *vcf_fname, *region, *targets; @@ -89,10 +102,30 @@ static inline int replace_iupac_codes(char *seq, int nseq) for (i=0; ihdr,line,gts,ngts); } -#define ERR_DUP_ALLELE -2 -#define ERR_REF_MISMATCH -1 -#define ERR_OK 0 -#define ERR_SYMBOLIC 1 +#define ERR_DUP_ALLELE -2 +#define ERR_REF_MISMATCH -1 +#define ERR_OK 0 +#define ERR_SYMBOLIC 1 +#define ERR_SPANNING_DELETION 2 static int realign(args_t *args, bcf1_t *line) { @@ -263,27 +297,41 @@ static int realign(args_t *args, bcf1_t *line) int i, nref, reflen = strlen(line->d.allele[0]); char *ref = faidx_fetch_seq(args->fai, (char*)args->hdr->id[BCF_DT_CTG][line->rid].key, line->pos, line->pos+reflen-1, &nref); if ( !ref ) error("faidx_fetch_seq failed at %s:%d\n", args->hdr->id[BCF_DT_CTG][line->rid].key, line->pos+1); - replace_iupac_codes(ref,nref); + seq_to_upper(ref,0); + replace_iupac_codes(ref,nref); // any non-ACGT character in fasta ref is replaced with N - // does REF contain non-standard bases? - if ( replace_iupac_codes(line->d.allele[0],reflen) ) + // does VCF REF contain non-standard bases? + if ( has_non_acgtn(line->d.allele[0],reflen) ) { - args->nchanged++; - bcf_update_alleles(args->hdr,line,(const char**)line->d.allele,line->n_allele); + if ( args->check_ref==CHECK_REF_EXIT ) + error("Non-ACGTN reference allele at %s:%d .. REF_SEQ:'%s' vs VCF:'%s'\n", bcf_seqname(args->hdr,line),line->pos+1,ref,line->d.allele[0]); + if ( args->check_ref & CHECK_REF_WARN ) + fprintf(bcftools_stderr,"NON_ACGTN_REF\t%s\t%d\t%s\n", bcf_seqname(args->hdr,line),line->pos+1,line->d.allele[0]); + free(ref); + return ERR_REF_MISMATCH; } if ( strcasecmp(ref,line->d.allele[0]) ) { if ( args->check_ref==CHECK_REF_EXIT ) error("Reference allele mismatch at %s:%d .. REF_SEQ:'%s' vs VCF:'%s'\n", bcf_seqname(args->hdr,line),line->pos+1,ref,line->d.allele[0]); if ( args->check_ref & CHECK_REF_WARN ) - fprintf(pysam_stderr,"REF_MISMATCH\t%s\t%d\t%s\n", bcf_seqname(args->hdr,line),line->pos+1,line->d.allele[0]); + fprintf(bcftools_stderr,"REF_MISMATCH\t%s\t%d\t%s\n", bcf_seqname(args->hdr,line),line->pos+1,line->d.allele[0]); free(ref); return ERR_REF_MISMATCH; } free(ref); ref = NULL; - if ( line->n_allele == 1 ) return ERR_OK; // a REF + if ( line->n_allele == 1 ) // a REF + { + if ( line->rlen > 1 ) + { + line->d.allele[0][1] = 0; + bcf_update_alleles(args->hdr,line,(const char**)line->d.allele,line->n_allele); + } + return ERR_OK; + } + if ( bcf_get_variant_types(line)==VCF_BND ) return ERR_SYMBOLIC; // breakend, not an error // make a copy of each allele for trimming hts_expand0(kstring_t,line->n_allele,args->ntmp_als,args->tmp_als); @@ -291,11 +339,21 @@ static int realign(args_t *args, bcf1_t *line) for (i=0; in_allele; i++) { if ( line->d.allele[i][0]=='<' ) return ERR_SYMBOLIC; // symbolic allele + if ( line->d.allele[i][0]=='*' ) return ERR_SPANNING_DELETION; // spanning deletion + if ( has_non_acgtn(line->d.allele[i],line->shared.l) ) + { + if ( args->check_ref==CHECK_REF_EXIT ) + error("Non-ACGTN alternate allele at %s:%d .. REF_SEQ:'%s' vs VCF:'%s'\n", bcf_seqname(args->hdr,line),line->pos+1,ref,line->d.allele[i]); + if ( args->check_ref & CHECK_REF_WARN ) + fprintf(bcftools_stderr,"NON_ACGTN_ALT\t%s\t%d\t%s\n", bcf_seqname(args->hdr,line),line->pos+1,line->d.allele[i]); + return ERR_REF_MISMATCH; + } als[i].l = 0; kputs(line->d.allele[i], &als[i]); + seq_to_upper(als[i].s,0); - if ( i>0 && als[i].l==als[0].l && !strcasecmp(als[0].s,als[i].s) ) return ERR_DUP_ALLELE; + if ( i>0 && als[i].l==als[0].l && !strcmp(als[0].s,als[i].s) ) return ERR_DUP_ALLELE; } // trim from right @@ -363,7 +421,7 @@ static int realign(args_t *args, bcf1_t *line) // Have the alleles changed? als[0].s[ als[0].l ] = 0; // in order for strcmp to work - if ( ori_pos==line->pos && !strcasecmp(line->d.allele[0],als[0].s) ) return ERR_OK; + if ( ori_pos==line->pos && !strcmp(line->d.allele[0],als[0].s) ) return ERR_OK; // Create new block of alleles and update args->tmp_als_str.l = 0; @@ -392,18 +450,24 @@ static void split_info_numeric(args_t *args, bcf1_t *src, bcf_info_t *info, int int len = bcf_hdr_id2length(args->hdr,BCF_HL_INFO,info->key); \ if ( len==BCF_VL_A ) \ { \ - assert( ret==src->n_allele-1); \ + if ( ret!=src->n_allele-1 ) \ + error("Error: wrong number of fields in INFO/%s at %s:%d, expected %d, found %d\n", \ + tag,bcf_seqname(args->hdr,src),src->pos+1,src->n_allele-1,ret); \ bcf_update_info_##type(args->hdr,dst,tag,vals+ialt,1); \ } \ else if ( len==BCF_VL_R ) \ { \ - assert( ret==src->n_allele); \ + if ( ret!=src->n_allele ) \ + error("Error: wrong number of fields in INFO/%s at %s:%d, expected %d, found %d\n", \ + tag,bcf_seqname(args->hdr,src),src->pos+1,src->n_allele,ret); \ if ( ialt!=0 ) vals[1] = vals[ialt+1]; \ bcf_update_info_##type(args->hdr,dst,tag,vals,2); \ } \ else if ( len==BCF_VL_G ) \ { \ - assert( ret==src->n_allele*(src->n_allele+1)/2 ); \ + if ( ret!=src->n_allele*(src->n_allele+1)/2 ) \ + error("Error: wrong number of fields in INFO/%s at %s:%d, expected %d, found %d\n", \ + tag,bcf_seqname(args->hdr,src),src->pos+1,src->n_allele*(src->n_allele+1)/2,ret); \ if ( ialt!=0 ) \ { \ vals[1] = vals[bcf_alleles2gt(0,ialt+1)]; \ @@ -547,7 +611,9 @@ static void split_format_numeric(args_t *args, bcf1_t *src, bcf_fmt_t *fmt, int } \ if ( len==BCF_VL_A ) \ { \ - assert( nvals==(src->n_allele-1)*nsmpl); \ + if ( nvals!=(src->n_allele-1)*nsmpl ) \ + error("Error: wrong number of fields in FMT/%s at %s:%d, expected %d, found %d\n", \ + tag,bcf_seqname(args->hdr,src),src->pos+1,(src->n_allele-1)*nsmpl,nvals); \ nvals /= nsmpl; \ type_t *src_vals = vals, *dst_vals = vals; \ for (i=0; in_allele*nsmpl); \ + if ( nvals!=src->n_allele*nsmpl ) \ + error("Error: wrong number of fields in FMT/%s at %s:%d, expected %d, found %d\n", \ + tag,bcf_seqname(args->hdr,src),src->pos+1,src->n_allele*nsmpl,nvals); \ nvals /= nsmpl; \ type_t *src_vals = vals, *dst_vals = vals; \ for (i=0; in_allele*(src->n_allele+1)/2 || nfields==src->n_allele ); + if ( nfields!=src->n_allele*(src->n_allele+1)/2 && nfields!=src->n_allele ) + error("Error: wrong number of fields in FMT/%s at %s:%d, expected %d or %d, found %d\n", + tag,bcf_seqname(args->hdr,src),src->pos+1,src->n_allele*(src->n_allele+1)/2,src->n_allele,nfields); + int len = 0; if ( nfields==src->n_allele ) // haploid { @@ -858,7 +929,7 @@ static void merge_info_numeric(args_t *args, bcf1_t **lines, int nlines, bcf_inf { \ /* expecting diploid gt in INFO */ \ if (nvals_ori!=lines[0]->n_allele*(lines[0]->n_allele+1)/2) { \ - fprintf(pysam_stderr, "todo: merge Number=G INFO fields for haploid sites\n"); \ + fprintf(bcftools_stderr, "todo: merge Number=G INFO fields for haploid sites\n"); \ error("vcfnorm: number of fields in first record at position %s:%d for INFO tag %s not as expected [found: %d vs expected:%d]\n", bcf_seqname(args->hdr,lines[0]),lines[0]->pos+1, tag, nvals_ori, lines[0]->n_allele*(lines[0]->n_allele+1)/2); \ } \ int nvals = dst->n_allele*(dst->n_allele+1)/2; \ @@ -996,7 +1067,7 @@ static void merge_format_genotype(args_t *args, bcf1_t **lines, int nlines, bcf_ else { int ial = bcf_gt_allele(gt2[k]); - assert( ialmaps[i].nals ); + if ( ial>=args->maps[i].nals ) error("Error at %s:%d: incorrect allele index %d\n",bcf_seqname(args->hdr,lines[i]),lines[i]->pos+1,ial); gt[k] = bcf_gt_unphased( args->maps[i].map[ial] ) | bcf_gt_is_phased(gt[k]); } } @@ -1453,10 +1524,74 @@ static bcf1_t *mrows_flush(args_t *args) } return NULL; } +static void cmpals_add(args_t *args, bcf1_t *rec) +{ + args->ncmpals++; + hts_expand0(cmpals_t, args->ncmpals, args->mcmpals, args->cmpals); + cmpals_t *cmpals = args->cmpals + args->ncmpals - 1; + free(cmpals->ref); + cmpals->ref = strdup(rec->d.allele[0]); + cmpals->n = rec->n_allele; + if ( rec->n_allele==2 ) + { + free(cmpals->alt); + cmpals->alt = strdup(rec->d.allele[1]); + } + else + { + if ( cmpals->hash ) khash_str2int_destroy_free(cmpals->hash); + cmpals->hash = khash_str2int_init(); + int i; + for (i=1; in_allele; i++) + khash_str2int_inc(cmpals->hash, strdup(rec->d.allele[i])); + } +} +static int cmpals_match(args_t *args, bcf1_t *rec) +{ + int i, j; + for (i=0; incmpals; i++) + { + cmpals_t *cmpals = args->cmpals + i; + if ( rec->n_allele != cmpals->n ) continue; + + // NB. assuming both are normalized + if ( strcmp(rec->d.allele[0], cmpals->ref) ) continue; + + // the most frequent case + if ( rec->n_allele==2 ) + { + if ( strcmp(rec->d.allele[1], cmpals->alt) ) continue; + return 1; + } + + khash_t(str2int) *hash = (khash_t(str2int)*) cmpals->hash; + for (j=1; jn_allele; j++) + if ( !khash_str2int_has_key(hash, rec->d.allele[j]) ) break; + if ( jn_allele ) continue; + return 1; + } + cmpals_add(args, rec); + return 0; +} +static void cmpals_reset(args_t *args) { args->ncmpals = 0; } +static void cmpals_destroy(args_t *args) +{ + int i; + for (i=0; imcmpals; i++) + { + cmpals_t *cmpals = args->cmpals + i; + free(cmpals->ref); + free(cmpals->alt); + if ( cmpals->hash ) khash_str2int_destroy_free(cmpals->hash); + } + free(args->cmpals); +} + static void flush_buffer(args_t *args, htsFile *file, int n) { bcf1_t *line; int i, k; + int prev_rid = -1, prev_pos = -1, prev_type = 0; for (i=0; irbuf); @@ -1477,6 +1612,26 @@ static void flush_buffer(args_t *args, htsFile *file, int n) continue; } } + else if ( args->rmdup ) + { + int line_type = bcf_get_variant_types(args->lines[k]); + if ( prev_rid>=0 && prev_rid==args->lines[k]->rid && prev_pos==args->lines[k]->pos ) + { + if ( args->rmdup & BCF_SR_PAIR_ANY ) continue; // rmdup by position only + if ( args->rmdup & BCF_SR_PAIR_SNPS && line_type&(VCF_SNP|VCF_MNP) && prev_type&(VCF_SNP|VCF_MNP) ) continue; + if ( args->rmdup & BCF_SR_PAIR_INDELS && line_type&(VCF_INDEL) && prev_type&(VCF_INDEL) ) continue; + if ( args->rmdup & BCF_SR_PAIR_EXACT && cmpals_match(args, args->lines[k]) ) continue; + } + else + { + prev_rid = args->lines[k]->rid; + prev_pos = args->lines[k]->pos; + prev_type = 0; + if ( args->rmdup & BCF_SR_PAIR_EXACT ) cmpals_reset(args); + } + prev_type |= line_type; + if ( args->rmdup & BCF_SR_PAIR_EXACT ) cmpals_add(args, args->lines[k]); + } bcf_write1(file, args->hdr, args->lines[k]); } if ( args->mrows_op==MROWS_MERGE && !args->rbuf.n ) @@ -1505,6 +1660,7 @@ static void init_data(args_t *args) static void destroy_data(args_t *args) { + cmpals_destroy(args); int i; for (i=0; irbuf.m; i++) if ( args->lines[i] ) bcf_destroy1(args->lines[i]); @@ -1563,7 +1719,7 @@ static void normalize_line(args_t *args, bcf1_t **line_ptr) else if ( args->check_ref==CHECK_REF_EXIT ) error("Duplicate alleles at %s:%d; run with -cw to turn the error into warning or with -cs to fix.\n", bcf_seqname(args->hdr,line),line->pos+1); else if ( args->check_ref & CHECK_REF_WARN ) - fprintf(pysam_stderr,"ALT_DUP\t%s\t%d\n", bcf_seqname(args->hdr,line),line->pos+1); + fprintf(bcftools_stderr,"ALT_DUP\t%s\t%d\n", bcf_seqname(args->hdr,line),line->pos+1); } } } @@ -1585,7 +1741,8 @@ static void normalize_vcf(args_t *args) { htsFile *out = hts_open(args->output_fname, hts_bcf_wmode(args->output_type)); if ( out == NULL ) error("Can't write to \"%s\": %s\n", args->output_fname, strerror(errno)); - if ( args->n_threads ) hts_set_threads(out, args->n_threads); + if ( args->n_threads ) + hts_set_opt(out, HTS_OPT_THREAD_POOL, args->files->p); if (args->record_cmd_line) bcf_hdr_append_version(args->hdr, args->argc, args->argv, "bcftools_norm"); bcf_hdr_write(out, args->hdr); @@ -1600,17 +1757,20 @@ static void normalize_vcf(args_t *args) int line_type = bcf_get_variant_types(line); if ( prev_rid>=0 && prev_rid==line->rid && prev_pos==line->pos ) { - if ( (args->rmdup>>1)&COLLAPSE_ANY ) continue; - if ( (args->rmdup>>1)&COLLAPSE_SNPS && line_type&(VCF_SNP|VCF_MNP) && prev_type&(VCF_SNP|VCF_MNP) ) continue; - if ( (args->rmdup>>1)&COLLAPSE_INDELS && line_type&(VCF_INDEL) && prev_type&(VCF_INDEL) ) continue; + if ( args->rmdup & BCF_SR_PAIR_ANY ) continue; // rmdup by position only + if ( args->rmdup & BCF_SR_PAIR_SNPS && line_type&(VCF_SNP|VCF_MNP) && prev_type&(VCF_SNP|VCF_MNP) ) continue; + if ( args->rmdup & BCF_SR_PAIR_INDELS && line_type&(VCF_INDEL) && prev_type&(VCF_INDEL) ) continue; + if ( args->rmdup & BCF_SR_PAIR_EXACT && cmpals_match(args, line) ) continue; } else { prev_rid = line->rid; prev_pos = line->pos; prev_type = 0; + if ( args->rmdup & BCF_SR_PAIR_EXACT ) cmpals_reset(args); } prev_type |= line_type; + if ( args->rmdup & BCF_SR_PAIR_EXACT ) cmpals_add(args, line); } // still on the same chromosome? @@ -1651,37 +1811,37 @@ static void normalize_vcf(args_t *args) flush_buffer(args, out, args->rbuf.n); hts_close(out); - fprintf(pysam_stderr,"Lines total/split/realigned/skipped:\t%d/%d/%d/%d\n", args->ntotal,args->nsplit,args->nchanged,args->nskipped); + fprintf(bcftools_stderr,"Lines total/split/realigned/skipped:\t%d/%d/%d/%d\n", args->ntotal,args->nsplit,args->nchanged,args->nskipped); if ( args->check_ref & CHECK_REF_FIX ) - fprintf(pysam_stderr,"REF/ALT total/modified/added: \t%d/%d/%d\n", args->nref.tot,args->nref.swap,args->nref.set); + fprintf(bcftools_stderr,"REF/ALT total/modified/added: \t%d/%d/%d\n", args->nref.tot,args->nref.swap,args->nref.set); } static void usage(void) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Left-align and normalize indels; check if REF alleles match the reference;\n"); - fprintf(pysam_stderr, " split multiallelic sites into multiple rows; recover multiallelics from\n"); - fprintf(pysam_stderr, " multiple rows.\n"); - fprintf(pysam_stderr, "Usage: bcftools norm [options] \n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Options:\n"); - fprintf(pysam_stderr, " -c, --check-ref check REF alleles and exit (e), warn (w), exclude (x), or set (s) bad sites [e]\n"); - fprintf(pysam_stderr, " -D, --remove-duplicates remove duplicate lines of the same type.\n"); - fprintf(pysam_stderr, " -d, --rm-dup remove duplicate snps|indels|both|any\n"); - fprintf(pysam_stderr, " -f, --fasta-ref reference sequence\n"); - fprintf(pysam_stderr, " -m, --multiallelics <-|+>[type] split multiallelics (-) or join biallelics (+), type: snps|indels|both|any [both]\n"); - fprintf(pysam_stderr, " --no-version do not append version and command line to the header\n"); - fprintf(pysam_stderr, " -N, --do-not-normalize do not normalize indels (with -m or -c s)\n"); - fprintf(pysam_stderr, " -o, --output write output to a file [standard output]\n"); - fprintf(pysam_stderr, " -O, --output-type 'b' compressed BCF; 'u' uncompressed BCF; 'z' compressed VCF; 'v' uncompressed VCF [v]\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " -s, --strict-filter when merging (-m+), merged site is PASS only if all sites being merged PASS\n"); - fprintf(pysam_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " --threads number of extra output compression threads [0]\n"); - fprintf(pysam_stderr, " -w, --site-win buffer for sorting lines which changed position during realignment [1000]\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Left-align and normalize indels; check if REF alleles match the reference;\n"); + fprintf(bcftools_stderr, " split multiallelic sites into multiple rows; recover multiallelics from\n"); + fprintf(bcftools_stderr, " multiple rows.\n"); + fprintf(bcftools_stderr, "Usage: bcftools norm [options] \n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Options:\n"); + fprintf(bcftools_stderr, " -c, --check-ref check REF alleles and exit (e), warn (w), exclude (x), or set (s) bad sites [e]\n"); + fprintf(bcftools_stderr, " -D, --remove-duplicates remove duplicate lines of the same type.\n"); + fprintf(bcftools_stderr, " -d, --rm-dup remove duplicate snps|indels|both|all|none\n"); + fprintf(bcftools_stderr, " -f, --fasta-ref reference sequence (MANDATORY)\n"); + fprintf(bcftools_stderr, " -m, --multiallelics <-|+>[type] split multiallelics (-) or join biallelics (+), type: snps|indels|both|any [both]\n"); + fprintf(bcftools_stderr, " --no-version do not append version and command line to the header\n"); + fprintf(bcftools_stderr, " -N, --do-not-normalize do not normalize indels (with -m or -c s)\n"); + fprintf(bcftools_stderr, " -o, --output write output to a file [standard output]\n"); + fprintf(bcftools_stderr, " -O, --output-type 'b' compressed BCF; 'u' uncompressed BCF; 'z' compressed VCF; 'v' uncompressed VCF [v]\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " -s, --strict-filter when merging (-m+), merged site is PASS only if all sites being merged PASS\n"); + fprintf(bcftools_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " --threads number of extra (de)compression threads [0]\n"); + fprintf(bcftools_stderr, " -w, --site-win buffer for sorting lines which changed position during realignment [1000]\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } @@ -1728,10 +1888,12 @@ int main_vcfnorm(int argc, char *argv[]) switch (c) { case 'N': args->do_indels = 0; break; case 'd': - if ( !strcmp("snps",optarg) ) args->rmdup = COLLAPSE_SNPS<<1; - else if ( !strcmp("indels",optarg) ) args->rmdup = COLLAPSE_INDELS<<1; - else if ( !strcmp("both",optarg) ) args->rmdup = COLLAPSE_BOTH<<1; - else if ( !strcmp("any",optarg) ) args->rmdup = COLLAPSE_ANY<<1; + if ( !strcmp("snps",optarg) ) args->rmdup = BCF_SR_PAIR_SNPS; + else if ( !strcmp("indels",optarg) ) args->rmdup = BCF_SR_PAIR_INDELS; + else if ( !strcmp("both",optarg) ) args->rmdup = BCF_SR_PAIR_BOTH; + else if ( !strcmp("all",optarg) ) args->rmdup = BCF_SR_PAIR_ANY; + else if ( !strcmp("any",optarg) ) args->rmdup = BCF_SR_PAIR_ANY; + else if ( !strcmp("none",optarg) ) args->rmdup = BCF_SR_PAIR_EXACT; else error("The argument to -d not recognised: %s\n", optarg); break; case 'm': @@ -1764,8 +1926,8 @@ int main_vcfnorm(int argc, char *argv[]) break; case 'o': args->output_fname = optarg; break; case 'D': - fprintf(pysam_stderr,"Warning: `-D` is functional but deprecated, replaced by `-d both`.\n"); - args->rmdup = COLLAPSE_NONE<<1; + fprintf(bcftools_stderr,"Warning: `-D` is functional but deprecated, replaced by `-d both`.\n"); + args->rmdup = BCF_SR_PAIR_EXACT; break; case 's': args->strict_filter = 1; break; case 'f': args->ref_fname = optarg; break; @@ -1806,6 +1968,7 @@ int main_vcfnorm(int argc, char *argv[]) error("Failed to read the targets: %s\n", args->targets); } + if ( bcf_sr_set_threads(args->files, args->n_threads)<0 ) error("Failed to create threads\n"); if ( !bcf_sr_add_reader(args->files, fname) ) error("Failed to open %s: %s\n", fname,bcf_sr_strerror(args->files->errnum)); if ( args->mrows_op&MROWS_SPLIT && args->rmdup ) error("Cannot combine -D and -m-\n"); init_data(args); diff --git a/bcftools/vcfplugin.c b/bcftools/vcfplugin.c index 87a773f50..90292f4e9 100644 --- a/bcftools/vcfplugin.c +++ b/bcftools/vcfplugin.c @@ -1,6 +1,6 @@ /* vcfplugin.c -- plugin modules for operating on VCF/BCF files. - Copyright (C) 2013-2015 Genome Research Ltd. + Copyright (C) 2013-2017 Genome Research Ltd. Author: Petr Danecek @@ -22,7 +22,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "config.h" #include +#include #include #include #include @@ -41,13 +43,15 @@ THE SOFTWARE. */ #include "vcmp.h" #include "filter.h" +#ifdef ENABLE_BCF_PLUGINS + typedef struct _plugin_t plugin_t; /** * Plugin API: * ---------- * const char *about(void) - * - short description used by 'bcftools plugin -l' + * - short description used by 'bcftools plugin -lv' * * const char *usage(void) * - longer description used by 'bcftools +name -h' @@ -170,11 +174,11 @@ static void add_plugin_paths(args_t *args, const char *path) args->plugin_paths = (char**) realloc(args->plugin_paths,sizeof(char*)*(args->nplugin_paths+1)); args->plugin_paths[args->nplugin_paths] = dir; args->nplugin_paths++; - if ( args->verbose ) fprintf(stderr, "plugin directory %s .. ok\n", dir); + if ( args->verbose > 1 ) fprintf(stderr, "plugin directory %s .. ok\n", dir); } else { - if ( args->verbose ) fprintf(stderr, "plugin directory %s .. %s\n", dir, strerror(errno)); + if ( args->verbose > 1 ) fprintf(stderr, "plugin directory %s .. %s\n", dir, strerror(errno)); free(dir); } @@ -208,9 +212,9 @@ static void *dlopen_plugin(args_t *args, const char *fname) int i; for (i=0; inplugin_paths; i++) { - tmp = msprintf("%s/%s.so", args->plugin_paths[i],fname); + tmp = msprintf("%s/%s%s", args->plugin_paths[i], fname, PLUGIN_EXT); handle = dlopen(tmp, RTLD_NOW); // valgrind complains about unfreed memory, not our problem though - if ( args->verbose ) + if ( args->verbose > 1 ) { if ( !handle ) fprintf(stderr,"%s:\n\tdlopen .. %s\n", tmp,dlerror()); else fprintf(stderr,"%s:\n\tdlopen .. ok\n", tmp); @@ -221,7 +225,7 @@ static void *dlopen_plugin(args_t *args, const char *fname) } handle = dlopen(fname, RTLD_NOW); - if ( args->verbose ) + if ( args->verbose > 1 ) { if ( !handle ) fprintf(stderr,"%s:\n\tdlopen .. %s\n", fname,dlerror()); else fprintf(stderr,"%s:\n\tdlopen .. ok\n", fname); @@ -266,19 +270,19 @@ static int load_plugin(args_t *args, const char *fname, int exit_on_error, plugi if ( ret ) plugin->init = NULL; else - if ( args->verbose ) fprintf(stderr,"\tinit .. ok\n"); + if ( args->verbose > 1 ) fprintf(stderr,"\tinit .. ok\n"); plugin->run = (dl_run_f) dlsym(plugin->handle, "run"); ret = dlerror(); if ( ret ) plugin->run = NULL; else - if ( args->verbose ) fprintf(stderr,"\trun .. ok\n"); + if ( args->verbose > 1 ) fprintf(stderr,"\trun .. ok\n"); if ( !plugin->init && !plugin->run ) { if ( exit_on_error ) error("Could not initialize %s, neither run or init found \n", plugin->name); - else if ( args->verbose ) fprintf(stderr,"\tinit/run .. not found\n"); + else if ( args->verbose > 1 ) fprintf(stderr,"\tinit/run .. not found\n"); return -1; } @@ -287,7 +291,7 @@ static int load_plugin(args_t *args, const char *fname, int exit_on_error, plugi if ( ret ) { if ( exit_on_error ) error("Could not initialize %s, version string not found\n", plugin->name); - else if ( args->verbose ) fprintf(stderr,"\tversion .. not found\n"); + else if ( args->verbose > 1 ) fprintf(stderr,"\tversion .. not found\n"); return -1; } @@ -361,6 +365,7 @@ static int list_plugins(args_t *args) init_plugin_paths(args); kstring_t str = {0,0,0}; + int plugin_ext_len = strlen(PLUGIN_EXT); int i; for (i=0; inplugin_paths; i++) { @@ -371,7 +376,7 @@ static int list_plugins(args_t *args) while ( (ep=readdir(dp)) ) { int len = strlen(ep->d_name); - if ( strcasecmp(".so",ep->d_name+len-3) ) continue; + if ( strcasecmp(PLUGIN_EXT,ep->d_name+len-plugin_ext_len) ) continue; str.l = 0; ksprintf(&str,"%s/%s", args->plugin_paths[i],ep->d_name); hts_expand(plugin_t, nplugins+1, mplugins, plugins); @@ -392,8 +397,13 @@ static int list_plugins(args_t *args) qsort(plugins, nplugins, sizeof(plugins[0]), cmp_plugin_name); for (i=0; iverbose ) + printf("\n-- %s --\n%s", plugins[i].name, plugins[i].about()); + else + printf("%s\n", plugins[i].name); + } + if ( args->verbose ) printf("\n"); } else print_plugin_usage_hint(); @@ -460,12 +470,33 @@ static void usage(args_t *args) fprintf(stderr, "Plugin options:\n"); fprintf(stderr, " -h, --help list plugin's options\n"); fprintf(stderr, " -l, --list-plugins list available plugins. See BCFTOOLS_PLUGINS environment variable and man page for details\n"); - fprintf(stderr, " -v, --verbose print debugging information on plugin failure\n"); + fprintf(stderr, " -v, --verbose print verbose information, -vv increases verbosity\n"); fprintf(stderr, " -V, --version print version string and exit\n"); fprintf(stderr, "\n"); exit(1); } +static int is_verbose(int argc, char *argv[]) +{ + int c, verbose = 0, opterr_ori = opterr; + static struct option loptions[] = + { + {"verbose",no_argument,NULL,'v'}, + {NULL,0,NULL,0} + }; + opterr = 0; + while ((c = getopt_long(argc, argv, "-v",loptions,NULL)) >= 0) + { + switch (c) { + case 'v': verbose++; break; + case 1: + default: break; + } + } + opterr = opterr_ori; + optind = 0; + return verbose; +} int main_plugin(int argc, char *argv[]) { int c; @@ -483,6 +514,7 @@ int main_plugin(int argc, char *argv[]) char *plugin_name = NULL; if ( argv[1][0]!='-' ) { + args->verbose = is_verbose(argc, argv); plugin_name = argv[1]; argc--; argv++; @@ -518,7 +550,7 @@ int main_plugin(int argc, char *argv[]) { switch (c) { case 'V': version_only = 1; break; - case 'v': args->verbose = 1; break; + case 'v': args->verbose++; break; case 'o': args->output_fname = optarg; break; case 'O': switch (optarg[0]) { @@ -605,7 +637,11 @@ int main_plugin(int argc, char *argv[]) if ( !pass ) continue; } line = args->plugin.process(line); - if ( line ) bcf_write1(args->out_fh, args->hdr_out, line); + if ( line ) + { + if ( line->errcode ) error("[E::main_plugin] Unchecked error (%d), exiting\n",line->errcode); + bcf_write1(args->out_fh, args->hdr_out, line); + } } destroy_data(args); bcf_sr_destroy(args->files); @@ -613,3 +649,13 @@ int main_plugin(int argc, char *argv[]) return 0; } +#else /* ENABLE_BCF_PLUGINS */ + +int main_plugin(int argc, char *argv[]) +{ + fprintf(stderr, "bcftools plugins are disabled. To use them, you will need to rebuild\n" + "bcftools from the source distribution with plugins enabled.\n"); + return 1; +} + +#endif /* ENABLE_BCF_PLUGINS */ diff --git a/bcftools/vcfplugin.c.pysam.c b/bcftools/vcfplugin.c.pysam.c index 8365f7e5f..606e24583 100644 --- a/bcftools/vcfplugin.c.pysam.c +++ b/bcftools/vcfplugin.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfplugin.c -- plugin modules for operating on VCF/BCF files. - Copyright (C) 2013-2015 Genome Research Ltd. + Copyright (C) 2013-2017 Genome Research Ltd. Author: Petr Danecek @@ -24,7 +24,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "config.h" #include +#include #include #include #include @@ -43,13 +45,15 @@ THE SOFTWARE. */ #include "vcmp.h" #include "filter.h" +#ifdef ENABLE_BCF_PLUGINS + typedef struct _plugin_t plugin_t; /** * Plugin API: * ---------- * const char *about(void) - * - short description used by 'bcftools plugin -l' + * - short description used by 'bcftools plugin -lv' * * const char *usage(void) * - longer description used by 'bcftools +name -h' @@ -172,11 +176,11 @@ static void add_plugin_paths(args_t *args, const char *path) args->plugin_paths = (char**) realloc(args->plugin_paths,sizeof(char*)*(args->nplugin_paths+1)); args->plugin_paths[args->nplugin_paths] = dir; args->nplugin_paths++; - if ( args->verbose ) fprintf(pysam_stderr, "plugin directory %s .. ok\n", dir); + if ( args->verbose > 1 ) fprintf(bcftools_stderr, "plugin directory %s .. ok\n", dir); } else { - if ( args->verbose ) fprintf(pysam_stderr, "plugin directory %s .. %s\n", dir, strerror(errno)); + if ( args->verbose > 1 ) fprintf(bcftools_stderr, "plugin directory %s .. %s\n", dir, strerror(errno)); free(dir); } @@ -210,12 +214,12 @@ static void *dlopen_plugin(args_t *args, const char *fname) int i; for (i=0; inplugin_paths; i++) { - tmp = msprintf("%s/%s.so", args->plugin_paths[i],fname); + tmp = msprintf("%s/%s%s", args->plugin_paths[i], fname, PLUGIN_EXT); handle = dlopen(tmp, RTLD_NOW); // valgrind complains about unfreed memory, not our problem though - if ( args->verbose ) + if ( args->verbose > 1 ) { - if ( !handle ) fprintf(pysam_stderr,"%s:\n\tdlopen .. %s\n", tmp,dlerror()); - else fprintf(pysam_stderr,"%s:\n\tdlopen .. ok\n", tmp); + if ( !handle ) fprintf(bcftools_stderr,"%s:\n\tdlopen .. %s\n", tmp,dlerror()); + else fprintf(bcftools_stderr,"%s:\n\tdlopen .. ok\n", tmp); } free(tmp); if ( handle ) return handle; @@ -223,10 +227,10 @@ static void *dlopen_plugin(args_t *args, const char *fname) } handle = dlopen(fname, RTLD_NOW); - if ( args->verbose ) + if ( args->verbose > 1 ) { - if ( !handle ) fprintf(pysam_stderr,"%s:\n\tdlopen .. %s\n", fname,dlerror()); - else fprintf(pysam_stderr,"%s:\n\tdlopen .. ok\n", fname); + if ( !handle ) fprintf(bcftools_stderr,"%s:\n\tdlopen .. %s\n", fname,dlerror()); + else fprintf(bcftools_stderr,"%s:\n\tdlopen .. ok\n", fname); } return handle; @@ -234,11 +238,11 @@ static void *dlopen_plugin(args_t *args, const char *fname) static void print_plugin_usage_hint(void) { - fprintf(pysam_stderr, "\nNo functional bcftools plugins were found"); + fprintf(bcftools_stderr, "\nNo functional bcftools plugins were found"); if ( !getenv("BCFTOOLS_PLUGINS") ) - fprintf(pysam_stderr,". The environment variable BCFTOOLS_PLUGINS is not set.\n\n"); + fprintf(bcftools_stderr,". The environment variable BCFTOOLS_PLUGINS is not set.\n\n"); else - fprintf(pysam_stderr, + fprintf(bcftools_stderr, " in\n\tBCFTOOLS_PLUGINS=\"%s\".\n\n" "- Is the plugin path correct?\n\n" "- Run \"bcftools plugin -lv\" for more detailed error output.\n" @@ -268,19 +272,19 @@ static int load_plugin(args_t *args, const char *fname, int exit_on_error, plugi if ( ret ) plugin->init = NULL; else - if ( args->verbose ) fprintf(pysam_stderr,"\tinit .. ok\n"); + if ( args->verbose > 1 ) fprintf(bcftools_stderr,"\tinit .. ok\n"); plugin->run = (dl_run_f) dlsym(plugin->handle, "run"); ret = dlerror(); if ( ret ) plugin->run = NULL; else - if ( args->verbose ) fprintf(pysam_stderr,"\trun .. ok\n"); + if ( args->verbose > 1 ) fprintf(bcftools_stderr,"\trun .. ok\n"); if ( !plugin->init && !plugin->run ) { if ( exit_on_error ) error("Could not initialize %s, neither run or init found \n", plugin->name); - else if ( args->verbose ) fprintf(pysam_stderr,"\tinit/run .. not found\n"); + else if ( args->verbose > 1 ) fprintf(bcftools_stderr,"\tinit/run .. not found\n"); return -1; } @@ -289,7 +293,7 @@ static int load_plugin(args_t *args, const char *fname, int exit_on_error, plugi if ( ret ) { if ( exit_on_error ) error("Could not initialize %s, version string not found\n", plugin->name); - else if ( args->verbose ) fprintf(pysam_stderr,"\tversion .. not found\n"); + else if ( args->verbose > 1 ) fprintf(bcftools_stderr,"\tversion .. not found\n"); return -1; } @@ -337,12 +341,12 @@ static void init_plugin(args_t *args) args->plugin.version(&bver, &hver); if ( strcmp(bver,bcftools_version()) && !warned_bcftools ) { - fprintf(pysam_stderr,"WARNING: bcftools version mismatch .. bcftools at %s, the plugin \"%s\" at %s\n", bcftools_version(),args->plugin.name,bver); + fprintf(bcftools_stderr,"WARNING: bcftools version mismatch .. bcftools at %s, the plugin \"%s\" at %s\n", bcftools_version(),args->plugin.name,bver); warned_bcftools = 1; } if ( strcmp(hver,hts_version()) && !warned_htslib ) { - fprintf(pysam_stderr,"WARNING: htslib version mismatch .. bcftools at %s, the plugin \"%s\" at %s\n", hts_version(),args->plugin.name,hver); + fprintf(bcftools_stderr,"WARNING: htslib version mismatch .. bcftools at %s, the plugin \"%s\" at %s\n", hts_version(),args->plugin.name,hver); warned_htslib = 1; } args->drop_header += ret; @@ -363,6 +367,7 @@ static int list_plugins(args_t *args) init_plugin_paths(args); kstring_t str = {0,0,0}; + int plugin_ext_len = strlen(PLUGIN_EXT); int i; for (i=0; inplugin_paths; i++) { @@ -373,7 +378,7 @@ static int list_plugins(args_t *args) while ( (ep=readdir(dp)) ) { int len = strlen(ep->d_name); - if ( strcasecmp(".so",ep->d_name+len-3) ) continue; + if ( strcasecmp(PLUGIN_EXT,ep->d_name+len-plugin_ext_len) ) continue; str.l = 0; ksprintf(&str,"%s/%s", args->plugin_paths[i],ep->d_name); hts_expand(plugin_t, nplugins+1, mplugins, plugins); @@ -394,8 +399,13 @@ static int list_plugins(args_t *args) qsort(plugins, nplugins, sizeof(plugins[0]), cmp_plugin_name); for (i=0; iverbose ) + fprintf(bcftools_stdout, "\n-- %s --\n%s", plugins[i].name, plugins[i].about()); + else + fprintf(bcftools_stdout, "%s\n", plugins[i].name); + } + if ( args->verbose ) fprintf(bcftools_stdout, "\n"); } else print_plugin_usage_hint(); @@ -442,32 +452,53 @@ static void destroy_data(args_t *args) static void usage(args_t *args) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Run user defined plugin\n"); - fprintf(pysam_stderr, "Usage: bcftools plugin [OPTIONS] [-- PLUGIN_OPTIONS]\n"); - fprintf(pysam_stderr, " bcftools +name [OPTIONS] [-- PLUGIN_OPTIONS]\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "VCF input options:\n"); - fprintf(pysam_stderr, " -e, --exclude exclude sites for which the expression is true\n"); - fprintf(pysam_stderr, " -i, --include select sites for which the expression is true\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); - fprintf(pysam_stderr, "VCF output options:\n"); - fprintf(pysam_stderr, " --no-version do not append version and command line to the header\n"); - fprintf(pysam_stderr, " -o, --output write output to a file [standard output]\n"); - fprintf(pysam_stderr, " -O, --output-type 'b' compressed BCF; 'u' uncompressed BCF; 'z' compressed VCF; 'v' uncompressed VCF [v]\n"); - fprintf(pysam_stderr, " --threads number of extra output compression threads [0]\n"); - fprintf(pysam_stderr, "Plugin options:\n"); - fprintf(pysam_stderr, " -h, --help list plugin's options\n"); - fprintf(pysam_stderr, " -l, --list-plugins list available plugins. See BCFTOOLS_PLUGINS environment variable and man page for details\n"); - fprintf(pysam_stderr, " -v, --verbose print debugging information on plugin failure\n"); - fprintf(pysam_stderr, " -V, --version print version string and exit\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Run user defined plugin\n"); + fprintf(bcftools_stderr, "Usage: bcftools plugin [OPTIONS] [-- PLUGIN_OPTIONS]\n"); + fprintf(bcftools_stderr, " bcftools +name [OPTIONS] [-- PLUGIN_OPTIONS]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "VCF input options:\n"); + fprintf(bcftools_stderr, " -e, --exclude exclude sites for which the expression is true\n"); + fprintf(bcftools_stderr, " -i, --include select sites for which the expression is true\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, "VCF output options:\n"); + fprintf(bcftools_stderr, " --no-version do not append version and command line to the header\n"); + fprintf(bcftools_stderr, " -o, --output write output to a file [standard output]\n"); + fprintf(bcftools_stderr, " -O, --output-type 'b' compressed BCF; 'u' uncompressed BCF; 'z' compressed VCF; 'v' uncompressed VCF [v]\n"); + fprintf(bcftools_stderr, " --threads number of extra output compression threads [0]\n"); + fprintf(bcftools_stderr, "Plugin options:\n"); + fprintf(bcftools_stderr, " -h, --help list plugin's options\n"); + fprintf(bcftools_stderr, " -l, --list-plugins list available plugins. See BCFTOOLS_PLUGINS environment variable and man page for details\n"); + fprintf(bcftools_stderr, " -v, --verbose print verbose information, -vv increases verbosity\n"); + fprintf(bcftools_stderr, " -V, --version print version string and exit\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } +static int is_verbose(int argc, char *argv[]) +{ + int c, verbose = 0, opterr_ori = opterr; + static struct option loptions[] = + { + {"verbose",no_argument,NULL,'v'}, + {NULL,0,NULL,0} + }; + opterr = 0; + while ((c = getopt_long(argc, argv, "-v",loptions,NULL)) >= 0) + { + switch (c) { + case 'v': verbose++; break; + case 1: + default: break; + } + } + opterr = opterr_ori; + optind = 0; + return verbose; +} int main_plugin(int argc, char *argv[]) { int c; @@ -485,6 +516,7 @@ int main_plugin(int argc, char *argv[]) char *plugin_name = NULL; if ( argv[1][0]!='-' ) { + args->verbose = is_verbose(argc, argv); plugin_name = argv[1]; argc--; argv++; @@ -520,7 +552,7 @@ int main_plugin(int argc, char *argv[]) { switch (c) { case 'V': version_only = 1; break; - case 'v': args->verbose = 1; break; + case 'v': args->verbose++; break; case 'o': args->output_fname = optarg; break; case 'O': switch (optarg[0]) { @@ -552,17 +584,17 @@ int main_plugin(int argc, char *argv[]) { const char *bver, *hver; args->plugin.version(&bver, &hver); - fprintf(pysam_stdout, "bcftools %s using htslib %s\n", bcftools_version(), hts_version()); - fprintf(pysam_stdout, "plugin at %s using htslib %s\n\n", bver, hver); + fprintf(bcftools_stdout, "bcftools %s using htslib %s\n", bcftools_version(), hts_version()); + fprintf(bcftools_stdout, "plugin at %s using htslib %s\n\n", bver, hver); return 0; } if ( usage_only ) { if ( args->plugin.usage ) - fprintf(pysam_stderr,"%s",args->plugin.usage()); + fprintf(bcftools_stderr,"%s",args->plugin.usage()); else - fprintf(pysam_stderr,"Usage: bcftools +%s [General Options] -- [Plugin Options]\n",plugin_name); + fprintf(bcftools_stderr,"Usage: bcftools +%s [General Options] -- [Plugin Options]\n",plugin_name); return 0; } @@ -607,7 +639,11 @@ int main_plugin(int argc, char *argv[]) if ( !pass ) continue; } line = args->plugin.process(line); - if ( line ) bcf_write1(args->out_fh, args->hdr_out, line); + if ( line ) + { + if ( line->errcode ) error("[E::main_plugin] Unchecked error (%d), exiting\n",line->errcode); + bcf_write1(args->out_fh, args->hdr_out, line); + } } destroy_data(args); bcf_sr_destroy(args->files); @@ -615,3 +651,13 @@ int main_plugin(int argc, char *argv[]) return 0; } +#else /* ENABLE_BCF_PLUGINS */ + +int main_plugin(int argc, char *argv[]) +{ + fprintf(bcftools_stderr, "bcftools plugins are disabled. To use them, you will need to rebuild\n" + "bcftools from the source distribution with plugins enabled.\n"); + return 1; +} + +#endif /* ENABLE_BCF_PLUGINS */ diff --git a/bcftools/vcfquery.c b/bcftools/vcfquery.c index ab4c100ef..29c4a9df2 100644 --- a/bcftools/vcfquery.c +++ b/bcftools/vcfquery.c @@ -1,6 +1,6 @@ /* vcfquery.c -- Extracts fields from VCF/BCF file. - Copyright (C) 2013-2014 Genome Research Ltd. + Copyright (C) 2013-2017 Genome Research Ltd. Author: Petr Danecek @@ -32,6 +32,7 @@ THE SOFTWARE. */ #include #include #include +#include #include #include "bcftools.h" #include "filter.h" @@ -47,6 +48,7 @@ typedef struct filter_t *filter; char *filter_str; int filter_logic; // include or exclude sites which match the filters? One of FLT_INCLUDE/FLT_EXCLUDE + uint8_t *smpl_pass; convert_t *convert; bcf_srs_t *files; bcf_hdr_t *header; @@ -98,6 +100,7 @@ static void init_data(args_t *args) } } args->convert = convert_init(args->header, samples, nsamples, args->format_str); + convert_set_option(args->convert, subset_samples, &args->smpl_pass); if ( args->allow_undef_tags ) convert_set_option(args->convert, allow_undef_tags, 1); free(samples); @@ -128,6 +131,7 @@ static void query_vcf(args_t *args) fwrite(str.s, str.l, 1, args->out); } + int i,max_convert_unpack = convert_max_unpack(args->convert); while ( bcf_sr_next_line(args->files) ) { if ( !bcf_sr_has_line(args->files,0) ) continue; @@ -136,9 +140,30 @@ static void query_vcf(args_t *args) if ( args->filter ) { - int pass = filter_test(args->filter, line, NULL); - if ( args->filter_logic & FLT_EXCLUDE ) pass = pass ? 0 : 1; - if ( !pass ) continue; + int pass = filter_test(args->filter, line, (const uint8_t**) &args->smpl_pass); + if ( args->filter_logic & FLT_EXCLUDE ) + { + // This code addresses this problem: + // -i can include a site but exclude a sample + // -e exclude a site but include a sample + + if ( pass ) + { + if ( !args->smpl_pass ) continue; + if ( !(max_convert_unpack & BCF_UN_FMT) ) continue; + + pass = 0; + for (i=0; in_sample; i++) + { + if ( args->smpl_pass[i] ) args->smpl_pass[i] = 0; + else { args->smpl_pass[i] = 1; pass = 1; } + } + if ( !pass ) continue; + } + else if ( args->smpl_pass ) + for (i=0; in_sample; i++) args->smpl_pass[i] = 1; + } + else if ( !pass ) continue; } str.l = 0; @@ -151,10 +176,26 @@ static void query_vcf(args_t *args) static void list_columns(args_t *args) { + void *has_sample = NULL; + if ( args->sample_list ) + { + has_sample = khash_str2int_init(); + int i, nsmpl; + char **smpl = hts_readlist(args->sample_list, args->sample_is_file, &nsmpl); + for (i=0; ifiles->readers[0]; for (i=0; iheader); i++) + { + if ( has_sample && !khash_str2int_has_key(has_sample, reader->header->samples[i]) ) continue; printf("%s\n", reader->header->samples[i]); + } + + if ( has_sample ) + khash_str2int_destroy_free(has_sample); } static char **copy_header(bcf_hdr_t *hdr, char **src, int nsrc) @@ -181,7 +222,6 @@ static void usage(void) fprintf(stderr, "Usage: bcftools query [options] [ [...]]\n"); fprintf(stderr, "\n"); fprintf(stderr, "Options:\n"); - fprintf(stderr, " -c, --collapse collapse lines with duplicate positions for , see man page [none]\n"); fprintf(stderr, " -e, --exclude exclude sites for which the expression is true (see man page for details)\n"); fprintf(stderr, " -f, --format see man page for details\n"); fprintf(stderr, " -H, --print-header print header\n"); @@ -237,14 +277,8 @@ int main_vcfquery(int argc, char *argv[]) case 'f': args->format_str = strdup(optarg); break; case 'H': args->print_header = 1; break; case 'v': args->vcf_list = optarg; break; - case 'c': - if ( !strcmp(optarg,"snps") ) collapse |= COLLAPSE_SNPS; - else if ( !strcmp(optarg,"indels") ) collapse |= COLLAPSE_INDELS; - else if ( !strcmp(optarg,"both") ) collapse |= COLLAPSE_SNPS | COLLAPSE_INDELS; - else if ( !strcmp(optarg,"any") ) collapse |= COLLAPSE_ANY; - else if ( !strcmp(optarg,"all") ) collapse |= COLLAPSE_ANY; - else if ( !strcmp(optarg,"some") ) collapse |= COLLAPSE_SOME; - else error("The --collapse string \"%s\" not recognised.\n", optarg); + case 'c': + error("The --collapse option is obsolete, pipe through `bcftools norm -c` instead.\n", optarg); break; case 'a': { @@ -305,7 +339,6 @@ int main_vcfquery(int argc, char *argv[]) { if ( !fname ) usage(); args->files = bcf_sr_init(); - args->files->collapse = collapse; if ( optind+1 < argc ) args->files->require_index = 1; if ( args->regions_list && bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 ) error("Failed to read the regions: %s\n", args->regions_list); diff --git a/bcftools/vcfquery.c.pysam.c b/bcftools/vcfquery.c.pysam.c index 10f56f157..8186a59d9 100644 --- a/bcftools/vcfquery.c.pysam.c +++ b/bcftools/vcfquery.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfquery.c -- Extracts fields from VCF/BCF file. - Copyright (C) 2013-2014 Genome Research Ltd. + Copyright (C) 2013-2017 Genome Research Ltd. Author: Petr Danecek @@ -34,6 +34,7 @@ THE SOFTWARE. */ #include #include #include +#include #include #include "bcftools.h" #include "filter.h" @@ -49,6 +50,7 @@ typedef struct filter_t *filter; char *filter_str; int filter_logic; // include or exclude sites which match the filters? One of FLT_INCLUDE/FLT_EXCLUDE + uint8_t *smpl_pass; convert_t *convert; bcf_srs_t *files; bcf_hdr_t *header; @@ -100,6 +102,7 @@ static void init_data(args_t *args) } } args->convert = convert_init(args->header, samples, nsamples, args->format_str); + convert_set_option(args->convert, subset_samples, &args->smpl_pass); if ( args->allow_undef_tags ) convert_set_option(args->convert, allow_undef_tags, 1); free(samples); @@ -130,6 +133,7 @@ static void query_vcf(args_t *args) fwrite(str.s, str.l, 1, args->out); } + int i,max_convert_unpack = convert_max_unpack(args->convert); while ( bcf_sr_next_line(args->files) ) { if ( !bcf_sr_has_line(args->files,0) ) continue; @@ -138,9 +142,30 @@ static void query_vcf(args_t *args) if ( args->filter ) { - int pass = filter_test(args->filter, line, NULL); - if ( args->filter_logic & FLT_EXCLUDE ) pass = pass ? 0 : 1; - if ( !pass ) continue; + int pass = filter_test(args->filter, line, (const uint8_t**) &args->smpl_pass); + if ( args->filter_logic & FLT_EXCLUDE ) + { + // This code addresses this problem: + // -i can include a site but exclude a sample + // -e exclude a site but include a sample + + if ( pass ) + { + if ( !args->smpl_pass ) continue; + if ( !(max_convert_unpack & BCF_UN_FMT) ) continue; + + pass = 0; + for (i=0; in_sample; i++) + { + if ( args->smpl_pass[i] ) args->smpl_pass[i] = 0; + else { args->smpl_pass[i] = 1; pass = 1; } + } + if ( !pass ) continue; + } + else if ( args->smpl_pass ) + for (i=0; in_sample; i++) args->smpl_pass[i] = 1; + } + else if ( !pass ) continue; } str.l = 0; @@ -153,10 +178,26 @@ static void query_vcf(args_t *args) static void list_columns(args_t *args) { + void *has_sample = NULL; + if ( args->sample_list ) + { + has_sample = khash_str2int_init(); + int i, nsmpl; + char **smpl = hts_readlist(args->sample_list, args->sample_is_file, &nsmpl); + for (i=0; ifiles->readers[0]; for (i=0; iheader); i++) - fprintf(pysam_stdout, "%s\n", reader->header->samples[i]); + { + if ( has_sample && !khash_str2int_has_key(has_sample, reader->header->samples[i]) ) continue; + fprintf(bcftools_stdout, "%s\n", reader->header->samples[i]); + } + + if ( has_sample ) + khash_str2int_destroy_free(has_sample); } static char **copy_header(bcf_hdr_t *hdr, char **src, int nsrc) @@ -178,30 +219,29 @@ static int compare_header(bcf_hdr_t *hdr, char **a, int na, char **b, int nb) static void usage(void) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Extracts fields from VCF/BCF file and prints them in user-defined format\n"); - fprintf(pysam_stderr, "Usage: bcftools query [options] [ [...]]\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Options:\n"); - fprintf(pysam_stderr, " -c, --collapse collapse lines with duplicate positions for , see man page [none]\n"); - fprintf(pysam_stderr, " -e, --exclude exclude sites for which the expression is true (see man page for details)\n"); - fprintf(pysam_stderr, " -f, --format see man page for details\n"); - fprintf(pysam_stderr, " -H, --print-header print header\n"); - fprintf(pysam_stderr, " -i, --include select sites for which the expression is true (see man page for details)\n"); - fprintf(pysam_stderr, " -l, --list-samples print the list of samples and exit\n"); - fprintf(pysam_stderr, " -o, --output-file output file name [pysam_stdout]\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " -s, --samples list of samples to include\n"); - fprintf(pysam_stderr, " -S, --samples-file file of samples to include\n"); - fprintf(pysam_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -u, --allow-undef-tags print \".\" for undefined tags\n"); - fprintf(pysam_stderr, " -v, --vcf-list process multiple VCFs listed in the file\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Examples:\n"); - fprintf(pysam_stderr, "\tbcftools query -f '%%CHROM\\t%%POS\\t%%REF\\t%%ALT[\\t%%SAMPLE=%%GT]\\n' file.vcf.gz\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Extracts fields from VCF/BCF file and prints them in user-defined format\n"); + fprintf(bcftools_stderr, "Usage: bcftools query [options] [ [...]]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Options:\n"); + fprintf(bcftools_stderr, " -e, --exclude exclude sites for which the expression is true (see man page for details)\n"); + fprintf(bcftools_stderr, " -f, --format see man page for details\n"); + fprintf(bcftools_stderr, " -H, --print-header print header\n"); + fprintf(bcftools_stderr, " -i, --include select sites for which the expression is true (see man page for details)\n"); + fprintf(bcftools_stderr, " -l, --list-samples print the list of samples and exit\n"); + fprintf(bcftools_stderr, " -o, --output-file output file name [bcftools_stdout]\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " -s, --samples list of samples to include\n"); + fprintf(bcftools_stderr, " -S, --samples-file file of samples to include\n"); + fprintf(bcftools_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -u, --allow-undef-tags print \".\" for undefined tags\n"); + fprintf(bcftools_stderr, " -v, --vcf-list process multiple VCFs listed in the file\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Examples:\n"); + fprintf(bcftools_stderr, "\tbcftools query -f '%%CHROM\\t%%POS\\t%%REF\\t%%ALT[\\t%%SAMPLE=%%GT]\\n' file.vcf.gz\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } @@ -239,14 +279,8 @@ int main_vcfquery(int argc, char *argv[]) case 'f': args->format_str = strdup(optarg); break; case 'H': args->print_header = 1; break; case 'v': args->vcf_list = optarg; break; - case 'c': - if ( !strcmp(optarg,"snps") ) collapse |= COLLAPSE_SNPS; - else if ( !strcmp(optarg,"indels") ) collapse |= COLLAPSE_INDELS; - else if ( !strcmp(optarg,"both") ) collapse |= COLLAPSE_SNPS | COLLAPSE_INDELS; - else if ( !strcmp(optarg,"any") ) collapse |= COLLAPSE_ANY; - else if ( !strcmp(optarg,"all") ) collapse |= COLLAPSE_ANY; - else if ( !strcmp(optarg,"some") ) collapse |= COLLAPSE_SOME; - else error("The --collapse string \"%s\" not recognised.\n", optarg); + case 'c': + error("The --collapse option is obsolete, pipe through `bcftools norm -c` instead.\n", optarg); break; case 'a': { @@ -300,14 +334,13 @@ int main_vcfquery(int argc, char *argv[]) } if ( !args->format_str ) usage(); - args->out = args->fn_out ? fopen(args->fn_out, "w") : pysam_stdout; + args->out = args->fn_out ? fopen(args->fn_out, "w") : bcftools_stdout; if ( !args->out ) error("%s: %s\n", args->fn_out,strerror(errno)); if ( !args->vcf_list ) { if ( !fname ) usage(); args->files = bcf_sr_init(); - args->files->collapse = collapse; if ( optind+1 < argc ) args->files->require_index = 1; if ( args->regions_list && bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 ) error("Failed to read the regions: %s\n", args->regions_list); diff --git a/bcftools/vcfroh.c b/bcftools/vcfroh.c index 95605592f..626f97538 100644 --- a/bcftools/vcfroh.c +++ b/bcftools/vcfroh.c @@ -1,6 +1,6 @@ /* vcfroh.c -- HMM model for detecting runs of autozygosity. - Copyright (C) 2013-2015 Genome Research Ltd. + Copyright (C) 2013-2017 Genome Research Ltd. Author: Petr Danecek @@ -30,12 +30,19 @@ THE SOFTWARE. */ #include #include #include +#include +#include #include "bcftools.h" #include "HMM.h" +#include "smpl_ilist.h" #define STATE_HW 0 // normal state, follows Hardy-Weinberg allele frequencies #define STATE_AZ 1 // autozygous state +#define OUTPUT_ST (1<<1) +#define OUTPUT_RG (1<<2) +#define OUTPUT_GZ (1<<3) + /** Genetic map */ typedef struct { @@ -44,6 +51,24 @@ typedef struct } genmap_t; +/** HMM data for each sample */ +typedef struct +{ + double *eprob; // emission probs [2*nsites,msites] + uint32_t *sites; // positions [nsites,msites] + int nsites, msites; + int igenmap; // current position in genmap + int nused; // some stats to detect if things didn't go wrong + int nrid, *rid, *rid_off; // for viterbi training, keep all chromosomes + void *snapshot; // hmm snapshot + struct { + uint32_t beg,end,nqual; + double qual; + int rid, state; + } rg; +} +smpl_t; + typedef struct _args_t { bcf_srs_t *files; @@ -57,29 +82,32 @@ typedef struct _args_t double rec_rate; // constant recombination rate if > 0 hmm_t *hmm; - double *eprob; // emission probs [2*nsites,msites] - uint32_t *sites; // positions [nsites,msites] - int nsites, msites; + double baum_welch_th; int nrids, *rids, *rid_offs; // multiple chroms with vi_training + int nbuf_max, nbuf_olap; - int32_t *itmp; - int nitmp, mitmp; float *AFs; - int mAFs; + int32_t *itmp; + int mAFs, nitmp, mitmp, pl_hdr_id, gt_hdr_id; double pl2p[256], *pdg; int32_t skip_rid, prev_rid, prev_pos; - int ntot, nused; // some stats to detect if things didn't go awfully wrong - int ismpl, nsmpl; // index of query sample - char *estimate_AF, *sample; // list of samples for AF estimate and query sample - char **argv, *targets_list, *regions_list, *af_fname, *af_tag; - int argc, fake_PLs, snps_only, vi_training; + int ntot; // some stats to detect if things didn't go wrong + smpl_t *smpl; // HMM data for each sample + smpl_ilist_t *af_smpl; // list of samples to estimate AF from (--estimate-AF) + smpl_ilist_t *roh_smpl; // list of samples to analyze (--samples, --samples-file) + char *estimate_AF; // list of samples for AF estimate and query sample + int af_from_PL; // estimate AF from FMT/PL rather than FMT/GT + char **argv, *targets_list, *regions_list, *af_fname, *af_tag, *samples, *buffer_size, *output_fname; + int argc, fake_PLs, snps_only, vi_training, samples_is_file, output_type, skip_homref, n_threads; + BGZF *out; + kstring_t str; } args_t; void set_tprob_genmap(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, double *tprob); -void set_tprob_recrate(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, double *tprob); +void set_tprob_rrate(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, double *tprob); void *smalloc(size_t size) { @@ -90,57 +118,137 @@ void *smalloc(size_t size) static void init_data(args_t *args) { + int i; + args->prev_rid = args->skip_rid = -1; args->hdr = args->files->readers[0].header; - if ( !args->sample ) - { - if ( bcf_hdr_nsamples(args->hdr)>1 ) error("Missing the option -s, --sample\n"); - args->sample = strdup(args->hdr->samples[0]); - } if ( !bcf_hdr_nsamples(args->hdr) ) error("No samples in the VCF?\n"); - // Set samples - kstring_t str = {0,0,0}; - if ( args->estimate_AF && strcmp("-",args->estimate_AF) ) + if ( !args->fake_PLs ) { - int i, n; - char **smpls = hts_readlist(args->estimate_AF, 1, &n); + args->pl_hdr_id = bcf_hdr_id2int(args->hdr, BCF_DT_ID, "PL"); + if ( !bcf_hdr_idinfo_exists(args->hdr,BCF_HL_FMT,args->pl_hdr_id) ) + error("Error: The FORMAT/PL tag not found in the header, consider running with -G\n"); + if ( bcf_hdr_id2type(args->hdr,BCF_HL_FMT,args->pl_hdr_id)!=BCF_HT_INT ) + error("Error: The FORMAT/PL tag not defined as Integer in the header\n"); + } - // Make sure the query sample is included - for (i=0; isample,smpls[i]) ) break; + if ( args->estimate_AF ) + { + if ( !strncmp("GT,",args->estimate_AF,3) ) args->estimate_AF += 3; + else if ( !strncmp("PL,",args->estimate_AF,3) ) { args->estimate_AF += 3; args->af_from_PL = 1; } + if ( strcmp("-",args->estimate_AF) ) + args->af_smpl = smpl_ilist_init(args->hdr, args->estimate_AF, 1, SMPL_NONE); + } - // Add the query sample if not present - if ( i!=n ) kputs(args->sample, &str); + if ( args->estimate_AF || args->fake_PLs ) + { + if ( args->af_from_PL ) + { + args->pl_hdr_id = bcf_hdr_id2int(args->hdr, BCF_DT_ID, "PL"); + if ( !bcf_hdr_idinfo_exists(args->hdr,BCF_HL_FMT,args->pl_hdr_id) ) + error("Error: The FORMAT/PL tag not found in the header\n"); + } + else + { + args->gt_hdr_id = bcf_hdr_id2int(args->hdr, BCF_DT_ID, "GT"); + if ( !bcf_hdr_idinfo_exists(args->hdr,BCF_HL_FMT,args->gt_hdr_id) ) + error("Error: The FORMAT/GT tag not found in the header\n"); + } + } + if ( args->fake_PLs ) + { + args->gt_hdr_id = bcf_hdr_id2int(args->hdr, BCF_DT_ID, "GT"); + if ( !bcf_hdr_idinfo_exists(args->hdr,BCF_HL_FMT,args->gt_hdr_id) ) + error("Error: The FORMAT/GT tag not found in the header\n"); + } - for (i=0; iroh_smpl = smpl_ilist_init(args->hdr, args->samples, args->samples_is_file, SMPL_NONE); + if ( args->samples ) + { + // we may be able to subset to a few samples, for a text VCF this can be a major speedup + if ( (bcf_sr_get_reader(args->files,0))->file->format.format==vcf ) { - if ( str.l ) kputc(',', &str); - kputs(smpls[i], &str); - free(smpls[i]); + kstring_t str = {0,0,0}; + smpl_ilist_t *tmp = args->roh_smpl, *rmme = NULL; + if ( args->af_smpl ) + { + for (i=0; iroh_smpl->n; i++) + { + if ( str.l ) kputc(',', &str); + kputs(args->hdr->samples[args->roh_smpl->idx[i]], &str); + } + for (i=0; iaf_smpl->n; i++) + { + kputc(',', &str); + kputs(args->hdr->samples[args->af_smpl->idx[i]], &str); + } + rmme = tmp = smpl_ilist_init(args->hdr, str.s, 0, SMPL_NONE); + } + if ( tmp->n < bcf_hdr_nsamples(args->hdr) ) + { + str.l = 0; + for (i=0; in; i++) + { + if ( str.l ) kputc(',', &str); + kputs(args->hdr->samples[tmp->idx[i]], &str); + } + int ret = bcf_hdr_set_samples(args->hdr, str.s, 0); + if ( ret<0 ) error("Error parsing the list of samples: %s\n", str.s); + else if ( ret>0 ) error("The %d-th sample not found in the VCF: %s\n", ret,str.s); + + // update sample ids + smpl_ilist_destroy(args->roh_smpl); + args->roh_smpl = smpl_ilist_init(args->hdr, args->samples, args->samples_is_file, SMPL_NONE); + + if ( args->af_smpl ) + { + smpl_ilist_destroy(args->af_smpl); + args->af_smpl = smpl_ilist_init(args->hdr, args->estimate_AF, 1, SMPL_NONE); + } + } + free(str.s); + if ( rmme ) + smpl_ilist_destroy(rmme); } - free(smpls); } - else if ( !args->estimate_AF ) - kputs(args->sample, &str); - if ( str.l ) + // check whether all samples are in this list. If so, the lookup will not be needed + if ( args->af_smpl && args->af_smpl->n == bcf_hdr_nsamples(args->hdr) ) { - int ret = bcf_hdr_set_samples(args->hdr, str.s, 0); - if ( ret<0 ) error("Error parsing the list of samples: %s\n", str.s); - else if ( ret>0 ) error("The %d-th sample not found in the VCF\n", ret); + // all samples are in this list + smpl_ilist_destroy(args->af_smpl); + args->af_smpl = NULL; } - if ( args->af_tag ) - if ( !bcf_hdr_idinfo_exists(args->hdr,BCF_HL_INFO,bcf_hdr_id2int(args->hdr,BCF_DT_ID,args->af_tag)) ) - error("No such INFO tag in the VCF: %s\n", args->af_tag); + if ( args->buffer_size ) + { + args->nbuf_olap = -1; + char *end; + double tmp = strtod(args->buffer_size,&end); + if ( *end ) + { + if ( *end!=',') error("Could not parse: --buffer-size %s\n", args->buffer_size); + args->nbuf_olap = strtol(end+1,&end,10); + if ( *end || args->nbuf_olap<0 ) error("Could not parse: --bufer-size %s\n", args->buffer_size); + } + if ( tmp<0 ) + args->nbuf_max = fabs(tmp)*1e6/(4+8*2)/args->roh_smpl->n; + else + args->nbuf_max = tmp; - args->nsmpl = bcf_hdr_nsamples(args->hdr); - args->ismpl = bcf_hdr_id2int(args->hdr, BCF_DT_SAMPLE, args->sample); - free(str.s); + if ( args->nbuf_olap<0 ) + args->nbuf_olap = args->nbuf_max*0.01; + } + fprintf(stderr,"Number of target samples: %d\n", args->roh_smpl->n); + fprintf(stderr,"Number of --estimate-AF samples: %d\n", args->af_smpl ? args->af_smpl->n : (args->estimate_AF ? bcf_hdr_nsamples(args->hdr) : 0)); + fprintf(stderr,"Number of sites in the buffer/overlap: "); + if ( args->nbuf_max ) fprintf(stderr,"%d/%d\n", args->nbuf_max,args->nbuf_olap); + else fprintf(stderr,"unlimited\n"); + + args->smpl = (smpl_t*) calloc(args->roh_smpl->n,sizeof(smpl_t)); - int i; for (i=0; i<256; i++) args->pl2p[i] = pow(10., -i/10.); // Init transition matrix and HMM @@ -150,43 +258,91 @@ static void init_data(args_t *args) MAT(tprob,2,STATE_AZ,STATE_HW) = args->t2AZ; MAT(tprob,2,STATE_AZ,STATE_AZ) = 1 - args->t2HW; + args->hmm = hmm_init(2, tprob, 10000); if ( args->genmap_fname ) - { - args->hmm = hmm_init(2, tprob, 0); hmm_set_tprob_func(args->hmm, set_tprob_genmap, args); - } else if ( args->rec_rate > 0 ) - { - args->hmm = hmm_init(2, tprob, 0); - hmm_set_tprob_func(args->hmm, set_tprob_recrate, args); + hmm_set_tprob_func(args->hmm, set_tprob_rrate, args); - } - else - args->hmm = hmm_init(2, tprob, 10000); + args->out = bgzf_open(strcmp("stdout",args->output_fname)?args->output_fname:"-", args->output_type&OUTPUT_GZ ? "wg" : "wu"); + if ( !args->out ) error("Failed to open %s: %s\n", args->output_fname, strerror(errno)); // print header - printf("# This file was produced by: bcftools roh(%s+htslib-%s)\n", bcftools_version(),hts_version()); - printf("# The command line was:\tbcftools %s", args->argv[0]); + args->str.l = 0; + ksprintf(&args->str, "# This file was produced by: bcftools roh(%s+htslib-%s)\n", bcftools_version(),hts_version()); + ksprintf(&args->str, "# The command line was:\tbcftools %s", args->argv[0]); for (i=1; iargc; i++) - printf(" %s",args->argv[i]); - printf("\n#\n"); - printf("# [1]Chromosome\t[2]Position\t[3]State (0:HW, 1:AZ)\t[4]Quality\n"); + ksprintf(&args->str, " %s",args->argv[i]); + ksprintf(&args->str, "\n#\n"); + if ( args->output_type & OUTPUT_RG ) + { + i = 2; + ksprintf(&args->str, "# RG"); + ksprintf(&args->str, "\t[%d]Sample", i++); + ksprintf(&args->str, "\t[%d]Chromosome", i++); + ksprintf(&args->str, "\t[%d]Start", i++); + ksprintf(&args->str, "\t[%d]End", i++); + ksprintf(&args->str, "\t[%d]Length (bp)", i++); + ksprintf(&args->str, "\t[%d]Number of markers", i++); + ksprintf(&args->str, "\t[%d]Quality (average fwd-bwd phred score)", i++); + ksprintf(&args->str, "\n"); + } + if ( args->output_type & OUTPUT_ST ) + { + i = 2; + ksprintf(&args->str, "# ST"); + ksprintf(&args->str, "\t[%d]Sample", i++); + ksprintf(&args->str, "\t[%d]Chromosome", i++); + ksprintf(&args->str, "\t[%d]Position", i++); + ksprintf(&args->str, "\t[%d]State (0:HW, 1:AZ)", i++); + ksprintf(&args->str, "\t[%d]Quality (fwd-bwd phred score)", i++); + ksprintf(&args->str, "\n"); + } + if ( args->vi_training) + { + i = 2; + ksprintf(&args->str, "# VT, Viterbi Training"); + ksprintf(&args->str, "\t[%d]Sample", i++); + ksprintf(&args->str, "\t[%d]Iteration", i++); + ksprintf(&args->str, "\t[%d]dAZ", i++); + ksprintf(&args->str, "\t[%d]dHW", i++); + ksprintf(&args->str, "\t[%d]1 - P(HW|HW)", i++); + ksprintf(&args->str, "\t[%d]P(AZ|HW)", i++); + ksprintf(&args->str, "\t[%d]1 - P(AZ|AZ)", i++); + ksprintf(&args->str, "\t[%d]P(HW|AZ)", i++); + ksprintf(&args->str, "\n"); + } + if ( bgzf_write(args->out, args->str.s, args->str.l) != args->str.l ) + error("Error writing %s: %s\n", args->output_fname, strerror(errno)); } static void destroy_data(args_t *args) { - free(args->sites); - free(args->eprob); - free(args->sample); + if ( bgzf_close(args->out)!=0 ) error("Error: close failed .. %s\n", args->output_fname); + int i; + for (i=0; iroh_smpl->n; i++) + { + free(args->smpl[i].eprob); + free(args->smpl[i].sites); + free(args->smpl[i].rid); + free(args->smpl[i].rid_off); + free(args->smpl[i].snapshot); + } + free(args->str.s); + free(args->smpl); + if ( args->af_smpl ) smpl_ilist_destroy(args->af_smpl); + smpl_ilist_destroy(args->roh_smpl); free(args->rids); free(args->rid_offs); hmm_destroy(args->hmm); bcf_sr_destroy(args->files); - free(args->itmp); free(args->AFs); free(args->pdg); + free(args->AFs); free(args->pdg); free(args->genmap); + free(args->itmp); + free(args->samples); } -static int load_genmap(args_t *args, bcf1_t *line) +static int load_genmap(args_t *args, const char *chr) { if ( !args->genmap_fname ) { args->ngenmap = 0; return 0; } @@ -195,7 +351,7 @@ static int load_genmap(args_t *args, bcf1_t *line) if ( fname ) { kputsn(args->genmap_fname, fname - args->genmap_fname, &str); - kputs(bcf_seqname(args->hdr,line), &str); + kputs(chr, &str); kputs(fname+7,&str); fname = str.s; } @@ -220,21 +376,22 @@ static int load_genmap(args_t *args, bcf1_t *line) hts_expand(genmap_t,args->ngenmap,args->mgenmap,args->genmap); genmap_t *gm = &args->genmap[args->ngenmap-1]; + // position, convert to 0-based char *tmp, *end; gm->pos = strtol(str.s, &tmp, 10); if ( str.s==tmp ) error("Could not parse %s: %s\n", fname, str.s); + gm->pos -= 1; // skip second column tmp++; while ( *tmp && !isspace(*tmp) ) tmp++; - // read the genetic map in cM + // read the genetic map in cM, scale from % to likelihood gm->rate = strtod(tmp+1, &end); if ( tmp+1==end ) error("Could not parse %s: %s\n", fname, str.s); + gm->rate *= 0.01; } if ( !args->ngenmap ) error("Genetic map empty?\n"); - int i; - for (i=0; ingenmap; i++) args->genmap[i].rate /= args->genmap[args->ngenmap-1].rate; // scale to 1 if ( hts_close(fp) ) error("Close failed\n"); free(str.s); return 0; @@ -255,7 +412,6 @@ static double get_genmap_rate(args_t *args, int start, int end) // position j to be equal or larger than end int j = i; while ( j+1ngenmap && args->genmap[j].pos < end ) j++; - if ( i==j ) { args->igenmap = i; @@ -272,17 +428,20 @@ static double get_genmap_rate(args_t *args, int start, int end) void set_tprob_genmap(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, double *tprob) { args_t *args = (args_t*) data; - double ci = get_genmap_rate(args, pos - prev_pos, pos); + double ci = get_genmap_rate(args, prev_pos, pos); + if ( args->rec_rate ) ci *= args->rec_rate; + if ( ci > 1 ) ci = 1; MAT(tprob,2,STATE_HW,STATE_AZ) *= ci; MAT(tprob,2,STATE_AZ,STATE_HW) *= ci; MAT(tprob,2,STATE_AZ,STATE_AZ) = 1 - MAT(tprob,2,STATE_HW,STATE_AZ); MAT(tprob,2,STATE_HW,STATE_HW) = 1 - MAT(tprob,2,STATE_AZ,STATE_HW); } -void set_tprob_recrate(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, double *tprob) +void set_tprob_rrate(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, double *tprob) { args_t *args = (args_t*) data; double ci = (pos - prev_pos) * args->rec_rate; + if ( ci > 1 ) ci = 1; MAT(tprob,2,STATE_HW,STATE_AZ) *= ci; MAT(tprob,2,STATE_AZ,STATE_HW) *= ci; MAT(tprob,2,STATE_AZ,STATE_AZ) = 1 - MAT(tprob,2,STATE_HW,STATE_AZ); @@ -315,133 +474,165 @@ void set_tprob_recrate(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, * */ -static void flush_viterbi(args_t *args) +static void flush_viterbi(args_t *args, int ismpl) { - int i,j; + smpl_t *smpl = &args->smpl[ismpl]; + if ( !smpl->nsites ) return; + + const char *name = args->hdr->samples[ args->roh_smpl->idx[ismpl] ]; - if ( !args->nsites ) return; + int i,j,k; - if ( !args->vi_training ) + if ( !args->vi_training ) // single viterbi pass { - // single viterbi pass, one chromsome - hmm_run_viterbi(args->hmm, args->nsites, args->eprob, args->sites); - hmm_run_fwd_bwd(args->hmm, args->nsites, args->eprob, args->sites); + hmm_restore(args->hmm, smpl->snapshot); + int end = (args->nbuf_max && smpl->nsites >= args->nbuf_max && smpl->nsites > args->nbuf_olap) ? smpl->nsites - args->nbuf_olap : smpl->nsites; + if ( end < smpl->nsites ) + smpl->snapshot = hmm_snapshot(args->hmm, smpl->snapshot, smpl->sites[smpl->nsites - args->nbuf_olap - 1]); + + args->igenmap = smpl->igenmap; + hmm_run_viterbi(args->hmm, smpl->nsites, smpl->eprob, smpl->sites); + hmm_run_fwd_bwd(args->hmm, smpl->nsites, smpl->eprob, smpl->sites); double *fwd = hmm_get_fwd_bwd_prob(args->hmm); - const char *chr = bcf_hdr_id2name(args->hdr,args->prev_rid); - uint8_t *vpath = hmm_get_viterbi_path(args->hmm); - for (i=0; insites; i++) + const char *chr = bcf_hdr_id2name(args->hdr,args->prev_rid); + uint8_t *vpath = hmm_get_viterbi_path(args->hmm); + + for (i=0; isites[i]+1, state, phred_score(1.0-pval[state])); - } - return; - } + double qual = phred_score(1.0 - fwd[i*2 + state]); + if ( args->output_type & OUTPUT_ST ) + { + args->str.l = 0; + ksprintf(&args->str, "ST\t%s\t%s\t%d\t%d\t%.1f\n", name,chr,smpl->sites[i]+1, state, qual); + if ( bgzf_write(args->out, args->str.s, args->str.l) != args->str.l ) error("Error writing %s: %s\n", args->output_fname, strerror(errno)); + } - // viterbi training, multiple chromosomes - double t2az_prev, t2hw_prev; - double deltaz, delthw; - int niter = 0; - do - { - double *tprob_arr = hmm_get_tprob(args->hmm); - t2az_prev = MAT(tprob_arr,2,1,0); //args->t2AZ; - t2hw_prev = MAT(tprob_arr,2,0,1); //args->t2HW; - double tcounts[] = { 0,0,0,0 }; - for (i=0; inrids; i++) - { - // run viterbi for each chromosomes. eprob and sites contain - // multiple chromosomes, rid_offs mark the boundaries - int ioff = args->rid_offs[i]; - int nsites = (i+1==args->nrids ? args->nsites : args->rid_offs[i+1]) - ioff; - hmm_run_viterbi(args->hmm, nsites, args->eprob+ioff*2, args->sites+ioff); - - // what transitions were observed: add to the total counts - uint8_t *vpath = hmm_get_viterbi_path(args->hmm); - for (j=1; joutput_type & OUTPUT_RG ) { - // count the number of transitions - int prev_state = vpath[2*(j-1)]; - int curr_state = vpath[2*j]; - MAT(tcounts,2,curr_state,prev_state) += 1; + if ( state!=smpl->rg.state ) + { + if ( !state ) // the region ends, flush + { + args->str.l = 0; + ksprintf(&args->str, "RG\t%s\t%s\t%d\t%d\t%d\t%d\t%.1f\n",name,bcf_hdr_id2name(args->hdr,smpl->rg.rid), + smpl->rg.beg+1,smpl->rg.end+1,smpl->rg.end-smpl->rg.beg+1,smpl->rg.nqual,smpl->rg.qual/smpl->rg.nqual); + if ( bgzf_write(args->out, args->str.s, args->str.l) != args->str.l ) error("Error writing %s: %s\n", args->output_fname, strerror(errno)); + smpl->rg.state = 0; + } + else + { + smpl->rg.state = 1; + smpl->rg.beg = smpl->sites[i]; + smpl->rg.rid = args->prev_rid; + smpl->rg.qual = qual; + smpl->rg.nqual = 1; + } + } + else if ( state ) + { + smpl->rg.nqual++; + smpl->rg.qual += qual; + smpl->rg.end = smpl->sites[i]; + } } } - // update the transition matrix - int n = 1; - for (i=0; i<2; i++) + if ( end < smpl->nsites ) { - for (j=0; j<2; j++) n += MAT(tcounts,2,i,j); + end = smpl->nsites - args->nbuf_olap; + memmove(smpl->sites, smpl->sites + end, sizeof(*smpl->sites)*args->nbuf_olap); + memmove(smpl->eprob, smpl->eprob + end*2, sizeof(*smpl->eprob)*args->nbuf_olap*2); + smpl->nsites = args->nbuf_olap; + smpl->igenmap = args->igenmap; } - for (i=0; i<2; i++) + else { - for (j=0; j<2; j++) + smpl->nsites = 0; + smpl->igenmap = 0; + + if ( smpl->rg.state ) { - // no transition to i-th state was observed, set to a small number - if ( !MAT(tcounts,2,i,j) ) MAT(tcounts,2,i,j) = 0.1/n; - else MAT(tcounts,2,i,j) /= n; + args->str.l = 0; + ksprintf(&args->str, "RG\t%s\t%s\t%d\t%d\t%d\t%d\t%.1f\n",name,bcf_hdr_id2name(args->hdr,smpl->rg.rid), + smpl->rg.beg+1,smpl->rg.end+1,smpl->rg.end-smpl->rg.beg+1,smpl->rg.nqual,smpl->rg.qual/smpl->rg.nqual); + if ( bgzf_write(args->out, args->str.s, args->str.l) != args->str.l ) error("Error writing %s: %s\n", args->output_fname, strerror(errno)); + smpl->rg.state = 0; } } - // normalize - for (i=0; i<2; i++) + return; + } + + + // viterbi training, multiple chromosomes + double t2az_prev, t2hw_prev; + double deltaz, delthw; + + double *tprob_arr = hmm_get_tprob(args->hmm); + MAT(tprob_arr,2,STATE_HW,STATE_HW) = 1 - args->t2AZ; + MAT(tprob_arr,2,STATE_HW,STATE_AZ) = args->t2HW; + MAT(tprob_arr,2,STATE_AZ,STATE_HW) = args->t2AZ; + MAT(tprob_arr,2,STATE_AZ,STATE_AZ) = 1 - args->t2HW; + hmm_set_tprob(args->hmm, tprob_arr, 10000); + + int niter = 0; + do + { + tprob_arr = hmm_get_tprob(args->hmm); + t2az_prev = MAT(tprob_arr,2,STATE_AZ,STATE_HW); //args->t2AZ; + t2hw_prev = MAT(tprob_arr,2,STATE_HW,STATE_AZ); //args->t2HW; + double tprob_new[] = { 0,0,0,0 }; + for (i=0; inrid; i++) { - double norm = 0; - for (j=0; j<2; j++) norm += MAT(tcounts,2,j,i); - assert( norm!=0 ); - for (j=0; j<2; j++) MAT(tcounts,2,j,i) /= norm; + int ioff = smpl->rid_off[i]; + int nsites = (i+1==smpl->nrid ? smpl->nsites : smpl->rid_off[i+1]) - ioff; + args->igenmap = 0; + tprob_arr = hmm_run_baum_welch(args->hmm, nsites, smpl->eprob+ioff*2, smpl->sites+ioff); + for (j=0; j<2; j++) + for (k=0; k<2; k++) MAT(tprob_new,2,j,k) += MAT(tprob_arr,2,j,k); } + for (j=0; j<2; j++) + for (k=0; k<2; k++) MAT(tprob_new,2,j,k) /= smpl->nrid; - if ( args->genmap_fname || args->rec_rate > 0 ) - hmm_set_tprob(args->hmm, tcounts, 0); - else - hmm_set_tprob(args->hmm, tcounts, 10000); + hmm_set_tprob(args->hmm, tprob_new, 10000); - tprob_arr = hmm_get_tprob(args->hmm); - deltaz = fabs(MAT(tprob_arr,2,1,0)-t2az_prev); - delthw = fabs(MAT(tprob_arr,2,0,1)-t2hw_prev); + deltaz = fabs(MAT(tprob_new,2,STATE_AZ,STATE_HW)-t2az_prev); + delthw = fabs(MAT(tprob_new,2,STATE_HW,STATE_AZ)-t2hw_prev); niter++; - fprintf(stderr,"Viterbi training, iteration %d: dAZ=%e dHW=%e\tP(HW|HW)=%e P(AZ|HW)=%e P(AZ|AZ)=%e P(HW|AZ)=%e\n", - niter,deltaz,delthw, - MAT(tprob_arr,2,STATE_HW,STATE_HW),MAT(tprob_arr,2,STATE_AZ,STATE_HW), - MAT(tprob_arr,2,STATE_AZ,STATE_AZ),MAT(tprob_arr,2,STATE_HW,STATE_AZ)); + args->str.l = 0; + ksprintf(&args->str, "VT\t%s\t%d\t%e\t%e\t%e\t%e\t%e\t%e\n", + name,niter,deltaz,delthw, + 1-MAT(tprob_new,2,STATE_HW,STATE_HW),MAT(tprob_new,2,STATE_AZ,STATE_HW), + 1-MAT(tprob_new,2,STATE_AZ,STATE_AZ),MAT(tprob_new,2,STATE_HW,STATE_AZ)); + if ( bgzf_write(args->out, args->str.s, args->str.l) != args->str.l ) error("Error writing %s: %s\n", args->output_fname, strerror(errno)); } - while ( deltaz > 0.0 || delthw > 0.0 ); - double *tprob_arr = hmm_get_tprob(args->hmm); - fprintf(stderr, "Viterbi training converged in %d iterations to P(HW|HW)=%e P(AZ|HW)=%e P(AZ|AZ)=%e P(HW|AZ)=%e\n", niter, - MAT(tprob_arr,2,STATE_HW,STATE_HW),MAT(tprob_arr,2,STATE_AZ,STATE_HW), - MAT(tprob_arr,2,STATE_AZ,STATE_AZ),MAT(tprob_arr,2,STATE_HW,STATE_AZ)); + while ( deltaz > args->baum_welch_th || delthw > args->baum_welch_th ); // output the results - for (i=0; inrids; i++) + for (i=0; inrid; i++) { - int ioff = args->rid_offs[i]; - int nsites = (i+1==args->nrids ? args->nsites : args->rid_offs[i+1]) - ioff; - hmm_run_viterbi(args->hmm, nsites, args->eprob+ioff*2, args->sites+ioff); - hmm_run_fwd_bwd(args->hmm, nsites, args->eprob+ioff*2, args->sites+ioff); + int ioff = smpl->rid_off[i]; + int nsites = (i+1==smpl->nrid ? smpl->nsites : smpl->rid_off[i+1]) - ioff; + args->igenmap = 0; + hmm_run_viterbi(args->hmm, nsites, smpl->eprob+ioff*2, smpl->sites+ioff); + hmm_run_fwd_bwd(args->hmm, nsites, smpl->eprob+ioff*2, smpl->sites+ioff); uint8_t *vpath = hmm_get_viterbi_path(args->hmm); double *fwd = hmm_get_fwd_bwd_prob(args->hmm); - const char *chr = bcf_hdr_id2name(args->hdr,args->rids[i]); + const char *chr = bcf_hdr_id2name(args->hdr,smpl->rid[i]); for (j=0; jsites[ioff+j]+1,state==STATE_AZ ? 1 : 0, pval); + int state = vpath[j*2]==STATE_AZ ? 1 : 0; + double *pval = fwd + j*2; + args->str.l = 0; + ksprintf(&args->str, "ROH\t%s\t%s\t%d\t%d\t%.1f\n", name,chr,smpl->sites[ioff+j]+1, state, phred_score(1.0-pval[state])); + if ( bgzf_write(args->out, args->str.s, args->str.l) != args->str.l ) error("Error writing %s: %s\n", args->output_fname, strerror(errno)); } } } -static void push_rid(args_t *args, int rid) -{ - args->nrids++; - args->rids = (int*) realloc(args->rids, args->nrids*sizeof(int)); - args->rid_offs = (int*) realloc(args->rid_offs, args->nrids*sizeof(int)); - args->rids[ args->nrids-1 ] = rid; - args->rid_offs[ args->nrids-1 ] = args->nsites; -} - int read_AF(bcf_sr_regions_t *tgt, bcf1_t *line, double *alt_freq) { if ( tgt->nals != line->n_allele ) return -1; // number of alleles does not match @@ -468,27 +659,52 @@ int read_AF(bcf_sr_regions_t *tgt, bcf1_t *line, double *alt_freq) return 0; } -int estimate_AF(args_t *args, bcf1_t *line, double *alt_freq) +int8_t *get_GT(args_t *args, bcf1_t *line) { - if ( !args->nitmp ) - { - args->nitmp = bcf_get_genotypes(args->hdr, line, &args->itmp, &args->mitmp); - if ( args->nitmp != 2*args->nsmpl ) return -1; // not diploid? - args->nitmp /= args->nsmpl; - } + int i; + for (i=0; in_fmt; i++) + if ( line->d.fmt[i].id==args->gt_hdr_id ) break; + if ( i==line->n_fmt ) return NULL; // the tag is not present in this record + + bcf_fmt_t *fmt = &line->d.fmt[i]; + if ( fmt->n!=2 ) return NULL; // not diploid + if ( fmt->type!=BCF_BT_INT8 ) error("This is unexpected, GT type is %d\n", fmt->type); + return (int8_t*) fmt->p; +} + +int estimate_AF_from_GT(args_t *args, int8_t *gt, double *alt_freq) +{ int i, nalt = 0, nref = 0; - for (i=0; insmpl; i++) + if ( args->af_smpl ) // subset samples for AF estimate { - int32_t *gt = &args->itmp[i*args->nitmp]; + for (i=0; iaf_smpl->n; i++) + { + int ismpl = args->af_smpl->idx[i]; + if ( bcf_gt_is_missing(gt[2*ismpl]) || bcf_gt_is_missing(gt[2*ismpl+1]) ) continue; - if ( bcf_gt_is_missing(gt[0]) || bcf_gt_is_missing(gt[1]) ) continue; + if ( bcf_gt_allele(gt[2*ismpl]) ) nalt++; + else nref++; - if ( bcf_gt_allele(gt[0]) ) nalt++; - else nref++; + if ( bcf_gt_allele(gt[2*ismpl+1]) ) nalt++; + else nref++; + } + } + else // all samples used in AF estimate + { + int8_t *end = gt + 2*bcf_hdr_nsamples(args->hdr); + while ( gt < end ) + { + if ( bcf_gt_is_missing(gt[0]) || bcf_gt_is_missing(gt[1]) ) continue; - if ( bcf_gt_allele(gt[1]) ) nalt++; - else nref++; + if ( bcf_gt_allele(gt[0]) ) nalt++; + else nref++; + + if ( bcf_gt_allele(gt[1]) ) nalt++; + else nref++; + + gt += 2; + } } if ( !nalt && !nref ) return -1; @@ -496,105 +712,249 @@ int estimate_AF(args_t *args, bcf1_t *line, double *alt_freq) return 0; } +int estimate_AF_from_PL(args_t *args, bcf_fmt_t *fmt_pl, int ial, double *alt_freq) +{ + double af = 0; + int i, j, naf = 0; + + int irr = bcf_alleles2gt(0,0), ira = bcf_alleles2gt(0,ial), iaa = bcf_alleles2gt(ial,ial); + if ( iaa >= fmt_pl->n ) return -1; // not diploid or wrong number of fields + + if ( args->af_smpl ) // subset samples for AF estimate + { + #define BRANCH(type_t) \ + { \ + for (i=0; iaf_smpl->n; i++) \ + { \ + int ismpl = args->af_smpl->idx[i]; \ + type_t *p = (type_t*)fmt_pl->p + fmt_pl->n*ismpl; \ + if ( p[irr]<0 || p[ira]<0 || p[iaa]<0 ) continue; /* missing value */ \ + if ( p[irr]==p[ira] && p[irr]==p[iaa] ) continue; /* all values are the same */ \ + double prob[3], norm = 0; \ + prob[0] = p[irr] < (type_t)256 ? args->pl2p[ p[irr] ] : args->pl2p[255]; \ + prob[1] = p[ira] < (type_t)256 ? args->pl2p[ p[ira] ] : args->pl2p[255]; \ + prob[2] = p[iaa] < (type_t)256 ? args->pl2p[ p[iaa] ] : args->pl2p[255]; \ + for (j=0; j<3; j++) norm += prob[j]; \ + for (j=0; j<3; j++) prob[j] /= norm; \ + af += 0.5*prob[1] + prob[2]; \ + naf++; \ + } \ + } + switch (fmt_pl->type) { + case BCF_BT_INT8: BRANCH(int8_t); break; + case BCF_BT_INT16: BRANCH(int16_t); break; + case BCF_BT_INT32: BRANCH(int32_t); break; + default: fprintf(stderr,"Unknown format type for PL: %s:%d .. fmt->type=%d\n", __FILE__,__LINE__, fmt_pl->type); exit(1); + } + #undef BRANCH + } + else // all samples used in AF estimate + { + int nsmpl = bcf_hdr_nsamples(args->hdr); + #define BRANCH(type_t) \ + { \ + type_t *p = (type_t*)fmt_pl->p; \ + p -= fmt_pl->n; \ + for (i=0; in; \ + if ( p[irr]<0 || p[ira]<0 || p[iaa]<0 ) continue; /* missing value */ \ + if ( p[irr]==p[ira] && p[irr]==p[iaa] ) continue; /* all values are the same */ \ + double prob[3], norm = 0; \ + prob[0] = p[irr] < (type_t)256 ? args->pl2p[ p[irr] ] : args->pl2p[255]; \ + prob[1] = p[ira] < (type_t)256 ? args->pl2p[ p[ira] ] : args->pl2p[255]; \ + prob[2] = p[iaa] < (type_t)256 ? args->pl2p[ p[iaa] ] : args->pl2p[255]; \ + for (j=0; j<3; j++) norm += prob[j]; \ + for (j=0; j<3; j++) prob[j] /= norm; \ + af += 0.5*prob[1] + prob[2]; \ + naf++; \ + } \ + } + switch (fmt_pl->type) { + case BCF_BT_INT8: BRANCH(int8_t); break; + case BCF_BT_INT16: BRANCH(int16_t); break; + case BCF_BT_INT32: BRANCH(int32_t); break; + default: fprintf(stderr,"Unknown format type for PL: %s:%d .. fmt->type=%d\n", __FILE__,__LINE__, fmt_pl->type); exit(1); + } + #undef BRANCH + } + if ( !naf ) return -1; + + *alt_freq = af / naf; + return 0; +} + +bcf_fmt_t *get_PL(args_t *args, bcf1_t *line) +{ + int i; + for (i=0; in_fmt; i++) + if ( line->d.fmt[i].id==args->pl_hdr_id ) return &line->d.fmt[i]; + return NULL; +} -int parse_line(args_t *args, bcf1_t *line, double *alt_freq, double *pdg) +int process_line(args_t *args, bcf1_t *line, int ial) { - args->nitmp = 0; + if ( !(line->unpacked & BCF_UN_FMT) ) bcf_unpack(line, BCF_UN_FMT); + + double alt_freq; + int8_t *GTs = NULL; + bcf_fmt_t *fmt_pl = NULL; // Set allele frequency - int ret; + int ret = 0, i,j; if ( args->af_tag ) { // Use an INFO tag provided by the user ret = bcf_get_info_float(args->hdr, line, args->af_tag, &args->AFs, &args->mAFs); - if ( ret==1 ) - *alt_freq = args->AFs[0]; + if ( ret>0 ) + alt_freq = args->AFs[ial-1]; if ( ret==-2 ) error("Type mismatch for INFO/%s tag at %s:%d\n", args->af_tag, bcf_seqname(args->hdr,line), line->pos+1); } else if ( args->af_fname ) { // Read AF from a file - ret = read_AF(args->files->targets, line, alt_freq); + ret = read_AF(args->files->targets, line, &alt_freq); + } + else if ( args->dflt_AF > 0 ) + { + alt_freq = args->dflt_AF; + } + else if ( args->estimate_AF ) + { + // Estimate AF from GTs or PLs of all samples or samples listed in a file + if ( args->af_from_PL ) + { + fmt_pl = get_PL(args, line); + if ( !fmt_pl ) return -1; + ret = estimate_AF_from_PL(args, fmt_pl, ial, &alt_freq); + } + else + { + GTs = get_GT(args, line); + if ( !GTs ) return -1; + ret = estimate_AF_from_GT(args, GTs, &alt_freq); + } } else { - // Use GTs or AC/AN: GTs when AC/AN not present or when GTs explicitly requested by --estimate-AF - ret = -1; - if ( !args->estimate_AF ) + // Use AC/AN + int AC = -1, AN = 0; + ret = bcf_get_info_int32(args->hdr, line, "AN", &args->itmp, &args->mitmp); + if ( ret==1 ) { - int AC = -1, AN = 0; - ret = bcf_get_info_int32(args->hdr, line, "AN", &args->itmp, &args->mitmp); - if ( ret==1 ) - { - AN = args->itmp[0]; - ret = bcf_get_info_int32(args->hdr, line, "AC", &args->itmp, &args->mitmp); - if ( ret>0 ) - AC = args->itmp[0]; - } - if ( AN<=0 || AC<0 ) - ret = -1; - else - *alt_freq = (double) AC/AN; + AN = args->itmp[0]; + ret = bcf_get_info_int32(args->hdr, line, "AC", &args->itmp, &args->mitmp); + if ( ret>0 ) + AC = args->itmp[0]; } - if ( ret==-1 ) - ret = estimate_AF(args, line, alt_freq); // reads GTs into args->itmp + if ( AN<=0 || AC<0 ) + ret = -1; + else + alt_freq = (double) AC/AN; } if ( ret<0 ) return ret; - if ( *alt_freq==0.0 ) - { - if ( args->dflt_AF==0 ) return -1; // we skip sites with AF=0 - *alt_freq = args->dflt_AF; - } + if ( alt_freq==0.0 ) return -1; - // Set P(D|G) + int irr = bcf_alleles2gt(0,0), ira = bcf_alleles2gt(0,ial), iaa = bcf_alleles2gt(ial,ial); if ( args->fake_PLs ) { - if ( !args->nitmp ) - { - args->nitmp = bcf_get_genotypes(args->hdr, line, &args->itmp, &args->mitmp); - if ( args->nitmp != 2*args->nsmpl ) return -1; // not diploid? - args->nitmp /= args->nsmpl; - } + if ( !GTs ) GTs = get_GT(args, line); + } + else + { + fmt_pl = get_PL(args, line); + if ( !fmt_pl ) return -1; + if ( iaa >= fmt_pl->n ) return -1; // not diploid or wrong number of fields + } - int32_t *gt = &args->itmp[args->ismpl*args->nitmp]; - if ( bcf_gt_is_missing(gt[0]) || bcf_gt_is_missing(gt[1]) ) return -1; + for (i=0; iroh_smpl->n; i++) + { + int ismpl = args->roh_smpl->idx[i]; - int a = bcf_gt_allele(gt[0]); - int b = bcf_gt_allele(gt[1]); - if ( a!=b ) - { - pdg[0] = pdg[2] = args->unseen_PL; - pdg[1] = 1 - 2*args->unseen_PL; - } - else if ( a==0 ) + // set P(D|G) + double pdg[3]; + if ( args->fake_PLs ) { - pdg[0] = 1 - 2*args->unseen_PL; - pdg[1] = pdg[2] = args->unseen_PL; + int8_t *gt = GTs + 2*ismpl; + if ( bcf_gt_is_missing(gt[0]) || bcf_gt_is_missing(gt[1]) ) continue; + + int a = bcf_gt_allele(gt[0]); + int b = bcf_gt_allele(gt[1]); + if ( a!=b ) + { + pdg[0] = pdg[2] = args->unseen_PL; + pdg[1] = 1 - 2*args->unseen_PL; + } + else if ( a==0 ) + { + pdg[0] = 1 - args->unseen_PL - args->unseen_PL*args->unseen_PL; + pdg[1] = args->unseen_PL; + pdg[2] = args->unseen_PL*args->unseen_PL; + } + else + { + pdg[0] = args->unseen_PL*args->unseen_PL; + pdg[1] = args->unseen_PL; + pdg[2] = 1 - args->unseen_PL - args->unseen_PL*args->unseen_PL; + } } else { - pdg[0] = pdg[1] = args->unseen_PL; - pdg[2] = 1 - 2*args->unseen_PL; + #define BRANCH(type_t) \ + { \ + type_t *p = (type_t*)fmt_pl->p + fmt_pl->n*ismpl; \ + if ( p[irr]<0 || p[ira]<0 || p[iaa]<0 ) continue; /* missing value */ \ + if ( p[irr]==p[ira] && p[irr]==p[iaa] ) continue; /* all values are the same */ \ + pdg[0] = p[irr] < (type_t)256 ? args->pl2p[ p[irr] ] : args->pl2p[255]; \ + pdg[1] = p[ira] < (type_t)256 ? args->pl2p[ p[ira] ] : args->pl2p[255]; \ + pdg[2] = p[iaa] < (type_t)256 ? args->pl2p[ p[iaa] ] : args->pl2p[255]; \ + } + switch (fmt_pl->type) { + case BCF_BT_INT8: BRANCH(int8_t); break; + case BCF_BT_INT16: BRANCH(int16_t); break; + case BCF_BT_INT32: BRANCH(int32_t); break; + default: fprintf(stderr,"Unknown format type for PL: %s:%d .. fmt->type=%d\n", __FILE__,__LINE__, fmt_pl->type); exit(1); + } + #undef BRANCH } - } - else - { - args->nitmp = bcf_get_format_int32(args->hdr, line, "PL", &args->itmp, &args->mitmp); - if ( args->nitmp != args->nsmpl*line->n_allele*(line->n_allele+1)/2. ) return -1; // not diploid? - args->nitmp /= args->nsmpl; - - int32_t *pl = &args->itmp[args->ismpl*args->nitmp]; - pdg[0] = pl[0] < 256 ? args->pl2p[ pl[0] ] : 1.0; - pdg[1] = pl[1] < 256 ? args->pl2p[ pl[1] ] : 1.0; - pdg[2] = pl[2] < 256 ? args->pl2p[ pl[2] ] : 1.0; double sum = pdg[0] + pdg[1] + pdg[2]; - if ( !sum ) return -1; - pdg[0] /= sum; - pdg[1] /= sum; - pdg[2] /= sum; + if ( !sum ) continue; + for (j=0; j<3; j++) pdg[j] /= sum; + if ( args->skip_homref && pdg[0]>0.99 ) continue; + + smpl_t *smpl = &args->smpl[i]; + smpl->nused++; + + if ( smpl->nsites >= smpl->msites ) + { + hts_expand(uint32_t,smpl->nsites+1,smpl->msites,smpl->sites); + smpl->eprob = (double*) realloc(smpl->eprob,sizeof(*smpl->eprob)*smpl->msites*2); + if ( !smpl->eprob ) error("Error: failed to alloc %d bytes\n", sizeof(*smpl->eprob)*smpl->msites*2); + } + + // Calculate emission probabilities P(D|AZ) and P(D|HW) + double *eprob = &smpl->eprob[2*smpl->nsites]; + eprob[STATE_AZ] = pdg[0]*(1-alt_freq) + pdg[2]*alt_freq; + eprob[STATE_HW] = pdg[0]*(1-alt_freq)*(1-alt_freq) + 2*pdg[1]*(1-alt_freq)*alt_freq + pdg[2]*alt_freq*alt_freq; + + smpl->sites[smpl->nsites] = line->pos; + smpl->nsites++; + + if ( args->vi_training ) + { + if ( !smpl->nrid || line->rid!=smpl->rid[smpl->nrid-1] ) + { + smpl->nrid++; + smpl->rid = (int*) realloc(smpl->rid,sizeof(*smpl->rid)*smpl->nrid); + smpl->rid[smpl->nrid-1] = line->rid; + smpl->rid_off = (int*) realloc(smpl->rid_off,sizeof(*smpl->rid_off)*smpl->nrid); + smpl->rid_off[smpl->nrid-1] = smpl->nsites - 1; + } + } + else if ( args->nbuf_max && smpl->nsites >= args->nbuf_max ) flush_viterbi(args, i); } return 0; @@ -602,18 +962,35 @@ int parse_line(args_t *args, bcf1_t *line, double *alt_freq, double *pdg) static void vcfroh(args_t *args, bcf1_t *line) { + int i; + // Are we done? if ( !line ) { - flush_viterbi(args); + for (i=0; iroh_smpl->n; i++) flush_viterbi(args, i); return; } args->ntot++; - // Skip unwanted lines + // Skip unwanted lines, for simplicity we consider only biallelic sites if ( line->rid == args->skip_rid ) return; if ( line->n_allele==1 ) return; // no ALT allele - if ( line->n_allele!=2 ) return; // only biallelic sites + if ( line->n_allele > 3 ) return; // cannot be bi-allelic, even with <*> + + // This can be raw callable VCF with the symbolic unseen allele <*> + int ial = 0; + for (i=1; in_allele; i++) + if ( !strcmp("<*>",line->d.allele[i]) ) { ial = i; break; } + if ( ial==0 ) // normal VCF, the symbolic allele is not present + { + if ( line->n_allele!=2 ) return; // not biallelic + ial = 1; + } + else + { + if ( line->n_allele!=3 ) return; // not biallelic + ial = ial==1 ? 2 : 1; // <*> can come in any order + } if ( args->snps_only && !bcf_is_snp(line) ) return; // Initialize genetic map @@ -622,26 +999,25 @@ static void vcfroh(args_t *args, bcf1_t *line) { args->prev_rid = line->rid; args->prev_pos = line->pos; - skip_rid = load_genmap(args, line); - if ( !skip_rid && args->vi_training ) push_rid(args, line->rid); + skip_rid = load_genmap(args, bcf_seqname(args->hdr,line)); } // New chromosome? if ( args->prev_rid!=line->rid ) { - skip_rid = load_genmap(args, line); - if ( args->vi_training ) - { - if ( !skip_rid ) push_rid(args, line->rid); - } - else + if ( !args->vi_training ) { - flush_viterbi(args); - args->nsites = 0; + for (i=0; iroh_smpl->n; i++) + { + flush_viterbi(args, i); + hmm_reset(args->hmm, args->smpl[i].snapshot); + } } args->prev_rid = line->rid; args->prev_pos = line->pos; + skip_rid = load_genmap(args, bcf_seqname(args->hdr,line)); } + else if ( args->prev_pos == line->pos ) return; // skip duplicate positions if ( skip_rid ) { @@ -655,25 +1031,8 @@ static void vcfroh(args_t *args, bcf1_t *line) args->prev_pos = line->pos; - // Ready for the new site - int m = args->msites; - hts_expand(uint32_t,args->nsites+1,args->msites,args->sites); - if ( args->msites!=m ) - args->eprob = (double*) realloc(args->eprob,sizeof(double)*args->msites*2); - - // Set likelihoods and alternate allele frequencies - double alt_freq, pdg[3]; - if ( parse_line(args, line, &alt_freq, pdg)<0 ) return; // something went wrong - - args->nused++; - - // Calculate emission probabilities P(D|AZ) and P(D|HW) - double *eprob = &args->eprob[2*args->nsites]; - eprob[STATE_AZ] = pdg[0]*(1-alt_freq) + pdg[2]*alt_freq; - eprob[STATE_HW] = pdg[0]*(1-alt_freq)*(1-alt_freq) + 2*pdg[1]*(1-alt_freq)*alt_freq + pdg[2]*alt_freq*alt_freq; - - args->sites[args->nsites] = line->pos; - args->nsites++; + // parse the new line + process_line(args, line, ial); } static void usage(args_t *args) @@ -686,21 +1045,32 @@ static void usage(args_t *args) fprintf(stderr, " --AF-dflt if AF is not known, use this allele frequency [skip]\n"); fprintf(stderr, " --AF-tag use TAG for allele frequency\n"); fprintf(stderr, " --AF-file read allele frequencies from file (CHR\\tPOS\\tREF,ALT\\tAF)\n"); - fprintf(stderr, " -e, --estimate-AF calculate AC,AN counts on the fly, using either all samples (\"-\") or samples listed in \n"); - fprintf(stderr, " -G, --GTs-only use GTs, ignore PLs, use for PL of unseen genotypes. Safe value to use is 30 to account for GT errors.\n"); + fprintf(stderr, " -b --buffer-size buffer size and the number of overlapping sites, 0 for unlimited [0]\n"); + fprintf(stderr, " If the first number is negative, it is interpreted as the maximum memory to\n"); + fprintf(stderr, " use, in MB. The default overlap is set to roughly 1%% of the buffer size.\n"); + fprintf(stderr, " -e, --estimate-AF [TAG], estimate AF from FORMAT/TAG (GT or PL) of all samples (\"-\") or samples listed\n"); + fprintf(stderr, " in . If TAG is not given, the frequency is estimated from GT by default\n"); + fprintf(stderr, " -G, --GTs-only use GTs and ignore PLs, instead using for PL of the two least likely genotypes.\n"); + fprintf(stderr, " Safe value to use is 30 to account for GT errors.\n"); + fprintf(stderr, " -i, --ignore-homref skip hom-ref genotypes (0/0)\n"); fprintf(stderr, " -I, --skip-indels skip indels as their genotypes are enriched for errors\n"); - fprintf(stderr, " -m, --genetic-map genetic map in IMPUTE2 format, single file or mask, where string \"{CHROM}\" is replaced with chromosome name\n"); + fprintf(stderr, " -m, --genetic-map genetic map in IMPUTE2 format, single file or mask, where string \"{CHROM}\"\n"); + fprintf(stderr, " is replaced with chromosome name\n"); fprintf(stderr, " -M, --rec-rate constant recombination rate per bp\n"); + fprintf(stderr, " -o, --output write output to a file [standard output]\n"); + fprintf(stderr, " -O, --output-type [srz] output s:per-site, r:regions, z:compressed [sr]\n"); fprintf(stderr, " -r, --regions restrict to comma-separated list of regions\n"); fprintf(stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(stderr, " -s, --sample sample to analyze\n"); + fprintf(stderr, " -s, --samples list of samples to analyze [all samples]\n"); + fprintf(stderr, " -S, --samples-file file of samples to analyze [all samples]\n"); fprintf(stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); fprintf(stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); + fprintf(stderr, " --threads number of extra decompression threads [0]\n"); fprintf(stderr, "\n"); fprintf(stderr, "HMM Options:\n"); fprintf(stderr, " -a, --hw-to-az P(AZ|HW) transition probability from HW (Hardy-Weinberg) to AZ (autozygous) state [6.7e-8]\n"); fprintf(stderr, " -H, --az-to-hw P(HW|AZ) transition probability from AZ to HW state [5e-9]\n"); - fprintf(stderr, " -V, --viterbi-training perform Viterbi training to estimate transition probabilities\n"); + fprintf(stderr, " -V, --viterbi-training estimate HMM parameters, is the convergence threshold, e.g. 1e-10 (experimental)\n"); fprintf(stderr, "\n"); exit(1); } @@ -721,12 +1091,17 @@ int main_vcfroh(int argc, char *argv[]) {"AF-tag",1,0,0}, {"AF-file",1,0,1}, {"AF-dflt",1,0,2}, + {"buffer-size",1,0,'b'}, + {"ignore-homref",0,0,'i'}, {"estimate-AF",1,0,'e'}, + {"output",1,0,'o'}, + {"output-type",1,0,'O'}, {"GTs-only",1,0,'G'}, - {"sample",1,0,'s'}, + {"samples",1,0,'s'}, + {"samples-file",1,0,'S'}, {"hw-to-az",1,0,'a'}, {"az-to-hw",1,0,'H'}, - {"viterbi-training",0,0,'V'}, + {"viterbi-training",1,0,'V'}, {"targets",1,0,'t'}, {"targets-file",1,0,'T'}, {"regions",1,0,'r'}, @@ -734,12 +1109,13 @@ int main_vcfroh(int argc, char *argv[]) {"genetic-map",1,0,'m'}, {"rec-rate",1,0,'M'}, {"skip-indels",0,0,'I'}, + {"threads",1,0,9}, {0,0,0,0} }; int naf_opts = 0; char *tmp; - while ((c = getopt_long(argc, argv, "h?r:R:t:T:H:a:s:m:M:G:Ia:e:V",loptions,NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "h?r:R:t:T:H:a:s:S:m:M:G:Ia:e:V:b:O:o:i",loptions,NULL)) >= 0) { switch (c) { case 0: args->af_tag = optarg; naf_opts++; break; case 1: args->af_fname = optarg; naf_opts++; break; @@ -747,7 +1123,15 @@ int main_vcfroh(int argc, char *argv[]) args->dflt_AF = strtod(optarg,&tmp); if ( *tmp ) error("Could not parse: --AF-dflt %s\n", optarg); break; + case 'o': args->output_fname = optarg; break; + case 'O': + if ( strchr(optarg,'s') || strchr(optarg,'S') ) args->output_type |= OUTPUT_ST; + if ( strchr(optarg,'r') || strchr(optarg,'R') ) args->output_type |= OUTPUT_RG; + if ( strchr(optarg,'z') || strchr(optarg,'z') ) args->output_type |= OUTPUT_GZ; + break; case 'e': args->estimate_AF = optarg; naf_opts++; break; + case 'b': args->buffer_size = optarg; break; + case 'i': args->skip_homref = 1; break; case 'I': args->snps_only = 1; break; case 'G': args->fake_PLs = 1; @@ -760,7 +1144,8 @@ int main_vcfroh(int argc, char *argv[]) args->rec_rate = strtod(optarg,&tmp); if ( *tmp ) error("Could not parse: -M %s\n", optarg); break; - case 's': args->sample = strdup(optarg); break; + case 's': args->samples = strdup(optarg); break; + case 'S': args->samples = strdup(optarg); args->samples_is_file = 1; break; case 'a': args->t2AZ = strtod(optarg,&tmp); if ( *tmp ) error("Could not parse: -a %s\n", optarg); @@ -773,14 +1158,28 @@ int main_vcfroh(int argc, char *argv[]) case 'T': args->targets_list = optarg; targets_is_file = 1; break; case 'r': args->regions_list = optarg; break; case 'R': args->regions_list = optarg; regions_is_file = 1; break; - case 'V': args->vi_training = 1; break; + case 9 : args->n_threads = strtol(optarg, 0, 0); break; + case 'V': + args->vi_training = 1; + args->baum_welch_th = strtod(optarg,&tmp); + if ( *tmp ) error("Could not parse: --viterbi-training %s\n", optarg); + break; case 'h': case '?': usage(args); break; default: error("Unknown argument: %s\n", optarg); } } + if ( !args->output_fname ) args->output_fname = "stdout"; + if ( !args->output_type ) args->output_type = OUTPUT_ST|OUTPUT_RG; + char *fname = NULL; + if ( optind==argc ) + { + if ( !isatty(fileno((FILE *)stdin)) ) fname = "-"; // reading from stdin + else usage(args); + } + else fname = argv[optind]; - if ( argcvi_training && args->buffer_size ) error("Error: cannot use -b with -V\n"); if ( args->t2AZ<0 || args->t2AZ>1 ) error("Error: The parameter --hw-to-az is not in [0,1]\n", args->t2AZ); if ( args->t2HW<0 || args->t2HW>1 ) error("Error: The parameter --az-to-hw is not in [0,1]\n", args->t2HW); if ( naf_opts>1 ) error("Error: The options --AF-tag, --AF-file and -e are mutually exclusive\n"); @@ -800,7 +1199,9 @@ int main_vcfroh(int argc, char *argv[]) if ( bcf_sr_set_targets(args->files, args->af_fname, 1, 3)<0 ) error("Failed to read the targets: %s\n", args->af_fname); } - if ( !bcf_sr_add_reader(args->files, argv[optind]) ) error("Failed to open %s: %s\n", argv[optind],bcf_sr_strerror(args->files->errnum)); + if ( args->n_threads && bcf_sr_set_threads(args->files, args->n_threads)<0) + error("Failed to create threads\n"); + if ( !bcf_sr_add_reader(args->files, fname) ) error("Failed to open %s: %s\n", fname,bcf_sr_strerror(args->files->errnum)); init_data(args); while ( bcf_sr_next_line(args->files) ) @@ -808,7 +1209,15 @@ int main_vcfroh(int argc, char *argv[]) vcfroh(args, args->files->readers[0].buffer[0]); } vcfroh(args, NULL); - fprintf(stderr,"Number of lines: total/processed: %d/%d\n", args->ntot,args->nused); + int i, nmin = 0; + for (i=0; iroh_smpl->n; i++) + if ( !i || args->smpl[i].nused < nmin ) nmin = args->smpl[i].nused; + fprintf(stderr,"Number of lines total/processed: %d/%d\n", args->ntot,nmin); + if ( nmin==0 ) + { + fprintf(stderr,"No usable sites were found."); + if ( !naf_opts && !args->dflt_AF ) fprintf(stderr, " Consider using one of the AF options.\n"); + } destroy_data(args); free(args); return 0; diff --git a/bcftools/vcfroh.c.pysam.c b/bcftools/vcfroh.c.pysam.c index 66ddc1701..77d2f4fdd 100644 --- a/bcftools/vcfroh.c.pysam.c +++ b/bcftools/vcfroh.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfroh.c -- HMM model for detecting runs of autozygosity. - Copyright (C) 2013-2015 Genome Research Ltd. + Copyright (C) 2013-2017 Genome Research Ltd. Author: Petr Danecek @@ -32,12 +32,19 @@ THE SOFTWARE. */ #include #include #include +#include +#include #include "bcftools.h" #include "HMM.h" +#include "smpl_ilist.h" #define STATE_HW 0 // normal state, follows Hardy-Weinberg allele frequencies #define STATE_AZ 1 // autozygous state +#define OUTPUT_ST (1<<1) +#define OUTPUT_RG (1<<2) +#define OUTPUT_GZ (1<<3) + /** Genetic map */ typedef struct { @@ -46,6 +53,24 @@ typedef struct } genmap_t; +/** HMM data for each sample */ +typedef struct +{ + double *eprob; // emission probs [2*nsites,msites] + uint32_t *sites; // positions [nsites,msites] + int nsites, msites; + int igenmap; // current position in genmap + int nused; // some stats to detect if things didn't go wrong + int nrid, *rid, *rid_off; // for viterbi training, keep all chromosomes + void *snapshot; // hmm snapshot + struct { + uint32_t beg,end,nqual; + double qual; + int rid, state; + } rg; +} +smpl_t; + typedef struct _args_t { bcf_srs_t *files; @@ -59,29 +84,32 @@ typedef struct _args_t double rec_rate; // constant recombination rate if > 0 hmm_t *hmm; - double *eprob; // emission probs [2*nsites,msites] - uint32_t *sites; // positions [nsites,msites] - int nsites, msites; + double baum_welch_th; int nrids, *rids, *rid_offs; // multiple chroms with vi_training + int nbuf_max, nbuf_olap; - int32_t *itmp; - int nitmp, mitmp; float *AFs; - int mAFs; + int32_t *itmp; + int mAFs, nitmp, mitmp, pl_hdr_id, gt_hdr_id; double pl2p[256], *pdg; int32_t skip_rid, prev_rid, prev_pos; - int ntot, nused; // some stats to detect if things didn't go awfully wrong - int ismpl, nsmpl; // index of query sample - char *estimate_AF, *sample; // list of samples for AF estimate and query sample - char **argv, *targets_list, *regions_list, *af_fname, *af_tag; - int argc, fake_PLs, snps_only, vi_training; + int ntot; // some stats to detect if things didn't go wrong + smpl_t *smpl; // HMM data for each sample + smpl_ilist_t *af_smpl; // list of samples to estimate AF from (--estimate-AF) + smpl_ilist_t *roh_smpl; // list of samples to analyze (--samples, --samples-file) + char *estimate_AF; // list of samples for AF estimate and query sample + int af_from_PL; // estimate AF from FMT/PL rather than FMT/GT + char **argv, *targets_list, *regions_list, *af_fname, *af_tag, *samples, *buffer_size, *output_fname; + int argc, fake_PLs, snps_only, vi_training, samples_is_file, output_type, skip_homref, n_threads; + BGZF *out; + kstring_t str; } args_t; void set_tprob_genmap(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, double *tprob); -void set_tprob_recrate(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, double *tprob); +void set_tprob_rrate(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, double *tprob); void *smalloc(size_t size) { @@ -92,57 +120,137 @@ void *smalloc(size_t size) static void init_data(args_t *args) { + int i; + args->prev_rid = args->skip_rid = -1; args->hdr = args->files->readers[0].header; - if ( !args->sample ) - { - if ( bcf_hdr_nsamples(args->hdr)>1 ) error("Missing the option -s, --sample\n"); - args->sample = strdup(args->hdr->samples[0]); - } if ( !bcf_hdr_nsamples(args->hdr) ) error("No samples in the VCF?\n"); - // Set samples - kstring_t str = {0,0,0}; - if ( args->estimate_AF && strcmp("-",args->estimate_AF) ) + if ( !args->fake_PLs ) { - int i, n; - char **smpls = hts_readlist(args->estimate_AF, 1, &n); + args->pl_hdr_id = bcf_hdr_id2int(args->hdr, BCF_DT_ID, "PL"); + if ( !bcf_hdr_idinfo_exists(args->hdr,BCF_HL_FMT,args->pl_hdr_id) ) + error("Error: The FORMAT/PL tag not found in the header, consider running with -G\n"); + if ( bcf_hdr_id2type(args->hdr,BCF_HL_FMT,args->pl_hdr_id)!=BCF_HT_INT ) + error("Error: The FORMAT/PL tag not defined as Integer in the header\n"); + } - // Make sure the query sample is included - for (i=0; isample,smpls[i]) ) break; + if ( args->estimate_AF ) + { + if ( !strncmp("GT,",args->estimate_AF,3) ) args->estimate_AF += 3; + else if ( !strncmp("PL,",args->estimate_AF,3) ) { args->estimate_AF += 3; args->af_from_PL = 1; } + if ( strcmp("-",args->estimate_AF) ) + args->af_smpl = smpl_ilist_init(args->hdr, args->estimate_AF, 1, SMPL_NONE); + } - // Add the query sample if not present - if ( i!=n ) kputs(args->sample, &str); + if ( args->estimate_AF || args->fake_PLs ) + { + if ( args->af_from_PL ) + { + args->pl_hdr_id = bcf_hdr_id2int(args->hdr, BCF_DT_ID, "PL"); + if ( !bcf_hdr_idinfo_exists(args->hdr,BCF_HL_FMT,args->pl_hdr_id) ) + error("Error: The FORMAT/PL tag not found in the header\n"); + } + else + { + args->gt_hdr_id = bcf_hdr_id2int(args->hdr, BCF_DT_ID, "GT"); + if ( !bcf_hdr_idinfo_exists(args->hdr,BCF_HL_FMT,args->gt_hdr_id) ) + error("Error: The FORMAT/GT tag not found in the header\n"); + } + } + if ( args->fake_PLs ) + { + args->gt_hdr_id = bcf_hdr_id2int(args->hdr, BCF_DT_ID, "GT"); + if ( !bcf_hdr_idinfo_exists(args->hdr,BCF_HL_FMT,args->gt_hdr_id) ) + error("Error: The FORMAT/GT tag not found in the header\n"); + } - for (i=0; iroh_smpl = smpl_ilist_init(args->hdr, args->samples, args->samples_is_file, SMPL_NONE); + if ( args->samples ) + { + // we may be able to subset to a few samples, for a text VCF this can be a major speedup + if ( (bcf_sr_get_reader(args->files,0))->file->format.format==vcf ) { - if ( str.l ) kputc(',', &str); - kputs(smpls[i], &str); - free(smpls[i]); + kstring_t str = {0,0,0}; + smpl_ilist_t *tmp = args->roh_smpl, *rmme = NULL; + if ( args->af_smpl ) + { + for (i=0; iroh_smpl->n; i++) + { + if ( str.l ) kputc(',', &str); + kputs(args->hdr->samples[args->roh_smpl->idx[i]], &str); + } + for (i=0; iaf_smpl->n; i++) + { + kputc(',', &str); + kputs(args->hdr->samples[args->af_smpl->idx[i]], &str); + } + rmme = tmp = smpl_ilist_init(args->hdr, str.s, 0, SMPL_NONE); + } + if ( tmp->n < bcf_hdr_nsamples(args->hdr) ) + { + str.l = 0; + for (i=0; in; i++) + { + if ( str.l ) kputc(',', &str); + kputs(args->hdr->samples[tmp->idx[i]], &str); + } + int ret = bcf_hdr_set_samples(args->hdr, str.s, 0); + if ( ret<0 ) error("Error parsing the list of samples: %s\n", str.s); + else if ( ret>0 ) error("The %d-th sample not found in the VCF: %s\n", ret,str.s); + + // update sample ids + smpl_ilist_destroy(args->roh_smpl); + args->roh_smpl = smpl_ilist_init(args->hdr, args->samples, args->samples_is_file, SMPL_NONE); + + if ( args->af_smpl ) + { + smpl_ilist_destroy(args->af_smpl); + args->af_smpl = smpl_ilist_init(args->hdr, args->estimate_AF, 1, SMPL_NONE); + } + } + free(str.s); + if ( rmme ) + smpl_ilist_destroy(rmme); } - free(smpls); } - else if ( !args->estimate_AF ) - kputs(args->sample, &str); - if ( str.l ) + // check whether all samples are in this list. If so, the lookup will not be needed + if ( args->af_smpl && args->af_smpl->n == bcf_hdr_nsamples(args->hdr) ) { - int ret = bcf_hdr_set_samples(args->hdr, str.s, 0); - if ( ret<0 ) error("Error parsing the list of samples: %s\n", str.s); - else if ( ret>0 ) error("The %d-th sample not found in the VCF\n", ret); + // all samples are in this list + smpl_ilist_destroy(args->af_smpl); + args->af_smpl = NULL; } - if ( args->af_tag ) - if ( !bcf_hdr_idinfo_exists(args->hdr,BCF_HL_INFO,bcf_hdr_id2int(args->hdr,BCF_DT_ID,args->af_tag)) ) - error("No such INFO tag in the VCF: %s\n", args->af_tag); + if ( args->buffer_size ) + { + args->nbuf_olap = -1; + char *end; + double tmp = strtod(args->buffer_size,&end); + if ( *end ) + { + if ( *end!=',') error("Could not parse: --buffer-size %s\n", args->buffer_size); + args->nbuf_olap = strtol(end+1,&end,10); + if ( *end || args->nbuf_olap<0 ) error("Could not parse: --bufer-size %s\n", args->buffer_size); + } + if ( tmp<0 ) + args->nbuf_max = fabs(tmp)*1e6/(4+8*2)/args->roh_smpl->n; + else + args->nbuf_max = tmp; - args->nsmpl = bcf_hdr_nsamples(args->hdr); - args->ismpl = bcf_hdr_id2int(args->hdr, BCF_DT_SAMPLE, args->sample); - free(str.s); + if ( args->nbuf_olap<0 ) + args->nbuf_olap = args->nbuf_max*0.01; + } + fprintf(bcftools_stderr,"Number of target samples: %d\n", args->roh_smpl->n); + fprintf(bcftools_stderr,"Number of --estimate-AF samples: %d\n", args->af_smpl ? args->af_smpl->n : (args->estimate_AF ? bcf_hdr_nsamples(args->hdr) : 0)); + fprintf(bcftools_stderr,"Number of sites in the buffer/overlap: "); + if ( args->nbuf_max ) fprintf(bcftools_stderr,"%d/%d\n", args->nbuf_max,args->nbuf_olap); + else fprintf(bcftools_stderr,"unlimited\n"); + + args->smpl = (smpl_t*) calloc(args->roh_smpl->n,sizeof(smpl_t)); - int i; for (i=0; i<256; i++) args->pl2p[i] = pow(10., -i/10.); // Init transition matrix and HMM @@ -152,43 +260,91 @@ static void init_data(args_t *args) MAT(tprob,2,STATE_AZ,STATE_HW) = args->t2AZ; MAT(tprob,2,STATE_AZ,STATE_AZ) = 1 - args->t2HW; + args->hmm = hmm_init(2, tprob, 10000); if ( args->genmap_fname ) - { - args->hmm = hmm_init(2, tprob, 0); hmm_set_tprob_func(args->hmm, set_tprob_genmap, args); - } else if ( args->rec_rate > 0 ) - { - args->hmm = hmm_init(2, tprob, 0); - hmm_set_tprob_func(args->hmm, set_tprob_recrate, args); + hmm_set_tprob_func(args->hmm, set_tprob_rrate, args); - } - else - args->hmm = hmm_init(2, tprob, 10000); + args->out = bgzf_open(strcmp("bcftools_stdout",args->output_fname)?args->output_fname:"-", args->output_type&OUTPUT_GZ ? "wg" : "wu"); + if ( !args->out ) error("Failed to open %s: %s\n", args->output_fname, strerror(errno)); // print header - fprintf(pysam_stdout, "# This file was produced by: bcftools roh(%s+htslib-%s)\n", bcftools_version(),hts_version()); - fprintf(pysam_stdout, "# The command line was:\tbcftools %s", args->argv[0]); + args->str.l = 0; + ksprintf(&args->str, "# This file was produced by: bcftools roh(%s+htslib-%s)\n", bcftools_version(),hts_version()); + ksprintf(&args->str, "# The command line was:\tbcftools %s", args->argv[0]); for (i=1; iargc; i++) - fprintf(pysam_stdout, " %s",args->argv[i]); - fprintf(pysam_stdout, "\n#\n"); - fprintf(pysam_stdout, "# [1]Chromosome\t[2]Position\t[3]State (0:HW, 1:AZ)\t[4]Quality\n"); + ksprintf(&args->str, " %s",args->argv[i]); + ksprintf(&args->str, "\n#\n"); + if ( args->output_type & OUTPUT_RG ) + { + i = 2; + ksprintf(&args->str, "# RG"); + ksprintf(&args->str, "\t[%d]Sample", i++); + ksprintf(&args->str, "\t[%d]Chromosome", i++); + ksprintf(&args->str, "\t[%d]Start", i++); + ksprintf(&args->str, "\t[%d]End", i++); + ksprintf(&args->str, "\t[%d]Length (bp)", i++); + ksprintf(&args->str, "\t[%d]Number of markers", i++); + ksprintf(&args->str, "\t[%d]Quality (average fwd-bwd phred score)", i++); + ksprintf(&args->str, "\n"); + } + if ( args->output_type & OUTPUT_ST ) + { + i = 2; + ksprintf(&args->str, "# ST"); + ksprintf(&args->str, "\t[%d]Sample", i++); + ksprintf(&args->str, "\t[%d]Chromosome", i++); + ksprintf(&args->str, "\t[%d]Position", i++); + ksprintf(&args->str, "\t[%d]State (0:HW, 1:AZ)", i++); + ksprintf(&args->str, "\t[%d]Quality (fwd-bwd phred score)", i++); + ksprintf(&args->str, "\n"); + } + if ( args->vi_training) + { + i = 2; + ksprintf(&args->str, "# VT, Viterbi Training"); + ksprintf(&args->str, "\t[%d]Sample", i++); + ksprintf(&args->str, "\t[%d]Iteration", i++); + ksprintf(&args->str, "\t[%d]dAZ", i++); + ksprintf(&args->str, "\t[%d]dHW", i++); + ksprintf(&args->str, "\t[%d]1 - P(HW|HW)", i++); + ksprintf(&args->str, "\t[%d]P(AZ|HW)", i++); + ksprintf(&args->str, "\t[%d]1 - P(AZ|AZ)", i++); + ksprintf(&args->str, "\t[%d]P(HW|AZ)", i++); + ksprintf(&args->str, "\n"); + } + if ( bgzf_write(args->out, args->str.s, args->str.l) != args->str.l ) + error("Error writing %s: %s\n", args->output_fname, strerror(errno)); } static void destroy_data(args_t *args) { - free(args->sites); - free(args->eprob); - free(args->sample); + if ( bgzf_close(args->out)!=0 ) error("Error: close failed .. %s\n", args->output_fname); + int i; + for (i=0; iroh_smpl->n; i++) + { + free(args->smpl[i].eprob); + free(args->smpl[i].sites); + free(args->smpl[i].rid); + free(args->smpl[i].rid_off); + free(args->smpl[i].snapshot); + } + free(args->str.s); + free(args->smpl); + if ( args->af_smpl ) smpl_ilist_destroy(args->af_smpl); + smpl_ilist_destroy(args->roh_smpl); free(args->rids); free(args->rid_offs); hmm_destroy(args->hmm); bcf_sr_destroy(args->files); - free(args->itmp); free(args->AFs); free(args->pdg); + free(args->AFs); free(args->pdg); free(args->genmap); + free(args->itmp); + free(args->samples); } -static int load_genmap(args_t *args, bcf1_t *line) +static int load_genmap(args_t *args, const char *chr) { if ( !args->genmap_fname ) { args->ngenmap = 0; return 0; } @@ -197,7 +353,7 @@ static int load_genmap(args_t *args, bcf1_t *line) if ( fname ) { kputsn(args->genmap_fname, fname - args->genmap_fname, &str); - kputs(bcf_seqname(args->hdr,line), &str); + kputs(chr, &str); kputs(fname+7,&str); fname = str.s; } @@ -222,21 +378,22 @@ static int load_genmap(args_t *args, bcf1_t *line) hts_expand(genmap_t,args->ngenmap,args->mgenmap,args->genmap); genmap_t *gm = &args->genmap[args->ngenmap-1]; + // position, convert to 0-based char *tmp, *end; gm->pos = strtol(str.s, &tmp, 10); if ( str.s==tmp ) error("Could not parse %s: %s\n", fname, str.s); + gm->pos -= 1; // skip second column tmp++; while ( *tmp && !isspace(*tmp) ) tmp++; - // read the genetic map in cM + // read the genetic map in cM, scale from % to likelihood gm->rate = strtod(tmp+1, &end); if ( tmp+1==end ) error("Could not parse %s: %s\n", fname, str.s); + gm->rate *= 0.01; } if ( !args->ngenmap ) error("Genetic map empty?\n"); - int i; - for (i=0; ingenmap; i++) args->genmap[i].rate /= args->genmap[args->ngenmap-1].rate; // scale to 1 if ( hts_close(fp) ) error("Close failed\n"); free(str.s); return 0; @@ -257,7 +414,6 @@ static double get_genmap_rate(args_t *args, int start, int end) // position j to be equal or larger than end int j = i; while ( j+1ngenmap && args->genmap[j].pos < end ) j++; - if ( i==j ) { args->igenmap = i; @@ -274,17 +430,20 @@ static double get_genmap_rate(args_t *args, int start, int end) void set_tprob_genmap(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, double *tprob) { args_t *args = (args_t*) data; - double ci = get_genmap_rate(args, pos - prev_pos, pos); + double ci = get_genmap_rate(args, prev_pos, pos); + if ( args->rec_rate ) ci *= args->rec_rate; + if ( ci > 1 ) ci = 1; MAT(tprob,2,STATE_HW,STATE_AZ) *= ci; MAT(tprob,2,STATE_AZ,STATE_HW) *= ci; MAT(tprob,2,STATE_AZ,STATE_AZ) = 1 - MAT(tprob,2,STATE_HW,STATE_AZ); MAT(tprob,2,STATE_HW,STATE_HW) = 1 - MAT(tprob,2,STATE_AZ,STATE_HW); } -void set_tprob_recrate(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, double *tprob) +void set_tprob_rrate(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, double *tprob) { args_t *args = (args_t*) data; double ci = (pos - prev_pos) * args->rec_rate; + if ( ci > 1 ) ci = 1; MAT(tprob,2,STATE_HW,STATE_AZ) *= ci; MAT(tprob,2,STATE_AZ,STATE_HW) *= ci; MAT(tprob,2,STATE_AZ,STATE_AZ) = 1 - MAT(tprob,2,STATE_HW,STATE_AZ); @@ -317,133 +476,165 @@ void set_tprob_recrate(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data, * */ -static void flush_viterbi(args_t *args) +static void flush_viterbi(args_t *args, int ismpl) { - int i,j; + smpl_t *smpl = &args->smpl[ismpl]; + if ( !smpl->nsites ) return; + + const char *name = args->hdr->samples[ args->roh_smpl->idx[ismpl] ]; - if ( !args->nsites ) return; + int i,j,k; - if ( !args->vi_training ) + if ( !args->vi_training ) // single viterbi pass { - // single viterbi pass, one chromsome - hmm_run_viterbi(args->hmm, args->nsites, args->eprob, args->sites); - hmm_run_fwd_bwd(args->hmm, args->nsites, args->eprob, args->sites); + hmm_restore(args->hmm, smpl->snapshot); + int end = (args->nbuf_max && smpl->nsites >= args->nbuf_max && smpl->nsites > args->nbuf_olap) ? smpl->nsites - args->nbuf_olap : smpl->nsites; + if ( end < smpl->nsites ) + smpl->snapshot = hmm_snapshot(args->hmm, smpl->snapshot, smpl->sites[smpl->nsites - args->nbuf_olap - 1]); + + args->igenmap = smpl->igenmap; + hmm_run_viterbi(args->hmm, smpl->nsites, smpl->eprob, smpl->sites); + hmm_run_fwd_bwd(args->hmm, smpl->nsites, smpl->eprob, smpl->sites); double *fwd = hmm_get_fwd_bwd_prob(args->hmm); - const char *chr = bcf_hdr_id2name(args->hdr,args->prev_rid); - uint8_t *vpath = hmm_get_viterbi_path(args->hmm); - for (i=0; insites; i++) + const char *chr = bcf_hdr_id2name(args->hdr,args->prev_rid); + uint8_t *vpath = hmm_get_viterbi_path(args->hmm); + + for (i=0; isites[i]+1, state, phred_score(1.0-pval[state])); - } - return; - } + double qual = phred_score(1.0 - fwd[i*2 + state]); + if ( args->output_type & OUTPUT_ST ) + { + args->str.l = 0; + ksprintf(&args->str, "ST\t%s\t%s\t%d\t%d\t%.1f\n", name,chr,smpl->sites[i]+1, state, qual); + if ( bgzf_write(args->out, args->str.s, args->str.l) != args->str.l ) error("Error writing %s: %s\n", args->output_fname, strerror(errno)); + } - // viterbi training, multiple chromosomes - double t2az_prev, t2hw_prev; - double deltaz, delthw; - int niter = 0; - do - { - double *tprob_arr = hmm_get_tprob(args->hmm); - t2az_prev = MAT(tprob_arr,2,1,0); //args->t2AZ; - t2hw_prev = MAT(tprob_arr,2,0,1); //args->t2HW; - double tcounts[] = { 0,0,0,0 }; - for (i=0; inrids; i++) - { - // run viterbi for each chromosomes. eprob and sites contain - // multiple chromosomes, rid_offs mark the boundaries - int ioff = args->rid_offs[i]; - int nsites = (i+1==args->nrids ? args->nsites : args->rid_offs[i+1]) - ioff; - hmm_run_viterbi(args->hmm, nsites, args->eprob+ioff*2, args->sites+ioff); - - // what transitions were observed: add to the total counts - uint8_t *vpath = hmm_get_viterbi_path(args->hmm); - for (j=1; joutput_type & OUTPUT_RG ) { - // count the number of transitions - int prev_state = vpath[2*(j-1)]; - int curr_state = vpath[2*j]; - MAT(tcounts,2,curr_state,prev_state) += 1; + if ( state!=smpl->rg.state ) + { + if ( !state ) // the region ends, flush + { + args->str.l = 0; + ksprintf(&args->str, "RG\t%s\t%s\t%d\t%d\t%d\t%d\t%.1f\n",name,bcf_hdr_id2name(args->hdr,smpl->rg.rid), + smpl->rg.beg+1,smpl->rg.end+1,smpl->rg.end-smpl->rg.beg+1,smpl->rg.nqual,smpl->rg.qual/smpl->rg.nqual); + if ( bgzf_write(args->out, args->str.s, args->str.l) != args->str.l ) error("Error writing %s: %s\n", args->output_fname, strerror(errno)); + smpl->rg.state = 0; + } + else + { + smpl->rg.state = 1; + smpl->rg.beg = smpl->sites[i]; + smpl->rg.rid = args->prev_rid; + smpl->rg.qual = qual; + smpl->rg.nqual = 1; + } + } + else if ( state ) + { + smpl->rg.nqual++; + smpl->rg.qual += qual; + smpl->rg.end = smpl->sites[i]; + } } } - // update the transition matrix - int n = 1; - for (i=0; i<2; i++) + if ( end < smpl->nsites ) { - for (j=0; j<2; j++) n += MAT(tcounts,2,i,j); + end = smpl->nsites - args->nbuf_olap; + memmove(smpl->sites, smpl->sites + end, sizeof(*smpl->sites)*args->nbuf_olap); + memmove(smpl->eprob, smpl->eprob + end*2, sizeof(*smpl->eprob)*args->nbuf_olap*2); + smpl->nsites = args->nbuf_olap; + smpl->igenmap = args->igenmap; } - for (i=0; i<2; i++) + else { - for (j=0; j<2; j++) + smpl->nsites = 0; + smpl->igenmap = 0; + + if ( smpl->rg.state ) { - // no transition to i-th state was observed, set to a small number - if ( !MAT(tcounts,2,i,j) ) MAT(tcounts,2,i,j) = 0.1/n; - else MAT(tcounts,2,i,j) /= n; + args->str.l = 0; + ksprintf(&args->str, "RG\t%s\t%s\t%d\t%d\t%d\t%d\t%.1f\n",name,bcf_hdr_id2name(args->hdr,smpl->rg.rid), + smpl->rg.beg+1,smpl->rg.end+1,smpl->rg.end-smpl->rg.beg+1,smpl->rg.nqual,smpl->rg.qual/smpl->rg.nqual); + if ( bgzf_write(args->out, args->str.s, args->str.l) != args->str.l ) error("Error writing %s: %s\n", args->output_fname, strerror(errno)); + smpl->rg.state = 0; } } - // normalize - for (i=0; i<2; i++) + return; + } + + + // viterbi training, multiple chromosomes + double t2az_prev, t2hw_prev; + double deltaz, delthw; + + double *tprob_arr = hmm_get_tprob(args->hmm); + MAT(tprob_arr,2,STATE_HW,STATE_HW) = 1 - args->t2AZ; + MAT(tprob_arr,2,STATE_HW,STATE_AZ) = args->t2HW; + MAT(tprob_arr,2,STATE_AZ,STATE_HW) = args->t2AZ; + MAT(tprob_arr,2,STATE_AZ,STATE_AZ) = 1 - args->t2HW; + hmm_set_tprob(args->hmm, tprob_arr, 10000); + + int niter = 0; + do + { + tprob_arr = hmm_get_tprob(args->hmm); + t2az_prev = MAT(tprob_arr,2,STATE_AZ,STATE_HW); //args->t2AZ; + t2hw_prev = MAT(tprob_arr,2,STATE_HW,STATE_AZ); //args->t2HW; + double tprob_new[] = { 0,0,0,0 }; + for (i=0; inrid; i++) { - double norm = 0; - for (j=0; j<2; j++) norm += MAT(tcounts,2,j,i); - assert( norm!=0 ); - for (j=0; j<2; j++) MAT(tcounts,2,j,i) /= norm; + int ioff = smpl->rid_off[i]; + int nsites = (i+1==smpl->nrid ? smpl->nsites : smpl->rid_off[i+1]) - ioff; + args->igenmap = 0; + tprob_arr = hmm_run_baum_welch(args->hmm, nsites, smpl->eprob+ioff*2, smpl->sites+ioff); + for (j=0; j<2; j++) + for (k=0; k<2; k++) MAT(tprob_new,2,j,k) += MAT(tprob_arr,2,j,k); } + for (j=0; j<2; j++) + for (k=0; k<2; k++) MAT(tprob_new,2,j,k) /= smpl->nrid; - if ( args->genmap_fname || args->rec_rate > 0 ) - hmm_set_tprob(args->hmm, tcounts, 0); - else - hmm_set_tprob(args->hmm, tcounts, 10000); + hmm_set_tprob(args->hmm, tprob_new, 10000); - tprob_arr = hmm_get_tprob(args->hmm); - deltaz = fabs(MAT(tprob_arr,2,1,0)-t2az_prev); - delthw = fabs(MAT(tprob_arr,2,0,1)-t2hw_prev); + deltaz = fabs(MAT(tprob_new,2,STATE_AZ,STATE_HW)-t2az_prev); + delthw = fabs(MAT(tprob_new,2,STATE_HW,STATE_AZ)-t2hw_prev); niter++; - fprintf(pysam_stderr,"Viterbi training, iteration %d: dAZ=%e dHW=%e\tP(HW|HW)=%e P(AZ|HW)=%e P(AZ|AZ)=%e P(HW|AZ)=%e\n", - niter,deltaz,delthw, - MAT(tprob_arr,2,STATE_HW,STATE_HW),MAT(tprob_arr,2,STATE_AZ,STATE_HW), - MAT(tprob_arr,2,STATE_AZ,STATE_AZ),MAT(tprob_arr,2,STATE_HW,STATE_AZ)); + args->str.l = 0; + ksprintf(&args->str, "VT\t%s\t%d\t%e\t%e\t%e\t%e\t%e\t%e\n", + name,niter,deltaz,delthw, + 1-MAT(tprob_new,2,STATE_HW,STATE_HW),MAT(tprob_new,2,STATE_AZ,STATE_HW), + 1-MAT(tprob_new,2,STATE_AZ,STATE_AZ),MAT(tprob_new,2,STATE_HW,STATE_AZ)); + if ( bgzf_write(args->out, args->str.s, args->str.l) != args->str.l ) error("Error writing %s: %s\n", args->output_fname, strerror(errno)); } - while ( deltaz > 0.0 || delthw > 0.0 ); - double *tprob_arr = hmm_get_tprob(args->hmm); - fprintf(pysam_stderr, "Viterbi training converged in %d iterations to P(HW|HW)=%e P(AZ|HW)=%e P(AZ|AZ)=%e P(HW|AZ)=%e\n", niter, - MAT(tprob_arr,2,STATE_HW,STATE_HW),MAT(tprob_arr,2,STATE_AZ,STATE_HW), - MAT(tprob_arr,2,STATE_AZ,STATE_AZ),MAT(tprob_arr,2,STATE_HW,STATE_AZ)); + while ( deltaz > args->baum_welch_th || delthw > args->baum_welch_th ); // output the results - for (i=0; inrids; i++) + for (i=0; inrid; i++) { - int ioff = args->rid_offs[i]; - int nsites = (i+1==args->nrids ? args->nsites : args->rid_offs[i+1]) - ioff; - hmm_run_viterbi(args->hmm, nsites, args->eprob+ioff*2, args->sites+ioff); - hmm_run_fwd_bwd(args->hmm, nsites, args->eprob+ioff*2, args->sites+ioff); + int ioff = smpl->rid_off[i]; + int nsites = (i+1==smpl->nrid ? smpl->nsites : smpl->rid_off[i+1]) - ioff; + args->igenmap = 0; + hmm_run_viterbi(args->hmm, nsites, smpl->eprob+ioff*2, smpl->sites+ioff); + hmm_run_fwd_bwd(args->hmm, nsites, smpl->eprob+ioff*2, smpl->sites+ioff); uint8_t *vpath = hmm_get_viterbi_path(args->hmm); double *fwd = hmm_get_fwd_bwd_prob(args->hmm); - const char *chr = bcf_hdr_id2name(args->hdr,args->rids[i]); + const char *chr = bcf_hdr_id2name(args->hdr,smpl->rid[i]); for (j=0; jsites[ioff+j]+1,state==STATE_AZ ? 1 : 0, pval); + int state = vpath[j*2]==STATE_AZ ? 1 : 0; + double *pval = fwd + j*2; + args->str.l = 0; + ksprintf(&args->str, "ROH\t%s\t%s\t%d\t%d\t%.1f\n", name,chr,smpl->sites[ioff+j]+1, state, phred_score(1.0-pval[state])); + if ( bgzf_write(args->out, args->str.s, args->str.l) != args->str.l ) error("Error writing %s: %s\n", args->output_fname, strerror(errno)); } } } -static void push_rid(args_t *args, int rid) -{ - args->nrids++; - args->rids = (int*) realloc(args->rids, args->nrids*sizeof(int)); - args->rid_offs = (int*) realloc(args->rid_offs, args->nrids*sizeof(int)); - args->rids[ args->nrids-1 ] = rid; - args->rid_offs[ args->nrids-1 ] = args->nsites; -} - int read_AF(bcf_sr_regions_t *tgt, bcf1_t *line, double *alt_freq) { if ( tgt->nals != line->n_allele ) return -1; // number of alleles does not match @@ -470,27 +661,52 @@ int read_AF(bcf_sr_regions_t *tgt, bcf1_t *line, double *alt_freq) return 0; } -int estimate_AF(args_t *args, bcf1_t *line, double *alt_freq) +int8_t *get_GT(args_t *args, bcf1_t *line) { - if ( !args->nitmp ) - { - args->nitmp = bcf_get_genotypes(args->hdr, line, &args->itmp, &args->mitmp); - if ( args->nitmp != 2*args->nsmpl ) return -1; // not diploid? - args->nitmp /= args->nsmpl; - } + int i; + for (i=0; in_fmt; i++) + if ( line->d.fmt[i].id==args->gt_hdr_id ) break; + if ( i==line->n_fmt ) return NULL; // the tag is not present in this record + + bcf_fmt_t *fmt = &line->d.fmt[i]; + if ( fmt->n!=2 ) return NULL; // not diploid + if ( fmt->type!=BCF_BT_INT8 ) error("This is unexpected, GT type is %d\n", fmt->type); + return (int8_t*) fmt->p; +} + +int estimate_AF_from_GT(args_t *args, int8_t *gt, double *alt_freq) +{ int i, nalt = 0, nref = 0; - for (i=0; insmpl; i++) + if ( args->af_smpl ) // subset samples for AF estimate { - int32_t *gt = &args->itmp[i*args->nitmp]; + for (i=0; iaf_smpl->n; i++) + { + int ismpl = args->af_smpl->idx[i]; + if ( bcf_gt_is_missing(gt[2*ismpl]) || bcf_gt_is_missing(gt[2*ismpl+1]) ) continue; - if ( bcf_gt_is_missing(gt[0]) || bcf_gt_is_missing(gt[1]) ) continue; + if ( bcf_gt_allele(gt[2*ismpl]) ) nalt++; + else nref++; - if ( bcf_gt_allele(gt[0]) ) nalt++; - else nref++; + if ( bcf_gt_allele(gt[2*ismpl+1]) ) nalt++; + else nref++; + } + } + else // all samples used in AF estimate + { + int8_t *end = gt + 2*bcf_hdr_nsamples(args->hdr); + while ( gt < end ) + { + if ( bcf_gt_is_missing(gt[0]) || bcf_gt_is_missing(gt[1]) ) continue; - if ( bcf_gt_allele(gt[1]) ) nalt++; - else nref++; + if ( bcf_gt_allele(gt[0]) ) nalt++; + else nref++; + + if ( bcf_gt_allele(gt[1]) ) nalt++; + else nref++; + + gt += 2; + } } if ( !nalt && !nref ) return -1; @@ -498,105 +714,249 @@ int estimate_AF(args_t *args, bcf1_t *line, double *alt_freq) return 0; } +int estimate_AF_from_PL(args_t *args, bcf_fmt_t *fmt_pl, int ial, double *alt_freq) +{ + double af = 0; + int i, j, naf = 0; + + int irr = bcf_alleles2gt(0,0), ira = bcf_alleles2gt(0,ial), iaa = bcf_alleles2gt(ial,ial); + if ( iaa >= fmt_pl->n ) return -1; // not diploid or wrong number of fields + + if ( args->af_smpl ) // subset samples for AF estimate + { + #define BRANCH(type_t) \ + { \ + for (i=0; iaf_smpl->n; i++) \ + { \ + int ismpl = args->af_smpl->idx[i]; \ + type_t *p = (type_t*)fmt_pl->p + fmt_pl->n*ismpl; \ + if ( p[irr]<0 || p[ira]<0 || p[iaa]<0 ) continue; /* missing value */ \ + if ( p[irr]==p[ira] && p[irr]==p[iaa] ) continue; /* all values are the same */ \ + double prob[3], norm = 0; \ + prob[0] = p[irr] < (type_t)256 ? args->pl2p[ p[irr] ] : args->pl2p[255]; \ + prob[1] = p[ira] < (type_t)256 ? args->pl2p[ p[ira] ] : args->pl2p[255]; \ + prob[2] = p[iaa] < (type_t)256 ? args->pl2p[ p[iaa] ] : args->pl2p[255]; \ + for (j=0; j<3; j++) norm += prob[j]; \ + for (j=0; j<3; j++) prob[j] /= norm; \ + af += 0.5*prob[1] + prob[2]; \ + naf++; \ + } \ + } + switch (fmt_pl->type) { + case BCF_BT_INT8: BRANCH(int8_t); break; + case BCF_BT_INT16: BRANCH(int16_t); break; + case BCF_BT_INT32: BRANCH(int32_t); break; + default: fprintf(bcftools_stderr,"Unknown format type for PL: %s:%d .. fmt->type=%d\n", __FILE__,__LINE__, fmt_pl->type); exit(1); + } + #undef BRANCH + } + else // all samples used in AF estimate + { + int nsmpl = bcf_hdr_nsamples(args->hdr); + #define BRANCH(type_t) \ + { \ + type_t *p = (type_t*)fmt_pl->p; \ + p -= fmt_pl->n; \ + for (i=0; in; \ + if ( p[irr]<0 || p[ira]<0 || p[iaa]<0 ) continue; /* missing value */ \ + if ( p[irr]==p[ira] && p[irr]==p[iaa] ) continue; /* all values are the same */ \ + double prob[3], norm = 0; \ + prob[0] = p[irr] < (type_t)256 ? args->pl2p[ p[irr] ] : args->pl2p[255]; \ + prob[1] = p[ira] < (type_t)256 ? args->pl2p[ p[ira] ] : args->pl2p[255]; \ + prob[2] = p[iaa] < (type_t)256 ? args->pl2p[ p[iaa] ] : args->pl2p[255]; \ + for (j=0; j<3; j++) norm += prob[j]; \ + for (j=0; j<3; j++) prob[j] /= norm; \ + af += 0.5*prob[1] + prob[2]; \ + naf++; \ + } \ + } + switch (fmt_pl->type) { + case BCF_BT_INT8: BRANCH(int8_t); break; + case BCF_BT_INT16: BRANCH(int16_t); break; + case BCF_BT_INT32: BRANCH(int32_t); break; + default: fprintf(bcftools_stderr,"Unknown format type for PL: %s:%d .. fmt->type=%d\n", __FILE__,__LINE__, fmt_pl->type); exit(1); + } + #undef BRANCH + } + if ( !naf ) return -1; + + *alt_freq = af / naf; + return 0; +} + +bcf_fmt_t *get_PL(args_t *args, bcf1_t *line) +{ + int i; + for (i=0; in_fmt; i++) + if ( line->d.fmt[i].id==args->pl_hdr_id ) return &line->d.fmt[i]; + return NULL; +} -int parse_line(args_t *args, bcf1_t *line, double *alt_freq, double *pdg) +int process_line(args_t *args, bcf1_t *line, int ial) { - args->nitmp = 0; + if ( !(line->unpacked & BCF_UN_FMT) ) bcf_unpack(line, BCF_UN_FMT); + + double alt_freq; + int8_t *GTs = NULL; + bcf_fmt_t *fmt_pl = NULL; // Set allele frequency - int ret; + int ret = 0, i,j; if ( args->af_tag ) { // Use an INFO tag provided by the user ret = bcf_get_info_float(args->hdr, line, args->af_tag, &args->AFs, &args->mAFs); - if ( ret==1 ) - *alt_freq = args->AFs[0]; + if ( ret>0 ) + alt_freq = args->AFs[ial-1]; if ( ret==-2 ) error("Type mismatch for INFO/%s tag at %s:%d\n", args->af_tag, bcf_seqname(args->hdr,line), line->pos+1); } else if ( args->af_fname ) { // Read AF from a file - ret = read_AF(args->files->targets, line, alt_freq); + ret = read_AF(args->files->targets, line, &alt_freq); + } + else if ( args->dflt_AF > 0 ) + { + alt_freq = args->dflt_AF; + } + else if ( args->estimate_AF ) + { + // Estimate AF from GTs or PLs of all samples or samples listed in a file + if ( args->af_from_PL ) + { + fmt_pl = get_PL(args, line); + if ( !fmt_pl ) return -1; + ret = estimate_AF_from_PL(args, fmt_pl, ial, &alt_freq); + } + else + { + GTs = get_GT(args, line); + if ( !GTs ) return -1; + ret = estimate_AF_from_GT(args, GTs, &alt_freq); + } } else { - // Use GTs or AC/AN: GTs when AC/AN not present or when GTs explicitly requested by --estimate-AF - ret = -1; - if ( !args->estimate_AF ) + // Use AC/AN + int AC = -1, AN = 0; + ret = bcf_get_info_int32(args->hdr, line, "AN", &args->itmp, &args->mitmp); + if ( ret==1 ) { - int AC = -1, AN = 0; - ret = bcf_get_info_int32(args->hdr, line, "AN", &args->itmp, &args->mitmp); - if ( ret==1 ) - { - AN = args->itmp[0]; - ret = bcf_get_info_int32(args->hdr, line, "AC", &args->itmp, &args->mitmp); - if ( ret>0 ) - AC = args->itmp[0]; - } - if ( AN<=0 || AC<0 ) - ret = -1; - else - *alt_freq = (double) AC/AN; + AN = args->itmp[0]; + ret = bcf_get_info_int32(args->hdr, line, "AC", &args->itmp, &args->mitmp); + if ( ret>0 ) + AC = args->itmp[0]; } - if ( ret==-1 ) - ret = estimate_AF(args, line, alt_freq); // reads GTs into args->itmp + if ( AN<=0 || AC<0 ) + ret = -1; + else + alt_freq = (double) AC/AN; } if ( ret<0 ) return ret; - if ( *alt_freq==0.0 ) - { - if ( args->dflt_AF==0 ) return -1; // we skip sites with AF=0 - *alt_freq = args->dflt_AF; - } + if ( alt_freq==0.0 ) return -1; - // Set P(D|G) + int irr = bcf_alleles2gt(0,0), ira = bcf_alleles2gt(0,ial), iaa = bcf_alleles2gt(ial,ial); if ( args->fake_PLs ) { - if ( !args->nitmp ) - { - args->nitmp = bcf_get_genotypes(args->hdr, line, &args->itmp, &args->mitmp); - if ( args->nitmp != 2*args->nsmpl ) return -1; // not diploid? - args->nitmp /= args->nsmpl; - } + if ( !GTs ) GTs = get_GT(args, line); + } + else + { + fmt_pl = get_PL(args, line); + if ( !fmt_pl ) return -1; + if ( iaa >= fmt_pl->n ) return -1; // not diploid or wrong number of fields + } - int32_t *gt = &args->itmp[args->ismpl*args->nitmp]; - if ( bcf_gt_is_missing(gt[0]) || bcf_gt_is_missing(gt[1]) ) return -1; + for (i=0; iroh_smpl->n; i++) + { + int ismpl = args->roh_smpl->idx[i]; - int a = bcf_gt_allele(gt[0]); - int b = bcf_gt_allele(gt[1]); - if ( a!=b ) - { - pdg[0] = pdg[2] = args->unseen_PL; - pdg[1] = 1 - 2*args->unseen_PL; - } - else if ( a==0 ) + // set P(D|G) + double pdg[3]; + if ( args->fake_PLs ) { - pdg[0] = 1 - 2*args->unseen_PL; - pdg[1] = pdg[2] = args->unseen_PL; + int8_t *gt = GTs + 2*ismpl; + if ( bcf_gt_is_missing(gt[0]) || bcf_gt_is_missing(gt[1]) ) continue; + + int a = bcf_gt_allele(gt[0]); + int b = bcf_gt_allele(gt[1]); + if ( a!=b ) + { + pdg[0] = pdg[2] = args->unseen_PL; + pdg[1] = 1 - 2*args->unseen_PL; + } + else if ( a==0 ) + { + pdg[0] = 1 - args->unseen_PL - args->unseen_PL*args->unseen_PL; + pdg[1] = args->unseen_PL; + pdg[2] = args->unseen_PL*args->unseen_PL; + } + else + { + pdg[0] = args->unseen_PL*args->unseen_PL; + pdg[1] = args->unseen_PL; + pdg[2] = 1 - args->unseen_PL - args->unseen_PL*args->unseen_PL; + } } else { - pdg[0] = pdg[1] = args->unseen_PL; - pdg[2] = 1 - 2*args->unseen_PL; + #define BRANCH(type_t) \ + { \ + type_t *p = (type_t*)fmt_pl->p + fmt_pl->n*ismpl; \ + if ( p[irr]<0 || p[ira]<0 || p[iaa]<0 ) continue; /* missing value */ \ + if ( p[irr]==p[ira] && p[irr]==p[iaa] ) continue; /* all values are the same */ \ + pdg[0] = p[irr] < (type_t)256 ? args->pl2p[ p[irr] ] : args->pl2p[255]; \ + pdg[1] = p[ira] < (type_t)256 ? args->pl2p[ p[ira] ] : args->pl2p[255]; \ + pdg[2] = p[iaa] < (type_t)256 ? args->pl2p[ p[iaa] ] : args->pl2p[255]; \ + } + switch (fmt_pl->type) { + case BCF_BT_INT8: BRANCH(int8_t); break; + case BCF_BT_INT16: BRANCH(int16_t); break; + case BCF_BT_INT32: BRANCH(int32_t); break; + default: fprintf(bcftools_stderr,"Unknown format type for PL: %s:%d .. fmt->type=%d\n", __FILE__,__LINE__, fmt_pl->type); exit(1); + } + #undef BRANCH } - } - else - { - args->nitmp = bcf_get_format_int32(args->hdr, line, "PL", &args->itmp, &args->mitmp); - if ( args->nitmp != args->nsmpl*line->n_allele*(line->n_allele+1)/2. ) return -1; // not diploid? - args->nitmp /= args->nsmpl; - - int32_t *pl = &args->itmp[args->ismpl*args->nitmp]; - pdg[0] = pl[0] < 256 ? args->pl2p[ pl[0] ] : 1.0; - pdg[1] = pl[1] < 256 ? args->pl2p[ pl[1] ] : 1.0; - pdg[2] = pl[2] < 256 ? args->pl2p[ pl[2] ] : 1.0; double sum = pdg[0] + pdg[1] + pdg[2]; - if ( !sum ) return -1; - pdg[0] /= sum; - pdg[1] /= sum; - pdg[2] /= sum; + if ( !sum ) continue; + for (j=0; j<3; j++) pdg[j] /= sum; + if ( args->skip_homref && pdg[0]>0.99 ) continue; + + smpl_t *smpl = &args->smpl[i]; + smpl->nused++; + + if ( smpl->nsites >= smpl->msites ) + { + hts_expand(uint32_t,smpl->nsites+1,smpl->msites,smpl->sites); + smpl->eprob = (double*) realloc(smpl->eprob,sizeof(*smpl->eprob)*smpl->msites*2); + if ( !smpl->eprob ) error("Error: failed to alloc %d bytes\n", sizeof(*smpl->eprob)*smpl->msites*2); + } + + // Calculate emission probabilities P(D|AZ) and P(D|HW) + double *eprob = &smpl->eprob[2*smpl->nsites]; + eprob[STATE_AZ] = pdg[0]*(1-alt_freq) + pdg[2]*alt_freq; + eprob[STATE_HW] = pdg[0]*(1-alt_freq)*(1-alt_freq) + 2*pdg[1]*(1-alt_freq)*alt_freq + pdg[2]*alt_freq*alt_freq; + + smpl->sites[smpl->nsites] = line->pos; + smpl->nsites++; + + if ( args->vi_training ) + { + if ( !smpl->nrid || line->rid!=smpl->rid[smpl->nrid-1] ) + { + smpl->nrid++; + smpl->rid = (int*) realloc(smpl->rid,sizeof(*smpl->rid)*smpl->nrid); + smpl->rid[smpl->nrid-1] = line->rid; + smpl->rid_off = (int*) realloc(smpl->rid_off,sizeof(*smpl->rid_off)*smpl->nrid); + smpl->rid_off[smpl->nrid-1] = smpl->nsites - 1; + } + } + else if ( args->nbuf_max && smpl->nsites >= args->nbuf_max ) flush_viterbi(args, i); } return 0; @@ -604,18 +964,35 @@ int parse_line(args_t *args, bcf1_t *line, double *alt_freq, double *pdg) static void vcfroh(args_t *args, bcf1_t *line) { + int i; + // Are we done? if ( !line ) { - flush_viterbi(args); + for (i=0; iroh_smpl->n; i++) flush_viterbi(args, i); return; } args->ntot++; - // Skip unwanted lines + // Skip unwanted lines, for simplicity we consider only biallelic sites if ( line->rid == args->skip_rid ) return; if ( line->n_allele==1 ) return; // no ALT allele - if ( line->n_allele!=2 ) return; // only biallelic sites + if ( line->n_allele > 3 ) return; // cannot be bi-allelic, even with <*> + + // This can be raw callable VCF with the symbolic unseen allele <*> + int ial = 0; + for (i=1; in_allele; i++) + if ( !strcmp("<*>",line->d.allele[i]) ) { ial = i; break; } + if ( ial==0 ) // normal VCF, the symbolic allele is not present + { + if ( line->n_allele!=2 ) return; // not biallelic + ial = 1; + } + else + { + if ( line->n_allele!=3 ) return; // not biallelic + ial = ial==1 ? 2 : 1; // <*> can come in any order + } if ( args->snps_only && !bcf_is_snp(line) ) return; // Initialize genetic map @@ -624,30 +1001,29 @@ static void vcfroh(args_t *args, bcf1_t *line) { args->prev_rid = line->rid; args->prev_pos = line->pos; - skip_rid = load_genmap(args, line); - if ( !skip_rid && args->vi_training ) push_rid(args, line->rid); + skip_rid = load_genmap(args, bcf_seqname(args->hdr,line)); } // New chromosome? if ( args->prev_rid!=line->rid ) { - skip_rid = load_genmap(args, line); - if ( args->vi_training ) - { - if ( !skip_rid ) push_rid(args, line->rid); - } - else + if ( !args->vi_training ) { - flush_viterbi(args); - args->nsites = 0; + for (i=0; iroh_smpl->n; i++) + { + flush_viterbi(args, i); + hmm_reset(args->hmm, args->smpl[i].snapshot); + } } args->prev_rid = line->rid; args->prev_pos = line->pos; + skip_rid = load_genmap(args, bcf_seqname(args->hdr,line)); } + else if ( args->prev_pos == line->pos ) return; // skip duplicate positions if ( skip_rid ) { - fprintf(pysam_stderr,"Skipping the sequence, no genmap for %s\n", bcf_seqname(args->hdr,line)); + fprintf(bcftools_stderr,"Skipping the sequence, no genmap for %s\n", bcf_seqname(args->hdr,line)); args->skip_rid = line->rid; return; } @@ -657,53 +1033,47 @@ static void vcfroh(args_t *args, bcf1_t *line) args->prev_pos = line->pos; - // Ready for the new site - int m = args->msites; - hts_expand(uint32_t,args->nsites+1,args->msites,args->sites); - if ( args->msites!=m ) - args->eprob = (double*) realloc(args->eprob,sizeof(double)*args->msites*2); - - // Set likelihoods and alternate allele frequencies - double alt_freq, pdg[3]; - if ( parse_line(args, line, &alt_freq, pdg)<0 ) return; // something went wrong - - args->nused++; - - // Calculate emission probabilities P(D|AZ) and P(D|HW) - double *eprob = &args->eprob[2*args->nsites]; - eprob[STATE_AZ] = pdg[0]*(1-alt_freq) + pdg[2]*alt_freq; - eprob[STATE_HW] = pdg[0]*(1-alt_freq)*(1-alt_freq) + 2*pdg[1]*(1-alt_freq)*alt_freq + pdg[2]*alt_freq*alt_freq; - - args->sites[args->nsites] = line->pos; - args->nsites++; + // parse the new line + process_line(args, line, ial); } static void usage(args_t *args) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: HMM model for detecting runs of autozygosity.\n"); - fprintf(pysam_stderr, "Usage: bcftools roh [options] \n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "General Options:\n"); - fprintf(pysam_stderr, " --AF-dflt if AF is not known, use this allele frequency [skip]\n"); - fprintf(pysam_stderr, " --AF-tag use TAG for allele frequency\n"); - fprintf(pysam_stderr, " --AF-file read allele frequencies from file (CHR\\tPOS\\tREF,ALT\\tAF)\n"); - fprintf(pysam_stderr, " -e, --estimate-AF calculate AC,AN counts on the fly, using either all samples (\"-\") or samples listed in \n"); - fprintf(pysam_stderr, " -G, --GTs-only use GTs, ignore PLs, use for PL of unseen genotypes. Safe value to use is 30 to account for GT errors.\n"); - fprintf(pysam_stderr, " -I, --skip-indels skip indels as their genotypes are enriched for errors\n"); - fprintf(pysam_stderr, " -m, --genetic-map genetic map in IMPUTE2 format, single file or mask, where string \"{CHROM}\" is replaced with chromosome name\n"); - fprintf(pysam_stderr, " -M, --rec-rate constant recombination rate per bp\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " -s, --sample sample to analyze\n"); - fprintf(pysam_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "HMM Options:\n"); - fprintf(pysam_stderr, " -a, --hw-to-az P(AZ|HW) transition probability from HW (Hardy-Weinberg) to AZ (autozygous) state [6.7e-8]\n"); - fprintf(pysam_stderr, " -H, --az-to-hw P(HW|AZ) transition probability from AZ to HW state [5e-9]\n"); - fprintf(pysam_stderr, " -V, --viterbi-training perform Viterbi training to estimate transition probabilities\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: HMM model for detecting runs of autozygosity.\n"); + fprintf(bcftools_stderr, "Usage: bcftools roh [options] \n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "General Options:\n"); + fprintf(bcftools_stderr, " --AF-dflt if AF is not known, use this allele frequency [skip]\n"); + fprintf(bcftools_stderr, " --AF-tag use TAG for allele frequency\n"); + fprintf(bcftools_stderr, " --AF-file read allele frequencies from file (CHR\\tPOS\\tREF,ALT\\tAF)\n"); + fprintf(bcftools_stderr, " -b --buffer-size buffer size and the number of overlapping sites, 0 for unlimited [0]\n"); + fprintf(bcftools_stderr, " If the first number is negative, it is interpreted as the maximum memory to\n"); + fprintf(bcftools_stderr, " use, in MB. The default overlap is set to roughly 1%% of the buffer size.\n"); + fprintf(bcftools_stderr, " -e, --estimate-AF [TAG], estimate AF from FORMAT/TAG (GT or PL) of all samples (\"-\") or samples listed\n"); + fprintf(bcftools_stderr, " in . If TAG is not given, the frequency is estimated from GT by default\n"); + fprintf(bcftools_stderr, " -G, --GTs-only use GTs and ignore PLs, instead using for PL of the two least likely genotypes.\n"); + fprintf(bcftools_stderr, " Safe value to use is 30 to account for GT errors.\n"); + fprintf(bcftools_stderr, " -i, --ignore-homref skip hom-ref genotypes (0/0)\n"); + fprintf(bcftools_stderr, " -I, --skip-indels skip indels as their genotypes are enriched for errors\n"); + fprintf(bcftools_stderr, " -m, --genetic-map genetic map in IMPUTE2 format, single file or mask, where string \"{CHROM}\"\n"); + fprintf(bcftools_stderr, " is replaced with chromosome name\n"); + fprintf(bcftools_stderr, " -M, --rec-rate constant recombination rate per bp\n"); + fprintf(bcftools_stderr, " -o, --output write output to a file [standard output]\n"); + fprintf(bcftools_stderr, " -O, --output-type [srz] output s:per-site, r:regions, z:compressed [sr]\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " -s, --samples list of samples to analyze [all samples]\n"); + fprintf(bcftools_stderr, " -S, --samples-file file of samples to analyze [all samples]\n"); + fprintf(bcftools_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " --threads number of extra decompression threads [0]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "HMM Options:\n"); + fprintf(bcftools_stderr, " -a, --hw-to-az P(AZ|HW) transition probability from HW (Hardy-Weinberg) to AZ (autozygous) state [6.7e-8]\n"); + fprintf(bcftools_stderr, " -H, --az-to-hw P(HW|AZ) transition probability from AZ to HW state [5e-9]\n"); + fprintf(bcftools_stderr, " -V, --viterbi-training estimate HMM parameters, is the convergence threshold, e.g. 1e-10 (experimental)\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } @@ -723,12 +1093,17 @@ int main_vcfroh(int argc, char *argv[]) {"AF-tag",1,0,0}, {"AF-file",1,0,1}, {"AF-dflt",1,0,2}, + {"buffer-size",1,0,'b'}, + {"ignore-homref",0,0,'i'}, {"estimate-AF",1,0,'e'}, + {"output",1,0,'o'}, + {"output-type",1,0,'O'}, {"GTs-only",1,0,'G'}, - {"sample",1,0,'s'}, + {"samples",1,0,'s'}, + {"samples-file",1,0,'S'}, {"hw-to-az",1,0,'a'}, {"az-to-hw",1,0,'H'}, - {"viterbi-training",0,0,'V'}, + {"viterbi-training",1,0,'V'}, {"targets",1,0,'t'}, {"targets-file",1,0,'T'}, {"regions",1,0,'r'}, @@ -736,12 +1111,13 @@ int main_vcfroh(int argc, char *argv[]) {"genetic-map",1,0,'m'}, {"rec-rate",1,0,'M'}, {"skip-indels",0,0,'I'}, + {"threads",1,0,9}, {0,0,0,0} }; int naf_opts = 0; char *tmp; - while ((c = getopt_long(argc, argv, "h?r:R:t:T:H:a:s:m:M:G:Ia:e:V",loptions,NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "h?r:R:t:T:H:a:s:S:m:M:G:Ia:e:V:b:O:o:i",loptions,NULL)) >= 0) { switch (c) { case 0: args->af_tag = optarg; naf_opts++; break; case 1: args->af_fname = optarg; naf_opts++; break; @@ -749,7 +1125,15 @@ int main_vcfroh(int argc, char *argv[]) args->dflt_AF = strtod(optarg,&tmp); if ( *tmp ) error("Could not parse: --AF-dflt %s\n", optarg); break; + case 'o': args->output_fname = optarg; break; + case 'O': + if ( strchr(optarg,'s') || strchr(optarg,'S') ) args->output_type |= OUTPUT_ST; + if ( strchr(optarg,'r') || strchr(optarg,'R') ) args->output_type |= OUTPUT_RG; + if ( strchr(optarg,'z') || strchr(optarg,'z') ) args->output_type |= OUTPUT_GZ; + break; case 'e': args->estimate_AF = optarg; naf_opts++; break; + case 'b': args->buffer_size = optarg; break; + case 'i': args->skip_homref = 1; break; case 'I': args->snps_only = 1; break; case 'G': args->fake_PLs = 1; @@ -762,7 +1146,8 @@ int main_vcfroh(int argc, char *argv[]) args->rec_rate = strtod(optarg,&tmp); if ( *tmp ) error("Could not parse: -M %s\n", optarg); break; - case 's': args->sample = strdup(optarg); break; + case 's': args->samples = strdup(optarg); break; + case 'S': args->samples = strdup(optarg); args->samples_is_file = 1; break; case 'a': args->t2AZ = strtod(optarg,&tmp); if ( *tmp ) error("Could not parse: -a %s\n", optarg); @@ -775,14 +1160,28 @@ int main_vcfroh(int argc, char *argv[]) case 'T': args->targets_list = optarg; targets_is_file = 1; break; case 'r': args->regions_list = optarg; break; case 'R': args->regions_list = optarg; regions_is_file = 1; break; - case 'V': args->vi_training = 1; break; + case 9 : args->n_threads = strtol(optarg, 0, 0); break; + case 'V': + args->vi_training = 1; + args->baum_welch_th = strtod(optarg,&tmp); + if ( *tmp ) error("Could not parse: --viterbi-training %s\n", optarg); + break; case 'h': case '?': usage(args); break; default: error("Unknown argument: %s\n", optarg); } } + if ( !args->output_fname ) args->output_fname = "bcftools_stdout"; + if ( !args->output_type ) args->output_type = OUTPUT_ST|OUTPUT_RG; + char *fname = NULL; + if ( optind==argc ) + { + if ( !isatty(fileno((FILE *)stdin)) ) fname = "-"; // reading from stdin + else usage(args); + } + else fname = argv[optind]; - if ( argcvi_training && args->buffer_size ) error("Error: cannot use -b with -V\n"); if ( args->t2AZ<0 || args->t2AZ>1 ) error("Error: The parameter --hw-to-az is not in [0,1]\n", args->t2AZ); if ( args->t2HW<0 || args->t2HW>1 ) error("Error: The parameter --az-to-hw is not in [0,1]\n", args->t2HW); if ( naf_opts>1 ) error("Error: The options --AF-tag, --AF-file and -e are mutually exclusive\n"); @@ -802,7 +1201,9 @@ int main_vcfroh(int argc, char *argv[]) if ( bcf_sr_set_targets(args->files, args->af_fname, 1, 3)<0 ) error("Failed to read the targets: %s\n", args->af_fname); } - if ( !bcf_sr_add_reader(args->files, argv[optind]) ) error("Failed to open %s: %s\n", argv[optind],bcf_sr_strerror(args->files->errnum)); + if ( args->n_threads && bcf_sr_set_threads(args->files, args->n_threads)<0) + error("Failed to create threads\n"); + if ( !bcf_sr_add_reader(args->files, fname) ) error("Failed to open %s: %s\n", fname,bcf_sr_strerror(args->files->errnum)); init_data(args); while ( bcf_sr_next_line(args->files) ) @@ -810,7 +1211,15 @@ int main_vcfroh(int argc, char *argv[]) vcfroh(args, args->files->readers[0].buffer[0]); } vcfroh(args, NULL); - fprintf(pysam_stderr,"Number of lines: total/processed: %d/%d\n", args->ntot,args->nused); + int i, nmin = 0; + for (i=0; iroh_smpl->n; i++) + if ( !i || args->smpl[i].nused < nmin ) nmin = args->smpl[i].nused; + fprintf(bcftools_stderr,"Number of lines total/processed: %d/%d\n", args->ntot,nmin); + if ( nmin==0 ) + { + fprintf(bcftools_stderr,"No usable sites were found."); + if ( !naf_opts && !args->dflt_AF ) fprintf(bcftools_stderr, " Consider using one of the AF options.\n"); + } destroy_data(args); free(args); return 0; diff --git a/bcftools/vcfsom.c b/bcftools/vcfsom.c index 03181e9b2..434dc1611 100644 --- a/bcftools/vcfsom.c +++ b/bcftools/vcfsom.c @@ -453,7 +453,7 @@ static void create_eval_plot(args_t *args) "import csv\n" "csv.register_dialect('tab', delimiter='\\t', quoting=csv.QUOTE_NONE)\n" "dat = []\n" - "with open('%s.eval', 'rb') as f:\n" + "with open('%s.eval', 'r') as f:\n" "\treader = csv.reader(f, 'tab')\n" "\tfor row in reader:\n" "\t\tif row[0][0]!='#': dat.append(row)\n" diff --git a/bcftools/vcfsom.c.pysam.c b/bcftools/vcfsom.c.pysam.c index 58875f664..092d37a58 100644 --- a/bcftools/vcfsom.c.pysam.c +++ b/bcftools/vcfsom.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfsom.c -- SOM (Self-Organizing Map) filtering. @@ -104,7 +104,7 @@ char *msprintf(const char *fmt, ...) /* * char *t, *p = str; * t = column_next(p, '\t'); - * if ( strlen("")==t-p && !strncmp(p,"",t-p) ) fprintf(pysam_stdout, "found!\n"); + * if ( strlen("")==t-p && !strncmp(p,"",t-p) ) fprintf(bcftools_stdout, "found!\n"); * * char *t; * t = column_next(str, '\t'); if ( !*t ) error("expected field\n", str); @@ -455,7 +455,7 @@ static void create_eval_plot(args_t *args) "import csv\n" "csv.register_dialect('tab', delimiter='\\t', quoting=csv.QUOTE_NONE)\n" "dat = []\n" - "with open('%s.eval', 'rb') as f:\n" + "with open('%s.eval', 'r') as f:\n" "\treader = csv.reader(f, 'tab')\n" "\tfor row in reader:\n" "\t\tif row[0][0]!='#': dat.append(row)\n" @@ -574,7 +574,7 @@ static void do_train(args_t *args) fprintf(fp,"%e\t%f\t%f\n", prev_score, (float)igood/ngood, (float)ibad/nbad); if ( !printed && (float)igood/ngood > 0.9 ) { - fprintf(pysam_stdout, "%.2f\t%.2f\t%e\t# %% of bad [1] and good [2] sites at a cutoff [3]\n", 100.*ibad/nbad,100.*igood/ngood,prev_score); + fprintf(bcftools_stdout, "%.2f\t%.2f\t%e\t# %% of bad [1] and good [2] sites at a cutoff [3]\n", 100.*ibad/nbad,100.*igood/ngood,prev_score); printed = 1; } @@ -582,7 +582,7 @@ static void do_train(args_t *args) else if ( igoodprefix,strerror(errno)); @@ -607,36 +607,36 @@ static void do_classify(args_t *args) case MERGE_MAX: score = get_max_score(args, -1); break; case MERGE_AVG: score = get_avg_score(args, -1); break; } - fprintf(pysam_stdout, "%e\n", 1.0 - score/max_score); + fprintf(bcftools_stdout, "%e\n", 1.0 - score/max_score); } annots_reader_close(args); } static void usage(void) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: SOM (Self-Organizing Map) filtering.\n"); - fprintf(pysam_stderr, "Usage: bcftools som --train [options] \n"); - fprintf(pysam_stderr, " bcftools som --classify [options]\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Model training options:\n"); - fprintf(pysam_stderr, " -f, --nfold n-fold cross-validation (number of maps) [5]\n"); - fprintf(pysam_stderr, " -p, --prefix prefix of output files\n"); - fprintf(pysam_stderr, " -s, --size map size [20]\n"); - fprintf(pysam_stderr, " -t, --train \n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Classifying options:\n"); - fprintf(pysam_stderr, " -c, --classify \n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Experimental training options (no reason to change):\n"); - fprintf(pysam_stderr, " -b, --bmu-threshold threshold for selection of best-matching unit [0.9]\n"); - fprintf(pysam_stderr, " -d, --som-dimension SOM dimension [2]\n"); - fprintf(pysam_stderr, " -e, --exclude-bad exclude bad sites from training, use for evaluation only\n"); - fprintf(pysam_stderr, " -l, --learning-rate learning rate [1.0]\n"); - fprintf(pysam_stderr, " -m, --merge -f merge algorithm [avg]\n"); - fprintf(pysam_stderr, " -n, --ntrain-sites effective number of training sites [number of good sites]\n"); - fprintf(pysam_stderr, " -r, --random-seed random seed, 0 for time() [1]\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: SOM (Self-Organizing Map) filtering.\n"); + fprintf(bcftools_stderr, "Usage: bcftools som --train [options] \n"); + fprintf(bcftools_stderr, " bcftools som --classify [options]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Model training options:\n"); + fprintf(bcftools_stderr, " -f, --nfold n-fold cross-validation (number of maps) [5]\n"); + fprintf(bcftools_stderr, " -p, --prefix prefix of output files\n"); + fprintf(bcftools_stderr, " -s, --size map size [20]\n"); + fprintf(bcftools_stderr, " -t, --train \n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Classifying options:\n"); + fprintf(bcftools_stderr, " -c, --classify \n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Experimental training options (no reason to change):\n"); + fprintf(bcftools_stderr, " -b, --bmu-threshold threshold for selection of best-matching unit [0.9]\n"); + fprintf(bcftools_stderr, " -d, --som-dimension SOM dimension [2]\n"); + fprintf(bcftools_stderr, " -e, --exclude-bad exclude bad sites from training, use for evaluation only\n"); + fprintf(bcftools_stderr, " -l, --learning-rate learning rate [1.0]\n"); + fprintf(bcftools_stderr, " -m, --merge -f merge algorithm [avg]\n"); + fprintf(bcftools_stderr, " -n, --ntrain-sites effective number of training sites [number of good sites]\n"); + fprintf(bcftools_stderr, " -r, --random-seed random seed, 0 for time() [1]\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } @@ -692,7 +692,7 @@ int main_vcfsom(int argc, char *argv[]) case 'd': args->ndim = atoi(optarg); if ( args->ndim<2 ) error("Expected -d >=2, got %d\n", args->ndim); - if ( args->ndim>3 ) fprintf(pysam_stderr,"Warning: This will take a long time and is not going to make the results better: -d %d\n", args->ndim); + if ( args->ndim>3 ) fprintf(bcftools_stderr,"Warning: This will take a long time and is not going to make the results better: -d %d\n", args->ndim); break; case 't': args->action = SOM_TRAIN; break; case 'c': args->action = SOM_CLASSIFY; break; diff --git a/bcftools/vcfsort.c b/bcftools/vcfsort.c new file mode 100644 index 000000000..e41b628c9 --- /dev/null +++ b/bcftools/vcfsort.c @@ -0,0 +1,306 @@ +/* vcfsort.c -- sort subcommand + + Copyright (C) 2017 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kheap.h" +#include "bcftools.h" + +typedef struct +{ + char *fname; + htsFile *fh; + bcf1_t *rec; +} +blk_t; + +typedef struct _args_t +{ + bcf_hdr_t *hdr; + char **argv, *fname, *output_fname, *tmp_dir; + int argc, output_type; + size_t max_mem, mem; + bcf1_t **buf; + size_t nbuf, mbuf, nblk; + blk_t *blk; +} +args_t; + +int cmp_bcf_pos(const void *aptr, const void *bptr) +{ + bcf1_t *a = *((bcf1_t**)aptr); + bcf1_t *b = *((bcf1_t**)bptr); + if ( a->rid < b->rid ) return -1; + if ( a->rid > b->rid ) return 1; + if ( a->pos < b->pos ) return -1; + if ( a->pos > b->pos ) return 1; + return 0; +} + +void buf_flush(args_t *args) +{ + if ( !args->nbuf ) return; + + qsort(args->buf, args->nbuf, sizeof(*args->buf), cmp_bcf_pos); + + args->nblk++; + args->blk = (blk_t*) realloc(args->blk, sizeof(blk_t)*args->nblk); + blk_t *blk = args->blk + args->nblk - 1; + + kstring_t str = {0,0,0}; + ksprintf(&str, "%s/%05d.bcf", args->tmp_dir, (int)args->nblk); + blk->fname = str.s; + + htsFile *fh = hts_open(blk->fname, "wbu"); + if ( fh == NULL ) error("Cannot write %s: %s\n", blk->fname, strerror(errno)); + bcf_hdr_write(fh, args->hdr); + + int i; + for (i=0; inbuf; i++) + { + bcf_write(fh, args->hdr, args->buf[i]); + bcf_destroy(args->buf[i]); + } + hts_close(fh); + + args->nbuf = 0; + args->mem = 0; +} + +void buf_push(args_t *args, bcf1_t *rec) +{ + int delta = sizeof(bcf1_t) + rec->shared.l + rec->indiv.l + sizeof(bcf1_t*); + if ( args->mem + delta > args->max_mem ) buf_flush(args); + args->nbuf++; + args->mem += delta; + hts_expand(bcf1_t*, args->nbuf, args->mbuf, args->buf); + args->buf[args->nbuf-1] = rec; +} + +void sort_blocks(args_t *args) +{ + htsFile *in = hts_open(args->fname, "r"); + if ( !in ) error("Could not read %s\n", args->fname); + args->hdr = bcf_hdr_read(in); + + while ( 1 ) + { + bcf1_t *rec = bcf_init(); + int ret = bcf_read1(in, args->hdr, rec); + if ( ret < -1 ) error("Error encountered while parsing the input\n"); + if ( ret == -1 ) + { + bcf_destroy(rec); + break; + } + buf_push(args, rec); + } + buf_flush(args); + free(args->buf); + + if ( hts_close(in)!=0 ) error("Close failed: %s\n", args->fname); +} + +static inline int blk_is_smaller(blk_t **aptr, blk_t **bptr) +{ + blk_t *a = *aptr; + blk_t *b = *bptr; + if ( a->rec->rid < b->rec->rid ) return 1; + if ( a->rec->rid > b->rec->rid ) return 0; + if ( a->rec->pos < b->rec->pos ) return 1; + return 0; +} +KHEAP_INIT(blk, blk_t*, blk_is_smaller) + +void blk_read(khp_blk_t *bhp, bcf_hdr_t *hdr, blk_t *blk) +{ + if ( !blk->fh ) return; + int ret = bcf_read(blk->fh, hdr, blk->rec); + if ( ret < -1 ) error("Error reading %s\n", blk->fname); + if ( ret == -1 ) + { + if ( hts_close(blk->fh)!=0 ) error("Close failed: %s\n", blk->fname); + blk->fh = 0; + return; + } + khp_insert(blk, bhp, &blk); +} + +void merge_blocks(args_t *args) +{ + fprintf(stderr,"Merging %d temporary files\n", (int)args->nblk); + + khp_blk_t *bhp = khp_init(blk); + + int i; + for (i=0; inblk; i++) + { + blk_t *blk = args->blk + i; + blk->fh = hts_open(blk->fname, "r"); + if ( !blk->fh ) error("Could not read %s: %s\n", blk->fname, strerror(errno)); + bcf_hdr_t *hdr = bcf_hdr_read(blk->fh); + bcf_hdr_destroy(hdr); + blk->rec = bcf_init(); + blk_read(bhp, args->hdr, blk); + } + + htsFile *out = hts_open(args->output_fname, hts_bcf_wmode(args->output_type)); + bcf_hdr_write(out, args->hdr); + while ( bhp->ndat ) + { + blk_t *blk = bhp->dat[0]; + bcf_write(out, args->hdr, blk->rec); + khp_delete(blk, bhp); + blk_read(bhp, args->hdr, blk); + } + if ( hts_close(out)!=0 ) error("Close failed: %s\n", args->output_fname); + + fprintf(stderr,"Cleaning\n"); + for (i=0; inblk; i++) + { + blk_t *blk = args->blk + i; + unlink(blk->fname); + free(blk->fname); + bcf_destroy(blk->rec); + } + rmdir(args->tmp_dir); + free(args->blk); + khp_destroy(blk, bhp); + fprintf(stderr,"Done\n"); +} + +static void usage(args_t *args) +{ + fprintf(stderr, "\n"); + fprintf(stderr, "About: Sort VCF/BCF file.\n"); + fprintf(stderr, "Usage: bcftools sort [OPTIONS] \n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Options:\n"); + fprintf(stderr, " -m, --max-mem [kMG] maximum memory to use [768M]\n"); // using metric units, 1M=1e6 + fprintf(stderr, " -o, --output-file output file name [stdout]\n"); + fprintf(stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); + fprintf(stderr, " -T, --temp-dir temporary files [/tmp/bcftools-sort.XXXXXX/]\n"); + fprintf(stderr, "\n"); + exit(1); +} + +size_t parse_mem_string(char *str) +{ + char *tmp; + double mem = strtod(str, &tmp); + if ( tmp==str ) error("Could not parse: --max-mem %s\n", str); + if ( !strcasecmp("k",tmp) ) mem *= 1000; + else if ( !strcasecmp("m",tmp) ) mem *= 1000*1000; + else if ( !strcasecmp("g",tmp) ) mem *= 1000*1000*1000; + return mem; +} + +void mkdir_p(const char *fmt, ...); +void init(args_t *args) +{ + if ( !args->tmp_dir ) + { + args->tmp_dir = strdup("/tmp/bcftools-sort.XXXXXX"); + char *tmp_dir = mkdtemp(args->tmp_dir); + if ( !tmp_dir ) error("mkdtemp(%s) failed: %s\n", args->tmp_dir,strerror(errno)); + } + else + { + args->tmp_dir = strdup(args->tmp_dir); + mkdir_p(args->tmp_dir); + } + fprintf(stderr,"Writing to %s\n", args->tmp_dir); +} +void destroy(args_t *args) +{ + bcf_hdr_destroy(args->hdr); + free(args->tmp_dir); + free(args); +} + +int main_sort(int argc, char *argv[]) +{ + int c; + args_t *args = (args_t*) calloc(1,sizeof(args_t)); + args->argc = argc; args->argv = argv; + args->max_mem = 768*1000*1000; + args->output_fname = "-"; + + static struct option loptions[] = + { + {"max-mem",required_argument,NULL,'m'}, + {"temp-dir",required_argument,NULL,'T'}, + {"output-type",required_argument,NULL,'O'}, + {"output-file",required_argument,NULL,'o'}, + {"help",no_argument,NULL,'h'}, + {0,0,0,0} + }; + while ((c = getopt_long(argc, argv, "m:T:O:o:h?",loptions,NULL)) >= 0) + { + switch (c) + { + case 'm': args->max_mem = parse_mem_string(optarg); break; + case 'T': args->tmp_dir = optarg; break; + case 'o': args->output_fname = optarg; break; + case 'O': + switch (optarg[0]) { + case 'b': args->output_type = FT_BCF_GZ; break; + case 'u': args->output_type = FT_BCF; break; + case 'z': args->output_type = FT_VCF_GZ; break; + case 'v': args->output_type = FT_VCF; break; + default: error("The output type \"%s\" not recognised\n", optarg); + }; + break; + case 'h': usage(args); + case '?': usage(args); + default: error("Unknown argument: %s\n", optarg); + } + } + + if ( optind>=argc ) + { + if ( !isatty(fileno((FILE *)stdin)) ) args->fname = "-"; // reading from stdin + else usage(args); + } + else args->fname = argv[optind]; + + init(args); + sort_blocks(args); + merge_blocks(args); + destroy(args); + + return 0; +} diff --git a/bcftools/vcfsort.c.pysam.c b/bcftools/vcfsort.c.pysam.c new file mode 100644 index 000000000..4a0325fcc --- /dev/null +++ b/bcftools/vcfsort.c.pysam.c @@ -0,0 +1,308 @@ +#include "bcftools.pysam.h" + +/* vcfsort.c -- sort subcommand + + Copyright (C) 2017 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kheap.h" +#include "bcftools.h" + +typedef struct +{ + char *fname; + htsFile *fh; + bcf1_t *rec; +} +blk_t; + +typedef struct _args_t +{ + bcf_hdr_t *hdr; + char **argv, *fname, *output_fname, *tmp_dir; + int argc, output_type; + size_t max_mem, mem; + bcf1_t **buf; + size_t nbuf, mbuf, nblk; + blk_t *blk; +} +args_t; + +int cmp_bcf_pos(const void *aptr, const void *bptr) +{ + bcf1_t *a = *((bcf1_t**)aptr); + bcf1_t *b = *((bcf1_t**)bptr); + if ( a->rid < b->rid ) return -1; + if ( a->rid > b->rid ) return 1; + if ( a->pos < b->pos ) return -1; + if ( a->pos > b->pos ) return 1; + return 0; +} + +void buf_flush(args_t *args) +{ + if ( !args->nbuf ) return; + + qsort(args->buf, args->nbuf, sizeof(*args->buf), cmp_bcf_pos); + + args->nblk++; + args->blk = (blk_t*) realloc(args->blk, sizeof(blk_t)*args->nblk); + blk_t *blk = args->blk + args->nblk - 1; + + kstring_t str = {0,0,0}; + ksprintf(&str, "%s/%05d.bcf", args->tmp_dir, (int)args->nblk); + blk->fname = str.s; + + htsFile *fh = hts_open(blk->fname, "wbu"); + if ( fh == NULL ) error("Cannot write %s: %s\n", blk->fname, strerror(errno)); + bcf_hdr_write(fh, args->hdr); + + int i; + for (i=0; inbuf; i++) + { + bcf_write(fh, args->hdr, args->buf[i]); + bcf_destroy(args->buf[i]); + } + hts_close(fh); + + args->nbuf = 0; + args->mem = 0; +} + +void buf_push(args_t *args, bcf1_t *rec) +{ + int delta = sizeof(bcf1_t) + rec->shared.l + rec->indiv.l + sizeof(bcf1_t*); + if ( args->mem + delta > args->max_mem ) buf_flush(args); + args->nbuf++; + args->mem += delta; + hts_expand(bcf1_t*, args->nbuf, args->mbuf, args->buf); + args->buf[args->nbuf-1] = rec; +} + +void sort_blocks(args_t *args) +{ + htsFile *in = hts_open(args->fname, "r"); + if ( !in ) error("Could not read %s\n", args->fname); + args->hdr = bcf_hdr_read(in); + + while ( 1 ) + { + bcf1_t *rec = bcf_init(); + int ret = bcf_read1(in, args->hdr, rec); + if ( ret < -1 ) error("Error encountered while parsing the input\n"); + if ( ret == -1 ) + { + bcf_destroy(rec); + break; + } + buf_push(args, rec); + } + buf_flush(args); + free(args->buf); + + if ( hts_close(in)!=0 ) error("Close failed: %s\n", args->fname); +} + +static inline int blk_is_smaller(blk_t **aptr, blk_t **bptr) +{ + blk_t *a = *aptr; + blk_t *b = *bptr; + if ( a->rec->rid < b->rec->rid ) return 1; + if ( a->rec->rid > b->rec->rid ) return 0; + if ( a->rec->pos < b->rec->pos ) return 1; + return 0; +} +KHEAP_INIT(blk, blk_t*, blk_is_smaller) + +void blk_read(khp_blk_t *bhp, bcf_hdr_t *hdr, blk_t *blk) +{ + if ( !blk->fh ) return; + int ret = bcf_read(blk->fh, hdr, blk->rec); + if ( ret < -1 ) error("Error reading %s\n", blk->fname); + if ( ret == -1 ) + { + if ( hts_close(blk->fh)!=0 ) error("Close failed: %s\n", blk->fname); + blk->fh = 0; + return; + } + khp_insert(blk, bhp, &blk); +} + +void merge_blocks(args_t *args) +{ + fprintf(bcftools_stderr,"Merging %d temporary files\n", (int)args->nblk); + + khp_blk_t *bhp = khp_init(blk); + + int i; + for (i=0; inblk; i++) + { + blk_t *blk = args->blk + i; + blk->fh = hts_open(blk->fname, "r"); + if ( !blk->fh ) error("Could not read %s: %s\n", blk->fname, strerror(errno)); + bcf_hdr_t *hdr = bcf_hdr_read(blk->fh); + bcf_hdr_destroy(hdr); + blk->rec = bcf_init(); + blk_read(bhp, args->hdr, blk); + } + + htsFile *out = hts_open(args->output_fname, hts_bcf_wmode(args->output_type)); + bcf_hdr_write(out, args->hdr); + while ( bhp->ndat ) + { + blk_t *blk = bhp->dat[0]; + bcf_write(out, args->hdr, blk->rec); + khp_delete(blk, bhp); + blk_read(bhp, args->hdr, blk); + } + if ( hts_close(out)!=0 ) error("Close failed: %s\n", args->output_fname); + + fprintf(bcftools_stderr,"Cleaning\n"); + for (i=0; inblk; i++) + { + blk_t *blk = args->blk + i; + unlink(blk->fname); + free(blk->fname); + bcf_destroy(blk->rec); + } + rmdir(args->tmp_dir); + free(args->blk); + khp_destroy(blk, bhp); + fprintf(bcftools_stderr,"Done\n"); +} + +static void usage(args_t *args) +{ + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Sort VCF/BCF file.\n"); + fprintf(bcftools_stderr, "Usage: bcftools sort [OPTIONS] \n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Options:\n"); + fprintf(bcftools_stderr, " -m, --max-mem [kMG] maximum memory to use [768M]\n"); // using metric units, 1M=1e6 + fprintf(bcftools_stderr, " -o, --output-file output file name [bcftools_stdout]\n"); + fprintf(bcftools_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); + fprintf(bcftools_stderr, " -T, --temp-dir temporary files [/tmp/bcftools-sort.XXXXXX/]\n"); + fprintf(bcftools_stderr, "\n"); + exit(1); +} + +size_t parse_mem_string(char *str) +{ + char *tmp; + double mem = strtod(str, &tmp); + if ( tmp==str ) error("Could not parse: --max-mem %s\n", str); + if ( !strcasecmp("k",tmp) ) mem *= 1000; + else if ( !strcasecmp("m",tmp) ) mem *= 1000*1000; + else if ( !strcasecmp("g",tmp) ) mem *= 1000*1000*1000; + return mem; +} + +void mkdir_p(const char *fmt, ...); +void init(args_t *args) +{ + if ( !args->tmp_dir ) + { + args->tmp_dir = strdup("/tmp/bcftools-sort.XXXXXX"); + char *tmp_dir = mkdtemp(args->tmp_dir); + if ( !tmp_dir ) error("mkdtemp(%s) failed: %s\n", args->tmp_dir,strerror(errno)); + } + else + { + args->tmp_dir = strdup(args->tmp_dir); + mkdir_p(args->tmp_dir); + } + fprintf(bcftools_stderr,"Writing to %s\n", args->tmp_dir); +} +void destroy(args_t *args) +{ + bcf_hdr_destroy(args->hdr); + free(args->tmp_dir); + free(args); +} + +int main_sort(int argc, char *argv[]) +{ + int c; + args_t *args = (args_t*) calloc(1,sizeof(args_t)); + args->argc = argc; args->argv = argv; + args->max_mem = 768*1000*1000; + args->output_fname = "-"; + + static struct option loptions[] = + { + {"max-mem",required_argument,NULL,'m'}, + {"temp-dir",required_argument,NULL,'T'}, + {"output-type",required_argument,NULL,'O'}, + {"output-file",required_argument,NULL,'o'}, + {"help",no_argument,NULL,'h'}, + {0,0,0,0} + }; + while ((c = getopt_long(argc, argv, "m:T:O:o:h?",loptions,NULL)) >= 0) + { + switch (c) + { + case 'm': args->max_mem = parse_mem_string(optarg); break; + case 'T': args->tmp_dir = optarg; break; + case 'o': args->output_fname = optarg; break; + case 'O': + switch (optarg[0]) { + case 'b': args->output_type = FT_BCF_GZ; break; + case 'u': args->output_type = FT_BCF; break; + case 'z': args->output_type = FT_VCF_GZ; break; + case 'v': args->output_type = FT_VCF; break; + default: error("The output type \"%s\" not recognised\n", optarg); + }; + break; + case 'h': usage(args); + case '?': usage(args); + default: error("Unknown argument: %s\n", optarg); + } + } + + if ( optind>=argc ) + { + if ( !isatty(fileno((FILE *)stdin)) ) args->fname = "-"; // reading from stdin + else usage(args); + } + else args->fname = argv[optind]; + + init(args); + sort_blocks(args); + merge_blocks(args); + destroy(args); + + return 0; +} diff --git a/bcftools/vcfstats.c b/bcftools/vcfstats.c index 1032bf87b..4f7765e39 100644 --- a/bcftools/vcfstats.c +++ b/bcftools/vcfstats.c @@ -1,6 +1,6 @@ /* vcfstats.c -- Produces stats which can be plotted using plot-vcfstats. - Copyright (C) 2012-2015 Genome Research Ltd. + Copyright (C) 2012-2017 Genome Research Ltd. Author: Petr Danecek @@ -39,6 +39,7 @@ THE SOFTWARE. */ #include #include "bcftools.h" #include "filter.h" +#include "bin.h" // Logic of the filters: include or exclude sites which match the filters? #define FLT_INCLUDE 1 @@ -67,17 +68,6 @@ typedef struct } idist_t; -typedef struct -{ - double x; - double x2; - double y; - double y2; - double xy; - double n; -} -smpl_r_t; - typedef struct { int n_snps, n_indels, n_mnps, n_others, n_mals, n_snp_mals, n_records, n_noalts; @@ -97,6 +87,7 @@ typedef struct int in_frame, out_frame, na_frame, in_frame_alt1, out_frame_alt1, na_frame_alt1; int subst[15]; int *smpl_hets, *smpl_homRR, *smpl_homAA, *smpl_ts, *smpl_tv, *smpl_indels, *smpl_ndp, *smpl_sngl; + int *smpl_hapRef, *smpl_hapAlt, *smpl_missing; int *smpl_indel_hets, *smpl_indel_homs; int *smpl_frm_shifts; // not-applicable, in-frame, out-frame unsigned long int *smpl_dp; @@ -108,9 +99,14 @@ stats_t; typedef struct { - uint64_t m[3], mm[3]; // number of hom, het and non-ref hom matches and mismatches - float r2sum; - uint32_t r2n; + uint64_t gt2gt[5][5]; // number of RR->RR, RR->RA, etc. matches/mismatches; see type2stats + /* + Pearson's R^2 is used for aggregate R^2 + y, yy .. sum of dosage and squared dosage in the query VCF (second file) + x, xx .. sum of squared dosage in the truth VCF (first file) + n .. number of genotypes + */ + double y, yy, x, xx, yx, n; } gtcmp_t; @@ -135,7 +131,11 @@ typedef struct int *tmp_iaf, ntmp_iaf, m_af, m_qual, naf_hwe, mtmp_frm; uint8_t *tmp_frm; int dp_min, dp_max, dp_step; - gtcmp_t *af_gts_snps, *af_gts_indels, *smpl_gts_snps, *smpl_gts_indels; // first bin of af_* stats are singletons + gtcmp_t *smpl_gts_snps, *smpl_gts_indels; + gtcmp_t *af_gts_snps, *af_gts_indels; // first bin of af_* stats are singletons + bin_t *af_bins; + float *farr; + int mfarr; // indel context indel_ctx_t *indel_ctx; @@ -148,21 +148,18 @@ typedef struct // other bcf_srs_t *files; bcf_sr_regions_t *exons; - char **argv, *exons_fname, *regions_list, *samples_list, *targets_list; + char **argv, *exons_fname, *regions_list, *samples_list, *targets_list, *af_bins_list, *af_tag; int argc, verbose_sites, first_allele_only, samples_is_file; int split_by_id, nstats; filter_t *filter[2]; char *filter_str; int filter_logic; // include or exclude sites which match the filters? One of FLT_INCLUDE/FLT_EXCLUDE - - // Per Sample r working data arrays of size equal to number of samples - smpl_r_t* smpl_r_snps; - smpl_r_t* smpl_r_indels; + int n_threads; } args_t; -static int type2dosage[6], type2ploidy[6], type2stats[6]; +static int type2dosage[6], type2ploidy[6], type2stats[7]; static void idist_init(idist_t *d, int min, int max, int step) { @@ -187,6 +184,12 @@ static inline int idist_i2bin(idist_t *d, int i) return i-1+d->min; } +static inline int clip_nonnegative(float x, int limit) +{ + if (x >= limit || isnan(x)) return limit - 1; + else if (x <= 0.0) return 0; + else return (int) x; +} #define IC_DBG 0 #if IC_DBG @@ -302,7 +305,7 @@ int indel_ctx_type(indel_ctx_t *ctx, char *chr, int pos, char *ref, char *alt, i // Sanity check: the reference sequence must match the REF allele for (i=0; ifilter[0] = filter_init(bcf_sr_get_header(args->files,0), args->filter_str); if ( args->files->nreaders==2 ) args->filter[1] = filter_init(bcf_sr_get_header(args->files,1), args->filter_str); + args->files->max_unpack |= filter_max_unpack(args->filter[0]); + } + + // AF corresponds to AC but is more robust to mixtures of haploid and diploid GTs + if ( !args->af_bins_list ) + { + args->m_af = 101; + for (i=0; ifiles->nreaders; i++) + if ( bcf_hdr_nsamples(args->files->readers[i].header) + 1> args->m_af ) + args->m_af = bcf_hdr_nsamples(args->files->readers[i].header) + 1; + } + else + { + args->af_bins = bin_init(args->af_bins_list,0,1); + + // m_af is used also for other af arrays, where the first bin is for + // singletons. However, since the last element is unused in af_bins + // (n boundaries form n-1 intervals), the m_af count is good for both. + args->m_af = bin_get_size(args->af_bins); } - // AF corresponds to AC but is more robust for mixture of haploid and diploid GTs - args->m_af = 101; - for (i=0; ifiles->nreaders; i++) - if ( bcf_hdr_nsamples(args->files->readers[i].header) + 1> args->m_af ) - args->m_af = bcf_hdr_nsamples(args->files->readers[i].header) + 1; + bcf_hdr_t *hdr = bcf_sr_get_header(args->files,0); + if ( args->af_tag && !bcf_hdr_idinfo_exists(hdr,BCF_HL_INFO,bcf_hdr_id2int(hdr,BCF_DT_ID,args->af_tag)) ) + error("No such INFO tag: %s\n", args->af_tag); #if QUAL_STATS args->m_qual = 999; @@ -430,8 +450,6 @@ static void init_stats(args_t *args) args->af_gts_indels = (gtcmp_t *) calloc(args->m_af,sizeof(gtcmp_t)); args->smpl_gts_snps = (gtcmp_t *) calloc(args->files->n_smpl,sizeof(gtcmp_t)); args->smpl_gts_indels = (gtcmp_t *) calloc(args->files->n_smpl,sizeof(gtcmp_t)); - args->smpl_r_snps = (smpl_r_t*) calloc(args->files->n_smpl, sizeof(smpl_r_t)); - args->smpl_r_indels = (smpl_r_t*) calloc(args->files->n_smpl, sizeof(smpl_r_t)); } for (i=0; instats; i++) { @@ -452,9 +470,12 @@ static void init_stats(args_t *args) #endif if ( args->files->n_smpl ) { + stats->smpl_missing = (int *) calloc(args->files->n_smpl,sizeof(int)); stats->smpl_hets = (int *) calloc(args->files->n_smpl,sizeof(int)); stats->smpl_homAA = (int *) calloc(args->files->n_smpl,sizeof(int)); stats->smpl_homRR = (int *) calloc(args->files->n_smpl,sizeof(int)); + stats->smpl_hapRef = (int *) calloc(args->files->n_smpl,sizeof(int)); + stats->smpl_hapAlt = (int *) calloc(args->files->n_smpl,sizeof(int)); stats->smpl_indel_hets = (int *) calloc(args->files->n_smpl,sizeof(int)); stats->smpl_indel_homs = (int *) calloc(args->files->n_smpl,sizeof(int)); stats->smpl_ts = (int *) calloc(args->files->n_smpl,sizeof(int)); @@ -503,9 +524,10 @@ static void init_stats(args_t *args) type2stats[GT_HOM_RR] = 0; type2stats[GT_HET_RA] = 1; type2stats[GT_HOM_AA] = 2; - type2stats[GT_HET_AA] = 1; + type2stats[GT_HET_AA] = 3; type2stats[GT_HAPL_R] = 0; type2stats[GT_HAPL_A] = 2; + type2stats[GT_UNKN] = 4; } static void destroy_stats(args_t *args) @@ -526,22 +548,24 @@ static void destroy_stats(args_t *args) if (stats->qual_indels) free(stats->qual_indels); #endif #if HWE_STATS - //if ( args->files->n_smpl ) free(stats->af_hwe); free(stats->af_hwe); #endif free(stats->insertions); free(stats->deletions); - if (stats->smpl_hets) free(stats->smpl_hets); - if (stats->smpl_homAA) free(stats->smpl_homAA); - if (stats->smpl_homRR) free(stats->smpl_homRR); - if (stats->smpl_indel_homs) free(stats->smpl_indel_homs); - if (stats->smpl_indel_hets) free(stats->smpl_indel_hets); - if (stats->smpl_ts) free(stats->smpl_ts); - if (stats->smpl_tv) free(stats->smpl_tv); - if (stats->smpl_indels) free(stats->smpl_indels); - if (stats->smpl_dp) free(stats->smpl_dp); - if (stats->smpl_ndp) free(stats->smpl_ndp); - if (stats->smpl_sngl) free(stats->smpl_sngl); + free(stats->smpl_missing); + free(stats->smpl_hets); + free(stats->smpl_homAA); + free(stats->smpl_homRR); + free(stats->smpl_hapRef); + free(stats->smpl_hapAlt); + free(stats->smpl_indel_homs); + free(stats->smpl_indel_hets); + free(stats->smpl_ts); + free(stats->smpl_tv); + free(stats->smpl_indels); + free(stats->smpl_dp); + free(stats->smpl_ndp); + free(stats->smpl_sngl); idist_destroy(&stats->dp); idist_destroy(&stats->dp_sites); for (j=0; jnusr; j++) @@ -554,6 +578,8 @@ static void destroy_stats(args_t *args) if ( args->exons ) free(stats->smpl_frm_shifts); } for (j=0; jnusr; j++) free(args->usr[j].tag); + if ( args->af_bins ) bin_destroy(args->af_bins); + free(args->farr); free(args->usr); free(args->tmp_frm); free(args->tmp_iaf); @@ -562,8 +588,6 @@ static void destroy_stats(args_t *args) free(args->af_gts_indels); free(args->smpl_gts_snps); free(args->smpl_gts_indels); - free(args->smpl_r_snps); - free(args->smpl_r_indels); if (args->indel_ctx) indel_ctx_destroy(args->indel_ctx); if (args->filter[0]) filter_destroy(args->filter[0]); if (args->filter[1]) filter_destroy(args->filter[1]); @@ -572,36 +596,59 @@ static void destroy_stats(args_t *args) static void init_iaf(args_t *args, bcf_sr_t *reader) { bcf1_t *line = reader->buffer[0]; - if ( args->ntmp_iaf < line->n_allele ) + hts_expand(int32_t,line->n_allele,args->ntmp_iaf,args->tmp_iaf); + + int i, ret; + if ( args->af_tag ) { - args->tmp_iaf = (int*)realloc(args->tmp_iaf, line->n_allele*sizeof(int)); - args->ntmp_iaf = line->n_allele; + ret = bcf_get_info_float(reader->header, line, args->af_tag, &args->farr, &args->mfarr); + if ( ret<=0 || ret!=line->n_allele-1 ) + { + // the AF tag is not present or wrong number of values, put in the singletons/unknown bin + for (i=0; in_allele; i++) args->tmp_iaf[i] = 0; + return; + } + args->tmp_iaf[0] = 0; + for (i=1; in_allele; i++) + { + float af = args->farr[i-1]; + if ( af<0 ) af = 0; + else if ( af>1 ) af = 1; + int iaf = args->af_bins ? bin_get_idx(args->af_bins,af) : af*(args->m_af-2); + args->tmp_iaf[i] = iaf + 1; // the first tmp_iaf bin is reserved for singletons + } + return; } + // tmp_iaf is first filled with AC counts in calc_ac and then transformed to // an index to af_gts_snps - int i, ret = bcf_calc_ac(reader->header, line, args->tmp_iaf, args->samples_list ? BCF_UN_INFO|BCF_UN_FMT : BCF_UN_INFO); - if ( ret ) + ret = bcf_calc_ac(reader->header, line, args->tmp_iaf, args->samples_list ? BCF_UN_INFO|BCF_UN_FMT : BCF_UN_INFO); + if ( !ret ) { - int an=0; - for (i=0; in_allele; i++) - an += args->tmp_iaf[i]; + for (i=0; in_allele; i++) args->tmp_iaf[i] = 0; // singletons/unknown bin + return; + } - args->tmp_iaf[0] = 0; - for (i=1; in_allele; i++) + int an = 0; + for (i=0; in_allele; i++) + an += args->tmp_iaf[i]; + + args->tmp_iaf[0] = 0; + for (i=1; in_allele; i++) + { + if ( args->tmp_iaf[i]==1 ) + args->tmp_iaf[i] = 0; // singletons into the first bin + else if ( !an ) + args->tmp_iaf[i] = 1; // no genotype at all, put to the AF=0 bin + else { - if ( args->tmp_iaf[i]==1 ) - args->tmp_iaf[i] = 0; // singletons into the first bin - else if ( !an ) - args->tmp_iaf[i] = 1; // no genotype at all, put to the AF=0 bin - else - args->tmp_iaf[i] = 1 + args->tmp_iaf[i] * (args->m_af-2.0) / an; + float af = (float) args->tmp_iaf[i] / an; + if ( af<0 ) af = 0; + else if ( af>1 ) af = 1; + int iaf = args->af_bins ? bin_get_idx(args->af_bins,af) : af*(args->m_af-2); + args->tmp_iaf[i] = iaf + 1; } } - else - for (i=0; in_allele; i++) - args->tmp_iaf[i] = 0; - - // todo: otherwise use AF } static inline void do_mnp_stats(args_t *args, stats_t *stats, bcf_sr_t *reader) @@ -621,7 +668,7 @@ static void do_indel_stats(args_t *args, stats_t *stats, bcf_sr_t *reader) bcf1_t *line = reader->buffer[0]; #if QUAL_STATS - int iqual = line->qual >= args->m_qual || isnan(line->qual) ? args->m_qual - 1 : line->qual; + int iqual = clip_nonnegative(line->qual, args->m_qual); stats->qual_indels[iqual]++; #endif @@ -756,7 +803,7 @@ static void do_snp_stats(args_t *args, stats_t *stats, bcf_sr_t *reader) if ( ref<0 ) return; #if QUAL_STATS - int iqual = line->qual >= args->m_qual || isnan(line->qual) ? args->m_qual - 1 : line->qual; + int iqual = clip_nonnegative(line->qual, args->m_qual); stats->qual_snps[iqual]++; #endif @@ -813,7 +860,11 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int { int ial, jal; int gt = bcf_gt_type(fmt_ptr, reader->samples[is], &ial, &jal); - if ( gt==GT_UNKN ) continue; + if ( gt==GT_UNKN ) + { + stats->smpl_missing[is]++; + continue; + } if ( gt==GT_HAPL_R || gt==GT_HAPL_A ) { if ( line_type&VCF_INDEL && stats->smpl_frm_shifts ) @@ -821,6 +872,8 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int assert( ialn_allele ); stats->smpl_frm_shifts[is*3 + args->tmp_frm[ial]]++; } + if ( gt == GT_HAPL_R ) stats->smpl_hapRef[is]++; + if ( gt == GT_HAPL_A ) stats->smpl_hapAlt[is]++; continue; } if ( gt != GT_HOM_RR ) { n_nref++; i_nref = is; } @@ -833,7 +886,10 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int case GT_HOM_AA: nalt_tot++; break; } #endif - if ( line_type&VCF_SNP || line_type==VCF_REF ) // count ALT=. as SNP + int var_type = 0; + if ( ial>0 ) var_type |= bcf_get_variant_type(line,ial); + if ( jal>0 ) var_type |= bcf_get_variant_type(line,jal); + if ( var_type&VCF_SNP || var_type==VCF_REF ) // count ALT=. as SNP { if ( gt == GT_HET_RA ) stats->smpl_hets[is]++; else if ( gt == GT_HET_AA ) stats->smpl_hets[is]++; @@ -849,7 +905,7 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int stats->smpl_tv[is]++; } } - if ( line_type&VCF_INDEL ) + if ( var_type&VCF_INDEL ) { if ( gt != GT_HOM_RR ) { @@ -873,6 +929,7 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int { float het_frac = (float)nhet_tot/(nhet_tot + nref_tot + nalt_tot); int idx = het_frac*(args->naf_hwe - 1); +//check me: what is this? if ( line->n_allele>1 ) idx += args->naf_hwe*args->tmp_iaf[1]; stats->af_hwe[idx]++; } @@ -911,88 +968,42 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int fmt1 = bcf_get_fmt(files->readers[1].header,files->readers[1].buffer[0],"GT"); if ( !fmt1 ) return; // only the first ALT allele is considered - int iaf = line->n_allele>1 ? args->tmp_iaf[1] : 1; + int iaf = args->tmp_iaf[1]; int line_type = bcf_get_variant_types(files->readers[0].buffer[0]); gtcmp_t *af_stats = line_type&VCF_SNP ? args->af_gts_snps : args->af_gts_indels; gtcmp_t *smpl_stats = line_type&VCF_SNP ? args->smpl_gts_snps : args->smpl_gts_indels; - // - // Calculates r squared - // x is mean dosage of x at given site - // x2 is mean squared dosage of x at given site - // y is mean dosage of x at given site - // y2 is mean squared dosage of x at given site - // xy is mean dosage of x*y at given site - // r2sum += (xy - x*y)^2 / ( (x2 - x^2) * (y2 - y^2) ) - // r2n is number of sites considered - // output as r2sum/r2n for each AF bin - int r2n = 0; - float x = 0, y = 0, xy = 0, x2 = 0, y2 = 0; - // Select smpl_r - smpl_r_t *smpl_r = NULL; - if (line_type&VCF_SNP) - { - smpl_r = args->smpl_r_snps; - } - else if (line_type&VCF_INDEL) - { - smpl_r = args->smpl_r_indels; - } for (is=0; isn_smpl; is++) { // Simplified comparison: only 0/0, 0/1, 1/1 is looked at as the identity of // actual alleles can be enforced by running without the -c option. int gt0 = bcf_gt_type(fmt0, files->readers[0].samples[is], NULL, NULL); - if ( gt0 == GT_UNKN ) continue; - int gt1 = bcf_gt_type(fmt1, files->readers[1].samples[is], NULL, NULL); - if ( gt1 == GT_UNKN ) continue; - - if ( type2ploidy[gt0]*type2ploidy[gt1] == -1 ) continue; // cannot compare diploid and haploid genotypes - - int dsg0 = type2dosage[gt0]; - int dsg1 = type2dosage[gt1]; - x += dsg0; - x2 += dsg0*dsg0; - y += dsg1; - y2 += dsg1*dsg1; - xy += dsg0*dsg1; - r2n++; - - int idx = type2stats[gt0]; - if ( gt0==gt1 ) - { - af_stats[iaf].m[idx]++; - smpl_stats[is].m[idx]++; - } - else - { - af_stats[iaf].mm[idx]++; - smpl_stats[is].mm[idx]++; - } - // Now do it across samples + int idx0 = type2stats[gt0]; + int idx1 = type2stats[gt1]; + af_stats[iaf].gt2gt[idx0][idx1]++; + smpl_stats[is].gt2gt[idx0][idx1]++; - if (smpl_r) { - smpl_r[is].xy += dsg0*dsg1; - smpl_r[is].x += dsg0; - smpl_r[is].x2 += dsg0*dsg0; - smpl_r[is].y += dsg1; - smpl_r[is].y2 += dsg1*dsg1; - ++(smpl_r[is].n); - } - } + if ( gt0 == GT_UNKN || gt1 == GT_UNKN ) continue; + if ( type2ploidy[gt0]*type2ploidy[gt1] == -1 ) continue; // cannot compare diploid and haploid genotypes - if ( r2n ) - { - x /= r2n; y /= r2n; x2 /= r2n; y2 /= r2n; xy /= r2n; - float cov = xy - x*y; - float var2 = (x2 - x*x) * (y2 - y*y); - if ( var2!=0 ) - { - af_stats[iaf].r2sum += cov*cov/var2; - af_stats[iaf].r2n++; - } + float y = type2dosage[gt0]; + float x = type2dosage[gt1]; + + smpl_stats[is].yx += y*x; + smpl_stats[is].x += x; + smpl_stats[is].xx += x*x; + smpl_stats[is].y += y; + smpl_stats[is].yy += y*y; + smpl_stats[is].n += 1; + + af_stats[iaf].yx += y*x; + af_stats[iaf].x += x; + af_stats[iaf].xx += x*x; + af_stats[iaf].y += y; + af_stats[iaf].yy += y*y; + af_stats[iaf].n += 1; } if ( args->verbose_sites ) @@ -1073,7 +1084,7 @@ static void do_vcf_stats(args_t *args) if ( line->n_allele>2 ) { stats->n_mals++; - if ( line_type == VCF_SNP ) stats->n_snp_mals++; + if ( line_type == VCF_SNP ) stats->n_snp_mals++; // note: this will be fooled by C>C,T } if ( files->n_smpl ) @@ -1129,8 +1140,23 @@ static void print_header(args_t *args) #define T2S(x) type2stats[x] static void print_stats(args_t *args) { - int i, id; - printf("# SN, Summary numbers:\n# SN\t[2]id\t[3]key\t[4]value\n"); + int i, j,k, id; + printf("# SN, Summary numbers:\n"); + printf("# number of records .. number of data rows in the VCF\n"); + printf("# number of no-ALTs .. reference-only sites, ALT is either \".\" or identical to REF\n"); + printf("# number of SNPs .. number of rows with a SNP\n"); + printf("# number of MNPs .. number of rows with a MNP, such as CC>TT\n"); + printf("# number of indels .. number of rows with an indel\n"); + printf("# number of others .. number of rows with other type, for example a symbolic allele or\n"); + printf("# a complex substitution, such as ACT>TCGA\n"); + printf("# number of multiallelic sites .. number of rows with multiple alternate alleles\n"); + printf("# number of multiallelic SNP sites .. number of rows with multiple alternate alleles, all SNPs\n"); + printf("# \n"); + printf("# Note that rows containing multiple types will be counted multiple times, in each\n"); + printf("# counter. For example, a row with a SNP and an indel increments both the SNP and\n"); + printf("# the indel counter.\n"); + printf("# \n"); + printf("# SN\t[2]id\t[3]key\t[4]value\n"); for (id=0; idfiles->nreaders; id++) printf("SN\t%d\tnumber of samples:\t%d\n", id, bcf_hdr_nsamples(args->files->readers[id].header)); for (id=0; idnstats; id++) @@ -1202,6 +1228,24 @@ static void print_stats(args_t *args) stats->af_repeats[1][1] += stats->af_repeats[1][0]; stats->af_repeats[2][1] += stats->af_repeats[2][0]; } + // move the singletons stats into the first AF bin, singleton stats was collected separately because of init_iaf + if ( args->af_gts_snps ) + { + args->af_gts_snps[1].y += args->af_gts_snps[0].y; + args->af_gts_snps[1].yy += args->af_gts_snps[0].yy; + args->af_gts_snps[1].xx += args->af_gts_snps[0].xx; + args->af_gts_snps[1].yx += args->af_gts_snps[0].yx; + args->af_gts_snps[1].n += args->af_gts_snps[0].n; + } + if ( args->af_gts_indels ) + { + args->af_gts_indels[1].y += args->af_gts_indels[0].y; + args->af_gts_indels[1].yy += args->af_gts_indels[0].yy; + args->af_gts_indels[1].xx += args->af_gts_indels[0].xx; + args->af_gts_indels[1].yx += args->af_gts_indels[0].yx; + args->af_gts_indels[1].n += args->af_gts_indels[0].n; + } + printf("# AF, Stats by non-reference allele frequency:\n# AF\t[2]id\t[3]allele frequency\t[4]number of SNPs\t[5]number of transitions\t[6]number of transversions\t[7]number of indels\t[8]repeat-consistent\t[9]repeat-inconsistent\t[10]not applicable\n"); for (id=0; idnstats; id++) { @@ -1209,7 +1253,8 @@ static void print_stats(args_t *args) for (i=1; im_af; i++) // note that af[1] now contains also af[0], see SiS stats output above { if ( stats->af_snps[i]+stats->af_ts[i]+stats->af_tv[i]+stats->af_repeats[0][i]+stats->af_repeats[1][i]+stats->af_repeats[2][i] == 0 ) continue; - printf("AF\t%d\t%f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", id,100.*(i-1)/(args->m_af-1),stats->af_snps[i],stats->af_ts[i],stats->af_tv[i], + double af = args->af_bins ? (bin_get_value(args->af_bins,i)+bin_get_value(args->af_bins,i-1))*0.5 : (double)(i-1)/(args->m_af-1); + printf("AF\t%d\t%f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", id,af,stats->af_snps[i],stats->af_ts[i],stats->af_tv[i], stats->af_repeats[0][i]+stats->af_repeats[1][i]+stats->af_repeats[2][i],stats->af_repeats[0][i],stats->af_repeats[1][i],stats->af_repeats[2][i]); } } @@ -1266,34 +1311,56 @@ static void print_stats(args_t *args) printf("SN\t%d\tnumber of samples:\t%d\n", 2, args->files->n_smpl); int x; - for (x=0; x<2; x++) + for (x=0; x<2; x++) // x=0: snps, x=1: indels { gtcmp_t *stats; if ( x==0 ) { - printf("# GCsAF, Genotype concordance by non-reference allele frequency (SNPs)\n# GCsAF\t[2]id\t[3]allele frequency\t[4]RR Hom matches\t[5]RA Het matches\t[6]AA Hom matches\t[7]RR Hom mismatches\t[8]RA Het mismatches\t[9]AA Hom mismatches\t[10]dosage r-squared\t[11]number of sites\n"); + printf("# GCsAF, Genotype concordance by non-reference allele frequency (SNPs)\n# GCsAF\t[2]id\t[3]allele frequency\t[4]RR Hom matches\t[5]RA Het matches\t[6]AA Hom matches\t[7]RR Hom mismatches\t[8]RA Het mismatches\t[9]AA Hom mismatches\t[10]dosage r-squared\t[11]number of genotypes\n"); stats = args->af_gts_snps; } else { - printf("# GCiAF, Genotype concordance by non-reference allele frequency (indels)\n# GCiAF\t[2]id\t[3]allele frequency\t[4]RR Hom matches\t[5]RA Het matches\t[6]AA Hom matches\t[7]RR Hom mismatches\t[8]RA Het mismatches\t[9]AA Hom mismatches\t[10]dosage r-squared\t[11]number of sites\n"); + printf("# GCiAF, Genotype concordance by non-reference allele frequency (indels)\n# GCiAF\t[2]id\t[3]allele frequency\t[4]RR Hom matches\t[5]RA Het matches\t[6]AA Hom matches\t[7]RR Hom mismatches\t[8]RA Het mismatches\t[9]AA Hom mismatches\t[10]dosage r-squared\t[11]number of genotypes\n"); stats = args->af_gts_indels; } - uint64_t nrd_m[3] = {0,0,0}, nrd_mm[3] = {0,0,0}; + uint64_t nrd_m[4] = {0,0,0,0}, nrd_mm[4] = {0,0,0,0}; // across all bins for (i=0; im_af; i++) { - int j, n = 0; - for (j=0; j<3; j++) + int n = 0; + uint64_t m[4] = {0,0,0,0}, mm[4] = {0,0,0,0}; // in i-th AF bin + for (j=0; j<4; j++) // rr, ra, aa hom, aa het, ./. + for (k=0; k<4; k++) + { + n += stats[i].gt2gt[j][k]; + if ( j==k ) + { + nrd_m[j] += stats[i].gt2gt[j][k]; + m[j] += stats[i].gt2gt[j][k]; + } + else + { + nrd_mm[j] += stats[i].gt2gt[j][k]; + mm[j] += stats[i].gt2gt[j][k]; + } + } + if ( !i || !n ) continue; // skip singleton stats and empty bins + + // Pearson's r2 + double r2 = 0; + if ( stats[i].n ) { - n += stats[i].m[j] + stats[i].mm[j]; - nrd_m[j] += stats[i].m[j]; - nrd_mm[j] += stats[i].mm[j]; + r2 = (stats[i].yx - stats[i].x*stats[i].y/stats[i].n); + r2 /= sqrt((stats[i].xx - stats[i].x*stats[i].x/stats[i].n) * (stats[i].yy - stats[i].y*stats[i].y/stats[i].n)); + r2 *= r2; } - if ( !i || !n ) continue; // skip singleton stats and empty bins - printf("GC%cAF\t2\t%f", x==0 ? 's' : 'i', 100.*(i-1)/(args->m_af-1)); - printf("\t%"PRId64"\t%"PRId64"\t%"PRId64"", stats[i].m[T2S(GT_HOM_RR)],stats[i].m[T2S(GT_HET_RA)],stats[i].m[T2S(GT_HOM_AA)]); - printf("\t%"PRId64"\t%"PRId64"\t%"PRId64"", stats[i].mm[T2S(GT_HOM_RR)],stats[i].mm[T2S(GT_HET_RA)],stats[i].mm[T2S(GT_HOM_AA)]); - printf("\t%f\t%"PRId32"\n", stats[i].r2n ? stats[i].r2sum/stats[i].r2n : -1.0, stats[i].r2n); + double af = args->af_bins ? (bin_get_value(args->af_bins,i)+bin_get_value(args->af_bins,i-1))*0.5 : (double)(i-1)/(args->m_af-1); + printf("GC%cAF\t2\t%f", x==0 ? 's' : 'i', af); + printf("\t%"PRId64"\t%"PRId64"\t%"PRId64"", m[T2S(GT_HOM_RR)],m[T2S(GT_HET_RA)],m[T2S(GT_HOM_AA)]); + printf("\t%"PRId64"\t%"PRId64"\t%"PRId64"", mm[T2S(GT_HOM_RR)],mm[T2S(GT_HET_RA)],mm[T2S(GT_HOM_AA)]); + if ( stats[i].n && !isnan(r2) ) printf("\t%f", r2); + else printf("\t"NA_STRING); + printf("\t%.0f\n", stats[i].n); } if ( x==0 ) @@ -1309,8 +1376,8 @@ static void print_stats(args_t *args) } else printf("# Non-Reference Discordance (NRD), indels\n# NRDi\t[2]id\t[3]NRD\t[4]Ref/Ref discordance\t[5]Ref/Alt discordance\t[6]Alt/Alt discordance\n"); - uint64_t m = nrd_m[T2S(GT_HET_RA)] + nrd_m[T2S(GT_HOM_AA)]; - uint64_t mm = nrd_mm[T2S(GT_HOM_RR)] + nrd_mm[T2S(GT_HET_RA)] + nrd_mm[T2S(GT_HOM_AA)]; + uint64_t m = nrd_m[T2S(GT_HET_RA)] + nrd_m[T2S(GT_HOM_AA)] + nrd_m[T2S(GT_HET_AA)]; + uint64_t mm = nrd_mm[T2S(GT_HOM_RR)] + nrd_mm[T2S(GT_HET_RA)] + nrd_mm[T2S(GT_HOM_AA)] + nrd_mm[T2S(GT_HET_AA)]; printf("NRD%c\t2\t%f\t%f\t%f\t%f\n", x==0 ? 's' : 'i', m+mm ? mm*100.0/(m+mm) : 0, nrd_m[T2S(GT_HOM_RR)]+nrd_mm[T2S(GT_HOM_RR)] ? nrd_mm[T2S(GT_HOM_RR)]*100.0/(nrd_m[T2S(GT_HOM_RR)]+nrd_mm[T2S(GT_HOM_RR)]) : 0, @@ -1319,42 +1386,99 @@ static void print_stats(args_t *args) ); } - for (x=0; x<2; x++) + for (x=0; x<2; x++) // x=0: snps, x=1: indels { gtcmp_t *stats; - smpl_r_t *smpl_r_array; if ( x==0 ) { printf("# GCsS, Genotype concordance by sample (SNPs)\n# GCsS\t[2]id\t[3]sample\t[4]non-reference discordance rate\t[5]RR Hom matches\t[6]RA Het matches\t[7]AA Hom matches\t[8]RR Hom mismatches\t[9]RA Het mismatches\t[10]AA Hom mismatches\t[11]dosage r-squared\n"); stats = args->smpl_gts_snps; - smpl_r_array = args->smpl_r_snps; } else { printf("# GCiS, Genotype concordance by sample (indels)\n# GCiS\t[2]id\t[3]sample\t[4]non-reference discordance rate\t[5]RR Hom matches\t[6]RA Het matches\t[7]AA Hom matches\t[8]RR Hom mismatches\t[9]RA Het mismatches\t[10]AA Hom mismatches\t[11]dosage r-squared\n"); stats = args->smpl_gts_indels; - smpl_r_array = args->smpl_r_indels; } for (i=0; ifiles->n_smpl; i++) { - uint64_t m = stats[i].m[T2S(GT_HET_RA)] + stats[i].m[T2S(GT_HOM_AA)]; - uint64_t mm = stats[i].mm[T2S(GT_HOM_RR)] + stats[i].mm[T2S(GT_HET_RA)] + stats[i].mm[T2S(GT_HOM_AA)]; - // Calculate r by formula 19.2 - Biostatistical Analysis 4th edition - Jerrold H. Zar - smpl_r_t *smpl_r = smpl_r_array + i; - double r = 0.0; - if (smpl_r->n) { - double sum_crossprod = smpl_r->xy-(smpl_r->x*smpl_r->y)/smpl_r->n;//per 17.3 machine formula - double x2_xx = smpl_r->x2-(smpl_r->x*smpl_r->x)/smpl_r->n; - double y2_yy = smpl_r->y2-(smpl_r->y*smpl_r->y)/smpl_r->n; - r = (sum_crossprod)/sqrt(x2_xx*y2_yy); + uint64_t mm = 0, m = stats[i].gt2gt[T2S(GT_HET_RA)][T2S(GT_HET_RA)] + stats[i].gt2gt[T2S(GT_HOM_AA)][T2S(GT_HOM_AA)]; + for (j=0; j<3; j++) + for (k=0; k<3; k++) + if ( j!=k ) mm += stats[i].gt2gt[j][k]; + + // Pearson's r2 + double r2 = 0; + if ( stats[i].n ) + { + r2 = (stats[i].yx - stats[i].x*stats[i].y/stats[i].n); + r2 /= sqrt((stats[i].xx - stats[i].x*stats[i].x/stats[i].n) * (stats[i].yy - stats[i].y*stats[i].y/stats[i].n)); + r2 *= r2; } printf("GC%cS\t2\t%s\t%.3f", x==0 ? 's' : 'i', args->files->samples[i], m+mm ? mm*100.0/(m+mm) : 0); - printf("\t%"PRId64"\t%"PRId64"\t%"PRId64"", stats[i].m[T2S(GT_HOM_RR)],stats[i].m[T2S(GT_HET_RA)],stats[i].m[T2S(GT_HOM_AA)]); - printf("\t%"PRId64"\t%"PRId64"\t%"PRId64"", stats[i].mm[T2S(GT_HOM_RR)],stats[i].mm[T2S(GT_HET_RA)],stats[i].mm[T2S(GT_HOM_AA)]); - if (smpl_r->n && !isnan(r)) printf("\t%f\n", r*r); + printf("\t%"PRId64"\t%"PRId64"\t%"PRId64"", + stats[i].gt2gt[T2S(GT_HOM_RR)][T2S(GT_HOM_RR)], + stats[i].gt2gt[T2S(GT_HET_RA)][T2S(GT_HET_RA)], + stats[i].gt2gt[T2S(GT_HOM_AA)][T2S(GT_HOM_AA)]); + printf("\t%"PRId64"\t%"PRId64"\t%"PRId64"", + stats[i].gt2gt[T2S(GT_HOM_RR)][T2S(GT_HET_RA)] + stats[i].gt2gt[T2S(GT_HOM_RR)][T2S(GT_HOM_AA)], + stats[i].gt2gt[T2S(GT_HET_RA)][T2S(GT_HOM_RR)] + stats[i].gt2gt[T2S(GT_HET_RA)][T2S(GT_HOM_AA)], + stats[i].gt2gt[T2S(GT_HOM_AA)][T2S(GT_HOM_RR)] + stats[i].gt2gt[T2S(GT_HOM_AA)][T2S(GT_HET_RA)]); + if ( stats[i].n && !isnan(r2) ) printf("\t%f\n", r2); else printf("\t"NA_STRING"\n"); } } + for (x=0; x<2; x++) // x=0: snps, x=1: indels + { + //printf("# GCiS, Genotype concordance by sample (indels)\n# GCiS\t[2]id\t[3]sample\t[4]non-reference discordance rate\t[5]RR Hom matches\t[6]RA Het matches\t[7]AA Hom matches\t[8]RR Hom mismatches\t[9]RA Het mismatches\t[10]AA Hom mismatches\t[11]dosage r-squared\n"); + + gtcmp_t *stats; + if ( x==0 ) + { + printf("# GCTs, Genotype concordance table (SNPs)\n# GCTs"); + stats = args->smpl_gts_snps; + } + else + { + printf("# GCTi, Genotype concordance table (indels)\n# GCTi"); + stats = args->smpl_gts_indels; + } + i = 1; + printf("\t[%d]sample", ++i); + printf("\t[%d]RR Hom -> RR Hom", ++i); + printf("\t[%d]RR Hom -> RA Het", ++i); + printf("\t[%d]RR Hom -> AA Hom", ++i); + printf("\t[%d]RR Hom -> AA Het", ++i); + printf("\t[%d]RR Hom -> missing", ++i); + printf("\t[%d]RA Het -> RR Hom", ++i); + printf("\t[%d]RA Het -> RA Het", ++i); + printf("\t[%d]RA Het -> AA Hom", ++i); + printf("\t[%d]RA Het -> AA Het", ++i); + printf("\t[%d]RA Het -> missing", ++i); + printf("\t[%d]AA Hom -> RR Hom", ++i); + printf("\t[%d]AA Hom -> RA Het", ++i); + printf("\t[%d]AA Hom -> AA Hom", ++i); + printf("\t[%d]AA Hom -> AA Het", ++i); + printf("\t[%d]AA Hom -> missing", ++i); + printf("\t[%d]AA Het -> RR Hom", ++i); + printf("\t[%d]AA Het -> RA Het", ++i); + printf("\t[%d]AA Het -> AA Hom", ++i); + printf("\t[%d]AA Het -> AA Het", ++i); + printf("\t[%d]AA Het -> missing", ++i); + printf("\t[%d]missing -> RR Hom", ++i); + printf("\t[%d]missing -> RA Het", ++i); + printf("\t[%d]missing -> AA Hom", ++i); + printf("\t[%d]missing -> AA Het", ++i); + printf("\t[%d]missing -> missing\n", ++i); + + for (i=0; ifiles->n_smpl; i++) + { + printf("GCT%c\t%s", x==0 ? 's' : 'i', args->files->samples[i]); + for (j=0; j<5; j++) + for (k=0; k<5; k++) + printf("\t%"PRId64, stats[i].gt2gt[j][k]); + printf("\n"); + } + } } printf("# DP, Depth distribution\n# DP\t[2]id\t[3]bin\t[4]number of genotypes\t[5]fraction of genotypes (%%)\t[6]number of sites\t[7]fraction of sites (%%)\n"); @@ -1377,16 +1501,19 @@ static void print_stats(args_t *args) if ( args->files->n_smpl ) { - printf("# PSC, Per-sample counts\n# PSC\t[2]id\t[3]sample\t[4]nRefHom\t[5]nNonRefHom\t[6]nHets\t[7]nTransitions\t[8]nTransversions\t[9]nIndels\t[10]average depth\t[11]nSingletons\n"); + printf("# PSC, Per-sample counts. Note that the ref/het/hom counts include only SNPs, for indels see PSI. The rest include both SNPs and indels.\n"); + printf("# PSC\t[2]id\t[3]sample\t[4]nRefHom\t[5]nNonRefHom\t[6]nHets\t[7]nTransitions\t[8]nTransversions\t[9]nIndels\t[10]average depth\t[11]nSingletons" + "\t[12]nHapRef\t[13]nHapAlt\t[14]nMissing\n"); for (id=0; idnstats; id++) { stats_t *stats = &args->stats[id]; for (i=0; ifiles->n_smpl; i++) { float dp = stats->smpl_ndp[i] ? stats->smpl_dp[i]/(float)stats->smpl_ndp[i] : 0; - printf("PSC\t%d\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%.1f\t%d\n", id,args->files->samples[i], + printf("PSC\t%d\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%.1f\t%d\t%d\t%d\t%d\n", id,args->files->samples[i], stats->smpl_homRR[i], stats->smpl_homAA[i], stats->smpl_hets[i], stats->smpl_ts[i], - stats->smpl_tv[i], stats->smpl_indels[i],dp, stats->smpl_sngl[i]); + stats->smpl_tv[i], stats->smpl_indels[i],dp, stats->smpl_sngl[i], stats->smpl_hapRef[i], + stats->smpl_hapAlt[i], stats->smpl_missing[i]); } } @@ -1423,8 +1550,10 @@ static void print_stats(args_t *args) for (j=0; jnaf_hwe; j++) sum_tot += ptr[j]; if ( !sum_tot ) continue; + double af = args->af_bins ? (bin_get_value(args->af_bins,i)+bin_get_value(args->af_bins,i-1))*0.5 : (double)(i-1)/(args->m_af-1); + int nprn = 3; - printf("HWE\t%d\t%f\t%d",id,100.*(i-1)/(args->m_af-1),sum_tot); + printf("HWE\t%d\t%f\t%d",id,af,sum_tot); for (j=0; jnaf_hwe; j++) { sum_tmp += ptr[j]; @@ -1462,6 +1591,8 @@ static void usage(void) fprintf(stderr, "Usage: bcftools stats [options] []\n"); fprintf(stderr, "\n"); fprintf(stderr, "Options:\n"); + fprintf(stderr, " --af-bins allele frequency bins, a list (0.1,0.5,1) or a file (0.1\\n0.5\\n1)\n"); + fprintf(stderr, " --af-tag allele frequency tag to use, by default estimated from AN,AC or GT\n"); fprintf(stderr, " -1, --1st-allele-only include only 1st allele at multiallelic sites\n"); fprintf(stderr, " -c, --collapse treat as identical records with , see man page for details [none]\n"); fprintf(stderr, " -d, --depth depth distribution: min,max,bin size [0,500,1]\n"); @@ -1478,6 +1609,7 @@ static void usage(void) fprintf(stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); fprintf(stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); fprintf(stderr, " -u, --user-tstv collect Ts/Tv stats for any tag using the given binning [0:1:100]\n"); + fprintf(stderr, " --threads number of extra decompression threads [0]\n"); fprintf(stderr, " -v, --verbose produce verbose per-site and per-sample output\n"); fprintf(stderr, "\n"); exit(1); @@ -1494,6 +1626,8 @@ int main_vcfstats(int argc, char *argv[]) static struct option loptions[] = { + {"af-bins",1,0,1}, + {"af-tag",1,0,2}, {"1st-allele-only",0,0,'1'}, {"include",1,0,'i'}, {"exclude",1,0,'e'}, @@ -1512,10 +1646,13 @@ int main_vcfstats(int argc, char *argv[]) {"targets-file",1,0,'T'}, {"fasta-ref",1,0,'F'}, {"user-tstv",1,0,'u'}, + {"threads",1,0,9}, {0,0,0,0} }; while ((c = getopt_long(argc, argv, "hc:r:R:e:s:S:d:i:t:T:F:f:1u:vIE:",loptions,NULL)) >= 0) { switch (c) { + case 1 : args->af_bins_list = optarg; break; + case 2 : args->af_tag = optarg; break; case 'u': add_user_stats(args,optarg); break; case '1': args->first_allele_only = 1; break; case 'F': args->ref_fname = optarg; break; @@ -1547,6 +1684,7 @@ int main_vcfstats(int argc, char *argv[]) case 'I': args->split_by_id = 1; break; case 'e': args->filter_str = optarg; args->filter_logic |= FLT_EXCLUDE; break; case 'i': args->filter_str = optarg; args->filter_logic |= FLT_INCLUDE; break; + case 9 : args->n_threads = strtol(optarg, 0, 0); break; case 'h': case '?': usage(); default: error("Unknown argument: %s\n", optarg); @@ -1571,6 +1709,9 @@ int main_vcfstats(int argc, char *argv[]) error("Failed to read the targets: %s\n", args->targets_list); if ( args->regions_list && bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 ) error("Failed to read the regions: %s\n", args->regions_list); + if ( args->n_threads && bcf_sr_set_threads(args->files, args->n_threads)<0) + error("Failed to create threads\n"); + while (fname) { if ( !bcf_sr_add_reader(args->files, fname) ) diff --git a/bcftools/vcfstats.c.pysam.c b/bcftools/vcfstats.c.pysam.c index 5653760ae..46a051f63 100644 --- a/bcftools/vcfstats.c.pysam.c +++ b/bcftools/vcfstats.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfstats.c -- Produces stats which can be plotted using plot-vcfstats. - Copyright (C) 2012-2015 Genome Research Ltd. + Copyright (C) 2012-2017 Genome Research Ltd. Author: Petr Danecek @@ -41,6 +41,7 @@ THE SOFTWARE. */ #include #include "bcftools.h" #include "filter.h" +#include "bin.h" // Logic of the filters: include or exclude sites which match the filters? #define FLT_INCLUDE 1 @@ -69,17 +70,6 @@ typedef struct } idist_t; -typedef struct -{ - double x; - double x2; - double y; - double y2; - double xy; - double n; -} -smpl_r_t; - typedef struct { int n_snps, n_indels, n_mnps, n_others, n_mals, n_snp_mals, n_records, n_noalts; @@ -99,6 +89,7 @@ typedef struct int in_frame, out_frame, na_frame, in_frame_alt1, out_frame_alt1, na_frame_alt1; int subst[15]; int *smpl_hets, *smpl_homRR, *smpl_homAA, *smpl_ts, *smpl_tv, *smpl_indels, *smpl_ndp, *smpl_sngl; + int *smpl_hapRef, *smpl_hapAlt, *smpl_missing; int *smpl_indel_hets, *smpl_indel_homs; int *smpl_frm_shifts; // not-applicable, in-frame, out-frame unsigned long int *smpl_dp; @@ -110,9 +101,14 @@ stats_t; typedef struct { - uint64_t m[3], mm[3]; // number of hom, het and non-ref hom matches and mismatches - float r2sum; - uint32_t r2n; + uint64_t gt2gt[5][5]; // number of RR->RR, RR->RA, etc. matches/mismatches; see type2stats + /* + Pearson's R^2 is used for aggregate R^2 + y, yy .. sum of dosage and squared dosage in the query VCF (second file) + x, xx .. sum of squared dosage in the truth VCF (first file) + n .. number of genotypes + */ + double y, yy, x, xx, yx, n; } gtcmp_t; @@ -137,7 +133,11 @@ typedef struct int *tmp_iaf, ntmp_iaf, m_af, m_qual, naf_hwe, mtmp_frm; uint8_t *tmp_frm; int dp_min, dp_max, dp_step; - gtcmp_t *af_gts_snps, *af_gts_indels, *smpl_gts_snps, *smpl_gts_indels; // first bin of af_* stats are singletons + gtcmp_t *smpl_gts_snps, *smpl_gts_indels; + gtcmp_t *af_gts_snps, *af_gts_indels; // first bin of af_* stats are singletons + bin_t *af_bins; + float *farr; + int mfarr; // indel context indel_ctx_t *indel_ctx; @@ -150,21 +150,18 @@ typedef struct // other bcf_srs_t *files; bcf_sr_regions_t *exons; - char **argv, *exons_fname, *regions_list, *samples_list, *targets_list; + char **argv, *exons_fname, *regions_list, *samples_list, *targets_list, *af_bins_list, *af_tag; int argc, verbose_sites, first_allele_only, samples_is_file; int split_by_id, nstats; filter_t *filter[2]; char *filter_str; int filter_logic; // include or exclude sites which match the filters? One of FLT_INCLUDE/FLT_EXCLUDE - - // Per Sample r working data arrays of size equal to number of samples - smpl_r_t* smpl_r_snps; - smpl_r_t* smpl_r_indels; + int n_threads; } args_t; -static int type2dosage[6], type2ploidy[6], type2stats[6]; +static int type2dosage[6], type2ploidy[6], type2stats[7]; static void idist_init(idist_t *d, int min, int max, int step) { @@ -189,23 +186,29 @@ static inline int idist_i2bin(idist_t *d, int i) return i-1+d->min; } +static inline int clip_nonnegative(float x, int limit) +{ + if (x >= limit || isnan(x)) return limit - 1; + else if (x <= 0.0) return 0; + else return (int) x; +} #define IC_DBG 0 #if IC_DBG static void _indel_ctx_print1(_idc1_t *idc) { int i; - fprintf(pysam_stdout, "%d\t", idc->cnt); + fprintf(bcftools_stdout, "%d\t", idc->cnt); for (i=0; ilen; i++) - fputc(idc->seq[i], pysam_stdout); - fputc('\n', pysam_stdout); + fputc(idc->seq[i], bcftools_stdout); + fputc('\n', bcftools_stdout); } static void _indel_ctx_print(indel_ctx_t *ctx) { int i; for (i=0; indat; i++) _indel_ctx_print1(&ctx->dat[i]); - fputc('\n',pysam_stdout); + fputc('\n',bcftools_stdout); } #endif static int _indel_ctx_lookup(indel_ctx_t *ctx, char *seq, int seq_len, int *hit) @@ -304,7 +307,7 @@ int indel_ctx_type(indel_ctx_t *ctx, char *chr, int pos, char *ref, char *alt, i // Sanity check: the reference sequence must match the REF allele for (i=0; ifilter[0] = filter_init(bcf_sr_get_header(args->files,0), args->filter_str); if ( args->files->nreaders==2 ) args->filter[1] = filter_init(bcf_sr_get_header(args->files,1), args->filter_str); + args->files->max_unpack |= filter_max_unpack(args->filter[0]); + } + + // AF corresponds to AC but is more robust to mixtures of haploid and diploid GTs + if ( !args->af_bins_list ) + { + args->m_af = 101; + for (i=0; ifiles->nreaders; i++) + if ( bcf_hdr_nsamples(args->files->readers[i].header) + 1> args->m_af ) + args->m_af = bcf_hdr_nsamples(args->files->readers[i].header) + 1; + } + else + { + args->af_bins = bin_init(args->af_bins_list,0,1); + + // m_af is used also for other af arrays, where the first bin is for + // singletons. However, since the last element is unused in af_bins + // (n boundaries form n-1 intervals), the m_af count is good for both. + args->m_af = bin_get_size(args->af_bins); } - // AF corresponds to AC but is more robust for mixture of haploid and diploid GTs - args->m_af = 101; - for (i=0; ifiles->nreaders; i++) - if ( bcf_hdr_nsamples(args->files->readers[i].header) + 1> args->m_af ) - args->m_af = bcf_hdr_nsamples(args->files->readers[i].header) + 1; + bcf_hdr_t *hdr = bcf_sr_get_header(args->files,0); + if ( args->af_tag && !bcf_hdr_idinfo_exists(hdr,BCF_HL_INFO,bcf_hdr_id2int(hdr,BCF_DT_ID,args->af_tag)) ) + error("No such INFO tag: %s\n", args->af_tag); #if QUAL_STATS args->m_qual = 999; @@ -432,8 +452,6 @@ static void init_stats(args_t *args) args->af_gts_indels = (gtcmp_t *) calloc(args->m_af,sizeof(gtcmp_t)); args->smpl_gts_snps = (gtcmp_t *) calloc(args->files->n_smpl,sizeof(gtcmp_t)); args->smpl_gts_indels = (gtcmp_t *) calloc(args->files->n_smpl,sizeof(gtcmp_t)); - args->smpl_r_snps = (smpl_r_t*) calloc(args->files->n_smpl, sizeof(smpl_r_t)); - args->smpl_r_indels = (smpl_r_t*) calloc(args->files->n_smpl, sizeof(smpl_r_t)); } for (i=0; instats; i++) { @@ -454,9 +472,12 @@ static void init_stats(args_t *args) #endif if ( args->files->n_smpl ) { + stats->smpl_missing = (int *) calloc(args->files->n_smpl,sizeof(int)); stats->smpl_hets = (int *) calloc(args->files->n_smpl,sizeof(int)); stats->smpl_homAA = (int *) calloc(args->files->n_smpl,sizeof(int)); stats->smpl_homRR = (int *) calloc(args->files->n_smpl,sizeof(int)); + stats->smpl_hapRef = (int *) calloc(args->files->n_smpl,sizeof(int)); + stats->smpl_hapAlt = (int *) calloc(args->files->n_smpl,sizeof(int)); stats->smpl_indel_hets = (int *) calloc(args->files->n_smpl,sizeof(int)); stats->smpl_indel_homs = (int *) calloc(args->files->n_smpl,sizeof(int)); stats->smpl_ts = (int *) calloc(args->files->n_smpl,sizeof(int)); @@ -505,9 +526,10 @@ static void init_stats(args_t *args) type2stats[GT_HOM_RR] = 0; type2stats[GT_HET_RA] = 1; type2stats[GT_HOM_AA] = 2; - type2stats[GT_HET_AA] = 1; + type2stats[GT_HET_AA] = 3; type2stats[GT_HAPL_R] = 0; type2stats[GT_HAPL_A] = 2; + type2stats[GT_UNKN] = 4; } static void destroy_stats(args_t *args) @@ -528,22 +550,24 @@ static void destroy_stats(args_t *args) if (stats->qual_indels) free(stats->qual_indels); #endif #if HWE_STATS - //if ( args->files->n_smpl ) free(stats->af_hwe); free(stats->af_hwe); #endif free(stats->insertions); free(stats->deletions); - if (stats->smpl_hets) free(stats->smpl_hets); - if (stats->smpl_homAA) free(stats->smpl_homAA); - if (stats->smpl_homRR) free(stats->smpl_homRR); - if (stats->smpl_indel_homs) free(stats->smpl_indel_homs); - if (stats->smpl_indel_hets) free(stats->smpl_indel_hets); - if (stats->smpl_ts) free(stats->smpl_ts); - if (stats->smpl_tv) free(stats->smpl_tv); - if (stats->smpl_indels) free(stats->smpl_indels); - if (stats->smpl_dp) free(stats->smpl_dp); - if (stats->smpl_ndp) free(stats->smpl_ndp); - if (stats->smpl_sngl) free(stats->smpl_sngl); + free(stats->smpl_missing); + free(stats->smpl_hets); + free(stats->smpl_homAA); + free(stats->smpl_homRR); + free(stats->smpl_hapRef); + free(stats->smpl_hapAlt); + free(stats->smpl_indel_homs); + free(stats->smpl_indel_hets); + free(stats->smpl_ts); + free(stats->smpl_tv); + free(stats->smpl_indels); + free(stats->smpl_dp); + free(stats->smpl_ndp); + free(stats->smpl_sngl); idist_destroy(&stats->dp); idist_destroy(&stats->dp_sites); for (j=0; jnusr; j++) @@ -556,6 +580,8 @@ static void destroy_stats(args_t *args) if ( args->exons ) free(stats->smpl_frm_shifts); } for (j=0; jnusr; j++) free(args->usr[j].tag); + if ( args->af_bins ) bin_destroy(args->af_bins); + free(args->farr); free(args->usr); free(args->tmp_frm); free(args->tmp_iaf); @@ -564,8 +590,6 @@ static void destroy_stats(args_t *args) free(args->af_gts_indels); free(args->smpl_gts_snps); free(args->smpl_gts_indels); - free(args->smpl_r_snps); - free(args->smpl_r_indels); if (args->indel_ctx) indel_ctx_destroy(args->indel_ctx); if (args->filter[0]) filter_destroy(args->filter[0]); if (args->filter[1]) filter_destroy(args->filter[1]); @@ -574,36 +598,59 @@ static void destroy_stats(args_t *args) static void init_iaf(args_t *args, bcf_sr_t *reader) { bcf1_t *line = reader->buffer[0]; - if ( args->ntmp_iaf < line->n_allele ) + hts_expand(int32_t,line->n_allele,args->ntmp_iaf,args->tmp_iaf); + + int i, ret; + if ( args->af_tag ) { - args->tmp_iaf = (int*)realloc(args->tmp_iaf, line->n_allele*sizeof(int)); - args->ntmp_iaf = line->n_allele; + ret = bcf_get_info_float(reader->header, line, args->af_tag, &args->farr, &args->mfarr); + if ( ret<=0 || ret!=line->n_allele-1 ) + { + // the AF tag is not present or wrong number of values, put in the singletons/unknown bin + for (i=0; in_allele; i++) args->tmp_iaf[i] = 0; + return; + } + args->tmp_iaf[0] = 0; + for (i=1; in_allele; i++) + { + float af = args->farr[i-1]; + if ( af<0 ) af = 0; + else if ( af>1 ) af = 1; + int iaf = args->af_bins ? bin_get_idx(args->af_bins,af) : af*(args->m_af-2); + args->tmp_iaf[i] = iaf + 1; // the first tmp_iaf bin is reserved for singletons + } + return; } + // tmp_iaf is first filled with AC counts in calc_ac and then transformed to // an index to af_gts_snps - int i, ret = bcf_calc_ac(reader->header, line, args->tmp_iaf, args->samples_list ? BCF_UN_INFO|BCF_UN_FMT : BCF_UN_INFO); - if ( ret ) + ret = bcf_calc_ac(reader->header, line, args->tmp_iaf, args->samples_list ? BCF_UN_INFO|BCF_UN_FMT : BCF_UN_INFO); + if ( !ret ) { - int an=0; - for (i=0; in_allele; i++) - an += args->tmp_iaf[i]; + for (i=0; in_allele; i++) args->tmp_iaf[i] = 0; // singletons/unknown bin + return; + } - args->tmp_iaf[0] = 0; - for (i=1; in_allele; i++) + int an = 0; + for (i=0; in_allele; i++) + an += args->tmp_iaf[i]; + + args->tmp_iaf[0] = 0; + for (i=1; in_allele; i++) + { + if ( args->tmp_iaf[i]==1 ) + args->tmp_iaf[i] = 0; // singletons into the first bin + else if ( !an ) + args->tmp_iaf[i] = 1; // no genotype at all, put to the AF=0 bin + else { - if ( args->tmp_iaf[i]==1 ) - args->tmp_iaf[i] = 0; // singletons into the first bin - else if ( !an ) - args->tmp_iaf[i] = 1; // no genotype at all, put to the AF=0 bin - else - args->tmp_iaf[i] = 1 + args->tmp_iaf[i] * (args->m_af-2.0) / an; + float af = (float) args->tmp_iaf[i] / an; + if ( af<0 ) af = 0; + else if ( af>1 ) af = 1; + int iaf = args->af_bins ? bin_get_idx(args->af_bins,af) : af*(args->m_af-2); + args->tmp_iaf[i] = iaf + 1; } } - else - for (i=0; in_allele; i++) - args->tmp_iaf[i] = 0; - - // todo: otherwise use AF } static inline void do_mnp_stats(args_t *args, stats_t *stats, bcf_sr_t *reader) @@ -623,7 +670,7 @@ static void do_indel_stats(args_t *args, stats_t *stats, bcf_sr_t *reader) bcf1_t *line = reader->buffer[0]; #if QUAL_STATS - int iqual = line->qual >= args->m_qual || isnan(line->qual) ? args->m_qual - 1 : line->qual; + int iqual = clip_nonnegative(line->qual, args->m_qual); stats->qual_indels[iqual]++; #endif @@ -758,7 +805,7 @@ static void do_snp_stats(args_t *args, stats_t *stats, bcf_sr_t *reader) if ( ref<0 ) return; #if QUAL_STATS - int iqual = line->qual >= args->m_qual || isnan(line->qual) ? args->m_qual - 1 : line->qual; + int iqual = clip_nonnegative(line->qual, args->m_qual); stats->qual_snps[iqual]++; #endif @@ -815,7 +862,11 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int { int ial, jal; int gt = bcf_gt_type(fmt_ptr, reader->samples[is], &ial, &jal); - if ( gt==GT_UNKN ) continue; + if ( gt==GT_UNKN ) + { + stats->smpl_missing[is]++; + continue; + } if ( gt==GT_HAPL_R || gt==GT_HAPL_A ) { if ( line_type&VCF_INDEL && stats->smpl_frm_shifts ) @@ -823,6 +874,8 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int assert( ialn_allele ); stats->smpl_frm_shifts[is*3 + args->tmp_frm[ial]]++; } + if ( gt == GT_HAPL_R ) stats->smpl_hapRef[is]++; + if ( gt == GT_HAPL_A ) stats->smpl_hapAlt[is]++; continue; } if ( gt != GT_HOM_RR ) { n_nref++; i_nref = is; } @@ -835,7 +888,10 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int case GT_HOM_AA: nalt_tot++; break; } #endif - if ( line_type&VCF_SNP || line_type==VCF_REF ) // count ALT=. as SNP + int var_type = 0; + if ( ial>0 ) var_type |= bcf_get_variant_type(line,ial); + if ( jal>0 ) var_type |= bcf_get_variant_type(line,jal); + if ( var_type&VCF_SNP || var_type==VCF_REF ) // count ALT=. as SNP { if ( gt == GT_HET_RA ) stats->smpl_hets[is]++; else if ( gt == GT_HET_AA ) stats->smpl_hets[is]++; @@ -851,7 +907,7 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int stats->smpl_tv[is]++; } } - if ( line_type&VCF_INDEL ) + if ( var_type&VCF_INDEL ) { if ( gt != GT_HOM_RR ) { @@ -875,6 +931,7 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int { float het_frac = (float)nhet_tot/(nhet_tot + nref_tot + nalt_tot); int idx = het_frac*(args->naf_hwe - 1); +//check me: what is this? if ( line->n_allele>1 ) idx += args->naf_hwe*args->tmp_iaf[1]; stats->af_hwe[idx]++; } @@ -900,7 +957,7 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int case BCF_BT_INT8: BRANCH_INT(int8_t, bcf_int8_missing, bcf_int8_vector_end); break; case BCF_BT_INT16: BRANCH_INT(int16_t, bcf_int16_missing, bcf_int16_vector_end); break; case BCF_BT_INT32: BRANCH_INT(int32_t, bcf_int32_missing, bcf_int32_vector_end); break; - default: fprintf(pysam_stderr, "[E::%s] todo: %d\n", __func__, fmt_ptr->type); exit(1); break; + default: fprintf(bcftools_stderr, "[E::%s] todo: %d\n", __func__, fmt_ptr->type); exit(1); break; } #undef BRANCH_INT } @@ -913,88 +970,42 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int fmt1 = bcf_get_fmt(files->readers[1].header,files->readers[1].buffer[0],"GT"); if ( !fmt1 ) return; // only the first ALT allele is considered - int iaf = line->n_allele>1 ? args->tmp_iaf[1] : 1; + int iaf = args->tmp_iaf[1]; int line_type = bcf_get_variant_types(files->readers[0].buffer[0]); gtcmp_t *af_stats = line_type&VCF_SNP ? args->af_gts_snps : args->af_gts_indels; gtcmp_t *smpl_stats = line_type&VCF_SNP ? args->smpl_gts_snps : args->smpl_gts_indels; - // - // Calculates r squared - // x is mean dosage of x at given site - // x2 is mean squared dosage of x at given site - // y is mean dosage of x at given site - // y2 is mean squared dosage of x at given site - // xy is mean dosage of x*y at given site - // r2sum += (xy - x*y)^2 / ( (x2 - x^2) * (y2 - y^2) ) - // r2n is number of sites considered - // output as r2sum/r2n for each AF bin - int r2n = 0; - float x = 0, y = 0, xy = 0, x2 = 0, y2 = 0; - // Select smpl_r - smpl_r_t *smpl_r = NULL; - if (line_type&VCF_SNP) - { - smpl_r = args->smpl_r_snps; - } - else if (line_type&VCF_INDEL) - { - smpl_r = args->smpl_r_indels; - } for (is=0; isn_smpl; is++) { // Simplified comparison: only 0/0, 0/1, 1/1 is looked at as the identity of // actual alleles can be enforced by running without the -c option. int gt0 = bcf_gt_type(fmt0, files->readers[0].samples[is], NULL, NULL); - if ( gt0 == GT_UNKN ) continue; - int gt1 = bcf_gt_type(fmt1, files->readers[1].samples[is], NULL, NULL); - if ( gt1 == GT_UNKN ) continue; - if ( type2ploidy[gt0]*type2ploidy[gt1] == -1 ) continue; // cannot compare diploid and haploid genotypes + int idx0 = type2stats[gt0]; + int idx1 = type2stats[gt1]; + af_stats[iaf].gt2gt[idx0][idx1]++; + smpl_stats[is].gt2gt[idx0][idx1]++; - int dsg0 = type2dosage[gt0]; - int dsg1 = type2dosage[gt1]; - x += dsg0; - x2 += dsg0*dsg0; - y += dsg1; - y2 += dsg1*dsg1; - xy += dsg0*dsg1; - r2n++; - - int idx = type2stats[gt0]; - if ( gt0==gt1 ) - { - af_stats[iaf].m[idx]++; - smpl_stats[is].m[idx]++; - } - else - { - af_stats[iaf].mm[idx]++; - smpl_stats[is].mm[idx]++; - } - - // Now do it across samples - - if (smpl_r) { - smpl_r[is].xy += dsg0*dsg1; - smpl_r[is].x += dsg0; - smpl_r[is].x2 += dsg0*dsg0; - smpl_r[is].y += dsg1; - smpl_r[is].y2 += dsg1*dsg1; - ++(smpl_r[is].n); - } - } + if ( gt0 == GT_UNKN || gt1 == GT_UNKN ) continue; + if ( type2ploidy[gt0]*type2ploidy[gt1] == -1 ) continue; // cannot compare diploid and haploid genotypes - if ( r2n ) - { - x /= r2n; y /= r2n; x2 /= r2n; y2 /= r2n; xy /= r2n; - float cov = xy - x*y; - float var2 = (x2 - x*x) * (y2 - y*y); - if ( var2!=0 ) - { - af_stats[iaf].r2sum += cov*cov/var2; - af_stats[iaf].r2n++; - } + float y = type2dosage[gt0]; + float x = type2dosage[gt1]; + + smpl_stats[is].yx += y*x; + smpl_stats[is].x += x; + smpl_stats[is].xx += x*x; + smpl_stats[is].y += y; + smpl_stats[is].yy += y*y; + smpl_stats[is].n += 1; + + af_stats[iaf].yx += y*x; + af_stats[iaf].x += x; + af_stats[iaf].xx += x*x; + af_stats[iaf].y += y; + af_stats[iaf].yy += y*y; + af_stats[iaf].n += 1; } if ( args->verbose_sites ) @@ -1010,7 +1021,7 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int { nmm++; bcf_sr_t *reader = &files->readers[0]; - fprintf(pysam_stdout, "DBG\t%s\t%d\t%s\t%d\t%d\n",reader->header->id[BCF_DT_CTG][reader->buffer[0]->rid].key,reader->buffer[0]->pos+1,files->samples[is],gt,gt2); + fprintf(bcftools_stdout, "DBG\t%s\t%d\t%s\t%d\t%d\n",reader->header->id[BCF_DT_CTG][reader->buffer[0]->rid].key,reader->buffer[0]->pos+1,files->samples[is],gt,gt2); } else { @@ -1019,7 +1030,7 @@ static void do_sample_stats(args_t *args, stats_t *stats, bcf_sr_t *reader, int } } float nrd = nrefm+nmm ? 100.*nmm/(nrefm+nmm) : 0; - fprintf(pysam_stdout, "PSD\t%s\t%d\t%d\t%d\t%f\n", reader->header->id[BCF_DT_CTG][reader->buffer[0]->rid].key,reader->buffer[0]->pos+1,nm,nmm,nrd); + fprintf(bcftools_stdout, "PSD\t%s\t%d\t%d\t%d\t%f\n", reader->header->id[BCF_DT_CTG][reader->buffer[0]->rid].key,reader->buffer[0]->pos+1,nm,nmm,nrd); } } } @@ -1075,7 +1086,7 @@ static void do_vcf_stats(args_t *args) if ( line->n_allele>2 ) { stats->n_mals++; - if ( line_type == VCF_SNP ) stats->n_snp_mals++; + if ( line_type == VCF_SNP ) stats->n_snp_mals++; // note: this will be fooled by C>C,T } if ( files->n_smpl ) @@ -1089,38 +1100,38 @@ static void do_vcf_stats(args_t *args) static void print_header(args_t *args) { int i; - fprintf(pysam_stdout, "# This file was produced by bcftools stats (%s+htslib-%s) and can be plotted using plot-vcfstats.\n", bcftools_version(),hts_version()); - fprintf(pysam_stdout, "# The command line was:\tbcftools %s ", args->argv[0]); + fprintf(bcftools_stdout, "# This file was produced by bcftools stats (%s+htslib-%s) and can be plotted using plot-vcfstats.\n", bcftools_version(),hts_version()); + fprintf(bcftools_stdout, "# The command line was:\tbcftools %s ", args->argv[0]); for (i=1; iargc; i++) - fprintf(pysam_stdout, " %s",args->argv[i]); - fprintf(pysam_stdout, "\n#\n"); + fprintf(bcftools_stdout, " %s",args->argv[i]); + fprintf(bcftools_stdout, "\n#\n"); - fprintf(pysam_stdout, "# Definition of sets:\n# ID\t[2]id\t[3]tab-separated file names\n"); + fprintf(bcftools_stdout, "# Definition of sets:\n# ID\t[2]id\t[3]tab-separated file names\n"); if ( args->files->nreaders==1 ) { const char *fname = strcmp("-",args->files->readers[0].fname) ? args->files->readers[0].fname : ""; if ( args->split_by_id ) { - fprintf(pysam_stdout, "ID\t0\t%s:known (sites with ID different from \".\")\n", fname); - fprintf(pysam_stdout, "ID\t1\t%s:novel (sites where ID column is \".\")\n", fname); + fprintf(bcftools_stdout, "ID\t0\t%s:known (sites with ID different from \".\")\n", fname); + fprintf(bcftools_stdout, "ID\t1\t%s:novel (sites where ID column is \".\")\n", fname); } else - fprintf(pysam_stdout, "ID\t0\t%s\n", fname); + fprintf(bcftools_stdout, "ID\t0\t%s\n", fname); } else { const char *fname0 = strcmp("-",args->files->readers[0].fname) ? args->files->readers[0].fname : ""; const char *fname1 = strcmp("-",args->files->readers[1].fname) ? args->files->readers[1].fname : ""; - fprintf(pysam_stdout, "ID\t0\t%s\n", fname0); - fprintf(pysam_stdout, "ID\t1\t%s\n", fname1); - fprintf(pysam_stdout, "ID\t2\t%s\t%s\n", fname0,fname1); + fprintf(bcftools_stdout, "ID\t0\t%s\n", fname0); + fprintf(bcftools_stdout, "ID\t1\t%s\n", fname1); + fprintf(bcftools_stdout, "ID\t2\t%s\t%s\n", fname0,fname1); if ( args->verbose_sites ) { - fprintf(pysam_stdout, + fprintf(bcftools_stdout, "# Verbose per-site discordance output.\n" "# PSD\t[2]CHROM\t[3]POS\t[4]Number of matches\t[5]Number of mismatches\t[6]NRD\n"); - fprintf(pysam_stdout, + fprintf(bcftools_stdout, "# Verbose per-site and per-sample output. Genotype codes: %d:HomRefRef, %d:HomAltAlt, %d:HetAltRef, %d:HetAltAlt, %d:haploidRef, %d:haploidAlt\n" "# DBG\t[2]CHROM\t[3]POS\t[4]Sample\t[5]GT in %s\t[6]GT in %s\n", GT_HOM_RR, GT_HOM_AA, GT_HET_RA, GT_HET_AA, GT_HAPL_R, GT_HAPL_A, fname0,fname1); @@ -1131,43 +1142,58 @@ static void print_header(args_t *args) #define T2S(x) type2stats[x] static void print_stats(args_t *args) { - int i, id; - fprintf(pysam_stdout, "# SN, Summary numbers:\n# SN\t[2]id\t[3]key\t[4]value\n"); + int i, j,k, id; + fprintf(bcftools_stdout, "# SN, Summary numbers:\n"); + fprintf(bcftools_stdout, "# number of records .. number of data rows in the VCF\n"); + fprintf(bcftools_stdout, "# number of no-ALTs .. reference-only sites, ALT is either \".\" or identical to REF\n"); + fprintf(bcftools_stdout, "# number of SNPs .. number of rows with a SNP\n"); + fprintf(bcftools_stdout, "# number of MNPs .. number of rows with a MNP, such as CC>TT\n"); + fprintf(bcftools_stdout, "# number of indels .. number of rows with an indel\n"); + fprintf(bcftools_stdout, "# number of others .. number of rows with other type, for example a symbolic allele or\n"); + fprintf(bcftools_stdout, "# a complex substitution, such as ACT>TCGA\n"); + fprintf(bcftools_stdout, "# number of multiallelic sites .. number of rows with multiple alternate alleles\n"); + fprintf(bcftools_stdout, "# number of multiallelic SNP sites .. number of rows with multiple alternate alleles, all SNPs\n"); + fprintf(bcftools_stdout, "# \n"); + fprintf(bcftools_stdout, "# Note that rows containing multiple types will be counted multiple times, in each\n"); + fprintf(bcftools_stdout, "# counter. For example, a row with a SNP and an indel increments both the SNP and\n"); + fprintf(bcftools_stdout, "# the indel counter.\n"); + fprintf(bcftools_stdout, "# \n"); + fprintf(bcftools_stdout, "# SN\t[2]id\t[3]key\t[4]value\n"); for (id=0; idfiles->nreaders; id++) - fprintf(pysam_stdout, "SN\t%d\tnumber of samples:\t%d\n", id, bcf_hdr_nsamples(args->files->readers[id].header)); + fprintf(bcftools_stdout, "SN\t%d\tnumber of samples:\t%d\n", id, bcf_hdr_nsamples(args->files->readers[id].header)); for (id=0; idnstats; id++) { stats_t *stats = &args->stats[id]; - fprintf(pysam_stdout, "SN\t%d\tnumber of records:\t%d\n", id, stats->n_records); - fprintf(pysam_stdout, "SN\t%d\tnumber of no-ALTs:\t%d\n", id, stats->n_noalts); - fprintf(pysam_stdout, "SN\t%d\tnumber of SNPs:\t%d\n", id, stats->n_snps); - fprintf(pysam_stdout, "SN\t%d\tnumber of MNPs:\t%d\n", id, stats->n_mnps); - fprintf(pysam_stdout, "SN\t%d\tnumber of indels:\t%d\n", id, stats->n_indels); - fprintf(pysam_stdout, "SN\t%d\tnumber of others:\t%d\n", id, stats->n_others); - fprintf(pysam_stdout, "SN\t%d\tnumber of multiallelic sites:\t%d\n", id, stats->n_mals); - fprintf(pysam_stdout, "SN\t%d\tnumber of multiallelic SNP sites:\t%d\n", id, stats->n_snp_mals); + fprintf(bcftools_stdout, "SN\t%d\tnumber of records:\t%d\n", id, stats->n_records); + fprintf(bcftools_stdout, "SN\t%d\tnumber of no-ALTs:\t%d\n", id, stats->n_noalts); + fprintf(bcftools_stdout, "SN\t%d\tnumber of SNPs:\t%d\n", id, stats->n_snps); + fprintf(bcftools_stdout, "SN\t%d\tnumber of MNPs:\t%d\n", id, stats->n_mnps); + fprintf(bcftools_stdout, "SN\t%d\tnumber of indels:\t%d\n", id, stats->n_indels); + fprintf(bcftools_stdout, "SN\t%d\tnumber of others:\t%d\n", id, stats->n_others); + fprintf(bcftools_stdout, "SN\t%d\tnumber of multiallelic sites:\t%d\n", id, stats->n_mals); + fprintf(bcftools_stdout, "SN\t%d\tnumber of multiallelic SNP sites:\t%d\n", id, stats->n_snp_mals); } - fprintf(pysam_stdout, "# TSTV, transitions/transversions:\n# TSTV\t[2]id\t[3]ts\t[4]tv\t[5]ts/tv\t[6]ts (1st ALT)\t[7]tv (1st ALT)\t[8]ts/tv (1st ALT)\n"); + fprintf(bcftools_stdout, "# TSTV, transitions/transversions:\n# TSTV\t[2]id\t[3]ts\t[4]tv\t[5]ts/tv\t[6]ts (1st ALT)\t[7]tv (1st ALT)\t[8]ts/tv (1st ALT)\n"); for (id=0; idnstats; id++) { stats_t *stats = &args->stats[id]; int ts=0,tv=0; for (i=0; im_af; i++) { ts += stats->af_ts[i]; tv += stats->af_tv[i]; } - fprintf(pysam_stdout, "TSTV\t%d\t%d\t%d\t%.2f\t%d\t%d\t%.2f\n", id,ts,tv,tv?(float)ts/tv:0, stats->ts_alt1,stats->tv_alt1,stats->tv_alt1?(float)stats->ts_alt1/stats->tv_alt1:0); + fprintf(bcftools_stdout, "TSTV\t%d\t%d\t%d\t%.2f\t%d\t%d\t%.2f\n", id,ts,tv,tv?(float)ts/tv:0, stats->ts_alt1,stats->tv_alt1,stats->tv_alt1?(float)stats->ts_alt1/stats->tv_alt1:0); } if ( args->exons_fname ) { - fprintf(pysam_stdout, "# FS, Indel frameshifts:\n# FS\t[2]id\t[3]in-frame\t[4]out-frame\t[5]not applicable\t[6]out/(in+out) ratio\t[7]in-frame (1st ALT)\t[8]out-frame (1st ALT)\t[9]not applicable (1st ALT)\t[10]out/(in+out) ratio (1st ALT)\n"); + fprintf(bcftools_stdout, "# FS, Indel frameshifts:\n# FS\t[2]id\t[3]in-frame\t[4]out-frame\t[5]not applicable\t[6]out/(in+out) ratio\t[7]in-frame (1st ALT)\t[8]out-frame (1st ALT)\t[9]not applicable (1st ALT)\t[10]out/(in+out) ratio (1st ALT)\n"); for (id=0; idnstats; id++) { int in=args->stats[id].in_frame, out=args->stats[id].out_frame, na=args->stats[id].na_frame; int in1=args->stats[id].in_frame_alt1, out1=args->stats[id].out_frame_alt1, na1=args->stats[id].na_frame_alt1; - fprintf(pysam_stdout, "FS\t%d\t%d\t%d\t%d\t%.2f\t%d\t%d\t%d\t%.2f\n", id, in,out,na,out?(float)out/(in+out):0,in1,out1,na1,out1?(float)out1/(in1+out1):0); + fprintf(bcftools_stdout, "FS\t%d\t%d\t%d\t%d\t%.2f\t%d\t%d\t%d\t%.2f\n", id, in,out,na,out?(float)out/(in+out):0,in1,out1,na1,out1?(float)out1/(in1+out1):0); } } if ( args->indel_ctx ) { - fprintf(pysam_stdout, "# ICS, Indel context summary:\n# ICS\t[2]id\t[3]repeat-consistent\t[4]repeat-inconsistent\t[5]not applicable\t[6]c/(c+i) ratio\n"); + fprintf(bcftools_stdout, "# ICS, Indel context summary:\n# ICS\t[2]id\t[3]repeat-consistent\t[4]repeat-inconsistent\t[5]not applicable\t[6]c/(c+i) ratio\n"); for (id=0; idnstats; id++) { int nc = 0, ni = 0, na = args->stats[id].n_repeat_na; @@ -1176,25 +1202,25 @@ static void print_stats(args_t *args) nc += args->stats[id].n_repeat[i][0] + args->stats[id].n_repeat[i][2]; ni += args->stats[id].n_repeat[i][1] + args->stats[id].n_repeat[i][3]; } - fprintf(pysam_stdout, "ICS\t%d\t%d\t%d\t%d\t%.4f\n", id, nc,ni,na,nc+ni ? (float)nc/(nc+ni) : 0.0); + fprintf(bcftools_stdout, "ICS\t%d\t%d\t%d\t%d\t%.4f\n", id, nc,ni,na,nc+ni ? (float)nc/(nc+ni) : 0.0); } - fprintf(pysam_stdout, "# ICL, Indel context by length:\n# ICL\t[2]id\t[3]length of repeat element\t[4]repeat-consistent deletions)\t[5]repeat-inconsistent deletions\t[6]consistent insertions\t[7]inconsistent insertions\t[8]c/(c+i) ratio\n"); + fprintf(bcftools_stdout, "# ICL, Indel context by length:\n# ICL\t[2]id\t[3]length of repeat element\t[4]repeat-consistent deletions)\t[5]repeat-inconsistent deletions\t[6]consistent insertions\t[7]inconsistent insertions\t[8]c/(c+i) ratio\n"); for (id=0; idnstats; id++) { for (i=1; istats[id].n_repeat[i][0]+args->stats[id].n_repeat[i][2], ni = args->stats[id].n_repeat[i][1]+args->stats[id].n_repeat[i][3]; - fprintf(pysam_stdout, "ICL\t%d\t%d\t%d\t%d\t%d\t%d\t%.4f\n", id, i+1, + fprintf(bcftools_stdout, "ICL\t%d\t%d\t%d\t%d\t%d\t%d\t%.4f\n", id, i+1, args->stats[id].n_repeat[i][0],args->stats[id].n_repeat[i][1],args->stats[id].n_repeat[i][2],args->stats[id].n_repeat[i][3], nc+ni ? (float)nc/(nc+ni) : 0.0); } } } - fprintf(pysam_stdout, "# SiS, Singleton stats:\n# SiS\t[2]id\t[3]allele count\t[4]number of SNPs\t[5]number of transitions\t[6]number of transversions\t[7]number of indels\t[8]repeat-consistent\t[9]repeat-inconsistent\t[10]not applicable\n"); + fprintf(bcftools_stdout, "# SiS, Singleton stats:\n# SiS\t[2]id\t[3]allele count\t[4]number of SNPs\t[5]number of transitions\t[6]number of transversions\t[7]number of indels\t[8]repeat-consistent\t[9]repeat-inconsistent\t[10]not applicable\n"); for (id=0; idnstats; id++) { stats_t *stats = &args->stats[id]; - fprintf(pysam_stdout, "SiS\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", id,1,stats->af_snps[0],stats->af_ts[0],stats->af_tv[0], + fprintf(bcftools_stdout, "SiS\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", id,1,stats->af_snps[0],stats->af_ts[0],stats->af_tv[0], stats->af_repeats[0][0]+stats->af_repeats[1][0]+stats->af_repeats[2][0],stats->af_repeats[0][0],stats->af_repeats[1][0],stats->af_repeats[2][0]); // put the singletons stats into the first AF bin, note that not all of the stats is transferred (i.e. nrd mismatches) stats->af_snps[1] += stats->af_snps[0]; @@ -1204,32 +1230,51 @@ static void print_stats(args_t *args) stats->af_repeats[1][1] += stats->af_repeats[1][0]; stats->af_repeats[2][1] += stats->af_repeats[2][0]; } - fprintf(pysam_stdout, "# AF, Stats by non-reference allele frequency:\n# AF\t[2]id\t[3]allele frequency\t[4]number of SNPs\t[5]number of transitions\t[6]number of transversions\t[7]number of indels\t[8]repeat-consistent\t[9]repeat-inconsistent\t[10]not applicable\n"); + // move the singletons stats into the first AF bin, singleton stats was collected separately because of init_iaf + if ( args->af_gts_snps ) + { + args->af_gts_snps[1].y += args->af_gts_snps[0].y; + args->af_gts_snps[1].yy += args->af_gts_snps[0].yy; + args->af_gts_snps[1].xx += args->af_gts_snps[0].xx; + args->af_gts_snps[1].yx += args->af_gts_snps[0].yx; + args->af_gts_snps[1].n += args->af_gts_snps[0].n; + } + if ( args->af_gts_indels ) + { + args->af_gts_indels[1].y += args->af_gts_indels[0].y; + args->af_gts_indels[1].yy += args->af_gts_indels[0].yy; + args->af_gts_indels[1].xx += args->af_gts_indels[0].xx; + args->af_gts_indels[1].yx += args->af_gts_indels[0].yx; + args->af_gts_indels[1].n += args->af_gts_indels[0].n; + } + + fprintf(bcftools_stdout, "# AF, Stats by non-reference allele frequency:\n# AF\t[2]id\t[3]allele frequency\t[4]number of SNPs\t[5]number of transitions\t[6]number of transversions\t[7]number of indels\t[8]repeat-consistent\t[9]repeat-inconsistent\t[10]not applicable\n"); for (id=0; idnstats; id++) { stats_t *stats = &args->stats[id]; for (i=1; im_af; i++) // note that af[1] now contains also af[0], see SiS stats output above { if ( stats->af_snps[i]+stats->af_ts[i]+stats->af_tv[i]+stats->af_repeats[0][i]+stats->af_repeats[1][i]+stats->af_repeats[2][i] == 0 ) continue; - fprintf(pysam_stdout, "AF\t%d\t%f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", id,100.*(i-1)/(args->m_af-1),stats->af_snps[i],stats->af_ts[i],stats->af_tv[i], + double af = args->af_bins ? (bin_get_value(args->af_bins,i)+bin_get_value(args->af_bins,i-1))*0.5 : (double)(i-1)/(args->m_af-1); + fprintf(bcftools_stdout, "AF\t%d\t%f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", id,af,stats->af_snps[i],stats->af_ts[i],stats->af_tv[i], stats->af_repeats[0][i]+stats->af_repeats[1][i]+stats->af_repeats[2][i],stats->af_repeats[0][i],stats->af_repeats[1][i],stats->af_repeats[2][i]); } } #if QUAL_STATS - fprintf(pysam_stdout, "# QUAL, Stats by quality:\n# QUAL\t[2]id\t[3]Quality\t[4]number of SNPs\t[5]number of transitions (1st ALT)\t[6]number of transversions (1st ALT)\t[7]number of indels\n"); + fprintf(bcftools_stdout, "# QUAL, Stats by quality:\n# QUAL\t[2]id\t[3]Quality\t[4]number of SNPs\t[5]number of transitions (1st ALT)\t[6]number of transversions (1st ALT)\t[7]number of indels\n"); for (id=0; idnstats; id++) { stats_t *stats = &args->stats[id]; for (i=0; im_qual; i++) { if ( stats->qual_snps[i]+stats->qual_ts[i]+stats->qual_tv[i]+stats->qual_indels[i] == 0 ) continue; - fprintf(pysam_stdout, "QUAL\t%d\t%d\t%d\t%d\t%d\t%d\n", id,i,stats->qual_snps[i],stats->qual_ts[i],stats->qual_tv[i],stats->qual_indels[i]); + fprintf(bcftools_stdout, "QUAL\t%d\t%d\t%d\t%d\t%d\t%d\n", id,i,stats->qual_snps[i],stats->qual_ts[i],stats->qual_tv[i],stats->qual_indels[i]); } } #endif for (i=0; inusr; i++) { - fprintf(pysam_stdout, "# USR:%s, Stats by %s:\n# USR:%s\t[2]id\t[3]%s\t[4]number of SNPs\t[5]number of transitions (1st ALT)\t[6]number of transversions (1st ALT)\n", + fprintf(bcftools_stdout, "# USR:%s, Stats by %s:\n# USR:%s\t[2]id\t[3]%s\t[4]number of SNPs\t[5]number of transitions (1st ALT)\t[6]number of transversions (1st ALT)\n", args->usr[i].tag,args->usr[i].tag,args->usr[i].tag,args->usr[i].tag); for (id=0; idnstats; id++) { @@ -1240,80 +1285,102 @@ static void print_stats(args_t *args) if ( usr->vals_ts[j]+usr->vals_tv[j] == 0 ) continue; // skip empty bins float val = usr->min + (usr->max - usr->min)*j/(usr->nbins-1); const char *fmt = usr->type==BCF_HT_REAL ? "USR:%s\t%d\t%e\t%d\t%d\t%d\n" : "USR:%s\t%d\t%.0f\t%d\t%d\t%d\n"; - fprintf(pysam_stdout, fmt,usr->tag,id,val,usr->vals_ts[j]+usr->vals_tv[j],usr->vals_ts[j],usr->vals_tv[j]); + fprintf(bcftools_stdout, fmt,usr->tag,id,val,usr->vals_ts[j]+usr->vals_tv[j],usr->vals_ts[j],usr->vals_tv[j]); } } } - fprintf(pysam_stdout, "# IDD, InDel distribution:\n# IDD\t[2]id\t[3]length (deletions negative)\t[4]count\n"); + fprintf(bcftools_stdout, "# IDD, InDel distribution:\n# IDD\t[2]id\t[3]length (deletions negative)\t[4]count\n"); for (id=0; idnstats; id++) { stats_t *stats = &args->stats[id]; for (i=stats->m_indel-1; i>=0; i--) - if ( stats->deletions[i] ) fprintf(pysam_stdout, "IDD\t%d\t%d\t%d\n", id,-i-1,stats->deletions[i]); + if ( stats->deletions[i] ) fprintf(bcftools_stdout, "IDD\t%d\t%d\t%d\n", id,-i-1,stats->deletions[i]); for (i=0; im_indel; i++) - if ( stats->insertions[i] ) fprintf(pysam_stdout, "IDD\t%d\t%d\t%d\n", id,i+1,stats->insertions[i]); + if ( stats->insertions[i] ) fprintf(bcftools_stdout, "IDD\t%d\t%d\t%d\n", id,i+1,stats->insertions[i]); } - fprintf(pysam_stdout, "# ST, Substitution types:\n# ST\t[2]id\t[3]type\t[4]count\n"); + fprintf(bcftools_stdout, "# ST, Substitution types:\n# ST\t[2]id\t[3]type\t[4]count\n"); for (id=0; idnstats; id++) { int t; for (t=0; t<15; t++) { if ( t>>2 == (t&3) ) continue; - fprintf(pysam_stdout, "ST\t%d\t%c>%c\t%d\n", id, bcf_int2acgt(t>>2),bcf_int2acgt(t&3),args->stats[id].subst[t]); + fprintf(bcftools_stdout, "ST\t%d\t%c>%c\t%d\n", id, bcf_int2acgt(t>>2),bcf_int2acgt(t&3),args->stats[id].subst[t]); } } if ( args->files->nreaders>1 && args->files->n_smpl ) { - fprintf(pysam_stdout, "SN\t%d\tnumber of samples:\t%d\n", 2, args->files->n_smpl); + fprintf(bcftools_stdout, "SN\t%d\tnumber of samples:\t%d\n", 2, args->files->n_smpl); int x; - for (x=0; x<2; x++) + for (x=0; x<2; x++) // x=0: snps, x=1: indels { gtcmp_t *stats; if ( x==0 ) { - fprintf(pysam_stdout, "# GCsAF, Genotype concordance by non-reference allele frequency (SNPs)\n# GCsAF\t[2]id\t[3]allele frequency\t[4]RR Hom matches\t[5]RA Het matches\t[6]AA Hom matches\t[7]RR Hom mismatches\t[8]RA Het mismatches\t[9]AA Hom mismatches\t[10]dosage r-squared\t[11]number of sites\n"); + fprintf(bcftools_stdout, "# GCsAF, Genotype concordance by non-reference allele frequency (SNPs)\n# GCsAF\t[2]id\t[3]allele frequency\t[4]RR Hom matches\t[5]RA Het matches\t[6]AA Hom matches\t[7]RR Hom mismatches\t[8]RA Het mismatches\t[9]AA Hom mismatches\t[10]dosage r-squared\t[11]number of genotypes\n"); stats = args->af_gts_snps; } else { - fprintf(pysam_stdout, "# GCiAF, Genotype concordance by non-reference allele frequency (indels)\n# GCiAF\t[2]id\t[3]allele frequency\t[4]RR Hom matches\t[5]RA Het matches\t[6]AA Hom matches\t[7]RR Hom mismatches\t[8]RA Het mismatches\t[9]AA Hom mismatches\t[10]dosage r-squared\t[11]number of sites\n"); + fprintf(bcftools_stdout, "# GCiAF, Genotype concordance by non-reference allele frequency (indels)\n# GCiAF\t[2]id\t[3]allele frequency\t[4]RR Hom matches\t[5]RA Het matches\t[6]AA Hom matches\t[7]RR Hom mismatches\t[8]RA Het mismatches\t[9]AA Hom mismatches\t[10]dosage r-squared\t[11]number of genotypes\n"); stats = args->af_gts_indels; } - uint64_t nrd_m[3] = {0,0,0}, nrd_mm[3] = {0,0,0}; + uint64_t nrd_m[4] = {0,0,0,0}, nrd_mm[4] = {0,0,0,0}; // across all bins for (i=0; im_af; i++) { - int j, n = 0; - for (j=0; j<3; j++) + int n = 0; + uint64_t m[4] = {0,0,0,0}, mm[4] = {0,0,0,0}; // in i-th AF bin + for (j=0; j<4; j++) // rr, ra, aa hom, aa het, ./. + for (k=0; k<4; k++) + { + n += stats[i].gt2gt[j][k]; + if ( j==k ) + { + nrd_m[j] += stats[i].gt2gt[j][k]; + m[j] += stats[i].gt2gt[j][k]; + } + else + { + nrd_mm[j] += stats[i].gt2gt[j][k]; + mm[j] += stats[i].gt2gt[j][k]; + } + } + if ( !i || !n ) continue; // skip singleton stats and empty bins + + // Pearson's r2 + double r2 = 0; + if ( stats[i].n ) { - n += stats[i].m[j] + stats[i].mm[j]; - nrd_m[j] += stats[i].m[j]; - nrd_mm[j] += stats[i].mm[j]; + r2 = (stats[i].yx - stats[i].x*stats[i].y/stats[i].n); + r2 /= sqrt((stats[i].xx - stats[i].x*stats[i].x/stats[i].n) * (stats[i].yy - stats[i].y*stats[i].y/stats[i].n)); + r2 *= r2; } - if ( !i || !n ) continue; // skip singleton stats and empty bins - fprintf(pysam_stdout, "GC%cAF\t2\t%f", x==0 ? 's' : 'i', 100.*(i-1)/(args->m_af-1)); - fprintf(pysam_stdout, "\t%"PRId64"\t%"PRId64"\t%"PRId64"", stats[i].m[T2S(GT_HOM_RR)],stats[i].m[T2S(GT_HET_RA)],stats[i].m[T2S(GT_HOM_AA)]); - fprintf(pysam_stdout, "\t%"PRId64"\t%"PRId64"\t%"PRId64"", stats[i].mm[T2S(GT_HOM_RR)],stats[i].mm[T2S(GT_HET_RA)],stats[i].mm[T2S(GT_HOM_AA)]); - fprintf(pysam_stdout, "\t%f\t%"PRId32"\n", stats[i].r2n ? stats[i].r2sum/stats[i].r2n : -1.0, stats[i].r2n); + double af = args->af_bins ? (bin_get_value(args->af_bins,i)+bin_get_value(args->af_bins,i-1))*0.5 : (double)(i-1)/(args->m_af-1); + fprintf(bcftools_stdout, "GC%cAF\t2\t%f", x==0 ? 's' : 'i', af); + fprintf(bcftools_stdout, "\t%"PRId64"\t%"PRId64"\t%"PRId64"", m[T2S(GT_HOM_RR)],m[T2S(GT_HET_RA)],m[T2S(GT_HOM_AA)]); + fprintf(bcftools_stdout, "\t%"PRId64"\t%"PRId64"\t%"PRId64"", mm[T2S(GT_HOM_RR)],mm[T2S(GT_HET_RA)],mm[T2S(GT_HOM_AA)]); + if ( stats[i].n && !isnan(r2) ) fprintf(bcftools_stdout, "\t%f", r2); + else fprintf(bcftools_stdout, "\t"NA_STRING); + fprintf(bcftools_stdout, "\t%.0f\n", stats[i].n); } if ( x==0 ) { - fprintf(pysam_stdout, "# NRD and discordance is calculated as follows:\n"); - fprintf(pysam_stdout, "# m .. number of matches\n"); - fprintf(pysam_stdout, "# x .. number of mismatches\n"); - fprintf(pysam_stdout, "# NRD = (xRR + xRA + xAA) / (xRR + xRA + xAA + mRA + mAA)\n"); - fprintf(pysam_stdout, "# RR discordance = xRR / (xRR + mRR)\n"); - fprintf(pysam_stdout, "# RA discordance = xRA / (xRA + mRA)\n"); - fprintf(pysam_stdout, "# AA discordance = xAA / (xAA + mAA)\n"); - fprintf(pysam_stdout, "# Non-Reference Discordance (NRD), SNPs\n# NRDs\t[2]id\t[3]NRD\t[4]Ref/Ref discordance\t[5]Ref/Alt discordance\t[6]Alt/Alt discordance\n"); + fprintf(bcftools_stdout, "# NRD and discordance is calculated as follows:\n"); + fprintf(bcftools_stdout, "# m .. number of matches\n"); + fprintf(bcftools_stdout, "# x .. number of mismatches\n"); + fprintf(bcftools_stdout, "# NRD = (xRR + xRA + xAA) / (xRR + xRA + xAA + mRA + mAA)\n"); + fprintf(bcftools_stdout, "# RR discordance = xRR / (xRR + mRR)\n"); + fprintf(bcftools_stdout, "# RA discordance = xRA / (xRA + mRA)\n"); + fprintf(bcftools_stdout, "# AA discordance = xAA / (xAA + mAA)\n"); + fprintf(bcftools_stdout, "# Non-Reference Discordance (NRD), SNPs\n# NRDs\t[2]id\t[3]NRD\t[4]Ref/Ref discordance\t[5]Ref/Alt discordance\t[6]Alt/Alt discordance\n"); } else - fprintf(pysam_stdout, "# Non-Reference Discordance (NRD), indels\n# NRDi\t[2]id\t[3]NRD\t[4]Ref/Ref discordance\t[5]Ref/Alt discordance\t[6]Alt/Alt discordance\n"); - uint64_t m = nrd_m[T2S(GT_HET_RA)] + nrd_m[T2S(GT_HOM_AA)]; - uint64_t mm = nrd_mm[T2S(GT_HOM_RR)] + nrd_mm[T2S(GT_HET_RA)] + nrd_mm[T2S(GT_HOM_AA)]; - fprintf(pysam_stdout, "NRD%c\t2\t%f\t%f\t%f\t%f\n", x==0 ? 's' : 'i', + fprintf(bcftools_stdout, "# Non-Reference Discordance (NRD), indels\n# NRDi\t[2]id\t[3]NRD\t[4]Ref/Ref discordance\t[5]Ref/Alt discordance\t[6]Alt/Alt discordance\n"); + uint64_t m = nrd_m[T2S(GT_HET_RA)] + nrd_m[T2S(GT_HOM_AA)] + nrd_m[T2S(GT_HET_AA)]; + uint64_t mm = nrd_mm[T2S(GT_HOM_RR)] + nrd_mm[T2S(GT_HET_RA)] + nrd_mm[T2S(GT_HOM_AA)] + nrd_mm[T2S(GT_HET_AA)]; + fprintf(bcftools_stdout, "NRD%c\t2\t%f\t%f\t%f\t%f\n", x==0 ? 's' : 'i', m+mm ? mm*100.0/(m+mm) : 0, nrd_m[T2S(GT_HOM_RR)]+nrd_mm[T2S(GT_HOM_RR)] ? nrd_mm[T2S(GT_HOM_RR)]*100.0/(nrd_m[T2S(GT_HOM_RR)]+nrd_mm[T2S(GT_HOM_RR)]) : 0, nrd_m[T2S(GT_HET_RA)]+nrd_mm[T2S(GT_HET_RA)] ? nrd_mm[T2S(GT_HET_RA)]*100.0/(nrd_m[T2S(GT_HET_RA)]+nrd_mm[T2S(GT_HET_RA)]) : 0, @@ -1321,45 +1388,102 @@ static void print_stats(args_t *args) ); } - for (x=0; x<2; x++) + for (x=0; x<2; x++) // x=0: snps, x=1: indels { gtcmp_t *stats; - smpl_r_t *smpl_r_array; if ( x==0 ) { - fprintf(pysam_stdout, "# GCsS, Genotype concordance by sample (SNPs)\n# GCsS\t[2]id\t[3]sample\t[4]non-reference discordance rate\t[5]RR Hom matches\t[6]RA Het matches\t[7]AA Hom matches\t[8]RR Hom mismatches\t[9]RA Het mismatches\t[10]AA Hom mismatches\t[11]dosage r-squared\n"); + fprintf(bcftools_stdout, "# GCsS, Genotype concordance by sample (SNPs)\n# GCsS\t[2]id\t[3]sample\t[4]non-reference discordance rate\t[5]RR Hom matches\t[6]RA Het matches\t[7]AA Hom matches\t[8]RR Hom mismatches\t[9]RA Het mismatches\t[10]AA Hom mismatches\t[11]dosage r-squared\n"); stats = args->smpl_gts_snps; - smpl_r_array = args->smpl_r_snps; } else { - fprintf(pysam_stdout, "# GCiS, Genotype concordance by sample (indels)\n# GCiS\t[2]id\t[3]sample\t[4]non-reference discordance rate\t[5]RR Hom matches\t[6]RA Het matches\t[7]AA Hom matches\t[8]RR Hom mismatches\t[9]RA Het mismatches\t[10]AA Hom mismatches\t[11]dosage r-squared\n"); + fprintf(bcftools_stdout, "# GCiS, Genotype concordance by sample (indels)\n# GCiS\t[2]id\t[3]sample\t[4]non-reference discordance rate\t[5]RR Hom matches\t[6]RA Het matches\t[7]AA Hom matches\t[8]RR Hom mismatches\t[9]RA Het mismatches\t[10]AA Hom mismatches\t[11]dosage r-squared\n"); stats = args->smpl_gts_indels; - smpl_r_array = args->smpl_r_indels; } for (i=0; ifiles->n_smpl; i++) { - uint64_t m = stats[i].m[T2S(GT_HET_RA)] + stats[i].m[T2S(GT_HOM_AA)]; - uint64_t mm = stats[i].mm[T2S(GT_HOM_RR)] + stats[i].mm[T2S(GT_HET_RA)] + stats[i].mm[T2S(GT_HOM_AA)]; - // Calculate r by formula 19.2 - Biostatistical Analysis 4th edition - Jerrold H. Zar - smpl_r_t *smpl_r = smpl_r_array + i; - double r = 0.0; - if (smpl_r->n) { - double sum_crossprod = smpl_r->xy-(smpl_r->x*smpl_r->y)/smpl_r->n;//per 17.3 machine formula - double x2_xx = smpl_r->x2-(smpl_r->x*smpl_r->x)/smpl_r->n; - double y2_yy = smpl_r->y2-(smpl_r->y*smpl_r->y)/smpl_r->n; - r = (sum_crossprod)/sqrt(x2_xx*y2_yy); + uint64_t mm = 0, m = stats[i].gt2gt[T2S(GT_HET_RA)][T2S(GT_HET_RA)] + stats[i].gt2gt[T2S(GT_HOM_AA)][T2S(GT_HOM_AA)]; + for (j=0; j<3; j++) + for (k=0; k<3; k++) + if ( j!=k ) mm += stats[i].gt2gt[j][k]; + + // Pearson's r2 + double r2 = 0; + if ( stats[i].n ) + { + r2 = (stats[i].yx - stats[i].x*stats[i].y/stats[i].n); + r2 /= sqrt((stats[i].xx - stats[i].x*stats[i].x/stats[i].n) * (stats[i].yy - stats[i].y*stats[i].y/stats[i].n)); + r2 *= r2; } - fprintf(pysam_stdout, "GC%cS\t2\t%s\t%.3f", x==0 ? 's' : 'i', args->files->samples[i], m+mm ? mm*100.0/(m+mm) : 0); - fprintf(pysam_stdout, "\t%"PRId64"\t%"PRId64"\t%"PRId64"", stats[i].m[T2S(GT_HOM_RR)],stats[i].m[T2S(GT_HET_RA)],stats[i].m[T2S(GT_HOM_AA)]); - fprintf(pysam_stdout, "\t%"PRId64"\t%"PRId64"\t%"PRId64"", stats[i].mm[T2S(GT_HOM_RR)],stats[i].mm[T2S(GT_HET_RA)],stats[i].mm[T2S(GT_HOM_AA)]); - if (smpl_r->n && !isnan(r)) fprintf(pysam_stdout, "\t%f\n", r*r); - else fprintf(pysam_stdout, "\t"NA_STRING"\n"); + fprintf(bcftools_stdout, "GC%cS\t2\t%s\t%.3f", x==0 ? 's' : 'i', args->files->samples[i], m+mm ? mm*100.0/(m+mm) : 0); + fprintf(bcftools_stdout, "\t%"PRId64"\t%"PRId64"\t%"PRId64"", + stats[i].gt2gt[T2S(GT_HOM_RR)][T2S(GT_HOM_RR)], + stats[i].gt2gt[T2S(GT_HET_RA)][T2S(GT_HET_RA)], + stats[i].gt2gt[T2S(GT_HOM_AA)][T2S(GT_HOM_AA)]); + fprintf(bcftools_stdout, "\t%"PRId64"\t%"PRId64"\t%"PRId64"", + stats[i].gt2gt[T2S(GT_HOM_RR)][T2S(GT_HET_RA)] + stats[i].gt2gt[T2S(GT_HOM_RR)][T2S(GT_HOM_AA)], + stats[i].gt2gt[T2S(GT_HET_RA)][T2S(GT_HOM_RR)] + stats[i].gt2gt[T2S(GT_HET_RA)][T2S(GT_HOM_AA)], + stats[i].gt2gt[T2S(GT_HOM_AA)][T2S(GT_HOM_RR)] + stats[i].gt2gt[T2S(GT_HOM_AA)][T2S(GT_HET_RA)]); + if ( stats[i].n && !isnan(r2) ) fprintf(bcftools_stdout, "\t%f\n", r2); + else fprintf(bcftools_stdout, "\t"NA_STRING"\n"); + } + } + for (x=0; x<2; x++) // x=0: snps, x=1: indels + { + //printf("# GCiS, Genotype concordance by sample (indels)\n# GCiS\t[2]id\t[3]sample\t[4]non-reference discordance rate\t[5]RR Hom matches\t[6]RA Het matches\t[7]AA Hom matches\t[8]RR Hom mismatches\t[9]RA Het mismatches\t[10]AA Hom mismatches\t[11]dosage r-squared\n"); + + gtcmp_t *stats; + if ( x==0 ) + { + fprintf(bcftools_stdout, "# GCTs, Genotype concordance table (SNPs)\n# GCTs"); + stats = args->smpl_gts_snps; + } + else + { + fprintf(bcftools_stdout, "# GCTi, Genotype concordance table (indels)\n# GCTi"); + stats = args->smpl_gts_indels; + } + i = 1; + fprintf(bcftools_stdout, "\t[%d]sample", ++i); + fprintf(bcftools_stdout, "\t[%d]RR Hom -> RR Hom", ++i); + fprintf(bcftools_stdout, "\t[%d]RR Hom -> RA Het", ++i); + fprintf(bcftools_stdout, "\t[%d]RR Hom -> AA Hom", ++i); + fprintf(bcftools_stdout, "\t[%d]RR Hom -> AA Het", ++i); + fprintf(bcftools_stdout, "\t[%d]RR Hom -> missing", ++i); + fprintf(bcftools_stdout, "\t[%d]RA Het -> RR Hom", ++i); + fprintf(bcftools_stdout, "\t[%d]RA Het -> RA Het", ++i); + fprintf(bcftools_stdout, "\t[%d]RA Het -> AA Hom", ++i); + fprintf(bcftools_stdout, "\t[%d]RA Het -> AA Het", ++i); + fprintf(bcftools_stdout, "\t[%d]RA Het -> missing", ++i); + fprintf(bcftools_stdout, "\t[%d]AA Hom -> RR Hom", ++i); + fprintf(bcftools_stdout, "\t[%d]AA Hom -> RA Het", ++i); + fprintf(bcftools_stdout, "\t[%d]AA Hom -> AA Hom", ++i); + fprintf(bcftools_stdout, "\t[%d]AA Hom -> AA Het", ++i); + fprintf(bcftools_stdout, "\t[%d]AA Hom -> missing", ++i); + fprintf(bcftools_stdout, "\t[%d]AA Het -> RR Hom", ++i); + fprintf(bcftools_stdout, "\t[%d]AA Het -> RA Het", ++i); + fprintf(bcftools_stdout, "\t[%d]AA Het -> AA Hom", ++i); + fprintf(bcftools_stdout, "\t[%d]AA Het -> AA Het", ++i); + fprintf(bcftools_stdout, "\t[%d]AA Het -> missing", ++i); + fprintf(bcftools_stdout, "\t[%d]missing -> RR Hom", ++i); + fprintf(bcftools_stdout, "\t[%d]missing -> RA Het", ++i); + fprintf(bcftools_stdout, "\t[%d]missing -> AA Hom", ++i); + fprintf(bcftools_stdout, "\t[%d]missing -> AA Het", ++i); + fprintf(bcftools_stdout, "\t[%d]missing -> missing\n", ++i); + + for (i=0; ifiles->n_smpl; i++) + { + fprintf(bcftools_stdout, "GCT%c\t%s", x==0 ? 's' : 'i', args->files->samples[i]); + for (j=0; j<5; j++) + for (k=0; k<5; k++) + fprintf(bcftools_stdout, "\t%"PRId64, stats[i].gt2gt[j][k]); + fprintf(bcftools_stdout, "\n"); } } } - fprintf(pysam_stdout, "# DP, Depth distribution\n# DP\t[2]id\t[3]bin\t[4]number of genotypes\t[5]fraction of genotypes (%%)\t[6]number of sites\t[7]fraction of sites (%%)\n"); + fprintf(bcftools_stdout, "# DP, Depth distribution\n# DP\t[2]id\t[3]bin\t[4]number of genotypes\t[5]fraction of genotypes (%%)\t[6]number of sites\t[7]fraction of sites (%%)\n"); for (id=0; idnstats; id++) { stats_t *stats = &args->stats[id]; @@ -1368,32 +1492,35 @@ static void print_stats(args_t *args) for (i=0; idp.m_vals; i++) { if ( stats->dp.vals[i]==0 && stats->dp_sites.vals[i]==0 ) continue; - fprintf(pysam_stdout, "DP\t%d\t", id); - if ( i==0 ) fprintf(pysam_stdout, "<%d", stats->dp.min); - else if ( i+1==stats->dp.m_vals ) fprintf(pysam_stdout, ">%d", stats->dp.max); - else fprintf(pysam_stdout, "%d", idist_i2bin(&stats->dp,i)); - fprintf(pysam_stdout, "\t%"PRId64"\t%f", stats->dp.vals[i], sum ? stats->dp.vals[i]*100./sum : 0); - fprintf(pysam_stdout, "\t%"PRId64"\t%f\n", stats->dp_sites.vals[i], sum_sites ? stats->dp_sites.vals[i]*100./sum_sites : 0); + fprintf(bcftools_stdout, "DP\t%d\t", id); + if ( i==0 ) fprintf(bcftools_stdout, "<%d", stats->dp.min); + else if ( i+1==stats->dp.m_vals ) fprintf(bcftools_stdout, ">%d", stats->dp.max); + else fprintf(bcftools_stdout, "%d", idist_i2bin(&stats->dp,i)); + fprintf(bcftools_stdout, "\t%"PRId64"\t%f", stats->dp.vals[i], sum ? stats->dp.vals[i]*100./sum : 0); + fprintf(bcftools_stdout, "\t%"PRId64"\t%f\n", stats->dp_sites.vals[i], sum_sites ? stats->dp_sites.vals[i]*100./sum_sites : 0); } } if ( args->files->n_smpl ) { - fprintf(pysam_stdout, "# PSC, Per-sample counts\n# PSC\t[2]id\t[3]sample\t[4]nRefHom\t[5]nNonRefHom\t[6]nHets\t[7]nTransitions\t[8]nTransversions\t[9]nIndels\t[10]average depth\t[11]nSingletons\n"); + fprintf(bcftools_stdout, "# PSC, Per-sample counts. Note that the ref/het/hom counts include only SNPs, for indels see PSI. The rest include both SNPs and indels.\n"); + fprintf(bcftools_stdout, "# PSC\t[2]id\t[3]sample\t[4]nRefHom\t[5]nNonRefHom\t[6]nHets\t[7]nTransitions\t[8]nTransversions\t[9]nIndels\t[10]average depth\t[11]nSingletons" + "\t[12]nHapRef\t[13]nHapAlt\t[14]nMissing\n"); for (id=0; idnstats; id++) { stats_t *stats = &args->stats[id]; for (i=0; ifiles->n_smpl; i++) { float dp = stats->smpl_ndp[i] ? stats->smpl_dp[i]/(float)stats->smpl_ndp[i] : 0; - fprintf(pysam_stdout, "PSC\t%d\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%.1f\t%d\n", id,args->files->samples[i], + fprintf(bcftools_stdout, "PSC\t%d\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%.1f\t%d\t%d\t%d\t%d\n", id,args->files->samples[i], stats->smpl_homRR[i], stats->smpl_homAA[i], stats->smpl_hets[i], stats->smpl_ts[i], - stats->smpl_tv[i], stats->smpl_indels[i],dp, stats->smpl_sngl[i]); + stats->smpl_tv[i], stats->smpl_indels[i],dp, stats->smpl_sngl[i], stats->smpl_hapRef[i], + stats->smpl_hapAlt[i], stats->smpl_missing[i]); } } - fprintf(pysam_stdout, "# PSI, Per-Sample Indels\n# PSI\t[2]id\t[3]sample\t[4]in-frame\t[5]out-frame\t[6]not applicable\t[7]out/(in+out) ratio\t[8]nHets\t[9]nAA\n"); + fprintf(bcftools_stdout, "# PSI, Per-Sample Indels\n# PSI\t[2]id\t[3]sample\t[4]in-frame\t[5]out-frame\t[6]not applicable\t[7]out/(in+out) ratio\t[8]nHets\t[9]nAA\n"); for (id=0; idnstats; id++) { stats_t *stats = &args->stats[id]; @@ -1408,12 +1535,12 @@ static void print_stats(args_t *args) } int nhom = stats->smpl_indel_homs[i]; int nhet = stats->smpl_indel_hets[i]; - fprintf(pysam_stdout, "PSI\t%d\t%s\t%d\t%d\t%d\t%.2f\t%d\t%d\n", id,args->files->samples[i], in,out,na,in+out?1.0*out/(in+out):0,nhet,nhom); + fprintf(bcftools_stdout, "PSI\t%d\t%s\t%d\t%d\t%d\t%.2f\t%d\t%d\n", id,args->files->samples[i], in,out,na,in+out?1.0*out/(in+out):0,nhet,nhom); } } #ifdef HWE_STATS - fprintf(pysam_stdout, "# HWE\n# HWE\t[2]id\t[3]1st ALT allele frequency\t[4]Number of observations\t[5]25th percentile\t[6]median\t[7]75th percentile\n"); + fprintf(bcftools_stdout, "# HWE\n# HWE\t[2]id\t[3]1st ALT allele frequency\t[4]Number of observations\t[5]25th percentile\t[6]median\t[7]75th percentile\n"); for (id=0; idnstats; id++) { stats_t *stats = &args->stats[id]; @@ -1425,29 +1552,31 @@ static void print_stats(args_t *args) for (j=0; jnaf_hwe; j++) sum_tot += ptr[j]; if ( !sum_tot ) continue; + double af = args->af_bins ? (bin_get_value(args->af_bins,i)+bin_get_value(args->af_bins,i-1))*0.5 : (double)(i-1)/(args->m_af-1); + int nprn = 3; - fprintf(pysam_stdout, "HWE\t%d\t%f\t%d",id,100.*(i-1)/(args->m_af-1),sum_tot); + fprintf(bcftools_stdout, "HWE\t%d\t%f\t%d",id,af,sum_tot); for (j=0; jnaf_hwe; j++) { sum_tmp += ptr[j]; float frac = (float)sum_tmp/sum_tot; if ( frac >= 0.75 ) { - while (nprn>0) { fprintf(pysam_stdout, "\t%f", (float)j/args->naf_hwe); nprn--; } + while (nprn>0) { fprintf(bcftools_stdout, "\t%f", (float)j/args->naf_hwe); nprn--; } break; } if ( frac >= 0.5 ) { - while (nprn>1) { fprintf(pysam_stdout, "\t%f", (float)j/args->naf_hwe); nprn--; } + while (nprn>1) { fprintf(bcftools_stdout, "\t%f", (float)j/args->naf_hwe); nprn--; } continue; } if ( frac >= 0.25 ) { - while (nprn>2) { fprintf(pysam_stdout, "\t%f", (float)j/args->naf_hwe); nprn--; } + while (nprn>2) { fprintf(bcftools_stdout, "\t%f", (float)j/args->naf_hwe); nprn--; } } } assert(nprn==0); - fprintf(pysam_stdout, "\n"); + fprintf(bcftools_stdout, "\n"); } } #endif @@ -1456,32 +1585,35 @@ static void print_stats(args_t *args) static void usage(void) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Parses VCF or BCF and produces stats which can be plotted using plot-vcfstats.\n"); - fprintf(pysam_stderr, " When two files are given, the program generates separate stats for intersection\n"); - fprintf(pysam_stderr, " and the complements. By default only sites are compared, -s/-S must given to include\n"); - fprintf(pysam_stderr, " also sample columns.\n"); - fprintf(pysam_stderr, "Usage: bcftools stats [options] []\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Options:\n"); - fprintf(pysam_stderr, " -1, --1st-allele-only include only 1st allele at multiallelic sites\n"); - fprintf(pysam_stderr, " -c, --collapse treat as identical records with , see man page for details [none]\n"); - fprintf(pysam_stderr, " -d, --depth depth distribution: min,max,bin size [0,500,1]\n"); - fprintf(pysam_stderr, " -e, --exclude exclude sites for which the expression is true (see man page for details)\n"); - fprintf(pysam_stderr, " -E, --exons tab-delimited file with exons for indel frameshifts (chr,from,to; 1-based, inclusive, bgzip compressed)\n"); - fprintf(pysam_stderr, " -f, --apply-filters require at least one of the listed FILTER strings (e.g. \"PASS,.\")\n"); - fprintf(pysam_stderr, " -F, --fasta-ref faidx indexed reference sequence file to determine INDEL context\n"); - fprintf(pysam_stderr, " -i, --include select sites for which the expression is true (see man page for details)\n"); - fprintf(pysam_stderr, " -I, --split-by-ID collect stats for sites with ID separately (known vs novel)\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " -s, --samples list of samples for sample stats, \"-\" to include all samples\n"); - fprintf(pysam_stderr, " -S, --samples-file file of samples to include\n"); - fprintf(pysam_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); - fprintf(pysam_stderr, " -u, --user-tstv collect Ts/Tv stats for any tag using the given binning [0:1:100]\n"); - fprintf(pysam_stderr, " -v, --verbose produce verbose per-site and per-sample output\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: Parses VCF or BCF and produces stats which can be plotted using plot-vcfstats.\n"); + fprintf(bcftools_stderr, " When two files are given, the program generates separate stats for intersection\n"); + fprintf(bcftools_stderr, " and the complements. By default only sites are compared, -s/-S must given to include\n"); + fprintf(bcftools_stderr, " also sample columns.\n"); + fprintf(bcftools_stderr, "Usage: bcftools stats [options] []\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Options:\n"); + fprintf(bcftools_stderr, " --af-bins allele frequency bins, a list (0.1,0.5,1) or a file (0.1\\n0.5\\n1)\n"); + fprintf(bcftools_stderr, " --af-tag allele frequency tag to use, by default estimated from AN,AC or GT\n"); + fprintf(bcftools_stderr, " -1, --1st-allele-only include only 1st allele at multiallelic sites\n"); + fprintf(bcftools_stderr, " -c, --collapse treat as identical records with , see man page for details [none]\n"); + fprintf(bcftools_stderr, " -d, --depth depth distribution: min,max,bin size [0,500,1]\n"); + fprintf(bcftools_stderr, " -e, --exclude exclude sites for which the expression is true (see man page for details)\n"); + fprintf(bcftools_stderr, " -E, --exons tab-delimited file with exons for indel frameshifts (chr,from,to; 1-based, inclusive, bgzip compressed)\n"); + fprintf(bcftools_stderr, " -f, --apply-filters require at least one of the listed FILTER strings (e.g. \"PASS,.\")\n"); + fprintf(bcftools_stderr, " -F, --fasta-ref faidx indexed reference sequence file to determine INDEL context\n"); + fprintf(bcftools_stderr, " -i, --include select sites for which the expression is true (see man page for details)\n"); + fprintf(bcftools_stderr, " -I, --split-by-ID collect stats for sites with ID separately (known vs novel)\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " -s, --samples list of samples for sample stats, \"-\" to include all samples\n"); + fprintf(bcftools_stderr, " -S, --samples-file file of samples to include\n"); + fprintf(bcftools_stderr, " -t, --targets similar to -r but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -T, --targets-file similar to -R but streams rather than index-jumps\n"); + fprintf(bcftools_stderr, " -u, --user-tstv collect Ts/Tv stats for any tag using the given binning [0:1:100]\n"); + fprintf(bcftools_stderr, " --threads number of extra decompression threads [0]\n"); + fprintf(bcftools_stderr, " -v, --verbose produce verbose per-site and per-sample output\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } @@ -1496,6 +1628,8 @@ int main_vcfstats(int argc, char *argv[]) static struct option loptions[] = { + {"af-bins",1,0,1}, + {"af-tag",1,0,2}, {"1st-allele-only",0,0,'1'}, {"include",1,0,'i'}, {"exclude",1,0,'e'}, @@ -1514,10 +1648,13 @@ int main_vcfstats(int argc, char *argv[]) {"targets-file",1,0,'T'}, {"fasta-ref",1,0,'F'}, {"user-tstv",1,0,'u'}, + {"threads",1,0,9}, {0,0,0,0} }; while ((c = getopt_long(argc, argv, "hc:r:R:e:s:S:d:i:t:T:F:f:1u:vIE:",loptions,NULL)) >= 0) { switch (c) { + case 1 : args->af_bins_list = optarg; break; + case 2 : args->af_tag = optarg; break; case 'u': add_user_stats(args,optarg); break; case '1': args->first_allele_only = 1; break; case 'F': args->ref_fname = optarg; break; @@ -1549,6 +1686,7 @@ int main_vcfstats(int argc, char *argv[]) case 'I': args->split_by_id = 1; break; case 'e': args->filter_str = optarg; args->filter_logic |= FLT_EXCLUDE; break; case 'i': args->filter_str = optarg; args->filter_logic |= FLT_INCLUDE; break; + case 9 : args->n_threads = strtol(optarg, 0, 0); break; case 'h': case '?': usage(); default: error("Unknown argument: %s\n", optarg); @@ -1573,6 +1711,9 @@ int main_vcfstats(int argc, char *argv[]) error("Failed to read the targets: %s\n", args->targets_list); if ( args->regions_list && bcf_sr_set_regions(args->files, args->regions_list, regions_is_file)<0 ) error("Failed to read the regions: %s\n", args->regions_list); + if ( args->n_threads && bcf_sr_set_threads(args->files, args->n_threads)<0) + error("Failed to create threads\n"); + while (fname) { if ( !bcf_sr_add_reader(args->files, fname) ) diff --git a/bcftools/vcfview.c b/bcftools/vcfview.c index c14075d63..5d523f164 100644 --- a/bcftools/vcfview.c +++ b/bcftools/vcfview.c @@ -1,6 +1,6 @@ /* vcfview.c -- VCF/BCF conversion, view, subset and filter VCF/BCF files. - Copyright (C) 2013-2014 Genome Research Ltd. + Copyright (C) 2013-2018 Genome Research Ltd. Author: Shane McCarthy @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#include #include #include #include @@ -181,10 +182,12 @@ static void init_data(args_t *args) if (args->include_types) { args->include = 0; for (i = 0; i < n; ++i) { - if (strcmp(type_list[i], "snps") == 0) args->include |= VCF_SNP; - else if (strcmp(type_list[i], "indels") == 0) args->include |= VCF_INDEL; - else if (strcmp(type_list[i], "mnps") == 0) args->include |= VCF_MNP; - else if (strcmp(type_list[i], "other") == 0) args->include |= VCF_OTHER; + if (strcmp(type_list[i], "snps") == 0) args->include |= VCF_SNP<<1; + else if (strcmp(type_list[i], "indels") == 0) args->include |= VCF_INDEL<<1; + else if (strcmp(type_list[i], "mnps") == 0) args->include |= VCF_MNP<<1; + else if (strcmp(type_list[i], "other") == 0) args->include |= VCF_OTHER<<1; + else if (strcmp(type_list[i], "ref") == 0) args->include |= VCF_OTHER<<1; + else if (strcmp(type_list[i], "bnd") == 0) args->include |= VCF_BND<<1; else { fprintf(stderr, "[E::%s] unknown type\n", type_list[i]); fprintf(stderr, "Accepted types are snps, indels, mnps, other\n"); @@ -195,10 +198,12 @@ static void init_data(args_t *args) if (args->exclude_types) { args->exclude = 0; for (i = 0; i < n; ++i) { - if (strcmp(type_list[i], "snps") == 0) args->exclude |= VCF_SNP; - else if (strcmp(type_list[i], "indels") == 0) args->exclude |= VCF_INDEL; - else if (strcmp(type_list[i], "mnps") == 0) args->exclude |= VCF_MNP; - else if (strcmp(type_list[i], "other") == 0) args->exclude |= VCF_OTHER; + if (strcmp(type_list[i], "snps") == 0) args->exclude |= VCF_SNP<<1; + else if (strcmp(type_list[i], "indels") == 0) args->exclude |= VCF_INDEL<<1; + else if (strcmp(type_list[i], "mnps") == 0) args->exclude |= VCF_MNP<<1; + else if (strcmp(type_list[i], "other") == 0) args->exclude |= VCF_OTHER<<1; + else if (strcmp(type_list[i], "ref") == 0) args->exclude |= VCF_OTHER<<1; + else if (strcmp(type_list[i], "bnd") == 0) args->exclude |= VCF_BND<<1; else { fprintf(stderr, "[E::%s] unknown type\n", type_list[i]); fprintf(stderr, "Accepted types are snps, indels, mnps, other\n"); @@ -220,7 +225,8 @@ static void init_data(args_t *args) else if (args->output_type & FT_GZ) strcat(modew,"z"); // compressed VCF args->out = hts_open(args->fn_out ? args->fn_out : "-", modew); if ( !args->out ) error("%s: %s\n", args->fn_out,strerror(errno)); - if ( args->n_threads ) hts_set_threads(args->out, args->n_threads); + if ( args->n_threads > 0) + hts_set_opt(args->out, HTS_OPT_THREAD_POOL, args->files->p); // headers: hdr=full header, hsub=subset header, hnull=sites only header if (args->sites_only){ @@ -315,8 +321,8 @@ int subset_vcf(args_t *args, bcf1_t *line) if (args->include || args->exclude) { int line_type = bcf_get_variant_types(line); - if ( args->include && !(line_type&args->include) ) return 0; // include only given variant types - if ( args->exclude && line_type&args->exclude ) return 0; // exclude given variant types + if ( args->include && !((line_type<<1) & args->include) ) return 0; // include only given variant types + if ( args->exclude && (line_type<<1) & args->exclude ) return 0; // exclude given variant types } if ( args->filter ) @@ -336,11 +342,14 @@ int subset_vcf(args_t *args, bcf1_t *line) an += args->ac[i]; } + int update_ac = args->calc_ac; if (args->n_samples) { int non_ref_ac_sub = 0, *ac_sub = (int*) calloc(line->n_allele,sizeof(int)); bcf_subset(args->hdr, line, args->n_samples, args->imap); - if (args->calc_ac) { + if ( args->calc_ac && !bcf_get_fmt(args->hdr,line,"GT") ) update_ac = 0; + if ( update_ac ) + { bcf_calc_ac(args->hsub, line, ac_sub, BCF_UN_FMT); // recalculate AC and AN an = 0; for (i=0; in_allele; i++) { @@ -398,7 +407,7 @@ int subset_vcf(args_t *args, bcf1_t *line) } } - if (args->min_ac) + if (args->min_ac!=-1) { if (args->min_ac_type == ALLELE_NONREF && args->min_ac>non_ref_ac) return 0; // min AC else if (args->min_ac_type == ALLELE_MINOR && args->min_ac>minor_ac) return 0; // min minor AC @@ -406,7 +415,7 @@ int subset_vcf(args_t *args, bcf1_t *line) else if (args->min_ac_type == ALLELE_MAJOR && args->min_ac > major_ac) return 0; // min major AC else if (args->min_ac_type == ALLELE_NONMAJOR && args->min_ac > an-major_ac) return 0; // min non-major AC } - if (args->max_ac) + if (args->max_ac!=-1) { if (args->max_ac_type == ALLELE_NONREF && args->max_acmax_ac_type == ALLELE_MINOR && args->max_acmax_ac_type == ALLELE_MAJOR && args->max_ac < major_ac) return 0; // max major AC else if (args->max_ac_type == ALLELE_NONMAJOR && args->max_ac < an-major_ac) return 0; // max non-major AC } - if (args->min_af) + if (args->min_af!=-1) { if (an == 0) return 0; // freq not defined, skip site if (args->min_af_type == ALLELE_NONREF && args->min_af>non_ref_ac/(double)an) return 0; // min AF @@ -423,7 +432,7 @@ int subset_vcf(args_t *args, bcf1_t *line) else if (args->min_af_type == ALLELE_MAJOR && args->min_af > major_ac/(double)an) return 0; // min major AF else if (args->min_af_type == ALLELE_NONMAJOR && args->min_af > (an-major_ac)/(double)an) return 0; // min non-major AF } - if (args->max_af) + if (args->max_af!=-1) { if (an == 0) return 0; // freq not defined, skip site if (args->max_af_type == ALLELE_NONREF && args->max_afuncalled == FLT_INCLUDE && an > 0) return 0; // select uncalled if (args->uncalled == FLT_EXCLUDE && an == 0) return 0; // skip if uncalled } - if (args->calc_ac && args->update_info) { + if (update_ac && args->update_info) { bcf_update_info_int32(args->hdr, line, "AC", &args->ac[1], line->n_allele-1); bcf_update_info_int32(args->hdr, line, "AN", &an, 1); } if (args->trim_alts) { int ret = bcf_trim_alleles(args->hsub ? args->hsub : args->hdr, line); - if ( ret==-1 ) error("Error: some GT index is out of bounds at %s:%d\n", bcf_seqname(args->hsub ? args->hsub : args->hdr, line), line->pos+1); + if ( ret<0 ) error("Error: Could not trim alleles at %s:%d\n", bcf_seqname(args->hsub ? args->hsub : args->hdr, line), line->pos+1); } if (args->phased) { int phased = bcf_all_phased(args->hdr, line); @@ -494,7 +503,7 @@ static void usage(args_t *args) fprintf(stderr, " -R, --regions-file restrict to regions listed in a file\n"); fprintf(stderr, " -t, --targets [^] similar to -r but streams rather than index-jumps. Exclude regions with \"^\" prefix\n"); fprintf(stderr, " -T, --targets-file [^] similar to -R but streams rather than index-jumps. Exclude regions with \"^\" prefix\n"); - fprintf(stderr, " --threads number of extra output compression threads [0]\n"); + fprintf(stderr, " --threads number of extra (de)compression threads [0]\n"); fprintf(stderr, "\n"); fprintf(stderr, "Subset options:\n"); fprintf(stderr, " -a, --trim-alt-alleles trim alternate alleles not seen in the subset\n"); @@ -515,7 +524,7 @@ static void usage(args_t *args) fprintf(stderr, " -q/Q, --min-af/--max-af [:] minimum/maximum frequency for non-reference (nref), 1st alternate (alt1), least frequent\n"); fprintf(stderr, " (minor), most frequent (major) or sum of all but most frequent (nonmajor) alleles [nref]\n"); fprintf(stderr, " -u/U, --uncalled/--exclude-uncalled select/exclude sites without a called genotype\n"); - fprintf(stderr, " -v/V, --types/--exclude-types select/exclude comma-separated list of variant types: snps,indels,mnps,other [null]\n"); + fprintf(stderr, " -v/V, --types/--exclude-types select/exclude comma-separated list of variant types: snps,indels,mnps,ref,bnd,other [null]\n"); fprintf(stderr, " -x/X, --private/--exclude-private select/exclude sites where the non-reference alleles are exclusive (private) to the subset samples\n"); fprintf(stderr, "\n"); exit(1); @@ -533,6 +542,7 @@ int main_vcfview(int argc, char *argv[]) args->output_type = FT_VCF; args->n_threads = 0; args->record_cmd_line = 1; + args->min_ac = args->max_ac = args->min_af = args->max_af = -1; int targets_is_file = 0, regions_is_file = 0; static struct option loptions[] = @@ -726,6 +736,7 @@ int main_vcfview(int argc, char *argv[]) error("Failed to read the targets: %s\n", args->targets_list); } + if ( bcf_sr_set_threads(args->files, args->n_threads)<0 ) error("Failed to create threads\n"); if ( !bcf_sr_add_reader(args->files, fname) ) error("Failed to open %s: %s\n", fname,bcf_sr_strerror(args->files->errnum)); init_data(args); @@ -734,6 +745,8 @@ int main_vcfview(int argc, char *argv[]) bcf_hdr_write(args->out, out_hdr); else if ( args->output_type & FT_BCF ) error("BCF output requires header, cannot proceed with -H\n"); + + int ret = 0; if (!args->header_only) { while ( bcf_sr_next_line(args->files) ) @@ -743,10 +756,12 @@ int main_vcfview(int argc, char *argv[]) if ( subset_vcf(args, line) ) bcf_write1(args->out, out_hdr, line); } + ret = args->files->errnum; + if ( ret ) fprintf(stderr,"Error: %s\n", bcf_sr_strerror(args->files->errnum)); } hts_close(args->out); destroy_data(args); bcf_sr_destroy(args->files); free(args); - return 0; + return ret; } diff --git a/bcftools/vcfview.c.pysam.c b/bcftools/vcfview.c.pysam.c index 53b7c5330..4de3ac452 100644 --- a/bcftools/vcfview.c.pysam.c +++ b/bcftools/vcfview.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcfview.c -- VCF/BCF conversion, view, subset and filter VCF/BCF files. - Copyright (C) 2013-2014 Genome Research Ltd. + Copyright (C) 2013-2018 Genome Research Ltd. Author: Shane McCarthy @@ -25,6 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#include #include #include #include @@ -114,7 +115,7 @@ static void init_data(args_t *args) for (i=0; iforce_samples) { - fprintf(pysam_stderr, "Warn: exclude called for sample that does not exist in header: \"%s\"... skipping\n", smpl[i]); + fprintf(bcftools_stderr, "Warn: exclude called for sample that does not exist in header: \"%s\"... skipping\n", smpl[i]); } else { error("Error: exclude called for sample that does not exist in header: \"%s\". Use \"--force-samples\" to ignore this error.\n", smpl[i]); } @@ -135,7 +136,7 @@ static void init_data(args_t *args) for (i=0; iforce_samples) { - fprintf(pysam_stderr, "Warn: subset called for sample that does not exist in header: \"%s\"... skipping\n", smpl[i]); + fprintf(bcftools_stderr, "Warn: subset called for sample that does not exist in header: \"%s\"... skipping\n", smpl[i]); continue; } else { error("Error: subset called for sample that does not exist in header: \"%s\". Use \"--force-samples\" to ignore this error.\n", smpl[i]); @@ -149,7 +150,7 @@ static void init_data(args_t *args) free(smpl); khash_str2int_destroy(hdr_samples); if (args->n_samples == 0) { - fprintf(pysam_stderr, "Warn: subsetting has removed all samples\n"); + fprintf(bcftools_stderr, "Warn: subsetting has removed all samples\n"); args->sites_only = 1; } } @@ -160,7 +161,7 @@ static void init_data(args_t *args) // determine variant types to include/exclude if (args->include_types || args->exclude_types) { if (args->include_types && args->exclude_types) { - fprintf(pysam_stderr, "Error: only supply one of --include-types, --exclude-types options\n"); + fprintf(bcftools_stderr, "Error: only supply one of --include-types, --exclude-types options\n"); exit(1); } char **type_list = 0; @@ -183,13 +184,15 @@ static void init_data(args_t *args) if (args->include_types) { args->include = 0; for (i = 0; i < n; ++i) { - if (strcmp(type_list[i], "snps") == 0) args->include |= VCF_SNP; - else if (strcmp(type_list[i], "indels") == 0) args->include |= VCF_INDEL; - else if (strcmp(type_list[i], "mnps") == 0) args->include |= VCF_MNP; - else if (strcmp(type_list[i], "other") == 0) args->include |= VCF_OTHER; + if (strcmp(type_list[i], "snps") == 0) args->include |= VCF_SNP<<1; + else if (strcmp(type_list[i], "indels") == 0) args->include |= VCF_INDEL<<1; + else if (strcmp(type_list[i], "mnps") == 0) args->include |= VCF_MNP<<1; + else if (strcmp(type_list[i], "other") == 0) args->include |= VCF_OTHER<<1; + else if (strcmp(type_list[i], "ref") == 0) args->include |= VCF_OTHER<<1; + else if (strcmp(type_list[i], "bnd") == 0) args->include |= VCF_BND<<1; else { - fprintf(pysam_stderr, "[E::%s] unknown type\n", type_list[i]); - fprintf(pysam_stderr, "Accepted types are snps, indels, mnps, other\n"); + fprintf(bcftools_stderr, "[E::%s] unknown type\n", type_list[i]); + fprintf(bcftools_stderr, "Accepted types are snps, indels, mnps, other\n"); exit(1); } } @@ -197,13 +200,15 @@ static void init_data(args_t *args) if (args->exclude_types) { args->exclude = 0; for (i = 0; i < n; ++i) { - if (strcmp(type_list[i], "snps") == 0) args->exclude |= VCF_SNP; - else if (strcmp(type_list[i], "indels") == 0) args->exclude |= VCF_INDEL; - else if (strcmp(type_list[i], "mnps") == 0) args->exclude |= VCF_MNP; - else if (strcmp(type_list[i], "other") == 0) args->exclude |= VCF_OTHER; + if (strcmp(type_list[i], "snps") == 0) args->exclude |= VCF_SNP<<1; + else if (strcmp(type_list[i], "indels") == 0) args->exclude |= VCF_INDEL<<1; + else if (strcmp(type_list[i], "mnps") == 0) args->exclude |= VCF_MNP<<1; + else if (strcmp(type_list[i], "other") == 0) args->exclude |= VCF_OTHER<<1; + else if (strcmp(type_list[i], "ref") == 0) args->exclude |= VCF_OTHER<<1; + else if (strcmp(type_list[i], "bnd") == 0) args->exclude |= VCF_BND<<1; else { - fprintf(pysam_stderr, "[E::%s] unknown type\n", type_list[i]); - fprintf(pysam_stderr, "Accepted types are snps, indels, mnps, other\n"); + fprintf(bcftools_stderr, "[E::%s] unknown type\n", type_list[i]); + fprintf(bcftools_stderr, "Accepted types are snps, indels, mnps, other\n"); exit(1); } } @@ -222,7 +227,8 @@ static void init_data(args_t *args) else if (args->output_type & FT_GZ) strcat(modew,"z"); // compressed VCF args->out = hts_open(args->fn_out ? args->fn_out : "-", modew); if ( !args->out ) error("%s: %s\n", args->fn_out,strerror(errno)); - if ( args->n_threads ) hts_set_threads(args->out, args->n_threads); + if ( args->n_threads > 0) + hts_set_opt(args->out, HTS_OPT_THREAD_POOL, args->files->p); // headers: hdr=full header, hsub=subset header, hnull=sites only header if (args->sites_only){ @@ -292,7 +298,7 @@ int bcf_all_phased(const bcf_hdr_t *header, bcf1_t *line) case BCF_BT_INT8: BRANCH_INT(int8_t, bcf_int8_vector_end); break; case BCF_BT_INT16: BRANCH_INT(int16_t, bcf_int16_vector_end); break; case BCF_BT_INT32: BRANCH_INT(int32_t, bcf_int32_vector_end); break; - default: fprintf(pysam_stderr, "[E::%s] todo: fmt_type %d\n", __func__, fmt_ptr->type); exit(1); break; + default: fprintf(bcftools_stderr, "[E::%s] todo: fmt_type %d\n", __func__, fmt_ptr->type); exit(1); break; } #undef BRANCH_INT if (!sample_phased) { @@ -317,8 +323,8 @@ int subset_vcf(args_t *args, bcf1_t *line) if (args->include || args->exclude) { int line_type = bcf_get_variant_types(line); - if ( args->include && !(line_type&args->include) ) return 0; // include only given variant types - if ( args->exclude && line_type&args->exclude ) return 0; // exclude given variant types + if ( args->include && !((line_type<<1) & args->include) ) return 0; // include only given variant types + if ( args->exclude && (line_type<<1) & args->exclude ) return 0; // exclude given variant types } if ( args->filter ) @@ -338,11 +344,14 @@ int subset_vcf(args_t *args, bcf1_t *line) an += args->ac[i]; } + int update_ac = args->calc_ac; if (args->n_samples) { int non_ref_ac_sub = 0, *ac_sub = (int*) calloc(line->n_allele,sizeof(int)); bcf_subset(args->hdr, line, args->n_samples, args->imap); - if (args->calc_ac) { + if ( args->calc_ac && !bcf_get_fmt(args->hdr,line,"GT") ) update_ac = 0; + if ( update_ac ) + { bcf_calc_ac(args->hsub, line, ac_sub, BCF_UN_FMT); // recalculate AC and AN an = 0; for (i=0; in_allele; i++) { @@ -400,7 +409,7 @@ int subset_vcf(args_t *args, bcf1_t *line) } } - if (args->min_ac) + if (args->min_ac!=-1) { if (args->min_ac_type == ALLELE_NONREF && args->min_ac>non_ref_ac) return 0; // min AC else if (args->min_ac_type == ALLELE_MINOR && args->min_ac>minor_ac) return 0; // min minor AC @@ -408,7 +417,7 @@ int subset_vcf(args_t *args, bcf1_t *line) else if (args->min_ac_type == ALLELE_MAJOR && args->min_ac > major_ac) return 0; // min major AC else if (args->min_ac_type == ALLELE_NONMAJOR && args->min_ac > an-major_ac) return 0; // min non-major AC } - if (args->max_ac) + if (args->max_ac!=-1) { if (args->max_ac_type == ALLELE_NONREF && args->max_acmax_ac_type == ALLELE_MINOR && args->max_acmax_ac_type == ALLELE_MAJOR && args->max_ac < major_ac) return 0; // max major AC else if (args->max_ac_type == ALLELE_NONMAJOR && args->max_ac < an-major_ac) return 0; // max non-major AC } - if (args->min_af) + if (args->min_af!=-1) { if (an == 0) return 0; // freq not defined, skip site if (args->min_af_type == ALLELE_NONREF && args->min_af>non_ref_ac/(double)an) return 0; // min AF @@ -425,7 +434,7 @@ int subset_vcf(args_t *args, bcf1_t *line) else if (args->min_af_type == ALLELE_MAJOR && args->min_af > major_ac/(double)an) return 0; // min major AF else if (args->min_af_type == ALLELE_NONMAJOR && args->min_af > (an-major_ac)/(double)an) return 0; // min non-major AF } - if (args->max_af) + if (args->max_af!=-1) { if (an == 0) return 0; // freq not defined, skip site if (args->max_af_type == ALLELE_NONREF && args->max_afuncalled == FLT_INCLUDE && an > 0) return 0; // select uncalled if (args->uncalled == FLT_EXCLUDE && an == 0) return 0; // skip if uncalled } - if (args->calc_ac && args->update_info) { + if (update_ac && args->update_info) { bcf_update_info_int32(args->hdr, line, "AC", &args->ac[1], line->n_allele-1); bcf_update_info_int32(args->hdr, line, "AN", &an, 1); } if (args->trim_alts) { int ret = bcf_trim_alleles(args->hsub ? args->hsub : args->hdr, line); - if ( ret==-1 ) error("Error: some GT index is out of bounds at %s:%d\n", bcf_seqname(args->hsub ? args->hsub : args->hdr, line), line->pos+1); + if ( ret<0 ) error("Error: Could not trim alleles at %s:%d\n", bcf_seqname(args->hsub ? args->hsub : args->hdr, line), line->pos+1); } if (args->phased) { int phased = bcf_all_phased(args->hdr, line); @@ -481,45 +490,45 @@ void set_allele_type (int *atype, char *atype_string) static void usage(args_t *args) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: VCF/BCF conversion, view, subset and filter VCF/BCF files.\n"); - fprintf(pysam_stderr, "Usage: bcftools view [options] [region1 [...]]\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Output options:\n"); - fprintf(pysam_stderr, " -G, --drop-genotypes drop individual genotype information (after subsetting if -s option set)\n"); - fprintf(pysam_stderr, " -h/H, --header-only/--no-header print the header only/suppress the header in VCF output\n"); - fprintf(pysam_stderr, " -l, --compression-level [0-9] compression level: 0 uncompressed, 1 best speed, 9 best compression [%d]\n", args->clevel); - fprintf(pysam_stderr, " --no-version do not append version and command line to the header\n"); - fprintf(pysam_stderr, " -o, --output-file output file name [pysam_stdout]\n"); - fprintf(pysam_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); - fprintf(pysam_stderr, " -r, --regions restrict to comma-separated list of regions\n"); - fprintf(pysam_stderr, " -R, --regions-file restrict to regions listed in a file\n"); - fprintf(pysam_stderr, " -t, --targets [^] similar to -r but streams rather than index-jumps. Exclude regions with \"^\" prefix\n"); - fprintf(pysam_stderr, " -T, --targets-file [^] similar to -R but streams rather than index-jumps. Exclude regions with \"^\" prefix\n"); - fprintf(pysam_stderr, " --threads number of extra output compression threads [0]\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Subset options:\n"); - fprintf(pysam_stderr, " -a, --trim-alt-alleles trim alternate alleles not seen in the subset\n"); - fprintf(pysam_stderr, " -I, --no-update do not (re)calculate INFO fields for the subset (currently INFO/AC and INFO/AN)\n"); - fprintf(pysam_stderr, " -s, --samples [^] comma separated list of samples to include (or exclude with \"^\" prefix)\n"); - fprintf(pysam_stderr, " -S, --samples-file [^] file of samples to include (or exclude with \"^\" prefix)\n"); - fprintf(pysam_stderr, " --force-samples only warn about unknown subset samples\n"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Filter options:\n"); - fprintf(pysam_stderr, " -c/C, --min-ac/--max-ac [:] minimum/maximum count for non-reference (nref), 1st alternate (alt1), least frequent\n"); - fprintf(pysam_stderr, " (minor), most frequent (major) or sum of all but most frequent (nonmajor) alleles [nref]\n"); - fprintf(pysam_stderr, " -f, --apply-filters require at least one of the listed FILTER strings (e.g. \"PASS,.\")\n"); - fprintf(pysam_stderr, " -g, --genotype [^] require one or more hom/het/missing genotype or, if prefixed with \"^\", exclude sites with hom/het/missing genotypes\n"); - fprintf(pysam_stderr, " -i/e, --include/--exclude select/exclude sites for which the expression is true (see man page for details)\n"); - fprintf(pysam_stderr, " -k/n, --known/--novel select known/novel sites only (ID is not/is '.')\n"); - fprintf(pysam_stderr, " -m/M, --min-alleles/--max-alleles minimum/maximum number of alleles listed in REF and ALT (e.g. -m2 -M2 for biallelic sites)\n"); - fprintf(pysam_stderr, " -p/P, --phased/--exclude-phased select/exclude sites where all samples are phased\n"); - fprintf(pysam_stderr, " -q/Q, --min-af/--max-af [:] minimum/maximum frequency for non-reference (nref), 1st alternate (alt1), least frequent\n"); - fprintf(pysam_stderr, " (minor), most frequent (major) or sum of all but most frequent (nonmajor) alleles [nref]\n"); - fprintf(pysam_stderr, " -u/U, --uncalled/--exclude-uncalled select/exclude sites without a called genotype\n"); - fprintf(pysam_stderr, " -v/V, --types/--exclude-types select/exclude comma-separated list of variant types: snps,indels,mnps,other [null]\n"); - fprintf(pysam_stderr, " -x/X, --private/--exclude-private select/exclude sites where the non-reference alleles are exclusive (private) to the subset samples\n"); - fprintf(pysam_stderr, "\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "About: VCF/BCF conversion, view, subset and filter VCF/BCF files.\n"); + fprintf(bcftools_stderr, "Usage: bcftools view [options] [region1 [...]]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Output options:\n"); + fprintf(bcftools_stderr, " -G, --drop-genotypes drop individual genotype information (after subsetting if -s option set)\n"); + fprintf(bcftools_stderr, " -h/H, --header-only/--no-header print the header only/suppress the header in VCF output\n"); + fprintf(bcftools_stderr, " -l, --compression-level [0-9] compression level: 0 uncompressed, 1 best speed, 9 best compression [%d]\n", args->clevel); + fprintf(bcftools_stderr, " --no-version do not append version and command line to the header\n"); + fprintf(bcftools_stderr, " -o, --output-file output file name [bcftools_stdout]\n"); + fprintf(bcftools_stderr, " -O, --output-type b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n"); + fprintf(bcftools_stderr, " -r, --regions restrict to comma-separated list of regions\n"); + fprintf(bcftools_stderr, " -R, --regions-file restrict to regions listed in a file\n"); + fprintf(bcftools_stderr, " -t, --targets [^] similar to -r but streams rather than index-jumps. Exclude regions with \"^\" prefix\n"); + fprintf(bcftools_stderr, " -T, --targets-file [^] similar to -R but streams rather than index-jumps. Exclude regions with \"^\" prefix\n"); + fprintf(bcftools_stderr, " --threads number of extra (de)compression threads [0]\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Subset options:\n"); + fprintf(bcftools_stderr, " -a, --trim-alt-alleles trim alternate alleles not seen in the subset\n"); + fprintf(bcftools_stderr, " -I, --no-update do not (re)calculate INFO fields for the subset (currently INFO/AC and INFO/AN)\n"); + fprintf(bcftools_stderr, " -s, --samples [^] comma separated list of samples to include (or exclude with \"^\" prefix)\n"); + fprintf(bcftools_stderr, " -S, --samples-file [^] file of samples to include (or exclude with \"^\" prefix)\n"); + fprintf(bcftools_stderr, " --force-samples only warn about unknown subset samples\n"); + fprintf(bcftools_stderr, "\n"); + fprintf(bcftools_stderr, "Filter options:\n"); + fprintf(bcftools_stderr, " -c/C, --min-ac/--max-ac [:] minimum/maximum count for non-reference (nref), 1st alternate (alt1), least frequent\n"); + fprintf(bcftools_stderr, " (minor), most frequent (major) or sum of all but most frequent (nonmajor) alleles [nref]\n"); + fprintf(bcftools_stderr, " -f, --apply-filters require at least one of the listed FILTER strings (e.g. \"PASS,.\")\n"); + fprintf(bcftools_stderr, " -g, --genotype [^] require one or more hom/het/missing genotype or, if prefixed with \"^\", exclude sites with hom/het/missing genotypes\n"); + fprintf(bcftools_stderr, " -i/e, --include/--exclude select/exclude sites for which the expression is true (see man page for details)\n"); + fprintf(bcftools_stderr, " -k/n, --known/--novel select known/novel sites only (ID is not/is '.')\n"); + fprintf(bcftools_stderr, " -m/M, --min-alleles/--max-alleles minimum/maximum number of alleles listed in REF and ALT (e.g. -m2 -M2 for biallelic sites)\n"); + fprintf(bcftools_stderr, " -p/P, --phased/--exclude-phased select/exclude sites where all samples are phased\n"); + fprintf(bcftools_stderr, " -q/Q, --min-af/--max-af [:] minimum/maximum frequency for non-reference (nref), 1st alternate (alt1), least frequent\n"); + fprintf(bcftools_stderr, " (minor), most frequent (major) or sum of all but most frequent (nonmajor) alleles [nref]\n"); + fprintf(bcftools_stderr, " -u/U, --uncalled/--exclude-uncalled select/exclude sites without a called genotype\n"); + fprintf(bcftools_stderr, " -v/V, --types/--exclude-types select/exclude comma-separated list of variant types: snps,indels,mnps,ref,bnd,other [null]\n"); + fprintf(bcftools_stderr, " -x/X, --private/--exclude-private select/exclude sites where the non-reference alleles are exclusive (private) to the subset samples\n"); + fprintf(bcftools_stderr, "\n"); exit(1); } @@ -535,6 +544,7 @@ int main_vcfview(int argc, char *argv[]) args->output_type = FT_VCF; args->n_threads = 0; args->record_cmd_line = 1; + args->min_ac = args->max_ac = args->min_af = args->max_af = -1; int targets_is_file = 0, regions_is_file = 0; static struct option loptions[] = @@ -728,6 +738,7 @@ int main_vcfview(int argc, char *argv[]) error("Failed to read the targets: %s\n", args->targets_list); } + if ( bcf_sr_set_threads(args->files, args->n_threads)<0 ) error("Failed to create threads\n"); if ( !bcf_sr_add_reader(args->files, fname) ) error("Failed to open %s: %s\n", fname,bcf_sr_strerror(args->files->errnum)); init_data(args); @@ -736,6 +747,8 @@ int main_vcfview(int argc, char *argv[]) bcf_hdr_write(args->out, out_hdr); else if ( args->output_type & FT_BCF ) error("BCF output requires header, cannot proceed with -H\n"); + + int ret = 0; if (!args->header_only) { while ( bcf_sr_next_line(args->files) ) @@ -745,10 +758,12 @@ int main_vcfview(int argc, char *argv[]) if ( subset_vcf(args, line) ) bcf_write1(args->out, out_hdr, line); } + ret = args->files->errnum; + if ( ret ) fprintf(bcftools_stderr,"Error: %s\n", bcf_sr_strerror(args->files->errnum)); } hts_close(args->out); destroy_data(args); bcf_sr_destroy(args->files); free(args); - return 0; + return ret; } diff --git a/bcftools/vcmp.c.pysam.c b/bcftools/vcmp.c.pysam.c index f1345e273..80b242048 100644 --- a/bcftools/vcmp.c.pysam.c +++ b/bcftools/vcmp.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* vcmp.c -- reference allele utility functions. diff --git a/bcftools/version.c.pysam.c b/bcftools/version.c.pysam.c index af5453276..236d93553 100644 --- a/bcftools/version.c.pysam.c +++ b/bcftools/version.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "bcftools.pysam.h" /* version.c -- report version numbers for plugins. @@ -41,7 +41,7 @@ void error(const char *format, ...) { va_list ap; va_start(ap, format); - vfprintf(pysam_stderr, format, ap); + vfprintf(bcftools_stderr, format, ap); va_end(ap); exit(-1); } diff --git a/bcftools/version.h b/bcftools/version.h index 05929f550..29d20170f 100644 --- a/bcftools/version.h +++ b/bcftools/version.h @@ -1 +1 @@ -#define BCFTOOLS_VERSION "1.3.1" +#define BCFTOOLS_VERSION "1.7" diff --git a/benchmark/AlignedSegment_bench.py b/benchmark/AlignedSegment_bench.py deleted file mode 100644 index 98286d044..000000000 --- a/benchmark/AlignedSegment_bench.py +++ /dev/null @@ -1,43 +0,0 @@ -"""Benchmarking module for AlignedSegment functionality""" - -import timeit - -iterations = 10000 -repeats = 5 - -setup_binary_tag = """ -import pysam -import array -read = pysam.AlignedSegment() -read.set_tag('FZ', array.array('H', range(1000))) -""" - -setup_binary_tag_from_file = """ -import pysam -with pysam.AlignmentFile("../tests/pysam_data/example_btag.bam", "rb") as inf: - read = inf.fetch().next() -""" - -def test_read_binary_get_tag(read): - tags = read.get_tag('FZ') - -def test_read_and_process_binary_get_tag(read): - tags = sum(read.get_tag('FZ')) - -tests = ( - ("test_read_binary_get_tag", "setup_binary_tag"), - ("test_read_binary_get_tag", "setup_binary_tag_from_file"), - ("test_read_and_process_binary_get_tag", "setup_binary_tag"), - ) - -for repeat in range(repeats): - print ("# repeat=", repeat) - for testf, setup_name in tests: - setup = locals()[setup_name] - setup += """\nfrom __main__ import %s""" % testf - #try: - t = timeit.timeit("%s(read)" % testf, number=iterations, setup=setup) - #except AttributeError, msg: - # print msg - # continue - print ("%5.2f\t%s\t%s" % (t,testf, setup_name)) diff --git a/benchmark/tabix_bench.py b/benchmark/tabix_bench.py deleted file mode 100644 index 431cd6fe4..000000000 --- a/benchmark/tabix_bench.py +++ /dev/null @@ -1,76 +0,0 @@ -import gzip -import pysam -import timeit - -iterations = 5 -repeats = 100 -print ("repeats=", repeats, "iterations=", iterations) - -fn_compressed = '/tmp/windows_small.bed.gz' -fn_uncompressed = '/tmp/windows_small.bed' - -def test_python_compressed(): - '''iterate through with python.''' - f = gzip.open( fn_compressed) - l = len( [x.encode().split("\t") for x in f]) - -def test_python_uncompressed(): - '''iterate through with python.''' - f = open( "windows_small.bed") - l = len( [x.split("\t") for x in f]) - -def test_fetch_plain(): - """Stupid test function""" - f = pysam.Tabixfile(fn_compressed) - l = len( list(f.fetch()) ) - -def test_fetch_parsed(): - """Stupid test function""" - f = pysam.Tabixfile(fn_compressed) - l = len( list(f.fetch( parser = pysam.asBed())) ) - -def test_iterator_generic_compressed(): - f = gzip.open(fn_compressed) - l = len( list( pysam.tabix_generic_iterator( f, parser = pysam.asBed() ))) - -def test_iterator_generic_uncompressed(): - f = open("windows_small.bed") - l = len( list( pysam.tabix_generic_iterator( f, parser = pysam.asBed() ))) - -def test_iterator_parsed_compressed(): - f = gzip.open(fn_compressed) - l = len( list( pysam.tabix_iterator( f, parser = pysam.asBed() ))) - -def test_iterator_parsed_uncompressed(): - f = open("windows_small.bed") - l = len( list( pysam.tabix_iterator( f, parser = pysam.asBed() ))) - -def test_iterator_file_compressed(): - f = gzip.open("windows_small.bed") - l = len( list( pysam.tabix_file_iterator( f, parser = pysam.asBed() ))) - -def test_iterator_file_uncompressed(): - f = open("windows_small.bed") - l = len( list( pysam.tabix_file_iterator( f, parser = pysam.asBed() ))) - -tests = ( test_python_compressed, - test_python_uncompressed, - test_fetch_plain, - test_fetch_parsed, - test_iterator_generic_compressed, - test_iterator_generic_uncompressed, - test_iterator_parsed_compressed, - test_iterator_parsed_uncompressed, - test_iterator_file_compressed, - test_iterator_file_uncompressed ) - -for repeat in range( repeats ): - print ("# repeat=", repeat) - for test in tests: - try: - t = timeit.timeit( test, number = iterations ) - except AttributeError: - continue - print ("%5.2f\t%s" % (t,str(test))) - - diff --git a/benchmark/windows_small.bed.gz.tbi b/benchmark/windows_small.bed.gz.tbi deleted file mode 100644 index 500fbe742..000000000 Binary files a/benchmark/windows_small.bed.gz.tbi and /dev/null differ diff --git a/buildwheels.sh b/buildwheels.sh index a5987f181..ae0d953e4 100755 --- a/buildwheels.sh +++ b/buildwheels.sh @@ -22,7 +22,7 @@ if ! grep -q docker /proc/1/cgroup; then exec docker run --rm -v $(pwd):/io quay.io/pypa/manylinux1_x86_64 /io/$0 fi -yum install -y zlib-devel +yum install -y zlib-devel bzip2-devel xz-devel # Python 2.6 is not supported rm -r /opt/python/cp26* diff --git a/cy_build.py b/cy_build.py index 29af588bc..fae705557 100644 --- a/cy_build.py +++ b/cy_build.py @@ -60,26 +60,22 @@ def build_extension(self, ext): ext.library_dirs.append(os.path.join(self.build_lib, "pysam")) if sys.platform == 'darwin': + # The idea is to give shared libraries an install name of the form + # `@rpath/`, and to set the rpath equal to + # @loader_path. This will allow Python packages to find the library + # in the expected place, while still giving enough flexibility to + # external applications to link against the library. relative_module_path = ext.name.replace(".", os.sep) + get_config_vars()["SO"] - - if "develop" in sys.argv or "test" in sys.argv: - # develop-mode and tests use local directory - pkg_root = os.path.dirname(__file__) - linker_path = os.path.join(pkg_root, relative_module_path) - elif "bdist_wheel" in sys.argv or is_pip_install(): - # making a wheel, or pip is secretly involved - linker_path = os.path.join("@rpath", relative_module_path) - else: - # making an egg: `python setup.py install` default behavior - egg_name = '%s.egg' % self._get_egg_name() - linker_path = os.path.join("@rpath", egg_name, relative_module_path) + library_path = os.path.join( + "@rpath", os.path.basename(relative_module_path) + ) if not ext.extra_link_args: ext.extra_link_args = [] ext.extra_link_args += ['-dynamiclib', - '-rpath', get_python_lib(), + '-rpath', '@loader_path', '-Wl,-headerpad_max_install_names', - '-Wl,-install_name,%s' % linker_path, + '-Wl,-install_name,%s' % library_path, '-Wl,-x'] else: if not ext.extra_link_args: diff --git a/doc/api.rst b/doc/api.rst index 686c60dda..8e766863e 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -88,11 +88,11 @@ The above code outputs:: Commands available in :term:`csamtools` are available as simple function calls. For example:: - pysam.sort("ex1.bam", "output") + pysam.sort("-o", "output.bam", "ex1.bam") corresponds to the command line:: - samtools sort ex1.bam output + samtools sort -o output.bam ex1.bam Analogous to :class:`~pysam.AlignmentFile`, a :class:`~pysam.TabixFile` allows fast random access to compressed and diff --git a/doc/benchmarking.rst b/doc/benchmarking.rst new file mode 100644 index 000000000..1ec0d43c5 --- /dev/null +++ b/doc/benchmarking.rst @@ -0,0 +1,68 @@ +============ +Benchmarking +============ + +Latest benchmarking results:: + + ------------------------------------------------------------------------------------------------------------------------ benchmark: 57 tests ------------------------------------------------------------------------------------------------------------------------ + Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations + --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + test_set_binary_tag 93.8382 (1.0) 199.8786 (1.0) 96.1554 (1.0) 2.6241 (1.0) 95.7036 (1.0) 1.2442 (1.0) 276;303 10,399.8372 (1.0) 3170 1 + test_fasta_iteration_long_sequences_without_persistence 145.3292 (1.55) 296.4940 (1.48) 176.5367 (1.84) 30.0896 (11.47) 167.2544 (1.75) 25.1532 (20.22) 840;579 5,664.5438 (0.54) 4972 1 + test_fasta_iteration_long_sequences_as_file 149.0638 (1.59) 312.6319 (1.56) 177.2990 (1.84) 30.5218 (11.63) 168.6383 (1.76) 27.7516 (22.30) 669;510 5,640.1883 (0.54) 4493 1 + test_fasta_iteration_long_sequences 150.3211 (1.60) 429.9153 (2.15) 176.7384 (1.84) 30.7021 (11.70) 167.5002 (1.75) 21.7482 (17.48) 682;647 5,658.0803 (0.54) 4845 1 + test_fasta_iteration_short_sequences_as_file 190.6604 (2.03) 395.8736 (1.98) 216.6984 (2.25) 32.8710 (12.53) 208.9385 (2.18) 16.8057 (13.51) 291;326 4,614.7086 (0.44) 3205 1 + test_read_python_uncompressed 214.1297 (2.28) 450.2051 (2.25) 234.6956 (2.44) 33.3642 (12.71) 223.4913 (2.34) 15.0129 (12.07) 140;221 4,260.8375 (0.41) 2043 1 + test_fastq_iteration_short_sequences_as_file 217.5961 (2.32) 420.1643 (2.10) 238.0264 (2.48) 30.4469 (11.60) 228.8874 (2.39) 15.5573 (12.50) 209;235 4,201.2146 (0.40) 2877 1 + test_iterate_file_uncompressed 225.5719 (2.40) 481.0989 (2.41) 249.7603 (2.60) 40.7266 (15.52) 239.5548 (2.50) 15.9908 (12.85) 209;327 4,003.8387 (0.38) 3627 1 + test_iterate_file_compressed 257.5517 (2.74) 576.6843 (2.89) 287.2536 (2.99) 49.8803 (19.01) 277.4149 (2.90) 14.3824 (11.56) 126;248 3,481.2446 (0.33) 3023 1 + test_iterate_generic_uncompressed 344.8855 (3.68) 712.5959 (3.57) 370.9369 (3.86) 46.2477 (17.62) 365.0384 (3.81) 15.7915 (12.69) 54;83 2,695.8763 (0.26) 2240 1 + test_iterate_parsed_uncompressed 349.3819 (3.72) 765.3460 (3.83) 378.1446 (3.93) 54.2199 (20.66) 369.5488 (3.86) 15.4320 (12.40) 48;69 2,644.4910 (0.25) 1638 1 + test_read_python_compressed 462.0645 (4.92) 836.2234 (4.18) 493.6158 (5.13) 51.2946 (19.55) 485.5469 (5.07) 11.4385 (9.19) 28;46 2,025.8670 (0.19) 906 1 + test_iterate_parsed_compressed 586.5730 (6.25) 1,050.1631 (5.25) 632.5464 (6.58) 82.6438 (31.49) 608.1080 (6.35) 20.1799 (16.22) 115;143 1,580.9117 (0.15) 1474 1 + test_iterate_generic_compressed 587.7707 (6.26) 1,093.4286 (5.47) 639.6830 (6.65) 85.2593 (32.49) 612.6408 (6.40) 19.9433 (16.03) 105;144 1,563.2743 (0.15) 1260 1 + test_fasta_iteration_short_sequences_without_persistence 725.2563 (7.73) 1,091.6069 (5.46) 774.6549 (8.06) 53.0901 (20.23) 751.8455 (7.86) 45.0788 (36.23) 172;110 1,290.8974 (0.12) 1276 1 + test_read_binary_tag 817.2598 (8.71) 1,232.0559 (6.16) 902.7002 (9.39) 87.7807 (33.45) 871.5261 (9.11) 17.4227 (14.00) 39;55 1,107.7875 (0.11) 331 1 + test_fastq_iteration_short_sequences_without_persistence 840.3640 (8.96) 1,201.5756 (6.01) 870.9679 (9.06) 35.8709 (13.67) 866.1682 (9.05) 15.9768 (12.84) 53;85 1,148.1480 (0.11) 1124 1 + test_count_number_lines_from_sam_with_pysam 2,755.6140 (29.37) 9,656.9806 (48.31) 2,963.2206 (30.82) 729.0077 (277.81) 2,814.3115 (29.41) 106.2388 (85.38) 8;14 337.4707 (0.03) 281 1 + test_fasta_iteration_short_sequences 2,905.5942 (30.96) 3,674.1439 (18.38) 2,982.3892 (31.02) 90.9585 (34.66) 2,941.2108 (30.73) 96.1348 (77.26) 27;7 335.3016 (0.03) 302 1 + test_fastq_iteration_short_sequences 3,601.3145 (38.38) 4,065.5769 (20.34) 3,671.8361 (38.19) 71.5348 (27.26) 3,635.1625 (37.98) 81.5415 (65.53) 43;10 272.3433 (0.03) 243 1 + test_count_number_lines_from_bam_with_pysam 4,178.8872 (44.53) 12,063.5536 (60.35) 4,395.9713 (45.72) 794.3991 (302.73) 4,240.1757 (44.31) 67.0198 (53.86) 6;19 227.4810 (0.02) 205 1 + test_build_depth_from_bam_with_pysam 6,290.2980 (67.03) 6,788.0806 (33.96) 6,420.3862 (66.77) 126.5447 (48.22) 6,357.6270 (66.43) 94.3104 (75.80) 35;29 155.7539 (0.01) 145 1 + test_build_depth_with_filter_from_bam_with_pysam 6,935.8926 (73.91) 8,309.5767 (41.57) 7,085.6801 (73.69) 221.5069 (84.41) 7,005.6170 (73.20) 74.4388 (59.83) 14;27 141.1297 (0.01) 139 1 + test_build_query_positions_from_bam_with_pysam 8,729.2437 (93.02) 16,836.6525 (84.23) 9,173.2902 (95.40) 1,057.4321 (402.97) 8,885.4395 (92.84) 264.7634 (212.79) 3;9 109.0121 (0.01) 103 1 + test_build_mapping_qualities_from_bam_with_pysam 8,805.0570 (93.83) 15,829.8910 (79.20) 9,274.7475 (96.46) 964.6925 (367.63) 9,004.7438 (94.09) 354.9103 (285.24) 4;9 107.8196 (0.01) 106 1 + test_build_query_qualities_from_bam_with_pysam 8,947.6798 (95.35) 16,756.8158 (83.83) 9,272.9117 (96.44) 1,008.7759 (384.43) 9,017.0493 (94.22) 217.2068 (174.57) 3;5 107.8410 (0.01) 94 1 + test_build_query_bases_from_bam_with_samtoolspysam 9,149.0448 (97.50) 9,776.0092 (48.91) 9,208.3405 (95.77) 86.1889 (32.85) 9,190.2809 (96.03) 34.1963 (27.48) 5;7 108.5972 (0.01) 84 1 + test_count_number_lines_from_bam_with_samtoolspipe 10,431.4052 (111.16) 13,431.7447 (67.20) 11,052.2360 (114.94) 445.8241 (169.90) 11,014.8042 (115.09) 492.6044 (395.91) 17;3 90.4794 (0.01) 90 1 + test_count_number_lines_from_bam_with_samtools 12,057.8520 (128.50) 13,537.5429 (67.73) 12,595.0708 (130.99) 381.1799 (145.26) 12,499.5783 (130.61) 457.8107 (367.94) 25;1 79.3961 (0.01) 73 1 + test_count_number_lines_from_sam_with_samtoolspipe 12,434.8756 (132.51) 14,234.1983 (71.21) 13,034.1032 (135.55) 371.0373 (141.40) 13,049.9089 (136.36) 464.8147 (373.57) 21;3 76.7218 (0.01) 72 1 + test_build_query_bases_from_bam_with_pysam 12,811.6887 (136.53) 19,972.7099 (99.92) 13,268.7908 (137.99) 1,103.9459 (420.70) 13,023.1632 (136.08) 202.3596 (162.64) 4;6 75.3648 (0.01) 76 1 + test_build_pileup_from_bam_with_samtoolspipe 13,480.7490 (143.66) 15,413.4836 (77.11) 13,968.3817 (145.27) 362.1282 (138.00) 13,917.4843 (145.42) 447.9736 (360.04) 12;3 71.5903 (0.01) 66 1 + test_count_number_lines_from_sam_with_samtools 13,963.2300 (148.80) 15,936.2238 (79.73) 14,442.5627 (150.20) 340.4846 (129.75) 14,395.4996 (150.42) 339.3036 (272.70) 12;2 69.2398 (0.01) 59 1 + test_build_pileup_from_bam_with_samtoolsshell 15,140.2969 (161.34) 16,469.8567 (82.40) 15,525.9034 (161.47) 256.0741 (97.59) 15,526.7641 (162.24) 318.5044 (255.98) 13;2 64.4085 (0.01) 51 1 + test_build_depth_from_bam_with_samtoolsshell 15,291.4841 (162.96) 16,387.9916 (81.99) 15,656.5365 (162.83) 217.2420 (82.79) 15,609.9945 (163.11) 258.9412 (208.11) 16;2 63.8711 (0.01) 57 1 + test_build_query_bases_from_bam_with_samtoolspipe 15,478.0652 (164.94) 17,068.8462 (85.40) 16,072.5749 (167.15) 327.6668 (124.87) 16,040.5049 (167.61) 428.1597 (344.11) 18;2 62.2178 (0.01) 60 1 + test_build_query_bases_from_bam_with_samtoolsshell 15,765.5794 (168.01) 17,102.8059 (85.57) 16,305.4955 (169.57) 367.6865 (140.12) 16,256.2486 (169.86) 593.9230 (477.34) 20;0 61.3290 (0.01) 57 1 + test_build_depth_from_bam_with_samtoolspipe 16,024.7944 (170.77) 25,804.2309 (129.10) 17,041.3497 (177.23) 1,522.0046 (580.01) 16,726.8887 (174.78) 767.1015 (616.52) 1;1 58.6808 (0.01) 40 1 + test_build_query_qualities_from_bam_with_samtoolspipe 16,275.7467 (173.44) 18,501.0433 (92.56) 17,262.6517 (179.53) 642.2656 (244.76) 17,255.3696 (180.30) 1,060.3429 (852.20) 20;0 57.9285 (0.01) 51 1 + test_build_pileup_from_bam_with_pysam 16,632.5681 (177.25) 19,306.6560 (96.59) 17,037.7162 (177.19) 531.0751 (202.38) 16,870.8330 (176.28) 279.1677 (224.37) 3;4 58.6933 (0.01) 32 1 + test_build_mapping_qualities_from_bam_with_samtoolspipe 17,398.3518 (185.41) 18,481.6569 (92.46) 17,832.1261 (185.45) 294.9103 (112.39) 17,837.8206 (186.39) 511.8400 (411.37) 21;0 56.0786 (0.01) 52 1 + test_build_query_names_from_bam_with_pysam 31,534.0199 (336.05) 38,316.2647 (191.70) 32,677.2804 (339.84) 1,371.6101 (522.70) 32,179.0325 (336.24) 1,392.1391 (>1000.0) 3;1 30.6023 (0.00) 30 1 + test_fetch_plain 43,747.1233 (466.20) 48,690.7829 (243.60) 44,573.8085 (463.56) 1,170.8588 (446.20) 44,067.5411 (460.46) 1,436.5837 (>1000.0) 3;1 22.4347 (0.00) 22 1 + test_build_query_positions_from_bam_with_samtoolspipe 46,316.5548 (493.58) 53,700.3577 (268.66) 48,235.6640 (501.64) 1,861.0317 (709.21) 47,625.2194 (497.63) 2,603.7074 (>1000.0) 6;1 20.7315 (0.00) 21 1 + test_build_query_bases_with_reference_from_bam_with_samtoolspysam 51,565.1479 (549.51) 53,523.1121 (267.78) 51,778.6650 (538.49) 424.4621 (161.76) 51,656.8925 (539.76) 110.5051 (88.81) 1;4 19.3130 (0.00) 20 1 + test_build_query_bases_with_reference_from_bam_with_pysam 58,850.6740 (627.15) 62,164.5451 (311.01) 60,161.6779 (625.67) 1,120.6101 (427.05) 59,595.2785 (622.71) 1,995.0196 (>1000.0) 7;0 16.6219 (0.00) 16 1 + test_iterate_file_large_uncompressed 59,419.9076 (633.22) 69,053.0874 (345.48) 62,825.7126 (653.38) 3,805.1150 (>1000.0) 60,805.1391 (635.35) 6,407.6949 (>1000.0) 3;0 15.9170 (0.00) 14 1 + test_iterate_file_large_compressed 63,986.9571 (681.89) 74,156.9120 (371.01) 68,370.8835 (711.05) 3,254.6200 (>1000.0) 67,221.2075 (702.39) 4,770.3525 (>1000.0) 5;0 14.6261 (0.00) 16 1 + test_read_python_large_uncompressed 67,611.8080 (720.51) 89,112.1533 (445.83) 73,631.8916 (765.76) 5,978.7052 (>1000.0) 71,702.4822 (749.21) 7,856.0165 (>1000.0) 2;1 13.5811 (0.00) 13 1 + test_fetch_parsed 72,237.5344 (769.81) 81,976.9856 (410.13) 74,540.4099 (775.21) 2,326.3668 (886.54) 74,016.3419 (773.39) 1,579.0667 (>1000.0) 1;1 13.4155 (0.00) 14 1 + test_build_query_bases_from_bam_with_pysam_pileups 75,841.3766 (808.21) 87,975.1425 (440.14) 79,393.9784 (825.68) 3,516.2458 (>1000.0) 79,346.7313 (829.09) 5,217.5033 (>1000.0) 2;0 12.5954 (0.00) 13 1 + test_build_query_bases_with_reference_from_bam_with_samtoolspipe 131,162.9396 (>1000.0) 132,858.8147 (664.70) 131,838.0199 (>1000.0) 595.6090 (226.98) 131,801.5633 (>1000.0) 956.9665 (769.11) 2;0 7.5851 (0.00) 8 1 + test_iterate_parsed_large_uncompressed 132,991.8914 (>1000.0) 140,153.4099 (701.19) 134,101.5892 (>1000.0) 2,452.3161 (934.54) 133,218.1590 (>1000.0) 396.3616 (318.56) 1;1 7.4570 (0.00) 8 1 + test_iterate_generic_large_uncompressed 134,743.7277 (>1000.0) 142,329.4526 (712.08) 138,167.4954 (>1000.0) 3,346.7773 (>1000.0) 136,839.1849 (>1000.0) 6,541.1879 (>1000.0) 4;0 7.2376 (0.00) 8 1 + test_read_python_large_compressed 175,127.6311 (>1000.0) 190,855.1529 (954.86) 181,702.9339 (>1000.0) 5,756.2207 (>1000.0) 181,221.0185 (>1000.0) 8,577.6616 (>1000.0) 2;0 5.5035 (0.00) 6 1 + test_iterate_parsed_large_compressed 231,405.7611 (>1000.0) 243,728.8519 (>1000.0) 239,037.8296 (>1000.0) 5,212.7778 (>1000.0) 241,544.3324 (>1000.0) 8,062.6113 (>1000.0) 1;0 4.1834 (0.00) 5 1 + test_iterate_generic_large_compressed 235,042.3876 (>1000.0) 256,518.8371 (>1000.0) 242,535.5468 (>1000.0) 8,272.5197 (>1000.0) 240,163.0748 (>1000.0) 8,360.1568 (>1000.0) 1;0 4.1231 (0.00) 5 1 + --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + diff --git a/doc/conf.py b/doc/conf.py index 5b92efdbf..375aa559f 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -57,12 +57,13 @@ .. _samtools: http://samtools.sourceforge.net/ .. _bcftools: https://samtools.github.io/bcftools/bcftools.html .. _htslib: http://www.htslib.org/ -.. _tabix: http://samtools.sourceforge.net/tabix.shtml/ +.. _tabix: http://samtools.sourceforge.net/tabix.shtml .. _Galaxy: https://main.g2.bx.psu.edu/ .. _cython: http://cython.org/ .. _python: http://python.org/ .. _pyximport: http://www.prescod.net/pyximport/ - +.. _conda: https://conda.io/docs/ +.. _bioconda: https://bioconda.github.io/ ''' autosummary_generate = True diff --git a/doc/developer.rst b/doc/developer.rst index 9931854f3..09ae832e1 100644 --- a/doc/developer.rst +++ b/doc/developer.rst @@ -17,22 +17,26 @@ directories: make -C doc html :file:`tests` - Code and data for testing + Code and data for testing and benchmarking :file:`htslib` Source code from htslib_ shipped with pysam. See - :file:`setup.py` about importing. + :file:`import.py` about importing. :file:`samtools` Source code from :term:`csamtools` shipped with pysam. See - :file:`setup.py` about importing. + :file:`import.py` about importing. + +:file:`bcftools` + Source code from :term:`cbcftools` shipped with pysam. See + :file:`import.py` about importing. Importing new versions of htslib and samtools ============================================= -See instructions in :file:`setup.py` to import the latest -version of htslib_ and samtools_. +See instructions in :file:`import.py` to import the latest +version of htslib_, samtools_ and bcftools_. Unit testing ============ @@ -40,10 +44,18 @@ Unit testing Unit tests are in the :file:`tests` directory. To run all unit tests, run:: - nosetests -s -v tests + pytest tests + +Benchmarking +============ + +To run the benchmarking suite, make sure that `pytest-benchmark +`_ is installed. To run +all benchmarks, type:: + + pytest tests/*_bench.py -Note to use the ``-s/--nocapture`` option to prevent nosetests from -captpuring standard output. +See :ref:`Benchmarking` for more on this topic. Contributors ============ diff --git a/doc/faq.rst b/doc/faq.rst index d5d84c40c..e07e1cfe3 100644 --- a/doc/faq.rst +++ b/doc/faq.rst @@ -261,4 +261,18 @@ cython_ when building pysam. There are some known incompatibilities: .. _global interpreter lock: https://en.wikipedia.org/wiki/Global_interpreter_lock +ImportError: cannot import name csamtools +========================================= + +In version 0.10.0 and onwards, all pysam extension modules contain a +``lib``-prefix. This facilates linking against pysam extension modules +with compilers that require to start with ``lib``. As a consequence, +all code using pysam extension modules directly will need to be +adapted. For example, for example:: + + cimport pysam.csamtools + +will become:: + + cimport pysam.libcamtools diff --git a/doc/glossary.rst b/doc/glossary.rst index e35a53711..3e739f902 100644 --- a/doc/glossary.rst +++ b/doc/glossary.rst @@ -1,4 +1,4 @@ -======== + ======== Glossary ======== @@ -6,12 +6,16 @@ Glossary :sorted: cigar - An alignment format string. In the python API, the cigar alignment is - presented as a list of tuples ``(operation,length)``. For example, the tuple - ``[ (0,3), (1,5), (0,2) ]`` refers to an alignment with 3 matches, 5 insertions - and another 2 matches. - - region + Stands for Compact Idiosyncratic Gapped Alignment Report and + represents a compressed (run-length encoded) pairwise alignment + format. It was first defined by the Exonerate Aligner, but was alter + adapted and adopted as part of the :term:`SAM` standard and many other + aligners. In the Python API, the cigar alignment is presented as a + list of tuples ``(operation,length)``. For example, the tuple ``[ + (0,3), (1,5), (0,2) ]`` refers to an alignment with 3 matches, 5 + insertions and another 2 matches. + + region A genomic region, stated relative to a reference sequence. A region consists of reference name ('chr1'), start (10000), and end (20000). Start and end can be omitted for regions spanning @@ -22,27 +26,30 @@ Glossary :term:`samtools` compatible region strings such as 'chr1:10000:20000', which are closed, i.e., both positions 10,000 and 20,000 are part of the interval. - + column Reads that are aligned to a base in the :term:`reference` sequence. - + tid The :term:`target` id. The target id is 0 or a positive integer mapping to - entries within the sequence dictionary in the header section of + entries within the sequence dictionary in the header section of a :term:`TAM` file or :term:`BAM` file. - Reference + contig The sequence that a :term:`tid` refers to. For example ``chr1``, ``contig123``. + Reference + Synonym for contig + SAM A textual format for storing genomic alignment information. BAM - Binary SAM format. BAM files are binary formatted, indexed and + Binary SAM format. BAM files are binary formatted, indexed and allow random access. TAM - Text SAM file. TAM files are human readable files of + Text SAM file. TAM files are human readable files of tab-separated fields. TAM files do not allow random access. sam file @@ -50,7 +57,7 @@ Glossary be a :term:`BAM` file or a :term:`TAM` file. pileup - Pileup + Pileup samtools The samtools_ package. @@ -63,7 +70,7 @@ Glossary target The sequence that a read has been aligned to. Target - sequences have bot a numerical identifier (:term:`tid`) + sequences have bot a numerical identifier (:term:`tid`) and an alphanumeric name (:term:`Reference`). tabix file @@ -73,15 +80,15 @@ Glossary is indexed by chromosomal coordinates. tabix row - A row in a :term:`tabix file`. Fields within a row are - tab-separated. + A row in a :term:`tabix file`. Fields within a row are + tab-separated. soft clipping soft clipped In alignments with soft clipping part of the query sequence are not aligned. The unaligned query sequence is still part - of the alignment record. This is in difference to + of the alignment record. This is in difference to :term:`hard clipped` reads. hard clipping @@ -92,7 +99,7 @@ Glossary recorded in the :term:`cigar` alignment, but the removed sequence will not be part of the alignment record, in contrast to :term:`soft clipped` reads. - + VCF Variant call format diff --git a/doc/index.rst b/doc/index.rst index da3602886..01b2a8e82 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -18,8 +18,8 @@ This module provides a low-level wrapper around the htslib_ C-API as using cython and a high-level, pythonic API for convenient access to the data within genomic file formats. -The current version wraps *htslib-1.3*, *samtools-1.3* and -*bcftools-1.3*. +The current version wraps *htslib-1.7*, *samtools-1.7* and +*bcftools-1.6*. To install the latest release, type:: @@ -39,6 +39,7 @@ Contents faq.rst developer.rst release.rst + benchmarking.rst glossary.rst Indices and tables diff --git a/doc/installation.rst b/doc/installation.rst index 2dbf2a472..535f4bce3 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -4,12 +4,32 @@ Installing pysam ================ +Pysam can be installed through conda_, pypi_ and from the repository. +The recommended way to install pysam is through conda/bioconda. + +Conda installation +================== + +To install pysam in your current conda_ environment, type:: + + conda config --add channels r + conda config --add channels bioconda + conda install pysam + +This will install pysam from the bioconda_ channel and automatically +makes sure that dependencies are installed. Also, compilation flags +will be set automatically, which will potentially save a lot of +trouble on OS X. + +Pypi installation +================= + Pysam provides a python interface to the functionality contained within the htslib_ C library. There are two ways that these two can be combined, ``builtin`` and ``external``. Builtin -======= +------- The typical installation will be through pypi_:: @@ -34,7 +54,7 @@ For example:: pip install pysam External -======== +-------- pysam can be combined with an externally installed htslib_ library. This is a good way to avoid duplication of libraries. To link @@ -49,12 +69,40 @@ Note that the location of the file :file:`libhts.so` needs to be known to the linker once you run pysam, for example by setting the environment-varirable `LD_LIBRARY_PATH`. -cython -====== +Note that generally the pysam and htslib version need to be +compatible. See the release notes for more information. + +Installation from repository +============================ pysam depends on cython_ to provide the connectivity to the htslib_ C library. The installation of the source tarball (:file:`.tar.gz`) -python 2.7 contains pre-built C-files and cython needs not be present -during installation. However, when installing the source tarball on -python 3 or building from the repository, these pre-built C-files are -not present and cython needs to be installed beforehand. +contains pre-built C-files and cython needs not be present +during installation. However, when installing from the repository, +cython needs to be installed beforehand. + +To install from repository, type:: + + python setup.py install + +For compilation options, see the section on Pypi installation above. + +Requirements +============ + +Depending on the installation method, requirements for building pysam differ. + +When installing through conda_, dependencies will be resolved by the +package manager. The pip_ installation and installation from source +require a C compiler and its standard libraries as well as all +requirements for building htslib. Htslib requirements are listed in +the htslib/INSTALL file. + +Installing from the repository will require cython_ to be installed. + + + + + + + diff --git a/doc/release.rst b/doc/release.rst index 1d378f35e..1a255b140 100644 --- a/doc/release.rst +++ b/doc/release.rst @@ -2,6 +2,215 @@ Release notes ============= +Release 0.14.1 +============== + +This is mostly a bugfix release, though bcftools has now also been +upgraded to 1.7.0. + +* [#621] Add a warning to count_coverage when an alignment has an + empty QUAL field +* [#635] Speed-up of AlignedSegment.find_intro() +* treat border case of all bases in pileup column below quality score +* [#634] Fix access to pileup reference_sequence + + +Release 0.14.0 +============== + +This release wraps htslib/samtools versions 1.7.0. + +* SAM/BAM/CRAM headers are now managed by a separate AlignmentHeader + class. +* AlignmentFile.header.as_dict() returns an ordered dictionary. +* Use "stop" instead of "end" to ensure consistency to + VariantFile. The end designations have been kept for backwards + compatibility. + +* [#611] and [#293] CRAM repeated fetch now works, each iterator + reloads index if multiple_iterators=True +* [#608] pysam now wraps htslib 1.7 and samtools 1.7. +* [#580] reference_name and next_reference_name can now be set to "*" + (will be converted to None to indicate an unmapped location) +* [#302] providing no coordinate to count_coverage will not count from + start/end of contig. +* [#325] @SQ records will be automatically added to header if they are + absent from text section of header. +* [#529] add get_forward_sequence() and get_forward_qualities() + methods +* [#577] add from_string() and to_dict()/from_dict() methods to + AlignedSegment. Rename tostring() to to_string() throughout for + consistency +* [#589] return None from build_alignment_sequence if no MD tag is set +* [#528] add PileupColumn.__len__ method + +Backwards incompatible changes: + +* AlignmentFile.header now returns an AlignmentHeader object. Use + AlignmentFile.header.to_dict() to get the dictionary as + previously. Most dictionary accessor methods (keys(), values(), + __getitem__, ...) have been implemented to ensure some level of + backwards compatibility when only reading. + + The rationale for this change is to have consistency between + AlignmentFile and VariantFile. + +* AlignmentFile and FastaFile now raise IOError instead of OSError + +Medium term we plan to have a 1.0 release. The pysam +interface has grown over the years and the API is cluttered with +deprecated names (Samfile, getrname(), gettid(), ...). To work towards +this, the next release (0.15.0) will yield DeprecationWarnings +for any parts of the API that are considered obsolete and will not be +in 1.0. Once 1.0 has been reached, we will use semantic versioning. + +Release 0.13.0 +=============== + +This release wraps htslib/samtools/bcftools versions 1.6.0 and +contains a series of bugfixes. + +* [#544] reading header from remote TabixFiles now works. +* [#531] add missing tag types H and A. A python float will now be + added as 'f' type instead of 'd' type. +* [#543] use FastaFile instead of Fastafile in pileup. +* [#546] set is_modified flag in setAttribute so updated attributes + are output. +* [#537] allow tabix index files to be created in a custom location. +* [#530] add get_index_statistics() method + + +Release 0.12.0.1 +================ + +Bugfix release to solve compilation issue due to missinge +bcftools/config.h file. + +Release 0.12.0 +============== + +This release wraps htslib/samtools/bcftools versions 1.5.0 and +contains a series of bugfixes. + +* [#473] A new FastxRecord class that can be instantiated from class and + modified in-place. Replaces PersistentFastqProxy. +* [#521] In AligmentFile, Simplify file detection logic and allow remote index files + * Removed attempts to guess data and index file names; this is magic left + to htslib. + * Removed file existence check prior to opening files with htslib + * Better error checking after opening files that raise the appropriate + error (IOError for when errno is set, ValueError otherwise for backward + compatibility). + * Report IO errors when loading an index by name. + * Allow remote indices (tested using S3 signed URLs). + * Document filepath_index and make it an alias for index_filename. + * Added a require_index parameter to AlignmentFile +* [#526] handle unset ref when creating new records +* [#513] fix bcf_translate to skip deleted FORMAT fields to avoid + segfaults +* [#516] expose IO errors via IOError exceptions +* [#487] add tabix line_skip, remove 'pileup' preset +* add FastxRecord, replaces PersistentFastqProxy (still present for + backwards compatibility) +* [#496] upgrade to htslib/samtools/bcftools versions 1.5 +* add start/stop to AlignmentFile.fetch() to be consistent with + VariantFile.fetch(). "end" is kept for backwards compatibility. +* [#512] add get_index_statistics() method to AlignmentFile. + +Upcoming changes: + +In the next release we are plannig to separate the header information +from AlignmentFile into a separate class AlignmentHeader. This layout +is similar to VariantFile/VariantHeader. With this change we will +ensure that an AlignedSegment record will be linked to a header so +that chromosome names can be automatically translated from the numeric +representation. As a consequence, the way new AlignedSegment records +are created will need to change as the constructor requires a header:: + + header = pysam.AlignmentHeader( + reference_names=["chr1", "chr2"], + reference_lengths=[1000, 1000]) + + read = pysam.AlignedSegment(header) + +This will affect all code that instantiates AlignedSegment objects +directly. We have not yet merged to allow users to provide feed-back. +The pull-request is here: https://github.com/pysam-developers/pysam/pull/518 +Please comment on github. + +Release 0.11.2.2 +================ + +Bugfix release to address two issues: + +* Changes in 0.11.2.1 broke the GTF/GFF3 parser. Corrected and + more tests have been added. +* [#479] Correct VariantRecord edge cases described in issue + +Release 0.11.2.1 +================ + +Release to fix release tar-ball containing 0.11.1 pre-compiled +C-files. + +Release 0.11.2 +============== + +This release wraps htslib/samtools/bcfools versions 1.4.1 in response +to a security fix in these libraries. Additionaly the following +issues have been fixed: + +* [#452] add GFF3 support for tabix parsers +* [#461] Multiple fixes related to VariantRecordInfo and handling of INFO/END +* [#447] limit query name to 251 characters (only partially addresses issue) + +VariantFile and related object fixes + +* Restore VariantFile.\_\_dealloc\_\_ +* Correct handling of bcf_str_missing in bcf_array_to_object and + bcf_object_to_array +* Added update() and pop() methods to some dict-like proxy objects +* scalar INFO entries could not be set again after being deleted +* VariantRecordInfo.__delitem__ now allows unset flags to be deleted without + raising a KeyError +* Multiple other fixes for VariantRecordInfo methods +* INFO/END is now accessible only via VariantRecord.stop and + VariantRecord.rlen. Even if present behind the scenes, it is no longer + accessible via VariantRecordInfo. +* Add argument to issue a warning instead of an exception if input appears + to be truncated + +Other features and fixes: + +* Make AlignmentFile \_\_dealloc\_\_ and close more + stringent +* Add argument AlignmentFile to issue a warning instead of an + exception if input appears to be truncated + +Release 0.11.1 +============== + +Bugfix release + +* [#440] add deprecated 'always' option to infer_query_length for backwards compatibility. + +Release 0.11.0 +============== + +This release wraps the latest versions of htslib/samtools/bcftools and +implements a few bugfixes. + +* [#413] Wrap HTSlib/Samtools/BCFtools 1.4 +* [#422] Fix missing pysam.sort.usage() message +* [#411] Fix BGZfile initialization bug +* [#412] Add seek support for BGZFile +* [#395] Make BGZfile iterable +* [#433] Correct getQueryEnd +* [#419] Export SAM enums such as pysam.CMATCH +* [#415] Fix access by tid in AlignmentFile.fetch() +* [#405] Writing SAM now outputs a header by default. +* [#332] split infer_query_length(always) into infer_query_length and infer_read_length + Release 0.10.0 ============== @@ -31,6 +240,17 @@ and includes several bugfixes: * Preliminary (potentially unsafe) support for removing and altering header metadata * Many minor fixes and improvements to VariantFile and related objects +Please note that all internal cython extensions now have a lib prefix +to facilitate linking against pysam extension modules. Any user cython +extensions using cimport to import pysam definitions will need +changes, for example:: + + cimport pysam.csamtools + +will become:: + + cimport pysam.libcamtools + Release 0.9.1 ============= @@ -311,9 +531,6 @@ Backwards incompatible changes * fancy_str() has been removed * qual, qqual now return arrays - - - Release 0.8.0 ============= diff --git a/doc/usage.rst b/doc/usage.rst index 936f3bdcd..6172329ac 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -123,26 +123,23 @@ Note that the file open mode needs to changed from ``r`` to ``rb``. Using samtools commands within python ===================================== -Commands available in :term:`csamtools` are available -as simple function calls. For example:: +Commands available in :term:`csamtools` are available as simple +function calls. Command line options are provided as arguments. For +example:: - pysam.sort("ex1.bam", "output") + pysam.sort("-o", "output.bam", "ex1.bam") corresponds to the command line:: - samtools sort ex1.bam output + samtools sort -o output.bam ex1.bam -Command line options can be provided as arguments:: - - pysam.sort("-n", "ex1.bam", "output") - -or:: +Or for example:: - pysam.sort("-m", "1000000", "ex1.bam", "output") + pysam.sort("-m", "1000000", "-o", "output.bam", "ex1.bam") In order to get usage information, try:: - print pysam.sort.usage() + print(pysam.sort.usage()) Argument errors raise a :class:`pysam.SamtoolsError`:: diff --git a/htslib/INSTALL b/htslib/INSTALL index 79a287498..8d9c3b6ec 100644 --- a/htslib/INSTALL +++ b/htslib/INSTALL @@ -1,3 +1,73 @@ + Building and Installing HTSlib + ============================== + +Requirements +============ + +Building HTSlib requires a few programs and libraries to be present. +At least the following are required: + + GNU make + C compiler (e.g. gcc or clang) + +In addition, building the configure script requires: + + autoheader + autoconf + +Running the configure script uses awk, along with a number of +standard UNIX tools (cat, cp, grep, mv, rm, sed, among others). Almost +all installations will have these already. + +Running the test harness (make test) uses: + + bash + perl + +HTSlib uses the following external libraries. Building requires both the +library itself, and include files needed to compile code that uses functions +from the library. Note that some Linux distributions put include files in +a development ('-dev' or '-devel') package separate from the main library. + + libz (required) + libbz2 (required, unless configured with --disable-bz2) + liblzma (required, unless configured with --disable-lzma) + libcurl (optional, but strongly recommended) + libcrypto (optional for Amazon S3 support; not needed on MacOS) + +Disabling libbzip2 and liblzma will make some CRAM files unreadable, so +is not recommended. + +Using libcurl provides HTSlib with better network protocol support, for +example it enables the use of https:// URLs. It is also required if +direct access to Amazon S3 or Google Cloud Storage is enabled. + +Amazon S3 support requires an HMAC function to calculate a message +authentication code. On MacOS, the CCHmac function from the standard +library is used. Systems that do not have CChmac will get this from +libcrypto. libcrypto is part of OpenSSL or one of its derivatives (LibreSSL +or BoringSSL). + +On Microsoft Windows we recommend use of Mingw64/Msys2. Note that +currently for the test harness to work you will need to override the +test temporary directory with e.g.: make check TEST_OPTS="-t C:/msys64/tmp/_" +Whilst the code may work on Windows with other environments, these have +not be verified. + +Building Configure +================== + +This step is only needed if configure.ac has been changed, or if configure +does not exist (for example, when building from a git clone). The +configure script and config.h.in can be built by running: + + autoheader + autoconf + +If you have a full GNU autotools install, you can alternatively run: + + autoreconf + Basic Installation ================== @@ -58,8 +128,26 @@ various features and specify further optional external requirements: --enable-libcurl Use libcurl () to implement network access to - remote files via FTP, HTTP, HTTPS, S3, etc. By default, HTSlib uses - its own simple networking code to provide access via FTP and HTTP only. + remote files via FTP, HTTP, HTTPS, etc. By default, HTSlib uses its + own simple networking code to provide access via FTP and HTTP only. + +--enable-gcs + Implement network access to Google Cloud Storage. By default or with + --enable-gcs=check, this is enabled when libcurl is enabled. + +--enable-s3 + Implement network access to Amazon AWS S3. By default or with + --enable-s3=check, this is enabled when libcurl is enabled. + +--disable-bz2 + Bzip2 is an optional compression codec format for CRAM, included + in HTSlib by default. It can be disabled with --disable-bz2, but + be aware that not all CRAM files may be possible to decode. + +--disable-lzma + LZMA is an optional compression codec for CRAM, included in HTSlib + by default. It can be disabled with --disable-lzma, but be aware + that not all CRAM files may be possible to decode. The configure script also accepts the usual options and environment variables for tuning installation locations and compilers: type './configure --help' diff --git a/htslib/Makefile b/htslib/Makefile index 1b3a746ee..93be040de 100644 --- a/htslib/Makefile +++ b/htslib/Makefile @@ -1,6 +1,6 @@ # Makefile for htslib, a C library for high-throughput sequencing data formats. # -# Copyright (C) 2013-2016 Genome Research Ltd. +# Copyright (C) 2013-2017 Genome Research Ltd. # # Author: John Marshall # @@ -26,30 +26,17 @@ CC = gcc AR = ar RANLIB = ranlib +# Default libraries to link if configure is not used +htslib_default_libs = -lz -lm -lbz2 -llzma + CPPFLAGS = # TODO: probably update cram code to make it compile cleanly with -Wc++-compat +# For testing strict C99 support add -std=c99 -D_XOPEN_SOURCE=600 +#CFLAGS = -g -Wall -O2 -pedantic -std=c99 -D_XOPEN_SOURCE=600 -D__FUNCTION__=__func__ CFLAGS = -g -Wall -O2 EXTRA_CFLAGS_PIC = -fpic LDFLAGS = -LIBS = - -# For now these don't work too well as samtools also needs to know to -# add -lbz2 and -llzma if linking against the static libhts.a library. -# TODO This needs configury and adding to htslib.pc.in. -# -# # Bzip2 support; optionally used by CRAM. -# HAVE_LIBBZ2 := $(shell echo -e "\#include \012int main(void){return 0;}" > .test.c && $(CC) $(CFLAGS) $(CPPFLAGS) -o .test .test.c -lbz2 2>/dev/null && echo yes) -# ifeq "$(HAVE_LIBBZ2)" "yes" -# CPPFLAGS += -DHAVE_LIBBZ2 -# LIBS += -lbz2 -# endif -# -# # Lzma support; optionally used by CRAM. -# HAVE_LIBLZMA := $(shell echo -e "\#include \012int main(void){return 0;}" > .test.c && $(CC) $(CFLAGS) $(CPPFLAGS) -o .test .test.c -llzma 2>/dev/null && echo yes) -# ifeq "$(HAVE_LIBLZMA)" "yes" -# CPPFLAGS += -DHAVE_LIBLZMA -# LIBS += -llzma -# endif +LIBS = $(htslib_default_libs) prefix = /usr/local exec_prefix = $(prefix) @@ -80,48 +67,42 @@ BUILT_PROGRAMS = \ tabix BUILT_TEST_PROGRAMS = \ + test/hts_endian \ test/fieldarith \ test/hfile \ test/sam \ + test/test_bgzf \ test/test-regidx \ test/test_view \ test/test-vcf-api \ - test/test-vcf-sweep + test/test-vcf-sweep \ + test/test-bcf-sr \ + test/test-bcf-translate + +BUILT_THRASH_PROGRAMS = \ + test/thrash_threads1 \ + test/thrash_threads2 \ + test/thrash_threads3 \ + test/thrash_threads4 \ + test/thrash_threads5 \ + test/thrash_threads6 all: lib-static lib-shared $(BUILT_PROGRAMS) plugins $(BUILT_TEST_PROGRAMS) HTSPREFIX = include htslib_vars.mk - -PACKAGE_VERSION = 1.3.2 +# If not using GNU make, you need to copy the version number from version.sh +# into here. +PACKAGE_VERSION := $(shell ./version.sh) LIBHTS_SOVERSION = 2 - # $(NUMERIC_VERSION) is for items that must have a numeric X.Y.Z string # even if this is a dirty or untagged Git working tree. -NUMERIC_VERSION = $(PACKAGE_VERSION) - -# If building from a Git repository, replace $(PACKAGE_VERSION) with the Git -# description of the working tree: either a release tag with the same value -# as $(PACKAGE_VERSION) above, or an exact description likely based on a tag. -# Much of this is also GNU Make-specific. If you don't have GNU Make and/or -# are not building from a Git repository, comment out this conditional. -ifneq "$(wildcard .git)" "" -original_version := $(PACKAGE_VERSION) -PACKAGE_VERSION := $(shell git describe --always --dirty) - -# Unless the Git description matches /\d*\.\d*(\.\d*)?/, i.e., is exactly a tag -# with a numeric name, revert $(NUMERIC_VERSION) to the original version number -# written above, but with the patchlevel field bumped to 255. -ifneq "$(subst ..,.,$(subst 0,,$(subst 1,,$(subst 2,,$(subst 3,,$(subst 4,,$(subst 5,,$(subst 6,,$(subst 7,,$(subst 8,,$(subst 9,,$(PACKAGE_VERSION))))))))))))" "." -empty := -NUMERIC_VERSION := $(subst $(empty) ,.,$(wordlist 1,2,$(subst ., ,$(original_version))) 255) -endif +NUMERIC_VERSION := $(shell ./version.sh numeric) # Force version.h to be remade if $(PACKAGE_VERSION) has changed. version.h: $(if $(wildcard version.h),$(if $(findstring "$(PACKAGE_VERSION)",$(shell cat version.h)),,force)) -endif version.h: echo '#define HTS_VERSION "$(PACKAGE_VERSION)"' > $@ @@ -129,6 +110,9 @@ version.h: print-version: @echo $(PACKAGE_VERSION) +show-version: + @echo PACKAGE_VERSION = $(PACKAGE_VERSION) + @echo NUMERIC_VERSION = $(NUMERIC_VERSION) .SUFFIXES: .bundle .c .cygdll .dll .o .pico .so @@ -143,13 +127,16 @@ LIBHTS_OBJS = \ kfunc.o \ knetfile.o \ kstring.o \ + bcf_sr_sort.o \ bgzf.o \ errmod.o \ faidx.o \ hfile.o \ hfile_net.o \ hts.o \ + hts_os.o\ md5.o \ + multipart.o \ probaln.o \ realn.o \ regidx.o \ @@ -157,6 +144,7 @@ LIBHTS_OBJS = \ synced_bcf_reader.o \ vcf_sweep.o \ tbx.o \ + textutils.o \ thread_pool.o \ vcf.o \ vcfutils.o \ @@ -175,8 +163,6 @@ LIBHTS_OBJS = \ cram/rANS_static.o \ cram/sam_header.o \ cram/string_alloc.o \ - cram/vlen.o \ - cram/zfio.o \ crypto.o PLUGIN_EXT = @@ -184,13 +170,15 @@ PLUGIN_OBJS = cram_h = cram/cram.h $(cram_samtools_h) $(cram_sam_header_h) $(cram_structs_h) $(cram_io_h) cram/cram_encode.h cram/cram_decode.h cram/cram_stats.h cram/cram_codecs.h cram/cram_index.h $(htslib_cram_h) cram_io_h = cram/cram_io.h $(cram_misc_h) -cram_misc_h = cram/misc.h cram/os.h +cram_misc_h = cram/misc.h $(cram_os_h) +cram_os_h = cram/os.h $(htslib_hts_endian_h) cram_sam_header_h = cram/sam_header.h cram/string_alloc.h cram/pooled_alloc.h $(htslib_khash_h) $(htslib_kstring_h) cram_samtools_h = cram/cram_samtools.h $(htslib_sam_h) $(cram_sam_header_h) cram_structs_h = cram/cram_structs.h $(htslib_thread_pool_h) cram/string_alloc.h $(htslib_khash_h) cram_open_trace_file_h = cram/open_trace_file.h cram/mFILE.h -hfile_internal_h = hfile_internal.h $(htslib_hfile_h) -hts_internal_h = hts_internal.h $(htslib_hts_h) +hfile_internal_h = hfile_internal.h $(htslib_hfile_h) $(textutils_internal_h) +hts_internal_h = hts_internal.h $(htslib_hts_h) $(textutils_internal_h) +textutils_internal_h = textutils_internal.h $(htslib_kstring_h) thread_pool_internal_h = thread_pool_internal.h $(htslib_thread_pool_h) @@ -206,7 +194,24 @@ thread_pool_internal_h = thread_pool_internal.h $(htslib_thread_pool_h) # Usually config.h is generated by running configure or config.status, # but if those aren't used create a default config.h here. config.h: - echo '/* Empty config.h generated by Makefile */' > $@ + echo '/* Default config.h generated by Makefile */' > $@ + echo '#define HAVE_LIBBZ2 1' >> $@ + echo '#define HAVE_LIBLZMA 1' >> $@ + echo '#define HAVE_LZMA_H 1' >> $@ + echo '#define HAVE_FSEEKO 1' >> $@ + echo '#define HAVE_DRAND48 1' >> $@ + +# And similarly for htslib.pc.tmp ("pkg-config template"). No dependency +# on htslib.pc.in listed, as if that file is newer the usual way to regenerate +# this target is via configure or config.status rather than this rule. +htslib.pc.tmp: + sed -e '/^static_libs=/s/@static_LIBS@/$(htslib_default_libs)/;s#@[^-][^@]*@##g' htslib.pc.in > $@ + +# Create a makefile fragment listing the libraries and LDFLAGS needed for +# static linking. This can be included by projects that want to build +# and link against the htslib source tree instead of an installed library. +htslib_static.mk: htslib.pc.tmp + sed -n '/^static_libs=/s/[^=]*=/HTSLIB_static_LIBS = /p;/^static_ldflags=/s/[^=]*=/HTSLIB_static_LDFLAGS = /p' $< > $@ lib-static: libhts.a @@ -222,6 +227,9 @@ lib-shared: libhts.dylib else ifeq "$(findstring CYGWIN,$(PLATFORM))" "CYGWIN" SHLIB_FLAVOUR = cygdll lib-shared: cyghts-$(LIBHTS_SOVERSION).dll +else ifeq "$(findstring MSYS,$(PLATFORM))" "MSYS" +SHLIB_FLAVOUR = dll +lib-shared: hts-$(LIBHTS_SOVERSION).dll else SHLIB_FLAVOUR = so lib-shared: libhts.so @@ -249,7 +257,7 @@ print-config: # file used at runtime (when $LD_LIBRARY_PATH includes the build directory). libhts.so: $(LIBHTS_OBJS:.o=.pico) - $(CC) -shared -Wl,-soname,libhts.so.$(LIBHTS_SOVERSION) -pthread $(LDFLAGS) -o $@ $(LIBHTS_OBJS:.o=.pico) -lz -lm $(LIBS) + $(CC) -shared -Wl,-soname,libhts.so.$(LIBHTS_SOVERSION) $(LDFLAGS) -o $@ $(LIBHTS_OBJS:.o=.pico) $(LIBS) -lpthread ln -sf $@ libhts.so.$(LIBHTS_SOVERSION) # Similarly this also creates libhts.NN.dylib as a byproduct, so that programs @@ -257,15 +265,18 @@ libhts.so: $(LIBHTS_OBJS:.o=.pico) # includes this project's build directory). libhts.dylib: $(LIBHTS_OBJS) - $(CC) -dynamiclib -install_name $(libdir)/libhts.$(LIBHTS_SOVERSION).dylib -current_version $(NUMERIC_VERSION) -compatibility_version $(LIBHTS_SOVERSION) $(LDFLAGS) -o $@ $(LIBHTS_OBJS) -lz $(LIBS) + $(CC) -dynamiclib -install_name $(libdir)/libhts.$(LIBHTS_SOVERSION).dylib -current_version $(NUMERIC_VERSION) -compatibility_version $(LIBHTS_SOVERSION) $(LDFLAGS) -o $@ $(LIBHTS_OBJS) $(LIBS) ln -sf $@ libhts.$(LIBHTS_SOVERSION).dylib cyghts-$(LIBHTS_SOVERSION).dll: $(LIBHTS_OBJS) - $(CC) -shared -Wl,--out-implib=libhts.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import -pthread $(LDFLAGS) -o $@ -Wl,--whole-archive $(LIBHTS_OBJS) -Wl,--no-whole-archive -lz -lm $(LIBS) + $(CC) -shared -Wl,--out-implib=libhts.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import -pthread $(LDFLAGS) -o $@ -Wl,--whole-archive $(LIBHTS_OBJS) -Wl,--no-whole-archive -lz -lm $(LIBS) -lpthread + +hts-$(LIBHTS_SOVERSION).dll: $(LIBHTS_OBJS) + $(CC) -shared -Wl,--out-implib=hts.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import $(LDFLAGS) -o $@ -Wl,--whole-archive $(LIBHTS_OBJS) -Wl,--no-whole-archive $(LIBS) -lpthread .pico.so: - $(CC) -shared -Wl,-E -pthread $(LDFLAGS) -o $@ $< $(LIBS) + $(CC) -shared -Wl,-E $(LDFLAGS) -o $@ $< $(LIBS) -lpthread .o.bundle: $(CC) -bundle -Wl,-undefined,dynamic_lookup $(LDFLAGS) -o $@ $< $(LIBS) @@ -273,58 +284,65 @@ cyghts-$(LIBHTS_SOVERSION).dll: $(LIBHTS_OBJS) .o.cygdll: $(CC) -shared $(LDFLAGS) -o $@ $< libhts.dll.a $(LIBS) +.o.dll: + $(CC) -shared $(LDFLAGS) -o $@ $< hts.dll.a $(LIBS) + bgzf.o bgzf.pico: bgzf.c config.h $(htslib_hts_h) $(htslib_bgzf_h) $(htslib_hfile_h) $(htslib_thread_pool_h) cram/pooled_alloc.h $(htslib_khash_h) crypto.h errmod.o errmod.pico: errmod.c config.h $(htslib_hts_h) $(htslib_ksort_h) kstring.o kstring.pico: kstring.c config.h $(htslib_kstring_h) -knetfile.o knetfile.pico: knetfile.c config.h $(htslib_knetfile_h) +knetfile.o knetfile.pico: knetfile.c config.h $(htslib_hts_log_h) $(htslib_knetfile_h) hfile.o hfile.pico: hfile.c config.h $(htslib_hfile_h) $(hfile_internal_h) $(hts_internal_h) $(htslib_khash_h) -hfile_libcurl.o hfile_libcurl.pico: hfile_libcurl.c config.h $(hts_internal_h) $(hfile_internal_h) $(htslib_hts_h) $(htslib_kstring_h) +hfile_gcs.o hfile_gcs.pico: hfile_gcs.c config.h $(htslib_hts_h) $(htslib_kstring_h) $(hfile_internal_h) +hfile_libcurl.o hfile_libcurl.pico: hfile_libcurl.c config.h $(hfile_internal_h) $(htslib_hts_h) $(htslib_kstring_h) hfile_net.o hfile_net.pico: hfile_net.c config.h $(hfile_internal_h) $(htslib_knetfile_h) -hts.o hts.pico: hts.c config.h $(htslib_hts_h) $(htslib_bgzf_h) $(cram_h) $(htslib_hfile_h) version.h $(hts_internal_h) $(htslib_khash_h) $(htslib_kseq_h) $(htslib_ksort_h) -vcf.o vcf.pico: vcf.c config.h $(htslib_vcf_h) $(htslib_bgzf_h) $(htslib_tbx_h) $(htslib_hfile_h) $(hts_internal_h) $(htslib_khash_str2int_h) $(htslib_kstring_h) $(htslib_khash_h) $(htslib_kseq_h) -sam.o sam.pico: sam.c config.h $(htslib_sam_h) $(htslib_bgzf_h) $(cram_h) $(hts_internal_h) $(htslib_hfile_h) $(htslib_khash_h) $(htslib_kseq_h) $(htslib_kstring_h) +hfile_s3.o hfile_s3.pico: hfile_s3.c config.h $(hfile_internal_h) $(htslib_hts_h) $(htslib_kstring_h) +hts.o hts.pico: hts.c config.h $(htslib_hts_h) $(htslib_bgzf_h) $(cram_h) $(hfile_internal_h) $(htslib_hfile_h) version.h $(hts_internal_h) $(htslib_khash_h) $(htslib_kseq_h) $(htslib_ksort_h) +hts_os.o hts_os.pico: hts_os.c config.h os/rand.c +vcf.o vcf.pico: vcf.c config.h $(htslib_vcf_h) $(htslib_bgzf_h) $(htslib_tbx_h) $(htslib_hfile_h) $(hts_internal_h) $(htslib_khash_str2int_h) $(htslib_kstring_h) $(htslib_khash_h) $(htslib_kseq_h) $(htslib_hts_endian_h) +sam.o sam.pico: sam.c config.h $(htslib_sam_h) $(htslib_bgzf_h) $(cram_h) $(hts_internal_h) $(htslib_hfile_h) $(htslib_khash_h) $(htslib_kseq_h) $(htslib_kstring_h) $(htslib_hts_endian_h) tbx.o tbx.pico: tbx.c config.h $(htslib_tbx_h) $(htslib_bgzf_h) $(hts_internal_h) $(htslib_khash_h) faidx.o faidx.pico: faidx.c config.h $(htslib_bgzf_h) $(htslib_faidx_h) $(htslib_hfile_h) $(htslib_khash_h) $(htslib_kstring_h) $(hts_internal_h) -synced_bcf_reader.o synced_bcf_reader.pico: synced_bcf_reader.c config.h $(htslib_synced_bcf_reader_h) $(htslib_kseq_h) $(htslib_khash_str2int_h) $(htslib_bgzf_h) $(htslib_thread_pool_h) +bcf_sr_sort.o bcf_sr_sort.pico: bcf_sr_sort.c config.h bcf_sr_sort.h $(htslib_kseq_h) $(htslib_khash_str2int_h) +synced_bcf_reader.o synced_bcf_reader.pico: synced_bcf_reader.c config.h bcf_sr_sort.h $(htslib_synced_bcf_reader_h) $(htslib_kseq_h) $(htslib_khash_str2int_h) $(htslib_bgzf_h) $(htslib_thread_pool_h) vcf_sweep.o vcf_sweep.pico: vcf_sweep.c config.h $(htslib_vcf_sweep_h) $(htslib_bgzf_h) vcfutils.o vcfutils.pico: vcfutils.c config.h $(htslib_vcfutils_h) $(htslib_kbitset_h) kfunc.o kfunc.pico: kfunc.c config.h $(htslib_kfunc_h) regidx.o regidx.pico: regidx.c config.h $(htslib_hts_h) $(htslib_kstring_h) $(htslib_kseq_h) $(htslib_khash_str2int_h) $(htslib_regidx_h) $(hts_internal_h) -md5.o md5.pico: md5.c config.h $(htslib_hts_h) +md5.o md5.pico: md5.c config.h $(htslib_hts_h) $(htslib_hts_endian_h) +multipart.o multipart.pico: multipart.c config.h $(htslib_kstring_h) $(hts_internal_h) $(hfile_internal_h) plugin.o plugin.pico: plugin.c config.h $(hts_internal_h) $(htslib_kstring_h) probaln.o probaln.pico: probaln.c config.h $(htslib_hts_h) realn.o realn.pico: realn.c config.h $(htslib_hts_h) $(htslib_sam_h) crypto.o crypto.pico: crypto.c crypto.h +textutils.o textutils.pico: textutils.c config.h $(htslib_hfile_h) $(htslib_kstring_h) $(hts_internal_h) cram/cram_codecs.o cram/cram_codecs.pico: cram/cram_codecs.c config.h $(cram_h) -cram/cram_decode.o cram/cram_decode.pico: cram/cram_decode.c config.h $(cram_h) cram/os.h $(htslib_hts_h) -cram/cram_encode.o cram/cram_encode.pico: cram/cram_encode.c config.h $(cram_h) cram/os.h $(htslib_hts_h) +cram/cram_decode.o cram/cram_decode.pico: cram/cram_decode.c config.h $(cram_h) $(cram_os_h) $(htslib_hts_h) +cram/cram_encode.o cram/cram_encode.pico: cram/cram_encode.c config.h $(cram_h) $(cram_os_h) $(htslib_hts_h) $(htslib_hts_endian_h) cram/cram_external.o cram/cram_external.pico: cram/cram_external.c config.h $(htslib_hfile_h) $(cram_h) -cram/cram_index.o cram/cram_index.pico: cram/cram_index.c config.h $(htslib_hfile_h) $(hts_internal_h) $(cram_h) cram/os.h cram/zfio.h -cram/cram_io.o cram/cram_io.pico: cram/cram_io.c config.h $(cram_h) cram/os.h $(htslib_hts_h) $(cram_open_trace_file_h) cram/rANS_static.h $(htslib_hfile_h) $(htslib_bgzf_h) $(htslib_faidx_h) $(hts_internal_h) +cram/cram_index.o cram/cram_index.pico: cram/cram_index.c config.h $(htslib_bgzf_h) $(htslib_hfile_h) $(hts_internal_h) $(cram_h) $(cram_os_h) +cram/cram_io.o cram/cram_io.pico: cram/cram_io.c config.h os/lzma_stub.h $(cram_h) $(cram_os_h) $(htslib_hts_h) $(cram_open_trace_file_h) cram/rANS_static.h $(htslib_hfile_h) $(htslib_bgzf_h) $(htslib_faidx_h) $(hts_internal_h) cram/cram_samtools.o cram/cram_samtools.pico: cram/cram_samtools.c config.h $(cram_h) $(htslib_sam_h) -cram/cram_stats.o cram/cram_stats.pico: cram/cram_stats.c config.h $(cram_h) cram/os.h +cram/cram_stats.o cram/cram_stats.pico: cram/cram_stats.c config.h $(cram_h) $(cram_os_h) cram/files.o cram/files.pico: cram/files.c config.h $(cram_misc_h) -cram/mFILE.o cram/mFILE.pico: cram/mFILE.c config.h cram/os.h cram/mFILE.h cram/vlen.h -cram/open_trace_file.o cram/open_trace_file.pico: cram/open_trace_file.c config.h cram/os.h $(cram_open_trace_file_h) $(cram_misc_h) $(htslib_hfile_h) +cram/mFILE.o cram/mFILE.pico: cram/mFILE.c config.h $(cram_os_h) cram/mFILE.h +cram/open_trace_file.o cram/open_trace_file.pico: cram/open_trace_file.c config.h $(cram_os_h) $(cram_open_trace_file_h) $(cram_misc_h) $(htslib_hfile_h) cram/pooled_alloc.o cram/pooled_alloc.pico: cram/pooled_alloc.c config.h cram/pooled_alloc.h $(cram_misc_h) cram/rANS_static.o cram/rANS_static.pico: cram/rANS_static.c config.h cram/rANS_static.h cram/rANS_byte.h cram/sam_header.o cram/sam_header.pico: cram/sam_header.c config.h $(cram_sam_header_h) cram/string_alloc.h cram/string_alloc.o cram/string_alloc.pico: cram/string_alloc.c config.h cram/string_alloc.h thread_pool.o thread_pool.pico: thread_pool.c config.h $(thread_pool_internal_h) -cram/vlen.o cram/vlen.pico: cram/vlen.c config.h cram/vlen.h cram/os.h -cram/zfio.o cram/zfio.pico: cram/zfio.c config.h cram/os.h cram/zfio.h bgzip: bgzip.o libhts.a - $(CC) -pthread $(LDFLAGS) -o $@ bgzip.o libhts.a -lz $(LIBS) + $(CC) $(LDFLAGS) -o $@ bgzip.o libhts.a $(LIBS) -lpthread htsfile: htsfile.o libhts.a - $(CC) -pthread $(LDFLAGS) -o $@ htsfile.o libhts.a -lz $(LIBS) + $(CC) $(LDFLAGS) -o $@ htsfile.o libhts.a $(LIBS) -lpthread tabix: tabix.o libhts.a - $(CC) -pthread $(LDFLAGS) -o $@ tabix.o libhts.a -lz $(LIBS) + $(CC) $(LDFLAGS) -o $@ tabix.o libhts.a $(LIBS) -lpthread bgzip.o: bgzip.c config.h $(htslib_bgzf_h) $(htslib_hts_h) htsfile.o: htsfile.c config.h $(htslib_hfile_h) $(htslib_hts_h) $(htslib_sam_h) $(htslib_vcf_h) @@ -333,41 +351,84 @@ tabix.o: tabix.c config.h $(htslib_tbx_h) $(htslib_sam_h) $(htslib_vcf_h) $(htsl # For tests that might use it, set $REF_PATH explicitly to use only reference # areas within the test suite (or set it to ':' to use no reference areas). -check test: bgzip htsfile $(BUILT_TEST_PROGRAMS) +# +# If using MSYS, avoid poor shell expansion via: +# MSYS2_ARG_CONV_EXCL="*" make check +check test: $(BUILT_PROGRAMS) $(BUILT_TEST_PROGRAMS) + test/hts_endian test/fieldarith test/fieldarith.sam test/hfile - test/sam test/ce.fa test/faidx.fa + test/test_bgzf test/bgziptest.txt + cd test/tabix && ./test-tabix.sh tabix.tst + REF_PATH=: test/sam test/ce.fa test/faidx.fa test/test-regidx - cd test && REF_PATH=: ./test.pl + cd test && REF_PATH=: ./test.pl $${TEST_OPTS:-} + +test/hts_endian: test/hts_endian.o + $(CC) $(LDFLAGS) -o $@ test/hts_endian.o $(LIBS) test/fieldarith: test/fieldarith.o libhts.a - $(CC) -pthread $(LDFLAGS) -o $@ test/fieldarith.o libhts.a -lz $(LIBS) + $(CC) $(LDFLAGS) -o $@ test/fieldarith.o libhts.a $(LIBS) -lpthread test/hfile: test/hfile.o libhts.a - $(CC) -pthread $(LDFLAGS) -o $@ test/hfile.o libhts.a -lz $(LIBS) + $(CC) $(LDFLAGS) -o $@ test/hfile.o libhts.a $(LIBS) -lpthread test/sam: test/sam.o libhts.a - $(CC) -pthread $(LDFLAGS) -o $@ test/sam.o libhts.a -lz $(LIBS) + $(CC) $(LDFLAGS) -o $@ test/sam.o libhts.a $(LIBS) -lpthread + +test/test_bgzf: test/test_bgzf.o libhts.a + $(CC) $(LDFLAGS) -o $@ test/test_bgzf.o libhts.a -lz $(LIBS) -lpthread test/test-regidx: test/test-regidx.o libhts.a - $(CC) -pthread $(LDFLAGS) -o $@ test/test-regidx.o libhts.a -lz $(LIBS) + $(CC) $(LDFLAGS) -o $@ test/test-regidx.o libhts.a $(LIBS) -lpthread test/test_view: test/test_view.o libhts.a - $(CC) -pthread $(LDFLAGS) -o $@ test/test_view.o libhts.a -lz $(LIBS) + $(CC) $(LDFLAGS) -o $@ test/test_view.o libhts.a $(LIBS) -lpthread test/test-vcf-api: test/test-vcf-api.o libhts.a - $(CC) -pthread $(LDFLAGS) -o $@ test/test-vcf-api.o libhts.a -lz $(LIBS) + $(CC) $(LDFLAGS) -o $@ test/test-vcf-api.o libhts.a $(LIBS) -lpthread test/test-vcf-sweep: test/test-vcf-sweep.o libhts.a - $(CC) -pthread $(LDFLAGS) -o $@ test/test-vcf-sweep.o libhts.a -lz $(LIBS) + $(CC) $(LDFLAGS) -o $@ test/test-vcf-sweep.o libhts.a $(LIBS) -lpthread +test/test-bcf-sr: test/test-bcf-sr.o libhts.a + $(CC) $(LDFLAGS) -o $@ test/test-bcf-sr.o libhts.a -lz $(LIBS) -lpthread + +test/test-bcf-translate: test/test-bcf-translate.o libhts.a + $(CC) $(LDFLAGS) -o $@ test/test-bcf-translate.o libhts.a -lz $(LIBS) -lpthread + +test/hts_endian.o: test/hts_endian.c $(htslib_hts_endian_h) test/fieldarith.o: test/fieldarith.c config.h $(htslib_sam_h) test/hfile.o: test/hfile.c config.h $(htslib_hfile_h) $(htslib_hts_defs_h) test/sam.o: test/sam.c config.h $(htslib_hts_defs_h) $(htslib_sam_h) $(htslib_faidx_h) $(htslib_kstring_h) +test/test_bgzf.o: test/test_bgzf.c $(htslib_bgzf_h) $(htslib_hfile_h) test/test-regidx.o: test/test-regidx.c config.h $(htslib_regidx_h) $(hts_internal_h) test/test_view.o: test/test_view.c config.h $(cram_h) $(htslib_sam_h) test/test-vcf-api.o: test/test-vcf-api.c config.h $(htslib_hts_h) $(htslib_vcf_h) $(htslib_kstring_h) $(htslib_kseq_h) test/test-vcf-sweep.o: test/test-vcf-sweep.c config.h $(htslib_vcf_sweep_h) +test/test-bcf-sr.o: test/test-bcf-sr.c config.h $(htslib_vcf_sweep_h) bcf_sr_sort.h +test/test-bcf-translate.o: test/test-bcf-translate.c config.h + + +test/thrash_threads1: test/thrash_threads1.o libhts.a + $(CC) $(LDFLAGS) -o $@ test/thrash_threads1.o libhts.a -lz $(LIBS) -lpthread + +test/thrash_threads2: test/thrash_threads2.o libhts.a + $(CC) $(LDFLAGS) -o $@ test/thrash_threads2.o libhts.a -lz $(LIBS) -lpthread + +test/thrash_threads3: test/thrash_threads3.o libhts.a + $(CC) $(LDFLAGS) -o $@ test/thrash_threads3.o libhts.a -lz $(LIBS) -lpthread + +test/thrash_threads4: test/thrash_threads4.o libhts.a + $(CC) $(LDFLAGS) -o $@ test/thrash_threads4.o libhts.a -lz $(LIBS) -lpthread + +test/thrash_threads5: test/thrash_threads5.o libhts.a + $(CC) $(LDFLAGS) -o $@ test/thrash_threads5.o libhts.a -lz $(LIBS) -lpthread + +test/thrash_threads6: test/thrash_threads6.o libhts.a + $(CC) $(LDFLAGS) -o $@ test/thrash_threads6.o libhts.a -lz $(LIBS) -lpthread + +test_thrash: $(BUILT_THRASH_PROGRAMS) install: libhts.a $(BUILT_PROGRAMS) $(BUILT_PLUGINS) installdirs install-$(SHLIB_FLAVOUR) install-pkgconfig @@ -395,6 +456,10 @@ install-cygdll: cyghts-$(LIBHTS_SOVERSION).dll installdirs $(INSTALL_PROGRAM) cyghts-$(LIBHTS_SOVERSION).dll $(DESTDIR)$(bindir)/cyghts-$(LIBHTS_SOVERSION).dll $(INSTALL_PROGRAM) libhts.dll.a $(DESTDIR)$(libdir)/libhts.dll.a +install-dll: hts-$(LIBHTS_SOVERSION).dll installdirs + $(INSTALL_PROGRAM) hts-$(LIBHTS_SOVERSION).dll $(DESTDIR)$(bindir)/hts-$(LIBHTS_SOVERSION).dll + $(INSTALL_PROGRAM) hts.dll.a $(DESTDIR)$(libdir)/hts.dll.a + install-dylib: libhts.dylib installdirs $(INSTALL_PROGRAM) libhts.dylib $(DESTDIR)$(libdir)/libhts.$(PACKAGE_VERSION).dylib ln -sf libhts.$(PACKAGE_VERSION).dylib $(DESTDIR)$(libdir)/libhts.dylib @@ -402,28 +467,29 @@ install-dylib: libhts.dylib installdirs # Substitute these pseudo-autoconf variables only at install time # so that "make install prefix=/prefix/path" etc continue to work. -install-pkgconfig: installdirs - sed -e 's#@includedir@#$(includedir)#g;s#@libdir@#$(libdir)#g;s#@PACKAGE_VERSION@#$(PACKAGE_VERSION)#g' htslib.pc.in > $(DESTDIR)$(pkgconfigdir)/htslib.pc +install-pkgconfig: htslib.pc.tmp installdirs + sed -e 's#@-includedir@#$(includedir)#g;s#@-libdir@#$(libdir)#g;s#@-PACKAGE_VERSION@#$(PACKAGE_VERSION)#g' htslib.pc.tmp > $(DESTDIR)$(pkgconfigdir)/htslib.pc chmod 644 $(DESTDIR)$(pkgconfigdir)/htslib.pc # A pkg-config file (suitable for copying to $PKG_CONFIG_PATH) that provides # flags for building against the uninstalled library in this build directory. -htslib-uninstalled.pc: htslib.pc.in - sed -e 's#@includedir@#'`pwd`'#g;s#@libdir@#'`pwd`'#g' htslib.pc.in > $@ +htslib-uninstalled.pc: htslib.pc.tmp + sed -e 's#@-includedir@#'`pwd`'#g;s#@-libdir@#'`pwd`'#g' htslib.pc.tmp > $@ testclean: - -rm -f test/*.tmp test/*.tmp.* + -rm -f test/*.tmp test/*.tmp.* test/tabix/*.tmp.* test/tabix/FAIL* mostlyclean: testclean -rm -f *.o *.pico cram/*.o cram/*.pico test/*.o test/*.dSYM version.h clean: mostlyclean clean-$(SHLIB_FLAVOUR) - -rm -f libhts.a $(BUILT_PROGRAMS) $(BUILT_PLUGINS) $(BUILT_TEST_PROGRAMS) + -rm -f libhts.a $(BUILT_PROGRAMS) $(BUILT_PLUGINS) $(BUILT_TEST_PROGRAMS) $(BUILT_THRASH_PROGRAMS) distclean maintainer-clean: clean -rm -f config.cache config.h config.log config.mk config.status - -rm -f TAGS *-uninstalled.pc + -rm -f TAGS *.pc.tmp *-uninstalled.pc htslib_static.mk + -rm -rf autom4te.cache clean-so: -rm -f libhts.so libhts.so.* @@ -431,6 +497,9 @@ clean-so: clean-cygdll: -rm -f cyghts-*.dll libhts.dll.a +clean-dll: + -rm -f hts-*.dll hts.dll.a + clean-dylib: -rm -f libhts.dylib libhts.*.dylib @@ -446,7 +515,8 @@ tags TAGS: # (The wildcards attempt to omit non-exported files (.git*, README.md, # etc) and other detritus that might be in the top-level directory.) distdir: - tar -c *.[ch15] [ILMNRcht]*[ELSbcekmnt] | (cd $(distdir) && tar -x) + @if [ -z "$(distdir)" ]; then echo "Please supply a distdir=DIR argument."; false; fi + tar -c *.[ch15] [ILMNRchtv]*[ELSbcekmnth] | (cd $(distdir) && tar -x) +cd $(distdir) && $(MAKE) distclean force: @@ -455,7 +525,8 @@ force: .PHONY: all check clean distclean distdir force .PHONY: install install-pkgconfig installdirs lib-shared lib-static .PHONY: maintainer-clean mostlyclean plugins print-config print-version -.PHONY: tags test testclean +.PHONY: show-version tags test testclean .PHONY: clean-so install-so .PHONY: clean-cygdll install-cygdll +.PHONY: clean-dll install-dll .PHONY: clean-dylib install-dylib diff --git a/htslib/NEWS b/htslib/NEWS index 34afdf313..a571bb5b0 100644 --- a/htslib/NEWS +++ b/htslib/NEWS @@ -1,16 +1,203 @@ -Noteworthy changes in release 1.4 +Noteworthy changes in release 1.7 (26th January 2018) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +* BAM: HTSlib now supports BAMs which include CIGARs with more than + 65535 operations as per HTS-Specs 18th November (dab57f4 and 2f915a8). + +* BCF/VCF: + - Removed the need for long double in pileup calculations. + - Sped up the synced reader in some situations. + - Bug fixing: removed memory leak in bcf_copy. + +* CRAM: + - Added support for HTS_IDX_START in cram iterators. + - Easier to build when lzma header files are absent. + - Bug fixing: a region query with REQUIRED_FIELDS option to + disable sequence retrieval now gives correct results. + - Bug fixing: stop queries to regions starting after the last + read on a chromosome from incorrectly reporting errors + (#651, #653; reported by Imran Haque and @egafni via pysam). + +* Multi-region iterator: The new structure takes a list of regions and + iterates over all, deduplicating reads in the process, and producing a + full list of file offset intervals. This is usually much faster than + repeatedly using the old single-region iterator on a series of regions. + +* Curl improvements: + - Add Bearer token support via HTS_AUTH_LOCATION env (#600). + - Use CURL_CA_BUNDLE environment variable to override the CA (#622; + thanks to Garret Kelly & David Alexander). + - Speed up (removal of excessive waiting) for both http(s) and ftp. + - Avoid repeatedly reconnecting by removal of unnecessary seeks. + - Bug fixing: double free when libcurl_open fails. + +* BGZF block caching, if enabled, now performs far better (#629; reported + by Ram Yalamanchili). + +* Added an hFILE layer for in-memory I/O buffers (#590; thanks to Thomas + Hickman). + +* Tidied up the drand48 support (intended for systems that do not + provide this function). + +Noteworthy changes in release 1.6 (28th September 2017) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +* Fixed bug where iterators on CRAM files did not propagate error return + values to the caller correctly. Thanks go to Chris Saunders. + +* Overhauled Windows builds. Building with msys2/mingw64 now works + correctly and passes all tests. + +* More improvements to logging output (thanks again to Anders Kaplan). + +* Return codes from sam_read1() when reading cram have been made + consistent with those returned when reading sam/bam. Thanks to + Chris Saunders (#575). + +* BGZF CRC32 checksums are now always verified. + +* It's now possible to set nthreads = 1 for cram files. + +* hfile_libcurl has been modified to make it thread-safe. It's also + better at handling web servers that do not honour byte range requests + when attempting to seek - it now sets errno to ESPIPE and keeps + the existing connection open so callers can revert to streaming mode + it they want to. + +* hfile_s3 now recalculates access tokens if they have become stale. This + fixes a reported problem where authentication failed after a file + had been in use for more than 15 minutes. + +* Fixed bug where remote index fetches would fail to notice errors when + writing files. + +* bam_read1() now checks that the query sequence length derived from the + CIGAR alignment matches the sequence length in the BAM record. + +Noteworthy changes in release 1.5 (21st June 2017) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +* Added a new logging API: hts_log(), along with hts_log_error(), + hts_log_warn() etc. convenience macros. Thanks go to Anders Kaplan + for the implementation. (#499, #543, #551) + +* Added a new file I/O option "block_size" (HTS_OPT_BLOCK_SIZE) to + alter the hFILE buffer size. + +* Fixed various bugs, including compilation issues samtools/bcftools#610, + samtools/bcftools#611 and robustness to corrupted data #537, #538, + #541, #546, #548, #549, #554. + + +Noteworthy changes in release 1.4.1 (8th May 2017) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This is primarily a security bug fix update. + +* Fixed SECURITY (CVE-2017-1000206) issue with buffer overruns with malicious data. (#514). + +* S3 support for non Amazon AWS endpoints. (#506) + +* Support for variant breakpoints in bcftools. (#516) + +* Improved handling of BCF NaNs. (#485) + +* Compilation / portability improvements. (#255, #423, #498, #488) + +* Miscellaneous bug fixes (#482, #521, #522, #523, #524). + +* Sanitise headers (#509) + + +Release 1.4 (13 March 2017) * Incompatible changes: several functions and data types have been changed in this release, and the shared library soversion has been bumped to 2. + - bam_pileup1_t has an additional field (which holds user data) + - bam1_core_t has been modified to allow for >64K CIGAR operations + and (along with bam1_t) so that CIGAR entries are aligned in memory + - hopen() has vararg arguments for setting URL scheme-dependent options + - the various tbx_conf_* presets are now const + - auxiliary fields in bam1_t are now always stored in little-endian byte + order (previously this depended on if you read a bam, sam or cram file) + - index metadata (accessible via hts_idx_get_meta()) is now always + stored in little-endian byte order (previously this depended on if + the index was in tbi or csi format) + - bam_aux2i() now returns an int64_t value + - fai_load() will no longer save local copies of remote fasta indexes + - hts_idx_get_meta() now takes a uint32_t * for l_meta (was int32_t *) + +* HTSlib now links against libbz2 and liblzma by default. To remove these + dependencies, run configure with options --disable-bz2 and --disable-lzma, + but note that this may make some CRAM files produced elsewhere unreadable. + +* Added a thread pool interface and replaced the bgzf multi-threading + code to use this pool. BAM and CRAM decoding is now multi-threaded + too, using the pool to automatically balance the number of threads + between decode, encode and any data processing jobs. * New errmod_cal(), probaln_glocal(), sam_cap_mapq(), and sam_prob_realn() functions, previously internal to SAMtools, have been added to HTSlib. +* Files can now be accessed via Google Cloud Storage using gs: URLs, when + HTSlib is configured to use libcurl for network file access rather than + the included basic knetfile networking. + +* S3 file access now also supports the "host_base" setting in the + $HOME/.s3cfg configuration file. + +* Data URLs ("data:,text") now follow the standard RFC 2397 format and may + be base64-encoded (when written as "data:;base64,text") or may include + percent-encoded characters. HTSlib's previous over-simplified "data:text" + format is no longer supported -- you will need to add an initial comma. + +* When plugins are enabled, S3 support is now provided by a separate + hfile_s3 plugin rather than by hfile_libcurl itself as previously. + When --enable-libcurl is used, by default both GCS and S3 support + and plugins will also be built; they can be individually disabled + via --disable-gcs and --disable-s3. + * The iRODS file access plugin has been moved to a separate repository. Configure no longer has a --with-irods option; instead build the plugin found at . +* APIs to portably read and write (possibly unaligned) data in little-endian + byte order have been added. + +* New functions bam_auxB_len(), bam_auxB2i() and bam_auxB2f() have been + added to make accessing array-type auxiliary data easier. bam_aux2i() + can now return the full range of values that can be stored in an integer + tag (including unsigned 32 bit tags). bam_aux2f() will return the value + of integer tags (as a double) as well as floating-point ones. All of + the bam_aux2 and bam_auxB2 functions will set errno if the requested + conversion is not valid. + +* New functions fai_load3() and fai_build3() allow fasta indexes to be + stored in a different location to the indexed fasta file. + +* New functions bgzf_index_dump_hfile() and bgzf_index_load_hfile() + allow bgzf index files (.gzi) to be written to / read from an existing + hFILE handle. + +* hts_idx_push() will report when trying to add a range to an index that + is beyond the limits that the given index can handle. This means trying + to index chromosomes longer than 2^29 bases with a .bai or .tbi index + will report an error instead of apparantly working but creating an invalid + index entry. + +* VCF formatting is now approximately 4x faster. (Whether this is + noticable depends on what was creating the VCF.) + +* CRAM lossy_names mode now works with TLEN of 0 or TLEN within +/- 1 + of the computed value. Note in these situations TLEN will be + generated / fixed during CRAM decode. + +* CRAM now supports bzip2 and lzma codecs. Within htslib these are + disabled by default, but can be enabled by specifying "use_bzip2" or + "use_lzma" in an hts_opt_add() call or via the mode string of the + hts_open_format() function. Noteworthy changes in release 1.3.2 (13 September 2016) diff --git a/htslib/bcf_sr_sort.c b/htslib/bcf_sr_sort.c new file mode 100644 index 000000000..4b5e5b71b --- /dev/null +++ b/htslib/bcf_sr_sort.c @@ -0,0 +1,674 @@ +/* + Copyright (C) 2017 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include + +#include "bcf_sr_sort.h" +#include "htslib/khash_str2int.h" + +#define SR_REF 1 +#define SR_SNP 2 +#define SR_INDEL 4 +#define SR_OTHER 8 +#define SR_SCORE(srt,a,b) (srt)->score[((a)<<4)|(b)] + +// Resize a bit set. +static inline kbitset_t *kbs_resize(kbitset_t *bs, size_t ni) +{ + if ( !bs ) return kbs_init(ni); + size_t n = (ni + KBS_ELTBITS-1) / KBS_ELTBITS; + if ( n==bs->n ) return bs; + + bs = (kbitset_t *) realloc(bs, sizeof(kbitset_t) + n * sizeof(unsigned long)); + if ( bs==NULL ) return NULL; + if ( n > bs->n ) + memset(bs->b + bs->n, 0, (n - bs->n) * sizeof (unsigned long)); + bs->n = n; + bs->b[n] = ~0UL; + return bs; +} + +// Logical AND +static inline int kbs_logical_and(kbitset_t *bs1, kbitset_t *bs2) +{ + // General case, bitsets of unequal size: + // int i, n = bs1->n < bs2->n ? bs1->n : bs2->n; + int i, n = bs1->n; + + for (i=0; ib[i] & bs2->b[i] ) return 1; + return 0; +} + +// Bitwise OR, dst will be modified, src will be left unchanged +static inline void kbs_bitwise_or(kbitset_t *dst, kbitset_t *src) +{ + int i; + for (i=0; in; i++) dst->b[i] |= src->b[i]; +} + + +static void bcf_sr_init_scores(sr_sort_t *srt) +{ + int i,jbit,kbit; + + // lower number = lower priority, zero means forbidden + + if ( srt->pair & BCF_SR_PAIR_ANY ) srt->pair |= (BCF_SR_PAIR_SNPS | BCF_SR_PAIR_INDELS | BCF_SR_PAIR_SNP_REF | BCF_SR_PAIR_INDEL_REF); + if ( srt->pair & BCF_SR_PAIR_SNPS ) SR_SCORE(srt,SR_SNP,SR_SNP) = 3; + if ( srt->pair & BCF_SR_PAIR_INDELS ) SR_SCORE(srt,SR_INDEL,SR_INDEL) = 3; + if ( srt->pair & BCF_SR_PAIR_SNP_REF ) + { + SR_SCORE(srt,SR_SNP,SR_REF) = 2; + SR_SCORE(srt,SR_REF,SR_SNP) = 2; + } + if ( srt->pair & BCF_SR_PAIR_INDEL_REF ) + { + SR_SCORE(srt,SR_INDEL,SR_REF) = 2; + SR_SCORE(srt,SR_REF,SR_INDEL) = 2; + } + if ( srt->pair & BCF_SR_PAIR_ANY ) + { + for (i=0; i<256; i++) + if ( !srt->score[i] ) srt->score[i] = 1; + } + + // set all combinations + for (i=0; i<256; i++) + { + if ( srt->score[i] ) continue; // already set + int max = 0; + for (jbit=0; jbit<4; jbit++) // high bits + { + int j = 1<score[i] = max; + } +} +static int multi_is_exact(var_t *avar, var_t *bvar) +{ + if ( avar->nalt != bvar->nalt ) return 0; + + int alen = strlen(avar->str); + int blen = strlen(bvar->str); + if ( alen != blen ) return 0; + + char *abeg = avar->str; + while ( *abeg ) + { + char *aend = abeg; + while ( *aend && *aend!=',' ) aend++; + + char *bbeg = bvar->str; + while ( *bbeg ) + { + char *bend = bbeg; + while ( *bend && *bend!=',' ) bend++; + if ( bend - bbeg == aend - abeg && !strncasecmp(abeg,bbeg,bend-bbeg) ) break; + bbeg = *bend ? bend+1 : bend; + } + if ( !*bbeg ) return 0; + + abeg = *aend ? aend+1 : aend; + } + return 1; +} +static int multi_is_subset(var_t *avar, var_t *bvar) +{ + char *abeg = avar->str; + while ( *abeg ) + { + char *aend = abeg; + while ( *aend && *aend!=',' ) aend++; + + char *bbeg = bvar->str; + while ( *bbeg ) + { + char *bend = bbeg; + while ( *bend && *bend!=',' ) bend++; + if ( bend - bbeg == aend - abeg && !strncasecmp(abeg,bbeg,bend-bbeg) ) return 1; + bbeg = *bend ? bend+1 : bend; + } + abeg = *aend ? aend+1 : aend; + } + return 0; +} +int32_t pairing_score(sr_sort_t *srt, int ivset, int jvset) +{ + varset_t *iv = &srt->vset[ivset]; + varset_t *jv = &srt->vset[jvset]; + + // Restrictive logic: the strictest type from a group is selected, + // so that, for example, snp+ref does not lead to the inclusion of an indel + int i,j; + uint32_t min = UINT32_MAX; + for (i=0; invar; i++) + { + var_t *ivar = &srt->var[iv->var[i]]; + for (j=0; jnvar; j++) + { + var_t *jvar = &srt->var[jv->var[j]]; + if ( srt->pair & BCF_SR_PAIR_EXACT ) + { + if ( ivar->type != jvar->type ) continue; + if ( !strcmp(ivar->str,jvar->str) ) return UINT32_MAX; // exact match, best possibility + if ( multi_is_exact(ivar,jvar) ) return UINT32_MAX; // identical alleles + continue; + } + if ( ivar->type==jvar->type && !strcmp(ivar->str,jvar->str) ) return UINT32_MAX; // exact match, best possibility + if ( ivar->type & jvar->type && multi_is_subset(ivar,jvar) ) return UINT32_MAX; // one of the alleles is identical + + uint32_t score = SR_SCORE(srt,ivar->type,jvar->type); + if ( !score ) return 0; // some of the varsets in the two groups are not compatible, will not pair + if ( min>score ) min = score; + } + } + if ( srt->pair & BCF_SR_PAIR_EXACT ) return 0; + + assert( min!=UINT32_MAX ); + + uint32_t cnt = 0; + for (i=0; invar; i++) cnt += srt->var[iv->var[i]].nvcf; + for (j=0; jnvar; j++) cnt += srt->var[jv->var[j]].nvcf; + + return (1<<(28+min)) + cnt; +} +void remove_vset(sr_sort_t *srt, int jvset) +{ + if ( jvset+1 < srt->nvset ) + { + varset_t tmp = srt->vset[jvset]; + memmove(&srt->vset[jvset], &srt->vset[jvset+1], sizeof(varset_t)*(srt->nvset - jvset - 1)); + srt->vset[srt->nvset-1] = tmp; + + int *jmat = srt->pmat + jvset*srt->ngrp; + memmove(jmat, &jmat[srt->ngrp],sizeof(int)*(srt->nvset - jvset - 1)*srt->ngrp); + + memmove(&srt->cnt[jvset], &srt->cnt[jvset+1], sizeof(int)*(srt->nvset - jvset - 1)); + } + srt->nvset--; +} +int merge_vsets(sr_sort_t *srt, int ivset, int jvset) +{ + int i,j; + if ( ivset > jvset ) { i = ivset; ivset = jvset; jvset = i; } + + varset_t *iv = &srt->vset[ivset]; + varset_t *jv = &srt->vset[jvset]; + + kbs_bitwise_or(iv->mask,jv->mask); + + i = iv->nvar; + iv->nvar += jv->nvar; + hts_expand(int, iv->nvar, iv->mvar, iv->var); + for (j=0; jnvar; j++,i++) iv->var[i] = jv->var[j]; + + int *imat = srt->pmat + ivset*srt->ngrp; + int *jmat = srt->pmat + jvset*srt->ngrp; + for (i=0; ingrp; i++) imat[i] += jmat[i]; + srt->cnt[ivset] += srt->cnt[jvset]; + + remove_vset(srt, jvset); + + return ivset; +} +void push_vset(sr_sort_t *srt, int ivset) +{ + varset_t *iv = &srt->vset[ivset]; + int i,j; + for (i=0; isr->nreaders; i++) + { + vcf_buf_t *buf = &srt->vcf_buf[i]; + buf->nrec++; + hts_expand(bcf1_t*,buf->nrec,buf->mrec,buf->rec); + buf->rec[buf->nrec-1] = NULL; + } + for (i=0; invar; i++) + { + var_t *var = &srt->var[ iv->var[i] ]; + for (j=0; jnvcf; j++) + { + int jvcf = var->vcf[j]; + vcf_buf_t *buf = &srt->vcf_buf[jvcf]; + buf->rec[buf->nrec-1] = var->rec[j]; + } + } + remove_vset(srt, ivset); +} + +static int cmpstringp(const void *p1, const void *p2) +{ + return strcmp(* (char * const *) p1, * (char * const *) p2); +} + +#if DEBUG_VSETS +void debug_vsets(sr_sort_t *srt) +{ + int i,j,k; + for (i=0; invset; i++) + { + fprintf(stderr,"dbg_vset %d:", i); + for (j=0; jvset[i].mask->n; j++) fprintf(stderr,"%c%lu",j==0?' ':':',srt->vset[i].mask->b[j]); + fprintf(stderr,"\t"); + for (j=0; jvset[i].nvar; j++) + { + var_t *var = &srt->var[srt->vset[i].var[j]]; + fprintf(stderr,"\t%s",var->str); + for (k=0; knvcf; k++) + fprintf(stderr,"%c%d", k==0?':':',',var->vcf[k]); + } + fprintf(stderr,"\n"); + } +} +#endif + +#if DEBUG_VBUF +void debug_vbuf(sr_sort_t *srt) +{ + int i, j; + for (j=0; jvcf_buf[0].nrec; j++) + { + fprintf(stderr,"dbg_vbuf %d:\t", j); + for (i=0; isr->nreaders; i++) + { + vcf_buf_t *buf = &srt->vcf_buf[i]; + fprintf(stderr,"\t%d", buf->rec[j] ? buf->rec[j]->pos+1 : 0); + } + fprintf(stderr,"\n"); + } +} +#endif + +char *grp_create_key(sr_sort_t *srt) +{ + if ( !srt->str.l ) return strdup(""); + int i; + hts_expand(char*,srt->noff,srt->mcharp,srt->charp); + for (i=0; inoff; i++) + { + srt->charp[i] = srt->str.s + srt->off[i]; + if ( i>0 ) srt->charp[i][-1] = 0; + } + qsort(srt->charp, srt->noff, sizeof(*srt->charp), cmpstringp); + char *ret = (char*) malloc(srt->str.l + 1), *ptr = ret; + for (i=0; inoff; i++) + { + int len = strlen(srt->charp[i]); + memcpy(ptr, srt->charp[i], len); + ptr += len + 1; + ptr[-1] = i+1==srt->noff ? 0 : ';'; + } + return ret; +} +int bcf_sr_sort_set_active(sr_sort_t *srt, int idx) +{ + hts_expand(int,idx+1,srt->mactive,srt->active); + srt->nactive = 1; + srt->active[srt->nactive - 1] = idx; + return 0; +} +int bcf_sr_sort_add_active(sr_sort_t *srt, int idx) +{ + hts_expand(int,idx+1,srt->mactive,srt->active); + srt->nactive++; + srt->active[srt->nactive - 1] = idx; + return 0; +} +static void bcf_sr_sort_set(bcf_srs_t *readers, sr_sort_t *srt, const char *chr, int min_pos) +{ + if ( !srt->grp_str2int ) + { + // first time here, initialize + if ( !srt->pair ) + { + if ( readers->collapse==COLLAPSE_NONE ) readers->collapse = BCF_SR_PAIR_EXACT; + bcf_sr_set_opt(readers, BCF_SR_PAIR_LOGIC, readers->collapse); + } + bcf_sr_init_scores(srt); + srt->grp_str2int = khash_str2int_init(); + srt->var_str2int = khash_str2int_init(); + } + int k; + khash_t(str2int) *hash; + hash = srt->grp_str2int; + for (k=0; k < kh_end(hash); k++) + if ( kh_exist(hash,k) ) free((char*)kh_key(hash,k)); + hash = srt->var_str2int; + for (k=0; k < kh_end(hash); k++) + if ( kh_exist(hash,k) ) free((char*)kh_key(hash,k)); + kh_clear(str2int, srt->grp_str2int); + kh_clear(str2int, srt->var_str2int); + srt->ngrp = srt->nvar = srt->nvset = 0; + + grp_t grp; + memset(&grp,0,sizeof(grp_t)); + + // group VCFs into groups, each with a unique combination of variants in the duplicate lines + int ireader,ivar,irec,igrp,ivset,iact; + for (ireader=0; ireadernreaders; ireader++) srt->vcf_buf[ireader].nrec = 0; + for (iact=0; iactnactive; iact++) + { + ireader = srt->active[iact]; + bcf_sr_t *reader = &readers->readers[ireader]; + int rid = bcf_hdr_name2id(reader->header, chr); + grp.nvar = 0; + hts_expand(int,reader->nbuffer,srt->moff,srt->off); + srt->noff = 0; + srt->str.l = 0; + for (irec=1; irec<=reader->nbuffer; irec++) + { + bcf1_t *line = reader->buffer[irec]; + if ( line->rid!=rid || line->pos!=min_pos ) break; + + if ( srt->str.l ) kputc(';',&srt->str); + srt->off[srt->noff++] = srt->str.l; + size_t beg = srt->str.l; + for (ivar=1; ivarn_allele; ivar++) + { + if ( ivar>1 ) kputc(',',&srt->str); + kputs(line->d.allele[0],&srt->str); + kputc('>',&srt->str); + kputs(line->d.allele[ivar],&srt->str); + } + if ( line->n_allele==1 ) + { + kputs(line->d.allele[0],&srt->str); + kputsn(">.",2,&srt->str); + } + + // Create new variant or attach to existing one. But careful, there can be duplicate + // records with the same POS,REF,ALT (e.g. in dbSNP-b142) + char *var_str = beg + srt->str.s; + int ret, var_idx = 0, var_end = srt->str.l; + while ( 1 ) + { + ret = khash_str2int_get(srt->var_str2int, var_str, &ivar); + if ( ret==-1 ) break; + + var_t *var = &srt->var[ivar]; + if ( var->vcf[var->nvcf-1] != ireader ) break; + + srt->str.l = var_end; + kputw(var_idx, &srt->str); + var_str = beg + srt->str.s; + var_idx++; + } + if ( ret==-1 ) + { + ivar = srt->nvar++; + hts_expand0(var_t,srt->nvar,srt->mvar,srt->var); + srt->var[ivar].nvcf = 0; + khash_str2int_set(srt->var_str2int, strdup(var_str), ivar); + free(srt->var[ivar].str); // possible left-over from the previous position + } + var_t *var = &srt->var[ivar]; + var->nalt = line->n_allele - 1; + var->type = bcf_get_variant_types(line); + srt->str.s[var_end] = 0; + if ( ret==-1 ) + var->str = strdup(var_str); + + int mvcf = var->mvcf; + var->nvcf++; + hts_expand0(int*, var->nvcf, var->mvcf, var->vcf); + if ( mvcf != var->mvcf ) var->rec = (bcf1_t **) realloc(var->rec,sizeof(bcf1_t*)*var->mvcf); + var->vcf[var->nvcf-1] = ireader; + var->rec[var->nvcf-1] = line; + + grp.nvar++; + hts_expand(var_t,grp.nvar,grp.mvar,grp.var); + grp.var[grp.nvar-1] = ivar; + } + char *grp_key = grp_create_key(srt); + int ret = khash_str2int_get(srt->grp_str2int, grp_key, &igrp); + if ( ret==-1 ) + { + igrp = srt->ngrp++; + hts_expand0(grp_t, srt->ngrp, srt->mgrp, srt->grp); + free(srt->grp[igrp].var); + srt->grp[igrp] = grp; + srt->grp[igrp].key = grp_key; + khash_str2int_set(srt->grp_str2int, grp_key, igrp); + memset(&grp,0,sizeof(grp_t)); + } + else + free(grp_key); + srt->grp[igrp].nvcf++; + } + free(grp.var); + + // initialize bitmask - which groups is the variant present in + for (ivar=0; ivarnvar; ivar++) + { + srt->var[ivar].mask = kbs_resize(srt->var[ivar].mask, srt->ngrp); + kbs_clear(srt->var[ivar].mask); + } + for (igrp=0; igrpngrp; igrp++) + { + for (ivar=0; ivargrp[igrp].nvar; ivar++) + { + int i = srt->grp[igrp].var[ivar]; + kbs_insert(srt->var[i].mask, igrp); + } + } + + // create the initial list of variant sets + for (ivar=0; ivarnvar; ivar++) + { + ivset = srt->nvset++; + hts_expand0(varset_t, srt->nvset, srt->mvset, srt->vset); + + varset_t *vset = &srt->vset[ivset]; + vset->nvar = 1; + hts_expand0(var_t, vset->nvar, vset->mvar, vset->var); + vset->var[vset->nvar-1] = ivar; + var_t *var = &srt->var[ivar]; + vset->cnt = var->nvcf; + vset->mask = kbs_resize(vset->mask, srt->ngrp); + kbs_clear(vset->mask); + kbs_bitwise_or(vset->mask, var->mask); + + int type = 0; + if ( var->type==VCF_REF ) type |= SR_REF; + else + { + if ( var->type & VCF_SNP ) type |= SR_SNP; + if ( var->type & VCF_MNP ) type |= SR_SNP; + if ( var->type & VCF_INDEL ) type |= SR_INDEL; + if ( var->type & VCF_OTHER ) type |= SR_OTHER; + } + var->type = type; + } +#if DEBUG_VSETS + debug_vsets(srt); +#endif + + // initialize the pairing matrix + hts_expand(int, srt->ngrp*srt->nvset, srt->mpmat, srt->pmat); + hts_expand(int, srt->nvset, srt->mcnt, srt->cnt); + memset(srt->pmat, 0, sizeof(*srt->pmat)*srt->ngrp*srt->nvset); + for (ivset=0; ivsetnvset; ivset++) + { + varset_t *vset = &srt->vset[ivset]; + for (igrp=0; igrpngrp; igrp++) srt->pmat[ivset*srt->ngrp+igrp] = 0; + srt->cnt[ivset] = vset->cnt; + } + + // pair the lines + while ( srt->nvset ) + { +#if DEBUG_VSETS + fprintf(stderr,"\n"); + debug_vsets(srt); +#endif + + int imax = 0; + for (ivset=1; ivsetnvset; ivset++) + if ( srt->cnt[imax] < srt->cnt[ivset] ) imax = ivset; + + int ipair = -1; + uint32_t max_score = 0; + for (ivset=0; ivsetnvset; ivset++) + { + if ( kbs_logical_and(srt->vset[imax].mask,srt->vset[ivset].mask) ) continue; // cannot be merged + uint32_t score = pairing_score(srt, imax, ivset); + // fprintf(stderr,"score: %d %d, logic=%d \t..\t %u\n", imax,ivset,srt->pair,score); + if ( max_score < score ) { max_score = score; ipair = ivset; } + } + + // merge rows creating a new variant set this way + if ( ipair!=-1 && ipair!=imax ) + { + imax = merge_vsets(srt, imax, ipair); + continue; + } + + push_vset(srt, imax); + } + + srt->chr = chr; + srt->pos = min_pos; +} + +int bcf_sr_sort_next(bcf_srs_t *readers, sr_sort_t *srt, const char *chr, int min_pos) +{ + int i,j; + assert( srt->nactive>0 ); + + if ( srt->nsr != readers->nreaders ) + { + srt->sr = readers; + if ( srt->nsr < readers->nreaders ) + { + srt->vcf_buf = (vcf_buf_t*) realloc(srt->vcf_buf,readers->nreaders*sizeof(vcf_buf_t)); + memset(srt->vcf_buf + srt->nsr, 0, sizeof(vcf_buf_t)*(readers->nreaders - srt->nsr)); + if ( srt->msr < srt->nsr ) srt->msr = srt->nsr; + } + srt->nsr = readers->nreaders; + srt->chr = NULL; + } + if ( srt->nactive == 1 ) + { + if ( readers->nreaders>1 ) + memset(readers->has_line, 0, readers->nreaders*sizeof(*readers->has_line)); + bcf_sr_t *reader = &readers->readers[srt->active[0]]; + assert( reader->buffer[1]->pos==min_pos ); + bcf1_t *tmp = reader->buffer[0]; + for (j=1; j<=reader->nbuffer; j++) reader->buffer[j-1] = reader->buffer[j]; + reader->buffer[ reader->nbuffer ] = tmp; + reader->nbuffer--; + readers->has_line[srt->active[0]] = 1; + return 1; + } + if ( !srt->chr || srt->pos!=min_pos || strcmp(srt->chr,chr) ) bcf_sr_sort_set(readers, srt, chr, min_pos); + + if ( !srt->vcf_buf[0].nrec ) return 0; + +#if DEBUG_VBUF + debug_vbuf(srt); +#endif + + int nret = 0; + for (i=0; isr->nreaders; i++) + { + vcf_buf_t *buf = &srt->vcf_buf[i]; + + if ( buf->rec[0] ) + { + bcf_sr_t *reader = &srt->sr->readers[i]; + for (j=1; j<=reader->nbuffer; j++) + if ( reader->buffer[j] == buf->rec[0] ) break; + + assert( j<=reader->nbuffer ); + + bcf1_t *tmp = reader->buffer[0]; + reader->buffer[0] = reader->buffer[j++]; + for (; j<=reader->nbuffer; j++) reader->buffer[j-1] = reader->buffer[j]; + reader->buffer[ reader->nbuffer ] = tmp; + reader->nbuffer--; + + nret++; + srt->sr->has_line[i] = 1; + } + else + srt->sr->has_line[i] = 0; + + buf->nrec--; + if ( buf->nrec > 0 ) + memmove(buf->rec, &buf->rec[1], buf->nrec*sizeof(bcf1_t*)); + } + return nret; +} +void bcf_sr_sort_remove_reader(bcf_srs_t *readers, sr_sort_t *srt, int i) +{ + free(srt->vcf_buf[i].rec); + if ( i+1 < srt->nsr ) + memmove(&srt->vcf_buf[i], &srt->vcf_buf[i+1], (srt->nsr - i - 1)*sizeof(vcf_buf_t)); + memset(srt->vcf_buf + srt->nsr - 1, 0, sizeof(vcf_buf_t)); +} +sr_sort_t *bcf_sr_sort_init(sr_sort_t *srt) +{ + if ( !srt ) return calloc(1,sizeof(sr_sort_t)); + memset(srt,0,sizeof(sr_sort_t)); + return srt; +} +void bcf_sr_sort_destroy(sr_sort_t *srt) +{ + free(srt->active); + if ( srt->var_str2int ) khash_str2int_destroy_free(srt->var_str2int); + if ( srt->grp_str2int ) khash_str2int_destroy_free(srt->grp_str2int); + int i; + for (i=0; insr; i++) free(srt->vcf_buf[i].rec); + free(srt->vcf_buf); + for (i=0; imvar; i++) + { + free(srt->var[i].str); + free(srt->var[i].vcf); + free(srt->var[i].rec); + kbs_destroy(srt->var[i].mask); + } + free(srt->var); + for (i=0; imgrp; i++) + free(srt->grp[i].var); + free(srt->grp); + for (i=0; imvset; i++) + { + kbs_destroy(srt->vset[i].mask); + free(srt->vset[i].var); + } + free(srt->vset); + free(srt->str.s); + free(srt->off); + free(srt->charp); + free(srt->cnt); + free(srt->pmat); + memset(srt,0,sizeof(*srt)); +} + diff --git a/htslib/bcf_sr_sort.h b/htslib/bcf_sr_sort.h new file mode 100644 index 000000000..81e776be1 --- /dev/null +++ b/htslib/bcf_sr_sort.h @@ -0,0 +1,106 @@ +/* + Copyright (C) 2017 Genome Research Ltd. + + Author: Petr Danecek + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +/* + Reorder duplicate lines so that compatible variant types are + returned together by bcf_sr_next_line() + + - readers grouped by variants. Even with many readers there will be + typically only several groups + +*/ + +#ifndef __BCF_SR_SORT_H__ +#define __BCF_SR_SORT_H__ + +#include "htslib/synced_bcf_reader.h" +#include "htslib/kbitset.h" + +typedef struct +{ + int nrec, mrec; + bcf1_t **rec; +} +vcf_buf_t; + +typedef struct +{ + char *str; // "A>C" for biallelic records or "A>C,A>CC" for multiallelic records + int type; // VCF_SNP, VCF_REF, etc. + int nalt; // number of alternate alleles in this record + int nvcf, mvcf, *vcf; // the list of readers with the same variants + bcf1_t **rec; // list of VCF records in the readers + kbitset_t *mask; // which groups contain the variant +} +var_t; + +typedef struct +{ + char *key; // only for debugging + int nvar, mvar, *var; // the variants and their type + int nvcf; // number of readers with the same variants +} +grp_t; + +typedef struct +{ + int nvar, mvar, *var; // list of compatible variants that can be output together + int cnt; // number of readers in this group + kbitset_t *mask; // which groups are populated in this set (replace with expandable bitmask) +} +varset_t; + +typedef struct +{ + uint8_t score[256]; + int nvar, mvar; + var_t *var; // list of all variants from all readers + int nvset, mvset; + int mpmat, *pmat; // pairing matrix, i-th vset and j-th group accessible as i*ngrp+j + int ngrp, mgrp; + int mcnt, *cnt; // number of VCF covered by a varset + grp_t *grp; // list of VCF representatives, each with a unique combination of duplicate lines + varset_t *vset; // list of variant sets - combinations of compatible variants across multiple groups ready for output + vcf_buf_t *vcf_buf; // records sorted in output order, for each VCF + bcf_srs_t *sr; + void *grp_str2int; + void *var_str2int; + kstring_t str; + int moff, noff, *off, mcharp; + char **charp; + const char *chr; + int pos, nsr, msr; + int pair; + int nactive, mactive, *active; // list of readers with lines at the current pos +} +sr_sort_t; + +sr_sort_t *bcf_sr_sort_init(sr_sort_t *srt); +int bcf_sr_sort_next(bcf_srs_t *readers, sr_sort_t *srt, const char *chr, int pos); +int bcf_sr_sort_set_active(sr_sort_t *srt, int i); +int bcf_sr_sort_add_active(sr_sort_t *srt, int i); +void bcf_sr_sort_destroy(sr_sort_t *srt); +void bcf_sr_sort_remove_reader(bcf_srs_t *readers, sr_sort_t *srt, int i); + +#endif diff --git a/htslib/bgzf.c b/htslib/bgzf.c index 22d804004..00ecd85f4 100644 --- a/htslib/bgzf.c +++ b/htslib/bgzf.c @@ -1,19 +1,15 @@ /* The MIT License - Copyright (c) 2008 Broad Institute / Massachusetts Institute of Technology 2011, 2012 Attractive Chaos Copyright (C) 2009, 2013-2016 Genome Research Ltd - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -61,7 +57,6 @@ | | | | FLG.EXTRA XLEN B C E/D - BGZF format is compatible with GZIP. It limits the size of each compressed block to 2^16 bytes and adds and an extra "BC" field in the gzip header which records the size. @@ -73,7 +68,6 @@ 64 bytes), initialization vector used to encrypt the data (16 bytes), compressed and encrypted data (BLK_LEN - 64 - 16 bytes). When present, the "DC" block is first in the file. - */ static const uint8_t bc_magic[19] = "\037\213\010\4\0\0\0\0\0\377\6\0\102\103\2\0\0\0"; static const uint8_t ec_magic[19] = "\037\213\010\4\0\0\0\0\0\377\6\0\105\103\2\0\0\0"; @@ -89,6 +83,11 @@ typedef struct { KHASH_MAP_INIT_INT64(cache, cache_t) #endif +struct bgzf_cache_t { + khash_t(cache) *h; // hash table h of type "cache" + khint_t last_pos; // iterator pointing to the last pos in hash table +}; + #ifdef BGZF_MT typedef struct bgzf_job { @@ -267,7 +266,16 @@ static BGZF *bgzf_read_init(hFILE *hfpr) fp->is_gzip = ( !fp->is_compressed || ((magic[3]&4) && memcmp(&magic[12], "BC\2\0",4)==0) ) ? 0 : 1; #ifdef BGZF_CACHE - fp->cache = kh_init(cache); + if (!(fp->cache = malloc(sizeof(*fp->cache)))) { + free(fp); + return NULL; + } + if (!(fp->cache->h = kh_init(cache))) { + free(fp->cache); + free(fp); + return NULL; + } + fp->cache->last_pos = 0; #endif return fp; } @@ -679,11 +687,12 @@ static int check_header(const uint8_t *header) static void free_cache(BGZF *fp) { khint_t k; - khash_t(cache) *h = (khash_t(cache)*)fp->cache; if (fp->is_write) return; + khash_t(cache) *h = fp->cache->h; for (k = kh_begin(h); k < kh_end(h); ++k) if (kh_exist(h, k)) free(kh_val(h, k).block); kh_destroy(cache, h); + free(fp->cache); } static int load_block_from_cache(BGZF *fp, int64_t block_address) @@ -691,19 +700,18 @@ static int load_block_from_cache(BGZF *fp, int64_t block_address) khint_t k; cache_t *p; - khash_t(cache) *h = (khash_t(cache)*)fp->cache; + khash_t(cache) *h = fp->cache->h; k = kh_get(cache, h, block_address); if (k == kh_end(h)) return 0; p = &kh_val(h, k); if (fp->block_length != 0) fp->block_offset = 0; fp->block_address = block_address; fp->block_length = p->size; - // FIXME: why BGZF_MAX_BLOCK_SIZE and not p->size? - memcpy(fp->uncompressed_block, p->block, BGZF_MAX_BLOCK_SIZE); + memcpy(fp->uncompressed_block, p->block, p->size); if ( hseek(fp->fp, p->end_offset, SEEK_SET) < 0 ) { // todo: move the error up - fprintf(stderr,"Could not hseek to %"PRId64"\n", p->end_offset); + hts_log_error("Could not hseek to %"PRId64"", p->end_offset); exit(1); } return p->size; @@ -712,29 +720,48 @@ static int load_block_from_cache(BGZF *fp, int64_t block_address) static void cache_block(BGZF *fp, int size) { int ret; - khint_t k; + khint_t k, k_orig; + uint8_t *block = NULL; cache_t *p; //fprintf(stderr, "Cache block at %llx\n", (int)fp->block_address); - khash_t(cache) *h = (khash_t(cache)*)fp->cache; + khash_t(cache) *h = fp->cache->h; if (BGZF_MAX_BLOCK_SIZE >= fp->cache_size) return; + if (fp->block_length < 0 || fp->block_length > BGZF_MAX_BLOCK_SIZE) return; if ((kh_size(h) + 1) * BGZF_MAX_BLOCK_SIZE > (uint32_t)fp->cache_size) { - /* A better way would be to remove the oldest block in the - * cache, but here we remove a random one for simplicity. This - * should not have a big impact on performance. */ - for (k = kh_begin(h); k < kh_end(h); ++k) - if (kh_exist(h, k)) break; - if (k < kh_end(h)) { - free(kh_val(h, k).block); + /* Remove uniformly from any position in the hash by a simple + * round-robin approach. An alternative strategy would be to + * remove the least recently accessed block, but the round-robin + * removal is simpler and is not expected to have a big impact + * on performance */ + if (fp->cache->last_pos >= kh_end(h)) fp->cache->last_pos = kh_begin(h); + k_orig = k = fp->cache->last_pos; + if (++k >= kh_end(h)) k = kh_begin(h); + while (k != k_orig) { + if (kh_exist(h, k)) + break; + if (++k == kh_end(h)) + k = kh_begin(h); + } + fp->cache->last_pos = k; + + if (k != k_orig) { + block = kh_val(h, k).block; kh_del(cache, h, k); } + } else { + block = (uint8_t*)malloc(BGZF_MAX_BLOCK_SIZE); } + if (!block) return; k = kh_put(cache, h, fp->block_address, &ret); - if (ret == 0) return; // if this happens, a bug! + if (ret <= 0) { // kh_put failed, or in there already (shouldn't happen) + free(block); + return; + } p = &kh_val(h, k); p->size = fp->block_length; p->end_offset = fp->block_address + size; - p->block = (uint8_t*)malloc(BGZF_MAX_BLOCK_SIZE); - memcpy(kh_val(h, k).block, fp->uncompressed_block, BGZF_MAX_BLOCK_SIZE); + p->block = block; + memcpy(p->block, fp->uncompressed_block, p->size); } #else static void free_cache(BGZF *fp) {} @@ -1963,3 +1990,8 @@ long bgzf_utell(BGZF *fp) { return fp->uncompressed_address; // currently maintained only when reading } + +/* prototype is in hfile_internal.h */ +struct hFILE *bgzf_hfile(struct BGZF *fp) { + return fp->fp; +} diff --git a/htslib/bgzip.c b/htslib/bgzip.c index 861f7026c..65f3a5027 100644 --- a/htslib/bgzip.c +++ b/htslib/bgzip.c @@ -1,7 +1,7 @@ /* bgzip.c -- Block compression/decompression utility. Copyright (C) 2008, 2009 Broad Institute / Massachusetts Institute of Technology - Copyright (C) 2010, 2013-2016 Genome Research Ltd. + Copyright (C) 2010, 2013-2018 Genome Research Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -36,6 +36,11 @@ #include "htslib/bgzf.h" #include "htslib/hts.h" +#ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# include +#endif + static const int WINDOW_SIZE = 64 * 1024; static void error(const char *format, ...) @@ -125,7 +130,7 @@ int main(int argc, char **argv) case 1: printf( "bgzip (htslib) %s\n" -"Copyright (C) 2016 Genome Research Ltd.\n", hts_version()); +"Copyright (C) 2018 Genome Research Ltd.\n", hts_version()); return EXIT_SUCCESS; case 'h': case '?': return bgzip_main_usage(); @@ -198,6 +203,9 @@ int main(int argc, char **argv) if ( index ) bgzf_index_build_init(fp); buffer = malloc(WINDOW_SIZE); +#ifdef _WIN32 + _setmode(f_src, O_BINARY); +#endif if (rebgzip){ if ( bgzf_index_load(fp, index_fname, NULL) < 0 ) error("Could not load index: %s.gzi\n", argv[optind]); @@ -319,13 +327,21 @@ int main(int argc, char **argv) if ( bgzf_index_load(fp, argv[optind], ".gzi") < 0 ) error("Could not load index: %s.gzi\n", argv[optind]); if ( bgzf_useek(fp, start, SEEK_SET) < 0 ) error("Could not seek to %d-th (uncompressd) byte\n", start); } +#ifdef _WIN32 + _setmode(f_dst, O_BINARY); +#endif while (1) { if (end < 0) c = bgzf_read(fp, buffer, WINDOW_SIZE); else c = bgzf_read(fp, buffer, (end - start > WINDOW_SIZE)? WINDOW_SIZE:(end - start)); if (c == 0) break; if (c < 0) error("Could not read %d bytes: Error %d\n", (end - start > WINDOW_SIZE)? WINDOW_SIZE:(end - start), fp->errcode); start += c; - if ( write(f_dst, buffer, c) != c ) error("Could not write %d bytes\n", c); + if ( write(f_dst, buffer, c) != c ) { +#ifdef _WIN32 + if (GetLastError() != ERROR_NO_DATA) +#endif + error("Could not write %d bytes\n", c); + } if (end >= 0 && start >= end) break; } free(buffer); @@ -333,5 +349,4 @@ int main(int argc, char **argv) if (!pstdout) unlink(argv[optind]); return 0; } - return 0; } diff --git a/htslib/config.h.in b/htslib/config.h.in index d744f9fb6..0ed6b484a 100644 --- a/htslib/config.h.in +++ b/htslib/config.h.in @@ -10,15 +10,30 @@ the PACKAGE_* defines are unused and are overridden by the more accurate PACKAGE_VERSION as computed by the Makefile. */ +/* Define if HTSlib should enable GCS support. */ +#undef ENABLE_GCS + /* Define if HTSlib should enable plugins. */ #undef ENABLE_PLUGINS +/* Define if HTSlib should enable S3 support. */ +#undef ENABLE_S3 + /* Define if you have the Common Crypto library. */ #undef HAVE_COMMONCRYPTO +/* Define to 1 if you have the `drand48' function. */ +#undef HAVE_DRAND48 + /* Define to 1 if you have the `fdatasync' function. */ #undef HAVE_FDATASYNC +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#undef HAVE_FSEEKO + +/* Define to 1 if you have the `fsync' function. */ +#undef HAVE_FSYNC + /* Define to 1 if you have the `getpagesize' function. */ #undef HAVE_GETPAGESIZE @@ -31,12 +46,21 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H +/* Define to 1 if you have the `bz2' library (-lbz2). */ +#undef HAVE_LIBBZ2 + /* Define if libcurl file access is enabled. */ #undef HAVE_LIBCURL +/* Define to 1 if you have the `lzma' library (-llzma). */ +#undef HAVE_LIBLZMA + /* Define to 1 if you have the `z' library (-lz). */ #undef HAVE_LIBZ +/* Define to 1 if you have the header file. */ +#undef HAVE_LZMA_H + /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H @@ -102,5 +126,11 @@ /* Number of bits in a file offset, on hosts where this is settable. */ #undef _FILE_OFFSET_BITS +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +#undef _LARGEFILE_SOURCE + /* Define for large files, on AIX-style hosts. */ #undef _LARGE_FILES + +/* Needed for PTHREAD_MUTEX_RECURSIVE */ +#undef _XOPEN_SOURCE diff --git a/htslib/config.mk.in b/htslib/config.mk.in index d525d4099..6f19e40ba 100644 --- a/htslib/config.mk.in +++ b/htslib/config.mk.in @@ -1,6 +1,6 @@ # Optional configure Makefile overrides for htslib. # -# Copyright (C) 2015, 2016 Genome Research Ltd. +# Copyright (C) 2015-2017 Genome Research Ltd. # # Author: John Marshall # @@ -68,6 +68,18 @@ noplugin_LIBS += $(LIBCURL_LIBS) endif +ifeq "gcs-@gcs@" "gcs-enabled" +plugin_OBJS += hfile_gcs.o +endif + +ifeq "s3-@s3@" "s3-enabled" +plugin_OBJS += hfile_s3.o + +CRYPTO_LIBS = @CRYPTO_LIBS@ +noplugin_LIBS += $(CRYPTO_LIBS) +hfile_s3$(PLUGIN_EXT): LIBS += $(CRYPTO_LIBS) +endif + ifeq "plugins-@enable_plugins@" "plugins-yes" plugindir = @plugindir@ @@ -79,7 +91,9 @@ PLUGIN_OBJS += $(plugin_OBJS) plugin.o plugin.pico: CPPFLAGS += -DPLUGINPATH=\"$(pluginpath)\" # When built as separate plugins, these record their version themselves. +hfile_gcs.o hfile_gcs.pico: version.h hfile_libcurl.o hfile_libcurl.pico: version.h +hfile_s3.o hfile_s3.pico: version.h # Windows DLL plugins depend on the import library, built as a byproduct. $(plugin_OBJS:.o=.cygdll): cyghts-$(LIBHTS_SOVERSION).dll diff --git a/htslib/configure b/htslib/configure index bb9b22386..12d3de0dc 100755 --- a/htslib/configure +++ b/htslib/configure @@ -1,11 +1,13 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for HTSlib 1.3.2. +# Generated by GNU Autoconf 2.68 for HTSlib 1.7. # # Report bugs to . # # -# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software +# Foundation, Inc. # # # This configure script is free software; the Free Software Foundation @@ -139,31 +141,6 @@ export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH -# Use a proper internal environment variable to ensure we don't fall - # into an infinite loop, continuously re-executing ourselves. - if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then - _as_can_reexec=no; export _as_can_reexec; - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -as_fn_exit 255 - fi - # We don't want this to propagate to other subprocesses. - { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh @@ -197,8 +174,7 @@ if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi -test x\$exitcode = x0 || exit 1 -test -x / || exit 1" +test x\$exitcode = x0 || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && @@ -243,25 +219,21 @@ IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : - export CONFIG_SHELL - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -exit 255 + # We cannot yet assume a decent shell, so we have to provide a + # neutralization value for shells without unset; and this also + # works around shells that cannot unset nonexistent variables. + # Preserve -v and -x to the replacement shell. + BASH_ENV=/dev/null + ENV=/dev/null + (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV + export CONFIG_SHELL + case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; + esac + exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"} fi if test x$as_have_required = xno; then : @@ -364,14 +336,6 @@ $as_echo X"$as_dir" | } # as_fn_mkdir_p - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take @@ -493,10 +457,6 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } - # If we had to re-execute with $CONFIG_SHELL, we're ensured to have - # already done that, so ensure we don't try to do so again and fall - # in an infinite loop. This has already happened in practice. - _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). @@ -531,16 +491,16 @@ if (echo >conf$$.file) 2>/dev/null; then # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -552,8 +512,28 @@ else as_mkdir_p=false fi -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -585,8 +565,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='HTSlib' PACKAGE_TARNAME='htslib' -PACKAGE_VERSION='1.3.2' -PACKAGE_STRING='HTSlib 1.3.2' +PACKAGE_VERSION='1.7' +PACKAGE_STRING='HTSlib 1.7' PACKAGE_BUGREPORT='samtools-help@lists.sourceforge.net' PACKAGE_URL='http://www.htslib.org/' @@ -630,17 +610,23 @@ ac_includes_default="\ ac_subst_vars='LTLIBOBJS LIBOBJS +static_LIBS +static_LDFLAGS +private_LIBS +pc_requires openssl CRYPTO_LIBS +s3 +gcs libcurl PLUGIN_EXT EGREP -GREP CPP PLATFORM pluginpath plugindir enable_plugins +GREP RANLIB OBJEXT EXEEXT @@ -690,12 +676,18 @@ SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking +enable_warnings +enable_werror +enable_bz2 +enable_gcs enable_largefile enable_libcurl +enable_lzma enable_openssl enable_plugins with_plugin_dir with_plugin_path +enable_s3 ' ac_precious_vars='build_alias host_alias @@ -1161,6 +1153,8 @@ target=$target_alias if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe + $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used" >&2 elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi @@ -1246,7 +1240,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures HTSlib 1.3.2 to adapt to many kinds of systems. +\`configure' configures HTSlib 1.7 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1307,7 +1301,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of HTSlib 1.3.2:";; + short | recursive ) echo "Configuration of HTSlib 1.7:";; esac cat <<\_ACEOF @@ -1315,10 +1309,16 @@ Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --disable-warnings turn off compiler warnings + --enable-werror change warnings into errors, where supported + --disable-bz2 omit support for BZ2-compressed CRAM files + --enable-gcs support Google Cloud Storage URLs --disable-largefile omit support for large files --enable-libcurl enable libcurl-based support for http/https/etc URLs + --disable-lzma omit support for LZMA-compressed CRAM files --enable-openssl enable openssl-based support for encrypted BGZF --enable-plugins enable separately-compiled plugins for file access + --enable-s3 support Amazon AWS S3 URLs Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -1403,10 +1403,10 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -HTSlib configure 1.3.2 -generated by GNU Autoconf 2.69 +HTSlib configure 1.7 +generated by GNU Autoconf 2.68 -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2010 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. @@ -1460,6 +1460,52 @@ fi } # ac_fn_c_try_compile +# ac_fn_c_try_link LINENO +# ----------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + $as_test_x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_link + # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in @@ -1570,52 +1616,6 @@ fi } # ac_fn_c_try_run -# ac_fn_c_try_link LINENO -# ----------------------- -# Try to link conftest.$ac_ext, and return whether this succeeded. -ac_fn_c_try_link () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext conftest$ac_exeext - if { { ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_link") 2>conftest.err - ac_status=$? - if test -s conftest.err; then - grep -v '^ *+' conftest.err >conftest.er1 - cat conftest.er1 >&5 - mv -f conftest.er1 conftest.err - fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - test -x conftest$ac_exeext - }; then : - ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_retval=1 -fi - # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information - # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would - # interfere with the next link command; also delete a directory that is - # left behind by Apple's compiler. We do this before executing the actions. - rm -rf conftest.dSYM conftest_ipa8_conftest.oo - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval - -} # ac_fn_c_try_link - # ac_fn_c_check_func LINENO FUNC VAR # ---------------------------------- # Tests whether FUNC exists, setting the cache variable VAR accordingly @@ -1732,8 +1732,8 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by HTSlib $as_me 1.3.2, which was -generated by GNU Autoconf 2.69. Invocation command line was +It was created by HTSlib $as_me 1.7, which was +generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -2089,6 +2089,17 @@ ac_config_headers="$ac_config_headers config.h" +# SYNOPSIS +# +# HTS_PROG_CC_WERROR(FLAGS_VAR) +# +# Set FLAGS_VAR to the flags needed to make the C compiler treat warnings +# as errors. + + + + + ac_ext=c @@ -2113,7 +2124,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2153,7 +2164,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2206,7 +2217,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2247,7 +2258,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue @@ -2305,7 +2316,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2349,7 +2360,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2795,7 +2806,8 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include -struct stat; +#include +#include /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); @@ -2897,7 +2909,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2937,7 +2949,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_RANLIB="ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2973,84 +2985,389 @@ else fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +$as_echo_n "checking for grep that handles long lines and -e... " >&6; } +if ${ac_cv_path_GREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$GREP"; then + ac_path_GREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue +# Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_GREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_GREP"; then + as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_GREP=$GREP +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +$as_echo "$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + -# Check whether --enable-largefile was given. -if test "${enable_largefile+set}" = set; then : - enableval=$enable_largefile; + + # Check whether --enable-warnings was given. +if test "${enable_warnings+set}" = set; then : + enableval=$enable_warnings; +else + enable_warnings=yes fi -if test "$enable_largefile" != no; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for special C compiler options needed for large files" >&5 -$as_echo_n "checking for special C compiler options needed for large files... " >&6; } -if ${ac_cv_sys_largefile_CC+:} false; then : + if test "x$enable_warnings" != xno; then : + + + + ansi="" + if test "x$ansi" = "x"; then : + msg="for C compiler warning flags" +else + msg="for C compiler warning and ANSI conformance flags" +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking $msg" >&5 +$as_echo_n "checking $msg... " >&6; } + if ${hts_cv_prog_cc_warnings+:} false; then : $as_echo_n "(cached) " >&6 else - ac_cv_sys_largefile_CC=no - if test "$GCC" != yes; then - ac_save_CC=$CC - while :; do - # IRIX 6.2 and later do not support large files by default, - # so use the C compiler's -n32 option if that helps. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include - /* Check that off_t can represent 2**63 - 1 correctly. - We can't simply define LARGE_OFF_T to be 9223372036854775807, - since some C++ compilers masquerading as C compilers - incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) - int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]; -int -main () -{ + hts_cv_prog_cc_warnings="" + if test "x$CC" != "x"; then : - ; - return 0; -} -_ACEOF - if ac_fn_c_try_compile "$LINENO"; then : - break + cat > conftest.c < /dev/null 2>&1 && + test -f conftest.o; then : + if test "x$ansi" = "x"; then : + hts_cv_prog_cc_warnings="-Wall" +else + hts_cv_prog_cc_warnings="-Wall -ansi -pedantic" fi -rm -f core conftest.err conftest.$ac_objext - CC="$CC -n32" - if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_sys_largefile_CC=' -n32'; break + +elif # Sun Studio or Solaris C compiler + "$CC" -V 2>&1 | $GREP -i -E "WorkShop|Sun C" > /dev/null 2>&1 && + "$CC" -c -v -Xc conftest.c > /dev/null 2>&1 && + test -f conftest.o; then : + if test "x$ansi" = "x"; then : + hts_cv_prog_cc_warnings="-v" +else + hts_cv_prog_cc_warnings="-v -Xc" fi -rm -f core conftest.err conftest.$ac_objext - break - done - CC=$ac_save_CC - rm -f conftest.$ac_ext - fi + +elif # Digital Unix C compiler + "$CC" -V 2>&1 | $GREP -i "Digital UNIX Compiler" > /dev/null 2>&1 && + "$CC" -c -verbose -w0 -warnprotos -std1 conftest.c > /dev/null 2>&1 && + test -f conftest.o; then : + if test "x$ansi" = "x"; then : + hts_cv_prog_cc_warnings="-verbose -w0 -warnprotos" +else + hts_cv_prog_cc_warnings="-verbose -w0 -warnprotos -std1" fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_largefile_CC" >&5 -$as_echo "$ac_cv_sys_largefile_CC" >&6; } - if test "$ac_cv_sys_largefile_CC" != no; then - CC=$CC$ac_cv_sys_largefile_CC - fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _FILE_OFFSET_BITS value needed for large files" >&5 -$as_echo_n "checking for _FILE_OFFSET_BITS value needed for large files... " >&6; } -if ${ac_cv_sys_file_offset_bits+:} false; then : - $as_echo_n "(cached) " >&6 +elif # C for AIX Compiler + "$CC" 2>&1 | $GREP -i "C for AIX Compiler" > /dev/null 2>&1 && + "$CC" -c -qlanglvl=ansi -qinfo=all conftest.c > /dev/null 2>&1 && + test -f conftest.o; then : + if test "x$ansi" = "x"; then : + hts_cv_prog_cc_warnings="-qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" else - while :; do - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include - /* Check that off_t can represent 2**63 - 1 correctly. - We can't simply define LARGE_OFF_T to be 9223372036854775807, - since some C++ compilers masquerading as C compilers - incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) - int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]; -int -main () + hts_cv_prog_cc_warnings="-qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd -qlanglvl=ansi" +fi + +elif # IRIX C compiler + "$CC" -version 2>&1 | $GREP -i "MIPSpro Compilers" > /dev/null 2>&1 && + "$CC" -c -fullwarn -ansi -ansiE conftest.c > /dev/null 2>&1 && + test -f conftest.o; then : + if test "x$ansi" = "x"; then : + hts_cv_prog_cc_warnings="-fullwarn" +else + hts_cv_prog_cc_warnings="-fullwarn -ansi -ansiE" +fi + +elif # HP-UX C compiler + what "$CC" 2>&1 | $GREP -i "HP C Compiler" > /dev/null 2>&1 && + "$CC" -c -Aa +w1 conftest.c > /dev/null 2>&1 && + test -f conftest.o; then : + if test "x$ansi" = "x"; then : + hts_cv_prog_cc_warnings="+w1" +else + hts_cv_prog_cc_warnings="+w1 -Aa" +fi + +elif # The NEC SX series (Super-UX 10) C compiler + "$CC" -V 2>&1 | $GREP "/SX" > /dev/null 2>&1 && + "$CC" -c -pvctl,fullmsg -Xc conftest.c > /dev/null 2>&1 && + test -f conftest.o; then : + + if test "x$ansi" = "x"; then : + hts_cv_prog_cc_warnings="-pvctl,fullmsg" +else + hts_cv_prog_cc_warnings="-pvctl,fullmsg -Xc" +fi + +elif # The Cray C compiler (Unicos) + "$CC" -V 2>&1 | $GREP -i "Cray" > /dev/null 2>&1 && + "$CC" -c -h msglevel_2 conftest.c > /dev/null 2>&1 && + test -f conftest.o; then : + if test "x$ansi" = "x"; then : + hts_cv_prog_cc_warnings="-h#msglevel_2" +else + hts_cv_prog_cc_warnings="-h#msglevel_2,conform" +fi + +elif # The Tiny C Compiler + "$CC" -v 2>&1 | $GREP "tcc version" > /dev/null && + "$CC" -Wall -c conftest.c > /dev/null 2>&1 && + test -f conftest.o; then : + hts_cv_prog_cc_warnings="-Wall" + +fi + rm -f conftest.* + +fi + +fi + + + if test "x$hts_cv_prog_cc_warnings" != "x"; then : + +ac_arg_result=`echo "$hts_cv_prog_cc_warnings" | tr '#' ' '` +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_arg_result" >&5 +$as_echo "$ac_arg_result" >&6; } + +ac_arg_needed="" +for ac_arg in $hts_cv_prog_cc_warnings +do + ac_arg_sp=`echo "$ac_arg" | tr '#' ' '` + case " $CFLAGS " in #( + *" $ac_arg_sp "*) : + ;; #( + *) : + ac_arg_needed="$ac_arg_all $ac_arg_sp" ;; +esac +done +CFLAGS="$ac_arg_needed $CFLAGS" +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unknown" >&5 +$as_echo "unknown" >&6; } + +fi + +fi + + + # Check whether --enable-werror was given. +if test "${enable_werror+set}" = set; then : + enableval=$enable_werror; enable_werror=yes +fi + + + if test "x$enable_werror" = xyes; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler flags to error on warnings" >&5 +$as_echo_n "checking for C compiler flags to error on warnings... " >&6; } + if ${hts_cv_prog_cc_werror+:} false; then : + $as_echo_n "(cached) " >&6 +else + hts_cv_prog_cc_werror="" + if test "x$CC" != "x"; then : + + cat > conftest.c < /dev/null 2>&1 && + test -f conftest.o; then : + hts_cv_prog_cc_werror="-Werror" +elif # Sun Studio or Solaris C compiler + "$CC" -V 2>&1 | $GREP -i -E "WorkShop|Sun C" > /dev/null 2>&1 && + "$CC" -c -errwarn=%all conftest.c > /dev/null 2>&1 && + test -f conftest.o; then : + hts_cv_prog_cc_werror="-errwarn=%all" +elif # The Tiny C Compiler + "$CC" -v 2>&1 | $GREP "tcc version" > /dev/null && + "$CC" -Wall -c conftest.c > /dev/null 2>&1 && + test -f conftest.o; then : + hts_cv_prog_cc_werror="-Werror" + +fi + rm -f conftest.* + +fi + +fi + + if test "x$hts_cv_prog_cc_werror" != x; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hts_cv_prog_cc_werror" >&5 +$as_echo "$hts_cv_prog_cc_werror" >&6; } + if test "xhts_late_cflags" != x; then : + eval hts_late_cflags="$hts_cv_prog_cc_werror" +fi + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unknown" >&5 +$as_echo "unknown" >&6; } + +fi + +fi + + +PKG_CONFIG="" + +need_crypto=no +pc_requires= +static_LDFLAGS= +static_LIBS='-lz -lm' +private_LIBS= + +# Check whether --enable-bz2 was given. +if test "${enable_bz2+set}" = set; then : + enableval=$enable_bz2; +else + enable_bz2=yes +fi + + +# Check whether --enable-gcs was given. +if test "${enable_gcs+set}" = set; then : + enableval=$enable_gcs; +else + enable_gcs=check +fi + + + +# Check whether --enable-largefile was given. +if test "${enable_largefile+set}" = set; then : + enableval=$enable_largefile; +fi + +if test "$enable_largefile" != no; then + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for special C compiler options needed for large files" >&5 +$as_echo_n "checking for special C compiler options needed for large files... " >&6; } +if ${ac_cv_sys_largefile_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_sys_largefile_CC=no + if test "$GCC" != yes; then + ac_save_CC=$CC + while :; do + # IRIX 6.2 and later do not support large files by default, + # so use the C compiler's -n32 option if that helps. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main () +{ + + ; + return 0; +} +_ACEOF + if ac_fn_c_try_compile "$LINENO"; then : + break +fi +rm -f core conftest.err conftest.$ac_objext + CC="$CC -n32" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_sys_largefile_CC=' -n32'; break +fi +rm -f core conftest.err conftest.$ac_objext + break + done + CC=$ac_save_CC + rm -f conftest.$ac_ext + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_largefile_CC" >&5 +$as_echo "$ac_cv_sys_largefile_CC" >&6; } + if test "$ac_cv_sys_largefile_CC" != no; then + CC=$CC$ac_cv_sys_largefile_CC + fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _FILE_OFFSET_BITS value needed for large files" >&5 +$as_echo_n "checking for _FILE_OFFSET_BITS value needed for large files... " >&6; } +if ${ac_cv_sys_file_offset_bits+:} false; then : + $as_echo_n "(cached) " >&6 +else + while :; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main () { ; @@ -3170,7 +3487,73 @@ _ACEOF esac rm -rf conftest* fi +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for _LARGEFILE_SOURCE value needed for large files" >&5 +$as_echo_n "checking for _LARGEFILE_SOURCE value needed for large files... " >&6; } +if ${ac_cv_sys_largefile_source+:} false; then : + $as_echo_n "(cached) " >&6 +else + while :; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include /* for off_t */ + #include +int +main () +{ +int (*fp) (FILE *, off_t, int) = fseeko; + return fseeko (stdin, 0, 0) && fp (stdin, 0, 0); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_sys_largefile_source=no; break +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#define _LARGEFILE_SOURCE 1 +#include /* for off_t */ + #include +int +main () +{ +int (*fp) (FILE *, off_t, int) = fseeko; + return fseeko (stdin, 0, 0) && fp (stdin, 0, 0); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_sys_largefile_source=1; break +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + ac_cv_sys_largefile_source=unknown + break +done +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_largefile_source" >&5 +$as_echo "$ac_cv_sys_largefile_source" >&6; } +case $ac_cv_sys_largefile_source in #( + no | unknown) ;; + *) +cat >>confdefs.h <<_ACEOF +#define _LARGEFILE_SOURCE $ac_cv_sys_largefile_source +_ACEOF +;; +esac +rm -rf conftest* + +# We used to try defining _XOPEN_SOURCE=500 too, to work around a bug +# in glibc 2.1.3, but that breaks too many other things. +# If you want fseeko and ftello with glibc, upgrade to a fixed glibc. +if test $ac_cv_sys_largefile_source != unknown; then +$as_echo "#define HAVE_FSEEKO 1" >>confdefs.h fi @@ -3181,7 +3564,15 @@ need_crypto=no if test "${enable_libcurl+set}" = set; then : enableval=$enable_libcurl; else - enable_libcurl=no + enable_libcurl=check +fi + + +# Check whether --enable-lzma was given. +if test "${enable_lzma+set}" = set; then : + enableval=$enable_lzma; +else + enable_lzma=yes fi @@ -3229,9 +3620,17 @@ fi pluginpath=$with_plugin_path -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking shared library type" >&5 -$as_echo_n "checking shared library type... " >&6; } +# Check whether --enable-s3 was given. +if test "${enable_s3+set}" = set; then : + enableval=$enable_s3; +else + enable_s3=check +fi + + test -n "$host_alias" || host_alias=unknown-`uname -s` +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking shared library type for $host_alias" >&5 +$as_echo_n "checking shared library type for $host_alias... " >&6; } case $host_alias in *-cygwin* | *-CYGWIN*) host_result="Cygwin DLL" @@ -3243,6 +3642,15 @@ case $host_alias in PLATFORM=Darwin PLUGIN_EXT=.bundle ;; + *-msys* | *-MSYS* | *-mingw* | *-MINGW*) + host_result="MSYS dll" + PLATFORM=MSYS + PLUGIN_EXT=.dll + # This also sets __USE_MINGW_ANSI_STDIO which in turn makes PRId64, + # %lld and %z printf formats work. It also enforces the snprintf to + # be C99 compliant so it returns the correct values (in kstring.c). + CPPFLAGS="$CPPCFLAGS -D_XOPEN_SOURCE=600" + ;; *) host_result="plain .so" PLATFORM=default @@ -3391,69 +3799,6 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 -$as_echo_n "checking for grep that handles long lines and -e... " >&6; } -if ${ac_cv_path_GREP+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -z "$GREP"; then - ac_path_GREP_found=false - # Loop through the user's path and test for each of PROGNAME-LIST - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in grep ggrep; do - for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_GREP" || continue -# Check for GNU ac_path_GREP and select it if it is found. - # Check for GNU $ac_path_GREP -case `"$ac_path_GREP" --version 2>&1` in -*GNU*) - ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; -*) - ac_count=0 - $as_echo_n 0123456789 >"conftest.in" - while : - do - cat "conftest.in" "conftest.in" >"conftest.tmp" - mv "conftest.tmp" "conftest.in" - cp "conftest.in" "conftest.nl" - $as_echo 'GREP' >> "conftest.nl" - "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break - diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break - as_fn_arith $ac_count + 1 && ac_count=$as_val - if test $ac_count -gt ${ac_path_GREP_max-0}; then - # Best one so far, save it but keep looking for a better one - ac_cv_path_GREP="$ac_path_GREP" - ac_path_GREP_max=$ac_count - fi - # 10*(2^10) chars as input seems more than enough - test $ac_count -gt 10 && break - done - rm -f conftest.in conftest.tmp conftest.nl conftest.out;; -esac - - $ac_path_GREP_found && break 3 - done - done - done -IFS=$as_save_IFS - if test -z "$ac_cv_path_GREP"; then - as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 - fi -else - ac_cv_path_GREP=$GREP -fi - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 -$as_echo "$ac_cv_path_GREP" >&6; } - GREP="$ac_cv_path_GREP" - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 $as_echo_n "checking for egrep... " >&6; } if ${ac_cv_path_EGREP+:} false; then : @@ -3473,7 +3818,7 @@ do for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_EGREP" || continue + { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in @@ -3851,12 +4196,13 @@ $as_echo "#define HAVE_MMAP 1" >>confdefs.h fi rm -f conftest.mmap conftest.txt -for ac_func in gmtime_r +for ac_func in gmtime_r fsync drand48 do : - ac_fn_c_check_func "$LINENO" "gmtime_r" "ac_cv_func_gmtime_r" -if test "x$ac_cv_func_gmtime_r" = xyes; then : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF -#define HAVE_GMTIME_R 1 +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi @@ -3945,6 +4291,10 @@ fi # TODO Test whether this is required and/or needs tweaking per-platform LDFLAGS="$LDFLAGS -rdynamic" + static_LDFLAGS="$static_LDFLAGS -rdynamic" + case "$ac_cv_search_dlopen" in + -l*) static_LIBS="$static_LIBS $ac_cv_search_dlopen" ;; + esac $as_echo "#define ENABLE_PLUGINS 1" >>confdefs.h @@ -3956,7 +4306,68 @@ _ACEOF fi -save_LIBS=$LIBS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing log" >&5 +$as_echo_n "checking for library containing log... " >&6; } +if ${ac_cv_search_log+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char log (); +int +main () +{ +return log (); + ; + return 0; +} +_ACEOF +for ac_lib in '' m; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_log=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if ${ac_cv_search_log+:} false; then : + break +fi +done +if ${ac_cv_search_log+:} false; then : + +else + ac_cv_search_log=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_log" >&5 +$as_echo "$ac_cv_search_log" >&6; } +ac_res=$ac_cv_search_log +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + +else + as_fn_error $? "log() not found + +HTSLIB requires a working floating-point math library. +FAILED. This error must be resolved in order to build HTSlib successfully." "$LINENO" 5 +fi + + zlib_devel=ok ac_fn_c_check_header_compile "$LINENO" "zlib.h" "ac_cv_header_zlib_h" "; " @@ -4014,7 +4425,6 @@ else zlib_devel=missing fi -LIBS=$save_LIBS if test $zlib_devel != ok; then as_fn_error $? "zlib development files not found @@ -4028,6 +4438,231 @@ is installed. FAILED. This error must be resolved in order to build HTSlib successfully." "$LINENO" 5 fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing recv" >&5 +$as_echo_n "checking for library containing recv... " >&6; } +if ${ac_cv_search_recv+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char recv (); +int +main () +{ +return recv (); + ; + return 0; +} +_ACEOF +for ac_lib in '' socket ws2_32; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_recv=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if ${ac_cv_search_recv+:} false; then : + break +fi +done +if ${ac_cv_search_recv+:} false; then : + +else + ac_cv_search_recv=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_recv" >&5 +$as_echo "$ac_cv_search_recv" >&6; } +ac_res=$ac_cv_search_recv +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + +if test "$ac_cv_search_recv" != "none required" +then + static_LIBS="$static_LIBS $ac_cv_search_recv" +fi +else + as_fn_error $? "unable to find the recv() function" "$LINENO" 5 +fi + + +if test "$enable_bz2" != no; then + bz2_devel=ok + ac_fn_c_check_header_compile "$LINENO" "bzlib.h" "ac_cv_header_bzlib_h" "; +" +if test "x$ac_cv_header_bzlib_h" = xyes; then : + +else + bz2_devel=missing +fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for BZ2_bzBuffToBuffCompress in -lbz2" >&5 +$as_echo_n "checking for BZ2_bzBuffToBuffCompress in -lbz2... " >&6; } +if ${ac_cv_lib_bz2_BZ2_bzBuffToBuffCompress+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lbz2 $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char BZ2_bzBuffToBuffCompress (); +int +main () +{ +return BZ2_bzBuffToBuffCompress (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_bz2_BZ2_bzBuffToBuffCompress=yes +else + ac_cv_lib_bz2_BZ2_bzBuffToBuffCompress=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bz2_BZ2_bzBuffToBuffCompress" >&5 +$as_echo "$ac_cv_lib_bz2_BZ2_bzBuffToBuffCompress" >&6; } +if test "x$ac_cv_lib_bz2_BZ2_bzBuffToBuffCompress" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBBZ2 1 +_ACEOF + + LIBS="-lbz2 $LIBS" + +else + bz2_devel=missing +fi + + if test $bz2_devel != ok; then + as_fn_error $? "libbzip2 development files not found + +The CRAM format may use bzip2 compression, which is implemented in HTSlib +by using compression routines from libbzip2 . + +Building HTSlib requires libbzip2 development files to be installed on the +build machine; you may need to ensure a package such as libbz2-dev (on Debian +or Ubuntu Linux) or bzip2-devel (on RPM-based Linux distributions or Cygwin) +is installed. + +Either configure with --disable-bz2 (which will make some CRAM files +produced elsewhere unreadable) or resolve this error to build HTSlib." "$LINENO" 5 + fi + if test -n "$PKG_CONFIG" && "$PKG_CONFIG" --exists bzip2; then + pc_requires="$pc_requires bzip2" + else + private_LIBS="$private_LIBS -lbz2" + fi + static_LIBS="$static_LIBS -lbz2" +fi + +if test "$enable_lzma" != no; then + lzma_devel=ok + for ac_header in lzma.h +do : + ac_fn_c_check_header_compile "$LINENO" "lzma.h" "ac_cv_header_lzma_h" "; +" +if test "x$ac_cv_header_lzma_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LZMA_H 1 +_ACEOF + +else + lzma_devel=header-missing +fi + +done + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for lzma_easy_buffer_encode in -llzma" >&5 +$as_echo_n "checking for lzma_easy_buffer_encode in -llzma... " >&6; } +if ${ac_cv_lib_lzma_lzma_easy_buffer_encode+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-llzma $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char lzma_easy_buffer_encode (); +int +main () +{ +return lzma_easy_buffer_encode (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_lzma_lzma_easy_buffer_encode=yes +else + ac_cv_lib_lzma_lzma_easy_buffer_encode=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lzma_lzma_easy_buffer_encode" >&5 +$as_echo "$ac_cv_lib_lzma_lzma_easy_buffer_encode" >&6; } +if test "x$ac_cv_lib_lzma_lzma_easy_buffer_encode" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBLZMA 1 +_ACEOF + + LIBS="-llzma $LIBS" + +else + lzma_devel=missing +fi + + if test $lzma_devel = missing; then + as_fn_error $? "liblzma development files not found + +The CRAM format may use LZMA2 compression, which is implemented in HTSlib +by using compression routines from liblzma . + +Building HTSlib requires liblzma development files to be installed on the +build machine; you may need to ensure a package such as liblzma-dev (on Debian +or Ubuntu Linux), xz-devel (on RPM-based Linux distributions or Cygwin), or +xz (via Homebrew on macOS) is installed; or build XZ Utils from source. + +Either configure with --disable-lzma (which will make some CRAM files +produced elsewhere unreadable) or resolve this error to build HTSlib." "$LINENO" 5 + fi + pc_requires="$pc_requires liblzma" + static_LIBS="$static_LIBS -llzma" +fi + libcurl=disabled if test "$enable_libcurl" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for curl_easy_pause in -lcurl" >&5 @@ -4131,10 +4766,53 @@ Either configure with --disable-libcurl or resolve this error to build HTSlib." esac fi - need_crypto=yes + if test "$libcurl" = enabled ; then + if test "$enable_plugins" != yes ; then + static_LIBS="$static_LIBS -lcurl" + fi + fi fi +gcs=disabled +if test "$enable_gcs" != no; then + if test $libcurl = enabled; then + +$as_echo "#define ENABLE_GCS 1" >>confdefs.h + + gcs=enabled + else + case "$enable_gcs" in + check) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: GCS support not enabled: requires libcurl support" >&5 +$as_echo "$as_me: WARNING: GCS support not enabled: requires libcurl support" >&2;} ;; + *) as_fn_error $? "GCS support not enabled + +Support for Google Cloud Storage URLs requires libcurl support to be enabled +in HTSlib. Configure with --enable-libcurl in order to use GCS URLs." "$LINENO" 5 + ;; + esac + fi +fi + + +s3=disabled +if test "$enable_s3" != no; then + if test $libcurl = enabled; then + s3=enabled + need_crypto="$enable_s3" + else + case "$enable_s3" in + check) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: S3 support not enabled: requires libcurl support" >&5 +$as_echo "$as_me: WARNING: S3 support not enabled: requires libcurl support" >&2;} ;; + *) as_fn_error $? "S3 support not enabled + +Support for Amazon AWS S3 URLs requires libcurl support to be enabled +in HTSlib. Configure with --enable-libcurl in order to use S3 URLs." "$LINENO" 5 + ;; + esac + fi +fi + CRYPTO_LIBS= if test $need_crypto != no; then ac_fn_c_check_func "$LINENO" "CCHmac" "ac_cv_func_CCHmac" @@ -4204,7 +4882,11 @@ $as_echo "#define HAVE_HMAC 1" >>confdefs.h -l*) CRYPTO_LIBS=$ac_cv_search_HMAC ;; esac else - as_fn_error $? "SSL development files not found + case "$need_crypto" in + check) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: S3 support not enabled: requires SSL development files" >&5 +$as_echo "$as_me: WARNING: S3 support not enabled: requires SSL development files" >&2;} + s3=disabled ;; + *) as_fn_error $? "SSL development files not found Support for AWS S3 URLs requires routines from an SSL library. Building HTSlib with libcurl enabled requires SSL development files to be installed @@ -4213,15 +4895,41 @@ libnss3-dev, or libssl-dev (on Debian or Ubuntu Linux, corresponding to the libcurl4-*-dev package installed), or openssl-devel (on RPM-based Linux distributions or Cygwin) is installed. -Either configure with --disable-libcurl or resolve this error to build HTSlib." "$LINENO" 5 +Either configure with --disable-s3 or resolve this error to build HTSlib." "$LINENO" 5 ;; + esac fi LIBS=$save_LIBS fi + if test "$enable_plugins" != yes ; then + static_LIBS="$static_LIBS $CRYPTO_LIBS" + fi +fi + +ac_fn_c_check_decl "$LINENO" "PTHREAD_MUTEX_RECURSIVE" "ac_cv_have_decl_PTHREAD_MUTEX_RECURSIVE" "#include +" +if test "x$ac_cv_have_decl_PTHREAD_MUTEX_RECURSIVE" = xyes; then : + +else + +$as_echo "#define _XOPEN_SOURCE 600" >>confdefs.h + fi +if test "$s3" = enabled ; then + +$as_echo "#define ENABLE_S3 1" >>confdefs.h + +fi + +if test "x$hts_late_cflags" != x; then : + CFLAGS="$CFLAGS $hts_late_cflags" +fi + + + openssl=enabled if test "$enable_openssl" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SSL_CTX_new in -lssl" >&5 @@ -4273,7 +4981,7 @@ fi fi -ac_config_files="$ac_config_files config.mk deps.mk" +ac_config_files="$ac_config_files config.mk htslib.pc.tmp:htslib.pc.in deps.mk" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -4682,16 +5390,16 @@ if (echo >conf$$.file) 2>/dev/null; then # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -4751,16 +5459,28 @@ else as_mkdir_p=false fi - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -4781,8 +5501,8 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by HTSlib $as_me 1.3.2, which was -generated by GNU Autoconf 2.69. Invocation command line was +This file was extended by HTSlib $as_me 1.7, which was +generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -4844,11 +5564,11 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -HTSlib config.status 1.3.2 -configured by $0, generated by GNU Autoconf 2.69, +HTSlib config.status 1.7 +configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2010 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -4936,7 +5656,7 @@ fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then - set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' @@ -4967,6 +5687,7 @@ do case $ac_config_target in "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; "config.mk") CONFIG_FILES="$CONFIG_FILES config.mk" ;; + "htslib.pc.tmp") CONFIG_FILES="$CONFIG_FILES htslib.pc.tmp:htslib.pc.in" ;; "deps.mk") CONFIG_FILES="$CONFIG_FILES deps.mk" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; diff --git a/htslib/configure.ac b/htslib/configure.ac index ad647c8c8..8e22012ef 100644 --- a/htslib/configure.ac +++ b/htslib/configure.ac @@ -1,6 +1,6 @@ # Configure script for htslib, a C library for high-throughput sequencing data. # -# Copyright (C) 2015-2016 Genome Research Ltd. +# Copyright (C) 2015-2017 Genome Research Ltd. # # Author: John Marshall # @@ -23,12 +23,14 @@ # DEALINGS IN THE SOFTWARE. dnl Process this file with autoconf to produce a configure script -AC_INIT([HTSlib], m4_esyscmd_s([make print-version]), +AC_INIT([HTSlib], m4_esyscmd_s([./version.sh 2>/dev/null]), [samtools-help@lists.sourceforge.net], [], [http://www.htslib.org/]) AC_PREREQ(2.63) dnl This version introduced 4-argument AC_CHECK_HEADER AC_CONFIG_SRCDIR(hts.c) AC_CONFIG_HEADERS(config.h) +m4_include([m4/hts_prog_cc_warnings.m4]) + dnl Copyright notice to be copied into the generated configure script AC_COPYRIGHT([Portions copyright (C) 2016 Genome Research Ltd. @@ -49,14 +51,45 @@ AH_TOP([/* If you use configure, this file provides @%:@defines reflecting your AC_PROG_CC AC_PROG_RANLIB -AC_SYS_LARGEFILE +dnl Turn on compiler warnings, if possible +HTS_PROG_CC_WARNINGS +dnl Flags to treat warnings as errors. These need to be applied to CFLAGS +dnl later as they can interfere with some of the tests (notably AC_SEARCH_LIBS) +HTS_PROG_CC_WERROR(hts_late_cflags) + +dnl Avoid chicken-and-egg problem where pkg-config supplies the +dnl PKG_PROG_PKG_CONFIG macro, but we want to use it to check +dnl for pkg-config... +m4_ifdef([PKG_PROG_PKG_CONFIG], [PKG_PROG_PKG_CONFIG], [PKG_CONFIG=""]) need_crypto=no +pc_requires= +static_LDFLAGS= +static_LIBS='-lz -lm' +private_LIBS= + +AC_ARG_ENABLE([bz2], + [AS_HELP_STRING([--disable-bz2], + [omit support for BZ2-compressed CRAM files])], + [], [enable_bz2=yes]) + +AC_ARG_ENABLE([gcs], + [AS_HELP_STRING([--enable-gcs], + [support Google Cloud Storage URLs])], + [], [enable_gcs=check]) + +AC_SYS_LARGEFILE +AC_FUNC_FSEEKO AC_ARG_ENABLE([libcurl], [AS_HELP_STRING([--enable-libcurl], [enable libcurl-based support for http/https/etc URLs])], - [], [enable_libcurl=no]) + [], [enable_libcurl=check]) + +AC_ARG_ENABLE([lzma], + [AS_HELP_STRING([--disable-lzma], + [omit support for LZMA-compressed CRAM files])], + [], [enable_lzma=yes]) AC_ARG_ENABLE([openssl], [AS_HELP_STRING([--enable-openssl], @@ -88,8 +121,13 @@ AC_ARG_WITH([plugin-path], [with_plugin_path=$with_plugin_dir]) AC_SUBST([pluginpath], $with_plugin_path) -AC_MSG_CHECKING([shared library type]) +AC_ARG_ENABLE([s3], + [AS_HELP_STRING([--enable-s3], + [support Amazon AWS S3 URLs])], + [], [enable_s3=check]) + test -n "$host_alias" || host_alias=unknown-`uname -s` +AC_MSG_CHECKING([shared library type for $host_alias]) case $host_alias in *-cygwin* | *-CYGWIN*) host_result="Cygwin DLL" @@ -101,6 +139,15 @@ case $host_alias in PLATFORM=Darwin PLUGIN_EXT=.bundle ;; + *-msys* | *-MSYS* | *-mingw* | *-MINGW*) + host_result="MSYS dll" + PLATFORM=MSYS + PLUGIN_EXT=.dll + # This also sets __USE_MINGW_ANSI_STDIO which in turn makes PRId64, + # %lld and %z printf formats work. It also enforces the snprintf to + # be C99 compliant so it returns the correct values (in kstring.c). + CPPFLAGS="$CPPCFLAGS -D_XOPEN_SOURCE=600" + ;; *) host_result="plain .so" PLATFORM=default @@ -112,7 +159,7 @@ AC_SUBST([PLATFORM]) dnl FIXME This pulls in dozens of standard header checks AC_FUNC_MMAP -AC_CHECK_FUNCS(gmtime_r) +AC_CHECK_FUNCS([gmtime_r fsync drand48]) # Darwin has a dubious fdatasync() symbol, but no declaration in AC_CHECK_DECL([fdatasync(int)], [AC_CHECK_FUNCS(fdatasync)]) @@ -125,18 +172,26 @@ Plugin support requires dynamic linking facilities from the operating system. Either configure with --disable-plugins or resolve this error to build HTSlib.])]) # TODO Test whether this is required and/or needs tweaking per-platform LDFLAGS="$LDFLAGS -rdynamic" + static_LDFLAGS="$static_LDFLAGS -rdynamic" + case "$ac_cv_search_dlopen" in + -l*) static_LIBS="$static_LIBS $ac_cv_search_dlopen" ;; + esac AC_DEFINE([ENABLE_PLUGINS], 1, [Define if HTSlib should enable plugins.]) AC_SUBST([PLUGIN_EXT]) AC_DEFINE_UNQUOTED([PLUGIN_EXT], ["$PLUGIN_EXT"], [Platform-dependent plugin filename extension.]) fi -save_LIBS=$LIBS +AC_SEARCH_LIBS([log], [m], [], + [AC_MSG_ERROR([log() not found + +HTSLIB requires a working floating-point math library. +FAILED. This error must be resolved in order to build HTSlib successfully.])]) + zlib_devel=ok dnl Set a trivial non-empty INCLUDES to avoid excess default includes tests AC_CHECK_HEADER([zlib.h], [], [zlib_devel=missing], [;]) AC_CHECK_LIB(z, inflate, [], [zlib_devel=missing]) -LIBS=$save_LIBS if test $zlib_devel != ok; then AC_MSG_ERROR([zlib development files not found @@ -150,6 +205,63 @@ is installed. FAILED. This error must be resolved in order to build HTSlib successfully.]) fi +dnl connect() etc. fns are in libc on linux, but libsocket on illumos/Solaris +AC_SEARCH_LIBS([recv], [socket ws2_32], [ +if test "$ac_cv_search_recv" != "none required" +then + static_LIBS="$static_LIBS $ac_cv_search_recv" +fi], [AC_MSG_ERROR([unable to find the recv() function])]) + +if test "$enable_bz2" != no; then + bz2_devel=ok + AC_CHECK_HEADER([bzlib.h], [], [bz2_devel=missing], [;]) + AC_CHECK_LIB([bz2], [BZ2_bzBuffToBuffCompress], [], [bz2_devel=missing]) + if test $bz2_devel != ok; then + AC_MSG_ERROR([libbzip2 development files not found + +The CRAM format may use bzip2 compression, which is implemented in HTSlib +by using compression routines from libbzip2 . + +Building HTSlib requires libbzip2 development files to be installed on the +build machine; you may need to ensure a package such as libbz2-dev (on Debian +or Ubuntu Linux) or bzip2-devel (on RPM-based Linux distributions or Cygwin) +is installed. + +Either configure with --disable-bz2 (which will make some CRAM files +produced elsewhere unreadable) or resolve this error to build HTSlib.]) + fi +dnl Unfortunately the 'bzip2' package-cfg module is not standard. +dnl Redhat/Fedora has it; Debian/Ubuntu does not. + if test -n "$PKG_CONFIG" && "$PKG_CONFIG" --exists bzip2; then + pc_requires="$pc_requires bzip2" + else + private_LIBS="$private_LIBS -lbz2" + fi + static_LIBS="$static_LIBS -lbz2" +fi + +if test "$enable_lzma" != no; then + lzma_devel=ok + AC_CHECK_HEADERS([lzma.h], [], [lzma_devel=header-missing], [;]) + AC_CHECK_LIB([lzma], [lzma_easy_buffer_encode], [], [lzma_devel=missing]) + if test $lzma_devel = missing; then + AC_MSG_ERROR([liblzma development files not found + +The CRAM format may use LZMA2 compression, which is implemented in HTSlib +by using compression routines from liblzma . + +Building HTSlib requires liblzma development files to be installed on the +build machine; you may need to ensure a package such as liblzma-dev (on Debian +or Ubuntu Linux), xz-devel (on RPM-based Linux distributions or Cygwin), or +xz (via Homebrew on macOS) is installed; or build XZ Utils from source. + +Either configure with --disable-lzma (which will make some CRAM files +produced elsewhere unreadable) or resolve this error to build HTSlib.]) + fi + pc_requires="$pc_requires liblzma" + static_LIBS="$static_LIBS -llzma" +fi + libcurl=disabled if test "$enable_libcurl" != no; then AC_CHECK_LIB([curl], [curl_easy_pause], @@ -172,10 +284,50 @@ or Cygwin) is installed. Either configure with --disable-libcurl or resolve this error to build HTSlib.]) ;; esac]) - need_crypto=yes +dnl -lcurl is only needed for static linking if hfile_libcurl is not a plugin + if test "$libcurl" = enabled ; then + if test "$enable_plugins" != yes ; then + static_LIBS="$static_LIBS -lcurl" + fi + fi fi AC_SUBST([libcurl]) +gcs=disabled +if test "$enable_gcs" != no; then + if test $libcurl = enabled; then + AC_DEFINE([ENABLE_GCS], 1, [Define if HTSlib should enable GCS support.]) + gcs=enabled + else + case "$enable_gcs" in + check) AC_MSG_WARN([GCS support not enabled: requires libcurl support]) ;; + *) AC_MSG_ERROR([GCS support not enabled + +Support for Google Cloud Storage URLs requires libcurl support to be enabled +in HTSlib. Configure with --enable-libcurl in order to use GCS URLs.]) + ;; + esac + fi +fi +AC_SUBST([gcs]) + +s3=disabled +if test "$enable_s3" != no; then + if test $libcurl = enabled; then + s3=enabled + need_crypto="$enable_s3" + else + case "$enable_s3" in + check) AC_MSG_WARN([S3 support not enabled: requires libcurl support]) ;; + *) AC_MSG_ERROR([S3 support not enabled + +Support for Amazon AWS S3 URLs requires libcurl support to be enabled +in HTSlib. Configure with --enable-libcurl in order to use S3 URLs.]) + ;; + esac + fi +fi + CRYPTO_LIBS= if test $need_crypto != no; then AC_CHECK_FUNC([CCHmac], @@ -187,7 +339,10 @@ if test $need_crypto != no; then case "$ac_cv_search_HMAC" in -l*) CRYPTO_LIBS=$ac_cv_search_HMAC ;; esac], - [AC_MSG_ERROR([SSL development files not found + [case "$need_crypto" in + check) AC_MSG_WARN([S3 support not enabled: requires SSL development files]) + s3=disabled ;; + *) AC_MSG_ERROR([SSL development files not found Support for AWS S3 URLs requires routines from an SSL library. Building HTSlib with libcurl enabled requires SSL development files to be installed @@ -196,11 +351,35 @@ libnss3-dev, or libssl-dev (on Debian or Ubuntu Linux, corresponding to the libcurl4-*-dev package installed), or openssl-devel (on RPM-based Linux distributions or Cygwin) is installed. -Either configure with --disable-libcurl or resolve this error to build HTSlib.])]) +Either configure with --disable-s3 or resolve this error to build HTSlib.]) ;; + esac]) LIBS=$save_LIBS]) +dnl Only need to add to static_LIBS if not building as a plugin + if test "$enable_plugins" != yes ; then + static_LIBS="$static_LIBS $CRYPTO_LIBS" + fi fi + +dnl Look for PTHREAD_MUTEX_RECURSIVE. +dnl This is normally in pthread.h except on some broken glibc implementations. +AC_CHECK_DECL(PTHREAD_MUTEX_RECURSIVE, [], [AC_DEFINE([_XOPEN_SOURCE],[600], [Needed for PTHREAD_MUTEX_RECURSIVE])], [[#include ]]) + +if test "$s3" = enabled ; then + AC_DEFINE([ENABLE_S3], 1, [Define if HTSlib should enable S3 support.]) +fi + +dnl Apply value from HTS_PROG_CC_WERROR (if set) +AS_IF([test "x$hts_late_cflags" != x],[CFLAGS="$CFLAGS $hts_late_cflags"]) + +AC_SUBST([s3]) AC_SUBST([CRYPTO_LIBS]) +AC_SUBST([pc_requires]) +AC_SUBST([private_LIBS]) +AC_SUBST([static_LDFLAGS]) +AC_SUBST([static_LIBS]) + +AC_CONFIG_FILES([config.mk htslib.pc.tmp:htslib.pc.in]) openssl=enabled if test "$enable_openssl" != no; then AC_CHECK_LIB([ssl], [SSL_library_init], diff --git a/htslib/cram/cram_codecs.c b/htslib/cram/cram_codecs.c index 0e073c63e..76fa73171 100644 --- a/htslib/cram/cram_codecs.c +++ b/htslib/cram/cram_codecs.c @@ -39,6 +39,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include #include "cram/cram.h" @@ -237,7 +239,7 @@ static inline unsigned int get_bits_MSB(cram_block *block, int nbits) { * for it elsewhere.) */ static int store_bits_MSB(cram_block *block, unsigned int val, int nbits) { - /* fprintf(stderr, " store_bits: %02x %d\n", val, nbits); */ + //fprintf(stderr, " store_bits: %02x %d\n", val, nbits); /* * Use slow mode until we tweak the huffman generator to never generate @@ -309,6 +311,10 @@ static char *cram_extract_block(cram_block *b, int size) { * --------------------------------------------------------------------------- * EXTERNAL */ +static void cram_external_decode_reset(cram_codec *c) { + c->external.b = NULL; +} + int cram_external_decode_int(cram_slice *slice, cram_codec *c, cram_block *in, char *out, int *out_size) { int l; @@ -316,7 +322,10 @@ int cram_external_decode_int(cram_slice *slice, cram_codec *c, cram_block *b; /* Find the external block */ - b = cram_get_block_by_id(slice, c->external.content_id); + if (!(b = c->external.b)){ + b = cram_get_block_by_id(slice, c->external.content_id); + c->external.b = b; + } if (!b) return *out_size?-1:0; @@ -336,7 +345,10 @@ int cram_external_decode_char(cram_slice *slice, cram_codec *c, cram_block *b; /* Find the external block */ - b = cram_get_block_by_id(slice, c->external.content_id); + if (!(b = c->external.b)){ + b = cram_get_block_by_id(slice, c->external.content_id); + c->external.b = b; + } if (!b) return *out_size?-1:0; @@ -353,11 +365,14 @@ static int cram_external_decode_block(cram_slice *slice, cram_codec *c, cram_block *in, char *out_, int *out_size) { char *cp; - cram_block *b = NULL; cram_block *out = (cram_block *)out_; + cram_block *b = NULL; /* Find the external block */ - b = cram_get_block_by_id(slice, c->external.content_id); + if (!(b = c->external.b)){ + b = cram_get_block_by_id(slice, c->external.content_id); + c->external.b = b; + } if (!b) return *out_size?-1:0; @@ -377,9 +392,12 @@ void cram_external_decode_free(cram_codec *c) { cram_codec *cram_external_decode_init(char *data, int size, enum cram_external_type option, int version) { - cram_codec *c; + cram_codec *c = NULL; char *cp = data; + if (size < 1) + goto malformed; + if (!(c = malloc(sizeof(*c)))) return NULL; @@ -392,17 +410,21 @@ cram_codec *cram_external_decode_init(char *data, int size, c->decode = cram_external_decode_block; c->free = cram_external_decode_free; - cp += itf8_get(cp, &c->external.content_id); + cp += safe_itf8_get(cp, data + size, &c->external.content_id); - if (cp - data != size) { - fprintf(stderr, "Malformed external header stream\n"); - free(c); - return NULL; - } + if (cp - data != size) + goto malformed; c->external.type = option; + c->external.b = NULL; + c->reset = cram_external_decode_reset; return c; + + malformed: + hts_log_error("Malformed external header stream"); + free(c); + return NULL; } int cram_external_encode_int(cram_slice *slice, cram_codec *c, @@ -473,18 +495,20 @@ cram_codec *cram_external_encode_init(cram_stats *st, * --------------------------------------------------------------------------- * BETA */ +void cram_nop_decode_reset(cram_codec *c) {} + int cram_beta_decode_int(cram_slice *slice, cram_codec *c, cram_block *in, char *out, int *out_size) { int32_t *out_i = (int32_t *)out; - int i, n; + int i, n = *out_size; if (c->beta.nbits) { - if (cram_not_enough_bits(in, c->beta.nbits)) + if (cram_not_enough_bits(in, c->beta.nbits * n)) return -1; - for (i = 0, n = *out_size; i < n; i++) + for (i = 0; i < n; i++) out_i[i] = get_bits_MSB(in, c->beta.nbits) - c->beta.offset; } else { - for (i = 0, n = *out_size; i < n; i++) + for (i = 0; i < n; i++) out_i[i] = -c->beta.offset; } @@ -492,22 +516,22 @@ int cram_beta_decode_int(cram_slice *slice, cram_codec *c, cram_block *in, char } int cram_beta_decode_char(cram_slice *slice, cram_codec *c, cram_block *in, char *out, int *out_size) { - int i, n; + int i, n = *out_size; if (c->beta.nbits) { - if (cram_not_enough_bits(in, c->beta.nbits)) + if (cram_not_enough_bits(in, c->beta.nbits * n)) return -1; if (out) - for (i = 0, n = *out_size; i < n; i++) + for (i = 0; i < n; i++) out[i] = get_bits_MSB(in, c->beta.nbits) - c->beta.offset; else - for (i = 0, n = *out_size; i < n; i++) + for (i = 0; i < n; i++) get_bits_MSB(in, c->beta.nbits); } else { if (out) - for (i = 0, n = *out_size; i < n; i++) + for (i = 0; i < n; i++) out[i] = -c->beta.offset; } @@ -533,20 +557,26 @@ cram_codec *cram_beta_decode_init(char *data, int size, c->decode = cram_beta_decode_int; else if (option == E_BYTE_ARRAY || option == E_BYTE) c->decode = cram_beta_decode_char; - else - abort(); + else { + hts_log_error("BYTE_ARRAYs not supported by this codec"); + return NULL; + } c->free = cram_beta_decode_free; - cp += itf8_get(cp, &c->beta.offset); - cp += itf8_get(cp, &c->beta.nbits); + c->beta.nbits = -1; + cp += safe_itf8_get(cp, data + size, &c->beta.offset); + if (cp < data + size) // Ensure test below works + cp += safe_itf8_get(cp, data + size, &c->beta.nbits); if (cp - data != size || c->beta.nbits < 0 || c->beta.nbits > 8 * sizeof(int)) { - fprintf(stderr, "Malformed beta header stream\n"); - free(c); - return NULL; + hts_log_error("Malformed beta header stream"); + free(c); + return NULL; } + c->reset = cram_nop_decode_reset; + return c; } @@ -603,6 +633,7 @@ cram_codec *cram_beta_encode_init(cram_stats *st, int version) { cram_codec *c; int min_val, max_val, len = 0; + int64_t range; c = malloc(sizeof(*c)); if (!c) @@ -647,10 +678,10 @@ cram_codec *cram_beta_encode_init(cram_stats *st, assert(max_val >= min_val); c->e_beta.offset = -min_val; - max_val -= min_val; - while (max_val) { + range = (int64_t) max_val - min_val; + while (range) { len++; - max_val >>= 1; + range >>= 1; } c->e_beta.nbits = len; @@ -716,6 +747,11 @@ cram_codec *cram_subexp_decode_init(char *data, int size, cram_codec *c; char *cp = data; + if (option != E_INT) { + hts_log_error("This codec only supports INT encodings"); + return NULL; + } + if (!(c = malloc(sizeof(*c)))) return NULL; @@ -728,11 +764,13 @@ cram_codec *cram_subexp_decode_init(char *data, int size, cp += safe_itf8_get(cp, data + size, &c->subexp.k); if (cp - data != size || c->subexp.k < 0) { - fprintf(stderr, "Malformed subexp header stream\n"); + hts_log_error("Malformed subexp header stream"); free(c); return NULL; } + c->reset = cram_nop_decode_reset; + return c; } @@ -772,9 +810,17 @@ void cram_gamma_decode_free(cram_codec *c) { cram_codec *cram_gamma_decode_init(char *data, int size, enum cram_external_type option, int version) { - cram_codec *c; + cram_codec *c = NULL; char *cp = data; + if (option != E_INT) { + hts_log_error("This codec only supports INT encodings"); + return NULL; + } + + if (size < 1) + goto malformed; + if (!(c = malloc(sizeof(*c)))) return NULL; @@ -782,15 +828,19 @@ cram_codec *cram_gamma_decode_init(char *data, int size, c->decode = cram_gamma_decode; c->free = cram_gamma_decode_free; - cp += itf8_get(cp, &c->gamma.offset); + cp += safe_itf8_get(cp, data + size, &c->gamma.offset); - if (cp - data != size) { - fprintf(stderr, "Malformed gamma header stream\n"); - free(c); - return NULL; - } + if (cp - data != size) + goto malformed; + + c->reset = cram_nop_decode_reset; return c; + + malformed: + hts_log_error("Malformed gamma header stream"); + free(c); + return NULL; } /* @@ -805,7 +855,7 @@ static int code_sort(const void *vp1, const void *vp2) { if (c1->len != c2->len) return c1->len - c2->len; else - return c1->symbol - c2->symbol; + return c1->symbol < c2->symbol ? -1 : (c1->symbol > c2->symbol ? 1 : 0); } void cram_huffman_decode_free(cram_codec *c) { @@ -862,7 +912,7 @@ int cram_huffman_decode_char(cram_slice *slice, cram_codec *c, return -1; if (codes[idx].code == val && codes[idx].len == len) { - out[i] = codes[idx].symbol; + if (out) out[i] = codes[idx].symbol; break; } } @@ -930,11 +980,27 @@ cram_codec *cram_huffman_decode_init(char *data, int size, int32_t ncodes = 0, i, j; char *cp = data, *data_end = &data[size]; cram_codec *h; - cram_huffman_code *codes; + cram_huffman_code *codes = NULL; int32_t val, last_len, max_len = 0; + uint32_t max_val; // needs one more bit than val + const int max_code_bits = sizeof(val) * 8 - 1; int l; + if (option == E_BYTE_ARRAY_BLOCK) { + hts_log_error("BYTE_ARRAYs not supported by this codec"); + return NULL; + } + cp += safe_itf8_get(cp, data_end, &ncodes); + if (ncodes < 0) { + hts_log_error("Invalid number of symbols in huffman stream"); + return NULL; + } + if (ncodes >= SIZE_MAX / sizeof(*codes)) { + errno = ENOMEM; + return NULL; + } + h = calloc(1, sizeof(*h)); if (!h) return NULL; @@ -943,10 +1009,14 @@ cram_codec *cram_huffman_decode_init(char *data, int size, h->free = cram_huffman_decode_free; h->huffman.ncodes = ncodes; - codes = h->huffman.codes = malloc(ncodes * sizeof(*codes)); - if (!codes) { - free(h); - return NULL; + if (ncodes) { + codes = h->huffman.codes = malloc(ncodes * sizeof(*codes)); + if (!codes) { + free(h); + return NULL; + } + } else { + codes = h->huffman.codes = NULL; } /* Read symbols and bit-lengths */ @@ -954,17 +1024,14 @@ cram_codec *cram_huffman_decode_init(char *data, int size, l = safe_itf8_get(cp, data_end, &codes[i].symbol); } - if (l < 1) { - fprintf(stderr, "Malformed huffman header stream\n"); - free(h); - return NULL; - } + if (l < 1) + goto malformed; + cp += safe_itf8_get(cp, data_end, &i); - if (i != ncodes) { - fprintf(stderr, "Malformed huffman header stream\n"); - free(h); - return NULL; - } + if (i != ncodes) + goto malformed; + + h->reset = cram_nop_decode_reset; if (ncodes == 0) { /* NULL huffman stream. Ensure it returns an error if @@ -980,24 +1047,32 @@ cram_codec *cram_huffman_decode_init(char *data, int size, if (max_len < codes[i].len) max_len = codes[i].len; } - if (l < 1 || cp - data != size || max_len >= ncodes) { - fprintf(stderr, "Malformed huffman header stream\n"); - free(h); - return NULL; + if (l < 1 || cp - data != size || max_len >= ncodes) + goto malformed; + + /* 31 is max. bits available in val */ + if (max_len > max_code_bits) { + hts_log_error("Huffman code length (%d) is greater " + "than maximum supported (%d)", max_len, max_code_bits); + free(h); + free(codes); + return NULL; } /* Sort by bit length and then by symbol value */ qsort(codes, ncodes, sizeof(*codes), code_sort); /* Assign canonical codes */ - val = -1, last_len = 0; + val = -1, last_len = 0, max_val = 0; for (i = 0; i < ncodes; i++) { val++; + if (val > max_val) + goto malformed; + if (codes[i].len > last_len) { - while (codes[i].len > last_len) { - val <<= 1; - last_len++; - } + val <<= (codes[i].len - last_len); + last_len = codes[i].len; + max_val = (1U << codes[i].len) - 1; } codes[i].code = val; } @@ -1046,6 +1121,12 @@ cram_codec *cram_huffman_decode_init(char *data, int size, } return (cram_codec *)h; + + malformed: + hts_log_error("Malformed huffman header stream"); + free(codes); + free(h); + return NULL; } int cram_huffman_encode_char0(cram_slice *slice, cram_codec *c, @@ -1391,6 +1472,11 @@ void cram_byte_array_len_decode_free(cram_codec *c) { free(c); } +static void cram_byte_array_len_decode_reset(cram_codec *c) { + c->byte_array_len.len_codec->reset(c->byte_array_len.len_codec); + c->byte_array_len.val_codec->reset(c->byte_array_len.val_codec); +} + cram_codec *cram_byte_array_len_decode_init(char *data, int size, enum cram_external_type option, int version) { @@ -1431,10 +1517,12 @@ cram_codec *cram_byte_array_len_decode_init(char *data, int size, if (cp - data != size) goto malformed; + c->reset = cram_byte_array_len_decode_reset; + return c; malformed: - fprintf(stderr, "Malformed byte_array_len header stream\n"); + hts_log_error("Malformed byte_array_len header stream"); no_codec: free(c); return NULL; @@ -1514,7 +1602,7 @@ cram_codec *cram_byte_array_len_encode_init(cram_stats *st, c->store = cram_byte_array_len_encode_store; c->e_byte_array_len.len_codec = cram_encoder_init(e->len_encoding, - NULL, E_INT, + st, E_INT, e->len_dat, version); c->e_byte_array_len.val_codec = cram_encoder_init(e->val_encoding, @@ -1529,13 +1617,20 @@ cram_codec *cram_byte_array_len_encode_init(cram_stats *st, * --------------------------------------------------------------------------- * BYTE_ARRAY_STOP */ +static void cram_byte_array_stop_decode_reset(cram_codec *c) { + c->byte_array_stop.b = NULL; +} + static int cram_byte_array_stop_decode_char(cram_slice *slice, cram_codec *c, cram_block *in, char *out, int *out_size) { - cram_block *b = NULL; char *cp, ch; + cram_block *b = NULL; - b = cram_get_block_by_id(slice, c->byte_array_stop.content_id); + if (!(b = c->byte_array_stop.b)){ + b = cram_get_block_by_id(slice, c->byte_array_stop.content_id); + c->byte_array_stop.b = b; + } if (!b) return *out_size?-1:0; @@ -1573,7 +1668,10 @@ int cram_byte_array_stop_decode_block(cram_slice *slice, cram_codec *c, char *cp, *out_cp, *cp_end; char stop; - b = cram_get_block_by_id(slice, c->byte_array_stop.content_id); + if (!(b = c->byte_array_stop.b)){ + b = cram_get_block_by_id(slice, c->byte_array_stop.content_id); + c->byte_array_stop.b = b; + } if (!b) return *out_size?-1:0; @@ -1611,9 +1709,12 @@ void cram_byte_array_stop_decode_free(cram_codec *c) { cram_codec *cram_byte_array_stop_decode_init(char *data, int size, enum cram_external_type option, int version) { - cram_codec *c; + cram_codec *c = NULL; unsigned char *cp = (unsigned char *)data; + if (size < (CRAM_MAJOR_VERS(version) == 1 ? 5 : 2)) + goto malformed; + if (!(c = malloc(sizeof(*c)))) return NULL; @@ -1626,7 +1727,7 @@ cram_codec *cram_byte_array_stop_decode_init(char *data, int size, c->decode = cram_byte_array_stop_decode_char; break; default: - fprintf(stderr, "byte_array_stop codec only supports BYTE_ARRAYs.\n"); + hts_log_error("The byte_array_stop codec only supports BYTE_ARRAYs"); free(c); return NULL; } @@ -1638,16 +1739,22 @@ cram_codec *cram_byte_array_stop_decode_init(char *data, int size, + (cp[3]<<24); cp += 4; } else { - cp += itf8_get(cp, &c->byte_array_stop.content_id); + cp += safe_itf8_get((char *) cp, data + size, + &c->byte_array_stop.content_id); } - if ((char *)cp - data != size) { - fprintf(stderr, "Malformed byte_array_stop header stream\n"); - free(c); - return NULL; - } + if ((char *)cp - data != size) + goto malformed; + + c->byte_array_stop.b = NULL; + c->reset = cram_byte_array_stop_decode_reset; return c; + + malformed: + hts_log_error("Malformed byte_array_stop header stream"); + free(c); + return NULL; } int cram_byte_array_stop_encode(cram_slice *slice, cram_codec *c, @@ -1759,7 +1866,7 @@ cram_codec *cram_decoder_init(enum cram_encoding codec, if (codec >= E_NULL && codec < E_NUM_CODECS && decode_init[codec]) { return decode_init[codec](data, size, option, version); } else { - fprintf(stderr, "Unimplemented codec of type %s\n", cram_encoding2str(codec)); + hts_log_error("Unimplemented codec of type %s", cram_encoding2str(codec)); return NULL; } } @@ -1794,7 +1901,7 @@ cram_codec *cram_encoder_init(enum cram_encoding codec, r->out = NULL; return r; } else { - fprintf(stderr, "Unimplemented codec of type %s\n", cram_encoding2str(codec)); + hts_log_error("Unimplemented codec of type %s", cram_encoding2str(codec)); abort(); } } @@ -1832,7 +1939,7 @@ int cram_codec_to_id(cram_codec *c, int *id2) { bnum1 = -2; break; default: - fprintf(stderr, "Unknown codec type %d\n", c->codec); + hts_log_error("Unknown codec type %d", c->codec); bnum1 = -1; } diff --git a/htslib/cram/cram_codecs.h b/htslib/cram/cram_codecs.h index 2c13c7e1c..650dfc5e8 100644 --- a/htslib/cram/cram_codecs.h +++ b/htslib/cram/cram_codecs.h @@ -84,6 +84,7 @@ typedef struct { typedef struct { int32_t content_id; enum cram_external_type type; + cram_block *b; } cram_external_decoder; typedef struct { @@ -94,6 +95,7 @@ typedef struct { typedef struct { unsigned char stop; int32_t content_id; + cram_block *b; } cram_byte_array_stop_decoder; typedef struct { @@ -118,6 +120,8 @@ typedef struct cram_codec { char *in, int in_size); int (*store)(struct cram_codec *codec, cram_block *b, char *prefix, int version); + void (*reset)(struct cram_codec *codec); // used between slices in a container + union { cram_huffman_decoder huffman; cram_external_decoder external; diff --git a/htslib/cram/cram_decode.c b/htslib/cram/cram_decode.c index 4974d74de..978483732 100644 --- a/htslib/cram/cram_decode.c +++ b/htslib/cram/cram_decode.c @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "cram/cram.h" #include "cram/os.h" @@ -151,6 +152,11 @@ cram_block_compression_hdr *cram_decode_compression_header(cram_fd *fd, cp += safe_itf8_get(cp, endp, &hdr->ref_seq_span); cp += safe_itf8_get(cp, endp, &hdr->num_records); cp += safe_itf8_get(cp, endp, &hdr->num_landmarks); + if ((hdr->num_landmarks < 0 || + hdr->num_landmarks >= SIZE_MAX / sizeof(int32_t))) { + free(hdr); + return NULL; + } if (!(hdr->landmark = malloc(hdr->num_landmarks * sizeof(int32_t)))) { free(hdr); return NULL; @@ -189,7 +195,7 @@ cram_block_compression_hdr *cram_decode_compression_header(cram_fd *fd, khint_t k; int r; - if (endp - cp < 2) { + if (endp - cp < 3) { cram_free_compression_header(hdr); return NULL; } @@ -328,8 +334,7 @@ cram_block_compression_hdr *cram_decode_compression_header(cram_fd *fd, } default: - fprintf(stderr, "Unrecognised preservation map key %c%c\n", - cp[-2], cp[-1]); + hts_log_warning("Unrecognised preservation map key %c%c", cp[-2], cp[-1]); // guess byte; cp++; break; @@ -599,8 +604,9 @@ cram_block_compression_hdr *cram_decode_compression_header(cram_fd *fd, } } else if (key[0] == 'T' && key[1] == 'M') { } else if (key[0] == 'T' && key[1] == 'V') { - } else - fprintf(stderr, "Unrecognised key: %.2s\n", key); + } else { + hts_log_warning("Unrecognised key: %.2s", key); + } cp += size; @@ -842,8 +848,10 @@ int cram_dependent_data_series(cram_fd *fd, while (m) { cram_codec *c = m->codec; - if (!c) + if (!c) { + m = m->next; continue; + } bnum1 = cram_codec_to_id(c, &bnum2); @@ -931,8 +939,10 @@ int cram_dependent_data_series(cram_fd *fd, while (m) { cram_codec *c = m->codec; - if (!c) + if (!c) { + m = m->next; continue; + } bnum1 = cram_codec_to_id(c, &bnum2); @@ -948,7 +958,7 @@ int cram_dependent_data_series(cram_fd *fd, default: for (j = 0; j < s->hdr->num_blocks; j++) { - if (s->block[j]->content_type && + if (s->block[j]->content_type == EXTERNAL && s->block[j]->content_id == bnum1) { if (block_used[j]) { //printf(" + data series %08x:\n", @@ -1027,6 +1037,7 @@ void cram_decode_estimate_sizes(cram_block_compression_hdr *hdr, cram_slice *s, /* Qual */ cd = hdr->codecs[DS_QS]; + if (cd == NULL) return; bnum1 = cram_codec_to_id(cd, &bnum2); if (bnum1 < 0 && bnum2 >= 0) bnum1 = bnum2; if (cram_ds_unique(hdr, cd, bnum1)) { @@ -1038,6 +1049,7 @@ void cram_decode_estimate_sizes(cram_block_compression_hdr *hdr, cram_slice *s, /* Name */ cd = hdr->codecs[DS_RN]; + if (cd == NULL) return; bnum1 = cram_codec_to_id(cd, &bnum2); if (bnum1 < 0 && bnum2 >= 0) bnum1 = bnum2; if (cram_ds_unique(hdr, cd, bnum1)) { @@ -1058,8 +1070,8 @@ void cram_decode_estimate_sizes(cram_block_compression_hdr *hdr, cram_slice *s, */ cram_block_slice_hdr *cram_decode_slice_header(cram_fd *fd, cram_block *b) { cram_block_slice_hdr *hdr; - char *cp; - char *cp_end; + unsigned char *cp; + unsigned char *cp_end; int i; if (b->method != RAW) { @@ -1068,7 +1080,7 @@ cram_block_slice_hdr *cram_decode_slice_header(cram_fd *fd, cram_block *b) { if (cram_uncompress_block(b) < 0) return NULL; } - cp = (char *)b->data; + cp = (unsigned char *)BLOCK_DATA(b); cp_end = cp + b->uncomp_size; if (b->content_type != MAPPED_SLICE && @@ -1081,23 +1093,23 @@ cram_block_slice_hdr *cram_decode_slice_header(cram_fd *fd, cram_block *b) { hdr->content_type = b->content_type; if (b->content_type == MAPPED_SLICE) { - cp += safe_itf8_get(cp, cp_end, &hdr->ref_seq_id); - cp += safe_itf8_get(cp, cp_end, &hdr->ref_seq_start); - cp += safe_itf8_get(cp, cp_end, &hdr->ref_seq_span); + cp += safe_itf8_get((char *)cp, (char *)cp_end, &hdr->ref_seq_id); + cp += safe_itf8_get((char *)cp, (char *)cp_end, &hdr->ref_seq_start); + cp += safe_itf8_get((char *)cp, (char *)cp_end, &hdr->ref_seq_span); } - cp += safe_itf8_get(cp, cp_end, &hdr->num_records); + cp += safe_itf8_get((char *)cp, (char *)cp_end, &hdr->num_records); hdr->record_counter = 0; if (CRAM_MAJOR_VERS(fd->version) == 2) { int32_t i32 = 0; - cp += safe_itf8_get(cp, cp_end, &i32); + cp += safe_itf8_get((char *)cp, (char *)cp_end, &i32); hdr->record_counter = i32; } else if (CRAM_MAJOR_VERS(fd->version) >= 3) { - cp += ltf8_get(cp, &hdr->record_counter); + cp += safe_ltf8_get((char *)cp, (char *)cp_end, &hdr->record_counter); } - cp += safe_itf8_get(cp, cp_end, &hdr->num_blocks); + cp += safe_itf8_get((char *)cp, (char *)cp_end, &hdr->num_blocks); - cp += safe_itf8_get(cp, cp_end, &hdr->num_content_ids); + cp += safe_itf8_get((char *)cp, (char *)cp_end, &hdr->num_content_ids); if (hdr->num_content_ids < 1 || hdr->num_content_ids >= SIZE_MAX / sizeof(int32_t)) { /* Slice must have at least one data block, @@ -1112,7 +1124,7 @@ cram_block_slice_hdr *cram_decode_slice_header(cram_fd *fd, cram_block *b) { } for (i = 0; i < hdr->num_content_ids; i++) { - int l = safe_itf8_get(cp, cp_end, + int l = safe_itf8_get((char *)cp, (char *)cp_end, &hdr->block_content_ids[i]); if (l <= 0) { free(hdr->block_content_ids); @@ -1123,7 +1135,7 @@ cram_block_slice_hdr *cram_decode_slice_header(cram_fd *fd, cram_block *b) { } if (b->content_type == MAPPED_SLICE) { - cp += safe_itf8_get(cp, cp_end, &hdr->ref_base_id); + cp += safe_itf8_get((char *)cp, (char *) cp_end, &hdr->ref_base_id); } if (CRAM_MAJOR_VERS(fd->version) != 1) { @@ -1199,8 +1211,8 @@ static int cram_decode_seq(cram_fd *fd, cram_container *c, cram_slice *s, uint32_t nm = 0; int32_t md_dist = 0; int orig_aux = 0; - int decode_md = fd->decode_md && s->ref && !has_MD; - int decode_nm = fd->decode_md && s->ref && !has_NM; + int decode_md = fd->decode_md && s->ref && !has_MD && cr->ref_id >= 0; + int decode_nm = fd->decode_md && s->ref && !has_NM && cr->ref_id >= 0; uint32_t ds = c->comp_hdr->data_series; if ((ds & CRAM_QS) && !(cf & CRAM_FLAG_PRESERVE_QUAL_SCORES)) { @@ -1262,8 +1274,7 @@ static int cram_decode_seq(cram_fd *fd, cram_container *c, cram_slice *s, pos += prev_pos; if (pos <= 0) { - fprintf(stderr, "Error: feature position %d before start of read.\n", - pos); + hts_log_error("Feature position %d before start of read", pos); return -1; } @@ -1276,8 +1287,7 @@ static int cram_decode_seq(cram_fd *fd, cram_container *c, cram_slice *s, static int whinged = 0; int rlen; if (!whinged) - fprintf(stderr, "Ref pos outside of ref " - "sequence boundary\n"); + hts_log_warning("Ref pos outside of ref sequence boundary"); whinged = 1; rlen = bfd->ref[cr->ref_id].len - ref_pos; // May miss MD/NM cases where both seq/ref are N, but this is a @@ -1339,9 +1349,6 @@ static int cram_decode_seq(cram_fd *fd, cram_container *c, cram_slice *s, if (!(ds & CRAM_FC)) goto skip_cigar; - if (!(ds & CRAM_FC)) - continue; - switch(op) { case 'S': { // soft clip: IN int32_t out_sz2 = 1; @@ -1422,7 +1429,7 @@ static int cram_decode_seq(cram_fd *fd, cram_container *c, cram_slice *s, ->decode(s, c->comp_hdr->codecs[DS_BS], blk, (char *)&base, &out_sz); if (r) return -1; - if (ref_pos >= bfd->ref[cr->ref_id].len || !s->ref) { + if (cr->ref_id < 0 || ref_pos >= bfd->ref[cr->ref_id].len || !s->ref) { if (pos-1 < cr->len) seq[pos-1] = c->comp_hdr-> substitution_matrix[fd->L1['N']][base]; @@ -1734,7 +1741,7 @@ static int cram_decode_seq(cram_fd *fd, cram_container *c, cram_slice *s, } default: - fprintf(stderr, "Error: Unknown feature code '%c'\n", op); + hts_log_error("Unknown feature code '%c'", op); return -1; } } @@ -1744,12 +1751,12 @@ static int cram_decode_seq(cram_fd *fd, cram_container *c, cram_slice *s, /* An implicit match op for any unaccounted for bases */ if ((ds & CRAM_FN) && cr->len >= seq_pos) { - if (s->ref) { + if (s->ref && cr->ref_id >= 0) { if (ref_pos + cr->len - seq_pos + 1 > bfd->ref[cr->ref_id].len) { static int whinged = 0; int rlen; if (!whinged) - fprintf(stderr, "Ref pos outside of ref sequence boundary\n"); + hts_log_warning("Ref pos outside of ref sequence boundary"); whinged = 1; rlen = bfd->ref[cr->ref_id].len - ref_pos; // May miss MD/NM cases where both seq/ref are N, but this is a @@ -1791,6 +1798,9 @@ static int cram_decode_seq(cram_fd *fd, cram_container *c, cram_slice *s, } ref_pos += cr->len - seq_pos + 1; } + } else if (cr->ref_id >= 0) { + // So alignment end can be computed even when not decoding sequence + ref_pos += cr->len - seq_pos + 1; } if (ncigar+1 >= cigar_alloc) { @@ -1943,7 +1953,7 @@ static int cram_decode_aux_1_0(cram_container *c, cram_slice *s, cr->aux_size += out_sz + 3; } - + return r; } @@ -1954,7 +1964,7 @@ static int cram_decode_aux(cram_container *c, cram_slice *s, int32_t TL = 0; unsigned char *TN; uint32_t ds = c->comp_hdr->data_series; - + if (!(ds & (CRAM_TL|CRAM_aux))) { cr->aux = 0; cr->aux_size = 0; @@ -2133,7 +2143,7 @@ static int cram_decode_slice_xref(cram_slice *s, int required_fields) { if (s->crecs[cr->mate_line].flags & BAM_FREVERSE) cr->flags |= BAM_FMREVERSE; } else { - fprintf(stderr, "Mate line out of bounds: %d vs [0, %d]\n", + hts_log_error("Mate line out of bounds: %d vs [0, %d]", cr->mate_line, s->hdr->num_records-1); } @@ -2167,6 +2177,27 @@ static char *md5_print(unsigned char *md5, char *out) { return out; } +static void reset_all_codecs(cram_block_compression_hdr *hdr) { + int i; + + for (i = 0; i < DS_END; i++) { + if (hdr->codecs[i] && hdr->codecs[i]->reset) + hdr->codecs[i]->reset(hdr->codecs[i]); + } + + for (i = 0; i < CRAM_MAP_HASH; i++) { + cram_map *m; + for (m = hdr->rec_encoding_map[i]; m; m = m->next) + if (m->codec) m->codec->reset(m->codec); + } + + for (i = 0; i < CRAM_MAP_HASH; i++) { + cram_map *m; + for (m = hdr->tag_encoding_map[i]; m; m = m->next) + if (m->codec) m->codec->reset(m->codec); + } +} + /* * Decode an entire slice from container blocks. Fills out s->crecs[] array. * Returns 0 on success @@ -2185,6 +2216,9 @@ int cram_decode_slice(cram_fd *fd, cram_container *c, cram_slice *s, char **refs = NULL; uint32_t ds; + /* Clear any cached blocks in the external / B.A.S. codecs */ + reset_all_codecs(c->comp_hdr); + if (cram_dependent_data_series(fd, c->comp_hdr, s) != 0) return -1; @@ -2234,8 +2268,7 @@ int cram_decode_slice(cram_fd *fd, cram_container *c, cram_slice *s, if (embed_ref) { cram_block *b; if (s->hdr->ref_base_id < 0) { - fprintf(stderr, "No reference specified and " - "no embedded reference is available.\n"); + hts_log_error("No reference specified and no embedded reference is available"); return -1; } b = cram_get_block_by_id(s, s->hdr->ref_base_id); @@ -2246,6 +2279,10 @@ int cram_decode_slice(cram_fd *fd, cram_container *c, cram_slice *s, s->ref = (char *)BLOCK_DATA(b); s->ref_start = s->hdr->ref_seq_start; s->ref_end = s->hdr->ref_seq_start + s->hdr->ref_seq_span-1; + if (s->ref_end - s->ref_start > b->uncomp_size) { + hts_log_error("Embedded reference is too small"); + return -1; + } } else if (!fd->no_ref) { //// Avoid Java cramtools bug by loading entire reference seq //s->ref = cram_get_ref(fd, s->hdr->ref_seq_id, 1, 0); @@ -2261,12 +2298,13 @@ int cram_decode_slice(cram_fd *fd, cram_container *c, cram_slice *s, /* Sanity check */ if (s->ref_start < 0) { - fprintf(stderr, "Slice starts before base 1.\n"); + hts_log_warning("Slice starts before base 1"); s->ref_start = 0; } pthread_mutex_lock(&fd->ref_lock); pthread_mutex_lock(&fd->refs->lock); if ((fd->required_fields & SAM_SEQ) && + ref_id < fd->refs->nref && s->ref_end > fd->refs->ref_id[ref_id]->length) { s->ref_end = fd->refs->ref_id[ref_id]->length; } @@ -2277,7 +2315,7 @@ int cram_decode_slice(cram_fd *fd, cram_container *c, cram_slice *s, if ((fd->required_fields & SAM_SEQ) && s->ref == NULL && s->hdr->ref_seq_id >= 0 && !fd->no_ref) { - fprintf(stderr, "Unable to fetch reference #%d %d..%d\n", + hts_log_error("Unable to fetch reference #%d %d..%d", s->hdr->ref_seq_id, s->hdr->ref_seq_start, s->hdr->ref_seq_start + s->hdr->ref_seq_span-1); return -1; @@ -2297,14 +2335,14 @@ int cram_decode_slice(cram_fd *fd, cram_container *c, cram_slice *s, if (s->hdr->ref_seq_start >= s->ref_start) { start = s->hdr->ref_seq_start - s->ref_start; } else { - fprintf(stderr, "Slice starts before base 1.\n"); + hts_log_warning("Slice starts before base 1"); start = 0; } if (s->hdr->ref_seq_span <= s->ref_end - s->ref_start + 1) { len = s->hdr->ref_seq_span; } else { - fprintf(stderr, "Slice ends beyond reference end.\n"); + hts_log_warning("Slice ends beyond reference end"); len = s->ref_end - s->ref_start + 1; } @@ -2330,10 +2368,10 @@ int cram_decode_slice(cram_fd *fd, cram_container *c, cram_slice *s, if ((!s->ref && s->hdr->ref_base_id < 0) || memcmp(digest, s->hdr->md5, 16) != 0) { char M[33]; - fprintf(stderr, "ERROR: md5sum reference mismatch for ref " - "%d pos %d..%d\n", ref_id, s->ref_start, s->ref_end); - fprintf(stderr, "CRAM: %s\n", md5_print(s->hdr->md5, M)); - fprintf(stderr, "Ref : %s\n", md5_print(digest, M)); + hts_log_error("MD5 checksum reference mismatch for ref %d pos %d..%d", + ref_id, s->ref_start, s->ref_end); + hts_log_error("CRAM: %s", md5_print(s->hdr->md5, M)); + hts_log_error("Ref : %s", md5_print(digest, M)); return -1; } } @@ -2429,8 +2467,8 @@ int cram_decode_slice(cram_fd *fd, cram_container *c, cram_slice *s, } else { cr->ref_id = ref_id; // Forced constant in CRAM 1.0 } - if (cr->ref_id >= bfd->nref) { - fprintf(stderr, "Requested unknown reference ID %d\n", cr->ref_id); + if (cr->ref_id < -1 || cr->ref_id >= bfd->nref) { + hts_log_error("Requested unknown reference ID %d", cr->ref_id); return -1; } @@ -2441,7 +2479,7 @@ int cram_decode_slice(cram_fd *fd, cram_container *c, cram_slice *s, (char *)&cr->len, &out_sz); if (r) return r; if (cr->len < 0) { - fprintf(stderr, "Read has negative length\n"); + hts_log_error("Read has negative length"); return -1; } } @@ -2628,8 +2666,7 @@ int cram_decode_slice(cram_fd *fd, cram_container *c, cram_slice *s, if (!(bf & BAM_FUNMAP)) { if ((ds & CRAM_AP) && cr->apos <= 0) { - fprintf(stderr, - "Read has alignment position %d but no unmapped flag\n", + hts_log_error("Read has alignment position %d but no unmapped flag", cr->apos); return -1; } @@ -2707,11 +2744,11 @@ int cram_decode_slice(cram_fd *fd, cram_container *c, cram_slice *s, // As we grow blocks we overallocate by up to 50%. So shrink // back to their final sizes here. // -// fprintf(stderr, "%d %d // %d %d // %d %d // %d %d\n", -// (int)s->seqs_blk->byte, (int)s->seqs_blk->alloc, -// (int)s->qual_blk->byte, (int)s->qual_blk->alloc, -// (int)s->name_blk->byte, (int)s->name_blk->alloc, -// (int)s->aux_blk->byte, (int)s->aux_blk->alloc); + //fprintf(stderr, "%d %d // %d %d // %d %d // %d %d\n", + // (int)s->seqs_blk->byte, (int)s->seqs_blk->alloc, + // (int)s->qual_blk->byte, (int)s->qual_blk->alloc, + // (int)s->name_blk->byte, (int)s->name_blk->alloc, + // (int)s->aux_blk->byte, (int)s->aux_blk->alloc); BLOCK_RESIZE_EXACT(s->seqs_blk, BLOCK_SIZE(s->seqs_blk)+1); BLOCK_RESIZE_EXACT(s->qual_blk, BLOCK_SIZE(s->qual_blk)+1); BLOCK_RESIZE_EXACT(s->name_blk, BLOCK_SIZE(s->name_blk)+1); @@ -2904,7 +2941,8 @@ static cram_slice *cram_next_slice(cram_fd *fd, cram_container **cp) { if (fd->range.refid != -2) { while (c->ref_seq_id != -2 && (c->ref_seq_id < fd->range.refid || - c->ref_seq_start + c->ref_seq_span-1 < fd->range.start)) { + (fd->range.refid >= 0 && c->ref_seq_id == fd->range.refid + && c->ref_seq_start + c->ref_seq_span-1 < fd->range.start))) { if (0 != cram_seek(fd, c->length, SEEK_CUR)) return NULL; cram_free_container(fd->ctr); @@ -2914,8 +2952,10 @@ static cram_slice *cram_next_slice(cram_fd *fd, cram_container **cp) { } while (c->length == 0); } - if (c->ref_seq_id != -2 && c->ref_seq_id != fd->range.refid) + if (c->ref_seq_id != -2 && c->ref_seq_id != fd->range.refid) { + fd->eof = 1; return NULL; + } } if (!(c->comp_hdr_block = cram_read_block(fd))) @@ -3068,7 +3108,7 @@ static cram_slice *cram_next_slice(cram_fd *fd, cram_container **cp) { if (cram_decode_slice_mt(fd, c, s, fd->header) != 0) { // if (cram_decode_slice(fd, c, s, fd->header) != 0) { - fprintf(stderr, "Failure to decode slice\n"); + hts_log_error("Failure to decode slice"); cram_free_slice(s); c->slice = NULL; return NULL; @@ -3087,9 +3127,9 @@ static cram_slice *cram_next_slice(cram_fd *fd, cram_container **cp) { hts_tpool_result *res; cram_decode_job *j; -// fprintf(stderr, "Thread pool len = %d, %d\n", -// hts_tpool_results_queue_len(fd->rqueue), -// hts_tpool_results_queue_sz(fd->rqueue)); + //fprintf(stderr, "Thread pool len = %d, %d\n", + // hts_tpool_results_queue_len(fd->rqueue), + // hts_tpool_results_queue_sz(fd->rqueue)); if (fd->ooc && hts_tpool_process_empty(fd->rqueue)) return NULL; @@ -3097,7 +3137,7 @@ static cram_slice *cram_next_slice(cram_fd *fd, cram_container **cp) { res = hts_tpool_next_result_wait(fd->rqueue); if (!res || !hts_tpool_result_data(res)) { - fprintf(stderr, "hts_tpool_next_result failure\n"); + hts_log_error("Call to hts_tpool_next_result failed"); return NULL; } @@ -3105,6 +3145,13 @@ static cram_slice *cram_next_slice(cram_fd *fd, cram_container **cp) { c = j->c; s = j->s; + if (j->exit_code != 0) { + hts_log_error("Slice decode failure"); + fd->eof = 0; + hts_tpool_delete_result(res, 1); + return NULL; + } + fd->ctr = c; hts_tpool_delete_result(res, 1); @@ -3184,7 +3231,7 @@ cram_record *cram_get_seq(cram_fd *fd) { /* * Read the next cram record and convert it to a bam_seq_t struct. * - * Returns 0 on success + * Returns >= 0 success (number of bytes written to *bam) * -1 on EOF or failure (check fd->err) */ int cram_get_bam_seq(cram_fd *fd, bam_seq_t **bam) { diff --git a/htslib/cram/cram_encode.c b/htslib/cram/cram_encode.c index 6a43d9933..884845c9a 100644 --- a/htslib/cram/cram_encode.c +++ b/htslib/cram/cram_encode.c @@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "cram/cram.h" #include "cram/os.h" #include "htslib/hts.h" +#include "htslib/hts_endian.h" KHASH_MAP_INIT_STR(m_s2u64, uint64_t) @@ -238,7 +239,7 @@ cram_block *cram_encode_compression_header(cram_fd *fd, cram_container *c, } default: - fprintf(stderr, "Unknown preservation key '%.2s'\n", key); + hts_log_warning("Unknown preservation key '%.2s'", key); break; } @@ -478,173 +479,19 @@ cram_block *cram_encode_compression_header(cram_fd *fd, cram_container *c, if (c->tags_used) { khint_t k; -#define TAG_ID(a) ((#a[0]<<8)+#a[1]) - for (k = kh_begin(c->tags_used); k != kh_end(c->tags_used); k++) { int key; if (!kh_exist(c->tags_used, k)) continue; - mc++; - itf8_put_blk(map, kh_key(c->tags_used, k)); + key = kh_key(c->tags_used, k); + cram_codec *cd = kh_val(c->tags_used, k)->codec; - // use block content id 4 - switch((key = kh_key(c->tags_used, k)) & 0xff) { - case 'Z': case 'H': - // string as byte_array_stop - if (CRAM_MAJOR_VERS(fd->version) == 1) { - BLOCK_APPEND(map, - "\005" // BYTE_ARRAY_STOP - "\005" // len - "\t" // stop-byte is also SAM separator - DS_aux_S "\000\000\000", - 7); - } else { - if (key>>8 == TAG_ID(OQ)) - BLOCK_APPEND(map, - "\005" // BYTE_ARRAY_STOP - "\002" // len - "\t" // stop-byte is also SAM separator - DS_aux_OQ_S, - 4); - else if (key>>8 == TAG_ID(BQ)) - BLOCK_APPEND(map, - "\005" // BYTE_ARRAY_STOP - "\002" // len - "\t" // stop-byte is also SAM separator - DS_aux_BQ_S, - 4); - else if (key>>8 == TAG_ID(BD)) - BLOCK_APPEND(map, - "\005" // BYTE_ARRAY_STOP - "\002" // len - "\t" // stop-byte is also SAM separator - DS_aux_BD_S, - 4); - else if (key>>8 == TAG_ID(BI)) - BLOCK_APPEND(map, - "\005" // BYTE_ARRAY_STOP - "\002" // len - "\t" // stop-byte is also SAM separator - DS_aux_BI_S, - 4); - else if ((key>>8 == TAG_ID(Q2)) || - (key>>8 == TAG_ID(U2)) || - (key>>8 == TAG_ID(QT)) || - (key>>8 == TAG_ID(CQ))) - BLOCK_APPEND(map, - "\005" // BYTE_ARRAY_STOP - "\002" // len - "\t" // stop-byte is also SAM separator - DS_aux_oq_S, - 4); - else if ((key>>8 == TAG_ID(R2)) || - (key>>8 == TAG_ID(E2)) || - (key>>8 == TAG_ID(CS)) || - (key>>8 == TAG_ID(BC)) || - (key>>8 == TAG_ID(RT))) - BLOCK_APPEND(map, - "\005" // BYTE_ARRAY_STOP - "\002" // len - "\t" // stop-byte is also SAM separator - DS_aux_os_S, - 4); - else - BLOCK_APPEND(map, - "\005" // BYTE_ARRAY_STOP - "\002" // len - "\t" // stop-byte is also SAM separator - DS_aux_oz_S, - 4); - } - break; - - case 'A': case 'c': case 'C': - // byte array len, 1 byte - BLOCK_APPEND(map, - "\004" // BYTE_ARRAY_LEN - "\011" // length - "\003" // HUFFMAN (len) - "\004" // huffman-len - "\001" // 1 symbol - "\001" // symbol=1 byte value - "\001" // 1 length - "\000" // length=0 - "\001" // EXTERNAL (val) - "\001" // external-len - DS_aux_S,// content-id - 11); - break; - - case 's': case 'S': - // byte array len, 2 byte - BLOCK_APPEND(map, - "\004" // BYTE_ARRAY_LEN - "\011" // length - "\003" // HUFFMAN (len) - "\004" // huffman-len - "\001" // 1 symbol - "\002" // symbol=2 byte value - "\001" // 1 length - "\000" // length=0 - "\001" // EXTERNAL (val) - "\001" // external-len - DS_aux_S,// content-id - 11); - break; - - case 'i': case 'I': case 'f': - // byte array len, 4 byte - BLOCK_APPEND(map, - "\004" // BYTE_ARRAY_LEN - "\011" // length - "\003" // HUFFMAN (len) - "\004" // huffman-len - "\001" // 1 symbol - "\004" // symbol=4 byte value - "\001" // 1 length - "\000" // length=0 - "\001" // EXTERNAL (val) - "\001" // external-len - DS_aux_S,// content-id - 11); - break; - - case 'B': - // Byte array of variable size, but we generate our tag - // byte stream at the wrong stage (during reading and not - // after slice header construction). So we use - // BYTE_ARRAY_LEN with the length codec being external - // too. - if ((key>>8 == TAG_ID(FZ)) || (key>>8 == TAG_ID(ZM))) - BLOCK_APPEND(map, - "\004" // BYTE_ARRAY_LEN - "\006" // length - "\001" // EXTERNAL (len) - "\001" // external-len - DS_aux_FZ_S // content-id - "\001" // EXTERNAL (val) - "\001" // external-len - DS_aux_FZ_S,// content-id - 8); - else - BLOCK_APPEND(map, - "\004" // BYTE_ARRAY_LEN - "\006" // length - "\001" // EXTERNAL (len) - "\001" // external-len - DS_aux_S // content-id - "\001" // EXTERNAL (val) - "\001" // external-len - DS_aux_S,// content-id - 8); - break; + itf8_put_blk(map, key); + if (-1 == cd->store(cd, map, NULL, fd->version)) + return NULL; - default: - fprintf(stderr, "Unsupported SAM aux type '%c'\n", - kh_key(c->tags_used, k) & 0xff); - } - //mp += m->codec->store(m->codec, mp, NULL, fd->version); + mc++; } } #endif @@ -652,9 +499,7 @@ cram_block *cram_encode_compression_header(cram_fd *fd, cram_container *c, itf8_put_blk(cb, mc); BLOCK_APPEND(cb, BLOCK_DATA(map), BLOCK_SIZE(map)); - if (fd->verbose) - fprintf(stderr, "Wrote compression block header in %d bytes\n", - (int)BLOCK_SIZE(cb)); + hts_log_info("Wrote compression block header in %d bytes", (int)BLOCK_SIZE(cb)); BLOCK_UPLEN(cb); @@ -899,8 +744,7 @@ static int cram_encode_slice_read(cram_fd *fd, default: - fprintf(stderr, "unhandled feature code %c\n", - f->X.code); + hts_log_error("Unhandled feature code %c", f->X.code); return -1; } } @@ -924,13 +768,13 @@ static int cram_encode_slice_read(cram_fd *fd, * Returns 0 on success * -1 on failure */ -static int cram_compress_slice(cram_fd *fd, cram_slice *s) { +static int cram_compress_slice(cram_fd *fd, cram_container *c, cram_slice *s) { int level = fd->level, i; int method = 1< 5 && s->block[0]->uncomp_size > 500) - cram_compress_block(fd, s->block[0], NULL, GZIP, 1); + cram_compress_block(fd, s->block[0], NULL, 1<use_bz2) method |= 1<naux_block; i++) { + if (!s->aux_block[i] || s->aux_block[i] == s->block[0]) + continue; + + if (s->aux_block[i]->method != RAW) + continue; + + if (cram_compress_block(fd, s->aux_block[i], s->aux_block[i]->m, + method, level)) + return -1; + } + } + /* * Minimal compression of any block still uncompressed, bar CORE */ { int i; - for (i = 1; i < DS_END; i++) { + for (i = 1; i < s->hdr->num_blocks && i < DS_END; i++) { if (!s->block[i] || s->block[i] == s->block[0]) continue; - // fast methods only - if (s->block[i]->method == RAW) { - cram_compress_block(fd, s->block[i], fd->m[i], - methodF, level); - } + if (s->block[i]->method != RAW) + continue; + + if (cram_compress_block(fd, s->block[i], fd->m[i], + methodF, level)) + return -1; } } @@ -1064,7 +927,8 @@ static int cram_encode_slice(cram_fd *fd, cram_container *c, s->hdr->record_counter = c->num_records + c->record_counter; c->num_records += s->hdr->num_records; - s->block = calloc(DS_END, sizeof(s->block[0])); + int ntags = c->tags_used ? c->tags_used->n_occupied : 0; + s->block = calloc(DS_END + ntags, sizeof(s->block[0])); s->hdr->block_content_ids = malloc(DS_END * sizeof(int32_t)); if (!s->block || !s->hdr->block_content_ids) return -1; @@ -1149,6 +1013,16 @@ static int cram_encode_slice(cram_fd *fd, cram_container *c, h->codecs[id]->out = s->block[id]; } + /* + * Add in the external tag blocks too. + */ + if (c->tags_used) { + int n; + s->hdr->num_blocks = DS_END; + for (n = 0; n < s->naux_block; n++) + s->block[s->hdr->num_blocks++] = s->aux_block[n]; + } + /* Encode reads */ last_pos = s->hdr->ref_seq_start; for (rec = 0; rec < s->hdr->num_records; rec++) { @@ -1165,18 +1039,9 @@ static int cram_encode_slice(cram_fd *fd, cram_container *c, s->block[DS_QS] = s->qual_blk; s->qual_blk = NULL; s->block[DS_RN] = s->name_blk; s->name_blk = NULL; s->block[DS_SC] = s->soft_blk; s->soft_blk = NULL; - s->block[DS_aux]= s->aux_blk; s->aux_blk = NULL; - s->block[DS_aux_OQ]= s->aux_OQ_blk; s->aux_OQ_blk = NULL; - s->block[DS_aux_BQ]= s->aux_BQ_blk; s->aux_BQ_blk = NULL; - s->block[DS_aux_BD]= s->aux_BD_blk; s->aux_BD_blk = NULL; - s->block[DS_aux_BI]= s->aux_BI_blk; s->aux_BI_blk = NULL; - s->block[DS_aux_FZ]= s->aux_FZ_blk; s->aux_FZ_blk = NULL; - s->block[DS_aux_oq]= s->aux_oq_blk; s->aux_oq_blk = NULL; - s->block[DS_aux_os]= s->aux_os_blk; s->aux_os_blk = NULL; - s->block[DS_aux_oz]= s->aux_oz_blk; s->aux_oz_blk = NULL; // Ensure block sizes are up to date. - for (id = 1; id < DS_END; id++) { + for (id = 1; id < s->hdr->num_blocks; id++) { if (!s->block[id] || s->block[id] == s->block[0]) continue; @@ -1185,13 +1050,19 @@ static int cram_encode_slice(cram_fd *fd, cram_container *c, } // Compress it all - if (cram_compress_slice(fd, s) == -1) + if (cram_compress_slice(fd, c, s) == -1) return -1; // Collapse empty blocks and create hdr_block { int i, j; - for (i = j = 1; i < DS_END; i++) { + + s->hdr->block_content_ids = realloc(s->hdr->block_content_ids, + s->hdr->num_blocks * sizeof(int32_t)); + if (!s->hdr->block_content_ids) + return -1; + + for (i = j = 1; i < s->hdr->num_blocks; i++) { if (!s->block[i] || s->block[i] == s->block[0]) continue; if (s->block[i]->uncomp_size == 0) { @@ -1404,7 +1275,7 @@ int cram_encode_container(cram_fd *fd, cram_container *c) { ref = cram_get_ref(fd, bam_ref(b), 1, 0); if (!ref && bam_ref(b) >= 0) { - fprintf(stderr, "Failed to load reference #%d\n", bam_ref(b)); + hts_log_error("Failed to load reference #%d", bam_ref(b)); return -1; } if ((c->ref_id = bam_ref(b)) >= 0) { @@ -1437,7 +1308,7 @@ int cram_encode_container(cram_fd *fd, cram_container *c) { // Iterate through records creating the cram blocks for some // fields and just gathering stats for others. - for (r2 = 0; r1 < c->curr_c_rec && r2 < c->max_rec; r1++, r2++) { + for (r2 = 0; r1 < c->curr_c_rec && r2 < s->hdr->num_records; r1++, r2++) { cram_record *cr = &s->crecs[r2]; bam_seq_t *b = c->bams[r1]; @@ -1448,13 +1319,13 @@ int cram_encode_container(cram_fd *fd, cram_container *c) { cram_ref_decr(fd->refs, c->ref_seq_id); if (!cram_get_ref(fd, bam_ref(b), 1, 0)) { - fprintf(stderr, "Failed to load reference #%d\n", - bam_ref(b)); + hts_log_error("Failed to load reference #%d", bam_ref(b)); return -1; } c->ref_seq_id = bam_ref(b); // overwritten later by -2 - assert(fd->refs->ref_id[c->ref_seq_id]->seq); + if (!fd->refs->ref_id[c->ref_seq_id]->seq) + return -1; c->ref = fd->refs->ref_id[c->ref_seq_id]->seq; c->ref_start = 1; c->ref_end = fd->refs->ref_id[c->ref_seq_id]->length; @@ -1488,6 +1359,29 @@ int cram_encode_container(cram_fd *fd, cram_container *c) { s->hdr->ref_seq_span = MAX(0, last_base - first_base + 1); } s->hdr->num_records = r2; + + // Processed a slice, now stash the aux blocks so the next + // slice can start aggregating them from the start again. + if (c->tags_used->n_occupied) { + int ntags = c->tags_used->n_occupied; + s->aux_block = calloc(ntags, sizeof(*s->aux_block)); + if (!s->aux_block) + return -1; + + khint_t k; + + s->naux_block = 0; + for (k = kh_begin(c->tags_used); k != kh_end(c->tags_used); k++) { + if (!kh_exist(c->tags_used, k)) + continue; + + cram_tag_map *tm = kh_val(c->tags_used, k); + if (!tm->blk) continue; + s->aux_block[s->naux_block++] = tm->blk; + tm->blk = NULL; + } + assert(s->naux_block <= c->tags_used->n_occupied); + } } if (c->multi_seq && !fd->no_ref) { @@ -1509,8 +1403,7 @@ int cram_encode_container(cram_fd *fd, cram_container *c) { multi_ref = c->stats[DS_RI]->nvals > 1; if (multi_ref) { - if (fd->verbose) - fprintf(stderr, "Multi-ref container\n"); + hts_log_info("Multi-ref container"); c->ref_seq_id = -2; c->ref_seq_start = 0; c->ref_seq_span = 0; @@ -1550,7 +1443,7 @@ int cram_encode_container(cram_fd *fd, cram_container *c) { h->codecs[DS_CF] = cram_encoder_init(cram_stats_encoding(fd, c->stats[DS_CF]), c->stats[DS_CF], E_INT, NULL, fd->version); -// fprintf(stderr, "=== RN ===\n"); + //fprintf(stderr, "=== RN ===\n"); // h->codecs[DS_RN] = cram_encoder_init(cram_stats_encoding(fd, c->stats[DS_RN]), // c->stats[DS_RN], E_BYTE_ARRAY, NULL, // fd->version); @@ -1744,8 +1637,8 @@ int cram_encode_container(cram_fd *fd, cram_container *c) { /* Encode slices */ for (i = 0; i < c->curr_slice; i++) { - if (fd->verbose) - fprintf(stderr, "Encode slice %d\n", i); + hts_log_info("Encode slice %d", i); + if (cram_encode_slice(fd, c, h, c->slices[i]) != 0) return -1; } @@ -1794,7 +1687,7 @@ int cram_encode_container(cram_fd *fd, cram_container *c) { for (i = 0; i < c->curr_slice; i++) { cram_slice *s = c->slices[i]; - c->num_blocks += s->hdr->num_blocks + 1; // slice header + c->num_blocks += s->hdr->num_blocks + 1; // slice header c->landmark[i] = slice_offset; if (s->hdr->ref_seq_start + s->hdr->ref_seq_span > @@ -2036,7 +1929,7 @@ static int cram_add_insertion(cram_container *c, cram_slice *s, cram_record *r, } /* - * Encodes auxiliary data. + * Encodes auxiliary data, CRAM 1.0 format. * Returns the read-group parsed out of the BAM aux fields on success * NULL on failure or no rg present (FIXME) */ @@ -2071,7 +1964,7 @@ static char *cram_encode_aux_1_0(cram_fd *fd, bam_seq_t *b, cram_container *c, case 'A': case 'C': case 'c': aux+=4; break; case 'I': case 'i': case 'f': aux+=7; break; default: - fprintf(stderr, "Unhandled type code for NM tag\n"); + hts_log_error("Unhandled type code for NM tag"); return NULL; } continue; @@ -2080,7 +1973,7 @@ static char *cram_encode_aux_1_0(cram_fd *fd, bam_seq_t *b, cram_container *c, cr->ntags++; i32 = (aux[0]<<16) | (aux[1]<<8) | aux[2]; - kh_put(s_i2i, c->tags_used, i32, &r); + kh_put(m_tagmap, c->tags_used, i32, &r); if (-1 == r) return NULL; @@ -2141,10 +2034,8 @@ static char *cram_encode_aux_1_0(cram_fd *fd, bam_seq_t *b, cram_container *c, blen = 4*count; break; default: - fprintf(stderr, "Unknown sub-type '%c' for aux type 'B'\n", - type); + hts_log_error("Unknown sub-type '%c' for aux type 'B'", type); return NULL; - } tmp += itf8_put(tmp, blen+5); @@ -2159,7 +2050,7 @@ static char *cram_encode_aux_1_0(cram_fd *fd, bam_seq_t *b, cram_container *c, break; } default: - fprintf(stderr, "Unknown aux type '%c'\n", aux[2]); + hts_log_error("Unknown aux type '%c'", aux[2]); return NULL; } } @@ -2182,24 +2073,17 @@ static char *cram_encode_aux_1_0(cram_fd *fd, bam_seq_t *b, cram_container *c, */ static char *cram_encode_aux(cram_fd *fd, bam_seq_t *b, cram_container *c, cram_slice *s, cram_record *cr) { - char *aux, *orig, *tmp, *rg = NULL; + char *aux, *orig, *rg = NULL; int aux_size = bam_get_l_aux(b); cram_block *td_b = c->comp_hdr->TD_blk; int TD_blk_size = BLOCK_SIZE(td_b), new; char *key; khint_t k; - - /* Worst case is 1 nul char on every ??:Z: string, so +33% */ - BLOCK_GROW(s->aux_blk, aux_size*1.34+1); - tmp = (char *)BLOCK_END(s->aux_blk); - - orig = aux = (char *)bam_aux(b); - // Copy aux keys to td_b and aux values to s->aux_blk + // Copy aux keys to td_b and aux values to slice aux blocks while (aux - orig < aux_size && aux[0] != 0) { - uint32_t i32; int r; // RG:Z @@ -2225,7 +2109,7 @@ static char *cram_encode_aux(cram_fd *fd, bam_seq_t *b, cram_container *c, case 'S': case 's': aux+=5; break; case 'I': case 'i': case 'f': aux+=7; break; default: - fprintf(stderr, "Unhandled type code for NM tag\n"); + hts_log_error("Unhandled type code for NM tag"); return NULL; } continue; @@ -2234,190 +2118,203 @@ static char *cram_encode_aux(cram_fd *fd, bam_seq_t *b, cram_container *c, BLOCK_APPEND(td_b, aux, 3); - i32 = (aux[0]<<16) | (aux[1]<<8) | aux[2]; - kh_put(s_i2i, c->tags_used, i32, &r); + // Container level tags_used, for TD series + // Maps integer key ('X0i') to cram_tag_map struct. + int key = (aux[0]<<16)|(aux[1]<<8)|aux[2]; + k = kh_put(m_tagmap, c->tags_used, key, &r); if (-1 == r) return NULL; - // BQ:Z - if (aux[0] == 'B' && aux[1] == 'Q' && aux[2] == 'Z') { - char *tmp; - if (!s->aux_BQ_blk) - if (!(s->aux_BQ_blk = cram_new_block(EXTERNAL, DS_aux_BQ))) - return NULL; - BLOCK_GROW(s->aux_BQ_blk, aux_size*1.34+1); - tmp = (char *)BLOCK_END(s->aux_BQ_blk); - aux += 3; - while ((*tmp++=*aux++)); - *tmp++ = '\t'; - BLOCK_SIZE(s->aux_BQ_blk) = (uc *)tmp - BLOCK_DATA(s->aux_BQ_blk); - continue; - } + if (r == 1) { + khint_t k_global; - // BD:Z - if (aux[0] == 'B' && aux[1]=='D' && aux[2] == 'Z') { - char *tmp; - if (!s->aux_BD_blk) - if (!(s->aux_BD_blk = cram_new_block(EXTERNAL, DS_aux_BD))) - return NULL; - BLOCK_GROW(s->aux_BD_blk, aux_size*1.34+1); - tmp = (char *)BLOCK_END(s->aux_BD_blk); - aux += 3; - while ((*tmp++=*aux++)); - *tmp++ = '\t'; - BLOCK_SIZE(s->aux_BD_blk) = (uc *)tmp - BLOCK_DATA(s->aux_BD_blk); - continue; - } + // Global tags_used for cram_metrics support + pthread_mutex_lock(&fd->metrics_lock); + k_global = kh_put(m_metrics, fd->tags_used, key, &r); + if (-1 == r) + return NULL; + if (r == 1) + kh_val(fd->tags_used, k_global) = cram_new_metrics(); - // BI:Z - if (aux[0] == 'B' && aux[1]=='I' && aux[2] == 'Z') { - char *tmp; - if (!s->aux_BI_blk) - if (!(s->aux_BI_blk = cram_new_block(EXTERNAL, DS_aux_BI))) - return NULL; - BLOCK_GROW(s->aux_BI_blk, aux_size*1.34+1); - tmp = (char *)BLOCK_END(s->aux_BI_blk); - aux += 3; - while ((*tmp++=*aux++)); - *tmp++ = '\t'; - BLOCK_SIZE(s->aux_BI_blk) = (uc *)tmp - BLOCK_DATA(s->aux_BI_blk); - continue; - } + pthread_mutex_unlock(&fd->metrics_lock); - // OQ:Z: - if (aux[0] == 'O' && aux[1] == 'Q' && aux[2] == 'Z') { - char *tmp; - if (!s->aux_OQ_blk) - if (!(s->aux_OQ_blk = cram_new_block(EXTERNAL, DS_aux_OQ))) - return NULL; - BLOCK_GROW(s->aux_OQ_blk, aux_size*1.34+1); - tmp = (char *)BLOCK_END(s->aux_OQ_blk); - aux += 3; - while ((*tmp++=*aux++)); - *tmp++ = '\t'; - BLOCK_SIZE(s->aux_OQ_blk) = (uc *)tmp - BLOCK_DATA(s->aux_OQ_blk); - continue; - } + int i2[2] = {'\t',key}; + size_t sk = key; + cram_tag_map *m = calloc(1, sizeof(*m)); + kh_val(c->tags_used, k) = m; - // FZ:B or ZM:B - if ((aux[0] == 'F' && aux[1] == 'Z' && aux[2] == 'B') || - (aux[0] == 'Z' && aux[1] == 'M' && aux[2] == 'B')) { - int type = aux[3], blen; - uint32_t count = (uint32_t)((((unsigned char *)aux)[4]<< 0) + - (((unsigned char *)aux)[5]<< 8) + - (((unsigned char *)aux)[6]<<16) + - (((unsigned char *)aux)[7]<<24)); - char *tmp; - if (!s->aux_FZ_blk) - if (!(s->aux_FZ_blk = cram_new_block(EXTERNAL, DS_aux_FZ))) - return NULL; - BLOCK_GROW(s->aux_FZ_blk, aux_size*1.34+1); - tmp = (char *)BLOCK_END(s->aux_FZ_blk); + cram_codec *c; - // skip TN field - aux+=3; + // Use a block content id based on the tag id. + // Codec type depends on tag data type. + switch(aux[2]) { + case 'Z': case 'H': + // string as byte_array_stop + c = cram_encoder_init(E_BYTE_ARRAY_STOP, NULL, + E_BYTE_ARRAY, (void *)i2, + fd->version); + break; - // We use BYTE_ARRAY_LEN with external length, so store that first - switch (type) { - case 'c': case 'C': - blen = count; + case 'A': case 'c': case 'C': { + // byte array len, 1 byte + cram_byte_array_len_encoder e; + cram_stats st; + + e.len_encoding = E_HUFFMAN; + e.len_dat = NULL; + memset(&st, 0, sizeof(st)); + cram_stats_add(&st, 1); + cram_stats_encoding(fd, &st); + + e.val_encoding = E_EXTERNAL; + e.val_dat = (void *)sk; + + c = cram_encoder_init(E_BYTE_ARRAY_LEN, &st, + E_BYTE_ARRAY, (void *)&e, + fd->version); break; - case 's': case 'S': - blen = 2*count; + } + + case 's': case 'S': { + // byte array len, 2 byte + cram_byte_array_len_encoder e; + cram_stats st; + + e.len_encoding = E_HUFFMAN; + e.len_dat = NULL; + memset(&st, 0, sizeof(st)); + cram_stats_add(&st, 2); + cram_stats_encoding(fd, &st); + + e.val_encoding = E_EXTERNAL; + e.val_dat = (void *)sk; + + c = cram_encoder_init(E_BYTE_ARRAY_LEN, &st, + E_BYTE_ARRAY, (void *)&e, + fd->version); break; - case 'i': case 'I': case 'f': - blen = 4*count; + } + case 'i': case 'I': case 'f': { + // byte array len, 4 byte + cram_byte_array_len_encoder e; + cram_stats st; + + e.len_encoding = E_HUFFMAN; + e.len_dat = NULL; + memset(&st, 0, sizeof(st)); + cram_stats_add(&st, 4); + cram_stats_encoding(fd, &st); + + e.val_encoding = E_EXTERNAL; + e.val_dat = (void *)sk; + + c = cram_encoder_init(E_BYTE_ARRAY_LEN, &st, + E_BYTE_ARRAY, (void *)&e, + fd->version); break; - default: - fprintf(stderr, "Unknown sub-type '%c' for aux type 'B'\n", - type); - return NULL; - } - blen += 5; // sub-type & length - tmp += itf8_put(tmp, blen); + case 'B': { + // Byte array of variable size, but we generate our tag + // byte stream at the wrong stage (during reading and not + // after slice header construction). So we use + // BYTE_ARRAY_LEN with the length codec being external + // too. + cram_byte_array_len_encoder e; - // The tag data itself - memcpy(tmp, aux, blen); tmp += blen; aux += blen; + e.len_encoding = E_EXTERNAL; + e.len_dat = (void *)sk; // or key+128 for len? - BLOCK_SIZE(s->aux_FZ_blk) = (uc *)tmp - BLOCK_DATA(s->aux_FZ_blk); - continue; - } + e.val_encoding = E_EXTERNAL; + e.val_dat = (void *)sk; - // Other quality data - {Q2,E2,U2,CQ}:Z and similar - if (((aux[0] == 'Q' && aux[1] == '2') || - (aux[0] == 'U' && aux[1] == '2') || - (aux[0] == 'Q' && aux[1] == 'T') || - (aux[0] == 'C' && aux[1] == 'Q')) && aux[2] == 'Z') { - char *tmp; - if (!s->aux_oq_blk) - if (!(s->aux_oq_blk = cram_new_block(EXTERNAL, DS_aux_oq))) - return NULL; - BLOCK_GROW(s->aux_oq_blk, aux_size*1.34+1); - tmp = (char *)BLOCK_END(s->aux_oq_blk); - aux += 3; - while ((*tmp++=*aux++)); - *tmp++ = '\t'; - BLOCK_SIZE(s->aux_oq_blk) = (uc *)tmp - BLOCK_DATA(s->aux_oq_blk); - continue; - } + c = cram_encoder_init(E_BYTE_ARRAY_LEN, NULL, + E_BYTE_ARRAY, (void *)&e, + fd->version); + break; + } - // Other sequence data - {R2,E2,CS,BC,RT}:Z and similar - if (((aux[0] == 'R' && aux[1] == '2') || - (aux[0] == 'E' && aux[1] == '2') || - (aux[0] == 'C' && aux[1] == 'S') || - (aux[0] == 'B' && aux[1] == 'C') || - (aux[0] == 'R' && aux[1] == 'T')) && aux[2] == 'Z') { - char *tmp; - if (!s->aux_os_blk) - if (!(s->aux_os_blk = cram_new_block(EXTERNAL, DS_aux_os))) - return NULL; - BLOCK_GROW(s->aux_os_blk, aux_size*1.34+1); - tmp = (char *)BLOCK_END(s->aux_os_blk); - aux += 3; - while ((*tmp++=*aux++)); - *tmp++ = '\t'; - BLOCK_SIZE(s->aux_os_blk) = (uc *)tmp - BLOCK_DATA(s->aux_os_blk); - continue; + default: + hts_log_error("Unsupported SAM aux type '%c'", aux[2]); + c = NULL; + } + + m->codec = c; + + // Link to fd-global tag metrics + m->m = k_global ? (cram_metrics *)kh_val(fd->tags_used, k_global) : NULL; } + cram_tag_map *tm = (cram_tag_map *)kh_val(c->tags_used, k); + cram_codec *codec = tm->codec; switch(aux[2]) { case 'A': case 'C': case 'c': + if (!tm->blk) { + if (!(tm->blk = cram_new_block(EXTERNAL, key))) + return NULL; + codec->e_byte_array_len.val_codec->out = tm->blk; + } + aux+=3; - *tmp++=*aux++; + //codec->encode(s, codec, aux, 1); + // Functionally equivalent, but less code. + BLOCK_APPEND_CHAR(tm->blk, *aux); + aux++; break; case 'S': case 's': + if (!tm->blk) { + if (!(tm->blk = cram_new_block(EXTERNAL, key))) + return NULL; + codec->e_byte_array_len.val_codec->out = tm->blk; + } + aux+=3; - *tmp++=*aux++; *tmp++=*aux++; + //codec->encode(s, codec, aux, 2); + BLOCK_APPEND(tm->blk, aux, 2); + aux+=2; break; case 'I': case 'i': case 'f': + if (!tm->blk) { + if (!(tm->blk = cram_new_block(EXTERNAL, key))) + return NULL; + codec->e_byte_array_len.val_codec->out = tm->blk; + } + aux+=3; - *tmp++=*aux++; *tmp++=*aux++; *tmp++=*aux++; *tmp++=*aux++; + //codec->encode(s, codec, aux, 4); + BLOCK_APPEND(tm->blk, aux, 4); + aux+=4; break; case 'd': + if (!tm->blk) { + if (!(tm->blk = cram_new_block(EXTERNAL, key))) + return NULL; + codec->e_byte_array_len.val_codec->out = tm->blk; + } + aux+=3; //*tmp++=*aux++; *tmp++=*aux++; *tmp++=*aux++; - *tmp++=*aux++; *tmp++=*aux++; *tmp++=*aux++; *tmp++=*aux++; - *tmp++=*aux++; *tmp++=*aux++; *tmp++=*aux++; *tmp++=*aux++; + //codec->encode(s, codec, aux, 8); + BLOCK_APPEND(tm->blk, aux, 8); + aux+=8; break; case 'Z': case 'H': { - char *tmp; - if (!s->aux_oz_blk) - if (!(s->aux_oz_blk = cram_new_block(EXTERNAL, DS_aux_oz))) + if (!tm->blk) { + if (!(tm->blk = cram_new_block(EXTERNAL, key))) return NULL; - BLOCK_GROW(s->aux_oz_blk, aux_size*1.34+1); - tmp = (char *)BLOCK_END(s->aux_oz_blk); + codec->out = tm->blk; + } + + char *aux_s; aux += 3; - while ((*tmp++=*aux++)); - *tmp++ = '\t'; - BLOCK_SIZE(s->aux_oz_blk) = (uc *)tmp - - BLOCK_DATA(s->aux_oz_blk); + aux_s = aux; + while (*aux++); + codec->encode(s, codec, aux_s, aux - aux_s); } break; @@ -2427,6 +2324,13 @@ static char *cram_encode_aux(cram_fd *fd, bam_seq_t *b, cram_container *c, (((unsigned char *)aux)[5]<< 8) + (((unsigned char *)aux)[6]<<16) + (((unsigned char *)aux)[7]<<24)); + if (!tm->blk) { + if (!(tm->blk = cram_new_block(EXTERNAL, key))) + return NULL; + codec->e_byte_array_len.len_codec->out = tm->blk; + codec->e_byte_array_len.val_codec->out = tm->blk; + } + // skip TN field aux+=3; @@ -2442,25 +2346,21 @@ static char *cram_encode_aux(cram_fd *fd, bam_seq_t *b, cram_container *c, blen = 4*count; break; default: - fprintf(stderr, "Unknown sub-type '%c' for aux type 'B'\n", - type); + hts_log_error("Unknown sub-type '%c' for aux type 'B'", type); return NULL; - } blen += 5; // sub-type & length - tmp += itf8_put(tmp, blen); - - // The tag data itself - memcpy(tmp, aux, blen); tmp += blen; aux += blen; - //cram_stats_add(c->aux_B_stats, blen); + codec->encode(s, codec, aux, blen); + aux += blen; break; } default: - fprintf(stderr, "Unknown aux type '%c'\n", aux[2]); + hts_log_error("Unknown aux type '%c'", aux[2]); return NULL; } + tm->blk->m = tm->m; } // FIXME: sort BLOCK_DATA(td_b) by char[3] triples @@ -2485,15 +2385,9 @@ static char *cram_encode_aux(cram_fd *fd, bam_seq_t *b, cram_container *c, cr->TL = kh_val(c->comp_hdr->TD_hash, k); cram_stats_add(c->stats[DS_TL], cr->TL); - cr->aux = BLOCK_SIZE(s->aux_blk); - cr->aux_size = (uc *)tmp - (BLOCK_DATA(s->aux_blk) + cr->aux); - BLOCK_SIZE(s->aux_blk) = (uc *)tmp - BLOCK_DATA(s->aux_blk); - assert(s->aux_blk->byte <= s->aux_blk->alloc); - return rg; } - /* * During cram_next_container or before the final flush at end of * file, we update the current slice headers and increment the slice @@ -2523,6 +2417,7 @@ void cram_update_curr_slice(cram_container *c) { c->curr_slice++; } + /* * Handles creation of a new container or new slice, flushing any * existing containers when appropriate. @@ -2547,10 +2442,9 @@ static cram_container *cram_next_container(cram_fd *fd, bam_seq_t *b) { if (c->curr_slice == c->max_slice || (bam_ref(b) != c->curr_ref && !c->multi_seq)) { c->ref_seq_span = fd->last_base - c->ref_seq_start + 1; - if (fd->verbose) - fprintf(stderr, "Flush container %d/%d..%d\n", - c->ref_seq_id, c->ref_seq_start, - c->ref_seq_start + c->ref_seq_span -1); + hts_log_info("Flush container %d/%d..%d", + c->ref_seq_id, c->ref_seq_start, + c->ref_seq_start + c->ref_seq_span -1); /* Encode slices */ if (fd->pool) { @@ -2602,6 +2496,7 @@ static cram_container *cram_next_container(cram_fd *fd, bam_seq_t *b) { } c->curr_rec = 0; + c->s_num_bases = 0; return c; } @@ -2693,7 +2588,7 @@ static int process_one_read(cram_fd *fd, cram_container *c, seq = cp = (char *)BLOCK_END(s->seqs_blk); *seq = 0; -#ifdef ALLOW_UAC +#if HTS_ALLOW_UNALIGNED != 0 { // Convert seq 2 bases at a time for speed. static const uint16_t code2base[256] = { @@ -2791,8 +2686,7 @@ static int process_one_read(cram_fd *fd, cram_container *c, char *rp = &ref[apos]; char *qp = &qual[spos]; if (end > cr->len) { - fprintf(stderr, "CIGAR and query sequence are of " - "different length\n"); + hts_log_error("CIGAR and query sequence are of different length"); return -1; } for (l = 0; l < end; l++) { @@ -2888,6 +2782,7 @@ static int process_one_read(cram_fd *fd, cram_container *c, cr->len ? &seq[spos] : NULL, fd->version)) return -1; + if (fd->no_ref && !(cr->cram_flags & CRAM_FLAG_PRESERVE_QUAL_SCORES)) { if (cr->len) { @@ -2913,11 +2808,14 @@ static int process_one_read(cram_fd *fd, cram_container *c, if (cram_add_pad(c, s, cr, spos, cig_len, &seq[spos])) return -1; break; + + default: + hts_log_error("Unknown CIGAR op code %d", cig_op); + return -1; } } if (cr->len && spos != cr->len) { - fprintf(stderr, "CIGAR and query sequence are of different " - "length\n"); + hts_log_error("CIGAR and query sequence are of different length"); return -1; } fake_qual = spos; @@ -3000,14 +2898,16 @@ static int process_one_read(cram_fd *fd, cram_container *c, } else { sign = -1; } - - //fprintf(stderr, "paired %"PRId64"\n", kh_val(s->pair[sec], k)); - // This vs p: tlen, matepos, flags - if (bam_ins_size(b) != sign*(aright-aleft+1)) + // This vs p: tlen, matepos, flags. Permit TLEN 0 and/or TLEN +/- + // a small amount, if appropriate options set. + if ((bam_ins_size(b) && + abs(bam_ins_size(b) - sign*(aright-aleft+1)) > fd->tlen_approx) || + (!bam_ins_size(b) && !fd->tlen_zero)) goto detached; - if (MAX(bam_mate_pos(b)+1, 0) != p->apos) + if ((!fd->tlen_zero && MAX(bam_mate_pos(b)+1, 0) != p->apos) && + !(fd->tlen_zero && bam_mate_pos(b) == 0)) goto detached; if (((bam_flag(b) & BAM_FMUNMAP) != 0) != @@ -3020,13 +2920,16 @@ static int process_one_read(cram_fd *fd, cram_container *c, // p vs this: tlen, matepos, flags - if (p->ref_id != cr->ref_id) + if (p->ref_id != cr->ref_id && + !(fd->tlen_zero && p->ref_id == -1)) goto detached; - if (p->tlen != -sign*(aright-aleft+1)) + if ((p->tlen && abs(p->tlen - -sign*(aright-aleft+1)) > fd->tlen_approx) || + (!p->tlen && !fd->tlen_zero)) goto detached; - if (p->mate_pos != cr->apos) + if (p->mate_pos != cr->apos && + !(fd->tlen_zero && p->mate_pos == 0)) goto detached; if (((p->flags & BAM_FMUNMAP) != 0) != @@ -3164,11 +3067,11 @@ int cram_put_bam_seq(cram_fd *fd, bam_seq_t *b) { c = fd->ctr; if (!c->slice || c->curr_rec == c->max_rec || - (bam_ref(b) != c->curr_ref && c->curr_ref >= -1)) { + (bam_ref(b) != c->curr_ref && c->curr_ref >= -1) || + (c->s_num_bases >= fd->bases_per_slice)) { int slice_rec, curr_rec, multi_seq = fd->multi_seq == 1; int curr_ref = c->slice ? c->curr_ref : bam_ref(b); - /* * Start packing slices when we routinely have under 1/4tr full. * @@ -3178,8 +3081,8 @@ int cram_put_bam_seq(cram_fd *fd, bam_seq_t *b) { if (fd->multi_seq == -1 && c->curr_rec < c->max_rec/4+10 && fd->last_slice && fd->last_slice < c->max_rec/4+10 && !fd->embed_ref) { - if (fd->verbose && !c->multi_seq) - fprintf(stderr, "Multi-ref enabled for this container\n"); + if (!c->multi_seq) + hts_log_info("Multi-ref enabled for this container"); multi_seq = 1; } @@ -3187,7 +3090,8 @@ int cram_put_bam_seq(cram_fd *fd, bam_seq_t *b) { curr_rec = c->curr_rec; if (CRAM_MAJOR_VERS(fd->version) == 1 || - c->curr_rec == c->max_rec || fd->multi_seq != 1 || !c->slice) { + c->curr_rec == c->max_rec || fd->multi_seq != 1 || !c->slice || + c->s_num_bases >= fd->bases_per_slice) { if (NULL == (c = cram_next_container(fd, b))) { if (fd->ctr) { // prevent cram_close attempting to flush @@ -3222,7 +3126,7 @@ int cram_put_bam_seq(cram_fd *fd, bam_seq_t *b) { c->slice_rec = c->curr_rec; // Have we seen this reference before? - if (bam_ref(b) >= 0 && bam_ref(b) != curr_ref && !fd->embed_ref && + if (bam_ref(b) >= 0 && curr_ref >= 0 && bam_ref(b) != curr_ref && !fd->embed_ref && !fd->unsorted && multi_seq) { if (!c->refs_used) { @@ -3267,6 +3171,7 @@ int cram_put_bam_seq(cram_fd *fd, bam_seq_t *b) { c->curr_rec++; c->curr_c_rec++; + c->s_num_bases += bam_seq_len(b); fd->record_counter++; return 0; diff --git a/htslib/cram/cram_external.c b/htslib/cram/cram_external.c index be1dc7b26..8d87f5847 100644 --- a/htslib/cram/cram_external.c +++ b/htslib/cram/cram_external.c @@ -301,8 +301,7 @@ int cram_transcode_rg(cram_fd *in, cram_fd *out, cram_block_compression_hdr *ch; if (nrg != 1) { - fprintf(stderr, "[%s] ERROR: not implemented for nrg != 1\n", - __func__); + hts_log_error("CRAM transcode supports only a single RG"); return -2; } diff --git a/htslib/cram/cram_index.c b/htslib/cram/cram_index.c index 5afbbbcab..41b4c063b 100644 --- a/htslib/cram/cram_index.c +++ b/htslib/cram/cram_index.c @@ -60,11 +60,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include "htslib/bgzf.h" #include "htslib/hfile.h" #include "hts_internal.h" #include "cram/cram.h" #include "cram/os.h" -#include "cram/zfio.h" #if 0 static void dump_index_(cram_index *e, int level) { @@ -208,7 +208,7 @@ int cram_index_load(cram_fd *fd, const char *fn, const char *fn_idx) { // Parse it line at a time - do { + while (pos < kstr.l) { /* 1.1 layout */ if (kget_int32(&kstr, &pos, &e.refid) == -1) goto fail; @@ -232,7 +232,7 @@ int cram_index_load(cram_fd *fd, const char *fn, const char *fn_idx) { //printf("%d/%d..%d\n", e.refid, e.start, e.end); if (e.refid < -1) { - fprintf(stderr, "Malformed index file, refid %d\n", e.refid); + hts_log_error("Malformed index file, refid %d", e.refid); goto fail; } @@ -292,7 +292,7 @@ int cram_index_load(cram_fd *fd, const char *fn, const char *fn_idx) { while (pos < kstr.l && kstr.s[pos] != '\n') pos++; pos++; - } while (pos < kstr.l); + } free(idx_stack); free(kstr.s); @@ -345,7 +345,10 @@ void cram_index_free(cram_fd *fd) { * "from" as the last slice we checked to find the next one. Otherwise * set "from" to be NULL to find the first one. * - * Returns the cram_index pointer on sucess + * Refid can also be any of the special HTS_IDX_ values. + * For backwards compatibility, refid -1 is equivalent to HTS_IDX_NOCOOR. + * + * Returns the cram_index pointer on success * NULL on failure */ cram_index *cram_index_query(cram_fd *fd, int refid, int pos, @@ -353,9 +356,34 @@ cram_index *cram_index_query(cram_fd *fd, int refid, int pos, int i, j, k; cram_index *e; - if (refid+1 < 0 || refid+1 >= fd->index_sz) + switch(refid) { + case HTS_IDX_NONE: + case HTS_IDX_REST: + // fail, or already there, dealt with elsewhere. return NULL; + case HTS_IDX_NOCOOR: + refid = -1; + break; + + case HTS_IDX_START: { + int64_t min_idx = INT64_MAX; + for (i = 0, j = -1; i < fd->index_sz; i++) { + if (fd->index[i].e && fd->index[i].e[0].offset < min_idx) { + min_idx = fd->index[i].e[0].offset; + j = i; + } + } + if (j < 0) + return NULL; + return fd->index[j].e; + } + + default: + if (refid < HTS_IDX_NONE || refid+1 >= fd->index_sz) + return NULL; + } + if (!from) from = &fd->index[refid+1]; @@ -406,6 +434,24 @@ cram_index *cram_index_query(cram_fd *fd, int refid, int pos, return e; } +// Return the index entry for last slice on a specific reference. +cram_index *cram_index_last(cram_fd *fd, int refid, cram_index *from) { + int slice; + + if (refid+1 < 0 || refid+1 >= fd->index_sz) + return NULL; + + if (!from) + from = &fd->index[refid+1]; + + // Ref with nothing aligned against it. + if (!from->e) + return NULL; + + slice = fd->index[refid+1].nslice - 1; + + return &from->e[slice]; +} /* * Skips to a container overlapping the start coordinate listed in @@ -424,6 +470,9 @@ cram_index *cram_index_query(cram_fd *fd, int refid, int pos, int cram_seek_to_refpos(cram_fd *fd, cram_range *r) { cram_index *e; + if (r->refid == HTS_IDX_NONE) + return -2; + // Ideally use an index, so see if we have one. if ((e = cram_index_query(fd, r->refid, r->start, NULL))) { if (0 != cram_seek(fd, e->offset, SEEK_SET)) @@ -434,6 +483,9 @@ int cram_seek_to_refpos(cram_fd *fd, cram_range *r) { return -2; } + if (r->refid == HTS_IDX_START || r->refid == HTS_IDX_REST) + fd->range.refid = -2; // special case in cram_next_slice + if (fd->ctr) { cram_free_container(fd->ctr); fd->ctr = NULL; @@ -450,12 +502,13 @@ int cram_seek_to_refpos(cram_fd *fd, cram_range *r) { * decode the slice to look at the RI data series instead. * * Returns 0 on success - * -1 on failure + * -1 on read failure + * -4 on write failure */ static int cram_index_build_multiref(cram_fd *fd, cram_container *c, cram_slice *s, - zfp *fp, + BGZF *fp, off_t cpos, int32_t landmark, int sz) { @@ -477,19 +530,21 @@ static int cram_index_build_multiref(cram_fd *fd, sprintf(buf, "%d\t%d\t%d\t%"PRId64"\t%d\t%d\n", ref, ref_start, ref_end - ref_start + 1, (int64_t)cpos, landmark, sz); - zfputs(buf, fp); + if (bgzf_write(fp, buf, strlen(buf)) < 0) + return -4; } ref = s->crecs[i].ref_id; ref_start = s->crecs[i].apos; - ref_end = INT_MIN; + ref_end = s->crecs[i].aend; } if (ref != -2) { sprintf(buf, "%d\t%d\t%d\t%"PRId64"\t%d\t%d\n", ref, ref_start, ref_end - ref_start + 1, (int64_t)cpos, landmark, sz); - zfputs(buf, fp); + if (bgzf_write(fp, buf, strlen(buf)) < 0) + return -4; } return 0; @@ -509,7 +564,7 @@ static int cram_index_build_multiref(cram_fd *fd, int cram_index_build(cram_fd *fd, const char *fn_base, const char *fn_idx) { cram_container *c; off_t cpos, spos, hpos; - zfp *fp; + BGZF *fp; kstring_t fn_idx_str = {0}; if (! fn_idx) { @@ -518,7 +573,7 @@ int cram_index_build(cram_fd *fd, const char *fn_base, const char *fn_idx) { fn_idx = fn_idx_str.s; } - if (!(fp = zfopen(fn_idx, "wz"))) { + if (!(fp = bgzf_open(fn_idx, "wg"))) { perror(fn_idx); free(fn_idx_str.s); return -4; @@ -549,30 +604,35 @@ int cram_index_build(cram_fd *fd, const char *fn_base, const char *fn_idx) { for (j = 0; j < c->num_landmarks; j++) { char buf[1024]; cram_slice *s; - int sz; + int sz, ret; spos = htell(fd->fp); assert(spos - cpos - c->offset == c->landmark[j]); if (!(s = cram_read_slice(fd))) { - zfclose(fp); + bgzf_close(fp); return -1; } sz = (int)(htell(fd->fp) - spos); if (s->hdr->ref_seq_id == -2) { - cram_index_build_multiref(fd, c, s, fp, - cpos, c->landmark[j], sz); + ret = cram_index_build_multiref(fd, c, s, fp, + cpos, c->landmark[j], sz); } else { sprintf(buf, "%d\t%d\t%d\t%"PRId64"\t%d\t%d\n", s->hdr->ref_seq_id, s->hdr->ref_seq_start, s->hdr->ref_seq_span, (int64_t)cpos, c->landmark[j], sz); - zfputs(buf, fp); + ret = (bgzf_write(fp, buf, strlen(buf)) >= 0)? 0 : -4; } cram_free_slice(s); + + if (ret < 0) { + bgzf_close(fp); + return ret; + } } cpos = htell(fd->fp); @@ -581,10 +641,9 @@ int cram_index_build(cram_fd *fd, const char *fn_base, const char *fn_idx) { cram_free_container(c); } if (fd->err) { - zfclose(fp); + bgzf_close(fp); return -1; } - - return (zfclose(fp) >= 0)? 0 : -4; + return (bgzf_close(fp) >= 0)? 0 : -4; } diff --git a/htslib/cram/cram_index.h b/htslib/cram/cram_index.h index 14d7a223a..504a0fa72 100644 --- a/htslib/cram/cram_index.h +++ b/htslib/cram/cram_index.h @@ -52,6 +52,7 @@ void cram_index_free(cram_fd *fd); * NULL on failure */ cram_index *cram_index_query(cram_fd *fd, int refid, int pos, cram_index *frm); +cram_index *cram_index_last(cram_fd *fd, int refid, cram_index *from); /* * Skips to a container overlapping the start coordinate listed in diff --git a/htslib/cram/cram_io.c b/htslib/cram/cram_io.c index f448f63d0..556a7c704 100644 --- a/htslib/cram/cram_io.c +++ b/htslib/cram/cram_io.c @@ -57,12 +57,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #endif #ifdef HAVE_LIBLZMA +#ifdef HAVE_LZMA_H #include +#else +#include "os/lzma_stub.h" +#endif #endif #include #include #include #include +#include #include "cram/cram.h" #include "cram/os.h" @@ -222,12 +227,15 @@ int itf8_decode_crc(cram_fd *fd, int32_t *val_p, uint32_t *crc) { return 4; case 4: // really 3.5 more, why make it different? - val = (val<<8) | (c[1]=hgetc(fd->fp)); - val = (val<<8) | (c[2]=hgetc(fd->fp)); - val = (val<<8) | (c[3]=hgetc(fd->fp)); - val = (val<<4) | (((c[4]=hgetc(fd->fp))) & 0x0f); - *val_p = val; - *crc = crc32(*crc, c, 5); + { + uint32_t uv = val; + uv = (uv<<8) | (c[1]=hgetc(fd->fp)); + uv = (uv<<8) | (c[2]=hgetc(fd->fp)); + uv = (uv<<8) | (c[3]=hgetc(fd->fp)); + uv = (uv<<4) | (((c[4]=hgetc(fd->fp))) & 0x0f); + *val_p = uv < 0x80000000UL ? uv : -((int32_t) (0xffffffffUL - uv)) - 1; + *crc = crc32(*crc, c, 5); + } } return 5; @@ -245,205 +253,33 @@ int itf8_encode(cram_fd *fd, int32_t val) { } const int itf8_bytes[16] = { - 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 3, 3, 4, 5 + 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 3, 3, 4, 5 }; -#ifndef ITF8_MACROS -/* - * As above, but decoding from memory - */ -int itf8_get(char *cp, int32_t *val_p) { - unsigned char *up = (unsigned char *)cp; - - if (up[0] < 0x80) { - *val_p = up[0]; - return 1; - } else if (up[0] < 0xc0) { - *val_p = ((up[0] <<8) | up[1]) & 0x3fff; - return 2; - } else if (up[0] < 0xe0) { - *val_p = ((up[0]<<16) | (up[1]<< 8) | up[2]) & 0x1fffff; - return 3; - } else if (up[0] < 0xf0) { - *val_p = ((up[0]<<24) | (up[1]<<16) | (up[2]<<8) | up[3]) & 0x0fffffff; - return 4; - } else { - *val_p = ((up[0] & 0x0f)<<28) | (up[1]<<20) | (up[2]<<12) | (up[3]<<4) | (up[4] & 0x0f); - return 5; - } -} +const int ltf8_bytes[256] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -/* - * Stores a value to memory in ITF-8 format. - * - * Returns the number of bytes required to store the number. - * This is a maximum of 5 bytes. - */ -int itf8_put(char *cp, int32_t val) { - if (!(val & ~0x00000007f)) { // 1 byte - *cp = val; - return 1; - } else if (!(val & ~0x00003fff)) { // 2 byte - *cp++ = (val >> 8 ) | 0x80; - *cp = val & 0xff; - return 2; - } else if (!(val & ~0x01fffff)) { // 3 byte - *cp++ = (val >> 16) | 0xc0; - *cp++ = (val >> 8 ) & 0xff; - *cp = val & 0xff; - return 3; - } else if (!(val & ~0x0fffffff)) { // 4 byte - *cp++ = (val >> 24) | 0xe0; - *cp++ = (val >> 16) & 0xff; - *cp++ = (val >> 8 ) & 0xff; - *cp = val & 0xff; - return 4; - } else { // 5 byte - *cp++ = 0xf0 | ((val>>28) & 0xff); - *cp++ = (val >> 20) & 0xff; - *cp++ = (val >> 12) & 0xff; - *cp++ = (val >> 4 ) & 0xff; - *cp = val & 0x0f; - return 5; - } -} -#endif + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -/* 64-bit itf8 variant */ -int ltf8_put(char *cp, int64_t val) { - if (!(val & ~((1LL<<7)-1))) { - *cp = val; - return 1; - } else if (!(val & ~((1LL<<(6+8))-1))) { - *cp++ = (val >> 8 ) | 0x80; - *cp = val & 0xff; - return 2; - } else if (!(val & ~((1LL<<(5+2*8))-1))) { - *cp++ = (val >> 16) | 0xc0; - *cp++ = (val >> 8 ) & 0xff; - *cp = val & 0xff; - return 3; - } else if (!(val & ~((1LL<<(4+3*8))-1))) { - *cp++ = (val >> 24) | 0xe0; - *cp++ = (val >> 16) & 0xff; - *cp++ = (val >> 8 ) & 0xff; - *cp = val & 0xff; - return 4; - } else if (!(val & ~((1LL<<(3+4*8))-1))) { - *cp++ = (val >> 32) | 0xf0; - *cp++ = (val >> 24) & 0xff; - *cp++ = (val >> 16) & 0xff; - *cp++ = (val >> 8 ) & 0xff; - *cp = val & 0xff; - return 5; - } else if (!(val & ~((1LL<<(2+5*8))-1))) { - *cp++ = (val >> 40) | 0xf8; - *cp++ = (val >> 32) & 0xff; - *cp++ = (val >> 24) & 0xff; - *cp++ = (val >> 16) & 0xff; - *cp++ = (val >> 8 ) & 0xff; - *cp = val & 0xff; - return 6; - } else if (!(val & ~((1LL<<(1+6*8))-1))) { - *cp++ = (val >> 48) | 0xfc; - *cp++ = (val >> 40) & 0xff; - *cp++ = (val >> 32) & 0xff; - *cp++ = (val >> 24) & 0xff; - *cp++ = (val >> 16) & 0xff; - *cp++ = (val >> 8 ) & 0xff; - *cp = val & 0xff; - return 7; - } else if (!(val & ~((1LL<<(7*8))-1))) { - *cp++ = (val >> 56) | 0xfe; - *cp++ = (val >> 48) & 0xff; - *cp++ = (val >> 40) & 0xff; - *cp++ = (val >> 32) & 0xff; - *cp++ = (val >> 24) & 0xff; - *cp++ = (val >> 16) & 0xff; - *cp++ = (val >> 8 ) & 0xff; - *cp = val & 0xff; - return 8; - } else { - *cp++ = 0xff; - *cp++ = (val >> 56) & 0xff; - *cp++ = (val >> 48) & 0xff; - *cp++ = (val >> 40) & 0xff; - *cp++ = (val >> 32) & 0xff; - *cp++ = (val >> 24) & 0xff; - *cp++ = (val >> 16) & 0xff; - *cp++ = (val >> 8 ) & 0xff; - *cp = val & 0xff; - return 9; - } -} + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -int ltf8_get(char *cp, int64_t *val_p) { - unsigned char *up = (unsigned char *)cp; - - if (up[0] < 0x80) { - *val_p = up[0]; - return 1; - } else if (up[0] < 0xc0) { - *val_p = (((uint64_t)up[0]<< 8) | - (uint64_t)up[1]) & (((1LL<<(6+8)))-1); - return 2; - } else if (up[0] < 0xe0) { - *val_p = (((uint64_t)up[0]<<16) | - ((uint64_t)up[1]<< 8) | - (uint64_t)up[2]) & ((1LL<<(5+2*8))-1); - return 3; - } else if (up[0] < 0xf0) { - *val_p = (((uint64_t)up[0]<<24) | - ((uint64_t)up[1]<<16) | - ((uint64_t)up[2]<< 8) | - (uint64_t)up[3]) & ((1LL<<(4+3*8))-1); - return 4; - } else if (up[0] < 0xf8) { - *val_p = (((uint64_t)up[0]<<32) | - ((uint64_t)up[1]<<24) | - ((uint64_t)up[2]<<16) | - ((uint64_t)up[3]<< 8) | - (uint64_t)up[4]) & ((1LL<<(3+4*8))-1); - return 5; - } else if (up[0] < 0xfc) { - *val_p = (((uint64_t)up[0]<<40) | - ((uint64_t)up[1]<<32) | - ((uint64_t)up[2]<<24) | - ((uint64_t)up[3]<<16) | - ((uint64_t)up[4]<< 8) | - (uint64_t)up[5]) & ((1LL<<(2+5*8))-1); - return 6; - } else if (up[0] < 0xfe) { - *val_p = (((uint64_t)up[0]<<48) | - ((uint64_t)up[1]<<40) | - ((uint64_t)up[2]<<32) | - ((uint64_t)up[3]<<24) | - ((uint64_t)up[4]<<16) | - ((uint64_t)up[5]<< 8) | - (uint64_t)up[6]) & ((1LL<<(1+6*8))-1); - return 7; - } else if (up[0] < 0xff) { - *val_p = (((uint64_t)up[1]<<48) | - ((uint64_t)up[2]<<40) | - ((uint64_t)up[3]<<32) | - ((uint64_t)up[4]<<24) | - ((uint64_t)up[5]<<16) | - ((uint64_t)up[6]<< 8) | - (uint64_t)up[7]) & ((1LL<<(7*8))-1); - return 8; - } else { - *val_p = (((uint64_t)up[1]<<56) | - ((uint64_t)up[2]<<48) | - ((uint64_t)up[3]<<40) | - ((uint64_t)up[4]<<32) | - ((uint64_t)up[5]<<24) | - ((uint64_t)up[6]<<16) | - ((uint64_t)up[7]<< 8) | - (uint64_t)up[8]); - return 9; - } -} + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + + 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, 9 +}; /* * LEGACY: consider using ltf8_decode_crc. @@ -722,7 +558,7 @@ char *zlib_mem_inflate(char *cdata, size_t csize, size_t *size) { //err = inflateInit(&s); err = inflateInit2(&s, 15 + 32); if (err != Z_OK) { - fprintf(stderr, "zlib inflateInit error: %s\n", s.msg); + hts_log_error("Call to zlib inflateInit failed: %s", s.msg); free(data); return NULL; } @@ -738,7 +574,7 @@ char *zlib_mem_inflate(char *cdata, size_t csize, size_t *size) { break; if (err != Z_OK) { - fprintf(stderr, "zlib inflate error: %s\n", s.msg); + hts_log_error("Call to zlib inflate failed: %s", s.msg); if (data) free(data); return NULL; @@ -786,7 +622,7 @@ static char *zlib_mem_deflate(char *data, size_t size, size_t *cdata_size, err = deflateInit2(&s, level, Z_DEFLATED, 15|16, 9, strat); if (err != Z_OK) { - fprintf(stderr, "zlib deflateInit2 error: %s\n", s.msg); + hts_log_error("Call to zlib deflateInit2 failed: %s", s.msg); return NULL; } @@ -795,23 +631,23 @@ static char *zlib_mem_deflate(char *data, size_t size, size_t *cdata_size, s.next_out = &cdata[cdata_pos]; s.avail_out = cdata_alloc - cdata_pos; if (cdata_alloc - cdata_pos <= 0) { - fprintf(stderr, "Deflate produced larger output than expected. Abort\n"); + hts_log_error("Deflate produced larger output than expected"); return NULL; } err = deflate(&s, Z_NO_FLUSH); cdata_pos = cdata_alloc - s.avail_out; if (err != Z_OK) { - fprintf(stderr, "zlib deflate error: %s\n", s.msg); + hts_log_error("Call to zlib deflate failed: %s", s.msg); break; } } if (deflate(&s, Z_FINISH) != Z_STREAM_END) { - fprintf(stderr, "zlib deflate error: %s\n", s.msg); + hts_log_error("Call to zlib deflate failed: %s", s.msg); } *cdata_size = s.total_out; if (deflateEnd(&s) != Z_OK) { - fprintf(stderr, "zlib deflate error: %s\n", s.msg); + hts_log_error("Call to zlib deflate failed: %s", s.msg); } return (char *)cdata; } @@ -856,7 +692,7 @@ static char *lzma_mem_inflate(char *cdata, size_t csize, size_t *size) { int r; /* Initiate the decoder */ - if (LZMA_OK != lzma_stream_decoder(&strm, 50000000, 0)) + if (LZMA_OK != lzma_stream_decoder(&strm, lzma_easy_decoder_memusage(9), 0)) return NULL; /* Decode loop */ @@ -873,8 +709,7 @@ static char *lzma_mem_inflate(char *cdata, size_t csize, size_t *size) { r = lzma_code(&strm, LZMA_RUN); if (LZMA_OK != r && LZMA_STREAM_END != r) { - fprintf(stderr, "r=%d\n", r); - fprintf(stderr, "mem=%"PRId64"d\n", (int64_t)lzma_memusage(&strm)); + hts_log_error("LZMA decode failure (error %d)", r); return NULL; } @@ -887,7 +722,7 @@ static char *lzma_mem_inflate(char *cdata, size_t csize, size_t *size) { /* finish up any unflushed data; necessary? */ r = lzma_code(&strm, LZMA_FINISH); if (r != LZMA_OK && r != LZMA_STREAM_END) { - fprintf(stderr, "r=%d\n", r); + hts_log_error("Call to lzma_code failed with error %d", r); return NULL; } @@ -955,10 +790,14 @@ cram_block *cram_read_block(cram_fd *fd) { if (-1 == itf8_decode_crc(fd, &b->comp_size, &crc)) { free(b); return NULL; } if (-1 == itf8_decode_crc(fd, &b->uncomp_size, &crc)) { free(b); return NULL; } - // fprintf(stderr, " method %d, ctype %d, cid %d, csize %d, ucsize %d\n", + //fprintf(stderr, " method %d, ctype %d, cid %d, csize %d, ucsize %d\n", // b->method, b->content_type, b->content_id, b->comp_size, b->uncomp_size); if (b->method == RAW) { + if (b->uncomp_size < 0 || b->comp_size != b->uncomp_size) { + free(b); + return NULL; + } b->alloc = b->uncomp_size; if (!(b->data = malloc(b->uncomp_size))){ free(b); return NULL; } if (b->uncomp_size != hread(fd->fp, b->data, b->uncomp_size)) { @@ -967,6 +806,7 @@ cram_block *cram_read_block(cram_fd *fd) { return NULL; } } else { + if (b->comp_size < 0) { free(b); return NULL; } b->alloc = b->comp_size; if (!(b->data = malloc(b->comp_size))) { free(b); return NULL; } if (b->comp_size != hread(fd->fp, b->data, b->comp_size)) { @@ -984,7 +824,7 @@ cram_block *cram_read_block(cram_fd *fd) { crc = crc32(crc, b->data ? b->data : (uc *)"", b->alloc); if (crc != b->crc32) { - fprintf(stderr, "Block CRC32 failure\n"); + hts_log_error("Block CRC32 failure"); free(b->data); free(b); return NULL; @@ -1010,9 +850,9 @@ uint32_t cram_block_size(cram_block *b) { *cp++ = b->method; *cp++ = b->content_type; - cp += itf8_put(cp, b->content_id); - cp += itf8_put(cp, b->comp_size); - cp += itf8_put(cp, b->uncomp_size); + cp += itf8_put((char*)cp, b->content_id); + cp += itf8_put((char*)cp, b->comp_size); + cp += itf8_put((char*)cp, b->uncomp_size); sz = cp-dat + 4; sz += b->method == RAW ? b->uncomp_size : b->comp_size; @@ -1034,12 +874,17 @@ int cram_write_block(cram_fd *fd, cram_block *b) { if (itf8_encode(fd, b->comp_size) == -1) return -1; if (itf8_encode(fd, b->uncomp_size) == -1) return -1; - if (b->method == RAW) { - if (b->uncomp_size != hwrite(fd->fp, b->data, b->uncomp_size)) - return -1; + if (b->data) { + if (b->method == RAW) { + if (b->uncomp_size != hwrite(fd->fp, b->data, b->uncomp_size)) + return -1; + } else { + if (b->comp_size != hwrite(fd->fp, b->data, b->comp_size)) + return -1; + } } else { - if (b->comp_size != hwrite(fd->fp, b->data, b->comp_size)) - return -1; + // Absent blocks should be size 0 + assert(b->method == RAW && b->uncomp_size == 0); } if (CRAM_MAJOR_VERS(fd->version) >= 3) { @@ -1048,9 +893,9 @@ int cram_write_block(cram_fd *fd, cram_block *b) { *cp++ = b->method; *cp++ = b->content_type; - cp += itf8_put(cp, b->content_id); - cp += itf8_put(cp, b->comp_size); - cp += itf8_put(cp, b->uncomp_size); + cp += itf8_put((char*)cp, b->content_id); + cp += itf8_put((char*)cp, b->comp_size); + cp += itf8_put((char*)cp, b->uncomp_size); crc = crc32(0L, dat, cp-dat); if (b->method == RAW) { @@ -1128,8 +973,7 @@ int cram_uncompress_block(cram_block *b) { } #else case BZIP2: - fprintf(stderr, "Bzip2 compression is not compiled into this " - "version.\nPlease rebuild and try again.\n"); + hts_log_error("Bzip2 compression is not compiled into this version. Please rebuild and try again"); return -1; #endif @@ -1147,8 +991,7 @@ int cram_uncompress_block(cram_block *b) { break; #else case LZMA: - fprintf(stderr, "Lzma compression is not compiled into this " - "version.\nPlease rebuild and try again.\n"); + hts_log_error("Lzma compression is not compiled into this version. Please rebuild and try again"); return -1; break; #endif @@ -1157,7 +1000,7 @@ int cram_uncompress_block(cram_block *b) { unsigned int usize = b->uncomp_size, usize2; uncomp = (char *)rans_uncompress(b->data, b->comp_size, &usize2); if (!uncomp || usize != usize2) - return -1; + return -1; free(b->data); b->data = (unsigned char *)uncomp; b->alloc = usize2; @@ -1301,7 +1144,7 @@ int cram_compress_block(cram_fd *fd, cram_block *b, cram_metrics *metrics, else metrics->revised_method = method; - if (metrics->next_trial == 0) { + if (metrics->next_trial <= 0) { metrics->next_trial = TRIAL_SPAN; metrics->trial = NTRIALS; metrics->sz_gz_rle /= 2; @@ -1566,7 +1409,7 @@ int cram_compress_block(cram_fd *fd, cram_block *b, cram_metrics *metrics, comp = cram_compress_by_method((char *)b->data, b->uncomp_size, &comp_size, GZIP, level, Z_FILTERED); if (!comp) { - fprintf(stderr, "Compression failed!\n"); + hts_log_error("Compression failed"); return -1; } free(b->data); @@ -1575,10 +1418,9 @@ int cram_compress_block(cram_fd *fd, cram_block *b, cram_metrics *metrics, b->method = GZIP; } - if (fd->verbose) - fprintf(stderr, "Compressed block ID %d from %d to %d by method %s\n", - b->content_id, b->uncomp_size, b->comp_size, - cram_block_method2str(b->method)); + hts_log_info("Compressed block ID %d from %d to %d by method %s", + b->content_id, b->uncomp_size, b->comp_size, + cram_block_method2str(b->method)); if (b->method == RANS1) b->method = RANS0; // Spec just has RANS (not 0/1) with auto-sensing @@ -1608,7 +1450,7 @@ char *cram_block_method2str(enum cram_block_method m) { case RANS0: return "RANS0"; case RANS1: return "RANS1"; case GZIP_RLE: return "GZIP_RLE"; - case ERROR: break; + case BM_ERROR: break; } return "?"; } @@ -1756,7 +1598,7 @@ static BGZF *bgzf_open_ref(char *fn, char *mode, int is_md5) { } if (fp->is_compressed == 1 && bgzf_index_load(fp, fn, ".gzi") < 0) { - fprintf(stderr, "Unable to load .gzi index '%s.gzi'\n", fn); + hts_log_error("Unable to load .gzi index '%s.gzi'", fn); bgzf_close(fp); return NULL; } @@ -1942,8 +1784,7 @@ static void sanitise_SQ_lines(cram_fd *fd) { // Should we also check MD5sums here to ensure the correct // reference was given? - fprintf(stderr, "WARNING: Header @SQ length mismatch for " - "ref %s, %d vs %d\n", + hts_log_warning("Header @SQ length mismatch for ref %s, %d vs %d", r->name, fd->header->ref[i].len, (int)r->length); // Fixing the parsed @SQ header will make MD:Z: strings work @@ -1978,8 +1819,7 @@ int refs2id(refs_t *r, SAM_hdr *h) { if (k != kh_end(r->h_meta)) { r->ref_id[i] = kh_val(r->h_meta, k); } else { - fprintf(stderr, "Unable to find ref name '%s'\n", - h->ref[i].name); + hts_log_warning("Unable to find ref name '%s'", h->ref[i].name); } } @@ -2187,8 +2027,7 @@ static int cram_populate_ref(cram_fd *fd, int id, ref_entry *r) { mFILE *mf; int local_path = 0; - if (fd->verbose) - fprintf(stderr, "cram_populate_ref on fd %p, id %d\n", fd, id); + hts_log_info("Running cram_populate_ref on fd %p, id %d", (void *)fd, id); cache_root[0] = '\0'; @@ -2204,8 +2043,7 @@ static int cram_populate_ref(cram_fd *fd, int id, ref_entry *r) { snprintf(cache_root, PATH_MAX, "%s%s/hts-ref", base, extra); snprintf(cache,PATH_MAX, "%s%s/hts-ref/%%2s/%%2s/%%s", base, extra); local_cache = cache; - if (fd->verbose) - fprintf(stderr, "Populating local cache: %s\n", local_cache); + hts_log_info("Populating local cache: %s", local_cache); } } @@ -2218,8 +2056,7 @@ static int cram_populate_ref(cram_fd *fd, int id, ref_entry *r) { if (!(tag = sam_hdr_find_key(fd->header, ty, "M5", NULL))) goto no_M5; - if (fd->verbose) - fprintf(stderr, "Querying ref %s\n", tag->str+3); + hts_log_info("Querying ref %s", tag->str+3); /* Use cache if available */ if (local_cache && *local_cache) { @@ -2319,19 +2156,18 @@ static int cram_populate_ref(cram_fd *fd, int id, ref_entry *r) { /* Populate the local disk cache if required */ if (local_cache && *local_cache) { - int pid = (int) getpid(); - unsigned thrid = get_int_threadid(); - hFILE *fp; - - if (*cache_root && !is_directory(cache_root) && hts_verbose >= 1) - fprintf(stderr, -"Creating reference cache directory %s\n" -"This may become large; see the samtools(1) manual page REF_CACHE discussion\n", - cache_root); + int pid = (int) getpid(); + unsigned thrid = get_int_threadid(); + hFILE *fp; + + if (*cache_root && !is_directory(cache_root)) { + hts_log_warning("Creating reference cache directory %s\n" + "This may become large; see the samtools(1) manual page REF_CACHE discussion", + cache_root); + } expand_cache_path(path, local_cache, tag->str+3); - if (fd->verbose) - fprintf(stderr, "Writing cache file '%s'\n", path); + hts_log_info("Writing cache file '%s'", path); mkdir_prefix(path, 01777); do { @@ -2365,7 +2201,7 @@ static int cram_populate_ref(cram_fd *fd, int id, ref_entry *r) { hts_md5_hex(md5_buf2, md5_buf1); if (strncmp(tag->str+3, md5_buf2, 32) != 0) { - fprintf(stderr, "[E::%s] mismatching md5sum for downloaded reference.\n", __func__); + hts_log_error("Mismatching md5sum for downloaded reference"); hclose_abruptly(fp); unlink(path_tmp); return -1; @@ -2390,7 +2226,7 @@ static int cram_populate_ref(cram_fd *fd, int id, ref_entry *r) { static void cram_ref_incr_locked(refs_t *r, int id) { RP("%d INC REF %d, %d %p\n", gettid(), id, (int)(id>=0?r->ref_id[id]->count+1:-999), id>=0?r->ref_id[id]->seq:(char *)1); - if (id < 0 || !r->ref_id[id]->seq) + if (id < 0 || !r->ref_id[id] || !r->ref_id[id]->seq) return; if (r->last_id == id) @@ -2408,7 +2244,7 @@ void cram_ref_incr(refs_t *r, int id) { static void cram_ref_decr_locked(refs_t *r, int id) { RP("%d DEC REF %d, %d %p\n", gettid(), id, (int)(id>=0?r->ref_id[id]->count-1:-999), id>=0?r->ref_id[id]->seq:(char *)1); - if (id < 0 || !r->ref_id[id]->seq) { + if (id < 0 || !r->ref_id[id] || !r->ref_id[id]->seq) { assert(r->ref_id[id]->count >= 0); return; } @@ -2492,7 +2328,7 @@ static char *load_ref_portion(BGZF *fp, ref_entry *e, int start, int end) { cp_to = cp+j; if (cp_to - seq != end-start+1) { - fprintf(stderr, "Malformed reference file?\n"); + hts_log_error("Malformed reference file"); free(seq); return NULL; } @@ -2625,19 +2461,19 @@ char *cram_get_ref(cram_fd *fd, int id, int start, int end) { /* Sanity checking: does this ID exist? */ if (id >= fd->refs->nref) { - fprintf(stderr, "No reference found for id %d\n", id); + hts_log_error("No reference found for id %d", id); pthread_mutex_unlock(&fd->ref_lock); return NULL; } if (!fd->refs || !fd->refs->ref_id[id]) { - fprintf(stderr, "No reference found for id %d\n", id); + hts_log_error("No reference found for id %d", id); pthread_mutex_unlock(&fd->ref_lock); return NULL; } if (!(r = fd->refs->ref_id[id])) { - fprintf(stderr, "No reference found for id %d\n", id); + hts_log_error("No reference found for id %d", id); pthread_mutex_unlock(&fd->ref_lock); return NULL; } @@ -2657,7 +2493,7 @@ char *cram_get_ref(cram_fd *fd, int id, int start, int end) { pthread_mutex_lock(&fd->refs->lock); if (r->length == 0) { if (cram_populate_ref(fd, id, r) == -1) { - fprintf(stderr, "Failed to populate reference for id %d\n", id); + hts_log_error("Failed to populate reference for id %d", id); pthread_mutex_unlock(&fd->refs->lock); pthread_mutex_unlock(&fd->ref_lock); return NULL; @@ -2677,7 +2513,8 @@ char *cram_get_ref(cram_fd *fd, int id, int start, int end) { end = r->length; if (end >= r->length) end = r->length; - assert(start >= 1); + if (start < 1) + return NULL; if (end - start >= 0.5*r->length || fd->shared_ref) { start = 1; @@ -2846,6 +2683,7 @@ cram_container *cram_new_container(int nrec, int nslice) { c->max_rec = nrec; c->record_counter = 0; c->num_bases = 0; + c->s_num_bases = 0; c->max_slice = nslice; c->curr_slice = 0; @@ -2869,7 +2707,7 @@ cram_container *cram_new_container(int nrec, int nslice) { //c->aux_B_stats = cram_stats_create(); - if (!(c->tags_used = kh_init(s_i2i))) + if (!(c->tags_used = kh_init(m_tagmap))) goto err; c->refs_used = 0; @@ -2915,7 +2753,22 @@ void cram_free_container(cram_container *c) { //if (c->aux_B_stats) cram_stats_free(c->aux_B_stats); - if (c->tags_used) kh_destroy(s_i2i, c->tags_used); + if (c->tags_used) { + khint_t k; + + for (k = kh_begin(c->tags_used); k != kh_end(c->tags_used); k++) { + if (!kh_exist(c->tags_used, k)) + continue; + + cram_tag_map *tm = (cram_tag_map *)kh_val(c->tags_used, k); + cram_codec *c = tm->codec; + + if (c) c->free(c); + free(tm); + } + + kh_destroy(m_tagmap, c->tags_used); + } free(c); } @@ -2989,6 +2842,9 @@ cram_container *cram_read_container(cram_fd *fd) { if ((s = itf8_decode_crc(fd, &c2.num_blocks, &crc)) == -1) return NULL; else rd+=s; if ((s = itf8_decode_crc(fd, &c2.num_landmarks, &crc))== -1) return NULL; else rd+=s; + if (c2.num_landmarks < 0 || c2.num_landmarks >= SIZE_MAX / sizeof(int32_t)) + return NULL; + if (!(c = calloc(1, sizeof(*c)))) return NULL; @@ -3016,7 +2872,7 @@ cram_container *cram_read_container(cram_fd *fd) { rd+=4; if (crc != c->crc32) { - fprintf(stderr, "Container header CRC32 failure\n"); + hts_log_error("Container header CRC32 failure"); cram_free_container(c); return NULL; } @@ -3060,7 +2916,7 @@ int cram_container_size(cram_container *c) { */ int cram_store_container(cram_fd *fd, cram_container *c, char *dat, int *size) { - char *cp = dat; + unsigned char *cp = (unsigned char *)dat; int i; // Check the input buffer is large enough according to our stated @@ -3069,36 +2925,36 @@ int cram_store_container(cram_fd *fd, cram_container *c, char *dat, int *size) return -1; if (CRAM_MAJOR_VERS(fd->version) == 1) { - cp += itf8_put(cp, c->length); + cp += itf8_put((char*)cp, c->length); } else { *(int32_t *)cp = le_int4(c->length); cp += 4; } if (c->multi_seq) { - cp += itf8_put(cp, -2); - cp += itf8_put(cp, 0); - cp += itf8_put(cp, 0); + cp += itf8_put((char*)cp, -2); + cp += itf8_put((char*)cp, 0); + cp += itf8_put((char*)cp, 0); } else { - cp += itf8_put(cp, c->ref_seq_id); - cp += itf8_put(cp, c->ref_seq_start); - cp += itf8_put(cp, c->ref_seq_span); + cp += itf8_put((char*)cp, c->ref_seq_id); + cp += itf8_put((char*)cp, c->ref_seq_start); + cp += itf8_put((char*)cp, c->ref_seq_span); } - cp += itf8_put(cp, c->num_records); + cp += itf8_put((char*)cp, c->num_records); if (CRAM_MAJOR_VERS(fd->version) == 2) { - cp += itf8_put(cp, c->record_counter); - cp += ltf8_put(cp, c->num_bases); + cp += itf8_put((char*)cp, c->record_counter); + cp += ltf8_put((char*)cp, c->num_bases); } else if (CRAM_MAJOR_VERS(fd->version) >= 3) { - cp += ltf8_put(cp, c->record_counter); - cp += ltf8_put(cp, c->num_bases); + cp += ltf8_put((char*)cp, c->record_counter); + cp += ltf8_put((char*)cp, c->num_bases); } - cp += itf8_put(cp, c->num_blocks); - cp += itf8_put(cp, c->num_landmarks); + cp += itf8_put((char*)cp, c->num_blocks); + cp += itf8_put((char*)cp, c->num_landmarks); for (i = 0; i < c->num_landmarks; i++) - cp += itf8_put(cp, c->landmark[i]); + cp += itf8_put((char*)cp, c->landmark[i]); if (CRAM_MAJOR_VERS(fd->version) >= 3) { - c->crc32 = crc32(0L, (uc *)dat, cp-dat); + c->crc32 = crc32(0L, (uc *)dat, (char*)cp-dat); cp[0] = c->crc32 & 0xff; cp[1] = (c->crc32 >> 8) & 0xff; cp[2] = (c->crc32 >> 16) & 0xff; @@ -3106,7 +2962,7 @@ int cram_store_container(cram_fd *fd, cram_container *c, char *dat, int *size) cp += 4; } - *size = cp-dat; // actual used size + *size = (char *)cp-dat; // actual used size return 0; } @@ -3119,44 +2975,45 @@ int cram_store_container(cram_fd *fd, cram_container *c, char *dat, int *size) * -1 on failure */ int cram_write_container(cram_fd *fd, cram_container *c) { - char buf_a[1024], *buf = buf_a, *cp; + char buf_a[1024], *buf = buf_a; + unsigned char *cp; int i; if (55 + c->num_landmarks * 5 >= 1024) buf = malloc(55 + c->num_landmarks * 5); - cp = buf; + cp = (unsigned char *)buf; if (CRAM_MAJOR_VERS(fd->version) == 1) { - cp += itf8_put(cp, c->length); + cp += itf8_put((char*)cp, c->length); } else { *(int32_t *)cp = le_int4(c->length); cp += 4; } if (c->multi_seq) { - cp += itf8_put(cp, -2); - cp += itf8_put(cp, 0); - cp += itf8_put(cp, 0); + cp += itf8_put((char*)cp, -2); + cp += itf8_put((char*)cp, 0); + cp += itf8_put((char*)cp, 0); } else { - cp += itf8_put(cp, c->ref_seq_id); - cp += itf8_put(cp, c->ref_seq_start); - cp += itf8_put(cp, c->ref_seq_span); + cp += itf8_put((char*)cp, c->ref_seq_id); + cp += itf8_put((char*)cp, c->ref_seq_start); + cp += itf8_put((char*)cp, c->ref_seq_span); } - cp += itf8_put(cp, c->num_records); + cp += itf8_put((char*)cp, c->num_records); if (CRAM_MAJOR_VERS(fd->version) == 2) { - cp += itf8_put(cp, c->record_counter); - cp += ltf8_put(cp, c->num_bases); + cp += itf8_put((char*)cp, c->record_counter); + cp += ltf8_put((char*)cp, c->num_bases); } else if (CRAM_MAJOR_VERS(fd->version) >= 3) { - cp += ltf8_put(cp, c->record_counter); - cp += ltf8_put(cp, c->num_bases); + cp += ltf8_put((char*)cp, c->record_counter); + cp += ltf8_put((char*)cp, c->num_bases); } - cp += itf8_put(cp, c->num_blocks); - cp += itf8_put(cp, c->num_landmarks); + cp += itf8_put((char*)cp, c->num_blocks); + cp += itf8_put((char*)cp, c->num_landmarks); for (i = 0; i < c->num_landmarks; i++) - cp += itf8_put(cp, c->landmark[i]); + cp += itf8_put((char*)cp, c->landmark[i]); if (CRAM_MAJOR_VERS(fd->version) >= 3) { - c->crc32 = crc32(0L, (uc *)buf, cp-buf); + c->crc32 = crc32(0L, (uc *)buf, (char*)cp-buf); cp[0] = c->crc32 & 0xff; cp[1] = (c->crc32 >> 8) & 0xff; cp[2] = (c->crc32 >> 16) & 0xff; @@ -3164,7 +3021,7 @@ int cram_write_container(cram_fd *fd, cram_container *c) { cp += 4; } - if (cp-buf != hwrite(fd->fp, buf, cp-buf)) { + if ((char*)cp-buf != hwrite(fd->fp, buf, (char*)cp-buf)) { if (buf != buf_a) free(buf); return -1; @@ -3235,7 +3092,7 @@ void *cram_flush_thread(void *arg) { /* Encode the container blocks and generate compression header */ if (0 != cram_encode_container(j->fd, j->c)) { - fprintf(stderr, "cram_encode_container failed\n"); + hts_log_error("Call to cram_encode_container failed"); return NULL; } @@ -3258,13 +3115,16 @@ static int cram_flush_result(cram_fd *fd) { fd = j->fd; c = j->c; - if (0 != cram_flush_container2(fd, c)) - return -1; + if (fd->mode == 'w') + if (0 != cram_flush_container2(fd, c)) + return -1; /* Free the container */ for (i = 0; i < c->max_slice; i++) { - cram_free_slice(c->slices[i]); - c->slices[i] = NULL; + if (c->slices && c->slices[i]) { + cram_free_slice(c->slices[i]); + c->slices[i] = NULL; + } } c->slice = NULL; @@ -3444,24 +3304,6 @@ void cram_free_slice(cram_slice *s) { if (s->aux_blk) cram_free_block(s->aux_blk); - if (s->aux_OQ_blk) - cram_free_block(s->aux_OQ_blk); - - if (s->aux_BQ_blk) - cram_free_block(s->aux_BQ_blk); - - if (s->aux_FZ_blk) - cram_free_block(s->aux_FZ_blk); - - if (s->aux_oq_blk) - cram_free_block(s->aux_oq_blk); - - if (s->aux_os_blk) - cram_free_block(s->aux_os_blk); - - if (s->aux_oz_blk) - cram_free_block(s->aux_oz_blk); - if (s->base_blk) cram_free_block(s->base_blk); @@ -3488,6 +3330,9 @@ void cram_free_slice(cram_slice *s) { if (s->pair[1]) kh_destroy(m_s2i, s->pair[1]); + if (s->aux_block) + free(s->aux_block); + free(s); } @@ -3577,13 +3422,13 @@ cram_slice *cram_read_slice(cram_fd *fd) { break; default: - fprintf(stderr, "Unexpected block of type %s\n", + hts_log_error("Unexpected block of type %s", cram_content_type2str(b->content_type)); goto err; } if (s->hdr->num_blocks < 1) { - fprintf(stderr, "Slice does not include any data blocks.\n"); + hts_log_error("Slice does not include any data blocks"); goto err; } @@ -3667,8 +3512,7 @@ cram_file_def *cram_read_file_def(cram_fd *fd) { } if (def->major_version > 3) { - fprintf(stderr, "CRAM version number mismatch\n" - "Expected 1.x, 2.x or 3.x, got %d.%d\n", + hts_log_error("CRAM version number mismatch. Expected 1.x, 2.x or 3.x, got %d.%d", def->major_version, def->minor_version); free(def); return NULL; @@ -3729,11 +3573,14 @@ SAM_hdr *cram_read_SAM_hdr(cram_fd *fd) { } else { cram_container *c = cram_read_container(fd); cram_block *b; - int i, len; + int i; + int64_t len; if (!c) return NULL; + fd->first_container += c->length + c->offset; + if (c->num_blocks < 1) { cram_free_container(c); return NULL; @@ -3745,6 +3592,7 @@ SAM_hdr *cram_read_SAM_hdr(cram_fd *fd) { } if (cram_uncompress_block(b) != 0) { cram_free_container(c); + cram_free_block(b); return NULL; } @@ -3767,7 +3615,7 @@ SAM_hdr *cram_read_SAM_hdr(cram_fd *fd) { return NULL; } memcpy(header, BLOCK_END(b), header_len); - header[header_len]='\0'; + header[header_len] = '\0'; cram_free_block(b); /* Consume any remaining blocks */ @@ -3813,7 +3661,11 @@ SAM_hdr *cram_read_SAM_hdr(cram_fd *fd) { * Out must be at least PATH_MAX bytes long. */ static void full_path(char *out, char *in) { - if (*in == '/') { + size_t in_l = strlen(in); + if (*in == '/' || + // Windows paths + (in_l > 3 && toupper(*in) >= 'A' && toupper(*in) <= 'Z' && + in[1] == ':' && (in[2] == '/' || in[2] == '\\'))) { strncpy(out, in, PATH_MAX); out[PATH_MAX-1] = 0; } else { @@ -3931,7 +3783,8 @@ int cram_write_SAM_hdr(cram_fd *fd, SAM_hdr *hdr) { } int32_put_blk(b, header_len); - BLOCK_APPEND(b, sam_hdr_str(hdr), header_len); + if (header_len) + BLOCK_APPEND(b, sam_hdr_str(hdr), header_len); BLOCK_UPLEN(b); // Compress header block if V3.0 and above @@ -4179,8 +4032,10 @@ cram_fd *cram_dopen(hFILE *fp, const char *filename, const char *mode) { fd->version = fd->file_def->major_version * 256 + fd->file_def->minor_version; - if (!(fd->header = cram_read_SAM_hdr(fd))) + if (!(fd->header = cram_read_SAM_hdr(fd))) { + cram_free_file_def(fd->file_def); goto err; + } } else { /* Writer */ @@ -4220,8 +4075,8 @@ cram_fd *cram_dopen(hFILE *fp, const char *filename, const char *mode) { fd->ref = NULL; fd->decode_md = 0; - fd->verbose = 0; fd->seqs_per_slice = SEQS_PER_SLICE; + fd->bases_per_slice = BASES_PER_SLICE; fd->slices_per_container = SLICE_PER_CNT; fd->embed_ref = 0; fd->no_ref = 0; @@ -4245,6 +4100,9 @@ cram_fd *cram_dopen(hFILE *fp, const char *filename, const char *mode) { for (i = 0; i < DS_END; i++) fd->m[i] = cram_new_metrics(); + if (!(fd->tags_used = kh_init(m_metrics))) + goto err; + fd->range.refid = -2; // no ref. fd->eof = 1; // See samtools issue #150 fd->ref_fn = NULL; @@ -4275,8 +4133,9 @@ int cram_seek(cram_fd *fd, off_t offset, int whence) { fd->ooc = 0; - if (hseek(fd->fp, offset, whence) >= 0) - return 0; + if (hseek(fd->fp, offset, whence) >= 0) { + return 0; + } if (!(whence == SEEK_CUR && offset >= 0)) return -1; @@ -4409,6 +4268,17 @@ int cram_close(cram_fd *fd) { if (fd->m[i]) free(fd->m[i]); + if (fd->tags_used) { + khint_t k; + + for (k = kh_begin(fd->tags_used); k != kh_end(fd->tags_used); k++) { + if (kh_exist(fd->tags_used, k)) + free(kh_val(fd->tags_used, k)); + } + + kh_destroy(m_metrics, fd->tags_used); + } + if (fd->index) cram_index_free(fd); @@ -4473,13 +4343,16 @@ int cram_set_voption(cram_fd *fd, enum hts_fmt_option opt, va_list args) { break; case CRAM_OPT_VERBOSITY: - fd->verbose = va_arg(args, int); break; case CRAM_OPT_SEQS_PER_SLICE: fd->seqs_per_slice = va_arg(args, int); break; + case CRAM_OPT_BASES_PER_SLICE: + fd->bases_per_slice = va_arg(args, int); + break; + case CRAM_OPT_SLICES_PER_CONTAINER: fd->slices_per_container = va_arg(args, int); break; @@ -4498,6 +4371,12 @@ int cram_set_voption(cram_fd *fd, enum hts_fmt_option opt, va_list args) { case CRAM_OPT_LOSSY_NAMES: fd->lossy_read_names = va_arg(args, int); + // Currently lossy read names required paired (attached) reads. + // TLEN 0 or being 1 out causes read pairs to be detached, breaking + // the lossy read name compression, so we have extra options to + // slacken the exact TLEN round-trip checks. + fd->tlen_approx = fd->lossy_read_names; + fd->tlen_zero = fd->lossy_read_names; break; case CRAM_OPT_USE_BZIP2: @@ -4534,14 +4413,13 @@ int cram_set_voption(cram_fd *fd, enum hts_fmt_option opt, va_list args) { int major, minor; char *s = va_arg(args, char *); if (2 != sscanf(s, "%d.%d", &major, &minor)) { - fprintf(stderr, "Malformed version string %s\n", s); + hts_log_error("Malformed version string %s", s); return -1; } if (!((major == 1 && minor == 0) || (major == 2 && (minor == 0 || minor == 1)) || (major == 3 && minor == 0))) { - fprintf(stderr, "Unknown version string; " - "use 1.0, 2.0, 2.1 or 3.0\n"); + hts_log_error("Unknown version string; use 1.0, 2.0, 2.1 or 3.0"); errno = EINVAL; return -1; } @@ -4558,7 +4436,7 @@ int cram_set_voption(cram_fd *fd, enum hts_fmt_option opt, va_list args) { case CRAM_OPT_NTHREADS: { int nthreads = va_arg(args, int); - if (nthreads > 1) { + if (nthreads >= 1) { if (!(fd->pool = hts_tpool_init(nthreads))) return -1; @@ -4601,7 +4479,7 @@ int cram_set_voption(cram_fd *fd, enum hts_fmt_option opt, va_list args) { break; default: - fprintf(stderr, "Unknown CRAM option code %d\n", opt); + hts_log_error("Unknown CRAM option code %d", opt); errno = EINVAL; return -1; } diff --git a/htslib/cram/cram_io.h b/htslib/cram/cram_io.h index d3fe90e34..e294255ea 100644 --- a/htslib/cram/cram_io.h +++ b/htslib/cram/cram_io.h @@ -42,8 +42,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef _CRAM_IO_H_ #define _CRAM_IO_H_ -#define ITF8_MACROS - #include #include @@ -69,43 +67,207 @@ extern "C" { */ int itf8_decode(cram_fd *fd, int32_t *val); -#ifndef ITF8_MACROS -/*! Reads an integer in ITF-8 encoding from 'cp' and stores it in - * *val. - * - * @return - * Returns the number of bytes read on success; - * -1 on failure - */ -int itf8_get(char *cp, int32_t *val_p); +static inline int itf8_get(char *cp, int32_t *val_p) { + unsigned char *up = (unsigned char *)cp; + + if (up[0] < 0x80) { + *val_p = up[0]; + return 1; + } else if (up[0] < 0xc0) { + *val_p = ((up[0] <<8) | up[1]) & 0x3fff; + return 2; + } else if (up[0] < 0xe0) { + *val_p = ((up[0]<<16) | (up[1]<< 8) | up[2]) & 0x1fffff; + return 3; + } else if (up[0] < 0xf0) { + *val_p = ((up[0]<<24) | (up[1]<<16) | (up[2]<<8) | up[3]) & 0x0fffffff; + return 4; + } else { + *val_p = ((up[0] & 0x0f)<<28) | (up[1]<<20) | (up[2]<<12) | (up[3]<<4) | (up[4] & 0x0f); + return 5; + } +} -/*! Stores a value to memory in ITF-8 format. +/* + * Stores a value to memory in ITF-8 format. * - * @return * Returns the number of bytes required to store the number. * This is a maximum of 5 bytes. */ -int itf8_put(char *cp, int32_t val); +static inline int itf8_put(char *cp, int32_t val) { + unsigned char *up = (unsigned char *)cp; + if (!(val & ~0x00000007f)) { // 1 byte + *up = val; + return 1; + } else if (!(val & ~0x00003fff)) { // 2 byte + *up++ = (val >> 8 ) | 0x80; + *up = val & 0xff; + return 2; + } else if (!(val & ~0x01fffff)) { // 3 byte + *up++ = (val >> 16) | 0xc0; + *up++ = (val >> 8 ) & 0xff; + *up = val & 0xff; + return 3; + } else if (!(val & ~0x0fffffff)) { // 4 byte + *up++ = (val >> 24) | 0xe0; + *up++ = (val >> 16) & 0xff; + *up++ = (val >> 8 ) & 0xff; + *up = val & 0xff; + return 4; + } else { // 5 byte + *up++ = 0xf0 | ((val>>28) & 0xff); + *up++ = (val >> 20) & 0xff; + *up++ = (val >> 12) & 0xff; + *up++ = (val >> 4 ) & 0xff; + *up = val & 0x0f; + return 5; + } +} -#else -/* - * Macro implementations of the above - */ -#define itf8_get(c,v) (((uc)(c)[0]<0x80)?(*(v)=(uc)(c)[0],1):(((uc)(c)[0]<0xc0)?(*(v)=(((uc)(c)[0]<<8)|(uc)(c)[1])&0x3fff,2):(((uc)(c)[0]<0xe0)?(*(v)=(((uc)(c)[0]<<16)|((uc)(c)[1]<<8)|(uc)(c)[2])&0x1fffff,3):(((uc)(c)[0]<0xf0)?(*(v)=(((uc)(c)[0]<<24)|((uc)(c)[1]<<16)|((uc)(c)[2]<<8)|(uc)(c)[3])&0x0fffffff,4):(*(v)=(((uc)(c)[0]&0x0f)<<28)|((uc)(c)[1]<<20)|((uc)(c)[2]<<12)|((uc)(c)[3]<<4)|((uc)(c)[4]&0x0f),5))))) +/* 64-bit itf8 variant */ +static inline int ltf8_put(char *cp, int64_t val) { + unsigned char *up = (unsigned char *)cp; + if (!(val & ~((1LL<<7)-1))) { + *up = val; + return 1; + } else if (!(val & ~((1LL<<(6+8))-1))) { + *up++ = (val >> 8 ) | 0x80; + *up = val & 0xff; + return 2; + } else if (!(val & ~((1LL<<(5+2*8))-1))) { + *up++ = (val >> 16) | 0xc0; + *up++ = (val >> 8 ) & 0xff; + *up = val & 0xff; + return 3; + } else if (!(val & ~((1LL<<(4+3*8))-1))) { + *up++ = (val >> 24) | 0xe0; + *up++ = (val >> 16) & 0xff; + *up++ = (val >> 8 ) & 0xff; + *up = val & 0xff; + return 4; + } else if (!(val & ~((1LL<<(3+4*8))-1))) { + *up++ = (val >> 32) | 0xf0; + *up++ = (val >> 24) & 0xff; + *up++ = (val >> 16) & 0xff; + *up++ = (val >> 8 ) & 0xff; + *up = val & 0xff; + return 5; + } else if (!(val & ~((1LL<<(2+5*8))-1))) { + *up++ = (val >> 40) | 0xf8; + *up++ = (val >> 32) & 0xff; + *up++ = (val >> 24) & 0xff; + *up++ = (val >> 16) & 0xff; + *up++ = (val >> 8 ) & 0xff; + *up = val & 0xff; + return 6; + } else if (!(val & ~((1LL<<(1+6*8))-1))) { + *up++ = (val >> 48) | 0xfc; + *up++ = (val >> 40) & 0xff; + *up++ = (val >> 32) & 0xff; + *up++ = (val >> 24) & 0xff; + *up++ = (val >> 16) & 0xff; + *up++ = (val >> 8 ) & 0xff; + *up = val & 0xff; + return 7; + } else if (!(val & ~((1LL<<(7*8))-1))) { + *up++ = (val >> 56) | 0xfe; + *up++ = (val >> 48) & 0xff; + *up++ = (val >> 40) & 0xff; + *up++ = (val >> 32) & 0xff; + *up++ = (val >> 24) & 0xff; + *up++ = (val >> 16) & 0xff; + *up++ = (val >> 8 ) & 0xff; + *up = val & 0xff; + return 8; + } else { + *up++ = 0xff; + *up++ = (val >> 56) & 0xff; + *up++ = (val >> 48) & 0xff; + *up++ = (val >> 40) & 0xff; + *up++ = (val >> 32) & 0xff; + *up++ = (val >> 24) & 0xff; + *up++ = (val >> 16) & 0xff; + *up++ = (val >> 8 ) & 0xff; + *up = val & 0xff; + return 9; + } +} -#define itf8_put(c,v) ((!((v)&~0x7f))?((c)[0]=(v),1):(!((v)&~0x3fff))?((c)[0]=((v)>>8)|0x80,(c)[1]=(v)&0xff,2):(!((v)&~0x1fffff))?((c)[0]=((v)>>16)|0xc0,(c)[1]=((v)>>8)&0xff,(c)[2]=(v)&0xff,3):(!((v)&~0xfffffff))?((c)[0]=((v)>>24)|0xe0,(c)[1]=((v)>>16)&0xff,(c)[2]=((v)>>8)&0xff,(c)[3]=(v)&0xff,4):((c)[0]=0xf0|(((v)>>28)&0xff),(c)[1]=((v)>>20)&0xff,(c)[2]=((v)>>12)&0xff,(c)[3]=((v)>>4)&0xff,(c)[4]=(v)&0xf,5)) +static inline int ltf8_get(char *cp, int64_t *val_p) { + unsigned char *up = (unsigned char *)cp; + + if (up[0] < 0x80) { + *val_p = up[0]; + return 1; + } else if (up[0] < 0xc0) { + *val_p = (((uint64_t)up[0]<< 8) | + (uint64_t)up[1]) & (((1LL<<(6+8)))-1); + return 2; + } else if (up[0] < 0xe0) { + *val_p = (((uint64_t)up[0]<<16) | + ((uint64_t)up[1]<< 8) | + (uint64_t)up[2]) & ((1LL<<(5+2*8))-1); + return 3; + } else if (up[0] < 0xf0) { + *val_p = (((uint64_t)up[0]<<24) | + ((uint64_t)up[1]<<16) | + ((uint64_t)up[2]<< 8) | + (uint64_t)up[3]) & ((1LL<<(4+3*8))-1); + return 4; + } else if (up[0] < 0xf8) { + *val_p = (((uint64_t)up[0]<<32) | + ((uint64_t)up[1]<<24) | + ((uint64_t)up[2]<<16) | + ((uint64_t)up[3]<< 8) | + (uint64_t)up[4]) & ((1LL<<(3+4*8))-1); + return 5; + } else if (up[0] < 0xfc) { + *val_p = (((uint64_t)up[0]<<40) | + ((uint64_t)up[1]<<32) | + ((uint64_t)up[2]<<24) | + ((uint64_t)up[3]<<16) | + ((uint64_t)up[4]<< 8) | + (uint64_t)up[5]) & ((1LL<<(2+5*8))-1); + return 6; + } else if (up[0] < 0xfe) { + *val_p = (((uint64_t)up[0]<<48) | + ((uint64_t)up[1]<<40) | + ((uint64_t)up[2]<<32) | + ((uint64_t)up[3]<<24) | + ((uint64_t)up[4]<<16) | + ((uint64_t)up[5]<< 8) | + (uint64_t)up[6]) & ((1LL<<(1+6*8))-1); + return 7; + } else if (up[0] < 0xff) { + *val_p = (((uint64_t)up[1]<<48) | + ((uint64_t)up[2]<<40) | + ((uint64_t)up[3]<<32) | + ((uint64_t)up[4]<<24) | + ((uint64_t)up[5]<<16) | + ((uint64_t)up[6]<< 8) | + (uint64_t)up[7]) & ((1LL<<(7*8))-1); + return 8; + } else { + *val_p = (((uint64_t)up[1]<<56) | + ((uint64_t)up[2]<<48) | + ((uint64_t)up[3]<<40) | + ((uint64_t)up[4]<<32) | + ((uint64_t)up[5]<<24) | + ((uint64_t)up[6]<<16) | + ((uint64_t)up[7]<< 8) | + (uint64_t)up[8]); + return 9; + } +} #define itf8_size(v) ((!((v)&~0x7f))?1:(!((v)&~0x3fff))?2:(!((v)&~0x1fffff))?3:(!((v)&~0xfffffff))?4:5) -#endif - -int ltf8_get(char *cp, int64_t *val_p); -int ltf8_put(char *cp, int64_t val); - /* Version of itf8_get that checks it hasn't run out of input */ +/* Version of itf8_get that checks it hasn't run out of input */ extern const int itf8_bytes[16]; +extern const int ltf8_bytes[256]; static inline int safe_itf8_get(const char *cp, const char *endp, int32_t *val_p) { @@ -127,14 +289,86 @@ static inline int safe_itf8_get(const char *cp, const char *endp, *val_p = ((up[0]<<16) | (up[1]<< 8) | up[2]) & 0x1fffff; return 3; } else if (up[0] < 0xf0) { - *val_p = ((up[0]<<24) | (up[1]<<16) | (up[2]<<8) | up[3]) & 0x0fffffff; + *val_p = (((uint32_t)up[0]<<24) | (up[1]<<16) | (up[2]<<8) | up[3]) & 0x0fffffff; return 4; } else { - *val_p = ((up[0] & 0x0f)<<28) | (up[1]<<20) | (up[2]<<12) | (up[3]<<4) | (up[4] & 0x0f); + uint32_t uv = (((uint32_t)up[0] & 0x0f)<<28) | (up[1]<<20) | (up[2]<<12) | (up[3]<<4) | (up[4] & 0x0f); + *val_p = uv < 0x80000000UL ? uv : -((int32_t) (0xffffffffUL - uv)) - 1; return 5; } } +static inline int safe_ltf8_get(const char *cp, const char *endp, + int64_t *val_p) { + unsigned char *up = (unsigned char *)cp; + + if (endp - cp < 9 && + (cp >= endp || endp - cp < ltf8_bytes[up[0]])) return 0; + + if (up[0] < 0x80) { + *val_p = up[0]; + return 1; + } else if (up[0] < 0xc0) { + *val_p = (((uint64_t)up[0]<< 8) | + (uint64_t)up[1]) & (((1LL<<(6+8)))-1); + return 2; + } else if (up[0] < 0xe0) { + *val_p = (((uint64_t)up[0]<<16) | + ((uint64_t)up[1]<< 8) | + (uint64_t)up[2]) & ((1LL<<(5+2*8))-1); + return 3; + } else if (up[0] < 0xf0) { + *val_p = (((uint64_t)up[0]<<24) | + ((uint64_t)up[1]<<16) | + ((uint64_t)up[2]<< 8) | + (uint64_t)up[3]) & ((1LL<<(4+3*8))-1); + return 4; + } else if (up[0] < 0xf8) { + *val_p = (((uint64_t)up[0]<<32) | + ((uint64_t)up[1]<<24) | + ((uint64_t)up[2]<<16) | + ((uint64_t)up[3]<< 8) | + (uint64_t)up[4]) & ((1LL<<(3+4*8))-1); + return 5; + } else if (up[0] < 0xfc) { + *val_p = (((uint64_t)up[0]<<40) | + ((uint64_t)up[1]<<32) | + ((uint64_t)up[2]<<24) | + ((uint64_t)up[3]<<16) | + ((uint64_t)up[4]<< 8) | + (uint64_t)up[5]) & ((1LL<<(2+5*8))-1); + return 6; + } else if (up[0] < 0xfe) { + *val_p = (((uint64_t)up[0]<<48) | + ((uint64_t)up[1]<<40) | + ((uint64_t)up[2]<<32) | + ((uint64_t)up[3]<<24) | + ((uint64_t)up[4]<<16) | + ((uint64_t)up[5]<< 8) | + (uint64_t)up[6]) & ((1LL<<(1+6*8))-1); + return 7; + } else if (up[0] < 0xff) { + *val_p = (((uint64_t)up[1]<<48) | + ((uint64_t)up[2]<<40) | + ((uint64_t)up[3]<<32) | + ((uint64_t)up[4]<<24) | + ((uint64_t)up[5]<<16) | + ((uint64_t)up[6]<< 8) | + (uint64_t)up[7]) & ((1LL<<(7*8))-1); + return 8; + } else { + *val_p = (((uint64_t)up[1]<<56) | + ((uint64_t)up[2]<<48) | + ((uint64_t)up[3]<<40) | + ((uint64_t)up[4]<<32) | + ((uint64_t)up[5]<<24) | + ((uint64_t)up[6]<<16) | + ((uint64_t)up[7]<< 8) | + (uint64_t)up[8]); + return 9; + } +} + /*! Pushes a value in ITF8 format onto the end of a block. * * This shouldn't be used for high-volume data as it is not the fastest @@ -608,6 +842,8 @@ int cram_close(cram_fd *fd); */ int cram_seek(cram_fd *fd, off_t offset, int whence); +int64_t cram_tell(cram_fd *fd); + /* * Flushes a CRAM file. * Useful for when writing to stdout without wishing to close the stream. @@ -661,6 +897,12 @@ int cram_set_voption(cram_fd *fd, enum hts_fmt_option opt, va_list args); */ int cram_set_header(cram_fd *fd, SAM_hdr *hdr); +/*! + * Returns the hFILE connected to a cram_fd. + */ +static inline struct hFILE *cram_hfile(cram_fd *fd) { + return fd->fp; +} #ifdef __cplusplus } diff --git a/htslib/cram/cram_samtools.c b/htslib/cram/cram_samtools.c index 60a7b5fed..a8a2f8d78 100644 --- a/htslib/cram/cram_samtools.c +++ b/htslib/cram/cram_samtools.c @@ -74,11 +74,14 @@ int bam_construct_seq(bam_seq_t **bp, size_t extra_len, }; bam1_t *b = (bam1_t *)*bp; uint8_t *cp; - int i, bam_len; + int i, qname_nuls, bam_len; //b->l_aux = extra_len; // we fill this out later - bam_len = qname_len + 1 + ncigar*4 + (len+1)/2 + len + extra_len; + qname_nuls = 4 - qname_len%4; + if (qname_len + qname_nuls > 255) // Check for core.l_qname overflow + return -1; + bam_len = qname_len + qname_nuls + ncigar*4 + (len+1)/2 + len + extra_len; if (b->m_data < bam_len) { b->m_data = bam_len; kroundup32(b->m_data); @@ -92,7 +95,8 @@ int bam_construct_seq(bam_seq_t **bp, size_t extra_len, b->core.pos = pos-1; b->core.bin = bam_reg2bin(pos-1, end); b->core.qual = mapq; - b->core.l_qname = qname_len+1; + b->core.l_qname = qname_len+qname_nuls; + b->core.l_extranul = qname_nuls-1; b->core.flag = flag; b->core.n_cigar = ncigar; b->core.l_qseq = len; @@ -103,9 +107,10 @@ int bam_construct_seq(bam_seq_t **bp, size_t extra_len, cp = b->data; strncpy((char *)cp, qname, qname_len); - cp[qname_len] = 0; - cp += qname_len+1; - memcpy(cp, cigar, ncigar*4); + for (i = 0; i < qname_nuls; i++) + cp[qname_len+i] = '\0'; + cp += qname_len+qname_nuls; + if (ncigar > 0) memcpy(cp, cigar, ncigar*4); cp += ncigar*4; for (i = 0; i+1 < len; i+=2) { @@ -119,7 +124,7 @@ int bam_construct_seq(bam_seq_t **bp, size_t extra_len, else memset(cp, '\xff', len); - return 0; + return bam_len; } bam_hdr_t *cram_header_to_bam(SAM_hdr *h) { diff --git a/htslib/cram/cram_samtools.h b/htslib/cram/cram_samtools.h index 635e2e029..606c60151 100644 --- a/htslib/cram/cram_samtools.h +++ b/htslib/cram/cram_samtools.h @@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define bam_flag(b) (b)->core.flag #define bam_bin(b) (b)->core.bin #define bam_map_qual(b) (b)->core.qual -#define bam_name_len(b) (b)->core.l_qname +#define bam_name_len(b) ((b)->core.l_qname - (b)->core.l_extranul) #define bam_name(b) bam_get_qname((b)) #define bam_qual(b) bam_get_qual((b)) #define bam_seq(b) bam_get_seq((b)) diff --git a/htslib/cram/cram_stats.c b/htslib/cram/cram_stats.c index e913055fb..5fb63d431 100644 --- a/htslib/cram/cram_stats.c +++ b/htslib/cram/cram_stats.c @@ -87,15 +87,16 @@ void cram_stats_del(cram_stats *st, int32_t val) { if (--kh_val(st->h, k) == 0) kh_del(m_i2i, st->h, k); } else { - fprintf(stderr, "Failed to remove val %d from cram_stats\n", val); + hts_log_warning("Failed to remove val %d from cram_stats", val); st->nsamp++; } } else { - fprintf(stderr, "Failed to remove val %d from cram_stats\n", val); + hts_log_warning("Failed to remove val %d from cram_stats", val); st->nsamp++; } } +#if DEBUG_CRAM_STATS void cram_stats_dump(cram_stats *st) { int i; fprintf(stderr, "cram_stats:\n"); @@ -114,6 +115,7 @@ void cram_stats_dump(cram_stats *st) { } } } +#endif /* * Computes entropy from integer frequencies for various encoding methods and @@ -128,7 +130,9 @@ enum cram_encoding cram_stats_encoding(cram_fd *fd, cram_stats *st) { int nvals, i, ntot = 0, max_val = 0, min_val = INT_MAX; int *vals = NULL, *freqs = NULL, vals_alloc = 0; - //cram_stats_dump(st); +#if DEBUG_CRAM_STATS + cram_stats_dump(st); +#endif /* Count number of unique symbols */ for (nvals = i = 0; i < MAX_STAT_VAL; i++) { diff --git a/htslib/cram/cram_structs.h b/htslib/cram/cram_structs.h index b3e0370bd..a50507e50 100644 --- a/htslib/cram/cram_structs.h +++ b/htslib/cram/cram_structs.h @@ -48,6 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include "htslib/thread_pool.h" #include "cram/string_alloc.h" @@ -83,6 +84,7 @@ KHASH_MAP_INIT_STR(map, pmap_t) struct hFILE; #define SEQS_PER_SLICE 10000 +#define BASES_PER_SLICE (SEQS_PER_SLICE*500) #define SLICE_PER_CNT 1 #define CRAM_SUBST_MATRIX "CGTNAGTNACTNACGNACGT" @@ -190,7 +192,7 @@ typedef struct cram_file_def { struct cram_slice; enum cram_block_method { - ERROR = -1, + BM_ERROR = -1, RAW = 0, GZIP = 1, BZIP2 = 2, @@ -246,6 +248,10 @@ typedef struct { double lzma_extra; } cram_metrics; +// Hash aux key (XX:i) to cram_metrics +KHASH_MAP_INIT_INT(m_metrics, cram_metrics*) + + /* Block */ typedef struct cram_block { enum cram_block_method method, orig_method; @@ -261,6 +267,9 @@ typedef struct cram_block { size_t alloc; size_t byte; int bit; + + // To aid compression + cram_metrics *m; // used to track aux block compression only } cram_block; struct cram_codec; /* defined in cram_codecs.h */ @@ -316,6 +325,15 @@ typedef struct cram_map { struct cram_map *next; // for noddy internal hash } cram_map; +typedef struct cram_tag_map { + struct cram_codec *codec; + cram_block *blk; + cram_metrics *m; +} cram_tag_map; + +// Hash aux key (XX:i) to cram_tag_map +KHASH_MAP_INIT_INT(m_tagmap, cram_tag_map*) + /* Mapped or unmapped slice header block */ typedef struct cram_block_slice_hdr { enum cram_content_type content_type; @@ -386,10 +404,12 @@ typedef struct cram_container { /* Statistics for encoding */ cram_stats *stats[DS_END]; - khash_t(s_i2i) *tags_used; // set of tag types in use, for tag encoding map + khash_t(m_tagmap) *tags_used; // set of tag types in use, for tag encoding map int *refs_used; // array of frequency of ref seq IDs uint32_t crc32; // CRC32 + + uint64_t s_num_bases; // number of bases in this slice } cram_container; /* @@ -556,23 +576,19 @@ typedef struct cram_slice { cram_block *qual_blk; cram_block *base_blk; cram_block *soft_blk; - cram_block *aux_blk; - cram_block *aux_OQ_blk; - cram_block *aux_BQ_blk; - cram_block *aux_BD_blk; - cram_block *aux_BI_blk; - cram_block *aux_FZ_blk; - cram_block *aux_oq_blk; - cram_block *aux_os_blk; - cram_block *aux_oz_blk; + cram_block *aux_blk; // BAM aux block, created while decoding CRAM string_alloc_t *pair_keys; // Pooled keys for pair hash. khash_t(m_s2i) *pair[2]; // for identifying read-pairs in this slice. - char *ref; // slice of current reference - int ref_start; // start position of current reference; - int ref_end; // end position of current reference; + char *ref; // slice of current reference + int ref_start; // start position of current reference; + int ref_end; // end position of current reference; int ref_id; + + // For going from BAM to CRAM; an array of auxiliary blocks per type + int naux_block; + cram_block **aux_block; } cram_slice; /*----------------------------------------------------------------------------- @@ -686,11 +702,12 @@ typedef struct cram_fd { // compression level and metrics int level; cram_metrics *m[DS_END]; + khash_t(m_metrics) *tags_used; // cram_metrics[], per tag types in use. // options int decode_md; // Whether to export MD and NM tags - int verbose; int seqs_per_slice; + int bases_per_slice; int slices_per_container; int embed_ref; int no_ref; @@ -728,7 +745,10 @@ typedef struct cram_fd { pthread_mutex_t bam_list_lock; void *job_pending; int ooc; // out of containers. - int lossy_read_names; + + int lossy_read_names; // boolean + int tlen_approx; // max TLEN calculation offset. + int tlen_zero; // If true, permit tlen 0 (=> tlen calculated) } cram_fd; // Translation of required fields to cram data series diff --git a/htslib/cram/mFILE.c b/htslib/cram/mFILE.c index 0d4bd72b6..dbb8b0afa 100644 --- a/htslib/cram/mFILE.c +++ b/htslib/cram/mFILE.c @@ -40,9 +40,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include "hts_internal.h" #include "cram/os.h" #include "cram/mFILE.h" -#include "cram/vlen.h" #ifdef HAVE_MMAP #include @@ -308,7 +308,7 @@ mFILE *mfreopen(const char *path, const char *mode_str, FILE *fp) { mf = mfcreate(NULL, 0); if (NULL == mf) return NULL; } else { - fprintf(stderr, "Must specify either r, w or a for mode\n"); + hts_log_error("Must specify either r, w or a for mode"); return NULL; } mf->fp = fp; @@ -630,45 +630,6 @@ int mfflush(mFILE *mf) { return 0; } -/* - * A wrapper around vsprintf() to write to an mFILE. This also uses vflen() to - * estimate how many additional bytes of storage will be required for the - * vsprintf to work. - */ -int mfprintf(mFILE *mf, char *fmt, ...) { - int ret; - size_t est_length; - va_list args; - - va_start(args, fmt); - est_length = vflen(fmt, args); - va_end(args); - while (est_length + mf->offset > mf->alloced) { - size_t new_alloced = mf->alloced ? mf->alloced * 2 : 1024; - void * new_data = realloc(mf->data, new_alloced); - if (NULL == new_data) return -1; - mf->alloced = new_alloced; - mf->data = new_data; - } - - va_start(args, fmt); - ret = vsprintf(&mf->data[mf->offset], fmt, args); - va_end(args); - - if (ret > 0) { - mf->offset += ret; - if (mf->size < mf->offset) - mf->size = mf->offset; - } - - if (mf->fp == stderr) { - /* Auto-flush for stderr */ - if (0 != mfflush(mf)) return -1; - } - - return ret; -} - /* * Converts an mFILE from binary to ascii mode by replacing all * cr-nl with nl. diff --git a/htslib/cram/mFILE.h b/htslib/cram/mFILE.h index 05a3a88d2..19df5fbd3 100644 --- a/htslib/cram/mFILE.h +++ b/htslib/cram/mFILE.h @@ -48,6 +48,11 @@ typedef struct { size_t flush_pos; } mFILE; +// Work around a clash with winuser.h +#ifdef MF_APPEND +# undef MF_APPEND +#endif + #define MF_READ 1 #define MF_WRITE 2 #define MF_APPEND 4 @@ -76,7 +81,6 @@ void mfrecreate(mFILE *mf, char *data, int size); void *mfsteal(mFILE *mf, size_t *size_out); char *mfgets(char *s, int size, mFILE *mf); int mfflush(mFILE *mf); -int mfprintf(mFILE *mf, char *fmt, ...); mFILE *mstdin(void); mFILE *mstdout(void); mFILE *mstderr(void); diff --git a/htslib/cram/os.h b/htslib/cram/os.h index 22d809649..ba0a20753 100644 --- a/htslib/cram/os.h +++ b/htslib/cram/os.h @@ -30,7 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* -Copyright (c) 2004, 2006, 2009-2011, 2013 Genome Research Ltd. +Copyright (c) 2004, 2006, 2009-2011, 2013, 2017 Genome Research Ltd. Author: James Bonfield Redistribution and use in source and binary forms, with or without @@ -77,91 +77,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include "htslib/hts_endian.h" #ifdef __cplusplus extern "C" { #endif -/*----------------------------------------------------------------------------- - * Detection of endianness. The main part of this is done in autoconf, but - * for the case of MacOS FAT binaries we fall back on auto-sensing based on - * processor type too. - */ - -/* Set by autoconf */ -#define SP_LITTLE_ENDIAN - -/* Mac FAT binaries or unknown. Auto detect based on CPU type */ -#if !defined(SP_BIG_ENDIAN) && !defined(SP_LITTLE_ENDIAN) - -/* - * x86 equivalents - */ -#if defined(__i386__) || defined(__i386) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(__i686__) || defined(__i686) -# if defined(SP_BIG_ENDIAN) -# undef SP_BIG_ENDIAN -# endif -# define SP_LITTLE_ENDIAN -#endif - -/* - * DEC Alpha - */ -#if defined(__alpha__) || defined(__alpha) -# if defined(SP_LITTLE_ENDIAN) -# undef SP_LITTLE_ENDIAN -# endif -# define SP_BIG_ENDIAN -#endif - -/* - * SUN Sparc - */ -#if defined(__sparc__) || defined(__sparc) -# if defined(SP_LITTLE_ENDIAN) -# undef SP_LITTLE_ENDIAN -# endif -# define SP_BIG_ENDIAN -#endif - -/* - * PowerPC - */ -#if defined(__ppc__) || defined(__ppc) -# if defined(SP_LITTLE_ENDIAN) -# undef SP_LITTLE_ENDIAN -# endif -# define SP_BIG_ENDIAN -#endif - -/* Some catch-alls */ -#if defined(__LITTLE_ENDIAN__) || defined(__LITTLEENDIAN__) -# define SP_LITTLE_ENDIAN -#endif - -#if defined(__BIG_ENDIAN__) || defined(__BIGENDIAN__) -# define SP_BIG_ENDIAN -#endif - -#if defined(SP_BIG_ENDIAN) && defined(SP_LITTLE_ENDIAN) -# error Both BIG and LITTLE endian defined. Fix os.h and/or Makefile -#endif - -#if !defined(SP_BIG_ENDIAN) && !defined(SP_LITTLE_ENDIAN) -# error Neither BIG nor LITTLE endian defined. Fix os.h and/or Makefile -#endif - -#endif - -/*----------------------------------------------------------------------------- - * Allow for unaligned memory access. This is used in BAM code as the packed - * structure has 4-byte cigar ints after the variable length name. - * - * Consider using AX_CHECK_ALIGNED_ACCESS_REQUIRED in autoconf. - */ -#if defined(__i386__) || defined(__i386) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(__i686__) || defined(__i686) -# define ALLOW_UAC -#endif /*----------------------------------------------------------------------------- * Byte swapping macros @@ -223,14 +144,19 @@ extern "C" { * This leads to efficient code as most of the time these macros are * trivial. */ -#ifdef SP_BIG_ENDIAN +#if defined(HTS_BIG_ENDIAN) #define le_int4(x) iswap_int4((x)) #define le_int2(x) iswap_int2((x)) -#endif - -#ifdef SP_LITTLE_ENDIAN +#elif defined(HTS_LITTLE_ENDIAN) #define le_int4(x) (x) #define le_int2(x) (x) +#else +static inline uint32_t le_int4(uint32_t x) { + return le_to_u32((uint8_t *) &x); +} +static inline uint16_t le_int2(uint16_t x) { + return le_to_u16((uint8_t *) &x); +} #endif /*----------------------------------------------------------------------------- @@ -279,27 +205,13 @@ extern "C" { * Microsoft Windows running MinGW */ #if defined(__MINGW32__) -/* #define mkdir(filename,mode) mkdir((filename)) */ +#include +#define mkdir(filename,mode) mkdir((filename)) #define sysconf(x) 512 -#define ftruncate(fd,len) _chsize(fd,len) +#ifndef ftruncate +# define ftruncate(fd,len) _chsize(fd,len) +#endif #endif - -/* Generic WIN32 API issues */ -#ifdef _WIN32 -# ifndef HAVE_FSEEKO -# if __MSVCRT_VERSION__ >= 0x800 - /* if you have MSVCR80 installed then you can use these definitions: */ -# define off_t __int64 -# define fseeko _fseeki64 -# define ftello _ftelli64 -# else - /* otherwise we're stuck with 32-bit file support */ -# define off_t long -# define fseeko fseek -# define ftello ftell -# endif -# endif /* !HAVE_FSEEKO */ -#endif /* _WIN32 */ #ifdef __cplusplus } diff --git a/htslib/cram/rANS_byte.h b/htslib/cram/rANS_byte.h index c61ed9d10..9f38743b5 100644 --- a/htslib/cram/rANS_byte.h +++ b/htslib/cram/rANS_byte.h @@ -326,11 +326,27 @@ static inline void RansDecRenorm(RansState* r, uint8_t** pptr) if (x < RANS_BYTE_L) { uint8_t* ptr = *pptr; - do x = (x << 8) | *ptr++; while (x < RANS_BYTE_L); + x = (x << 8) | *ptr++; + if (x < RANS_BYTE_L) + x = (x << 8) | *ptr++; *pptr = ptr; } *r = x; } +// Renormalize, with extra checks for falling off the end of the input. +static inline void RansDecRenormSafe(RansState* r, uint8_t** pptr, uint8_t *ptr_end) +{ + uint32_t x = *r; + uint8_t* ptr = *pptr; + if (x >= RANS_BYTE_L || ptr >= ptr_end) return; + x = (x << 8) | *ptr++; + if (x < RANS_BYTE_L && ptr < ptr_end) + x = (x << 8) | *ptr++; + *pptr = ptr; + *r = x; +} + + #endif // RANS_BYTE_HEADER diff --git a/htslib/cram/rANS_static.c b/htslib/cram/rANS_static.c index 00eda5aed..da5745829 100644 --- a/htslib/cram/rANS_static.c +++ b/htslib/cram/rANS_static.c @@ -87,7 +87,7 @@ unsigned char *rans_compress_O0(unsigned char *in, unsigned int in_size, F[in[i]]++; } tr = ((uint64_t)TOTFREQ<<31)/in_size + (1<<30)/in_size; - + normalise_harder: // Normalise so T[i] == TOTFREQ for (m = M = j = 0; j < 256; j++) { if (!F[j]) @@ -102,10 +102,14 @@ unsigned char *rans_compress_O0(unsigned char *in, unsigned int in_size, } fsum++; - if (fsum < TOTFREQ) + if (fsum < TOTFREQ) { F[M] += TOTFREQ-fsum; - else + } else if (fsum-TOTFREQ > F[M]/2) { + // Corner case to avoid excessive frequency reduction + tr = 2104533975; goto normalise_harder; // equiv to *0.98. + } else { F[M] -= fsum-TOTFREQ; + } //printf("F[%d]=%d\n", M, F[M]); assert(F[M]>0); @@ -196,23 +200,21 @@ unsigned char *rans_compress_O0(unsigned char *in, unsigned int in_size, } typedef struct { - struct { - int F; - int C; - } fc[256]; - unsigned char *R; + unsigned char R[TOTFREQ]; } ari_decoder; unsigned char *rans_uncompress_O0(unsigned char *in, unsigned int in_size, unsigned int *out_size) { /* Load in the static tables */ unsigned char *cp = in + 9; + unsigned char *cp_end = in + in_size; int i, j, x, out_sz, in_sz, rle; char *out_buf; ari_decoder D; RansDecSymbol syms[256]; - memset(&D, 0, sizeof(D)); + if (in_size < 26) // Need at least this many bytes just to start + return NULL; if (*in++ != 0) // Order-0 check return NULL; @@ -222,29 +224,26 @@ unsigned char *rans_uncompress_O0(unsigned char *in, unsigned int in_size, if (in_sz != in_size-9) return NULL; - out_buf = malloc(out_sz); - if (!out_buf) - return NULL; - - //fprintf(stderr, "out_sz=%d\n", out_sz); - // Precompute reverse lookup of frequency. rle = x = 0; j = *cp++; do { - if ((D.fc[j].F = *cp++) >= 128) { - D.fc[j].F &= ~128; - D.fc[j].F = ((D.fc[j].F & 127) << 8) | *cp++; + int F, C; + if (cp > cp_end - 16) return NULL; // Not enough input bytes left + if ((F = *cp++) >= 128) { + F &= ~128; + F = ((F & 127) << 8) | *cp++; } - D.fc[j].C = x; + C = x; - RansDecSymbolInit(&syms[j], D.fc[j].C, D.fc[j].F); + RansDecSymbolInit(&syms[j], C, F); /* Build reverse lookup table */ - if (!D.R) D.R = (unsigned char *)malloc(TOTFREQ); - memset(&D.R[x], j, D.fc[j].F); + if (x + F > TOTFREQ) + return NULL; + memset(&D.R[x], j, F); - x += D.fc[j].F; + x += F; if (!rle && j+1 == *cp) { j = *cp++; @@ -252,12 +251,19 @@ unsigned char *rans_uncompress_O0(unsigned char *in, unsigned int in_size, } else if (rle) { rle--; j++; + if (j > 255) + return NULL; } else { j = *cp++; } } while(j); - assert(x < TOTFREQ); + if (x < TOTFREQ-1 || x > TOTFREQ) + return NULL; + if (x < TOTFREQ) // historically we fill 4095, not 4096 + D.R[x] = D.R[x-1]; + + if (cp > cp_end - 16) return NULL; // Not enough input bytes left RansState rans0, rans1, rans2, rans3; uint8_t *ptr = cp; @@ -266,6 +272,10 @@ unsigned char *rans_uncompress_O0(unsigned char *in, unsigned int in_size, RansDecInit(&rans2, &ptr); RansDecInit(&rans3, &ptr); + out_buf = malloc(out_sz); + if (!out_buf) + return NULL; + int out_end = (out_sz&~3); RansState R[4]; @@ -289,70 +299,57 @@ unsigned char *rans_uncompress_O0(unsigned char *in, unsigned int in_size, out_buf[i+2] = c[2]; out_buf[i+3] = c[3]; + // In theory all TOTFREQ elements of D.R are filled out, but it's + // possible this may not be true (invalid input). We could + // check with x == TOTFREQ after filling out D.R matrix, but + // for historical reasons this sums to TOTFREQ-1 leaving one + // byte in D.R uninitialised. Or we could check here that + // syms[c[0..3]].freq > 0 and initialising syms, but that is + // slow. + // + // We take the former approach and accept a potential for garbage in + // -> garbage out in the rare 1 in TOTFREQ case as the overhead of + // continuous validation of freq > 0 is steep on this tight loop. + // RansDecAdvanceSymbolStep(&R[0], &syms[c[0]], TF_SHIFT); // RansDecAdvanceSymbolStep(&R[1], &syms[c[1]], TF_SHIFT); // RansDecAdvanceSymbolStep(&R[2], &syms[c[2]], TF_SHIFT); // RansDecAdvanceSymbolStep(&R[3], &syms[c[3]], TF_SHIFT); R[0] = syms[c[0]].freq * (R[0]>>TF_SHIFT); - R[1] = syms[c[1]].freq * (R[1]>>TF_SHIFT); - R[2] = syms[c[2]].freq * (R[2]>>TF_SHIFT); - R[3] = syms[c[3]].freq * (R[3]>>TF_SHIFT); - R[0] += m[0] - syms[c[0]].start; + R[1] = syms[c[1]].freq * (R[1]>>TF_SHIFT); R[1] += m[1] - syms[c[1]].start; + R[2] = syms[c[2]].freq * (R[2]>>TF_SHIFT); R[2] += m[2] - syms[c[2]].start; + R[3] = syms[c[3]].freq * (R[3]>>TF_SHIFT); R[3] += m[3] - syms[c[3]].start; - RansDecRenorm(&R[0], &ptr); - RansDecRenorm(&R[1], &ptr); - RansDecRenorm(&R[2], &ptr); - RansDecRenorm(&R[3], &ptr); + if (ptr < cp_end - 8) { // Each renorm reads no more than 2 bytes + RansDecRenorm(&R[0], &ptr); + RansDecRenorm(&R[1], &ptr); + RansDecRenorm(&R[2], &ptr); + RansDecRenorm(&R[3], &ptr); + } else { + RansDecRenormSafe(&R[0], &ptr, cp_end); + RansDecRenormSafe(&R[1], &ptr, cp_end); + RansDecRenormSafe(&R[2], &ptr, cp_end); + RansDecRenormSafe(&R[3], &ptr, cp_end); + } } - rans0 = R[0]; - rans1 = R[1]; - rans2 = R[2]; - rans3 = R[3]; - switch(out_sz&3) { - unsigned char c; - case 0: - break; - case 1: - c = D.R[RansDecGet(&rans0, TF_SHIFT)]; - RansDecAdvanceSymbol(&rans0, &ptr, &syms[c], TF_SHIFT); - out_buf[out_end] = c; - break; - - case 2: - c = D.R[RansDecGet(&rans0, TF_SHIFT)]; - RansDecAdvanceSymbol(&rans0, &ptr, &syms[c], TF_SHIFT); - out_buf[out_end] = c; - - c = D.R[RansDecGet(&rans1, TF_SHIFT)]; - RansDecAdvanceSymbol(&rans1, &ptr, &syms[c], TF_SHIFT); - out_buf[out_end+1] = c; - break; - case 3: - c = D.R[RansDecGet(&rans0, TF_SHIFT)]; - RansDecAdvanceSymbol(&rans0, &ptr, &syms[c], TF_SHIFT); - out_buf[out_end] = c; - - c = D.R[RansDecGet(&rans1, TF_SHIFT)]; - RansDecAdvanceSymbol(&rans1, &ptr, &syms[c], TF_SHIFT); - out_buf[out_end+1] = c; - - c = D.R[RansDecGet(&rans2, TF_SHIFT)]; - RansDecAdvanceSymbol(&rans2, &ptr, &syms[c], TF_SHIFT); - out_buf[out_end+2] = c; - break; + out_buf[out_end+2] = D.R[RansDecGet(&R[2], TF_SHIFT)]; + case 2: + out_buf[out_end+1] = D.R[RansDecGet(&R[1], TF_SHIFT)]; + case 1: + out_buf[out_end] = D.R[RansDecGet(&R[0], TF_SHIFT)]; + default: + break; } *out_size = out_sz; - if (D.R) free(D.R); - return (unsigned char *)out_buf; } @@ -407,6 +404,7 @@ unsigned char *rans_compress_O1(unsigned char *in, unsigned int in_size, //uint64_t p = (TOTFREQ * TOTFREQ) / t; double p = ((double)TOTFREQ)/T[i]; + normalise_harder: for (t2 = m = M = j = 0; j < 256; j++) { if (!F[i][j]) continue; @@ -421,10 +419,14 @@ unsigned char *rans_compress_O1(unsigned char *in, unsigned int in_size, } t2++; - if (t2 < TOTFREQ) + if (t2 < TOTFREQ) { F[i][M] += TOTFREQ-t2; - else + } else if (t2-TOTFREQ >= F[i][M]/2) { + // Corner case to avoid excessive frequency reduction + p = .98; goto normalise_harder; + } else { F[i][M] -= t2-TOTFREQ; + } // Store frequency table // i @@ -566,11 +568,15 @@ unsigned char *rans_uncompress_O1(unsigned char *in, unsigned int in_size, unsigned int *out_size) { /* Load in the static tables */ unsigned char *cp = in + 9; + unsigned char *ptr_end = in + in_size; int i, j = -999, x, out_sz, in_sz, rle_i, rle_j; char *out_buf = NULL; ari_decoder *D = NULL; /* D[256] */ RansDecSymbol (*syms)[256] = NULL; /* syms[256][256] */ + if (in_size < 27) // Need at least this many bytes to start + return NULL; + if (*in++ != 1) // Order-1 check return NULL; @@ -579,10 +585,12 @@ unsigned char *rans_uncompress_O1(unsigned char *in, unsigned int in_size, if (in_sz != in_size-9) return NULL; + // calloc may add 2% overhead to CRAM decode, but on linux with glibc it's + // often the same thing due to using mmap. D = calloc(256, sizeof(*D)); if (!D) goto cleanup; syms = malloc(256 * sizeof(*syms)); - if (!syms) goto cleanup; + memset(&syms[0], 0, sizeof(syms[0])); //fprintf(stderr, "out_sz=%d\n", out_sz); @@ -593,29 +601,27 @@ unsigned char *rans_uncompress_O1(unsigned char *in, unsigned int in_size, rle_j = x = 0; j = *cp++; do { - if ((D[i].fc[j].F = *cp++) >= 128) { - D[i].fc[j].F &= ~128; - D[i].fc[j].F = ((D[i].fc[j].F & 127) << 8) | *cp++; + int F, C; + if (cp > ptr_end - 16) goto cleanup; // Not enough input bytes left + if ((F = *cp++) >= 128) { + F &= ~128; + F = ((F & 127) << 8) | *cp++; } - D[i].fc[j].C = x; + C = x; - //fprintf(stderr, "i=%d j=%d F=%d C=%d\n", i, j, D[i].fc[j].F, D[i].fc[j].C); + //fprintf(stderr, "i=%d j=%d F=%d C=%d\n", i, j, F, C); - if (!D[i].fc[j].F) - D[i].fc[j].F = TOTFREQ; + if (!F) + F = TOTFREQ; - RansDecSymbolInit(&syms[i][j], D[i].fc[j].C, D[i].fc[j].F); + RansDecSymbolInit(&syms[i][j], C, F); /* Build reverse lookup table */ - if (!D[i].R) { - D[i].R = (unsigned char *)malloc(TOTFREQ); - if (!D[i].R) - goto cleanup; - } - memset(&D[i].R[x], j, D[i].fc[j].F); + if (x + F > TOTFREQ) + goto cleanup; + memset(&D[i].R[x], j, F); - x += D[i].fc[j].F; - assert(x <= TOTFREQ); + x += F; if (!rle_j && j+1 == *cp) { j = *cp++; @@ -623,17 +629,26 @@ unsigned char *rans_uncompress_O1(unsigned char *in, unsigned int in_size, } else if (rle_j) { rle_j--; j++; + if (j > 255) + goto cleanup; } else { j = *cp++; } } while(j); + if (x < TOTFREQ-1 || x > TOTFREQ) + goto cleanup; + if (x < TOTFREQ) // historically we fill 4095, not 4096 + D[i].R[x] = D[i].R[x-1]; + if (!rle_i && i+1 == *cp) { i = *cp++; rle_i = *cp++; } else if (rle_i) { rle_i--; i++; + if (i > 255) + goto cleanup; } else { i = *cp++; } @@ -643,10 +658,11 @@ unsigned char *rans_uncompress_O1(unsigned char *in, unsigned int in_size, RansState rans0, rans1, rans2, rans3; uint8_t *ptr = cp; - RansDecInit(&rans0, &ptr); - RansDecInit(&rans1, &ptr); - RansDecInit(&rans2, &ptr); - RansDecInit(&rans3, &ptr); + if (ptr > ptr_end - 16) goto cleanup; // Not enough input bytes left + RansDecInit(&rans0, &ptr); if (rans0 < RANS_BYTE_L) goto cleanup; + RansDecInit(&rans1, &ptr); if (rans1 < RANS_BYTE_L) goto cleanup; + RansDecInit(&rans2, &ptr); if (rans2 < RANS_BYTE_L) goto cleanup; + RansDecInit(&rans3, &ptr); if (rans3 < RANS_BYTE_L) goto cleanup; int isz4 = out_sz>>2; int l0 = 0; @@ -687,19 +703,25 @@ unsigned char *rans_uncompress_O1(unsigned char *in, unsigned int in_size, //RansDecAdvanceSymbolStep(&R[3], &syms[l3][c[3]], TF_SHIFT); R[0] = syms[l0][c[0]].freq * (R[0]>>TF_SHIFT); - R[1] = syms[l1][c[1]].freq * (R[1]>>TF_SHIFT); - R[2] = syms[l2][c[2]].freq * (R[2]>>TF_SHIFT); - R[3] = syms[l3][c[3]].freq * (R[3]>>TF_SHIFT); - R[0] += m[0] - syms[l0][c[0]].start; + R[1] = syms[l1][c[1]].freq * (R[1]>>TF_SHIFT); R[1] += m[1] - syms[l1][c[1]].start; + R[2] = syms[l2][c[2]].freq * (R[2]>>TF_SHIFT); R[2] += m[2] - syms[l2][c[2]].start; + R[3] = syms[l3][c[3]].freq * (R[3]>>TF_SHIFT); R[3] += m[3] - syms[l3][c[3]].start; - RansDecRenorm(&R[0], &ptr); - RansDecRenorm(&R[1], &ptr); - RansDecRenorm(&R[2], &ptr); - RansDecRenorm(&R[3], &ptr); + if (ptr < ptr_end - 8) { // Each renorm reads no more than 2 bytes + RansDecRenorm(&R[0], &ptr); + RansDecRenorm(&R[1], &ptr); + RansDecRenorm(&R[2], &ptr); + RansDecRenorm(&R[3], &ptr); + } else { + RansDecRenormSafe(&R[0], &ptr, ptr_end); + RansDecRenormSafe(&R[1], &ptr, ptr_end); + RansDecRenormSafe(&R[2], &ptr, ptr_end); + RansDecRenormSafe(&R[3], &ptr, ptr_end); + } l0 = c[0]; l1 = c[1]; @@ -707,27 +729,22 @@ unsigned char *rans_uncompress_O1(unsigned char *in, unsigned int in_size, l3 = c[3]; } - rans0 = R[0]; - rans1 = R[1]; - rans2 = R[2]; - rans3 = R[3]; - // Remainder for (; i4[3] < out_sz; i4[3]++) { - unsigned char c3 = D[l3].R[RansDecGet(&rans3, TF_SHIFT)]; + unsigned char c3 = D[l3].R[RansDecGet(&R[3], TF_SHIFT)]; out_buf[i4[3]] = c3; - RansDecAdvanceSymbol(&rans3, &ptr, &syms[l3][c3], TF_SHIFT); + + uint32_t m = R[3] & ((1u << TF_SHIFT)-1); + R[3] = syms[l3][c3].freq * (R[3]>>TF_SHIFT) + m - syms[l3][c3].start; + RansDecRenormSafe(&R[3], &ptr, ptr_end); l3 = c3; } *out_size = out_sz; cleanup: - if (D) { - for (i = 0; i < 256; i++) - if (D[i].R) free(D[i].R); + if (D) free(D); - } free(syms); return (unsigned char *)out_buf; diff --git a/htslib/cram/sam_header.c b/htslib/cram/sam_header.c index e2cb55d36..288a35604 100644 --- a/htslib/cram/sam_header.c +++ b/htslib/cram/sam_header.c @@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include "hts_internal.h" #include "cram/sam_header.h" #include "cram/string_alloc.h" @@ -41,7 +42,7 @@ static void sam_hdr_error(char *msg, char *line, int len, int lno) { for (j = 0; j < len && line[j] != '\n'; j++) ; - fprintf(stderr, "%s at line %d: \"%.*s\"\n", msg, lno, j, line); + hts_log_error("%s at line %d: \"%.*s\"", msg, lno, j, line); } void sam_hdr_dump(SAM_hdr *hdr) { @@ -775,8 +776,7 @@ static enum sam_sort_order sam_hdr_parse_sort_order(SAM_hdr *hdr) { else if (strcmp(tag->str+3, "coordinate") == 0) so = ORDER_COORD; else if (strcmp(tag->str+3, "unknown") != 0) - fprintf(stderr, "Unknown sort order field: %s\n", - tag->str+3); + hts_log_error("Unknown sort order field: %s", tag->str+3); } } } diff --git a/htslib/cram/vlen.c b/htslib/cram/vlen.c deleted file mode 100644 index 083174144..000000000 --- a/htslib/cram/vlen.c +++ /dev/null @@ -1,430 +0,0 @@ -/* -Author: James Bonfield (jkb@sanger.ac.uk) - -Copyright (c) 1995-1996 MEDICAL RESEARCH COUNCIL -All rights reserved - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1 Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - - 2 Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. - - 3 Neither the name of the MEDICAL RESEARCH COUNCIL, THE LABORATORY OF -MOLECULAR BIOLOGY nor the names of its contributors may be used to endorse or -promote products derived from this software without specific prior written -permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* -Copyright (c) 2004, 2009, 2011-2012 Genome Research Ltd. - -Author: James Bonfield - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. - - 3. Neither the names Genome Research Ltd and Wellcome Trust Sanger -Institute nor the names of its contributors may be used to endorse or promote -products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY GENOME RESEARCH LTD AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL GENOME RESEARCH LTD OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#include -#include -#include -#include -#include - -#include "cram/vlen.h" -#include "cram/os.h" - -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - -#ifndef ABS -#define ABS(a) ((a)>0?(a):-(a)) -#endif - -/* #define DEBUG_printf(a,n) printf(a,n) */ -#define DEBUG_printf(a,n) - -/* - * vlen: 27/10/95 written by James Bonfield, jkb@mrc-lmb.cam.ac.uk - * - * Given sprintf style of arguments this routine returns the maximum - * size of buffer needed to allocate to use with sprintf. It errs on - * the side of caution by being simplistic in its approach: we assume - * all numbers are of maximum length. - * - * Handles the usual type conversions (%[%diuaxXcfeEgGpns]), but not - * the 'wide' character conversions (%C and %S). - * Precision is handled in the correct formats, including %*.* - * notations. - * Additionally, some of the more dubious (but probably illegal) cases - * are supported (eg "%10%" will expand to " %" on many - * systems). - * - * We also assume that the largest integer and larger pointer are 64 - * bits, which at least covers the machines we'll need it for. - */ -int flen(char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - return vflen(fmt, args); -} - -int vflen(char *fmt, va_list ap) -{ - int len = 0; - char *cp, c; - long long l; - int i; - double d; - - /* - * This code modifies 'ap', but we do not know if va_list is a structure - * or a pointer to an array so we do not know if it is a local variable - * or not. - * C99 gets around this by defining va_copy() to make copies of ap, but - * this does not exist on all systems. - * For now, I just assume that when va_list is a pointer the system also - * provides a va_copy macro to work around this problem. The only system - * I have seen needing this so far was Linux on AMD64. - */ -#if defined(HAVE_VA_COPY) - va_list ap_local; - va_copy(ap_local, ap); -# define ap ap_local -#endif - - for(cp = fmt; *cp; cp++) { - switch(*cp) { - - /* A format specifier */ - case '%': { - char *endp; - long conv_len1=0, conv_len2=0, conv_len=0; - signed int arg_size; - - /* Firstly, strip the modifier flags (+-#0 and [space]) */ - for(; (c=*++cp);) { - if ('#' == c) - len+=2; /* Worst case of "0x" */ - else if ('-' == c || '+' == c || ' ' == c) - len++; - else - break; - } - - /* Width specifier */ - l = strtol(cp, &endp, 10); - if (endp != cp) { - cp = endp; - conv_len = conv_len1 = l; - } else if (*cp == '*') { - conv_len = conv_len1 = (int)va_arg(ap, int); - cp++; - } - - /* Precision specifier */ - if ('.' == *cp) { - cp++; - conv_len2 = strtol(cp, &endp, 10); - if (endp != cp) { - cp = endp; - } else if (*cp == '*') { - conv_len2 = (int)va_arg(ap, int); - cp++; - } - conv_len = MAX(conv_len1, conv_len2); - } - - /* Short/long identifier */ - if ('h' == *cp) { - arg_size = -1; /* short */ - cp++; - } else if ('l' == *cp) { - arg_size = 1; /* long */ - cp++; - if ('l' == *cp) { - arg_size = 2; /* long long */ - cp++; - } - } else { - arg_size = 0; /* int */ - } - - /* The actual type */ - switch (*cp) { - case '%': - /* - * Not real ANSI I suspect, but we'll allow for the - * completely daft "%10%" example. - */ - len += MAX(conv_len1, 1); - break; - - case 'd': - case 'i': - case 'u': - case 'a': - case 'x': - case 'X': - /* Remember: char and short are sent as int on the stack */ - if (arg_size == -1) - l = (long)va_arg(ap, int); - else if (arg_size == 1) - l = va_arg(ap, long); - else if (arg_size == 2) - l = va_arg(ap, long long); - else - l = (long)va_arg(ap, int); - - DEBUG_printf("%d", l); - - /* - * No number can be more than 24 characters so we'll take - * the max of conv_len and 24 (23 is len(2^64) in octal). - * All that work above and we then go and estimate ;-), - * but it's needed incase someone does %500d. - */ - len += MAX(conv_len, 23); - break; - - case 'c': - i = va_arg(ap, int); - DEBUG_printf("%c", i); - /* - * Note that %10c and %.10c act differently. - * Besides, I think precision is not really allowed for %c. - */ - len += MAX(conv_len1, i>=0x80 ?MB_CUR_MAX :1); - break; - - case 'f': - d = va_arg(ap, double); - DEBUG_printf("%f", d); - /* - * Maybe "Inf" or "NaN", but we'll not worry about that. - * Again, err on side of caution and take max of conv_len - * and max length of a double. The worst case I can - * think of is 317 characters (-1[308 zeros].000000) - * without using precision codes. That's horrid. I - * cheat and either use 317 or 15 depending on how - * large the number is as I reckon 99% of floats - * aren't that long. - */ - l = (ABS(d) > 1000000) ? 317 : 15; - l = MAX(l, conv_len1 + 2); - if (conv_len2) l += conv_len2 - 6; - len += l; - break; - - case 'e': - case 'E': - case 'g': - case 'G': - d = va_arg(ap, double); - DEBUG_printf("%g", d); - /* - * Maybe "Inf" or "NaN", but we'll not worry about that - * Again, err on side of caution and take max of conv_len - * and max length of a double (which defaults to only - * '-' + 6 + '.' + 'E[+-]xxx' == 13. - */ - len += MAX(conv_len, 13); - break; - - case 'p': - l = (long)va_arg(ap, void *); - /* - * Max pointer is 64bits == 16 chars (on alpha), - * == 20 with + "0x". - */ - DEBUG_printf("%p", (void *)l); - len += MAX(conv_len, 20); - break; - - case 'n': - /* produces no output */ - break; - - case 's': { - char *s = (char *)va_arg(ap, char *); - DEBUG_printf("%s", s); - - if (!conv_len2) { - len += MAX(conv_len, (int)strlen(s)); - } else { - len += conv_len; - } - break; - } - - default: - /* wchar_t types of 'C' and 'S' aren't supported */ - DEBUG_printf("Arg is %c\n", *cp); - } - - } - - case '\0': - break; - - default: - DEBUG_printf("%c", *cp); - len++; - } - } - - va_end(ap); - - return len+1; /* one for the null character */ -} - -#if 0 -int main() { - int l; - char buf[10000]; - - sprintf(buf, "d: %d\n", 500); - l = flen("d: %d\n", 500); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, ""); - l = flen(""); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%s\n","test"); - l = flen("%s\n", "test"); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%c\n", 'a'); - l = flen("%c\n", 'a'); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%31.30f\n", -9999.99); - l = flen("%31.30f\n", -9999.99); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%f\n", -1e308); - l = flen("%f\n", -1e308); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%.9f\n", -1e308); - l = flen("%.9f\n", -1e308); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%10.20f\n", -1.999222333); - l = flen("%10.20f\n", -1.999222333); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%#g\n", -3.14159265358e-222); - l = flen("%#g\n", -3.1415927e-222); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%e\n", -123456789123456789.1); - l = flen("%e\n", -123456789123456789.1); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%c %f %d %s %c %g %ld %s\n", 'a', 3.1, 9, "one", 'b', 4.2, 9, "two"); - l = flen("%c %f %d %s %c %g %ld %s\n", 'a', 3.1, 9, "one", 'b', 4.2, 9, "two"); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%*.*e %*c\n", 10, 5, 9.0, 20, 'x'); - l = flen("%*.*e %*c\n", 10, 5, 9.0, 20, 'x'); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%10c\n", 'z'); - l = flen("%10c\n", 'z'); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%.10c\n", 'z'); - l = flen("%.10c\n", 'z'); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%10d\n", 'z'); - l = flen("%10d\n", 'z'); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%.10d\n", 'z'); - l = flen("%.10d\n", 'z'); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%10%\n"); - l = flen("%10%\n"); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%.10%\n"); - l = flen("%.10%\n"); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%s\n", "0123456789"); - l = flen("%s\n", "0123456789"); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%5s\n", "0123456789"); - l = flen("%5s\n", "0123456789"); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%50s\n", "0123456789"); - l = flen("%50s\n", "0123456789"); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%.5s\n", "0123456789"); - l = flen("%.5s\n", "0123456789"); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%.50s\n", "0123456789"); - l = flen("%.50s\n", "0123456789"); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%5.50s\n", "0123456789"); - l = flen("%5.50s\n", "0123456789"); - printf("%d %d\n\n", strlen(buf), l); - - sprintf(buf, "%50.5s\n", "0123456789"); - l = flen("%50.5s\n", "0123456789"); - printf("%d %d\n\n", strlen(buf), l); - - return 0; -} -#endif diff --git a/htslib/cram/vlen.h b/htslib/cram/vlen.h deleted file mode 100644 index 9619ac32d..000000000 --- a/htslib/cram/vlen.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -Author: James Bonfield (jkb@sanger.ac.uk) - -Copyright (c) 1995-1996 MEDICAL RESEARCH COUNCIL -All rights reserved - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1 Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - - 2 Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. - - 3 Neither the name of the MEDICAL RESEARCH COUNCIL, THE LABORATORY OF -MOLECULAR BIOLOGY nor the names of its contributors may be used to endorse or -promote products derived from this software without specific prior written -permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef _VLEN_H_ -#define _VLEN_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -extern int vflen(char *fmt, va_list ap); -extern int flen(char *fmt, ...); - -#ifdef __cplusplus -} -#endif - -#endif /* _VLEN_H_ */ diff --git a/htslib/cram/zfio.c b/htslib/cram/zfio.c deleted file mode 100644 index 34e2587ab..000000000 --- a/htslib/cram/zfio.c +++ /dev/null @@ -1,154 +0,0 @@ -/* -Copyright (c) 2009-2013 Genome Research Ltd. -Author: James Bonfield - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. - - 3. Neither the names Genome Research Ltd and Wellcome Trust Sanger -Institute nor the names of its contributors may be used to endorse or promote -products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY GENOME RESEARCH LTD AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL GENOME RESEARCH LTD OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#include -#include -#include - -#include "cram/os.h" -#include "cram/zfio.h" - -/* ------------------------------------------------------------------------ */ -/* Some wrappers around FILE * vs gzFile *, allowing for either */ - -/* - * gzopen() works on both compressed and uncompressed data, but it has - * a significant performance hit even for uncompressed data (tested as - * 25s using FILE* to 46s via gzOpen and 66s via gzOpen when gzipped). - * - * Hence we use our own wrapper 'zfp' which is a FILE* when uncompressed - * and gzFile* when compressed. This also means we could hide bzopen in - * there too if desired. - */ - -off_t zftello(zfp *zf) { - return zf->fp ? ftello(zf->fp) : -1; -} - -int zfseeko(zfp *zf, off_t offset, int whence) { - return zf->fp ? fseeko(zf->fp, offset, whence) : -1; -} - - -/* - * A wrapper for either fgets or gzgets depending on what has been - * opened. - */ -char *zfgets(char *line, int size, zfp *zf) { - if (zf->fp) - return fgets(line, size, zf->fp); - else - return gzgets(zf->gz, line, size); -} - -/* - * A wrapper for either fputs or gzputs depending on what has been - * opened. - */ -int zfputs(char *line, zfp *zf) { - if (zf->fp) - return fputs(line, zf->fp); - else - return gzputs(zf->gz, line) ? 0 : EOF; -} - -/* - * Peeks at and returns the next character without consuming it from the - * input. (Ie a combination of getc and ungetc). - */ -int zfpeek(zfp *zf) { - int c; - - if (zf->fp) { - c = getc(zf->fp); - if (c != EOF) - ungetc(c, zf->fp); - } else { - c = gzgetc(zf->gz); - if (c != EOF) - gzungetc(c, zf->gz); - } - - return c; -} - -/* A replacement for either feof of gzeof */ -int zfeof(zfp *zf) { - return zf->fp ? feof(zf->fp) : gzeof(zf->gz); -} - -/* A replacement for either fopen or gzopen */ -zfp *zfopen(const char *path, const char *mode) { - char path2[1024]; - zfp *zf; - - if (!(zf = (zfp *)malloc(sizeof(*zf)))) - return NULL; - zf->fp = NULL; - zf->gz = NULL; - - /* Try normal fopen */ - if (mode[0] != 'z' && mode[1] != 'z' && - NULL != (zf->fp = fopen(path, mode))) { - unsigned char magic[2]; - if (2 != fread(magic, 1, 2, zf->fp)) { - free(zf); - return NULL; - } - if (!(magic[0] == 0x1f && - magic[1] == 0x8b)) { - fseeko(zf->fp, 0, SEEK_SET); - return zf; - } - - fclose(zf->fp); - zf->fp = NULL; - } - - if ((zf->gz = gzopen(path, mode))) - return zf; - - if (!strchr(mode, 'w')) { - sprintf(path2, "%.*s.gz", 1020, path); - if ((zf->gz = gzopen(path2, mode))) - return zf; - } - - free(zf); - return NULL; -} - -int zfclose(zfp *zf) { - int r = (zf->fp) ? fclose(zf->fp) : gzclose(zf->gz); - free(zf); - return r; -} diff --git a/htslib/cram/zfio.h b/htslib/cram/zfio.h deleted file mode 100644 index ab9c9c97c..000000000 --- a/htslib/cram/zfio.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright (c) 2009-2013 Genome Research Ltd. -Author: James Bonfield - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. - - 3. Neither the names Genome Research Ltd and Wellcome Trust Sanger -Institute nor the names of its contributors may be used to endorse or promote -products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY GENOME RESEARCH LTD AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL GENOME RESEARCH LTD OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef _ZFIO_H_ -#define _ZFIO_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Either a gzFile or a FILE. - */ -typedef struct { - FILE *fp; - gzFile gz; -} zfp; - -off_t zftello(zfp *zf); -int zfseeko(zfp *zf, off_t offset, int whence); -char *zfgets(char *line, int size, zfp *zf); -int zfputs(char *line, zfp *zf); -zfp *zfopen(const char *path, const char *mode); -int zfclose(zfp *zf); -int zfpeek(zfp *zf); -int zfeof(zfp *zf); - -#ifdef __cplusplus -} -#endif - -#endif /* _ZFIO_H_ */ diff --git a/htslib/errmod.c b/htslib/errmod.c index 0c025bfdf..acc89227f 100644 --- a/htslib/errmod.c +++ b/htslib/errmod.c @@ -1,35 +1,42 @@ /* errmod.c -- revised MAQ error model. - Copyright (C) 2010 Broad Institute. - Copyright (C) 2012, 2013, 2016 Genome Research Ltd. - Author: Heng Li - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. */ + + Copyright (C) 2010 Broad Institute. + Copyright (C) 2012, 2013, 2016 Genome Research Ltd. + + Author: Heng Li + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ #include #include #include "htslib/hts.h" #include "htslib/ksort.h" +#include "htslib/hts_os.h" // for drand48 + KSORT_INIT_GENERIC(uint16_t) -typedef struct { +struct errmod_t { double depcorr; /* table of constants generated for given depcorr and eta */ double *fk, *beta, *lhet; -} errmod_t; +}; typedef struct { double fsum[16], bsum[16]; @@ -57,7 +64,7 @@ static double* logbinomial_table( const int n_size ) static void cal_coef(errmod_t *em, double depcorr, double eta) { int k, n, q; - long double sum, sum1; + double sum, sum1; double *lC; // initialize ->fk @@ -77,10 +84,11 @@ static void cal_coef(errmod_t *em, double depcorr, double eta) double le1 = log(1.0 - e); for (n = 1; n <= 255; ++n) { double *beta = em->beta + (q<<16|n<<8); - sum1 = sum = 0.0; - for (k = n; k >= 0; --k, sum1 = sum) { - sum = sum1 + expl(lC[n<<8|k] + k*le + (n-k)*le1); - beta[k] = -10. / M_LN10 * logl(sum1 / sum); + sum1 = lC[n<<8|n] + n*le; + beta[n] = HUGE_VAL; + for (k = n - 1; k >= 0; --k, sum1 = sum) { + sum = sum1 + log1p(exp(lC[n<<8|k] + k*le + (n-k)*le1 - sum1)); + beta[k] = -10. / M_LN10 * (sum1 - sum); } } } diff --git a/samtools/errmod.c b/htslib/errmod.c~crypto similarity index 64% rename from samtools/errmod.c rename to htslib/errmod.c~crypto index c37c6d1cc..0c025bfdf 100644 --- a/samtools/errmod.c +++ b/htslib/errmod.c~crypto @@ -1,39 +1,35 @@ /* errmod.c -- revised MAQ error model. - - Copyright (C) 2010 Broad Institute. - Copyright (C) 2012, 2013 Genome Research Ltd. - - Author: Heng Li - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. */ + Copyright (C) 2010 Broad Institute. + Copyright (C) 2012, 2013, 2016 Genome Research Ltd. + Author: Heng Li + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include #include -#include "errmod.h" +#include "htslib/hts.h" #include "htslib/ksort.h" KSORT_INIT_GENERIC(uint16_t) -/* table of constants generated for given depcorr and eta */ -typedef struct __errmod_coef_t { +typedef struct { + double depcorr; + /* table of constants generated for given depcorr and eta */ double *fk, *beta, *lhet; -} errmod_coef_t; +} errmod_t; typedef struct { double fsum[16], bsum[16]; @@ -58,21 +54,20 @@ static double* logbinomial_table( const int n_size ) return logbinom; } -static errmod_coef_t *cal_coef(double depcorr, double eta) +static void cal_coef(errmod_t *em, double depcorr, double eta) { int k, n, q; long double sum, sum1; double *lC; - errmod_coef_t *ec; - ec = calloc(1, sizeof(errmod_coef_t)); // initialize ->fk - ec->fk = (double*)calloc(256, sizeof(double)); - ec->fk[0] = 1.0; + em->fk = (double*)calloc(256, sizeof(double)); + em->fk[0] = 1.0; for (n = 1; n < 256; ++n) - ec->fk[n] = pow(1. - depcorr, n) * (1.0 - eta) + eta; - // initialize ->coef - ec->beta = (double*)calloc(256 * 256 * 64, sizeof(double)); + em->fk[n] = pow(1. - depcorr, n) * (1.0 - eta) + eta; + + // initialize ->beta + em->beta = (double*)calloc(256 * 256 * 64, sizeof(double)); lC = logbinomial_table( 256 ); @@ -81,7 +76,7 @@ static errmod_coef_t *cal_coef(double depcorr, double eta) double le = log(e); double le1 = log(1.0 - e); for (n = 1; n <= 255; ++n) { - double *beta = ec->beta + (q<<16|n<<8); + double *beta = em->beta + (q<<16|n<<8); sum1 = sum = 0.0; for (k = n; k >= 0; --k, sum1 = sum) { sum = sum1 + expl(lC[n<<8|k] + k*le + (n-k)*le1); @@ -89,13 +84,13 @@ static errmod_coef_t *cal_coef(double depcorr, double eta) } } } + // initialize ->lhet - ec->lhet = (double*)calloc(256 * 256, sizeof(double)); + em->lhet = (double*)calloc(256 * 256, sizeof(double)); for (n = 0; n < 256; ++n) for (k = 0; k < 256; ++k) - ec->lhet[n<<8|k] = lC[n<<8|k] - M_LN2 * n; + em->lhet[n<<8|k] = lC[n<<8|k] - M_LN2 * n; free(lC); - return ec; } /** @@ -106,7 +101,7 @@ errmod_t *errmod_init(double depcorr) errmod_t *em; em = (errmod_t*)calloc(1, sizeof(errmod_t)); em->depcorr = depcorr; - em->coef = cal_coef(depcorr, 0.03); + cal_coef(em, depcorr, 0.03); return em; } @@ -116,8 +111,8 @@ errmod_t *errmod_init(double depcorr) void errmod_destroy(errmod_t *em) { if (em == 0) return; - free(em->coef->lhet); free(em->coef->fk); free(em->coef->beta); - free(em->coef); free(em); + free(em->lhet); free(em->fk); free(em->beta); + free(em); } // @@ -157,8 +152,8 @@ int errmod_cal(const errmod_t *em, int n, int m, uint16_t *bases, float *q) int basestrand = b&0x1f; /* extract base */ int base = b&0xf; - aux.fsum[base] += em->coef->fk[w[basestrand]]; - aux.bsum[base] += em->coef->fk[w[basestrand]] * em->coef->beta[qual<<16|n<<8|aux.c[base]]; + aux.fsum[base] += em->fk[w[basestrand]]; + aux.bsum[base] += em->fk[w[basestrand]] * em->beta[qual<<16|n<<8|aux.c[base]]; ++aux.c[base]; ++w[basestrand]; } @@ -183,8 +178,8 @@ int errmod_cal(const errmod_t *em, int n, int m, uint16_t *bases, float *q) tmp1 += aux.bsum[i]; tmp2 += aux.c[i]; tmp3 += aux.fsum[i]; } if (tmp2) { - q[j*m+k] = q[k*m+j] = -4.343 * em->coef->lhet[cjk<<8|aux.c[k]] + tmp1; - } else q[j*m+k] = q[k*m+j] = -4.343 * em->coef->lhet[cjk<<8|aux.c[k]]; // all the bases are either j or k + q[j*m+k] = q[k*m+j] = -4.343 * em->lhet[cjk<<8|aux.c[k]] + tmp1; + } else q[j*m+k] = q[k*m+j] = -4.343 * em->lhet[cjk<<8|aux.c[k]]; // all the bases are either j or k } /* clamp to greater than 0 */ for (k = 0; k < m; ++k) if (q[j*m+k] < 0.0) q[j*m+k] = 0.0; diff --git a/htslib/faidx.c b/htslib/faidx.c index da5da5f07..f85ffb5dc 100644 --- a/htslib/faidx.c +++ b/htslib/faidx.c @@ -1,6 +1,6 @@ /* faidx.c -- FASTA random access. - Copyright (C) 2008, 2009, 2013-2016 Genome Research Ltd. + Copyright (C) 2008, 2009, 2013-2017 Genome Research Ltd. Portions copyright (C) 2011 Broad Institute. Author: Heng Li @@ -31,6 +31,9 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include +#include +#include #include "htslib/bgzf.h" #include "htslib/faidx.h" @@ -60,7 +63,7 @@ struct __faidx_t { static inline int fai_insert_index(faidx_t *idx, const char *name, int64_t len, int line_len, int line_blen, uint64_t offset) { if (!name) { - fprintf(stderr, "[fai_build_core] malformed line\n"); + hts_log_error("Malformed line"); return -1; } @@ -70,7 +73,7 @@ static inline int fai_insert_index(faidx_t *idx, const char *name, int64_t len, faidx1_t *v = &kh_value(idx->hash, k); if (! absent) { - fprintf(stderr, "[fai_build_core] ignoring duplicate sequence \"%s\" at byte offset %"PRIu64"\n", name, offset); + hts_log_warning("Ignoring duplicate sequence \"%s\" at byte offset %"PRIu64"", name, offset); free(name_key); return 0; } @@ -79,7 +82,7 @@ static inline int fai_insert_index(faidx_t *idx, const char *name, int64_t len, char **tmp; idx->m = idx->m? idx->m<<1 : 16; if (!(tmp = (char**)realloc(idx->name, sizeof(char*) * idx->m))) { - fprintf(stderr, "[fai_build_core] out of memory\n"); + hts_log_error("Out of memory"); return -1; } idx->name = tmp; @@ -127,7 +130,7 @@ faidx_t *fai_build_core(BGZF *bgzf) kputsn("", 0, &name); if ( c<0 ) { - fprintf(stderr, "[fai_build_core] the last entry has no sequence\n"); + hts_log_error("The last entry has no sequence"); goto fail; } if (c != '\n') while ( (c=bgzf_getc(bgzf))>=0 && c != '\n'); @@ -135,7 +138,7 @@ faidx_t *fai_build_core(BGZF *bgzf) offset = bgzf_utell(bgzf); } else { if (state == 3) { - fprintf(stderr, "[fai_build_core] inlined empty line is not allowed in sequence '%s'.\n", name.s); + hts_log_error("Inlined empty line is not allowed in sequence '%s'", name.s); goto fail; } if (state == 2) state = 3; @@ -145,7 +148,7 @@ faidx_t *fai_build_core(BGZF *bgzf) if (isgraph(c)) ++l2; } while ( (c=bgzf_getc(bgzf))>=0 && c != '\n'); if (state == 3 && l2) { - fprintf(stderr, "[fai_build_core] different line length in sequence '%s'.\n", name.s); + hts_log_error("Different line length in sequence '%s'", name.s); goto fail; } ++l1; len += l2; @@ -172,49 +175,76 @@ faidx_t *fai_build_core(BGZF *bgzf) return NULL; } -void fai_save(const faidx_t *fai, FILE *fp) -{ +static int fai_save(const faidx_t *fai, hFILE *fp) { khint_t k; int i; + char buf[96]; // Must be big enough for format below. + for (i = 0; i < fai->n; ++i) { faidx1_t x; k = kh_get(s, fai->hash, fai->name[i]); + assert(k < kh_end(fai->hash)); x = kh_value(fai->hash, k); - fprintf(fp, "%s\t%"PRId64"\t%"PRIu64"\t%"PRId32"\t%"PRId32"\n", fai->name[i], x.len, x.offset, x.line_blen, x.line_len); + snprintf(buf, sizeof(buf), + "\t%"PRId64"\t%"PRIu64"\t%"PRId32"\t%"PRId32"\n", + x.len, x.offset, x.line_blen, x.line_len); + if (hputs(fai->name[i], fp) != 0) return -1; + if (hputs(buf, fp) != 0) return -1; } + return 0; } -static faidx_t *fai_read(FILE *fp, const char *fname) +static faidx_t *fai_read(hFILE *fp, const char *fname) { faidx_t *fai; - char *buf, *p; - int line_len, line_blen; + char *buf = NULL, *p; + int line_len, line_blen, n; int64_t len; uint64_t offset; + ssize_t l, lnum = 1; + fai = (faidx_t*)calloc(1, sizeof(faidx_t)); + if (!fai) return NULL; + fai->hash = kh_init(s); + if (!fai->hash) goto fail; + buf = (char*)calloc(0x10000, 1); - while (fgets(buf, 0x10000, fp)) { - for (p = buf; *p && isgraph_c(*p); ++p); - *p = 0; ++p; - sscanf(p, "%"SCNd64"%"SCNu64"%d%d", &len, &offset, &line_blen, &line_len); + if (!buf) goto fail; + + while ((l = hgetln(buf, 0x10000, fp)) > 0) { + for (p = buf; *p && !isspace_c(*p); ++p); + if (p - buf < l) { + *p = 0; ++p; + } + n = sscanf(p, "%"SCNd64"%"SCNu64"%d%d", &len, &offset, &line_blen, &line_len); + if (n != 4) { + hts_log_error("Could not understand FAI %s line %zd", fname, lnum); + goto fail; + } if (fai_insert_index(fai, buf, len, line_len, line_blen, offset) != 0) { - free(buf); - return NULL; + goto fail; } + if (buf[l - 1] == '\n') ++lnum; } - free(buf); - if (ferror(fp)) { - fprintf(stderr, "[fai_load] error while reading \"%s\": %s\n", fname, strerror(errno)); - fai_destroy(fai); - return NULL; + + if (l < 0) { + hts_log_error("Error while reading %s: %s", fname, strerror(errno)); + goto fail; } + free(buf); return fai; + + fail: + free(buf); + fai_destroy(fai); + return NULL; } void fai_destroy(faidx_t *fai) { int i; + if (!fai) return; for (i = 0; i < fai->n; ++i) free(fai->name[i]); free(fai->name); kh_destroy(s, fai->hash); @@ -222,173 +252,234 @@ void fai_destroy(faidx_t *fai) free(fai); } -int fai_build(const char *fn) +int fai_build3(const char *fn, const char *fnfai, const char *fngzi) { - char *str; - BGZF *bgzf; - FILE *fp; - faidx_t *fai; - str = (char*)calloc(strlen(fn) + 5, 1); - sprintf(str, "%s.fai", fn); + kstring_t fai_kstr = { 0, 0, NULL }; + kstring_t gzi_kstr = { 0, 0, NULL }; + BGZF *bgzf = NULL; + hFILE *fp = NULL; + faidx_t *fai = NULL; + int save_errno, res; + + if (!fnfai) { + if (ksprintf(&fai_kstr, "%s.fai", fn) < 0) goto fail; + fnfai = fai_kstr.s; + } + if (!fngzi) { + if (ksprintf(&gzi_kstr, "%s.gzi", fn) < 0) goto fail; + fngzi = gzi_kstr.s; + } + bgzf = bgzf_open(fn, "r"); if ( !bgzf ) { - fprintf(stderr, "[fai_build] fail to open the FASTA file %s\n",fn); - free(str); - return -1; + hts_log_error("Failed to open the FASTA file %s", fn); + goto fail; + } + if ( bgzf->is_compressed ) { + if (bgzf_index_build_init(bgzf) != 0) { + hts_log_error("Failed to allocate bgzf index"); + goto fail; + } } - if ( bgzf->is_compressed ) bgzf_index_build_init(bgzf); fai = fai_build_core(bgzf); - if ( !fai ) - { - if ( bgzf->is_compressed && bgzf->is_gzip ) fprintf(stderr,"Cannot index files compressed with gzip, please use bgzip\n"); - bgzf_close(bgzf); - free(str); - return -1; + if ( !fai ) { + if (bgzf->is_compressed && bgzf->is_gzip) { + hts_log_error("Cannot index files compressed with gzip, please use bgzip"); + } + goto fail; } if ( bgzf->is_compressed ) { - if (bgzf_index_dump(bgzf, fn, ".gzi") < 0) { - fprintf(stderr, "[fai_build] fail to make bgzf index %s.gzi\n", fn); - fai_destroy(fai); free(str); - return -1; + if (bgzf_index_dump(bgzf, fngzi, NULL) < 0) { + hts_log_error("Failed to make bgzf index %s", fngzi); + goto fail; } } - if (bgzf_close(bgzf) < 0) { - fprintf(stderr, "[fai_build] Error on closing %s\n", fn); - fai_destroy(fai); free(str); - return -1; + res = bgzf_close(bgzf); + bgzf = NULL; + if (res < 0) { + hts_log_error("Error on closing %s : %s", fn, strerror(errno)); + goto fail; } - fp = fopen(str, "wb"); + fp = hopen(fnfai, "wb"); if ( !fp ) { - fprintf(stderr, "[fai_build] fail to write FASTA index %s\n",str); - fai_destroy(fai); free(str); - return -1; + hts_log_error("Failed to open FASTA index %s : %s", fnfai, strerror(errno)); + goto fail; + } + if (fai_save(fai, fp) != 0) { + hts_log_error("Failed to write FASTA index %s : %s", fnfai, strerror(errno)); + goto fail; + } + if (hclose(fp) != 0) { + hts_log_error("Failed on closing FASTA index %s : %s", fnfai, strerror(errno)); + goto fail; } - fai_save(fai, fp); - fclose(fp); - free(str); + + free(fai_kstr.s); + free(gzi_kstr.s); fai_destroy(fai); return 0; + + fail: + save_errno = errno; + free(fai_kstr.s); + free(gzi_kstr.s); + bgzf_close(bgzf); + fai_destroy(fai); + errno = save_errno; + return -1; } -static FILE *download_and_open(const char *fn) +int fai_build(const char *fn) { + return fai_build3(fn, NULL, NULL); +} + +faidx_t *fai_load3(const char *fn, const char *fnfai, const char *fngzi, + int flags) { - const int buf_size = 1 * 1024 * 1024; - uint8_t *buf; - FILE *fp; - hFILE *fp_remote; - const char *url = fn; - const char *p; - int l = strlen(fn); - for (p = fn + l - 1; p >= fn; --p) - if (*p == '/') break; - fn = p + 1; - - // First try to open a local copy - fp = fopen(fn, "r"); - if (fp) - return fp; - - // If failed, download from remote and open - fp_remote = hopen(url, "rb"); - if (fp_remote == 0) { - fprintf(stderr, "[download_from_remote] fail to open remote file %s\n",url); + kstring_t fai_kstr = { 0, 0, NULL }; + kstring_t gzi_kstr = { 0, 0, NULL }; + hFILE *fp = NULL; + faidx_t *fai = NULL; + int res; + + if (fn == NULL) return NULL; + + if (fnfai == NULL) { + if (ksprintf(&fai_kstr, "%s.fai", fn) < 0) goto fail; + fnfai = fai_kstr.s; } - if ((fp = fopen(fn, "wb")) == 0) { - fprintf(stderr, "[download_from_remote] fail to create file in the working directory %s\n",fn); - hclose_abruptly(fp_remote); - return NULL; + if (fngzi == NULL) { + if (ksprintf(&gzi_kstr, "%s.gzi", fn) < 0) goto fail; + fngzi = gzi_kstr.s; } - buf = (uint8_t*)calloc(buf_size, 1); - while ((l = hread(fp_remote, buf, buf_size)) > 0) - fwrite(buf, 1, l, fp); - free(buf); - fclose(fp); - if (hclose(fp_remote) != 0) - fprintf(stderr, "[download_from_remote] fail to close remote file %s\n", url); - - return fopen(fn, "r"); -} -faidx_t *fai_load(const char *fn) -{ - char *str; - FILE *fp; - faidx_t *fai; - str = (char*)calloc(strlen(fn) + 5, 1); - sprintf(str, "%s.fai", fn); + fp = hopen(fnfai, "rb"); - if (hisremote(str)) - { - fp = download_and_open(str); - if ( !fp ) - { - fprintf(stderr, "[fai_load] failed to open remote FASTA index %s\n", str); - free(str); - return 0; + if (fp == 0) { + if (!(flags & FAI_CREATE) || errno != ENOENT) { + hts_log_error("Failed to open FASTA index %s: %s", fnfai, strerror(errno)); + goto fail; } - } - else - fp = fopen(str, "rb"); - if (fp == 0) { - fprintf(stderr, "[fai_load] build FASTA index.\n"); - if (fai_build(fn) < 0) { - free(str); - return 0; + hts_log_info("Build FASTA index"); + + if (fai_build3(fn, fnfai, fngzi) < 0) { + goto fail; } - fp = fopen(str, "rb"); + + fp = hopen(fnfai, "rb"); if (fp == 0) { - fprintf(stderr, "[fai_load] failed to open FASTA index: %s\n", strerror(errno)); - free(str); - return 0; + hts_log_error("Failed to open FASTA index %s: %s", fnfai, strerror(errno)); + goto fail; } } - fai = fai_read(fp, str); - fclose(fp); - free(str); + fai = fai_read(fp, fnfai); if (fai == NULL) { - return NULL; + hts_log_error("Failed to read FASTA index %s", fnfai); + goto fail; + } + + res = hclose(fp); + fp = NULL; + if (res < 0) { + hts_log_error("Failed on closing FASTA index %s : %s", fnfai, strerror(errno)); + goto fail; } fai->bgzf = bgzf_open(fn, "rb"); if (fai->bgzf == 0) { - fprintf(stderr, "[fai_load] fail to open FASTA file.\n"); - return 0; + hts_log_error("Failed to open FASTA file %s", fn); + goto fail; } - if ( fai->bgzf->is_compressed==1 ) - { - if ( bgzf_index_load(fai->bgzf, fn, ".gzi") < 0 ) - { - fprintf(stderr, "[fai_load] failed to load .gzi index: %s[.gzi]\n", fn); - fai_destroy(fai); - return NULL; + if ( fai->bgzf->is_compressed==1 ) { + if ( bgzf_index_load(fai->bgzf, fngzi, NULL) < 0 ) { + hts_log_error("Failed to load .gzi index: %s", fngzi); + goto fail; } } + free(fai_kstr.s); + free(gzi_kstr.s); return fai; + + fail: + if (fai) fai_destroy(fai); + if (fp) hclose_abruptly(fp); + free(fai_kstr.s); + free(gzi_kstr.s); + return NULL; } -char *fai_fetch(const faidx_t *fai, const char *str, int *len) +faidx_t *fai_load(const char *fn) { + return fai_load3(fn, NULL, NULL, FAI_CREATE); +} + +static char *fai_retrieve(const faidx_t *fai, const faidx1_t *val, + long beg, long end, int *len) { char *s; - int c, i, l, k, name_end; + size_t l; + int c = 0; + int ret = bgzf_useek(fai->bgzf, + val->offset + + beg / val->line_blen * val->line_len + + beg % val->line_blen, SEEK_SET); + + if (ret < 0) { + *len = -1; + hts_log_error("Failed to retrieve block. (Seeking in a compressed, .gzi unindexed, file?)"); + return NULL; + } + + l = 0; + s = (char*)malloc((size_t) end - beg + 2); + if (!s) { + *len = -1; + return NULL; + } + + while ( l < end - beg && (c=bgzf_getc(fai->bgzf))>=0 ) + if (isgraph(c)) s[l++] = c; + if (c < 0) { + hts_log_error("Failed to retrieve block: %s", + c == -1 ? "unexpected end of file" : "error reading file"); + free(s); + *len = -1; + return NULL; + } + + s[l] = '\0'; + *len = l < INT_MAX ? l : INT_MAX; + return s; +} + +char *fai_fetch(const faidx_t *fai, const char *str, int *len) +{ + char *s, *ep; + size_t i, l, k, name_end; khiter_t iter; faidx1_t val; khash_t(s) *h; - int beg, end; + long beg, end; beg = end = -1; h = fai->hash; name_end = l = strlen(str); s = (char*)malloc(l+1); + if (!s) { + *len = -1; + return NULL; + } + // remove space for (i = k = 0; i < l; ++i) if (!isspace_c(str[i])) s[k++] = str[i]; - s[k] = 0; l = k; + s[k] = 0; + name_end = l = k; // determine the sequence name - for (i = l - 1; i >= 0; --i) if (s[i] == ':') break; // look for colon from the end - if (i >= 0) name_end = i; + for (i = l; i > 0; --i) if (s[i - 1] == ':') break; // look for colon from the end + if (i > 0) name_end = i - 1; if (name_end < l) { // check if this is really the end int n_hyphen = 0; for (i = name_end + 1; i < l; ++i) { @@ -400,28 +491,44 @@ char *fai_fetch(const faidx_t *fai, const char *str, int *len) iter = kh_get(s, h, s); if (iter == kh_end(h)) { // cannot find the sequence name iter = kh_get(s, h, str); // try str as the name - if (iter == kh_end(h)) { - *len = 0; - free(s); return 0; - } else s[name_end] = ':', name_end = l; + if (iter != kh_end(h)) { + s[name_end] = ':'; + name_end = l; + } } } else iter = kh_get(s, h, str); if(iter == kh_end(h)) { - fprintf(stderr, "[fai_fetch] Warning - Reference %s not found in FASTA file, returning empty sequence\n", str); + hts_log_warning("Reference %s not found in FASTA file, returning empty sequence", str); free(s); *len = -2; return 0; - }; + } val = kh_value(h, iter); // parse the interval if (name_end < l) { + int save_errno = errno; + errno = 0; for (i = k = name_end + 1; i < l; ++i) if (s[i] != ',') s[k++] = s[i]; s[k] = 0; - beg = atoi(s + name_end + 1); - for (i = name_end + 1; i != k; ++i) if (s[i] == '-') break; - end = i < k? atoi(s + i + 1) : val.len; + if (s[name_end + 1] == '-') { + beg = 0; + i = name_end + 2; + } else { + beg = strtol(s + name_end + 1, &ep, 10); + for (i = ep - s; i < k;) if (s[i++] == '-') break; + } + end = i < k? strtol(s + i, &ep, 10) : val.len; if (beg > 0) --beg; + // Check for out of range numbers. Only going to be a problem on + // 32-bit platforms with >2Gb sequence length. + if (errno == ERANGE && (uint64_t) val.len > LONG_MAX) { + hts_log_error("Positions in range %s are too large for this platform", s); + free(s); + *len = -2; + return NULL; + } + errno = save_errno; } else beg = 0, end = val.len; if (beg >= val.len) beg = val.len; if (end >= val.len) end = val.len; @@ -429,20 +536,7 @@ char *fai_fetch(const faidx_t *fai, const char *str, int *len) free(s); // now retrieve the sequence - int ret = bgzf_useek(fai->bgzf, val.offset + beg / val.line_blen * val.line_len + beg % val.line_blen, SEEK_SET); - if ( ret<0 ) - { - *len = -1; - fprintf(stderr, "[fai_fetch] Error: fai_fetch failed. (Seeking in a compressed, .gzi unindexed, file?)\n"); - return NULL; - } - l = 0; - s = (char*)malloc(end - beg + 2); - while ( (c=bgzf_getc(fai->bgzf))>=0 && l < end - beg ) - if (isgraph(c)) s[l++] = c; - s[l] = '\0'; - *len = l; - return s; + return fai_retrieve(fai, &val, beg, end, len); } int faidx_fetch_nseq(const faidx_t *fai) @@ -469,17 +563,15 @@ int faidx_seq_len(const faidx_t *fai, const char *seq) char *faidx_fetch_seq(const faidx_t *fai, const char *c_name, int p_beg_i, int p_end_i, int *len) { - int l, c; khiter_t iter; faidx1_t val; - char *seq=NULL; // Adjust position iter = kh_get(s, fai->hash, c_name); if (iter == kh_end(fai->hash)) { *len = -2; - fprintf(stderr, "[fai_fetch_seq] The sequence \"%s\" not found\n", c_name); + hts_log_error("The sequence \"%s\" not found", c_name); return NULL; } val = kh_value(fai->hash, iter); @@ -490,20 +582,7 @@ char *faidx_fetch_seq(const faidx_t *fai, const char *c_name, int p_beg_i, int p else if(val.len <= p_end_i) p_end_i = val.len - 1; // Now retrieve the sequence - int ret = bgzf_useek(fai->bgzf, val.offset + p_beg_i / val.line_blen * val.line_len + p_beg_i % val.line_blen, SEEK_SET); - if ( ret<0 ) - { - *len = -1; - fprintf(stderr, "[fai_fetch_seq] Error: fai_fetch failed. (Seeking in a compressed, .gzi unindexed, file?)\n"); - return NULL; - } - l = 0; - seq = (char*)malloc(p_end_i - p_beg_i + 2); - while ( (c=bgzf_getc(fai->bgzf))>=0 && l < p_end_i - p_beg_i + 1) - if (isgraph(c)) seq[l++] = c; - seq[l] = '\0'; - *len = l; - return seq; + return fai_retrieve(fai, &val, p_beg_i, (long) p_end_i + 1, len); } int faidx_has_seq(const faidx_t *fai, const char *seq) diff --git a/htslib/hfile.c b/htslib/hfile.c index 30d77e894..74dc3bdfc 100644 --- a/htslib/hfile.c +++ b/htslib/hfile.c @@ -26,6 +26,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include +#include #include #include #include @@ -60,6 +61,8 @@ DEALINGS IN THE SOFTWARE. */ off_t offset; // Offset within the stream of buffer position 0 unsigned at_eof:1;// For reading, whether EOF has been seen + unsigned mobile:1;// Buffer is a mobile window or fixed full contents + unsigned readonly:1;// Whether opened as "r" rather than "r+"/"w"/"a" int has_errno; // Error number from the last failure on this stream For reading, begin is the first unread character in the buffer and end is the @@ -78,7 +81,17 @@ equal to buffer: Thus if begin > end then there is a non-empty write buffer, if begin < end then there is a non-empty read buffer, and if begin == end then both buffers are empty. In all cases, the stream's file position indicator corresponds -to the position pointed to by begin. */ +to the position pointed to by begin. + +The above is the normal scenario of a mobile window. For in-memory +streams (eg via hfile_init_fixed) the buffer can be used as the full +contents without any separate backend behind it. These always have at_eof +set, offset set to 0, need no read() method, and should just return EINVAL +for seek(): + + abcdefghijkLMNOPQRSTUVWXYZ------ + ^buffer ^begin ^end ^limit +*/ hFILE *hfile_init(size_t struct_size, const char *mode, size_t capacity) { @@ -97,6 +110,8 @@ hFILE *hfile_init(size_t struct_size, const char *mode, size_t capacity) fp->offset = 0; fp->at_eof = 0; + fp->mobile = 1; + fp->readonly = (strchr(mode, 'r') && ! strchr(mode, '+')); fp->has_errno = 0; return fp; @@ -105,6 +120,26 @@ hFILE *hfile_init(size_t struct_size, const char *mode, size_t capacity) return NULL; } +hFILE *hfile_init_fixed(size_t struct_size, const char *mode, + char *buffer, size_t buf_filled, size_t buf_size) +{ + hFILE *fp = (hFILE *) malloc(struct_size); + if (fp == NULL) return NULL; + + fp->buffer = fp->begin = buffer; + fp->end = &fp->buffer[buf_filled]; + fp->limit = &fp->buffer[buf_size]; + + fp->offset = 0; + fp->at_eof = 1; + fp->mobile = 0; + fp->readonly = (strchr(mode, 'r') && ! strchr(mode, '+')); + fp->has_errno = 0; + return fp; +} + +static const struct hFILE_backend mem_backend; + void hfile_destroy(hFILE *fp) { int save = errno; @@ -126,7 +161,7 @@ static ssize_t refill_buffer(hFILE *fp) ssize_t n; // Move any unread characters to the start of the buffer - if (fp->begin > fp->buffer) { + if (fp->mobile && fp->begin > fp->buffer) { fp->offset += fp->begin - fp->buffer; memmove(fp->buffer, fp->begin, fp->end - fp->begin); fp->end = &fp->buffer[fp->end - fp->begin]; @@ -145,6 +180,36 @@ static ssize_t refill_buffer(hFILE *fp) return n; } +/* + * Changes the buffer size for an hFILE. Ideally this is done + * immediately after opening. If performed later, this function may + * fail if we are reducing the buffer size and the current offset into + * the buffer is beyond the new capacity. + * + * Returns 0 on success; + * -1 on failure. + */ +int hfile_set_blksize(hFILE *fp, size_t bufsiz) { + char *buffer; + ptrdiff_t curr_used; + if (!fp) return -1; + curr_used = (fp->begin > fp->end ? fp->begin : fp->end) - fp->buffer; + if (bufsiz == 0) bufsiz = 32768; + + // Ensure buffer resize will not erase live data + if (bufsiz < curr_used) + return -1; + + if (!(buffer = (char *) realloc(fp->buffer, bufsiz))) return -1; + + fp->begin = buffer + (fp->begin - fp->buffer); + fp->end = buffer + (fp->end - fp->buffer); + fp->buffer = buffer; + fp->limit = &fp->buffer[bufsiz]; + + return 0; +} + /* Called only from hgetc(), when our buffer is empty. */ int hgetc2(hFILE *fp) { @@ -230,6 +295,7 @@ ssize_t hpeek(hFILE *fp, void *buffer, size_t nbytes) ssize_t hread2(hFILE *fp, void *destv, size_t nbytes, size_t nread) { const size_t capacity = fp->limit - fp->buffer; + int buffer_invalidated = 0; char *dest = (char *) destv; dest += nread, nbytes -= nread; @@ -238,11 +304,21 @@ ssize_t hread2(hFILE *fp, void *destv, size_t nbytes, size_t nread) ssize_t n = fp->backend->read(fp, dest, nbytes); if (n < 0) { fp->has_errno = errno; return n; } else if (n == 0) fp->at_eof = 1; + else buffer_invalidated = 1; fp->offset += n; dest += n, nbytes -= n; nread += n; } + if (buffer_invalidated) { + // Our unread buffer is empty, so begin == end, but our already-read + // buffer [buffer,begin) is likely non-empty and is no longer valid as + // its contents are no longer adjacent to the file position indicator. + // Discard it so that hseek() can't try to take advantage of it. + fp->offset += fp->begin - fp->buffer; + fp->begin = fp->end = fp->buffer; + } + while (nbytes > 0 && !fp->at_eof) { size_t n; ssize_t ret = refill_buffer(fp); @@ -330,7 +406,7 @@ off_t hseek(hFILE *fp, off_t offset, int whence) { off_t curpos, pos; - if (writebuffer_is_nonempty(fp)) { + if (writebuffer_is_nonempty(fp) && fp->mobile) { int ret = flush_buffer(fp); if (ret < 0) return ret; } @@ -351,8 +427,26 @@ off_t hseek(hFILE *fp, off_t offset, int whence) whence = SEEK_SET; offset = curpos + offset; } + // For fixed immobile buffers, convert everything else to SEEK_SET too + // so that seeking can be avoided for all (within range) requests. + else if (! fp->mobile && whence == SEEK_END) { + size_t length = fp->end - fp->buffer; + if (offset > 0 || -offset > length) { + fp->has_errno = errno = EINVAL; + return -1; + } + + whence = SEEK_SET; + offset = length + offset; + } - // TODO Avoid seeking if the desired position is within our read buffer + // Avoid seeking if the desired position is within our read buffer. + // (But not when the next operation may be a write on a mobile buffer.) + if (whence == SEEK_SET && (! fp->mobile || fp->readonly) && + offset >= fp->offset && offset - fp->offset <= fp->end - fp->buffer) { + fp->begin = &fp->buffer[offset - fp->offset]; + return offset; + } pos = fp->backend->seek(fp, offset, whence); if (pos < 0) { fp->has_errno = errno; return pos; } @@ -434,6 +528,18 @@ static ssize_t fd_write(hFILE *fpv, const void *buffer, size_t nbytes) n = fp->is_socket? send(fp->fd, buffer, nbytes, 0) : write(fp->fd, buffer, nbytes); } while (n < 0 && errno == EINTR); +#ifdef _WIN32 + // On windows we have no SIGPIPE. Instead write returns + // EINVAL. We check for this and our fd being a pipe. + // If so, we raise SIGTERM instead of SIGPIPE. It's not + // ideal, but I think the only alternative is extra checking + // in every single piece of code. + if (n < 0 && errno == EINVAL && + GetLastError() == ERROR_NO_DATA && + GetFileType((HANDLE)_get_osfhandle(fp->fd)) == FILE_TYPE_PIPE) { + raise(SIGTERM); + } +#endif return n; } @@ -445,12 +551,13 @@ static off_t fd_seek(hFILE *fpv, off_t offset, int whence) static int fd_flush(hFILE *fpv) { - hFILE_fd *fp = (hFILE_fd *) fpv; - int ret; + int ret = 0; do { #ifdef HAVE_FDATASYNC + hFILE_fd *fp = (hFILE_fd *) fpv; ret = fdatasync(fp->fd); -#else +#elif defined(HAVE_FSYNC) + hFILE_fd *fp = (hFILE_fd *) fpv; ret = fsync(fp->fd); #endif // Ignore invalid-for-fsync(2) errors due to being, e.g., a pipe, @@ -510,6 +617,56 @@ static hFILE *hopen_fd(const char *filename, const char *mode) return NULL; } +// Loads the contents of filename to produced a read-only, in memory, +// immobile hfile. fp is the already opened file. We always close this +// input fp, irrespective of whether we error or whether we return a new +// immobile hfile. +static hFILE *hpreload(hFILE *fp) { + hFILE *mem_fp; + char *buf = NULL; + off_t buf_sz = 0, buf_a = 0, buf_inc = 8192, len; + + for (;;) { + if (buf_a - buf_sz < 5000) { + buf_a += buf_inc; + char *t = realloc(buf, buf_a); + if (!t) goto err; + buf = t; + if (buf_inc < 1000000) buf_inc *= 1.3; + } + len = hread(fp, buf+buf_sz, buf_a-buf_sz); + if (len > 0) + buf_sz += len; + else + break; + } + + if (len < 0) goto err; + mem_fp = hfile_init_fixed(sizeof(hFILE), "r", buf, buf_sz, buf_a); + if (!mem_fp) goto err; + mem_fp->backend = &mem_backend; + + if (hclose(fp) < 0) { + hclose_abruptly(mem_fp); + goto err; + } + return mem_fp; + + err: + free(buf); + hclose_abruptly(fp); + return NULL; +} + +static int is_preload_url_remote(const char *url){ + return hisremote(url + 8); // len("preload:") = 8 +} + +static hFILE *hopen_preload(const char *url, const char *mode){ + hFILE* fp = hopen(url + 8, mode); + return hpreload(fp); +} + hFILE *hdopen(int fd, const char *mode) { hFILE_fd *fp = (hFILE_fd*) hfile_init(sizeof (hFILE_fd), mode, blksize(fd)); @@ -527,6 +684,11 @@ static hFILE *hopen_fd_fileuri(const char *url, const char *mode) else if (strncmp(url, "file:///", 8) == 0) url += 7; else { errno = EPROTONOSUPPORT; return NULL; } +#ifdef _WIN32 + // For cases like C:/foo + if (url[0] == '/' && url[2] == ':' && url[3] == '/') url++; +#endif + return hopen_fd(url, mode); } @@ -570,43 +732,16 @@ int hfile_oflags(const char *mode) * In-memory backend * *********************/ +#include "hts_internal.h" + typedef struct { hFILE base; - const char *buffer; - size_t length, pos; } hFILE_mem; -static ssize_t mem_read(hFILE *fpv, void *buffer, size_t nbytes) -{ - hFILE_mem *fp = (hFILE_mem *) fpv; - size_t avail = fp->length - fp->pos; - if (nbytes > avail) nbytes = avail; - memcpy(buffer, fp->buffer + fp->pos, nbytes); - fp->pos += nbytes; - return nbytes; -} - static off_t mem_seek(hFILE *fpv, off_t offset, int whence) { - hFILE_mem *fp = (hFILE_mem *) fpv; - size_t absoffset = (offset >= 0)? offset : -offset; - size_t origin; - - switch (whence) { - case SEEK_SET: origin = 0; break; - case SEEK_CUR: origin = fp->pos; break; - case SEEK_END: origin = fp->length; break; - default: errno = EINVAL; return -1; - } - - if ((offset < 0 && absoffset > origin) || - (offset >= 0 && absoffset > fp->length - origin)) { - errno = EINVAL; - return -1; - } - - fp->pos = origin + offset; - return fp->pos; + errno = EINVAL; + return -1; } static int mem_close(hFILE *fpv) @@ -616,35 +751,114 @@ static int mem_close(hFILE *fpv) static const struct hFILE_backend mem_backend = { - mem_read, NULL, mem_seek, NULL, mem_close + NULL, NULL, mem_seek, NULL, mem_close }; -static hFILE *hopen_mem(const char *data, const char *mode) +static int cmp_prefix(const char *key, const char *s) { - if (strncmp(data, "data:", 5) == 0) data += 5; + while (*key) + if (tolower_c(*s) != *key) return +1; + else s++, key++; - // TODO Implement write modes, which will require memory allocation - if (strchr(mode, 'r') == NULL) { errno = EINVAL; return NULL; } + return 0; +} - hFILE_mem *fp = (hFILE_mem *) hfile_init(sizeof (hFILE_mem), mode, 0); - if (fp == NULL) return NULL; +static hFILE *create_hfile_mem(char* buffer, const char* mode, size_t buf_filled, size_t buf_size) +{ + hFILE_mem *fp = (hFILE_mem *) hfile_init_fixed(sizeof(hFILE_mem), mode, buffer, buf_filled, buf_size); + if (fp == NULL) + return NULL; - fp->buffer = data; - fp->length = strlen(data); - fp->pos = 0; fp->base.backend = &mem_backend; return &fp->base; } +static hFILE *hopen_mem(const char *url, const char *mode) +{ + size_t length, size; + char *buffer; + const char *data, *comma = strchr(url, ','); + if (comma == NULL) { errno = EINVAL; return NULL; } + data = comma+1; + + // TODO Implement write modes + if (strchr(mode, 'r') == NULL) { errno = EROFS; return NULL; } + + if (comma - url >= 7 && cmp_prefix(";base64", &comma[-7]) == 0) { + size = hts_base64_decoded_length(strlen(data)); + buffer = malloc(size); + if (buffer == NULL) return NULL; + hts_decode_base64(buffer, &length, data); + } + else { + size = strlen(data) + 1; + buffer = malloc(size); + if (buffer == NULL) return NULL; + hts_decode_percent(buffer, &length, data); + } + hFILE* hf; + + if(!(hf = create_hfile_mem(buffer, mode, length, size))){ + free(buffer); + return NULL; + } + + return hf; +} + +hFILE *hopenv_mem(const char *filename, const char *mode, va_list args) +{ + char* buffer = va_arg(args, char*); + size_t sz = va_arg(args, size_t); + va_end(args); + + hFILE* hf; + + if(!(hf = create_hfile_mem(buffer, mode, sz, sz))){ + free(buffer); + return NULL; + } + + return hf; +} + +char *hfile_mem_get_buffer(hFILE *file, size_t *length) { + if (file->backend != &mem_backend) { + errno = EINVAL; + return NULL; + } + + if (length) + *length = file->buffer - file->limit; + + return file->buffer; +} + +char *hfile_mem_steal_buffer(hFILE *file, size_t *length) { + char *buf = hfile_mem_get_buffer(file, length); + if (buf) + file->buffer = NULL; + return buf; +} + +int hfile_plugin_init_mem(struct hFILE_plugin *self) +{ + // mem files are declared remote so they work with a tabix index + static const struct hFILE_scheme_handler handler = + {NULL, hfile_always_remote, "mem", 2000 + 50, hopenv_mem}; + self->name = "mem"; + hfile_add_scheme_handler("mem", &handler); + return 0; +} + /***************************************** * Plugin and hopen() backend dispatcher * *****************************************/ -#include "hts_internal.h" #include "htslib/khash.h" -KHASH_MAP_INIT_STR(scheme_string, const struct hFILE_scheme_handler *); +KHASH_MAP_INIT_STR(scheme_string, const struct hFILE_scheme_handler *) static khash_t(scheme_string) *schemes = NULL; struct hFILE_plugin_list { @@ -675,12 +889,17 @@ static void hfile_exit() pthread_mutex_destroy(&plugins_lock); } +static inline int priority(const struct hFILE_scheme_handler *handler) +{ + return handler->priority % 1000; +} + void hfile_add_scheme_handler(const char *scheme, const struct hFILE_scheme_handler *handler) { int absent; khint_t k = kh_put(scheme_string, schemes, scheme, &absent); - if (absent || handler->priority > kh_value(schemes, k)->priority) { + if (absent || priority(handler) > priority(kh_value(schemes, k))) { kh_value(schemes, k) = handler; } } @@ -699,16 +918,12 @@ static int init_add_plugin(void *obj, int (*init)(struct hFILE_plugin *), int ret = (*init)(&p->plugin); if (ret != 0) { - if (hts_verbose >= 4) - fprintf(stderr, "[W::load_hfile_plugins] " - "initialisation failed for plugin \"%s\": %d\n", - pluginname, ret); + hts_log_debug("Initialisation failed for plugin \"%s\": %d", pluginname, ret); free(p); return ret; } - if (hts_verbose >= 5) - fprintf(stderr, "[M::load_hfile_plugins] loaded \"%s\"\n", pluginname); + hts_log_debug("Loaded \"%s\"", pluginname); p->next = plugins, plugins = p; return 0; @@ -718,14 +933,17 @@ static void load_hfile_plugins() { static const struct hFILE_scheme_handler data = { hopen_mem, hfile_always_local, "built-in", 80 }, - file = { hopen_fd_fileuri, hfile_always_local, "built-in", 80 }; + file = { hopen_fd_fileuri, hfile_always_local, "built-in", 80 }, + preload = { hopen_preload, is_preload_url_remote, "built-in", 80 }; schemes = kh_init(scheme_string); if (schemes == NULL) abort(); hfile_add_scheme_handler("data", &data); hfile_add_scheme_handler("file", &file); + hfile_add_scheme_handler("preload", &preload); init_add_plugin(NULL, hfile_plugin_init_net, "knetfile"); + init_add_plugin(NULL, hfile_plugin_init_mem, "mem"); #ifdef ENABLE_PLUGINS struct hts_path_itr path; @@ -746,6 +964,12 @@ static void load_hfile_plugins() #ifdef HAVE_LIBCURL init_add_plugin(NULL, hfile_plugin_init_libcurl, "libcurl"); #endif +#ifdef ENABLE_GCS + init_add_plugin(NULL, hfile_plugin_init_gcs, "gcs"); +#endif +#ifdef ENABLE_S3 + init_add_plugin(NULL, hfile_plugin_init_s3, "s3"); +#endif #endif @@ -781,7 +1005,8 @@ static const struct hFILE_scheme_handler *find_scheme_handler(const char *s) else if (s[i] == ':') break; else return NULL; - if (i == 0 || i >= sizeof scheme) return NULL; + // 1 byte schemes are likely windows C:/foo pathnames + if (i <= 1 || i >= sizeof scheme) return NULL; scheme[i] = '\0'; pthread_mutex_lock(&plugins_lock); @@ -792,10 +1017,24 @@ static const struct hFILE_scheme_handler *find_scheme_handler(const char *s) return (k != kh_end(schemes))? kh_value(schemes, k) : &unknown_scheme; } -hFILE *hopen(const char *fname, const char *mode) +hFILE *hopen(const char *fname, const char *mode, ...) { const struct hFILE_scheme_handler *handler = find_scheme_handler(fname); - if (handler) return handler->open(fname, mode); + if (handler) { + if (strchr(mode, ':') == NULL + || handler->priority < 2000 + || handler->vopen == NULL) { + return handler->open(fname, mode); + } + else { + hFILE *fp; + va_list arg; + va_start(arg, mode); + fp = handler->vopen(fname, mode, arg); + va_end(arg); + return fp; + } + } else if (strcmp(fname, "-") == 0) return hopen_fd_stdinout(mode); else return hopen_fd(fname, mode); } diff --git a/htslib/hfile_gcs.c b/htslib/hfile_gcs.c new file mode 100644 index 000000000..cdf2076b9 --- /dev/null +++ b/htslib/hfile_gcs.c @@ -0,0 +1,137 @@ +/* hfile_gcs.c -- Google Cloud Storage backend for low-level file streams. + + Copyright (C) 2016 Genome Research Ltd. + + Author: John Marshall + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include + +#include +#include +#include +#include +#include + +#include "htslib/hts.h" +#include "htslib/kstring.h" +#include "hfile_internal.h" +#ifdef ENABLE_PLUGINS +#include "version.h" +#endif + +static hFILE * +gcs_rewrite(const char *gsurl, const char *mode, int mode_has_colon, + va_list *argsp) +{ + const char *bucket, *path, *access_token; + kstring_t mode_colon = { 0, 0, NULL }; + kstring_t url = { 0, 0, NULL }; + kstring_t auth_hdr = { 0, 0, NULL }; + hFILE *fp = NULL; + + // GCS URL format is gs[+SCHEME]://BUCKET/PATH + + if (gsurl[2] == '+') { + bucket = strchr(gsurl, ':') + 1; + kputsn(&gsurl[3], bucket - &gsurl[3], &url); + } + else { + kputs("https:", &url); + bucket = &gsurl[3]; + } + while (*bucket == '/') kputc(*bucket++, &url); + + path = bucket + strcspn(bucket, "/?#"); + + kputsn(bucket, path - bucket, &url); + if (strchr(mode, 'r')) kputs(".storage-download", &url); + else if (strchr(mode, 'w')) kputs(".storage-upload", &url); + else kputs(".storage", &url); + kputs(".googleapis.com", &url); + + kputs(path, &url); + + if (hts_verbose >= 8) + fprintf(stderr, "[M::gcs_open] rewrote URL as %s\n", url.s); + + // TODO Find the access token in a more standard way + access_token = getenv("GCS_OAUTH_TOKEN"); + + if (access_token) { + kputs("Authorization: Bearer ", &auth_hdr); + kputs(access_token, &auth_hdr); + } + + if (argsp || auth_hdr.l > 0 || mode_has_colon) { + if (! mode_has_colon) { + kputs(mode, &mode_colon); + kputc(':', &mode_colon); + mode = mode_colon.s; + } + + fp = hopen(url.s, mode, "va_list", argsp, + "httphdr", (auth_hdr.l > 0)? auth_hdr.s : NULL, NULL); + } + else + fp = hopen(url.s, mode); + + free(mode_colon.s); + free(url.s); + free(auth_hdr.s); + return fp; +} + +static hFILE *gcs_open(const char *url, const char *mode) +{ + return gcs_rewrite(url, mode, 0, NULL); +} + +static hFILE *gcs_vopen(const char *url, const char *mode_colon, va_list args0) +{ + // Need to use va_copy() as we can only take the address of an actual + // va_list object, not that of a parameter as its type may have decayed. + va_list args; + va_copy(args, args0); + hFILE *fp = gcs_rewrite(url, mode_colon, 1, &args); + va_end(args); + return fp; +} + +int PLUGIN_GLOBAL(hfile_plugin_init,_gcs)(struct hFILE_plugin *self) +{ + static const struct hFILE_scheme_handler handler = + { gcs_open, hfile_always_remote, "Google Cloud Storage", + 2000 + 50, gcs_vopen + }; + +#ifdef ENABLE_PLUGINS + // Embed version string for examination via strings(1) or what(1) + static const char id[] = "@(#)hfile_gcs plugin (htslib)\t" HTS_VERSION; + if (hts_verbose >= 9) + fprintf(stderr, "[M::hfile_gcs.init] version %s\n", strchr(id, '\t')+1); +#endif + + self->name = "Google Cloud Storage"; + hfile_add_scheme_handler("gs", &handler); + hfile_add_scheme_handler("gs+http", &handler); + hfile_add_scheme_handler("gs+https", &handler); + return 0; +} diff --git a/htslib/hfile_internal.h b/htslib/hfile_internal.h index 947bd04de..c243f8e77 100644 --- a/htslib/hfile_internal.h +++ b/htslib/hfile_internal.h @@ -1,6 +1,6 @@ /* hfile_internal.h -- internal parts of low-level input/output streams. - Copyright (C) 2013-2015 Genome Research Ltd. + Copyright (C) 2013-2016 Genome Research Ltd. Author: John Marshall @@ -25,12 +25,37 @@ DEALINGS IN THE SOFTWARE. */ #ifndef HFILE_INTERNAL_H #define HFILE_INTERNAL_H +#include + #include "htslib/hfile.h" +#include "textutils_internal.h" + #ifdef __cplusplus extern "C" { #endif +/*! + @abstract Resizes the buffer within an hFILE. + + @notes Changes the buffer size for an hFILE. Ideally this is done + immediately after opening. If performed later, this function may + fail if we are reducing the buffer size and the current offset into + the buffer is beyond the new capacity. + + @param fp The file stream + @param bufsiz The size of the new buffer + + @return Returns 0 on success, -1 on failure. + */ +int hfile_set_blksize(hFILE *fp, size_t bufsiz); + +struct BGZF; +/*! + @abstract Return the hFILE connected to a BGZF + */ +struct hFILE *bgzf_hfile(struct BGZF *fp); + struct hFILE_backend { /* As per read(2), returning the number of bytes read (possibly 0) or negative (and setting errno) on errors. Front-end code will call this @@ -66,6 +91,13 @@ int hfile_oflags(const char *mode); or 0 for a default-sized buffer. */ hFILE *hfile_init(size_t struct_size, const char *mode, size_t capacity); +/* Alternative to hfile_init() for in-memory backends for which the base + buffer is the only storage. Buffer is already allocated via malloc(2) + of size buf_size and with buf_filled bytes already filled. Ownership + of the buffer is transferred to the resulting hFILE. */ +hFILE *hfile_init_fixed(size_t struct_size, const char *mode, + char *buffer, size_t buf_filled, size_t buf_size); + /* May be called by hopen_*() functions to undo the effects of hfile_init() in the event opening the stream subsequently fails. (This is safe to use even if fp is NULL. This takes care to preserve errno.) */ @@ -86,8 +118,17 @@ struct hFILE_scheme_handler { const char *provider; /* If multiple handlers are registered for the same scheme, the one with - the highest priority is used; range is 0 (lowest) to 100 (highest). */ + the highest priority is used; range is 0 (lowest) to 100 (highest). + This field is used modulo 1000 as a priority; thousands indicate + later revisions to this structure, as noted below. */ int priority; + + /* Fields below are present when priority >= 2000. */ + + /* Same as the open() method, used when extra arguments have been given + to hopen(). */ + hFILE *(*vopen)(const char *filename, const char *mode, va_list args) + HTS_RESULT_USED; }; /* May be used as an isremote() function in simple cases. */ @@ -125,12 +166,19 @@ extern int hfile_plugin_init(struct hFILE_plugin *self); even with --disable-plugins need to use PLUGIN_GLOBAL and be listed here; others can simply define hfile_plugin_init(). */ +extern int hfile_plugin_init_gcs(struct hFILE_plugin *self); extern int hfile_plugin_init_libcurl(struct hFILE_plugin *self); +extern int hfile_plugin_init_s3(struct hFILE_plugin *self); #endif /* This one is never built as a separate plugin. */ extern int hfile_plugin_init_net(struct hFILE_plugin *self); +// Callback to allow headers to be set in http connections. Currently used +// to allow s3 to renew tokens when seeking. Kept internal for now, +// although we may consider exposing it in the API later. +typedef int (* hts_httphdr_callback) (void *cb_data, char ***hdrs); + #ifdef __cplusplus } #endif diff --git a/htslib/hfile_libcurl.c b/htslib/hfile_libcurl.c index e9e57a19a..eee69242e 100644 --- a/htslib/hfile_libcurl.c +++ b/htslib/hfile_libcurl.c @@ -1,19 +1,14 @@ /* hfile_libcurl.c -- libcurl backend for low-level file streams. - Copyright (C) 2015, 2016 Genome Research Ltd. - Author: John Marshall - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL diff --git a/htslib/hfile_s3.c b/htslib/hfile_s3.c new file mode 100644 index 000000000..98afa3deb --- /dev/null +++ b/htslib/hfile_s3.c @@ -0,0 +1,466 @@ +/* hfile_s3.c -- Amazon S3 backend for low-level file streams. + + Copyright (C) 2015-2017 Genome Research Ltd. + + Author: John Marshall + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include + +#include +#include +#include +#include +#include + +#include "hfile_internal.h" +#ifdef ENABLE_PLUGINS +#include "version.h" +#endif +#include "htslib/hts.h" // for hts_version() and hts_verbose +#include "htslib/kstring.h" + +typedef struct { + kstring_t id; + kstring_t token; + kstring_t secret; + char *bucket; + kstring_t auth_hdr; + time_t auth_time; + char date[40]; + char mode; + char *headers[3]; +} s3_auth_data; + +#define AUTH_LIFETIME 60 + +#if defined HAVE_COMMONCRYPTO + +#include + +#define DIGEST_BUFSIZ CC_SHA1_DIGEST_LENGTH + +static size_t +s3_sign(unsigned char *digest, kstring_t *key, kstring_t *message) +{ + CCHmac(kCCHmacAlgSHA1, key->s, key->l, message->s, message->l, digest); + return CC_SHA1_DIGEST_LENGTH; +} + +#elif defined HAVE_HMAC + +#include + +#define DIGEST_BUFSIZ EVP_MAX_MD_SIZE + +static size_t +s3_sign(unsigned char *digest, kstring_t *key, kstring_t *message) +{ + unsigned int len; + HMAC(EVP_sha1(), key->s, key->l, + (unsigned char *) message->s, message->l, digest, &len); + return len; +} + +#else +#error No HMAC() routine found by configure +#endif + +static void +urldecode_kput(const char *s, int len, kstring_t *str) +{ + char buf[3]; + int i = 0; + + while (i < len) + if (s[i] == '%' && i+2 < len) { + buf[0] = s[i+1], buf[1] = s[i+2], buf[2] = '\0'; + kputc(strtol(buf, NULL, 16), str); + i += 3; + } + else kputc(s[i++], str); +} + +static void base64_kput(const unsigned char *data, size_t len, kstring_t *str) +{ + static const char base64[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + size_t i = 0; + unsigned x = 0; + int bits = 0, pad = 0; + + while (bits || i < len) { + if (bits < 6) { + x <<= 8, bits += 8; + if (i < len) x |= data[i++]; + else pad++; + } + + bits -= 6; + kputc(base64[(x >> bits) & 63], str); + } + + str->l -= pad; + kputsn("==", pad, str); +} + +static int is_dns_compliant(const char *s0, const char *slim) +{ + int has_nondigit = 0, len = 0; + const char *s; + + for (s = s0; s < slim; len++, s++) + if (islower_c(*s)) + has_nondigit = 1; + else if (*s == '-') { + has_nondigit = 1; + if (s == s0 || s+1 == slim) return 0; + } + else if (isdigit_c(*s)) + ; + else if (*s == '.') { + if (s == s0 || ! isalnum_c(s[-1])) return 0; + if (s+1 == slim || ! isalnum_c(s[1])) return 0; + } + else return 0; + + return has_nondigit && len >= 3 && len <= 63; +} + +static FILE *expand_tilde_open(const char *fname, const char *mode) +{ + FILE *fp; + + if (strncmp(fname, "~/", 2) == 0) { + kstring_t full_fname = { 0, 0, NULL }; + const char *home = getenv("HOME"); + if (! home) return NULL; + + kputs(home, &full_fname); + kputs(&fname[1], &full_fname); + + fp = fopen(full_fname.s, mode); + free(full_fname.s); + } + else + fp = fopen(fname, mode); + + return fp; +} + +static void parse_ini(const char *fname, const char *section, ...) +{ + kstring_t line = { 0, 0, NULL }; + int active = 1; // Start active, so global properties are accepted + char *s; + + FILE *fp = expand_tilde_open(fname, "r"); + if (fp == NULL) return; + + while (line.l = 0, kgetline(&line, (kgets_func *) fgets, fp) >= 0) + if (line.s[0] == '[' && (s = strchr(line.s, ']')) != NULL) { + *s = '\0'; + active = (strcmp(&line.s[1], section) == 0); + } + else if (active && (s = strpbrk(line.s, ":=")) != NULL) { + const char *key = line.s, *value = &s[1], *akey; + va_list args; + + while (isspace_c(*key)) key++; + while (s > key && isspace_c(s[-1])) s--; + *s = '\0'; + + while (isspace_c(*value)) value++; + while (line.l > 0 && isspace_c(line.s[line.l-1])) + line.s[--line.l] = '\0'; + + va_start(args, section); + while ((akey = va_arg(args, const char *)) != NULL) { + kstring_t *avar = va_arg(args, kstring_t *); + if (strcmp(key, akey) == 0) { kputs(value, avar); break; } + } + va_end(args); + } + + fclose(fp); + free(line.s); +} + +static void parse_simple(const char *fname, kstring_t *id, kstring_t *secret) +{ + kstring_t text = { 0, 0, NULL }; + char *s; + size_t len; + + FILE *fp = expand_tilde_open(fname, "r"); + if (fp == NULL) return; + + while (kgetline(&text, (kgets_func *) fgets, fp) >= 0) + kputc(' ', &text); + fclose(fp); + + s = text.s; + while (isspace_c(*s)) s++; + kputsn(s, len = strcspn(s, " \t"), id); + + s += len; + while (isspace_c(*s)) s++; + kputsn(s, strcspn(s, " \t"), secret); + + free(text.s); +} + +static int copy_auth_headers(s3_auth_data *ad, char ***hdrs) { + char **hdr = &ad->headers[0]; + *hdrs = hdr; + *hdr = strdup(ad->date); + if (!*hdr) return -1; + hdr++; + if (ad->auth_hdr.l) { + *hdr = strdup(ad->auth_hdr.s); + if (!*hdr) { free(ad->headers[0]); return -1; } + hdr++; + } + *hdr = NULL; + return 0; +} + +static void free_auth_data(s3_auth_data *ad) { + free(ad->id.s); + free(ad->token.s); + free(ad->secret.s); + free(ad->bucket); + free(ad->auth_hdr.s); + free(ad); +} + +static int auth_header_callback(void *ctx, char ***hdrs) { + s3_auth_data *ad = (s3_auth_data *) ctx; + + time_t now = time(NULL); +#ifdef HAVE_GMTIME_R + struct tm tm_buffer; + struct tm *tm = gmtime_r(&now, &tm_buffer); +#else + struct tm *tm = gmtime(&now); +#endif + kstring_t message = { 0, 0, NULL }; + unsigned char digest[DIGEST_BUFSIZ]; + size_t digest_len; + + if (!hdrs) { // Closing connection + free_auth_data(ad); + return 0; + } + + if (now - ad->auth_time < AUTH_LIFETIME) { + // Last auth string should still be valid + *hdrs = NULL; + return 0; + } + + strftime(ad->date, sizeof(ad->date), "Date: %a, %d %b %Y %H:%M:%S GMT", tm); + if (!ad->id.l || !ad->secret.l) { + ad->auth_time = now; + return copy_auth_headers(ad, hdrs); + } + + if (ksprintf(&message, "%s\n\n\n%s\n%s%s%s/%s", + ad->mode == 'r' ? "GET" : "PUT", ad->date + 6, + ad->token.l ? "x-amz-security-token:" : "", + ad->token.l ? ad->token.s : "", + ad->token.l ? "\n" : "", + ad->bucket) < 0) { + return -1; + } + + digest_len = s3_sign(digest, &ad->secret, &message); + ad->auth_hdr.l = 0; + if (ksprintf(&ad->auth_hdr, "Authorization: AWS %s:", ad->id.s) < 0) + goto fail; + base64_kput(digest, digest_len, &ad->auth_hdr); + + free(message.s); + ad->auth_time = now; + return copy_auth_headers(ad, hdrs); + + fail: + free(message.s); + return -1; +} + +static hFILE * s3_rewrite(const char *s3url, const char *mode, va_list *argsp) +{ + const char *bucket, *path; + char *header_list[4], **header = header_list; + + kstring_t url = { 0, 0, NULL }; + kstring_t profile = { 0, 0, NULL }; + kstring_t host_base = { 0, 0, NULL }; + kstring_t token_hdr = { 0, 0, NULL }; + + s3_auth_data *ad = calloc(1, sizeof(*ad)); + + if (!ad) + return NULL; + ad->mode = strchr(mode, 'r') ? 'r' : 'w'; + + // Our S3 URL format is s3[+SCHEME]://[ID[:SECRET[:TOKEN]]@]BUCKET/PATH + + if (s3url[2] == '+') { + bucket = strchr(s3url, ':') + 1; + kputsn(&s3url[3], bucket - &s3url[3], &url); + } + else { + kputs("https:", &url); + bucket = &s3url[3]; + } + while (*bucket == '/') kputc(*bucket++, &url); + + path = bucket + strcspn(bucket, "/?#@"); + if (*path == '@') { + const char *colon = strpbrk(bucket, ":@"); + if (*colon != ':') { + urldecode_kput(bucket, colon - bucket, &profile); + } + else { + const char *colon2 = strpbrk(&colon[1], ":@"); + urldecode_kput(bucket, colon - bucket, &ad->id); + urldecode_kput(&colon[1], colon2 - &colon[1], &ad->secret); + if (*colon2 == ':') + urldecode_kput(&colon2[1], path - &colon2[1], &ad->token); + } + + bucket = &path[1]; + path = bucket + strcspn(bucket, "/?#"); + } + else { + // If the URL has no ID[:SECRET]@, consider environment variables. + const char *v; + if ((v = getenv("AWS_ACCESS_KEY_ID")) != NULL) kputs(v, &ad->id); + if ((v = getenv("AWS_SECRET_ACCESS_KEY")) != NULL) kputs(v, &ad->secret); + if ((v = getenv("AWS_SESSION_TOKEN")) != NULL) kputs(v, &ad->token); + + if ((v = getenv("AWS_DEFAULT_PROFILE")) != NULL) kputs(v, &profile); + else if ((v = getenv("AWS_PROFILE")) != NULL) kputs(v, &profile); + else kputs("default", &profile); + } + + if (ad->id.l == 0) { + const char *v = getenv("AWS_SHARED_CREDENTIALS_FILE"); + parse_ini(v? v : "~/.aws/credentials", profile.s, + "aws_access_key_id", &ad->id, + "aws_secret_access_key", &ad->secret, + "aws_session_token", &ad->token, NULL); + } + if (ad->id.l == 0) + parse_ini("~/.s3cfg", profile.s, "access_key", &ad->id, + "secret_key", &ad->secret, "access_token", &ad->token, + "host_base", &host_base, NULL); + if (ad->id.l == 0) + parse_simple("~/.awssecret", &ad->id, &ad->secret); + + if (host_base.l == 0) + kputs("s3.amazonaws.com", &host_base); + // Use virtual hosted-style access if possible, otherwise path-style. + if (is_dns_compliant(bucket, path)) { + kputsn(bucket, path - bucket, &url); + kputc('.', &url); + kputs(host_base.s, &url); + } + else { + kputs(host_base.s, &url); + kputc('/', &url); + kputsn(bucket, path - bucket, &url); + } + kputs(path, &url); + + if (ad->token.l > 0) { + kputs("X-Amz-Security-Token: ", &token_hdr); + kputs(ad->token.s, &token_hdr); + *header++ = token_hdr.s; + } + + ad->bucket = strdup(bucket); + if (!ad->bucket) + goto fail; + + *header = NULL; + hFILE *fp = hopen(url.s, mode, "va_list", argsp, "httphdr:v", header_list, + "httphdr_callback", auth_header_callback, + "httphdr_callback_data", ad, NULL); + if (!fp) goto fail; + + free(url.s); + free(profile.s); + free(host_base.s); + free(token_hdr.s); + return fp; + + fail: + free(url.s); + free(profile.s); + free(host_base.s); + free(token_hdr.s); + free_auth_data(ad); + return NULL; +} + +static hFILE *s3_open(const char *url, const char *mode) +{ + kstring_t mode_colon = { 0, 0, NULL }; + kputs(mode, &mode_colon); + kputc(':', &mode_colon); + hFILE *fp = s3_rewrite(url, mode_colon.s, NULL); + free(mode_colon.s); + return fp; +} + +static hFILE *s3_vopen(const char *url, const char *mode_colon, va_list args0) +{ + // Need to use va_copy() as we can only take the address of an actual + // va_list object, not that of a parameter whose type may have decayed. + va_list args; + va_copy(args, args0); + hFILE *fp = s3_rewrite(url, mode_colon, &args); + va_end(args); + return fp; +} + +int PLUGIN_GLOBAL(hfile_plugin_init,_s3)(struct hFILE_plugin *self) +{ + static const struct hFILE_scheme_handler handler = + { s3_open, hfile_always_remote, "Amazon S3", 2000 + 50, s3_vopen + }; + +#ifdef ENABLE_PLUGINS + // Embed version string for examination via strings(1) or what(1) + static const char id[] = "@(#)hfile_s3 plugin (htslib)\t" HTS_VERSION; + if (hts_verbose >= 9) + fprintf(stderr, "[M::hfile_s3.init] version %s\n", strchr(id, '\t')+1); +#endif + + self->name = "Amazon S3"; + hfile_add_scheme_handler("s3", &handler); + hfile_add_scheme_handler("s3+http", &handler); + hfile_add_scheme_handler("s3+https", &handler); + return 0; +} diff --git a/htslib/hts.c b/htslib/hts.c index 846b9ae46..c41d51bdd 100644 --- a/htslib/hts.c +++ b/htslib/hts.c @@ -1,6 +1,6 @@ /* hts.c -- format-neutral I/O, indexing, and iterator API functions. - Copyright (C) 2008, 2009, 2012-2016 Genome Research Ltd. + Copyright (C) 2008, 2009, 2012-2017 Genome Research Ltd. Copyright (C) 2012, 2013 Broad Institute. Author: Heng Li @@ -28,18 +28,23 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include #include #include #include #include #include +#include #include "htslib/hts.h" #include "htslib/bgzf.h" #include "cram/cram.h" #include "htslib/hfile.h" +#include "htslib/hts_endian.h" #include "version.h" #include "hts_internal.h" +#include "hfile_internal.h" +#include "htslib/hts_os.h" // drand48 #include "htslib/khash.h" #include "htslib/kseq.h" @@ -55,7 +60,7 @@ DEALINGS IN THE SOFTWARE. */ KHASH_INIT2(s2i,, kh_cstr_t, int64_t, 1, kh_str_hash_func, kh_str_hash_equal) -int hts_verbose = 3; +int hts_verbose = HTS_LOG_WARNING; const char *hts_version() { @@ -112,6 +117,9 @@ static enum htsFormatCategory format_category(enum htsExactFormat fmt) case bed: return region_list; + case htsget: + return unknown_category; + case unknown_format: case binary_format: case text_format: @@ -181,9 +189,23 @@ parse_version(htsFormat *fmt, const unsigned char *u, const unsigned char *ulim) } } +static int +cmp_nonblank(const char *key, const unsigned char *u, const unsigned char *ulim) +{ + const unsigned char *ukey = (const unsigned char *) key; + + while (*ukey) + if (u >= ulim) return +1; + else if (isspace_c(*u)) u++; + else if (*u != *ukey) return (*ukey < *u)? -1 : +1; + else u++, ukey++; + + return 0; +} + int hts_detect_format(hFILE *hfile, htsFormat *fmt) { - unsigned char s[21]; + unsigned char s[32]; ssize_t len = hpeek(hfile, s, 18); if (len < 0) return -1; @@ -290,6 +312,12 @@ int hts_detect_format(hFILE *hfile, htsFormat *fmt) fmt->version.major = 1, fmt->version.minor = -1; return 0; } + else if (cmp_nonblank("{\"htsget\":", s, &s[len]) == 0) { + fmt->category = unknown_category; + fmt->format = htsget; + fmt->version.major = fmt->version.minor = -1; + return 0; + } else { // Various possibilities for tab-delimited text: // .crai (gzipped tab-delimited six columns: seqid 5*number) @@ -327,6 +355,7 @@ char *hts_format_description(const htsFormat *format) case crai: kputs("CRAI", &str); break; case csi: kputs("CSI", &str); break; case tbi: kputs("Tabix", &str); break; + case htsget: kputs("htsget", &str); break; default: kputs("unknown", &str); break; } @@ -373,6 +402,7 @@ char *hts_format_description(const htsFormat *format) case crai: case vcf: case bed: + case htsget: kputs(" text", &str); break; @@ -429,8 +459,7 @@ htsFile *hts_open_format(const char *fn, const char *mode, const htsFormat *fmt) return fp; error: - if (hts_verbose >= 2) - fprintf(stderr, "[E::%s] fail to open file '%s'\n", __func__, fn); + hts_log_error("Failed to open file %s", fn); if (hfile) hclose_abruptly(hfile); @@ -472,6 +501,12 @@ int hts_opt_add(hts_opt **opts, const char *c_arg) { hts_opt *o, *t; char *val; + /* + * IMPORTANT!!! + * If you add another string option here, don't forget to also add + * it to the case statement in hts_opt_apply. + */ + if (!c_arg) return -1; @@ -500,6 +535,10 @@ int hts_opt_add(hts_opt **opts, const char *c_arg) { strcmp(o->arg, "SEQS_PER_SLICE") == 0) o->opt = CRAM_OPT_SEQS_PER_SLICE, o->val.i = atoi(val); + else if (strcmp(o->arg, "bases_per_slice") == 0 || + strcmp(o->arg, "BASES_PER_SLICE") == 0) + o->opt = CRAM_OPT_BASES_PER_SLICE, o->val.i = atoi(val); + else if (strcmp(o->arg, "slices_per_container") == 0 || strcmp(o->arg, "SLICES_PER_CONTAINER") == 0) o->opt = CRAM_OPT_SLICES_PER_CONTAINER, o->val.i = atoi(val); @@ -557,7 +596,7 @@ int hts_opt_add(hts_opt **opts, const char *c_arg) { case 'k': case 'K': o->val.i *= 1024; break; case '\0': break; default: - fprintf(stderr, "Unrecognised cache size suffix '%c'\n", *endp); + hts_log_error("Unrecognised cache size suffix '%c'", *endp); free(o->arg); free(o); return -1; @@ -576,8 +615,12 @@ int hts_opt_add(hts_opt **opts, const char *c_arg) { strcmp(o->arg, "NAME_PREFIX") == 0) o->opt = CRAM_OPT_PREFIX, o->val.s = val; + else if (strcmp(o->arg, "block_size") == 0 || + strcmp(o->arg, "BLOCK_SIZE") == 0) + o->opt = HTS_OPT_BLOCK_SIZE, o->val.i = strtol(val, NULL, 0); + else { - fprintf(stderr, "Unknown option '%s'\n", o->arg); + hts_log_error("Unknown option '%s'", o->arg); free(o->arg); free(o); return -1; @@ -607,9 +650,20 @@ int hts_opt_add(hts_opt **opts, const char *c_arg) { int hts_opt_apply(htsFile *fp, hts_opt *opts) { hts_opt *last = NULL; - for (; opts; opts = (last=opts)->next) - if (hts_set_opt(fp, opts->opt, opts->val) != 0) - return -1; + for (; opts; opts = (last=opts)->next) { + switch (opts->opt) { + case CRAM_OPT_REFERENCE: + case CRAM_OPT_VERSION: + case CRAM_OPT_PREFIX: + if (hts_set_opt(fp, opts->opt, opts->val.s) != 0) + return -1; + break; + default: + if (hts_set_opt(fp, opts->opt, opts->val.i) != 0) + return -1; + break; + } + } return 0; } @@ -744,8 +798,9 @@ static int hts_process_opts(htsFile *fp, const char *opts) { } -htsFile *hts_hopen(struct hFILE *hfile, const char *fn, const char *mode) +htsFile *hts_hopen(hFILE *hfile, const char *fn, const char *mode) { + hFILE *hfile_orig = hfile; htsFile *fp = (htsFile*)calloc(1, sizeof(htsFile)); char simple_mode[101], *cp, *opts; simple_mode[100] = '\0'; @@ -767,6 +822,15 @@ htsFile *hts_hopen(struct hFILE *hfile, const char *fn, const char *mode) if (strchr(simple_mode, 'r')) { if (hts_detect_format(hfile, &fp->format) < 0) goto error; + + if (fp->format.format == htsget) { + hFILE *hfile2 = hopen_htsget_redirect(hfile, simple_mode); + if (hfile2 == NULL) goto error; + + // Build fp against the result of the redirection + hfile = hfile2; + if (hts_detect_format(hfile, &fp->format) < 0) goto error; + } } else if (strchr(simple_mode, 'w') || strchr(simple_mode, 'a')) { htsFormat *fmt = &fp->format; @@ -796,7 +860,7 @@ htsFile *hts_hopen(struct hFILE *hfile, const char *fn, const char *mode) fmt->compression_level = -1; fmt->specific = NULL; } - else goto error; + else { errno = EINVAL; goto error; } switch (fp->format.format) { case binary_format: @@ -804,7 +868,7 @@ htsFile *hts_hopen(struct hFILE *hfile, const char *fn, const char *mode) case bcf: fp->fp.bgzf = bgzf_hopen(hfile, simple_mode); if (fp->fp.bgzf == NULL) goto error; - fp->is_bin = 1; + fp->is_bin = fp->is_bgzf = 1; break; case cram: @@ -818,37 +882,34 @@ htsFile *hts_hopen(struct hFILE *hfile, const char *fn, const char *mode) case text_format: case sam: case vcf: - if (!fp->is_write) { - #if KS_BGZF - BGZF *gzfp = bgzf_hopen(hfile, simple_mode); - #else - // TODO Implement gzip hFILE adaptor - hclose(hfile); // This won't work, especially for stdin - gzFile gzfp = strcmp(fn, "-")? gzopen(fn, "rb") : gzdopen(fileno(stdin), "rb"); - #endif - if (gzfp) fp->fp.voidp = ks_init(gzfp); - else goto error; - } - else if (fp->format.compression != no_compression) { + if (fp->format.compression != no_compression) { fp->fp.bgzf = bgzf_hopen(hfile, simple_mode); if (fp->fp.bgzf == NULL) goto error; + fp->is_bgzf = 1; } else fp->fp.hfile = hfile; break; default: + errno = ENOEXEC; goto error; } if (opts) hts_process_opts(fp, opts); + // If redirecting, close the original hFILE now (pedantically we would + // instead close it in hts_close(), but this a simplifying optimisation) + if (hfile != hfile_orig) hclose_abruptly(hfile_orig); + return fp; error: - if (hts_verbose >= 2) - fprintf(stderr, "[E::%s] fail to open file '%s'\n", __func__, fn); + hts_log_error("Failed to open file %s", fn); + + // If redirecting, close the failed redirection hFILE that we have opened + if (hfile != hfile_orig) hclose_abruptly(hfile); if (fp) { free(fp->fn); @@ -873,7 +934,7 @@ int hts_close(htsFile *fp) if (!fp->is_write) { switch (cram_eof(fp->fp.cram)) { case 2: - fprintf(stderr, "[W::%s] EOF marker is absent. The input is probably truncated.\n", __func__); + hts_log_warning("EOF marker is absent. The input is probably truncated"); break; case 0: /* not at EOF, but may not have wanted all seqs */ default: /* case 1, expected EOF */ @@ -886,17 +947,7 @@ int hts_close(htsFile *fp) case text_format: case sam: case vcf: - if (!fp->is_write) { - #if KS_BGZF - BGZF *gzfp = ((kstream_t*)fp->fp.voidp)->f; - ret = bgzf_close(gzfp); - #else - gzFile gzfp = ((kstream_t*)fp->fp.voidp)->f; - ret = gzclose(gzfp); - #endif - ks_destroy((kstream_t*)fp->fp.voidp); - } - else if (fp->format.compression != no_compression) + if (fp->format.compression != no_compression) ret = bgzf_close(fp->fp.bgzf); else ret = hclose(fp->fp.hfile); @@ -941,6 +992,17 @@ const char *hts_format_file_extension(const htsFormat *format) { } } +static hFILE *hts_hfile(htsFile *fp) { + switch (fp->format.format) { + case binary_format: // fall through; still valid if bcf? + case bam: return bgzf_hfile(fp->fp.bgzf); + case cram: return cram_hfile(fp->fp.cram); + case text_format: return fp->fp.hfile; + case sam: return fp->fp.hfile; + default: return NULL; + } +} + int hts_set_opt(htsFile *fp, enum hts_fmt_option opt, ...) { int r; va_list args; @@ -953,6 +1015,23 @@ int hts_set_opt(htsFile *fp, enum hts_fmt_option opt, ...) { return hts_set_threads(fp, nthreads); } + case HTS_OPT_BLOCK_SIZE: { + hFILE *hf = hts_hfile(fp); + + if (hf) { + va_start(args, opt); + if (hfile_set_blksize(hf, va_arg(args, int)) != 0) + hts_log_warning("Failed to change block size"); + va_end(args); + } + else { + // To do - implement for vcf/bcf. + hts_log_warning("Cannot change block size for this format"); + } + + return 0; + } + case HTS_OPT_THREAD_POOL: { va_start(args, opt); htsThreadPool *p = va_arg(args, htsThreadPool *); @@ -1029,68 +1108,75 @@ int hts_set_fai_filename(htsFile *fp, const char *fn_aux) // future is uncertain. Things will probably have to change with hFILE... BGZF *hts_get_bgzfp(htsFile *fp) { - if ( fp->is_bin || fp->is_write ) + if (fp->is_bgzf) return fp->fp.bgzf; else - return ((kstream_t*)fp->fp.voidp)->f; + return NULL; } int hts_useek(htsFile *fp, long uoffset, int where) { - if ( fp->is_bin ) + if (fp->is_bgzf) return bgzf_useek(fp->fp.bgzf, uoffset, where); else - { - ks_rewind((kstream_t*)fp->fp.voidp); - ((kstream_t*)fp->fp.voidp)->seek_pos = uoffset; - return bgzf_useek(((kstream_t*)fp->fp.voidp)->f, uoffset, where); - } + return (hseek(fp->fp.hfile, uoffset, SEEK_SET) >= 0)? 0 : -1; } long hts_utell(htsFile *fp) { - if ( fp->is_bin ) + if (fp->is_bgzf) return bgzf_utell(fp->fp.bgzf); else - return ((kstream_t*)fp->fp.voidp)->seek_pos; + return htell(fp->fp.hfile); } int hts_getline(htsFile *fp, int delimiter, kstring_t *str) { - int ret, dret; - ret = ks_getuntil((kstream_t*)fp->fp.voidp, delimiter, str, &dret); + int ret; + if (! (delimiter == KS_SEP_LINE || delimiter == '\n')) { + hts_log_error("Unexpected delimiter %d", delimiter); + abort(); + } + + switch (fp->format.compression) { + case no_compression: + str->l = 0; + ret = kgetline(str, (kgets_func *) hgets, fp->fp.hfile); + if (ret >= 0) ret = str->l; + else if (herrno(fp->fp.hfile)) ret = -2, errno = herrno(fp->fp.hfile); + else ret = -1; + break; + + case gzip: + case bgzf: + ret = bgzf_getline(fp->fp.bgzf, '\n', str); + break; + + default: + abort(); + } + ++fp->lineno; return ret; } char **hts_readlist(const char *string, int is_file, int *_n) { - int m = 0, n = 0, dret; + int m = 0, n = 0; char **s = 0; if ( is_file ) { -#if KS_BGZF BGZF *fp = bgzf_open(string, "r"); -#else - gzFile fp = gzopen(string, "r"); -#endif if ( !fp ) return NULL; - kstream_t *ks; kstring_t str; str.s = 0; str.l = str.m = 0; - ks = ks_init(fp); - while (ks_getuntil(ks, KS_SEP_LINE, &str, &dret) >= 0) + while (bgzf_getline(fp, '\n', &str) >= 0) { if (str.l == 0) continue; n++; hts_expand(char*,n,m,s); s[n-1] = strdup(str.s); } - ks_destroy(ks); -#if KS_BGZF bgzf_close(fp); -#else - gzclose(fp); -#endif free(str.s); } else @@ -1117,19 +1203,13 @@ char **hts_readlist(const char *string, int is_file, int *_n) char **hts_readlines(const char *fn, int *_n) { - int m = 0, n = 0, dret; + int m = 0, n = 0; char **s = 0; -#if KS_BGZF BGZF *fp = bgzf_open(fn, "r"); -#else - gzFile fp = gzopen(fn, "r"); -#endif if ( fp ) { // read from file - kstream_t *ks; kstring_t str; str.s = 0; str.l = str.m = 0; - ks = ks_init(fp); - while (ks_getuntil(ks, KS_SEP_LINE, &str, &dret) >= 0) { + while (bgzf_getline(fp, '\n', &str) >= 0) { if (str.l == 0) continue; if (m == n) { m = m? m<<1 : 16; @@ -1137,12 +1217,7 @@ char **hts_readlines(const char *fn, int *_n) } s[n++] = strdup(str.s); } - ks_destroy(ks); - #if KS_BGZF - bgzf_close(fp); - #else - gzclose(fp); - #endif + bgzf_close(fp); s = (char**)realloc(s, n * sizeof(char*)); free(str.s); } else if (*fn == ':') { // read from string @@ -1211,6 +1286,7 @@ int hts_check_EOF(htsFile *fp) #define pair64_lt(a,b) ((a).u < (b).u) KSORT_INIT(_off, hts_pair64_t, pair64_lt) +KSORT_INIT(_off_max, hts_pair64_max_t, pair64_lt) typedef struct { int32_t m, n; @@ -1233,7 +1309,7 @@ struct __hts_idx_t { uint64_t n_no_coor; bidx_t **bidx; lidx_t *lidx; - uint8_t *meta; + uint8_t *meta; // MUST have a terminating NUL on the end struct { uint32_t last_bin, save_bin; int last_coor, last_tid, save_tid, finished; @@ -1243,44 +1319,65 @@ struct __hts_idx_t { } z; // keep internal states }; -static inline void insert_to_b(bidx_t *b, int bin, uint64_t beg, uint64_t end) +static char * idx_format_name(int fmt) { + switch (fmt) { + case HTS_FMT_CSI: return "csi"; + case HTS_FMT_BAI: return "bai"; + case HTS_FMT_TBI: return "tbi"; + case HTS_FMT_CRAI: return "crai"; + default: return "unknown"; + } +} + +static inline int insert_to_b(bidx_t *b, int bin, uint64_t beg, uint64_t end) { khint_t k; bins_t *l; int absent; k = kh_put(bin, b, bin, &absent); + if (absent < 0) return -1; // Out of memory l = &kh_value(b, k); if (absent) { l->m = 1; l->n = 0; l->list = (hts_pair64_t*)calloc(l->m, sizeof(hts_pair64_t)); - } - if (l->n == l->m) { - l->m <<= 1; - l->list = (hts_pair64_t*)realloc(l->list, l->m * sizeof(hts_pair64_t)); + if (!l->list) { + kh_del(bin, b, k); + return -1; + } + } else if (l->n == l->m) { + uint32_t new_m = l->m ? l->m << 1 : 1; + hts_pair64_t *new_list = realloc(l->list, new_m * sizeof(hts_pair64_t)); + if (!new_list) return -1; + l->list = new_list; + l->m = new_m; } l->list[l->n].u = beg; l->list[l->n++].v = end; + return 0; } -static inline void insert_to_l(lidx_t *l, int64_t _beg, int64_t _end, uint64_t offset, int min_shift) +static inline int insert_to_l(lidx_t *l, int64_t _beg, int64_t _end, uint64_t offset, int min_shift) { int i, beg, end; beg = _beg >> min_shift; end = (_end - 1) >> min_shift; if (l->m < end + 1) { - int old_m = l->m; - l->m = end + 1; - kroundup32(l->m); - l->offset = (uint64_t*)realloc(l->offset, l->m * sizeof(uint64_t)); - memset(l->offset + old_m, 0xff, 8 * (l->m - old_m)); // fill l->offset with (uint64_t)-1 - } - if (beg == end) { // to save a loop in this case - if (l->offset[beg] == (uint64_t)-1) l->offset[beg] = offset; - } else { - for (i = beg; i <= end; ++i) - if (l->offset[i] == (uint64_t)-1) l->offset[i] = offset; + size_t new_m = l->m * 2 > end + 1 ? l->m * 2 : end + 1; + uint64_t *new_offset; + + new_offset = (uint64_t*)realloc(l->offset, new_m * sizeof(uint64_t)); + if (!new_offset) return -1; + + // fill unused memory with (uint64_t)-1 + memset(new_offset + l->m, 0xff, sizeof(uint64_t) * (new_m - l->m)); + l->m = new_m; + l->offset = new_offset; + } + for (i = beg; i <= end; ++i) { + if (l->offset[i] == (uint64_t)-1) l->offset[i] = offset; } if (l->n < end + 1) l->n = end + 1; + return 0; } hts_idx_t *hts_idx_init(int n, int fmt, uint64_t offset0, int min_shift, int n_lvls) @@ -1408,32 +1505,45 @@ void hts_idx_finish(hts_idx_t *idx, uint64_t final_offset) int hts_idx_push(hts_idx_t *idx, int tid, int beg, int end, uint64_t offset, int is_mapped) { int bin; + int64_t maxpos = (int64_t) 1 << (idx->min_shift + idx->n_lvls * 3); if (tid<0) beg = -1, end = 0; + if (tid >= 0 && (beg > maxpos || end > maxpos)) { + goto pos_too_big; + } if (tid >= idx->m) { // enlarge the index - int32_t oldm = idx->m; - idx->m = idx->m? idx->m<<1 : 2; - idx->bidx = (bidx_t**)realloc(idx->bidx, idx->m * sizeof(bidx_t*)); - idx->lidx = (lidx_t*) realloc(idx->lidx, idx->m * sizeof(lidx_t)); - memset(&idx->bidx[oldm], 0, (idx->m - oldm) * sizeof(bidx_t*)); - memset(&idx->lidx[oldm], 0, (idx->m - oldm) * sizeof(lidx_t)); + uint32_t new_m = idx->m * 2 > tid + 1 ? idx->m * 2 : tid + 1; + bidx_t **new_bidx; + lidx_t *new_lidx; + + new_bidx = (bidx_t**)realloc(idx->bidx, new_m * sizeof(bidx_t*)); + if (!new_bidx) return -1; + idx->bidx = new_bidx; + + new_lidx = (lidx_t*) realloc(idx->lidx, new_m * sizeof(lidx_t)); + if (!new_lidx) return -1; + idx->lidx = new_lidx; + + memset(&idx->bidx[idx->m], 0, (new_m - idx->m) * sizeof(bidx_t*)); + memset(&idx->lidx[idx->m], 0, (new_m - idx->m) * sizeof(lidx_t)); + idx->m = new_m; } if (idx->n < tid + 1) idx->n = tid + 1; if (idx->z.finished) return 0; if (idx->z.last_tid != tid || (idx->z.last_tid >= 0 && tid < 0)) { // change of chromosome if ( tid>=0 && idx->n_no_coor ) { - if (hts_verbose >= 1) fprintf(stderr,"[E::%s] NO_COOR reads not in a single block at the end %d %d\n", __func__, tid,idx->z.last_tid); + hts_log_error("NO_COOR reads not in a single block at the end %d %d", tid, idx->z.last_tid); return -1; } if (tid>=0 && idx->bidx[tid] != 0) { - if (hts_verbose >= 1) fprintf(stderr, "[E::%s] chromosome blocks not continuous\n", __func__); + hts_log_error("Chromosome blocks not continuous"); return -1; } idx->z.last_tid = tid; idx->z.last_bin = 0xffffffffu; } else if (tid >= 0 && idx->z.last_coor > beg) { // test if positions are out of order - if (hts_verbose >= 1) fprintf(stderr, "[E::%s] unsorted positions on sequence #%d: %d followed by %d\n", __func__, tid+1, idx->z.last_coor+1, beg+1); + hts_log_error("Unsorted positions on sequence #%d: %d followed by %d", tid+1, idx->z.last_coor+1, beg+1); return -1; } if ( tid>=0 ) @@ -1443,18 +1553,24 @@ int hts_idx_push(hts_idx_t *idx, int tid, int beg, int end, uint64_t offset, int // shoehorn [-1,0) (VCF POS=0) into the leftmost bottom-level bin if (beg < 0) beg = 0; if (end <= 0) end = 1; - insert_to_l(&idx->lidx[tid], beg, end, idx->z.last_off, idx->min_shift); // last_off points to the start of the current record + // idx->z.last_off points to the start of the current record + if (insert_to_l(&idx->lidx[tid], beg, end, + idx->z.last_off, idx->min_shift) < 0) return -1; } } else idx->n_no_coor++; bin = hts_reg2bin(beg, end, idx->min_shift, idx->n_lvls); if ((int)idx->z.last_bin != bin) { // then possibly write the binning index - if (idx->z.save_bin != 0xffffffffu) // save_bin==0xffffffffu only happens to the first record - insert_to_b(idx->bidx[idx->z.save_tid], idx->z.save_bin, idx->z.save_off, idx->z.last_off); + if (idx->z.save_bin != 0xffffffffu) { // save_bin==0xffffffffu only happens to the first record + if (insert_to_b(idx->bidx[idx->z.save_tid], idx->z.save_bin, + idx->z.save_off, idx->z.last_off) < 0) return -1; + } if (idx->z.last_bin == 0xffffffffu && idx->z.save_bin != 0xffffffffu) { // change of chr; keep meta information idx->z.off_end = idx->z.last_off; - insert_to_b(idx->bidx[idx->z.save_tid], META_BIN(idx), idx->z.off_beg, idx->z.off_end); - insert_to_b(idx->bidx[idx->z.save_tid], META_BIN(idx), idx->z.n_mapped, idx->z.n_unmapped); + if (insert_to_b(idx->bidx[idx->z.save_tid], META_BIN(idx), + idx->z.off_beg, idx->z.off_end) < 0) return -1; + if (insert_to_b(idx->bidx[idx->z.save_tid], META_BIN(idx), + idx->z.n_mapped, idx->z.n_unmapped) < 0) return -1; idx->z.n_mapped = idx->z.n_unmapped = 0; idx->z.off_beg = idx->z.off_end; } @@ -1467,6 +1583,32 @@ int hts_idx_push(hts_idx_t *idx, int tid, int beg, int end, uint64_t offset, int idx->z.last_off = offset; idx->z.last_coor = beg; return 0; + + pos_too_big: { + int64_t max = end > beg ? end : beg, s = 1 << 14; + int n_lvls = 0; + while (max > s) { + n_lvls++; + s <<= 3; + } + + if (idx->fmt == HTS_FMT_CSI) { + hts_log_error("Region %d..%d cannot be stored in a csi index " + "with min_shift = %d, n_lvls = %d. Try using " + "min_shift = 14, n_lvls >= %d", + beg, end, + idx->min_shift, idx->n_lvls, + n_lvls); + } else { + hts_log_error("Region %d..%d cannot be stored in a %s index. " + "Try using a csi index with min_shift = 14, " + "n_lvls >= %d", + beg, end, idx_format_name(idx->fmt), + n_lvls); + } + errno = ERANGE; + return -1; + } } void hts_idx_destroy(hts_idx_t *idx) @@ -1691,8 +1833,11 @@ static hts_idx_t *hts_idx_load_local(const char *fn) if (bgzf_read(fp, x, 12) != 12) goto fail; if (is_be) for (i = 0; i < 3; ++i) ed_swap_4p(&x[i]); if (x[2]) { - if ((meta = (uint8_t*)malloc(x[2])) == NULL) goto fail; + if (SIZE_MAX - x[2] < 1) goto fail; // Prevent possible overflow + if ((meta = (uint8_t*)malloc((size_t) x[2] + 1)) == NULL) goto fail; if (bgzf_read(fp, meta, x[2]) != x[2]) goto fail; + // Prevent possible strlen past the end in tbx_index_load2 + meta[x[2]] = '\0'; } if (bgzf_read(fp, &n, 4) != 4) goto fail; if (is_be) ed_swap_4p(&n); @@ -1703,14 +1848,23 @@ static hts_idx_t *hts_idx_load_local(const char *fn) if (hts_idx_load_core(idx, fp, HTS_FMT_CSI) < 0) goto fail; } else if (memcmp(magic, "TBI\1", 4) == 0) { - uint32_t x[8]; - if (bgzf_read(fp, x, 32) != 32) goto fail; - if (is_be) for (i = 0; i < 8; ++i) ed_swap_4p(&x[i]); - if ((idx = hts_idx_init(x[0], HTS_FMT_TBI, 0, 14, 5)) == NULL) goto fail; - idx->l_meta = 28 + x[7]; - if ((idx->meta = (uint8_t*)malloc(idx->l_meta)) == NULL) goto fail; - memcpy(idx->meta, &x[1], 28); - if (bgzf_read(fp, idx->meta + 28, x[7]) != x[7]) goto fail; + uint8_t x[8 * 4]; + uint32_t n; + // Read file header + if (bgzf_read(fp, x, sizeof(x)) != sizeof(x)) goto fail; + n = le_to_u32(&x[0]); // location of n_ref + if ((idx = hts_idx_init(n, HTS_FMT_TBI, 0, 14, 5)) == NULL) goto fail; + n = le_to_u32(&x[7*4]); // location of l_nm + if (n > UINT32_MAX - 29) goto fail; // Prevent possible overflow + idx->l_meta = 28 + n; + if ((idx->meta = (uint8_t*)malloc(idx->l_meta + 1)) == NULL) goto fail; + // copy format, col_seq, col_beg, col_end, meta, skip, l_nm + // N.B. left in little-endian byte order. + memcpy(idx->meta, &x[1*4], 28); + // Read in sequence names. + if (bgzf_read(fp, idx->meta + 28, n) != n) goto fail; + // Prevent possible strlen past the end in tbx_index_load2 + idx->meta[idx->l_meta] = '\0'; if (hts_idx_load_core(idx, fp, HTS_FMT_TBI) < 0) goto fail; } else if (memcmp(magic, "BAI\1", 4) == 0) { @@ -1732,17 +1886,29 @@ static hts_idx_t *hts_idx_load_local(const char *fn) return NULL; } -void hts_idx_set_meta(hts_idx_t *idx, int l_meta, uint8_t *meta, int is_copy) +int hts_idx_set_meta(hts_idx_t *idx, uint32_t l_meta, uint8_t *meta, + int is_copy) { + uint8_t *new_meta = meta; + if (is_copy) { + size_t l = l_meta; + if (l > SIZE_MAX - 1) { + errno = ENOMEM; + return -1; + } + new_meta = malloc(l + 1); + if (!new_meta) return -1; + memcpy(new_meta, meta, l); + // Prevent possible strlen past the end in tbx_index_load2 + meta[l + 1] = '\0'; + } if (idx->meta) free(idx->meta); idx->l_meta = l_meta; - if (is_copy) { - idx->meta = (uint8_t*)malloc(l_meta); - memcpy(idx->meta, meta, l_meta); - } else idx->meta = meta; + idx->meta = new_meta; + return 0; } -uint8_t *hts_idx_get_meta(hts_idx_t *idx, int *l_meta) +uint8_t *hts_idx_get_meta(hts_idx_t *idx, uint32_t *l_meta) { *l_meta = idx->l_meta; return idx->meta; @@ -1814,6 +1980,115 @@ static inline int reg2bins(int64_t beg, int64_t end, hts_itr_t *itr, int min_shi return itr->bins.n; } +static inline int reg2intervals(hts_itr_multi_t *iter, const hts_idx_t *idx, int tid, int64_t beg, int64_t end, uint64_t min_off, uint64_t max_off, int min_shift, int n_lvls) +{ + int l, t, s; + int b, e, i, j; + hts_pair64_max_t *off; + bidx_t *bidx; + khint_t k; + + if (!iter || !idx || (bidx = idx->bidx[tid]) == NULL || beg >= end) + return -1; + + s = min_shift + (n_lvls<<1) + n_lvls; + if (end >= 1LL<>s); e = t + (end>>s); + + for (i = b; i <= e; ++i) { + if ((k = kh_get(bin, bidx, i)) != kh_end(bidx)) { + bins_t *p = &kh_value(bidx, k); + + if (p->n) { + off = (hts_pair64_max_t*)realloc(iter->off, (iter->n_off + p->n) * sizeof(hts_pair64_max_t)); + if (!off) + return -2; + + iter->off = off; + for (j = 0; j < p->n; ++j) { + if (p->list[j].v > min_off && p->list[j].u < max_off) { + iter->off[iter->n_off].u = p->list[j].u; + iter->off[iter->n_off].v = p->list[j].v; + iter->off[iter->n_off].max = ((uint64_t)tid<<32) | (end+1); + iter->n_off++; + } + } + } + } + } + } + + return iter->n_off; +} + +static int compare_regions(const void *r1, const void *r2) { + hts_reglist_t *reg1 = (hts_reglist_t *)r1; + hts_reglist_t *reg2 = (hts_reglist_t *)r2; + + if (reg1->tid < 0 && reg2->tid >= 0) + return 1; + else if (reg1->tid >= 0 && reg2->tid < 0) + return -1; + else + return reg1->tid - reg2->tid; +} + +uint64_t hts_itr_off(const hts_idx_t* idx, int tid) { + + int i; + bidx_t* bidx; + uint64_t off0 = (uint64_t) -1; + khint_t k; + switch (tid) { + case HTS_IDX_START: + // Find the smallest offset, note that sequence ids may not be ordered sequentially + for (i = 0; i < idx->n; i++) { + bidx = idx->bidx[i]; + k = kh_get(bin, bidx, META_BIN(idx)); + if (k == kh_end(bidx)) + continue; + + if (off0 > kh_val(bidx, k).list[0].u) + off0 = kh_val(bidx, k).list[0].u; + } + if (off0 == (uint64_t) -1 && idx->n_no_coor) + off0 = 0; + // only no-coor reads in this bam + break; + case HTS_IDX_NOCOOR: + /* No-coor reads sort after all of the mapped reads. The position + is not stored in the index itself, so need to find the end + offset for the last mapped read. A loop is needed here in + case references at the end of the file have no mapped reads, + or sequence ids are not ordered sequentially. + See issue samtools#568 and commits b2aab8, 60c22d and cc207d. */ + for (i = 0; i < idx->n; i++) { + bidx = idx->bidx[i]; + k = kh_get(bin, bidx, META_BIN(idx)); + if (k != kh_end(bidx)) { + if (off0 == (uint64_t) -1 || off0 < kh_val(bidx, k).list[0].v) { + off0 = kh_val(bidx, k).list[0].v; + } + } + } + if (off0 == (uint64_t) -1 && idx->n_no_coor) + off0 = 0; + // only no-coor reads in this bam + break; + case HTS_IDX_REST: + off0 = 0; + break; + case HTS_IDX_NONE: + off0 = 0; + break; + } + + return off0; +} + hts_itr_t *hts_itr_query(const hts_idx_t *idx, int tid, int beg, int end, hts_readrec_func *readrec) { int i, n_off, l, bin; @@ -1821,133 +2096,351 @@ hts_itr_t *hts_itr_query(const hts_idx_t *idx, int tid, int beg, int end, hts_re khint_t k; bidx_t *bidx; uint64_t min_off, max_off; - hts_itr_t *iter = 0; - if (tid < 0) { - int finished0 = 0; - uint64_t off0 = (uint64_t)-1; - khint_t k; - switch (tid) { - case HTS_IDX_START: - // Find the smallest offset, note that sequence ids may not be ordered sequentially - for (i=0; in; i++) - { - bidx = idx->bidx[i]; - k = kh_get(bin, bidx, META_BIN(idx)); - if (k == kh_end(bidx)) continue; - if ( off0 > kh_val(bidx, k).list[0].u ) off0 = kh_val(bidx, k).list[0].u; + hts_itr_t *iter = (hts_itr_t*)calloc(1, sizeof(hts_itr_t)); + if (iter) { + if (tid < 0) { + uint64_t off = hts_itr_off(idx, tid); + if (off != (uint64_t) -1) { + iter->read_rest = 1; + iter->curr_off = off; + iter->readrec = readrec; + if (tid == HTS_IDX_NONE) + iter->finished = 1; + } else { + free(iter); + iter = NULL; } - if ( off0==(uint64_t)-1 && idx->n_no_coor ) off0 = 0; // only no-coor reads in this bam - break; + } else { + if (beg < 0) beg = 0; + if (end < beg) return 0; + if (tid >= idx->n || (bidx = idx->bidx[tid]) == NULL) return 0; + + iter->tid = tid, iter->beg = beg, iter->end = end; iter->i = -1; + iter->readrec = readrec; + + if ( !kh_size(bidx) ) { iter->finished = 1; return iter; } + + // compute min_off + bin = hts_bin_first(idx->n_lvls) + (beg>>idx->min_shift); + do { + int first; + k = kh_get(bin, bidx, bin); + if (k != kh_end(bidx)) break; + first = (hts_bin_parent(bin)<<3) + 1; + if (bin > first) --bin; + else bin = hts_bin_parent(bin); + } while (bin); + if (bin == 0) k = kh_get(bin, bidx, bin); + min_off = k != kh_end(bidx)? kh_val(bidx, k).loff : 0; + + // compute max_off: a virtual offset from a bin to the right of end + bin = hts_bin_first(idx->n_lvls) + ((end-1) >> idx->min_shift) + 1; + if (bin >= idx->n_bins) bin = 0; + while (1) { + // search for an extant bin by moving right, but moving up to the + // parent whenever we get to a first child (which also covers falling + // off the RHS, which wraps around and immediately goes up to bin 0) + while (bin % 8 == 1) bin = hts_bin_parent(bin); + if (bin == 0) { max_off = (uint64_t)-1; break; } + k = kh_get(bin, bidx, bin); + if (k != kh_end(bidx) && kh_val(bidx, k).n > 0) { max_off = kh_val(bidx, k).list[0].u; break; } + bin++; + } + + // retrieve bins + reg2bins(beg, end, iter, idx->min_shift, idx->n_lvls); + + for (i = n_off = 0; i < iter->bins.n; ++i) + if ((k = kh_get(bin, bidx, iter->bins.a[i])) != kh_end(bidx)) + n_off += kh_value(bidx, k).n; + if (n_off == 0) { + // No overlapping bins means the iterator has already finished. + iter->finished = 1; + return iter; + } + off = (hts_pair64_t*)calloc(n_off, sizeof(hts_pair64_t)); + for (i = n_off = 0; i < iter->bins.n; ++i) { + if ((k = kh_get(bin, bidx, iter->bins.a[i])) != kh_end(bidx)) { + int j; + bins_t *p = &kh_value(bidx, k); + for (j = 0; j < p->n; ++j) + if (p->list[j].v > min_off && p->list[j].u < max_off) + off[n_off++] = p->list[j]; + } + } + + if (n_off == 0) { + free(off); + iter->finished = 1; + return iter; + } + ks_introsort(_off, n_off, off); + // resolve completely contained adjacent blocks + for (i = 1, l = 0; i < n_off; ++i) + if (off[l].v < off[i].v) off[++l] = off[i]; + n_off = l + 1; + // resolve overlaps between adjacent blocks; this may happen due to the merge in indexing + for (i = 1; i < n_off; ++i) + if (off[i-1].v >= off[i].u) off[i-1].v = off[i].u; + // merge adjacent blocks + for (i = 1, l = 0; i < n_off; ++i) { + if (off[l].v>>16 == off[i].u>>16) off[l].v = off[i].v; + else off[++l] = off[i]; + } + n_off = l + 1; + iter->n_off = n_off; iter->off = off; + } + } + return iter; +} - case HTS_IDX_NOCOOR: - /* No-coor reads sort after all of the mapped reads. The position - is not stored in the index itself, so need to find the end - offset for the last mapped read. A loop is needed here in - case references at the end of the file have no mapped reads, - or sequence ids are not ordered sequentially. - See issue samtools#568 and commits b2aab8, 60c22d and cc207d. */ - for (i = 0; i < idx->n; i++) { - bidx = idx->bidx[i]; - k = kh_get(bin, bidx, META_BIN(idx)); - if (k != kh_end(bidx)) { - if (off0==(uint64_t)-1 || off0 < kh_val(bidx, k).list[0].v) { - off0 = kh_val(bidx, k).list[0].v; +hts_itr_multi_t *hts_itr_multi_bam(const hts_idx_t *idx, hts_itr_multi_t *iter) +{ + int i, j, l, n_off = 0, bin; + hts_pair64_max_t *off = NULL; + khint_t k; + bidx_t *bidx; + uint64_t min_off, max_off, t_off = (uint64_t)-1; + int tid, beg, end; + hts_reglist_t *curr_reg; + + if (iter) { + iter->i = -1; + for (i=0; in_reg; i++) { + + curr_reg = &iter->reg_list[i]; + tid = curr_reg->tid; + + if (tid < 0) { + t_off = hts_itr_off(idx, tid); + if (t_off != (uint64_t)-1) { + switch (tid) { + case HTS_IDX_NONE: + iter->finished = 1; + case HTS_IDX_START: + case HTS_IDX_REST: + iter->curr_off = t_off; + iter->n_reg = 0; + iter->reg_list = NULL; + iter->read_rest = 1; + return iter; + case HTS_IDX_NOCOOR: + iter->nocoor = 1; + iter->nocoor_off = t_off; } } + } else { + if (tid >= idx->n || (bidx = idx->bidx[tid]) == NULL || !kh_size(bidx)) + continue; + + for(j=0; jcount; j++) { + hts_pair32_t *curr_intv = &curr_reg->intervals[j]; + if (curr_intv->end < curr_intv->beg) + continue; + + beg = curr_intv->beg; + end = curr_intv->end; + + /* Compute 'min_off' by searching the lowest level bin containing 'beg'. + If the computed bin is not in the index, try the next bin to the + left, belonging to the same parent. If it is the first sibling bin, + try the parent bin. */ + bin = hts_bin_first(idx->n_lvls) + (beg>>idx->min_shift); + do { + int first; + k = kh_get(bin, bidx, bin); + if (k != kh_end(bidx)) break; + first = (hts_bin_parent(bin)<<3) + 1; + if (bin > first) --bin; + else bin = hts_bin_parent(bin); + } while (bin); + if (bin == 0) + k = kh_get(bin, bidx, bin); + min_off = k != kh_end(bidx)? kh_val(bidx, k).loff : 0; + + // compute max_off: a virtual offset from a bin to the right of end + bin = hts_bin_first(idx->n_lvls) + ((end-1) >> idx->min_shift) + 1; + if (bin >= idx->n_bins) bin = 0; + while (1) { + // search for an extant bin by moving right, but moving up to the + // parent whenever we get to a first child (which also covers falling + // off the RHS, which wraps around and immediately goes up to bin 0) + while (bin % 8 == 1) bin = hts_bin_parent(bin); + if (bin == 0) { max_off = (uint64_t)-1; break; } + k = kh_get(bin, bidx, bin); + if (k != kh_end(bidx) && kh_val(bidx, k).n > 0) { + max_off = kh_val(bidx, k).loff; + break; + } + bin++; + } + + //convert coordinates to file offsets + reg2intervals(iter, idx, tid, beg, end, min_off, max_off, idx->min_shift, idx->n_lvls); + } } - if ( off0==(uint64_t)-1 && idx->n_no_coor ) off0 = 0; // only no-coor reads in this bam - break; + } - case HTS_IDX_REST: - off0 = 0; - break; + off = iter->off; + n_off = iter->n_off; + + if (n_off) { + ks_introsort(_off_max, n_off, off); + // resolve completely contained adjacent blocks + for (i = 1, l = 0; i < n_off; ++i) { + if (off[l].v < off[i].v) { + off[++l] = off[i]; + } else { + off[l].max = (off[i].max > off[l].max ? off[i].max : off[l].max); + } + } + n_off = l + 1; + // resolve overlaps between adjacent blocks; this may happen due to the merge in indexing + for (i = 1; i < n_off; ++i) + if (off[i-1].v >= off[i].u) off[i-1].v = off[i].u; + // merge adjacent blocks + for (i = 1, l = 0; i < n_off; ++i) { + if (off[l].v>>16 == off[i].u>>16) { + off[l].v = off[i].v; + off[l].max = (off[i].max > off[l].max ? off[i].max : off[l].max); + } else off[++l] = off[i]; + } + n_off = l + 1; + iter->n_off = n_off; iter->off = off; + } - case HTS_IDX_NONE: - finished0 = 1; - off0 = 0; - break; + if(!n_off && !iter->nocoor) + iter->finished = 1; + } + return iter; +} - default: - return 0; +hts_itr_multi_t *hts_itr_multi_cram(const hts_idx_t *idx, hts_itr_multi_t *iter) +{ + const hts_cram_idx_t *cidx = (const hts_cram_idx_t *) idx; + int tid, beg, end, i, j, l, n_off = 0; + hts_reglist_t *curr_reg; + hts_pair32_t *curr_intv; + hts_pair64_max_t *off = NULL; + cram_index *e = NULL; + + if (!cidx || !iter) + return NULL; + + iter->is_cram = 1; + iter->read_rest = 0; + iter->off = NULL; + iter->n_off = 0; + iter->curr_off = 0; + iter->i = -1; + + for (i=0; in_reg; i++) { + + curr_reg = &iter->reg_list[i]; + tid = curr_reg->tid; + + if (tid >= 0) { + off = (hts_pair64_max_t*)realloc(off, (n_off + curr_reg->count) * sizeof(hts_pair64_max_t)); + if (!off) + return NULL; + + for (j=0; j < curr_reg->count; j++) { + curr_intv = &curr_reg->intervals[j]; + if (curr_intv->end < curr_intv->beg) + continue; + + beg = curr_intv->beg; + end = curr_intv->end; + +/* First, fetch the container overlapping 'beg' and assign its file offset to u, then + * find the container overlapping 'end' and assing the relative end of the slice to v. + * The cram_ptell function will adjust with the container offset, which is not stored + * in the index. + */ + e = cram_index_query(cidx->cram, tid, beg+1, NULL); + if (e) { + off[n_off].u = e->offset; + + if (end == INT_MAX) { + e = cram_index_last(cidx->cram, tid, NULL); + } else { + e = cram_index_query(cidx->cram, tid, end+1, NULL); + } + + if (e) { + off[n_off].v = e->offset + e->slice + e->len; + off[n_off].max = (uint64_t)tid<<32 | end; + n_off++; + } else { + hts_log_warning("Could not set offset end for region %d(%s):%d-%d. Skipping", tid, curr_reg->reg, beg, end); + } + } else { + hts_log_warning("No index entry for region %d:%d-%d", tid, beg, end); + } + } + } else { + switch (tid) { + case HTS_IDX_NOCOOR: + e = cram_index_query(cidx->cram, tid, 1, NULL); + if (e) { + iter->nocoor = 1; + iter->nocoor_off = e->offset; + } else { + hts_log_warning("No index entry for NOCOOR region"); + } + break; + case HTS_IDX_START: + e = cram_index_query(cidx->cram, tid, 1, NULL); + if (e) { + iter->read_rest = 1; + off = (hts_pair64_max_t*)realloc(off, sizeof(hts_pair64_max_t)); + off[0].u = e->offset; + off[0].v = 0; + off[0].max = 0; + n_off=1; + } else { + hts_log_warning("No index entries"); + } + break; + case HTS_IDX_REST: + break; + case HTS_IDX_NONE: + iter->finished = 1; + break; + default: + hts_log_error("Query with tid=%d not implemented for CRAM files", tid); + } } - if (off0 != (uint64_t)-1) { - iter = (hts_itr_t*)calloc(1, sizeof(hts_itr_t)); - iter->read_rest = 1; - iter->finished = finished0; - iter->curr_off = off0; - iter->readrec = readrec; - return iter; - } else return 0; - } - - if (beg < 0) beg = 0; - if (end < beg) return 0; - if (tid >= idx->n || (bidx = idx->bidx[tid]) == NULL) return 0; - - iter = (hts_itr_t*)calloc(1, sizeof(hts_itr_t)); - iter->tid = tid, iter->beg = beg, iter->end = end; iter->i = -1; - iter->readrec = readrec; - - // compute min_off - bin = hts_bin_first(idx->n_lvls) + (beg>>idx->min_shift); - do { - int first; - k = kh_get(bin, bidx, bin); - if (k != kh_end(bidx)) break; - first = (hts_bin_parent(bin)<<3) + 1; - if (bin > first) --bin; - else bin = hts_bin_parent(bin); - } while (bin); - if (bin == 0) k = kh_get(bin, bidx, bin); - min_off = k != kh_end(bidx)? kh_val(bidx, k).loff : 0; - - // compute max_off: a virtual offset from a bin to the right of end - bin = hts_bin_first(idx->n_lvls) + ((end-1) >> idx->min_shift) + 1; - while (1) { - // search for an extant bin by moving right, but moving up to the - // parent whenever we get to a first child (which also covers falling - // off the RHS, which wraps around and immediately goes up to bin 0) - while (bin % 8 == 1) bin = hts_bin_parent(bin); - if (bin == 0) { max_off = (uint64_t)-1; break; } - k = kh_get(bin, bidx, bin); - if (k != kh_end(bidx) && kh_val(bidx, k).n > 0) { max_off = kh_val(bidx, k).list[0].u; break; } - bin++; - } - - // retrieve bins - reg2bins(beg, end, iter, idx->min_shift, idx->n_lvls); - for (i = n_off = 0; i < iter->bins.n; ++i) - if ((k = kh_get(bin, bidx, iter->bins.a[i])) != kh_end(bidx)) - n_off += kh_value(bidx, k).n; - if (n_off == 0) return iter; - off = (hts_pair64_t*)calloc(n_off, sizeof(hts_pair64_t)); - for (i = n_off = 0; i < iter->bins.n; ++i) { - if ((k = kh_get(bin, bidx, iter->bins.a[i])) != kh_end(bidx)) { - int j; - bins_t *p = &kh_value(bidx, k); - for (j = 0; j < p->n; ++j) - if (p->list[j].v > min_off && p->list[j].u < max_off) - off[n_off++] = p->list[j]; - } - } - if (n_off == 0) { - free(off); return iter; - } - ks_introsort(_off, n_off, off); - // resolve completely contained adjacent blocks - for (i = 1, l = 0; i < n_off; ++i) - if (off[l].v < off[i].v) off[++l] = off[i]; - n_off = l + 1; - // resolve overlaps between adjacent blocks; this may happen due to the merge in indexing - for (i = 1; i < n_off; ++i) - if (off[i-1].v >= off[i].u) off[i-1].v = off[i].u; - // merge adjacent blocks - for (i = 1, l = 0; i < n_off; ++i) { - if (off[l].v>>16 == off[i].u>>16) off[l].v = off[i].v; - else off[++l] = off[i]; - } - n_off = l + 1; - iter->n_off = n_off; iter->off = off; + } + + if (n_off) { + ks_introsort(_off_max, n_off, off); + // resolve completely contained adjacent blocks + for (i = 1, l = 0; i < n_off; ++i) { + if (off[l].v < off[i].v) { + off[++l] = off[i]; + } else { + off[l].max = (off[i].max > off[l].max ? off[i].max : off[l].max); + } + } + n_off = l + 1; + // resolve overlaps between adjacent blocks; this may happen due to the merge in indexing + for (i = 1; i < n_off; ++i) + if (off[i-1].v >= off[i].u) off[i-1].v = off[i].u; + // merge adjacent blocks + for (i = 1, l = 0; i < n_off; ++i) { + if (off[l].v>>16 == off[i].u>>16) { + off[l].v = off[i].v; + off[l].max = (off[i].max > off[l].max ? off[i].max : off[l].max); + } else off[++l] = off[i]; + } + n_off = l + 1; + iter->n_off = n_off; iter->off = off; + } + + if(!n_off && !iter->nocoor) + iter->finished = 1; + return iter; } @@ -1956,6 +2449,30 @@ void hts_itr_destroy(hts_itr_t *iter) if (iter) { free(iter->off); free(iter->bins.a); free(iter); } } +void hts_reglist_free(hts_reglist_t *reglist, int count) { + + int i; + if(reglist) { + for (i=0;ireg_list && iter->n_reg) + hts_reglist_free(iter->reg_list, iter->n_reg); + + if (iter->off && iter->n_off) + free(iter->off); + free(iter); + } +} + static inline long long push_digit(long long i, char c) { // ensure subtraction occurs first, avoiding overflow for >= MAX-48 or so @@ -1995,14 +2512,15 @@ long long hts_parse_decimal(const char *str, char **strend, int flags) while (e > 0) n *= 10, e--; while (e < 0) lost += n % 10, n /= 10, e++; - if (lost > 0 && hts_verbose >= 3) - fprintf(stderr, "[W::%s] discarding fractional part of %.*s\n", - __func__, (int)(s - str), str); + if (lost > 0) { + hts_log_warning("Discarding fractional part of %.*s", (int)(s - str), str); + } - if (strend) *strend = (char *) s; - else if (*s && hts_verbose >= 2) - fprintf(stderr, "[W::%s] ignoring unknown characters after %.*s[%s]\n", - __func__, (int)(s - str), str, s); + if (strend) { + *strend = (char *)s; + } else if (*s) { + hts_log_warning("Ignoring unknown characters after %.*s[%s]", (int)(s - str), str, s); + } return (sign == '+')? n : -n; } @@ -2039,10 +2557,15 @@ hts_itr_t *hts_itr_querys(const hts_idx_t *idx, const char *reg, hts_name2id_f g q = hts_parse_reg(reg, &beg, &end); if (q) { - char *tmp = (char*)alloca(q - reg + 1); + char tmp_a[1024], *tmp = tmp_a; + if (q - reg + 1 > 1024) + if (!(tmp = malloc(q - reg + 1))) + return NULL; strncpy(tmp, reg, q - reg); tmp[q - reg] = 0; tid = getid(hdr, tmp); + if (tmp != tmp_a) + free(tmp); } else { // not parsable as a region, but possibly a sequence named "foo:a" @@ -2054,6 +2577,46 @@ hts_itr_t *hts_itr_querys(const hts_idx_t *idx, const char *reg, hts_name2id_f g return itr_query(idx, tid, beg, end, readrec); } +hts_itr_multi_t *hts_itr_regions(const hts_idx_t *idx, hts_reglist_t *reglist, int count, hts_name2id_f getid, void *hdr, hts_itr_multi_query_func *itr_specific, hts_readrec_func *readrec, hts_seek_func *seek, hts_tell_func *tell) { + + int i; + + if (!reglist) + return NULL; + + hts_itr_multi_t *itr = (hts_itr_multi_t*)calloc(1, sizeof(hts_itr_multi_t)); + if (itr) { + itr->n_reg = count; + itr->readrec = readrec; + itr->seek = seek; + itr->tell = tell; + itr->reg_list = reglist; + itr->finished = 0; + itr->nocoor = 0; + + + for (i = 0; i < itr->n_reg; i++) { + if (!strcmp(itr->reg_list[i].reg, ".")) { + itr->reg_list[i].tid = HTS_IDX_START; + continue; + } + + if (!strcmp(itr->reg_list[i].reg, "*")) { + itr->reg_list[i].tid = HTS_IDX_NOCOOR; + continue; + } + + itr->reg_list[i].tid = getid(hdr, reglist[i].reg); + if (itr->reg_list[i].tid < 0) + hts_log_warning("Region '%s' specifies an unknown reference name. Continue anyway", reglist[i].reg); + } + + qsort(itr->reg_list, itr->n_reg, sizeof(hts_reglist_t), compare_regions); + itr_specific(idx, itr); + } + return itr; +} + int hts_itr_next(BGZF *fp, hts_itr_t *iter, void *r, void *data) { int ret, tid, beg, end; @@ -2070,7 +2633,8 @@ int hts_itr_next(BGZF *fp, hts_itr_t *iter, void *r, void *data) iter->curr_end = end; return ret; } - if (iter->off == 0) return -1; + // A NULL iter->off should always be accompanied by iter->finished. + assert(iter->off != NULL); for (;;) { if (iter->curr_off == 0 || iter->curr_off >= iter->off[iter->i].v) { // then jump to the next chunk if (iter->i == iter->n_off - 1) { ret = -1; break; } // no more chunks @@ -2096,69 +2660,208 @@ int hts_itr_next(BGZF *fp, hts_itr_t *iter, void *r, void *data) return ret; } +int hts_itr_multi_next(htsFile *fd, hts_itr_multi_t *iter, void *r) +{ + void *fp; + int ret, tid, beg, end, i, cr, ci; + hts_reglist_t *found_reg; + + if (iter == NULL || iter->finished) return -1; + + if (iter->is_cram) { + fp = fd->fp.cram; + } else { + fp = fd->fp.bgzf; + } + + if (iter->read_rest) { + if (iter->curr_off) { // seek to the start + if (iter->seek(fp, iter->curr_off, SEEK_SET) < 0) { + return -1; + } + iter->curr_off = 0; // only seek once + } + + ret = iter->readrec(fp, fd, r, &tid, &beg, &end); + if (ret < 0) { + iter->finished = 1; + } + + iter->curr_tid = tid; + iter->curr_beg = beg; + iter->curr_end = end; + + return ret; + } + // A NULL iter->off should always be accompanied by iter->finished. + assert(iter->off != NULL || iter->nocoor != 0); + + for (;;) { + if (iter->curr_off == 0 || iter->curr_off >= iter->off[iter->i].v) { // then jump to the next chunk + if (iter->i == iter->n_off - 1) { // no more chunks, except NOCOORs + if (iter->nocoor) { + iter->read_rest = 1; + iter->curr_off = iter->nocoor_off; + + return hts_itr_multi_next(fd, iter, r); + } else { + ret = -1; break; + } + } + + if (iter->i < 0 || iter->off[iter->i].v != iter->off[iter->i+1].u) { // not adjacent chunks; then seek + if (iter->seek(fp, iter->off[iter->i+1].u, SEEK_SET) < 0) { + return -1; + } + + iter->curr_off = iter->tell(fp); + } + ++iter->i; + } + + if ((ret = iter->readrec(fp, fd, r, &tid, &beg, &end)) >= 0) { + iter->curr_off = iter->tell(fp); + if (tid != iter->curr_tid) { + hts_reglist_t key; + key.tid = tid; + + found_reg = (hts_reglist_t *)bsearch(&key, iter->reg_list, iter->n_reg, sizeof(hts_reglist_t), compare_regions); + + if (!found_reg) + continue; + + iter->curr_reg = (found_reg - iter->reg_list); + iter->curr_tid = tid; + iter->curr_intv = 0; + } + + cr = iter->curr_reg; + ci = iter->curr_intv; + + + if (beg > iter->off[iter->i].max) { + iter->curr_off = iter->off[iter->i].v; + continue; + } + if (beg > iter->reg_list[cr].max_end) + continue; + + for (i = ci; i < iter->reg_list[cr].count; i++) { + if (end > iter->reg_list[cr].intervals[i].beg && iter->reg_list[cr].intervals[i].end > beg) { + iter->curr_beg = beg; + iter->curr_end = end; + iter->curr_intv = i; + + return ret; + } + } + } else { + break; // end of file or error + } + } + iter->finished = 1; + + return ret; +} + /********************** *** Retrieve index *** **********************/ - -static char *test_and_fetch(const char *fn) +// Returns -1 if index couldn't be opened. +// -2 on other errors +static int test_and_fetch(const char *fn, const char **local_fn) { + hFILE *remote_hfp; + FILE *local_fp = NULL; + uint8_t *buf = NULL; + int save_errno; + if (hisremote(fn)) { const int buf_size = 1 * 1024 * 1024; - hFILE *fp_remote; - FILE *fp; - uint8_t *buf; int l; const char *p; for (p = fn + strlen(fn) - 1; p >= fn; --p) if (*p == '/') break; ++p; // p now points to the local file name // Attempt to open local file first - if ((fp = fopen((char*)p, "rb")) != 0) + if ((local_fp = fopen((char*)p, "rb")) != 0) { - fclose(fp); - return (char*)p; + fclose(local_fp); + *local_fn = p; + return 0; } // Attempt to open remote file. Stay quiet on failure, it is OK to fail when trying first .csi then .tbi index. - if ((fp_remote = hopen(fn, "r")) == 0) return 0; - if ((fp = fopen(p, "w")) == 0) { - if (hts_verbose >= 1) fprintf(stderr, "[E::%s] fail to create file '%s' in the working directory\n", __func__, p); - hclose_abruptly(fp_remote); - return 0; + if ((remote_hfp = hopen(fn, "r")) == 0) return -1; + if ((local_fp = fopen(p, "w")) == 0) { + hts_log_error("Failed to create file %s in the working directory", p); + goto fail; } - if (hts_verbose >= 3) fprintf(stderr, "[M::%s] downloading file '%s' to local directory\n", __func__, fn); + hts_log_info("Downloading file %s to local directory", fn); buf = (uint8_t*)calloc(buf_size, 1); - while ((l = hread(fp_remote, buf, buf_size)) > 0) fwrite(buf, 1, l, fp); + if (!buf) { + hts_log_error("%s", strerror(errno)); + goto fail; + } + while ((l = hread(remote_hfp, buf, buf_size)) > 0) { + if (fwrite(buf, 1, l, local_fp) != l) { + hts_log_error("Failed to write data to %s : %s", + fn, strerror(errno)); + goto fail; + } + } free(buf); - fclose(fp); - if (hclose(fp_remote) != 0) fprintf(stderr, "[E::%s] fail to close remote file '%s'\n", __func__, fn); - return (char*)p; + if (fclose(local_fp) < 0) { + hts_log_error("Error closing %s : %s", fn, strerror(errno)); + local_fp = NULL; + goto fail; + } + if (hclose(remote_hfp) != 0) { + hts_log_error("Failed to close remote file %s", fn); + } + *local_fn = p; + return 0; } else { - hFILE *fp; - if ((fp = hopen(fn, "r")) == 0) return 0; - hclose_abruptly(fp); - return (char*)fn; + hFILE *local_hfp; + if ((local_hfp = hopen(fn, "r")) == 0) return -1; + hclose_abruptly(local_hfp); + *local_fn = fn; + return 0; } + + fail: + save_errno = errno; + hclose_abruptly(remote_hfp); + if (local_fp) fclose(local_fp); + free(buf); + errno = save_errno; + return -2; } char *hts_idx_getfn(const char *fn, const char *ext) { - int i, l_fn, l_ext; - char *fnidx, *ret; + int i, l_fn, l_ext, ret; + char *fnidx; + const char *local_fn = NULL; l_fn = strlen(fn); l_ext = strlen(ext); fnidx = (char*)calloc(l_fn + l_ext + 1, 1); + if (!fnidx) return NULL; + // First try : append `ext` to `fn` strcpy(fnidx, fn); strcpy(fnidx + l_fn, ext); - if ((ret = test_and_fetch(fnidx)) == 0) { + if ((ret = test_and_fetch(fnidx, &local_fn)) == -1) { + // Second try : replace suffix of `fn` with `ext` for (i = l_fn - 1; i > 0; --i) - if (fnidx[i] == '.') break; - strcpy(fnidx + i, ext); - ret = test_and_fetch(fnidx); + if (fnidx[i] == '.' || fnidx[i] == '/') break; + if (fnidx[i] == '.') { + strcpy(fnidx + i, ext); + ret = test_and_fetch(fnidx, &local_fn); + } } - if (ret == 0) { + if (ret < 0) { free(fnidx); - return 0; + return NULL; } - l_fn = strlen(ret); - memmove(fnidx, ret, l_fn + 1); + l_fn = strlen(local_fn); + memmove(fnidx, local_fn, l_fn + 1); return fnidx; } @@ -2181,9 +2884,104 @@ hts_idx_t *hts_idx_load2(const char *fn, const char *fnidx) struct stat stat_idx,stat_main; if ( !stat(fn, &stat_main) && !stat(fnidx, &stat_idx) ) { - if ( hts_verbose >= 1 && stat_idx.st_mtime < stat_main.st_mtime ) - fprintf(stderr, "Warning: The index file is older than the data file: %s\n", fnidx); + if ( stat_idx.st_mtime < stat_main.st_mtime ) + hts_log_warning("The index file is older than the data file: %s", fnidx); } return hts_idx_load_local(fnidx); } + + + +/********************** + *** Memory *** + **********************/ + +/* For use with hts_expand macros *only* */ +size_t hts_realloc_or_die(size_t n, size_t m, size_t m_sz, size_t size, + int clear, void **ptr, const char *func) { + /* If new_m and size are both below this limit, multiplying them + together can't overflow */ + const size_t safe = (size_t) 1 << (sizeof(size_t) * 4); + void *new_ptr; + size_t bytes, new_m; + + new_m = n; + kroundup_size_t(new_m); + + bytes = size * new_m; + + /* Check for overflow. Both ensure that new_m will fit in m (we make the + pessimistic assumption that m is signed), and that bytes has not + wrapped around. */ + if (new_m > (((size_t) 1 << (m_sz * 8 - 1)) - 1) + || ((size > safe || new_m > safe) + && bytes / new_m != size)) { + errno = ENOMEM; + goto die; + } + + new_ptr = realloc(*ptr, bytes); + if (new_ptr == NULL) goto die; + + if (clear) { + if (new_m > m) { + memset((char *) new_ptr + m * size, 0, (new_m - m) * size); + } + } + + *ptr = new_ptr; + + return new_m; + + die: + hts_log_error("%s", strerror(errno)); + exit(1); +} + +void hts_set_log_level(enum htsLogLevel level) +{ + hts_verbose = level; +} + +enum htsLogLevel hts_get_log_level() +{ + return hts_verbose; +} + +static char get_severity_tag(enum htsLogLevel severity) +{ + switch (severity) { + case HTS_LOG_ERROR: + return 'E'; + case HTS_LOG_WARNING: + return 'W'; + case HTS_LOG_INFO: + return 'I'; + case HTS_LOG_DEBUG: + return 'D'; + case HTS_LOG_TRACE: + return 'T'; + default: + break; + } + + return '*'; +} + +void hts_log(enum htsLogLevel severity, const char *context, const char *format, ...) +{ + int save_errno = errno; + if (severity <= hts_verbose) { + va_list argptr; + + fprintf(stderr, "[%c::%s] ", get_severity_tag(severity), context); + + va_start(argptr, format); + vfprintf(stderr, format, argptr); + va_end(argptr); + + fprintf(stderr, "\n"); + } + errno = save_errno; +} diff --git a/htslib/hts_internal.h b/htslib/hts_internal.h index 07d6a1175..dec151288 100644 --- a/htslib/hts_internal.h +++ b/htslib/hts_internal.h @@ -28,29 +28,21 @@ DEALINGS IN THE SOFTWARE. */ #include "htslib/hts.h" +#include "textutils_internal.h" + #ifdef __cplusplus extern "C" { #endif -// The functions operate on ints such as are returned by fgetc(), -// i.e., characters represented as unsigned-char-valued ints, or EOF. -// To operate on plain chars (and to avoid warnings on some platforms), -// technically one must cast to unsigned char everywhere (see CERT STR37-C) -// or less painfully use these *_c() functions that operate on plain chars -// (but not EOF, which must be considered separately where it is applicable). -// TODO We may eventually wish to implement these functions directly without -// using their equivalents, and thus make them immune to locales. -static inline int isalnum_c(char c) { return isalnum((unsigned char) c); } -static inline int isalpha_c(char c) { return isalpha((unsigned char) c); } -static inline int isdigit_c(char c) { return isdigit((unsigned char) c); } -static inline int isgraph_c(char c) { return isgraph((unsigned char) c); } -static inline int islower_c(char c) { return islower((unsigned char) c); } -static inline int isprint_c(char c) { return isprint((unsigned char) c); } -static inline int isspace_c(char c) { return isspace((unsigned char) c); } -static inline int isupper_c(char c) { return isupper((unsigned char) c); } -static inline char tolower_c(char c) { return tolower((unsigned char) c); } -static inline char toupper_c(char c) { return toupper((unsigned char) c); } +struct hFILE; +struct hts_json_token { + char type; ///< Token type + char *str; ///< Value as a C string (filled in for all token types) + // TODO Add other fields to fill in for particular data types, e.g. + // int inum; + // float fnum; +}; struct cram_fd; @@ -66,6 +58,9 @@ typedef struct hts_cram_idx_t { } hts_cram_idx_t; +// Entry point to hFILE_multipart backend. +struct hFILE *hopen_htsget_redirect(struct hFILE *hfile, const char *mode); + struct hts_path_itr { kstring_t path, entry; void *dirv; // DIR * privately diff --git a/samtools/errmod.h b/htslib/hts_os.c similarity index 60% rename from samtools/errmod.h rename to htslib/hts_os.c index 6db46f4b8..0e6dc8eb1 100644 --- a/samtools/errmod.h +++ b/htslib/hts_os.c @@ -1,9 +1,9 @@ -/* errmod.h -- revised MAQ error model. - - Copyright (C) 2010 Broad Institute. - Copyright (C) 2012 Genome Research Ltd. +/// @file hts_os.c +/// Operating System specific tweaks, for compatibility with POSIX. +/* + Copyright (C) 2017 Genome Research Ltd. - Author: Heng Li + Author: James Bonfield Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,27 +23,21 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef ERRMOD_H -#define ERRMOD_H - -#include - -struct __errmod_coef_t; - -typedef struct { - double depcorr; - struct __errmod_coef_t *coef; -} errmod_t; - -errmod_t *errmod_init(double depcorr); -void errmod_destroy(errmod_t *em); - -/* - n: number of bases - m: maximum base - bases[i]: qual:6, strand:1, base:4 - q[i*m+j]: phred-scaled likelihood of (i,j) - */ -int errmod_cal(const errmod_t *em, int n, int m, uint16_t *bases, float *q); - +#include + +// Windows (maybe more) lack a drand48 implementation. +#ifndef HAVE_DRAND48 +#include "os/rand.c" +#else +#include +void hts_srand48(long seed) { srand48(seed); } +double hts_erand48(unsigned short xseed[3]) { return erand48(xseed); } +double hts_drand48(void) { return drand48(); } +double hts_lrand48(void) { return lrand48(); } #endif + +// // On Windows when using the MSYS or Cygwin terminals, isatty fails +// #ifdef _WIN32 +// #define USE_FILEEXTD +// #include "os/iscygpty.c" +// #endif diff --git a/htslib/htsfile.1 b/htslib/htsfile.1 index 56361f586..502b3f57d 100644 --- a/htslib/htsfile.1 +++ b/htslib/htsfile.1 @@ -1,8 +1,8 @@ -.TH htsfile 1 "13 September 2016" "htslib-1.3.2" "Bioinformatics tools" +.TH htsfile 1 "26 January 2018" "htslib-1.7" "Bioinformatics tools" .SH NAME htsfile \- identify high-throughput sequencing data files .\" -.\" Copyright (C) 2015 Genome Research Ltd. +.\" Copyright (C) 2015, 2017 Genome Research Ltd. .\" .\" Author: John Marshall .\" @@ -57,6 +57,11 @@ The following options are accepted: .BR -c ", " --view Instead of identifying the specified files, display a textual representation of their contents on standard output. +.IP +By default, \fB--view\fR refuses to display files in unknown formats. +When \fB--verbose\fR is also given, the raw contents of such files are +displayed, with non-printable characters shown via C-style "\\x" hexadecimal +escape sequences. .TP .BR -h ", " --header-only Display data file headers only. diff --git a/htslib/htsfile.c b/htslib/htsfile.c index 3fa067847..bc54ab6dc 100644 --- a/htslib/htsfile.c +++ b/htslib/htsfile.c @@ -1,6 +1,6 @@ /* htsfile.c -- file identifier and minimal viewer. - Copyright (C) 2014-2016 Genome Research Ltd. + Copyright (C) 2014-2018 Genome Research Ltd. Author: John Marshall @@ -24,9 +24,12 @@ DEALINGS IN THE SOFTWARE. */ #include +#include #include +#include #include #include +#include #include #include @@ -37,110 +40,134 @@ DEALINGS IN THE SOFTWARE. */ enum { identify, view_headers, view_all } mode = identify; int show_headers = 1; +int verbose = 0; int status = EXIT_SUCCESS; /* Exit status from main */ +void error(const char *format, ...) +{ + int err = errno; + va_list args; + va_start(args, format); + fflush(stdout); + fprintf(stderr, "htsfile: "); + vfprintf(stderr, format, args); + if (err) fprintf(stderr, ": %s\n", strerror(err)); + else fprintf(stderr, "\n"); + fflush(stderr); + va_end(args); + status = EXIT_FAILURE; +} + static htsFile *dup_stdout(const char *mode) { int fd = dup(STDOUT_FILENO); - if (fd < 0) { - perror("htsfile: Couldn't duplicate stdout"); - return NULL; - } - hFILE *hfp = hdopen(fd, mode); + hFILE *hfp = (fd >= 0)? hdopen(fd, mode) : NULL; return hfp? hts_hopen(hfp, "-", mode) : NULL; } -static int view_sam(hFILE *hfp, const char *filename) +static void view_sam(samFile *in, const char *filename) { - samFile *in = hts_hopen(hfp, filename, "r"); + bam1_t *b = NULL; bam_hdr_t *hdr = NULL; samFile *out = NULL; - if (in == NULL) { - status = EXIT_FAILURE; - return 0; - } + hdr = sam_hdr_read(in); if (hdr == NULL) { - status = EXIT_FAILURE; + errno = 0; error("reading headers from \"%s\" failed", filename); goto clean; } + out = dup_stdout("w"); - if (out == NULL) { - status = EXIT_FAILURE; - goto clean; - } + if (out == NULL) { error("reopening standard output failed"); goto clean; } if (show_headers) { if (sam_hdr_write(out, hdr) != 0) { - status = EXIT_FAILURE; + error("writing headers to standard output failed"); goto clean; } } + if (mode == view_all) { - bam1_t *b = bam_init1(); int ret; + + b = bam_init1(); + if (b == NULL) { error("can't create record"); goto clean; } + while ((ret = sam_read1(in, hdr, b)) >= 0) { if (sam_write1(out, hdr, b) < 0) { - status = EXIT_FAILURE; + error("writing to standard output failed"); goto clean; } } - bam_destroy1(b); - if (ret != -1) // eof - status = EXIT_FAILURE; + + if (ret < -1) { error("reading \"%s\" failed", filename); goto clean; } } clean: - if (hdr != NULL) bam_hdr_destroy(hdr); - if (out != NULL && hts_close(out) != 0) - status = EXIT_FAILURE; - if (hts_close(in) != 0) - status = EXIT_FAILURE; - return 1; + bam_hdr_destroy(hdr); + bam_destroy1(b); + if (out) hts_close(out); } -static int view_vcf(hFILE *hfp, const char *filename) +static void view_vcf(vcfFile *in, const char *filename) { - vcfFile *in = hts_hopen(hfp, filename, "r"); + bcf1_t *rec = NULL; bcf_hdr_t *hdr = NULL; vcfFile *out = NULL; - if (in == NULL) { - status = EXIT_FAILURE; - return 0; - } + hdr = bcf_hdr_read(in); if (hdr == NULL) { - status = EXIT_FAILURE; + errno = 0; error("reading headers from \"%s\" failed", filename); goto clean; } + out = dup_stdout("w"); - if (out == NULL) { - status = EXIT_FAILURE; - goto clean; - } + if (out == NULL) { error("reopening standard output failed"); goto clean; } if (show_headers) { if (bcf_hdr_write(out, hdr) != 0) { - status = EXIT_FAILURE; + error("writing headers to standard output failed"); goto clean; } } + if (mode == view_all) { - bcf1_t *rec = bcf_init(); - while (bcf_read(in, hdr, rec) >= 0) { + int ret; + + rec = bcf_init(); + if (rec == NULL) { error("can't create record"); goto clean; } + + while ((ret = bcf_read(in, hdr, rec)) >= 0) { if (bcf_write(out, hdr, rec) < 0) { - status = EXIT_FAILURE; + error("writing to standard output failed"); goto clean; } } - bcf_destroy(rec); + + if (ret < -1) { error("reading \"%s\" failed", filename); goto clean; } } clean: - if (hdr != NULL) bcf_hdr_destroy(hdr); - if (out != NULL) hts_close(out); - hts_close(in); - return 1; + if (hdr) bcf_hdr_destroy(hdr); + if (rec) bcf_destroy(rec); + if (out) hts_close(out); +} + +static void view_raw(hFILE *fp, const char *filename) +{ + int c, prev; + for (prev = '\n'; (c = hgetc(fp)) != EOF; prev = c) + if (isprint(c) || c == '\n' || c == '\t') putchar(c); + else if (c == '\r') fputs("\\r", stdout); + else if (c == '\0') fputs("\\0", stdout); + else printf("\\x%02x", c); + + if (prev != '\n') putchar('\n'); + + if (herrno(fp)) { + errno = herrno(fp); + error("reading \"%s\" failed", filename); + } } static void usage(FILE *fp, int status) @@ -175,11 +202,11 @@ int main(int argc, char **argv) case 'c': mode = view_all; break; case 'h': mode = view_headers; show_headers = 1; break; case 'H': show_headers = 0; break; - case 'v': hts_verbose++; break; + case 'v': hts_verbose++; verbose++; break; case 1: printf( "htsfile (htslib) %s\n" -"Copyright (C) 2016 Genome Research Ltd.\n", +"Copyright (C) 2018 Genome Research Ltd.\n", hts_version()); exit(EXIT_SUCCESS); break; @@ -190,44 +217,54 @@ int main(int argc, char **argv) if (optind == argc) usage(stderr, EXIT_FAILURE); for (i = optind; i < argc; i++) { - htsFormat fmt; hFILE *fp = hopen(argv[i], "r"); if (fp == NULL) { - fprintf(stderr, "htsfile: can't open \"%s\": %s\n", argv[i], strerror(errno)); - status = EXIT_FAILURE; - continue; - } - - if (hts_detect_format(fp, &fmt) < 0) { - fprintf(stderr, "htsfile: detecting \"%s\" format failed: %s\n", argv[i], strerror(errno)); - hclose_abruptly(fp); - status = EXIT_FAILURE; + error("can't open \"%s\"", argv[i]); continue; } if (mode == identify) { + htsFormat fmt; + if (hts_detect_format(fp, &fmt) < 0) { + error("detecting \"%s\" format failed", argv[i]); + hclose_abruptly(fp); + continue; + } + char *description = hts_format_description(&fmt); printf("%s:\t%s\n", argv[i], description); free(description); } - else - switch (fmt.category) { - case sequence_data: - if (view_sam(fp, argv[i])) fp = NULL; - break; - case variant_data: - if (view_vcf(fp, argv[i])) fp = NULL; - break; - default: - fprintf(stderr, "htsfile: can't view %s: unknown format\n", argv[i]); - status = EXIT_FAILURE; - break; - } + else { + htsFile *hts = hts_hopen(fp, argv[i], "r"); + if (hts) { + switch (hts_get_format(hts)->category) { + case sequence_data: + view_sam(hts, argv[i]); + break; + case variant_data: + view_vcf(hts, argv[i]); + break; + default: + if (verbose) + view_raw(fp, argv[i]); + else { + errno = 0; + error("can't view \"%s\": unknown format", argv[i]); + } + break; + } - if (fp && hclose(fp) < 0) { - fprintf(stderr, "htsfile: closing %s failed\n", argv[i]); - status = EXIT_FAILURE; + if (hts_close(hts) < 0) error("closing \"%s\" failed", argv[i]); + fp = NULL; + } + else if (errno == ENOEXEC && verbose) + view_raw(fp, argv[i]); + else + error("can't view \"%s\"", argv[i]); } + + if (fp && hclose(fp) < 0) error("closing \"%s\" failed", argv[i]); } return status; diff --git a/htslib/htslib.mk b/htslib/htslib.mk index 6940e8a77..93ef1c7bc 100644 --- a/htslib/htslib.mk +++ b/htslib/htslib.mk @@ -1,6 +1,6 @@ # Makefile rules useful for third-party code using htslib's public API. # -# Copyright (C) 2013-2015 Genome Research Ltd. +# Copyright (C) 2013-2016 Genome Research Ltd. # # Author: John Marshall # @@ -53,6 +53,8 @@ HTSLIB_PUBLIC_HEADERS = \ $(HTSDIR)/htslib/hfile.h \ $(HTSDIR)/htslib/hts.h \ $(HTSDIR)/htslib/hts_defs.h \ + $(HTSDIR)/htslib/hts_endian.h \ + $(HTSDIR)/htslib/hts_log.h \ $(HTSDIR)/htslib/kbitset.h \ $(HTSDIR)/htslib/kfunc.h \ $(HTSDIR)/htslib/khash.h \ @@ -73,6 +75,8 @@ HTSLIB_PUBLIC_HEADERS = \ HTSLIB_ALL = \ $(HTSLIB_PUBLIC_HEADERS) \ + $(HTSDIR)/bcf_sr_sort.c \ + $(HTSDIR)/bcf_sr_sort.h \ $(HTSDIR)/bgzf.c \ $(HTSDIR)/config.h \ $(HTSDIR)/crypto.h \ @@ -81,14 +85,17 @@ HTSLIB_ALL = \ $(HTSDIR)/faidx.c \ $(HTSDIR)/hfile_internal.h \ $(HTSDIR)/hfile.c \ + $(HTSDIR)/hfile_gcs.c \ $(HTSDIR)/hfile_libcurl.c \ $(HTSDIR)/hfile_net.c \ + $(HTSDIR)/hfile_s3.c \ $(HTSDIR)/hts.c \ $(HTSDIR)/hts_internal.h \ $(HTSDIR)/kfunc.c \ $(HTSDIR)/knetfile.c \ $(HTSDIR)/kstring.c \ $(HTSDIR)/md5.c \ + $(HTSDIR)/multipart.c \ $(HTSDIR)/plugin.c \ $(HTSDIR)/probaln.c \ $(HTSDIR)/realn.c \ @@ -96,7 +103,9 @@ HTSLIB_ALL = \ $(HTSDIR)/sam.c \ $(HTSDIR)/synced_bcf_reader.c \ $(HTSDIR)/tbx.c \ + $(HTSDIR)/textutils.c \ $(HTSDIR)/thread_pool.c \ + $(HTSDIR)/thread_pool_internal.h \ $(HTSDIR)/vcf.c \ $(HTSDIR)/vcf_sweep.c \ $(HTSDIR)/vcfutils.c \ @@ -132,11 +141,7 @@ HTSLIB_ALL = \ $(HTSDIR)/cram/sam_header.c \ $(HTSDIR)/cram/sam_header.h \ $(HTSDIR)/cram/string_alloc.c \ - $(HTSDIR)/cram/string_alloc.h \ - $(HTSDIR)/cram/vlen.c \ - $(HTSDIR)/cram/vlen.h \ - $(HTSDIR)/cram/zfio.c \ - $(HTSDIR)/cram/zfio.h + $(HTSDIR)/cram/string_alloc.h $(HTSDIR)/config.h: +cd $(HTSDIR) && $(MAKE) config.h @@ -156,6 +161,12 @@ $(HTSDIR)/htsfile: $(HTSDIR)/htsfile.c $(HTSLIB_PUBLIC_HEADERS) $(HTSDIR)/tabix: $(HTSDIR)/tabix.c $(HTSLIB_PUBLIC_HEADERS) +cd $(HTSDIR) && $(MAKE) tabix +$(HTSDIR)/htslib_static.mk: $(HTSDIR)/htslib.pc.tmp + +cd $(HTSDIR) && $(MAKE) htslib_static.mk + +$(HTSDIR)/htslib.pc.tmp: + +cd $(HTSDIR) && $(MAKE) htslib.pc.tmp + # Rules for phony targets. You may wish to have your corresponding phony # targets invoke these in addition to their own recipes: # diff --git a/htslib/htslib.pc.in b/htslib/htslib.pc.in index 465de178e..d969d6b4d 100644 --- a/htslib/htslib.pc.in +++ b/htslib/htslib.pc.in @@ -1,10 +1,15 @@ -includedir=@includedir@ -libdir=@libdir@ +includedir=@-includedir@ +libdir=@-libdir@ + +# Flags and libraries needed when linking against a static libhts.a +# (used by manual and semi-manual pkg-config(1)-style enquiries). +static_ldflags=@static_LDFLAGS@ +static_libs=@static_LIBS@ Name: htslib Description: C library for high-throughput sequencing data formats -Version: @PACKAGE_VERSION@ +Version: @-PACKAGE_VERSION@ Cflags: -I${includedir} Libs: -L${libdir} -lhts -Libs.private: -L${libdir} -lhts -lm -lpthread -Requires.private: zlib +Libs.private: -L${libdir} @private_LIBS@ -lhts -lm -lpthread +Requires.private: zlib @pc_requires@ diff --git a/htslib/htslib.pc.tmp b/htslib/htslib.pc.tmp new file mode 100644 index 000000000..60801aa86 --- /dev/null +++ b/htslib/htslib.pc.tmp @@ -0,0 +1,15 @@ +includedir=@-includedir@ +libdir=@-libdir@ + +# Flags and libraries needed when linking against a static libhts.a +# (used by manual and semi-manual pkg-config(1)-style enquiries). +static_ldflags= +static_libs=-lz -lm -lbz2 -llzma -lcurl + +Name: htslib +Description: C library for high-throughput sequencing data formats +Version: @-PACKAGE_VERSION@ +Cflags: -I${includedir} +Libs: -L${libdir} -lhts +Libs.private: -L${libdir} -lbz2 -lhts -lm -lpthread +Requires.private: zlib liblzma diff --git a/htslib/htslib/bgzf.h b/htslib/htslib/bgzf.h index 27935b69a..c78fa929f 100644 --- a/htslib/htslib/bgzf.h +++ b/htslib/htslib/bgzf.h @@ -3,7 +3,7 @@ /* Copyright (c) 2008 Broad Institute / Massachusetts Institute of Technology 2011, 2012 Attractive Chaos - Copyright (C) 2009, 2013, 2014 Genome Research Ltd + Copyright (C) 2009, 2013, 2014,2017 Genome Research Ltd Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -48,22 +48,26 @@ extern "C" { #define BGZF_ERR_HEADER 2 #define BGZF_ERR_IO 4 #define BGZF_ERR_MISUSE 8 +#define BGZF_ERR_MT 16 // stream cannot be multi-threaded +#define BGZF_ERR_CRC 32 struct hFILE; struct hts_tpool; struct bgzf_mtaux_t; typedef struct __bgzidx_t bgzidx_t; typedef struct __bgzf_aux_t bgzf_aux_t; +typedef struct bgzf_cache_t bgzf_cache_t; struct BGZF { - unsigned errcode:16, is_write:2, is_be:2; + // Reserved bits should be written as 0; read as "don't care" + unsigned errcode:16, reserved:1, is_write:1, no_eof_block:1, is_be:1; signed compress_level:9; - unsigned is_compressed:2, is_gzip:1; + unsigned last_block_eof:1, is_compressed:1, is_gzip:1; int cache_size; int block_length, block_clength, block_offset; int64_t block_address, uncompressed_address; void *uncompressed_block, *compressed_block; - void *cache; // a pointer to a hash table + bgzf_cache_t *cache; // pointer to a hash table struct hFILE *fp; // actual file handle struct bgzf_mtaux_t *mt; // only used for multi-threading bgzidx_t *idx; // BGZF index @@ -92,6 +96,9 @@ typedef struct __kstring_t { * Open an existing file descriptor for reading or writing. * * @param fd file descriptor + * Note that the file must be opened in binary mode, or else + * there will be problems on platforms that make a difference + * between text and binary mode. * @param mode mode matching /[rwag][u0-9]+/: 'r' for reading, 'w' for * writing, 'a' for appending, 'g' for gzip rather than BGZF * compression (with 'w' only), and digit specifies the zlib @@ -198,7 +205,7 @@ typedef struct __kstring_t { /** * Return a virtual file pointer to the current location in the file. - * No interpetation of the value should be made, other than a subsequent + * No interpretation of the value should be made, other than a subsequent * call to bgzf_seek can be used to position the file at the same point. * Return value is non-negative on success. */ @@ -225,13 +232,25 @@ typedef struct __kstring_t { */ int bgzf_check_EOF(BGZF *fp); + /** Return the file's compression format + * + * @param fp BGZF file handle + * @return A small integer matching the corresponding + * `enum htsCompression` value: + * - 0 / `no_compression` if the file is uncompressed + * - 1 / `gzip` if the file is plain GZIP-compressed + * - 2 / `bgzf` if the file is BGZF-compressed + * @since 1.4 + */ + int bgzf_compression(BGZF *fp); + /** * Check if a file is in the BGZF format * * @param fn file name * @return 1 if _fn_ is BGZF; 0 if not or on I/O error */ - int bgzf_is_bgzf(const char *fn); + int bgzf_is_bgzf(const char *fn) HTS_DEPRECATED("Use bgzf_compression() or hts_detect_format() instead"); /********************* * Advanced routines * @@ -264,7 +283,7 @@ typedef struct __kstring_t { * @param fp BGZF file handler * @param delim delimitor * @param str string to write to; must be initialized - * @return length of the string; 0 on end-of-file; negative on error + * @return length of the string; -1 on end-of-file; <= -2 on error */ int bgzf_getline(BGZF *fp, int delim, kstring_t *str); @@ -339,29 +358,61 @@ typedef struct __kstring_t { */ int bgzf_index_build_init(BGZF *fp); + /// Load BGZF index /** - * Load BGZF index - * * @param fp BGZF file handler * @param bname base name * @param suffix suffix to add to bname (can be NULL) - * - * Returns 0 on success and -1 on error. + * @return 0 on success and -1 on error. */ - int bgzf_index_load(BGZF *fp, const char *bname, const char *suffix); + int bgzf_index_load(BGZF *fp, + const char *bname, const char *suffix) HTS_RESULT_USED; + /// Load BGZF index from an hFILE /** - * Save BGZF index + * @param fp BGZF file handle + * @param idx hFILE to read from + * @param name file name (for error reporting only; can be NULL) + * @return 0 on success and -1 on error. + * + * Populates @p fp with index data read from the hFILE handle @p idx. + * The file pointer to @idx should point to the start of the index + * data when this function is called. * + * The file name can optionally be passed in the @p name parameter. This + * is only used for printing error messages; if NULL the word "index" is + * used instead. + */ + int bgzf_index_load_hfile(BGZF *fp, struct hFILE *idx, + const char *name) HTS_RESULT_USED; + + /// Save BGZF index + /** * @param fp BGZF file handler * @param bname base name * @param suffix suffix to add to bname (can be NULL) - * - * Returns 0 on success and -1 on error. + * @return 0 on success and -1 on error. */ int bgzf_index_dump(BGZF *fp, const char *bname, const char *suffix) HTS_RESULT_USED; + /// Write a BGZF index to an hFILE + /** + * @param fp BGZF file handle + * @param idx hFILE to write to + * @param name file name (for error reporting only, can be NULL) + * @return 0 on success and -1 on error. + * + * Write index data from @p fp to the file @p idx. + * + * The file name can optionally be passed in the @p name parameter. This + * is only used for printing error messages; if NULL the word "index" is + * used instead. + */ + + int bgzf_index_dump_hfile(BGZF *fp, struct hFILE *idx, + const char *name) HTS_RESULT_USED; + #ifdef __cplusplus } #endif diff --git a/htslib/htslib/faidx.h b/htslib/htslib/faidx.h index 5d60efc3f..76235cfbb 100644 --- a/htslib/htslib/faidx.h +++ b/htslib/htslib/faidx.h @@ -1,7 +1,7 @@ /// @file htslib/faidx.h /// FASTA random access. /* - Copyright (C) 2008, 2009, 2013, 2014, 2016 Genome Research Ltd. + Copyright (C) 2008, 2009, 2013, 2014, 2016, 2017 Genome Research Ltd. Author: Heng Li @@ -53,19 +53,56 @@ struct __faidx_t; /// Opaque structure representing FASTA index typedef struct __faidx_t faidx_t; +/// Build index for a FASTA or bgzip-compressed FASTA file. +/** @param fn FASTA file name + @param fnfai Name of .fai file to build. + @param fngzi Name of .gzi file to build (if fn is bgzip-compressed). + @return 0 on success; or -1 on failure + +If fnfai is NULL, ".fai" will be appended to fn to make the FAI file name. +If fngzi is NULL, ".gzi" will be appended to fn for the GZI file. The GZI +file will only be built if fn is bgzip-compressed. +*/ +int fai_build3(const char *fn, const char *fnfai, const char *fngzi) HTS_RESULT_USED; + /// Build index for a FASTA or bgzip-compressed FASTA file. /** @param fn FASTA file name @return 0 on success; or -1 on failure -File "fn.fai" will be generated. +File "fn.fai" will be generated. This function is equivalent to +fai_build3(fn, NULL, NULL); */ int fai_build(const char *fn) HTS_RESULT_USED; /// Destroy a faidx_t struct void fai_destroy(faidx_t *fai); +enum fai_load_options { + FAI_CREATE = 0x01, +}; + +/// Load FASTA indexes. +/** @param fn File name of the FASTA file (can be compressed with bgzip). + @param fnfai File name of the FASTA index. + @param fngzi File name of the bgzip index. + @param flags Option flags to control index file caching and creation. + @return Pointer to a faidx_t struct on success, NULL on failure. + +If fnfai is NULL, ".fai" will be appended to fn to make the FAI file name. +If fngzi is NULL, ".gzi" will be appended to fn for the bgzip index name. +The bgzip index is only needed if fn is compressed. + +If (flags & FAI_CREATE) is true, the index files will be built using +fai_build3() if they are not already present. +*/ +faidx_t *fai_load3(const char *fn, const char *fnfai, const char *fngzi, + int flags); + /// Load index from "fn.fai". /** @param fn File name of the FASTA file + @return Pointer to a faidx_t struct on success, NULL on failure. + +This function is equivalent to fai_load3(fn, NULL, NULL, FAI_CREATE|FAI_CACHE); */ faidx_t *fai_load(const char *fn); diff --git a/htslib/htslib/hfile.h b/htslib/htslib/hfile.h index b916c564b..e1607102c 100644 --- a/htslib/htslib/hfile.h +++ b/htslib/htslib/hfile.h @@ -48,7 +48,7 @@ typedef struct hFILE { char *buffer, *begin, *end, *limit; const struct hFILE_backend *backend; off_t offset; - unsigned at_eof:1; + unsigned at_eof:1, mobile:1, readonly:1; int has_errno; // @endcond } hFILE; @@ -58,13 +58,18 @@ typedef struct hFILE { The usual `fopen(3)` _mode_ letters are supported: one of `r` (read), `w` (write), `a` (append), optionally followed by any of -`+` (update), `e` (close on `exec(2)`), `x` (create exclusively). +`+` (update), `e` (close on `exec(2)`), `x` (create exclusively), +`:` (indicates scheme-specific variable arguments follow). */ -hFILE *hopen(const char *filename, const char *mode) HTS_RESULT_USED; +hFILE *hopen(const char *filename, const char *mode, ...) HTS_RESULT_USED; /// Associate a stream with an existing open file descriptor /** @return An hFILE pointer, or `NULL` (with _errno_ set) if an error occurred. +Note that the file must be opened in binary mode, or else +there will be problems on platforms that make a difference +between text and binary mode. + For socket descriptors (on Windows), _mode_ should contain `s`. */ hFILE *hdopen(int fd, const char *mode) HTS_RESULT_USED; @@ -197,7 +202,7 @@ hread(hFILE *fp, void *buffer, size_t nbytes) if (n > nbytes) n = nbytes; memcpy(buffer, fp->begin, n); fp->begin += n; - return (n == nbytes)? (ssize_t) n : hread2(fp, buffer, nbytes, n); + return (n == nbytes || !fp->mobile)? (ssize_t) n : hread2(fp, buffer, nbytes, n); } /// Write a character to the stream @@ -234,6 +239,14 @@ static inline ssize_t HTS_RESULT_USED hwrite(hFILE *fp, const void *buffer, size_t nbytes) { extern ssize_t hwrite2(hFILE *, const void *, size_t, size_t); + extern int hfile_set_blksize(hFILE *fp, size_t bufsiz); + + if(!fp->mobile){ + if (fp->limit - fp->begin < nbytes){ + hfile_set_blksize(fp, fp->limit - fp->buffer + nbytes); + fp->end = fp->limit; + } + } size_t n = fp->limit - fp->begin; if (n > nbytes) n = nbytes; @@ -249,6 +262,24 @@ This includes low-level flushing such as via `fdatasync(2)`. */ int hflush(hFILE *fp) HTS_RESULT_USED; +/// For hfile_mem: get the internal buffer and it's size from a hfile +/** @return buffer if successful, or NULL if an error occurred + +The buffer returned should not be freed as this will happen when the +hFILE is closed. +*/ +char *hfile_mem_get_buffer(hFILE *file, size_t *length); + +/// For hfile_mem: get the internal buffer and it's size from a hfile. +/** @return buffer if successful, or NULL if an error occurred + +This is similar to hfile_mem_get_buffer except that ownership of the +buffer is granted to the caller, who now has responsibility for freeing +it. From this point onwards, the hFILE should not be used for any +purpose other than closing. +*/ +char *hfile_mem_steal_buffer(hFILE *file, size_t *length); + #ifdef __cplusplus } #endif diff --git a/htslib/htslib/hts.h b/htslib/htslib/hts.h index 3da997649..728814bc9 100644 --- a/htslib/htslib/hts.h +++ b/htslib/htslib/hts.h @@ -32,6 +32,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include "hts_defs.h" +#include "hts_log.h" #ifdef __cplusplus extern "C" { @@ -58,21 +59,64 @@ typedef struct __kstring_t { #endif /** - * hts_expand() - expands memory block pointed to by $ptr; - * hts_expand0() the latter sets the newly allocated part to 0. + * @hideinitializer + * Macro to expand a dynamic array of a given type * - * @param n requested number of elements of type type_t - * @param m size of memory allocated + * @param type_t The type of the array elements + * @param[in] n Requested number of elements of type type_t + * @param[in,out] m Size of memory allocated + * @param[in,out] ptr Pointer to the array + * + * @discussion + * The array *ptr will be expanded if necessary so that it can hold @p n + * or more elements. If the array is expanded then the new size will be + * written to @p m and the value in @ptr may change. + * + * It must be possible to take the address of @p ptr and @p m must be usable + * as an lvalue. + * + * @bug + * If the memory allocation fails, this will call exit(1). This is + * not ideal behaviour in a library. + */ +#define hts_expand(type_t, n, m, ptr) do { \ + if ((n) > (m)) { \ + size_t hts_realloc_or_die(size_t, size_t, size_t, size_t, \ + int, void **, const char *); \ + (m) = hts_realloc_or_die((n) >= 1 ? (n) : 1, (m), sizeof(m), \ + sizeof(type_t), 0, \ + (void **)&(ptr), __func__); \ + } \ + } while (0) + +/** + * @hideinitializer + * Macro to expand a dynamic array, zeroing any newly-allocated memory + * + * @param type_t The type of the array elements + * @param[in] n Requested number of elements of type type_t + * @param[in,out] m Size of memory allocated + * @param[in,out] ptr Pointer to the array + * + * @discussion + * As for hts_expand(), except the bytes that make up the array elements + * between the old and new values of @p m are set to zero using memset(). + * + * @bug + * If the memory allocation fails, this will call exit(1). This is + * not ideal behaviour in a library. */ -#define hts_expand(type_t, n, m, ptr) if ((n) > (m)) { \ - (m) = (n); kroundup32(m); \ - (ptr) = (type_t*)realloc((ptr), (m) * sizeof(type_t)); \ - } -#define hts_expand0(type_t, n, m, ptr) if ((n) > (m)) { \ - int t = (m); (m) = (n); kroundup32(m); \ - (ptr) = (type_t*)realloc((ptr), (m) * sizeof(type_t)); \ - memset(((type_t*)ptr)+t,0,sizeof(type_t)*((m)-t)); \ - } + + +#define hts_expand0(type_t, n, m, ptr) do { \ + if ((n) > (m)) { \ + size_t hts_realloc_or_die(size_t, size_t, size_t, size_t, \ + int, void **, const char *); \ + (m) = hts_realloc_or_die((n) >= 1 ? (n) : 1, (m), sizeof(m), \ + sizeof(type_t), 1, \ + (void **)&(ptr), __func__); \ + } \ + } while (0) /************ * File I/O * @@ -94,6 +138,8 @@ enum htsExactFormat { unknown_format, binary_format, text_format, sam, bam, bai, cram, crai, vcf, bcf, csi, gzi, tbi, bed, + htsget, + json HTS_DEPRECATED_ENUM("Use htsExactFormat 'htsget' instead") = htsget, format_maximum = 32767 }; @@ -119,7 +165,7 @@ typedef struct htsFormat { // - fp is used directly in samtools (up to and including current develop) // - line is used directly in bcftools (up to and including current develop) typedef struct { - uint32_t is_bin:1, is_write:1, is_be:1, is_cram:1, dummy:28; + uint32_t is_bin:1, is_write:1, is_be:1, is_cram:1, is_bgzf:1, dummy:27; int64_t lineno; kstring_t line; char *fn, *fn_aux; @@ -127,7 +173,6 @@ typedef struct { BGZF *bgzf; struct cram_fd *cram; struct hFILE *hfile; - void *voidp; } fp; htsFormat format; } htsFile; @@ -166,7 +211,7 @@ enum hts_fmt_option { // CRAM specific CRAM_OPT_DECODE_MD, CRAM_OPT_PREFIX, - CRAM_OPT_VERBOSITY, // make general + CRAM_OPT_VERBOSITY, // obsolete, use hts_set_log_level() instead CRAM_OPT_SEQS_PER_SLICE, CRAM_OPT_SLICES_PER_CONTAINER, CRAM_OPT_RANGE, @@ -184,12 +229,14 @@ enum hts_fmt_option { CRAM_OPT_USE_RANS, CRAM_OPT_REQUIRED_FIELDS, CRAM_OPT_LOSSY_NAMES, + CRAM_OPT_BASES_PER_SLICE, // General purpose HTS_OPT_COMPRESSION_LEVEL = 100, HTS_OPT_NTHREADS, HTS_OPT_THREAD_POOL, HTS_OPT_CACHE_SIZE, + HTS_OPT_BLOCK_SIZE, }; // For backwards compatibility @@ -255,8 +302,6 @@ int hts_parse_format(htsFormat *opt, const char *str); */ int hts_parse_opt_list(htsFormat *opt, const char *str); -extern int hts_verbose; - /*! @abstract Table for converting a nucleotide character to 4-bit encoding. The input character may be either an IUPAC ambiguity code, '=' for 0, or '0'/'1'/'2'/'3' for a result of 1/2/4/8. The result is encoded as 1/2/4/8 @@ -465,11 +510,30 @@ When REST or NONE is used, idx is also ignored and may be NULL. struct __hts_idx_t; typedef struct __hts_idx_t hts_idx_t; +typedef struct { + uint32_t beg, end; +} hts_pair32_t; + typedef struct { uint64_t u, v; } hts_pair64_t; +typedef struct { + uint64_t u, v; + uint64_t max; +} hts_pair64_max_t; + +typedef struct { + const char *reg; + int tid; + hts_pair32_t *intervals; + uint32_t count; + uint32_t min_beg, max_end; +} hts_reglist_t; + typedef int hts_readrec_func(BGZF *fp, void *data, void *r, int *tid, int *beg, int *end); +typedef int hts_seek_func(void *fp, int64_t offset, int where); +typedef int64_t hts_tell_func(void *fp); typedef struct { uint32_t read_rest:1, finished:1, is_cram:1, dummy:29; @@ -484,6 +548,24 @@ typedef struct { } bins; } hts_itr_t; +typedef struct { + int key; + uint64_t min_off, max_off; +} aux_key_t; + +typedef struct { + uint32_t read_rest:1, finished:1, is_cram:1, nocoor:1, dummy:28; + hts_reglist_t *reg_list; + int n_reg, i; + int curr_tid, curr_intv, curr_beg, curr_end, curr_reg; + hts_pair64_max_t *off; + int n_off; + uint64_t curr_off, nocoor_off; + hts_readrec_func *readrec; + hts_seek_func *seek; + hts_tell_func *tell; +} hts_itr_multi_t; + #define hts_bin_first(l) (((1<<(((l)<<1) + (l))) - 1) / 7) #define hts_bin_parent(l) (((l) - 1) >> 3) @@ -524,8 +606,33 @@ hts_idx_t *hts_idx_load(const char *fn, int fmt); */ hts_idx_t *hts_idx_load2(const char *fn, const char *fnidx); - uint8_t *hts_idx_get_meta(hts_idx_t *idx, int *l_meta); - void hts_idx_set_meta(hts_idx_t *idx, int l_meta, uint8_t *meta, int is_copy); + +/// Get extra index meta-data +/** @param idx The index + @param l_meta Pointer to where the length of the extra data is stored + @return Pointer to the extra data if present; NULL otherwise + + Indexes (both .tbi and .csi) made by tabix include extra data about + the indexed file. The returns a pointer to this data. Note that the + data is stored exactly as it is in the index. Callers need to interpret + the results themselves, including knowing what sort of data to expect; + byte swapping etc. +*/ +uint8_t *hts_idx_get_meta(hts_idx_t *idx, uint32_t *l_meta); + +/// Set extra index meta-data +/** @param idx The index + @param l_meta Length of data + @param meta Pointer to the extra data + @param is_copy If not zero, a copy of the data is taken + @return 0 on success; -1 on failure (out of memory). + + Sets the data that is returned by hts_idx_get_meta(). + + If is_copy != 0, a copy of the input data is taken. If not, ownership of + the data pointed to by *meta passes to the index. +*/ +int hts_idx_set_meta(hts_idx_t *idx, uint32_t l_meta, uint8_t *meta, int is_copy); int hts_idx_get_stat(const hts_idx_t* idx, int tid, uint64_t* mapped, uint64_t* unmapped); uint64_t hts_idx_get_n_no_coor(const hts_idx_t* idx); @@ -542,7 +649,7 @@ hts_idx_t *hts_idx_load2(const char *fn, const char *fnidx); @param flags Or'ed-together combination of HTS_PARSE_* flags @return Converted value of the parsed number. - When @a strend is NULL, a warning will be printed (if hts_verbose is 2 + When @a strend is NULL, a warning will be printed (if hts_verbose is HTS_LOG_WARNING or more) if there are any trailing characters after the number. */ long long hts_parse_decimal(const char *str, char **strend, int flags); @@ -567,6 +674,19 @@ const char *hts_parse_reg(const char *str, int *beg, int *end); int hts_itr_next(BGZF *fp, hts_itr_t *iter, void *r, void *data) HTS_RESULT_USED; const char **hts_idx_seqnames(const hts_idx_t *idx, int *n, hts_id2name_f getid, void *hdr); // free only the array, not the values +/********************************** + * Iterator with multiple regions * + **********************************/ + +typedef hts_itr_multi_t *hts_itr_multi_query_func(const hts_idx_t *idx, hts_itr_multi_t *itr); +hts_itr_multi_t *hts_itr_multi_bam(const hts_idx_t *idx, hts_itr_multi_t *iter); +hts_itr_multi_t *hts_itr_multi_cram(const hts_idx_t *idx, hts_itr_multi_t *iter); +hts_itr_multi_t *hts_itr_regions(const hts_idx_t *idx, hts_reglist_t *reglist, int count, hts_name2id_f getid, void *hdr, hts_itr_multi_query_func *itr_specific, hts_readrec_func *readrec, hts_seek_func *seek, hts_tell_func *tell); +int hts_itr_multi_next(htsFile *fd, hts_itr_multi_t *iter, void *r); +void hts_reglist_free(hts_reglist_t *reglist, int count); +void hts_itr_multi_destroy(hts_itr_multi_t *iter); + + /** * hts_file_type() - Convenience function to determine file type * DEPRECATED: This function has been replaced by hts_detect_format(). @@ -587,10 +707,10 @@ const char *hts_parse_reg(const char *str, int *beg, int *end); ***************************/ struct errmod_t; -// typedef struct errmod_t errmod_t; +typedef struct errmod_t errmod_t; -// errmod_t *errmod_init(double depcorr); -// void errmod_destroy(errmod_t *em); +errmod_t *errmod_init(double depcorr); +void errmod_destroy(errmod_t *em); /* n: number of bases @@ -598,7 +718,7 @@ struct errmod_t; bases[i]: qual:6, strand:1, base:4 q[i*m+j]: phred-scaled likelihood of (i,j) */ -// int errmod_cal(const errmod_t *em, int n, int m, uint16_t *bases, float *q); +int errmod_cal(const errmod_t *em, int n, int m, uint16_t *bases, float *q); /***************************************** diff --git a/htslib/htslib/hts_defs.h b/htslib/htslib/hts_defs.h index 0a672c6d3..3bf4a4630 100644 --- a/htslib/htslib/hts_defs.h +++ b/htslib/htslib/hts_defs.h @@ -1,6 +1,6 @@ /* hts_defs.h -- Miscellaneous definitions. - Copyright (C) 2013-2015 Genome Research Ltd. + Copyright (C) 2013-2015,2017 Genome Research Ltd. Author: John Marshall @@ -69,4 +69,28 @@ DEALINGS IN THE SOFTWARE. */ #define HTS_DEPRECATED(message) #endif +#if HTS_COMPILER_HAS(__deprecated__) || HTS_GCC_AT_LEAST(6,4) +#define HTS_DEPRECATED_ENUM(message) __attribute__ ((__deprecated__ (message))) +#else +#define HTS_DEPRECATED_ENUM(message) +#endif + +// On mingw the "printf" format type doesn't work. It needs "gnu_printf" +// in order to check %lld and %z, otherwise it defaults to checking against +// the Microsoft library printf format options despite linking against the +// GNU posix implementation of printf. The __MINGW_PRINTF_FORMAT macro +// expands to printf or gnu_printf as required, but obviously may not +// exist +#ifdef __MINGW_PRINTF_FORMAT +#define HTS_PRINTF_FMT __MINGW_PRINTF_FORMAT +#else +#define HTS_PRINTF_FMT printf +#endif + +#if HTS_COMPILER_HAS(__format__) || HTS_GCC_AT_LEAST(3,0) +#define HTS_FORMAT(type, idx, first) __attribute__((__format__ (type, idx, first))) +#else +#define HTS_FORMAT(type, idx, first) +#endif + #endif diff --git a/htslib/htslib/hts_endian.h b/htslib/htslib/hts_endian.h new file mode 100644 index 000000000..9a843d535 --- /dev/null +++ b/htslib/htslib/hts_endian.h @@ -0,0 +1,354 @@ +/// @file hts_endian.h +/// Byte swapping and unaligned access functions. +/* + Copyright (C) 2017 Genome Research Ltd. + + Author: Rob Davies + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#ifndef HTS_ENDIAN_H +#define HTS_ENDIAN_H + +#include + +/* + * Compile-time endianness tests. + * + * Note that these tests may fail. They should only be used to enable + * faster versions of endian-neutral implementations. The endian-neutral + * version should always be available as a fall-back. + * + * See https://sourceforge.net/p/predef/wiki/Endianness/ + */ + +/* Save typing as both endian and unaligned tests want to know about x86 */ +#if (defined(__i386__) || defined(__i386) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(__i686__) || defined(__i686)) && !defined(HTS_x86) +# define HTS_x86 /* x86 and x86_64 platform */ +#endif + +/** @def HTS_LITTLE_ENDIAN + * @brief Defined if platform is known to be little-endian + */ + +#ifndef HTS_LITTLE_ENDIAN +# if (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) \ + || defined(__LITTLE_ENDIAN__) \ + || defined(HTS_x86) \ + || defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) \ + || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) +# define HTS_LITTLE_ENDIAN +# endif +#endif + +/** @def HTS_BIG_ENDIAN + * @brief Defined if platform is known to be big-endian + */ + +#ifndef HTS_BIG_ENDIAN +# if (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) \ + || defined(__BIG_ENDIAN__) \ + || defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AAARCHEB__) \ + || defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) +# define HTS_BIG_ENDIAN +# endif +#endif + +/** @def HTS_ENDIAN_NEUTRAL + * @brief Define this to disable any endian-specific optimizations + */ + +#if defined(HTS_ENDIAN_NEUTRAL) || (defined(HTS_LITTLE_ENDIAN) && defined(HTS_BIG_ENDIAN)) +/* Disable all endian-specific code. */ +# undef HTS_LITTLE_ENDIAN +# undef HTS_BIG_ENDIAN +#endif + +/** @def HTS_ALLOW_UNALIGNED + * @brief Control use of unaligned memory access. + * + * Defining HTS_ALLOW_UNALIGNED=1 converts shift-and-or to simple casts on + * little-endian platforms that can tolerate unaligned access (notably Intel + * x86). + * + * Defining HTS_ALLOW_UNALIGNED=0 forces shift-and-or. + */ + +// Consider using AX_CHECK_ALIGNED_ACCESS_REQUIRED in autoconf. +#ifndef HTS_ALLOW_UNALIGNED +# if defined(HTS_x86) +# define HTS_ALLOW_UNALIGNED 1 +# else +# define HTS_ALLOW_UNALIGNED 0 +# endif +#endif + +#if HTS_ALLOW_UNALIGNED != 0 +# if defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) +// This prevents problems with gcc's vectoriser generating the wrong +// instructions for unaligned data. +typedef uint16_t uint16_u __attribute__ ((__aligned__ (1))); +typedef uint32_t uint32_u __attribute__ ((__aligned__ (1))); +typedef uint64_t uint64_u __attribute__ ((__aligned__ (1))); +#else +typedef uint16_t uint16_u; +typedef uint32_t uint32_u; +typedef uint64_t uint64_u; +# endif +#endif + +/// Get a uint16_t value from an unsigned byte array +/** @param buf Pointer to source byte, may be unaligned + * @return A 16 bit unsigned integer + * The input is read in little-endian byte order. + */ +static inline uint16_t le_to_u16(const uint8_t *buf) { +#if defined(HTS_LITTLE_ENDIAN) && HTS_ALLOW_UNALIGNED != 0 + return *((uint16_u *) buf); +#else + return (uint16_t) buf[0] | ((uint16_t) buf[1] << 8); +#endif +} + +/// Get a uint32_t value from an unsigned byte array +/** @param buf Pointer to source byte array, may be unaligned + * @return A 32 bit unsigned integer + * The input is read in little-endian byte order. + */ +static inline uint32_t le_to_u32(const uint8_t *buf) { +#if defined(HTS_LITTLE_ENDIAN) && HTS_ALLOW_UNALIGNED != 0 + return *((uint32_u *) buf); +#else + return ((uint32_t) buf[0] | + ((uint32_t) buf[1] << 8) | + ((uint32_t) buf[2] << 16) | + ((uint32_t) buf[3] << 24)); +#endif +} + +/// Get a uint64_t value from an unsigned byte array +/** @param buf Pointer to source byte array, may be unaligned + * @return A 64 bit unsigned integer + * The input is read in little-endian byte order. + */ +static inline uint64_t le_to_u64(const uint8_t *buf) { +#if defined(HTS_LITTLE_ENDIAN) && HTS_ALLOW_UNALIGNED != 0 + return *((uint64_u *) buf); +#else + return ((uint64_t) buf[0] | + ((uint64_t) buf[1] << 8) | + ((uint64_t) buf[2] << 16) | + ((uint64_t) buf[3] << 24) | + ((uint64_t) buf[4] << 32) | + ((uint64_t) buf[5] << 40) | + ((uint64_t) buf[6] << 48) | + ((uint64_t) buf[7] << 56)); +#endif +} + +/// Store a uint16_t value in little-endian byte order +/** @param val The value to store + * @param buf Where to store it (may be unaligned) + */ +static inline void u16_to_le(uint16_t val, uint8_t *buf) { +#if defined(HTS_LITTLE_ENDIAN) && HTS_ALLOW_UNALIGNED != 0 + *((uint16_u *) buf) = val; +#else + buf[0] = val & 0xff; + buf[1] = (val >> 8) & 0xff; +#endif +} + +/// Store a uint32_t value in little-endian byte order +/** @param val The value to store + * @param buf Where to store it (may be unaligned) + */ +static inline void u32_to_le(uint32_t val, uint8_t *buf) { +#if defined(HTS_LITTLE_ENDIAN) && HTS_ALLOW_UNALIGNED != 0 + *((uint32_u *) buf) = val; +#else + buf[0] = val & 0xff; + buf[1] = (val >> 8) & 0xff; + buf[2] = (val >> 16) & 0xff; + buf[3] = (val >> 24) & 0xff; +#endif +} + +/// Store a uint64_t value in little-endian byte order +/** @param val The value to store + * @param buf Where to store it (may be unaligned) + */ +static inline void u64_to_le(uint64_t val, uint8_t *buf) { +#if defined(HTS_LITTLE_ENDIAN) && HTS_ALLOW_UNALIGNED != 0 + *((uint64_u *) buf) = val; +#else + buf[0] = val & 0xff; + buf[1] = (val >> 8) & 0xff; + buf[2] = (val >> 16) & 0xff; + buf[3] = (val >> 24) & 0xff; + buf[4] = (val >> 32) & 0xff; + buf[5] = (val >> 40) & 0xff; + buf[6] = (val >> 48) & 0xff; + buf[7] = (val >> 56) & 0xff; +#endif +} + +/* Signed values. Grab the data as unsigned, then convert to signed without + * triggering undefined behaviour. On any sensible platform, the conversion + * should optimise away to nothing. + */ + +/// Get an int8_t value from an unsigned byte array +/** @param buf Pointer to source byte array, may be unaligned + * @return A 8 bit signed integer + * The input data is interpreted as 2's complement representation. + */ +static inline int8_t le_to_i8(const uint8_t *buf) { + return *buf < 0x80 ? *buf : -((int8_t) (0xff - *buf)) - 1; +} + +/// Get an int16_t value from an unsigned byte array +/** @param buf Pointer to source byte array, may be unaligned + * @return A 16 bit signed integer + * The input data is interpreted as 2's complement representation in + * little-endian byte order. + */ +static inline int16_t le_to_i16(const uint8_t *buf) { + uint16_t v = le_to_u16(buf); + return v < 0x8000 ? v : -((int16_t) (0xffff - v)) - 1; +} + +/// Get an int32_t value from an unsigned byte array +/** @param buf Pointer to source byte array, may be unaligned + * @return A 32 bit signed integer + * The input data is interpreted as 2's complement representation in + * little-endian byte order. + */ +static inline int32_t le_to_i32(const uint8_t *buf) { + uint32_t v = le_to_u32(buf); + return v < 0x80000000U ? v : -((int32_t) (0xffffffffU - v)) - 1; +} + +/// Get an int64_t value from an unsigned byte array +/** @param buf Pointer to source byte array, may be unaligned + * @return A 64 bit signed integer + * The input data is interpreted as 2's complement representation in + * little-endian byte order. + */ +static inline int64_t le_to_i64(const uint8_t *buf) { + uint64_t v = le_to_u64(buf); + return (v < 0x8000000000000000ULL + ? v : -((int64_t) (0xffffffffffffffffULL - v)) - 1); +} + +// Converting the other way is easier as signed -> unsigned is well defined. + +/// Store a uint16_t value in little-endian byte order +/** @param val The value to store + * @param buf Where to store it (may be unaligned) + */ +static inline void i16_to_le(int16_t val, uint8_t *buf) { + u16_to_le(val, buf); +} + +/// Store a uint32_t value in little-endian byte order +/** @param val The value to store + * @param buf Where to store it (may be unaligned) + */ +static inline void i32_to_le(int32_t val, uint8_t *buf) { + u32_to_le(val, buf); +} + +/// Store a uint64_t value in little-endian byte order +/** @param val The value to store + * @param buf Where to store it (may be unaligned) + */ +static inline void i64_to_le(int64_t val, uint8_t *buf) { + u64_to_le(val, buf); +} + +/* Floating point. Assumptions: + * Platform uses IEEE 754 format + * sizeof(float) == sizeof(uint32_t) + * sizeof(double) == sizeof(uint64_t) + * Endian-ness is the same for both floating point and integer + * Type-punning via a union is allowed + */ + +/// Get a float value from an unsigned byte array +/** @param buf Pointer to source byte array, may be unaligned + * @return A 32 bit floating point value + * The input is interpreted as an IEEE 754 format float in little-endian + * byte order. + */ +static inline float le_to_float(const uint8_t *buf) { + union { + uint32_t u; + float f; + } convert; + + convert.u = le_to_u32(buf); + return convert.f; +} + +/// Get a double value from an unsigned byte array +/** @param buf Pointer to source byte array, may be unaligned + * @return A 64 bit floating point value + * The input is interpreted as an IEEE 754 format double in little-endian + * byte order. + */ +static inline double le_to_double(const uint8_t *buf) { + union { + uint64_t u; + double f; + } convert; + + convert.u = le_to_u64(buf); + return convert.f; +} + +/// Store a float value in little-endian byte order +/** @param val The value to store + * @param buf Where to store it (may be unaligned) + */ +static inline void float_to_le(float val, uint8_t *buf) { + union { + uint32_t u; + float f; + } convert; + + convert.f = val; + u32_to_le(convert.u, buf); +} + +/// Store a double value in little-endian byte order +/** @param val The value to store + * @param buf Where to store it (may be unaligned) + */ +static inline void double_to_le(double val, uint8_t *buf) { + union { + uint64_t u; + double f; + } convert; + + convert.f = val; + u64_to_le(convert.u, buf); +} + +#endif /* HTS_ENDIAN_H */ diff --git a/htslib/htslib/hts_log.h b/htslib/htslib/hts_log.h new file mode 100644 index 000000000..4273738a1 --- /dev/null +++ b/htslib/htslib/hts_log.h @@ -0,0 +1,93 @@ +/// \file htslib/hts_log.h +/// Configuration of log levels. +/* The MIT License +Copyright (C) 2017 Genome Research Ltd. + +Author: Anders Kaplan + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef HTS_LOG_H +#define HTS_LOG_H + +#include "hts_defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/// Log levels. +enum htsLogLevel { + HTS_LOG_OFF, ///< All logging disabled. + HTS_LOG_ERROR, ///< Logging of errors only. + HTS_LOG_WARNING = 3, ///< Logging of errors and warnings. + HTS_LOG_INFO, ///< Logging of errors, warnings, and normal but significant events. + HTS_LOG_DEBUG, ///< Logging of all except the most detailed debug events. + HTS_LOG_TRACE ///< All logging enabled. +}; + +/// Sets the selected log level. +void hts_set_log_level(enum htsLogLevel level); + +/// Gets the selected log level. +enum htsLogLevel hts_get_log_level(); + +/// Selected log level. +/*! + * One of the HTS_LOG_* values. The default is HTS_LOG_WARNING. + * \note Avoid direct use of this variable. Use hts_set_log_level and hts_get_log_level instead. + */ +extern int hts_verbose; + +/*! Logs an event. +* \param severity Severity of the event: +* - HTS_LOG_ERROR means that something went wrong so that a task could not be completed. +* - HTS_LOG_WARNING means that something unexpected happened, but that execution can continue, perhaps in a degraded mode. +* - HTS_LOG_INFO means that something normal but significant happened. +* - HTS_LOG_DEBUG means that something normal and insignificant happened. +* - HTS_LOG_TRACE means that something happened that might be of interest when troubleshooting. +* \param context Context where the event occurred. Typically set to "__func__". +* \param format Format string with placeholders, like printf. +*/ +void hts_log(enum htsLogLevel severity, const char *context, const char *format, ...) +HTS_FORMAT(printf, 3, 4); + +/*! Logs an event with severity HTS_LOG_ERROR and default context. Parameters: format, ... */ +#define hts_log_error(...) hts_log(HTS_LOG_ERROR, __func__, __VA_ARGS__) + +/*! Logs an event with severity HTS_LOG_WARNING and default context. Parameters: format, ... */ +#define hts_log_warning(...) hts_log(HTS_LOG_WARNING, __func__, __VA_ARGS__) + +/*! Logs an event with severity HTS_LOG_INFO and default context. Parameters: format, ... */ +#define hts_log_info(...) hts_log(HTS_LOG_INFO, __func__, __VA_ARGS__) + +/*! Logs an event with severity HTS_LOG_DEBUG and default context. Parameters: format, ... */ +#define hts_log_debug(...) hts_log(HTS_LOG_DEBUG, __func__, __VA_ARGS__) + +/*! Logs an event with severity HTS_LOG_TRACE and default context. Parameters: format, ... */ +#define hts_log_trace(...) hts_log(HTS_LOG_TRACE, __func__, __VA_ARGS__) + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef HTS_LOG_H diff --git a/htslib/htslib/hts_os.h b/htslib/htslib/hts_os.h new file mode 100644 index 000000000..3a671d4a2 --- /dev/null +++ b/htslib/htslib/hts_os.h @@ -0,0 +1,59 @@ +/// @file hts_os.h +/// Operating System specific tweaks, for compatibility with POSIX. +/* + Copyright (C) 2017 Genome Research Ltd. + + Author: James Bonfield + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#ifndef HTSLIB_HTS_OS_H +#define HTSLIB_HTS_OS_H + +extern void hts_srand48(long seed); +extern double hts_erand48(unsigned short xseed[3]); +extern double hts_drand48(void); +extern long hts_lrand48(void); + +#if defined(_WIN32) && !defined(__CYGWIN__) +// Windows usually lacks *rand48(), but cygwin provides them. +#define srand48(S) hts_srand48((S)) +#define erand48(X) hts_erand48((X)) +#define drand48() hts_drand48() +#define lrand48() hts_lrand48() +#endif + +#if 0 /* def _WIN32 - disabled for now, not currently used */ +/* Check if the fd is a cygwin/msys's pty. */ +extern int is_cygpty(int fd); +#endif + + +#if defined(__MINGW32__) +#include +#define mkdir(filename,mode) mkdir((filename)) +#endif + +#ifdef _WIN32 +#include +#define srandom srand +#define random rand +#endif + +#endif diff --git a/htslib/htslib/khash.h b/htslib/htslib/khash.h index 06fc7a331..b2179d4ac 100644 --- a/htslib/htslib/khash.h +++ b/htslib/htslib/khash.h @@ -594,7 +594,7 @@ static kh_inline khint_t __ac_Wang_hash(khint_t key) KHASH_INIT(name, khint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal) /*! @function - @abstract Instantiate a hash map containing 64-bit integer keys + @abstract Instantiate a hash set containing 64-bit integer keys @param name Name of the hash table [symbol] */ #define KHASH_SET_INIT_INT64(name) \ @@ -610,7 +610,7 @@ static kh_inline khint_t __ac_Wang_hash(khint_t key) typedef const char *kh_cstr_t; /*! @function - @abstract Instantiate a hash map containing const char* keys + @abstract Instantiate a hash set containing const char* keys @param name Name of the hash table [symbol] */ #define KHASH_SET_INIT_STR(name) \ diff --git a/htslib/htslib/knetfile.h b/htslib/htslib/knetfile.h index 1249a7c31..863359670 100644 --- a/htslib/htslib/knetfile.h +++ b/htslib/htslib/knetfile.h @@ -77,7 +77,7 @@ extern "C" { knetFile *knet_open(const char *fn, const char *mode); - /* + /* This only works with local files. */ knetFile *knet_dopen(int fd, const char *mode); diff --git a/htslib/htslib/ksort.h b/htslib/htslib/ksort.h index 331b11dc3..cf99884e6 100644 --- a/htslib/htslib/ksort.h +++ b/htslib/htslib/ksort.h @@ -65,6 +65,16 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + +// Use our own drand48() symbol (used by ks_shuffle) to avoid portability +// problems on Windows. Don't include htslib/hts_os.h for this as it +// may not get on with older attempts to fix this in code that includes +// this file. +extern double hts_drand48(void); + typedef struct { void *left, *right; int depth; @@ -261,7 +271,7 @@ typedef struct { int i, j; \ for (i = n; i > 1; --i) { \ type_t tmp; \ - j = (int)(drand48() * i); \ + j = (int)(hts_drand48() * i); \ tmp = a[j]; a[j] = a[i-1]; a[i-1] = tmp; \ } \ } @@ -283,4 +293,8 @@ typedef const char *ksstr_t; #define KSORT_INIT_GENERIC(type_t) KSORT_INIT(type_t, type_t, ks_lt_generic) #define KSORT_INIT_STR KSORT_INIT(str, ksstr_t, ks_lt_str) +#ifdef __cplusplus +} +#endif + #endif diff --git a/htslib/htslib/kstring.h b/htslib/htslib/kstring.h index 86cf10df3..3f053029e 100644 --- a/htslib/htslib/kstring.h +++ b/htslib/htslib/kstring.h @@ -82,6 +82,7 @@ extern "C" { int kvsprintf(kstring_t *s, const char *fmt, va_list ap) KS_ATTR_PRINTF(2,0); int ksprintf(kstring_t *s, const char *fmt, ...) KS_ATTR_PRINTF(2,3); + int kputd(double d, kstring_t *s); // custom %g only handler int ksplit_core(char *s, int delimiter, int *_max, int **_offsets); char *kstrstr(const char *str, const char *pat, int **_prep); char *kstrnstr(const char *str, const char *pat, int n, int **_prep); diff --git a/htslib/htslib/regidx.h b/htslib/htslib/regidx.h index e432f73d7..f2e0e00da 100644 --- a/htslib/htslib/regidx.h +++ b/htslib/htslib/regidx.h @@ -1,6 +1,6 @@ /// @file htslib/regidx.h /// Region indexing. -/* +/* Copyright (C) 2014 Genome Research Ltd. Author: Petr Danecek @@ -11,10 +11,10 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -42,7 +42,7 @@ while ( REGITR_OVERLAP(itr,from,to) ) { - printf("[%d,%d] overlaps with [%d,%d], payload=%s\n", from,to, + printf("[%d,%d] overlaps with [%d,%d], payload=%s\n", from,to, REGITR_START(itr), REGITR_END(itr), REGITR_PAYLOAD(itr,char*)); itr.i++; } @@ -128,7 +128,7 @@ void regidx_destroy(regidx_t *idx); int regidx_overlap(regidx_t *idx, const char *chr, uint32_t start, uint32_t end, regitr_t *itr); /* - * regidx_insert() - add a new region. + * regidx_insert() - add a new region. * * After last region has been added, call regidx_insert(idx,NULL) to * build the index. diff --git a/htslib/htslib/sam.h b/htslib/htslib/sam.h index 62f9daf09..769a12c14 100644 --- a/htslib/htslib/sam.h +++ b/htslib/htslib/sam.h @@ -1,7 +1,7 @@ /// @file htslib/sam.h /// High-level SAM/BAM/CRAM sequence file operations. /* - Copyright (C) 2008, 2009, 2013-2014 Genome Research Ltd. + Copyright (C) 2008, 2009, 2013-2017 Genome Research Ltd. Copyright (C) 2010, 2012, 2013 Broad Institute. Author: Heng Li @@ -34,6 +34,9 @@ DEALINGS IN THE SOFTWARE. */ extern "C" { #endif +/// Highest SAM format version supported by this library +#define SAM_FORMAT_VERSION "1.5" + /********************** *** SAM/BAM header *** **********************/ @@ -80,7 +83,11 @@ typedef struct { #define bam_cigar_op(c) ((c)&BAM_CIGAR_MASK) #define bam_cigar_oplen(c) ((c)>>BAM_CIGAR_SHIFT) -#define bam_cigar_opchr(c) (BAM_CIGAR_STR[bam_cigar_op(c)]) +// Note that BAM_CIGAR_STR is padded to length 16 bytes below so that +// the array look-up will not fall off the end. '?' is chosen as the +// padding character so it's easy to spot if one is emitted, and will +// result in a parsing failure (in sam_parse1(), at least) if read. +#define bam_cigar_opchr(c) (BAM_CIGAR_STR "??????" [bam_cigar_op(c)]) #define bam_cigar_gen(l, o) ((l)<fp.bgzf, (itr), (r), (htsfp)) + #define sam_itr_multi_next(htsfp, itr, r) hts_itr_multi_next((htsfp), (itr), (r)) /*************** *** SAM I/O *** @@ -363,9 +382,14 @@ int sam_index_build3(const char *fn, const char *fnidx, int min_shift, int nthre bam_hdr_t *sam_hdr_parse(int l_text, const char *text); bam_hdr_t *sam_hdr_read(samFile *fp); int sam_hdr_write(samFile *fp, const bam_hdr_t *h) HTS_RESULT_USED; + int sam_hdr_change_HD(bam_hdr_t *h, const char *key, const char *val); int sam_parse1(kstring_t *s, bam_hdr_t *h, bam1_t *b) HTS_RESULT_USED; int sam_format1(const bam_hdr_t *h, const bam1_t *b, kstring_t *str) HTS_RESULT_USED; + + /*! + * @return >= 0 on successfully reading a new record, -1 on end of stream, < -1 on error + **/ int sam_read1(samFile *fp, bam_hdr_t *h, bam1_t *b) HTS_RESULT_USED; int sam_write1(samFile *fp, const bam_hdr_t *h, const bam1_t *b) HTS_RESULT_USED; @@ -373,15 +397,105 @@ int sam_index_build3(const char *fn, const char *fnidx, int min_shift, int nthre *** Manipulating auxiliary fields *** *************************************/ - uint8_t *bam_aux_get(const bam1_t *b, const char tag[2]); - int32_t bam_aux2i(const uint8_t *s); - double bam_aux2f(const uint8_t *s); - char bam_aux2A(const uint8_t *s); - char *bam_aux2Z(const uint8_t *s); +/// Return a pointer to an aux record +/** @param b Pointer to the bam record + @param tag Desired aux tag + @return Pointer to the tag data, or NULL if tag is not present or on error + If the tag is not present, this function returns NULL and sets errno to + ENOENT. If the bam record's aux data is corrupt (either a tag has an + invalid type, or the last record is incomplete) then errno is set to + EINVAL and NULL is returned. + */ +uint8_t *bam_aux_get(const bam1_t *b, const char tag[2]); + +/// Get an integer aux value +/** @param s Pointer to the tag data, as returned by bam_aux_get() + @return The value, or 0 if the tag was not an integer type + If the tag is not an integer type, errno is set to EINVAL. This function + will not return the value of floating-point tags. +*/ +int64_t bam_aux2i(const uint8_t *s); - void bam_aux_append(bam1_t *b, const char tag[2], char type, int len, const uint8_t *data); - int bam_aux_del(bam1_t *b, uint8_t *s); - int bam_aux_update_str(bam1_t *b, const char tag[2], int len, const char *data); +/// Get an integer aux value +/** @param s Pointer to the tag data, as returned by bam_aux_get() + @return The value, or 0 if the tag was not an integer type + If the tag is not an numeric type, errno is set to EINVAL. The value of + integer flags will be returned cast to a double. +*/ +double bam_aux2f(const uint8_t *s); + +/// Get a character aux value +/** @param s Pointer to the tag data, as returned by bam_aux_get(). + @return The value, or 0 if the tag was not a character ('A') type + If the tag is not a character type, errno is set to EINVAL. +*/ +char bam_aux2A(const uint8_t *s); + +/// Get a string aux value +/** @param s Pointer to the tag data, as returned by bam_aux_get(). + @return Pointer to the string, or NULL if the tag was not a string type + If the tag is not a string type ('Z' or 'H'), errno is set to EINVAL. +*/ +char *bam_aux2Z(const uint8_t *s); + +/// Get the length of an array-type ('B') tag +/** @param s Pointer to the tag data, as returned by bam_aux_get(). + @return The length of the array, or 0 if the tag is not an array type. + If the tag is not an array type, errno is set to EINVAL. + */ +uint32_t bam_auxB_len(const uint8_t *s); + +/// Get an integer value from an array-type tag +/** @param s Pointer to the tag data, as returned by bam_aux_get(). + @param idx 0-based Index into the array + @return The idx'th value, or 0 on error. + If the array is not an integer type, errno is set to EINVAL. If idx + is greater than or equal to the value returned by bam_auxB_len(s), + errno is set to ERANGE. In both cases, 0 will be returned. + */ +int64_t bam_auxB2i(const uint8_t *s, uint32_t idx); + +/// Get a floating-point value from an array-type tag +/** @param s Pointer to the tag data, as returned by bam_aux_get(). + @param idx 0-based Index into the array + @return The idx'th value, or 0.0 on error. + If the array is not a numeric type, errno is set to EINVAL. This can + only actually happen if the input record has an invalid type field. If + idx is greater than or equal to the value returned by bam_auxB_len(s), + errno is set to ERANGE. In both cases, 0.0 will be returned. + */ +double bam_auxB2f(const uint8_t *s, uint32_t idx); + +/// Append tag data to a bam record +/* @param b The bam record to append to. + @param tag Tag identifier + @param type Tag data type + @param len Length of the data in bytes + @param data The data to append + @return 0 on success; -1 on failure. +If there is not enough space to store the additional tag, errno is set to +ENOMEM. If the type is invalid, errno may be set to EINVAL. errno is +also set to EINVAL if the bam record's aux data is corrupt. +*/ +int bam_aux_append(bam1_t *b, const char tag[2], char type, int len, const uint8_t *data); + +/// Delete tag data from a bam record +/* @param b The bam record to update + @param s Pointer to the tag to delete, as returned by bam_aux_get(). + @return 0 on success; -1 on failure + If the bam record's aux data is corrupt, errno is set to EINVAL and this + function returns -1; +*/ +int bam_aux_del(bam1_t *b, uint8_t *s); + +/// Update a string-type tag +/* @param b The bam record to update + @param tag Tag identifier + @param len The length of the new string + @param data The new string + @return 0 on success, -1 on failure +*/ +int bam_aux_update_str(bam1_t *b, const char tag[2], int len, const char *data); /************************** *** Pileup and Mpileup *** diff --git a/htslib/htslib/synced_bcf_reader.h b/htslib/htslib/synced_bcf_reader.h index 35d6da4ec..cfcb8c824 100644 --- a/htslib/htslib/synced_bcf_reader.h +++ b/htslib/htslib/synced_bcf_reader.h @@ -37,6 +37,8 @@ DEALINGS IN THE SOFTWARE. */ Example of usage: bcf_srs_t *sr = bcf_sr_init(); + bcf_sr_set_opt(sr, BCF_SR_PAIR_LOGIC, BCF_SR_PAIR_BOTH_REF); + bcf_sr_set_opt(sr, BCF_SR_REQUIRE_IDX); for (i=0; ierrnum ) error("Error: %s\n", bcf_sr_strerror(sr->errnum)); bcf_sr_destroy(sr); */ @@ -61,7 +64,17 @@ DEALINGS IN THE SOFTWARE. */ extern "C" { #endif -// How should be treated sites with the same position but different alleles +/* + When reading multiple files in paralel, duplicate records within each + file will be reordered and offered in intuitive order. For example, + when reading two files, each with unsorted SNP and indel record, the + reader should return the SNP records together and the indel records + together. The logic of compatible records can vary depending on the + application and can be set using the PAIR_* defined below. + + The COLLAPSE_* definitions will be deprecated in future versions, please + use the PAIR_* definitions instead. +*/ #define COLLAPSE_NONE 0 // require the exact same set of alleles in all files #define COLLAPSE_SNPS 1 // allow different alleles, as long as they all are SNPs #define COLLAPSE_INDELS 2 // the same as above, but with indels @@ -69,6 +82,23 @@ extern "C" { #define COLLAPSE_SOME 8 // at least some of the ALTs must match #define COLLAPSE_BOTH (COLLAPSE_SNPS|COLLAPSE_INDELS) +#define BCF_SR_PAIR_SNPS (1<<0) // allow different alleles, as long as they all are SNPs +#define BCF_SR_PAIR_INDELS (1<<1) // the same as above, but with indels +#define BCF_SR_PAIR_ANY (1<<2) // any combination of alleles can be returned by bcf_sr_next_line() +#define BCF_SR_PAIR_SOME (1<<3) // at least some of multiallelic ALTs must match. Implied by all the others with the exception of EXACT +#define BCF_SR_PAIR_SNP_REF (1<<4) // allow REF-only records with SNPs +#define BCF_SR_PAIR_INDEL_REF (1<<5) // allow REF-only records with indels +#define BCF_SR_PAIR_EXACT (1<<6) // require the exact same set of alleles in all files +#define BCF_SR_PAIR_BOTH (BCF_SR_PAIR_SNPS|BCF_SR_PAIR_INDELS) +#define BCF_SR_PAIR_BOTH_REF (BCF_SR_PAIR_SNPS|BCF_SR_PAIR_INDELS|BCF_SR_PAIR_SNP_REF|BCF_SR_PAIR_INDEL_REF) + +typedef enum +{ + BCF_SR_REQUIRE_IDX, + BCF_SR_PAIR_LOGIC // combination of the PAIR_* values above +} +bcf_sr_opt_t; + typedef struct _bcf_sr_regions_t { // for reading from tabix-indexed file (big data) @@ -118,14 +148,14 @@ bcf_sr_t; typedef enum { open_failed, not_bgzf, idx_load_failed, file_type_error, api_usage_error, - header_error, no_eof, no_memory + header_error, no_eof, no_memory, vcf_parse_error, bcf_read_error } bcf_sr_error; typedef struct { // Parameters controlling the logic - int collapse; // How should the duplicate sites be treated. One of the COLLAPSE_* types above. + int collapse; // Do not access directly, use bcf_sr_set_pairing_logic() instead char *apply_filters; // If set, sites where none of the FILTER strings is listed // will be skipped. Active only at the time of // initialization, that is during the add_reader() @@ -150,6 +180,7 @@ typedef struct int n_threads; // Simple multi-threaded decoding / encoding. htsThreadPool *p; // Our pool, but it can be used by others if needed. + void *aux; // Opaque auxiliary data } bcf_srs_t; @@ -161,6 +192,19 @@ void bcf_sr_destroy(bcf_srs_t *readers); char *bcf_sr_strerror(int errnum); +int bcf_sr_set_opt(bcf_srs_t *readers, bcf_sr_opt_t opt, ...); + + +/** + * bcf_sr_set_threads() - allocates a thread-pool for use by the synced reader. + * @n_threads: size of thread pool + * + * Returns 0 if the call succeeded, or <0 on error. + */ +int bcf_sr_set_threads(bcf_srs_t *files, int n_threads); + +/** Deallocates thread memory, if owned by us. */ +void bcf_sr_destroy_threads(bcf_srs_t *files); /** * bcf_sr_set_threads() - allocates a thread-pool for use by the synced reader. @@ -202,6 +246,7 @@ int bcf_sr_next_line(bcf_srs_t *readers); #define bcf_sr_get_header(_readers, i) (_readers)->readers[i].header #define bcf_sr_get_reader(_readers, i) &((_readers)->readers[i]) + /** * bcf_sr_seek() - set all readers to selected position * @seq: sequence name; NULL to seek to start diff --git a/htslib/htslib/tbx.h b/htslib/htslib/tbx.h index c8757a882..0a1953891 100644 --- a/htslib/htslib/tbx.h +++ b/htslib/htslib/tbx.h @@ -52,7 +52,7 @@ typedef struct { void *dict; } tbx_t; -extern tbx_conf_t tbx_conf_gff, tbx_conf_bed, tbx_conf_psltbl, tbx_conf_sam, tbx_conf_vcf; +extern const tbx_conf_t tbx_conf_gff, tbx_conf_bed, tbx_conf_psltbl, tbx_conf_sam, tbx_conf_vcf; #define tbx_itr_destroy(iter) hts_itr_destroy(iter) #define tbx_itr_queryi(tbx, tid, beg, end) hts_itr_query((tbx)->idx, (tid), (beg), (end), tbx_readrec) diff --git a/htslib/htslib/thread_pool.h b/htslib/htslib/thread_pool.h index b15b2b99d..70fd7391a 100644 --- a/htslib/htslib/thread_pool.h +++ b/htslib/htslib/thread_pool.h @@ -1,7 +1,7 @@ /// @file htslib/thread_pool.h /// Thread pool for multi-threading applications. /* - Copyright (c) 2013-2016 Genome Research Ltd. + Copyright (c) 2013-2017 Genome Research Ltd. Author: James Bonfield @@ -68,7 +68,7 @@ extern "C" { * growing too large and serial numbers to ensure sequential consumption of * the output. * - * The thread pool may have many hetergeneous tasks, each using its own + * The thread pool may have many heterogeneous tasks, each using its own * process mixed into the same thread pool. */ typedef struct hts_tpool_process hts_tpool_process; @@ -145,7 +145,7 @@ void hts_tpool_wake_dispatch(hts_tpool_process *q); int hts_tpool_process_flush(hts_tpool_process *q); /* - * Resets a process to the intial state. + * Resets a process to the initial state. * * This removes any queued up input jobs, disables any notification of * new results/output, flushes what is left and then discards any @@ -274,6 +274,15 @@ void hts_tpool_process_shutdown(hts_tpool_process *q); void hts_tpool_process_attach(hts_tpool *p, hts_tpool_process *q); void hts_tpool_process_detach(hts_tpool *p, hts_tpool_process *q); +/* + * Increment and decrement the reference count in a process-queue. + * If the queue is being driven from two external (non thread-pool) + * threads, eg "main" and a "reader", this permits each end to + * decrement its use of the process-queue independently. + */ +void hts_tpool_process_ref_incr(hts_tpool_process *q); +void hts_tpool_process_ref_decr(hts_tpool_process *q); + #ifdef __cplusplus } #endif diff --git a/htslib/htslib/vcf.h b/htslib/htslib/vcf.h index 92404d0bc..4ee873949 100644 --- a/htslib/htslib/vcf.h +++ b/htslib/htslib/vcf.h @@ -39,6 +39,7 @@ DEALINGS IN THE SOFTWARE. */ #include "hts.h" #include "kstring.h" #include "hts_defs.h" +#include "hts_endian.h" #ifdef __cplusplus extern "C" { @@ -136,6 +137,7 @@ extern uint8_t bcf_type_shift[]; #define VCF_MNP 2 #define VCF_INDEL 4 #define VCF_OTHER 8 +#define VCF_BND 16 // breakend typedef struct { int type, n; // variant type and the number of bases affected, negative for deletions @@ -650,10 +652,11 @@ typedef struct { * @dst: *dst is pointer to a memory location, can point to NULL * @ndst: pointer to the size of allocated memory * - * Returns negative value on error or the number of written values on - * success. bcf_get_info_string() returns on success the number of - * characters written excluding the null-terminating byte. bcf_get_info_flag() - * returns 1 when flag is set or 0 if not. + * Returns negative value on error or the number of written values + * (including missing values) on success. bcf_get_info_string() returns + * on success the number of characters written excluding the null- + * terminating byte. bcf_get_info_flag() returns 1 when flag is set or 0 + * if not. * * List of return codes: * -1 .. no such INFO tag defined in the header @@ -677,6 +680,10 @@ typedef struct { * * Returns negative value on error or the number of written values on success. * + * Use the returned number of written values for accessing valid entries of dst, as ndst is only a + * watermark that can be higher than the returned value, i.e. the end of dst can contain carry-over + * values from previous calls to bcf_get_format_*() on lines with more values per sample. + * * Example: * int ndst = 0; char **dst = NULL; * if ( bcf_get_format_string(hdr, line, "XX", &dst, &ndst) > 0 ) @@ -684,8 +691,35 @@ typedef struct { * free(dst[0]); free(dst); * * Example: - * int ngt, *gt_arr = NULL, ngt_arr = 0; + * int i, j, ngt, nsmpl = bcf_hdr_nsamples(hdr); + * int32_t *gt_arr = NULL, ngt_arr = 0; + * * ngt = bcf_get_genotypes(hdr, line, >_arr, &ngt_arr); + * if ( ngt<=0 ) return; // GT not present + * + * int max_ploidy = ngt/nsmpl; + * for (i=0; itype); abort(); break; + default: hts_log_error("Unexpected type %d", fmt->type); abort(); break; } #undef BRANCH } @@ -936,13 +973,13 @@ static inline int32_t bcf_dec_int1(const uint8_t *p, int type, uint8_t **q) { if (type == BCF_BT_INT8) { *q = (uint8_t*)p + 1; - return *(int8_t*)p; + return le_to_i8(p); } else if (type == BCF_BT_INT16) { *q = (uint8_t*)p + 2; - return *(int16_t*)p; + return le_to_i16(p); } else { *q = (uint8_t*)p + 4; - return *(int32_t*)p; + return le_to_i32(p); } } diff --git a/htslib/htslib/vcfutils.h b/htslib/htslib/vcfutils.h index 639a13c9c..4999df415 100644 --- a/htslib/htslib/vcfutils.h +++ b/htslib/htslib/vcfutils.h @@ -1,7 +1,7 @@ /// @file htslib/vcfutils.h /// Allele-related utility functions. /* - Copyright (C) 2012, 2013, 2015 Genome Research Ltd. + Copyright (C) 2012, 2013, 2015-2016 Genome Research Ltd. Author: Petr Danecek @@ -42,6 +42,7 @@ struct kbitset_t; * Returns the number of removed alleles on success or negative * on error: * -1 .. some allele index is out of bounds + * -2 .. could not remove alleles */ int bcf_trim_alleles(const bcf_hdr_t *header, bcf1_t *line); @@ -50,11 +51,11 @@ int bcf_trim_alleles(const bcf_hdr_t *header, bcf1_t *line); * @header: for access to BCF_DT_ID dictionary * @line: VCF line obtained from vcf_parse1 * @mask: alleles to remove - * + * * If you have more than 31 alleles, then the integer bit mask will * overflow, so use bcf_remove_allele_set instead */ -void bcf_remove_alleles(const bcf_hdr_t *header, bcf1_t *line, int mask); +void bcf_remove_alleles(const bcf_hdr_t *header, bcf1_t *line, int mask) HTS_DEPRECATED("Please use bcf_remove_allele_set instead"); /** * bcf_remove_allele_set() - remove ALT alleles according to bitset @rm_set @@ -62,10 +63,12 @@ void bcf_remove_alleles(const bcf_hdr_t *header, bcf1_t *line, int mask); * @line: VCF line obtained from vcf_parse1 * @rm_set: pointer to kbitset_t object with bits set for allele * indexes to remove - * + * + * Returns 0 on success or -1 on failure + * * Number=A,R,G INFO and FORMAT fields will be updated accordingly. */ -void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct kbitset_t *rm_set); +int bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct kbitset_t *rm_set); /** * bcf_calc_ac() - calculate the number of REF and ALT alleles diff --git a/htslib/htslib_vars.mk b/htslib/htslib_vars.mk index 957bff178..525c56f94 100644 --- a/htslib/htslib_vars.mk +++ b/htslib/htslib_vars.mk @@ -1,6 +1,6 @@ # Makefile variables useful for third-party code using htslib's public API. # -# Copyright (C) 2013-2016 Genome Research Ltd. +# Copyright (C) 2013-2017 Genome Research Ltd. # # Author: John Marshall # @@ -29,8 +29,10 @@ htslib_bgzf_h = $(HTSPREFIX)htslib/bgzf.h $(htslib_hts_defs_h) htslib_cram_h = $(HTSPREFIX)htslib/cram.h $(htslib_hts_h) htslib_faidx_h = $(HTSPREFIX)htslib/faidx.h $(htslib_hts_defs_h) htslib_hfile_h = $(HTSPREFIX)htslib/hfile.h $(htslib_hts_defs_h) -htslib_hts_h = $(HTSPREFIX)htslib/hts.h $(htslib_hts_defs_h) +htslib_hts_h = $(HTSPREFIX)htslib/hts.h $(htslib_hts_defs_h) $(htslib_hts_log_h) htslib_hts_defs_h = $(HTSPREFIX)htslib/hts_defs.h +htslib_hts_endian_h = $(HTSPREFIX)htslib/hts_endian.h +htslib_hts_log_h = $(HTSPREFIX)htslib/hts_log.h htslib_kbitset_h = $(HTSPREFIX)htslib/kbitset.h htslib_kfunc_h = $(HTSPREFIX)htslib/kfunc.h htslib_khash_h = $(HTSPREFIX)htslib/khash.h @@ -45,6 +47,6 @@ htslib_sam_h = $(HTSPREFIX)htslib/sam.h $(htslib_hts_h) htslib_synced_bcf_reader_h = $(HTSPREFIX)htslib/synced_bcf_reader.h $(htslib_hts_h) $(htslib_vcf_h) $(htslib_tbx_h) htslib_tbx_h = $(HTSPREFIX)htslib/tbx.h $(htslib_hts_h) htslib_thread_pool_h = $(HTSPREFIX)htslib/thread_pool.h -htslib_vcf_h = $(HTSPREFIX)htslib/vcf.h $(htslib_hts_h) $(htslib_kstring_h) $(htslib_hts_defs_h) +htslib_vcf_h = $(HTSPREFIX)htslib/vcf.h $(htslib_hts_h) $(htslib_kstring_h) $(htslib_hts_defs_h) $(htslib_hts_endian_h) htslib_vcf_sweep_h = $(HTSPREFIX)htslib/vcf_sweep.h $(htslib_hts_h) $(htslib_vcf_h) htslib_vcfutils_h = $(HTSPREFIX)htslib/vcfutils.h $(htslib_vcf_h) diff --git a/htslib/knetfile.c b/htslib/knetfile.c index 4c44f3eed..6bbc9e2e7 100644 --- a/htslib/knetfile.c +++ b/htslib/knetfile.c @@ -43,9 +43,11 @@ #include #include #include +#include #endif #include "htslib/knetfile.h" +#include "htslib/hts_log.h" /* In winsock.h, the type of a socket is SOCKET, which is: "typedef * u_int SOCKET". An invalid SOCKET is: "(SOCKET)(~0)", or signed @@ -74,9 +76,9 @@ static int socket_wait(int fd, int is_read) if (ret == -1) perror("select"); #else if (ret == 0) - fprintf(stderr, "select time-out\n"); + hts_log_warning("Select timed out"); else if (ret == SOCKET_ERROR) - fprintf(stderr, "select: %d\n", WSAGetLastError()); + hts_log_error("Select returned error %d", WSAGetLastError()); #endif return ret; } @@ -97,7 +99,7 @@ static int socket_connect(const char *host, const char *port) hints.ai_socktype = SOCK_STREAM; /* In Unix/Mac, getaddrinfo() is the most convenient way to get * server information. */ - if ((ai_err = getaddrinfo(host, port, &hints, &res)) != 0) { fprintf(stderr, "can't resolve %s:%s: %s\n", host, port, gai_strerror(ai_err)); return -1; } + if ((ai_err = getaddrinfo(host, port, &hints, &res)) != 0) { hts_log_error("Can't resolve %s:%s: %s", host, port, gai_strerror(ai_err)); return -1; } if ((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) __err_connect("socket"); /* The following two setsockopt() are used by ftplib * (http://nbpfaus.net/~pfau/ftplib/). I am not sure if they @@ -148,10 +150,10 @@ void knet_win32_destroy() * non-Windows OS, I do not use this one. */ static SOCKET socket_connect(const char *host, const char *port) { -#define __err_connect(func) \ - do { \ - fprintf(stderr, "%s: %d\n", func, WSAGetLastError()); \ - return -1; \ +#define __err_connect(func) \ + do { \ + hts_log_error("The %s operation returned error %d", func, WSAGetLastError()); \ + return -1; \ } while (0) int on = 1; @@ -259,7 +261,7 @@ static int kftp_pasv_connect(knetFile *ftp) { char host[80], port[10]; if (ftp->pasv_port == 0) { - fprintf(stderr, "[kftp_pasv_connect] kftp_pasv_prep() is not called before hand.\n"); + hts_log_error("Must call kftp_pasv_prep() first"); return -1; } sprintf(host, "%d.%d.%d.%d", ftp->pasv_ip[0], ftp->pasv_ip[1], ftp->pasv_ip[2], ftp->pasv_ip[3]); @@ -354,7 +356,7 @@ int kftp_connect_file(knetFile *fp) kftp_pasv_connect(fp); ret = kftp_get_response(fp); if (ret != 150) { - fprintf(stderr, "[kftp_connect_file] %s\n", fp->response); + hts_log_error("%s", fp->response); netclose(fp->fd); fp->fd = -1; return -1; @@ -393,7 +395,7 @@ knetFile *khttp_parse_url(const char *fn, const char *mode) } else { fp->host = (strstr(proxy, "http://") == proxy)? strdup(proxy + 7) : strdup(proxy); for (q = fp->host; *q && *q != ':'; ++q); - if (*q == ':') *q++ = 0; + if (*q == ':') *q++ = 0; fp->port = strdup(*q? q : "80"); fp->path = strdup(fn); } @@ -465,7 +467,8 @@ knetFile *knet_open(const char *fn, const char *mode) { knetFile *fp = 0; if (mode[0] != 'r') { - fprintf(stderr, "[kftp_open] only mode \"r\" is supported.\n"); + hts_log_error("Only mode \"r\" is supported"); + errno = ENOTSUP; return 0; } if (strstr(fn, "ftp://") == fn) { @@ -486,7 +489,7 @@ knetFile *knet_open(const char *fn, const char *mode) * be undefined on some systems, although it is defined on my * Mac and the Linux I have tested on. */ int fd = open(fn, O_RDONLY | O_BINARY); -#else +#else int fd = open(fn, O_RDONLY); #endif if (fd == -1) { @@ -560,7 +563,7 @@ off_t knet_seek(knetFile *fp, off_t off, int whence) return fp->offset; } else if (fp->type == KNF_TYPE_HTTP) { if (whence == SEEK_END) { // FIXME: can we allow SEEK_END in future? - fprintf(stderr, "[knet_seek] SEEK_END is not supported for HTTP. Offset is unchanged.\n"); + hts_log_error("SEEK_END is not supported for HTTP. Offset is unchanged"); errno = ESPIPE; return -1; } @@ -571,7 +574,7 @@ off_t knet_seek(knetFile *fp, off_t off, int whence) return fp->offset; } errno = EINVAL; - fprintf(stderr,"[knet_seek] %s\n", strerror(errno)); + hts_log_error("%s", strerror(errno)); return -1; } diff --git a/htslib/kstring.c b/htslib/kstring.c index 3dc78b697..6da457ef7 100644 --- a/htslib/kstring.c +++ b/htslib/kstring.c @@ -30,13 +30,127 @@ #include #include #include +#include #include "htslib/kstring.h" +int kputd(double d, kstring_t *s) { + int len = 0; + char buf[21], *cp = buf+20, *ep; + if (d == 0) { + if (signbit(d)) { + kputsn("-0",2,s); + return 2; + } else { + kputsn("0",1,s); + return 1; + } + } + + if (d < 0) { + kputc('-',s); + len = 1; + d=-d; + } + if (!(d >= 0.0001 && d <= 999999)) { + if (ks_resize(s, s->l + 50) < 0) + return EOF; + // We let stdio handle the exponent cases + int s2 = sprintf(s->s + s->l, "%g", d); + len += s2; + s->l += s2; + return len; + } + + uint64_t i = d*10000000000LL; + // Correction for rounding - rather ugly + + // Optimised for small numbers. + // Better still would be __builtin_clz on hi/lo 32 and get the + // starting point very rapidly. + if (d<.0001) + i+=0; + else if (d<0.001) + i+=5; + else if (d < 0.01) + i+=50; + else if (d < 0.1) + i+=500; + else if (d < 1) + i+=5000; + else if (d < 10) + i+=50000; + else if (d < 100) + i+=500000; + else if (d < 1000) + i+=5000000; + else if (d < 10000) + i+=50000000; + else if (d < 100000) + i+=500000000; + else + i+=5000000000LL; + + do { + *--cp = '0' + i%10; + i /= 10; + } while (i >= 1); + buf[20] = 0; + int p = buf+20-cp; + if (p <= 10) { // d < 1 + //assert(d/1); + cp[6] = 0; ep = cp+5;// 6 precision + while (p < 10) { + *--cp = '0'; + p++; + } + *--cp = '.'; + *--cp = '0'; + } else { + char *xp = --cp; + while (p > 10) { + xp[0] = xp[1]; + p--; + xp++; + } + xp[0] = '.'; + cp[7] = 0; ep=cp+6; + if (cp[6] == '.') cp[6] = 0; + } + + // Cull trailing zeros + while (*ep == '0' && ep > cp) + ep--; + char *z = ep+1; + while (ep > cp) { + if (*ep == '.') { + if (z[-1] == '.') + z[-1] = 0; + else + z[0] = 0; + break; + } + ep--; + } + + int sl = strlen(cp); + len += sl; + kputsn(cp, sl, s); + return len; +} + int kvsprintf(kstring_t *s, const char *fmt, va_list ap) { va_list args; int l; va_copy(args, ap); + + if (fmt[0] == '%' && fmt[1] == 'g' && fmt[2] == 0) { + double d = va_arg(args, double); + l = kputd(d, s); + va_end(args); + return l; + } + l = vsnprintf(s->s + s->l, s->m - s->l, fmt, args); // This line does not work with glibc 2.0. See `man snprintf'. va_end(args); if (l + 1 > s->m - s->l) { @@ -60,28 +174,29 @@ int ksprintf(kstring_t *s, const char *fmt, ...) return l; } -char *kstrtok(const char *str, const char *sep, ks_tokaux_t *aux) +char *kstrtok(const char *str, const char *sep_in, ks_tokaux_t *aux) { - const char *p, *start; + const unsigned char *p, *start, *sep = (unsigned char *) sep_in; if (sep) { // set up the table - if (str == 0 && (aux->tab[0]&1)) return 0; // no need to set up if we have finished + if (str == 0 && aux->finished) return 0; // no need to set up if we have finished aux->finished = 0; - if (sep[1]) { + if (sep[0] && sep[1]) { aux->sep = -1; aux->tab[0] = aux->tab[1] = aux->tab[2] = aux->tab[3] = 0; for (p = sep; *p; ++p) aux->tab[*p>>6] |= 1ull<<(*p&0x3f); } else aux->sep = sep[0]; } if (aux->finished) return 0; - else if (str) aux->p = str - 1, aux->finished = 0; + else if (str) start = (unsigned char *) str, aux->finished = 0; + else start = (unsigned char *) aux->p + 1; if (aux->sep < 0) { - for (p = start = aux->p + 1; *p; ++p) + for (p = start; *p; ++p) if (aux->tab[*p>>6]>>(*p&0x3f)&1) break; } else { - for (p = start = aux->p + 1; *p; ++p) + for (p = start; *p; ++p) if (*p == aux->sep) break; } - aux->p = p; // end of token + aux->p = (const char *) p; // end of token if (*p == 0) aux->finished = 1; // no more tokens return (char*)start; } @@ -92,7 +207,7 @@ int ksplit_core(char *s, int delimiter, int *_max, int **_offsets) int i, n, max, last_char, last_start, *offsets, l; n = 0; max = *_max; offsets = *_offsets; l = strlen(s); - + #define __ksplit_aux do { \ if (_offsets) { \ s[i] = 0; \ diff --git a/htslib/md5.c b/htslib/md5.c index ddcfcdf92..93515a73d 100644 --- a/htslib/md5.c +++ b/htslib/md5.c @@ -50,6 +50,7 @@ #include #include "htslib/hts.h" +#include "htslib/hts_endian.h" #ifndef HAVE_OPENSSL @@ -94,7 +95,7 @@ struct hts_md5_context { * memory accesses is just an optimization. Nothing will break if it * doesn't work. */ -#if defined(__i386__) || defined(__x86_64__) || defined(__vax__) +#if defined(HTS_LITTLE_ENDIAN) && HTS_ALLOW_UNALIGNED != 0 #define SET(n) \ (*(hts_md5_u32plus *)&ptr[(n) * 4]) #define GET(n) \ diff --git a/htslib/multipart.c b/htslib/multipart.c new file mode 100644 index 000000000..14c2584dd --- /dev/null +++ b/htslib/multipart.c @@ -0,0 +1,266 @@ +/* multipart.c -- GA4GH redirection and multipart backend for file streams. + + Copyright (C) 2016 Genome Research Ltd. + + Author: John Marshall + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include + +#include +#include +#include + +#include "htslib/kstring.h" + +#include "hts_internal.h" +#include "hfile_internal.h" + +#ifndef EPROTO +#define EPROTO ENOEXEC +#endif + +typedef struct hfile_part { + char *url; + char **headers; +} hfile_part; + +typedef struct { + hFILE base; + hfile_part *parts; + size_t nparts, maxparts, current; + hFILE *currentfp; +} hFILE_multipart; + +static void free_part(hfile_part *p) +{ + free(p->url); + if (p->headers) { + char **hdr; + for (hdr = p->headers; *hdr; hdr++) free(*hdr); + free(p->headers); + } + + p->url = NULL; + p->headers = NULL; +} + +static void free_all_parts(hFILE_multipart *fp) +{ + size_t i; + for (i = 0; i < fp->nparts; i++) free_part(&fp->parts[i]); + free(fp->parts); +} + +static ssize_t multipart_read(hFILE *fpv, void *buffer, size_t nbytes) +{ + hFILE_multipart *fp = (hFILE_multipart *) fpv; + size_t n; + +open_next: + if (fp->currentfp == NULL) { + if (fp->current < fp->nparts) { + const hfile_part *p = &fp->parts[fp->current]; + hts_log_debug("Opening part #%zu of %zu: \"%.120s%s\"", + fp->current+1, fp->nparts, p->url, + (strlen(p->url) > 120)? "..." : ""); + + fp->currentfp = p->headers? + hopen(p->url, "r:", + "httphdr:v", p->headers, + "auth_token_enabled", "false", NULL) + : hopen(p->url, "r:", "auth_token_enabled", "false", NULL); + + if (fp->currentfp == NULL) return -1; + } + else return 0; // No more parts, so we're truly at EOF + } + + n = fp->currentfp->mobile? + fp->currentfp->backend->read(fp->currentfp, buffer, nbytes) + : hread(fp->currentfp, buffer, nbytes); + + if (n == 0) { + // We're at EOF on this part, so set up the next part + hFILE *prevfp = fp->currentfp; + free_part(&fp->parts[fp->current]); + fp->current++; + fp->currentfp = NULL; + if (hclose(prevfp) < 0) return -1; + goto open_next; + } + + return n; // Number of bytes read by (or an error from) fp->currentfp +} + +static ssize_t multipart_write(hFILE *fpv, const void *buffer, size_t nbytes) +{ + errno = EROFS; + return -1; +} + +static off_t multipart_seek(hFILE *fpv, off_t offset, int whence) +{ + errno = ESPIPE; + return -1; +} + +static int multipart_close(hFILE *fpv) +{ + hFILE_multipart *fp = (hFILE_multipart *) fpv; + + free_all_parts(fp); + if (fp->currentfp) { + if (hclose(fp->currentfp) < 0) return -1; + } + + return 0; +} + +static const struct hFILE_backend multipart_backend = +{ + multipart_read, multipart_write, multipart_seek, NULL, multipart_close +}; + +// Returns 'v' (valid value), 'i' (invalid; required GA4GH field missing), +// or upon encountering an unexpected token, that token's type. +// Explicit `return '?'` means a JSON parsing error, typically a member key +// that is not a string. An unexpected token may be a valid token that was +// not the type expected for a particular GA4GH field, or it may be '?' or +// '\0' which should be propagated. +static char +parse_ga4gh_body_json(hFILE_multipart *fp, hFILE *json, + kstring_t *b, kstring_t *header) +{ + hts_json_token t; + + if (hts_json_fnext(json, &t, b) != '{') return t.type; + while (hts_json_fnext(json, &t, b) != '}') { + if (t.type != 's') return '?'; + + if (strcmp(t.str, "urls") == 0) { + if (hts_json_fnext(json, &t, b) != '[') return t.type; + + while (hts_json_fnext(json, &t, b) != ']') { + hfile_part *part; + size_t n = 0, max = 0; + + hts_expand(hfile_part, fp->nparts+1, fp->maxparts, fp->parts); + part = &fp->parts[fp->nparts++]; + part->url = NULL; + part->headers = NULL; + + if (t.type != '{') return t.type; + while (hts_json_fnext(json, &t, b) != '}') { + if (t.type != 's') return '?'; + + if (strcmp(t.str, "url") == 0) { + if (hts_json_fnext(json, &t, b) != 's') return t.type; + part->url = ks_release(b); + } + else if (strcmp(t.str, "headers") == 0) { + if (hts_json_fnext(json, &t, b) != '{') return t.type; + + while (hts_json_fnext(json, &t, header) != '}') { + if (t.type != 's') return '?'; + + if (hts_json_fnext(json, &t, b) != 's') + return t.type; + + kputs(": ", header); + kputs(t.str, header); + n++; + hts_expand(char *, n+1, max, part->headers); + part->headers[n-1] = ks_release(header); + part->headers[n] = NULL; + } + } + else if (hts_json_fskip_value(json, '\0') != 'v') + return '?'; + } + + if (! part->url) return 'i'; + } + } + else if (strcmp(t.str, "format") == 0) { + if (hts_json_fnext(json, &t, b) != 's') return t.type; + + hts_log_debug("GA4GH JSON redirection to multipart %s data", t.str); + } + else if (hts_json_fskip_value(json, '\0') != 'v') return '?'; + } + + return 'v'; +} + +// Returns 'v' (valid value), 'i' (invalid; required GA4GH field missing), +// or upon encountering an unexpected token, that token's type. +// Explicit `return '?'` means a JSON parsing error, typically a member key +// that is not a string. An unexpected token may be a valid token that was +// not the type expected for a particular GA4GH field, or it may be '?' or +// '\0' which should be propagated. +static char +parse_ga4gh_redirect_json(hFILE_multipart *fp, hFILE *json, + kstring_t *b, kstring_t *header) { + hts_json_token t; + + if (hts_json_fnext(json, &t, b) != '{') return t.type; + while (hts_json_fnext(json, &t, b) != '}') { + if (t.type != 's') return '?'; + + if (strcmp(t.str, "htsget") == 0) { + char ret = parse_ga4gh_body_json(fp, json, b, header); + if (ret != 'v') return ret; + } + else return '?'; + } + + if (hts_json_fnext(json, &t, b) != '\0') return '?'; + + return 'v'; +} + +hFILE *hopen_htsget_redirect(hFILE *hfile, const char *mode) +{ + hFILE_multipart *fp; + kstring_t s1 = { 0, 0, NULL }, s2 = { 0, 0, NULL }; + char ret; + + fp = (hFILE_multipart *) hfile_init(sizeof (hFILE_multipart), mode, 0); + if (fp == NULL) return NULL; + + fp->parts = NULL; + fp->nparts = fp->maxparts = 0; + + ret = parse_ga4gh_redirect_json(fp, hfile, &s1, &s2); + free(s1.s); + free(s2.s); + if (ret != 'v') { + free_all_parts(fp); + hfile_destroy((hFILE *) fp); + errno = (ret == '?' || ret == '\0')? EPROTO : EINVAL; + return NULL; + } + + fp->current = 0; + fp->currentfp = NULL; + fp->base.backend = &multipart_backend; + return &fp->base; +} diff --git a/htslib/os/lzma_stub.h b/htslib/os/lzma_stub.h new file mode 100644 index 000000000..5dd9c1a5e --- /dev/null +++ b/htslib/os/lzma_stub.h @@ -0,0 +1,85 @@ +#ifndef LZMA_STUB_H +#define LZMA_STUB_H + +/* Some platforms, notably macOS, ship a usable liblzma shared library but + do not ship any LZMA header files. The and header + files that come with the library contain the following statement: + + * + * Author: Lasse Collin + * + * This file has been put into the public domain. + * You can do whatever you want with this file. + * + + Accordingly the following declarations have been copied and distilled + from and (primarily) and are sufficient + to compile cram/cram_io.c in the absence of proper LZMA headers. + + This file, lzma_stub.h, remains in the public domain. */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { LZMA_OK = 0, LZMA_STREAM_END = 1 } lzma_ret; +typedef enum { LZMA_RUN = 0, LZMA_FINISH = 3 } lzma_action; +typedef enum { LZMA_CHECK_CRC32 = 1 } lzma_check; +typedef enum { LZMA_RESERVED_ENUM = 0 } lzma_reserved_enum; + +struct lzma_allocator; +struct lzma_internal; + +typedef struct { + const uint8_t *next_in; + size_t avail_in; + uint64_t total_in; + + uint8_t *next_out; + size_t avail_out; + uint64_t total_out; + + const struct lzma_allocator *allocator; + struct lzma_internal *internal; + + void *reserved_ptr1; + void *reserved_ptr2; + void *reserved_ptr3; + void *reserved_ptr4; + uint64_t reserved_int1; + uint64_t reserved_int2; + size_t reserved_int3; + size_t reserved_int4; + lzma_reserved_enum reserved_enum1; + lzma_reserved_enum reserved_enum2; +} lzma_stream; + +#define LZMA_STREAM_INIT \ + { NULL, 0, 0, NULL, 0, 0, NULL, NULL, \ + NULL, NULL, NULL, NULL, 0, 0, 0, 0, \ + LZMA_RESERVED_ENUM, LZMA_RESERVED_ENUM } + +extern size_t lzma_stream_buffer_bound(size_t uncompressed_size); + +extern lzma_ret lzma_easy_buffer_encode( + uint32_t preset, lzma_check check, + const struct lzma_allocator *allocator, + const uint8_t *in, size_t in_size, + uint8_t *out, size_t *out_pos, size_t out_size); + +extern lzma_ret lzma_stream_decoder( + lzma_stream *strm, uint64_t memlimit, uint32_t flags); + +extern uint64_t lzma_easy_decoder_memusage(uint32_t preset); + +extern lzma_ret lzma_code(lzma_stream *strm, lzma_action action); + +extern void lzma_end(lzma_stream *strm); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/htslib/os/rand.c b/htslib/os/rand.c new file mode 100644 index 000000000..ff0046d31 --- /dev/null +++ b/htslib/os/rand.c @@ -0,0 +1,97 @@ +/* rand.c -- drand48 implementation from the FreeBSD source tree. */ + +// This file is an amalgamation of the many small files in FreeBSD to do with +// drand48 and friends implementations. +// It comprises _rand48.c, rand48.h, srand48.c, drand48.c, erand48.c, lrand48.c + +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +//#include +//__FBSDID("$FreeBSD: src/lib/libc/gen/_rand48.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); + +#include + +#define RAND48_SEED_0 (0x330e) +#define RAND48_SEED_1 (0xabcd) +#define RAND48_SEED_2 (0x1234) +#define RAND48_MULT_0 (0xe66d) +#define RAND48_MULT_1 (0xdeec) +#define RAND48_MULT_2 (0x0005) +#define RAND48_ADD (0x000b) + +static unsigned short _rand48_seed[3] = { + RAND48_SEED_0, + RAND48_SEED_1, + RAND48_SEED_2 +}; +static unsigned short _rand48_mult[3] = { + RAND48_MULT_0, + RAND48_MULT_1, + RAND48_MULT_2 +}; +static unsigned short _rand48_add = RAND48_ADD; + +static void +_dorand48(unsigned short xseed[3]) +{ + unsigned long accu; + unsigned short temp[2]; + + accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] + + (unsigned long) _rand48_add; + temp[0] = (unsigned short) accu; /* lower 16 bits */ + accu >>= sizeof(unsigned short) * 8; + accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] + + (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0]; + temp[1] = (unsigned short) accu; /* middle 16 bits */ + accu >>= sizeof(unsigned short) * 8; + accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0]; + xseed[0] = temp[0]; + xseed[1] = temp[1]; + xseed[2] = (unsigned short) accu; +} + +void +hts_srand48(long seed) +{ + _rand48_seed[0] = RAND48_SEED_0; + _rand48_seed[1] = (unsigned short) seed; + _rand48_seed[2] = (unsigned short) (seed >> 16); + _rand48_mult[0] = RAND48_MULT_0; + _rand48_mult[1] = RAND48_MULT_1; + _rand48_mult[2] = RAND48_MULT_2; + _rand48_add = RAND48_ADD; +} + +double +hts_erand48(unsigned short xseed[3]) +{ + _dorand48(xseed); + return ldexp((double) xseed[0], -48) + + ldexp((double) xseed[1], -32) + + ldexp((double) xseed[2], -16); +} + +double +hts_drand48(void) +{ + return hts_erand48(_rand48_seed); +} + +long +hts_lrand48(void) +{ + _dorand48(_rand48_seed); + return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] >> 1); +} diff --git a/htslib/realn.c b/htslib/realn.c index d856f3c6a..a33acde84 100644 --- a/htslib/realn.c +++ b/htslib/realn.c @@ -78,7 +78,7 @@ int sam_cap_mapq(bam1_t *b, const char *ref, int ref_len, int thres) if (t > thres) return -1; if (t < 0) t = 0; t = sqrt((thres - t) / thres) * thres; -// fprintf(stderr, "%s %lf %d\n", bam_get_qname(b), t, q); + //fprintf(stderr, "%s %lf %d\n", bam_get_qname(b), t, q); return (int)(t + .499); } diff --git a/htslib/regidx.c b/htslib/regidx.c index 770a0755f..874f9c9f9 100644 --- a/htslib/regidx.c +++ b/htslib/regidx.c @@ -1,4 +1,4 @@ -/* +/* Copyright (C) 2014 Genome Research Ltd. Author: Petr Danecek @@ -9,10 +9,10 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,6 +23,7 @@ */ #include +#include #include "htslib/hts.h" #include "htslib/kstring.h" @@ -94,7 +95,7 @@ int _regidx_build_index(regidx_t *idx) int iend = list->regs[j].end >> LIDX_SHIFT; if ( imax < iend + 1 ) { - int old_imax = imax; + int old_imax = imax; imax = iend + 1; kroundup32(imax); list->idx = (int*) realloc(list->idx, imax*sizeof(int)); @@ -147,15 +148,15 @@ int regidx_insert(regidx_t *idx, char *line) if ( idx->payload_size ) { if ( m_prev < list->mregs ) list->payload = realloc(list->payload,idx->payload_size*list->mregs); - memcpy(list->payload + idx->payload_size*(list->nregs-1), idx->payload, idx->payload_size); + memcpy((char*)list->payload + idx->payload_size*(list->nregs-1), idx->payload, idx->payload_size); } if ( idx->rid_prev==rid ) { - if ( idx->start_prev > reg.start || (idx->start_prev==reg.start && idx->end_prev>reg.end) ) - { - fprintf(stderr,"The regions are not sorted: %s:%d-%d is before %s:%d-%d\n", - idx->str.s,idx->start_prev+1,idx->end_prev+1,idx->str.s,reg.start+1,reg.end+1); + if ( idx->start_prev > reg.start || (idx->start_prev==reg.start && idx->end_prev>reg.end) ) + { + hts_log_error("The regions are not sorted: %s:%d-%d is before %s:%d-%d", + idx->str.s,idx->start_prev+1,idx->end_prev+1,idx->str.s,reg.start+1,reg.end+1); return -1; } } @@ -196,7 +197,7 @@ regidx_t *regidx_init(const char *fname, regidx_parse_f parser, regidx_free_f fr if ( payload_size ) idx->payload = malloc(payload_size); if ( !fname ) return idx; - + kstring_t str = {0,0,0}; htsFile *fp = hts_open(fname,"r"); @@ -207,7 +208,7 @@ regidx_t *regidx_init(const char *fname, regidx_parse_f parser, regidx_free_f fr if ( regidx_insert(idx, str.s) ) goto error; } regidx_insert(idx, NULL); - + free(str.s); hts_close(fp); return idx; @@ -228,7 +229,7 @@ void regidx_destroy(regidx_t *idx) if ( idx->free ) { for (j=0; jnregs; j++) - idx->free(list->payload + idx->payload_size*j); + idx->free((char*)list->payload + idx->payload_size*j); } free(list->payload); free(list->regs); @@ -252,7 +253,7 @@ int regidx_overlap(regidx_t *idx, const char *chr, uint32_t from, uint32_t to, r reglist_t *list = &idx->seq[iseq]; if ( !list->nregs ) return 0; - int i, ibeg = from>>LIDX_SHIFT; + int i, ibeg = from>>LIDX_SHIFT; int ireg = ibeg < list->nidx ? list->idx[ibeg] : list->idx[ list->nidx - 1 ]; if ( ireg < 0 ) { @@ -276,7 +277,7 @@ int regidx_overlap(regidx_t *idx, const char *chr, uint32_t from, uint32_t to, r itr->n = list->nregs - i; itr->reg = &idx->seq[iseq].regs[i]; if ( idx->payload_size ) - itr->payload = idx->seq[iseq].payload + i*idx->payload_size; + itr->payload = (char*)idx->seq[iseq].payload + i*idx->payload_size; else itr->payload = NULL; @@ -289,22 +290,22 @@ int regidx_parse_bed(const char *line, char **chr_beg, char **chr_end, reg_t *re while ( *ss && isspace_c(*ss) ) ss++; if ( !*ss ) return -1; // skip blank lines if ( *ss=='#' ) return -1; // skip comments - + char *se = ss; while ( *se && !isspace_c(*se) ) se++; - if ( !*se ) { fprintf(stderr,"Could not parse bed line: %s\n", line); return -2; } + if ( !*se ) { hts_log_error("Could not parse bed line: %s", line); return -2; } *chr_beg = ss; *chr_end = se-1; ss = se+1; reg->start = hts_parse_decimal(ss, &se, 0); - if ( ss==se ) { fprintf(stderr,"Could not parse bed line: %s\n", line); return -2; } + if ( ss==se ) { hts_log_error("Could not parse bed line: %s", line); return -2; } ss = se+1; reg->end = hts_parse_decimal(ss, &se, 0) - 1; - if ( ss==se ) { fprintf(stderr,"Could not parse bed line: %s\n", line); return -2; } - + if ( ss==se ) { hts_log_error("Could not parse bed line: %s", line); return -2; } + return 0; } @@ -314,17 +315,17 @@ int regidx_parse_tab(const char *line, char **chr_beg, char **chr_end, reg_t *re while ( *ss && isspace_c(*ss) ) ss++; if ( !*ss ) return -1; // skip blank lines if ( *ss=='#' ) return -1; // skip comments - + char *se = ss; while ( *se && !isspace_c(*se) ) se++; - if ( !*se ) { fprintf(stderr,"Could not parse bed line: %s\n", line); return -2; } + if ( !*se ) { hts_log_error("Could not parse bed line: %s", line); return -2; } *chr_beg = ss; *chr_end = se-1; ss = se+1; reg->start = hts_parse_decimal(ss, &se, 0) - 1; - if ( ss==se ) { fprintf(stderr,"Could not parse bed line: %s\n", line); return -2; } + if ( ss==se ) { hts_log_error("Could not parse bed line: %s", line); return -2; } if ( !se[0] || !se[1] ) reg->end = reg->start; @@ -335,7 +336,7 @@ int regidx_parse_tab(const char *line, char **chr_beg, char **chr_end, reg_t *re if ( ss==se ) reg->end = reg->start; else reg->end--; } - + return 0; } diff --git a/htslib/sam.c b/htslib/sam.c index 44441f2c1..7f98e951c 100644 --- a/htslib/sam.c +++ b/htslib/sam.c @@ -1,6 +1,6 @@ /* sam.c -- SAM and BAM file I/O and manipulation. - Copyright (C) 2008-2010, 2012-2016 Genome Research Ltd. + Copyright (C) 2008-2010, 2012-2018 Genome Research Ltd. Copyright (C) 2010, 2012, 2013 Broad Institute. Author: Heng Li @@ -25,22 +25,29 @@ DEALINGS IN THE SOFTWARE. */ #include +#include #include #include #include #include #include +#include #include "htslib/sam.h" #include "htslib/bgzf.h" #include "cram/cram.h" #include "hts_internal.h" #include "htslib/hfile.h" +#include "htslib/hts_endian.h" #include "htslib/khash.h" KHASH_DECLARE(s2i, kh_cstr_t, int64_t) typedef khash_t(s2i) sdict_t; +#ifndef EOVERFLOW +#define EOVERFLOW ERANGE +#endif + /********************** *** BAM header I/O *** **********************/ @@ -104,7 +111,7 @@ static bam_hdr_t *hdr_from_dict(sdict_t *d) for (k = kh_begin(d); k != kh_end(d); ++k) { if (!kh_exist(d, k)) continue; h->target_name[kh_val(d, k)>>32] = (char*)kh_key(d, k); - h->target_len[kh_val(d, k)>>32] = kh_val(d, k)<<32>>32; + h->target_len[kh_val(d, k)>>32] = kh_val(d, k) & 0xffffffffUL; kh_val(d, k) >>= 32; } return h; @@ -122,12 +129,13 @@ bam_hdr_t *bam_hdr_read(BGZF *fp) has_EOF = bgzf_check_EOF(fp); if (has_EOF < 0) { perror("[W::bam_hdr_read] bgzf_check_EOF"); - } else if (has_EOF == 0 && hts_verbose >= 2) - fprintf(stderr, "[W::%s] EOF marker is absent. The input is probably truncated.\n", __func__); + } else if (has_EOF == 0) { + hts_log_warning("EOF marker is absent. The input is probably truncated"); + } // read "BAM1" magic_len = bgzf_read(fp, buf, 4); if (magic_len != 4 || strncmp(buf, "BAM\1", 4)) { - if (hts_verbose >= 1) fprintf(stderr, "[E::%s] invalid BAM binary header\n", __func__); + hts_log_error("Invalid BAM binary header"); return 0; } h = bam_hdr_init(); @@ -195,23 +203,19 @@ bam_hdr_t *bam_hdr_read(BGZF *fp) return h; nomem: - if (hts_verbose >= 1) fprintf(stderr, "[E::%s] out of memory\n", __func__); + hts_log_error("Out of memory"); goto clean; read_err: - if (hts_verbose >= 1) { - if (bytes < 0) { - fprintf(stderr, "[E::%s] error reading BGZF stream\n", __func__); - } else { - fprintf(stderr, "[E::%s] truncated bam header\n", __func__); - } + if (bytes < 0) { + hts_log_error("Error reading BGZF stream"); + } else { + hts_log_error("Truncated BAM header"); } goto clean; invalid: - if (hts_verbose >= 1) { - fprintf(stderr, "[E::%s] invalid BAM binary header\n", __func__); - } + hts_log_error("Invalid BAM binary header"); clean: if (h != NULL) { @@ -322,6 +326,18 @@ bam1_t *bam_dup1(const bam1_t *bsrc) return bam_copy1(bdst, bsrc); } +void bam_cigar2rqlens(int n_cigar, const uint32_t *cigar, int *rlen, int *qlen) +{ + int k; + *rlen = *qlen = 0; + for (k = 0; k < n_cigar; ++k) { + int type = bam_cigar_type(bam_cigar_op(cigar[k])); + int len = bam_cigar_oplen(cigar[k]); + if (type & 1) *qlen += len; + if (type & 2) *rlen += len; + } +} + int bam_cigar2qlen(int n_cigar, const uint32_t *cigar) { int k, l; @@ -348,6 +364,49 @@ int32_t bam_endpos(const bam1_t *b) return b->core.pos + 1; } +static int bam_tag2cigar(bam1_t *b, int recal_bin, int give_warning) // return 0 if CIGAR is untouched; 1 if CIGAR is updated with CG +{ + bam1_core_t *c = &b->core; + uint32_t cigar_st, n_cigar4, CG_st, CG_en, ori_len = b->l_data, *cigar0, CG_len, fake_bytes; + uint8_t *CG; + + // test where there is a real CIGAR in the CG tag to move + if (c->n_cigar == 0 || c->tid < 0 || c->pos < 0) return 0; + cigar0 = bam_get_cigar(b); + if (bam_cigar_op(cigar0[0]) != BAM_CSOFT_CLIP || bam_cigar_oplen(cigar0[0]) != c->l_qseq) return 0; + fake_bytes = c->n_cigar * 4; + if ((CG = bam_aux_get(b, "CG")) == 0) return 0; // no CG tag + if (CG[0] != 'B' || CG[1] != 'I') return 0; // not of type B,I + CG_len = le_to_u32(CG + 2); + if (CG_len < c->n_cigar || CG_len >= 1U<<29) return 0; // don't move if the real CIGAR length is shorter than the fake cigar length + + // move from the CG tag to the right position + cigar_st = (uint8_t*)cigar0 - b->data; + c->n_cigar = CG_len; + n_cigar4 = c->n_cigar * 4; + CG_st = CG - b->data - 2; + CG_en = CG_st + 8 + n_cigar4; + b->l_data = b->l_data - fake_bytes + n_cigar4; // we need c->n_cigar-fake_bytes bytes to swap CIGAR to the right place + if (b->m_data < b->l_data) { + uint8_t *new_data; + uint32_t new_max = b->l_data; + kroundup32(new_max); + new_data = (uint8_t*)realloc(b->data, new_max); + if (new_data == 0) return -1; + b->m_data = new_max, b->data = new_data; + } + memmove(b->data + cigar_st + n_cigar4, b->data + cigar_st + fake_bytes, ori_len - (cigar_st + fake_bytes)); // insert c->n_cigar-fake_bytes empty space to make room + memcpy(b->data + cigar_st, b->data + (n_cigar4 - fake_bytes) + CG_st + 8, n_cigar4); // copy the real CIGAR to the right place; -fake_bytes for the fake CIGAR + if (ori_len > CG_en) // move data after the CG tag + memmove(b->data + CG_st + n_cigar4 - fake_bytes, b->data + CG_en + n_cigar4 - fake_bytes, ori_len - CG_en); + b->l_data -= n_cigar4 + 8; // 8: CGBI (4 bytes) and CGBI length (4) + if (recal_bin) + b->core.bin = hts_reg2bin(b->core.pos, b->core.pos + bam_cigar2rlen(b->core.n_cigar, bam_get_cigar(b)), 14, 5); + if (give_warning) + hts_log_error("%s encodes a CIGAR with %d operators at the CG tag", bam_get_qname(b), c->n_cigar); + return 1; +} + static inline int aux_type2size(uint8_t type) { switch (type) { @@ -368,39 +427,9 @@ static inline int aux_type2size(uint8_t type) static void swap_data(const bam1_core_t *c, int l_data, uint8_t *data, int is_host) { - uint8_t *s; uint32_t *cigar = (uint32_t*)(data + c->l_qname); - uint32_t i, n; - s = data + c->n_cigar*4 + c->l_qname + c->l_qseq + (c->l_qseq + 1)/2; + uint32_t i; for (i = 0; i < c->n_cigar; ++i) ed_swap_4p(&cigar[i]); - while (s < data + l_data) { - int size; - s += 2; // skip key - size = aux_type2size(*s); ++s; // skip type - switch (size) { - case 1: ++s; break; - case 2: ed_swap_2p(s); s += 2; break; - case 4: ed_swap_4p(s); s += 4; break; - case 8: ed_swap_8p(s); s += 8; break; - case 'Z': - case 'H': - while (*s) ++s; - ++s; - break; - case 'B': - size = aux_type2size(*s); ++s; - if (is_host) memcpy(&n, s, 4), ed_swap_4p(s); - else ed_swap_4p(s), memcpy(&n, s, 4); - s += 4; - switch (size) { - case 1: s += n; break; - case 2: for (i = 0; i < n; ++i, s += 2) ed_swap_2p(s); break; - case 4: for (i = 0; i < n; ++i, s += 4) ed_swap_4p(s); break; - case 8: for (i = 0; i < n; ++i, s += 8) ed_swap_8p(s); break; - } - break; - } - } } int bam_read1(BGZF *fp, bam1_t *b) @@ -412,42 +441,73 @@ int bam_read1(BGZF *fp, bam1_t *b) if (ret == 0) return -1; // normal end-of-file else return -2; // truncated } + if (fp->is_be) + ed_swap_4p(&block_len); + if (block_len < 32) return -4; // block_len includes core data if (bgzf_read(fp, x, 32) != 32) return -3; if (fp->is_be) { - ed_swap_4p(&block_len); for (i = 0; i < 8; ++i) ed_swap_4p(x + i); } c->tid = x[0]; c->pos = x[1]; c->bin = x[2]>>16; c->qual = x[2]>>8&0xff; c->l_qname = x[2]&0xff; + c->l_extranul = (c->l_qname%4 != 0)? (4 - c->l_qname%4) : 0; + if ((uint32_t) c->l_qname + c->l_extranul > 255) // l_qname would overflow + return -4; c->flag = x[3]>>16; c->n_cigar = x[3]&0xffff; c->l_qseq = x[4]; c->mtid = x[5]; c->mpos = x[6]; c->isize = x[7]; - b->l_data = block_len - 32; + b->l_data = block_len - 32 + c->l_extranul; if (b->l_data < 0 || c->l_qseq < 0 || c->l_qname < 1) return -4; - if ((char *)bam_get_aux(b) - (char *)b->data > b->l_data) + if (((uint64_t) c->n_cigar << 2) + c->l_qname + c->l_extranul + + (((uint64_t) c->l_qseq + 1) >> 1) + c->l_qseq > (uint64_t) b->l_data) return -4; if (b->m_data < b->l_data) { - b->m_data = b->l_data; - kroundup32(b->m_data); - b->data = (uint8_t*)realloc(b->data, b->m_data); - if (!b->data) + uint8_t *new_data; + uint32_t new_m = b->l_data; + kroundup32(new_m); + new_data = (uint8_t*)realloc(b->data, new_m); + if (!new_data) return -4; - } - if (bgzf_read(fp, b->data, b->l_data) != b->l_data) return -4; - //b->l_aux = b->l_data - c->n_cigar * 4 - c->l_qname - c->l_qseq - (c->l_qseq+1)/2; + b->data = new_data; + b->m_data = new_m; + } + if (bgzf_read(fp, b->data, c->l_qname) != c->l_qname) return -4; + for (i = 0; i < c->l_extranul; ++i) b->data[c->l_qname+i] = '\0'; + c->l_qname += c->l_extranul; + if (b->l_data < c->l_qname || + bgzf_read(fp, b->data + c->l_qname, b->l_data - c->l_qname) != b->l_data - c->l_qname) + return -4; if (fp->is_be) swap_data(c, b->l_data, b->data, 0); + if (bam_tag2cigar(b, 0, 0) < 0) + return -4; + + if (c->n_cigar > 0) { // recompute "bin" and check CIGAR-qlen consistency + int rlen, qlen; + bam_cigar2rqlens(c->n_cigar, bam_get_cigar(b), &rlen, &qlen); + if ((b->core.flag & BAM_FUNMAP)) rlen=1; + b->core.bin = hts_reg2bin(b->core.pos, b->core.pos + rlen, 14, 5); + // Sanity check for broken CIGAR alignments + if (c->l_qseq > 0 && !(c->flag & BAM_FUNMAP) && qlen != c->l_qseq) { + hts_log_error("CIGAR and query sequence lengths differ for %s", + bam_get_qname(b)); + return -4; + } + } + return 4 + block_len; } int bam_write1(BGZF *fp, const bam1_t *b) { const bam1_core_t *c = &b->core; - uint32_t x[8], block_len = b->l_data + 32, y; + uint32_t x[8], block_len = b->l_data - c->l_extranul + 32, y; int i, ok; + if (c->n_cigar > 0xffff) block_len += 16; // "16" for "CGBI", 4-byte tag length and 8-byte fake CIGAR x[0] = c->tid; x[1] = c->pos; - x[2] = (uint32_t)c->bin<<16 | c->qual<<8 | c->l_qname; - x[3] = (uint32_t)c->flag<<16 | c->n_cigar; + x[2] = (uint32_t)c->bin<<16 | c->qual<<8 | (c->l_qname - c->l_extranul); + if (c->n_cigar > 0xffff) x[3] = (uint32_t)c->flag << 16 | 2; + else x[3] = (uint32_t)c->flag << 16 | (c->n_cigar & 0xffff); x[4] = c->l_qseq; x[5] = c->mtid; x[6] = c->mpos; @@ -462,7 +522,25 @@ int bam_write1(BGZF *fp, const bam1_t *b) if (ok) ok = (bgzf_write(fp, &block_len, 4) >= 0); } if (ok) ok = (bgzf_write(fp, x, 32) >= 0); - if (ok) ok = (bgzf_write(fp, b->data, b->l_data) >= 0); + if (ok) ok = (bgzf_write(fp, b->data, c->l_qname - c->l_extranul) >= 0); + if (c->n_cigar <= 0xffff) { // no long CIGAR; write normally + if (ok) ok = (bgzf_write(fp, b->data + c->l_qname, b->l_data - c->l_qname) >= 0); + } else { // with long CIGAR, insert a fake CIGAR record and move the real CIGAR to the CG:B,I tag + uint8_t buf[8]; + uint32_t cigar_st, cigar_en, cigar[2]; + cigar_st = (uint8_t*)bam_get_cigar(b) - b->data; + cigar_en = cigar_st + c->n_cigar * 4; + cigar[0] = (uint32_t)c->l_qseq << 4 | BAM_CSOFT_CLIP; + cigar[1] = (uint32_t)bam_cigar2rlen(c->n_cigar, bam_get_cigar(b)) << 4 | BAM_CREF_SKIP; + u32_to_le(cigar[0], buf); + u32_to_le(cigar[1], buf + 4); + if (ok) ok = (bgzf_write(fp, buf, 8) >= 0); // write cigar: SN + if (ok) ok = (bgzf_write(fp, &b->data[cigar_en], b->l_data - cigar_en) >= 0); // write data after CIGAR + if (ok) ok = (bgzf_write(fp, "CGBI", 4) >= 0); // write CG:B,I + u32_to_le(c->n_cigar, buf); + if (ok) ok = (bgzf_write(fp, buf, 4) >= 0); // write the true CIGAR length + if (ok) ok = (bgzf_write(fp, &b->data[cigar_st], c->n_cigar * 4) >= 0); // write the real CIGAR + } if (fp->is_be) swap_data(c, b->l_data, b->data, 0); return ok? 4 + block_len : -1; } @@ -574,7 +652,74 @@ static int cram_readrec(BGZF *ignored, void *fpv, void *bv, int *tid, int *beg, { htsFile *fp = fpv; bam1_t *b = bv; - return cram_get_bam_seq(fp->fp.cram, &b); + int ret = cram_get_bam_seq(fp->fp.cram, &b); + if (ret < 0) + return cram_eof(fp->fp.cram) ? -1 : -2; + + if (bam_tag2cigar(b, 1, 1) < 0) + return -2; + + *tid = b->core.tid; + *beg = b->core.pos; + *end = bam_endpos(b); + + return ret; +} + +static int cram_pseek(void *fp, int64_t offset, int whence) +{ + cram_fd *fd = (cram_fd *)fp; + + if ((0 != cram_seek(fd, offset, SEEK_SET)) + && (0 != cram_seek(fd, offset - fd->first_container, SEEK_CUR))) + return -1; + + if (fd->ctr) { + cram_free_container(fd->ctr); + fd->ctr = NULL; + fd->ooc = 0; + } + + return 0; +} + +/* + * cram_ptell is a pseudo-tell function, because it matches the position of the disk cursor only + * after a fresh seek call. Otherwise it indicates that the read takes place inside the buffered + * container previously fetched. It was designed like this to integrate with the functionality + * of the iterator stepping logic. + */ + +static int64_t cram_ptell(void *fp) +{ + cram_fd *fd = (cram_fd *)fp; + cram_container *c; + int64_t ret = -1L; + + if (fd && fd->fp) { + ret = htell(fd->fp); + if ((c = fd->ctr) != NULL) { + ret -= ((c->curr_slice != c->max_slice || c->curr_rec != c->max_rec) ? c->offset + 1 : 0); + } + } + + return ret; +} + +static int bam_pseek(void *fp, int64_t offset, int whence) +{ + BGZF *fd = (BGZF *)fp; + + return bgzf_seek(fd, offset, whence); +} + +static int64_t bam_ptell(void *fp) +{ + BGZF *fd = (BGZF *)fp; + if (!fd) + return -1L; + + return bgzf_tell(fd); } // This is used only with read_rest=1 iterators, so need not set tid/beg/end. @@ -584,10 +729,18 @@ static int sam_bam_cram_readrec(BGZF *bgzfp, void *fpv, void *bv, int *tid, int bam1_t *b = bv; switch (fp->format.format) { case bam: return bam_read1(bgzfp, b); - case cram: return cram_get_bam_seq(fp->fp.cram, &b); + case cram: { + int ret = cram_get_bam_seq(fp->fp.cram, &b); + if (ret < 0) + return cram_eof(fp->fp.cram) ? -1 : -2; + + if (bam_tag2cigar(b, 1, 1) < 0) + return -2; + return ret; + } default: // TODO Need headers available to implement this for SAM files - fprintf(stderr, "[sam_bam_cram_readrec] Not implemented for SAM files -- Exiting\n"); + hts_log_error("Not implemented for SAM files"); abort(); } } @@ -632,8 +785,8 @@ static hts_itr_t *cram_itr_query(const hts_idx_t *idx, int tid, int beg, int end iter->bins.a = NULL; iter->readrec = readrec; - if (tid >= 0 || tid == HTS_IDX_NOCOOR) { - cram_range r = { tid == HTS_IDX_NOCOOR ? -1 : tid, beg+1, end }; + if (tid >= 0 || tid == HTS_IDX_NOCOOR || tid == HTS_IDX_START) { + cram_range r = { tid, beg+1, end }; int ret = cram_set_option(cidx->cram, CRAM_OPT_RANGE, &r); iter->curr_off = 0; @@ -667,7 +820,7 @@ static hts_itr_t *cram_itr_query(const hts_idx_t *idx, int tid, int beg, int end iter->finished = 1; break; default: - fprintf(stderr, "[cram_itr_query] tid=%d not implemented for CRAM files -- Exiting\n", tid); + hts_log_error("Query with tid=%d not implemented for CRAM files", tid); abort(); break; } @@ -701,6 +854,17 @@ hts_itr_t *sam_itr_querys(const hts_idx_t *idx, bam_hdr_t *hdr, const char *regi return hts_itr_querys(idx, region, (hts_name2id_f)(bam_name2id), hdr, hts_itr_query, bam_readrec); } +hts_itr_multi_t *sam_itr_regions(const hts_idx_t *idx, bam_hdr_t *hdr, hts_reglist_t *reglist, unsigned int regcount) +{ + const hts_cram_idx_t *cidx = (const hts_cram_idx_t *) idx; + if (cidx->fmt == HTS_FMT_CRAI) + return hts_itr_regions(idx, reglist, regcount, cram_name2id, cidx->cram, + hts_itr_multi_cram, cram_readrec, cram_pseek, cram_ptell); + else + return hts_itr_regions(idx, reglist, regcount, (hts_name2id_f)(bam_name2id), hdr, + hts_itr_multi_bam, bam_readrec, bam_pseek, bam_ptell); +} + /********************** *** SAM header I/O *** **********************/ @@ -735,8 +899,7 @@ bam_hdr_t *sam_hdr_parse(int l_text, const char *text) int absent; k = kh_put(s2i, d, sn, &absent); if (!absent) { - if (hts_verbose >= 2) - fprintf(stderr, "[W::%s] duplicated sequence '%s'\n", __func__, sn); + hts_log_warning("Duplicated sequence '%s'", sn); free(sn); } else kh_val(d, k) = (int64_t)(kh_size(d) - 1)<<32 | ln; } @@ -746,41 +909,126 @@ bam_hdr_t *sam_hdr_parse(int l_text, const char *text) return hdr_from_dict(d); } +// Minimal sanitisation of a header to ensure. +// - null terminated string. +// - all lines start with @ (also implies no blank lines). +// +// Much more could be done, but currently is not, including: +// - checking header types are known (HD, SQ, etc). +// - syntax (eg checking tab separated fields). +// - validating n_targets matches @SQ records. +// - validating target lengths against @SQ records. +static bam_hdr_t *sam_hdr_sanitise(bam_hdr_t *h) { + if (!h) + return NULL; + + // Special case for empty headers. + if (h->l_text == 0) + return h; + + uint32_t i, lnum = 0; + char *cp = h->text, last = '\n'; + for (i = 0; i < h->l_text; i++) { + // NB: l_text excludes terminating nul. This finds early ones. + if (cp[i] == 0) + break; + + // Error on \n[^@], including duplicate newlines + if (last == '\n') { + lnum++; + if (cp[i] != '@') { + hts_log_error("Malformed SAM header at line %u", lnum); + bam_hdr_destroy(h); + return NULL; + } + } + + last = cp[i]; + } + + if (i < h->l_text) { // Early nul found. Complain if not just padding. + uint32_t j = i; + while (j < h->l_text && cp[j] == '\0') j++; + if (j < h->l_text) + hts_log_warning("Unexpected NUL character in header. Possibly truncated"); + } + + // Add trailing newline and/or trailing nul if required. + if (last != '\n') { + hts_log_warning("Missing trailing newline on SAM header. Possibly truncated"); + + if (h->l_text == UINT32_MAX) { + hts_log_error("No room for extra newline"); + bam_hdr_destroy(h); + return NULL; + } + + if (i >= h->l_text - 1) { + cp = realloc(h->text, (size_t) h->l_text+2); + if (!cp) { + bam_hdr_destroy(h); + return NULL; + } + h->text = cp; + } + cp[i++] = '\n'; + + // l_text may be larger already due to multiple nul padding + if (h->l_text < i) + h->l_text = i; + cp[h->l_text] = '\0'; + } + + return h; +} + bam_hdr_t *sam_hdr_read(htsFile *fp) { switch (fp->format.format) { case bam: - return bam_hdr_read(fp->fp.bgzf); + return sam_hdr_sanitise(bam_hdr_read(fp->fp.bgzf)); case cram: - return cram_header_to_bam(fp->fp.cram->header); + return sam_hdr_sanitise(cram_header_to_bam(fp->fp.cram->header)); case sam: { - kstring_t str; - bam_hdr_t *h; - int has_SQ = 0; - str.l = str.m = 0; str.s = 0; - while (hts_getline(fp, KS_SEP_LINE, &fp->line) >= 0) { + kstring_t str = { 0, 0, NULL }; + bam_hdr_t *h = NULL; + int ret, has_SQ = 0; + while ((ret = hts_getline(fp, KS_SEP_LINE, &fp->line)) >= 0) { if (fp->line.s[0] != '@') break; if (fp->line.l > 3 && strncmp(fp->line.s,"@SQ",3) == 0) has_SQ = 1; kputsn(fp->line.s, fp->line.l, &str); kputc('\n', &str); } + if (ret < -1) goto error; if (! has_SQ && fp->fn_aux) { - char line[2048]; - FILE *f = fopen(fp->fn_aux, "r"); - if (f == NULL) return NULL; - while (fgets(line, sizeof line, f)) { - const char *name = strtok(line, "\t"); - const char *length = strtok(NULL, "\t"); - ksprintf(&str, "@SQ\tSN:%s\tLN:%s\n", name, length); + kstring_t line = { 0, 0, NULL }; + hFILE *f = hopen(fp->fn_aux, "r"); + if (f == NULL) goto error; + while (line.l = 0, kgetline(&line, (kgets_func *) hgets, f) >= 0) { + char *tab = strchr(line.s, '\t'); + if (tab == NULL) continue; + kputs("@SQ\tSN:", &str); + kputsn(line.s, tab - line.s, &str); + kputs("\tLN:", &str); + kputl(atol(tab), &str); + kputc('\n', &str); + } + free(line.s); + if (hclose(f) != 0) { + hts_log_warning("Failed to close %s", fp->fn_aux); } - fclose(f); } if (str.l == 0) kputsn("", 0, &str); h = sam_hdr_parse(str.l, str.s); h->l_text = str.l; h->text = str.s; - return h; + return sam_hdr_sanitise(h); + + error: + bam_hdr_destroy(h); + free(str.s); + return NULL; } default: @@ -790,6 +1038,11 @@ bam_hdr_t *sam_hdr_read(htsFile *fp) int sam_hdr_write(htsFile *fp, const bam_hdr_t *h) { + if (!h) { + errno = EINVAL; + return -1; + } + switch (fp->format.format) { case binary_format: fp->format.category = sequence_data; @@ -837,6 +1090,78 @@ int sam_hdr_write(htsFile *fp, const bam_hdr_t *h) return 0; } +int sam_hdr_change_HD(bam_hdr_t *h, const char *key, const char *val) +{ + char *p, *q, *beg = NULL, *end = NULL, *newtext; + if (!h || !key) + return -1; + + if (h->l_text > 3) { + if (strncmp(h->text, "@HD", 3) == 0) { //@HD line exists + if ((p = strchr(h->text, '\n')) == 0) return -1; + *p = '\0'; // for strstr call + + char tmp[5] = { '\t', key[0], key[0] ? key[1] : '\0', ':', '\0' }; + + if ((q = strstr(h->text, tmp)) != 0) { // key exists + *p = '\n'; // change back + + // mark the key:val + beg = q; + for (q += 4; *q != '\n' && *q != '\t'; ++q); + end = q; + + if (val && (strncmp(beg + 4, val, end - beg - 4) == 0) + && strlen(val) == end - beg - 4) + return 0; // val is the same, no need to change + + } else { + beg = end = p; + *p = '\n'; + } + } + } + if (beg == NULL) { // no @HD + if (h->l_text > UINT32_MAX - strlen(SAM_FORMAT_VERSION) - 9) + return -1; + h->l_text += strlen(SAM_FORMAT_VERSION) + 8; + if (val) { + if (h->l_text > UINT32_MAX - strlen(val) - 5) + return -1; + h->l_text += strlen(val) + 4; + } + newtext = (char*)malloc(h->l_text + 1); + if (!newtext) return -1; + + if (val) + snprintf(newtext, h->l_text + 1, + "@HD\tVN:%s\t%s:%s\n%s", SAM_FORMAT_VERSION, key, val, h->text); + else + snprintf(newtext, h->l_text + 1, + "@HD\tVN:%s\n%s", SAM_FORMAT_VERSION, h->text); + } else { // has @HD but different or no key + h->l_text = (beg - h->text) + (h->text + h->l_text - end); + if (val) { + if (h->l_text > UINT32_MAX - strlen(val) - 5) + return -1; + h->l_text += strlen(val) + 4; + } + newtext = (char*)malloc(h->l_text + 1); + if (!newtext) return -1; + + if (val) { + snprintf(newtext, h->l_text + 1, "%.*s\t%s:%s%s", + (int) (beg - h->text), h->text, key, val, end); + } else { //delete key + snprintf(newtext, h->l_text + 1, "%.*s%s", + (int) (beg - h->text), h->text, end); + } + } + free(h->text); + h->text = newtext; + return 0; +} + /********************** *** SAM record I/O *** **********************/ @@ -846,8 +1171,9 @@ int sam_parse1(kstring_t *s, bam_hdr_t *h, bam1_t *b) #define _read_token(_p) (_p); for (; *(_p) && *(_p) != '\t'; ++(_p)); if (*(_p) != '\t') goto err_ret; *(_p)++ = 0 #define _read_token_aux(_p) (_p); for (; *(_p) && *(_p) != '\t'; ++(_p)); *(_p)++ = 0 // this is different in that it does not test *(_p)=='\t' #define _get_mem(type_t, _x, _s, _l) ks_resize((_s), (_s)->l + (_l)); *(_x) = (type_t*)((_s)->s + (_s)->l); (_s)->l += (_l) -#define _parse_err(cond, msg) do { if ((cond) && hts_verbose >= 1) { fprintf(stderr, "[E::%s] " msg "\n", __func__); goto err_ret; } } while (0) -#define _parse_warn(cond, msg) if ((cond) && hts_verbose >= 2) fprintf(stderr, "[W::%s] " msg "\n", __func__) +#define _parse_err(cond, msg) do { if (cond) { hts_log_error(msg); goto err_ret; } } while (0) +#define _parse_err_param(cond, msg, param) do { if (cond) { hts_log_error(msg, param); goto err_ret; } } while (0) +#define _parse_warn(cond, msg) do { if (cond) { hts_log_warning(msg); } } while (0) uint8_t *t; char *p = s->s, *q; @@ -868,9 +1194,11 @@ int sam_parse1(kstring_t *s, bam_hdr_t *h, bam1_t *b) // qname q = _read_token(p); _parse_warn(p - q <= 1, "empty query name"); - _parse_err(p - q > 255, "query name too long"); + _parse_err(p - q > 252, "query name too long"); kputsn_(q, p - q, &str); - c->l_qname = p - q; + for (c->l_extranul = 0; str.l % 4 != 0; c->l_extranul++) + kputc_('\0', &str); + c->l_qname = p - q + c->l_extranul; // flag c->flag = strtol(p, &p, 0); if (*p++ != '\t') goto err_ret; // malformated flag @@ -900,7 +1228,7 @@ int sam_parse1(kstring_t *s, bam_hdr_t *h, bam1_t *b) if (!isdigit_c(*p)) ++n_cigar; if (*p++ != '\t') goto err_ret; _parse_err(n_cigar == 0, "no CIGAR operations"); - _parse_err(n_cigar >= 65536, "too many CIGAR operations"); + _parse_err(n_cigar >= 2147483647, "too many CIGAR operations"); c->n_cigar = n_cigar; _get_mem(uint32_t, &cigar, &str, c->n_cigar * sizeof(uint32_t)); for (i = 0; i < c->n_cigar; ++i, ++q) { @@ -959,8 +1287,6 @@ int sam_parse1(kstring_t *s, bam_hdr_t *h, bam1_t *b) for (i = 0; i < c->l_qseq; ++i) t[i] = q[i] - 33; } else memset(t, 0xff, c->l_qseq); // aux - // Note that (like the bam1_core_t fields) this aux data in b->data is - // stored in host endianness; so there is no byte swapping needed here. while (p < s->s + s->l) { uint8_t type; q = _read_token_aux(p); // FIXME: can be accelerated for long 'B' arrays @@ -969,6 +1295,12 @@ int sam_parse1(kstring_t *s, bam_hdr_t *h, bam1_t *b) q += 3; type = *q++; ++q; // q points to value if (type != 'Z' && type != 'H') // the only zero length acceptable fields _parse_err(p - q - 1 < 1, "incomplete aux field"); + + // Ensure str has enough space for a double + type allocated. + // This is so we can stuff bigger integers and floats directly into + // the kstring. Sorry. + _parse_err(ks_resize(&str, str.l + 16), "out of memory"); + if (type == 'A' || type == 'a' || type == 'c' || type == 'C') { kputc_('A', &str); kputc_(*q, &str); @@ -978,60 +1310,91 @@ int sam_parse1(kstring_t *s, bam_hdr_t *h, bam1_t *b) if (x >= INT8_MIN) { kputc_('c', &str); kputc_(x, &str); } else if (x >= INT16_MIN) { - int16_t y = x; - kputc_('s', &str); kputsn_((char*)&y, 2, &str); + str.s[str.l++] = 's'; + i16_to_le(x, (uint8_t *) str.s + str.l); + str.l += 2; } else { - int32_t y = x; - kputc_('i', &str); kputsn_(&y, 4, &str); + str.s[str.l++] = 'i'; + i32_to_le(x, (uint8_t *) str.s + str.l); + str.l += 4; } } else { unsigned long x = strtoul(q, &q, 10); if (x <= UINT8_MAX) { kputc_('C', &str); kputc_(x, &str); } else if (x <= UINT16_MAX) { - uint16_t y = x; - kputc_('S', &str); kputsn_(&y, 2, &str); + str.s[str.l++] = 'S'; + u16_to_le(x, (uint8_t *) str.s + str.l); + str.l += 2; } else { - uint32_t y = x; - kputc_('I', &str); kputsn_(&y, 4, &str); + str.s[str.l++] = 'I'; + u32_to_le(x, (uint8_t *) str.s + str.l); + str.l += 4; } } } else if (type == 'f') { - float x; - x = strtod(q, &q); - kputc_('f', &str); kputsn_(&x, 4, &str); + str.s[str.l++] = 'f'; + float_to_le(strtod(q, &q), (uint8_t *) str.s + str.l); + str.l += sizeof(float); } else if (type == 'd') { - double x; - x = strtod(q, &q); - kputc_('d', &str); kputsn_(&x, 8, &str); + str.s[str.l++] = 'd'; + double_to_le(strtod(q, &q), (uint8_t *) str.s + str.l); + str.l += sizeof(double); } else if (type == 'Z' || type == 'H') { _parse_err(type == 'H' && !((p-q)&1), "hex field does not have an even number of digits"); kputc_(type, &str);kputsn_(q, p - q, &str); // note that this include the trailing NULL } else if (type == 'B') { - int32_t n; + int32_t n, size; + size_t bytes; char *r; _parse_err(p - q - 1 < 3, "incomplete B-typed aux field"); type = *q++; // q points to the first ',' following the typing byte + + size = aux_type2size(type); + _parse_err_param(size <= 0 || size > 4, + "unrecognized type B:%c", type); + _parse_err(*q && *q != ',', "B aux field type not followed by ','"); + for (r = q, n = 0; *r; ++r) if (*r == ',') ++n; - kputc_('B', &str); kputc_(type, &str); kputsn_(&n, 4, &str); - // FIXME: to evaluate which is faster: a) aligned array and then memmove(); b) unaligned array; c) kputsn_() + + // Ensure space for type + values + bytes = (size_t) n * (size_t) size; + _parse_err(bytes / size != n + || ks_resize(&str, str.l + bytes + 2 + sizeof(uint32_t)), + "out of memory"); + str.s[str.l++] = 'B'; + str.s[str.l++] = type; + i32_to_le(n, (uint8_t *) str.s + str.l); + str.l += sizeof(uint32_t); + + // This ensures that q always ends up at the next comma after + // reading a number even if it's followed by junk. It + // prevents the possibility of trying to read more than n items. +#define _skip_to_comma(q, p) do { while ((q) < (p) && *(q) != ',') (q)++; } while (0) + if (type == 'c') while (q + 1 < p) { int8_t x = strtol(q + 1, &q, 0); kputc_(x, &str); } else if (type == 'C') while (q + 1 < p) { uint8_t x = strtoul(q + 1, &q, 0); kputc_(x, &str); } - else if (type == 's') while (q + 1 < p) { int16_t x = strtol(q + 1, &q, 0); kputsn_(&x, 2, &str); } - else if (type == 'S') while (q + 1 < p) { uint16_t x = strtoul(q + 1, &q, 0); kputsn_(&x, 2, &str); } - else if (type == 'i') while (q + 1 < p) { int32_t x = strtol(q + 1, &q, 0); kputsn_(&x, 4, &str); } - else if (type == 'I') while (q + 1 < p) { uint32_t x = strtoul(q + 1, &q, 0); kputsn_(&x, 4, &str); } - else if (type == 'f') while (q + 1 < p) { float x = strtod(q + 1, &q); kputsn_(&x, 4, &str); } - else _parse_err(1, "unrecognized type"); - } else _parse_err(1, "unrecognized type"); + else if (type == 's') while (q + 1 < p) { i16_to_le(strtol(q + 1, &q, 0), (uint8_t *) str.s + str.l); str.l += 2; _skip_to_comma(q, p); } + else if (type == 'S') while (q + 1 < p) { u16_to_le(strtoul(q + 1, &q, 0), (uint8_t *) str.s + str.l); str.l += 2; _skip_to_comma(q, p); } + else if (type == 'i') while (q + 1 < p) { i32_to_le(strtol(q + 1, &q, 0), (uint8_t *) str.s + str.l); str.l += 4; _skip_to_comma(q, p); } + else if (type == 'I') while (q + 1 < p) { u32_to_le(strtoul(q + 1, &q, 0), (uint8_t *) str.s + str.l); str.l += 4; _skip_to_comma(q, p); } + else if (type == 'f') while (q + 1 < p) { float_to_le(strtod(q + 1, &q), (uint8_t *) str.s + str.l); str.l += 4; _skip_to_comma(q, p); } + else _parse_err_param(1, "unrecognized type B:%c", type); + +#undef _skip_to_comma + + } else _parse_err_param(1, "unrecognized type %c", type); } b->data = (uint8_t*)str.s; b->l_data = str.l; b->m_data = str.m; + if (bam_tag2cigar(b, 1, 1) < 0) + return -2; return 0; #undef _parse_warn #undef _parse_err +#undef _parse_err_param #undef _get_mem #undef _read_token_aux #undef _read_token @@ -1055,9 +1418,12 @@ int sam_read1(htsFile *fp, bam_hdr_t *h, bam1_t *b) case cram: { int ret = cram_get_bam_seq(fp->fp.cram, &b); - return ret >= 0 - ? ret - : (cram_eof(fp->fp.cram) ? -1 : -2); + if (ret < 0) + return cram_eof(fp->fp.cram) ? -1 : -2; + + if (bam_tag2cigar(b, 1, 1) < 0) + return -2; + return ret; } case sam: { @@ -1065,17 +1431,16 @@ int sam_read1(htsFile *fp, bam_hdr_t *h, bam1_t *b) err_recover: if (fp->line.l == 0) { ret = hts_getline(fp, KS_SEP_LINE, &fp->line); - if (ret < 0) return -1; + if (ret < 0) return ret; } ret = sam_parse1(&fp->line, h, b); fp->line.l = 0; if (ret < 0) { - if (hts_verbose >= 1) - fprintf(stderr, "[W::%s] parse error at line %lld\n", __func__, (long long)fp->lineno); + hts_log_warning("Parse error at line %lld", (long long)fp->lineno); if (h->ignore_sam_err) goto err_recover; } return ret; - } + } default: abort(); @@ -1085,11 +1450,11 @@ int sam_read1(htsFile *fp, bam_hdr_t *h, bam1_t *b) int sam_format1(const bam_hdr_t *h, const bam1_t *b, kstring_t *str) { int i; - uint8_t *s; + uint8_t *s, *end; const bam1_core_t *c = &b->core; str->l = 0; - kputsn(bam_get_qname(b), c->l_qname-1, str); kputc('\t', str); // query name + kputsn(bam_get_qname(b), c->l_qname-1-c->l_extranul, str); kputc('\t', str); // query name kputw(c->flag, str); kputc('\t', str); // flag if (c->tid >= 0) { // chr kputs(h->target_name[c->tid] , str); @@ -1122,10 +1487,9 @@ int sam_format1(const bam_hdr_t *h, const bam1_t *b, kstring_t *str) else for (i = 0; i < c->l_qseq; ++i) kputc(s[i] + 33, str); } else kputsn("*\t*", 3, str); - // FIXME change "s+N <= b->data+b->l_data" to "b->data+b->l_data - s >= N" - // (or equivalent) everywhere to avoid looking past the end of the array s = bam_get_aux(b); // aux - while (s+4 <= b->data + b->l_data) { + end = b->data + b->l_data; + while (end - s >= 4) { uint8_t type, key[2]; key[0] = s[0]; key[1] = s[1]; s += 2; type = *s++; @@ -1143,71 +1507,79 @@ int sam_format1(const bam_hdr_t *h, const bam1_t *b, kstring_t *str) kputw(*(int8_t*)s, str); ++s; } else if (type == 'S') { - if (s+2 <= b->data + b->l_data) { + if (end - s >= 2) { kputsn("i:", 2, str); - kputw(*(uint16_t*)s, str); + kputuw(le_to_u16(s), str); s += 2; - } else return -1; + } else goto bad_aux; } else if (type == 's') { - if (s+2 <= b->data + b->l_data) { + if (end - s >= 2) { kputsn("i:", 2, str); - kputw(*(int16_t*)s, str); + kputw(le_to_i16(s), str); s += 2; - } else return -1; + } else goto bad_aux; } else if (type == 'I') { - if (s+4 <= b->data + b->l_data) { + if (end - s >= 4) { kputsn("i:", 2, str); - kputuw(*(uint32_t*)s, str); + kputuw(le_to_u32(s), str); s += 4; - } else return -1; + } else goto bad_aux; } else if (type == 'i') { - if (s+4 <= b->data + b->l_data) { + if (end - s >= 4) { kputsn("i:", 2, str); - kputw(*(int32_t*)s, str); + kputw(le_to_i32(s), str); s += 4; - } else return -1; + } else goto bad_aux; } else if (type == 'f') { - if (s+4 <= b->data + b->l_data) { - ksprintf(str, "f:%g", *(float*)s); + if (end - s >= 4) { + ksprintf(str, "f:%g", le_to_float(s)); s += 4; - } else return -1; + } else goto bad_aux; } else if (type == 'd') { - if (s+8 <= b->data + b->l_data) { - ksprintf(str, "d:%g", *(double*)s); + if (end - s >= 8) { + ksprintf(str, "d:%g", le_to_double(s)); s += 8; - } else return -1; + } else goto bad_aux; } else if (type == 'Z' || type == 'H') { kputc(type, str); kputc(':', str); - while (s < b->data + b->l_data && *s) kputc(*s++, str); - if (s >= b->data + b->l_data) - return -1; + while (s < end && *s) kputc(*s++, str); + if (s >= end) + goto bad_aux; ++s; } else if (type == 'B') { uint8_t sub_type = *(s++); int sub_type_size = aux_type2size(sub_type); uint32_t n; - if (sub_type_size == 0 || b->data + b->l_data - s < 4) - return -1; - memcpy(&n, s, 4); + if (sub_type_size == 0 || end - s < 4) + goto bad_aux; + n = le_to_u32(s); s += 4; // now points to the start of the array - if ((b->data + b->l_data - s) / sub_type_size < n) - return -1; + if ((end - s) / sub_type_size < n) + goto bad_aux; kputsn("B:", 2, str); kputc(sub_type, str); // write the typing for (i = 0; i < n; ++i) { // FIXME: for better performance, put the loop after "if" kputc(',', str); if ('c' == sub_type) { kputw(*(int8_t*)s, str); ++s; } else if ('C' == sub_type) { kputw(*(uint8_t*)s, str); ++s; } - else if ('s' == sub_type) { kputw(*(int16_t*)s, str); s += 2; } - else if ('S' == sub_type) { kputw(*(uint16_t*)s, str); s += 2; } - else if ('i' == sub_type) { kputw(*(int32_t*)s, str); s += 4; } - else if ('I' == sub_type) { kputuw(*(uint32_t*)s, str); s += 4; } - else if ('f' == sub_type) { ksprintf(str, "%g", *(float*)s); s += 4; } - else return -1; + else if ('s' == sub_type) { kputw(le_to_i16(s), str); s += 2; } + else if ('S' == sub_type) { kputw(le_to_u16(s), str); s += 2; } + else if ('i' == sub_type) { kputw(le_to_i32(s), str); s += 4; } + else if ('I' == sub_type) { kputuw(le_to_u32(s), str); s += 4; } + else if ('f' == sub_type) { kputd(le_to_float(s), str); s += 4; } + else goto bad_aux; // Unknown sub-type } + } else { // Unknown type + goto bad_aux; } } return str->l; + + bad_aux: + hts_log_error("Corrupted aux data for read %.*s", + b->core.l_qname, bam_get_qname(b)); + errno = EINVAL; + return -1; } int sam_write1(htsFile *fp, const bam_hdr_t *h, const bam1_t *b) @@ -1241,54 +1613,148 @@ int sam_write1(htsFile *fp, const bam_hdr_t *h, const bam1_t *b) /************************ *** Auxiliary fields *** ************************/ +#ifndef HTS_LITTLE_ENDIAN +static int aux_to_le(char type, uint8_t *out, const uint8_t *in, size_t len) { + int tsz = aux_type2size(type); + + if (tsz >= 2 && tsz <= 8 && (len & (tsz - 1)) != 0) return -1; + + switch (tsz) { + case 'H': case 'Z': case 1: // Trivial + memcpy(out, in, len); + break; + +#define aux_val_to_le(type_t, store_le) do { \ + type_t v; \ + size_t i; \ + for (i = 0; i < len; i += sizeof(type_t), out += sizeof(type_t)) { \ + memcpy(&v, in + i, sizeof(type_t)); \ + store_le(v, out); \ + } \ + } while (0) + + case 2: aux_val_to_le(uint16_t, u16_to_le); break; + case 4: aux_val_to_le(uint32_t, u32_to_le); break; + case 8: aux_val_to_le(uint64_t, u64_to_le); break; + +#undef aux_val_to_le + + case 'B': { // Recurse! + uint32_t n; + if (len < 5) return -1; + memcpy(&n, in + 1, 4); + out[0] = in[0]; + u32_to_le(n, out + 1); + return aux_to_le(in[0], out + 5, in + 5, len - 5); + } + + default: // Unknown type code + return -1; + } + + + + return 0; +} +#endif -void bam_aux_append(bam1_t *b, const char tag[2], char type, int len, const uint8_t *data) +int bam_aux_append(bam1_t *b, const char tag[2], char type, int len, const uint8_t *data) { - int ori_len = b->l_data; - b->l_data += 3 + len; - if (b->m_data < b->l_data) { - b->m_data = b->l_data; - kroundup32(b->m_data); - b->data = (uint8_t*)realloc(b->data, b->m_data); + uint32_t new_len; + + assert(b->l_data >= 0); + new_len = b->l_data + 3 + len; + if (new_len > INT32_MAX || new_len < b->l_data) goto nomem; + + if (b->m_data < new_len) { + uint32_t new_size = new_len; + uint8_t *new_data; + kroundup32(new_size); + new_data = realloc(b->data, new_size); + if (new_data == NULL) goto nomem; + b->m_data = new_size; + b->data = new_data; } - b->data[ori_len] = tag[0]; b->data[ori_len + 1] = tag[1]; - b->data[ori_len + 2] = type; - memcpy(b->data + ori_len + 3, data, len); + + b->data[b->l_data] = tag[0]; + b->data[b->l_data + 1] = tag[1]; + b->data[b->l_data + 2] = type; + +#ifdef HTS_LITTLE_ENDIAN + memcpy(b->data + b->l_data + 3, data, len); +#else + if (aux_to_le(type, b->data + b->l_data + 3, data, len) != 0) { + errno = EINVAL; + return -1; + } +#endif + + b->l_data = new_len; + + return 0; + + nomem: + errno = ENOMEM; + return -1; } -static inline uint8_t *skip_aux(uint8_t *s) +static inline uint8_t *skip_aux(uint8_t *s, uint8_t *end) { - int size = aux_type2size(*s); ++s; // skip type + int size; uint32_t n; + if (s >= end) return end; + size = aux_type2size(*s); ++s; // skip type switch (size) { case 'Z': case 'H': - while (*s) ++s; - return s + 1; + while (*s && s < end) ++s; + return s < end ? s + 1 : end; case 'B': + if (end - s < 5) return NULL; size = aux_type2size(*s); ++s; - memcpy(&n, s, 4); s += 4; + n = le_to_u32(s); + s += 4; + if (size == 0 || end - s < size * n) return NULL; return s + size * n; case 0: - abort(); - break; + return NULL; default: + if (end - s < size) return NULL; return s + size; } } uint8_t *bam_aux_get(const bam1_t *b, const char tag[2]) { - uint8_t *s; - int y = tag[0]<<8 | tag[1]; + uint8_t *s, *end, *t = (uint8_t *) tag; + uint16_t y = (uint16_t) t[0]<<8 | t[1]; s = bam_get_aux(b); - while (s < b->data + b->l_data) { - int x = (int)s[0]<<8 | s[1]; + end = b->data + b->l_data; + while (s != NULL && end - s >= 3) { + uint16_t x = (uint16_t) s[0]<<8 | s[1]; s += 2; - if (x == y) return s; - s = skip_aux(s); + if (x == y) { + // Check the tag value is valid and complete + uint8_t *e = skip_aux(s, end); + if ((*s == 'Z' || *s == 'H') && *(e - 1) != '\0') { + goto bad_aux; // Unterminated string + } + if (e != NULL) { + return s; + } else { + goto bad_aux; + } + } + s = skip_aux(s, end); } - return 0; + if (s == NULL) goto bad_aux; + errno = ENOENT; + return NULL; + + bad_aux: + hts_log_error("Corrupted aux data for read %s", bam_get_qname(b)); + errno = EINVAL; + return NULL; } // s MUST BE returned by bam_aux_get() int bam_aux_del(bam1_t *b, uint8_t *s) @@ -1297,18 +1763,36 @@ int bam_aux_del(bam1_t *b, uint8_t *s) int l_aux = bam_get_l_aux(b); aux = bam_get_aux(b); p = s - 2; - s = skip_aux(s); + s = skip_aux(s, aux + l_aux); + if (s == NULL) goto bad_aux; memmove(p, s, l_aux - (s - aux)); b->l_data -= s - p; return 0; + + bad_aux: + hts_log_error("Corrupted aux data for read %s", bam_get_qname(b)); + errno = EINVAL; + return -1; } int bam_aux_update_str(bam1_t *b, const char tag[2], int len, const char *data) { + // FIXME: This is not at all efficient! uint8_t *s = bam_aux_get(b,tag); - if (!s) return -1; + if (!s) { + if (errno == ENOENT) { // Tag doesn't exist - add a new one + return bam_aux_append(b, tag, 'Z', len, (const uint8_t *) data); + } else { // Invalid aux data, give up. + return -1; + } + } char type = *s; - if (type != 'Z') { fprintf(stderr,"bam_aux_update_str() called for type '%c' instead of 'Z'\n", type); abort(); } + if (type != 'Z') { + hts_log_error("Called bam_aux_update_str for type '%c' instead of 'Z'", type); + errno = EINVAL; + return -1; + } + bam_aux_del(b,s); s -= 2; int l_aux = bam_get_l_aux(b); @@ -1329,25 +1813,36 @@ int bam_aux_update_str(bam1_t *b, const char tag[2], int len, const char *data) return 0; } -int32_t bam_aux2i(const uint8_t *s) +static inline int64_t get_int_aux_val(uint8_t type, const uint8_t *s, + uint32_t idx) +{ + switch (type) { + case 'c': return le_to_i8(s + idx); + case 'C': return s[idx]; + case 's': return le_to_i16(s + 2 * idx); + case 'S': return le_to_u16(s + 2 * idx); + case 'i': return le_to_i32(s + 4 * idx); + case 'I': return le_to_u32(s + 4 * idx); + default: + errno = EINVAL; + return 0; + } +} + +int64_t bam_aux2i(const uint8_t *s) { int type; type = *s++; - if (type == 'c') return (int32_t)*(int8_t*)s; - else if (type == 'C') return (int32_t)*(uint8_t*)s; - else if (type == 's') return (int32_t)*(int16_t*)s; - else if (type == 'S') return (int32_t)*(uint16_t*)s; - else if (type == 'i' || type == 'I') return *(int32_t*)s; - else return 0; + return get_int_aux_val(type, s, 0); } double bam_aux2f(const uint8_t *s) { int type; type = *s++; - if (type == 'd') return *(double*)s; - else if (type == 'f') return *(float*)s; - else return 0.0; + if (type == 'd') return le_to_double(s); + else if (type == 'f') return le_to_float(s); + else return get_int_aux_val(type, s, 0); } char bam_aux2A(const uint8_t *s) @@ -1355,7 +1850,8 @@ char bam_aux2A(const uint8_t *s) int type; type = *s++; if (type == 'A') return *(char*)s; - else return 0; + errno = EINVAL; + return 0; } char *bam_aux2Z(const uint8_t *s) @@ -1363,7 +1859,38 @@ char *bam_aux2Z(const uint8_t *s) int type; type = *s++; if (type == 'Z' || type == 'H') return (char*)s; - else return 0; + errno = EINVAL; + return 0; +} + +uint32_t bam_auxB_len(const uint8_t *s) +{ + if (s[0] != 'B') { + errno = EINVAL; + return 0; + } + return le_to_u32(s + 2); +} + +int64_t bam_auxB2i(const uint8_t *s, uint32_t idx) +{ + uint32_t len = bam_auxB_len(s); + if (idx >= len) { + errno = ERANGE; + return 0; + } + return get_int_aux_val(s[1], s + 6, idx); +} + +double bam_auxB2f(const uint8_t *s, uint32_t idx) +{ + uint32_t len = bam_auxB_len(s); + if (idx >= len) { + errno = ERANGE; + return 0.0; + } + if (s[1] == 'f') return le_to_float(s + 6 + 4 * idx); + else return get_int_aux_val(s[1], s + 6, idx); } int sam_open_mode(char *mode, const char *fn, const char *format) @@ -1575,7 +2102,7 @@ static inline int resolve_cigar2(bam_pileup1_t *p, int32_t pos, cstate_t *s) uint32_t *cigar = bam_get_cigar(b); int k; // determine the current CIGAR operation -// fprintf(stderr, "%s\tpos=%d\tend=%d\t(%d,%d,%d)\n", bam_get_qname(b), pos, s->end, s->k, s->x, s->y); + //fprintf(stderr, "%s\tpos=%d\tend=%d\t(%d,%d,%d)\n", bam_get_qname(b), pos, s->end, s->k, s->x, s->y); if (s->k == -1) { // never processed if (c->n_cigar == 1) { // just one operation, save a loop if (_cop(cigar[0]) == BAM_CMATCH || _cop(cigar[0]) == BAM_CEQUAL || _cop(cigar[0]) == BAM_CDIFF) s->k = 0, s->x = c->pos, s->y = 0; @@ -1758,7 +2285,7 @@ static inline int cigar_iref2iseq_set(uint32_t **cigar, uint32_t *cigar_max, int (*cigar)++; *icig = 0; *iref += ncig; continue; } - fprintf(stderr,"todo: cigar %d\n", cig); + hts_log_error("Unexpected cigar %d", cig); assert(0); } *iseq = -1; @@ -1781,7 +2308,7 @@ static inline int cigar_iref2iseq_next(uint32_t **cigar, uint32_t *cigar_max, in if ( cig==BAM_CINS ) { (*cigar)++; *iseq += ncig; *icig = 0; continue; } if ( cig==BAM_CSOFT_CLIP ) { (*cigar)++; *iseq += ncig; *icig = 0; continue; } if ( cig==BAM_CHARD_CLIP || cig==BAM_CPAD ) { (*cigar)++; *icig = 0; continue; } - fprintf(stderr,"todo: cigar %d\n", cig); + hts_log_error("Unexpected cigar %d", cig); assert(0); } *iseq = -1; @@ -1951,7 +2478,7 @@ const bam_pileup1_t *bam_plp_next(bam_plp_t iter, int *_tid, int *_pos, int *_n_ // update iter->tid and iter->pos if (iter->head != iter->tail) { if (iter->tid > iter->head->b.core.tid) { - fprintf(stderr, "[%s] unsorted input. Pileup aborts.\n", __func__); + hts_log_error("Unsorted input. Pileup aborts"); iter->error = 1; *_n_plp = -1; return NULL; @@ -1990,12 +2517,12 @@ int bam_plp_push(bam_plp_t iter, const bam1_t *b) iter->tail->end = bam_endpos(b); iter->tail->s = g_cstate_null; iter->tail->s.end = iter->tail->end - 1; // initialize cstate_t if (b->core.tid < iter->max_tid) { - fprintf(stderr, "[bam_pileup_core] the input is not sorted (chromosomes out of order)\n"); + hts_log_error("The input is not sorted (chromosomes out of order)"); iter->error = 1; return -1; } if ((b->core.tid == iter->max_tid) && (iter->tail->beg < iter->max_pos)) { - fprintf(stderr, "[bam_pileup_core] the input is not sorted (reads out of order)\n"); + hts_log_error("The input is not sorted (reads out of order)"); iter->error = 1; return -1; } diff --git a/htslib/synced_bcf_reader.c b/htslib/synced_bcf_reader.c index a28bf72bb..8a6bbfc71 100644 --- a/htslib/synced_bcf_reader.c +++ b/htslib/synced_bcf_reader.c @@ -27,6 +27,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include #include #include #include @@ -35,6 +36,7 @@ DEALINGS IN THE SOFTWARE. */ #include "htslib/khash_str2int.h" #include "htslib/bgzf.h" #include "htslib/thread_pool.h" +#include "bcf_sr_sort.h" #define MAX_CSI_COOR 0x7fffffff // maximum indexable coordinate of .csi @@ -51,6 +53,13 @@ typedef struct _region_t } region_t; +#define BCF_SR_AUX(x) ((aux_t*)((x)->aux)) +typedef struct +{ + sr_sort_t sort; +} +aux_t; + static void _regions_add(bcf_sr_regions_t *reg, const char *chr, int start, int end); static bcf_sr_regions_t *_regions_init_string(const char *str); static int _regions_match_alleles(bcf_sr_regions_t *reg, int als_idx, bcf1_t *rec); @@ -75,10 +84,34 @@ char *bcf_sr_strerror(int errnum) return "no BGZF EOF marker; file may be truncated"; break; case no_memory: return "Out of memory"; break; + case vcf_parse_error: + return "VCF parse error"; break; + case bcf_read_error: + return "BCF read error"; break; default: return ""; } } +int bcf_sr_set_opt(bcf_srs_t *readers, bcf_sr_opt_t opt, ...) +{ + va_list args; + switch (opt) + { + case BCF_SR_REQUIRE_IDX: + readers->require_index = 1; + return 0; + + case BCF_SR_PAIR_LOGIC: + va_start(args, opt); + BCF_SR_AUX(readers)->sort.pair = va_arg(args, int); + return 0; + + default: + break; + } + return 1; +} + static int *init_filters(bcf_hdr_t *hdr, const char *filters, int *nfilters) { kstring_t str = {0,0,0}; @@ -116,7 +149,7 @@ int bcf_sr_set_regions(bcf_srs_t *readers, const char *regions, int is_file) assert( !readers->regions ); if ( readers->nreaders ) { - fprintf(stderr,"[%s:%d %s] Error: bcf_sr_set_regions() must be called before bcf_sr_add_reader()\n", __FILE__,__LINE__,__FUNCTION__); + hts_log_error("Must call bcf_sr_set_regions() before bcf_sr_add_reader()"); return -1; } readers->regions = bcf_sr_regions_init(regions,is_file,0,1,-2); @@ -187,7 +220,7 @@ int bcf_sr_add_reader(bcf_srs_t *files, const char *fname) BGZF *bgzf = hts_get_bgzfp(reader->file); if ( bgzf && bgzf_check_EOF(bgzf) == 0 ) { files->errnum = no_eof; - fprintf(stderr,"[%s] Warning: no BGZF EOF marker; file may be truncated.\n", fname); + hts_log_warning("No BGZF EOF marker; file '%s' may be truncated", fname); } if (files->p) bgzf_thread_pool(bgzf, files->p->pool, files->p->qsize); @@ -251,13 +284,13 @@ int bcf_sr_add_reader(bcf_srs_t *files, const char *fname) if ( files->streaming && files->nreaders>1 ) { files->errnum = api_usage_error; - fprintf(stderr,"[%s:%d %s] Error: %d readers, yet require_index not set\n", __FILE__,__LINE__,__FUNCTION__,files->nreaders); + hts_log_error("Must set require_index when the number of readers is greater than one"); return 0; } if ( files->streaming && files->regions ) { files->errnum = api_usage_error; - fprintf(stderr,"[%s:%d %s] Error: cannot tabix-jump in streaming mode\n", __FILE__,__LINE__,__FUNCTION__); + hts_log_error("Cannot tabix-jump in streaming mode"); return 0; } if ( !reader->header ) @@ -291,6 +324,8 @@ int bcf_sr_add_reader(bcf_srs_t *files, const char *fname) bcf_srs_t *bcf_sr_init(void) { bcf_srs_t *files = (bcf_srs_t*) calloc(1,sizeof(bcf_srs_t)); + files->aux = (aux_t*) calloc(1,sizeof(aux_t)); + bcf_sr_sort_init(&BCF_SR_AUX(files)->sort); return files; } @@ -323,12 +358,15 @@ void bcf_sr_destroy(bcf_srs_t *files) if (files->regions) bcf_sr_regions_destroy(files->regions); if (files->tmps.m) free(files->tmps.s); if (files->n_threads) bcf_sr_destroy_threads(files); + bcf_sr_sort_destroy(&BCF_SR_AUX(files)->sort); + free(files->aux); free(files); } void bcf_sr_remove_reader(bcf_srs_t *files, int i) { assert( !files->samples ); // not ready for this yet + bcf_sr_sort_remove_reader(files, &BCF_SR_AUX(files)->sort, i); bcf_sr_destroy1(&files->readers[i]); if ( i+1 < files->nreaders ) { @@ -339,59 +377,13 @@ void bcf_sr_remove_reader(bcf_srs_t *files, int i) } -/* - Removes duplicate records from the buffer. The meaning of "duplicate" is - controlled by the $collapse variable, which can cause that from multiple - lines only the first is considered and the rest is ignored. - The removal is done by setting the redundant lines' positions to -1 and - moving these lines at the end of the buffer. - */ -static void collapse_buffer(bcf_srs_t *files, bcf_sr_t *reader) -{ - int irec,jrec, has_snp=0, has_indel=0, has_any=0; - for (irec=1; irec<=reader->nbuffer; irec++) - { - bcf1_t *line = reader->buffer[irec]; - if ( line->pos != reader->buffer[1]->pos ) break; - if ( files->collapse&COLLAPSE_ANY ) - { - if ( !has_any ) has_any = 1; - else line->pos = -1; - } - int line_type = bcf_get_variant_types(line); - if ( files->collapse&COLLAPSE_SNPS && line_type&(VCF_SNP|VCF_MNP) ) - { - if ( !has_snp ) has_snp = 1; - else line->pos = -1; - } - if ( files->collapse&COLLAPSE_INDELS && line_type&VCF_INDEL ) - { - if ( !has_indel ) has_indel = 1; - else line->pos = -1; - } - } - bcf1_t *tmp; - irec = jrec = 1; - while ( irec<=reader->nbuffer && jrec<=reader->nbuffer ) - { - if ( reader->buffer[irec]->pos != -1 ) { irec++; continue; } - if ( jrec<=irec ) jrec = irec+1; - while ( jrec<=reader->nbuffer && reader->buffer[jrec]->pos==-1 ) jrec++; - if ( jrec<=reader->nbuffer ) - { - tmp = reader->buffer[irec]; reader->buffer[irec] = reader->buffer[jrec]; reader->buffer[jrec] = tmp; - } - } - reader->nbuffer = irec - 1; -} - void debug_buffer(FILE *fp, bcf_sr_t *reader) { int j; for (j=0; j<=reader->nbuffer; j++) { bcf1_t *line = reader->buffer[j]; - fprintf(fp,"\t%p\t%s%s\t%s:%d\t%s ", line,reader->fname,j==0?"*":" ",reader->header->id[BCF_DT_CTG][line->rid].key,line->pos+1,line->n_allele?line->d.allele[0]:""); + fprintf(fp,"\t%p\t%s%s\t%s:%d\t%s ", (void*)line,reader->fname,j==0?"*":" ",reader->header->id[BCF_DT_CTG][line->rid].key,line->pos+1,line->n_allele?line->d.allele[0]:""); int k; for (k=1; kn_allele; k++) fprintf(fp," %s", line->d.allele[k]); fprintf(fp,"\n"); @@ -430,7 +422,7 @@ static int _reader_seek(bcf_sr_t *reader, const char *seq, int start, int end) { if ( end>=MAX_CSI_COOR ) { - fprintf(stderr,"The coordinate is out of csi index limit: %d\n", end+1); + hts_log_error("The coordinate is out of csi index limit: %d", end+1); exit(1); } if ( reader->itr ) @@ -451,8 +443,10 @@ static int _reader_seek(bcf_sr_t *reader, const char *seq, int start, int end) if ( tid==-1 ) return -1; // the sequence not present in this file reader->itr = bcf_itr_queryi(reader->bcf_idx,tid,start,end+1); } - if ( !reader->itr ) fprintf(stderr,"Could not seek: %s:%d-%d\n",seq,start+1,end+1); - assert(reader->itr); + if (!reader->itr) { + hts_log_error("Could not seek: %s:%d-%d", seq, start + 1, end + 1); + assert(0); + } return 0; } @@ -514,27 +508,32 @@ static void _reader_fill_buffer(bcf_srs_t *files, bcf_sr_t *reader) if ( reader->file->format.format==vcf ) { if ( (ret=hts_getline(reader->file, KS_SEP_LINE, &files->tmps)) < 0 ) break; // no more lines - int ret = vcf_parse1(&files->tmps, reader->header, reader->buffer[reader->nbuffer+1]); - if ( ret<0 ) break; + ret = vcf_parse1(&files->tmps, reader->header, reader->buffer[reader->nbuffer+1]); + if ( ret<0 ) { files->errnum = vcf_parse_error; break; } } else if ( reader->file->format.format==bcf ) { - if ( (ret=bcf_read1(reader->file, reader->header, reader->buffer[reader->nbuffer+1])) < 0 ) break; // no more lines + ret = bcf_read1(reader->file, reader->header, reader->buffer[reader->nbuffer+1]); + if ( ret < -1 ) files->errnum = bcf_read_error; + if ( ret < 0 ) break; // no more lines or an error } else { - fprintf(stderr,"[%s:%d %s] fixme: not ready for this\n", __FILE__,__LINE__,__FUNCTION__); + hts_log_error("Fixme: not ready for this"); exit(1); } } else if ( reader->tbx_idx ) { if ( (ret=tbx_itr_next(reader->file, reader->tbx_idx, reader->itr, &files->tmps)) < 0 ) break; // no more lines - vcf_parse1(&files->tmps, reader->header, reader->buffer[reader->nbuffer+1]); + ret = vcf_parse1(&files->tmps, reader->header, reader->buffer[reader->nbuffer+1]); + if ( ret<0 ) { files->errnum = vcf_parse_error; break; } } else { - if ( (ret=bcf_itr_next(reader->file, reader->itr, reader->buffer[reader->nbuffer+1])) < 0 ) break; // no more lines + ret = bcf_itr_next(reader->file, reader->itr, reader->buffer[reader->nbuffer+1]); + if ( ret < -1 ) files->errnum = bcf_read_error; + if ( ret < 0 ) break; // no more lines or an error bcf_subset_format(reader->header,reader->buffer[reader->nbuffer+1]); } @@ -556,8 +555,6 @@ static void _reader_fill_buffer(bcf_srs_t *files, bcf_sr_t *reader) tbx_itr_destroy(reader->itr); reader->itr = NULL; } - if ( files->collapse && reader->nbuffer>=2 && reader->buffer[1]->pos==reader->buffer[2]->pos ) - collapse_buffer(files, reader); } /* @@ -579,85 +576,10 @@ static void _reader_shift_buffer(bcf_sr_t *reader) reader->nbuffer = 0; // no other line } -/* - * _reader_match_alleles() - from multiple buffered lines selects the one which - * corresponds best to the template line. The logic is controlled by COLLAPSE_* - * Returns 0 on success or -1 when no good matching line is found. - */ -static int _reader_match_alleles(bcf_srs_t *files, bcf_sr_t *reader, bcf1_t *tmpl) -{ - int i, irec = -1; - - // if no template given, use the first available record - if ( !tmpl ) - irec = 1; - else - { - int tmpl_type = bcf_get_variant_types(tmpl); - for (i=1; i<=reader->nbuffer; i++) - { - bcf1_t *line = reader->buffer[i]; - if ( line->pos != reader->buffer[1]->pos ) break; // done with this reader - - // Easiest case: matching by position only - if ( files->collapse&COLLAPSE_ANY ) { irec=i; break; } - - int line_type = bcf_get_variant_types(line); - - // No matter what the alleles are, as long as they are both SNPs - if ( files->collapse&COLLAPSE_SNPS && tmpl_type&VCF_SNP && line_type&VCF_SNP ) { irec=i; break; } - // ... or indels - if ( files->collapse&COLLAPSE_INDELS && tmpl_type&VCF_INDEL && line_type&VCF_INDEL ) { irec=i; break; } - - // More thorough checking: REFs must match - if ( tmpl->rlen != line->rlen ) continue; // different length - if ( !tmpl->d.allele || !line->d.allele ) continue; // one of the lines is empty, someone is swapped buffered lines?! - if ( strcmp(tmpl->d.allele[0], line->d.allele[0]) ) continue; // the strings do not match - - int ial,jal; - if ( files->collapse==COLLAPSE_NONE ) - { - // Exact match, all alleles must be identical - if ( tmpl->n_allele!=line->n_allele ) continue; // different number of alleles, skip - - int nmatch = 1; // REF has been already checked - for (ial=1; ialn_allele; ial++) - { - for (jal=1; jaln_allele; jal++) - if ( !strcmp(tmpl->d.allele[ial], line->d.allele[jal]) ) { nmatch++; break; } - } - if ( nmatch==tmpl->n_allele ) { irec=i; break; } // found: exact match - continue; - } - - if ( line->n_allele==1 && tmpl->n_allele==1 ) { irec=i; break; } // both sites are non-variant - - // COLLAPSE_SOME: at least some ALTs must match - for (ial=1; ialn_allele; ial++) - { - for (jal=1; jaln_allele; jal++) - if ( !strcmp(tmpl->d.allele[ial], line->d.allele[jal]) ) { irec=i; break; } - if ( irec>=1 ) break; - } - if ( irec>=1 ) break; - } - if ( irec==-1 ) return -1; // no matching line was found - } - - // Set the selected line (irec) as active: set it to buffer[0], move the remaining lines forward - // and put the old bcf1_t record at the end. - bcf1_t *tmp = reader->buffer[0]; - reader->buffer[0] = reader->buffer[irec]; - for (i=irec+1; i<=reader->nbuffer; i++) reader->buffer[i-1] = reader->buffer[i]; - reader->buffer[ reader->nbuffer ] = tmp; - reader->nbuffer--; - - return 0; -} - int _reader_next_line(bcf_srs_t *files) { int i, min_pos = INT_MAX; + const char *chr = NULL; // Loop until next suitable line is found or all readers have finished while ( 1 ) @@ -666,7 +588,6 @@ int _reader_next_line(bcf_srs_t *files) if ( files->regions && _readers_next_region(files)<0 ) break; // Fill buffers - const char *chr = NULL; for (i=0; inreaders; i++) { _reader_fill_buffer(files, &files->readers[i]); @@ -677,7 +598,10 @@ int _reader_next_line(bcf_srs_t *files) { min_pos = files->readers[i].buffer[1]->pos; chr = bcf_seqname(files->readers[i].header, files->readers[i].buffer[1]); + bcf_sr_sort_set_active(&BCF_SR_AUX(files)->sort, i); } + else if ( min_pos==files->readers[i].buffer[1]->pos ) + bcf_sr_sort_add_active(&BCF_SR_AUX(files)->sort, i); } if ( min_pos==INT_MAX ) { @@ -696,33 +620,16 @@ int _reader_next_line(bcf_srs_t *files) if ( files->readers[i].nbuffer && files->readers[i].buffer[1]->pos==min_pos ) _reader_shift_buffer(&files->readers[i]); min_pos = INT_MAX; + chr = NULL; continue; } } - break; // done: min_pos is set + break; // done: chr and min_pos are set } + if ( !chr ) return 0; - // There can be records with duplicate positions. Set the active line intelligently so that - // the alleles match. - int nret = 0; // number of readers sharing the position - bcf1_t *first = NULL; // record which will be used for allele matching - for (i=0; inreaders; i++) - { - files->has_line[i] = 0; - - // Skip readers with no records at this position - if ( !files->readers[i].nbuffer || files->readers[i].buffer[1]->pos!=min_pos ) continue; - - // Until now buffer[0] of all reader was empty and the lines started at buffer[1]. - // Now lines which are ready to be output will be moved to buffer[0]. - if ( _reader_match_alleles(files, &files->readers[i], first) < 0 ) continue; - if ( !first ) first = files->readers[i].buffer[0]; - - nret++; - files->has_line[i] = 1; - } - return nret; + return bcf_sr_sort_next(files, &BCF_SR_AUX(files)->sort, chr, min_pos); } int bcf_sr_next_line(bcf_srs_t *files) @@ -791,7 +698,7 @@ int bcf_sr_set_samples(bcf_srs_t *files, const char *fname, int is_file) smpl = hts_readlist(fname, is_file, &nsmpl); if ( !smpl ) { - fprintf(stderr,"Could not read the file: \"%s\"\n", fname); + hts_log_error("Could not read the file: \"%s\"", fname); return 0; } if ( exclude ) @@ -821,7 +728,8 @@ int bcf_sr_set_samples(bcf_srs_t *files, const char *fname, int is_file) } if ( n_isec!=files->nreaders ) { - fprintf(stderr,"Warning: The sample \"%s\" was not found in %s, skipping\n", smpl[i], files->readers[n_isec].fname); + hts_log_warning("The sample \"%s\" was not found in %s, skipping", + smpl[i], files->readers[n_isec].fname); continue; } @@ -839,7 +747,7 @@ int bcf_sr_set_samples(bcf_srs_t *files, const char *fname, int is_file) if ( !files->n_smpl ) { if ( files->nreaders>1 ) - fprintf(stderr,"No samples in common.\n"); + hts_log_warning("No samples in common"); return 0; } for (i=0; inreaders; i++) @@ -926,7 +834,7 @@ static bcf_sr_regions_t *_regions_init_string(const char *str) from = hts_parse_decimal(sp,(char**)&ep,0); if ( sp==ep ) { - fprintf(stderr,"[%s:%d %s] Could not parse the region(s): %s\n", __FILE__,__LINE__,__FUNCTION__,str); + hts_log_error("Could not parse the region(s): %s", str); free(reg); free(tmp.s); return NULL; } if ( !*ep || *ep==',' ) @@ -937,7 +845,7 @@ static bcf_sr_regions_t *_regions_init_string(const char *str) } if ( *ep!='-' ) { - fprintf(stderr,"[%s:%d %s] Could not parse the region(s): %s\n", __FILE__,__LINE__,__FUNCTION__,str); + hts_log_error("Could not parse the region(s): %s", str); free(reg); free(tmp.s); return NULL; } ep++; @@ -945,7 +853,7 @@ static bcf_sr_regions_t *_regions_init_string(const char *str) to = hts_parse_decimal(sp,(char**)&ep,0); if ( *ep && *ep!=',' ) { - fprintf(stderr,"[%s:%d %s] Could not parse the region(s): %s\n", __FILE__,__LINE__,__FUNCTION__,str); + hts_log_error("Could not parse the region(s): %s", str); free(reg); free(tmp.s); return NULL; } if ( sp==ep ) to = MAX_CSI_COOR-1; @@ -1037,7 +945,7 @@ bcf_sr_regions_t *bcf_sr_regions_init(const char *regions, int is_file, int ichr reg->file = hts_open(regions, "rb"); if ( !reg->file ) { - fprintf(stderr,"[%s:%d %s] Could not open file: %s\n", __FILE__,__LINE__,__FUNCTION__,regions); + hts_log_error("Could not open file: %s", regions); free(reg); return NULL; } @@ -1063,7 +971,8 @@ bcf_sr_regions_t *bcf_sr_regions_init(const char *regions, int is_file, int ichr ret = _regions_parse_line(reg->line.s, ichr,ifrom,ifrom, &chr,&chr_end,&from,&to); if ( ret<0 ) { - fprintf(stderr,"[%s:%d] Could not parse the file %s, using the columns %d,%d[,%d]\n", __FILE__,__LINE__,regions,ichr+1,ifrom+1,ito+1); + hts_log_error("Could not parse the file %s, using the columns %d,%d[,%d]", + regions,ichr+1,ifrom+1,ito+1); hts_close(reg->file); reg->file = NULL; free(reg); return NULL; } @@ -1190,7 +1099,7 @@ int bcf_sr_regions_next(bcf_sr_regions_t *reg) reg->file = hts_open(reg->fname, "r"); if ( !reg->file ) { - fprintf(stderr,"[%s:%d %s] Could not open file: %s\n", __FILE__,__LINE__,__FUNCTION__,reg->fname); + hts_log_error("Could not open file: %s", reg->fname); reg->file = NULL; bcf_sr_regions_destroy(reg); return -1; @@ -1205,7 +1114,8 @@ int bcf_sr_regions_next(bcf_sr_regions_t *reg) ret = _regions_parse_line(reg->line.s, ichr,ifrom,ito, &chr,&chr_end,&from,&to); if ( ret<0 ) { - fprintf(stderr,"[%s:%d] Could not parse the file %s, using the columns %d,%d,%d\n", __FILE__,__LINE__,reg->fname,ichr+1,ifrom+1,ito+1); + hts_log_error("Could not parse the file %s, using the columns %d,%d,%d", + reg->fname,ichr+1,ifrom+1,ito+1); return -1; } } @@ -1214,7 +1124,8 @@ int bcf_sr_regions_next(bcf_sr_regions_t *reg) *chr_end = 0; if ( khash_str2int_get(reg->seq_hash, chr, ®->iseq)<0 ) { - fprintf(stderr,"Broken tabix index? The sequence \"%s\" not in dictionary [%s]\n", chr,reg->line.s); + hts_log_error("Broken tabix index? The sequence \"%s\" not in dictionary [%s]", + chr, reg->line.s); exit(1); } *chr_end = '\t'; @@ -1229,7 +1140,7 @@ static int _regions_match_alleles(bcf_sr_regions_t *reg, int als_idx, bcf1_t *re if ( reg->regs ) { // payload is not supported for in-memory regions, switch to regidx instead in future - fprintf(stderr,"Error: Compressed and indexed targets file is required\n"); + hts_log_error("Compressed and indexed targets file is required"); exit(1); } diff --git a/htslib/tabix.1 b/htslib/tabix.1 index 6d46f791d..c28c0d00f 100644 --- a/htslib/tabix.1 +++ b/htslib/tabix.1 @@ -1,4 +1,4 @@ -.TH tabix 1 "13 September 2016" "htslib-1.3.2" "Bioinformatics tools" +.TH tabix 1 "26 January 2018" "htslib-1.7" "Bioinformatics tools" .SH NAME .PP bgzip \- Block compression/decompression utility diff --git a/htslib/tabix.c b/htslib/tabix.c index 8bd65e743..f75f2a525 100644 --- a/htslib/tabix.c +++ b/htslib/tabix.c @@ -1,7 +1,7 @@ /* tabix.c -- Generic indexer for TAB-delimited genome position files. Copyright (C) 2009-2011 Broad Institute. - Copyright (C) 2010-2012, 2014-2016 Genome Research Ltd. + Copyright (C) 2010-2012, 2014-2018 Genome Research Ltd. Author: Heng Li @@ -29,6 +29,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include #include #include #include @@ -69,7 +70,6 @@ static void error(const char *format, ...) int file_type(const char *fname) { int l = strlen(fname); - int strcasecmp(const char *s1, const char *s2); if (l>=7 && strcasecmp(fname+l-7, ".gff.gz") == 0) return IS_GFF; else if (l>=7 && strcasecmp(fname+l-7, ".bed.gz") == 0) return IS_BED; else if (l>=7 && strcasecmp(fname+l-7, ".sam.gz") == 0) return IS_SAM; @@ -171,7 +171,7 @@ static int query_regions(args_t *args, char *fname, char **regs, int nregs) hts_itr_t *itr = bcf_itr_querys(idx,hdr,regs[i]); while ( bcf_itr_next(fp, itr, rec) >=0 ) { - if ( reg_idx && !regidx_overlap(reg_idx, bcf_seqname(hdr,rec),rec->pos,rec->pos+rec->rlen-1, NULL) ) continue; + if ( reg_idx && !regidx_overlap(reg_idx, bcf_seqname(hdr,rec),rec->pos,rec->pos+rec->rlen-1, NULL) ) continue; bcf_write(out,hdr,rec); } tbx_itr_destroy(itr); @@ -366,15 +366,15 @@ static int usage(void) int main(int argc, char *argv[]) { - int c, min_shift = 0, is_force = 0, list_chroms = 0, do_csi = 0; - tbx_conf_t conf = tbx_conf_gff, *conf_ptr = NULL; + int c, detect = 1, min_shift = 0, is_force = 0, list_chroms = 0, do_csi = 0; + tbx_conf_t conf = tbx_conf_gff; char *reheader = NULL; args_t args; memset(&args,0,sizeof(args_t)); static const struct option loptions[] = { - {"help", no_argument, NULL, 'h'}, + {"help", no_argument, NULL, 2}, {"regions", required_argument, NULL, 'R'}, {"targets", required_argument, NULL, 'T'}, {"csi", no_argument, NULL, 'C'}, @@ -406,42 +406,47 @@ int main(int argc, char *argv[]) case 'h': args.print_header = 1; break; case 'H': args.print_header = 1; args.header_only = 1; break; case 'l': list_chroms = 1; break; - case '0': conf.preset |= TBX_UCSC; break; + case '0': conf.preset |= TBX_UCSC; detect = 0; break; case 'b': conf.bc = strtol(optarg,&tmp,10); if ( *tmp ) error("Could not parse argument: -b %s\n", optarg); + detect = 0; break; case 'e': conf.ec = strtol(optarg,&tmp,10); if ( *tmp ) error("Could not parse argument: -e %s\n", optarg); + detect = 0; break; - case 'c': conf.meta_char = *optarg; break; + case 'c': conf.meta_char = *optarg; detect = 0; break; case 'f': is_force = 1; break; case 'm': min_shift = strtol(optarg,&tmp,10); if ( *tmp ) error("Could not parse argument: -m %s\n", optarg); break; case 'p': - if (strcmp(optarg, "gff") == 0) conf_ptr = &tbx_conf_gff; - else if (strcmp(optarg, "bed") == 0) conf_ptr = &tbx_conf_bed; - else if (strcmp(optarg, "sam") == 0) conf_ptr = &tbx_conf_sam; - else if (strcmp(optarg, "vcf") == 0) conf_ptr = &tbx_conf_vcf; - else if (strcmp(optarg, "bcf") == 0) ; // bcf is autodetected, preset is not needed - else if (strcmp(optarg, "bam") == 0) ; // same as bcf - else error("The preset string not recognised: '%s'\n", optarg); - break; + detect = 0; + if (strcmp(optarg, "gff") == 0) conf = tbx_conf_gff; + else if (strcmp(optarg, "bed") == 0) conf = tbx_conf_bed; + else if (strcmp(optarg, "sam") == 0) conf = tbx_conf_sam; + else if (strcmp(optarg, "vcf") == 0) conf = tbx_conf_vcf; + else if (strcmp(optarg, "bcf") == 0) detect = 1; // bcf is autodetected, preset is not needed + else if (strcmp(optarg, "bam") == 0) detect = 1; // same as bcf + else error("The preset string not recognised: '%s'\n", optarg); + break; case 's': conf.sc = strtol(optarg,&tmp,10); if ( *tmp ) error("Could not parse argument: -s %s\n", optarg); + detect = 0; break; case 'S': conf.line_skip = strtol(optarg,&tmp,10); if ( *tmp ) error("Could not parse argument: -S %s\n", optarg); + detect = 0; break; case 1: printf( "tabix (htslib) %s\n" -"Copyright (C) 2016 Genome Research Ltd.\n", hts_version()); +"Copyright (C) 2018 Genome Research Ltd.\n", hts_version()); return EXIT_SUCCESS; default: return usage(); } @@ -463,14 +468,14 @@ int main(int argc, char *argv[]) char *fname = argv[optind]; int ftype = file_type(fname); - if ( !conf_ptr ) // no preset given + if ( detect ) // no preset given { - if ( ftype==IS_GFF ) conf_ptr = &tbx_conf_gff; - else if ( ftype==IS_BED ) conf_ptr = &tbx_conf_bed; - else if ( ftype==IS_SAM ) conf_ptr = &tbx_conf_sam; + if ( ftype==IS_GFF ) conf = tbx_conf_gff; + else if ( ftype==IS_BED ) conf = tbx_conf_bed; + else if ( ftype==IS_SAM ) conf = tbx_conf_sam; else if ( ftype==IS_VCF ) { - conf_ptr = &tbx_conf_vcf; + conf = tbx_conf_vcf; if ( !min_shift && do_csi ) min_shift = 14; } else if ( ftype==IS_BCF ) @@ -490,10 +495,7 @@ int main(int argc, char *argv[]) if ( min_shift!=0 && !do_csi ) do_csi = 1; if ( reheader ) - return reheader_file(fname, reheader, ftype, conf_ptr); - - if ( conf_ptr ) - conf = *conf_ptr; + return reheader_file(fname, reheader, ftype, &conf); char *suffix = ".tbi"; if ( do_csi ) suffix = ".csi"; diff --git a/htslib/tbx.c b/htslib/tbx.c index a5d0c483b..7c5c99033 100644 --- a/htslib/tbx.c +++ b/htslib/tbx.c @@ -1,6 +1,6 @@ /* tbx.c -- tabix API functions. - Copyright (C) 2009, 2010, 2012-2015 Genome Research Ltd. + Copyright (C) 2009, 2010, 2012-2015, 2017 Genome Research Ltd. Copyright (C) 2010-2012 Broad Institute. Author: Heng Li @@ -29,18 +29,20 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include #include "htslib/tbx.h" #include "htslib/bgzf.h" +#include "htslib/hts_endian.h" #include "hts_internal.h" #include "htslib/khash.h" KHASH_DECLARE(s2i, kh_cstr_t, int64_t) -tbx_conf_t tbx_conf_gff = { 0, 1, 4, 5, '#', 0 }; -tbx_conf_t tbx_conf_bed = { TBX_UCSC, 1, 2, 3, '#', 0 }; -tbx_conf_t tbx_conf_psltbl = { TBX_UCSC, 15, 17, 18, '#', 0 }; -tbx_conf_t tbx_conf_sam = { TBX_SAM, 3, 4, 0, '@', 0 }; -tbx_conf_t tbx_conf_vcf = { TBX_VCF, 1, 2, 0, '#', 0 }; +const tbx_conf_t tbx_conf_gff = { 0, 1, 4, 5, '#', 0 }; +const tbx_conf_t tbx_conf_bed = { TBX_UCSC, 1, 2, 3, '#', 0 }; +const tbx_conf_t tbx_conf_psltbl = { TBX_UCSC, 15, 17, 18, '#', 0 }; +const tbx_conf_t tbx_conf_sam = { TBX_SAM, 3, 4, 0, '@', 0 }; +const tbx_conf_t tbx_conf_vcf = { TBX_VCF, 1, 2, 0, '#', 0 }; typedef struct { int64_t beg, end; @@ -57,9 +59,17 @@ static inline int get_tid(tbx_t *tbx, const char *ss, int is_add) if (is_add) { int absent; k = kh_put(s2i, d, ss, &absent); - if (absent) { - kh_key(d, k) = strdup(ss); - kh_val(d, k) = kh_size(d) - 1; + if (absent < 0) { + return -1; // Out of memory + } else if (absent) { + char *ss_dup = strdup(ss); + if (ss_dup) { + kh_key(d, k) = ss_dup; + kh_val(d, k) = kh_size(d) - 1; + } else { + kh_del(s2i, d, k); + return -1; // Out of memory + } } } else k = kh_get(s2i, d, ss); return k == kh_end(d)? -1 : kh_val(d, k); @@ -148,7 +158,8 @@ static inline int get_intv(tbx_t *tbx, kstring_t *str, tbx_intv_t *intv, int is_ case TBX_UCSC: type = "TBX_UCSC"; break; default: type = "TBX_GENERIC"; break; } - fprintf(stderr, "[E::%s] failed to parse %s, was wrong -p [type] used?\nThe offending line was: \"%s\"\n", __func__, type, str->s); + hts_log_error("Failed to parse %s, was wrong -p [type] used?\nThe offending line was: \"%s\"", + type, str->s); return -1; } } @@ -257,7 +268,6 @@ int tbx_index_build3(const char *fn, const char *fnidx, int min_shift, int n_thr tbx_t *tbx; BGZF *fp; int ret; - if ( bgzf_is_bgzf(fn)!=1 ) { fprintf(stderr,"Not a BGZF file: %s\n", fn); return -1; } if ((fp = bgzf_open(fn, "r")) == 0) return -1; if ( n_threads ) bgzf_mt(fp, n_threads, 256); if ( !fp->is_compressed ) { bgzf_close(fp); return -1; } @@ -284,8 +294,7 @@ tbx_t *tbx_index_load2(const char *fn, const char *fnidx) tbx_t *tbx; uint8_t *meta; char *nm, *p; - uint32_t x[7]; - int l_meta, l_nm; + uint32_t l_meta, l_nm; tbx = (tbx_t*)calloc(1, sizeof(tbx_t)); tbx->idx = fnidx? hts_idx_load2(fn, fnidx) : hts_idx_load(fn, HTS_FMT_TBI); if ( !tbx->idx ) @@ -294,17 +303,35 @@ tbx_t *tbx_index_load2(const char *fn, const char *fnidx) return NULL; } meta = hts_idx_get_meta(tbx->idx, &l_meta); - if ( !meta ) - { - free(tbx); - return NULL; - } - memcpy(x, meta, 28); - memcpy(&tbx->conf, x, 24); + if ( !meta || l_meta < 28) goto invalid; + + tbx->conf.preset = le_to_i32(&meta[0]); + tbx->conf.sc = le_to_i32(&meta[4]); + tbx->conf.bc = le_to_i32(&meta[8]); + tbx->conf.ec = le_to_i32(&meta[12]); + tbx->conf.meta_char = le_to_i32(&meta[16]); + tbx->conf.line_skip = le_to_i32(&meta[20]); + l_nm = le_to_u32(&meta[24]); + if (l_nm > l_meta - 28) goto invalid; + p = nm = (char*)meta + 28; - l_nm = x[6]; - for (; p - nm < l_nm; p += strlen(p) + 1) get_tid(tbx, p, 1); + // This assumes meta is NUL-terminated, so we can merrily strlen away. + // hts_idx_load_local() assures this for us by adding a NUL on the end + // of whatever it reads. + for (; p - nm < l_nm; p += strlen(p) + 1) { + if (get_tid(tbx, p, 1) < 0) { + hts_log_error("%s", strerror(errno)); + goto fail; + } + } return tbx; + + invalid: + hts_log_error("Invalid index header for %s", fnidx ? fnidx : fn); + + fail: + tbx_destroy(tbx); + return NULL; } tbx_t *tbx_index_load(const char *fn) diff --git a/htslib/textutils.c b/htslib/textutils.c new file mode 100644 index 000000000..dc688b4a6 --- /dev/null +++ b/htslib/textutils.c @@ -0,0 +1,395 @@ +/* textutils.c -- non-bioinformatics utility routines for text etc. + + Copyright (C) 2016 Genome Research Ltd. + + Author: John Marshall + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include + +#include +#include + +#include "htslib/hfile.h" +#include "htslib/kstring.h" + +#include "hts_internal.h" + +static int dehex(char c) +{ + if (c >= 'a' && c <= 'f') return c - 'a' + 10; + else if (c >= 'A' && c <= 'F') return c - 'A' + 10; + else if (c >= '0' && c <= '9') return c - '0'; + else return -1; // Hence dehex('\0') = -1 +} + +int hts_decode_percent(char *dest, size_t *destlen, const char *s) +{ + char *d = dest; + int hi, lo; + + while (*s) { + if (*s == '%' && (hi = dehex(s[1])) >= 0 && (lo = dehex(s[2])) >= 0) { + *d++ = (hi << 4) | lo; + s += 3; + } + else *d++ = *s++; + } + + *d = '\0'; + *destlen = d - dest; + return 0; +} + +static int debase64(char c) +{ + if (c >= 'a' && c <= 'z') return c - 'a' + 26; + else if (c >= 'A' && c <= 'Z') return c - 'A'; + else if (c >= '0' && c <= '9') return c - '0' + 52; + else if (c == '/') return 63; + else if (c == '+') return 62; + else return -1; // Hence debase64('\0') = -1 +} + +size_t hts_base64_decoded_length(size_t len) +{ + size_t nquartets = (len + 2) / 4; + return 3 * nquartets; +} + +int hts_decode_base64(char *dest, size_t *destlen, const char *s) +{ + char *d = dest; + int x0, x1, x2, x3; + + while (1) { + x0 = debase64(*s++); + x1 = (x0 >= 0)? debase64(*s++) : -1; + x2 = (x1 >= 0)? debase64(*s++) : -1; + x3 = (x2 >= 0)? debase64(*s++) : -1; + if (x3 < 0) break; + + *d++ = (x0 << 2) | (x1 >> 4); + *d++ = (x1 << 4) | (x2 >> 2); + *d++ = (x2 << 6) | x3; + } + + if (x1 >= 0) *d++ = (x0 << 2) | (x1 >> 4); + if (x2 >= 0) *d++ = (x1 << 4) | (x2 >> 2); + + *destlen = d - dest; + return 0; +} + +static char *encode_utf8(char *s, unsigned x) +{ + if (x >= 0x10000) { + *s++ = 0xF0 | (x >> 18); + *s++ = 0x80 | ((x >> 12) & 0x3F); + *s++ = 0x80 | ((x >> 6) & 0x3F); + *s++ = 0x80 | (x & 0x3F); + } + else if (x >= 0x800) { + *s++ = 0xE0 | (x >> 12); + *s++ = 0x80 | ((x >> 6) & 0x3F); + *s++ = 0x80 | (x & 0x3F); + } + else if (x >= 0x80) { + *s++ = 0xC0 | (x >> 6); + *s++ = 0x80 | (x & 0x3F); + } + else *s++ = x; + + return s; +} + +static char *sscan_string(char *s) +{ + char *d = s; + int d1, d2, d3, d4; + + for (;;) switch (*s) { + case '\\': + switch (s[1]) { + case '\0': *d = '\0'; return s+1; + case 'b': *d++ = '\b'; s += 2; break; + case 'f': *d++ = '\f'; s += 2; break; + case 'n': *d++ = '\n'; s += 2; break; + case 'r': *d++ = '\r'; s += 2; break; + case 't': *d++ = '\t'; s += 2; break; + default: *d++ = s[1]; s += 2; break; + case 'u': + if ((d1 = dehex(s[2])) >= 0 && (d2 = dehex(s[3])) >= 0 && + (d3 = dehex(s[4])) >= 0 && (d4 = dehex(s[5])) >= 0) { + d = encode_utf8(d, d1 << 12 | d2 << 8 | d3 << 4 | d4); + s += 6; + } + break; + } + break; + + case '"': + *d = '\0'; + return s+1; + + case '\0': + *d = '\0'; + return s; + + default: + *d++ = *s++; + break; + } +} + +static void fscan_string(hFILE *fp, kstring_t *d) +{ + int c, d1, d2, d3, d4; + + while ((c = hgetc(fp)) != EOF) switch (c) { + case '\\': + if ((c = hgetc(fp)) == EOF) return; + switch (c) { + case 'b': kputc('\b', d); break; + case 'f': kputc('\f', d); break; + case 'n': kputc('\n', d); break; + case 'r': kputc('\r', d); break; + case 't': kputc('\t', d); break; + default: kputc(c, d); break; + case 'u': + if ((c = hgetc(fp)) != EOF && (d1 = dehex(c)) >= 0 && + (c = hgetc(fp)) != EOF && (d2 = dehex(c)) >= 0 && + (c = hgetc(fp)) != EOF && (d3 = dehex(c)) >= 0 && + (c = hgetc(fp)) != EOF && (d4 = dehex(c)) >= 0) { + char buf[8]; + char *lim = encode_utf8(buf, d1 << 12 | d2 << 8 | d3 << 4 | d4); + kputsn(buf, lim - buf, d); + } + break; + } + break; + + case '"': + return; + + default: + kputc(c, d); + break; + } +} + +static char token_type(hts_json_token *token) +{ + const char *s = token->str; + + switch (*s) { + case 'f': + return (strcmp(s, "false") == 0)? 'b' : '?'; + case 'n': + return (strcmp(s, "null") == 0)? '.' : '?'; + case 't': + return (strcmp(s, "true") == 0)? 'b' : '?'; + case '-': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return 'n'; + default: + return '?'; + } +} + +hts_json_token * hts_json_alloc_token() { + return calloc(1, sizeof(hts_json_token)); +} + +char hts_json_token_type(hts_json_token *token) { + return token->type; +} + +void hts_json_free_token(hts_json_token *token) { + free(token); +} + +char *hts_json_token_str(hts_json_token *token) { + return token->str; +} + +char hts_json_snext(char *str, size_t *state, hts_json_token *token) +{ + char *s = &str[*state >> 2]; + int hidden = *state & 3; + + if (hidden) { + *state &= ~3; + return token->type = "?}]?"[hidden]; + } + +#define STATE(s,h) (((s) - str) << 2 | (h)) + + for (;;) switch (*s) { + case ' ': + case '\t': + case '\r': + case '\n': + case ',': + case ':': + s++; + continue; + + case '\0': + return token->type = '\0'; + + case '{': + case '[': + case '}': + case ']': + *state = STATE(s+1, 0); + return token->type = *s; + + case '"': + token->str = s+1; + *state = STATE(sscan_string(s+1), 0); + return token->type = 's'; + + default: + token->str = s; + s += strcspn(s, " \t\r\n,]}"); + hidden = (*s == '}')? 1 : (*s == ']')? 2 : 0; + if (*s != '\0') *s++ = '\0'; + *state = STATE(s, hidden); + return token->type = token_type(token); + } + +#undef STATE +} + +char hts_json_fnext(struct hFILE *fp, hts_json_token *token, kstring_t *kstr) +{ + char peek; + int c; + + for (;;) switch (c = hgetc(fp)) { + case ' ': + case '\t': + case '\r': + case '\n': + case ',': + case ':': + continue; + + case EOF: + return token->type = '\0'; + + case '{': + case '[': + case '}': + case ']': + return token->type = c; + + case '"': + kstr->l = 0; + fscan_string(fp, kstr); + if (kstr->l == 0) kputsn("", 0, kstr); + token->str = kstr->s; + return token->type = 's'; + + default: + kstr->l = 0; + kputc(c, kstr); + while (hpeek(fp, &peek, 1) == 1 && !strchr(" \t\r\n,]}", peek)) { + if ((c = hgetc(fp)) == EOF) break; + kputc(c, kstr); + } + token->str = kstr->s; + return token->type = token_type(token); + } +} + + +typedef char hts_json_nextfn(void *arg1, void *arg2, hts_json_token *token); + +static char skip_value(char type, hts_json_nextfn *next, void *arg1, void *arg2) +{ + hts_json_token token; + int level; + + switch (type? type : next(arg1, arg2, &token)) { + case '\0': + return '\0'; + + case '?': + case '}': + case ']': + return '?'; + + case '{': + case '[': + level = 1; + break; + + default: + return 'v'; + } + + while (level > 0) + switch (next(arg1, arg2, &token)) { + case '\0': + return '\0'; + + case '?': + return '?'; + + case '{': + case '[': + level++; + break; + + case '}': + case ']': + --level; + break; + + default: + break; + } + + return 'v'; +} + +static char snext(void *arg1, void *arg2, hts_json_token *token) +{ + return hts_json_snext(arg1, arg2, token); +} +char hts_json_sskip_value(char *str, size_t *state, char type) +{ + return skip_value(type, snext, str, state); +} + +static char fnext(void *arg1, void *arg2, hts_json_token *token) +{ + return hts_json_fnext(arg1, token, arg2); +} +char hts_json_fskip_value(struct hFILE *fp, char type) +{ + kstring_t str = { 0, 0, NULL }; + char ret = skip_value(type, fnext, fp, &str); + free(str.s); + return ret; +} diff --git a/htslib/textutils_internal.h b/htslib/textutils_internal.h new file mode 100644 index 000000000..5edd5d293 --- /dev/null +++ b/htslib/textutils_internal.h @@ -0,0 +1,175 @@ +/* textutils_internal.h -- non-bioinformatics utility routines for text etc. + + Copyright (C) 2016,2018 Genome Research Ltd. + + Author: John Marshall + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#ifndef HTSLIB_TEXTUTILS_INTERNAL_H +#define HTSLIB_TEXTUTILS_INTERNAL_H + +/* N.B. These interfaces may be used by plug-ins */ + +#include +#include +#include "htslib/kstring.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/// Decode percent-encoded (URL-encoded) text +/** On input, _dest_ should be a buffer at least the same size as _s_, + and may be equal to _s_ to decode in place. On output, _dest_ will be + NUL-terminated and the number of characters written (not including the + NUL) is stored in _destlen_. +*/ +int hts_decode_percent(char *dest, size_t *destlen, const char *s); + +/// Return decoded data length given length of base64-encoded text +/** This gives an upper bound, as it overestimates by a byte or two when + the encoded text ends with (possibly omitted) `=` padding characters. +*/ +size_t hts_base64_decoded_length(size_t len); + +/// Decode base64-encoded data +/** On input, _dest_ should be a sufficient buffer (see `hts_base64_length()`), + and may be equal to _s_ to decode in place. On output, the number of + bytes writen is stored in _destlen_. +*/ +int hts_decode_base64(char *dest, size_t *destlen, const char *s); + +/// Token structure returned by JSON lexing functions +/** Structure is defined in hts_internal.h + */ + +typedef struct hts_json_token hts_json_token; + +/// Allocate an empty JSON token structure, for use with hts_json_* functions +/** @return An empty token on success; NULL on failure + */ +hts_json_token * hts_json_alloc_token(); + +/// Free a JSON token +void hts_json_free_token(hts_json_token *token); + +/// Accessor funtion to get JSON token type +/** @param token Pointer to JSON token + @return Character indicating the token type + +Token types correspond to scalar JSON values and selected punctuation +as follows: + - `s` string + - `n` number + - `b` boolean literal + - `.` null literal + - `{`, `}`, `[`, `]` object and array delimiters + - `?` lexing error + - `!` other errors (e.g. out of memory) + - `\0` terminator at end of input +*/ +char hts_json_token_type(hts_json_token *token); + +/// Accessor funtion to get JSON token in string form +/** @param token Pointer to JSON token + @return String representation of the JSON token; NULL if unset + +If the token was parsed from a string using hts_json_snext(), the return value +will point into the string passed as the first parameter to hts_json_snext(). +If the token was parsed from a file using hts_json_fnext(), the return value +will point at the kstring_t buffer passed as the third parameter to +hts_json_fnext(). In that case, the value will only be valid until the +next call to hts_json_fnext(). + */ +char *hts_json_token_str(hts_json_token *token); + +/// Read one JSON token from a string +/** @param str The input C string + @param state The input string state + @param token On return, filled in with the token read + @return The type of the token read + +On return, `token->str` points into the supplied input string, which +is modified by having token-terminating characters overwritten as NULs. +The `state` argument records the current position within `str` after each +`hts_json_snext()` call, and should be set to 0 before the first call. +*/ +char hts_json_snext(char *str, size_t *state, hts_json_token *token); + +/// Read and discard a complete JSON value from a string +/** @param str The input C string + @param state The input string state, as per `hts_json_snext()` + @param type If the first token of the value to be discarded has already + been read, provide its type; otherwise `'\0'` + @return One of `v` (success), `\0` (end of string), and `?` (lexing error) + +Skips a complete JSON value, which may be a single token or an entire object +or array. +*/ +char hts_json_sskip_value(char *str, size_t *state, char type); + +/// Read one JSON token from a file +/** @param fp The file stream + @param token On return, filled in with the token read + @param kstr Buffer used to store the token string returned + @return The type of the token read + +The `kstr` buffer is used to store the string value of the token read, +so `token->str` is only valid until the next time `hts_json_fnext()` is +called with the same `kstr` argument. +*/ +char hts_json_fnext(struct hFILE *fp, hts_json_token *token, kstring_t *kstr); + +/// Read and discard a complete JSON value from a file +/** @param fp The file stream + @param type If the first token of the value to be discarded has already + been read, provide its type; otherwise `'\0'` + @return One of `v` (success), `\0` (EOF), and `?` (lexing error) + +Skips a complete JSON value, which may be a single token or an entire object +or array. +*/ +char hts_json_fskip_value(struct hFILE *fp, char type); + + +// The functions operate on ints such as are returned by fgetc(), +// i.e., characters represented as unsigned-char-valued ints, or EOF. +// To operate on plain chars (and to avoid warnings on some platforms), +// technically one must cast to unsigned char everywhere (see CERT STR37-C) +// or less painfully use these *_c() functions that operate on plain chars +// (but not EOF, which must be considered separately where it is applicable). +// TODO We may eventually wish to implement these functions directly without +// using their equivalents, and thus make them immune to locales. +static inline int isalnum_c(char c) { return isalnum((unsigned char) c); } +static inline int isalpha_c(char c) { return isalpha((unsigned char) c); } +static inline int isdigit_c(char c) { return isdigit((unsigned char) c); } +static inline int isgraph_c(char c) { return isgraph((unsigned char) c); } +static inline int islower_c(char c) { return islower((unsigned char) c); } +static inline int isprint_c(char c) { return isprint((unsigned char) c); } +static inline int isspace_c(char c) { return isspace((unsigned char) c); } +static inline int isupper_c(char c) { return isupper((unsigned char) c); } +static inline char tolower_c(char c) { return tolower((unsigned char) c); } +static inline char toupper_c(char c) { return toupper((unsigned char) c); } + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/htslib/thread_pool.c b/htslib/thread_pool.c index 4119bfe9e..962b565c8 100644 --- a/htslib/thread_pool.c +++ b/htslib/thread_pool.c @@ -1,6 +1,6 @@ /* thread_pool.c -- A pool of generic worker threads - Copyright (c) 2013-2016 Genome Research Ltd. + Copyright (c) 2013-2017 Genome Research Ltd. Author: James Bonfield @@ -43,7 +43,7 @@ DEALINGS IN THE SOFTWARE. */ //#define DEBUG #ifdef DEBUG -static int worker_id(t_pool *p) { +static int worker_id(hts_tpool *p) { int i; pthread_t s = pthread_self(); for (i = 0; i < p->tsize; i++) { @@ -127,6 +127,9 @@ static void wake_next_worker(hts_tpool_process *q, int locked); static hts_tpool_result *hts_tpool_next_result_locked(hts_tpool_process *q) { hts_tpool_result *r, *last; + if (q->shutdown) + return NULL; + for (last = NULL, r = q->output_head; r; last = r, r = r->next) { if (r->serial == q->next_serial) break; @@ -239,6 +242,24 @@ int hts_tpool_process_empty(hts_tpool_process *q) { return empty; } +void hts_tpool_process_ref_incr(hts_tpool_process *q) { + pthread_mutex_lock(&q->p->pool_m); + q->ref_count++; + pthread_mutex_unlock(&q->p->pool_m); +} + +void hts_tpool_process_ref_decr(hts_tpool_process *q) { + pthread_mutex_lock(&q->p->pool_m); + if (--q->ref_count <= 0) { + pthread_mutex_unlock(&q->p->pool_m); + hts_tpool_process_destroy(q); + return; + } + + // maybe also call destroy here if needed? + pthread_mutex_unlock(&q->p->pool_m); +} + /* * Returns the number of completed jobs in the process results queue. */ @@ -671,8 +692,10 @@ hts_tpool *hts_tpool_init(int n) { w->p = p; w->idx = i; pthread_cond_init(&w->pending_c, NULL); - if (0 != pthread_create(&w->tid, NULL, tpool_worker, w)) + if (0 != pthread_create(&w->tid, NULL, tpool_worker, w)) { + pthread_mutex_unlock(&p->pool_m); return NULL; + } } pthread_mutex_unlock(&p->pool_m); @@ -720,8 +743,10 @@ int hts_tpool_dispatch2(hts_tpool *p, hts_tpool_process *q, return -1; } - if (!(j = malloc(sizeof(*j)))) + if (!(j = malloc(sizeof(*j)))) { + pthread_mutex_unlock(&p->pool_m); return -1; + } j->func = func; j->arg = arg; j->next = NULL; @@ -733,6 +758,7 @@ int hts_tpool_dispatch2(hts_tpool *p, hts_tpool_process *q, while (q->n_input >= q->qsize && !q->shutdown && !q->wake_dispatch) pthread_cond_wait(&q->input_not_full_c, &q->p->pool_m); if (q->shutdown) { + free(j); pthread_mutex_unlock(&p->pool_m); return -1; } @@ -827,7 +853,7 @@ int hts_tpool_process_flush(hts_tpool_process *q) { } /* - * Resets a process to the intial state. + * Resets a process to the initial state. * * This removes any queued up input jobs, disables any notification of * new results/output, flushes what is left and then discards any @@ -1061,7 +1087,7 @@ int test_square(int n) { // Check for results. if ((r = hts_tpool_next_result(q))) { - printf("RESULT: %d\n", *(int *)r->data); + printf("RESULT: %d\n", *(int *)hts_tpool_result_data(r)); hts_tpool_delete_result(r, 1); } if (blk == -1) { @@ -1077,7 +1103,7 @@ int test_square(int n) { hts_tpool_process_flush(q); while ((r = hts_tpool_next_result(q))) { - printf("RESULT: %d\n", *(int *)r->data); + printf("RESULT: %d\n", *(int *)hts_tpool_result_data(r)); hts_tpool_delete_result(r, 1); } @@ -1129,7 +1155,7 @@ int test_squareB(int n) { // Consume all results until we find the end-of-job marker. for(;;) { hts_tpool_result *r = hts_tpool_next_result_wait(q); - int x = *(int *)r->data; + int x = *(int *)hts_tpool_result_data(r); hts_tpool_delete_result(r, 1); if (x == -1) break; @@ -1152,7 +1178,7 @@ int test_squareB(int n) { /*----------------------------------------------------------------------------- * A simple pipeline test. - * We use a dediocated input thread that does the initial generation of job + * We use a dedicated input thread that does the initial generation of job * and dispatch, several execution steps running in a shared pool, and a * dedicated output thread that prints up the final result. It's key that our * pipeline execution stages can run independently and don't themselves have @@ -1230,7 +1256,7 @@ static void *pipe_stage1to2(void *arg) { hts_tpool_result *r; while ((r = hts_tpool_next_result_wait(o->q1))) { - pipe_job *j = (pipe_job *)r->data; + pipe_job *j = (pipe_job *)hts_tpool_result_data(r); hts_tpool_delete_result(r, 0); if (hts_tpool_dispatch(j->o->p, j->o->q2, pipe_stage2, j) != 0) pthread_exit((void *)1); @@ -1256,7 +1282,7 @@ static void *pipe_stage2to3(void *arg) { hts_tpool_result *r; while ((r = hts_tpool_next_result_wait(o->q2))) { - pipe_job *j = (pipe_job *)r->data; + pipe_job *j = (pipe_job *)hts_tpool_result_data(r); hts_tpool_delete_result(r, 0); if (hts_tpool_dispatch(j->o->p, j->o->q3, pipe_stage3, j) != 0) pthread_exit((void *)1); @@ -1280,7 +1306,7 @@ static void *pipe_output_thread(void *arg) { hts_tpool_result *r; while ((r = hts_tpool_next_result_wait(o->q3))) { - pipe_job *j = (pipe_job *)r->data; + pipe_job *j = (pipe_job *)hts_tpool_result_data(r); int eof = j->eof; printf("O %08x\n", j->x); hts_tpool_delete_result(r, 1); diff --git a/htslib/vcf.c b/htslib/vcf.c index 37ec600ca..f95ffc0e1 100644 --- a/htslib/vcf.c +++ b/htslib/vcf.c @@ -1,7 +1,7 @@ /* vcf.c -- VCF/BCF API functions. Copyright (C) 2012, 2013 Broad Institute. - Copyright (C) 2012-2016 Genome Research Ltd. + Copyright (C) 2012-2017 Genome Research Ltd. Portions copyright (C) 2014 Intel Corporation. Author: Heng Li @@ -26,18 +26,21 @@ DEALINGS IN THE SOFTWARE. */ #include -#include #include #include #include +#include #include #include +#include +#include #include "htslib/vcf.h" #include "htslib/bgzf.h" #include "htslib/tbx.h" #include "htslib/hfile.h" #include "hts_internal.h" +#include "htslib/hts_endian.h" #include "htslib/khash_str2int.h" #include "htslib/kstring.h" @@ -46,7 +49,6 @@ KHASH_MAP_INIT_STR(vdict, bcf_idinfo_t) typedef khash_t(vdict) vdict_t; #include "htslib/kseq.h" -KSTREAM_DECLARE(gzFile, gzread) uint32_t bcf_float_missing = 0x7F800001; uint32_t bcf_float_vector_end = 0x7F800002; @@ -92,7 +94,7 @@ int bcf_hdr_add_sample(bcf_hdr_t *h, const char *s) while ( !*ss && isspace_c(*ss) ) ss++; if ( !*ss ) { - fprintf(stderr,"[E::%s] Empty sample name: trailing spaces/tabs in the header line?\n", __func__); + hts_log_error("Empty sample name: trailing spaces/tabs in the header line?"); abort(); } @@ -104,11 +106,7 @@ int bcf_hdr_add_sample(bcf_hdr_t *h, const char *s) kh_val(d, k) = bcf_idinfo_def; kh_val(d, k).id = kh_size(d) - 1; } else { - if (hts_verbose >= 2) - { - fprintf(stderr, "[E::%s] Duplicated sample name '%s'\n", __func__, s); - abort(); - } + hts_log_error("Duplicated sample name '%s'", s); free(sdup); return -1; } @@ -294,7 +292,7 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len) p += 2; const char *q = p; - while ( *q && *q!='=' ) q++; + while ( *q && *q!='=' && *q != '\n' ) q++; int n = q-p; if ( *q!='=' || !n ) { *len = q-line+1; return NULL; } // wrong format @@ -310,7 +308,7 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len) hrec->value = (char*) malloc((q-p+1)*sizeof(char)); memcpy(hrec->value, p, q-p); hrec->value[q-p] = 0; - *len = q-line+1; + *len = q - line + (*q ? 1 : 0); // Skip \n but not \0 return hrec; } @@ -335,11 +333,9 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len) { // wrong format while ( *q && *q!='\n' ) q++; - kstring_t tmp = {0,0,0}; - kputsn(line,q-line,&tmp); - fprintf(stderr,"Could not parse the header line: \"%s\"\n", tmp.s); - free(tmp.s); - *len = q-line+1; + hts_log_error("Could not parse the header line: \"%.*s\"", + (int) (q - line), line); + *len = q - line + (*q ? 1 : 0); bcf_hrec_destroy(hrec); return NULL; } @@ -367,10 +363,15 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len) if ( *q=='>' ) { nopen--; q++; } } - // Skip trailing spaces - while ( *q && *q==' ' ) { q++; } + // Skip to end of line + int nonspace = 0; + p = q; + while ( *q && *q!='\n' ) { nonspace |= !isspace(*q); q++; } + if (nonspace) { + hts_log_warning("Dropped trailing junk from header line '%.*s'", (int) (q - line), line); + } - *len = q-line+1; + *len = q - line + (*q ? 1 : 0); return hrec; } @@ -381,7 +382,8 @@ static int bcf_hdr_set_idx(bcf_hdr_t *hdr, int dict_type, const char *tag, bcf_i idinfo->id = hdr->n[dict_type]++; else if ( idinfo->id < hdr->n[dict_type] && hdr->id[dict_type][idinfo->id].key ) { - fprintf(stderr,"[%s:%d %s] Conflicting IDX=%d lines in the header dictionary, the new tag is %s\n", __FILE__,__LINE__,__FUNCTION__, idinfo->id, tag); + hts_log_error("Conflicting IDX=%d lines in the header dictionary, the new tag is %s", + idinfo->id, tag); exit(1); } @@ -426,9 +428,9 @@ int bcf_hdr_register_hrec(bcf_hdr_t *hdr, bcf_hrec_t *hrec) { char *tmp = hrec->vals[idx]; idx = strtol(hrec->vals[idx], &tmp, 10); - if ( *tmp || idx < 0 ) + if ( *tmp || idx < 0 || idx >= INT_MAX - 1) { - fprintf(stderr,"[%s:%d %s] Error parsing the IDX tag, skipping.\n", __FILE__,__LINE__,__FUNCTION__); + hts_log_warning("Error parsing the IDX tag, skipping"); return 0; } } @@ -451,7 +453,8 @@ int bcf_hdr_register_hrec(bcf_hdr_t *hdr, bcf_hrec_t *hrec) // INFO/FILTER/FORMAT char *id = NULL; - int type = -1, num = -1, var = -1, idx = -1; + uint32_t type = -1, var = -1; + int num = -1, idx = -1; for (i=0; inkeys; i++) { if ( !strcmp(hrec->keys[i], "ID") ) id = hrec->vals[i]; @@ -459,9 +462,9 @@ int bcf_hdr_register_hrec(bcf_hdr_t *hdr, bcf_hrec_t *hrec) { char *tmp = hrec->vals[i]; idx = strtol(hrec->vals[i], &tmp, 10); - if ( *tmp || idx < 0 ) + if ( *tmp || idx < 0 || idx >= INT_MAX - 1) { - fprintf(stderr,"[%s:%d %s] Error parsing the IDX tag, skipping.\n", __FILE__,__LINE__,__FUNCTION__); + hts_log_warning("Error parsing the IDX tag, skipping"); return 0; } } @@ -474,7 +477,7 @@ int bcf_hdr_register_hrec(bcf_hdr_t *hdr, bcf_hrec_t *hrec) else if ( !strcmp(hrec->vals[i], "Flag") ) type = BCF_HT_FLAG; else { - if (hts_verbose >= 2) fprintf(stderr, "[E::%s] The type \"%s\" is not supported, assuming \"String\"\n", __func__, hrec->vals[i]); + hts_log_warning("The type \"%s\" is not supported, assuming \"String\"", hrec->vals[i]); type = BCF_HT_STR; } } @@ -492,14 +495,29 @@ int bcf_hdr_register_hrec(bcf_hdr_t *hdr, bcf_hrec_t *hrec) if (var != BCF_VL_FIXED) num = 0xfffff; } } - uint32_t info = (uint32_t)num<<12 | var<<8 | type<<4 | hrec->type; + if (hrec->type == BCF_HL_INFO || hrec->type == BCF_HL_FMT) { + if (type == -1) { + hts_log_warning("%s %s field has no Type defined. Assuming String", + *hrec->key == 'I' ? "An" : "A", hrec->key); + type = BCF_HT_STR; + } + if (var == -1) { + hts_log_warning("%s %s field has no Number defined. Assuming '.'", + *hrec->key == 'I' ? "An" : "A", hrec->key); + var = BCF_VL_VAR; + } + } + uint32_t info = ((((uint32_t)num) & 0xfffff)<<12 | + (var & 0xf) << 8 | + (type & 0xf) << 4 | + (((uint32_t) hrec->type) & 0xf)); if ( !id ) return 0; str = strdup(id); vdict_t *d = (vdict_t*)hdr->dict[BCF_DT_ID]; k = kh_get(vdict, d, str); - if ( k != kh_end(d) ) + if ( k != kh_end(d) ) { // already present free(str); @@ -603,7 +621,7 @@ void bcf_hdr_check_sanity(bcf_hdr_t *hdr) int id = bcf_hdr_id2int(hdr, BCF_DT_ID, "PL"); if ( bcf_hdr_idinfo_exists(hdr,BCF_HL_FMT,id) && bcf_hdr_id2length(hdr,BCF_HL_FMT,id)!=BCF_VL_G ) { - if (hts_verbose >= 2) fprintf(stderr,"[W::%s] PL should be declared as Number=G\n", __func__); + hts_log_warning("PL should be declared as Number=G"); PL_warned = 1; } } @@ -612,7 +630,7 @@ void bcf_hdr_check_sanity(bcf_hdr_t *hdr) int id = bcf_hdr_id2int(hdr, BCF_DT_ID, "GL"); if ( bcf_hdr_idinfo_exists(hdr,BCF_HL_FMT,id) && bcf_hdr_id2length(hdr,BCF_HL_FMT,id)!=BCF_VL_G ) { - if (hts_verbose >= 2) fprintf(stderr,"[W::%s] GL should be declared as Number=G\n", __func__); + hts_log_warning("GL should be declared as Number=G"); GL_warned = 1; } } @@ -620,13 +638,13 @@ void bcf_hdr_check_sanity(bcf_hdr_t *hdr) int bcf_hdr_parse(bcf_hdr_t *hdr, char *htxt) { - int len, needs_sync = 0; + int len, needs_sync = 0, done = 0; char *p = htxt; // Check sanity: "fileformat" string must come as first bcf_hrec_t *hrec = bcf_hdr_parse_line(hdr,p,&len); if ( !hrec || !hrec->key || strcasecmp(hrec->key,"fileformat") ) - fprintf(stderr, "[W::%s] The first line should be ##fileformat; is the VCF/BCF header broken?\n", __func__); + hts_log_warning("The first line should be ##fileformat; is the VCF/BCF header broken?"); needs_sync += bcf_hdr_add_hrec(hdr, hrec); // The filter PASS must appear first in the dictionary @@ -634,11 +652,39 @@ int bcf_hdr_parse(bcf_hdr_t *hdr, char *htxt) needs_sync += bcf_hdr_add_hrec(hdr, hrec); // Parse the whole header - while ( (hrec=bcf_hdr_parse_line(hdr,p,&len)) ) - { - needs_sync += bcf_hdr_add_hrec(hdr, hrec); - p += len; + do { + while (NULL != (hrec = bcf_hdr_parse_line(hdr, p, &len))) { + needs_sync += bcf_hdr_add_hrec(hdr, hrec); + p += len; + } + + // Next should be the sample line. If not, it was a malformed + // header, in which case print a warning and skip (many VCF + // operations do not really care about a few malformed lines). + // In the future we may want to add a strict mode that errors in + // this case. + if ( strncmp("#CHROM\tPOS",p,10) != 0 ) { + char *eol = strchr(p, '\n'); + if (*p != '\0') { + hts_log_warning("Could not parse header line: %.*s", + eol ? (int)(eol - p) : INT_MAX, p); + } + if (eol) { + p = eol + 1; // Try from the next line. + } else { + done = -1; // No more lines left, give up. + } + } else { + done = 1; // Sample line found + } + } while (!done); + + if (done < 0) { + // No sample line is fatal. + hts_log_error("Could not parse the header, sample line not found"); + return -1; } + int ret = bcf_hdr_parse_sample_line(hdr,p); bcf_hdr_sync(hdr); bcf_hdr_check_sanity(hdr); @@ -755,7 +801,7 @@ const char *bcf_hdr_get_version(const bcf_hdr_t *hdr) bcf_hrec_t *hrec = bcf_hdr_get_hrec(hdr, BCF_HL_GEN, "fileformat", NULL, NULL); if ( !hrec ) { - fprintf(stderr,"No version string found, assuming VCFv4.2\n"); + hts_log_warning("No version string found, assuming VCFv4.2"); return "VCFv4.2"; } return hrec->value; @@ -807,6 +853,7 @@ void bcf_hdr_destroy(bcf_hdr_t *h) { int i; khint_t k; + if (!h) return; for (i = 0; i < 3; ++i) { vdict_t *d = (vdict_t*)h->dict[i]; if (d == 0) continue; @@ -829,43 +876,51 @@ bcf_hdr_t *bcf_hdr_read(htsFile *hfp) { if (hfp->format.format == vcf) return vcf_hdr_read(hfp); + if (hfp->format.format != bcf) { + hts_log_error("Input is not detected as bcf or vcf format"); + return NULL; + } + + assert(hfp->is_bgzf); BGZF *fp = hfp->fp.bgzf; uint8_t magic[5]; bcf_hdr_t *h; h = bcf_hdr_init("r"); if (!h) { - fprintf(stderr, "[E::%s] failed to allocate bcf header\n", __func__); + hts_log_error("Failed to allocate bcf header"); return NULL; } if (bgzf_read(fp, magic, 5) != 5) { - fprintf(stderr,"[%s:%d %s] Failed to read the header (reading BCF in text mode?)\n", __FILE__,__LINE__,__FUNCTION__); + hts_log_error("Failed to read the header (reading BCF in text mode?)"); bcf_hdr_destroy(h); return NULL; } if (strncmp((char*)magic, "BCF\2\2", 5) != 0) { if (!strncmp((char*)magic, "BCF", 3)) - fprintf(stderr,"[%s:%d %s] invalid BCF2 magic string: only BCFv2.2 is supported.\n", __FILE__,__LINE__,__FUNCTION__); - else if (hts_verbose >= 2) - fprintf(stderr, "[E::%s] invalid BCF2 magic string\n", __func__); + hts_log_error("Invalid BCF2 magic string: only BCFv2.2 is supported"); + else + hts_log_error("Invalid BCF2 magic string"); bcf_hdr_destroy(h); return NULL; } - uint32_t hlen; + uint8_t buf[4]; + size_t hlen; char *htxt = NULL; - if (bgzf_read(fp, &hlen, 4) != 4) goto fail; - htxt = (char*)malloc(hlen); + if (bgzf_read(fp, buf, 4) != 4) goto fail; + hlen = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); + if (hlen >= SIZE_MAX) { errno = ENOMEM; goto fail; } + htxt = (char*)malloc(hlen + 1); if (!htxt) goto fail; if (bgzf_read(fp, htxt, hlen) != hlen) goto fail; - bcf_hdr_parse(h, htxt); // FIXME: Does this return anything meaningful? + htxt[hlen] = '\0'; // Ensure htxt is terminated + if ( bcf_hdr_parse(h, htxt) < 0 ) goto fail; free(htxt); return h; fail: - if (hts_verbose >= 2) { - fprintf(stderr, "[E::%s] failed to read BCF header\n", __func__); - } + hts_log_error("Failed to read BCF header"); free(htxt); bcf_hdr_destroy(h); return NULL; @@ -873,6 +928,10 @@ bcf_hdr_t *bcf_hdr_read(htsFile *hfp) int bcf_hdr_write(htsFile *hfp, bcf_hdr_t *h) { + if (!h) { + errno = EINVAL; + return -1; + } if ( h->dirty ) bcf_hdr_sync(h); if (hfp->format.format == vcf || hfp->format.format == text_format) return vcf_hdr_write(hfp, h); @@ -883,8 +942,9 @@ int bcf_hdr_write(htsFile *hfp, bcf_hdr_t *h) BGZF *fp = hfp->fp.bgzf; if ( bgzf_write(fp, "BCF\2\2", 5) !=5 ) return -1; - uint32_t hlen = htxt.l; - if ( bgzf_write(fp, &hlen, 4) !=4 ) return -1; + uint8_t hlen[4]; + u32_to_le(htxt.l, hlen); + if ( bgzf_write(fp, hlen, 4) !=4 ) return -1; if ( bgzf_write(fp, htxt.s, htxt.l) != htxt.l ) return -1; free(htxt.s); @@ -946,6 +1006,7 @@ void bcf_empty(bcf1_t *v) void bcf_destroy(bcf1_t *v) { + if (!v) return; bcf_empty1(v); free(v); } @@ -953,15 +1014,15 @@ void bcf_destroy(bcf1_t *v) static inline int bcf_read1_core(BGZF *fp, bcf1_t *v) { uint32_t x[8]; - int ret; + ssize_t ret; if ((ret = bgzf_read(fp, x, 32)) != 32) { if (ret == 0) return -1; return -2; } bcf_clear1(v); x[0] -= 24; // to exclude six 32-bit integers - ks_resize(&v->shared, x[0]); - ks_resize(&v->indiv, x[1]); + if (ks_resize(&v->shared, x[0]) != 0) return -2; + if (ks_resize(&v->indiv, x[1]) != 0) return -2; memcpy(v, x + 2, 16); v->n_allele = x[6]>>16; v->n_info = x[6]&0xffff; v->n_fmt = x[7]>>24; v->n_sample = x[7]&0xffffff; @@ -969,8 +1030,8 @@ static inline int bcf_read1_core(BGZF *fp, bcf1_t *v) // silent fix of broken BCFs produced by earlier versions of bcf_subset, prior to and including bd6ed8b4 if ( (!v->indiv.l || !v->n_sample) && v->n_fmt ) v->n_fmt = 0; - if (bgzf_read(fp, v->shared.s, v->shared.l) != v->shared.l) return -1; - if (bgzf_read(fp, v->indiv.s, v->indiv.l) != v->indiv.l) return -1; + if (bgzf_read(fp, v->shared.s, v->shared.l) != v->shared.l) return -2; + if (bgzf_read(fp, v->indiv.s, v->indiv.l) != v->indiv.l) return -2; return 0; } @@ -979,6 +1040,182 @@ static inline int bcf_read1_core(BGZF *fp, bcf1_t *v) #define bit_array_clear(a,i) ((a)[(i)/8] &= ~(1 << ((i)%8))) #define bit_array_test(a,i) ((a)[(i)/8] & (1 << ((i)%8))) +static int bcf_dec_typed_int1_safe(uint8_t *p, uint8_t *end, uint8_t **q, + int32_t *val) { + uint32_t v; + uint32_t t; + if (end - p < 2) return -1; + t = *p++ & 0xf; + /* Use if .. else if ... else instead of switch to force order. Assumption + is that small integers are more frequent than big ones. */ + if (t == BCF_BT_INT8) { + *q = p + 1; + *val = *(int8_t *) p; + } else if (t == BCF_BT_INT16) { + if (end - p < 2) return -1; + *q = p + 2; + v = p[0] | (p[1] << 8); + *val = v < 0x8000 ? v : -((int32_t) (0xffff - v)) - 1; + } else if (t == BCF_BT_INT32) { + if (end - p < 4) return -1; + *q = p + 4; + v = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); + *val = v < 0x80000000UL ? v : -((int32_t) (0xffffffffUL - v)) - 1; + } else { + return -1; + } + return 0; +} + +static int bcf_dec_size_safe(uint8_t *p, uint8_t *end, uint8_t **q, + int *num, int *type) { + int r; + if (p >= end) return -1; + *type = *p & 0xf; + if (*p>>4 != 15) { + *q = p + 1; + *num = *p >> 4; + return 0; + } + r = bcf_dec_typed_int1_safe(p + 1, end, q, num); + if (r) return r; + return *num >= 0 ? 0 : -1; +} + +static const char *get_type_name(int type) { + const char *types[9] = { + "null", "int (8-bit)", "int (16 bit)", "int (32 bit)", + "unknown", "float", "unknown", "char", "unknown" + }; + int t = (type >= 0 && type < 8) ? type : 8; + return types[t]; +} + +static int bcf_record_check(const bcf_hdr_t *hdr, bcf1_t *rec) { + uint8_t *ptr, *end; + size_t bytes; + uint32_t err = 0; + int type = 0; + int num = 0; + uint32_t i, reports; + const uint32_t is_integer = ((1 << BCF_BT_INT8) | + (1 << BCF_BT_INT16) | + (1 << BCF_BT_INT32)); + const uint32_t is_valid_type = (is_integer | + (1 << BCF_BT_NULL) | + (1 << BCF_BT_FLOAT) | + (1 << BCF_BT_CHAR)); + + + // Check for valid contig ID + if (rec->rid < 0 || rec->rid >= hdr->n[BCF_DT_CTG]) { + hts_log_warning("Bad BCF record: Invalid %s id %d", "CONTIG", rec->rid); + err |= BCF_ERR_CTG_INVALID; + } + + // Check ID + ptr = (uint8_t *) rec->shared.s; + end = ptr + rec->shared.l; + if (bcf_dec_size_safe(ptr, end, &ptr, &num, &type) != 0) goto bad_shared; + if (type != BCF_BT_CHAR) { + hts_log_warning("Bad BCF record: Invalid %s type %d (%s)", "ID", type, get_type_name(type)); + err |= BCF_ERR_TAG_INVALID; + } + bytes = (size_t) num << bcf_type_shift[type]; + if (end - ptr < bytes) goto bad_shared; + ptr += bytes; + + // Check REF and ALT + reports = 0; + for (i = 0; i < rec->n_allele; i++) { + if (bcf_dec_size_safe(ptr, end, &ptr, &num, &type) != 0) goto bad_shared; + if (type != BCF_BT_CHAR) { + if (!reports++ || hts_verbose >= HTS_LOG_DEBUG) + hts_log_warning("Bad BCF record: Invalid %s type %d (%s)", "REF/ALT", type, get_type_name(type)); + err |= BCF_ERR_CHAR; + } + bytes = (size_t) num << bcf_type_shift[type]; + if (end - ptr < bytes) goto bad_shared; + ptr += bytes; + } + + // Check FILTER + reports = 0; + if (bcf_dec_size_safe(ptr, end, &ptr, &num, &type) != 0) goto bad_shared; + if (num > 0) { + if (((1 << type) & is_integer) == 0) { + hts_log_warning("Bad BCF record: Invalid %s type %d (%s)", "FILTER", type, get_type_name(type)); + err |= BCF_ERR_TAG_INVALID; + } + bytes = (size_t) num << bcf_type_shift[type]; + if (end - ptr < bytes) goto bad_shared; + for (i = 0; i < num; i++) { + int32_t key = bcf_dec_int1(ptr, type, &ptr); + if (key < 0 || key >= hdr->n[BCF_DT_ID]) { + if (!reports++ || hts_verbose >= HTS_LOG_DEBUG) + hts_log_warning("Bad BCF record: Invalid %s id %d", "FILTER", key); + err |= BCF_ERR_TAG_UNDEF; + } + } + } + + // Check INFO + reports = 0; + for (i = 0; i < rec->n_info; i++) { + int32_t key = -1; + if (bcf_dec_typed_int1_safe(ptr, end, &ptr, &key) != 0) goto bad_shared; + if (key < 0 || key >= hdr->n[BCF_DT_ID]) { + if (!reports++ || hts_verbose >= HTS_LOG_DEBUG) + hts_log_warning("Bad BCF record: Invalid %s id %d", "INFO", key); + err |= BCF_ERR_TAG_UNDEF; + } + if (bcf_dec_size_safe(ptr, end, &ptr, &num, &type) != 0) goto bad_shared; + if (((1 << type) & is_valid_type) == 0) { + if (!reports++ || hts_verbose >= HTS_LOG_DEBUG) + hts_log_warning("Bad BCF record: Invalid %s type %d (%s)", "INFO", type, get_type_name(type)); + err |= BCF_ERR_TAG_INVALID; + } + bytes = (size_t) num << bcf_type_shift[type]; + if (end - ptr < bytes) goto bad_shared; + ptr += bytes; + } + + // Check FORMAT and individual information + ptr = (uint8_t *) rec->indiv.s; + end = ptr + rec->indiv.l; + reports = 0; + for (i = 0; i < rec->n_fmt; i++) { + int32_t key = -1; + if (bcf_dec_typed_int1_safe(ptr, end, &ptr, &key) != 0) goto bad_indiv; + if (key < 0 || key >= hdr->n[BCF_DT_ID]) { + if (!reports++ || hts_verbose >= HTS_LOG_DEBUG) + hts_log_warning("Bad BCF record: Invalid %s id %d", "FORMAT", key); + err |= BCF_ERR_TAG_UNDEF; + } + if (bcf_dec_size_safe(ptr, end, &ptr, &num, &type) != 0) goto bad_indiv; + if (((1 << type) & is_valid_type) == 0) { + if (!reports++ || hts_verbose >= HTS_LOG_DEBUG) + hts_log_warning("Bad BCF record: Invalid %s type %d (%s)", "FORMAT", type, get_type_name(type)); + err |= BCF_ERR_TAG_INVALID; + } + bytes = ((size_t) num << bcf_type_shift[type]) * rec->n_sample; + if (end - ptr < bytes) goto bad_indiv; + ptr += bytes; + } + + rec->errcode |= err; + + return err ? -1 : 0; + + bad_shared: + hts_log_error("Bad BCF record - shared section malformed or too short"); + return -1; + + bad_indiv: + hts_log_error("Bad BCF record - individuals section malformed or too short"); + return -1; +} + static inline uint8_t *bcf_unpack_fmt_core1(uint8_t *ptr, int n_sample, bcf_fmt_t *fmt); int bcf_subset_format(const bcf_hdr_t *hdr, bcf1_t *rec) { @@ -1025,6 +1262,7 @@ int bcf_read(htsFile *fp, const bcf_hdr_t *h, bcf1_t *v) { if (fp->format.format == vcf) return vcf_read(fp,h,v); int ret = bcf_read1_core(fp->fp.bgzf, v); + if (ret == 0) ret = bcf_record_check(h, v); if ( ret!=0 || !h->keep_samples ) return ret; return bcf_subset_format(h,v); } @@ -1107,9 +1345,9 @@ static int bcf1_sync(bcf1_t *line) else if ( line->d.shared_dirty ) { // The line was edited, update the BCF data block. - + if ( !(line->unpacked & BCF_UN_STR) ) bcf_unpack(line,BCF_UN_STR); - + // ptr_ori points to the original unchanged BCF data. uint8_t *ptr_ori = (uint8_t *) line->shared.s; @@ -1236,12 +1474,20 @@ bcf1_t *bcf_copy(bcf1_t *dst, bcf1_t *src) dst->n_info = src->n_info; dst->n_allele = src->n_allele; dst->n_fmt = src->n_fmt; dst->n_sample = src->n_sample; - dst->shared.m = dst->shared.l = src->shared.l; - dst->shared.s = (char*) malloc(dst->shared.l); + if ( dst->shared.m < src->shared.l ) + { + dst->shared.s = (char*) realloc(dst->shared.s, src->shared.l); + dst->shared.m = src->shared.l; + } + dst->shared.l = src->shared.l; memcpy(dst->shared.s,src->shared.s,dst->shared.l); - dst->indiv.m = dst->indiv.l = src->indiv.l; - dst->indiv.s = (char*) malloc(dst->indiv.l); + if ( dst->indiv.m < src->indiv.l ) + { + dst->indiv.s = (char*) realloc(dst->indiv.s, src->indiv.l); + dst->indiv.m = src->indiv.l; + } + dst->indiv.l = src->indiv.l; memcpy(dst->indiv.s,src->indiv.s,dst->indiv.l); return dst; @@ -1257,8 +1503,8 @@ int bcf_write(htsFile *hfp, bcf_hdr_t *h, bcf1_t *v) if ( h->dirty ) bcf_hdr_sync(h); if ( bcf_hdr_nsamples(h)!=v->n_sample ) { - fprintf(stderr,"[%s:%d %s] Broken VCF record, the number of columns at %s:%d does not match the number of samples (%d vs %d).\n", - __FILE__,__LINE__,__FUNCTION__,bcf_seqname(h,v),v->pos+1, v->n_sample,bcf_hdr_nsamples(h)); + hts_log_error("Broken VCF record, the number of columns at %s:%d does not match the number of samples (%d vs %d)", + bcf_seqname(h,v), v->pos+1, v->n_sample, bcf_hdr_nsamples(h)); return -1; } @@ -1271,7 +1517,7 @@ int bcf_write(htsFile *hfp, bcf_hdr_t *h, bcf1_t *v) // header. At this point, the header must have been printed, // proceeding would lead to a broken BCF file. Errors must be checked // and cleared by the caller before we can proceed. - fprintf(stderr,"[%s:%d %s] Unchecked error (%d), exiting.\n", __FILE__,__LINE__,__FUNCTION__,v->errcode); + hts_log_error("Unchecked error (%d), exiting", v->errcode); exit(1); } bcf1_sync(v); // check if the BCF record was modified @@ -1296,53 +1542,50 @@ int bcf_write(htsFile *hfp, bcf_hdr_t *h, bcf1_t *v) bcf_hdr_t *vcf_hdr_read(htsFile *fp) { kstring_t txt, *s = &fp->line; + int ret; bcf_hdr_t *h; h = bcf_hdr_init("r"); if (!h) { - fprintf(stderr, "[E::%s] failed to allocate bcf header\n", __func__); + hts_log_error("Failed to allocate bcf header"); return NULL; } txt.l = txt.m = 0; txt.s = 0; - while (hts_getline(fp, KS_SEP_LINE, s) >= 0) { + while ((ret = hts_getline(fp, KS_SEP_LINE, s)) >= 0) { if (s->l == 0) continue; if (s->s[0] != '#') { - if (hts_verbose >= 2) - fprintf(stderr, "[E::%s] no sample line\n", __func__); - free(txt.s); - bcf_hdr_destroy(h); - return NULL; + hts_log_error("No sample line"); + goto error; } if (s->s[1] != '#' && fp->fn_aux) { // insert contigs here - int dret; - gzFile f; - kstream_t *ks; - kstring_t tmp; - tmp.l = tmp.m = 0; tmp.s = 0; - f = gzopen(fp->fn_aux, "r"); - ks = ks_init(f); - while (ks_getuntil(ks, 0, &tmp, &dret) >= 0) { - int c; - kputs("##contig=fn_aux); + goto error; + } + while (tmp.l = 0, kgetline(&tmp, (kgets_func *) hgets, f) >= 0) { + char *tab = strchr(tmp.s, '\t'); + if (tab == NULL) continue; + kputs("##contig=\n", 2, &txt); - if (dret != '\n') - while ((c = ks_getc(ks)) != '\n' && c != -1); // skip the rest of the line } free(tmp.s); - ks_destroy(ks); - gzclose(f); + if (hclose(f) != 0) { + hts_log_warning("Failed to close %s", fp->fn_aux); + } } kputsn(s->s, s->l, &txt); kputc('\n', &txt); if (s->s[1] != '#') break; } + if ( ret < -1 ) goto error; if ( !txt.s ) { - fprintf(stderr,"[%s:%d %s] Could not read the header\n", __FILE__,__LINE__,__FUNCTION__); - return NULL; + hts_log_error("Could not read the header"); + goto error; } - bcf_hdr_parse(h, txt.s); + if ( bcf_hdr_parse(h, txt.s) < 0 ) goto error; // check tabix index, are all contigs listed in the header? add the missing ones tbx_t *idx = tbx_index_load(fp->fn); @@ -1368,6 +1611,11 @@ bcf_hdr_t *vcf_hdr_read(htsFile *fp) } free(txt.s); return h; + + error: + free(txt.s); + if (h) bcf_hdr_destroy(h); + return NULL; } int bcf_hdr_set(bcf_hdr_t *hdr, const char *fname) @@ -1482,7 +1730,7 @@ void bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize) { int32_t max = INT32_MIN + 1, min = INT32_MAX; int i; - if (n == 0) bcf_enc_size(s, 0, BCF_BT_NULL); + if (n <= 0) bcf_enc_size(s, 0, BCF_BT_NULL); else if (n == 1) bcf_enc_int1(s, a[0]); else { if (wsize <= 0) wsize = n; @@ -1498,29 +1746,57 @@ void bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize) else if ( a[i]==bcf_int32_missing ) kputc(bcf_int8_missing, s); else kputc(a[i], s); } else if (max <= INT16_MAX && min > bcf_int16_vector_end) { + uint8_t *p; bcf_enc_size(s, wsize, BCF_BT_INT16); + ks_resize(s, s->l + n * sizeof(int16_t)); + p = (uint8_t *) s->s + s->l; for (i = 0; i < n; ++i) { int16_t x; if ( a[i]==bcf_int32_vector_end ) x = bcf_int16_vector_end; else if ( a[i]==bcf_int32_missing ) x = bcf_int16_missing; else x = a[i]; - kputsn((char*)&x, 2, s); + i16_to_le(x, p); + p += sizeof(int16_t); } + s->l += n * sizeof(int16_t); } else { + uint8_t *p; bcf_enc_size(s, wsize, BCF_BT_INT32); + ks_resize(s, s->l + n * sizeof(int32_t)); + p = (uint8_t *) s->s + s->l; for (i = 0; i < n; ++i) { - int32_t x = a[i]; - kputsn((char*)&x, 4, s); + i32_to_le(a[i], p); + p += sizeof(int32_t); } + s->l += n * sizeof(int32_t); } } } +static inline int serialize_float_array(kstring_t *s, size_t n, const float *a) { + uint8_t *p; + size_t i; + size_t bytes = n * sizeof(float); + + if (bytes / sizeof(float) != n) return -1; + if (ks_resize(s, s->l + bytes) < 0) return -1; + + p = (uint8_t *) s->s + s->l; + for (i = 0; i < n; i++) { + float_to_le(a[i], p); + p += sizeof(float); + } + s->l += bytes; + + return 0; +} + void bcf_enc_vfloat(kstring_t *s, int n, float *a) { + assert(n >= 0); bcf_enc_size(s, n, BCF_BT_FLOAT); - kputsn((char*)a, n << 2, s); + serialize_float_array(s, n, a); } void bcf_enc_vchar(kstring_t *s, int l, const char *a) @@ -1547,10 +1823,11 @@ void bcf_fmt_array(kstring_t *s, int n, int type, void *data) } else { - #define BRANCH(type_t, is_missing, is_vector_end, kprint) { \ - type_t *p = (type_t *) data; \ - for (j=0; js + s->l; if ( q>=end ) { - fprintf(stderr,"[%s:%d %s] Error: FORMAT column with no sample columns starting at %s:%d\n", __FILE__,__LINE__,__FUNCTION__,s->s,v->pos+1); + hts_log_error("FORMAT column with no sample columns starting at %s:%d", s->s, v->pos+1); return -1; } @@ -1629,7 +1906,8 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p for (j = 0, t = kstrtok(p, ":", &aux1); t; t = kstrtok(0, 0, &aux1), ++j) { if (j >= MAX_N_FMT) { v->errcode |= BCF_ERR_LIMITS; - fprintf(stderr,"[E::%s] Error: FORMAT column at %s:%d lists more identifiers than htslib can handle.\n", __func__, bcf_seqname(h,v), v->pos+1); + hts_log_error("FORMAT column at %s:%d lists more identifiers than htslib can handle", + bcf_seqname(h,v), v->pos+1); return -1; } @@ -1638,11 +1916,11 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p if (k == kh_end(d) || kh_val(d, k).info[BCF_HL_FMT] == 15) { if ( t[0]=='.' && t[1]==0 ) { - fprintf(stderr, "[E::%s] Invalid FORMAT tag name '.'\n", __func__); + hts_log_error("Invalid FORMAT tag name '.'"); v->errcode |= BCF_ERR_TAG_INVALID; return -1; } - if (hts_verbose >= 2) fprintf(stderr, "[W::%s] FORMAT '%s' is not defined in the header, assuming Type=String\n", __func__, t); + hts_log_warning("FORMAT '%s' is not defined in the header, assuming Type=String", t); kstring_t tmp = {0,0,0}; int l; ksprintf(&tmp, "##FORMAT=", t); @@ -1652,7 +1930,7 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p k = kh_get(vdict, d, t); v->errcode = BCF_ERR_TAG_UNDEF; if (k == kh_end(d)) { - fprintf(stderr, "[E::%s] Could not add dummy header for FORMAT '%s'\n", __func__, t); + hts_log_error("Could not add dummy header for FORMAT '%s'", t); v->errcode |= BCF_ERR_TAG_INVALID; return -1; } @@ -1692,13 +1970,14 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p if (fmt[j].max_l < l) fmt[j].max_l = l; if (fmt[j].is_gt && fmt[j].max_g < g) fmt[j].max_g = g; l = 0, m = g = 1; - if ( *r==':' ) + if ( *r==':' ) { j++; - if ( j>=v->n_fmt ) - { - fprintf(stderr,"Incorrect number of FORMAT fields at %s:%d\n", h->id[BCF_DT_CTG][v->rid].key,v->pos+1); - exit(1); + if ( j>=v->n_fmt ) + { + hts_log_error("Incorrect number of FORMAT fields at %s:%d", + h->id[BCF_DT_CTG][v->rid].key, v->pos+1); + exit(1); } } else break; @@ -1723,7 +2002,7 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p f->size = f->max_m << 2; } else { - fprintf(stderr, "[E::%s] the format type %d currently not supported\n", __func__, f->y>>4&0xf); + hts_log_error("The format type %d is currently not supported", f->y>>4&0xf); abort(); // I do not know how to do with Flag in the genotype fields } align_mem(mem); @@ -1802,7 +2081,8 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p } else { char buffer[8]; - fprintf(stderr,"[E::%s] Invalid character '%s' in '%s' FORMAT field at %s:%d\n", __FUNCTION__, dump_char(buffer, *t), h->id[BCF_DT_ID][z->key].key, bcf_seqname(h,v), v->pos+1); + hts_log_error("Invalid character '%s' in '%s' FORMAT field at %s:%d", + dump_char(buffer, *t), h->id[BCF_DT_ID][z->key].key, bcf_seqname(h,v), v->pos+1); v->errcode |= BCF_ERR_CHAR; return -1; } @@ -1848,22 +2128,26 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p bcf_enc_vint(str, (z->size>>2) * v->n_sample, (int32_t*)z->buf, z->size>>2); } else { bcf_enc_size(str, z->size>>2, BCF_BT_FLOAT); - kputsn((char*)z->buf, z->size * v->n_sample, str); + if (serialize_float_array(str, (z->size>>2) * v->n_sample, + (float *) z->buf) != 0) { + v->errcode |= BCF_ERR_LIMITS; + hts_log_error("Out of memory"); + return -1; + } } } } if ( v->n_sample!=bcf_hdr_nsamples(h) ) { - fprintf(stderr,"[%s:%d %s] Number of columns at %s:%d does not match the number of samples (%d vs %d).\n", - __FILE__,__LINE__,__FUNCTION__,bcf_seqname(h,v),v->pos+1, v->n_sample,bcf_hdr_nsamples(h)); + hts_log_error("Number of columns at %s:%d does not match the number of samples (%d vs %d)", + bcf_seqname(h,v), v->pos+1, v->n_sample, bcf_hdr_nsamples(h)); v->errcode |= BCF_ERR_NCOLS; return -1; } if ( v->indiv.l > 0xffffffff ) { - fprintf(stderr,"[%s:%d %s] The FORMAT at %s:%d is too long...\n", - __FILE__,__LINE__,__FUNCTION__,bcf_seqname(h,v),v->pos+1); + hts_log_error("The FORMAT at %s:%d is too long", bcf_seqname(h,v), v->pos+1); v->errcode |= BCF_ERR_LIMITS; // Error recovery: return -1 if this is a critical error or 0 if we want to ignore the FORMAT and proceed @@ -1881,6 +2165,15 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v) kstring_t *str; khint_t k; ks_tokaux_t aux; + int max_n_flt = 0, max_n_val = 0; + int32_t *flt_a = NULL, *val_a = NULL; + int ret = -1; + + if (!s || !h || !v || !(s->s)) + return ret; + + // Assumed in lots of places, but we may as well spot this early + assert(sizeof(float) == sizeof(int32_t)); bcf_clear1(v); str = &v->shared; @@ -1895,7 +2188,7 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v) { // Simple error recovery for chromosomes not defined in the header. It will not help when VCF header has // been already printed, but will enable tools like vcfcheck to proceed. - if (hts_verbose >= 2) fprintf(stderr, "[W::%s] contig '%s' is not defined in the header. (Quick workaround: index the file with tabix.)\n", __func__, p); + hts_log_warning("Contig '%s' is not defined in the header. (Quick workaround: index the file with tabix.)", p); kstring_t tmp = {0,0,0}; int l; ksprintf(&tmp, "##contig=", p); @@ -1905,9 +2198,9 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v) k = kh_get(vdict, d, p); v->errcode = BCF_ERR_CTG_UNDEF; if (k == kh_end(d)) { - fprintf(stderr, "[E::%s] Could not add dummy header for contig '%s'\n", __func__, p); + hts_log_error("Could not add dummy header for contig '%s'", p); v->errcode |= BCF_ERR_CTG_INVALID; - return -1; + goto err; } } v->rid = kh_val(d, k).id; @@ -1932,11 +2225,10 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v) } } else if (i == 5) { // QUAL if (strcmp(p, ".")) v->qual = atof(p); - else memcpy(&v->qual, &bcf_float_missing, 4); - if ( v->max_unpack && !(v->max_unpack>>1) ) return 0; // BCF_UN_STR + else bcf_float_set_missing(v->qual); + if ( v->max_unpack && !(v->max_unpack>>1) ) goto end; // BCF_UN_STR } else if (i == 6) { // FILTER if (strcmp(p, ".")) { - int32_t *a; int n_flt = 1, i; ks_tokaux_t aux1; vdict_t *d = (vdict_t*)h->dict[BCF_DT_ID]; @@ -1944,7 +2236,16 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v) if (*(q-1) == ';') *(q-1) = 0; for (r = p; *r; ++r) if (*r == ';') ++n_flt; - a = (int32_t*)alloca(n_flt * sizeof(int32_t)); + if (n_flt > max_n_flt) { + int32_t *a = realloc(flt_a, n_flt * sizeof(int32_t)); + if (!a) { + hts_log_error("Could not allocate memory"); + v->errcode |= BCF_ERR_LIMITS; // No appropriate code? + goto err; + } + max_n_flt = n_flt; + flt_a = a; + } // add filters for (t = kstrtok(p, ";", &aux1), i = 0; t; t = kstrtok(0, 0, &aux1)) { *(char*)aux1.p = 0; @@ -1953,7 +2254,7 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v) { // Simple error recovery for FILTERs not defined in the header. It will not help when VCF header has // been already printed, but will enable tools like vcfcheck to proceed. - if (hts_verbose >= 2) fprintf(stderr, "[W::%s] FILTER '%s' is not defined in the header\n", __func__, t); + hts_log_warning("FILTER '%s' is not defined in the header", t); kstring_t tmp = {0,0,0}; int l; ksprintf(&tmp, "##FILTER=", t); @@ -1963,17 +2264,17 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v) k = kh_get(vdict, d, t); v->errcode = BCF_ERR_TAG_UNDEF; if (k == kh_end(d)) { - fprintf(stderr, "[E::%s] Could not add dummy header for FILTER '%s'\n", __func__, t); + hts_log_error("Could not add dummy header for FILTER '%s'", t); v->errcode |= BCF_ERR_TAG_INVALID; - return -1; + goto err; } } - a[i++] = kh_val(d, k).id; + flt_a[i++] = kh_val(d, k).id; } n_flt = i; - bcf_enc_vint(str, n_flt, a, -1); + bcf_enc_vint(str, n_flt, flt_a, -1); } else bcf_enc_vint(str, 0, 0, -1); - if ( v->max_unpack && !(v->max_unpack>>2) ) return 0; // BCF_UN_FLT + if ( v->max_unpack && !(v->max_unpack>>2) ) goto end; // BCF_UN_FLT } else if (i == 7) { // INFO char *key; vdict_t *d = (vdict_t*)h->dict[BCF_DT_ID]; @@ -1995,7 +2296,7 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v) k = kh_get(vdict, d, key); if (k == kh_end(d) || kh_val(d, k).info[BCF_HL_INFO] == 15) { - if (hts_verbose >= 2) fprintf(stderr, "[W::%s] INFO '%s' is not defined in the header, assuming Type=String\n", __func__, key); + hts_log_warning("INFO '%s' is not defined in the header, assuming Type=String", key); kstring_t tmp = {0,0,0}; int l; ksprintf(&tmp, "##INFO=", key); @@ -2005,9 +2306,9 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v) k = kh_get(vdict, d, key); v->errcode = BCF_ERR_TAG_UNDEF; if (k == kh_end(d)) { - fprintf(stderr, "[E::%s] Could not add dummy header for INFO '%s'\n", __func__, key); + hts_log_error("Could not add dummy header for INFO '%s'", key); v->errcode |= BCF_ERR_TAG_INVALID; - return -1; + goto err; } } uint32_t y = kh_val(d, k).info[BCF_HL_INFO]; @@ -2022,35 +2323,44 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v) char *t, *te; for (t = val, n_val = 1; *t; ++t) // count the number of values if (*t == ',') ++n_val; - if ((y>>4&0xf) == BCF_HT_INT) { + // Check both int and float size in one step for simplicity + if (n_val > max_n_val) { int32_t *z; - z = (int32_t*)alloca(n_val * sizeof(int32_t)); + z = (int32_t *)realloc((void *)val_a, n_val * sizeof(*z)); + if (!z) { + hts_log_error("Could not allocate memory"); + v->errcode |= BCF_ERR_LIMITS; // No appropriate code? + goto err; + } + max_n_val = n_val; + val_a = z; + } + if ((y>>4&0xf) == BCF_HT_INT) { for (i = 0, t = val; i < n_val; ++i, ++t) { - z[i] = strtol(t, &te, 10); + val_a[i] = strtol(t, &te, 10); if ( te==t ) // conversion failed { - z[i] = bcf_int32_missing; + val_a[i] = bcf_int32_missing; while ( *te && *te!=',' ) te++; } t = te; } - bcf_enc_vint(str, n_val, z, -1); - if (strcmp(key, "END") == 0) v->rlen = z[0] - v->pos; + bcf_enc_vint(str, n_val, val_a, -1); + if (strcmp(key, "END") == 0) v->rlen = val_a[0] - v->pos; } else if ((y>>4&0xf) == BCF_HT_REAL) { - float *z; - z = (float*)alloca(n_val * sizeof(float)); + float *val_f = (float *)val_a; for (i = 0, t = val; i < n_val; ++i, ++t) { - z[i] = strtod(t, &te); + val_f[i] = strtod(t, &te); if ( te==t ) // conversion failed { - bcf_float_set_missing(z[i]); + bcf_float_set_missing(val_f[i]); while ( *te && *te!=',' ) te++; } t = te; } - bcf_enc_vfloat(str, n_val, z); + bcf_enc_vfloat(str, n_val, val_f); } } if (c == 0) break; @@ -2058,18 +2368,28 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v) key = r + 1; } } - if ( v->max_unpack && !(v->max_unpack>>3) ) return 0; - } else if (i == 8) // FORMAT + if ( v->max_unpack && !(v->max_unpack>>3) ) goto end; + } else if (i == 8) {// FORMAT + free(flt_a); + free(val_a); return vcf_parse_format(s, h, v, p, q); + } } - return 0; + + end: + ret = 0; + + err: + free(flt_a); + free(val_a); + return ret; } int vcf_read(htsFile *fp, const bcf_hdr_t *h, bcf1_t *v) { int ret; ret = hts_getline(fp, KS_SEP_LINE, &fp->line); - if (ret < 0) return -1; + if (ret < 0) return ret; return vcf_parse1(&fp->line, h, v); } @@ -2098,9 +2418,9 @@ static inline uint8_t *bcf_unpack_info_core1(uint8_t *ptr, bcf_info_t *info) info->v1.i = 0; if (info->len == 1) { if (info->type == BCF_BT_INT8 || info->type == BCF_BT_CHAR) info->v1.i = *(int8_t*)ptr; - else if (info->type == BCF_BT_INT32) info->v1.i = *(int32_t*)ptr; - else if (info->type == BCF_BT_FLOAT) info->v1.f = *(float*)ptr; - else if (info->type == BCF_BT_INT16) info->v1.i = *(int16_t*)ptr; + else if (info->type == BCF_BT_INT32) info->v1.i = le_to_i32(ptr); + else if (info->type == BCF_BT_FLOAT) info->v1.f = le_to_float(ptr); + else if (info->type == BCF_BT_INT16) info->v1.i = le_to_i16(ptr); } ptr += info->len << bcf_type_shift[info->type]; info->vptr_len = ptr - info->vptr; @@ -2111,7 +2431,7 @@ int bcf_unpack(bcf1_t *b, int which) { if ( !b->shared.l ) return 0; // Building a new BCF record from scratch uint8_t *ptr = (uint8_t*)b->shared.s, *ptr_ori; - int *offset, i; + int i; bcf_dec_t *d = &b->d; if (which & BCF_UN_FLT) which |= BCF_UN_STR; if (which & BCF_UN_INFO) which |= BCF_UN_SHR; @@ -2128,20 +2448,20 @@ int bcf_unpack(bcf1_t *b, int which) d->id = tmp.s; d->m_id = tmp.m; // REF and ALT are in a single block (d->als) and d->alleles are pointers into this block + hts_expand(char*, b->n_allele, d->m_allele, d->allele); // NM: hts_expand() is a macro tmp.l = 0; tmp.s = d->als; tmp.m = d->m_als; - offset = (int*)alloca(b->n_allele * sizeof(int)); ptr_ori = ptr; + char *o = ""; for (i = 0; i < b->n_allele; ++i) { - offset[i] = tmp.l; + d->allele[i] = o + tmp.l; ptr = bcf_fmt_sized_array(&tmp, ptr); kputc('\0', &tmp); } b->unpack_size[1] = ptr - ptr_ori; d->als = tmp.s; d->m_als = tmp.m; - hts_expand(char*, b->n_allele, d->m_allele, d->allele); // NM: hts_expand() is a macro for (i = 0; i < b->n_allele; ++i) - d->allele[i] = d->als + offset[i]; + d->allele[i] = d->als + (d->allele[i]-o); b->unpacked |= BCF_UN_STR; } if ((which&BCF_UN_FLT) && !(b->unpacked&BCF_UN_FLT)) { // FILTER @@ -2195,7 +2515,7 @@ int vcf_format(const bcf_hdr_t *h, const bcf1_t *v, kstring_t *s) } else kputc('.', s); kputc('\t', s); // QUAL if ( bcf_float_is_missing(v->qual) ) kputc('.', s); // QUAL - else ksprintf(s, "%g", v->qual); + else kputd(v->qual, s); kputc('\t', s); // FILTER if (v->d.n_flt) { for (i = 0; i < v->d.n_flt; ++i) { @@ -2211,19 +2531,24 @@ int vcf_format(const bcf_hdr_t *h, const bcf1_t *v, kstring_t *s) if ( !z->vptr ) continue; if ( !first ) kputc(';', s); first = 0; + if (z->key >= h->n[BCF_DT_ID]) { + hts_log_error("Invalid BCF, the INFO index is too large"); + errno = EINVAL; + return -1; + } kputs(h->id[BCF_DT_ID][z->key].key, s); if (z->len <= 0) continue; kputc('=', s); - if (z->len == 1) + if (z->len == 1) { - switch (z->type) + switch (z->type) { case BCF_BT_INT8: if ( z->v1.i==bcf_int8_missing ) kputc('.', s); else kputw(z->v1.i, s); break; case BCF_BT_INT16: if ( z->v1.i==bcf_int16_missing ) kputc('.', s); else kputw(z->v1.i, s); break; case BCF_BT_INT32: if ( z->v1.i==bcf_int32_missing ) kputc('.', s); else kputw(z->v1.i, s); break; - case BCF_BT_FLOAT: if ( bcf_float_is_missing(z->v1.f) ) kputc('.', s); else ksprintf(s, "%g", z->v1.f); break; + case BCF_BT_FLOAT: if ( bcf_float_is_missing(z->v1.f) ) kputc('.', s); else kputd(z->v1.f, s); break; case BCF_BT_CHAR: kputc(z->v1.i, s); break; - default: fprintf(stderr,"todo: type %d\n", z->type); exit(1); break; + default: hts_log_error("Unexpected type %d", z->type); exit(1); break; } } else bcf_fmt_array(s, z->len, z->type, z->vptr); @@ -2244,7 +2569,7 @@ int vcf_format(const bcf_hdr_t *h, const bcf1_t *v, kstring_t *s) kputc(!first ? ':' : '\t', s); first = 0; if ( fmt[i].id<0 ) //!bcf_hdr_idinfo_exists(h,BCF_HL_FMT,fmt[i].id) ) { - fprintf(stderr, "[E::%s] invalid BCF, the FORMAT tag id=%d not present in the header.\n", __func__, fmt[i].id); + hts_log_error("Invalid BCF, the FORMAT tag id=%d not present in the header", fmt[i].id); abort(); } kputs(h->id[BCF_DT_ID][fmt[i].id].key, s); @@ -2290,7 +2615,8 @@ int vcf_write(htsFile *fp, const bcf_hdr_t *h, bcf1_t *v) { int ret; fp->line.l = 0; - vcf_format1(h, v, &fp->line); + if (vcf_format1(h, v, &fp->line) != 0) + return -1; if ( fp->format.compression!=no_compression ) ret = bgzf_write(fp->fp.bgzf, fp->line.s, fp->line.l); else @@ -2318,10 +2644,11 @@ int bcf_hdr_id2int(const bcf_hdr_t *h, int which, const char *id) hts_idx_t *bcf_index(htsFile *fp, int min_shift) { int n_lvls, i; - bcf1_t *b; - hts_idx_t *idx; + bcf1_t *b = NULL; + hts_idx_t *idx = NULL; bcf_hdr_t *h; int64_t max_len = 0, s; + int r; h = bcf_hdr_read(fp); if ( !h ) return NULL; int nids = 0; @@ -2335,21 +2662,25 @@ hts_idx_t *bcf_index(htsFile *fp, int min_shift) max_len += 256; for (n_lvls = 0, s = 1< s; ++n_lvls, s <<= 3); idx = hts_idx_init(nids, HTS_FMT_CSI, bgzf_tell(fp->fp.bgzf), min_shift, n_lvls); + if (!idx) goto fail; b = bcf_init1(); - while (bcf_read1(fp,h, b) >= 0) { + if (!b) goto fail; + while ((r = bcf_read1(fp,h, b)) >= 0) { int ret; ret = hts_idx_push(idx, b->rid, b->pos, b->pos + b->rlen, bgzf_tell(fp->fp.bgzf), 1); - if (ret < 0) - { - bcf_destroy1(b); - hts_idx_destroy(idx); - return NULL; - } + if (ret < 0) goto fail; } + if (r < -1) goto fail; hts_idx_finish(idx, bgzf_tell(fp->fp.bgzf)); bcf_destroy1(b); bcf_hdr_destroy(h); return idx; + + fail: + hts_idx_destroy(idx); + bcf_destroy1(b); + bcf_hdr_destroy(h); + return NULL; } hts_idx_t *bcf_index_load2(const char *fn, const char *fnidx) @@ -2372,6 +2703,7 @@ int bcf_index_build3(const char *fn, const char *fnidx, int min_shift, int n_thr idx = bcf_index(fp, min_shift); if (idx) { ret = hts_idx_save_as(idx, fn, fnidx, HTS_FMT_CSI); + if (ret < 0) ret = -4; hts_idx_destroy(idx); } else ret = -1; @@ -2381,6 +2713,7 @@ int bcf_index_build3(const char *fn, const char *fnidx, int min_shift, int n_thr tbx = tbx_index(hts_get_bgzfp(fp), min_shift, &tbx_conf_vcf); if (tbx) { ret = hts_idx_save_as(tbx->idx, fn, fnidx, min_shift > 0 ? HTS_FMT_CSI : HTS_FMT_TBI); + if (ret < 0) ret = -4; tbx_destroy(tbx); } else ret = -1; @@ -2457,12 +2790,14 @@ int bcf_hdr_combine(bcf_hdr_t *dst, const bcf_hdr_t *src) khint_t k_dst = kh_get(vdict, d_dst, src->hrec[i]->vals[0]); if ( (kh_val(d_src,k_src).info[rec->type]>>8 & 0xf) != (kh_val(d_dst,k_dst).info[rec->type]>>8 & 0xf) ) { - fprintf(stderr,"Warning: trying to combine \"%s\" tag definitions of different lengths\n", src->hrec[i]->vals[0]); + hts_log_warning("Trying to combine \"%s\" tag definitions of different lengths", + src->hrec[i]->vals[0]); ret |= 1; } if ( (kh_val(d_src,k_src).info[rec->type]>>4 & 0xf) != (kh_val(d_dst,k_dst).info[rec->type]>>4 & 0xf) ) { - fprintf(stderr,"Warning: trying to combine \"%s\" tag definitions of different types\n", src->hrec[i]->vals[0]); + hts_log_warning("Trying to combine \"%s\" tag definitions of different types", + src->hrec[i]->vals[0]); ret |= 1; } } @@ -2480,7 +2815,10 @@ bcf_hdr_t *bcf_hdr_merge(bcf_hdr_t *dst, const bcf_hdr_t *src) dst = bcf_hdr_init("r"); kstring_t htxt = {0,0,0}; bcf_hdr_format(src, 0, &htxt); - bcf_hdr_parse(dst, htxt.s); + if ( bcf_hdr_parse(dst, htxt.s) < 0 ) { + bcf_hdr_destroy(dst); + dst = NULL; + } free(htxt.s); return dst; } @@ -2532,12 +2870,14 @@ bcf_hdr_t *bcf_hdr_merge(bcf_hdr_t *dst, const bcf_hdr_t *src) khint_t k_dst = kh_get(vdict, d_dst, src->hrec[i]->vals[0]); if ( (kh_val(d_src,k_src).info[rec->type]>>8 & 0xf) != (kh_val(d_dst,k_dst).info[rec->type]>>8 & 0xf) ) { - fprintf(stderr,"Warning: trying to combine \"%s\" tag definitions of different lengths\n", src->hrec[i]->vals[0]); + hts_log_warning("Trying to combine \"%s\" tag definitions of different lengths", + src->hrec[i]->vals[0]); ret |= 1; } if ( (kh_val(d_src,k_src).info[rec->type]>>4 & 0xf) != (kh_val(d_dst,k_dst).info[rec->type]>>4 & 0xf) ) { - fprintf(stderr,"Warning: trying to combine \"%s\" tag definitions of different types\n", src->hrec[i]->vals[0]); + hts_log_warning("Trying to combine \"%s\" tag definitions of different types", + src->hrec[i]->vals[0]); ret |= 1; } } @@ -2551,7 +2891,7 @@ int bcf_translate(const bcf_hdr_t *dst_hdr, bcf_hdr_t *src_hdr, bcf1_t *line) int i; if ( line->errcode ) { - fprintf(stderr,"[%s:%d %s] Unchecked error (%d), exiting.\n", __FILE__,__LINE__,__FUNCTION__,line->errcode); + hts_log_error("Unchecked error (%d), exiting", line->errcode); exit(1); } if ( src_hdr->ntransl==-1 ) return 0; // no need to translate, all tags have the same id @@ -2600,11 +2940,12 @@ int bcf_translate(const bcf_hdr_t *dst_hdr, bcf_hdr_t *src_hdr, bcf1_t *line) int src_id = line->d.info[i].key; int dst_id = src_hdr->transl[BCF_DT_ID][src_id]; if ( dst_id<0 ) continue; + line->d.info[i].key = dst_id; + if ( !line->d.info[i].vptr ) continue; // skip deleted int src_size = src_id>>7 ? ( src_id>>15 ? BCF_BT_INT32 : BCF_BT_INT16) : BCF_BT_INT8; int dst_size = dst_id>>7 ? ( dst_id>>15 ? BCF_BT_INT32 : BCF_BT_INT16) : BCF_BT_INT8; if ( src_size==dst_size ) // can overwrite { - line->d.info[i].key = dst_id; uint8_t *vptr = line->d.info[i].vptr - line->d.info[i].vptr_off; if ( dst_size==BCF_BT_INT8 ) { vptr[1] = (uint8_t)dst_id; } else if ( dst_size==BCF_BT_INT16 ) { *(uint16_t*)vptr = (uint16_t)dst_id; } @@ -2613,15 +2954,15 @@ int bcf_translate(const bcf_hdr_t *dst_hdr, bcf_hdr_t *src_hdr, bcf1_t *line) else // must realloc { bcf_info_t *info = &line->d.info[i]; - assert( !info->vptr_free ); kstring_t str = {0,0,0}; bcf_enc_int1(&str, dst_id); bcf_enc_size(&str, info->len,info->type); - info->vptr_off = str.l; + uint32_t vptr_off = str.l; kputsn((char*)info->vptr, info->vptr_len, &str); + if( info->vptr_free ) free(info->vptr - info->vptr_off); + info->vptr_off = vptr_off; info->vptr = (uint8_t*)str.s + info->vptr_off; info->vptr_free = 1; - info->key = dst_id; line->d.shared_dirty |= BCF1_DIRTY_INF; } } @@ -2632,11 +2973,12 @@ int bcf_translate(const bcf_hdr_t *dst_hdr, bcf_hdr_t *src_hdr, bcf1_t *line) int src_id = line->d.fmt[i].id; int dst_id = src_hdr->transl[BCF_DT_ID][src_id]; if ( dst_id<0 ) continue; + line->d.fmt[i].id = dst_id; + if( !line->d.fmt[i].p ) continue; // skip deleted int src_size = src_id>>7 ? ( src_id>>15 ? BCF_BT_INT32 : BCF_BT_INT16) : BCF_BT_INT8; int dst_size = dst_id>>7 ? ( dst_id>>15 ? BCF_BT_INT32 : BCF_BT_INT16) : BCF_BT_INT8; if ( src_size==dst_size ) // can overwrite { - line->d.fmt[i].id = dst_id; uint8_t *p = line->d.fmt[i].p - line->d.fmt[i].p_off; // pointer to the vector size (4bits) and BT type (4bits) if ( dst_size==BCF_BT_INT8 ) { p[1] = dst_id; } else if ( dst_size==BCF_BT_INT16 ) { uint8_t *x = (uint8_t*) &dst_id; p[1] = x[0]; p[2] = x[1]; } @@ -2645,15 +2987,15 @@ int bcf_translate(const bcf_hdr_t *dst_hdr, bcf_hdr_t *src_hdr, bcf1_t *line) else // must realloc { bcf_fmt_t *fmt = &line->d.fmt[i]; - assert( !fmt->p_free ); kstring_t str = {0,0,0}; bcf_enc_int1(&str, dst_id); bcf_enc_size(&str, fmt->n, fmt->type); - fmt->p_off = str.l; + uint32_t p_off = str.l; kputsn((char*)fmt->p, fmt->p_len, &str); + if( fmt->p_free ) free(fmt->p - fmt->p_off); + fmt->p_off = p_off; fmt->p = (uint8_t*)str.s + fmt->p_off; fmt->p_free = 1; - fmt->id = dst_id; line->d.indiv_dirty = 1; } } @@ -2664,12 +3006,15 @@ bcf_hdr_t *bcf_hdr_dup(const bcf_hdr_t *hdr) { bcf_hdr_t *hout = bcf_hdr_init("r"); if (!hout) { - fprintf(stderr, "[E::%s] failed to allocate bcf header\n", __func__); + hts_log_error("Failed to allocate bcf header"); return NULL; } kstring_t htxt = {0,0,0}; bcf_hdr_format(hdr, 1, &htxt); - bcf_hdr_parse(hout, htxt.s); + if ( bcf_hdr_parse(hout, htxt.s) < 0 ) { + bcf_hdr_destroy(hout); + hout = NULL; + } free(htxt.s); return hout; } @@ -2681,7 +3026,7 @@ bcf_hdr_t *bcf_hdr_subset(const bcf_hdr_t *h0, int n, char *const* samples, int kstring_t str = {0,0,0}; bcf_hdr_t *h = bcf_hdr_init("w"); if (!h) { - fprintf(stderr, "[E::%s] failed to allocate bcf header\n", __func__); + hts_log_error("Failed to allocate bcf header"); return NULL; } bcf_hdr_format(h0, 1, &htxt); @@ -2700,7 +3045,7 @@ bcf_hdr_t *bcf_hdr_subset(const bcf_hdr_t *h0, int n, char *const* samples, int for (i = 0; i < n; ++i) { if ( khash_str2int_has_key(names_hash,samples[i]) ) { - fprintf(stderr,"[E::bcf_hdr_subset] Duplicate sample name \"%s\".\n", samples[i]); + hts_log_error("Duplicate sample name \"%s\"", samples[i]); free(str.s); free(htxt.s); khash_str2int_destroy(names_hash); @@ -2716,7 +3061,10 @@ bcf_hdr_t *bcf_hdr_subset(const bcf_hdr_t *h0, int n, char *const* samples, int } else kputsn(htxt.s, htxt.l, &str); while (str.l && (!str.s[str.l-1] || str.s[str.l-1]=='\n') ) str.l--; // kill trailing zeros and newlines kputc('\n',&str); - bcf_hdr_parse(h, str.s); + if ( bcf_hdr_parse(h, str.s) < 0 ) { + bcf_hdr_destroy(h); + h = NULL; + } free(str.s); free(htxt.s); khash_str2int_destroy(names_hash); @@ -2794,9 +3142,8 @@ int bcf_subset(const bcf_hdr_t *h, bcf1_t *v, int n, int *imap) kstring_t ind; ind.s = 0; ind.l = ind.m = 0; if (n) { - bcf_fmt_t *fmt; + bcf_fmt_t fmt[MAX_N_FMT]; int i, j; - fmt = (bcf_fmt_t*)alloca(v->n_fmt * sizeof(bcf_fmt_t)); uint8_t *ptr = (uint8_t*)v->indiv.s; for (i = 0; i < v->n_fmt; ++i) ptr = bcf_unpack_fmt_core1(ptr, v->n_sample, &fmt[i]); @@ -2842,7 +3189,7 @@ static void bcf_set_variant_type(const char *ref, const char *alt, variant_t *va { if ( *alt == '.' || *ref==*alt ) { var->n = 0; var->type = VCF_REF; return; } if ( *alt == 'X' ) { var->n = 0; var->type = VCF_REF; return; } // mpileup's X allele shouldn't be treated as variant - if ( *alt == '*' ) { var->n = 0; var->type = VCF_REF; return; } + if ( *alt == '*' ) { var->n = 0; var->type = VCF_REF; return; } var->n = 1; var->type = VCF_SNP; return; } if ( alt[0]=='<' ) @@ -2858,6 +3205,7 @@ static void bcf_set_variant_type(const char *ref, const char *alt, variant_t *va if ( *a && !*r ) { + if ( *a==']' || *a=='[' ) { var->type = VCF_BND; return; } while ( *a ) a++; var->n = (a-alt)-(r-ref); var->type = VCF_INDEL; return; } @@ -2971,7 +3319,7 @@ int bcf_update_info(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const v } else { - fprintf(stderr, "[E::%s] the type %d not implemented yet\n", __func__, type); + hts_log_error("The type %d not implemented yet", type); abort(); } @@ -3083,7 +3431,7 @@ int bcf_update_format(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const else if ( type==BCF_HT_REAL ) { bcf_enc_size(&str, nps, BCF_BT_FLOAT); - kputsn((char*)values, nps*line->n_sample*sizeof(float), &str); + serialize_float_array(&str, nps*line->n_sample, (float *) values); } else if ( type==BCF_HT_STR ) { @@ -3092,7 +3440,7 @@ int bcf_update_format(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const } else { - fprintf(stderr, "[E::%s] the type %d not implemented yet\n", __func__, type); + hts_log_error("The type %d not implemented yet", type); abort(); } @@ -3324,7 +3672,7 @@ bcf_info_t *bcf_get_info(const bcf_hdr_t *hdr, bcf1_t *line, const char *key) return bcf_get_info_id(line, id); } -bcf_fmt_t *bcf_get_fmt_id(bcf1_t *line, const int id) +bcf_fmt_t *bcf_get_fmt_id(bcf1_t *line, const int id) { int i; if ( !(line->unpacked & BCF_UN_FMT) ) bcf_unpack(line, BCF_UN_FMT); @@ -3335,7 +3683,7 @@ bcf_fmt_t *bcf_get_fmt_id(bcf1_t *line, const int id) return NULL; } -bcf_info_t *bcf_get_info_id(bcf1_t *line, const int id) +bcf_info_t *bcf_get_info_id(bcf1_t *line, const int id) { int i; if ( !(line->unpacked & BCF_UN_INFO) ) bcf_unpack(line, BCF_UN_INFO); @@ -3382,44 +3730,24 @@ int bcf_get_info_values(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, voi *dst = realloc(*dst, *ndst * size1); } - if ( info->len == 1 ) - { - if ( info->type==BCF_BT_FLOAT ) *((float*)*dst) = info->v1.f; - else - { - #define BRANCH(type_t, missing) { \ - if ( info->v1.i==missing ) *((int32_t*)*dst) = bcf_int32_missing; \ - else *((int32_t*)*dst) = info->v1.i; \ - } - switch (info->type) - { - case BCF_BT_INT8: BRANCH(int8_t, bcf_int8_missing ); break; - case BCF_BT_INT16: BRANCH(int16_t, bcf_int16_missing); break; - case BCF_BT_INT32: BRANCH(int32_t, bcf_int32_missing); break; - } - #undef BRANCH - } - return 1; - } - - #define BRANCH(type_t, is_missing, is_vector_end, set_missing, out_type_t) { \ + #define BRANCH(type_t, convert, is_missing, is_vector_end, set_missing, set_regular, out_type_t) { \ out_type_t *tmp = (out_type_t *) *dst; \ - type_t *p = (type_t *) info->vptr; \ for (j=0; jlen; j++) \ { \ + type_t p = convert(info->vptr + j * sizeof(type_t)); \ if ( is_vector_end ) return j; \ if ( is_missing ) set_missing; \ - else *tmp = p[j]; \ + else set_regular; \ tmp++; \ } \ return j; \ } switch (info->type) { - case BCF_BT_INT8: BRANCH(int8_t, p[j]==bcf_int8_missing, p[j]==bcf_int8_vector_end, *tmp=bcf_int32_missing, int32_t); break; - case BCF_BT_INT16: BRANCH(int16_t, p[j]==bcf_int16_missing, p[j]==bcf_int16_vector_end, *tmp=bcf_int32_missing, int32_t); break; - case BCF_BT_INT32: BRANCH(int32_t, p[j]==bcf_int32_missing, p[j]==bcf_int32_vector_end, *tmp=bcf_int32_missing, int32_t); break; - case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(p[j]), bcf_float_is_vector_end(p[j]), bcf_float_set_missing(*tmp), float); break; - default: fprintf(stderr,"TODO: %s:%d .. info->type=%d\n", __FILE__,__LINE__, info->type); exit(1); + case BCF_BT_INT8: BRANCH(int8_t, le_to_i8, p==bcf_int8_missing, p==bcf_int8_vector_end, *tmp=bcf_int32_missing, *tmp=p, int32_t); break; + case BCF_BT_INT16: BRANCH(int16_t, le_to_i16, p==bcf_int16_missing, p==bcf_int16_vector_end, *tmp=bcf_int32_missing, *tmp=p, int32_t); break; + case BCF_BT_INT32: BRANCH(int32_t, le_to_i32, p==bcf_int32_missing, p==bcf_int32_vector_end, *tmp=bcf_int32_missing, *tmp=p, int32_t); break; + case BCF_BT_FLOAT: BRANCH(uint32_t, le_to_u32, p==bcf_float_missing, p==bcf_float_vector_end, bcf_float_set_missing(*tmp), bcf_float_set(tmp, p), float); break; + default: hts_log_error("Unexpected type %d", info->type); exit(1); } #undef BRANCH return -4; // this can never happen @@ -3506,30 +3834,30 @@ int bcf_get_format_values(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, v if ( !dst ) return -4; // could not alloc } - #define BRANCH(type_t, is_missing, is_vector_end, set_missing, set_vector_end, out_type_t) { \ + #define BRANCH(type_t, convert, is_missing, is_vector_end, set_missing, set_vector_end, set_regular, out_type_t) { \ out_type_t *tmp = (out_type_t *) *dst; \ - type_t *p = (type_t*) fmt->p; \ + uint8_t *fmt_p = fmt->p; \ for (i=0; in; j++) \ { \ + type_t p = convert(fmt_p + j * sizeof(type_t)); \ if ( is_missing ) set_missing; \ else if ( is_vector_end ) { set_vector_end; break; } \ - else *tmp = p[j]; \ + else set_regular; \ tmp++; \ } \ for (; jn; j++) { set_vector_end; tmp++; } \ - p = (type_t *)((char *)p + fmt->size); \ + fmt_p += fmt->size; \ } \ } switch (fmt->type) { - case BCF_BT_INT8: BRANCH(int8_t, p[j]==bcf_int8_missing, p[j]==bcf_int8_vector_end, *tmp=bcf_int32_missing, *tmp=bcf_int32_vector_end, int32_t); break; - case BCF_BT_INT16: BRANCH(int16_t, p[j]==bcf_int16_missing, p[j]==bcf_int16_vector_end, *tmp=bcf_int32_missing, *tmp=bcf_int32_vector_end, int32_t); break; - case BCF_BT_INT32: BRANCH(int32_t, p[j]==bcf_int32_missing, p[j]==bcf_int32_vector_end, *tmp=bcf_int32_missing, *tmp=bcf_int32_vector_end, int32_t); break; - case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(p[j]), bcf_float_is_vector_end(p[j]), bcf_float_set_missing(*tmp), bcf_float_set_vector_end(*tmp), float); break; - default: fprintf(stderr,"TODO: %s:%d .. fmt->type=%d\n", __FILE__,__LINE__, fmt->type); exit(1); + case BCF_BT_INT8: BRANCH(int8_t, le_to_i8, p==bcf_int8_missing, p==bcf_int8_vector_end, *tmp=bcf_int32_missing, *tmp=bcf_int32_vector_end, *tmp=p, int32_t); break; + case BCF_BT_INT16: BRANCH(int16_t, le_to_i16, p==bcf_int16_missing, p==bcf_int16_vector_end, *tmp=bcf_int32_missing, *tmp=bcf_int32_vector_end, *tmp=p, int32_t); break; + case BCF_BT_INT32: BRANCH(int32_t, le_to_i32, p==bcf_int32_missing, p==bcf_int32_vector_end, *tmp=bcf_int32_missing, *tmp=bcf_int32_vector_end, *tmp=p, int32_t); break; + case BCF_BT_FLOAT: BRANCH(uint32_t, le_to_u32, p==bcf_float_missing, p==bcf_float_vector_end, bcf_float_set_missing(*tmp), bcf_float_set_vector_end(*tmp), bcf_float_set(tmp, p), float); break; + default: hts_log_error("Unexpected type %d", fmt->type); exit(1); } #undef BRANCH return nsmpl*fmt->n; } - diff --git a/htslib/vcf_sweep.c b/htslib/vcf_sweep.c index 38e384f97..799e78af3 100644 --- a/htslib/vcf_sweep.c +++ b/htslib/vcf_sweep.c @@ -109,7 +109,7 @@ bcf_sweep_t *bcf_sweep_init(const char *fname) bcf_sweep_t *sw = (bcf_sweep_t*) calloc(1,sizeof(bcf_sweep_t)); sw->file = hts_open(fname, "r"); sw->fp = hts_get_bgzfp(sw->file); - bgzf_index_build_init(sw->fp); + if (sw->fp) bgzf_index_build_init(sw->fp); sw->hdr = bcf_hdr_read(sw->file); sw->mrec = 1; sw->rec = (bcf1_t*) calloc(sw->mrec,(sizeof(bcf1_t))); @@ -154,7 +154,7 @@ bcf1_t *bcf_sweep_fwd(bcf_sweep_t *sw) if ( ret!=0 ) // last record, get ready for sweeping backwards { sw->idx_done = 1; - sw->fp->idx_build_otf = 0; + if (sw->fp) sw->fp->idx_build_otf = 0; sw_seek(sw, SW_BWD); return NULL; } diff --git a/htslib/vcfutils.c b/htslib/vcfutils.c index 141fe0e3f..39fc69584 100644 --- a/htslib/vcfutils.c +++ b/htslib/vcfutils.c @@ -1,6 +1,6 @@ /* vcfutils.c -- allele-related utility functions. - Copyright (C) 2012-2015 Genome Research Ltd. + Copyright (C) 2012-2016 Genome Research Ltd. Author: Petr Danecek @@ -64,13 +64,13 @@ int bcf_calc_ac(const bcf_hdr_t *header, bcf1_t *line, int *ac, int which) case BCF_BT_INT8: BRANCH_INT(int8_t); break; case BCF_BT_INT16: BRANCH_INT(int16_t); break; case BCF_BT_INT32: BRANCH_INT(int32_t); break; - default: fprintf(stderr, "[E::%s] todo: %d at %s:%d\n", __func__, ac_type, header->id[BCF_DT_CTG][line->rid].key, line->pos+1); exit(1); break; + default: hts_log_error("Unexpected type %d at %s:%d", ac_type, header->id[BCF_DT_CTG][line->rid].key, line->pos+1); exit(1); break; } #undef BRANCH_INT if ( anid[BCF_DT_CTG][line->rid].key, line->pos+1); - exit(1); + hts_log_error("Incorrect AN/AC counts at %s:%d", header->id[BCF_DT_CTG][line->rid].key, line->pos+1); + exit(1); } ac[0] = an - nac; return 1; @@ -98,7 +98,7 @@ int bcf_calc_ac(const bcf_hdr_t *header, bcf1_t *line, int *ac, int which) if ( bcf_gt_is_missing(p[ial]) ) continue; /* missing allele */ \ if ( p[ial]>>1 > line->n_allele ) \ { \ - fprintf(stderr,"[E::%s] Incorrect allele (\"%d\") in %s at %s:%d\n", __func__,(p[ial]>>1)-1, header->samples[i],header->id[BCF_DT_CTG][line->rid].key, line->pos+1); \ + hts_log_error("Incorrect allele (\"%d\") in %s at %s:%d", (p[ial]>>1)-1, header->samples[i], header->id[BCF_DT_CTG][line->rid].key, line->pos+1); \ exit(1); \ } \ ac[(p[ial]>>1)-1]++; \ @@ -109,7 +109,7 @@ int bcf_calc_ac(const bcf_hdr_t *header, bcf1_t *line, int *ac, int which) case BCF_BT_INT8: BRANCH_INT(int8_t, bcf_int8_vector_end); break; case BCF_BT_INT16: BRANCH_INT(int16_t, bcf_int16_vector_end); break; case BCF_BT_INT32: BRANCH_INT(int32_t, bcf_int32_vector_end); break; - default: fprintf(stderr, "[E::%s] todo: %d at %s:%d\n", __func__, fmt_gt->type, header->id[BCF_DT_CTG][line->rid].key, line->pos+1); exit(1); break; + default: hts_log_error("Unexpected type %d at %s:%d", fmt_gt->type, header->id[BCF_DT_CTG][line->rid].key, line->pos+1); exit(1); break; } #undef BRANCH_INT return 1; @@ -152,7 +152,7 @@ int bcf_gt_type(bcf_fmt_t *fmt_ptr, int isample, int *_ial, int *_jal) case BCF_BT_INT8: BRANCH_INT(int8_t, bcf_int8_vector_end); break; case BCF_BT_INT16: BRANCH_INT(int16_t, bcf_int16_vector_end); break; case BCF_BT_INT32: BRANCH_INT(int32_t, bcf_int32_vector_end); break; - default: fprintf(stderr, "[E::%s] todo: fmt_type %d\n", __func__, fmt_ptr->type); exit(1); break; + default: hts_log_error("Unexpected type %d", fmt_ptr->type); exit(1); break; } #undef BRANCH_INT @@ -170,7 +170,8 @@ int bcf_gt_type(bcf_fmt_t *fmt_ptr, int isample, int *_ial, int *_jal) int bcf_trim_alleles(const bcf_hdr_t *header, bcf1_t *line) { - int i; + int i, ret = 0, nrm = 0; + kbitset_t *rm_set = NULL; bcf_fmt_t *gt = bcf_get_fmt(header, line, "GT"); if ( !gt ) return 0; @@ -186,7 +187,11 @@ int bcf_trim_alleles(const bcf_hdr_t *header, bcf1_t *line) { \ if ( p[ial]==vector_end ) break; /* smaller ploidy */ \ if ( bcf_gt_is_missing(p[ial]) ) continue; /* missing allele */ \ - if ( (p[ial]>>1)-1 >= line->n_allele ) { free(ac); return -1; } \ + if ( (p[ial]>>1)-1 >= line->n_allele ) { \ + hts_log_error("Allele index is out of bounds at %s:%d", header->id[BCF_DT_CTG][line->rid].key, line->pos+1); \ + ret = -1; \ + goto clean; \ + } \ ac[(p[ial]>>1)-1]++; \ } \ } \ @@ -195,21 +200,26 @@ int bcf_trim_alleles(const bcf_hdr_t *header, bcf1_t *line) case BCF_BT_INT8: BRANCH(int8_t, bcf_int8_vector_end); break; case BCF_BT_INT16: BRANCH(int16_t, bcf_int16_vector_end); break; case BCF_BT_INT32: BRANCH(int32_t, bcf_int32_vector_end); break; - default: fprintf(stderr, "[E::%s] todo: %d at %s:%d\n", __func__, gt->type, header->id[BCF_DT_CTG][line->rid].key, line->pos+1); exit(1); break; + default: hts_log_error("Unexpected GT %d at %s:%d", + gt->type, header->id[BCF_DT_CTG][line->rid].key, line->pos + 1); + goto clean; break; } #undef BRANCH - int nrm = 0; - kbitset_t *rm_set = kbs_init(line->n_allele); - for (i=1; in_allele; i++) - { + rm_set = kbs_init(line->n_allele); + for (i=1; in_allele; i++) { if ( !ac[i] ) { kbs_insert(rm_set, i); nrm++; } } - free(ac); - if ( nrm ) bcf_remove_allele_set(header, line, rm_set); - kbs_destroy(rm_set); - return nrm; + if (nrm) { + if (bcf_remove_allele_set(header, line, rm_set)) + ret = -2; + } + +clean: + free(ac); + if (rm_set) kbs_destroy(rm_set); + return ret ? ret : nrm; } void bcf_remove_alleles(const bcf_hdr_t *header, bcf1_t *line, int rm_mask) @@ -223,9 +233,10 @@ void bcf_remove_alleles(const bcf_hdr_t *header, bcf1_t *line, int rm_mask) kbs_destroy(rm_set); } -void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct kbitset_t *rm_set) +int bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct kbitset_t *rm_set) { int *map = (int*) calloc(line->n_allele, sizeof(int)); + uint8_t *dat = NULL; // create map of indexes from old to new ALT numbering and modify ALT kstring_t str = {0,0,0}; @@ -246,11 +257,16 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k map[i] = j; j++; } - if ( !nrm ) { free(map); free(str.s); return; } + if ( !nrm ) goto clean; int nR_ori = line->n_allele; int nR_new = line->n_allele-nrm; - assert(nR_new > 0); // should not be able to remove reference allele + if ( nR_new<=0 ) // should not be able to remove reference allele + { + hts_log_error("Cannot remove reference allele at %s:%d [%d]", + bcf_seqname(header,line), line->pos+1, nR_new); + goto err; + } int nA_ori = nR_ori-1; int nA_new = nR_new-1; @@ -260,7 +276,6 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k bcf_update_alleles_str(header, line, str.s); // remove from Number=G, Number=R and Number=A INFO fields. - uint8_t *dat = NULL; int mdat = 0, ndat = 0, mdat_bytes = 0, nret; for (i=0; in_info; i++) { @@ -279,14 +294,16 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k mdat_bytes = mdat * size; if ( nret<0 ) { - fprintf(stderr,"[%s:%d %s] Could not access INFO/%s at %s:%d [%d]\n", __FILE__,__LINE__,__FUNCTION__, + hts_log_error("Could not access INFO/%s at %s:%d [%d]", bcf_hdr_int2id(header,BCF_DT_ID,info->key), bcf_seqname(header,line), line->pos+1, nret); - exit(1); + goto err; } + if ( nret==0 ) continue; // no data for this tag + if ( type==BCF_HT_STR ) { str.l = 0; - char *ss = (char*) dat, *se = (char*) dat; + char *ss = (char*) dat, *se = (char*) dat, s = ss[0]; if ( vlen==BCF_VL_A || vlen==BCF_VL_R ) { int nexp, inc = 0; @@ -312,7 +329,13 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k if ( *se ) se++; ss = se; } - assert( j==nexp ); + if ( j==1 && s == '.' ) continue; // missing + if ( j!=nexp ) + { + hts_log_error("Unexpected number of values in INFO/%s at %s:%d; expected Number=%c=%d, but found %d", + bcf_hdr_int2id(header,BCF_DT_ID,info->key), bcf_seqname(header,line), line->pos+1, vlen==BCF_VL_A ? 'A' : 'R', nexp, j); + goto err; + } } else // Number=G, assuming diploid genotype { @@ -337,32 +360,66 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k } if ( !*se ) break; } - assert( n==nG_ori ); + if ( n==1 && s == '.' ) continue; // missing + if ( n!=nG_ori ) + { + hts_log_error("Unexpected number of values in INFO/%s at %s:%d; expected Number=G=%d, but found %d", + bcf_hdr_int2id(header,BCF_DT_ID,info->key), bcf_seqname(header,line), line->pos+1, nG_ori, n); + goto err; + } } nret = bcf_update_info(header, line, bcf_hdr_int2id(header,BCF_DT_ID,info->key), (void*)str.s, str.l, type); if ( nret<0 ) { - fprintf(stderr,"[%s:%d %s] Could not update INFO/%s at %s:%d [%d]\n", __FILE__,__LINE__,__FUNCTION__, - bcf_hdr_int2id(header,BCF_DT_ID,info->key), bcf_seqname(header,line), line->pos+1, nret); - exit(1); + hts_log_error("Could not update INFO/%s at %s:%d [%d]", + bcf_hdr_int2id(header,BCF_DT_ID,info->key), bcf_seqname(header,line), line->pos+1, nret); + goto err; } continue; } + if (nret==1) // could be missing - check + { + int missing = 0; + #define BRANCH(type_t, is_missing) { \ + type_t *p = (type_t *) info->vptr; \ + if ( is_missing ) missing = 1; \ + } + switch (info->type) { + case BCF_BT_INT8: BRANCH(int8_t, p[0]==bcf_int8_missing); break; + case BCF_BT_INT16: BRANCH(int16_t, p[0]==bcf_int16_missing); break; + case BCF_BT_INT32: BRANCH(int32_t, p[0]==bcf_int32_missing); break; + case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(p[0])); break; + default: hts_log_error("Unexpected type %d", info->type); goto err; break; + } + #undef BRANCH + if (missing) continue; // could remove this INFO tag? + } + if ( vlen==BCF_VL_A || vlen==BCF_VL_R ) { int inc = 0, ntop; if ( vlen==BCF_VL_A ) { - assert( nret==nA_ori ); + if ( nret!=nA_ori ) + { + hts_log_error("Unexpected number of values in INFO/%s at %s:%d; expected Number=A=%d, but found %d", + bcf_hdr_int2id(header,BCF_DT_ID,info->key), bcf_seqname(header,line), line->pos+1, nA_ori, nret); + goto err; + } ntop = nA_ori; ndat = nA_new; inc = 1; } else { - assert( nret==nR_ori ); + if ( nret!=nR_ori ) + { + hts_log_error("Unexpected number of values in INFO/%s at %s:%d; expected Number=R=%d, but found %d", + bcf_hdr_int2id(header,BCF_DT_ID,info->key), bcf_seqname(header,line), line->pos+1, nR_ori, nret); + goto err; + } ntop = nR_ori; ndat = nR_new; } @@ -389,7 +446,12 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k } else // Number=G { - assert( nret==nG_ori ); + if ( nret!=nG_ori ) + { + hts_log_error("Unexpected number of values in INFO/%s at %s:%d; expected Number=R=%d, but found %d", + bcf_hdr_int2id(header,BCF_DT_ID,info->key), bcf_seqname(header,line), line->pos+1, nG_ori, nret); + goto err; + } int k, l_ori = -1, l_new = 0; ndat = nG_new; @@ -420,9 +482,9 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k nret = bcf_update_info(header, line, bcf_hdr_int2id(header,BCF_DT_ID,info->key), (void*)dat, ndat, type); if ( nret<0 ) { - fprintf(stderr,"[%s:%d %s] Could not update INFO/%s at %s:%d [%d]\n", __FILE__,__LINE__,__FUNCTION__, - bcf_hdr_int2id(header,BCF_DT_ID,info->key), bcf_seqname(header,line), line->pos+1, nret); - exit(1); + hts_log_error("Could not update INFO/%s at %s:%d [%d]", + bcf_hdr_int2id(header,BCF_DT_ID,info->key), bcf_seqname(header,line), line->pos+1, nret); + goto err; } } @@ -444,12 +506,23 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k if ( bcf_gt_is_missing(ptr[j]) ) continue; if ( ptr[j]==bcf_int32_vector_end ) break; int al = bcf_gt_allele(ptr[j]); - assert( al=0 ); + if ( !( al=0 ) ) + { + hts_log_error("Problem updating genotypes at %s:%d [ al=0 :: al=%d,nR_ori=%d,map[al]=%d ]", + bcf_seqname(header,line), line->pos+1, al, nR_ori, map[al]); + goto err; + } ptr[j] = (map[al]+1)<<1 | (ptr[j]&1); } ptr += nret; } - bcf_update_genotypes(header, line, (void*)dat, nret*line->n_sample); + nret = bcf_update_genotypes(header, line, (void*)dat, nret*line->n_sample); + if ( nret<0 ) + { + hts_log_error("Could not update FORMAT/GT at %s:%d [%d]", + bcf_seqname(header,line), line->pos+1, nret); + goto err; + } } } @@ -473,10 +546,11 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k mdat_bytes = mdat * size; if ( nret<0 ) { - fprintf(stderr,"[%s:%d %s] Could not access FORMAT/%s at %s:%d [%d]\n", __FILE__,__LINE__,__FUNCTION__, - bcf_hdr_int2id(header,BCF_DT_ID,fmt->id), bcf_seqname(header,line), line->pos+1, nret); - exit(1); + hts_log_error("Could not access FORMAT/%s at %s:%d [%d]", + bcf_hdr_int2id(header,BCF_DT_ID,fmt->id), bcf_seqname(header,line), line->pos+1, nret); + goto err; } + if ( nret == 0 ) continue; // no data for this tag if ( type==BCF_HT_STR ) { @@ -494,7 +568,7 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k nexp = nR_ori; for (j=0; jn_sample; j++) { - char *ss = ((char*)dat) + j*size, *se = ss + size, *ptr = ss; + char *ss = ((char*)dat) + j*size, *se = ss + size, *ptr = ss, s = ss[0]; int k_src = 0, k_dst = 0, l = str.l; for (k_src=0; k_srcid), bcf_seqname(header,line), line->pos+1, vlen==BCF_VL_A ? 'A' : 'R', nexp, k_src); + goto err; + } l = str.l - l; for (; ln_sample; j++) { - char *ss = ((char*)dat) + j*size, *se = ss + size, *ptr = ss; + char *ss = ((char*)dat) + j*size, *se = ss + size, *ptr = ss, s = ss[0]; int k_src = 0, k_dst = 0, l = str.l; int nexp = 0; // diploid or haploid? while ( ptrid), bcf_seqname(header,line), line->pos+1, nG_ori, nR_ori, nexp); + goto err; + } ptr = ss; if ( nexp==nG_ori ) // diploid { @@ -569,7 +655,12 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k ss = ++ptr; k_dst++; } - assert( k_src==nR_ori ); + if ( k_src!=nR_ori ) + { + hts_log_error("Unexpected number of values in FORMAT/%s at %s:%d; expected Number=G=%d(haploid), but found %d", + bcf_hdr_int2id(header,BCF_DT_ID,fmt->id), bcf_seqname(header,line), line->pos+1, nR_ori, k_src); + goto err; + } l = str.l - l; for (; lid), (void*)str.s, str.l, type); if ( nret<0 ) { - fprintf(stderr,"[%s:%d %s] Could not update FORMAT/%s at %s:%d [%d]\n", __FILE__,__LINE__,__FUNCTION__, - bcf_hdr_int2id(header,BCF_DT_ID,fmt->id), bcf_seqname(header,line), line->pos+1, nret); - exit(1); + hts_log_error("Could not update FORMAT/%s at %s:%d [%d]", + bcf_hdr_int2id(header,BCF_DT_ID,fmt->id), bcf_seqname(header,line), line->pos+1, nret); + goto err; } continue; } int nori = nret / line->n_sample; + if ( nori==1 && !(vlen==BCF_VL_A && nori==nA_ori) ) // all values may be missing - check + { + int all_missing = 1; + #define BRANCH(type_t, is_missing) { \ + for (j=0; jn_sample; j++) \ + { \ + type_t *p = (type_t*) (fmt->p + j*fmt->size); \ + if ( !(is_missing)) { all_missing = 0; break; } \ + } \ + } + switch (fmt->type) { + case BCF_BT_INT8: BRANCH(int8_t, p[0]==bcf_int8_missing); break; + case BCF_BT_INT16: BRANCH(int16_t, p[0]==bcf_int16_missing); break; + case BCF_BT_INT32: BRANCH(int32_t, p[0]==bcf_int32_missing); break; + case BCF_BT_FLOAT: BRANCH(float, bcf_float_is_missing(p[0])); break; + default: hts_log_error("Unexpected type %d", fmt->type); goto err; break; + } + #undef BRANCH + if (all_missing) continue; // could remove this FORMAT tag? + } + if ( vlen==BCF_VL_A || vlen==BCF_VL_R || (vlen==BCF_VL_G && nori==nR_ori) ) // Number=A, R or haploid Number=G { int inc = 0, nnew; if ( vlen==BCF_VL_A ) { - assert( nori==nA_ori ); // todo: will fail if all values are missing + if ( nori!=nA_ori ) + { + hts_log_error("Unexpected number of values in FORMAT/%s at %s:%d; expected Number=A=%d, but found %d", + bcf_hdr_int2id(header,BCF_DT_ID,fmt->id), bcf_seqname(header,line), line->pos+1, nA_ori, nori); + goto err; + } ndat = nA_new*line->n_sample; nnew = nA_new; inc = 1; } else { - assert( nori==nR_ori ); // todo: will fail if all values are missing + if ( nori!=nR_ori ) + { + hts_log_error("Unexpected number of values in FORMAT/%s at %s:%d; expected Number=R=%d, but found %d", + bcf_hdr_int2id(header,BCF_DT_ID,fmt->id), bcf_seqname(header,line), line->pos+1, nR_ori, nori); + goto err; + } ndat = nR_new*line->n_sample; nnew = nR_new; } @@ -629,7 +751,12 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k } else // Number=G, diploid or mixture of haploid+diploid { - assert( nori==nG_ori ); + if ( nori!=nG_ori ) + { + hts_log_error("Unexpected number of values in FORMAT/%s at %s:%d; expected Number=G=%d, but found %d", + bcf_hdr_int2id(header,BCF_DT_ID,fmt->id), bcf_seqname(header,line), line->pos+1, nG_ori, nori); + goto err; + } ndat = nG_new*line->n_sample; #define BRANCH(type_t,is_vector_end) \ @@ -679,13 +806,22 @@ void bcf_remove_allele_set(const bcf_hdr_t *header, bcf1_t *line, const struct k nret = bcf_update_format(header, line, bcf_hdr_int2id(header,BCF_DT_ID,fmt->id), (void*)dat, ndat, type); if ( nret<0 ) { - fprintf(stderr,"[%s:%d %s] Could not update FORMAT/%s at %s:%d [%d]\n", __FILE__,__LINE__,__FUNCTION__, - bcf_hdr_int2id(header,BCF_DT_ID,fmt->id), bcf_seqname(header,line), line->pos+1, nret); - exit(1); + hts_log_error("Could not update FORMAT/%s at %s:%d [%d]", + bcf_hdr_int2id(header,BCF_DT_ID,fmt->id), bcf_seqname(header,line), line->pos+1, nret); + goto err; } } + +clean: + free(str.s); + free(map); free(dat); + return 0; + +err: free(str.s); free(map); + free(dat); + return -1; } diff --git a/htslib/version.h b/htslib/version.h index fb0205e07..d10e41ada 100644 --- a/htslib/version.h +++ b/htslib/version.h @@ -1 +1 @@ -#define HTS_VERSION "1.3.2" +#define HTS_VERSION "1.7" diff --git a/htslib/version.sh b/htslib/version.sh new file mode 100755 index 000000000..de33c6d88 --- /dev/null +++ b/htslib/version.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# Master version, for use in tarballs or non-git source copies +VERSION=1.7 + +# If we have a git clone, then check against the current tag +if [ -e .git ] +then + # If we ever get to 10.x this will need to be more liberal + VERSION=`git describe --match '[0-9].[0-9]*' --dirty` +fi + +# Numeric version is for use in .dylib or .so libraries +# +# Follows the same logic from the Makefile commit c2e93911 +# as non-numeric versions get bumped to patch level 255 to indicate +# an unknown value. +if [ "$1" = "numeric" ] +then + v1=`expr "$VERSION" : '\([0-9]*\)'` + v2=`expr "$VERSION" : '[0-9]*.\([0-9]*\)'` + v3=`expr "$VERSION" : '[0-9]*.[0-9]*.\([0-9]*\)'` + if [ -z "`expr "$VERSION" : '^\([0-9.]*\)$'`" ] + then + VERSION="$v1.$v2.255" + else + VERSION="$v1.$v2${v3:+.}$v3" + fi +fi + +echo $VERSION diff --git a/import.py b/import.py index 12d20162e..89aa9f139 100644 --- a/import.py +++ b/import.py @@ -12,18 +12,21 @@ # For samtools, type: # rm -rf samtools # python import.py samtools download/samtools +# git checkout -- samtools/version.h # # Manually, then: # modify config.h to set compatibility flags # # For bcftools, type: -# rm -rf bedtools -# python import.py bedtools download/bedtools +# rm -rf bcftools +# python import.py bcftools download/bedtools +# git checkout -- bcftools/version.h # rm -rf bedtools/test bedtools/plugins import fnmatch import os import re +import itertools import shutil import sys import hashlib @@ -31,18 +34,29 @@ EXCLUDE = { "samtools": ( - "razip.c", "bgzip.c", "main.c", - "calDepth.c", "bam2bed.c", "wgsim.c", - "md5fa.c", "md5sum-lite.c", "maq2sam.c", - "bamcheck.c", "chk_indel.c", "vcf-miniview.c", - "htslib-1.3", # do not import twice + "razip.c", + "bgzip.c", + "main.c", + "calDepth.c", + "bam2bed.c", + "wgsim.c", + "bam_tview.c", + "bam_tview.h", + "bam_tview_html.c", + "bam_tview_curses.c", + "md5fa.c", + "md5sum-lite.c", + "maq2sam.c", + "bamcheck.c", + "chk_indel.c", + "vcf-miniview.c", "hfile_irods.c", # requires irods library ), "bcftools": ( "test", "plugins", "peakfit.c", "peakfit.h", # needs to renamed, name conflict with samtools reheader - "reheader.c", + # "reheader.c", "polysomy.c"), "htslib": ( 'htslib/tabix.c', 'htslib/bgzip.c', @@ -73,10 +87,11 @@ def _update_pysam_files(cf, destdir): if not filename: continue dest = filename + ".pysam.c" - with open(filename) as infile: + with open(filename, encoding="utf-8") as infile: lines = "".join(infile.readlines()) - with open(dest, "w") as outfile: - outfile.write('#include "pysam.h"\n\n') + + with open(dest, "w", encoding="utf-8") as outfile: + outfile.write('#include "{}.pysam.h"\n\n'.format(basename)) subname, _ = os.path.splitext(os.path.basename(filename)) if subname in MAIN.get(basename, []): lines = re.sub("int main\(", "int {}_main(".format( @@ -84,27 +99,27 @@ def _update_pysam_files(cf, destdir): else: lines = re.sub("int main\(", "int {}_{}_main(".format( basename, subname), lines) - lines = re.sub("stderr", "pysam_stderr", lines) - lines = re.sub("stdout", "pysam_stdout", lines) - lines = re.sub(" printf\(", " fprintf(pysam_stdout, ", lines) + lines = re.sub("stderr", "{}_stderr".format(basename), lines) + lines = re.sub("stdout", "{}_stdout".format(basename), lines) + lines = re.sub(" printf\(", " fprintf({}_stdout, ".format(basename), lines) lines = re.sub("([^kf])puts\(([^)]+)\)", - r"\1fputs(\2, pysam_stdout) & fputc('\\n', pysam_stdout)", + r"\1fputs(\2, {}_stdout) & fputc('\\n', {}_stdout)".format(basename, basename), lines) lines = re.sub("putchar\(([^)]+)\)", - r"fputc(\1, pysam_stdout)", lines) + r"fputc(\1, {}_stdout)".format(basename), lines) fn = os.path.basename(filename) # some specific fixes: SPECIFIC_SUBSTITUTIONS = { "bam_md.c": ( 'sam_open_format("-", mode_w', - 'sam_open_format(pysam_stdout_fn, mode_w'), + 'sam_open_format({}_stdout_fn, mode_w'.format(basename)), "phase.c": ( - 'putc("ACGT"[f->seq[j] == 1? (c&3, pysam_stdout) : (c>>16&3)]);', - 'putc("ACGT"[f->seq[j] == 1? (c&3) : (c>>16&3)], pysam_stdout);'), + 'putc("ACGT"[f->seq[j] == 1? (c&3, {}_stdout) : (c>>16&3)]);'.format(basename), + 'putc("ACGT"[f->seq[j] == 1? (c&3) : (c>>16&3)], {}_stdout);'.format(basename)), "cut_target.c": ( - 'putc(33 + (cns[j]>>8>>2, pysam_stdout));', - 'putc(33 + (cns[j]>>8>>2), pysam_stdout);') + 'putc(33 + (cns[j]>>8>>2, {}_stdout));'.format(basename), + 'putc(33 + (cns[j]>>8>>2), {}_stdout);'.format(basename)) } if fn in SPECIFIC_SUBSTITUTIONS: lines = lines.replace( @@ -112,15 +127,13 @@ def _update_pysam_files(cf, destdir): SPECIFIC_SUBSTITUTIONS[fn][1]) outfile.write(lines) - with open(os.path.join(destdir, "pysam.h"), "w")as outfile: - outfile.write("""#ifndef PYSAM_H -#define PYSAM_H -#include "stdio.h" -extern FILE * pysam_stderr; -extern FILE * pysam_stdout; -extern const char * pysam_stdout_fn; -#endif -""") + with open(os.path.join("import", "pysam.h")) as inf, \ + open(os.path.join(destdir, "{}.pysam.h".format(basename)), "w") as outf: + outf.write(re.sub("@pysam@", basename, inf.read())) + + with open(os.path.join("import", "pysam.c")) as inf, \ + open(os.path.join(destdir, "{}.pysam.c".format(basename)), "w") as outf: + outf.write(re.sub("@pysam@", basename, inf.read())) if len(sys.argv) >= 1: @@ -140,7 +153,8 @@ def _update_pysam_files(cf, destdir): cfiles = locate("*.c", srcdir) hfiles = locate("*.h", srcdir) - + mfiles = itertools.chain(locate("README", srcdir), locate("LICENSE", srcdir)) + # remove unwanted files and htslib subdirectory. cfiles = [x for x in cfiles if os.path.basename(x) not in exclude and not re.search("htslib-", x)] @@ -161,9 +175,9 @@ def _compareAndCopy(src, srcdir, destdir, exclude): old_file = os.path.join(targetdir, f) if os.path.exists(old_file): md5_old = hashlib.md5( - "".join(open(old_file, "r").readlines())).digest() + "".join(open(old_file, "r", encoding="utf-8").readlines()).encode()).digest() md5_new = hashlib.md5( - "".join(open(src, "r").readlines())).digest() + "".join(open(src, "r", encoding="utf-8").readlines()).encode()).digest() if md5_old != md5_new: raise ValueError( "incompatible files for %s and %s" % @@ -176,6 +190,10 @@ def _compareAndCopy(src, srcdir, destdir, exclude): _compareAndCopy(src_file, srcdir, destdir, exclude) ncopied += 1 + for src_file in mfiles: + _compareAndCopy(src_file, srcdir, destdir, exclude) + ncopied += 1 + cf = [] for src_file in cfiles: cf.append(_compareAndCopy(src_file, diff --git a/import/pysam.c b/import/pysam.c new file mode 100644 index 000000000..164201375 --- /dev/null +++ b/import/pysam.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include +#include + +#include "@pysam@.pysam.h" + +FILE * @pysam@_stderr = NULL; +FILE * @pysam@_stdout = NULL; +const char * @pysam@_stdout_fn = NULL; +int @pysam@_stdout_fileno = STDOUT_FILENO; + + +FILE * @pysam@_set_stderr(int fd) +{ + if (@pysam@_stderr != NULL) + fclose(@pysam@_stderr); + @pysam@_stderr = fdopen(fd, "w"); + return @pysam@_stderr; +} + +void @pysam@_unset_stderr(void) +{ + if (@pysam@_stderr != NULL) + fclose(@pysam@_stderr); + @pysam@_stderr = fopen("/dev/null", "w"); +} + +FILE * @pysam@_set_stdout(int fd) +{ + if (@pysam@_stdout != NULL) + fclose(@pysam@_stdout); + @pysam@_stdout = fdopen(fd, "w"); + if (@pysam@_stdout == NULL) + { + fprintf(@pysam@_stderr, "could not set stdout to fd %i", fd); + } + @pysam@_stdout_fileno = fd; + return @pysam@_stdout; +} + +void @pysam@_set_stdout_fn(const char *fn) +{ + @pysam@_stdout_fn = fn; +} + +void @pysam@_unset_stdout(void) +{ + if (@pysam@_stdout != NULL) + fclose(@pysam@_stdout); + @pysam@_stdout = fopen("/dev/null", "w"); + @pysam@_stdout_fileno = STDOUT_FILENO; +} + +void @pysam@_set_optind(int val) +{ + // setting this in cython via + // "from posix.unistd cimport optind" + // did not work. + // + // setting to 0 forces a complete re-initialization + optind = val; +} + + + diff --git a/import/pysam.h b/import/pysam.h new file mode 100644 index 000000000..4a6ec2961 --- /dev/null +++ b/import/pysam.h @@ -0,0 +1,47 @@ +#ifndef PYSAM_H +#define PYSAM_H + +#include "stdio.h" + +extern FILE * @pysam@_stderr; + +extern FILE * @pysam@_stdout; + +extern const char * @pysam@_stdout_fn; + +/*! set pysam standard error to point to file descriptor + + Setting the stderr will close the previous stderr. + */ +FILE * @pysam@_set_stderr(int fd); + +/*! set pysam standard output to point to file descriptor + + Setting the stderr will close the previous stdout. + */ +FILE * @pysam@_set_stdout(int fd); + +/*! set pysam standard output to point to filename + + */ +void @pysam@_set_stdout_fn(const char * fn); + +/*! set pysam standard error to /dev/null. + + Unsetting the stderr will close the previous stderr. + */ +void @pysam@_unset_stderr(void); + +/*! set pysam standard error to /dev/null. + + Unsetting the stderr will close the previous stderr. + */ +void @pysam@_unset_stdout(void); + +int @pysam@_dispatch(int argc, char *argv[]); + +void @pysam@_set_optind(int); + +extern int @pysam@_main(int argc, char *argv[]); + +#endif diff --git a/linker_tests/link_pre_489/PysamTestModule_link_pre_489/BuildRead.pyx b/linker_tests/link_pre_489/PysamTestModule_link_pre_489/BuildRead.pyx new file mode 100644 index 000000000..9c51e8f38 --- /dev/null +++ b/linker_tests/link_pre_489/PysamTestModule_link_pre_489/BuildRead.pyx @@ -0,0 +1,24 @@ +from __future__ import absolute_import + +from pysam.libchtslib cimport bam1_t, bam_endpos +from pysam.libcsamfile cimport aux_type2size +from pysam.libcalignedsegment cimport AlignedSegment + +import pysam + + +cpdef build_read(): + cdef AlignedSegment read = pysam.AlignedSegment() + read.query_name = "hello" + read.query_sequence = "ACGT" + read.reference_start = 10 + read.cigarstring = "4M" + + # Test calling htslib function + cdef bam1_t *calign = read._delegate + print(bam_endpos(calign)) + + # Test calling pysam htslib_util function + print(aux_type2size(12)) + + return read diff --git a/linker_tests/link_pre_489/PysamTestModule_link_pre_489/__init__.py b/linker_tests/link_pre_489/PysamTestModule_link_pre_489/__init__.py new file mode 100644 index 000000000..e44102118 --- /dev/null +++ b/linker_tests/link_pre_489/PysamTestModule_link_pre_489/__init__.py @@ -0,0 +1,3 @@ +from PysamTestModule_link_pre_489.BuildRead import build_read + +all = ["build_read"] diff --git a/linker_tests/link_pre_489/cy_build.py b/linker_tests/link_pre_489/cy_build.py new file mode 100644 index 000000000..fae705557 --- /dev/null +++ b/linker_tests/link_pre_489/cy_build.py @@ -0,0 +1,86 @@ +import os +import re +import sys + +try: + from Cython.Distutils import build_ext +except ImportError: + from setuptools.command.build_ext import build_ext + +from distutils.extension import Extension +from distutils.sysconfig import get_config_vars, get_python_lib, get_python_version +from pkg_resources import Distribution + + +if sys.platform == 'darwin': + config_vars = get_config_vars() + config_vars['LDSHARED'] = config_vars['LDSHARED'].replace('-bundle', '') + config_vars['SHLIB_EXT'] = '.so' + + +def is_pip_install(): + if "_" in os.environ and os.environ["_"].endswith("pip"): + return True + if "pip-egg-info" in sys.argv: + return True + if re.search("/pip-.*-build/", __file__): + return True + return False + + +class CyExtension(Extension): + def __init__(self, *args, **kwargs): + self._init_func = kwargs.pop("init_func", None) + Extension.__init__(self, *args, **kwargs) + + def extend_includes(self, includes): + self.include_dirs.extend(includes) + + def extend_macros(self, macros): + self.define_macros.extend(macros) + + def extend_extra_objects(self, objs): + self.extra_objects.extend(objs) + + +class cy_build_ext(build_ext): + + def _get_egg_name(self): + ei_cmd = self.get_finalized_command("egg_info") + return Distribution( + None, None, ei_cmd.egg_name, ei_cmd.egg_version, get_python_version(), + self.distribution.has_ext_modules() and self.plat_name).egg_name() + + def build_extension(self, ext): + + if isinstance(ext, CyExtension) and ext._init_func: + ext._init_func(ext) + + if not self.inplace: + ext.library_dirs.append(os.path.join(self.build_lib, "pysam")) + + if sys.platform == 'darwin': + # The idea is to give shared libraries an install name of the form + # `@rpath/`, and to set the rpath equal to + # @loader_path. This will allow Python packages to find the library + # in the expected place, while still giving enough flexibility to + # external applications to link against the library. + relative_module_path = ext.name.replace(".", os.sep) + get_config_vars()["SO"] + library_path = os.path.join( + "@rpath", os.path.basename(relative_module_path) + ) + + if not ext.extra_link_args: + ext.extra_link_args = [] + ext.extra_link_args += ['-dynamiclib', + '-rpath', '@loader_path', + '-Wl,-headerpad_max_install_names', + '-Wl,-install_name,%s' % library_path, + '-Wl,-x'] + else: + if not ext.extra_link_args: + ext.extra_link_args = [] + + ext.extra_link_args += ['-Wl,-rpath,$ORIGIN'] + + build_ext.build_extension(self, ext) diff --git a/linker_tests/link_pre_489/setup.py b/linker_tests/link_pre_489/setup.py new file mode 100644 index 000000000..5fc75d529 --- /dev/null +++ b/linker_tests/link_pre_489/setup.py @@ -0,0 +1,28 @@ +import glob +import sys +import os + +from setuptools import setup, find_packages, Extension +from cy_build import CyExtension as Extension, cy_build_ext as build_ext + +import pysam + +test_module_suffix = os.path.dirname(os.path.abspath(__file__)).split(os.sep)[-1] +test_module_name = "PysamTestModule_{}".format(test_module_suffix) + +TestModule = Extension( + "{}.BuildRead".format(test_module_name), + ["{}/BuildRead.pyx".format(test_module_name)], + include_dirs=pysam.get_include(), + extra_link_args=pysam.get_libraries(), + define_macros=pysam.get_defines(), +) + +setup( + name=test_module_name, + version='0.1', + packages=find_packages(), + package_dir={test_module_name: test_module_name}, + ext_modules=[TestModule], + cmdclass={'build_ext': build_ext}, +) diff --git a/linker_tests/link_pre_489/tests/test_module.py b/linker_tests/link_pre_489/tests/test_module.py new file mode 100644 index 000000000..46ba27a1a --- /dev/null +++ b/linker_tests/link_pre_489/tests/test_module.py @@ -0,0 +1,15 @@ +import unittest + +from PysamTestModule_link_pre_489 import build_read + + +class TestModule(unittest.TestCase): + + def test_pass_if_module_can_be_called(self): + read = build_read() + self.assertEqual(read.query_name, "hello") + self.assertEqual(read.query_sequence, "ACGT") + + +if __name__ == "__main__": + unittest.main() diff --git a/linker_tests/link_with_rpath/PysamTestModule_link_with_rpath/BuildRead.pyx b/linker_tests/link_with_rpath/PysamTestModule_link_with_rpath/BuildRead.pyx new file mode 100644 index 000000000..9c51e8f38 --- /dev/null +++ b/linker_tests/link_with_rpath/PysamTestModule_link_with_rpath/BuildRead.pyx @@ -0,0 +1,24 @@ +from __future__ import absolute_import + +from pysam.libchtslib cimport bam1_t, bam_endpos +from pysam.libcsamfile cimport aux_type2size +from pysam.libcalignedsegment cimport AlignedSegment + +import pysam + + +cpdef build_read(): + cdef AlignedSegment read = pysam.AlignedSegment() + read.query_name = "hello" + read.query_sequence = "ACGT" + read.reference_start = 10 + read.cigarstring = "4M" + + # Test calling htslib function + cdef bam1_t *calign = read._delegate + print(bam_endpos(calign)) + + # Test calling pysam htslib_util function + print(aux_type2size(12)) + + return read diff --git a/linker_tests/link_with_rpath/PysamTestModule_link_with_rpath/__init__.py b/linker_tests/link_with_rpath/PysamTestModule_link_with_rpath/__init__.py new file mode 100644 index 000000000..c4b1a0904 --- /dev/null +++ b/linker_tests/link_with_rpath/PysamTestModule_link_with_rpath/__init__.py @@ -0,0 +1,3 @@ +from PysamTestModule_link_with_rpath.BuildRead import build_read + +all = ["build_read"] diff --git a/linker_tests/link_with_rpath/setup.py b/linker_tests/link_with_rpath/setup.py new file mode 100644 index 000000000..2e5a8af80 --- /dev/null +++ b/linker_tests/link_with_rpath/setup.py @@ -0,0 +1,36 @@ +import glob +import sys +import os + +from setuptools import setup, find_packages, Extension +from Cython.Distutils import build_ext + +import pysam + +test_module_suffix = os.path.dirname(os.path.abspath(__file__)).split(os.sep)[-1] +test_module_name = "PysamTestModule_{}".format(test_module_suffix) + +pysam_libraries = pysam.get_libraries() +pysam_libdirs, pysam_libs = zip(*[os.path.split(x) for x in pysam_libraries]) +pysam_libdir = pysam_libdirs[0] +# remove lib and .so +pysam_libs = [x[3:-3] for x in pysam_libs] + +TestModule = Extension( + "{}.BuildRead".format(test_module_name), + ["{}/BuildRead.pyx".format(test_module_name)], + include_dirs=pysam.get_include(), + library_dirs=[pysam_libdir], + libraries=pysam_libs, + extra_link_args=['-Wl,-rpath,{}'.format(pysam_libdir)], + language="C", +) + +setup( + name=test_module_name, + version='0.1', + packages=find_packages(), + package_dir={test_module_name: test_module_name}, + ext_modules=[TestModule], + cmdclass={'build_ext': build_ext}, +) diff --git a/linker_tests/link_with_rpath/tests/test_module.py b/linker_tests/link_with_rpath/tests/test_module.py new file mode 100644 index 000000000..f8621b4a0 --- /dev/null +++ b/linker_tests/link_with_rpath/tests/test_module.py @@ -0,0 +1,15 @@ +import unittest + +from PysamTestModule_link_with_rpath import build_read + + +class TestModule(unittest.TestCase): + + def test_pass_if_module_can_be_called(self): + read = build_read() + self.assertEqual(read.query_name, "hello") + self.assertEqual(read.query_sequence, "ACGT") + + +if __name__ == "__main__": + unittest.main() diff --git a/linker_tests/link_without_rpath/PysamTestModule_link_without_rpath/BuildRead.pyx b/linker_tests/link_without_rpath/PysamTestModule_link_without_rpath/BuildRead.pyx new file mode 100644 index 000000000..9c51e8f38 --- /dev/null +++ b/linker_tests/link_without_rpath/PysamTestModule_link_without_rpath/BuildRead.pyx @@ -0,0 +1,24 @@ +from __future__ import absolute_import + +from pysam.libchtslib cimport bam1_t, bam_endpos +from pysam.libcsamfile cimport aux_type2size +from pysam.libcalignedsegment cimport AlignedSegment + +import pysam + + +cpdef build_read(): + cdef AlignedSegment read = pysam.AlignedSegment() + read.query_name = "hello" + read.query_sequence = "ACGT" + read.reference_start = 10 + read.cigarstring = "4M" + + # Test calling htslib function + cdef bam1_t *calign = read._delegate + print(bam_endpos(calign)) + + # Test calling pysam htslib_util function + print(aux_type2size(12)) + + return read diff --git a/linker_tests/link_without_rpath/PysamTestModule_link_without_rpath/__init__.py b/linker_tests/link_without_rpath/PysamTestModule_link_without_rpath/__init__.py new file mode 100644 index 000000000..722c5d063 --- /dev/null +++ b/linker_tests/link_without_rpath/PysamTestModule_link_without_rpath/__init__.py @@ -0,0 +1,3 @@ +from PysamTestModule_link_without_rpath.BuildRead import build_read + +all = ["build_read"] diff --git a/linker_tests/link_without_rpath/setup.py b/linker_tests/link_without_rpath/setup.py new file mode 100644 index 000000000..7846e4b6e --- /dev/null +++ b/linker_tests/link_without_rpath/setup.py @@ -0,0 +1,35 @@ +import glob +import sys +import os + +from setuptools import setup, find_packages, Extension +from Cython.Distutils import build_ext + +import pysam + +test_module_suffix = os.path.dirname(os.path.abspath(__file__)).split(os.sep)[-1] +test_module_name = "PysamTestModule_{}".format(test_module_suffix) + +pysam_libraries = pysam.get_libraries() +pysam_libdirs, pysam_libs = zip(*[os.path.split(x) for x in pysam_libraries]) +pysam_libdir = pysam_libdirs[0] +# remove lib and .so +pysam_libs = [x[3:-3] for x in pysam_libs] + +TestModule = Extension( + "{}.BuildRead".format(test_module_name), + ["{}/BuildRead.pyx".format(test_module_name)], + include_dirs=pysam.get_include(), + library_dirs=[pysam_libdir], + libraries=pysam_libs, + language="C", +) + +setup( + name=test_module_name, + version='0.1', + packages=find_packages(), + package_dir={test_module_name: test_module_name}, + ext_modules=[TestModule], + cmdclass={'build_ext': build_ext}, +) diff --git a/linker_tests/link_without_rpath/tests/test_module.py b/linker_tests/link_without_rpath/tests/test_module.py new file mode 100644 index 000000000..1da5bbca3 --- /dev/null +++ b/linker_tests/link_without_rpath/tests/test_module.py @@ -0,0 +1,15 @@ +import unittest + +from PysamTestModule_link_without_rpath import build_read + + +class TestModule(unittest.TestCase): + + def test_pass_if_module_can_be_called(self): + read = build_read() + self.assertEqual(read.query_name, "hello") + self.assertEqual(read.query_sequence, "ACGT") + + +if __name__ == "__main__": + unittest.main() diff --git a/pysam/Pileup.py b/pysam/Pileup.py index 998127b03..1fe05ecc4 100644 --- a/pysam/Pileup.py +++ b/pysam/Pileup.py @@ -2,36 +2,37 @@ import collections import pysam -PileupSubstitution = collections.namedtuple( "PileupSubstitution", - " ".join( (\ - "chromosome", - "pos", - "reference_base", - "genotype", - "consensus_quality", - "snp_quality", - "mapping_quality", - "coverage", - "read_bases", - "base_qualities" ) ) ) - -PileupIndel = collections.namedtuple( "PileupIndel", - " ".join( (\ - "chromosome", - "pos", - "reference_base", - "genotype", - "consensus_quality", - "snp_quality", - "mapping_quality", - "coverage", - "first_allele", - "second_allele", - "reads_first", - "reads_second", - "reads_diff" ) ) ) - -def iterate( infile ): +PileupSubstitution = collections.namedtuple("PileupSubstitution", + " ".join(( + "chromosome", + "pos", + "reference_base", + "genotype", + "consensus_quality", + "snp_quality", + "mapping_quality", + "coverage", + "read_bases", + "base_qualities"))) + +PileupIndel = collections.namedtuple("PileupIndel", + " ".join(( + "chromosome", + "pos", + "reference_base", + "genotype", + "consensus_quality", + "snp_quality", + "mapping_quality", + "coverage", + "first_allele", + "second_allele", + "reads_first", + "reads_second", + "reads_diff"))) + + +def iterate(infile): '''iterate over ``samtools pileup -c`` formatted file. *infile* can be any iterator over a lines. @@ -39,25 +40,29 @@ def iterate( infile ): The function yields named tuples of the type :class:`pysam.Pileup.PileupSubstitution` or :class:`pysam.Pileup.PileupIndel`. - .. note:: + .. note:: + The parser converts to 0-based coordinates ''' - - conv_subst = (str,lambda x: int(x)-1,str,str,int,int,int,int,str,str) - conv_indel = (str,lambda x: int(x)-1,str,str,int,int,int,int,str,str,int,int,int) + + conv_subst = (str, lambda x: int(x) - 1, str, + str, int, int, int, int, str, str) + conv_indel = (str, lambda x: int(x) - 1, str, str, int, + int, int, int, str, str, int, int, int) for line in infile: d = line[:-1].split() if d[2] == "*": try: - yield PileupIndel( *[x(y) for x,y in zip(conv_indel,d) ] ) + yield PileupIndel(*[x(y) for x, y in zip(conv_indel, d)]) except TypeError: - raise pysam.SamtoolsError( "parsing error in line: `%s`" % line) + raise pysam.SamtoolsError("parsing error in line: `%s`" % line) else: try: - yield PileupSubstitution( *[x(y) for x,y in zip(conv_subst,d) ] ) + yield PileupSubstitution(*[x(y) for x, y in zip(conv_subst, d)]) except TypeError: - raise pysam.SamtoolsError( "parsing error in line: `%s`" % line) + raise pysam.SamtoolsError("parsing error in line: `%s`" % line) + ENCODE_GENOTYPE = { 'A': 'A', 'C': 'C', 'G': 'G', 'T': 'T', @@ -68,7 +73,7 @@ def iterate( infile ): 'GT': 'k', 'TG': 'K', 'CG': 's', 'GC': 'S', 'AT': 'w', 'TA': 'W', - } +} DECODE_GENOTYPE = { 'A': 'AA', @@ -81,59 +86,67 @@ def iterate( infile ): 'k': 'GT', 'K': 'GT', 's': 'CG', 'S': 'CG', 'w': 'AT', 'W': 'AT', - } +} + +# ------------------------------------------------------------ + -##------------------------------------------------------------ -def encodeGenotype( code ): +def encodeGenotype(code): '''encode genotypes like GG, GA into a one-letter code. The returned code is lower case if code[0] < code[1], otherwise it is uppercase. ''' - return ENCODE_GENOTYPE[ code.upper() ] + return ENCODE_GENOTYPE[code.upper()] -def decodeGenotype( code ): + +def decodeGenotype(code): '''decode single letter genotypes like m, M into two letters. This is the reverse operation to :meth:`encodeGenotype`. ''' - return DECODE_GENOTYPE[ code ] + return DECODE_GENOTYPE[code] + -def translateIndelGenotypeFromVCF( vcf_genotypes, ref ): +def translateIndelGenotypeFromVCF(vcf_genotypes, ref): '''translate indel from vcf to pileup format.''' # indels - def getPrefix( s1, s2 ): + def getPrefix(s1, s2): '''get common prefix of strings s1 and s2.''' - n = min( len( s1), len( s2 ) ) - for x in range( n ): - if s1[x] != s2[x]: return s1[:x] + n = min(len(s1), len(s2)) + for x in range(n): + if s1[x] != s2[x]: + return s1[:x] return s1[:n] - def getSuffix( s1, s2 ): + def getSuffix(s1, s2): '''get common sufix of strings s1 and s2.''' - n = min( len( s1), len( s2 ) ) - if s1[-1] != s2[-1]: return "" - for x in range( -2, -n - 1, -1 ): - if s1[x] != s2[x]: return s1[x+1:] + n = min(len(s1), len(s2)) + if s1[-1] != s2[-1]: + return "" + for x in range(-2, -n - 1, -1): + if s1[x] != s2[x]: + return s1[x + 1:] return s1[-n:] - def getGenotype( variant, ref ): + def getGenotype(variant, ref): + + if variant == ref: + return "*", 0 - if variant == ref: return "*", 0 - if len(ref) > len(variant): # is a deletion if ref.startswith(variant): return "-%s" % ref[len(variant):], len(variant) - 1 - elif ref.endswith( variant ): + elif ref.endswith(variant): return "-%s" % ref[:-len(variant)], -1 else: - prefix = getPrefix( ref, variant ) - suffix = getSuffix( ref, variant ) - shared = len(prefix) + len(suffix) - len(variant) + prefix = getPrefix(ref, variant) + suffix = getSuffix(ref, variant) + shared = len(prefix) + len(suffix) - len(variant) # print "-", prefix, suffix, ref, variant, shared, len(prefix), len(suffix), len(ref) if shared < 0: raise ValueError() - return "-%s" % ref[len(prefix):-(len(suffix)-shared)], len(prefix) - 1 + return "-%s" % ref[len(prefix):-(len(suffix) - shared)], len(prefix) - 1 elif len(ref) < len(variant): # is an insertion @@ -142,47 +155,49 @@ def getGenotype( variant, ref ): elif variant.endswith(ref): return "+%s" % variant[:len(ref)], 0 else: - prefix = getPrefix( ref, variant ) - suffix = getSuffix( ref, variant ) - shared = len(prefix) + len(suffix) - len(ref) + prefix = getPrefix(ref, variant) + suffix = getSuffix(ref, variant) + shared = len(prefix) + len(suffix) - len(ref) if shared < 0: raise ValueError() - return "+%s" % variant[len(prefix):-(len(suffix)-shared)], len(prefix) + return "+%s" % variant[len(prefix):-(len(suffix) - shared)], len(prefix) else: assert 0, "snp?" # in pileup, the position refers to the base # after the coordinate, hence subtract 1 - #pos -= 1 + # pos -= 1 genotypes, offsets = [], [] is_error = True for variant in vcf_genotypes: try: - g, offset = getGenotype( variant, ref ) + g, offset = getGenotype(variant, ref) except ValueError: break - genotypes.append( g ) - if g != "*": offsets.append( offset ) - - else: + genotypes.append(g) + if g != "*": + offsets.append(offset) + + else: is_error = False - if is_error: + if is_error: raise ValueError() - assert len(set(offsets )) == 1, "multiple offsets for indel" + assert len(set(offsets)) == 1, "multiple offsets for indel" offset = offsets[0] - genotypes = "/".join( genotypes ) + genotypes = "/".join(genotypes) return genotypes, offset -def vcf2pileup( vcf, sample ): + +def vcf2pileup(vcf, sample): '''convert vcf record to pileup record.''' - + chromosome = vcf.contig pos = vcf.pos reference = vcf.ref @@ -193,79 +208,75 @@ def vcf2pileup( vcf, sample ): # get genotype genotypes = data["GT"] if len(genotypes) > 1: - raise ValueError( "only single genotype per position, %s" % (str(vcf))) + raise ValueError("only single genotype per position, %s" % (str(vcf))) genotypes = genotypes[0] # not a variant - if genotypes[0] == ".": return None + if genotypes[0] == ".": + return None - genotypes = [ allelles[int(x)] for x in genotypes if x != "/" ] + genotypes = [allelles[int(x)] for x in genotypes if x != "/"] # snp_quality is "genotype quality" - snp_quality = consensus_quality = data.get( "GQ", [0])[0] - mapping_quality = vcf.info.get( "MQ", [0])[0] - coverage = data.get( "DP", 0) + snp_quality = consensus_quality = data.get("GQ", [0])[0] + mapping_quality = vcf.info.get("MQ", [0])[0] + coverage = data.get("DP", 0) - if len(reference) > 1 or max([len(x) for x in vcf.alt] ) > 1: + if len(reference) > 1 or max([len(x) for x in vcf.alt]) > 1: # indel - genotype, offset = translateIndelGenotypeFromVCF( genotypes, reference ) - - return PileupIndel( chromosome, - pos + offset, - "*", - genotype, - consensus_quality, - snp_quality, - mapping_quality, - coverage, - genotype, - "<" * len(genotype), - 0, - 0, - 0 ) - - else: - - genotype = encodeGenotype( "".join(genotypes) ) + genotype, offset = translateIndelGenotypeFromVCF(genotypes, reference) + + return PileupIndel(chromosome, + pos + offset, + "*", + genotype, + consensus_quality, + snp_quality, + mapping_quality, + coverage, + genotype, + "<" * len(genotype), + 0, + 0, + 0) - + else: + genotype = encodeGenotype("".join(genotypes)) read_bases = "" base_qualities = "" - return PileupSubstitution( chromosome, pos, reference, - genotype, - consensus_quality, - snp_quality, - mapping_quality, - coverage, read_bases, base_qualities ) + return PileupSubstitution(chromosome, pos, reference, + genotype, consensus_quality, + snp_quality, mapping_quality, + coverage, read_bases, + base_qualities) -def iterate_from_vcf( infile, sample ): +def iterate_from_vcf(infile, sample): '''iterate over a vcf-formatted file. *infile* can be any iterator over a lines. - The function yields named tuples of the type :class:`pysam.Pileup.PileupSubstitution` - or :class:`pysam.Pileup.PileupIndel`. + The function yields named tuples of the type + :class:`pysam.Pileup.PileupSubstitution` or + :class:`pysam.Pileup.PileupIndel`. - Positions without a snp will be skipped. + Positions without a snp will be skipped. - This method is wasteful and written to support same - legacy code that expects samtools pileup output. + This method is wasteful and written to support same legacy code + that expects samtools pileup output. Better use the vcf parser directly. ''' - - vcf = pysam.VCF() - vcf.connect( infile ) + vcf.connect(infile) if sample not in vcf.getsamples(): - raise KeyErorr( "sample %s not vcf file" ) + raise KeyError("sample %s not vcf file") for row in vcf.fetch(): - result = vcf2pileup( row, sample ) - if result: yield result - + result = vcf2pileup(row, sample) + if result: + yield result diff --git a/pysam/__init__.py b/pysam/__init__.py index ed17e04c0..40877da05 100644 --- a/pysam/__init__.py +++ b/pysam/__init__.py @@ -3,12 +3,16 @@ import sysconfig from pysam.libchtslib import * +from pysam.libcsamtools import * +from pysam.libcbcftools import * from pysam.libcutils import * import pysam.libcutils as libcutils import pysam.libcfaidx as libcfaidx from pysam.libcfaidx import * import pysam.libctabix as libctabix from pysam.libctabix import * +# import pysam.libctabixproxies as libctabixproxies +# from pysam.libctabixproxies import * import pysam.libcsamfile as libcsamfile from pysam.libcsamfile import * import pysam.libcalignmentfile as libcalignmentfile @@ -36,6 +40,7 @@ libcbcf.__all__ +\ libcbgzf.__all__ +\ libcfaidx.__all__ +\ + libctabixproxies.__all__ +\ libcalignmentfile.__all__ +\ libcalignedsegment.__all__ +\ libcsamfile.__all__ +\ @@ -72,8 +77,9 @@ def get_include(): def get_defines(): '''return a list of defined compilation parameters.''' - return [] #('_FILE_OFFSET_BITS', '64'), + # ('_FILE_OFFSET_BITS', '64'), # ('_USE_KNETFILE', '')] + return [] def get_libraries(): diff --git a/pysam/cbcftools_util.h b/pysam/cbcftools_util.h new file mode 100644 index 000000000..4a9f2e9ca --- /dev/null +++ b/pysam/cbcftools_util.h @@ -0,0 +1,6 @@ +#ifndef CBCFTOOLS_UTIL_H +#define CBCFTOOLS_UTIL_H + +int bcftools_main(int argc, char *argv[]); + +#endif diff --git a/pysam/csamtools_util.h b/pysam/csamtools_util.h new file mode 100644 index 000000000..0a03c1389 --- /dev/null +++ b/pysam/csamtools_util.h @@ -0,0 +1,6 @@ +#ifndef CSAMTOOLS_UTIL_H +#define CSAMTOOLS_UTIL_H + +int samtools_main(int argc, char *argv[]); + +#endif diff --git a/pysam/htslib_util.c b/pysam/htslib_util.c index 28eeca209..08309006e 100644 --- a/pysam/htslib_util.c +++ b/pysam/htslib_util.c @@ -22,17 +22,14 @@ int hts_set_verbosity(int verbosity) return old_verbosity; } -int hts_get_verbosity() +int hts_get_verbosity(void) { return hts_verbose; } -int hts_get_hts_verbose(); - - // taken from samtools/bam_import.c -static inline uint8_t *alloc_data(bam1_t *b, size_t size) +static inline uint8_t * alloc_data(bam1_t *b, size_t size) { if (b->m_data < size) { @@ -47,6 +44,7 @@ static inline uint8_t *alloc_data(bam1_t *b, size_t size) // Adds *nbytes_new* - *nbytes_old* into the variable length data of *src* at *pos*. // Data within the bam1_t entry is moved so that it is // consistent with the data field lengths. +// Return NULL on error (memory allocation) bam1_t * pysam_bam_update(bam1_t * b, const size_t nbytes_old, const size_t nbytes_new, @@ -55,7 +53,8 @@ bam1_t * pysam_bam_update(bam1_t * b, int d = nbytes_new - nbytes_old; int new_size; size_t nbytes_before; - + uint8_t * retval = NULL; + // no change if (d == 0) return b; @@ -75,7 +74,9 @@ bam1_t * pysam_bam_update(bam1_t * b, // increase memory if required if (d > 0) { - alloc_data(b, new_size); + retval = alloc_data(b, new_size); + if (retval == NULL) + return NULL; field_start = b->data + nbytes_before; } @@ -156,6 +157,3 @@ int aux_type2size(uint8_t type) return 0; } } - - - diff --git a/pysam/htslib_util.h b/pysam/htslib_util.h index f0d582cce..25bd3e496 100644 --- a/pysam/htslib_util.h +++ b/pysam/htslib_util.h @@ -9,7 +9,7 @@ int hts_useek(htsFile *fp, long uoffset, int where); long hts_utell(htsFile *fp); int hts_set_verbosity(int verbosity); -int hts_get_verbosity(); +int hts_get_verbosity(void); KHASH_MAP_INIT_STR(vdict, bcf_idinfo_t) @@ -44,7 +44,7 @@ typedef khash_t(s2i) s2i_t; Old data is deleted and the data within b are re-arranged to make place for new data. - @discussion Returns b + @discussion Return NULL on error, otherwise b is returned. @param b bam1_t data @param nbytes_old size of old data @@ -92,38 +92,16 @@ static inline int pysam_bam_get_l_aux(bam1_t * b) { static inline char pysam_bam_seqi(uint8_t * s, int i) { return bam_seqi(s,i);} -// Wrapping bit field access in bam1_core_t -// bit fields not supported in cython and due -// to endian-ness it is not clear which part -// of the bit-field is in the higher or lower bytes. -static inline uint16_t pysam_get_bin(bam1_t * b) { - return b->core.bin;} - static inline uint8_t pysam_get_qual(bam1_t * b) { return b->core.qual;} -static inline uint8_t pysam_get_l_qname(bam1_t * b) { - return b->core.l_qname;} - -static inline uint16_t pysam_get_flag(bam1_t * b) { - return b->core.flag;} - -static inline uint16_t pysam_get_n_cigar(bam1_t * b) { +static inline uint32_t pysam_get_n_cigar(bam1_t * b) { return b->core.n_cigar;} -static inline void pysam_set_bin(bam1_t * b, uint16_t v) { - b->core.bin=v;} - static inline void pysam_set_qual(bam1_t * b, uint8_t v) { b->core.qual=v;} -static inline void pysam_set_l_qname(bam1_t * b, uint8_t v) { - b->core.l_qname=v;} - -static inline void pysam_set_flag(bam1_t * b, uint16_t v) { - b->core.flag=v;} - -static inline void pysam_set_n_cigar(bam1_t * b, uint16_t v) { +static inline void pysam_set_n_cigar(bam1_t * b, uint32_t v) { b->core.n_cigar=v;} static inline void pysam_update_flag(bam1_t * b, uint16_t v, uint16_t flag) { @@ -133,5 +111,4 @@ static inline void pysam_update_flag(bam1_t * b, uint16_t v, uint16_t flag) { b->core.flag &= ~flag; } - #endif diff --git a/pysam/libcalignedsegment.c b/pysam/libcalignedsegment.c index 294dacbe9..68549a4f3 100644 --- a/pysam/libcalignedsegment.c +++ b/pysam/libcalignedsegment.c @@ -567,6 +567,7 @@ static CYTHON_INLINE float __PYX_NAN() { #include #include #include +#include "stdarg.h" #include "htslib/kstring.h" #include "htslib_util.h" #include "htslib/hfile.h" @@ -577,10 +578,9 @@ static CYTHON_INLINE float __PYX_NAN() { #include "htslib/tbx.h" #include "htslib/vcf.h" #include "htslib/vcfutils.h" +#include "htslib/cram.h" #include "pythread.h" #include "pysam_stream.h" -#include "samfile_util.h" -#include "pysam_util.h" #include "pystate.h" #ifdef _OPENMP #include @@ -787,6 +787,7 @@ static const char *__pyx_filename; static const char *__pyx_f[] = { "pysam/libcalignedsegment.pyx", "stringsource", + "pysam/libcalignedsegment.pxd", "array.pxd", "pysam/libchtslib.pxd", "type.pxd", @@ -912,10 +913,11 @@ typedef struct arrayobject arrayobject; struct __pyx_obj_5pysam_10libchtslib_HTSFile; struct __pyx_obj_5pysam_9libcfaidx_FastaFile; struct __pyx_obj_5pysam_9libcfaidx_FastqProxy; -struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy; +struct __pyx_obj_5pysam_9libcfaidx_FastxRecord; struct __pyx_obj_5pysam_9libcfaidx_FastxFile; struct __pyx_obj_5pysam_9libcfaidx_FastqFile; struct __pyx_obj_5pysam_9libcfaidx_Fastafile; +struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader; struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile; struct __pyx_obj_5pysam_17libcalignmentfile_PileupColumn; struct __pyx_obj_5pysam_17libcalignmentfile_PileupRead; @@ -934,15 +936,18 @@ struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn; struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead; struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr; struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr; +struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict; +struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr; +struct __pyx_obj___Pyx_EnumMeta; struct __pyx_array_obj; struct __pyx_MemviewEnum_obj; struct __pyx_memoryview_obj; struct __pyx_memoryviewslice_obj; struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array; -struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array; +struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array; -/* "pysam/libcfaidx.pxd":48 - * cdef kseq_t * _delegate +/* "pysam/libcfaidx.pxd":49 + * cdef cython.str to_string(self) * cdef cython.str tostring(self) * cpdef array.array get_quality_array(self, int offset=*) # <<<<<<<<<<<<<< * @@ -953,22 +958,22 @@ struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array { int offset; }; -/* "pysam/libcfaidx.pxd":57 - * cdef public str comment, quality, sequence, name +/* "pysam/libcfaidx.pxd":59 + * cdef cython.str to_string(self) * cdef cython.str tostring(self) * cpdef array.array get_quality_array(self, int offset=*) # <<<<<<<<<<<<<< * - * + * cdef class FastxFile: */ -struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array { +struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array { int __pyx_n; int offset; }; struct __pyx_t_5pysam_17libcalignmentfile___iterdata; typedef struct __pyx_t_5pysam_17libcalignmentfile___iterdata __pyx_t_5pysam_17libcalignmentfile___iterdata; -struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData; +struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator; -/* "pysam/libcalignmentfile.pxd":29 +/* "pysam/libcalignmentfile.pxd":24 * # Utility types * * ctypedef struct __iterdata: # <<<<<<<<<<<<<< @@ -983,16 +988,23 @@ struct __pyx_t_5pysam_17libcalignmentfile___iterdata { int tid; char *seq; int seq_len; + int min_mapping_quality; + int flag_require; + int flag_filter; + int compute_baq; + int redo_baq; + int ignore_orphans; + int adjust_capq_threshold; }; -/* "pysam/libcalignmentfile.pxd":131 - * cdef char * getSequence(self) - * cdef setMask(self, mask) - * cdef setupIteratorData(self, # <<<<<<<<<<<<<< - * int tid, - * int start, +/* "pysam/libcalignmentfile.pxd":138 + * cdef int cnext(self) + * cdef char * get_sequence(self) + * cdef _setup_iterator(self, # <<<<<<<<<<<<<< + * int tid, + * int start, */ -struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData { +struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator { int __pyx_n; int multiple_iterators; }; @@ -1118,19 +1130,20 @@ struct __pyx_opt_args_5pysam_9libcutils_force_bytes { }; struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag; struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag; -struct __pyx_opt_args_5pysam_18libcalignedsegment_get_value_code; -struct __pyx_opt_args_5pysam_18libcalignedsegment_getTypecode; +struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring; +struct __pyx_opt_args_5pysam_18libcalignedsegment_get_tag_typecode; +struct __pyx_opt_args_5pysam_18libcalignedsegment_get_btag_typecode; -/* "pysam/libcalignedsegment.pxd":36 +/* "pysam/libcalignedsegment.pxd":30 * - * from pysam.libcalignmentfile cimport AlignmentFile + * from pysam.libcalignmentfile cimport AlignmentFile, AlignmentHeader * ctypedef AlignmentFile AlignmentFile_t # <<<<<<<<<<<<<< * * */ typedef struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t; -/* "pysam/libcalignedsegment.pxd":56 +/* "pysam/libcalignedsegment.pxd":50 * # add an alignment tag with value to the AlignedSegment * # an existing tag of the same name will be replaced. * cpdef set_tag(self, tag, value, value_type=?, replace=?) # <<<<<<<<<<<<<< @@ -1143,7 +1156,7 @@ struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag { PyObject *replace; }; -/* "pysam/libcalignedsegment.pxd":60 +/* "pysam/libcalignedsegment.pxd":54 * # add an alignment tag with value to the AlignedSegment * # an existing tag of the same name will be replaced. * cpdef get_tag(self, tag, with_value_type=?) # <<<<<<<<<<<<<< @@ -1155,31 +1168,86 @@ struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag { PyObject *with_value_type; }; -/* "pysam/libcalignedsegment.pyx":145 +/* "pysam/libcalignedsegment.pxd":63 + * + * # returns a valid sam alignment string (deprecated) + * cpdef tostring(self, htsfile=*) # <<<<<<<<<<<<<< + * + * + */ +struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring { + int __pyx_n; + PyObject *htsfile; +}; + +/* "pysam/libcalignedsegment.pyx":3205 + * + * + * cpdef enum CIGAR_OPS: # <<<<<<<<<<<<<< + * CMATCH = 0 + * CINS = 1 + */ +enum __pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS { + __pyx_e_5pysam_18libcalignedsegment_CMATCH = 0, + __pyx_e_5pysam_18libcalignedsegment_CINS = 1, + __pyx_e_5pysam_18libcalignedsegment_CDEL = 2, + __pyx_e_5pysam_18libcalignedsegment_CREF_SKIP = 3, + __pyx_e_5pysam_18libcalignedsegment_CSOFT_CLIP = 4, + __pyx_e_5pysam_18libcalignedsegment_CHARD_CLIP = 5, + __pyx_e_5pysam_18libcalignedsegment_CPAD = 6, + __pyx_e_5pysam_18libcalignedsegment_CEQUAL = 7, + __pyx_e_5pysam_18libcalignedsegment_CDIFF = 8, + __pyx_e_5pysam_18libcalignedsegment_CBACK = 9 +}; + +/* "pysam/libcalignedsegment.pyx":3218 + * + * + * cpdef enum SAM_FLAGS: # <<<<<<<<<<<<<< + * # the read is paired in sequencing, no matter whether it is mapped in a pair + * FPAIRED = 1 + */ +enum __pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS { + __pyx_e_5pysam_18libcalignedsegment_FPAIRED = 1, + __pyx_e_5pysam_18libcalignedsegment_FPROPER_PAIR = 2, + __pyx_e_5pysam_18libcalignedsegment_FUNMAP = 4, + __pyx_e_5pysam_18libcalignedsegment_FMUNMAP = 8, + __pyx_e_5pysam_18libcalignedsegment_FREVERSE = 16, + __pyx_e_5pysam_18libcalignedsegment_FMREVERSE = 32, + __pyx_e_5pysam_18libcalignedsegment_FREAD1 = 64, + __pyx_e_5pysam_18libcalignedsegment_FREAD2 = 0x80, + __pyx_e_5pysam_18libcalignedsegment_FSECONDARY = 0x100, + __pyx_e_5pysam_18libcalignedsegment_FQCFAIL = 0x200, + __pyx_e_5pysam_18libcalignedsegment_FDUP = 0x400, + __pyx_e_5pysam_18libcalignedsegment_FSUPPLEMENTARY = 0x800 +}; + +/* "pysam/libcalignedsegment.pyx":223 * * - * cdef inline uint8_t get_value_code(value, value_type=None): # <<<<<<<<<<<<<< - * '''guess type code for a *value*. If *value_type* is None, - * the type code will be inferred based on the Python type of + * cdef inline uint8_t get_tag_typecode(value, value_type=None): # <<<<<<<<<<<<<< + * """guess type code for a *value*. If *value_type* is None, the type + * code will be inferred based on the Python type of *value* */ -struct __pyx_opt_args_5pysam_18libcalignedsegment_get_value_code { +struct __pyx_opt_args_5pysam_18libcalignedsegment_get_tag_typecode { int __pyx_n; PyObject *value_type; }; -/* "pysam/libcalignedsegment.pyx":177 +/* "pysam/libcalignedsegment.pyx":265 * * - * cdef inline bytes getTypecode(value, maximum_value=None): # <<<<<<<<<<<<<< + * cdef inline uint8_t get_btag_typecode(value, min_value=None, max_value=None): # <<<<<<<<<<<<<< * '''returns the value typecode of a value. * */ -struct __pyx_opt_args_5pysam_18libcalignedsegment_getTypecode { +struct __pyx_opt_args_5pysam_18libcalignedsegment_get_btag_typecode { int __pyx_n; - PyObject *maximum_value; + PyObject *min_value; + PyObject *max_value; }; -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -1193,6 +1261,7 @@ struct __pyx_obj_5pysam_10libchtslib_HTSFile { int64_t start_offset; PyObject *filename; PyObject *mode; + PyObject *threads; PyObject *index_filename; int is_stream; int is_remote; @@ -1224,7 +1293,7 @@ struct __pyx_obj_5pysam_9libcfaidx_FastaFile { * * cdef class FastqProxy: # <<<<<<<<<<<<<< * cdef kseq_t * _delegate - * cdef cython.str tostring(self) + * cdef cython.str to_string(self) */ struct __pyx_obj_5pysam_9libcfaidx_FastqProxy { PyObject_HEAD @@ -1233,16 +1302,16 @@ struct __pyx_obj_5pysam_9libcfaidx_FastqProxy { }; -/* "pysam/libcfaidx.pxd":51 +/* "pysam/libcfaidx.pxd":52 * * - * cdef class PersistentFastqProxy: # <<<<<<<<<<<<<< + * cdef class FastxRecord: # <<<<<<<<<<<<<< * """ * Python container for pysam.libcfaidx.FastqProxy with persistence. */ -struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy { +struct __pyx_obj_5pysam_9libcfaidx_FastxRecord { PyObject_HEAD - struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_vtab; + struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *__pyx_vtab; PyObject *comment; PyObject *quality; PyObject *sequence; @@ -1250,8 +1319,8 @@ struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy { }; -/* "pysam/libcfaidx.pxd":60 - * +/* "pysam/libcfaidx.pxd":61 + * cpdef array.array get_quality_array(self, int offset=*) * * cdef class FastxFile: # <<<<<<<<<<<<<< * cdef object _filename @@ -1268,7 +1337,7 @@ struct __pyx_obj_5pysam_9libcfaidx_FastxFile { }; -/* "pysam/libcfaidx.pxd":72 +/* "pysam/libcfaidx.pxd":73 * * # Compatibility Layer for pysam 0.8.1 * cdef class FastqFile(FastxFile): # <<<<<<<<<<<<<< @@ -1280,7 +1349,7 @@ struct __pyx_obj_5pysam_9libcfaidx_FastqFile { }; -/* "pysam/libcfaidx.pxd":77 +/* "pysam/libcfaidx.pxd":78 * * # Compatibility Layer for pysam < 0.8 * cdef class Fastafile(FastaFile): # <<<<<<<<<<<<<< @@ -1292,23 +1361,36 @@ struct __pyx_obj_5pysam_9libcfaidx_Fastafile { }; -/* "pysam/libcalignmentfile.pxd":39 +/* "pysam/libcalignmentfile.pxd":41 + * + * + * cdef class AlignmentHeader(object): # <<<<<<<<<<<<<< + * cdef bam_hdr_t *ptr * + */ +struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader { + PyObject_HEAD + bam_hdr_t *ptr; +}; + + +/* "pysam/libcalignmentfile.pxd":44 + * cdef bam_hdr_t *ptr * * cdef class AlignmentFile(HTSFile): # <<<<<<<<<<<<<< * cdef readonly object reference_filename - * + * cdef readonly AlignmentHeader header */ struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile { struct __pyx_obj_5pysam_10libchtslib_HTSFile __pyx_base; PyObject *reference_filename; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; hts_idx_t *index; - bam_hdr_t *header; bam1_t *b; }; -/* "pysam/libcalignmentfile.pxd":57 +/* "pysam/libcalignmentfile.pxd":61 * * * cdef class PileupColumn: # <<<<<<<<<<<<<< @@ -1324,7 +1406,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_PileupColumn { }; -/* "pysam/libcalignmentfile.pxd":64 +/* "pysam/libcalignmentfile.pxd":68 * * * cdef class PileupRead: # <<<<<<<<<<<<<< @@ -1344,7 +1426,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_PileupRead { }; -/* "pysam/libcalignmentfile.pxd":75 +/* "pysam/libcalignmentfile.pxd":79 * * * cdef class IteratorRow: # <<<<<<<<<<<<<< @@ -1357,12 +1439,13 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow { bam1_t *b; struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *samfile; htsFile *htsfile; - bam_hdr_t *header; + hts_idx_t *index; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; int owns_samfile; }; -/* "pysam/libcalignmentfile.pxd":84 +/* "pysam/libcalignmentfile.pxd":89 * * * cdef class IteratorRowRegion(IteratorRow): # <<<<<<<<<<<<<< @@ -1376,8 +1459,8 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion { }; -/* "pysam/libcalignmentfile.pxd":89 - * cdef int cnext(self) +/* "pysam/libcalignmentfile.pxd":95 + * * * cdef class IteratorRowHead(IteratorRow): # <<<<<<<<<<<<<< * cdef int max_rows @@ -1391,8 +1474,8 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead { }; -/* "pysam/libcalignmentfile.pxd":95 - * cdef int cnext(self) +/* "pysam/libcalignmentfile.pxd":102 + * * * cdef class IteratorRowAll(IteratorRow): # <<<<<<<<<<<<<< * cdef bam1_t * getCurrent(self) @@ -1404,7 +1487,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll { }; -/* "pysam/libcalignmentfile.pxd":100 +/* "pysam/libcalignmentfile.pxd":107 * * * cdef class IteratorRowAllRefs(IteratorRow): # <<<<<<<<<<<<<< @@ -1418,7 +1501,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs { }; -/* "pysam/libcalignmentfile.pxd":105 +/* "pysam/libcalignmentfile.pxd":112 * * * cdef class IteratorRowSelection(IteratorRow): # <<<<<<<<<<<<<< @@ -1433,7 +1516,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection { }; -/* "pysam/libcalignmentfile.pxd":112 +/* "pysam/libcalignmentfile.pxd":119 * * * cdef class IteratorColumn: # <<<<<<<<<<<<<< @@ -1447,33 +1530,34 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn { int tid; int pos; int n_plp; - int mask; + uint32_t min_base_quality; bam_pileup1_t *plp; - bam_plp_t pileup_iter; + bam_mplp_t pileup_iter; __pyx_t_5pysam_17libcalignmentfile___iterdata iterdata; struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *samfile; - struct __pyx_obj_5pysam_9libcfaidx_Fastafile *fastafile; + struct __pyx_obj_5pysam_9libcfaidx_FastaFile *fastafile; PyObject *stepper; int max_depth; + int ignore_overlaps; }; -/* "pysam/libcalignmentfile.pxd":141 +/* "pysam/libcalignmentfile.pxd":150 * * * cdef class IteratorColumnRegion(IteratorColumn): # <<<<<<<<<<<<<< * cdef int start - * cdef int end + * cdef int stop */ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion { struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn __pyx_base; int start; - int end; + int stop; int truncate; }; -/* "pysam/libcalignmentfile.pxd":147 +/* "pysam/libcalignmentfile.pxd":156 * * * cdef class IteratorColumnAllRefs(IteratorColumn): # <<<<<<<<<<<<<< @@ -1485,7 +1569,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs { }; -/* "pysam/libcalignmentfile.pxd":151 +/* "pysam/libcalignmentfile.pxd":160 * * * cdef class IndexedReads: # <<<<<<<<<<<<<< @@ -1498,11 +1582,11 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads { htsFile *htsfile; PyObject *index; int owns_samfile; - bam_hdr_t *header; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; }; -/* "pysam/libcalignedsegment.pxd":40 +/* "pysam/libcalignedsegment.pxd":34 * * # Note: need to declare all C fields and methods here * cdef class AlignedSegment: # <<<<<<<<<<<<<< @@ -1513,7 +1597,7 @@ struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment { PyObject_HEAD struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *__pyx_vtab; bam1_t *_delegate; - struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *_alignment_file; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; PyObject *cache_query_qualities; PyObject *cache_query_alignment_qualities; PyObject *cache_query_sequence; @@ -1521,7 +1605,7 @@ struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment { }; -/* "pysam/libcalignedsegment.pxd":69 +/* "pysam/libcalignedsegment.pxd":66 * * * cdef class PileupColumn: # <<<<<<<<<<<<<< @@ -1534,21 +1618,24 @@ struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn { int tid; int pos; int n_pu; - struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *_alignment_file; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; + uint32_t min_base_quality; + uint8_t *buf; + char *reference_sequence; }; -/* "pysam/libcalignedsegment.pxd":77 - * +/* "pysam/libcalignedsegment.pxd":76 + * cdef char * reference_sequence * * cdef class PileupRead: # <<<<<<<<<<<<<< - * cdef AlignedSegment _alignment * cdef int32_t _qpos + * cdef AlignedSegment _alignment */ struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead { PyObject_HEAD - struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *_alignment; int32_t _qpos; + struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *_alignment; int _indel; int _level; uint32_t _is_del; @@ -1558,12 +1645,12 @@ struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead { }; -/* "pysam/libcalignedsegment.pyx":84 +/* "pysam/libcalignedsegment.pyx":96 * - * if PY_MAJOR_VERSION >= 3: + * if IS_PYTHON3: * CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) # <<<<<<<<<<<<<< + * maketrans = str.maketrans * else: - * CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR)) */ struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr { PyObject_HEAD @@ -1575,12 +1662,12 @@ struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr { }; -/* "pysam/libcalignedsegment.pyx":86 - * CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) +/* "pysam/libcalignedsegment.pyx":99 + * maketrans = str.maketrans * else: * CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR)) # <<<<<<<<<<<<<< + * maketrans = string.maketrans * - * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=XB])") */ struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr { PyObject_HEAD @@ -1592,6 +1679,48 @@ struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr { }; +/* "pysam/libcalignedsegment.pyx":1124 + * + * @classmethod + * def from_dict(cls, sam_dict, AlignmentHeader header): # <<<<<<<<<<<<<< + * """parses a dictionary representation of the aligned segment. + * + */ +struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict { + PyObject_HEAD + PyObject *__pyx_v_sam_dict; +}; + + +/* "pysam/libcalignedsegment.pyx":1136 + * # the tags field can be missing + * return cls.fromstring( + * "\t".join((sam_dict[x] for x in KEY_NAMES[:-1])) + # <<<<<<<<<<<<<< + * "\t" + + * "\t".join(sam_dict.get(KEY_NAMES[-1], [])), header) + */ +struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr { + PyObject_HEAD + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *__pyx_outer_scope; + PyObject *__pyx_v_x; + PyObject *__pyx_t_0; + Py_ssize_t __pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); +}; + + +/* "EnumBase":15 + * + * @cython.internal + * cdef class __Pyx_EnumMeta(type): # <<<<<<<<<<<<<< + * def __init__(cls, name, parents, dct): + * type.__init__(cls, name, parents, dct) + */ +struct __pyx_obj___Pyx_EnumMeta { + PyHeapTypeObject __pyx_base; +}; + + /* "View.MemoryView":104 * * @cname("__pyx_array") @@ -1670,7 +1799,7 @@ struct __pyx_memoryviewslice_obj { -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -1703,33 +1832,35 @@ static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile *__pyx_vtabptr_5pysam * * cdef class FastqProxy: # <<<<<<<<<<<<<< * cdef kseq_t * _delegate - * cdef cython.str tostring(self) + * cdef cython.str to_string(self) */ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy { + PyObject *(*to_string)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *); PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *); arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array *__pyx_optional_args); }; static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy *__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy; -/* "pysam/libcfaidx.pxd":51 +/* "pysam/libcfaidx.pxd":52 * * - * cdef class PersistentFastqProxy: # <<<<<<<<<<<<<< + * cdef class FastxRecord: # <<<<<<<<<<<<<< * """ * Python container for pysam.libcfaidx.FastqProxy with persistence. */ -struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy { - PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *); - arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array *__pyx_optional_args); +struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord { + PyObject *(*to_string)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *); + PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *); + arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array *__pyx_optional_args); }; -static struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy; +static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *__pyx_vtabptr_5pysam_9libcfaidx_FastxRecord; -/* "pysam/libcfaidx.pxd":60 - * +/* "pysam/libcfaidx.pxd":61 + * cpdef array.array get_quality_array(self, int offset=*) * * cdef class FastxFile: # <<<<<<<<<<<<<< * cdef object _filename @@ -1743,7 +1874,7 @@ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile { static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile *__pyx_vtabptr_5pysam_9libcfaidx_FastxFile; -/* "pysam/libcfaidx.pxd":72 +/* "pysam/libcfaidx.pxd":73 * * # Compatibility Layer for pysam 0.8.1 * cdef class FastqFile(FastxFile): # <<<<<<<<<<<<<< @@ -1757,7 +1888,7 @@ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile { static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile *__pyx_vtabptr_5pysam_9libcfaidx_FastqFile; -/* "pysam/libcfaidx.pxd":77 +/* "pysam/libcfaidx.pxd":78 * * # Compatibility Layer for pysam < 0.8 * cdef class Fastafile(FastaFile): # <<<<<<<<<<<<<< @@ -1771,12 +1902,12 @@ struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile { static struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile *__pyx_vtabptr_5pysam_9libcfaidx_Fastafile; -/* "pysam/libcalignmentfile.pxd":39 - * +/* "pysam/libcalignmentfile.pxd":44 + * cdef bam_hdr_t *ptr * * cdef class AlignmentFile(HTSFile): # <<<<<<<<<<<<<< * cdef readonly object reference_filename - * + * cdef readonly AlignmentHeader header */ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile { @@ -1788,7 +1919,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *__pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile; -/* "pysam/libcalignmentfile.pxd":84 +/* "pysam/libcalignmentfile.pxd":89 * * * cdef class IteratorRowRegion(IteratorRow): # <<<<<<<<<<<<<< @@ -1803,8 +1934,8 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion; -/* "pysam/libcalignmentfile.pxd":89 - * cdef int cnext(self) +/* "pysam/libcalignmentfile.pxd":95 + * * * cdef class IteratorRowHead(IteratorRow): # <<<<<<<<<<<<<< * cdef int max_rows @@ -1818,8 +1949,8 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead; -/* "pysam/libcalignmentfile.pxd":95 - * cdef int cnext(self) +/* "pysam/libcalignmentfile.pxd":102 + * * * cdef class IteratorRowAll(IteratorRow): # <<<<<<<<<<<<<< * cdef bam1_t * getCurrent(self) @@ -1833,7 +1964,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll; -/* "pysam/libcalignmentfile.pxd":105 +/* "pysam/libcalignmentfile.pxd":112 * * * cdef class IteratorRowSelection(IteratorRow): # <<<<<<<<<<<<<< @@ -1848,7 +1979,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection; -/* "pysam/libcalignmentfile.pxd":112 +/* "pysam/libcalignmentfile.pxd":119 * * * cdef class IteratorColumn: # <<<<<<<<<<<<<< @@ -1858,21 +1989,21 @@ static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection * struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn { int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); - char *(*getSequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); - PyObject *(*setMask)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, PyObject *); - PyObject *(*setupIteratorData)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData *__pyx_optional_args); + char *(*get_sequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); + PyObject *(*_setup_iterator)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args); PyObject *(*reset)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, PyObject *, PyObject *, PyObject *); PyObject *(*_free_pileup_iter)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); + char *(*getSequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); }; static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn; -/* "pysam/libcalignmentfile.pxd":141 +/* "pysam/libcalignmentfile.pxd":150 * * * cdef class IteratorColumnRegion(IteratorColumn): # <<<<<<<<<<<<<< * cdef int start - * cdef int end + * cdef int stop */ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion { @@ -1881,7 +2012,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion; -/* "pysam/libcalignmentfile.pxd":147 +/* "pysam/libcalignmentfile.pxd":156 * * * cdef class IteratorColumnAllRefs(IteratorColumn): # <<<<<<<<<<<<<< @@ -1895,7 +2026,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs; -/* "pysam/libcalignedsegment.pyx":647 +/* "pysam/libcalignedsegment.pyx":899 * * * cdef class AlignedSegment: # <<<<<<<<<<<<<< @@ -1907,7 +2038,8 @@ struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment { PyObject *(*set_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag *__pyx_optional_args); PyObject *(*get_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag *__pyx_optional_args); PyObject *(*has_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch); - PyObject *(*tostring)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, __pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t, int __pyx_skip_dispatch); + PyObject *(*to_string)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch); + PyObject *(*tostring)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring *__pyx_optional_args); }; static struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *__pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment; @@ -2341,6 +2473,9 @@ static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* s return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); } +/* bytes_index.proto */ +static CYTHON_INLINE char __Pyx_PyBytes_GetItemInt(PyObject* bytes, Py_ssize_t index, int check_bounds); + /* RaiseException.proto */ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); @@ -2356,23 +2491,6 @@ static CYTHON_INLINE int __Pyx_IterFinish(void); /* UnpackItemEndCheck.proto */ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); -/* PyDictContains.proto */ -static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) { - int result = PyDict_Contains(dict, item); - return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); -} - -/* DictGetItem.proto */ -#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY -static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key); -#define __Pyx_PyObject_Dict_GetItem(obj, name)\ - (likely(PyDict_CheckExact(obj)) ?\ - __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name)) -#else -#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key) -#define __Pyx_PyObject_Dict_GetItem(obj, name) PyObject_GetItem(obj, name) -#endif - /* GetItemInt.proto */ #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ @@ -2455,12 +2573,6 @@ static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { #define __Pyx_PyList_Append(L,x) PyList_Append(L,x) #endif -/* IncludeStringH.proto */ -#include - -/* BytesEquals.proto */ -static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); - /* StringJoin.proto */ #if PY_MAJOR_VERSION < 3 #define __Pyx_PyString_Join __Pyx_PyBytes_Join @@ -2485,13 +2597,18 @@ static CYTHON_INLINE long __Pyx_div_long(long, long); /* None.proto */ static CYTHON_INLINE long __Pyx_mod_long(long, long); +/* RaiseDoubleKeywords.proto */ +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); + +/* ParseKeywords.proto */ +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ + const char* function_name); + /* RaiseArgTupleInvalid.proto */ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); -/* KeywordStringCheck.proto */ -static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); - /* ArgTypeTest.proto */ #define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\ ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\ @@ -2506,6 +2623,38 @@ static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, i PyObject_RichCompare(op1, op2, Py_EQ) #endif +/* tp_new.proto */ +#define __Pyx_tp_new(type_obj, args) __Pyx_tp_new_kwargs(type_obj, args, NULL) +static CYTHON_INLINE PyObject* __Pyx_tp_new_kwargs(PyObject* type_obj, PyObject* args, PyObject* kwargs) { + return (PyObject*) (((PyTypeObject*)type_obj)->tp_new((PyTypeObject*)type_obj, args, kwargs)); +} + +/* None.proto */ +static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname); + +/* ObjectGetItem.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key); +#else +#define __Pyx_PyObject_GetItem(obj, key) PyObject_GetItem(obj, key) +#endif + +/* IncludeStringH.proto */ +#include + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* StrEquals.proto */ +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals +#else +#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals +#endif + /* PyObjectSetAttrStr.proto */ #if CYTHON_USE_TYPE_SLOTS #define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL) @@ -2515,14 +2664,6 @@ static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr #define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v) #endif -/* RaiseDoubleKeywords.proto */ -static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); - -/* ParseKeywords.proto */ -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ - PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ - const char* function_name); - /* None.proto */ static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); @@ -2555,15 +2696,8 @@ static CYTHON_INLINE int __pyx_sub_acquisition_count_locked( static CYTHON_INLINE void __Pyx_INC_MEMVIEW(__Pyx_memviewslice *, int, int); static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *, int, int); -/* UnicodeEquals.proto */ -static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); - -/* StrEquals.proto */ -#if PY_MAJOR_VERSION >= 3 -#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals -#else -#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals -#endif +/* KeywordStringCheck.proto */ +static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /* PyErrExceptionMatches.proto */ #if CYTHON_FAST_THREAD_STATE @@ -2597,13 +2731,6 @@ static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t, Py_ssize_t); static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *); /*proto*/ -/* ObjectGetItem.proto */ -#if CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key); -#else -#define __Pyx_PyObject_GetItem(obj, key) PyObject_GetItem(obj, key) -#endif - /* decode_c_string_utf16.proto */ static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors) { int byteorder = 0; @@ -2691,6 +2818,92 @@ static int __Pyx_setup_reduce(PyObject* type_obj); /* GetVTable.proto */ static void* __Pyx_GetVtable(PyObject *dict); +/* ClassMethod.proto */ +#include "descrobject.h" +static PyObject* __Pyx_Method_ClassMethod(PyObject *method); + +/* GetNameInClass.proto */ +static PyObject *__Pyx_GetNameInClass(PyObject *nmspace, PyObject *name); + +/* CalculateMetaclass.proto */ +static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases); + +/* SetNameInClass.proto */ +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 +#define __Pyx_SetNameInClass(ns, name, value)\ + (likely(PyDict_CheckExact(ns)) ? _PyDict_SetItem_KnownHash(ns, name, value, ((PyASCIIObject *) name)->hash) : PyObject_SetItem(ns, name, value)) +#elif CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_SetNameInClass(ns, name, value)\ + (likely(PyDict_CheckExact(ns)) ? PyDict_SetItem(ns, name, value) : PyObject_SetItem(ns, name, value)) +#else +#define __Pyx_SetNameInClass(ns, name, value) PyObject_SetItem(ns, name, value) +#endif + +/* FetchCommonType.proto */ +static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type); + +/* CythonFunction.proto */ +#define __Pyx_CyFunction_USED 1 +#define __Pyx_CYFUNCTION_STATICMETHOD 0x01 +#define __Pyx_CYFUNCTION_CLASSMETHOD 0x02 +#define __Pyx_CYFUNCTION_CCLASS 0x04 +#define __Pyx_CyFunction_GetClosure(f)\ + (((__pyx_CyFunctionObject *) (f))->func_closure) +#define __Pyx_CyFunction_GetClassObj(f)\ + (((__pyx_CyFunctionObject *) (f))->func_classobj) +#define __Pyx_CyFunction_Defaults(type, f)\ + ((type *)(((__pyx_CyFunctionObject *) (f))->defaults)) +#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\ + ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g) +typedef struct { + PyCFunctionObject func; +#if PY_VERSION_HEX < 0x030500A0 + PyObject *func_weakreflist; +#endif + PyObject *func_dict; + PyObject *func_name; + PyObject *func_qualname; + PyObject *func_doc; + PyObject *func_globals; + PyObject *func_code; + PyObject *func_closure; + PyObject *func_classobj; + void *defaults; + int defaults_pyobjects; + int flags; + PyObject *defaults_tuple; + PyObject *defaults_kwdict; + PyObject *(*defaults_getter)(PyObject *); + PyObject *func_annotations; +} __pyx_CyFunctionObject; +static PyTypeObject *__pyx_CyFunctionType = 0; +#define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code)\ + __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, qualname, self, module, globals, code) +static PyObject *__Pyx_CyFunction_New(PyTypeObject *, PyMethodDef *ml, + int flags, PyObject* qualname, + PyObject *self, + PyObject *module, PyObject *globals, + PyObject* code); +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m, + size_t size, + int pyobjects); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m, + PyObject *tuple); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m, + PyObject *dict); +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m, + PyObject *dict); +static int __pyx_CyFunction_init(void); + +/* Py3ClassCreate.proto */ +static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname, + PyObject *mkw, PyObject *modname, PyObject *doc); +static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict, + PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass); + +/* Globals.proto */ +static PyObject* __Pyx_Globals(void); + /* CLineInTraceback.proto */ #ifdef CYTHON_CLINE_IN_TRACEBACK #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) @@ -2884,9 +3097,18 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint8_t(uint8_t value); +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int8_t(int8_t value); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int16_t(int16_t value); + /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value); +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value); + /* MemviewSliceCopyTemplate.proto */ static __Pyx_memviewslice __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, @@ -2907,16 +3129,25 @@ static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *); static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); /* CIntFromPy.proto */ -static CYTHON_INLINE uint16_t __Pyx_PyInt_As_uint16_t(PyObject *); +static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *); /* CIntFromPy.proto */ static CYTHON_INLINE uint8_t __Pyx_PyInt_As_uint8_t(PyObject *); /* CIntFromPy.proto */ -static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *); +static CYTHON_INLINE uint16_t __Pyx_PyInt_As_uint16_t(PyObject *); -/* FetchCommonType.proto */ -static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type); +/* CIntFromPy.proto */ +static CYTHON_INLINE int16_t __Pyx_PyInt_As_int16_t(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int8_t __Pyx_PyInt_As_int8_t(PyObject *); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(enum __pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS value); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(enum __pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS value); /* PyObjectCallMethod1.proto */ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); @@ -3037,7 +3268,8 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** /* InitStrings.proto */ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); -static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_tostring(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, __pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t __pyx_v_htsfile, int __pyx_skip_dispatch); /* proto*/ +static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_to_string(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ +static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_tostring(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring *__pyx_optional_args); /* proto*/ static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_set_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag *__pyx_optional_args); /* proto*/ static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_has_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch); /* proto*/ static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_get_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag *__pyx_optional_args); /* proto*/ @@ -3157,12 +3389,13 @@ static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *, ch /* Module declarations from 'pysam.libcfaidx' */ static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastaFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastqProxy = 0; -static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy = 0; +static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastxRecord = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastxFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastqFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_Fastafile = 0; /* Module declarations from 'pysam.libcalignmentfile' */ +static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader = 0; static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile = 0; static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_PileupColumn = 0; static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_PileupRead = 0; @@ -3192,14 +3425,21 @@ static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn = 0; static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_PileupRead = 0; static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr = 0; static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr = 0; +static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict = 0; +static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr = 0; +static PyTypeObject *__pyx_ptype___Pyx_EnumMeta = 0; static PyTypeObject *__pyx_array_type = 0; static PyTypeObject *__pyx_MemviewEnum_type = 0; static PyTypeObject *__pyx_memoryview_type = 0; static PyTypeObject *__pyx_memoryviewslice_type = 0; static char *__pyx_v_5pysam_18libcalignedsegment_htslib_types; static char *__pyx_v_5pysam_18libcalignedsegment_parray_types; +static int __pyx_v_5pysam_18libcalignedsegment_IS_PYTHON3; static char *__pyx_v_5pysam_18libcalignedsegment_CODE2CIGAR; static int __pyx_v_5pysam_18libcalignedsegment_NCIGAR_CODES; +static uint32_t __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE; +static PyObject *__Pyx_OrderedDict = 0; +static PyObject *__Pyx_EnumBase = 0; static PyObject *generic = 0; static PyObject *strided = 0; static PyObject *indirect = 0; @@ -3207,23 +3447,33 @@ static PyObject *contiguous = 0; static PyObject *indirect_contiguous = 0; static int __pyx_memoryview_thread_locks_used; static PyThread_type_lock __pyx_memoryview_thread_locks[8]; -static PyObject *__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(bam1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupRead(bam_pileup1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *); /*proto*/ +static PyObject *__Pyx_globals = 0; +static struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(bam1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *); /*proto*/ +static struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_f_5pysam_18libcalignedsegment_makePileupRead(bam_pileup1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *); /*proto*/ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_length(bam1_t *); /*proto*/ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_c_mul(uint32_t, uint32_t); /*proto*/ +static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_tolower(uint8_t); /*proto*/ +static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_toupper(uint8_t); /*proto*/ +static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_strand_mark_char(uint8_t, bam1_t *); /*proto*/ +static CYTHON_INLINE int __pyx_f_5pysam_18libcalignedsegment_pileup_base_qual_skip(bam_pileup1_t *, uint32_t); /*proto*/ static CYTHON_INLINE char __pyx_f_5pysam_18libcalignedsegment_map_typecode_htslib_to_python(uint8_t); /*proto*/ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_map_typecode_python_to_htslib(char); /*proto*/ +static CYTHON_INLINE void __pyx_f_5pysam_18libcalignedsegment_update_bin(bam1_t *); /*proto*/ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t *); /*proto*/ -static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_value_code(PyObject *, struct __pyx_opt_args_5pysam_18libcalignedsegment_get_value_code *__pyx_optional_args); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getTypecode(PyObject *, struct __pyx_opt_args_5pysam_18libcalignedsegment_getTypecode *__pyx_optional_args); /*proto*/ -static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyObject *); /*proto*/ -static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryLength(bam1_t *); /*proto*/ +static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_tag_typecode(PyObject *, struct __pyx_opt_args_5pysam_18libcalignedsegment_get_tag_typecode *__pyx_optional_args); /*proto*/ +static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_btag_typecode(PyObject *, struct __pyx_opt_args_5pysam_18libcalignedsegment_get_btag_typecode *__pyx_optional_args); /*proto*/ +static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_pack_tags(PyObject *); /*proto*/ +static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryLengthWithoutHardClipping(bam1_t *); /*proto*/ +static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryLengthWithHardClipping(bam1_t *); /*proto*/ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_getQueryStart(bam1_t *); /*proto*/ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(bam1_t *); /*proto*/ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getSequenceInRange(bam1_t *, uint32_t, uint32_t); /*proto*/ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getQualitiesInRange(bam1_t *, uint32_t, uint32_t); /*proto*/ +static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_md_reference_length(char *); /*proto*/ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignment_sequence(bam1_t *); /*proto*/ +static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_reference_sequence(bam1_t *); /*proto*/ static PyObject *__pyx_f_5pysam_18libcalignedsegment___pyx_unpickle_PileupRead__set_state(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *, PyObject *); /*proto*/ +static PyObject *__pyx_unpickle___Pyx_EnumMeta__set_state(struct __pyx_obj___Pyx_EnumMeta *, PyObject *); /*proto*/ static struct __pyx_array_obj *__pyx_array_new(PyObject *, Py_ssize_t, char *, char *, char *); /*proto*/ static void *__pyx_align_pointer(void *, size_t); /*proto*/ static PyObject *__pyx_memoryview_new(PyObject *, int, int, __Pyx_TypeInfo *); /*proto*/ @@ -3268,44 +3518,51 @@ static PyObject *__pyx_builtin_chr; static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_min; static PyObject *__pyx_builtin_max; +static PyObject *__pyx_builtin_MemoryError; static PyObject *__pyx_builtin_NotImplementedError; +static PyObject *__pyx_builtin_AssertionError; static PyObject *__pyx_builtin_map; static PyObject *__pyx_builtin_NotImplemented; +static PyObject *__pyx_builtin_zip; static PyObject *__pyx_builtin_KeyError; static PyObject *__pyx_builtin_TypeError; -static PyObject *__pyx_builtin_MemoryError; static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_Ellipsis; static PyObject *__pyx_builtin_id; static PyObject *__pyx_builtin_IndexError; static const char __pyx_k_A[] = "A"; static const char __pyx_k_B[] = "B"; -static const char __pyx_k_C[] = "C"; static const char __pyx_k_D[] = "D"; static const char __pyx_k_F[] = "F"; static const char __pyx_k_H[] = "H"; static const char __pyx_k_I[] = "I"; static const char __pyx_k_O[] = "O"; -static const char __pyx_k_S[] = "S"; static const char __pyx_k_Z[] = "Z"; +static const char __pyx_k_a[] = "a"; static const char __pyx_k_b[] = "b"; -static const char __pyx_k_c[] = "c"; +static const char __pyx_k_c[] = "%c"; static const char __pyx_k_d[] = "d"; static const char __pyx_k_f[] = "f"; static const char __pyx_k_h[] = "h"; static const char __pyx_k_i[] = "i"; -static const char __pyx_k_s[] = "s"; -static const char __pyx_k_AZ[] = "AZ"; +static const char __pyx_k_v[] = "v"; static const char __pyx_k__4[] = "<"; +static const char __pyx_k__8[] = ""; static const char __pyx_k_id[] = "id"; static const char __pyx_k_re[] = "re"; -static const char __pyx_k__16[] = ""; -static const char __pyx_k__19[] = "\t"; -static const char __pyx_k__33[] = "\n"; +static const char __pyx_k__16[] = "\t"; +static const char __pyx_k__24[] = "*"; +static const char __pyx_k__27[] = "="; +static const char __pyx_k__42[] = "\n"; +static const char __pyx_k__44[] = ":"; static const char __pyx_k_all[] = "__all__"; -static const char __pyx_k_c_2[] = "%c"; +static const char __pyx_k_c_2[] = "c"; static const char __pyx_k_chr[] = "chr"; +static const char __pyx_k_cls[] = "cls"; +static const char __pyx_k_dct[] = "dct"; +static const char __pyx_k_doc[] = "__doc__"; static const char __pyx_k_end[] = "end"; +static const char __pyx_k_get[] = "get"; static const char __pyx_k_i_c[] = "%i%c"; static const char __pyx_k_map[] = "map"; static const char __pyx_k_max[] = "max"; @@ -3313,28 +3570,47 @@ static const char __pyx_k_min[] = "min"; static const char __pyx_k_new[] = "__new__"; static const char __pyx_k_obj[] = "obj"; static const char __pyx_k_raw[] = "raw"; +static const char __pyx_k_res[] = "res"; +static const char __pyx_k_s_s[] = "%s.%s"; +static const char __pyx_k_sam[] = "sam"; +static const char __pyx_k_seq[] = "seq"; +static const char __pyx_k_str[] = "__str__"; static const char __pyx_k_tag[] = "tag"; -static const char __pyx_k_Zidf[] = "Zidf"; +static const char __pyx_k_zip[] = "zip"; +static const char __pyx_k_CDEL[] = "CDEL"; +static const char __pyx_k_CINS[] = "CINS"; +static const char __pyx_k_CPAD[] = "CPAD"; +static const char __pyx_k_FDUP[] = "FDUP"; static const char __pyx_k_args[] = "args"; static const char __pyx_k_base[] = "base"; static const char __pyx_k_dict[] = "__dict__"; +static const char __pyx_k_enum[] = "enum"; static const char __pyx_k_flag[] = "flag"; +static const char __pyx_k_init[] = "__init__"; static const char __pyx_k_join[] = "join"; +static const char __pyx_k_json[] = "json"; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_mode[] = "mode"; static const char __pyx_k_name[] = "name"; static const char __pyx_k_ndim[] = "ndim"; static const char __pyx_k_pack[] = "pack"; +static const char __pyx_k_qual[] = "qual"; +static const char __pyx_k_repr[] = "__repr__"; +static const char __pyx_k_self[] = "self"; static const char __pyx_k_send[] = "send"; static const char __pyx_k_size[] = "size"; static const char __pyx_k_step[] = "step"; static const char __pyx_k_stop[] = "stop"; static const char __pyx_k_tags[] = "tags"; static const char __pyx_k_test[] = "__test__"; -static const char __pyx_k_2sc_s[] = "2sc%s"; +static const char __pyx_k_todo[] = "todo"; +static const char __pyx_k_2sB_s[] = "2sB%s"; static const char __pyx_k_ASCII[] = "ASCII"; +static const char __pyx_k_CBACK[] = "CBACK"; +static const char __pyx_k_CDIFF[] = "CDIFF"; static const char __pyx_k_array[] = "array"; static const char __pyx_k_ascii[] = "ascii"; +static const char __pyx_k_cigar[] = "cigar"; static const char __pyx_k_class[] = "__class__"; static const char __pyx_k_close[] = "close"; static const char __pyx_k_error[] = "error"; @@ -3342,95 +3618,156 @@ static const char __pyx_k_flags[] = "flags"; static const char __pyx_k_indel[] = "indel"; static const char __pyx_k_level[] = "level"; static const char __pyx_k_range[] = "range"; +static const char __pyx_k_s_s_d[] = "<%s.%s: %d>"; static const char __pyx_k_shape[] = "shape"; +static const char __pyx_k_split[] = "split"; static const char __pyx_k_start[] = "start"; static const char __pyx_k_throw[] = "throw"; static const char __pyx_k_value[] = "value"; -static const char __pyx_k_2sc_is[] = "2sc%is"; +static const char __pyx_k_2sB_is[] = "2sB%is"; +static const char __pyx_k_CEQUAL[] = "CEQUAL"; +static const char __pyx_k_CMATCH[] = "CMATCH"; +static const char __pyx_k_FREAD1[] = "FREAD1"; +static const char __pyx_k_FREAD2[] = "FREAD2"; +static const char __pyx_k_FUNMAP[] = "FUNMAP"; static const char __pyx_k_always[] = "always"; static const char __pyx_k_ctypes[] = "ctypes"; static const char __pyx_k_encode[] = "encode"; static const char __pyx_k_format[] = "format"; +static const char __pyx_k_header[] = "header"; +static const char __pyx_k_iIcCsS[] = "iIcCsS"; static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_is_del[] = "is_del"; +static const char __pyx_k_length[] = "length"; +static const char __pyx_k_module[] = "__module__"; static const char __pyx_k_name_2[] = "__name__"; static const char __pyx_k_pickle[] = "pickle"; static const char __pyx_k_reduce[] = "__reduce__"; +static const char __pyx_k_string[] = "string"; static const char __pyx_k_struct[] = "struct"; static const char __pyx_k_unpack[] = "unpack"; static const char __pyx_k_update[] = "update"; +static const char __pyx_k_values[] = "values"; +static const char __pyx_k_FMUNMAP[] = "FMUNMAP"; +static const char __pyx_k_FPAIRED[] = "FPAIRED"; +static const char __pyx_k_FQCFAIL[] = "FQCFAIL"; +static const char __pyx_k_IntEnum[] = "IntEnum"; static const char __pyx_k_compare[] = "compare"; static const char __pyx_k_compile[] = "compile"; static const char __pyx_k_findall[] = "findall"; static const char __pyx_k_fortran[] = "fortran"; static const char __pyx_k_genexpr[] = "genexpr"; static const char __pyx_k_get_tag[] = "get_tag"; +static const char __pyx_k_get_tid[] = "get_tid"; static const char __pyx_k_has_tag[] = "has_tag"; +static const char __pyx_k_htsfile[] = "htsfile"; static const char __pyx_k_is_head[] = "is_head"; static const char __pyx_k_is_tail[] = "is_tail"; +static const char __pyx_k_members[] = "__members__"; static const char __pyx_k_memview[] = "memview"; +static const char __pyx_k_parents[] = "parents"; static const char __pyx_k_pileups[] = "pileups"; +static const char __pyx_k_prepare[] = "__prepare__"; +static const char __pyx_k_ref_pos[] = "ref_pos"; static const char __pyx_k_replace[] = "replace"; static const char __pyx_k_set_tag[] = "set_tag"; -static const char __pyx_k_2sccI_is[] = "2sccI%is"; +static const char __pyx_k_2sBBI_is[] = "2sBBI%is"; static const char __pyx_k_Ellipsis[] = "Ellipsis"; +static const char __pyx_k_EnumBase[] = "EnumBase"; +static const char __pyx_k_EnumType[] = "EnumType"; +static const char __pyx_k_FREVERSE[] = "FREVERSE"; static const char __pyx_k_KeyError[] = "KeyError"; static const char __pyx_k_calcsize[] = "calcsize"; static const char __pyx_k_get_tags[] = "get_tags"; -static const char __pyx_k_getrname[] = "getrname"; static const char __pyx_k_getstate[] = "__getstate__"; static const char __pyx_k_itemsize[] = "itemsize"; static const char __pyx_k_pyx_type[] = "__pyx_type"; +static const char __pyx_k_qualname[] = "__qualname__"; +static const char __pyx_k_ref_name[] = "ref_name"; +static const char __pyx_k_sam_dict[] = "sam_dict"; static const char __pyx_k_set_tags[] = "set_tags"; static const char __pyx_k_setstate[] = "__setstate__"; static const char __pyx_k_tostring[] = "tostring"; static const char __pyx_k_typecode[] = "typecode"; static const char __pyx_k_with_seq[] = "with_seq"; -static const char __pyx_k_2sccI_i_s[] = "2sccI%i%s"; +static const char __pyx_k_2sBBI_i_s[] = "2sBBI%i%s"; +static const char __pyx_k_CIGAR_OPS[] = "CIGAR_OPS"; +static const char __pyx_k_CREF_SKIP[] = "CREF_SKIP"; +static const char __pyx_k_FMREVERSE[] = "FMREVERSE"; +static const char __pyx_k_KEY_NAMES[] = "KEY_NAMES"; +static const char __pyx_k_SAM_FLAGS[] = "SAM_FLAGS"; static const char __pyx_k_TypeError[] = "TypeError"; static const char __pyx_k_alignment[] = "alignment"; static const char __pyx_k_enumerate[] = "enumerate"; +static const char __pyx_k_from_dict[] = "from_dict"; +static const char __pyx_k_maketrans[] = "maketrans"; +static const char __pyx_k_mark_ends[] = "mark_ends"; +static const char __pyx_k_metaclass[] = "__metaclass__"; static const char __pyx_k_nsegments[] = "nsegments"; static const char __pyx_k_pack_into[] = "pack_into"; static const char __pyx_k_pyx_state[] = "__pyx_state"; static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_to_string[] = "to_string"; +static const char __pyx_k_translate[] = "translate"; +static const char __pyx_k_CHARD_CLIP[] = "CHARD_CLIP"; static const char __pyx_k_CIGAR2CODE[] = "CIGAR2CODE"; +static const char __pyx_k_CSOFT_CLIP[] = "CSOFT_CLIP"; +static const char __pyx_k_FSECONDARY[] = "FSECONDARY"; static const char __pyx_k_IndexError[] = "IndexError"; static const char __pyx_k_PileupRead[] = "PileupRead"; static const char __pyx_k_ValueError[] = "ValueError"; +static const char __pyx_k_add_indels[] = "add_indels"; +static const char __pyx_k_fromstring[] = "fromstring"; static const char __pyx_k_get_blocks[] = "get_blocks"; static const char __pyx_k_is_refskip[] = "is_refskip"; +static const char __pyx_k_is_reverse[] = "is_reverse"; static const char __pyx_k_pyx_result[] = "__pyx_result"; static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; static const char __pyx_k_query_name[] = "query_name"; static const char __pyx_k_value_type[] = "value_type"; static const char __pyx_k_CIGAR_REGEX[] = "CIGAR_REGEX"; static const char __pyx_k_MemoryError[] = "MemoryError"; +static const char __pyx_k_OrderedDict[] = "OrderedDict"; static const char __pyx_k_PickleError[] = "PickleError"; static const char __pyx_k_cigarstring[] = "cigarstring"; static const char __pyx_k_cigartuples[] = "cigartuples"; +static const char __pyx_k_collections[] = "collections"; static const char __pyx_k_full_length[] = "full_length"; static const char __pyx_k_get_overlap[] = "get_overlap"; +static const char __pyx_k_map_quality[] = "map_quality"; +static const char __pyx_k_ACGTacgtNnXx[] = "ACGTacgtNnXx"; +static const char __pyx_k_FPROPER_PAIR[] = "FPROPER_PAIR"; static const char __pyx_k_PileupColumn[] = "PileupColumn"; +static const char __pyx_k_Pyx_EnumBase[] = "__Pyx_EnumBase"; +static const char __pyx_k_TGCAtgcaNnXx[] = "TGCAtgcaNnXx"; +static const char __pyx_k_aAsSIcCZidfH[] = "aAsSIcCZidfH"; static const char __pyx_k_d_MIDNSHP_XB[] = "(\\d+)([MIDNSHP=XB])"; +static const char __pyx_k_is_valid_tid[] = "is_valid_tid"; +static const char __pyx_k_mark_matches[] = "mark_matches"; static const char __pyx_k_matches_only[] = "matches_only"; +static const char __pyx_k_next_ref_pos[] = "next_ref_pos"; static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; static const char __pyx_k_query_length[] = "query_length"; static const char __pyx_k_reference_id[] = "reference_id"; static const char __pyx_k_stringsource[] = "stringsource"; static const char __pyx_k_Invalid_tag_s[] = "Invalid tag: %s"; +static const char __pyx_k_next_ref_name[] = "next_ref_name"; static const char __pyx_k_pyx_getbuffer[] = "__pyx_getbuffer"; static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; static const char __pyx_k_reference_end[] = "reference_end"; static const char __pyx_k_reference_pos[] = "reference_pos"; static const char __pyx_k_AlignedSegment[] = "AlignedSegment"; +static const char __pyx_k_AssertionError[] = "AssertionError"; +static const char __pyx_k_FSUPPLEMENTARY[] = "FSUPPLEMENTARY"; static const char __pyx_k_NotImplemented[] = "NotImplemented"; static const char __pyx_k_query_position[] = "query_position"; static const char __pyx_k_query_sequence[] = "query_sequence"; static const char __pyx_k_unknown_type_s[] = "unknown type '%s'"; +static const char __pyx_k_DATATYPE2FORMAT[] = "DATATYPE2FORMAT"; static const char __pyx_k_View_MemoryView[] = "View.MemoryView"; static const char __pyx_k_allocate_buffer[] = "allocate_buffer"; static const char __pyx_k_dtype_is_object[] = "dtype_is_object"; +static const char __pyx_k_get_num_aligned[] = "get_num_aligned"; static const char __pyx_k_mapping_quality[] = "mapping_quality"; static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError"; static const char __pyx_k_query_qualities[] = "query_qualities"; @@ -3440,45 +3777,53 @@ static const char __pyx_k_template_length[] = "template_length"; static const char __pyx_k_with_value_type[] = "with_value_type"; static const char __pyx_k_reference_length[] = "reference_length"; static const char __pyx_k_get_aligned_pairs[] = "get_aligned_pairs"; +static const char __pyx_k_infer_read_length[] = "infer_read_length"; static const char __pyx_k_next_reference_id[] = "next_reference_id"; static const char __pyx_k_pyx_unpickle_Enum[] = "__pyx_unpickle_Enum"; static const char __pyx_k_sam_format_failed[] = "sam_format failed"; static const char __pyx_k_tag_s_not_present[] = "tag '%s' not present"; static const char __pyx_k_MD_tag_not_present[] = "MD tag not present"; +static const char __pyx_k_Pyx_EnumBase___new[] = "__Pyx_EnumBase.__new__"; +static const char __pyx_k_Pyx_EnumBase___str[] = "__Pyx_EnumBase.__str__"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_get_reference_name[] = "get_reference_name"; static const char __pyx_k_infer_query_length[] = "infer_query_length"; +static const char __pyx_k_invalid_value_type[] = "invalid value type '{}'"; static const char __pyx_k_malformatted_tag_s[] = "malformatted tag: %s"; static const char __pyx_k_strided_and_direct[] = ""; static const char __pyx_k_NotImplementedError[] = "NotImplementedError"; +static const char __pyx_k_Pyx_EnumBase___repr[] = "__Pyx_EnumBase.__repr__"; static const char __pyx_k_query_alignment_end[] = "query_alignment_end"; +static const char __pyx_k_Unknown_enum_value_s[] = "Unknown enum value: '%s'"; static const char __pyx_k_create_string_buffer[] = "create_string_buffer"; -static const char __pyx_k_invalid_value_type_s[] = "invalid value type '%s'"; +static const char __pyx_k_invalid_value_type_2[] = "invalid value type '{}' ({})"; static const char __pyx_k_next_reference_start[] = "next_reference_start"; static const char __pyx_k_strided_and_indirect[] = ""; static const char __pyx_k_contiguous_and_direct[] = ""; static const char __pyx_k_query_alignment_start[] = "query_alignment_start"; static const char __pyx_k_unsupported_type_code[] = "unsupported type code '{}'"; static const char __pyx_k_MemoryView_of_r_object[] = ""; -static const char __pyx_k_get_reference_sequence[] = "get_reference_sequence"; -static const char __pyx_k_invalid_value_type_s_s[] = "invalid value type '%s' (%s)"; static const char __pyx_k_query_alignment_length[] = "query_alignment_length"; static const char __pyx_k_MemoryView_of_r_at_0x_x[] = ""; static const char __pyx_k_contiguous_and_indirect[] = ""; static const char __pyx_k_get_reference_positions[] = "get_reference_positions"; static const char __pyx_k_pyx_unpickle_PileupRead[] = "__pyx_unpickle_PileupRead"; static const char __pyx_k_Cannot_index_with_type_s[] = "Cannot index with type '%s'"; +static const char __pyx_k_from_dict_locals_genexpr[] = "from_dict..genexpr"; static const char __pyx_k_pysam_libcalignedsegment[] = "pysam.libcalignedsegment"; static const char __pyx_k_query_alignment_sequence[] = "query_alignment_sequence"; static const char __pyx_k_unknown_auxiliary_type_s[] = "unknown auxiliary type '%s'"; static const char __pyx_k_Invalid_shape_in_axis_d_d[] = "Invalid shape in axis %d: %d."; +static const char __pyx_k_could_not_allocate_memory[] = "could not allocate memory"; static const char __pyx_k_query_alignment_qualities[] = "query_alignment_qualities"; +static const char __pyx_k_could_not_allocated_memory[] = "could not allocated memory"; static const char __pyx_k_itemsize_0_for_cython_array[] = "itemsize <= 0 for cython.array"; -static const char __pyx_k_query_length_out_of_range_254[] = "query length out of range {} > 254"; +static const char __pyx_k_pyx_unpickle___Pyx_EnumMeta[] = "__pyx_unpickle___Pyx_EnumMeta"; +static const char __pyx_k_query_length_out_of_range_251[] = "query length out of range {} > 251"; static const char __pyx_k_unable_to_allocate_array_data[] = "unable to allocate array data."; static const char __pyx_k_strided_and_direct_or_indirect[] = ""; static const char __pyx_k_Padding_BAM_CPAD_6_is_currently[] = "Padding (BAM_CPAD, 6) is currently not supported. Please implement. Sorry about that."; static const char __pyx_k_at_least_one_signed_integer_out[] = "at least one signed integer out of range of BAM/SAM specification"; -static const char __pyx_k_could_not_allocated_sequence_of[] = "could not allocated sequence of length %i"; static const char __pyx_k_quality_and_sequence_mismatch_i[] = "quality and sequence mismatch: %i != %i"; static const char __pyx_k_self_plp_cannot_be_converted_to[] = "self.plp cannot be converted to a Python object for pickling"; static const char __pyx_k_Buffer_view_does_not_expose_stri[] = "Buffer view does not expose strides"; @@ -3488,55 +3833,95 @@ static const char __pyx_k_Cannot_create_writable_memory_vi[] = "Cannot create wr static const char __pyx_k_Empty_shape_tuple_for_cython_arr[] = "Empty shape tuple for cython.array"; static const char __pyx_k_Incompatible_checksums_s_vs_0xb0[] = "Incompatible checksums (%s vs 0xb068931 = (name))"; static const char __pyx_k_Incompatible_checksums_s_vs_0xbb[] = "Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))"; +static const char __pyx_k_Incompatible_checksums_s_vs_0xd4[] = "Incompatible checksums (%s vs 0xd41d8cd = ())"; static const char __pyx_k_Indirect_dimensions_not_supporte[] = "Indirect dimensions not supported"; +static const char __pyx_k_Invalid_MD_tag_MD_length_mismatc[] = "Invalid MD tag: MD length {} mismatch with CIGAR length {} and {} insertions"; +static const char __pyx_k_Invalid_clipping_in_CIGAR_string[] = "Invalid clipping in CIGAR string"; static const char __pyx_k_Invalid_mode_expected_c_or_fortr[] = "Invalid mode, expected 'c' or 'fortran', got %s"; static const char __pyx_k_Out_of_bounds_on_buffer_access_a[] = "Out of bounds on buffer access (axis %d)"; static const char __pyx_k_PileupColumn_accessed_after_iter[] = "PileupColumn accessed after iterator finished"; static const char __pyx_k_Unable_to_convert_item_to_object[] = "Unable to convert item to object"; static const char __pyx_k_at_least_one_integer_out_of_rang[] = "at least one integer out of range of BAM/SAM specification"; -static const char __pyx_k_can_t_guess_type_or_invalid_type[] = "can't guess type or invalid type code specified"; +static const char __pyx_k_can_t_guess_type_or_invalid_type[] = "can't guess type or invalid type code specified: {} {}"; +static const char __pyx_k_could_not_allocate_memory_of_byt[] = "could not allocate memory of {} bytes"; +static const char __pyx_k_could_not_allocate_pileup_buffer[] = "could not allocate pileup buffer"; +static const char __pyx_k_could_not_allocate_sequence_of_l[] = "could not allocate sequence of length %i"; +static const char __pyx_k_could_not_allocated_memory_of_by[] = "could not allocated memory of {} bytes"; +static const char __pyx_k_could_not_deduce_typecode_for_va[] = "could not deduce typecode for value {}"; static const char __pyx_k_could_not_determine_alignment_le[] = "could not determine alignment length"; static const char __pyx_k_got_differing_extents_in_dimensi[] = "got differing extents in dimension %d (got %d and %d)"; -static const char __pyx_k_htsfile_does_not_match_aligned_s[] = "htsfile does not match aligned segment"; +static const char __pyx_k_next_reference_name_can_not_be_s[] = "next_reference_name can not be set if no header associated with record"; +static const char __pyx_k_next_reference_name_unknown_if_n[] = "next_reference_name unknown if no header associated with record"; static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__"; +static const char __pyx_k_reference_does_not_exist_in_head[] = "reference {} does not exist in header"; +static const char __pyx_k_reference_id_does_not_exist_in_h[] = "reference id {} does not exist in header"; +static const char __pyx_k_reference_name_can_not_be_set_if[] = "reference_name can not be set if no header associated with record"; +static const char __pyx_k_reference_name_unknown_if_no_hea[] = "reference_name unknown if no header associated with record"; static const char __pyx_k_self__delegate_cannot_be_convert[] = "self._delegate cannot be converted to a Python object for pickling"; static const char __pyx_k_this_class_cannot_be_instantiate[] = "this class cannot be instantiated from Python"; static const char __pyx_k_unable_to_allocate_shape_and_str[] = "unable to allocate shape and strides."; -static const char __pyx_k_unsupported_value_type_in_set_op[] = "unsupported value_type in set_option"; -static PyObject *__pyx_kp_s_2sc_is; -static PyObject *__pyx_kp_s_2sc_s; -static PyObject *__pyx_kp_s_2sccI_i_s; -static PyObject *__pyx_kp_s_2sccI_is; -static PyObject *__pyx_n_b_A; +static const char __pyx_k_unsupported_value_type_in_set_op[] = "unsupported value_type {} in set_option"; +static PyObject *__pyx_kp_s_2sBBI_i_s; +static PyObject *__pyx_kp_s_2sBBI_is; +static PyObject *__pyx_kp_s_2sB_is; +static PyObject *__pyx_kp_s_2sB_s; static PyObject *__pyx_n_s_A; +static PyObject *__pyx_n_s_ACGTacgtNnXx; static PyObject *__pyx_n_s_ASCII; -static PyObject *__pyx_n_b_AZ; static PyObject *__pyx_n_s_AlignedSegment; -static PyObject *__pyx_n_b_B; +static PyObject *__pyx_n_s_AssertionError; static PyObject *__pyx_n_s_B; static PyObject *__pyx_kp_s_Buffer_view_does_not_expose_stri; -static PyObject *__pyx_n_b_C; -static PyObject *__pyx_n_s_C; +static PyObject *__pyx_n_s_CBACK; +static PyObject *__pyx_n_s_CDEL; +static PyObject *__pyx_n_s_CDIFF; +static PyObject *__pyx_n_s_CEQUAL; +static PyObject *__pyx_n_s_CHARD_CLIP; static PyObject *__pyx_n_s_CIGAR2CODE; +static PyObject *__pyx_n_s_CIGAR_OPS; static PyObject *__pyx_n_s_CIGAR_REGEX; +static PyObject *__pyx_n_s_CINS; +static PyObject *__pyx_n_s_CMATCH; +static PyObject *__pyx_n_s_CPAD; +static PyObject *__pyx_n_s_CREF_SKIP; +static PyObject *__pyx_n_s_CSOFT_CLIP; static PyObject *__pyx_kp_s_Can_only_create_a_buffer_that_is; static PyObject *__pyx_kp_s_Cannot_assign_to_read_only_memor; static PyObject *__pyx_kp_s_Cannot_create_writable_memory_vi; static PyObject *__pyx_kp_s_Cannot_index_with_type_s; static PyObject *__pyx_n_s_D; +static PyObject *__pyx_n_s_DATATYPE2FORMAT; static PyObject *__pyx_n_s_Ellipsis; static PyObject *__pyx_kp_s_Empty_shape_tuple_for_cython_arr; +static PyObject *__pyx_n_s_EnumBase; +static PyObject *__pyx_n_s_EnumType; static PyObject *__pyx_n_s_F; +static PyObject *__pyx_n_s_FDUP; +static PyObject *__pyx_n_s_FMREVERSE; +static PyObject *__pyx_n_s_FMUNMAP; +static PyObject *__pyx_n_s_FPAIRED; +static PyObject *__pyx_n_s_FPROPER_PAIR; +static PyObject *__pyx_n_s_FQCFAIL; +static PyObject *__pyx_n_s_FREAD1; +static PyObject *__pyx_n_s_FREAD2; +static PyObject *__pyx_n_s_FREVERSE; +static PyObject *__pyx_n_s_FSECONDARY; +static PyObject *__pyx_n_s_FSUPPLEMENTARY; +static PyObject *__pyx_n_s_FUNMAP; static PyObject *__pyx_n_s_H; -static PyObject *__pyx_n_b_I; static PyObject *__pyx_n_s_I; static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xb0; static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xbb; +static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xd4; static PyObject *__pyx_n_s_IndexError; static PyObject *__pyx_kp_s_Indirect_dimensions_not_supporte; +static PyObject *__pyx_n_s_IntEnum; +static PyObject *__pyx_kp_s_Invalid_MD_tag_MD_length_mismatc; +static PyObject *__pyx_kp_s_Invalid_clipping_in_CIGAR_string; static PyObject *__pyx_kp_s_Invalid_mode_expected_c_or_fortr; static PyObject *__pyx_kp_s_Invalid_shape_in_axis_d_d; static PyObject *__pyx_kp_s_Invalid_tag_s; +static PyObject *__pyx_n_s_KEY_NAMES; static PyObject *__pyx_n_s_KeyError; static PyObject *__pyx_kp_s_MD_tag_not_present; static PyObject *__pyx_n_s_MemoryError; @@ -3545,25 +3930,35 @@ static PyObject *__pyx_kp_s_MemoryView_of_r_object; static PyObject *__pyx_n_s_NotImplemented; static PyObject *__pyx_n_s_NotImplementedError; static PyObject *__pyx_n_b_O; +static PyObject *__pyx_n_s_OrderedDict; static PyObject *__pyx_kp_s_Out_of_bounds_on_buffer_access_a; static PyObject *__pyx_kp_s_Padding_BAM_CPAD_6_is_currently; static PyObject *__pyx_n_s_PickleError; static PyObject *__pyx_n_s_PileupColumn; static PyObject *__pyx_kp_s_PileupColumn_accessed_after_iter; static PyObject *__pyx_n_s_PileupRead; -static PyObject *__pyx_n_b_S; -static PyObject *__pyx_n_s_S; +static PyObject *__pyx_n_s_Pyx_EnumBase; +static PyObject *__pyx_n_s_Pyx_EnumBase___new; +static PyObject *__pyx_n_s_Pyx_EnumBase___repr; +static PyObject *__pyx_n_s_Pyx_EnumBase___str; +static PyObject *__pyx_n_s_SAM_FLAGS; +static PyObject *__pyx_n_s_TGCAtgcaNnXx; static PyObject *__pyx_n_s_TypeError; static PyObject *__pyx_kp_s_Unable_to_convert_item_to_object; +static PyObject *__pyx_kp_s_Unknown_enum_value_s; static PyObject *__pyx_n_s_ValueError; static PyObject *__pyx_n_s_View_MemoryView; -static PyObject *__pyx_n_b_Z; static PyObject *__pyx_n_s_Z; -static PyObject *__pyx_n_s_Zidf; static PyObject *__pyx_kp_s__16; -static PyObject *__pyx_kp_s__19; -static PyObject *__pyx_kp_s__33; +static PyObject *__pyx_kp_s__24; +static PyObject *__pyx_kp_s__27; static PyObject *__pyx_kp_s__4; +static PyObject *__pyx_kp_s__42; +static PyObject *__pyx_kp_s__44; +static PyObject *__pyx_kp_s__8; +static PyObject *__pyx_n_s_a; +static PyObject *__pyx_n_s_aAsSIcCZidfH; +static PyObject *__pyx_n_s_add_indels; static PyObject *__pyx_n_s_alignment; static PyObject *__pyx_n_s_all; static PyObject *__pyx_n_s_allocate_buffer; @@ -3575,35 +3970,45 @@ static PyObject *__pyx_kp_s_at_least_one_integer_out_of_rang; static PyObject *__pyx_kp_s_at_least_one_signed_integer_out; static PyObject *__pyx_n_s_b; static PyObject *__pyx_n_s_base; -static PyObject *__pyx_n_b_c; -static PyObject *__pyx_n_s_c; -static PyObject *__pyx_n_u_c; -static PyObject *__pyx_kp_s_c_2; +static PyObject *__pyx_kp_s_c; +static PyObject *__pyx_n_s_c_2; +static PyObject *__pyx_n_u_c_2; static PyObject *__pyx_n_s_calcsize; static PyObject *__pyx_kp_s_can_t_guess_type_or_invalid_type; static PyObject *__pyx_n_s_chr; +static PyObject *__pyx_n_s_cigar; static PyObject *__pyx_n_s_cigarstring; static PyObject *__pyx_n_s_cigartuples; static PyObject *__pyx_n_s_class; static PyObject *__pyx_n_s_cline_in_traceback; static PyObject *__pyx_n_s_close; +static PyObject *__pyx_n_s_cls; +static PyObject *__pyx_n_s_collections; static PyObject *__pyx_n_s_compare; static PyObject *__pyx_n_s_compile; static PyObject *__pyx_kp_s_contiguous_and_direct; static PyObject *__pyx_kp_s_contiguous_and_indirect; -static PyObject *__pyx_kp_s_could_not_allocated_sequence_of; +static PyObject *__pyx_kp_s_could_not_allocate_memory; +static PyObject *__pyx_kp_s_could_not_allocate_memory_of_byt; +static PyObject *__pyx_kp_s_could_not_allocate_pileup_buffer; +static PyObject *__pyx_kp_s_could_not_allocate_sequence_of_l; +static PyObject *__pyx_kp_s_could_not_allocated_memory; +static PyObject *__pyx_kp_s_could_not_allocated_memory_of_by; +static PyObject *__pyx_kp_s_could_not_deduce_typecode_for_va; static PyObject *__pyx_kp_s_could_not_determine_alignment_le; static PyObject *__pyx_n_s_create_string_buffer; static PyObject *__pyx_n_s_ctypes; static PyObject *__pyx_n_s_d; static PyObject *__pyx_kp_s_d_MIDNSHP_XB; +static PyObject *__pyx_n_s_dct; static PyObject *__pyx_n_s_dict; +static PyObject *__pyx_n_s_doc; static PyObject *__pyx_n_s_dtype_is_object; static PyObject *__pyx_n_s_encode; static PyObject *__pyx_n_s_end; +static PyObject *__pyx_n_s_enum; static PyObject *__pyx_n_s_enumerate; static PyObject *__pyx_n_s_error; -static PyObject *__pyx_n_b_f; static PyObject *__pyx_n_s_f; static PyObject *__pyx_n_s_findall; static PyObject *__pyx_n_s_flag; @@ -3611,60 +4016,85 @@ static PyObject *__pyx_n_s_flags; static PyObject *__pyx_n_s_format; static PyObject *__pyx_n_s_fortran; static PyObject *__pyx_n_u_fortran; +static PyObject *__pyx_n_s_from_dict; +static PyObject *__pyx_n_s_from_dict_locals_genexpr; +static PyObject *__pyx_n_s_fromstring; static PyObject *__pyx_n_s_full_length; static PyObject *__pyx_n_s_genexpr; +static PyObject *__pyx_n_s_get; static PyObject *__pyx_n_s_get_aligned_pairs; static PyObject *__pyx_n_s_get_blocks; +static PyObject *__pyx_n_s_get_num_aligned; static PyObject *__pyx_n_s_get_overlap; +static PyObject *__pyx_n_s_get_reference_name; static PyObject *__pyx_n_s_get_reference_positions; -static PyObject *__pyx_n_s_get_reference_sequence; static PyObject *__pyx_n_s_get_tag; static PyObject *__pyx_n_s_get_tags; -static PyObject *__pyx_n_s_getrname; +static PyObject *__pyx_n_s_get_tid; static PyObject *__pyx_n_s_getstate; static PyObject *__pyx_kp_s_got_differing_extents_in_dimensi; static PyObject *__pyx_n_s_h; static PyObject *__pyx_n_s_has_tag; -static PyObject *__pyx_kp_s_htsfile_does_not_match_aligned_s; -static PyObject *__pyx_n_b_i; +static PyObject *__pyx_n_s_header; +static PyObject *__pyx_n_s_htsfile; static PyObject *__pyx_n_s_i; +static PyObject *__pyx_n_s_iIcCsS; static PyObject *__pyx_kp_s_i_c; static PyObject *__pyx_n_s_id; static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_indel; static PyObject *__pyx_n_s_infer_query_length; -static PyObject *__pyx_kp_s_invalid_value_type_s; -static PyObject *__pyx_kp_s_invalid_value_type_s_s; +static PyObject *__pyx_n_s_infer_read_length; +static PyObject *__pyx_n_s_init; +static PyObject *__pyx_kp_s_invalid_value_type; +static PyObject *__pyx_kp_s_invalid_value_type_2; static PyObject *__pyx_n_s_is_del; static PyObject *__pyx_n_s_is_head; static PyObject *__pyx_n_s_is_refskip; +static PyObject *__pyx_n_s_is_reverse; static PyObject *__pyx_n_s_is_tail; +static PyObject *__pyx_n_s_is_valid_tid; static PyObject *__pyx_n_s_itemsize; static PyObject *__pyx_kp_s_itemsize_0_for_cython_array; static PyObject *__pyx_n_s_join; +static PyObject *__pyx_n_s_json; +static PyObject *__pyx_n_s_length; static PyObject *__pyx_n_s_level; static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_maketrans; static PyObject *__pyx_kp_s_malformatted_tag_s; static PyObject *__pyx_n_s_map; +static PyObject *__pyx_n_s_map_quality; static PyObject *__pyx_n_s_mapping_quality; +static PyObject *__pyx_n_s_mark_ends; +static PyObject *__pyx_n_s_mark_matches; static PyObject *__pyx_n_s_matches_only; static PyObject *__pyx_n_s_max; +static PyObject *__pyx_n_s_members; static PyObject *__pyx_n_s_memview; +static PyObject *__pyx_n_s_metaclass; static PyObject *__pyx_n_s_min; static PyObject *__pyx_n_s_mode; +static PyObject *__pyx_n_s_module; static PyObject *__pyx_n_s_name; static PyObject *__pyx_n_s_name_2; static PyObject *__pyx_n_s_ndim; static PyObject *__pyx_n_s_new; +static PyObject *__pyx_n_s_next_ref_name; +static PyObject *__pyx_n_s_next_ref_pos; static PyObject *__pyx_n_s_next_reference_id; +static PyObject *__pyx_kp_s_next_reference_name_can_not_be_s; +static PyObject *__pyx_kp_s_next_reference_name_unknown_if_n; static PyObject *__pyx_n_s_next_reference_start; static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; static PyObject *__pyx_n_s_nsegments; static PyObject *__pyx_n_s_obj; static PyObject *__pyx_n_s_pack; static PyObject *__pyx_n_s_pack_into; +static PyObject *__pyx_n_s_parents; static PyObject *__pyx_n_s_pickle; static PyObject *__pyx_n_s_pileups; +static PyObject *__pyx_n_s_prepare; static PyObject *__pyx_n_s_pysam_libcalignedsegment; static PyObject *__pyx_n_s_pyx_PickleError; static PyObject *__pyx_n_s_pyx_checksum; @@ -3674,15 +4104,18 @@ static PyObject *__pyx_n_s_pyx_state; static PyObject *__pyx_n_s_pyx_type; static PyObject *__pyx_n_s_pyx_unpickle_Enum; static PyObject *__pyx_n_s_pyx_unpickle_PileupRead; +static PyObject *__pyx_n_s_pyx_unpickle___Pyx_EnumMeta; static PyObject *__pyx_n_s_pyx_vtable; +static PyObject *__pyx_n_s_qual; static PyObject *__pyx_kp_s_quality_and_sequence_mismatch_i; +static PyObject *__pyx_n_s_qualname; static PyObject *__pyx_n_s_query_alignment_end; static PyObject *__pyx_n_s_query_alignment_length; static PyObject *__pyx_n_s_query_alignment_qualities; static PyObject *__pyx_n_s_query_alignment_sequence; static PyObject *__pyx_n_s_query_alignment_start; static PyObject *__pyx_n_s_query_length; -static PyObject *__pyx_kp_s_query_length_out_of_range_254; +static PyObject *__pyx_kp_s_query_length_out_of_range_251; static PyObject *__pyx_n_s_query_name; static PyObject *__pyx_n_s_query_position; static PyObject *__pyx_n_s_query_qualities; @@ -3693,30 +4126,45 @@ static PyObject *__pyx_n_s_re; static PyObject *__pyx_n_s_reduce; static PyObject *__pyx_n_s_reduce_cython; static PyObject *__pyx_n_s_reduce_ex; +static PyObject *__pyx_n_s_ref_name; +static PyObject *__pyx_n_s_ref_pos; +static PyObject *__pyx_kp_s_reference_does_not_exist_in_head; static PyObject *__pyx_n_s_reference_end; static PyObject *__pyx_n_s_reference_id; +static PyObject *__pyx_kp_s_reference_id_does_not_exist_in_h; static PyObject *__pyx_n_s_reference_length; +static PyObject *__pyx_kp_s_reference_name_can_not_be_set_if; +static PyObject *__pyx_kp_s_reference_name_unknown_if_no_hea; static PyObject *__pyx_n_s_reference_pos; static PyObject *__pyx_n_s_reference_start; static PyObject *__pyx_n_s_replace; -static PyObject *__pyx_n_b_s; -static PyObject *__pyx_n_s_s; +static PyObject *__pyx_n_s_repr; +static PyObject *__pyx_n_s_res; +static PyObject *__pyx_kp_s_s_s; +static PyObject *__pyx_kp_s_s_s_d; +static PyObject *__pyx_n_s_sam; +static PyObject *__pyx_n_s_sam_dict; static PyObject *__pyx_kp_s_sam_format_failed; +static PyObject *__pyx_n_s_self; static PyObject *__pyx_kp_s_self__delegate_cannot_be_convert; static PyObject *__pyx_kp_s_self_plp_cannot_be_converted_to; static PyObject *__pyx_n_s_send; +static PyObject *__pyx_n_s_seq; static PyObject *__pyx_n_s_set_tag; static PyObject *__pyx_n_s_set_tags; static PyObject *__pyx_n_s_setstate; static PyObject *__pyx_n_s_setstate_cython; static PyObject *__pyx_n_s_shape; static PyObject *__pyx_n_s_size; +static PyObject *__pyx_n_s_split; static PyObject *__pyx_n_s_start; static PyObject *__pyx_n_s_step; static PyObject *__pyx_n_s_stop; +static PyObject *__pyx_n_s_str; static PyObject *__pyx_kp_s_strided_and_direct; static PyObject *__pyx_kp_s_strided_and_direct_or_indirect; static PyObject *__pyx_kp_s_strided_and_indirect; +static PyObject *__pyx_n_s_string; static PyObject *__pyx_kp_s_stringsource; static PyObject *__pyx_n_s_struct; static PyObject *__pyx_n_s_tag; @@ -3726,7 +4174,10 @@ static PyObject *__pyx_n_s_template_length; static PyObject *__pyx_n_s_test; static PyObject *__pyx_kp_s_this_class_cannot_be_instantiate; static PyObject *__pyx_n_s_throw; +static PyObject *__pyx_n_s_to_string; +static PyObject *__pyx_n_s_todo; static PyObject *__pyx_n_s_tostring; +static PyObject *__pyx_n_s_translate; static PyObject *__pyx_n_s_typecode; static PyObject *__pyx_kp_s_unable_to_allocate_array_data; static PyObject *__pyx_kp_s_unable_to_allocate_shape_and_str; @@ -3736,13 +4187,16 @@ static PyObject *__pyx_n_s_unpack; static PyObject *__pyx_kp_s_unsupported_type_code; static PyObject *__pyx_kp_s_unsupported_value_type_in_set_op; static PyObject *__pyx_n_s_update; +static PyObject *__pyx_n_s_v; static PyObject *__pyx_n_s_value; static PyObject *__pyx_n_s_value_type; +static PyObject *__pyx_n_s_values; static PyObject *__pyx_n_s_with_seq; static PyObject *__pyx_n_s_with_value_type; +static PyObject *__pyx_n_s_zip; static PyObject *__pyx_pf_5pysam_18libcalignedsegment_genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_3genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment___init__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment___init__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header); /* proto */ static void __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_2__dealloc__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4__str__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6__copy__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ @@ -3750,12 +4204,18 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8__deepco static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10compare(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_other); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12__richcmp__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_other, int __pyx_v_op); /* proto */ static Py_hash_t __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14__hash__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16tostring(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, __pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t __pyx_v_htsfile); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16to_string(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_18fromstring(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_sam, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20tostring(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_htsfile); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_22to_dict(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9from_dict_genexpr(PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_24from_dict(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_sam_dict, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10query_name___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qname); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4flag___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4flag_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_flag); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ @@ -3767,6 +4227,7 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_2 static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mtid); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mpos); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12query_length___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ @@ -3809,20 +4270,23 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_25query_a static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_21query_alignment_start___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19query_alignment_end___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_22query_alignment_length___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_18get_reference_positions(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_full_length); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20infer_query_length(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_always); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_22get_reference_sequence(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_24get_aligned_pairs(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_matches_only, PyObject *__pyx_v_with_seq); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_26get_blocks(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_28get_overlap(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, uint32_t __pyx_v_start, uint32_t __pyx_v_end); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_30get_cigar_stats(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_26get_reference_positions(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_full_length); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_28infer_query_length(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_always); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_30infer_read_length(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_32get_reference_sequence(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_34get_forward_sequence(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_36get_forward_qualities(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_38get_aligned_pairs(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_matches_only, PyObject *__pyx_v_with_seq); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_40get_blocks(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_42get_overlap(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, uint32_t __pyx_v_start, uint32_t __pyx_v_end); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_44get_cigar_stats(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_values); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_32set_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_34has_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_36get_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_with_value_type); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_38get_tags(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_with_value_type); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_40set_tags(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_46set_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_48has_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_50get_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_with_value_type); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_52get_tags(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_with_value_type); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_54set_tags(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qname___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qname_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3tid___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ @@ -3873,13 +4337,17 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15inferre static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9positions___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tags___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tags_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_42overlap(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_44opt(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_46setTag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_48__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_50__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_56overlap(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_58opt(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_60setTag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6header___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_62__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_64__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_2__str__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ +static void __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_4__dealloc__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_6set_min_base_quality(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_min_base_quality); /* proto */ +static Py_ssize_t __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_8__len__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_12reference_id___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_14reference_name___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_9nsegments___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ @@ -3892,8 +4360,14 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3tid___get_ static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3tid_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_1n___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_1n_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_10get_num_aligned(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_12get_query_sequences(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, int __pyx_v_mark_matches, int __pyx_v_mark_ends, int __pyx_v_add_indels); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_14get_query_qualities(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_16get_mapping_qualities(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_18get_query_positions(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_20get_query_names(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_22__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_24__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_18libcalignedsegment_10PileupRead___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_2__str__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_9alignment___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self); /* proto */ @@ -3910,6 +4384,15 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_6__setstate_c static PyObject *__pyx_pf_5pysam_18libcalignedsegment_6__pyx_unpickle_PileupRead(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags); /* proto */ static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ +static int __pyx_pf_8EnumBase_14__Pyx_EnumMeta___init__(struct __pyx_obj___Pyx_EnumMeta *__pyx_v_cls, PyObject *__pyx_v_name, PyObject *__pyx_v_parents, PyObject *__pyx_v_dct); /* proto */ +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumMeta_2__iter__(struct __pyx_obj___Pyx_EnumMeta *__pyx_v_cls); /* proto */ +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumMeta_4__getitem__(struct __pyx_obj___Pyx_EnumMeta *__pyx_v_cls, PyObject *__pyx_v_name); /* proto */ +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumMeta_6__reduce_cython__(struct __pyx_obj___Pyx_EnumMeta *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumMeta_8__setstate_cython__(struct __pyx_obj___Pyx_EnumMeta *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumBase___new__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cls, PyObject *__pyx_v_value, PyObject *__pyx_v_name); /* proto */ +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumBase_2__repr__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumBase_4__str__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8EnumBase___pyx_unpickle___Pyx_EnumMeta(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer); /* proto */ static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self); /* proto */ @@ -3957,6 +4440,9 @@ static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment_PileupColumn(PyTypeObj static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment_PileupRead(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new___Pyx_EnumMeta(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_memoryview(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ @@ -3965,73 +4451,74 @@ static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; static PyObject *__pyx_int_2; static PyObject *__pyx_int_4; -static PyObject *__pyx_int_128; -static PyObject *__pyx_int_256; -static PyObject *__pyx_int_32768; -static PyObject *__pyx_int_65536; +static PyObject *__pyx_int_8; +static PyObject *__pyx_int_65; +static PyObject *__pyx_int_66; +static PyObject *__pyx_int_67; +static PyObject *__pyx_int_73; +static PyObject *__pyx_int_83; +static PyObject *__pyx_int_97; +static PyObject *__pyx_int_99; +static PyObject *__pyx_int_100; +static PyObject *__pyx_int_102; +static PyObject *__pyx_int_105; +static PyObject *__pyx_int_115; static PyObject *__pyx_int_184977713; static PyObject *__pyx_int_196873109; -static PyObject *__pyx_int_2147483648; +static PyObject *__pyx_int_222419149; static PyObject *__pyx_int_4294967295; -static PyObject *__pyx_int_4294967296; static PyObject *__pyx_int_neg_1; -static PyObject *__pyx_int_neg_128; -static PyObject *__pyx_int_neg_32768; -static PyObject *__pyx_int_neg_2147483648; static PyObject *__pyx_tuple_; +static PyObject *__pyx_slice__5; +static PyObject *__pyx_slice__6; +static PyObject *__pyx_slice__7; static PyObject *__pyx_tuple__2; static PyObject *__pyx_tuple__3; -static PyObject *__pyx_tuple__5; -static PyObject *__pyx_tuple__6; -static PyObject *__pyx_tuple__7; -static PyObject *__pyx_tuple__8; static PyObject *__pyx_tuple__9; -static PyObject *__pyx_slice__13; -static PyObject *__pyx_slice__14; -static PyObject *__pyx_slice__15; -static PyObject *__pyx_slice__27; -static PyObject *__pyx_slice__28; -static PyObject *__pyx_slice__54; -static PyObject *__pyx_slice__55; -static PyObject *__pyx_slice__56; +static PyObject *__pyx_slice__20; +static PyObject *__pyx_slice__21; +static PyObject *__pyx_slice__31; +static PyObject *__pyx_slice__32; +static PyObject *__pyx_slice__36; +static PyObject *__pyx_slice__37; +static PyObject *__pyx_slice__69; +static PyObject *__pyx_slice__70; +static PyObject *__pyx_slice__71; static PyObject *__pyx_tuple__10; static PyObject *__pyx_tuple__11; static PyObject *__pyx_tuple__12; +static PyObject *__pyx_tuple__13; +static PyObject *__pyx_tuple__14; +static PyObject *__pyx_tuple__15; static PyObject *__pyx_tuple__17; static PyObject *__pyx_tuple__18; -static PyObject *__pyx_tuple__20; -static PyObject *__pyx_tuple__21; +static PyObject *__pyx_tuple__19; static PyObject *__pyx_tuple__22; static PyObject *__pyx_tuple__23; -static PyObject *__pyx_tuple__24; static PyObject *__pyx_tuple__25; static PyObject *__pyx_tuple__26; +static PyObject *__pyx_tuple__28; static PyObject *__pyx_tuple__29; static PyObject *__pyx_tuple__30; -static PyObject *__pyx_tuple__31; -static PyObject *__pyx_tuple__32; +static PyObject *__pyx_tuple__33; static PyObject *__pyx_tuple__34; static PyObject *__pyx_tuple__35; -static PyObject *__pyx_tuple__36; -static PyObject *__pyx_tuple__37; +static PyObject *__pyx_tuple__38; static PyObject *__pyx_tuple__39; static PyObject *__pyx_tuple__40; static PyObject *__pyx_tuple__41; -static PyObject *__pyx_tuple__42; static PyObject *__pyx_tuple__43; -static PyObject *__pyx_tuple__44; static PyObject *__pyx_tuple__45; static PyObject *__pyx_tuple__46; static PyObject *__pyx_tuple__47; static PyObject *__pyx_tuple__48; -static PyObject *__pyx_tuple__49; -static PyObject *__pyx_tuple__50; -static PyObject *__pyx_tuple__51; -static PyObject *__pyx_tuple__52; -static PyObject *__pyx_tuple__53; +static PyObject *__pyx_tuple__54; +static PyObject *__pyx_tuple__55; +static PyObject *__pyx_tuple__56; static PyObject *__pyx_tuple__57; static PyObject *__pyx_tuple__58; static PyObject *__pyx_tuple__59; +static PyObject *__pyx_tuple__60; static PyObject *__pyx_tuple__61; static PyObject *__pyx_tuple__62; static PyObject *__pyx_tuple__63; @@ -4040,17 +4527,47 @@ static PyObject *__pyx_tuple__65; static PyObject *__pyx_tuple__66; static PyObject *__pyx_tuple__67; static PyObject *__pyx_tuple__68; -static PyObject *__pyx_codeobj__38; -static PyObject *__pyx_codeobj__60; +static PyObject *__pyx_tuple__72; +static PyObject *__pyx_tuple__73; +static PyObject *__pyx_tuple__74; +static PyObject *__pyx_tuple__76; +static PyObject *__pyx_tuple__77; +static PyObject *__pyx_tuple__78; +static PyObject *__pyx_tuple__79; +static PyObject *__pyx_tuple__80; +static PyObject *__pyx_tuple__81; +static PyObject *__pyx_tuple__82; +static PyObject *__pyx_tuple__83; +static PyObject *__pyx_tuple__84; +static PyObject *__pyx_tuple__85; +static PyObject *__pyx_tuple__86; +static PyObject *__pyx_tuple__87; +static PyObject *__pyx_tuple__88; +static PyObject *__pyx_tuple__89; +static PyObject *__pyx_tuple__90; +static PyObject *__pyx_tuple__91; +static PyObject *__pyx_tuple__92; +static PyObject *__pyx_tuple__93; +static PyObject *__pyx_tuple__94; +static PyObject *__pyx_tuple__95; +static PyObject *__pyx_tuple__96; +static PyObject *__pyx_tuple__97; +static PyObject *__pyx_tuple__98; +static PyObject *__pyx_codeobj__49; +static PyObject *__pyx_codeobj__50; +static PyObject *__pyx_codeobj__51; +static PyObject *__pyx_codeobj__52; +static PyObject *__pyx_codeobj__53; +static PyObject *__pyx_codeobj__75; /* Late includes */ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_2generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcalignedsegment.pyx":84 +/* "pysam/libcalignedsegment.pyx":96 * - * if PY_MAJOR_VERSION >= 3: + * if IS_PYTHON3: * CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) # <<<<<<<<<<<<<< + * maketrans = str.maketrans * else: - * CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR)) */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_genexpr(CYTHON_UNUSED PyObject *__pyx_self) { @@ -4062,12 +4579,12 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_genexpr(CYTHON_UNUSED PyOb if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 84, __pyx_L1_error) + __PYX_ERR(0, 96, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_18libcalignedsegment_2generator, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_genexpr, __pyx_n_s_pysam_libcalignedsegment); if (unlikely(!gen)) __PYX_ERR(0, 84, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_18libcalignedsegment_2generator, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_genexpr, __pyx_n_s_pysam_libcalignedsegment); if (unlikely(!gen)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -4094,7 +4611,7 @@ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_2generator(__pyx_Coroutine PyObject *(*__pyx_t_4)(PyObject *); __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("genexpr", 0); - __Pyx_TraceCall("genexpr", __pyx_f[0], 84, 0, __PYX_ERR(0, 84, __pyx_L1_error)); + __Pyx_TraceCall("genexpr", __pyx_f[0], 96, 0, __PYX_ERR(0, 96, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -4104,14 +4621,14 @@ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_2generator(__pyx_Coroutine return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 84, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_INCREF(__pyx_int_0); __pyx_t_1 = __pyx_int_0; - __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_5pysam_18libcalignedsegment_CODE2CIGAR); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 84, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_5pysam_18libcalignedsegment_CODE2CIGAR); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 84, __pyx_L1_error) + __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 84, __pyx_L1_error) + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { { @@ -4120,7 +4637,7 @@ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_2generator(__pyx_Coroutine PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 84, __pyx_L1_error) + else __PYX_ERR(0, 96, __pyx_L1_error) } break; } @@ -4134,12 +4651,12 @@ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_2generator(__pyx_Coroutine __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x); __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 84, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = __pyx_t_2; __pyx_t_2 = 0; - __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 84, __pyx_L1_error) + __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_cur_scope->__pyx_v_y); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_y); @@ -4169,7 +4686,7 @@ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_2generator(__pyx_Coroutine __pyx_cur_scope->__pyx_t_1 = 0; __Pyx_XGOTREF(__pyx_t_3); __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 84, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 96, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -4194,12 +4711,12 @@ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_2generator(__pyx_Coroutine } static PyObject *__pyx_gb_5pysam_18libcalignedsegment_5generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcalignedsegment.pyx":86 - * CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) +/* "pysam/libcalignedsegment.pyx":99 + * maketrans = str.maketrans * else: * CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR)) # <<<<<<<<<<<<<< + * maketrans = string.maketrans * - * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=XB])") */ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_3genexpr(CYTHON_UNUSED PyObject *__pyx_self) { @@ -4211,12 +4728,12 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_3genexpr(CYTHON_UNUSED PyO if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 86, __pyx_L1_error) + __PYX_ERR(0, 99, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_18libcalignedsegment_5generator1, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_genexpr, __pyx_n_s_pysam_libcalignedsegment); if (unlikely(!gen)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_18libcalignedsegment_5generator1, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_genexpr, __pyx_n_s_pysam_libcalignedsegment); if (unlikely(!gen)) __PYX_ERR(0, 99, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -4245,7 +4762,7 @@ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_5generator1(__pyx_Coroutin PyObject *__pyx_t_6 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("genexpr", 0); - __Pyx_TraceCall("genexpr", __pyx_f[0], 86, 0, __PYX_ERR(0, 86, __pyx_L1_error)); + __Pyx_TraceCall("genexpr", __pyx_f[0], 99, 0, __PYX_ERR(0, 99, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -4255,14 +4772,14 @@ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_5generator1(__pyx_Coroutin return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 86, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 99, __pyx_L1_error) __Pyx_INCREF(__pyx_int_0); __pyx_t_1 = __pyx_int_0; - __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_5pysam_18libcalignedsegment_CODE2CIGAR); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_5pysam_18libcalignedsegment_CODE2CIGAR); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 99, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 99, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 99, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { { @@ -4271,7 +4788,7 @@ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_5generator1(__pyx_Coroutin PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 86, __pyx_L1_error) + else __PYX_ERR(0, 99, __pyx_L1_error) } break; } @@ -4285,15 +4802,15 @@ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_5generator1(__pyx_Coroutin __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x); __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 99, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = __pyx_t_2; __pyx_t_2 = 0; - __pyx_t_5 = __Pyx_PyObject_Ord(__pyx_cur_scope->__pyx_v_y); if (unlikely(__pyx_t_5 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 86, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Ord(__pyx_cur_scope->__pyx_v_y); if (unlikely(__pyx_t_5 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 99, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 99, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 99, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_2); PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); @@ -4323,7 +4840,7 @@ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_5generator1(__pyx_Coroutin __pyx_cur_scope->__pyx_t_1 = 0; __Pyx_XGOTREF(__pyx_t_3); __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 86, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 99, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -4348,7 +4865,7 @@ static PyObject *__pyx_gb_5pysam_18libcalignedsegment_5generator1(__pyx_Coroutin return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":92 +/* "pysam/libcalignedsegment.pyx":110 * ##################################################################### * # C multiplication with wrapping around * cdef inline uint32_t c_mul(uint32_t a, uint32_t b): # <<<<<<<<<<<<<< @@ -4364,26 +4881,26 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_c_mul(uint32_t PyObject *__pyx_t_2 = NULL; uint32_t __pyx_t_3; __Pyx_RefNannySetupContext("c_mul", 0); - __Pyx_TraceCall("c_mul", __pyx_f[0], 92, 0, __PYX_ERR(0, 92, __pyx_L1_error)); + __Pyx_TraceCall("c_mul", __pyx_f[0], 110, 0, __PYX_ERR(0, 110, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":93 + /* "pysam/libcalignedsegment.pyx":111 * # C multiplication with wrapping around * cdef inline uint32_t c_mul(uint32_t a, uint32_t b): * return (a * b) & 0xffffffff # <<<<<<<<<<<<<< * * */ - __pyx_t_1 = __Pyx_PyInt_From_uint32_t((__pyx_v_a * __pyx_v_b)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_uint32_t((__pyx_v_a * __pyx_v_b)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 111, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4294967295); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4294967295); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 111, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = __Pyx_PyInt_As_uint32_t(__pyx_t_2); if (unlikely((__pyx_t_3 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_As_uint32_t(__pyx_t_2); if (unlikely((__pyx_t_3 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 111, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":92 + /* "pysam/libcalignedsegment.pyx":110 * ##################################################################### * # C multiplication with wrapping around * cdef inline uint32_t c_mul(uint32_t a, uint32_t b): # <<<<<<<<<<<<<< @@ -4403,9 +4920,429 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_c_mul(uint32_t return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":98 - * ##################################################################### - * # typecode guessing +/* "pysam/libcalignedsegment.pyx":114 + * + * + * cdef inline uint8_t tolower(uint8_t ch): # <<<<<<<<<<<<<< + * if ch >= 65 and ch <= 90: + * return ch + 32 + */ + +static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_tolower(uint8_t __pyx_v_ch) { + uint8_t __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + __Pyx_RefNannySetupContext("tolower", 0); + __Pyx_TraceCall("tolower", __pyx_f[0], 114, 0, __PYX_ERR(0, 114, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":115 + * + * cdef inline uint8_t tolower(uint8_t ch): + * if ch >= 65 and ch <= 90: # <<<<<<<<<<<<<< + * return ch + 32 + * else: + */ + __pyx_t_2 = ((__pyx_v_ch >= 65) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_ch <= 90) != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":116 + * cdef inline uint8_t tolower(uint8_t ch): + * if ch >= 65 and ch <= 90: + * return ch + 32 # <<<<<<<<<<<<<< + * else: + * return ch + */ + __pyx_r = (__pyx_v_ch + 32); + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":115 + * + * cdef inline uint8_t tolower(uint8_t ch): + * if ch >= 65 and ch <= 90: # <<<<<<<<<<<<<< + * return ch + 32 + * else: + */ + } + + /* "pysam/libcalignedsegment.pyx":118 + * return ch + 32 + * else: + * return ch # <<<<<<<<<<<<<< + * + * + */ + /*else*/ { + __pyx_r = __pyx_v_ch; + goto __pyx_L0; + } + + /* "pysam/libcalignedsegment.pyx":114 + * + * + * cdef inline uint8_t tolower(uint8_t ch): # <<<<<<<<<<<<<< + * if ch >= 65 and ch <= 90: + * return ch + 32 + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("pysam.libcalignedsegment.tolower", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":121 + * + * + * cdef inline uint8_t toupper(uint8_t ch): # <<<<<<<<<<<<<< + * if ch >= 97 and ch <= 122: + * return ch - 32 + */ + +static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_toupper(uint8_t __pyx_v_ch) { + uint8_t __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + __Pyx_RefNannySetupContext("toupper", 0); + __Pyx_TraceCall("toupper", __pyx_f[0], 121, 0, __PYX_ERR(0, 121, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":122 + * + * cdef inline uint8_t toupper(uint8_t ch): + * if ch >= 97 and ch <= 122: # <<<<<<<<<<<<<< + * return ch - 32 + * else: + */ + __pyx_t_2 = ((__pyx_v_ch >= 97) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_ch <= 0x7A) != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":123 + * cdef inline uint8_t toupper(uint8_t ch): + * if ch >= 97 and ch <= 122: + * return ch - 32 # <<<<<<<<<<<<<< + * else: + * return ch + */ + __pyx_r = (__pyx_v_ch - 32); + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":122 + * + * cdef inline uint8_t toupper(uint8_t ch): + * if ch >= 97 and ch <= 122: # <<<<<<<<<<<<<< + * return ch - 32 + * else: + */ + } + + /* "pysam/libcalignedsegment.pyx":125 + * return ch - 32 + * else: + * return ch # <<<<<<<<<<<<<< + * + * + */ + /*else*/ { + __pyx_r = __pyx_v_ch; + goto __pyx_L0; + } + + /* "pysam/libcalignedsegment.pyx":121 + * + * + * cdef inline uint8_t toupper(uint8_t ch): # <<<<<<<<<<<<<< + * if ch >= 97 and ch <= 122: + * return ch - 32 + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("pysam.libcalignedsegment.toupper", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":128 + * + * + * cdef inline uint8_t strand_mark_char(uint8_t ch, bam1_t *b): # <<<<<<<<<<<<<< + * if ch == '=': + * if bam_is_rev(b): + */ + +static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_strand_mark_char(uint8_t __pyx_v_ch, bam1_t *__pyx_v_b) { + uint8_t __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("strand_mark_char", 0); + __Pyx_TraceCall("strand_mark_char", __pyx_f[0], 128, 0, __PYX_ERR(0, 128, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":129 + * + * cdef inline uint8_t strand_mark_char(uint8_t ch, bam1_t *b): + * if ch == '=': # <<<<<<<<<<<<<< + * if bam_is_rev(b): + * return ',' + */ + __pyx_t_1 = ((__pyx_v_ch == '=') != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":130 + * cdef inline uint8_t strand_mark_char(uint8_t ch, bam1_t *b): + * if ch == '=': + * if bam_is_rev(b): # <<<<<<<<<<<<<< + * return ',' + * else: + */ + __pyx_t_1 = (bam_is_rev(__pyx_v_b) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":131 + * if ch == '=': + * if bam_is_rev(b): + * return ',' # <<<<<<<<<<<<<< + * else: + * return '.' + */ + __pyx_r = ','; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":130 + * cdef inline uint8_t strand_mark_char(uint8_t ch, bam1_t *b): + * if ch == '=': + * if bam_is_rev(b): # <<<<<<<<<<<<<< + * return ',' + * else: + */ + } + + /* "pysam/libcalignedsegment.pyx":133 + * return ',' + * else: + * return '.' # <<<<<<<<<<<<<< + * else: + * if bam_is_rev(b): + */ + /*else*/ { + __pyx_r = '.'; + goto __pyx_L0; + } + + /* "pysam/libcalignedsegment.pyx":129 + * + * cdef inline uint8_t strand_mark_char(uint8_t ch, bam1_t *b): + * if ch == '=': # <<<<<<<<<<<<<< + * if bam_is_rev(b): + * return ',' + */ + } + + /* "pysam/libcalignedsegment.pyx":135 + * return '.' + * else: + * if bam_is_rev(b): # <<<<<<<<<<<<<< + * return tolower(ch) + * else: + */ + /*else*/ { + __pyx_t_1 = (bam_is_rev(__pyx_v_b) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":136 + * else: + * if bam_is_rev(b): + * return tolower(ch) # <<<<<<<<<<<<<< + * else: + * return toupper(ch) + */ + __pyx_r = __pyx_f_5pysam_18libcalignedsegment_tolower(__pyx_v_ch); + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":135 + * return '.' + * else: + * if bam_is_rev(b): # <<<<<<<<<<<<<< + * return tolower(ch) + * else: + */ + } + + /* "pysam/libcalignedsegment.pyx":138 + * return tolower(ch) + * else: + * return toupper(ch) # <<<<<<<<<<<<<< + * + * + */ + /*else*/ { + __pyx_r = __pyx_f_5pysam_18libcalignedsegment_toupper(__pyx_v_ch); + goto __pyx_L0; + } + } + + /* "pysam/libcalignedsegment.pyx":128 + * + * + * cdef inline uint8_t strand_mark_char(uint8_t ch, bam1_t *b): # <<<<<<<<<<<<<< + * if ch == '=': + * if bam_is_rev(b): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("pysam.libcalignedsegment.strand_mark_char", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":141 + * + * + * cdef inline bint pileup_base_qual_skip(bam_pileup1_t * p, uint32_t threshold): # <<<<<<<<<<<<<< + * cdef uint32_t c + * if p.qpos < p.b.core.l_qseq: + */ + +static CYTHON_INLINE int __pyx_f_5pysam_18libcalignedsegment_pileup_base_qual_skip(bam_pileup1_t *__pyx_v_p, uint32_t __pyx_v_threshold) { + uint32_t __pyx_v_c; + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("pileup_base_qual_skip", 0); + __Pyx_TraceCall("pileup_base_qual_skip", __pyx_f[0], 141, 0, __PYX_ERR(0, 141, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":143 + * cdef inline bint pileup_base_qual_skip(bam_pileup1_t * p, uint32_t threshold): + * cdef uint32_t c + * if p.qpos < p.b.core.l_qseq: # <<<<<<<<<<<<<< + * c = bam_get_qual(p.b)[p.qpos] + * else: + */ + __pyx_t_1 = ((__pyx_v_p->qpos < __pyx_v_p->b->core.l_qseq) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":144 + * cdef uint32_t c + * if p.qpos < p.b.core.l_qseq: + * c = bam_get_qual(p.b)[p.qpos] # <<<<<<<<<<<<<< + * else: + * c = 0 + */ + __pyx_v_c = (bam_get_qual(__pyx_v_p->b)[__pyx_v_p->qpos]); + + /* "pysam/libcalignedsegment.pyx":143 + * cdef inline bint pileup_base_qual_skip(bam_pileup1_t * p, uint32_t threshold): + * cdef uint32_t c + * if p.qpos < p.b.core.l_qseq: # <<<<<<<<<<<<<< + * c = bam_get_qual(p.b)[p.qpos] + * else: + */ + goto __pyx_L3; + } + + /* "pysam/libcalignedsegment.pyx":146 + * c = bam_get_qual(p.b)[p.qpos] + * else: + * c = 0 # <<<<<<<<<<<<<< + * if c < threshold: + * return True + */ + /*else*/ { + __pyx_v_c = 0; + } + __pyx_L3:; + + /* "pysam/libcalignedsegment.pyx":147 + * else: + * c = 0 + * if c < threshold: # <<<<<<<<<<<<<< + * return True + * return False + */ + __pyx_t_1 = ((__pyx_v_c < __pyx_v_threshold) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":148 + * c = 0 + * if c < threshold: + * return True # <<<<<<<<<<<<<< + * return False + * + */ + __pyx_r = 1; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":147 + * else: + * c = 0 + * if c < threshold: # <<<<<<<<<<<<<< + * return True + * return False + */ + } + + /* "pysam/libcalignedsegment.pyx":149 + * if c < threshold: + * return True + * return False # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":141 + * + * + * cdef inline bint pileup_base_qual_skip(bam_pileup1_t * p, uint32_t threshold): # <<<<<<<<<<<<<< + * cdef uint32_t c + * if p.qpos < p.b.core.l_qseq: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("pysam.libcalignedsegment.pileup_base_qual_skip", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":152 + * + * * cdef inline char map_typecode_htslib_to_python(uint8_t s): # <<<<<<<<<<<<<< * """map an htslib typecode to the corresponding python typecode * to be used in the struct or array modules.""" @@ -4418,9 +5355,9 @@ static CYTHON_INLINE char __pyx_f_5pysam_18libcalignedsegment_map_typecode_htsli __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("map_typecode_htslib_to_python", 0); - __Pyx_TraceCall("map_typecode_htslib_to_python", __pyx_f[0], 98, 0, __PYX_ERR(0, 98, __pyx_L1_error)); + __Pyx_TraceCall("map_typecode_htslib_to_python", __pyx_f[0], 152, 0, __PYX_ERR(0, 152, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":103 + /* "pysam/libcalignedsegment.pyx":157 * * # map type from htslib to python array * cdef char * f = strchr(htslib_types, s) # <<<<<<<<<<<<<< @@ -4429,7 +5366,7 @@ static CYTHON_INLINE char __pyx_f_5pysam_18libcalignedsegment_map_typecode_htsli */ __pyx_v_f = strchr(__pyx_v_5pysam_18libcalignedsegment_htslib_types, __pyx_v_s); - /* "pysam/libcalignedsegment.pyx":105 + /* "pysam/libcalignedsegment.pyx":159 * cdef char * f = strchr(htslib_types, s) * * if f == NULL: # <<<<<<<<<<<<<< @@ -4439,7 +5376,7 @@ static CYTHON_INLINE char __pyx_f_5pysam_18libcalignedsegment_map_typecode_htsli __pyx_t_1 = ((__pyx_v_f == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":106 + /* "pysam/libcalignedsegment.pyx":160 * * if f == NULL: * return 0 # <<<<<<<<<<<<<< @@ -4449,7 +5386,7 @@ static CYTHON_INLINE char __pyx_f_5pysam_18libcalignedsegment_map_typecode_htsli __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":105 + /* "pysam/libcalignedsegment.pyx":159 * cdef char * f = strchr(htslib_types, s) * * if f == NULL: # <<<<<<<<<<<<<< @@ -4458,19 +5395,19 @@ static CYTHON_INLINE char __pyx_f_5pysam_18libcalignedsegment_map_typecode_htsli */ } - /* "pysam/libcalignedsegment.pyx":107 + /* "pysam/libcalignedsegment.pyx":161 * if f == NULL: * return 0 * return parray_types[f - htslib_types] # <<<<<<<<<<<<<< * - * cdef inline uint8_t map_typecode_python_to_htslib(char s): + * */ __pyx_r = (__pyx_v_5pysam_18libcalignedsegment_parray_types[(__pyx_v_f - __pyx_v_5pysam_18libcalignedsegment_htslib_types)]); goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":98 - * ##################################################################### - * # typecode guessing + /* "pysam/libcalignedsegment.pyx":152 + * + * * cdef inline char map_typecode_htslib_to_python(uint8_t s): # <<<<<<<<<<<<<< * """map an htslib typecode to the corresponding python typecode * to be used in the struct or array modules.""" @@ -4486,8 +5423,8 @@ static CYTHON_INLINE char __pyx_f_5pysam_18libcalignedsegment_map_typecode_htsli return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":109 - * return parray_types[f - htslib_types] +/* "pysam/libcalignedsegment.pyx":164 + * * * cdef inline uint8_t map_typecode_python_to_htslib(char s): # <<<<<<<<<<<<<< * """determine value type from type code of array""" @@ -4501,9 +5438,9 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_map_typecode_py __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("map_typecode_python_to_htslib", 0); - __Pyx_TraceCall("map_typecode_python_to_htslib", __pyx_f[0], 109, 0, __PYX_ERR(0, 109, __pyx_L1_error)); + __Pyx_TraceCall("map_typecode_python_to_htslib", __pyx_f[0], 164, 0, __PYX_ERR(0, 164, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":111 + /* "pysam/libcalignedsegment.pyx":166 * cdef inline uint8_t map_typecode_python_to_htslib(char s): * """determine value type from type code of array""" * cdef char * f = strchr(parray_types, s) # <<<<<<<<<<<<<< @@ -4512,7 +5449,7 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_map_typecode_py */ __pyx_v_f = strchr(__pyx_v_5pysam_18libcalignedsegment_parray_types, __pyx_v_s); - /* "pysam/libcalignedsegment.pyx":112 + /* "pysam/libcalignedsegment.pyx":167 * """determine value type from type code of array""" * cdef char * f = strchr(parray_types, s) * if f == NULL: # <<<<<<<<<<<<<< @@ -4522,7 +5459,7 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_map_typecode_py __pyx_t_1 = ((__pyx_v_f == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":113 + /* "pysam/libcalignedsegment.pyx":168 * cdef char * f = strchr(parray_types, s) * if f == NULL: * return 0 # <<<<<<<<<<<<<< @@ -4532,7 +5469,7 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_map_typecode_py __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":112 + /* "pysam/libcalignedsegment.pyx":167 * """determine value type from type code of array""" * cdef char * f = strchr(parray_types, s) * if f == NULL: # <<<<<<<<<<<<<< @@ -4541,18 +5478,18 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_map_typecode_py */ } - /* "pysam/libcalignedsegment.pyx":114 + /* "pysam/libcalignedsegment.pyx":169 * if f == NULL: * return 0 * return htslib_types[f - parray_types] # <<<<<<<<<<<<<< * - * # optional tag data manipulation + * */ __pyx_r = (__pyx_v_5pysam_18libcalignedsegment_htslib_types[(__pyx_v_f - __pyx_v_5pysam_18libcalignedsegment_parray_types)]); goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":109 - * return parray_types[f - htslib_types] + /* "pysam/libcalignedsegment.pyx":164 + * * * cdef inline uint8_t map_typecode_python_to_htslib(char s): # <<<<<<<<<<<<<< * """determine value type from type code of array""" @@ -4569,7 +5506,117 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_map_typecode_py return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":117 +/* "pysam/libcalignedsegment.pyx":172 + * + * + * cdef inline void update_bin(bam1_t * src): # <<<<<<<<<<<<<< + * if src.core.flag & BAM_FUNMAP: + * # treat alignment as length of 1 for unmapped reads + */ + +static CYTHON_INLINE void __pyx_f_5pysam_18libcalignedsegment_update_bin(bam1_t *__pyx_v_src) { + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("update_bin", 0); + __Pyx_TraceCall("update_bin", __pyx_f[0], 172, 0, __PYX_ERR(0, 172, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":173 + * + * cdef inline void update_bin(bam1_t * src): + * if src.core.flag & BAM_FUNMAP: # <<<<<<<<<<<<<< + * # treat alignment as length of 1 for unmapped reads + * src.core.bin = hts_reg2bin( + */ + __pyx_t_1 = ((__pyx_v_src->core.flag & BAM_FUNMAP) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":175 + * if src.core.flag & BAM_FUNMAP: + * # treat alignment as length of 1 for unmapped reads + * src.core.bin = hts_reg2bin( # <<<<<<<<<<<<<< + * src.core.pos, + * src.core.pos + 1, + */ + __pyx_v_src->core.bin = hts_reg2bin(__pyx_v_src->core.pos, (__pyx_v_src->core.pos + 1), 14, 5); + + /* "pysam/libcalignedsegment.pyx":173 + * + * cdef inline void update_bin(bam1_t * src): + * if src.core.flag & BAM_FUNMAP: # <<<<<<<<<<<<<< + * # treat alignment as length of 1 for unmapped reads + * src.core.bin = hts_reg2bin( + */ + goto __pyx_L3; + } + + /* "pysam/libcalignedsegment.pyx":180 + * 14, + * 5) + * elif pysam_get_n_cigar(src): # <<<<<<<<<<<<<< + * src.core.bin = hts_reg2bin( + * src.core.pos, + */ + __pyx_t_1 = (pysam_get_n_cigar(__pyx_v_src) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":181 + * 5) + * elif pysam_get_n_cigar(src): + * src.core.bin = hts_reg2bin( # <<<<<<<<<<<<<< + * src.core.pos, + * bam_endpos(src), + */ + __pyx_v_src->core.bin = hts_reg2bin(__pyx_v_src->core.pos, bam_endpos(__pyx_v_src), 14, 5); + + /* "pysam/libcalignedsegment.pyx":180 + * 14, + * 5) + * elif pysam_get_n_cigar(src): # <<<<<<<<<<<<<< + * src.core.bin = hts_reg2bin( + * src.core.pos, + */ + goto __pyx_L3; + } + + /* "pysam/libcalignedsegment.pyx":187 + * 5) + * else: + * src.core.bin = hts_reg2bin( # <<<<<<<<<<<<<< + * src.core.pos, + * src.core.pos + 1, + */ + /*else*/ { + + /* "pysam/libcalignedsegment.pyx":189 + * src.core.bin = hts_reg2bin( + * src.core.pos, + * src.core.pos + 1, # <<<<<<<<<<<<<< + * 14, + * 5) + */ + __pyx_v_src->core.bin = hts_reg2bin(__pyx_v_src->core.pos, (__pyx_v_src->core.pos + 1), 14, 5); + } + __pyx_L3:; + + /* "pysam/libcalignedsegment.pyx":172 + * + * + * cdef inline void update_bin(bam1_t * src): # <<<<<<<<<<<<<< + * if src.core.flag & BAM_FUNMAP: + * # treat alignment as length of 1 for unmapped reads + */ + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("pysam.libcalignedsegment.update_bin", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); +} + +/* "pysam/libcalignedsegment.pyx":195 * * # optional tag data manipulation * cdef convert_binary_tag(uint8_t * tag): # <<<<<<<<<<<<<< @@ -4592,9 +5639,9 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t PyObject *__pyx_t_5 = NULL; int __pyx_t_6; __Pyx_RefNannySetupContext("convert_binary_tag", 0); - __Pyx_TraceCall("convert_binary_tag", __pyx_f[0], 117, 0, __PYX_ERR(0, 117, __pyx_L1_error)); + __Pyx_TraceCall("convert_binary_tag", __pyx_f[0], 195, 0, __PYX_ERR(0, 195, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":124 + /* "pysam/libcalignedsegment.pyx":202 * cdef int32_t nvalues * # get byte size * auxtype = tag[0] # <<<<<<<<<<<<<< @@ -4603,7 +5650,7 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t */ __pyx_v_auxtype = (__pyx_v_tag[0]); - /* "pysam/libcalignedsegment.pyx":125 + /* "pysam/libcalignedsegment.pyx":203 * # get byte size * auxtype = tag[0] * byte_size = aux_type2size(auxtype) # <<<<<<<<<<<<<< @@ -4612,7 +5659,7 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t */ __pyx_v_byte_size = aux_type2size(__pyx_v_auxtype); - /* "pysam/libcalignedsegment.pyx":126 + /* "pysam/libcalignedsegment.pyx":204 * auxtype = tag[0] * byte_size = aux_type2size(auxtype) * tag += 1 # <<<<<<<<<<<<<< @@ -4621,7 +5668,7 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t */ __pyx_v_tag = (__pyx_v_tag + 1); - /* "pysam/libcalignedsegment.pyx":128 + /* "pysam/libcalignedsegment.pyx":206 * tag += 1 * # get number of values in array * nvalues = (tag)[0] # <<<<<<<<<<<<<< @@ -4630,7 +5677,7 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t */ __pyx_v_nvalues = (((int32_t *)__pyx_v_tag)[0]); - /* "pysam/libcalignedsegment.pyx":129 + /* "pysam/libcalignedsegment.pyx":207 * # get number of values in array * nvalues = (tag)[0] * tag += 4 # <<<<<<<<<<<<<< @@ -4639,29 +5686,29 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t */ __pyx_v_tag = (__pyx_v_tag + 4); - /* "pysam/libcalignedsegment.pyx":132 + /* "pysam/libcalignedsegment.pyx":210 * * # define python array * cdef c_array.array c_values = array.array( # <<<<<<<<<<<<<< * chr(map_typecode_htslib_to_python(auxtype))) * c_array.resize(c_values, nvalues) */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 132, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 210, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 132, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 210, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignedsegment.pyx":133 + /* "pysam/libcalignedsegment.pyx":211 * # define python array * cdef c_array.array c_values = array.array( * chr(map_typecode_htslib_to_python(auxtype))) # <<<<<<<<<<<<<< * c_array.resize(c_values, nvalues) * */ - __pyx_t_2 = __Pyx_PyInt_From_char(__pyx_f_5pysam_18libcalignedsegment_map_typecode_htslib_to_python(__pyx_v_auxtype)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 133, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_char(__pyx_f_5pysam_18libcalignedsegment_map_typecode_htslib_to_python(__pyx_v_auxtype)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 211, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 133, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 211, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = NULL; @@ -4675,14 +5722,14 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t } } if (!__pyx_t_2) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -4691,47 +5738,47 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 132, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 210, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":132 + /* "pysam/libcalignedsegment.pyx":210 * * # define python array * cdef c_array.array c_values = array.array( # <<<<<<<<<<<<<< * chr(map_typecode_htslib_to_python(auxtype))) * c_array.resize(c_values, nvalues) */ - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 132, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 210, __pyx_L1_error) __pyx_v_c_values = ((arrayobject *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":134 + /* "pysam/libcalignedsegment.pyx":212 * cdef c_array.array c_values = array.array( * chr(map_typecode_htslib_to_python(auxtype))) * c_array.resize(c_values, nvalues) # <<<<<<<<<<<<<< * * # copy data */ - __pyx_t_6 = resize(__pyx_v_c_values, __pyx_v_nvalues); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 134, __pyx_L1_error) + __pyx_t_6 = resize(__pyx_v_c_values, __pyx_v_nvalues); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 212, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":137 + /* "pysam/libcalignedsegment.pyx":215 * * # copy data * memcpy(c_values.data.as_voidptr, tag, nvalues * byte_size) # <<<<<<<<<<<<<< @@ -4740,7 +5787,7 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t */ (void)(memcpy(__pyx_v_c_values->data.as_voidptr, ((uint8_t *)__pyx_v_tag), (__pyx_v_nvalues * __pyx_v_byte_size))); - /* "pysam/libcalignedsegment.pyx":142 + /* "pysam/libcalignedsegment.pyx":220 * # and aux_data are in host endian-ness. See sam.c and calls * # to swap_data * return byte_size, nvalues, c_values # <<<<<<<<<<<<<< @@ -4748,11 +5795,11 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint8_t(__pyx_v_byte_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_uint8_t(__pyx_v_byte_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 220, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_nvalues); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_nvalues); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 220, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 220, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); @@ -4767,7 +5814,7 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t __pyx_t_5 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":117 + /* "pysam/libcalignedsegment.pyx":195 * * # optional tag data manipulation * cdef convert_binary_tag(uint8_t * tag): # <<<<<<<<<<<<<< @@ -4792,18 +5839,17 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(uint8_t return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":145 +/* "pysam/libcalignedsegment.pyx":223 * * - * cdef inline uint8_t get_value_code(value, value_type=None): # <<<<<<<<<<<<<< - * '''guess type code for a *value*. If *value_type* is None, - * the type code will be inferred based on the Python type of + * cdef inline uint8_t get_tag_typecode(value, value_type=None): # <<<<<<<<<<<<<< + * """guess type code for a *value*. If *value_type* is None, the type + * code will be inferred based on the Python type of *value* */ -static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_value_code(PyObject *__pyx_v_value, struct __pyx_opt_args_5pysam_18libcalignedsegment_get_value_code *__pyx_optional_args) { +static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_tag_typecode(PyObject *__pyx_v_value, struct __pyx_opt_args_5pysam_18libcalignedsegment_get_tag_typecode *__pyx_optional_args) { PyObject *__pyx_v_value_type = ((PyObject *)Py_None); - uint8_t __pyx_v_typecode; - char *__pyx_v__char_type; + char __pyx_v_typecode; uint8_t __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -4812,90 +5858,318 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_value_code( PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_t_5; - char *__pyx_t_6; - __Pyx_RefNannySetupContext("get_value_code", 0); - __Pyx_TraceCall("get_value_code", __pyx_f[0], 145, 0, __PYX_ERR(0, 145, __pyx_L1_error)); + char __pyx_t_6; + __Pyx_RefNannySetupContext("get_tag_typecode", 0); + __Pyx_TraceCall("get_tag_typecode", __pyx_f[0], 223, 0, __PYX_ERR(0, 223, __pyx_L1_error)); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_value_type = __pyx_optional_args->value_type; } } - __Pyx_INCREF(__pyx_v_value_type); - /* "pysam/libcalignedsegment.pyx":152 - * cdef char * _char_type + /* "pysam/libcalignedsegment.pyx":229 + * """ + * # 0 is unknown typecode + * cdef char typecode = 0 # <<<<<<<<<<<<<< + * + * if value_type is None: + */ + __pyx_v_typecode = 0; + + /* "pysam/libcalignedsegment.pyx":231 + * cdef char typecode = 0 * * if value_type is None: # <<<<<<<<<<<<<< * if isinstance(value, int): - * typecode = 'i' + * if value < 0: */ __pyx_t_1 = (__pyx_v_value_type == Py_None); __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":153 + /* "pysam/libcalignedsegment.pyx":232 * * if value_type is None: * if isinstance(value, int): # <<<<<<<<<<<<<< - * typecode = 'i' - * elif isinstance(value, float): + * if value < 0: + * if value >= INT8_MIN: */ __pyx_t_2 = PyInt_Check(__pyx_v_value); __pyx_t_1 = (__pyx_t_2 != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":154 + /* "pysam/libcalignedsegment.pyx":233 + * if value_type is None: + * if isinstance(value, int): + * if value < 0: # <<<<<<<<<<<<<< + * if value >= INT8_MIN: + * typecode = 'c' + */ + __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 233, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 233, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":234 + * if isinstance(value, int): + * if value < 0: + * if value >= INT8_MIN: # <<<<<<<<<<<<<< + * typecode = 'c' + * elif value >= INT16_MIN: + */ + __pyx_t_3 = __Pyx_PyInt_From_int8_t(INT8_MIN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_t_3, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 234, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 234, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":235 + * if value < 0: + * if value >= INT8_MIN: + * typecode = 'c' # <<<<<<<<<<<<<< + * elif value >= INT16_MIN: + * typecode = 's' + */ + __pyx_v_typecode = 'c'; + + /* "pysam/libcalignedsegment.pyx":234 + * if isinstance(value, int): + * if value < 0: + * if value >= INT8_MIN: # <<<<<<<<<<<<<< + * typecode = 'c' + * elif value >= INT16_MIN: + */ + goto __pyx_L6; + } + + /* "pysam/libcalignedsegment.pyx":236 + * if value >= INT8_MIN: + * typecode = 'c' + * elif value >= INT16_MIN: # <<<<<<<<<<<<<< + * typecode = 's' + * elif value >= INT32_MIN: + */ + __pyx_t_4 = __Pyx_PyInt_From_int16_t(INT16_MIN); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 236, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_t_4, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 236, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 236, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":237 + * typecode = 'c' + * elif value >= INT16_MIN: + * typecode = 's' # <<<<<<<<<<<<<< + * elif value >= INT32_MIN: + * typecode = 'i' + */ + __pyx_v_typecode = 's'; + + /* "pysam/libcalignedsegment.pyx":236 + * if value >= INT8_MIN: + * typecode = 'c' + * elif value >= INT16_MIN: # <<<<<<<<<<<<<< + * typecode = 's' + * elif value >= INT32_MIN: + */ + goto __pyx_L6; + } + + /* "pysam/libcalignedsegment.pyx":238 + * elif value >= INT16_MIN: + * typecode = 's' + * elif value >= INT32_MIN: # <<<<<<<<<<<<<< + * typecode = 'i' + * # unsigned ints + */ + __pyx_t_3 = __Pyx_PyInt_From_int32_t(INT32_MIN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_t_3, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 238, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 238, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":239 + * typecode = 's' + * elif value >= INT32_MIN: + * typecode = 'i' # <<<<<<<<<<<<<< + * # unsigned ints + * else: + */ + __pyx_v_typecode = 'i'; + + /* "pysam/libcalignedsegment.pyx":238 + * elif value >= INT16_MIN: + * typecode = 's' + * elif value >= INT32_MIN: # <<<<<<<<<<<<<< + * typecode = 'i' + * # unsigned ints + */ + } + __pyx_L6:; + + /* "pysam/libcalignedsegment.pyx":233 * if value_type is None: * if isinstance(value, int): - * typecode = 'i' # <<<<<<<<<<<<<< + * if value < 0: # <<<<<<<<<<<<<< + * if value >= INT8_MIN: + * typecode = 'c' + */ + goto __pyx_L5; + } + + /* "pysam/libcalignedsegment.pyx":242 + * # unsigned ints + * else: + * if value <= UINT8_MAX: # <<<<<<<<<<<<<< + * typecode = 'C' + * elif value <= UINT16_MAX: + */ + /*else*/ { + __pyx_t_4 = __Pyx_PyInt_From_uint8_t(UINT8_MAX); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 242, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_t_4, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 242, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 242, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":243 + * else: + * if value <= UINT8_MAX: + * typecode = 'C' # <<<<<<<<<<<<<< + * elif value <= UINT16_MAX: + * typecode = 'S' + */ + __pyx_v_typecode = 'C'; + + /* "pysam/libcalignedsegment.pyx":242 + * # unsigned ints + * else: + * if value <= UINT8_MAX: # <<<<<<<<<<<<<< + * typecode = 'C' + * elif value <= UINT16_MAX: + */ + goto __pyx_L7; + } + + /* "pysam/libcalignedsegment.pyx":244 + * if value <= UINT8_MAX: + * typecode = 'C' + * elif value <= UINT16_MAX: # <<<<<<<<<<<<<< + * typecode = 'S' + * elif value <= UINT32_MAX: + */ + __pyx_t_3 = __Pyx_PyInt_From_uint16_t(UINT16_MAX); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 244, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_t_3, Py_LE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 244, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 244, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":245 + * typecode = 'C' + * elif value <= UINT16_MAX: + * typecode = 'S' # <<<<<<<<<<<<<< + * elif value <= UINT32_MAX: + * typecode = 'I' + */ + __pyx_v_typecode = 'S'; + + /* "pysam/libcalignedsegment.pyx":244 + * if value <= UINT8_MAX: + * typecode = 'C' + * elif value <= UINT16_MAX: # <<<<<<<<<<<<<< + * typecode = 'S' + * elif value <= UINT32_MAX: + */ + goto __pyx_L7; + } + + /* "pysam/libcalignedsegment.pyx":246 + * elif value <= UINT16_MAX: + * typecode = 'S' + * elif value <= UINT32_MAX: # <<<<<<<<<<<<<< + * typecode = 'I' + * elif isinstance(value, float): + */ + __pyx_t_4 = __Pyx_PyInt_From_uint32_t(UINT32_MAX); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 246, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_t_4, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 246, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 246, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":247 + * typecode = 'S' + * elif value <= UINT32_MAX: + * typecode = 'I' # <<<<<<<<<<<<<< * elif isinstance(value, float): - * typecode = 'd' + * typecode = 'f' */ - __pyx_v_typecode = 'i'; + __pyx_v_typecode = 'I'; - /* "pysam/libcalignedsegment.pyx":153 + /* "pysam/libcalignedsegment.pyx":246 + * elif value <= UINT16_MAX: + * typecode = 'S' + * elif value <= UINT32_MAX: # <<<<<<<<<<<<<< + * typecode = 'I' + * elif isinstance(value, float): + */ + } + __pyx_L7:; + } + __pyx_L5:; + + /* "pysam/libcalignedsegment.pyx":232 * * if value_type is None: * if isinstance(value, int): # <<<<<<<<<<<<<< - * typecode = 'i' - * elif isinstance(value, float): + * if value < 0: + * if value >= INT8_MIN: */ goto __pyx_L4; } - /* "pysam/libcalignedsegment.pyx":155 - * if isinstance(value, int): - * typecode = 'i' + /* "pysam/libcalignedsegment.pyx":248 + * elif value <= UINT32_MAX: + * typecode = 'I' * elif isinstance(value, float): # <<<<<<<<<<<<<< - * typecode = 'd' + * typecode = 'f' * elif isinstance(value, str): */ __pyx_t_1 = PyFloat_Check(__pyx_v_value); __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":156 - * typecode = 'i' + /* "pysam/libcalignedsegment.pyx":249 + * typecode = 'I' * elif isinstance(value, float): - * typecode = 'd' # <<<<<<<<<<<<<< + * typecode = 'f' # <<<<<<<<<<<<<< * elif isinstance(value, str): * typecode = 'Z' */ - __pyx_v_typecode = 'd'; + __pyx_v_typecode = 'f'; - /* "pysam/libcalignedsegment.pyx":155 - * if isinstance(value, int): - * typecode = 'i' + /* "pysam/libcalignedsegment.pyx":248 + * elif value <= UINT32_MAX: + * typecode = 'I' * elif isinstance(value, float): # <<<<<<<<<<<<<< - * typecode = 'd' + * typecode = 'f' * elif isinstance(value, str): */ goto __pyx_L4; } - /* "pysam/libcalignedsegment.pyx":157 + /* "pysam/libcalignedsegment.pyx":250 * elif isinstance(value, float): - * typecode = 'd' + * typecode = 'f' * elif isinstance(value, str): # <<<<<<<<<<<<<< * typecode = 'Z' * elif isinstance(value, bytes): @@ -4904,8 +6178,8 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_value_code( __pyx_t_1 = (__pyx_t_2 != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":158 - * typecode = 'd' + /* "pysam/libcalignedsegment.pyx":251 + * typecode = 'f' * elif isinstance(value, str): * typecode = 'Z' # <<<<<<<<<<<<<< * elif isinstance(value, bytes): @@ -4913,9 +6187,9 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_value_code( */ __pyx_v_typecode = 'Z'; - /* "pysam/libcalignedsegment.pyx":157 + /* "pysam/libcalignedsegment.pyx":250 * elif isinstance(value, float): - * typecode = 'd' + * typecode = 'f' * elif isinstance(value, str): # <<<<<<<<<<<<<< * typecode = 'Z' * elif isinstance(value, bytes): @@ -4923,7 +6197,7 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_value_code( goto __pyx_L4; } - /* "pysam/libcalignedsegment.pyx":159 + /* "pysam/libcalignedsegment.pyx":252 * elif isinstance(value, str): * typecode = 'Z' * elif isinstance(value, bytes): # <<<<<<<<<<<<<< @@ -4934,7 +6208,7 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_value_code( __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":160 + /* "pysam/libcalignedsegment.pyx":253 * typecode = 'Z' * elif isinstance(value, bytes): * typecode = 'Z' # <<<<<<<<<<<<<< @@ -4943,7 +6217,7 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_value_code( */ __pyx_v_typecode = 'Z'; - /* "pysam/libcalignedsegment.pyx":159 + /* "pysam/libcalignedsegment.pyx":252 * elif isinstance(value, str): * typecode = 'Z' * elif isinstance(value, bytes): # <<<<<<<<<<<<<< @@ -4953,28 +6227,28 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_value_code( goto __pyx_L4; } - /* "pysam/libcalignedsegment.pyx":161 + /* "pysam/libcalignedsegment.pyx":254 * elif isinstance(value, bytes): * typecode = 'Z' * elif isinstance(value, array.array) or \ # <<<<<<<<<<<<<< * isinstance(value, list) or \ * isinstance(value, tuple): */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 254, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 161, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 254, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = PyObject_IsInstance(__pyx_v_value, __pyx_t_4); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 161, __pyx_L1_error) + __pyx_t_1 = PyObject_IsInstance(__pyx_v_value, __pyx_t_4); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 254, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_5 = (__pyx_t_1 != 0); if (!__pyx_t_5) { } else { __pyx_t_2 = __pyx_t_5; - goto __pyx_L5_bool_binop_done; + goto __pyx_L8_bool_binop_done; } - /* "pysam/libcalignedsegment.pyx":162 + /* "pysam/libcalignedsegment.pyx":255 * typecode = 'Z' * elif isinstance(value, array.array) or \ * isinstance(value, list) or \ # <<<<<<<<<<<<<< @@ -4986,22 +6260,22 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_value_code( if (!__pyx_t_1) { } else { __pyx_t_2 = __pyx_t_1; - goto __pyx_L5_bool_binop_done; + goto __pyx_L8_bool_binop_done; } - /* "pysam/libcalignedsegment.pyx":163 + /* "pysam/libcalignedsegment.pyx":256 * elif isinstance(value, array.array) or \ * isinstance(value, list) or \ * isinstance(value, tuple): # <<<<<<<<<<<<<< * typecode = 'B' - * else: + * else: */ __pyx_t_1 = PyTuple_Check(__pyx_v_value); __pyx_t_5 = (__pyx_t_1 != 0); __pyx_t_2 = __pyx_t_5; - __pyx_L5_bool_binop_done:; + __pyx_L8_bool_binop_done:; - /* "pysam/libcalignedsegment.pyx":161 + /* "pysam/libcalignedsegment.pyx":254 * elif isinstance(value, bytes): * typecode = 'Z' * elif isinstance(value, array.array) or \ # <<<<<<<<<<<<<< @@ -5010,114 +6284,77 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_value_code( */ if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":164 + /* "pysam/libcalignedsegment.pyx":257 * isinstance(value, list) or \ * isinstance(value, tuple): * typecode = 'B' # <<<<<<<<<<<<<< - * else: - * return 0 + * else: + * if value_type in 'aAsSIcCZidfH': */ __pyx_v_typecode = 'B'; - /* "pysam/libcalignedsegment.pyx":161 + /* "pysam/libcalignedsegment.pyx":254 * elif isinstance(value, bytes): * typecode = 'Z' * elif isinstance(value, array.array) or \ # <<<<<<<<<<<<<< * isinstance(value, list) or \ * isinstance(value, tuple): */ - goto __pyx_L4; - } - - /* "pysam/libcalignedsegment.pyx":166 - * typecode = 'B' - * else: - * return 0 # <<<<<<<<<<<<<< - * else: - * if value_type not in 'Zidf': - */ - /*else*/ { - __pyx_r = 0; - goto __pyx_L0; } __pyx_L4:; - /* "pysam/libcalignedsegment.pyx":152 - * cdef char * _char_type + /* "pysam/libcalignedsegment.pyx":231 + * cdef char typecode = 0 * * if value_type is None: # <<<<<<<<<<<<<< * if isinstance(value, int): - * typecode = 'i' + * if value < 0: */ goto __pyx_L3; } - /* "pysam/libcalignedsegment.pyx":168 - * return 0 + /* "pysam/libcalignedsegment.pyx":259 + * typecode = 'B' * else: - * if value_type not in 'Zidf': # <<<<<<<<<<<<<< - * return 0 - * value_type = force_bytes(value_type) + * if value_type in 'aAsSIcCZidfH': # <<<<<<<<<<<<<< + * typecode = force_bytes(value_type)[0] + * */ /*else*/ { - __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_value_type, __pyx_n_s_Zidf, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 168, __pyx_L1_error) + __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_value_type, __pyx_n_s_aAsSIcCZidfH, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 259, __pyx_L1_error) __pyx_t_5 = (__pyx_t_2 != 0); if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":169 - * else: - * if value_type not in 'Zidf': - * return 0 # <<<<<<<<<<<<<< - * value_type = force_bytes(value_type) - * _char_type = value_type - */ - __pyx_r = 0; - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":168 - * return 0 + /* "pysam/libcalignedsegment.pyx":260 * else: - * if value_type not in 'Zidf': # <<<<<<<<<<<<<< - * return 0 - * value_type = force_bytes(value_type) - */ - } - - /* "pysam/libcalignedsegment.pyx":170 - * if value_type not in 'Zidf': - * return 0 - * value_type = force_bytes(value_type) # <<<<<<<<<<<<<< - * _char_type = value_type - * typecode = (_char_type)[0] - */ - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value_type, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 170, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF_SET(__pyx_v_value_type, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pysam/libcalignedsegment.pyx":171 - * return 0 - * value_type = force_bytes(value_type) - * _char_type = value_type # <<<<<<<<<<<<<< - * typecode = (_char_type)[0] + * if value_type in 'aAsSIcCZidfH': + * typecode = force_bytes(value_type)[0] # <<<<<<<<<<<<<< * + * return typecode */ - __pyx_t_6 = __Pyx_PyObject_AsWritableString(__pyx_v_value_type); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 171, __pyx_L1_error) - __pyx_v__char_type = __pyx_t_6; + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value_type, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (unlikely(__pyx_t_4 == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 260, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_PyBytes_GetItemInt(((PyObject*)__pyx_t_4), 0, 1); if (unlikely(__pyx_t_6 == ((char)((char)-1)) && PyErr_Occurred())) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_typecode = __pyx_t_6; - /* "pysam/libcalignedsegment.pyx":172 - * value_type = force_bytes(value_type) - * _char_type = value_type - * typecode = (_char_type)[0] # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":259 + * typecode = 'B' + * else: + * if value_type in 'aAsSIcCZidfH': # <<<<<<<<<<<<<< + * typecode = force_bytes(value_type)[0] * - * return typecode */ - __pyx_v_typecode = (((uint8_t *)__pyx_v__char_type)[0]); + } } __pyx_L3:; - /* "pysam/libcalignedsegment.pyx":174 - * typecode = (_char_type)[0] + /* "pysam/libcalignedsegment.pyx":262 + * typecode = force_bytes(value_type)[0] * * return typecode # <<<<<<<<<<<<<< * @@ -5126,40 +6363,40 @@ static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_value_code( __pyx_r = __pyx_v_typecode; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":145 + /* "pysam/libcalignedsegment.pyx":223 * * - * cdef inline uint8_t get_value_code(value, value_type=None): # <<<<<<<<<<<<<< - * '''guess type code for a *value*. If *value_type* is None, - * the type code will be inferred based on the Python type of + * cdef inline uint8_t get_tag_typecode(value, value_type=None): # <<<<<<<<<<<<<< + * """guess type code for a *value*. If *value_type* is None, the type + * code will be inferred based on the Python type of *value* */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_WriteUnraisable("pysam.libcalignedsegment.get_value_code", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __Pyx_WriteUnraisable("pysam.libcalignedsegment.get_tag_typecode", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_r = 0; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_value_type); __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":177 +/* "pysam/libcalignedsegment.pyx":265 * * - * cdef inline bytes getTypecode(value, maximum_value=None): # <<<<<<<<<<<<<< + * cdef inline uint8_t get_btag_typecode(value, min_value=None, max_value=None): # <<<<<<<<<<<<<< * '''returns the value typecode of a value. * */ -static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getTypecode(PyObject *__pyx_v_value, struct __pyx_opt_args_5pysam_18libcalignedsegment_getTypecode *__pyx_optional_args) { - PyObject *__pyx_v_maximum_value = ((PyObject *)Py_None); - PyObject *__pyx_v_valuetype = 0; +static CYTHON_INLINE uint8_t __pyx_f_5pysam_18libcalignedsegment_get_btag_typecode(PyObject *__pyx_v_value, struct __pyx_opt_args_5pysam_18libcalignedsegment_get_btag_typecode *__pyx_optional_args) { + PyObject *__pyx_v_min_value = ((PyObject *)Py_None); + PyObject *__pyx_v_max_value = ((PyObject *)Py_None); + uint8_t __pyx_v_typecode; PyTypeObject *__pyx_v_t = NULL; - PyObject *__pyx_r = NULL; + uint8_t __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; @@ -5167,48 +6404,22 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getTypecode(P PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; Py_ssize_t __pyx_t_5; - __Pyx_RefNannySetupContext("getTypecode", 0); - __Pyx_TraceCall("getTypecode", __pyx_f[0], 177, 0, __PYX_ERR(0, 177, __pyx_L1_error)); + __Pyx_RefNannySetupContext("get_btag_typecode", 0); + __Pyx_TraceCall("get_btag_typecode", __pyx_f[0], 265, 0, __PYX_ERR(0, 265, __pyx_L1_error)); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { - __pyx_v_maximum_value = __pyx_optional_args->maximum_value; + __pyx_v_min_value = __pyx_optional_args->min_value; + if (__pyx_optional_args->__pyx_n > 1) { + __pyx_v_max_value = __pyx_optional_args->max_value; + } } } __Pyx_INCREF(__pyx_v_value); - __Pyx_INCREF(__pyx_v_maximum_value); - - /* "pysam/libcalignedsegment.pyx":184 - * ''' - * - * if maximum_value is None: # <<<<<<<<<<<<<< - * maximum_value = value - * - */ - __pyx_t_1 = (__pyx_v_maximum_value == Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __Pyx_INCREF(__pyx_v_min_value); + __Pyx_INCREF(__pyx_v_max_value); - /* "pysam/libcalignedsegment.pyx":185 - * - * if maximum_value is None: - * maximum_value = value # <<<<<<<<<<<<<< - * - * cdef bytes valuetype - */ - __Pyx_INCREF(__pyx_v_value); - __Pyx_DECREF_SET(__pyx_v_maximum_value, __pyx_v_value); - - /* "pysam/libcalignedsegment.pyx":184 - * ''' - * - * if maximum_value is None: # <<<<<<<<<<<<<< - * maximum_value = value - * - */ - } - - /* "pysam/libcalignedsegment.pyx":189 - * cdef bytes valuetype + /* "pysam/libcalignedsegment.pyx":279 + * cdef uint8_t typecode * * t = type(value) # <<<<<<<<<<<<<< * @@ -5217,336 +6428,418 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getTypecode(P __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value))); __pyx_v_t = ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_v_value))); - /* "pysam/libcalignedsegment.pyx":191 + /* "pysam/libcalignedsegment.pyx":281 * t = type(value) * * if t is float: # <<<<<<<<<<<<<< - * valuetype = b'f' + * typecode = 'f' * elif t is int: */ - __pyx_t_2 = (__pyx_v_t == (&PyFloat_Type)); - __pyx_t_1 = (__pyx_t_2 != 0); - if (__pyx_t_1) { + __pyx_t_1 = (__pyx_v_t == (&PyFloat_Type)); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":192 + /* "pysam/libcalignedsegment.pyx":282 * * if t is float: - * valuetype = b'f' # <<<<<<<<<<<<<< + * typecode = 'f' # <<<<<<<<<<<<<< * elif t is int: - * # signed ints + * if max_value is None: */ - __Pyx_INCREF(__pyx_n_b_f); - __pyx_v_valuetype = __pyx_n_b_f; + __pyx_v_typecode = 'f'; - /* "pysam/libcalignedsegment.pyx":191 + /* "pysam/libcalignedsegment.pyx":281 * t = type(value) * * if t is float: # <<<<<<<<<<<<<< - * valuetype = b'f' + * typecode = 'f' * elif t is int: */ - goto __pyx_L4; + goto __pyx_L3; } - /* "pysam/libcalignedsegment.pyx":193 + /* "pysam/libcalignedsegment.pyx":283 * if t is float: - * valuetype = b'f' + * typecode = 'f' * elif t is int: # <<<<<<<<<<<<<< - * # signed ints - * if value < 0: + * if max_value is None: + * max_value = value */ - __pyx_t_1 = (__pyx_v_t == (&PyInt_Type)); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __pyx_t_2 = (__pyx_v_t == (&PyInt_Type)); + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":284 + * typecode = 'f' + * elif t is int: + * if max_value is None: # <<<<<<<<<<<<<< + * max_value = value + * if min_value is None: + */ + __pyx_t_1 = (__pyx_v_max_value == Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":195 + /* "pysam/libcalignedsegment.pyx":285 * elif t is int: + * if max_value is None: + * max_value = value # <<<<<<<<<<<<<< + * if min_value is None: + * min_value = value + */ + __Pyx_INCREF(__pyx_v_value); + __Pyx_DECREF_SET(__pyx_v_max_value, __pyx_v_value); + + /* "pysam/libcalignedsegment.pyx":284 + * typecode = 'f' + * elif t is int: + * if max_value is None: # <<<<<<<<<<<<<< + * max_value = value + * if min_value is None: + */ + } + + /* "pysam/libcalignedsegment.pyx":286 + * if max_value is None: + * max_value = value + * if min_value is None: # <<<<<<<<<<<<<< + * min_value = value + * # signed ints + */ + __pyx_t_2 = (__pyx_v_min_value == Py_None); + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":287 + * max_value = value + * if min_value is None: + * min_value = value # <<<<<<<<<<<<<< + * # signed ints + * if min_value < 0: + */ + __Pyx_INCREF(__pyx_v_value); + __Pyx_DECREF_SET(__pyx_v_min_value, __pyx_v_value); + + /* "pysam/libcalignedsegment.pyx":286 + * if max_value is None: + * max_value = value + * if min_value is None: # <<<<<<<<<<<<<< + * min_value = value + * # signed ints + */ + } + + /* "pysam/libcalignedsegment.pyx":289 + * min_value = value * # signed ints - * if value < 0: # <<<<<<<<<<<<<< - * if value >= -128 and maximum_value < 128: - * valuetype = b'c' + * if min_value < 0: # <<<<<<<<<<<<<< + * if min_value >= INT8_MIN and max_value <= INT8_MAX: + * typecode = 'c' */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 195, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 195, __pyx_L1_error) + __pyx_t_3 = PyObject_RichCompare(__pyx_v_min_value, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 289, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 289, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_2) { + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":196 + /* "pysam/libcalignedsegment.pyx":290 * # signed ints - * if value < 0: - * if value >= -128 and maximum_value < 128: # <<<<<<<<<<<<<< - * valuetype = b'c' - * elif value >= -32768 and maximum_value < 32768: + * if min_value < 0: + * if min_value >= INT8_MIN and max_value <= INT8_MAX: # <<<<<<<<<<<<<< + * typecode = 'c' + * elif min_value >= INT16_MIN and max_value <= INT16_MAX: */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_128, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 196, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 196, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int8_t(INT8_MIN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 290, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_min_value, __pyx_t_3, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 290, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_1) { + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 290, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_2) { } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L7_bool_binop_done; + __pyx_t_1 = __pyx_t_2; + goto __pyx_L8_bool_binop_done; } - __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_128, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 196, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 196, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int8_t(INT8_MAX); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 290, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_max_value, __pyx_t_4, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 290, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 290, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_2 = __pyx_t_1; - __pyx_L7_bool_binop_done:; - if (__pyx_t_2) { + __pyx_t_1 = __pyx_t_2; + __pyx_L8_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":197 - * if value < 0: - * if value >= -128 and maximum_value < 128: - * valuetype = b'c' # <<<<<<<<<<<<<< - * elif value >= -32768 and maximum_value < 32768: - * valuetype = b's' + /* "pysam/libcalignedsegment.pyx":291 + * if min_value < 0: + * if min_value >= INT8_MIN and max_value <= INT8_MAX: + * typecode = 'c' # <<<<<<<<<<<<<< + * elif min_value >= INT16_MIN and max_value <= INT16_MAX: + * typecode = 's' */ - __Pyx_INCREF(__pyx_n_b_c); - __pyx_v_valuetype = __pyx_n_b_c; + __pyx_v_typecode = 'c'; - /* "pysam/libcalignedsegment.pyx":196 + /* "pysam/libcalignedsegment.pyx":290 * # signed ints - * if value < 0: - * if value >= -128 and maximum_value < 128: # <<<<<<<<<<<<<< - * valuetype = b'c' - * elif value >= -32768 and maximum_value < 32768: + * if min_value < 0: + * if min_value >= INT8_MIN and max_value <= INT8_MAX: # <<<<<<<<<<<<<< + * typecode = 'c' + * elif min_value >= INT16_MIN and max_value <= INT16_MAX: */ - goto __pyx_L6; + goto __pyx_L7; } - /* "pysam/libcalignedsegment.pyx":198 - * if value >= -128 and maximum_value < 128: - * valuetype = b'c' - * elif value >= -32768 and maximum_value < 32768: # <<<<<<<<<<<<<< - * valuetype = b's' - * elif value < -2147483648 or maximum_value >= 2147483648: + /* "pysam/libcalignedsegment.pyx":292 + * if min_value >= INT8_MIN and max_value <= INT8_MAX: + * typecode = 'c' + * elif min_value >= INT16_MIN and max_value <= INT16_MAX: # <<<<<<<<<<<<<< + * typecode = 's' + * elif min_value >= INT32_MIN or max_value <= INT32_MAX: */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_32768, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 198, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 198, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int16_t(INT16_MIN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_min_value, __pyx_t_3, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 292, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_1) { + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 292, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_2) { } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L9_bool_binop_done; + __pyx_t_1 = __pyx_t_2; + goto __pyx_L10_bool_binop_done; } - __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_32768, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 198, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 198, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int16_t(INT16_MAX); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_max_value, __pyx_t_4, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 292, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 292, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_2 = __pyx_t_1; - __pyx_L9_bool_binop_done:; - if (__pyx_t_2) { + __pyx_t_1 = __pyx_t_2; + __pyx_L10_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":199 - * valuetype = b'c' - * elif value >= -32768 and maximum_value < 32768: - * valuetype = b's' # <<<<<<<<<<<<<< - * elif value < -2147483648 or maximum_value >= 2147483648: - * raise ValueError( + /* "pysam/libcalignedsegment.pyx":293 + * typecode = 'c' + * elif min_value >= INT16_MIN and max_value <= INT16_MAX: + * typecode = 's' # <<<<<<<<<<<<<< + * elif min_value >= INT32_MIN or max_value <= INT32_MAX: + * typecode = 'i' */ - __Pyx_INCREF(__pyx_n_b_s); - __pyx_v_valuetype = __pyx_n_b_s; + __pyx_v_typecode = 's'; - /* "pysam/libcalignedsegment.pyx":198 - * if value >= -128 and maximum_value < 128: - * valuetype = b'c' - * elif value >= -32768 and maximum_value < 32768: # <<<<<<<<<<<<<< - * valuetype = b's' - * elif value < -2147483648 or maximum_value >= 2147483648: + /* "pysam/libcalignedsegment.pyx":292 + * if min_value >= INT8_MIN and max_value <= INT8_MAX: + * typecode = 'c' + * elif min_value >= INT16_MIN and max_value <= INT16_MAX: # <<<<<<<<<<<<<< + * typecode = 's' + * elif min_value >= INT32_MIN or max_value <= INT32_MAX: */ - goto __pyx_L6; + goto __pyx_L7; } - /* "pysam/libcalignedsegment.pyx":200 - * elif value >= -32768 and maximum_value < 32768: - * valuetype = b's' - * elif value < -2147483648 or maximum_value >= 2147483648: # <<<<<<<<<<<<<< - * raise ValueError( - * "at least one signed integer out of range of " + /* "pysam/libcalignedsegment.pyx":294 + * elif min_value >= INT16_MIN and max_value <= INT16_MAX: + * typecode = 's' + * elif min_value >= INT32_MIN or max_value <= INT32_MAX: # <<<<<<<<<<<<<< + * typecode = 'i' + * else: */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_2147483648, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 200, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 200, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int32_t(INT32_MIN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 294, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_min_value, __pyx_t_3, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 294, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!__pyx_t_1) { + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 294, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!__pyx_t_2) { } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L11_bool_binop_done; + __pyx_t_1 = __pyx_t_2; + goto __pyx_L12_bool_binop_done; } - __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_2147483648, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 200, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 200, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int32_t(INT32_MAX); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 294, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_max_value, __pyx_t_4, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 294, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 294, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_2 = __pyx_t_1; - __pyx_L11_bool_binop_done:; - if (unlikely(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; + __pyx_L12_bool_binop_done:; + if (likely(__pyx_t_1)) { - /* "pysam/libcalignedsegment.pyx":201 - * valuetype = b's' - * elif value < -2147483648 or maximum_value >= 2147483648: - * raise ValueError( # <<<<<<<<<<<<<< - * "at least one signed integer out of range of " - * "BAM/SAM specification") + /* "pysam/libcalignedsegment.pyx":295 + * typecode = 's' + * elif min_value >= INT32_MIN or max_value <= INT32_MAX: + * typecode = 'i' # <<<<<<<<<<<<<< + * else: + * raise ValueError( */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 201, __pyx_L1_error) + __pyx_v_typecode = 'i'; - /* "pysam/libcalignedsegment.pyx":200 - * elif value >= -32768 and maximum_value < 32768: - * valuetype = b's' - * elif value < -2147483648 or maximum_value >= 2147483648: # <<<<<<<<<<<<<< - * raise ValueError( - * "at least one signed integer out of range of " + /* "pysam/libcalignedsegment.pyx":294 + * elif min_value >= INT16_MIN and max_value <= INT16_MAX: + * typecode = 's' + * elif min_value >= INT32_MIN or max_value <= INT32_MAX: # <<<<<<<<<<<<<< + * typecode = 'i' + * else: */ + goto __pyx_L7; } - /* "pysam/libcalignedsegment.pyx":205 - * "BAM/SAM specification") + /* "pysam/libcalignedsegment.pyx":297 + * typecode = 'i' * else: - * valuetype = b'i' # <<<<<<<<<<<<<< - * # unsigned ints - * else: + * raise ValueError( # <<<<<<<<<<<<<< + * "at least one signed integer out of range of " + * "BAM/SAM specification") */ /*else*/ { - __Pyx_INCREF(__pyx_n_b_i); - __pyx_v_valuetype = __pyx_n_b_i; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 297, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 297, __pyx_L1_error) } - __pyx_L6:; + __pyx_L7:; - /* "pysam/libcalignedsegment.pyx":195 - * elif t is int: + /* "pysam/libcalignedsegment.pyx":289 + * min_value = value * # signed ints - * if value < 0: # <<<<<<<<<<<<<< - * if value >= -128 and maximum_value < 128: - * valuetype = b'c' + * if min_value < 0: # <<<<<<<<<<<<<< + * if min_value >= INT8_MIN and max_value <= INT8_MAX: + * typecode = 'c' */ - goto __pyx_L5; + goto __pyx_L6; } - /* "pysam/libcalignedsegment.pyx":208 + /* "pysam/libcalignedsegment.pyx":302 * # unsigned ints * else: - * if maximum_value < 256: # <<<<<<<<<<<<<< - * valuetype = b'C' - * elif maximum_value < 65536: + * if max_value <= UINT8_MAX: # <<<<<<<<<<<<<< + * typecode = 'C' + * elif max_value <= UINT16_MAX: */ /*else*/ { - __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_256, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 208, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 208, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_uint8_t(UINT8_MAX); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 302, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_max_value, __pyx_t_3, Py_LE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 302, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 302, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":209 + /* "pysam/libcalignedsegment.pyx":303 * else: - * if maximum_value < 256: - * valuetype = b'C' # <<<<<<<<<<<<<< - * elif maximum_value < 65536: - * valuetype = b'S' + * if max_value <= UINT8_MAX: + * typecode = 'C' # <<<<<<<<<<<<<< + * elif max_value <= UINT16_MAX: + * typecode = 'S' */ - __Pyx_INCREF(__pyx_n_b_C); - __pyx_v_valuetype = __pyx_n_b_C; + __pyx_v_typecode = 'C'; - /* "pysam/libcalignedsegment.pyx":208 + /* "pysam/libcalignedsegment.pyx":302 * # unsigned ints * else: - * if maximum_value < 256: # <<<<<<<<<<<<<< - * valuetype = b'C' - * elif maximum_value < 65536: + * if max_value <= UINT8_MAX: # <<<<<<<<<<<<<< + * typecode = 'C' + * elif max_value <= UINT16_MAX: */ - goto __pyx_L13; + goto __pyx_L14; } - /* "pysam/libcalignedsegment.pyx":210 - * if maximum_value < 256: - * valuetype = b'C' - * elif maximum_value < 65536: # <<<<<<<<<<<<<< - * valuetype = b'S' - * elif maximum_value >= 4294967296: + /* "pysam/libcalignedsegment.pyx":304 + * if max_value <= UINT8_MAX: + * typecode = 'C' + * elif max_value <= UINT16_MAX: # <<<<<<<<<<<<<< + * typecode = 'S' + * elif max_value <= UINT32_MAX: */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_65536, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 210, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 210, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_uint16_t(UINT16_MAX); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_max_value, __pyx_t_4, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 304, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_2) { + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":211 - * valuetype = b'C' - * elif maximum_value < 65536: - * valuetype = b'S' # <<<<<<<<<<<<<< - * elif maximum_value >= 4294967296: - * raise ValueError( + /* "pysam/libcalignedsegment.pyx":305 + * typecode = 'C' + * elif max_value <= UINT16_MAX: + * typecode = 'S' # <<<<<<<<<<<<<< + * elif max_value <= UINT32_MAX: + * typecode = 'I' */ - __Pyx_INCREF(__pyx_n_b_S); - __pyx_v_valuetype = __pyx_n_b_S; + __pyx_v_typecode = 'S'; - /* "pysam/libcalignedsegment.pyx":210 - * if maximum_value < 256: - * valuetype = b'C' - * elif maximum_value < 65536: # <<<<<<<<<<<<<< - * valuetype = b'S' - * elif maximum_value >= 4294967296: + /* "pysam/libcalignedsegment.pyx":304 + * if max_value <= UINT8_MAX: + * typecode = 'C' + * elif max_value <= UINT16_MAX: # <<<<<<<<<<<<<< + * typecode = 'S' + * elif max_value <= UINT32_MAX: */ - goto __pyx_L13; + goto __pyx_L14; } - /* "pysam/libcalignedsegment.pyx":212 - * elif maximum_value < 65536: - * valuetype = b'S' - * elif maximum_value >= 4294967296: # <<<<<<<<<<<<<< - * raise ValueError( - * "at least one integer out of range of BAM/SAM specification") + /* "pysam/libcalignedsegment.pyx":306 + * elif max_value <= UINT16_MAX: + * typecode = 'S' + * elif max_value <= UINT32_MAX: # <<<<<<<<<<<<<< + * typecode = 'I' + * else: */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_4294967296, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 212, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 212, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(UINT32_MAX); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 306, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_max_value, __pyx_t_3, Py_LE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 306, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(__pyx_t_2)) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 306, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (likely(__pyx_t_1)) { - /* "pysam/libcalignedsegment.pyx":213 - * valuetype = b'S' - * elif maximum_value >= 4294967296: - * raise ValueError( # <<<<<<<<<<<<<< - * "at least one integer out of range of BAM/SAM specification") + /* "pysam/libcalignedsegment.pyx":307 + * typecode = 'S' + * elif max_value <= UINT32_MAX: + * typecode = 'I' # <<<<<<<<<<<<<< * else: + * raise ValueError( */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 213, __pyx_L1_error) + __pyx_v_typecode = 'I'; - /* "pysam/libcalignedsegment.pyx":212 - * elif maximum_value < 65536: - * valuetype = b'S' - * elif maximum_value >= 4294967296: # <<<<<<<<<<<<<< - * raise ValueError( - * "at least one integer out of range of BAM/SAM specification") + /* "pysam/libcalignedsegment.pyx":306 + * elif max_value <= UINT16_MAX: + * typecode = 'S' + * elif max_value <= UINT32_MAX: # <<<<<<<<<<<<<< + * typecode = 'I' + * else: */ + goto __pyx_L14; } - /* "pysam/libcalignedsegment.pyx":216 - * "at least one integer out of range of BAM/SAM specification") + /* "pysam/libcalignedsegment.pyx":309 + * typecode = 'I' * else: - * valuetype = b'I' # <<<<<<<<<<<<<< + * raise ValueError( # <<<<<<<<<<<<<< + * "at least one integer out of range of BAM/SAM specification") * else: - * # Note: hex strings (H) are not supported yet */ /*else*/ { - __Pyx_INCREF(__pyx_n_b_I); - __pyx_v_valuetype = __pyx_n_b_I; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 309, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 309, __pyx_L1_error) } - __pyx_L13:; + __pyx_L14:; } - __pyx_L5:; + __pyx_L6:; - /* "pysam/libcalignedsegment.pyx":193 + /* "pysam/libcalignedsegment.pyx":283 * if t is float: - * valuetype = b'f' + * typecode = 'f' * elif t is int: # <<<<<<<<<<<<<< - * # signed ints - * if value < 0: + * if max_value is None: + * max_value = value */ - goto __pyx_L4; + goto __pyx_L3; } - /* "pysam/libcalignedsegment.pyx":219 + /* "pysam/libcalignedsegment.pyx":313 * else: * # Note: hex strings (H) are not supported yet * if t is not bytes: # <<<<<<<<<<<<<< @@ -5554,26 +6847,26 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getTypecode(P * if len(value) == 1: */ /*else*/ { - __pyx_t_2 = (__pyx_v_t != (&PyBytes_Type)); - __pyx_t_1 = (__pyx_t_2 != 0); - if (__pyx_t_1) { + __pyx_t_1 = (__pyx_v_t != (&PyBytes_Type)); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":220 + /* "pysam/libcalignedsegment.pyx":314 * # Note: hex strings (H) are not supported yet * if t is not bytes: * value = value.encode('ascii') # <<<<<<<<<<<<<< * if len(value) == 1: - * valuetype = b'A' + * typecode = 'A' */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 220, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 220, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 314, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_4); - __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":219 + /* "pysam/libcalignedsegment.pyx":313 * else: * # Note: hex strings (H) are not supported yet * if t is not bytes: # <<<<<<<<<<<<<< @@ -5582,68 +6875,64 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getTypecode(P */ } - /* "pysam/libcalignedsegment.pyx":221 + /* "pysam/libcalignedsegment.pyx":315 * if t is not bytes: * value = value.encode('ascii') * if len(value) == 1: # <<<<<<<<<<<<<< - * valuetype = b'A' + * typecode = 'A' * else: */ - __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 221, __pyx_L1_error) - __pyx_t_1 = ((__pyx_t_5 == 1) != 0); - if (__pyx_t_1) { + __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 315, __pyx_L1_error) + __pyx_t_2 = ((__pyx_t_5 == 1) != 0); + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":222 + /* "pysam/libcalignedsegment.pyx":316 * value = value.encode('ascii') * if len(value) == 1: - * valuetype = b'A' # <<<<<<<<<<<<<< + * typecode = 'A' # <<<<<<<<<<<<<< * else: - * valuetype = b'Z' + * typecode = 'Z' */ - __Pyx_INCREF(__pyx_n_b_A); - __pyx_v_valuetype = __pyx_n_b_A; + __pyx_v_typecode = 'A'; - /* "pysam/libcalignedsegment.pyx":221 + /* "pysam/libcalignedsegment.pyx":315 * if t is not bytes: * value = value.encode('ascii') * if len(value) == 1: # <<<<<<<<<<<<<< - * valuetype = b'A' + * typecode = 'A' * else: */ - goto __pyx_L15; + goto __pyx_L16; } - /* "pysam/libcalignedsegment.pyx":224 - * valuetype = b'A' + /* "pysam/libcalignedsegment.pyx":318 + * typecode = 'A' * else: - * valuetype = b'Z' # <<<<<<<<<<<<<< + * typecode = 'Z' # <<<<<<<<<<<<<< * - * return valuetype + * return typecode */ /*else*/ { - __Pyx_INCREF(__pyx_n_b_Z); - __pyx_v_valuetype = __pyx_n_b_Z; + __pyx_v_typecode = 'Z'; } - __pyx_L15:; + __pyx_L16:; } - __pyx_L4:; + __pyx_L3:; - /* "pysam/libcalignedsegment.pyx":226 - * valuetype = b'Z' + /* "pysam/libcalignedsegment.pyx":320 + * typecode = 'Z' * - * return valuetype # <<<<<<<<<<<<<< + * return typecode # <<<<<<<<<<<<<< * * */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_valuetype); - __pyx_r = __pyx_v_valuetype; + __pyx_r = __pyx_v_typecode; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":177 + /* "pysam/libcalignedsegment.pyx":265 * * - * cdef inline bytes getTypecode(value, maximum_value=None): # <<<<<<<<<<<<<< + * cdef inline uint8_t get_btag_typecode(value, min_value=None, max_value=None): # <<<<<<<<<<<<<< * '''returns the value typecode of a value. * */ @@ -5652,37 +6941,35 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getTypecode(P __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcalignedsegment.getTypecode", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_WriteUnraisable("pysam.libcalignedsegment.get_btag_typecode", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_r = 0; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_valuetype); __Pyx_XDECREF(__pyx_v_t); __Pyx_XDECREF(__pyx_v_value); - __Pyx_XDECREF(__pyx_v_maximum_value); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_XDECREF(__pyx_v_min_value); + __Pyx_XDECREF(__pyx_v_max_value); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":229 +/* "pysam/libcalignedsegment.pyx":337 * * - * cdef inline packTags(tags): # <<<<<<<<<<<<<< + * cdef inline pack_tags(tags): # <<<<<<<<<<<<<< * """pack a list of tags. Each tag is a tuple of (tag, tuple). * */ -static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyObject *__pyx_v_tags) { +static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_pack_tags(PyObject *__pyx_v_tags) { PyObject *__pyx_v_fmts = NULL; PyObject *__pyx_v_args = NULL; - char __pyx_v_array_typecode; - PyObject *__pyx_v_datatype2format = NULL; + uint8_t __pyx_v_typecode; PyObject *__pyx_v_tag = NULL; PyObject *__pyx_v_pytag = NULL; PyObject *__pyx_v_value = NULL; PyObject *__pyx_v_valuetype = NULL; - PyTypeObject *__pyx_v_t = NULL; + PyTypeObject *__pyx_v_pytype = NULL; PyObject *__pyx_v_datafmt = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations @@ -5698,116 +6985,43 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb PyObject *(*__pyx_t_9)(PyObject *); PyObject *__pyx_t_10 = NULL; int __pyx_t_11; - int __pyx_t_12; - struct __pyx_opt_args_5pysam_18libcalignedsegment_getTypecode __pyx_t_13; + uint8_t __pyx_t_12; + long __pyx_t_13; int __pyx_t_14; - long __pyx_t_15; + struct __pyx_opt_args_5pysam_18libcalignedsegment_get_btag_typecode __pyx_t_15; PyObject *__pyx_t_16 = NULL; int __pyx_t_17; int __pyx_t_18; - int __pyx_t_19; + PyObject *__pyx_t_19 = NULL; int __pyx_t_20; - __Pyx_RefNannySetupContext("packTags", 0); - __Pyx_TraceCall("packTags", __pyx_f[0], 229, 0, __PYX_ERR(0, 229, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":238 - * to be used in a call to struct.pack_into. + int __pyx_t_21; + int __pyx_t_22; + int __pyx_t_23; + __Pyx_RefNannySetupContext("pack_tags", 0); + __Pyx_TraceCall("pack_tags", __pyx_f[0], 337, 0, __PYX_ERR(0, 337, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":346 + * used in a call to struct.pack_into. * """ * fmts, args = ["<"], [] # <<<<<<<<<<<<<< * - * cdef char array_typecode + * # htslib typecode */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 238, __pyx_L1_error) + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 346, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_kp_s__4); __Pyx_GIVEREF(__pyx_kp_s__4); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_s__4); - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 238, __pyx_L1_error) + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_fmts = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_args = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignedsegment.pyx":243 - * - * datatype2format = { - * b'c': ('b', 1), # <<<<<<<<<<<<<< - * b'C': ('B', 1), - * b's': ('h', 2), - */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 243, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_c, __pyx_tuple__5) < 0) __PYX_ERR(0, 243, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":244 - * datatype2format = { - * b'c': ('b', 1), - * b'C': ('B', 1), # <<<<<<<<<<<<<< - * b's': ('h', 2), - * b'S': ('H', 2), - */ - if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_C, __pyx_tuple__6) < 0) __PYX_ERR(0, 243, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":245 - * b'c': ('b', 1), - * b'C': ('B', 1), - * b's': ('h', 2), # <<<<<<<<<<<<<< - * b'S': ('H', 2), - * b'i': ('i', 4), - */ - if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_s, __pyx_tuple__7) < 0) __PYX_ERR(0, 243, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":246 - * b'C': ('B', 1), - * b's': ('h', 2), - * b'S': ('H', 2), # <<<<<<<<<<<<<< - * b'i': ('i', 4), - * b'I': ('I', 4), - */ - if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_S, __pyx_tuple__8) < 0) __PYX_ERR(0, 243, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":247 - * b's': ('h', 2), - * b'S': ('H', 2), - * b'i': ('i', 4), # <<<<<<<<<<<<<< - * b'I': ('I', 4), - * b'f': ('f', 4), - */ - if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_i, __pyx_tuple__9) < 0) __PYX_ERR(0, 243, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":248 - * b'S': ('H', 2), - * b'i': ('i', 4), - * b'I': ('I', 4), # <<<<<<<<<<<<<< - * b'f': ('f', 4), - * b'A': ('c', 1)} - */ - if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_I, __pyx_tuple__10) < 0) __PYX_ERR(0, 243, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":249 - * b'i': ('i', 4), - * b'I': ('I', 4), - * b'f': ('f', 4), # <<<<<<<<<<<<<< - * b'A': ('c', 1)} - * - */ - if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_f, __pyx_tuple__11) < 0) __PYX_ERR(0, 243, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":250 - * b'I': ('I', 4), - * b'f': ('f', 4), - * b'A': ('c', 1)} # <<<<<<<<<<<<<< - * - * for tag in tags: - */ - if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_A, __pyx_tuple__12) < 0) __PYX_ERR(0, 243, __pyx_L1_error) - __pyx_v_datatype2format = ((PyObject*)__pyx_t_2); - __pyx_t_2 = 0; - - /* "pysam/libcalignedsegment.pyx":252 - * b'A': ('c', 1)} - * + /* "pysam/libcalignedsegment.pyx":350 + * # htslib typecode + * cdef uint8_t typecode * for tag in tags: # <<<<<<<<<<<<<< * * if len(tag) == 2: @@ -5816,26 +7030,26 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb __pyx_t_2 = __pyx_v_tags; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; __pyx_t_4 = NULL; } else { - __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_tags); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 252, __pyx_L1_error) + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_tags); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 350, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 252, __pyx_L1_error) + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 350, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_4)) { if (likely(PyList_CheckExact(__pyx_t_2))) { if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 252, __pyx_L1_error) + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 350, __pyx_L1_error) #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 252, __pyx_L1_error) + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 350, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif } else { if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 252, __pyx_L1_error) + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 350, __pyx_L1_error) #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 252, __pyx_L1_error) + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 350, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif } @@ -5845,7 +7059,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 252, __pyx_L1_error) + else __PYX_ERR(0, 350, __pyx_L1_error) } break; } @@ -5854,18 +7068,18 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb __Pyx_XDECREF_SET(__pyx_v_tag, __pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":254 + /* "pysam/libcalignedsegment.pyx":352 * for tag in tags: * * if len(tag) == 2: # <<<<<<<<<<<<<< * pytag, value = tag * valuetype = None */ - __pyx_t_5 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 254, __pyx_L1_error) + __pyx_t_5 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 352, __pyx_L1_error) __pyx_t_6 = ((__pyx_t_5 == 2) != 0); if (__pyx_t_6) { - /* "pysam/libcalignedsegment.pyx":255 + /* "pysam/libcalignedsegment.pyx":353 * * if len(tag) == 2: * pytag, value = tag # <<<<<<<<<<<<<< @@ -5878,7 +7092,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 255, __pyx_L1_error) + __PYX_ERR(0, 353, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { @@ -5891,21 +7105,21 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx_t_7); #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 255, __pyx_L1_error) + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 353, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 255, __pyx_L1_error) + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 353, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); #endif } else { Py_ssize_t index = -1; - __pyx_t_8 = PyObject_GetIter(__pyx_v_tag); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 255, __pyx_L1_error) + __pyx_t_8 = PyObject_GetIter(__pyx_v_tag); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 353, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_1)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_1); index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) __PYX_ERR(0, 255, __pyx_L1_error) + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) __PYX_ERR(0, 353, __pyx_L1_error) __pyx_t_9 = NULL; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; goto __pyx_L7_unpacking_done; @@ -5913,7 +7127,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_9 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 255, __pyx_L1_error) + __PYX_ERR(0, 353, __pyx_L1_error) __pyx_L7_unpacking_done:; } __Pyx_XDECREF_SET(__pyx_v_pytag, __pyx_t_1); @@ -5921,7 +7135,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcalignedsegment.pyx":256 + /* "pysam/libcalignedsegment.pyx":354 * if len(tag) == 2: * pytag, value = tag * valuetype = None # <<<<<<<<<<<<<< @@ -5931,7 +7145,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb __Pyx_INCREF(Py_None); __Pyx_XDECREF_SET(__pyx_v_valuetype, Py_None); - /* "pysam/libcalignedsegment.pyx":254 + /* "pysam/libcalignedsegment.pyx":352 * for tag in tags: * * if len(tag) == 2: # <<<<<<<<<<<<<< @@ -5941,18 +7155,18 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb goto __pyx_L5; } - /* "pysam/libcalignedsegment.pyx":257 + /* "pysam/libcalignedsegment.pyx":355 * pytag, value = tag * valuetype = None * elif len(tag) == 3: # <<<<<<<<<<<<<< * pytag, value, valuetype = tag * else: */ - __pyx_t_5 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 257, __pyx_L1_error) + __pyx_t_5 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 355, __pyx_L1_error) __pyx_t_6 = ((__pyx_t_5 == 3) != 0); if (likely(__pyx_t_6)) { - /* "pysam/libcalignedsegment.pyx":258 + /* "pysam/libcalignedsegment.pyx":356 * valuetype = None * elif len(tag) == 3: * pytag, value, valuetype = tag # <<<<<<<<<<<<<< @@ -5965,7 +7179,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb if (unlikely(size != 3)) { if (size > 3) __Pyx_RaiseTooManyValuesError(3); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 258, __pyx_L1_error) + __PYX_ERR(0, 356, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { @@ -5981,16 +7195,16 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx_t_8); #else - __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 356, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 356, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_8 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 356, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); #endif } else { Py_ssize_t index = -1; - __pyx_t_10 = PyObject_GetIter(__pyx_v_tag); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_10 = PyObject_GetIter(__pyx_v_tag); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 356, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_9 = Py_TYPE(__pyx_t_10)->tp_iternext; index = 0; __pyx_t_7 = __pyx_t_9(__pyx_t_10); if (unlikely(!__pyx_t_7)) goto __pyx_L8_unpacking_failed; @@ -5999,7 +7213,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb __Pyx_GOTREF(__pyx_t_1); index = 2; __pyx_t_8 = __pyx_t_9(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_8); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_10), 3) < 0) __PYX_ERR(0, 258, __pyx_L1_error) + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_10), 3) < 0) __PYX_ERR(0, 356, __pyx_L1_error) __pyx_t_9 = NULL; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; goto __pyx_L9_unpacking_done; @@ -6007,7 +7221,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_9 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 258, __pyx_L1_error) + __PYX_ERR(0, 356, __pyx_L1_error) __pyx_L9_unpacking_done:; } __Pyx_XDECREF_SET(__pyx_v_pytag, __pyx_t_7); @@ -6017,7 +7231,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb __Pyx_XDECREF_SET(__pyx_v_valuetype, __pyx_t_8); __pyx_t_8 = 0; - /* "pysam/libcalignedsegment.pyx":257 + /* "pysam/libcalignedsegment.pyx":355 * pytag, value = tag * valuetype = None * elif len(tag) == 3: # <<<<<<<<<<<<<< @@ -6027,755 +7241,1086 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb goto __pyx_L5; } - /* "pysam/libcalignedsegment.pyx":260 + /* "pysam/libcalignedsegment.pyx":358 * pytag, value, valuetype = tag * else: * raise ValueError("malformatted tag: %s" % str(tag)) # <<<<<<<<<<<<<< * - * pytag = force_bytes(pytag) + * if valuetype is None: */ /*else*/ { - __pyx_t_8 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_tag); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 260, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_tag); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 358, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_malformatted_tag_s, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 260, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_malformatted_tag_s, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 358, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 260, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 358, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_8, 0, 0, 0); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 260, __pyx_L1_error) + __PYX_ERR(0, 358, __pyx_L1_error) } __pyx_L5:; - /* "pysam/libcalignedsegment.pyx":262 + /* "pysam/libcalignedsegment.pyx":360 * raise ValueError("malformatted tag: %s" % str(tag)) * - * pytag = force_bytes(pytag) # <<<<<<<<<<<<<< - * valuetype = force_bytes(valuetype) - * t = type(value) + * if valuetype is None: # <<<<<<<<<<<<<< + * typecode = 0 + * else: */ - __pyx_t_8 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_pytag, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 262, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF_SET(__pyx_v_pytag, __pyx_t_8); - __pyx_t_8 = 0; + __pyx_t_6 = (__pyx_v_valuetype == Py_None); + __pyx_t_11 = (__pyx_t_6 != 0); + if (__pyx_t_11) { - /* "pysam/libcalignedsegment.pyx":263 + /* "pysam/libcalignedsegment.pyx":361 + * + * if valuetype is None: + * typecode = 0 # <<<<<<<<<<<<<< + * else: + * # only first character in valuecode matters + */ + __pyx_v_typecode = 0; + + /* "pysam/libcalignedsegment.pyx":360 + * raise ValueError("malformatted tag: %s" % str(tag)) + * + * if valuetype is None: # <<<<<<<<<<<<<< + * typecode = 0 + * else: + */ + goto __pyx_L10; + } + + /* "pysam/libcalignedsegment.pyx":364 + * else: + * # only first character in valuecode matters + * if IS_PYTHON3: # <<<<<<<<<<<<<< + * typecode = force_bytes(valuetype)[0] + * else: + */ + /*else*/ { + __pyx_t_11 = (__pyx_v_5pysam_18libcalignedsegment_IS_PYTHON3 != 0); + if (__pyx_t_11) { + + /* "pysam/libcalignedsegment.pyx":365 + * # only first character in valuecode matters + * if IS_PYTHON3: + * typecode = force_bytes(valuetype)[0] # <<<<<<<<<<<<<< + * else: + * typecode = ord(valuetype[0]) + */ + __pyx_t_8 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_valuetype, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 365, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_8, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 365, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_12 = __Pyx_PyInt_As_uint8_t(__pyx_t_1); if (unlikely((__pyx_t_12 == ((uint8_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 365, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_typecode = __pyx_t_12; + + /* "pysam/libcalignedsegment.pyx":364 + * else: + * # only first character in valuecode matters + * if IS_PYTHON3: # <<<<<<<<<<<<<< + * typecode = force_bytes(valuetype)[0] + * else: + */ + goto __pyx_L11; + } + + /* "pysam/libcalignedsegment.pyx":367 + * typecode = force_bytes(valuetype)[0] + * else: + * typecode = ord(valuetype[0]) # <<<<<<<<<<<<<< * * pytag = force_bytes(pytag) - * valuetype = force_bytes(valuetype) # <<<<<<<<<<<<<< - * t = type(value) + */ + /*else*/ { + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_valuetype, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_13 = __Pyx_PyObject_Ord(__pyx_t_1); if (unlikely(__pyx_t_13 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_typecode = __pyx_t_13; + } + __pyx_L11:; + } + __pyx_L10:; + + /* "pysam/libcalignedsegment.pyx":369 + * typecode = ord(valuetype[0]) + * + * pytag = force_bytes(pytag) # <<<<<<<<<<<<<< + * pytype = type(value) * */ - __pyx_t_8 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_valuetype, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 263, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF_SET(__pyx_v_valuetype, __pyx_t_8); - __pyx_t_8 = 0; + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_pytag, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 369, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF_SET(__pyx_v_pytag, __pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":264 + /* "pysam/libcalignedsegment.pyx":370 + * * pytag = force_bytes(pytag) - * valuetype = force_bytes(valuetype) - * t = type(value) # <<<<<<<<<<<<<< + * pytype = type(value) # <<<<<<<<<<<<<< * - * if t is tuple or t is list: + * if pytype is tuple or pytype is list: */ __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value))); - __Pyx_XDECREF_SET(__pyx_v_t, ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_v_value)))); + __Pyx_XDECREF_SET(__pyx_v_pytype, ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_v_value)))); - /* "pysam/libcalignedsegment.pyx":266 - * t = type(value) + /* "pysam/libcalignedsegment.pyx":372 + * pytype = type(value) * - * if t is tuple or t is list: # <<<<<<<<<<<<<< + * if pytype is tuple or pytype is list: # <<<<<<<<<<<<<< * # binary tags from tuples or lists - * if valuetype is None: + * if not typecode: */ - __pyx_t_11 = (__pyx_v_t == (&PyTuple_Type)); - __pyx_t_12 = (__pyx_t_11 != 0); - if (!__pyx_t_12) { + __pyx_t_6 = (__pyx_v_pytype == (&PyTuple_Type)); + __pyx_t_14 = (__pyx_t_6 != 0); + if (!__pyx_t_14) { } else { - __pyx_t_6 = __pyx_t_12; - goto __pyx_L11_bool_binop_done; + __pyx_t_11 = __pyx_t_14; + goto __pyx_L13_bool_binop_done; } - __pyx_t_12 = (__pyx_v_t == (&PyList_Type)); - __pyx_t_11 = (__pyx_t_12 != 0); - __pyx_t_6 = __pyx_t_11; - __pyx_L11_bool_binop_done:; - if (__pyx_t_6) { + __pyx_t_14 = (__pyx_v_pytype == (&PyList_Type)); + __pyx_t_6 = (__pyx_t_14 != 0); + __pyx_t_11 = __pyx_t_6; + __pyx_L13_bool_binop_done:; + if (__pyx_t_11) { - /* "pysam/libcalignedsegment.pyx":268 - * if t is tuple or t is list: + /* "pysam/libcalignedsegment.pyx":374 + * if pytype is tuple or pytype is list: * # binary tags from tuples or lists - * if valuetype is None: # <<<<<<<<<<<<<< + * if not typecode: # <<<<<<<<<<<<<< * # automatically determine value type - first value * # determines type. If there is a mix of types, the */ - __pyx_t_6 = (__pyx_v_valuetype == Py_None); - __pyx_t_11 = (__pyx_t_6 != 0); + __pyx_t_11 = ((!(__pyx_v_typecode != 0)) != 0); if (__pyx_t_11) { - /* "pysam/libcalignedsegment.pyx":272 + /* "pysam/libcalignedsegment.pyx":378 * # determines type. If there is a mix of types, the * # result is undefined. - * valuetype = getTypecode(min(value), max(value)) # <<<<<<<<<<<<<< + * typecode = get_btag_typecode(min(value), # <<<<<<<<<<<<<< + * min_value=min(value), + * max_value=max(value)) + */ + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_min, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 378, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pysam/libcalignedsegment.pyx":379 + * # result is undefined. + * typecode = get_btag_typecode(min(value), + * min_value=min(value), # <<<<<<<<<<<<<< + * max_value=max(value)) * - * if valuetype not in datatype2format: */ - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_min, __pyx_v_value); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 272, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_min, __pyx_v_value); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_max, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 272, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_13.__pyx_n = 1; - __pyx_t_13.maximum_value = __pyx_t_1; - __pyx_t_7 = __pyx_f_5pysam_18libcalignedsegment_getTypecode(__pyx_t_8, &__pyx_t_13); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 272, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":380 + * typecode = get_btag_typecode(min(value), + * min_value=min(value), + * max_value=max(value)) # <<<<<<<<<<<<<< + * + * if typecode not in DATATYPE2FORMAT: + */ + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_max, __pyx_v_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 380, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pysam/libcalignedsegment.pyx":378 + * # determines type. If there is a mix of types, the + * # result is undefined. + * typecode = get_btag_typecode(min(value), # <<<<<<<<<<<<<< + * min_value=min(value), + * max_value=max(value)) + */ + __pyx_t_15.__pyx_n = 2; + __pyx_t_15.min_value = __pyx_t_8; + __pyx_t_15.max_value = __pyx_t_7; + __pyx_t_12 = __pyx_f_5pysam_18libcalignedsegment_get_btag_typecode(__pyx_t_1, &__pyx_t_15); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_valuetype, __pyx_t_7); - __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_typecode = __pyx_t_12; - /* "pysam/libcalignedsegment.pyx":268 - * if t is tuple or t is list: + /* "pysam/libcalignedsegment.pyx":374 + * if pytype is tuple or pytype is list: * # binary tags from tuples or lists - * if valuetype is None: # <<<<<<<<<<<<<< + * if not typecode: # <<<<<<<<<<<<<< * # automatically determine value type - first value * # determines type. If there is a mix of types, the */ } - /* "pysam/libcalignedsegment.pyx":274 - * valuetype = getTypecode(min(value), max(value)) + /* "pysam/libcalignedsegment.pyx":382 + * max_value=max(value)) * - * if valuetype not in datatype2format: # <<<<<<<<<<<<<< - * raise ValueError("invalid value type '%s'" % valuetype) + * if typecode not in DATATYPE2FORMAT: # <<<<<<<<<<<<<< + * raise ValueError("invalid value type '{}'".format(chr(typecode))) * */ - __pyx_t_11 = (__Pyx_PyDict_ContainsTF(__pyx_v_valuetype, __pyx_v_datatype2format, Py_NE)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 274, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyInt_From_uint8_t(__pyx_v_typecode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 382, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_DATATYPE2FORMAT); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 382, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_11 = (__Pyx_PySequence_ContainsTF(__pyx_t_7, __pyx_t_8, Py_NE)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 382, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_6 = (__pyx_t_11 != 0); if (unlikely(__pyx_t_6)) { - /* "pysam/libcalignedsegment.pyx":275 + /* "pysam/libcalignedsegment.pyx":383 * - * if valuetype not in datatype2format: - * raise ValueError("invalid value type '%s'" % valuetype) # <<<<<<<<<<<<<< + * if typecode not in DATATYPE2FORMAT: + * raise ValueError("invalid value type '{}'".format(chr(typecode))) # <<<<<<<<<<<<<< * - * datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0]) + * datafmt = "2sBBI%i%s" % (len(value), DATATYPE2FORMAT[typecode][0]) */ - __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_invalid_value_type_s, __pyx_v_valuetype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 275, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_value_type, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 383, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 275, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_uint8_t(__pyx_v_typecode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 383, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 383, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 275, __pyx_L1_error) + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_1) { + __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 383, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_10}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 383, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_10}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 383, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else + #endif + { + __pyx_t_16 = PyTuple_New(1+1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 383, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_1); __pyx_t_1 = NULL; + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_16, 0+1, __pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_16, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 383, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 383, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 383, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":274 - * valuetype = getTypecode(min(value), max(value)) + /* "pysam/libcalignedsegment.pyx":382 + * max_value=max(value)) * - * if valuetype not in datatype2format: # <<<<<<<<<<<<<< - * raise ValueError("invalid value type '%s'" % valuetype) + * if typecode not in DATATYPE2FORMAT: # <<<<<<<<<<<<<< + * raise ValueError("invalid value type '{}'".format(chr(typecode))) * */ } - /* "pysam/libcalignedsegment.pyx":277 - * raise ValueError("invalid value type '%s'" % valuetype) + /* "pysam/libcalignedsegment.pyx":385 + * raise ValueError("invalid value type '{}'".format(chr(typecode))) * - * datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0]) # <<<<<<<<<<<<<< + * datafmt = "2sBBI%i%s" % (len(value), DATATYPE2FORMAT[typecode][0]) # <<<<<<<<<<<<<< * args.extend([pytag[:2], - * b"B", + * ord("B"), */ - __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 277, __pyx_L1_error) - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 277, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_datatype2format, __pyx_v_valuetype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 277, __pyx_L1_error) + __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 385, __pyx_L1_error) + __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 277, __pyx_L1_error) + __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_DATATYPE2FORMAT); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 277, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1); + __pyx_t_16 = __Pyx_GetItemInt(__pyx_t_8, __pyx_v_typecode, uint8_t, 0, __Pyx_PyInt_From_uint8_t, 0, 0, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 385, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_16, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 385, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 385, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_7); __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8); - __pyx_t_1 = 0; + PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_8); + __pyx_t_7 = 0; __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_2sccI_i_s, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 277, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_2sBBI_i_s, __pyx_t_16); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; __Pyx_XDECREF_SET(__pyx_v_datafmt, __pyx_t_8); __pyx_t_8 = 0; - /* "pysam/libcalignedsegment.pyx":278 + /* "pysam/libcalignedsegment.pyx":386 * - * datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0]) + * datafmt = "2sBBI%i%s" % (len(value), DATATYPE2FORMAT[typecode][0]) * args.extend([pytag[:2], # <<<<<<<<<<<<<< - * b"B", - * valuetype, + * ord("B"), + * typecode, */ - __pyx_t_8 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__13, 0, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 278, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__5, 0, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 386, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); - /* "pysam/libcalignedsegment.pyx":281 - * b"B", - * valuetype, + /* "pysam/libcalignedsegment.pyx":388 + * args.extend([pytag[:2], + * ord("B"), + * typecode, # <<<<<<<<<<<<<< + * len(value)] + list(value)) + * + */ + __pyx_t_16 = __Pyx_PyInt_From_uint8_t(__pyx_v_typecode); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 388, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + + /* "pysam/libcalignedsegment.pyx":389 + * ord("B"), + * typecode, * len(value)] + list(value)) # <<<<<<<<<<<<<< * * elif isinstance(value, array.array): */ - __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 281, __pyx_L1_error) - __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 281, __pyx_L1_error) + __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 389, __pyx_L1_error) + __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 389, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcalignedsegment.pyx":278 + /* "pysam/libcalignedsegment.pyx":386 * - * datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0]) + * datafmt = "2sBBI%i%s" % (len(value), DATATYPE2FORMAT[typecode][0]) * args.extend([pytag[:2], # <<<<<<<<<<<<<< - * b"B", - * valuetype, + * ord("B"), + * typecode, */ - __pyx_t_1 = PyList_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 278, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyList_New(4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_8); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_8); - __Pyx_INCREF(__pyx_n_b_B); - __Pyx_GIVEREF(__pyx_n_b_B); - PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_b_B); - __Pyx_INCREF(__pyx_v_valuetype); - __Pyx_GIVEREF(__pyx_v_valuetype); - PyList_SET_ITEM(__pyx_t_1, 2, __pyx_v_valuetype); + PyList_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); + __Pyx_INCREF(__pyx_int_66); + __Pyx_GIVEREF(__pyx_int_66); + PyList_SET_ITEM(__pyx_t_10, 1, __pyx_int_66); + __Pyx_GIVEREF(__pyx_t_16); + PyList_SET_ITEM(__pyx_t_10, 2, __pyx_t_16); __Pyx_GIVEREF(__pyx_t_7); - PyList_SET_ITEM(__pyx_t_1, 3, __pyx_t_7); + PyList_SET_ITEM(__pyx_t_10, 3, __pyx_t_7); __pyx_t_8 = 0; + __pyx_t_16 = 0; __pyx_t_7 = 0; - /* "pysam/libcalignedsegment.pyx":281 - * b"B", - * valuetype, + /* "pysam/libcalignedsegment.pyx":389 + * ord("B"), + * typecode, * len(value)] + list(value)) # <<<<<<<<<<<<<< * * elif isinstance(value, array.array): */ - __pyx_t_7 = PySequence_List(__pyx_v_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 281, __pyx_L1_error) + __pyx_t_7 = PySequence_List(__pyx_v_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 389, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyNumber_Add(__pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 281, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_16 = PyNumber_Add(__pyx_t_10, __pyx_t_7); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 389, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcalignedsegment.pyx":278 + /* "pysam/libcalignedsegment.pyx":386 * - * datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0]) + * datafmt = "2sBBI%i%s" % (len(value), DATATYPE2FORMAT[typecode][0]) * args.extend([pytag[:2], # <<<<<<<<<<<<<< - * b"B", - * valuetype, + * ord("B"), + * typecode, */ - __pyx_t_14 = __Pyx_PyList_Extend(__pyx_v_args, __pyx_t_8); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 278, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_17 = __Pyx_PyList_Extend(__pyx_v_args, __pyx_t_16); if (unlikely(__pyx_t_17 == ((int)-1))) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - /* "pysam/libcalignedsegment.pyx":266 - * t = type(value) + /* "pysam/libcalignedsegment.pyx":372 + * pytype = type(value) * - * if t is tuple or t is list: # <<<<<<<<<<<<<< + * if pytype is tuple or pytype is list: # <<<<<<<<<<<<<< * # binary tags from tuples or lists - * if valuetype is None: + * if not typecode: */ - goto __pyx_L10; + goto __pyx_L12; } - /* "pysam/libcalignedsegment.pyx":283 + /* "pysam/libcalignedsegment.pyx":391 * len(value)] + list(value)) * * elif isinstance(value, array.array): # <<<<<<<<<<<<<< * # binary tags from arrays - * if valuetype is None: + * if typecode == 0: */ - __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 283, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_array); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 283, __pyx_L1_error) + __pyx_t_16 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 391, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_array); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 391, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_6 = PyObject_IsInstance(__pyx_v_value, __pyx_t_7); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 283, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_6 = PyObject_IsInstance(__pyx_v_value, __pyx_t_7); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 391, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_11 = (__pyx_t_6 != 0); if (__pyx_t_11) { - /* "pysam/libcalignedsegment.pyx":285 + /* "pysam/libcalignedsegment.pyx":393 * elif isinstance(value, array.array): * # binary tags from arrays - * if valuetype is None: # <<<<<<<<<<<<<< - * array_typecode = map_typecode_python_to_htslib(ord(value.typecode)) + * if typecode == 0: # <<<<<<<<<<<<<< + * typecode = map_typecode_python_to_htslib(ord(value.typecode)) * */ - __pyx_t_11 = (__pyx_v_valuetype == Py_None); - __pyx_t_6 = (__pyx_t_11 != 0); - if (__pyx_t_6) { + __pyx_t_11 = ((__pyx_v_typecode == 0) != 0); + if (__pyx_t_11) { - /* "pysam/libcalignedsegment.pyx":286 + /* "pysam/libcalignedsegment.pyx":394 * # binary tags from arrays - * if valuetype is None: - * array_typecode = map_typecode_python_to_htslib(ord(value.typecode)) # <<<<<<<<<<<<<< + * if typecode == 0: + * typecode = map_typecode_python_to_htslib(ord(value.typecode)) # <<<<<<<<<<<<<< * - * if array_typecode == 0: + * if typecode == 0: */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_typecode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 286, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_typecode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 394, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_15 = __Pyx_PyObject_Ord(__pyx_t_7); if (unlikely(__pyx_t_15 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 286, __pyx_L1_error) + __pyx_t_13 = __Pyx_PyObject_Ord(__pyx_t_7); if (unlikely(__pyx_t_13 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 394, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_array_typecode = __pyx_f_5pysam_18libcalignedsegment_map_typecode_python_to_htslib(__pyx_t_15); + __pyx_v_typecode = __pyx_f_5pysam_18libcalignedsegment_map_typecode_python_to_htslib(__pyx_t_13); - /* "pysam/libcalignedsegment.pyx":288 - * array_typecode = map_typecode_python_to_htslib(ord(value.typecode)) + /* "pysam/libcalignedsegment.pyx":396 + * typecode = map_typecode_python_to_htslib(ord(value.typecode)) + * + * if typecode == 0: # <<<<<<<<<<<<<< + * raise ValueError("unsupported type code '{}'".format(value.typecode)) * - * if array_typecode == 0: # <<<<<<<<<<<<<< - * raise ValueError("unsupported type code '{}'" - * .format(value.typecode)) */ - __pyx_t_6 = ((__pyx_v_array_typecode == 0) != 0); - if (unlikely(__pyx_t_6)) { + __pyx_t_11 = ((__pyx_v_typecode == 0) != 0); + if (unlikely(__pyx_t_11)) { - /* "pysam/libcalignedsegment.pyx":290 - * if array_typecode == 0: - * raise ValueError("unsupported type code '{}'" - * .format(value.typecode)) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":397 * - * valuetype = force_bytes(chr(array_typecode)) + * if typecode == 0: + * raise ValueError("unsupported type code '{}'".format(value.typecode)) # <<<<<<<<<<<<<< + * + * if typecode not in DATATYPE2FORMAT: */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unsupported_type_code, __pyx_n_s_format); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_typecode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_10); + __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unsupported_type_code, __pyx_n_s_format); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 397, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_typecode); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 397, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_16))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_16); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16); + __Pyx_INCREF(__pyx_t_8); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); + __Pyx_DECREF_SET(__pyx_t_16, function); } } - if (!__pyx_t_10) { - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 290, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_8) { + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 397, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_GOTREF(__pyx_t_7); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_1}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 290, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + if (PyFunction_Check(__pyx_t_16)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_10}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_16, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 397, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_1}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 290, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__Pyx_PyFastCFunction_Check(__pyx_t_16)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_10}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_16, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 397, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else #endif { - __pyx_t_16 = PyTuple_New(1+1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_10); __pyx_t_10 = NULL; - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_16, 0+1, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_16, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 290, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 397, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_1, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 397, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pysam/libcalignedsegment.pyx":289 - * - * if array_typecode == 0: - * raise ValueError("unsupported type code '{}'" # <<<<<<<<<<<<<< - * .format(value.typecode)) - * - */ - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_16 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 397, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 289, __pyx_L1_error) + __Pyx_Raise(__pyx_t_16, 0, 0, 0); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __PYX_ERR(0, 397, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":288 - * array_typecode = map_typecode_python_to_htslib(ord(value.typecode)) - * - * if array_typecode == 0: # <<<<<<<<<<<<<< - * raise ValueError("unsupported type code '{}'" - * .format(value.typecode)) - */ - } - - /* "pysam/libcalignedsegment.pyx":292 - * .format(value.typecode)) + /* "pysam/libcalignedsegment.pyx":396 + * typecode = map_typecode_python_to_htslib(ord(value.typecode)) * - * valuetype = force_bytes(chr(array_typecode)) # <<<<<<<<<<<<<< + * if typecode == 0: # <<<<<<<<<<<<<< + * raise ValueError("unsupported type code '{}'".format(value.typecode)) * - * if valuetype not in datatype2format: */ - __pyx_t_8 = __Pyx_PyInt_From_char(__pyx_v_array_typecode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF_SET(__pyx_v_valuetype, __pyx_t_8); - __pyx_t_8 = 0; + } - /* "pysam/libcalignedsegment.pyx":285 + /* "pysam/libcalignedsegment.pyx":393 * elif isinstance(value, array.array): * # binary tags from arrays - * if valuetype is None: # <<<<<<<<<<<<<< - * array_typecode = map_typecode_python_to_htslib(ord(value.typecode)) + * if typecode == 0: # <<<<<<<<<<<<<< + * typecode = map_typecode_python_to_htslib(ord(value.typecode)) * */ } - /* "pysam/libcalignedsegment.pyx":294 - * valuetype = force_bytes(chr(array_typecode)) + /* "pysam/libcalignedsegment.pyx":399 + * raise ValueError("unsupported type code '{}'".format(value.typecode)) * - * if valuetype not in datatype2format: # <<<<<<<<<<<<<< - * raise ValueError("invalid value type '%s' (%s)" % - * (valuetype, type(valuetype))) - */ - __pyx_t_6 = (__Pyx_PyDict_ContainsTF(__pyx_v_valuetype, __pyx_v_datatype2format, Py_NE)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 294, __pyx_L1_error) - __pyx_t_11 = (__pyx_t_6 != 0); - if (unlikely(__pyx_t_11)) { - - /* "pysam/libcalignedsegment.pyx":296 - * if valuetype not in datatype2format: - * raise ValueError("invalid value type '%s' (%s)" % - * (valuetype, type(valuetype))) # <<<<<<<<<<<<<< + * if typecode not in DATATYPE2FORMAT: # <<<<<<<<<<<<<< + * raise ValueError("invalid value type '{}' ({})".format(chr(typecode), array.typecode)) * - * # use array.tostring() to retrieve byte representation and */ - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 296, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_v_valuetype); - __Pyx_GIVEREF(__pyx_v_valuetype); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_valuetype); - __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_valuetype))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_valuetype))); - PyTuple_SET_ITEM(__pyx_t_8, 1, ((PyObject *)Py_TYPE(__pyx_v_valuetype))); + __pyx_t_16 = __Pyx_PyInt_From_uint8_t(__pyx_v_typecode); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 399, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_DATATYPE2FORMAT); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 399, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = (__Pyx_PySequence_ContainsTF(__pyx_t_16, __pyx_t_7, Py_NE)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 399, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_6 = (__pyx_t_11 != 0); + if (unlikely(__pyx_t_6)) { - /* "pysam/libcalignedsegment.pyx":295 + /* "pysam/libcalignedsegment.pyx":400 * - * if valuetype not in datatype2format: - * raise ValueError("invalid value type '%s' (%s)" % # <<<<<<<<<<<<<< - * (valuetype, type(valuetype))) + * if typecode not in DATATYPE2FORMAT: + * raise ValueError("invalid value type '{}' ({})".format(chr(typecode), array.typecode)) # <<<<<<<<<<<<<< * + * # use array.tostring() to retrieve byte representation and */ - __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_invalid_value_type_s_s, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 295, __pyx_L1_error) + __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_value_type_2, __pyx_n_s_format); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 400, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_1 = __Pyx_PyInt_From_uint8_t(__pyx_v_typecode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 400, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 400, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 400, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_typecode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 400, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + __pyx_t_18 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_16))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_16); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_16, function); + __pyx_t_18 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_16)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_10, __pyx_t_8}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_16, __pyx_temp+1-__pyx_t_18, 2+__pyx_t_18); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 400, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_16)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_10, __pyx_t_8}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_16, __pyx_temp+1-__pyx_t_18, 2+__pyx_t_18); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 400, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_19 = PyTuple_New(2+__pyx_t_18); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 400, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_18, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_18, __pyx_t_8); + __pyx_t_10 = 0; + __pyx_t_8 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_19, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 400, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + } + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_16 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 400, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 295, __pyx_L1_error) + __Pyx_Raise(__pyx_t_16, 0, 0, 0); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __PYX_ERR(0, 400, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":294 - * valuetype = force_bytes(chr(array_typecode)) + /* "pysam/libcalignedsegment.pyx":399 + * raise ValueError("unsupported type code '{}'".format(value.typecode)) + * + * if typecode not in DATATYPE2FORMAT: # <<<<<<<<<<<<<< + * raise ValueError("invalid value type '{}' ({})".format(chr(typecode), array.typecode)) * - * if valuetype not in datatype2format: # <<<<<<<<<<<<<< - * raise ValueError("invalid value type '%s' (%s)" % - * (valuetype, type(valuetype))) */ } - /* "pysam/libcalignedsegment.pyx":300 + /* "pysam/libcalignedsegment.pyx":404 * # use array.tostring() to retrieve byte representation and * # save as bytes - * datafmt = "2sccI%is" % (len(value) * datatype2format[valuetype][1]) # <<<<<<<<<<<<<< + * datafmt = "2sBBI%is" % (len(value) * DATATYPE2FORMAT[typecode][1]) # <<<<<<<<<<<<<< * args.extend([pytag[:2], - * b"B", + * ord("B"), */ - __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 300, __pyx_L1_error) - __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 300, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_datatype2format, __pyx_v_valuetype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 300, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_16 = __Pyx_GetItemInt(__pyx_t_7, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 300, __pyx_L1_error) + __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 404, __pyx_L1_error) + __pyx_t_16 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_16); + __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_DATATYPE2FORMAT); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 404, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_19 = __Pyx_GetItemInt(__pyx_t_7, __pyx_v_typecode, uint8_t, 0, __Pyx_PyInt_From_uint8_t, 0, 0, 1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 404, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_t_8, __pyx_t_16); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 300, __pyx_L1_error) + __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_19, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_t_19 = PyNumber_Multiply(__pyx_t_16, __pyx_t_7); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 404, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = __Pyx_PyString_Format(__pyx_kp_s_2sccI_is, __pyx_t_7); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 300, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_datafmt, __pyx_t_16); - __pyx_t_16 = 0; + __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_2sBBI_is, __pyx_t_19); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 404, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF_SET(__pyx_v_datafmt, __pyx_t_7); + __pyx_t_7 = 0; - /* "pysam/libcalignedsegment.pyx":305 - * valuetype, + /* "pysam/libcalignedsegment.pyx":409 + * typecode, * len(value), * force_bytes(value.tostring())]) # <<<<<<<<<<<<<< * * else: */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_tostring); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 305, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_8); + __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_tostring); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 409, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_16 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_19))) { + __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_19); + if (likely(__pyx_t_16)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); + __Pyx_INCREF(__pyx_t_16); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); + __Pyx_DECREF_SET(__pyx_t_19, function); } } - if (__pyx_t_8) { - __pyx_t_16 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 305, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__pyx_t_16) { + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_t_16); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 409, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; } else { - __pyx_t_16 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 305, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_19); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 409, __pyx_L1_error) } - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_16, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_t_19 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_7, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 409, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcalignedsegment.pyx":301 + /* "pysam/libcalignedsegment.pyx":405 * # save as bytes - * datafmt = "2sccI%is" % (len(value) * datatype2format[valuetype][1]) + * datafmt = "2sBBI%is" % (len(value) * DATATYPE2FORMAT[typecode][1]) * args.extend([pytag[:2], # <<<<<<<<<<<<<< - * b"B", - * valuetype, + * ord("B"), + * typecode, */ - __pyx_t_16 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__14, 0, 1, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 301, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_14 = __Pyx_ListComp_Append(__pyx_v_args, __pyx_t_16); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 301, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_17 = __Pyx_ListComp_Append(__pyx_v_args, __pyx_n_b_B); if (unlikely(__pyx_t_17 == ((int)-1))) __PYX_ERR(0, 301, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__6, 0, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 405, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_17 = __Pyx_ListComp_Append(__pyx_v_args, __pyx_t_7); if (unlikely(__pyx_t_17 == ((int)-1))) __PYX_ERR(0, 405, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_20 = __Pyx_ListComp_Append(__pyx_v_args, __pyx_int_66); if (unlikely(__pyx_t_20 == ((int)-1))) __PYX_ERR(0, 405, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":303 + /* "pysam/libcalignedsegment.pyx":407 * args.extend([pytag[:2], - * b"B", - * valuetype, # <<<<<<<<<<<<<< + * ord("B"), + * typecode, # <<<<<<<<<<<<<< * len(value), * force_bytes(value.tostring())]) */ - __pyx_t_18 = __Pyx_ListComp_Append(__pyx_v_args, __pyx_v_valuetype); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 301, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyInt_From_uint8_t(__pyx_v_typecode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 407, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcalignedsegment.pyx":304 - * b"B", - * valuetype, + /* "pysam/libcalignedsegment.pyx":405 + * # save as bytes + * datafmt = "2sBBI%is" % (len(value) * DATATYPE2FORMAT[typecode][1]) + * args.extend([pytag[:2], # <<<<<<<<<<<<<< + * ord("B"), + * typecode, + */ + __pyx_t_21 = __Pyx_ListComp_Append(__pyx_v_args, __pyx_t_7); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 405, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pysam/libcalignedsegment.pyx":408 + * ord("B"), + * typecode, * len(value), # <<<<<<<<<<<<<< * force_bytes(value.tostring())]) * */ - __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 304, __pyx_L1_error) - __pyx_t_16 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 304, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); + __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 408, __pyx_L1_error) + __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 408, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcalignedsegment.pyx":301 + /* "pysam/libcalignedsegment.pyx":405 * # save as bytes - * datafmt = "2sccI%is" % (len(value) * datatype2format[valuetype][1]) + * datafmt = "2sBBI%is" % (len(value) * DATATYPE2FORMAT[typecode][1]) * args.extend([pytag[:2], # <<<<<<<<<<<<<< - * b"B", - * valuetype, + * ord("B"), + * typecode, */ - __pyx_t_19 = __Pyx_ListComp_Append(__pyx_v_args, __pyx_t_16); if (unlikely(__pyx_t_19 == ((int)-1))) __PYX_ERR(0, 301, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_20 = __Pyx_PyList_Append(__pyx_v_args, __pyx_t_7); if (unlikely(__pyx_t_20 == ((int)-1))) __PYX_ERR(0, 301, __pyx_L1_error) + __pyx_t_22 = __Pyx_ListComp_Append(__pyx_v_args, __pyx_t_7); if (unlikely(__pyx_t_22 == ((int)-1))) __PYX_ERR(0, 405, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - (void)((__pyx_t_14 | (__pyx_t_17 | (__pyx_t_18 | (__pyx_t_19 | __pyx_t_20))))); + __pyx_t_23 = __Pyx_PyList_Append(__pyx_v_args, __pyx_t_19); if (unlikely(__pyx_t_23 == ((int)-1))) __PYX_ERR(0, 405, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + (void)((__pyx_t_17 | (__pyx_t_20 | (__pyx_t_21 | (__pyx_t_22 | __pyx_t_23))))); - /* "pysam/libcalignedsegment.pyx":283 + /* "pysam/libcalignedsegment.pyx":391 * len(value)] + list(value)) * * elif isinstance(value, array.array): # <<<<<<<<<<<<<< * # binary tags from arrays - * if valuetype is None: + * if typecode == 0: */ - goto __pyx_L10; + goto __pyx_L12; } - /* "pysam/libcalignedsegment.pyx":308 + /* "pysam/libcalignedsegment.pyx":412 * * else: - * if valuetype is None: # <<<<<<<<<<<<<< - * valuetype = getTypecode(value) - * + * if typecode == 0: # <<<<<<<<<<<<<< + * typecode = get_tag_typecode(value) + * if typecode == 0: */ /*else*/ { - __pyx_t_11 = (__pyx_v_valuetype == Py_None); - __pyx_t_6 = (__pyx_t_11 != 0); + __pyx_t_6 = ((__pyx_v_typecode == 0) != 0); if (__pyx_t_6) { - /* "pysam/libcalignedsegment.pyx":309 + /* "pysam/libcalignedsegment.pyx":413 * else: - * if valuetype is None: - * valuetype = getTypecode(value) # <<<<<<<<<<<<<< + * if typecode == 0: + * typecode = get_tag_typecode(value) # <<<<<<<<<<<<<< + * if typecode == 0: + * raise ValueError("could not deduce typecode for value {}".format(value)) + */ + __pyx_v_typecode = __pyx_f_5pysam_18libcalignedsegment_get_tag_typecode(__pyx_v_value, NULL); + + /* "pysam/libcalignedsegment.pyx":414 + * if typecode == 0: + * typecode = get_tag_typecode(value) + * if typecode == 0: # <<<<<<<<<<<<<< + * raise ValueError("could not deduce typecode for value {}".format(value)) * - * if valuetype in b"AZ": */ - __pyx_t_7 = __pyx_f_5pysam_18libcalignedsegment_getTypecode(__pyx_v_value, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF_SET(__pyx_v_valuetype, __pyx_t_7); - __pyx_t_7 = 0; + __pyx_t_6 = ((__pyx_v_typecode == 0) != 0); + if (unlikely(__pyx_t_6)) { - /* "pysam/libcalignedsegment.pyx":308 + /* "pysam/libcalignedsegment.pyx":415 + * typecode = get_tag_typecode(value) + * if typecode == 0: + * raise ValueError("could not deduce typecode for value {}".format(value)) # <<<<<<<<<<<<<< * - * else: - * if valuetype is None: # <<<<<<<<<<<<<< - * valuetype = getTypecode(value) + * if typecode == 'a' or typecode == 'A' or typecode == 'Z' or typecode == 'H': + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_deduce_typecode_for_va, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 415, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_16 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_16)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_16); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_16) { + __pyx_t_19 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_value); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 415, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_16, __pyx_v_value}; + __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 415, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_GOTREF(__pyx_t_19); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_16, __pyx_v_value}; + __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 415, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_GOTREF(__pyx_t_19); + } else + #endif + { + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 415, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_16); __pyx_t_16 = NULL; + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_value); + __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 415, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_19); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 415, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 415, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":414 + * if typecode == 0: + * typecode = get_tag_typecode(value) + * if typecode == 0: # <<<<<<<<<<<<<< + * raise ValueError("could not deduce typecode for value {}".format(value)) + * + */ + } + + /* "pysam/libcalignedsegment.pyx":412 * + * else: + * if typecode == 0: # <<<<<<<<<<<<<< + * typecode = get_tag_typecode(value) + * if typecode == 0: */ } - /* "pysam/libcalignedsegment.pyx":311 - * valuetype = getTypecode(value) + /* "pysam/libcalignedsegment.pyx":417 + * raise ValueError("could not deduce typecode for value {}".format(value)) * - * if valuetype in b"AZ": # <<<<<<<<<<<<<< + * if typecode == 'a' or typecode == 'A' or typecode == 'Z' or typecode == 'H': # <<<<<<<<<<<<<< * value = force_bytes(value) * */ - __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_v_valuetype, __pyx_n_b_AZ, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 311, __pyx_L1_error) - __pyx_t_11 = (__pyx_t_6 != 0); - if (__pyx_t_11) { + switch (__pyx_v_typecode) { + case 'a': + case 'A': + case 'Z': + case 'H': - /* "pysam/libcalignedsegment.pyx":312 + /* "pysam/libcalignedsegment.pyx":418 * - * if valuetype in b"AZ": + * if typecode == 'a' or typecode == 'A' or typecode == 'Z' or typecode == 'H': * value = force_bytes(value) # <<<<<<<<<<<<<< * - * if valuetype == b"Z": + * if typecode == "a": */ - __pyx_t_7 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 312, __pyx_L1_error) + __pyx_t_7 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 418, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcalignedsegment.pyx":311 - * valuetype = getTypecode(value) + /* "pysam/libcalignedsegment.pyx":417 + * raise ValueError("could not deduce typecode for value {}".format(value)) * - * if valuetype in b"AZ": # <<<<<<<<<<<<<< + * if typecode == 'a' or typecode == 'A' or typecode == 'Z' or typecode == 'H': # <<<<<<<<<<<<<< * value = force_bytes(value) * */ + break; + default: break; } - /* "pysam/libcalignedsegment.pyx":314 + /* "pysam/libcalignedsegment.pyx":420 * value = force_bytes(value) * - * if valuetype == b"Z": # <<<<<<<<<<<<<< - * datafmt = "2sc%is" % (len(value)+1) + * if typecode == "a": # <<<<<<<<<<<<<< + * typecode = 'A' + * + */ + __pyx_t_6 = ((__pyx_v_typecode == 'a') != 0); + if (__pyx_t_6) { + + /* "pysam/libcalignedsegment.pyx":421 + * + * if typecode == "a": + * typecode = 'A' # <<<<<<<<<<<<<< + * + * if typecode == 'Z' or typecode == 'H': + */ + __pyx_v_typecode = 'A'; + + /* "pysam/libcalignedsegment.pyx":420 + * value = force_bytes(value) + * + * if typecode == "a": # <<<<<<<<<<<<<< + * typecode = 'A' + * + */ + } + + /* "pysam/libcalignedsegment.pyx":423 + * typecode = 'A' + * + * if typecode == 'Z' or typecode == 'H': # <<<<<<<<<<<<<< + * datafmt = "2sB%is" % (len(value)+1) * else: */ - __pyx_t_11 = (__Pyx_PyBytes_Equals(__pyx_v_valuetype, __pyx_n_b_Z, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 314, __pyx_L1_error) - if (__pyx_t_11) { + switch (__pyx_v_typecode) { + case 'Z': + case 'H': - /* "pysam/libcalignedsegment.pyx":315 + /* "pysam/libcalignedsegment.pyx":424 * - * if valuetype == b"Z": - * datafmt = "2sc%is" % (len(value)+1) # <<<<<<<<<<<<<< + * if typecode == 'Z' or typecode == 'H': + * datafmt = "2sB%is" % (len(value)+1) # <<<<<<<<<<<<<< * else: - * datafmt = "2sc%s" % datatype2format[valuetype][0] + * datafmt = "2sB%s" % DATATYPE2FORMAT[typecode][0] */ - __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 315, __pyx_L1_error) - __pyx_t_7 = PyInt_FromSsize_t((__pyx_t_5 + 1)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 315, __pyx_L1_error) + __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 424, __pyx_L1_error) + __pyx_t_7 = PyInt_FromSsize_t((__pyx_t_5 + 1)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 424, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_16 = __Pyx_PyString_Format(__pyx_kp_s_2sc_is, __pyx_t_7); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 315, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); + __pyx_t_19 = __Pyx_PyString_Format(__pyx_kp_s_2sB_is, __pyx_t_7); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 424, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_datafmt, __pyx_t_16); - __pyx_t_16 = 0; + __Pyx_XDECREF_SET(__pyx_v_datafmt, __pyx_t_19); + __pyx_t_19 = 0; - /* "pysam/libcalignedsegment.pyx":314 - * value = force_bytes(value) + /* "pysam/libcalignedsegment.pyx":423 + * typecode = 'A' * - * if valuetype == b"Z": # <<<<<<<<<<<<<< - * datafmt = "2sc%is" % (len(value)+1) + * if typecode == 'Z' or typecode == 'H': # <<<<<<<<<<<<<< + * datafmt = "2sB%is" % (len(value)+1) * else: */ - goto __pyx_L20; - } + break; + default: - /* "pysam/libcalignedsegment.pyx":317 - * datafmt = "2sc%is" % (len(value)+1) + /* "pysam/libcalignedsegment.pyx":426 + * datafmt = "2sB%is" % (len(value)+1) * else: - * datafmt = "2sc%s" % datatype2format[valuetype][0] # <<<<<<<<<<<<<< + * datafmt = "2sB%s" % DATATYPE2FORMAT[typecode][0] # <<<<<<<<<<<<<< * * args.extend([pytag[:2], */ - /*else*/ { - __pyx_t_16 = __Pyx_PyDict_GetItem(__pyx_v_datatype2format, __pyx_v_valuetype); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 317, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_16, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 317, __pyx_L1_error) + __pyx_t_19 = __Pyx_GetModuleGlobalName(__pyx_n_s_DATATYPE2FORMAT); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_19, __pyx_v_typecode, uint8_t, 0, __Pyx_PyInt_From_uint8_t, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 426, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - __pyx_t_16 = __Pyx_PyString_Format(__pyx_kp_s_2sc_s, __pyx_t_7); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 317, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_t_19 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_19); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_datafmt, __pyx_t_16); - __pyx_t_16 = 0; + __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_2sB_s, __pyx_t_19); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF_SET(__pyx_v_datafmt, __pyx_t_7); + __pyx_t_7 = 0; + break; } - __pyx_L20:; - /* "pysam/libcalignedsegment.pyx":319 - * datafmt = "2sc%s" % datatype2format[valuetype][0] + /* "pysam/libcalignedsegment.pyx":428 + * datafmt = "2sB%s" % DATATYPE2FORMAT[typecode][0] * * args.extend([pytag[:2], # <<<<<<<<<<<<<< - * valuetype, + * typecode, * value]) */ - __pyx_t_16 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__15, 0, 1, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 319, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_20 = __Pyx_ListComp_Append(__pyx_v_args, __pyx_t_16); if (unlikely(__pyx_t_20 == ((int)-1))) __PYX_ERR(0, 319, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__7, 0, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 428, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_23 = __Pyx_ListComp_Append(__pyx_v_args, __pyx_t_7); if (unlikely(__pyx_t_23 == ((int)-1))) __PYX_ERR(0, 428, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcalignedsegment.pyx":320 + /* "pysam/libcalignedsegment.pyx":429 * * args.extend([pytag[:2], - * valuetype, # <<<<<<<<<<<<<< + * typecode, # <<<<<<<<<<<<<< + * value]) + * + */ + __pyx_t_7 = __Pyx_PyInt_From_uint8_t(__pyx_v_typecode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "pysam/libcalignedsegment.pyx":428 + * datafmt = "2sB%s" % DATATYPE2FORMAT[typecode][0] + * + * args.extend([pytag[:2], # <<<<<<<<<<<<<< + * typecode, * value]) + */ + __pyx_t_22 = __Pyx_ListComp_Append(__pyx_v_args, __pyx_t_7); if (unlikely(__pyx_t_22 == ((int)-1))) __PYX_ERR(0, 428, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pysam/libcalignedsegment.pyx":430 + * args.extend([pytag[:2], + * typecode, + * value]) # <<<<<<<<<<<<<< * + * fmts.append(datafmt) */ - __pyx_t_19 = __Pyx_ListComp_Append(__pyx_v_args, __pyx_v_valuetype); if (unlikely(__pyx_t_19 == ((int)-1))) __PYX_ERR(0, 319, __pyx_L1_error) + __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_args, __pyx_v_value); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 428, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":319 - * datafmt = "2sc%s" % datatype2format[valuetype][0] + /* "pysam/libcalignedsegment.pyx":428 + * datafmt = "2sB%s" % DATATYPE2FORMAT[typecode][0] * * args.extend([pytag[:2], # <<<<<<<<<<<<<< - * valuetype, + * typecode, * value]) */ - __pyx_t_18 = __Pyx_PyList_Append(__pyx_v_args, __pyx_v_value); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 319, __pyx_L1_error) - (void)((__pyx_t_20 | (__pyx_t_19 | __pyx_t_18))); + (void)((__pyx_t_23 | (__pyx_t_22 | __pyx_t_21))); } - __pyx_L10:; + __pyx_L12:; - /* "pysam/libcalignedsegment.pyx":323 + /* "pysam/libcalignedsegment.pyx":432 * value]) * * fmts.append(datafmt) # <<<<<<<<<<<<<< * * return "".join(fmts), args */ - __pyx_t_18 = __Pyx_PyList_Append(__pyx_v_fmts, __pyx_v_datafmt); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 323, __pyx_L1_error) + __pyx_t_21 = __Pyx_PyList_Append(__pyx_v_fmts, __pyx_v_datafmt); if (unlikely(__pyx_t_21 == ((int)-1))) __PYX_ERR(0, 432, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":252 - * b'A': ('c', 1)} - * + /* "pysam/libcalignedsegment.pyx":350 + * # htslib typecode + * cdef uint8_t typecode * for tag in tags: # <<<<<<<<<<<<<< * * if len(tag) == 2: @@ -6783,7 +8328,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignedsegment.pyx":325 + /* "pysam/libcalignedsegment.pyx":434 * fmts.append(datafmt) * * return "".join(fmts), args # <<<<<<<<<<<<<< @@ -6791,24 +8336,24 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__16, __pyx_v_fmts); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 325, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__8, __pyx_v_fmts); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 434, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 325, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_16); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 434, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); __Pyx_INCREF(__pyx_v_args); __Pyx_GIVEREF(__pyx_v_args); - PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_v_args); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_args); __pyx_t_2 = 0; - __pyx_r = __pyx_t_16; - __pyx_t_16 = 0; + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":229 + /* "pysam/libcalignedsegment.pyx":337 * * - * cdef inline packTags(tags): # <<<<<<<<<<<<<< + * cdef inline pack_tags(tags): # <<<<<<<<<<<<<< * """pack a list of tags. Each tag is a tuple of (tag, tuple). * */ @@ -6821,17 +8366,17 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_10); __Pyx_XDECREF(__pyx_t_16); - __Pyx_AddTraceback("pysam.libcalignedsegment.packTags", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_19); + __Pyx_AddTraceback("pysam.libcalignedsegment.pack_tags", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_fmts); __Pyx_XDECREF(__pyx_v_args); - __Pyx_XDECREF(__pyx_v_datatype2format); __Pyx_XDECREF(__pyx_v_tag); __Pyx_XDECREF(__pyx_v_pytag); __Pyx_XDECREF(__pyx_v_value); __Pyx_XDECREF(__pyx_v_valuetype); - __Pyx_XDECREF(__pyx_v_t); + __Pyx_XDECREF(__pyx_v_pytype); __Pyx_XDECREF(__pyx_v_datafmt); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); @@ -6839,15 +8384,15 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_packTags(PyOb return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":328 +/* "pysam/libcalignedsegment.pyx":437 * * - * cdef inline int32_t calculateQueryLength(bam1_t * src): # <<<<<<<<<<<<<< + * cdef inline int32_t calculateQueryLengthWithoutHardClipping(bam1_t * src): # <<<<<<<<<<<<<< * """return query length computed from CIGAR alignment. * */ -static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryLength(bam1_t *__pyx_v_src) { +static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryLengthWithoutHardClipping(bam1_t *__pyx_v_src) { uint32_t *__pyx_v_cigar_p; uint32_t __pyx_v_k; uint32_t __pyx_v_qpos; @@ -6856,12 +8401,12 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; - uint16_t __pyx_t_2; + uint32_t __pyx_t_2; int __pyx_t_3; - __Pyx_RefNannySetupContext("calculateQueryLength", 0); - __Pyx_TraceCall("calculateQueryLength", __pyx_f[0], 328, 0, __PYX_ERR(0, 328, __pyx_L1_error)); + __Pyx_RefNannySetupContext("calculateQueryLengthWithoutHardClipping", 0); + __Pyx_TraceCall("calculateQueryLengthWithoutHardClipping", __pyx_f[0], 437, 0, __PYX_ERR(0, 437, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":334 + /* "pysam/libcalignedsegment.pyx":445 * """ * * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< @@ -6870,7 +8415,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL */ __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":336 + /* "pysam/libcalignedsegment.pyx":447 * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) * * if cigar_p == NULL: # <<<<<<<<<<<<<< @@ -6880,7 +8425,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL __pyx_t_1 = ((__pyx_v_cigar_p == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":337 + /* "pysam/libcalignedsegment.pyx":448 * * if cigar_p == NULL: * return 0 # <<<<<<<<<<<<<< @@ -6890,7 +8435,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":336 + /* "pysam/libcalignedsegment.pyx":447 * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) * * if cigar_p == NULL: # <<<<<<<<<<<<<< @@ -6899,7 +8444,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL */ } - /* "pysam/libcalignedsegment.pyx":341 + /* "pysam/libcalignedsegment.pyx":452 * cdef uint32_t k, qpos * cdef int op * qpos = 0 # <<<<<<<<<<<<<< @@ -6908,7 +8453,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL */ __pyx_v_qpos = 0; - /* "pysam/libcalignedsegment.pyx":343 + /* "pysam/libcalignedsegment.pyx":454 * qpos = 0 * * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< @@ -6918,7 +8463,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL __pyx_t_2 = pysam_get_n_cigar(__pyx_v_src); for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_2; __pyx_v_k++) { - /* "pysam/libcalignedsegment.pyx":344 + /* "pysam/libcalignedsegment.pyx":455 * * for k from 0 <= k < pysam_get_n_cigar(src): * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< @@ -6927,7 +8472,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL */ __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); - /* "pysam/libcalignedsegment.pyx":346 + /* "pysam/libcalignedsegment.pyx":457 * op = cigar_p[k] & BAM_CIGAR_MASK * * if op == BAM_CMATCH or \ # <<<<<<<<<<<<<< @@ -6941,7 +8486,218 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL goto __pyx_L7_bool_binop_done; } - /* "pysam/libcalignedsegment.pyx":347 + /* "pysam/libcalignedsegment.pyx":458 + * + * if op == BAM_CMATCH or \ + * op == BAM_CINS or \ # <<<<<<<<<<<<<< + * op == BAM_CSOFT_CLIP or \ + * op == BAM_CEQUAL or \ + */ + __pyx_t_3 = ((__pyx_v_op == BAM_CINS) != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L7_bool_binop_done; + } + + /* "pysam/libcalignedsegment.pyx":459 + * if op == BAM_CMATCH or \ + * op == BAM_CINS or \ + * op == BAM_CSOFT_CLIP or \ # <<<<<<<<<<<<<< + * op == BAM_CEQUAL or \ + * op == BAM_CDIFF: + */ + __pyx_t_3 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L7_bool_binop_done; + } + + /* "pysam/libcalignedsegment.pyx":460 + * op == BAM_CINS or \ + * op == BAM_CSOFT_CLIP or \ + * op == BAM_CEQUAL or \ # <<<<<<<<<<<<<< + * op == BAM_CDIFF: + * qpos += cigar_p[k] >> BAM_CIGAR_SHIFT + */ + __pyx_t_3 = ((__pyx_v_op == BAM_CEQUAL) != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L7_bool_binop_done; + } + + /* "pysam/libcalignedsegment.pyx":461 + * op == BAM_CSOFT_CLIP or \ + * op == BAM_CEQUAL or \ + * op == BAM_CDIFF: # <<<<<<<<<<<<<< + * qpos += cigar_p[k] >> BAM_CIGAR_SHIFT + * + */ + __pyx_t_3 = ((__pyx_v_op == BAM_CDIFF) != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L7_bool_binop_done:; + + /* "pysam/libcalignedsegment.pyx":457 + * op = cigar_p[k] & BAM_CIGAR_MASK + * + * if op == BAM_CMATCH or \ # <<<<<<<<<<<<<< + * op == BAM_CINS or \ + * op == BAM_CSOFT_CLIP or \ + */ + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":462 + * op == BAM_CEQUAL or \ + * op == BAM_CDIFF: + * qpos += cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< + * + * return qpos + */ + __pyx_v_qpos = (__pyx_v_qpos + ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); + + /* "pysam/libcalignedsegment.pyx":457 + * op = cigar_p[k] & BAM_CIGAR_MASK + * + * if op == BAM_CMATCH or \ # <<<<<<<<<<<<<< + * op == BAM_CINS or \ + * op == BAM_CSOFT_CLIP or \ + */ + } + } + + /* "pysam/libcalignedsegment.pyx":464 + * qpos += cigar_p[k] >> BAM_CIGAR_SHIFT + * + * return qpos # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_qpos; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":437 + * + * + * cdef inline int32_t calculateQueryLengthWithoutHardClipping(bam1_t * src): # <<<<<<<<<<<<<< + * """return query length computed from CIGAR alignment. + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("pysam.libcalignedsegment.calculateQueryLengthWithoutHardClipping", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":467 + * + * + * cdef inline int32_t calculateQueryLengthWithHardClipping(bam1_t * src): # <<<<<<<<<<<<<< + * """return query length computed from CIGAR alignment. + * + */ + +static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryLengthWithHardClipping(bam1_t *__pyx_v_src) { + uint32_t *__pyx_v_cigar_p; + uint32_t __pyx_v_k; + uint32_t __pyx_v_qpos; + int __pyx_v_op; + int32_t __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + uint32_t __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("calculateQueryLengthWithHardClipping", 0); + __Pyx_TraceCall("calculateQueryLengthWithHardClipping", __pyx_f[0], 467, 0, __PYX_ERR(0, 467, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":475 + * """ + * + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + * + * if cigar_p == NULL: + */ + __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); + + /* "pysam/libcalignedsegment.pyx":477 + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) + * + * if cigar_p == NULL: # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_t_1 = ((__pyx_v_cigar_p == NULL) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":478 + * + * if cigar_p == NULL: + * return 0 # <<<<<<<<<<<<<< + * + * cdef uint32_t k, qpos + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":477 + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) + * + * if cigar_p == NULL: # <<<<<<<<<<<<<< + * return 0 + * + */ + } + + /* "pysam/libcalignedsegment.pyx":482 + * cdef uint32_t k, qpos + * cdef int op + * qpos = 0 # <<<<<<<<<<<<<< + * + * for k from 0 <= k < pysam_get_n_cigar(src): + */ + __pyx_v_qpos = 0; + + /* "pysam/libcalignedsegment.pyx":484 + * qpos = 0 + * + * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< + * op = cigar_p[k] & BAM_CIGAR_MASK + * + */ + __pyx_t_2 = pysam_get_n_cigar(__pyx_v_src); + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_2; __pyx_v_k++) { + + /* "pysam/libcalignedsegment.pyx":485 + * + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< + * + * if op == BAM_CMATCH or \ + */ + __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); + + /* "pysam/libcalignedsegment.pyx":487 + * op = cigar_p[k] & BAM_CIGAR_MASK + * + * if op == BAM_CMATCH or \ # <<<<<<<<<<<<<< + * op == BAM_CINS or \ + * op == BAM_CSOFT_CLIP or \ + */ + __pyx_t_3 = ((__pyx_v_op == BAM_CMATCH) != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L7_bool_binop_done; + } + + /* "pysam/libcalignedsegment.pyx":488 * * if op == BAM_CMATCH or \ * op == BAM_CINS or \ # <<<<<<<<<<<<<< @@ -6955,7 +8711,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL goto __pyx_L7_bool_binop_done; } - /* "pysam/libcalignedsegment.pyx":348 + /* "pysam/libcalignedsegment.pyx":489 * if op == BAM_CMATCH or \ * op == BAM_CINS or \ * op == BAM_CSOFT_CLIP or \ # <<<<<<<<<<<<<< @@ -6969,7 +8725,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL goto __pyx_L7_bool_binop_done; } - /* "pysam/libcalignedsegment.pyx":349 + /* "pysam/libcalignedsegment.pyx":490 * op == BAM_CINS or \ * op == BAM_CSOFT_CLIP or \ * op == BAM_CHARD_CLIP or \ # <<<<<<<<<<<<<< @@ -6983,7 +8739,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL goto __pyx_L7_bool_binop_done; } - /* "pysam/libcalignedsegment.pyx":350 + /* "pysam/libcalignedsegment.pyx":491 * op == BAM_CSOFT_CLIP or \ * op == BAM_CHARD_CLIP or \ * op == BAM_CEQUAL or \ # <<<<<<<<<<<<<< @@ -6997,7 +8753,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL goto __pyx_L7_bool_binop_done; } - /* "pysam/libcalignedsegment.pyx":351 + /* "pysam/libcalignedsegment.pyx":492 * op == BAM_CHARD_CLIP or \ * op == BAM_CEQUAL or \ * op == BAM_CDIFF: # <<<<<<<<<<<<<< @@ -7008,7 +8764,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL __pyx_t_1 = __pyx_t_3; __pyx_L7_bool_binop_done:; - /* "pysam/libcalignedsegment.pyx":346 + /* "pysam/libcalignedsegment.pyx":487 * op = cigar_p[k] & BAM_CIGAR_MASK * * if op == BAM_CMATCH or \ # <<<<<<<<<<<<<< @@ -7017,7 +8773,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL */ if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":352 + /* "pysam/libcalignedsegment.pyx":493 * op == BAM_CEQUAL or \ * op == BAM_CDIFF: * qpos += cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< @@ -7026,7 +8782,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL */ __pyx_v_qpos = (__pyx_v_qpos + ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); - /* "pysam/libcalignedsegment.pyx":346 + /* "pysam/libcalignedsegment.pyx":487 * op = cigar_p[k] & BAM_CIGAR_MASK * * if op == BAM_CMATCH or \ # <<<<<<<<<<<<<< @@ -7036,7 +8792,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL } } - /* "pysam/libcalignedsegment.pyx":354 + /* "pysam/libcalignedsegment.pyx":495 * qpos += cigar_p[k] >> BAM_CIGAR_SHIFT * * return qpos # <<<<<<<<<<<<<< @@ -7046,17 +8802,17 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL __pyx_r = __pyx_v_qpos; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":328 + /* "pysam/libcalignedsegment.pyx":467 * * - * cdef inline int32_t calculateQueryLength(bam1_t * src): # <<<<<<<<<<<<<< + * cdef inline int32_t calculateQueryLengthWithHardClipping(bam1_t * src): # <<<<<<<<<<<<<< * """return query length computed from CIGAR alignment. * */ /* function exit code */ __pyx_L1_error:; - __Pyx_WriteUnraisable("pysam.libcalignedsegment.calculateQueryLength", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __Pyx_WriteUnraisable("pysam.libcalignedsegment.calculateQueryLengthWithHardClipping", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_r = 0; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -7064,195 +8820,171 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_calculateQueryL return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":357 +/* "pysam/libcalignedsegment.pyx":498 * * * cdef inline int32_t getQueryStart(bam1_t *src) except -1: # <<<<<<<<<<<<<< * cdef uint32_t * cigar_p - * cdef uint32_t k, op + * cdef uint32_t start_offset = 0 */ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_getQueryStart(bam1_t *__pyx_v_src) { uint32_t *__pyx_v_cigar_p; + uint32_t __pyx_v_start_offset; uint32_t __pyx_v_k; uint32_t __pyx_v_op; - uint32_t __pyx_v_start_offset; int32_t __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - uint16_t __pyx_t_2; + uint32_t __pyx_t_1; + int __pyx_t_2; int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("getQueryStart", 0); - __Pyx_TraceCall("getQueryStart", __pyx_f[0], 357, 0, __PYX_ERR(0, 357, __pyx_L1_error)); + __Pyx_TraceCall("getQueryStart", __pyx_f[0], 498, 0, __PYX_ERR(0, 498, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":360 + /* "pysam/libcalignedsegment.pyx":500 + * cdef inline int32_t getQueryStart(bam1_t *src) except -1: * cdef uint32_t * cigar_p - * cdef uint32_t k, op * cdef uint32_t start_offset = 0 # <<<<<<<<<<<<<< + * cdef uint32_t k, op * - * if pysam_get_n_cigar(src): */ __pyx_v_start_offset = 0; - /* "pysam/libcalignedsegment.pyx":362 - * cdef uint32_t start_offset = 0 + /* "pysam/libcalignedsegment.pyx":503 + * cdef uint32_t k, op * - * if pysam_get_n_cigar(src): # <<<<<<<<<<<<<< - * cigar_p = pysam_bam_get_cigar(src); - * for k from 0 <= k < pysam_get_n_cigar(src): + * cigar_p = pysam_bam_get_cigar(src); # <<<<<<<<<<<<<< + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK */ - __pyx_t_1 = (pysam_get_n_cigar(__pyx_v_src) != 0); - if (__pyx_t_1) { + __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":363 + /* "pysam/libcalignedsegment.pyx":504 * - * if pysam_get_n_cigar(src): - * cigar_p = pysam_bam_get_cigar(src); # <<<<<<<<<<<<<< - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK - */ - __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - - /* "pysam/libcalignedsegment.pyx":364 - * if pysam_get_n_cigar(src): - * cigar_p = pysam_bam_get_cigar(src); - * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< - * op = cigar_p[k] & BAM_CIGAR_MASK - * if op == BAM_CHARD_CLIP: - */ - __pyx_t_2 = pysam_get_n_cigar(__pyx_v_src); - for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_2; __pyx_v_k++) { - - /* "pysam/libcalignedsegment.pyx":365 - * cigar_p = pysam_bam_get_cigar(src); - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< - * if op == BAM_CHARD_CLIP: - * if start_offset != 0 and start_offset != src.core.l_qseq: - */ - __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); - - /* "pysam/libcalignedsegment.pyx":366 - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK - * if op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< - * if start_offset != 0 and start_offset != src.core.l_qseq: - * PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string') + * cigar_p = pysam_bam_get_cigar(src); + * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< + * op = cigar_p[k] & BAM_CIGAR_MASK + * if op == BAM_CHARD_CLIP: */ - __pyx_t_1 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0); - if (__pyx_t_1) { + __pyx_t_1 = pysam_get_n_cigar(__pyx_v_src); + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_1; __pyx_v_k++) { - /* "pysam/libcalignedsegment.pyx":367 - * op = cigar_p[k] & BAM_CIGAR_MASK - * if op == BAM_CHARD_CLIP: - * if start_offset != 0 and start_offset != src.core.l_qseq: # <<<<<<<<<<<<<< - * PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string') - * return -1 + /* "pysam/libcalignedsegment.pyx":505 + * cigar_p = pysam_bam_get_cigar(src); + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< + * if op == BAM_CHARD_CLIP: + * if start_offset != 0 and start_offset != src.core.l_qseq: */ - __pyx_t_3 = ((__pyx_v_start_offset != 0) != 0); - if (__pyx_t_3) { - } else { - __pyx_t_1 = __pyx_t_3; - goto __pyx_L8_bool_binop_done; - } - __pyx_t_3 = ((__pyx_v_start_offset != __pyx_v_src->core.l_qseq) != 0); - __pyx_t_1 = __pyx_t_3; - __pyx_L8_bool_binop_done:; - if (__pyx_t_1) { + __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); - /* "pysam/libcalignedsegment.pyx":368 - * if op == BAM_CHARD_CLIP: - * if start_offset != 0 and start_offset != src.core.l_qseq: - * PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string') # <<<<<<<<<<<<<< - * return -1 - * elif op == BAM_CSOFT_CLIP: + /* "pysam/libcalignedsegment.pyx":506 + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK + * if op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< + * if start_offset != 0 and start_offset != src.core.l_qseq: + * raise ValueError('Invalid clipping in CIGAR string') */ - PyErr_SetString(__pyx_builtin_ValueError, ((char *)"Invalid clipping in CIGAR string")); + __pyx_t_2 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0); + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":369 - * if start_offset != 0 and start_offset != src.core.l_qseq: - * PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string') - * return -1 # <<<<<<<<<<<<<< - * elif op == BAM_CSOFT_CLIP: - * start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT + /* "pysam/libcalignedsegment.pyx":507 + * op = cigar_p[k] & BAM_CIGAR_MASK + * if op == BAM_CHARD_CLIP: + * if start_offset != 0 and start_offset != src.core.l_qseq: # <<<<<<<<<<<<<< + * raise ValueError('Invalid clipping in CIGAR string') + * elif op == BAM_CSOFT_CLIP: */ - __pyx_r = -1; - goto __pyx_L0; + __pyx_t_3 = ((__pyx_v_start_offset != 0) != 0); + if (__pyx_t_3) { + } else { + __pyx_t_2 = __pyx_t_3; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_3 = ((__pyx_v_start_offset != __pyx_v_src->core.l_qseq) != 0); + __pyx_t_2 = __pyx_t_3; + __pyx_L7_bool_binop_done:; + if (unlikely(__pyx_t_2)) { - /* "pysam/libcalignedsegment.pyx":367 - * op = cigar_p[k] & BAM_CIGAR_MASK - * if op == BAM_CHARD_CLIP: - * if start_offset != 0 and start_offset != src.core.l_qseq: # <<<<<<<<<<<<<< - * PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string') - * return -1 + /* "pysam/libcalignedsegment.pyx":508 + * if op == BAM_CHARD_CLIP: + * if start_offset != 0 and start_offset != src.core.l_qseq: + * raise ValueError('Invalid clipping in CIGAR string') # <<<<<<<<<<<<<< + * elif op == BAM_CSOFT_CLIP: + * start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT */ - } + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 508, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 508, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":366 - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK - * if op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< - * if start_offset != 0 and start_offset != src.core.l_qseq: - * PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string') + /* "pysam/libcalignedsegment.pyx":507 + * op = cigar_p[k] & BAM_CIGAR_MASK + * if op == BAM_CHARD_CLIP: + * if start_offset != 0 and start_offset != src.core.l_qseq: # <<<<<<<<<<<<<< + * raise ValueError('Invalid clipping in CIGAR string') + * elif op == BAM_CSOFT_CLIP: */ - goto __pyx_L6; } - /* "pysam/libcalignedsegment.pyx":370 - * PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string') - * return -1 - * elif op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< - * start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT - * else: + /* "pysam/libcalignedsegment.pyx":506 + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK + * if op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< + * if start_offset != 0 and start_offset != src.core.l_qseq: + * raise ValueError('Invalid clipping in CIGAR string') */ - __pyx_t_1 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0); - if (__pyx_t_1) { + goto __pyx_L5; + } - /* "pysam/libcalignedsegment.pyx":371 - * return -1 - * elif op == BAM_CSOFT_CLIP: - * start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< - * else: - * break + /* "pysam/libcalignedsegment.pyx":509 + * if start_offset != 0 and start_offset != src.core.l_qseq: + * raise ValueError('Invalid clipping in CIGAR string') + * elif op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< + * start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT + * else: */ - __pyx_v_start_offset = (__pyx_v_start_offset + ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); + __pyx_t_2 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0); + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":370 - * PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string') - * return -1 - * elif op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< - * start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT - * else: + /* "pysam/libcalignedsegment.pyx":510 + * raise ValueError('Invalid clipping in CIGAR string') + * elif op == BAM_CSOFT_CLIP: + * start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< + * else: + * break */ - goto __pyx_L6; - } + __pyx_v_start_offset = (__pyx_v_start_offset + ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); - /* "pysam/libcalignedsegment.pyx":373 - * start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT - * else: - * break # <<<<<<<<<<<<<< - * - * return start_offset + /* "pysam/libcalignedsegment.pyx":509 + * if start_offset != 0 and start_offset != src.core.l_qseq: + * raise ValueError('Invalid clipping in CIGAR string') + * elif op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< + * start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT + * else: */ - /*else*/ { - goto __pyx_L5_break; - } - __pyx_L6:; + goto __pyx_L5; } - __pyx_L5_break:; - /* "pysam/libcalignedsegment.pyx":362 - * cdef uint32_t start_offset = 0 + /* "pysam/libcalignedsegment.pyx":512 + * start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT + * else: + * break # <<<<<<<<<<<<<< * - * if pysam_get_n_cigar(src): # <<<<<<<<<<<<<< - * cigar_p = pysam_bam_get_cigar(src); - * for k from 0 <= k < pysam_get_n_cigar(src): + * return start_offset */ + /*else*/ { + goto __pyx_L4_break; + } + __pyx_L5:; } + __pyx_L4_break:; - /* "pysam/libcalignedsegment.pyx":375 - * break + /* "pysam/libcalignedsegment.pyx":514 + * break * * return start_offset # <<<<<<<<<<<<<< * @@ -7261,16 +8993,17 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_getQueryStart(b __pyx_r = __pyx_v_start_offset; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":357 + /* "pysam/libcalignedsegment.pyx":498 * * * cdef inline int32_t getQueryStart(bam1_t *src) except -1: # <<<<<<<<<<<<<< * cdef uint32_t * cigar_p - * cdef uint32_t k, op + * cdef uint32_t start_offset = 0 */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("pysam.libcalignedsegment.getQueryStart", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -7279,172 +9012,263 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_getQueryStart(b return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":378 +/* "pysam/libcalignedsegment.pyx":517 * * * cdef inline int32_t getQueryEnd(bam1_t *src) except -1: # <<<<<<<<<<<<<< - * cdef uint32_t * cigar_p - * cdef uint32_t k, op + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) + * cdef uint32_t end_offset = src.core.l_qseq */ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(bam1_t *__pyx_v_src) { uint32_t *__pyx_v_cigar_p; + uint32_t __pyx_v_end_offset; uint32_t __pyx_v_k; uint32_t __pyx_v_op; - uint32_t __pyx_v_end_offset; int32_t __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int32_t __pyx_t_1; int __pyx_t_2; - int __pyx_t_3; + uint32_t __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("getQueryEnd", 0); - __Pyx_TraceCall("getQueryEnd", __pyx_f[0], 378, 0, __PYX_ERR(0, 378, __pyx_L1_error)); + __Pyx_TraceCall("getQueryEnd", __pyx_f[0], 517, 0, __PYX_ERR(0, 517, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":381 - * cdef uint32_t * cigar_p + /* "pysam/libcalignedsegment.pyx":518 + * + * cdef inline int32_t getQueryEnd(bam1_t *src) except -1: + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + * cdef uint32_t end_offset = src.core.l_qseq * cdef uint32_t k, op + */ + __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); + + /* "pysam/libcalignedsegment.pyx":519 + * cdef inline int32_t getQueryEnd(bam1_t *src) except -1: + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) * cdef uint32_t end_offset = src.core.l_qseq # <<<<<<<<<<<<<< + * cdef uint32_t k, op * - * # if there is no sequence, compute length from cigar string */ __pyx_t_1 = __pyx_v_src->core.l_qseq; __pyx_v_end_offset = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":384 + /* "pysam/libcalignedsegment.pyx":523 * * # if there is no sequence, compute length from cigar string * if end_offset == 0: # <<<<<<<<<<<<<< - * end_offset = calculateQueryLength(src) - * + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK */ __pyx_t_2 = ((__pyx_v_end_offset == 0) != 0); if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":385 + /* "pysam/libcalignedsegment.pyx":524 * # if there is no sequence, compute length from cigar string * if end_offset == 0: - * end_offset = calculateQueryLength(src) # <<<<<<<<<<<<<< - * - * # walk backwards in cigar string + * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< + * op = cigar_p[k] & BAM_CIGAR_MASK + * if op == BAM_CMATCH or \ */ - __pyx_v_end_offset = __pyx_f_5pysam_18libcalignedsegment_calculateQueryLength(__pyx_v_src); + __pyx_t_3 = pysam_get_n_cigar(__pyx_v_src); + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) { - /* "pysam/libcalignedsegment.pyx":384 - * - * # if there is no sequence, compute length from cigar string - * if end_offset == 0: # <<<<<<<<<<<<<< - * end_offset = calculateQueryLength(src) - * + /* "pysam/libcalignedsegment.pyx":525 + * if end_offset == 0: + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< + * if op == BAM_CMATCH or \ + * op == BAM_CINS or \ */ - } + __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); - /* "pysam/libcalignedsegment.pyx":388 - * - * # walk backwards in cigar string - * if pysam_get_n_cigar(src) > 1: # <<<<<<<<<<<<<< - * cigar_p = pysam_bam_get_cigar(src); - * for k from pysam_get_n_cigar(src) > k >= 1: + /* "pysam/libcalignedsegment.pyx":526 + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK + * if op == BAM_CMATCH or \ # <<<<<<<<<<<<<< + * op == BAM_CINS or \ + * op == BAM_CEQUAL or \ */ - __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) > 1) != 0); - if (__pyx_t_2) { + __pyx_t_4 = ((__pyx_v_op == BAM_CMATCH) != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L7_bool_binop_done; + } - /* "pysam/libcalignedsegment.pyx":389 - * # walk backwards in cigar string - * if pysam_get_n_cigar(src) > 1: - * cigar_p = pysam_bam_get_cigar(src); # <<<<<<<<<<<<<< - * for k from pysam_get_n_cigar(src) > k >= 1: + /* "pysam/libcalignedsegment.pyx":527 + * op = cigar_p[k] & BAM_CIGAR_MASK + * if op == BAM_CMATCH or \ + * op == BAM_CINS or \ # <<<<<<<<<<<<<< + * op == BAM_CEQUAL or \ + * op == BAM_CDIFF or \ + */ + __pyx_t_4 = ((__pyx_v_op == BAM_CINS) != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L7_bool_binop_done; + } + + /* "pysam/libcalignedsegment.pyx":528 + * if op == BAM_CMATCH or \ + * op == BAM_CINS or \ + * op == BAM_CEQUAL or \ # <<<<<<<<<<<<<< + * op == BAM_CDIFF or \ + * (op == BAM_CSOFT_CLIP and end_offset == 0): + */ + __pyx_t_4 = ((__pyx_v_op == BAM_CEQUAL) != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L7_bool_binop_done; + } + + /* "pysam/libcalignedsegment.pyx":529 + * op == BAM_CINS or \ + * op == BAM_CEQUAL or \ + * op == BAM_CDIFF or \ # <<<<<<<<<<<<<< + * (op == BAM_CSOFT_CLIP and end_offset == 0): + * end_offset += cigar_p[k] >> BAM_CIGAR_SHIFT + */ + __pyx_t_4 = ((__pyx_v_op == BAM_CDIFF) != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L7_bool_binop_done; + } + + /* "pysam/libcalignedsegment.pyx":530 + * op == BAM_CEQUAL or \ + * op == BAM_CDIFF or \ + * (op == BAM_CSOFT_CLIP and end_offset == 0): # <<<<<<<<<<<<<< + * end_offset += cigar_p[k] >> BAM_CIGAR_SHIFT + * else: + */ + __pyx_t_4 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_4 = ((__pyx_v_end_offset == 0) != 0); + __pyx_t_2 = __pyx_t_4; + __pyx_L7_bool_binop_done:; + + /* "pysam/libcalignedsegment.pyx":526 + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK + * if op == BAM_CMATCH or \ # <<<<<<<<<<<<<< + * op == BAM_CINS or \ + * op == BAM_CEQUAL or \ + */ + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":531 + * op == BAM_CDIFF or \ + * (op == BAM_CSOFT_CLIP and end_offset == 0): + * end_offset += cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< + * else: + * # walk backwards in cigar string + */ + __pyx_v_end_offset = (__pyx_v_end_offset + ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); + + /* "pysam/libcalignedsegment.pyx":526 + * for k from 0 <= k < pysam_get_n_cigar(src): * op = cigar_p[k] & BAM_CIGAR_MASK + * if op == BAM_CMATCH or \ # <<<<<<<<<<<<<< + * op == BAM_CINS or \ + * op == BAM_CEQUAL or \ */ - __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); + } + } + + /* "pysam/libcalignedsegment.pyx":523 + * + * # if there is no sequence, compute length from cigar string + * if end_offset == 0: # <<<<<<<<<<<<<< + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK + */ + goto __pyx_L3; + } - /* "pysam/libcalignedsegment.pyx":390 - * if pysam_get_n_cigar(src) > 1: - * cigar_p = pysam_bam_get_cigar(src); + /* "pysam/libcalignedsegment.pyx":534 + * else: + * # walk backwards in cigar string * for k from pysam_get_n_cigar(src) > k >= 1: # <<<<<<<<<<<<<< * op = cigar_p[k] & BAM_CIGAR_MASK * if op == BAM_CHARD_CLIP: */ + /*else*/ { for (__pyx_v_k = pysam_get_n_cigar(__pyx_v_src)-1 + 1; __pyx_v_k >= 1 + 1; ) { __pyx_v_k--; - /* "pysam/libcalignedsegment.pyx":391 - * cigar_p = pysam_bam_get_cigar(src); + /* "pysam/libcalignedsegment.pyx":535 + * # walk backwards in cigar string * for k from pysam_get_n_cigar(src) > k >= 1: * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< * if op == BAM_CHARD_CLIP: - * if end_offset != 0 and end_offset != src.core.l_qseq: + * if end_offset != src.core.l_qseq: */ __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); - /* "pysam/libcalignedsegment.pyx":392 + /* "pysam/libcalignedsegment.pyx":536 * for k from pysam_get_n_cigar(src) > k >= 1: * op = cigar_p[k] & BAM_CIGAR_MASK * if op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< - * if end_offset != 0 and end_offset != src.core.l_qseq: - * PyErr_SetString(ValueError, + * if end_offset != src.core.l_qseq: + * raise ValueError('Invalid clipping in CIGAR string') */ __pyx_t_2 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0); if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":393 + /* "pysam/libcalignedsegment.pyx":537 * op = cigar_p[k] & BAM_CIGAR_MASK * if op == BAM_CHARD_CLIP: - * if end_offset != 0 and end_offset != src.core.l_qseq: # <<<<<<<<<<<<<< - * PyErr_SetString(ValueError, - * 'Invalid clipping in CIGAR string') + * if end_offset != src.core.l_qseq: # <<<<<<<<<<<<<< + * raise ValueError('Invalid clipping in CIGAR string') + * elif op == BAM_CSOFT_CLIP: */ - __pyx_t_3 = ((__pyx_v_end_offset != 0) != 0); - if (__pyx_t_3) { - } else { - __pyx_t_2 = __pyx_t_3; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_3 = ((__pyx_v_end_offset != __pyx_v_src->core.l_qseq) != 0); - __pyx_t_2 = __pyx_t_3; - __pyx_L9_bool_binop_done:; - if (__pyx_t_2) { + __pyx_t_2 = ((__pyx_v_end_offset != __pyx_v_src->core.l_qseq) != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcalignedsegment.pyx":394 + /* "pysam/libcalignedsegment.pyx":538 * if op == BAM_CHARD_CLIP: - * if end_offset != 0 and end_offset != src.core.l_qseq: - * PyErr_SetString(ValueError, # <<<<<<<<<<<<<< - * 'Invalid clipping in CIGAR string') - * return -1 - */ - PyErr_SetString(__pyx_builtin_ValueError, ((char *)"Invalid clipping in CIGAR string")); - - /* "pysam/libcalignedsegment.pyx":396 - * PyErr_SetString(ValueError, - * 'Invalid clipping in CIGAR string') - * return -1 # <<<<<<<<<<<<<< + * if end_offset != src.core.l_qseq: + * raise ValueError('Invalid clipping in CIGAR string') # <<<<<<<<<<<<<< * elif op == BAM_CSOFT_CLIP: * end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT */ - __pyx_r = -1; - goto __pyx_L0; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 538, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 538, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":393 + /* "pysam/libcalignedsegment.pyx":537 * op = cigar_p[k] & BAM_CIGAR_MASK * if op == BAM_CHARD_CLIP: - * if end_offset != 0 and end_offset != src.core.l_qseq: # <<<<<<<<<<<<<< - * PyErr_SetString(ValueError, - * 'Invalid clipping in CIGAR string') + * if end_offset != src.core.l_qseq: # <<<<<<<<<<<<<< + * raise ValueError('Invalid clipping in CIGAR string') + * elif op == BAM_CSOFT_CLIP: */ } - /* "pysam/libcalignedsegment.pyx":392 + /* "pysam/libcalignedsegment.pyx":536 * for k from pysam_get_n_cigar(src) > k >= 1: * op = cigar_p[k] & BAM_CIGAR_MASK * if op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< - * if end_offset != 0 and end_offset != src.core.l_qseq: - * PyErr_SetString(ValueError, + * if end_offset != src.core.l_qseq: + * raise ValueError('Invalid clipping in CIGAR string') */ - goto __pyx_L7; + goto __pyx_L15; } - /* "pysam/libcalignedsegment.pyx":397 - * 'Invalid clipping in CIGAR string') - * return -1 + /* "pysam/libcalignedsegment.pyx":539 + * if end_offset != src.core.l_qseq: + * raise ValueError('Invalid clipping in CIGAR string') * elif op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< * end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT * else: @@ -7452,8 +9276,8 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(bam __pyx_t_2 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0); if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":398 - * return -1 + /* "pysam/libcalignedsegment.pyx":540 + * raise ValueError('Invalid clipping in CIGAR string') * elif op == BAM_CSOFT_CLIP: * end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< * else: @@ -7461,17 +9285,17 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(bam */ __pyx_v_end_offset = (__pyx_v_end_offset - ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); - /* "pysam/libcalignedsegment.pyx":397 - * 'Invalid clipping in CIGAR string') - * return -1 + /* "pysam/libcalignedsegment.pyx":539 + * if end_offset != src.core.l_qseq: + * raise ValueError('Invalid clipping in CIGAR string') * elif op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< * end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT * else: */ - goto __pyx_L7; + goto __pyx_L15; } - /* "pysam/libcalignedsegment.pyx":400 + /* "pysam/libcalignedsegment.pyx":542 * end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT * else: * break # <<<<<<<<<<<<<< @@ -7479,22 +9303,15 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(bam * return end_offset */ /*else*/ { - goto __pyx_L6_break; + goto __pyx_L14_break; } - __pyx_L7:; + __pyx_L15:; } - __pyx_L6_break:; - - /* "pysam/libcalignedsegment.pyx":388 - * - * # walk backwards in cigar string - * if pysam_get_n_cigar(src) > 1: # <<<<<<<<<<<<<< - * cigar_p = pysam_bam_get_cigar(src); - * for k from pysam_get_n_cigar(src) > k >= 1: - */ + __pyx_L14_break:; } + __pyx_L3:; - /* "pysam/libcalignedsegment.pyx":402 + /* "pysam/libcalignedsegment.pyx":544 * break * * return end_offset # <<<<<<<<<<<<<< @@ -7504,16 +9321,17 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(bam __pyx_r = __pyx_v_end_offset; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":378 + /* "pysam/libcalignedsegment.pyx":517 * * * cdef inline int32_t getQueryEnd(bam1_t *src) except -1: # <<<<<<<<<<<<<< - * cdef uint32_t * cigar_p - * cdef uint32_t k, op + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) + * cdef uint32_t end_offset = src.core.l_qseq */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("pysam.libcalignedsegment.getQueryEnd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -7522,7 +9340,7 @@ static CYTHON_INLINE int32_t __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(bam return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":405 +/* "pysam/libcalignedsegment.pyx":547 * * * cdef inline bytes getSequenceInRange(bam1_t *src, # <<<<<<<<<<<<<< @@ -7544,9 +9362,9 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getSequenceIn uint32_t __pyx_t_4; char const *__pyx_t_5; __Pyx_RefNannySetupContext("getSequenceInRange", 0); - __Pyx_TraceCall("getSequenceInRange", __pyx_f[0], 405, 0, __PYX_ERR(0, 405, __pyx_L1_error)); + __Pyx_TraceCall("getSequenceInRange", __pyx_f[0], 547, 0, __PYX_ERR(0, 547, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":415 + /* "pysam/libcalignedsegment.pyx":557 * cdef char * s * * if not src.core.l_qseq: # <<<<<<<<<<<<<< @@ -7556,7 +9374,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getSequenceIn __pyx_t_1 = ((!(__pyx_v_src->core.l_qseq != 0)) != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":416 + /* "pysam/libcalignedsegment.pyx":558 * * if not src.core.l_qseq: * return None # <<<<<<<<<<<<<< @@ -7567,7 +9385,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getSequenceIn __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":415 + /* "pysam/libcalignedsegment.pyx":557 * cdef char * s * * if not src.core.l_qseq: # <<<<<<<<<<<<<< @@ -7576,19 +9394,19 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getSequenceIn */ } - /* "pysam/libcalignedsegment.pyx":418 + /* "pysam/libcalignedsegment.pyx":560 * return None * * seq = PyBytes_FromStringAndSize(NULL, end - start) # <<<<<<<<<<<<<< * s = seq * p = pysam_bam_get_seq(src) */ - __pyx_t_2 = PyBytes_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 418, __pyx_L1_error) + __pyx_t_2 = PyBytes_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_seq = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignedsegment.pyx":419 + /* "pysam/libcalignedsegment.pyx":561 * * seq = PyBytes_FromStringAndSize(NULL, end - start) * s = seq # <<<<<<<<<<<<<< @@ -7597,12 +9415,12 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getSequenceIn */ if (unlikely(__pyx_v_seq == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 419, __pyx_L1_error) + __PYX_ERR(0, 561, __pyx_L1_error) } - __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v_seq); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 419, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v_seq); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 561, __pyx_L1_error) __pyx_v_s = ((char *)__pyx_t_3); - /* "pysam/libcalignedsegment.pyx":420 + /* "pysam/libcalignedsegment.pyx":562 * seq = PyBytes_FromStringAndSize(NULL, end - start) * s = seq * p = pysam_bam_get_seq(src) # <<<<<<<<<<<<<< @@ -7611,7 +9429,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getSequenceIn */ __pyx_v_p = pysam_bam_get_seq(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":422 + /* "pysam/libcalignedsegment.pyx":564 * p = pysam_bam_get_seq(src) * * for k from start <= k < end: # <<<<<<<<<<<<<< @@ -7621,7 +9439,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getSequenceIn __pyx_t_4 = __pyx_v_end; for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_4; __pyx_v_k++) { - /* "pysam/libcalignedsegment.pyx":425 + /* "pysam/libcalignedsegment.pyx":567 * # equivalent to seq_nt16_str[bam1_seqi(s, i)] (see bam.c) * # note: do not use string literal as it will be a python string * s[k-start] = seq_nt16_str[p[k/2] >> 4 * (1 - k%2) & 0xf] # <<<<<<<<<<<<<< @@ -7631,7 +9449,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getSequenceIn (__pyx_v_s[(__pyx_v_k - __pyx_v_start)]) = (seq_nt16_str[(((__pyx_v_p[__Pyx_div_long(__pyx_v_k, 2)]) >> (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2)))) & 0xf)]); } - /* "pysam/libcalignedsegment.pyx":427 + /* "pysam/libcalignedsegment.pyx":569 * s[k-start] = seq_nt16_str[p[k/2] >> 4 * (1 - k%2) & 0xf] * * return charptr_to_bytes(seq) # <<<<<<<<<<<<<< @@ -7641,16 +9459,16 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getSequenceIn __Pyx_XDECREF(__pyx_r); if (unlikely(__pyx_v_seq == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 427, __pyx_L1_error) + __PYX_ERR(0, 569, __pyx_L1_error) } - __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 427, __pyx_L1_error) - __pyx_t_2 = __pyx_f_5pysam_9libcutils_charptr_to_bytes(__pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 427, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 569, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_charptr_to_bytes(__pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 569, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":405 + /* "pysam/libcalignedsegment.pyx":547 * * * cdef inline bytes getSequenceInRange(bam1_t *src, # <<<<<<<<<<<<<< @@ -7671,7 +9489,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getSequenceIn return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":430 +/* "pysam/libcalignedsegment.pyx":572 * * * cdef inline object getQualitiesInRange(bam1_t *src, # <<<<<<<<<<<<<< @@ -7693,9 +9511,9 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getQualitiesI int __pyx_t_6; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("getQualitiesInRange", 0); - __Pyx_TraceCall("getQualitiesInRange", __pyx_f[0], 430, 0, __PYX_ERR(0, 430, __pyx_L1_error)); + __Pyx_TraceCall("getQualitiesInRange", __pyx_f[0], 572, 0, __PYX_ERR(0, 572, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":438 + /* "pysam/libcalignedsegment.pyx":580 * cdef uint32_t k * * p = pysam_bam_get_qual(src) # <<<<<<<<<<<<<< @@ -7704,7 +9522,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getQualitiesI */ __pyx_v_p = pysam_bam_get_qual(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":439 + /* "pysam/libcalignedsegment.pyx":581 * * p = pysam_bam_get_qual(src) * if p[0] == 0xff: # <<<<<<<<<<<<<< @@ -7714,7 +9532,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getQualitiesI __pyx_t_1 = (((__pyx_v_p[0]) == 0xff) != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":440 + /* "pysam/libcalignedsegment.pyx":582 * p = pysam_bam_get_qual(src) * if p[0] == 0xff: * return None # <<<<<<<<<<<<<< @@ -7725,7 +9543,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getQualitiesI __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":439 + /* "pysam/libcalignedsegment.pyx":581 * * p = pysam_bam_get_qual(src) * if p[0] == 0xff: # <<<<<<<<<<<<<< @@ -7734,19 +9552,19 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getQualitiesI */ } - /* "pysam/libcalignedsegment.pyx":443 + /* "pysam/libcalignedsegment.pyx":585 * * # 'B': unsigned char * cdef c_array.array result = array.array('B', [0]) # <<<<<<<<<<<<<< * c_array.resize(result, end - start) * */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 443, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 443, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 443, __pyx_L1_error) + __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); @@ -7766,7 +9584,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getQualitiesI #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_n_s_B, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 443, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 585, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -7775,14 +9593,14 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getQualitiesI #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_n_s_B, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 443, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 585, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else #endif { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 443, __pyx_L1_error) + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); if (__pyx_t_5) { __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; @@ -7793,25 +9611,25 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getQualitiesI __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3); __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 443, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 443, __pyx_L1_error) + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 585, __pyx_L1_error) __pyx_v_result = ((arrayobject *)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignedsegment.pyx":444 + /* "pysam/libcalignedsegment.pyx":586 * # 'B': unsigned char * cdef c_array.array result = array.array('B', [0]) * c_array.resize(result, end - start) # <<<<<<<<<<<<<< * * # copy data */ - __pyx_t_6 = resize(__pyx_v_result, (__pyx_v_end - __pyx_v_start)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 444, __pyx_L1_error) + __pyx_t_6 = resize(__pyx_v_result, (__pyx_v_end - __pyx_v_start)); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 586, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":447 + /* "pysam/libcalignedsegment.pyx":589 * * # copy data * memcpy(result.data.as_voidptr, &p[start], end - start) # <<<<<<<<<<<<<< @@ -7820,7 +9638,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getQualitiesI */ (void)(memcpy(__pyx_v_result->data.as_voidptr, ((void *)(&(__pyx_v_p[__pyx_v_start]))), (__pyx_v_end - __pyx_v_start))); - /* "pysam/libcalignedsegment.pyx":449 + /* "pysam/libcalignedsegment.pyx":591 * memcpy(result.data.as_voidptr, &p[start], end - start) * * return result # <<<<<<<<<<<<<< @@ -7832,7 +9650,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getQualitiesI __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":430 + /* "pysam/libcalignedsegment.pyx":572 * * * cdef inline object getQualitiesInRange(bam1_t *src, # <<<<<<<<<<<<<< @@ -7857,75 +9675,75 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_getQualitiesI return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":455 - * ## private factory methods +/* "pysam/libcalignedsegment.pyx":597 + * ## factory methods for instantiating extension classes * cdef class AlignedSegment - * cdef makeAlignedSegment(bam1_t * src, AlignmentFile alignment_file): # <<<<<<<<<<<<<< + * cdef AlignedSegment makeAlignedSegment(bam1_t *src, # <<<<<<<<<<<<<< + * AlignmentHeader header): * '''return an AlignedSegment object constructed from `src`''' - * # note that the following does not call __init__ */ -static PyObject *__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(bam1_t *__pyx_v_src, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_alignment_file) { +static struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(bam1_t *__pyx_v_src, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header) { struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_dest = 0; - PyObject *__pyx_r = NULL; + struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("makeAlignedSegment", 0); - __Pyx_TraceCall("makeAlignedSegment", __pyx_f[0], 455, 0, __PYX_ERR(0, 455, __pyx_L1_error)); + __Pyx_TraceCall("makeAlignedSegment", __pyx_f[0], 597, 0, __PYX_ERR(0, 597, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":458 + /* "pysam/libcalignedsegment.pyx":601 * '''return an AlignedSegment object constructed from `src`''' * # note that the following does not call __init__ * cdef AlignedSegment dest = AlignedSegment.__new__(AlignedSegment) # <<<<<<<<<<<<<< * dest._delegate = bam_dup1(src) - * dest._alignment_file = alignment_file + * dest.header = header */ - __pyx_t_1 = ((PyObject *)__pyx_tp_new_5pysam_18libcalignedsegment_AlignedSegment(((PyTypeObject *)__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 458, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_tp_new_5pysam_18libcalignedsegment_AlignedSegment(((PyTypeObject *)__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_v_dest = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":459 + /* "pysam/libcalignedsegment.pyx":602 * # note that the following does not call __init__ * cdef AlignedSegment dest = AlignedSegment.__new__(AlignedSegment) * dest._delegate = bam_dup1(src) # <<<<<<<<<<<<<< - * dest._alignment_file = alignment_file + * dest.header = header * return dest */ __pyx_v_dest->_delegate = bam_dup1(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":460 + /* "pysam/libcalignedsegment.pyx":603 * cdef AlignedSegment dest = AlignedSegment.__new__(AlignedSegment) * dest._delegate = bam_dup1(src) - * dest._alignment_file = alignment_file # <<<<<<<<<<<<<< + * dest.header = header # <<<<<<<<<<<<<< * return dest * */ - __Pyx_INCREF(((PyObject *)__pyx_v_alignment_file)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_alignment_file)); - __Pyx_GOTREF(__pyx_v_dest->_alignment_file); - __Pyx_DECREF(((PyObject *)__pyx_v_dest->_alignment_file)); - __pyx_v_dest->_alignment_file = __pyx_v_alignment_file; + __Pyx_INCREF(((PyObject *)__pyx_v_header)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_header)); + __Pyx_GOTREF(__pyx_v_dest->header); + __Pyx_DECREF(((PyObject *)__pyx_v_dest->header)); + __pyx_v_dest->header = __pyx_v_header; - /* "pysam/libcalignedsegment.pyx":461 + /* "pysam/libcalignedsegment.pyx":604 * dest._delegate = bam_dup1(src) - * dest._alignment_file = alignment_file + * dest.header = header * return dest # <<<<<<<<<<<<<< * * */ - __Pyx_XDECREF(__pyx_r); + __Pyx_XDECREF(((PyObject *)__pyx_r)); __Pyx_INCREF(((PyObject *)__pyx_v_dest)); - __pyx_r = ((PyObject *)__pyx_v_dest); + __pyx_r = __pyx_v_dest; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":455 - * ## private factory methods + /* "pysam/libcalignedsegment.pyx":597 + * ## factory methods for instantiating extension classes * cdef class AlignedSegment - * cdef makeAlignedSegment(bam1_t * src, AlignmentFile alignment_file): # <<<<<<<<<<<<<< + * cdef AlignedSegment makeAlignedSegment(bam1_t *src, # <<<<<<<<<<<<<< + * AlignmentHeader header): * '''return an AlignedSegment object constructed from `src`''' - * # note that the following does not call __init__ */ /* function exit code */ @@ -7935,65 +9753,66 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(bam1_t * __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_dest); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":465 +/* "pysam/libcalignedsegment.pyx":608 * * cdef class PileupColumn - * cdef makePileupColumn(bam_pileup1_t ** plp, int tid, int pos, # <<<<<<<<<<<<<< - * int n_pu, AlignmentFile alignment_file): - * '''return a PileupColumn object constructed from pileup in `plp` and + * cdef PileupColumn makePileupColumn(bam_pileup1_t ** plp, # <<<<<<<<<<<<<< + * int tid, + * int pos, */ -static PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupColumn(bam_pileup1_t **__pyx_v_plp, int __pyx_v_tid, int __pyx_v_pos, int __pyx_v_n_pu, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_alignment_file) { +static struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_f_5pysam_18libcalignedsegment_makePileupColumn(bam_pileup1_t **__pyx_v_plp, int __pyx_v_tid, int __pyx_v_pos, int __pyx_v_n_pu, uint32_t __pyx_v_min_base_quality, char *__pyx_v_reference_sequence, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header) { struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_dest = 0; - PyObject *__pyx_r = NULL; + struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; __Pyx_RefNannySetupContext("makePileupColumn", 0); - __Pyx_TraceCall("makePileupColumn", __pyx_f[0], 465, 0, __PYX_ERR(0, 465, __pyx_L1_error)); + __Pyx_TraceCall("makePileupColumn", __pyx_f[0], 608, 0, __PYX_ERR(0, 608, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":472 + /* "pysam/libcalignedsegment.pyx":620 * ''' * # note that the following does not call __init__ * cdef PileupColumn dest = PileupColumn.__new__(PileupColumn) # <<<<<<<<<<<<<< - * dest._alignment_file = alignment_file + * dest.header = header * dest.plp = plp */ - __pyx_t_1 = ((PyObject *)__pyx_tp_new_5pysam_18libcalignedsegment_PileupColumn(((PyTypeObject *)__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 472, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_tp_new_5pysam_18libcalignedsegment_PileupColumn(((PyTypeObject *)__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 620, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_v_dest = ((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":473 + /* "pysam/libcalignedsegment.pyx":621 * # note that the following does not call __init__ * cdef PileupColumn dest = PileupColumn.__new__(PileupColumn) - * dest._alignment_file = alignment_file # <<<<<<<<<<<<<< + * dest.header = header # <<<<<<<<<<<<<< * dest.plp = plp * dest.tid = tid */ - __Pyx_INCREF(((PyObject *)__pyx_v_alignment_file)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_alignment_file)); - __Pyx_GOTREF(__pyx_v_dest->_alignment_file); - __Pyx_DECREF(((PyObject *)__pyx_v_dest->_alignment_file)); - __pyx_v_dest->_alignment_file = __pyx_v_alignment_file; + __Pyx_INCREF(((PyObject *)__pyx_v_header)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_header)); + __Pyx_GOTREF(__pyx_v_dest->header); + __Pyx_DECREF(((PyObject *)__pyx_v_dest->header)); + __pyx_v_dest->header = __pyx_v_header; - /* "pysam/libcalignedsegment.pyx":474 + /* "pysam/libcalignedsegment.pyx":622 * cdef PileupColumn dest = PileupColumn.__new__(PileupColumn) - * dest._alignment_file = alignment_file + * dest.header = header * dest.plp = plp # <<<<<<<<<<<<<< * dest.tid = tid * dest.pos = pos */ __pyx_v_dest->plp = __pyx_v_plp; - /* "pysam/libcalignedsegment.pyx":475 - * dest._alignment_file = alignment_file + /* "pysam/libcalignedsegment.pyx":623 + * dest.header = header * dest.plp = plp * dest.tid = tid # <<<<<<<<<<<<<< * dest.pos = pos @@ -8001,42 +9820,101 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupColumn(bam_pileup */ __pyx_v_dest->tid = __pyx_v_tid; - /* "pysam/libcalignedsegment.pyx":476 + /* "pysam/libcalignedsegment.pyx":624 * dest.plp = plp * dest.tid = tid * dest.pos = pos # <<<<<<<<<<<<<< * dest.n_pu = n_pu - * return dest + * dest.min_base_quality = min_base_quality */ __pyx_v_dest->pos = __pyx_v_pos; - /* "pysam/libcalignedsegment.pyx":477 + /* "pysam/libcalignedsegment.pyx":625 * dest.tid = tid * dest.pos = pos * dest.n_pu = n_pu # <<<<<<<<<<<<<< - * return dest - * + * dest.min_base_quality = min_base_quality + * dest.reference_sequence = reference_sequence */ __pyx_v_dest->n_pu = __pyx_v_n_pu; - /* "pysam/libcalignedsegment.pyx":478 + /* "pysam/libcalignedsegment.pyx":626 * dest.pos = pos * dest.n_pu = n_pu + * dest.min_base_quality = min_base_quality # <<<<<<<<<<<<<< + * dest.reference_sequence = reference_sequence + * dest.buf = calloc(MAX_PILEUP_BUFFER_SIZE, sizeof(uint8_t)) + */ + __pyx_v_dest->min_base_quality = __pyx_v_min_base_quality; + + /* "pysam/libcalignedsegment.pyx":627 + * dest.n_pu = n_pu + * dest.min_base_quality = min_base_quality + * dest.reference_sequence = reference_sequence # <<<<<<<<<<<<<< + * dest.buf = calloc(MAX_PILEUP_BUFFER_SIZE, sizeof(uint8_t)) + * if dest.buf == NULL: + */ + __pyx_v_dest->reference_sequence = __pyx_v_reference_sequence; + + /* "pysam/libcalignedsegment.pyx":628 + * dest.min_base_quality = min_base_quality + * dest.reference_sequence = reference_sequence + * dest.buf = calloc(MAX_PILEUP_BUFFER_SIZE, sizeof(uint8_t)) # <<<<<<<<<<<<<< + * if dest.buf == NULL: + * raise MemoryError("could not allocate pileup buffer") + */ + __pyx_v_dest->buf = ((uint8_t *)calloc(__pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE, (sizeof(uint8_t)))); + + /* "pysam/libcalignedsegment.pyx":629 + * dest.reference_sequence = reference_sequence + * dest.buf = calloc(MAX_PILEUP_BUFFER_SIZE, sizeof(uint8_t)) + * if dest.buf == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate pileup buffer") + * + */ + __pyx_t_2 = ((__pyx_v_dest->buf == NULL) != 0); + if (unlikely(__pyx_t_2)) { + + /* "pysam/libcalignedsegment.pyx":630 + * dest.buf = calloc(MAX_PILEUP_BUFFER_SIZE, sizeof(uint8_t)) + * if dest.buf == NULL: + * raise MemoryError("could not allocate pileup buffer") # <<<<<<<<<<<<<< + * + * return dest + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 630, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 630, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":629 + * dest.reference_sequence = reference_sequence + * dest.buf = calloc(MAX_PILEUP_BUFFER_SIZE, sizeof(uint8_t)) + * if dest.buf == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate pileup buffer") + * + */ + } + + /* "pysam/libcalignedsegment.pyx":632 + * raise MemoryError("could not allocate pileup buffer") + * * return dest # <<<<<<<<<<<<<< * - * cdef class PileupRead + * */ - __Pyx_XDECREF(__pyx_r); + __Pyx_XDECREF(((PyObject *)__pyx_r)); __Pyx_INCREF(((PyObject *)__pyx_v_dest)); - __pyx_r = ((PyObject *)__pyx_v_dest); + __pyx_r = __pyx_v_dest; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":465 + /* "pysam/libcalignedsegment.pyx":608 * * cdef class PileupColumn - * cdef makePileupColumn(bam_pileup1_t ** plp, int tid, int pos, # <<<<<<<<<<<<<< - * int n_pu, AlignmentFile alignment_file): - * '''return a PileupColumn object constructed from pileup in `plp` and + * cdef PileupColumn makePileupColumn(bam_pileup1_t ** plp, # <<<<<<<<<<<<<< + * int tid, + * int pos, */ /* function exit code */ @@ -8046,23 +9924,23 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupColumn(bam_pileup __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_dest); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":481 +/* "pysam/libcalignedsegment.pyx":636 * * cdef class PileupRead - * cdef inline makePileupRead(bam_pileup1_t * src, AlignmentFile alignment_file): # <<<<<<<<<<<<<< + * cdef PileupRead makePileupRead(bam_pileup1_t *src, # <<<<<<<<<<<<<< + * AlignmentHeader header): * '''return a PileupRead object construted from a bam_pileup1_t * object.''' - * cdef PileupRead dest = PileupRead.__new__(PileupRead) */ -static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupRead(bam_pileup1_t *__pyx_v_src, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_alignment_file) { +static struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_f_5pysam_18libcalignedsegment_makePileupRead(bam_pileup1_t *__pyx_v_src, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header) { struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_dest = 0; - PyObject *__pyx_r = NULL; + struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -8070,39 +9948,38 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupRea int __pyx_t_3; uint32_t __pyx_t_4; __Pyx_RefNannySetupContext("makePileupRead", 0); - __Pyx_TraceCall("makePileupRead", __pyx_f[0], 481, 0, __PYX_ERR(0, 481, __pyx_L1_error)); + __Pyx_TraceCall("makePileupRead", __pyx_f[0], 636, 0, __PYX_ERR(0, 636, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":483 - * cdef inline makePileupRead(bam_pileup1_t * src, AlignmentFile alignment_file): + /* "pysam/libcalignedsegment.pyx":640 * '''return a PileupRead object construted from a bam_pileup1_t * object.''' + * # note that the following does not call __init__ * cdef PileupRead dest = PileupRead.__new__(PileupRead) # <<<<<<<<<<<<<< - * dest._alignment = makeAlignedSegment(src.b, alignment_file) + * dest._alignment = makeAlignedSegment(src.b, header) * dest._qpos = src.qpos */ - __pyx_t_1 = ((PyObject *)__pyx_tp_new_5pysam_18libcalignedsegment_PileupRead(((PyTypeObject *)__pyx_ptype_5pysam_18libcalignedsegment_PileupRead), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 483, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_tp_new_5pysam_18libcalignedsegment_PileupRead(((PyTypeObject *)__pyx_ptype_5pysam_18libcalignedsegment_PileupRead), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 640, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_v_dest = ((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":484 - * '''return a PileupRead object construted from a bam_pileup1_t * object.''' + /* "pysam/libcalignedsegment.pyx":641 + * # note that the following does not call __init__ * cdef PileupRead dest = PileupRead.__new__(PileupRead) - * dest._alignment = makeAlignedSegment(src.b, alignment_file) # <<<<<<<<<<<<<< + * dest._alignment = makeAlignedSegment(src.b, header) # <<<<<<<<<<<<<< * dest._qpos = src.qpos * dest._indel = src.indel */ - __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_src->b, __pyx_v_alignment_file); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 484, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_src->b, __pyx_v_header)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 641, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(0, 484, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_dest->_alignment); __Pyx_DECREF(((PyObject *)__pyx_v_dest->_alignment)); __pyx_v_dest->_alignment = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":485 + /* "pysam/libcalignedsegment.pyx":642 * cdef PileupRead dest = PileupRead.__new__(PileupRead) - * dest._alignment = makeAlignedSegment(src.b, alignment_file) + * dest._alignment = makeAlignedSegment(src.b, header) * dest._qpos = src.qpos # <<<<<<<<<<<<<< * dest._indel = src.indel * dest._level = src.level @@ -8110,8 +9987,8 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupRea __pyx_t_2 = __pyx_v_src->qpos; __pyx_v_dest->_qpos = __pyx_t_2; - /* "pysam/libcalignedsegment.pyx":486 - * dest._alignment = makeAlignedSegment(src.b, alignment_file) + /* "pysam/libcalignedsegment.pyx":643 + * dest._alignment = makeAlignedSegment(src.b, header) * dest._qpos = src.qpos * dest._indel = src.indel # <<<<<<<<<<<<<< * dest._level = src.level @@ -8120,7 +9997,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupRea __pyx_t_3 = __pyx_v_src->indel; __pyx_v_dest->_indel = __pyx_t_3; - /* "pysam/libcalignedsegment.pyx":487 + /* "pysam/libcalignedsegment.pyx":644 * dest._qpos = src.qpos * dest._indel = src.indel * dest._level = src.level # <<<<<<<<<<<<<< @@ -8130,7 +10007,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupRea __pyx_t_3 = __pyx_v_src->level; __pyx_v_dest->_level = __pyx_t_3; - /* "pysam/libcalignedsegment.pyx":488 + /* "pysam/libcalignedsegment.pyx":645 * dest._indel = src.indel * dest._level = src.level * dest._is_del = src.is_del # <<<<<<<<<<<<<< @@ -8140,7 +10017,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupRea __pyx_t_4 = __pyx_v_src->is_del; __pyx_v_dest->_is_del = __pyx_t_4; - /* "pysam/libcalignedsegment.pyx":489 + /* "pysam/libcalignedsegment.pyx":646 * dest._level = src.level * dest._is_del = src.is_del * dest._is_head = src.is_head # <<<<<<<<<<<<<< @@ -8150,7 +10027,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupRea __pyx_t_4 = __pyx_v_src->is_head; __pyx_v_dest->_is_head = __pyx_t_4; - /* "pysam/libcalignedsegment.pyx":490 + /* "pysam/libcalignedsegment.pyx":647 * dest._is_del = src.is_del * dest._is_head = src.is_head * dest._is_tail = src.is_tail # <<<<<<<<<<<<<< @@ -8160,7 +10037,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupRea __pyx_t_4 = __pyx_v_src->is_tail; __pyx_v_dest->_is_tail = __pyx_t_4; - /* "pysam/libcalignedsegment.pyx":491 + /* "pysam/libcalignedsegment.pyx":648 * dest._is_head = src.is_head * dest._is_tail = src.is_tail * dest._is_refskip = src.is_refskip # <<<<<<<<<<<<<< @@ -8170,24 +10047,24 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupRea __pyx_t_4 = __pyx_v_src->is_refskip; __pyx_v_dest->_is_refskip = __pyx_t_4; - /* "pysam/libcalignedsegment.pyx":492 + /* "pysam/libcalignedsegment.pyx":649 * dest._is_tail = src.is_tail * dest._is_refskip = src.is_refskip * return dest # <<<<<<<<<<<<<< * * */ - __Pyx_XDECREF(__pyx_r); + __Pyx_XDECREF(((PyObject *)__pyx_r)); __Pyx_INCREF(((PyObject *)__pyx_v_dest)); - __pyx_r = ((PyObject *)__pyx_v_dest); + __pyx_r = __pyx_v_dest; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":481 + /* "pysam/libcalignedsegment.pyx":636 * * cdef class PileupRead - * cdef inline makePileupRead(bam_pileup1_t * src, AlignmentFile alignment_file): # <<<<<<<<<<<<<< + * cdef PileupRead makePileupRead(bam_pileup1_t *src, # <<<<<<<<<<<<<< + * AlignmentHeader header): * '''return a PileupRead object construted from a bam_pileup1_t * object.''' - * cdef PileupRead dest = PileupRead.__new__(PileupRead) */ /* function exit code */ @@ -8197,55 +10074,55 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_makePileupRea __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_dest); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":495 +/* "pysam/libcalignedsegment.pyx":652 * * - * cdef inline uint32_t get_alignment_length(bam1_t * src): # <<<<<<<<<<<<<< - * cdef int k = 0 + * cdef inline uint32_t get_alignment_length(bam1_t *src): # <<<<<<<<<<<<<< + * cdef uint32_t k = 0 * cdef uint32_t l = 0 */ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_length(bam1_t *__pyx_v_src) { - int __pyx_v_k; + uint32_t __pyx_v_k; uint32_t __pyx_v_l; uint32_t *__pyx_v_cigar_p; int __pyx_v_op; - int __pyx_v_n; + uint32_t __pyx_v_n; uint32_t __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; - int __pyx_t_2; + uint32_t __pyx_t_2; int __pyx_t_3; __Pyx_RefNannySetupContext("get_alignment_length", 0); - __Pyx_TraceCall("get_alignment_length", __pyx_f[0], 495, 0, __PYX_ERR(0, 495, __pyx_L1_error)); + __Pyx_TraceCall("get_alignment_length", __pyx_f[0], 652, 0, __PYX_ERR(0, 652, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":496 + /* "pysam/libcalignedsegment.pyx":653 * - * cdef inline uint32_t get_alignment_length(bam1_t * src): - * cdef int k = 0 # <<<<<<<<<<<<<< + * cdef inline uint32_t get_alignment_length(bam1_t *src): + * cdef uint32_t k = 0 # <<<<<<<<<<<<<< * cdef uint32_t l = 0 * if src == NULL: */ __pyx_v_k = 0; - /* "pysam/libcalignedsegment.pyx":497 - * cdef inline uint32_t get_alignment_length(bam1_t * src): - * cdef int k = 0 + /* "pysam/libcalignedsegment.pyx":654 + * cdef inline uint32_t get_alignment_length(bam1_t *src): + * cdef uint32_t k = 0 * cdef uint32_t l = 0 # <<<<<<<<<<<<<< * if src == NULL: * return 0 */ __pyx_v_l = 0; - /* "pysam/libcalignedsegment.pyx":498 - * cdef int k = 0 + /* "pysam/libcalignedsegment.pyx":655 + * cdef uint32_t k = 0 * cdef uint32_t l = 0 * if src == NULL: # <<<<<<<<<<<<<< * return 0 @@ -8254,7 +10131,7 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ __pyx_t_1 = ((__pyx_v_src == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":499 + /* "pysam/libcalignedsegment.pyx":656 * cdef uint32_t l = 0 * if src == NULL: * return 0 # <<<<<<<<<<<<<< @@ -8264,8 +10141,8 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":498 - * cdef int k = 0 + /* "pysam/libcalignedsegment.pyx":655 + * cdef uint32_t k = 0 * cdef uint32_t l = 0 * if src == NULL: # <<<<<<<<<<<<<< * return 0 @@ -8273,7 +10150,7 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ */ } - /* "pysam/libcalignedsegment.pyx":500 + /* "pysam/libcalignedsegment.pyx":657 * if src == NULL: * return 0 * cdef uint32_t * cigar_p = bam_get_cigar(src) # <<<<<<<<<<<<<< @@ -8282,7 +10159,7 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ */ __pyx_v_cigar_p = bam_get_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":501 + /* "pysam/libcalignedsegment.pyx":658 * return 0 * cdef uint32_t * cigar_p = bam_get_cigar(src) * if cigar_p == NULL: # <<<<<<<<<<<<<< @@ -8292,17 +10169,17 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ __pyx_t_1 = ((__pyx_v_cigar_p == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":502 + /* "pysam/libcalignedsegment.pyx":659 * cdef uint32_t * cigar_p = bam_get_cigar(src) * if cigar_p == NULL: * return 0 # <<<<<<<<<<<<<< * cdef int op - * cdef int n = pysam_get_n_cigar(src) + * cdef uint32_t n = pysam_get_n_cigar(src) */ __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":501 + /* "pysam/libcalignedsegment.pyx":658 * return 0 * cdef uint32_t * cigar_p = bam_get_cigar(src) * if cigar_p == NULL: # <<<<<<<<<<<<<< @@ -8311,18 +10188,18 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ */ } - /* "pysam/libcalignedsegment.pyx":504 + /* "pysam/libcalignedsegment.pyx":661 * return 0 * cdef int op - * cdef int n = pysam_get_n_cigar(src) # <<<<<<<<<<<<<< + * cdef uint32_t n = pysam_get_n_cigar(src) # <<<<<<<<<<<<<< * for k from 0 <= k < n: * op = cigar_p[k] & BAM_CIGAR_MASK */ __pyx_v_n = pysam_get_n_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":505 + /* "pysam/libcalignedsegment.pyx":662 * cdef int op - * cdef int n = pysam_get_n_cigar(src) + * cdef uint32_t n = pysam_get_n_cigar(src) * for k from 0 <= k < n: # <<<<<<<<<<<<<< * op = cigar_p[k] & BAM_CIGAR_MASK * if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP: @@ -8330,8 +10207,8 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ __pyx_t_2 = __pyx_v_n; for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_2; __pyx_v_k++) { - /* "pysam/libcalignedsegment.pyx":506 - * cdef int n = pysam_get_n_cigar(src) + /* "pysam/libcalignedsegment.pyx":663 + * cdef uint32_t n = pysam_get_n_cigar(src) * for k from 0 <= k < n: * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< * if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP: @@ -8339,7 +10216,7 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ */ __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); - /* "pysam/libcalignedsegment.pyx":507 + /* "pysam/libcalignedsegment.pyx":664 * for k from 0 <= k < n: * op = cigar_p[k] & BAM_CIGAR_MASK * if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< @@ -8357,7 +10234,7 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ __pyx_L8_bool_binop_done:; if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":508 + /* "pysam/libcalignedsegment.pyx":665 * op = cigar_p[k] & BAM_CIGAR_MASK * if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP: * continue # <<<<<<<<<<<<<< @@ -8366,7 +10243,7 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ */ goto __pyx_L5_continue; - /* "pysam/libcalignedsegment.pyx":507 + /* "pysam/libcalignedsegment.pyx":664 * for k from 0 <= k < n: * op = cigar_p[k] & BAM_CIGAR_MASK * if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< @@ -8375,7 +10252,7 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ */ } - /* "pysam/libcalignedsegment.pyx":509 + /* "pysam/libcalignedsegment.pyx":666 * if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP: * continue * l += cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< @@ -8386,7 +10263,7 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ __pyx_L5_continue:; } - /* "pysam/libcalignedsegment.pyx":510 + /* "pysam/libcalignedsegment.pyx":667 * continue * l += cigar_p[k] >> BAM_CIGAR_SHIFT * return l # <<<<<<<<<<<<<< @@ -8396,11 +10273,11 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ __pyx_r = __pyx_v_l; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":495 + /* "pysam/libcalignedsegment.pyx":652 * * - * cdef inline uint32_t get_alignment_length(bam1_t * src): # <<<<<<<<<<<<<< - * cdef int k = 0 + * cdef inline uint32_t get_alignment_length(bam1_t *src): # <<<<<<<<<<<<<< + * cdef uint32_t k = 0 * cdef uint32_t l = 0 */ @@ -8414,7 +10291,275 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":514 +/* "pysam/libcalignedsegment.pyx":670 + * + * + * cdef inline uint32_t get_md_reference_length(char * md_tag): # <<<<<<<<<<<<<< + * cdef int l = 0 + * cdef int md_idx = 0 + */ + +static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_md_reference_length(char *__pyx_v_md_tag) { + int __pyx_v_l; + int __pyx_v_md_idx; + int __pyx_v_nmatches; + uint32_t __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + __Pyx_RefNannySetupContext("get_md_reference_length", 0); + __Pyx_TraceCall("get_md_reference_length", __pyx_f[0], 670, 0, __PYX_ERR(0, 670, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":671 + * + * cdef inline uint32_t get_md_reference_length(char * md_tag): + * cdef int l = 0 # <<<<<<<<<<<<<< + * cdef int md_idx = 0 + * cdef int nmatches = 0 + */ + __pyx_v_l = 0; + + /* "pysam/libcalignedsegment.pyx":672 + * cdef inline uint32_t get_md_reference_length(char * md_tag): + * cdef int l = 0 + * cdef int md_idx = 0 # <<<<<<<<<<<<<< + * cdef int nmatches = 0 + * + */ + __pyx_v_md_idx = 0; + + /* "pysam/libcalignedsegment.pyx":673 + * cdef int l = 0 + * cdef int md_idx = 0 + * cdef int nmatches = 0 # <<<<<<<<<<<<<< + * + * while md_tag[md_idx] != 0: + */ + __pyx_v_nmatches = 0; + + /* "pysam/libcalignedsegment.pyx":675 + * cdef int nmatches = 0 + * + * while md_tag[md_idx] != 0: # <<<<<<<<<<<<<< + * if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57: + * nmatches *= 10 + */ + while (1) { + __pyx_t_1 = (((__pyx_v_md_tag[__pyx_v_md_idx]) != 0) != 0); + if (!__pyx_t_1) break; + + /* "pysam/libcalignedsegment.pyx":676 + * + * while md_tag[md_idx] != 0: + * if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57: # <<<<<<<<<<<<<< + * nmatches *= 10 + * nmatches += md_tag[md_idx] - 48 + */ + __pyx_t_2 = (((__pyx_v_md_tag[__pyx_v_md_idx]) >= 48) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L6_bool_binop_done; + } + __pyx_t_2 = (((__pyx_v_md_tag[__pyx_v_md_idx]) <= 57) != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L6_bool_binop_done:; + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":677 + * while md_tag[md_idx] != 0: + * if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57: + * nmatches *= 10 # <<<<<<<<<<<<<< + * nmatches += md_tag[md_idx] - 48 + * md_idx += 1 + */ + __pyx_v_nmatches = (__pyx_v_nmatches * 10); + + /* "pysam/libcalignedsegment.pyx":678 + * if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57: + * nmatches *= 10 + * nmatches += md_tag[md_idx] - 48 # <<<<<<<<<<<<<< + * md_idx += 1 + * continue + */ + __pyx_v_nmatches = (__pyx_v_nmatches + ((__pyx_v_md_tag[__pyx_v_md_idx]) - 48)); + + /* "pysam/libcalignedsegment.pyx":679 + * nmatches *= 10 + * nmatches += md_tag[md_idx] - 48 + * md_idx += 1 # <<<<<<<<<<<<<< + * continue + * else: + */ + __pyx_v_md_idx = (__pyx_v_md_idx + 1); + + /* "pysam/libcalignedsegment.pyx":680 + * nmatches += md_tag[md_idx] - 48 + * md_idx += 1 + * continue # <<<<<<<<<<<<<< + * else: + * l += nmatches + */ + goto __pyx_L3_continue; + + /* "pysam/libcalignedsegment.pyx":676 + * + * while md_tag[md_idx] != 0: + * if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57: # <<<<<<<<<<<<<< + * nmatches *= 10 + * nmatches += md_tag[md_idx] - 48 + */ + } + + /* "pysam/libcalignedsegment.pyx":682 + * continue + * else: + * l += nmatches # <<<<<<<<<<<<<< + * nmatches = 0 + * if md_tag[md_idx] == '^': + */ + /*else*/ { + __pyx_v_l = (__pyx_v_l + __pyx_v_nmatches); + + /* "pysam/libcalignedsegment.pyx":683 + * else: + * l += nmatches + * nmatches = 0 # <<<<<<<<<<<<<< + * if md_tag[md_idx] == '^': + * md_idx += 1 + */ + __pyx_v_nmatches = 0; + + /* "pysam/libcalignedsegment.pyx":684 + * l += nmatches + * nmatches = 0 + * if md_tag[md_idx] == '^': # <<<<<<<<<<<<<< + * md_idx += 1 + * while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: + */ + __pyx_t_1 = (((__pyx_v_md_tag[__pyx_v_md_idx]) == '^') != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":685 + * nmatches = 0 + * if md_tag[md_idx] == '^': + * md_idx += 1 # <<<<<<<<<<<<<< + * while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: + * md_idx += 1 + */ + __pyx_v_md_idx = (__pyx_v_md_idx + 1); + + /* "pysam/libcalignedsegment.pyx":686 + * if md_tag[md_idx] == '^': + * md_idx += 1 + * while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: # <<<<<<<<<<<<<< + * md_idx += 1 + * l += 1 + */ + while (1) { + __pyx_t_2 = (((__pyx_v_md_tag[__pyx_v_md_idx]) >= 65) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L11_bool_binop_done; + } + __pyx_t_2 = (((__pyx_v_md_tag[__pyx_v_md_idx]) <= 90) != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L11_bool_binop_done:; + if (!__pyx_t_1) break; + + /* "pysam/libcalignedsegment.pyx":687 + * md_idx += 1 + * while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: + * md_idx += 1 # <<<<<<<<<<<<<< + * l += 1 + * else: + */ + __pyx_v_md_idx = (__pyx_v_md_idx + 1); + + /* "pysam/libcalignedsegment.pyx":688 + * while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: + * md_idx += 1 + * l += 1 # <<<<<<<<<<<<<< + * else: + * md_idx += 1 + */ + __pyx_v_l = (__pyx_v_l + 1); + } + + /* "pysam/libcalignedsegment.pyx":684 + * l += nmatches + * nmatches = 0 + * if md_tag[md_idx] == '^': # <<<<<<<<<<<<<< + * md_idx += 1 + * while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: + */ + goto __pyx_L8; + } + + /* "pysam/libcalignedsegment.pyx":690 + * l += 1 + * else: + * md_idx += 1 # <<<<<<<<<<<<<< + * l += 1 + * + */ + /*else*/ { + __pyx_v_md_idx = (__pyx_v_md_idx + 1); + + /* "pysam/libcalignedsegment.pyx":691 + * else: + * md_idx += 1 + * l += 1 # <<<<<<<<<<<<<< + * + * l += nmatches + */ + __pyx_v_l = (__pyx_v_l + 1); + } + __pyx_L8:; + } + __pyx_L3_continue:; + } + + /* "pysam/libcalignedsegment.pyx":693 + * l += 1 + * + * l += nmatches # <<<<<<<<<<<<<< + * return l + * + */ + __pyx_v_l = (__pyx_v_l + __pyx_v_nmatches); + + /* "pysam/libcalignedsegment.pyx":694 + * + * l += nmatches + * return l # <<<<<<<<<<<<<< + * + * # TODO: avoid string copying for getSequenceInRange, reconstituneSequenceFromMD, ... + */ + __pyx_r = __pyx_v_l; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":670 + * + * + * cdef inline uint32_t get_md_reference_length(char * md_tag): # <<<<<<<<<<<<<< + * cdef int l = 0 + * cdef int md_idx = 0 + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("pysam.libcalignedsegment.get_md_reference_length", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":697 * * # TODO: avoid string copying for getSequenceInRange, reconstituneSequenceFromMD, ... * cdef inline bytes build_alignment_sequence(bam1_t * src): # <<<<<<<<<<<<<< @@ -8423,6 +10568,7 @@ static CYTHON_INLINE uint32_t __pyx_f_5pysam_18libcalignedsegment_get_alignment_ */ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignment_sequence(bam1_t *__pyx_v_src) { + uint8_t *__pyx_v_md_tag_ptr; uint32_t __pyx_v_start; uint32_t __pyx_v_end; PyObject *__pyx_v_r = NULL; @@ -8438,10 +10584,11 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme int __pyx_v_s_idx; uint32_t __pyx_v_max_len; char *__pyx_v_s; - uint8_t *__pyx_v_md_tag_ptr; - PyObject *__pyx_v_seq = NULL; char *__pyx_v_md_tag; int __pyx_v_md_idx; + int __pyx_v_insertions; + uint32_t __pyx_v_md_len; + PyObject *__pyx_v_seq = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -8450,14 +10597,19 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme PyObject *__pyx_t_3 = NULL; char *__pyx_t_4; PyObject *__pyx_t_5 = NULL; - uint16_t __pyx_t_6; + uint32_t __pyx_t_6; int __pyx_t_7; uint32_t __pyx_t_8; - int __pyx_t_9; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + int __pyx_t_13; + PyObject *__pyx_t_14 = NULL; __Pyx_RefNannySetupContext("build_alignment_sequence", 0); - __Pyx_TraceCall("build_alignment_sequence", __pyx_f[0], 514, 0, __PYX_ERR(0, 514, __pyx_L1_error)); + __Pyx_TraceCall("build_alignment_sequence", __pyx_f[0], 697, 0, __PYX_ERR(0, 697, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":535 + /* "pysam/libcalignedsegment.pyx":718 * * """ * if src == NULL: # <<<<<<<<<<<<<< @@ -8467,18 +10619,18 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_1 = ((__pyx_v_src == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":536 + /* "pysam/libcalignedsegment.pyx":719 * """ * if src == NULL: * return None # <<<<<<<<<<<<<< * - * cdef uint32_t start = getQueryStart(src) + * cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD") */ __Pyx_XDECREF(__pyx_r); __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":535 + /* "pysam/libcalignedsegment.pyx":718 * * """ * if src == NULL: # <<<<<<<<<<<<<< @@ -8487,39 +10639,78 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ } - /* "pysam/libcalignedsegment.pyx":538 + /* "pysam/libcalignedsegment.pyx":721 + * return None + * + * cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD") # <<<<<<<<<<<<<< + * if md_tag_ptr == NULL: + * return None + */ + __pyx_v_md_tag_ptr = bam_aux_get(__pyx_v_src, ((char const *)"MD")); + + /* "pysam/libcalignedsegment.pyx":722 + * + * cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD") + * if md_tag_ptr == NULL: # <<<<<<<<<<<<<< + * return None + * + */ + __pyx_t_1 = ((__pyx_v_md_tag_ptr == NULL) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":723 + * cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD") + * if md_tag_ptr == NULL: + * return None # <<<<<<<<<<<<<< + * + * cdef uint32_t start = getQueryStart(src) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":722 + * + * cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD") + * if md_tag_ptr == NULL: # <<<<<<<<<<<<<< + * return None + * + */ + } + + /* "pysam/libcalignedsegment.pyx":725 * return None * * cdef uint32_t start = getQueryStart(src) # <<<<<<<<<<<<<< * cdef uint32_t end = getQueryEnd(src) * # get read sequence, taking into account soft-clipping */ - __pyx_t_2 = __pyx_f_5pysam_18libcalignedsegment_getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_2 == ((int32_t)-1))) __PYX_ERR(0, 538, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_18libcalignedsegment_getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_2 == ((int32_t)-1))) __PYX_ERR(0, 725, __pyx_L1_error) __pyx_v_start = __pyx_t_2; - /* "pysam/libcalignedsegment.pyx":539 + /* "pysam/libcalignedsegment.pyx":726 * * cdef uint32_t start = getQueryStart(src) * cdef uint32_t end = getQueryEnd(src) # <<<<<<<<<<<<<< * # get read sequence, taking into account soft-clipping * r = getSequenceInRange(src, start, end) */ - __pyx_t_2 = __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_2 == ((int32_t)-1))) __PYX_ERR(0, 539, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_2 == ((int32_t)-1))) __PYX_ERR(0, 726, __pyx_L1_error) __pyx_v_end = __pyx_t_2; - /* "pysam/libcalignedsegment.pyx":541 + /* "pysam/libcalignedsegment.pyx":728 * cdef uint32_t end = getQueryEnd(src) * # get read sequence, taking into account soft-clipping * r = getSequenceInRange(src, start, end) # <<<<<<<<<<<<<< * cdef char * read_sequence = r * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) */ - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getSequenceInRange(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 541, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getSequenceInRange(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 728, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_r = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":542 + /* "pysam/libcalignedsegment.pyx":729 * # get read sequence, taking into account soft-clipping * r = getSequenceInRange(src, start, end) * cdef char * read_sequence = r # <<<<<<<<<<<<<< @@ -8528,12 +10719,12 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ if (unlikely(__pyx_v_r == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 542, __pyx_L1_error) + __PYX_ERR(0, 729, __pyx_L1_error) } - __pyx_t_4 = __Pyx_PyBytes_AsWritableString(__pyx_v_r); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 542, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyBytes_AsWritableString(__pyx_v_r); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 729, __pyx_L1_error) __pyx_v_read_sequence = __pyx_t_4; - /* "pysam/libcalignedsegment.pyx":543 + /* "pysam/libcalignedsegment.pyx":730 * r = getSequenceInRange(src, start, end) * cdef char * read_sequence = r * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< @@ -8542,7 +10733,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":544 + /* "pysam/libcalignedsegment.pyx":731 * cdef char * read_sequence = r * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) * if cigar_p == NULL: # <<<<<<<<<<<<<< @@ -8552,7 +10743,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_1 = ((__pyx_v_cigar_p == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":545 + /* "pysam/libcalignedsegment.pyx":732 * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) * if cigar_p == NULL: * return None # <<<<<<<<<<<<<< @@ -8563,7 +10754,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":544 + /* "pysam/libcalignedsegment.pyx":731 * cdef char * read_sequence = r * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) * if cigar_p == NULL: # <<<<<<<<<<<<<< @@ -8572,7 +10763,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ } - /* "pysam/libcalignedsegment.pyx":547 + /* "pysam/libcalignedsegment.pyx":734 * return None * * cdef uint32_t r_idx = 0 # <<<<<<<<<<<<<< @@ -8581,7 +10772,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_r_idx = 0; - /* "pysam/libcalignedsegment.pyx":550 + /* "pysam/libcalignedsegment.pyx":737 * cdef int op * cdef uint32_t k, i, l, x * cdef int nmatches = 0 # <<<<<<<<<<<<<< @@ -8590,7 +10781,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_nmatches = 0; - /* "pysam/libcalignedsegment.pyx":551 + /* "pysam/libcalignedsegment.pyx":738 * cdef uint32_t k, i, l, x * cdef int nmatches = 0 * cdef int s_idx = 0 # <<<<<<<<<<<<<< @@ -8599,7 +10790,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_s_idx = 0; - /* "pysam/libcalignedsegment.pyx":553 + /* "pysam/libcalignedsegment.pyx":740 * cdef int s_idx = 0 * * cdef uint32_t max_len = get_alignment_length(src) # <<<<<<<<<<<<<< @@ -8608,7 +10799,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_max_len = __pyx_f_5pysam_18libcalignedsegment_get_alignment_length(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":554 + /* "pysam/libcalignedsegment.pyx":741 * * cdef uint32_t max_len = get_alignment_length(src) * if max_len == 0: # <<<<<<<<<<<<<< @@ -8618,20 +10809,20 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_1 = ((__pyx_v_max_len == 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignedsegment.pyx":555 + /* "pysam/libcalignedsegment.pyx":742 * cdef uint32_t max_len = get_alignment_length(src) * if max_len == 0: * raise ValueError("could not determine alignment length") # <<<<<<<<<<<<<< * * cdef char * s = calloc(max_len + 1, sizeof(char)) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 555, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 742, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 555, __pyx_L1_error) + __PYX_ERR(0, 742, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":554 + /* "pysam/libcalignedsegment.pyx":741 * * cdef uint32_t max_len = get_alignment_length(src) * if max_len == 0: # <<<<<<<<<<<<<< @@ -8640,7 +10831,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ } - /* "pysam/libcalignedsegment.pyx":557 + /* "pysam/libcalignedsegment.pyx":744 * raise ValueError("could not determine alignment length") * * cdef char * s = calloc(max_len + 1, sizeof(char)) # <<<<<<<<<<<<<< @@ -8649,54 +10840,54 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_s = ((char *)calloc((__pyx_v_max_len + 1), (sizeof(char)))); - /* "pysam/libcalignedsegment.pyx":558 + /* "pysam/libcalignedsegment.pyx":745 * * cdef char * s = calloc(max_len + 1, sizeof(char)) * if s == NULL: # <<<<<<<<<<<<<< * raise ValueError( - * "could not allocated sequence of length %i" % max_len) + * "could not allocate sequence of length %i" % max_len) */ __pyx_t_1 = ((__pyx_v_s == NULL) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignedsegment.pyx":560 + /* "pysam/libcalignedsegment.pyx":747 * if s == NULL: * raise ValueError( - * "could not allocated sequence of length %i" % max_len) # <<<<<<<<<<<<<< + * "could not allocate sequence of length %i" % max_len) # <<<<<<<<<<<<<< * * for k from 0 <= k < pysam_get_n_cigar(src): */ - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_max_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 560, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_max_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 747, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_could_not_allocated_sequence_of, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 560, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_could_not_allocate_sequence_of_l, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 747, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":559 + /* "pysam/libcalignedsegment.pyx":746 * cdef char * s = calloc(max_len + 1, sizeof(char)) * if s == NULL: * raise ValueError( # <<<<<<<<<<<<<< - * "could not allocated sequence of length %i" % max_len) + * "could not allocate sequence of length %i" % max_len) * */ - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 559, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 746, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 559, __pyx_L1_error) + __PYX_ERR(0, 746, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":558 + /* "pysam/libcalignedsegment.pyx":745 * * cdef char * s = calloc(max_len + 1, sizeof(char)) * if s == NULL: # <<<<<<<<<<<<<< * raise ValueError( - * "could not allocated sequence of length %i" % max_len) + * "could not allocate sequence of length %i" % max_len) */ } - /* "pysam/libcalignedsegment.pyx":562 - * "could not allocated sequence of length %i" % max_len) + /* "pysam/libcalignedsegment.pyx":749 + * "could not allocate sequence of length %i" % max_len) * * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< * op = cigar_p[k] & BAM_CIGAR_MASK @@ -8705,7 +10896,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_6 = pysam_get_n_cigar(__pyx_v_src); for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) { - /* "pysam/libcalignedsegment.pyx":563 + /* "pysam/libcalignedsegment.pyx":750 * * for k from 0 <= k < pysam_get_n_cigar(src): * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< @@ -8714,7 +10905,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); - /* "pysam/libcalignedsegment.pyx":564 + /* "pysam/libcalignedsegment.pyx":751 * for k from 0 <= k < pysam_get_n_cigar(src): * op = cigar_p[k] & BAM_CIGAR_MASK * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< @@ -8723,7 +10914,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT); - /* "pysam/libcalignedsegment.pyx":565 + /* "pysam/libcalignedsegment.pyx":752 * op = cigar_p[k] & BAM_CIGAR_MASK * l = cigar_p[k] >> BAM_CIGAR_SHIFT * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: # <<<<<<<<<<<<<< @@ -8734,20 +10925,20 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme if (!__pyx_t_7) { } else { __pyx_t_1 = __pyx_t_7; - goto __pyx_L10_bool_binop_done; + goto __pyx_L11_bool_binop_done; } __pyx_t_7 = ((__pyx_v_op == BAM_CEQUAL) != 0); if (!__pyx_t_7) { } else { __pyx_t_1 = __pyx_t_7; - goto __pyx_L10_bool_binop_done; + goto __pyx_L11_bool_binop_done; } __pyx_t_7 = ((__pyx_v_op == BAM_CDIFF) != 0); __pyx_t_1 = __pyx_t_7; - __pyx_L10_bool_binop_done:; + __pyx_L11_bool_binop_done:; if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":566 + /* "pysam/libcalignedsegment.pyx":753 * l = cigar_p[k] >> BAM_CIGAR_SHIFT * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: * for i from 0 <= i < l: # <<<<<<<<<<<<<< @@ -8757,7 +10948,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_8 = __pyx_v_l; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":567 + /* "pysam/libcalignedsegment.pyx":754 * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: * for i from 0 <= i < l: * s[s_idx] = read_sequence[r_idx] # <<<<<<<<<<<<<< @@ -8766,7 +10957,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ (__pyx_v_s[__pyx_v_s_idx]) = (__pyx_v_read_sequence[__pyx_v_r_idx]); - /* "pysam/libcalignedsegment.pyx":568 + /* "pysam/libcalignedsegment.pyx":755 * for i from 0 <= i < l: * s[s_idx] = read_sequence[r_idx] * r_idx += 1 # <<<<<<<<<<<<<< @@ -8775,7 +10966,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_r_idx = (__pyx_v_r_idx + 1); - /* "pysam/libcalignedsegment.pyx":569 + /* "pysam/libcalignedsegment.pyx":756 * s[s_idx] = read_sequence[r_idx] * r_idx += 1 * s_idx += 1 # <<<<<<<<<<<<<< @@ -8785,17 +10976,17 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_v_s_idx = (__pyx_v_s_idx + 1); } - /* "pysam/libcalignedsegment.pyx":565 + /* "pysam/libcalignedsegment.pyx":752 * op = cigar_p[k] & BAM_CIGAR_MASK * l = cigar_p[k] >> BAM_CIGAR_SHIFT * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: # <<<<<<<<<<<<<< * for i from 0 <= i < l: * s[s_idx] = read_sequence[r_idx] */ - goto __pyx_L9; + goto __pyx_L10; } - /* "pysam/libcalignedsegment.pyx":570 + /* "pysam/libcalignedsegment.pyx":757 * r_idx += 1 * s_idx += 1 * elif op == BAM_CDEL: # <<<<<<<<<<<<<< @@ -8805,7 +10996,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_1 = ((__pyx_v_op == BAM_CDEL) != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":571 + /* "pysam/libcalignedsegment.pyx":758 * s_idx += 1 * elif op == BAM_CDEL: * for i from 0 <= i < l: # <<<<<<<<<<<<<< @@ -8815,7 +11006,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_8 = __pyx_v_l; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":572 + /* "pysam/libcalignedsegment.pyx":759 * elif op == BAM_CDEL: * for i from 0 <= i < l: * s[s_idx] = '-' # <<<<<<<<<<<<<< @@ -8824,7 +11015,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ (__pyx_v_s[__pyx_v_s_idx]) = '-'; - /* "pysam/libcalignedsegment.pyx":573 + /* "pysam/libcalignedsegment.pyx":760 * for i from 0 <= i < l: * s[s_idx] = '-' * s_idx += 1 # <<<<<<<<<<<<<< @@ -8834,17 +11025,17 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_v_s_idx = (__pyx_v_s_idx + 1); } - /* "pysam/libcalignedsegment.pyx":570 + /* "pysam/libcalignedsegment.pyx":757 * r_idx += 1 * s_idx += 1 * elif op == BAM_CDEL: # <<<<<<<<<<<<<< * for i from 0 <= i < l: * s[s_idx] = '-' */ - goto __pyx_L9; + goto __pyx_L10; } - /* "pysam/libcalignedsegment.pyx":574 + /* "pysam/libcalignedsegment.pyx":761 * s[s_idx] = '-' * s_idx += 1 * elif op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< @@ -8853,10 +11044,10 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_t_1 = ((__pyx_v_op == BAM_CREF_SKIP) != 0); if (__pyx_t_1) { - goto __pyx_L9; + goto __pyx_L10; } - /* "pysam/libcalignedsegment.pyx":576 + /* "pysam/libcalignedsegment.pyx":763 * elif op == BAM_CREF_SKIP: * pass * elif op == BAM_CINS: # <<<<<<<<<<<<<< @@ -8866,7 +11057,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_1 = ((__pyx_v_op == BAM_CINS) != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":577 + /* "pysam/libcalignedsegment.pyx":764 * pass * elif op == BAM_CINS: * for i from 0 <= i < l: # <<<<<<<<<<<<<< @@ -8876,7 +11067,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_8 = __pyx_v_l; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":579 + /* "pysam/libcalignedsegment.pyx":766 * for i from 0 <= i < l: * # encode insertions into reference as lowercase * s[s_idx] = read_sequence[r_idx] + 32 # <<<<<<<<<<<<<< @@ -8885,7 +11076,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ (__pyx_v_s[__pyx_v_s_idx]) = ((__pyx_v_read_sequence[__pyx_v_r_idx]) + 32); - /* "pysam/libcalignedsegment.pyx":580 + /* "pysam/libcalignedsegment.pyx":767 * # encode insertions into reference as lowercase * s[s_idx] = read_sequence[r_idx] + 32 * r_idx += 1 # <<<<<<<<<<<<<< @@ -8894,7 +11085,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_r_idx = (__pyx_v_r_idx + 1); - /* "pysam/libcalignedsegment.pyx":581 + /* "pysam/libcalignedsegment.pyx":768 * s[s_idx] = read_sequence[r_idx] + 32 * r_idx += 1 * s_idx += 1 # <<<<<<<<<<<<<< @@ -8904,17 +11095,17 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_v_s_idx = (__pyx_v_s_idx + 1); } - /* "pysam/libcalignedsegment.pyx":576 + /* "pysam/libcalignedsegment.pyx":763 * elif op == BAM_CREF_SKIP: * pass * elif op == BAM_CINS: # <<<<<<<<<<<<<< * for i from 0 <= i < l: * # encode insertions into reference as lowercase */ - goto __pyx_L9; + goto __pyx_L10; } - /* "pysam/libcalignedsegment.pyx":582 + /* "pysam/libcalignedsegment.pyx":769 * r_idx += 1 * s_idx += 1 * elif op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< @@ -8923,10 +11114,10 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_t_1 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0); if (__pyx_t_1) { - goto __pyx_L9; + goto __pyx_L10; } - /* "pysam/libcalignedsegment.pyx":584 + /* "pysam/libcalignedsegment.pyx":771 * elif op == BAM_CSOFT_CLIP: * pass * elif op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< @@ -8935,10 +11126,10 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_t_1 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0); if (__pyx_t_1) { - goto __pyx_L9; + goto __pyx_L10; } - /* "pysam/libcalignedsegment.pyx":586 + /* "pysam/libcalignedsegment.pyx":773 * elif op == BAM_CHARD_CLIP: * pass # advances neither * elif op == BAM_CPAD: # <<<<<<<<<<<<<< @@ -8948,20 +11139,20 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_1 = ((__pyx_v_op == BAM_CPAD) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignedsegment.pyx":587 + /* "pysam/libcalignedsegment.pyx":774 * pass # advances neither * elif op == BAM_CPAD: * raise NotImplementedError( # <<<<<<<<<<<<<< * "Padding (BAM_CPAD, 6) is currently not supported. " * "Please implement. Sorry about that.") */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 587, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 774, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 587, __pyx_L1_error) + __PYX_ERR(0, 774, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":586 + /* "pysam/libcalignedsegment.pyx":773 * elif op == BAM_CHARD_CLIP: * pass # advances neither * elif op == BAM_CPAD: # <<<<<<<<<<<<<< @@ -8969,100 +11160,226 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme * "Padding (BAM_CPAD, 6) is currently not supported. " */ } - __pyx_L9:; + __pyx_L10:; } - /* "pysam/libcalignedsegment.pyx":591 + /* "pysam/libcalignedsegment.pyx":778 * "Please implement. Sorry about that.") * - * cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD") # <<<<<<<<<<<<<< - * if md_tag_ptr == NULL: - * seq = PyBytes_FromStringAndSize(s, s_idx) + * cdef char * md_tag = bam_aux2Z(md_tag_ptr) # <<<<<<<<<<<<<< + * cdef int md_idx = 0 + * s_idx = 0 */ - __pyx_v_md_tag_ptr = bam_aux_get(__pyx_v_src, ((char const *)"MD")); + __pyx_v_md_tag = ((char *)bam_aux2Z(__pyx_v_md_tag_ptr)); - /* "pysam/libcalignedsegment.pyx":592 + /* "pysam/libcalignedsegment.pyx":779 + * + * cdef char * md_tag = bam_aux2Z(md_tag_ptr) + * cdef int md_idx = 0 # <<<<<<<<<<<<<< + * s_idx = 0 * - * cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD") - * if md_tag_ptr == NULL: # <<<<<<<<<<<<<< - * seq = PyBytes_FromStringAndSize(s, s_idx) - * free(s) */ - __pyx_t_1 = ((__pyx_v_md_tag_ptr == NULL) != 0); - if (__pyx_t_1) { + __pyx_v_md_idx = 0; - /* "pysam/libcalignedsegment.pyx":593 - * cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD") - * if md_tag_ptr == NULL: - * seq = PyBytes_FromStringAndSize(s, s_idx) # <<<<<<<<<<<<<< - * free(s) - * return seq + /* "pysam/libcalignedsegment.pyx":780 + * cdef char * md_tag = bam_aux2Z(md_tag_ptr) + * cdef int md_idx = 0 + * s_idx = 0 # <<<<<<<<<<<<<< + * + * # Check if MD tag is valid by matching CIGAR length to MD tag defined length */ - __pyx_t_3 = PyBytes_FromStringAndSize(__pyx_v_s, __pyx_v_s_idx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 593, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_seq = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_v_s_idx = 0; - /* "pysam/libcalignedsegment.pyx":594 - * if md_tag_ptr == NULL: - * seq = PyBytes_FromStringAndSize(s, s_idx) - * free(s) # <<<<<<<<<<<<<< - * return seq + /* "pysam/libcalignedsegment.pyx":785 + * # Insertions would be in addition to what is described by MD, so we calculate + * # the number of insertions seperately. + * cdef int insertions = 0 # <<<<<<<<<<<<<< * + * while s[s_idx] != 0: */ - free(__pyx_v_s); + __pyx_v_insertions = 0; - /* "pysam/libcalignedsegment.pyx":595 - * seq = PyBytes_FromStringAndSize(s, s_idx) - * free(s) - * return seq # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":787 + * cdef int insertions = 0 * - * cdef char * md_tag = bam_aux2Z(md_tag_ptr) + * while s[s_idx] != 0: # <<<<<<<<<<<<<< + * if s[s_idx] >= 'a': + * insertions += 1 */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_seq); - __pyx_r = __pyx_v_seq; - goto __pyx_L0; + while (1) { + __pyx_t_1 = (((__pyx_v_s[__pyx_v_s_idx]) != 0) != 0); + if (!__pyx_t_1) break; - /* "pysam/libcalignedsegment.pyx":592 + /* "pysam/libcalignedsegment.pyx":788 * - * cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD") - * if md_tag_ptr == NULL: # <<<<<<<<<<<<<< - * seq = PyBytes_FromStringAndSize(s, s_idx) - * free(s) + * while s[s_idx] != 0: + * if s[s_idx] >= 'a': # <<<<<<<<<<<<<< + * insertions += 1 + * s_idx += 1 */ - } + __pyx_t_1 = (((__pyx_v_s[__pyx_v_s_idx]) >= 'a') != 0); + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":597 - * return seq - * - * cdef char * md_tag = bam_aux2Z(md_tag_ptr) # <<<<<<<<<<<<<< - * cdef int md_idx = 0 + /* "pysam/libcalignedsegment.pyx":789 + * while s[s_idx] != 0: + * if s[s_idx] >= 'a': + * insertions += 1 # <<<<<<<<<<<<<< + * s_idx += 1 * s_idx = 0 */ - __pyx_v_md_tag = ((char *)bam_aux2Z(__pyx_v_md_tag_ptr)); + __pyx_v_insertions = (__pyx_v_insertions + 1); - /* "pysam/libcalignedsegment.pyx":598 + /* "pysam/libcalignedsegment.pyx":788 * - * cdef char * md_tag = bam_aux2Z(md_tag_ptr) - * cdef int md_idx = 0 # <<<<<<<<<<<<<< + * while s[s_idx] != 0: + * if s[s_idx] >= 'a': # <<<<<<<<<<<<<< + * insertions += 1 + * s_idx += 1 + */ + } + + /* "pysam/libcalignedsegment.pyx":790 + * if s[s_idx] >= 'a': + * insertions += 1 + * s_idx += 1 # <<<<<<<<<<<<<< * s_idx = 0 * */ - __pyx_v_md_idx = 0; + __pyx_v_s_idx = (__pyx_v_s_idx + 1); + } - /* "pysam/libcalignedsegment.pyx":599 - * cdef char * md_tag = bam_aux2Z(md_tag_ptr) - * cdef int md_idx = 0 + /* "pysam/libcalignedsegment.pyx":791 + * insertions += 1 + * s_idx += 1 * s_idx = 0 # <<<<<<<<<<<<<< * - * while md_tag[md_idx] != 0: + * cdef uint32_t md_len = get_md_reference_length(md_tag) */ __pyx_v_s_idx = 0; - /* "pysam/libcalignedsegment.pyx":601 + /* "pysam/libcalignedsegment.pyx":793 * s_idx = 0 * + * cdef uint32_t md_len = get_md_reference_length(md_tag) # <<<<<<<<<<<<<< + * if md_len + insertions > max_len: + * raise AssertionError( + */ + __pyx_v_md_len = __pyx_f_5pysam_18libcalignedsegment_get_md_reference_length(__pyx_v_md_tag); + + /* "pysam/libcalignedsegment.pyx":794 + * + * cdef uint32_t md_len = get_md_reference_length(md_tag) + * if md_len + insertions > max_len: # <<<<<<<<<<<<<< + * raise AssertionError( + * "Invalid MD tag: MD length {} mismatch with CIGAR length {} and {} insertions".format( + */ + __pyx_t_1 = (((__pyx_v_md_len + __pyx_v_insertions) > __pyx_v_max_len) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcalignedsegment.pyx":796 + * if md_len + insertions > max_len: + * raise AssertionError( + * "Invalid MD tag: MD length {} mismatch with CIGAR length {} and {} insertions".format( # <<<<<<<<<<<<<< + * md_len, max_len, insertions)) + * + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_MD_tag_MD_length_mismatc, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 796, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + + /* "pysam/libcalignedsegment.pyx":797 + * raise AssertionError( + * "Invalid MD tag: MD length {} mismatch with CIGAR length {} and {} insertions".format( + * md_len, max_len, insertions)) # <<<<<<<<<<<<<< + * + * while md_tag[md_idx] != 0: + */ + __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_md_len); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 797, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = __Pyx_PyInt_From_uint32_t(__pyx_v_max_len); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 797, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_insertions); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 797, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = NULL; + __pyx_t_13 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_13 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[4] = {__pyx_t_12, __pyx_t_9, __pyx_t_10, __pyx_t_11}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 796, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[4] = {__pyx_t_12, __pyx_t_9, __pyx_t_10, __pyx_t_11}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 796, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + { + __pyx_t_14 = PyTuple_New(3+__pyx_t_13); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 796, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + if (__pyx_t_12) { + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_12); __pyx_t_12 = NULL; + } + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_13, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_13, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_14, 2+__pyx_t_13, __pyx_t_11); + __pyx_t_9 = 0; + __pyx_t_10 = 0; + __pyx_t_11 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_14, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 796, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pysam/libcalignedsegment.pyx":795 + * cdef uint32_t md_len = get_md_reference_length(md_tag) + * if md_len + insertions > max_len: + * raise AssertionError( # <<<<<<<<<<<<<< + * "Invalid MD tag: MD length {} mismatch with CIGAR length {} and {} insertions".format( + * md_len, max_len, insertions)) + */ + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_AssertionError, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 795, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 795, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":794 + * + * cdef uint32_t md_len = get_md_reference_length(md_tag) + * if md_len + insertions > max_len: # <<<<<<<<<<<<<< + * raise AssertionError( + * "Invalid MD tag: MD length {} mismatch with CIGAR length {} and {} insertions".format( + */ + } + + /* "pysam/libcalignedsegment.pyx":799 + * md_len, max_len, insertions)) + * * while md_tag[md_idx] != 0: # <<<<<<<<<<<<<< * # c is numerical * if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57: @@ -9071,7 +11388,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_1 = (((__pyx_v_md_tag[__pyx_v_md_idx]) != 0) != 0); if (!__pyx_t_1) break; - /* "pysam/libcalignedsegment.pyx":603 + /* "pysam/libcalignedsegment.pyx":801 * while md_tag[md_idx] != 0: * # c is numerical * if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57: # <<<<<<<<<<<<<< @@ -9082,14 +11399,14 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme if (__pyx_t_7) { } else { __pyx_t_1 = __pyx_t_7; - goto __pyx_L23_bool_binop_done; + goto __pyx_L27_bool_binop_done; } __pyx_t_7 = (((__pyx_v_md_tag[__pyx_v_md_idx]) <= 57) != 0); __pyx_t_1 = __pyx_t_7; - __pyx_L23_bool_binop_done:; + __pyx_L27_bool_binop_done:; if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":604 + /* "pysam/libcalignedsegment.pyx":802 * # c is numerical * if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57: * nmatches *= 10 # <<<<<<<<<<<<<< @@ -9098,7 +11415,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_nmatches = (__pyx_v_nmatches * 10); - /* "pysam/libcalignedsegment.pyx":605 + /* "pysam/libcalignedsegment.pyx":803 * if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57: * nmatches *= 10 * nmatches += md_tag[md_idx] - 48 # <<<<<<<<<<<<<< @@ -9107,7 +11424,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_nmatches = (__pyx_v_nmatches + ((__pyx_v_md_tag[__pyx_v_md_idx]) - 48)); - /* "pysam/libcalignedsegment.pyx":606 + /* "pysam/libcalignedsegment.pyx":804 * nmatches *= 10 * nmatches += md_tag[md_idx] - 48 * md_idx += 1 # <<<<<<<<<<<<<< @@ -9116,16 +11433,16 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_md_idx = (__pyx_v_md_idx + 1); - /* "pysam/libcalignedsegment.pyx":607 + /* "pysam/libcalignedsegment.pyx":805 * nmatches += md_tag[md_idx] - 48 * md_idx += 1 * continue # <<<<<<<<<<<<<< * else: * # save matches up to this point, skipping insertions */ - goto __pyx_L20_continue; + goto __pyx_L24_continue; - /* "pysam/libcalignedsegment.pyx":603 + /* "pysam/libcalignedsegment.pyx":801 * while md_tag[md_idx] != 0: * # c is numerical * if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57: # <<<<<<<<<<<<<< @@ -9134,7 +11451,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ } - /* "pysam/libcalignedsegment.pyx":610 + /* "pysam/libcalignedsegment.pyx":808 * else: * # save matches up to this point, skipping insertions * for x from 0 <= x < nmatches: # <<<<<<<<<<<<<< @@ -9142,10 +11459,10 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme * s_idx += 1 */ /*else*/ { - __pyx_t_9 = __pyx_v_nmatches; - for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_9; __pyx_v_x++) { + __pyx_t_13 = __pyx_v_nmatches; + for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_13; __pyx_v_x++) { - /* "pysam/libcalignedsegment.pyx":611 + /* "pysam/libcalignedsegment.pyx":809 * # save matches up to this point, skipping insertions * for x from 0 <= x < nmatches: * while s[s_idx] >= 'a': # <<<<<<<<<<<<<< @@ -9156,7 +11473,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_1 = (((__pyx_v_s[__pyx_v_s_idx]) >= 'a') != 0); if (!__pyx_t_1) break; - /* "pysam/libcalignedsegment.pyx":612 + /* "pysam/libcalignedsegment.pyx":810 * for x from 0 <= x < nmatches: * while s[s_idx] >= 'a': * s_idx += 1 # <<<<<<<<<<<<<< @@ -9166,7 +11483,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_v_s_idx = (__pyx_v_s_idx + 1); } - /* "pysam/libcalignedsegment.pyx":613 + /* "pysam/libcalignedsegment.pyx":811 * while s[s_idx] >= 'a': * s_idx += 1 * s_idx += 1 # <<<<<<<<<<<<<< @@ -9176,7 +11493,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_v_s_idx = (__pyx_v_s_idx + 1); } - /* "pysam/libcalignedsegment.pyx":614 + /* "pysam/libcalignedsegment.pyx":812 * s_idx += 1 * s_idx += 1 * while s[s_idx] >= 'a': # <<<<<<<<<<<<<< @@ -9187,7 +11504,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_1 = (((__pyx_v_s[__pyx_v_s_idx]) >= 'a') != 0); if (!__pyx_t_1) break; - /* "pysam/libcalignedsegment.pyx":615 + /* "pysam/libcalignedsegment.pyx":813 * s_idx += 1 * while s[s_idx] >= 'a': * s_idx += 1 # <<<<<<<<<<<<<< @@ -9197,7 +11514,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_v_s_idx = (__pyx_v_s_idx + 1); } - /* "pysam/libcalignedsegment.pyx":617 + /* "pysam/libcalignedsegment.pyx":815 * s_idx += 1 * * r_idx += nmatches # <<<<<<<<<<<<<< @@ -9206,7 +11523,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_r_idx = (__pyx_v_r_idx + __pyx_v_nmatches); - /* "pysam/libcalignedsegment.pyx":618 + /* "pysam/libcalignedsegment.pyx":816 * * r_idx += nmatches * nmatches = 0 # <<<<<<<<<<<<<< @@ -9215,7 +11532,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_nmatches = 0; - /* "pysam/libcalignedsegment.pyx":619 + /* "pysam/libcalignedsegment.pyx":817 * r_idx += nmatches * nmatches = 0 * if md_tag[md_idx] == '^': # <<<<<<<<<<<<<< @@ -9225,20 +11542,20 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_1 = (((__pyx_v_md_tag[__pyx_v_md_idx]) == '^') != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":620 + /* "pysam/libcalignedsegment.pyx":818 * nmatches = 0 * if md_tag[md_idx] == '^': * md_idx += 1 # <<<<<<<<<<<<<< * while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: - * assert s[s_idx] == '-' + * # assert s[s_idx] == '-' */ __pyx_v_md_idx = (__pyx_v_md_idx + 1); - /* "pysam/libcalignedsegment.pyx":621 + /* "pysam/libcalignedsegment.pyx":819 * if md_tag[md_idx] == '^': * md_idx += 1 * while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: # <<<<<<<<<<<<<< - * assert s[s_idx] == '-' + * # assert s[s_idx] == '-' * s[s_idx] = md_tag[md_idx] */ while (1) { @@ -9246,40 +11563,24 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme if (__pyx_t_7) { } else { __pyx_t_1 = __pyx_t_7; - goto __pyx_L34_bool_binop_done; + goto __pyx_L38_bool_binop_done; } __pyx_t_7 = (((__pyx_v_md_tag[__pyx_v_md_idx]) <= 90) != 0); __pyx_t_1 = __pyx_t_7; - __pyx_L34_bool_binop_done:; + __pyx_L38_bool_binop_done:; if (!__pyx_t_1) break; - /* "pysam/libcalignedsegment.pyx":622 - * md_idx += 1 - * while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: - * assert s[s_idx] == '-' # <<<<<<<<<<<<<< - * s[s_idx] = md_tag[md_idx] - * s_idx += 1 - */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - if (unlikely(!(((__pyx_v_s[__pyx_v_s_idx]) == '-') != 0))) { - PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 622, __pyx_L1_error) - } - } - #endif - - /* "pysam/libcalignedsegment.pyx":623 + /* "pysam/libcalignedsegment.pyx":821 * while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: - * assert s[s_idx] == '-' + * # assert s[s_idx] == '-' * s[s_idx] = md_tag[md_idx] # <<<<<<<<<<<<<< * s_idx += 1 * md_idx += 1 */ (__pyx_v_s[__pyx_v_s_idx]) = (__pyx_v_md_tag[__pyx_v_md_idx]); - /* "pysam/libcalignedsegment.pyx":624 - * assert s[s_idx] == '-' + /* "pysam/libcalignedsegment.pyx":822 + * # assert s[s_idx] == '-' * s[s_idx] = md_tag[md_idx] * s_idx += 1 # <<<<<<<<<<<<<< * md_idx += 1 @@ -9287,7 +11588,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_s_idx = (__pyx_v_s_idx + 1); - /* "pysam/libcalignedsegment.pyx":625 + /* "pysam/libcalignedsegment.pyx":823 * s[s_idx] = md_tag[md_idx] * s_idx += 1 * md_idx += 1 # <<<<<<<<<<<<<< @@ -9297,17 +11598,17 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_v_md_idx = (__pyx_v_md_idx + 1); } - /* "pysam/libcalignedsegment.pyx":619 + /* "pysam/libcalignedsegment.pyx":817 * r_idx += nmatches * nmatches = 0 * if md_tag[md_idx] == '^': # <<<<<<<<<<<<<< * md_idx += 1 * while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: */ - goto __pyx_L31; + goto __pyx_L35; } - /* "pysam/libcalignedsegment.pyx":628 + /* "pysam/libcalignedsegment.pyx":826 * else: * # save mismatch and change to lower case * s[s_idx] = md_tag[md_idx] + 32 # <<<<<<<<<<<<<< @@ -9317,7 +11618,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme /*else*/ { (__pyx_v_s[__pyx_v_s_idx]) = ((__pyx_v_md_tag[__pyx_v_md_idx]) + 32); - /* "pysam/libcalignedsegment.pyx":629 + /* "pysam/libcalignedsegment.pyx":827 * # save mismatch and change to lower case * s[s_idx] = md_tag[md_idx] + 32 * s_idx += 1 # <<<<<<<<<<<<<< @@ -9326,7 +11627,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_s_idx = (__pyx_v_s_idx + 1); - /* "pysam/libcalignedsegment.pyx":630 + /* "pysam/libcalignedsegment.pyx":828 * s[s_idx] = md_tag[md_idx] + 32 * s_idx += 1 * r_idx += 1 # <<<<<<<<<<<<<< @@ -9335,7 +11636,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_r_idx = (__pyx_v_r_idx + 1); - /* "pysam/libcalignedsegment.pyx":631 + /* "pysam/libcalignedsegment.pyx":829 * s_idx += 1 * r_idx += 1 * md_idx += 1 # <<<<<<<<<<<<<< @@ -9344,22 +11645,22 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ __pyx_v_md_idx = (__pyx_v_md_idx + 1); } - __pyx_L31:; + __pyx_L35:; } - __pyx_L20_continue:; + __pyx_L24_continue:; } - /* "pysam/libcalignedsegment.pyx":634 + /* "pysam/libcalignedsegment.pyx":832 * * # save matches up to this point, skipping insertions * for x from 0 <= x < nmatches: # <<<<<<<<<<<<<< * while s[s_idx] >= 'a': * s_idx += 1 */ - __pyx_t_9 = __pyx_v_nmatches; - for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_9; __pyx_v_x++) { + __pyx_t_13 = __pyx_v_nmatches; + for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_13; __pyx_v_x++) { - /* "pysam/libcalignedsegment.pyx":635 + /* "pysam/libcalignedsegment.pyx":833 * # save matches up to this point, skipping insertions * for x from 0 <= x < nmatches: * while s[s_idx] >= 'a': # <<<<<<<<<<<<<< @@ -9370,7 +11671,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_1 = (((__pyx_v_s[__pyx_v_s_idx]) >= 'a') != 0); if (!__pyx_t_1) break; - /* "pysam/libcalignedsegment.pyx":636 + /* "pysam/libcalignedsegment.pyx":834 * for x from 0 <= x < nmatches: * while s[s_idx] >= 'a': * s_idx += 1 # <<<<<<<<<<<<<< @@ -9380,7 +11681,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_v_s_idx = (__pyx_v_s_idx + 1); } - /* "pysam/libcalignedsegment.pyx":637 + /* "pysam/libcalignedsegment.pyx":835 * while s[s_idx] >= 'a': * s_idx += 1 * s_idx += 1 # <<<<<<<<<<<<<< @@ -9390,7 +11691,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_v_s_idx = (__pyx_v_s_idx + 1); } - /* "pysam/libcalignedsegment.pyx":638 + /* "pysam/libcalignedsegment.pyx":836 * s_idx += 1 * s_idx += 1 * while s[s_idx] >= 'a': # <<<<<<<<<<<<<< @@ -9401,7 +11702,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_t_1 = (((__pyx_v_s[__pyx_v_s_idx]) >= 'a') != 0); if (!__pyx_t_1) break; - /* "pysam/libcalignedsegment.pyx":639 + /* "pysam/libcalignedsegment.pyx":837 * s_idx += 1 * while s[s_idx] >= 'a': * s_idx += 1 # <<<<<<<<<<<<<< @@ -9411,19 +11712,19 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_v_s_idx = (__pyx_v_s_idx + 1); } - /* "pysam/libcalignedsegment.pyx":641 + /* "pysam/libcalignedsegment.pyx":839 * s_idx += 1 * * seq = PyBytes_FromStringAndSize(s, s_idx) # <<<<<<<<<<<<<< * free(s) * */ - __pyx_t_3 = PyBytes_FromStringAndSize(__pyx_v_s, __pyx_v_s_idx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 641, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_seq = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_5 = PyBytes_FromStringAndSize(__pyx_v_s, __pyx_v_s_idx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 839, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_v_seq = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; - /* "pysam/libcalignedsegment.pyx":642 + /* "pysam/libcalignedsegment.pyx":840 * * seq = PyBytes_FromStringAndSize(s, s_idx) * free(s) # <<<<<<<<<<<<<< @@ -9432,7 +11733,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme */ free(__pyx_v_s); - /* "pysam/libcalignedsegment.pyx":644 + /* "pysam/libcalignedsegment.pyx":842 * free(s) * * return seq # <<<<<<<<<<<<<< @@ -9444,7 +11745,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_r = __pyx_v_seq; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":514 + /* "pysam/libcalignedsegment.pyx":697 * * # TODO: avoid string copying for getSequenceInRange, reconstituneSequenceFromMD, ... * cdef inline bytes build_alignment_sequence(bam1_t * src): # <<<<<<<<<<<<<< @@ -9456,6 +11757,11 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_14); __Pyx_AddTraceback("pysam.libcalignedsegment.build_alignment_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; @@ -9467,1512 +11773,1288 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_alignme return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":667 +/* "pysam/libcalignedsegment.pyx":845 * - * # Now only called when instances are created from Python - * def __init__(self): # <<<<<<<<<<<<<< - * # see bam_init1 - * self._delegate = calloc(1, sizeof(bam1_t)) + * + * cdef inline bytes build_reference_sequence(bam1_t * src): # <<<<<<<<<<<<<< + * """return the reference sequence in the region that is covered by the + * alignment of the read to the reference. */ -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { - __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} - if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment___init__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment___init__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - int __pyx_r; +static CYTHON_INLINE PyObject *__pyx_f_5pysam_18libcalignedsegment_build_reference_sequence(bam1_t *__pyx_v_src) { + uint32_t __pyx_v_k; + CYTHON_UNUSED uint32_t __pyx_v_i; + uint32_t __pyx_v_l; + int __pyx_v_op; + int __pyx_v_s_idx; + PyObject *__pyx_v_ref_seq = NULL; + char *__pyx_v_s; + char *__pyx_v_cref_seq; + uint32_t *__pyx_v_cigar_p; + uint32_t __pyx_v_r_idx; + PyObject *__pyx_v_seq = NULL; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 667, 0, __PYX_ERR(0, 667, __pyx_L1_error)); + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + char *__pyx_t_6; + uint32_t __pyx_t_7; + uint32_t __pyx_t_8; + __Pyx_RefNannySetupContext("build_reference_sequence", 0); + __Pyx_TraceCall("build_reference_sequence", __pyx_f[0], 845, 0, __PYX_ERR(0, 845, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":669 - * def __init__(self): - * # see bam_init1 - * self._delegate = calloc(1, sizeof(bam1_t)) # <<<<<<<<<<<<<< - * # allocate some memory. If size is 0, calloc does not return a - * # pointer that can be passed to free() so allocate 40 bytes + /* "pysam/libcalignedsegment.pyx":854 + * cdef uint32_t k, i, l + * cdef int op + * cdef int s_idx = 0 # <<<<<<<<<<<<<< + * ref_seq = build_alignment_sequence(src) + * if ref_seq is None: */ - __pyx_v_self->_delegate = ((bam1_t *)calloc(1, (sizeof(bam1_t)))); + __pyx_v_s_idx = 0; - /* "pysam/libcalignedsegment.pyx":673 - * # pointer that can be passed to free() so allocate 40 bytes - * # for a new read - * self._delegate.m_data = 40 # <<<<<<<<<<<<<< - * self._delegate.data = calloc( - * self._delegate.m_data, 1) + /* "pysam/libcalignedsegment.pyx":855 + * cdef int op + * cdef int s_idx = 0 + * ref_seq = build_alignment_sequence(src) # <<<<<<<<<<<<<< + * if ref_seq is None: + * raise ValueError("MD tag not present") */ - __pyx_v_self->_delegate->m_data = 40; + __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_build_alignment_sequence(__pyx_v_src); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_ref_seq = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":674 - * # for a new read - * self._delegate.m_data = 40 - * self._delegate.data = calloc( # <<<<<<<<<<<<<< - * self._delegate.m_data, 1) - * self._delegate.l_data = 0 + /* "pysam/libcalignedsegment.pyx":856 + * cdef int s_idx = 0 + * ref_seq = build_alignment_sequence(src) + * if ref_seq is None: # <<<<<<<<<<<<<< + * raise ValueError("MD tag not present") + * */ - __pyx_v_self->_delegate->data = ((uint8_t *)calloc(__pyx_v_self->_delegate->m_data, 1)); + __pyx_t_2 = (__pyx_v_ref_seq == ((PyObject*)Py_None)); + __pyx_t_3 = (__pyx_t_2 != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignedsegment.pyx":676 - * self._delegate.data = calloc( - * self._delegate.m_data, 1) - * self._delegate.l_data = 0 # <<<<<<<<<<<<<< - * # set some data to make read approximately legit. - * # Note, SAM writing fails with q_name of length 0 + /* "pysam/libcalignedsegment.pyx":857 + * ref_seq = build_alignment_sequence(src) + * if ref_seq is None: + * raise ValueError("MD tag not present") # <<<<<<<<<<<<<< + * + * cdef char * s = calloc(len(ref_seq) + 1, sizeof(char)) */ - __pyx_v_self->_delegate->l_data = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 857, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 857, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":679 - * # set some data to make read approximately legit. - * # Note, SAM writing fails with q_name of length 0 - * self._delegate.core.l_qname = 0 # <<<<<<<<<<<<<< - * self._delegate.core.tid = -1 - * self._delegate.core.pos = -1 + /* "pysam/libcalignedsegment.pyx":856 + * cdef int s_idx = 0 + * ref_seq = build_alignment_sequence(src) + * if ref_seq is None: # <<<<<<<<<<<<<< + * raise ValueError("MD tag not present") + * */ - __pyx_v_self->_delegate->core.l_qname = 0; + } - /* "pysam/libcalignedsegment.pyx":680 - * # Note, SAM writing fails with q_name of length 0 - * self._delegate.core.l_qname = 0 - * self._delegate.core.tid = -1 # <<<<<<<<<<<<<< - * self._delegate.core.pos = -1 - * self._delegate.core.mtid = -1 + /* "pysam/libcalignedsegment.pyx":859 + * raise ValueError("MD tag not present") + * + * cdef char * s = calloc(len(ref_seq) + 1, sizeof(char)) # <<<<<<<<<<<<<< + * if s == NULL: + * raise ValueError( */ - __pyx_v_self->_delegate->core.tid = -1; + if (unlikely(__pyx_v_ref_seq == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(0, 859, __pyx_L1_error) + } + __pyx_t_4 = PyBytes_GET_SIZE(__pyx_v_ref_seq); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 859, __pyx_L1_error) + __pyx_v_s = ((char *)calloc((__pyx_t_4 + 1), (sizeof(char)))); - /* "pysam/libcalignedsegment.pyx":681 - * self._delegate.core.l_qname = 0 - * self._delegate.core.tid = -1 - * self._delegate.core.pos = -1 # <<<<<<<<<<<<<< - * self._delegate.core.mtid = -1 - * self._delegate.core.mpos = -1 + /* "pysam/libcalignedsegment.pyx":860 + * + * cdef char * s = calloc(len(ref_seq) + 1, sizeof(char)) + * if s == NULL: # <<<<<<<<<<<<<< + * raise ValueError( + * "could not allocate sequence of length %i" % len(ref_seq)) */ - __pyx_v_self->_delegate->core.pos = -1; + __pyx_t_3 = ((__pyx_v_s == NULL) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignedsegment.pyx":682 - * self._delegate.core.tid = -1 - * self._delegate.core.pos = -1 - * self._delegate.core.mtid = -1 # <<<<<<<<<<<<<< - * self._delegate.core.mpos = -1 + /* "pysam/libcalignedsegment.pyx":862 + * if s == NULL: + * raise ValueError( + * "could not allocate sequence of length %i" % len(ref_seq)) # <<<<<<<<<<<<<< * + * cdef char * cref_seq = ref_seq */ - __pyx_v_self->_delegate->core.mtid = -1; + if (unlikely(__pyx_v_ref_seq == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(0, 862, __pyx_L1_error) + } + __pyx_t_4 = PyBytes_GET_SIZE(__pyx_v_ref_seq); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 862, __pyx_L1_error) + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 862, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_could_not_allocate_sequence_of_l, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 862, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":683 - * self._delegate.core.pos = -1 - * self._delegate.core.mtid = -1 - * self._delegate.core.mpos = -1 # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":861 + * cdef char * s = calloc(len(ref_seq) + 1, sizeof(char)) + * if s == NULL: + * raise ValueError( # <<<<<<<<<<<<<< + * "could not allocate sequence of length %i" % len(ref_seq)) * - * # caching for selected fields */ - __pyx_v_self->_delegate->core.mpos = -1; + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 861, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 861, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":686 + /* "pysam/libcalignedsegment.pyx":860 * - * # caching for selected fields - * self.cache_query_qualities = None # <<<<<<<<<<<<<< - * self.cache_query_alignment_qualities = None - * self.cache_query_sequence = None + * cdef char * s = calloc(len(ref_seq) + 1, sizeof(char)) + * if s == NULL: # <<<<<<<<<<<<<< + * raise ValueError( + * "could not allocate sequence of length %i" % len(ref_seq)) */ - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->cache_query_qualities); - __Pyx_DECREF(__pyx_v_self->cache_query_qualities); - __pyx_v_self->cache_query_qualities = Py_None; + } - /* "pysam/libcalignedsegment.pyx":687 - * # caching for selected fields - * self.cache_query_qualities = None - * self.cache_query_alignment_qualities = None # <<<<<<<<<<<<<< - * self.cache_query_sequence = None - * self.cache_query_alignment_sequence = None + /* "pysam/libcalignedsegment.pyx":864 + * "could not allocate sequence of length %i" % len(ref_seq)) + * + * cdef char * cref_seq = ref_seq # <<<<<<<<<<<<<< + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) + * cdef uint32_t r_idx = 0 */ - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_qualities); - __Pyx_DECREF(__pyx_v_self->cache_query_alignment_qualities); - __pyx_v_self->cache_query_alignment_qualities = Py_None; + if (unlikely(__pyx_v_ref_seq == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 864, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_PyBytes_AsWritableString(__pyx_v_ref_seq); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 864, __pyx_L1_error) + __pyx_v_cref_seq = __pyx_t_6; - /* "pysam/libcalignedsegment.pyx":688 - * self.cache_query_qualities = None - * self.cache_query_alignment_qualities = None - * self.cache_query_sequence = None # <<<<<<<<<<<<<< - * self.cache_query_alignment_sequence = None + /* "pysam/libcalignedsegment.pyx":865 * + * cdef char * cref_seq = ref_seq + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + * cdef uint32_t r_idx = 0 + * for k from 0 <= k < pysam_get_n_cigar(src): */ - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->cache_query_sequence); - __Pyx_DECREF(__pyx_v_self->cache_query_sequence); - __pyx_v_self->cache_query_sequence = Py_None; + __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":689 - * self.cache_query_alignment_qualities = None - * self.cache_query_sequence = None - * self.cache_query_alignment_sequence = None # <<<<<<<<<<<<<< - * - * def __dealloc__(self): + /* "pysam/libcalignedsegment.pyx":866 + * cdef char * cref_seq = ref_seq + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) + * cdef uint32_t r_idx = 0 # <<<<<<<<<<<<<< + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK */ - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_sequence); - __Pyx_DECREF(__pyx_v_self->cache_query_alignment_sequence); - __pyx_v_self->cache_query_alignment_sequence = Py_None; + __pyx_v_r_idx = 0; - /* "pysam/libcalignedsegment.pyx":667 - * - * # Now only called when instances are created from Python - * def __init__(self): # <<<<<<<<<<<<<< - * # see bam_init1 - * self._delegate = calloc(1, sizeof(bam1_t)) + /* "pysam/libcalignedsegment.pyx":867 + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) + * cdef uint32_t r_idx = 0 + * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT */ + __pyx_t_7 = pysam_get_n_cigar(__pyx_v_src); + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_7; __pyx_v_k++) { - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":868 + * cdef uint32_t r_idx = 0 + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: + */ + __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); -/* "pysam/libcalignedsegment.pyx":691 - * self.cache_query_alignment_sequence = None - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * bam_destroy1(self._delegate) - * + /* "pysam/libcalignedsegment.pyx":869 + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< + * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: + * for i from 0 <= i < l: */ + __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT); -/* Python wrapper */ -static void __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_2__dealloc__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + /* "pysam/libcalignedsegment.pyx":870 + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: # <<<<<<<<<<<<<< + * for i from 0 <= i < l: + * s[s_idx] = cref_seq[r_idx] + */ + __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0); + if (!__pyx_t_2) { + } else { + __pyx_t_3 = __pyx_t_2; + goto __pyx_L8_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_op == BAM_CEQUAL) != 0); + if (!__pyx_t_2) { + } else { + __pyx_t_3 = __pyx_t_2; + goto __pyx_L8_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_op == BAM_CDIFF) != 0); + __pyx_t_3 = __pyx_t_2; + __pyx_L8_bool_binop_done:; + if (__pyx_t_3) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} + /* "pysam/libcalignedsegment.pyx":871 + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: + * for i from 0 <= i < l: # <<<<<<<<<<<<<< + * s[s_idx] = cref_seq[r_idx] + * r_idx += 1 + */ + __pyx_t_8 = __pyx_v_l; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { -static void __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_2__dealloc__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 691, 0, __PYX_ERR(0, 691, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":872 + * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: + * for i from 0 <= i < l: + * s[s_idx] = cref_seq[r_idx] # <<<<<<<<<<<<<< + * r_idx += 1 + * s_idx += 1 + */ + (__pyx_v_s[__pyx_v_s_idx]) = (__pyx_v_cref_seq[__pyx_v_r_idx]); - /* "pysam/libcalignedsegment.pyx":692 - * - * def __dealloc__(self): - * bam_destroy1(self._delegate) # <<<<<<<<<<<<<< - * - * def __str__(self): + /* "pysam/libcalignedsegment.pyx":873 + * for i from 0 <= i < l: + * s[s_idx] = cref_seq[r_idx] + * r_idx += 1 # <<<<<<<<<<<<<< + * s_idx += 1 + * elif op == BAM_CDEL: */ - bam_destroy1(__pyx_v_self->_delegate); + __pyx_v_r_idx = (__pyx_v_r_idx + 1); - /* "pysam/libcalignedsegment.pyx":691 - * self.cache_query_alignment_sequence = None - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * bam_destroy1(self._delegate) - * + /* "pysam/libcalignedsegment.pyx":874 + * s[s_idx] = cref_seq[r_idx] + * r_idx += 1 + * s_idx += 1 # <<<<<<<<<<<<<< + * elif op == BAM_CDEL: + * for i from 0 <= i < l: */ + __pyx_v_s_idx = (__pyx_v_s_idx + 1); + } - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("pysam.libcalignedsegment.AlignedSegment.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); -} + /* "pysam/libcalignedsegment.pyx":870 + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: # <<<<<<<<<<<<<< + * for i from 0 <= i < l: + * s[s_idx] = cref_seq[r_idx] + */ + goto __pyx_L7; + } -/* "pysam/libcalignedsegment.pyx":694 - * bam_destroy1(self._delegate) - * - * def __str__(self): # <<<<<<<<<<<<<< - * """return string representation of alignment. - * + /* "pysam/libcalignedsegment.pyx":875 + * r_idx += 1 + * s_idx += 1 + * elif op == BAM_CDEL: # <<<<<<<<<<<<<< + * for i from 0 <= i < l: + * s[s_idx] = cref_seq[r_idx] */ + __pyx_t_3 = ((__pyx_v_op == BAM_CDEL) != 0); + if (__pyx_t_3) { -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5__str__(PyObject *__pyx_v_self); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_4__str__[] = "return string representation of alignment.\n\n The representation is an approximate :term:`SAM` format, because\n an aligned read might not be associated with a :term:`AlignmentFile`.\n As a result :term:`tid` is shown instead of the reference name.\n Similarly, the tags field is returned in its parsed state.\n\n To get a valid SAM record, use :meth:`tostring`.\n "; -#if CYTHON_COMPILING_IN_CPYTHON -struct wrapperbase __pyx_wrapperbase_5pysam_18libcalignedsegment_14AlignedSegment_4__str__; -#endif -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5__str__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4__str__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + /* "pysam/libcalignedsegment.pyx":876 + * s_idx += 1 + * elif op == BAM_CDEL: + * for i from 0 <= i < l: # <<<<<<<<<<<<<< + * s[s_idx] = cref_seq[r_idx] + * r_idx += 1 + */ + __pyx_t_8 = __pyx_v_l; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":877 + * elif op == BAM_CDEL: + * for i from 0 <= i < l: + * s[s_idx] = cref_seq[r_idx] # <<<<<<<<<<<<<< + * r_idx += 1 + * s_idx += 1 + */ + (__pyx_v_s[__pyx_v_s_idx]) = (__pyx_v_cref_seq[__pyx_v_r_idx]); -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4__str__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - __Pyx_RefNannySetupContext("__str__", 0); - __Pyx_TraceCall("__str__", __pyx_f[0], 694, 0, __PYX_ERR(0, 694, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":706 - * # sam-parsing is done in sam.c/bam_format1_core which - * # requires a valid header. - * return "\t".join(map(str, (self.query_name, # <<<<<<<<<<<<<< - * self.flag, - * self.reference_id, - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pysam/libcalignedsegment.pyx":707 - * # requires a valid header. - * return "\t".join(map(str, (self.query_name, - * self.flag, # <<<<<<<<<<<<<< - * self.reference_id, - * self.reference_start, - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 707, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - - /* "pysam/libcalignedsegment.pyx":708 - * return "\t".join(map(str, (self.query_name, - * self.flag, - * self.reference_id, # <<<<<<<<<<<<<< - * self.reference_start, - * self.mapping_quality, - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 708, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pysam/libcalignedsegment.pyx":709 - * self.flag, - * self.reference_id, - * self.reference_start, # <<<<<<<<<<<<<< - * self.mapping_quality, - * self.cigarstring, + /* "pysam/libcalignedsegment.pyx":878 + * for i from 0 <= i < l: + * s[s_idx] = cref_seq[r_idx] + * r_idx += 1 # <<<<<<<<<<<<<< + * s_idx += 1 + * elif op == BAM_CREF_SKIP: */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_start); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_v_r_idx = (__pyx_v_r_idx + 1); - /* "pysam/libcalignedsegment.pyx":710 - * self.reference_id, - * self.reference_start, - * self.mapping_quality, # <<<<<<<<<<<<<< - * self.cigarstring, - * self.next_reference_id, + /* "pysam/libcalignedsegment.pyx":879 + * s[s_idx] = cref_seq[r_idx] + * r_idx += 1 + * s_idx += 1 # <<<<<<<<<<<<<< + * elif op == BAM_CREF_SKIP: + * pass */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 710, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __pyx_v_s_idx = (__pyx_v_s_idx + 1); + } - /* "pysam/libcalignedsegment.pyx":711 - * self.reference_start, - * self.mapping_quality, - * self.cigarstring, # <<<<<<<<<<<<<< - * self.next_reference_id, - * self.next_reference_start, + /* "pysam/libcalignedsegment.pyx":875 + * r_idx += 1 + * s_idx += 1 + * elif op == BAM_CDEL: # <<<<<<<<<<<<<< + * for i from 0 <= i < l: + * s[s_idx] = cref_seq[r_idx] */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigarstring); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 711, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); + goto __pyx_L7; + } - /* "pysam/libcalignedsegment.pyx":712 - * self.mapping_quality, - * self.cigarstring, - * self.next_reference_id, # <<<<<<<<<<<<<< - * self.next_reference_start, - * self.query_alignment_length, + /* "pysam/libcalignedsegment.pyx":880 + * r_idx += 1 + * s_idx += 1 + * elif op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< + * pass + * elif op == BAM_CINS: */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 712, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = ((__pyx_v_op == BAM_CREF_SKIP) != 0); + if (__pyx_t_3) { + goto __pyx_L7; + } - /* "pysam/libcalignedsegment.pyx":713 - * self.cigarstring, - * self.next_reference_id, - * self.next_reference_start, # <<<<<<<<<<<<<< - * self.query_alignment_length, - * self.query_sequence, + /* "pysam/libcalignedsegment.pyx":882 + * elif op == BAM_CREF_SKIP: + * pass + * elif op == BAM_CINS: # <<<<<<<<<<<<<< + * r_idx += l + * elif op == BAM_CSOFT_CLIP: */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 713, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = ((__pyx_v_op == BAM_CINS) != 0); + if (__pyx_t_3) { - /* "pysam/libcalignedsegment.pyx":714 - * self.next_reference_id, - * self.next_reference_start, - * self.query_alignment_length, # <<<<<<<<<<<<<< - * self.query_sequence, - * self.query_qualities, + /* "pysam/libcalignedsegment.pyx":883 + * pass + * elif op == BAM_CINS: + * r_idx += l # <<<<<<<<<<<<<< + * elif op == BAM_CSOFT_CLIP: + * pass */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_length); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 714, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); + __pyx_v_r_idx = (__pyx_v_r_idx + __pyx_v_l); - /* "pysam/libcalignedsegment.pyx":715 - * self.next_reference_start, - * self.query_alignment_length, - * self.query_sequence, # <<<<<<<<<<<<<< - * self.query_qualities, - * self.tags))) + /* "pysam/libcalignedsegment.pyx":882 + * elif op == BAM_CREF_SKIP: + * pass + * elif op == BAM_CINS: # <<<<<<<<<<<<<< + * r_idx += l + * elif op == BAM_CSOFT_CLIP: */ - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 715, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); + goto __pyx_L7; + } - /* "pysam/libcalignedsegment.pyx":716 - * self.query_alignment_length, - * self.query_sequence, - * self.query_qualities, # <<<<<<<<<<<<<< - * self.tags))) - * + /* "pysam/libcalignedsegment.pyx":884 + * elif op == BAM_CINS: + * r_idx += l + * elif op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< + * pass + * elif op == BAM_CHARD_CLIP: */ - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 716, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); + __pyx_t_3 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0); + if (__pyx_t_3) { + goto __pyx_L7; + } - /* "pysam/libcalignedsegment.pyx":717 - * self.query_sequence, - * self.query_qualities, - * self.tags))) # <<<<<<<<<<<<<< - * - * def __copy__(self): + /* "pysam/libcalignedsegment.pyx":886 + * elif op == BAM_CSOFT_CLIP: + * pass + * elif op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< + * pass # advances neither + * elif op == BAM_CPAD: */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tags); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 717, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); + __pyx_t_3 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0); + if (__pyx_t_3) { + goto __pyx_L7; + } - /* "pysam/libcalignedsegment.pyx":706 - * # sam-parsing is done in sam.c/bam_format1_core which - * # requires a valid header. - * return "\t".join(map(str, (self.query_name, # <<<<<<<<<<<<<< - * self.flag, - * self.reference_id, + /* "pysam/libcalignedsegment.pyx":888 + * elif op == BAM_CHARD_CLIP: + * pass # advances neither + * elif op == BAM_CPAD: # <<<<<<<<<<<<<< + * raise NotImplementedError( + * "Padding (BAM_CPAD, 6) is currently not supported. " */ - __pyx_t_13 = PyTuple_New(12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_13, 5, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_13, 6, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_13, 7, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_13, 8, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_13, 9, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_13, 10, __pyx_t_11); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_13, 11, __pyx_t_12); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_t_5 = 0; - __pyx_t_6 = 0; - __pyx_t_7 = 0; - __pyx_t_8 = 0; - __pyx_t_9 = 0; - __pyx_t_10 = 0; - __pyx_t_11 = 0; - __pyx_t_12 = 0; - __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(((PyObject *)(&PyString_Type))); - __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)(&PyString_Type))); - __Pyx_GIVEREF(__pyx_t_13); - PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_13); - __pyx_t_13 = 0; - __pyx_t_13 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_12, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = __Pyx_PyString_Join(__pyx_kp_s__19, __pyx_t_13); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_r = __pyx_t_12; - __pyx_t_12 = 0; - goto __pyx_L0; + __pyx_t_3 = ((__pyx_v_op == BAM_CPAD) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignedsegment.pyx":694 - * bam_destroy1(self._delegate) - * - * def __str__(self): # <<<<<<<<<<<<<< - * """return string representation of alignment. - * + /* "pysam/libcalignedsegment.pyx":889 + * pass # advances neither + * elif op == BAM_CPAD: + * raise NotImplementedError( # <<<<<<<<<<<<<< + * "Padding (BAM_CPAD, 6) is currently not supported. " + * "Please implement. Sorry about that.") */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 889, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 889, __pyx_L1_error) - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":719 - * self.tags))) - * - * def __copy__(self): # <<<<<<<<<<<<<< - * return makeAlignedSegment(self._delegate, self._alignment_file) - * + /* "pysam/libcalignedsegment.pyx":888 + * elif op == BAM_CHARD_CLIP: + * pass # advances neither + * elif op == BAM_CPAD: # <<<<<<<<<<<<<< + * raise NotImplementedError( + * "Padding (BAM_CPAD, 6) is currently not supported. " */ + } + __pyx_L7:; + } -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_7__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_6__copy__[] = "AlignedSegment.__copy__(self)"; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_7__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__copy__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6__copy__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6__copy__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__copy__", 0); - __Pyx_TraceCall("__copy__", __pyx_f[0], 719, 0, __PYX_ERR(0, 719, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":720 + /* "pysam/libcalignedsegment.pyx":893 + * "Please implement. Sorry about that.") * - * def __copy__(self): - * return makeAlignedSegment(self._delegate, self._alignment_file) # <<<<<<<<<<<<<< + * seq = PyBytes_FromStringAndSize(s, s_idx) # <<<<<<<<<<<<<< + * free(s) * - * def __deepcopy__(self, memo): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)__pyx_v_self->_alignment_file); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->_delegate, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 720, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_t_1 = PyBytes_FromStringAndSize(__pyx_v_s, __pyx_v_s_idx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 893, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_seq = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":719 - * self.tags))) + /* "pysam/libcalignedsegment.pyx":894 * - * def __copy__(self): # <<<<<<<<<<<<<< - * return makeAlignedSegment(self._delegate, self._alignment_file) + * seq = PyBytes_FromStringAndSize(s, s_idx) + * free(s) # <<<<<<<<<<<<<< * + * return seq */ + free(__pyx_v_s); - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__copy__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":722 - * return makeAlignedSegment(self._delegate, self._alignment_file) - * - * def __deepcopy__(self, memo): # <<<<<<<<<<<<<< - * return makeAlignedSegment(self._delegate, self._alignment_file) + /* "pysam/libcalignedsegment.pyx":896 + * free(s) * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_8__deepcopy__[] = "AlignedSegment.__deepcopy__(self, memo)"; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__deepcopy__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8__deepcopy__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_memo)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8__deepcopy__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__deepcopy__", 0); - __Pyx_TraceCall("__deepcopy__", __pyx_f[0], 722, 0, __PYX_ERR(0, 722, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":723 + * return seq # <<<<<<<<<<<<<< * - * def __deepcopy__(self, memo): - * return makeAlignedSegment(self._delegate, self._alignment_file) # <<<<<<<<<<<<<< * - * def compare(self, AlignedSegment other): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)__pyx_v_self->_alignment_file); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->_delegate, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 723, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v_seq); + __pyx_r = __pyx_v_seq; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":722 - * return makeAlignedSegment(self._delegate, self._alignment_file) + /* "pysam/libcalignedsegment.pyx":845 * - * def __deepcopy__(self, memo): # <<<<<<<<<<<<<< - * return makeAlignedSegment(self._delegate, self._alignment_file) * + * cdef inline bytes build_reference_sequence(bam1_t * src): # <<<<<<<<<<<<<< + * """return the reference sequence in the region that is covered by the + * alignment of the read to the reference. */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__deepcopy__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcalignedsegment.build_reference_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ref_seq); + __Pyx_XDECREF(__pyx_v_seq); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":725 - * return makeAlignedSegment(self._delegate, self._alignment_file) +/* "pysam/libcalignedsegment.pyx":926 * - * def compare(self, AlignedSegment other): # <<<<<<<<<<<<<< - * '''return -1,0,1, if contents in this are binary - * <,=,> to *other* + * # Now only called when instances are created from Python + * def __init__(self, AlignmentHeader header=None): # <<<<<<<<<<<<<< + * # see bam_init1 + * self._delegate = calloc(1, sizeof(bam1_t)) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_10compare[] = "AlignedSegment.compare(self, AlignedSegment other)\nreturn -1,0,1, if contents in this are binary\n <,=,> to *other*\n\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header = 0; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("compare (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment, 1, "other", 0))) __PYX_ERR(0, 725, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10compare(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_other)); + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_header,0}; + PyObject* values[1] = {0}; + values[0] = (PyObject *)((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_header); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 926, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)values[0]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 926, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_header), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, 1, "header", 0))) __PYX_ERR(0, 926, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment___init__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_header); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; - __pyx_r = NULL; + __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10compare(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_other) { - int __pyx_v_retval; - bam1_t *__pyx_v_t; - bam1_t *__pyx_v_o; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment___init__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; - int __pyx_t_2; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("compare", 0); - __Pyx_TraceCall("compare", __pyx_f[0], 725, 0, __PYX_ERR(0, 725, __pyx_L1_error)); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannySetupContext("__init__", 0); + __Pyx_TraceCall("__init__", __pyx_f[0], 926, 0, __PYX_ERR(0, 926, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":735 - * cdef bam1_t *o - * - * t = self._delegate # <<<<<<<<<<<<<< - * o = other._delegate - * + /* "pysam/libcalignedsegment.pyx":928 + * def __init__(self, AlignmentHeader header=None): + * # see bam_init1 + * self._delegate = calloc(1, sizeof(bam1_t)) # <<<<<<<<<<<<<< + * if self._delegate == NULL: + * raise MemoryError("could not allocated memory of {} bytes".format(sizeof(bam1_t))) */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_t = __pyx_t_1; + __pyx_v_self->_delegate = ((bam1_t *)calloc(1, (sizeof(bam1_t)))); - /* "pysam/libcalignedsegment.pyx":736 - * - * t = self._delegate - * o = other._delegate # <<<<<<<<<<<<<< - * - * # uncomment for debugging purposes + /* "pysam/libcalignedsegment.pyx":929 + * # see bam_init1 + * self._delegate = calloc(1, sizeof(bam1_t)) + * if self._delegate == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocated memory of {} bytes".format(sizeof(bam1_t))) + * # allocate some memory. If size is 0, calloc does not return a */ - __pyx_t_1 = __pyx_v_other->_delegate; - __pyx_v_o = __pyx_t_1; + __pyx_t_1 = ((__pyx_v_self->_delegate == NULL) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignedsegment.pyx":748 - * - * # Fast-path test for object identity - * if t == o: # <<<<<<<<<<<<<< - * return 0 - * + /* "pysam/libcalignedsegment.pyx":930 + * self._delegate = calloc(1, sizeof(bam1_t)) + * if self._delegate == NULL: + * raise MemoryError("could not allocated memory of {} bytes".format(sizeof(bam1_t))) # <<<<<<<<<<<<<< + * # allocate some memory. If size is 0, calloc does not return a + * # pointer that can be passed to free() so allocate 40 bytes */ - __pyx_t_2 = ((__pyx_v_t == __pyx_v_o) != 0); - if (__pyx_t_2) { + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocated_memory_of_by, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 930, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_FromSize_t((sizeof(bam1_t))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 930, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 930, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 930, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 930, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 930, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 930, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 930, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 930, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":749 - * # Fast-path test for object identity - * if t == o: - * return 0 # <<<<<<<<<<<<<< - * - * retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t)) + /* "pysam/libcalignedsegment.pyx":929 + * # see bam_init1 + * self._delegate = calloc(1, sizeof(bam1_t)) + * if self._delegate == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocated memory of {} bytes".format(sizeof(bam1_t))) + * # allocate some memory. If size is 0, calloc does not return a */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_int_0); - __pyx_r = __pyx_int_0; - goto __pyx_L0; + } - /* "pysam/libcalignedsegment.pyx":748 - * - * # Fast-path test for object identity - * if t == o: # <<<<<<<<<<<<<< - * return 0 - * + /* "pysam/libcalignedsegment.pyx":934 + * # pointer that can be passed to free() so allocate 40 bytes + * # for a new read + * self._delegate.m_data = 40 # <<<<<<<<<<<<<< + * self._delegate.data = calloc( + * self._delegate.m_data, 1) + */ + __pyx_v_self->_delegate->m_data = 40; + + /* "pysam/libcalignedsegment.pyx":935 + * # for a new read + * self._delegate.m_data = 40 + * self._delegate.data = calloc( # <<<<<<<<<<<<<< + * self._delegate.m_data, 1) + * if self._delegate.data == NULL: + */ + __pyx_v_self->_delegate->data = ((uint8_t *)calloc(__pyx_v_self->_delegate->m_data, 1)); + + /* "pysam/libcalignedsegment.pyx":937 + * self._delegate.data = calloc( + * self._delegate.m_data, 1) + * if self._delegate.data == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate memory of {} bytes".format(self._delegate.m_data)) + * self._delegate.l_data = 0 + */ + __pyx_t_1 = ((__pyx_v_self->_delegate->data == NULL) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcalignedsegment.pyx":938 + * self._delegate.m_data, 1) + * if self._delegate.data == NULL: + * raise MemoryError("could not allocate memory of {} bytes".format(self._delegate.m_data)) # <<<<<<<<<<<<<< + * self._delegate.l_data = 0 + * # set some data to make read approximately legit. + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_memory_of_byt, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 938, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_delegate->m_data); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 938, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_4) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 938, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 938, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 938, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 938, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 938, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 938, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 938, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":937 + * self._delegate.data = calloc( + * self._delegate.m_data, 1) + * if self._delegate.data == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate memory of {} bytes".format(self._delegate.m_data)) + * self._delegate.l_data = 0 */ } - /* "pysam/libcalignedsegment.pyx":751 - * return 0 - * - * retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t)) # <<<<<<<<<<<<<< - * - * if retval: + /* "pysam/libcalignedsegment.pyx":939 + * if self._delegate.data == NULL: + * raise MemoryError("could not allocate memory of {} bytes".format(self._delegate.m_data)) + * self._delegate.l_data = 0 # <<<<<<<<<<<<<< + * # set some data to make read approximately legit. + * # Note, SAM writing fails with q_name of length 0 */ - __pyx_v_retval = memcmp((&__pyx_v_t->core), (&__pyx_v_o->core), (sizeof(bam1_core_t))); + __pyx_v_self->_delegate->l_data = 0; - /* "pysam/libcalignedsegment.pyx":753 - * retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t)) - * - * if retval: # <<<<<<<<<<<<<< - * return retval - * # cmp(t.l_data, o.l_data) + /* "pysam/libcalignedsegment.pyx":942 + * # set some data to make read approximately legit. + * # Note, SAM writing fails with q_name of length 0 + * self._delegate.core.l_qname = 0 # <<<<<<<<<<<<<< + * self._delegate.core.tid = -1 + * self._delegate.core.pos = -1 */ - __pyx_t_2 = (__pyx_v_retval != 0); - if (__pyx_t_2) { + __pyx_v_self->_delegate->core.l_qname = 0; + + /* "pysam/libcalignedsegment.pyx":943 + * # Note, SAM writing fails with q_name of length 0 + * self._delegate.core.l_qname = 0 + * self._delegate.core.tid = -1 # <<<<<<<<<<<<<< + * self._delegate.core.pos = -1 + * self._delegate.core.mtid = -1 + */ + __pyx_v_self->_delegate->core.tid = -1; + + /* "pysam/libcalignedsegment.pyx":944 + * self._delegate.core.l_qname = 0 + * self._delegate.core.tid = -1 + * self._delegate.core.pos = -1 # <<<<<<<<<<<<<< + * self._delegate.core.mtid = -1 + * self._delegate.core.mpos = -1 + */ + __pyx_v_self->_delegate->core.pos = -1; - /* "pysam/libcalignedsegment.pyx":754 + /* "pysam/libcalignedsegment.pyx":945 + * self._delegate.core.tid = -1 + * self._delegate.core.pos = -1 + * self._delegate.core.mtid = -1 # <<<<<<<<<<<<<< + * self._delegate.core.mpos = -1 * - * if retval: - * return retval # <<<<<<<<<<<<<< - * # cmp(t.l_data, o.l_data) - * retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_retval); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 754, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __pyx_v_self->_delegate->core.mtid = -1; - /* "pysam/libcalignedsegment.pyx":753 - * retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t)) + /* "pysam/libcalignedsegment.pyx":946 + * self._delegate.core.pos = -1 + * self._delegate.core.mtid = -1 + * self._delegate.core.mpos = -1 # <<<<<<<<<<<<<< * - * if retval: # <<<<<<<<<<<<<< - * return retval - * # cmp(t.l_data, o.l_data) + * # caching for selected fields */ - } + __pyx_v_self->_delegate->core.mpos = -1; - /* "pysam/libcalignedsegment.pyx":756 - * return retval - * # cmp(t.l_data, o.l_data) - * retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) # <<<<<<<<<<<<<< - * if retval: - * return retval + /* "pysam/libcalignedsegment.pyx":949 + * + * # caching for selected fields + * self.cache_query_qualities = None # <<<<<<<<<<<<<< + * self.cache_query_alignment_qualities = None + * self.cache_query_sequence = None */ - __pyx_v_retval = ((__pyx_v_t->l_data > __pyx_v_o->l_data) - (__pyx_v_t->l_data < __pyx_v_o->l_data)); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->cache_query_qualities); + __Pyx_DECREF(__pyx_v_self->cache_query_qualities); + __pyx_v_self->cache_query_qualities = Py_None; - /* "pysam/libcalignedsegment.pyx":757 - * # cmp(t.l_data, o.l_data) - * retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) - * if retval: # <<<<<<<<<<<<<< - * return retval - * return memcmp(t.data, o.data, t.l_data) + /* "pysam/libcalignedsegment.pyx":950 + * # caching for selected fields + * self.cache_query_qualities = None + * self.cache_query_alignment_qualities = None # <<<<<<<<<<<<<< + * self.cache_query_sequence = None + * self.cache_query_alignment_sequence = None */ - __pyx_t_2 = (__pyx_v_retval != 0); - if (__pyx_t_2) { + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_qualities); + __Pyx_DECREF(__pyx_v_self->cache_query_alignment_qualities); + __pyx_v_self->cache_query_alignment_qualities = Py_None; - /* "pysam/libcalignedsegment.pyx":758 - * retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) - * if retval: - * return retval # <<<<<<<<<<<<<< - * return memcmp(t.data, o.data, t.l_data) + /* "pysam/libcalignedsegment.pyx":951 + * self.cache_query_qualities = None + * self.cache_query_alignment_qualities = None + * self.cache_query_sequence = None # <<<<<<<<<<<<<< + * self.cache_query_alignment_sequence = None * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_retval); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->cache_query_sequence); + __Pyx_DECREF(__pyx_v_self->cache_query_sequence); + __pyx_v_self->cache_query_sequence = Py_None; - /* "pysam/libcalignedsegment.pyx":757 - * # cmp(t.l_data, o.l_data) - * retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) - * if retval: # <<<<<<<<<<<<<< - * return retval - * return memcmp(t.data, o.data, t.l_data) + /* "pysam/libcalignedsegment.pyx":952 + * self.cache_query_alignment_qualities = None + * self.cache_query_sequence = None + * self.cache_query_alignment_sequence = None # <<<<<<<<<<<<<< + * + * self.header = header */ - } + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_sequence); + __Pyx_DECREF(__pyx_v_self->cache_query_alignment_sequence); + __pyx_v_self->cache_query_alignment_sequence = Py_None; - /* "pysam/libcalignedsegment.pyx":759 - * if retval: - * return retval - * return memcmp(t.data, o.data, t.l_data) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":954 + * self.cache_query_alignment_sequence = None * - * def __richcmp__(self, AlignedSegment other, int op): + * self.header = header # <<<<<<<<<<<<<< + * + * def __dealloc__(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyInt_From_int(memcmp(__pyx_v_t->data, __pyx_v_o->data, __pyx_v_t->l_data)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 759, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __Pyx_INCREF(((PyObject *)__pyx_v_header)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_header)); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = __pyx_v_header; - /* "pysam/libcalignedsegment.pyx":725 - * return makeAlignedSegment(self._delegate, self._alignment_file) + /* "pysam/libcalignedsegment.pyx":926 * - * def compare(self, AlignedSegment other): # <<<<<<<<<<<<<< - * '''return -1,0,1, if contents in this are binary - * <,=,> to *other* + * # Now only called when instances are created from Python + * def __init__(self, AlignmentHeader header=None): # <<<<<<<<<<<<<< + * # see bam_init1 + * self._delegate = calloc(1, sizeof(bam1_t)) */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.compare", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":761 - * return memcmp(t.data, o.data, t.l_data) +/* "pysam/libcalignedsegment.pyx":956 + * self.header = header + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * bam_destroy1(self._delegate) * - * def __richcmp__(self, AlignedSegment other, int op): # <<<<<<<<<<<<<< - * if op == 2: # == operator - * return self.compare(other) == 0 */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { - PyObject *__pyx_r = 0; +static void __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment, 1, "other", 0))) __PYX_ERR(0, 761, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12__richcmp__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_other), ((int)__pyx_v_op)); + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_2__dealloc__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; __Pyx_RefNannyFinishContext(); - return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12__richcmp__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_other, int __pyx_v_op) { - PyObject *__pyx_r = NULL; +static void __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_2__dealloc__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannySetupContext("__richcmp__", 0); - __Pyx_TraceCall("__richcmp__", __pyx_f[0], 761, 0, __PYX_ERR(0, 761, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__dealloc__", 0); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 956, 0, __PYX_ERR(0, 956, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":762 + /* "pysam/libcalignedsegment.pyx":957 * - * def __richcmp__(self, AlignedSegment other, int op): - * if op == 2: # == operator # <<<<<<<<<<<<<< - * return self.compare(other) == 0 - * elif op == 3: # != operator - */ - switch (__pyx_v_op) { - case 2: - - /* "pysam/libcalignedsegment.pyx":763 - * def __richcmp__(self, AlignedSegment other, int op): - * if op == 2: # == operator - * return self.compare(other) == 0 # <<<<<<<<<<<<<< - * elif op == 3: # != operator - * return self.compare(other) != 0 - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_compare); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_other)}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_other)}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_INCREF(((PyObject *)__pyx_v_other)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_other)); - PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_other)); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 763, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":762 + * def __dealloc__(self): + * bam_destroy1(self._delegate) # <<<<<<<<<<<<<< * - * def __richcmp__(self, AlignedSegment other, int op): - * if op == 2: # == operator # <<<<<<<<<<<<<< - * return self.compare(other) == 0 - * elif op == 3: # != operator - */ - break; - - /* "pysam/libcalignedsegment.pyx":764 - * if op == 2: # == operator - * return self.compare(other) == 0 - * elif op == 3: # != operator # <<<<<<<<<<<<<< - * return self.compare(other) != 0 - * else: - */ - case 3: - - /* "pysam/libcalignedsegment.pyx":765 - * return self.compare(other) == 0 - * elif op == 3: # != operator - * return self.compare(other) != 0 # <<<<<<<<<<<<<< - * else: - * return NotImplemented - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_compare); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - if (!__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_other)}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_other)}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL; - __Pyx_INCREF(((PyObject *)__pyx_v_other)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_other)); - PyTuple_SET_ITEM(__pyx_t_3, 0+1, ((PyObject *)__pyx_v_other)); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 765, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":764 - * if op == 2: # == operator - * return self.compare(other) == 0 - * elif op == 3: # != operator # <<<<<<<<<<<<<< - * return self.compare(other) != 0 - * else: + * def __str__(self): */ - break; - default: + bam_destroy1(__pyx_v_self->_delegate); - /* "pysam/libcalignedsegment.pyx":767 - * return self.compare(other) != 0 - * else: - * return NotImplemented # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":956 + * self.header = header * - * def __hash__(self): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_builtin_NotImplemented); - __pyx_r = __pyx_builtin_NotImplemented; - goto __pyx_L0; - break; - } - - /* "pysam/libcalignedsegment.pyx":761 - * return memcmp(t.data, o.data, t.l_data) + * def __dealloc__(self): # <<<<<<<<<<<<<< + * bam_destroy1(self._delegate) * - * def __richcmp__(self, AlignedSegment other, int op): # <<<<<<<<<<<<<< - * if op == 2: # == operator - * return self.compare(other) == 0 */ /* function exit code */ + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_WriteUnraisable("pysam.libcalignedsegment.AlignedSegment.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); - return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":769 - * return NotImplemented +/* "pysam/libcalignedsegment.pyx":959 + * bam_destroy1(self._delegate) + * + * def __str__(self): # <<<<<<<<<<<<<< + * """return string representation of alignment. * - * def __hash__(self): # <<<<<<<<<<<<<< - * cdef bam1_t * src = self._delegate - * cdef int x */ /* Python wrapper */ -static Py_hash_t __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15__hash__(PyObject *__pyx_v_self); /*proto*/ -static Py_hash_t __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15__hash__(PyObject *__pyx_v_self) { - Py_hash_t __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5__str__(PyObject *__pyx_v_self); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_4__str__[] = "return string representation of alignment.\n\n The representation is an approximate :term:`SAM` format, because\n an aligned read might not be associated with a :term:`AlignmentFile`.\n As a result :term:`tid` is shown instead of the reference name.\n Similarly, the tags field is returned in its parsed state.\n\n To get a valid SAM record, use :meth:`to_string`.\n "; +#if CYTHON_COMPILING_IN_CPYTHON +struct wrapperbase __pyx_wrapperbase_5pysam_18libcalignedsegment_14AlignedSegment_4__str__; +#endif +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14__hash__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4__str__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static Py_hash_t __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14__hash__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - bam1_t *__pyx_v_src; - int __pyx_v_x; - uint8_t *__pyx_v_c; - uint32_t __pyx_v_hash_value; - Py_hash_t __pyx_r; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4__str__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; - size_t __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("__hash__", 0); - __Pyx_TraceCall("__hash__", __pyx_f[0], 769, 0, __PYX_ERR(0, 769, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":770 - * - * def __hash__(self): - * cdef bam1_t * src = self._delegate # <<<<<<<<<<<<<< - * cdef int x - * - */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + __Pyx_RefNannySetupContext("__str__", 0); + __Pyx_TraceCall("__str__", __pyx_f[0], 959, 0, __PYX_ERR(0, 959, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":774 - * - * # see http://effbot.org/zone/python-hash.htm - * cdef uint8_t * c = &src.core # <<<<<<<<<<<<<< - * cdef uint32_t hash_value = c[0] - * for x from 1 <= x < sizeof(bam1_core_t): + /* "pysam/libcalignedsegment.pyx":971 + * # sam-parsing is done in sam.c/bam_format1_core which + * # requires a valid header. + * return "\t".join(map(str, (self.query_name, # <<<<<<<<<<<<<< + * self.flag, + * self.reference_id, */ - __pyx_v_c = ((uint8_t *)(&__pyx_v_src->core)); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 971, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libcalignedsegment.pyx":775 - * # see http://effbot.org/zone/python-hash.htm - * cdef uint8_t * c = &src.core - * cdef uint32_t hash_value = c[0] # <<<<<<<<<<<<<< - * for x from 1 <= x < sizeof(bam1_core_t): - * hash_value = c_mul(hash_value, 1000003) ^ c[x] - */ - __pyx_v_hash_value = (__pyx_v_c[0]); - - /* "pysam/libcalignedsegment.pyx":776 - * cdef uint8_t * c = &src.core - * cdef uint32_t hash_value = c[0] - * for x from 1 <= x < sizeof(bam1_core_t): # <<<<<<<<<<<<<< - * hash_value = c_mul(hash_value, 1000003) ^ c[x] - * c = src.data - */ - __pyx_t_2 = (sizeof(bam1_core_t)); - for (__pyx_v_x = 1; __pyx_v_x < __pyx_t_2; __pyx_v_x++) { - - /* "pysam/libcalignedsegment.pyx":777 - * cdef uint32_t hash_value = c[0] - * for x from 1 <= x < sizeof(bam1_core_t): - * hash_value = c_mul(hash_value, 1000003) ^ c[x] # <<<<<<<<<<<<<< - * c = src.data - * for x from 0 <= x < src.l_data: - */ - __pyx_v_hash_value = (__pyx_f_5pysam_18libcalignedsegment_c_mul(__pyx_v_hash_value, 0xF4243) ^ (__pyx_v_c[__pyx_v_x])); - } - - /* "pysam/libcalignedsegment.pyx":778 - * for x from 1 <= x < sizeof(bam1_core_t): - * hash_value = c_mul(hash_value, 1000003) ^ c[x] - * c = src.data # <<<<<<<<<<<<<< - * for x from 0 <= x < src.l_data: - * hash_value = c_mul(hash_value, 1000003) ^ c[x] + /* "pysam/libcalignedsegment.pyx":972 + * # requires a valid header. + * return "\t".join(map(str, (self.query_name, + * self.flag, # <<<<<<<<<<<<<< + * self.reference_id, + * self.reference_start, */ - __pyx_v_c = ((uint8_t *)__pyx_v_src->data); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 972, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); - /* "pysam/libcalignedsegment.pyx":779 - * hash_value = c_mul(hash_value, 1000003) ^ c[x] - * c = src.data - * for x from 0 <= x < src.l_data: # <<<<<<<<<<<<<< - * hash_value = c_mul(hash_value, 1000003) ^ c[x] - * + /* "pysam/libcalignedsegment.pyx":973 + * return "\t".join(map(str, (self.query_name, + * self.flag, + * self.reference_id, # <<<<<<<<<<<<<< + * self.reference_start, + * self.mapping_quality, */ - __pyx_t_3 = __pyx_v_src->l_data; - for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) { + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 973, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); - /* "pysam/libcalignedsegment.pyx":780 - * c = src.data - * for x from 0 <= x < src.l_data: - * hash_value = c_mul(hash_value, 1000003) ^ c[x] # <<<<<<<<<<<<<< - * - * return hash_value + /* "pysam/libcalignedsegment.pyx":974 + * self.flag, + * self.reference_id, + * self.reference_start, # <<<<<<<<<<<<<< + * self.mapping_quality, + * self.cigarstring, */ - __pyx_v_hash_value = (__pyx_f_5pysam_18libcalignedsegment_c_mul(__pyx_v_hash_value, 0xF4243) ^ (__pyx_v_c[__pyx_v_x])); - } + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_start); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 974, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libcalignedsegment.pyx":782 - * hash_value = c_mul(hash_value, 1000003) ^ c[x] - * - * return hash_value # <<<<<<<<<<<<<< - * - * cpdef tostring(self, AlignmentFile_t htsfile): + /* "pysam/libcalignedsegment.pyx":975 + * self.reference_id, + * self.reference_start, + * self.mapping_quality, # <<<<<<<<<<<<<< + * self.cigarstring, + * self.next_reference_id, */ - __pyx_r = __pyx_v_hash_value; - goto __pyx_L0; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 975, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); - /* "pysam/libcalignedsegment.pyx":769 - * return NotImplemented - * - * def __hash__(self): # <<<<<<<<<<<<<< - * cdef bam1_t * src = self._delegate - * cdef int x + /* "pysam/libcalignedsegment.pyx":976 + * self.reference_start, + * self.mapping_quality, + * self.cigarstring, # <<<<<<<<<<<<<< + * self.next_reference_id, + * self.next_reference_start, */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigarstring); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 976, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); - /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":784 - * return hash_value - * - * cpdef tostring(self, AlignmentFile_t htsfile): # <<<<<<<<<<<<<< - * """returns a string representation of the aligned segment. - * + /* "pysam/libcalignedsegment.pyx":977 + * self.mapping_quality, + * self.cigarstring, + * self.next_reference_id, # <<<<<<<<<<<<<< + * self.next_reference_start, + * self.query_alignment_length, */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 977, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17tostring(PyObject *__pyx_v_self, PyObject *__pyx_v_htsfile); /*proto*/ -static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_tostring(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, __pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t __pyx_v_htsfile, int __pyx_skip_dispatch) { - int __pyx_v_n_targets; - kstring_t __pyx_v_line; - PyObject *__pyx_v_ret = NULL; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int32_t __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - __Pyx_RefNannySetupContext("tostring", 0); - __Pyx_TraceCall("tostring", __pyx_f[0], 784, 0, __PYX_ERR(0, 784, __pyx_L1_error)); - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tostring); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 784, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17tostring)) { - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (!__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_htsfile)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 784, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_htsfile)}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 784, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_htsfile)}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 784, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 784, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; - __Pyx_INCREF(((PyObject *)__pyx_v_htsfile)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_htsfile)); - PyTuple_SET_ITEM(__pyx_t_5, 0+1, ((PyObject *)__pyx_v_htsfile)); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 784, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "pysam/libcalignedsegment.pyx":795 - * identifiers to chromosome names. - * """ - * cdef int n_targets = htsfile.header.n_targets # <<<<<<<<<<<<<< - * - * if self._delegate.core.tid >= n_targets \ + /* "pysam/libcalignedsegment.pyx":978 + * self.cigarstring, + * self.next_reference_id, + * self.next_reference_start, # <<<<<<<<<<<<<< + * self.query_alignment_length, + * self.query_sequence, */ - __pyx_t_6 = __pyx_v_htsfile->header->n_targets; - __pyx_v_n_targets = __pyx_t_6; + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 978, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); - /* "pysam/libcalignedsegment.pyx":797 - * cdef int n_targets = htsfile.header.n_targets - * - * if self._delegate.core.tid >= n_targets \ # <<<<<<<<<<<<<< - * or self._delegate.core.mtid >= n_targets: - * raise ValueError('htsfile does not match aligned segment') + /* "pysam/libcalignedsegment.pyx":979 + * self.next_reference_id, + * self.next_reference_start, + * self.query_alignment_length, # <<<<<<<<<<<<<< + * self.query_sequence, + * self.query_qualities, */ - __pyx_t_8 = ((__pyx_v_self->_delegate->core.tid >= __pyx_v_n_targets) != 0); - if (!__pyx_t_8) { - } else { - __pyx_t_7 = __pyx_t_8; - goto __pyx_L4_bool_binop_done; - } + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_length); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 979, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); - /* "pysam/libcalignedsegment.pyx":798 - * - * if self._delegate.core.tid >= n_targets \ - * or self._delegate.core.mtid >= n_targets: # <<<<<<<<<<<<<< - * raise ValueError('htsfile does not match aligned segment') - * + /* "pysam/libcalignedsegment.pyx":980 + * self.next_reference_start, + * self.query_alignment_length, + * self.query_sequence, # <<<<<<<<<<<<<< + * self.query_qualities, + * self.tags))) */ - __pyx_t_8 = ((__pyx_v_self->_delegate->core.mtid >= __pyx_v_n_targets) != 0); - __pyx_t_7 = __pyx_t_8; - __pyx_L4_bool_binop_done:; + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 980, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); - /* "pysam/libcalignedsegment.pyx":797 - * cdef int n_targets = htsfile.header.n_targets + /* "pysam/libcalignedsegment.pyx":981 + * self.query_alignment_length, + * self.query_sequence, + * self.query_qualities, # <<<<<<<<<<<<<< + * self.tags))) * - * if self._delegate.core.tid >= n_targets \ # <<<<<<<<<<<<<< - * or self._delegate.core.mtid >= n_targets: - * raise ValueError('htsfile does not match aligned segment') */ - if (unlikely(__pyx_t_7)) { + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 981, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); - /* "pysam/libcalignedsegment.pyx":799 - * if self._delegate.core.tid >= n_targets \ - * or self._delegate.core.mtid >= n_targets: - * raise ValueError('htsfile does not match aligned segment') # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":982 + * self.query_sequence, + * self.query_qualities, + * self.tags))) # <<<<<<<<<<<<<< * - * cdef kstring_t line + * def __copy__(self): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 799, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 799, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tags); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 982, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); - /* "pysam/libcalignedsegment.pyx":797 - * cdef int n_targets = htsfile.header.n_targets - * - * if self._delegate.core.tid >= n_targets \ # <<<<<<<<<<<<<< - * or self._delegate.core.mtid >= n_targets: - * raise ValueError('htsfile does not match aligned segment') + /* "pysam/libcalignedsegment.pyx":971 + * # sam-parsing is done in sam.c/bam_format1_core which + * # requires a valid header. + * return "\t".join(map(str, (self.query_name, # <<<<<<<<<<<<<< + * self.flag, + * self.reference_id, */ - } + __pyx_t_13 = PyTuple_New(12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 971, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_13, 5, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_13, 6, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_13, 7, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_13, 8, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_13, 9, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_13, 10, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_13, 11, __pyx_t_12); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_6 = 0; + __pyx_t_7 = 0; + __pyx_t_8 = 0; + __pyx_t_9 = 0; + __pyx_t_10 = 0; + __pyx_t_11 = 0; + __pyx_t_12 = 0; + __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 971, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); + PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_13); + __pyx_t_13 = 0; + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_12, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 971, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyString_Join(__pyx_kp_s__16, __pyx_t_13); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 971, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_r = __pyx_t_12; + __pyx_t_12 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":802 - * - * cdef kstring_t line - * line.l = line.m = 0 # <<<<<<<<<<<<<< - * line.s = NULL + /* "pysam/libcalignedsegment.pyx":959 + * bam_destroy1(self._delegate) * - */ - __pyx_v_line.l = 0; - __pyx_v_line.m = 0; - - /* "pysam/libcalignedsegment.pyx":803 - * cdef kstring_t line - * line.l = line.m = 0 - * line.s = NULL # <<<<<<<<<<<<<< + * def __str__(self): # <<<<<<<<<<<<<< + * """return string representation of alignment. * - * if sam_format1(htsfile.header, self._delegate, &line) < 0: */ - __pyx_v_line.s = NULL; - /* "pysam/libcalignedsegment.pyx":805 - * line.s = NULL - * - * if sam_format1(htsfile.header, self._delegate, &line) < 0: # <<<<<<<<<<<<<< - * if line.m: - * free(line.s) - */ - __pyx_t_7 = ((sam_format1(__pyx_v_htsfile->header, __pyx_v_self->_delegate, (&__pyx_v_line)) < 0) != 0); - if (__pyx_t_7) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":806 +/* "pysam/libcalignedsegment.pyx":984 + * self.tags))) * - * if sam_format1(htsfile.header, self._delegate, &line) < 0: - * if line.m: # <<<<<<<<<<<<<< - * free(line.s) - * raise ValueError('sam_format failed') - */ - __pyx_t_7 = (__pyx_v_line.m != 0); - if (__pyx_t_7) { - - /* "pysam/libcalignedsegment.pyx":807 - * if sam_format1(htsfile.header, self._delegate, &line) < 0: - * if line.m: - * free(line.s) # <<<<<<<<<<<<<< - * raise ValueError('sam_format failed') + * def __copy__(self): # <<<<<<<<<<<<<< + * return makeAlignedSegment(self._delegate, self.header) * */ - free(__pyx_v_line.s); - /* "pysam/libcalignedsegment.pyx":806 - * - * if sam_format1(htsfile.header, self._delegate, &line) < 0: - * if line.m: # <<<<<<<<<<<<<< - * free(line.s) - * raise ValueError('sam_format failed') - */ - } +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_7__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_6__copy__[] = "AlignedSegment.__copy__(self)"; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_7__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__copy__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6__copy__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - /* "pysam/libcalignedsegment.pyx":808 - * if line.m: - * free(line.s) - * raise ValueError('sam_format failed') # <<<<<<<<<<<<<< - * - * ret = force_str(line.s[:line.l]) - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 808, __pyx_L1_error) + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":805 - * line.s = NULL - * - * if sam_format1(htsfile.header, self._delegate, &line) < 0: # <<<<<<<<<<<<<< - * if line.m: - * free(line.s) - */ - } +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6__copy__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__copy__", 0); + __Pyx_TraceCall("__copy__", __pyx_f[0], 984, 0, __PYX_ERR(0, 984, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":810 - * raise ValueError('sam_format failed') + /* "pysam/libcalignedsegment.pyx":985 * - * ret = force_str(line.s[:line.l]) # <<<<<<<<<<<<<< + * def __copy__(self): + * return makeAlignedSegment(self._delegate, self.header) # <<<<<<<<<<<<<< * - * if line.m: + * def __deepcopy__(self, memo): */ - __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_line.s + 0, __pyx_v_line.l - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 810, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 810, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = ((PyObject *)__pyx_v_self->header); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->_delegate, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 985, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_ret = __pyx_t_2; + __pyx_r = __pyx_t_2; __pyx_t_2 = 0; - - /* "pysam/libcalignedsegment.pyx":812 - * ret = force_str(line.s[:line.l]) - * - * if line.m: # <<<<<<<<<<<<<< - * free(line.s) - * - */ - __pyx_t_7 = (__pyx_v_line.m != 0); - if (__pyx_t_7) { - - /* "pysam/libcalignedsegment.pyx":813 - * - * if line.m: - * free(line.s) # <<<<<<<<<<<<<< - * - * return ret - */ - free(__pyx_v_line.s); - - /* "pysam/libcalignedsegment.pyx":812 - * ret = force_str(line.s[:line.l]) - * - * if line.m: # <<<<<<<<<<<<<< - * free(line.s) - * - */ - } - - /* "pysam/libcalignedsegment.pyx":815 - * free(line.s) - * - * return ret # <<<<<<<<<<<<<< - * - * ######################################################## - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_ret); - __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":784 - * return hash_value + /* "pysam/libcalignedsegment.pyx":984 + * self.tags))) * - * cpdef tostring(self, AlignmentFile_t htsfile): # <<<<<<<<<<<<<< - * """returns a string representation of the aligned segment. + * def __copy__(self): # <<<<<<<<<<<<<< + * return makeAlignedSegment(self._delegate, self.header) * */ @@ -10980,56 +13062,76 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_tostring(s __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__copy__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_ret); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } +/* "pysam/libcalignedsegment.pyx":987 + * return makeAlignedSegment(self._delegate, self.header) + * + * def __deepcopy__(self, memo): # <<<<<<<<<<<<<< + * return makeAlignedSegment(self._delegate, self.header) + * + */ + /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17tostring(PyObject *__pyx_v_self, PyObject *__pyx_v_htsfile); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_16tostring[] = "AlignedSegment.tostring(self, AlignmentFile_t htsfile)\nreturns a string representation of the aligned segment.\n\n The output format is valid SAM format.\n\n Parameters\n ----------\n\n htsfile -- AlignmentFile object to map numerical\n identifiers to chromosome names.\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17tostring(PyObject *__pyx_v_self, PyObject *__pyx_v_htsfile) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_8__deepcopy__[] = "AlignedSegment.__deepcopy__(self, memo)"; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("tostring (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_htsfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "htsfile", 0))) __PYX_ERR(0, 784, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16tostring(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((__pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t)__pyx_v_htsfile)); + __Pyx_RefNannySetupContext("__deepcopy__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8__deepcopy__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_memo)); /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16tostring(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, __pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t __pyx_v_htsfile) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8__deepcopy__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("tostring", 0); - __Pyx_TraceCall("tostring (wrapper)", __pyx_f[0], 784, 0, __PYX_ERR(0, 784, __pyx_L1_error)); + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__deepcopy__", 0); + __Pyx_TraceCall("__deepcopy__", __pyx_f[0], 987, 0, __PYX_ERR(0, 987, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":988 + * + * def __deepcopy__(self, memo): + * return makeAlignedSegment(self._delegate, self.header) # <<<<<<<<<<<<<< + * + * def compare(self, AlignedSegment other): + */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_tostring(__pyx_v_self, __pyx_v_htsfile, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 784, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_1 = ((PyObject *)__pyx_v_self->header); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->_delegate, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 988, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; + /* "pysam/libcalignedsegment.pyx":987 + * return makeAlignedSegment(self._delegate, self.header) + * + * def __deepcopy__(self, memo): # <<<<<<<<<<<<<< + * return makeAlignedSegment(self._delegate, self.header) + * + */ + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__deepcopy__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -11038,104 +13140,227 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16tostrin return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":821 - * property query_name: - * """the query template name (None if not present)""" - * def __get__(self): # <<<<<<<<<<<<<< - * cdef bam1_t * src - * src = self._delegate +/* "pysam/libcalignedsegment.pyx":990 + * return makeAlignedSegment(self._delegate, self.header) + * + * def compare(self, AlignedSegment other): # <<<<<<<<<<<<<< + * '''return -1,0,1, if contents in this are binary + * <,=,> to *other* */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_10compare[] = "AlignedSegment.compare(self, AlignedSegment other)\nreturn -1,0,1, if contents in this are binary\n <,=,> to *other*\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10query_name___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("compare (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment, 1, "other", 0))) __PYX_ERR(0, 990, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10compare(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_other)); /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10query_name___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - bam1_t *__pyx_v_src; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10compare(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_other) { + int __pyx_v_retval; + bam1_t *__pyx_v_t; + bam1_t *__pyx_v_o; + CYTHON_UNUSED uint8_t *__pyx_v_a; + CYTHON_UNUSED uint8_t *__pyx_v_b; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations bam1_t *__pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 821, 0, __PYX_ERR(0, 821, __pyx_L1_error)); + __Pyx_RefNannySetupContext("compare", 0); + __Pyx_TraceCall("compare", __pyx_f[0], 990, 0, __PYX_ERR(0, 990, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":823 - * def __get__(self): - * cdef bam1_t * src - * src = self._delegate # <<<<<<<<<<<<<< - * if pysam_get_l_qname(src) == 0: - * return None + /* "pysam/libcalignedsegment.pyx":999 + * cdef bam1_t *o + * + * t = self._delegate # <<<<<<<<<<<<<< + * o = other._delegate + * */ __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; + __pyx_v_t = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":824 - * cdef bam1_t * src - * src = self._delegate - * if pysam_get_l_qname(src) == 0: # <<<<<<<<<<<<<< - * return None - * return charptr_to_str(pysam_bam_get_qname(src)) + /* "pysam/libcalignedsegment.pyx":1000 + * + * t = self._delegate + * o = other._delegate # <<<<<<<<<<<<<< + * + * # uncomment for debugging purposes */ - __pyx_t_2 = ((pysam_get_l_qname(__pyx_v_src) == 0) != 0); - if (__pyx_t_2) { + __pyx_t_1 = __pyx_v_other->_delegate; + __pyx_v_o = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":825 - * src = self._delegate - * if pysam_get_l_qname(src) == 0: - * return None # <<<<<<<<<<<<<< - * return charptr_to_str(pysam_bam_get_qname(src)) + /* "pysam/libcalignedsegment.pyx":1012 + * + * # Fast-path test for object identity + * if t == o: # <<<<<<<<<<<<<< + * return 0 * + */ + __pyx_t_2 = ((__pyx_v_t == __pyx_v_o) != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":1013 + * # Fast-path test for object identity + * if t == o: + * return 0 # <<<<<<<<<<<<<< + * + * cdef uint8_t *a = &t.core */ __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_INCREF(__pyx_int_0); + __pyx_r = __pyx_int_0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":824 - * cdef bam1_t * src - * src = self._delegate - * if pysam_get_l_qname(src) == 0: # <<<<<<<<<<<<<< - * return None - * return charptr_to_str(pysam_bam_get_qname(src)) + /* "pysam/libcalignedsegment.pyx":1012 + * + * # Fast-path test for object identity + * if t == o: # <<<<<<<<<<<<<< + * return 0 + * */ } - /* "pysam/libcalignedsegment.pyx":826 - * if pysam_get_l_qname(src) == 0: - * return None - * return charptr_to_str(pysam_bam_get_qname(src)) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1015 + * return 0 * - * def __set__(self, qname): + * cdef uint8_t *a = &t.core # <<<<<<<<<<<<<< + * cdef uint8_t *b = &o.core + * + */ + __pyx_v_a = ((uint8_t *)(&__pyx_v_t->core)); + + /* "pysam/libcalignedsegment.pyx":1016 + * + * cdef uint8_t *a = &t.core + * cdef uint8_t *b = &o.core # <<<<<<<<<<<<<< + * + * retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t)) + */ + __pyx_v_b = ((uint8_t *)(&__pyx_v_o->core)); + + /* "pysam/libcalignedsegment.pyx":1018 + * cdef uint8_t *b = &o.core + * + * retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t)) # <<<<<<<<<<<<<< + * if retval: + * return retval + */ + __pyx_v_retval = memcmp((&__pyx_v_t->core), (&__pyx_v_o->core), (sizeof(bam1_core_t))); + + /* "pysam/libcalignedsegment.pyx":1019 + * + * retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t)) + * if retval: # <<<<<<<<<<<<<< + * return retval + * + */ + __pyx_t_2 = (__pyx_v_retval != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":1020 + * retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t)) + * if retval: + * return retval # <<<<<<<<<<<<<< + * + * # cmp(t.l_data, o.l_data) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_retval); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1020, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":1019 + * + * retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t)) + * if retval: # <<<<<<<<<<<<<< + * return retval + * + */ + } + + /* "pysam/libcalignedsegment.pyx":1023 + * + * # cmp(t.l_data, o.l_data) + * retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) # <<<<<<<<<<<<<< + * if retval: + * return retval + */ + __pyx_v_retval = ((__pyx_v_t->l_data > __pyx_v_o->l_data) - (__pyx_v_t->l_data < __pyx_v_o->l_data)); + + /* "pysam/libcalignedsegment.pyx":1024 + * # cmp(t.l_data, o.l_data) + * retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) + * if retval: # <<<<<<<<<<<<<< + * return retval + * return memcmp(t.data, o.data, t.l_data) + */ + __pyx_t_2 = (__pyx_v_retval != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":1025 + * retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) + * if retval: + * return retval # <<<<<<<<<<<<<< + * return memcmp(t.data, o.data, t.l_data) + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_retval); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":1024 + * # cmp(t.l_data, o.l_data) + * retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) + * if retval: # <<<<<<<<<<<<<< + * return retval + * return memcmp(t.data, o.data, t.l_data) + */ + } + + /* "pysam/libcalignedsegment.pyx":1026 + * if retval: + * return retval + * return memcmp(t.data, o.data, t.l_data) # <<<<<<<<<<<<<< + * + * def __richcmp__(self, AlignedSegment other, int op): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str(((char *)pysam_bam_get_qname(__pyx_v_src)), NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 826, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(memcmp(__pyx_v_t->data, __pyx_v_o->data, __pyx_v_t->l_data)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1026, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":821 - * property query_name: - * """the query template name (None if not present)""" - * def __get__(self): # <<<<<<<<<<<<<< - * cdef bam1_t * src - * src = self._delegate + /* "pysam/libcalignedsegment.pyx":990 + * return makeAlignedSegment(self._delegate, self.header) + * + * def compare(self, AlignedSegment other): # <<<<<<<<<<<<<< + * '''return -1,0,1, if contents in this are binary + * <,=,> to *other* */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.compare", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -11144,597 +13369,652 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10query_n return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":828 - * return charptr_to_str(pysam_bam_get_qname(src)) +/* "pysam/libcalignedsegment.pyx":1028 + * return memcmp(t.data, o.data, t.l_data) * - * def __set__(self, qname): # <<<<<<<<<<<<<< - * if qname is None or len(qname) == 0: - * return + * def __richcmp__(self, AlignedSegment other, int op): # <<<<<<<<<<<<<< + * if op == 2: # == operator + * return self.compare(other) == 0 */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_qname)); + __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment, 1, "other", 0))) __PYX_ERR(0, 1028, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12__richcmp__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_other), ((int)__pyx_v_op)); /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qname) { - bam1_t *__pyx_v_src; - int __pyx_v_l; - char *__pyx_v_p; - int __pyx_r; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12__richcmp__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_other, int __pyx_v_op) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - Py_ssize_t __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - bam1_t *__pyx_t_10; - char const *__pyx_t_11; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 828, 0, __PYX_ERR(0, 828, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_qname); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("__richcmp__", 0); + __Pyx_TraceCall("__richcmp__", __pyx_f[0], 1028, 0, __PYX_ERR(0, 1028, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":829 - * - * def __set__(self, qname): - * if qname is None or len(qname) == 0: # <<<<<<<<<<<<<< - * return + /* "pysam/libcalignedsegment.pyx":1029 * + * def __richcmp__(self, AlignedSegment other, int op): + * if op == 2: # == operator # <<<<<<<<<<<<<< + * return self.compare(other) == 0 + * elif op == 3: # != operator */ - __pyx_t_2 = (__pyx_v_qname == Py_None); - __pyx_t_3 = (__pyx_t_2 != 0); - if (!__pyx_t_3) { - } else { - __pyx_t_1 = __pyx_t_3; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_4 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 829, __pyx_L1_error) - __pyx_t_3 = ((__pyx_t_4 == 0) != 0); - __pyx_t_1 = __pyx_t_3; - __pyx_L4_bool_binop_done:; - if (__pyx_t_1) { + switch (__pyx_v_op) { + case 2: - /* "pysam/libcalignedsegment.pyx":830 - * def __set__(self, qname): - * if qname is None or len(qname) == 0: - * return # <<<<<<<<<<<<<< - * - * if len(qname) >= 255: + /* "pysam/libcalignedsegment.pyx":1030 + * def __richcmp__(self, AlignedSegment other, int op): + * if op == 2: # == operator + * return self.compare(other) == 0 # <<<<<<<<<<<<<< + * elif op == 3: # != operator + * return self.compare(other) != 0 */ - __pyx_r = 0; + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_compare); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1030, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1030, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_other)}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1030, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_other)}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1030, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1030, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(((PyObject *)__pyx_v_other)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_other)); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_other)); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1030, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1030, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":829 - * - * def __set__(self, qname): - * if qname is None or len(qname) == 0: # <<<<<<<<<<<<<< - * return - * - */ - } - - /* "pysam/libcalignedsegment.pyx":832 - * return + /* "pysam/libcalignedsegment.pyx":1029 * - * if len(qname) >= 255: # <<<<<<<<<<<<<< - * raise ValueError("query length out of range {} > 254".format( - * len(qname))) + * def __richcmp__(self, AlignedSegment other, int op): + * if op == 2: # == operator # <<<<<<<<<<<<<< + * return self.compare(other) == 0 + * elif op == 3: # != operator */ - __pyx_t_4 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 832, __pyx_L1_error) - __pyx_t_1 = ((__pyx_t_4 >= 0xFF) != 0); - if (unlikely(__pyx_t_1)) { + break; - /* "pysam/libcalignedsegment.pyx":833 - * - * if len(qname) >= 255: - * raise ValueError("query length out of range {} > 254".format( # <<<<<<<<<<<<<< - * len(qname))) - * + /* "pysam/libcalignedsegment.pyx":1031 + * if op == 2: # == operator + * return self.compare(other) == 0 + * elif op == 3: # != operator # <<<<<<<<<<<<<< + * return self.compare(other) != 0 + * else: */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_query_length_out_of_range_254, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 833, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); + case 3: - /* "pysam/libcalignedsegment.pyx":834 - * if len(qname) >= 255: - * raise ValueError("query length out of range {} > 254".format( - * len(qname))) # <<<<<<<<<<<<<< - * - * qname = force_bytes(qname) + /* "pysam/libcalignedsegment.pyx":1032 + * return self.compare(other) == 0 + * elif op == 3: # != operator + * return self.compare(other) != 0 # <<<<<<<<<<<<<< + * else: + * return NotImplemented */ - __pyx_t_4 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 834, __pyx_L1_error) - __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 834, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_compare); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1032, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); + __Pyx_DECREF_SET(__pyx_t_1, function); } } - if (!__pyx_t_8) { - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 833, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_5); + if (!__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1032, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; - __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 833, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_other)}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1032, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; - __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 833, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_other)}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1032, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 833, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 833, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1032, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_INCREF(((PyObject *)__pyx_v_other)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_other)); + PyTuple_SET_ITEM(__pyx_t_3, 0+1, ((PyObject *)__pyx_v_other)); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1032, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1032, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":833 - * - * if len(qname) >= 255: - * raise ValueError("query length out of range {} > 254".format( # <<<<<<<<<<<<<< - * len(qname))) - * + /* "pysam/libcalignedsegment.pyx":1031 + * if op == 2: # == operator + * return self.compare(other) == 0 + * elif op == 3: # != operator # <<<<<<<<<<<<<< + * return self.compare(other) != 0 + * else: */ - __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 833, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 833, __pyx_L1_error) + break; + default: - /* "pysam/libcalignedsegment.pyx":832 - * return + /* "pysam/libcalignedsegment.pyx":1034 + * return self.compare(other) != 0 + * else: + * return NotImplemented # <<<<<<<<<<<<<< * - * if len(qname) >= 255: # <<<<<<<<<<<<<< - * raise ValueError("query length out of range {} > 254".format( - * len(qname))) + * def __hash__(self): */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_builtin_NotImplemented); + __pyx_r = __pyx_builtin_NotImplemented; + goto __pyx_L0; + break; } - /* "pysam/libcalignedsegment.pyx":836 - * len(qname))) - * - * qname = force_bytes(qname) # <<<<<<<<<<<<<< - * cdef bam1_t * src - * cdef int l - */ - __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_qname, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 836, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF_SET(__pyx_v_qname, __pyx_t_6); - __pyx_t_6 = 0; - - /* "pysam/libcalignedsegment.pyx":841 - * cdef char * p - * - * src = self._delegate # <<<<<<<<<<<<<< - * p = pysam_bam_get_qname(src) - * - */ - __pyx_t_10 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_10; - - /* "pysam/libcalignedsegment.pyx":842 - * - * src = self._delegate - * p = pysam_bam_get_qname(src) # <<<<<<<<<<<<<< - * - * # the qname is \0 terminated - */ - __pyx_v_p = pysam_bam_get_qname(__pyx_v_src); - - /* "pysam/libcalignedsegment.pyx":845 - * - * # the qname is \0 terminated - * l = len(qname) + 1 # <<<<<<<<<<<<<< - * pysam_bam_update(src, - * pysam_get_l_qname(src), - */ - __pyx_t_4 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 845, __pyx_L1_error) - __pyx_v_l = (__pyx_t_4 + 1); - - /* "pysam/libcalignedsegment.pyx":846 - * # the qname is \0 terminated - * l = len(qname) + 1 - * pysam_bam_update(src, # <<<<<<<<<<<<<< - * pysam_get_l_qname(src), - * l, - */ - (void)(pysam_bam_update(__pyx_v_src, pysam_get_l_qname(__pyx_v_src), __pyx_v_l, ((uint8_t *)__pyx_v_p))); - - /* "pysam/libcalignedsegment.pyx":851 - * p) - * - * pysam_set_l_qname(src, l) # <<<<<<<<<<<<<< - * - * # re-acquire pointer to location in memory - */ - pysam_set_l_qname(__pyx_v_src, __pyx_v_l); - - /* "pysam/libcalignedsegment.pyx":855 - * # re-acquire pointer to location in memory - * # as it might have moved - * p = pysam_bam_get_qname(src) # <<<<<<<<<<<<<< - * - * strncpy(p, qname, l) - */ - __pyx_v_p = pysam_bam_get_qname(__pyx_v_src); - - /* "pysam/libcalignedsegment.pyx":857 - * p = pysam_bam_get_qname(src) - * - * strncpy(p, qname, l) # <<<<<<<<<<<<<< - * - * property flag: - */ - __pyx_t_11 = __Pyx_PyObject_AsString(__pyx_v_qname); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) __PYX_ERR(0, 857, __pyx_L1_error) - (void)(strncpy(__pyx_v_p, __pyx_t_11, __pyx_v_l)); - - /* "pysam/libcalignedsegment.pyx":828 - * return charptr_to_str(pysam_bam_get_qname(src)) + /* "pysam/libcalignedsegment.pyx":1028 + * return memcmp(t.data, o.data, t.l_data) * - * def __set__(self, qname): # <<<<<<<<<<<<<< - * if qname is None or len(qname) == 0: - * return + * def __richcmp__(self, AlignedSegment other, int op): # <<<<<<<<<<<<<< + * if op == 2: # == operator + * return self.compare(other) == 0 */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_name.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_qname); - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":861 - * property flag: - * """properties flag""" - * def __get__(self): # <<<<<<<<<<<<<< - * return pysam_get_flag(self._delegate) - * def __set__(self, flag): +/* "pysam/libcalignedsegment.pyx":1036 + * return NotImplemented + * + * def __hash__(self): # <<<<<<<<<<<<<< + * cdef bam1_t * src = self._delegate + * cdef int x */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4flag_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4flag_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static Py_hash_t __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15__hash__(PyObject *__pyx_v_self); /*proto*/ +static Py_hash_t __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15__hash__(PyObject *__pyx_v_self) { + Py_hash_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4flag___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14__hash__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4flag___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static Py_hash_t __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14__hash__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + bam1_t *__pyx_v_src; + int __pyx_v_x; + uint8_t *__pyx_v_c; + uint32_t __pyx_v_hash_value; + Py_hash_t __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 861, 0, __PYX_ERR(0, 861, __pyx_L1_error)); + bam1_t *__pyx_t_1; + size_t __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("__hash__", 0); + __Pyx_TraceCall("__hash__", __pyx_f[0], 1036, 0, __PYX_ERR(0, 1036, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":862 - * """properties flag""" - * def __get__(self): - * return pysam_get_flag(self._delegate) # <<<<<<<<<<<<<< - * def __set__(self, flag): - * pysam_set_flag(self._delegate, flag) + /* "pysam/libcalignedsegment.pyx":1037 + * + * def __hash__(self): + * cdef bam1_t * src = self._delegate # <<<<<<<<<<<<<< + * cdef int x + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint16_t(pysam_get_flag(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 862, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_1 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":861 - * property flag: - * """properties flag""" - * def __get__(self): # <<<<<<<<<<<<<< - * return pysam_get_flag(self._delegate) - * def __set__(self, flag): + /* "pysam/libcalignedsegment.pyx":1041 + * + * # see http://effbot.org/zone/python-hash.htm + * cdef uint8_t * c = &src.core # <<<<<<<<<<<<<< + * cdef uint32_t hash_value = c[0] + * for x from 1 <= x < sizeof(bam1_core_t): */ + __pyx_v_c = ((uint8_t *)(&__pyx_v_src->core)); - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.flag.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1042 + * # see http://effbot.org/zone/python-hash.htm + * cdef uint8_t * c = &src.core + * cdef uint32_t hash_value = c[0] # <<<<<<<<<<<<<< + * for x from 1 <= x < sizeof(bam1_core_t): + * hash_value = c_mul(hash_value, 1000003) ^ c[x] + */ + __pyx_v_hash_value = (__pyx_v_c[0]); -/* "pysam/libcalignedsegment.pyx":863 - * def __get__(self): - * return pysam_get_flag(self._delegate) - * def __set__(self, flag): # <<<<<<<<<<<<<< - * pysam_set_flag(self._delegate, flag) - * + /* "pysam/libcalignedsegment.pyx":1043 + * cdef uint8_t * c = &src.core + * cdef uint32_t hash_value = c[0] + * for x from 1 <= x < sizeof(bam1_core_t): # <<<<<<<<<<<<<< + * hash_value = c_mul(hash_value, 1000003) ^ c[x] + * c = src.data */ + __pyx_t_2 = (sizeof(bam1_core_t)); + for (__pyx_v_x = 1; __pyx_v_x < __pyx_t_2; __pyx_v_x++) { -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4flag_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4flag_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4flag_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_flag)); + /* "pysam/libcalignedsegment.pyx":1044 + * cdef uint32_t hash_value = c[0] + * for x from 1 <= x < sizeof(bam1_core_t): + * hash_value = c_mul(hash_value, 1000003) ^ c[x] # <<<<<<<<<<<<<< + * c = src.data + * for x from 0 <= x < src.l_data: + */ + __pyx_v_hash_value = (__pyx_f_5pysam_18libcalignedsegment_c_mul(__pyx_v_hash_value, 0xF4243) ^ (__pyx_v_c[__pyx_v_x])); + } - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1045 + * for x from 1 <= x < sizeof(bam1_core_t): + * hash_value = c_mul(hash_value, 1000003) ^ c[x] + * c = src.data # <<<<<<<<<<<<<< + * for x from 0 <= x < src.l_data: + * hash_value = c_mul(hash_value, 1000003) ^ c[x] + */ + __pyx_v_c = ((uint8_t *)__pyx_v_src->data); -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4flag_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_flag) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 863, 0, __PYX_ERR(0, 863, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":1046 + * hash_value = c_mul(hash_value, 1000003) ^ c[x] + * c = src.data + * for x from 0 <= x < src.l_data: # <<<<<<<<<<<<<< + * hash_value = c_mul(hash_value, 1000003) ^ c[x] + * + */ + __pyx_t_3 = __pyx_v_src->l_data; + for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) { - /* "pysam/libcalignedsegment.pyx":864 - * return pysam_get_flag(self._delegate) - * def __set__(self, flag): - * pysam_set_flag(self._delegate, flag) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1047 + * c = src.data + * for x from 0 <= x < src.l_data: + * hash_value = c_mul(hash_value, 1000003) ^ c[x] # <<<<<<<<<<<<<< * - * property reference_name: + * return hash_value + */ + __pyx_v_hash_value = (__pyx_f_5pysam_18libcalignedsegment_c_mul(__pyx_v_hash_value, 0xF4243) ^ (__pyx_v_c[__pyx_v_x])); + } + + /* "pysam/libcalignedsegment.pyx":1049 + * hash_value = c_mul(hash_value, 1000003) ^ c[x] + * + * return hash_value # <<<<<<<<<<<<<< + * + * cpdef to_string(self): */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_flag); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 864, __pyx_L1_error) - pysam_set_flag(__pyx_v_self->_delegate, __pyx_t_1); + __pyx_r = __pyx_v_hash_value; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":863 - * def __get__(self): - * return pysam_get_flag(self._delegate) - * def __set__(self, flag): # <<<<<<<<<<<<<< - * pysam_set_flag(self._delegate, flag) + /* "pysam/libcalignedsegment.pyx":1036 + * return NotImplemented * + * def __hash__(self): # <<<<<<<<<<<<<< + * cdef bam1_t * src = self._delegate + * cdef int x */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.flag.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; + if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2; __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":868 - * property reference_name: - * """:term:`reference` name (None if no AlignmentFile is associated)""" - * def __get__(self): # <<<<<<<<<<<<<< - * if self._alignment_file is not None: - * return self._alignment_file.getrname(self._delegate.core.tid) +/* "pysam/libcalignedsegment.pyx":1051 + * return hash_value + * + * cpdef to_string(self): # <<<<<<<<<<<<<< + * """returns a string representation of the aligned segment. + * */ -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17to_string(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_to_string(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, int __pyx_skip_dispatch) { + kstring_t __pyx_v_line; + PyObject *__pyx_v_ret = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 868, 0, __PYX_ERR(0, 868, __pyx_L1_error)); + int __pyx_t_5; + __Pyx_RefNannySetupContext("to_string", 0); + __Pyx_TraceCall("to_string", __pyx_f[0], 1051, 0, __PYX_ERR(0, 1051, __pyx_L1_error)); + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_string); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1051, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17to_string)) { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1051, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1051, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } - /* "pysam/libcalignedsegment.pyx":869 - * """:term:`reference` name (None if no AlignmentFile is associated)""" - * def __get__(self): - * if self._alignment_file is not None: # <<<<<<<<<<<<<< - * return self._alignment_file.getrname(self._delegate.core.tid) - * return None + /* "pysam/libcalignedsegment.pyx":1058 + * """ + * cdef kstring_t line + * line.l = line.m = 0 # <<<<<<<<<<<<<< + * line.s = NULL + * */ - __pyx_t_1 = (((PyObject *)__pyx_v_self->_alignment_file) != Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __pyx_v_line.l = 0; + __pyx_v_line.m = 0; - /* "pysam/libcalignedsegment.pyx":870 - * def __get__(self): - * if self._alignment_file is not None: - * return self._alignment_file.getrname(self._delegate.core.tid) # <<<<<<<<<<<<<< - * return None + /* "pysam/libcalignedsegment.pyx":1059 + * cdef kstring_t line + * line.l = line.m = 0 + * line.s = NULL # <<<<<<<<<<<<<< * + * if self.header: + */ + __pyx_v_line.s = NULL; + + /* "pysam/libcalignedsegment.pyx":1061 + * line.s = NULL + * + * if self.header: # <<<<<<<<<<<<<< + * if sam_format1(self.header.ptr, self._delegate, &line) < 0: + * if line.m: + */ + __pyx_t_5 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1061, __pyx_L1_error) + if (likely(__pyx_t_5)) { + + /* "pysam/libcalignedsegment.pyx":1062 + * + * if self.header: + * if sam_format1(self.header.ptr, self._delegate, &line) < 0: # <<<<<<<<<<<<<< + * if line.m: + * free(line.s) + */ + __pyx_t_5 = ((sam_format1(__pyx_v_self->header->ptr, __pyx_v_self->_delegate, (&__pyx_v_line)) < 0) != 0); + if (__pyx_t_5) { + + /* "pysam/libcalignedsegment.pyx":1063 + * if self.header: + * if sam_format1(self.header.ptr, self._delegate, &line) < 0: + * if line.m: # <<<<<<<<<<<<<< + * free(line.s) + * raise ValueError('sam_format failed') + */ + __pyx_t_5 = (__pyx_v_line.m != 0); + if (__pyx_t_5) { + + /* "pysam/libcalignedsegment.pyx":1064 + * if sam_format1(self.header.ptr, self._delegate, &line) < 0: + * if line.m: + * free(line.s) # <<<<<<<<<<<<<< + * raise ValueError('sam_format failed') + * else: + */ + free(__pyx_v_line.s); + + /* "pysam/libcalignedsegment.pyx":1063 + * if self.header: + * if sam_format1(self.header.ptr, self._delegate, &line) < 0: + * if line.m: # <<<<<<<<<<<<<< + * free(line.s) + * raise ValueError('sam_format failed') */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->_alignment_file), __pyx_n_s_getrname); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 870, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 870, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 870, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 870, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 870, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 870, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 870, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } + + /* "pysam/libcalignedsegment.pyx":1065 + * if line.m: + * free(line.s) + * raise ValueError('sam_format failed') # <<<<<<<<<<<<<< + * else: + * raise NotImplementedError("todo") + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1065, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 1065, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":1062 + * + * if self.header: + * if sam_format1(self.header.ptr, self._delegate, &line) < 0: # <<<<<<<<<<<<<< + * if line.m: + * free(line.s) + */ } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":869 - * """:term:`reference` name (None if no AlignmentFile is associated)""" - * def __get__(self): - * if self._alignment_file is not None: # <<<<<<<<<<<<<< - * return self._alignment_file.getrname(self._delegate.core.tid) - * return None + /* "pysam/libcalignedsegment.pyx":1061 + * line.s = NULL + * + * if self.header: # <<<<<<<<<<<<<< + * if sam_format1(self.header.ptr, self._delegate, &line) < 0: + * if line.m: */ + goto __pyx_L3; } - /* "pysam/libcalignedsegment.pyx":871 - * if self._alignment_file is not None: - * return self._alignment_file.getrname(self._delegate.core.tid) - * return None # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1067 + * raise ValueError('sam_format failed') + * else: + * raise NotImplementedError("todo") # <<<<<<<<<<<<<< + * + * ret = force_str(line.s[:line.l]) + */ + /*else*/ { + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1067, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 1067, __pyx_L1_error) + } + __pyx_L3:; + + /* "pysam/libcalignedsegment.pyx":1069 + * raise NotImplementedError("todo") + * + * ret = force_str(line.s[:line.l]) # <<<<<<<<<<<<<< + * + * if line.m: + */ + __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_line.s + 0, __pyx_v_line.l - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1069, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1069, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_ret = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pysam/libcalignedsegment.pyx":1071 + * ret = force_str(line.s[:line.l]) + * + * if line.m: # <<<<<<<<<<<<<< + * free(line.s) * - * property reference_id: + */ + __pyx_t_5 = (__pyx_v_line.m != 0); + if (__pyx_t_5) { + + /* "pysam/libcalignedsegment.pyx":1072 + * + * if line.m: + * free(line.s) # <<<<<<<<<<<<<< + * + * return ret + */ + free(__pyx_v_line.s); + + /* "pysam/libcalignedsegment.pyx":1071 + * ret = force_str(line.s[:line.l]) + * + * if line.m: # <<<<<<<<<<<<<< + * free(line.s) + * + */ + } + + /* "pysam/libcalignedsegment.pyx":1074 + * free(line.s) + * + * return ret # <<<<<<<<<<<<<< + * + * @classmethod */ __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_INCREF(__pyx_v_ret); + __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":868 - * property reference_name: - * """:term:`reference` name (None if no AlignmentFile is associated)""" - * def __get__(self): # <<<<<<<<<<<<<< - * if self._alignment_file is not None: - * return self._alignment_file.getrname(self._delegate.core.tid) + /* "pysam/libcalignedsegment.pyx":1051 + * return hash_value + * + * cpdef to_string(self): # <<<<<<<<<<<<<< + * """returns a string representation of the aligned segment. + * */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.to_string", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ret); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":884 - * - * """ - * def __get__(self): return self._delegate.core.tid # <<<<<<<<<<<<<< - * def __set__(self, tid): self._delegate.core.tid = tid - * - */ - /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17to_string(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_16to_string[] = "AlignedSegment.to_string(self)\nreturns a string representation of the aligned segment.\n\n The output format is valid SAM format if a header is associated\n with the AlignedSegment.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17to_string(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("to_string (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16to_string(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16to_string(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 884, 0, __PYX_ERR(0, 884, __pyx_L1_error)); + __Pyx_RefNannySetupContext("to_string", 0); + __Pyx_TraceCall("to_string (wrapper)", __pyx_f[0], 1051, 0, __PYX_ERR(0, 1051, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 884, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_to_string(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1051, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -11743,7 +14023,7 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12referen /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_id.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.to_string", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -11752,272 +14032,415 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12referen return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":885 - * """ - * def __get__(self): return self._delegate.core.tid - * def __set__(self, tid): self._delegate.core.tid = tid # <<<<<<<<<<<<<< +/* "pysam/libcalignedsegment.pyx":1077 + * + * @classmethod + * def fromstring(cls, sam, AlignmentHeader header): # <<<<<<<<<<<<<< + * """parses a string representation of the aligned segment. * - * property reference_start: */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19fromstring(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_18fromstring[] = "AlignedSegment.fromstring(type cls, sam, AlignmentHeader header)\nparses a string representation of the aligned segment.\n\n The input format should be valid SAM format.\n\n Parameters\n ----------\n sam -- :term:`SAM` formatted string\n\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19fromstring(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_sam = 0; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header = 0; + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tid)); - - /* function exit code */ + __Pyx_RefNannySetupContext("fromstring (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sam,&__pyx_n_s_header,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sam)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_header)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("fromstring", 1, 2, 2, 1); __PYX_ERR(0, 1077, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fromstring") < 0)) __PYX_ERR(0, 1077, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_sam = values[0]; + __pyx_v_header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)values[1]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("fromstring", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1077, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.fromstring", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tid) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int32_t __pyx_t_1; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 885, 0, __PYX_ERR(0, 885, __pyx_L1_error)); - __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_tid); if (unlikely((__pyx_t_1 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 885, __pyx_L1_error) - __pyx_v_self->_delegate->core.tid = __pyx_t_1; + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_header), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, 1, "header", 0))) __PYX_ERR(0, 1077, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_18fromstring(((PyTypeObject*)__pyx_v_cls), __pyx_v_sam, __pyx_v_header); /* function exit code */ - __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_id.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":889 - * property reference_start: - * """0-based leftmost coordinate""" - * def __get__(self): return self._delegate.core.pos # <<<<<<<<<<<<<< - * def __set__(self, pos): - * ## setting the position requires updating the "bin" attribute - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_18fromstring(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_sam, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header) { + struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_dest = 0; + kstring_t __pyx_v_line; + PyObject *__pyx_v__sam = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 889, 0, __PYX_ERR(0, 889, __pyx_L1_error)); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 889, __pyx_L1_error) + Py_ssize_t __pyx_t_2; + char *__pyx_t_3; + __Pyx_RefNannySetupContext("fromstring", 0); + __Pyx_TraceCall("fromstring", __pyx_f[0], 1077, 0, __PYX_ERR(0, 1077, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1087 + * + * """ + * cdef AlignedSegment dest = cls.__new__(cls) # <<<<<<<<<<<<<< + * dest._delegate = calloc(1, sizeof(bam1_t)) + * dest.header = header + */ + if (unlikely(((PyObject *)__pyx_v_cls) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object.__new__(X): X is not a type object (NoneType)"); + __PYX_ERR(0, 1087, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_tp_new(((PyObject *)__pyx_v_cls), __pyx_empty_tuple); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1087, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment)))) __PYX_ERR(0, 1087, __pyx_L1_error) + __pyx_v_dest = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignedsegment.pyx":1088 + * """ + * cdef AlignedSegment dest = cls.__new__(cls) + * dest._delegate = calloc(1, sizeof(bam1_t)) # <<<<<<<<<<<<<< + * dest.header = header + * + */ + __pyx_v_dest->_delegate = ((bam1_t *)calloc(1, (sizeof(bam1_t)))); + + /* "pysam/libcalignedsegment.pyx":1089 + * cdef AlignedSegment dest = cls.__new__(cls) + * dest._delegate = calloc(1, sizeof(bam1_t)) + * dest.header = header # <<<<<<<<<<<<<< + * + * cdef kstring_t line + */ + __Pyx_INCREF(((PyObject *)__pyx_v_header)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_header)); + __Pyx_GOTREF(__pyx_v_dest->header); + __Pyx_DECREF(((PyObject *)__pyx_v_dest->header)); + __pyx_v_dest->header = __pyx_v_header; + + /* "pysam/libcalignedsegment.pyx":1092 + * + * cdef kstring_t line + * line.l = line.m = len(sam) # <<<<<<<<<<<<<< + * _sam = force_bytes(sam) + * line.s = _sam + */ + __pyx_t_2 = PyObject_Length(__pyx_v_sam); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1092, __pyx_L1_error) + __pyx_v_line.l = __pyx_t_2; + __pyx_v_line.m = __pyx_t_2; + + /* "pysam/libcalignedsegment.pyx":1093 + * cdef kstring_t line + * line.l = line.m = len(sam) + * _sam = force_bytes(sam) # <<<<<<<<<<<<<< + * line.s = _sam + * + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_sam, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1093, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v__sam = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcalignedsegment.pyx":1094 + * line.l = line.m = len(sam) + * _sam = force_bytes(sam) + * line.s = _sam # <<<<<<<<<<<<<< + * + * sam_parse1(&line, dest.header.ptr, dest._delegate) + */ + if (unlikely(__pyx_v__sam == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 1094, __pyx_L1_error) + } + __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v__sam); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 1094, __pyx_L1_error) + __pyx_v_line.s = __pyx_t_3; + + /* "pysam/libcalignedsegment.pyx":1096 + * line.s = _sam + * + * sam_parse1(&line, dest.header.ptr, dest._delegate) # <<<<<<<<<<<<<< + * + * return dest + */ + (void)(sam_parse1((&__pyx_v_line), __pyx_v_dest->header->ptr, __pyx_v_dest->_delegate)); + + /* "pysam/libcalignedsegment.pyx":1098 + * sam_parse1(&line, dest.header.ptr, dest._delegate) + * + * return dest # <<<<<<<<<<<<<< + * + * cpdef tostring(self, htsfile=None): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_dest)); + __pyx_r = ((PyObject *)__pyx_v_dest); goto __pyx_L0; + /* "pysam/libcalignedsegment.pyx":1077 + * + * @classmethod + * def fromstring(cls, sam, AlignmentHeader header): # <<<<<<<<<<<<<< + * """parses a string representation of the aligned segment. + * + */ + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_start.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.fromstring", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_dest); + __Pyx_XDECREF(__pyx_v__sam); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":890 - * """0-based leftmost coordinate""" - * def __get__(self): return self._delegate.core.pos - * def __set__(self, pos): # <<<<<<<<<<<<<< - * ## setting the position requires updating the "bin" attribute - * cdef bam1_t * src +/* "pysam/libcalignedsegment.pyx":1100 + * return dest + * + * cpdef tostring(self, htsfile=None): # <<<<<<<<<<<<<< + * """deprecated, use :meth:`to_string()` instead. + * */ -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_pos)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_pos) { - bam1_t *__pyx_v_src; - int __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21tostring(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_tostring(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring *__pyx_optional_args) { + PyObject *__pyx_v_htsfile = ((PyObject *)Py_None); + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; - int32_t __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 890, 0, __PYX_ERR(0, 890, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":893 - * ## setting the position requires updating the "bin" attribute - * cdef bam1_t * src - * src = self._delegate # <<<<<<<<<<<<<< - * src.core.pos = pos - * if pysam_get_n_cigar(src): - */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; - - /* "pysam/libcalignedsegment.pyx":894 - * cdef bam1_t * src - * src = self._delegate - * src.core.pos = pos # <<<<<<<<<<<<<< - * if pysam_get_n_cigar(src): - * pysam_set_bin(src, - */ - __pyx_t_2 = __Pyx_PyInt_As_int32_t(__pyx_v_pos); if (unlikely((__pyx_t_2 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 894, __pyx_L1_error) - __pyx_v_src->core.pos = __pyx_t_2; - - /* "pysam/libcalignedsegment.pyx":895 - * src = self._delegate - * src.core.pos = pos - * if pysam_get_n_cigar(src): # <<<<<<<<<<<<<< - * pysam_set_bin(src, - * hts_reg2bin( - */ - __pyx_t_3 = (pysam_get_n_cigar(__pyx_v_src) != 0); - if (__pyx_t_3) { - - /* "pysam/libcalignedsegment.pyx":896 - * src.core.pos = pos - * if pysam_get_n_cigar(src): - * pysam_set_bin(src, # <<<<<<<<<<<<<< - * hts_reg2bin( - * src.core.pos, - */ - pysam_set_bin(__pyx_v_src, hts_reg2bin(__pyx_v_src->core.pos, bam_endpos(__pyx_v_src), 14, 5)); - - /* "pysam/libcalignedsegment.pyx":895 - * src = self._delegate - * src.core.pos = pos - * if pysam_get_n_cigar(src): # <<<<<<<<<<<<<< - * pysam_set_bin(src, - * hts_reg2bin( - */ - goto __pyx_L3; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("tostring", 0); + __Pyx_TraceCall("tostring", __pyx_f[0], 1100, 0, __PYX_ERR(0, 1100, __pyx_L1_error)); + if (__pyx_optional_args) { + if (__pyx_optional_args->__pyx_n > 0) { + __pyx_v_htsfile = __pyx_optional_args->htsfile; + } + } + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tostring); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1100, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21tostring)) { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_htsfile); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1100, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_htsfile}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1100, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_htsfile}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1100, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1100, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_INCREF(__pyx_v_htsfile); + __Pyx_GIVEREF(__pyx_v_htsfile); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_htsfile); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1100, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - /* "pysam/libcalignedsegment.pyx":903 - * 5)) - * else: - * pysam_set_bin(src, # <<<<<<<<<<<<<< - * hts_reg2bin( - * src.core.pos, - */ - /*else*/ { - - /* "pysam/libcalignedsegment.pyx":904 - * else: - * pysam_set_bin(src, - * hts_reg2bin( # <<<<<<<<<<<<<< - * src.core.pos, - * src.core.pos + 1, + /* "pysam/libcalignedsegment.pyx":1111 + * """ + * + * return self.to_string() # <<<<<<<<<<<<<< + * + * def to_dict(self): */ - pysam_set_bin(__pyx_v_src, hts_reg2bin(__pyx_v_src->core.pos, (__pyx_v_src->core.pos + 1), 14, 5)); - } - __pyx_L3:; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self->__pyx_vtab)->to_string(__pyx_v_self, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":890 - * """0-based leftmost coordinate""" - * def __get__(self): return self._delegate.core.pos - * def __set__(self, pos): # <<<<<<<<<<<<<< - * ## setting the position requires updating the "bin" attribute - * cdef bam1_t * src + /* "pysam/libcalignedsegment.pyx":1100 + * return dest + * + * cpdef tostring(self, htsfile=None): # <<<<<<<<<<<<<< + * """deprecated, use :meth:`to_string()` instead. + * */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_start.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":912 - * property mapping_quality: - * """mapping quality""" - * def __get__(self): # <<<<<<<<<<<<<< - * return pysam_get_qual(self._delegate) - * def __set__(self, qual): - */ - /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21tostring(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_20tostring[] = "AlignedSegment.tostring(self, htsfile=None)\ndeprecated, use :meth:`to_string()` instead.\n\n Parameters\n ----------\n\n htsfile -- (deprecated) AlignmentFile object to map numerical\n identifiers to chromosome names. This parameter is present\n for backwards compatibility and ignored.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21tostring(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_htsfile = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("tostring (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_htsfile,0}; + PyObject* values[1] = {0}; + values[0] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_htsfile); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tostring") < 0)) __PYX_ERR(0, 1100, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_htsfile = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("tostring", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1100, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20tostring(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_htsfile); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20tostring(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_htsfile) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 912, 0, __PYX_ERR(0, 912, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":913 - * """mapping quality""" - * def __get__(self): - * return pysam_get_qual(self._delegate) # <<<<<<<<<<<<<< - * def __set__(self, qual): - * pysam_set_qual(self._delegate, qual) - */ + struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring __pyx_t_2; + __Pyx_RefNannySetupContext("tostring", 0); + __Pyx_TraceCall("tostring (wrapper)", __pyx_f[0], 1100, 0, __PYX_ERR(0, 1100, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint8_t(pysam_get_qual(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 913, __pyx_L1_error) + __pyx_t_2.__pyx_n = 1; + __pyx_t_2.htsfile = __pyx_v_htsfile; + __pyx_t_1 = __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment->tostring(__pyx_v_self, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1100, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":912 - * property mapping_quality: - * """mapping quality""" - * def __get__(self): # <<<<<<<<<<<<<< - * return pysam_get_qual(self._delegate) - * def __set__(self, qual): - */ - /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mapping_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -12026,641 +14449,719 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mapping return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":914 - * def __get__(self): - * return pysam_get_qual(self._delegate) - * def __set__(self, qual): # <<<<<<<<<<<<<< - * pysam_set_qual(self._delegate, qual) - * - */ - -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_qual)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qual) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - uint8_t __pyx_t_1; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 914, 0, __PYX_ERR(0, 914, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":915 - * return pysam_get_qual(self._delegate) - * def __set__(self, qual): - * pysam_set_qual(self._delegate, qual) # <<<<<<<<<<<<<< +/* "pysam/libcalignedsegment.pyx":1113 + * return self.to_string() * - * property cigarstring: - */ - __pyx_t_1 = __Pyx_PyInt_As_uint8_t(__pyx_v_qual); if (unlikely((__pyx_t_1 == ((uint8_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 915, __pyx_L1_error) - pysam_set_qual(__pyx_v_self->_delegate, __pyx_t_1); - - /* "pysam/libcalignedsegment.pyx":914 - * def __get__(self): - * return pysam_get_qual(self._delegate) - * def __set__(self, qual): # <<<<<<<<<<<<<< - * pysam_set_qual(self._delegate, qual) + * def to_dict(self): # <<<<<<<<<<<<<< + * """returns a json representation of the aligned segment. * */ - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mapping_quality.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":934 - * empty string. - * ''' - * def __get__(self): # <<<<<<<<<<<<<< - * c = self.cigartuples - * if c is None: - */ - /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_23to_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_22to_dict[] = "AlignedSegment.to_dict(self)\nreturns a json representation of the aligned segment.\n\n Field names are abbreviated versions of the class attributes.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_23to_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("to_dict (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_22to_dict(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_v_c = NULL; - PyObject *__pyx_v_x = NULL; - PyObject *__pyx_v_y = NULL; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_22to_dict(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_v_vals = NULL; + Py_ssize_t __pyx_v_n; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; PyObject *__pyx_t_4 = NULL; - Py_ssize_t __pyx_t_5; - PyObject *(*__pyx_t_6)(PyObject *); - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *(*__pyx_t_11)(PyObject *); - Py_ssize_t __pyx_t_12; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 934, 0, __PYX_ERR(0, 934, __pyx_L1_error)); + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("to_dict", 0); + __Pyx_TraceCall("to_dict", __pyx_f[0], 1113, 0, __PYX_ERR(0, 1113, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":935 - * ''' - * def __get__(self): - * c = self.cigartuples # <<<<<<<<<<<<<< - * if c is None: - * return None + /* "pysam/libcalignedsegment.pyx":1119 + * """ + * # let htslib do the string conversions, but treat optional field properly as list + * vals = self.to_string().split("\t") # <<<<<<<<<<<<<< + * n = len(KEY_NAMES) - 1 + * return dict(list(zip(KEY_NAMES[:-1], vals[:n])) + [(KEY_NAMES[-1], vals[n:])]) */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 935, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self->__pyx_vtab)->to_string(__pyx_v_self, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1119, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_v_c = __pyx_t_1; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_split); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_vals = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":936 - * def __get__(self): - * c = self.cigartuples - * if c is None: # <<<<<<<<<<<<<< - * return None - * # reverse order - */ - __pyx_t_2 = (__pyx_v_c == Py_None); - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { - - /* "pysam/libcalignedsegment.pyx":937 - * c = self.cigartuples - * if c is None: - * return None # <<<<<<<<<<<<<< - * # reverse order - * else: - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":936 - * def __get__(self): - * c = self.cigartuples - * if c is None: # <<<<<<<<<<<<<< - * return None - * # reverse order + /* "pysam/libcalignedsegment.pyx":1120 + * # let htslib do the string conversions, but treat optional field properly as list + * vals = self.to_string().split("\t") + * n = len(KEY_NAMES) - 1 # <<<<<<<<<<<<<< + * return dict(list(zip(KEY_NAMES[:-1], vals[:n])) + [(KEY_NAMES[-1], vals[n:])]) + * */ - } + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_KEY_NAMES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1120, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1120, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_n = (__pyx_t_3 - 1); - /* "pysam/libcalignedsegment.pyx":940 - * # reverse order - * else: - * return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c]) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1121 + * vals = self.to_string().split("\t") + * n = len(KEY_NAMES) - 1 + * return dict(list(zip(KEY_NAMES[:-1], vals[:n])) + [(KEY_NAMES[-1], vals[n:])]) # <<<<<<<<<<<<<< * - * def __set__(self, cigar): + * @classmethod */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (likely(PyList_CheckExact(__pyx_v_c)) || PyTuple_CheckExact(__pyx_v_c)) { - __pyx_t_4 = __pyx_v_c; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0; - __pyx_t_6 = NULL; - } else { - __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_c); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 940, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_6)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 940, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } else { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 940, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } - } else { - __pyx_t_7 = __pyx_t_6(__pyx_t_4); - if (unlikely(!__pyx_t_7)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 940, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_7); - } - if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { - PyObject* sequence = __pyx_t_7; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 940, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_8 = PyList_GET_ITEM(sequence, 0); - __pyx_t_9 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_9); - #else - __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - #endif - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext; - index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_9); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) __PYX_ERR(0, 940, __pyx_L1_error) - __pyx_t_11 = NULL; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_11 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 940, __pyx_L1_error) - __pyx_L7_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 940, __pyx_L1_error) - __pyx_t_7 = __Pyx_PyInt_From_char((__pyx_v_5pysam_18libcalignedsegment_CODE2CIGAR[__pyx_t_12])); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_INCREF(__pyx_v_y); - __Pyx_GIVEREF(__pyx_v_y); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_y); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_i_c, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 940, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyString_Join(__pyx_kp_s__16, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_KEY_NAMES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_t_1, 0, -1L, NULL, NULL, &__pyx_slice__20, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_vals, 0, __pyx_v_n, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_KEY_NAMES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_vals, __pyx_v_n, 0, NULL, NULL, NULL, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_5); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":934 - * empty string. - * ''' - * def __get__(self): # <<<<<<<<<<<<<< - * c = self.cigartuples - * if c is None: + /* "pysam/libcalignedsegment.pyx":1113 + * return self.to_string() + * + * def to_dict(self): # <<<<<<<<<<<<<< + * """returns a json representation of the aligned segment. + * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.cigarstring.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.to_dict", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_c); - __Pyx_XDECREF(__pyx_v_x); - __Pyx_XDECREF(__pyx_v_y); + __Pyx_XDECREF(__pyx_v_vals); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":942 - * return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c]) +/* "pysam/libcalignedsegment.pyx":1124 + * + * @classmethod + * def from_dict(cls, sam_dict, AlignmentHeader header): # <<<<<<<<<<<<<< + * """parses a dictionary representation of the aligned segment. * - * def __set__(self, cigar): # <<<<<<<<<<<<<< - * if cigar is None or len(cigar) == 0: - * self.cigartuples = [] */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_cigar); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_cigar) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_25from_dict(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_24from_dict[] = "AlignedSegment.from_dict(type cls, sam_dict, AlignmentHeader header)\nparses a dictionary representation of the aligned segment.\n\n Parameters\n ----------\n sam_dict -- dictionary of alignment values, keys corresponding to output from\n :meth:`todict()`.\n\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_25from_dict(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_sam_dict = 0; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header = 0; + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_cigar)); + __Pyx_RefNannySetupContext("from_dict (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sam_dict,&__pyx_n_s_header,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sam_dict)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_header)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("from_dict", 1, 2, 2, 1); __PYX_ERR(0, 1124, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "from_dict") < 0)) __PYX_ERR(0, 1124, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_sam_dict = values[0]; + __pyx_v_header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)values[1]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("from_dict", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1124, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.from_dict", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_header), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, 1, "header", 0))) __PYX_ERR(0, 1124, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_24from_dict(((PyTypeObject*)__pyx_v_cls), __pyx_v_sam_dict, __pyx_v_header); /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5pysam_18libcalignedsegment_14AlignedSegment_9from_dict_2generator2(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_cigar) { - PyObject *__pyx_v_parts = NULL; - PyObject *__pyx_v_x = NULL; - PyObject *__pyx_v_y = NULL; - int __pyx_r; +/* "pysam/libcalignedsegment.pyx":1136 + * # the tags field can be missing + * return cls.fromstring( + * "\t".join((sam_dict[x] for x in KEY_NAMES[:-1])) + # <<<<<<<<<<<<<< + * "\t" + + * "\t".join(sam_dict.get(KEY_NAMES[-1], [])), header) + */ + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9from_dict_genexpr(PyObject *__pyx_self) { + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("genexpr", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr *)__pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr(__pyx_ptype_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 1136, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *) __pyx_self; + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); + { + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_18libcalignedsegment_14AlignedSegment_9from_dict_2generator2, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_from_dict_locals_genexpr, __pyx_n_s_pysam_libcalignedsegment); if (unlikely(!gen)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.from_dict.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5pysam_18libcalignedsegment_14AlignedSegment_9from_dict_2generator2(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - Py_ssize_t __pyx_t_4; + __Pyx_RefNannySetupContext("genexpr", 0); + __Pyx_TraceCall("genexpr", __pyx_f[0], 1136, 0, __PYX_ERR(0, 1136, __pyx_L1_error)); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1136, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_KEY_NAMES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_t_1, 0, -1L, NULL, NULL, &__pyx_slice__21, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1136, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_4)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1136, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1136, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_4(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1136, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_sam_dict)) { __Pyx_RaiseClosureNameError("sam_dict"); __PYX_ERR(0, 1136, __pyx_L1_error) } + __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_sam_dict, __pyx_cur_scope->__pyx_v_x); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1136, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); + + /* function exit code */ + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1124 + * + * @classmethod + * def from_dict(cls, sam_dict, AlignmentHeader header): # <<<<<<<<<<<<<< + * """parses a dictionary representation of the aligned segment. + * + */ + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_24from_dict(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_sam_dict, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header) { + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; - PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_t_9; PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *(*__pyx_t_12)(PyObject *); - long __pyx_t_13; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 942, 0, __PYX_ERR(0, 942, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":943 - * - * def __set__(self, cigar): - * if cigar is None or len(cigar) == 0: # <<<<<<<<<<<<<< - * self.cigartuples = [] - * else: - */ - __pyx_t_2 = (__pyx_v_cigar == Py_None); - __pyx_t_3 = (__pyx_t_2 != 0); - if (!__pyx_t_3) { + __Pyx_RefNannySetupContext("from_dict", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *)__pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict(__pyx_ptype_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 1124, __pyx_L1_error) } else { - __pyx_t_1 = __pyx_t_3; - goto __pyx_L4_bool_binop_done; + __Pyx_GOTREF(__pyx_cur_scope); } - __pyx_t_4 = PyObject_Length(__pyx_v_cigar); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 943, __pyx_L1_error) - __pyx_t_3 = ((__pyx_t_4 == 0) != 0); - __pyx_t_1 = __pyx_t_3; - __pyx_L4_bool_binop_done:; - if (__pyx_t_1) { + __Pyx_TraceCall("from_dict", __pyx_f[0], 1124, 0, __PYX_ERR(0, 1124, __pyx_L1_error)); + __pyx_cur_scope->__pyx_v_sam_dict = __pyx_v_sam_dict; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_sam_dict); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_sam_dict); - /* "pysam/libcalignedsegment.pyx":944 - * def __set__(self, cigar): - * if cigar is None or len(cigar) == 0: - * self.cigartuples = [] # <<<<<<<<<<<<<< - * else: - * parts = CIGAR_REGEX.findall(cigar) + /* "pysam/libcalignedsegment.pyx":1135 + * # let htslib do the parsing + * # the tags field can be missing + * return cls.fromstring( # <<<<<<<<<<<<<< + * "\t".join((sam_dict[x] for x in KEY_NAMES[:-1])) + + * "\t" + */ - __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 944, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples, __pyx_t_5) < 0) __PYX_ERR(0, 944, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_fromstring); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); - /* "pysam/libcalignedsegment.pyx":943 - * - * def __set__(self, cigar): - * if cigar is None or len(cigar) == 0: # <<<<<<<<<<<<<< - * self.cigartuples = [] - * else: + /* "pysam/libcalignedsegment.pyx":1136 + * # the tags field can be missing + * return cls.fromstring( + * "\t".join((sam_dict[x] for x in KEY_NAMES[:-1])) + # <<<<<<<<<<<<<< + * "\t" + + * "\t".join(sam_dict.get(KEY_NAMES[-1], [])), header) */ - goto __pyx_L3; - } + __pyx_t_3 = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9from_dict_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyString_Join(__pyx_kp_s__16, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_kp_s__16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignedsegment.pyx":946 - * self.cigartuples = [] - * else: - * parts = CIGAR_REGEX.findall(cigar) # <<<<<<<<<<<<<< - * # reverse order - * self.cigartuples = [(CIGAR2CODE[ord(y)], int(x)) for x,y in parts] + /* "pysam/libcalignedsegment.pyx":1138 + * "\t".join((sam_dict[x] for x in KEY_NAMES[:-1])) + + * "\t" + + * "\t".join(sam_dict.get(KEY_NAMES[-1], [])), header) # <<<<<<<<<<<<<< + * + * ######################################################## */ - /*else*/ { - __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_REGEX); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 946, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_findall); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 946, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - if (!__pyx_t_6) { - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_cigar); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 946, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_cigar}; - __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 946, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_5); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_cigar}; - __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 946, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_5); - } else - #endif - { - __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 946, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; - __Pyx_INCREF(__pyx_v_cigar); - __Pyx_GIVEREF(__pyx_v_cigar); - PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_cigar); - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 946, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_sam_dict, __pyx_n_s_get); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_KEY_NAMES); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_6, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_9 = 1; } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_7, __pyx_t_6}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1138, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_parts = __pyx_t_5; - __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_7, __pyx_t_6}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1138, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_6); + __pyx_t_7 = 0; + __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyString_Join(__pyx_kp_s__16, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignedsegment.pyx":948 - * parts = CIGAR_REGEX.findall(cigar) - * # reverse order - * self.cigartuples = [(CIGAR2CODE[ord(y)], int(x)) for x,y in parts] # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1137 + * return cls.fromstring( + * "\t".join((sam_dict[x] for x in KEY_NAMES[:-1])) + + * "\t" + # <<<<<<<<<<<<<< + * "\t".join(sam_dict.get(KEY_NAMES[-1], [])), header) * - * # TODO */ - __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (likely(PyList_CheckExact(__pyx_v_parts)) || PyTuple_CheckExact(__pyx_v_parts)) { - __pyx_t_7 = __pyx_v_parts; __Pyx_INCREF(__pyx_t_7); __pyx_t_4 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_4 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_parts); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 948, __pyx_L1_error) + __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pysam/libcalignedsegment.pyx":1138 + * "\t".join((sam_dict[x] for x in KEY_NAMES[:-1])) + + * "\t" + + * "\t".join(sam_dict.get(KEY_NAMES[-1], [])), header) # <<<<<<<<<<<<<< + * + * ######################################################## + */ + __pyx_t_5 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_9 = 1; } - for (;;) { - if (likely(!__pyx_t_9)) { - if (likely(PyList_CheckExact(__pyx_t_7))) { - if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_4); __Pyx_INCREF(__pyx_t_8); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 948, __pyx_L1_error) - #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - } else { - if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_4); __Pyx_INCREF(__pyx_t_8); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 948, __pyx_L1_error) - #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - } - } else { - __pyx_t_8 = __pyx_t_9(__pyx_t_7); - if (unlikely(!__pyx_t_8)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 948, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_8); - } - if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) { - PyObject* sequence = __pyx_t_8; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 948, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_6 = PyList_GET_ITEM(sequence, 0); - __pyx_t_10 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(__pyx_t_10); - #else - __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - #endif - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_11 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; - index = 0; __pyx_t_6 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_6)) goto __pyx_L8_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L8_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) __PYX_ERR(0, 948, __pyx_L1_error) - __pyx_t_12 = NULL; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L9_unpacking_done; - __pyx_L8_unpacking_failed:; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_12 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 948, __pyx_L1_error) - __pyx_L9_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_6); - __pyx_t_6 = 0; - __Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_10); - __pyx_t_10 = 0; - __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR2CODE); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_13 = __Pyx_PyObject_Ord(__pyx_v_y); if (unlikely(__pyx_t_13 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 948, __pyx_L1_error) - __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_8, __pyx_t_13, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyNumber_Int(__pyx_v_x); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_8); - __pyx_t_10 = 0; - __pyx_t_8 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_4, ((PyObject *)__pyx_v_header)}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1135, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_4, ((PyObject *)__pyx_v_header)}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1135, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL; } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples, __pyx_t_5) < 0) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_9, __pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_v_header)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_header)); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_9, ((PyObject *)__pyx_v_header)); + __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } - __pyx_L3:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":942 - * return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c]) + /* "pysam/libcalignedsegment.pyx":1124 + * + * @classmethod + * def from_dict(cls, sam_dict, AlignmentHeader header): # <<<<<<<<<<<<<< + * """parses a dictionary representation of the aligned segment. * - * def __set__(self, cigar): # <<<<<<<<<<<<<< - * if cigar is None or len(cigar) == 0: - * self.cigartuples = [] */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.cigarstring.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.from_dict", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_parts); - __Pyx_XDECREF(__pyx_v_x); - __Pyx_XDECREF(__pyx_v_y); - __Pyx_TraceReturn(Py_None, 0); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":956 - * property next_reference_id: - * """the :term:`reference` id of the mate/next read.""" - * def __get__(self): return self._delegate.core.mtid # <<<<<<<<<<<<<< - * def __set__(self, mtid): - * self._delegate.core.mtid = mtid +/* "pysam/libcalignedsegment.pyx":1144 + * property query_name: + * """the query template name (None if not present)""" + * def __get__(self): # <<<<<<<<<<<<<< + * + * cdef bam1_t * src = self._delegate */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10query_name___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10query_name___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + bam1_t *__pyx_v_src; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + bam1_t *__pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 956, 0, __PYX_ERR(0, 956, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1144, 0, __PYX_ERR(0, 1144, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1146 + * def __get__(self): + * + * cdef bam1_t * src = self._delegate # <<<<<<<<<<<<<< + * if src.core.l_qname == 0: + * return None + */ + __pyx_t_1 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_1; + + /* "pysam/libcalignedsegment.pyx":1147 + * + * cdef bam1_t * src = self._delegate + * if src.core.l_qname == 0: # <<<<<<<<<<<<<< + * return None + * + */ + __pyx_t_2 = ((__pyx_v_src->core.l_qname == 0) != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":1148 + * cdef bam1_t * src = self._delegate + * if src.core.l_qname == 0: + * return None # <<<<<<<<<<<<<< + * + * return charptr_to_str(pysam_bam_get_qname(src)) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":1147 + * + * cdef bam1_t * src = self._delegate + * if src.core.l_qname == 0: # <<<<<<<<<<<<<< + * return None + * + */ + } + + /* "pysam/libcalignedsegment.pyx":1150 + * return None + * + * return charptr_to_str(pysam_bam_get_qname(src)) # <<<<<<<<<<<<<< + * + * def __set__(self, qname): + */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 956, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str(((char *)pysam_bam_get_qname(__pyx_v_src)), NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1150, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; goto __pyx_L0; + /* "pysam/libcalignedsegment.pyx":1144 + * property query_name: + * """the query template name (None if not present)""" + * def __get__(self): # <<<<<<<<<<<<<< + * + * cdef bam1_t * src = self._delegate + */ + /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.next_reference_id.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -12669,457 +15170,459 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_17next_re return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":957 - * """the :term:`reference` id of the mate/next read.""" - * def __get__(self): return self._delegate.core.mtid - * def __set__(self, mtid): # <<<<<<<<<<<<<< - * self._delegate.core.mtid = mtid +/* "pysam/libcalignedsegment.pyx":1152 + * return charptr_to_str(pysam_bam_get_qname(src)) + * + * def __set__(self, qname): # <<<<<<<<<<<<<< * + * if qname is None or len(qname) == 0: */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_mtid)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_qname)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mtid) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qname) { + bam1_t *__pyx_v_src; + uint8_t __pyx_v_l; + char *__pyx_v_p; + uint8_t __pyx_v_l_extranul; + bam1_t *__pyx_v_retval; + uint16_t __pyx_v_x; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int32_t __pyx_t_1; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 957, 0, __PYX_ERR(0, 957, __pyx_L1_error)); + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + bam1_t *__pyx_t_10; + char const *__pyx_t_11; + int __pyx_t_12; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1152, 0, __PYX_ERR(0, 1152, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_qname); - /* "pysam/libcalignedsegment.pyx":958 - * def __get__(self): return self._delegate.core.mtid - * def __set__(self, mtid): - * self._delegate.core.mtid = mtid # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1154 + * def __set__(self, qname): + * + * if qname is None or len(qname) == 0: # <<<<<<<<<<<<<< + * return * - * property next_reference_name: */ - __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_mtid); if (unlikely((__pyx_t_1 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 958, __pyx_L1_error) - __pyx_v_self->_delegate->core.mtid = __pyx_t_1; + __pyx_t_2 = (__pyx_v_qname == Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1154, __pyx_L1_error) + __pyx_t_3 = ((__pyx_t_4 == 0) != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":957 - * """the :term:`reference` id of the mate/next read.""" - * def __get__(self): return self._delegate.core.mtid - * def __set__(self, mtid): # <<<<<<<<<<<<<< - * self._delegate.core.mtid = mtid + /* "pysam/libcalignedsegment.pyx":1155 + * + * if qname is None or len(qname) == 0: + * return # <<<<<<<<<<<<<< * + * # See issue #447 */ + __pyx_r = 0; + goto __pyx_L0; - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.next_reference_id.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":963 - * """:term:`reference` name of the mate/next read (None if no - * AlignmentFile is associated)""" - * def __get__(self): # <<<<<<<<<<<<<< - * if self._alignment_file is not None: - * return self._alignment_file.getrname(self._delegate.core.mtid) + /* "pysam/libcalignedsegment.pyx":1154 + * def __set__(self, qname): + * + * if qname is None or len(qname) == 0: # <<<<<<<<<<<<<< + * return + * */ + } -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 963, 0, __PYX_ERR(0, 963, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":1159 + * # See issue #447 + * # (The threshold is 252 chars, but this includes a \0 byte. + * if len(qname) > 251: # <<<<<<<<<<<<<< + * raise ValueError("query length out of range {} > 251".format( + * len(qname))) + */ + __pyx_t_4 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1159, __pyx_L1_error) + __pyx_t_1 = ((__pyx_t_4 > 0xFB) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignedsegment.pyx":964 - * AlignmentFile is associated)""" - * def __get__(self): - * if self._alignment_file is not None: # <<<<<<<<<<<<<< - * return self._alignment_file.getrname(self._delegate.core.mtid) - * return None + /* "pysam/libcalignedsegment.pyx":1160 + * # (The threshold is 252 chars, but this includes a \0 byte. + * if len(qname) > 251: + * raise ValueError("query length out of range {} > 251".format( # <<<<<<<<<<<<<< + * len(qname))) + * */ - __pyx_t_1 = (((PyObject *)__pyx_v_self->_alignment_file) != Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_query_length_out_of_range_251, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); - /* "pysam/libcalignedsegment.pyx":965 - * def __get__(self): - * if self._alignment_file is not None: - * return self._alignment_file.getrname(self._delegate.core.mtid) # <<<<<<<<<<<<<< - * return None + /* "pysam/libcalignedsegment.pyx":1161 + * if len(qname) > 251: + * raise ValueError("query length out of range {} > 251".format( + * len(qname))) # <<<<<<<<<<<<<< * + * qname = force_bytes(qname) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->_alignment_file), __pyx_n_s_getrname); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 965, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 965, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_6); + __pyx_t_4 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1161, __pyx_L1_error) + __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1161, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_8); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); + __Pyx_DECREF_SET(__pyx_t_6, function); } } - if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 965, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); + if (!__pyx_t_8) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_5); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 965, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 965, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else #endif { - __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 965, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 965, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libcalignedsegment.pyx":964 - * AlignmentFile is associated)""" - * def __get__(self): - * if self._alignment_file is not None: # <<<<<<<<<<<<<< - * return self._alignment_file.getrname(self._delegate.core.mtid) - * return None + /* "pysam/libcalignedsegment.pyx":1160 + * # (The threshold is 252 chars, but this includes a \0 byte. + * if len(qname) > 251: + * raise ValueError("query length out of range {} > 251".format( # <<<<<<<<<<<<<< + * len(qname))) + * + */ + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1160, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 1160, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":1159 + * # See issue #447 + * # (The threshold is 252 chars, but this includes a \0 byte. + * if len(qname) > 251: # <<<<<<<<<<<<<< + * raise ValueError("query length out of range {} > 251".format( + * len(qname))) */ } - /* "pysam/libcalignedsegment.pyx":966 - * if self._alignment_file is not None: - * return self._alignment_file.getrname(self._delegate.core.mtid) - * return None # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1163 + * len(qname))) * - * property next_reference_start: + * qname = force_bytes(qname) # <<<<<<<<<<<<<< + * cdef bam1_t * src = self._delegate + * # the qname is \0 terminated */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_qname, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1163, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF_SET(__pyx_v_qname, __pyx_t_6); + __pyx_t_6 = 0; - /* "pysam/libcalignedsegment.pyx":963 - * """:term:`reference` name of the mate/next read (None if no - * AlignmentFile is associated)""" - * def __get__(self): # <<<<<<<<<<<<<< - * if self._alignment_file is not None: - * return self._alignment_file.getrname(self._delegate.core.mtid) + /* "pysam/libcalignedsegment.pyx":1164 + * + * qname = force_bytes(qname) + * cdef bam1_t * src = self._delegate # <<<<<<<<<<<<<< + * # the qname is \0 terminated + * cdef uint8_t l = len(qname) + 1 */ + __pyx_t_10 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_10; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.next_reference_name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1166 + * cdef bam1_t * src = self._delegate + * # the qname is \0 terminated + * cdef uint8_t l = len(qname) + 1 # <<<<<<<<<<<<<< + * + * cdef char * p = pysam_bam_get_qname(src) + */ + __pyx_t_4 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1166, __pyx_L1_error) + __pyx_v_l = (__pyx_t_4 + 1); -/* "pysam/libcalignedsegment.pyx":970 - * property next_reference_start: - * """the position of the mate/next read.""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self._delegate.core.mpos - * def __set__(self, mpos): + /* "pysam/libcalignedsegment.pyx":1168 + * cdef uint8_t l = len(qname) + 1 + * + * cdef char * p = pysam_bam_get_qname(src) # <<<<<<<<<<<<<< + * cdef uint8_t l_extranul = 0 + * */ + __pyx_v_p = pysam_bam_get_qname(__pyx_v_src); -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + /* "pysam/libcalignedsegment.pyx":1169 + * + * cdef char * p = pysam_bam_get_qname(src) + * cdef uint8_t l_extranul = 0 # <<<<<<<<<<<<<< + * + * if l % 4 != 0: + */ + __pyx_v_l_extranul = 0; - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1171 + * cdef uint8_t l_extranul = 0 + * + * if l % 4 != 0: # <<<<<<<<<<<<<< + * l_extranul = 4 - l % 4 + * + */ + __pyx_t_1 = ((__Pyx_mod_long(__pyx_v_l, 4) != 0) != 0); + if (__pyx_t_1) { -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 970, 0, __PYX_ERR(0, 970, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":1172 + * + * if l % 4 != 0: + * l_extranul = 4 - l % 4 # <<<<<<<<<<<<<< + * + * cdef bam1_t * retval = pysam_bam_update(src, + */ + __pyx_v_l_extranul = (4 - __Pyx_mod_long(__pyx_v_l, 4)); - /* "pysam/libcalignedsegment.pyx":971 - * """the position of the mate/next read.""" - * def __get__(self): - * return self._delegate.core.mpos # <<<<<<<<<<<<<< - * def __set__(self, mpos): - * self._delegate.core.mpos = mpos + /* "pysam/libcalignedsegment.pyx":1171 + * cdef uint8_t l_extranul = 0 + * + * if l % 4 != 0: # <<<<<<<<<<<<<< + * l_extranul = 4 - l % 4 + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 971, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + } - /* "pysam/libcalignedsegment.pyx":970 - * property next_reference_start: - * """the position of the mate/next read.""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self._delegate.core.mpos - * def __set__(self, mpos): + /* "pysam/libcalignedsegment.pyx":1174 + * l_extranul = 4 - l % 4 + * + * cdef bam1_t * retval = pysam_bam_update(src, # <<<<<<<<<<<<<< + * src.core.l_qname, + * l + l_extranul, */ + __pyx_v_retval = pysam_bam_update(__pyx_v_src, __pyx_v_src->core.l_qname, (__pyx_v_l + __pyx_v_l_extranul), ((uint8_t *)__pyx_v_p)); - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.next_reference_start.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1178 + * l + l_extranul, + * p) + * if retval == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate memory") + * + */ + __pyx_t_1 = ((__pyx_v_retval == NULL) != 0); + if (unlikely(__pyx_t_1)) { -/* "pysam/libcalignedsegment.pyx":972 - * def __get__(self): - * return self._delegate.core.mpos - * def __set__(self, mpos): # <<<<<<<<<<<<<< - * self._delegate.core.mpos = mpos + /* "pysam/libcalignedsegment.pyx":1179 + * p) + * if retval == NULL: + * raise MemoryError("could not allocate memory") # <<<<<<<<<<<<<< * + * src.core.l_extranul = l_extranul */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 1179, __pyx_L1_error) -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_mpos)); + /* "pysam/libcalignedsegment.pyx":1178 + * l + l_extranul, + * p) + * if retval == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate memory") + * + */ + } - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1181 + * raise MemoryError("could not allocate memory") + * + * src.core.l_extranul = l_extranul # <<<<<<<<<<<<<< + * src.core.l_qname = l + l_extranul + * + */ + __pyx_v_src->core.l_extranul = __pyx_v_l_extranul; -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mpos) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int32_t __pyx_t_1; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 972, 0, __PYX_ERR(0, 972, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":1182 + * + * src.core.l_extranul = l_extranul + * src.core.l_qname = l + l_extranul # <<<<<<<<<<<<<< + * + * # re-acquire pointer to location in memory + */ + __pyx_v_src->core.l_qname = (__pyx_v_l + __pyx_v_l_extranul); - /* "pysam/libcalignedsegment.pyx":973 - * return self._delegate.core.mpos - * def __set__(self, mpos): - * self._delegate.core.mpos = mpos # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1186 + * # re-acquire pointer to location in memory + * # as it might have moved + * p = pysam_bam_get_qname(src) # <<<<<<<<<<<<<< * - * property query_length: + * strncpy(p, qname, l) */ - __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_mpos); if (unlikely((__pyx_t_1 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 973, __pyx_L1_error) - __pyx_v_self->_delegate->core.mpos = __pyx_t_1; + __pyx_v_p = pysam_bam_get_qname(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":972 - * def __get__(self): - * return self._delegate.core.mpos - * def __set__(self, mpos): # <<<<<<<<<<<<<< - * self._delegate.core.mpos = mpos + /* "pysam/libcalignedsegment.pyx":1188 + * p = pysam_bam_get_qname(src) * + * strncpy(p, qname, l) # <<<<<<<<<<<<<< + * # x might be > 255 + * cdef uint16_t x = 0 */ + __pyx_t_11 = __Pyx_PyObject_AsString(__pyx_v_qname); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) __PYX_ERR(0, 1188, __pyx_L1_error) + (void)(strncpy(__pyx_v_p, __pyx_t_11, __pyx_v_l)); - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.next_reference_start.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1190 + * strncpy(p, qname, l) + * # x might be > 255 + * cdef uint16_t x = 0 # <<<<<<<<<<<<<< + * + * for x from l <= x < l + l_extranul: + */ + __pyx_v_x = 0; -/* "pysam/libcalignedsegment.pyx":993 + /* "pysam/libcalignedsegment.pyx":1192 + * cdef uint16_t x = 0 * - * """ - * def __get__(self): # <<<<<<<<<<<<<< - * return self._delegate.core.l_qseq + * for x from l <= x < l + l_extranul: # <<<<<<<<<<<<<< + * p[x] = '\0' * */ + __pyx_t_12 = (__pyx_v_l + __pyx_v_l_extranul); + for (__pyx_v_x = __pyx_v_l; __pyx_v_x < __pyx_t_12; __pyx_v_x++) { -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12query_length_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12query_length_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12query_length___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12query_length___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 993, 0, __PYX_ERR(0, 993, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":994 - * """ - * def __get__(self): - * return self._delegate.core.l_qseq # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1193 * - * property template_length: + * for x from l <= x < l + l_extranul: + * p[x] = '\0' # <<<<<<<<<<<<<< + * + * property flag: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.l_qseq); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 994, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + (__pyx_v_p[__pyx_v_x]) = '\x00'; + } - /* "pysam/libcalignedsegment.pyx":993 + /* "pysam/libcalignedsegment.pyx":1152 + * return charptr_to_str(pysam_bam_get_qname(src)) * - * """ - * def __get__(self): # <<<<<<<<<<<<<< - * return self._delegate.core.l_qseq + * def __set__(self, qname): # <<<<<<<<<<<<<< * + * if qname is None or len(qname) == 0: */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_name.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_XDECREF(__pyx_v_qname); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":998 - * property template_length: - * """the observed query template length""" +/* "pysam/libcalignedsegment.pyx":1197 + * property flag: + * """properties flag""" * def __get__(self): # <<<<<<<<<<<<<< - * return self._delegate.core.isize - * def __set__(self, isize): + * return self._delegate.core.flag + * def __set__(self, flag): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4flag_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4flag_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15template_length___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4flag___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15template_length___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4flag___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 998, 0, __PYX_ERR(0, 998, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1197, 0, __PYX_ERR(0, 1197, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":999 - * """the observed query template length""" + /* "pysam/libcalignedsegment.pyx":1198 + * """properties flag""" * def __get__(self): - * return self._delegate.core.isize # <<<<<<<<<<<<<< - * def __set__(self, isize): - * self._delegate.core.isize = isize + * return self._delegate.core.flag # <<<<<<<<<<<<<< + * def __set__(self, flag): + * self._delegate.core.flag = flag */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.isize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 999, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_uint16_t(__pyx_v_self->_delegate->core.flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":998 - * property template_length: - * """the observed query template length""" + /* "pysam/libcalignedsegment.pyx":1197 + * property flag: + * """properties flag""" * def __get__(self): # <<<<<<<<<<<<<< - * return self._delegate.core.isize - * def __set__(self, isize): + * return self._delegate.core.flag + * def __set__(self, flag): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.template_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.flag.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -13128,50 +15631,50 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15templat return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1000 +/* "pysam/libcalignedsegment.pyx":1199 * def __get__(self): - * return self._delegate.core.isize - * def __set__(self, isize): # <<<<<<<<<<<<<< - * self._delegate.core.isize = isize + * return self._delegate.core.flag + * def __set__(self, flag): # <<<<<<<<<<<<<< + * self._delegate.core.flag = flag * */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4flag_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4flag_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_isize)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4flag_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_flag)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_isize) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4flag_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_flag) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int32_t __pyx_t_1; + uint16_t __pyx_t_1; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1000, 0, __PYX_ERR(0, 1000, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 1199, 0, __PYX_ERR(0, 1199, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1001 - * return self._delegate.core.isize - * def __set__(self, isize): - * self._delegate.core.isize = isize # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1200 + * return self._delegate.core.flag + * def __set__(self, flag): + * self._delegate.core.flag = flag # <<<<<<<<<<<<<< * - * property query_sequence: + * property reference_name: */ - __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_isize); if (unlikely((__pyx_t_1 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1001, __pyx_L1_error) - __pyx_v_self->_delegate->core.isize = __pyx_t_1; + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_flag); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1200, __pyx_L1_error) + __pyx_v_self->_delegate->core.flag = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":1000 + /* "pysam/libcalignedsegment.pyx":1199 * def __get__(self): - * return self._delegate.core.isize - * def __set__(self, isize): # <<<<<<<<<<<<<< - * self._delegate.core.isize = isize + * return self._delegate.core.flag + * def __set__(self, flag): # <<<<<<<<<<<<<< + * self._delegate.core.flag = flag * */ @@ -13179,7 +15682,7 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15template_leng __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.template_length.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.flag.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -13187,153 +15690,182 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15template_leng return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1019 - * sequence. - * """ +/* "pysam/libcalignedsegment.pyx":1204 + * property reference_name: + * """:term:`reference` name""" * def __get__(self): # <<<<<<<<<<<<<< - * if self.cache_query_sequence: - * return self.cache_query_sequence + * if self._delegate.core.tid == -1: + * return None */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - bam1_t *__pyx_v_src; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; - bam1_t *__pyx_t_2; + PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1019, 0, __PYX_ERR(0, 1019, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1204, 0, __PYX_ERR(0, 1204, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1020 - * """ + /* "pysam/libcalignedsegment.pyx":1205 + * """:term:`reference` name""" * def __get__(self): - * if self.cache_query_sequence: # <<<<<<<<<<<<<< - * return self.cache_query_sequence - * + * if self._delegate.core.tid == -1: # <<<<<<<<<<<<<< + * return None + * if self.header: */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->cache_query_sequence); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1020, __pyx_L1_error) + __pyx_t_1 = ((__pyx_v_self->_delegate->core.tid == -1L) != 0); if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1021 + /* "pysam/libcalignedsegment.pyx":1206 * def __get__(self): - * if self.cache_query_sequence: - * return self.cache_query_sequence # <<<<<<<<<<<<<< - * - * cdef bam1_t * src + * if self._delegate.core.tid == -1: + * return None # <<<<<<<<<<<<<< + * if self.header: + * return self.header.get_reference_name(self._delegate.core.tid) */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->cache_query_sequence); - __pyx_r = __pyx_v_self->cache_query_sequence; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1020 - * """ + /* "pysam/libcalignedsegment.pyx":1205 + * """:term:`reference` name""" * def __get__(self): - * if self.cache_query_sequence: # <<<<<<<<<<<<<< - * return self.cache_query_sequence - * + * if self._delegate.core.tid == -1: # <<<<<<<<<<<<<< + * return None + * if self.header: */ } - /* "pysam/libcalignedsegment.pyx":1025 - * cdef bam1_t * src - * cdef char * s - * src = self._delegate # <<<<<<<<<<<<<< - * - * if src.core.l_qseq == 0: - */ - __pyx_t_2 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_2; - - /* "pysam/libcalignedsegment.pyx":1027 - * src = self._delegate - * - * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1207 + * if self._delegate.core.tid == -1: * return None - * + * if self.header: # <<<<<<<<<<<<<< + * return self.header.get_reference_name(self._delegate.core.tid) + * else: */ - __pyx_t_1 = ((__pyx_v_src->core.l_qseq == 0) != 0); - if (__pyx_t_1) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1207, __pyx_L1_error) + if (likely(__pyx_t_1)) { - /* "pysam/libcalignedsegment.pyx":1028 - * - * if src.core.l_qseq == 0: - * return None # <<<<<<<<<<<<<< - * - * self.cache_query_sequence = force_str(getSequenceInRange( + /* "pysam/libcalignedsegment.pyx":1208 + * return None + * if self.header: + * return self.header.get_reference_name(self._delegate.core.tid) # <<<<<<<<<<<<<< + * else: + * raise ValueError("reference_name unknown if no header associated with record") */ __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1208, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1208, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1208, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1208, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1208, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1208, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1208, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1027 - * src = self._delegate - * - * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1207 + * if self._delegate.core.tid == -1: * return None - * + * if self.header: # <<<<<<<<<<<<<< + * return self.header.get_reference_name(self._delegate.core.tid) + * else: */ } - /* "pysam/libcalignedsegment.pyx":1030 - * return None - * - * self.cache_query_sequence = force_str(getSequenceInRange( # <<<<<<<<<<<<<< - * src, 0, src.core.l_qseq)) - * return self.cache_query_sequence - */ - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getSequenceInRange(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_v_self->cache_query_sequence); - __Pyx_DECREF(__pyx_v_self->cache_query_sequence); - __pyx_v_self->cache_query_sequence = __pyx_t_4; - __pyx_t_4 = 0; - - /* "pysam/libcalignedsegment.pyx":1032 - * self.cache_query_sequence = force_str(getSequenceInRange( - * src, 0, src.core.l_qseq)) - * return self.cache_query_sequence # <<<<<<<<<<<<<< - * - * def __set__(self, seq): + /* "pysam/libcalignedsegment.pyx":1210 + * return self.header.get_reference_name(self._delegate.core.tid) + * else: + * raise ValueError("reference_name unknown if no header associated with record") # <<<<<<<<<<<<<< + * def __set__(self, reference): + * cdef int tid */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->cache_query_sequence); - __pyx_r = __pyx_v_self->cache_query_sequence; - goto __pyx_L0; + /*else*/ { + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 1210, __pyx_L1_error) + } - /* "pysam/libcalignedsegment.pyx":1019 - * sequence. - * """ + /* "pysam/libcalignedsegment.pyx":1204 + * property reference_name: + * """:term:`reference` name""" * def __get__(self): # <<<<<<<<<<<<<< - * if self.cache_query_sequence: - * return self.cache_query_sequence + * if self._delegate.core.tid == -1: + * return None */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_sequence.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -13342,792 +15874,645 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14query_s return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1034 - * return self.cache_query_sequence - * - * def __set__(self, seq): # <<<<<<<<<<<<<< - * # samtools manages sequence and quality length memory together - * # if no quality information is present, the first byte says 0xff. +/* "pysam/libcalignedsegment.pyx":1211 + * else: + * raise ValueError("reference_name unknown if no header associated with record") + * def __set__(self, reference): # <<<<<<<<<<<<<< + * cdef int tid + * if reference is None or reference == "*": */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_seq)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_reference)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_seq) { - bam1_t *__pyx_v_src; - uint8_t *__pyx_v_p; - char *__pyx_v_s; - int __pyx_v_l; - int __pyx_v_k; - Py_ssize_t __pyx_v_nbytes_new; - Py_ssize_t __pyx_v_nbytes_old; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_reference) { + int __pyx_v_tid; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; int __pyx_t_2; - Py_ssize_t __pyx_t_3; - bam1_t *__pyx_t_4; - char *__pyx_t_5; - int __pyx_t_6; - long __pyx_t_7; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1034, 0, __PYX_ERR(0, 1034, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_seq); - - /* "pysam/libcalignedsegment.pyx":1043 - * cdef Py_ssize_t nbytes_new, nbytes_old - * - * if seq == None: # <<<<<<<<<<<<<< - * l = 0 - * else: - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_seq, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1043, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1043, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "pysam/libcalignedsegment.pyx":1044 - * - * if seq == None: - * l = 0 # <<<<<<<<<<<<<< - * else: - * l = len(seq) - */ - __pyx_v_l = 0; + __Pyx_TraceCall("__set__", __pyx_f[0], 1211, 0, __PYX_ERR(0, 1211, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1043 - * cdef Py_ssize_t nbytes_new, nbytes_old - * - * if seq == None: # <<<<<<<<<<<<<< - * l = 0 - * else: + /* "pysam/libcalignedsegment.pyx":1213 + * def __set__(self, reference): + * cdef int tid + * if reference is None or reference == "*": # <<<<<<<<<<<<<< + * self._delegate.core.tid = -1 + * elif self.header: */ - goto __pyx_L3; + __pyx_t_2 = (__pyx_v_reference == Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; } + __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_reference, __pyx_kp_s__24, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1213, __pyx_L1_error) + __pyx_t_1 = __pyx_t_3; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1046 - * l = 0 - * else: - * l = len(seq) # <<<<<<<<<<<<<< - * seq = force_bytes(seq) - * + /* "pysam/libcalignedsegment.pyx":1214 + * cdef int tid + * if reference is None or reference == "*": + * self._delegate.core.tid = -1 # <<<<<<<<<<<<<< + * elif self.header: + * tid = self.header.get_tid(reference) */ - /*else*/ { - __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1046, __pyx_L1_error) - __pyx_v_l = __pyx_t_3; + __pyx_v_self->_delegate->core.tid = -1; - /* "pysam/libcalignedsegment.pyx":1047 - * else: - * l = len(seq) - * seq = force_bytes(seq) # <<<<<<<<<<<<<< - * - * src = self._delegate + /* "pysam/libcalignedsegment.pyx":1213 + * def __set__(self, reference): + * cdef int tid + * if reference is None or reference == "*": # <<<<<<<<<<<<<< + * self._delegate.core.tid = -1 + * elif self.header: */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_seq, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1047, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF_SET(__pyx_v_seq, __pyx_t_1); - __pyx_t_1 = 0; + goto __pyx_L3; } - __pyx_L3:; - - /* "pysam/libcalignedsegment.pyx":1049 - * seq = force_bytes(seq) - * - * src = self._delegate # <<<<<<<<<<<<<< - * - * # as the sequence is stored in half-bytes, the total length (sequence - */ - __pyx_t_4 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_4; - - /* "pysam/libcalignedsegment.pyx":1053 - * # as the sequence is stored in half-bytes, the total length (sequence - * # plus quality scores) is (l+1)/2 + l - * nbytes_new = (l + 1) / 2 + l # <<<<<<<<<<<<<< - * nbytes_old = (src.core.l_qseq + 1) / 2 + src.core.l_qseq - * - */ - __pyx_v_nbytes_new = (__Pyx_div_long((__pyx_v_l + 1), 2) + __pyx_v_l); - - /* "pysam/libcalignedsegment.pyx":1054 - * # plus quality scores) is (l+1)/2 + l - * nbytes_new = (l + 1) / 2 + l - * nbytes_old = (src.core.l_qseq + 1) / 2 + src.core.l_qseq # <<<<<<<<<<<<<< - * - * # acquire pointer to location in memory - */ - __pyx_v_nbytes_old = (__Pyx_div_long((__pyx_v_src->core.l_qseq + 1), 2) + __pyx_v_src->core.l_qseq); - - /* "pysam/libcalignedsegment.pyx":1057 - * - * # acquire pointer to location in memory - * p = pysam_bam_get_seq(src) # <<<<<<<<<<<<<< - * src.core.l_qseq = l - * - */ - __pyx_v_p = pysam_bam_get_seq(__pyx_v_src); - - /* "pysam/libcalignedsegment.pyx":1058 - * # acquire pointer to location in memory - * p = pysam_bam_get_seq(src) - * src.core.l_qseq = l # <<<<<<<<<<<<<< - * - * # change length of data field - */ - __pyx_v_src->core.l_qseq = __pyx_v_l; - - /* "pysam/libcalignedsegment.pyx":1061 - * - * # change length of data field - * pysam_bam_update(src, # <<<<<<<<<<<<<< - * nbytes_old, - * nbytes_new, - */ - (void)(pysam_bam_update(__pyx_v_src, __pyx_v_nbytes_old, __pyx_v_nbytes_new, __pyx_v_p)); - - /* "pysam/libcalignedsegment.pyx":1066 - * p) - * - * if l > 0: # <<<<<<<<<<<<<< - * # re-acquire pointer to location in memory - * # as it might have moved - */ - __pyx_t_2 = ((__pyx_v_l > 0) != 0); - if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":1069 - * # re-acquire pointer to location in memory - * # as it might have moved - * p = pysam_bam_get_seq(src) # <<<<<<<<<<<<<< - * for k from 0 <= k < nbytes_new: - * p[k] = 0 - */ - __pyx_v_p = pysam_bam_get_seq(__pyx_v_src); + /* "pysam/libcalignedsegment.pyx":1215 + * if reference is None or reference == "*": + * self._delegate.core.tid = -1 + * elif self.header: # <<<<<<<<<<<<<< + * tid = self.header.get_tid(reference) + * if tid < 0: + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1215, __pyx_L1_error) + if (likely(__pyx_t_1)) { + + /* "pysam/libcalignedsegment.pyx":1216 + * self._delegate.core.tid = -1 + * elif self.header: + * tid = self.header.get_tid(reference) # <<<<<<<<<<<<<< + * if tid < 0: + * raise ValueError("reference {} does not exist in header".format( + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1216, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (!__pyx_t_6) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_reference); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1216, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_reference}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1216, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_reference}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1216, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1216, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_INCREF(__pyx_v_reference); + __Pyx_GIVEREF(__pyx_v_reference); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_reference); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1216, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1216, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_tid = __pyx_t_8; - /* "pysam/libcalignedsegment.pyx":1070 - * # as it might have moved - * p = pysam_bam_get_seq(src) - * for k from 0 <= k < nbytes_new: # <<<<<<<<<<<<<< - * p[k] = 0 - * # convert to C string + /* "pysam/libcalignedsegment.pyx":1217 + * elif self.header: + * tid = self.header.get_tid(reference) + * if tid < 0: # <<<<<<<<<<<<<< + * raise ValueError("reference {} does not exist in header".format( + * reference)) */ - __pyx_t_3 = __pyx_v_nbytes_new; - for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) { + __pyx_t_1 = ((__pyx_v_tid < 0) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignedsegment.pyx":1071 - * p = pysam_bam_get_seq(src) - * for k from 0 <= k < nbytes_new: - * p[k] = 0 # <<<<<<<<<<<<<< - * # convert to C string - * s = seq + /* "pysam/libcalignedsegment.pyx":1218 + * tid = self.header.get_tid(reference) + * if tid < 0: + * raise ValueError("reference {} does not exist in header".format( # <<<<<<<<<<<<<< + * reference)) + * self._delegate.core.tid = tid */ - (__pyx_v_p[__pyx_v_k]) = 0; - } + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_reference_does_not_exist_in_head, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1218, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); - /* "pysam/libcalignedsegment.pyx":1073 - * p[k] = 0 - * # convert to C string - * s = seq # <<<<<<<<<<<<<< - * for k from 0 <= k < l: - * p[k/2] |= seq_nt16_table[s[k]] << 4 * (1 - k % 2) + /* "pysam/libcalignedsegment.pyx":1219 + * if tid < 0: + * raise ValueError("reference {} does not exist in header".format( + * reference)) # <<<<<<<<<<<<<< + * self._delegate.core.tid = tid + * else: */ - __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_seq); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 1073, __pyx_L1_error) - __pyx_v_s = __pyx_t_5; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (!__pyx_t_7) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_reference); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1218, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_reference}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1218, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_reference}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1218, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1218, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL; + __Pyx_INCREF(__pyx_v_reference); + __Pyx_GIVEREF(__pyx_v_reference); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_reference); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1218, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcalignedsegment.pyx":1074 - * # convert to C string - * s = seq - * for k from 0 <= k < l: # <<<<<<<<<<<<<< - * p[k/2] |= seq_nt16_table[s[k]] << 4 * (1 - k % 2) - * + /* "pysam/libcalignedsegment.pyx":1218 + * tid = self.header.get_tid(reference) + * if tid < 0: + * raise ValueError("reference {} does not exist in header".format( # <<<<<<<<<<<<<< + * reference)) + * self._delegate.core.tid = tid */ - __pyx_t_6 = __pyx_v_l; - for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1218, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 1218, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":1075 - * s = seq - * for k from 0 <= k < l: - * p[k/2] |= seq_nt16_table[s[k]] << 4 * (1 - k % 2) # <<<<<<<<<<<<<< - * - * # erase qualities + /* "pysam/libcalignedsegment.pyx":1217 + * elif self.header: + * tid = self.header.get_tid(reference) + * if tid < 0: # <<<<<<<<<<<<<< + * raise ValueError("reference {} does not exist in header".format( + * reference)) */ - __pyx_t_7 = __Pyx_div_long(__pyx_v_k, 2); - (__pyx_v_p[__pyx_t_7]) = ((__pyx_v_p[__pyx_t_7]) | ((seq_nt16_table[((unsigned char)(__pyx_v_s[__pyx_v_k]))]) << (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2))))); } - /* "pysam/libcalignedsegment.pyx":1078 - * - * # erase qualities - * p = pysam_bam_get_qual(src) # <<<<<<<<<<<<<< - * p[0] = 0xff - * - */ - __pyx_v_p = pysam_bam_get_qual(__pyx_v_src); - - /* "pysam/libcalignedsegment.pyx":1079 - * # erase qualities - * p = pysam_bam_get_qual(src) - * p[0] = 0xff # <<<<<<<<<<<<<< - * - * self.cache_query_sequence = force_str(seq) + /* "pysam/libcalignedsegment.pyx":1220 + * raise ValueError("reference {} does not exist in header".format( + * reference)) + * self._delegate.core.tid = tid # <<<<<<<<<<<<<< + * else: + * raise ValueError("reference_name can not be set if no header associated with record") */ - (__pyx_v_p[0]) = 0xff; + __pyx_v_self->_delegate->core.tid = __pyx_v_tid; - /* "pysam/libcalignedsegment.pyx":1066 - * p) - * - * if l > 0: # <<<<<<<<<<<<<< - * # re-acquire pointer to location in memory - * # as it might have moved + /* "pysam/libcalignedsegment.pyx":1215 + * if reference is None or reference == "*": + * self._delegate.core.tid = -1 + * elif self.header: # <<<<<<<<<<<<<< + * tid = self.header.get_tid(reference) + * if tid < 0: */ + goto __pyx_L3; } - /* "pysam/libcalignedsegment.pyx":1081 - * p[0] = 0xff - * - * self.cache_query_sequence = force_str(seq) # <<<<<<<<<<<<<< - * - * # clear cached values for quality values - */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_seq, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1081, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->cache_query_sequence); - __Pyx_DECREF(__pyx_v_self->cache_query_sequence); - __pyx_v_self->cache_query_sequence = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pysam/libcalignedsegment.pyx":1084 - * - * # clear cached values for quality values - * self.cache_query_qualities = None # <<<<<<<<<<<<<< - * self.cache_query_alignment_qualities = None - * - */ - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->cache_query_qualities); - __Pyx_DECREF(__pyx_v_self->cache_query_qualities); - __pyx_v_self->cache_query_qualities = Py_None; - - /* "pysam/libcalignedsegment.pyx":1085 - * # clear cached values for quality values - * self.cache_query_qualities = None - * self.cache_query_alignment_qualities = None # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1222 + * self._delegate.core.tid = tid + * else: + * raise ValueError("reference_name can not be set if no header associated with record") # <<<<<<<<<<<<<< * - * property query_qualities: + * property reference_id: */ - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_qualities); - __Pyx_DECREF(__pyx_v_self->cache_query_alignment_qualities); - __pyx_v_self->cache_query_alignment_qualities = Py_None; + /*else*/ { + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1222, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 1222, __pyx_L1_error) + } + __pyx_L3:; - /* "pysam/libcalignedsegment.pyx":1034 - * return self.cache_query_sequence - * - * def __set__(self, seq): # <<<<<<<<<<<<<< - * # samtools manages sequence and quality length memory together - * # if no quality information is present, the first byte says 0xff. + /* "pysam/libcalignedsegment.pyx":1211 + * else: + * raise ValueError("reference_name unknown if no header associated with record") + * def __set__(self, reference): # <<<<<<<<<<<<<< + * cdef int tid + * if reference is None or reference == "*": */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_sequence.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_name.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_seq); __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1104 +/* "pysam/libcalignedsegment.pyx":1234 * * """ * def __get__(self): # <<<<<<<<<<<<<< - * - * if self.cache_query_qualities: + * return self._delegate.core.tid + * def __set__(self, tid): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - bam1_t *__pyx_v_src; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - bam1_t *__pyx_t_2; - PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1104, 0, __PYX_ERR(0, 1104, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1234, 0, __PYX_ERR(0, 1234, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1106 + /* "pysam/libcalignedsegment.pyx":1235 + * """ * def __get__(self): - * - * if self.cache_query_qualities: # <<<<<<<<<<<<<< - * return self.cache_query_qualities - * + * return self._delegate.core.tid # <<<<<<<<<<<<<< + * def __set__(self, tid): + * if tid != -1 and self.header and not self.header.is_valid_tid(tid): */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->cache_query_qualities); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1106, __pyx_L1_error) - if (__pyx_t_1) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1235, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1107 - * - * if self.cache_query_qualities: - * return self.cache_query_qualities # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1234 * - * cdef bam1_t * src + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * return self._delegate.core.tid + * def __set__(self, tid): */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->cache_query_qualities); - __pyx_r = __pyx_v_self->cache_query_qualities; - goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1106 + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_id.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1236 * def __get__(self): - * - * if self.cache_query_qualities: # <<<<<<<<<<<<<< - * return self.cache_query_qualities - * - */ - } - - /* "pysam/libcalignedsegment.pyx":1112 - * cdef char * q - * - * src = self._delegate # <<<<<<<<<<<<<< - * - * if src.core.l_qseq == 0: - */ - __pyx_t_2 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_2; - - /* "pysam/libcalignedsegment.pyx":1114 - * src = self._delegate - * - * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< - * return None - * - */ - __pyx_t_1 = ((__pyx_v_src->core.l_qseq == 0) != 0); - if (__pyx_t_1) { - - /* "pysam/libcalignedsegment.pyx":1115 - * - * if src.core.l_qseq == 0: - * return None # <<<<<<<<<<<<<< - * - * self.cache_query_qualities = getQualitiesInRange(src, 0, src.core.l_qseq) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":1114 - * src = self._delegate - * - * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< - * return None - * - */ - } - - /* "pysam/libcalignedsegment.pyx":1117 - * return None - * - * self.cache_query_qualities = getQualitiesInRange(src, 0, src.core.l_qseq) # <<<<<<<<<<<<<< - * return self.cache_query_qualities - * - */ - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getQualitiesInRange(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_GOTREF(__pyx_v_self->cache_query_qualities); - __Pyx_DECREF(__pyx_v_self->cache_query_qualities); - __pyx_v_self->cache_query_qualities = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pysam/libcalignedsegment.pyx":1118 - * - * self.cache_query_qualities = getQualitiesInRange(src, 0, src.core.l_qseq) - * return self.cache_query_qualities # <<<<<<<<<<<<<< - * - * def __set__(self, qual): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->cache_query_qualities); - __pyx_r = __pyx_v_self->cache_query_qualities; - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":1104 - * - * """ - * def __get__(self): # <<<<<<<<<<<<<< - * - * if self.cache_query_qualities: - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_qualities.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":1120 - * return self.cache_query_qualities - * - * def __set__(self, qual): # <<<<<<<<<<<<<< - * - * # note that memory is already allocated via setting the sequence + * return self._delegate.core.tid + * def __set__(self, tid): # <<<<<<<<<<<<<< + * if tid != -1 and self.header and not self.header.is_valid_tid(tid): + * raise ValueError("reference id {} does not exist in header".format( */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_qual)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tid)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qual) { - bam1_t *__pyx_v_src; - uint8_t *__pyx_v_p; - int __pyx_v_l; - arrayobject *__pyx_v_result = 0; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tid) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; - int __pyx_t_2; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; int __pyx_t_3; - int __pyx_t_4; - Py_ssize_t __pyx_t_5; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; + int __pyx_t_7; + int32_t __pyx_t_8; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1120, 0, __PYX_ERR(0, 1120, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":1128 - * cdef int l - * - * src = self._delegate # <<<<<<<<<<<<<< - * p = pysam_bam_get_qual(src) - * if qual is None or len(qual) == 0: - */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; - - /* "pysam/libcalignedsegment.pyx":1129 - * - * src = self._delegate - * p = pysam_bam_get_qual(src) # <<<<<<<<<<<<<< - * if qual is None or len(qual) == 0: - * # if absent and there is a sequence: set to 0xff - */ - __pyx_v_p = pysam_bam_get_qual(__pyx_v_src); + __Pyx_TraceCall("__set__", __pyx_f[0], 1236, 0, __PYX_ERR(0, 1236, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1130 - * src = self._delegate - * p = pysam_bam_get_qual(src) - * if qual is None or len(qual) == 0: # <<<<<<<<<<<<<< - * # if absent and there is a sequence: set to 0xff - * if src.core.l_qseq != 0: + /* "pysam/libcalignedsegment.pyx":1237 + * return self._delegate.core.tid + * def __set__(self, tid): + * if tid != -1 and self.header and not self.header.is_valid_tid(tid): # <<<<<<<<<<<<<< + * raise ValueError("reference id {} does not exist in header".format( + * tid)) */ - __pyx_t_3 = (__pyx_v_qual == Py_None); - __pyx_t_4 = (__pyx_t_3 != 0); - if (!__pyx_t_4) { + __pyx_t_2 = PyObject_RichCompare(__pyx_v_tid, __pyx_int_neg_1, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1237, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1237, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_3) { } else { - __pyx_t_2 = __pyx_t_4; + __pyx_t_1 = __pyx_t_3; goto __pyx_L4_bool_binop_done; } - __pyx_t_5 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1130, __pyx_L1_error) - __pyx_t_4 = ((__pyx_t_5 == 0) != 0); - __pyx_t_2 = __pyx_t_4; - __pyx_L4_bool_binop_done:; - if (__pyx_t_2) { - - /* "pysam/libcalignedsegment.pyx":1132 - * if qual is None or len(qual) == 0: - * # if absent and there is a sequence: set to 0xff - * if src.core.l_qseq != 0: # <<<<<<<<<<<<<< - * p[0] = 0xff - * return - */ - __pyx_t_2 = ((__pyx_v_src->core.l_qseq != 0) != 0); - if (__pyx_t_2) { - - /* "pysam/libcalignedsegment.pyx":1133 - * # if absent and there is a sequence: set to 0xff - * if src.core.l_qseq != 0: - * p[0] = 0xff # <<<<<<<<<<<<<< - * return - * - */ - (__pyx_v_p[0]) = 0xff; - - /* "pysam/libcalignedsegment.pyx":1132 - * if qual is None or len(qual) == 0: - * # if absent and there is a sequence: set to 0xff - * if src.core.l_qseq != 0: # <<<<<<<<<<<<<< - * p[0] = 0xff - * return - */ + __pyx_t_3 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1237, __pyx_L1_error) + if (__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_is_valid_tid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); } - - /* "pysam/libcalignedsegment.pyx":1134 - * if src.core.l_qseq != 0: - * p[0] = 0xff - * return # <<<<<<<<<<<<<< - * - * # check for length match - */ - __pyx_r = 0; - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":1130 - * src = self._delegate - * p = pysam_bam_get_qual(src) - * if qual is None or len(qual) == 0: # <<<<<<<<<<<<<< - * # if absent and there is a sequence: set to 0xff - * if src.core.l_qseq != 0: - */ } + if (!__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_tid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_tid}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1237, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_tid}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1237, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_tid); + __Pyx_GIVEREF(__pyx_v_tid); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_tid); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1237, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_7 = ((!__pyx_t_3) != 0); + __pyx_t_1 = __pyx_t_7; + __pyx_L4_bool_binop_done:; + if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignedsegment.pyx":1137 - * - * # check for length match - * l = len(qual) # <<<<<<<<<<<<<< - * if src.core.l_qseq != l: - * raise ValueError( - */ - __pyx_t_5 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1137, __pyx_L1_error) - __pyx_v_l = __pyx_t_5; - - /* "pysam/libcalignedsegment.pyx":1138 - * # check for length match - * l = len(qual) - * if src.core.l_qseq != l: # <<<<<<<<<<<<<< - * raise ValueError( - * "quality and sequence mismatch: %i != %i" % - */ - __pyx_t_2 = ((__pyx_v_src->core.l_qseq != __pyx_v_l) != 0); - if (unlikely(__pyx_t_2)) { - - /* "pysam/libcalignedsegment.pyx":1141 - * raise ValueError( - * "quality and sequence mismatch: %i != %i" % - * (l, src.core.l_qseq)) # <<<<<<<<<<<<<< - * - * # create a python array object filling it + /* "pysam/libcalignedsegment.pyx":1238 + * def __set__(self, tid): + * if tid != -1 and self.header and not self.header.is_valid_tid(tid): + * raise ValueError("reference id {} does not exist in header".format( # <<<<<<<<<<<<<< + * tid)) + * self._delegate.core.tid = tid */ - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_l); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyInt_From_int32_t(__pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7); - __pyx_t_6 = 0; - __pyx_t_7 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_reference_id_does_not_exist_in_h, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libcalignedsegment.pyx":1140 - * if src.core.l_qseq != l: - * raise ValueError( - * "quality and sequence mismatch: %i != %i" % # <<<<<<<<<<<<<< - * (l, src.core.l_qseq)) + /* "pysam/libcalignedsegment.pyx":1239 + * if tid != -1 and self.header and not self.header.is_valid_tid(tid): + * raise ValueError("reference id {} does not exist in header".format( + * tid)) # <<<<<<<<<<<<<< + * self._delegate.core.tid = tid * */ - __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_quality_and_sequence_mismatch_i, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1140, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_6) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_tid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_tid}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1238, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_tid}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1238, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_INCREF(__pyx_v_tid); + __Pyx_GIVEREF(__pyx_v_tid); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_tid); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignedsegment.pyx":1139 - * l = len(qual) - * if src.core.l_qseq != l: - * raise ValueError( # <<<<<<<<<<<<<< - * "quality and sequence mismatch: %i != %i" % - * (l, src.core.l_qseq)) + /* "pysam/libcalignedsegment.pyx":1238 + * def __set__(self, tid): + * if tid != -1 and self.header and not self.header.is_valid_tid(tid): + * raise ValueError("reference id {} does not exist in header".format( # <<<<<<<<<<<<<< + * tid)) + * self._delegate.core.tid = tid */ - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 1139, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 1238, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":1138 - * # check for length match - * l = len(qual) - * if src.core.l_qseq != l: # <<<<<<<<<<<<<< - * raise ValueError( - * "quality and sequence mismatch: %i != %i" % + /* "pysam/libcalignedsegment.pyx":1237 + * return self._delegate.core.tid + * def __set__(self, tid): + * if tid != -1 and self.header and not self.header.is_valid_tid(tid): # <<<<<<<<<<<<<< + * raise ValueError("reference id {} does not exist in header".format( + * tid)) */ } - /* "pysam/libcalignedsegment.pyx":1148 - * # NB: should avoid this copying if qual is - * # already of the correct type. - * cdef c_array.array result = c_array.array('B', qual) # <<<<<<<<<<<<<< - * - * # copy data - */ - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_n_s_B); - __Pyx_GIVEREF(__pyx_n_s_B); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_n_s_B); - __Pyx_INCREF(__pyx_v_qual); - __Pyx_GIVEREF(__pyx_v_qual); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_qual); - __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_result = ((arrayobject *)__pyx_t_7); - __pyx_t_7 = 0; - - /* "pysam/libcalignedsegment.pyx":1151 - * - * # copy data - * memcpy(p, result.data.as_voidptr, l) # <<<<<<<<<<<<<< - * - * # save in cache - */ - (void)(memcpy(__pyx_v_p, __pyx_v_result->data.as_voidptr, __pyx_v_l)); - - /* "pysam/libcalignedsegment.pyx":1154 - * - * # save in cache - * self.cache_query_qualities = qual # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1240 + * raise ValueError("reference id {} does not exist in header".format( + * tid)) + * self._delegate.core.tid = tid # <<<<<<<<<<<<<< * - * property bin: + * property reference_start: */ - __Pyx_INCREF(__pyx_v_qual); - __Pyx_GIVEREF(__pyx_v_qual); - __Pyx_GOTREF(__pyx_v_self->cache_query_qualities); - __Pyx_DECREF(__pyx_v_self->cache_query_qualities); - __pyx_v_self->cache_query_qualities = __pyx_v_qual; + __pyx_t_8 = __Pyx_PyInt_As_int32_t(__pyx_v_tid); if (unlikely((__pyx_t_8 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1240, __pyx_L1_error) + __pyx_v_self->_delegate->core.tid = __pyx_t_8; - /* "pysam/libcalignedsegment.pyx":1120 - * return self.cache_query_qualities - * - * def __set__(self, qual): # <<<<<<<<<<<<<< - * - * # note that memory is already allocated via setting the sequence + /* "pysam/libcalignedsegment.pyx":1236 + * def __get__(self): + * return self._delegate.core.tid + * def __set__(self, tid): # <<<<<<<<<<<<<< + * if tid != -1 and self.header and not self.header.is_valid_tid(tid): + * raise ValueError("reference id {} does not exist in header".format( */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_qualities.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_id.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1158 - * property bin: - * """properties bin""" +/* "pysam/libcalignedsegment.pyx":1244 + * property reference_start: + * """0-based leftmost coordinate""" * def __get__(self): # <<<<<<<<<<<<<< - * return pysam_get_bin(self._delegate) - * def __set__(self, bin): + * return self._delegate.core.pos + * def __set__(self, pos): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3bin_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3bin_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3bin___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3bin___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1158, 0, __PYX_ERR(0, 1158, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1244, 0, __PYX_ERR(0, 1244, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1159 - * """properties bin""" + /* "pysam/libcalignedsegment.pyx":1245 + * """0-based leftmost coordinate""" * def __get__(self): - * return pysam_get_bin(self._delegate) # <<<<<<<<<<<<<< - * def __set__(self, bin): - * pysam_set_bin(self._delegate, bin) + * return self._delegate.core.pos # <<<<<<<<<<<<<< + * def __set__(self, pos): + * ## setting the position requires updating the "bin" attribute */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint16_t(pysam_get_bin(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1159, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1245, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1158 - * property bin: - * """properties bin""" + /* "pysam/libcalignedsegment.pyx":1244 + * property reference_start: + * """0-based leftmost coordinate""" * def __get__(self): # <<<<<<<<<<<<<< - * return pysam_get_bin(self._delegate) - * def __set__(self, bin): + * return self._delegate.core.pos + * def __set__(self, pos): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.bin.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_start.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -14136,58 +16521,79 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3bin___ge return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1160 +/* "pysam/libcalignedsegment.pyx":1246 * def __get__(self): - * return pysam_get_bin(self._delegate) - * def __set__(self, bin): # <<<<<<<<<<<<<< - * pysam_set_bin(self._delegate, bin) - * + * return self._delegate.core.pos + * def __set__(self, pos): # <<<<<<<<<<<<<< + * ## setting the position requires updating the "bin" attribute + * cdef bam1_t * src */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3bin_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3bin_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3bin_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_bin)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_pos)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3bin_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_bin) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_pos) { + bam1_t *__pyx_v_src; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; + bam1_t *__pyx_t_1; + int32_t __pyx_t_2; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1160, 0, __PYX_ERR(0, 1160, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 1246, 0, __PYX_ERR(0, 1246, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1161 - * return pysam_get_bin(self._delegate) - * def __set__(self, bin): - * pysam_set_bin(self._delegate, bin) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1249 + * ## setting the position requires updating the "bin" attribute + * cdef bam1_t * src + * src = self._delegate # <<<<<<<<<<<<<< + * src.core.pos = pos + * update_bin(src) + */ + __pyx_t_1 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_1; + + /* "pysam/libcalignedsegment.pyx":1250 + * cdef bam1_t * src + * src = self._delegate + * src.core.pos = pos # <<<<<<<<<<<<<< + * update_bin(src) * + */ + __pyx_t_2 = __Pyx_PyInt_As_int32_t(__pyx_v_pos); if (unlikely((__pyx_t_2 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1250, __pyx_L1_error) + __pyx_v_src->core.pos = __pyx_t_2; + + /* "pysam/libcalignedsegment.pyx":1251 + * src = self._delegate + * src.core.pos = pos + * update_bin(src) # <<<<<<<<<<<<<< * + * property mapping_quality: */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_bin); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1161, __pyx_L1_error) - pysam_set_bin(__pyx_v_self->_delegate, __pyx_t_1); + __pyx_f_5pysam_18libcalignedsegment_update_bin(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":1160 + /* "pysam/libcalignedsegment.pyx":1246 * def __get__(self): - * return pysam_get_bin(self._delegate) - * def __set__(self, bin): # <<<<<<<<<<<<<< - * pysam_set_bin(self._delegate, bin) - * + * return self._delegate.core.pos + * def __set__(self, pos): # <<<<<<<<<<<<<< + * ## setting the position requires updating the "bin" attribute + * cdef bam1_t * src */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.bin.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_start.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -14195,73 +16601,61 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3bin_2__set__(s return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1172 - * property is_paired: - * """true if read is paired in sequencing""" +/* "pysam/libcalignedsegment.pyx":1255 + * property mapping_quality: + * """mapping quality""" * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FPAIRED) != 0 - * def __set__(self,val): + * return pysam_get_qual(self._delegate) + * def __set__(self, qual): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1172, 0, __PYX_ERR(0, 1172, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1255, 0, __PYX_ERR(0, 1255, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1173 - * """true if read is paired in sequencing""" + /* "pysam/libcalignedsegment.pyx":1256 + * """mapping quality""" * def __get__(self): - * return (self.flag & BAM_FPAIRED) != 0 # <<<<<<<<<<<<<< - * def __set__(self,val): - * pysam_update_flag(self._delegate, val, BAM_FPAIRED) + * return pysam_get_qual(self._delegate) # <<<<<<<<<<<<<< + * def __set__(self, qual): + * pysam_set_qual(self._delegate, qual) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1173, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_uint8_t(pysam_get_qual(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1256, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FPAIRED); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1173, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1172 - * property is_paired: - * """true if read is paired in sequencing""" + /* "pysam/libcalignedsegment.pyx":1255 + * property mapping_quality: + * """mapping quality""" * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FPAIRED) != 0 - * def __set__(self,val): + * return pysam_get_qual(self._delegate) + * def __set__(self, qual): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_paired.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mapping_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -14270,50 +16664,50 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_paire return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1174 +/* "pysam/libcalignedsegment.pyx":1257 * def __get__(self): - * return (self.flag & BAM_FPAIRED) != 0 - * def __set__(self,val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FPAIRED) + * return pysam_get_qual(self._delegate) + * def __set__(self, qual): # <<<<<<<<<<<<<< + * pysam_set_qual(self._delegate, qual) * */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_qual)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qual) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; + uint8_t __pyx_t_1; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1174, 0, __PYX_ERR(0, 1174, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 1257, 0, __PYX_ERR(0, 1257, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1175 - * return (self.flag & BAM_FPAIRED) != 0 - * def __set__(self,val): - * pysam_update_flag(self._delegate, val, BAM_FPAIRED) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1258 + * return pysam_get_qual(self._delegate) + * def __set__(self, qual): + * pysam_set_qual(self._delegate, qual) # <<<<<<<<<<<<<< * - * property is_proper_pair: + * property cigarstring: */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1175, __pyx_L1_error) - pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FPAIRED); + __pyx_t_1 = __Pyx_PyInt_As_uint8_t(__pyx_v_qual); if (unlikely((__pyx_t_1 == ((uint8_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1258, __pyx_L1_error) + pysam_set_qual(__pyx_v_self->_delegate, __pyx_t_1); - /* "pysam/libcalignedsegment.pyx":1174 + /* "pysam/libcalignedsegment.pyx":1257 * def __get__(self): - * return (self.flag & BAM_FPAIRED) != 0 - * def __set__(self,val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FPAIRED) + * return pysam_get_qual(self._delegate) + * def __set__(self, qual): # <<<<<<<<<<<<<< + * pysam_set_qual(self._delegate, qual) * */ @@ -14321,7 +16715,7 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_2__s __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_paired.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mapping_quality.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -14329,207 +16723,598 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_2__s return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1179 - * property is_proper_pair: - * """true if read is mapped in a proper pair""" +/* "pysam/libcalignedsegment.pyx":1277 + * empty string. + * ''' * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FPROPER_PAIR) != 0 - * def __set__(self,val): + * c = self.cigartuples + * if c is None: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_v_c = NULL; + PyObject *__pyx_v_x = NULL; + PyObject *__pyx_v_y = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + PyObject *(*__pyx_t_6)(PyObject *); + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *(*__pyx_t_11)(PyObject *); + Py_ssize_t __pyx_t_12; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1179, 0, __PYX_ERR(0, 1179, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1277, 0, __PYX_ERR(0, 1277, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1180 - * """true if read is mapped in a proper pair""" + /* "pysam/libcalignedsegment.pyx":1278 + * ''' * def __get__(self): - * return (self.flag & BAM_FPROPER_PAIR) != 0 # <<<<<<<<<<<<<< - * def __set__(self,val): - * pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR) + * c = self.cigartuples # <<<<<<<<<<<<<< + * if c is None: + * return None */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1180, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1278, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FPROPER_PAIR); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1180, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1180, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1180, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_v_c = __pyx_t_1; + __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":1179 - * property is_proper_pair: - * """true if read is mapped in a proper pair""" + /* "pysam/libcalignedsegment.pyx":1279 + * def __get__(self): + * c = self.cigartuples + * if c is None: # <<<<<<<<<<<<<< + * return None + * # reverse order + */ + __pyx_t_2 = (__pyx_v_c == Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":1280 + * c = self.cigartuples + * if c is None: + * return None # <<<<<<<<<<<<<< + * # reverse order + * else: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":1279 + * def __get__(self): + * c = self.cigartuples + * if c is None: # <<<<<<<<<<<<<< + * return None + * # reverse order + */ + } + + /* "pysam/libcalignedsegment.pyx":1283 + * # reverse order + * else: + * return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c]) # <<<<<<<<<<<<<< + * + * def __set__(self, cigar): + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (likely(PyList_CheckExact(__pyx_v_c)) || PyTuple_CheckExact(__pyx_v_c)) { + __pyx_t_4 = __pyx_v_c; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_c); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1283, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_6)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1283, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } else { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1283, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } + } else { + __pyx_t_7 = __pyx_t_6(__pyx_t_4); + if (unlikely(!__pyx_t_7)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1283, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { + PyObject* sequence = __pyx_t_7; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1283, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_8 = PyList_GET_ITEM(sequence, 0); + __pyx_t_9 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + #else + __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext; + index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) __PYX_ERR(0, 1283, __pyx_L1_error) + __pyx_t_11 = NULL; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1283, __pyx_L1_error) + __pyx_L7_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_8); + __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 1283, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyInt_From_char((__pyx_v_5pysam_18libcalignedsegment_CODE2CIGAR[__pyx_t_12])); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_INCREF(__pyx_v_y); + __Pyx_GIVEREF(__pyx_v_y); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_y); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_i_c, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 1283, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyString_Join(__pyx_kp_s__8, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + } + + /* "pysam/libcalignedsegment.pyx":1277 + * empty string. + * ''' * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FPROPER_PAIR) != 0 - * def __set__(self,val): + * c = self.cigartuples + * if c is None: */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_proper_pair.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.cigarstring.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_c); + __Pyx_XDECREF(__pyx_v_x); + __Pyx_XDECREF(__pyx_v_y); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1181 - * def __get__(self): - * return (self.flag & BAM_FPROPER_PAIR) != 0 - * def __set__(self,val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR) - * property is_unmapped: +/* "pysam/libcalignedsegment.pyx":1285 + * return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c]) + * + * def __set__(self, cigar): # <<<<<<<<<<<<<< + * if cigar is None or len(cigar) == 0: + * self.cigartuples = [] */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_cigar); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_cigar) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_cigar)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_cigar) { + PyObject *__pyx_v_parts = NULL; + PyObject *__pyx_v_x = NULL; + PyObject *__pyx_v_y = NULL; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *(*__pyx_t_12)(PyObject *); + long __pyx_t_13; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1181, 0, __PYX_ERR(0, 1181, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 1285, 0, __PYX_ERR(0, 1285, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1182 - * return (self.flag & BAM_FPROPER_PAIR) != 0 - * def __set__(self,val): - * pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR) # <<<<<<<<<<<<<< - * property is_unmapped: - * """true if read itself is unmapped""" + /* "pysam/libcalignedsegment.pyx":1286 + * + * def __set__(self, cigar): + * if cigar is None or len(cigar) == 0: # <<<<<<<<<<<<<< + * self.cigartuples = [] + * else: */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1182, __pyx_L1_error) - pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FPROPER_PAIR); + __pyx_t_2 = (__pyx_v_cigar == Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = PyObject_Length(__pyx_v_cigar); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1286, __pyx_L1_error) + __pyx_t_3 = ((__pyx_t_4 == 0) != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1181 - * def __get__(self): - * return (self.flag & BAM_FPROPER_PAIR) != 0 - * def __set__(self,val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR) - * property is_unmapped: + /* "pysam/libcalignedsegment.pyx":1287 + * def __set__(self, cigar): + * if cigar is None or len(cigar) == 0: + * self.cigartuples = [] # <<<<<<<<<<<<<< + * else: + * parts = CIGAR_REGEX.findall(cigar) + */ + __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples, __pyx_t_5) < 0) __PYX_ERR(0, 1287, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pysam/libcalignedsegment.pyx":1286 + * + * def __set__(self, cigar): + * if cigar is None or len(cigar) == 0: # <<<<<<<<<<<<<< + * self.cigartuples = [] + * else: + */ + goto __pyx_L3; + } + + /* "pysam/libcalignedsegment.pyx":1289 + * self.cigartuples = [] + * else: + * parts = CIGAR_REGEX.findall(cigar) # <<<<<<<<<<<<<< + * # reverse order + * self.cigartuples = [(CIGAR2CODE[ord(y)], int(x)) for x,y in parts] + */ + /*else*/ { + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_REGEX); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1289, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_findall); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1289, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_6) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_cigar); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1289, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_cigar}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1289, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_cigar}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1289, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + { + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1289, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_INCREF(__pyx_v_cigar); + __Pyx_GIVEREF(__pyx_v_cigar); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_cigar); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1289, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_parts = __pyx_t_5; + __pyx_t_5 = 0; + + /* "pysam/libcalignedsegment.pyx":1291 + * parts = CIGAR_REGEX.findall(cigar) + * # reverse order + * self.cigartuples = [(CIGAR2CODE[ord(y)], int(x)) for x,y in parts] # <<<<<<<<<<<<<< + * + * # TODO + */ + __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (likely(PyList_CheckExact(__pyx_v_parts)) || PyTuple_CheckExact(__pyx_v_parts)) { + __pyx_t_7 = __pyx_v_parts; __Pyx_INCREF(__pyx_t_7); __pyx_t_4 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_parts); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1291, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_9)) { + if (likely(PyList_CheckExact(__pyx_t_7))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_8 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_4); __Pyx_INCREF(__pyx_t_8); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1291, __pyx_L1_error) + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_4); __Pyx_INCREF(__pyx_t_8); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1291, __pyx_L1_error) + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + } + } else { + __pyx_t_8 = __pyx_t_9(__pyx_t_7); + if (unlikely(!__pyx_t_8)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1291, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_8); + } + if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) { + PyObject* sequence = __pyx_t_8; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1291, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_10 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_10); + #else + __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + #endif + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_11 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_6)) goto __pyx_L8_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L8_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) __PYX_ERR(0, 1291, __pyx_L1_error) + __pyx_t_12 = NULL; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L9_unpacking_done; + __pyx_L8_unpacking_failed:; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_12 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1291, __pyx_L1_error) + __pyx_L9_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR2CODE); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_13 = __Pyx_PyObject_Ord(__pyx_v_y); if (unlikely(__pyx_t_13 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 1291, __pyx_L1_error) + __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_8, __pyx_t_13, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyNumber_Int(__pyx_v_x); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_8); + __pyx_t_10 = 0; + __pyx_t_8 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples, __pyx_t_5) < 0) __PYX_ERR(0, 1291, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __pyx_L3:; + + /* "pysam/libcalignedsegment.pyx":1285 + * return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c]) + * + * def __set__(self, cigar): # <<<<<<<<<<<<<< + * if cigar is None or len(cigar) == 0: + * self.cigartuples = [] */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_proper_pair.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.cigarstring.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_parts); + __Pyx_XDECREF(__pyx_v_x); + __Pyx_XDECREF(__pyx_v_y); __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1185 - * property is_unmapped: - * """true if read itself is unmapped""" +/* "pysam/libcalignedsegment.pyx":1299 + * property next_reference_id: + * """the :term:`reference` id of the mate/next read.""" * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FUNMAP) != 0 - * def __set__(self, val): + * return self._delegate.core.mtid + * def __set__(self, mtid): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1185, 0, __PYX_ERR(0, 1185, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1299, 0, __PYX_ERR(0, 1299, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1186 - * """true if read itself is unmapped""" + /* "pysam/libcalignedsegment.pyx":1300 + * """the :term:`reference` id of the mate/next read.""" * def __get__(self): - * return (self.flag & BAM_FUNMAP) != 0 # <<<<<<<<<<<<<< - * def __set__(self, val): - * pysam_update_flag(self._delegate, val, BAM_FUNMAP) + * return self._delegate.core.mtid # <<<<<<<<<<<<<< + * def __set__(self, mtid): + * if mtid != -1 and self.header and not self.header.is_valid_tid(mtid): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1186, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1300, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1186, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1185 - * property is_unmapped: - * """true if read itself is unmapped""" + /* "pysam/libcalignedsegment.pyx":1299 + * property next_reference_id: + * """the :term:`reference` id of the mate/next read.""" * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FUNMAP) != 0 - * def __set__(self, val): + * return self._delegate.core.mtid + * def __set__(self, mtid): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.next_reference_id.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -14538,58 +17323,226 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11is_unma return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1187 +/* "pysam/libcalignedsegment.pyx":1301 * def __get__(self): - * return (self.flag & BAM_FUNMAP) != 0 - * def __set__(self, val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FUNMAP) - * property mate_is_unmapped: + * return self._delegate.core.mtid + * def __set__(self, mtid): # <<<<<<<<<<<<<< + * if mtid != -1 and self.header and not self.header.is_valid_tid(mtid): + * raise ValueError("reference id {} does not exist in header".format( */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_mtid)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mtid) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1187, 0, __PYX_ERR(0, 1187, __pyx_L1_error)); + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + int32_t __pyx_t_8; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1301, 0, __PYX_ERR(0, 1301, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1188 - * return (self.flag & BAM_FUNMAP) != 0 - * def __set__(self, val): - * pysam_update_flag(self._delegate, val, BAM_FUNMAP) # <<<<<<<<<<<<<< - * property mate_is_unmapped: - * """true if the mate is unmapped""" + /* "pysam/libcalignedsegment.pyx":1302 + * return self._delegate.core.mtid + * def __set__(self, mtid): + * if mtid != -1 and self.header and not self.header.is_valid_tid(mtid): # <<<<<<<<<<<<<< + * raise ValueError("reference id {} does not exist in header".format( + * mtid)) */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1188, __pyx_L1_error) - pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FUNMAP); + __pyx_t_2 = PyObject_RichCompare(__pyx_v_mtid, __pyx_int_neg_1, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1302, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1302, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_3 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1302, __pyx_L1_error) + if (__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_is_valid_tid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1302, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_mtid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1302, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_mtid}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1302, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_mtid}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1302, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1302, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_mtid); + __Pyx_GIVEREF(__pyx_v_mtid); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_mtid); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1302, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1302, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_7 = ((!__pyx_t_3) != 0); + __pyx_t_1 = __pyx_t_7; + __pyx_L4_bool_binop_done:; + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcalignedsegment.pyx":1303 + * def __set__(self, mtid): + * if mtid != -1 and self.header and not self.header.is_valid_tid(mtid): + * raise ValueError("reference id {} does not exist in header".format( # <<<<<<<<<<<<<< + * mtid)) + * self._delegate.core.mtid = mtid + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_reference_id_does_not_exist_in_h, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1303, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pysam/libcalignedsegment.pyx":1304 + * if mtid != -1 and self.header and not self.header.is_valid_tid(mtid): + * raise ValueError("reference id {} does not exist in header".format( + * mtid)) # <<<<<<<<<<<<<< + * self._delegate.core.mtid = mtid + * + */ + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_6) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_mtid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1303, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_mtid}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1303, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_mtid}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1303, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1303, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_INCREF(__pyx_v_mtid); + __Pyx_GIVEREF(__pyx_v_mtid); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_mtid); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1303, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libcalignedsegment.pyx":1303 + * def __set__(self, mtid): + * if mtid != -1 and self.header and not self.header.is_valid_tid(mtid): + * raise ValueError("reference id {} does not exist in header".format( # <<<<<<<<<<<<<< + * mtid)) + * self._delegate.core.mtid = mtid + */ + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1303, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 1303, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":1302 + * return self._delegate.core.mtid + * def __set__(self, mtid): + * if mtid != -1 and self.header and not self.header.is_valid_tid(mtid): # <<<<<<<<<<<<<< + * raise ValueError("reference id {} does not exist in header".format( + * mtid)) + */ + } + + /* "pysam/libcalignedsegment.pyx":1305 + * raise ValueError("reference id {} does not exist in header".format( + * mtid)) + * self._delegate.core.mtid = mtid # <<<<<<<<<<<<<< + * + * property next_reference_name: + */ + __pyx_t_8 = __Pyx_PyInt_As_int32_t(__pyx_v_mtid); if (unlikely((__pyx_t_8 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1305, __pyx_L1_error) + __pyx_v_self->_delegate->core.mtid = __pyx_t_8; - /* "pysam/libcalignedsegment.pyx":1187 + /* "pysam/libcalignedsegment.pyx":1301 * def __get__(self): - * return (self.flag & BAM_FUNMAP) != 0 - * def __set__(self, val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FUNMAP) - * property mate_is_unmapped: + * return self._delegate.core.mtid + * def __set__(self, mtid): # <<<<<<<<<<<<<< + * if mtid != -1 and self.header and not self.header.is_valid_tid(mtid): + * raise ValueError("reference id {} does not exist in header".format( */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_unmapped.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.next_reference_id.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -14597,73 +17550,182 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_2 return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1191 - * property mate_is_unmapped: - * """true if the mate is unmapped""" +/* "pysam/libcalignedsegment.pyx":1310 + * """:term:`reference` name of the mate/next read (None if no + * AlignmentFile is associated)""" * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FMUNMAP) != 0 - * def __set__(self,val): + * if self._delegate.core.mtid == -1: + * return None */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1191, 0, __PYX_ERR(0, 1191, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1310, 0, __PYX_ERR(0, 1310, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1192 - * """true if the mate is unmapped""" + /* "pysam/libcalignedsegment.pyx":1311 + * AlignmentFile is associated)""" * def __get__(self): - * return (self.flag & BAM_FMUNMAP) != 0 # <<<<<<<<<<<<<< - * def __set__(self,val): - * pysam_update_flag(self._delegate, val, BAM_FMUNMAP) + * if self._delegate.core.mtid == -1: # <<<<<<<<<<<<<< + * return None + * if self.header: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1192, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FMUNMAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1192, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1192, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1192, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_t_1 = ((__pyx_v_self->_delegate->core.mtid == -1L) != 0); + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1191 - * property mate_is_unmapped: - * """true if the mate is unmapped""" + /* "pysam/libcalignedsegment.pyx":1312 + * def __get__(self): + * if self._delegate.core.mtid == -1: + * return None # <<<<<<<<<<<<<< + * if self.header: + * return self.header.get_reference_name(self._delegate.core.mtid) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":1311 + * AlignmentFile is associated)""" + * def __get__(self): + * if self._delegate.core.mtid == -1: # <<<<<<<<<<<<<< + * return None + * if self.header: + */ + } + + /* "pysam/libcalignedsegment.pyx":1313 + * if self._delegate.core.mtid == -1: + * return None + * if self.header: # <<<<<<<<<<<<<< + * return self.header.get_reference_name(self._delegate.core.mtid) + * else: + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1313, __pyx_L1_error) + if (likely(__pyx_t_1)) { + + /* "pysam/libcalignedsegment.pyx":1314 + * return None + * if self.header: + * return self.header.get_reference_name(self._delegate.core.mtid) # <<<<<<<<<<<<<< + * else: + * raise ValueError("next_reference_name unknown if no header associated with record") + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1314, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1314, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1314, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":1313 + * if self._delegate.core.mtid == -1: + * return None + * if self.header: # <<<<<<<<<<<<<< + * return self.header.get_reference_name(self._delegate.core.mtid) + * else: + */ + } + + /* "pysam/libcalignedsegment.pyx":1316 + * return self.header.get_reference_name(self._delegate.core.mtid) + * else: + * raise ValueError("next_reference_name unknown if no header associated with record") # <<<<<<<<<<<<<< + * + * def __set__(self, reference): + */ + /*else*/ { + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 1316, __pyx_L1_error) + } + + /* "pysam/libcalignedsegment.pyx":1310 + * """:term:`reference` name of the mate/next read (None if no + * AlignmentFile is associated)""" * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FMUNMAP) != 0 - * def __set__(self,val): + * if self._delegate.core.mtid == -1: + * return None */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mate_is_unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.next_reference_name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -14672,58 +17734,324 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1193 - * def __get__(self): - * return (self.flag & BAM_FMUNMAP) != 0 - * def __set__(self,val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FMUNMAP) - * property is_reverse: +/* "pysam/libcalignedsegment.pyx":1318 + * raise ValueError("next_reference_name unknown if no header associated with record") + * + * def __set__(self, reference): # <<<<<<<<<<<<<< + * cdef int mtid + * if reference is None or reference == "*": */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_reference)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_reference) { + int __pyx_v_mtid; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int32_t __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1193, 0, __PYX_ERR(0, 1193, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 1318, 0, __PYX_ERR(0, 1318, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1194 - * return (self.flag & BAM_FMUNMAP) != 0 - * def __set__(self,val): - * pysam_update_flag(self._delegate, val, BAM_FMUNMAP) # <<<<<<<<<<<<<< - * property is_reverse: - * """true if read is mapped to reverse strand""" + /* "pysam/libcalignedsegment.pyx":1320 + * def __set__(self, reference): + * cdef int mtid + * if reference is None or reference == "*": # <<<<<<<<<<<<<< + * self._delegate.core.mtid = -1 + * elif reference == "=": */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1194, __pyx_L1_error) - pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FMUNMAP); + __pyx_t_2 = (__pyx_v_reference == Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_reference, __pyx_kp_s__24, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1320, __pyx_L1_error) + __pyx_t_1 = __pyx_t_3; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1193 - * def __get__(self): - * return (self.flag & BAM_FMUNMAP) != 0 - * def __set__(self,val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FMUNMAP) - * property is_reverse: + /* "pysam/libcalignedsegment.pyx":1321 + * cdef int mtid + * if reference is None or reference == "*": + * self._delegate.core.mtid = -1 # <<<<<<<<<<<<<< + * elif reference == "=": + * self._delegate.core.mtid = self._delegate.core.tid + */ + __pyx_v_self->_delegate->core.mtid = -1; + + /* "pysam/libcalignedsegment.pyx":1320 + * def __set__(self, reference): + * cdef int mtid + * if reference is None or reference == "*": # <<<<<<<<<<<<<< + * self._delegate.core.mtid = -1 + * elif reference == "=": + */ + goto __pyx_L3; + } + + /* "pysam/libcalignedsegment.pyx":1322 + * if reference is None or reference == "*": + * self._delegate.core.mtid = -1 + * elif reference == "=": # <<<<<<<<<<<<<< + * self._delegate.core.mtid = self._delegate.core.tid + * elif self.header: + */ + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_reference, __pyx_kp_s__27, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1322, __pyx_L1_error) + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":1323 + * self._delegate.core.mtid = -1 + * elif reference == "=": + * self._delegate.core.mtid = self._delegate.core.tid # <<<<<<<<<<<<<< + * elif self.header: + * mtid = self.header.get_tid(reference) + */ + __pyx_t_4 = __pyx_v_self->_delegate->core.tid; + __pyx_v_self->_delegate->core.mtid = __pyx_t_4; + + /* "pysam/libcalignedsegment.pyx":1322 + * if reference is None or reference == "*": + * self._delegate.core.mtid = -1 + * elif reference == "=": # <<<<<<<<<<<<<< + * self._delegate.core.mtid = self._delegate.core.tid + * elif self.header: + */ + goto __pyx_L3; + } + + /* "pysam/libcalignedsegment.pyx":1324 + * elif reference == "=": + * self._delegate.core.mtid = self._delegate.core.tid + * elif self.header: # <<<<<<<<<<<<<< + * mtid = self.header.get_tid(reference) + * if mtid < 0: + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1324, __pyx_L1_error) + if (likely(__pyx_t_1)) { + + /* "pysam/libcalignedsegment.pyx":1325 + * self._delegate.core.mtid = self._delegate.core.tid + * elif self.header: + * mtid = self.header.get_tid(reference) # <<<<<<<<<<<<<< + * if mtid < 0: + * raise ValueError("reference {} does not exist in header".format( + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1325, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + if (!__pyx_t_7) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_reference); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1325, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_reference}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1325, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_reference}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1325, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + { + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1325, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL; + __Pyx_INCREF(__pyx_v_reference); + __Pyx_GIVEREF(__pyx_v_reference); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_reference); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1325, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1325, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_mtid = __pyx_t_9; + + /* "pysam/libcalignedsegment.pyx":1326 + * elif self.header: + * mtid = self.header.get_tid(reference) + * if mtid < 0: # <<<<<<<<<<<<<< + * raise ValueError("reference {} does not exist in header".format( + * reference)) + */ + __pyx_t_1 = ((__pyx_v_mtid < 0) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcalignedsegment.pyx":1327 + * mtid = self.header.get_tid(reference) + * if mtid < 0: + * raise ValueError("reference {} does not exist in header".format( # <<<<<<<<<<<<<< + * reference)) + * self._delegate.core.mtid = mtid + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_reference_does_not_exist_in_head, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1327, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + + /* "pysam/libcalignedsegment.pyx":1328 + * if mtid < 0: + * raise ValueError("reference {} does not exist in header".format( + * reference)) # <<<<<<<<<<<<<< + * self._delegate.core.mtid = mtid + * else: + */ + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + if (!__pyx_t_8) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_reference); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1327, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_reference}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1327, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_reference}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1327, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1327, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_INCREF(__pyx_v_reference); + __Pyx_GIVEREF(__pyx_v_reference); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_reference); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1327, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pysam/libcalignedsegment.pyx":1327 + * mtid = self.header.get_tid(reference) + * if mtid < 0: + * raise ValueError("reference {} does not exist in header".format( # <<<<<<<<<<<<<< + * reference)) + * self._delegate.core.mtid = mtid + */ + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1327, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 1327, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":1326 + * elif self.header: + * mtid = self.header.get_tid(reference) + * if mtid < 0: # <<<<<<<<<<<<<< + * raise ValueError("reference {} does not exist in header".format( + * reference)) + */ + } + + /* "pysam/libcalignedsegment.pyx":1329 + * raise ValueError("reference {} does not exist in header".format( + * reference)) + * self._delegate.core.mtid = mtid # <<<<<<<<<<<<<< + * else: + * raise ValueError("next_reference_name can not be set if no header associated with record") + */ + __pyx_v_self->_delegate->core.mtid = __pyx_v_mtid; + + /* "pysam/libcalignedsegment.pyx":1324 + * elif reference == "=": + * self._delegate.core.mtid = self._delegate.core.tid + * elif self.header: # <<<<<<<<<<<<<< + * mtid = self.header.get_tid(reference) + * if mtid < 0: + */ + goto __pyx_L3; + } + + /* "pysam/libcalignedsegment.pyx":1331 + * self._delegate.core.mtid = mtid + * else: + * raise ValueError("next_reference_name can not be set if no header associated with record") # <<<<<<<<<<<<<< + * + * property next_reference_start: + */ + /*else*/ { + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 1331, __pyx_L1_error) + } + __pyx_L3:; + + /* "pysam/libcalignedsegment.pyx":1318 + * raise ValueError("next_reference_name unknown if no header associated with record") + * + * def __set__(self, reference): # <<<<<<<<<<<<<< + * cdef int mtid + * if reference is None or reference == "*": */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mate_is_unmapped.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.next_reference_name.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -14731,73 +18059,61 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmap return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1197 - * property is_reverse: - * """true if read is mapped to reverse strand""" +/* "pysam/libcalignedsegment.pyx":1335 + * property next_reference_start: + * """the position of the mate/next read.""" * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FREVERSE) != 0 - * def __set__(self,val): + * return self._delegate.core.mpos + * def __set__(self, mpos): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1197, 0, __PYX_ERR(0, 1197, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1335, 0, __PYX_ERR(0, 1335, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1198 - * """true if read is mapped to reverse strand""" + /* "pysam/libcalignedsegment.pyx":1336 + * """the position of the mate/next read.""" * def __get__(self): - * return (self.flag & BAM_FREVERSE) != 0 # <<<<<<<<<<<<<< - * def __set__(self,val): - * pysam_update_flag(self._delegate, val, BAM_FREVERSE) + * return self._delegate.core.mpos # <<<<<<<<<<<<<< + * def __set__(self, mpos): + * self._delegate.core.mpos = mpos */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1198, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1336, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREVERSE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1198, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1198, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1198, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1197 - * property is_reverse: - * """true if read is mapped to reverse strand""" + /* "pysam/libcalignedsegment.pyx":1335 + * property next_reference_start: + * """the position of the mate/next read.""" * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FREVERSE) != 0 - * def __set__(self,val): + * return self._delegate.core.mpos + * def __set__(self, mpos): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_reverse.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.next_reference_start.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -14806,58 +18122,58 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10is_reve return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1199 +/* "pysam/libcalignedsegment.pyx":1337 * def __get__(self): - * return (self.flag & BAM_FREVERSE) != 0 - * def __set__(self,val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FREVERSE) - * property mate_is_reverse: + * return self._delegate.core.mpos + * def __set__(self, mpos): # <<<<<<<<<<<<<< + * self._delegate.core.mpos = mpos + * */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_mpos)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mpos) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; + int32_t __pyx_t_1; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1199, 0, __PYX_ERR(0, 1199, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 1337, 0, __PYX_ERR(0, 1337, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1200 - * return (self.flag & BAM_FREVERSE) != 0 - * def __set__(self,val): - * pysam_update_flag(self._delegate, val, BAM_FREVERSE) # <<<<<<<<<<<<<< - * property mate_is_reverse: - * """true is read is mapped to reverse strand""" + /* "pysam/libcalignedsegment.pyx":1338 + * return self._delegate.core.mpos + * def __set__(self, mpos): + * self._delegate.core.mpos = mpos # <<<<<<<<<<<<<< + * + * property query_length: */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1200, __pyx_L1_error) - pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREVERSE); + __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_mpos); if (unlikely((__pyx_t_1 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1338, __pyx_L1_error) + __pyx_v_self->_delegate->core.mpos = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":1199 + /* "pysam/libcalignedsegment.pyx":1337 * def __get__(self): - * return (self.flag & BAM_FREVERSE) != 0 - * def __set__(self,val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FREVERSE) - * property mate_is_reverse: + * return self._delegate.core.mpos + * def __set__(self, mpos): # <<<<<<<<<<<<<< + * self._delegate.core.mpos = mpos + * */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_reverse.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.next_reference_start.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -14865,73 +18181,61 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_2_ return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1203 - * property mate_is_reverse: - * """true is read is mapped to reverse strand""" +/* "pysam/libcalignedsegment.pyx":1358 + * + * """ * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FMREVERSE) != 0 - * def __set__(self,val): + * return self._delegate.core.l_qseq + * */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12query_length_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12query_length_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12query_length___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12query_length___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1203, 0, __PYX_ERR(0, 1203, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1358, 0, __PYX_ERR(0, 1358, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1204 - * """true is read is mapped to reverse strand""" + /* "pysam/libcalignedsegment.pyx":1359 + * """ * def __get__(self): - * return (self.flag & BAM_FMREVERSE) != 0 # <<<<<<<<<<<<<< - * def __set__(self,val): - * pysam_update_flag(self._delegate, val, BAM_FMREVERSE) + * return self._delegate.core.l_qseq # <<<<<<<<<<<<<< + * + * property template_length: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1204, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.l_qseq); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1359, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FMREVERSE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1204, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1204, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1204, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1203 - * property mate_is_reverse: - * """true is read is mapped to reverse strand""" + /* "pysam/libcalignedsegment.pyx":1358 + * + * """ * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FMREVERSE) != 0 - * def __set__(self,val): + * return self._delegate.core.l_qseq + * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mate_is_reverse.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -14940,132 +18244,61 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1205 - * def __get__(self): - * return (self.flag & BAM_FMREVERSE) != 0 - * def __set__(self,val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FMREVERSE) - * property is_read1: - */ - -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1205, 0, __PYX_ERR(0, 1205, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":1206 - * return (self.flag & BAM_FMREVERSE) != 0 - * def __set__(self,val): - * pysam_update_flag(self._delegate, val, BAM_FMREVERSE) # <<<<<<<<<<<<<< - * property is_read1: - * """true if this is read1""" - */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1206, __pyx_L1_error) - pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FMREVERSE); - - /* "pysam/libcalignedsegment.pyx":1205 - * def __get__(self): - * return (self.flag & BAM_FMREVERSE) != 0 - * def __set__(self,val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FMREVERSE) - * property is_read1: - */ - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mate_is_reverse.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":1209 - * property is_read1: - * """true if this is read1""" +/* "pysam/libcalignedsegment.pyx":1363 + * property template_length: + * """the observed query template length""" * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FREAD1) != 0 - * def __set__(self,val): + * return self._delegate.core.isize + * def __set__(self, isize): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15template_length___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15template_length___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1209, 0, __PYX_ERR(0, 1209, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1363, 0, __PYX_ERR(0, 1363, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1210 - * """true if this is read1""" + /* "pysam/libcalignedsegment.pyx":1364 + * """the observed query template length""" * def __get__(self): - * return (self.flag & BAM_FREAD1) != 0 # <<<<<<<<<<<<<< - * def __set__(self,val): - * pysam_update_flag(self._delegate, val, BAM_FREAD1) + * return self._delegate.core.isize # <<<<<<<<<<<<<< + * def __set__(self, isize): + * self._delegate.core.isize = isize */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1210, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.isize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1364, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREAD1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1210, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1209 - * property is_read1: - * """true if this is read1""" + /* "pysam/libcalignedsegment.pyx":1363 + * property template_length: + * """the observed query template length""" * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FREAD1) != 0 - * def __set__(self,val): + * return self._delegate.core.isize + * def __set__(self, isize): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_read1.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.template_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -15074,58 +18307,58 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1 return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1211 +/* "pysam/libcalignedsegment.pyx":1365 * def __get__(self): - * return (self.flag & BAM_FREAD1) != 0 - * def __set__(self,val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FREAD1) - * property is_read2: + * return self._delegate.core.isize + * def __set__(self, isize): # <<<<<<<<<<<<<< + * self._delegate.core.isize = isize + * */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_isize)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_isize) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; + int32_t __pyx_t_1; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1211, 0, __PYX_ERR(0, 1211, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 1365, 0, __PYX_ERR(0, 1365, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1212 - * return (self.flag & BAM_FREAD1) != 0 - * def __set__(self,val): - * pysam_update_flag(self._delegate, val, BAM_FREAD1) # <<<<<<<<<<<<<< - * property is_read2: - * """true if this is read2""" + /* "pysam/libcalignedsegment.pyx":1366 + * return self._delegate.core.isize + * def __set__(self, isize): + * self._delegate.core.isize = isize # <<<<<<<<<<<<<< + * + * property query_sequence: */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1212, __pyx_L1_error) - pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREAD1); + __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_isize); if (unlikely((__pyx_t_1 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1366, __pyx_L1_error) + __pyx_v_self->_delegate->core.isize = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":1211 + /* "pysam/libcalignedsegment.pyx":1365 * def __get__(self): - * return (self.flag & BAM_FREAD1) != 0 - * def __set__(self,val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FREAD1) - * property is_read2: + * return self._delegate.core.isize + * def __set__(self, isize): # <<<<<<<<<<<<<< + * self._delegate.core.isize = isize + * */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_read1.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.template_length.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -15133,207 +18366,153 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_2__se return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1215 - * property is_read2: - * """true if this is read2""" +/* "pysam/libcalignedsegment.pyx":1384 + * sequence. + * """ * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FREAD2) != 0 - * def __set__(self, val): + * if self.cache_query_sequence: + * return self.cache_query_sequence */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + bam1_t *__pyx_v_src; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + int __pyx_t_1; + bam1_t *__pyx_t_2; PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1215, 0, __PYX_ERR(0, 1215, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1384, 0, __PYX_ERR(0, 1384, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1216 - * """true if this is read2""" + /* "pysam/libcalignedsegment.pyx":1385 + * """ * def __get__(self): - * return (self.flag & BAM_FREAD2) != 0 # <<<<<<<<<<<<<< - * def __set__(self, val): - * pysam_update_flag(self._delegate, val, BAM_FREAD2) + * if self.cache_query_sequence: # <<<<<<<<<<<<<< + * return self.cache_query_sequence + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1216, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREAD2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1216, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1216, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1216, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->cache_query_sequence); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1385, __pyx_L1_error) + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1215 - * property is_read2: - * """true if this is read2""" - * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FREAD2) != 0 - * def __set__(self, val): + /* "pysam/libcalignedsegment.pyx":1386 + * def __get__(self): + * if self.cache_query_sequence: + * return self.cache_query_sequence # <<<<<<<<<<<<<< + * + * cdef bam1_t * src */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->cache_query_sequence); + __pyx_r = __pyx_v_self->cache_query_sequence; + goto __pyx_L0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_read2.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":1217 + /* "pysam/libcalignedsegment.pyx":1385 + * """ * def __get__(self): - * return (self.flag & BAM_FREAD2) != 0 - * def __set__(self, val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FREAD2) - * property is_secondary: + * if self.cache_query_sequence: # <<<<<<<<<<<<<< + * return self.cache_query_sequence + * */ + } -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1217, 0, __PYX_ERR(0, 1217, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":1218 - * return (self.flag & BAM_FREAD2) != 0 - * def __set__(self, val): - * pysam_update_flag(self._delegate, val, BAM_FREAD2) # <<<<<<<<<<<<<< - * property is_secondary: - * """true if not primary alignment""" + /* "pysam/libcalignedsegment.pyx":1390 + * cdef bam1_t * src + * cdef char * s + * src = self._delegate # <<<<<<<<<<<<<< + * + * if src.core.l_qseq == 0: */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1218, __pyx_L1_error) - pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREAD2); + __pyx_t_2 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_2; - /* "pysam/libcalignedsegment.pyx":1217 - * def __get__(self): - * return (self.flag & BAM_FREAD2) != 0 - * def __set__(self, val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FREAD2) - * property is_secondary: + /* "pysam/libcalignedsegment.pyx":1392 + * src = self._delegate + * + * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< + * return None + * */ + __pyx_t_1 = ((__pyx_v_src->core.l_qseq == 0) != 0); + if (__pyx_t_1) { - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_read2.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":1221 - * property is_secondary: - * """true if not primary alignment""" - * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FSECONDARY) != 0 - * def __set__(self, val): + /* "pysam/libcalignedsegment.pyx":1393 + * + * if src.core.l_qseq == 0: + * return None # <<<<<<<<<<<<<< + * + * self.cache_query_sequence = force_str(getSequenceInRange( */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1221, 0, __PYX_ERR(0, 1221, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":1392 + * src = self._delegate + * + * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< + * return None + * + */ + } - /* "pysam/libcalignedsegment.pyx":1222 - * """true if not primary alignment""" - * def __get__(self): - * return (self.flag & BAM_FSECONDARY) != 0 # <<<<<<<<<<<<<< - * def __set__(self, val): - * pysam_update_flag(self._delegate, val, BAM_FSECONDARY) + /* "pysam/libcalignedsegment.pyx":1395 + * return None + * + * self.cache_query_sequence = force_str(getSequenceInRange( # <<<<<<<<<<<<<< + * src, 0, src.core.l_qseq)) + * return self.cache_query_sequence */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1222, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FSECONDARY); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1222, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1222, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getSequenceInRange(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1395, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1222, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1395, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_v_self->cache_query_sequence); + __Pyx_DECREF(__pyx_v_self->cache_query_sequence); + __pyx_v_self->cache_query_sequence = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pysam/libcalignedsegment.pyx":1397 + * self.cache_query_sequence = force_str(getSequenceInRange( + * src, 0, src.core.l_qseq)) + * return self.cache_query_sequence # <<<<<<<<<<<<<< + * + * def __set__(self, seq): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->cache_query_sequence); + __pyx_r = __pyx_v_self->cache_query_sequence; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1221 - * property is_secondary: - * """true if not primary alignment""" + /* "pysam/libcalignedsegment.pyx":1384 + * sequence. + * """ * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FSECONDARY) != 0 - * def __set__(self, val): + * if self.cache_query_sequence: + * return self.cache_query_sequence */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_secondary.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_sequence.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -15342,400 +18521,495 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_seco return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1223 - * def __get__(self): - * return (self.flag & BAM_FSECONDARY) != 0 - * def __set__(self, val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FSECONDARY) - * property is_qcfail: +/* "pysam/libcalignedsegment.pyx":1399 + * return self.cache_query_sequence + * + * def __set__(self, seq): # <<<<<<<<<<<<<< + * # samtools manages sequence and quality length memory together + * # if no quality information is present, the first byte says 0xff. */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_seq)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_seq) { + bam1_t *__pyx_v_src; + uint8_t *__pyx_v_p; + char *__pyx_v_s; + int __pyx_v_l; + int __pyx_v_k; + Py_ssize_t __pyx_v_nbytes_new; + Py_ssize_t __pyx_v_nbytes_old; + bam1_t *__pyx_v_retval; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + Py_ssize_t __pyx_t_3; + bam1_t *__pyx_t_4; + char *__pyx_t_5; + int __pyx_t_6; + long __pyx_t_7; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1223, 0, __PYX_ERR(0, 1223, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 1399, 0, __PYX_ERR(0, 1399, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_seq); - /* "pysam/libcalignedsegment.pyx":1224 - * return (self.flag & BAM_FSECONDARY) != 0 - * def __set__(self, val): - * pysam_update_flag(self._delegate, val, BAM_FSECONDARY) # <<<<<<<<<<<<<< - * property is_qcfail: - * """true if QC failure""" + /* "pysam/libcalignedsegment.pyx":1408 + * cdef Py_ssize_t nbytes_new, nbytes_old + * + * if seq == None: # <<<<<<<<<<<<<< + * l = 0 + * else: */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1224, __pyx_L1_error) - pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FSECONDARY); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_seq, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1408, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1408, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":1223 - * def __get__(self): - * return (self.flag & BAM_FSECONDARY) != 0 - * def __set__(self, val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FSECONDARY) - * property is_qcfail: + /* "pysam/libcalignedsegment.pyx":1409 + * + * if seq == None: + * l = 0 # <<<<<<<<<<<<<< + * else: + * l = len(seq) */ + __pyx_v_l = 0; - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_secondary.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":1227 - * property is_qcfail: - * """true if QC failure""" - * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FQCFAIL) != 0 - * def __set__(self, val): + /* "pysam/libcalignedsegment.pyx":1408 + * cdef Py_ssize_t nbytes_new, nbytes_old + * + * if seq == None: # <<<<<<<<<<<<<< + * l = 0 + * else: */ + goto __pyx_L3; + } -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1411 + * l = 0 + * else: + * l = len(seq) # <<<<<<<<<<<<<< + * seq = force_bytes(seq) + * + */ + /*else*/ { + __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1411, __pyx_L1_error) + __pyx_v_l = __pyx_t_3; -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1227, 0, __PYX_ERR(0, 1227, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":1412 + * else: + * l = len(seq) + * seq = force_bytes(seq) # <<<<<<<<<<<<<< + * + * src = self._delegate + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_seq, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1412, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF_SET(__pyx_v_seq, __pyx_t_1); + __pyx_t_1 = 0; + } + __pyx_L3:; - /* "pysam/libcalignedsegment.pyx":1228 - * """true if QC failure""" - * def __get__(self): - * return (self.flag & BAM_FQCFAIL) != 0 # <<<<<<<<<<<<<< - * def __set__(self, val): - * pysam_update_flag(self._delegate, val, BAM_FQCFAIL) + /* "pysam/libcalignedsegment.pyx":1414 + * seq = force_bytes(seq) + * + * src = self._delegate # <<<<<<<<<<<<<< + * + * # as the sequence is stored in half-bytes, the total length (sequence */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FQCFAIL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1228, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_t_4 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_4; - /* "pysam/libcalignedsegment.pyx":1227 - * property is_qcfail: - * """true if QC failure""" - * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FQCFAIL) != 0 - * def __set__(self, val): + /* "pysam/libcalignedsegment.pyx":1418 + * # as the sequence is stored in half-bytes, the total length (sequence + * # plus quality scores) is (l+1)/2 + l + * nbytes_new = (l + 1) / 2 + l # <<<<<<<<<<<<<< + * nbytes_old = (src.core.l_qseq + 1) / 2 + src.core.l_qseq + * */ + __pyx_v_nbytes_new = (__Pyx_div_long((__pyx_v_l + 1), 2) + __pyx_v_l); - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_qcfail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1419 + * # plus quality scores) is (l+1)/2 + l + * nbytes_new = (l + 1) / 2 + l + * nbytes_old = (src.core.l_qseq + 1) / 2 + src.core.l_qseq # <<<<<<<<<<<<<< + * + * # acquire pointer to location in memory + */ + __pyx_v_nbytes_old = (__Pyx_div_long((__pyx_v_src->core.l_qseq + 1), 2) + __pyx_v_src->core.l_qseq); -/* "pysam/libcalignedsegment.pyx":1229 - * def __get__(self): - * return (self.flag & BAM_FQCFAIL) != 0 - * def __set__(self, val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FQCFAIL) - * property is_duplicate: + /* "pysam/libcalignedsegment.pyx":1422 + * + * # acquire pointer to location in memory + * p = pysam_bam_get_seq(src) # <<<<<<<<<<<<<< + * src.core.l_qseq = l + * */ + __pyx_v_p = pysam_bam_get_seq(__pyx_v_src); -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + /* "pysam/libcalignedsegment.pyx":1423 + * # acquire pointer to location in memory + * p = pysam_bam_get_seq(src) + * src.core.l_qseq = l # <<<<<<<<<<<<<< + * + * # change length of data field + */ + __pyx_v_src->core.l_qseq = __pyx_v_l; - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1426 + * + * # change length of data field + * cdef bam1_t * retval = pysam_bam_update(src, # <<<<<<<<<<<<<< + * nbytes_old, + * nbytes_new, + */ + __pyx_v_retval = pysam_bam_update(__pyx_v_src, __pyx_v_nbytes_old, __pyx_v_nbytes_new, __pyx_v_p); -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1229, 0, __PYX_ERR(0, 1229, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":1431 + * p) + * + * if retval == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate memory") + * + */ + __pyx_t_2 = ((__pyx_v_retval == NULL) != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcalignedsegment.pyx":1230 - * return (self.flag & BAM_FQCFAIL) != 0 - * def __set__(self, val): - * pysam_update_flag(self._delegate, val, BAM_FQCFAIL) # <<<<<<<<<<<<<< - * property is_duplicate: - * """true if optical or PCR duplicate""" + /* "pysam/libcalignedsegment.pyx":1432 + * + * if retval == NULL: + * raise MemoryError("could not allocate memory") # <<<<<<<<<<<<<< + * + * if l > 0: */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1230, __pyx_L1_error) - pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FQCFAIL); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1432, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 1432, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":1229 - * def __get__(self): - * return (self.flag & BAM_FQCFAIL) != 0 - * def __set__(self, val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FQCFAIL) - * property is_duplicate: + /* "pysam/libcalignedsegment.pyx":1431 + * p) + * + * if retval == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate memory") + * */ + } - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_qcfail.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1434 + * raise MemoryError("could not allocate memory") + * + * if l > 0: # <<<<<<<<<<<<<< + * # re-acquire pointer to location in memory + * # as it might have moved + */ + __pyx_t_2 = ((__pyx_v_l > 0) != 0); + if (__pyx_t_2) { -/* "pysam/libcalignedsegment.pyx":1233 - * property is_duplicate: - * """true if optical or PCR duplicate""" - * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FDUP) != 0 - * def __set__(self, val): + /* "pysam/libcalignedsegment.pyx":1437 + * # re-acquire pointer to location in memory + * # as it might have moved + * p = pysam_bam_get_seq(src) # <<<<<<<<<<<<<< + * for k from 0 <= k < nbytes_new: + * p[k] = 0 */ + __pyx_v_p = pysam_bam_get_seq(__pyx_v_src); -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + /* "pysam/libcalignedsegment.pyx":1438 + * # as it might have moved + * p = pysam_bam_get_seq(src) + * for k from 0 <= k < nbytes_new: # <<<<<<<<<<<<<< + * p[k] = 0 + * # convert to C string + */ + __pyx_t_3 = __pyx_v_nbytes_new; + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1439 + * p = pysam_bam_get_seq(src) + * for k from 0 <= k < nbytes_new: + * p[k] = 0 # <<<<<<<<<<<<<< + * # convert to C string + * s = seq + */ + (__pyx_v_p[__pyx_v_k]) = 0; + } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1233, 0, __PYX_ERR(0, 1233, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":1441 + * p[k] = 0 + * # convert to C string + * s = seq # <<<<<<<<<<<<<< + * for k from 0 <= k < l: + * p[k/2] |= seq_nt16_table[s[k]] << 4 * (1 - k % 2) + */ + __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_seq); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 1441, __pyx_L1_error) + __pyx_v_s = __pyx_t_5; - /* "pysam/libcalignedsegment.pyx":1234 - * """true if optical or PCR duplicate""" - * def __get__(self): - * return (self.flag & BAM_FDUP) != 0 # <<<<<<<<<<<<<< - * def __set__(self, val): - * pysam_update_flag(self._delegate, val, BAM_FDUP) + /* "pysam/libcalignedsegment.pyx":1442 + * # convert to C string + * s = seq + * for k from 0 <= k < l: # <<<<<<<<<<<<<< + * p[k/2] |= seq_nt16_table[s[k]] << 4 * (1 - k % 2) + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1234, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FDUP); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1234, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1234, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1234, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_t_6 = __pyx_v_l; + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) { - /* "pysam/libcalignedsegment.pyx":1233 - * property is_duplicate: - * """true if optical or PCR duplicate""" - * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FDUP) != 0 - * def __set__(self, val): + /* "pysam/libcalignedsegment.pyx":1443 + * s = seq + * for k from 0 <= k < l: + * p[k/2] |= seq_nt16_table[s[k]] << 4 * (1 - k % 2) # <<<<<<<<<<<<<< + * + * # erase qualities */ + __pyx_t_7 = __Pyx_div_long(__pyx_v_k, 2); + (__pyx_v_p[__pyx_t_7]) = ((__pyx_v_p[__pyx_t_7]) | ((seq_nt16_table[((unsigned char)(__pyx_v_s[__pyx_v_k]))]) << (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2))))); + } - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_duplicate.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1446 + * + * # erase qualities + * p = pysam_bam_get_qual(src) # <<<<<<<<<<<<<< + * p[0] = 0xff + * + */ + __pyx_v_p = pysam_bam_get_qual(__pyx_v_src); -/* "pysam/libcalignedsegment.pyx":1235 - * def __get__(self): - * return (self.flag & BAM_FDUP) != 0 - * def __set__(self, val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FDUP) - * property is_supplementary: + /* "pysam/libcalignedsegment.pyx":1447 + * # erase qualities + * p = pysam_bam_get_qual(src) + * p[0] = 0xff # <<<<<<<<<<<<<< + * + * self.cache_query_sequence = force_str(seq) */ + (__pyx_v_p[0]) = 0xff; -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + /* "pysam/libcalignedsegment.pyx":1434 + * raise MemoryError("could not allocate memory") + * + * if l > 0: # <<<<<<<<<<<<<< + * # re-acquire pointer to location in memory + * # as it might have moved + */ + } - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1449 + * p[0] = 0xff + * + * self.cache_query_sequence = force_str(seq) # <<<<<<<<<<<<<< + * + * # clear cached values for quality values + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_seq, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->cache_query_sequence); + __Pyx_DECREF(__pyx_v_self->cache_query_sequence); + __pyx_v_self->cache_query_sequence = __pyx_t_1; + __pyx_t_1 = 0; -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1235, 0, __PYX_ERR(0, 1235, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":1452 + * + * # clear cached values for quality values + * self.cache_query_qualities = None # <<<<<<<<<<<<<< + * self.cache_query_alignment_qualities = None + * + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->cache_query_qualities); + __Pyx_DECREF(__pyx_v_self->cache_query_qualities); + __pyx_v_self->cache_query_qualities = Py_None; - /* "pysam/libcalignedsegment.pyx":1236 - * return (self.flag & BAM_FDUP) != 0 - * def __set__(self, val): - * pysam_update_flag(self._delegate, val, BAM_FDUP) # <<<<<<<<<<<<<< - * property is_supplementary: - * """true if this is a supplementary alignment""" + /* "pysam/libcalignedsegment.pyx":1453 + * # clear cached values for quality values + * self.cache_query_qualities = None + * self.cache_query_alignment_qualities = None # <<<<<<<<<<<<<< + * + * property query_qualities: */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1236, __pyx_L1_error) - pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FDUP); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_qualities); + __Pyx_DECREF(__pyx_v_self->cache_query_alignment_qualities); + __pyx_v_self->cache_query_alignment_qualities = Py_None; - /* "pysam/libcalignedsegment.pyx":1235 - * def __get__(self): - * return (self.flag & BAM_FDUP) != 0 - * def __set__(self, val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FDUP) - * property is_supplementary: + /* "pysam/libcalignedsegment.pyx":1399 + * return self.cache_query_sequence + * + * def __set__(self, seq): # <<<<<<<<<<<<<< + * # samtools manages sequence and quality length memory together + * # if no quality information is present, the first byte says 0xff. */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_duplicate.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_sequence.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_seq); __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1239 - * property is_supplementary: - * """true if this is a supplementary alignment""" +/* "pysam/libcalignedsegment.pyx":1472 + * + * """ * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FSUPPLEMENTARY) != 0 - * def __set__(self, val): + * + * if self.cache_query_qualities: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + bam1_t *__pyx_v_src; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + int __pyx_t_1; + bam1_t *__pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1239, 0, __PYX_ERR(0, 1239, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1472, 0, __PYX_ERR(0, 1472, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1240 - * """true if this is a supplementary alignment""" + /* "pysam/libcalignedsegment.pyx":1474 * def __get__(self): - * return (self.flag & BAM_FSUPPLEMENTARY) != 0 # <<<<<<<<<<<<<< - * def __set__(self, val): - * pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY) + * + * if self.cache_query_qualities: # <<<<<<<<<<<<<< + * return self.cache_query_qualities + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FSUPPLEMENTARY); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1240, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->cache_query_qualities); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1474, __pyx_L1_error) + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":1475 + * + * if self.cache_query_qualities: + * return self.cache_query_qualities # <<<<<<<<<<<<<< + * + * cdef bam1_t * src + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->cache_query_qualities); + __pyx_r = __pyx_v_self->cache_query_qualities; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":1474 + * def __get__(self): + * + * if self.cache_query_qualities: # <<<<<<<<<<<<<< + * return self.cache_query_qualities + * + */ + } + + /* "pysam/libcalignedsegment.pyx":1480 + * cdef char * q + * + * src = self._delegate # <<<<<<<<<<<<<< + * + * if src.core.l_qseq == 0: + */ + __pyx_t_2 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_2; + + /* "pysam/libcalignedsegment.pyx":1482 + * src = self._delegate + * + * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< + * return None + * + */ + __pyx_t_1 = ((__pyx_v_src->core.l_qseq == 0) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":1483 + * + * if src.core.l_qseq == 0: + * return None # <<<<<<<<<<<<<< + * + * self.cache_query_qualities = getQualitiesInRange(src, 0, src.core.l_qseq) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":1482 + * src = self._delegate + * + * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< + * return None + * + */ + } + + /* "pysam/libcalignedsegment.pyx":1485 + * return None + * + * self.cache_query_qualities = getQualitiesInRange(src, 0, src.core.l_qseq) # <<<<<<<<<<<<<< + * return self.cache_query_qualities + * + */ + __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getQualitiesInRange(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1485, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->cache_query_qualities); + __Pyx_DECREF(__pyx_v_self->cache_query_qualities); + __pyx_v_self->cache_query_qualities = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pysam/libcalignedsegment.pyx":1486 + * + * self.cache_query_qualities = getQualitiesInRange(src, 0, src.core.l_qseq) + * return self.cache_query_qualities # <<<<<<<<<<<<<< + * + * def __set__(self, qual): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->cache_query_qualities); + __pyx_r = __pyx_v_self->cache_query_qualities; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1239 - * property is_supplementary: - * """true if this is a supplementary alignment""" + /* "pysam/libcalignedsegment.pyx":1472 + * + * """ * def __get__(self): # <<<<<<<<<<<<<< - * return (self.flag & BAM_FSUPPLEMENTARY) != 0 - * def __set__(self, val): + * + * if self.cache_query_qualities: */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_supplementary.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_qualities.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -15744,321 +19018,462 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16is_supp return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1241 - * def __get__(self): - * return (self.flag & BAM_FSUPPLEMENTARY) != 0 - * def __set__(self, val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY) +/* "pysam/libcalignedsegment.pyx":1488 + * return self.cache_query_qualities + * + * def __set__(self, qual): # <<<<<<<<<<<<<< * + * # note that memory is already allocated via setting the sequence */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { - int __pyx_r; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) { + int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_qual)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qual) { + bam1_t *__pyx_v_src; + uint8_t *__pyx_v_p; + int __pyx_v_l; + arrayobject *__pyx_v_result = 0; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; + bam1_t *__pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1241, 0, __PYX_ERR(0, 1241, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 1488, 0, __PYX_ERR(0, 1488, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1242 - * return (self.flag & BAM_FSUPPLEMENTARY) != 0 - * def __set__(self, val): - * pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1496 + * cdef int l * - * # 2. Coordinates and lengths + * src = self._delegate # <<<<<<<<<<<<<< + * p = pysam_bam_get_qual(src) + * if qual is None or len(qual) == 0: */ - __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1242, __pyx_L1_error) - pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FSUPPLEMENTARY); + __pyx_t_1 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":1241 - * def __get__(self): - * return (self.flag & BAM_FSUPPLEMENTARY) != 0 - * def __set__(self, val): # <<<<<<<<<<<<<< - * pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY) + /* "pysam/libcalignedsegment.pyx":1497 + * + * src = self._delegate + * p = pysam_bam_get_qual(src) # <<<<<<<<<<<<<< + * if qual is None or len(qual) == 0: + * # if absent and there is a sequence: set to 0xff + */ + __pyx_v_p = pysam_bam_get_qual(__pyx_v_src); + + /* "pysam/libcalignedsegment.pyx":1498 + * src = self._delegate + * p = pysam_bam_get_qual(src) + * if qual is None or len(qual) == 0: # <<<<<<<<<<<<<< + * # if absent and there is a sequence: set to 0xff + * if src.core.l_qseq != 0: + */ + __pyx_t_3 = (__pyx_v_qual == Py_None); + __pyx_t_4 = (__pyx_t_3 != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_5 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1498, __pyx_L1_error) + __pyx_t_4 = ((__pyx_t_5 == 0) != 0); + __pyx_t_2 = __pyx_t_4; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":1500 + * if qual is None or len(qual) == 0: + * # if absent and there is a sequence: set to 0xff + * if src.core.l_qseq != 0: # <<<<<<<<<<<<<< + * p[0] = 0xff + * return + */ + __pyx_t_2 = ((__pyx_v_src->core.l_qseq != 0) != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":1501 + * # if absent and there is a sequence: set to 0xff + * if src.core.l_qseq != 0: + * p[0] = 0xff # <<<<<<<<<<<<<< + * return + * + */ + (__pyx_v_p[0]) = 0xff; + + /* "pysam/libcalignedsegment.pyx":1500 + * if qual is None or len(qual) == 0: + * # if absent and there is a sequence: set to 0xff + * if src.core.l_qseq != 0: # <<<<<<<<<<<<<< + * p[0] = 0xff + * return + */ + } + + /* "pysam/libcalignedsegment.pyx":1502 + * if src.core.l_qseq != 0: + * p[0] = 0xff + * return # <<<<<<<<<<<<<< + * + * # check for length match + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":1498 + * src = self._delegate + * p = pysam_bam_get_qual(src) + * if qual is None or len(qual) == 0: # <<<<<<<<<<<<<< + * # if absent and there is a sequence: set to 0xff + * if src.core.l_qseq != 0: + */ + } + + /* "pysam/libcalignedsegment.pyx":1505 + * + * # check for length match + * l = len(qual) # <<<<<<<<<<<<<< + * if src.core.l_qseq != l: + * raise ValueError( + */ + __pyx_t_5 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1505, __pyx_L1_error) + __pyx_v_l = __pyx_t_5; + + /* "pysam/libcalignedsegment.pyx":1506 + * # check for length match + * l = len(qual) + * if src.core.l_qseq != l: # <<<<<<<<<<<<<< + * raise ValueError( + * "quality and sequence mismatch: %i != %i" % + */ + __pyx_t_2 = ((__pyx_v_src->core.l_qseq != __pyx_v_l) != 0); + if (unlikely(__pyx_t_2)) { + + /* "pysam/libcalignedsegment.pyx":1509 + * raise ValueError( + * "quality and sequence mismatch: %i != %i" % + * (l, src.core.l_qseq)) # <<<<<<<<<<<<<< + * + * # create a python array object filling it + */ + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_l); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1509, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyInt_From_int32_t(__pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1509, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1509, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7); + __pyx_t_6 = 0; + __pyx_t_7 = 0; + + /* "pysam/libcalignedsegment.pyx":1508 + * if src.core.l_qseq != l: + * raise ValueError( + * "quality and sequence mismatch: %i != %i" % # <<<<<<<<<<<<<< + * (l, src.core.l_qseq)) + * + */ + __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_quality_and_sequence_mismatch_i, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1508, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pysam/libcalignedsegment.pyx":1507 + * l = len(qual) + * if src.core.l_qseq != l: + * raise ValueError( # <<<<<<<<<<<<<< + * "quality and sequence mismatch: %i != %i" % + * (l, src.core.l_qseq)) + */ + __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_Raise(__pyx_t_8, 0, 0, 0); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __PYX_ERR(0, 1507, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":1506 + * # check for length match + * l = len(qual) + * if src.core.l_qseq != l: # <<<<<<<<<<<<<< + * raise ValueError( + * "quality and sequence mismatch: %i != %i" % + */ + } + + /* "pysam/libcalignedsegment.pyx":1516 + * # NB: should avoid this copying if qual is + * # already of the correct type. + * cdef c_array.array result = c_array.array('B', qual) # <<<<<<<<<<<<<< + * + * # copy data + */ + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1516, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_n_s_B); + __Pyx_GIVEREF(__pyx_n_s_B); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_n_s_B); + __Pyx_INCREF(__pyx_v_qual); + __Pyx_GIVEREF(__pyx_v_qual); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_qual); + __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1516, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_result = ((arrayobject *)__pyx_t_7); + __pyx_t_7 = 0; + + /* "pysam/libcalignedsegment.pyx":1519 + * + * # copy data + * memcpy(p, result.data.as_voidptr, l) # <<<<<<<<<<<<<< + * + * # save in cache + */ + (void)(memcpy(__pyx_v_p, __pyx_v_result->data.as_voidptr, __pyx_v_l)); + + /* "pysam/libcalignedsegment.pyx":1522 + * + * # save in cache + * self.cache_query_qualities = qual # <<<<<<<<<<<<<< + * + * property bin: + */ + __Pyx_INCREF(__pyx_v_qual); + __Pyx_GIVEREF(__pyx_v_qual); + __Pyx_GOTREF(__pyx_v_self->cache_query_qualities); + __Pyx_DECREF(__pyx_v_self->cache_query_qualities); + __pyx_v_self->cache_query_qualities = __pyx_v_qual; + + /* "pysam/libcalignedsegment.pyx":1488 + * return self.cache_query_qualities + * + * def __set__(self, qual): # <<<<<<<<<<<<<< * + * # note that memory is already allocated via setting the sequence */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_supplementary.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_qualities.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1253 - * - * ''' +/* "pysam/libcalignedsegment.pyx":1526 + * property bin: + * """properties bin""" * def __get__(self): # <<<<<<<<<<<<<< - * cdef bam1_t * src - * src = self._delegate + * return self._delegate.core.bin + * def __set__(self, bin): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13reference_end_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13reference_end_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3bin_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3bin_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_13reference_end___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3bin___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_13reference_end___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - bam1_t *__pyx_v_src; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3bin___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; + PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1253, 0, __PYX_ERR(0, 1253, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1526, 0, __PYX_ERR(0, 1526, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1255 + /* "pysam/libcalignedsegment.pyx":1527 + * """properties bin""" * def __get__(self): - * cdef bam1_t * src - * src = self._delegate # <<<<<<<<<<<<<< - * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: - * return None + * return self._delegate.core.bin # <<<<<<<<<<<<<< + * def __set__(self, bin): + * self._delegate.core.bin = bin */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_uint16_t(__pyx_v_self->_delegate->core.bin); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1527, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1256 - * cdef bam1_t * src - * src = self._delegate - * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return None - * return bam_endpos(src) + /* "pysam/libcalignedsegment.pyx":1526 + * property bin: + * """properties bin""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._delegate.core.bin + * def __set__(self, bin): */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1256, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1256, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyNumber_And(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1256, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1256, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (!__pyx_t_6) { - } else { - __pyx_t_2 = __pyx_t_6; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_6 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); - __pyx_t_2 = __pyx_t_6; - __pyx_L4_bool_binop_done:; - if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":1257 - * src = self._delegate - * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: - * return None # <<<<<<<<<<<<<< - * return bam_endpos(src) + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.bin.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1528 + * def __get__(self): + * return self._delegate.core.bin + * def __set__(self, bin): # <<<<<<<<<<<<<< + * self._delegate.core.bin = bin * */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1256 - * cdef bam1_t * src - * src = self._delegate - * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return None - * return bam_endpos(src) - */ - } +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3bin_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3bin_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3bin_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_bin)); - /* "pysam/libcalignedsegment.pyx":1258 - * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: - * return None - * return bam_endpos(src) # <<<<<<<<<<<<<< + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3bin_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_bin) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1528, 0, __PYX_ERR(0, 1528, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1529 + * return self._delegate.core.bin + * def __set__(self, bin): + * self._delegate.core.bin = bin # <<<<<<<<<<<<<< + * * - * property reference_length: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_PyInt_From_int32_t(bam_endpos(__pyx_v_src)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_bin); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1529, __pyx_L1_error) + __pyx_v_self->_delegate->core.bin = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":1253 + /* "pysam/libcalignedsegment.pyx":1528 + * def __get__(self): + * return self._delegate.core.bin + * def __set__(self, bin): # <<<<<<<<<<<<<< + * self._delegate.core.bin = bin * - * ''' - * def __get__(self): # <<<<<<<<<<<<<< - * cdef bam1_t * src - * src = self._delegate */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_end.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.bin.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1264 - * - * This is equal to `aend - pos`. Returns None if not available.''' +/* "pysam/libcalignedsegment.pyx":1540 + * property is_paired: + * """true if read is paired in sequencing""" * def __get__(self): # <<<<<<<<<<<<<< - * cdef bam1_t * src - * src = self._delegate + * return (self.flag & BAM_FPAIRED) != 0 + * def __set__(self,val): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16reference_length_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16reference_length_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16reference_length___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16reference_length___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - bam1_t *__pyx_v_src; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; - int __pyx_t_2; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1264, 0, __PYX_ERR(0, 1264, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1540, 0, __PYX_ERR(0, 1540, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1266 + /* "pysam/libcalignedsegment.pyx":1541 + * """true if read is paired in sequencing""" * def __get__(self): - * cdef bam1_t * src - * src = self._delegate # <<<<<<<<<<<<<< - * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: - * return None - */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; - - /* "pysam/libcalignedsegment.pyx":1267 - * cdef bam1_t * src - * src = self._delegate - * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return None - * return bam_endpos(src) - \ + * return (self.flag & BAM_FPAIRED) != 0 # <<<<<<<<<<<<<< + * def __set__(self,val): + * pysam_update_flag(self._delegate, val, BAM_FPAIRED) */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1267, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1541, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FPAIRED); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1541, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1541, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1267, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyNumber_And(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1267, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1541, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1267, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (!__pyx_t_6) { - } else { - __pyx_t_2 = __pyx_t_6; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_6 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); - __pyx_t_2 = __pyx_t_6; - __pyx_L4_bool_binop_done:; - if (__pyx_t_2) { - - /* "pysam/libcalignedsegment.pyx":1268 - * src = self._delegate - * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: - * return None # <<<<<<<<<<<<<< - * return bam_endpos(src) - \ - * self._delegate.core.pos - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":1267 - * cdef bam1_t * src - * src = self._delegate - * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return None - * return bam_endpos(src) - \ - */ - } - - /* "pysam/libcalignedsegment.pyx":1269 - * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: - * return None - * return bam_endpos(src) - \ # <<<<<<<<<<<<<< - * self._delegate.core.pos - * - */ - __Pyx_XDECREF(__pyx_r); - - /* "pysam/libcalignedsegment.pyx":1270 - * return None - * return bam_endpos(src) - \ - * self._delegate.core.pos # <<<<<<<<<<<<<< - * - * property query_alignment_sequence: - */ - __pyx_t_5 = __Pyx_PyInt_From_int32_t((bam_endpos(__pyx_v_src) - __pyx_v_self->_delegate->core.pos)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1269, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1264 - * - * This is equal to `aend - pos`. Returns None if not available.''' + /* "pysam/libcalignedsegment.pyx":1540 + * property is_paired: + * """true if read is paired in sequencing""" * def __get__(self): # <<<<<<<<<<<<<< - * cdef bam1_t * src - * src = self._delegate + * return (self.flag & BAM_FPAIRED) != 0 + * def __set__(self,val): */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_paired.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -16067,184 +19482,132 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16referen return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1289 - * """ +/* "pysam/libcalignedsegment.pyx":1542 + * def __get__(self): + * return (self.flag & BAM_FPAIRED) != 0 + * def __set__(self,val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FPAIRED) * - * def __get__(self): # <<<<<<<<<<<<<< - * if self.cache_query_alignment_sequence: - * return self.cache_query_alignment_sequence */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_24query_alignment_sequence_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_24query_alignment_sequence_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_24query_alignment_sequence___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_24query_alignment_sequence___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - bam1_t *__pyx_v_src; - uint32_t __pyx_v_start; - uint32_t __pyx_v_end; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - bam1_t *__pyx_t_2; - int32_t __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1289, 0, __PYX_ERR(0, 1289, __pyx_L1_error)); + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1542, 0, __PYX_ERR(0, 1542, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1290 + /* "pysam/libcalignedsegment.pyx":1543 + * return (self.flag & BAM_FPAIRED) != 0 + * def __set__(self,val): + * pysam_update_flag(self._delegate, val, BAM_FPAIRED) # <<<<<<<<<<<<<< * + * property is_proper_pair: + */ + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1543, __pyx_L1_error) + pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FPAIRED); + + /* "pysam/libcalignedsegment.pyx":1542 * def __get__(self): - * if self.cache_query_alignment_sequence: # <<<<<<<<<<<<<< - * return self.cache_query_alignment_sequence + * return (self.flag & BAM_FPAIRED) != 0 + * def __set__(self,val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FPAIRED) * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->cache_query_alignment_sequence); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1290, __pyx_L1_error) - if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1291 - * def __get__(self): - * if self.cache_query_alignment_sequence: - * return self.cache_query_alignment_sequence # <<<<<<<<<<<<<< - * - * cdef bam1_t * src - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->cache_query_alignment_sequence); - __pyx_r = __pyx_v_self->cache_query_alignment_sequence; - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":1290 - * - * def __get__(self): - * if self.cache_query_alignment_sequence: # <<<<<<<<<<<<<< - * return self.cache_query_alignment_sequence - * - */ - } - - /* "pysam/libcalignedsegment.pyx":1296 - * cdef uint32_t start, end - * - * src = self._delegate # <<<<<<<<<<<<<< - * - * if src.core.l_qseq == 0: - */ - __pyx_t_2 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_2; - - /* "pysam/libcalignedsegment.pyx":1298 - * src = self._delegate - * - * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< - * return None - * - */ - __pyx_t_1 = ((__pyx_v_src->core.l_qseq == 0) != 0); - if (__pyx_t_1) { - - /* "pysam/libcalignedsegment.pyx":1299 - * - * if src.core.l_qseq == 0: - * return None # <<<<<<<<<<<<<< - * - * start = getQueryStart(src) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":1298 - * src = self._delegate - * - * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< - * return None - * - */ - } + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_paired.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1301 - * return None - * - * start = getQueryStart(src) # <<<<<<<<<<<<<< - * end = getQueryEnd(src) - * +/* "pysam/libcalignedsegment.pyx":1547 + * property is_proper_pair: + * """true if read is mapped in a proper pair""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FPROPER_PAIR) != 0 + * def __set__(self,val): */ - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_3 == ((int32_t)-1))) __PYX_ERR(0, 1301, __pyx_L1_error) - __pyx_v_start = __pyx_t_3; - /* "pysam/libcalignedsegment.pyx":1302 - * - * start = getQueryStart(src) - * end = getQueryEnd(src) # <<<<<<<<<<<<<< - * - * self.cache_query_alignment_sequence = force_str( - */ - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_3 == ((int32_t)-1))) __PYX_ERR(0, 1302, __pyx_L1_error) - __pyx_v_end = __pyx_t_3; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - /* "pysam/libcalignedsegment.pyx":1305 - * - * self.cache_query_alignment_sequence = force_str( - * getSequenceInRange(src, start, end)) # <<<<<<<<<<<<<< - * return self.cache_query_alignment_sequence - * - */ - __pyx_t_4 = __pyx_f_5pysam_18libcalignedsegment_getSequenceInRange(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1305, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1304 - * end = getQueryEnd(src) - * - * self.cache_query_alignment_sequence = force_str( # <<<<<<<<<<<<<< - * getSequenceInRange(src, start, end)) - * return self.cache_query_alignment_sequence - */ - __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1304, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GIVEREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_sequence); - __Pyx_DECREF(__pyx_v_self->cache_query_alignment_sequence); - __pyx_v_self->cache_query_alignment_sequence = __pyx_t_5; - __pyx_t_5 = 0; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1547, 0, __PYX_ERR(0, 1547, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1306 - * self.cache_query_alignment_sequence = force_str( - * getSequenceInRange(src, start, end)) - * return self.cache_query_alignment_sequence # <<<<<<<<<<<<<< - * - * property query_alignment_qualities: + /* "pysam/libcalignedsegment.pyx":1548 + * """true if read is mapped in a proper pair""" + * def __get__(self): + * return (self.flag & BAM_FPROPER_PAIR) != 0 # <<<<<<<<<<<<<< + * def __set__(self,val): + * pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR) */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->cache_query_alignment_sequence); - __pyx_r = __pyx_v_self->cache_query_alignment_sequence; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1548, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FPROPER_PAIR); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1548, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1548, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1548, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1289 - * """ - * + /* "pysam/libcalignedsegment.pyx":1547 + * property is_proper_pair: + * """true if read is mapped in a proper pair""" * def __get__(self): # <<<<<<<<<<<<<< - * if self.cache_query_alignment_sequence: - * return self.cache_query_alignment_sequence + * return (self.flag & BAM_FPROPER_PAIR) != 0 + * def __set__(self,val): */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_alignment_sequence.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_proper_pair.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -16253,244 +19616,132 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_24query_a return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1322 - * - * """ - * def __get__(self): # <<<<<<<<<<<<<< - * - * if self.cache_query_alignment_qualities: +/* "pysam/libcalignedsegment.pyx":1549 + * def __get__(self): + * return (self.flag & BAM_FPROPER_PAIR) != 0 + * def __set__(self,val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR) + * property is_unmapped: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_25query_alignment_qualities_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_25query_alignment_qualities_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_25query_alignment_qualities___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_25query_alignment_qualities___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - bam1_t *__pyx_v_src; - uint32_t __pyx_v_start; - uint32_t __pyx_v_end; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - bam1_t *__pyx_t_2; - int32_t __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1322, 0, __PYX_ERR(0, 1322, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":1324 - * def __get__(self): - * - * if self.cache_query_alignment_qualities: # <<<<<<<<<<<<<< - * return self.cache_query_alignment_qualities - * - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->cache_query_alignment_qualities); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1324, __pyx_L1_error) - if (__pyx_t_1) { + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1549, 0, __PYX_ERR(0, 1549, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1325 - * - * if self.cache_query_alignment_qualities: - * return self.cache_query_alignment_qualities # <<<<<<<<<<<<<< - * - * cdef bam1_t * src + /* "pysam/libcalignedsegment.pyx":1550 + * return (self.flag & BAM_FPROPER_PAIR) != 0 + * def __set__(self,val): + * pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR) # <<<<<<<<<<<<<< + * property is_unmapped: + * """true if read itself is unmapped""" */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->cache_query_alignment_qualities); - __pyx_r = __pyx_v_self->cache_query_alignment_qualities; - goto __pyx_L0; + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1550, __pyx_L1_error) + pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FPROPER_PAIR); - /* "pysam/libcalignedsegment.pyx":1324 + /* "pysam/libcalignedsegment.pyx":1549 * def __get__(self): - * - * if self.cache_query_alignment_qualities: # <<<<<<<<<<<<<< - * return self.cache_query_alignment_qualities - * - */ - } - - /* "pysam/libcalignedsegment.pyx":1330 - * cdef uint32_t start, end - * - * src = self._delegate # <<<<<<<<<<<<<< - * - * if src.core.l_qseq == 0: - */ - __pyx_t_2 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_2; - - /* "pysam/libcalignedsegment.pyx":1332 - * src = self._delegate - * - * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< - * return None - * - */ - __pyx_t_1 = ((__pyx_v_src->core.l_qseq == 0) != 0); - if (__pyx_t_1) { - - /* "pysam/libcalignedsegment.pyx":1333 - * - * if src.core.l_qseq == 0: - * return None # <<<<<<<<<<<<<< - * - * start = getQueryStart(src) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":1332 - * src = self._delegate - * - * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< - * return None - * - */ - } - - /* "pysam/libcalignedsegment.pyx":1335 - * return None - * - * start = getQueryStart(src) # <<<<<<<<<<<<<< - * end = getQueryEnd(src) - * self.cache_query_alignment_qualities = \ - */ - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_3 == ((int32_t)-1))) __PYX_ERR(0, 1335, __pyx_L1_error) - __pyx_v_start = __pyx_t_3; - - /* "pysam/libcalignedsegment.pyx":1336 - * - * start = getQueryStart(src) - * end = getQueryEnd(src) # <<<<<<<<<<<<<< - * self.cache_query_alignment_qualities = \ - * getQualitiesInRange(src, start, end) - */ - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_3 == ((int32_t)-1))) __PYX_ERR(0, 1336, __pyx_L1_error) - __pyx_v_end = __pyx_t_3; - - /* "pysam/libcalignedsegment.pyx":1338 - * end = getQueryEnd(src) - * self.cache_query_alignment_qualities = \ - * getQualitiesInRange(src, start, end) # <<<<<<<<<<<<<< - * return self.cache_query_alignment_qualities - * - */ - __pyx_t_4 = __pyx_f_5pysam_18libcalignedsegment_getQualitiesInRange(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1338, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pysam/libcalignedsegment.pyx":1337 - * start = getQueryStart(src) - * end = getQueryEnd(src) - * self.cache_query_alignment_qualities = \ # <<<<<<<<<<<<<< - * getQualitiesInRange(src, start, end) - * return self.cache_query_alignment_qualities - */ - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_qualities); - __Pyx_DECREF(__pyx_v_self->cache_query_alignment_qualities); - __pyx_v_self->cache_query_alignment_qualities = __pyx_t_4; - __pyx_t_4 = 0; - - /* "pysam/libcalignedsegment.pyx":1339 - * self.cache_query_alignment_qualities = \ - * getQualitiesInRange(src, start, end) - * return self.cache_query_alignment_qualities # <<<<<<<<<<<<<< - * - * property query_alignment_start: - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->cache_query_alignment_qualities); - __pyx_r = __pyx_v_self->cache_query_alignment_qualities; - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":1322 - * - * """ - * def __get__(self): # <<<<<<<<<<<<<< - * - * if self.cache_query_alignment_qualities: + * return (self.flag & BAM_FPROPER_PAIR) != 0 + * def __set__(self,val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR) + * property is_unmapped: */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_alignment_qualities.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_proper_pair.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1349 - * - * """ +/* "pysam/libcalignedsegment.pyx":1553 + * property is_unmapped: + * """true if read itself is unmapped""" * def __get__(self): # <<<<<<<<<<<<<< - * return getQueryStart(self._delegate) - * + * return (self.flag & BAM_FUNMAP) != 0 + * def __set__(self, val): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21query_alignment_start_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21query_alignment_start_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_21query_alignment_start___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_21query_alignment_start___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int32_t __pyx_t_1; + PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1349, 0, __PYX_ERR(0, 1349, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1553, 0, __PYX_ERR(0, 1553, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1350 - * """ + /* "pysam/libcalignedsegment.pyx":1554 + * """true if read itself is unmapped""" * def __get__(self): - * return getQueryStart(self._delegate) # <<<<<<<<<<<<<< - * - * property query_alignment_end: + * return (self.flag & BAM_FUNMAP) != 0 # <<<<<<<<<<<<<< + * def __set__(self, val): + * pysam_update_flag(self._delegate, val, BAM_FUNMAP) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_getQueryStart(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == ((int32_t)-1))) __PYX_ERR(0, 1350, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1350, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1554, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1554, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1554, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1554, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1349 - * - * """ + /* "pysam/libcalignedsegment.pyx":1553 + * property is_unmapped: + * """true if read itself is unmapped""" * def __get__(self): # <<<<<<<<<<<<<< - * return getQueryStart(self._delegate) - * + * return (self.flag & BAM_FUNMAP) != 0 + * def __set__(self, val): */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_alignment_start.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -16499,142 +19750,141 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_21query_a return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1355 - * """end index of the aligned query portion of the sequence (0-based, - * exclusive)""" - * def __get__(self): # <<<<<<<<<<<<<< - * return getQueryEnd(self._delegate) - * +/* "pysam/libcalignedsegment.pyx":1555 + * def __get__(self): + * return (self.flag & BAM_FUNMAP) != 0 + * def __set__(self, val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FUNMAP) + * # setting the unmapped flag requires recalculation of */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19query_alignment_end_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19query_alignment_end_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19query_alignment_end___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19query_alignment_end___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int32_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1355, 0, __PYX_ERR(0, 1355, __pyx_L1_error)); + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1555, 0, __PYX_ERR(0, 1555, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1356 - * exclusive)""" - * def __get__(self): - * return getQueryEnd(self._delegate) # <<<<<<<<<<<<<< - * - * property query_alignment_length: + /* "pysam/libcalignedsegment.pyx":1556 + * return (self.flag & BAM_FUNMAP) != 0 + * def __set__(self, val): + * pysam_update_flag(self._delegate, val, BAM_FUNMAP) # <<<<<<<<<<<<<< + * # setting the unmapped flag requires recalculation of + * # bin as alignment length is now implicitely 1 */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == ((int32_t)-1))) __PYX_ERR(0, 1356, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1356, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1556, __pyx_L1_error) + pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FUNMAP); - /* "pysam/libcalignedsegment.pyx":1355 - * """end index of the aligned query portion of the sequence (0-based, - * exclusive)""" - * def __get__(self): # <<<<<<<<<<<<<< - * return getQueryEnd(self._delegate) + /* "pysam/libcalignedsegment.pyx":1559 + * # setting the unmapped flag requires recalculation of + * # bin as alignment length is now implicitely 1 + * update_bin(self._delegate) # <<<<<<<<<<<<<< * + * property mate_is_unmapped: + */ + __pyx_f_5pysam_18libcalignedsegment_update_bin(__pyx_v_self->_delegate); + + /* "pysam/libcalignedsegment.pyx":1555 + * def __get__(self): + * return (self.flag & BAM_FUNMAP) != 0 + * def __set__(self, val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FUNMAP) + * # setting the unmapped flag requires recalculation of */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_alignment_end.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_unmapped.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1362 - * - * This is equal to :attr:`qend` - :attr:`qstart`""" +/* "pysam/libcalignedsegment.pyx":1563 + * property mate_is_unmapped: + * """true if the mate is unmapped""" * def __get__(self): # <<<<<<<<<<<<<< - * cdef bam1_t * src - * src = self._delegate + * return (self.flag & BAM_FMUNMAP) != 0 + * def __set__(self,val): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_22query_alignment_length_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_22query_alignment_length_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_22query_alignment_length___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_22query_alignment_length___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - bam1_t *__pyx_v_src; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; - int32_t __pyx_t_2; - int32_t __pyx_t_3; - PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1362, 0, __PYX_ERR(0, 1362, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1563, 0, __PYX_ERR(0, 1563, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1364 + /* "pysam/libcalignedsegment.pyx":1564 + * """true if the mate is unmapped""" * def __get__(self): - * cdef bam1_t * src - * src = self._delegate # <<<<<<<<<<<<<< - * return getQueryEnd(src) - getQueryStart(src) - * - */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; - - /* "pysam/libcalignedsegment.pyx":1365 - * cdef bam1_t * src - * src = self._delegate - * return getQueryEnd(src) - getQueryStart(src) # <<<<<<<<<<<<<< - * - * ##################################################### + * return (self.flag & BAM_FMUNMAP) != 0 # <<<<<<<<<<<<<< + * def __set__(self,val): + * pysam_update_flag(self._delegate, val, BAM_FMUNMAP) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_2 == ((int32_t)-1))) __PYX_ERR(0, 1365, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_3 == ((int32_t)-1))) __PYX_ERR(0, 1365, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyInt_From_int32_t((__pyx_t_2 - __pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1365, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1564, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FMUNMAP); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1564, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1564, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1564, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1362 - * - * This is equal to :attr:`qend` - :attr:`qstart`""" + /* "pysam/libcalignedsegment.pyx":1563 + * property mate_is_unmapped: + * """true if the mate is unmapped""" * def __get__(self): # <<<<<<<<<<<<<< - * cdef bam1_t * src - * src = self._delegate + * return (self.flag & BAM_FMUNMAP) != 0 + * def __set__(self,val): */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_alignment_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mate_is_unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -16643,2352 +19893,2001 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_22query_a return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1370 - * # Computed properties - * - * def get_reference_positions(self, full_length=False): # <<<<<<<<<<<<<< - * """a list of reference positions that this read aligns to. - * - */ +/* "pysam/libcalignedsegment.pyx":1565 + * def __get__(self): + * return (self.flag & BAM_FMUNMAP) != 0 + * def __set__(self,val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FMUNMAP) + * property is_reverse: + */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19get_reference_positions(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_18get_reference_positions[] = "AlignedSegment.get_reference_positions(self, full_length=False)\na list of reference positions that this read aligns to.\n\n By default, this method only returns positions in the\n reference that are within the alignment. If *full_length* is\n set, None values will be included for any soft-clipped or\n unaligned positions within the read. The returned list will\n thus be of the same length as the read.\n\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19get_reference_positions(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_full_length = 0; - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_reference_positions (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_full_length,0}; - PyObject* values[1] = {0}; - values[0] = ((PyObject *)Py_False); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_full_length); - if (value) { values[0] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_reference_positions") < 0)) __PYX_ERR(0, 1370, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_full_length = values[0]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_reference_positions", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1370, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_reference_positions", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_18get_reference_positions(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_full_length); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_18get_reference_positions(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_full_length) { - uint32_t __pyx_v_k; - uint32_t __pyx_v_i; - uint32_t __pyx_v_pos; - int __pyx_v_op; - uint32_t *__pyx_v_cigar_p; - bam1_t *__pyx_v_src; - int __pyx_v__full; - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_l = NULL; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - bam1_t *__pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int32_t __pyx_t_4; - uint16_t __pyx_t_5; - int __pyx_t_6; - uint32_t __pyx_t_7; - int __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - __Pyx_RefNannySetupContext("get_reference_positions", 0); - __Pyx_TraceCall("get_reference_positions", __pyx_f[0], 1370, 0, __PYX_ERR(0, 1370, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":1384 - * cdef uint32_t * cigar_p - * cdef bam1_t * src - * cdef bint _full = full_length # <<<<<<<<<<<<<< - * - * src = self._delegate - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_full_length); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1384, __pyx_L1_error) - __pyx_v__full = __pyx_t_1; - - /* "pysam/libcalignedsegment.pyx":1386 - * cdef bint _full = full_length - * - * src = self._delegate # <<<<<<<<<<<<<< - * if pysam_get_n_cigar(src) == 0: - * return [] - */ - __pyx_t_2 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_2; - - /* "pysam/libcalignedsegment.pyx":1387 - * - * src = self._delegate - * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return [] - * - */ - __pyx_t_1 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); - if (__pyx_t_1) { - - /* "pysam/libcalignedsegment.pyx":1388 - * src = self._delegate - * if pysam_get_n_cigar(src) == 0: - * return [] # <<<<<<<<<<<<<< - * - * result = [] - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1388, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1565, 0, __PYX_ERR(0, 1565, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1387 - * - * src = self._delegate - * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return [] - * + /* "pysam/libcalignedsegment.pyx":1566 + * return (self.flag & BAM_FMUNMAP) != 0 + * def __set__(self,val): + * pysam_update_flag(self._delegate, val, BAM_FMUNMAP) # <<<<<<<<<<<<<< + * property is_reverse: + * """true if read is mapped to reverse strand""" */ - } + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1566, __pyx_L1_error) + pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FMUNMAP); - /* "pysam/libcalignedsegment.pyx":1390 - * return [] - * - * result = [] # <<<<<<<<<<<<<< - * pos = src.core.pos - * cigar_p = pysam_bam_get_cigar(src) + /* "pysam/libcalignedsegment.pyx":1565 + * def __get__(self): + * return (self.flag & BAM_FMUNMAP) != 0 + * def __set__(self,val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FMUNMAP) + * property is_reverse: */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1390, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_result = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1391 - * - * result = [] - * pos = src.core.pos # <<<<<<<<<<<<<< - * cigar_p = pysam_bam_get_cigar(src) - * - */ - __pyx_t_4 = __pyx_v_src->core.pos; - __pyx_v_pos = __pyx_t_4; + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mate_is_unmapped.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1392 - * result = [] - * pos = src.core.pos - * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< - * - * for k from 0 <= k < pysam_get_n_cigar(src): +/* "pysam/libcalignedsegment.pyx":1569 + * property is_reverse: + * """true if read is mapped to reverse strand""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FREVERSE) != 0 + * def __set__(self,val): */ - __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":1394 - * cigar_p = pysam_bam_get_cigar(src) - * - * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - */ - __pyx_t_5 = pysam_get_n_cigar(__pyx_v_src); - for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) { +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - /* "pysam/libcalignedsegment.pyx":1395 - * - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * - */ - __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1396 - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< - * - * if op == BAM_CSOFT_CLIP or op == BAM_CINS: - */ - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1396, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_3); - __pyx_t_3 = 0; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1569, 0, __PYX_ERR(0, 1569, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1398 - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * - * if op == BAM_CSOFT_CLIP or op == BAM_CINS: # <<<<<<<<<<<<<< - * if _full: - * for i from 0 <= i < l: + /* "pysam/libcalignedsegment.pyx":1570 + * """true if read is mapped to reverse strand""" + * def __get__(self): + * return (self.flag & BAM_FREVERSE) != 0 # <<<<<<<<<<<<<< + * def __set__(self,val): + * pysam_update_flag(self._delegate, val, BAM_FREVERSE) */ - __pyx_t_6 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_1 = __pyx_t_6; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_op == BAM_CINS) != 0); - __pyx_t_1 = __pyx_t_6; - __pyx_L7_bool_binop_done:; - if (__pyx_t_1) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1570, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREVERSE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1570, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1570, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1570, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1399 - * - * if op == BAM_CSOFT_CLIP or op == BAM_CINS: - * if _full: # <<<<<<<<<<<<<< - * for i from 0 <= i < l: - * result.append(None) + /* "pysam/libcalignedsegment.pyx":1569 + * property is_reverse: + * """true if read is mapped to reverse strand""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FREVERSE) != 0 + * def __set__(self,val): */ - __pyx_t_1 = (__pyx_v__full != 0); - if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1400 - * if op == BAM_CSOFT_CLIP or op == BAM_CINS: - * if _full: - * for i from 0 <= i < l: # <<<<<<<<<<<<<< - * result.append(None) - * elif op == BAM_CMATCH: - */ - __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_l); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1400, __pyx_L1_error) - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_7; __pyx_v_i++) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_reverse.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1401 - * if _full: - * for i from 0 <= i < l: - * result.append(None) # <<<<<<<<<<<<<< - * elif op == BAM_CMATCH: - * for i from pos <= i < pos + l: +/* "pysam/libcalignedsegment.pyx":1571 + * def __get__(self): + * return (self.flag & BAM_FREVERSE) != 0 + * def __set__(self,val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FREVERSE) + * property mate_is_reverse: */ - __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, Py_None); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1401, __pyx_L1_error) - } - /* "pysam/libcalignedsegment.pyx":1399 - * - * if op == BAM_CSOFT_CLIP or op == BAM_CINS: - * if _full: # <<<<<<<<<<<<<< - * for i from 0 <= i < l: - * result.append(None) - */ - } +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); - /* "pysam/libcalignedsegment.pyx":1398 - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * - * if op == BAM_CSOFT_CLIP or op == BAM_CINS: # <<<<<<<<<<<<<< - * if _full: - * for i from 0 <= i < l: - */ - goto __pyx_L6; - } + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1402 - * for i from 0 <= i < l: - * result.append(None) - * elif op == BAM_CMATCH: # <<<<<<<<<<<<<< - * for i from pos <= i < pos + l: - * result.append(i) - */ - __pyx_t_1 = ((__pyx_v_op == BAM_CMATCH) != 0); - if (__pyx_t_1) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1571, 0, __PYX_ERR(0, 1571, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1403 - * result.append(None) - * elif op == BAM_CMATCH: - * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< - * result.append(i) - * pos += l + /* "pysam/libcalignedsegment.pyx":1572 + * return (self.flag & BAM_FREVERSE) != 0 + * def __set__(self,val): + * pysam_update_flag(self._delegate, val, BAM_FREVERSE) # <<<<<<<<<<<<<< + * property mate_is_reverse: + * """true is read is mapped to reverse strand""" */ - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1403, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1403, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_9); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1403, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_7; __pyx_v_i++) { + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1572, __pyx_L1_error) + pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREVERSE); - /* "pysam/libcalignedsegment.pyx":1404 - * elif op == BAM_CMATCH: - * for i from pos <= i < pos + l: - * result.append(i) # <<<<<<<<<<<<<< - * pos += l - * elif op == BAM_CDEL or op == BAM_CREF_SKIP: + /* "pysam/libcalignedsegment.pyx":1571 + * def __get__(self): + * return (self.flag & BAM_FREVERSE) != 0 + * def __set__(self,val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FREVERSE) + * property mate_is_reverse: */ - __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1404, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - /* "pysam/libcalignedsegment.pyx":1405 - * for i from pos <= i < pos + l: - * result.append(i) - * pos += l # <<<<<<<<<<<<<< - * elif op == BAM_CDEL or op == BAM_CREF_SKIP: - * pos += l - */ - __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1405, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_pos = __pyx_t_7; + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_reverse.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1402 - * for i from 0 <= i < l: - * result.append(None) - * elif op == BAM_CMATCH: # <<<<<<<<<<<<<< - * for i from pos <= i < pos + l: - * result.append(i) +/* "pysam/libcalignedsegment.pyx":1575 + * property mate_is_reverse: + * """true is read is mapped to reverse strand""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FMREVERSE) != 0 + * def __set__(self,val): */ - goto __pyx_L6; - } - /* "pysam/libcalignedsegment.pyx":1406 - * result.append(i) - * pos += l - * elif op == BAM_CDEL or op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< - * pos += l - * - */ - __pyx_t_6 = ((__pyx_v_op == BAM_CDEL) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_1 = __pyx_t_6; - goto __pyx_L14_bool_binop_done; - } - __pyx_t_6 = ((__pyx_v_op == BAM_CREF_SKIP) != 0); - __pyx_t_1 = __pyx_t_6; - __pyx_L14_bool_binop_done:; - if (__pyx_t_1) { +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - /* "pysam/libcalignedsegment.pyx":1407 - * pos += l - * elif op == BAM_CDEL or op == BAM_CREF_SKIP: - * pos += l # <<<<<<<<<<<<<< - * - * return result - */ - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_9); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1407, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_pos = __pyx_t_7; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1406 - * result.append(i) - * pos += l - * elif op == BAM_CDEL or op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< - * pos += l - * - */ - } - __pyx_L6:; - } +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1575, 0, __PYX_ERR(0, 1575, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1409 - * pos += l - * - * return result # <<<<<<<<<<<<<< - * - * def infer_query_length(self, always=True): + /* "pysam/libcalignedsegment.pyx":1576 + * """true is read is mapped to reverse strand""" + * def __get__(self): + * return (self.flag & BAM_FMREVERSE) != 0 # <<<<<<<<<<<<<< + * def __set__(self,val): + * pysam_update_flag(self._delegate, val, BAM_FMREVERSE) */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result); - __pyx_r = __pyx_v_result; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1576, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FMREVERSE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1576, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1576, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1576, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1370 - * # Computed properties - * - * def get_reference_positions(self, full_length=False): # <<<<<<<<<<<<<< - * """a list of reference positions that this read aligns to. - * + /* "pysam/libcalignedsegment.pyx":1575 + * property mate_is_reverse: + * """true is read is mapped to reverse strand""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FMREVERSE) != 0 + * def __set__(self,val): */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_reference_positions", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mate_is_reverse.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_l); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1411 - * return result - * - * def infer_query_length(self, always=True): # <<<<<<<<<<<<<< - * """inferred read length from CIGAR string. - * +/* "pysam/libcalignedsegment.pyx":1577 + * def __get__(self): + * return (self.flag & BAM_FMREVERSE) != 0 + * def __set__(self,val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FMREVERSE) + * property is_read1: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21infer_query_length(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_20infer_query_length[] = "AlignedSegment.infer_query_length(self, always=True)\ninferred read length from CIGAR string.\n\n If *always* is set to True, the read length\n will be always inferred. If set to False, the length\n of the read sequence will be returned if it is\n available.\n\n Returns None if CIGAR string is not present.\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21infer_query_length(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_always = 0; - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("infer_query_length (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_always,0}; - PyObject* values[1] = {0}; - values[0] = ((PyObject *)Py_True); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_always); - if (value) { values[0] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "infer_query_length") < 0)) __PYX_ERR(0, 1411, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_always = values[0]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("infer_query_length", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1411, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.infer_query_length", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20infer_query_length(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_always); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_20infer_query_length(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_always) { - bam1_t *__pyx_v_src; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("infer_query_length", 0); - __Pyx_TraceCall("infer_query_length", __pyx_f[0], 1411, 0, __PYX_ERR(0, 1411, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":1425 - * cdef bam1_t * src - * - * src = self._delegate # <<<<<<<<<<<<<< - * - * if not always and src.core.l_qseq: - */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; - - /* "pysam/libcalignedsegment.pyx":1427 - * src = self._delegate - * - * if not always and src.core.l_qseq: # <<<<<<<<<<<<<< - * return src.core.l_qseq - * - */ - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_always); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1427, __pyx_L1_error) - __pyx_t_4 = ((!__pyx_t_3) != 0); - if (__pyx_t_4) { - } else { - __pyx_t_2 = __pyx_t_4; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_4 = (__pyx_v_src->core.l_qseq != 0); - __pyx_t_2 = __pyx_t_4; - __pyx_L4_bool_binop_done:; - if (__pyx_t_2) { - - /* "pysam/libcalignedsegment.pyx":1428 - * - * if not always and src.core.l_qseq: - * return src.core.l_qseq # <<<<<<<<<<<<<< - * - * return calculateQueryLength(src) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1428, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":1427 - * src = self._delegate - * - * if not always and src.core.l_qseq: # <<<<<<<<<<<<<< - * return src.core.l_qseq - * - */ - } + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1577, 0, __PYX_ERR(0, 1577, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1430 - * return src.core.l_qseq - * - * return calculateQueryLength(src) # <<<<<<<<<<<<<< - * - * def get_reference_sequence(self): + /* "pysam/libcalignedsegment.pyx":1578 + * return (self.flag & BAM_FMREVERSE) != 0 + * def __set__(self,val): + * pysam_update_flag(self._delegate, val, BAM_FMREVERSE) # <<<<<<<<<<<<<< + * property is_read1: + * """true if this is read1""" */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_f_5pysam_18libcalignedsegment_calculateQueryLength(__pyx_v_src)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1430, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1578, __pyx_L1_error) + pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FMREVERSE); - /* "pysam/libcalignedsegment.pyx":1411 - * return result - * - * def infer_query_length(self, always=True): # <<<<<<<<<<<<<< - * """inferred read length from CIGAR string. - * + /* "pysam/libcalignedsegment.pyx":1577 + * def __get__(self): + * return (self.flag & BAM_FMREVERSE) != 0 + * def __set__(self,val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FMREVERSE) + * property is_read1: */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.infer_query_length", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mate_is_reverse.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1432 - * return calculateQueryLength(src) - * - * def get_reference_sequence(self): # <<<<<<<<<<<<<< - * """return the reference sequence. - * +/* "pysam/libcalignedsegment.pyx":1581 + * property is_read1: + * """true if this is read1""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FREAD1) != 0 + * def __set__(self,val): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_23get_reference_sequence(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_22get_reference_sequence[] = "AlignedSegment.get_reference_sequence(self)\nreturn the reference sequence.\n\n This method requires the MD tag to be set.\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_23get_reference_sequence(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_reference_sequence (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_22get_reference_sequence(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_22get_reference_sequence(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - uint32_t __pyx_v_k; - CYTHON_UNUSED uint32_t __pyx_v_i; - int __pyx_v_op; - bam1_t *__pyx_v_src; - PyObject *__pyx_v_ref_seq = NULL; - uint32_t *__pyx_v_cigar_p; - uint32_t __pyx_v_r_idx; - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_l = NULL; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; + PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_t_5; - uint16_t __pyx_t_6; - uint32_t __pyx_t_7; - int __pyx_t_8; - __Pyx_RefNannySetupContext("get_reference_sequence", 0); - __Pyx_TraceCall("get_reference_sequence", __pyx_f[0], 1432, 0, __PYX_ERR(0, 1432, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":1439 - * cdef uint32_t k, i - * cdef int op - * cdef bam1_t * src = self._delegate # <<<<<<<<<<<<<< - * ref_seq = force_str(build_alignment_sequence(src)) - * if ref_seq is None: - */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1581, 0, __PYX_ERR(0, 1581, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1440 - * cdef int op - * cdef bam1_t * src = self._delegate - * ref_seq = force_str(build_alignment_sequence(src)) # <<<<<<<<<<<<<< - * if ref_seq is None: - * raise ValueError("MD tag not present") + /* "pysam/libcalignedsegment.pyx":1582 + * """true if this is read1""" + * def __get__(self): + * return (self.flag & BAM_FREAD1) != 0 # <<<<<<<<<<<<<< + * def __set__(self,val): + * pysam_update_flag(self._delegate, val, BAM_FREAD1) */ - __pyx_t_2 = __pyx_f_5pysam_18libcalignedsegment_build_alignment_sequence(__pyx_v_src); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1440, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1582, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREAD1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1440, __pyx_L1_error) + __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_ref_seq = __pyx_t_3; - __pyx_t_3 = 0; - - /* "pysam/libcalignedsegment.pyx":1441 - * cdef bam1_t * src = self._delegate - * ref_seq = force_str(build_alignment_sequence(src)) - * if ref_seq is None: # <<<<<<<<<<<<<< - * raise ValueError("MD tag not present") - * - */ - __pyx_t_4 = (__pyx_v_ref_seq == Py_None); - __pyx_t_5 = (__pyx_t_4 != 0); - if (unlikely(__pyx_t_5)) { - - /* "pysam/libcalignedsegment.pyx":1442 - * ref_seq = force_str(build_alignment_sequence(src)) - * if ref_seq is None: - * raise ValueError("MD tag not present") # <<<<<<<<<<<<<< - * - * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1442, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":1441 - * cdef bam1_t * src = self._delegate - * ref_seq = force_str(build_alignment_sequence(src)) - * if ref_seq is None: # <<<<<<<<<<<<<< - * raise ValueError("MD tag not present") - * - */ - } - - /* "pysam/libcalignedsegment.pyx":1444 - * raise ValueError("MD tag not present") - * - * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< - * cdef uint32_t r_idx = 0 - * result = [] - */ - __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - - /* "pysam/libcalignedsegment.pyx":1445 - * - * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) - * cdef uint32_t r_idx = 0 # <<<<<<<<<<<<<< - * result = [] - * for k from 0 <= k < pysam_get_n_cigar(src): - */ - __pyx_v_r_idx = 0; - - /* "pysam/libcalignedsegment.pyx":1446 - * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) - * cdef uint32_t r_idx = 0 - * result = [] # <<<<<<<<<<<<<< - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK - */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1446, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_result = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pysam/libcalignedsegment.pyx":1447 - * cdef uint32_t r_idx = 0 - * result = [] - * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - */ - __pyx_t_6 = pysam_get_n_cigar(__pyx_v_src); - for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) { - - /* "pysam/libcalignedsegment.pyx":1448 - * result = [] - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: - */ - __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); - - /* "pysam/libcalignedsegment.pyx":1449 - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< - * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: - * for i from 0 <= i < l: - */ - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pysam/libcalignedsegment.pyx":1450 - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: # <<<<<<<<<<<<<< - * for i from 0 <= i < l: - * result.append(ref_seq[r_idx]) - */ - __pyx_t_4 = ((__pyx_v_op == BAM_CMATCH) != 0); - if (!__pyx_t_4) { - } else { - __pyx_t_5 = __pyx_t_4; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_4 = ((__pyx_v_op == BAM_CEQUAL) != 0); - if (!__pyx_t_4) { - } else { - __pyx_t_5 = __pyx_t_4; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_4 = ((__pyx_v_op == BAM_CDIFF) != 0); - __pyx_t_5 = __pyx_t_4; - __pyx_L7_bool_binop_done:; - if (__pyx_t_5) { - - /* "pysam/libcalignedsegment.pyx":1451 - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: - * for i from 0 <= i < l: # <<<<<<<<<<<<<< - * result.append(ref_seq[r_idx]) - * r_idx += 1 - */ - __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_l); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1451, __pyx_L1_error) - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_7; __pyx_v_i++) { - - /* "pysam/libcalignedsegment.pyx":1452 - * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: - * for i from 0 <= i < l: - * result.append(ref_seq[r_idx]) # <<<<<<<<<<<<<< - * r_idx += 1 - * elif op == BAM_CDEL: - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_ref_seq, __pyx_v_r_idx, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1452, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1452, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pysam/libcalignedsegment.pyx":1453 - * for i from 0 <= i < l: - * result.append(ref_seq[r_idx]) - * r_idx += 1 # <<<<<<<<<<<<<< - * elif op == BAM_CDEL: - * for i from 0 <= i < l: - */ - __pyx_v_r_idx = (__pyx_v_r_idx + 1); - } - - /* "pysam/libcalignedsegment.pyx":1450 - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: # <<<<<<<<<<<<<< - * for i from 0 <= i < l: - * result.append(ref_seq[r_idx]) - */ - goto __pyx_L6; - } - - /* "pysam/libcalignedsegment.pyx":1454 - * result.append(ref_seq[r_idx]) - * r_idx += 1 - * elif op == BAM_CDEL: # <<<<<<<<<<<<<< - * for i from 0 <= i < l: - * result.append(ref_seq[r_idx]) - */ - __pyx_t_5 = ((__pyx_v_op == BAM_CDEL) != 0); - if (__pyx_t_5) { + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1582, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1455 - * r_idx += 1 - * elif op == BAM_CDEL: - * for i from 0 <= i < l: # <<<<<<<<<<<<<< - * result.append(ref_seq[r_idx]) - * r_idx += 1 + /* "pysam/libcalignedsegment.pyx":1581 + * property is_read1: + * """true if this is read1""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FREAD1) != 0 + * def __set__(self,val): */ - __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_l); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1455, __pyx_L1_error) - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_7; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":1456 - * elif op == BAM_CDEL: - * for i from 0 <= i < l: - * result.append(ref_seq[r_idx]) # <<<<<<<<<<<<<< - * r_idx += 1 - * elif op == BAM_CREF_SKIP: - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_ref_seq, __pyx_v_r_idx, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1456, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1456, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_read1.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1457 - * for i from 0 <= i < l: - * result.append(ref_seq[r_idx]) - * r_idx += 1 # <<<<<<<<<<<<<< - * elif op == BAM_CREF_SKIP: - * pass +/* "pysam/libcalignedsegment.pyx":1583 + * def __get__(self): + * return (self.flag & BAM_FREAD1) != 0 + * def __set__(self,val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FREAD1) + * property is_read2: */ - __pyx_v_r_idx = (__pyx_v_r_idx + 1); - } - /* "pysam/libcalignedsegment.pyx":1454 - * result.append(ref_seq[r_idx]) - * r_idx += 1 - * elif op == BAM_CDEL: # <<<<<<<<<<<<<< - * for i from 0 <= i < l: - * result.append(ref_seq[r_idx]) - */ - goto __pyx_L6; - } +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); - /* "pysam/libcalignedsegment.pyx":1458 - * result.append(ref_seq[r_idx]) - * r_idx += 1 - * elif op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< - * pass - * elif op == BAM_CINS: - */ - __pyx_t_5 = ((__pyx_v_op == BAM_CREF_SKIP) != 0); - if (__pyx_t_5) { - goto __pyx_L6; - } + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1460 - * elif op == BAM_CREF_SKIP: - * pass - * elif op == BAM_CINS: # <<<<<<<<<<<<<< - * r_idx += l - * elif op == BAM_CSOFT_CLIP: - */ - __pyx_t_5 = ((__pyx_v_op == BAM_CINS) != 0); - if (__pyx_t_5) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1583, 0, __PYX_ERR(0, 1583, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1461 - * pass - * elif op == BAM_CINS: - * r_idx += l # <<<<<<<<<<<<<< - * elif op == BAM_CSOFT_CLIP: - * pass + /* "pysam/libcalignedsegment.pyx":1584 + * return (self.flag & BAM_FREAD1) != 0 + * def __set__(self,val): + * pysam_update_flag(self._delegate, val, BAM_FREAD1) # <<<<<<<<<<<<<< + * property is_read2: + * """true if this is read2""" */ - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_r_idx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1461, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_2); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1461, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_r_idx = __pyx_t_7; + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1584, __pyx_L1_error) + pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREAD1); - /* "pysam/libcalignedsegment.pyx":1460 - * elif op == BAM_CREF_SKIP: - * pass - * elif op == BAM_CINS: # <<<<<<<<<<<<<< - * r_idx += l - * elif op == BAM_CSOFT_CLIP: + /* "pysam/libcalignedsegment.pyx":1583 + * def __get__(self): + * return (self.flag & BAM_FREAD1) != 0 + * def __set__(self,val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FREAD1) + * property is_read2: */ - goto __pyx_L6; - } - /* "pysam/libcalignedsegment.pyx":1462 - * elif op == BAM_CINS: - * r_idx += l - * elif op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< - * pass - * elif op == BAM_CHARD_CLIP: - */ - __pyx_t_5 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0); - if (__pyx_t_5) { - goto __pyx_L6; - } + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_read1.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1464 - * elif op == BAM_CSOFT_CLIP: - * pass - * elif op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< - * pass # advances neither - * elif op == BAM_CPAD: +/* "pysam/libcalignedsegment.pyx":1587 + * property is_read2: + * """true if this is read2""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FREAD2) != 0 + * def __set__(self, val): */ - __pyx_t_5 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0); - if (__pyx_t_5) { - goto __pyx_L6; - } - /* "pysam/libcalignedsegment.pyx":1466 - * elif op == BAM_CHARD_CLIP: - * pass # advances neither - * elif op == BAM_CPAD: # <<<<<<<<<<<<<< - * raise NotImplementedError( - * "Padding (BAM_CPAD, 6) is currently not supported. " - */ - __pyx_t_5 = ((__pyx_v_op == BAM_CPAD) != 0); - if (unlikely(__pyx_t_5)) { +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - /* "pysam/libcalignedsegment.pyx":1467 - * pass # advances neither - * elif op == BAM_CPAD: - * raise NotImplementedError( # <<<<<<<<<<<<<< - * "Padding (BAM_CPAD, 6) is currently not supported. " - * "Please implement. Sorry about that.") - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1467, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 1467, __pyx_L1_error) + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1466 - * elif op == BAM_CHARD_CLIP: - * pass # advances neither - * elif op == BAM_CPAD: # <<<<<<<<<<<<<< - * raise NotImplementedError( - * "Padding (BAM_CPAD, 6) is currently not supported. " - */ - } - __pyx_L6:; - } +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1587, 0, __PYX_ERR(0, 1587, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1471 - * "Please implement. Sorry about that.") - * - * return "".join(result) # <<<<<<<<<<<<<< - * - * def get_aligned_pairs(self, matches_only=False, with_seq=False): + /* "pysam/libcalignedsegment.pyx":1588 + * """true if this is read2""" + * def __get__(self): + * return (self.flag & BAM_FREAD2) != 0 # <<<<<<<<<<<<<< + * def __set__(self, val): + * pysam_update_flag(self._delegate, val, BAM_FREAD2) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__16, __pyx_v_result); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1471, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREAD2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1588, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1588, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1432 - * return calculateQueryLength(src) - * - * def get_reference_sequence(self): # <<<<<<<<<<<<<< - * """return the reference sequence. - * + /* "pysam/libcalignedsegment.pyx":1587 + * property is_read2: + * """true if this is read2""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FREAD2) != 0 + * def __set__(self, val): */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_reference_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_read2.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_ref_seq); - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_l); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1473 - * return "".join(result) - * - * def get_aligned_pairs(self, matches_only=False, with_seq=False): # <<<<<<<<<<<<<< - * """a list of aligned read (query) and reference positions. - * +/* "pysam/libcalignedsegment.pyx":1589 + * def __get__(self): + * return (self.flag & BAM_FREAD2) != 0 + * def __set__(self, val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FREAD2) + * property is_secondary: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_25get_aligned_pairs(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_24get_aligned_pairs[] = "AlignedSegment.get_aligned_pairs(self, matches_only=False, with_seq=False)\na list of aligned read (query) and reference positions.\n\n For inserts, deletions, skipping either query or reference\n position may be None.\n\n Padding is currently not supported and leads to an exception.\n\n Parameters\n ----------\n\n matches_only : bool\n If True, only matched bases are returned - no None on either\n side.\n with_seq : bool\n If True, return a third element in the tuple containing the\n reference sequence. Substitutions are lower-case. This option\n requires an MD tag to be present.\n\n Returns\n -------\n\n aligned_pairs : list of tuples\n\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_25get_aligned_pairs(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_matches_only = 0; - PyObject *__pyx_v_with_seq = 0; - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_aligned_pairs (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_matches_only,&__pyx_n_s_with_seq,0}; - PyObject* values[2] = {0,0}; - values[0] = ((PyObject *)Py_False); - values[1] = ((PyObject *)Py_False); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_matches_only); - if (value) { values[0] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_with_seq); - if (value) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_aligned_pairs") < 0)) __PYX_ERR(0, 1473, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_matches_only = values[0]; - __pyx_v_with_seq = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_aligned_pairs", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1473, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_aligned_pairs", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_24get_aligned_pairs(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_matches_only, __pyx_v_with_seq); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_24get_aligned_pairs(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_matches_only, PyObject *__pyx_v_with_seq) { - uint32_t __pyx_v_k; - uint32_t __pyx_v_i; - uint32_t __pyx_v_pos; - uint32_t __pyx_v_qpos; - uint32_t __pyx_v_r_idx; - uint32_t __pyx_v_l; - int __pyx_v_op; - uint32_t *__pyx_v_cigar_p; - bam1_t *__pyx_v_src; - int __pyx_v__matches_only; - int __pyx_v__with_seq; - PyObject *__pyx_v_ref_seq = NULL; - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - int32_t __pyx_t_7; - uint16_t __pyx_t_8; - uint32_t __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - int __pyx_t_11; - __Pyx_RefNannySetupContext("get_aligned_pairs", 0); - __Pyx_TraceCall("get_aligned_pairs", __pyx_f[0], 1473, 0, __PYX_ERR(0, 1473, __pyx_L1_error)); + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1589, 0, __PYX_ERR(0, 1589, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1501 - * cdef int op - * cdef uint32_t * cigar_p - * cdef bam1_t * src = self._delegate # <<<<<<<<<<<<<< - * cdef bint _matches_only = bool(matches_only) - * cdef bint _with_seq = bool(with_seq) + /* "pysam/libcalignedsegment.pyx":1590 + * return (self.flag & BAM_FREAD2) != 0 + * def __set__(self, val): + * pysam_update_flag(self._delegate, val, BAM_FREAD2) # <<<<<<<<<<<<<< + * property is_secondary: + * """true if not primary alignment""" */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1590, __pyx_L1_error) + pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREAD2); - /* "pysam/libcalignedsegment.pyx":1502 - * cdef uint32_t * cigar_p - * cdef bam1_t * src = self._delegate - * cdef bint _matches_only = bool(matches_only) # <<<<<<<<<<<<<< - * cdef bint _with_seq = bool(with_seq) - * + /* "pysam/libcalignedsegment.pyx":1589 + * def __get__(self): + * return (self.flag & BAM_FREAD2) != 0 + * def __set__(self, val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FREAD2) + * property is_secondary: */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_matches_only); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1502, __pyx_L1_error) - __pyx_v__matches_only = (!(!__pyx_t_2)); - /* "pysam/libcalignedsegment.pyx":1503 - * cdef bam1_t * src = self._delegate - * cdef bint _matches_only = bool(matches_only) - * cdef bint _with_seq = bool(with_seq) # <<<<<<<<<<<<<< - * - * # TODO: this method performs no checking and assumes that - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_with_seq); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1503, __pyx_L1_error) - __pyx_v__with_seq = (!(!__pyx_t_2)); + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_read2.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1508 - * # read sequence, cigar and MD tag are consistent. - * - * if _with_seq: # <<<<<<<<<<<<<< - * ref_seq = force_str(self.get_reference_sequence()) - * if ref_seq is None: +/* "pysam/libcalignedsegment.pyx":1593 + * property is_secondary: + * """true if not primary alignment""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FSECONDARY) != 0 + * def __set__(self, val): */ - __pyx_t_2 = (__pyx_v__with_seq != 0); - if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":1509 - * - * if _with_seq: - * ref_seq = force_str(self.get_reference_sequence()) # <<<<<<<<<<<<<< - * if ref_seq is None: - * raise ValueError("MD tag not present") - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_sequence); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1509, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1509, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else { - __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1509, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1509, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_ref_seq = __pyx_t_4; - __pyx_t_4 = 0; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - /* "pysam/libcalignedsegment.pyx":1510 - * if _with_seq: - * ref_seq = force_str(self.get_reference_sequence()) - * if ref_seq is None: # <<<<<<<<<<<<<< - * raise ValueError("MD tag not present") - * - */ - __pyx_t_2 = (__pyx_v_ref_seq == Py_None); - __pyx_t_6 = (__pyx_t_2 != 0); - if (unlikely(__pyx_t_6)) { + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1511 - * ref_seq = force_str(self.get_reference_sequence()) - * if ref_seq is None: - * raise ValueError("MD tag not present") # <<<<<<<<<<<<<< - * - * r_idx = 0 - */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1511, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1511, __pyx_L1_error) +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1593, 0, __PYX_ERR(0, 1593, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1510 - * if _with_seq: - * ref_seq = force_str(self.get_reference_sequence()) - * if ref_seq is None: # <<<<<<<<<<<<<< - * raise ValueError("MD tag not present") - * + /* "pysam/libcalignedsegment.pyx":1594 + * """true if not primary alignment""" + * def __get__(self): + * return (self.flag & BAM_FSECONDARY) != 0 # <<<<<<<<<<<<<< + * def __set__(self, val): + * pysam_update_flag(self._delegate, val, BAM_FSECONDARY) */ - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1594, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FSECONDARY); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1594, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1594, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1594, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1508 - * # read sequence, cigar and MD tag are consistent. - * - * if _with_seq: # <<<<<<<<<<<<<< - * ref_seq = force_str(self.get_reference_sequence()) - * if ref_seq is None: + /* "pysam/libcalignedsegment.pyx":1593 + * property is_secondary: + * """true if not primary alignment""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FSECONDARY) != 0 + * def __set__(self, val): */ - } - /* "pysam/libcalignedsegment.pyx":1513 - * raise ValueError("MD tag not present") - * - * r_idx = 0 # <<<<<<<<<<<<<< - * - * if pysam_get_n_cigar(src) == 0: - */ - __pyx_v_r_idx = 0; + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_secondary.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1515 - * r_idx = 0 - * - * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return [] - * +/* "pysam/libcalignedsegment.pyx":1595 + * def __get__(self): + * return (self.flag & BAM_FSECONDARY) != 0 + * def __set__(self, val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FSECONDARY) + * property is_qcfail: */ - __pyx_t_6 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); - if (__pyx_t_6) { - /* "pysam/libcalignedsegment.pyx":1516 - * - * if pysam_get_n_cigar(src) == 0: - * return [] # <<<<<<<<<<<<<< - * - * result = [] - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1516, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); - /* "pysam/libcalignedsegment.pyx":1515 - * r_idx = 0 - * - * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return [] - * - */ - } + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1518 - * return [] - * - * result = [] # <<<<<<<<<<<<<< - * pos = src.core.pos - * qpos = 0 - */ - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1518, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_v_result = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1595, 0, __PYX_ERR(0, 1595, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1519 - * - * result = [] - * pos = src.core.pos # <<<<<<<<<<<<<< - * qpos = 0 - * cigar_p = pysam_bam_get_cigar(src) + /* "pysam/libcalignedsegment.pyx":1596 + * return (self.flag & BAM_FSECONDARY) != 0 + * def __set__(self, val): + * pysam_update_flag(self._delegate, val, BAM_FSECONDARY) # <<<<<<<<<<<<<< + * property is_qcfail: + * """true if QC failure""" */ - __pyx_t_7 = __pyx_v_src->core.pos; - __pyx_v_pos = __pyx_t_7; + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1596, __pyx_L1_error) + pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FSECONDARY); - /* "pysam/libcalignedsegment.pyx":1520 - * result = [] - * pos = src.core.pos - * qpos = 0 # <<<<<<<<<<<<<< - * cigar_p = pysam_bam_get_cigar(src) - * for k from 0 <= k < pysam_get_n_cigar(src): + /* "pysam/libcalignedsegment.pyx":1595 + * def __get__(self): + * return (self.flag & BAM_FSECONDARY) != 0 + * def __set__(self, val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FSECONDARY) + * property is_qcfail: */ - __pyx_v_qpos = 0; - /* "pysam/libcalignedsegment.pyx":1521 - * pos = src.core.pos - * qpos = 0 - * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK - */ - __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_secondary.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1522 - * qpos = 0 - * cigar_p = pysam_bam_get_cigar(src) - * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT +/* "pysam/libcalignedsegment.pyx":1599 + * property is_qcfail: + * """true if QC failure""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FQCFAIL) != 0 + * def __set__(self, val): */ - __pyx_t_8 = pysam_get_n_cigar(__pyx_v_src); - for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_8; __pyx_v_k++) { - /* "pysam/libcalignedsegment.pyx":1523 - * cigar_p = pysam_bam_get_cigar(src) - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * - */ - __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - /* "pysam/libcalignedsegment.pyx":1524 - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< - * - * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: - */ - __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT); + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1526 - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * - * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: # <<<<<<<<<<<<<< - * if _with_seq: - * for i from pos <= i < pos + l: - */ - __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0); - if (!__pyx_t_2) { - } else { - __pyx_t_6 = __pyx_t_2; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_2 = ((__pyx_v_op == BAM_CEQUAL) != 0); - if (!__pyx_t_2) { - } else { - __pyx_t_6 = __pyx_t_2; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_2 = ((__pyx_v_op == BAM_CDIFF) != 0); - __pyx_t_6 = __pyx_t_2; - __pyx_L9_bool_binop_done:; - if (__pyx_t_6) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1599, 0, __PYX_ERR(0, 1599, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1527 - * - * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: - * if _with_seq: # <<<<<<<<<<<<<< - * for i from pos <= i < pos + l: - * result.append((qpos, i, ref_seq[r_idx])) + /* "pysam/libcalignedsegment.pyx":1600 + * """true if QC failure""" + * def __get__(self): + * return (self.flag & BAM_FQCFAIL) != 0 # <<<<<<<<<<<<<< + * def __set__(self, val): + * pysam_update_flag(self._delegate, val, BAM_FQCFAIL) */ - __pyx_t_6 = (__pyx_v__with_seq != 0); - if (__pyx_t_6) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1600, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FQCFAIL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1600, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1600, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1600, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1528 - * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: - * if _with_seq: - * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< - * result.append((qpos, i, ref_seq[r_idx])) - * r_idx += 1 + /* "pysam/libcalignedsegment.pyx":1599 + * property is_qcfail: + * """true if QC failure""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FQCFAIL) != 0 + * def __set__(self, val): */ - __pyx_t_9 = (__pyx_v_pos + __pyx_v_l); - for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":1529 - * if _with_seq: - * for i from pos <= i < pos + l: - * result.append((qpos, i, ref_seq[r_idx])) # <<<<<<<<<<<<<< - * r_idx += 1 - * qpos += 1 - */ - __pyx_t_4 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1529, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1529, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (unlikely(!__pyx_v_ref_seq)) { __Pyx_RaiseUnboundLocalError("ref_seq"); __PYX_ERR(0, 1529, __pyx_L1_error) } - __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_ref_seq, __pyx_v_r_idx, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1529, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1529, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_5); - __pyx_t_4 = 0; - __pyx_t_3 = 0; - __pyx_t_5 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1529, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_qcfail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1530 - * for i from pos <= i < pos + l: - * result.append((qpos, i, ref_seq[r_idx])) - * r_idx += 1 # <<<<<<<<<<<<<< - * qpos += 1 - * else: +/* "pysam/libcalignedsegment.pyx":1601 + * def __get__(self): + * return (self.flag & BAM_FQCFAIL) != 0 + * def __set__(self, val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FQCFAIL) + * property is_duplicate: */ - __pyx_v_r_idx = (__pyx_v_r_idx + 1); - /* "pysam/libcalignedsegment.pyx":1531 - * result.append((qpos, i, ref_seq[r_idx])) - * r_idx += 1 - * qpos += 1 # <<<<<<<<<<<<<< - * else: - * for i from pos <= i < pos + l: - */ - __pyx_v_qpos = (__pyx_v_qpos + 1); - } +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); - /* "pysam/libcalignedsegment.pyx":1527 - * - * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: - * if _with_seq: # <<<<<<<<<<<<<< - * for i from pos <= i < pos + l: - * result.append((qpos, i, ref_seq[r_idx])) - */ - goto __pyx_L12; - } + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1533 - * qpos += 1 - * else: - * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< - * result.append((qpos, i)) - * qpos += 1 - */ - /*else*/ { - __pyx_t_9 = (__pyx_v_pos + __pyx_v_l); - for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1601, 0, __PYX_ERR(0, 1601, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1534 - * else: - * for i from pos <= i < pos + l: - * result.append((qpos, i)) # <<<<<<<<<<<<<< - * qpos += 1 - * pos += l + /* "pysam/libcalignedsegment.pyx":1602 + * return (self.flag & BAM_FQCFAIL) != 0 + * def __set__(self, val): + * pysam_update_flag(self._delegate, val, BAM_FQCFAIL) # <<<<<<<<<<<<<< + * property is_duplicate: + * """true if optical or PCR duplicate""" */ - __pyx_t_10 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1534, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1534, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1534, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5); - __pyx_t_10 = 0; - __pyx_t_5 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1534, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1602, __pyx_L1_error) + pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FQCFAIL); - /* "pysam/libcalignedsegment.pyx":1535 - * for i from pos <= i < pos + l: - * result.append((qpos, i)) - * qpos += 1 # <<<<<<<<<<<<<< - * pos += l - * + /* "pysam/libcalignedsegment.pyx":1601 + * def __get__(self): + * return (self.flag & BAM_FQCFAIL) != 0 + * def __set__(self, val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FQCFAIL) + * property is_duplicate: */ - __pyx_v_qpos = (__pyx_v_qpos + 1); - } - } - __pyx_L12:; - /* "pysam/libcalignedsegment.pyx":1536 - * result.append((qpos, i)) - * qpos += 1 - * pos += l # <<<<<<<<<<<<<< - * - * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: - */ - __pyx_v_pos = (__pyx_v_pos + __pyx_v_l); + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_qcfail.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1526 - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * - * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: # <<<<<<<<<<<<<< - * if _with_seq: - * for i from pos <= i < pos + l: +/* "pysam/libcalignedsegment.pyx":1605 + * property is_duplicate: + * """true if optical or PCR duplicate""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FDUP) != 0 + * def __set__(self, val): */ - goto __pyx_L8; - } - /* "pysam/libcalignedsegment.pyx":1538 - * pos += l - * - * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< - * if not _matches_only: - * if _with_seq: - */ - __pyx_t_2 = ((__pyx_v_op == BAM_CINS) != 0); - if (!__pyx_t_2) { - } else { - __pyx_t_6 = __pyx_t_2; - goto __pyx_L17_bool_binop_done; - } - __pyx_t_2 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0); - __pyx_t_6 = __pyx_t_2; - __pyx_L17_bool_binop_done:; - if (__pyx_t_6) { +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - /* "pysam/libcalignedsegment.pyx":1539 - * - * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: - * if not _matches_only: # <<<<<<<<<<<<<< - * if _with_seq: - * for i from pos <= i < pos + l: - */ - __pyx_t_6 = ((!(__pyx_v__matches_only != 0)) != 0); - if (__pyx_t_6) { + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1540 - * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: - * if not _matches_only: - * if _with_seq: # <<<<<<<<<<<<<< - * for i from pos <= i < pos + l: - * result.append((qpos, None, None)) - */ - __pyx_t_6 = (__pyx_v__with_seq != 0); - if (__pyx_t_6) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1605, 0, __PYX_ERR(0, 1605, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1541 - * if not _matches_only: - * if _with_seq: - * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< - * result.append((qpos, None, None)) - * qpos += 1 + /* "pysam/libcalignedsegment.pyx":1606 + * """true if optical or PCR duplicate""" + * def __get__(self): + * return (self.flag & BAM_FDUP) != 0 # <<<<<<<<<<<<<< + * def __set__(self, val): + * pysam_update_flag(self._delegate, val, BAM_FDUP) */ - __pyx_t_9 = (__pyx_v_pos + __pyx_v_l); - for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1606, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FDUP); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1606, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1606, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1606, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1542 - * if _with_seq: - * for i from pos <= i < pos + l: - * result.append((qpos, None, None)) # <<<<<<<<<<<<<< - * qpos += 1 - * else: + /* "pysam/libcalignedsegment.pyx":1605 + * property is_duplicate: + * """true if optical or PCR duplicate""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FDUP) != 0 + * def __set__(self, val): */ - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1542, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1542, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_5, 1, Py_None); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_5, 2, Py_None); - __pyx_t_3 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_5); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1542, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcalignedsegment.pyx":1543 - * for i from pos <= i < pos + l: - * result.append((qpos, None, None)) - * qpos += 1 # <<<<<<<<<<<<<< - * else: - * for i from pos <= i < pos + l: + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_duplicate.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1607 + * def __get__(self): + * return (self.flag & BAM_FDUP) != 0 + * def __set__(self, val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FDUP) + * property is_supplementary: */ - __pyx_v_qpos = (__pyx_v_qpos + 1); - } - /* "pysam/libcalignedsegment.pyx":1540 - * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: - * if not _matches_only: - * if _with_seq: # <<<<<<<<<<<<<< - * for i from pos <= i < pos + l: - * result.append((qpos, None, None)) +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1607, 0, __PYX_ERR(0, 1607, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1608 + * return (self.flag & BAM_FDUP) != 0 + * def __set__(self, val): + * pysam_update_flag(self._delegate, val, BAM_FDUP) # <<<<<<<<<<<<<< + * property is_supplementary: + * """true if this is a supplementary alignment""" */ - goto __pyx_L20; - } + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1608, __pyx_L1_error) + pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FDUP); - /* "pysam/libcalignedsegment.pyx":1545 - * qpos += 1 - * else: - * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< - * result.append((qpos, None)) - * qpos += 1 + /* "pysam/libcalignedsegment.pyx":1607 + * def __get__(self): + * return (self.flag & BAM_FDUP) != 0 + * def __set__(self, val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FDUP) + * property is_supplementary: */ - /*else*/ { - __pyx_t_9 = (__pyx_v_pos + __pyx_v_l); - for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":1546 - * else: - * for i from pos <= i < pos + l: - * result.append((qpos, None)) # <<<<<<<<<<<<<< - * qpos += 1 - * else: + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_duplicate.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1611 + * property is_supplementary: + * """true if this is a supplementary alignment""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FSUPPLEMENTARY) != 0 + * def __set__(self, val): */ - __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1546, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1546, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_3, 1, Py_None); - __pyx_t_5 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1546, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1547 - * for i from pos <= i < pos + l: - * result.append((qpos, None)) - * qpos += 1 # <<<<<<<<<<<<<< - * else: - * qpos += l +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1611, 0, __PYX_ERR(0, 1611, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1612 + * """true if this is a supplementary alignment""" + * def __get__(self): + * return (self.flag & BAM_FSUPPLEMENTARY) != 0 # <<<<<<<<<<<<<< + * def __set__(self, val): + * pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY) */ - __pyx_v_qpos = (__pyx_v_qpos + 1); - } - } - __pyx_L20:; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FSUPPLEMENTARY); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1612, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1539 - * - * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: - * if not _matches_only: # <<<<<<<<<<<<<< - * if _with_seq: - * for i from pos <= i < pos + l: + /* "pysam/libcalignedsegment.pyx":1611 + * property is_supplementary: + * """true if this is a supplementary alignment""" + * def __get__(self): # <<<<<<<<<<<<<< + * return (self.flag & BAM_FSUPPLEMENTARY) != 0 + * def __set__(self, val): */ - goto __pyx_L19; - } - /* "pysam/libcalignedsegment.pyx":1549 - * qpos += 1 - * else: - * qpos += l # <<<<<<<<<<<<<< + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_supplementary.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1613 + * def __get__(self): + * return (self.flag & BAM_FSUPPLEMENTARY) != 0 + * def __set__(self, val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY) * - * elif op == BAM_CDEL: */ - /*else*/ { - __pyx_v_qpos = (__pyx_v_qpos + __pyx_v_l); - } - __pyx_L19:; - /* "pysam/libcalignedsegment.pyx":1538 - * pos += l +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + uint16_t __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 1613, 0, __PYX_ERR(0, 1613, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1614 + * return (self.flag & BAM_FSUPPLEMENTARY) != 0 + * def __set__(self, val): + * pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY) # <<<<<<<<<<<<<< * - * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< - * if not _matches_only: - * if _with_seq: + * # 2. Coordinates and lengths */ - goto __pyx_L8; - } + __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1614, __pyx_L1_error) + pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FSUPPLEMENTARY); - /* "pysam/libcalignedsegment.pyx":1551 - * qpos += l + /* "pysam/libcalignedsegment.pyx":1613 + * def __get__(self): + * return (self.flag & BAM_FSUPPLEMENTARY) != 0 + * def __set__(self, val): # <<<<<<<<<<<<<< + * pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY) * - * elif op == BAM_CDEL: # <<<<<<<<<<<<<< - * if not _matches_only: - * if _with_seq: */ - __pyx_t_6 = ((__pyx_v_op == BAM_CDEL) != 0); - if (__pyx_t_6) { - /* "pysam/libcalignedsegment.pyx":1552 + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.is_supplementary.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1625 * - * elif op == BAM_CDEL: - * if not _matches_only: # <<<<<<<<<<<<<< - * if _with_seq: - * for i from pos <= i < pos + l: + * ''' + * def __get__(self): # <<<<<<<<<<<<<< + * cdef bam1_t * src + * src = self._delegate */ - __pyx_t_6 = ((!(__pyx_v__matches_only != 0)) != 0); - if (__pyx_t_6) { - /* "pysam/libcalignedsegment.pyx":1553 - * elif op == BAM_CDEL: - * if not _matches_only: - * if _with_seq: # <<<<<<<<<<<<<< - * for i from pos <= i < pos + l: - * result.append((None, i, ref_seq[r_idx])) - */ - __pyx_t_6 = (__pyx_v__with_seq != 0); - if (__pyx_t_6) { +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13reference_end_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13reference_end_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_13reference_end___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - /* "pysam/libcalignedsegment.pyx":1554 - * if not _matches_only: - * if _with_seq: - * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< - * result.append((None, i, ref_seq[r_idx])) - * r_idx += 1 - */ - __pyx_t_9 = (__pyx_v_pos + __pyx_v_l); - for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) { + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1555 - * if _with_seq: - * for i from pos <= i < pos + l: - * result.append((None, i, ref_seq[r_idx])) # <<<<<<<<<<<<<< - * r_idx += 1 - * else: - */ - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1555, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (unlikely(!__pyx_v_ref_seq)) { __Pyx_RaiseUnboundLocalError("ref_seq"); __PYX_ERR(0, 1555, __pyx_L1_error) } - __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_ref_seq, __pyx_v_r_idx, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1555, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1555, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_10, 0, Py_None); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_5); - __pyx_t_3 = 0; - __pyx_t_5 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1555, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_13reference_end___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + bam1_t *__pyx_v_src; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + bam1_t *__pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1625, 0, __PYX_ERR(0, 1625, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1556 - * for i from pos <= i < pos + l: - * result.append((None, i, ref_seq[r_idx])) - * r_idx += 1 # <<<<<<<<<<<<<< - * else: - * for i from pos <= i < pos + l: + /* "pysam/libcalignedsegment.pyx":1627 + * def __get__(self): + * cdef bam1_t * src + * src = self._delegate # <<<<<<<<<<<<<< + * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: + * return None */ - __pyx_v_r_idx = (__pyx_v_r_idx + 1); - } + __pyx_t_1 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":1553 - * elif op == BAM_CDEL: - * if not _matches_only: - * if _with_seq: # <<<<<<<<<<<<<< - * for i from pos <= i < pos + l: - * result.append((None, i, ref_seq[r_idx])) + /* "pysam/libcalignedsegment.pyx":1628 + * cdef bam1_t * src + * src = self._delegate + * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< + * return None + * return bam_endpos(src) */ - goto __pyx_L26; - } + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1628, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1628, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyNumber_And(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1628, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1628, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (!__pyx_t_6) { + } else { + __pyx_t_2 = __pyx_t_6; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_6 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); + __pyx_t_2 = __pyx_t_6; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":1558 - * r_idx += 1 - * else: - * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< - * result.append((None, i)) - * pos += l + /* "pysam/libcalignedsegment.pyx":1629 + * src = self._delegate + * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: + * return None # <<<<<<<<<<<<<< + * return bam_endpos(src) + * */ - /*else*/ { - __pyx_t_9 = (__pyx_v_pos + __pyx_v_l); - for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) { + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1559 - * else: - * for i from pos <= i < pos + l: - * result.append((None, i)) # <<<<<<<<<<<<<< - * pos += l - * + /* "pysam/libcalignedsegment.pyx":1628 + * cdef bam1_t * src + * src = self._delegate + * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< + * return None + * return bam_endpos(src) */ - __pyx_t_10 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_5, 0, Py_None); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_10); - __pyx_t_10 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_5); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - } - __pyx_L26:; + } - /* "pysam/libcalignedsegment.pyx":1552 + /* "pysam/libcalignedsegment.pyx":1630 + * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: + * return None + * return bam_endpos(src) # <<<<<<<<<<<<<< * - * elif op == BAM_CDEL: - * if not _matches_only: # <<<<<<<<<<<<<< - * if _with_seq: - * for i from pos <= i < pos + l: + * property reference_length: */ - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = __Pyx_PyInt_From_int32_t(bam_endpos(__pyx_v_src)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1630, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1560 - * for i from pos <= i < pos + l: - * result.append((None, i)) - * pos += l # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1625 * - * elif op == BAM_CHARD_CLIP: + * ''' + * def __get__(self): # <<<<<<<<<<<<<< + * cdef bam1_t * src + * src = self._delegate */ - __pyx_v_pos = (__pyx_v_pos + __pyx_v_l); - /* "pysam/libcalignedsegment.pyx":1551 - * qpos += l - * - * elif op == BAM_CDEL: # <<<<<<<<<<<<<< - * if not _matches_only: - * if _with_seq: - */ - goto __pyx_L8; - } + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_end.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1562 - * pos += l - * - * elif op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< - * pass # advances neither +/* "pysam/libcalignedsegment.pyx":1636 * + * This is equal to `aend - pos`. Returns None if not available.''' + * def __get__(self): # <<<<<<<<<<<<<< + * cdef bam1_t * src + * src = self._delegate */ - __pyx_t_6 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0); - if (__pyx_t_6) { - goto __pyx_L8; - } - /* "pysam/libcalignedsegment.pyx":1565 - * pass # advances neither +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16reference_length_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16reference_length_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16reference_length___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_16reference_length___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + bam1_t *__pyx_v_src; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + bam1_t *__pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1636, 0, __PYX_ERR(0, 1636, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1638 + * def __get__(self): + * cdef bam1_t * src + * src = self._delegate # <<<<<<<<<<<<<< + * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: + * return None + */ + __pyx_t_1 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_1; + + /* "pysam/libcalignedsegment.pyx":1639 + * cdef bam1_t * src + * src = self._delegate + * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< + * return None + * return bam_endpos(src) - \ + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1639, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1639, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyNumber_And(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1639, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1639, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (!__pyx_t_6) { + } else { + __pyx_t_2 = __pyx_t_6; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_6 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); + __pyx_t_2 = __pyx_t_6; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":1640 + * src = self._delegate + * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: + * return None # <<<<<<<<<<<<<< + * return bam_endpos(src) - \ + * self._delegate.core.pos + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":1639 + * cdef bam1_t * src + * src = self._delegate + * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< + * return None + * return bam_endpos(src) - \ + */ + } + + /* "pysam/libcalignedsegment.pyx":1641 + * if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0: + * return None + * return bam_endpos(src) - \ # <<<<<<<<<<<<<< + * self._delegate.core.pos * - * elif op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< - * if not _matches_only: - * if _with_seq: */ - __pyx_t_6 = ((__pyx_v_op == BAM_CREF_SKIP) != 0); - if (__pyx_t_6) { + __Pyx_XDECREF(__pyx_r); - /* "pysam/libcalignedsegment.pyx":1566 + /* "pysam/libcalignedsegment.pyx":1642 + * return None + * return bam_endpos(src) - \ + * self._delegate.core.pos # <<<<<<<<<<<<<< * - * elif op == BAM_CREF_SKIP: - * if not _matches_only: # <<<<<<<<<<<<<< - * if _with_seq: - * for i from pos <= i < pos + l: + * property query_alignment_sequence: */ - __pyx_t_6 = ((!(__pyx_v__matches_only != 0)) != 0); - if (__pyx_t_6) { + __pyx_t_5 = __Pyx_PyInt_From_int32_t((bam_endpos(__pyx_v_src) - __pyx_v_self->_delegate->core.pos)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1641, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1567 - * elif op == BAM_CREF_SKIP: - * if not _matches_only: - * if _with_seq: # <<<<<<<<<<<<<< - * for i from pos <= i < pos + l: - * result.append((None, i, None)) + /* "pysam/libcalignedsegment.pyx":1636 + * + * This is equal to `aend - pos`. Returns None if not available.''' + * def __get__(self): # <<<<<<<<<<<<<< + * cdef bam1_t * src + * src = self._delegate */ - __pyx_t_6 = (__pyx_v__with_seq != 0); - if (__pyx_t_6) { - /* "pysam/libcalignedsegment.pyx":1568 - * if not _matches_only: - * if _with_seq: - * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< - * result.append((None, i, None)) - * else: + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.reference_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1661 + * """ + * + * def __get__(self): # <<<<<<<<<<<<<< + * if self.cache_query_alignment_sequence: + * return self.cache_query_alignment_sequence */ - __pyx_t_9 = (__pyx_v_pos + __pyx_v_l); - for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":1569 - * if _with_seq: - * for i from pos <= i < pos + l: - * result.append((None, i, None)) # <<<<<<<<<<<<<< - * else: - * for i from pos <= i < pos + l: +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_24query_alignment_sequence_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_24query_alignment_sequence_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_24query_alignment_sequence___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_24query_alignment_sequence___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + bam1_t *__pyx_v_src; + uint32_t __pyx_v_start; + uint32_t __pyx_v_end; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + bam1_t *__pyx_t_2; + int32_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1661, 0, __PYX_ERR(0, 1661, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1662 + * + * def __get__(self): + * if self.cache_query_alignment_sequence: # <<<<<<<<<<<<<< + * return self.cache_query_alignment_sequence + * */ - __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1569, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1569, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_10, 0, Py_None); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_5); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_10, 2, Py_None); - __pyx_t_5 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1569, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->cache_query_alignment_sequence); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1662, __pyx_L1_error) + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1567 - * elif op == BAM_CREF_SKIP: - * if not _matches_only: - * if _with_seq: # <<<<<<<<<<<<<< - * for i from pos <= i < pos + l: - * result.append((None, i, None)) + /* "pysam/libcalignedsegment.pyx":1663 + * def __get__(self): + * if self.cache_query_alignment_sequence: + * return self.cache_query_alignment_sequence # <<<<<<<<<<<<<< + * + * cdef bam1_t * src */ - goto __pyx_L32; - } + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->cache_query_alignment_sequence); + __pyx_r = __pyx_v_self->cache_query_alignment_sequence; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1571 - * result.append((None, i, None)) - * else: - * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< - * result.append((None, i)) + /* "pysam/libcalignedsegment.pyx":1662 + * + * def __get__(self): + * if self.cache_query_alignment_sequence: # <<<<<<<<<<<<<< + * return self.cache_query_alignment_sequence * */ - /*else*/ { - __pyx_t_9 = (__pyx_v_pos + __pyx_v_l); - for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) { + } - /* "pysam/libcalignedsegment.pyx":1572 - * else: - * for i from pos <= i < pos + l: - * result.append((None, i)) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1668 + * cdef uint32_t start, end * - * pos += l + * src = self._delegate # <<<<<<<<<<<<<< + * + * if src.core.l_qseq == 0: */ - __pyx_t_10 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_5, 0, Py_None); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_10); - __pyx_t_10 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_5); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1572, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - } - __pyx_L32:; + __pyx_t_2 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_2; - /* "pysam/libcalignedsegment.pyx":1566 + /* "pysam/libcalignedsegment.pyx":1670 + * src = self._delegate + * + * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< + * return None * - * elif op == BAM_CREF_SKIP: - * if not _matches_only: # <<<<<<<<<<<<<< - * if _with_seq: - * for i from pos <= i < pos + l: */ - } + __pyx_t_1 = ((__pyx_v_src->core.l_qseq == 0) != 0); + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1574 - * result.append((None, i)) + /* "pysam/libcalignedsegment.pyx":1671 * - * pos += l # <<<<<<<<<<<<<< + * if src.core.l_qseq == 0: + * return None # <<<<<<<<<<<<<< * - * elif op == BAM_CPAD: + * start = getQueryStart(src) */ - __pyx_v_pos = (__pyx_v_pos + __pyx_v_l); + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1565 - * pass # advances neither + /* "pysam/libcalignedsegment.pyx":1670 + * src = self._delegate + * + * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< + * return None * - * elif op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< - * if not _matches_only: - * if _with_seq: */ - goto __pyx_L8; - } + } - /* "pysam/libcalignedsegment.pyx":1576 - * pos += l + /* "pysam/libcalignedsegment.pyx":1673 + * return None + * + * start = getQueryStart(src) # <<<<<<<<<<<<<< + * end = getQueryEnd(src) * - * elif op == BAM_CPAD: # <<<<<<<<<<<<<< - * raise NotImplementedError( - * "Padding (BAM_CPAD, 6) is currently not supported. " */ - __pyx_t_6 = ((__pyx_v_op == BAM_CPAD) != 0); - if (unlikely(__pyx_t_6)) { + __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_3 == ((int32_t)-1))) __PYX_ERR(0, 1673, __pyx_L1_error) + __pyx_v_start = __pyx_t_3; - /* "pysam/libcalignedsegment.pyx":1577 + /* "pysam/libcalignedsegment.pyx":1674 * - * elif op == BAM_CPAD: - * raise NotImplementedError( # <<<<<<<<<<<<<< - * "Padding (BAM_CPAD, 6) is currently not supported. " - * "Please implement. Sorry about that.") + * start = getQueryStart(src) + * end = getQueryEnd(src) # <<<<<<<<<<<<<< + * + * self.cache_query_alignment_sequence = force_str( */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1577, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 1577, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_3 == ((int32_t)-1))) __PYX_ERR(0, 1674, __pyx_L1_error) + __pyx_v_end = __pyx_t_3; - /* "pysam/libcalignedsegment.pyx":1576 - * pos += l + /* "pysam/libcalignedsegment.pyx":1677 + * + * self.cache_query_alignment_sequence = force_str( + * getSequenceInRange(src, start, end)) # <<<<<<<<<<<<<< + * return self.cache_query_alignment_sequence * - * elif op == BAM_CPAD: # <<<<<<<<<<<<<< - * raise NotImplementedError( - * "Padding (BAM_CPAD, 6) is currently not supported. " */ - } - __pyx_L8:; - } + __pyx_t_4 = __pyx_f_5pysam_18libcalignedsegment_getSequenceInRange(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1677, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libcalignedsegment.pyx":1581 - * "Please implement. Sorry about that.") + /* "pysam/libcalignedsegment.pyx":1676 + * end = getQueryEnd(src) * - * return result # <<<<<<<<<<<<<< + * self.cache_query_alignment_sequence = force_str( # <<<<<<<<<<<<<< + * getSequenceInRange(src, start, end)) + * return self.cache_query_alignment_sequence + */ + __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1676, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_sequence); + __Pyx_DECREF(__pyx_v_self->cache_query_alignment_sequence); + __pyx_v_self->cache_query_alignment_sequence = __pyx_t_5; + __pyx_t_5 = 0; + + /* "pysam/libcalignedsegment.pyx":1678 + * self.cache_query_alignment_sequence = force_str( + * getSequenceInRange(src, start, end)) + * return self.cache_query_alignment_sequence # <<<<<<<<<<<<<< * - * def get_blocks(self): + * property query_alignment_qualities: */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result); - __pyx_r = __pyx_v_result; + __Pyx_INCREF(__pyx_v_self->cache_query_alignment_sequence); + __pyx_r = __pyx_v_self->cache_query_alignment_sequence; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1473 - * return "".join(result) - * - * def get_aligned_pairs(self, matches_only=False, with_seq=False): # <<<<<<<<<<<<<< - * """a list of aligned read (query) and reference positions. + /* "pysam/libcalignedsegment.pyx":1661 + * """ * + * def __get__(self): # <<<<<<<<<<<<<< + * if self.cache_query_alignment_sequence: + * return self.cache_query_alignment_sequence */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_aligned_pairs", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_alignment_sequence.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_ref_seq); - __Pyx_XDECREF(__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1583 - * return result +/* "pysam/libcalignedsegment.pyx":1694 * - * def get_blocks(self): # <<<<<<<<<<<<<< - * """ a list of start and end positions of - * aligned gapless blocks. + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * + * if self.cache_query_alignment_qualities: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_27get_blocks(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_26get_blocks[] = "AlignedSegment.get_blocks(self)\n a list of start and end positions of\n aligned gapless blocks.\n\n The start and end positions are in genomic\n coordinates.\n\n Blocks are not normalized, i.e. two blocks\n might be directly adjacent. This happens if\n the two blocks are separated by an insertion\n in the read.\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_27get_blocks(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_25query_alignment_qualities_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_25query_alignment_qualities_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_blocks (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_26get_blocks(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_25query_alignment_qualities___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_26get_blocks(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - uint32_t __pyx_v_k; - uint32_t __pyx_v_pos; - uint32_t __pyx_v_l; - int __pyx_v_op; - uint32_t *__pyx_v_cigar_p; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_25query_alignment_qualities___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { bam1_t *__pyx_v_src; - PyObject *__pyx_v_result = NULL; + uint32_t __pyx_v_start; + uint32_t __pyx_v_end; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int32_t __pyx_t_4; - uint16_t __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - int __pyx_t_8; - int __pyx_t_9; - __Pyx_RefNannySetupContext("get_blocks", 0); - __Pyx_TraceCall("get_blocks", __pyx_f[0], 1583, 0, __PYX_ERR(0, 1583, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":1601 - * cdef bam1_t * src - * - * src = self._delegate # <<<<<<<<<<<<<< - * if pysam_get_n_cigar(src) == 0: - * return [] - */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; + int __pyx_t_1; + bam1_t *__pyx_t_2; + int32_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1694, 0, __PYX_ERR(0, 1694, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1602 + /* "pysam/libcalignedsegment.pyx":1696 + * def __get__(self): * - * src = self._delegate - * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return [] + * if self.cache_query_alignment_qualities: # <<<<<<<<<<<<<< + * return self.cache_query_alignment_qualities * */ - __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); - if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->cache_query_alignment_qualities); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1696, __pyx_L1_error) + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1603 - * src = self._delegate - * if pysam_get_n_cigar(src) == 0: - * return [] # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1697 * - * result = [] + * if self.cache_query_alignment_qualities: + * return self.cache_query_alignment_qualities # <<<<<<<<<<<<<< + * + * cdef bam1_t * src */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1603, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_v_self->cache_query_alignment_qualities); + __pyx_r = __pyx_v_self->cache_query_alignment_qualities; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1602 + /* "pysam/libcalignedsegment.pyx":1696 + * def __get__(self): * - * src = self._delegate - * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return [] + * if self.cache_query_alignment_qualities: # <<<<<<<<<<<<<< + * return self.cache_query_alignment_qualities * */ } - /* "pysam/libcalignedsegment.pyx":1605 - * return [] + /* "pysam/libcalignedsegment.pyx":1702 + * cdef uint32_t start, end * - * result = [] # <<<<<<<<<<<<<< - * pos = src.core.pos - * cigar_p = pysam_bam_get_cigar(src) + * src = self._delegate # <<<<<<<<<<<<<< + * + * if src.core.l_qseq == 0: */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1605, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_result = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_2 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_2; - /* "pysam/libcalignedsegment.pyx":1606 + /* "pysam/libcalignedsegment.pyx":1704 + * src = self._delegate + * + * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< + * return None * - * result = [] - * pos = src.core.pos # <<<<<<<<<<<<<< - * cigar_p = pysam_bam_get_cigar(src) - * l = 0 */ - __pyx_t_4 = __pyx_v_src->core.pos; - __pyx_v_pos = __pyx_t_4; + __pyx_t_1 = ((__pyx_v_src->core.l_qseq == 0) != 0); + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1607 - * result = [] - * pos = src.core.pos - * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< - * l = 0 + /* "pysam/libcalignedsegment.pyx":1705 + * + * if src.core.l_qseq == 0: + * return None # <<<<<<<<<<<<<< * + * start = getQueryStart(src) */ - __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1608 - * pos = src.core.pos - * cigar_p = pysam_bam_get_cigar(src) - * l = 0 # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1704 + * src = self._delegate + * + * if src.core.l_qseq == 0: # <<<<<<<<<<<<<< + * return None * - * for k from 0 <= k < pysam_get_n_cigar(src): */ - __pyx_v_l = 0; + } - /* "pysam/libcalignedsegment.pyx":1610 - * l = 0 + /* "pysam/libcalignedsegment.pyx":1707 + * return None * - * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * start = getQueryStart(src) # <<<<<<<<<<<<<< + * end = getQueryEnd(src) + * self.cache_query_alignment_qualities = \ */ - __pyx_t_5 = pysam_get_n_cigar(__pyx_v_src); - for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) { + __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_3 == ((int32_t)-1))) __PYX_ERR(0, 1707, __pyx_L1_error) + __pyx_v_start = __pyx_t_3; - /* "pysam/libcalignedsegment.pyx":1611 + /* "pysam/libcalignedsegment.pyx":1708 * - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * if op == BAM_CMATCH: + * start = getQueryStart(src) + * end = getQueryEnd(src) # <<<<<<<<<<<<<< + * self.cache_query_alignment_qualities = \ + * getQualitiesInRange(src, start, end) */ - __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); + __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_3 == ((int32_t)-1))) __PYX_ERR(0, 1708, __pyx_L1_error) + __pyx_v_end = __pyx_t_3; - /* "pysam/libcalignedsegment.pyx":1612 - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< - * if op == BAM_CMATCH: - * result.append((pos, pos + l)) + /* "pysam/libcalignedsegment.pyx":1710 + * end = getQueryEnd(src) + * self.cache_query_alignment_qualities = \ + * getQualitiesInRange(src, start, end) # <<<<<<<<<<<<<< + * return self.cache_query_alignment_qualities + * */ - __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT); + __pyx_t_4 = __pyx_f_5pysam_18libcalignedsegment_getQualitiesInRange(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1710, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libcalignedsegment.pyx":1613 - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * if op == BAM_CMATCH: # <<<<<<<<<<<<<< - * result.append((pos, pos + l)) - * pos += l + /* "pysam/libcalignedsegment.pyx":1709 + * start = getQueryStart(src) + * end = getQueryEnd(src) + * self.cache_query_alignment_qualities = \ # <<<<<<<<<<<<<< + * getQualitiesInRange(src, start, end) + * return self.cache_query_alignment_qualities */ - __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0); - if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_qualities); + __Pyx_DECREF(__pyx_v_self->cache_query_alignment_qualities); + __pyx_v_self->cache_query_alignment_qualities = __pyx_t_4; + __pyx_t_4 = 0; - /* "pysam/libcalignedsegment.pyx":1614 - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * if op == BAM_CMATCH: - * result.append((pos, pos + l)) # <<<<<<<<<<<<<< - * pos += l - * elif op == BAM_CDEL or op == BAM_CREF_SKIP: + /* "pysam/libcalignedsegment.pyx":1711 + * self.cache_query_alignment_qualities = \ + * getQualitiesInRange(src, start, end) + * return self.cache_query_alignment_qualities # <<<<<<<<<<<<<< + * + * property query_alignment_start: */ - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1614, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyInt_From_uint32_t((__pyx_v_pos + __pyx_v_l)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1614, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1614, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6); - __pyx_t_3 = 0; - __pyx_t_6 = 0; - __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1614, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->cache_query_alignment_qualities); + __pyx_r = __pyx_v_self->cache_query_alignment_qualities; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1615 - * if op == BAM_CMATCH: - * result.append((pos, pos + l)) - * pos += l # <<<<<<<<<<<<<< - * elif op == BAM_CDEL or op == BAM_CREF_SKIP: - * pos += l + /* "pysam/libcalignedsegment.pyx":1694 + * + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * + * if self.cache_query_alignment_qualities: */ - __pyx_v_pos = (__pyx_v_pos + __pyx_v_l); - /* "pysam/libcalignedsegment.pyx":1613 - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * if op == BAM_CMATCH: # <<<<<<<<<<<<<< - * result.append((pos, pos + l)) - * pos += l + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_alignment_qualities.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1720 + * soft-clipped. + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * return getQueryStart(self._delegate) + * */ - goto __pyx_L6; - } - /* "pysam/libcalignedsegment.pyx":1616 - * result.append((pos, pos + l)) - * pos += l - * elif op == BAM_CDEL or op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< - * pos += l +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21query_alignment_start_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21query_alignment_start_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_21query_alignment_start___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_21query_alignment_start___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int32_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1720, 0, __PYX_ERR(0, 1720, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1721 + * """ + * def __get__(self): + * return getQueryStart(self._delegate) # <<<<<<<<<<<<<< * + * property query_alignment_end: */ - __pyx_t_9 = ((__pyx_v_op == BAM_CDEL) != 0); - if (!__pyx_t_9) { - } else { - __pyx_t_2 = __pyx_t_9; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_9 = ((__pyx_v_op == BAM_CREF_SKIP) != 0); - __pyx_t_2 = __pyx_t_9; - __pyx_L7_bool_binop_done:; - if (__pyx_t_2) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_getQueryStart(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == ((int32_t)-1))) __PYX_ERR(0, 1721, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1721, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1617 - * pos += l - * elif op == BAM_CDEL or op == BAM_CREF_SKIP: - * pos += l # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1720 + * soft-clipped. + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * return getQueryStart(self._delegate) * - * return result */ - __pyx_v_pos = (__pyx_v_pos + __pyx_v_l); - /* "pysam/libcalignedsegment.pyx":1616 - * result.append((pos, pos + l)) - * pos += l - * elif op == BAM_CDEL or op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< - * pos += l + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_alignment_start.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1730 + * soft-clipped. + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * return getQueryEnd(self._delegate) * */ - } - __pyx_L6:; - } - /* "pysam/libcalignedsegment.pyx":1619 - * pos += l +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19query_alignment_end_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19query_alignment_end_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19query_alignment_end___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_19query_alignment_end___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int32_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1730, 0, __PYX_ERR(0, 1730, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1731 + * """ + * def __get__(self): + * return getQueryEnd(self._delegate) # <<<<<<<<<<<<<< * - * return result # <<<<<<<<<<<<<< + * property query_alignment_length: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == ((int32_t)-1))) __PYX_ERR(0, 1731, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1731, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":1730 + * soft-clipped. + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * return getQueryEnd(self._delegate) * - * def get_overlap(self, uint32_t start, uint32_t end): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_alignment_end.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1737 + * + * This is equal to :attr:`qend` - :attr:`qstart`""" + * def __get__(self): # <<<<<<<<<<<<<< + * cdef bam1_t * src + * src = self._delegate + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_22query_alignment_length_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_22query_alignment_length_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_22query_alignment_length___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_22query_alignment_length___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + bam1_t *__pyx_v_src; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + bam1_t *__pyx_t_1; + int32_t __pyx_t_2; + int32_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1737, 0, __PYX_ERR(0, 1737, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1739 + * def __get__(self): + * cdef bam1_t * src + * src = self._delegate # <<<<<<<<<<<<<< + * return getQueryEnd(src) - getQueryStart(src) + * + */ + __pyx_t_1 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_1; + + /* "pysam/libcalignedsegment.pyx":1740 + * cdef bam1_t * src + * src = self._delegate + * return getQueryEnd(src) - getQueryStart(src) # <<<<<<<<<<<<<< + * + * ##################################################### */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result); - __pyx_r = __pyx_v_result; + __pyx_t_2 = __pyx_f_5pysam_18libcalignedsegment_getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_2 == ((int32_t)-1))) __PYX_ERR(0, 1740, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_3 == ((int32_t)-1))) __PYX_ERR(0, 1740, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int32_t((__pyx_t_2 - __pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1740, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1583 - * return result + /* "pysam/libcalignedsegment.pyx":1737 * - * def get_blocks(self): # <<<<<<<<<<<<<< - * """ a list of start and end positions of - * aligned gapless blocks. + * This is equal to :attr:`qend` - :attr:`qstart`""" + * def __get__(self): # <<<<<<<<<<<<<< + * cdef bam1_t * src + * src = self._delegate */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_blocks", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query_alignment_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1621 - * return result +/* "pysam/libcalignedsegment.pyx":1745 + * # Computed properties + * + * def get_reference_positions(self, full_length=False): # <<<<<<<<<<<<<< + * """a list of reference positions that this read aligns to. * - * def get_overlap(self, uint32_t start, uint32_t end): # <<<<<<<<<<<<<< - * """return number of aligned bases of read overlapping the interval - * *start* and *end* on the reference sequence. */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_29get_overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_28get_overlap[] = "AlignedSegment.get_overlap(self, uint32_t start, uint32_t end)\nreturn number of aligned bases of read overlapping the interval\n *start* and *end* on the reference sequence.\n\n Return None if cigar alignment is not available.\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_29get_overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - uint32_t __pyx_v_start; - uint32_t __pyx_v_end; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_27get_reference_positions(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_26get_reference_positions[] = "AlignedSegment.get_reference_positions(self, full_length=False)\na list of reference positions that this read aligns to.\n\n By default, this method only returns positions in the\n reference that are within the alignment. If *full_length* is\n set, None values will be included for any soft-clipped or\n unaligned positions within the read. The returned list will\n thus be of the same length as the read.\n\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_27get_reference_positions(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_full_length = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_overlap (wrapper)", 0); + __Pyx_RefNannySetupContext("get_reference_positions (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_start,&__pyx_n_s_end,0}; - PyObject* values[2] = {0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_full_length,0}; + PyObject* values[1] = {0}; + values[0] = ((PyObject *)Py_False); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; @@ -18997,159 +21896,159 @@ static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_29get_ove kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("get_overlap", 1, 2, 2, 1); __PYX_ERR(0, 1621, __pyx_L3_error) + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_full_length); + if (value) { values[0] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_overlap") < 0)) __PYX_ERR(0, 1621, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_reference_positions") < 0)) __PYX_ERR(0, 1745, __pyx_L3_error) } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } } - __pyx_v_start = __Pyx_PyInt_As_uint32_t(values[0]); if (unlikely((__pyx_v_start == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1621, __pyx_L3_error) - __pyx_v_end = __Pyx_PyInt_As_uint32_t(values[1]); if (unlikely((__pyx_v_end == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1621, __pyx_L3_error) + __pyx_v_full_length = values[0]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_overlap", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1621, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get_reference_positions", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1745, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_overlap", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_reference_positions", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_28get_overlap(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_start, __pyx_v_end); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_26get_reference_positions(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_full_length); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_28get_overlap(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, uint32_t __pyx_v_start, uint32_t __pyx_v_end) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_26get_reference_positions(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_full_length) { uint32_t __pyx_v_k; + uint32_t __pyx_v_i; + uint32_t __pyx_v_l; uint32_t __pyx_v_pos; - uint32_t __pyx_v_overlap; int __pyx_v_op; - int __pyx_v_o; uint32_t *__pyx_v_cigar_p; bam1_t *__pyx_v_src; - PyObject *__pyx_v_l = NULL; + int __pyx_v__full; + PyObject *__pyx_v_result = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; - int __pyx_t_2; - int32_t __pyx_t_3; - uint16_t __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - uint32_t __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - uint32_t __pyx_t_10; - uint32_t __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - __Pyx_RefNannySetupContext("get_overlap", 0); - __Pyx_TraceCall("get_overlap", __pyx_f[0], 1621, 0, __PYX_ERR(0, 1621, __pyx_L1_error)); + int __pyx_t_1; + bam1_t *__pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int32_t __pyx_t_4; + uint32_t __pyx_t_5; + int __pyx_t_6; + uint32_t __pyx_t_7; + int __pyx_t_8; + __Pyx_RefNannySetupContext("get_reference_positions", 0); + __Pyx_TraceCall("get_reference_positions", __pyx_f[0], 1745, 0, __PYX_ERR(0, 1745, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1632 + /* "pysam/libcalignedsegment.pyx":1759 + * cdef uint32_t * cigar_p * cdef bam1_t * src - * - * overlap = 0 # <<<<<<<<<<<<<< + * cdef bint _full = full_length # <<<<<<<<<<<<<< * * src = self._delegate */ - __pyx_v_overlap = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_full_length); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1759, __pyx_L1_error) + __pyx_v__full = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":1634 - * overlap = 0 + /* "pysam/libcalignedsegment.pyx":1761 + * cdef bint _full = full_length * * src = self._delegate # <<<<<<<<<<<<<< * if pysam_get_n_cigar(src) == 0: - * return None + * return [] */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; + __pyx_t_2 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_2; - /* "pysam/libcalignedsegment.pyx":1635 + /* "pysam/libcalignedsegment.pyx":1762 * * src = self._delegate * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return None - * pos = src.core.pos + * return [] + * */ - __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); - if (__pyx_t_2) { + __pyx_t_1 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1636 + /* "pysam/libcalignedsegment.pyx":1763 * src = self._delegate * if pysam_get_n_cigar(src) == 0: - * return None # <<<<<<<<<<<<<< - * pos = src.core.pos - * o = 0 + * return [] # <<<<<<<<<<<<<< + * + * result = [] */ __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1635 + /* "pysam/libcalignedsegment.pyx":1762 * * src = self._delegate * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return None - * pos = src.core.pos + * return [] + * */ } - /* "pysam/libcalignedsegment.pyx":1637 - * if pysam_get_n_cigar(src) == 0: - * return None - * pos = src.core.pos # <<<<<<<<<<<<<< - * o = 0 + /* "pysam/libcalignedsegment.pyx":1765 + * return [] * + * result = [] # <<<<<<<<<<<<<< + * pos = src.core.pos + * cigar_p = pysam_bam_get_cigar(src) */ - __pyx_t_3 = __pyx_v_src->core.pos; - __pyx_v_pos = __pyx_t_3; + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_result = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1638 - * return None - * pos = src.core.pos - * o = 0 # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1766 * + * result = [] + * pos = src.core.pos # <<<<<<<<<<<<<< * cigar_p = pysam_bam_get_cigar(src) + * */ - __pyx_v_o = 0; + __pyx_t_4 = __pyx_v_src->core.pos; + __pyx_v_pos = __pyx_t_4; - /* "pysam/libcalignedsegment.pyx":1640 - * o = 0 - * + /* "pysam/libcalignedsegment.pyx":1767 + * result = [] + * pos = src.core.pos * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + * * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK */ __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":1641 - * + /* "pysam/libcalignedsegment.pyx":1769 * cigar_p = pysam_bam_get_cigar(src) + * * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< * op = cigar_p[k] & BAM_CIGAR_MASK * l = cigar_p[k] >> BAM_CIGAR_SHIFT */ - __pyx_t_4 = pysam_get_n_cigar(__pyx_v_src); - for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_4; __pyx_v_k++) { + __pyx_t_5 = pysam_get_n_cigar(__pyx_v_src); + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) { - /* "pysam/libcalignedsegment.pyx":1642 - * cigar_p = pysam_bam_get_cigar(src) + /* "pysam/libcalignedsegment.pyx":1770 + * * for k from 0 <= k < pysam_get_n_cigar(src): * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< * l = cigar_p[k] >> BAM_CIGAR_SHIFT @@ -19157,633 +22056,744 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_28get_ove */ __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); - /* "pysam/libcalignedsegment.pyx":1643 + /* "pysam/libcalignedsegment.pyx":1771 * for k from 0 <= k < pysam_get_n_cigar(src): * op = cigar_p[k] & BAM_CIGAR_MASK * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< * - * if op == BAM_CMATCH: + * if op == BAM_CSOFT_CLIP or op == BAM_CINS: */ - __pyx_t_5 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1643, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_5); - __pyx_t_5 = 0; + __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT); - /* "pysam/libcalignedsegment.pyx":1645 + /* "pysam/libcalignedsegment.pyx":1773 * l = cigar_p[k] >> BAM_CIGAR_SHIFT * - * if op == BAM_CMATCH: # <<<<<<<<<<<<<< - * o = min( pos + l, end) - max( pos, start ) - * if o > 0: overlap += o + * if op == BAM_CSOFT_CLIP or op == BAM_CINS: # <<<<<<<<<<<<<< + * if _full: + * for i from 0 <= i < l: */ - __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0); - if (__pyx_t_2) { + __pyx_t_6 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_1 = __pyx_t_6; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_op == BAM_CINS) != 0); + __pyx_t_1 = __pyx_t_6; + __pyx_L7_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1646 - * - * if op == BAM_CMATCH: - * o = min( pos + l, end) - max( pos, start ) # <<<<<<<<<<<<<< - * if o > 0: overlap += o + /* "pysam/libcalignedsegment.pyx":1774 * + * if op == BAM_CSOFT_CLIP or op == BAM_CINS: + * if _full: # <<<<<<<<<<<<<< + * for i from 0 <= i < l: + * result.append(None) */ - __pyx_t_6 = __pyx_v_end; - __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1646, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = PyNumber_Add(__pyx_t_5, __pyx_v_l); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1646, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1646, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = PyObject_RichCompare(__pyx_t_8, __pyx_t_7, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1646, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1646, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (__pyx_t_2) { - __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1646, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_5 = __pyx_t_9; - __pyx_t_9 = 0; - } else { - __Pyx_INCREF(__pyx_t_7); - __pyx_t_5 = __pyx_t_7; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_6 = __pyx_v_start; - __pyx_t_10 = __pyx_v_pos; - if (((__pyx_t_6 > __pyx_t_10) != 0)) { - __pyx_t_11 = __pyx_t_6; - } else { - __pyx_t_11 = __pyx_t_10; - } - __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1646, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = PyNumber_Subtract(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1646, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1646, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_o = __pyx_t_12; + __pyx_t_1 = (__pyx_v__full != 0); + if (__pyx_t_1) { - /* "pysam/libcalignedsegment.pyx":1647 - * if op == BAM_CMATCH: - * o = min( pos + l, end) - max( pos, start ) - * if o > 0: overlap += o # <<<<<<<<<<<<<< - * - * if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP: + /* "pysam/libcalignedsegment.pyx":1775 + * if op == BAM_CSOFT_CLIP or op == BAM_CINS: + * if _full: + * for i from 0 <= i < l: # <<<<<<<<<<<<<< + * result.append(None) + * elif op == BAM_CMATCH: */ - __pyx_t_2 = ((__pyx_v_o > 0) != 0); - if (__pyx_t_2) { - __pyx_v_overlap = (__pyx_v_overlap + __pyx_v_o); - } + __pyx_t_7 = __pyx_v_l; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_7; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":1645 - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * - * if op == BAM_CMATCH: # <<<<<<<<<<<<<< - * o = min( pos + l, end) - max( pos, start ) - * if o > 0: overlap += o + /* "pysam/libcalignedsegment.pyx":1776 + * if _full: + * for i from 0 <= i < l: + * result.append(None) # <<<<<<<<<<<<<< + * elif op == BAM_CMATCH: + * for i from pos <= i < pos + l: */ - } + __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, Py_None); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1776, __pyx_L1_error) + } - /* "pysam/libcalignedsegment.pyx":1649 - * if o > 0: overlap += o + /* "pysam/libcalignedsegment.pyx":1774 * - * if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< - * pos += l + * if op == BAM_CSOFT_CLIP or op == BAM_CINS: + * if _full: # <<<<<<<<<<<<<< + * for i from 0 <= i < l: + * result.append(None) + */ + } + + /* "pysam/libcalignedsegment.pyx":1773 + * l = cigar_p[k] >> BAM_CIGAR_SHIFT * + * if op == BAM_CSOFT_CLIP or op == BAM_CINS: # <<<<<<<<<<<<<< + * if _full: + * for i from 0 <= i < l: */ - __pyx_t_13 = ((__pyx_v_op == BAM_CMATCH) != 0); - if (!__pyx_t_13) { - } else { - __pyx_t_2 = __pyx_t_13; - goto __pyx_L9_bool_binop_done; + goto __pyx_L6; } - __pyx_t_13 = ((__pyx_v_op == BAM_CDEL) != 0); - if (!__pyx_t_13) { - } else { - __pyx_t_2 = __pyx_t_13; - goto __pyx_L9_bool_binop_done; + + /* "pysam/libcalignedsegment.pyx":1777 + * for i from 0 <= i < l: + * result.append(None) + * elif op == BAM_CMATCH: # <<<<<<<<<<<<<< + * for i from pos <= i < pos + l: + * result.append(i) + */ + __pyx_t_1 = ((__pyx_v_op == BAM_CMATCH) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":1778 + * result.append(None) + * elif op == BAM_CMATCH: + * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< + * result.append(i) + * pos += l + */ + __pyx_t_7 = (__pyx_v_pos + __pyx_v_l); + for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_7; __pyx_v_i++) { + + /* "pysam/libcalignedsegment.pyx":1779 + * elif op == BAM_CMATCH: + * for i from pos <= i < pos + l: + * result.append(i) # <<<<<<<<<<<<<< + * pos += l + * elif op == BAM_CDEL or op == BAM_CREF_SKIP: + */ + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1779, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1779, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + + /* "pysam/libcalignedsegment.pyx":1780 + * for i from pos <= i < pos + l: + * result.append(i) + * pos += l # <<<<<<<<<<<<<< + * elif op == BAM_CDEL or op == BAM_CREF_SKIP: + * pos += l + */ + __pyx_v_pos = (__pyx_v_pos + __pyx_v_l); + + /* "pysam/libcalignedsegment.pyx":1777 + * for i from 0 <= i < l: + * result.append(None) + * elif op == BAM_CMATCH: # <<<<<<<<<<<<<< + * for i from pos <= i < pos + l: + * result.append(i) + */ + goto __pyx_L6; } - __pyx_t_13 = ((__pyx_v_op == BAM_CREF_SKIP) != 0); - __pyx_t_2 = __pyx_t_13; - __pyx_L9_bool_binop_done:; - if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":1650 + /* "pysam/libcalignedsegment.pyx":1781 + * result.append(i) + * pos += l + * elif op == BAM_CDEL or op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< + * pos += l * - * if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP: + */ + __pyx_t_6 = ((__pyx_v_op == BAM_CDEL) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_1 = __pyx_t_6; + goto __pyx_L14_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_op == BAM_CREF_SKIP) != 0); + __pyx_t_1 = __pyx_t_6; + __pyx_L14_bool_binop_done:; + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":1782 + * pos += l + * elif op == BAM_CDEL or op == BAM_CREF_SKIP: * pos += l # <<<<<<<<<<<<<< * - * return overlap + * return result */ - __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1650, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1650, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_11 = __Pyx_PyInt_As_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_11 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1650, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_pos = __pyx_t_11; + __pyx_v_pos = (__pyx_v_pos + __pyx_v_l); - /* "pysam/libcalignedsegment.pyx":1649 - * if o > 0: overlap += o - * - * if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1781 + * result.append(i) + * pos += l + * elif op == BAM_CDEL or op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< * pos += l * */ } + __pyx_L6:; } - /* "pysam/libcalignedsegment.pyx":1652 + /* "pysam/libcalignedsegment.pyx":1784 * pos += l * - * return overlap # <<<<<<<<<<<<<< + * return result # <<<<<<<<<<<<<< * - * def get_cigar_stats(self): + * def infer_query_length(self, always=False): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_overlap); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1652, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_r = __pyx_t_7; - __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1621 - * return result + /* "pysam/libcalignedsegment.pyx":1745 + * # Computed properties + * + * def get_reference_positions(self, full_length=False): # <<<<<<<<<<<<<< + * """a list of reference positions that this read aligns to. * - * def get_overlap(self, uint32_t start, uint32_t end): # <<<<<<<<<<<<<< - * """return number of aligned bases of read overlapping the interval - * *start* and *end* on the reference sequence. */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_overlap", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_reference_positions", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_l); + __Pyx_XDECREF(__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1654 - * return overlap +/* "pysam/libcalignedsegment.pyx":1786 + * return result * - * def get_cigar_stats(self): # <<<<<<<<<<<<<< - * """summary of operations in cigar string. + * def infer_query_length(self, always=False): # <<<<<<<<<<<<<< + * """infer query length from CIGAR alignment. * */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_31get_cigar_stats(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_30get_cigar_stats[] = "AlignedSegment.get_cigar_stats(self)\nsummary of operations in cigar string.\n\n The output order in the array is \"MIDNSHP=X\" followed by a\n field for the NM tag. If the NM tag is not present, this\n field will always be 0.\n\n +-----+--------------+-----+\n |M |BAM_CMATCH |0 |\n +-----+--------------+-----+\n |I |BAM_CINS |1 |\n +-----+--------------+-----+\n |D |BAM_CDEL |2 |\n +-----+--------------+-----+\n |N |BAM_CREF_SKIP |3 |\n +-----+--------------+-----+\n |S |BAM_CSOFT_CLIP|4 |\n +-----+--------------+-----+\n |H |BAM_CHARD_CLIP|5 |\n +-----+--------------+-----+\n |P |BAM_CPAD |6 |\n +-----+--------------+-----+\n |= |BAM_CEQUAL |7 |\n +-----+--------------+-----+\n |X |BAM_CDIFF |8 |\n +-----+--------------+-----+\n |NM |NM tag |9 |\n +-----+--------------+-----+\n\n If no cigar string is present, empty arrays will be returned.\n\n Parameters\n ----------\n\n Returns\n -------\n\n arrays : two arrays. The first contains the nucleotide counts within\n each cigar operation, the second contains the number of blocks for\n each cigar operation.\n\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_31get_cigar_stats(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_29infer_query_length(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_28infer_query_length[] = "AlignedSegment.infer_query_length(self, always=False)\ninfer query length from CIGAR alignment.\n\n This method deduces the query length from the CIGAR alignment\n but does not include hard-clipped bases.\n\n Returns None if CIGAR alignment is not present.\n\n If *always* is set to True, `infer_read_length` is used instead.\n This is deprecated and only present for backward compatibility.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_29infer_query_length(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_always = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_cigar_stats (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_30get_cigar_stats(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("infer_query_length (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_always,0}; + PyObject* values[1] = {0}; + values[0] = ((PyObject *)Py_False); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_always); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "infer_query_length") < 0)) __PYX_ERR(0, 1786, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_always = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("infer_query_length", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1786, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.infer_query_length", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_28infer_query_length(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_always); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_30get_cigar_stats(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - int __pyx_v_nfields; - arrayobject *__pyx_v_base_counts = 0; - __Pyx_memviewslice __pyx_v_base_view = { 0, 0, { 0 }, { 0 }, { 0 } }; - arrayobject *__pyx_v_block_counts = 0; - __Pyx_memviewslice __pyx_v_block_view = { 0, 0, { 0 }, { 0 }, { 0 } }; - bam1_t *__pyx_v_src; - int __pyx_v_op; - uint32_t __pyx_v_l; - int32_t __pyx_v_k; - uint32_t *__pyx_v_cigar_p; - uint8_t *__pyx_v_v; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_28infer_query_length(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_always) { + int32_t __pyx_v_l; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + int __pyx_t_1; + int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } }; - bam1_t *__pyx_t_8; - int __pyx_t_9; - uint16_t __pyx_t_10; - Py_ssize_t __pyx_t_11; - Py_ssize_t __pyx_t_12; - Py_ssize_t __pyx_t_13; - __Pyx_RefNannySetupContext("get_cigar_stats", 0); - __Pyx_TraceCall("get_cigar_stats", __pyx_f[0], 1654, 0, __PYX_ERR(0, 1654, __pyx_L1_error)); + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("infer_query_length", 0); + __Pyx_TraceCall("infer_query_length", __pyx_f[0], 1786, 0, __PYX_ERR(0, 1786, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1697 + /* "pysam/libcalignedsegment.pyx":1797 + * This is deprecated and only present for backward compatibility. * """ - * - * cdef int nfields = NCIGAR_CODES + 1 # <<<<<<<<<<<<<< - * - * cdef c_array.array base_counts = array.array( - */ - __pyx_v_nfields = (__pyx_v_5pysam_18libcalignedsegment_NCIGAR_CODES + 1); - - /* "pysam/libcalignedsegment.pyx":1699 - * cdef int nfields = NCIGAR_CODES + 1 - * - * cdef c_array.array base_counts = array.array( # <<<<<<<<<<<<<< - * "I", - * [0] * nfields) + * if always is True: # <<<<<<<<<<<<<< + * return self.infer_read_length() + * cdef int32_t l = calculateQueryLengthWithoutHardClipping(self._delegate) */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1699, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1699, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = (__pyx_v_always == Py_True); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":1701 - * cdef c_array.array base_counts = array.array( - * "I", - * [0] * nfields) # <<<<<<<<<<<<<< - * cdef uint32_t [:] base_view = base_counts - * cdef c_array.array block_counts = array.array( + /* "pysam/libcalignedsegment.pyx":1798 + * """ + * if always is True: + * return self.infer_read_length() # <<<<<<<<<<<<<< + * cdef int32_t l = calculateQueryLengthWithoutHardClipping(self._delegate) + * if l > 0: */ - __pyx_t_2 = PyList_New(1 * ((__pyx_v_nfields<0) ? 0:__pyx_v_nfields)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1701, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - { Py_ssize_t __pyx_temp; - for (__pyx_temp=0; __pyx_temp < __pyx_v_nfields; __pyx_temp++) { - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyList_SET_ITEM(__pyx_t_2, __pyx_temp, __pyx_int_0); - } - } - __pyx_t_4 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_5 = 1; + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_infer_read_length); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1798, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_s_I, __pyx_t_2}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1699, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_s_I, __pyx_t_2}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1699, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1699, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + if (__pyx_t_5) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1798, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else { + __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1798, __pyx_L1_error) } - __Pyx_INCREF(__pyx_n_s_I); - __Pyx_GIVEREF(__pyx_n_s_I); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_n_s_I); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1699, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1699 - * cdef int nfields = NCIGAR_CODES + 1 - * - * cdef c_array.array base_counts = array.array( # <<<<<<<<<<<<<< - * "I", - * [0] * nfields) + /* "pysam/libcalignedsegment.pyx":1797 + * This is deprecated and only present for backward compatibility. + * """ + * if always is True: # <<<<<<<<<<<<<< + * return self.infer_read_length() + * cdef int32_t l = calculateQueryLengthWithoutHardClipping(self._delegate) */ - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 1699, __pyx_L1_error) - __pyx_v_base_counts = ((arrayobject *)__pyx_t_1); - __pyx_t_1 = 0; + } - /* "pysam/libcalignedsegment.pyx":1702 - * "I", - * [0] * nfields) - * cdef uint32_t [:] base_view = base_counts # <<<<<<<<<<<<<< - * cdef c_array.array block_counts = array.array( - * "I", + /* "pysam/libcalignedsegment.pyx":1799 + * if always is True: + * return self.infer_read_length() + * cdef int32_t l = calculateQueryLengthWithoutHardClipping(self._delegate) # <<<<<<<<<<<<<< + * if l > 0: + * return l */ - __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn_uint32_t(((PyObject *)__pyx_v_base_counts), PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 1702, __pyx_L1_error) - __pyx_v_base_view = __pyx_t_7; - __pyx_t_7.memview = NULL; - __pyx_t_7.data = NULL; + __pyx_v_l = __pyx_f_5pysam_18libcalignedsegment_calculateQueryLengthWithoutHardClipping(__pyx_v_self->_delegate); - /* "pysam/libcalignedsegment.pyx":1703 - * [0] * nfields) - * cdef uint32_t [:] base_view = base_counts - * cdef c_array.array block_counts = array.array( # <<<<<<<<<<<<<< - * "I", - * [0] * nfields) + /* "pysam/libcalignedsegment.pyx":1800 + * return self.infer_read_length() + * cdef int32_t l = calculateQueryLengthWithoutHardClipping(self._delegate) + * if l > 0: # <<<<<<<<<<<<<< + * return l + * else: */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1703, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1703, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_2 = ((__pyx_v_l > 0) != 0); + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":1705 - * cdef c_array.array block_counts = array.array( - * "I", - * [0] * nfields) # <<<<<<<<<<<<<< - * cdef uint32_t [:] block_view = block_counts - * + /* "pysam/libcalignedsegment.pyx":1801 + * cdef int32_t l = calculateQueryLengthWithoutHardClipping(self._delegate) + * if l > 0: + * return l # <<<<<<<<<<<<<< + * else: + * return None */ - __pyx_t_3 = PyList_New(1 * ((__pyx_v_nfields<0) ? 0:__pyx_v_nfields)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1705, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - { Py_ssize_t __pyx_temp; - for (__pyx_temp=0; __pyx_temp < __pyx_v_nfields; __pyx_temp++) { - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyList_SET_ITEM(__pyx_t_3, __pyx_temp, __pyx_int_0); - } - } - __pyx_t_2 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - __pyx_t_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_n_s_I, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1703, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_n_s_I, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1703, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1703, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (__pyx_t_2) { - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL; - } - __Pyx_INCREF(__pyx_n_s_I); - __Pyx_GIVEREF(__pyx_n_s_I); - PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_5, __pyx_n_s_I); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_5, __pyx_t_3); + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_l); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1801, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1703, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1703 - * [0] * nfields) - * cdef uint32_t [:] base_view = base_counts - * cdef c_array.array block_counts = array.array( # <<<<<<<<<<<<<< - * "I", - * [0] * nfields) + /* "pysam/libcalignedsegment.pyx":1800 + * return self.infer_read_length() + * cdef int32_t l = calculateQueryLengthWithoutHardClipping(self._delegate) + * if l > 0: # <<<<<<<<<<<<<< + * return l + * else: */ - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 1703, __pyx_L1_error) - __pyx_v_block_counts = ((arrayobject *)__pyx_t_1); - __pyx_t_1 = 0; + } - /* "pysam/libcalignedsegment.pyx":1706 - * "I", - * [0] * nfields) - * cdef uint32_t [:] block_view = block_counts # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1803 + * return l + * else: + * return None # <<<<<<<<<<<<<< * - * cdef bam1_t * src = self._delegate + * def infer_read_length(self): */ - __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn_uint32_t(((PyObject *)__pyx_v_block_counts), PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 1706, __pyx_L1_error) - __pyx_v_block_view = __pyx_t_7; - __pyx_t_7.memview = NULL; - __pyx_t_7.data = NULL; + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + } - /* "pysam/libcalignedsegment.pyx":1708 - * cdef uint32_t [:] block_view = block_counts + /* "pysam/libcalignedsegment.pyx":1786 + * return result + * + * def infer_query_length(self, always=False): # <<<<<<<<<<<<<< + * """infer query length from CIGAR alignment. * - * cdef bam1_t * src = self._delegate # <<<<<<<<<<<<<< - * cdef int op - * cdef uint32_t l */ - __pyx_t_8 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_8; - /* "pysam/libcalignedsegment.pyx":1712 - * cdef uint32_t l - * cdef int32_t k - * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.infer_query_length", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1805 + * return None + * + * def infer_read_length(self): # <<<<<<<<<<<<<< + * """infer read length from CIGAR alignment. * - * if cigar_p == NULL: */ - __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":1714 - * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) - * - * if cigar_p == NULL: # <<<<<<<<<<<<<< +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_31infer_read_length(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_30infer_read_length[] = "AlignedSegment.infer_read_length(self)\ninfer read length from CIGAR alignment.\n\n This method deduces the read length from the CIGAR alignment\n including hard-clipped bases.\n\n Returns None if CIGAR alignment is not present.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_31infer_read_length(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("infer_read_length (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_30infer_read_length(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_30infer_read_length(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + int32_t __pyx_v_l; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("infer_read_length", 0); + __Pyx_TraceCall("infer_read_length", __pyx_f[0], 1805, 0, __PYX_ERR(0, 1805, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1813 + * Returns None if CIGAR alignment is not present. + * """ + * cdef int32_t l = calculateQueryLengthWithHardClipping(self._delegate) # <<<<<<<<<<<<<< + * if l > 0: + * return l + */ + __pyx_v_l = __pyx_f_5pysam_18libcalignedsegment_calculateQueryLengthWithHardClipping(__pyx_v_self->_delegate); + + /* "pysam/libcalignedsegment.pyx":1814 + * """ + * cdef int32_t l = calculateQueryLengthWithHardClipping(self._delegate) + * if l > 0: # <<<<<<<<<<<<<< + * return l + * else: + */ + __pyx_t_1 = ((__pyx_v_l > 0) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":1815 + * cdef int32_t l = calculateQueryLengthWithHardClipping(self._delegate) + * if l > 0: + * return l # <<<<<<<<<<<<<< + * else: * return None - * */ - __pyx_t_9 = ((__pyx_v_cigar_p == NULL) != 0); - if (__pyx_t_9) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_v_l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1815, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1715 - * - * if cigar_p == NULL: + /* "pysam/libcalignedsegment.pyx":1814 + * """ + * cdef int32_t l = calculateQueryLengthWithHardClipping(self._delegate) + * if l > 0: # <<<<<<<<<<<<<< + * return l + * else: + */ + } + + /* "pysam/libcalignedsegment.pyx":1817 + * return l + * else: * return None # <<<<<<<<<<<<<< * - * for k from 0 <= k < pysam_get_n_cigar(src): + * def get_reference_sequence(self): */ + /*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; + } - /* "pysam/libcalignedsegment.pyx":1714 - * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) - * - * if cigar_p == NULL: # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1805 * return None * + * def infer_read_length(self): # <<<<<<<<<<<<<< + * """infer read length from CIGAR alignment. + * */ - } - /* "pysam/libcalignedsegment.pyx":1717 + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.infer_read_length", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1819 * return None * - * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * def get_reference_sequence(self): # <<<<<<<<<<<<<< + * """return the reference sequence in the region that is covered by the + * alignment of the read to the reference. */ - __pyx_t_10 = pysam_get_n_cigar(__pyx_v_src); - for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_10; __pyx_v_k++) { - /* "pysam/libcalignedsegment.pyx":1718 - * - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * base_view[op] += l - */ - __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_33get_reference_sequence(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_32get_reference_sequence[] = "AlignedSegment.get_reference_sequence(self)\nreturn the reference sequence in the region that is covered by the\n alignment of the read to the reference.\n\n This method requires the MD tag to be set.\n\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_33get_reference_sequence(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_reference_sequence (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_32get_reference_sequence(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - /* "pysam/libcalignedsegment.pyx":1719 - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< - * base_view[op] += l - * block_view[op] += 1 - */ - __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT); + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":1720 - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * base_view[op] += l # <<<<<<<<<<<<<< - * block_view[op] += 1 - * - */ - __pyx_t_11 = __pyx_v_op; - __pyx_t_5 = -1; - if (__pyx_t_11 < 0) { - __pyx_t_11 += __pyx_v_base_view.shape[0]; - if (unlikely(__pyx_t_11 < 0)) __pyx_t_5 = 0; - } else if (unlikely(__pyx_t_11 >= __pyx_v_base_view.shape[0])) __pyx_t_5 = 0; - if (unlikely(__pyx_t_5 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_5); - __PYX_ERR(0, 1720, __pyx_L1_error) - } - *((uint32_t *) ( /* dim=0 */ (__pyx_v_base_view.data + __pyx_t_11 * __pyx_v_base_view.strides[0]) )) += __pyx_v_l; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_32get_reference_sequence(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("get_reference_sequence", 0); + __Pyx_TraceCall("get_reference_sequence", __pyx_f[0], 1819, 0, __PYX_ERR(0, 1819, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1721 - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * base_view[op] += l - * block_view[op] += 1 # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1826 * - * cdef uint8_t * v = bam_aux_get(src, 'NM') + * """ + * return force_str(build_reference_sequence(self._delegate)) # <<<<<<<<<<<<<< + * + * def get_forward_sequence(self): */ - __pyx_t_12 = __pyx_v_op; - __pyx_t_5 = -1; - if (__pyx_t_12 < 0) { - __pyx_t_12 += __pyx_v_block_view.shape[0]; - if (unlikely(__pyx_t_12 < 0)) __pyx_t_5 = 0; - } else if (unlikely(__pyx_t_12 >= __pyx_v_block_view.shape[0])) __pyx_t_5 = 0; - if (unlikely(__pyx_t_5 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_5); - __PYX_ERR(0, 1721, __pyx_L1_error) - } - *((uint32_t *) ( /* dim=0 */ (__pyx_v_block_view.data + __pyx_t_12 * __pyx_v_block_view.strides[0]) )) += 1; - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_build_reference_sequence(__pyx_v_self->_delegate); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1826, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1826, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1723 - * block_view[op] += 1 + /* "pysam/libcalignedsegment.pyx":1819 + * return None * - * cdef uint8_t * v = bam_aux_get(src, 'NM') # <<<<<<<<<<<<<< - * if v != NULL: - * base_view[nfields - 1] = bam_aux2i(v) + * def get_reference_sequence(self): # <<<<<<<<<<<<<< + * """return the reference sequence in the region that is covered by the + * alignment of the read to the reference. */ - __pyx_v_v = bam_aux_get(__pyx_v_src, ((char const *)"NM")); - /* "pysam/libcalignedsegment.pyx":1724 + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_reference_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1828 + * return force_str(build_reference_sequence(self._delegate)) * - * cdef uint8_t * v = bam_aux_get(src, 'NM') - * if v != NULL: # <<<<<<<<<<<<<< - * base_view[nfields - 1] = bam_aux2i(v) + * def get_forward_sequence(self): # <<<<<<<<<<<<<< + * """return the original read sequence. * */ - __pyx_t_9 = ((__pyx_v_v != NULL) != 0); - if (__pyx_t_9) { - /* "pysam/libcalignedsegment.pyx":1725 - * cdef uint8_t * v = bam_aux_get(src, 'NM') - * if v != NULL: - * base_view[nfields - 1] = bam_aux2i(v) # <<<<<<<<<<<<<< +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_35get_forward_sequence(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_34get_forward_sequence[] = "AlignedSegment.get_forward_sequence(self)\nreturn the original read sequence.\n \n Reads mapping to the reverse strand will be reverse\n complemented.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_35get_forward_sequence(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_forward_sequence (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_34get_forward_sequence(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_34get_forward_sequence(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_v_s = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannySetupContext("get_forward_sequence", 0); + __Pyx_TraceCall("get_forward_sequence", __pyx_f[0], 1828, 0, __PYX_ERR(0, 1828, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1834 + * complemented. + * """ + * s = force_str(self.query_sequence) # <<<<<<<<<<<<<< + * if self.is_reverse: + * s = s.translate(maketrans("ACGTacgtNnXx", "TGCAtgcaNnXx"))[::-1] + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1834, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1834, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_s = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pysam/libcalignedsegment.pyx":1835 + * """ + * s = force_str(self.query_sequence) + * if self.is_reverse: # <<<<<<<<<<<<<< + * s = s.translate(maketrans("ACGTacgtNnXx", "TGCAtgcaNnXx"))[::-1] + * return s + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_reverse); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1835, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1835, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":1836 + * s = force_str(self.query_sequence) + * if self.is_reverse: + * s = s.translate(maketrans("ACGTacgtNnXx", "TGCAtgcaNnXx"))[::-1] # <<<<<<<<<<<<<< + * return s * - * return base_counts, block_counts */ - __pyx_t_13 = (__pyx_v_nfields - 1); - __pyx_t_5 = -1; - if (__pyx_t_13 < 0) { - __pyx_t_13 += __pyx_v_base_view.shape[0]; - if (unlikely(__pyx_t_13 < 0)) __pyx_t_5 = 0; - } else if (unlikely(__pyx_t_13 >= __pyx_v_base_view.shape[0])) __pyx_t_5 = 0; - if (unlikely(__pyx_t_5 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_5); - __PYX_ERR(0, 1725, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_translate); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1836, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_maketrans); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1836, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1836, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } } - *((uint32_t *) ( /* dim=0 */ (__pyx_v_base_view.data + __pyx_t_13 * __pyx_v_base_view.strides[0]) )) = ((int32_t)bam_aux2i(__pyx_v_v)); + if (!__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1836, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1836, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1836, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1836, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1836, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_slice__31); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1836, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":1724 - * - * cdef uint8_t * v = bam_aux_get(src, 'NM') - * if v != NULL: # <<<<<<<<<<<<<< - * base_view[nfields - 1] = bam_aux2i(v) - * + /* "pysam/libcalignedsegment.pyx":1835 + * """ + * s = force_str(self.query_sequence) + * if self.is_reverse: # <<<<<<<<<<<<<< + * s = s.translate(maketrans("ACGTacgtNnXx", "TGCAtgcaNnXx"))[::-1] + * return s */ } - /* "pysam/libcalignedsegment.pyx":1727 - * base_view[nfields - 1] = bam_aux2i(v) - * - * return base_counts, block_counts # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1837 + * if self.is_reverse: + * s = s.translate(maketrans("ACGTacgtNnXx", "TGCAtgcaNnXx"))[::-1] + * return s # <<<<<<<<<<<<<< * - * ##################################################### + * def get_forward_qualities(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1727, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_base_counts)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_base_counts)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_base_counts)); - __Pyx_INCREF(((PyObject *)__pyx_v_block_counts)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_block_counts)); - PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_block_counts)); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __Pyx_INCREF(__pyx_v_s); + __pyx_r = __pyx_v_s; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1654 - * return overlap + /* "pysam/libcalignedsegment.pyx":1828 + * return force_str(build_reference_sequence(self._delegate)) * - * def get_cigar_stats(self): # <<<<<<<<<<<<<< - * """summary of operations in cigar string. + * def get_forward_sequence(self): # <<<<<<<<<<<<<< + * """return the original read sequence. * */ @@ -19791,1579 +22801,1445 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_30get_cig __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_cigar_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_forward_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_base_counts); - __PYX_XDEC_MEMVIEW(&__pyx_v_base_view, 1); - __Pyx_XDECREF((PyObject *)__pyx_v_block_counts); - __PYX_XDEC_MEMVIEW(&__pyx_v_block_view, 1); + __Pyx_XDECREF(__pyx_v_s); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1770 - * or None. - * """ - * def __get__(self): # <<<<<<<<<<<<<< - * cdef uint32_t * cigar_p - * cdef bam1_t * src +/* "pysam/libcalignedsegment.pyx":1839 + * return s + * + * def get_forward_qualities(self): # <<<<<<<<<<<<<< + * """return the original read sequence. + * */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_37get_forward_qualities(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_36get_forward_qualities[] = "AlignedSegment.get_forward_qualities(self)\nreturn the original read sequence.\n \n Reads mapping to the reverse strand will be reverse\n complemented.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_37get_forward_qualities(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("get_forward_qualities (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_36get_forward_qualities(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - uint32_t *__pyx_v_cigar_p; - bam1_t *__pyx_v_src; - uint32_t __pyx_v_op; - uint32_t __pyx_v_l; - int __pyx_v_k; - PyObject *__pyx_v_cigar = NULL; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_36get_forward_qualities(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; + PyObject *__pyx_t_1 = NULL; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; - uint16_t __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1770, 0, __PYX_ERR(0, 1770, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":1776 - * cdef int k - * - * src = self._delegate # <<<<<<<<<<<<<< - * if pysam_get_n_cigar(src) == 0: - * return None - */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; + __Pyx_RefNannySetupContext("get_forward_qualities", 0); + __Pyx_TraceCall("get_forward_qualities", __pyx_f[0], 1839, 0, __PYX_ERR(0, 1839, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1777 - * - * src = self._delegate - * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return None - * + /* "pysam/libcalignedsegment.pyx":1845 + * complemented. + * """ + * if self.is_reverse: # <<<<<<<<<<<<<< + * return self.query_qualities[::-1] + * else: */ - __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_reverse); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1845, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1845, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":1778 - * src = self._delegate - * if pysam_get_n_cigar(src) == 0: - * return None # <<<<<<<<<<<<<< - * - * cigar = [] + /* "pysam/libcalignedsegment.pyx":1846 + * """ + * if self.is_reverse: + * return self.query_qualities[::-1] # <<<<<<<<<<<<<< + * else: + * return self.query_qualities */ __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1846, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_slice__32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1846, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1777 - * - * src = self._delegate - * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< - * return None - * + /* "pysam/libcalignedsegment.pyx":1845 + * complemented. + * """ + * if self.is_reverse: # <<<<<<<<<<<<<< + * return self.query_qualities[::-1] + * else: */ } - /* "pysam/libcalignedsegment.pyx":1780 - * return None - * - * cigar = [] # <<<<<<<<<<<<<< - * - * cigar_p = pysam_bam_get_cigar(src); - */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1780, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_cigar = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pysam/libcalignedsegment.pyx":1782 - * cigar = [] - * - * cigar_p = pysam_bam_get_cigar(src); # <<<<<<<<<<<<<< - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK - */ - __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - - /* "pysam/libcalignedsegment.pyx":1783 + /* "pysam/libcalignedsegment.pyx":1848 + * return self.query_qualities[::-1] + * else: + * return self.query_qualities # <<<<<<<<<<<<<< * - * cigar_p = pysam_bam_get_cigar(src); - * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - */ - __pyx_t_4 = pysam_get_n_cigar(__pyx_v_src); - for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_4; __pyx_v_k++) { - - /* "pysam/libcalignedsegment.pyx":1784 - * cigar_p = pysam_bam_get_cigar(src); - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * cigar.append((op, l)) - */ - __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); - - /* "pysam/libcalignedsegment.pyx":1785 - * for k from 0 <= k < pysam_get_n_cigar(src): - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< - * cigar.append((op, l)) - * return cigar - */ - __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT); - - /* "pysam/libcalignedsegment.pyx":1786 - * op = cigar_p[k] & BAM_CIGAR_MASK - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * cigar.append((op, l)) # <<<<<<<<<<<<<< - * return cigar * */ - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_op); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1786, __pyx_L1_error) + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1848, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_l); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1786, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1786, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __pyx_r = __pyx_t_3; __pyx_t_3 = 0; - __pyx_t_5 = 0; - __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_cigar, __pyx_t_6); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 1786, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L0; } - /* "pysam/libcalignedsegment.pyx":1787 - * l = cigar_p[k] >> BAM_CIGAR_SHIFT - * cigar.append((op, l)) - * return cigar # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1839 + * return s + * + * def get_forward_qualities(self): # <<<<<<<<<<<<<< + * """return the original read sequence. * - * def __set__(self, values): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_cigar); - __pyx_r = __pyx_v_cigar; - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":1770 - * or None. - * """ - * def __get__(self): # <<<<<<<<<<<<<< - * cdef uint32_t * cigar_p - * cdef bam1_t * src */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.cigartuples.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_forward_qualities", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_cigar); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1789 - * return cigar +/* "pysam/libcalignedsegment.pyx":1851 + * + * + * def get_aligned_pairs(self, matches_only=False, with_seq=False): # <<<<<<<<<<<<<< + * """a list of aligned read (query) and reference positions. * - * def __set__(self, values): # <<<<<<<<<<<<<< - * cdef uint32_t * p - * cdef bam1_t * src */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_39get_aligned_pairs(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_38get_aligned_pairs[] = "AlignedSegment.get_aligned_pairs(self, matches_only=False, with_seq=False)\na list of aligned read (query) and reference positions.\n\n For inserts, deletions, skipping either query or reference\n position may be None.\n\n Padding is currently not supported and leads to an exception.\n\n Parameters\n ----------\n\n matches_only : bool\n If True, only matched bases are returned - no None on either\n side.\n with_seq : bool\n If True, return a third element in the tuple containing the\n reference sequence. Substitutions are lower-case. This option\n requires an MD tag to be present.\n\n Returns\n -------\n\n aligned_pairs : list of tuples\n\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_39get_aligned_pairs(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_matches_only = 0; + PyObject *__pyx_v_with_seq = 0; + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_values)); + __Pyx_RefNannySetupContext("get_aligned_pairs (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_matches_only,&__pyx_n_s_with_seq,0}; + PyObject* values[2] = {0,0}; + values[0] = ((PyObject *)Py_False); + values[1] = ((PyObject *)Py_False); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_matches_only); + if (value) { values[0] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_with_seq); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_aligned_pairs") < 0)) __PYX_ERR(0, 1851, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_matches_only = values[0]; + __pyx_v_with_seq = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_aligned_pairs", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1851, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_aligned_pairs", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_38get_aligned_pairs(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_matches_only, __pyx_v_with_seq); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_values) { - uint32_t *__pyx_v_p; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_38get_aligned_pairs(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_matches_only, PyObject *__pyx_v_with_seq) { + uint32_t __pyx_v_k; + uint32_t __pyx_v_i; + uint32_t __pyx_v_pos; + uint32_t __pyx_v_qpos; + uint32_t __pyx_v_r_idx; + uint32_t __pyx_v_l; + int __pyx_v_op; + uint32_t *__pyx_v_cigar_p; bam1_t *__pyx_v_src; - PyObject *__pyx_v_op = 0; - PyObject *__pyx_v_l = 0; - int __pyx_v_k; - int __pyx_v_ncigar; - int __pyx_r; + int __pyx_v__matches_only; + int __pyx_v__with_seq; + PyObject *__pyx_v_ref_seq = NULL; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations bam1_t *__pyx_t_1; int __pyx_t_2; - int __pyx_t_3; + PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - Py_ssize_t __pyx_t_5; - PyObject *(*__pyx_t_6)(PyObject *); - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; + int __pyx_t_5; + int32_t __pyx_t_6; + uint32_t __pyx_t_7; + uint32_t __pyx_t_8; PyObject *__pyx_t_9 = NULL; PyObject *__pyx_t_10 = NULL; - PyObject *(*__pyx_t_11)(PyObject *); - uint32_t __pyx_t_12; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 1789, 0, __PYX_ERR(0, 1789, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_values); - - /* "pysam/libcalignedsegment.pyx":1795 - * cdef int k, ncigar - * - * k = 0 # <<<<<<<<<<<<<< - * - * src = self._delegate - */ - __pyx_v_k = 0; + int __pyx_t_11; + __Pyx_RefNannySetupContext("get_aligned_pairs", 0); + __Pyx_TraceCall("get_aligned_pairs", __pyx_f[0], 1851, 0, __PYX_ERR(0, 1851, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":1797 - * k = 0 - * - * src = self._delegate # <<<<<<<<<<<<<< - * - * # get location of cigar string + /* "pysam/libcalignedsegment.pyx":1879 + * cdef int op + * cdef uint32_t * cigar_p + * cdef bam1_t * src = self._delegate # <<<<<<<<<<<<<< + * cdef bint _matches_only = bool(matches_only) + * cdef bint _with_seq = bool(with_seq) */ __pyx_t_1 = __pyx_v_self->_delegate; __pyx_v_src = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":1800 - * - * # get location of cigar string - * p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1880 + * cdef uint32_t * cigar_p + * cdef bam1_t * src = self._delegate + * cdef bint _matches_only = bool(matches_only) # <<<<<<<<<<<<<< + * cdef bint _with_seq = bool(with_seq) * - * # empty values for cigar string */ - __pyx_v_p = pysam_bam_get_cigar(__pyx_v_src); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_matches_only); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1880, __pyx_L1_error) + __pyx_v__matches_only = (!(!__pyx_t_2)); - /* "pysam/libcalignedsegment.pyx":1803 - * - * # empty values for cigar string - * if values is None: # <<<<<<<<<<<<<< - * values = [] + /* "pysam/libcalignedsegment.pyx":1881 + * cdef bam1_t * src = self._delegate + * cdef bint _matches_only = bool(matches_only) + * cdef bint _with_seq = bool(with_seq) # <<<<<<<<<<<<<< * + * # TODO: this method performs no checking and assumes that */ - __pyx_t_2 = (__pyx_v_values == Py_None); - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_with_seq); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1881, __pyx_L1_error) + __pyx_v__with_seq = (!(!__pyx_t_2)); - /* "pysam/libcalignedsegment.pyx":1804 - * # empty values for cigar string - * if values is None: - * values = [] # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1886 + * # read sequence, cigar and MD tag are consistent. * - * ncigar = len(values) + * if _with_seq: # <<<<<<<<<<<<<< + * # force_str required for py2/py3 compatibility + * ref_seq = force_str(build_reference_sequence(src)) + */ + __pyx_t_2 = (__pyx_v__with_seq != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":1888 + * if _with_seq: + * # force_str required for py2/py3 compatibility + * ref_seq = force_str(build_reference_sequence(src)) # <<<<<<<<<<<<<< + * if ref_seq is None: + * raise ValueError("MD tag not present") */ - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1804, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_build_reference_sequence(__pyx_v_src); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1888, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF_SET(__pyx_v_values, __pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_ref_seq = __pyx_t_4; __pyx_t_4 = 0; - /* "pysam/libcalignedsegment.pyx":1803 + /* "pysam/libcalignedsegment.pyx":1889 + * # force_str required for py2/py3 compatibility + * ref_seq = force_str(build_reference_sequence(src)) + * if ref_seq is None: # <<<<<<<<<<<<<< + * raise ValueError("MD tag not present") * - * # empty values for cigar string - * if values is None: # <<<<<<<<<<<<<< - * values = [] + */ + __pyx_t_2 = (__pyx_v_ref_seq == Py_None); + __pyx_t_5 = (__pyx_t_2 != 0); + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcalignedsegment.pyx":1890 + * ref_seq = force_str(build_reference_sequence(src)) + * if ref_seq is None: + * raise ValueError("MD tag not present") # <<<<<<<<<<<<<< * + * r_idx = 0 */ - } + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1890, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 1890, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":1806 - * values = [] + /* "pysam/libcalignedsegment.pyx":1889 + * # force_str required for py2/py3 compatibility + * ref_seq = force_str(build_reference_sequence(src)) + * if ref_seq is None: # <<<<<<<<<<<<<< + * raise ValueError("MD tag not present") * - * ncigar = len(values) # <<<<<<<<<<<<<< - * # create space for cigar data within src.data - * pysam_bam_update(src, */ - __pyx_t_5 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1806, __pyx_L1_error) - __pyx_v_ncigar = __pyx_t_5; + } - /* "pysam/libcalignedsegment.pyx":1808 - * ncigar = len(values) - * # create space for cigar data within src.data - * pysam_bam_update(src, # <<<<<<<<<<<<<< - * pysam_get_n_cigar(src) * 4, - * ncigar * 4, + /* "pysam/libcalignedsegment.pyx":1886 + * # read sequence, cigar and MD tag are consistent. + * + * if _with_seq: # <<<<<<<<<<<<<< + * # force_str required for py2/py3 compatibility + * ref_seq = force_str(build_reference_sequence(src)) */ - (void)(pysam_bam_update(__pyx_v_src, (pysam_get_n_cigar(__pyx_v_src) * 4), (__pyx_v_ncigar * 4), ((uint8_t *)__pyx_v_p))); + } - /* "pysam/libcalignedsegment.pyx":1814 + /* "pysam/libcalignedsegment.pyx":1892 + * raise ValueError("MD tag not present") * - * # length is number of cigar operations, not bytes - * pysam_set_n_cigar(src, ncigar) # <<<<<<<<<<<<<< + * r_idx = 0 # <<<<<<<<<<<<<< * - * # re-acquire pointer to location in memory + * if pysam_get_n_cigar(src) == 0: */ - pysam_set_n_cigar(__pyx_v_src, __pyx_v_ncigar); + __pyx_v_r_idx = 0; - /* "pysam/libcalignedsegment.pyx":1818 - * # re-acquire pointer to location in memory - * # as it might have moved - * p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1894 + * r_idx = 0 + * + * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< + * return [] * - * # insert cigar operations */ - __pyx_v_p = pysam_bam_get_cigar(__pyx_v_src); + __pyx_t_5 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); + if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":1821 + /* "pysam/libcalignedsegment.pyx":1895 * - * # insert cigar operations - * for op, l in values: # <<<<<<<<<<<<<< - * p[k] = l << BAM_CIGAR_SHIFT | op - * k += 1 + * if pysam_get_n_cigar(src) == 0: + * return [] # <<<<<<<<<<<<<< + * + * result = [] */ - if (likely(PyList_CheckExact(__pyx_v_values)) || PyTuple_CheckExact(__pyx_v_values)) { - __pyx_t_4 = __pyx_v_values; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0; - __pyx_t_6 = NULL; - } else { - __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1821, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1895, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1821, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_6)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1821, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1821, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } else { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1821, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1821, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } - } else { - __pyx_t_7 = __pyx_t_6(__pyx_t_4); - if (unlikely(!__pyx_t_7)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1821, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_7); - } - if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { - PyObject* sequence = __pyx_t_7; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 1821, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_8 = PyList_GET_ITEM(sequence, 0); - __pyx_t_9 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_9); - #else - __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1821, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1821, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - #endif - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1821, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext; - index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_9); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) __PYX_ERR(0, 1821, __pyx_L1_error) - __pyx_t_11 = NULL; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_11 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1821, __pyx_L1_error) - __pyx_L7_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_op, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_9); - __pyx_t_9 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1822 - * # insert cigar operations - * for op, l in values: - * p[k] = l << BAM_CIGAR_SHIFT | op # <<<<<<<<<<<<<< - * k += 1 + /* "pysam/libcalignedsegment.pyx":1894 + * r_idx = 0 + * + * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< + * return [] * */ - __pyx_t_7 = __Pyx_PyInt_From_int(BAM_CIGAR_SHIFT); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1822, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = PyNumber_Lshift(__pyx_v_l, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1822, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Or(__pyx_t_9, __pyx_v_op); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1822, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_12 = __Pyx_PyInt_As_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_12 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1822, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - (__pyx_v_p[__pyx_v_k]) = __pyx_t_12; + } - /* "pysam/libcalignedsegment.pyx":1823 - * for op, l in values: - * p[k] = l << BAM_CIGAR_SHIFT | op - * k += 1 # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1897 + * return [] * - * ## setting the cigar string requires updating the bin + * result = [] # <<<<<<<<<<<<<< + * pos = src.core.pos + * qpos = 0 */ - __pyx_v_k = (__pyx_v_k + 1); + __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1897, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_result = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcalignedsegment.pyx":1821 + /* "pysam/libcalignedsegment.pyx":1898 * - * # insert cigar operations - * for op, l in values: # <<<<<<<<<<<<<< - * p[k] = l << BAM_CIGAR_SHIFT | op - * k += 1 + * result = [] + * pos = src.core.pos # <<<<<<<<<<<<<< + * qpos = 0 + * cigar_p = pysam_bam_get_cigar(src) */ - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __pyx_v_src->core.pos; + __pyx_v_pos = __pyx_t_6; - /* "pysam/libcalignedsegment.pyx":1826 - * - * ## setting the cigar string requires updating the bin - * pysam_set_bin(src, # <<<<<<<<<<<<<< - * hts_reg2bin( - * src.core.pos, + /* "pysam/libcalignedsegment.pyx":1899 + * result = [] + * pos = src.core.pos + * qpos = 0 # <<<<<<<<<<<<<< + * cigar_p = pysam_bam_get_cigar(src) + * for k from 0 <= k < pysam_get_n_cigar(src): */ - pysam_set_bin(__pyx_v_src, hts_reg2bin(__pyx_v_src->core.pos, bam_endpos(__pyx_v_src), 14, 5)); + __pyx_v_qpos = 0; - /* "pysam/libcalignedsegment.pyx":1789 - * return cigar - * - * def __set__(self, values): # <<<<<<<<<<<<<< - * cdef uint32_t * p - * cdef bam1_t * src + /* "pysam/libcalignedsegment.pyx":1900 + * pos = src.core.pos + * qpos = 0 + * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK */ + __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.cigartuples.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_op); - __Pyx_XDECREF(__pyx_v_l); - __Pyx_XDECREF(__pyx_v_values); - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":1901 + * qpos = 0 + * cigar_p = pysam_bam_get_cigar(src) + * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + */ + __pyx_t_7 = pysam_get_n_cigar(__pyx_v_src); + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_7; __pyx_v_k++) { -/* "pysam/libcalignedsegment.pyx":1834 - * + /* "pysam/libcalignedsegment.pyx":1902 + * cigar_p = pysam_bam_get_cigar(src) + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< + * l = cigar_p[k] >> BAM_CIGAR_SHIFT * - * cpdef set_tag(self, # <<<<<<<<<<<<<< - * tag, - * value, */ + __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_33set_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_set_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag *__pyx_optional_args) { - - /* "pysam/libcalignedsegment.pyx":1837 - * tag, - * value, - * value_type=None, # <<<<<<<<<<<<<< - * replace=True): - * """sets a particular field *tag* to *value* in the optional alignment + /* "pysam/libcalignedsegment.pyx":1903 + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< + * + * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: */ - PyObject *__pyx_v_value_type = ((PyObject *)Py_None); + __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT); - /* "pysam/libcalignedsegment.pyx":1838 - * value, - * value_type=None, - * replace=True): # <<<<<<<<<<<<<< - * """sets a particular field *tag* to *value* in the optional alignment - * section. + /* "pysam/libcalignedsegment.pyx":1905 + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * + * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: # <<<<<<<<<<<<<< + * if _with_seq: + * for i from pos <= i < pos + l: */ - PyObject *__pyx_v_replace = ((PyObject *)Py_True); - int __pyx_v_value_size; - uint8_t *__pyx_v_value_ptr; - uint8_t *__pyx_v_existing_ptr; - uint8_t __pyx_v_typecode; - float __pyx_v_float_value; - double __pyx_v_double_value; - int32_t __pyx_v_int_value; - bam1_t *__pyx_v_src; - PyObject *__pyx_v_buffer = 0; - PyObject *__pyx_v_fmt = NULL; - PyObject *__pyx_v_args = NULL; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - bam1_t *__pyx_t_7; - Py_ssize_t __pyx_t_8; - int __pyx_t_9; - char const *__pyx_t_10; - int __pyx_t_11; - uint8_t __pyx_t_12; - struct __pyx_opt_args_5pysam_18libcalignedsegment_get_value_code __pyx_t_13; - char *__pyx_t_14; - int32_t __pyx_t_15; - double __pyx_t_16; - float __pyx_t_17; - PyObject *(*__pyx_t_18)(PyObject *); - char const *__pyx_t_19; - uint8_t *__pyx_t_20; - __Pyx_RefNannySetupContext("set_tag", 0); - __Pyx_TraceCall("set_tag", __pyx_f[0], 1834, 0, __PYX_ERR(0, 1834, __pyx_L1_error)); - if (__pyx_optional_args) { - if (__pyx_optional_args->__pyx_n > 0) { - __pyx_v_value_type = __pyx_optional_args->value_type; - if (__pyx_optional_args->__pyx_n > 1) { - __pyx_v_replace = __pyx_optional_args->replace; - } + __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0); + if (!__pyx_t_2) { + } else { + __pyx_t_5 = __pyx_t_2; + goto __pyx_L9_bool_binop_done; } - } - __Pyx_INCREF(__pyx_v_tag); - __Pyx_INCREF(__pyx_v_value); + __pyx_t_2 = ((__pyx_v_op == BAM_CEQUAL) != 0); + if (!__pyx_t_2) { + } else { + __pyx_t_5 = __pyx_t_2; + goto __pyx_L9_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_op == BAM_CDIFF) != 0); + __pyx_t_5 = __pyx_t_2; + __pyx_L9_bool_binop_done:; + if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":1834 + /* "pysam/libcalignedsegment.pyx":1906 * - * - * cpdef set_tag(self, # <<<<<<<<<<<<<< - * tag, - * value, + * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: + * if _with_seq: # <<<<<<<<<<<<<< + * for i from pos <= i < pos + l: + * result.append((qpos, i, ref_seq[r_idx])) */ - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_tag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1834, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_33set_tag)) { - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[5] = {__pyx_t_4, __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 4+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1834, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[5] = {__pyx_t_4, __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 4+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1834, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_6 = PyTuple_New(4+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1834, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; - } - __Pyx_INCREF(__pyx_v_tag); - __Pyx_GIVEREF(__pyx_v_tag); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_tag); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_value); - __Pyx_INCREF(__pyx_v_value_type); - __Pyx_GIVEREF(__pyx_v_value_type); - PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_5, __pyx_v_value_type); - __Pyx_INCREF(__pyx_v_replace); - __Pyx_GIVEREF(__pyx_v_replace); - PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_5, __pyx_v_replace); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1834, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } + __pyx_t_5 = (__pyx_v__with_seq != 0); + if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":1861 - * cdef double double_value - * cdef int32_t int_value - * cdef bam1_t * src = self._delegate # <<<<<<<<<<<<<< - * cdef char * _value_type - * cdef c_array.array array_value + /* "pysam/libcalignedsegment.pyx":1907 + * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: + * if _with_seq: + * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< + * result.append((qpos, i, ref_seq[r_idx])) + * r_idx += 1 */ - __pyx_t_7 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_7; + __pyx_t_8 = (__pyx_v_pos + __pyx_v_l); + for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":1866 - * cdef object buffer - * - * if len(tag) != 2: # <<<<<<<<<<<<<< - * raise ValueError('Invalid tag: %s' % tag) - * + /* "pysam/libcalignedsegment.pyx":1908 + * if _with_seq: + * for i from pos <= i < pos + l: + * result.append((qpos, i, ref_seq[r_idx])) # <<<<<<<<<<<<<< + * r_idx += 1 + * qpos += 1 */ - __pyx_t_8 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1866, __pyx_L1_error) - __pyx_t_9 = ((__pyx_t_8 != 2) != 0); - if (unlikely(__pyx_t_9)) { + __pyx_t_4 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(!__pyx_v_ref_seq)) { __Pyx_RaiseUnboundLocalError("ref_seq"); __PYX_ERR(0, 1908, __pyx_L1_error) } + __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_ref_seq, __pyx_v_r_idx, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9); + __pyx_t_4 = 0; + __pyx_t_3 = 0; + __pyx_t_9 = 0; + __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1908, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - /* "pysam/libcalignedsegment.pyx":1867 - * - * if len(tag) != 2: - * raise ValueError('Invalid tag: %s' % tag) # <<<<<<<<<<<<<< - * - * tag = force_bytes(tag) + /* "pysam/libcalignedsegment.pyx":1909 + * for i from pos <= i < pos + l: + * result.append((qpos, i, ref_seq[r_idx])) + * r_idx += 1 # <<<<<<<<<<<<<< + * qpos += 1 + * else: */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_tag_s, __pyx_v_tag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1867, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1867, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 1867, __pyx_L1_error) + __pyx_v_r_idx = (__pyx_v_r_idx + 1); - /* "pysam/libcalignedsegment.pyx":1866 - * cdef object buffer - * - * if len(tag) != 2: # <<<<<<<<<<<<<< - * raise ValueError('Invalid tag: %s' % tag) - * + /* "pysam/libcalignedsegment.pyx":1910 + * result.append((qpos, i, ref_seq[r_idx])) + * r_idx += 1 + * qpos += 1 # <<<<<<<<<<<<<< + * else: + * for i from pos <= i < pos + l: */ - } + __pyx_v_qpos = (__pyx_v_qpos + 1); + } - /* "pysam/libcalignedsegment.pyx":1869 - * raise ValueError('Invalid tag: %s' % tag) + /* "pysam/libcalignedsegment.pyx":1906 * - * tag = force_bytes(tag) # <<<<<<<<<<<<<< - * if replace: - * existing_ptr = bam_aux_get(src, tag) + * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: + * if _with_seq: # <<<<<<<<<<<<<< + * for i from pos <= i < pos + l: + * result.append((qpos, i, ref_seq[r_idx])) */ - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_tag, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1869, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF_SET(__pyx_v_tag, __pyx_t_2); - __pyx_t_2 = 0; + goto __pyx_L12; + } - /* "pysam/libcalignedsegment.pyx":1870 - * - * tag = force_bytes(tag) - * if replace: # <<<<<<<<<<<<<< - * existing_ptr = bam_aux_get(src, tag) - * if existing_ptr: + /* "pysam/libcalignedsegment.pyx":1912 + * qpos += 1 + * else: + * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< + * result.append((qpos, i)) + * qpos += 1 */ - __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_replace); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1870, __pyx_L1_error) - if (__pyx_t_9) { + /*else*/ { + __pyx_t_8 = (__pyx_v_pos + __pyx_v_l); + for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":1871 - * tag = force_bytes(tag) - * if replace: - * existing_ptr = bam_aux_get(src, tag) # <<<<<<<<<<<<<< - * if existing_ptr: - * bam_aux_del(src, existing_ptr) + /* "pysam/libcalignedsegment.pyx":1913 + * else: + * for i from pos <= i < pos + l: + * result.append((qpos, i)) # <<<<<<<<<<<<<< + * qpos += 1 + * pos += l */ - __pyx_t_10 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 1871, __pyx_L1_error) - __pyx_v_existing_ptr = bam_aux_get(__pyx_v_src, __pyx_t_10); + __pyx_t_10 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1913, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1913, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1913, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_9); + __pyx_t_10 = 0; + __pyx_t_9 = 0; + __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1913, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1872 - * if replace: - * existing_ptr = bam_aux_get(src, tag) - * if existing_ptr: # <<<<<<<<<<<<<< - * bam_aux_del(src, existing_ptr) + /* "pysam/libcalignedsegment.pyx":1914 + * for i from pos <= i < pos + l: + * result.append((qpos, i)) + * qpos += 1 # <<<<<<<<<<<<<< + * pos += l * */ - __pyx_t_9 = (__pyx_v_existing_ptr != 0); - if (__pyx_t_9) { + __pyx_v_qpos = (__pyx_v_qpos + 1); + } + } + __pyx_L12:; - /* "pysam/libcalignedsegment.pyx":1873 - * existing_ptr = bam_aux_get(src, tag) - * if existing_ptr: - * bam_aux_del(src, existing_ptr) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1915 + * result.append((qpos, i)) + * qpos += 1 + * pos += l # <<<<<<<<<<<<<< * - * # setting value to None deletes a tag + * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: */ - (void)(bam_aux_del(__pyx_v_src, __pyx_v_existing_ptr)); + __pyx_v_pos = (__pyx_v_pos + __pyx_v_l); - /* "pysam/libcalignedsegment.pyx":1872 - * if replace: - * existing_ptr = bam_aux_get(src, tag) - * if existing_ptr: # <<<<<<<<<<<<<< - * bam_aux_del(src, existing_ptr) + /* "pysam/libcalignedsegment.pyx":1905 + * l = cigar_p[k] >> BAM_CIGAR_SHIFT * + * if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: # <<<<<<<<<<<<<< + * if _with_seq: + * for i from pos <= i < pos + l: */ + goto __pyx_L8; } - /* "pysam/libcalignedsegment.pyx":1870 + /* "pysam/libcalignedsegment.pyx":1917 + * pos += l * - * tag = force_bytes(tag) - * if replace: # <<<<<<<<<<<<<< - * existing_ptr = bam_aux_get(src, tag) - * if existing_ptr: + * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< + * if not _matches_only: + * if _with_seq: */ - } + __pyx_t_2 = ((__pyx_v_op == BAM_CINS) != 0); + if (!__pyx_t_2) { + } else { + __pyx_t_5 = __pyx_t_2; + goto __pyx_L17_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0); + __pyx_t_5 = __pyx_t_2; + __pyx_L17_bool_binop_done:; + if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":1876 - * - * # setting value to None deletes a tag - * if value is None: # <<<<<<<<<<<<<< - * return + /* "pysam/libcalignedsegment.pyx":1918 * + * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: + * if not _matches_only: # <<<<<<<<<<<<<< + * if _with_seq: + * for i from pos <= i < pos + l: */ - __pyx_t_9 = (__pyx_v_value == Py_None); - __pyx_t_11 = (__pyx_t_9 != 0); - if (__pyx_t_11) { + __pyx_t_5 = ((!(__pyx_v__matches_only != 0)) != 0); + if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":1877 - * # setting value to None deletes a tag - * if value is None: - * return # <<<<<<<<<<<<<< - * - * typecode = get_value_code(value, value_type) + /* "pysam/libcalignedsegment.pyx":1919 + * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: + * if not _matches_only: + * if _with_seq: # <<<<<<<<<<<<<< + * for i from pos <= i < pos + l: + * result.append((qpos, None, None)) */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + __pyx_t_5 = (__pyx_v__with_seq != 0); + if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":1876 - * - * # setting value to None deletes a tag - * if value is None: # <<<<<<<<<<<<<< - * return - * + /* "pysam/libcalignedsegment.pyx":1920 + * if not _matches_only: + * if _with_seq: + * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< + * result.append((qpos, None, None)) + * qpos += 1 */ - } + __pyx_t_8 = (__pyx_v_pos + __pyx_v_l); + for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":1879 - * return - * - * typecode = get_value_code(value, value_type) # <<<<<<<<<<<<<< - * if typecode == 0: - * raise ValueError("can't guess type or invalid type code specified") + /* "pysam/libcalignedsegment.pyx":1921 + * if _with_seq: + * for i from pos <= i < pos + l: + * result.append((qpos, None, None)) # <<<<<<<<<<<<<< + * qpos += 1 + * else: */ - __pyx_t_13.__pyx_n = 1; - __pyx_t_13.value_type = __pyx_v_value_type; - __pyx_t_12 = __pyx_f_5pysam_18libcalignedsegment_get_value_code(__pyx_v_value, &__pyx_t_13); - __pyx_v_typecode = __pyx_t_12; + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_9, 1, Py_None); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_9, 2, Py_None); + __pyx_t_3 = 0; + __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1921, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - /* "pysam/libcalignedsegment.pyx":1880 - * - * typecode = get_value_code(value, value_type) - * if typecode == 0: # <<<<<<<<<<<<<< - * raise ValueError("can't guess type or invalid type code specified") - * + /* "pysam/libcalignedsegment.pyx":1922 + * for i from pos <= i < pos + l: + * result.append((qpos, None, None)) + * qpos += 1 # <<<<<<<<<<<<<< + * else: + * for i from pos <= i < pos + l: */ - __pyx_t_11 = ((__pyx_v_typecode == 0) != 0); - if (unlikely(__pyx_t_11)) { + __pyx_v_qpos = (__pyx_v_qpos + 1); + } - /* "pysam/libcalignedsegment.pyx":1881 - * typecode = get_value_code(value, value_type) - * if typecode == 0: - * raise ValueError("can't guess type or invalid type code specified") # <<<<<<<<<<<<<< - * - * # Not Endian-safe, but then again neither is samtools! + /* "pysam/libcalignedsegment.pyx":1919 + * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: + * if not _matches_only: + * if _with_seq: # <<<<<<<<<<<<<< + * for i from pos <= i < pos + l: + * result.append((qpos, None, None)) */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1881, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 1881, __pyx_L1_error) + goto __pyx_L20; + } - /* "pysam/libcalignedsegment.pyx":1880 - * - * typecode = get_value_code(value, value_type) - * if typecode == 0: # <<<<<<<<<<<<<< - * raise ValueError("can't guess type or invalid type code specified") - * + /* "pysam/libcalignedsegment.pyx":1924 + * qpos += 1 + * else: + * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< + * result.append((qpos, None)) + * qpos += 1 */ - } + /*else*/ { + __pyx_t_8 = (__pyx_v_pos + __pyx_v_l); + for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":1884 - * - * # Not Endian-safe, but then again neither is samtools! - * if typecode == 'Z': # <<<<<<<<<<<<<< - * value = force_bytes(value) - * value_ptr = value + /* "pysam/libcalignedsegment.pyx":1925 + * else: + * for i from pos <= i < pos + l: + * result.append((qpos, None)) # <<<<<<<<<<<<<< + * qpos += 1 + * else: */ - switch (__pyx_v_typecode) { - case 'Z': + __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1925, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1925, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_3, 1, Py_None); + __pyx_t_9 = 0; + __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1925, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1885 - * # Not Endian-safe, but then again neither is samtools! - * if typecode == 'Z': - * value = force_bytes(value) # <<<<<<<<<<<<<< - * value_ptr = value - * value_size = len(value)+1 + /* "pysam/libcalignedsegment.pyx":1926 + * for i from pos <= i < pos + l: + * result.append((qpos, None)) + * qpos += 1 # <<<<<<<<<<<<<< + * else: + * qpos += l */ - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1885, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_2); - __pyx_t_2 = 0; + __pyx_v_qpos = (__pyx_v_qpos + 1); + } + } + __pyx_L20:; - /* "pysam/libcalignedsegment.pyx":1886 - * if typecode == 'Z': - * value = force_bytes(value) - * value_ptr = value # <<<<<<<<<<<<<< - * value_size = len(value)+1 - * elif typecode == 'i': + /* "pysam/libcalignedsegment.pyx":1918 + * + * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: + * if not _matches_only: # <<<<<<<<<<<<<< + * if _with_seq: + * for i from pos <= i < pos + l: */ - __pyx_t_14 = __Pyx_PyObject_AsWritableString(__pyx_v_value); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) __PYX_ERR(0, 1886, __pyx_L1_error) - __pyx_v_value_ptr = ((uint8_t *)((char *)__pyx_t_14)); + goto __pyx_L19; + } - /* "pysam/libcalignedsegment.pyx":1887 - * value = force_bytes(value) - * value_ptr = value - * value_size = len(value)+1 # <<<<<<<<<<<<<< - * elif typecode == 'i': - * int_value = value + /* "pysam/libcalignedsegment.pyx":1928 + * qpos += 1 + * else: + * qpos += l # <<<<<<<<<<<<<< + * + * elif op == BAM_CDEL: */ - __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1887, __pyx_L1_error) - __pyx_v_value_size = (__pyx_t_8 + 1); + /*else*/ { + __pyx_v_qpos = (__pyx_v_qpos + __pyx_v_l); + } + __pyx_L19:; - /* "pysam/libcalignedsegment.pyx":1884 + /* "pysam/libcalignedsegment.pyx":1917 + * pos += l * - * # Not Endian-safe, but then again neither is samtools! - * if typecode == 'Z': # <<<<<<<<<<<<<< - * value = force_bytes(value) - * value_ptr = value + * elif op == BAM_CINS or op == BAM_CSOFT_CLIP: # <<<<<<<<<<<<<< + * if not _matches_only: + * if _with_seq: */ - break; + goto __pyx_L8; + } - /* "pysam/libcalignedsegment.pyx":1888 - * value_ptr = value - * value_size = len(value)+1 - * elif typecode == 'i': # <<<<<<<<<<<<<< - * int_value = value - * value_ptr = &int_value + /* "pysam/libcalignedsegment.pyx":1930 + * qpos += l + * + * elif op == BAM_CDEL: # <<<<<<<<<<<<<< + * if not _matches_only: + * if _with_seq: */ - case 'i': + __pyx_t_5 = ((__pyx_v_op == BAM_CDEL) != 0); + if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":1889 - * value_size = len(value)+1 - * elif typecode == 'i': - * int_value = value # <<<<<<<<<<<<<< - * value_ptr = &int_value - * value_size = sizeof(int32_t) + /* "pysam/libcalignedsegment.pyx":1931 + * + * elif op == BAM_CDEL: + * if not _matches_only: # <<<<<<<<<<<<<< + * if _with_seq: + * for i from pos <= i < pos + l: */ - __pyx_t_15 = __Pyx_PyInt_As_int32_t(__pyx_v_value); if (unlikely((__pyx_t_15 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1889, __pyx_L1_error) - __pyx_v_int_value = __pyx_t_15; + __pyx_t_5 = ((!(__pyx_v__matches_only != 0)) != 0); + if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":1890 - * elif typecode == 'i': - * int_value = value - * value_ptr = &int_value # <<<<<<<<<<<<<< - * value_size = sizeof(int32_t) - * elif typecode == 'd': + /* "pysam/libcalignedsegment.pyx":1932 + * elif op == BAM_CDEL: + * if not _matches_only: + * if _with_seq: # <<<<<<<<<<<<<< + * for i from pos <= i < pos + l: + * result.append((None, i, ref_seq[r_idx])) */ - __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_int_value)); + __pyx_t_5 = (__pyx_v__with_seq != 0); + if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":1891 - * int_value = value - * value_ptr = &int_value - * value_size = sizeof(int32_t) # <<<<<<<<<<<<<< - * elif typecode == 'd': - * double_value = value + /* "pysam/libcalignedsegment.pyx":1933 + * if not _matches_only: + * if _with_seq: + * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< + * result.append((None, i, ref_seq[r_idx])) + * r_idx += 1 */ - __pyx_v_value_size = (sizeof(int32_t)); + __pyx_t_8 = (__pyx_v_pos + __pyx_v_l); + for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":1888 - * value_ptr = value - * value_size = len(value)+1 - * elif typecode == 'i': # <<<<<<<<<<<<<< - * int_value = value - * value_ptr = &int_value + /* "pysam/libcalignedsegment.pyx":1934 + * if _with_seq: + * for i from pos <= i < pos + l: + * result.append((None, i, ref_seq[r_idx])) # <<<<<<<<<<<<<< + * r_idx += 1 + * else: */ - break; + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1934, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(!__pyx_v_ref_seq)) { __Pyx_RaiseUnboundLocalError("ref_seq"); __PYX_ERR(0, 1934, __pyx_L1_error) } + __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_ref_seq, __pyx_v_r_idx, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1934, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1934, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_10, 0, Py_None); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9); + __pyx_t_3 = 0; + __pyx_t_9 = 0; + __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1934, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - /* "pysam/libcalignedsegment.pyx":1892 - * value_ptr = &int_value - * value_size = sizeof(int32_t) - * elif typecode == 'd': # <<<<<<<<<<<<<< - * double_value = value - * value_ptr = &double_value + /* "pysam/libcalignedsegment.pyx":1935 + * for i from pos <= i < pos + l: + * result.append((None, i, ref_seq[r_idx])) + * r_idx += 1 # <<<<<<<<<<<<<< + * else: + * for i from pos <= i < pos + l: */ - case 'd': + __pyx_v_r_idx = (__pyx_v_r_idx + 1); + } - /* "pysam/libcalignedsegment.pyx":1893 - * value_size = sizeof(int32_t) - * elif typecode == 'd': - * double_value = value # <<<<<<<<<<<<<< - * value_ptr = &double_value - * value_size = sizeof(double) + /* "pysam/libcalignedsegment.pyx":1932 + * elif op == BAM_CDEL: + * if not _matches_only: + * if _with_seq: # <<<<<<<<<<<<<< + * for i from pos <= i < pos + l: + * result.append((None, i, ref_seq[r_idx])) */ - __pyx_t_16 = __pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_16 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1893, __pyx_L1_error) - __pyx_v_double_value = __pyx_t_16; + goto __pyx_L26; + } - /* "pysam/libcalignedsegment.pyx":1894 - * elif typecode == 'd': - * double_value = value - * value_ptr = &double_value # <<<<<<<<<<<<<< - * value_size = sizeof(double) - * elif typecode == 'f': + /* "pysam/libcalignedsegment.pyx":1937 + * r_idx += 1 + * else: + * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< + * result.append((None, i)) + * pos += l */ - __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_double_value)); + /*else*/ { + __pyx_t_8 = (__pyx_v_pos + __pyx_v_l); + for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":1895 - * double_value = value - * value_ptr = &double_value - * value_size = sizeof(double) # <<<<<<<<<<<<<< - * elif typecode == 'f': - * float_value = value + /* "pysam/libcalignedsegment.pyx":1938 + * else: + * for i from pos <= i < pos + l: + * result.append((None, i)) # <<<<<<<<<<<<<< + * pos += l + * */ - __pyx_v_value_size = (sizeof(double)); + __pyx_t_10 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1938, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1938, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_9, 0, Py_None); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1938, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __pyx_L26:; - /* "pysam/libcalignedsegment.pyx":1892 - * value_ptr = &int_value - * value_size = sizeof(int32_t) - * elif typecode == 'd': # <<<<<<<<<<<<<< - * double_value = value - * value_ptr = &double_value + /* "pysam/libcalignedsegment.pyx":1931 + * + * elif op == BAM_CDEL: + * if not _matches_only: # <<<<<<<<<<<<<< + * if _with_seq: + * for i from pos <= i < pos + l: */ - break; + } - /* "pysam/libcalignedsegment.pyx":1896 - * value_ptr = &double_value - * value_size = sizeof(double) - * elif typecode == 'f': # <<<<<<<<<<<<<< - * float_value = value - * value_ptr = &float_value + /* "pysam/libcalignedsegment.pyx":1939 + * for i from pos <= i < pos + l: + * result.append((None, i)) + * pos += l # <<<<<<<<<<<<<< + * + * elif op == BAM_CHARD_CLIP: */ - case 'f': + __pyx_v_pos = (__pyx_v_pos + __pyx_v_l); - /* "pysam/libcalignedsegment.pyx":1897 - * value_size = sizeof(double) - * elif typecode == 'f': - * float_value = value # <<<<<<<<<<<<<< - * value_ptr = &float_value - * value_size = sizeof(float) + /* "pysam/libcalignedsegment.pyx":1930 + * qpos += l + * + * elif op == BAM_CDEL: # <<<<<<<<<<<<<< + * if not _matches_only: + * if _with_seq: */ - __pyx_t_17 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_17 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 1897, __pyx_L1_error) - __pyx_v_float_value = __pyx_t_17; + goto __pyx_L8; + } - /* "pysam/libcalignedsegment.pyx":1898 - * elif typecode == 'f': - * float_value = value - * value_ptr = &float_value # <<<<<<<<<<<<<< - * value_size = sizeof(float) - * elif typecode == 'B': + /* "pysam/libcalignedsegment.pyx":1941 + * pos += l + * + * elif op == BAM_CHARD_CLIP: # <<<<<<<<<<<<<< + * pass # advances neither + * */ - __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_float_value)); + __pyx_t_5 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0); + if (__pyx_t_5) { + goto __pyx_L8; + } - /* "pysam/libcalignedsegment.pyx":1899 - * float_value = value - * value_ptr = &float_value - * value_size = sizeof(float) # <<<<<<<<<<<<<< - * elif typecode == 'B': - * # the following goes through python, needs to be cleaned up + /* "pysam/libcalignedsegment.pyx":1944 + * pass # advances neither + * + * elif op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< + * if not _matches_only: + * if _with_seq: */ - __pyx_v_value_size = (sizeof(float)); + __pyx_t_5 = ((__pyx_v_op == BAM_CREF_SKIP) != 0); + if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":1896 - * value_ptr = &double_value - * value_size = sizeof(double) - * elif typecode == 'f': # <<<<<<<<<<<<<< - * float_value = value - * value_ptr = &float_value + /* "pysam/libcalignedsegment.pyx":1945 + * + * elif op == BAM_CREF_SKIP: + * if not _matches_only: # <<<<<<<<<<<<<< + * if _with_seq: + * for i from pos <= i < pos + l: */ - break; + __pyx_t_5 = ((!(__pyx_v__matches_only != 0)) != 0); + if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":1900 - * value_ptr = &float_value - * value_size = sizeof(float) - * elif typecode == 'B': # <<<<<<<<<<<<<< - * # the following goes through python, needs to be cleaned up - * # pack array using struct + /* "pysam/libcalignedsegment.pyx":1946 + * elif op == BAM_CREF_SKIP: + * if not _matches_only: + * if _with_seq: # <<<<<<<<<<<<<< + * for i from pos <= i < pos + l: + * result.append((None, i, None)) */ - case 'B': + __pyx_t_5 = (__pyx_v__with_seq != 0); + if (__pyx_t_5) { - /* "pysam/libcalignedsegment.pyx":1903 - * # the following goes through python, needs to be cleaned up - * # pack array using struct - * if value_type is None: # <<<<<<<<<<<<<< - * fmt, args = packTags([(tag, value)]) - * else: + /* "pysam/libcalignedsegment.pyx":1947 + * if not _matches_only: + * if _with_seq: + * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< + * result.append((None, i, None)) + * else: */ - __pyx_t_11 = (__pyx_v_value_type == Py_None); - __pyx_t_9 = (__pyx_t_11 != 0); - if (__pyx_t_9) { + __pyx_t_8 = (__pyx_v_pos + __pyx_v_l); + for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { - /* "pysam/libcalignedsegment.pyx":1904 - * # pack array using struct - * if value_type is None: - * fmt, args = packTags([(tag, value)]) # <<<<<<<<<<<<<< - * else: - * fmt, args = packTags([(tag, value, value_type)]) + /* "pysam/libcalignedsegment.pyx":1948 + * if _with_seq: + * for i from pos <= i < pos + l: + * result.append((None, i, None)) # <<<<<<<<<<<<<< + * else: + * for i from pos <= i < pos + l: */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1904, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_tag); - __Pyx_GIVEREF(__pyx_v_tag); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_tag); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_value); - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1904, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __pyx_f_5pysam_18libcalignedsegment_packTags(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1904, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 1904, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1948, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1948, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_10, 0, Py_None); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_9); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_10, 2, Py_None); + __pyx_t_9 = 0; + __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1948, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + + /* "pysam/libcalignedsegment.pyx":1946 + * elif op == BAM_CREF_SKIP: + * if not _matches_only: + * if _with_seq: # <<<<<<<<<<<<<< + * for i from pos <= i < pos + l: + * result.append((None, i, None)) + */ + goto __pyx_L32; } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + + /* "pysam/libcalignedsegment.pyx":1950 + * result.append((None, i, None)) + * else: + * for i from pos <= i < pos + l: # <<<<<<<<<<<<<< + * result.append((None, i)) + * + */ + /*else*/ { + __pyx_t_8 = (__pyx_v_pos + __pyx_v_l); + for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_8; __pyx_v_i++) { + + /* "pysam/libcalignedsegment.pyx":1951 + * else: + * for i from pos <= i < pos + l: + * result.append((None, i)) # <<<<<<<<<<<<<< + * + * pos += l + */ + __pyx_t_10 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1951, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1951, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_9, 0, Py_None); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 1951, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_3); - #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1904, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1904, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_6 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1904, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_18 = Py_TYPE(__pyx_t_6)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_18(__pyx_t_6); if (unlikely(!__pyx_t_1)) goto __pyx_L9_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_3 = __pyx_t_18(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L9_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_18(__pyx_t_6), 2) < 0) __PYX_ERR(0, 1904, __pyx_L1_error) - __pyx_t_18 = NULL; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - goto __pyx_L10_unpacking_done; - __pyx_L9_unpacking_failed:; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_18 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1904, __pyx_L1_error) - __pyx_L10_unpacking_done:; + __pyx_L32:; + + /* "pysam/libcalignedsegment.pyx":1945 + * + * elif op == BAM_CREF_SKIP: + * if not _matches_only: # <<<<<<<<<<<<<< + * if _with_seq: + * for i from pos <= i < pos + l: + */ } - __pyx_v_fmt = __pyx_t_1; - __pyx_t_1 = 0; - __pyx_v_args = __pyx_t_3; - __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1903 - * # the following goes through python, needs to be cleaned up - * # pack array using struct - * if value_type is None: # <<<<<<<<<<<<<< - * fmt, args = packTags([(tag, value)]) - * else: + /* "pysam/libcalignedsegment.pyx":1953 + * result.append((None, i)) + * + * pos += l # <<<<<<<<<<<<<< + * + * elif op == BAM_CPAD: + */ + __pyx_v_pos = (__pyx_v_pos + __pyx_v_l); + + /* "pysam/libcalignedsegment.pyx":1944 + * pass # advances neither + * + * elif op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< + * if not _matches_only: + * if _with_seq: */ goto __pyx_L8; } - /* "pysam/libcalignedsegment.pyx":1906 - * fmt, args = packTags([(tag, value)]) - * else: - * fmt, args = packTags([(tag, value, value_type)]) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1955 + * pos += l * - * # remove tag and type code as set by bam_aux_append + * elif op == BAM_CPAD: # <<<<<<<<<<<<<< + * raise NotImplementedError( + * "Padding (BAM_CPAD, 6) is currently not supported. " + */ + __pyx_t_5 = ((__pyx_v_op == BAM_CPAD) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcalignedsegment.pyx":1956 + * + * elif op == BAM_CPAD: + * raise NotImplementedError( # <<<<<<<<<<<<<< + * "Padding (BAM_CPAD, 6) is currently not supported. " + * "Please implement. Sorry about that.") + */ + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1956, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 1956, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":1955 + * pos += l + * + * elif op == BAM_CPAD: # <<<<<<<<<<<<<< + * raise NotImplementedError( + * "Padding (BAM_CPAD, 6) is currently not supported. " */ - /*else*/ { - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_tag); - __Pyx_GIVEREF(__pyx_v_tag); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_tag); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_value); - __Pyx_INCREF(__pyx_v_value_type); - __Pyx_GIVEREF(__pyx_v_value_type); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_value_type); - __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_2); - PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __pyx_f_5pysam_18libcalignedsegment_packTags(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 1906, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_1); - #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_6 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_18 = Py_TYPE(__pyx_t_6)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_18(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_1 = __pyx_t_18(__pyx_t_6); if (unlikely(!__pyx_t_1)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_18(__pyx_t_6), 2) < 0) __PYX_ERR(0, 1906, __pyx_L1_error) - __pyx_t_18 = NULL; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - goto __pyx_L12_unpacking_done; - __pyx_L11_unpacking_failed:; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_18 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1906, __pyx_L1_error) - __pyx_L12_unpacking_done:; - } - __pyx_v_fmt = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_v_args = __pyx_t_1; - __pyx_t_1 = 0; } __pyx_L8:; + } - /* "pysam/libcalignedsegment.pyx":1910 - * # remove tag and type code as set by bam_aux_append - * # first four chars of format (<2sc) - * fmt = '<' + fmt[4:] # <<<<<<<<<<<<<< - * # first two values to pack - * args = args[2:] + /* "pysam/libcalignedsegment.pyx":1960 + * "Please implement. Sorry about that.") + * + * return result # <<<<<<<<<<<<<< + * + * def get_blocks(self): */ - __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_fmt, 4, 0, NULL, NULL, &__pyx_slice__27, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1910, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyNumber_Add(__pyx_kp_s__4, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1910, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_fmt, __pyx_t_1); - __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1912 - * fmt = '<' + fmt[4:] - * # first two values to pack - * args = args[2:] # <<<<<<<<<<<<<< - * value_size = struct.calcsize(fmt) - * # buffer will be freed when object goes out of scope + /* "pysam/libcalignedsegment.pyx":1851 + * + * + * def get_aligned_pairs(self, matches_only=False, with_seq=False): # <<<<<<<<<<<<<< + * """a list of aligned read (query) and reference positions. + * */ - __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_args, 2, 0, NULL, NULL, &__pyx_slice__28, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1912, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_1); - __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":1913 - * # first two values to pack - * args = args[2:] - * value_size = struct.calcsize(fmt) # <<<<<<<<<<<<<< - * # buffer will be freed when object goes out of scope - * buffer = ctypes.create_string_buffer(value_size) + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_aligned_pairs", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ref_seq); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":1962 + * return result + * + * def get_blocks(self): # <<<<<<<<<<<<<< + * """ a list of start and end positions of + * aligned gapless blocks. */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1913, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_calcsize); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1913, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (!__pyx_t_2) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_fmt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1913, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_fmt}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1913, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_fmt}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1913, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1913, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL; - __Pyx_INCREF(__pyx_v_fmt); - __Pyx_GIVEREF(__pyx_v_fmt); - PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_fmt); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1913, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1913, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_value_size = __pyx_t_5; - /* "pysam/libcalignedsegment.pyx":1915 - * value_size = struct.calcsize(fmt) - * # buffer will be freed when object goes out of scope - * buffer = ctypes.create_string_buffer(value_size) # <<<<<<<<<<<<<< - * struct.pack_into(fmt, buffer, 0, *args) - * # bam_aux_append copies data from value_ptr +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_41get_blocks(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_40get_blocks[] = "AlignedSegment.get_blocks(self)\n a list of start and end positions of\n aligned gapless blocks.\n\n The start and end positions are in genomic\n coordinates.\n\n Blocks are not normalized, i.e. two blocks\n might be directly adjacent. This happens if\n the two blocks are separated by an insertion\n in the read.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_41get_blocks(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_blocks (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_40get_blocks(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_40get_blocks(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + uint32_t __pyx_v_k; + uint32_t __pyx_v_pos; + uint32_t __pyx_v_l; + int __pyx_v_op; + uint32_t *__pyx_v_cigar_p; + bam1_t *__pyx_v_src; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + bam1_t *__pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int32_t __pyx_t_4; + uint32_t __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + int __pyx_t_9; + __Pyx_RefNannySetupContext("get_blocks", 0); + __Pyx_TraceCall("get_blocks", __pyx_f[0], 1962, 0, __PYX_ERR(0, 1962, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":1980 + * cdef bam1_t * src + * + * src = self._delegate # <<<<<<<<<<<<<< + * if pysam_get_n_cigar(src) == 0: + * return [] */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_ctypes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_create_string_buffer); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_value_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - if (!__pyx_t_2) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1915, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1915, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1915, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL; - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1915, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_buffer = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_1 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":1916 - * # buffer will be freed when object goes out of scope - * buffer = ctypes.create_string_buffer(value_size) - * struct.pack_into(fmt, buffer, 0, *args) # <<<<<<<<<<<<<< - * # bam_aux_append copies data from value_ptr - * bam_aux_append(src, + /* "pysam/libcalignedsegment.pyx":1981 + * + * src = self._delegate + * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< + * return [] + * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1916, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_pack_into); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1916, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1916, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_fmt); - __Pyx_GIVEREF(__pyx_v_fmt); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fmt); - __Pyx_INCREF(__pyx_v_buffer); - __Pyx_GIVEREF(__pyx_v_buffer); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_buffer); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_0); - __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1916, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1916, __pyx_L1_error) + __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":1982 + * src = self._delegate + * if pysam_get_n_cigar(src) == 0: + * return [] # <<<<<<<<<<<<<< + * + * result = [] + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1982, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1916, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1919 - * # bam_aux_append copies data from value_ptr - * bam_aux_append(src, - * tag, # <<<<<<<<<<<<<< - * typecode, - * value_size, + /* "pysam/libcalignedsegment.pyx":1981 + * + * src = self._delegate + * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< + * return [] + * */ - __pyx_t_19 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 1919, __pyx_L1_error) + } - /* "pysam/libcalignedsegment.pyx":1922 - * typecode, - * value_size, - * buffer.raw) # <<<<<<<<<<<<<< - * return - * else: + /* "pysam/libcalignedsegment.pyx":1984 + * return [] + * + * result = [] # <<<<<<<<<<<<<< + * pos = src.core.pos + * cigar_p = pysam_bam_get_cigar(src) */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_buffer, __pyx_n_s_raw); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1922, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_20 = __Pyx_PyObject_AsWritableUString(__pyx_t_4); if (unlikely((!__pyx_t_20) && PyErr_Occurred())) __PYX_ERR(0, 1922, __pyx_L1_error) + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1984, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_result = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1918 - * struct.pack_into(fmt, buffer, 0, *args) - * # bam_aux_append copies data from value_ptr - * bam_aux_append(src, # <<<<<<<<<<<<<< - * tag, - * typecode, + /* "pysam/libcalignedsegment.pyx":1985 + * + * result = [] + * pos = src.core.pos # <<<<<<<<<<<<<< + * cigar_p = pysam_bam_get_cigar(src) + * l = 0 */ - bam_aux_append(__pyx_v_src, __pyx_t_19, __pyx_v_typecode, __pyx_v_value_size, ((uint8_t *)__pyx_t_20)); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __pyx_v_src->core.pos; + __pyx_v_pos = __pyx_t_4; - /* "pysam/libcalignedsegment.pyx":1923 - * value_size, - * buffer.raw) - * return # <<<<<<<<<<<<<< - * else: - * raise ValueError('unsupported value_type in set_option') + /* "pysam/libcalignedsegment.pyx":1986 + * result = [] + * pos = src.core.pos + * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + * l = 0 + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; + __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":1900 - * value_ptr = &float_value - * value_size = sizeof(float) - * elif typecode == 'B': # <<<<<<<<<<<<<< - * # the following goes through python, needs to be cleaned up - * # pack array using struct + /* "pysam/libcalignedsegment.pyx":1987 + * pos = src.core.pos + * cigar_p = pysam_bam_get_cigar(src) + * l = 0 # <<<<<<<<<<<<<< + * + * for k from 0 <= k < pysam_get_n_cigar(src): */ - break; - default: + __pyx_v_l = 0; - /* "pysam/libcalignedsegment.pyx":1925 - * return - * else: - * raise ValueError('unsupported value_type in set_option') # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1989 + * l = 0 * - * bam_aux_append(src, + * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1925, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1925, __pyx_L1_error) - break; - } + __pyx_t_5 = pysam_get_n_cigar(__pyx_v_src); + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) { - /* "pysam/libcalignedsegment.pyx":1928 + /* "pysam/libcalignedsegment.pyx":1990 * - * bam_aux_append(src, - * tag, # <<<<<<<<<<<<<< - * typecode, - * value_size, + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * if op == BAM_CMATCH: + */ + __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); + + /* "pysam/libcalignedsegment.pyx":1991 + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< + * if op == BAM_CMATCH: + * result.append((pos, pos + l)) + */ + __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT); + + /* "pysam/libcalignedsegment.pyx":1992 + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * if op == BAM_CMATCH: # <<<<<<<<<<<<<< + * result.append((pos, pos + l)) + * pos += l + */ + __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":1993 + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * if op == BAM_CMATCH: + * result.append((pos, pos + l)) # <<<<<<<<<<<<<< + * pos += l + * elif op == BAM_CDEL or op == BAM_CREF_SKIP: + */ + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1993, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __Pyx_PyInt_From_uint32_t((__pyx_v_pos + __pyx_v_l)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1993, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1993, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6); + __pyx_t_3 = 0; + __pyx_t_6 = 0; + __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1993, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pysam/libcalignedsegment.pyx":1994 + * if op == BAM_CMATCH: + * result.append((pos, pos + l)) + * pos += l # <<<<<<<<<<<<<< + * elif op == BAM_CDEL or op == BAM_CREF_SKIP: + * pos += l + */ + __pyx_v_pos = (__pyx_v_pos + __pyx_v_l); + + /* "pysam/libcalignedsegment.pyx":1992 + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * if op == BAM_CMATCH: # <<<<<<<<<<<<<< + * result.append((pos, pos + l)) + * pos += l */ - __pyx_t_19 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 1928, __pyx_L1_error) + goto __pyx_L6; + } - /* "pysam/libcalignedsegment.pyx":1927 - * raise ValueError('unsupported value_type in set_option') + /* "pysam/libcalignedsegment.pyx":1995 + * result.append((pos, pos + l)) + * pos += l + * elif op == BAM_CDEL or op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< + * pos += l * - * bam_aux_append(src, # <<<<<<<<<<<<<< - * tag, - * typecode, */ - bam_aux_append(__pyx_v_src, __pyx_t_19, __pyx_v_typecode, __pyx_v_value_size, __pyx_v_value_ptr); + __pyx_t_9 = ((__pyx_v_op == BAM_CDEL) != 0); + if (!__pyx_t_9) { + } else { + __pyx_t_2 = __pyx_t_9; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_9 = ((__pyx_v_op == BAM_CREF_SKIP) != 0); + __pyx_t_2 = __pyx_t_9; + __pyx_L7_bool_binop_done:; + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":1834 + /* "pysam/libcalignedsegment.pyx":1996 + * pos += l + * elif op == BAM_CDEL or op == BAM_CREF_SKIP: + * pos += l # <<<<<<<<<<<<<< * + * return result + */ + __pyx_v_pos = (__pyx_v_pos + __pyx_v_l); + + /* "pysam/libcalignedsegment.pyx":1995 + * result.append((pos, pos + l)) + * pos += l + * elif op == BAM_CDEL or op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< + * pos += l * - * cpdef set_tag(self, # <<<<<<<<<<<<<< - * tag, - * value, */ + } + __pyx_L6:; + } - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + /* "pysam/libcalignedsegment.pyx":1998 + * pos += l + * + * return result # <<<<<<<<<<<<<< + * + * def get_overlap(self, uint32_t start, uint32_t end): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":1962 + * return result + * + * def get_blocks(self): # <<<<<<<<<<<<<< + * """ a list of start and end positions of + * aligned gapless blocks. + */ + + /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.set_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_blocks", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_buffer); - __Pyx_XDECREF(__pyx_v_fmt); - __Pyx_XDECREF(__pyx_v_args); - __Pyx_XDECREF(__pyx_v_tag); - __Pyx_XDECREF(__pyx_v_value); + __Pyx_XDECREF(__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } +/* "pysam/libcalignedsegment.pyx":2000 + * return result + * + * def get_overlap(self, uint32_t start, uint32_t end): # <<<<<<<<<<<<<< + * """return number of aligned bases of read overlapping the interval + * *start* and *end* on the reference sequence. + */ + /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_33set_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_32set_tag[] = "AlignedSegment.set_tag(self, tag, value, value_type=None, replace=True)\nsets a particular field *tag* to *value* in the optional alignment\n section.\n\n *value_type* describes the type of *value* that is to entered\n into the alignment record.. It can be set explicitly to one\n of the valid one-letter type codes. If unset, an appropriate\n type will be chosen automatically.\n\n An existing value of the same *tag* will be overwritten unless\n replace is set to False. This is usually not recommened as a\n tag may only appear once in the optional alignment section.\n\n If *value* is None, the tag will be deleted.\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_33set_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_tag = 0; - PyObject *__pyx_v_value = 0; - PyObject *__pyx_v_value_type = 0; - PyObject *__pyx_v_replace = 0; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_43get_overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_42get_overlap[] = "AlignedSegment.get_overlap(self, uint32_t start, uint32_t end)\nreturn number of aligned bases of read overlapping the interval\n *start* and *end* on the reference sequence.\n\n Return None if cigar alignment is not available.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_43get_overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + uint32_t __pyx_v_start; + uint32_t __pyx_v_end; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("set_tag (wrapper)", 0); + __Pyx_RefNannySetupContext("get_overlap (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tag,&__pyx_n_s_value,&__pyx_n_s_value_type,&__pyx_n_s_replace,0}; - PyObject* values[4] = {0,0,0,0}; - - /* "pysam/libcalignedsegment.pyx":1837 - * tag, - * value, - * value_type=None, # <<<<<<<<<<<<<< - * replace=True): - * """sets a particular field *tag* to *value* in the optional alignment - */ - values[2] = ((PyObject *)Py_None); - - /* "pysam/libcalignedsegment.pyx":1838 - * value, - * value_type=None, - * replace=True): # <<<<<<<<<<<<<< - * """sets a particular field *tag* to *value* in the optional alignment - * section. - */ - values[3] = ((PyObject *)Py_True); + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_start,&__pyx_n_s_end,0}; + PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -21374,306 +24250,377 @@ static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_33set_tag kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tag)) != 0)) kw_args--; + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("set_tag", 0, 2, 4, 1); __PYX_ERR(0, 1834, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value_type); - if (value) { values[2] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_replace); - if (value) { values[3] = value; kw_args--; } + __Pyx_RaiseArgtupleInvalid("get_overlap", 1, 2, 2, 1); __PYX_ERR(0, 2000, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "set_tag") < 0)) __PYX_ERR(0, 1834, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_overlap") < 0)) __PYX_ERR(0, 2000, __pyx_L3_error) } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } - __pyx_v_tag = values[0]; - __pyx_v_value = values[1]; - __pyx_v_value_type = values[2]; - __pyx_v_replace = values[3]; + __pyx_v_start = __Pyx_PyInt_As_uint32_t(values[0]); if (unlikely((__pyx_v_start == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2000, __pyx_L3_error) + __pyx_v_end = __Pyx_PyInt_As_uint32_t(values[1]); if (unlikely((__pyx_v_end == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2000, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("set_tag", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1834, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get_overlap", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2000, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.set_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_overlap", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_32set_tag(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace); - - /* "pysam/libcalignedsegment.pyx":1834 - * - * - * cpdef set_tag(self, # <<<<<<<<<<<<<< - * tag, - * value, - */ + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_42get_overlap(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_start, __pyx_v_end); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_32set_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_42get_overlap(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, uint32_t __pyx_v_start, uint32_t __pyx_v_end) { + uint32_t __pyx_v_k; + uint32_t __pyx_v_pos; + uint32_t __pyx_v_overlap; + int __pyx_v_op; + int __pyx_v_o; + uint32_t *__pyx_v_cigar_p; + bam1_t *__pyx_v_src; + PyObject *__pyx_v_l = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag __pyx_t_2; - __Pyx_RefNannySetupContext("set_tag", 0); - __Pyx_TraceCall("set_tag (wrapper)", __pyx_f[0], 1834, 0, __PYX_ERR(0, 1834, __pyx_L1_error)); - __Pyx_XDECREF(__pyx_r); - __pyx_t_2.__pyx_n = 2; - __pyx_t_2.value_type = __pyx_v_value_type; - __pyx_t_2.replace = __pyx_v_replace; - __pyx_t_1 = __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment->set_tag(__pyx_v_self, __pyx_v_tag, __pyx_v_value, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1834, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + bam1_t *__pyx_t_1; + int __pyx_t_2; + int32_t __pyx_t_3; + uint32_t __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + uint32_t __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + uint32_t __pyx_t_10; + uint32_t __pyx_t_11; + int __pyx_t_12; + int __pyx_t_13; + __Pyx_RefNannySetupContext("get_overlap", 0); + __Pyx_TraceCall("get_overlap", __pyx_f[0], 2000, 0, __PYX_ERR(0, 2000, __pyx_L1_error)); - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.set_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2011 + * cdef bam1_t * src + * + * overlap = 0 # <<<<<<<<<<<<<< + * + * src = self._delegate + */ + __pyx_v_overlap = 0; -/* "pysam/libcalignedsegment.pyx":1933 - * value_ptr) + /* "pysam/libcalignedsegment.pyx":2013 + * overlap = 0 * - * cpdef has_tag(self, tag): # <<<<<<<<<<<<<< - * """returns true if the optional alignment section - * contains a given *tag*.""" + * src = self._delegate # <<<<<<<<<<<<<< + * if pysam_get_n_cigar(src) == 0: + * return None */ + __pyx_t_1 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_1; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_35has_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/ -static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_has_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch) { - uint8_t *__pyx_v_v; - PyObject *__pyx_v_btag = NULL; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - char const *__pyx_t_6; - __Pyx_RefNannySetupContext("has_tag", 0); - __Pyx_TraceCall("has_tag", __pyx_f[0], 1933, 0, __PYX_ERR(0, 1933, __pyx_L1_error)); - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_tag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1933, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_35has_tag)) { - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } + /* "pysam/libcalignedsegment.pyx":2014 + * + * src = self._delegate + * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< + * return None + * pos = src.core.pos + */ + __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":2015 + * src = self._delegate + * if pysam_get_n_cigar(src) == 0: + * return None # <<<<<<<<<<<<<< + * pos = src.core.pos + * o = 0 + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":2014 + * + * src = self._delegate + * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< + * return None + * pos = src.core.pos + */ + } + + /* "pysam/libcalignedsegment.pyx":2016 + * if pysam_get_n_cigar(src) == 0: + * return None + * pos = src.core.pos # <<<<<<<<<<<<<< + * o = 0 + * + */ + __pyx_t_3 = __pyx_v_src->core.pos; + __pyx_v_pos = __pyx_t_3; + + /* "pysam/libcalignedsegment.pyx":2017 + * return None + * pos = src.core.pos + * o = 0 # <<<<<<<<<<<<<< + * + * cigar_p = pysam_bam_get_cigar(src) + */ + __pyx_v_o = 0; + + /* "pysam/libcalignedsegment.pyx":2019 + * o = 0 + * + * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK + */ + __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); + + /* "pysam/libcalignedsegment.pyx":2020 + * + * cigar_p = pysam_bam_get_cigar(src) + * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + */ + __pyx_t_4 = pysam_get_n_cigar(__pyx_v_src); + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_4; __pyx_v_k++) { + + /* "pysam/libcalignedsegment.pyx":2021 + * cigar_p = pysam_bam_get_cigar(src) + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * + */ + __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); + + /* "pysam/libcalignedsegment.pyx":2022 + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< + * + * if op == BAM_CMATCH: + */ + __pyx_t_5 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2022, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_5); + __pyx_t_5 = 0; + + /* "pysam/libcalignedsegment.pyx":2024 + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * + * if op == BAM_CMATCH: # <<<<<<<<<<<<<< + * o = min( pos + l, end) - max( pos, start ) + * if o > 0: overlap += o + */ + __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":2025 + * + * if op == BAM_CMATCH: + * o = min( pos + l, end) - max( pos, start ) # <<<<<<<<<<<<<< + * if o > 0: overlap += o + * + */ + __pyx_t_6 = __pyx_v_end; + __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = PyNumber_Add(__pyx_t_5, __pyx_v_l); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyObject_RichCompare(__pyx_t_8, __pyx_t_7, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2025, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2025, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (__pyx_t_2) { + __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_5 = __pyx_t_9; + __pyx_t_9 = 0; + } else { + __Pyx_INCREF(__pyx_t_7); + __pyx_t_5 = __pyx_t_7; } - if (!__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_tag); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1933, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_6 = __pyx_v_start; + __pyx_t_10 = __pyx_v_pos; + if (((__pyx_t_6 > __pyx_t_10) != 0)) { + __pyx_t_11 = __pyx_t_6; } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_tag}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1933, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_tag}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1933, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1933, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; - __Pyx_INCREF(__pyx_v_tag); - __Pyx_GIVEREF(__pyx_v_tag); - PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_tag); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1933, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } + __pyx_t_11 = __pyx_t_10; } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = PyNumber_Subtract(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2025, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_o = __pyx_t_12; + + /* "pysam/libcalignedsegment.pyx":2026 + * if op == BAM_CMATCH: + * o = min( pos + l, end) - max( pos, start ) + * if o > 0: overlap += o # <<<<<<<<<<<<<< + * + * if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP: + */ + __pyx_t_2 = ((__pyx_v_o > 0) != 0); + if (__pyx_t_2) { + __pyx_v_overlap = (__pyx_v_overlap + __pyx_v_o); + } + + /* "pysam/libcalignedsegment.pyx":2024 + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * + * if op == BAM_CMATCH: # <<<<<<<<<<<<<< + * o = min( pos + l, end) - max( pos, start ) + * if o > 0: overlap += o + */ } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - /* "pysam/libcalignedsegment.pyx":1938 - * cdef uint8_t * v - * cdef int nvalues - * btag = force_bytes(tag) # <<<<<<<<<<<<<< - * v = bam_aux_get(self._delegate, btag) - * return v != NULL + /* "pysam/libcalignedsegment.pyx":2028 + * if o > 0: overlap += o + * + * if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< + * pos += l + * */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_tag, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1938, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_btag = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_13 = ((__pyx_v_op == BAM_CMATCH) != 0); + if (!__pyx_t_13) { + } else { + __pyx_t_2 = __pyx_t_13; + goto __pyx_L9_bool_binop_done; + } + __pyx_t_13 = ((__pyx_v_op == BAM_CDEL) != 0); + if (!__pyx_t_13) { + } else { + __pyx_t_2 = __pyx_t_13; + goto __pyx_L9_bool_binop_done; + } + __pyx_t_13 = ((__pyx_v_op == BAM_CREF_SKIP) != 0); + __pyx_t_2 = __pyx_t_13; + __pyx_L9_bool_binop_done:; + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":1939 - * cdef int nvalues - * btag = force_bytes(tag) - * v = bam_aux_get(self._delegate, btag) # <<<<<<<<<<<<<< - * return v != NULL + /* "pysam/libcalignedsegment.pyx":2029 + * + * if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP: + * pos += l # <<<<<<<<<<<<<< * + * return overlap */ - if (unlikely(__pyx_v_btag == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 1939, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2029, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2029, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_11 = __Pyx_PyInt_As_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_11 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2029, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_pos = __pyx_t_11; + + /* "pysam/libcalignedsegment.pyx":2028 + * if o > 0: overlap += o + * + * if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< + * pos += l + * + */ + } } - __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_btag); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 1939, __pyx_L1_error) - __pyx_v_v = bam_aux_get(__pyx_v_self->_delegate, __pyx_t_6); - /* "pysam/libcalignedsegment.pyx":1940 - * btag = force_bytes(tag) - * v = bam_aux_get(self._delegate, btag) - * return v != NULL # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2031 + * pos += l * - * cpdef get_tag(self, tag, with_value_type=False): + * return overlap # <<<<<<<<<<<<<< + * + * def get_cigar_stats(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_v != NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1940, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_overlap); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2031, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1933 - * value_ptr) + /* "pysam/libcalignedsegment.pyx":2000 + * return result * - * cpdef has_tag(self, tag): # <<<<<<<<<<<<<< - * """returns true if the optional alignment section - * contains a given *tag*.""" + * def get_overlap(self, uint32_t start, uint32_t end): # <<<<<<<<<<<<<< + * """return number of aligned bases of read overlapping the interval + * *start* and *end* on the reference sequence. */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.has_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_overlap", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_btag); + __Pyx_XDECREF(__pyx_v_l); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } +/* "pysam/libcalignedsegment.pyx":2033 + * return overlap + * + * def get_cigar_stats(self): # <<<<<<<<<<<<<< + * """summary of operations in cigar string. + * + */ + /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_35has_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_34has_tag[] = "AlignedSegment.has_tag(self, tag)\nreturns true if the optional alignment section\n contains a given *tag*."; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_35has_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_45get_cigar_stats(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_44get_cigar_stats[] = "AlignedSegment.get_cigar_stats(self)\nsummary of operations in cigar string.\n\n The output order in the array is \"MIDNSHP=X\" followed by a\n field for the NM tag. If the NM tag is not present, this\n field will always be 0.\n\n +-----+--------------+-----+\n |M |BAM_CMATCH |0 |\n +-----+--------------+-----+\n |I |BAM_CINS |1 |\n +-----+--------------+-----+\n |D |BAM_CDEL |2 |\n +-----+--------------+-----+\n |N |BAM_CREF_SKIP |3 |\n +-----+--------------+-----+\n |S |BAM_CSOFT_CLIP|4 |\n +-----+--------------+-----+\n |H |BAM_CHARD_CLIP|5 |\n +-----+--------------+-----+\n |P |BAM_CPAD |6 |\n +-----+--------------+-----+\n |= |BAM_CEQUAL |7 |\n +-----+--------------+-----+\n |X |BAM_CDIFF |8 |\n +-----+--------------+-----+\n |B |BAM_CBACK |9 |\n +-----+--------------+-----+\n |NM |NM tag |10 |\n +-----+--------------+-----+\n\n If no cigar string is present, empty arrays will be returned.\n\n Parameters\n ----------\n\n Returns\n -------\n\n arrays : two arrays. The first contains the nucleotide counts within\n each cigar operation, the second contains the number of blocks for\n each cigar operation.\n\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_45get_cigar_stats(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("has_tag (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_34has_tag(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tag)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_34has_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("has_tag", 0); - __Pyx_TraceCall("has_tag (wrapper)", __pyx_f[0], 1933, 0, __PYX_ERR(0, 1933, __pyx_L1_error)); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_has_tag(__pyx_v_self, __pyx_v_tag, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1933, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __Pyx_RefNannySetupContext("get_cigar_stats (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_44get_cigar_stats(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.has_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":1942 - * return v != NULL - * - * cpdef get_tag(self, tag, with_value_type=False): # <<<<<<<<<<<<<< - * """ - * retrieves data from the optional alignment section - */ - -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_37get_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_get_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag *__pyx_optional_args) { - PyObject *__pyx_v_with_value_type = ((PyObject *)Py_False); +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_44get_cigar_stats(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + int __pyx_v_nfields; + arrayobject *__pyx_v_base_counts = 0; + __Pyx_memviewslice __pyx_v_base_view = { 0, 0, { 0 }, { 0 }, { 0 } }; + arrayobject *__pyx_v_block_counts = 0; + __Pyx_memviewslice __pyx_v_block_view = { 0, 0, { 0 }, { 0 }, { 0 } }; + bam1_t *__pyx_v_src; + int __pyx_v_op; + uint32_t __pyx_v_l; + int32_t __pyx_v_k; + uint32_t *__pyx_v_cigar_p; uint8_t *__pyx_v_v; - CYTHON_UNUSED int __pyx_v_nvalues; - PyObject *__pyx_v_btag = NULL; - PyObject *__pyx_v_auxtype = NULL; - PyObject *__pyx_v_value = NULL; - CYTHON_UNUSED PyObject *__pyx_v_bytesize = NULL; - PyObject *__pyx_v_values = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -21683,1781 +24630,2163 @@ static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_get_tag(st PyObject *__pyx_t_4 = NULL; int __pyx_t_5; PyObject *__pyx_t_6 = NULL; - char const *__pyx_t_7; - int __pyx_t_8; + __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } }; + bam1_t *__pyx_t_8; int __pyx_t_9; - PyObject *(*__pyx_t_10)(PyObject *); - __Pyx_RefNannySetupContext("get_tag", 0); - __Pyx_TraceCall("get_tag", __pyx_f[0], 1942, 0, __PYX_ERR(0, 1942, __pyx_L1_error)); - if (__pyx_optional_args) { - if (__pyx_optional_args->__pyx_n > 0) { - __pyx_v_with_value_type = __pyx_optional_args->with_value_type; + uint32_t __pyx_t_10; + Py_ssize_t __pyx_t_11; + Py_ssize_t __pyx_t_12; + Py_ssize_t __pyx_t_13; + __Pyx_RefNannySetupContext("get_cigar_stats", 0); + __Pyx_TraceCall("get_cigar_stats", __pyx_f[0], 2033, 0, __PYX_ERR(0, 2033, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":2078 + * """ + * + * cdef int nfields = NCIGAR_CODES + 1 # <<<<<<<<<<<<<< + * + * cdef c_array.array base_counts = array.array( + */ + __pyx_v_nfields = (__pyx_v_5pysam_18libcalignedsegment_NCIGAR_CODES + 1); + + /* "pysam/libcalignedsegment.pyx":2080 + * cdef int nfields = NCIGAR_CODES + 1 + * + * cdef c_array.array base_counts = array.array( # <<<<<<<<<<<<<< + * "I", + * [0] * nfields) + */ + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libcalignedsegment.pyx":2082 + * cdef c_array.array base_counts = array.array( + * "I", + * [0] * nfields) # <<<<<<<<<<<<<< + * cdef uint32_t [:] base_view = base_counts + * cdef c_array.array block_counts = array.array( + */ + __pyx_t_2 = PyList_New(1 * ((__pyx_v_nfields<0) ? 0:__pyx_v_nfields)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2082, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + { Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < __pyx_v_nfields; __pyx_temp++) { + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyList_SET_ITEM(__pyx_t_2, __pyx_temp, __pyx_int_0); } } - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1942, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_37get_tag)) { - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_tag, __pyx_v_with_value_type}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1942, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_tag, __pyx_v_with_value_type}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1942, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1942, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; - } - __Pyx_INCREF(__pyx_v_tag); - __Pyx_GIVEREF(__pyx_v_tag); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_tag); - __Pyx_INCREF(__pyx_v_with_value_type); - __Pyx_GIVEREF(__pyx_v_with_value_type); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_with_value_type); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1942, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_4 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_5 = 1; } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "pysam/libcalignedsegment.pyx":1977 - * cdef uint8_t * v - * cdef int nvalues - * btag = force_bytes(tag) # <<<<<<<<<<<<<< - * v = bam_aux_get(self._delegate, btag) - * if v == NULL: - */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_tag, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1977, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_btag = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pysam/libcalignedsegment.pyx":1978 - * cdef int nvalues - * btag = force_bytes(tag) - * v = bam_aux_get(self._delegate, btag) # <<<<<<<<<<<<<< - * if v == NULL: - * raise KeyError("tag '%s' not present" % tag) - */ - if (unlikely(__pyx_v_btag == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 1978, __pyx_L1_error) } - __pyx_t_7 = __Pyx_PyBytes_AsString(__pyx_v_btag); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 1978, __pyx_L1_error) - __pyx_v_v = bam_aux_get(__pyx_v_self->_delegate, __pyx_t_7); - - /* "pysam/libcalignedsegment.pyx":1979 - * btag = force_bytes(tag) - * v = bam_aux_get(self._delegate, btag) - * if v == NULL: # <<<<<<<<<<<<<< - * raise KeyError("tag '%s' not present" % tag) - * if chr(v[0]) == "B": - */ - __pyx_t_8 = ((__pyx_v_v == NULL) != 0); - if (unlikely(__pyx_t_8)) { - - /* "pysam/libcalignedsegment.pyx":1980 - * v = bam_aux_get(self._delegate, btag) - * if v == NULL: - * raise KeyError("tag '%s' not present" % tag) # <<<<<<<<<<<<<< - * if chr(v[0]) == "B": - * auxtype = chr(v[0]) + chr(v[1]) - */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_tag_s_not_present, __pyx_v_tag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1980, __pyx_L1_error) + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_s_I, __pyx_t_2}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1980, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 1980, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":1979 - * btag = force_bytes(tag) - * v = bam_aux_get(self._delegate, btag) - * if v == NULL: # <<<<<<<<<<<<<< - * raise KeyError("tag '%s' not present" % tag) - * if chr(v[0]) == "B": - */ + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_s_I, __pyx_t_2}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_n_s_I); + __Pyx_GIVEREF(__pyx_n_s_I); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_n_s_I); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1981 - * if v == NULL: - * raise KeyError("tag '%s' not present" % tag) - * if chr(v[0]) == "B": # <<<<<<<<<<<<<< - * auxtype = chr(v[0]) + chr(v[1]) - * else: + /* "pysam/libcalignedsegment.pyx":2080 + * cdef int nfields = NCIGAR_CODES + 1 + * + * cdef c_array.array base_counts = array.array( # <<<<<<<<<<<<<< + * "I", + * [0] * nfields) */ - __pyx_t_2 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1981, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1981, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_B, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1981, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_8) { + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 2080, __pyx_L1_error) + __pyx_v_base_counts = ((arrayobject *)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":1982 - * raise KeyError("tag '%s' not present" % tag) - * if chr(v[0]) == "B": - * auxtype = chr(v[0]) + chr(v[1]) # <<<<<<<<<<<<<< - * else: - * auxtype = chr(v[0]) + /* "pysam/libcalignedsegment.pyx":2083 + * "I", + * [0] * nfields) + * cdef uint32_t [:] base_view = base_counts # <<<<<<<<<<<<<< + * cdef c_array.array block_counts = array.array( + * "I", */ - __pyx_t_1 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1982, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1982, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[1])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1982, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1982, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1982, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_auxtype = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn_uint32_t(((PyObject *)__pyx_v_base_counts), PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 2083, __pyx_L1_error) + __pyx_v_base_view = __pyx_t_7; + __pyx_t_7.memview = NULL; + __pyx_t_7.data = NULL; - /* "pysam/libcalignedsegment.pyx":1981 - * if v == NULL: - * raise KeyError("tag '%s' not present" % tag) - * if chr(v[0]) == "B": # <<<<<<<<<<<<<< - * auxtype = chr(v[0]) + chr(v[1]) - * else: + /* "pysam/libcalignedsegment.pyx":2084 + * [0] * nfields) + * cdef uint32_t [:] base_view = base_counts + * cdef c_array.array block_counts = array.array( # <<<<<<<<<<<<<< + * "I", + * [0] * nfields) */ - goto __pyx_L4; - } + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1984 - * auxtype = chr(v[0]) + chr(v[1]) - * else: - * auxtype = chr(v[0]) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2086 + * cdef c_array.array block_counts = array.array( + * "I", + * [0] * nfields) # <<<<<<<<<<<<<< + * cdef uint32_t [:] block_view = block_counts * - * if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S': */ - /*else*/ { - __pyx_t_1 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1984, __pyx_L1_error) + __pyx_t_3 = PyList_New(1 * ((__pyx_v_nfields<0) ? 0:__pyx_v_nfields)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2086, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + { Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < __pyx_v_nfields; __pyx_temp++) { + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyList_SET_ITEM(__pyx_t_3, __pyx_temp, __pyx_int_0); + } + } + __pyx_t_2 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_n_s_I, __pyx_t_3}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2084, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1984, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_auxtype = __pyx_t_3; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_n_s_I, __pyx_t_3}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2084, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_n_s_I); + __Pyx_GIVEREF(__pyx_n_s_I); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_5, __pyx_n_s_I); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_5, __pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - __pyx_L4:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libcalignedsegment.pyx":1986 - * auxtype = chr(v[0]) - * - * if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S': # <<<<<<<<<<<<<< - * value = bam_aux2i(v) - * elif auxtype == 'i' or auxtype == 'I': + /* "pysam/libcalignedsegment.pyx":2084 + * [0] * nfields) + * cdef uint32_t [:] base_view = base_counts + * cdef c_array.array block_counts = array.array( # <<<<<<<<<<<<<< + * "I", + * [0] * nfields) */ - __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_c, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1986, __pyx_L1_error) - if (!__pyx_t_9) { - } else { - __pyx_t_8 = __pyx_t_9; - goto __pyx_L6_bool_binop_done; - } - __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_C, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1986, __pyx_L1_error) - if (!__pyx_t_9) { - } else { - __pyx_t_8 = __pyx_t_9; - goto __pyx_L6_bool_binop_done; - } - __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_s, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1986, __pyx_L1_error) - if (!__pyx_t_9) { - } else { - __pyx_t_8 = __pyx_t_9; - goto __pyx_L6_bool_binop_done; - } - __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_S, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1986, __pyx_L1_error) - __pyx_t_8 = __pyx_t_9; - __pyx_L6_bool_binop_done:; - if (__pyx_t_8) { + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 2084, __pyx_L1_error) + __pyx_v_block_counts = ((arrayobject *)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":1987 + /* "pysam/libcalignedsegment.pyx":2087 + * "I", + * [0] * nfields) + * cdef uint32_t [:] block_view = block_counts # <<<<<<<<<<<<<< * - * if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S': - * value = bam_aux2i(v) # <<<<<<<<<<<<<< - * elif auxtype == 'i' or auxtype == 'I': - * value = bam_aux2i(v) + * cdef bam1_t * src = self._delegate */ - __pyx_t_3 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1987, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_value = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_nn_uint32_t(((PyObject *)__pyx_v_block_counts), PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 2087, __pyx_L1_error) + __pyx_v_block_view = __pyx_t_7; + __pyx_t_7.memview = NULL; + __pyx_t_7.data = NULL; - /* "pysam/libcalignedsegment.pyx":1986 - * auxtype = chr(v[0]) + /* "pysam/libcalignedsegment.pyx":2089 + * cdef uint32_t [:] block_view = block_counts * - * if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S': # <<<<<<<<<<<<<< - * value = bam_aux2i(v) - * elif auxtype == 'i' or auxtype == 'I': + * cdef bam1_t * src = self._delegate # <<<<<<<<<<<<<< + * cdef int op + * cdef uint32_t l */ - goto __pyx_L5; - } + __pyx_t_8 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_8; - /* "pysam/libcalignedsegment.pyx":1988 - * if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S': - * value = bam_aux2i(v) - * elif auxtype == 'i' or auxtype == 'I': # <<<<<<<<<<<<<< - * value = bam_aux2i(v) - * elif auxtype == 'f' or auxtype == 'F': + /* "pysam/libcalignedsegment.pyx":2093 + * cdef uint32_t l + * cdef int32_t k + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + * + * if cigar_p == NULL: */ - __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_i, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1988, __pyx_L1_error) - if (!__pyx_t_9) { - } else { - __pyx_t_8 = __pyx_t_9; - goto __pyx_L10_bool_binop_done; - } - __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_I, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1988, __pyx_L1_error) - __pyx_t_8 = __pyx_t_9; - __pyx_L10_bool_binop_done:; - if (__pyx_t_8) { + __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":1989 - * value = bam_aux2i(v) - * elif auxtype == 'i' or auxtype == 'I': - * value = bam_aux2i(v) # <<<<<<<<<<<<<< - * elif auxtype == 'f' or auxtype == 'F': - * value = bam_aux2f(v) + /* "pysam/libcalignedsegment.pyx":2095 + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) + * + * if cigar_p == NULL: # <<<<<<<<<<<<<< + * return None + * */ - __pyx_t_3 = __Pyx_PyInt_From_int32_t(((int32_t)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1989, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_value = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_9 = ((__pyx_v_cigar_p == NULL) != 0); + if (__pyx_t_9) { - /* "pysam/libcalignedsegment.pyx":1988 - * if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S': - * value = bam_aux2i(v) - * elif auxtype == 'i' or auxtype == 'I': # <<<<<<<<<<<<<< - * value = bam_aux2i(v) - * elif auxtype == 'f' or auxtype == 'F': + /* "pysam/libcalignedsegment.pyx":2096 + * + * if cigar_p == NULL: + * return None # <<<<<<<<<<<<<< + * + * for k from 0 <= k < pysam_get_n_cigar(src): */ - goto __pyx_L5; - } + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":1990 - * elif auxtype == 'i' or auxtype == 'I': - * value = bam_aux2i(v) - * elif auxtype == 'f' or auxtype == 'F': # <<<<<<<<<<<<<< - * value = bam_aux2f(v) - * elif auxtype == 'd' or auxtype == 'D': + /* "pysam/libcalignedsegment.pyx":2095 + * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) + * + * if cigar_p == NULL: # <<<<<<<<<<<<<< + * return None + * */ - __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_f, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1990, __pyx_L1_error) - if (!__pyx_t_9) { - } else { - __pyx_t_8 = __pyx_t_9; - goto __pyx_L12_bool_binop_done; } - __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_F, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1990, __pyx_L1_error) - __pyx_t_8 = __pyx_t_9; - __pyx_L12_bool_binop_done:; - if (__pyx_t_8) { - /* "pysam/libcalignedsegment.pyx":1991 - * value = bam_aux2i(v) - * elif auxtype == 'f' or auxtype == 'F': - * value = bam_aux2f(v) # <<<<<<<<<<<<<< - * elif auxtype == 'd' or auxtype == 'D': - * value = bam_aux2f(v) + /* "pysam/libcalignedsegment.pyx":2098 + * return None + * + * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT */ - __pyx_t_3 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_v))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1991, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_value = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_10 = pysam_get_n_cigar(__pyx_v_src); + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_10; __pyx_v_k++) { - /* "pysam/libcalignedsegment.pyx":1990 - * elif auxtype == 'i' or auxtype == 'I': - * value = bam_aux2i(v) - * elif auxtype == 'f' or auxtype == 'F': # <<<<<<<<<<<<<< - * value = bam_aux2f(v) - * elif auxtype == 'd' or auxtype == 'D': + /* "pysam/libcalignedsegment.pyx":2099 + * + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * base_view[op] += l */ - goto __pyx_L5; - } + __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); - /* "pysam/libcalignedsegment.pyx":1992 - * elif auxtype == 'f' or auxtype == 'F': - * value = bam_aux2f(v) - * elif auxtype == 'd' or auxtype == 'D': # <<<<<<<<<<<<<< - * value = bam_aux2f(v) - * elif auxtype == 'A': + /* "pysam/libcalignedsegment.pyx":2100 + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< + * base_view[op] += l + * block_view[op] += 1 */ - __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_d, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1992, __pyx_L1_error) - if (!__pyx_t_9) { - } else { - __pyx_t_8 = __pyx_t_9; - goto __pyx_L14_bool_binop_done; - } - __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_D, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1992, __pyx_L1_error) - __pyx_t_8 = __pyx_t_9; - __pyx_L14_bool_binop_done:; - if (__pyx_t_8) { + __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT); - /* "pysam/libcalignedsegment.pyx":1993 - * value = bam_aux2f(v) - * elif auxtype == 'd' or auxtype == 'D': - * value = bam_aux2f(v) # <<<<<<<<<<<<<< - * elif auxtype == 'A': - * # there might a more efficient way + /* "pysam/libcalignedsegment.pyx":2101 + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * base_view[op] += l # <<<<<<<<<<<<<< + * block_view[op] += 1 + * */ - __pyx_t_3 = PyFloat_FromDouble(((double)bam_aux2f(__pyx_v_v))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1993, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_value = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_11 = __pyx_v_op; + __pyx_t_5 = -1; + if (__pyx_t_11 < 0) { + __pyx_t_11 += __pyx_v_base_view.shape[0]; + if (unlikely(__pyx_t_11 < 0)) __pyx_t_5 = 0; + } else if (unlikely(__pyx_t_11 >= __pyx_v_base_view.shape[0])) __pyx_t_5 = 0; + if (unlikely(__pyx_t_5 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_5); + __PYX_ERR(0, 2101, __pyx_L1_error) + } + *((uint32_t *) ( /* dim=0 */ (__pyx_v_base_view.data + __pyx_t_11 * __pyx_v_base_view.strides[0]) )) += __pyx_v_l; - /* "pysam/libcalignedsegment.pyx":1992 - * elif auxtype == 'f' or auxtype == 'F': - * value = bam_aux2f(v) - * elif auxtype == 'd' or auxtype == 'D': # <<<<<<<<<<<<<< - * value = bam_aux2f(v) - * elif auxtype == 'A': + /* "pysam/libcalignedsegment.pyx":2102 + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * base_view[op] += l + * block_view[op] += 1 # <<<<<<<<<<<<<< + * + * cdef uint8_t * v = bam_aux_get(src, 'NM') */ - goto __pyx_L5; + __pyx_t_12 = __pyx_v_op; + __pyx_t_5 = -1; + if (__pyx_t_12 < 0) { + __pyx_t_12 += __pyx_v_block_view.shape[0]; + if (unlikely(__pyx_t_12 < 0)) __pyx_t_5 = 0; + } else if (unlikely(__pyx_t_12 >= __pyx_v_block_view.shape[0])) __pyx_t_5 = 0; + if (unlikely(__pyx_t_5 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_5); + __PYX_ERR(0, 2102, __pyx_L1_error) + } + *((uint32_t *) ( /* dim=0 */ (__pyx_v_block_view.data + __pyx_t_12 * __pyx_v_block_view.strides[0]) )) += 1; } - /* "pysam/libcalignedsegment.pyx":1994 - * elif auxtype == 'd' or auxtype == 'D': - * value = bam_aux2f(v) - * elif auxtype == 'A': # <<<<<<<<<<<<<< - * # there might a more efficient way - * # to convert a char into a string - */ - __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_A, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1994, __pyx_L1_error) - if (__pyx_t_8) { - - /* "pysam/libcalignedsegment.pyx":1997 - * # there might a more efficient way - * # to convert a char into a string - * value = '%c' % bam_aux2A(v) # <<<<<<<<<<<<<< - * elif auxtype == 'Z': - * value = charptr_to_str(bam_aux2Z(v)) - */ - __pyx_t_3 = __Pyx_PyInt_From_char(((char)bam_aux2A(__pyx_v_v))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1997, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_c_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1997, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_value = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pysam/libcalignedsegment.pyx":1994 - * elif auxtype == 'd' or auxtype == 'D': - * value = bam_aux2f(v) - * elif auxtype == 'A': # <<<<<<<<<<<<<< - * # there might a more efficient way - * # to convert a char into a string + /* "pysam/libcalignedsegment.pyx":2104 + * block_view[op] += 1 + * + * cdef uint8_t * v = bam_aux_get(src, 'NM') # <<<<<<<<<<<<<< + * if v != NULL: + * base_view[nfields - 1] = bam_aux2i(v) */ - goto __pyx_L5; - } + __pyx_v_v = bam_aux_get(__pyx_v_src, ((char const *)"NM")); - /* "pysam/libcalignedsegment.pyx":1998 - * # to convert a char into a string - * value = '%c' % bam_aux2A(v) - * elif auxtype == 'Z': # <<<<<<<<<<<<<< - * value = charptr_to_str(bam_aux2Z(v)) - * elif auxtype[0] == 'B': + /* "pysam/libcalignedsegment.pyx":2105 + * + * cdef uint8_t * v = bam_aux_get(src, 'NM') + * if v != NULL: # <<<<<<<<<<<<<< + * base_view[nfields - 1] = bam_aux2i(v) + * */ - __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_Z, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1998, __pyx_L1_error) - if (__pyx_t_8) { + __pyx_t_9 = ((__pyx_v_v != NULL) != 0); + if (__pyx_t_9) { - /* "pysam/libcalignedsegment.pyx":1999 - * value = '%c' % bam_aux2A(v) - * elif auxtype == 'Z': - * value = charptr_to_str(bam_aux2Z(v)) # <<<<<<<<<<<<<< - * elif auxtype[0] == 'B': - * bytesize, nvalues, values = convert_binary_tag(v + 1) + /* "pysam/libcalignedsegment.pyx":2106 + * cdef uint8_t * v = bam_aux_get(src, 'NM') + * if v != NULL: + * base_view[nfields - 1] = bam_aux2i(v) # <<<<<<<<<<<<<< + * + * return base_counts, block_counts */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str(((char *)bam_aux2Z(__pyx_v_v)), NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1999, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_value = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_13 = (__pyx_v_nfields - 1); + __pyx_t_5 = -1; + if (__pyx_t_13 < 0) { + __pyx_t_13 += __pyx_v_base_view.shape[0]; + if (unlikely(__pyx_t_13 < 0)) __pyx_t_5 = 0; + } else if (unlikely(__pyx_t_13 >= __pyx_v_base_view.shape[0])) __pyx_t_5 = 0; + if (unlikely(__pyx_t_5 != -1)) { + __Pyx_RaiseBufferIndexError(__pyx_t_5); + __PYX_ERR(0, 2106, __pyx_L1_error) + } + *((uint32_t *) ( /* dim=0 */ (__pyx_v_base_view.data + __pyx_t_13 * __pyx_v_base_view.strides[0]) )) = ((int32_t)bam_aux2i(__pyx_v_v)); - /* "pysam/libcalignedsegment.pyx":1998 - * # to convert a char into a string - * value = '%c' % bam_aux2A(v) - * elif auxtype == 'Z': # <<<<<<<<<<<<<< - * value = charptr_to_str(bam_aux2Z(v)) - * elif auxtype[0] == 'B': + /* "pysam/libcalignedsegment.pyx":2105 + * + * cdef uint8_t * v = bam_aux_get(src, 'NM') + * if v != NULL: # <<<<<<<<<<<<<< + * base_view[nfields - 1] = bam_aux2i(v) + * */ - goto __pyx_L5; } - /* "pysam/libcalignedsegment.pyx":2000 - * elif auxtype == 'Z': - * value = charptr_to_str(bam_aux2Z(v)) - * elif auxtype[0] == 'B': # <<<<<<<<<<<<<< - * bytesize, nvalues, values = convert_binary_tag(v + 1) - * value = values + /* "pysam/libcalignedsegment.pyx":2108 + * base_view[nfields - 1] = bam_aux2i(v) + * + * return base_counts, block_counts # <<<<<<<<<<<<<< + * + * ##################################################### */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_auxtype, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2000, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_B, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2000, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (likely(__pyx_t_8)) { + __Pyx_INCREF(((PyObject *)__pyx_v_base_counts)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_base_counts)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_base_counts)); + __Pyx_INCREF(((PyObject *)__pyx_v_block_counts)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_block_counts)); + PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_block_counts)); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2001 - * value = charptr_to_str(bam_aux2Z(v)) - * elif auxtype[0] == 'B': - * bytesize, nvalues, values = convert_binary_tag(v + 1) # <<<<<<<<<<<<<< - * value = values - * else: + /* "pysam/libcalignedsegment.pyx":2033 + * return overlap + * + * def get_cigar_stats(self): # <<<<<<<<<<<<<< + * """summary of operations in cigar string. + * */ - __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_convert_binary_tag((__pyx_v_v + 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2001, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 3)) { - if (size > 3) __Pyx_RaiseTooManyValuesError(3); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 2001, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 2); - } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_2 = PyList_GET_ITEM(sequence, 1); - __pyx_t_6 = PyList_GET_ITEM(sequence, 2); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_6); - #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2001, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2001, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2001, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - #endif - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2001, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_4)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L16_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L16_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 2; __pyx_t_6 = __pyx_t_10(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L16_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_4), 3) < 0) __PYX_ERR(0, 2001, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L17_unpacking_done; - __pyx_L16_unpacking_failed:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 2001, __pyx_L1_error) - __pyx_L17_unpacking_done:; - } - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2001, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_bytesize = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_v_nvalues = __pyx_t_5; - __pyx_v_values = __pyx_t_6; - __pyx_t_6 = 0; - /* "pysam/libcalignedsegment.pyx":2002 - * elif auxtype[0] == 'B': - * bytesize, nvalues, values = convert_binary_tag(v + 1) - * value = values # <<<<<<<<<<<<<< - * else: - * raise ValueError("unknown auxiliary type '%s'" % auxtype) - */ - __Pyx_INCREF(__pyx_v_values); - __pyx_v_value = __pyx_v_values; + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_cigar_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_base_counts); + __PYX_XDEC_MEMVIEW(&__pyx_v_base_view, 1); + __Pyx_XDECREF((PyObject *)__pyx_v_block_counts); + __PYX_XDEC_MEMVIEW(&__pyx_v_block_view, 1); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":2000 - * elif auxtype == 'Z': - * value = charptr_to_str(bam_aux2Z(v)) - * elif auxtype[0] == 'B': # <<<<<<<<<<<<<< - * bytesize, nvalues, values = convert_binary_tag(v + 1) - * value = values +/* "pysam/libcalignedsegment.pyx":2153 + * or None. + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * cdef uint32_t * cigar_p + * cdef bam1_t * src */ - goto __pyx_L5; - } - /* "pysam/libcalignedsegment.pyx":2004 - * value = values - * else: - * raise ValueError("unknown auxiliary type '%s'" % auxtype) # <<<<<<<<<<<<<< +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + uint32_t *__pyx_v_cigar_p; + bam1_t *__pyx_v_src; + uint32_t __pyx_v_op; + uint32_t __pyx_v_l; + uint32_t __pyx_v_k; + PyObject *__pyx_v_cigar = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + bam1_t *__pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + uint32_t __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2153, 0, __PYX_ERR(0, 2153, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":2159 + * cdef uint32_t k * - * if with_value_type: + * src = self._delegate # <<<<<<<<<<<<<< + * if pysam_get_n_cigar(src) == 0: + * return None */ - /*else*/ { - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_unknown_auxiliary_type_s, __pyx_v_auxtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2004, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2004, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 2004, __pyx_L1_error) - } - __pyx_L5:; + __pyx_t_1 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":2006 - * raise ValueError("unknown auxiliary type '%s'" % auxtype) + /* "pysam/libcalignedsegment.pyx":2160 + * + * src = self._delegate + * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< + * return None * - * if with_value_type: # <<<<<<<<<<<<<< - * return (value, auxtype) - * else: */ - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_with_value_type); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2006, __pyx_L1_error) - if (__pyx_t_8) { + __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0); + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":2007 + /* "pysam/libcalignedsegment.pyx":2161 + * src = self._delegate + * if pysam_get_n_cigar(src) == 0: + * return None # <<<<<<<<<<<<<< * - * if with_value_type: - * return (value, auxtype) # <<<<<<<<<<<<<< - * else: - * return value + * cigar = [] */ __Pyx_XDECREF(__pyx_r); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2007, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_value); - __Pyx_INCREF(__pyx_v_auxtype); - __Pyx_GIVEREF(__pyx_v_auxtype); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_auxtype); - __pyx_r = __pyx_t_6; - __pyx_t_6 = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2006 - * raise ValueError("unknown auxiliary type '%s'" % auxtype) + /* "pysam/libcalignedsegment.pyx":2160 + * + * src = self._delegate + * if pysam_get_n_cigar(src) == 0: # <<<<<<<<<<<<<< + * return None * - * if with_value_type: # <<<<<<<<<<<<<< - * return (value, auxtype) - * else: */ } - /* "pysam/libcalignedsegment.pyx":2009 - * return (value, auxtype) - * else: - * return value # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2163 + * return None * - * def get_tags(self, with_value_type=False): + * cigar = [] # <<<<<<<<<<<<<< + * + * cigar_p = pysam_bam_get_cigar(src); */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_value); - __pyx_r = __pyx_v_value; - goto __pyx_L0; - } + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2163, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_cigar = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1942 - * return v != NULL + /* "pysam/libcalignedsegment.pyx":2165 + * cigar = [] * - * cpdef get_tag(self, tag, with_value_type=False): # <<<<<<<<<<<<<< - * """ - * retrieves data from the optional alignment section + * cigar_p = pysam_bam_get_cigar(src); # <<<<<<<<<<<<<< + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK */ + __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src); - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_btag); - __Pyx_XDECREF(__pyx_v_auxtype); - __Pyx_XDECREF(__pyx_v_value); - __Pyx_XDECREF(__pyx_v_bytesize); - __Pyx_XDECREF(__pyx_v_values); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2166 + * + * cigar_p = pysam_bam_get_cigar(src); + * for k from 0 <= k < pysam_get_n_cigar(src): # <<<<<<<<<<<<<< + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + */ + __pyx_t_4 = pysam_get_n_cigar(__pyx_v_src); + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_4; __pyx_v_k++) { -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_37get_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_36get_tag[] = "AlignedSegment.get_tag(self, tag, with_value_type=False)\n\n retrieves data from the optional alignment section\n given a two-letter *tag* denoting the field.\n\n The returned value is cast into an appropriate python type.\n\n This method is the fastest way to access the optional\n alignment section if only few tags need to be retrieved.\n\n Parameters\n ----------\n\n tag :\n data tag.\n\n with_value_type : Optional[bool]\n if set to True, the return value is a tuple of (tag value, type code).\n (default False)\n\n Returns\n -------\n\n A python object with the value of the `tag`. The type of the\n object depends on the data type in the data record.\n\n Raises\n ------\n\n KeyError\n If `tag` is not present, a KeyError is raised.\n\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_37get_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_tag = 0; - PyObject *__pyx_v_with_value_type = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_tag (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tag,&__pyx_n_s_with_value_type,0}; - PyObject* values[2] = {0,0}; - values[1] = ((PyObject *)Py_False); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tag)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_with_value_type); - if (value) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_tag") < 0)) __PYX_ERR(0, 1942, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_tag = values[0]; - __pyx_v_with_value_type = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_tag", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1942, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_36get_tag(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_tag, __pyx_v_with_value_type); + /* "pysam/libcalignedsegment.pyx":2167 + * cigar_p = pysam_bam_get_cigar(src); + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK # <<<<<<<<<<<<<< + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * cigar.append((op, l)) + */ + __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK); - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2168 + * for k from 0 <= k < pysam_get_n_cigar(src): + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT # <<<<<<<<<<<<<< + * cigar.append((op, l)) + * return cigar + */ + __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT); -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_36get_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_with_value_type) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag __pyx_t_2; - __Pyx_RefNannySetupContext("get_tag", 0); - __Pyx_TraceCall("get_tag (wrapper)", __pyx_f[0], 1942, 0, __PYX_ERR(0, 1942, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":2169 + * op = cigar_p[k] & BAM_CIGAR_MASK + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * cigar.append((op, l)) # <<<<<<<<<<<<<< + * return cigar + * + */ + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_op); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2169, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_l); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2169, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2169, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __pyx_t_3 = 0; + __pyx_t_5 = 0; + __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_cigar, __pyx_t_6); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 2169, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + + /* "pysam/libcalignedsegment.pyx":2170 + * l = cigar_p[k] >> BAM_CIGAR_SHIFT + * cigar.append((op, l)) + * return cigar # <<<<<<<<<<<<<< + * + * def __set__(self, values): + */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2.__pyx_n = 1; - __pyx_t_2.with_value_type = __pyx_v_with_value_type; - __pyx_t_1 = __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment->get_tag(__pyx_v_self, __pyx_v_tag, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1942, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __Pyx_INCREF(__pyx_v_cigar); + __pyx_r = __pyx_v_cigar; goto __pyx_L0; + /* "pysam/libcalignedsegment.pyx":2153 + * or None. + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * cdef uint32_t * cigar_p + * cdef bam1_t * src + */ + /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.cigartuples.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_cigar); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2011 - * return value - * - * def get_tags(self, with_value_type=False): # <<<<<<<<<<<<<< - * """the fields in the optional aligment section. +/* "pysam/libcalignedsegment.pyx":2172 + * return cigar * + * def __set__(self, values): # <<<<<<<<<<<<<< + * cdef uint32_t * p + * cdef bam1_t * src */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_39get_tags(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_38get_tags[] = "AlignedSegment.get_tags(self, with_value_type=False)\nthe fields in the optional aligment section.\n\n Returns a list of all fields in the optional\n alignment section. Values are converted to appropriate python\n values. For example:\n\n [(NM, 2), (RG, \"GJP00TM04\")]\n\n If *with_value_type* is set, the value type as encode in\n the AlignedSegment record will be returned as well:\n\n [(NM, 2, \"i\"), (RG, \"GJP00TM04\", \"Z\")]\n\n This method will convert all values in the optional alignment\n section. When getting only one or few tags, please see\n :meth:`get_tag` for a quicker way to achieve this.\n\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_39get_tags(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_with_value_type = 0; - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_tags (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_with_value_type,0}; - PyObject* values[1] = {0}; - values[0] = ((PyObject *)Py_False); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_with_value_type); - if (value) { values[0] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_tags") < 0)) __PYX_ERR(0, 2011, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_with_value_type = values[0]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_tags", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2011, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_tags", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_38get_tags(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_with_value_type); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_values)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_38get_tags(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_with_value_type) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_values) { + uint32_t *__pyx_v_p; bam1_t *__pyx_v_src; - uint8_t *__pyx_v_s; - char __pyx_v_auxtag[3]; - char __pyx_v_auxtype; - uint8_t __pyx_v_byte_size; - int32_t __pyx_v_nvalues; - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_value = NULL; - PyObject *__pyx_r = NULL; + PyObject *__pyx_v_op = 0; + PyObject *__pyx_v_l = 0; + int __pyx_v_k; + uint32_t __pyx_v_ncigar; + bam1_t *__pyx_v_retval; + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations bam1_t *__pyx_t_1; int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; + int __pyx_t_3; PyObject *__pyx_t_4 = NULL; Py_ssize_t __pyx_t_5; - PyObject *__pyx_t_6 = NULL; + PyObject *(*__pyx_t_6)(PyObject *); PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; - PyObject *(*__pyx_t_9)(PyObject *); - uint8_t __pyx_t_10; - int32_t __pyx_t_11; - int __pyx_t_12; - __Pyx_RefNannySetupContext("get_tags", 0); - __Pyx_TraceCall("get_tags", __pyx_f[0], 2011, 0, __PYX_ERR(0, 2011, __pyx_L1_error)); + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *(*__pyx_t_11)(PyObject *); + uint32_t __pyx_t_12; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2172, 0, __PYX_ERR(0, 2172, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_values); - /* "pysam/libcalignedsegment.pyx":2039 - * cdef int32_t nvalues + /* "pysam/libcalignedsegment.pyx":2178 + * cdef int k * - * src = self._delegate # <<<<<<<<<<<<<< - * if src.l_data == 0: - * return [] + * k = 0 # <<<<<<<<<<<<<< + * + * src = self._delegate + */ + __pyx_v_k = 0; + + /* "pysam/libcalignedsegment.pyx":2180 + * k = 0 + * + * src = self._delegate # <<<<<<<<<<<<<< + * + * # get location of cigar string */ __pyx_t_1 = __pyx_v_self->_delegate; __pyx_v_src = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":2040 + /* "pysam/libcalignedsegment.pyx":2183 * - * src = self._delegate - * if src.l_data == 0: # <<<<<<<<<<<<<< - * return [] - * s = pysam_bam_get_aux(src) + * # get location of cigar string + * p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + * + * # empty values for cigar string */ - __pyx_t_2 = ((__pyx_v_src->l_data == 0) != 0); - if (__pyx_t_2) { + __pyx_v_p = pysam_bam_get_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":2041 - * src = self._delegate - * if src.l_data == 0: - * return [] # <<<<<<<<<<<<<< - * s = pysam_bam_get_aux(src) - * result = [] + /* "pysam/libcalignedsegment.pyx":2186 + * + * # empty values for cigar string + * if values is None: # <<<<<<<<<<<<<< + * values = [] + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2041, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __pyx_t_2 = (__pyx_v_values == Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { - /* "pysam/libcalignedsegment.pyx":2040 + /* "pysam/libcalignedsegment.pyx":2187 + * # empty values for cigar string + * if values is None: + * values = [] # <<<<<<<<<<<<<< + * + * cdef uint32_t ncigar = len(values) + */ + __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2187, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_values, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pysam/libcalignedsegment.pyx":2186 + * + * # empty values for cigar string + * if values is None: # <<<<<<<<<<<<<< + * values = [] * - * src = self._delegate - * if src.l_data == 0: # <<<<<<<<<<<<<< - * return [] - * s = pysam_bam_get_aux(src) */ } - /* "pysam/libcalignedsegment.pyx":2042 - * if src.l_data == 0: - * return [] - * s = pysam_bam_get_aux(src) # <<<<<<<<<<<<<< - * result = [] - * auxtag[2] = 0 + /* "pysam/libcalignedsegment.pyx":2189 + * values = [] + * + * cdef uint32_t ncigar = len(values) # <<<<<<<<<<<<<< + * + * cdef bam1_t * retval = pysam_bam_update(src, */ - __pyx_v_s = pysam_bam_get_aux(__pyx_v_src); + __pyx_t_5 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2189, __pyx_L1_error) + __pyx_v_ncigar = __pyx_t_5; - /* "pysam/libcalignedsegment.pyx":2043 - * return [] - * s = pysam_bam_get_aux(src) - * result = [] # <<<<<<<<<<<<<< - * auxtag[2] = 0 - * while s < (src.data + src.l_data): + /* "pysam/libcalignedsegment.pyx":2191 + * cdef uint32_t ncigar = len(values) + * + * cdef bam1_t * retval = pysam_bam_update(src, # <<<<<<<<<<<<<< + * pysam_get_n_cigar(src) * 4, + * ncigar * 4, */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2043, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_result = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_v_retval = pysam_bam_update(__pyx_v_src, (pysam_get_n_cigar(__pyx_v_src) * 4), (__pyx_v_ncigar * 4), ((uint8_t *)__pyx_v_p)); - /* "pysam/libcalignedsegment.pyx":2044 - * s = pysam_bam_get_aux(src) - * result = [] - * auxtag[2] = 0 # <<<<<<<<<<<<<< - * while s < (src.data + src.l_data): - * # get tag + /* "pysam/libcalignedsegment.pyx":2196 + * p) + * + * if retval == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate memory") + * */ - (__pyx_v_auxtag[2]) = 0; + __pyx_t_3 = ((__pyx_v_retval == NULL) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignedsegment.pyx":2045 - * result = [] - * auxtag[2] = 0 - * while s < (src.data + src.l_data): # <<<<<<<<<<<<<< - * # get tag - * auxtag[0] = s[0] + /* "pysam/libcalignedsegment.pyx":2197 + * + * if retval == NULL: + * raise MemoryError("could not allocate memory") # <<<<<<<<<<<<<< + * + * # length is number of cigar operations, not bytes */ - while (1) { - __pyx_t_2 = ((__pyx_v_s < (__pyx_v_src->data + __pyx_v_src->l_data)) != 0); - if (!__pyx_t_2) break; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2197, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2197, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2047 - * while s < (src.data + src.l_data): - * # get tag - * auxtag[0] = s[0] # <<<<<<<<<<<<<< - * auxtag[1] = s[1] - * s += 2 + /* "pysam/libcalignedsegment.pyx":2196 + * p) + * + * if retval == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate memory") + * */ - (__pyx_v_auxtag[0]) = (__pyx_v_s[0]); + } - /* "pysam/libcalignedsegment.pyx":2048 - * # get tag - * auxtag[0] = s[0] - * auxtag[1] = s[1] # <<<<<<<<<<<<<< - * s += 2 - * auxtype = s[0] + /* "pysam/libcalignedsegment.pyx":2200 + * + * # length is number of cigar operations, not bytes + * pysam_set_n_cigar(src, ncigar) # <<<<<<<<<<<<<< + * + * # re-acquire pointer to location in memory */ - (__pyx_v_auxtag[1]) = (__pyx_v_s[1]); + pysam_set_n_cigar(__pyx_v_src, __pyx_v_ncigar); - /* "pysam/libcalignedsegment.pyx":2049 - * auxtag[0] = s[0] - * auxtag[1] = s[1] - * s += 2 # <<<<<<<<<<<<<< - * auxtype = s[0] - * if auxtype in ('c', 'C'): + /* "pysam/libcalignedsegment.pyx":2204 + * # re-acquire pointer to location in memory + * # as it might have moved + * p = pysam_bam_get_cigar(src) # <<<<<<<<<<<<<< + * + * # insert cigar operations */ - __pyx_v_s = (__pyx_v_s + 2); + __pyx_v_p = pysam_bam_get_cigar(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":2050 - * auxtag[1] = s[1] - * s += 2 - * auxtype = s[0] # <<<<<<<<<<<<<< - * if auxtype in ('c', 'C'): - * value = bam_aux2i(s) + /* "pysam/libcalignedsegment.pyx":2207 + * + * # insert cigar operations + * for op, l in values: # <<<<<<<<<<<<<< + * p[k] = l << BAM_CIGAR_SHIFT | op + * k += 1 */ - __pyx_v_auxtype = (__pyx_v_s[0]); + if (likely(PyList_CheckExact(__pyx_v_values)) || PyTuple_CheckExact(__pyx_v_values)) { + __pyx_t_4 = __pyx_v_values; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2207, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2207, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_6)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 2207, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2207, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } else { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 2207, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2207, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } + } else { + __pyx_t_7 = __pyx_t_6(__pyx_t_4); + if (unlikely(!__pyx_t_7)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2207, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { + PyObject* sequence = __pyx_t_7; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 2207, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_8 = PyList_GET_ITEM(sequence, 0); + __pyx_t_9 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + #else + __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2207, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2207, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2207, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext; + index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L7_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L7_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) __PYX_ERR(0, 2207, __pyx_L1_error) + __pyx_t_11 = NULL; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L8_unpacking_done; + __pyx_L7_unpacking_failed:; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2207, __pyx_L1_error) + __pyx_L8_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_op, __pyx_t_8); + __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_9); + __pyx_t_9 = 0; - /* "pysam/libcalignedsegment.pyx":2051 - * s += 2 - * auxtype = s[0] - * if auxtype in ('c', 'C'): # <<<<<<<<<<<<<< - * value = bam_aux2i(s) - * s += 1 + /* "pysam/libcalignedsegment.pyx":2208 + * # insert cigar operations + * for op, l in values: + * p[k] = l << BAM_CIGAR_SHIFT | op # <<<<<<<<<<<<<< + * k += 1 + * */ - switch (__pyx_v_auxtype) { - case 'c': - case 'C': + __pyx_t_7 = __Pyx_PyInt_From_int(BAM_CIGAR_SHIFT); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2208, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = PyNumber_Lshift(__pyx_v_l, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2208, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyNumber_Or(__pyx_t_9, __pyx_v_op); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2208, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_12 = __Pyx_PyInt_As_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_12 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2208, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + (__pyx_v_p[__pyx_v_k]) = __pyx_t_12; - /* "pysam/libcalignedsegment.pyx":2052 - * auxtype = s[0] - * if auxtype in ('c', 'C'): - * value = bam_aux2i(s) # <<<<<<<<<<<<<< - * s += 1 - * elif auxtype in ('s', 'S'): + /* "pysam/libcalignedsegment.pyx":2209 + * for op, l in values: + * p[k] = l << BAM_CIGAR_SHIFT | op + * k += 1 # <<<<<<<<<<<<<< + * + * ## setting the cigar string requires updating the bin */ - __pyx_t_3 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2052, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3); - __pyx_t_3 = 0; + __pyx_v_k = (__pyx_v_k + 1); - /* "pysam/libcalignedsegment.pyx":2053 - * if auxtype in ('c', 'C'): - * value = bam_aux2i(s) - * s += 1 # <<<<<<<<<<<<<< - * elif auxtype in ('s', 'S'): - * value = bam_aux2i(s) + /* "pysam/libcalignedsegment.pyx":2207 + * + * # insert cigar operations + * for op, l in values: # <<<<<<<<<<<<<< + * p[k] = l << BAM_CIGAR_SHIFT | op + * k += 1 */ - __pyx_v_s = (__pyx_v_s + 1); + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignedsegment.pyx":2051 - * s += 2 - * auxtype = s[0] - * if auxtype in ('c', 'C'): # <<<<<<<<<<<<<< - * value = bam_aux2i(s) - * s += 1 + /* "pysam/libcalignedsegment.pyx":2212 + * + * ## setting the cigar string requires updating the bin + * update_bin(src) # <<<<<<<<<<<<<< + * + * cpdef set_tag(self, */ - break; + __pyx_f_5pysam_18libcalignedsegment_update_bin(__pyx_v_src); - /* "pysam/libcalignedsegment.pyx":2054 - * value = bam_aux2i(s) - * s += 1 - * elif auxtype in ('s', 'S'): # <<<<<<<<<<<<<< - * value = bam_aux2i(s) - * s += 2 + /* "pysam/libcalignedsegment.pyx":2172 + * return cigar + * + * def __set__(self, values): # <<<<<<<<<<<<<< + * cdef uint32_t * p + * cdef bam1_t * src */ - case 's': - case 'S': - /* "pysam/libcalignedsegment.pyx":2055 - * s += 1 - * elif auxtype in ('s', 'S'): - * value = bam_aux2i(s) # <<<<<<<<<<<<<< - * s += 2 - * elif auxtype in ('i', 'I'): - */ - __pyx_t_3 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2055, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3); - __pyx_t_3 = 0; + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.cigartuples.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_op); + __Pyx_XDECREF(__pyx_v_l); + __Pyx_XDECREF(__pyx_v_values); + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":2056 - * elif auxtype in ('s', 'S'): - * value = bam_aux2i(s) - * s += 2 # <<<<<<<<<<<<<< - * elif auxtype in ('i', 'I'): - * value = bam_aux2i(s) +/* "pysam/libcalignedsegment.pyx":2214 + * update_bin(src) + * + * cpdef set_tag(self, # <<<<<<<<<<<<<< + * tag, + * value, */ - __pyx_v_s = (__pyx_v_s + 2); - /* "pysam/libcalignedsegment.pyx":2054 - * value = bam_aux2i(s) - * s += 1 - * elif auxtype in ('s', 'S'): # <<<<<<<<<<<<<< - * value = bam_aux2i(s) - * s += 2 - */ - break; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_47set_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_set_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag *__pyx_optional_args) { - /* "pysam/libcalignedsegment.pyx":2057 - * value = bam_aux2i(s) - * s += 2 - * elif auxtype in ('i', 'I'): # <<<<<<<<<<<<<< - * value = bam_aux2i(s) - * s += 4 + /* "pysam/libcalignedsegment.pyx":2217 + * tag, + * value, + * value_type=None, # <<<<<<<<<<<<<< + * replace=True): + * """sets a particular field *tag* to *value* in the optional alignment */ - case 'i': - case 'I': + PyObject *__pyx_v_value_type = ((PyObject *)Py_None); - /* "pysam/libcalignedsegment.pyx":2058 - * s += 2 - * elif auxtype in ('i', 'I'): - * value = bam_aux2i(s) # <<<<<<<<<<<<<< - * s += 4 - * elif auxtype == 'f': + /* "pysam/libcalignedsegment.pyx":2218 + * value, + * value_type=None, + * replace=True): # <<<<<<<<<<<<<< + * """sets a particular field *tag* to *value* in the optional alignment + * section. */ - __pyx_t_3 = __Pyx_PyInt_From_int32_t(((int32_t)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2058, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3); - __pyx_t_3 = 0; + PyObject *__pyx_v_replace = ((PyObject *)Py_True); + int __pyx_v_value_size; + uint8_t *__pyx_v_value_ptr; + uint8_t *__pyx_v_existing_ptr; + float __pyx_v_float_value; + double __pyx_v_double_value; + int32_t __pyx_v_int32_t_value; + uint32_t __pyx_v_uint32_t_value; + int16_t __pyx_v_int16_t_value; + uint16_t __pyx_v_uint16_t_value; + int8_t __pyx_v_int8_t_value; + uint8_t __pyx_v_uint8_t_value; + bam1_t *__pyx_v_src; + PyObject *__pyx_v_buffer = 0; + uint8_t __pyx_v_typecode; + PyObject *__pyx_v_fmt = NULL; + PyObject *__pyx_v_args = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + bam1_t *__pyx_t_7; + Py_ssize_t __pyx_t_8; + int __pyx_t_9; + char const *__pyx_t_10; + int __pyx_t_11; + uint8_t __pyx_t_12; + struct __pyx_opt_args_5pysam_18libcalignedsegment_get_tag_typecode __pyx_t_13; + char *__pyx_t_14; + int32_t __pyx_t_15; + uint32_t __pyx_t_16; + int16_t __pyx_t_17; + uint16_t __pyx_t_18; + int8_t __pyx_t_19; + double __pyx_t_20; + float __pyx_t_21; + PyObject *(*__pyx_t_22)(PyObject *); + char const *__pyx_t_23; + uint8_t *__pyx_t_24; + __Pyx_RefNannySetupContext("set_tag", 0); + __Pyx_TraceCall("set_tag", __pyx_f[0], 2214, 0, __PYX_ERR(0, 2214, __pyx_L1_error)); + if (__pyx_optional_args) { + if (__pyx_optional_args->__pyx_n > 0) { + __pyx_v_value_type = __pyx_optional_args->value_type; + if (__pyx_optional_args->__pyx_n > 1) { + __pyx_v_replace = __pyx_optional_args->replace; + } + } + } + __Pyx_INCREF(__pyx_v_tag); + __Pyx_INCREF(__pyx_v_value); - /* "pysam/libcalignedsegment.pyx":2059 - * elif auxtype in ('i', 'I'): - * value = bam_aux2i(s) - * s += 4 # <<<<<<<<<<<<<< - * elif auxtype == 'f': - * value = bam_aux2f(s) + /* "pysam/libcalignedsegment.pyx":2214 + * update_bin(src) + * + * cpdef set_tag(self, # <<<<<<<<<<<<<< + * tag, + * value, */ - __pyx_v_s = (__pyx_v_s + 4); + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_tag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2214, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_47set_tag)) { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[5] = {__pyx_t_4, __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 4+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2214, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[5] = {__pyx_t_4, __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 4+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2214, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_6 = PyTuple_New(4+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2214, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_tag); + __Pyx_GIVEREF(__pyx_v_tag); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_tag); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_value); + __Pyx_INCREF(__pyx_v_value_type); + __Pyx_GIVEREF(__pyx_v_value_type); + PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_5, __pyx_v_value_type); + __Pyx_INCREF(__pyx_v_replace); + __Pyx_GIVEREF(__pyx_v_replace); + PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_5, __pyx_v_replace); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2214, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } - /* "pysam/libcalignedsegment.pyx":2057 - * value = bam_aux2i(s) - * s += 2 - * elif auxtype in ('i', 'I'): # <<<<<<<<<<<<<< - * value = bam_aux2i(s) - * s += 4 + /* "pysam/libcalignedsegment.pyx":2273 + * cdef int8_t int8_t_value + * cdef uint8_t uint8_t_value + * cdef bam1_t * src = self._delegate # <<<<<<<<<<<<<< + * cdef char * _value_type + * cdef c_array.array array_value */ - break; + __pyx_t_7 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_7; - /* "pysam/libcalignedsegment.pyx":2060 - * value = bam_aux2i(s) - * s += 4 - * elif auxtype == 'f': # <<<<<<<<<<<<<< - * value = bam_aux2f(s) - * s += 4 + /* "pysam/libcalignedsegment.pyx":2278 + * cdef object buffer + * + * if len(tag) != 2: # <<<<<<<<<<<<<< + * raise ValueError('Invalid tag: %s' % tag) + * */ - case 'f': + __pyx_t_8 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2278, __pyx_L1_error) + __pyx_t_9 = ((__pyx_t_8 != 2) != 0); + if (unlikely(__pyx_t_9)) { - /* "pysam/libcalignedsegment.pyx":2061 - * s += 4 - * elif auxtype == 'f': - * value = bam_aux2f(s) # <<<<<<<<<<<<<< - * s += 4 - * elif auxtype == 'd': + /* "pysam/libcalignedsegment.pyx":2279 + * + * if len(tag) != 2: + * raise ValueError('Invalid tag: %s' % tag) # <<<<<<<<<<<<<< + * + * tag = force_bytes(tag) */ - __pyx_t_3 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2061, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_tag_s, __pyx_v_tag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2279, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2279, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 2279, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2062 - * elif auxtype == 'f': - * value = bam_aux2f(s) - * s += 4 # <<<<<<<<<<<<<< - * elif auxtype == 'd': - * value = bam_aux2f(s) + /* "pysam/libcalignedsegment.pyx":2278 + * cdef object buffer + * + * if len(tag) != 2: # <<<<<<<<<<<<<< + * raise ValueError('Invalid tag: %s' % tag) + * */ - __pyx_v_s = (__pyx_v_s + 4); + } - /* "pysam/libcalignedsegment.pyx":2060 - * value = bam_aux2i(s) - * s += 4 - * elif auxtype == 'f': # <<<<<<<<<<<<<< - * value = bam_aux2f(s) - * s += 4 + /* "pysam/libcalignedsegment.pyx":2281 + * raise ValueError('Invalid tag: %s' % tag) + * + * tag = force_bytes(tag) # <<<<<<<<<<<<<< + * if replace: + * existing_ptr = bam_aux_get(src, tag) */ - break; + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_tag, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2281, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF_SET(__pyx_v_tag, __pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libcalignedsegment.pyx":2063 - * value = bam_aux2f(s) - * s += 4 - * elif auxtype == 'd': # <<<<<<<<<<<<<< - * value = bam_aux2f(s) - * s += 8 + /* "pysam/libcalignedsegment.pyx":2282 + * + * tag = force_bytes(tag) + * if replace: # <<<<<<<<<<<<<< + * existing_ptr = bam_aux_get(src, tag) + * if existing_ptr: */ - case 'd': + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_replace); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 2282, __pyx_L1_error) + if (__pyx_t_9) { - /* "pysam/libcalignedsegment.pyx":2064 - * s += 4 - * elif auxtype == 'd': - * value = bam_aux2f(s) # <<<<<<<<<<<<<< - * s += 8 - * elif auxtype == 'A': + /* "pysam/libcalignedsegment.pyx":2283 + * tag = force_bytes(tag) + * if replace: + * existing_ptr = bam_aux_get(src, tag) # <<<<<<<<<<<<<< + * if existing_ptr: + * bam_aux_del(src, existing_ptr) */ - __pyx_t_3 = PyFloat_FromDouble(((double)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2064, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_10 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 2283, __pyx_L1_error) + __pyx_v_existing_ptr = bam_aux_get(__pyx_v_src, __pyx_t_10); - /* "pysam/libcalignedsegment.pyx":2065 - * elif auxtype == 'd': - * value = bam_aux2f(s) - * s += 8 # <<<<<<<<<<<<<< - * elif auxtype == 'A': - * value = "%c" % bam_aux2A(s) + /* "pysam/libcalignedsegment.pyx":2284 + * if replace: + * existing_ptr = bam_aux_get(src, tag) + * if existing_ptr: # <<<<<<<<<<<<<< + * bam_aux_del(src, existing_ptr) + * */ - __pyx_v_s = (__pyx_v_s + 8); + __pyx_t_9 = (__pyx_v_existing_ptr != 0); + if (__pyx_t_9) { - /* "pysam/libcalignedsegment.pyx":2063 - * value = bam_aux2f(s) - * s += 4 - * elif auxtype == 'd': # <<<<<<<<<<<<<< - * value = bam_aux2f(s) - * s += 8 - */ - break; - - /* "pysam/libcalignedsegment.pyx":2066 - * value = bam_aux2f(s) - * s += 8 - * elif auxtype == 'A': # <<<<<<<<<<<<<< - * value = "%c" % bam_aux2A(s) - * s += 1 - */ - case 'A': - - /* "pysam/libcalignedsegment.pyx":2067 - * s += 8 - * elif auxtype == 'A': - * value = "%c" % bam_aux2A(s) # <<<<<<<<<<<<<< - * s += 1 - * elif auxtype in ('Z', 'H'): + /* "pysam/libcalignedsegment.pyx":2285 + * existing_ptr = bam_aux_get(src, tag) + * if existing_ptr: + * bam_aux_del(src, existing_ptr) # <<<<<<<<<<<<<< + * + * # setting value to None deletes a tag */ - __pyx_t_3 = __Pyx_PyInt_From_char(((char)bam_aux2A(__pyx_v_s))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2067, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_c_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2067, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_4); - __pyx_t_4 = 0; + (void)(bam_aux_del(__pyx_v_src, __pyx_v_existing_ptr)); - /* "pysam/libcalignedsegment.pyx":2068 - * elif auxtype == 'A': - * value = "%c" % bam_aux2A(s) - * s += 1 # <<<<<<<<<<<<<< - * elif auxtype in ('Z', 'H'): - * value = charptr_to_str(bam_aux2Z(s)) + /* "pysam/libcalignedsegment.pyx":2284 + * if replace: + * existing_ptr = bam_aux_get(src, tag) + * if existing_ptr: # <<<<<<<<<<<<<< + * bam_aux_del(src, existing_ptr) + * */ - __pyx_v_s = (__pyx_v_s + 1); + } - /* "pysam/libcalignedsegment.pyx":2066 - * value = bam_aux2f(s) - * s += 8 - * elif auxtype == 'A': # <<<<<<<<<<<<<< - * value = "%c" % bam_aux2A(s) - * s += 1 + /* "pysam/libcalignedsegment.pyx":2282 + * + * tag = force_bytes(tag) + * if replace: # <<<<<<<<<<<<<< + * existing_ptr = bam_aux_get(src, tag) + * if existing_ptr: */ - break; + } - /* "pysam/libcalignedsegment.pyx":2069 - * value = "%c" % bam_aux2A(s) - * s += 1 - * elif auxtype in ('Z', 'H'): # <<<<<<<<<<<<<< - * value = charptr_to_str(bam_aux2Z(s)) - * # +1 for NULL terminated string + /* "pysam/libcalignedsegment.pyx":2288 + * + * # setting value to None deletes a tag + * if value is None: # <<<<<<<<<<<<<< + * return + * */ - case 'Z': - case 'H': + __pyx_t_9 = (__pyx_v_value == Py_None); + __pyx_t_11 = (__pyx_t_9 != 0); + if (__pyx_t_11) { - /* "pysam/libcalignedsegment.pyx":2070 - * s += 1 - * elif auxtype in ('Z', 'H'): - * value = charptr_to_str(bam_aux2Z(s)) # <<<<<<<<<<<<<< - * # +1 for NULL terminated string - * s += len(value) + 1 + /* "pysam/libcalignedsegment.pyx":2289 + * # setting value to None deletes a tag + * if value is None: + * return # <<<<<<<<<<<<<< + * + * cdef uint8_t typecode = get_tag_typecode(value, value_type) */ - __pyx_t_4 = __pyx_f_5pysam_9libcutils_charptr_to_str(((char *)bam_aux2Z(__pyx_v_s)), NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2070, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_4); - __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2072 - * value = charptr_to_str(bam_aux2Z(s)) - * # +1 for NULL terminated string - * s += len(value) + 1 # <<<<<<<<<<<<<< - * elif auxtype == 'B': - * s += 1 + /* "pysam/libcalignedsegment.pyx":2288 + * + * # setting value to None deletes a tag + * if value is None: # <<<<<<<<<<<<<< + * return + * */ - __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2072, __pyx_L1_error) - __pyx_v_s = (__pyx_v_s + (__pyx_t_5 + 1)); + } - /* "pysam/libcalignedsegment.pyx":2069 - * value = "%c" % bam_aux2A(s) - * s += 1 - * elif auxtype in ('Z', 'H'): # <<<<<<<<<<<<<< - * value = charptr_to_str(bam_aux2Z(s)) - * # +1 for NULL terminated string + /* "pysam/libcalignedsegment.pyx":2291 + * return + * + * cdef uint8_t typecode = get_tag_typecode(value, value_type) # <<<<<<<<<<<<<< + * if typecode == 0: + * raise ValueError("can't guess type or invalid type code specified: {} {}".format( */ - break; + __pyx_t_13.__pyx_n = 1; + __pyx_t_13.value_type = __pyx_v_value_type; + __pyx_t_12 = __pyx_f_5pysam_18libcalignedsegment_get_tag_typecode(__pyx_v_value, &__pyx_t_13); + __pyx_v_typecode = __pyx_t_12; - /* "pysam/libcalignedsegment.pyx":2073 - * # +1 for NULL terminated string - * s += len(value) + 1 - * elif auxtype == 'B': # <<<<<<<<<<<<<< - * s += 1 - * byte_size, nvalues, value = convert_binary_tag(s) + /* "pysam/libcalignedsegment.pyx":2292 + * + * cdef uint8_t typecode = get_tag_typecode(value, value_type) + * if typecode == 0: # <<<<<<<<<<<<<< + * raise ValueError("can't guess type or invalid type code specified: {} {}".format( + * value, value_type)) */ - case 'B': + __pyx_t_11 = ((__pyx_v_typecode == 0) != 0); + if (unlikely(__pyx_t_11)) { - /* "pysam/libcalignedsegment.pyx":2074 - * s += len(value) + 1 - * elif auxtype == 'B': - * s += 1 # <<<<<<<<<<<<<< - * byte_size, nvalues, value = convert_binary_tag(s) - * # 5 for 1 char and 1 int + /* "pysam/libcalignedsegment.pyx":2293 + * cdef uint8_t typecode = get_tag_typecode(value, value_type) + * if typecode == 0: + * raise ValueError("can't guess type or invalid type code specified: {} {}".format( # <<<<<<<<<<<<<< + * value, value_type)) + * */ - __pyx_v_s = (__pyx_v_s + 1); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_can_t_guess_type_or_invalid_type, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libcalignedsegment.pyx":2075 - * elif auxtype == 'B': - * s += 1 - * byte_size, nvalues, value = convert_binary_tag(s) # <<<<<<<<<<<<<< - * # 5 for 1 char and 1 int - * s += 5 + (nvalues * byte_size) - 1 + /* "pysam/libcalignedsegment.pyx":2294 + * if typecode == 0: + * raise ValueError("can't guess type or invalid type code specified: {} {}".format( + * value, value_type)) # <<<<<<<<<<<<<< + * + * # sam_format1 for typecasting */ - __pyx_t_4 = __pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(__pyx_v_s); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2075, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { - PyObject* sequence = __pyx_t_4; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 3)) { - if (size > 3) __Pyx_RaiseTooManyValuesError(3); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 2075, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); - } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_6 = PyList_GET_ITEM(sequence, 1); - __pyx_t_7 = PyList_GET_ITEM(sequence, 2); - } + __pyx_t_3 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(__pyx_t_7); - #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2075, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2075, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2075, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_8 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2075, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - index = 2; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 3) < 0) __PYX_ERR(0, 2075, __pyx_L1_error) - __pyx_t_9 = NULL; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 2075, __pyx_L1_error) - __pyx_L7_unpacking_done:; + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_5 = 1; } - __pyx_t_10 = __Pyx_PyInt_As_uint8_t(__pyx_t_3); if (unlikely((__pyx_t_10 == ((uint8_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2075, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_11 = __Pyx_PyInt_As_int32_t(__pyx_t_6); if (unlikely((__pyx_t_11 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2075, __pyx_L1_error) + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_value, __pyx_v_value_type}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2293, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_value, __pyx_v_value_type}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2293, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_value); + __Pyx_INCREF(__pyx_v_value_type); + __Pyx_GIVEREF(__pyx_v_value_type); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_value_type); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_byte_size = __pyx_t_10; - __pyx_v_nvalues = __pyx_t_11; - __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_7); - __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":2077 - * byte_size, nvalues, value = convert_binary_tag(s) - * # 5 for 1 char and 1 int - * s += 5 + (nvalues * byte_size) - 1 # <<<<<<<<<<<<<< - * else: - * raise KeyError("unknown type '%s'" % auxtype) + /* "pysam/libcalignedsegment.pyx":2293 + * cdef uint8_t typecode = get_tag_typecode(value, value_type) + * if typecode == 0: + * raise ValueError("can't guess type or invalid type code specified: {} {}".format( # <<<<<<<<<<<<<< + * value, value_type)) + * */ - __pyx_v_s = (__pyx_v_s + ((5 + (__pyx_v_nvalues * __pyx_v_byte_size)) - 1)); + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2293, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2073 - * # +1 for NULL terminated string - * s += len(value) + 1 - * elif auxtype == 'B': # <<<<<<<<<<<<<< - * s += 1 - * byte_size, nvalues, value = convert_binary_tag(s) + /* "pysam/libcalignedsegment.pyx":2292 + * + * cdef uint8_t typecode = get_tag_typecode(value, value_type) + * if typecode == 0: # <<<<<<<<<<<<<< + * raise ValueError("can't guess type or invalid type code specified: {} {}".format( + * value, value_type)) */ - break; - default: + } - /* "pysam/libcalignedsegment.pyx":2079 - * s += 5 + (nvalues * byte_size) - 1 - * else: - * raise KeyError("unknown type '%s'" % auxtype) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2297 * - * s += 1 + * # sam_format1 for typecasting + * if typecode == 'Z': # <<<<<<<<<<<<<< + * value = force_bytes(value) + * value_ptr = value */ - __pyx_t_4 = __Pyx_PyInt_From_char(__pyx_v_auxtype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2079, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_unknown_type_s, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2079, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2079, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 2079, __pyx_L1_error) - break; - } + switch (__pyx_v_typecode) { + case 'Z': - /* "pysam/libcalignedsegment.pyx":2081 - * raise KeyError("unknown type '%s'" % auxtype) - * - * s += 1 # <<<<<<<<<<<<<< - * - * if with_value_type: + /* "pysam/libcalignedsegment.pyx":2298 + * # sam_format1 for typecasting + * if typecode == 'Z': + * value = force_bytes(value) # <<<<<<<<<<<<<< + * value_ptr = value + * value_size = len(value)+1 */ - __pyx_v_s = (__pyx_v_s + 1); + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2298, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":2083 - * s += 1 - * - * if with_value_type: # <<<<<<<<<<<<<< - * result.append((charptr_to_str(auxtag), value, chr(auxtype))) - * else: + /* "pysam/libcalignedsegment.pyx":2299 + * if typecode == 'Z': + * value = force_bytes(value) + * value_ptr = value # <<<<<<<<<<<<<< + * value_size = len(value)+1 + * elif typecode == 'H': */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_with_value_type); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2083, __pyx_L1_error) - if (__pyx_t_2) { + __pyx_t_14 = __Pyx_PyObject_AsWritableString(__pyx_v_value); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) __PYX_ERR(0, 2299, __pyx_L1_error) + __pyx_v_value_ptr = ((uint8_t *)((char *)__pyx_t_14)); - /* "pysam/libcalignedsegment.pyx":2084 - * - * if with_value_type: - * result.append((charptr_to_str(auxtag), value, chr(auxtype))) # <<<<<<<<<<<<<< - * else: - * result.append((charptr_to_str(auxtag), value)) + /* "pysam/libcalignedsegment.pyx":2300 + * value = force_bytes(value) + * value_ptr = value + * value_size = len(value)+1 # <<<<<<<<<<<<<< + * elif typecode == 'H': + * # Note that hex tags are stored the very same */ - __pyx_t_4 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_auxtag, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2084, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyInt_From_char(__pyx_v_auxtype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2084, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2084, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2084, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_value); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_6); - __pyx_t_4 = 0; - __pyx_t_6 = 0; - __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 2084, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2300, __pyx_L1_error) + __pyx_v_value_size = (__pyx_t_8 + 1); - /* "pysam/libcalignedsegment.pyx":2083 - * s += 1 + /* "pysam/libcalignedsegment.pyx":2297 * - * if with_value_type: # <<<<<<<<<<<<<< - * result.append((charptr_to_str(auxtag), value, chr(auxtype))) - * else: + * # sam_format1 for typecasting + * if typecode == 'Z': # <<<<<<<<<<<<<< + * value = force_bytes(value) + * value_ptr = value */ - goto __pyx_L8; - } + break; - /* "pysam/libcalignedsegment.pyx":2086 - * result.append((charptr_to_str(auxtag), value, chr(auxtype))) - * else: - * result.append((charptr_to_str(auxtag), value)) # <<<<<<<<<<<<<< - * - * return result + /* "pysam/libcalignedsegment.pyx":2301 + * value_ptr = value + * value_size = len(value)+1 + * elif typecode == 'H': # <<<<<<<<<<<<<< + * # Note that hex tags are stored the very same + * # way as Z string.s */ - /*else*/ { - __pyx_t_7 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_auxtag, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2086, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2086, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_value); - __pyx_t_7 = 0; - __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_6); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 2086, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __pyx_L8:; - } + case 'H': - /* "pysam/libcalignedsegment.pyx":2088 - * result.append((charptr_to_str(auxtag), value)) - * - * return result # <<<<<<<<<<<<<< - * - * def set_tags(self, tags): + /* "pysam/libcalignedsegment.pyx":2304 + * # Note that hex tags are stored the very same + * # way as Z string.s + * value = force_bytes(value) # <<<<<<<<<<<<<< + * value_ptr = value + * value_size = len(value)+1 */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result); - __pyx_r = __pyx_v_result; - goto __pyx_L0; + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":2011 - * return value - * - * def get_tags(self, with_value_type=False): # <<<<<<<<<<<<<< - * """the fields in the optional aligment section. - * + /* "pysam/libcalignedsegment.pyx":2305 + * # way as Z string.s + * value = force_bytes(value) + * value_ptr = value # <<<<<<<<<<<<<< + * value_size = len(value)+1 + * elif typecode == 'A' or typecode == 'a': */ + __pyx_t_14 = __Pyx_PyObject_AsWritableString(__pyx_v_value); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) __PYX_ERR(0, 2305, __pyx_L1_error) + __pyx_v_value_ptr = ((uint8_t *)((char *)__pyx_t_14)); - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_tags", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_value); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2306 + * value = force_bytes(value) + * value_ptr = value + * value_size = len(value)+1 # <<<<<<<<<<<<<< + * elif typecode == 'A' or typecode == 'a': + * value = force_bytes(value) + */ + __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2306, __pyx_L1_error) + __pyx_v_value_size = (__pyx_t_8 + 1); -/* "pysam/libcalignedsegment.pyx":2090 - * return result - * - * def set_tags(self, tags): # <<<<<<<<<<<<<< - * """sets the fields in the optional alignmest section with - * a list of (tag, value) tuples. + /* "pysam/libcalignedsegment.pyx":2301 + * value_ptr = value + * value_size = len(value)+1 + * elif typecode == 'H': # <<<<<<<<<<<<<< + * # Note that hex tags are stored the very same + * # way as Z string.s */ + break; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_41set_tags(PyObject *__pyx_v_self, PyObject *__pyx_v_tags); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_40set_tags[] = "AlignedSegment.set_tags(self, tags)\nsets the fields in the optional alignmest section with\n a list of (tag, value) tuples.\n\n The :term:`value type` of the values is determined from the\n python type. Optionally, a type may be given explicitly as\n a third value in the tuple, For example:\n\n x.set_tags([(NM, 2, \"i\"), (RG, \"GJP00TM04\", \"Z\")]\n\n This method will not enforce the rule that the same tag may appear\n only once in the optional alignment section.\n "; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_41set_tags(PyObject *__pyx_v_self, PyObject *__pyx_v_tags) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("set_tags (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_40set_tags(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tags)); + /* "pysam/libcalignedsegment.pyx":2307 + * value_ptr = value + * value_size = len(value)+1 + * elif typecode == 'A' or typecode == 'a': # <<<<<<<<<<<<<< + * value = force_bytes(value) + * value_ptr = value + */ + case 'A': + case 'a': - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2308 + * value_size = len(value)+1 + * elif typecode == 'A' or typecode == 'a': + * value = force_bytes(value) # <<<<<<<<<<<<<< + * value_ptr = value + * value_size = sizeof(char) + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2308, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); + __pyx_t_1 = 0; -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_40set_tags(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags) { - bam1_t *__pyx_v_src; - uint8_t *__pyx_v_s; - char *__pyx_v_temp; - int __pyx_v_new_size; - int __pyx_v_old_size; - PyObject *__pyx_v_fmt = NULL; - PyObject *__pyx_v_args = NULL; - PyObject *__pyx_v_buffer = NULL; - PyObject *__pyx_v_p = NULL; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - bam1_t *__pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - Py_ssize_t __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *(*__pyx_t_10)(PyObject *); - int __pyx_t_11; - PyObject *__pyx_t_12 = NULL; - char *__pyx_t_13; - __Pyx_RefNannySetupContext("set_tags", 0); - __Pyx_TraceCall("set_tags", __pyx_f[0], 2090, 0, __PYX_ERR(0, 2090, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":2309 + * elif typecode == 'A' or typecode == 'a': + * value = force_bytes(value) + * value_ptr = value # <<<<<<<<<<<<<< + * value_size = sizeof(char) + * typecode = 'A' + */ + __pyx_t_14 = __Pyx_PyObject_AsWritableString(__pyx_v_value); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) __PYX_ERR(0, 2309, __pyx_L1_error) + __pyx_v_value_ptr = ((uint8_t *)((char *)__pyx_t_14)); - /* "pysam/libcalignedsegment.pyx":2107 - * cdef uint8_t * s - * cdef char * temp - * cdef int new_size = 0 # <<<<<<<<<<<<<< - * cdef int old_size - * src = self._delegate + /* "pysam/libcalignedsegment.pyx":2310 + * value = force_bytes(value) + * value_ptr = value + * value_size = sizeof(char) # <<<<<<<<<<<<<< + * typecode = 'A' + * elif typecode == 'i': */ - __pyx_v_new_size = 0; + __pyx_v_value_size = (sizeof(char)); - /* "pysam/libcalignedsegment.pyx":2109 - * cdef int new_size = 0 - * cdef int old_size - * src = self._delegate # <<<<<<<<<<<<<< - * - * # convert and pack the data + /* "pysam/libcalignedsegment.pyx":2311 + * value_ptr = value + * value_size = sizeof(char) + * typecode = 'A' # <<<<<<<<<<<<<< + * elif typecode == 'i': + * int32_t_value = value */ - __pyx_t_1 = __pyx_v_self->_delegate; - __pyx_v_src = __pyx_t_1; + __pyx_v_typecode = 'A'; - /* "pysam/libcalignedsegment.pyx":2112 - * - * # convert and pack the data - * if tags is not None and len(tags) > 0: # <<<<<<<<<<<<<< - * fmt, args = packTags(tags) - * new_size = struct.calcsize(fmt) + /* "pysam/libcalignedsegment.pyx":2307 + * value_ptr = value + * value_size = len(value)+1 + * elif typecode == 'A' or typecode == 'a': # <<<<<<<<<<<<<< + * value = force_bytes(value) + * value_ptr = value */ - __pyx_t_3 = (__pyx_v_tags != Py_None); - __pyx_t_4 = (__pyx_t_3 != 0); - if (__pyx_t_4) { - } else { - __pyx_t_2 = __pyx_t_4; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_5 = PyObject_Length(__pyx_v_tags); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2112, __pyx_L1_error) - __pyx_t_4 = ((__pyx_t_5 > 0) != 0); - __pyx_t_2 = __pyx_t_4; - __pyx_L4_bool_binop_done:; - if (__pyx_t_2) { + break; - /* "pysam/libcalignedsegment.pyx":2113 - * # convert and pack the data - * if tags is not None and len(tags) > 0: - * fmt, args = packTags(tags) # <<<<<<<<<<<<<< - * new_size = struct.calcsize(fmt) - * buffer = ctypes.create_string_buffer(new_size) + /* "pysam/libcalignedsegment.pyx":2312 + * value_size = sizeof(char) + * typecode = 'A' + * elif typecode == 'i': # <<<<<<<<<<<<<< + * int32_t_value = value + * value_ptr = &int32_t_value */ - __pyx_t_6 = __pyx_f_5pysam_18libcalignedsegment_packTags(__pyx_v_tags); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2113, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { - PyObject* sequence = __pyx_t_6; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 2113, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_7 = PyList_GET_ITEM(sequence, 0); - __pyx_t_8 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_8); - #else - __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2113, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2113, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_9 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2113, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; - index = 0; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) __PYX_ERR(0, 2113, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 2113, __pyx_L1_error) - __pyx_L7_unpacking_done:; + case 'i': + + /* "pysam/libcalignedsegment.pyx":2313 + * typecode = 'A' + * elif typecode == 'i': + * int32_t_value = value # <<<<<<<<<<<<<< + * value_ptr = &int32_t_value + * value_size = sizeof(int32_t) + */ + __pyx_t_15 = __Pyx_PyInt_As_int32_t(__pyx_v_value); if (unlikely((__pyx_t_15 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2313, __pyx_L1_error) + __pyx_v_int32_t_value = __pyx_t_15; + + /* "pysam/libcalignedsegment.pyx":2314 + * elif typecode == 'i': + * int32_t_value = value + * value_ptr = &int32_t_value # <<<<<<<<<<<<<< + * value_size = sizeof(int32_t) + * elif typecode == 'I': + */ + __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_int32_t_value)); + + /* "pysam/libcalignedsegment.pyx":2315 + * int32_t_value = value + * value_ptr = &int32_t_value + * value_size = sizeof(int32_t) # <<<<<<<<<<<<<< + * elif typecode == 'I': + * uint32_t_value = value + */ + __pyx_v_value_size = (sizeof(int32_t)); + + /* "pysam/libcalignedsegment.pyx":2312 + * value_size = sizeof(char) + * typecode = 'A' + * elif typecode == 'i': # <<<<<<<<<<<<<< + * int32_t_value = value + * value_ptr = &int32_t_value + */ + break; + + /* "pysam/libcalignedsegment.pyx":2316 + * value_ptr = &int32_t_value + * value_size = sizeof(int32_t) + * elif typecode == 'I': # <<<<<<<<<<<<<< + * uint32_t_value = value + * value_ptr = &uint32_t_value + */ + case 'I': + + /* "pysam/libcalignedsegment.pyx":2317 + * value_size = sizeof(int32_t) + * elif typecode == 'I': + * uint32_t_value = value # <<<<<<<<<<<<<< + * value_ptr = &uint32_t_value + * value_size = sizeof(uint32_t) + */ + __pyx_t_16 = __Pyx_PyInt_As_uint32_t(__pyx_v_value); if (unlikely((__pyx_t_16 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2317, __pyx_L1_error) + __pyx_v_uint32_t_value = __pyx_t_16; + + /* "pysam/libcalignedsegment.pyx":2318 + * elif typecode == 'I': + * uint32_t_value = value + * value_ptr = &uint32_t_value # <<<<<<<<<<<<<< + * value_size = sizeof(uint32_t) + * elif typecode == 's': + */ + __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_uint32_t_value)); + + /* "pysam/libcalignedsegment.pyx":2319 + * uint32_t_value = value + * value_ptr = &uint32_t_value + * value_size = sizeof(uint32_t) # <<<<<<<<<<<<<< + * elif typecode == 's': + * int16_t_value = value + */ + __pyx_v_value_size = (sizeof(uint32_t)); + + /* "pysam/libcalignedsegment.pyx":2316 + * value_ptr = &int32_t_value + * value_size = sizeof(int32_t) + * elif typecode == 'I': # <<<<<<<<<<<<<< + * uint32_t_value = value + * value_ptr = &uint32_t_value + */ + break; + + /* "pysam/libcalignedsegment.pyx":2320 + * value_ptr = &uint32_t_value + * value_size = sizeof(uint32_t) + * elif typecode == 's': # <<<<<<<<<<<<<< + * int16_t_value = value + * value_ptr = &int16_t_value + */ + case 's': + + /* "pysam/libcalignedsegment.pyx":2321 + * value_size = sizeof(uint32_t) + * elif typecode == 's': + * int16_t_value = value # <<<<<<<<<<<<<< + * value_ptr = &int16_t_value + * value_size = sizeof(int16_t) + */ + __pyx_t_17 = __Pyx_PyInt_As_int16_t(__pyx_v_value); if (unlikely((__pyx_t_17 == ((int16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2321, __pyx_L1_error) + __pyx_v_int16_t_value = __pyx_t_17; + + /* "pysam/libcalignedsegment.pyx":2322 + * elif typecode == 's': + * int16_t_value = value + * value_ptr = &int16_t_value # <<<<<<<<<<<<<< + * value_size = sizeof(int16_t) + * elif typecode == 'S': + */ + __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_int16_t_value)); + + /* "pysam/libcalignedsegment.pyx":2323 + * int16_t_value = value + * value_ptr = &int16_t_value + * value_size = sizeof(int16_t) # <<<<<<<<<<<<<< + * elif typecode == 'S': + * uint16_t_value = value + */ + __pyx_v_value_size = (sizeof(int16_t)); + + /* "pysam/libcalignedsegment.pyx":2320 + * value_ptr = &uint32_t_value + * value_size = sizeof(uint32_t) + * elif typecode == 's': # <<<<<<<<<<<<<< + * int16_t_value = value + * value_ptr = &int16_t_value + */ + break; + + /* "pysam/libcalignedsegment.pyx":2324 + * value_ptr = &int16_t_value + * value_size = sizeof(int16_t) + * elif typecode == 'S': # <<<<<<<<<<<<<< + * uint16_t_value = value + * value_ptr = &uint16_t_value + */ + case 'S': + + /* "pysam/libcalignedsegment.pyx":2325 + * value_size = sizeof(int16_t) + * elif typecode == 'S': + * uint16_t_value = value # <<<<<<<<<<<<<< + * value_ptr = &uint16_t_value + * value_size = sizeof(uint16_t) + */ + __pyx_t_18 = __Pyx_PyInt_As_uint16_t(__pyx_v_value); if (unlikely((__pyx_t_18 == ((uint16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2325, __pyx_L1_error) + __pyx_v_uint16_t_value = __pyx_t_18; + + /* "pysam/libcalignedsegment.pyx":2326 + * elif typecode == 'S': + * uint16_t_value = value + * value_ptr = &uint16_t_value # <<<<<<<<<<<<<< + * value_size = sizeof(uint16_t) + * elif typecode == 'c': + */ + __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_uint16_t_value)); + + /* "pysam/libcalignedsegment.pyx":2327 + * uint16_t_value = value + * value_ptr = &uint16_t_value + * value_size = sizeof(uint16_t) # <<<<<<<<<<<<<< + * elif typecode == 'c': + * int8_t_value = value + */ + __pyx_v_value_size = (sizeof(uint16_t)); + + /* "pysam/libcalignedsegment.pyx":2324 + * value_ptr = &int16_t_value + * value_size = sizeof(int16_t) + * elif typecode == 'S': # <<<<<<<<<<<<<< + * uint16_t_value = value + * value_ptr = &uint16_t_value + */ + break; + + /* "pysam/libcalignedsegment.pyx":2328 + * value_ptr = &uint16_t_value + * value_size = sizeof(uint16_t) + * elif typecode == 'c': # <<<<<<<<<<<<<< + * int8_t_value = value + * value_ptr = &int8_t_value + */ + case 'c': + + /* "pysam/libcalignedsegment.pyx":2329 + * value_size = sizeof(uint16_t) + * elif typecode == 'c': + * int8_t_value = value # <<<<<<<<<<<<<< + * value_ptr = &int8_t_value + * value_size = sizeof(int8_t) + */ + __pyx_t_19 = __Pyx_PyInt_As_int8_t(__pyx_v_value); if (unlikely((__pyx_t_19 == ((int8_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2329, __pyx_L1_error) + __pyx_v_int8_t_value = __pyx_t_19; + + /* "pysam/libcalignedsegment.pyx":2330 + * elif typecode == 'c': + * int8_t_value = value + * value_ptr = &int8_t_value # <<<<<<<<<<<<<< + * value_size = sizeof(int8_t) + * elif typecode == 'C': + */ + __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_int8_t_value)); + + /* "pysam/libcalignedsegment.pyx":2331 + * int8_t_value = value + * value_ptr = &int8_t_value + * value_size = sizeof(int8_t) # <<<<<<<<<<<<<< + * elif typecode == 'C': + * uint8_t_value = value + */ + __pyx_v_value_size = (sizeof(int8_t)); + + /* "pysam/libcalignedsegment.pyx":2328 + * value_ptr = &uint16_t_value + * value_size = sizeof(uint16_t) + * elif typecode == 'c': # <<<<<<<<<<<<<< + * int8_t_value = value + * value_ptr = &int8_t_value + */ + break; + + /* "pysam/libcalignedsegment.pyx":2332 + * value_ptr = &int8_t_value + * value_size = sizeof(int8_t) + * elif typecode == 'C': # <<<<<<<<<<<<<< + * uint8_t_value = value + * value_ptr = &uint8_t_value + */ + case 'C': + + /* "pysam/libcalignedsegment.pyx":2333 + * value_size = sizeof(int8_t) + * elif typecode == 'C': + * uint8_t_value = value # <<<<<<<<<<<<<< + * value_ptr = &uint8_t_value + * value_size = sizeof(uint8_t) + */ + __pyx_t_12 = __Pyx_PyInt_As_uint8_t(__pyx_v_value); if (unlikely((__pyx_t_12 == ((uint8_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2333, __pyx_L1_error) + __pyx_v_uint8_t_value = __pyx_t_12; + + /* "pysam/libcalignedsegment.pyx":2334 + * elif typecode == 'C': + * uint8_t_value = value + * value_ptr = &uint8_t_value # <<<<<<<<<<<<<< + * value_size = sizeof(uint8_t) + * elif typecode == 'd': + */ + __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_uint8_t_value)); + + /* "pysam/libcalignedsegment.pyx":2335 + * uint8_t_value = value + * value_ptr = &uint8_t_value + * value_size = sizeof(uint8_t) # <<<<<<<<<<<<<< + * elif typecode == 'd': + * double_value = value + */ + __pyx_v_value_size = (sizeof(uint8_t)); + + /* "pysam/libcalignedsegment.pyx":2332 + * value_ptr = &int8_t_value + * value_size = sizeof(int8_t) + * elif typecode == 'C': # <<<<<<<<<<<<<< + * uint8_t_value = value + * value_ptr = &uint8_t_value + */ + break; + + /* "pysam/libcalignedsegment.pyx":2336 + * value_ptr = &uint8_t_value + * value_size = sizeof(uint8_t) + * elif typecode == 'd': # <<<<<<<<<<<<<< + * double_value = value + * value_ptr = &double_value + */ + case 'd': + + /* "pysam/libcalignedsegment.pyx":2337 + * value_size = sizeof(uint8_t) + * elif typecode == 'd': + * double_value = value # <<<<<<<<<<<<<< + * value_ptr = &double_value + * value_size = sizeof(double) + */ + __pyx_t_20 = __pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_20 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 2337, __pyx_L1_error) + __pyx_v_double_value = __pyx_t_20; + + /* "pysam/libcalignedsegment.pyx":2338 + * elif typecode == 'd': + * double_value = value + * value_ptr = &double_value # <<<<<<<<<<<<<< + * value_size = sizeof(double) + * elif typecode == 'f': + */ + __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_double_value)); + + /* "pysam/libcalignedsegment.pyx":2339 + * double_value = value + * value_ptr = &double_value + * value_size = sizeof(double) # <<<<<<<<<<<<<< + * elif typecode == 'f': + * float_value = value + */ + __pyx_v_value_size = (sizeof(double)); + + /* "pysam/libcalignedsegment.pyx":2336 + * value_ptr = &uint8_t_value + * value_size = sizeof(uint8_t) + * elif typecode == 'd': # <<<<<<<<<<<<<< + * double_value = value + * value_ptr = &double_value + */ + break; + + /* "pysam/libcalignedsegment.pyx":2340 + * value_ptr = &double_value + * value_size = sizeof(double) + * elif typecode == 'f': # <<<<<<<<<<<<<< + * float_value = value + * value_ptr = &float_value + */ + case 'f': + + /* "pysam/libcalignedsegment.pyx":2341 + * value_size = sizeof(double) + * elif typecode == 'f': + * float_value = value # <<<<<<<<<<<<<< + * value_ptr = &float_value + * value_size = sizeof(float) + */ + __pyx_t_21 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_21 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 2341, __pyx_L1_error) + __pyx_v_float_value = __pyx_t_21; + + /* "pysam/libcalignedsegment.pyx":2342 + * elif typecode == 'f': + * float_value = value + * value_ptr = &float_value # <<<<<<<<<<<<<< + * value_size = sizeof(float) + * elif typecode == 'B': + */ + __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_float_value)); + + /* "pysam/libcalignedsegment.pyx":2343 + * float_value = value + * value_ptr = &float_value + * value_size = sizeof(float) # <<<<<<<<<<<<<< + * elif typecode == 'B': + * # the following goes through python, needs to be cleaned up + */ + __pyx_v_value_size = (sizeof(float)); + + /* "pysam/libcalignedsegment.pyx":2340 + * value_ptr = &double_value + * value_size = sizeof(double) + * elif typecode == 'f': # <<<<<<<<<<<<<< + * float_value = value + * value_ptr = &float_value + */ + break; + + /* "pysam/libcalignedsegment.pyx":2344 + * value_ptr = &float_value + * value_size = sizeof(float) + * elif typecode == 'B': # <<<<<<<<<<<<<< + * # the following goes through python, needs to be cleaned up + * # pack array using struct + */ + case 'B': + + /* "pysam/libcalignedsegment.pyx":2347 + * # the following goes through python, needs to be cleaned up + * # pack array using struct + * fmt, args = pack_tags([(tag, value, value_type)]) # <<<<<<<<<<<<<< + * + * # remove tag and type code as set by bam_aux_append + */ + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_tag); + __Pyx_GIVEREF(__pyx_v_tag); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_tag); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_value); + __Pyx_INCREF(__pyx_v_value_type); + __Pyx_GIVEREF(__pyx_v_value_type); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_value_type); + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_pack_tags(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 2347, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2347, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_22 = Py_TYPE(__pyx_t_3)->tp_iternext; + index = 0; __pyx_t_2 = __pyx_t_22(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L8_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 1; __pyx_t_6 = __pyx_t_22(__pyx_t_3); if (unlikely(!__pyx_t_6)) goto __pyx_L8_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_22(__pyx_t_3), 2) < 0) __PYX_ERR(0, 2347, __pyx_L1_error) + __pyx_t_22 = NULL; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L9_unpacking_done; + __pyx_L8_unpacking_failed:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_22 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2347, __pyx_L1_error) + __pyx_L9_unpacking_done:; } - __pyx_v_fmt = __pyx_t_7; - __pyx_t_7 = 0; - __pyx_v_args = __pyx_t_8; - __pyx_t_8 = 0; + __pyx_v_fmt = __pyx_t_2; + __pyx_t_2 = 0; + __pyx_v_args = __pyx_t_6; + __pyx_t_6 = 0; - /* "pysam/libcalignedsegment.pyx":2114 - * if tags is not None and len(tags) > 0: - * fmt, args = packTags(tags) - * new_size = struct.calcsize(fmt) # <<<<<<<<<<<<<< - * buffer = ctypes.create_string_buffer(new_size) - * struct.pack_into(fmt, + /* "pysam/libcalignedsegment.pyx":2351 + * # remove tag and type code as set by bam_aux_append + * # first four chars of format (<2sB) + * fmt = '<' + fmt[4:] # <<<<<<<<<<<<<< + * # first two values to pack + * args = args[2:] */ - __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2114, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_calcsize); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2114, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_fmt, 4, 0, NULL, NULL, &__pyx_slice__36, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyNumber_Add(__pyx_kp_s__4, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_fmt, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libcalignedsegment.pyx":2353 + * fmt = '<' + fmt[4:] + * # first two values to pack + * args = args[2:] # <<<<<<<<<<<<<< + * value_size = struct.calcsize(fmt) + * # buffer will be freed when object goes out of scope + */ + __pyx_t_6 = __Pyx_PyObject_GetSlice(__pyx_v_args, 2, 0, NULL, NULL, &__pyx_slice__37, 1, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libcalignedsegment.pyx":2354 + * # first two values to pack + * args = args[2:] + * value_size = struct.calcsize(fmt) # <<<<<<<<<<<<<< + * # buffer will be freed when object goes out of scope + * buffer = ctypes.create_string_buffer(value_size) + */ + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2354, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_calcsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2354, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); + __Pyx_DECREF_SET(__pyx_t_2, function); } } - if (!__pyx_t_8) { - __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_fmt); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2114, __pyx_L1_error) + if (!__pyx_t_1) { + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_fmt); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2354, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_fmt}; - __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2114, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_fmt}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2354, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GOTREF(__pyx_t_6); } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_fmt}; - __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2114, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_fmt}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2354, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GOTREF(__pyx_t_6); } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2114, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2354, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __pyx_t_1 = NULL; __Pyx_INCREF(__pyx_v_fmt); __Pyx_GIVEREF(__pyx_v_fmt); - PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_fmt); - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2114, __pyx_L1_error) + PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_fmt); + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2354, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2114, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2354, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_new_size = __pyx_t_11; + __pyx_v_value_size = __pyx_t_5; - /* "pysam/libcalignedsegment.pyx":2115 - * fmt, args = packTags(tags) - * new_size = struct.calcsize(fmt) - * buffer = ctypes.create_string_buffer(new_size) # <<<<<<<<<<<<<< - * struct.pack_into(fmt, - * buffer, + /* "pysam/libcalignedsegment.pyx":2356 + * value_size = struct.calcsize(fmt) + * # buffer will be freed when object goes out of scope + * buffer = ctypes.create_string_buffer(value_size) # <<<<<<<<<<<<<< + * struct.pack_into(fmt, buffer, 0, *args) + * # bam_aux_append copies data from value_ptr */ - __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_ctypes); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_create_string_buffer); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_new_size); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_8); + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_ctypes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2356, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_create_string_buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2356, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_value_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2356, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); + __Pyx_DECREF_SET(__pyx_t_3, function); } } - if (!__pyx_t_8) { - __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2115, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (!__pyx_t_1) { + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2356, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_6); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; - __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2115, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_2}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2356, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; - __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2115, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_2}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2356, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else #endif { - __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_8); __pyx_t_8 = NULL; - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2115, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2356, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL; + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2356, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_buffer = __pyx_t_6; __pyx_t_6 = 0; - /* "pysam/libcalignedsegment.pyx":2116 - * new_size = struct.calcsize(fmt) - * buffer = ctypes.create_string_buffer(new_size) - * struct.pack_into(fmt, # <<<<<<<<<<<<<< - * buffer, - * 0, + /* "pysam/libcalignedsegment.pyx":2357 + * # buffer will be freed when object goes out of scope + * buffer = ctypes.create_string_buffer(value_size) + * struct.pack_into(fmt, buffer, 0, *args) # <<<<<<<<<<<<<< + * # bam_aux_append copies data from value_ptr + * bam_aux_append(src, */ - __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2116, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2357, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_pack_into); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_pack_into); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pysam/libcalignedsegment.pyx":2117 - * buffer = ctypes.create_string_buffer(new_size) - * struct.pack_into(fmt, - * buffer, # <<<<<<<<<<<<<< - * 0, - * *args) - */ - __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2116, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2357, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_INCREF(__pyx_v_fmt); __Pyx_GIVEREF(__pyx_v_fmt); @@ -23468,261 +26797,311 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_40set_tag __Pyx_INCREF(__pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_int_0); - - /* "pysam/libcalignedsegment.pyx":2116 - * new_size = struct.calcsize(fmt) - * buffer = ctypes.create_string_buffer(new_size) - * struct.pack_into(fmt, # <<<<<<<<<<<<<< - * buffer, - * 0, - */ - __pyx_t_12 = __Pyx_PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_7 = PyNumber_Add(__pyx_t_6, __pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyNumber_Add(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "pysam/libcalignedsegment.pyx":2112 - * - * # convert and pack the data - * if tags is not None and len(tags) > 0: # <<<<<<<<<<<<<< - * fmt, args = packTags(tags) - * new_size = struct.calcsize(fmt) - */ - } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignedsegment.pyx":2124 - * # If total_size == 0, the aux field will be - * # empty - * old_size = pysam_bam_get_l_aux(src) # <<<<<<<<<<<<<< - * pysam_bam_update(src, - * old_size, + /* "pysam/libcalignedsegment.pyx":2360 + * # bam_aux_append copies data from value_ptr + * bam_aux_append(src, + * tag, # <<<<<<<<<<<<<< + * typecode, + * value_size, */ - __pyx_v_old_size = pysam_bam_get_l_aux(__pyx_v_src); + __pyx_t_23 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_23) && PyErr_Occurred())) __PYX_ERR(0, 2360, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2125 - * # empty - * old_size = pysam_bam_get_l_aux(src) - * pysam_bam_update(src, # <<<<<<<<<<<<<< - * old_size, - * new_size, + /* "pysam/libcalignedsegment.pyx":2363 + * typecode, + * value_size, + * buffer.raw) # <<<<<<<<<<<<<< + * return + * else: */ - (void)(pysam_bam_update(__pyx_v_src, __pyx_v_old_size, __pyx_v_new_size, pysam_bam_get_aux(__pyx_v_src))); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_buffer, __pyx_n_s_raw); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2363, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_24 = __Pyx_PyObject_AsWritableUString(__pyx_t_4); if (unlikely((!__pyx_t_24) && PyErr_Occurred())) __PYX_ERR(0, 2363, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2131 - * - * # copy data only if there is any - * if new_size > 0: # <<<<<<<<<<<<<< - * - * # get location of new data + /* "pysam/libcalignedsegment.pyx":2359 + * struct.pack_into(fmt, buffer, 0, *args) + * # bam_aux_append copies data from value_ptr + * bam_aux_append(src, # <<<<<<<<<<<<<< + * tag, + * typecode, */ - __pyx_t_2 = ((__pyx_v_new_size > 0) != 0); - if (__pyx_t_2) { + bam_aux_append(__pyx_v_src, __pyx_t_23, __pyx_v_typecode, __pyx_v_value_size, ((uint8_t *)__pyx_t_24)); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignedsegment.pyx":2134 - * - * # get location of new data - * s = pysam_bam_get_aux(src) # <<<<<<<<<<<<<< - * - * # check if there is direct path from buffer.raw to tmp + /* "pysam/libcalignedsegment.pyx":2364 + * value_size, + * buffer.raw) + * return # <<<<<<<<<<<<<< + * else: + * raise ValueError('unsupported value_type {} in set_option'.format(typecode)) */ - __pyx_v_s = pysam_bam_get_aux(__pyx_v_src); + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2137 - * - * # check if there is direct path from buffer.raw to tmp - * p = buffer.raw # <<<<<<<<<<<<<< - * # create handle to make sure buffer stays alive long - * # enough for memcpy, see issue 129 + /* "pysam/libcalignedsegment.pyx":2344 + * value_ptr = &float_value + * value_size = sizeof(float) + * elif typecode == 'B': # <<<<<<<<<<<<<< + * # the following goes through python, needs to be cleaned up + * # pack array using struct */ - if (unlikely(!__pyx_v_buffer)) { __Pyx_RaiseUnboundLocalError("buffer"); __PYX_ERR(0, 2137, __pyx_L1_error) } - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_buffer, __pyx_n_s_raw); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_v_p = __pyx_t_12; - __pyx_t_12 = 0; + break; + default: - /* "pysam/libcalignedsegment.pyx":2140 - * # create handle to make sure buffer stays alive long - * # enough for memcpy, see issue 129 - * temp = p # <<<<<<<<<<<<<< - * memcpy(s, temp, new_size) + /* "pysam/libcalignedsegment.pyx":2366 + * return + * else: + * raise ValueError('unsupported value_type {} in set_option'.format(typecode)) # <<<<<<<<<<<<<< * + * bam_aux_append(src, */ - __pyx_t_13 = __Pyx_PyObject_AsWritableString(__pyx_v_p); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) __PYX_ERR(0, 2140, __pyx_L1_error) - __pyx_v_temp = __pyx_t_13; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unsupported_value_type_in_set_op, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_From_uint8_t(__pyx_v_typecode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_6) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2366, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_3}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2366, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_3}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2366, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 2366, __pyx_L1_error) + break; + } - /* "pysam/libcalignedsegment.pyx":2141 - * # enough for memcpy, see issue 129 - * temp = p - * memcpy(s, temp, new_size) # <<<<<<<<<<<<<< - * + /* "pysam/libcalignedsegment.pyx":2369 * + * bam_aux_append(src, + * tag, # <<<<<<<<<<<<<< + * typecode, + * value_size, */ - (void)(memcpy(__pyx_v_s, __pyx_v_temp, __pyx_v_new_size)); + __pyx_t_23 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_23) && PyErr_Occurred())) __PYX_ERR(0, 2369, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2131 - * - * # copy data only if there is any - * if new_size > 0: # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2368 + * raise ValueError('unsupported value_type {} in set_option'.format(typecode)) * - * # get location of new data + * bam_aux_append(src, # <<<<<<<<<<<<<< + * tag, + * typecode, */ - } + bam_aux_append(__pyx_v_src, __pyx_t_23, __pyx_v_typecode, __pyx_v_value_size, __pyx_v_value_ptr); - /* "pysam/libcalignedsegment.pyx":2090 - * return result + /* "pysam/libcalignedsegment.pyx":2214 + * update_bin(src) * - * def set_tags(self, tags): # <<<<<<<<<<<<<< - * """sets the fields in the optional alignmest section with - * a list of (tag, value) tuples. + * cpdef set_tag(self, # <<<<<<<<<<<<<< + * tag, + * value, */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.set_tags", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.set_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_buffer); __Pyx_XDECREF(__pyx_v_fmt); __Pyx_XDECREF(__pyx_v_args); - __Pyx_XDECREF(__pyx_v_buffer); - __Pyx_XDECREF(__pyx_v_p); + __Pyx_XDECREF(__pyx_v_tag); + __Pyx_XDECREF(__pyx_v_value); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2159 - * property qname: - * """deprecated, use query_name instead""" - * def __get__(self): return self.query_name # <<<<<<<<<<<<<< - * def __set__(self, v): self.query_name = v - * property tid: - */ - /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qname_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qname_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_47set_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_46set_tag[] = "AlignedSegment.set_tag(self, tag, value, value_type=None, replace=True)\nsets a particular field *tag* to *value* in the optional alignment\n section.\n\n *value_type* describes the type of *value* that is to entered\n into the alignment record. It can be set explicitly to one of\n the valid one-letter type codes. If unset, an appropriate type\n will be chosen automatically based on the python type of\n *value*.\n\n An existing value of the same *tag* will be overwritten unless\n *replace* is set to False. This is usually not recommened as a\n tag may only appear once in the optional alignment section.\n\n If *value* is None, the tag will be deleted.\n\n This method accepts valid SAM specification value types, which\n are::\n \n A: printable char\n i: signed int\n f: float\n Z: printable string\n H: Byte array in hex format\n B: Integer or numeric array\n\n Additionally, it will accept the integer BAM types ('cCsSI')\n\n For htslib compatibility, 'a' is synonymous with 'A' and the\n method accepts a 'd' type code for a double precision float.\n\n When deducing the type code by the python type of *value*, the\n following mapping is applied::\n \n i: python int\n f: python float\n Z: python str or bytes\n B: python array.array, list or tuple\n \n Note that a single character string will be output as 'Z' and\n not 'A' as the former is the more general type.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_47set_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_tag = 0; + PyObject *__pyx_v_value = 0; + PyObject *__pyx_v_value_type = 0; + PyObject *__pyx_v_replace = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qname___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qname___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2159, 0, __PYX_ERR(0, 2159, __pyx_L1_error)); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qname.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + __Pyx_RefNannySetupContext("set_tag (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tag,&__pyx_n_s_value,&__pyx_n_s_value_type,&__pyx_n_s_replace,0}; + PyObject* values[4] = {0,0,0,0}; -/* "pysam/libcalignedsegment.pyx":2160 - * """deprecated, use query_name instead""" - * def __get__(self): return self.query_name - * def __set__(self, v): self.query_name = v # <<<<<<<<<<<<<< - * property tid: - * """deprecated, use reference_id instead""" + /* "pysam/libcalignedsegment.pyx":2217 + * tag, + * value, + * value_type=None, # <<<<<<<<<<<<<< + * replace=True): + * """sets a particular field *tag* to *value* in the optional alignment */ + values[2] = ((PyObject *)Py_None); -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qname_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qname_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2160, 0, __PYX_ERR(0, 2160, __pyx_L1_error)); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_name, __pyx_v_v) < 0) __PYX_ERR(0, 2160, __pyx_L1_error) - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qname.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + /* "pysam/libcalignedsegment.pyx":2218 + * value, + * value_type=None, + * replace=True): # <<<<<<<<<<<<<< + * """sets a particular field *tag* to *value* in the optional alignment + * section. + */ + values[3] = ((PyObject *)Py_True); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tag)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("set_tag", 0, 2, 4, 1); __PYX_ERR(0, 2214, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value_type); + if (value) { values[2] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_replace); + if (value) { values[3] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "set_tag") < 0)) __PYX_ERR(0, 2214, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_tag = values[0]; + __pyx_v_value = values[1]; + __pyx_v_value_type = values[2]; + __pyx_v_replace = values[3]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("set_tag", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2214, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.set_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_46set_tag(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace); -/* "pysam/libcalignedsegment.pyx":2163 - * property tid: - * """deprecated, use reference_id instead""" - * def __get__(self): return self.reference_id # <<<<<<<<<<<<<< - * def __set__(self, v): self.reference_id = v - * property pos: + /* "pysam/libcalignedsegment.pyx":2214 + * update_bin(src) + * + * cpdef set_tag(self, # <<<<<<<<<<<<<< + * tag, + * value, */ -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3tid_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3tid___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3tid___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_46set_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2163, 0, __PYX_ERR(0, 2163, __pyx_L1_error)); + struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag __pyx_t_2; + __Pyx_RefNannySetupContext("set_tag", 0); + __Pyx_TraceCall("set_tag (wrapper)", __pyx_f[0], 2214, 0, __PYX_ERR(0, 2214, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2163, __pyx_L1_error) + __pyx_t_2.__pyx_n = 2; + __pyx_t_2.value_type = __pyx_v_value_type; + __pyx_t_2.replace = __pyx_v_replace; + __pyx_t_1 = __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment->set_tag(__pyx_v_self, __pyx_v_tag, __pyx_v_value, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -23731,7 +27110,7 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3tid___ge /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.set_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -23740,253 +27119,177 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3tid___ge return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2164 - * """deprecated, use reference_id instead""" - * def __get__(self): return self.reference_id - * def __set__(self, v): self.reference_id = v # <<<<<<<<<<<<<< - * property pos: - * """deprecated, use reference_start instead""" - */ - -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3tid_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3tid_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2164, 0, __PYX_ERR(0, 2164, __pyx_L1_error)); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id, __pyx_v_v) < 0) __PYX_ERR(0, 2164, __pyx_L1_error) - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tid.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2167 - * property pos: - * """deprecated, use reference_start instead""" - * def __get__(self): return self.reference_start # <<<<<<<<<<<<<< - * def __set__(self, v): self.reference_start = v - * property mapq: +/* "pysam/libcalignedsegment.pyx":2374 + * value_ptr) + * + * cpdef has_tag(self, tag): # <<<<<<<<<<<<<< + * """returns true if the optional alignment section + * contains a given *tag*.""" */ -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3pos_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3pos___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3pos___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_49has_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/ +static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_has_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch) { + uint8_t *__pyx_v_v; + PyObject *__pyx_v_btag = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2167, 0, __PYX_ERR(0, 2167, __pyx_L1_error)); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2167, __pyx_L1_error) + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + char const *__pyx_t_6; + __Pyx_RefNannySetupContext("has_tag", 0); + __Pyx_TraceCall("has_tag", __pyx_f[0], 2374, 0, __PYX_ERR(0, 2374, __pyx_L1_error)); + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_tag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2374, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_49has_tag)) { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_tag); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2374, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_tag}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2374, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_tag}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2374, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2374, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_INCREF(__pyx_v_tag); + __Pyx_GIVEREF(__pyx_v_tag); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_tag); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2374, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "pysam/libcalignedsegment.pyx":2379 + * cdef uint8_t * v + * cdef int nvalues + * btag = force_bytes(tag) # <<<<<<<<<<<<<< + * v = bam_aux_get(self._delegate, btag) + * return v != NULL + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_tag, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; + __pyx_v_btag = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* "pysam/libcalignedsegment.pyx":2168 - * """deprecated, use reference_start instead""" - * def __get__(self): return self.reference_start - * def __set__(self, v): self.reference_start = v # <<<<<<<<<<<<<< - * property mapq: - * """deprecated, use mapping_quality instead""" + /* "pysam/libcalignedsegment.pyx":2380 + * cdef int nvalues + * btag = force_bytes(tag) + * v = bam_aux_get(self._delegate, btag) # <<<<<<<<<<<<<< + * return v != NULL + * */ + if (unlikely(__pyx_v_btag == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2380, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_btag); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 2380, __pyx_L1_error) + __pyx_v_v = bam_aux_get(__pyx_v_self->_delegate, __pyx_t_6); -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3pos_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3pos_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2168, 0, __PYX_ERR(0, 2168, __pyx_L1_error)); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_start, __pyx_v_v) < 0) __PYX_ERR(0, 2168, __pyx_L1_error) - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.pos.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2171 - * property mapq: - * """deprecated, use mapping_quality instead""" - * def __get__(self): return self.mapping_quality # <<<<<<<<<<<<<< - * def __set__(self, v): self.mapping_quality = v - * property rnext: + /* "pysam/libcalignedsegment.pyx":2381 + * btag = force_bytes(tag) + * v = bam_aux_get(self._delegate, btag) + * return v != NULL # <<<<<<<<<<<<<< + * + * cpdef get_tag(self, tag, with_value_type=False): */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mapq___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mapq___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2171, 0, __PYX_ERR(0, 2171, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2171, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_v != NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; + /* "pysam/libcalignedsegment.pyx":2374 + * value_ptr) + * + * cpdef has_tag(self, tag): # <<<<<<<<<<<<<< + * """returns true if the optional alignment section + * contains a given *tag*.""" + */ + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mapq.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.has_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_btag); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2172 - * """deprecated, use mapping_quality instead""" - * def __get__(self): return self.mapping_quality - * def __set__(self, v): self.mapping_quality = v # <<<<<<<<<<<<<< - * property rnext: - * """deprecated, use next_reference_id instead""" - */ - -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2172, 0, __PYX_ERR(0, 2172, __pyx_L1_error)); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality, __pyx_v_v) < 0) __PYX_ERR(0, 2172, __pyx_L1_error) - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mapq.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2175 - * property rnext: - * """deprecated, use next_reference_id instead""" - * def __get__(self): return self.next_reference_id # <<<<<<<<<<<<<< - * def __set__(self, v): self.next_reference_id = v - * property pnext: - */ - /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_49has_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_48has_tag[] = "AlignedSegment.has_tag(self, tag)\nreturns true if the optional alignment section\n contains a given *tag*."; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_49has_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rnext___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("has_tag (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_48has_tag(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tag)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rnext___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_48has_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2175, 0, __PYX_ERR(0, 2175, __pyx_L1_error)); + __Pyx_RefNannySetupContext("has_tag", 0); + __Pyx_TraceCall("has_tag (wrapper)", __pyx_f[0], 2374, 0, __PYX_ERR(0, 2374, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2175, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_has_tag(__pyx_v_self, __pyx_v_tag, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2374, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -23995,7 +27298,7 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rnext___ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.rnext.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.has_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -24004,492 +27307,731 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rnext___ return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2176 - * """deprecated, use next_reference_id instead""" - * def __get__(self): return self.next_reference_id - * def __set__(self, v): self.next_reference_id = v # <<<<<<<<<<<<<< - * property pnext: - * """deprecated, use next_reference_start instead""" +/* "pysam/libcalignedsegment.pyx":2383 + * return v != NULL + * + * cpdef get_tag(self, tag, with_value_type=False): # <<<<<<<<<<<<<< + * """ + * retrieves data from the optional alignment section */ -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2176, 0, __PYX_ERR(0, 2176, __pyx_L1_error)); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id, __pyx_v_v) < 0) __PYX_ERR(0, 2176, __pyx_L1_error) - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.rnext.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2179 - * property pnext: - * """deprecated, use next_reference_start instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.next_reference_start - * def __set__(self, v): - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5pnext___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5pnext___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_51get_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_get_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag *__pyx_optional_args) { + PyObject *__pyx_v_with_value_type = ((PyObject *)Py_False); + uint8_t *__pyx_v_v; + CYTHON_UNUSED int __pyx_v_nvalues; + PyObject *__pyx_v_btag = NULL; + PyObject *__pyx_v_auxtype = NULL; + PyObject *__pyx_v_value = NULL; + CYTHON_UNUSED PyObject *__pyx_v_bytesize = NULL; + PyObject *__pyx_v_values = NULL; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2179, 0, __PYX_ERR(0, 2179, __pyx_L1_error)); + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + char const *__pyx_t_7; + int __pyx_t_8; + int __pyx_t_9; + PyObject *(*__pyx_t_10)(PyObject *); + __Pyx_RefNannySetupContext("get_tag", 0); + __Pyx_TraceCall("get_tag", __pyx_f[0], 2383, 0, __PYX_ERR(0, 2383, __pyx_L1_error)); + if (__pyx_optional_args) { + if (__pyx_optional_args->__pyx_n > 0) { + __pyx_v_with_value_type = __pyx_optional_args->with_value_type; + } + } + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2383, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_51get_tag)) { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_tag, __pyx_v_with_value_type}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2383, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_tag, __pyx_v_with_value_type}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2383, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2383, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_tag); + __Pyx_GIVEREF(__pyx_v_tag); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_tag); + __Pyx_INCREF(__pyx_v_with_value_type); + __Pyx_GIVEREF(__pyx_v_with_value_type); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_with_value_type); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2383, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } - /* "pysam/libcalignedsegment.pyx":2180 - * """deprecated, use next_reference_start instead""" - * def __get__(self): - * return self.next_reference_start # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.next_reference_start = v + /* "pysam/libcalignedsegment.pyx":2422 + * cdef uint8_t * v + * cdef int nvalues + * btag = force_bytes(tag) # <<<<<<<<<<<<<< + * v = bam_aux_get(self._delegate, btag) + * if v == NULL: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2180, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_tag, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2422, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; + __pyx_v_btag = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2179 - * property pnext: - * """deprecated, use next_reference_start instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.next_reference_start - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2423 + * cdef int nvalues + * btag = force_bytes(tag) + * v = bam_aux_get(self._delegate, btag) # <<<<<<<<<<<<<< + * if v == NULL: + * raise KeyError("tag '%s' not present" % tag) */ + if (unlikely(__pyx_v_btag == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2423, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_PyBytes_AsString(__pyx_v_btag); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 2423, __pyx_L1_error) + __pyx_v_v = bam_aux_get(__pyx_v_self->_delegate, __pyx_t_7); - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.pnext.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2181 - * def __get__(self): - * return self.next_reference_start - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.next_reference_start = v - * property cigar: + /* "pysam/libcalignedsegment.pyx":2424 + * btag = force_bytes(tag) + * v = bam_aux_get(self._delegate, btag) + * if v == NULL: # <<<<<<<<<<<<<< + * raise KeyError("tag '%s' not present" % tag) + * if chr(v[0]) == "B": */ + __pyx_t_8 = ((__pyx_v_v == NULL) != 0); + if (unlikely(__pyx_t_8)) { -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2181, 0, __PYX_ERR(0, 2181, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2182 - * return self.next_reference_start - * def __set__(self, v): - * self.next_reference_start = v # <<<<<<<<<<<<<< - * property cigar: - * """deprecated, use cigartuples instead""" + /* "pysam/libcalignedsegment.pyx":2425 + * v = bam_aux_get(self._delegate, btag) + * if v == NULL: + * raise KeyError("tag '%s' not present" % tag) # <<<<<<<<<<<<<< + * if chr(v[0]) == "B": + * auxtype = chr(v[0]) + chr(v[1]) */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start, __pyx_v_v) < 0) __PYX_ERR(0, 2182, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_tag_s_not_present, __pyx_v_tag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2425, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2425, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 2425, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2181 - * def __get__(self): - * return self.next_reference_start - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.next_reference_start = v - * property cigar: + /* "pysam/libcalignedsegment.pyx":2424 + * btag = force_bytes(tag) + * v = bam_aux_get(self._delegate, btag) + * if v == NULL: # <<<<<<<<<<<<<< + * raise KeyError("tag '%s' not present" % tag) + * if chr(v[0]) == "B": */ + } - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.pnext.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2185 - * property cigar: - * """deprecated, use cigartuples instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * r = self.cigartuples - * if r is None: + /* "pysam/libcalignedsegment.pyx":2426 + * if v == NULL: + * raise KeyError("tag '%s' not present" % tag) + * if chr(v[0]) == "B": # <<<<<<<<<<<<<< + * auxtype = chr(v[0]) + chr(v[1]) + * else: */ + __pyx_t_2 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_B, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2426, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_8) { -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5cigar___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + /* "pysam/libcalignedsegment.pyx":2427 + * raise KeyError("tag '%s' not present" % tag) + * if chr(v[0]) == "B": + * auxtype = chr(v[0]) + chr(v[1]) # <<<<<<<<<<<<<< + * else: + * auxtype = chr(v[0]) + */ + __pyx_t_1 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[1])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_auxtype = __pyx_t_1; + __pyx_t_1 = 0; - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2426 + * if v == NULL: + * raise KeyError("tag '%s' not present" % tag) + * if chr(v[0]) == "B": # <<<<<<<<<<<<<< + * auxtype = chr(v[0]) + chr(v[1]) + * else: + */ + goto __pyx_L4; + } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5cigar___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_v_r = NULL; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2185, 0, __PYX_ERR(0, 2185, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":2429 + * auxtype = chr(v[0]) + chr(v[1]) + * else: + * auxtype = chr(v[0]) # <<<<<<<<<<<<<< + * + * if auxtype in "iIcCsS": + */ + /*else*/ { + __pyx_t_1 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_auxtype = __pyx_t_3; + __pyx_t_3 = 0; + } + __pyx_L4:; - /* "pysam/libcalignedsegment.pyx":2186 - * """deprecated, use cigartuples instead""" - * def __get__(self): - * r = self.cigartuples # <<<<<<<<<<<<<< - * if r is None: - * r = [] + /* "pysam/libcalignedsegment.pyx":2431 + * auxtype = chr(v[0]) + * + * if auxtype in "iIcCsS": # <<<<<<<<<<<<<< + * value = bam_aux2i(v) + * elif auxtype == 'f' or auxtype == 'F': */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_8 = (__Pyx_PySequence_ContainsTF(__pyx_v_auxtype, __pyx_n_s_iIcCsS, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2431, __pyx_L1_error) + __pyx_t_9 = (__pyx_t_8 != 0); + if (__pyx_t_9) { - /* "pysam/libcalignedsegment.pyx":2187 - * def __get__(self): - * r = self.cigartuples - * if r is None: # <<<<<<<<<<<<<< - * r = [] - * return r + /* "pysam/libcalignedsegment.pyx":2432 + * + * if auxtype in "iIcCsS": + * value = bam_aux2i(v) # <<<<<<<<<<<<<< + * elif auxtype == 'f' or auxtype == 'F': + * value = bam_aux2f(v) */ - __pyx_t_2 = (__pyx_v_r == Py_None); - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { + __pyx_t_3 = __Pyx_PyInt_From_int64_t(bam_aux2i(__pyx_v_v)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2432, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_value = __pyx_t_3; + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":2188 - * r = self.cigartuples - * if r is None: - * r = [] # <<<<<<<<<<<<<< - * return r - * def __set__(self, v): self.cigartuples = v + /* "pysam/libcalignedsegment.pyx":2431 + * auxtype = chr(v[0]) + * + * if auxtype in "iIcCsS": # <<<<<<<<<<<<<< + * value = bam_aux2i(v) + * elif auxtype == 'f' or auxtype == 'F': */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2188, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF_SET(__pyx_v_r, __pyx_t_1); - __pyx_t_1 = 0; + goto __pyx_L5; + } - /* "pysam/libcalignedsegment.pyx":2187 - * def __get__(self): - * r = self.cigartuples - * if r is None: # <<<<<<<<<<<<<< - * r = [] - * return r + /* "pysam/libcalignedsegment.pyx":2433 + * if auxtype in "iIcCsS": + * value = bam_aux2i(v) + * elif auxtype == 'f' or auxtype == 'F': # <<<<<<<<<<<<<< + * value = bam_aux2f(v) + * elif auxtype == 'd' or auxtype == 'D': */ + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_f, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2433, __pyx_L1_error) + if (!__pyx_t_8) { + } else { + __pyx_t_9 = __pyx_t_8; + goto __pyx_L6_bool_binop_done; } + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_F, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2433, __pyx_L1_error) + __pyx_t_9 = __pyx_t_8; + __pyx_L6_bool_binop_done:; + if (__pyx_t_9) { - /* "pysam/libcalignedsegment.pyx":2189 - * if r is None: - * r = [] - * return r # <<<<<<<<<<<<<< - * def __set__(self, v): self.cigartuples = v - * property tlen: + /* "pysam/libcalignedsegment.pyx":2434 + * value = bam_aux2i(v) + * elif auxtype == 'f' or auxtype == 'F': + * value = bam_aux2f(v) # <<<<<<<<<<<<<< + * elif auxtype == 'd' or auxtype == 'D': + * value = bam_aux2f(v) */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_r); - __pyx_r = __pyx_v_r; - goto __pyx_L0; + __pyx_t_3 = PyFloat_FromDouble(bam_aux2f(__pyx_v_v)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2434, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_value = __pyx_t_3; + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":2185 - * property cigar: - * """deprecated, use cigartuples instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * r = self.cigartuples - * if r is None: + /* "pysam/libcalignedsegment.pyx":2433 + * if auxtype in "iIcCsS": + * value = bam_aux2i(v) + * elif auxtype == 'f' or auxtype == 'F': # <<<<<<<<<<<<<< + * value = bam_aux2f(v) + * elif auxtype == 'd' or auxtype == 'D': */ + goto __pyx_L5; + } - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.cigar.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_r); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2435 + * elif auxtype == 'f' or auxtype == 'F': + * value = bam_aux2f(v) + * elif auxtype == 'd' or auxtype == 'D': # <<<<<<<<<<<<<< + * value = bam_aux2f(v) + * elif auxtype == 'A' or auxtype == 'a': + */ + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_d, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2435, __pyx_L1_error) + if (!__pyx_t_8) { + } else { + __pyx_t_9 = __pyx_t_8; + goto __pyx_L8_bool_binop_done; + } + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_D, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2435, __pyx_L1_error) + __pyx_t_9 = __pyx_t_8; + __pyx_L8_bool_binop_done:; + if (__pyx_t_9) { -/* "pysam/libcalignedsegment.pyx":2190 - * r = [] - * return r - * def __set__(self, v): self.cigartuples = v # <<<<<<<<<<<<<< - * property tlen: - * """deprecated, use template_length instead""" + /* "pysam/libcalignedsegment.pyx":2436 + * value = bam_aux2f(v) + * elif auxtype == 'd' or auxtype == 'D': + * value = bam_aux2f(v) # <<<<<<<<<<<<<< + * elif auxtype == 'A' or auxtype == 'a': + * # force A to a */ + __pyx_t_3 = PyFloat_FromDouble(bam_aux2f(__pyx_v_v)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2436, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_value = __pyx_t_3; + __pyx_t_3 = 0; -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + /* "pysam/libcalignedsegment.pyx":2435 + * elif auxtype == 'f' or auxtype == 'F': + * value = bam_aux2f(v) + * elif auxtype == 'd' or auxtype == 'D': # <<<<<<<<<<<<<< + * value = bam_aux2f(v) + * elif auxtype == 'A' or auxtype == 'a': + */ + goto __pyx_L5; + } - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2437 + * elif auxtype == 'd' or auxtype == 'D': + * value = bam_aux2f(v) + * elif auxtype == 'A' or auxtype == 'a': # <<<<<<<<<<<<<< + * # force A to a + * v[0] = 'A' + */ + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_A, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2437, __pyx_L1_error) + if (!__pyx_t_8) { + } else { + __pyx_t_9 = __pyx_t_8; + goto __pyx_L10_bool_binop_done; + } + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_a, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2437, __pyx_L1_error) + __pyx_t_9 = __pyx_t_8; + __pyx_L10_bool_binop_done:; + if (__pyx_t_9) { -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2190, 0, __PYX_ERR(0, 2190, __pyx_L1_error)); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples, __pyx_v_v) < 0) __PYX_ERR(0, 2190, __pyx_L1_error) + /* "pysam/libcalignedsegment.pyx":2439 + * elif auxtype == 'A' or auxtype == 'a': + * # force A to a + * v[0] = 'A' # <<<<<<<<<<<<<< + * # there might a more efficient way + * # to convert a char into a string + */ + (__pyx_v_v[0]) = 'A'; - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.cigar.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2442 + * # there might a more efficient way + * # to convert a char into a string + * value = '%c' % bam_aux2A(v) # <<<<<<<<<<<<<< + * elif auxtype == 'Z' or auxtype == 'H': + * # Z and H are treated equally as strings in htslib + */ + __pyx_t_3 = __Pyx_PyInt_From_char(((char)bam_aux2A(__pyx_v_v))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2442, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_c, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2442, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_value = __pyx_t_1; + __pyx_t_1 = 0; -/* "pysam/libcalignedsegment.pyx":2193 - * property tlen: - * """deprecated, use template_length instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.template_length - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2437 + * elif auxtype == 'd' or auxtype == 'D': + * value = bam_aux2f(v) + * elif auxtype == 'A' or auxtype == 'a': # <<<<<<<<<<<<<< + * # force A to a + * v[0] = 'A' */ + goto __pyx_L5; + } -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tlen___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + /* "pysam/libcalignedsegment.pyx":2443 + * # to convert a char into a string + * value = '%c' % bam_aux2A(v) + * elif auxtype == 'Z' or auxtype == 'H': # <<<<<<<<<<<<<< + * # Z and H are treated equally as strings in htslib + * value = charptr_to_str(bam_aux2Z(v)) + */ + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_Z, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2443, __pyx_L1_error) + if (!__pyx_t_8) { + } else { + __pyx_t_9 = __pyx_t_8; + goto __pyx_L12_bool_binop_done; + } + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_H, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2443, __pyx_L1_error) + __pyx_t_9 = __pyx_t_8; + __pyx_L12_bool_binop_done:; + if (__pyx_t_9) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2445 + * elif auxtype == 'Z' or auxtype == 'H': + * # Z and H are treated equally as strings in htslib + * value = charptr_to_str(bam_aux2Z(v)) # <<<<<<<<<<<<<< + * elif auxtype[0] == 'B': + * bytesize, nvalues, values = convert_binary_tag(v + 1) + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str(((char *)bam_aux2Z(__pyx_v_v)), NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2445, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_value = __pyx_t_1; + __pyx_t_1 = 0; -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tlen___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2193, 0, __PYX_ERR(0, 2193, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":2443 + * # to convert a char into a string + * value = '%c' % bam_aux2A(v) + * elif auxtype == 'Z' or auxtype == 'H': # <<<<<<<<<<<<<< + * # Z and H are treated equally as strings in htslib + * value = charptr_to_str(bam_aux2Z(v)) + */ + goto __pyx_L5; + } - /* "pysam/libcalignedsegment.pyx":2194 - * """deprecated, use template_length instead""" - * def __get__(self): - * return self.template_length # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.template_length = v + /* "pysam/libcalignedsegment.pyx":2446 + * # Z and H are treated equally as strings in htslib + * value = charptr_to_str(bam_aux2Z(v)) + * elif auxtype[0] == 'B': # <<<<<<<<<<<<<< + * bytesize, nvalues, values = convert_binary_tag(v + 1) + * value = values */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2194, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_auxtype, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2446, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_B, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 2446, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (likely(__pyx_t_9)) { - /* "pysam/libcalignedsegment.pyx":2193 - * property tlen: - * """deprecated, use template_length instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.template_length - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2447 + * value = charptr_to_str(bam_aux2Z(v)) + * elif auxtype[0] == 'B': + * bytesize, nvalues, values = convert_binary_tag(v + 1) # <<<<<<<<<<<<<< + * value = values + * else: */ + __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment_convert_binary_tag((__pyx_v_v + 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 2447, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 2); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_2 = PyList_GET_ITEM(sequence, 1); + __pyx_t_6 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_4)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L14_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L14_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 2; __pyx_t_6 = __pyx_t_10(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L14_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_4), 3) < 0) __PYX_ERR(0, 2447, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L15_unpacking_done; + __pyx_L14_unpacking_failed:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2447, __pyx_L1_error) + __pyx_L15_unpacking_done:; + } + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2447, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_bytesize = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_v_nvalues = __pyx_t_5; + __pyx_v_values = __pyx_t_6; + __pyx_t_6 = 0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2448 + * elif auxtype[0] == 'B': + * bytesize, nvalues, values = convert_binary_tag(v + 1) + * value = values # <<<<<<<<<<<<<< + * else: + * raise ValueError("unknown auxiliary type '%s'" % auxtype) + */ + __Pyx_INCREF(__pyx_v_values); + __pyx_v_value = __pyx_v_values; -/* "pysam/libcalignedsegment.pyx":2195 - * def __get__(self): - * return self.template_length - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.template_length = v - * property seq: + /* "pysam/libcalignedsegment.pyx":2446 + * # Z and H are treated equally as strings in htslib + * value = charptr_to_str(bam_aux2Z(v)) + * elif auxtype[0] == 'B': # <<<<<<<<<<<<<< + * bytesize, nvalues, values = convert_binary_tag(v + 1) + * value = values */ + goto __pyx_L5; + } -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + /* "pysam/libcalignedsegment.pyx":2450 + * value = values + * else: + * raise ValueError("unknown auxiliary type '%s'" % auxtype) # <<<<<<<<<<<<<< + * + * if with_value_type: + */ + /*else*/ { + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_unknown_auxiliary_type_s, __pyx_v_auxtype); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2450, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2450, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 2450, __pyx_L1_error) + } + __pyx_L5:; - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2452 + * raise ValueError("unknown auxiliary type '%s'" % auxtype) + * + * if with_value_type: # <<<<<<<<<<<<<< + * return (value, auxtype) + * else: + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_with_value_type); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 2452, __pyx_L1_error) + if (__pyx_t_9) { -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2195, 0, __PYX_ERR(0, 2195, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":2453 + * + * if with_value_type: + * return (value, auxtype) # <<<<<<<<<<<<<< + * else: + * return value + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_value); + __Pyx_INCREF(__pyx_v_auxtype); + __Pyx_GIVEREF(__pyx_v_auxtype); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_auxtype); + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2196 - * return self.template_length - * def __set__(self, v): - * self.template_length = v # <<<<<<<<<<<<<< - * property seq: - * """deprecated, use query_sequence instead""" + /* "pysam/libcalignedsegment.pyx":2452 + * raise ValueError("unknown auxiliary type '%s'" % auxtype) + * + * if with_value_type: # <<<<<<<<<<<<<< + * return (value, auxtype) + * else: */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length, __pyx_v_v) < 0) __PYX_ERR(0, 2196, __pyx_L1_error) + } - /* "pysam/libcalignedsegment.pyx":2195 - * def __get__(self): - * return self.template_length - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.template_length = v - * property seq: + /* "pysam/libcalignedsegment.pyx":2455 + * return (value, auxtype) + * else: + * return value # <<<<<<<<<<<<<< + * + * def get_tags(self, with_value_type=False): + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_value); + __pyx_r = __pyx_v_value; + goto __pyx_L0; + } + + /* "pysam/libcalignedsegment.pyx":2383 + * return v != NULL + * + * cpdef get_tag(self, tag, with_value_type=False): # <<<<<<<<<<<<<< + * """ + * retrieves data from the optional alignment section */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tlen.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF(__pyx_v_btag); + __Pyx_XDECREF(__pyx_v_auxtype); + __Pyx_XDECREF(__pyx_v_value); + __Pyx_XDECREF(__pyx_v_bytesize); + __Pyx_XDECREF(__pyx_v_values); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2199 - * property seq: - * """deprecated, use query_sequence instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.query_sequence - * def __set__(self, v): - */ - /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3seq_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3seq_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_51get_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_50get_tag[] = "AlignedSegment.get_tag(self, tag, with_value_type=False)\n\n retrieves data from the optional alignment section\n given a two-letter *tag* denoting the field.\n\n The returned value is cast into an appropriate python type.\n\n This method is the fastest way to access the optional\n alignment section if only few tags need to be retrieved.\n\n Possible value types are \"AcCsSiIfZHB\" (see BAM format\n specification) as well as additional value type 'd' as\n implemented in htslib.\n\n Parameters\n ----------\n\n tag :\n data tag.\n\n with_value_type : Optional[bool]\n if set to True, the return value is a tuple of (tag value, type code).\n (default False)\n\n Returns\n -------\n\n A python object with the value of the `tag`. The type of the\n object depends on the data type in the data record.\n\n Raises\n ------\n\n KeyError\n If `tag` is not present, a KeyError is raised.\n\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_51get_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_tag = 0; + PyObject *__pyx_v_with_value_type = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3seq___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("get_tag (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tag,&__pyx_n_s_with_value_type,0}; + PyObject* values[2] = {0,0}; + values[1] = ((PyObject *)Py_False); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tag)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_with_value_type); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_tag") < 0)) __PYX_ERR(0, 2383, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_tag = values[0]; + __pyx_v_with_value_type = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_tag", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2383, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_50get_tag(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_tag, __pyx_v_with_value_type); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3seq___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_50get_tag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_with_value_type) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2199, 0, __PYX_ERR(0, 2199, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2200 - * """deprecated, use query_sequence instead""" - * def __get__(self): - * return self.query_sequence # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.query_sequence = v - */ + struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag __pyx_t_2; + __Pyx_RefNannySetupContext("get_tag", 0); + __Pyx_TraceCall("get_tag (wrapper)", __pyx_f[0], 2383, 0, __PYX_ERR(0, 2383, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2200, __pyx_L1_error) + __pyx_t_2.__pyx_n = 1; + __pyx_t_2.with_value_type = __pyx_v_with_value_type; + __pyx_t_1 = __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment->get_tag(__pyx_v_self, __pyx_v_tag, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2383, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2199 - * property seq: - * """deprecated, use query_sequence instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.query_sequence - * def __set__(self, v): - */ - /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.seq.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_tag", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -24498,980 +28040,1261 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3seq___ge return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2201 - * def __get__(self): - * return self.query_sequence - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_sequence = v - * property qual: +/* "pysam/libcalignedsegment.pyx":2457 + * return value + * + * def get_tags(self, with_value_type=False): # <<<<<<<<<<<<<< + * """the fields in the optional aligment section. + * */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3seq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3seq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_53get_tags(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_52get_tags[] = "AlignedSegment.get_tags(self, with_value_type=False)\nthe fields in the optional aligment section.\n\n Returns a list of all fields in the optional\n alignment section. Values are converted to appropriate python\n values. For example:\n\n [(NM, 2), (RG, \"GJP00TM04\")]\n\n If *with_value_type* is set, the value type as encode in\n the AlignedSegment record will be returned as well:\n\n [(NM, 2, \"i\"), (RG, \"GJP00TM04\", \"Z\")]\n\n This method will convert all values in the optional alignment\n section. When getting only one or few tags, please see\n :meth:`get_tag` for a quicker way to achieve this.\n\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_53get_tags(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_with_value_type = 0; + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3seq_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + __Pyx_RefNannySetupContext("get_tags (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_with_value_type,0}; + PyObject* values[1] = {0}; + values[0] = ((PyObject *)Py_False); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_with_value_type); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_tags") < 0)) __PYX_ERR(0, 2457, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_with_value_type = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_tags", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2457, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_tags", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_52get_tags(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_with_value_type); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3seq_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_52get_tags(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_with_value_type) { + bam1_t *__pyx_v_src; + uint8_t *__pyx_v_s; + char __pyx_v_auxtag[3]; + char __pyx_v_auxtype; + uint8_t __pyx_v_byte_size; + int32_t __pyx_v_nvalues; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_value = NULL; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2201, 0, __PYX_ERR(0, 2201, __pyx_L1_error)); + bam1_t *__pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *(*__pyx_t_9)(PyObject *); + uint8_t __pyx_t_10; + int32_t __pyx_t_11; + int __pyx_t_12; + __Pyx_RefNannySetupContext("get_tags", 0); + __Pyx_TraceCall("get_tags", __pyx_f[0], 2457, 0, __PYX_ERR(0, 2457, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2202 - * return self.query_sequence - * def __set__(self, v): - * self.query_sequence = v # <<<<<<<<<<<<<< - * property qual: - * """deprecated, query_qualities instead""" + /* "pysam/libcalignedsegment.pyx":2485 + * cdef int32_t nvalues + * + * src = self._delegate # <<<<<<<<<<<<<< + * if src.l_data == 0: + * return [] */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence, __pyx_v_v) < 0) __PYX_ERR(0, 2202, __pyx_L1_error) + __pyx_t_1 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_1; - /* "pysam/libcalignedsegment.pyx":2201 - * def __get__(self): - * return self.query_sequence - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_sequence = v - * property qual: + /* "pysam/libcalignedsegment.pyx":2486 + * + * src = self._delegate + * if src.l_data == 0: # <<<<<<<<<<<<<< + * return [] + * s = pysam_bam_get_aux(src) */ + __pyx_t_2 = ((__pyx_v_src->l_data == 0) != 0); + if (__pyx_t_2) { - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.seq.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2205 - * property qual: - * """deprecated, query_qualities instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return array_to_qualitystring(self.query_qualities) - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2487 + * src = self._delegate + * if src.l_data == 0: + * return [] # <<<<<<<<<<<<<< + * s = pysam_bam_get_aux(src) + * result = [] */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qual_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qual_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qual___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + /* "pysam/libcalignedsegment.pyx":2486 + * + * src = self._delegate + * if src.l_data == 0: # <<<<<<<<<<<<<< + * return [] + * s = pysam_bam_get_aux(src) + */ + } - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2488 + * if src.l_data == 0: + * return [] + * s = pysam_bam_get_aux(src) # <<<<<<<<<<<<<< + * result = [] + * auxtag[2] = 0 + */ + __pyx_v_s = pysam_bam_get_aux(__pyx_v_src); -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qual___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2205, 0, __PYX_ERR(0, 2205, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":2489 + * return [] + * s = pysam_bam_get_aux(src) + * result = [] # <<<<<<<<<<<<<< + * auxtag[2] = 0 + * while s < (src.data + src.l_data): + */ + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2489, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_result = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":2206 - * """deprecated, query_qualities instead""" - * def __get__(self): - * return array_to_qualitystring(self.query_qualities) # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.query_qualities = qualitystring_to_array(v) + /* "pysam/libcalignedsegment.pyx":2490 + * s = pysam_bam_get_aux(src) + * result = [] + * auxtag[2] = 0 # <<<<<<<<<<<<<< + * while s < (src.data + src.l_data): + * # get tag */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2206, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 2206, __pyx_L1_error) - __pyx_t_2 = __pyx_f_5pysam_9libcutils_array_to_qualitystring(((arrayobject *)__pyx_t_1), 0, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2206, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + (__pyx_v_auxtag[2]) = 0; - /* "pysam/libcalignedsegment.pyx":2205 - * property qual: - * """deprecated, query_qualities instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return array_to_qualitystring(self.query_qualities) - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2491 + * result = [] + * auxtag[2] = 0 + * while s < (src.data + src.l_data): # <<<<<<<<<<<<<< + * # get tag + * auxtag[0] = s[0] */ + while (1) { + __pyx_t_2 = ((__pyx_v_s < (__pyx_v_src->data + __pyx_v_src->l_data)) != 0); + if (!__pyx_t_2) break; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qual.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2493 + * while s < (src.data + src.l_data): + * # get tag + * auxtag[0] = s[0] # <<<<<<<<<<<<<< + * auxtag[1] = s[1] + * s += 2 + */ + (__pyx_v_auxtag[0]) = (__pyx_v_s[0]); -/* "pysam/libcalignedsegment.pyx":2207 - * def __get__(self): - * return array_to_qualitystring(self.query_qualities) - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_qualities = qualitystring_to_array(v) - * property alen: + /* "pysam/libcalignedsegment.pyx":2494 + * # get tag + * auxtag[0] = s[0] + * auxtag[1] = s[1] # <<<<<<<<<<<<<< + * s += 2 + * auxtype = s[0] */ + (__pyx_v_auxtag[1]) = (__pyx_v_s[1]); -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qual_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qual_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2207, 0, __PYX_ERR(0, 2207, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2208 - * return array_to_qualitystring(self.query_qualities) - * def __set__(self, v): - * self.query_qualities = qualitystring_to_array(v) # <<<<<<<<<<<<<< - * property alen: - * """deprecated, reference_length instead""" + /* "pysam/libcalignedsegment.pyx":2495 + * auxtag[0] = s[0] + * auxtag[1] = s[1] + * s += 2 # <<<<<<<<<<<<<< + * auxtype = s[0] + * if auxtype in ('c', 'C'): */ - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9libcutils_qualitystring_to_array(__pyx_v_v, 0, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2208, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities, __pyx_t_1) < 0) __PYX_ERR(0, 2208, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_s = (__pyx_v_s + 2); - /* "pysam/libcalignedsegment.pyx":2207 - * def __get__(self): - * return array_to_qualitystring(self.query_qualities) - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_qualities = qualitystring_to_array(v) - * property alen: + /* "pysam/libcalignedsegment.pyx":2496 + * auxtag[1] = s[1] + * s += 2 + * auxtype = s[0] # <<<<<<<<<<<<<< + * if auxtype in ('c', 'C'): + * value = bam_aux2i(s) */ + __pyx_v_auxtype = (__pyx_v_s[0]); - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qual.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2211 - * property alen: - * """deprecated, reference_length instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.reference_length - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2497 + * s += 2 + * auxtype = s[0] + * if auxtype in ('c', 'C'): # <<<<<<<<<<<<<< + * value = bam_aux2i(s) + * s += 1 */ + switch (__pyx_v_auxtype) { + case 'c': + case 'C': -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4alen_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4alen_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4alen___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4alen___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2211, 0, __PYX_ERR(0, 2211, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2212 - * """deprecated, reference_length instead""" - * def __get__(self): - * return self.reference_length # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.reference_length = v + /* "pysam/libcalignedsegment.pyx":2498 + * auxtype = s[0] + * if auxtype in ('c', 'C'): + * value = bam_aux2i(s) # <<<<<<<<<<<<<< + * s += 1 + * elif auxtype in ('s', 'S'): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2212, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_3 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2498, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":2211 - * property alen: - * """deprecated, reference_length instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.reference_length - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2499 + * if auxtype in ('c', 'C'): + * value = bam_aux2i(s) + * s += 1 # <<<<<<<<<<<<<< + * elif auxtype in ('s', 'S'): + * value = bam_aux2i(s) */ + __pyx_v_s = (__pyx_v_s + 1); - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.alen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2213 - * def __get__(self): - * return self.reference_length - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.reference_length = v - * property aend: + /* "pysam/libcalignedsegment.pyx":2497 + * s += 2 + * auxtype = s[0] + * if auxtype in ('c', 'C'): # <<<<<<<<<<<<<< + * value = bam_aux2i(s) + * s += 1 */ + break; -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4alen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4alen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4alen_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4alen_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2213, 0, __PYX_ERR(0, 2213, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":2500 + * value = bam_aux2i(s) + * s += 1 + * elif auxtype in ('s', 'S'): # <<<<<<<<<<<<<< + * value = bam_aux2i(s) + * s += 2 + */ + case 's': + case 'S': - /* "pysam/libcalignedsegment.pyx":2214 - * return self.reference_length - * def __set__(self, v): - * self.reference_length = v # <<<<<<<<<<<<<< - * property aend: - * """deprecated, reference_end instead""" + /* "pysam/libcalignedsegment.pyx":2501 + * s += 1 + * elif auxtype in ('s', 'S'): + * value = bam_aux2i(s) # <<<<<<<<<<<<<< + * s += 2 + * elif auxtype in ('i', 'I'): */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_length, __pyx_v_v) < 0) __PYX_ERR(0, 2214, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2501, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":2213 - * def __get__(self): - * return self.reference_length - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.reference_length = v - * property aend: + /* "pysam/libcalignedsegment.pyx":2502 + * elif auxtype in ('s', 'S'): + * value = bam_aux2i(s) + * s += 2 # <<<<<<<<<<<<<< + * elif auxtype in ('i', 'I'): + * value = bam_aux2i(s) */ + __pyx_v_s = (__pyx_v_s + 2); - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.alen.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2500 + * value = bam_aux2i(s) + * s += 1 + * elif auxtype in ('s', 'S'): # <<<<<<<<<<<<<< + * value = bam_aux2i(s) + * s += 2 + */ + break; -/* "pysam/libcalignedsegment.pyx":2217 - * property aend: - * """deprecated, reference_end instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.reference_end - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2503 + * value = bam_aux2i(s) + * s += 2 + * elif auxtype in ('i', 'I'): # <<<<<<<<<<<<<< + * value = bam_aux2i(s) + * s += 4 */ + case 'i': + case 'I': -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4aend_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4aend_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4aend___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + /* "pysam/libcalignedsegment.pyx":2504 + * s += 2 + * elif auxtype in ('i', 'I'): + * value = bam_aux2i(s) # <<<<<<<<<<<<<< + * s += 4 + * elif auxtype == 'f': + */ + __pyx_t_3 = __Pyx_PyInt_From_int32_t(((int32_t)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2504, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3); + __pyx_t_3 = 0; - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2505 + * elif auxtype in ('i', 'I'): + * value = bam_aux2i(s) + * s += 4 # <<<<<<<<<<<<<< + * elif auxtype == 'f': + * value = bam_aux2f(s) + */ + __pyx_v_s = (__pyx_v_s + 4); -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4aend___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2217, 0, __PYX_ERR(0, 2217, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":2503 + * value = bam_aux2i(s) + * s += 2 + * elif auxtype in ('i', 'I'): # <<<<<<<<<<<<<< + * value = bam_aux2i(s) + * s += 4 + */ + break; - /* "pysam/libcalignedsegment.pyx":2218 - * """deprecated, reference_end instead""" - * def __get__(self): - * return self.reference_end # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.reference_end = v + /* "pysam/libcalignedsegment.pyx":2506 + * value = bam_aux2i(s) + * s += 4 + * elif auxtype == 'f': # <<<<<<<<<<<<<< + * value = bam_aux2f(s) + * s += 4 */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2218, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + case 'f': - /* "pysam/libcalignedsegment.pyx":2217 - * property aend: - * """deprecated, reference_end instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.reference_end - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2507 + * s += 4 + * elif auxtype == 'f': + * value = bam_aux2f(s) # <<<<<<<<<<<<<< + * s += 4 + * elif auxtype == 'd': */ + __pyx_t_3 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3); + __pyx_t_3 = 0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.aend.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2508 + * elif auxtype == 'f': + * value = bam_aux2f(s) + * s += 4 # <<<<<<<<<<<<<< + * elif auxtype == 'd': + * value = bam_aux2f(s) + */ + __pyx_v_s = (__pyx_v_s + 4); -/* "pysam/libcalignedsegment.pyx":2219 - * def __get__(self): - * return self.reference_end - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.reference_end = v - * property rlen: + /* "pysam/libcalignedsegment.pyx":2506 + * value = bam_aux2i(s) + * s += 4 + * elif auxtype == 'f': # <<<<<<<<<<<<<< + * value = bam_aux2f(s) + * s += 4 */ + break; -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4aend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4aend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4aend_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + /* "pysam/libcalignedsegment.pyx":2509 + * value = bam_aux2f(s) + * s += 4 + * elif auxtype == 'd': # <<<<<<<<<<<<<< + * value = bam_aux2f(s) + * s += 8 + */ + case 'd': - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2510 + * s += 4 + * elif auxtype == 'd': + * value = bam_aux2f(s) # <<<<<<<<<<<<<< + * s += 8 + * elif auxtype in ('A', 'a'): + */ + __pyx_t_3 = PyFloat_FromDouble(((double)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2510, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3); + __pyx_t_3 = 0; -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4aend_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2219, 0, __PYX_ERR(0, 2219, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":2511 + * elif auxtype == 'd': + * value = bam_aux2f(s) + * s += 8 # <<<<<<<<<<<<<< + * elif auxtype in ('A', 'a'): + * value = "%c" % bam_aux2A(s) + */ + __pyx_v_s = (__pyx_v_s + 8); - /* "pysam/libcalignedsegment.pyx":2220 - * return self.reference_end - * def __set__(self, v): - * self.reference_end = v # <<<<<<<<<<<<<< - * property rlen: - * """deprecated, query_length instead""" + /* "pysam/libcalignedsegment.pyx":2509 + * value = bam_aux2f(s) + * s += 4 + * elif auxtype == 'd': # <<<<<<<<<<<<<< + * value = bam_aux2f(s) + * s += 8 */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_end, __pyx_v_v) < 0) __PYX_ERR(0, 2220, __pyx_L1_error) + break; - /* "pysam/libcalignedsegment.pyx":2219 - * def __get__(self): - * return self.reference_end - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.reference_end = v - * property rlen: + /* "pysam/libcalignedsegment.pyx":2512 + * value = bam_aux2f(s) + * s += 8 + * elif auxtype in ('A', 'a'): # <<<<<<<<<<<<<< + * value = "%c" % bam_aux2A(s) + * s += 1 */ + case 'A': + case 'a': - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.aend.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2513 + * s += 8 + * elif auxtype in ('A', 'a'): + * value = "%c" % bam_aux2A(s) # <<<<<<<<<<<<<< + * s += 1 + * elif auxtype in ('Z', 'H'): + */ + __pyx_t_3 = __Pyx_PyInt_From_char(((char)bam_aux2A(__pyx_v_s))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2513, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_c, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2513, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_4); + __pyx_t_4 = 0; -/* "pysam/libcalignedsegment.pyx":2223 - * property rlen: - * """deprecated, query_length instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.query_length - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2514 + * elif auxtype in ('A', 'a'): + * value = "%c" % bam_aux2A(s) + * s += 1 # <<<<<<<<<<<<<< + * elif auxtype in ('Z', 'H'): + * value = charptr_to_str(bam_aux2Z(s)) */ + __pyx_v_s = (__pyx_v_s + 1); -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4rlen___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + /* "pysam/libcalignedsegment.pyx":2512 + * value = bam_aux2f(s) + * s += 8 + * elif auxtype in ('A', 'a'): # <<<<<<<<<<<<<< + * value = "%c" % bam_aux2A(s) + * s += 1 + */ + break; - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2515 + * value = "%c" % bam_aux2A(s) + * s += 1 + * elif auxtype in ('Z', 'H'): # <<<<<<<<<<<<<< + * value = charptr_to_str(bam_aux2Z(s)) + * # +1 for NULL terminated string + */ + case 'Z': + case 'H': -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4rlen___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2223, 0, __PYX_ERR(0, 2223, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":2516 + * s += 1 + * elif auxtype in ('Z', 'H'): + * value = charptr_to_str(bam_aux2Z(s)) # <<<<<<<<<<<<<< + * # +1 for NULL terminated string + * s += len(value) + 1 + */ + __pyx_t_4 = __pyx_f_5pysam_9libcutils_charptr_to_str(((char *)bam_aux2Z(__pyx_v_s)), NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2516, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcalignedsegment.pyx":2224 - * """deprecated, query_length instead""" - * def __get__(self): - * return self.query_length # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.query_length = v + /* "pysam/libcalignedsegment.pyx":2518 + * value = charptr_to_str(bam_aux2Z(s)) + * # +1 for NULL terminated string + * s += len(value) + 1 # <<<<<<<<<<<<<< + * elif auxtype == 'B': + * s += 1 */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2224, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2518, __pyx_L1_error) + __pyx_v_s = (__pyx_v_s + (__pyx_t_5 + 1)); - /* "pysam/libcalignedsegment.pyx":2223 - * property rlen: - * """deprecated, query_length instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.query_length - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2515 + * value = "%c" % bam_aux2A(s) + * s += 1 + * elif auxtype in ('Z', 'H'): # <<<<<<<<<<<<<< + * value = charptr_to_str(bam_aux2Z(s)) + * # +1 for NULL terminated string */ + break; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.rlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2519 + * # +1 for NULL terminated string + * s += len(value) + 1 + * elif auxtype == 'B': # <<<<<<<<<<<<<< + * s += 1 + * byte_size, nvalues, value = convert_binary_tag(s) + */ + case 'B': -/* "pysam/libcalignedsegment.pyx":2225 - * def __get__(self): - * return self.query_length - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_length = v - * property query: + /* "pysam/libcalignedsegment.pyx":2520 + * s += len(value) + 1 + * elif auxtype == 'B': + * s += 1 # <<<<<<<<<<<<<< + * byte_size, nvalues, value = convert_binary_tag(s) + * # 5 for 1 char and 1 int */ + __pyx_v_s = (__pyx_v_s + 1); -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2225, 0, __PYX_ERR(0, 2225, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2226 - * return self.query_length - * def __set__(self, v): - * self.query_length = v # <<<<<<<<<<<<<< - * property query: - * """deprecated, query_alignment_sequence instead""" + /* "pysam/libcalignedsegment.pyx":2521 + * elif auxtype == 'B': + * s += 1 + * byte_size, nvalues, value = convert_binary_tag(s) # <<<<<<<<<<<<<< + * # 5 for 1 char and 1 int + * s += 5 + (nvalues * byte_size) - 1 */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_length, __pyx_v_v) < 0) __PYX_ERR(0, 2226, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_18libcalignedsegment_convert_binary_tag(__pyx_v_s); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { + PyObject* sequence = __pyx_t_4; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 2521, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + __pyx_t_7 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_8 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 2; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 3) < 0) __PYX_ERR(0, 2521, __pyx_L1_error) + __pyx_t_9 = NULL; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2521, __pyx_L1_error) + __pyx_L7_unpacking_done:; + } + __pyx_t_10 = __Pyx_PyInt_As_uint8_t(__pyx_t_3); if (unlikely((__pyx_t_10 == ((uint8_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2521, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_11 = __Pyx_PyInt_As_int32_t(__pyx_t_6); if (unlikely((__pyx_t_11 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2521, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_byte_size = __pyx_t_10; + __pyx_v_nvalues = __pyx_t_11; + __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_7); + __pyx_t_7 = 0; - /* "pysam/libcalignedsegment.pyx":2225 - * def __get__(self): - * return self.query_length - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_length = v - * property query: + /* "pysam/libcalignedsegment.pyx":2523 + * byte_size, nvalues, value = convert_binary_tag(s) + * # 5 for 1 char and 1 int + * s += 5 + (nvalues * byte_size) - 1 # <<<<<<<<<<<<<< + * else: + * raise KeyError("unknown type '%s'" % auxtype) */ + __pyx_v_s = (__pyx_v_s + ((5 + (__pyx_v_nvalues * __pyx_v_byte_size)) - 1)); - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.rlen.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2229 - * property query: - * """deprecated, query_alignment_sequence instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.query_alignment_sequence - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2519 + * # +1 for NULL terminated string + * s += len(value) + 1 + * elif auxtype == 'B': # <<<<<<<<<<<<<< + * s += 1 + * byte_size, nvalues, value = convert_binary_tag(s) */ + break; + default: -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5query_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5query_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5query___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5query___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2229, 0, __PYX_ERR(0, 2229, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2230 - * """deprecated, query_alignment_sequence instead""" - * def __get__(self): - * return self.query_alignment_sequence # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.query_alignment_sequence = v + /* "pysam/libcalignedsegment.pyx":2525 + * s += 5 + (nvalues * byte_size) - 1 + * else: + * raise KeyError("unknown type '%s'" % auxtype) # <<<<<<<<<<<<<< + * + * s += 1 */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2230, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_4 = __Pyx_PyInt_From_char(__pyx_v_auxtype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_unknown_type_s, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2525, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2525, __pyx_L1_error) + break; + } - /* "pysam/libcalignedsegment.pyx":2229 - * property query: - * """deprecated, query_alignment_sequence instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.query_alignment_sequence - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2527 + * raise KeyError("unknown type '%s'" % auxtype) + * + * s += 1 # <<<<<<<<<<<<<< + * + * if with_value_type: */ + __pyx_v_s = (__pyx_v_s + 1); - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2231 - * def __get__(self): - * return self.query_alignment_sequence - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_alignment_sequence = v - * property qqual: + /* "pysam/libcalignedsegment.pyx":2529 + * s += 1 + * + * if with_value_type: # <<<<<<<<<<<<<< + * result.append((charptr_to_str(auxtag), value, chr(auxtype))) + * else: */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_with_value_type); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2529, __pyx_L1_error) + if (__pyx_t_2) { -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5query_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5query_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5query_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5query_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2231, 0, __PYX_ERR(0, 2231, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2232 - * return self.query_alignment_sequence - * def __set__(self, v): - * self.query_alignment_sequence = v # <<<<<<<<<<<<<< - * property qqual: - * """deprecated, query_alignment_qualities instead""" + /* "pysam/libcalignedsegment.pyx":2530 + * + * if with_value_type: + * result.append((charptr_to_str(auxtag), value, chr(auxtype))) # <<<<<<<<<<<<<< + * else: + * result.append((charptr_to_str(auxtag), value)) */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_sequence, __pyx_v_v) < 0) __PYX_ERR(0, 2232, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_auxtag, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2530, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyInt_From_char(__pyx_v_auxtype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2530, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2530, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2530, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_value); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_6); + __pyx_t_4 = 0; + __pyx_t_6 = 0; + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 2530, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcalignedsegment.pyx":2231 - * def __get__(self): - * return self.query_alignment_sequence - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_alignment_sequence = v - * property qqual: + /* "pysam/libcalignedsegment.pyx":2529 + * s += 1 + * + * if with_value_type: # <<<<<<<<<<<<<< + * result.append((charptr_to_str(auxtag), value, chr(auxtype))) + * else: */ + goto __pyx_L8; + } - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2235 - * property qqual: - * """deprecated, query_alignment_qualities instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return array_to_qualitystring(self.query_alignment_qualities) - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2532 + * result.append((charptr_to_str(auxtag), value, chr(auxtype))) + * else: + * result.append((charptr_to_str(auxtag), value)) # <<<<<<<<<<<<<< + * + * return result */ + /*else*/ { + __pyx_t_7 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_auxtag, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_value); + __pyx_t_7 = 0; + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_6); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 2532, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __pyx_L8:; + } -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qqual___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qqual___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2235, 0, __PYX_ERR(0, 2235, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2236 - * """deprecated, query_alignment_qualities instead""" - * def __get__(self): - * return array_to_qualitystring(self.query_alignment_qualities) # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.query_alignment_qualities = qualitystring_to_array(v) + /* "pysam/libcalignedsegment.pyx":2534 + * result.append((charptr_to_str(auxtag), value)) + * + * return result # <<<<<<<<<<<<<< + * + * def set_tags(self, tags): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_qualities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2236, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 2236, __pyx_L1_error) - __pyx_t_2 = __pyx_f_5pysam_9libcutils_array_to_qualitystring(((arrayobject *)__pyx_t_1), 0, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2236, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2235 - * property qqual: - * """deprecated, query_alignment_qualities instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return array_to_qualitystring(self.query_alignment_qualities) - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2457 + * return value + * + * def get_tags(self, with_value_type=False): # <<<<<<<<<<<<<< + * """the fields in the optional aligment section. + * */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qqual.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.get_tags", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_value); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2237 - * def __get__(self): - * return array_to_qualitystring(self.query_alignment_qualities) - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_alignment_qualities = qualitystring_to_array(v) - * property qstart: - */ - -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2237, 0, __PYX_ERR(0, 2237, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2238 - * return array_to_qualitystring(self.query_alignment_qualities) - * def __set__(self, v): - * self.query_alignment_qualities = qualitystring_to_array(v) # <<<<<<<<<<<<<< - * property qstart: - * """deprecated, use query_alignment_start instead""" - */ - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9libcutils_qualitystring_to_array(__pyx_v_v, 0, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2238, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_qualities, __pyx_t_1) < 0) __PYX_ERR(0, 2238, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pysam/libcalignedsegment.pyx":2237 - * def __get__(self): - * return array_to_qualitystring(self.query_alignment_qualities) - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_alignment_qualities = qualitystring_to_array(v) - * property qstart: - */ - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qqual.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2241 - * property qstart: - * """deprecated, use query_alignment_start instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.query_alignment_start - * def __set__(self, v): +/* "pysam/libcalignedsegment.pyx":2536 + * return result + * + * def set_tags(self, tags): # <<<<<<<<<<<<<< + * """sets the fields in the optional alignment section with + * a list of (tag, value) tuples. */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_55set_tags(PyObject *__pyx_v_self, PyObject *__pyx_v_tags); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_54set_tags[] = "AlignedSegment.set_tags(self, tags)\nsets the fields in the optional alignment section with\n a list of (tag, value) tuples.\n\n The :term:`value type` of the values is determined from the\n python type. Optionally, a type may be given explicitly as\n a third value in the tuple, For example:\n\n x.set_tags([(NM, 2, \"i\"), (RG, \"GJP00TM04\", \"Z\")]\n\n This method will not enforce the rule that the same tag may appear\n only once in the optional alignment section.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_55set_tags(PyObject *__pyx_v_self, PyObject *__pyx_v_tags) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6qstart___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("set_tags (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_54set_tags(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tags)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6qstart___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_54set_tags(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags) { + bam1_t *__pyx_v_src; + uint8_t *__pyx_v_s; + char *__pyx_v_temp; + int __pyx_v_new_size; + int __pyx_v_old_size; + PyObject *__pyx_v_fmt = NULL; + PyObject *__pyx_v_args = NULL; + PyObject *__pyx_v_buffer = NULL; + bam1_t *__pyx_v_retval; + PyObject *__pyx_v_p = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2241, 0, __PYX_ERR(0, 2241, __pyx_L1_error)); + bam1_t *__pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *(*__pyx_t_10)(PyObject *); + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + char *__pyx_t_13; + __Pyx_RefNannySetupContext("set_tags", 0); + __Pyx_TraceCall("set_tags", __pyx_f[0], 2536, 0, __PYX_ERR(0, 2536, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2242 - * """deprecated, use query_alignment_start instead""" - * def __get__(self): - * return self.query_alignment_start # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.query_alignment_start = v + /* "pysam/libcalignedsegment.pyx":2553 + * cdef uint8_t * s + * cdef char * temp + * cdef int new_size = 0 # <<<<<<<<<<<<<< + * cdef int old_size + * src = self._delegate */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2242, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_v_new_size = 0; - /* "pysam/libcalignedsegment.pyx":2241 - * property qstart: - * """deprecated, use query_alignment_start instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.query_alignment_start - * def __set__(self, v): + /* "pysam/libcalignedsegment.pyx":2555 + * cdef int new_size = 0 + * cdef int old_size + * src = self._delegate # <<<<<<<<<<<<<< + * + * # convert and pack the data */ + __pyx_t_1 = __pyx_v_self->_delegate; + __pyx_v_src = __pyx_t_1; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qstart.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2243 - * def __get__(self): - * return self.query_alignment_start - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_alignment_start = v - * property qend: + /* "pysam/libcalignedsegment.pyx":2558 + * + * # convert and pack the data + * if tags is not None and len(tags) > 0: # <<<<<<<<<<<<<< + * fmt, args = pack_tags(tags) + * new_size = struct.calcsize(fmt) */ + __pyx_t_3 = (__pyx_v_tags != Py_None); + __pyx_t_4 = (__pyx_t_3 != 0); + if (__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_5 = PyObject_Length(__pyx_v_tags); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2558, __pyx_L1_error) + __pyx_t_4 = ((__pyx_t_5 > 0) != 0); + __pyx_t_2 = __pyx_t_4; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { -/* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2243, 0, __PYX_ERR(0, 2243, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":2559 + * # convert and pack the data + * if tags is not None and len(tags) > 0: + * fmt, args = pack_tags(tags) # <<<<<<<<<<<<<< + * new_size = struct.calcsize(fmt) + * buffer = ctypes.create_string_buffer(new_size) + */ + __pyx_t_6 = __pyx_f_5pysam_18libcalignedsegment_pack_tags(__pyx_v_tags); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { + PyObject* sequence = __pyx_t_6; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 2559, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_7 = PyList_GET_ITEM(sequence, 0); + __pyx_t_8 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + #else + __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_9 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; + index = 0; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) __PYX_ERR(0, 2559, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2559, __pyx_L1_error) + __pyx_L7_unpacking_done:; + } + __pyx_v_fmt = __pyx_t_7; + __pyx_t_7 = 0; + __pyx_v_args = __pyx_t_8; + __pyx_t_8 = 0; - /* "pysam/libcalignedsegment.pyx":2244 - * return self.query_alignment_start - * def __set__(self, v): - * self.query_alignment_start = v # <<<<<<<<<<<<<< - * property qend: - * """deprecated, use query_alignment_end instead""" + /* "pysam/libcalignedsegment.pyx":2560 + * if tags is not None and len(tags) > 0: + * fmt, args = pack_tags(tags) + * new_size = struct.calcsize(fmt) # <<<<<<<<<<<<<< + * buffer = ctypes.create_string_buffer(new_size) + * struct.pack_into(fmt, */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_start, __pyx_v_v) < 0) __PYX_ERR(0, 2244, __pyx_L1_error) + __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2560, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_calcsize); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2560, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_8) { + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_fmt); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2560, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_fmt}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2560, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_fmt}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2560, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2560, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_INCREF(__pyx_v_fmt); + __Pyx_GIVEREF(__pyx_v_fmt); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_fmt); + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2560, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2560, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_new_size = __pyx_t_11; - /* "pysam/libcalignedsegment.pyx":2243 - * def __get__(self): - * return self.query_alignment_start - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_alignment_start = v - * property qend: + /* "pysam/libcalignedsegment.pyx":2561 + * fmt, args = pack_tags(tags) + * new_size = struct.calcsize(fmt) + * buffer = ctypes.create_string_buffer(new_size) # <<<<<<<<<<<<<< + * struct.pack_into(fmt, + * buffer, + */ + __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_ctypes); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_create_string_buffer); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_new_size); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + if (!__pyx_t_8) { + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2561, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2561, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2561, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_buffer = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pysam/libcalignedsegment.pyx":2562 + * new_size = struct.calcsize(fmt) + * buffer = ctypes.create_string_buffer(new_size) + * struct.pack_into(fmt, # <<<<<<<<<<<<<< + * buffer, + * 0, + */ + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_pack_into); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pysam/libcalignedsegment.pyx":2563 + * buffer = ctypes.create_string_buffer(new_size) + * struct.pack_into(fmt, + * buffer, # <<<<<<<<<<<<<< + * 0, + * *args) + */ + __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_v_fmt); + __Pyx_GIVEREF(__pyx_v_fmt); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_fmt); + __Pyx_INCREF(__pyx_v_buffer); + __Pyx_GIVEREF(__pyx_v_buffer); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_buffer); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_int_0); + + /* "pysam/libcalignedsegment.pyx":2562 + * new_size = struct.calcsize(fmt) + * buffer = ctypes.create_string_buffer(new_size) + * struct.pack_into(fmt, # <<<<<<<<<<<<<< + * buffer, + * 0, + */ + __pyx_t_12 = __Pyx_PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_7 = PyNumber_Add(__pyx_t_6, __pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pysam/libcalignedsegment.pyx":2558 + * + * # convert and pack the data + * if tags is not None and len(tags) > 0: # <<<<<<<<<<<<<< + * fmt, args = pack_tags(tags) + * new_size = struct.calcsize(fmt) + */ + } + + /* "pysam/libcalignedsegment.pyx":2571 + * # If total_size == 0, the aux field will be + * # empty + * old_size = pysam_bam_get_l_aux(src) # <<<<<<<<<<<<<< + * cdef bam1_t * retval = pysam_bam_update(src, + * old_size, + */ + __pyx_v_old_size = pysam_bam_get_l_aux(__pyx_v_src); + + /* "pysam/libcalignedsegment.pyx":2572 + * # empty + * old_size = pysam_bam_get_l_aux(src) + * cdef bam1_t * retval = pysam_bam_update(src, # <<<<<<<<<<<<<< + * old_size, + * new_size, + */ + __pyx_v_retval = pysam_bam_update(__pyx_v_src, __pyx_v_old_size, __pyx_v_new_size, pysam_bam_get_aux(__pyx_v_src)); + + /* "pysam/libcalignedsegment.pyx":2576 + * new_size, + * pysam_bam_get_aux(src)) + * if retval == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocated memory") + * + */ + __pyx_t_2 = ((__pyx_v_retval == NULL) != 0); + if (unlikely(__pyx_t_2)) { + + /* "pysam/libcalignedsegment.pyx":2577 + * pysam_bam_get_aux(src)) + * if retval == NULL: + * raise MemoryError("could not allocated memory") # <<<<<<<<<<<<<< + * + * # copy data only if there is any + */ + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2577, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_Raise(__pyx_t_12, 0, 0, 0); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __PYX_ERR(0, 2577, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":2576 + * new_size, + * pysam_bam_get_aux(src)) + * if retval == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocated memory") + * + */ + } + + /* "pysam/libcalignedsegment.pyx":2580 + * + * # copy data only if there is any + * if new_size > 0: # <<<<<<<<<<<<<< + * + * # get location of new data + */ + __pyx_t_2 = ((__pyx_v_new_size > 0) != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":2583 + * + * # get location of new data + * s = pysam_bam_get_aux(src) # <<<<<<<<<<<<<< + * + * # check if there is direct path from buffer.raw to tmp + */ + __pyx_v_s = pysam_bam_get_aux(__pyx_v_src); + + /* "pysam/libcalignedsegment.pyx":2586 + * + * # check if there is direct path from buffer.raw to tmp + * p = buffer.raw # <<<<<<<<<<<<<< + * # create handle to make sure buffer stays alive long + * # enough for memcpy, see issue 129 + */ + if (unlikely(!__pyx_v_buffer)) { __Pyx_RaiseUnboundLocalError("buffer"); __PYX_ERR(0, 2586, __pyx_L1_error) } + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_buffer, __pyx_n_s_raw); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2586, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_v_p = __pyx_t_12; + __pyx_t_12 = 0; + + /* "pysam/libcalignedsegment.pyx":2589 + * # create handle to make sure buffer stays alive long + * # enough for memcpy, see issue 129 + * temp = p # <<<<<<<<<<<<<< + * memcpy(s, temp, new_size) + * + */ + __pyx_t_13 = __Pyx_PyObject_AsWritableString(__pyx_v_p); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) __PYX_ERR(0, 2589, __pyx_L1_error) + __pyx_v_temp = __pyx_t_13; + + /* "pysam/libcalignedsegment.pyx":2590 + * # enough for memcpy, see issue 129 + * temp = p + * memcpy(s, temp, new_size) # <<<<<<<<<<<<<< + * + * + */ + (void)(memcpy(__pyx_v_s, __pyx_v_temp, __pyx_v_new_size)); + + /* "pysam/libcalignedsegment.pyx":2580 + * + * # copy data only if there is any + * if new_size > 0: # <<<<<<<<<<<<<< + * + * # get location of new data + */ + } + + /* "pysam/libcalignedsegment.pyx":2536 + * return result + * + * def set_tags(self, tags): # <<<<<<<<<<<<<< + * """sets the fields in the optional alignment section with + * a list of (tag, value) tuples. */ /* function exit code */ - __pyx_r = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qstart.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.set_tags", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF(__pyx_v_fmt); + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_buffer); + __Pyx_XDECREF(__pyx_v_p); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2247 - * property qend: - * """deprecated, use query_alignment_end instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.query_alignment_end - * def __set__(self, v): +/* "pysam/libcalignedsegment.pyx":2608 + * property qname: + * """deprecated, use query_name instead""" + * def __get__(self): return self.query_name # <<<<<<<<<<<<<< + * def __set__(self, v): self.query_name = v + * property tid: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qend_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qend_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qname_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qname_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qend___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qname___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qend___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qname___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2247, 0, __PYX_ERR(0, 2247, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2248 - * """deprecated, use query_alignment_end instead""" - * def __get__(self): - * return self.query_alignment_end # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.query_alignment_end = v - */ + __Pyx_TraceCall("__get__", __pyx_f[0], 2608, 0, __PYX_ERR(0, 2608, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2248, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2608, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2247 - * property qend: - * """deprecated, use query_alignment_end instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.query_alignment_end - * def __set__(self, v): - */ - /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qend.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qname.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -25480,56 +29303,40 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qend___g return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2249 - * def __get__(self): - * return self.query_alignment_end - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_alignment_end = v - * property qlen: +/* "pysam/libcalignedsegment.pyx":2609 + * """deprecated, use query_name instead""" + * def __get__(self): return self.query_name + * def __set__(self, v): self.query_name = v # <<<<<<<<<<<<<< + * property tid: + * """deprecated, use reference_id instead""" */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qend_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qname_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qend_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qname_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2249, 0, __PYX_ERR(0, 2249, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2250 - * return self.query_alignment_end - * def __set__(self, v): - * self.query_alignment_end = v # <<<<<<<<<<<<<< - * property qlen: - * """deprecated, use query_alignment_length instead""" - */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_end, __pyx_v_v) < 0) __PYX_ERR(0, 2250, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":2249 - * def __get__(self): - * return self.query_alignment_end - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_alignment_end = v - * property qlen: - */ + __Pyx_TraceCall("__set__", __pyx_f[0], 2609, 0, __PYX_ERR(0, 2609, __pyx_L1_error)); + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_name, __pyx_v_v) < 0) __PYX_ERR(0, 2609, __pyx_L1_error) /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qend.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qname.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -25537,61 +29344,45 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qend_2__set__( return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2253 - * property qlen: - * """deprecated, use query_alignment_length instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.query_alignment_length - * def __set__(self, v): +/* "pysam/libcalignedsegment.pyx":2612 + * property tid: + * """deprecated, use reference_id instead""" + * def __get__(self): return self.reference_id # <<<<<<<<<<<<<< + * def __set__(self, v): self.reference_id = v + * property pos: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3tid_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qlen___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3tid___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qlen___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3tid___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2253, 0, __PYX_ERR(0, 2253, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2254 - * """deprecated, use query_alignment_length instead""" - * def __get__(self): - * return self.query_alignment_length # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.query_alignment_length = v - */ + __Pyx_TraceCall("__get__", __pyx_f[0], 2612, 0, __PYX_ERR(0, 2612, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2254, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2612, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2253 - * property qlen: - * """deprecated, use query_alignment_length instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.query_alignment_length - * def __set__(self, v): - */ - /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -25600,56 +29391,40 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qlen___g return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2255 - * def __get__(self): - * return self.query_alignment_length - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_alignment_length = v - * property mrnm: +/* "pysam/libcalignedsegment.pyx":2613 + * """deprecated, use reference_id instead""" + * def __get__(self): return self.reference_id + * def __set__(self, v): self.reference_id = v # <<<<<<<<<<<<<< + * property pos: + * """deprecated, use reference_start instead""" */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3tid_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3tid_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2255, 0, __PYX_ERR(0, 2255, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2256 - * return self.query_alignment_length - * def __set__(self, v): - * self.query_alignment_length = v # <<<<<<<<<<<<<< - * property mrnm: - * """deprecated, use next_reference_id instead""" - */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_length, __pyx_v_v) < 0) __PYX_ERR(0, 2256, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":2255 - * def __get__(self): - * return self.query_alignment_length - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.query_alignment_length = v - * property mrnm: - */ + __Pyx_TraceCall("__set__", __pyx_f[0], 2613, 0, __PYX_ERR(0, 2613, __pyx_L1_error)); + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id, __pyx_v_v) < 0) __PYX_ERR(0, 2613, __pyx_L1_error) /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qlen.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tid.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -25657,61 +29432,45 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_2__set__( return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2259 - * property mrnm: - * """deprecated, use next_reference_id instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.next_reference_id - * def __set__(self, v): +/* "pysam/libcalignedsegment.pyx":2616 + * property pos: + * """deprecated, use reference_start instead""" + * def __get__(self): return self.reference_start # <<<<<<<<<<<<<< + * def __set__(self, v): self.reference_start = v + * property mapq: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3pos_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3pos___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3pos___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2259, 0, __PYX_ERR(0, 2259, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2260 - * """deprecated, use next_reference_id instead""" - * def __get__(self): - * return self.next_reference_id # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.next_reference_id = v - */ + __Pyx_TraceCall("__get__", __pyx_f[0], 2616, 0, __PYX_ERR(0, 2616, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2260, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2616, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2259 - * property mrnm: - * """deprecated, use next_reference_id instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.next_reference_id - * def __set__(self, v): - */ - /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mrnm.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -25720,56 +29479,40 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm___g return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2261 - * def __get__(self): - * return self.next_reference_id - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.next_reference_id = v - * property mpos: +/* "pysam/libcalignedsegment.pyx":2617 + * """deprecated, use reference_start instead""" + * def __get__(self): return self.reference_start + * def __set__(self, v): self.reference_start = v # <<<<<<<<<<<<<< + * property mapq: + * """deprecated, use mapping_quality instead""" */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3pos_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3pos_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2261, 0, __PYX_ERR(0, 2261, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2262 - * return self.next_reference_id - * def __set__(self, v): - * self.next_reference_id = v # <<<<<<<<<<<<<< - * property mpos: - * """deprecated, use next_reference_start instead""" - */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id, __pyx_v_v) < 0) __PYX_ERR(0, 2262, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":2261 - * def __get__(self): - * return self.next_reference_id - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.next_reference_id = v - * property mpos: - */ + __Pyx_TraceCall("__set__", __pyx_f[0], 2617, 0, __PYX_ERR(0, 2617, __pyx_L1_error)); + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_start, __pyx_v_v) < 0) __PYX_ERR(0, 2617, __pyx_L1_error) /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mrnm.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.pos.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -25777,8 +29520,184 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_2__set__( return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2265 - * property mpos: +/* "pysam/libcalignedsegment.pyx":2620 + * property mapq: + * """deprecated, use mapping_quality instead""" + * def __get__(self): return self.mapping_quality # <<<<<<<<<<<<<< + * def __set__(self, v): self.mapping_quality = v + * property rnext: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mapq___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mapq___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2620, 0, __PYX_ERR(0, 2620, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2620, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mapq.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":2621 + * """deprecated, use mapping_quality instead""" + * def __get__(self): return self.mapping_quality + * def __set__(self, v): self.mapping_quality = v # <<<<<<<<<<<<<< + * property rnext: + * """deprecated, use next_reference_id instead""" + */ + +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2621, 0, __PYX_ERR(0, 2621, __pyx_L1_error)); + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality, __pyx_v_v) < 0) __PYX_ERR(0, 2621, __pyx_L1_error) + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mapq.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":2624 + * property rnext: + * """deprecated, use next_reference_id instead""" + * def __get__(self): return self.next_reference_id # <<<<<<<<<<<<<< + * def __set__(self, v): self.next_reference_id = v + * property pnext: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rnext___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rnext___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2624, 0, __PYX_ERR(0, 2624, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2624, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.rnext.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":2625 + * """deprecated, use next_reference_id instead""" + * def __get__(self): return self.next_reference_id + * def __set__(self, v): self.next_reference_id = v # <<<<<<<<<<<<<< + * property pnext: + * """deprecated, use next_reference_start instead""" + */ + +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2625, 0, __PYX_ERR(0, 2625, __pyx_L1_error)); + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id, __pyx_v_v) < 0) __PYX_ERR(0, 2625, __pyx_L1_error) + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.rnext.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":2628 + * property pnext: * """deprecated, use next_reference_start instead""" * def __get__(self): # <<<<<<<<<<<<<< * return self.next_reference_start @@ -25786,27 +29705,27 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_2__set__( */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mpos___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5pnext___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mpos___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5pnext___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2265, 0, __PYX_ERR(0, 2265, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2628, 0, __PYX_ERR(0, 2628, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2266 + /* "pysam/libcalignedsegment.pyx":2629 * """deprecated, use next_reference_start instead""" * def __get__(self): * return self.next_reference_start # <<<<<<<<<<<<<< @@ -25814,14 +29733,14 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mpos___g * self.next_reference_start = v */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2266, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2629, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2265 - * property mpos: + /* "pysam/libcalignedsegment.pyx":2628 + * property pnext: * """deprecated, use next_reference_start instead""" * def __get__(self): # <<<<<<<<<<<<<< * return self.next_reference_start @@ -25831,7 +29750,7 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mpos___g /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mpos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.pnext.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -25840,56 +29759,56 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mpos___g return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2267 +/* "pysam/libcalignedsegment.pyx":2630 * def __get__(self): * return self.next_reference_start * def __set__(self, v): # <<<<<<<<<<<<<< * self.next_reference_start = v - * property rname: + * property cigar: */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2267, 0, __PYX_ERR(0, 2267, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 2630, 0, __PYX_ERR(0, 2630, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2268 + /* "pysam/libcalignedsegment.pyx":2631 * return self.next_reference_start * def __set__(self, v): * self.next_reference_start = v # <<<<<<<<<<<<<< - * property rname: - * """deprecated, use reference_id instead""" + * property cigar: + * """deprecated, use cigartuples instead""" */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start, __pyx_v_v) < 0) __PYX_ERR(0, 2268, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start, __pyx_v_v) < 0) __PYX_ERR(0, 2631, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2267 + /* "pysam/libcalignedsegment.pyx":2630 * def __get__(self): * return self.next_reference_start * def __set__(self, v): # <<<<<<<<<<<<<< * self.next_reference_start = v - * property rname: + * property cigar: */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mpos.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.pnext.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -25897,119 +29816,149 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_2__set__( return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2271 - * property rname: - * """deprecated, use reference_id instead""" +/* "pysam/libcalignedsegment.pyx":2634 + * property cigar: + * """deprecated, use cigartuples instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.reference_id - * def __set__(self, v): + * r = self.cigartuples + * if r is None: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rname_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rname_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rname___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5cigar___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rname___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5cigar___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { + PyObject *__pyx_v_r = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2271, 0, __PYX_ERR(0, 2271, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2634, 0, __PYX_ERR(0, 2634, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2272 - * """deprecated, use reference_id instead""" + /* "pysam/libcalignedsegment.pyx":2635 + * """deprecated, use cigartuples instead""" * def __get__(self): - * return self.reference_id # <<<<<<<<<<<<<< - * def __set__(self, v): - * self.reference_id = v + * r = self.cigartuples # <<<<<<<<<<<<<< + * if r is None: + * r = [] */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2272, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2635, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; + __pyx_v_r = __pyx_t_1; __pyx_t_1 = 0; + + /* "pysam/libcalignedsegment.pyx":2636 + * def __get__(self): + * r = self.cigartuples + * if r is None: # <<<<<<<<<<<<<< + * r = [] + * return r + */ + __pyx_t_2 = (__pyx_v_r == Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":2637 + * r = self.cigartuples + * if r is None: + * r = [] # <<<<<<<<<<<<<< + * return r + * def __set__(self, v): self.cigartuples = v + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2637, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF_SET(__pyx_v_r, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignedsegment.pyx":2636 + * def __get__(self): + * r = self.cigartuples + * if r is None: # <<<<<<<<<<<<<< + * r = [] + * return r + */ + } + + /* "pysam/libcalignedsegment.pyx":2638 + * if r is None: + * r = [] + * return r # <<<<<<<<<<<<<< + * def __set__(self, v): self.cigartuples = v + * property tlen: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_r); + __pyx_r = __pyx_v_r; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2271 - * property rname: - * """deprecated, use reference_id instead""" + /* "pysam/libcalignedsegment.pyx":2634 + * property cigar: + * """deprecated, use cigartuples instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.reference_id - * def __set__(self, v): + * r = self.cigartuples + * if r is None: */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.rname.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.cigar.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_r); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2273 - * def __get__(self): - * return self.reference_id - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.reference_id = v - * property isize: +/* "pysam/libcalignedsegment.pyx":2639 + * r = [] + * return r + * def __set__(self, v): self.cigartuples = v # <<<<<<<<<<<<<< + * property tlen: + * """deprecated, use template_length instead""" */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rname_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rname_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2273, 0, __PYX_ERR(0, 2273, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2274 - * return self.reference_id - * def __set__(self, v): - * self.reference_id = v # <<<<<<<<<<<<<< - * property isize: - * """deprecated, use template_length instead""" - */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id, __pyx_v_v) < 0) __PYX_ERR(0, 2274, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":2273 - * def __get__(self): - * return self.reference_id - * def __set__(self, v): # <<<<<<<<<<<<<< - * self.reference_id = v - * property isize: - */ + __Pyx_TraceCall("__set__", __pyx_f[0], 2639, 0, __PYX_ERR(0, 2639, __pyx_L1_error)); + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples, __pyx_v_v) < 0) __PYX_ERR(0, 2639, __pyx_L1_error) /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.rname.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.cigar.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -26017,8 +29966,8 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rname_2__set__ return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2277 - * property isize: +/* "pysam/libcalignedsegment.pyx":2642 + * property tlen: * """deprecated, use template_length instead""" * def __get__(self): # <<<<<<<<<<<<<< * return self.template_length @@ -26026,27 +29975,27 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rname_2__set__ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5isize_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5isize_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5isize___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tlen___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5isize___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tlen___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2277, 0, __PYX_ERR(0, 2277, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2642, 0, __PYX_ERR(0, 2642, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2278 + /* "pysam/libcalignedsegment.pyx":2643 * """deprecated, use template_length instead""" * def __get__(self): * return self.template_length # <<<<<<<<<<<<<< @@ -26054,14 +30003,14 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5isize___ * self.template_length = v */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2278, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2643, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2277 - * property isize: + /* "pysam/libcalignedsegment.pyx":2642 + * property tlen: * """deprecated, use template_length instead""" * def __get__(self): # <<<<<<<<<<<<<< * return self.template_length @@ -26071,7 +30020,7 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5isize___ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.isize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -26080,56 +30029,56 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5isize___ return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2279 +/* "pysam/libcalignedsegment.pyx":2644 * def __get__(self): * return self.template_length * def __set__(self, v): # <<<<<<<<<<<<<< * self.template_length = v - * property blocks: + * property seq: */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5isize_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5isize_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5isize_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5isize_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2279, 0, __PYX_ERR(0, 2279, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 2644, 0, __PYX_ERR(0, 2644, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2280 + /* "pysam/libcalignedsegment.pyx":2645 * return self.template_length * def __set__(self, v): * self.template_length = v # <<<<<<<<<<<<<< - * property blocks: - * """deprecated, use get_blocks() instead""" + * property seq: + * """deprecated, use query_sequence instead""" */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length, __pyx_v_v) < 0) __PYX_ERR(0, 2280, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length, __pyx_v_v) < 0) __PYX_ERR(0, 2645, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2279 + /* "pysam/libcalignedsegment.pyx":2644 * def __get__(self): * return self.template_length * def __set__(self, v): # <<<<<<<<<<<<<< * self.template_length = v - * property blocks: + * property seq: */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.isize.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tlen.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -26137,83 +30086,61 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5isize_2__set__ return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2283 - * property blocks: - * """deprecated, use get_blocks() instead""" +/* "pysam/libcalignedsegment.pyx":2648 + * property seq: + * """deprecated, use query_sequence instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.get_blocks() - * property aligned_pairs: + * return self.query_sequence + * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6blocks_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6blocks_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3seq_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3seq_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6blocks___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3seq___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6blocks___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3seq___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2283, 0, __PYX_ERR(0, 2283, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2648, 0, __PYX_ERR(0, 2648, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2284 - * """deprecated, use get_blocks() instead""" + /* "pysam/libcalignedsegment.pyx":2649 + * """deprecated, use query_sequence instead""" * def __get__(self): - * return self.get_blocks() # <<<<<<<<<<<<<< - * property aligned_pairs: - * """deprecated, use get_aligned_pairs() instead""" + * return self.query_sequence # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.query_sequence = v */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_blocks); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2284, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2284, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2284, __pyx_L1_error) - } + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2649, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2283 - * property blocks: - * """deprecated, use get_blocks() instead""" + /* "pysam/libcalignedsegment.pyx":2648 + * property seq: + * """deprecated, use query_sequence instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.get_blocks() - * property aligned_pairs: + * return self.query_sequence + * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.blocks.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.seq.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -26222,168 +30149,124 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6blocks__ return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2287 - * property aligned_pairs: - * """deprecated, use get_aligned_pairs() instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.get_aligned_pairs() - * property inferred_length: +/* "pysam/libcalignedsegment.pyx":2650 + * def __get__(self): + * return self.query_sequence + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_sequence = v + * property qual: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13aligned_pairs_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13aligned_pairs_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3seq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3seq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_13aligned_pairs___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3seq_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_13aligned_pairs___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_3seq_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2287, 0, __PYX_ERR(0, 2287, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2650, 0, __PYX_ERR(0, 2650, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2288 - * """deprecated, use get_aligned_pairs() instead""" - * def __get__(self): - * return self.get_aligned_pairs() # <<<<<<<<<<<<<< - * property inferred_length: - * """deprecated, use infer_query_length() instead""" + /* "pysam/libcalignedsegment.pyx":2651 + * return self.query_sequence + * def __set__(self, v): + * self.query_sequence = v # <<<<<<<<<<<<<< + * property qual: + * """deprecated, query_qualities instead""" */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2288, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2288, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2288, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence, __pyx_v_v) < 0) __PYX_ERR(0, 2651, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2287 - * property aligned_pairs: - * """deprecated, use get_aligned_pairs() instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.get_aligned_pairs() - * property inferred_length: + /* "pysam/libcalignedsegment.pyx":2650 + * def __get__(self): + * return self.query_sequence + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_sequence = v + * property qual: */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.aligned_pairs.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.seq.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2291 - * property inferred_length: - * """deprecated, use infer_query_length() instead""" +/* "pysam/libcalignedsegment.pyx":2654 + * property qual: + * """deprecated, query_qualities instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.infer_query_length() - * property positions: + * return array_to_qualitystring(self.query_qualities) + * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15inferred_length_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15inferred_length_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qual_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qual_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15inferred_length___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qual___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15inferred_length___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qual___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2291, 0, __PYX_ERR(0, 2291, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2654, 0, __PYX_ERR(0, 2654, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2292 - * """deprecated, use infer_query_length() instead""" + /* "pysam/libcalignedsegment.pyx":2655 + * """deprecated, query_qualities instead""" * def __get__(self): - * return self.infer_query_length() # <<<<<<<<<<<<<< - * property positions: - * """deprecated, use get_reference_positions() instead""" + * return array_to_qualitystring(self.query_qualities) # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.query_qualities = qualitystring_to_array(v) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_infer_query_length); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2292, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2655, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 2655, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_array_to_qualitystring(((arrayobject *)__pyx_t_1), 0, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2655, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2292, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2292, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2291 - * property inferred_length: - * """deprecated, use infer_query_length() instead""" + /* "pysam/libcalignedsegment.pyx":2654 + * property qual: + * """deprecated, query_qualities instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.infer_query_length() - * property positions: + * return array_to_qualitystring(self.query_qualities) + * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.inferred_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qual.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -26392,168 +30275,123 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15inferre return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2295 - * property positions: - * """deprecated, use get_reference_positions() instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.get_reference_positions() - * property tags: +/* "pysam/libcalignedsegment.pyx":2656 + * def __get__(self): + * return array_to_qualitystring(self.query_qualities) + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_qualities = qualitystring_to_array(v) + * property alen: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9positions_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9positions_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9positions___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qual_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9positions___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qual_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2295, 0, __PYX_ERR(0, 2295, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2656, 0, __PYX_ERR(0, 2656, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2296 - * """deprecated, use get_reference_positions() instead""" - * def __get__(self): - * return self.get_reference_positions() # <<<<<<<<<<<<<< - * property tags: - * """deprecated, use get_tags() instead""" + /* "pysam/libcalignedsegment.pyx":2657 + * return array_to_qualitystring(self.query_qualities) + * def __set__(self, v): + * self.query_qualities = qualitystring_to_array(v) # <<<<<<<<<<<<<< + * property alen: + * """deprecated, reference_length instead""" */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_positions); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2296, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2296, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2296, __pyx_L1_error) - } + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9libcutils_qualitystring_to_array(__pyx_v_v, 0, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2657, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities, __pyx_t_1) < 0) __PYX_ERR(0, 2657, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":2295 - * property positions: - * """deprecated, use get_reference_positions() instead""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self.get_reference_positions() - * property tags: + /* "pysam/libcalignedsegment.pyx":2656 + * def __get__(self): + * return array_to_qualitystring(self.query_qualities) + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_qualities = qualitystring_to_array(v) + * property alen: */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.positions.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qual.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2299 - * property tags: - * """deprecated, use get_tags() instead""" +/* "pysam/libcalignedsegment.pyx":2660 + * property alen: + * """deprecated, reference_length instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.get_tags() - * def __set__(self, tags): + * return self.reference_length + * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tags_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tags_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4alen_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4alen_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tags___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4alen___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tags___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4alen___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2299, 0, __PYX_ERR(0, 2299, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2660, 0, __PYX_ERR(0, 2660, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2300 - * """deprecated, use get_tags() instead""" + /* "pysam/libcalignedsegment.pyx":2661 + * """deprecated, reference_length instead""" * def __get__(self): - * return self.get_tags() # <<<<<<<<<<<<<< - * def __set__(self, tags): - * self.set_tags(tags) + * return self.reference_length # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.reference_length = v */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tags); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2300, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2300, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2300, __pyx_L1_error) - } + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2661, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2299 - * property tags: - * """deprecated, use get_tags() instead""" + /* "pysam/libcalignedsegment.pyx":2660 + * property alen: + * """deprecated, reference_length instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.get_tags() - * def __set__(self, tags): + * return self.reference_length + * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tags.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.alen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -26562,109 +30400,56 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tags___g return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2301 +/* "pysam/libcalignedsegment.pyx":2662 * def __get__(self): - * return self.get_tags() - * def __set__(self, tags): # <<<<<<<<<<<<<< - * self.set_tags(tags) - * def overlap(self): + * return self.reference_length + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.reference_length = v + * property aend: */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tags_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tags_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4alen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4alen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tags_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tags)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4alen_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tags_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4alen_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2301, 0, __PYX_ERR(0, 2301, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 2662, 0, __PYX_ERR(0, 2662, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2302 - * return self.get_tags() - * def __set__(self, tags): - * self.set_tags(tags) # <<<<<<<<<<<<<< - * def overlap(self): - * """deprecated, use get_overlap() instead""" + /* "pysam/libcalignedsegment.pyx":2663 + * return self.reference_length + * def __set__(self, v): + * self.reference_length = v # <<<<<<<<<<<<<< + * property aend: + * """deprecated, reference_end instead""" */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_tags); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2302, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_tags); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2302, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_tags}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2302, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_tags}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2302, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2302, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_INCREF(__pyx_v_tags); - __Pyx_GIVEREF(__pyx_v_tags); - PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_tags); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2302, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_length, __pyx_v_v) < 0) __PYX_ERR(0, 2663, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2301 + /* "pysam/libcalignedsegment.pyx":2662 * def __get__(self): - * return self.get_tags() - * def __set__(self, tags): # <<<<<<<<<<<<<< - * self.set_tags(tags) - * def overlap(self): + * return self.reference_length + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.reference_length = v + * property aend: */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tags.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.alen.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -26672,84 +30457,61 @@ static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tags_2__set__( return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2303 - * def __set__(self, tags): - * self.set_tags(tags) - * def overlap(self): # <<<<<<<<<<<<<< - * """deprecated, use get_overlap() instead""" - * return self.get_overlap() +/* "pysam/libcalignedsegment.pyx":2666 + * property aend: + * """deprecated, reference_end instead""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.reference_end + * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_43overlap(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_42overlap[] = "AlignedSegment.overlap(self)\ndeprecated, use get_overlap() instead"; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_43overlap(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4aend_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4aend_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("overlap (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_42overlap(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4aend___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_42overlap(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4aend___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("overlap", 0); - __Pyx_TraceCall("overlap", __pyx_f[0], 2303, 0, __PYX_ERR(0, 2303, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2666, 0, __PYX_ERR(0, 2666, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2305 - * def overlap(self): - * """deprecated, use get_overlap() instead""" - * return self.get_overlap() # <<<<<<<<<<<<<< - * def opt(self, tag): - * """deprecated, use get_tag() instead""" + /* "pysam/libcalignedsegment.pyx":2667 + * """deprecated, reference_end instead""" + * def __get__(self): + * return self.reference_end # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.reference_end = v */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_overlap); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2305, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2305, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2305, __pyx_L1_error) - } + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2667, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2303 - * def __set__(self, tags): - * self.set_tags(tags) - * def overlap(self): # <<<<<<<<<<<<<< - * """deprecated, use get_overlap() instead""" - * return self.get_overlap() + /* "pysam/libcalignedsegment.pyx":2666 + * property aend: + * """deprecated, reference_end instead""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.reference_end + * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.overlap", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.aend.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -26758,206 +30520,118 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_42overlap return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2306 - * """deprecated, use get_overlap() instead""" - * return self.get_overlap() - * def opt(self, tag): # <<<<<<<<<<<<<< - * """deprecated, use get_tag() instead""" - * return self.get_tag(tag) +/* "pysam/libcalignedsegment.pyx":2668 + * def __get__(self): + * return self.reference_end + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.reference_end = v + * property rlen: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_45opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_44opt[] = "AlignedSegment.opt(self, tag)\ndeprecated, use get_tag() instead"; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_45opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4aend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4aend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("opt (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_44opt(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tag)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4aend_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_44opt(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4aend_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("opt", 0); - __Pyx_TraceCall("opt", __pyx_f[0], 2306, 0, __PYX_ERR(0, 2306, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2668, 0, __PYX_ERR(0, 2668, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2308 - * def opt(self, tag): - * """deprecated, use get_tag() instead""" - * return self.get_tag(tag) # <<<<<<<<<<<<<< - * def setTag(self, tag, value, value_type=None, replace=True): - * """deprecated, use set_tag() instead""" + /* "pysam/libcalignedsegment.pyx":2669 + * return self.reference_end + * def __set__(self, v): + * self.reference_end = v # <<<<<<<<<<<<<< + * property rlen: + * """deprecated, query_length instead""" */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self->__pyx_vtab)->get_tag(__pyx_v_self, __pyx_v_tag, 0, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2308, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_end, __pyx_v_v) < 0) __PYX_ERR(0, 2669, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2306 - * """deprecated, use get_overlap() instead""" - * return self.get_overlap() - * def opt(self, tag): # <<<<<<<<<<<<<< - * """deprecated, use get_tag() instead""" - * return self.get_tag(tag) + /* "pysam/libcalignedsegment.pyx":2668 + * def __get__(self): + * return self.reference_end + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.reference_end = v + * property rlen: */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.opt", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.aend.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2309 - * """deprecated, use get_tag() instead""" - * return self.get_tag(tag) - * def setTag(self, tag, value, value_type=None, replace=True): # <<<<<<<<<<<<<< - * """deprecated, use set_tag() instead""" - * return self.set_tag(tag, value, value_type, replace) +/* "pysam/libcalignedsegment.pyx":2672 + * property rlen: + * """deprecated, query_length instead""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.query_length + * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_47setTag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_46setTag[] = "AlignedSegment.setTag(self, tag, value, value_type=None, replace=True)\ndeprecated, use set_tag() instead"; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_47setTag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_tag = 0; - PyObject *__pyx_v_value = 0; - PyObject *__pyx_v_value_type = 0; - PyObject *__pyx_v_replace = 0; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("setTag (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tag,&__pyx_n_s_value,&__pyx_n_s_value_type,&__pyx_n_s_replace,0}; - PyObject* values[4] = {0,0,0,0}; - values[2] = ((PyObject *)Py_None); - values[3] = ((PyObject *)Py_True); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tag)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("setTag", 0, 2, 4, 1); __PYX_ERR(0, 2309, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value_type); - if (value) { values[2] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_replace); - if (value) { values[3] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setTag") < 0)) __PYX_ERR(0, 2309, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_tag = values[0]; - __pyx_v_value = values[1]; - __pyx_v_value_type = values[2]; - __pyx_v_replace = values[3]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("setTag", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2309, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.setTag", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_46setTag(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4rlen___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_46setTag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4rlen___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag __pyx_t_2; - __Pyx_RefNannySetupContext("setTag", 0); - __Pyx_TraceCall("setTag", __pyx_f[0], 2309, 0, __PYX_ERR(0, 2309, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2672, 0, __PYX_ERR(0, 2672, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2311 - * def setTag(self, tag, value, value_type=None, replace=True): - * """deprecated, use set_tag() instead""" - * return self.set_tag(tag, value, value_type, replace) # <<<<<<<<<<<<<< - * - * + /* "pysam/libcalignedsegment.pyx":2673 + * """deprecated, query_length instead""" + * def __get__(self): + * return self.query_length # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.query_length = v */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2.__pyx_n = 2; - __pyx_t_2.value_type = __pyx_v_value_type; - __pyx_t_2.replace = __pyx_v_replace; - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self->__pyx_vtab)->set_tag(__pyx_v_self, __pyx_v_tag, __pyx_v_value, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2311, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2673, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2309 - * """deprecated, use get_tag() instead""" - * return self.get_tag(tag) - * def setTag(self, tag, value, value_type=None, replace=True): # <<<<<<<<<<<<<< - * """deprecated, use set_tag() instead""" - * return self.set_tag(tag, value, value_type, replace) + /* "pysam/libcalignedsegment.pyx":2672 + * property rlen: + * """deprecated, query_length instead""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.query_length + * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.setTag", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.rlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -26966,424 +30640,369 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_46setTag( return __pyx_r; } -/* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") - * def __setstate_cython__(self, __pyx_state): +/* "pysam/libcalignedsegment.pyx":2674 + * def __get__(self): + * return self.query_length + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_length = v + * property query: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_49__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_48__reduce_cython__[] = "AlignedSegment.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_49__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_48__reduce_cython__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_48__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2674, 0, __PYX_ERR(0, 2674, __pyx_L1_error)); - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + /* "pysam/libcalignedsegment.pyx":2675 + * return self.query_length + * def __set__(self, v): + * self.query_length = v # <<<<<<<<<<<<<< + * property query: + * """deprecated, query_alignment_sequence instead""" + */ + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_length, __pyx_v_v) < 0) __PYX_ERR(0, 2675, __pyx_L1_error) - /* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") - * def __setstate_cython__(self, __pyx_state): + /* "pysam/libcalignedsegment.pyx":2674 + * def __get__(self): + * return self.query_length + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_length = v + * property query: */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.rlen.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") +/* "pysam/libcalignedsegment.pyx":2678 + * property query: + * """deprecated, query_alignment_sequence instead""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.query_alignment_sequence + * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_51__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_50__setstate_cython__[] = "AlignedSegment.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_51__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5query_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5query_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_50__setstate_cython__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5query___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_50__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5query___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2678, 0, __PYX_ERR(0, 2678, __pyx_L1_error)); - /* "(tree fragment)":4 - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2679 + * """deprecated, query_alignment_sequence instead""" + * def __get__(self): + * return self.query_alignment_sequence # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.query_alignment_sequence = v */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2679, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") + /* "pysam/libcalignedsegment.pyx":2678 + * property query: + * """deprecated, query_alignment_sequence instead""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.query_alignment_sequence + * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; + __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2324 - * - * ''' - * def __init__(self): # <<<<<<<<<<<<<< - * raise TypeError("this class cannot be instantiated from Python") - * +/* "pysam/libcalignedsegment.pyx":2680 + * def __get__(self): + * return self.query_alignment_sequence + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_alignment_sequence = v + * property qqual: */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5query_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5query_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { - __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} - if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn___init__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5query_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5query_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 2324, 0, __PYX_ERR(0, 2324, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2680, 0, __PYX_ERR(0, 2680, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2325 - * ''' - * def __init__(self): - * raise TypeError("this class cannot be instantiated from Python") # <<<<<<<<<<<<<< - * - * def __str__(self): + /* "pysam/libcalignedsegment.pyx":2681 + * return self.query_alignment_sequence + * def __set__(self, v): + * self.query_alignment_sequence = v # <<<<<<<<<<<<<< + * property qqual: + * """deprecated, query_alignment_qualities instead""" */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2325, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 2325, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_sequence, __pyx_v_v) < 0) __PYX_ERR(0, 2681, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2324 - * - * ''' - * def __init__(self): # <<<<<<<<<<<<<< - * raise TypeError("this class cannot be instantiated from Python") - * + /* "pysam/libcalignedsegment.pyx":2680 + * def __get__(self): + * return self.query_alignment_sequence + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_alignment_sequence = v + * property qqual: */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.query.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; + __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2327 - * raise TypeError("this class cannot be instantiated from Python") - * - * def __str__(self): # <<<<<<<<<<<<<< - * return "\t".join(map(str, - * (self.reference_id, +/* "pysam/libcalignedsegment.pyx":2684 + * property qqual: + * """deprecated, query_alignment_qualities instead""" + * def __get__(self): # <<<<<<<<<<<<<< + * return array_to_qualitystring(self.query_alignment_qualities) + * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_2__str__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qqual___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_2__str__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qqual___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannySetupContext("__str__", 0); - __Pyx_TraceCall("__str__", __pyx_f[0], 2327, 0, __PYX_ERR(0, 2327, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2684, 0, __PYX_ERR(0, 2684, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2328 - * - * def __str__(self): - * return "\t".join(map(str, # <<<<<<<<<<<<<< - * (self.reference_id, - * self.reference_pos, + /* "pysam/libcalignedsegment.pyx":2685 + * """deprecated, query_alignment_qualities instead""" + * def __get__(self): + * return array_to_qualitystring(self.query_alignment_qualities) # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.query_alignment_qualities = qualitystring_to_array(v) */ __Pyx_XDECREF(__pyx_r); - - /* "pysam/libcalignedsegment.pyx":2329 - * def __str__(self): - * return "\t".join(map(str, - * (self.reference_id, # <<<<<<<<<<<<<< - * self.reference_pos, - * self.nsegments))) +\ - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2329, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_qualities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2685, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - - /* "pysam/libcalignedsegment.pyx":2330 - * return "\t".join(map(str, - * (self.reference_id, - * self.reference_pos, # <<<<<<<<<<<<<< - * self.nsegments))) +\ - * "\n" +\ - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2330, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 2685, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_array_to_qualitystring(((arrayobject *)__pyx_t_1), 0, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2685, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2331 - * (self.reference_id, - * self.reference_pos, - * self.nsegments))) +\ # <<<<<<<<<<<<<< - * "\n" +\ - * "\n".join(map(str, self.pileups)) + /* "pysam/libcalignedsegment.pyx":2684 + * property qqual: + * """deprecated, query_alignment_qualities instead""" + * def __get__(self): # <<<<<<<<<<<<<< + * return array_to_qualitystring(self.query_alignment_qualities) + * def __set__(self, v): */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nsegments); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - /* "pysam/libcalignedsegment.pyx":2329 - * def __str__(self): - * return "\t".join(map(str, - * (self.reference_id, # <<<<<<<<<<<<<< - * self.reference_pos, - * self.nsegments))) +\ - */ - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2329, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_3 = 0; + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qqual.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":2328 - * - * def __str__(self): - * return "\t".join(map(str, # <<<<<<<<<<<<<< - * (self.reference_id, - * self.reference_pos, +/* "pysam/libcalignedsegment.pyx":2686 + * def __get__(self): + * return array_to_qualitystring(self.query_alignment_qualities) + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_alignment_qualities = qualitystring_to_array(v) + * property qstart: */ - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2328, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)(&PyString_Type))); - __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)(&PyString_Type))); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2328, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__19, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2328, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignedsegment.pyx":2331 - * (self.reference_id, - * self.reference_pos, - * self.nsegments))) +\ # <<<<<<<<<<<<<< - * "\n" +\ - * "\n".join(map(str, self.pileups)) - */ - __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_kp_s__33); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - /* "pysam/libcalignedsegment.pyx":2333 - * self.nsegments))) +\ - * "\n" +\ - * "\n".join(map(str, self.pileups)) # <<<<<<<<<<<<<< - * - * property reference_id: - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_pileups); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2333, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2333, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)(&PyString_Type))); - __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)(&PyString_Type))); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2333, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__33, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2333, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignedsegment.pyx":2332 - * self.reference_pos, - * self.nsegments))) +\ - * "\n" +\ # <<<<<<<<<<<<<< - * "\n".join(map(str, self.pileups)) - * +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2686, 0, __PYX_ERR(0, 2686, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":2687 + * return array_to_qualitystring(self.query_alignment_qualities) + * def __set__(self, v): + * self.query_alignment_qualities = qualitystring_to_array(v) # <<<<<<<<<<<<<< + * property qstart: + * """deprecated, use query_alignment_start instead""" */ - __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2332, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9libcutils_qualitystring_to_array(__pyx_v_v, 0, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2687, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_qualities, __pyx_t_1) < 0) __PYX_ERR(0, 2687, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":2327 - * raise TypeError("this class cannot be instantiated from Python") - * - * def __str__(self): # <<<<<<<<<<<<<< - * return "\t".join(map(str, - * (self.reference_id, + /* "pysam/libcalignedsegment.pyx":2686 + * def __get__(self): + * return array_to_qualitystring(self.query_alignment_qualities) + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_alignment_qualities = qualitystring_to_array(v) + * property qstart: */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qqual.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2337 - * property reference_id: - * '''the reference sequence number as defined in the header''' +/* "pysam/libcalignedsegment.pyx":2690 + * property qstart: + * """deprecated, use query_alignment_start instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.tid - * + * return self.query_alignment_start + * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_12reference_id_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_12reference_id_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_12reference_id___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6qstart___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_12reference_id___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6qstart___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2337, 0, __PYX_ERR(0, 2337, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2690, 0, __PYX_ERR(0, 2690, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2338 - * '''the reference sequence number as defined in the header''' + /* "pysam/libcalignedsegment.pyx":2691 + * """deprecated, use query_alignment_start instead""" * def __get__(self): - * return self.tid # <<<<<<<<<<<<<< - * - * property reference_name: + * return self.query_alignment_start # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.query_alignment_start = v */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2338, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2691, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2337 - * property reference_id: - * '''the reference sequence number as defined in the header''' + /* "pysam/libcalignedsegment.pyx":2690 + * property qstart: + * """deprecated, use query_alignment_start instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.tid - * + * return self.query_alignment_start + * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.reference_id.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qstart.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -27392,213 +31011,118 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_12reference return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2342 - * property reference_name: - * """:term:`reference` name (None if no AlignmentFile is associated)""" - * def __get__(self): # <<<<<<<<<<<<<< - * if self._alignment_file is not None: - * return self._alignment_file.getrname(self.tid) +/* "pysam/libcalignedsegment.pyx":2692 + * def __get__(self): + * return self.query_alignment_start + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_alignment_start = v + * property qend: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_14reference_name_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_14reference_name_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_14reference_name___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_14reference_name___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2342, 0, __PYX_ERR(0, 2342, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2343 - * """:term:`reference` name (None if no AlignmentFile is associated)""" - * def __get__(self): - * if self._alignment_file is not None: # <<<<<<<<<<<<<< - * return self._alignment_file.getrname(self.tid) - * return None - */ - __pyx_t_1 = (((PyObject *)__pyx_v_self->_alignment_file) != Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2692, 0, __PYX_ERR(0, 2692, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2344 - * def __get__(self): - * if self._alignment_file is not None: - * return self._alignment_file.getrname(self.tid) # <<<<<<<<<<<<<< - * return None - * + /* "pysam/libcalignedsegment.pyx":2693 + * return self.query_alignment_start + * def __set__(self, v): + * self.query_alignment_start = v # <<<<<<<<<<<<<< + * property qend: + * """deprecated, use query_alignment_end instead""" */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->_alignment_file), __pyx_n_s_getrname); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2344, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2344, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2344, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2344, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2344, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2344, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2344, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_start, __pyx_v_v) < 0) __PYX_ERR(0, 2693, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2343 - * """:term:`reference` name (None if no AlignmentFile is associated)""" + /* "pysam/libcalignedsegment.pyx":2692 * def __get__(self): - * if self._alignment_file is not None: # <<<<<<<<<<<<<< - * return self._alignment_file.getrname(self.tid) - * return None - */ - } - - /* "pysam/libcalignedsegment.pyx":2345 - * if self._alignment_file is not None: - * return self._alignment_file.getrname(self.tid) - * return None # <<<<<<<<<<<<<< - * - * property nsegments: - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":2342 - * property reference_name: - * """:term:`reference` name (None if no AlignmentFile is associated)""" - * def __get__(self): # <<<<<<<<<<<<<< - * if self._alignment_file is not None: - * return self._alignment_file.getrname(self.tid) + * return self.query_alignment_start + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_alignment_start = v + * property qend: */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.reference_name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qstart.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2349 - * property nsegments: - * '''number of reads mapping to this column.''' +/* "pysam/libcalignedsegment.pyx":2696 + * property qend: + * """deprecated, use query_alignment_end instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.n_pu - * def __set__(self, n): + * return self.query_alignment_end + * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qend_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qend_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_9nsegments___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qend___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_9nsegments___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qend___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2349, 0, __PYX_ERR(0, 2349, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2696, 0, __PYX_ERR(0, 2696, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2350 - * '''number of reads mapping to this column.''' + /* "pysam/libcalignedsegment.pyx":2697 + * """deprecated, use query_alignment_end instead""" * def __get__(self): - * return self.n_pu # <<<<<<<<<<<<<< - * def __set__(self, n): - * self.n_pu = n - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->n_pu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2350, __pyx_L1_error) + * return self.query_alignment_end # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.query_alignment_end = v + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2697, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2349 - * property nsegments: - * '''number of reads mapping to this column.''' + /* "pysam/libcalignedsegment.pyx":2696 + * property qend: + * """deprecated, use query_alignment_end instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.n_pu - * def __set__(self, n): + * return self.query_alignment_end + * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.nsegments.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qend.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -27607,58 +31131,56 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_ return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2351 +/* "pysam/libcalignedsegment.pyx":2698 * def __get__(self): - * return self.n_pu - * def __set__(self, n): # <<<<<<<<<<<<<< - * self.n_pu = n - * + * return self.query_alignment_end + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_alignment_end = v + * property qlen: */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_n)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qend_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_n) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qend_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2351, 0, __PYX_ERR(0, 2351, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 2698, 0, __PYX_ERR(0, 2698, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2352 - * return self.n_pu - * def __set__(self, n): - * self.n_pu = n # <<<<<<<<<<<<<< - * - * property reference_pos: + /* "pysam/libcalignedsegment.pyx":2699 + * return self.query_alignment_end + * def __set__(self, v): + * self.query_alignment_end = v # <<<<<<<<<<<<<< + * property qlen: + * """deprecated, use query_alignment_length instead""" */ - __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_n); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2352, __pyx_L1_error) - __pyx_v_self->n_pu = __pyx_t_1; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_end, __pyx_v_v) < 0) __PYX_ERR(0, 2699, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2351 + /* "pysam/libcalignedsegment.pyx":2698 * def __get__(self): - * return self.n_pu - * def __set__(self, n): # <<<<<<<<<<<<<< - * self.n_pu = n - * + * return self.query_alignment_end + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_alignment_end = v + * property qlen: */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.nsegments.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qend.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -27666,61 +31188,61 @@ static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_2__set return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2356 - * property reference_pos: - * '''the position in the reference sequence (0-based).''' +/* "pysam/libcalignedsegment.pyx":2702 + * property qlen: + * """deprecated, use query_alignment_length instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.pos - * + * return self.query_alignment_length + * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_13reference_pos_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_13reference_pos_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_13reference_pos___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qlen___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_13reference_pos___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qlen___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2356, 0, __PYX_ERR(0, 2356, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2702, 0, __PYX_ERR(0, 2702, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2357 - * '''the position in the reference sequence (0-based).''' + /* "pysam/libcalignedsegment.pyx":2703 + * """deprecated, use query_alignment_length instead""" * def __get__(self): - * return self.pos # <<<<<<<<<<<<<< - * - * property pileups: + * return self.query_alignment_length # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.query_alignment_length = v */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2357, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2703, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2356 - * property reference_pos: - * '''the position in the reference sequence (0-based).''' + /* "pysam/libcalignedsegment.pyx":2702 + * property qlen: + * """deprecated, use query_alignment_length instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.pos - * + * return self.query_alignment_length + * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.reference_pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -27729,217 +31251,118 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_13reference return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2361 - * property pileups: - * '''list of reads (:class:`pysam.PileupRead`) aligned to this column''' - * def __get__(self): # <<<<<<<<<<<<<< - * cdef int x - * pileups = [] +/* "pysam/libcalignedsegment.pyx":2704 + * def __get__(self): + * return self.query_alignment_length + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_alignment_length = v + * property mrnm: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_7pileups_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_7pileups_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_7pileups___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_7pileups___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { - int __pyx_v_x; - PyObject *__pyx_v_pileups = NULL; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2361, 0, __PYX_ERR(0, 2361, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2363 - * def __get__(self): - * cdef int x - * pileups = [] # <<<<<<<<<<<<<< - * - * if self.plp == NULL or self.plp[0] == NULL: - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2363, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_pileups = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pysam/libcalignedsegment.pyx":2365 - * pileups = [] - * - * if self.plp == NULL or self.plp[0] == NULL: # <<<<<<<<<<<<<< - * raise ValueError("PileupColumn accessed after iterator finished") - * - */ - __pyx_t_3 = ((__pyx_v_self->plp == NULL) != 0); - if (!__pyx_t_3) { - } else { - __pyx_t_2 = __pyx_t_3; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_3 = (((__pyx_v_self->plp[0]) == NULL) != 0); - __pyx_t_2 = __pyx_t_3; - __pyx_L4_bool_binop_done:; - if (unlikely(__pyx_t_2)) { - - /* "pysam/libcalignedsegment.pyx":2366 - * - * if self.plp == NULL or self.plp[0] == NULL: - * raise ValueError("PileupColumn accessed after iterator finished") # <<<<<<<<<<<<<< - * - * # warning: there could be problems if self.n and self.buf are - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 2366, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":2365 - * pileups = [] - * - * if self.plp == NULL or self.plp[0] == NULL: # <<<<<<<<<<<<<< - * raise ValueError("PileupColumn accessed after iterator finished") - * - */ - } - - /* "pysam/libcalignedsegment.pyx":2370 - * # warning: there could be problems if self.n and self.buf are - * # out of sync. - * for x from 0 <= x < self.n_pu: # <<<<<<<<<<<<<< - * pileups.append(makePileupRead(&(self.plp[0][x]), - * self._alignment_file)) - */ - __pyx_t_4 = __pyx_v_self->n_pu; - for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_4; __pyx_v_x++) { - - /* "pysam/libcalignedsegment.pyx":2372 - * for x from 0 <= x < self.n_pu: - * pileups.append(makePileupRead(&(self.plp[0][x]), - * self._alignment_file)) # <<<<<<<<<<<<<< - * return pileups - * - */ - __pyx_t_1 = ((PyObject *)__pyx_v_self->_alignment_file); - __Pyx_INCREF(__pyx_t_1); - - /* "pysam/libcalignedsegment.pyx":2371 - * # out of sync. - * for x from 0 <= x < self.n_pu: - * pileups.append(makePileupRead(&(self.plp[0][x]), # <<<<<<<<<<<<<< - * self._alignment_file)) - * return pileups - */ - __pyx_t_5 = __pyx_f_5pysam_18libcalignedsegment_makePileupRead((&((__pyx_v_self->plp[0])[__pyx_v_x])), ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_t_1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2371, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_pileups, __pyx_t_5); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 2371, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2704, 0, __PYX_ERR(0, 2704, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2373 - * pileups.append(makePileupRead(&(self.plp[0][x]), - * self._alignment_file)) - * return pileups # <<<<<<<<<<<<<< - * - * ######################################################## + /* "pysam/libcalignedsegment.pyx":2705 + * return self.query_alignment_length + * def __set__(self, v): + * self.query_alignment_length = v # <<<<<<<<<<<<<< + * property mrnm: + * """deprecated, use next_reference_id instead""" */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_pileups); - __pyx_r = __pyx_v_pileups; - goto __pyx_L0; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_length, __pyx_v_v) < 0) __PYX_ERR(0, 2705, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2361 - * property pileups: - * '''list of reads (:class:`pysam.PileupRead`) aligned to this column''' - * def __get__(self): # <<<<<<<<<<<<<< - * cdef int x - * pileups = [] + /* "pysam/libcalignedsegment.pyx":2704 + * def __get__(self): + * return self.query_alignment_length + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.query_alignment_length = v + * property mrnm: */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.pileups.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.qlen.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_pileups); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2380 - * ######################################################## - * property pos: +/* "pysam/libcalignedsegment.pyx":2708 + * property mrnm: + * """deprecated, use next_reference_id instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.reference_pos + * return self.next_reference_id * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3pos_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3pos___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3pos___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2380, 0, __PYX_ERR(0, 2380, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2708, 0, __PYX_ERR(0, 2708, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2381 - * property pos: + /* "pysam/libcalignedsegment.pyx":2709 + * """deprecated, use next_reference_id instead""" * def __get__(self): - * return self.reference_pos # <<<<<<<<<<<<<< + * return self.next_reference_id # <<<<<<<<<<<<<< * def __set__(self, v): - * self.reference_pos = v + * self.next_reference_id = v */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2381, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2709, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2380 - * ######################################################## - * property pos: + /* "pysam/libcalignedsegment.pyx":2708 + * property mrnm: + * """deprecated, use next_reference_id instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.reference_pos + * return self.next_reference_id * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mrnm.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -27948,56 +31371,56 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3pos___get_ return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2382 +/* "pysam/libcalignedsegment.pyx":2710 * def __get__(self): - * return self.reference_pos + * return self.next_reference_id * def __set__(self, v): # <<<<<<<<<<<<<< - * self.reference_pos = v - * + * self.next_reference_id = v + * property mpos: */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3pos_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3pos_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2382, 0, __PYX_ERR(0, 2382, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 2710, 0, __PYX_ERR(0, 2710, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2383 - * return self.reference_pos + /* "pysam/libcalignedsegment.pyx":2711 + * return self.next_reference_id * def __set__(self, v): - * self.reference_pos = v # <<<<<<<<<<<<<< - * - * property tid: + * self.next_reference_id = v # <<<<<<<<<<<<<< + * property mpos: + * """deprecated, use next_reference_start instead""" */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos, __pyx_v_v) < 0) __PYX_ERR(0, 2383, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id, __pyx_v_v) < 0) __PYX_ERR(0, 2711, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2382 + /* "pysam/libcalignedsegment.pyx":2710 * def __get__(self): - * return self.reference_pos + * return self.next_reference_id * def __set__(self, v): # <<<<<<<<<<<<<< - * self.reference_pos = v - * + * self.next_reference_id = v + * property mpos: */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.pos.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mrnm.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -28005,61 +31428,61 @@ static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3pos_2__set__(str return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2386 - * - * property tid: +/* "pysam/libcalignedsegment.pyx":2714 + * property mpos: + * """deprecated, use next_reference_start instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.reference_id + * return self.next_reference_start * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3tid_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3tid___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mpos___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3tid___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mpos___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2386, 0, __PYX_ERR(0, 2386, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2714, 0, __PYX_ERR(0, 2714, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2387 - * property tid: + /* "pysam/libcalignedsegment.pyx":2715 + * """deprecated, use next_reference_start instead""" * def __get__(self): - * return self.reference_id # <<<<<<<<<<<<<< + * return self.next_reference_start # <<<<<<<<<<<<<< * def __set__(self, v): - * self.reference_id = v + * self.next_reference_start = v */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2387, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2715, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2386 - * - * property tid: + /* "pysam/libcalignedsegment.pyx":2714 + * property mpos: + * """deprecated, use next_reference_start instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.reference_id + * return self.next_reference_start * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mpos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -28068,56 +31491,56 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3tid___get_ return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2388 +/* "pysam/libcalignedsegment.pyx":2716 * def __get__(self): - * return self.reference_id + * return self.next_reference_start * def __set__(self, v): # <<<<<<<<<<<<<< - * self.reference_id = v - * + * self.next_reference_start = v + * property rname: */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3tid_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3tid_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2388, 0, __PYX_ERR(0, 2388, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 2716, 0, __PYX_ERR(0, 2716, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2389 - * return self.reference_id + /* "pysam/libcalignedsegment.pyx":2717 + * return self.next_reference_start * def __set__(self, v): - * self.reference_id = v # <<<<<<<<<<<<<< - * - * property n: + * self.next_reference_start = v # <<<<<<<<<<<<<< + * property rname: + * """deprecated, use reference_id instead""" */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id, __pyx_v_v) < 0) __PYX_ERR(0, 2389, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start, __pyx_v_v) < 0) __PYX_ERR(0, 2717, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2388 + /* "pysam/libcalignedsegment.pyx":2716 * def __get__(self): - * return self.reference_id + * return self.next_reference_start * def __set__(self, v): # <<<<<<<<<<<<<< - * self.reference_id = v - * + * self.next_reference_start = v + * property rname: */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.tid.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.mpos.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -28125,61 +31548,61 @@ static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3tid_2__set__(str return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2392 - * - * property n: +/* "pysam/libcalignedsegment.pyx":2720 + * property rname: + * """deprecated, use reference_id instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.nsegments + * return self.reference_id * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1n_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1n_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rname_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rname_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_1n___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rname___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_1n___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rname___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2392, 0, __PYX_ERR(0, 2392, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2720, 0, __PYX_ERR(0, 2720, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2393 - * property n: + /* "pysam/libcalignedsegment.pyx":2721 + * """deprecated, use reference_id instead""" * def __get__(self): - * return self.nsegments # <<<<<<<<<<<<<< + * return self.reference_id # <<<<<<<<<<<<<< * def __set__(self, v): - * self.nsegments = v + * self.reference_id = v */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nsegments); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2393, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2721, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2392 - * - * property n: + /* "pysam/libcalignedsegment.pyx":2720 + * property rname: + * """deprecated, use reference_id instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self.nsegments + * return self.reference_id * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.n.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.rname.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -28188,56 +31611,56 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_1n___get__( return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2394 +/* "pysam/libcalignedsegment.pyx":2722 * def __get__(self): - * return self.nsegments + * return self.reference_id * def __set__(self, v): # <<<<<<<<<<<<<< - * self.nsegments = v - * + * self.reference_id = v + * property isize: */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1n_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1n_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_1n_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rname_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_1n_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v) { +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5rname_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2394, 0, __PYX_ERR(0, 2394, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 2722, 0, __PYX_ERR(0, 2722, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2395 - * return self.nsegments + /* "pysam/libcalignedsegment.pyx":2723 + * return self.reference_id * def __set__(self, v): - * self.nsegments = v # <<<<<<<<<<<<<< - * - * + * self.reference_id = v # <<<<<<<<<<<<<< + * property isize: + * """deprecated, use template_length instead""" */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nsegments, __pyx_v_v) < 0) __PYX_ERR(0, 2395, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id, __pyx_v_v) < 0) __PYX_ERR(0, 2723, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2394 + /* "pysam/libcalignedsegment.pyx":2722 * def __get__(self): - * return self.nsegments + * return self.reference_id * def __set__(self, v): # <<<<<<<<<<<<<< - * self.nsegments = v - * + * self.reference_id = v + * property isize: */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.n.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.rname.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -28245,351 +31668,195 @@ static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_1n_2__set__(struc return __pyx_r; } -/* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.plp cannot be converted to a Python object for pickling") - * def __setstate_cython__(self, __pyx_state): +/* "pysam/libcalignedsegment.pyx":2726 + * property isize: + * """deprecated, use template_length instead""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.template_length + * def __set__(self, v): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_4__reduce_cython__[] = "PileupColumn.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5isize_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5isize_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_4__reduce_cython__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5isize___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5isize___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2726, 0, __PYX_ERR(0, 2726, __pyx_L1_error)); - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("self.plp cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.plp cannot be converted to a Python object for pickling") + /* "pysam/libcalignedsegment.pyx":2727 + * """deprecated, use template_length instead""" + * def __get__(self): + * return self.template_length # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.template_length = v */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2727, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.plp cannot be converted to a Python object for pickling") - * def __setstate_cython__(self, __pyx_state): + /* "pysam/libcalignedsegment.pyx":2726 + * property isize: + * """deprecated, use template_length instead""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.template_length + * def __set__(self, v): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.isize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; + __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("self.plp cannot be converted to a Python object for pickling") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.plp cannot be converted to a Python object for pickling") +/* "pysam/libcalignedsegment.pyx":2728 + * def __get__(self): + * return self.template_length + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.template_length = v + * property blocks: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_6__setstate_cython__[] = "PileupColumn.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5isize_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5isize_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_6__setstate_cython__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5isize_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_5isize_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2728, 0, __PYX_ERR(0, 2728, __pyx_L1_error)); - /* "(tree fragment)":4 - * raise TypeError("self.plp cannot be converted to a Python object for pickling") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.plp cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2729 + * return self.template_length + * def __set__(self, v): + * self.template_length = v # <<<<<<<<<<<<<< + * property blocks: + * """deprecated, use get_blocks() instead""" */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length, __pyx_v_v) < 0) __PYX_ERR(0, 2729, __pyx_L1_error) - /* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("self.plp cannot be converted to a Python object for pickling") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.plp cannot be converted to a Python object for pickling") + /* "pysam/libcalignedsegment.pyx":2728 + * def __get__(self): + * return self.template_length + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.template_length = v + * property blocks: */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.isize.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2404 - * ''' - * - * def __init__(self): # <<<<<<<<<<<<<< - * raise TypeError( - * "this class cannot be instantiated from Python") +/* "pysam/libcalignedsegment.pyx":2732 + * property blocks: + * """deprecated, use get_blocks() instead""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.get_blocks() + * property aligned_pairs: */ /* Python wrapper */ -static int __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { - __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} - if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead___init__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_18libcalignedsegment_10PileupRead___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 2404, 0, __PYX_ERR(0, 2404, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2405 - * - * def __init__(self): - * raise TypeError( # <<<<<<<<<<<<<< - * "this class cannot be instantiated from Python") - * - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 2405, __pyx_L1_error) - - /* "pysam/libcalignedsegment.pyx":2404 - * ''' - * - * def __init__(self): # <<<<<<<<<<<<<< - * raise TypeError( - * "this class cannot be instantiated from Python") - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignedsegment.pyx":2408 - * "this class cannot be instantiated from Python") - * - * def __str__(self): # <<<<<<<<<<<<<< - * return "\t".join( - * map(str, - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_3__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_3__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6blocks_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6blocks_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_2__str__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6blocks___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_2__str__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6blocks___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - __Pyx_RefNannySetupContext("__str__", 0); - __Pyx_TraceCall("__str__", __pyx_f[0], 2408, 0, __PYX_ERR(0, 2408, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2732, 0, __PYX_ERR(0, 2732, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2409 - * - * def __str__(self): - * return "\t".join( # <<<<<<<<<<<<<< - * map(str, - * (self.alignment, self.query_position, + /* "pysam/libcalignedsegment.pyx":2733 + * """deprecated, use get_blocks() instead""" + * def __get__(self): + * return self.get_blocks() # <<<<<<<<<<<<<< + * property aligned_pairs: + * """deprecated, use get_aligned_pairs() instead""" */ __Pyx_XDECREF(__pyx_r); - - /* "pysam/libcalignedsegment.pyx":2411 - * return "\t".join( - * map(str, - * (self.alignment, self.query_position, # <<<<<<<<<<<<<< - * self.indel, self.level, - * self.is_del, self.is_head, - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_alignment); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2411, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_position); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2411, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_blocks); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2733, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - - /* "pysam/libcalignedsegment.pyx":2412 - * map(str, - * (self.alignment, self.query_position, - * self.indel, self.level, # <<<<<<<<<<<<<< - * self.is_del, self.is_head, - * self.is_tail, self.is_refskip))) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_indel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2412, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_level); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2412, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pysam/libcalignedsegment.pyx":2413 - * (self.alignment, self.query_position, - * self.indel, self.level, - * self.is_del, self.is_head, # <<<<<<<<<<<<<< - * self.is_tail, self.is_refskip))) - * - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_del); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2413, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_head); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2413, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - - /* "pysam/libcalignedsegment.pyx":2414 - * self.indel, self.level, - * self.is_del, self.is_head, - * self.is_tail, self.is_refskip))) # <<<<<<<<<<<<<< - * - * property alignment: - */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_tail); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_refskip); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - - /* "pysam/libcalignedsegment.pyx":2411 - * return "\t".join( - * map(str, - * (self.alignment, self.query_position, # <<<<<<<<<<<<<< - * self.indel, self.level, - * self.is_del, self.is_head, - */ - __pyx_t_9 = PyTuple_New(8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2411, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_9, 7, __pyx_t_8); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2733, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2733, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_t_5 = 0; - __pyx_t_6 = 0; - __pyx_t_7 = 0; - __pyx_t_8 = 0; - - /* "pysam/libcalignedsegment.pyx":2410 - * def __str__(self): - * return "\t".join( - * map(str, # <<<<<<<<<<<<<< - * (self.alignment, self.query_position, - * self.indel, self.level, - */ - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2410, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(((PyObject *)(&PyString_Type))); - __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)(&PyString_Type))); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2410, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "pysam/libcalignedsegment.pyx":2409 - * - * def __str__(self): - * return "\t".join( # <<<<<<<<<<<<<< - * map(str, - * (self.alignment, self.query_position, - */ - __pyx_t_8 = __Pyx_PyString_Join(__pyx_kp_s__19, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2409, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2408 - * "this class cannot be instantiated from Python") - * - * def __str__(self): # <<<<<<<<<<<<<< - * return "\t".join( - * map(str, + /* "pysam/libcalignedsegment.pyx":2732 + * property blocks: + * """deprecated, use get_blocks() instead""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.get_blocks() + * property aligned_pairs: */ /* function exit code */ @@ -28597,13 +31864,7 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_2__str__(stru __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.blocks.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -28612,57 +31873,83 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_2__str__(stru return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2418 - * property alignment: - * """a :class:`pysam.AlignedSegment` object of the aligned read""" +/* "pysam/libcalignedsegment.pyx":2736 + * property aligned_pairs: + * """deprecated, use get_aligned_pairs() instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self._alignment - * + * return self.get_aligned_pairs() + * property inferred_length: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_9alignment_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_9alignment_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13aligned_pairs_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13aligned_pairs_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_9alignment___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_13aligned_pairs___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_9alignment___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_13aligned_pairs___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2418, 0, __PYX_ERR(0, 2418, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2736, 0, __PYX_ERR(0, 2736, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2419 - * """a :class:`pysam.AlignedSegment` object of the aligned read""" + /* "pysam/libcalignedsegment.pyx":2737 + * """deprecated, use get_aligned_pairs() instead""" * def __get__(self): - * return self._alignment # <<<<<<<<<<<<<< - * - * property query_position: + * return self.get_aligned_pairs() # <<<<<<<<<<<<<< + * property inferred_length: + * """deprecated, use infer_query_length() instead""" */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->_alignment)); - __pyx_r = ((PyObject *)__pyx_v_self->_alignment); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2737, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2737, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2737, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2418 - * property alignment: - * """a :class:`pysam.AlignedSegment` object of the aligned read""" + /* "pysam/libcalignedsegment.pyx":2736 + * property aligned_pairs: + * """deprecated, use get_aligned_pairs() instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self._alignment - * + * return self.get_aligned_pairs() + * property inferred_length: */ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.alignment.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.aligned_pairs.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -28671,109 +31958,83 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_9alignment___ return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2426 - * - * """ +/* "pysam/libcalignedsegment.pyx":2740 + * property inferred_length: + * """deprecated, use infer_query_length() instead""" * def __get__(self): # <<<<<<<<<<<<<< - * if self.is_del or self.is_refskip: - * return None + * return self.infer_query_length() + * property positions: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_14query_position_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_14query_position_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15inferred_length_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15inferred_length_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_14query_position___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15inferred_length___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_14query_position___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_15inferred_length___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; + PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; + PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2426, 0, __PYX_ERR(0, 2426, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2740, 0, __PYX_ERR(0, 2740, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2427 - * """ + /* "pysam/libcalignedsegment.pyx":2741 + * """deprecated, use infer_query_length() instead""" * def __get__(self): - * if self.is_del or self.is_refskip: # <<<<<<<<<<<<<< - * return None - * else: + * return self.infer_query_length() # <<<<<<<<<<<<<< + * property positions: + * """deprecated, use get_reference_positions() instead""" */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_del); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2427, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_infer_query_length); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2741, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2427, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (!__pyx_t_3) { + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2741, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __pyx_t_3; - goto __pyx_L4_bool_binop_done; + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2741, __pyx_L1_error) } - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_refskip); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_1 = __pyx_t_3; - __pyx_L4_bool_binop_done:; - if (__pyx_t_1) { - - /* "pysam/libcalignedsegment.pyx":2428 - * def __get__(self): - * if self.is_del or self.is_refskip: - * return None # <<<<<<<<<<<<<< - * else: - * return self._qpos - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "pysam/libcalignedsegment.pyx":2427 - * """ - * def __get__(self): - * if self.is_del or self.is_refskip: # <<<<<<<<<<<<<< - * return None - * else: - */ - } - - /* "pysam/libcalignedsegment.pyx":2430 - * return None - * else: - * return self._qpos # <<<<<<<<<<<<<< - * - * property query_position_or_next: - */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_qpos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2430, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2426 - * - * """ + /* "pysam/libcalignedsegment.pyx":2740 + * property inferred_length: + * """deprecated, use infer_query_length() instead""" * def __get__(self): # <<<<<<<<<<<<<< - * if self.is_del or self.is_refskip: - * return None + * return self.infer_query_length() + * property positions: */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.query_position.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.inferred_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -28782,61 +32043,83 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_14query_posit return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2439 - * - * """ +/* "pysam/libcalignedsegment.pyx":2744 + * property positions: + * """deprecated, use get_reference_positions() instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self._qpos - * + * return self.get_reference_positions() + * property tags: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_22query_position_or_next_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_22query_position_or_next_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9positions_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9positions_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_22query_position_or_next___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9positions___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_22query_position_or_next___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_9positions___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2439, 0, __PYX_ERR(0, 2439, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2744, 0, __PYX_ERR(0, 2744, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2440 - * """ + /* "pysam/libcalignedsegment.pyx":2745 + * """deprecated, use get_reference_positions() instead""" * def __get__(self): - * return self._qpos # <<<<<<<<<<<<<< - * - * property indel: + * return self.get_reference_positions() # <<<<<<<<<<<<<< + * property tags: + * """deprecated, use get_tags() instead""" */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_qpos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2440, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_positions); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2745, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2745, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2745, __pyx_L1_error) + } __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2439 - * - * """ + /* "pysam/libcalignedsegment.pyx":2744 + * property positions: + * """deprecated, use get_reference_positions() instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self._qpos - * + * return self.get_reference_positions() + * property tags: */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.query_position_or_next.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.positions.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -28845,61 +32128,83 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_22query_posit return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2451 - * - * """ +/* "pysam/libcalignedsegment.pyx":2748 + * property tags: + * """deprecated, use get_tags() instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self._indel - * + * return self.get_tags() + * def __set__(self, tags): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5indel_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5indel_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tags_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tags_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_5indel___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tags___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_5indel___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tags___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2451, 0, __PYX_ERR(0, 2451, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2748, 0, __PYX_ERR(0, 2748, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2452 - * """ + /* "pysam/libcalignedsegment.pyx":2749 + * """deprecated, use get_tags() instead""" * def __get__(self): - * return self._indel # <<<<<<<<<<<<<< - * - * property level: + * return self.get_tags() # <<<<<<<<<<<<<< + * def __set__(self, tags): + * self.set_tags(tags) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_indel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2452, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tags); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2749, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2749, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2749, __pyx_L1_error) + } __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2451 - * - * """ + /* "pysam/libcalignedsegment.pyx":2748 + * property tags: + * """deprecated, use get_tags() instead""" * def __get__(self): # <<<<<<<<<<<<<< - * return self._indel - * + * return self.get_tags() + * def __set__(self, tags): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.indel.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tags.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -28908,124 +32213,194 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_5indel___get_ return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2457 - * """the level of the read in the "viewer" mode. Note that this value - * is currently not computed.""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self._level - * +/* "pysam/libcalignedsegment.pyx":2750 + * def __get__(self): + * return self.get_tags() + * def __set__(self, tags): # <<<<<<<<<<<<<< + * self.set_tags(tags) + * def overlap(self): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5level_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5level_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tags_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tags_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_5level___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tags_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tags)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_5level___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_4tags_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2457, 0, __PYX_ERR(0, 2457, __pyx_L1_error)); + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2750, 0, __PYX_ERR(0, 2750, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2458 - * is currently not computed.""" - * def __get__(self): - * return self._level # <<<<<<<<<<<<<< - * - * property is_del: + /* "pysam/libcalignedsegment.pyx":2751 + * return self.get_tags() + * def __set__(self, tags): + * self.set_tags(tags) # <<<<<<<<<<<<<< + * def overlap(self): + * """deprecated, use get_overlap() instead""" */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_level); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2458, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_tags); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2751, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_tags); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2751, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_tags}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2751, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_tags}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2751, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2751, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_tags); + __Pyx_GIVEREF(__pyx_v_tags); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_tags); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2751, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":2457 - * """the level of the read in the "viewer" mode. Note that this value - * is currently not computed.""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self._level - * + /* "pysam/libcalignedsegment.pyx":2750 + * def __get__(self): + * return self.get_tags() + * def __set__(self, tags): # <<<<<<<<<<<<<< + * self.set_tags(tags) + * def overlap(self): */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.level.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.tags.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2462 - * property is_del: - * """1 iff the base on the padded read is a deletion""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self._is_del - * +/* "pysam/libcalignedsegment.pyx":2752 + * def __set__(self, tags): + * self.set_tags(tags) + * def overlap(self): # <<<<<<<<<<<<<< + * """deprecated, use get_overlap() instead""" + * return self.get_overlap() */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_6is_del_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_6is_del_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_57overlap(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_56overlap[] = "AlignedSegment.overlap(self)\ndeprecated, use get_overlap() instead"; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_57overlap(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_6is_del___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + __Pyx_RefNannySetupContext("overlap (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_56overlap(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_6is_del___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_56overlap(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2462, 0, __PYX_ERR(0, 2462, __pyx_L1_error)); + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("overlap", 0); + __Pyx_TraceCall("overlap", __pyx_f[0], 2752, 0, __PYX_ERR(0, 2752, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2463 - * """1 iff the base on the padded read is a deletion""" - * def __get__(self): - * return self._is_del # <<<<<<<<<<<<<< - * - * property is_head: + /* "pysam/libcalignedsegment.pyx":2754 + * def overlap(self): + * """deprecated, use get_overlap() instead""" + * return self.get_overlap() # <<<<<<<<<<<<<< + * def opt(self, tag): + * """deprecated, use get_tag() instead""" */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_del); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2463, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_overlap); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2754, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2754, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2754, __pyx_L1_error) + } __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2462 - * property is_del: - * """1 iff the base on the padded read is a deletion""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self._is_del - * + /* "pysam/libcalignedsegment.pyx":2752 + * def __set__(self, tags): + * self.set_tags(tags) + * def overlap(self): # <<<<<<<<<<<<<< + * """deprecated, use get_overlap() instead""" + * return self.get_overlap() */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.is_del.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.overlap", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -29034,61 +32409,62 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_6is_del___get return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2467 - * property is_head: - * """1 iff the base on the padded read is the left-most base.""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self._is_head - * +/* "pysam/libcalignedsegment.pyx":2755 + * """deprecated, use get_overlap() instead""" + * return self.get_overlap() + * def opt(self, tag): # <<<<<<<<<<<<<< + * """deprecated, use get_tag() instead""" + * return self.get_tag(tag) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7is_head_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7is_head_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_59opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_58opt[] = "AlignedSegment.opt(self, tag)\ndeprecated, use get_tag() instead"; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_59opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_7is_head___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + __Pyx_RefNannySetupContext("opt (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_58opt(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tag)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_7is_head___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_58opt(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2467, 0, __PYX_ERR(0, 2467, __pyx_L1_error)); + __Pyx_RefNannySetupContext("opt", 0); + __Pyx_TraceCall("opt", __pyx_f[0], 2755, 0, __PYX_ERR(0, 2755, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2468 - * """1 iff the base on the padded read is the left-most base.""" - * def __get__(self): - * return self._is_head # <<<<<<<<<<<<<< - * - * property is_tail: + /* "pysam/libcalignedsegment.pyx":2757 + * def opt(self, tag): + * """deprecated, use get_tag() instead""" + * return self.get_tag(tag) # <<<<<<<<<<<<<< + * def setTag(self, tag, value, value_type=None, replace=True): + * """deprecated, use set_tag() instead""" */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_head); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2468, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self->__pyx_vtab)->get_tag(__pyx_v_self, __pyx_v_tag, 0, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2757, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2467 - * property is_head: - * """1 iff the base on the padded read is the left-most base.""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self._is_head - * + /* "pysam/libcalignedsegment.pyx":2755 + * """deprecated, use get_overlap() instead""" + * return self.get_overlap() + * def opt(self, tag): # <<<<<<<<<<<<<< + * """deprecated, use get_tag() instead""" + * return self.get_tag(tag) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.is_head.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.opt", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -29097,61 +32473,142 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_7is_head___ge return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2472 - * property is_tail: - * """1 iff the base on the padded read is the right-most base.""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self._is_tail - * +/* "pysam/libcalignedsegment.pyx":2758 + * """deprecated, use get_tag() instead""" + * return self.get_tag(tag) + * def setTag(self, tag, value, value_type=None, replace=True): # <<<<<<<<<<<<<< + * """deprecated, use set_tag() instead""" + * return self.set_tag(tag, value, value_type, replace) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7is_tail_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7is_tail_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_61setTag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_60setTag[] = "AlignedSegment.setTag(self, tag, value, value_type=None, replace=True)\ndeprecated, use set_tag() instead"; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_61setTag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_tag = 0; + PyObject *__pyx_v_value = 0; + PyObject *__pyx_v_value_type = 0; + PyObject *__pyx_v_replace = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_7is_tail___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + __Pyx_RefNannySetupContext("setTag (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tag,&__pyx_n_s_value,&__pyx_n_s_value_type,&__pyx_n_s_replace,0}; + PyObject* values[4] = {0,0,0,0}; + values[2] = ((PyObject *)Py_None); + values[3] = ((PyObject *)Py_True); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tag)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("setTag", 0, 2, 4, 1); __PYX_ERR(0, 2758, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value_type); + if (value) { values[2] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_replace); + if (value) { values[3] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setTag") < 0)) __PYX_ERR(0, 2758, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_tag = values[0]; + __pyx_v_value = values[1]; + __pyx_v_value_type = values[2]; + __pyx_v_replace = values[3]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("setTag", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2758, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.setTag", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_60setTag(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_7is_tail___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_60setTag(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2472, 0, __PYX_ERR(0, 2472, __pyx_L1_error)); + struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag __pyx_t_2; + __Pyx_RefNannySetupContext("setTag", 0); + __Pyx_TraceCall("setTag", __pyx_f[0], 2758, 0, __PYX_ERR(0, 2758, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":2473 - * """1 iff the base on the padded read is the right-most base.""" - * def __get__(self): - * return self._is_tail # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2760 + * def setTag(self, tag, value, value_type=None, replace=True): + * """deprecated, use set_tag() instead""" + * return self.set_tag(tag, value, value_type, replace) # <<<<<<<<<<<<<< + * * - * property is_refskip: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_tail); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2473, __pyx_L1_error) + __pyx_t_2.__pyx_n = 2; + __pyx_t_2.value_type = __pyx_v_value_type; + __pyx_t_2.replace = __pyx_v_replace; + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self->__pyx_vtab)->set_tag(__pyx_v_self, __pyx_v_tag, __pyx_v_value, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2760, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2472 - * property is_tail: - * """1 iff the base on the padded read is the right-most base.""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self._is_tail - * + /* "pysam/libcalignedsegment.pyx":2758 + * """deprecated, use get_tag() instead""" + * return self.get_tag(tag) + * def setTag(self, tag, value, value_type=None, replace=True): # <<<<<<<<<<<<<< + * """deprecated, use set_tag() instead""" + * return self.set_tag(tag, value, value_type, replace) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.is_tail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.setTag", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -29160,61 +32617,41 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_7is_tail___ge return __pyx_r; } -/* "pysam/libcalignedsegment.pyx":2477 - * property is_refskip: - * """1 iff the base on the padded read is part of CIGAR N op.""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self._is_refskip +/* "pysam/libcalignedsegment.pxd":40 * + * # the header that a read is associated with + * cdef readonly AlignmentHeader header # <<<<<<<<<<<<<< + * + * # caching of array properties for quick access */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_10is_refskip_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_10is_refskip_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6header_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_10is_refskip___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6header___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_10is_refskip___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_6header___get__(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2477, 0, __PYX_ERR(0, 2477, __pyx_L1_error)); - - /* "pysam/libcalignedsegment.pyx":2478 - * """1 iff the base on the padded read is part of CIGAR N op.""" - * def __get__(self): - * return self._is_refskip # <<<<<<<<<<<<<< - * - * __all__ = [ - */ + __Pyx_TraceCall("__get__", __pyx_f[2], 40, 0, __PYX_ERR(2, 40, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_refskip); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2478, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); + __pyx_r = ((PyObject *)__pyx_v_self->header); goto __pyx_L0; - /* "pysam/libcalignedsegment.pyx":2477 - * property is_refskip: - * """1 iff the base on the padded read is part of CIGAR N op.""" - * def __get__(self): # <<<<<<<<<<<<<< - * return self._is_refskip - * - */ - /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.is_refskip.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -29225,1443 +32662,918 @@ static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_10is_refskip_ /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * cdef bint use_setstate - * state = (self._alignment, self._indel, self._is_del, self._is_head, self._is_refskip, self._is_tail, self._level, self._qpos) + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_10PileupRead_4__reduce_cython__[] = "PileupRead.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_63__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_62__reduce_cython__[] = "AlignedSegment.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_63__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_4__reduce_cython__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_62__reduce_cython__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_4__reduce_cython__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { - int __pyx_v_use_setstate; - PyObject *__pyx_v_state = NULL; - PyObject *__pyx_v__dict = NULL; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_62__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; - int __pyx_t_10; __Pyx_RefNannySetupContext("__reduce_cython__", 0); __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); - /* "(tree fragment)":3 + /* "(tree fragment)":2 * def __reduce_cython__(self): - * cdef bint use_setstate - * state = (self._alignment, self._indel, self._is_del, self._is_head, self._is_refskip, self._is_tail, self._level, self._qpos) # <<<<<<<<<<<<<< - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_indel); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_del); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_head); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_refskip); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_tail); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->_level); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_qpos); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyTuple_New(8); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(((PyObject *)__pyx_v_self->_alignment)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->_alignment)); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_v_self->_alignment)); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_8, 6, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_8, 7, __pyx_t_7); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_t_5 = 0; - __pyx_t_6 = 0; - __pyx_t_7 = 0; - __pyx_v_state = ((PyObject*)__pyx_t_8); - __pyx_t_8 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 2, __pyx_L1_error) - /* "(tree fragment)":4 - * cdef bint use_setstate - * state = (self._alignment, self._indel, self._is_del, self._is_head, self._is_refskip, self._is_tail, self._level, self._qpos) - * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< - * if _dict is not None: - * state += (_dict,) + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): */ - __pyx_t_8 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_v__dict = __pyx_t_8; - __pyx_t_8 = 0; - /* "(tree fragment)":5 - * state = (self._alignment, self._indel, self._is_del, self._is_head, self._is_refskip, self._is_tail, self._level, self._qpos) - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: # <<<<<<<<<<<<<< - * state += (_dict,) - * use_setstate = True - */ - __pyx_t_9 = (__pyx_v__dict != Py_None); - __pyx_t_10 = (__pyx_t_9 != 0); - if (__pyx_t_10) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "(tree fragment)":6 - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: - * state += (_dict,) # <<<<<<<<<<<<<< - * use_setstate = True - * else: +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") */ - __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_v__dict); - __Pyx_GIVEREF(__pyx_v__dict); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v__dict); - __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_7)); - __pyx_t_7 = 0; - /* "(tree fragment)":7 - * if _dict is not None: - * state += (_dict,) - * use_setstate = True # <<<<<<<<<<<<<< - * else: - * use_setstate = self._alignment is not None - */ - __pyx_v_use_setstate = 1; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_65__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_64__setstate_cython__[] = "AlignedSegment.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_65__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_64__setstate_cython__(((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); - /* "(tree fragment)":5 - * state = (self._alignment, self._indel, self._is_del, self._is_head, self._is_refskip, self._is_tail, self._level, self._qpos) - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: # <<<<<<<<<<<<<< - * state += (_dict,) - * use_setstate = True - */ - goto __pyx_L3; - } + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "(tree fragment)":9 - * use_setstate = True - * else: - * use_setstate = self._alignment is not None # <<<<<<<<<<<<<< - * if use_setstate: - * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, None), state - */ - /*else*/ { - __pyx_t_10 = (((PyObject *)__pyx_v_self->_alignment) != Py_None); - __pyx_v_use_setstate = __pyx_t_10; - } - __pyx_L3:; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_14AlignedSegment_64__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); - /* "(tree fragment)":10 - * else: - * use_setstate = self._alignment is not None - * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, None), state - * else: + /* "(tree fragment)":4 + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_10 = (__pyx_v_use_setstate != 0); - if (__pyx_t_10) { + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) - /* "(tree fragment)":11 - * use_setstate = self._alignment is not None - * if use_setstate: - * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, None), state # <<<<<<<<<<<<<< - * else: - * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, state) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_PileupRead); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_INCREF(__pyx_int_196873109); - __Pyx_GIVEREF(__pyx_int_196873109); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_196873109); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_8, 2, Py_None); - __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_8); - __Pyx_INCREF(__pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_v_state); - __pyx_t_7 = 0; - __pyx_t_8 = 0; - __pyx_r = __pyx_t_6; - __pyx_t_6 = 0; - goto __pyx_L0; - - /* "(tree fragment)":10 - * else: - * use_setstate = self._alignment is not None - * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, None), state - * else: - */ - } - - /* "(tree fragment)":13 - * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, None), state - * else: - * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, state) # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_PileupRead__set_state(self, __pyx_state) - */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_PileupRead); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_INCREF(__pyx_int_196873109); - __Pyx_GIVEREF(__pyx_int_196873109); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_196873109); - __Pyx_INCREF(__pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_state); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8); - __pyx_t_6 = 0; - __pyx_t_8 = 0; - __pyx_r = __pyx_t_7; - __pyx_t_7 = 0; - goto __pyx_L0; - } - - /* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * cdef bint use_setstate - * state = (self._alignment, self._indel, self._is_del, self._is_head, self._is_refskip, self._is_tail, self._level, self._qpos) + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.AlignedSegment.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_state); - __Pyx_XDECREF(__pyx_v__dict); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":14 - * else: - * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, state) - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_PileupRead__set_state(self, __pyx_state) +/* "pysam/libcalignedsegment.pyx":2772 + * of this column will change. + * ''' + * def __init__(self): # <<<<<<<<<<<<<< + * raise TypeError("this class cannot be instantiated from Python") + * */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_10PileupRead_6__setstate_cython__[] = "PileupRead.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_6__setstate_cython__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn___init__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_6__setstate_cython__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__init__", 0); + __Pyx_TraceCall("__init__", __pyx_f[0], 2772, 0, __PYX_ERR(0, 2772, __pyx_L1_error)); - /* "(tree fragment)":15 - * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, state) - * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_PileupRead__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2773 + * ''' + * def __init__(self): + * raise TypeError("this class cannot be instantiated from Python") # <<<<<<<<<<<<<< + * + * def __str__(self): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment___pyx_unpickle_PileupRead__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2773, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2773, __pyx_L1_error) - /* "(tree fragment)":14 - * else: - * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, state) - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_PileupRead__set_state(self, __pyx_state) + /* "pysam/libcalignedsegment.pyx":2772 + * of this column will change. + * ''' + * def __init__(self): # <<<<<<<<<<<<<< + * raise TypeError("this class cannot be instantiated from Python") + * */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":1 - * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< - * if __pyx_checksum != 0xbbc0b95: - * from pickle import PickleError as __pyx_PickleError +/* "pysam/libcalignedsegment.pyx":2775 + * raise TypeError("this class cannot be instantiated from Python") + * + * def __str__(self): # <<<<<<<<<<<<<< + * return "\t".join(map(str, + * (self.reference_id, */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_7__pyx_unpickle_PileupRead(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_18libcalignedsegment_6__pyx_unpickle_PileupRead[] = "__pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state)"; -static PyMethodDef __pyx_mdef_5pysam_18libcalignedsegment_7__pyx_unpickle_PileupRead = {"__pyx_unpickle_PileupRead", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_7__pyx_unpickle_PileupRead, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_6__pyx_unpickle_PileupRead}; -static PyObject *__pyx_pw_5pysam_18libcalignedsegment_7__pyx_unpickle_PileupRead(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v___pyx_type = 0; - long __pyx_v___pyx_checksum; - PyObject *__pyx_v___pyx_state = 0; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__pyx_unpickle_PileupRead (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PileupRead", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PileupRead", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_PileupRead") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - } - __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) - __pyx_v___pyx_state = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PileupRead", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignedsegment.__pyx_unpickle_PileupRead", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_6__pyx_unpickle_PileupRead(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_2__str__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_18libcalignedsegment_6__pyx_unpickle_PileupRead(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_v___pyx_PickleError = NULL; - PyObject *__pyx_v___pyx_result = NULL; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_2__str__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; + PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__38) - __Pyx_RefNannySetupContext("__pyx_unpickle_PileupRead", 0); - __Pyx_TraceCall("__pyx_unpickle_PileupRead", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__str__", 0); + __Pyx_TraceCall("__str__", __pyx_f[0], 2775, 0, __PYX_ERR(0, 2775, __pyx_L1_error)); - /* "(tree fragment)":2 - * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): - * if __pyx_checksum != 0xbbc0b95: # <<<<<<<<<<<<<< - * from pickle import PickleError as __pyx_PickleError - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) + /* "pysam/libcalignedsegment.pyx":2776 + * + * def __str__(self): + * return "\t".join(map(str, # <<<<<<<<<<<<<< + * (self.reference_id, + * self.reference_pos, */ - __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xbbc0b95) != 0); - if (__pyx_t_1) { + __Pyx_XDECREF(__pyx_r); - /* "(tree fragment)":3 - * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): - * if __pyx_checksum != 0xbbc0b95: - * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) - * __pyx_result = PileupRead.__new__(__pyx_type) + /* "pysam/libcalignedsegment.pyx":2777 + * def __str__(self): + * return "\t".join(map(str, + * (self.reference_id, # <<<<<<<<<<<<<< + * self.reference_pos, + * self.nsegments))) +\ */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_PickleError); - __Pyx_GIVEREF(__pyx_n_s_PickleError); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_2); - __pyx_v___pyx_PickleError = __pyx_t_2; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2777, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); - /* "(tree fragment)":4 - * if __pyx_checksum != 0xbbc0b95: - * from pickle import PickleError as __pyx_PickleError - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) # <<<<<<<<<<<<<< - * __pyx_result = PileupRead.__new__(__pyx_type) - * if __pyx_state is not None: + /* "pysam/libcalignedsegment.pyx":2778 + * return "\t".join(map(str, + * (self.reference_id, + * self.reference_pos, # <<<<<<<<<<<<<< + * self.nsegments))) +\ + * "\n" +\ */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xbb, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_INCREF(__pyx_v___pyx_PickleError); - __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2778, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); - /* "(tree fragment)":2 - * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): - * if __pyx_checksum != 0xbbc0b95: # <<<<<<<<<<<<<< - * from pickle import PickleError as __pyx_PickleError - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) + /* "pysam/libcalignedsegment.pyx":2779 + * (self.reference_id, + * self.reference_pos, + * self.nsegments))) +\ # <<<<<<<<<<<<<< + * "\n" +\ + * "\n".join(map(str, self.pileups)) */ - } + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nsegments); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2779, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); - /* "(tree fragment)":5 - * from pickle import PickleError as __pyx_PickleError - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) - * __pyx_result = PileupRead.__new__(__pyx_type) # <<<<<<<<<<<<<< - * if __pyx_state is not None: - * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) + /* "pysam/libcalignedsegment.pyx":2777 + * def __str__(self): + * return "\t".join(map(str, + * (self.reference_id, # <<<<<<<<<<<<<< + * self.reference_pos, + * self.nsegments))) +\ */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_18libcalignedsegment_PileupRead), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; - __Pyx_INCREF(__pyx_v___pyx_type); - __Pyx_GIVEREF(__pyx_v___pyx_type); - PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2777, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); + __pyx_t_1 = 0; + __pyx_t_2 = 0; __pyx_t_3 = 0; - /* "(tree fragment)":6 - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) - * __pyx_result = PileupRead.__new__(__pyx_type) - * if __pyx_state is not None: # <<<<<<<<<<<<<< - * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) - * return __pyx_result + /* "pysam/libcalignedsegment.pyx":2776 + * + * def __str__(self): + * return "\t".join(map(str, # <<<<<<<<<<<<<< + * (self.reference_id, + * self.reference_pos, */ - __pyx_t_1 = (__pyx_v___pyx_state != Py_None); - __pyx_t_7 = (__pyx_t_1 != 0); - if (__pyx_t_7) { + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2776, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2776, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__16, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2776, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "(tree fragment)":7 - * __pyx_result = PileupRead.__new__(__pyx_type) - * if __pyx_state is not None: - * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< - * return __pyx_result - * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): + /* "pysam/libcalignedsegment.pyx":2779 + * (self.reference_id, + * self.reference_pos, + * self.nsegments))) +\ # <<<<<<<<<<<<<< + * "\n" +\ + * "\n".join(map(str, self.pileups)) */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment___pyx_unpickle_PileupRead__set_state(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_kp_s__42); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2779, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "(tree fragment)":6 - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) - * __pyx_result = PileupRead.__new__(__pyx_type) - * if __pyx_state is not None: # <<<<<<<<<<<<<< - * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) - * return __pyx_result + /* "pysam/libcalignedsegment.pyx":2781 + * self.nsegments))) +\ + * "\n" +\ + * "\n".join(map(str, self.pileups)) # <<<<<<<<<<<<<< + * + * def __dealloc__(self): */ - } + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_pileups); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2781, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2781, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2781, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__42, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2781, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "(tree fragment)":8 - * if __pyx_state is not None: - * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) - * return __pyx_result # <<<<<<<<<<<<<< - * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): - * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] + /* "pysam/libcalignedsegment.pyx":2780 + * self.reference_pos, + * self.nsegments))) +\ + * "\n" +\ # <<<<<<<<<<<<<< + * "\n".join(map(str, self.pileups)) + * */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v___pyx_result); - __pyx_r = __pyx_v___pyx_result; + __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; goto __pyx_L0; - /* "(tree fragment)":1 - * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< - * if __pyx_checksum != 0xbbc0b95: - * from pickle import PickleError as __pyx_PickleError + /* "pysam/libcalignedsegment.pyx":2775 + * raise TypeError("this class cannot be instantiated from Python") + * + * def __str__(self): # <<<<<<<<<<<<<< + * return "\t".join(map(str, + * (self.reference_id, */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libcalignedsegment.__pyx_unpickle_PileupRead", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v___pyx_PickleError); - __Pyx_XDECREF(__pyx_v___pyx_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":9 - * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) - * return __pyx_result - * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< - * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] - * if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'): +/* "pysam/libcalignedsegment.pyx":2783 + * "\n".join(map(str, self.pileups)) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * if self.buf is not NULL: + * free(self.buf) */ -static PyObject *__pyx_f_5pysam_18libcalignedsegment___pyx_unpickle_PileupRead__set_state(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations +/* Python wrapper */ +static void __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_5__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_5__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - uint32_t __pyx_t_3; - int32_t __pyx_t_4; - int __pyx_t_5; - Py_ssize_t __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - __Pyx_RefNannySetupContext("__pyx_unpickle_PileupRead__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_PileupRead__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_4__dealloc__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); - /* "(tree fragment)":10 - * return __pyx_result - * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): - * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] # <<<<<<<<<<<<<< - * if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'): - * __pyx_result.__dict__.update(__pyx_state[8]) - */ - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v___pyx_result->_alignment); - __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->_alignment)); - __pyx_v___pyx_result->_alignment = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_1); - __pyx_t_1 = 0; - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v___pyx_result->_indel = __pyx_t_2; - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_3 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v___pyx_result->_is_del = __pyx_t_3; - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_3 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v___pyx_result->_is_head = __pyx_t_3; - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_3 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v___pyx_result->_is_refskip = __pyx_t_3; - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_3 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v___pyx_result->_is_tail = __pyx_t_3; - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 6, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v___pyx_result->_level = __pyx_t_2; - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 7, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_4 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v___pyx_result->_qpos = __pyx_t_4; + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} - /* "(tree fragment)":11 - * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): - * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] - * if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< - * __pyx_result.__dict__.update(__pyx_state[8]) +static void __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_4__dealloc__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__dealloc__", 0); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2783, 0, __PYX_ERR(0, 2783, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":2784 + * + * def __dealloc__(self): + * if self.buf is not NULL: # <<<<<<<<<<<<<< + * free(self.buf) + * */ - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) - } - __pyx_t_6 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) - __pyx_t_7 = ((__pyx_t_6 > 8) != 0); - if (__pyx_t_7) { - } else { - __pyx_t_5 = __pyx_t_7; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_7 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) - __pyx_t_8 = (__pyx_t_7 != 0); - __pyx_t_5 = __pyx_t_8; - __pyx_L4_bool_binop_done:; - if (__pyx_t_5) { + __pyx_t_1 = ((__pyx_v_self->buf != NULL) != 0); + if (__pyx_t_1) { - /* "(tree fragment)":12 - * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] - * if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'): - * __pyx_result.__dict__.update(__pyx_state[8]) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2785 + * def __dealloc__(self): + * if self.buf is not NULL: + * free(self.buf) # <<<<<<<<<<<<<< + * + * def set_min_base_quality(self, min_base_quality): */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_update); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) - } - __pyx_t_9 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 8, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - } - } - if (!__pyx_t_11) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_t_9}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_t_9}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - { - __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + free(__pyx_v_self->buf); - /* "(tree fragment)":11 - * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): - * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] - * if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< - * __pyx_result.__dict__.update(__pyx_state[8]) + /* "pysam/libcalignedsegment.pyx":2784 + * + * def __dealloc__(self): + * if self.buf is not NULL: # <<<<<<<<<<<<<< + * free(self.buf) + * */ } - /* "(tree fragment)":9 - * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) - * return __pyx_result - * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< - * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] - * if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'): + /* "pysam/libcalignedsegment.pyx":2783 + * "\n".join(map(str, self.pileups)) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * if self.buf is not NULL: + * free(self.buf) */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("pysam.libcalignedsegment.__pyx_unpickle_PileupRead__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_WriteUnraisable("pysam.libcalignedsegment.PileupColumn.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); - return __pyx_r; } -/* "array.pxd":93 - * __data_union data +/* "pysam/libcalignedsegment.pyx":2787 + * free(self.buf) * - * def __getbuffer__(self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< - * # This implementation of getbuffer is geared towards Cython - * # requirements, and does not yet fulfill the PEP. + * def set_min_base_quality(self, min_base_quality): # <<<<<<<<<<<<<< + * """set the minimum base quality for this pileup column. + * """ */ /* Python wrapper */ -static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ -static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_7set_min_base_quality(PyObject *__pyx_v_self, PyObject *__pyx_v_min_base_quality); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_6set_min_base_quality[] = "PileupColumn.set_min_base_quality(self, min_base_quality)\nset the minimum base quality for this pileup column.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_7set_min_base_quality(PyObject *__pyx_v_self, PyObject *__pyx_v_min_base_quality) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0); - __pyx_r = __pyx_pf_7cpython_5array_5array___getbuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); + __Pyx_RefNannySetupContext("set_min_base_quality (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_6set_min_base_quality(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_min_base_quality)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags) { - PyObject *__pyx_v_item_count = NULL; - int __pyx_r; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_6set_min_base_quality(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_min_base_quality) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - char *__pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - Py_ssize_t __pyx_t_5; - int __pyx_t_6; - if (__pyx_v_info == NULL) { - PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete"); - return -1; - } - __Pyx_RefNannySetupContext("__getbuffer__", 0); - __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(__pyx_v_info->obj); - __Pyx_TraceCall("__getbuffer__", __pyx_f[2], 93, 0, __PYX_ERR(2, 93, __pyx_L1_error)); + uint32_t __pyx_t_1; + __Pyx_RefNannySetupContext("set_min_base_quality", 0); + __Pyx_TraceCall("set_min_base_quality", __pyx_f[0], 2787, 0, __PYX_ERR(0, 2787, __pyx_L1_error)); - /* "array.pxd":98 - * # In particular strided access is always provided regardless - * # of flags - * item_count = Py_SIZE(self) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2790 + * """set the minimum base quality for this pileup column. + * """ + * self.min_base_quality = min_base_quality # <<<<<<<<<<<<<< * - * info.suboffsets = NULL + * def __len__(self): */ - __pyx_t_1 = PyInt_FromSsize_t(Py_SIZE(((PyObject *)__pyx_v_self))); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 98, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_item_count = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_As_uint32_t(__pyx_v_min_base_quality); if (unlikely((__pyx_t_1 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2790, __pyx_L1_error) + __pyx_v_self->min_base_quality = __pyx_t_1; - /* "array.pxd":100 - * item_count = Py_SIZE(self) + /* "pysam/libcalignedsegment.pyx":2787 + * free(self.buf) * - * info.suboffsets = NULL # <<<<<<<<<<<<<< - * info.buf = self.data.as_chars - * info.readonly = 0 + * def set_min_base_quality(self, min_base_quality): # <<<<<<<<<<<<<< + * """set the minimum base quality for this pileup column. + * """ */ - __pyx_v_info->suboffsets = NULL; - /* "array.pxd":101 + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.set_min_base_quality", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":2792 + * self.min_base_quality = min_base_quality + * + * def __len__(self): # <<<<<<<<<<<<<< + * """return number of reads aligned to this column. * - * info.suboffsets = NULL - * info.buf = self.data.as_chars # <<<<<<<<<<<<<< - * info.readonly = 0 - * info.ndim = 1 */ - __pyx_t_2 = __pyx_v_self->data.as_chars; - __pyx_v_info->buf = __pyx_t_2; - /* "array.pxd":102 - * info.suboffsets = NULL - * info.buf = self.data.as_chars - * info.readonly = 0 # <<<<<<<<<<<<<< - * info.ndim = 1 - * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) - */ - __pyx_v_info->readonly = 0; +/* Python wrapper */ +static Py_ssize_t __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9__len__(PyObject *__pyx_v_self); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_8__len__[] = "return number of reads aligned to this column.\n\n see :meth:`get_num_aligned`\n "; +#if CYTHON_COMPILING_IN_CPYTHON +struct wrapperbase __pyx_wrapperbase_5pysam_18libcalignedsegment_12PileupColumn_8__len__; +#endif +static Py_ssize_t __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_8__len__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); - /* "array.pxd":103 - * info.buf = self.data.as_chars - * info.readonly = 0 - * info.ndim = 1 # <<<<<<<<<<<<<< - * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) - * info.len = info.itemsize * item_count - */ - __pyx_v_info->ndim = 1; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "array.pxd":104 - * info.readonly = 0 - * info.ndim = 1 - * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) # <<<<<<<<<<<<<< - * info.len = info.itemsize * item_count - * - */ - __pyx_t_3 = __pyx_v_self->ob_descr->itemsize; - __pyx_v_info->itemsize = __pyx_t_3; +static Py_ssize_t __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_8__len__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + __Pyx_RefNannySetupContext("__len__", 0); + __Pyx_TraceCall("__len__", __pyx_f[0], 2792, 0, __PYX_ERR(0, 2792, __pyx_L1_error)); - /* "array.pxd":105 - * info.ndim = 1 - * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) - * info.len = info.itemsize * item_count # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2797 + * see :meth:`get_num_aligned` + * """ + * return self.get_num_aligned() # <<<<<<<<<<<<<< * - * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) + * property reference_id: */ - __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_info->itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 105, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_num_aligned); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2797, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2797, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2797, __pyx_L1_error) + } __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyNumber_Multiply(__pyx_t_1, __pyx_v_item_count); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 105, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 2797, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 105, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_info->len = __pyx_t_5; + __pyx_r = __pyx_t_4; + goto __pyx_L0; - /* "array.pxd":107 - * info.len = info.itemsize * item_count + /* "pysam/libcalignedsegment.pyx":2792 + * self.min_base_quality = min_base_quality * - * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) # <<<<<<<<<<<<<< - * if not info.shape: - * raise MemoryError() - */ - __pyx_v_info->shape = ((Py_ssize_t *)PyObject_Malloc(((sizeof(Py_ssize_t)) + 2))); - - /* "array.pxd":108 + * def __len__(self): # <<<<<<<<<<<<<< + * """return number of reads aligned to this column. * - * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) - * if not info.shape: # <<<<<<<<<<<<<< - * raise MemoryError() - * info.shape[0] = item_count # constant regardless of resizing */ - __pyx_t_6 = ((!(__pyx_v_info->shape != 0)) != 0); - if (unlikely(__pyx_t_6)) { - /* "array.pxd":109 - * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) - * if not info.shape: - * raise MemoryError() # <<<<<<<<<<<<<< - * info.shape[0] = item_count # constant regardless of resizing - * info.strides = &info.itemsize - */ - PyErr_NoMemory(); __PYX_ERR(2, 109, __pyx_L1_error) + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "array.pxd":108 +/* "pysam/libcalignedsegment.pyx":2801 + * property reference_id: + * '''the reference sequence number as defined in the header''' + * def __get__(self): # <<<<<<<<<<<<<< + * return self.tid * - * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) - * if not info.shape: # <<<<<<<<<<<<<< - * raise MemoryError() - * info.shape[0] = item_count # constant regardless of resizing */ - } - /* "array.pxd":110 - * if not info.shape: - * raise MemoryError() - * info.shape[0] = item_count # constant regardless of resizing # <<<<<<<<<<<<<< - * info.strides = &info.itemsize - * - */ - __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_item_count); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 110, __pyx_L1_error) - (__pyx_v_info->shape[0]) = __pyx_t_5; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_12reference_id_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_12reference_id_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_12reference_id___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); - /* "array.pxd":111 - * raise MemoryError() - * info.shape[0] = item_count # constant regardless of resizing - * info.strides = &info.itemsize # <<<<<<<<<<<<<< - * - * info.format = (info.shape + 1) - */ - __pyx_v_info->strides = (&__pyx_v_info->itemsize); + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "array.pxd":113 - * info.strides = &info.itemsize - * - * info.format = (info.shape + 1) # <<<<<<<<<<<<<< - * info.format[0] = self.ob_descr.typecode - * info.format[1] = 0 - */ - __pyx_v_info->format = ((char *)(__pyx_v_info->shape + 1)); +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_12reference_id___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2801, 0, __PYX_ERR(0, 2801, __pyx_L1_error)); - /* "array.pxd":114 + /* "pysam/libcalignedsegment.pyx":2802 + * '''the reference sequence number as defined in the header''' + * def __get__(self): + * return self.tid # <<<<<<<<<<<<<< * - * info.format = (info.shape + 1) - * info.format[0] = self.ob_descr.typecode # <<<<<<<<<<<<<< - * info.format[1] = 0 - * info.obj = self + * property reference_name: */ - __pyx_t_3 = __pyx_v_self->ob_descr->typecode; - (__pyx_v_info->format[0]) = __pyx_t_3; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2802, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "array.pxd":115 - * info.format = (info.shape + 1) - * info.format[0] = self.ob_descr.typecode - * info.format[1] = 0 # <<<<<<<<<<<<<< - * info.obj = self + /* "pysam/libcalignedsegment.pyx":2801 + * property reference_id: + * '''the reference sequence number as defined in the header''' + * def __get__(self): # <<<<<<<<<<<<<< + * return self.tid * - */ - (__pyx_v_info->format[1]) = 0; - - /* "array.pxd":116 - * info.format[0] = self.ob_descr.typecode - * info.format[1] = 0 - * info.obj = self # <<<<<<<<<<<<<< - * - * def __releasebuffer__(self, Py_buffer* info): - */ - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); - __pyx_v_info->obj = ((PyObject *)__pyx_v_self); - - /* "array.pxd":93 - * __data_union data - * - * def __getbuffer__(self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< - * # This implementation of getbuffer is geared towards Cython - * # requirements, and does not yet fulfill the PEP. */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("cpython.array.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - if (__pyx_v_info->obj != NULL) { - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; - } - goto __pyx_L2; + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.reference_id.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - if (__pyx_v_info->obj == Py_None) { - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; - } - __pyx_L2:; - __Pyx_XDECREF(__pyx_v_item_count); - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "array.pxd":118 - * info.obj = self - * - * def __releasebuffer__(self, Py_buffer* info): # <<<<<<<<<<<<<< - * PyObject_Free(info.shape) - * +/* "pysam/libcalignedsegment.pyx":2806 + * property reference_name: + * """:term:`reference` name (None if no AlignmentFile is associated)""" + * def __get__(self): # <<<<<<<<<<<<<< + * if self.header is not None: + * return self.header.get_reference_name(self.tid) */ /* Python wrapper */ -static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/ -static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0); - __pyx_pf_7cpython_5array_5array_2__releasebuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info) { - __Pyx_TraceDeclarations +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_14reference_name_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_14reference_name_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__releasebuffer__", 0); - __Pyx_TraceCall("__releasebuffer__", __pyx_f[2], 118, 0, __PYX_ERR(2, 118, __pyx_L1_error)); - - /* "array.pxd":119 - * - * def __releasebuffer__(self, Py_buffer* info): - * PyObject_Free(info.shape) # <<<<<<<<<<<<<< - * - * array newarrayobject(PyTypeObject* type, Py_ssize_t size, arraydescr *descr) - */ - PyObject_Free(__pyx_v_info->shape); - - /* "array.pxd":118 - * info.obj = self - * - * def __releasebuffer__(self, Py_buffer* info): # <<<<<<<<<<<<<< - * PyObject_Free(info.shape) - * - */ + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_14reference_name___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("cpython.array.array.__releasebuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "array.pxd":130 - * - * - * cdef inline array clone(array template, Py_ssize_t length, bint zero): # <<<<<<<<<<<<<< - * """ fast creation of a new array, given a template array. - * type will be same as template. - */ - -static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_clone(arrayobject *__pyx_v_template, Py_ssize_t __pyx_v_length, int __pyx_v_zero) { - arrayobject *__pyx_v_op = NULL; - arrayobject *__pyx_r = NULL; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_14reference_name___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("clone", 0); - __Pyx_TraceCall("clone", __pyx_f[2], 130, 0, __PYX_ERR(2, 130, __pyx_L1_error)); - - /* "array.pxd":134 - * type will be same as template. - * if zero is true, new array will be initialized with zeroes.""" - * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) # <<<<<<<<<<<<<< - * if zero and op is not None: - * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) - */ - __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_template)), __pyx_v_length, __pyx_v_template->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 134, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_op = ((arrayobject *)__pyx_t_1); - __pyx_t_1 = 0; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2806, 0, __PYX_ERR(0, 2806, __pyx_L1_error)); - /* "array.pxd":135 - * if zero is true, new array will be initialized with zeroes.""" - * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) - * if zero and op is not None: # <<<<<<<<<<<<<< - * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) - * return op + /* "pysam/libcalignedsegment.pyx":2807 + * """:term:`reference` name (None if no AlignmentFile is associated)""" + * def __get__(self): + * if self.header is not None: # <<<<<<<<<<<<<< + * return self.header.get_reference_name(self.tid) + * return None */ - __pyx_t_3 = (__pyx_v_zero != 0); - if (__pyx_t_3) { - } else { - __pyx_t_2 = __pyx_t_3; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_3 = (((PyObject *)__pyx_v_op) != Py_None); - __pyx_t_4 = (__pyx_t_3 != 0); - __pyx_t_2 = __pyx_t_4; - __pyx_L4_bool_binop_done:; + __pyx_t_1 = (((PyObject *)__pyx_v_self->header) != Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "array.pxd":136 - * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) - * if zero and op is not None: - * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) # <<<<<<<<<<<<<< - * return op + /* "pysam/libcalignedsegment.pyx":2808 + * def __get__(self): + * if self.header is not None: + * return self.header.get_reference_name(self.tid) # <<<<<<<<<<<<<< + * return None * */ - (void)(memset(__pyx_v_op->data.as_chars, 0, (__pyx_v_length * __pyx_v_op->ob_descr->itemsize))); + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2808, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2808, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2808, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2808, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2808, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2808, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2808, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "array.pxd":135 - * if zero is true, new array will be initialized with zeroes.""" - * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) - * if zero and op is not None: # <<<<<<<<<<<<<< - * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) - * return op + /* "pysam/libcalignedsegment.pyx":2807 + * """:term:`reference` name (None if no AlignmentFile is associated)""" + * def __get__(self): + * if self.header is not None: # <<<<<<<<<<<<<< + * return self.header.get_reference_name(self.tid) + * return None */ } - /* "array.pxd":137 - * if zero and op is not None: - * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) - * return op # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2809 + * if self.header is not None: + * return self.header.get_reference_name(self.tid) + * return None # <<<<<<<<<<<<<< * - * cdef inline array copy(array self): + * property nsegments: */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_op)); - __pyx_r = __pyx_v_op; + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "array.pxd":130 - * - * - * cdef inline array clone(array template, Py_ssize_t length, bint zero): # <<<<<<<<<<<<<< - * """ fast creation of a new array, given a template array. - * type will be same as template. + /* "pysam/libcalignedsegment.pyx":2806 + * property reference_name: + * """:term:`reference` name (None if no AlignmentFile is associated)""" + * def __get__(self): # <<<<<<<<<<<<<< + * if self.header is not None: + * return self.header.get_reference_name(self.tid) */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("cpython.array.clone", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.reference_name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_op); - __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "array.pxd":139 - * return op +/* "pysam/libcalignedsegment.pyx":2815 * - * cdef inline array copy(array self): # <<<<<<<<<<<<<< - * """ make a copy of an array. """ - * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) + * Note that this number ignores the base quality filter.''' + * def __get__(self): # <<<<<<<<<<<<<< + * return self.n_pu + * def __set__(self, n): */ -static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_copy(arrayobject *__pyx_v_self) { - arrayobject *__pyx_v_op = NULL; - arrayobject *__pyx_r = NULL; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_9nsegments___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_9nsegments___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("copy", 0); - __Pyx_TraceCall("copy", __pyx_f[2], 139, 0, __PYX_ERR(2, 139, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2815, 0, __PYX_ERR(0, 2815, __pyx_L1_error)); - /* "array.pxd":141 - * cdef inline array copy(array self): - * """ make a copy of an array. """ - * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) # <<<<<<<<<<<<<< - * memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize) - * return op + /* "pysam/libcalignedsegment.pyx":2816 + * Note that this number ignores the base quality filter.''' + * def __get__(self): + * return self.n_pu # <<<<<<<<<<<<<< + * def __set__(self, n): + * self.n_pu = n */ - __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_self)), Py_SIZE(((PyObject *)__pyx_v_self)), __pyx_v_self->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 141, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->n_pu); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2816, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_v_op = ((arrayobject *)__pyx_t_1); + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; - - /* "array.pxd":142 - * """ make a copy of an array. """ - * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) - * memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize) # <<<<<<<<<<<<<< - * return op - * - */ - (void)(memcpy(__pyx_v_op->data.as_chars, __pyx_v_self->data.as_chars, (Py_SIZE(((PyObject *)__pyx_v_op)) * __pyx_v_op->ob_descr->itemsize))); - - /* "array.pxd":143 - * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) - * memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize) - * return op # <<<<<<<<<<<<<< - * - * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1: - */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_op)); - __pyx_r = __pyx_v_op; goto __pyx_L0; - /* "array.pxd":139 - * return op + /* "pysam/libcalignedsegment.pyx":2815 * - * cdef inline array copy(array self): # <<<<<<<<<<<<<< - * """ make a copy of an array. """ - * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) + * Note that this number ignores the base quality filter.''' + * def __get__(self): # <<<<<<<<<<<<<< + * return self.n_pu + * def __set__(self, n): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("cpython.array.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.nsegments.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_op); - __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "array.pxd":145 - * return op +/* "pysam/libcalignedsegment.pyx":2817 + * def __get__(self): + * return self.n_pu + * def __set__(self, n): # <<<<<<<<<<<<<< + * self.n_pu = n * - * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1: # <<<<<<<<<<<<<< - * """ efficient appending of new stuff of same type - * (e.g. of same array type) */ -static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *__pyx_v_self, char *__pyx_v_stuff, Py_ssize_t __pyx_v_n) { - Py_ssize_t __pyx_v_itemsize; - Py_ssize_t __pyx_v_origsize; +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n) { int __pyx_r; - __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("extend_buffer", 0); - __Pyx_TraceCall("extend_buffer", __pyx_f[2], 145, 0, __PYX_ERR(2, 145, __pyx_L1_error)); - - /* "array.pxd":149 - * (e.g. of same array type) - * n: number of elements (not number of bytes!) """ - * cdef Py_ssize_t itemsize = self.ob_descr.itemsize # <<<<<<<<<<<<<< - * cdef Py_ssize_t origsize = Py_SIZE(self) - * resize_smart(self, origsize + n) - */ - __pyx_t_1 = __pyx_v_self->ob_descr->itemsize; - __pyx_v_itemsize = __pyx_t_1; - - /* "array.pxd":150 - * n: number of elements (not number of bytes!) """ - * cdef Py_ssize_t itemsize = self.ob_descr.itemsize - * cdef Py_ssize_t origsize = Py_SIZE(self) # <<<<<<<<<<<<<< - * resize_smart(self, origsize + n) - * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) - */ - __pyx_v_origsize = Py_SIZE(((PyObject *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_n)); - /* "array.pxd":151 - * cdef Py_ssize_t itemsize = self.ob_descr.itemsize - * cdef Py_ssize_t origsize = Py_SIZE(self) - * resize_smart(self, origsize + n) # <<<<<<<<<<<<<< - * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) - * return 0 - */ - __pyx_t_1 = resize_smart(__pyx_v_self, (__pyx_v_origsize + __pyx_v_n)); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(2, 151, __pyx_L1_error) + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "array.pxd":152 - * cdef Py_ssize_t origsize = Py_SIZE(self) - * resize_smart(self, origsize + n) - * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) # <<<<<<<<<<<<<< - * return 0 - * - */ - (void)(memcpy((__pyx_v_self->data.as_chars + (__pyx_v_origsize * __pyx_v_itemsize)), __pyx_v_stuff, (__pyx_v_n * __pyx_v_itemsize))); +static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_n) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2817, 0, __PYX_ERR(0, 2817, __pyx_L1_error)); - /* "array.pxd":153 - * resize_smart(self, origsize + n) - * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) - * return 0 # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2818 + * return self.n_pu + * def __set__(self, n): + * self.n_pu = n # <<<<<<<<<<<<<< * - * cdef inline int extend(array self, array other) except -1: + * property reference_pos: */ - __pyx_r = 0; - goto __pyx_L0; + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_n); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2818, __pyx_L1_error) + __pyx_v_self->n_pu = __pyx_t_1; - /* "array.pxd":145 - * return op + /* "pysam/libcalignedsegment.pyx":2817 + * def __get__(self): + * return self.n_pu + * def __set__(self, n): # <<<<<<<<<<<<<< + * self.n_pu = n * - * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1: # <<<<<<<<<<<<<< - * """ efficient appending of new stuff of same type - * (e.g. of same array type) */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("cpython.array.extend_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.nsegments.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -30669,834 +33581,610 @@ static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *__py return __pyx_r; } -/* "array.pxd":155 - * return 0 +/* "pysam/libcalignedsegment.pyx":2822 + * property reference_pos: + * '''the position in the reference sequence (0-based).''' + * def __get__(self): # <<<<<<<<<<<<<< + * return self.pos * - * cdef inline int extend(array self, array other) except -1: # <<<<<<<<<<<<<< - * """ extend array with data from another array; types must match. """ - * if self.ob_descr.typecode != other.ob_descr.typecode: */ -static CYTHON_INLINE int __pyx_f_7cpython_5array_extend(arrayobject *__pyx_v_self, arrayobject *__pyx_v_other) { - int __pyx_r; - __Pyx_TraceDeclarations +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_13reference_pos_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_13reference_pos_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - __Pyx_RefNannySetupContext("extend", 0); - __Pyx_TraceCall("extend", __pyx_f[2], 155, 0, __PYX_ERR(2, 155, __pyx_L1_error)); - - /* "array.pxd":157 - * cdef inline int extend(array self, array other) except -1: - * """ extend array with data from another array; types must match. """ - * if self.ob_descr.typecode != other.ob_descr.typecode: # <<<<<<<<<<<<<< - * PyErr_BadArgument() - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) - */ - __pyx_t_1 = ((__pyx_v_self->ob_descr->typecode != __pyx_v_other->ob_descr->typecode) != 0); - if (__pyx_t_1) { + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_13reference_pos___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); - /* "array.pxd":158 - * """ extend array with data from another array; types must match. """ - * if self.ob_descr.typecode != other.ob_descr.typecode: - * PyErr_BadArgument() # <<<<<<<<<<<<<< - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) - * - */ - __pyx_t_2 = PyErr_BadArgument(); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(2, 158, __pyx_L1_error) + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "array.pxd":157 - * cdef inline int extend(array self, array other) except -1: - * """ extend array with data from another array; types must match. """ - * if self.ob_descr.typecode != other.ob_descr.typecode: # <<<<<<<<<<<<<< - * PyErr_BadArgument() - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) - */ - } +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_13reference_pos___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2822, 0, __PYX_ERR(0, 2822, __pyx_L1_error)); - /* "array.pxd":159 - * if self.ob_descr.typecode != other.ob_descr.typecode: - * PyErr_BadArgument() - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2823 + * '''the position in the reference sequence (0-based).''' + * def __get__(self): + * return self.pos # <<<<<<<<<<<<<< * - * cdef inline void zero(array self): + * property pileups: */ - __pyx_t_2 = __pyx_f_7cpython_5array_extend_buffer(__pyx_v_self, __pyx_v_other->data.as_chars, Py_SIZE(((PyObject *)__pyx_v_other))); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(2, 159, __pyx_L1_error) - __pyx_r = __pyx_t_2; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2823, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "array.pxd":155 - * return 0 + /* "pysam/libcalignedsegment.pyx":2822 + * property reference_pos: + * '''the position in the reference sequence (0-based).''' + * def __get__(self): # <<<<<<<<<<<<<< + * return self.pos * - * cdef inline int extend(array self, array other) except -1: # <<<<<<<<<<<<<< - * """ extend array with data from another array; types must match. """ - * if self.ob_descr.typecode != other.ob_descr.typecode: */ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("cpython.array.extend", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.reference_pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "array.pxd":161 - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) - * - * cdef inline void zero(array self): # <<<<<<<<<<<<<< - * """ set all elements of array to zero. """ - * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) +/* "pysam/libcalignedsegment.pyx":2827 + * property pileups: + * '''list of reads (:class:`pysam.PileupRead`) aligned to this column''' + * def __get__(self): # <<<<<<<<<<<<<< + * if self.plp == NULL or self.plp[0] == NULL: + * raise ValueError("PileupColumn accessed after iterator finished") */ -static CYTHON_INLINE void __pyx_f_7cpython_5array_zero(arrayobject *__pyx_v_self) { - __Pyx_TraceDeclarations +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_7pileups_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_7pileups_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("zero", 0); - __Pyx_TraceCall("zero", __pyx_f[2], 161, 0, __PYX_ERR(2, 161, __pyx_L1_error)); - - /* "array.pxd":163 - * cdef inline void zero(array self): - * """ set all elements of array to zero. """ - * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) # <<<<<<<<<<<<<< - */ - (void)(memset(__pyx_v_self->data.as_chars, 0, (Py_SIZE(((PyObject *)__pyx_v_self)) * __pyx_v_self->ob_descr->itemsize))); - - /* "array.pxd":161 - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) - * - * cdef inline void zero(array self): # <<<<<<<<<<<<<< - * """ set all elements of array to zero. """ - * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) - */ - - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("cpython.array.zero", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); -} - -/* "View.MemoryView":121 - * cdef bint dtype_is_object - * - * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< - * mode="c", bint allocate_buffer=True): - * - */ - -/* Python wrapper */ -static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_shape = 0; - Py_ssize_t __pyx_v_itemsize; - PyObject *__pyx_v_format = 0; - PyObject *__pyx_v_mode = 0; - int __pyx_v_allocate_buffer; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_shape,&__pyx_n_s_itemsize,&__pyx_n_s_format,&__pyx_n_s_mode,&__pyx_n_s_allocate_buffer,0}; - PyObject* values[5] = {0,0,0,0,0}; - values[3] = ((PyObject *)__pyx_n_s_c); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_shape)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_itemsize)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); __PYX_ERR(1, 121, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); __PYX_ERR(1, 121, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode); - if (value) { values[3] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_allocate_buffer); - if (value) { values[4] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 121, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_shape = ((PyObject*)values[0]); - __pyx_v_itemsize = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_itemsize == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 121, __pyx_L3_error) - __pyx_v_format = values[2]; - __pyx_v_mode = values[3]; - if (values[4]) { - __pyx_v_allocate_buffer = __Pyx_PyObject_IsTrue(values[4]); if (unlikely((__pyx_v_allocate_buffer == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 122, __pyx_L3_error) - } else { - - /* "View.MemoryView":122 - * - * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, - * mode="c", bint allocate_buffer=True): # <<<<<<<<<<<<<< - * - * cdef int idx - */ - __pyx_v_allocate_buffer = ((int)1); - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 121, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_shape), (&PyTuple_Type), 1, "shape", 1))) __PYX_ERR(1, 121, __pyx_L1_error) - if (unlikely(((PyObject *)__pyx_v_format) == Py_None)) { - PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "format"); __PYX_ERR(1, 121, __pyx_L1_error) - } - __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(((struct __pyx_array_obj *)__pyx_v_self), __pyx_v_shape, __pyx_v_itemsize, __pyx_v_format, __pyx_v_mode, __pyx_v_allocate_buffer); - - /* "View.MemoryView":121 - * cdef bint dtype_is_object - * - * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< - * mode="c", bint allocate_buffer=True): - * - */ + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_7pileups___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = -1; - __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer) { - int __pyx_v_idx; - Py_ssize_t __pyx_v_i; - Py_ssize_t __pyx_v_dim; - PyObject **__pyx_v_p; - char __pyx_v_order; - int __pyx_r; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_7pileups___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + int __pyx_v_x; + bam_pileup1_t *__pyx_v_p; + PyObject *__pyx_v_pileups = NULL; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; + int __pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; PyObject *__pyx_t_5 = NULL; - char *__pyx_t_6; - int __pyx_t_7; - Py_ssize_t __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - Py_ssize_t __pyx_t_11; - __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[1], 121, 0, __PYX_ERR(1, 121, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_format); + int __pyx_t_6; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2827, 0, __PYX_ERR(0, 2827, __pyx_L1_error)); - /* "View.MemoryView":128 - * cdef PyObject **p - * - * self.ndim = len(shape) # <<<<<<<<<<<<<< - * self.itemsize = itemsize + /* "pysam/libcalignedsegment.pyx":2828 + * '''list of reads (:class:`pysam.PileupRead`) aligned to this column''' + * def __get__(self): + * if self.plp == NULL or self.plp[0] == NULL: # <<<<<<<<<<<<<< + * raise ValueError("PileupColumn accessed after iterator finished") * */ - if (unlikely(__pyx_v_shape == Py_None)) { - PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 128, __pyx_L1_error) + __pyx_t_2 = ((__pyx_v_self->plp == NULL) != 0); + if (!__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; } - __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_shape); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(1, 128, __pyx_L1_error) - __pyx_v_self->ndim = ((int)__pyx_t_1); - - /* "View.MemoryView":129 - * - * self.ndim = len(shape) - * self.itemsize = itemsize # <<<<<<<<<<<<<< - * - * if not self.ndim: - */ - __pyx_v_self->itemsize = __pyx_v_itemsize; - - /* "View.MemoryView":131 - * self.itemsize = itemsize - * - * if not self.ndim: # <<<<<<<<<<<<<< - * raise ValueError("Empty shape tuple for cython.array") - * - */ - __pyx_t_2 = ((!(__pyx_v_self->ndim != 0)) != 0); - if (unlikely(__pyx_t_2)) { + __pyx_t_2 = (((__pyx_v_self->plp[0]) == NULL) != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L4_bool_binop_done:; + if (unlikely(__pyx_t_1)) { - /* "View.MemoryView":132 - * - * if not self.ndim: - * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2829 + * def __get__(self): + * if self.plp == NULL or self.plp[0] == NULL: + * raise ValueError("PileupColumn accessed after iterator finished") # <<<<<<<<<<<<<< * - * if itemsize <= 0: + * cdef int x */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 132, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2829, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 132, __pyx_L1_error) + __PYX_ERR(0, 2829, __pyx_L1_error) - /* "View.MemoryView":131 - * self.itemsize = itemsize - * - * if not self.ndim: # <<<<<<<<<<<<<< - * raise ValueError("Empty shape tuple for cython.array") + /* "pysam/libcalignedsegment.pyx":2828 + * '''list of reads (:class:`pysam.PileupRead`) aligned to this column''' + * def __get__(self): + * if self.plp == NULL or self.plp[0] == NULL: # <<<<<<<<<<<<<< + * raise ValueError("PileupColumn accessed after iterator finished") * */ } - /* "View.MemoryView":134 - * raise ValueError("Empty shape tuple for cython.array") + /* "pysam/libcalignedsegment.pyx":2832 * - * if itemsize <= 0: # <<<<<<<<<<<<<< - * raise ValueError("itemsize <= 0 for cython.array") + * cdef int x + * cdef bam_pileup1_t * p = NULL # <<<<<<<<<<<<<< + * pileups = [] * */ - __pyx_t_2 = ((__pyx_v_itemsize <= 0) != 0); - if (unlikely(__pyx_t_2)) { + __pyx_v_p = NULL; - /* "View.MemoryView":135 - * - * if itemsize <= 0: - * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2833 + * cdef int x + * cdef bam_pileup1_t * p = NULL + * pileups = [] # <<<<<<<<<<<<<< * - * if not isinstance(format, bytes): + * # warning: there could be problems if self.n and self.buf are */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 135, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 135, __pyx_L1_error) + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2833, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_pileups = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; - /* "View.MemoryView":134 - * raise ValueError("Empty shape tuple for cython.array") - * - * if itemsize <= 0: # <<<<<<<<<<<<<< - * raise ValueError("itemsize <= 0 for cython.array") - * + /* "pysam/libcalignedsegment.pyx":2837 + * # warning: there could be problems if self.n and self.buf are + * # out of sync. + * for x from 0 <= x < self.n_pu: # <<<<<<<<<<<<<< + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): */ - } + __pyx_t_4 = __pyx_v_self->n_pu; + for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_4; __pyx_v_x++) { - /* "View.MemoryView":137 - * raise ValueError("itemsize <= 0 for cython.array") - * - * if not isinstance(format, bytes): # <<<<<<<<<<<<<< - * format = format.encode('ASCII') - * self._format = format # keep a reference to the byte string + /* "pysam/libcalignedsegment.pyx":2838 + * # out of sync. + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) # <<<<<<<<<<<<<< + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue */ - __pyx_t_2 = PyBytes_Check(__pyx_v_format); - __pyx_t_4 = ((!(__pyx_t_2 != 0)) != 0); - if (__pyx_t_4) { + __pyx_v_p = (&((__pyx_v_self->plp[0])[__pyx_v_x])); - /* "View.MemoryView":138 - * - * if not isinstance(format, bytes): - * format = format.encode('ASCII') # <<<<<<<<<<<<<< - * self._format = format # keep a reference to the byte string - * self.format = self._format + /* "pysam/libcalignedsegment.pyx":2839 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): # <<<<<<<<<<<<<< + * continue + * pileups.append(makePileupRead(p, self.header)) */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_format, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF_SET(__pyx_v_format, __pyx_t_5); - __pyx_t_5 = 0; + __pyx_t_1 = (__pyx_f_5pysam_18libcalignedsegment_pileup_base_qual_skip(__pyx_v_p, __pyx_v_self->min_base_quality) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":137 - * raise ValueError("itemsize <= 0 for cython.array") - * - * if not isinstance(format, bytes): # <<<<<<<<<<<<<< - * format = format.encode('ASCII') - * self._format = format # keep a reference to the byte string + /* "pysam/libcalignedsegment.pyx":2840 + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue # <<<<<<<<<<<<<< + * pileups.append(makePileupRead(p, self.header)) + * return pileups */ - } + goto __pyx_L6_continue; - /* "View.MemoryView":139 - * if not isinstance(format, bytes): - * format = format.encode('ASCII') - * self._format = format # keep a reference to the byte string # <<<<<<<<<<<<<< - * self.format = self._format - * + /* "pysam/libcalignedsegment.pyx":2839 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): # <<<<<<<<<<<<<< + * continue + * pileups.append(makePileupRead(p, self.header)) */ - if (!(likely(PyBytes_CheckExact(__pyx_v_format))||((__pyx_v_format) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_format)->tp_name), 0))) __PYX_ERR(1, 139, __pyx_L1_error) - __pyx_t_5 = __pyx_v_format; - __Pyx_INCREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_v_self->_format); - __Pyx_DECREF(__pyx_v_self->_format); - __pyx_v_self->_format = ((PyObject*)__pyx_t_5); - __pyx_t_5 = 0; + } - /* "View.MemoryView":140 - * format = format.encode('ASCII') - * self._format = format # keep a reference to the byte string - * self.format = self._format # <<<<<<<<<<<<<< - * + /* "pysam/libcalignedsegment.pyx":2841 + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue + * pileups.append(makePileupRead(p, self.header)) # <<<<<<<<<<<<<< + * return pileups * */ - if (unlikely(__pyx_v_self->_format == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(1, 140, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_v_self->header); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_5 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makePileupRead(__pyx_v_p, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_3))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2841, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_pileups, __pyx_t_5); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 2841, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_L6_continue:; } - __pyx_t_6 = __Pyx_PyBytes_AsWritableString(__pyx_v_self->_format); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(1, 140, __pyx_L1_error) - __pyx_v_self->format = __pyx_t_6; - /* "View.MemoryView":143 - * - * - * self._shape = PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2) # <<<<<<<<<<<<<< - * self._strides = self._shape + self.ndim + /* "pysam/libcalignedsegment.pyx":2842 + * continue + * pileups.append(makePileupRead(p, self.header)) + * return pileups # <<<<<<<<<<<<<< * + * ######################################################## */ - __pyx_v_self->_shape = ((Py_ssize_t *)PyObject_Malloc((((sizeof(Py_ssize_t)) * __pyx_v_self->ndim) * 2))); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_pileups); + __pyx_r = __pyx_v_pileups; + goto __pyx_L0; - /* "View.MemoryView":144 - * - * self._shape = PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2) - * self._strides = self._shape + self.ndim # <<<<<<<<<<<<<< - * - * if not self._shape: + /* "pysam/libcalignedsegment.pyx":2827 + * property pileups: + * '''list of reads (:class:`pysam.PileupRead`) aligned to this column''' + * def __get__(self): # <<<<<<<<<<<<<< + * if self.plp == NULL or self.plp[0] == NULL: + * raise ValueError("PileupColumn accessed after iterator finished") */ - __pyx_v_self->_strides = (__pyx_v_self->_shape + __pyx_v_self->ndim); - /* "View.MemoryView":146 - * self._strides = self._shape + self.ndim - * - * if not self._shape: # <<<<<<<<<<<<<< - * raise MemoryError("unable to allocate shape and strides.") - * + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.pileups.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_pileups); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":2850 + * property pos: + * """deprecated: use reference_pos""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.reference_pos + * def __set__(self, v): */ - __pyx_t_4 = ((!(__pyx_v_self->_shape != 0)) != 0); - if (unlikely(__pyx_t_4)) { - /* "View.MemoryView":147 - * - * if not self._shape: - * raise MemoryError("unable to allocate shape and strides.") # <<<<<<<<<<<<<< - * - * +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3pos_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3pos___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3pos___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2850, 0, __PYX_ERR(0, 2850, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":2851 + * """deprecated: use reference_pos""" + * def __get__(self): + * return self.reference_pos # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.reference_pos = v */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 147, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(1, 147, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2851, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "View.MemoryView":146 - * self._strides = self._shape + self.ndim - * - * if not self._shape: # <<<<<<<<<<<<<< - * raise MemoryError("unable to allocate shape and strides.") - * + /* "pysam/libcalignedsegment.pyx":2850 + * property pos: + * """deprecated: use reference_pos""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.reference_pos + * def __set__(self, v): */ - } - /* "View.MemoryView":150 - * + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":2852 + * def __get__(self): + * return self.reference_pos + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.reference_pos = v * - * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<< - * if dim <= 0: - * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) */ - __pyx_t_7 = 0; - __pyx_t_5 = __pyx_v_shape; __Pyx_INCREF(__pyx_t_5); __pyx_t_1 = 0; - for (;;) { - if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_5)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(1, 150, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 150, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 150, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_dim = __pyx_t_8; - __pyx_v_idx = __pyx_t_7; - __pyx_t_7 = (__pyx_t_7 + 1); - /* "View.MemoryView":151 +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3pos_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_v)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3pos_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2852, 0, __PYX_ERR(0, 2852, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":2853 + * return self.reference_pos + * def __set__(self, v): + * self.reference_pos = v # <<<<<<<<<<<<<< * - * for idx, dim in enumerate(shape): - * if dim <= 0: # <<<<<<<<<<<<<< - * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) - * self._shape[idx] = dim + * property tid: */ - __pyx_t_4 = ((__pyx_v_dim <= 0) != 0); - if (unlikely(__pyx_t_4)) { + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos, __pyx_v_v) < 0) __PYX_ERR(0, 2853, __pyx_L1_error) - /* "View.MemoryView":152 - * for idx, dim in enumerate(shape): - * if dim <= 0: - * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) # <<<<<<<<<<<<<< - * self._shape[idx] = dim + /* "pysam/libcalignedsegment.pyx":2852 + * def __get__(self): + * return self.reference_pos + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.reference_pos = v * */ - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_9); - __pyx_t_3 = 0; - __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_Raise(__pyx_t_10, 0, 0, 0); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __PYX_ERR(1, 152, __pyx_L1_error) - - /* "View.MemoryView":151 - * - * for idx, dim in enumerate(shape): - * if dim <= 0: # <<<<<<<<<<<<<< - * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) - * self._shape[idx] = dim - */ - } - /* "View.MemoryView":153 - * if dim <= 0: - * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) - * self._shape[idx] = dim # <<<<<<<<<<<<<< - * - * cdef char order - */ - (__pyx_v_self->_shape[__pyx_v_idx]) = __pyx_v_dim; + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.pos.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":150 - * - * - * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<< - * if dim <= 0: - * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) +/* "pysam/libcalignedsegment.pyx":2857 + * property tid: + * """deprecated: use reference_id""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.reference_id + * def __set__(self, v): */ - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "View.MemoryView":156 - * - * cdef char order - * if mode == 'fortran': # <<<<<<<<<<<<<< - * order = b'F' - * self.mode = u'fortran' - */ - __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_fortran, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 156, __pyx_L1_error) - if (__pyx_t_4) { +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3tid_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3tid___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); - /* "View.MemoryView":157 - * cdef char order - * if mode == 'fortran': - * order = b'F' # <<<<<<<<<<<<<< - * self.mode = u'fortran' - * elif mode == 'c': - */ - __pyx_v_order = 'F'; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":158 - * if mode == 'fortran': - * order = b'F' - * self.mode = u'fortran' # <<<<<<<<<<<<<< - * elif mode == 'c': - * order = b'C' - */ - __Pyx_INCREF(__pyx_n_u_fortran); - __Pyx_GIVEREF(__pyx_n_u_fortran); - __Pyx_GOTREF(__pyx_v_self->mode); - __Pyx_DECREF(__pyx_v_self->mode); - __pyx_v_self->mode = __pyx_n_u_fortran; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3tid___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2857, 0, __PYX_ERR(0, 2857, __pyx_L1_error)); - /* "View.MemoryView":156 - * - * cdef char order - * if mode == 'fortran': # <<<<<<<<<<<<<< - * order = b'F' - * self.mode = u'fortran' + /* "pysam/libcalignedsegment.pyx":2858 + * """deprecated: use reference_id""" + * def __get__(self): + * return self.reference_id # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.reference_id = v */ - goto __pyx_L10; - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2858, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "View.MemoryView":159 - * order = b'F' - * self.mode = u'fortran' - * elif mode == 'c': # <<<<<<<<<<<<<< - * order = b'C' - * self.mode = u'c' + /* "pysam/libcalignedsegment.pyx":2857 + * property tid: + * """deprecated: use reference_id""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.reference_id + * def __set__(self, v): */ - __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_c, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 159, __pyx_L1_error) - if (likely(__pyx_t_4)) { - /* "View.MemoryView":160 - * self.mode = u'fortran' - * elif mode == 'c': - * order = b'C' # <<<<<<<<<<<<<< - * self.mode = u'c' - * else: - */ - __pyx_v_order = 'C'; + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":161 - * elif mode == 'c': - * order = b'C' - * self.mode = u'c' # <<<<<<<<<<<<<< - * else: - * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) +/* "pysam/libcalignedsegment.pyx":2859 + * def __get__(self): + * return self.reference_id + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.reference_id = v + * */ - __Pyx_INCREF(__pyx_n_u_c); - __Pyx_GIVEREF(__pyx_n_u_c); - __Pyx_GOTREF(__pyx_v_self->mode); - __Pyx_DECREF(__pyx_v_self->mode); - __pyx_v_self->mode = __pyx_n_u_c; - /* "View.MemoryView":159 - * order = b'F' - * self.mode = u'fortran' - * elif mode == 'c': # <<<<<<<<<<<<<< - * order = b'C' - * self.mode = u'c' - */ - goto __pyx_L10; - } +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3tid_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - /* "View.MemoryView":163 - * self.mode = u'c' - * else: - * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) # <<<<<<<<<<<<<< - * - * self.len = fill_contig_strides_array(self._shape, self._strides, - */ - /*else*/ { - __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_v_mode); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 163, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 163, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_10, 0, 0, 0); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __PYX_ERR(1, 163, __pyx_L1_error) - } - __pyx_L10:; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":165 - * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) - * - * self.len = fill_contig_strides_array(self._shape, self._strides, # <<<<<<<<<<<<<< - * itemsize, self.ndim, order) - * - */ - __pyx_v_self->len = __pyx_fill_contig_strides_array(__pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_itemsize, __pyx_v_self->ndim, __pyx_v_order); +static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_3tid_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2859, 0, __PYX_ERR(0, 2859, __pyx_L1_error)); - /* "View.MemoryView":168 - * itemsize, self.ndim, order) + /* "pysam/libcalignedsegment.pyx":2860 + * return self.reference_id + * def __set__(self, v): + * self.reference_id = v # <<<<<<<<<<<<<< * - * self.free_data = allocate_buffer # <<<<<<<<<<<<<< - * self.dtype_is_object = format == b'O' - * if allocate_buffer: + * property n: */ - __pyx_v_self->free_data = __pyx_v_allocate_buffer; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id, __pyx_v_v) < 0) __PYX_ERR(0, 2860, __pyx_L1_error) - /* "View.MemoryView":169 - * - * self.free_data = allocate_buffer - * self.dtype_is_object = format == b'O' # <<<<<<<<<<<<<< - * if allocate_buffer: + /* "pysam/libcalignedsegment.pyx":2859 + * def __get__(self): + * return self.reference_id + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.reference_id = v * */ - __pyx_t_10 = PyObject_RichCompare(__pyx_v_format, __pyx_n_b_O, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 169, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 169, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_v_self->dtype_is_object = __pyx_t_4; - /* "View.MemoryView":170 - * self.free_data = allocate_buffer - * self.dtype_is_object = format == b'O' - * if allocate_buffer: # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_4 = (__pyx_v_allocate_buffer != 0); - if (__pyx_t_4) { + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.tid.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":173 - * - * - * self.data = malloc(self.len) # <<<<<<<<<<<<<< - * if not self.data: - * raise MemoryError("unable to allocate array data.") +/* "pysam/libcalignedsegment.pyx":2864 + * property n: + * """deprecated: use nsegments""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.nsegments + * def __set__(self, v): */ - __pyx_v_self->data = ((char *)malloc(__pyx_v_self->len)); - /* "View.MemoryView":174 - * - * self.data = malloc(self.len) - * if not self.data: # <<<<<<<<<<<<<< - * raise MemoryError("unable to allocate array data.") - * - */ - __pyx_t_4 = ((!(__pyx_v_self->data != 0)) != 0); - if (unlikely(__pyx_t_4)) { +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1n_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1n_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_1n___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); - /* "View.MemoryView":175 - * self.data = malloc(self.len) - * if not self.data: - * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<< - * - * if self.dtype_is_object: - */ - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_Raise(__pyx_t_10, 0, 0, 0); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __PYX_ERR(1, 175, __pyx_L1_error) + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":174 - * - * self.data = malloc(self.len) - * if not self.data: # <<<<<<<<<<<<<< - * raise MemoryError("unable to allocate array data.") - * - */ - } +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_1n___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 2864, 0, __PYX_ERR(0, 2864, __pyx_L1_error)); - /* "View.MemoryView":177 - * raise MemoryError("unable to allocate array data.") - * - * if self.dtype_is_object: # <<<<<<<<<<<<<< - * p = self.data - * for i in range(self.len / itemsize): + /* "pysam/libcalignedsegment.pyx":2865 + * """deprecated: use nsegments""" + * def __get__(self): + * return self.nsegments # <<<<<<<<<<<<<< + * def __set__(self, v): + * self.nsegments = v */ - __pyx_t_4 = (__pyx_v_self->dtype_is_object != 0); - if (__pyx_t_4) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nsegments); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2865, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "View.MemoryView":178 - * - * if self.dtype_is_object: - * p = self.data # <<<<<<<<<<<<<< - * for i in range(self.len / itemsize): - * p[i] = Py_None + /* "pysam/libcalignedsegment.pyx":2864 + * property n: + * """deprecated: use nsegments""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.nsegments + * def __set__(self, v): */ - __pyx_v_p = ((PyObject **)__pyx_v_self->data); - /* "View.MemoryView":179 - * if self.dtype_is_object: - * p = self.data - * for i in range(self.len / itemsize): # <<<<<<<<<<<<<< - * p[i] = Py_None - * Py_INCREF(Py_None) - */ - if (unlikely(__pyx_v_itemsize == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - __PYX_ERR(1, 179, __pyx_L1_error) - } - else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_self->len))) { - PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); - __PYX_ERR(1, 179, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_div_Py_ssize_t(__pyx_v_self->len, __pyx_v_itemsize); - __pyx_t_8 = __pyx_t_1; - for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_8; __pyx_t_11+=1) { - __pyx_v_i = __pyx_t_11; + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.n.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":180 - * p = self.data - * for i in range(self.len / itemsize): - * p[i] = Py_None # <<<<<<<<<<<<<< - * Py_INCREF(Py_None) +/* "pysam/libcalignedsegment.pyx":2866 + * def __get__(self): + * return self.nsegments + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.nsegments = v * */ - (__pyx_v_p[__pyx_v_i]) = Py_None; - /* "View.MemoryView":181 - * for i in range(self.len / itemsize): - * p[i] = Py_None - * Py_INCREF(Py_None) # <<<<<<<<<<<<<< - * - * @cname('getbuffer') - */ - Py_INCREF(Py_None); - } +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1n_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1n_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_1n_2__set__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_v)); - /* "View.MemoryView":177 - * raise MemoryError("unable to allocate array data.") - * - * if self.dtype_is_object: # <<<<<<<<<<<<<< - * p = self.data - * for i in range(self.len / itemsize): - */ - } + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":170 - * self.free_data = allocate_buffer - * self.dtype_is_object = format == b'O' - * if allocate_buffer: # <<<<<<<<<<<<<< - * +static int __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_1n_2__set__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[0], 2866, 0, __PYX_ERR(0, 2866, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":2867 + * return self.nsegments + * def __set__(self, v): + * self.nsegments = v # <<<<<<<<<<<<<< * + * def get_num_aligned(self): */ - } + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nsegments, __pyx_v_v) < 0) __PYX_ERR(0, 2867, __pyx_L1_error) - /* "View.MemoryView":121 - * cdef bint dtype_is_object - * - * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< - * mode="c", bint allocate_buffer=True): + /* "pysam/libcalignedsegment.pyx":2866 + * def __get__(self): + * return self.nsegments + * def __set__(self, v): # <<<<<<<<<<<<<< + * self.nsegments = v * */ @@ -31504,600 +34192,1325 @@ static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.n.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_format); __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":184 +/* "pysam/libcalignedsegment.pyx":2869 + * self.nsegments = v + * + * def get_num_aligned(self): # <<<<<<<<<<<<<< + * """return number of aligned bases at pileup column position. * - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< - * cdef int bufmode = -1 - * if self.mode == u"c": */ /* Python wrapper */ -static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ -static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_11get_num_aligned(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_10get_num_aligned[] = "PileupColumn.get_num_aligned(self)\nreturn number of aligned bases at pileup column position.\n \n This method applies a base quality filter and the number is\n equal to the size of :meth:`get_query_sequences`,\n :meth:`get_mapping_qualities`, etc.\n\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_11get_num_aligned(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0); - __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(((struct __pyx_array_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); + __Pyx_RefNannySetupContext("get_num_aligned (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_10get_num_aligned(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { - int __pyx_v_bufmode; - int __pyx_r; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_10get_num_aligned(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + uint32_t __pyx_v_x; + CYTHON_UNUSED uint32_t __pyx_v_c; + uint32_t __pyx_v_cnt; + bam_pileup1_t *__pyx_v_p; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; - char *__pyx_t_4; - Py_ssize_t __pyx_t_5; - int __pyx_t_6; - Py_ssize_t *__pyx_t_7; - if (__pyx_v_info == NULL) { - PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete"); - return -1; - } - __Pyx_RefNannySetupContext("__getbuffer__", 0); - __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(__pyx_v_info->obj); - __Pyx_TraceCall("__getbuffer__", __pyx_f[1], 184, 0, __PYX_ERR(1, 184, __pyx_L1_error)); + __Pyx_RefNannySetupContext("get_num_aligned", 0); + __Pyx_TraceCall("get_num_aligned", __pyx_f[0], 2869, 0, __PYX_ERR(0, 2869, __pyx_L1_error)); - /* "View.MemoryView":185 - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): - * cdef int bufmode = -1 # <<<<<<<<<<<<<< - * if self.mode == u"c": - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + /* "pysam/libcalignedsegment.pyx":2877 + * + * """ + * cdef uint32_t x = 0 # <<<<<<<<<<<<<< + * cdef uint32_t c = 0 + * cdef uint32_t cnt = 0 */ - __pyx_v_bufmode = -1; + __pyx_v_x = 0; - /* "View.MemoryView":186 - * def __getbuffer__(self, Py_buffer *info, int flags): - * cdef int bufmode = -1 - * if self.mode == u"c": # <<<<<<<<<<<<<< - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * elif self.mode == u"fortran": + /* "pysam/libcalignedsegment.pyx":2878 + * """ + * cdef uint32_t x = 0 + * cdef uint32_t c = 0 # <<<<<<<<<<<<<< + * cdef uint32_t cnt = 0 + * cdef bam_pileup1_t * p = NULL + */ + __pyx_v_c = 0; + + /* "pysam/libcalignedsegment.pyx":2879 + * cdef uint32_t x = 0 + * cdef uint32_t c = 0 + * cdef uint32_t cnt = 0 # <<<<<<<<<<<<<< + * cdef bam_pileup1_t * p = NULL + * for x from 0 <= x < self.n_pu: + */ + __pyx_v_cnt = 0; + + /* "pysam/libcalignedsegment.pyx":2880 + * cdef uint32_t c = 0 + * cdef uint32_t cnt = 0 + * cdef bam_pileup1_t * p = NULL # <<<<<<<<<<<<<< + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + */ + __pyx_v_p = NULL; + + /* "pysam/libcalignedsegment.pyx":2881 + * cdef uint32_t cnt = 0 + * cdef bam_pileup1_t * p = NULL + * for x from 0 <= x < self.n_pu: # <<<<<<<<<<<<<< + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): + */ + __pyx_t_1 = __pyx_v_self->n_pu; + for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_1; __pyx_v_x++) { + + /* "pysam/libcalignedsegment.pyx":2882 + * cdef bam_pileup1_t * p = NULL + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) # <<<<<<<<<<<<<< + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue + */ + __pyx_v_p = (&((__pyx_v_self->plp[0])[__pyx_v_x])); + + /* "pysam/libcalignedsegment.pyx":2883 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): # <<<<<<<<<<<<<< + * continue + * cnt += 1 + */ + __pyx_t_2 = (__pyx_f_5pysam_18libcalignedsegment_pileup_base_qual_skip(__pyx_v_p, __pyx_v_self->min_base_quality) != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignedsegment.pyx":2884 + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue # <<<<<<<<<<<<<< + * cnt += 1 + * return cnt */ - __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_c, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 186, __pyx_L1_error) - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + goto __pyx_L3_continue; - /* "View.MemoryView":187 - * cdef int bufmode = -1 - * if self.mode == u"c": - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<< - * elif self.mode == u"fortran": - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + /* "pysam/libcalignedsegment.pyx":2883 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): # <<<<<<<<<<<<<< + * continue + * cnt += 1 */ - __pyx_v_bufmode = (PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS); + } - /* "View.MemoryView":186 - * def __getbuffer__(self, Py_buffer *info, int flags): - * cdef int bufmode = -1 - * if self.mode == u"c": # <<<<<<<<<<<<<< - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * elif self.mode == u"fortran": + /* "pysam/libcalignedsegment.pyx":2885 + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue + * cnt += 1 # <<<<<<<<<<<<<< + * return cnt + * */ - goto __pyx_L3; + __pyx_v_cnt = (__pyx_v_cnt + 1); + __pyx_L3_continue:; } - /* "View.MemoryView":188 - * if self.mode == u"c": - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * elif self.mode == u"fortran": # <<<<<<<<<<<<<< - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * if not (flags & bufmode): - */ - __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_fortran, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 188, __pyx_L1_error) - __pyx_t_1 = (__pyx_t_2 != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":189 - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * elif self.mode == u"fortran": - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<< - * if not (flags & bufmode): - * raise ValueError("Can only create a buffer that is contiguous in memory.") + /* "pysam/libcalignedsegment.pyx":2886 + * continue + * cnt += 1 + * return cnt # <<<<<<<<<<<<<< + * + * def get_query_sequences(self, bint mark_matches=False, bint mark_ends=False, bint add_indels=False): */ - __pyx_v_bufmode = (PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS); + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_cnt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2886, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "View.MemoryView":188 - * if self.mode == u"c": - * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * elif self.mode == u"fortran": # <<<<<<<<<<<<<< - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * if not (flags & bufmode): + /* "pysam/libcalignedsegment.pyx":2869 + * self.nsegments = v + * + * def get_num_aligned(self): # <<<<<<<<<<<<<< + * """return number of aligned bases at pileup column position. + * */ - } - __pyx_L3:; - /* "View.MemoryView":190 - * elif self.mode == u"fortran": - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * if not (flags & bufmode): # <<<<<<<<<<<<<< - * raise ValueError("Can only create a buffer that is contiguous in memory.") - * info.buf = self.data - */ - __pyx_t_1 = ((!((__pyx_v_flags & __pyx_v_bufmode) != 0)) != 0); - if (unlikely(__pyx_t_1)) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.get_num_aligned", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":191 - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * if not (flags & bufmode): - * raise ValueError("Can only create a buffer that is contiguous in memory.") # <<<<<<<<<<<<<< - * info.buf = self.data - * info.len = self.len +/* "pysam/libcalignedsegment.pyx":2888 + * return cnt + * + * def get_query_sequences(self, bint mark_matches=False, bint mark_ends=False, bint add_indels=False): # <<<<<<<<<<<<<< + * """query bases/sequences at pileup column position. + * */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 191, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 191, __pyx_L1_error) - /* "View.MemoryView":190 - * elif self.mode == u"fortran": - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * if not (flags & bufmode): # <<<<<<<<<<<<<< - * raise ValueError("Can only create a buffer that is contiguous in memory.") - * info.buf = self.data - */ +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_13get_query_sequences(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_12get_query_sequences[] = "PileupColumn.get_query_sequences(self, bool mark_matches=False, bool mark_ends=False, bool add_indels=False)\nquery bases/sequences at pileup column position.\n\n Optionally, the bases/sequences can be annotated according to the samtools\n mpileup format. This is the format description from the samtools mpileup tool::\n \n Information on match, mismatch, indel, strand, mapping\n quality and start and end of a read are all encoded at the\n read base column. At this column, a dot stands for a match\n to the reference base on the forward strand, a comma for a\n match on the reverse strand, a '>' or '<' for a reference\n skip, `ACGTN' for a mismatch on the forward strand and\n `acgtn' for a mismatch on the reverse strand. A pattern\n `\\+[0-9]+[ACGTNacgtn]+' indicates there is an insertion\n between this reference position and the next reference\n position. The length of the insertion is given by the\n integer in the pattern, followed by the inserted\n sequence. Similarly, a pattern `-[0-9]+[ACGTNacgtn]+'\n represents a deletion from the reference. The deleted bases\n will be presented as `*' in the following lines. Also at\n the read base column, a symbol `^' marks the start of a\n read. The ASCII of the character following `^' minus 33\n gives the mapping quality. A symbol `$' marks the end of a\n read segment\n\n To reproduce samtools mpileup format, set all of mark_matches,\n mark_ends and add_indels to True.\n \n Parameters\n ----------\n\n mark_matches: bool\n\n If True, output bases matching the reference as \",\" or \".\"\n for forward and reverse strand, respectively. This mark\n requires the reference sequence. If no reference is\n present, this option is ignored.\n\n mark_ends :"" bool\n\n If True, add markers \"^\" and \"$\" for read start and end, respectively.\n\n add_indels : bool\n\n If True, add bases for bases inserted into the reference and\n 'N's for base skipped from the reference. If a reference sequence\n is given, add the actual bases.\n \n Returns\n -------\n\n list: a list of bases/sequences per read at pileup column position.\n\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_13get_query_sequences(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_mark_matches; + int __pyx_v_mark_ends; + int __pyx_v_add_indels; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_query_sequences (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_mark_matches,&__pyx_n_s_mark_ends,&__pyx_n_s_add_indels,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mark_matches); + if (value) { values[0] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mark_ends); + if (value) { values[1] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_add_indels); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_query_sequences") < 0)) __PYX_ERR(0, 2888, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + if (values[0]) { + __pyx_v_mark_matches = __Pyx_PyObject_IsTrue(values[0]); if (unlikely((__pyx_v_mark_matches == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2888, __pyx_L3_error) + } else { + __pyx_v_mark_matches = ((int)0); + } + if (values[1]) { + __pyx_v_mark_ends = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_mark_ends == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2888, __pyx_L3_error) + } else { + __pyx_v_mark_ends = ((int)0); + } + if (values[2]) { + __pyx_v_add_indels = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_add_indels == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2888, __pyx_L3_error) + } else { + __pyx_v_add_indels = ((int)0); + } } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_query_sequences", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2888, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.get_query_sequences", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_12get_query_sequences(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self), __pyx_v_mark_matches, __pyx_v_mark_ends, __pyx_v_add_indels); - /* "View.MemoryView":192 - * if not (flags & bufmode): - * raise ValueError("Can only create a buffer that is contiguous in memory.") - * info.buf = self.data # <<<<<<<<<<<<<< - * info.len = self.len - * info.ndim = self.ndim - */ - __pyx_t_4 = __pyx_v_self->data; - __pyx_v_info->buf = __pyx_t_4; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":193 - * raise ValueError("Can only create a buffer that is contiguous in memory.") - * info.buf = self.data - * info.len = self.len # <<<<<<<<<<<<<< - * info.ndim = self.ndim - * info.shape = self._shape - */ - __pyx_t_5 = __pyx_v_self->len; - __pyx_v_info->len = __pyx_t_5; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_12get_query_sequences(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, int __pyx_v_mark_matches, int __pyx_v_mark_ends, int __pyx_v_add_indels) { + uint32_t __pyx_v_x; + uint32_t __pyx_v_j; + CYTHON_UNUSED uint32_t __pyx_v_c; + uint32_t __pyx_v_n; + uint8_t __pyx_v_cc; + uint8_t __pyx_v_rb; + uint8_t *__pyx_v_buf; + bam_pileup1_t *__pyx_v_p; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + uint8_t *__pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("get_query_sequences", 0); + __Pyx_TraceCall("get_query_sequences", __pyx_f[0], 2888, 0, __PYX_ERR(0, 2888, __pyx_L1_error)); - /* "View.MemoryView":194 - * info.buf = self.data - * info.len = self.len - * info.ndim = self.ndim # <<<<<<<<<<<<<< - * info.shape = self._shape - * info.strides = self._strides + /* "pysam/libcalignedsegment.pyx":2942 + * + * """ + * cdef uint32_t x = 0 # <<<<<<<<<<<<<< + * cdef uint32_t j = 0 + * cdef uint32_t c = 0 */ - __pyx_t_6 = __pyx_v_self->ndim; - __pyx_v_info->ndim = __pyx_t_6; + __pyx_v_x = 0; - /* "View.MemoryView":195 - * info.len = self.len - * info.ndim = self.ndim - * info.shape = self._shape # <<<<<<<<<<<<<< - * info.strides = self._strides - * info.suboffsets = NULL + /* "pysam/libcalignedsegment.pyx":2943 + * """ + * cdef uint32_t x = 0 + * cdef uint32_t j = 0 # <<<<<<<<<<<<<< + * cdef uint32_t c = 0 + * cdef uint32_t n = 0 + */ + __pyx_v_j = 0; + + /* "pysam/libcalignedsegment.pyx":2944 + * cdef uint32_t x = 0 + * cdef uint32_t j = 0 + * cdef uint32_t c = 0 # <<<<<<<<<<<<<< + * cdef uint32_t n = 0 + * cdef uint8_t cc = 0 + */ + __pyx_v_c = 0; + + /* "pysam/libcalignedsegment.pyx":2945 + * cdef uint32_t j = 0 + * cdef uint32_t c = 0 + * cdef uint32_t n = 0 # <<<<<<<<<<<<<< + * cdef uint8_t cc = 0 + * cdef uint8_t rb = 0 + */ + __pyx_v_n = 0; + + /* "pysam/libcalignedsegment.pyx":2946 + * cdef uint32_t c = 0 + * cdef uint32_t n = 0 + * cdef uint8_t cc = 0 # <<<<<<<<<<<<<< + * cdef uint8_t rb = 0 + * cdef uint8_t * buf = self.buf + */ + __pyx_v_cc = 0; + + /* "pysam/libcalignedsegment.pyx":2947 + * cdef uint32_t n = 0 + * cdef uint8_t cc = 0 + * cdef uint8_t rb = 0 # <<<<<<<<<<<<<< + * cdef uint8_t * buf = self.buf + * cdef bam_pileup1_t * p = NULL + */ + __pyx_v_rb = 0; + + /* "pysam/libcalignedsegment.pyx":2948 + * cdef uint8_t cc = 0 + * cdef uint8_t rb = 0 + * cdef uint8_t * buf = self.buf # <<<<<<<<<<<<<< + * cdef bam_pileup1_t * p = NULL + * + */ + __pyx_t_1 = __pyx_v_self->buf; + __pyx_v_buf = __pyx_t_1; + + /* "pysam/libcalignedsegment.pyx":2949 + * cdef uint8_t rb = 0 + * cdef uint8_t * buf = self.buf + * cdef bam_pileup1_t * p = NULL # <<<<<<<<<<<<<< + * + * # todo: reference sequence to count matches/mismatches + */ + __pyx_v_p = NULL; + + /* "pysam/libcalignedsegment.pyx":2953 + * # todo: reference sequence to count matches/mismatches + * # todo: convert assertions to exceptions + * for x from 0 <= x < self.n_pu: # <<<<<<<<<<<<<< + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): + */ + __pyx_t_2 = __pyx_v_self->n_pu; + for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) { + + /* "pysam/libcalignedsegment.pyx":2954 + * # todo: convert assertions to exceptions + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) # <<<<<<<<<<<<<< + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue + */ + __pyx_v_p = (&((__pyx_v_self->plp[0])[__pyx_v_x])); + + /* "pysam/libcalignedsegment.pyx":2955 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): # <<<<<<<<<<<<<< + * continue + * # see samtools pileup_seq + */ + __pyx_t_3 = (__pyx_f_5pysam_18libcalignedsegment_pileup_base_qual_skip(__pyx_v_p, __pyx_v_self->min_base_quality) != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":2956 + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue # <<<<<<<<<<<<<< + * # see samtools pileup_seq + * if mark_ends and p.is_head: + */ + goto __pyx_L3_continue; + + /* "pysam/libcalignedsegment.pyx":2955 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): # <<<<<<<<<<<<<< + * continue + * # see samtools pileup_seq */ - __pyx_t_7 = __pyx_v_self->_shape; - __pyx_v_info->shape = __pyx_t_7; + } - /* "View.MemoryView":196 - * info.ndim = self.ndim - * info.shape = self._shape - * info.strides = self._strides # <<<<<<<<<<<<<< - * info.suboffsets = NULL - * info.itemsize = self.itemsize + /* "pysam/libcalignedsegment.pyx":2958 + * continue + * # see samtools pileup_seq + * if mark_ends and p.is_head: # <<<<<<<<<<<<<< + * buf[n] = '^' + * n += 1 */ - __pyx_t_7 = __pyx_v_self->_strides; - __pyx_v_info->strides = __pyx_t_7; + __pyx_t_4 = (__pyx_v_mark_ends != 0); + if (__pyx_t_4) { + } else { + __pyx_t_3 = __pyx_t_4; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_p->is_head != 0); + __pyx_t_3 = __pyx_t_4; + __pyx_L7_bool_binop_done:; + if (__pyx_t_3) { - /* "View.MemoryView":197 - * info.shape = self._shape - * info.strides = self._strides - * info.suboffsets = NULL # <<<<<<<<<<<<<< - * info.itemsize = self.itemsize - * info.readonly = 0 + /* "pysam/libcalignedsegment.pyx":2959 + * # see samtools pileup_seq + * if mark_ends and p.is_head: + * buf[n] = '^' # <<<<<<<<<<<<<< + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE */ - __pyx_v_info->suboffsets = NULL; + (__pyx_v_buf[__pyx_v_n]) = '^'; - /* "View.MemoryView":198 - * info.strides = self._strides - * info.suboffsets = NULL - * info.itemsize = self.itemsize # <<<<<<<<<<<<<< - * info.readonly = 0 + /* "pysam/libcalignedsegment.pyx":2960 + * if mark_ends and p.is_head: + * buf[n] = '^' + * n += 1 # <<<<<<<<<<<<<< + * assert n < MAX_PILEUP_BUFFER_SIZE * */ - __pyx_t_5 = __pyx_v_self->itemsize; - __pyx_v_info->itemsize = __pyx_t_5; + __pyx_v_n = (__pyx_v_n + 1); - /* "View.MemoryView":199 - * info.suboffsets = NULL - * info.itemsize = self.itemsize - * info.readonly = 0 # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":2961 + * buf[n] = '^' + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE # <<<<<<<<<<<<<< * - * if flags & PyBUF_FORMAT: + * if p.b.core.qual > 93: */ - __pyx_v_info->readonly = 0; + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_n < __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 2961, __pyx_L1_error) + } + } + #endif - /* "View.MemoryView":201 - * info.readonly = 0 + /* "pysam/libcalignedsegment.pyx":2963 + * assert n < MAX_PILEUP_BUFFER_SIZE * - * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< - * info.format = self.format - * else: + * if p.b.core.qual > 93: # <<<<<<<<<<<<<< + * buf[n] = 126 + * else: */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0); - if (__pyx_t_1) { + __pyx_t_3 = ((__pyx_v_p->b->core.qual > 93) != 0); + if (__pyx_t_3) { - /* "View.MemoryView":202 + /* "pysam/libcalignedsegment.pyx":2964 * - * if flags & PyBUF_FORMAT: - * info.format = self.format # <<<<<<<<<<<<<< - * else: - * info.format = NULL + * if p.b.core.qual > 93: + * buf[n] = 126 # <<<<<<<<<<<<<< + * else: + * buf[n] = p.b.core.qual + 33 */ - __pyx_t_4 = __pyx_v_self->format; - __pyx_v_info->format = __pyx_t_4; + (__pyx_v_buf[__pyx_v_n]) = 0x7E; - /* "View.MemoryView":201 - * info.readonly = 0 + /* "pysam/libcalignedsegment.pyx":2963 + * assert n < MAX_PILEUP_BUFFER_SIZE * - * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< - * info.format = self.format - * else: + * if p.b.core.qual > 93: # <<<<<<<<<<<<<< + * buf[n] = 126 + * else: */ - goto __pyx_L5; - } + goto __pyx_L9; + } - /* "View.MemoryView":204 - * info.format = self.format - * else: - * info.format = NULL # <<<<<<<<<<<<<< - * - * info.obj = self + /* "pysam/libcalignedsegment.pyx":2966 + * buf[n] = 126 + * else: + * buf[n] = p.b.core.qual + 33 # <<<<<<<<<<<<<< + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE */ - /*else*/ { - __pyx_v_info->format = NULL; - } - __pyx_L5:; + /*else*/ { + (__pyx_v_buf[__pyx_v_n]) = (__pyx_v_p->b->core.qual + 33); + } + __pyx_L9:; - /* "View.MemoryView":206 - * info.format = NULL - * - * info.obj = self # <<<<<<<<<<<<<< - * - * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") + /* "pysam/libcalignedsegment.pyx":2967 + * else: + * buf[n] = p.b.core.qual + 33 + * n += 1 # <<<<<<<<<<<<<< + * assert n < MAX_PILEUP_BUFFER_SIZE + * if not p.is_del: + */ + __pyx_v_n = (__pyx_v_n + 1); + + /* "pysam/libcalignedsegment.pyx":2968 + * buf[n] = p.b.core.qual + 33 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE # <<<<<<<<<<<<<< + * if not p.is_del: + * if p.qpos < p.b.core.l_qseq: + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_n < __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 2968, __pyx_L1_error) + } + } + #endif + + /* "pysam/libcalignedsegment.pyx":2958 + * continue + * # see samtools pileup_seq + * if mark_ends and p.is_head: # <<<<<<<<<<<<<< + * buf[n] = '^' + * n += 1 */ - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); - __pyx_v_info->obj = ((PyObject *)__pyx_v_self); + } - /* "View.MemoryView":184 - * - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< - * cdef int bufmode = -1 - * if self.mode == u"c": + /* "pysam/libcalignedsegment.pyx":2969 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + * if not p.is_del: # <<<<<<<<<<<<<< + * if p.qpos < p.b.core.l_qseq: + * cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos)] + */ + __pyx_t_3 = ((!(__pyx_v_p->is_del != 0)) != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":2970 + * assert n < MAX_PILEUP_BUFFER_SIZE + * if not p.is_del: + * if p.qpos < p.b.core.l_qseq: # <<<<<<<<<<<<<< + * cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos)] + * else: */ + __pyx_t_3 = ((__pyx_v_p->qpos < __pyx_v_p->b->core.l_qseq) != 0); + if (__pyx_t_3) { - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - if (__pyx_v_info->obj != NULL) { - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; - } - goto __pyx_L2; - __pyx_L0:; - if (__pyx_v_info->obj == Py_None) { - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; - } - __pyx_L2:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2971 + * if not p.is_del: + * if p.qpos < p.b.core.l_qseq: + * cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos)] # <<<<<<<<<<<<<< + * else: + * cc = 'N' + */ + __pyx_v_cc = ((uint8_t)(seq_nt16_str[bam_seqi(bam_get_seq(__pyx_v_p->b), __pyx_v_p->qpos)])); -/* "View.MemoryView":210 - * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") + /* "pysam/libcalignedsegment.pyx":2970 + * assert n < MAX_PILEUP_BUFFER_SIZE + * if not p.is_del: + * if p.qpos < p.b.core.l_qseq: # <<<<<<<<<<<<<< + * cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos)] + * else: + */ + goto __pyx_L11; + } + + /* "pysam/libcalignedsegment.pyx":2973 + * cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos)] + * else: + * cc = 'N' # <<<<<<<<<<<<<< * - * def __dealloc__(array self): # <<<<<<<<<<<<<< - * if self.callback_free_data != NULL: - * self.callback_free_data(self.data) + * if mark_matches and self.reference_sequence != NULL: */ + /*else*/ { + __pyx_v_cc = 'N'; + } + __pyx_L11:; -/* Python wrapper */ -static void __pyx_array___dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_array___dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(((struct __pyx_array_obj *)__pyx_v_self)); + /* "pysam/libcalignedsegment.pyx":2975 + * cc = 'N' + * + * if mark_matches and self.reference_sequence != NULL: # <<<<<<<<<<<<<< + * rb = self.reference_sequence[self.reference_pos] + * if seq_nt16_table[cc] == seq_nt16_table[rb]: + */ + __pyx_t_4 = (__pyx_v_mark_matches != 0); + if (__pyx_t_4) { + } else { + __pyx_t_3 = __pyx_t_4; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_4 = ((__pyx_v_self->reference_sequence != NULL) != 0); + __pyx_t_3 = __pyx_t_4; + __pyx_L13_bool_binop_done:; + if (__pyx_t_3) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} + /* "pysam/libcalignedsegment.pyx":2976 + * + * if mark_matches and self.reference_sequence != NULL: + * rb = self.reference_sequence[self.reference_pos] # <<<<<<<<<<<<<< + * if seq_nt16_table[cc] == seq_nt16_table[rb]: + * cc = "=" + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2976, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 2976, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_rb = (__pyx_v_self->reference_sequence[__pyx_t_6]); -static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self) { - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[1], 210, 0, __PYX_ERR(1, 210, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":2977 + * if mark_matches and self.reference_sequence != NULL: + * rb = self.reference_sequence[self.reference_pos] + * if seq_nt16_table[cc] == seq_nt16_table[rb]: # <<<<<<<<<<<<<< + * cc = "=" + * buf[n] = strand_mark_char(cc, p.b) + */ + __pyx_t_3 = (((seq_nt16_table[__pyx_v_cc]) == (seq_nt16_table[__pyx_v_rb])) != 0); + if (__pyx_t_3) { - /* "View.MemoryView":211 - * - * def __dealloc__(array self): - * if self.callback_free_data != NULL: # <<<<<<<<<<<<<< - * self.callback_free_data(self.data) - * elif self.free_data: + /* "pysam/libcalignedsegment.pyx":2978 + * rb = self.reference_sequence[self.reference_pos] + * if seq_nt16_table[cc] == seq_nt16_table[rb]: + * cc = "=" # <<<<<<<<<<<<<< + * buf[n] = strand_mark_char(cc, p.b) + * n += 1 */ - __pyx_t_1 = ((__pyx_v_self->callback_free_data != NULL) != 0); - if (__pyx_t_1) { + __pyx_v_cc = '='; - /* "View.MemoryView":212 - * def __dealloc__(array self): - * if self.callback_free_data != NULL: - * self.callback_free_data(self.data) # <<<<<<<<<<<<<< - * elif self.free_data: - * if self.dtype_is_object: + /* "pysam/libcalignedsegment.pyx":2977 + * if mark_matches and self.reference_sequence != NULL: + * rb = self.reference_sequence[self.reference_pos] + * if seq_nt16_table[cc] == seq_nt16_table[rb]: # <<<<<<<<<<<<<< + * cc = "=" + * buf[n] = strand_mark_char(cc, p.b) */ - __pyx_v_self->callback_free_data(__pyx_v_self->data); + } - /* "View.MemoryView":211 + /* "pysam/libcalignedsegment.pyx":2975 + * cc = 'N' * - * def __dealloc__(array self): - * if self.callback_free_data != NULL: # <<<<<<<<<<<<<< - * self.callback_free_data(self.data) - * elif self.free_data: + * if mark_matches and self.reference_sequence != NULL: # <<<<<<<<<<<<<< + * rb = self.reference_sequence[self.reference_pos] + * if seq_nt16_table[cc] == seq_nt16_table[rb]: */ - goto __pyx_L3; - } + } - /* "View.MemoryView":213 - * if self.callback_free_data != NULL: - * self.callback_free_data(self.data) - * elif self.free_data: # <<<<<<<<<<<<<< - * if self.dtype_is_object: - * refcount_objects_in_slice(self.data, self._shape, - */ - __pyx_t_1 = (__pyx_v_self->free_data != 0); - if (__pyx_t_1) { + /* "pysam/libcalignedsegment.pyx":2979 + * if seq_nt16_table[cc] == seq_nt16_table[rb]: + * cc = "=" + * buf[n] = strand_mark_char(cc, p.b) # <<<<<<<<<<<<<< + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + */ + (__pyx_v_buf[__pyx_v_n]) = __pyx_f_5pysam_18libcalignedsegment_strand_mark_char(__pyx_v_cc, __pyx_v_p->b); + + /* "pysam/libcalignedsegment.pyx":2980 + * cc = "=" + * buf[n] = strand_mark_char(cc, p.b) + * n += 1 # <<<<<<<<<<<<<< + * assert n < MAX_PILEUP_BUFFER_SIZE + * elif add_indels: + */ + __pyx_v_n = (__pyx_v_n + 1); + + /* "pysam/libcalignedsegment.pyx":2981 + * buf[n] = strand_mark_char(cc, p.b) + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE # <<<<<<<<<<<<<< + * elif add_indels: + * if p.is_refskip: + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_n < __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 2981, __pyx_L1_error) + } + } + #endif - /* "View.MemoryView":214 - * self.callback_free_data(self.data) - * elif self.free_data: - * if self.dtype_is_object: # <<<<<<<<<<<<<< - * refcount_objects_in_slice(self.data, self._shape, - * self._strides, self.ndim, False) + /* "pysam/libcalignedsegment.pyx":2969 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + * if not p.is_del: # <<<<<<<<<<<<<< + * if p.qpos < p.b.core.l_qseq: + * cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos)] */ - __pyx_t_1 = (__pyx_v_self->dtype_is_object != 0); - if (__pyx_t_1) { + goto __pyx_L10; + } - /* "View.MemoryView":215 - * elif self.free_data: - * if self.dtype_is_object: - * refcount_objects_in_slice(self.data, self._shape, # <<<<<<<<<<<<<< - * self._strides, self.ndim, False) - * free(self.data) + /* "pysam/libcalignedsegment.pyx":2982 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + * elif add_indels: # <<<<<<<<<<<<<< + * if p.is_refskip: + * if bam_is_rev(p.b): + */ + __pyx_t_3 = (__pyx_v_add_indels != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":2983 + * assert n < MAX_PILEUP_BUFFER_SIZE + * elif add_indels: + * if p.is_refskip: # <<<<<<<<<<<<<< + * if bam_is_rev(p.b): + * buf[n] = '<' + */ + __pyx_t_3 = (__pyx_v_p->is_refskip != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":2984 + * elif add_indels: + * if p.is_refskip: + * if bam_is_rev(p.b): # <<<<<<<<<<<<<< + * buf[n] = '<' + * else: */ - __pyx_memoryview_refcount_objects_in_slice(__pyx_v_self->data, __pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_self->ndim, 0); + __pyx_t_3 = (bam_is_rev(__pyx_v_p->b) != 0); + if (__pyx_t_3) { - /* "View.MemoryView":214 - * self.callback_free_data(self.data) - * elif self.free_data: - * if self.dtype_is_object: # <<<<<<<<<<<<<< - * refcount_objects_in_slice(self.data, self._shape, - * self._strides, self.ndim, False) + /* "pysam/libcalignedsegment.pyx":2985 + * if p.is_refskip: + * if bam_is_rev(p.b): + * buf[n] = '<' # <<<<<<<<<<<<<< + * else: + * buf[n] = '>' */ - } + (__pyx_v_buf[__pyx_v_n]) = '<'; - /* "View.MemoryView":217 - * refcount_objects_in_slice(self.data, self._shape, - * self._strides, self.ndim, False) - * free(self.data) # <<<<<<<<<<<<<< - * PyObject_Free(self._shape) - * + /* "pysam/libcalignedsegment.pyx":2984 + * elif add_indels: + * if p.is_refskip: + * if bam_is_rev(p.b): # <<<<<<<<<<<<<< + * buf[n] = '<' + * else: */ - free(__pyx_v_self->data); + goto __pyx_L17; + } - /* "View.MemoryView":213 - * if self.callback_free_data != NULL: - * self.callback_free_data(self.data) - * elif self.free_data: # <<<<<<<<<<<<<< - * if self.dtype_is_object: - * refcount_objects_in_slice(self.data, self._shape, + /* "pysam/libcalignedsegment.pyx":2987 + * buf[n] = '<' + * else: + * buf[n] = '>' # <<<<<<<<<<<<<< + * else: + * buf[n] = '*' */ - } - __pyx_L3:; + /*else*/ { + (__pyx_v_buf[__pyx_v_n]) = '>'; + } + __pyx_L17:; - /* "View.MemoryView":218 - * self._strides, self.ndim, False) - * free(self.data) - * PyObject_Free(self._shape) # <<<<<<<<<<<<<< - * - * @property + /* "pysam/libcalignedsegment.pyx":2983 + * assert n < MAX_PILEUP_BUFFER_SIZE + * elif add_indels: + * if p.is_refskip: # <<<<<<<<<<<<<< + * if bam_is_rev(p.b): + * buf[n] = '<' */ - PyObject_Free(__pyx_v_self->_shape); + goto __pyx_L16; + } - /* "View.MemoryView":210 - * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") - * - * def __dealloc__(array self): # <<<<<<<<<<<<<< - * if self.callback_free_data != NULL: - * self.callback_free_data(self.data) + /* "pysam/libcalignedsegment.pyx":2989 + * buf[n] = '>' + * else: + * buf[n] = '*' # <<<<<<<<<<<<<< + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE */ + /*else*/ { + (__pyx_v_buf[__pyx_v_n]) = '*'; + } + __pyx_L16:; - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.array.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); -} + /* "pysam/libcalignedsegment.pyx":2990 + * else: + * buf[n] = '*' + * n += 1 # <<<<<<<<<<<<<< + * assert n < MAX_PILEUP_BUFFER_SIZE + * if add_indels: + */ + __pyx_v_n = (__pyx_v_n + 1); + + /* "pysam/libcalignedsegment.pyx":2991 + * buf[n] = '*' + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE # <<<<<<<<<<<<<< + * if add_indels: + * if p.indel > 0: + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_n < __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 2991, __pyx_L1_error) + } + } + #endif -/* "View.MemoryView":221 - * - * @property - * def memview(self): # <<<<<<<<<<<<<< - * return self.get_memview() - * + /* "pysam/libcalignedsegment.pyx":2982 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + * elif add_indels: # <<<<<<<<<<<<<< + * if p.is_refskip: + * if bam_is_rev(p.b): */ + } + __pyx_L10:; -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_5array_7memview___get__(((struct __pyx_array_obj *)__pyx_v_self)); + /* "pysam/libcalignedsegment.pyx":2992 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + * if add_indels: # <<<<<<<<<<<<<< + * if p.indel > 0: + * buf[n] = '+' + */ + __pyx_t_3 = (__pyx_v_add_indels != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":2993 + * assert n < MAX_PILEUP_BUFFER_SIZE + * if add_indels: + * if p.indel > 0: # <<<<<<<<<<<<<< + * buf[n] = '+' + * n += 1 + */ + __pyx_t_3 = ((__pyx_v_p->indel > 0) != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":2994 + * if add_indels: + * if p.indel > 0: + * buf[n] = '+' # <<<<<<<<<<<<<< + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + */ + (__pyx_v_buf[__pyx_v_n]) = '+'; + + /* "pysam/libcalignedsegment.pyx":2995 + * if p.indel > 0: + * buf[n] = '+' + * n += 1 # <<<<<<<<<<<<<< + * assert n < MAX_PILEUP_BUFFER_SIZE + * n += snprintf(&(buf[n]), + */ + __pyx_v_n = (__pyx_v_n + 1); + + /* "pysam/libcalignedsegment.pyx":2996 + * buf[n] = '+' + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE # <<<<<<<<<<<<<< + * n += snprintf(&(buf[n]), + * MAX_PILEUP_BUFFER_SIZE - n, + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_n < __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 2996, __pyx_L1_error) + } + } + #endif - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":2997 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + * n += snprintf(&(buf[n]), # <<<<<<<<<<<<<< + * MAX_PILEUP_BUFFER_SIZE - n, + * "%i", + */ + __pyx_v_n = (__pyx_v_n + snprintf(((char *)(&(__pyx_v_buf[__pyx_v_n]))), (__pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE - __pyx_v_n), ((char const *)"%i"), __pyx_v_p->indel)); + + /* "pysam/libcalignedsegment.pyx":3001 + * "%i", + * p.indel) + * assert n < MAX_PILEUP_BUFFER_SIZE # <<<<<<<<<<<<<< + * for j from 1 <= j <= p.indel: + * cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos + j)] + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_n < __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 3001, __pyx_L1_error) + } + } + #endif -static PyObject *__pyx_pf_15View_dot_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[1], 221, 0, __PYX_ERR(1, 221, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":3002 + * p.indel) + * assert n < MAX_PILEUP_BUFFER_SIZE + * for j from 1 <= j <= p.indel: # <<<<<<<<<<<<<< + * cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos + j)] + * buf[n] = strand_mark_char(cc, p.b) + */ + __pyx_t_7 = __pyx_v_p->indel; + for (__pyx_v_j = 1; __pyx_v_j <= __pyx_t_7; __pyx_v_j++) { + + /* "pysam/libcalignedsegment.pyx":3003 + * assert n < MAX_PILEUP_BUFFER_SIZE + * for j from 1 <= j <= p.indel: + * cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos + j)] # <<<<<<<<<<<<<< + * buf[n] = strand_mark_char(cc, p.b) + * n += 1 + */ + __pyx_v_cc = (seq_nt16_str[bam_seqi(bam_get_seq(__pyx_v_p->b), (__pyx_v_p->qpos + __pyx_v_j))]); + + /* "pysam/libcalignedsegment.pyx":3004 + * for j from 1 <= j <= p.indel: + * cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos + j)] + * buf[n] = strand_mark_char(cc, p.b) # <<<<<<<<<<<<<< + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + */ + (__pyx_v_buf[__pyx_v_n]) = __pyx_f_5pysam_18libcalignedsegment_strand_mark_char(__pyx_v_cc, __pyx_v_p->b); + + /* "pysam/libcalignedsegment.pyx":3005 + * cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos + j)] + * buf[n] = strand_mark_char(cc, p.b) + * n += 1 # <<<<<<<<<<<<<< + * assert n < MAX_PILEUP_BUFFER_SIZE + * elif p.indel < 0: + */ + __pyx_v_n = (__pyx_v_n + 1); + + /* "pysam/libcalignedsegment.pyx":3006 + * buf[n] = strand_mark_char(cc, p.b) + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE # <<<<<<<<<<<<<< + * elif p.indel < 0: + * buf[n] = '-' + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_n < __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 3006, __pyx_L1_error) + } + } + #endif + } - /* "View.MemoryView":222 - * @property - * def memview(self): - * return self.get_memview() # <<<<<<<<<<<<<< - * - * @cname('get_memview') + /* "pysam/libcalignedsegment.pyx":2993 + * assert n < MAX_PILEUP_BUFFER_SIZE + * if add_indels: + * if p.indel > 0: # <<<<<<<<<<<<<< + * buf[n] = '+' + * n += 1 */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((struct __pyx_vtabstruct_array *)__pyx_v_self->__pyx_vtab)->get_memview(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 222, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + goto __pyx_L19; + } - /* "View.MemoryView":221 + /* "pysam/libcalignedsegment.pyx":3007 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + * elif p.indel < 0: # <<<<<<<<<<<<<< + * buf[n] = '-' + * n += 1 + */ + __pyx_t_3 = ((__pyx_v_p->indel < 0) != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":3008 + * assert n < MAX_PILEUP_BUFFER_SIZE + * elif p.indel < 0: + * buf[n] = '-' # <<<<<<<<<<<<<< + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + */ + (__pyx_v_buf[__pyx_v_n]) = '-'; + + /* "pysam/libcalignedsegment.pyx":3009 + * elif p.indel < 0: + * buf[n] = '-' + * n += 1 # <<<<<<<<<<<<<< + * assert n < MAX_PILEUP_BUFFER_SIZE + * n += snprintf(&(buf[n]), + */ + __pyx_v_n = (__pyx_v_n + 1); + + /* "pysam/libcalignedsegment.pyx":3010 + * buf[n] = '-' + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE # <<<<<<<<<<<<<< + * n += snprintf(&(buf[n]), + * MAX_PILEUP_BUFFER_SIZE - n, + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_n < __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 3010, __pyx_L1_error) + } + } + #endif + + /* "pysam/libcalignedsegment.pyx":3011 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + * n += snprintf(&(buf[n]), # <<<<<<<<<<<<<< + * MAX_PILEUP_BUFFER_SIZE - n, + * "%i", + */ + __pyx_v_n = (__pyx_v_n + snprintf(((char *)(&(__pyx_v_buf[__pyx_v_n]))), (__pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE - __pyx_v_n), ((char const *)"%i"), (-__pyx_v_p->indel))); + + /* "pysam/libcalignedsegment.pyx":3015 + * "%i", + * -p.indel) + * assert n < MAX_PILEUP_BUFFER_SIZE # <<<<<<<<<<<<<< + * for j from 1 <= j <= -p.indel: + * # TODO: out-of-range check here? + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_n < __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 3015, __pyx_L1_error) + } + } + #endif + + /* "pysam/libcalignedsegment.pyx":3016 + * -p.indel) + * assert n < MAX_PILEUP_BUFFER_SIZE + * for j from 1 <= j <= -p.indel: # <<<<<<<<<<<<<< + * # TODO: out-of-range check here? + * if self.reference_sequence == NULL: + */ + __pyx_t_7 = (-__pyx_v_p->indel); + for (__pyx_v_j = 1; __pyx_v_j <= __pyx_t_7; __pyx_v_j++) { + + /* "pysam/libcalignedsegment.pyx":3018 + * for j from 1 <= j <= -p.indel: + * # TODO: out-of-range check here? + * if self.reference_sequence == NULL: # <<<<<<<<<<<<<< + * cc = 'N' + * else: + */ + __pyx_t_3 = ((__pyx_v_self->reference_sequence == NULL) != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":3019 + * # TODO: out-of-range check here? + * if self.reference_sequence == NULL: + * cc = 'N' # <<<<<<<<<<<<<< + * else: + * cc = self.reference_sequence[self.reference_pos + j] + */ + __pyx_v_cc = 'N'; + + /* "pysam/libcalignedsegment.pyx":3018 + * for j from 1 <= j <= -p.indel: + * # TODO: out-of-range check here? + * if self.reference_sequence == NULL: # <<<<<<<<<<<<<< + * cc = 'N' + * else: + */ + goto __pyx_L24; + } + + /* "pysam/libcalignedsegment.pyx":3021 + * cc = 'N' + * else: + * cc = self.reference_sequence[self.reference_pos + j] # <<<<<<<<<<<<<< + * buf[n] = strand_mark_char(cc, p.b) + * n += 1 + */ + /*else*/ { + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3021, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_v_j); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3021, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyNumber_Add(__pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3021, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3021, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_cc = (__pyx_v_self->reference_sequence[__pyx_t_6]); + } + __pyx_L24:; + + /* "pysam/libcalignedsegment.pyx":3022 + * else: + * cc = self.reference_sequence[self.reference_pos + j] + * buf[n] = strand_mark_char(cc, p.b) # <<<<<<<<<<<<<< + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + */ + (__pyx_v_buf[__pyx_v_n]) = __pyx_f_5pysam_18libcalignedsegment_strand_mark_char(__pyx_v_cc, __pyx_v_p->b); + + /* "pysam/libcalignedsegment.pyx":3023 + * cc = self.reference_sequence[self.reference_pos + j] + * buf[n] = strand_mark_char(cc, p.b) + * n += 1 # <<<<<<<<<<<<<< + * assert n < MAX_PILEUP_BUFFER_SIZE + * if mark_ends and p.is_tail: + */ + __pyx_v_n = (__pyx_v_n + 1); + + /* "pysam/libcalignedsegment.pyx":3024 + * buf[n] = strand_mark_char(cc, p.b) + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE # <<<<<<<<<<<<<< + * if mark_ends and p.is_tail: + * buf[n] = '$' + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_n < __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 3024, __pyx_L1_error) + } + } + #endif + } + + /* "pysam/libcalignedsegment.pyx":3007 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + * elif p.indel < 0: # <<<<<<<<<<<<<< + * buf[n] = '-' + * n += 1 + */ + } + __pyx_L19:; + + /* "pysam/libcalignedsegment.pyx":2992 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + * if add_indels: # <<<<<<<<<<<<<< + * if p.indel > 0: + * buf[n] = '+' + */ + } + + /* "pysam/libcalignedsegment.pyx":3025 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + * if mark_ends and p.is_tail: # <<<<<<<<<<<<<< + * buf[n] = '$' + * n += 1 + */ + __pyx_t_4 = (__pyx_v_mark_ends != 0); + if (__pyx_t_4) { + } else { + __pyx_t_3 = __pyx_t_4; + goto __pyx_L26_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_p->is_tail != 0); + __pyx_t_3 = __pyx_t_4; + __pyx_L26_bool_binop_done:; + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":3026 + * assert n < MAX_PILEUP_BUFFER_SIZE + * if mark_ends and p.is_tail: + * buf[n] = '$' # <<<<<<<<<<<<<< + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + */ + (__pyx_v_buf[__pyx_v_n]) = '$'; + + /* "pysam/libcalignedsegment.pyx":3027 + * if mark_ends and p.is_tail: + * buf[n] = '$' + * n += 1 # <<<<<<<<<<<<<< + * assert n < MAX_PILEUP_BUFFER_SIZE * - * @property - * def memview(self): # <<<<<<<<<<<<<< - * return self.get_memview() + */ + __pyx_v_n = (__pyx_v_n + 1); + + /* "pysam/libcalignedsegment.pyx":3028 + * buf[n] = '$' + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE # <<<<<<<<<<<<<< * + * buf[n] = ':' */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_n < __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 3028, __pyx_L1_error) + } + } + #endif - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.array.memview.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignedsegment.pyx":3025 + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE + * if mark_ends and p.is_tail: # <<<<<<<<<<<<<< + * buf[n] = '$' + * n += 1 + */ + } -/* "View.MemoryView":225 + /* "pysam/libcalignedsegment.pyx":3030 + * assert n < MAX_PILEUP_BUFFER_SIZE * - * @cname('get_memview') - * cdef get_memview(self): # <<<<<<<<<<<<<< - * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE - * return memoryview(self, flags, self.dtype_is_object) + * buf[n] = ':' # <<<<<<<<<<<<<< + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE */ + (__pyx_v_buf[__pyx_v_n]) = ':'; -static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self) { - int __pyx_v_flags; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("get_memview", 0); - __Pyx_TraceCall("get_memview", __pyx_f[1], 225, 0, __PYX_ERR(1, 225, __pyx_L1_error)); + /* "pysam/libcalignedsegment.pyx":3031 + * + * buf[n] = ':' + * n += 1 # <<<<<<<<<<<<<< + * assert n < MAX_PILEUP_BUFFER_SIZE + * + */ + __pyx_v_n = (__pyx_v_n + 1); - /* "View.MemoryView":226 - * @cname('get_memview') - * cdef get_memview(self): - * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE # <<<<<<<<<<<<<< - * return memoryview(self, flags, self.dtype_is_object) + /* "pysam/libcalignedsegment.pyx":3032 + * buf[n] = ':' + * n += 1 + * assert n < MAX_PILEUP_BUFFER_SIZE # <<<<<<<<<<<<<< * + * if n == 0: */ - __pyx_v_flags = ((PyBUF_ANY_CONTIGUOUS | PyBUF_FORMAT) | PyBUF_WRITABLE); + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_n < __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 3032, __pyx_L1_error) + } + } + #endif + __pyx_L3_continue:; + } - /* "View.MemoryView":227 - * cdef get_memview(self): - * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE - * return memoryview(self, flags, self.dtype_is_object) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":3034 + * assert n < MAX_PILEUP_BUFFER_SIZE * - * def __len__(self): + * if n == 0: # <<<<<<<<<<<<<< + * # could be zero if all qualities are too low + * return "" */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 227, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 227, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 227, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 227, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_t_3 = ((__pyx_v_n == 0) != 0); + if (__pyx_t_3) { - /* "View.MemoryView":225 + /* "pysam/libcalignedsegment.pyx":3036 + * if n == 0: + * # could be zero if all qualities are too low + * return "" # <<<<<<<<<<<<<< + * else: + * # quicker to ensemble all and split than to encode all separately. + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_kp_s__8); + __pyx_r = __pyx_kp_s__8; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":3034 + * assert n < MAX_PILEUP_BUFFER_SIZE + * + * if n == 0: # <<<<<<<<<<<<<< + * # could be zero if all qualities are too low + * return "" + */ + } + + /* "pysam/libcalignedsegment.pyx":3040 + * # quicker to ensemble all and split than to encode all separately. + * # ignore last ":" + * return force_str(PyBytes_FromStringAndSize(buf, n-1)).split(":") # <<<<<<<<<<<<<< + * + * def get_query_qualities(self): + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_9 = PyBytes_FromStringAndSize(((char *)__pyx_v_buf), (__pyx_v_n - 1)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_split); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__45, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L0; + } + + /* "pysam/libcalignedsegment.pyx":2888 + * return cnt + * + * def get_query_sequences(self, bint mark_matches=False, bint mark_ends=False, bint add_indels=False): # <<<<<<<<<<<<<< + * """query bases/sequences at pileup column position. * - * @cname('get_memview') - * cdef get_memview(self): # <<<<<<<<<<<<<< - * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE - * return memoryview(self, flags, self.dtype_is_object) */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.array.get_memview", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.get_query_sequences", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); @@ -32105,280 +35518,718 @@ static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self) { return __pyx_r; } -/* "View.MemoryView":229 - * return memoryview(self, flags, self.dtype_is_object) +/* "pysam/libcalignedsegment.pyx":3042 + * return force_str(PyBytes_FromStringAndSize(buf, n-1)).split(":") * - * def __len__(self): # <<<<<<<<<<<<<< - * return self._shape[0] + * def get_query_qualities(self): # <<<<<<<<<<<<<< + * """query base quality scores at pileup column position. * */ /* Python wrapper */ -static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_15get_query_qualities(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_14get_query_qualities[] = "PileupColumn.get_query_qualities(self)\nquery base quality scores at pileup column position.\n\n Returns\n -------\n\n list: a list of quality scores\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_15get_query_qualities(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(((struct __pyx_array_obj *)__pyx_v_self)); + __Pyx_RefNannySetupContext("get_query_qualities (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_14get_query_qualities(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static Py_ssize_t __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(struct __pyx_array_obj *__pyx_v_self) { - Py_ssize_t __pyx_r; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_14get_query_qualities(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + uint32_t __pyx_v_x; + bam_pileup1_t *__pyx_v_p; + uint32_t __pyx_v_c; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[1], 229, 0, __PYX_ERR(1, 229, __pyx_L1_error)); + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("get_query_qualities", 0); + __Pyx_TraceCall("get_query_qualities", __pyx_f[0], 3042, 0, __PYX_ERR(0, 3042, __pyx_L1_error)); - /* "View.MemoryView":230 + /* "pysam/libcalignedsegment.pyx":3050 + * list: a list of quality scores + * """ + * cdef uint32_t x = 0 # <<<<<<<<<<<<<< + * cdef bam_pileup1_t * p = NULL + * cdef uint32_t c = 0 + */ + __pyx_v_x = 0; + + /* "pysam/libcalignedsegment.pyx":3051 + * """ + * cdef uint32_t x = 0 + * cdef bam_pileup1_t * p = NULL # <<<<<<<<<<<<<< + * cdef uint32_t c = 0 + * result = [] + */ + __pyx_v_p = NULL; + + /* "pysam/libcalignedsegment.pyx":3052 + * cdef uint32_t x = 0 + * cdef bam_pileup1_t * p = NULL + * cdef uint32_t c = 0 # <<<<<<<<<<<<<< + * result = [] + * for x from 0 <= x < self.n_pu: + */ + __pyx_v_c = 0; + + /* "pysam/libcalignedsegment.pyx":3053 + * cdef bam_pileup1_t * p = NULL + * cdef uint32_t c = 0 + * result = [] # <<<<<<<<<<<<<< + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3053, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignedsegment.pyx":3054 + * cdef uint32_t c = 0 + * result = [] + * for x from 0 <= x < self.n_pu: # <<<<<<<<<<<<<< + * p = &(self.plp[0][x]) + * if p.qpos < p.b.core.l_qseq: + */ + __pyx_t_2 = __pyx_v_self->n_pu; + for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) { + + /* "pysam/libcalignedsegment.pyx":3055 + * result = [] + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) # <<<<<<<<<<<<<< + * if p.qpos < p.b.core.l_qseq: + * c = bam_get_qual(p.b)[p.qpos] + */ + __pyx_v_p = (&((__pyx_v_self->plp[0])[__pyx_v_x])); + + /* "pysam/libcalignedsegment.pyx":3056 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if p.qpos < p.b.core.l_qseq: # <<<<<<<<<<<<<< + * c = bam_get_qual(p.b)[p.qpos] + * else: + */ + __pyx_t_3 = ((__pyx_v_p->qpos < __pyx_v_p->b->core.l_qseq) != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":3057 + * p = &(self.plp[0][x]) + * if p.qpos < p.b.core.l_qseq: + * c = bam_get_qual(p.b)[p.qpos] # <<<<<<<<<<<<<< + * else: + * c = 0 + */ + __pyx_v_c = (bam_get_qual(__pyx_v_p->b)[__pyx_v_p->qpos]); + + /* "pysam/libcalignedsegment.pyx":3056 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if p.qpos < p.b.core.l_qseq: # <<<<<<<<<<<<<< + * c = bam_get_qual(p.b)[p.qpos] + * else: + */ + goto __pyx_L5; + } + + /* "pysam/libcalignedsegment.pyx":3059 + * c = bam_get_qual(p.b)[p.qpos] + * else: + * c = 0 # <<<<<<<<<<<<<< + * if c < self.min_base_quality: + * continue + */ + /*else*/ { + __pyx_v_c = 0; + } + __pyx_L5:; + + /* "pysam/libcalignedsegment.pyx":3060 + * else: + * c = 0 + * if c < self.min_base_quality: # <<<<<<<<<<<<<< + * continue + * result.append(c) + */ + __pyx_t_3 = ((__pyx_v_c < __pyx_v_self->min_base_quality) != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":3061 + * c = 0 + * if c < self.min_base_quality: + * continue # <<<<<<<<<<<<<< + * result.append(c) + * return result + */ + goto __pyx_L3_continue; + + /* "pysam/libcalignedsegment.pyx":3060 + * else: + * c = 0 + * if c < self.min_base_quality: # <<<<<<<<<<<<<< + * continue + * result.append(c) + */ + } + + /* "pysam/libcalignedsegment.pyx":3062 + * if c < self.min_base_quality: + * continue + * result.append(c) # <<<<<<<<<<<<<< + * return result * - * def __len__(self): - * return self._shape[0] # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_c); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3062, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 3062, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_L3_continue:; + } + + /* "pysam/libcalignedsegment.pyx":3063 + * continue + * result.append(c) + * return result # <<<<<<<<<<<<<< * - * def __getattr__(self, attr): + * def get_mapping_qualities(self): */ - __pyx_r = (__pyx_v_self->_shape[0]); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; goto __pyx_L0; - /* "View.MemoryView":229 - * return memoryview(self, flags, self.dtype_is_object) + /* "pysam/libcalignedsegment.pyx":3042 + * return force_str(PyBytes_FromStringAndSize(buf, n-1)).split(":") * - * def __len__(self): # <<<<<<<<<<<<<< - * return self._shape[0] + * def get_query_qualities(self): # <<<<<<<<<<<<<< + * """query base quality scores at pileup column position. * */ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("View.MemoryView.array.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.get_query_qualities", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":232 - * return self._shape[0] +/* "pysam/libcalignedsegment.pyx":3065 + * return result * - * def __getattr__(self, attr): # <<<<<<<<<<<<<< - * return getattr(self.memview, attr) + * def get_mapping_qualities(self): # <<<<<<<<<<<<<< + * """query mapping quality scores at pileup column position. * */ /* Python wrapper */ -static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr); /*proto*/ -static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_17get_mapping_qualities(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_16get_mapping_qualities[] = "PileupColumn.get_mapping_qualities(self)\nquery mapping quality scores at pileup column position.\n\n Returns\n -------\n\n list: a list of quality scores\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_17get_mapping_qualities(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0); - __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_attr)); + __Pyx_RefNannySetupContext("get_mapping_qualities (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_16get_mapping_qualities(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_16get_mapping_qualities(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + uint32_t __pyx_v_x; + bam_pileup1_t *__pyx_v_p; + PyObject *__pyx_v_result = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__getattr__", 0); - __Pyx_TraceCall("__getattr__", __pyx_f[1], 232, 0, __PYX_ERR(1, 232, __pyx_L1_error)); + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("get_mapping_qualities", 0); + __Pyx_TraceCall("get_mapping_qualities", __pyx_f[0], 3065, 0, __PYX_ERR(0, 3065, __pyx_L1_error)); - /* "View.MemoryView":233 + /* "pysam/libcalignedsegment.pyx":3073 + * list: a list of quality scores + * """ + * cdef uint32_t x = 0 # <<<<<<<<<<<<<< + * cdef bam_pileup1_t * p = NULL + * result = [] + */ + __pyx_v_x = 0; + + /* "pysam/libcalignedsegment.pyx":3074 + * """ + * cdef uint32_t x = 0 + * cdef bam_pileup1_t * p = NULL # <<<<<<<<<<<<<< + * result = [] + * for x from 0 <= x < self.n_pu: + */ + __pyx_v_p = NULL; + + /* "pysam/libcalignedsegment.pyx":3075 + * cdef uint32_t x = 0 + * cdef bam_pileup1_t * p = NULL + * result = [] # <<<<<<<<<<<<<< + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3075, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignedsegment.pyx":3076 + * cdef bam_pileup1_t * p = NULL + * result = [] + * for x from 0 <= x < self.n_pu: # <<<<<<<<<<<<<< + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): + */ + __pyx_t_2 = __pyx_v_self->n_pu; + for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) { + + /* "pysam/libcalignedsegment.pyx":3077 + * result = [] + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) # <<<<<<<<<<<<<< + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue + */ + __pyx_v_p = (&((__pyx_v_self->plp[0])[__pyx_v_x])); + + /* "pysam/libcalignedsegment.pyx":3078 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): # <<<<<<<<<<<<<< + * continue + * result.append(p.b.core.qual) + */ + __pyx_t_3 = (__pyx_f_5pysam_18libcalignedsegment_pileup_base_qual_skip(__pyx_v_p, __pyx_v_self->min_base_quality) != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":3079 + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue # <<<<<<<<<<<<<< + * result.append(p.b.core.qual) + * return result + */ + goto __pyx_L3_continue; + + /* "pysam/libcalignedsegment.pyx":3078 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): # <<<<<<<<<<<<<< + * continue + * result.append(p.b.core.qual) + */ + } + + /* "pysam/libcalignedsegment.pyx":3080 + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue + * result.append(p.b.core.qual) # <<<<<<<<<<<<<< + * return result * - * def __getattr__(self, attr): - * return getattr(self.memview, attr) # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_PyInt_From_uint8_t(__pyx_v_p->b->core.qual); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 3080, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_L3_continue:; + } + + /* "pysam/libcalignedsegment.pyx":3081 + * continue + * result.append(p.b.core.qual) + * return result # <<<<<<<<<<<<<< * - * def __getitem__(self, item): + * def get_query_positions(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetAttr(__pyx_t_1, __pyx_v_attr); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; goto __pyx_L0; - /* "View.MemoryView":232 - * return self._shape[0] + /* "pysam/libcalignedsegment.pyx":3065 + * return result * - * def __getattr__(self, attr): # <<<<<<<<<<<<<< - * return getattr(self.memview, attr) + * def get_mapping_qualities(self): # <<<<<<<<<<<<<< + * """query mapping quality scores at pileup column position. * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.array.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.get_mapping_qualities", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":235 - * return getattr(self.memview, attr) +/* "pysam/libcalignedsegment.pyx":3083 + * return result * - * def __getitem__(self, item): # <<<<<<<<<<<<<< - * return self.memview[item] + * def get_query_positions(self): # <<<<<<<<<<<<<< + * """positions in read at pileup column position. * */ /* Python wrapper */ -static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item); /*proto*/ -static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_19get_query_positions(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_18get_query_positions[] = "PileupColumn.get_query_positions(self)\npositions in read at pileup column position.\n\n Returns\n -------\n\n list: a list of read positions\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_19get_query_positions(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item)); + __Pyx_RefNannySetupContext("get_query_positions (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_18get_query_positions(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_18get_query_positions(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + uint32_t __pyx_v_x; + bam_pileup1_t *__pyx_v_p; + PyObject *__pyx_v_result = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[1], 235, 0, __PYX_ERR(1, 235, __pyx_L1_error)); + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("get_query_positions", 0); + __Pyx_TraceCall("get_query_positions", __pyx_f[0], 3083, 0, __PYX_ERR(0, 3083, __pyx_L1_error)); - /* "View.MemoryView":236 + /* "pysam/libcalignedsegment.pyx":3092 + * """ * - * def __getitem__(self, item): - * return self.memview[item] # <<<<<<<<<<<<<< + * cdef uint32_t x = 0 # <<<<<<<<<<<<<< + * cdef bam_pileup1_t * p = NULL + * result = [] + */ + __pyx_v_x = 0; + + /* "pysam/libcalignedsegment.pyx":3093 * - * def __setitem__(self, item, value): + * cdef uint32_t x = 0 + * cdef bam_pileup1_t * p = NULL # <<<<<<<<<<<<<< + * result = [] + * for x from 0 <= x < self.n_pu: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 236, __pyx_L1_error) + __pyx_v_p = NULL; + + /* "pysam/libcalignedsegment.pyx":3094 + * cdef uint32_t x = 0 + * cdef bam_pileup1_t * p = NULL + * result = [] # <<<<<<<<<<<<<< + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3094, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_item); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 236, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_v_result = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignedsegment.pyx":3095 + * cdef bam_pileup1_t * p = NULL + * result = [] + * for x from 0 <= x < self.n_pu: # <<<<<<<<<<<<<< + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): + */ + __pyx_t_2 = __pyx_v_self->n_pu; + for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) { + + /* "pysam/libcalignedsegment.pyx":3096 + * result = [] + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) # <<<<<<<<<<<<<< + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue + */ + __pyx_v_p = (&((__pyx_v_self->plp[0])[__pyx_v_x])); + + /* "pysam/libcalignedsegment.pyx":3097 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): # <<<<<<<<<<<<<< + * continue + * result.append(p.qpos) + */ + __pyx_t_3 = (__pyx_f_5pysam_18libcalignedsegment_pileup_base_qual_skip(__pyx_v_p, __pyx_v_self->min_base_quality) != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":3098 + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue # <<<<<<<<<<<<<< + * result.append(p.qpos) + * return result + */ + goto __pyx_L3_continue; + + /* "pysam/libcalignedsegment.pyx":3097 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): # <<<<<<<<<<<<<< + * continue + * result.append(p.qpos) + */ + } + + /* "pysam/libcalignedsegment.pyx":3099 + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue + * result.append(p.qpos) # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_p->qpos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3099, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 3099, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_L3_continue:; + } + + /* "pysam/libcalignedsegment.pyx":3100 + * continue + * result.append(p.qpos) + * return result # <<<<<<<<<<<<<< + * + * def get_query_names(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; goto __pyx_L0; - /* "View.MemoryView":235 - * return getattr(self.memview, attr) + /* "pysam/libcalignedsegment.pyx":3083 + * return result * - * def __getitem__(self, item): # <<<<<<<<<<<<<< - * return self.memview[item] + * def get_query_positions(self): # <<<<<<<<<<<<<< + * """positions in read at pileup column position. * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.array.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.get_query_positions", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":238 - * return self.memview[item] +/* "pysam/libcalignedsegment.pyx":3102 + * return result * - * def __setitem__(self, item, value): # <<<<<<<<<<<<<< - * self.memview[item] = value + * def get_query_names(self): # <<<<<<<<<<<<<< + * """query/read names aligned at pileup column position. * */ /* Python wrapper */ -static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_21get_query_names(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_20get_query_names[] = "PileupColumn.get_query_names(self)\nquery/read names aligned at pileup column position.\n\n Returns\n -------\n\n list: a list of query names at pileup column position.\n "; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_21get_query_names(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); - __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("get_query_names (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_20get_query_names(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_20get_query_names(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { + uint32_t __pyx_v_x; + bam_pileup1_t *__pyx_v_p; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__setitem__", 0); - __Pyx_TraceCall("__setitem__", __pyx_f[1], 238, 0, __PYX_ERR(1, 238, __pyx_L1_error)); + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("get_query_names", 0); + __Pyx_TraceCall("get_query_names", __pyx_f[0], 3102, 0, __PYX_ERR(0, 3102, __pyx_L1_error)); - /* "View.MemoryView":239 + /* "pysam/libcalignedsegment.pyx":3110 + * list: a list of query names at pileup column position. + * """ + * cdef uint32_t x = 0 # <<<<<<<<<<<<<< + * cdef bam_pileup1_t * p = NULL + * result = [] + */ + __pyx_v_x = 0; + + /* "pysam/libcalignedsegment.pyx":3111 + * """ + * cdef uint32_t x = 0 + * cdef bam_pileup1_t * p = NULL # <<<<<<<<<<<<<< + * result = [] + * for x from 0 <= x < self.n_pu: + */ + __pyx_v_p = NULL; + + /* "pysam/libcalignedsegment.pyx":3112 + * cdef uint32_t x = 0 + * cdef bam_pileup1_t * p = NULL + * result = [] # <<<<<<<<<<<<<< + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignedsegment.pyx":3113 + * cdef bam_pileup1_t * p = NULL + * result = [] + * for x from 0 <= x < self.n_pu: # <<<<<<<<<<<<<< + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): + */ + __pyx_t_2 = __pyx_v_self->n_pu; + for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) { + + /* "pysam/libcalignedsegment.pyx":3114 + * result = [] + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) # <<<<<<<<<<<<<< + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue + */ + __pyx_v_p = (&((__pyx_v_self->plp[0])[__pyx_v_x])); + + /* "pysam/libcalignedsegment.pyx":3115 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): # <<<<<<<<<<<<<< + * continue + * result.append(charptr_to_str(pysam_bam_get_qname(p.b))) + */ + __pyx_t_3 = (__pyx_f_5pysam_18libcalignedsegment_pileup_base_qual_skip(__pyx_v_p, __pyx_v_self->min_base_quality) != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignedsegment.pyx":3116 + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue # <<<<<<<<<<<<<< + * result.append(charptr_to_str(pysam_bam_get_qname(p.b))) + * return result + */ + goto __pyx_L3_continue; + + /* "pysam/libcalignedsegment.pyx":3115 + * for x from 0 <= x < self.n_pu: + * p = &(self.plp[0][x]) + * if pileup_base_qual_skip(p, self.min_base_quality): # <<<<<<<<<<<<<< + * continue + * result.append(charptr_to_str(pysam_bam_get_qname(p.b))) + */ + } + + /* "pysam/libcalignedsegment.pyx":3117 + * if pileup_base_qual_skip(p, self.min_base_quality): + * continue + * result.append(charptr_to_str(pysam_bam_get_qname(p.b))) # <<<<<<<<<<<<<< + * return result * - * def __setitem__(self, item, value): - * self.memview[item] = value # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str(pysam_bam_get_qname(__pyx_v_p->b), NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 3117, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_L3_continue:; + } + + /* "pysam/libcalignedsegment.pyx":3118 + * continue + * result.append(charptr_to_str(pysam_bam_get_qname(p.b))) + * return result # <<<<<<<<<<<<<< * * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_v_item, __pyx_v_value) < 0)) __PYX_ERR(1, 239, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; - /* "View.MemoryView":238 - * return self.memview[item] + /* "pysam/libcalignedsegment.pyx":3102 + * return result * - * def __setitem__(self, item, value): # <<<<<<<<<<<<<< - * self.memview[item] = value + * def get_query_names(self): # <<<<<<<<<<<<<< + * """query/read names aligned at pileup column position. * */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.array.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.get_query_names", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * raise TypeError("self.plp cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ /* Python wrapper */ -static PyObject *__pyx_pw___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_23__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_22__reduce_cython__[] = "PileupColumn.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_23__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf___pyx_array___reduce_cython__(((struct __pyx_array_obj *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_22__reduce_cython__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_22__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -32388,11 +36239,11 @@ static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __p /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * raise TypeError("self.plp cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * raise TypeError("self.plp cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__45, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -32400,14 +36251,14 @@ static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __p /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * raise TypeError("self.plp cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.array.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); @@ -32417,25 +36268,26 @@ static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __p /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * raise TypeError("self.plp cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * raise TypeError("self.plp cannot be converted to a Python object for pickling") */ /* Python wrapper */ -static PyObject *__pyx_pw___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_25__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_24__setstate_cython__[] = "PileupColumn.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_25__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf___pyx_array_2__setstate_cython__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_24__setstate_cython__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_12PileupColumn_24__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -32444,11 +36296,11 @@ static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); /* "(tree fragment)":4 - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * raise TypeError("self.plp cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * raise TypeError("self.plp cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -32456,15 +36308,15 @@ static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * raise TypeError("self.plp cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * raise TypeError("self.plp cannot be converted to a Python object for pickling") */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.array.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupColumn.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); @@ -32472,330 +36324,420 @@ static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct return __pyx_r; } -/* "View.MemoryView":243 +/* "pysam/libcalignedsegment.pyx":3127 + * ''' * - * @cname("__pyx_array_new") - * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<< - * char *mode, char *buf): - * cdef array result + * def __init__(self): # <<<<<<<<<<<<<< + * raise TypeError( + * "this class cannot be instantiated from Python") */ -static struct __pyx_array_obj *__pyx_array_new(PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, char *__pyx_v_format, char *__pyx_v_mode, char *__pyx_v_buf) { - struct __pyx_array_obj *__pyx_v_result = 0; - struct __pyx_array_obj *__pyx_r = NULL; - __Pyx_TraceDeclarations +/* Python wrapper */ +static int __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; __Pyx_RefNannyDeclarations - int __pyx_t_1; + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead___init__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_18libcalignedsegment_10PileupRead___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__init__", 0); + __Pyx_TraceCall("__init__", __pyx_f[0], 3127, 0, __PYX_ERR(0, 3127, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":3128 + * + * def __init__(self): + * raise TypeError( # <<<<<<<<<<<<<< + * "this class cannot be instantiated from Python") + * + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 3128, __pyx_L1_error) + + /* "pysam/libcalignedsegment.pyx":3127 + * ''' + * + * def __init__(self): # <<<<<<<<<<<<<< + * raise TypeError( + * "this class cannot be instantiated from Python") + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":3131 + * "this class cannot be instantiated from Python") + * + * def __str__(self): # <<<<<<<<<<<<<< + * return "\t".join( + * map(str, + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_3__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_3__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_2__str__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_2__str__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("array_cwrapper", 0); - __Pyx_TraceCall("array_cwrapper", __pyx_f[1], 243, 0, __PYX_ERR(1, 243, __pyx_L1_error)); + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("__str__", 0); + __Pyx_TraceCall("__str__", __pyx_f[0], 3131, 0, __PYX_ERR(0, 3131, __pyx_L1_error)); - /* "View.MemoryView":247 - * cdef array result + /* "pysam/libcalignedsegment.pyx":3132 * - * if buf == NULL: # <<<<<<<<<<<<<< - * result = array(shape, itemsize, format, mode.decode('ASCII')) - * else: + * def __str__(self): + * return "\t".join( # <<<<<<<<<<<<<< + * map(str, + * (self.alignment, self.query_position, */ - __pyx_t_1 = ((__pyx_v_buf == NULL) != 0); - if (__pyx_t_1) { + __Pyx_XDECREF(__pyx_r); - /* "View.MemoryView":248 - * - * if buf == NULL: - * result = array(shape, itemsize, format, mode.decode('ASCII')) # <<<<<<<<<<<<<< - * else: - * result = array(shape, itemsize, format, mode.decode('ASCII'), + /* "pysam/libcalignedsegment.pyx":3134 + * return "\t".join( + * map(str, + * (self.alignment, self.query_position, # <<<<<<<<<<<<<< + * self.indel, self.level, + * self.is_del, self.is_head, */ - __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 248, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 248, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 248, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 248, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_v_shape); - __Pyx_GIVEREF(__pyx_v_shape); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_shape); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 248, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_4); - __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_alignment); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_position); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); - /* "View.MemoryView":247 - * cdef array result - * - * if buf == NULL: # <<<<<<<<<<<<<< - * result = array(shape, itemsize, format, mode.decode('ASCII')) - * else: + /* "pysam/libcalignedsegment.pyx":3135 + * map(str, + * (self.alignment, self.query_position, + * self.indel, self.level, # <<<<<<<<<<<<<< + * self.is_del, self.is_head, + * self.is_tail, self.is_refskip))) */ - goto __pyx_L3; - } + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_indel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_level); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); - /* "View.MemoryView":250 - * result = array(shape, itemsize, format, mode.decode('ASCII')) - * else: - * result = array(shape, itemsize, format, mode.decode('ASCII'), # <<<<<<<<<<<<<< - * allocate_buffer=False) - * result.data = buf + /* "pysam/libcalignedsegment.pyx":3136 + * (self.alignment, self.query_position, + * self.indel, self.level, + * self.is_del, self.is_head, # <<<<<<<<<<<<<< + * self.is_tail, self.is_refskip))) + * */ - /*else*/ { - __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_shape); - __Pyx_GIVEREF(__pyx_v_shape); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_shape); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_3); - __pyx_t_4 = 0; - __pyx_t_5 = 0; - __pyx_t_3 = 0; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_del); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_head); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); - /* "View.MemoryView":251 - * else: - * result = array(shape, itemsize, format, mode.decode('ASCII'), - * allocate_buffer=False) # <<<<<<<<<<<<<< - * result.data = buf + /* "pysam/libcalignedsegment.pyx":3137 + * self.indel, self.level, + * self.is_del, self.is_head, + * self.is_tail, self.is_refskip))) # <<<<<<<<<<<<<< * + * property alignment: */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 251, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_allocate_buffer, Py_False) < 0) __PYX_ERR(1, 251, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_tail); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_refskip); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); - /* "View.MemoryView":250 - * result = array(shape, itemsize, format, mode.decode('ASCII')) - * else: - * result = array(shape, itemsize, format, mode.decode('ASCII'), # <<<<<<<<<<<<<< - * allocate_buffer=False) - * result.data = buf + /* "pysam/libcalignedsegment.pyx":3134 + * return "\t".join( + * map(str, + * (self.alignment, self.query_position, # <<<<<<<<<<<<<< + * self.indel, self.level, + * self.is_del, self.is_head, */ - __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_5); - __pyx_t_5 = 0; + __pyx_t_9 = PyTuple_New(8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_9, 7, __pyx_t_8); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_6 = 0; + __pyx_t_7 = 0; + __pyx_t_8 = 0; - /* "View.MemoryView":252 - * result = array(shape, itemsize, format, mode.decode('ASCII'), - * allocate_buffer=False) - * result.data = buf # <<<<<<<<<<<<<< - * - * return result + /* "pysam/libcalignedsegment.pyx":3133 + * def __str__(self): + * return "\t".join( + * map(str, # <<<<<<<<<<<<<< + * (self.alignment, self.query_position, + * self.indel, self.level, */ - __pyx_v_result->data = __pyx_v_buf; - } - __pyx_L3:; + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3133, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3133, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - /* "View.MemoryView":254 - * result.data = buf - * - * return result # <<<<<<<<<<<<<< - * + /* "pysam/libcalignedsegment.pyx":3132 * + * def __str__(self): + * return "\t".join( # <<<<<<<<<<<<<< + * map(str, + * (self.alignment, self.query_position, */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = __pyx_v_result; + __pyx_t_8 = __Pyx_PyString_Join(__pyx_kp_s__16, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3132, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; goto __pyx_L0; - /* "View.MemoryView":243 + /* "pysam/libcalignedsegment.pyx":3131 + * "this class cannot be instantiated from Python") * - * @cname("__pyx_array_new") - * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<< - * char *mode, char *buf): - * cdef array result + * def __str__(self): # <<<<<<<<<<<<<< + * return "\t".join( + * map(str, */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.array_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_result); - __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":280 - * cdef class Enum(object): - * cdef object name - * def __init__(self, name): # <<<<<<<<<<<<<< - * self.name = name - * def __repr__(self): +/* "pysam/libcalignedsegment.pyx":3141 + * property alignment: + * """a :class:`pysam.AlignedSegment` object of the aligned read""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._alignment + * */ /* Python wrapper */ -static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_name = 0; - int __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_9alignment_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_9alignment_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,0}; - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(1, 280, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - } - __pyx_v_name = values[0]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 280, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("View.MemoryView.Enum.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), __pyx_v_name); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_9alignment___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_9alignment___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[1], 280, 0, __PYX_ERR(1, 280, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 3141, 0, __PYX_ERR(0, 3141, __pyx_L1_error)); - /* "View.MemoryView":281 - * cdef object name - * def __init__(self, name): - * self.name = name # <<<<<<<<<<<<<< - * def __repr__(self): - * return self.name + /* "pysam/libcalignedsegment.pyx":3142 + * """a :class:`pysam.AlignedSegment` object of the aligned read""" + * def __get__(self): + * return self._alignment # <<<<<<<<<<<<<< + * + * property query_position: */ - __Pyx_INCREF(__pyx_v_name); - __Pyx_GIVEREF(__pyx_v_name); - __Pyx_GOTREF(__pyx_v_self->name); - __Pyx_DECREF(__pyx_v_self->name); - __pyx_v_self->name = __pyx_v_name; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->_alignment)); + __pyx_r = ((PyObject *)__pyx_v_self->_alignment); + goto __pyx_L0; - /* "View.MemoryView":280 - * cdef class Enum(object): - * cdef object name - * def __init__(self, name): # <<<<<<<<<<<<<< - * self.name = name - * def __repr__(self): + /* "pysam/libcalignedsegment.pyx":3141 + * property alignment: + * """a :class:`pysam.AlignedSegment` object of the aligned read""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._alignment + * */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("View.MemoryView.Enum.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.alignment.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":282 - * def __init__(self, name): - * self.name = name - * def __repr__(self): # <<<<<<<<<<<<<< - * return self.name +/* "pysam/libcalignedsegment.pyx":3149 * + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * if self.is_del or self.is_refskip: + * return None */ /* Python wrapper */ -static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_14query_position_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_14query_position_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0); - __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_14query_position___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_14query_position___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__repr__", 0); - __Pyx_TraceCall("__repr__", __pyx_f[1], 282, 0, __PYX_ERR(1, 282, __pyx_L1_error)); + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 3149, 0, __PYX_ERR(0, 3149, __pyx_L1_error)); - /* "View.MemoryView":283 - * self.name = name - * def __repr__(self): - * return self.name # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":3150 + * """ + * def __get__(self): + * if self.is_del or self.is_refskip: # <<<<<<<<<<<<<< + * return None + * else: + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_del); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3150, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 3150, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_refskip); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3150, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 3150, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = __pyx_t_3; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { + + /* "pysam/libcalignedsegment.pyx":3151 + * def __get__(self): + * if self.is_del or self.is_refskip: + * return None # <<<<<<<<<<<<<< + * else: + * return self._qpos + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":3150 + * """ + * def __get__(self): + * if self.is_del or self.is_refskip: # <<<<<<<<<<<<<< + * return None + * else: + */ + } + + /* "pysam/libcalignedsegment.pyx":3153 + * return None + * else: + * return self._qpos # <<<<<<<<<<<<<< * - * cdef generic = Enum("") + * property query_position_or_next: */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->name); - __pyx_r = __pyx_v_self->name; - goto __pyx_L0; + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_qpos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + } - /* "View.MemoryView":282 - * def __init__(self, name): - * self.name = name - * def __repr__(self): # <<<<<<<<<<<<<< - * return self.name + /* "pysam/libcalignedsegment.pyx":3149 * + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * if self.is_del or self.is_refskip: + * return None */ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("View.MemoryView.Enum.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.query_position.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -32804,291 +36746,250 @@ static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr_ return __pyx_r; } -/* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * cdef bint use_setstate - * state = (self.name,) +/* "pysam/libcalignedsegment.pyx":3162 + * + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * return self._qpos + * */ /* Python wrapper */ -static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_22query_position_or_next_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_22query_position_or_next_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf___pyx_MemviewEnum___reduce_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_22query_position_or_next___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf___pyx_MemviewEnum___reduce_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self) { - int __pyx_v_use_setstate; - PyObject *__pyx_v_state = NULL; - PyObject *__pyx_v__dict = NULL; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_22query_position_or_next___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 3162, 0, __PYX_ERR(0, 3162, __pyx_L1_error)); - /* "(tree fragment)":3 - * def __reduce_cython__(self): - * cdef bint use_setstate - * state = (self.name,) # <<<<<<<<<<<<<< - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: + /* "pysam/libcalignedsegment.pyx":3163 + * """ + * def __get__(self): + * return self._qpos # <<<<<<<<<<<<<< + * + * property indel: */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_qpos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3163, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_self->name); - __Pyx_GIVEREF(__pyx_v_self->name); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->name); - __pyx_v_state = ((PyObject*)__pyx_t_1); + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; + goto __pyx_L0; - /* "(tree fragment)":4 - * cdef bint use_setstate - * state = (self.name,) - * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< - * if _dict is not None: - * state += (_dict,) + /* "pysam/libcalignedsegment.pyx":3162 + * + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * return self._qpos + * */ - __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v__dict = __pyx_t_1; - __pyx_t_1 = 0; - /* "(tree fragment)":5 - * state = (self.name,) - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: # <<<<<<<<<<<<<< - * state += (_dict,) - * use_setstate = True - */ - __pyx_t_2 = (__pyx_v__dict != Py_None); - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.query_position_or_next.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "(tree fragment)":6 - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: - * state += (_dict,) # <<<<<<<<<<<<<< - * use_setstate = True - * else: +/* "pysam/libcalignedsegment.pyx":3174 + * + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * return self._indel + * */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v__dict); - __Pyx_GIVEREF(__pyx_v__dict); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); - __pyx_t_4 = 0; - /* "(tree fragment)":7 - * if _dict is not None: - * state += (_dict,) - * use_setstate = True # <<<<<<<<<<<<<< - * else: - * use_setstate = self.name is not None - */ - __pyx_v_use_setstate = 1; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5indel_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5indel_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_5indel___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); - /* "(tree fragment)":5 - * state = (self.name,) - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: # <<<<<<<<<<<<<< - * state += (_dict,) - * use_setstate = True - */ - goto __pyx_L3; - } + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "(tree fragment)":9 - * use_setstate = True - * else: - * use_setstate = self.name is not None # <<<<<<<<<<<<<< - * if use_setstate: - * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state - */ - /*else*/ { - __pyx_t_3 = (__pyx_v_self->name != Py_None); - __pyx_v_use_setstate = __pyx_t_3; - } - __pyx_L3:; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_5indel___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 3174, 0, __PYX_ERR(0, 3174, __pyx_L1_error)); - /* "(tree fragment)":10 - * else: - * use_setstate = self.name is not None - * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state - * else: + /* "pysam/libcalignedsegment.pyx":3175 + * """ + * def __get__(self): + * return self._indel # <<<<<<<<<<<<<< + * + * property level: */ - __pyx_t_3 = (__pyx_v_use_setstate != 0); - if (__pyx_t_3) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_indel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3175, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "(tree fragment)":11 - * use_setstate = self.name is not None - * if use_setstate: - * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state # <<<<<<<<<<<<<< - * else: - * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) + /* "pysam/libcalignedsegment.pyx":3174 + * + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * return self._indel + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_INCREF(__pyx_int_184977713); - __Pyx_GIVEREF(__pyx_int_184977713); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); - __Pyx_INCREF(__pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); - __pyx_t_4 = 0; - __pyx_t_1 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; - /* "(tree fragment)":10 - * else: - * use_setstate = self.name is not None - * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state - * else: + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.indel.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignedsegment.pyx":3180 + * """the level of the read in the "viewer" mode. Note that this value + * is currently not computed.""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._level + * */ - } - /* "(tree fragment)":13 - * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state - * else: - * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_Enum__set_state(self, __pyx_state) +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5level_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5level_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_5level___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_5level___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 3180, 0, __PYX_ERR(0, 3180, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":3181 + * is currently not computed.""" + * def __get__(self): + * return self._level # <<<<<<<<<<<<<< + * + * property is_del: */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_INCREF(__pyx_int_184977713); - __Pyx_GIVEREF(__pyx_int_184977713); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713); - __Pyx_INCREF(__pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); - __pyx_t_5 = 0; - __pyx_t_1 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_level); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3181, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * cdef bint use_setstate - * state = (self.name,) + /* "pysam/libcalignedsegment.pyx":3180 + * """the level of the read in the "viewer" mode. Note that this value + * is currently not computed.""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._level + * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.Enum.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.level.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_state); - __Pyx_XDECREF(__pyx_v__dict); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":14 - * else: - * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_Enum__set_state(self, __pyx_state) +/* "pysam/libcalignedsegment.pyx":3185 + * property is_del: + * """1 iff the base on the padded read is a deletion""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._is_del + * */ /* Python wrapper */ -static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_6is_del_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_6is_del_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf___pyx_MemviewEnum_2__setstate_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_6is_del___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_6is_del___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 3185, 0, __PYX_ERR(0, 3185, __pyx_L1_error)); - /* "(tree fragment)":15 - * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) - * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_Enum__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":3186 + * """1 iff the base on the padded read is a deletion""" + * def __get__(self): + * return self._is_del # <<<<<<<<<<<<<< + * + * property is_head: */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_unpickle_Enum__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_del); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3186, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "(tree fragment)":14 - * else: - * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_Enum__set_state(self, __pyx_state) + /* "pysam/libcalignedsegment.pyx":3185 + * property is_del: + * """1 iff the base on the padded read is a deletion""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._is_del + * */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.Enum.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.is_del.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -33097,116 +36998,556 @@ static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_Me return __pyx_r; } -/* "View.MemoryView":297 +/* "pysam/libcalignedsegment.pyx":3190 + * property is_head: + * """1 iff the base on the padded read is the left-most base.""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._is_head * - * @cname('__pyx_align_pointer') - * cdef void *align_pointer(void *memory, size_t alignment) nogil: # <<<<<<<<<<<<<< - * "Align pointer memory on a given boundary" - * cdef Py_intptr_t aligned_p = memory */ -static void *__pyx_align_pointer(void *__pyx_v_memory, size_t __pyx_v_alignment) { - Py_intptr_t __pyx_v_aligned_p; - size_t __pyx_v_offset; - void *__pyx_r; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7is_head_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7is_head_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_7is_head___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_7is_head___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations - int __pyx_t_1; - __Pyx_TraceCall("align_pointer", __pyx_f[1], 297, 1, __PYX_ERR(1, 297, __pyx_L1_error)); + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 3190, 0, __PYX_ERR(0, 3190, __pyx_L1_error)); - /* "View.MemoryView":299 - * cdef void *align_pointer(void *memory, size_t alignment) nogil: - * "Align pointer memory on a given boundary" - * cdef Py_intptr_t aligned_p = memory # <<<<<<<<<<<<<< - * cdef size_t offset + /* "pysam/libcalignedsegment.pyx":3191 + * """1 iff the base on the padded read is the left-most base.""" + * def __get__(self): + * return self._is_head # <<<<<<<<<<<<<< * + * property is_tail: */ - __pyx_v_aligned_p = ((Py_intptr_t)__pyx_v_memory); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_head); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "View.MemoryView":303 - * - * with cython.cdivision(True): - * offset = aligned_p % alignment # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":3190 + * property is_head: + * """1 iff the base on the padded read is the left-most base.""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._is_head * - * if offset > 0: */ - __pyx_v_offset = (__pyx_v_aligned_p % __pyx_v_alignment); - /* "View.MemoryView":305 - * offset = aligned_p % alignment - * - * if offset > 0: # <<<<<<<<<<<<<< - * aligned_p += alignment - offset - * - */ - __pyx_t_1 = ((__pyx_v_offset > 0) != 0); - if (__pyx_t_1) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.is_head.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":306 - * - * if offset > 0: - * aligned_p += alignment - offset # <<<<<<<<<<<<<< +/* "pysam/libcalignedsegment.pyx":3195 + * property is_tail: + * """1 iff the base on the padded read is the right-most base.""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._is_tail * - * return aligned_p */ - __pyx_v_aligned_p = (__pyx_v_aligned_p + (__pyx_v_alignment - __pyx_v_offset)); - /* "View.MemoryView":305 - * offset = aligned_p % alignment - * - * if offset > 0: # <<<<<<<<<<<<<< - * aligned_p += alignment - offset - * - */ - } +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7is_tail_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7is_tail_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_7is_tail___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); - /* "View.MemoryView":308 - * aligned_p += alignment - offset - * - * return aligned_p # <<<<<<<<<<<<<< - * + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_7is_tail___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 3195, 0, __PYX_ERR(0, 3195, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":3196 + * """1 iff the base on the padded read is the right-most base.""" + * def __get__(self): + * return self._is_tail # <<<<<<<<<<<<<< * + * property is_refskip: */ - __pyx_r = ((void *)__pyx_v_aligned_p); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_tail); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "View.MemoryView":297 + /* "pysam/libcalignedsegment.pyx":3195 + * property is_tail: + * """1 iff the base on the padded read is the right-most base.""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._is_tail * - * @cname('__pyx_align_pointer') - * cdef void *align_pointer(void *memory, size_t alignment) nogil: # <<<<<<<<<<<<<< - * "Align pointer memory on a given boundary" - * cdef Py_intptr_t aligned_p = memory */ /* function exit code */ __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.align_pointer", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.is_tail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":344 - * cdef __Pyx_TypeInfo *typeinfo +/* "pysam/libcalignedsegment.pyx":3200 + * property is_refskip: + * """1 iff the base on the padded read is part of CIGAR N op.""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._is_refskip * - * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): # <<<<<<<<<<<<<< - * self.obj = obj - * self.flags = flags */ /* Python wrapper */ -static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_obj = 0; - int __pyx_v_flags; - int __pyx_v_dtype_is_object; - int __pyx_r; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_10is_refskip_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_10is_refskip_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_obj,&__pyx_n_s_flags,&__pyx_n_s_dtype_is_object,0}; - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_10is_refskip___get__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_10is_refskip___get__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 3200, 0, __PYX_ERR(0, 3200, __pyx_L1_error)); + + /* "pysam/libcalignedsegment.pyx":3201 + * """1 iff the base on the padded read is part of CIGAR N op.""" + * def __get__(self): + * return self._is_refskip # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_refskip); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignedsegment.pyx":3200 + * property is_refskip: + * """1 iff the base on the padded read is part of CIGAR N op.""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self._is_refskip + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.is_refskip.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef bint use_setstate + * state = (self._alignment, self._indel, self._is_del, self._is_head, self._is_refskip, self._is_tail, self._level, self._qpos) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_10PileupRead_4__reduce_cython__[] = "PileupRead.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_4__reduce_cython__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_4__reduce_cython__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self) { + int __pyx_v_use_setstate; + PyObject *__pyx_v_state = NULL; + PyObject *__pyx_v__dict = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + int __pyx_t_10; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * cdef bint use_setstate + * state = (self._alignment, self._indel, self._is_del, self._is_head, self._is_refskip, self._is_tail, self._level, self._qpos) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_indel); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_del); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_head); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_refskip); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_tail); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->_level); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_qpos); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyTuple_New(8); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(((PyObject *)__pyx_v_self->_alignment)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->_alignment)); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_v_self->_alignment)); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_8, 6, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_8, 7, __pyx_t_7); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_6 = 0; + __pyx_t_7 = 0; + __pyx_v_state = ((PyObject*)__pyx_t_8); + __pyx_t_8 = 0; + + /* "(tree fragment)":4 + * cdef bint use_setstate + * state = (self._alignment, self._indel, self._is_del, self._is_head, self._is_refskip, self._is_tail, self._level, self._qpos) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_8 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_v__dict = __pyx_t_8; + __pyx_t_8 = 0; + + /* "(tree fragment)":5 + * state = (self._alignment, self._indel, self._is_del, self._is_head, self._is_refskip, self._is_tail, self._level, self._qpos) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_9 = (__pyx_v__dict != Py_None); + __pyx_t_10 = (__pyx_t_9 != 0); + if (__pyx_t_10) { + + /* "(tree fragment)":6 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v__dict); + __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_7)); + __pyx_t_7 = 0; + + /* "(tree fragment)":7 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self._alignment is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":5 + * state = (self._alignment, self._indel, self._is_del, self._is_head, self._is_refskip, self._is_tail, self._level, self._qpos) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":9 + * use_setstate = True + * else: + * use_setstate = self._alignment is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, None), state + */ + /*else*/ { + __pyx_t_10 = (((PyObject *)__pyx_v_self->_alignment) != Py_None); + __pyx_v_use_setstate = __pyx_t_10; + } + __pyx_L3:; + + /* "(tree fragment)":10 + * else: + * use_setstate = self._alignment is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, None), state + * else: + */ + __pyx_t_10 = (__pyx_v_use_setstate != 0); + if (__pyx_t_10) { + + /* "(tree fragment)":11 + * use_setstate = self._alignment is not None + * if use_setstate: + * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, state) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_PileupRead); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_196873109); + __Pyx_GIVEREF(__pyx_int_196873109); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_196873109); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_8, 2, Py_None); + __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_8); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_v_state); + __pyx_t_7 = 0; + __pyx_t_8 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L0; + + /* "(tree fragment)":10 + * else: + * use_setstate = self._alignment is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, None), state + * else: + */ + } + + /* "(tree fragment)":13 + * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, None), state + * else: + * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_PileupRead__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_PileupRead); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_196873109); + __Pyx_GIVEREF(__pyx_int_196873109); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_int_196873109); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_state); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8); + __pyx_t_6 = 0; + __pyx_t_8 = 0; + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef bint use_setstate + * state = (self._alignment, self._indel, self._is_del, self._is_head, self._is_refskip, self._is_tail, self._level, self._qpos) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":14 + * else: + * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_PileupRead__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_10PileupRead_6__setstate_cython__[] = "PileupRead.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_10PileupRead_6__setstate_cython__(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_10PileupRead_6__setstate_cython__(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + + /* "(tree fragment)":15 + * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_PileupRead__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_18libcalignedsegment___pyx_unpickle_PileupRead__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":14 + * else: + * return __pyx_unpickle_PileupRead, (type(self), 0xbbc0b95, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_PileupRead__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignedsegment.PileupRead.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0xbbc0b95: + * from pickle import PickleError as __pyx_PickleError + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_7__pyx_unpickle_PileupRead(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_18libcalignedsegment_6__pyx_unpickle_PileupRead[] = "__pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state)"; +static PyMethodDef __pyx_mdef_5pysam_18libcalignedsegment_7__pyx_unpickle_PileupRead = {"__pyx_unpickle_PileupRead", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_7__pyx_unpickle_PileupRead, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_6__pyx_unpickle_PileupRead}; +static PyObject *__pyx_pw_5pysam_18libcalignedsegment_7__pyx_unpickle_PileupRead(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_PileupRead (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { @@ -33222,2238 +37563,1811 @@ static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_ar kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_obj)) != 0)) kw_args--; + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flags)) != 0)) kw_args--; + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); __PYX_ERR(1, 344, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PileupRead", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dtype_is_object); - if (value) { values[2] = value; kw_args--; } + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PileupRead", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 344, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_PileupRead") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) } - } - __pyx_v_obj = values[0]; - __pyx_v_flags = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 344, __pyx_L3_error) - if (values[2]) { - __pyx_v_dtype_is_object = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_dtype_is_object == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 344, __pyx_L3_error) + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; } else { - __pyx_v_dtype_is_object = ((int)0); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 344, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PileupRead", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignedsegment.__pyx_unpickle_PileupRead", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); - return -1; + return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_obj, __pyx_v_flags, __pyx_v_dtype_is_object); + __pyx_r = __pyx_pf_5pysam_18libcalignedsegment_6__pyx_unpickle_PileupRead(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_18libcalignedsegment_6__pyx_unpickle_PileupRead(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = NULL; + PyObject *__pyx_v___pyx_result = NULL; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[1], 344, 0, __PYX_ERR(1, 344, __pyx_L1_error)); - - /* "View.MemoryView":345 - * - * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): - * self.obj = obj # <<<<<<<<<<<<<< - * self.flags = flags - * if type(self) is memoryview or obj is not None: - */ - __Pyx_INCREF(__pyx_v_obj); - __Pyx_GIVEREF(__pyx_v_obj); - __Pyx_GOTREF(__pyx_v_self->obj); - __Pyx_DECREF(__pyx_v_self->obj); - __pyx_v_self->obj = __pyx_v_obj; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + __Pyx_TraceFrameInit(__pyx_codeobj__49) + __Pyx_RefNannySetupContext("__pyx_unpickle_PileupRead", 0); + __Pyx_TraceCall("__pyx_unpickle_PileupRead", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); - /* "View.MemoryView":346 - * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): - * self.obj = obj - * self.flags = flags # <<<<<<<<<<<<<< - * if type(self) is memoryview or obj is not None: - * __Pyx_GetBuffer(obj, &self.view, flags) + /* "(tree fragment)":2 + * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): + * if __pyx_checksum != 0xbbc0b95: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) */ - __pyx_v_self->flags = __pyx_v_flags; + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xbbc0b95) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":347 - * self.obj = obj - * self.flags = flags - * if type(self) is memoryview or obj is not None: # <<<<<<<<<<<<<< - * __Pyx_GetBuffer(obj, &self.view, flags) - * if self.view.obj == NULL: + /* "(tree fragment)":3 + * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): + * if __pyx_checksum != 0xbbc0b95: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) + * __pyx_result = PileupRead.__new__(__pyx_type) */ - __pyx_t_2 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_memoryview_type)); - __pyx_t_3 = (__pyx_t_2 != 0); - if (!__pyx_t_3) { - } else { - __pyx_t_1 = __pyx_t_3; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_3 = (__pyx_v_obj != Py_None); - __pyx_t_2 = (__pyx_t_3 != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L4_bool_binop_done:; - if (__pyx_t_1) { - - /* "View.MemoryView":348 - * self.flags = flags - * if type(self) is memoryview or obj is not None: - * __Pyx_GetBuffer(obj, &self.view, flags) # <<<<<<<<<<<<<< - * if self.view.obj == NULL: - * (<__pyx_buffer *> &self.view).obj = Py_None - */ - __pyx_t_4 = __Pyx_GetBuffer(__pyx_v_obj, (&__pyx_v_self->view), __pyx_v_flags); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 348, __pyx_L1_error) - - /* "View.MemoryView":349 - * if type(self) is memoryview or obj is not None: - * __Pyx_GetBuffer(obj, &self.view, flags) - * if self.view.obj == NULL: # <<<<<<<<<<<<<< - * (<__pyx_buffer *> &self.view).obj = Py_None - * Py_INCREF(Py_None) - */ - __pyx_t_1 = ((((PyObject *)__pyx_v_self->view.obj) == NULL) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":350 - * __Pyx_GetBuffer(obj, &self.view, flags) - * if self.view.obj == NULL: - * (<__pyx_buffer *> &self.view).obj = Py_None # <<<<<<<<<<<<<< - * Py_INCREF(Py_None) - * - */ - ((Py_buffer *)(&__pyx_v_self->view))->obj = Py_None; - - /* "View.MemoryView":351 - * if self.view.obj == NULL: - * (<__pyx_buffer *> &self.view).obj = Py_None - * Py_INCREF(Py_None) # <<<<<<<<<<<<<< - * - * global __pyx_memoryview_thread_locks_used - */ - Py_INCREF(Py_None); + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "View.MemoryView":349 - * if type(self) is memoryview or obj is not None: - * __Pyx_GetBuffer(obj, &self.view, flags) - * if self.view.obj == NULL: # <<<<<<<<<<<<<< - * (<__pyx_buffer *> &self.view).obj = Py_None - * Py_INCREF(Py_None) + /* "(tree fragment)":4 + * if __pyx_checksum != 0xbbc0b95: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = PileupRead.__new__(__pyx_type) + * if __pyx_state is not None: */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xbb, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_5) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) - /* "View.MemoryView":347 - * self.obj = obj - * self.flags = flags - * if type(self) is memoryview or obj is not None: # <<<<<<<<<<<<<< - * __Pyx_GetBuffer(obj, &self.view, flags) - * if self.view.obj == NULL: + /* "(tree fragment)":2 + * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): + * if __pyx_checksum != 0xbbc0b95: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) */ } - /* "View.MemoryView":354 - * - * global __pyx_memoryview_thread_locks_used - * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: # <<<<<<<<<<<<<< - * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] - * __pyx_memoryview_thread_locks_used += 1 - */ - __pyx_t_1 = ((__pyx_memoryview_thread_locks_used < 8) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":355 - * global __pyx_memoryview_thread_locks_used - * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: - * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] # <<<<<<<<<<<<<< - * __pyx_memoryview_thread_locks_used += 1 - * if self.lock is NULL: - */ - __pyx_v_self->lock = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]); - - /* "View.MemoryView":356 - * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: - * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] - * __pyx_memoryview_thread_locks_used += 1 # <<<<<<<<<<<<<< - * if self.lock is NULL: - * self.lock = PyThread_allocate_lock() - */ - __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used + 1); - - /* "View.MemoryView":354 - * - * global __pyx_memoryview_thread_locks_used - * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: # <<<<<<<<<<<<<< - * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] - * __pyx_memoryview_thread_locks_used += 1 + /* "(tree fragment)":5 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) + * __pyx_result = PileupRead.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_18libcalignedsegment_PileupRead), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } } - - /* "View.MemoryView":357 - * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] - * __pyx_memoryview_thread_locks_used += 1 - * if self.lock is NULL: # <<<<<<<<<<<<<< - * self.lock = PyThread_allocate_lock() - * if self.lock is NULL: - */ - __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":358 - * __pyx_memoryview_thread_locks_used += 1 - * if self.lock is NULL: - * self.lock = PyThread_allocate_lock() # <<<<<<<<<<<<<< - * if self.lock is NULL: - * raise MemoryError - */ - __pyx_v_self->lock = PyThread_allocate_lock(); - - /* "View.MemoryView":359 - * if self.lock is NULL: - * self.lock = PyThread_allocate_lock() - * if self.lock is NULL: # <<<<<<<<<<<<<< - * raise MemoryError - * - */ - __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0); - if (unlikely(__pyx_t_1)) { - - /* "View.MemoryView":360 - * self.lock = PyThread_allocate_lock() - * if self.lock is NULL: - * raise MemoryError # <<<<<<<<<<<<<< - * - * if flags & PyBUF_FORMAT: - */ - PyErr_NoMemory(); __PYX_ERR(1, 360, __pyx_L1_error) - - /* "View.MemoryView":359 - * if self.lock is NULL: - * self.lock = PyThread_allocate_lock() - * if self.lock is NULL: # <<<<<<<<<<<<<< - * raise MemoryError - * - */ + if (!__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_INCREF(__pyx_v___pyx_type); + __Pyx_GIVEREF(__pyx_v___pyx_type); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - - /* "View.MemoryView":357 - * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] - * __pyx_memoryview_thread_locks_used += 1 - * if self.lock is NULL: # <<<<<<<<<<<<<< - * self.lock = PyThread_allocate_lock() - * if self.lock is NULL: - */ } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; - /* "View.MemoryView":362 - * raise MemoryError - * - * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< - * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') - * else: - */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":363 - * - * if flags & PyBUF_FORMAT: - * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') # <<<<<<<<<<<<<< - * else: - * self.dtype_is_object = dtype_is_object + /* "(tree fragment)":6 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) + * __pyx_result = PileupRead.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) + * return __pyx_result */ - __pyx_t_2 = (((__pyx_v_self->view.format[0]) == 'O') != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L11_bool_binop_done; - } - __pyx_t_2 = (((__pyx_v_self->view.format[1]) == '\x00') != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L11_bool_binop_done:; - __pyx_v_self->dtype_is_object = __pyx_t_1; + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_7 = (__pyx_t_1 != 0); + if (__pyx_t_7) { - /* "View.MemoryView":362 - * raise MemoryError - * - * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< - * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') - * else: + /* "(tree fragment)":7 + * __pyx_result = PileupRead.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): */ - goto __pyx_L10; - } + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment___pyx_unpickle_PileupRead__set_state(((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "View.MemoryView":365 - * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') - * else: - * self.dtype_is_object = dtype_is_object # <<<<<<<<<<<<<< - * - * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( + /* "(tree fragment)":6 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbbc0b95 = (_alignment, _indel, _is_del, _is_head, _is_refskip, _is_tail, _level, _qpos))" % __pyx_checksum) + * __pyx_result = PileupRead.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) + * return __pyx_result */ - /*else*/ { - __pyx_v_self->dtype_is_object = __pyx_v_dtype_is_object; } - __pyx_L10:; - - /* "View.MemoryView":367 - * self.dtype_is_object = dtype_is_object - * - * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( # <<<<<<<<<<<<<< - * &self.acquisition_count[0], sizeof(__pyx_atomic_int)) - * self.typeinfo = NULL - */ - __pyx_v_self->acquisition_count_aligned_p = ((__pyx_atomic_int *)__pyx_align_pointer(((void *)(&(__pyx_v_self->acquisition_count[0]))), (sizeof(__pyx_atomic_int)))); - /* "View.MemoryView":369 - * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( - * &self.acquisition_count[0], sizeof(__pyx_atomic_int)) - * self.typeinfo = NULL # <<<<<<<<<<<<<< - * - * def __dealloc__(memoryview self): + /* "(tree fragment)":8 + * if __pyx_state is not None: + * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): + * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] */ - __pyx_v_self->typeinfo = NULL; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; - /* "View.MemoryView":344 - * cdef __Pyx_TypeInfo *typeinfo - * - * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): # <<<<<<<<<<<<<< - * self.obj = obj - * self.flags = flags + /* "(tree fragment)":1 + * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0xbbc0b95: + * from pickle import PickleError as __pyx_PickleError */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcalignedsegment.__pyx_unpickle_PileupRead", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":371 - * self.typeinfo = NULL - * - * def __dealloc__(memoryview self): # <<<<<<<<<<<<<< - * if self.obj is not None: - * __Pyx_ReleaseBuffer(&self.view) +/* "(tree fragment)":9 + * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] + * if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'): */ -/* Python wrapper */ -static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -static void __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self) { - int __pyx_v_i; +static PyObject *__pyx_f_5pysam_18libcalignedsegment___pyx_unpickle_PileupRead__set_state(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; + PyObject *__pyx_t_1 = NULL; int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; + uint32_t __pyx_t_3; + int32_t __pyx_t_4; int __pyx_t_5; - PyThread_type_lock __pyx_t_6; - PyThread_type_lock __pyx_t_7; - __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[1], 371, 0, __PYX_ERR(1, 371, __pyx_L1_error)); - - /* "View.MemoryView":372 - * - * def __dealloc__(memoryview self): - * if self.obj is not None: # <<<<<<<<<<<<<< - * __Pyx_ReleaseBuffer(&self.view) - * - */ - __pyx_t_1 = (__pyx_v_self->obj != Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":373 - * def __dealloc__(memoryview self): - * if self.obj is not None: - * __Pyx_ReleaseBuffer(&self.view) # <<<<<<<<<<<<<< - * - * cdef int i - */ - __Pyx_ReleaseBuffer((&__pyx_v_self->view)); + Py_ssize_t __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + __Pyx_RefNannySetupContext("__pyx_unpickle_PileupRead__set_state", 0); + __Pyx_TraceCall("__pyx_unpickle_PileupRead__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); - /* "View.MemoryView":372 - * - * def __dealloc__(memoryview self): - * if self.obj is not None: # <<<<<<<<<<<<<< - * __Pyx_ReleaseBuffer(&self.view) - * + /* "(tree fragment)":10 + * return __pyx_result + * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): + * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[8]) */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 10, __pyx_L1_error) } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->_alignment); + __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->_alignment)); + __pyx_v___pyx_result->_alignment = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 10, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->_indel = __pyx_t_2; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 10, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_3 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->_is_del = __pyx_t_3; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 10, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_3 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->_is_head = __pyx_t_3; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 10, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_3 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->_is_refskip = __pyx_t_3; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 10, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_3 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->_is_tail = __pyx_t_3; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 10, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 6, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->_level = __pyx_t_2; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 10, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 7, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_4 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->_qpos = __pyx_t_4; - /* "View.MemoryView":377 - * cdef int i - * global __pyx_memoryview_thread_locks_used - * if self.lock != NULL: # <<<<<<<<<<<<<< - * for i in range(__pyx_memoryview_thread_locks_used): - * if __pyx_memoryview_thread_locks[i] is self.lock: - */ - __pyx_t_2 = ((__pyx_v_self->lock != NULL) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":378 - * global __pyx_memoryview_thread_locks_used - * if self.lock != NULL: - * for i in range(__pyx_memoryview_thread_locks_used): # <<<<<<<<<<<<<< - * if __pyx_memoryview_thread_locks[i] is self.lock: - * __pyx_memoryview_thread_locks_used -= 1 - */ - __pyx_t_3 = __pyx_memoryview_thread_locks_used; - __pyx_t_4 = __pyx_t_3; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_i = __pyx_t_5; - - /* "View.MemoryView":379 - * if self.lock != NULL: - * for i in range(__pyx_memoryview_thread_locks_used): - * if __pyx_memoryview_thread_locks[i] is self.lock: # <<<<<<<<<<<<<< - * __pyx_memoryview_thread_locks_used -= 1 - * if i != __pyx_memoryview_thread_locks_used: - */ - __pyx_t_2 = (((__pyx_memoryview_thread_locks[__pyx_v_i]) == __pyx_v_self->lock) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":380 - * for i in range(__pyx_memoryview_thread_locks_used): - * if __pyx_memoryview_thread_locks[i] is self.lock: - * __pyx_memoryview_thread_locks_used -= 1 # <<<<<<<<<<<<<< - * if i != __pyx_memoryview_thread_locks_used: - * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( - */ - __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used - 1); - - /* "View.MemoryView":381 - * if __pyx_memoryview_thread_locks[i] is self.lock: - * __pyx_memoryview_thread_locks_used -= 1 - * if i != __pyx_memoryview_thread_locks_used: # <<<<<<<<<<<<<< - * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( - * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) - */ - __pyx_t_2 = ((__pyx_v_i != __pyx_memoryview_thread_locks_used) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":383 - * if i != __pyx_memoryview_thread_locks_used: - * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( - * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) # <<<<<<<<<<<<<< - * break - * else: - */ - __pyx_t_6 = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]); - __pyx_t_7 = (__pyx_memoryview_thread_locks[__pyx_v_i]); - - /* "View.MemoryView":382 - * __pyx_memoryview_thread_locks_used -= 1 - * if i != __pyx_memoryview_thread_locks_used: - * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( # <<<<<<<<<<<<<< - * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) - * break - */ - (__pyx_memoryview_thread_locks[__pyx_v_i]) = __pyx_t_6; - (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]) = __pyx_t_7; - - /* "View.MemoryView":381 - * if __pyx_memoryview_thread_locks[i] is self.lock: - * __pyx_memoryview_thread_locks_used -= 1 - * if i != __pyx_memoryview_thread_locks_used: # <<<<<<<<<<<<<< - * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( - * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) - */ - } - - /* "View.MemoryView":384 - * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( - * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) - * break # <<<<<<<<<<<<<< - * else: - * PyThread_free_lock(self.lock) + /* "(tree fragment)":11 + * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): + * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] + * if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[8]) */ - goto __pyx_L6_break; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(1, 11, __pyx_L1_error) + } + __pyx_t_6 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_7 = ((__pyx_t_6 > 8) != 0); + if (__pyx_t_7) { + } else { + __pyx_t_5 = __pyx_t_7; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_7 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_8 = (__pyx_t_7 != 0); + __pyx_t_5 = __pyx_t_8; + __pyx_L4_bool_binop_done:; + if (__pyx_t_5) { - /* "View.MemoryView":379 - * if self.lock != NULL: - * for i in range(__pyx_memoryview_thread_locks_used): - * if __pyx_memoryview_thread_locks[i] is self.lock: # <<<<<<<<<<<<<< - * __pyx_memoryview_thread_locks_used -= 1 - * if i != __pyx_memoryview_thread_locks_used: + /* "(tree fragment)":12 + * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] + * if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[8]) # <<<<<<<<<<<<<< */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_update); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_9 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 8, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); } } - /*else*/ { - - /* "View.MemoryView":386 - * break - * else: - * PyThread_free_lock(self.lock) # <<<<<<<<<<<<<< - * - * cdef char *get_item_pointer(memoryview self, object index) except NULL: - */ - PyThread_free_lock(__pyx_v_self->lock); + if (!__pyx_t_11) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_10)) { + PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_t_9}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { + PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_t_9}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } } - __pyx_L6_break:; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "View.MemoryView":377 - * cdef int i - * global __pyx_memoryview_thread_locks_used - * if self.lock != NULL: # <<<<<<<<<<<<<< - * for i in range(__pyx_memoryview_thread_locks_used): - * if __pyx_memoryview_thread_locks[i] is self.lock: + /* "(tree fragment)":11 + * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): + * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] + * if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[8]) */ } - /* "View.MemoryView":371 - * self.typeinfo = NULL - * - * def __dealloc__(memoryview self): # <<<<<<<<<<<<<< - * if self.obj is not None: - * __Pyx_ReleaseBuffer(&self.view) + /* "(tree fragment)":9 + * __pyx_unpickle_PileupRead__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_PileupRead__set_state(PileupRead __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result._alignment = __pyx_state[0]; __pyx_result._indel = __pyx_state[1]; __pyx_result._is_del = __pyx_state[2]; __pyx_result._is_head = __pyx_state[3]; __pyx_result._is_refskip = __pyx_state[4]; __pyx_result._is_tail = __pyx_state[5]; __pyx_result._level = __pyx_state[6]; __pyx_result._qpos = __pyx_state[7] + * if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'): */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.memoryview.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("pysam.libcalignedsegment.__pyx_unpickle_PileupRead__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "View.MemoryView":388 - * PyThread_free_lock(self.lock) +/* "array.pxd":93 + * __data_union data * - * cdef char *get_item_pointer(memoryview self, object index) except NULL: # <<<<<<<<<<<<<< - * cdef Py_ssize_t dim - * cdef char *itemp = self.view.buf + * def __getbuffer__(self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< + * # This implementation of getbuffer is geared towards Cython + * # requirements, and does not yet fulfill the PEP. */ -static char *__pyx_memoryview_get_item_pointer(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) { - Py_ssize_t __pyx_v_dim; - char *__pyx_v_itemp; - PyObject *__pyx_v_idx = NULL; - char *__pyx_r; +/* Python wrapper */ +static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ +static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0); + __pyx_r = __pyx_pf_7cpython_5array_5array___getbuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags) { + PyObject *__pyx_v_item_count = NULL; + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - PyObject *(*__pyx_t_4)(PyObject *); - PyObject *__pyx_t_5 = NULL; - Py_ssize_t __pyx_t_6; - char *__pyx_t_7; - __Pyx_RefNannySetupContext("get_item_pointer", 0); - __Pyx_TraceCall("get_item_pointer", __pyx_f[1], 388, 0, __PYX_ERR(1, 388, __pyx_L1_error)); + PyObject *__pyx_t_1 = NULL; + char *__pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + int __pyx_t_6; + if (__pyx_v_info == NULL) { + PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete"); + return -1; + } + __Pyx_RefNannySetupContext("__getbuffer__", 0); + __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(__pyx_v_info->obj); + __Pyx_TraceCall("__getbuffer__", __pyx_f[3], 93, 0, __PYX_ERR(3, 93, __pyx_L1_error)); - /* "View.MemoryView":390 - * cdef char *get_item_pointer(memoryview self, object index) except NULL: - * cdef Py_ssize_t dim - * cdef char *itemp = self.view.buf # <<<<<<<<<<<<<< + /* "array.pxd":98 + * # In particular strided access is always provided regardless + * # of flags + * item_count = Py_SIZE(self) # <<<<<<<<<<<<<< * - * for dim, idx in enumerate(index): + * info.suboffsets = NULL */ - __pyx_v_itemp = ((char *)__pyx_v_self->view.buf); + __pyx_t_1 = PyInt_FromSsize_t(Py_SIZE(((PyObject *)__pyx_v_self))); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 98, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_item_count = __pyx_t_1; + __pyx_t_1 = 0; - /* "View.MemoryView":392 - * cdef char *itemp = self.view.buf - * - * for dim, idx in enumerate(index): # <<<<<<<<<<<<<< - * itemp = pybuffer_index(&self.view, itemp, idx, dim) + /* "array.pxd":100 + * item_count = Py_SIZE(self) * + * info.suboffsets = NULL # <<<<<<<<<<<<<< + * info.buf = self.data.as_chars + * info.readonly = 0 */ - __pyx_t_1 = 0; - if (likely(PyList_CheckExact(__pyx_v_index)) || PyTuple_CheckExact(__pyx_v_index)) { - __pyx_t_2 = __pyx_v_index; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 392, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(1, 392, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(1, 392, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 392, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } - } else { - __pyx_t_5 = __pyx_t_4(__pyx_t_2); - if (unlikely(!__pyx_t_5)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(1, 392, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_v_dim = __pyx_t_1; - __pyx_t_1 = (__pyx_t_1 + 1); + __pyx_v_info->suboffsets = NULL; - /* "View.MemoryView":393 - * - * for dim, idx in enumerate(index): - * itemp = pybuffer_index(&self.view, itemp, idx, dim) # <<<<<<<<<<<<<< + /* "array.pxd":101 * - * return itemp + * info.suboffsets = NULL + * info.buf = self.data.as_chars # <<<<<<<<<<<<<< + * info.readonly = 0 + * info.ndim = 1 */ - __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 393, __pyx_L1_error) - __pyx_t_7 = __pyx_pybuffer_index((&__pyx_v_self->view), __pyx_v_itemp, __pyx_t_6, __pyx_v_dim); if (unlikely(__pyx_t_7 == ((char *)NULL))) __PYX_ERR(1, 393, __pyx_L1_error) - __pyx_v_itemp = __pyx_t_7; + __pyx_t_2 = __pyx_v_self->data.as_chars; + __pyx_v_info->buf = __pyx_t_2; - /* "View.MemoryView":392 - * cdef char *itemp = self.view.buf - * - * for dim, idx in enumerate(index): # <<<<<<<<<<<<<< - * itemp = pybuffer_index(&self.view, itemp, idx, dim) - * + /* "array.pxd":102 + * info.suboffsets = NULL + * info.buf = self.data.as_chars + * info.readonly = 0 # <<<<<<<<<<<<<< + * info.ndim = 1 + * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) */ - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_info->readonly = 0; - /* "View.MemoryView":395 - * itemp = pybuffer_index(&self.view, itemp, idx, dim) + /* "array.pxd":103 + * info.buf = self.data.as_chars + * info.readonly = 0 + * info.ndim = 1 # <<<<<<<<<<<<<< + * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) + * info.len = info.itemsize * item_count + */ + __pyx_v_info->ndim = 1; + + /* "array.pxd":104 + * info.readonly = 0 + * info.ndim = 1 + * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) # <<<<<<<<<<<<<< + * info.len = info.itemsize * item_count * - * return itemp # <<<<<<<<<<<<<< + */ + __pyx_t_3 = __pyx_v_self->ob_descr->itemsize; + __pyx_v_info->itemsize = __pyx_t_3; + + /* "array.pxd":105 + * info.ndim = 1 + * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) + * info.len = info.itemsize * item_count # <<<<<<<<<<<<<< * + * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) + */ + __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_info->itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 105, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyNumber_Multiply(__pyx_t_1, __pyx_v_item_count); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 105, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(3, 105, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_info->len = __pyx_t_5; + + /* "array.pxd":107 + * info.len = info.itemsize * item_count * + * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) # <<<<<<<<<<<<<< + * if not info.shape: + * raise MemoryError() */ - __pyx_r = __pyx_v_itemp; - goto __pyx_L0; + __pyx_v_info->shape = ((Py_ssize_t *)PyObject_Malloc(((sizeof(Py_ssize_t)) + 2))); - /* "View.MemoryView":388 - * PyThread_free_lock(self.lock) + /* "array.pxd":108 * - * cdef char *get_item_pointer(memoryview self, object index) except NULL: # <<<<<<<<<<<<<< - * cdef Py_ssize_t dim - * cdef char *itemp = self.view.buf + * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) + * if not info.shape: # <<<<<<<<<<<<<< + * raise MemoryError() + * info.shape[0] = item_count # constant regardless of resizing */ + __pyx_t_6 = ((!(__pyx_v_info->shape != 0)) != 0); + if (unlikely(__pyx_t_6)) { - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.memoryview.get_item_pointer", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_idx); - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "array.pxd":109 + * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) + * if not info.shape: + * raise MemoryError() # <<<<<<<<<<<<<< + * info.shape[0] = item_count # constant regardless of resizing + * info.strides = &info.itemsize + */ + PyErr_NoMemory(); __PYX_ERR(3, 109, __pyx_L1_error) -/* "View.MemoryView":398 - * + /* "array.pxd":108 * - * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<< - * if index is Ellipsis: - * return self + * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) + * if not info.shape: # <<<<<<<<<<<<<< + * raise MemoryError() + * info.shape[0] = item_count # constant regardless of resizing */ + } -/* Python wrapper */ -static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index); /*proto*/ -static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "array.pxd":110 + * if not info.shape: + * raise MemoryError() + * info.shape[0] = item_count # constant regardless of resizing # <<<<<<<<<<<<<< + * info.strides = &info.itemsize + * + */ + __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_item_count); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(3, 110, __pyx_L1_error) + (__pyx_v_info->shape[0]) = __pyx_t_5; -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) { - PyObject *__pyx_v_have_slices = NULL; - PyObject *__pyx_v_indices = NULL; - char *__pyx_v_itemp; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - char *__pyx_t_6; - __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[1], 398, 0, __PYX_ERR(1, 398, __pyx_L1_error)); - - /* "View.MemoryView":399 - * - * def __getitem__(memoryview self, object index): - * if index is Ellipsis: # <<<<<<<<<<<<<< - * return self - * - */ - __pyx_t_1 = (__pyx_v_index == __pyx_builtin_Ellipsis); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":400 - * def __getitem__(memoryview self, object index): - * if index is Ellipsis: - * return self # <<<<<<<<<<<<<< - * - * have_slices, indices = _unellipsify(index, self.view.ndim) - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __pyx_r = ((PyObject *)__pyx_v_self); - goto __pyx_L0; - - /* "View.MemoryView":399 - * - * def __getitem__(memoryview self, object index): - * if index is Ellipsis: # <<<<<<<<<<<<<< - * return self - * - */ - } - - /* "View.MemoryView":402 - * return self - * - * have_slices, indices = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<< + /* "array.pxd":111 + * raise MemoryError() + * info.shape[0] = item_count # constant regardless of resizing + * info.strides = &info.itemsize # <<<<<<<<<<<<<< * - * cdef char *itemp + * info.format = (info.shape + 1) */ - __pyx_t_3 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (likely(__pyx_t_3 != Py_None)) { - PyObject* sequence = __pyx_t_3; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(1, 402, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - #else - __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(1, 402, __pyx_L1_error) - } - __pyx_v_have_slices = __pyx_t_4; - __pyx_t_4 = 0; - __pyx_v_indices = __pyx_t_5; - __pyx_t_5 = 0; + __pyx_v_info->strides = (&__pyx_v_info->itemsize); - /* "View.MemoryView":405 + /* "array.pxd":113 + * info.strides = &info.itemsize * - * cdef char *itemp - * if have_slices: # <<<<<<<<<<<<<< - * return memview_slice(self, indices) - * else: - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 405, __pyx_L1_error) - if (__pyx_t_2) { - - /* "View.MemoryView":406 - * cdef char *itemp - * if have_slices: - * return memview_slice(self, indices) # <<<<<<<<<<<<<< - * else: - * itemp = self.get_item_pointer(indices) + * info.format = (info.shape + 1) # <<<<<<<<<<<<<< + * info.format[0] = self.ob_descr.typecode + * info.format[1] = 0 */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = ((PyObject *)__pyx_memview_slice(__pyx_v_self, __pyx_v_indices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 406, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __pyx_v_info->format = ((char *)(__pyx_v_info->shape + 1)); - /* "View.MemoryView":405 + /* "array.pxd":114 * - * cdef char *itemp - * if have_slices: # <<<<<<<<<<<<<< - * return memview_slice(self, indices) - * else: + * info.format = (info.shape + 1) + * info.format[0] = self.ob_descr.typecode # <<<<<<<<<<<<<< + * info.format[1] = 0 + * info.obj = self */ - } + __pyx_t_3 = __pyx_v_self->ob_descr->typecode; + (__pyx_v_info->format[0]) = __pyx_t_3; - /* "View.MemoryView":408 - * return memview_slice(self, indices) - * else: - * itemp = self.get_item_pointer(indices) # <<<<<<<<<<<<<< - * return self.convert_item_to_object(itemp) + /* "array.pxd":115 + * info.format = (info.shape + 1) + * info.format[0] = self.ob_descr.typecode + * info.format[1] = 0 # <<<<<<<<<<<<<< + * info.obj = self * */ - /*else*/ { - __pyx_t_6 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_indices); if (unlikely(__pyx_t_6 == ((char *)NULL))) __PYX_ERR(1, 408, __pyx_L1_error) - __pyx_v_itemp = __pyx_t_6; + (__pyx_v_info->format[1]) = 0; - /* "View.MemoryView":409 - * else: - * itemp = self.get_item_pointer(indices) - * return self.convert_item_to_object(itemp) # <<<<<<<<<<<<<< + /* "array.pxd":116 + * info.format[0] = self.ob_descr.typecode + * info.format[1] = 0 + * info.obj = self # <<<<<<<<<<<<<< * - * def __setitem__(memoryview self, object index, object value): + * def __releasebuffer__(self, Py_buffer* info): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->convert_item_to_object(__pyx_v_self, __pyx_v_itemp); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 409, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - } + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); + __pyx_v_info->obj = ((PyObject *)__pyx_v_self); - /* "View.MemoryView":398 - * + /* "array.pxd":93 + * __data_union data * - * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<< - * if index is Ellipsis: - * return self + * def __getbuffer__(self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< + * # This implementation of getbuffer is geared towards Cython + * # requirements, and does not yet fulfill the PEP. */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.memoryview.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("cpython.array.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + if (__pyx_v_info->obj != NULL) { + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; + } + goto __pyx_L2; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_have_slices); - __Pyx_XDECREF(__pyx_v_indices); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + if (__pyx_v_info->obj == Py_None) { + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; + } + __pyx_L2:; + __Pyx_XDECREF(__pyx_v_item_count); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":411 - * return self.convert_item_to_object(itemp) +/* "array.pxd":118 + * info.obj = self + * + * def __releasebuffer__(self, Py_buffer* info): # <<<<<<<<<<<<<< + * PyObject_Free(info.shape) * - * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<< - * if self.view.readonly: - * raise TypeError("Cannot assign to read-only memoryview") */ /* Python wrapper */ -static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) { - int __pyx_r; +static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/ +static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) { __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0); + __pyx_pf_7cpython_5array_5array_2__releasebuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info)); /* function exit code */ __Pyx_RefNannyFinishContext(); - return __pyx_r; } -static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) { - PyObject *__pyx_v_have_slices = NULL; - PyObject *__pyx_v_obj = NULL; - int __pyx_r; +static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info) { __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannySetupContext("__setitem__", 0); - __Pyx_TraceCall("__setitem__", __pyx_f[1], 411, 0, __PYX_ERR(1, 411, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_index); + __Pyx_RefNannySetupContext("__releasebuffer__", 0); + __Pyx_TraceCall("__releasebuffer__", __pyx_f[3], 118, 0, __PYX_ERR(3, 118, __pyx_L1_error)); - /* "View.MemoryView":412 - * - * def __setitem__(memoryview self, object index, object value): - * if self.view.readonly: # <<<<<<<<<<<<<< - * raise TypeError("Cannot assign to read-only memoryview") + /* "array.pxd":119 * - */ - __pyx_t_1 = (__pyx_v_self->view.readonly != 0); - if (unlikely(__pyx_t_1)) { - - /* "View.MemoryView":413 - * def __setitem__(memoryview self, object index, object value): - * if self.view.readonly: - * raise TypeError("Cannot assign to read-only memoryview") # <<<<<<<<<<<<<< + * def __releasebuffer__(self, Py_buffer* info): + * PyObject_Free(info.shape) # <<<<<<<<<<<<<< * - * have_slices, index = _unellipsify(index, self.view.ndim) + * array newarrayobject(PyTypeObject* type, Py_ssize_t size, arraydescr *descr) */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 413, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(1, 413, __pyx_L1_error) + PyObject_Free(__pyx_v_info->shape); - /* "View.MemoryView":412 + /* "array.pxd":118 + * info.obj = self * - * def __setitem__(memoryview self, object index, object value): - * if self.view.readonly: # <<<<<<<<<<<<<< - * raise TypeError("Cannot assign to read-only memoryview") + * def __releasebuffer__(self, Py_buffer* info): # <<<<<<<<<<<<<< + * PyObject_Free(info.shape) * */ - } - /* "View.MemoryView":415 - * raise TypeError("Cannot assign to read-only memoryview") - * - * have_slices, index = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<< - * - * if have_slices: - */ - __pyx_t_2 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 415, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (likely(__pyx_t_2 != Py_None)) { - PyObject* sequence = __pyx_t_2; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(1, 415, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 415, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 415, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(1, 415, __pyx_L1_error) - } - __pyx_v_have_slices = __pyx_t_3; - __pyx_t_3 = 0; - __Pyx_DECREF_SET(__pyx_v_index, __pyx_t_4); - __pyx_t_4 = 0; + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("cpython.array.array.__releasebuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); +} - /* "View.MemoryView":417 - * have_slices, index = _unellipsify(index, self.view.ndim) +/* "array.pxd":130 * - * if have_slices: # <<<<<<<<<<<<<< - * obj = self.is_slice(value) - * if obj: - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 417, __pyx_L1_error) - if (__pyx_t_1) { - - /* "View.MemoryView":418 * - * if have_slices: - * obj = self.is_slice(value) # <<<<<<<<<<<<<< - * if obj: - * self.setitem_slice_assignment(self[index], obj) + * cdef inline array clone(array template, Py_ssize_t length, bint zero): # <<<<<<<<<<<<<< + * """ fast creation of a new array, given a template array. + * type will be same as template. */ - __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->is_slice(__pyx_v_self, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 418, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_obj = __pyx_t_2; - __pyx_t_2 = 0; - /* "View.MemoryView":419 - * if have_slices: - * obj = self.is_slice(value) - * if obj: # <<<<<<<<<<<<<< - * self.setitem_slice_assignment(self[index], obj) - * else: - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_obj); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 419, __pyx_L1_error) - if (__pyx_t_1) { +static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_clone(arrayobject *__pyx_v_template, Py_ssize_t __pyx_v_length, int __pyx_v_zero) { + arrayobject *__pyx_v_op = NULL; + arrayobject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("clone", 0); + __Pyx_TraceCall("clone", __pyx_f[3], 130, 0, __PYX_ERR(3, 130, __pyx_L1_error)); - /* "View.MemoryView":420 - * obj = self.is_slice(value) - * if obj: - * self.setitem_slice_assignment(self[index], obj) # <<<<<<<<<<<<<< - * else: - * self.setitem_slice_assign_scalar(self[index], value) + /* "array.pxd":134 + * type will be same as template. + * if zero is true, new array will be initialized with zeroes.""" + * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) # <<<<<<<<<<<<<< + * if zero and op is not None: + * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) */ - __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assignment(__pyx_v_self, __pyx_t_2, __pyx_v_obj); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_template)), __pyx_v_length, __pyx_v_template->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_op = ((arrayobject *)__pyx_t_1); + __pyx_t_1 = 0; - /* "View.MemoryView":419 - * if have_slices: - * obj = self.is_slice(value) - * if obj: # <<<<<<<<<<<<<< - * self.setitem_slice_assignment(self[index], obj) - * else: + /* "array.pxd":135 + * if zero is true, new array will be initialized with zeroes.""" + * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) + * if zero and op is not None: # <<<<<<<<<<<<<< + * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) + * return op */ - goto __pyx_L5; - } + __pyx_t_3 = (__pyx_v_zero != 0); + if (__pyx_t_3) { + } else { + __pyx_t_2 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_3 = (((PyObject *)__pyx_v_op) != Py_None); + __pyx_t_4 = (__pyx_t_3 != 0); + __pyx_t_2 = __pyx_t_4; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { - /* "View.MemoryView":422 - * self.setitem_slice_assignment(self[index], obj) - * else: - * self.setitem_slice_assign_scalar(self[index], value) # <<<<<<<<<<<<<< - * else: - * self.setitem_indexed(index, value) + /* "array.pxd":136 + * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) + * if zero and op is not None: + * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) # <<<<<<<<<<<<<< + * return op + * */ - /*else*/ { - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 422, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_memoryview_type))))) __PYX_ERR(1, 422, __pyx_L1_error) - __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assign_scalar(__pyx_v_self, ((struct __pyx_memoryview_obj *)__pyx_t_4), __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 422, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __pyx_L5:; + (void)(memset(__pyx_v_op->data.as_chars, 0, (__pyx_v_length * __pyx_v_op->ob_descr->itemsize))); - /* "View.MemoryView":417 - * have_slices, index = _unellipsify(index, self.view.ndim) - * - * if have_slices: # <<<<<<<<<<<<<< - * obj = self.is_slice(value) - * if obj: + /* "array.pxd":135 + * if zero is true, new array will be initialized with zeroes.""" + * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) + * if zero and op is not None: # <<<<<<<<<<<<<< + * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) + * return op */ - goto __pyx_L4; } - /* "View.MemoryView":424 - * self.setitem_slice_assign_scalar(self[index], value) - * else: - * self.setitem_indexed(index, value) # <<<<<<<<<<<<<< + /* "array.pxd":137 + * if zero and op is not None: + * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) + * return op # <<<<<<<<<<<<<< * - * cdef is_slice(self, obj): + * cdef inline array copy(array self): */ - /*else*/ { - __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_indexed(__pyx_v_self, __pyx_v_index, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 424, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __pyx_L4:; + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_op)); + __pyx_r = __pyx_v_op; + goto __pyx_L0; - /* "View.MemoryView":411 - * return self.convert_item_to_object(itemp) + /* "array.pxd":130 * - * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<< - * if self.view.readonly: - * raise TypeError("Cannot assign to read-only memoryview") + * + * cdef inline array clone(array template, Py_ssize_t length, bint zero): # <<<<<<<<<<<<<< + * """ fast creation of a new array, given a template array. + * type will be same as template. */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("View.MemoryView.memoryview.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cpython.array.clone", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_have_slices); - __Pyx_XDECREF(__pyx_v_obj); - __Pyx_XDECREF(__pyx_v_index); - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF((PyObject *)__pyx_v_op); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":426 - * self.setitem_indexed(index, value) +/* "array.pxd":139 + * return op * - * cdef is_slice(self, obj): # <<<<<<<<<<<<<< - * if not isinstance(obj, memoryview): - * try: + * cdef inline array copy(array self): # <<<<<<<<<<<<<< + * """ make a copy of an array. """ + * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) */ -static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj) { - PyObject *__pyx_r = NULL; +static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_copy(arrayobject *__pyx_v_self) { + arrayobject *__pyx_v_op = NULL; + arrayobject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; - __Pyx_RefNannySetupContext("is_slice", 0); - __Pyx_TraceCall("is_slice", __pyx_f[1], 426, 0, __PYX_ERR(1, 426, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_obj); + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("copy", 0); + __Pyx_TraceCall("copy", __pyx_f[3], 139, 0, __PYX_ERR(3, 139, __pyx_L1_error)); - /* "View.MemoryView":427 - * - * cdef is_slice(self, obj): - * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<< - * try: - * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, - */ - __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_obj, __pyx_memoryview_type); - __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":428 - * cdef is_slice(self, obj): - * if not isinstance(obj, memoryview): - * try: # <<<<<<<<<<<<<< - * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, - * self.dtype_is_object) - */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_4); - __Pyx_XGOTREF(__pyx_t_5); - /*try:*/ { - - /* "View.MemoryView":429 - * if not isinstance(obj, memoryview): - * try: - * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<< - * self.dtype_is_object) - * except TypeError: - */ - __pyx_t_6 = __Pyx_PyInt_From_int((__pyx_v_self->flags | PyBUF_ANY_CONTIGUOUS)); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 429, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_6); - - /* "View.MemoryView":430 - * try: - * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, - * self.dtype_is_object) # <<<<<<<<<<<<<< - * except TypeError: - * return None - */ - __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 430, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_7); - - /* "View.MemoryView":429 - * if not isinstance(obj, memoryview): - * try: - * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<< - * self.dtype_is_object) - * except TypeError: - */ - __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 429, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_v_obj); - __Pyx_GIVEREF(__pyx_v_obj); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_obj); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7); - __pyx_t_6 = 0; - __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 429, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF_SET(__pyx_v_obj, __pyx_t_7); - __pyx_t_7 = 0; - - /* "View.MemoryView":428 - * cdef is_slice(self, obj): - * if not isinstance(obj, memoryview): - * try: # <<<<<<<<<<<<<< - * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, - * self.dtype_is_object) - */ - } - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L9_try_end; - __pyx_L4_error:; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "View.MemoryView":431 - * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, - * self.dtype_is_object) - * except TypeError: # <<<<<<<<<<<<<< - * return None - * - */ - __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError); - if (__pyx_t_9) { - __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_6) < 0) __PYX_ERR(1, 431, __pyx_L6_except_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GOTREF(__pyx_t_6); - - /* "View.MemoryView":432 - * self.dtype_is_object) - * except TypeError: - * return None # <<<<<<<<<<<<<< - * - * return obj - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L7_except_return; - } - goto __pyx_L6_except_error; - __pyx_L6_except_error:; - - /* "View.MemoryView":428 - * cdef is_slice(self, obj): - * if not isinstance(obj, memoryview): - * try: # <<<<<<<<<<<<<< - * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, - * self.dtype_is_object) + /* "array.pxd":141 + * cdef inline array copy(array self): + * """ make a copy of an array. """ + * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) # <<<<<<<<<<<<<< + * memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize) + * return op */ - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5); - goto __pyx_L1_error; - __pyx_L7_except_return:; - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5); - goto __pyx_L0; - __pyx_L9_try_end:; - } + __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_self)), Py_SIZE(((PyObject *)__pyx_v_self)), __pyx_v_self->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_op = ((arrayobject *)__pyx_t_1); + __pyx_t_1 = 0; - /* "View.MemoryView":427 + /* "array.pxd":142 + * """ make a copy of an array. """ + * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) + * memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize) # <<<<<<<<<<<<<< + * return op * - * cdef is_slice(self, obj): - * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<< - * try: - * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, */ - } + (void)(memcpy(__pyx_v_op->data.as_chars, __pyx_v_self->data.as_chars, (Py_SIZE(((PyObject *)__pyx_v_op)) * __pyx_v_op->ob_descr->itemsize))); - /* "View.MemoryView":434 - * return None - * - * return obj # <<<<<<<<<<<<<< + /* "array.pxd":143 + * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) + * memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize) + * return op # <<<<<<<<<<<<<< * - * cdef setitem_slice_assignment(self, dst, src): + * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1: */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_obj); - __pyx_r = __pyx_v_obj; + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_op)); + __pyx_r = __pyx_v_op; goto __pyx_L0; - /* "View.MemoryView":426 - * self.setitem_indexed(index, value) + /* "array.pxd":139 + * return op * - * cdef is_slice(self, obj): # <<<<<<<<<<<<<< - * if not isinstance(obj, memoryview): - * try: + * cdef inline array copy(array self): # <<<<<<<<<<<<<< + * """ make a copy of an array. """ + * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cpython.array.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_obj); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF((PyObject *)__pyx_v_op); + __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":436 - * return obj +/* "array.pxd":145 + * return op * - * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice dst_slice - * cdef __Pyx_memviewslice src_slice + * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1: # <<<<<<<<<<<<<< + * """ efficient appending of new stuff of same type + * (e.g. of same array type) */ -static PyObject *__pyx_memoryview_setitem_slice_assignment(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_dst, PyObject *__pyx_v_src) { - __Pyx_memviewslice __pyx_v_dst_slice; - __Pyx_memviewslice __pyx_v_src_slice; - PyObject *__pyx_r = NULL; +static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *__pyx_v_self, char *__pyx_v_stuff, Py_ssize_t __pyx_v_n) { + Py_ssize_t __pyx_v_itemsize; + Py_ssize_t __pyx_v_origsize; + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("setitem_slice_assignment", 0); - __Pyx_TraceCall("setitem_slice_assignment", __pyx_f[1], 436, 0, __PYX_ERR(1, 436, __pyx_L1_error)); + int __pyx_t_1; + __Pyx_RefNannySetupContext("extend_buffer", 0); + __Pyx_TraceCall("extend_buffer", __pyx_f[3], 145, 0, __PYX_ERR(3, 145, __pyx_L1_error)); - /* "View.MemoryView":440 - * cdef __Pyx_memviewslice src_slice - * - * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], # <<<<<<<<<<<<<< - * get_slice_from_memview(dst, &dst_slice)[0], - * src.ndim, dst.ndim, self.dtype_is_object) + /* "array.pxd":149 + * (e.g. of same array type) + * n: number of elements (not number of bytes!) """ + * cdef Py_ssize_t itemsize = self.ob_descr.itemsize # <<<<<<<<<<<<<< + * cdef Py_ssize_t origsize = Py_SIZE(self) + * resize_smart(self, origsize + n) */ - if (!(likely(((__pyx_v_src) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_src, __pyx_memoryview_type))))) __PYX_ERR(1, 440, __pyx_L1_error) + __pyx_t_1 = __pyx_v_self->ob_descr->itemsize; + __pyx_v_itemsize = __pyx_t_1; - /* "View.MemoryView":441 - * - * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], - * get_slice_from_memview(dst, &dst_slice)[0], # <<<<<<<<<<<<<< - * src.ndim, dst.ndim, self.dtype_is_object) - * + /* "array.pxd":150 + * n: number of elements (not number of bytes!) """ + * cdef Py_ssize_t itemsize = self.ob_descr.itemsize + * cdef Py_ssize_t origsize = Py_SIZE(self) # <<<<<<<<<<<<<< + * resize_smart(self, origsize + n) + * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) */ - if (!(likely(((__pyx_v_dst) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_dst, __pyx_memoryview_type))))) __PYX_ERR(1, 441, __pyx_L1_error) + __pyx_v_origsize = Py_SIZE(((PyObject *)__pyx_v_self)); - /* "View.MemoryView":442 - * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], - * get_slice_from_memview(dst, &dst_slice)[0], - * src.ndim, dst.ndim, self.dtype_is_object) # <<<<<<<<<<<<<< + /* "array.pxd":151 + * cdef Py_ssize_t itemsize = self.ob_descr.itemsize + * cdef Py_ssize_t origsize = Py_SIZE(self) + * resize_smart(self, origsize + n) # <<<<<<<<<<<<<< + * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) + * return 0 + */ + __pyx_t_1 = resize_smart(__pyx_v_self, (__pyx_v_origsize + __pyx_v_n)); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(3, 151, __pyx_L1_error) + + /* "array.pxd":152 + * cdef Py_ssize_t origsize = Py_SIZE(self) + * resize_smart(self, origsize + n) + * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) # <<<<<<<<<<<<<< + * return 0 * - * cdef setitem_slice_assign_scalar(self, memoryview dst, value): */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_src, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 442, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dst, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 442, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + (void)(memcpy((__pyx_v_self->data.as_chars + (__pyx_v_origsize * __pyx_v_itemsize)), __pyx_v_stuff, (__pyx_v_n * __pyx_v_itemsize))); - /* "View.MemoryView":440 - * cdef __Pyx_memviewslice src_slice + /* "array.pxd":153 + * resize_smart(self, origsize + n) + * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) + * return 0 # <<<<<<<<<<<<<< * - * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], # <<<<<<<<<<<<<< - * get_slice_from_memview(dst, &dst_slice)[0], - * src.ndim, dst.ndim, self.dtype_is_object) + * cdef inline int extend(array self, array other) except -1: */ - __pyx_t_4 = __pyx_memoryview_copy_contents((__pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_src), (&__pyx_v_src_slice))[0]), (__pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_dst), (&__pyx_v_dst_slice))[0]), __pyx_t_2, __pyx_t_3, __pyx_v_self->dtype_is_object); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 440, __pyx_L1_error) + __pyx_r = 0; + goto __pyx_L0; - /* "View.MemoryView":436 - * return obj + /* "array.pxd":145 + * return op * - * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice dst_slice - * cdef __Pyx_memviewslice src_slice + * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1: # <<<<<<<<<<<<<< + * """ efficient appending of new stuff of same type + * (e.g. of same array type) */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assignment", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_AddTraceback("cpython.array.extend_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":444 - * src.ndim, dst.ndim, self.dtype_is_object) +/* "array.pxd":155 + * return 0 * - * cdef setitem_slice_assign_scalar(self, memoryview dst, value): # <<<<<<<<<<<<<< - * cdef int array[128] - * cdef void *tmp = NULL + * cdef inline int extend(array self, array other) except -1: # <<<<<<<<<<<<<< + * """ extend array with data from another array; types must match. """ + * if self.ob_descr.typecode != other.ob_descr.typecode: */ -static PyObject *__pyx_memoryview_setitem_slice_assign_scalar(struct __pyx_memoryview_obj *__pyx_v_self, struct __pyx_memoryview_obj *__pyx_v_dst, PyObject *__pyx_v_value) { - int __pyx_v_array[0x80]; - void *__pyx_v_tmp; - void *__pyx_v_item; - __Pyx_memviewslice *__pyx_v_dst_slice; - __Pyx_memviewslice __pyx_v_tmp_slice; - PyObject *__pyx_r = NULL; +static CYTHON_INLINE int __pyx_f_7cpython_5array_extend(arrayobject *__pyx_v_self, arrayobject *__pyx_v_other) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_t_4; - char const *__pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - __Pyx_RefNannySetupContext("setitem_slice_assign_scalar", 0); - __Pyx_TraceCall("setitem_slice_assign_scalar", __pyx_f[1], 444, 0, __PYX_ERR(1, 444, __pyx_L1_error)); - - /* "View.MemoryView":446 - * cdef setitem_slice_assign_scalar(self, memoryview dst, value): - * cdef int array[128] - * cdef void *tmp = NULL # <<<<<<<<<<<<<< - * cdef void *item - * - */ - __pyx_v_tmp = NULL; - - /* "View.MemoryView":451 - * cdef __Pyx_memviewslice *dst_slice - * cdef __Pyx_memviewslice tmp_slice - * dst_slice = get_slice_from_memview(dst, &tmp_slice) # <<<<<<<<<<<<<< - * - * if self.view.itemsize > sizeof(array): - */ - __pyx_v_dst_slice = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_dst, (&__pyx_v_tmp_slice)); + int __pyx_t_2; + __Pyx_RefNannySetupContext("extend", 0); + __Pyx_TraceCall("extend", __pyx_f[3], 155, 0, __PYX_ERR(3, 155, __pyx_L1_error)); - /* "View.MemoryView":453 - * dst_slice = get_slice_from_memview(dst, &tmp_slice) - * - * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<< - * tmp = PyMem_Malloc(self.view.itemsize) - * if tmp == NULL: + /* "array.pxd":157 + * cdef inline int extend(array self, array other) except -1: + * """ extend array with data from another array; types must match. """ + * if self.ob_descr.typecode != other.ob_descr.typecode: # <<<<<<<<<<<<<< + * PyErr_BadArgument() + * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) */ - __pyx_t_1 = ((((size_t)__pyx_v_self->view.itemsize) > (sizeof(__pyx_v_array))) != 0); + __pyx_t_1 = ((__pyx_v_self->ob_descr->typecode != __pyx_v_other->ob_descr->typecode) != 0); if (__pyx_t_1) { - /* "View.MemoryView":454 + /* "array.pxd":158 + * """ extend array with data from another array; types must match. """ + * if self.ob_descr.typecode != other.ob_descr.typecode: + * PyErr_BadArgument() # <<<<<<<<<<<<<< + * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) * - * if self.view.itemsize > sizeof(array): - * tmp = PyMem_Malloc(self.view.itemsize) # <<<<<<<<<<<<<< - * if tmp == NULL: - * raise MemoryError */ - __pyx_v_tmp = PyMem_Malloc(__pyx_v_self->view.itemsize); + __pyx_t_2 = PyErr_BadArgument(); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(3, 158, __pyx_L1_error) - /* "View.MemoryView":455 - * if self.view.itemsize > sizeof(array): - * tmp = PyMem_Malloc(self.view.itemsize) - * if tmp == NULL: # <<<<<<<<<<<<<< - * raise MemoryError - * item = tmp + /* "array.pxd":157 + * cdef inline int extend(array self, array other) except -1: + * """ extend array with data from another array; types must match. """ + * if self.ob_descr.typecode != other.ob_descr.typecode: # <<<<<<<<<<<<<< + * PyErr_BadArgument() + * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) */ - __pyx_t_1 = ((__pyx_v_tmp == NULL) != 0); - if (unlikely(__pyx_t_1)) { + } - /* "View.MemoryView":456 - * tmp = PyMem_Malloc(self.view.itemsize) - * if tmp == NULL: - * raise MemoryError # <<<<<<<<<<<<<< - * item = tmp - * else: + /* "array.pxd":159 + * if self.ob_descr.typecode != other.ob_descr.typecode: + * PyErr_BadArgument() + * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) # <<<<<<<<<<<<<< + * + * cdef inline void zero(array self): */ - PyErr_NoMemory(); __PYX_ERR(1, 456, __pyx_L1_error) + __pyx_t_2 = __pyx_f_7cpython_5array_extend_buffer(__pyx_v_self, __pyx_v_other->data.as_chars, Py_SIZE(((PyObject *)__pyx_v_other))); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(3, 159, __pyx_L1_error) + __pyx_r = __pyx_t_2; + goto __pyx_L0; - /* "View.MemoryView":455 - * if self.view.itemsize > sizeof(array): - * tmp = PyMem_Malloc(self.view.itemsize) - * if tmp == NULL: # <<<<<<<<<<<<<< - * raise MemoryError - * item = tmp + /* "array.pxd":155 + * return 0 + * + * cdef inline int extend(array self, array other) except -1: # <<<<<<<<<<<<<< + * """ extend array with data from another array; types must match. """ + * if self.ob_descr.typecode != other.ob_descr.typecode: */ - } - /* "View.MemoryView":457 - * if tmp == NULL: - * raise MemoryError - * item = tmp # <<<<<<<<<<<<<< - * else: - * item = array - */ - __pyx_v_item = __pyx_v_tmp; + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("cpython.array.extend", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":453 - * dst_slice = get_slice_from_memview(dst, &tmp_slice) +/* "array.pxd":161 + * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) * - * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<< - * tmp = PyMem_Malloc(self.view.itemsize) - * if tmp == NULL: + * cdef inline void zero(array self): # <<<<<<<<<<<<<< + * """ set all elements of array to zero. """ + * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) */ - goto __pyx_L3; - } - /* "View.MemoryView":459 - * item = tmp - * else: - * item = array # <<<<<<<<<<<<<< - * - * try: - */ - /*else*/ { - __pyx_v_item = ((void *)__pyx_v_array); - } - __pyx_L3:; +static CYTHON_INLINE void __pyx_f_7cpython_5array_zero(arrayobject *__pyx_v_self) { + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("zero", 0); + __Pyx_TraceCall("zero", __pyx_f[3], 161, 0, __PYX_ERR(3, 161, __pyx_L1_error)); - /* "View.MemoryView":461 - * item = array - * - * try: # <<<<<<<<<<<<<< - * if self.dtype_is_object: - * ( item)[0] = value + /* "array.pxd":163 + * cdef inline void zero(array self): + * """ set all elements of array to zero. """ + * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) # <<<<<<<<<<<<<< */ - /*try:*/ { + (void)(memset(__pyx_v_self->data.as_chars, 0, (Py_SIZE(((PyObject *)__pyx_v_self)) * __pyx_v_self->ob_descr->itemsize))); - /* "View.MemoryView":462 + /* "array.pxd":161 + * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) * - * try: - * if self.dtype_is_object: # <<<<<<<<<<<<<< - * ( item)[0] = value - * else: + * cdef inline void zero(array self): # <<<<<<<<<<<<<< + * """ set all elements of array to zero. """ + * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) */ - __pyx_t_1 = (__pyx_v_self->dtype_is_object != 0); - if (__pyx_t_1) { - /* "View.MemoryView":463 - * try: - * if self.dtype_is_object: - * ( item)[0] = value # <<<<<<<<<<<<<< - * else: - * self.assign_item_from_object( item, value) + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("cpython.array.zero", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); +} + +/* "EnumBase":16 + * @cython.internal + * cdef class __Pyx_EnumMeta(type): + * def __init__(cls, name, parents, dct): # <<<<<<<<<<<<<< + * type.__init__(cls, name, parents, dct) + * cls.__members__ = __Pyx_OrderedDict() */ - (((PyObject **)__pyx_v_item)[0]) = ((PyObject *)__pyx_v_value); - /* "View.MemoryView":462 - * - * try: - * if self.dtype_is_object: # <<<<<<<<<<<<<< - * ( item)[0] = value - * else: - */ - goto __pyx_L8; +/* Python wrapper */ +static int __pyx_pw_8EnumBase_14__Pyx_EnumMeta_1__init__(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8EnumBase_14__Pyx_EnumMeta_1__init__(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_name = 0; + PyObject *__pyx_v_parents = 0; + PyObject *__pyx_v_dct = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,&__pyx_n_s_parents,&__pyx_n_s_dct,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_parents)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 1); __PYX_ERR(1, 16, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dct)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 2); __PYX_ERR(1, 16, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(1, 16, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } + __pyx_v_name = values[0]; + __pyx_v_parents = values[1]; + __pyx_v_dct = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 16, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("EnumBase.__Pyx_EnumMeta.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8EnumBase_14__Pyx_EnumMeta___init__(((struct __pyx_obj___Pyx_EnumMeta *)__pyx_v_cls), __pyx_v_name, __pyx_v_parents, __pyx_v_dct); - /* "View.MemoryView":465 - * ( item)[0] = value - * else: - * self.assign_item_from_object( item, value) # <<<<<<<<<<<<<< - * - * + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8EnumBase_14__Pyx_EnumMeta___init__(struct __pyx_obj___Pyx_EnumMeta *__pyx_v_cls, PyObject *__pyx_v_name, PyObject *__pyx_v_parents, PyObject *__pyx_v_dct) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__init__", 0); + + /* "EnumBase":17 + * cdef class __Pyx_EnumMeta(type): + * def __init__(cls, name, parents, dct): + * type.__init__(cls, name, parents, dct) # <<<<<<<<<<<<<< + * cls.__members__ = __Pyx_OrderedDict() + * def __iter__(cls): */ - /*else*/ { - __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, ((char *)__pyx_v_item), __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 465, __pyx_L6_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)(&PyType_Type)), __pyx_n_s_init); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + __pyx_t_4 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_4 = 1; } - __pyx_L8:; + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[5] = {__pyx_t_3, ((PyObject *)__pyx_v_cls), __pyx_v_name, __pyx_v_parents, __pyx_v_dct}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[5] = {__pyx_t_3, ((PyObject *)__pyx_v_cls), __pyx_v_name, __pyx_v_parents, __pyx_v_dct}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(((PyObject *)__pyx_v_cls)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_cls)); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_cls)); + __Pyx_INCREF(__pyx_v_name); + __Pyx_GIVEREF(__pyx_v_name); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_name); + __Pyx_INCREF(__pyx_v_parents); + __Pyx_GIVEREF(__pyx_v_parents); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_parents); + __Pyx_INCREF(__pyx_v_dct); + __Pyx_GIVEREF(__pyx_v_dct); + PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, __pyx_v_dct); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "View.MemoryView":469 - * - * - * if self.view.suboffsets != NULL: # <<<<<<<<<<<<<< - * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) - * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, - */ - __pyx_t_1 = ((__pyx_v_self->view.suboffsets != NULL) != 0); - if (__pyx_t_1) { + /* "EnumBase":18 + * def __init__(cls, name, parents, dct): + * type.__init__(cls, name, parents, dct) + * cls.__members__ = __Pyx_OrderedDict() # <<<<<<<<<<<<<< + * def __iter__(cls): + * return iter(cls.__members__.values()) + */ + __Pyx_INCREF(__Pyx_OrderedDict); + __pyx_t_2 = __Pyx_OrderedDict; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_5) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 18, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 18, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_members, __pyx_t_1) < 0) __PYX_ERR(1, 18, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "View.MemoryView":470 - * - * if self.view.suboffsets != NULL: - * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) # <<<<<<<<<<<<<< - * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, - * item, self.dtype_is_object) + /* "EnumBase":16 + * @cython.internal + * cdef class __Pyx_EnumMeta(type): + * def __init__(cls, name, parents, dct): # <<<<<<<<<<<<<< + * type.__init__(cls, name, parents, dct) + * cls.__members__ = __Pyx_OrderedDict() */ - __pyx_t_2 = assert_direct_dimensions(__pyx_v_self->view.suboffsets, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 470, __pyx_L6_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "View.MemoryView":469 - * - * - * if self.view.suboffsets != NULL: # <<<<<<<<<<<<<< - * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) - * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, - */ - } + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("EnumBase.__Pyx_EnumMeta.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":471 - * if self.view.suboffsets != NULL: - * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) - * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, # <<<<<<<<<<<<<< - * item, self.dtype_is_object) - * finally: +/* "EnumBase":19 + * type.__init__(cls, name, parents, dct) + * cls.__members__ = __Pyx_OrderedDict() + * def __iter__(cls): # <<<<<<<<<<<<<< + * return iter(cls.__members__.values()) + * def __getitem__(cls, name): */ - __pyx_memoryview_slice_assign_scalar(__pyx_v_dst_slice, __pyx_v_dst->view.ndim, __pyx_v_self->view.itemsize, __pyx_v_item, __pyx_v_self->dtype_is_object); - } - /* "View.MemoryView":474 - * item, self.dtype_is_object) - * finally: - * PyMem_Free(tmp) # <<<<<<<<<<<<<< - * - * cdef setitem_indexed(self, index, value): +/* Python wrapper */ +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumMeta_3__iter__(PyObject *__pyx_v_cls); /*proto*/ +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumMeta_3__iter__(PyObject *__pyx_v_cls) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_8EnumBase_14__Pyx_EnumMeta_2__iter__(((struct __pyx_obj___Pyx_EnumMeta *)__pyx_v_cls)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumMeta_2__iter__(struct __pyx_obj___Pyx_EnumMeta *__pyx_v_cls) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__iter__", 0); + + /* "EnumBase":20 + * cls.__members__ = __Pyx_OrderedDict() + * def __iter__(cls): + * return iter(cls.__members__.values()) # <<<<<<<<<<<<<< + * def __getitem__(cls, name): + * return cls.__members__[name] */ - /*finally:*/ { - /*normal exit:*/{ - PyMem_Free(__pyx_v_tmp); - goto __pyx_L7; - } - __pyx_L6_error:; - /*exception exit:*/{ - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __pyx_t_6 = 0; __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); - if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_8); - __Pyx_XGOTREF(__pyx_t_9); - __Pyx_XGOTREF(__pyx_t_10); - __Pyx_XGOTREF(__pyx_t_11); - __pyx_t_3 = __pyx_lineno; __pyx_t_4 = __pyx_clineno; __pyx_t_5 = __pyx_filename; - { - PyMem_Free(__pyx_v_tmp); - } - if (PY_MAJOR_VERSION >= 3) { - __Pyx_XGIVEREF(__pyx_t_9); - __Pyx_XGIVEREF(__pyx_t_10); - __Pyx_XGIVEREF(__pyx_t_11); - __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); - } - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_XGIVEREF(__pyx_t_8); - __Pyx_ErrRestore(__pyx_t_6, __pyx_t_7, __pyx_t_8); - __pyx_t_6 = 0; __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; - __pyx_lineno = __pyx_t_3; __pyx_clineno = __pyx_t_4; __pyx_filename = __pyx_t_5; - goto __pyx_L1_error; + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_members); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 20, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 20, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); } - __pyx_L7:; } + if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 20, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 20, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 20, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "View.MemoryView":444 - * src.ndim, dst.ndim, self.dtype_is_object) - * - * cdef setitem_slice_assign_scalar(self, memoryview dst, value): # <<<<<<<<<<<<<< - * cdef int array[128] - * cdef void *tmp = NULL + /* "EnumBase":19 + * type.__init__(cls, name, parents, dct) + * cls.__members__ = __Pyx_OrderedDict() + * def __iter__(cls): # <<<<<<<<<<<<<< + * return iter(cls.__members__.values()) + * def __getitem__(cls, name): */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("EnumBase.__Pyx_EnumMeta.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":476 - * PyMem_Free(tmp) +/* "EnumBase":21 + * def __iter__(cls): + * return iter(cls.__members__.values()) + * def __getitem__(cls, name): # <<<<<<<<<<<<<< + * return cls.__members__[name] * - * cdef setitem_indexed(self, index, value): # <<<<<<<<<<<<<< - * cdef char *itemp = self.get_item_pointer(index) - * self.assign_item_from_object(itemp, value) */ -static PyObject *__pyx_memoryview_setitem_indexed(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) { - char *__pyx_v_itemp; +/* Python wrapper */ +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumMeta_5__getitem__(PyObject *__pyx_v_cls, PyObject *__pyx_v_name); /*proto*/ +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumMeta_5__getitem__(PyObject *__pyx_v_cls, PyObject *__pyx_v_name) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_8EnumBase_14__Pyx_EnumMeta_4__getitem__(((struct __pyx_obj___Pyx_EnumMeta *)__pyx_v_cls), ((PyObject *)__pyx_v_name)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumMeta_4__getitem__(struct __pyx_obj___Pyx_EnumMeta *__pyx_v_cls, PyObject *__pyx_v_name) { PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - char *__pyx_t_1; + PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("setitem_indexed", 0); - __Pyx_TraceCall("setitem_indexed", __pyx_f[1], 476, 0, __PYX_ERR(1, 476, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__getitem__", 0); - /* "View.MemoryView":477 - * - * cdef setitem_indexed(self, index, value): - * cdef char *itemp = self.get_item_pointer(index) # <<<<<<<<<<<<<< - * self.assign_item_from_object(itemp, value) + /* "EnumBase":22 + * return iter(cls.__members__.values()) + * def __getitem__(cls, name): + * return cls.__members__[name] # <<<<<<<<<<<<<< * - */ - __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_index); if (unlikely(__pyx_t_1 == ((char *)NULL))) __PYX_ERR(1, 477, __pyx_L1_error) - __pyx_v_itemp = __pyx_t_1; - - /* "View.MemoryView":478 - * cdef setitem_indexed(self, index, value): - * cdef char *itemp = self.get_item_pointer(index) - * self.assign_item_from_object(itemp, value) # <<<<<<<<<<<<<< * - * cdef convert_item_to_object(self, char *itemp): */ - __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 478, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_members); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "View.MemoryView":476 - * PyMem_Free(tmp) + /* "EnumBase":21 + * def __iter__(cls): + * return iter(cls.__members__.values()) + * def __getitem__(cls, name): # <<<<<<<<<<<<<< + * return cls.__members__[name] * - * cdef setitem_indexed(self, index, value): # <<<<<<<<<<<<<< - * cdef char *itemp = self.get_item_pointer(index) - * self.assign_item_from_object(itemp, value) */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_indexed", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_AddTraceback("EnumBase.__Pyx_EnumMeta.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":480 - * self.assign_item_from_object(itemp, value) - * - * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< - * """Only used if instantiated manually by the user, or if Cython doesn't - * know how to convert the type""" +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef bint use_setstate + * state = () */ -static PyObject *__pyx_memoryview_convert_item_to_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp) { - PyObject *__pyx_v_struct = NULL; - PyObject *__pyx_v_bytesitem = 0; - PyObject *__pyx_v_result = NULL; +/* Python wrapper */ +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumMeta_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumMeta_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_8EnumBase_14__Pyx_EnumMeta_6__reduce_cython__(((struct __pyx_obj___Pyx_EnumMeta *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumMeta_6__reduce_cython__(struct __pyx_obj___Pyx_EnumMeta *__pyx_v_self) { + int __pyx_v_use_setstate; + PyObject *__pyx_v_state = NULL; + PyObject *__pyx_v__dict = NULL; PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; + int __pyx_t_2; + int __pyx_t_3; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - int __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - size_t __pyx_t_10; - int __pyx_t_11; - __Pyx_RefNannySetupContext("convert_item_to_object", 0); - __Pyx_TraceCall("convert_item_to_object", __pyx_f[1], 480, 0, __PYX_ERR(1, 480, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__reduce_cython__", 0); - /* "View.MemoryView":483 - * """Only used if instantiated manually by the user, or if Cython doesn't - * know how to convert the type""" - * import struct # <<<<<<<<<<<<<< - * cdef bytes bytesitem - * + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * cdef bint use_setstate + * state = () # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 483, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_struct = __pyx_t_1; - __pyx_t_1 = 0; + __Pyx_INCREF(__pyx_empty_tuple); + __pyx_v_state = __pyx_empty_tuple; - /* "View.MemoryView":486 - * cdef bytes bytesitem - * - * bytesitem = itemp[:self.view.itemsize] # <<<<<<<<<<<<<< - * try: - * result = struct.unpack(self.view.format, bytesitem) + /* "(tree fragment)":4 + * cdef bint use_setstate + * state = () + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) */ - __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_itemp + 0, __pyx_v_self->view.itemsize - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 486, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_v_bytesitem = ((PyObject*)__pyx_t_1); + __pyx_v__dict = __pyx_t_1; __pyx_t_1 = 0; - /* "View.MemoryView":487 - * - * bytesitem = itemp[:self.view.itemsize] - * try: # <<<<<<<<<<<<<< - * result = struct.unpack(self.view.format, bytesitem) - * except struct.error: + /* "(tree fragment)":5 + * state = () + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4); - __Pyx_XGOTREF(__pyx_t_2); - __Pyx_XGOTREF(__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_4); - /*try:*/ { + __pyx_t_2 = (__pyx_v__dict != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { - /* "View.MemoryView":488 - * bytesitem = itemp[:self.view.itemsize] - * try: - * result = struct.unpack(self.view.format, bytesitem) # <<<<<<<<<<<<<< - * except struct.error: - * raise ValueError("Unable to convert item to object") + /* "(tree fragment)":6 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_unpack); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 488, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 488, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = NULL; - __pyx_t_8 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - __pyx_t_8 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 488, __pyx_L3_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 488, __pyx_L3_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 488, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_7) { - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; - } - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_6); - __Pyx_INCREF(__pyx_v_bytesitem); - __Pyx_GIVEREF(__pyx_v_bytesitem); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_bytesitem); - __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 488, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_result = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; - /* "View.MemoryView":487 - * - * bytesitem = itemp[:self.view.itemsize] - * try: # <<<<<<<<<<<<<< - * result = struct.unpack(self.view.format, bytesitem) - * except struct.error: + /* "(tree fragment)":7 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = False */ - } + __pyx_v_use_setstate = 1; - /* "View.MemoryView":492 - * raise ValueError("Unable to convert item to object") - * else: - * if len(self.view.format) == 1: # <<<<<<<<<<<<<< - * return result[0] - * return result + /* "(tree fragment)":5 + * state = () + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True */ - /*else:*/ { - __pyx_t_10 = strlen(__pyx_v_self->view.format); - __pyx_t_11 = ((__pyx_t_10 == 1) != 0); - if (__pyx_t_11) { - - /* "View.MemoryView":493 - * else: - * if len(self.view.format) == 1: - * return result[0] # <<<<<<<<<<<<<< - * return result - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_result, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 493, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L6_except_return; + goto __pyx_L3; + } - /* "View.MemoryView":492 - * raise ValueError("Unable to convert item to object") - * else: - * if len(self.view.format) == 1: # <<<<<<<<<<<<<< - * return result[0] - * return result + /* "(tree fragment)":9 + * use_setstate = True + * else: + * use_setstate = False # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle___Pyx_EnumMeta, (type(self), 0xd41d8cd, None), state */ - } + /*else*/ { + __pyx_v_use_setstate = 0; + } + __pyx_L3:; - /* "View.MemoryView":494 - * if len(self.view.format) == 1: - * return result[0] - * return result # <<<<<<<<<<<<<< - * - * cdef assign_item_from_object(self, char *itemp, object value): + /* "(tree fragment)":10 + * else: + * use_setstate = False + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle___Pyx_EnumMeta, (type(self), 0xd41d8cd, None), state + * else: */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result); - __pyx_r = __pyx_v_result; - goto __pyx_L6_except_return; - } - __pyx_L3_error:; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = (__pyx_v_use_setstate != 0); + if (__pyx_t_3) { - /* "View.MemoryView":489 - * try: - * result = struct.unpack(self.view.format, bytesitem) - * except struct.error: # <<<<<<<<<<<<<< - * raise ValueError("Unable to convert item to object") - * else: + /* "(tree fragment)":11 + * use_setstate = False + * if use_setstate: + * return __pyx_unpickle___Pyx_EnumMeta, (type(self), 0xd41d8cd, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle___Pyx_EnumMeta, (type(self), 0xd41d8cd, state) */ - __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_5, &__pyx_t_9); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 489, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_6); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_ErrRestore(__pyx_t_1, __pyx_t_5, __pyx_t_9); - __pyx_t_1 = 0; __pyx_t_5 = 0; __pyx_t_9 = 0; - if (__pyx_t_8) { - __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_5, &__pyx_t_1) < 0) __PYX_ERR(1, 489, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle___Pyx_EnumMeta); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_222419149); + __Pyx_GIVEREF(__pyx_int_222419149); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_222419149); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; - /* "View.MemoryView":490 - * result = struct.unpack(self.view.format, bytesitem) - * except struct.error: - * raise ValueError("Unable to convert item to object") # <<<<<<<<<<<<<< - * else: - * if len(self.view.format) == 1: + /* "(tree fragment)":10 + * else: + * use_setstate = False + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle___Pyx_EnumMeta, (type(self), 0xd41d8cd, None), state + * else: */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 490, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(1, 490, __pyx_L5_except_error) - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; + } - /* "View.MemoryView":487 - * - * bytesitem = itemp[:self.view.itemsize] - * try: # <<<<<<<<<<<<<< - * result = struct.unpack(self.view.format, bytesitem) - * except struct.error: + /* "(tree fragment)":13 + * return __pyx_unpickle___Pyx_EnumMeta, (type(self), 0xd41d8cd, None), state + * else: + * return __pyx_unpickle___Pyx_EnumMeta, (type(self), 0xd41d8cd, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle___Pyx_EnumMeta__set_state(self, __pyx_state) */ - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); - goto __pyx_L1_error; - __pyx_L6_except_return:; - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle___Pyx_EnumMeta); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_222419149); + __Pyx_GIVEREF(__pyx_int_222419149); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_222419149); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __pyx_t_5 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; goto __pyx_L0; } - /* "View.MemoryView":480 - * self.assign_item_from_object(itemp, value) - * - * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< - * """Only used if instantiated manually by the user, or if Cython doesn't - * know how to convert the type""" + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef bint use_setstate + * state = () */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_AddTraceback("EnumBase.__Pyx_EnumMeta.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_struct); - __Pyx_XDECREF(__pyx_v_bytesitem); - __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":496 - * return result - * - * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< - * """Only used if instantiated manually by the user, or if Cython doesn't - * know how to convert the type""" +/* "(tree fragment)":14 + * else: + * return __pyx_unpickle___Pyx_EnumMeta, (type(self), 0xd41d8cd, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle___Pyx_EnumMeta__set_state(self, __pyx_state) */ -static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) { - PyObject *__pyx_v_struct = NULL; - char __pyx_v_c; - PyObject *__pyx_v_bytesvalue = 0; - Py_ssize_t __pyx_v_i; +/* Python wrapper */ +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumMeta_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumMeta_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_8EnumBase_14__Pyx_EnumMeta_8__setstate_cython__(((struct __pyx_obj___Pyx_EnumMeta *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumMeta_8__setstate_cython__(struct __pyx_obj___Pyx_EnumMeta *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - Py_ssize_t __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - char *__pyx_t_11; - char *__pyx_t_12; - char *__pyx_t_13; - char *__pyx_t_14; - __Pyx_RefNannySetupContext("assign_item_from_object", 0); - __Pyx_TraceCall("assign_item_from_object", __pyx_f[1], 496, 0, __PYX_ERR(1, 496, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__setstate_cython__", 0); - /* "View.MemoryView":499 - * """Only used if instantiated manually by the user, or if Cython doesn't - * know how to convert the type""" - * import struct # <<<<<<<<<<<<<< - * cdef char c - * cdef bytes bytesvalue + /* "(tree fragment)":15 + * return __pyx_unpickle___Pyx_EnumMeta, (type(self), 0xd41d8cd, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle___Pyx_EnumMeta__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 499, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_unpickle___Pyx_EnumMeta__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_v_struct = __pyx_t_1; - __pyx_t_1 = 0; - - /* "View.MemoryView":504 - * cdef Py_ssize_t i - * - * if isinstance(value, tuple): # <<<<<<<<<<<<<< - * bytesvalue = struct.pack(self.view.format, *value) - * else: - */ - __pyx_t_2 = PyTuple_Check(__pyx_v_value); - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { - - /* "View.MemoryView":505 - * - * if isinstance(value, tuple): - * bytesvalue = struct.pack(self.view.format, *value) # <<<<<<<<<<<<<< - * else: - * bytesvalue = struct.pack(self.view.format, value) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 505, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 505, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 505, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 505, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = PyNumber_Add(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 505, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 505, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(1, 505, __pyx_L1_error) - __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; - - /* "View.MemoryView":504 - * cdef Py_ssize_t i - * - * if isinstance(value, tuple): # <<<<<<<<<<<<<< - * bytesvalue = struct.pack(self.view.format, *value) - * else: - */ - goto __pyx_L3; - } - - /* "View.MemoryView":507 - * bytesvalue = struct.pack(self.view.format, *value) - * else: - * bytesvalue = struct.pack(self.view.format, value) # <<<<<<<<<<<<<< - * - * for i, c in enumerate(bytesvalue): - */ - /*else*/ { - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 507, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 507, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_1); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_v_value); - __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(1, 507, __pyx_L1_error) - __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; - } - __pyx_L3:; - - /* "View.MemoryView":509 - * bytesvalue = struct.pack(self.view.format, value) - * - * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<< - * itemp[i] = c - * - */ - __pyx_t_9 = 0; - if (unlikely(__pyx_v_bytesvalue == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable"); - __PYX_ERR(1, 509, __pyx_L1_error) - } - __Pyx_INCREF(__pyx_v_bytesvalue); - __pyx_t_10 = __pyx_v_bytesvalue; - __pyx_t_12 = PyBytes_AS_STRING(__pyx_t_10); - __pyx_t_13 = (__pyx_t_12 + PyBytes_GET_SIZE(__pyx_t_10)); - for (__pyx_t_14 = __pyx_t_12; __pyx_t_14 < __pyx_t_13; __pyx_t_14++) { - __pyx_t_11 = __pyx_t_14; - __pyx_v_c = (__pyx_t_11[0]); - - /* "View.MemoryView":510 - * - * for i, c in enumerate(bytesvalue): - * itemp[i] = c # <<<<<<<<<<<<<< - * - * @cname('getbuffer') - */ - __pyx_v_i = __pyx_t_9; - - /* "View.MemoryView":509 - * bytesvalue = struct.pack(self.view.format, value) - * - * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<< - * itemp[i] = c - * - */ - __pyx_t_9 = (__pyx_t_9 + 1); - - /* "View.MemoryView":510 - * - * for i, c in enumerate(bytesvalue): - * itemp[i] = c # <<<<<<<<<<<<<< - * - * @cname('getbuffer') - */ - (__pyx_v_itemp[__pyx_v_i]) = __pyx_v_c; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "View.MemoryView":496 - * return result - * - * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< - * """Only used if instantiated manually by the user, or if Cython doesn't - * know how to convert the type""" + /* "(tree fragment)":14 + * else: + * return __pyx_unpickle___Pyx_EnumMeta, (type(self), 0xd41d8cd, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle___Pyx_EnumMeta__set_state(self, __pyx_state) */ /* function exit code */ @@ -35461,503 +39375,537 @@ static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryvie goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("View.MemoryView.memoryview.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_AddTraceback("EnumBase.__Pyx_EnumMeta.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_struct); - __Pyx_XDECREF(__pyx_v_bytesvalue); __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":513 - * - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< - * if flags & PyBUF_WRITABLE and self.view.readonly: - * raise ValueError("Cannot create writable memory view from read-only memoryview") +/* "EnumBase":28 + * class __Pyx_EnumBase(int): + * __metaclass__ = __Pyx_EnumMeta + * def __new__(cls, value, name=None): # <<<<<<<<<<<<<< + * for v in cls: + * if v == value: */ /* Python wrapper */ -static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ -static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { - int __pyx_r; +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumBase_1__new__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_8EnumBase_14__Pyx_EnumBase_1__new__ = {"__new__", (PyCFunction)__pyx_pw_8EnumBase_14__Pyx_EnumBase_1__new__, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumBase_1__new__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_cls = 0; + PyObject *__pyx_v_value = 0; + PyObject *__pyx_v_name = 0; + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); + __Pyx_RefNannySetupContext("__new__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_cls,&__pyx_n_s_value,&__pyx_n_s_name,0}; + PyObject* values[3] = {0,0,0}; + values[2] = ((PyObject *)((PyObject *)Py_None)); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_cls)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__new__", 0, 2, 3, 1); __PYX_ERR(1, 28, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__new__") < 0)) __PYX_ERR(1, 28, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_cls = values[0]; + __pyx_v_value = values[1]; + __pyx_v_name = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__new__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 28, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("EnumBase.__Pyx_EnumBase.__new__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8EnumBase_14__Pyx_EnumBase___new__(__pyx_self, __pyx_v_cls, __pyx_v_value, __pyx_v_name); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { - int __pyx_r; +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumBase___new__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cls, PyObject *__pyx_v_value, PyObject *__pyx_v_name) { + PyObject *__pyx_v_v = NULL; + PyObject *__pyx_v_res = NULL; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t *__pyx_t_4; - char *__pyx_t_5; - void *__pyx_t_6; - int __pyx_t_7; - Py_ssize_t __pyx_t_8; - if (__pyx_v_info == NULL) { - PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete"); - return -1; + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + int __pyx_t_10; + __Pyx_TraceFrameInit(__pyx_codeobj__50) + __Pyx_RefNannySetupContext("__new__", 0); + __Pyx_TraceCall("__new__", __pyx_f[1], 28, 0, __PYX_ERR(1, 28, __pyx_L1_error)); + + /* "EnumBase":29 + * __metaclass__ = __Pyx_EnumMeta + * def __new__(cls, value, name=None): + * for v in cls: # <<<<<<<<<<<<<< + * if v == value: + * return v + */ + if (likely(PyList_CheckExact(__pyx_v_cls)) || PyTuple_CheckExact(__pyx_v_cls)) { + __pyx_t_1 = __pyx_v_cls; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_cls); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 29, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 29, __pyx_L1_error) } - __Pyx_RefNannySetupContext("__getbuffer__", 0); - __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(__pyx_v_info->obj); - __Pyx_TraceCall("__getbuffer__", __pyx_f[1], 513, 0, __PYX_ERR(1, 513, __pyx_L1_error)); - - /* "View.MemoryView":514 - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): - * if flags & PyBUF_WRITABLE and self.view.readonly: # <<<<<<<<<<<<<< - * raise ValueError("Cannot create writable memory view from read-only memoryview") - * - */ - __pyx_t_2 = ((__pyx_v_flags & PyBUF_WRITABLE) != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_2 = (__pyx_v_self->view.readonly != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L4_bool_binop_done:; - if (unlikely(__pyx_t_1)) { - - /* "View.MemoryView":515 - * def __getbuffer__(self, Py_buffer *info, int flags): - * if flags & PyBUF_WRITABLE and self.view.readonly: - * raise ValueError("Cannot create writable memory view from read-only memoryview") # <<<<<<<<<<<<<< - * - * if flags & PyBUF_STRIDES: - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__49, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 515, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 515, __pyx_L1_error) - - /* "View.MemoryView":514 - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): - * if flags & PyBUF_WRITABLE and self.view.readonly: # <<<<<<<<<<<<<< - * raise ValueError("Cannot create writable memory view from read-only memoryview") - * - */ - } - - /* "View.MemoryView":517 - * raise ValueError("Cannot create writable memory view from read-only memoryview") - * - * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< - * info.shape = self.view.shape - * else: - */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_STRIDES) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":518 - * - * if flags & PyBUF_STRIDES: - * info.shape = self.view.shape # <<<<<<<<<<<<<< - * else: - * info.shape = NULL - */ - __pyx_t_4 = __pyx_v_self->view.shape; - __pyx_v_info->shape = __pyx_t_4; - - /* "View.MemoryView":517 - * raise ValueError("Cannot create writable memory view from read-only memoryview") - * - * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< - * info.shape = self.view.shape - * else: - */ - goto __pyx_L6; - } - - /* "View.MemoryView":520 - * info.shape = self.view.shape - * else: - * info.shape = NULL # <<<<<<<<<<<<<< - * - * if flags & PyBUF_STRIDES: - */ - /*else*/ { - __pyx_v_info->shape = NULL; - } - __pyx_L6:; + for (;;) { + if (likely(!__pyx_t_3)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(1, 29, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 29, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(1, 29, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 29, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(1, 29, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_4); + __pyx_t_4 = 0; - /* "View.MemoryView":522 - * info.shape = NULL - * - * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< - * info.strides = self.view.strides - * else: + /* "EnumBase":30 + * def __new__(cls, value, name=None): + * for v in cls: + * if v == value: # <<<<<<<<<<<<<< + * return v + * if name is None: */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_STRIDES) != 0); - if (__pyx_t_1) { + __pyx_t_4 = PyObject_RichCompare(__pyx_v_v, __pyx_v_value, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 30, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(1, 30, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { - /* "View.MemoryView":523 - * - * if flags & PyBUF_STRIDES: - * info.strides = self.view.strides # <<<<<<<<<<<<<< - * else: - * info.strides = NULL + /* "EnumBase":31 + * for v in cls: + * if v == value: + * return v # <<<<<<<<<<<<<< + * if name is None: + * raise ValueError("Unknown enum value: '%s'" % value) */ - __pyx_t_4 = __pyx_v_self->view.strides; - __pyx_v_info->strides = __pyx_t_4; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_v); + __pyx_r = __pyx_v_v; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; - /* "View.MemoryView":522 - * info.shape = NULL - * - * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< - * info.strides = self.view.strides - * else: + /* "EnumBase":30 + * def __new__(cls, value, name=None): + * for v in cls: + * if v == value: # <<<<<<<<<<<<<< + * return v + * if name is None: */ - goto __pyx_L7; - } + } - /* "View.MemoryView":525 - * info.strides = self.view.strides - * else: - * info.strides = NULL # <<<<<<<<<<<<<< - * - * if flags & PyBUF_INDIRECT: + /* "EnumBase":29 + * __metaclass__ = __Pyx_EnumMeta + * def __new__(cls, value, name=None): + * for v in cls: # <<<<<<<<<<<<<< + * if v == value: + * return v */ - /*else*/ { - __pyx_v_info->strides = NULL; } - __pyx_L7:; - - /* "View.MemoryView":527 - * info.strides = NULL - * - * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<< - * info.suboffsets = self.view.suboffsets - * else: - */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_INDIRECT) != 0); - if (__pyx_t_1) { + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "View.MemoryView":528 - * - * if flags & PyBUF_INDIRECT: - * info.suboffsets = self.view.suboffsets # <<<<<<<<<<<<<< - * else: - * info.suboffsets = NULL + /* "EnumBase":32 + * if v == value: + * return v + * if name is None: # <<<<<<<<<<<<<< + * raise ValueError("Unknown enum value: '%s'" % value) + * res = int.__new__(cls, value) */ - __pyx_t_4 = __pyx_v_self->view.suboffsets; - __pyx_v_info->suboffsets = __pyx_t_4; + __pyx_t_5 = (__pyx_v_name == Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (unlikely(__pyx_t_6)) { - /* "View.MemoryView":527 - * info.strides = NULL - * - * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<< - * info.suboffsets = self.view.suboffsets - * else: + /* "EnumBase":33 + * return v + * if name is None: + * raise ValueError("Unknown enum value: '%s'" % value) # <<<<<<<<<<<<<< + * res = int.__new__(cls, value) + * res.name = name */ - goto __pyx_L8; - } + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_Unknown_enum_value_s, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 33, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 33, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(1, 33, __pyx_L1_error) - /* "View.MemoryView":530 - * info.suboffsets = self.view.suboffsets - * else: - * info.suboffsets = NULL # <<<<<<<<<<<<<< - * - * if flags & PyBUF_FORMAT: + /* "EnumBase":32 + * if v == value: + * return v + * if name is None: # <<<<<<<<<<<<<< + * raise ValueError("Unknown enum value: '%s'" % value) + * res = int.__new__(cls, value) */ - /*else*/ { - __pyx_v_info->suboffsets = NULL; } - __pyx_L8:; - - /* "View.MemoryView":532 - * info.suboffsets = NULL - * - * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< - * info.format = self.view.format - * else: - */ - __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0); - if (__pyx_t_1) { - - /* "View.MemoryView":533 - * - * if flags & PyBUF_FORMAT: - * info.format = self.view.format # <<<<<<<<<<<<<< - * else: - * info.format = NULL - */ - __pyx_t_5 = __pyx_v_self->view.format; - __pyx_v_info->format = __pyx_t_5; - /* "View.MemoryView":532 - * info.suboffsets = NULL - * - * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< - * info.format = self.view.format - * else: + /* "EnumBase":34 + * if name is None: + * raise ValueError("Unknown enum value: '%s'" % value) + * res = int.__new__(cls, value) # <<<<<<<<<<<<<< + * res.name = name + * setattr(cls, name, res) */ - goto __pyx_L9; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)(&PyInt_Type)), __pyx_n_s_new); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 34, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = NULL; + __pyx_t_8 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_8 = 1; + } } - - /* "View.MemoryView":535 - * info.format = self.view.format - * else: - * info.format = NULL # <<<<<<<<<<<<<< - * - * info.buf = self.view.buf - */ - /*else*/ { - __pyx_v_info->format = NULL; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_cls, __pyx_v_value}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 34, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_cls, __pyx_v_value}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 34, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 34, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_cls); + __Pyx_GIVEREF(__pyx_v_cls); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_v_cls); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_value); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 34, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } - __pyx_L9:; - - /* "View.MemoryView":537 - * info.format = NULL - * - * info.buf = self.view.buf # <<<<<<<<<<<<<< - * info.ndim = self.view.ndim - * info.itemsize = self.view.itemsize - */ - __pyx_t_6 = __pyx_v_self->view.buf; - __pyx_v_info->buf = __pyx_t_6; - - /* "View.MemoryView":538 - * - * info.buf = self.view.buf - * info.ndim = self.view.ndim # <<<<<<<<<<<<<< - * info.itemsize = self.view.itemsize - * info.len = self.view.len - */ - __pyx_t_7 = __pyx_v_self->view.ndim; - __pyx_v_info->ndim = __pyx_t_7; - - /* "View.MemoryView":539 - * info.buf = self.view.buf - * info.ndim = self.view.ndim - * info.itemsize = self.view.itemsize # <<<<<<<<<<<<<< - * info.len = self.view.len - * info.readonly = self.view.readonly - */ - __pyx_t_8 = __pyx_v_self->view.itemsize; - __pyx_v_info->itemsize = __pyx_t_8; - - /* "View.MemoryView":540 - * info.ndim = self.view.ndim - * info.itemsize = self.view.itemsize - * info.len = self.view.len # <<<<<<<<<<<<<< - * info.readonly = self.view.readonly - * info.obj = self - */ - __pyx_t_8 = __pyx_v_self->view.len; - __pyx_v_info->len = __pyx_t_8; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_res = __pyx_t_4; + __pyx_t_4 = 0; - /* "View.MemoryView":541 - * info.itemsize = self.view.itemsize - * info.len = self.view.len - * info.readonly = self.view.readonly # <<<<<<<<<<<<<< - * info.obj = self - * + /* "EnumBase":35 + * raise ValueError("Unknown enum value: '%s'" % value) + * res = int.__new__(cls, value) + * res.name = name # <<<<<<<<<<<<<< + * setattr(cls, name, res) + * cls.__members__[name] = res + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_v_res, __pyx_n_s_name, __pyx_v_name) < 0) __PYX_ERR(1, 35, __pyx_L1_error) + + /* "EnumBase":36 + * res = int.__new__(cls, value) + * res.name = name + * setattr(cls, name, res) # <<<<<<<<<<<<<< + * cls.__members__[name] = res + * return res + */ + __pyx_t_10 = PyObject_SetAttr(__pyx_v_cls, __pyx_v_name, __pyx_v_res); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(1, 36, __pyx_L1_error) + + /* "EnumBase":37 + * res.name = name + * setattr(cls, name, res) + * cls.__members__[name] = res # <<<<<<<<<<<<<< + * return res + * def __repr__(self): */ - __pyx_t_1 = __pyx_v_self->view.readonly; - __pyx_v_info->readonly = __pyx_t_1; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_cls, __pyx_n_s_members); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 37, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (unlikely(PyObject_SetItem(__pyx_t_4, __pyx_v_name, __pyx_v_res) < 0)) __PYX_ERR(1, 37, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "View.MemoryView":542 - * info.len = self.view.len - * info.readonly = self.view.readonly - * info.obj = self # <<<<<<<<<<<<<< - * - * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") + /* "EnumBase":38 + * setattr(cls, name, res) + * cls.__members__[name] = res + * return res # <<<<<<<<<<<<<< + * def __repr__(self): + * return "<%s.%s: %d>" % (self.__class__.__name__, self.name, self) */ - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); - __pyx_v_info->obj = ((PyObject *)__pyx_v_self); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_res); + __pyx_r = __pyx_v_res; + goto __pyx_L0; - /* "View.MemoryView":513 - * - * @cname('getbuffer') - * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< - * if flags & PyBUF_WRITABLE and self.view.readonly: - * raise ValueError("Cannot create writable memory view from read-only memoryview") + /* "EnumBase":28 + * class __Pyx_EnumBase(int): + * __metaclass__ = __Pyx_EnumMeta + * def __new__(cls, value, name=None): # <<<<<<<<<<<<<< + * for v in cls: + * if v == value: */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - if (__pyx_v_info->obj != NULL) { - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; - } - goto __pyx_L2; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("EnumBase.__Pyx_EnumBase.__new__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - if (__pyx_v_info->obj == Py_None) { - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; - } - __pyx_L2:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF(__pyx_v_v); + __Pyx_XDECREF(__pyx_v_res); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":548 - * - * @property - * def T(self): # <<<<<<<<<<<<<< - * cdef _memoryviewslice result = memoryview_copy(self) - * transpose_memslice(&result.from_slice) +/* "EnumBase":39 + * cls.__members__[name] = res + * return res + * def __repr__(self): # <<<<<<<<<<<<<< + * return "<%s.%s: %d>" % (self.__class__.__name__, self.name, self) + * def __str__(self): */ /* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumBase_3__repr__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/ +static PyMethodDef __pyx_mdef_8EnumBase_14__Pyx_EnumBase_3__repr__ = {"__repr__", (PyCFunction)__pyx_pw_8EnumBase_14__Pyx_EnumBase_3__repr__, METH_O, 0}; +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumBase_3__repr__(PyObject *__pyx_self, PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0); + __pyx_r = __pyx_pf_8EnumBase_14__Pyx_EnumBase_2__repr__(__pyx_self, ((PyObject *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - struct __pyx_memoryviewslice_obj *__pyx_v_result = 0; +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumBase_2__repr__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[1], 548, 0, __PYX_ERR(1, 548, __pyx_L1_error)); + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_TraceFrameInit(__pyx_codeobj__51) + __Pyx_RefNannySetupContext("__repr__", 0); + __Pyx_TraceCall("__repr__", __pyx_f[1], 39, 0, __PYX_ERR(1, 39, __pyx_L1_error)); - /* "View.MemoryView":549 - * @property - * def T(self): - * cdef _memoryviewslice result = memoryview_copy(self) # <<<<<<<<<<<<<< - * transpose_memslice(&result.from_slice) - * return result + /* "EnumBase":40 + * return res + * def __repr__(self): + * return "<%s.%s: %d>" % (self.__class__.__name__, self.name, self) # <<<<<<<<<<<<<< + * def __str__(self): + * return "%s.%s" % (self.__class__.__name__, self.name) */ - __pyx_t_1 = __pyx_memoryview_copy_object(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 549, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 40, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_memoryviewslice_type))))) __PYX_ERR(1, 549, __pyx_L1_error) - __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_name_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 40, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 40, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 40, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_v_self); + __Pyx_GIVEREF(__pyx_v_self); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_self); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s_s_d, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 40, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; - - /* "View.MemoryView":550 - * def T(self): - * cdef _memoryviewslice result = memoryview_copy(self) - * transpose_memslice(&result.from_slice) # <<<<<<<<<<<<<< - * return result - * - */ - __pyx_t_2 = __pyx_memslice_transpose((&__pyx_v_result->from_slice)); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(1, 550, __pyx_L1_error) - - /* "View.MemoryView":551 - * cdef _memoryviewslice result = memoryview_copy(self) - * transpose_memslice(&result.from_slice) - * return result # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0; - /* "View.MemoryView":548 - * - * @property - * def T(self): # <<<<<<<<<<<<<< - * cdef _memoryviewslice result = memoryview_copy(self) - * transpose_memslice(&result.from_slice) + /* "EnumBase":39 + * cls.__members__[name] = res + * return res + * def __repr__(self): # <<<<<<<<<<<<<< + * return "<%s.%s: %d>" % (self.__class__.__name__, self.name, self) + * def __str__(self): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview.T.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("EnumBase.__Pyx_EnumBase.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":554 - * - * @property - * def base(self): # <<<<<<<<<<<<<< - * return self.obj +/* "EnumBase":41 + * def __repr__(self): + * return "<%s.%s: %d>" % (self.__class__.__name__, self.name, self) + * def __str__(self): # <<<<<<<<<<<<<< + * return "%s.%s" % (self.__class__.__name__, self.name) * */ /* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumBase_5__str__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/ +static PyMethodDef __pyx_mdef_8EnumBase_14__Pyx_EnumBase_5__str__ = {"__str__", (PyCFunction)__pyx_pw_8EnumBase_14__Pyx_EnumBase_5__str__, METH_O, 0}; +static PyObject *__pyx_pw_8EnumBase_14__Pyx_EnumBase_5__str__(PyObject *__pyx_self, PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_8EnumBase_14__Pyx_EnumBase_4__str__(__pyx_self, ((PyObject *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self) { +static PyObject *__pyx_pf_8EnumBase_14__Pyx_EnumBase_4__str__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[1], 554, 0, __PYX_ERR(1, 554, __pyx_L1_error)); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_TraceFrameInit(__pyx_codeobj__52) + __Pyx_RefNannySetupContext("__str__", 0); + __Pyx_TraceCall("__str__", __pyx_f[1], 41, 0, __PYX_ERR(1, 41, __pyx_L1_error)); - /* "View.MemoryView":555 - * @property - * def base(self): - * return self.obj # <<<<<<<<<<<<<< + /* "EnumBase":42 + * return "<%s.%s: %d>" % (self.__class__.__name__, self.name, self) + * def __str__(self): + * return "%s.%s" % (self.__class__.__name__, self.name) # <<<<<<<<<<<<<< * - * @property + * if PY_VERSION_HEX >= 0x03040000: */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->obj); - __pyx_r = __pyx_v_self->obj; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 42, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_name_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 42, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 42, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 42, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 42, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "View.MemoryView":554 - * - * @property - * def base(self): # <<<<<<<<<<<<<< - * return self.obj + /* "EnumBase":41 + * def __repr__(self): + * return "<%s.%s: %d>" % (self.__class__.__name__, self.name, self) + * def __str__(self): # <<<<<<<<<<<<<< + * return "%s.%s" % (self.__class__.__name__, self.name) * */ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("View.MemoryView.memoryview.base.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("EnumBase.__Pyx_EnumBase.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -35966,312 +39914,465 @@ static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struc return __pyx_r; } -/* "View.MemoryView":558 - * - * @property - * def shape(self): # <<<<<<<<<<<<<< - * return tuple([length for length in self.view.shape[:self.view.ndim]]) - * +/* "(tree fragment)":1 + * def __pyx_unpickle___Pyx_EnumMeta(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0xd41d8cd: + * from pickle import PickleError as __pyx_PickleError */ /* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_8EnumBase_1__pyx_unpickle___Pyx_EnumMeta(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_8EnumBase_1__pyx_unpickle___Pyx_EnumMeta = {"__pyx_unpickle___Pyx_EnumMeta", (PyCFunction)__pyx_pw_8EnumBase_1__pyx_unpickle___Pyx_EnumMeta, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_8EnumBase_1__pyx_unpickle___Pyx_EnumMeta(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - Py_ssize_t __pyx_v_length; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t *__pyx_t_2; - Py_ssize_t *__pyx_t_3; - Py_ssize_t *__pyx_t_4; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[1], 558, 0, __PYX_ERR(1, 558, __pyx_L1_error)); - - /* "View.MemoryView":559 - * @property - * def shape(self): - * return tuple([length for length in self.view.shape[:self.view.ndim]]) # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim); - for (__pyx_t_4 = __pyx_v_self->view.shape; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) { - __pyx_t_2 = __pyx_t_4; - __pyx_v_length = (__pyx_t_2[0]); - __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(1, 559, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_RefNannySetupContext("__pyx_unpickle___Pyx_EnumMeta (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle___Pyx_EnumMeta", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle___Pyx_EnumMeta", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle___Pyx_EnumMeta") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; } - __pyx_t_5 = PyList_AsTuple(((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; - - /* "View.MemoryView":558 - * - * @property - * def shape(self): # <<<<<<<<<<<<<< - * return tuple([length for length in self.view.shape[:self.view.ndim]]) - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.memoryview.shape.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle___Pyx_EnumMeta", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("EnumBase.__pyx_unpickle___Pyx_EnumMeta", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":562 - * - * @property - * def strides(self): # <<<<<<<<<<<<<< - * if self.view.strides == NULL: - * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8EnumBase___pyx_unpickle___Pyx_EnumMeta(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - Py_ssize_t __pyx_v_stride; +static PyObject *__pyx_pf_8EnumBase___pyx_unpickle___Pyx_EnumMeta(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = NULL; + PyObject *__pyx_v___pyx_result = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; - Py_ssize_t *__pyx_t_3; - Py_ssize_t *__pyx_t_4; - Py_ssize_t *__pyx_t_5; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[1], 562, 0, __PYX_ERR(1, 562, __pyx_L1_error)); + int __pyx_t_7; + __Pyx_TraceFrameInit(__pyx_codeobj__53) + __Pyx_RefNannySetupContext("__pyx_unpickle___Pyx_EnumMeta", 0); + __Pyx_TraceCall("__pyx_unpickle___Pyx_EnumMeta", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); - /* "View.MemoryView":563 - * @property - * def strides(self): - * if self.view.strides == NULL: # <<<<<<<<<<<<<< - * - * raise ValueError("Buffer view does not expose strides") + /* "(tree fragment)":2 + * def __pyx_unpickle___Pyx_EnumMeta(__pyx_type, long __pyx_checksum, __pyx_state): + * if __pyx_checksum != 0xd41d8cd: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum) */ - __pyx_t_1 = ((__pyx_v_self->view.strides == NULL) != 0); - if (unlikely(__pyx_t_1)) { + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xd41d8cd) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":565 - * if self.view.strides == NULL: - * - * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<< - * - * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) + /* "(tree fragment)":3 + * def __pyx_unpickle___Pyx_EnumMeta(__pyx_type, long __pyx_checksum, __pyx_state): + * if __pyx_checksum != 0xd41d8cd: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum) + * __pyx_result = __Pyx_EnumMeta.__new__(__pyx_type) */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__50, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 565, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(1, 565, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "View.MemoryView":563 - * @property - * def strides(self): - * if self.view.strides == NULL: # <<<<<<<<<<<<<< - * - * raise ValueError("Buffer view does not expose strides") + /* "(tree fragment)":4 + * if __pyx_checksum != 0xd41d8cd: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = __Pyx_EnumMeta.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xd4, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_5) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) + + /* "(tree fragment)":2 + * def __pyx_unpickle___Pyx_EnumMeta(__pyx_type, long __pyx_checksum, __pyx_state): + * if __pyx_checksum != 0xd41d8cd: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum) */ } - /* "View.MemoryView":567 - * raise ValueError("Buffer view does not expose strides") - * - * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) # <<<<<<<<<<<<<< - * - * @property + /* "(tree fragment)":5 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum) + * __pyx_result = __Pyx_EnumMeta.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle___Pyx_EnumMeta__set_state(<__Pyx_EnumMeta> __pyx_result, __pyx_state) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 567, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype___Pyx_EnumMeta), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = (__pyx_v_self->view.strides + __pyx_v_self->view.ndim); - for (__pyx_t_5 = __pyx_v_self->view.strides; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) { - __pyx_t_3 = __pyx_t_5; - __pyx_v_stride = (__pyx_t_3[0]); - __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_stride); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 567, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_6))) __PYX_ERR(1, 567, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_INCREF(__pyx_v___pyx_type); + __Pyx_GIVEREF(__pyx_v___pyx_type); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } } - __pyx_t_6 = PyList_AsTuple(((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 567, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_6; - __pyx_t_6 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum) + * __pyx_result = __Pyx_EnumMeta.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle___Pyx_EnumMeta__set_state(<__Pyx_EnumMeta> __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_7 = (__pyx_t_1 != 0); + if (__pyx_t_7) { + + /* "(tree fragment)":7 + * __pyx_result = __Pyx_EnumMeta.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle___Pyx_EnumMeta__set_state(<__Pyx_EnumMeta> __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle___Pyx_EnumMeta__set_state(__Pyx_EnumMeta __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_unpickle___Pyx_EnumMeta__set_state(((struct __pyx_obj___Pyx_EnumMeta *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xd41d8cd = ())" % __pyx_checksum) + * __pyx_result = __Pyx_EnumMeta.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle___Pyx_EnumMeta__set_state(<__Pyx_EnumMeta> __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":8 + * if __pyx_state is not None: + * __pyx_unpickle___Pyx_EnumMeta__set_state(<__Pyx_EnumMeta> __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle___Pyx_EnumMeta__set_state(__Pyx_EnumMeta __pyx_result, tuple __pyx_state): + * if len(__pyx_state) > 0 and hasattr(__pyx_result, '__dict__'): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; goto __pyx_L0; - /* "View.MemoryView":562 - * - * @property - * def strides(self): # <<<<<<<<<<<<<< - * if self.view.strides == NULL: - * + /* "(tree fragment)":1 + * def __pyx_unpickle___Pyx_EnumMeta(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0xd41d8cd: + * from pickle import PickleError as __pyx_PickleError */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("View.MemoryView.memoryview.strides.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("EnumBase.__pyx_unpickle___Pyx_EnumMeta", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":570 - * - * @property - * def suboffsets(self): # <<<<<<<<<<<<<< - * if self.view.suboffsets == NULL: - * return (-1,) * self.view.ndim +/* "(tree fragment)":9 + * __pyx_unpickle___Pyx_EnumMeta__set_state(<__Pyx_EnumMeta> __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle___Pyx_EnumMeta__set_state(__Pyx_EnumMeta __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * if len(__pyx_state) > 0 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[0]) */ -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - Py_ssize_t __pyx_v_suboffset; +static PyObject *__pyx_unpickle___Pyx_EnumMeta__set_state(struct __pyx_obj___Pyx_EnumMeta *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t *__pyx_t_4; - Py_ssize_t *__pyx_t_5; - Py_ssize_t *__pyx_t_6; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[1], 570, 0, __PYX_ERR(1, 570, __pyx_L1_error)); + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("__pyx_unpickle___Pyx_EnumMeta__set_state", 0); + __Pyx_TraceCall("__pyx_unpickle___Pyx_EnumMeta__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); - /* "View.MemoryView":571 - * @property - * def suboffsets(self): - * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<< - * return (-1,) * self.view.ndim - * + /* "(tree fragment)":10 + * return __pyx_result + * cdef __pyx_unpickle___Pyx_EnumMeta__set_state(__Pyx_EnumMeta __pyx_result, tuple __pyx_state): + * if len(__pyx_state) > 0 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[0]) */ - __pyx_t_1 = ((__pyx_v_self->view.suboffsets == NULL) != 0); + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(1, 10, __pyx_L1_error) + } + __pyx_t_2 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_3 = ((__pyx_t_2 > 0) != 0); + if (__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_3 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_4 = (__pyx_t_3 != 0); + __pyx_t_1 = __pyx_t_4; + __pyx_L4_bool_binop_done:; if (__pyx_t_1) { - /* "View.MemoryView":572 - * def suboffsets(self): - * if self.view.suboffsets == NULL: - * return (-1,) * self.view.ndim # <<<<<<<<<<<<<< - * - * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_Multiply(__pyx_tuple__51, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - /* "View.MemoryView":571 - * @property - * def suboffsets(self): - * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<< - * return (-1,) * self.view.ndim - * + /* "(tree fragment)":11 + * cdef __pyx_unpickle___Pyx_EnumMeta__set_state(__Pyx_EnumMeta __pyx_result, tuple __pyx_state): + * if len(__pyx_state) > 0 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[0]) # <<<<<<<<<<<<<< */ - } + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 11, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_8) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "View.MemoryView":574 - * return (-1,) * self.view.ndim - * - * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) # <<<<<<<<<<<<<< - * - * @property + /* "(tree fragment)":10 + * return __pyx_result + * cdef __pyx_unpickle___Pyx_EnumMeta__set_state(__Pyx_EnumMeta __pyx_result, tuple __pyx_state): + * if len(__pyx_state) > 0 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[0]) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 574, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = (__pyx_v_self->view.suboffsets + __pyx_v_self->view.ndim); - for (__pyx_t_6 = __pyx_v_self->view.suboffsets; __pyx_t_6 < __pyx_t_5; __pyx_t_6++) { - __pyx_t_4 = __pyx_t_6; - __pyx_v_suboffset = (__pyx_t_4[0]); - __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_suboffset); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 574, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_2))) __PYX_ERR(1, 574, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } - __pyx_t_2 = PyList_AsTuple(((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 574, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - /* "View.MemoryView":570 - * - * @property - * def suboffsets(self): # <<<<<<<<<<<<<< - * if self.view.suboffsets == NULL: - * return (-1,) * self.view.ndim + /* "(tree fragment)":9 + * __pyx_unpickle___Pyx_EnumMeta__set_state(<__Pyx_EnumMeta> __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle___Pyx_EnumMeta__set_state(__Pyx_EnumMeta __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * if len(__pyx_state) > 0 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[0]) */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview.suboffsets.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("EnumBase.__pyx_unpickle___Pyx_EnumMeta__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); @@ -36279,753 +40380,1242 @@ static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get_ return __pyx_r; } -/* "View.MemoryView":577 +/* "View.MemoryView":121 + * cdef bint dtype_is_object * - * @property - * def ndim(self): # <<<<<<<<<<<<<< - * return self.view.ndim + * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< + * mode="c", bint allocate_buffer=True): * */ /* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations +static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_shape = 0; + Py_ssize_t __pyx_v_itemsize; + PyObject *__pyx_v_format = 0; + PyObject *__pyx_v_mode = 0; + int __pyx_v_allocate_buffer; + int __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[1], 577, 0, __PYX_ERR(1, 577, __pyx_L1_error)); - - /* "View.MemoryView":578 - * @property - * def ndim(self): - * return self.view.ndim # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 578, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_shape,&__pyx_n_s_itemsize,&__pyx_n_s_format,&__pyx_n_s_mode,&__pyx_n_s_allocate_buffer,0}; + PyObject* values[5] = {0,0,0,0,0}; + values[3] = ((PyObject *)__pyx_n_s_c_2); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_shape)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_itemsize)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); __PYX_ERR(1, 121, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); __PYX_ERR(1, 121, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode); + if (value) { values[3] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 4: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_allocate_buffer); + if (value) { values[4] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 121, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_shape = ((PyObject*)values[0]); + __pyx_v_itemsize = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_itemsize == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 121, __pyx_L3_error) + __pyx_v_format = values[2]; + __pyx_v_mode = values[3]; + if (values[4]) { + __pyx_v_allocate_buffer = __Pyx_PyObject_IsTrue(values[4]); if (unlikely((__pyx_v_allocate_buffer == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 122, __pyx_L3_error) + } else { - /* "View.MemoryView":577 + /* "View.MemoryView":122 * - * @property - * def ndim(self): # <<<<<<<<<<<<<< - * return self.view.ndim + * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, + * mode="c", bint allocate_buffer=True): # <<<<<<<<<<<<<< * + * cdef int idx */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview.ndim.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __pyx_v_allocate_buffer = ((int)1); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 121, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_shape), (&PyTuple_Type), 1, "shape", 1))) __PYX_ERR(1, 121, __pyx_L1_error) + if (unlikely(((PyObject *)__pyx_v_format) == Py_None)) { + PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "format"); __PYX_ERR(1, 121, __pyx_L1_error) + } + __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(((struct __pyx_array_obj *)__pyx_v_self), __pyx_v_shape, __pyx_v_itemsize, __pyx_v_format, __pyx_v_mode, __pyx_v_allocate_buffer); -/* "View.MemoryView":581 + /* "View.MemoryView":121 + * cdef bint dtype_is_object * - * @property - * def itemsize(self): # <<<<<<<<<<<<<< - * return self.view.itemsize + * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< + * mode="c", bint allocate_buffer=True): * */ -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer) { + int __pyx_v_idx; + Py_ssize_t __pyx_v_i; + Py_ssize_t __pyx_v_dim; + PyObject **__pyx_v_p; + char __pyx_v_order; + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[1], 581, 0, __PYX_ERR(1, 581, __pyx_L1_error)); + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + char *__pyx_t_6; + int __pyx_t_7; + Py_ssize_t __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + Py_ssize_t __pyx_t_11; + __Pyx_RefNannySetupContext("__cinit__", 0); + __Pyx_TraceCall("__cinit__", __pyx_f[1], 121, 0, __PYX_ERR(1, 121, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_format); - /* "View.MemoryView":582 - * @property - * def itemsize(self): - * return self.view.itemsize # <<<<<<<<<<<<<< + /* "View.MemoryView":128 + * cdef PyObject **p + * + * self.ndim = len(shape) # <<<<<<<<<<<<<< + * self.itemsize = itemsize * - * @property */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 582, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + if (unlikely(__pyx_v_shape == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(1, 128, __pyx_L1_error) + } + __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_shape); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(1, 128, __pyx_L1_error) + __pyx_v_self->ndim = ((int)__pyx_t_1); - /* "View.MemoryView":581 + /* "View.MemoryView":129 * - * @property - * def itemsize(self): # <<<<<<<<<<<<<< - * return self.view.itemsize + * self.ndim = len(shape) + * self.itemsize = itemsize # <<<<<<<<<<<<<< * + * if not self.ndim: */ + __pyx_v_self->itemsize = __pyx_v_itemsize; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview.itemsize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":585 + /* "View.MemoryView":131 + * self.itemsize = itemsize * - * @property - * def nbytes(self): # <<<<<<<<<<<<<< - * return self.size * self.view.itemsize + * if not self.ndim: # <<<<<<<<<<<<<< + * raise ValueError("Empty shape tuple for cython.array") * */ + __pyx_t_2 = ((!(__pyx_v_self->ndim != 0)) != 0); + if (unlikely(__pyx_t_2)) { -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "View.MemoryView":132 + * + * if not self.ndim: + * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<< + * + * if itemsize <= 0: + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 132, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(1, 132, __pyx_L1_error) -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[1], 585, 0, __PYX_ERR(1, 585, __pyx_L1_error)); + /* "View.MemoryView":131 + * self.itemsize = itemsize + * + * if not self.ndim: # <<<<<<<<<<<<<< + * raise ValueError("Empty shape tuple for cython.array") + * + */ + } - /* "View.MemoryView":586 - * @property - * def nbytes(self): - * return self.size * self.view.itemsize # <<<<<<<<<<<<<< + /* "View.MemoryView":134 + * raise ValueError("Empty shape tuple for cython.array") + * + * if itemsize <= 0: # <<<<<<<<<<<<<< + * raise ValueError("itemsize <= 0 for cython.array") * - * @property */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 586, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 586, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 586, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __pyx_t_2 = ((__pyx_v_itemsize <= 0) != 0); + if (unlikely(__pyx_t_2)) { - /* "View.MemoryView":585 + /* "View.MemoryView":135 * - * @property - * def nbytes(self): # <<<<<<<<<<<<<< - * return self.size * self.view.itemsize + * if itemsize <= 0: + * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<< * + * if not isinstance(format, bytes): */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__55, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(1, 135, __pyx_L1_error) - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview.nbytes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "View.MemoryView":134 + * raise ValueError("Empty shape tuple for cython.array") + * + * if itemsize <= 0: # <<<<<<<<<<<<<< + * raise ValueError("itemsize <= 0 for cython.array") + * + */ + } -/* "View.MemoryView":589 + /* "View.MemoryView":137 + * raise ValueError("itemsize <= 0 for cython.array") * - * @property - * def size(self): # <<<<<<<<<<<<<< - * if self._size is None: - * result = 1 + * if not isinstance(format, bytes): # <<<<<<<<<<<<<< + * format = format.encode('ASCII') + * self._format = format # keep a reference to the byte string */ + __pyx_t_2 = PyBytes_Check(__pyx_v_format); + __pyx_t_4 = ((!(__pyx_t_2 != 0)) != 0); + if (__pyx_t_4) { -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + /* "View.MemoryView":138 + * + * if not isinstance(format, bytes): + * format = format.encode('ASCII') # <<<<<<<<<<<<<< + * self._format = format # keep a reference to the byte string + * self.format = self._format + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_format, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__56, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF_SET(__pyx_v_format, __pyx_t_5); + __pyx_t_5 = 0; - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "View.MemoryView":137 + * raise ValueError("itemsize <= 0 for cython.array") + * + * if not isinstance(format, bytes): # <<<<<<<<<<<<<< + * format = format.encode('ASCII') + * self._format = format # keep a reference to the byte string + */ + } -static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_length = NULL; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - Py_ssize_t *__pyx_t_3; - Py_ssize_t *__pyx_t_4; - Py_ssize_t *__pyx_t_5; - PyObject *__pyx_t_6 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[1], 589, 0, __PYX_ERR(1, 589, __pyx_L1_error)); + /* "View.MemoryView":139 + * if not isinstance(format, bytes): + * format = format.encode('ASCII') + * self._format = format # keep a reference to the byte string # <<<<<<<<<<<<<< + * self.format = self._format + * + */ + if (!(likely(PyBytes_CheckExact(__pyx_v_format))||((__pyx_v_format) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_format)->tp_name), 0))) __PYX_ERR(1, 139, __pyx_L1_error) + __pyx_t_5 = __pyx_v_format; + __Pyx_INCREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->_format); + __Pyx_DECREF(__pyx_v_self->_format); + __pyx_v_self->_format = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; - /* "View.MemoryView":590 - * @property - * def size(self): - * if self._size is None: # <<<<<<<<<<<<<< - * result = 1 + /* "View.MemoryView":140 + * format = format.encode('ASCII') + * self._format = format # keep a reference to the byte string + * self.format = self._format # <<<<<<<<<<<<<< + * * */ - __pyx_t_1 = (__pyx_v_self->_size == Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + if (unlikely(__pyx_v_self->_format == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(1, 140, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_PyBytes_AsWritableString(__pyx_v_self->_format); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(1, 140, __pyx_L1_error) + __pyx_v_self->format = __pyx_t_6; - /* "View.MemoryView":591 - * def size(self): - * if self._size is None: - * result = 1 # <<<<<<<<<<<<<< + /* "View.MemoryView":143 + * + * + * self._shape = PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2) # <<<<<<<<<<<<<< + * self._strides = self._shape + self.ndim * - * for length in self.view.shape[:self.view.ndim]: */ - __Pyx_INCREF(__pyx_int_1); - __pyx_v_result = __pyx_int_1; + __pyx_v_self->_shape = ((Py_ssize_t *)PyObject_Malloc((((sizeof(Py_ssize_t)) * __pyx_v_self->ndim) * 2))); - /* "View.MemoryView":593 - * result = 1 + /* "View.MemoryView":144 * - * for length in self.view.shape[:self.view.ndim]: # <<<<<<<<<<<<<< - * result *= length + * self._shape = PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2) + * self._strides = self._shape + self.ndim # <<<<<<<<<<<<<< * + * if not self._shape: */ - __pyx_t_4 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim); - for (__pyx_t_5 = __pyx_v_self->view.shape; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) { - __pyx_t_3 = __pyx_t_5; - __pyx_t_6 = PyInt_FromSsize_t((__pyx_t_3[0])); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 593, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_6); - __pyx_t_6 = 0; + __pyx_v_self->_strides = (__pyx_v_self->_shape + __pyx_v_self->ndim); - /* "View.MemoryView":594 + /* "View.MemoryView":146 + * self._strides = self._shape + self.ndim * - * for length in self.view.shape[:self.view.ndim]: - * result *= length # <<<<<<<<<<<<<< + * if not self._shape: # <<<<<<<<<<<<<< + * raise MemoryError("unable to allocate shape and strides.") * - * self._size = result */ - __pyx_t_6 = PyNumber_InPlaceMultiply(__pyx_v_result, __pyx_v_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 594, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF_SET(__pyx_v_result, __pyx_t_6); - __pyx_t_6 = 0; - } + __pyx_t_4 = ((!(__pyx_v_self->_shape != 0)) != 0); + if (unlikely(__pyx_t_4)) { - /* "View.MemoryView":596 - * result *= length + /* "View.MemoryView":147 + * + * if not self._shape: + * raise MemoryError("unable to allocate shape and strides.") # <<<<<<<<<<<<<< * - * self._size = result # <<<<<<<<<<<<<< * - * return self._size */ - __Pyx_INCREF(__pyx_v_result); - __Pyx_GIVEREF(__pyx_v_result); - __Pyx_GOTREF(__pyx_v_self->_size); - __Pyx_DECREF(__pyx_v_self->_size); - __pyx_v_self->_size = __pyx_v_result; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__57, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 147, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(1, 147, __pyx_L1_error) - /* "View.MemoryView":590 - * @property - * def size(self): - * if self._size is None: # <<<<<<<<<<<<<< - * result = 1 + /* "View.MemoryView":146 + * self._strides = self._shape + self.ndim + * + * if not self._shape: # <<<<<<<<<<<<<< + * raise MemoryError("unable to allocate shape and strides.") * */ } - /* "View.MemoryView":598 - * self._size = result + /* "View.MemoryView":150 * - * return self._size # <<<<<<<<<<<<<< * - * def __len__(self): + * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<< + * if dim <= 0: + * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->_size); - __pyx_r = __pyx_v_self->_size; - goto __pyx_L0; + __pyx_t_7 = 0; + __pyx_t_5 = __pyx_v_shape; __Pyx_INCREF(__pyx_t_5); __pyx_t_1 = 0; + for (;;) { + if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(1, 150, __pyx_L1_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 150, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 150, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_dim = __pyx_t_8; + __pyx_v_idx = __pyx_t_7; + __pyx_t_7 = (__pyx_t_7 + 1); - /* "View.MemoryView":589 + /* "View.MemoryView":151 * - * @property - * def size(self): # <<<<<<<<<<<<<< - * if self._size is None: - * result = 1 + * for idx, dim in enumerate(shape): + * if dim <= 0: # <<<<<<<<<<<<<< + * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) + * self._shape[idx] = dim */ + __pyx_t_4 = ((__pyx_v_dim <= 0) != 0); + if (unlikely(__pyx_t_4)) { - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("View.MemoryView.memoryview.size.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_length); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "View.MemoryView":152 + * for idx, dim in enumerate(shape): + * if dim <= 0: + * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) # <<<<<<<<<<<<<< + * self._shape[idx] = dim + * + */ + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_9); + __pyx_t_3 = 0; + __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_Raise(__pyx_t_10, 0, 0, 0); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __PYX_ERR(1, 152, __pyx_L1_error) -/* "View.MemoryView":600 - * return self._size + /* "View.MemoryView":151 * - * def __len__(self): # <<<<<<<<<<<<<< - * if self.view.ndim >= 1: - * return self.view.shape[0] + * for idx, dim in enumerate(shape): + * if dim <= 0: # <<<<<<<<<<<<<< + * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) + * self._shape[idx] = dim */ + } -/* Python wrapper */ -static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + /* "View.MemoryView":153 + * if dim <= 0: + * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) + * self._shape[idx] = dim # <<<<<<<<<<<<<< + * + * cdef char order + */ + (__pyx_v_self->_shape[__pyx_v_idx]) = __pyx_v_dim; - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "View.MemoryView":150 + * + * + * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<< + * if dim <= 0: + * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) + */ + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; -static Py_ssize_t __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[1], 600, 0, __PYX_ERR(1, 600, __pyx_L1_error)); + /* "View.MemoryView":156 + * + * cdef char order + * if mode == 'fortran': # <<<<<<<<<<<<<< + * order = b'F' + * self.mode = u'fortran' + */ + __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_fortran, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 156, __pyx_L1_error) + if (__pyx_t_4) { - /* "View.MemoryView":601 + /* "View.MemoryView":157 + * cdef char order + * if mode == 'fortran': + * order = b'F' # <<<<<<<<<<<<<< + * self.mode = u'fortran' + * elif mode == 'c': + */ + __pyx_v_order = 'F'; + + /* "View.MemoryView":158 + * if mode == 'fortran': + * order = b'F' + * self.mode = u'fortran' # <<<<<<<<<<<<<< + * elif mode == 'c': + * order = b'C' + */ + __Pyx_INCREF(__pyx_n_u_fortran); + __Pyx_GIVEREF(__pyx_n_u_fortran); + __Pyx_GOTREF(__pyx_v_self->mode); + __Pyx_DECREF(__pyx_v_self->mode); + __pyx_v_self->mode = __pyx_n_u_fortran; + + /* "View.MemoryView":156 * - * def __len__(self): - * if self.view.ndim >= 1: # <<<<<<<<<<<<<< - * return self.view.shape[0] + * cdef char order + * if mode == 'fortran': # <<<<<<<<<<<<<< + * order = b'F' + * self.mode = u'fortran' + */ + goto __pyx_L10; + } + + /* "View.MemoryView":159 + * order = b'F' + * self.mode = u'fortran' + * elif mode == 'c': # <<<<<<<<<<<<<< + * order = b'C' + * self.mode = u'c' + */ + __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_c_2, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 159, __pyx_L1_error) + if (likely(__pyx_t_4)) { + + /* "View.MemoryView":160 + * self.mode = u'fortran' + * elif mode == 'c': + * order = b'C' # <<<<<<<<<<<<<< + * self.mode = u'c' + * else: + */ + __pyx_v_order = 'C'; + + /* "View.MemoryView":161 + * elif mode == 'c': + * order = b'C' + * self.mode = u'c' # <<<<<<<<<<<<<< + * else: + * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) + */ + __Pyx_INCREF(__pyx_n_u_c_2); + __Pyx_GIVEREF(__pyx_n_u_c_2); + __Pyx_GOTREF(__pyx_v_self->mode); + __Pyx_DECREF(__pyx_v_self->mode); + __pyx_v_self->mode = __pyx_n_u_c_2; + + /* "View.MemoryView":159 + * order = b'F' + * self.mode = u'fortran' + * elif mode == 'c': # <<<<<<<<<<<<<< + * order = b'C' + * self.mode = u'c' + */ + goto __pyx_L10; + } + + /* "View.MemoryView":163 + * self.mode = u'c' + * else: + * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) # <<<<<<<<<<<<<< * + * self.len = fill_contig_strides_array(self._shape, self._strides, */ - __pyx_t_1 = ((__pyx_v_self->view.ndim >= 1) != 0); - if (__pyx_t_1) { + /*else*/ { + __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_v_mode); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 163, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 163, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_10, 0, 0, 0); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __PYX_ERR(1, 163, __pyx_L1_error) + } + __pyx_L10:; - /* "View.MemoryView":602 - * def __len__(self): - * if self.view.ndim >= 1: - * return self.view.shape[0] # <<<<<<<<<<<<<< + /* "View.MemoryView":165 + * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) + * + * self.len = fill_contig_strides_array(self._shape, self._strides, # <<<<<<<<<<<<<< + * itemsize, self.ndim, order) * - * return 0 */ - __pyx_r = (__pyx_v_self->view.shape[0]); - goto __pyx_L0; + __pyx_v_self->len = __pyx_fill_contig_strides_array(__pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_itemsize, __pyx_v_self->ndim, __pyx_v_order); - /* "View.MemoryView":601 + /* "View.MemoryView":168 + * itemsize, self.ndim, order) * - * def __len__(self): - * if self.view.ndim >= 1: # <<<<<<<<<<<<<< - * return self.view.shape[0] + * self.free_data = allocate_buffer # <<<<<<<<<<<<<< + * self.dtype_is_object = format == b'O' + * if allocate_buffer: + */ + __pyx_v_self->free_data = __pyx_v_allocate_buffer; + + /* "View.MemoryView":169 + * + * self.free_data = allocate_buffer + * self.dtype_is_object = format == b'O' # <<<<<<<<<<<<<< + * if allocate_buffer: * */ - } + __pyx_t_10 = PyObject_RichCompare(__pyx_v_format, __pyx_n_b_O, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 169, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 169, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_v_self->dtype_is_object = __pyx_t_4; - /* "View.MemoryView":604 - * return self.view.shape[0] + /* "View.MemoryView":170 + * self.free_data = allocate_buffer + * self.dtype_is_object = format == b'O' + * if allocate_buffer: # <<<<<<<<<<<<<< * - * return 0 # <<<<<<<<<<<<<< * - * def __repr__(self): */ - __pyx_r = 0; - goto __pyx_L0; + __pyx_t_4 = (__pyx_v_allocate_buffer != 0); + if (__pyx_t_4) { - /* "View.MemoryView":600 - * return self._size + /* "View.MemoryView":173 * - * def __len__(self): # <<<<<<<<<<<<<< - * if self.view.ndim >= 1: - * return self.view.shape[0] + * + * self.data = malloc(self.len) # <<<<<<<<<<<<<< + * if not self.data: + * raise MemoryError("unable to allocate array data.") */ + __pyx_v_self->data = ((char *)malloc(__pyx_v_self->len)); - /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("View.MemoryView.memoryview.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "View.MemoryView":174 + * + * self.data = malloc(self.len) + * if not self.data: # <<<<<<<<<<<<<< + * raise MemoryError("unable to allocate array data.") + * + */ + __pyx_t_4 = ((!(__pyx_v_self->data != 0)) != 0); + if (unlikely(__pyx_t_4)) { -/* "View.MemoryView":606 - * return 0 + /* "View.MemoryView":175 + * self.data = malloc(self.len) + * if not self.data: + * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<< * - * def __repr__(self): # <<<<<<<<<<<<<< - * return "" % (self.base.__class__.__name__, - * id(self)) + * if self.dtype_is_object: */ + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__58, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 175, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_Raise(__pyx_t_10, 0, 0, 0); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __PYX_ERR(1, 175, __pyx_L1_error) -/* Python wrapper */ -static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + /* "View.MemoryView":174 + * + * self.data = malloc(self.len) + * if not self.data: # <<<<<<<<<<<<<< + * raise MemoryError("unable to allocate array data.") + * + */ + } - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "View.MemoryView":177 + * raise MemoryError("unable to allocate array data.") + * + * if self.dtype_is_object: # <<<<<<<<<<<<<< + * p = self.data + * for i in range(self.len / itemsize): + */ + __pyx_t_4 = (__pyx_v_self->dtype_is_object != 0); + if (__pyx_t_4) { -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__repr__", 0); - __Pyx_TraceCall("__repr__", __pyx_f[1], 606, 0, __PYX_ERR(1, 606, __pyx_L1_error)); + /* "View.MemoryView":178 + * + * if self.dtype_is_object: + * p = self.data # <<<<<<<<<<<<<< + * for i in range(self.len / itemsize): + * p[i] = Py_None + */ + __pyx_v_p = ((PyObject **)__pyx_v_self->data); - /* "View.MemoryView":607 + /* "View.MemoryView":179 + * if self.dtype_is_object: + * p = self.data + * for i in range(self.len / itemsize): # <<<<<<<<<<<<<< + * p[i] = Py_None + * Py_INCREF(Py_None) + */ + if (unlikely(__pyx_v_itemsize == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + __PYX_ERR(1, 179, __pyx_L1_error) + } + else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_self->len))) { + PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); + __PYX_ERR(1, 179, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_div_Py_ssize_t(__pyx_v_self->len, __pyx_v_itemsize); + __pyx_t_8 = __pyx_t_1; + for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_8; __pyx_t_11+=1) { + __pyx_v_i = __pyx_t_11; + + /* "View.MemoryView":180 + * p = self.data + * for i in range(self.len / itemsize): + * p[i] = Py_None # <<<<<<<<<<<<<< + * Py_INCREF(Py_None) * - * def __repr__(self): - * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<< - * id(self)) + */ + (__pyx_v_p[__pyx_v_i]) = Py_None; + + /* "View.MemoryView":181 + * for i in range(self.len / itemsize): + * p[i] = Py_None + * Py_INCREF(Py_None) # <<<<<<<<<<<<<< * + * @cname('getbuffer') */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 607, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 607, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 607, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + Py_INCREF(Py_None); + } - /* "View.MemoryView":608 - * def __repr__(self): - * return "" % (self.base.__class__.__name__, - * id(self)) # <<<<<<<<<<<<<< + /* "View.MemoryView":177 + * raise MemoryError("unable to allocate array data.") * - * def __str__(self): + * if self.dtype_is_object: # <<<<<<<<<<<<<< + * p = self.data + * for i in range(self.len / itemsize): */ - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 608, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + } - /* "View.MemoryView":607 + /* "View.MemoryView":170 + * self.free_data = allocate_buffer + * self.dtype_is_object = format == b'O' + * if allocate_buffer: # <<<<<<<<<<<<<< * - * def __repr__(self): - * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<< - * id(self)) * */ - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 607, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 607, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + } - /* "View.MemoryView":606 - * return 0 + /* "View.MemoryView":121 + * cdef bint dtype_is_object + * + * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<< + * mode="c", bint allocate_buffer=True): * - * def __repr__(self): # <<<<<<<<<<<<<< - * return "" % (self.base.__class__.__name__, - * id(self)) */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_XDECREF(__pyx_v_format); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":610 - * id(self)) - * - * def __str__(self): # <<<<<<<<<<<<<< - * return "" % (self.base.__class__.__name__,) +/* "View.MemoryView":184 * + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< + * cdef int bufmode = -1 + * if self.mode == u"c": */ /* Python wrapper */ -static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ +static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0); + __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(((struct __pyx_array_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { + int __pyx_v_bufmode; + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__str__", 0); - __Pyx_TraceCall("__str__", __pyx_f[1], 610, 0, __PYX_ERR(1, 610, __pyx_L1_error)); + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; + Py_ssize_t __pyx_t_5; + int __pyx_t_6; + Py_ssize_t *__pyx_t_7; + if (__pyx_v_info == NULL) { + PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete"); + return -1; + } + __Pyx_RefNannySetupContext("__getbuffer__", 0); + __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(__pyx_v_info->obj); + __Pyx_TraceCall("__getbuffer__", __pyx_f[1], 184, 0, __PYX_ERR(1, 184, __pyx_L1_error)); - /* "View.MemoryView":611 - * - * def __str__(self): - * return "" % (self.base.__class__.__name__,) # <<<<<<<<<<<<<< - * - * + /* "View.MemoryView":185 + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): + * cdef int bufmode = -1 # <<<<<<<<<<<<<< + * if self.mode == u"c": + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 611, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 611, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 611, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 611, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_object, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 611, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_v_bufmode = -1; - /* "View.MemoryView":610 - * id(self)) + /* "View.MemoryView":186 + * def __getbuffer__(self, Py_buffer *info, int flags): + * cdef int bufmode = -1 + * if self.mode == u"c": # <<<<<<<<<<<<<< + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * elif self.mode == u"fortran": + */ + __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_c_2, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 186, __pyx_L1_error) + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":187 + * cdef int bufmode = -1 + * if self.mode == u"c": + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<< + * elif self.mode == u"fortran": + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + */ + __pyx_v_bufmode = (PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS); + + /* "View.MemoryView":186 + * def __getbuffer__(self, Py_buffer *info, int flags): + * cdef int bufmode = -1 + * if self.mode == u"c": # <<<<<<<<<<<<<< + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * elif self.mode == u"fortran": + */ + goto __pyx_L3; + } + + /* "View.MemoryView":188 + * if self.mode == u"c": + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * elif self.mode == u"fortran": # <<<<<<<<<<<<<< + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * if not (flags & bufmode): + */ + __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_fortran, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 188, __pyx_L1_error) + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":189 + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * elif self.mode == u"fortran": + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<< + * if not (flags & bufmode): + * raise ValueError("Can only create a buffer that is contiguous in memory.") + */ + __pyx_v_bufmode = (PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS); + + /* "View.MemoryView":188 + * if self.mode == u"c": + * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * elif self.mode == u"fortran": # <<<<<<<<<<<<<< + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * if not (flags & bufmode): + */ + } + __pyx_L3:; + + /* "View.MemoryView":190 + * elif self.mode == u"fortran": + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * if not (flags & bufmode): # <<<<<<<<<<<<<< + * raise ValueError("Can only create a buffer that is contiguous in memory.") + * info.buf = self.data + */ + __pyx_t_1 = ((!((__pyx_v_flags & __pyx_v_bufmode) != 0)) != 0); + if (unlikely(__pyx_t_1)) { + + /* "View.MemoryView":191 + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * if not (flags & bufmode): + * raise ValueError("Can only create a buffer that is contiguous in memory.") # <<<<<<<<<<<<<< + * info.buf = self.data + * info.len = self.len + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__59, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(1, 191, __pyx_L1_error) + + /* "View.MemoryView":190 + * elif self.mode == u"fortran": + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * if not (flags & bufmode): # <<<<<<<<<<<<<< + * raise ValueError("Can only create a buffer that is contiguous in memory.") + * info.buf = self.data + */ + } + + /* "View.MemoryView":192 + * if not (flags & bufmode): + * raise ValueError("Can only create a buffer that is contiguous in memory.") + * info.buf = self.data # <<<<<<<<<<<<<< + * info.len = self.len + * info.ndim = self.ndim + */ + __pyx_t_4 = __pyx_v_self->data; + __pyx_v_info->buf = __pyx_t_4; + + /* "View.MemoryView":193 + * raise ValueError("Can only create a buffer that is contiguous in memory.") + * info.buf = self.data + * info.len = self.len # <<<<<<<<<<<<<< + * info.ndim = self.ndim + * info.shape = self._shape + */ + __pyx_t_5 = __pyx_v_self->len; + __pyx_v_info->len = __pyx_t_5; + + /* "View.MemoryView":194 + * info.buf = self.data + * info.len = self.len + * info.ndim = self.ndim # <<<<<<<<<<<<<< + * info.shape = self._shape + * info.strides = self._strides + */ + __pyx_t_6 = __pyx_v_self->ndim; + __pyx_v_info->ndim = __pyx_t_6; + + /* "View.MemoryView":195 + * info.len = self.len + * info.ndim = self.ndim + * info.shape = self._shape # <<<<<<<<<<<<<< + * info.strides = self._strides + * info.suboffsets = NULL + */ + __pyx_t_7 = __pyx_v_self->_shape; + __pyx_v_info->shape = __pyx_t_7; + + /* "View.MemoryView":196 + * info.ndim = self.ndim + * info.shape = self._shape + * info.strides = self._strides # <<<<<<<<<<<<<< + * info.suboffsets = NULL + * info.itemsize = self.itemsize + */ + __pyx_t_7 = __pyx_v_self->_strides; + __pyx_v_info->strides = __pyx_t_7; + + /* "View.MemoryView":197 + * info.shape = self._shape + * info.strides = self._strides + * info.suboffsets = NULL # <<<<<<<<<<<<<< + * info.itemsize = self.itemsize + * info.readonly = 0 + */ + __pyx_v_info->suboffsets = NULL; + + /* "View.MemoryView":198 + * info.strides = self._strides + * info.suboffsets = NULL + * info.itemsize = self.itemsize # <<<<<<<<<<<<<< + * info.readonly = 0 * - * def __str__(self): # <<<<<<<<<<<<<< - * return "" % (self.base.__class__.__name__,) + */ + __pyx_t_5 = __pyx_v_self->itemsize; + __pyx_v_info->itemsize = __pyx_t_5; + + /* "View.MemoryView":199 + * info.suboffsets = NULL + * info.itemsize = self.itemsize + * info.readonly = 0 # <<<<<<<<<<<<<< + * + * if flags & PyBUF_FORMAT: + */ + __pyx_v_info->readonly = 0; + + /* "View.MemoryView":201 + * info.readonly = 0 + * + * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< + * info.format = self.format + * else: + */ + __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":202 + * + * if flags & PyBUF_FORMAT: + * info.format = self.format # <<<<<<<<<<<<<< + * else: + * info.format = NULL + */ + __pyx_t_4 = __pyx_v_self->format; + __pyx_v_info->format = __pyx_t_4; + + /* "View.MemoryView":201 + * info.readonly = 0 + * + * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< + * info.format = self.format + * else: + */ + goto __pyx_L5; + } + + /* "View.MemoryView":204 + * info.format = self.format + * else: + * info.format = NULL # <<<<<<<<<<<<<< + * + * info.obj = self + */ + /*else*/ { + __pyx_v_info->format = NULL; + } + __pyx_L5:; + + /* "View.MemoryView":206 + * info.format = NULL + * + * info.obj = self # <<<<<<<<<<<<<< + * + * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") + */ + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); + __pyx_v_info->obj = ((PyObject *)__pyx_v_self); + + /* "View.MemoryView":184 * + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< + * cdef int bufmode = -1 + * if self.mode == u"c": */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.memoryview.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + if (__pyx_v_info->obj != NULL) { + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; + } + goto __pyx_L2; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + if (__pyx_v_info->obj == Py_None) { + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; + } + __pyx_L2:; + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":614 - * +/* "View.MemoryView":210 + * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") * - * def is_c_contig(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice *mslice - * cdef __Pyx_memviewslice tmp + * def __dealloc__(array self): # <<<<<<<<<<<<<< + * if self.callback_free_data != NULL: + * self.callback_free_data(self.data) */ /* Python wrapper */ -static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; +static void __pyx_array___dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_array___dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("is_c_contig (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(((struct __pyx_memoryview_obj *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(((struct __pyx_array_obj *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); - return __pyx_r; } -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self) { - __Pyx_memviewslice *__pyx_v_mslice; - __Pyx_memviewslice __pyx_v_tmp; - PyObject *__pyx_r = NULL; +static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self) { __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("is_c_contig", 0); - __Pyx_TraceCall("is_c_contig", __pyx_f[1], 614, 0, __PYX_ERR(1, 614, __pyx_L1_error)); + int __pyx_t_1; + __Pyx_RefNannySetupContext("__dealloc__", 0); + __Pyx_TraceCall("__dealloc__", __pyx_f[1], 210, 0, __PYX_ERR(1, 210, __pyx_L1_error)); - /* "View.MemoryView":617 - * cdef __Pyx_memviewslice *mslice - * cdef __Pyx_memviewslice tmp - * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<< - * return slice_is_contig(mslice[0], 'C', self.view.ndim) + /* "View.MemoryView":211 * + * def __dealloc__(array self): + * if self.callback_free_data != NULL: # <<<<<<<<<<<<<< + * self.callback_free_data(self.data) + * elif self.free_data: */ - __pyx_v_mslice = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); + __pyx_t_1 = ((__pyx_v_self->callback_free_data != NULL) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":618 - * cdef __Pyx_memviewslice tmp - * mslice = get_slice_from_memview(self, &tmp) - * return slice_is_contig(mslice[0], 'C', self.view.ndim) # <<<<<<<<<<<<<< + /* "View.MemoryView":212 + * def __dealloc__(array self): + * if self.callback_free_data != NULL: + * self.callback_free_data(self.data) # <<<<<<<<<<<<<< + * elif self.free_data: + * if self.dtype_is_object: + */ + __pyx_v_self->callback_free_data(__pyx_v_self->data); + + /* "View.MemoryView":211 * - * def is_f_contig(self): + * def __dealloc__(array self): + * if self.callback_free_data != NULL: # <<<<<<<<<<<<<< + * self.callback_free_data(self.data) + * elif self.free_data: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'C', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + goto __pyx_L3; + } - /* "View.MemoryView":614 + /* "View.MemoryView":213 + * if self.callback_free_data != NULL: + * self.callback_free_data(self.data) + * elif self.free_data: # <<<<<<<<<<<<<< + * if self.dtype_is_object: + * refcount_objects_in_slice(self.data, self._shape, + */ + __pyx_t_1 = (__pyx_v_self->free_data != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":214 + * self.callback_free_data(self.data) + * elif self.free_data: + * if self.dtype_is_object: # <<<<<<<<<<<<<< + * refcount_objects_in_slice(self.data, self._shape, + * self._strides, self.ndim, False) + */ + __pyx_t_1 = (__pyx_v_self->dtype_is_object != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":215 + * elif self.free_data: + * if self.dtype_is_object: + * refcount_objects_in_slice(self.data, self._shape, # <<<<<<<<<<<<<< + * self._strides, self.ndim, False) + * free(self.data) + */ + __pyx_memoryview_refcount_objects_in_slice(__pyx_v_self->data, __pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_self->ndim, 0); + + /* "View.MemoryView":214 + * self.callback_free_data(self.data) + * elif self.free_data: + * if self.dtype_is_object: # <<<<<<<<<<<<<< + * refcount_objects_in_slice(self.data, self._shape, + * self._strides, self.ndim, False) + */ + } + + /* "View.MemoryView":217 + * refcount_objects_in_slice(self.data, self._shape, + * self._strides, self.ndim, False) + * free(self.data) # <<<<<<<<<<<<<< + * PyObject_Free(self._shape) * + */ + free(__pyx_v_self->data); + + /* "View.MemoryView":213 + * if self.callback_free_data != NULL: + * self.callback_free_data(self.data) + * elif self.free_data: # <<<<<<<<<<<<<< + * if self.dtype_is_object: + * refcount_objects_in_slice(self.data, self._shape, + */ + } + __pyx_L3:; + + /* "View.MemoryView":218 + * self._strides, self.ndim, False) + * free(self.data) + * PyObject_Free(self._shape) # <<<<<<<<<<<<<< * - * def is_c_contig(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice *mslice - * cdef __Pyx_memviewslice tmp + * @property + */ + PyObject_Free(__pyx_v_self->_shape); + + /* "View.MemoryView":210 + * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") + * + * def __dealloc__(array self): # <<<<<<<<<<<<<< + * if self.callback_free_data != NULL: + * self.callback_free_data(self.data) */ /* function exit code */ + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview.is_c_contig", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_WriteUnraisable("View.MemoryView.array.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); - return __pyx_r; } -/* "View.MemoryView":620 - * return slice_is_contig(mslice[0], 'C', self.view.ndim) +/* "View.MemoryView":221 + * + * @property + * def memview(self): # <<<<<<<<<<<<<< + * return self.get_memview() * - * def is_f_contig(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice *mslice - * cdef __Pyx_memviewslice tmp */ /* Python wrapper */ -static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("is_f_contig (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(((struct __pyx_memoryview_obj *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_5array_7memview___get__(((struct __pyx_array_obj *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self) { - __Pyx_memviewslice *__pyx_v_mslice; - __Pyx_memviewslice __pyx_v_tmp; +static PyObject *__pyx_pf_15View_dot_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("is_f_contig", 0); - __Pyx_TraceCall("is_f_contig", __pyx_f[1], 620, 0, __PYX_ERR(1, 620, __pyx_L1_error)); - - /* "View.MemoryView":623 - * cdef __Pyx_memviewslice *mslice - * cdef __Pyx_memviewslice tmp - * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<< - * return slice_is_contig(mslice[0], 'F', self.view.ndim) - * - */ - __pyx_v_mslice = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 221, 0, __PYX_ERR(1, 221, __pyx_L1_error)); - /* "View.MemoryView":624 - * cdef __Pyx_memviewslice tmp - * mslice = get_slice_from_memview(self, &tmp) - * return slice_is_contig(mslice[0], 'F', self.view.ndim) # <<<<<<<<<<<<<< + /* "View.MemoryView":222 + * @property + * def memview(self): + * return self.get_memview() # <<<<<<<<<<<<<< * - * def copy(self): + * @cname('get_memview') */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'F', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 624, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_array *)__pyx_v_self->__pyx_vtab)->get_memview(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 222, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "View.MemoryView":620 - * return slice_is_contig(mslice[0], 'C', self.view.ndim) + /* "View.MemoryView":221 + * + * @property + * def memview(self): # <<<<<<<<<<<<<< + * return self.get_memview() * - * def is_f_contig(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice *mslice - * cdef __Pyx_memviewslice tmp */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview.is_f_contig", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("View.MemoryView.array.memview.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -37034,92 +41624,202 @@ static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18 return __pyx_r; } -/* "View.MemoryView":626 - * return slice_is_contig(mslice[0], 'F', self.view.ndim) +/* "View.MemoryView":225 * - * def copy(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice mslice - * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS + * @cname('get_memview') + * cdef get_memview(self): # <<<<<<<<<<<<<< + * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE + * return memoryview(self, flags, self.dtype_is_object) */ -/* Python wrapper */ -static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; +static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self) { + int __pyx_v_flags; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("copy (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(((struct __pyx_memoryview_obj *)__pyx_v_self)); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("get_memview", 0); + __Pyx_TraceCall("get_memview", __pyx_f[1], 225, 0, __PYX_ERR(1, 225, __pyx_L1_error)); + + /* "View.MemoryView":226 + * @cname('get_memview') + * cdef get_memview(self): + * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE # <<<<<<<<<<<<<< + * return memoryview(self, flags, self.dtype_is_object) + * + */ + __pyx_v_flags = ((PyBUF_ANY_CONTIGUOUS | PyBUF_FORMAT) | PyBUF_WRITABLE); + + /* "View.MemoryView":227 + * cdef get_memview(self): + * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE + * return memoryview(self, flags, self.dtype_is_object) # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 227, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 227, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 227, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 227, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "View.MemoryView":225 + * + * @cname('get_memview') + * cdef get_memview(self): # <<<<<<<<<<<<<< + * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE + * return memoryview(self, flags, self.dtype_is_object) + */ /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.array.get_memview", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self) { - __Pyx_memviewslice __pyx_v_mslice; - int __pyx_v_flags; - PyObject *__pyx_r = NULL; +/* "View.MemoryView":229 + * return memoryview(self, flags, self.dtype_is_object) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self._shape[0] + * + */ + +/* Python wrapper */ +static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(((struct __pyx_array_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static Py_ssize_t __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(struct __pyx_array_obj *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_memviewslice __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("copy", 0); - __Pyx_TraceCall("copy", __pyx_f[1], 626, 0, __PYX_ERR(1, 626, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__len__", 0); + __Pyx_TraceCall("__len__", __pyx_f[1], 229, 0, __PYX_ERR(1, 229, __pyx_L1_error)); - /* "View.MemoryView":628 - * def copy(self): - * cdef __Pyx_memviewslice mslice - * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS # <<<<<<<<<<<<<< + /* "View.MemoryView":230 * - * slice_copy(self, &mslice) + * def __len__(self): + * return self._shape[0] # <<<<<<<<<<<<<< + * + * def __getattr__(self, attr): */ - __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_F_CONTIGUOUS)); + __pyx_r = (__pyx_v_self->_shape[0]); + goto __pyx_L0; - /* "View.MemoryView":630 - * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS + /* "View.MemoryView":229 + * return memoryview(self, flags, self.dtype_is_object) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self._shape[0] * - * slice_copy(self, &mslice) # <<<<<<<<<<<<<< - * mslice = slice_copy_contig(&mslice, "c", self.view.ndim, - * self.view.itemsize, */ - __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_mslice)); - /* "View.MemoryView":631 + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("View.MemoryView.array.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":232 + * return self._shape[0] + * + * def __getattr__(self, attr): # <<<<<<<<<<<<<< + * return getattr(self.memview, attr) * - * slice_copy(self, &mslice) - * mslice = slice_copy_contig(&mslice, "c", self.view.ndim, # <<<<<<<<<<<<<< - * self.view.itemsize, - * flags|PyBUF_C_CONTIGUOUS, */ - __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_mslice), ((char *)"c"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_C_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 631, __pyx_L1_error) - __pyx_v_mslice = __pyx_t_1; - /* "View.MemoryView":636 - * self.dtype_is_object) +/* Python wrapper */ +static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr); /*proto*/ +static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0); + __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_attr)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__getattr__", 0); + __Pyx_TraceCall("__getattr__", __pyx_f[1], 232, 0, __PYX_ERR(1, 232, __pyx_L1_error)); + + /* "View.MemoryView":233 * - * return memoryview_copy_from_slice(self, &mslice) # <<<<<<<<<<<<<< + * def __getattr__(self, attr): + * return getattr(self.memview, attr) # <<<<<<<<<<<<<< * - * def copy_fortran(self): + * def __getitem__(self, item): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_mslice)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 636, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 233, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_GetAttr(__pyx_t_1, __pyx_v_attr); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 233, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "View.MemoryView":626 - * return slice_is_contig(mslice[0], 'F', self.view.ndim) + /* "View.MemoryView":232 + * return self._shape[0] + * + * def __getattr__(self, attr): # <<<<<<<<<<<<<< + * return getattr(self.memview, attr) * - * def copy(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice mslice - * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.memoryview.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("View.MemoryView.array.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -37128,97 +41828,132 @@ static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20 return __pyx_r; } -/* "View.MemoryView":638 - * return memoryview_copy_from_slice(self, &mslice) +/* "View.MemoryView":235 + * return getattr(self.memview, attr) + * + * def __getitem__(self, item): # <<<<<<<<<<<<<< + * return self.memview[item] * - * def copy_fortran(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice src, dst - * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS */ /* Python wrapper */ -static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item); /*proto*/ +static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("copy_fortran (wrapper)", 0); - __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(((struct __pyx_memoryview_obj *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self) { - __Pyx_memviewslice __pyx_v_src; - __Pyx_memviewslice __pyx_v_dst; - int __pyx_v_flags; +static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_memviewslice __pyx_t_1; + PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("copy_fortran", 0); - __Pyx_TraceCall("copy_fortran", __pyx_f[1], 638, 0, __PYX_ERR(1, 638, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__getitem__", 0); + __Pyx_TraceCall("__getitem__", __pyx_f[1], 235, 0, __PYX_ERR(1, 235, __pyx_L1_error)); - /* "View.MemoryView":640 - * def copy_fortran(self): - * cdef __Pyx_memviewslice src, dst - * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS # <<<<<<<<<<<<<< + /* "View.MemoryView":236 * - * slice_copy(self, &src) + * def __getitem__(self, item): + * return self.memview[item] # <<<<<<<<<<<<<< + * + * def __setitem__(self, item, value): */ - __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_C_CONTIGUOUS)); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 236, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_item); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 236, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "View.MemoryView":642 - * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS + /* "View.MemoryView":235 + * return getattr(self.memview, attr) + * + * def __getitem__(self, item): # <<<<<<<<<<<<<< + * return self.memview[item] * - * slice_copy(self, &src) # <<<<<<<<<<<<<< - * dst = slice_copy_contig(&src, "fortran", self.view.ndim, - * self.view.itemsize, */ - __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_src)); - /* "View.MemoryView":643 + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.array.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":238 + * return self.memview[item] + * + * def __setitem__(self, item, value): # <<<<<<<<<<<<<< + * self.memview[item] = value * - * slice_copy(self, &src) - * dst = slice_copy_contig(&src, "fortran", self.view.ndim, # <<<<<<<<<<<<<< - * self.view.itemsize, - * flags|PyBUF_F_CONTIGUOUS, */ - __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_src), ((char *)"fortran"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_F_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 643, __pyx_L1_error) - __pyx_v_dst = __pyx_t_1; - /* "View.MemoryView":648 - * self.dtype_is_object) +/* Python wrapper */ +static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setitem__", 0); + __Pyx_TraceCall("__setitem__", __pyx_f[1], 238, 0, __PYX_ERR(1, 238, __pyx_L1_error)); + + /* "View.MemoryView":239 * - * return memoryview_copy_from_slice(self, &dst) # <<<<<<<<<<<<<< + * def __setitem__(self, item, value): + * self.memview[item] = value # <<<<<<<<<<<<<< * * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_dst)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 648, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_v_item, __pyx_v_value) < 0)) __PYX_ERR(1, 239, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "View.MemoryView":638 - * return memoryview_copy_from_slice(self, &mslice) + /* "View.MemoryView":238 + * return self.memview[item] + * + * def __setitem__(self, item, value): # <<<<<<<<<<<<<< + * self.memview[item] = value * - * def copy_fortran(self): # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice src, dst - * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView.memoryview.copy_fortran", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.array.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } @@ -37230,19 +41965,19 @@ static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22 */ /* Python wrapper */ -static PyObject *__pyx_pw___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf___pyx_memoryview___reduce_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + __pyx_r = __pyx_pf___pyx_array___reduce_cython__(((struct __pyx_array_obj *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self) { +static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -37256,7 +41991,7 @@ static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struc * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__60, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -37271,7 +42006,7 @@ static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struc /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("View.MemoryView.array.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); @@ -37287,19 +42022,19 @@ static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struc */ /* Python wrapper */ -static PyObject *__pyx_pw___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf___pyx_memoryview_2__setstate_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf___pyx_array_2__setstate_cython__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -37312,7 +42047,7 @@ static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED st * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__53, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__61, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -37328,7 +42063,7 @@ static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED st /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("View.MemoryView.array.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); @@ -37336,2805 +42071,3492 @@ static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED st return __pyx_r; } -/* "View.MemoryView":652 +/* "View.MemoryView":243 * - * @cname('__pyx_memoryview_new') - * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): # <<<<<<<<<<<<<< - * cdef memoryview result = memoryview(o, flags, dtype_is_object) - * result.typeinfo = typeinfo + * @cname("__pyx_array_new") + * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<< + * char *mode, char *buf): + * cdef array result */ -static PyObject *__pyx_memoryview_new(PyObject *__pyx_v_o, int __pyx_v_flags, int __pyx_v_dtype_is_object, __Pyx_TypeInfo *__pyx_v_typeinfo) { - struct __pyx_memoryview_obj *__pyx_v_result = 0; - PyObject *__pyx_r = NULL; +static struct __pyx_array_obj *__pyx_array_new(PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, char *__pyx_v_format, char *__pyx_v_mode, char *__pyx_v_buf) { + struct __pyx_array_obj *__pyx_v_result = 0; + struct __pyx_array_obj *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("memoryview_cwrapper", 0); - __Pyx_TraceCall("memoryview_cwrapper", __pyx_f[1], 652, 0, __PYX_ERR(1, 652, __pyx_L1_error)); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("array_cwrapper", 0); + __Pyx_TraceCall("array_cwrapper", __pyx_f[1], 243, 0, __PYX_ERR(1, 243, __pyx_L1_error)); - /* "View.MemoryView":653 - * @cname('__pyx_memoryview_new') - * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): - * cdef memoryview result = memoryview(o, flags, dtype_is_object) # <<<<<<<<<<<<<< - * result.typeinfo = typeinfo - * return result + /* "View.MemoryView":247 + * cdef array result + * + * if buf == NULL: # <<<<<<<<<<<<<< + * result = array(shape, itemsize, format, mode.decode('ASCII')) + * else: */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 653, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 653, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 653, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_o); - __Pyx_GIVEREF(__pyx_v_o); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_o); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 653, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_result = ((struct __pyx_memoryview_obj *)__pyx_t_2); - __pyx_t_2 = 0; + __pyx_t_1 = ((__pyx_v_buf == NULL) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":654 - * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): - * cdef memoryview result = memoryview(o, flags, dtype_is_object) - * result.typeinfo = typeinfo # <<<<<<<<<<<<<< - * return result + /* "View.MemoryView":248 * + * if buf == NULL: + * result = array(shape, itemsize, format, mode.decode('ASCII')) # <<<<<<<<<<<<<< + * else: + * result = array(shape, itemsize, format, mode.decode('ASCII'), */ - __pyx_v_result->typeinfo = __pyx_v_typeinfo; + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 248, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 248, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 248, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 248, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_shape); + __Pyx_GIVEREF(__pyx_v_shape); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_shape); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 248, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_4); + __pyx_t_4 = 0; - /* "View.MemoryView":655 - * cdef memoryview result = memoryview(o, flags, dtype_is_object) - * result.typeinfo = typeinfo - * return result # <<<<<<<<<<<<<< + /* "View.MemoryView":247 + * cdef array result * - * @cname('__pyx_memoryview_check') + * if buf == NULL: # <<<<<<<<<<<<<< + * result = array(shape, itemsize, format, mode.decode('ASCII')) + * else: */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = ((PyObject *)__pyx_v_result); - goto __pyx_L0; + goto __pyx_L3; + } - /* "View.MemoryView":652 + /* "View.MemoryView":250 + * result = array(shape, itemsize, format, mode.decode('ASCII')) + * else: + * result = array(shape, itemsize, format, mode.decode('ASCII'), # <<<<<<<<<<<<<< + * allocate_buffer=False) + * result.data = buf + */ + /*else*/ { + __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_shape); + __Pyx_GIVEREF(__pyx_v_shape); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_shape); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_3); + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_3 = 0; + + /* "View.MemoryView":251 + * else: + * result = array(shape, itemsize, format, mode.decode('ASCII'), + * allocate_buffer=False) # <<<<<<<<<<<<<< + * result.data = buf * - * @cname('__pyx_memoryview_new') - * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): # <<<<<<<<<<<<<< - * cdef memoryview result = memoryview(o, flags, dtype_is_object) - * result.typeinfo = typeinfo */ + __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_allocate_buffer, Py_False) < 0) __PYX_ERR(1, 251, __pyx_L1_error) - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; + /* "View.MemoryView":250 + * result = array(shape, itemsize, format, mode.decode('ASCII')) + * else: + * result = array(shape, itemsize, format, mode.decode('ASCII'), # <<<<<<<<<<<<<< + * allocate_buffer=False) + * result.data = buf + */ + __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_5); + __pyx_t_5 = 0; + + /* "View.MemoryView":252 + * result = array(shape, itemsize, format, mode.decode('ASCII'), + * allocate_buffer=False) + * result.data = buf # <<<<<<<<<<<<<< + * + * return result + */ + __pyx_v_result->data = __pyx_v_buf; + } + __pyx_L3:; + + /* "View.MemoryView":254 + * result.data = buf + * + * return result # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + /* "View.MemoryView":243 + * + * @cname("__pyx_array_new") + * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<< + * char *mode, char *buf): + * cdef array result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.array_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":658 - * - * @cname('__pyx_memoryview_check') - * cdef inline bint memoryview_check(object o): # <<<<<<<<<<<<<< - * return isinstance(o, memoryview) - * +/* "View.MemoryView":280 + * cdef class Enum(object): + * cdef object name + * def __init__(self, name): # <<<<<<<<<<<<<< + * self.name = name + * def __repr__(self): */ -static CYTHON_INLINE int __pyx_memoryview_check(PyObject *__pyx_v_o) { +/* Python wrapper */ +static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_name = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(1, 280, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + } + __pyx_v_name = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 280, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("View.MemoryView.Enum.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), __pyx_v_name); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("memoryview_check", 0); - __Pyx_TraceCall("memoryview_check", __pyx_f[1], 658, 0, __PYX_ERR(1, 658, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__init__", 0); + __Pyx_TraceCall("__init__", __pyx_f[1], 280, 0, __PYX_ERR(1, 280, __pyx_L1_error)); - /* "View.MemoryView":659 - * @cname('__pyx_memoryview_check') - * cdef inline bint memoryview_check(object o): - * return isinstance(o, memoryview) # <<<<<<<<<<<<<< - * - * cdef tuple _unellipsify(object index, int ndim): + /* "View.MemoryView":281 + * cdef object name + * def __init__(self, name): + * self.name = name # <<<<<<<<<<<<<< + * def __repr__(self): + * return self.name */ - __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_o, __pyx_memoryview_type); - __pyx_r = __pyx_t_1; + __Pyx_INCREF(__pyx_v_name); + __Pyx_GIVEREF(__pyx_v_name); + __Pyx_GOTREF(__pyx_v_self->name); + __Pyx_DECREF(__pyx_v_self->name); + __pyx_v_self->name = __pyx_v_name; + + /* "View.MemoryView":280 + * cdef class Enum(object): + * cdef object name + * def __init__(self, name): # <<<<<<<<<<<<<< + * self.name = name + * def __repr__(self): + */ + + /* function exit code */ + __pyx_r = 0; goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("View.MemoryView.Enum.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":658 +/* "View.MemoryView":282 + * def __init__(self, name): + * self.name = name + * def __repr__(self): # <<<<<<<<<<<<<< + * return self.name * - * @cname('__pyx_memoryview_check') - * cdef inline bint memoryview_check(object o): # <<<<<<<<<<<<<< - * return isinstance(o, memoryview) + */ + +/* Python wrapper */ +static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0); + __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__repr__", 0); + __Pyx_TraceCall("__repr__", __pyx_f[1], 282, 0, __PYX_ERR(1, 282, __pyx_L1_error)); + + /* "View.MemoryView":283 + * self.name = name + * def __repr__(self): + * return self.name # <<<<<<<<<<<<<< + * + * cdef generic = Enum("") + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->name); + __pyx_r = __pyx_v_self->name; + goto __pyx_L0; + + /* "View.MemoryView":282 + * def __init__(self, name): + * self.name = name + * def __repr__(self): # <<<<<<<<<<<<<< + * return self.name * */ /* function exit code */ __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.memoryview_check", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_r = 0; + __Pyx_AddTraceback("View.MemoryView.Enum.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":661 - * return isinstance(o, memoryview) - * - * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<< - * """ - * Replace all ellipses with full slices and fill incomplete indices with +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef bint use_setstate + * state = (self.name,) */ -static PyObject *_unellipsify(PyObject *__pyx_v_index, int __pyx_v_ndim) { - PyObject *__pyx_v_tup = NULL; - PyObject *__pyx_v_result = NULL; - int __pyx_v_have_slices; - int __pyx_v_seen_ellipsis; - CYTHON_UNUSED PyObject *__pyx_v_idx = NULL; - PyObject *__pyx_v_item = NULL; - Py_ssize_t __pyx_v_nslices; +/* Python wrapper */ +static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf___pyx_MemviewEnum___reduce_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_MemviewEnum___reduce_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self) { + int __pyx_v_use_setstate; + PyObject *__pyx_v_state = NULL; + PyObject *__pyx_v__dict = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; + PyObject *__pyx_t_1 = NULL; int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; + int __pyx_t_3; PyObject *__pyx_t_4 = NULL; - Py_ssize_t __pyx_t_5; - PyObject *(*__pyx_t_6)(PyObject *); - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - PyObject *__pyx_t_11 = NULL; - __Pyx_RefNannySetupContext("_unellipsify", 0); - __Pyx_TraceCall("_unellipsify", __pyx_f[1], 661, 0, __PYX_ERR(1, 661, __pyx_L1_error)); + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); - /* "View.MemoryView":666 - * full slices. - * """ - * if not isinstance(index, tuple): # <<<<<<<<<<<<<< - * tup = (index,) - * else: + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * cdef bint use_setstate + * state = (self.name,) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: */ - __pyx_t_1 = PyTuple_Check(__pyx_v_index); - __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); - if (__pyx_t_2) { + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->name); + __pyx_v_state = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "View.MemoryView":667 - * """ - * if not isinstance(index, tuple): - * tup = (index,) # <<<<<<<<<<<<<< + /* "(tree fragment)":4 + * cdef bint use_setstate + * state = (self.name,) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v__dict = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":5 + * state = (self.name,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_2 = (__pyx_v__dict != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":6 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True * else: - * tup = index */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 667, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_index); - __Pyx_GIVEREF(__pyx_v_index); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_index); - __pyx_v_tup = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; - /* "View.MemoryView":666 - * full slices. - * """ - * if not isinstance(index, tuple): # <<<<<<<<<<<<<< - * tup = (index,) + /* "(tree fragment)":7 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< * else: + * use_setstate = self.name is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":5 + * state = (self.name,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True */ goto __pyx_L3; } - /* "View.MemoryView":669 - * tup = (index,) + /* "(tree fragment)":9 + * use_setstate = True * else: - * tup = index # <<<<<<<<<<<<<< - * - * result = [] + * use_setstate = self.name is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state */ /*else*/ { - __Pyx_INCREF(__pyx_v_index); - __pyx_v_tup = __pyx_v_index; + __pyx_t_3 = (__pyx_v_self->name != Py_None); + __pyx_v_use_setstate = __pyx_t_3; } __pyx_L3:; - /* "View.MemoryView":671 - * tup = index - * - * result = [] # <<<<<<<<<<<<<< - * have_slices = False - * seen_ellipsis = False + /* "(tree fragment)":10 + * else: + * use_setstate = self.name is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state + * else: */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 671, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_result = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_3 = (__pyx_v_use_setstate != 0); + if (__pyx_t_3) { - /* "View.MemoryView":672 - * - * result = [] - * have_slices = False # <<<<<<<<<<<<<< - * seen_ellipsis = False - * for idx, item in enumerate(tup): + /* "(tree fragment)":11 + * use_setstate = self.name is not None + * if use_setstate: + * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) */ - __pyx_v_have_slices = 0; + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_184977713); + __Pyx_GIVEREF(__pyx_int_184977713); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; - /* "View.MemoryView":673 - * result = [] - * have_slices = False - * seen_ellipsis = False # <<<<<<<<<<<<<< - * for idx, item in enumerate(tup): - * if item is Ellipsis: + /* "(tree fragment)":10 + * else: + * use_setstate = self.name is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state + * else: */ - __pyx_v_seen_ellipsis = 0; + } - /* "View.MemoryView":674 - * have_slices = False - * seen_ellipsis = False - * for idx, item in enumerate(tup): # <<<<<<<<<<<<<< - * if item is Ellipsis: - * if not seen_ellipsis: + /* "(tree fragment)":13 + * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state + * else: + * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_Enum__set_state(self, __pyx_state) */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_3 = __pyx_int_0; - if (likely(PyList_CheckExact(__pyx_v_tup)) || PyTuple_CheckExact(__pyx_v_tup)) { - __pyx_t_4 = __pyx_v_tup; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0; - __pyx_t_6 = NULL; - } else { - __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_tup); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 674, __pyx_L1_error) + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_184977713); + __Pyx_GIVEREF(__pyx_int_184977713); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 674, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __pyx_t_5 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; } - for (;;) { - if (likely(!__pyx_t_6)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 674, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } else { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 674, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } - } else { - __pyx_t_7 = __pyx_t_6(__pyx_t_4); - if (unlikely(!__pyx_t_7)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(1, 674, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_7); - } - __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_INCREF(__pyx_t_3); - __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_3); - __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); - __pyx_t_3 = __pyx_t_7; - __pyx_t_7 = 0; - /* "View.MemoryView":675 - * seen_ellipsis = False - * for idx, item in enumerate(tup): - * if item is Ellipsis: # <<<<<<<<<<<<<< - * if not seen_ellipsis: - * result.extend([slice(None)] * (ndim - len(tup) + 1)) + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef bint use_setstate + * state = (self.name,) */ - __pyx_t_2 = (__pyx_v_item == __pyx_builtin_Ellipsis); - __pyx_t_1 = (__pyx_t_2 != 0); - if (__pyx_t_1) { - /* "View.MemoryView":676 - * for idx, item in enumerate(tup): - * if item is Ellipsis: - * if not seen_ellipsis: # <<<<<<<<<<<<<< - * result.extend([slice(None)] * (ndim - len(tup) + 1)) - * seen_ellipsis = True - */ - __pyx_t_1 = ((!(__pyx_v_seen_ellipsis != 0)) != 0); - if (__pyx_t_1) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.Enum.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":677 - * if item is Ellipsis: - * if not seen_ellipsis: - * result.extend([slice(None)] * (ndim - len(tup) + 1)) # <<<<<<<<<<<<<< - * seen_ellipsis = True - * else: +/* "(tree fragment)":14 + * else: + * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_Enum__set_state(self, __pyx_state) */ - __pyx_t_8 = PyObject_Length(__pyx_v_tup); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(1, 677, __pyx_L1_error) - __pyx_t_7 = PyList_New(1 * ((((__pyx_v_ndim - __pyx_t_8) + 1)<0) ? 0:((__pyx_v_ndim - __pyx_t_8) + 1))); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 677, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - { Py_ssize_t __pyx_temp; - for (__pyx_temp=0; __pyx_temp < ((__pyx_v_ndim - __pyx_t_8) + 1); __pyx_temp++) { - __Pyx_INCREF(__pyx_slice__54); - __Pyx_GIVEREF(__pyx_slice__54); - PyList_SET_ITEM(__pyx_t_7, __pyx_temp, __pyx_slice__54); - } - } - __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 677, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "View.MemoryView":678 - * if not seen_ellipsis: - * result.extend([slice(None)] * (ndim - len(tup) + 1)) - * seen_ellipsis = True # <<<<<<<<<<<<<< - * else: - * result.append(slice(None)) - */ - __pyx_v_seen_ellipsis = 1; +/* Python wrapper */ +static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf___pyx_MemviewEnum_2__setstate_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); - /* "View.MemoryView":676 - * for idx, item in enumerate(tup): - * if item is Ellipsis: - * if not seen_ellipsis: # <<<<<<<<<<<<<< - * result.extend([slice(None)] * (ndim - len(tup) + 1)) - * seen_ellipsis = True - */ - goto __pyx_L7; - } + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":680 - * seen_ellipsis = True - * else: - * result.append(slice(None)) # <<<<<<<<<<<<<< - * have_slices = True - * else: - */ - /*else*/ { - __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_slice__55); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 680, __pyx_L1_error) - } - __pyx_L7:; +static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); - /* "View.MemoryView":681 - * else: - * result.append(slice(None)) - * have_slices = True # <<<<<<<<<<<<<< - * else: - * if not isinstance(item, slice) and not PyIndex_Check(item): + /* "(tree fragment)":15 + * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_Enum__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - __pyx_v_have_slices = 1; + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_unpickle_Enum__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "View.MemoryView":675 - * seen_ellipsis = False - * for idx, item in enumerate(tup): - * if item is Ellipsis: # <<<<<<<<<<<<<< - * if not seen_ellipsis: - * result.extend([slice(None)] * (ndim - len(tup) + 1)) + /* "(tree fragment)":14 + * else: + * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_Enum__set_state(self, __pyx_state) */ - goto __pyx_L6; - } - /* "View.MemoryView":683 - * have_slices = True - * else: - * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<< - * raise TypeError("Cannot index with type '%s'" % type(item)) - * - */ - /*else*/ { - __pyx_t_2 = PySlice_Check(__pyx_v_item); - __pyx_t_10 = ((!(__pyx_t_2 != 0)) != 0); - if (__pyx_t_10) { - } else { - __pyx_t_1 = __pyx_t_10; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_10 = ((!(PyIndex_Check(__pyx_v_item) != 0)) != 0); - __pyx_t_1 = __pyx_t_10; - __pyx_L9_bool_binop_done:; - if (unlikely(__pyx_t_1)) { + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.Enum.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":684 - * else: - * if not isinstance(item, slice) and not PyIndex_Check(item): - * raise TypeError("Cannot index with type '%s'" % type(item)) # <<<<<<<<<<<<<< +/* "View.MemoryView":297 * - * have_slices = have_slices or isinstance(item, slice) + * @cname('__pyx_align_pointer') + * cdef void *align_pointer(void *memory, size_t alignment) nogil: # <<<<<<<<<<<<<< + * "Align pointer memory on a given boundary" + * cdef Py_intptr_t aligned_p = memory */ - __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_Cannot_index_with_type_s, ((PyObject *)Py_TYPE(__pyx_v_item))); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 684, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 684, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_Raise(__pyx_t_11, 0, 0, 0); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __PYX_ERR(1, 684, __pyx_L1_error) - /* "View.MemoryView":683 - * have_slices = True - * else: - * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<< - * raise TypeError("Cannot index with type '%s'" % type(item)) - * - */ - } +static void *__pyx_align_pointer(void *__pyx_v_memory, size_t __pyx_v_alignment) { + Py_intptr_t __pyx_v_aligned_p; + size_t __pyx_v_offset; + void *__pyx_r; + __Pyx_TraceDeclarations + int __pyx_t_1; + __Pyx_TraceCall("align_pointer", __pyx_f[1], 297, 1, __PYX_ERR(1, 297, __pyx_L1_error)); - /* "View.MemoryView":686 - * raise TypeError("Cannot index with type '%s'" % type(item)) - * - * have_slices = have_slices or isinstance(item, slice) # <<<<<<<<<<<<<< - * result.append(item) + /* "View.MemoryView":299 + * cdef void *align_pointer(void *memory, size_t alignment) nogil: + * "Align pointer memory on a given boundary" + * cdef Py_intptr_t aligned_p = memory # <<<<<<<<<<<<<< + * cdef size_t offset * */ - __pyx_t_10 = (__pyx_v_have_slices != 0); - if (!__pyx_t_10) { - } else { - __pyx_t_1 = __pyx_t_10; - goto __pyx_L11_bool_binop_done; - } - __pyx_t_10 = PySlice_Check(__pyx_v_item); - __pyx_t_2 = (__pyx_t_10 != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L11_bool_binop_done:; - __pyx_v_have_slices = __pyx_t_1; + __pyx_v_aligned_p = ((Py_intptr_t)__pyx_v_memory); - /* "View.MemoryView":687 - * - * have_slices = have_slices or isinstance(item, slice) - * result.append(item) # <<<<<<<<<<<<<< + /* "View.MemoryView":303 * - * nslices = ndim - len(result) - */ - __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_v_item); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 687, __pyx_L1_error) - } - __pyx_L6:; - - /* "View.MemoryView":674 - * have_slices = False - * seen_ellipsis = False - * for idx, item in enumerate(tup): # <<<<<<<<<<<<<< - * if item is Ellipsis: - * if not seen_ellipsis: - */ - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "View.MemoryView":689 - * result.append(item) + * with cython.cdivision(True): + * offset = aligned_p % alignment # <<<<<<<<<<<<<< * - * nslices = ndim - len(result) # <<<<<<<<<<<<<< - * if nslices: - * result.extend([slice(None)] * nslices) + * if offset > 0: */ - __pyx_t_5 = PyList_GET_SIZE(__pyx_v_result); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(1, 689, __pyx_L1_error) - __pyx_v_nslices = (__pyx_v_ndim - __pyx_t_5); + __pyx_v_offset = (__pyx_v_aligned_p % __pyx_v_alignment); - /* "View.MemoryView":690 + /* "View.MemoryView":305 + * offset = aligned_p % alignment * - * nslices = ndim - len(result) - * if nslices: # <<<<<<<<<<<<<< - * result.extend([slice(None)] * nslices) + * if offset > 0: # <<<<<<<<<<<<<< + * aligned_p += alignment - offset * */ - __pyx_t_1 = (__pyx_v_nslices != 0); + __pyx_t_1 = ((__pyx_v_offset > 0) != 0); if (__pyx_t_1) { - /* "View.MemoryView":691 - * nslices = ndim - len(result) - * if nslices: - * result.extend([slice(None)] * nslices) # <<<<<<<<<<<<<< + /* "View.MemoryView":306 * - * return have_slices or nslices, tuple(result) + * if offset > 0: + * aligned_p += alignment - offset # <<<<<<<<<<<<<< + * + * return aligned_p */ - __pyx_t_3 = PyList_New(1 * ((__pyx_v_nslices<0) ? 0:__pyx_v_nslices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 691, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - { Py_ssize_t __pyx_temp; - for (__pyx_temp=0; __pyx_temp < __pyx_v_nslices; __pyx_temp++) { - __Pyx_INCREF(__pyx_slice__56); - __Pyx_GIVEREF(__pyx_slice__56); - PyList_SET_ITEM(__pyx_t_3, __pyx_temp, __pyx_slice__56); - } - } - __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 691, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_aligned_p = (__pyx_v_aligned_p + (__pyx_v_alignment - __pyx_v_offset)); - /* "View.MemoryView":690 + /* "View.MemoryView":305 + * offset = aligned_p % alignment * - * nslices = ndim - len(result) - * if nslices: # <<<<<<<<<<<<<< - * result.extend([slice(None)] * nslices) + * if offset > 0: # <<<<<<<<<<<<<< + * aligned_p += alignment - offset * */ } - /* "View.MemoryView":693 - * result.extend([slice(None)] * nslices) + /* "View.MemoryView":308 + * aligned_p += alignment - offset + * + * return aligned_p # <<<<<<<<<<<<<< * - * return have_slices or nslices, tuple(result) # <<<<<<<<<<<<<< * - * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): */ - __Pyx_XDECREF(__pyx_r); - if (!__pyx_v_have_slices) { - } else { - __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_have_slices); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L14_bool_binop_done; - } - __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_nslices); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __pyx_t_4; - __pyx_t_4 = 0; - __pyx_L14_bool_binop_done:; - __pyx_t_4 = PyList_AsTuple(__pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 693, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_4); - __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_r = ((PyObject*)__pyx_t_11); - __pyx_t_11 = 0; + __pyx_r = ((void *)__pyx_v_aligned_p); goto __pyx_L0; - /* "View.MemoryView":661 - * return isinstance(o, memoryview) + /* "View.MemoryView":297 * - * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<< - * """ - * Replace all ellipses with full slices and fill incomplete indices with + * @cname('__pyx_align_pointer') + * cdef void *align_pointer(void *memory, size_t alignment) nogil: # <<<<<<<<<<<<<< + * "Align pointer memory on a given boundary" + * cdef Py_intptr_t aligned_p = memory */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("View.MemoryView._unellipsify", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_WriteUnraisable("View.MemoryView.align_pointer", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); __pyx_r = 0; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_tup); - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_idx); - __Pyx_XDECREF(__pyx_v_item); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); + __Pyx_TraceReturn(Py_None, 1); return __pyx_r; } -/* "View.MemoryView":695 - * return have_slices or nslices, tuple(result) +/* "View.MemoryView":344 + * cdef __Pyx_TypeInfo *typeinfo * - * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<< - * for suboffset in suboffsets[:ndim]: - * if suboffset >= 0: + * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): # <<<<<<<<<<<<<< + * self.obj = obj + * self.flags = flags */ -static PyObject *assert_direct_dimensions(Py_ssize_t *__pyx_v_suboffsets, int __pyx_v_ndim) { - Py_ssize_t __pyx_v_suboffset; - PyObject *__pyx_r = NULL; +/* Python wrapper */ +static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_obj = 0; + int __pyx_v_flags; + int __pyx_v_dtype_is_object; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_obj,&__pyx_n_s_flags,&__pyx_n_s_dtype_is_object,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_obj)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flags)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); __PYX_ERR(1, 344, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dtype_is_object); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 344, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_obj = values[0]; + __pyx_v_flags = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 344, __pyx_L3_error) + if (values[2]) { + __pyx_v_dtype_is_object = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_dtype_is_object == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 344, __pyx_L3_error) + } else { + __pyx_v_dtype_is_object = ((int)0); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 344, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_obj, __pyx_v_flags, __pyx_v_dtype_is_object); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - Py_ssize_t *__pyx_t_1; - Py_ssize_t *__pyx_t_2; - Py_ssize_t *__pyx_t_3; + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("assert_direct_dimensions", 0); - __Pyx_TraceCall("assert_direct_dimensions", __pyx_f[1], 695, 0, __PYX_ERR(1, 695, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__cinit__", 0); + __Pyx_TraceCall("__cinit__", __pyx_f[1], 344, 0, __PYX_ERR(1, 344, __pyx_L1_error)); - /* "View.MemoryView":696 + /* "View.MemoryView":345 * - * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): - * for suboffset in suboffsets[:ndim]: # <<<<<<<<<<<<<< - * if suboffset >= 0: - * raise ValueError("Indirect dimensions not supported") + * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): + * self.obj = obj # <<<<<<<<<<<<<< + * self.flags = flags + * if type(self) is memoryview or obj is not None: */ - __pyx_t_2 = (__pyx_v_suboffsets + __pyx_v_ndim); - for (__pyx_t_3 = __pyx_v_suboffsets; __pyx_t_3 < __pyx_t_2; __pyx_t_3++) { - __pyx_t_1 = __pyx_t_3; - __pyx_v_suboffset = (__pyx_t_1[0]); + __Pyx_INCREF(__pyx_v_obj); + __Pyx_GIVEREF(__pyx_v_obj); + __Pyx_GOTREF(__pyx_v_self->obj); + __Pyx_DECREF(__pyx_v_self->obj); + __pyx_v_self->obj = __pyx_v_obj; - /* "View.MemoryView":697 - * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): - * for suboffset in suboffsets[:ndim]: - * if suboffset >= 0: # <<<<<<<<<<<<<< - * raise ValueError("Indirect dimensions not supported") - * + /* "View.MemoryView":346 + * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): + * self.obj = obj + * self.flags = flags # <<<<<<<<<<<<<< + * if type(self) is memoryview or obj is not None: + * __Pyx_GetBuffer(obj, &self.view, flags) */ - __pyx_t_4 = ((__pyx_v_suboffset >= 0) != 0); - if (unlikely(__pyx_t_4)) { + __pyx_v_self->flags = __pyx_v_flags; - /* "View.MemoryView":698 - * for suboffset in suboffsets[:ndim]: - * if suboffset >= 0: - * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__57, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 698, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(1, 698, __pyx_L1_error) - - /* "View.MemoryView":697 - * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): - * for suboffset in suboffsets[:ndim]: - * if suboffset >= 0: # <<<<<<<<<<<<<< - * raise ValueError("Indirect dimensions not supported") - * + /* "View.MemoryView":347 + * self.obj = obj + * self.flags = flags + * if type(self) is memoryview or obj is not None: # <<<<<<<<<<<<<< + * __Pyx_GetBuffer(obj, &self.view, flags) + * if self.view.obj == NULL: */ - } + __pyx_t_2 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_memoryview_type)); + __pyx_t_3 = (__pyx_t_2 != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; } + __pyx_t_3 = (__pyx_v_obj != Py_None); + __pyx_t_2 = (__pyx_t_3 != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { - /* "View.MemoryView":695 - * return have_slices or nslices, tuple(result) - * - * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<< - * for suboffset in suboffsets[:ndim]: - * if suboffset >= 0: + /* "View.MemoryView":348 + * self.flags = flags + * if type(self) is memoryview or obj is not None: + * __Pyx_GetBuffer(obj, &self.view, flags) # <<<<<<<<<<<<<< + * if self.view.obj == NULL: + * (<__pyx_buffer *> &self.view).obj = Py_None */ + __pyx_t_4 = __Pyx_GetBuffer(__pyx_v_obj, (&__pyx_v_self->view), __pyx_v_flags); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 348, __pyx_L1_error) - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.assert_direct_dimensions", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":705 - * - * @cname('__pyx_memview_slice') - * cdef memoryview memview_slice(memoryview memview, object indices): # <<<<<<<<<<<<<< - * cdef int new_ndim = 0, suboffset_dim = -1, dim - * cdef bint negative_step + /* "View.MemoryView":349 + * if type(self) is memoryview or obj is not None: + * __Pyx_GetBuffer(obj, &self.view, flags) + * if self.view.obj == NULL: # <<<<<<<<<<<<<< + * (<__pyx_buffer *> &self.view).obj = Py_None + * Py_INCREF(Py_None) */ + __pyx_t_1 = ((((PyObject *)__pyx_v_self->view.obj) == NULL) != 0); + if (__pyx_t_1) { -static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *__pyx_v_memview, PyObject *__pyx_v_indices) { - int __pyx_v_new_ndim; - int __pyx_v_suboffset_dim; - int __pyx_v_dim; - __Pyx_memviewslice __pyx_v_src; - __Pyx_memviewslice __pyx_v_dst; - __Pyx_memviewslice *__pyx_v_p_src; - struct __pyx_memoryviewslice_obj *__pyx_v_memviewsliceobj = 0; - __Pyx_memviewslice *__pyx_v_p_dst; - int *__pyx_v_p_suboffset_dim; - Py_ssize_t __pyx_v_start; - Py_ssize_t __pyx_v_stop; - Py_ssize_t __pyx_v_step; - int __pyx_v_have_start; - int __pyx_v_have_stop; - int __pyx_v_have_step; - PyObject *__pyx_v_index = NULL; - struct __pyx_memoryview_obj *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - struct __pyx_memoryview_obj *__pyx_t_4; - char *__pyx_t_5; - int __pyx_t_6; - Py_ssize_t __pyx_t_7; - PyObject *(*__pyx_t_8)(PyObject *); - PyObject *__pyx_t_9 = NULL; - Py_ssize_t __pyx_t_10; - int __pyx_t_11; - Py_ssize_t __pyx_t_12; - __Pyx_RefNannySetupContext("memview_slice", 0); - __Pyx_TraceCall("memview_slice", __pyx_f[1], 705, 0, __PYX_ERR(1, 705, __pyx_L1_error)); - - /* "View.MemoryView":706 - * @cname('__pyx_memview_slice') - * cdef memoryview memview_slice(memoryview memview, object indices): - * cdef int new_ndim = 0, suboffset_dim = -1, dim # <<<<<<<<<<<<<< - * cdef bint negative_step - * cdef __Pyx_memviewslice src, dst + /* "View.MemoryView":350 + * __Pyx_GetBuffer(obj, &self.view, flags) + * if self.view.obj == NULL: + * (<__pyx_buffer *> &self.view).obj = Py_None # <<<<<<<<<<<<<< + * Py_INCREF(Py_None) + * */ - __pyx_v_new_ndim = 0; - __pyx_v_suboffset_dim = -1; + ((Py_buffer *)(&__pyx_v_self->view))->obj = Py_None; - /* "View.MemoryView":713 - * - * - * memset(&dst, 0, sizeof(dst)) # <<<<<<<<<<<<<< + /* "View.MemoryView":351 + * if self.view.obj == NULL: + * (<__pyx_buffer *> &self.view).obj = Py_None + * Py_INCREF(Py_None) # <<<<<<<<<<<<<< * - * cdef _memoryviewslice memviewsliceobj + * global __pyx_memoryview_thread_locks_used */ - (void)(memset((&__pyx_v_dst), 0, (sizeof(__pyx_v_dst)))); + Py_INCREF(Py_None); - /* "View.MemoryView":717 - * cdef _memoryviewslice memviewsliceobj - * - * assert memview.view.ndim > 0 # <<<<<<<<<<<<<< - * - * if isinstance(memview, _memoryviewslice): + /* "View.MemoryView":349 + * if type(self) is memoryview or obj is not None: + * __Pyx_GetBuffer(obj, &self.view, flags) + * if self.view.obj == NULL: # <<<<<<<<<<<<<< + * (<__pyx_buffer *> &self.view).obj = Py_None + * Py_INCREF(Py_None) */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - if (unlikely(!((__pyx_v_memview->view.ndim > 0) != 0))) { - PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(1, 717, __pyx_L1_error) } + + /* "View.MemoryView":347 + * self.obj = obj + * self.flags = flags + * if type(self) is memoryview or obj is not None: # <<<<<<<<<<<<<< + * __Pyx_GetBuffer(obj, &self.view, flags) + * if self.view.obj == NULL: + */ } - #endif - /* "View.MemoryView":719 - * assert memview.view.ndim > 0 + /* "View.MemoryView":354 * - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * memviewsliceobj = memview - * p_src = &memviewsliceobj.from_slice + * global __pyx_memoryview_thread_locks_used + * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: # <<<<<<<<<<<<<< + * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] + * __pyx_memoryview_thread_locks_used += 1 */ - __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __pyx_t_1 = ((__pyx_memoryview_thread_locks_used < 8) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":720 - * - * if isinstance(memview, _memoryviewslice): - * memviewsliceobj = memview # <<<<<<<<<<<<<< - * p_src = &memviewsliceobj.from_slice - * else: + /* "View.MemoryView":355 + * global __pyx_memoryview_thread_locks_used + * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: + * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] # <<<<<<<<<<<<<< + * __pyx_memoryview_thread_locks_used += 1 + * if self.lock is NULL: */ - if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(1, 720, __pyx_L1_error) - __pyx_t_3 = ((PyObject *)__pyx_v_memview); - __Pyx_INCREF(__pyx_t_3); - __pyx_v_memviewsliceobj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_v_self->lock = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]); - /* "View.MemoryView":721 - * if isinstance(memview, _memoryviewslice): - * memviewsliceobj = memview - * p_src = &memviewsliceobj.from_slice # <<<<<<<<<<<<<< - * else: - * slice_copy(memview, &src) + /* "View.MemoryView":356 + * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: + * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] + * __pyx_memoryview_thread_locks_used += 1 # <<<<<<<<<<<<<< + * if self.lock is NULL: + * self.lock = PyThread_allocate_lock() */ - __pyx_v_p_src = (&__pyx_v_memviewsliceobj->from_slice); + __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used + 1); - /* "View.MemoryView":719 - * assert memview.view.ndim > 0 + /* "View.MemoryView":354 * - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * memviewsliceobj = memview - * p_src = &memviewsliceobj.from_slice + * global __pyx_memoryview_thread_locks_used + * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: # <<<<<<<<<<<<<< + * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] + * __pyx_memoryview_thread_locks_used += 1 */ - goto __pyx_L3; } - /* "View.MemoryView":723 - * p_src = &memviewsliceobj.from_slice - * else: - * slice_copy(memview, &src) # <<<<<<<<<<<<<< - * p_src = &src - * + /* "View.MemoryView":357 + * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] + * __pyx_memoryview_thread_locks_used += 1 + * if self.lock is NULL: # <<<<<<<<<<<<<< + * self.lock = PyThread_allocate_lock() + * if self.lock is NULL: */ - /*else*/ { - __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_src)); + __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":724 - * else: - * slice_copy(memview, &src) - * p_src = &src # <<<<<<<<<<<<<< - * - * + /* "View.MemoryView":358 + * __pyx_memoryview_thread_locks_used += 1 + * if self.lock is NULL: + * self.lock = PyThread_allocate_lock() # <<<<<<<<<<<<<< + * if self.lock is NULL: + * raise MemoryError */ - __pyx_v_p_src = (&__pyx_v_src); - } - __pyx_L3:; + __pyx_v_self->lock = PyThread_allocate_lock(); - /* "View.MemoryView":730 - * - * - * dst.memview = p_src.memview # <<<<<<<<<<<<<< - * dst.data = p_src.data + /* "View.MemoryView":359 + * if self.lock is NULL: + * self.lock = PyThread_allocate_lock() + * if self.lock is NULL: # <<<<<<<<<<<<<< + * raise MemoryError * */ - __pyx_t_4 = __pyx_v_p_src->memview; - __pyx_v_dst.memview = __pyx_t_4; + __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0); + if (unlikely(__pyx_t_1)) { - /* "View.MemoryView":731 - * - * dst.memview = p_src.memview - * dst.data = p_src.data # <<<<<<<<<<<<<< - * + /* "View.MemoryView":360 + * self.lock = PyThread_allocate_lock() + * if self.lock is NULL: + * raise MemoryError # <<<<<<<<<<<<<< * + * if flags & PyBUF_FORMAT: */ - __pyx_t_5 = __pyx_v_p_src->data; - __pyx_v_dst.data = __pyx_t_5; + PyErr_NoMemory(); __PYX_ERR(1, 360, __pyx_L1_error) - /* "View.MemoryView":736 - * + /* "View.MemoryView":359 + * if self.lock is NULL: + * self.lock = PyThread_allocate_lock() + * if self.lock is NULL: # <<<<<<<<<<<<<< + * raise MemoryError * - * cdef __Pyx_memviewslice *p_dst = &dst # <<<<<<<<<<<<<< - * cdef int *p_suboffset_dim = &suboffset_dim - * cdef Py_ssize_t start, stop, step */ - __pyx_v_p_dst = (&__pyx_v_dst); + } - /* "View.MemoryView":737 - * - * cdef __Pyx_memviewslice *p_dst = &dst - * cdef int *p_suboffset_dim = &suboffset_dim # <<<<<<<<<<<<<< - * cdef Py_ssize_t start, stop, step - * cdef bint have_start, have_stop, have_step + /* "View.MemoryView":357 + * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] + * __pyx_memoryview_thread_locks_used += 1 + * if self.lock is NULL: # <<<<<<<<<<<<<< + * self.lock = PyThread_allocate_lock() + * if self.lock is NULL: */ - __pyx_v_p_suboffset_dim = (&__pyx_v_suboffset_dim); + } - /* "View.MemoryView":741 - * cdef bint have_start, have_stop, have_step + /* "View.MemoryView":362 + * raise MemoryError * - * for dim, index in enumerate(indices): # <<<<<<<<<<<<<< - * if PyIndex_Check(index): - * slice_memviewslice( + * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< + * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') + * else: */ - __pyx_t_6 = 0; - if (likely(PyList_CheckExact(__pyx_v_indices)) || PyTuple_CheckExact(__pyx_v_indices)) { - __pyx_t_3 = __pyx_v_indices; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0; - __pyx_t_8 = NULL; - } else { - __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_indices); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 741, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 741, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_8)) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(1, 741, __pyx_L1_error) - #else - __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 741, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - #endif - } else { - if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(1, 741, __pyx_L1_error) - #else - __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 741, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - #endif - } - } else { - __pyx_t_9 = __pyx_t_8(__pyx_t_3); - if (unlikely(!__pyx_t_9)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(1, 741, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_9); - } - __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_v_dim = __pyx_t_6; - __pyx_t_6 = (__pyx_t_6 + 1); + __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":742 + /* "View.MemoryView":363 * - * for dim, index in enumerate(indices): - * if PyIndex_Check(index): # <<<<<<<<<<<<<< - * slice_memviewslice( - * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], + * if flags & PyBUF_FORMAT: + * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') # <<<<<<<<<<<<<< + * else: + * self.dtype_is_object = dtype_is_object */ - __pyx_t_2 = (PyIndex_Check(__pyx_v_index) != 0); + __pyx_t_2 = (((__pyx_v_self->view.format[0]) == 'O') != 0); if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L11_bool_binop_done; + } + __pyx_t_2 = (((__pyx_v_self->view.format[1]) == '\x00') != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L11_bool_binop_done:; + __pyx_v_self->dtype_is_object = __pyx_t_1; - /* "View.MemoryView":746 - * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], - * dim, new_ndim, p_suboffset_dim, - * index, 0, 0, # start, stop, step # <<<<<<<<<<<<<< - * 0, 0, 0, # have_{start,stop,step} - * False) + /* "View.MemoryView":362 + * raise MemoryError + * + * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< + * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') + * else: */ - __pyx_t_10 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_10 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 746, __pyx_L1_error) + goto __pyx_L10; + } - /* "View.MemoryView":743 - * for dim, index in enumerate(indices): - * if PyIndex_Check(index): - * slice_memviewslice( # <<<<<<<<<<<<<< - * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], - * dim, new_ndim, p_suboffset_dim, + /* "View.MemoryView":365 + * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') + * else: + * self.dtype_is_object = dtype_is_object # <<<<<<<<<<<<<< + * + * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( */ - __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_t_10, 0, 0, 0, 0, 0, 0); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(1, 743, __pyx_L1_error) + /*else*/ { + __pyx_v_self->dtype_is_object = __pyx_v_dtype_is_object; + } + __pyx_L10:; - /* "View.MemoryView":742 + /* "View.MemoryView":367 + * self.dtype_is_object = dtype_is_object * - * for dim, index in enumerate(indices): - * if PyIndex_Check(index): # <<<<<<<<<<<<<< - * slice_memviewslice( - * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], + * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( # <<<<<<<<<<<<<< + * &self.acquisition_count[0], sizeof(__pyx_atomic_int)) + * self.typeinfo = NULL */ - goto __pyx_L6; - } + __pyx_v_self->acquisition_count_aligned_p = ((__pyx_atomic_int *)__pyx_align_pointer(((void *)(&(__pyx_v_self->acquisition_count[0]))), (sizeof(__pyx_atomic_int)))); - /* "View.MemoryView":749 - * 0, 0, 0, # have_{start,stop,step} - * False) - * elif index is None: # <<<<<<<<<<<<<< - * p_dst.shape[new_ndim] = 1 - * p_dst.strides[new_ndim] = 0 + /* "View.MemoryView":369 + * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( + * &self.acquisition_count[0], sizeof(__pyx_atomic_int)) + * self.typeinfo = NULL # <<<<<<<<<<<<<< + * + * def __dealloc__(memoryview self): */ - __pyx_t_2 = (__pyx_v_index == Py_None); - __pyx_t_1 = (__pyx_t_2 != 0); - if (__pyx_t_1) { + __pyx_v_self->typeinfo = NULL; - /* "View.MemoryView":750 - * False) - * elif index is None: - * p_dst.shape[new_ndim] = 1 # <<<<<<<<<<<<<< - * p_dst.strides[new_ndim] = 0 - * p_dst.suboffsets[new_ndim] = -1 + /* "View.MemoryView":344 + * cdef __Pyx_TypeInfo *typeinfo + * + * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): # <<<<<<<<<<<<<< + * self.obj = obj + * self.flags = flags */ - (__pyx_v_p_dst->shape[__pyx_v_new_ndim]) = 1; - /* "View.MemoryView":751 - * elif index is None: - * p_dst.shape[new_ndim] = 1 - * p_dst.strides[new_ndim] = 0 # <<<<<<<<<<<<<< - * p_dst.suboffsets[new_ndim] = -1 - * new_ndim += 1 - */ - (__pyx_v_p_dst->strides[__pyx_v_new_ndim]) = 0; + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":752 - * p_dst.shape[new_ndim] = 1 - * p_dst.strides[new_ndim] = 0 - * p_dst.suboffsets[new_ndim] = -1 # <<<<<<<<<<<<<< - * new_ndim += 1 - * else: +/* "View.MemoryView":371 + * self.typeinfo = NULL + * + * def __dealloc__(memoryview self): # <<<<<<<<<<<<<< + * if self.obj is not None: + * __Pyx_ReleaseBuffer(&self.view) */ - (__pyx_v_p_dst->suboffsets[__pyx_v_new_ndim]) = -1L; - /* "View.MemoryView":753 - * p_dst.strides[new_ndim] = 0 - * p_dst.suboffsets[new_ndim] = -1 - * new_ndim += 1 # <<<<<<<<<<<<<< - * else: - * start = index.start or 0 - */ - __pyx_v_new_ndim = (__pyx_v_new_ndim + 1); +/* Python wrapper */ +static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - /* "View.MemoryView":749 - * 0, 0, 0, # have_{start,stop,step} - * False) - * elif index is None: # <<<<<<<<<<<<<< - * p_dst.shape[new_ndim] = 1 - * p_dst.strides[new_ndim] = 0 - */ - goto __pyx_L6; - } + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} - /* "View.MemoryView":755 - * new_ndim += 1 - * else: - * start = index.start or 0 # <<<<<<<<<<<<<< - * stop = index.stop or 0 - * step = index.step or 0 - */ - /*else*/ { - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 755, __pyx_L1_error) - if (!__pyx_t_1) { - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else { - __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 755, __pyx_L1_error) - __pyx_t_10 = __pyx_t_12; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_10 = 0; - __pyx_L7_bool_binop_done:; - __pyx_v_start = __pyx_t_10; +static void __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self) { + int __pyx_v_i; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyThread_type_lock __pyx_t_6; + PyThread_type_lock __pyx_t_7; + __Pyx_RefNannySetupContext("__dealloc__", 0); + __Pyx_TraceCall("__dealloc__", __pyx_f[1], 371, 0, __PYX_ERR(1, 371, __pyx_L1_error)); - /* "View.MemoryView":756 - * else: - * start = index.start or 0 - * stop = index.stop or 0 # <<<<<<<<<<<<<< - * step = index.step or 0 + /* "View.MemoryView":372 * - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 756, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 756, __pyx_L1_error) - if (!__pyx_t_1) { - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else { - __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 756, __pyx_L1_error) - __pyx_t_10 = __pyx_t_12; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_10 = 0; - __pyx_L9_bool_binop_done:; - __pyx_v_stop = __pyx_t_10; - - /* "View.MemoryView":757 - * start = index.start or 0 - * stop = index.stop or 0 - * step = index.step or 0 # <<<<<<<<<<<<<< + * def __dealloc__(memoryview self): + * if self.obj is not None: # <<<<<<<<<<<<<< + * __Pyx_ReleaseBuffer(&self.view) * - * have_start = index.start is not None */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 757, __pyx_L1_error) - if (!__pyx_t_1) { - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else { - __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 757, __pyx_L1_error) - __pyx_t_10 = __pyx_t_12; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L11_bool_binop_done; - } - __pyx_t_10 = 0; - __pyx_L11_bool_binop_done:; - __pyx_v_step = __pyx_t_10; + __pyx_t_1 = (__pyx_v_self->obj != Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { - /* "View.MemoryView":759 - * step = index.step or 0 + /* "View.MemoryView":373 + * def __dealloc__(memoryview self): + * if self.obj is not None: + * __Pyx_ReleaseBuffer(&self.view) # <<<<<<<<<<<<<< * - * have_start = index.start is not None # <<<<<<<<<<<<<< - * have_stop = index.stop is not None - * have_step = index.step is not None + * cdef int i */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 759, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = (__pyx_t_9 != Py_None); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_have_start = __pyx_t_1; + __Pyx_ReleaseBuffer((&__pyx_v_self->view)); - /* "View.MemoryView":760 - * - * have_start = index.start is not None - * have_stop = index.stop is not None # <<<<<<<<<<<<<< - * have_step = index.step is not None + /* "View.MemoryView":372 * - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 760, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = (__pyx_t_9 != Py_None); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_have_stop = __pyx_t_1; - - /* "View.MemoryView":761 - * have_start = index.start is not None - * have_stop = index.stop is not None - * have_step = index.step is not None # <<<<<<<<<<<<<< + * def __dealloc__(memoryview self): + * if self.obj is not None: # <<<<<<<<<<<<<< + * __Pyx_ReleaseBuffer(&self.view) * - * slice_memviewslice( */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 761, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = (__pyx_t_9 != Py_None); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_have_step = __pyx_t_1; + } - /* "View.MemoryView":763 - * have_step = index.step is not None - * - * slice_memviewslice( # <<<<<<<<<<<<<< - * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], - * dim, new_ndim, p_suboffset_dim, + /* "View.MemoryView":377 + * cdef int i + * global __pyx_memoryview_thread_locks_used + * if self.lock != NULL: # <<<<<<<<<<<<<< + * for i in range(__pyx_memoryview_thread_locks_used): + * if __pyx_memoryview_thread_locks[i] is self.lock: */ - __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_v_start, __pyx_v_stop, __pyx_v_step, __pyx_v_have_start, __pyx_v_have_stop, __pyx_v_have_step, 1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(1, 763, __pyx_L1_error) + __pyx_t_2 = ((__pyx_v_self->lock != NULL) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":769 - * have_start, have_stop, have_step, - * True) - * new_ndim += 1 # <<<<<<<<<<<<<< - * - * if isinstance(memview, _memoryviewslice): + /* "View.MemoryView":378 + * global __pyx_memoryview_thread_locks_used + * if self.lock != NULL: + * for i in range(__pyx_memoryview_thread_locks_used): # <<<<<<<<<<<<<< + * if __pyx_memoryview_thread_locks[i] is self.lock: + * __pyx_memoryview_thread_locks_used -= 1 */ - __pyx_v_new_ndim = (__pyx_v_new_ndim + 1); - } - __pyx_L6:; + __pyx_t_3 = __pyx_memoryview_thread_locks_used; + __pyx_t_4 = __pyx_t_3; + for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { + __pyx_v_i = __pyx_t_5; - /* "View.MemoryView":741 - * cdef bint have_start, have_stop, have_step - * - * for dim, index in enumerate(indices): # <<<<<<<<<<<<<< - * if PyIndex_Check(index): - * slice_memviewslice( + /* "View.MemoryView":379 + * if self.lock != NULL: + * for i in range(__pyx_memoryview_thread_locks_used): + * if __pyx_memoryview_thread_locks[i] is self.lock: # <<<<<<<<<<<<<< + * __pyx_memoryview_thread_locks_used -= 1 + * if i != __pyx_memoryview_thread_locks_used: */ - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_2 = (((__pyx_memoryview_thread_locks[__pyx_v_i]) == __pyx_v_self->lock) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":771 - * new_ndim += 1 - * - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * return memoryview_fromslice(dst, new_ndim, - * memviewsliceobj.to_object_func, + /* "View.MemoryView":380 + * for i in range(__pyx_memoryview_thread_locks_used): + * if __pyx_memoryview_thread_locks[i] is self.lock: + * __pyx_memoryview_thread_locks_used -= 1 # <<<<<<<<<<<<<< + * if i != __pyx_memoryview_thread_locks_used: + * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( */ - __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used - 1); - /* "View.MemoryView":772 - * - * if isinstance(memview, _memoryviewslice): - * return memoryview_fromslice(dst, new_ndim, # <<<<<<<<<<<<<< - * memviewsliceobj.to_object_func, - * memviewsliceobj.to_dtype_func, + /* "View.MemoryView":381 + * if __pyx_memoryview_thread_locks[i] is self.lock: + * __pyx_memoryview_thread_locks_used -= 1 + * if i != __pyx_memoryview_thread_locks_used: # <<<<<<<<<<<<<< + * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( + * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); + __pyx_t_2 = ((__pyx_v_i != __pyx_memoryview_thread_locks_used) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":773 - * if isinstance(memview, _memoryviewslice): - * return memoryview_fromslice(dst, new_ndim, - * memviewsliceobj.to_object_func, # <<<<<<<<<<<<<< - * memviewsliceobj.to_dtype_func, - * memview.dtype_is_object) + /* "View.MemoryView":383 + * if i != __pyx_memoryview_thread_locks_used: + * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( + * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) # <<<<<<<<<<<<<< + * break + * else: */ - if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(1, 773, __pyx_L1_error) } + __pyx_t_6 = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]); + __pyx_t_7 = (__pyx_memoryview_thread_locks[__pyx_v_i]); - /* "View.MemoryView":774 - * return memoryview_fromslice(dst, new_ndim, - * memviewsliceobj.to_object_func, - * memviewsliceobj.to_dtype_func, # <<<<<<<<<<<<<< - * memview.dtype_is_object) - * else: + /* "View.MemoryView":382 + * __pyx_memoryview_thread_locks_used -= 1 + * if i != __pyx_memoryview_thread_locks_used: + * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( # <<<<<<<<<<<<<< + * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) + * break */ - if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(1, 774, __pyx_L1_error) } + (__pyx_memoryview_thread_locks[__pyx_v_i]) = __pyx_t_6; + (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]) = __pyx_t_7; - /* "View.MemoryView":772 - * - * if isinstance(memview, _memoryviewslice): - * return memoryview_fromslice(dst, new_ndim, # <<<<<<<<<<<<<< - * memviewsliceobj.to_object_func, - * memviewsliceobj.to_dtype_func, + /* "View.MemoryView":381 + * if __pyx_memoryview_thread_locks[i] is self.lock: + * __pyx_memoryview_thread_locks_used -= 1 + * if i != __pyx_memoryview_thread_locks_used: # <<<<<<<<<<<<<< + * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( + * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) */ - __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, __pyx_v_memviewsliceobj->to_object_func, __pyx_v_memviewsliceobj->to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 772, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(1, 772, __pyx_L1_error) - __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3); - __pyx_t_3 = 0; - goto __pyx_L0; + } - /* "View.MemoryView":771 - * new_ndim += 1 - * - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * return memoryview_fromslice(dst, new_ndim, - * memviewsliceobj.to_object_func, + /* "View.MemoryView":384 + * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( + * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) + * break # <<<<<<<<<<<<<< + * else: + * PyThread_free_lock(self.lock) */ - } + goto __pyx_L6_break; - /* "View.MemoryView":777 - * memview.dtype_is_object) - * else: - * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<< - * memview.dtype_is_object) - * + /* "View.MemoryView":379 + * if self.lock != NULL: + * for i in range(__pyx_memoryview_thread_locks_used): + * if __pyx_memoryview_thread_locks[i] is self.lock: # <<<<<<<<<<<<<< + * __pyx_memoryview_thread_locks_used -= 1 + * if i != __pyx_memoryview_thread_locks_used: */ - /*else*/ { - __Pyx_XDECREF(((PyObject *)__pyx_r)); + } + } + /*else*/ { - /* "View.MemoryView":778 - * else: - * return memoryview_fromslice(dst, new_ndim, NULL, NULL, - * memview.dtype_is_object) # <<<<<<<<<<<<<< - * + /* "View.MemoryView":386 + * break + * else: + * PyThread_free_lock(self.lock) # <<<<<<<<<<<<<< * + * cdef char *get_item_pointer(memoryview self, object index) except NULL: */ - __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, NULL, NULL, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 777, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + PyThread_free_lock(__pyx_v_self->lock); + } + __pyx_L6_break:; - /* "View.MemoryView":777 - * memview.dtype_is_object) - * else: - * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<< - * memview.dtype_is_object) - * + /* "View.MemoryView":377 + * cdef int i + * global __pyx_memoryview_thread_locks_used + * if self.lock != NULL: # <<<<<<<<<<<<<< + * for i in range(__pyx_memoryview_thread_locks_used): + * if __pyx_memoryview_thread_locks[i] is self.lock: */ - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(1, 777, __pyx_L1_error) - __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3); - __pyx_t_3 = 0; - goto __pyx_L0; } - /* "View.MemoryView":705 + /* "View.MemoryView":371 + * self.typeinfo = NULL * - * @cname('__pyx_memview_slice') - * cdef memoryview memview_slice(memoryview memview, object indices): # <<<<<<<<<<<<<< - * cdef int new_ndim = 0, suboffset_dim = -1, dim - * cdef bint negative_step + * def __dealloc__(memoryview self): # <<<<<<<<<<<<<< + * if self.obj is not None: + * __Pyx_ReleaseBuffer(&self.view) */ /* function exit code */ + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("View.MemoryView.memview_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_WriteUnraisable("View.MemoryView.memoryview.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_memviewsliceobj); - __Pyx_XDECREF(__pyx_v_index); - __Pyx_XGIVEREF((PyObject *)__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); - return __pyx_r; } -/* "View.MemoryView":802 +/* "View.MemoryView":388 + * PyThread_free_lock(self.lock) * - * @cname('__pyx_memoryview_slice_memviewslice') - * cdef int slice_memviewslice( # <<<<<<<<<<<<<< - * __Pyx_memviewslice *dst, - * Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset, + * cdef char *get_item_pointer(memoryview self, object index) except NULL: # <<<<<<<<<<<<<< + * cdef Py_ssize_t dim + * cdef char *itemp = self.view.buf */ -static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *__pyx_v_dst, Py_ssize_t __pyx_v_shape, Py_ssize_t __pyx_v_stride, Py_ssize_t __pyx_v_suboffset, int __pyx_v_dim, int __pyx_v_new_ndim, int *__pyx_v_suboffset_dim, Py_ssize_t __pyx_v_start, Py_ssize_t __pyx_v_stop, Py_ssize_t __pyx_v_step, int __pyx_v_have_start, int __pyx_v_have_stop, int __pyx_v_have_step, int __pyx_v_is_slice) { - Py_ssize_t __pyx_v_new_shape; - int __pyx_v_negative_step; - int __pyx_r; +static char *__pyx_memoryview_get_item_pointer(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) { + Py_ssize_t __pyx_v_dim; + char *__pyx_v_itemp; + PyObject *__pyx_v_idx = NULL; + char *__pyx_r; __Pyx_TraceDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_TraceCall("slice_memviewslice", __pyx_f[1], 802, 1, __PYX_ERR(1, 802, __pyx_L1_error)); - - /* "View.MemoryView":822 - * cdef bint negative_step - * - * if not is_slice: # <<<<<<<<<<<<<< - * - * if start < 0: - */ - __pyx_t_1 = ((!(__pyx_v_is_slice != 0)) != 0); - if (__pyx_t_1) { + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + char *__pyx_t_7; + __Pyx_RefNannySetupContext("get_item_pointer", 0); + __Pyx_TraceCall("get_item_pointer", __pyx_f[1], 388, 0, __PYX_ERR(1, 388, __pyx_L1_error)); - /* "View.MemoryView":824 - * if not is_slice: + /* "View.MemoryView":390 + * cdef char *get_item_pointer(memoryview self, object index) except NULL: + * cdef Py_ssize_t dim + * cdef char *itemp = self.view.buf # <<<<<<<<<<<<<< * - * if start < 0: # <<<<<<<<<<<<<< - * start += shape - * if not 0 <= start < shape: + * for dim, idx in enumerate(index): */ - __pyx_t_1 = ((__pyx_v_start < 0) != 0); - if (__pyx_t_1) { + __pyx_v_itemp = ((char *)__pyx_v_self->view.buf); - /* "View.MemoryView":825 + /* "View.MemoryView":392 + * cdef char *itemp = self.view.buf * - * if start < 0: - * start += shape # <<<<<<<<<<<<<< - * if not 0 <= start < shape: - * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) - */ - __pyx_v_start = (__pyx_v_start + __pyx_v_shape); - - /* "View.MemoryView":824 - * if not is_slice: + * for dim, idx in enumerate(index): # <<<<<<<<<<<<<< + * itemp = pybuffer_index(&self.view, itemp, idx, dim) * - * if start < 0: # <<<<<<<<<<<<<< - * start += shape - * if not 0 <= start < shape: - */ - } - - /* "View.MemoryView":826 - * if start < 0: - * start += shape - * if not 0 <= start < shape: # <<<<<<<<<<<<<< - * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) - * else: */ - __pyx_t_1 = (0 <= __pyx_v_start); - if (__pyx_t_1) { - __pyx_t_1 = (__pyx_v_start < __pyx_v_shape); + __pyx_t_1 = 0; + if (likely(PyList_CheckExact(__pyx_v_index)) || PyTuple_CheckExact(__pyx_v_index)) { + __pyx_t_2 = __pyx_v_index; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 392, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 392, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_4)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(1, 392, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 392, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } else { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(1, 392, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 392, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } + } else { + __pyx_t_5 = __pyx_t_4(__pyx_t_2); + if (unlikely(!__pyx_t_5)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(1, 392, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_5); } - __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); - if (__pyx_t_2) { + __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_v_dim = __pyx_t_1; + __pyx_t_1 = (__pyx_t_1 + 1); - /* "View.MemoryView":827 - * start += shape - * if not 0 <= start < shape: - * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) # <<<<<<<<<<<<<< - * else: + /* "View.MemoryView":393 * + * for dim, idx in enumerate(index): + * itemp = pybuffer_index(&self.view, itemp, idx, dim) # <<<<<<<<<<<<<< + * + * return itemp */ - __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"Index out of bounds (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 827, __pyx_L1_error) - - /* "View.MemoryView":826 - * if start < 0: - * start += shape - * if not 0 <= start < shape: # <<<<<<<<<<<<<< - * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) - * else: - */ - } + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 393, __pyx_L1_error) + __pyx_t_7 = __pyx_pybuffer_index((&__pyx_v_self->view), __pyx_v_itemp, __pyx_t_6, __pyx_v_dim); if (unlikely(__pyx_t_7 == ((char *)NULL))) __PYX_ERR(1, 393, __pyx_L1_error) + __pyx_v_itemp = __pyx_t_7; - /* "View.MemoryView":822 - * cdef bint negative_step + /* "View.MemoryView":392 + * cdef char *itemp = self.view.buf * - * if not is_slice: # <<<<<<<<<<<<<< + * for dim, idx in enumerate(index): # <<<<<<<<<<<<<< + * itemp = pybuffer_index(&self.view, itemp, idx, dim) * - * if start < 0: */ - goto __pyx_L3; } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "View.MemoryView":830 - * else: + /* "View.MemoryView":395 + * itemp = pybuffer_index(&self.view, itemp, idx, dim) + * + * return itemp # <<<<<<<<<<<<<< * - * negative_step = have_step != 0 and step < 0 # <<<<<<<<<<<<<< * - * if have_step and step == 0: */ - /*else*/ { - __pyx_t_1 = ((__pyx_v_have_step != 0) != 0); - if (__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L6_bool_binop_done; - } - __pyx_t_1 = ((__pyx_v_step < 0) != 0); - __pyx_t_2 = __pyx_t_1; - __pyx_L6_bool_binop_done:; - __pyx_v_negative_step = __pyx_t_2; + __pyx_r = __pyx_v_itemp; + goto __pyx_L0; - /* "View.MemoryView":832 - * negative_step = have_step != 0 and step < 0 + /* "View.MemoryView":388 + * PyThread_free_lock(self.lock) + * + * cdef char *get_item_pointer(memoryview self, object index) except NULL: # <<<<<<<<<<<<<< + * cdef Py_ssize_t dim + * cdef char *itemp = self.view.buf + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.memoryview.get_item_pointer", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_idx); + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":398 * - * if have_step and step == 0: # <<<<<<<<<<<<<< - * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) * + * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<< + * if index is Ellipsis: + * return self */ - __pyx_t_1 = (__pyx_v_have_step != 0); - if (__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_1 = ((__pyx_v_step == 0) != 0); - __pyx_t_2 = __pyx_t_1; - __pyx_L9_bool_binop_done:; - if (__pyx_t_2) { - /* "View.MemoryView":833 +/* Python wrapper */ +static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index); /*proto*/ +static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) { + PyObject *__pyx_v_have_slices = NULL; + PyObject *__pyx_v_indices = NULL; + char *__pyx_v_itemp; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + char *__pyx_t_6; + __Pyx_RefNannySetupContext("__getitem__", 0); + __Pyx_TraceCall("__getitem__", __pyx_f[1], 398, 0, __PYX_ERR(1, 398, __pyx_L1_error)); + + /* "View.MemoryView":399 * - * if have_step and step == 0: - * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) # <<<<<<<<<<<<<< + * def __getitem__(memoryview self, object index): + * if index is Ellipsis: # <<<<<<<<<<<<<< + * return self * + */ + __pyx_t_1 = (__pyx_v_index == __pyx_builtin_Ellipsis); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":400 + * def __getitem__(memoryview self, object index): + * if index is Ellipsis: + * return self # <<<<<<<<<<<<<< * + * have_slices, indices = _unellipsify(index, self.view.ndim) */ - __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Step may not be zero (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 833, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + goto __pyx_L0; - /* "View.MemoryView":832 - * negative_step = have_step != 0 and step < 0 + /* "View.MemoryView":399 * - * if have_step and step == 0: # <<<<<<<<<<<<<< - * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) + * def __getitem__(memoryview self, object index): + * if index is Ellipsis: # <<<<<<<<<<<<<< + * return self * */ - } + } - /* "View.MemoryView":836 + /* "View.MemoryView":402 + * return self * + * have_slices, indices = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<< * - * if have_start: # <<<<<<<<<<<<<< - * if start < 0: - * start += shape + * cdef char *itemp */ - __pyx_t_2 = (__pyx_v_have_start != 0); - if (__pyx_t_2) { + __pyx_t_3 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 402, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (likely(__pyx_t_3 != Py_None)) { + PyObject* sequence = __pyx_t_3; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(1, 402, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + #else + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 402, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 402, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(1, 402, __pyx_L1_error) + } + __pyx_v_have_slices = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_v_indices = __pyx_t_5; + __pyx_t_5 = 0; - /* "View.MemoryView":837 + /* "View.MemoryView":405 * - * if have_start: - * if start < 0: # <<<<<<<<<<<<<< - * start += shape - * if start < 0: + * cdef char *itemp + * if have_slices: # <<<<<<<<<<<<<< + * return memview_slice(self, indices) + * else: */ - __pyx_t_2 = ((__pyx_v_start < 0) != 0); - if (__pyx_t_2) { + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 405, __pyx_L1_error) + if (__pyx_t_2) { - /* "View.MemoryView":838 - * if have_start: - * if start < 0: - * start += shape # <<<<<<<<<<<<<< - * if start < 0: - * start = 0 + /* "View.MemoryView":406 + * cdef char *itemp + * if have_slices: + * return memview_slice(self, indices) # <<<<<<<<<<<<<< + * else: + * itemp = self.get_item_pointer(indices) */ - __pyx_v_start = (__pyx_v_start + __pyx_v_shape); + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = ((PyObject *)__pyx_memview_slice(__pyx_v_self, __pyx_v_indices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 406, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "View.MemoryView":839 - * if start < 0: - * start += shape - * if start < 0: # <<<<<<<<<<<<<< - * start = 0 - * elif start >= shape: + /* "View.MemoryView":405 + * + * cdef char *itemp + * if have_slices: # <<<<<<<<<<<<<< + * return memview_slice(self, indices) + * else: */ - __pyx_t_2 = ((__pyx_v_start < 0) != 0); - if (__pyx_t_2) { + } - /* "View.MemoryView":840 - * start += shape - * if start < 0: - * start = 0 # <<<<<<<<<<<<<< - * elif start >= shape: - * if negative_step: + /* "View.MemoryView":408 + * return memview_slice(self, indices) + * else: + * itemp = self.get_item_pointer(indices) # <<<<<<<<<<<<<< + * return self.convert_item_to_object(itemp) + * */ - __pyx_v_start = 0; + /*else*/ { + __pyx_t_6 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_indices); if (unlikely(__pyx_t_6 == ((char *)NULL))) __PYX_ERR(1, 408, __pyx_L1_error) + __pyx_v_itemp = __pyx_t_6; - /* "View.MemoryView":839 - * if start < 0: - * start += shape - * if start < 0: # <<<<<<<<<<<<<< - * start = 0 - * elif start >= shape: + /* "View.MemoryView":409 + * else: + * itemp = self.get_item_pointer(indices) + * return self.convert_item_to_object(itemp) # <<<<<<<<<<<<<< + * + * def __setitem__(memoryview self, object index, object value): */ - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->convert_item_to_object(__pyx_v_self, __pyx_v_itemp); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 409, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + } - /* "View.MemoryView":837 + /* "View.MemoryView":398 * - * if have_start: - * if start < 0: # <<<<<<<<<<<<<< - * start += shape - * if start < 0: + * + * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<< + * if index is Ellipsis: + * return self */ - goto __pyx_L12; - } - /* "View.MemoryView":841 - * if start < 0: - * start = 0 - * elif start >= shape: # <<<<<<<<<<<<<< - * if negative_step: - * start = shape - 1 - */ - __pyx_t_2 = ((__pyx_v_start >= __pyx_v_shape) != 0); - if (__pyx_t_2) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.memoryview.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_have_slices); + __Pyx_XDECREF(__pyx_v_indices); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":842 - * start = 0 - * elif start >= shape: - * if negative_step: # <<<<<<<<<<<<<< - * start = shape - 1 - * else: +/* "View.MemoryView":411 + * return self.convert_item_to_object(itemp) + * + * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<< + * if self.view.readonly: + * raise TypeError("Cannot assign to read-only memoryview") */ - __pyx_t_2 = (__pyx_v_negative_step != 0); - if (__pyx_t_2) { - /* "View.MemoryView":843 - * elif start >= shape: - * if negative_step: - * start = shape - 1 # <<<<<<<<<<<<<< - * else: - * start = shape - */ - __pyx_v_start = (__pyx_v_shape - 1); +/* Python wrapper */ +static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index), ((PyObject *)__pyx_v_value)); - /* "View.MemoryView":842 - * start = 0 - * elif start >= shape: - * if negative_step: # <<<<<<<<<<<<<< - * start = shape - 1 - * else: + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) { + PyObject *__pyx_v_have_slices = NULL; + PyObject *__pyx_v_obj = NULL; + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("__setitem__", 0); + __Pyx_TraceCall("__setitem__", __pyx_f[1], 411, 0, __PYX_ERR(1, 411, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_index); + + /* "View.MemoryView":412 + * + * def __setitem__(memoryview self, object index, object value): + * if self.view.readonly: # <<<<<<<<<<<<<< + * raise TypeError("Cannot assign to read-only memoryview") + * */ - goto __pyx_L14; - } + __pyx_t_1 = (__pyx_v_self->view.readonly != 0); + if (unlikely(__pyx_t_1)) { - /* "View.MemoryView":845 - * start = shape - 1 - * else: - * start = shape # <<<<<<<<<<<<<< - * else: - * if negative_step: + /* "View.MemoryView":413 + * def __setitem__(memoryview self, object index, object value): + * if self.view.readonly: + * raise TypeError("Cannot assign to read-only memoryview") # <<<<<<<<<<<<<< + * + * have_slices, index = _unellipsify(index, self.view.ndim) */ - /*else*/ { - __pyx_v_start = __pyx_v_shape; - } - __pyx_L14:; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 413, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(1, 413, __pyx_L1_error) - /* "View.MemoryView":841 - * if start < 0: - * start = 0 - * elif start >= shape: # <<<<<<<<<<<<<< - * if negative_step: - * start = shape - 1 + /* "View.MemoryView":412 + * + * def __setitem__(memoryview self, object index, object value): + * if self.view.readonly: # <<<<<<<<<<<<<< + * raise TypeError("Cannot assign to read-only memoryview") + * */ - } - __pyx_L12:; + } - /* "View.MemoryView":836 + /* "View.MemoryView":415 + * raise TypeError("Cannot assign to read-only memoryview") * + * have_slices, index = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<< * - * if have_start: # <<<<<<<<<<<<<< - * if start < 0: - * start += shape + * if have_slices: */ - goto __pyx_L11; + __pyx_t_2 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 415, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (likely(__pyx_t_2 != Py_None)) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(1, 415, __pyx_L1_error) } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 415, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 415, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(1, 415, __pyx_L1_error) + } + __pyx_v_have_slices = __pyx_t_3; + __pyx_t_3 = 0; + __Pyx_DECREF_SET(__pyx_v_index, __pyx_t_4); + __pyx_t_4 = 0; - /* "View.MemoryView":847 - * start = shape - * else: - * if negative_step: # <<<<<<<<<<<<<< - * start = shape - 1 + /* "View.MemoryView":417 + * have_slices, index = _unellipsify(index, self.view.ndim) + * + * if have_slices: # <<<<<<<<<<<<<< + * obj = self.is_slice(value) + * if obj: + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 417, __pyx_L1_error) + if (__pyx_t_1) { + + /* "View.MemoryView":418 + * + * if have_slices: + * obj = self.is_slice(value) # <<<<<<<<<<<<<< + * if obj: + * self.setitem_slice_assignment(self[index], obj) + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->is_slice(__pyx_v_self, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 418, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_obj = __pyx_t_2; + __pyx_t_2 = 0; + + /* "View.MemoryView":419 + * if have_slices: + * obj = self.is_slice(value) + * if obj: # <<<<<<<<<<<<<< + * self.setitem_slice_assignment(self[index], obj) * else: */ - /*else*/ { - __pyx_t_2 = (__pyx_v_negative_step != 0); - if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_obj); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 419, __pyx_L1_error) + if (__pyx_t_1) { - /* "View.MemoryView":848 - * else: - * if negative_step: - * start = shape - 1 # <<<<<<<<<<<<<< + /* "View.MemoryView":420 + * obj = self.is_slice(value) + * if obj: + * self.setitem_slice_assignment(self[index], obj) # <<<<<<<<<<<<<< * else: - * start = 0 + * self.setitem_slice_assign_scalar(self[index], value) */ - __pyx_v_start = (__pyx_v_shape - 1); + __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 420, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assignment(__pyx_v_self, __pyx_t_2, __pyx_v_obj); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 420, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "View.MemoryView":847 - * start = shape - * else: - * if negative_step: # <<<<<<<<<<<<<< - * start = shape - 1 + /* "View.MemoryView":419 + * if have_slices: + * obj = self.is_slice(value) + * if obj: # <<<<<<<<<<<<<< + * self.setitem_slice_assignment(self[index], obj) * else: */ - goto __pyx_L15; - } + goto __pyx_L5; + } - /* "View.MemoryView":850 - * start = shape - 1 + /* "View.MemoryView":422 + * self.setitem_slice_assignment(self[index], obj) * else: - * start = 0 # <<<<<<<<<<<<<< - * - * if have_stop: + * self.setitem_slice_assign_scalar(self[index], value) # <<<<<<<<<<<<<< + * else: + * self.setitem_indexed(index, value) */ - /*else*/ { - __pyx_v_start = 0; - } - __pyx_L15:; + /*else*/ { + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 422, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_memoryview_type))))) __PYX_ERR(1, 422, __pyx_L1_error) + __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assign_scalar(__pyx_v_self, ((struct __pyx_memoryview_obj *)__pyx_t_4), __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 422, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } - __pyx_L11:; + __pyx_L5:; - /* "View.MemoryView":852 - * start = 0 + /* "View.MemoryView":417 + * have_slices, index = _unellipsify(index, self.view.ndim) * - * if have_stop: # <<<<<<<<<<<<<< - * if stop < 0: - * stop += shape + * if have_slices: # <<<<<<<<<<<<<< + * obj = self.is_slice(value) + * if obj: */ - __pyx_t_2 = (__pyx_v_have_stop != 0); - if (__pyx_t_2) { + goto __pyx_L4; + } - /* "View.MemoryView":853 - * - * if have_stop: - * if stop < 0: # <<<<<<<<<<<<<< - * stop += shape - * if stop < 0: + /* "View.MemoryView":424 + * self.setitem_slice_assign_scalar(self[index], value) + * else: + * self.setitem_indexed(index, value) # <<<<<<<<<<<<<< + * + * cdef is_slice(self, obj): */ - __pyx_t_2 = ((__pyx_v_stop < 0) != 0); - if (__pyx_t_2) { + /*else*/ { + __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_indexed(__pyx_v_self, __pyx_v_index, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 424, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_L4:; - /* "View.MemoryView":854 - * if have_stop: - * if stop < 0: - * stop += shape # <<<<<<<<<<<<<< - * if stop < 0: - * stop = 0 + /* "View.MemoryView":411 + * return self.convert_item_to_object(itemp) + * + * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<< + * if self.view.readonly: + * raise TypeError("Cannot assign to read-only memoryview") */ - __pyx_v_stop = (__pyx_v_stop + __pyx_v_shape); - /* "View.MemoryView":855 - * if stop < 0: - * stop += shape - * if stop < 0: # <<<<<<<<<<<<<< - * stop = 0 - * elif stop > shape: - */ - __pyx_t_2 = ((__pyx_v_stop < 0) != 0); - if (__pyx_t_2) { + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("View.MemoryView.memoryview.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_have_slices); + __Pyx_XDECREF(__pyx_v_obj); + __Pyx_XDECREF(__pyx_v_index); + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":856 - * stop += shape - * if stop < 0: - * stop = 0 # <<<<<<<<<<<<<< - * elif stop > shape: - * stop = shape +/* "View.MemoryView":426 + * self.setitem_indexed(index, value) + * + * cdef is_slice(self, obj): # <<<<<<<<<<<<<< + * if not isinstance(obj, memoryview): + * try: */ - __pyx_v_stop = 0; - /* "View.MemoryView":855 - * if stop < 0: - * stop += shape - * if stop < 0: # <<<<<<<<<<<<<< - * stop = 0 - * elif stop > shape: - */ - } +static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + __Pyx_RefNannySetupContext("is_slice", 0); + __Pyx_TraceCall("is_slice", __pyx_f[1], 426, 0, __PYX_ERR(1, 426, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_obj); - /* "View.MemoryView":853 + /* "View.MemoryView":427 * - * if have_stop: - * if stop < 0: # <<<<<<<<<<<<<< - * stop += shape - * if stop < 0: + * cdef is_slice(self, obj): + * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<< + * try: + * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, */ - goto __pyx_L17; - } + __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_obj, __pyx_memoryview_type); + __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":857 - * if stop < 0: - * stop = 0 - * elif stop > shape: # <<<<<<<<<<<<<< - * stop = shape - * else: + /* "View.MemoryView":428 + * cdef is_slice(self, obj): + * if not isinstance(obj, memoryview): + * try: # <<<<<<<<<<<<<< + * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, + * self.dtype_is_object) */ - __pyx_t_2 = ((__pyx_v_stop > __pyx_v_shape) != 0); - if (__pyx_t_2) { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + /*try:*/ { - /* "View.MemoryView":858 - * stop = 0 - * elif stop > shape: - * stop = shape # <<<<<<<<<<<<<< - * else: - * if negative_step: + /* "View.MemoryView":429 + * if not isinstance(obj, memoryview): + * try: + * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<< + * self.dtype_is_object) + * except TypeError: */ - __pyx_v_stop = __pyx_v_shape; + __pyx_t_6 = __Pyx_PyInt_From_int((__pyx_v_self->flags | PyBUF_ANY_CONTIGUOUS)); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 429, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_6); - /* "View.MemoryView":857 - * if stop < 0: - * stop = 0 - * elif stop > shape: # <<<<<<<<<<<<<< - * stop = shape - * else: + /* "View.MemoryView":430 + * try: + * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, + * self.dtype_is_object) # <<<<<<<<<<<<<< + * except TypeError: + * return None */ - } - __pyx_L17:; + __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 430, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); - /* "View.MemoryView":852 - * start = 0 - * - * if have_stop: # <<<<<<<<<<<<<< - * if stop < 0: - * stop += shape + /* "View.MemoryView":429 + * if not isinstance(obj, memoryview): + * try: + * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<< + * self.dtype_is_object) + * except TypeError: */ - goto __pyx_L16; - } + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 429, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v_obj); + __Pyx_GIVEREF(__pyx_v_obj); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_obj); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7); + __pyx_t_6 = 0; + __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 429, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF_SET(__pyx_v_obj, __pyx_t_7); + __pyx_t_7 = 0; - /* "View.MemoryView":860 - * stop = shape - * else: - * if negative_step: # <<<<<<<<<<<<<< - * stop = -1 - * else: + /* "View.MemoryView":428 + * cdef is_slice(self, obj): + * if not isinstance(obj, memoryview): + * try: # <<<<<<<<<<<<<< + * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, + * self.dtype_is_object) */ - /*else*/ { - __pyx_t_2 = (__pyx_v_negative_step != 0); - if (__pyx_t_2) { + } + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L9_try_end; + __pyx_L4_error:; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "View.MemoryView":861 - * else: - * if negative_step: - * stop = -1 # <<<<<<<<<<<<<< - * else: - * stop = shape + /* "View.MemoryView":431 + * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, + * self.dtype_is_object) + * except TypeError: # <<<<<<<<<<<<<< + * return None + * */ - __pyx_v_stop = -1L; + __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError); + if (__pyx_t_9) { + __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_6) < 0) __PYX_ERR(1, 431, __pyx_L6_except_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_6); - /* "View.MemoryView":860 - * stop = shape - * else: - * if negative_step: # <<<<<<<<<<<<<< - * stop = -1 - * else: + /* "View.MemoryView":432 + * self.dtype_is_object) + * except TypeError: + * return None # <<<<<<<<<<<<<< + * + * return obj */ - goto __pyx_L19; + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L7_except_return; } + goto __pyx_L6_except_error; + __pyx_L6_except_error:; - /* "View.MemoryView":863 - * stop = -1 - * else: - * stop = shape # <<<<<<<<<<<<<< - * - * if not have_step: + /* "View.MemoryView":428 + * cdef is_slice(self, obj): + * if not isinstance(obj, memoryview): + * try: # <<<<<<<<<<<<<< + * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, + * self.dtype_is_object) */ - /*else*/ { - __pyx_v_stop = __pyx_v_shape; - } - __pyx_L19:; + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5); + goto __pyx_L1_error; + __pyx_L7_except_return:; + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5); + goto __pyx_L0; + __pyx_L9_try_end:; } - __pyx_L16:; - /* "View.MemoryView":865 - * stop = shape - * - * if not have_step: # <<<<<<<<<<<<<< - * step = 1 + /* "View.MemoryView":427 * + * cdef is_slice(self, obj): + * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<< + * try: + * obj = memoryview(obj, self.flags|PyBUF_ANY_CONTIGUOUS, */ - __pyx_t_2 = ((!(__pyx_v_have_step != 0)) != 0); - if (__pyx_t_2) { + } - /* "View.MemoryView":866 - * - * if not have_step: - * step = 1 # <<<<<<<<<<<<<< + /* "View.MemoryView":434 + * return None * + * return obj # <<<<<<<<<<<<<< * + * cdef setitem_slice_assignment(self, dst, src): */ - __pyx_v_step = 1; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_obj); + __pyx_r = __pyx_v_obj; + goto __pyx_L0; - /* "View.MemoryView":865 - * stop = shape - * - * if not have_step: # <<<<<<<<<<<<<< - * step = 1 + /* "View.MemoryView":426 + * self.setitem_indexed(index, value) * + * cdef is_slice(self, obj): # <<<<<<<<<<<<<< + * if not isinstance(obj, memoryview): + * try: */ - } - /* "View.MemoryView":870 - * - * with cython.cdivision(True): - * new_shape = (stop - start) // step # <<<<<<<<<<<<<< - * - * if (stop - start) - step * new_shape: - */ - __pyx_v_new_shape = ((__pyx_v_stop - __pyx_v_start) / __pyx_v_step); + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_obj); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":872 - * new_shape = (stop - start) // step - * - * if (stop - start) - step * new_shape: # <<<<<<<<<<<<<< - * new_shape += 1 +/* "View.MemoryView":436 + * return obj * + * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice dst_slice + * cdef __Pyx_memviewslice src_slice */ - __pyx_t_2 = (((__pyx_v_stop - __pyx_v_start) - (__pyx_v_step * __pyx_v_new_shape)) != 0); - if (__pyx_t_2) { - /* "View.MemoryView":873 - * - * if (stop - start) - step * new_shape: - * new_shape += 1 # <<<<<<<<<<<<<< +static PyObject *__pyx_memoryview_setitem_slice_assignment(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_dst, PyObject *__pyx_v_src) { + __Pyx_memviewslice __pyx_v_dst_slice; + __Pyx_memviewslice __pyx_v_src_slice; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("setitem_slice_assignment", 0); + __Pyx_TraceCall("setitem_slice_assignment", __pyx_f[1], 436, 0, __PYX_ERR(1, 436, __pyx_L1_error)); + + /* "View.MemoryView":440 + * cdef __Pyx_memviewslice src_slice * - * if new_shape < 0: + * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], # <<<<<<<<<<<<<< + * get_slice_from_memview(dst, &dst_slice)[0], + * src.ndim, dst.ndim, self.dtype_is_object) */ - __pyx_v_new_shape = (__pyx_v_new_shape + 1); + if (!(likely(((__pyx_v_src) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_src, __pyx_memoryview_type))))) __PYX_ERR(1, 440, __pyx_L1_error) - /* "View.MemoryView":872 - * new_shape = (stop - start) // step + /* "View.MemoryView":441 * - * if (stop - start) - step * new_shape: # <<<<<<<<<<<<<< - * new_shape += 1 + * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], + * get_slice_from_memview(dst, &dst_slice)[0], # <<<<<<<<<<<<<< + * src.ndim, dst.ndim, self.dtype_is_object) * */ - } + if (!(likely(((__pyx_v_dst) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_dst, __pyx_memoryview_type))))) __PYX_ERR(1, 441, __pyx_L1_error) - /* "View.MemoryView":875 - * new_shape += 1 - * - * if new_shape < 0: # <<<<<<<<<<<<<< - * new_shape = 0 + /* "View.MemoryView":442 + * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], + * get_slice_from_memview(dst, &dst_slice)[0], + * src.ndim, dst.ndim, self.dtype_is_object) # <<<<<<<<<<<<<< * + * cdef setitem_slice_assign_scalar(self, memoryview dst, value): */ - __pyx_t_2 = ((__pyx_v_new_shape < 0) != 0); - if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_src, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 442, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 442, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_dst, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 442, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 442, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "View.MemoryView":876 - * - * if new_shape < 0: - * new_shape = 0 # <<<<<<<<<<<<<< - * + /* "View.MemoryView":440 + * cdef __Pyx_memviewslice src_slice * + * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], # <<<<<<<<<<<<<< + * get_slice_from_memview(dst, &dst_slice)[0], + * src.ndim, dst.ndim, self.dtype_is_object) */ - __pyx_v_new_shape = 0; + __pyx_t_4 = __pyx_memoryview_copy_contents((__pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_src), (&__pyx_v_src_slice))[0]), (__pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_dst), (&__pyx_v_dst_slice))[0]), __pyx_t_2, __pyx_t_3, __pyx_v_self->dtype_is_object); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 440, __pyx_L1_error) - /* "View.MemoryView":875 - * new_shape += 1 - * - * if new_shape < 0: # <<<<<<<<<<<<<< - * new_shape = 0 + /* "View.MemoryView":436 + * return obj * + * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice dst_slice + * cdef __Pyx_memviewslice src_slice */ - } - /* "View.MemoryView":879 - * + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assignment", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":444 + * src.ndim, dst.ndim, self.dtype_is_object) * - * dst.strides[new_ndim] = stride * step # <<<<<<<<<<<<<< - * dst.shape[new_ndim] = new_shape - * dst.suboffsets[new_ndim] = suboffset + * cdef setitem_slice_assign_scalar(self, memoryview dst, value): # <<<<<<<<<<<<<< + * cdef int array[128] + * cdef void *tmp = NULL */ - (__pyx_v_dst->strides[__pyx_v_new_ndim]) = (__pyx_v_stride * __pyx_v_step); - /* "View.MemoryView":880 - * - * dst.strides[new_ndim] = stride * step - * dst.shape[new_ndim] = new_shape # <<<<<<<<<<<<<< - * dst.suboffsets[new_ndim] = suboffset +static PyObject *__pyx_memoryview_setitem_slice_assign_scalar(struct __pyx_memoryview_obj *__pyx_v_self, struct __pyx_memoryview_obj *__pyx_v_dst, PyObject *__pyx_v_value) { + int __pyx_v_array[0x80]; + void *__pyx_v_tmp; + void *__pyx_v_item; + __Pyx_memviewslice *__pyx_v_dst_slice; + __Pyx_memviewslice __pyx_v_tmp_slice; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + char const *__pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + __Pyx_RefNannySetupContext("setitem_slice_assign_scalar", 0); + __Pyx_TraceCall("setitem_slice_assign_scalar", __pyx_f[1], 444, 0, __PYX_ERR(1, 444, __pyx_L1_error)); + + /* "View.MemoryView":446 + * cdef setitem_slice_assign_scalar(self, memoryview dst, value): + * cdef int array[128] + * cdef void *tmp = NULL # <<<<<<<<<<<<<< + * cdef void *item * */ - (__pyx_v_dst->shape[__pyx_v_new_ndim]) = __pyx_v_new_shape; + __pyx_v_tmp = NULL; - /* "View.MemoryView":881 - * dst.strides[new_ndim] = stride * step - * dst.shape[new_ndim] = new_shape - * dst.suboffsets[new_ndim] = suboffset # <<<<<<<<<<<<<< - * + /* "View.MemoryView":451 + * cdef __Pyx_memviewslice *dst_slice + * cdef __Pyx_memviewslice tmp_slice + * dst_slice = get_slice_from_memview(dst, &tmp_slice) # <<<<<<<<<<<<<< * + * if self.view.itemsize > sizeof(array): */ - (__pyx_v_dst->suboffsets[__pyx_v_new_ndim]) = __pyx_v_suboffset; - } - __pyx_L3:; + __pyx_v_dst_slice = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_dst, (&__pyx_v_tmp_slice)); - /* "View.MemoryView":884 - * + /* "View.MemoryView":453 + * dst_slice = get_slice_from_memview(dst, &tmp_slice) * - * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<< - * dst.data += start * stride - * else: + * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<< + * tmp = PyMem_Malloc(self.view.itemsize) + * if tmp == NULL: */ - __pyx_t_2 = (((__pyx_v_suboffset_dim[0]) < 0) != 0); - if (__pyx_t_2) { + __pyx_t_1 = ((((size_t)__pyx_v_self->view.itemsize) > (sizeof(__pyx_v_array))) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":885 + /* "View.MemoryView":454 * - * if suboffset_dim[0] < 0: - * dst.data += start * stride # <<<<<<<<<<<<<< - * else: - * dst.suboffsets[suboffset_dim[0]] += start * stride + * if self.view.itemsize > sizeof(array): + * tmp = PyMem_Malloc(self.view.itemsize) # <<<<<<<<<<<<<< + * if tmp == NULL: + * raise MemoryError */ - __pyx_v_dst->data = (__pyx_v_dst->data + (__pyx_v_start * __pyx_v_stride)); + __pyx_v_tmp = PyMem_Malloc(__pyx_v_self->view.itemsize); - /* "View.MemoryView":884 - * + /* "View.MemoryView":455 + * if self.view.itemsize > sizeof(array): + * tmp = PyMem_Malloc(self.view.itemsize) + * if tmp == NULL: # <<<<<<<<<<<<<< + * raise MemoryError + * item = tmp + */ + __pyx_t_1 = ((__pyx_v_tmp == NULL) != 0); + if (unlikely(__pyx_t_1)) { + + /* "View.MemoryView":456 + * tmp = PyMem_Malloc(self.view.itemsize) + * if tmp == NULL: + * raise MemoryError # <<<<<<<<<<<<<< + * item = tmp + * else: + */ + PyErr_NoMemory(); __PYX_ERR(1, 456, __pyx_L1_error) + + /* "View.MemoryView":455 + * if self.view.itemsize > sizeof(array): + * tmp = PyMem_Malloc(self.view.itemsize) + * if tmp == NULL: # <<<<<<<<<<<<<< + * raise MemoryError + * item = tmp + */ + } + + /* "View.MemoryView":457 + * if tmp == NULL: + * raise MemoryError + * item = tmp # <<<<<<<<<<<<<< + * else: + * item = array + */ + __pyx_v_item = __pyx_v_tmp; + + /* "View.MemoryView":453 + * dst_slice = get_slice_from_memview(dst, &tmp_slice) * - * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<< - * dst.data += start * stride - * else: + * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<< + * tmp = PyMem_Malloc(self.view.itemsize) + * if tmp == NULL: */ - goto __pyx_L23; + goto __pyx_L3; } - /* "View.MemoryView":887 - * dst.data += start * stride - * else: - * dst.suboffsets[suboffset_dim[0]] += start * stride # <<<<<<<<<<<<<< + /* "View.MemoryView":459 + * item = tmp + * else: + * item = array # <<<<<<<<<<<<<< * - * if suboffset >= 0: + * try: */ /*else*/ { - __pyx_t_3 = (__pyx_v_suboffset_dim[0]); - (__pyx_v_dst->suboffsets[__pyx_t_3]) = ((__pyx_v_dst->suboffsets[__pyx_t_3]) + (__pyx_v_start * __pyx_v_stride)); + __pyx_v_item = ((void *)__pyx_v_array); } - __pyx_L23:; + __pyx_L3:; - /* "View.MemoryView":889 - * dst.suboffsets[suboffset_dim[0]] += start * stride + /* "View.MemoryView":461 + * item = array * - * if suboffset >= 0: # <<<<<<<<<<<<<< - * if not is_slice: - * if new_ndim == 0: + * try: # <<<<<<<<<<<<<< + * if self.dtype_is_object: + * ( item)[0] = value */ - __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0); - if (__pyx_t_2) { + /*try:*/ { - /* "View.MemoryView":890 + /* "View.MemoryView":462 * - * if suboffset >= 0: - * if not is_slice: # <<<<<<<<<<<<<< - * if new_ndim == 0: - * dst.data = ( dst.data)[0] + suboffset - */ - __pyx_t_2 = ((!(__pyx_v_is_slice != 0)) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":891 - * if suboffset >= 0: - * if not is_slice: - * if new_ndim == 0: # <<<<<<<<<<<<<< - * dst.data = ( dst.data)[0] + suboffset + * try: + * if self.dtype_is_object: # <<<<<<<<<<<<<< + * ( item)[0] = value * else: */ - __pyx_t_2 = ((__pyx_v_new_ndim == 0) != 0); - if (__pyx_t_2) { + __pyx_t_1 = (__pyx_v_self->dtype_is_object != 0); + if (__pyx_t_1) { - /* "View.MemoryView":892 - * if not is_slice: - * if new_ndim == 0: - * dst.data = ( dst.data)[0] + suboffset # <<<<<<<<<<<<<< + /* "View.MemoryView":463 + * try: + * if self.dtype_is_object: + * ( item)[0] = value # <<<<<<<<<<<<<< * else: - * _err_dim(IndexError, "All dimensions preceding dimension %d " + * self.assign_item_from_object( item, value) */ - __pyx_v_dst->data = ((((char **)__pyx_v_dst->data)[0]) + __pyx_v_suboffset); + (((PyObject **)__pyx_v_item)[0]) = ((PyObject *)__pyx_v_value); - /* "View.MemoryView":891 - * if suboffset >= 0: - * if not is_slice: - * if new_ndim == 0: # <<<<<<<<<<<<<< - * dst.data = ( dst.data)[0] + suboffset + /* "View.MemoryView":462 + * + * try: + * if self.dtype_is_object: # <<<<<<<<<<<<<< + * ( item)[0] = value * else: */ - goto __pyx_L26; - } + goto __pyx_L8; + } - /* "View.MemoryView":894 - * dst.data = ( dst.data)[0] + suboffset + /* "View.MemoryView":465 + * ( item)[0] = value * else: - * _err_dim(IndexError, "All dimensions preceding dimension %d " # <<<<<<<<<<<<<< - * "must be indexed and not sliced", dim) - * else: + * self.assign_item_from_object( item, value) # <<<<<<<<<<<<<< + * + * */ - /*else*/ { + /*else*/ { + __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, ((char *)__pyx_v_item), __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 465, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_L8:; - /* "View.MemoryView":895 - * else: - * _err_dim(IndexError, "All dimensions preceding dimension %d " - * "must be indexed and not sliced", dim) # <<<<<<<<<<<<<< - * else: - * suboffset_dim[0] = new_ndim + /* "View.MemoryView":469 + * + * + * if self.view.suboffsets != NULL: # <<<<<<<<<<<<<< + * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) + * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, */ - __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"All dimensions preceding dimension %d must be indexed and not sliced"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 894, __pyx_L1_error) - } - __pyx_L26:; + __pyx_t_1 = ((__pyx_v_self->view.suboffsets != NULL) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":890 + /* "View.MemoryView":470 * - * if suboffset >= 0: - * if not is_slice: # <<<<<<<<<<<<<< - * if new_ndim == 0: - * dst.data = ( dst.data)[0] + suboffset + * if self.view.suboffsets != NULL: + * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) # <<<<<<<<<<<<<< + * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, + * item, self.dtype_is_object) */ - goto __pyx_L25; - } + __pyx_t_2 = assert_direct_dimensions(__pyx_v_self->view.suboffsets, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 470, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "View.MemoryView":897 - * "must be indexed and not sliced", dim) - * else: - * suboffset_dim[0] = new_ndim # <<<<<<<<<<<<<< + /* "View.MemoryView":469 * - * return 0 + * + * if self.view.suboffsets != NULL: # <<<<<<<<<<<<<< + * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) + * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, */ - /*else*/ { - (__pyx_v_suboffset_dim[0]) = __pyx_v_new_ndim; } - __pyx_L25:; - /* "View.MemoryView":889 - * dst.suboffsets[suboffset_dim[0]] += start * stride - * - * if suboffset >= 0: # <<<<<<<<<<<<<< - * if not is_slice: - * if new_ndim == 0: + /* "View.MemoryView":471 + * if self.view.suboffsets != NULL: + * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) + * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, # <<<<<<<<<<<<<< + * item, self.dtype_is_object) + * finally: */ + __pyx_memoryview_slice_assign_scalar(__pyx_v_dst_slice, __pyx_v_dst->view.ndim, __pyx_v_self->view.itemsize, __pyx_v_item, __pyx_v_self->dtype_is_object); } - /* "View.MemoryView":899 - * suboffset_dim[0] = new_ndim - * - * return 0 # <<<<<<<<<<<<<< - * + /* "View.MemoryView":474 + * item, self.dtype_is_object) + * finally: + * PyMem_Free(tmp) # <<<<<<<<<<<<<< * + * cdef setitem_indexed(self, index, value): */ - __pyx_r = 0; - goto __pyx_L0; + /*finally:*/ { + /*normal exit:*/{ + PyMem_Free(__pyx_v_tmp); + goto __pyx_L7; + } + __pyx_L6_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_6 = 0; __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __pyx_t_3 = __pyx_lineno; __pyx_t_4 = __pyx_clineno; __pyx_t_5 = __pyx_filename; + { + PyMem_Free(__pyx_v_tmp); + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); + } + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ErrRestore(__pyx_t_6, __pyx_t_7, __pyx_t_8); + __pyx_t_6 = 0; __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; + __pyx_lineno = __pyx_t_3; __pyx_clineno = __pyx_t_4; __pyx_filename = __pyx_t_5; + goto __pyx_L1_error; + } + __pyx_L7:; + } - /* "View.MemoryView":802 + /* "View.MemoryView":444 + * src.ndim, dst.ndim, self.dtype_is_object) * - * @cname('__pyx_memoryview_slice_memviewslice') - * cdef int slice_memviewslice( # <<<<<<<<<<<<<< - * __Pyx_memviewslice *dst, - * Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset, + * cdef setitem_slice_assign_scalar(self, memoryview dst, value): # <<<<<<<<<<<<<< + * cdef int array[128] + * cdef void *tmp = NULL */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; - { - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_AddTraceback("View.MemoryView.slice_memviewslice", __pyx_clineno, __pyx_lineno, __pyx_filename); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - } - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":905 +/* "View.MemoryView":476 + * PyMem_Free(tmp) * - * @cname('__pyx_pybuffer_index') - * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<< - * Py_ssize_t dim) except NULL: - * cdef Py_ssize_t shape, stride, suboffset = -1 + * cdef setitem_indexed(self, index, value): # <<<<<<<<<<<<<< + * cdef char *itemp = self.get_item_pointer(index) + * self.assign_item_from_object(itemp, value) */ -static char *__pyx_pybuffer_index(Py_buffer *__pyx_v_view, char *__pyx_v_bufp, Py_ssize_t __pyx_v_index, Py_ssize_t __pyx_v_dim) { - Py_ssize_t __pyx_v_shape; - Py_ssize_t __pyx_v_stride; - Py_ssize_t __pyx_v_suboffset; - Py_ssize_t __pyx_v_itemsize; - char *__pyx_v_resultp; - char *__pyx_r; +static PyObject *__pyx_memoryview_setitem_indexed(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) { + char *__pyx_v_itemp; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannySetupContext("pybuffer_index", 0); - __Pyx_TraceCall("pybuffer_index", __pyx_f[1], 905, 0, __PYX_ERR(1, 905, __pyx_L1_error)); - - /* "View.MemoryView":907 - * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, - * Py_ssize_t dim) except NULL: - * cdef Py_ssize_t shape, stride, suboffset = -1 # <<<<<<<<<<<<<< - * cdef Py_ssize_t itemsize = view.itemsize - * cdef char *resultp - */ - __pyx_v_suboffset = -1L; + char *__pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("setitem_indexed", 0); + __Pyx_TraceCall("setitem_indexed", __pyx_f[1], 476, 0, __PYX_ERR(1, 476, __pyx_L1_error)); - /* "View.MemoryView":908 - * Py_ssize_t dim) except NULL: - * cdef Py_ssize_t shape, stride, suboffset = -1 - * cdef Py_ssize_t itemsize = view.itemsize # <<<<<<<<<<<<<< - * cdef char *resultp + /* "View.MemoryView":477 + * + * cdef setitem_indexed(self, index, value): + * cdef char *itemp = self.get_item_pointer(index) # <<<<<<<<<<<<<< + * self.assign_item_from_object(itemp, value) * */ - __pyx_t_1 = __pyx_v_view->itemsize; - __pyx_v_itemsize = __pyx_t_1; + __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_index); if (unlikely(__pyx_t_1 == ((char *)NULL))) __PYX_ERR(1, 477, __pyx_L1_error) + __pyx_v_itemp = __pyx_t_1; - /* "View.MemoryView":911 - * cdef char *resultp + /* "View.MemoryView":478 + * cdef setitem_indexed(self, index, value): + * cdef char *itemp = self.get_item_pointer(index) + * self.assign_item_from_object(itemp, value) # <<<<<<<<<<<<<< * - * if view.ndim == 0: # <<<<<<<<<<<<<< - * shape = view.len / itemsize - * stride = itemsize + * cdef convert_item_to_object(self, char *itemp): */ - __pyx_t_2 = ((__pyx_v_view->ndim == 0) != 0); - if (__pyx_t_2) { + __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "View.MemoryView":912 + /* "View.MemoryView":476 + * PyMem_Free(tmp) * - * if view.ndim == 0: - * shape = view.len / itemsize # <<<<<<<<<<<<<< - * stride = itemsize - * else: + * cdef setitem_indexed(self, index, value): # <<<<<<<<<<<<<< + * cdef char *itemp = self.get_item_pointer(index) + * self.assign_item_from_object(itemp, value) */ - if (unlikely(__pyx_v_itemsize == 0)) { - PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - __PYX_ERR(1, 912, __pyx_L1_error) - } - else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_view->len))) { - PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); - __PYX_ERR(1, 912, __pyx_L1_error) - } - __pyx_v_shape = __Pyx_div_Py_ssize_t(__pyx_v_view->len, __pyx_v_itemsize); - /* "View.MemoryView":913 - * if view.ndim == 0: - * shape = view.len / itemsize - * stride = itemsize # <<<<<<<<<<<<<< - * else: - * shape = view.shape[dim] - */ - __pyx_v_stride = __pyx_v_itemsize; + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_indexed", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":911 - * cdef char *resultp +/* "View.MemoryView":480 + * self.assign_item_from_object(itemp, value) * - * if view.ndim == 0: # <<<<<<<<<<<<<< - * shape = view.len / itemsize - * stride = itemsize - */ - goto __pyx_L3; - } - - /* "View.MemoryView":915 - * stride = itemsize - * else: - * shape = view.shape[dim] # <<<<<<<<<<<<<< - * stride = view.strides[dim] - * if view.suboffsets != NULL: + * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< + * """Only used if instantiated manually by the user, or if Cython doesn't + * know how to convert the type""" */ - /*else*/ { - __pyx_v_shape = (__pyx_v_view->shape[__pyx_v_dim]); - /* "View.MemoryView":916 - * else: - * shape = view.shape[dim] - * stride = view.strides[dim] # <<<<<<<<<<<<<< - * if view.suboffsets != NULL: - * suboffset = view.suboffsets[dim] - */ - __pyx_v_stride = (__pyx_v_view->strides[__pyx_v_dim]); +static PyObject *__pyx_memoryview_convert_item_to_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp) { + PyObject *__pyx_v_struct = NULL; + PyObject *__pyx_v_bytesitem = 0; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + size_t __pyx_t_10; + int __pyx_t_11; + __Pyx_RefNannySetupContext("convert_item_to_object", 0); + __Pyx_TraceCall("convert_item_to_object", __pyx_f[1], 480, 0, __PYX_ERR(1, 480, __pyx_L1_error)); - /* "View.MemoryView":917 - * shape = view.shape[dim] - * stride = view.strides[dim] - * if view.suboffsets != NULL: # <<<<<<<<<<<<<< - * suboffset = view.suboffsets[dim] + /* "View.MemoryView":483 + * """Only used if instantiated manually by the user, or if Cython doesn't + * know how to convert the type""" + * import struct # <<<<<<<<<<<<<< + * cdef bytes bytesitem * */ - __pyx_t_2 = ((__pyx_v_view->suboffsets != NULL) != 0); - if (__pyx_t_2) { + __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 483, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_struct = __pyx_t_1; + __pyx_t_1 = 0; - /* "View.MemoryView":918 - * stride = view.strides[dim] - * if view.suboffsets != NULL: - * suboffset = view.suboffsets[dim] # <<<<<<<<<<<<<< + /* "View.MemoryView":486 + * cdef bytes bytesitem * - * if index < 0: + * bytesitem = itemp[:self.view.itemsize] # <<<<<<<<<<<<<< + * try: + * result = struct.unpack(self.view.format, bytesitem) */ - __pyx_v_suboffset = (__pyx_v_view->suboffsets[__pyx_v_dim]); + __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_itemp + 0, __pyx_v_self->view.itemsize - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_bytesitem = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "View.MemoryView":917 - * shape = view.shape[dim] - * stride = view.strides[dim] - * if view.suboffsets != NULL: # <<<<<<<<<<<<<< - * suboffset = view.suboffsets[dim] + /* "View.MemoryView":487 * + * bytesitem = itemp[:self.view.itemsize] + * try: # <<<<<<<<<<<<<< + * result = struct.unpack(self.view.format, bytesitem) + * except struct.error: */ - } - } - __pyx_L3:; + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_4); + /*try:*/ { - /* "View.MemoryView":920 - * suboffset = view.suboffsets[dim] - * - * if index < 0: # <<<<<<<<<<<<<< - * index += view.shape[dim] - * if index < 0: + /* "View.MemoryView":488 + * bytesitem = itemp[:self.view.itemsize] + * try: + * result = struct.unpack(self.view.format, bytesitem) # <<<<<<<<<<<<<< + * except struct.error: + * raise ValueError("Unable to convert item to object") */ - __pyx_t_2 = ((__pyx_v_index < 0) != 0); - if (__pyx_t_2) { + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_unpack); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 488, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 488, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = NULL; + __pyx_t_8 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 488, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 488, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 488, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_6); + __Pyx_INCREF(__pyx_v_bytesitem); + __Pyx_GIVEREF(__pyx_v_bytesitem); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_bytesitem); + __pyx_t_6 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 488, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_result = __pyx_t_1; + __pyx_t_1 = 0; - /* "View.MemoryView":921 + /* "View.MemoryView":487 * - * if index < 0: - * index += view.shape[dim] # <<<<<<<<<<<<<< - * if index < 0: - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + * bytesitem = itemp[:self.view.itemsize] + * try: # <<<<<<<<<<<<<< + * result = struct.unpack(self.view.format, bytesitem) + * except struct.error: */ - __pyx_v_index = (__pyx_v_index + (__pyx_v_view->shape[__pyx_v_dim])); + } - /* "View.MemoryView":922 - * if index < 0: - * index += view.shape[dim] - * if index < 0: # <<<<<<<<<<<<<< - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) - * + /* "View.MemoryView":492 + * raise ValueError("Unable to convert item to object") + * else: + * if len(self.view.format) == 1: # <<<<<<<<<<<<<< + * return result[0] + * return result */ - __pyx_t_2 = ((__pyx_v_index < 0) != 0); - if (unlikely(__pyx_t_2)) { + /*else:*/ { + __pyx_t_10 = strlen(__pyx_v_self->view.format); + __pyx_t_11 = ((__pyx_t_10 == 1) != 0); + if (__pyx_t_11) { - /* "View.MemoryView":923 - * index += view.shape[dim] - * if index < 0: - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<< + /* "View.MemoryView":493 + * else: + * if len(self.view.format) == 1: + * return result[0] # <<<<<<<<<<<<<< + * return result * - * if index >= shape: */ - __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 923, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 923, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 923, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 923, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_result, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 493, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L6_except_return; - /* "View.MemoryView":922 - * if index < 0: - * index += view.shape[dim] - * if index < 0: # <<<<<<<<<<<<<< - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + /* "View.MemoryView":492 + * raise ValueError("Unable to convert item to object") + * else: + * if len(self.view.format) == 1: # <<<<<<<<<<<<<< + * return result[0] + * return result + */ + } + + /* "View.MemoryView":494 + * if len(self.view.format) == 1: + * return result[0] + * return result # <<<<<<<<<<<<<< * + * cdef assign_item_from_object(self, char *itemp, object value): */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L6_except_return; } + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "View.MemoryView":920 - * suboffset = view.suboffsets[dim] + /* "View.MemoryView":489 + * try: + * result = struct.unpack(self.view.format, bytesitem) + * except struct.error: # <<<<<<<<<<<<<< + * raise ValueError("Unable to convert item to object") + * else: + */ + __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_5, &__pyx_t_9); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 489, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_6); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_ErrRestore(__pyx_t_1, __pyx_t_5, __pyx_t_9); + __pyx_t_1 = 0; __pyx_t_5 = 0; __pyx_t_9 = 0; + if (__pyx_t_8) { + __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_5, &__pyx_t_1) < 0) __PYX_ERR(1, 489, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_1); + + /* "View.MemoryView":490 + * result = struct.unpack(self.view.format, bytesitem) + * except struct.error: + * raise ValueError("Unable to convert item to object") # <<<<<<<<<<<<<< + * else: + * if len(self.view.format) == 1: + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__63, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 490, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(1, 490, __pyx_L5_except_error) + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "View.MemoryView":487 * - * if index < 0: # <<<<<<<<<<<<<< - * index += view.shape[dim] - * if index < 0: + * bytesitem = itemp[:self.view.itemsize] + * try: # <<<<<<<<<<<<<< + * result = struct.unpack(self.view.format, bytesitem) + * except struct.error: */ + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); + goto __pyx_L1_error; + __pyx_L6_except_return:; + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); + goto __pyx_L0; } - /* "View.MemoryView":925 - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + /* "View.MemoryView":480 + * self.assign_item_from_object(itemp, value) * - * if index >= shape: # <<<<<<<<<<<<<< - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< + * """Only used if instantiated manually by the user, or if Cython doesn't + * know how to convert the type""" + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_struct); + __Pyx_XDECREF(__pyx_v_bytesitem); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":496 + * return result * + * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< + * """Only used if instantiated manually by the user, or if Cython doesn't + * know how to convert the type""" */ - __pyx_t_2 = ((__pyx_v_index >= __pyx_v_shape) != 0); - if (unlikely(__pyx_t_2)) { - /* "View.MemoryView":926 +static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) { + PyObject *__pyx_v_struct = NULL; + char __pyx_v_c; + PyObject *__pyx_v_bytesvalue = 0; + Py_ssize_t __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + Py_ssize_t __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + char *__pyx_t_11; + char *__pyx_t_12; + char *__pyx_t_13; + char *__pyx_t_14; + __Pyx_RefNannySetupContext("assign_item_from_object", 0); + __Pyx_TraceCall("assign_item_from_object", __pyx_f[1], 496, 0, __PYX_ERR(1, 496, __pyx_L1_error)); + + /* "View.MemoryView":499 + * """Only used if instantiated manually by the user, or if Cython doesn't + * know how to convert the type""" + * import struct # <<<<<<<<<<<<<< + * cdef char c + * cdef bytes bytesvalue + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 499, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_struct = __pyx_t_1; + __pyx_t_1 = 0; + + /* "View.MemoryView":504 + * cdef Py_ssize_t i * - * if index >= shape: - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<< + * if isinstance(value, tuple): # <<<<<<<<<<<<<< + * bytesvalue = struct.pack(self.view.format, *value) + * else: + */ + __pyx_t_2 = PyTuple_Check(__pyx_v_value); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "View.MemoryView":505 * - * resultp = bufp + index * stride + * if isinstance(value, tuple): + * bytesvalue = struct.pack(self.view.format, *value) # <<<<<<<<<<<<<< + * else: + * bytesvalue = struct.pack(self.view.format, value) */ - __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 926, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 926, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 505, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 505, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 926, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 505, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 505, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyNumber_Add(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 505, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 926, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 505, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(1, 505, __pyx_L1_error) + __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; - /* "View.MemoryView":925 - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) - * - * if index >= shape: # <<<<<<<<<<<<<< - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + /* "View.MemoryView":504 + * cdef Py_ssize_t i * + * if isinstance(value, tuple): # <<<<<<<<<<<<<< + * bytesvalue = struct.pack(self.view.format, *value) + * else: */ + goto __pyx_L3; } - /* "View.MemoryView":928 - * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + /* "View.MemoryView":507 + * bytesvalue = struct.pack(self.view.format, *value) + * else: + * bytesvalue = struct.pack(self.view.format, value) # <<<<<<<<<<<<<< * - * resultp = bufp + index * stride # <<<<<<<<<<<<<< - * if suboffset >= 0: - * resultp = ( resultp)[0] + suboffset + * for i, c in enumerate(bytesvalue): */ - __pyx_v_resultp = (__pyx_v_bufp + (__pyx_v_index * __pyx_v_stride)); + /*else*/ { + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 507, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 507, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_1); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_v_value); + __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(1, 507, __pyx_L1_error) + __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + } + __pyx_L3:; - /* "View.MemoryView":929 + /* "View.MemoryView":509 + * bytesvalue = struct.pack(self.view.format, value) * - * resultp = bufp + index * stride - * if suboffset >= 0: # <<<<<<<<<<<<<< - * resultp = ( resultp)[0] + suboffset + * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<< + * itemp[i] = c * */ - __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0); - if (__pyx_t_2) { + __pyx_t_9 = 0; + if (unlikely(__pyx_v_bytesvalue == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable"); + __PYX_ERR(1, 509, __pyx_L1_error) + } + __Pyx_INCREF(__pyx_v_bytesvalue); + __pyx_t_10 = __pyx_v_bytesvalue; + __pyx_t_12 = PyBytes_AS_STRING(__pyx_t_10); + __pyx_t_13 = (__pyx_t_12 + PyBytes_GET_SIZE(__pyx_t_10)); + for (__pyx_t_14 = __pyx_t_12; __pyx_t_14 < __pyx_t_13; __pyx_t_14++) { + __pyx_t_11 = __pyx_t_14; + __pyx_v_c = (__pyx_t_11[0]); - /* "View.MemoryView":930 - * resultp = bufp + index * stride - * if suboffset >= 0: - * resultp = ( resultp)[0] + suboffset # <<<<<<<<<<<<<< + /* "View.MemoryView":510 * - * return resultp + * for i, c in enumerate(bytesvalue): + * itemp[i] = c # <<<<<<<<<<<<<< + * + * @cname('getbuffer') */ - __pyx_v_resultp = ((((char **)__pyx_v_resultp)[0]) + __pyx_v_suboffset); + __pyx_v_i = __pyx_t_9; - /* "View.MemoryView":929 + /* "View.MemoryView":509 + * bytesvalue = struct.pack(self.view.format, value) * - * resultp = bufp + index * stride - * if suboffset >= 0: # <<<<<<<<<<<<<< - * resultp = ( resultp)[0] + suboffset + * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<< + * itemp[i] = c * */ - } + __pyx_t_9 = (__pyx_t_9 + 1); - /* "View.MemoryView":932 - * resultp = ( resultp)[0] + suboffset - * - * return resultp # <<<<<<<<<<<<<< + /* "View.MemoryView":510 * + * for i, c in enumerate(bytesvalue): + * itemp[i] = c # <<<<<<<<<<<<<< * + * @cname('getbuffer') */ - __pyx_r = __pyx_v_resultp; - goto __pyx_L0; + (__pyx_v_itemp[__pyx_v_i]) = __pyx_v_c; + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - /* "View.MemoryView":905 + /* "View.MemoryView":496 + * return result * - * @cname('__pyx_pybuffer_index') - * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<< - * Py_ssize_t dim) except NULL: - * cdef Py_ssize_t shape, stride, suboffset = -1 + * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< + * """Only used if instantiated manually by the user, or if Cython doesn't + * know how to convert the type""" */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("View.MemoryView.pybuffer_index", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("View.MemoryView.memoryview.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF(__pyx_v_struct); + __Pyx_XDECREF(__pyx_v_bytesvalue); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":938 - * - * @cname('__pyx_memslice_transpose') - * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<< - * cdef int ndim = memslice.memview.view.ndim +/* "View.MemoryView":513 * + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< + * if flags & PyBUF_WRITABLE and self.view.readonly: + * raise ValueError("Cannot create writable memory view from read-only memoryview") */ -static int __pyx_memslice_transpose(__Pyx_memviewslice *__pyx_v_memslice) { - int __pyx_v_ndim; - Py_ssize_t *__pyx_v_shape; - Py_ssize_t *__pyx_v_strides; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_r; +/* Python wrapper */ +static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ +static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { + int __pyx_r; __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations int __pyx_t_1; - Py_ssize_t *__pyx_t_2; - long __pyx_t_3; - long __pyx_t_4; - Py_ssize_t __pyx_t_5; - Py_ssize_t __pyx_t_6; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t *__pyx_t_4; + char *__pyx_t_5; + void *__pyx_t_6; int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - __Pyx_TraceCall("transpose_memslice", __pyx_f[1], 938, 1, __PYX_ERR(1, 938, __pyx_L1_error)); + Py_ssize_t __pyx_t_8; + if (__pyx_v_info == NULL) { + PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete"); + return -1; + } + __Pyx_RefNannySetupContext("__getbuffer__", 0); + __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(__pyx_v_info->obj); + __Pyx_TraceCall("__getbuffer__", __pyx_f[1], 513, 0, __PYX_ERR(1, 513, __pyx_L1_error)); - /* "View.MemoryView":939 - * @cname('__pyx_memslice_transpose') - * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: - * cdef int ndim = memslice.memview.view.ndim # <<<<<<<<<<<<<< + /* "View.MemoryView":514 + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): + * if flags & PyBUF_WRITABLE and self.view.readonly: # <<<<<<<<<<<<<< + * raise ValueError("Cannot create writable memory view from read-only memoryview") * - * cdef Py_ssize_t *shape = memslice.shape */ - __pyx_t_1 = __pyx_v_memslice->memview->view.ndim; - __pyx_v_ndim = __pyx_t_1; + __pyx_t_2 = ((__pyx_v_flags & PyBUF_WRITABLE) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = (__pyx_v_self->view.readonly != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L4_bool_binop_done:; + if (unlikely(__pyx_t_1)) { - /* "View.MemoryView":941 - * cdef int ndim = memslice.memview.view.ndim - * - * cdef Py_ssize_t *shape = memslice.shape # <<<<<<<<<<<<<< - * cdef Py_ssize_t *strides = memslice.strides + /* "View.MemoryView":515 + * def __getbuffer__(self, Py_buffer *info, int flags): + * if flags & PyBUF_WRITABLE and self.view.readonly: + * raise ValueError("Cannot create writable memory view from read-only memoryview") # <<<<<<<<<<<<<< * + * if flags & PyBUF_STRIDES: */ - __pyx_t_2 = __pyx_v_memslice->shape; - __pyx_v_shape = __pyx_t_2; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 515, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(1, 515, __pyx_L1_error) - /* "View.MemoryView":942 - * - * cdef Py_ssize_t *shape = memslice.shape - * cdef Py_ssize_t *strides = memslice.strides # <<<<<<<<<<<<<< - * + /* "View.MemoryView":514 + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): + * if flags & PyBUF_WRITABLE and self.view.readonly: # <<<<<<<<<<<<<< + * raise ValueError("Cannot create writable memory view from read-only memoryview") * */ - __pyx_t_2 = __pyx_v_memslice->strides; - __pyx_v_strides = __pyx_t_2; + } - /* "View.MemoryView":946 + /* "View.MemoryView":517 + * raise ValueError("Cannot create writable memory view from read-only memoryview") * - * cdef int i, j - * for i in range(ndim / 2): # <<<<<<<<<<<<<< - * j = ndim - 1 - i - * strides[i], strides[j] = strides[j], strides[i] - */ - __pyx_t_3 = __Pyx_div_long(__pyx_v_ndim, 2); - __pyx_t_4 = __pyx_t_3; - for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_4; __pyx_t_1+=1) { - __pyx_v_i = __pyx_t_1; - - /* "View.MemoryView":947 - * cdef int i, j - * for i in range(ndim / 2): - * j = ndim - 1 - i # <<<<<<<<<<<<<< - * strides[i], strides[j] = strides[j], strides[i] - * shape[i], shape[j] = shape[j], shape[i] + * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< + * info.shape = self.view.shape + * else: */ - __pyx_v_j = ((__pyx_v_ndim - 1) - __pyx_v_i); + __pyx_t_1 = ((__pyx_v_flags & PyBUF_STRIDES) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":948 - * for i in range(ndim / 2): - * j = ndim - 1 - i - * strides[i], strides[j] = strides[j], strides[i] # <<<<<<<<<<<<<< - * shape[i], shape[j] = shape[j], shape[i] + /* "View.MemoryView":518 * + * if flags & PyBUF_STRIDES: + * info.shape = self.view.shape # <<<<<<<<<<<<<< + * else: + * info.shape = NULL */ - __pyx_t_5 = (__pyx_v_strides[__pyx_v_j]); - __pyx_t_6 = (__pyx_v_strides[__pyx_v_i]); - (__pyx_v_strides[__pyx_v_i]) = __pyx_t_5; - (__pyx_v_strides[__pyx_v_j]) = __pyx_t_6; + __pyx_t_4 = __pyx_v_self->view.shape; + __pyx_v_info->shape = __pyx_t_4; - /* "View.MemoryView":949 - * j = ndim - 1 - i - * strides[i], strides[j] = strides[j], strides[i] - * shape[i], shape[j] = shape[j], shape[i] # <<<<<<<<<<<<<< + /* "View.MemoryView":517 + * raise ValueError("Cannot create writable memory view from read-only memoryview") * - * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: + * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< + * info.shape = self.view.shape + * else: */ - __pyx_t_6 = (__pyx_v_shape[__pyx_v_j]); - __pyx_t_5 = (__pyx_v_shape[__pyx_v_i]); - (__pyx_v_shape[__pyx_v_i]) = __pyx_t_6; - (__pyx_v_shape[__pyx_v_j]) = __pyx_t_5; + goto __pyx_L6; + } - /* "View.MemoryView":951 - * shape[i], shape[j] = shape[j], shape[i] - * - * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: # <<<<<<<<<<<<<< - * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") + /* "View.MemoryView":520 + * info.shape = self.view.shape + * else: + * info.shape = NULL # <<<<<<<<<<<<<< * + * if flags & PyBUF_STRIDES: */ - __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_i]) >= 0) != 0); - if (!__pyx_t_8) { - } else { - __pyx_t_7 = __pyx_t_8; - goto __pyx_L6_bool_binop_done; - } - __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_j]) >= 0) != 0); - __pyx_t_7 = __pyx_t_8; - __pyx_L6_bool_binop_done:; - if (__pyx_t_7) { + /*else*/ { + __pyx_v_info->shape = NULL; + } + __pyx_L6:; - /* "View.MemoryView":952 - * - * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: - * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") # <<<<<<<<<<<<<< + /* "View.MemoryView":522 + * info.shape = NULL * - * return 1 + * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< + * info.strides = self.view.strides + * else: */ - __pyx_t_9 = __pyx_memoryview_err(__pyx_builtin_ValueError, ((char *)"Cannot transpose memoryview with indirect dimensions")); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 952, __pyx_L1_error) + __pyx_t_1 = ((__pyx_v_flags & PyBUF_STRIDES) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":951 - * shape[i], shape[j] = shape[j], shape[i] - * - * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: # <<<<<<<<<<<<<< - * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") + /* "View.MemoryView":523 * + * if flags & PyBUF_STRIDES: + * info.strides = self.view.strides # <<<<<<<<<<<<<< + * else: + * info.strides = NULL */ - } - } + __pyx_t_4 = __pyx_v_self->view.strides; + __pyx_v_info->strides = __pyx_t_4; - /* "View.MemoryView":954 - * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") - * - * return 1 # <<<<<<<<<<<<<< - * + /* "View.MemoryView":522 + * info.shape = NULL * + * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<< + * info.strides = self.view.strides + * else: */ - __pyx_r = 1; - goto __pyx_L0; + goto __pyx_L7; + } - /* "View.MemoryView":938 - * - * @cname('__pyx_memslice_transpose') - * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<< - * cdef int ndim = memslice.memview.view.ndim + /* "View.MemoryView":525 + * info.strides = self.view.strides + * else: + * info.strides = NULL # <<<<<<<<<<<<<< * + * if flags & PyBUF_INDIRECT: */ - - /* function exit code */ - __pyx_L1_error:; - { - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_AddTraceback("View.MemoryView.transpose_memslice", __pyx_clineno, __pyx_lineno, __pyx_filename); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif + /*else*/ { + __pyx_v_info->strides = NULL; } - __pyx_r = 0; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); - return __pyx_r; -} + __pyx_L7:; -/* "View.MemoryView":971 - * cdef int (*to_dtype_func)(char *, object) except 0 - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) + /* "View.MemoryView":527 + * info.strides = NULL * + * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<< + * info.suboffsets = self.view.suboffsets + * else: */ + __pyx_t_1 = ((__pyx_v_flags & PyBUF_INDIRECT) != 0); + if (__pyx_t_1) { -/* Python wrapper */ -static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -static void __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self) { - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[1], 971, 0, __PYX_ERR(1, 971, __pyx_L1_error)); - - /* "View.MemoryView":972 - * - * def __dealloc__(self): - * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) # <<<<<<<<<<<<<< + /* "View.MemoryView":528 * - * cdef convert_item_to_object(self, char *itemp): + * if flags & PyBUF_INDIRECT: + * info.suboffsets = self.view.suboffsets # <<<<<<<<<<<<<< + * else: + * info.suboffsets = NULL */ - __PYX_XDEC_MEMVIEW((&__pyx_v_self->from_slice), 1); + __pyx_t_4 = __pyx_v_self->view.suboffsets; + __pyx_v_info->suboffsets = __pyx_t_4; - /* "View.MemoryView":971 - * cdef int (*to_dtype_func)(char *, object) except 0 - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) + /* "View.MemoryView":527 + * info.strides = NULL * + * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<< + * info.suboffsets = self.view.suboffsets + * else: */ + goto __pyx_L8; + } - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView._memoryviewslice.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); -} - -/* "View.MemoryView":974 - * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) + /* "View.MemoryView":530 + * info.suboffsets = self.view.suboffsets + * else: + * info.suboffsets = NULL # <<<<<<<<<<<<<< * - * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< - * if self.to_object_func != NULL: - * return self.to_object_func(itemp) + * if flags & PyBUF_FORMAT: */ + /*else*/ { + __pyx_v_info->suboffsets = NULL; + } + __pyx_L8:; -static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("convert_item_to_object", 0); - __Pyx_TraceCall("convert_item_to_object", __pyx_f[1], 974, 0, __PYX_ERR(1, 974, __pyx_L1_error)); - - /* "View.MemoryView":975 + /* "View.MemoryView":532 + * info.suboffsets = NULL * - * cdef convert_item_to_object(self, char *itemp): - * if self.to_object_func != NULL: # <<<<<<<<<<<<<< - * return self.to_object_func(itemp) + * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< + * info.format = self.view.format * else: */ - __pyx_t_1 = ((__pyx_v_self->to_object_func != NULL) != 0); + __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0); if (__pyx_t_1) { - /* "View.MemoryView":976 - * cdef convert_item_to_object(self, char *itemp): - * if self.to_object_func != NULL: - * return self.to_object_func(itemp) # <<<<<<<<<<<<<< + /* "View.MemoryView":533 + * + * if flags & PyBUF_FORMAT: + * info.format = self.view.format # <<<<<<<<<<<<<< * else: - * return memoryview.convert_item_to_object(self, itemp) + * info.format = NULL */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_v_self->to_object_func(__pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 976, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_t_5 = __pyx_v_self->view.format; + __pyx_v_info->format = __pyx_t_5; - /* "View.MemoryView":975 + /* "View.MemoryView":532 + * info.suboffsets = NULL * - * cdef convert_item_to_object(self, char *itemp): - * if self.to_object_func != NULL: # <<<<<<<<<<<<<< - * return self.to_object_func(itemp) + * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<< + * info.format = self.view.format * else: */ + goto __pyx_L9; } - /* "View.MemoryView":978 - * return self.to_object_func(itemp) + /* "View.MemoryView":535 + * info.format = self.view.format * else: - * return memoryview.convert_item_to_object(self, itemp) # <<<<<<<<<<<<<< + * info.format = NULL # <<<<<<<<<<<<<< * - * cdef assign_item_from_object(self, char *itemp, object value): + * info.buf = self.view.buf */ /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_memoryview_convert_item_to_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 978, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_v_info->format = NULL; } + __pyx_L9:; - /* "View.MemoryView":974 - * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) + /* "View.MemoryView":537 + * info.format = NULL * - * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< - * if self.to_object_func != NULL: - * return self.to_object_func(itemp) + * info.buf = self.view.buf # <<<<<<<<<<<<<< + * info.ndim = self.view.ndim + * info.itemsize = self.view.itemsize */ + __pyx_t_6 = __pyx_v_self->view.buf; + __pyx_v_info->buf = __pyx_t_6; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("View.MemoryView._memoryviewslice.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "View.MemoryView":980 - * return memoryview.convert_item_to_object(self, itemp) + /* "View.MemoryView":538 * - * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< - * if self.to_dtype_func != NULL: - * self.to_dtype_func(itemp, value) + * info.buf = self.view.buf + * info.ndim = self.view.ndim # <<<<<<<<<<<<<< + * info.itemsize = self.view.itemsize + * info.len = self.view.len */ + __pyx_t_7 = __pyx_v_self->view.ndim; + __pyx_v_info->ndim = __pyx_t_7; -static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("assign_item_from_object", 0); - __Pyx_TraceCall("assign_item_from_object", __pyx_f[1], 980, 0, __PYX_ERR(1, 980, __pyx_L1_error)); - - /* "View.MemoryView":981 - * - * cdef assign_item_from_object(self, char *itemp, object value): - * if self.to_dtype_func != NULL: # <<<<<<<<<<<<<< - * self.to_dtype_func(itemp, value) - * else: + /* "View.MemoryView":539 + * info.buf = self.view.buf + * info.ndim = self.view.ndim + * info.itemsize = self.view.itemsize # <<<<<<<<<<<<<< + * info.len = self.view.len + * info.readonly = self.view.readonly */ - __pyx_t_1 = ((__pyx_v_self->to_dtype_func != NULL) != 0); - if (__pyx_t_1) { + __pyx_t_8 = __pyx_v_self->view.itemsize; + __pyx_v_info->itemsize = __pyx_t_8; - /* "View.MemoryView":982 - * cdef assign_item_from_object(self, char *itemp, object value): - * if self.to_dtype_func != NULL: - * self.to_dtype_func(itemp, value) # <<<<<<<<<<<<<< - * else: - * memoryview.assign_item_from_object(self, itemp, value) + /* "View.MemoryView":540 + * info.ndim = self.view.ndim + * info.itemsize = self.view.itemsize + * info.len = self.view.len # <<<<<<<<<<<<<< + * info.readonly = self.view.readonly + * info.obj = self */ - __pyx_t_2 = __pyx_v_self->to_dtype_func(__pyx_v_itemp, __pyx_v_value); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(1, 982, __pyx_L1_error) + __pyx_t_8 = __pyx_v_self->view.len; + __pyx_v_info->len = __pyx_t_8; - /* "View.MemoryView":981 + /* "View.MemoryView":541 + * info.itemsize = self.view.itemsize + * info.len = self.view.len + * info.readonly = self.view.readonly # <<<<<<<<<<<<<< + * info.obj = self * - * cdef assign_item_from_object(self, char *itemp, object value): - * if self.to_dtype_func != NULL: # <<<<<<<<<<<<<< - * self.to_dtype_func(itemp, value) - * else: */ - goto __pyx_L3; - } + __pyx_t_1 = __pyx_v_self->view.readonly; + __pyx_v_info->readonly = __pyx_t_1; - /* "View.MemoryView":984 - * self.to_dtype_func(itemp, value) - * else: - * memoryview.assign_item_from_object(self, itemp, value) # <<<<<<<<<<<<<< + /* "View.MemoryView":542 + * info.len = self.view.len + * info.readonly = self.view.readonly + * info.obj = self # <<<<<<<<<<<<<< * - * @property + * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") */ - /*else*/ { - __pyx_t_3 = __pyx_memoryview_assign_item_from_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 984, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __pyx_L3:; + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); + __pyx_v_info->obj = ((PyObject *)__pyx_v_self); - /* "View.MemoryView":980 - * return memoryview.convert_item_to_object(self, itemp) + /* "View.MemoryView":513 * - * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< - * if self.to_dtype_func != NULL: - * self.to_dtype_func(itemp, value) + * @cname('getbuffer') + * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<< + * if flags & PyBUF_WRITABLE and self.view.readonly: + * raise ValueError("Cannot create writable memory view from read-only memoryview") */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView._memoryviewslice.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_AddTraceback("View.MemoryView.memoryview.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + if (__pyx_v_info->obj != NULL) { + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; + } + goto __pyx_L2; __pyx_L0:; + if (__pyx_v_info->obj == Py_None) { + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; + } + __pyx_L2:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":548 + * + * @property + * def T(self): # <<<<<<<<<<<<<< + * cdef _memoryviewslice result = memoryview_copy(self) + * transpose_memslice(&result.from_slice) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + struct __pyx_memoryviewslice_obj *__pyx_v_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 548, 0, __PYX_ERR(1, 548, __pyx_L1_error)); + + /* "View.MemoryView":549 + * @property + * def T(self): + * cdef _memoryviewslice result = memoryview_copy(self) # <<<<<<<<<<<<<< + * transpose_memslice(&result.from_slice) + * return result + */ + __pyx_t_1 = __pyx_memoryview_copy_object(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 549, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_memoryviewslice_type))))) __PYX_ERR(1, 549, __pyx_L1_error) + __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "View.MemoryView":550 + * def T(self): + * cdef _memoryviewslice result = memoryview_copy(self) + * transpose_memslice(&result.from_slice) # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_2 = __pyx_memslice_transpose((&__pyx_v_result->from_slice)); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(1, 550, __pyx_L1_error) + + /* "View.MemoryView":551 + * cdef _memoryviewslice result = memoryview_copy(self) + * transpose_memslice(&result.from_slice) + * return result # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; + + /* "View.MemoryView":548 + * + * @property + * def T(self): # <<<<<<<<<<<<<< + * cdef _memoryviewslice result = memoryview_copy(self) + * transpose_memslice(&result.from_slice) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview.T.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":987 +/* "View.MemoryView":554 * * @property * def base(self): # <<<<<<<<<<<<<< - * return self.from_object + * return self.obj * */ /* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self) { +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[1], 987, 0, __PYX_ERR(1, 987, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[1], 554, 0, __PYX_ERR(1, 554, __pyx_L1_error)); - /* "View.MemoryView":988 + /* "View.MemoryView":555 * @property * def base(self): - * return self.from_object # <<<<<<<<<<<<<< + * return self.obj # <<<<<<<<<<<<<< * - * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") + * @property */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->from_object); - __pyx_r = __pyx_v_self->from_object; + __Pyx_INCREF(__pyx_v_self->obj); + __pyx_r = __pyx_v_self->obj; goto __pyx_L0; - /* "View.MemoryView":987 + /* "View.MemoryView":554 * * @property * def base(self): # <<<<<<<<<<<<<< - * return self.from_object + * return self.obj * */ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("View.MemoryView._memoryviewslice.base.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("View.MemoryView.memoryview.base.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -40143,498 +45565,652 @@ static PyObject *__pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__ return __pyx_r; } -/* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): +/* "View.MemoryView":558 + * + * @property + * def shape(self): # <<<<<<<<<<<<<< + * return tuple([length for length in self.view.shape[:self.view.ndim]]) + * */ /* Python wrapper */ -static PyObject *__pyx_pw___pyx_memoryviewslice_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw___pyx_memoryviewslice_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf___pyx_memoryviewslice___reduce_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf___pyx_memoryviewslice___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self) { +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + Py_ssize_t __pyx_v_length; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + Py_ssize_t *__pyx_t_2; + Py_ssize_t *__pyx_t_3; + Py_ssize_t *__pyx_t_4; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 558, 0, __PYX_ERR(1, 558, __pyx_L1_error)); - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + /* "View.MemoryView":559 + * @property + * def shape(self): + * return tuple([length for length in self.view.shape[:self.view.ndim]]) # <<<<<<<<<<<<<< + * + * @property */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__58, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 559, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __pyx_t_3 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim); + for (__pyx_t_4 = __pyx_v_self->view.shape; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) { + __pyx_t_2 = __pyx_t_4; + __pyx_v_length = (__pyx_t_2[0]); + __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(1, 559, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __pyx_t_5 = PyList_AsTuple(((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; - /* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): + /* "View.MemoryView":558 + * + * @property + * def shape(self): # <<<<<<<<<<<<<< + * return tuple([length for length in self.view.shape[:self.view.ndim]]) + * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView._memoryviewslice.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.memoryview.shape.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; + __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") +/* "View.MemoryView":562 + * + * @property + * def strides(self): # <<<<<<<<<<<<<< + * if self.view.strides == NULL: + * */ /* Python wrapper */ -static PyObject *__pyx_pw___pyx_memoryviewslice_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw___pyx_memoryviewslice_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf___pyx_memoryviewslice_2__setstate_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf___pyx_memoryviewslice_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + Py_ssize_t __pyx_v_stride; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t *__pyx_t_3; + Py_ssize_t *__pyx_t_4; + Py_ssize_t *__pyx_t_5; + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 562, 0, __PYX_ERR(1, 562, __pyx_L1_error)); - /* "(tree fragment)":4 - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + /* "View.MemoryView":563 + * @property + * def strides(self): + * if self.view.strides == NULL: # <<<<<<<<<<<<<< + * + * raise ValueError("Buffer view does not expose strides") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__59, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = ((__pyx_v_self->view.strides == NULL) != 0); + if (unlikely(__pyx_t_1)) { - /* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + /* "View.MemoryView":565 + * if self.view.strides == NULL: + * + * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<< + * + * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__65, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 565, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(1, 565, __pyx_L1_error) + + /* "View.MemoryView":563 + * @property + * def strides(self): + * if self.view.strides == NULL: # <<<<<<<<<<<<<< + * + * raise ValueError("Buffer view does not expose strides") + */ + } + + /* "View.MemoryView":567 + * raise ValueError("Buffer view does not expose strides") + * + * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 567, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = (__pyx_v_self->view.strides + __pyx_v_self->view.ndim); + for (__pyx_t_5 = __pyx_v_self->view.strides; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) { + __pyx_t_3 = __pyx_t_5; + __pyx_v_stride = (__pyx_t_3[0]); + __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_stride); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 567, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_6))) __PYX_ERR(1, 567, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __pyx_t_6 = PyList_AsTuple(((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 567, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L0; + + /* "View.MemoryView":562 + * + * @property + * def strides(self): # <<<<<<<<<<<<<< + * if self.view.strides == NULL: + * */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView._memoryviewslice.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("View.MemoryView.memoryview.strides.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; + __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":994 +/* "View.MemoryView":570 * - * @cname('__pyx_memoryview_fromslice') - * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice, # <<<<<<<<<<<<<< - * int ndim, - * object (*to_object_func)(char *), + * @property + * def suboffsets(self): # <<<<<<<<<<<<<< + * if self.view.suboffsets == NULL: + * return (-1,) * self.view.ndim */ -static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice __pyx_v_memviewslice, int __pyx_v_ndim, PyObject *(*__pyx_v_to_object_func)(char *), int (*__pyx_v_to_dtype_func)(char *, PyObject *), int __pyx_v_dtype_is_object) { - struct __pyx_memoryviewslice_obj *__pyx_v_result = 0; +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self) { Py_ssize_t __pyx_v_suboffset; - PyObject *__pyx_v_length = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - __Pyx_TypeInfo *__pyx_t_4; - Py_buffer __pyx_t_5; + Py_ssize_t *__pyx_t_4; + Py_ssize_t *__pyx_t_5; Py_ssize_t *__pyx_t_6; - Py_ssize_t *__pyx_t_7; - Py_ssize_t *__pyx_t_8; - Py_ssize_t __pyx_t_9; - __Pyx_RefNannySetupContext("memoryview_fromslice", 0); - __Pyx_TraceCall("memoryview_fromslice", __pyx_f[1], 994, 0, __PYX_ERR(1, 994, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 570, 0, __PYX_ERR(1, 570, __pyx_L1_error)); - /* "View.MemoryView":1002 - * cdef _memoryviewslice result - * - * if memviewslice.memview == Py_None: # <<<<<<<<<<<<<< - * return None + /* "View.MemoryView":571 + * @property + * def suboffsets(self): + * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<< + * return (-1,) * self.view.ndim * */ - __pyx_t_1 = ((((PyObject *)__pyx_v_memviewslice.memview) == Py_None) != 0); + __pyx_t_1 = ((__pyx_v_self->view.suboffsets == NULL) != 0); if (__pyx_t_1) { - /* "View.MemoryView":1003 - * - * if memviewslice.memview == Py_None: - * return None # <<<<<<<<<<<<<< - * + /* "View.MemoryView":572 + * def suboffsets(self): + * if self.view.suboffsets == NULL: + * return (-1,) * self.view.ndim # <<<<<<<<<<<<<< * + * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) */ __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 572, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_Multiply(__pyx_tuple__66, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 572, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; goto __pyx_L0; - /* "View.MemoryView":1002 - * cdef _memoryviewslice result - * - * if memviewslice.memview == Py_None: # <<<<<<<<<<<<<< - * return None + /* "View.MemoryView":571 + * @property + * def suboffsets(self): + * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<< + * return (-1,) * self.view.ndim * */ } - /* "View.MemoryView":1008 - * + /* "View.MemoryView":574 + * return (-1,) * self.view.ndim * - * result = _memoryviewslice(None, 0, dtype_is_object) # <<<<<<<<<<<<<< + * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) # <<<<<<<<<<<<<< * - * result.from_slice = memviewslice + * @property */ - __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1008, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1008, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 574, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_3, 0, Py_None); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryviewslice_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1008, __pyx_L1_error) + __pyx_t_5 = (__pyx_v_self->view.suboffsets + __pyx_v_self->view.ndim); + for (__pyx_t_6 = __pyx_v_self->view.suboffsets; __pyx_t_6 < __pyx_t_5; __pyx_t_6++) { + __pyx_t_4 = __pyx_t_6; + __pyx_v_suboffset = (__pyx_t_4[0]); + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_suboffset); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 574, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_2))) __PYX_ERR(1, 574, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_t_2 = PyList_AsTuple(((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 574, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_2); + __pyx_r = __pyx_t_2; __pyx_t_2 = 0; + goto __pyx_L0; - /* "View.MemoryView":1010 - * result = _memoryviewslice(None, 0, dtype_is_object) - * - * result.from_slice = memviewslice # <<<<<<<<<<<<<< - * __PYX_INC_MEMVIEW(&memviewslice, 1) + /* "View.MemoryView":570 * + * @property + * def suboffsets(self): # <<<<<<<<<<<<<< + * if self.view.suboffsets == NULL: + * return (-1,) * self.view.ndim */ - __pyx_v_result->from_slice = __pyx_v_memviewslice; - /* "View.MemoryView":1011 + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview.suboffsets.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":577 * - * result.from_slice = memviewslice - * __PYX_INC_MEMVIEW(&memviewslice, 1) # <<<<<<<<<<<<<< + * @property + * def ndim(self): # <<<<<<<<<<<<<< + * return self.view.ndim * - * result.from_object = ( memviewslice.memview).base */ - __PYX_INC_MEMVIEW((&__pyx_v_memviewslice), 1); - /* "View.MemoryView":1013 - * __PYX_INC_MEMVIEW(&memviewslice, 1) - * - * result.from_object = ( memviewslice.memview).base # <<<<<<<<<<<<<< - * result.typeinfo = memviewslice.memview.typeinfo +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 577, 0, __PYX_ERR(1, 577, __pyx_L1_error)); + + /* "View.MemoryView":578 + * @property + * def ndim(self): + * return self.view.ndim # <<<<<<<<<<<<<< * + * @property */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_memviewslice.memview), __pyx_n_s_base); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1013, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_v_result->from_object); - __Pyx_DECREF(__pyx_v_result->from_object); - __pyx_v_result->from_object = __pyx_t_2; - __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 578, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "View.MemoryView":1014 + /* "View.MemoryView":577 * - * result.from_object = ( memviewslice.memview).base - * result.typeinfo = memviewslice.memview.typeinfo # <<<<<<<<<<<<<< + * @property + * def ndim(self): # <<<<<<<<<<<<<< + * return self.view.ndim * - * result.view = memviewslice.memview.view */ - __pyx_t_4 = __pyx_v_memviewslice.memview->typeinfo; - __pyx_v_result->__pyx_base.typeinfo = __pyx_t_4; - /* "View.MemoryView":1016 - * result.typeinfo = memviewslice.memview.typeinfo - * - * result.view = memviewslice.memview.view # <<<<<<<<<<<<<< - * result.view.buf = memviewslice.data - * result.view.ndim = ndim - */ - __pyx_t_5 = __pyx_v_memviewslice.memview->view; - __pyx_v_result->__pyx_base.view = __pyx_t_5; + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview.ndim.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":1017 +/* "View.MemoryView":581 + * + * @property + * def itemsize(self): # <<<<<<<<<<<<<< + * return self.view.itemsize * - * result.view = memviewslice.memview.view - * result.view.buf = memviewslice.data # <<<<<<<<<<<<<< - * result.view.ndim = ndim - * (<__pyx_buffer *> &result.view).obj = Py_None */ - __pyx_v_result->__pyx_base.view.buf = ((void *)__pyx_v_memviewslice.data); - /* "View.MemoryView":1018 - * result.view = memviewslice.memview.view - * result.view.buf = memviewslice.data - * result.view.ndim = ndim # <<<<<<<<<<<<<< - * (<__pyx_buffer *> &result.view).obj = Py_None - * Py_INCREF(Py_None) - */ - __pyx_v_result->__pyx_base.view.ndim = __pyx_v_ndim; +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - /* "View.MemoryView":1019 - * result.view.buf = memviewslice.data - * result.view.ndim = ndim - * (<__pyx_buffer *> &result.view).obj = Py_None # <<<<<<<<<<<<<< - * Py_INCREF(Py_None) - * - */ - ((Py_buffer *)(&__pyx_v_result->__pyx_base.view))->obj = Py_None; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":1020 - * result.view.ndim = ndim - * (<__pyx_buffer *> &result.view).obj = Py_None - * Py_INCREF(Py_None) # <<<<<<<<<<<<<< - * - * if (memviewslice.memview).flags & PyBUF_WRITABLE: - */ - Py_INCREF(Py_None); +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 581, 0, __PYX_ERR(1, 581, __pyx_L1_error)); - /* "View.MemoryView":1022 - * Py_INCREF(Py_None) + /* "View.MemoryView":582 + * @property + * def itemsize(self): + * return self.view.itemsize # <<<<<<<<<<<<<< * - * if (memviewslice.memview).flags & PyBUF_WRITABLE: # <<<<<<<<<<<<<< - * result.flags = PyBUF_RECORDS - * else: + * @property */ - __pyx_t_1 = ((((struct __pyx_memoryview_obj *)__pyx_v_memviewslice.memview)->flags & PyBUF_WRITABLE) != 0); - if (__pyx_t_1) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 582, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "View.MemoryView":1023 + /* "View.MemoryView":581 * - * if (memviewslice.memview).flags & PyBUF_WRITABLE: - * result.flags = PyBUF_RECORDS # <<<<<<<<<<<<<< - * else: - * result.flags = PyBUF_RECORDS_RO - */ - __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS; - - /* "View.MemoryView":1022 - * Py_INCREF(Py_None) + * @property + * def itemsize(self): # <<<<<<<<<<<<<< + * return self.view.itemsize * - * if (memviewslice.memview).flags & PyBUF_WRITABLE: # <<<<<<<<<<<<<< - * result.flags = PyBUF_RECORDS - * else: */ - goto __pyx_L4; - } - /* "View.MemoryView":1025 - * result.flags = PyBUF_RECORDS - * else: - * result.flags = PyBUF_RECORDS_RO # <<<<<<<<<<<<<< - * - * result.view.shape = result.from_slice.shape - */ - /*else*/ { - __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS_RO; - } - __pyx_L4:; + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview.itemsize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":1027 - * result.flags = PyBUF_RECORDS_RO +/* "View.MemoryView":585 * - * result.view.shape = result.from_slice.shape # <<<<<<<<<<<<<< - * result.view.strides = result.from_slice.strides + * @property + * def nbytes(self): # <<<<<<<<<<<<<< + * return self.size * self.view.itemsize * */ - __pyx_v_result->__pyx_base.view.shape = ((Py_ssize_t *)__pyx_v_result->from_slice.shape); - /* "View.MemoryView":1028 - * - * result.view.shape = result.from_slice.shape - * result.view.strides = result.from_slice.strides # <<<<<<<<<<<<<< - * +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 585, 0, __PYX_ERR(1, 585, __pyx_L1_error)); + + /* "View.MemoryView":586 + * @property + * def nbytes(self): + * return self.size * self.view.itemsize # <<<<<<<<<<<<<< * + * @property */ - __pyx_v_result->__pyx_base.view.strides = ((Py_ssize_t *)__pyx_v_result->from_slice.strides); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 586, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 586, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 586, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "View.MemoryView":1031 + /* "View.MemoryView":585 * + * @property + * def nbytes(self): # <<<<<<<<<<<<<< + * return self.size * self.view.itemsize * - * result.view.suboffsets = NULL # <<<<<<<<<<<<<< - * for suboffset in result.from_slice.suboffsets[:ndim]: - * if suboffset >= 0: */ - __pyx_v_result->__pyx_base.view.suboffsets = NULL; - /* "View.MemoryView":1032 + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview.nbytes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":589 * - * result.view.suboffsets = NULL - * for suboffset in result.from_slice.suboffsets[:ndim]: # <<<<<<<<<<<<<< - * if suboffset >= 0: - * result.view.suboffsets = result.from_slice.suboffsets + * @property + * def size(self): # <<<<<<<<<<<<<< + * if self._size is None: + * result = 1 */ - __pyx_t_7 = (__pyx_v_result->from_slice.suboffsets + __pyx_v_ndim); - for (__pyx_t_8 = __pyx_v_result->from_slice.suboffsets; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) { - __pyx_t_6 = __pyx_t_8; - __pyx_v_suboffset = (__pyx_t_6[0]); - /* "View.MemoryView":1033 - * result.view.suboffsets = NULL - * for suboffset in result.from_slice.suboffsets[:ndim]: - * if suboffset >= 0: # <<<<<<<<<<<<<< - * result.view.suboffsets = result.from_slice.suboffsets - * break - */ - __pyx_t_1 = ((__pyx_v_suboffset >= 0) != 0); - if (__pyx_t_1) { +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - /* "View.MemoryView":1034 - * for suboffset in result.from_slice.suboffsets[:ndim]: - * if suboffset >= 0: - * result.view.suboffsets = result.from_slice.suboffsets # <<<<<<<<<<<<<< - * break - * - */ - __pyx_v_result->__pyx_base.view.suboffsets = ((Py_ssize_t *)__pyx_v_result->from_slice.suboffsets); + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":1035 - * if suboffset >= 0: - * result.view.suboffsets = result.from_slice.suboffsets - * break # <<<<<<<<<<<<<< - * - * result.view.len = result.view.itemsize - */ - goto __pyx_L6_break; +static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_length = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + Py_ssize_t *__pyx_t_3; + Py_ssize_t *__pyx_t_4; + Py_ssize_t *__pyx_t_5; + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 589, 0, __PYX_ERR(1, 589, __pyx_L1_error)); - /* "View.MemoryView":1033 - * result.view.suboffsets = NULL - * for suboffset in result.from_slice.suboffsets[:ndim]: - * if suboffset >= 0: # <<<<<<<<<<<<<< - * result.view.suboffsets = result.from_slice.suboffsets - * break + /* "View.MemoryView":590 + * @property + * def size(self): + * if self._size is None: # <<<<<<<<<<<<<< + * result = 1 + * */ - } - } - __pyx_L6_break:; + __pyx_t_1 = (__pyx_v_self->_size == Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1037 - * break + /* "View.MemoryView":591 + * def size(self): + * if self._size is None: + * result = 1 # <<<<<<<<<<<<<< * - * result.view.len = result.view.itemsize # <<<<<<<<<<<<<< - * for length in result.view.shape[:ndim]: - * result.view.len *= length + * for length in self.view.shape[:self.view.ndim]: */ - __pyx_t_9 = __pyx_v_result->__pyx_base.view.itemsize; - __pyx_v_result->__pyx_base.view.len = __pyx_t_9; + __Pyx_INCREF(__pyx_int_1); + __pyx_v_result = __pyx_int_1; - /* "View.MemoryView":1038 + /* "View.MemoryView":593 + * result = 1 * - * result.view.len = result.view.itemsize - * for length in result.view.shape[:ndim]: # <<<<<<<<<<<<<< - * result.view.len *= length + * for length in self.view.shape[:self.view.ndim]: # <<<<<<<<<<<<<< + * result *= length * */ - __pyx_t_7 = (__pyx_v_result->__pyx_base.view.shape + __pyx_v_ndim); - for (__pyx_t_8 = __pyx_v_result->__pyx_base.view.shape; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) { - __pyx_t_6 = __pyx_t_8; - __pyx_t_2 = PyInt_FromSsize_t((__pyx_t_6[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1038, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_2); - __pyx_t_2 = 0; + __pyx_t_4 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim); + for (__pyx_t_5 = __pyx_v_self->view.shape; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) { + __pyx_t_3 = __pyx_t_5; + __pyx_t_6 = PyInt_FromSsize_t((__pyx_t_3[0])); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 593, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_6); + __pyx_t_6 = 0; - /* "View.MemoryView":1039 - * result.view.len = result.view.itemsize - * for length in result.view.shape[:ndim]: - * result.view.len *= length # <<<<<<<<<<<<<< + /* "View.MemoryView":594 * - * result.to_object_func = to_object_func + * for length in self.view.shape[:self.view.ndim]: + * result *= length # <<<<<<<<<<<<<< + * + * self._size = result */ - __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_result->__pyx_base.view.len); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1039, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_InPlaceMultiply(__pyx_t_2, __pyx_v_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1039, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 1039, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_result->__pyx_base.view.len = __pyx_t_9; - } + __pyx_t_6 = PyNumber_InPlaceMultiply(__pyx_v_result, __pyx_v_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 594, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF_SET(__pyx_v_result, __pyx_t_6); + __pyx_t_6 = 0; + } - /* "View.MemoryView":1041 - * result.view.len *= length + /* "View.MemoryView":596 + * result *= length * - * result.to_object_func = to_object_func # <<<<<<<<<<<<<< - * result.to_dtype_func = to_dtype_func + * self._size = result # <<<<<<<<<<<<<< * + * return self._size */ - __pyx_v_result->to_object_func = __pyx_v_to_object_func; + __Pyx_INCREF(__pyx_v_result); + __Pyx_GIVEREF(__pyx_v_result); + __Pyx_GOTREF(__pyx_v_self->_size); + __Pyx_DECREF(__pyx_v_self->_size); + __pyx_v_self->_size = __pyx_v_result; - /* "View.MemoryView":1042 - * - * result.to_object_func = to_object_func - * result.to_dtype_func = to_dtype_func # <<<<<<<<<<<<<< + /* "View.MemoryView":590 + * @property + * def size(self): + * if self._size is None: # <<<<<<<<<<<<<< + * result = 1 * - * return result */ - __pyx_v_result->to_dtype_func = __pyx_v_to_dtype_func; + } - /* "View.MemoryView":1044 - * result.to_dtype_func = to_dtype_func + /* "View.MemoryView":598 + * self._size = result * - * return result # <<<<<<<<<<<<<< + * return self._size # <<<<<<<<<<<<<< * - * @cname('__pyx_memoryview_get_slice_from_memoryview') + * def __len__(self): */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = ((PyObject *)__pyx_v_result); + __Pyx_INCREF(__pyx_v_self->_size); + __pyx_r = __pyx_v_self->_size; goto __pyx_L0; - /* "View.MemoryView":994 + /* "View.MemoryView":589 * - * @cname('__pyx_memoryview_fromslice') - * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice, # <<<<<<<<<<<<<< - * int ndim, - * object (*to_object_func)(char *), + * @property + * def size(self): # <<<<<<<<<<<<<< + * if self._size is None: + * result = 1 */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("View.MemoryView.memoryview_fromslice", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("View.MemoryView.memoryview.size.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XDECREF(__pyx_v_result); __Pyx_XDECREF(__pyx_v_length); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); @@ -40642,295 +46218,266 @@ static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice __pyx_v_memviewsl return __pyx_r; } -/* "View.MemoryView":1047 +/* "View.MemoryView":600 + * return self._size * - * @cname('__pyx_memoryview_get_slice_from_memoryview') - * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview, # <<<<<<<<<<<<<< - * __Pyx_memviewslice *mslice): - * cdef _memoryviewslice obj + * def __len__(self): # <<<<<<<<<<<<<< + * if self.view.ndim >= 1: + * return self.view.shape[0] */ -static __Pyx_memviewslice *__pyx_memoryview_get_slice_from_memoryview(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_mslice) { - struct __pyx_memoryviewslice_obj *__pyx_v_obj = 0; - __Pyx_memviewslice *__pyx_r; +/* Python wrapper */ +static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static Py_ssize_t __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("get_slice_from_memview", 0); - __Pyx_TraceCall("get_slice_from_memview", __pyx_f[1], 1047, 0, __PYX_ERR(1, 1047, __pyx_L1_error)); - - /* "View.MemoryView":1050 - * __Pyx_memviewslice *mslice): - * cdef _memoryviewslice obj - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * obj = memview - * return &obj.from_slice - */ - __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __Pyx_RefNannySetupContext("__len__", 0); + __Pyx_TraceCall("__len__", __pyx_f[1], 600, 0, __PYX_ERR(1, 600, __pyx_L1_error)); - /* "View.MemoryView":1051 - * cdef _memoryviewslice obj - * if isinstance(memview, _memoryviewslice): - * obj = memview # <<<<<<<<<<<<<< - * return &obj.from_slice - * else: + /* "View.MemoryView":601 + * + * def __len__(self): + * if self.view.ndim >= 1: # <<<<<<<<<<<<<< + * return self.view.shape[0] + * */ - if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(1, 1051, __pyx_L1_error) - __pyx_t_3 = ((PyObject *)__pyx_v_memview); - __Pyx_INCREF(__pyx_t_3); - __pyx_v_obj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_1 = ((__pyx_v_self->view.ndim >= 1) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":1052 - * if isinstance(memview, _memoryviewslice): - * obj = memview - * return &obj.from_slice # <<<<<<<<<<<<<< - * else: - * slice_copy(memview, mslice) + /* "View.MemoryView":602 + * def __len__(self): + * if self.view.ndim >= 1: + * return self.view.shape[0] # <<<<<<<<<<<<<< + * + * return 0 */ - __pyx_r = (&__pyx_v_obj->from_slice); + __pyx_r = (__pyx_v_self->view.shape[0]); goto __pyx_L0; - /* "View.MemoryView":1050 - * __Pyx_memviewslice *mslice): - * cdef _memoryviewslice obj - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * obj = memview - * return &obj.from_slice + /* "View.MemoryView":601 + * + * def __len__(self): + * if self.view.ndim >= 1: # <<<<<<<<<<<<<< + * return self.view.shape[0] + * */ } - /* "View.MemoryView":1054 - * return &obj.from_slice - * else: - * slice_copy(memview, mslice) # <<<<<<<<<<<<<< - * return mslice + /* "View.MemoryView":604 + * return self.view.shape[0] + * + * return 0 # <<<<<<<<<<<<<< * + * def __repr__(self): */ - /*else*/ { - __pyx_memoryview_slice_copy(__pyx_v_memview, __pyx_v_mslice); + __pyx_r = 0; + goto __pyx_L0; - /* "View.MemoryView":1055 - * else: - * slice_copy(memview, mslice) - * return mslice # <<<<<<<<<<<<<< + /* "View.MemoryView":600 + * return self._size * - * @cname('__pyx_memoryview_slice_copy') - */ - __pyx_r = __pyx_v_mslice; - goto __pyx_L0; - } - - /* "View.MemoryView":1047 - * - * @cname('__pyx_memoryview_get_slice_from_memoryview') - * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview, # <<<<<<<<<<<<<< - * __Pyx_memviewslice *mslice): - * cdef _memoryviewslice obj + * def __len__(self): # <<<<<<<<<<<<<< + * if self.view.ndim >= 1: + * return self.view.shape[0] */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_WriteUnraisable("View.MemoryView.get_slice_from_memview", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_r = 0; + __Pyx_AddTraceback("View.MemoryView.memoryview.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_obj); __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":1058 +/* "View.MemoryView":606 + * return 0 * - * @cname('__pyx_memoryview_slice_copy') - * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst): # <<<<<<<<<<<<<< - * cdef int dim - * cdef (Py_ssize_t*) shape, strides, suboffsets + * def __repr__(self): # <<<<<<<<<<<<<< + * return "" % (self.base.__class__.__name__, + * id(self)) */ -static void __pyx_memoryview_slice_copy(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_dst) { - int __pyx_v_dim; - Py_ssize_t *__pyx_v_shape; - Py_ssize_t *__pyx_v_strides; - Py_ssize_t *__pyx_v_suboffsets; - __Pyx_TraceDeclarations +/* Python wrapper */ +static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - Py_ssize_t *__pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - Py_ssize_t __pyx_t_5; - __Pyx_RefNannySetupContext("slice_copy", 0); - __Pyx_TraceCall("slice_copy", __pyx_f[1], 1058, 0, __PYX_ERR(1, 1058, __pyx_L1_error)); - - /* "View.MemoryView":1062 - * cdef (Py_ssize_t*) shape, strides, suboffsets - * - * shape = memview.view.shape # <<<<<<<<<<<<<< - * strides = memview.view.strides - * suboffsets = memview.view.suboffsets - */ - __pyx_t_1 = __pyx_v_memview->view.shape; - __pyx_v_shape = __pyx_t_1; - - /* "View.MemoryView":1063 - * - * shape = memview.view.shape - * strides = memview.view.strides # <<<<<<<<<<<<<< - * suboffsets = memview.view.suboffsets - * - */ - __pyx_t_1 = __pyx_v_memview->view.strides; - __pyx_v_strides = __pyx_t_1; + __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(((struct __pyx_memoryview_obj *)__pyx_v_self)); - /* "View.MemoryView":1064 - * shape = memview.view.shape - * strides = memview.view.strides - * suboffsets = memview.view.suboffsets # <<<<<<<<<<<<<< - * - * dst.memview = <__pyx_memoryview *> memview - */ - __pyx_t_1 = __pyx_v_memview->view.suboffsets; - __pyx_v_suboffsets = __pyx_t_1; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":1066 - * suboffsets = memview.view.suboffsets - * - * dst.memview = <__pyx_memoryview *> memview # <<<<<<<<<<<<<< - * dst.data = memview.view.buf - * - */ - __pyx_v_dst->memview = ((struct __pyx_memoryview_obj *)__pyx_v_memview); +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__repr__", 0); + __Pyx_TraceCall("__repr__", __pyx_f[1], 606, 0, __PYX_ERR(1, 606, __pyx_L1_error)); - /* "View.MemoryView":1067 - * - * dst.memview = <__pyx_memoryview *> memview - * dst.data = memview.view.buf # <<<<<<<<<<<<<< + /* "View.MemoryView":607 * - * for dim in range(memview.view.ndim): - */ - __pyx_v_dst->data = ((char *)__pyx_v_memview->view.buf); - - /* "View.MemoryView":1069 - * dst.data = memview.view.buf + * def __repr__(self): + * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<< + * id(self)) * - * for dim in range(memview.view.ndim): # <<<<<<<<<<<<<< - * dst.shape[dim] = shape[dim] - * dst.strides[dim] = strides[dim] */ - __pyx_t_2 = __pyx_v_memview->view.ndim; - __pyx_t_3 = __pyx_t_2; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_dim = __pyx_t_4; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 607, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 607, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 607, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "View.MemoryView":1070 + /* "View.MemoryView":608 + * def __repr__(self): + * return "" % (self.base.__class__.__name__, + * id(self)) # <<<<<<<<<<<<<< * - * for dim in range(memview.view.ndim): - * dst.shape[dim] = shape[dim] # <<<<<<<<<<<<<< - * dst.strides[dim] = strides[dim] - * dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1 + * def __str__(self): */ - (__pyx_v_dst->shape[__pyx_v_dim]) = (__pyx_v_shape[__pyx_v_dim]); + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 608, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); - /* "View.MemoryView":1071 - * for dim in range(memview.view.ndim): - * dst.shape[dim] = shape[dim] - * dst.strides[dim] = strides[dim] # <<<<<<<<<<<<<< - * dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1 + /* "View.MemoryView":607 * - */ - (__pyx_v_dst->strides[__pyx_v_dim]) = (__pyx_v_strides[__pyx_v_dim]); - - /* "View.MemoryView":1072 - * dst.shape[dim] = shape[dim] - * dst.strides[dim] = strides[dim] - * dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1 # <<<<<<<<<<<<<< + * def __repr__(self): + * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<< + * id(self)) * - * @cname('__pyx_memoryview_copy_object') */ - if ((__pyx_v_suboffsets != 0)) { - __pyx_t_5 = (__pyx_v_suboffsets[__pyx_v_dim]); - } else { - __pyx_t_5 = -1L; - } - (__pyx_v_dst->suboffsets[__pyx_v_dim]) = __pyx_t_5; - } + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 607, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 607, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "View.MemoryView":1058 + /* "View.MemoryView":606 + * return 0 * - * @cname('__pyx_memoryview_slice_copy') - * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst): # <<<<<<<<<<<<<< - * cdef int dim - * cdef (Py_ssize_t*) shape, strides, suboffsets + * def __repr__(self): # <<<<<<<<<<<<<< + * return "" % (self.base.__class__.__name__, + * id(self)) */ /* function exit code */ - goto __pyx_L0; __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.slice_copy", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "View.MemoryView":1075 +/* "View.MemoryView":610 + * id(self)) + * + * def __str__(self): # <<<<<<<<<<<<<< + * return "" % (self.base.__class__.__name__,) * - * @cname('__pyx_memoryview_copy_object') - * cdef memoryview_copy(memoryview memview): # <<<<<<<<<<<<<< - * "Create a new memoryview object" - * cdef __Pyx_memviewslice memviewslice */ -static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *__pyx_v_memview) { - __Pyx_memviewslice __pyx_v_memviewslice; +/* Python wrapper */ +static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("memoryview_copy", 0); - __Pyx_TraceCall("memoryview_copy", __pyx_f[1], 1075, 0, __PYX_ERR(1, 1075, __pyx_L1_error)); + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__str__", 0); + __Pyx_TraceCall("__str__", __pyx_f[1], 610, 0, __PYX_ERR(1, 610, __pyx_L1_error)); - /* "View.MemoryView":1078 - * "Create a new memoryview object" - * cdef __Pyx_memviewslice memviewslice - * slice_copy(memview, &memviewslice) # <<<<<<<<<<<<<< - * return memoryview_copy_from_slice(memview, &memviewslice) + /* "View.MemoryView":611 + * + * def __str__(self): + * return "" % (self.base.__class__.__name__,) # <<<<<<<<<<<<<< * - */ - __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_memviewslice)); - - /* "View.MemoryView":1079 - * cdef __Pyx_memviewslice memviewslice - * slice_copy(memview, &memviewslice) - * return memoryview_copy_from_slice(memview, &memviewslice) # <<<<<<<<<<<<<< * - * @cname('__pyx_memoryview_copy_object_from_slice') */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_memoryview_copy_object_from_slice(__pyx_v_memview, (&__pyx_v_memviewslice)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1079, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 611, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 611, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 611, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 611, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_object, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 611, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "View.MemoryView":1075 + /* "View.MemoryView":610 + * id(self)) + * + * def __str__(self): # <<<<<<<<<<<<<< + * return "" % (self.base.__class__.__name__,) * - * @cname('__pyx_memoryview_copy_object') - * cdef memoryview_copy(memoryview memview): # <<<<<<<<<<<<<< - * "Create a new memoryview object" - * cdef __Pyx_memviewslice memviewslice */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("View.MemoryView.memoryview_copy", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.memoryview.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); @@ -40938,125 +46485,147 @@ static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *__pyx return __pyx_r; } -/* "View.MemoryView":1082 +/* "View.MemoryView":614 * - * @cname('__pyx_memoryview_copy_object_from_slice') - * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice): # <<<<<<<<<<<<<< - * """ - * Create a new memoryview object from a given memoryview object and slice. + * + * def is_c_contig(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice *mslice + * cdef __Pyx_memviewslice tmp */ -static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_memviewslice) { - PyObject *(*__pyx_v_to_object_func)(char *); - int (*__pyx_v_to_dtype_func)(char *, PyObject *); +/* Python wrapper */ +static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_c_contig (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self) { + __Pyx_memviewslice *__pyx_v_mslice; + __Pyx_memviewslice __pyx_v_tmp; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *(*__pyx_t_3)(char *); - int (*__pyx_t_4)(char *, PyObject *); - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("memoryview_copy_from_slice", 0); - __Pyx_TraceCall("memoryview_copy_from_slice", __pyx_f[1], 1082, 0, __PYX_ERR(1, 1082, __pyx_L1_error)); + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("is_c_contig", 0); + __Pyx_TraceCall("is_c_contig", __pyx_f[1], 614, 0, __PYX_ERR(1, 614, __pyx_L1_error)); - /* "View.MemoryView":1089 - * cdef int (*to_dtype_func)(char *, object) except 0 + /* "View.MemoryView":617 + * cdef __Pyx_memviewslice *mslice + * cdef __Pyx_memviewslice tmp + * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<< + * return slice_is_contig(mslice[0], 'C', self.view.ndim) * - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * to_object_func = (<_memoryviewslice> memview).to_object_func - * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func */ - __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __pyx_v_mslice = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); - /* "View.MemoryView":1090 + /* "View.MemoryView":618 + * cdef __Pyx_memviewslice tmp + * mslice = get_slice_from_memview(self, &tmp) + * return slice_is_contig(mslice[0], 'C', self.view.ndim) # <<<<<<<<<<<<<< * - * if isinstance(memview, _memoryviewslice): - * to_object_func = (<_memoryviewslice> memview).to_object_func # <<<<<<<<<<<<<< - * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func - * else: - */ - __pyx_t_3 = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_object_func; - __pyx_v_to_object_func = __pyx_t_3; - - /* "View.MemoryView":1091 - * if isinstance(memview, _memoryviewslice): - * to_object_func = (<_memoryviewslice> memview).to_object_func - * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func # <<<<<<<<<<<<<< - * else: - * to_object_func = NULL + * def is_f_contig(self): */ - __pyx_t_4 = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_dtype_func; - __pyx_v_to_dtype_func = __pyx_t_4; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'C', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 618, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "View.MemoryView":1089 - * cdef int (*to_dtype_func)(char *, object) except 0 + /* "View.MemoryView":614 * - * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< - * to_object_func = (<_memoryviewslice> memview).to_object_func - * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func - */ - goto __pyx_L3; - } - - /* "View.MemoryView":1093 - * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func - * else: - * to_object_func = NULL # <<<<<<<<<<<<<< - * to_dtype_func = NULL * + * def is_c_contig(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice *mslice + * cdef __Pyx_memviewslice tmp */ - /*else*/ { - __pyx_v_to_object_func = NULL; - /* "View.MemoryView":1094 - * else: - * to_object_func = NULL - * to_dtype_func = NULL # <<<<<<<<<<<<<< + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview.is_c_contig", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":620 + * return slice_is_contig(mslice[0], 'C', self.view.ndim) * - * return memoryview_fromslice(memviewslice[0], memview.view.ndim, + * def is_f_contig(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice *mslice + * cdef __Pyx_memviewslice tmp */ - __pyx_v_to_dtype_func = NULL; - } - __pyx_L3:; - /* "View.MemoryView":1096 - * to_dtype_func = NULL +/* Python wrapper */ +static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_f_contig (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self) { + __Pyx_memviewslice *__pyx_v_mslice; + __Pyx_memviewslice __pyx_v_tmp; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("is_f_contig", 0); + __Pyx_TraceCall("is_f_contig", __pyx_f[1], 620, 0, __PYX_ERR(1, 620, __pyx_L1_error)); + + /* "View.MemoryView":623 + * cdef __Pyx_memviewslice *mslice + * cdef __Pyx_memviewslice tmp + * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<< + * return slice_is_contig(mslice[0], 'F', self.view.ndim) * - * return memoryview_fromslice(memviewslice[0], memview.view.ndim, # <<<<<<<<<<<<<< - * to_object_func, to_dtype_func, - * memview.dtype_is_object) */ - __Pyx_XDECREF(__pyx_r); + __pyx_v_mslice = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); - /* "View.MemoryView":1098 - * return memoryview_fromslice(memviewslice[0], memview.view.ndim, - * to_object_func, to_dtype_func, - * memview.dtype_is_object) # <<<<<<<<<<<<<< - * + /* "View.MemoryView":624 + * cdef __Pyx_memviewslice tmp + * mslice = get_slice_from_memview(self, &tmp) + * return slice_is_contig(mslice[0], 'F', self.view.ndim) # <<<<<<<<<<<<<< * + * def copy(self): */ - __pyx_t_5 = __pyx_memoryview_fromslice((__pyx_v_memviewslice[0]), __pyx_v_memview->view.ndim, __pyx_v_to_object_func, __pyx_v_to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 1096, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'F', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 624, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "View.MemoryView":1082 + /* "View.MemoryView":620 + * return slice_is_contig(mslice[0], 'C', self.view.ndim) * - * @cname('__pyx_memoryview_copy_object_from_slice') - * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice): # <<<<<<<<<<<<<< - * """ - * Create a new memoryview object from a given memoryview object and slice. + * def is_f_contig(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice *mslice + * cdef __Pyx_memviewslice tmp */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView.memoryview_copy_from_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview.is_f_contig", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); @@ -41064,1915 +46633,2334 @@ static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview return __pyx_r; } -/* "View.MemoryView":1104 - * +/* "View.MemoryView":626 + * return slice_is_contig(mslice[0], 'F', self.view.ndim) * - * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: # <<<<<<<<<<<<<< - * if arg < 0: - * return -arg + * def copy(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice mslice + * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS */ -static Py_ssize_t abs_py_ssize_t(Py_ssize_t __pyx_v_arg) { - Py_ssize_t __pyx_r; - __Pyx_TraceDeclarations - int __pyx_t_1; - __Pyx_TraceCall("abs_py_ssize_t", __pyx_f[1], 1104, 1, __PYX_ERR(1, 1104, __pyx_L1_error)); +/* Python wrapper */ +static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("copy (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(((struct __pyx_memoryview_obj *)__pyx_v_self)); - /* "View.MemoryView":1105 - * - * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: - * if arg < 0: # <<<<<<<<<<<<<< - * return -arg - * else: - */ - __pyx_t_1 = ((__pyx_v_arg < 0) != 0); - if (__pyx_t_1) { + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":1106 - * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: - * if arg < 0: - * return -arg # <<<<<<<<<<<<<< - * else: - * return arg +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self) { + __Pyx_memviewslice __pyx_v_mslice; + int __pyx_v_flags; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_memviewslice __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("copy", 0); + __Pyx_TraceCall("copy", __pyx_f[1], 626, 0, __PYX_ERR(1, 626, __pyx_L1_error)); + + /* "View.MemoryView":628 + * def copy(self): + * cdef __Pyx_memviewslice mslice + * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS # <<<<<<<<<<<<<< + * + * slice_copy(self, &mslice) */ - __pyx_r = (-__pyx_v_arg); - goto __pyx_L0; + __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_F_CONTIGUOUS)); - /* "View.MemoryView":1105 + /* "View.MemoryView":630 + * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS * - * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: - * if arg < 0: # <<<<<<<<<<<<<< - * return -arg - * else: + * slice_copy(self, &mslice) # <<<<<<<<<<<<<< + * mslice = slice_copy_contig(&mslice, "c", self.view.ndim, + * self.view.itemsize, */ - } + __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_mslice)); - /* "View.MemoryView":1108 - * return -arg - * else: - * return arg # <<<<<<<<<<<<<< + /* "View.MemoryView":631 * - * @cname('__pyx_get_best_slice_order') + * slice_copy(self, &mslice) + * mslice = slice_copy_contig(&mslice, "c", self.view.ndim, # <<<<<<<<<<<<<< + * self.view.itemsize, + * flags|PyBUF_C_CONTIGUOUS, */ - /*else*/ { - __pyx_r = __pyx_v_arg; - goto __pyx_L0; - } + __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_mslice), ((char *)"c"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_C_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 631, __pyx_L1_error) + __pyx_v_mslice = __pyx_t_1; - /* "View.MemoryView":1104 + /* "View.MemoryView":636 + * self.dtype_is_object) * + * return memoryview_copy_from_slice(self, &mslice) # <<<<<<<<<<<<<< * - * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: # <<<<<<<<<<<<<< - * if arg < 0: - * return -arg + * def copy_fortran(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_mslice)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 636, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "View.MemoryView":626 + * return slice_is_contig(mslice[0], 'F', self.view.ndim) + * + * def copy(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice mslice + * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS */ /* function exit code */ __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.abs_py_ssize_t", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.memoryview.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":1111 +/* "View.MemoryView":638 + * return memoryview_copy_from_slice(self, &mslice) * - * @cname('__pyx_get_best_slice_order') - * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil: # <<<<<<<<<<<<<< - * """ - * Figure out the best memory access order for a given slice. + * def copy_fortran(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice src, dst + * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS */ -static char __pyx_get_best_slice_order(__Pyx_memviewslice *__pyx_v_mslice, int __pyx_v_ndim) { - int __pyx_v_i; - Py_ssize_t __pyx_v_c_stride; - Py_ssize_t __pyx_v_f_stride; - char __pyx_r; +/* Python wrapper */ +static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("copy_fortran (wrapper)", 0); + __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self) { + __Pyx_memviewslice __pyx_v_src; + __Pyx_memviewslice __pyx_v_dst; + int __pyx_v_flags; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_TraceCall("get_best_order", __pyx_f[1], 1111, 1, __PYX_ERR(1, 1111, __pyx_L1_error)); + __Pyx_RefNannyDeclarations + __Pyx_memviewslice __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("copy_fortran", 0); + __Pyx_TraceCall("copy_fortran", __pyx_f[1], 638, 0, __PYX_ERR(1, 638, __pyx_L1_error)); - /* "View.MemoryView":1116 - * """ - * cdef int i - * cdef Py_ssize_t c_stride = 0 # <<<<<<<<<<<<<< - * cdef Py_ssize_t f_stride = 0 + /* "View.MemoryView":640 + * def copy_fortran(self): + * cdef __Pyx_memviewslice src, dst + * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS # <<<<<<<<<<<<<< * + * slice_copy(self, &src) */ - __pyx_v_c_stride = 0; + __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_C_CONTIGUOUS)); - /* "View.MemoryView":1117 - * cdef int i - * cdef Py_ssize_t c_stride = 0 - * cdef Py_ssize_t f_stride = 0 # <<<<<<<<<<<<<< + /* "View.MemoryView":642 + * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS * - * for i in range(ndim - 1, -1, -1): + * slice_copy(self, &src) # <<<<<<<<<<<<<< + * dst = slice_copy_contig(&src, "fortran", self.view.ndim, + * self.view.itemsize, */ - __pyx_v_f_stride = 0; + __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_src)); - /* "View.MemoryView":1119 - * cdef Py_ssize_t f_stride = 0 + /* "View.MemoryView":643 * - * for i in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< - * if mslice.shape[i] > 1: - * c_stride = mslice.strides[i] + * slice_copy(self, &src) + * dst = slice_copy_contig(&src, "fortran", self.view.ndim, # <<<<<<<<<<<<<< + * self.view.itemsize, + * flags|PyBUF_F_CONTIGUOUS, */ - for (__pyx_t_1 = (__pyx_v_ndim - 1); __pyx_t_1 > -1; __pyx_t_1-=1) { - __pyx_v_i = __pyx_t_1; + __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_src), ((char *)"fortran"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_F_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 643, __pyx_L1_error) + __pyx_v_dst = __pyx_t_1; - /* "View.MemoryView":1120 + /* "View.MemoryView":648 + * self.dtype_is_object) + * + * return memoryview_copy_from_slice(self, &dst) # <<<<<<<<<<<<<< * - * for i in range(ndim - 1, -1, -1): - * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< - * c_stride = mslice.strides[i] - * break - */ - __pyx_t_2 = (((__pyx_v_mslice->shape[__pyx_v_i]) > 1) != 0); - if (__pyx_t_2) { - - /* "View.MemoryView":1121 - * for i in range(ndim - 1, -1, -1): - * if mslice.shape[i] > 1: - * c_stride = mslice.strides[i] # <<<<<<<<<<<<<< - * break * */ - __pyx_v_c_stride = (__pyx_v_mslice->strides[__pyx_v_i]); + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_dst)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 648, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "View.MemoryView":1122 - * if mslice.shape[i] > 1: - * c_stride = mslice.strides[i] - * break # <<<<<<<<<<<<<< + /* "View.MemoryView":638 + * return memoryview_copy_from_slice(self, &mslice) * - * for i in range(ndim): + * def copy_fortran(self): # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice src, dst + * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS */ - goto __pyx_L4_break; - /* "View.MemoryView":1120 - * - * for i in range(ndim - 1, -1, -1): - * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< - * c_stride = mslice.strides[i] - * break + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView.memoryview.copy_fortran", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): */ - } - } - __pyx_L4_break:; - /* "View.MemoryView":1124 - * break - * - * for i in range(ndim): # <<<<<<<<<<<<<< - * if mslice.shape[i] > 1: - * f_stride = mslice.strides[i] +/* Python wrapper */ +static PyObject *__pyx_pw___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf___pyx_memoryview___reduce_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __pyx_v_ndim; - __pyx_t_3 = __pyx_t_1; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_i = __pyx_t_4; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__67, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 2, __pyx_L1_error) - /* "View.MemoryView":1125 - * - * for i in range(ndim): - * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< - * f_stride = mslice.strides[i] - * break + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): */ - __pyx_t_2 = (((__pyx_v_mslice->shape[__pyx_v_i]) > 1) != 0); - if (__pyx_t_2) { - /* "View.MemoryView":1126 - * for i in range(ndim): - * if mslice.shape[i] > 1: - * f_stride = mslice.strides[i] # <<<<<<<<<<<<<< - * break - * + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_v_f_stride = (__pyx_v_mslice->strides[__pyx_v_i]); - /* "View.MemoryView":1127 - * if mslice.shape[i] > 1: - * f_stride = mslice.strides[i] - * break # <<<<<<<<<<<<<< - * - * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): +/* Python wrapper */ +static PyObject *__pyx_pw___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf___pyx_memoryview_2__setstate_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - goto __pyx_L7_break; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__68, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) - /* "View.MemoryView":1125 - * - * for i in range(ndim): - * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< - * f_stride = mslice.strides[i] - * break + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - } - } - __pyx_L7_break:; - /* "View.MemoryView":1129 - * break + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "View.MemoryView":652 * - * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): # <<<<<<<<<<<<<< - * return 'C' - * else: + * @cname('__pyx_memoryview_new') + * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): # <<<<<<<<<<<<<< + * cdef memoryview result = memoryview(o, flags, dtype_is_object) + * result.typeinfo = typeinfo */ - __pyx_t_2 = ((abs_py_ssize_t(__pyx_v_c_stride) <= abs_py_ssize_t(__pyx_v_f_stride)) != 0); - if (__pyx_t_2) { - /* "View.MemoryView":1130 - * - * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): - * return 'C' # <<<<<<<<<<<<<< - * else: - * return 'F' +static PyObject *__pyx_memoryview_new(PyObject *__pyx_v_o, int __pyx_v_flags, int __pyx_v_dtype_is_object, __Pyx_TypeInfo *__pyx_v_typeinfo) { + struct __pyx_memoryview_obj *__pyx_v_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("memoryview_cwrapper", 0); + __Pyx_TraceCall("memoryview_cwrapper", __pyx_f[1], 652, 0, __PYX_ERR(1, 652, __pyx_L1_error)); + + /* "View.MemoryView":653 + * @cname('__pyx_memoryview_new') + * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): + * cdef memoryview result = memoryview(o, flags, dtype_is_object) # <<<<<<<<<<<<<< + * result.typeinfo = typeinfo + * return result */ - __pyx_r = 'C'; - goto __pyx_L0; + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 653, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 653, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 653, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_o); + __Pyx_GIVEREF(__pyx_v_o); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_o); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 653, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_result = ((struct __pyx_memoryview_obj *)__pyx_t_2); + __pyx_t_2 = 0; - /* "View.MemoryView":1129 - * break + /* "View.MemoryView":654 + * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): + * cdef memoryview result = memoryview(o, flags, dtype_is_object) + * result.typeinfo = typeinfo # <<<<<<<<<<<<<< + * return result * - * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): # <<<<<<<<<<<<<< - * return 'C' - * else: */ - } + __pyx_v_result->typeinfo = __pyx_v_typeinfo; - /* "View.MemoryView":1132 - * return 'C' - * else: - * return 'F' # <<<<<<<<<<<<<< + /* "View.MemoryView":655 + * cdef memoryview result = memoryview(o, flags, dtype_is_object) + * result.typeinfo = typeinfo + * return result # <<<<<<<<<<<<<< * - * @cython.cdivision(True) + * @cname('__pyx_memoryview_check') */ - /*else*/ { - __pyx_r = 'F'; - goto __pyx_L0; - } + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; - /* "View.MemoryView":1111 + /* "View.MemoryView":652 * - * @cname('__pyx_get_best_slice_order') - * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil: # <<<<<<<<<<<<<< - * """ - * Figure out the best memory access order for a given slice. + * @cname('__pyx_memoryview_new') + * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): # <<<<<<<<<<<<<< + * cdef memoryview result = memoryview(o, flags, dtype_is_object) + * result.typeinfo = typeinfo */ /* function exit code */ __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.get_best_order", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":1135 +/* "View.MemoryView":658 + * + * @cname('__pyx_memoryview_check') + * cdef inline bint memoryview_check(object o): # <<<<<<<<<<<<<< + * return isinstance(o, memoryview) * - * @cython.cdivision(True) - * cdef void _copy_strided_to_strided(char *src_data, Py_ssize_t *src_strides, # <<<<<<<<<<<<<< - * char *dst_data, Py_ssize_t *dst_strides, - * Py_ssize_t *src_shape, Py_ssize_t *dst_shape, */ -static void _copy_strided_to_strided(char *__pyx_v_src_data, Py_ssize_t *__pyx_v_src_strides, char *__pyx_v_dst_data, Py_ssize_t *__pyx_v_dst_strides, Py_ssize_t *__pyx_v_src_shape, Py_ssize_t *__pyx_v_dst_shape, int __pyx_v_ndim, size_t __pyx_v_itemsize) { - CYTHON_UNUSED Py_ssize_t __pyx_v_i; - CYTHON_UNUSED Py_ssize_t __pyx_v_src_extent; - Py_ssize_t __pyx_v_dst_extent; - Py_ssize_t __pyx_v_src_stride; - Py_ssize_t __pyx_v_dst_stride; +static CYTHON_INLINE int __pyx_memoryview_check(PyObject *__pyx_v_o) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - Py_ssize_t __pyx_t_4; - Py_ssize_t __pyx_t_5; - Py_ssize_t __pyx_t_6; + __Pyx_RefNannySetupContext("memoryview_check", 0); + __Pyx_TraceCall("memoryview_check", __pyx_f[1], 658, 0, __PYX_ERR(1, 658, __pyx_L1_error)); - /* "View.MemoryView":1142 + /* "View.MemoryView":659 + * @cname('__pyx_memoryview_check') + * cdef inline bint memoryview_check(object o): + * return isinstance(o, memoryview) # <<<<<<<<<<<<<< * - * cdef Py_ssize_t i - * cdef Py_ssize_t src_extent = src_shape[0] # <<<<<<<<<<<<<< - * cdef Py_ssize_t dst_extent = dst_shape[0] - * cdef Py_ssize_t src_stride = src_strides[0] + * cdef tuple _unellipsify(object index, int ndim): */ - __pyx_v_src_extent = (__pyx_v_src_shape[0]); + __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_o, __pyx_memoryview_type); + __pyx_r = __pyx_t_1; + goto __pyx_L0; - /* "View.MemoryView":1143 - * cdef Py_ssize_t i - * cdef Py_ssize_t src_extent = src_shape[0] - * cdef Py_ssize_t dst_extent = dst_shape[0] # <<<<<<<<<<<<<< - * cdef Py_ssize_t src_stride = src_strides[0] - * cdef Py_ssize_t dst_stride = dst_strides[0] - */ - __pyx_v_dst_extent = (__pyx_v_dst_shape[0]); - - /* "View.MemoryView":1144 - * cdef Py_ssize_t src_extent = src_shape[0] - * cdef Py_ssize_t dst_extent = dst_shape[0] - * cdef Py_ssize_t src_stride = src_strides[0] # <<<<<<<<<<<<<< - * cdef Py_ssize_t dst_stride = dst_strides[0] + /* "View.MemoryView":658 * - */ - __pyx_v_src_stride = (__pyx_v_src_strides[0]); - - /* "View.MemoryView":1145 - * cdef Py_ssize_t dst_extent = dst_shape[0] - * cdef Py_ssize_t src_stride = src_strides[0] - * cdef Py_ssize_t dst_stride = dst_strides[0] # <<<<<<<<<<<<<< + * @cname('__pyx_memoryview_check') + * cdef inline bint memoryview_check(object o): # <<<<<<<<<<<<<< + * return isinstance(o, memoryview) * - * if ndim == 1: */ - __pyx_v_dst_stride = (__pyx_v_dst_strides[0]); - /* "View.MemoryView":1147 - * cdef Py_ssize_t dst_stride = dst_strides[0] - * - * if ndim == 1: # <<<<<<<<<<<<<< - * if (src_stride > 0 and dst_stride > 0 and - * src_stride == itemsize == dst_stride): - */ - __pyx_t_1 = ((__pyx_v_ndim == 1) != 0); - if (__pyx_t_1) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView.memoryview_check", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "View.MemoryView":1148 +/* "View.MemoryView":661 + * return isinstance(o, memoryview) * - * if ndim == 1: - * if (src_stride > 0 and dst_stride > 0 and # <<<<<<<<<<<<<< - * src_stride == itemsize == dst_stride): - * memcpy(dst_data, src_data, itemsize * dst_extent) + * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<< + * """ + * Replace all ellipses with full slices and fill incomplete indices with */ - __pyx_t_2 = ((__pyx_v_src_stride > 0) != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L5_bool_binop_done; - } - __pyx_t_2 = ((__pyx_v_dst_stride > 0) != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L5_bool_binop_done; - } - /* "View.MemoryView":1149 - * if ndim == 1: - * if (src_stride > 0 and dst_stride > 0 and - * src_stride == itemsize == dst_stride): # <<<<<<<<<<<<<< - * memcpy(dst_data, src_data, itemsize * dst_extent) - * else: +static PyObject *_unellipsify(PyObject *__pyx_v_index, int __pyx_v_ndim) { + PyObject *__pyx_v_tup = NULL; + PyObject *__pyx_v_result = NULL; + int __pyx_v_have_slices; + int __pyx_v_seen_ellipsis; + CYTHON_UNUSED PyObject *__pyx_v_idx = NULL; + PyObject *__pyx_v_item = NULL; + Py_ssize_t __pyx_v_nslices; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + PyObject *(*__pyx_t_6)(PyObject *); + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + int __pyx_t_9; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + __Pyx_RefNannySetupContext("_unellipsify", 0); + __Pyx_TraceCall("_unellipsify", __pyx_f[1], 661, 0, __PYX_ERR(1, 661, __pyx_L1_error)); + + /* "View.MemoryView":666 + * full slices. + * """ + * if not isinstance(index, tuple): # <<<<<<<<<<<<<< + * tup = (index,) + * else: */ - __pyx_t_2 = (((size_t)__pyx_v_src_stride) == __pyx_v_itemsize); - if (__pyx_t_2) { - __pyx_t_2 = (__pyx_v_itemsize == ((size_t)__pyx_v_dst_stride)); - } - __pyx_t_3 = (__pyx_t_2 != 0); - __pyx_t_1 = __pyx_t_3; - __pyx_L5_bool_binop_done:; + __pyx_t_1 = PyTuple_Check(__pyx_v_index); + __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1148 - * - * if ndim == 1: - * if (src_stride > 0 and dst_stride > 0 and # <<<<<<<<<<<<<< - * src_stride == itemsize == dst_stride): - * memcpy(dst_data, src_data, itemsize * dst_extent) + /* "View.MemoryView":667 + * """ + * if not isinstance(index, tuple): + * tup = (index,) # <<<<<<<<<<<<<< + * else: + * tup = index */ - if (__pyx_t_1) { + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 667, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_index); + __Pyx_GIVEREF(__pyx_v_index); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_index); + __pyx_v_tup = __pyx_t_3; + __pyx_t_3 = 0; - /* "View.MemoryView":1150 - * if (src_stride > 0 and dst_stride > 0 and - * src_stride == itemsize == dst_stride): - * memcpy(dst_data, src_data, itemsize * dst_extent) # <<<<<<<<<<<<<< - * else: - * for i in range(dst_extent): + /* "View.MemoryView":666 + * full slices. + * """ + * if not isinstance(index, tuple): # <<<<<<<<<<<<<< + * tup = (index,) + * else: */ - (void)(memcpy(__pyx_v_dst_data, __pyx_v_src_data, (__pyx_v_itemsize * __pyx_v_dst_extent))); + goto __pyx_L3; + } - /* "View.MemoryView":1148 + /* "View.MemoryView":669 + * tup = (index,) + * else: + * tup = index # <<<<<<<<<<<<<< * - * if ndim == 1: - * if (src_stride > 0 and dst_stride > 0 and # <<<<<<<<<<<<<< - * src_stride == itemsize == dst_stride): - * memcpy(dst_data, src_data, itemsize * dst_extent) + * result = [] */ - goto __pyx_L4; - } + /*else*/ { + __Pyx_INCREF(__pyx_v_index); + __pyx_v_tup = __pyx_v_index; + } + __pyx_L3:; - /* "View.MemoryView":1152 - * memcpy(dst_data, src_data, itemsize * dst_extent) - * else: - * for i in range(dst_extent): # <<<<<<<<<<<<<< - * memcpy(dst_data, src_data, itemsize) - * src_data += src_stride + /* "View.MemoryView":671 + * tup = index + * + * result = [] # <<<<<<<<<<<<<< + * have_slices = False + * seen_ellipsis = False */ - /*else*/ { - __pyx_t_4 = __pyx_v_dst_extent; - __pyx_t_5 = __pyx_t_4; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_i = __pyx_t_6; + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 671, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_result = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; - /* "View.MemoryView":1153 - * else: - * for i in range(dst_extent): - * memcpy(dst_data, src_data, itemsize) # <<<<<<<<<<<<<< - * src_data += src_stride - * dst_data += dst_stride + /* "View.MemoryView":672 + * + * result = [] + * have_slices = False # <<<<<<<<<<<<<< + * seen_ellipsis = False + * for idx, item in enumerate(tup): */ - (void)(memcpy(__pyx_v_dst_data, __pyx_v_src_data, __pyx_v_itemsize)); + __pyx_v_have_slices = 0; - /* "View.MemoryView":1154 - * for i in range(dst_extent): - * memcpy(dst_data, src_data, itemsize) - * src_data += src_stride # <<<<<<<<<<<<<< - * dst_data += dst_stride - * else: + /* "View.MemoryView":673 + * result = [] + * have_slices = False + * seen_ellipsis = False # <<<<<<<<<<<<<< + * for idx, item in enumerate(tup): + * if item is Ellipsis: */ - __pyx_v_src_data = (__pyx_v_src_data + __pyx_v_src_stride); + __pyx_v_seen_ellipsis = 0; - /* "View.MemoryView":1155 - * memcpy(dst_data, src_data, itemsize) - * src_data += src_stride - * dst_data += dst_stride # <<<<<<<<<<<<<< - * else: - * for i in range(dst_extent): + /* "View.MemoryView":674 + * have_slices = False + * seen_ellipsis = False + * for idx, item in enumerate(tup): # <<<<<<<<<<<<<< + * if item is Ellipsis: + * if not seen_ellipsis: */ - __pyx_v_dst_data = (__pyx_v_dst_data + __pyx_v_dst_stride); + __Pyx_INCREF(__pyx_int_0); + __pyx_t_3 = __pyx_int_0; + if (likely(PyList_CheckExact(__pyx_v_tup)) || PyTuple_CheckExact(__pyx_v_tup)) { + __pyx_t_4 = __pyx_v_tup; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_tup); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 674, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_6)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 674, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } else { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 674, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } + } else { + __pyx_t_7 = __pyx_t_6(__pyx_t_4); + if (unlikely(!__pyx_t_7)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(1, 674, __pyx_L1_error) + } + break; } + __Pyx_GOTREF(__pyx_t_7); } - __pyx_L4:; + __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_3); + __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); + __pyx_t_3 = __pyx_t_7; + __pyx_t_7 = 0; - /* "View.MemoryView":1147 - * cdef Py_ssize_t dst_stride = dst_strides[0] - * - * if ndim == 1: # <<<<<<<<<<<<<< - * if (src_stride > 0 and dst_stride > 0 and - * src_stride == itemsize == dst_stride): + /* "View.MemoryView":675 + * seen_ellipsis = False + * for idx, item in enumerate(tup): + * if item is Ellipsis: # <<<<<<<<<<<<<< + * if not seen_ellipsis: + * result.extend([slice(None)] * (ndim - len(tup) + 1)) */ - goto __pyx_L3; - } + __pyx_t_2 = (__pyx_v_item == __pyx_builtin_Ellipsis); + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { - /* "View.MemoryView":1157 - * dst_data += dst_stride - * else: - * for i in range(dst_extent): # <<<<<<<<<<<<<< - * _copy_strided_to_strided(src_data, src_strides + 1, - * dst_data, dst_strides + 1, + /* "View.MemoryView":676 + * for idx, item in enumerate(tup): + * if item is Ellipsis: + * if not seen_ellipsis: # <<<<<<<<<<<<<< + * result.extend([slice(None)] * (ndim - len(tup) + 1)) + * seen_ellipsis = True */ - /*else*/ { - __pyx_t_4 = __pyx_v_dst_extent; - __pyx_t_5 = __pyx_t_4; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_i = __pyx_t_6; + __pyx_t_1 = ((!(__pyx_v_seen_ellipsis != 0)) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":1158 - * else: - * for i in range(dst_extent): - * _copy_strided_to_strided(src_data, src_strides + 1, # <<<<<<<<<<<<<< - * dst_data, dst_strides + 1, - * src_shape + 1, dst_shape + 1, + /* "View.MemoryView":677 + * if item is Ellipsis: + * if not seen_ellipsis: + * result.extend([slice(None)] * (ndim - len(tup) + 1)) # <<<<<<<<<<<<<< + * seen_ellipsis = True + * else: */ - _copy_strided_to_strided(__pyx_v_src_data, (__pyx_v_src_strides + 1), __pyx_v_dst_data, (__pyx_v_dst_strides + 1), (__pyx_v_src_shape + 1), (__pyx_v_dst_shape + 1), (__pyx_v_ndim - 1), __pyx_v_itemsize); + __pyx_t_8 = PyObject_Length(__pyx_v_tup); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(1, 677, __pyx_L1_error) + __pyx_t_7 = PyList_New(1 * ((((__pyx_v_ndim - __pyx_t_8) + 1)<0) ? 0:((__pyx_v_ndim - __pyx_t_8) + 1))); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 677, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + { Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < ((__pyx_v_ndim - __pyx_t_8) + 1); __pyx_temp++) { + __Pyx_INCREF(__pyx_slice__69); + __Pyx_GIVEREF(__pyx_slice__69); + PyList_SET_ITEM(__pyx_t_7, __pyx_temp, __pyx_slice__69); + } + } + __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 677, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "View.MemoryView":1162 - * src_shape + 1, dst_shape + 1, - * ndim - 1, itemsize) - * src_data += src_stride # <<<<<<<<<<<<<< - * dst_data += dst_stride - * + /* "View.MemoryView":678 + * if not seen_ellipsis: + * result.extend([slice(None)] * (ndim - len(tup) + 1)) + * seen_ellipsis = True # <<<<<<<<<<<<<< + * else: + * result.append(slice(None)) */ - __pyx_v_src_data = (__pyx_v_src_data + __pyx_v_src_stride); + __pyx_v_seen_ellipsis = 1; - /* "View.MemoryView":1163 - * ndim - 1, itemsize) - * src_data += src_stride - * dst_data += dst_stride # <<<<<<<<<<<<<< - * - * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, + /* "View.MemoryView":676 + * for idx, item in enumerate(tup): + * if item is Ellipsis: + * if not seen_ellipsis: # <<<<<<<<<<<<<< + * result.extend([slice(None)] * (ndim - len(tup) + 1)) + * seen_ellipsis = True */ - __pyx_v_dst_data = (__pyx_v_dst_data + __pyx_v_dst_stride); - } - } - __pyx_L3:; + goto __pyx_L7; + } - /* "View.MemoryView":1135 - * - * @cython.cdivision(True) - * cdef void _copy_strided_to_strided(char *src_data, Py_ssize_t *src_strides, # <<<<<<<<<<<<<< - * char *dst_data, Py_ssize_t *dst_strides, - * Py_ssize_t *src_shape, Py_ssize_t *dst_shape, + /* "View.MemoryView":680 + * seen_ellipsis = True + * else: + * result.append(slice(None)) # <<<<<<<<<<<<<< + * have_slices = True + * else: */ + /*else*/ { + __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_slice__70); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 680, __pyx_L1_error) + } + __pyx_L7:; - /* function exit code */ -} - -/* "View.MemoryView":1165 - * dst_data += dst_stride - * - * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< - * __Pyx_memviewslice *dst, - * int ndim, size_t itemsize) nogil: + /* "View.MemoryView":681 + * else: + * result.append(slice(None)) + * have_slices = True # <<<<<<<<<<<<<< + * else: + * if not isinstance(item, slice) and not PyIndex_Check(item): */ + __pyx_v_have_slices = 1; -static void copy_strided_to_strided(__Pyx_memviewslice *__pyx_v_src, __Pyx_memviewslice *__pyx_v_dst, int __pyx_v_ndim, size_t __pyx_v_itemsize) { - __Pyx_TraceDeclarations - __Pyx_TraceCall("copy_strided_to_strided", __pyx_f[1], 1165, 1, __PYX_ERR(1, 1165, __pyx_L1_error)); + /* "View.MemoryView":675 + * seen_ellipsis = False + * for idx, item in enumerate(tup): + * if item is Ellipsis: # <<<<<<<<<<<<<< + * if not seen_ellipsis: + * result.extend([slice(None)] * (ndim - len(tup) + 1)) + */ + goto __pyx_L6; + } - /* "View.MemoryView":1168 - * __Pyx_memviewslice *dst, - * int ndim, size_t itemsize) nogil: - * _copy_strided_to_strided(src.data, src.strides, dst.data, dst.strides, # <<<<<<<<<<<<<< - * src.shape, dst.shape, ndim, itemsize) + /* "View.MemoryView":683 + * have_slices = True + * else: + * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<< + * raise TypeError("Cannot index with type '%s'" % type(item)) * */ - _copy_strided_to_strided(__pyx_v_src->data, __pyx_v_src->strides, __pyx_v_dst->data, __pyx_v_dst->strides, __pyx_v_src->shape, __pyx_v_dst->shape, __pyx_v_ndim, __pyx_v_itemsize); + /*else*/ { + __pyx_t_2 = PySlice_Check(__pyx_v_item); + __pyx_t_10 = ((!(__pyx_t_2 != 0)) != 0); + if (__pyx_t_10) { + } else { + __pyx_t_1 = __pyx_t_10; + goto __pyx_L9_bool_binop_done; + } + __pyx_t_10 = ((!(PyIndex_Check(__pyx_v_item) != 0)) != 0); + __pyx_t_1 = __pyx_t_10; + __pyx_L9_bool_binop_done:; + if (unlikely(__pyx_t_1)) { - /* "View.MemoryView":1165 - * dst_data += dst_stride + /* "View.MemoryView":684 + * else: + * if not isinstance(item, slice) and not PyIndex_Check(item): + * raise TypeError("Cannot index with type '%s'" % type(item)) # <<<<<<<<<<<<<< * - * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< - * __Pyx_memviewslice *dst, - * int ndim, size_t itemsize) nogil: + * have_slices = have_slices or isinstance(item, slice) */ + __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_Cannot_index_with_type_s, ((PyObject *)Py_TYPE(__pyx_v_item))); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 684, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 684, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_Raise(__pyx_t_11, 0, 0, 0); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __PYX_ERR(1, 684, __pyx_L1_error) - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.copy_strided_to_strided", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); -} - -/* "View.MemoryView":1172 + /* "View.MemoryView":683 + * have_slices = True + * else: + * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<< + * raise TypeError("Cannot index with type '%s'" % type(item)) * - * @cname('__pyx_memoryview_slice_get_size') - * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil: # <<<<<<<<<<<<<< - * "Return the size of the memory occupied by the slice in number of bytes" - * cdef int i */ + } -static Py_ssize_t __pyx_memoryview_slice_get_size(__Pyx_memviewslice *__pyx_v_src, int __pyx_v_ndim) { - int __pyx_v_i; - Py_ssize_t __pyx_v_size; - Py_ssize_t __pyx_r; - __Pyx_TraceDeclarations - Py_ssize_t __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_TraceCall("slice_get_size", __pyx_f[1], 1172, 1, __PYX_ERR(1, 1172, __pyx_L1_error)); - - /* "View.MemoryView":1175 - * "Return the size of the memory occupied by the slice in number of bytes" - * cdef int i - * cdef Py_ssize_t size = src.memview.view.itemsize # <<<<<<<<<<<<<< + /* "View.MemoryView":686 + * raise TypeError("Cannot index with type '%s'" % type(item)) + * + * have_slices = have_slices or isinstance(item, slice) # <<<<<<<<<<<<<< + * result.append(item) * - * for i in range(ndim): */ - __pyx_t_1 = __pyx_v_src->memview->view.itemsize; - __pyx_v_size = __pyx_t_1; + __pyx_t_10 = (__pyx_v_have_slices != 0); + if (!__pyx_t_10) { + } else { + __pyx_t_1 = __pyx_t_10; + goto __pyx_L11_bool_binop_done; + } + __pyx_t_10 = PySlice_Check(__pyx_v_item); + __pyx_t_2 = (__pyx_t_10 != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L11_bool_binop_done:; + __pyx_v_have_slices = __pyx_t_1; - /* "View.MemoryView":1177 - * cdef Py_ssize_t size = src.memview.view.itemsize + /* "View.MemoryView":687 * - * for i in range(ndim): # <<<<<<<<<<<<<< - * size *= src.shape[i] + * have_slices = have_slices or isinstance(item, slice) + * result.append(item) # <<<<<<<<<<<<<< * + * nslices = ndim - len(result) */ - __pyx_t_2 = __pyx_v_ndim; - __pyx_t_3 = __pyx_t_2; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_i = __pyx_t_4; + __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_v_item); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 687, __pyx_L1_error) + } + __pyx_L6:; - /* "View.MemoryView":1178 + /* "View.MemoryView":674 + * have_slices = False + * seen_ellipsis = False + * for idx, item in enumerate(tup): # <<<<<<<<<<<<<< + * if item is Ellipsis: + * if not seen_ellipsis: + */ + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "View.MemoryView":689 + * result.append(item) * - * for i in range(ndim): - * size *= src.shape[i] # <<<<<<<<<<<<<< + * nslices = ndim - len(result) # <<<<<<<<<<<<<< + * if nslices: + * result.extend([slice(None)] * nslices) + */ + __pyx_t_5 = PyList_GET_SIZE(__pyx_v_result); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(1, 689, __pyx_L1_error) + __pyx_v_nslices = (__pyx_v_ndim - __pyx_t_5); + + /* "View.MemoryView":690 + * + * nslices = ndim - len(result) + * if nslices: # <<<<<<<<<<<<<< + * result.extend([slice(None)] * nslices) + * + */ + __pyx_t_1 = (__pyx_v_nslices != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":691 + * nslices = ndim - len(result) + * if nslices: + * result.extend([slice(None)] * nslices) # <<<<<<<<<<<<<< + * + * return have_slices or nslices, tuple(result) + */ + __pyx_t_3 = PyList_New(1 * ((__pyx_v_nslices<0) ? 0:__pyx_v_nslices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + { Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < __pyx_v_nslices; __pyx_temp++) { + __Pyx_INCREF(__pyx_slice__71); + __Pyx_GIVEREF(__pyx_slice__71); + PyList_SET_ITEM(__pyx_t_3, __pyx_temp, __pyx_slice__71); + } + } + __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 691, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "View.MemoryView":690 + * + * nslices = ndim - len(result) + * if nslices: # <<<<<<<<<<<<<< + * result.extend([slice(None)] * nslices) * - * return size */ - __pyx_v_size = (__pyx_v_size * (__pyx_v_src->shape[__pyx_v_i])); } - /* "View.MemoryView":1180 - * size *= src.shape[i] + /* "View.MemoryView":693 + * result.extend([slice(None)] * nslices) * - * return size # <<<<<<<<<<<<<< + * return have_slices or nslices, tuple(result) # <<<<<<<<<<<<<< * - * @cname('__pyx_fill_contig_strides_array') + * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): */ - __pyx_r = __pyx_v_size; + __Pyx_XDECREF(__pyx_r); + if (!__pyx_v_have_slices) { + } else { + __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_have_slices); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 693, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L14_bool_binop_done; + } + __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_nslices); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 693, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_L14_bool_binop_done:; + __pyx_t_4 = PyList_AsTuple(__pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 693, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 693, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_4); + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_r = ((PyObject*)__pyx_t_11); + __pyx_t_11 = 0; goto __pyx_L0; - /* "View.MemoryView":1172 + /* "View.MemoryView":661 + * return isinstance(o, memoryview) * - * @cname('__pyx_memoryview_slice_get_size') - * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil: # <<<<<<<<<<<<<< - * "Return the size of the memory occupied by the slice in number of bytes" - * cdef int i + * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<< + * """ + * Replace all ellipses with full slices and fill incomplete indices with */ /* function exit code */ __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.slice_get_size", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("View.MemoryView._unellipsify", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); + __Pyx_XDECREF(__pyx_v_tup); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_idx); + __Pyx_XDECREF(__pyx_v_item); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":1183 +/* "View.MemoryView":695 + * return have_slices or nslices, tuple(result) * - * @cname('__pyx_fill_contig_strides_array') - * cdef Py_ssize_t fill_contig_strides_array( # <<<<<<<<<<<<<< - * Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride, - * int ndim, char order) nogil: + * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<< + * for suboffset in suboffsets[:ndim]: + * if suboffset >= 0: */ -static Py_ssize_t __pyx_fill_contig_strides_array(Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, Py_ssize_t __pyx_v_stride, int __pyx_v_ndim, char __pyx_v_order) { - int __pyx_v_idx; - Py_ssize_t __pyx_r; +static PyObject *assert_direct_dimensions(Py_ssize_t *__pyx_v_suboffsets, int __pyx_v_ndim) { + Py_ssize_t __pyx_v_suboffset; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; + __Pyx_RefNannyDeclarations + Py_ssize_t *__pyx_t_1; + Py_ssize_t *__pyx_t_2; + Py_ssize_t *__pyx_t_3; int __pyx_t_4; - __Pyx_TraceCall("fill_contig_strides_array", __pyx_f[1], 1183, 1, __PYX_ERR(1, 1183, __pyx_L1_error)); + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("assert_direct_dimensions", 0); + __Pyx_TraceCall("assert_direct_dimensions", __pyx_f[1], 695, 0, __PYX_ERR(1, 695, __pyx_L1_error)); - /* "View.MemoryView":1192 - * cdef int idx + /* "View.MemoryView":696 * - * if order == 'F': # <<<<<<<<<<<<<< - * for idx in range(ndim): - * strides[idx] = stride + * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): + * for suboffset in suboffsets[:ndim]: # <<<<<<<<<<<<<< + * if suboffset >= 0: + * raise ValueError("Indirect dimensions not supported") */ - __pyx_t_1 = ((__pyx_v_order == 'F') != 0); - if (__pyx_t_1) { + __pyx_t_2 = (__pyx_v_suboffsets + __pyx_v_ndim); + for (__pyx_t_3 = __pyx_v_suboffsets; __pyx_t_3 < __pyx_t_2; __pyx_t_3++) { + __pyx_t_1 = __pyx_t_3; + __pyx_v_suboffset = (__pyx_t_1[0]); - /* "View.MemoryView":1193 + /* "View.MemoryView":697 + * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): + * for suboffset in suboffsets[:ndim]: + * if suboffset >= 0: # <<<<<<<<<<<<<< + * raise ValueError("Indirect dimensions not supported") * - * if order == 'F': - * for idx in range(ndim): # <<<<<<<<<<<<<< - * strides[idx] = stride - * stride = stride * shape[idx] - */ - __pyx_t_2 = __pyx_v_ndim; - __pyx_t_3 = __pyx_t_2; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_idx = __pyx_t_4; - - /* "View.MemoryView":1194 - * if order == 'F': - * for idx in range(ndim): - * strides[idx] = stride # <<<<<<<<<<<<<< - * stride = stride * shape[idx] - * else: - */ - (__pyx_v_strides[__pyx_v_idx]) = __pyx_v_stride; - - /* "View.MemoryView":1195 - * for idx in range(ndim): - * strides[idx] = stride - * stride = stride * shape[idx] # <<<<<<<<<<<<<< - * else: - * for idx in range(ndim - 1, -1, -1): */ - __pyx_v_stride = (__pyx_v_stride * (__pyx_v_shape[__pyx_v_idx])); - } + __pyx_t_4 = ((__pyx_v_suboffset >= 0) != 0); + if (unlikely(__pyx_t_4)) { - /* "View.MemoryView":1192 - * cdef int idx + /* "View.MemoryView":698 + * for suboffset in suboffsets[:ndim]: + * if suboffset >= 0: + * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<< * - * if order == 'F': # <<<<<<<<<<<<<< - * for idx in range(ndim): - * strides[idx] = stride - */ - goto __pyx_L3; - } - - /* "View.MemoryView":1197 - * stride = stride * shape[idx] - * else: - * for idx in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< - * strides[idx] = stride - * stride = stride * shape[idx] - */ - /*else*/ { - for (__pyx_t_2 = (__pyx_v_ndim - 1); __pyx_t_2 > -1; __pyx_t_2-=1) { - __pyx_v_idx = __pyx_t_2; - - /* "View.MemoryView":1198 - * else: - * for idx in range(ndim - 1, -1, -1): - * strides[idx] = stride # <<<<<<<<<<<<<< - * stride = stride * shape[idx] * */ - (__pyx_v_strides[__pyx_v_idx]) = __pyx_v_stride; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__72, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 698, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(1, 698, __pyx_L1_error) - /* "View.MemoryView":1199 - * for idx in range(ndim - 1, -1, -1): - * strides[idx] = stride - * stride = stride * shape[idx] # <<<<<<<<<<<<<< + /* "View.MemoryView":697 + * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): + * for suboffset in suboffsets[:ndim]: + * if suboffset >= 0: # <<<<<<<<<<<<<< + * raise ValueError("Indirect dimensions not supported") * - * return stride */ - __pyx_v_stride = (__pyx_v_stride * (__pyx_v_shape[__pyx_v_idx])); } } - __pyx_L3:; - - /* "View.MemoryView":1201 - * stride = stride * shape[idx] - * - * return stride # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_copy_data_to_temp') - */ - __pyx_r = __pyx_v_stride; - goto __pyx_L0; - /* "View.MemoryView":1183 + /* "View.MemoryView":695 + * return have_slices or nslices, tuple(result) * - * @cname('__pyx_fill_contig_strides_array') - * cdef Py_ssize_t fill_contig_strides_array( # <<<<<<<<<<<<<< - * Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride, - * int ndim, char order) nogil: + * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<< + * for suboffset in suboffsets[:ndim]: + * if suboffset >= 0: */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.fill_contig_strides_array", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.assert_direct_dimensions", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":1204 +/* "View.MemoryView":705 * - * @cname('__pyx_memoryview_copy_data_to_temp') - * cdef void *copy_data_to_temp(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< - * __Pyx_memviewslice *tmpslice, - * char order, + * @cname('__pyx_memview_slice') + * cdef memoryview memview_slice(memoryview memview, object indices): # <<<<<<<<<<<<<< + * cdef int new_ndim = 0, suboffset_dim = -1, dim + * cdef bint negative_step */ -static void *__pyx_memoryview_copy_data_to_temp(__Pyx_memviewslice *__pyx_v_src, __Pyx_memviewslice *__pyx_v_tmpslice, char __pyx_v_order, int __pyx_v_ndim) { - int __pyx_v_i; - void *__pyx_v_result; - size_t __pyx_v_itemsize; - size_t __pyx_v_size; - void *__pyx_r; +static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *__pyx_v_memview, PyObject *__pyx_v_indices) { + int __pyx_v_new_ndim; + int __pyx_v_suboffset_dim; + int __pyx_v_dim; + __Pyx_memviewslice __pyx_v_src; + __Pyx_memviewslice __pyx_v_dst; + __Pyx_memviewslice *__pyx_v_p_src; + struct __pyx_memoryviewslice_obj *__pyx_v_memviewsliceobj = 0; + __Pyx_memviewslice *__pyx_v_p_dst; + int *__pyx_v_p_suboffset_dim; + Py_ssize_t __pyx_v_start; + Py_ssize_t __pyx_v_stop; + Py_ssize_t __pyx_v_step; + int __pyx_v_have_start; + int __pyx_v_have_stop; + int __pyx_v_have_step; + PyObject *__pyx_v_index = NULL; + struct __pyx_memoryview_obj *__pyx_r = NULL; __Pyx_TraceDeclarations - Py_ssize_t __pyx_t_1; + __Pyx_RefNannyDeclarations + int __pyx_t_1; int __pyx_t_2; - int __pyx_t_3; + PyObject *__pyx_t_3 = NULL; struct __pyx_memoryview_obj *__pyx_t_4; - int __pyx_t_5; + char *__pyx_t_5; int __pyx_t_6; - __Pyx_TraceCall("copy_data_to_temp", __pyx_f[1], 1204, 1, __PYX_ERR(1, 1204, __pyx_L1_error)); + Py_ssize_t __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + PyObject *__pyx_t_9 = NULL; + Py_ssize_t __pyx_t_10; + int __pyx_t_11; + Py_ssize_t __pyx_t_12; + __Pyx_RefNannySetupContext("memview_slice", 0); + __Pyx_TraceCall("memview_slice", __pyx_f[1], 705, 0, __PYX_ERR(1, 705, __pyx_L1_error)); - /* "View.MemoryView":1215 - * cdef void *result - * - * cdef size_t itemsize = src.memview.view.itemsize # <<<<<<<<<<<<<< - * cdef size_t size = slice_get_size(src, ndim) - * + /* "View.MemoryView":706 + * @cname('__pyx_memview_slice') + * cdef memoryview memview_slice(memoryview memview, object indices): + * cdef int new_ndim = 0, suboffset_dim = -1, dim # <<<<<<<<<<<<<< + * cdef bint negative_step + * cdef __Pyx_memviewslice src, dst */ - __pyx_t_1 = __pyx_v_src->memview->view.itemsize; - __pyx_v_itemsize = __pyx_t_1; + __pyx_v_new_ndim = 0; + __pyx_v_suboffset_dim = -1; - /* "View.MemoryView":1216 + /* "View.MemoryView":713 * - * cdef size_t itemsize = src.memview.view.itemsize - * cdef size_t size = slice_get_size(src, ndim) # <<<<<<<<<<<<<< * - * result = malloc(size) - */ - __pyx_v_size = __pyx_memoryview_slice_get_size(__pyx_v_src, __pyx_v_ndim); - - /* "View.MemoryView":1218 - * cdef size_t size = slice_get_size(src, ndim) + * memset(&dst, 0, sizeof(dst)) # <<<<<<<<<<<<<< * - * result = malloc(size) # <<<<<<<<<<<<<< - * if not result: - * _err(MemoryError, NULL) + * cdef _memoryviewslice memviewsliceobj */ - __pyx_v_result = malloc(__pyx_v_size); + (void)(memset((&__pyx_v_dst), 0, (sizeof(__pyx_v_dst)))); - /* "View.MemoryView":1219 + /* "View.MemoryView":717 + * cdef _memoryviewslice memviewsliceobj * - * result = malloc(size) - * if not result: # <<<<<<<<<<<<<< - * _err(MemoryError, NULL) + * assert memview.view.ndim > 0 # <<<<<<<<<<<<<< * + * if isinstance(memview, _memoryviewslice): */ - __pyx_t_2 = ((!(__pyx_v_result != 0)) != 0); - if (__pyx_t_2) { + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_memview->view.ndim > 0) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(1, 717, __pyx_L1_error) + } + } + #endif - /* "View.MemoryView":1220 - * result = malloc(size) - * if not result: - * _err(MemoryError, NULL) # <<<<<<<<<<<<<< - * + /* "View.MemoryView":719 + * assert memview.view.ndim > 0 * + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * memviewsliceobj = memview + * p_src = &memviewsliceobj.from_slice */ - __pyx_t_3 = __pyx_memoryview_err(__pyx_builtin_MemoryError, NULL); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 1220, __pyx_L1_error) + __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1219 - * - * result = malloc(size) - * if not result: # <<<<<<<<<<<<<< - * _err(MemoryError, NULL) + /* "View.MemoryView":720 * + * if isinstance(memview, _memoryviewslice): + * memviewsliceobj = memview # <<<<<<<<<<<<<< + * p_src = &memviewsliceobj.from_slice + * else: */ - } + if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(1, 720, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_v_memview); + __Pyx_INCREF(__pyx_t_3); + __pyx_v_memviewsliceobj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3); + __pyx_t_3 = 0; - /* "View.MemoryView":1223 - * - * - * tmpslice.data = result # <<<<<<<<<<<<<< - * tmpslice.memview = src.memview - * for i in range(ndim): + /* "View.MemoryView":721 + * if isinstance(memview, _memoryviewslice): + * memviewsliceobj = memview + * p_src = &memviewsliceobj.from_slice # <<<<<<<<<<<<<< + * else: + * slice_copy(memview, &src) */ - __pyx_v_tmpslice->data = ((char *)__pyx_v_result); + __pyx_v_p_src = (&__pyx_v_memviewsliceobj->from_slice); - /* "View.MemoryView":1224 + /* "View.MemoryView":719 + * assert memview.view.ndim > 0 * - * tmpslice.data = result - * tmpslice.memview = src.memview # <<<<<<<<<<<<<< - * for i in range(ndim): - * tmpslice.shape[i] = src.shape[i] - */ - __pyx_t_4 = __pyx_v_src->memview; - __pyx_v_tmpslice->memview = __pyx_t_4; - - /* "View.MemoryView":1225 - * tmpslice.data = result - * tmpslice.memview = src.memview - * for i in range(ndim): # <<<<<<<<<<<<<< - * tmpslice.shape[i] = src.shape[i] - * tmpslice.suboffsets[i] = -1 + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * memviewsliceobj = memview + * p_src = &memviewsliceobj.from_slice */ - __pyx_t_3 = __pyx_v_ndim; - __pyx_t_5 = __pyx_t_3; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_i = __pyx_t_6; + goto __pyx_L3; + } - /* "View.MemoryView":1226 - * tmpslice.memview = src.memview - * for i in range(ndim): - * tmpslice.shape[i] = src.shape[i] # <<<<<<<<<<<<<< - * tmpslice.suboffsets[i] = -1 + /* "View.MemoryView":723 + * p_src = &memviewsliceobj.from_slice + * else: + * slice_copy(memview, &src) # <<<<<<<<<<<<<< + * p_src = &src * */ - (__pyx_v_tmpslice->shape[__pyx_v_i]) = (__pyx_v_src->shape[__pyx_v_i]); + /*else*/ { + __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_src)); - /* "View.MemoryView":1227 - * for i in range(ndim): - * tmpslice.shape[i] = src.shape[i] - * tmpslice.suboffsets[i] = -1 # <<<<<<<<<<<<<< + /* "View.MemoryView":724 + * else: + * slice_copy(memview, &src) + * p_src = &src # <<<<<<<<<<<<<< + * * - * fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize, */ - (__pyx_v_tmpslice->suboffsets[__pyx_v_i]) = -1L; + __pyx_v_p_src = (&__pyx_v_src); } + __pyx_L3:; - /* "View.MemoryView":1229 - * tmpslice.suboffsets[i] = -1 + /* "View.MemoryView":730 * - * fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize, # <<<<<<<<<<<<<< - * ndim, order) + * + * dst.memview = p_src.memview # <<<<<<<<<<<<<< + * dst.data = p_src.data * */ - (void)(__pyx_fill_contig_strides_array((&(__pyx_v_tmpslice->shape[0])), (&(__pyx_v_tmpslice->strides[0])), __pyx_v_itemsize, __pyx_v_ndim, __pyx_v_order)); + __pyx_t_4 = __pyx_v_p_src->memview; + __pyx_v_dst.memview = __pyx_t_4; - /* "View.MemoryView":1233 + /* "View.MemoryView":731 + * + * dst.memview = p_src.memview + * dst.data = p_src.data # <<<<<<<<<<<<<< * * - * for i in range(ndim): # <<<<<<<<<<<<<< - * if tmpslice.shape[i] == 1: - * tmpslice.strides[i] = 0 */ - __pyx_t_3 = __pyx_v_ndim; - __pyx_t_5 = __pyx_t_3; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_i = __pyx_t_6; + __pyx_t_5 = __pyx_v_p_src->data; + __pyx_v_dst.data = __pyx_t_5; - /* "View.MemoryView":1234 + /* "View.MemoryView":736 * - * for i in range(ndim): - * if tmpslice.shape[i] == 1: # <<<<<<<<<<<<<< - * tmpslice.strides[i] = 0 * + * cdef __Pyx_memviewslice *p_dst = &dst # <<<<<<<<<<<<<< + * cdef int *p_suboffset_dim = &suboffset_dim + * cdef Py_ssize_t start, stop, step */ - __pyx_t_2 = (((__pyx_v_tmpslice->shape[__pyx_v_i]) == 1) != 0); - if (__pyx_t_2) { + __pyx_v_p_dst = (&__pyx_v_dst); - /* "View.MemoryView":1235 - * for i in range(ndim): - * if tmpslice.shape[i] == 1: - * tmpslice.strides[i] = 0 # <<<<<<<<<<<<<< + /* "View.MemoryView":737 * - * if slice_is_contig(src[0], order, ndim): + * cdef __Pyx_memviewslice *p_dst = &dst + * cdef int *p_suboffset_dim = &suboffset_dim # <<<<<<<<<<<<<< + * cdef Py_ssize_t start, stop, step + * cdef bint have_start, have_stop, have_step */ - (__pyx_v_tmpslice->strides[__pyx_v_i]) = 0; + __pyx_v_p_suboffset_dim = (&__pyx_v_suboffset_dim); - /* "View.MemoryView":1234 + /* "View.MemoryView":741 + * cdef bint have_start, have_stop, have_step * - * for i in range(ndim): - * if tmpslice.shape[i] == 1: # <<<<<<<<<<<<<< - * tmpslice.strides[i] = 0 + * for dim, index in enumerate(indices): # <<<<<<<<<<<<<< + * if PyIndex_Check(index): + * slice_memviewslice( + */ + __pyx_t_6 = 0; + if (likely(PyList_CheckExact(__pyx_v_indices)) || PyTuple_CheckExact(__pyx_v_indices)) { + __pyx_t_3 = __pyx_v_indices; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + } else { + __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_indices); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 741, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 741, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_8)) { + if (likely(PyList_CheckExact(__pyx_t_3))) { + if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(1, 741, __pyx_L1_error) + #else + __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 741, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + } else { + if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(1, 741, __pyx_L1_error) + #else + __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 741, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + } + } else { + __pyx_t_9 = __pyx_t_8(__pyx_t_3); + if (unlikely(!__pyx_t_9)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(1, 741, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_9); + } + __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_v_dim = __pyx_t_6; + __pyx_t_6 = (__pyx_t_6 + 1); + + /* "View.MemoryView":742 + * + * for dim, index in enumerate(indices): + * if PyIndex_Check(index): # <<<<<<<<<<<<<< + * slice_memviewslice( + * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], + */ + __pyx_t_2 = (PyIndex_Check(__pyx_v_index) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":746 + * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], + * dim, new_ndim, p_suboffset_dim, + * index, 0, 0, # start, stop, step # <<<<<<<<<<<<<< + * 0, 0, 0, # have_{start,stop,step} + * False) + */ + __pyx_t_10 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_10 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 746, __pyx_L1_error) + + /* "View.MemoryView":743 + * for dim, index in enumerate(indices): + * if PyIndex_Check(index): + * slice_memviewslice( # <<<<<<<<<<<<<< + * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], + * dim, new_ndim, p_suboffset_dim, + */ + __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_t_10, 0, 0, 0, 0, 0, 0); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(1, 743, __pyx_L1_error) + + /* "View.MemoryView":742 + * + * for dim, index in enumerate(indices): + * if PyIndex_Check(index): # <<<<<<<<<<<<<< + * slice_memviewslice( + * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], + */ + goto __pyx_L6; + } + + /* "View.MemoryView":749 + * 0, 0, 0, # have_{start,stop,step} + * False) + * elif index is None: # <<<<<<<<<<<<<< + * p_dst.shape[new_ndim] = 1 + * p_dst.strides[new_ndim] = 0 + */ + __pyx_t_2 = (__pyx_v_index == Py_None); + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":750 + * False) + * elif index is None: + * p_dst.shape[new_ndim] = 1 # <<<<<<<<<<<<<< + * p_dst.strides[new_ndim] = 0 + * p_dst.suboffsets[new_ndim] = -1 + */ + (__pyx_v_p_dst->shape[__pyx_v_new_ndim]) = 1; + + /* "View.MemoryView":751 + * elif index is None: + * p_dst.shape[new_ndim] = 1 + * p_dst.strides[new_ndim] = 0 # <<<<<<<<<<<<<< + * p_dst.suboffsets[new_ndim] = -1 + * new_ndim += 1 + */ + (__pyx_v_p_dst->strides[__pyx_v_new_ndim]) = 0; + + /* "View.MemoryView":752 + * p_dst.shape[new_ndim] = 1 + * p_dst.strides[new_ndim] = 0 + * p_dst.suboffsets[new_ndim] = -1 # <<<<<<<<<<<<<< + * new_ndim += 1 + * else: + */ + (__pyx_v_p_dst->suboffsets[__pyx_v_new_ndim]) = -1L; + + /* "View.MemoryView":753 + * p_dst.strides[new_ndim] = 0 + * p_dst.suboffsets[new_ndim] = -1 + * new_ndim += 1 # <<<<<<<<<<<<<< + * else: + * start = index.start or 0 + */ + __pyx_v_new_ndim = (__pyx_v_new_ndim + 1); + + /* "View.MemoryView":749 + * 0, 0, 0, # have_{start,stop,step} + * False) + * elif index is None: # <<<<<<<<<<<<<< + * p_dst.shape[new_ndim] = 1 + * p_dst.strides[new_ndim] = 0 + */ + goto __pyx_L6; + } + + /* "View.MemoryView":755 + * new_ndim += 1 + * else: + * start = index.start or 0 # <<<<<<<<<<<<<< + * stop = index.stop or 0 + * step = index.step or 0 + */ + /*else*/ { + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 755, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 755, __pyx_L1_error) + if (!__pyx_t_1) { + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else { + __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 755, __pyx_L1_error) + __pyx_t_10 = __pyx_t_12; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_10 = 0; + __pyx_L7_bool_binop_done:; + __pyx_v_start = __pyx_t_10; + + /* "View.MemoryView":756 + * else: + * start = index.start or 0 + * stop = index.stop or 0 # <<<<<<<<<<<<<< + * step = index.step or 0 + * + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 756, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 756, __pyx_L1_error) + if (!__pyx_t_1) { + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else { + __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 756, __pyx_L1_error) + __pyx_t_10 = __pyx_t_12; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L9_bool_binop_done; + } + __pyx_t_10 = 0; + __pyx_L9_bool_binop_done:; + __pyx_v_stop = __pyx_t_10; + + /* "View.MemoryView":757 + * start = index.start or 0 + * stop = index.stop or 0 + * step = index.step or 0 # <<<<<<<<<<<<<< + * + * have_start = index.start is not None + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 757, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 757, __pyx_L1_error) + if (!__pyx_t_1) { + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else { + __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 757, __pyx_L1_error) + __pyx_t_10 = __pyx_t_12; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L11_bool_binop_done; + } + __pyx_t_10 = 0; + __pyx_L11_bool_binop_done:; + __pyx_v_step = __pyx_t_10; + + /* "View.MemoryView":759 + * step = index.step or 0 + * + * have_start = index.start is not None # <<<<<<<<<<<<<< + * have_stop = index.stop is not None + * have_step = index.step is not None + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 759, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = (__pyx_t_9 != Py_None); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_have_start = __pyx_t_1; + + /* "View.MemoryView":760 + * + * have_start = index.start is not None + * have_stop = index.stop is not None # <<<<<<<<<<<<<< + * have_step = index.step is not None + * + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 760, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = (__pyx_t_9 != Py_None); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_have_stop = __pyx_t_1; + + /* "View.MemoryView":761 + * have_start = index.start is not None + * have_stop = index.stop is not None + * have_step = index.step is not None # <<<<<<<<<<<<<< + * + * slice_memviewslice( + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 761, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = (__pyx_t_9 != Py_None); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_have_step = __pyx_t_1; + + /* "View.MemoryView":763 + * have_step = index.step is not None + * + * slice_memviewslice( # <<<<<<<<<<<<<< + * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim], + * dim, new_ndim, p_suboffset_dim, + */ + __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_v_start, __pyx_v_stop, __pyx_v_step, __pyx_v_have_start, __pyx_v_have_stop, __pyx_v_have_step, 1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(1, 763, __pyx_L1_error) + + /* "View.MemoryView":769 + * have_start, have_stop, have_step, + * True) + * new_ndim += 1 # <<<<<<<<<<<<<< * + * if isinstance(memview, _memoryviewslice): */ + __pyx_v_new_ndim = (__pyx_v_new_ndim + 1); } + __pyx_L6:; + + /* "View.MemoryView":741 + * cdef bint have_start, have_stop, have_step + * + * for dim, index in enumerate(indices): # <<<<<<<<<<<<<< + * if PyIndex_Check(index): + * slice_memviewslice( + */ } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "View.MemoryView":1237 - * tmpslice.strides[i] = 0 + /* "View.MemoryView":771 + * new_ndim += 1 * - * if slice_is_contig(src[0], order, ndim): # <<<<<<<<<<<<<< - * memcpy(result, src.data, size) - * else: + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * return memoryview_fromslice(dst, new_ndim, + * memviewsliceobj.to_object_func, */ - __pyx_t_2 = (__pyx_memviewslice_is_contig((__pyx_v_src[0]), __pyx_v_order, __pyx_v_ndim) != 0); + __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); + __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "View.MemoryView":1238 + /* "View.MemoryView":772 * - * if slice_is_contig(src[0], order, ndim): - * memcpy(result, src.data, size) # <<<<<<<<<<<<<< + * if isinstance(memview, _memoryviewslice): + * return memoryview_fromslice(dst, new_ndim, # <<<<<<<<<<<<<< + * memviewsliceobj.to_object_func, + * memviewsliceobj.to_dtype_func, + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + + /* "View.MemoryView":773 + * if isinstance(memview, _memoryviewslice): + * return memoryview_fromslice(dst, new_ndim, + * memviewsliceobj.to_object_func, # <<<<<<<<<<<<<< + * memviewsliceobj.to_dtype_func, + * memview.dtype_is_object) + */ + if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(1, 773, __pyx_L1_error) } + + /* "View.MemoryView":774 + * return memoryview_fromslice(dst, new_ndim, + * memviewsliceobj.to_object_func, + * memviewsliceobj.to_dtype_func, # <<<<<<<<<<<<<< + * memview.dtype_is_object) * else: - * copy_strided_to_strided(src, tmpslice, ndim, itemsize) */ - (void)(memcpy(__pyx_v_result, __pyx_v_src->data, __pyx_v_size)); + if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(1, 774, __pyx_L1_error) } - /* "View.MemoryView":1237 - * tmpslice.strides[i] = 0 + /* "View.MemoryView":772 * - * if slice_is_contig(src[0], order, ndim): # <<<<<<<<<<<<<< - * memcpy(result, src.data, size) - * else: + * if isinstance(memview, _memoryviewslice): + * return memoryview_fromslice(dst, new_ndim, # <<<<<<<<<<<<<< + * memviewsliceobj.to_object_func, + * memviewsliceobj.to_dtype_func, + */ + __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, __pyx_v_memviewsliceobj->to_object_func, __pyx_v_memviewsliceobj->to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 772, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(1, 772, __pyx_L1_error) + __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3); + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "View.MemoryView":771 + * new_ndim += 1 + * + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * return memoryview_fromslice(dst, new_ndim, + * memviewsliceobj.to_object_func, */ - goto __pyx_L9; } - /* "View.MemoryView":1240 - * memcpy(result, src.data, size) + /* "View.MemoryView":777 + * memview.dtype_is_object) * else: - * copy_strided_to_strided(src, tmpslice, ndim, itemsize) # <<<<<<<<<<<<<< + * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<< + * memview.dtype_is_object) * - * return result */ /*else*/ { - copy_strided_to_strided(__pyx_v_src, __pyx_v_tmpslice, __pyx_v_ndim, __pyx_v_itemsize); - } - __pyx_L9:; + __Pyx_XDECREF(((PyObject *)__pyx_r)); - /* "View.MemoryView":1242 - * copy_strided_to_strided(src, tmpslice, ndim, itemsize) + /* "View.MemoryView":778 + * else: + * return memoryview_fromslice(dst, new_ndim, NULL, NULL, + * memview.dtype_is_object) # <<<<<<<<<<<<<< * - * return result # <<<<<<<<<<<<<< * + */ + __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, NULL, NULL, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 777, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + + /* "View.MemoryView":777 + * memview.dtype_is_object) + * else: + * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<< + * memview.dtype_is_object) * */ - __pyx_r = __pyx_v_result; - goto __pyx_L0; + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(1, 777, __pyx_L1_error) + __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3); + __pyx_t_3 = 0; + goto __pyx_L0; + } - /* "View.MemoryView":1204 + /* "View.MemoryView":705 * - * @cname('__pyx_memoryview_copy_data_to_temp') - * cdef void *copy_data_to_temp(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< - * __Pyx_memviewslice *tmpslice, - * char order, + * @cname('__pyx_memview_slice') + * cdef memoryview memview_slice(memoryview memview, object indices): # <<<<<<<<<<<<<< + * cdef int new_ndim = 0, suboffset_dim = -1, dim + * cdef bint negative_step */ /* function exit code */ __pyx_L1_error:; - { - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_AddTraceback("View.MemoryView.copy_data_to_temp", __pyx_clineno, __pyx_lineno, __pyx_filename); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - } - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("View.MemoryView.memview_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); + __Pyx_XDECREF((PyObject *)__pyx_v_memviewsliceobj); + __Pyx_XDECREF(__pyx_v_index); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "View.MemoryView":1247 +/* "View.MemoryView":802 * - * @cname('__pyx_memoryview_err_extents') - * cdef int _err_extents(int i, Py_ssize_t extent1, # <<<<<<<<<<<<<< - * Py_ssize_t extent2) except -1 with gil: - * raise ValueError("got differing extents in dimension %d (got %d and %d)" % + * @cname('__pyx_memoryview_slice_memviewslice') + * cdef int slice_memviewslice( # <<<<<<<<<<<<<< + * __Pyx_memviewslice *dst, + * Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset, */ -static int __pyx_memoryview_err_extents(int __pyx_v_i, Py_ssize_t __pyx_v_extent1, Py_ssize_t __pyx_v_extent2) { +static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *__pyx_v_dst, Py_ssize_t __pyx_v_shape, Py_ssize_t __pyx_v_stride, Py_ssize_t __pyx_v_suboffset, int __pyx_v_dim, int __pyx_v_new_ndim, int *__pyx_v_suboffset_dim, Py_ssize_t __pyx_v_start, Py_ssize_t __pyx_v_stop, Py_ssize_t __pyx_v_step, int __pyx_v_have_start, int __pyx_v_have_stop, int __pyx_v_have_step, int __pyx_v_is_slice) { + Py_ssize_t __pyx_v_new_shape; + int __pyx_v_negative_step; int __pyx_r; __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_RefNannySetupContext("_err_extents", 0); - __Pyx_TraceCall("_err_extents", __pyx_f[1], 1247, 0, __PYX_ERR(1, 1247, __pyx_L1_error)); + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_TraceCall("slice_memviewslice", __pyx_f[1], 802, 1, __PYX_ERR(1, 802, __pyx_L1_error)); - /* "View.MemoryView":1250 - * Py_ssize_t extent2) except -1 with gil: - * raise ValueError("got differing extents in dimension %d (got %d and %d)" % - * (i, extent1, extent2)) # <<<<<<<<<<<<<< + /* "View.MemoryView":822 + * cdef bint negative_step * - * @cname('__pyx_memoryview_err_dim') + * if not is_slice: # <<<<<<<<<<<<<< + * + * if start < 0: */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_extent1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_extent2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 1250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_3 = 0; + __pyx_t_1 = ((!(__pyx_v_is_slice != 0)) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":1249 - * cdef int _err_extents(int i, Py_ssize_t extent1, - * Py_ssize_t extent2) except -1 with gil: - * raise ValueError("got differing extents in dimension %d (got %d and %d)" % # <<<<<<<<<<<<<< - * (i, extent1, extent2)) + /* "View.MemoryView":824 + * if not is_slice: * + * if start < 0: # <<<<<<<<<<<<<< + * start += shape + * if not 0 <= start < shape: */ - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_got_differing_extents_in_dimensi, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1249, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 1249, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(1, 1249, __pyx_L1_error) + __pyx_t_1 = ((__pyx_v_start < 0) != 0); + if (__pyx_t_1) { - /* "View.MemoryView":1247 + /* "View.MemoryView":825 * - * @cname('__pyx_memoryview_err_extents') - * cdef int _err_extents(int i, Py_ssize_t extent1, # <<<<<<<<<<<<<< - * Py_ssize_t extent2) except -1 with gil: - * raise ValueError("got differing extents in dimension %d (got %d and %d)" % + * if start < 0: + * start += shape # <<<<<<<<<<<<<< + * if not 0 <= start < shape: + * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) */ + __pyx_v_start = (__pyx_v_start + __pyx_v_shape); - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("View.MemoryView._err_extents", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - return __pyx_r; -} - -/* "View.MemoryView":1253 - * - * @cname('__pyx_memoryview_err_dim') - * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil: # <<<<<<<<<<<<<< - * raise error(msg.decode('ascii') % dim) + /* "View.MemoryView":824 + * if not is_slice: * + * if start < 0: # <<<<<<<<<<<<<< + * start += shape + * if not 0 <= start < shape: */ + } -static int __pyx_memoryview_err_dim(PyObject *__pyx_v_error, char *__pyx_v_msg, int __pyx_v_dim) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_RefNannySetupContext("_err_dim", 0); - __Pyx_TraceCall("_err_dim", __pyx_f[1], 1253, 0, __PYX_ERR(1, 1253, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_error); - - /* "View.MemoryView":1254 - * @cname('__pyx_memoryview_err_dim') - * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil: - * raise error(msg.decode('ascii') % dim) # <<<<<<<<<<<<<< - * - * @cname('__pyx_memoryview_err') + /* "View.MemoryView":826 + * if start < 0: + * start += shape + * if not 0 <= start < shape: # <<<<<<<<<<<<<< + * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) + * else: */ - __pyx_t_2 = __Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyUnicode_Format(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 1254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_INCREF(__pyx_v_error); - __pyx_t_3 = __pyx_v_error; __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (!__pyx_t_2) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1254, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1254, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1254, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 1254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL; - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_1 = (0 <= __pyx_v_start); + if (__pyx_t_1) { + __pyx_t_1 = (__pyx_v_start < __pyx_v_shape); } - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 1254, __pyx_L1_error) + __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1253 - * - * @cname('__pyx_memoryview_err_dim') - * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil: # <<<<<<<<<<<<<< - * raise error(msg.decode('ascii') % dim) + /* "View.MemoryView":827 + * start += shape + * if not 0 <= start < shape: + * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) # <<<<<<<<<<<<<< + * else: * */ + __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"Index out of bounds (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 827, __pyx_L1_error) - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("View.MemoryView._err_dim", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __Pyx_XDECREF(__pyx_v_error); - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - return __pyx_r; -} + /* "View.MemoryView":826 + * if start < 0: + * start += shape + * if not 0 <= start < shape: # <<<<<<<<<<<<<< + * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) + * else: + */ + } -/* "View.MemoryView":1257 + /* "View.MemoryView":822 + * cdef bint negative_step * - * @cname('__pyx_memoryview_err') - * cdef int _err(object error, char *msg) except -1 with gil: # <<<<<<<<<<<<<< - * if msg != NULL: - * raise error(msg.decode('ascii')) + * if not is_slice: # <<<<<<<<<<<<<< + * + * if start < 0: */ + goto __pyx_L3; + } -static int __pyx_memoryview_err(PyObject *__pyx_v_error, char *__pyx_v_msg) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_RefNannySetupContext("_err", 0); - __Pyx_TraceCall("_err", __pyx_f[1], 1257, 0, __PYX_ERR(1, 1257, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_error); - - /* "View.MemoryView":1258 - * @cname('__pyx_memoryview_err') - * cdef int _err(object error, char *msg) except -1 with gil: - * if msg != NULL: # <<<<<<<<<<<<<< - * raise error(msg.decode('ascii')) + /* "View.MemoryView":830 * else: + * + * negative_step = have_step != 0 and step < 0 # <<<<<<<<<<<<<< + * + * if have_step and step == 0: */ - __pyx_t_1 = ((__pyx_v_msg != NULL) != 0); - if (unlikely(__pyx_t_1)) { + /*else*/ { + __pyx_t_1 = ((__pyx_v_have_step != 0) != 0); + if (__pyx_t_1) { + } else { + __pyx_t_2 = __pyx_t_1; + goto __pyx_L6_bool_binop_done; + } + __pyx_t_1 = ((__pyx_v_step < 0) != 0); + __pyx_t_2 = __pyx_t_1; + __pyx_L6_bool_binop_done:; + __pyx_v_negative_step = __pyx_t_2; - /* "View.MemoryView":1259 - * cdef int _err(object error, char *msg) except -1 with gil: - * if msg != NULL: - * raise error(msg.decode('ascii')) # <<<<<<<<<<<<<< - * else: - * raise error + /* "View.MemoryView":832 + * negative_step = have_step != 0 and step < 0 + * + * if have_step and step == 0: # <<<<<<<<<<<<<< + * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) + * */ - __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1259, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_error); - __pyx_t_4 = __pyx_v_error; __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (!__pyx_t_5) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1259, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = (__pyx_v_have_step != 0); + if (__pyx_t_1) { } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1259, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1259, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 1259, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1259, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } + __pyx_t_2 = __pyx_t_1; + goto __pyx_L9_bool_binop_done; } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(1, 1259, __pyx_L1_error) + __pyx_t_1 = ((__pyx_v_step == 0) != 0); + __pyx_t_2 = __pyx_t_1; + __pyx_L9_bool_binop_done:; + if (__pyx_t_2) { - /* "View.MemoryView":1258 - * @cname('__pyx_memoryview_err') - * cdef int _err(object error, char *msg) except -1 with gil: - * if msg != NULL: # <<<<<<<<<<<<<< - * raise error(msg.decode('ascii')) - * else: + /* "View.MemoryView":833 + * + * if have_step and step == 0: + * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) # <<<<<<<<<<<<<< + * + * */ - } + __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Step may not be zero (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 833, __pyx_L1_error) - /* "View.MemoryView":1261 - * raise error(msg.decode('ascii')) - * else: - * raise error # <<<<<<<<<<<<<< + /* "View.MemoryView":832 + * negative_step = have_step != 0 and step < 0 + * + * if have_step and step == 0: # <<<<<<<<<<<<<< + * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) * - * @cname('__pyx_memoryview_copy_contents') */ - /*else*/ { - __Pyx_Raise(__pyx_v_error, 0, 0, 0); - __PYX_ERR(1, 1261, __pyx_L1_error) - } + } - /* "View.MemoryView":1257 + /* "View.MemoryView":836 * - * @cname('__pyx_memoryview_err') - * cdef int _err(object error, char *msg) except -1 with gil: # <<<<<<<<<<<<<< - * if msg != NULL: - * raise error(msg.decode('ascii')) + * + * if have_start: # <<<<<<<<<<<<<< + * if start < 0: + * start += shape */ + __pyx_t_2 = (__pyx_v_have_start != 0); + if (__pyx_t_2) { - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("View.MemoryView._err", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __Pyx_XDECREF(__pyx_v_error); - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif - return __pyx_r; -} - -/* "View.MemoryView":1264 + /* "View.MemoryView":837 * - * @cname('__pyx_memoryview_copy_contents') - * cdef int memoryview_copy_contents(__Pyx_memviewslice src, # <<<<<<<<<<<<<< - * __Pyx_memviewslice dst, - * int src_ndim, int dst_ndim, + * if have_start: + * if start < 0: # <<<<<<<<<<<<<< + * start += shape + * if start < 0: */ + __pyx_t_2 = ((__pyx_v_start < 0) != 0); + if (__pyx_t_2) { -static int __pyx_memoryview_copy_contents(__Pyx_memviewslice __pyx_v_src, __Pyx_memviewslice __pyx_v_dst, int __pyx_v_src_ndim, int __pyx_v_dst_ndim, int __pyx_v_dtype_is_object) { - void *__pyx_v_tmpdata; - size_t __pyx_v_itemsize; - int __pyx_v_i; - char __pyx_v_order; - int __pyx_v_broadcasting; - int __pyx_v_direct_copy; - __Pyx_memviewslice __pyx_v_tmp; - int __pyx_v_ndim; - int __pyx_r; - __Pyx_TraceDeclarations - Py_ssize_t __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - void *__pyx_t_7; - int __pyx_t_8; - __Pyx_TraceCall("memoryview_copy_contents", __pyx_f[1], 1264, 1, __PYX_ERR(1, 1264, __pyx_L1_error)); - - /* "View.MemoryView":1272 - * Check for overlapping memory and verify the shapes. - * """ - * cdef void *tmpdata = NULL # <<<<<<<<<<<<<< - * cdef size_t itemsize = src.memview.view.itemsize - * cdef int i + /* "View.MemoryView":838 + * if have_start: + * if start < 0: + * start += shape # <<<<<<<<<<<<<< + * if start < 0: + * start = 0 */ - __pyx_v_tmpdata = NULL; + __pyx_v_start = (__pyx_v_start + __pyx_v_shape); - /* "View.MemoryView":1273 - * """ - * cdef void *tmpdata = NULL - * cdef size_t itemsize = src.memview.view.itemsize # <<<<<<<<<<<<<< - * cdef int i - * cdef char order = get_best_order(&src, src_ndim) + /* "View.MemoryView":839 + * if start < 0: + * start += shape + * if start < 0: # <<<<<<<<<<<<<< + * start = 0 + * elif start >= shape: */ - __pyx_t_1 = __pyx_v_src.memview->view.itemsize; - __pyx_v_itemsize = __pyx_t_1; + __pyx_t_2 = ((__pyx_v_start < 0) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1275 - * cdef size_t itemsize = src.memview.view.itemsize - * cdef int i - * cdef char order = get_best_order(&src, src_ndim) # <<<<<<<<<<<<<< - * cdef bint broadcasting = False - * cdef bint direct_copy = False + /* "View.MemoryView":840 + * start += shape + * if start < 0: + * start = 0 # <<<<<<<<<<<<<< + * elif start >= shape: + * if negative_step: */ - __pyx_v_order = __pyx_get_best_slice_order((&__pyx_v_src), __pyx_v_src_ndim); + __pyx_v_start = 0; - /* "View.MemoryView":1276 - * cdef int i - * cdef char order = get_best_order(&src, src_ndim) - * cdef bint broadcasting = False # <<<<<<<<<<<<<< - * cdef bint direct_copy = False - * cdef __Pyx_memviewslice tmp + /* "View.MemoryView":839 + * if start < 0: + * start += shape + * if start < 0: # <<<<<<<<<<<<<< + * start = 0 + * elif start >= shape: */ - __pyx_v_broadcasting = 0; + } - /* "View.MemoryView":1277 - * cdef char order = get_best_order(&src, src_ndim) - * cdef bint broadcasting = False - * cdef bint direct_copy = False # <<<<<<<<<<<<<< - * cdef __Pyx_memviewslice tmp + /* "View.MemoryView":837 * + * if have_start: + * if start < 0: # <<<<<<<<<<<<<< + * start += shape + * if start < 0: */ - __pyx_v_direct_copy = 0; + goto __pyx_L12; + } - /* "View.MemoryView":1280 - * cdef __Pyx_memviewslice tmp - * - * if src_ndim < dst_ndim: # <<<<<<<<<<<<<< - * broadcast_leading(&src, src_ndim, dst_ndim) - * elif dst_ndim < src_ndim: + /* "View.MemoryView":841 + * if start < 0: + * start = 0 + * elif start >= shape: # <<<<<<<<<<<<<< + * if negative_step: + * start = shape - 1 */ - __pyx_t_2 = ((__pyx_v_src_ndim < __pyx_v_dst_ndim) != 0); - if (__pyx_t_2) { + __pyx_t_2 = ((__pyx_v_start >= __pyx_v_shape) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1281 - * - * if src_ndim < dst_ndim: - * broadcast_leading(&src, src_ndim, dst_ndim) # <<<<<<<<<<<<<< - * elif dst_ndim < src_ndim: - * broadcast_leading(&dst, dst_ndim, src_ndim) + /* "View.MemoryView":842 + * start = 0 + * elif start >= shape: + * if negative_step: # <<<<<<<<<<<<<< + * start = shape - 1 + * else: */ - __pyx_memoryview_broadcast_leading((&__pyx_v_src), __pyx_v_src_ndim, __pyx_v_dst_ndim); + __pyx_t_2 = (__pyx_v_negative_step != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1280 - * cdef __Pyx_memviewslice tmp - * - * if src_ndim < dst_ndim: # <<<<<<<<<<<<<< - * broadcast_leading(&src, src_ndim, dst_ndim) - * elif dst_ndim < src_ndim: + /* "View.MemoryView":843 + * elif start >= shape: + * if negative_step: + * start = shape - 1 # <<<<<<<<<<<<<< + * else: + * start = shape */ - goto __pyx_L3; - } + __pyx_v_start = (__pyx_v_shape - 1); - /* "View.MemoryView":1282 - * if src_ndim < dst_ndim: - * broadcast_leading(&src, src_ndim, dst_ndim) - * elif dst_ndim < src_ndim: # <<<<<<<<<<<<<< - * broadcast_leading(&dst, dst_ndim, src_ndim) - * + /* "View.MemoryView":842 + * start = 0 + * elif start >= shape: + * if negative_step: # <<<<<<<<<<<<<< + * start = shape - 1 + * else: */ - __pyx_t_2 = ((__pyx_v_dst_ndim < __pyx_v_src_ndim) != 0); - if (__pyx_t_2) { + goto __pyx_L14; + } - /* "View.MemoryView":1283 - * broadcast_leading(&src, src_ndim, dst_ndim) - * elif dst_ndim < src_ndim: - * broadcast_leading(&dst, dst_ndim, src_ndim) # <<<<<<<<<<<<<< - * - * cdef int ndim = max(src_ndim, dst_ndim) + /* "View.MemoryView":845 + * start = shape - 1 + * else: + * start = shape # <<<<<<<<<<<<<< + * else: + * if negative_step: */ - __pyx_memoryview_broadcast_leading((&__pyx_v_dst), __pyx_v_dst_ndim, __pyx_v_src_ndim); - - /* "View.MemoryView":1282 - * if src_ndim < dst_ndim: - * broadcast_leading(&src, src_ndim, dst_ndim) - * elif dst_ndim < src_ndim: # <<<<<<<<<<<<<< - * broadcast_leading(&dst, dst_ndim, src_ndim) - * - */ - } - __pyx_L3:; + /*else*/ { + __pyx_v_start = __pyx_v_shape; + } + __pyx_L14:; - /* "View.MemoryView":1285 - * broadcast_leading(&dst, dst_ndim, src_ndim) - * - * cdef int ndim = max(src_ndim, dst_ndim) # <<<<<<<<<<<<<< - * - * for i in range(ndim): + /* "View.MemoryView":841 + * if start < 0: + * start = 0 + * elif start >= shape: # <<<<<<<<<<<<<< + * if negative_step: + * start = shape - 1 */ - __pyx_t_3 = __pyx_v_dst_ndim; - __pyx_t_4 = __pyx_v_src_ndim; - if (((__pyx_t_3 > __pyx_t_4) != 0)) { - __pyx_t_5 = __pyx_t_3; - } else { - __pyx_t_5 = __pyx_t_4; - } - __pyx_v_ndim = __pyx_t_5; + } + __pyx_L12:; - /* "View.MemoryView":1287 - * cdef int ndim = max(src_ndim, dst_ndim) + /* "View.MemoryView":836 * - * for i in range(ndim): # <<<<<<<<<<<<<< - * if src.shape[i] != dst.shape[i]: - * if src.shape[i] == 1: - */ - __pyx_t_5 = __pyx_v_ndim; - __pyx_t_3 = __pyx_t_5; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_i = __pyx_t_4; - - /* "View.MemoryView":1288 * - * for i in range(ndim): - * if src.shape[i] != dst.shape[i]: # <<<<<<<<<<<<<< - * if src.shape[i] == 1: - * broadcasting = True + * if have_start: # <<<<<<<<<<<<<< + * if start < 0: + * start += shape */ - __pyx_t_2 = (((__pyx_v_src.shape[__pyx_v_i]) != (__pyx_v_dst.shape[__pyx_v_i])) != 0); - if (__pyx_t_2) { + goto __pyx_L11; + } - /* "View.MemoryView":1289 - * for i in range(ndim): - * if src.shape[i] != dst.shape[i]: - * if src.shape[i] == 1: # <<<<<<<<<<<<<< - * broadcasting = True - * src.strides[i] = 0 + /* "View.MemoryView":847 + * start = shape + * else: + * if negative_step: # <<<<<<<<<<<<<< + * start = shape - 1 + * else: */ - __pyx_t_2 = (((__pyx_v_src.shape[__pyx_v_i]) == 1) != 0); + /*else*/ { + __pyx_t_2 = (__pyx_v_negative_step != 0); if (__pyx_t_2) { - /* "View.MemoryView":1290 - * if src.shape[i] != dst.shape[i]: - * if src.shape[i] == 1: - * broadcasting = True # <<<<<<<<<<<<<< - * src.strides[i] = 0 + /* "View.MemoryView":848 + * else: + * if negative_step: + * start = shape - 1 # <<<<<<<<<<<<<< * else: + * start = 0 */ - __pyx_v_broadcasting = 1; + __pyx_v_start = (__pyx_v_shape - 1); - /* "View.MemoryView":1291 - * if src.shape[i] == 1: - * broadcasting = True - * src.strides[i] = 0 # <<<<<<<<<<<<<< + /* "View.MemoryView":847 + * start = shape + * else: + * if negative_step: # <<<<<<<<<<<<<< + * start = shape - 1 * else: - * _err_extents(i, dst.shape[i], src.shape[i]) - */ - (__pyx_v_src.strides[__pyx_v_i]) = 0; - - /* "View.MemoryView":1289 - * for i in range(ndim): - * if src.shape[i] != dst.shape[i]: - * if src.shape[i] == 1: # <<<<<<<<<<<<<< - * broadcasting = True - * src.strides[i] = 0 */ - goto __pyx_L7; + goto __pyx_L15; } - /* "View.MemoryView":1293 - * src.strides[i] = 0 + /* "View.MemoryView":850 + * start = shape - 1 * else: - * _err_extents(i, dst.shape[i], src.shape[i]) # <<<<<<<<<<<<<< + * start = 0 # <<<<<<<<<<<<<< * - * if src.suboffsets[i] >= 0: + * if have_stop: */ /*else*/ { - __pyx_t_6 = __pyx_memoryview_err_extents(__pyx_v_i, (__pyx_v_dst.shape[__pyx_v_i]), (__pyx_v_src.shape[__pyx_v_i])); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 1293, __pyx_L1_error) + __pyx_v_start = 0; } - __pyx_L7:; - - /* "View.MemoryView":1288 - * - * for i in range(ndim): - * if src.shape[i] != dst.shape[i]: # <<<<<<<<<<<<<< - * if src.shape[i] == 1: - * broadcasting = True - */ + __pyx_L15:; } + __pyx_L11:; - /* "View.MemoryView":1295 - * _err_extents(i, dst.shape[i], src.shape[i]) - * - * if src.suboffsets[i] >= 0: # <<<<<<<<<<<<<< - * _err_dim(ValueError, "Dimension %d is not direct", i) + /* "View.MemoryView":852 + * start = 0 * + * if have_stop: # <<<<<<<<<<<<<< + * if stop < 0: + * stop += shape */ - __pyx_t_2 = (((__pyx_v_src.suboffsets[__pyx_v_i]) >= 0) != 0); + __pyx_t_2 = (__pyx_v_have_stop != 0); if (__pyx_t_2) { - /* "View.MemoryView":1296 - * - * if src.suboffsets[i] >= 0: - * _err_dim(ValueError, "Dimension %d is not direct", i) # <<<<<<<<<<<<<< + /* "View.MemoryView":853 * - * if slices_overlap(&src, &dst, ndim, itemsize): + * if have_stop: + * if stop < 0: # <<<<<<<<<<<<<< + * stop += shape + * if stop < 0: */ - __pyx_t_6 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Dimension %d is not direct"), __pyx_v_i); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 1296, __pyx_L1_error) + __pyx_t_2 = ((__pyx_v_stop < 0) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1295 - * _err_extents(i, dst.shape[i], src.shape[i]) - * - * if src.suboffsets[i] >= 0: # <<<<<<<<<<<<<< - * _err_dim(ValueError, "Dimension %d is not direct", i) - * + /* "View.MemoryView":854 + * if have_stop: + * if stop < 0: + * stop += shape # <<<<<<<<<<<<<< + * if stop < 0: + * stop = 0 */ - } - } + __pyx_v_stop = (__pyx_v_stop + __pyx_v_shape); - /* "View.MemoryView":1298 - * _err_dim(ValueError, "Dimension %d is not direct", i) - * - * if slices_overlap(&src, &dst, ndim, itemsize): # <<<<<<<<<<<<<< - * - * if not slice_is_contig(src, order, ndim): + /* "View.MemoryView":855 + * if stop < 0: + * stop += shape + * if stop < 0: # <<<<<<<<<<<<<< + * stop = 0 + * elif stop > shape: */ - __pyx_t_2 = (__pyx_slices_overlap((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize) != 0); - if (__pyx_t_2) { + __pyx_t_2 = ((__pyx_v_stop < 0) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1300 - * if slices_overlap(&src, &dst, ndim, itemsize): - * - * if not slice_is_contig(src, order, ndim): # <<<<<<<<<<<<<< - * order = get_best_order(&dst, ndim) - * + /* "View.MemoryView":856 + * stop += shape + * if stop < 0: + * stop = 0 # <<<<<<<<<<<<<< + * elif stop > shape: + * stop = shape */ - __pyx_t_2 = ((!(__pyx_memviewslice_is_contig(__pyx_v_src, __pyx_v_order, __pyx_v_ndim) != 0)) != 0); - if (__pyx_t_2) { + __pyx_v_stop = 0; - /* "View.MemoryView":1301 - * - * if not slice_is_contig(src, order, ndim): - * order = get_best_order(&dst, ndim) # <<<<<<<<<<<<<< - * - * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) + /* "View.MemoryView":855 + * if stop < 0: + * stop += shape + * if stop < 0: # <<<<<<<<<<<<<< + * stop = 0 + * elif stop > shape: */ - __pyx_v_order = __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim); + } - /* "View.MemoryView":1300 - * if slices_overlap(&src, &dst, ndim, itemsize): - * - * if not slice_is_contig(src, order, ndim): # <<<<<<<<<<<<<< - * order = get_best_order(&dst, ndim) + /* "View.MemoryView":853 * + * if have_stop: + * if stop < 0: # <<<<<<<<<<<<<< + * stop += shape + * if stop < 0: */ - } + goto __pyx_L17; + } - /* "View.MemoryView":1303 - * order = get_best_order(&dst, ndim) - * - * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) # <<<<<<<<<<<<<< - * src = tmp - * + /* "View.MemoryView":857 + * if stop < 0: + * stop = 0 + * elif stop > shape: # <<<<<<<<<<<<<< + * stop = shape + * else: */ - __pyx_t_7 = __pyx_memoryview_copy_data_to_temp((&__pyx_v_src), (&__pyx_v_tmp), __pyx_v_order, __pyx_v_ndim); if (unlikely(__pyx_t_7 == ((void *)NULL))) __PYX_ERR(1, 1303, __pyx_L1_error) - __pyx_v_tmpdata = __pyx_t_7; + __pyx_t_2 = ((__pyx_v_stop > __pyx_v_shape) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1304 - * - * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) - * src = tmp # <<<<<<<<<<<<<< - * - * if not broadcasting: + /* "View.MemoryView":858 + * stop = 0 + * elif stop > shape: + * stop = shape # <<<<<<<<<<<<<< + * else: + * if negative_step: */ - __pyx_v_src = __pyx_v_tmp; + __pyx_v_stop = __pyx_v_shape; - /* "View.MemoryView":1298 - * _err_dim(ValueError, "Dimension %d is not direct", i) - * - * if slices_overlap(&src, &dst, ndim, itemsize): # <<<<<<<<<<<<<< - * - * if not slice_is_contig(src, order, ndim): + /* "View.MemoryView":857 + * if stop < 0: + * stop = 0 + * elif stop > shape: # <<<<<<<<<<<<<< + * stop = shape + * else: */ - } + } + __pyx_L17:; - /* "View.MemoryView":1306 - * src = tmp - * - * if not broadcasting: # <<<<<<<<<<<<<< - * + /* "View.MemoryView":852 + * start = 0 * + * if have_stop: # <<<<<<<<<<<<<< + * if stop < 0: + * stop += shape */ - __pyx_t_2 = ((!(__pyx_v_broadcasting != 0)) != 0); - if (__pyx_t_2) { + goto __pyx_L16; + } - /* "View.MemoryView":1309 - * - * - * if slice_is_contig(src, 'C', ndim): # <<<<<<<<<<<<<< - * direct_copy = slice_is_contig(dst, 'C', ndim) - * elif slice_is_contig(src, 'F', ndim): + /* "View.MemoryView":860 + * stop = shape + * else: + * if negative_step: # <<<<<<<<<<<<<< + * stop = -1 + * else: */ - __pyx_t_2 = (__pyx_memviewslice_is_contig(__pyx_v_src, 'C', __pyx_v_ndim) != 0); - if (__pyx_t_2) { + /*else*/ { + __pyx_t_2 = (__pyx_v_negative_step != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1310 - * - * if slice_is_contig(src, 'C', ndim): - * direct_copy = slice_is_contig(dst, 'C', ndim) # <<<<<<<<<<<<<< - * elif slice_is_contig(src, 'F', ndim): - * direct_copy = slice_is_contig(dst, 'F', ndim) + /* "View.MemoryView":861 + * else: + * if negative_step: + * stop = -1 # <<<<<<<<<<<<<< + * else: + * stop = shape */ - __pyx_v_direct_copy = __pyx_memviewslice_is_contig(__pyx_v_dst, 'C', __pyx_v_ndim); + __pyx_v_stop = -1L; - /* "View.MemoryView":1309 - * + /* "View.MemoryView":860 + * stop = shape + * else: + * if negative_step: # <<<<<<<<<<<<<< + * stop = -1 + * else: + */ + goto __pyx_L19; + } + + /* "View.MemoryView":863 + * stop = -1 + * else: + * stop = shape # <<<<<<<<<<<<<< * - * if slice_is_contig(src, 'C', ndim): # <<<<<<<<<<<<<< - * direct_copy = slice_is_contig(dst, 'C', ndim) - * elif slice_is_contig(src, 'F', ndim): + * if not have_step: */ - goto __pyx_L12; + /*else*/ { + __pyx_v_stop = __pyx_v_shape; + } + __pyx_L19:; } + __pyx_L16:; - /* "View.MemoryView":1311 - * if slice_is_contig(src, 'C', ndim): - * direct_copy = slice_is_contig(dst, 'C', ndim) - * elif slice_is_contig(src, 'F', ndim): # <<<<<<<<<<<<<< - * direct_copy = slice_is_contig(dst, 'F', ndim) + /* "View.MemoryView":865 + * stop = shape + * + * if not have_step: # <<<<<<<<<<<<<< + * step = 1 * */ - __pyx_t_2 = (__pyx_memviewslice_is_contig(__pyx_v_src, 'F', __pyx_v_ndim) != 0); + __pyx_t_2 = ((!(__pyx_v_have_step != 0)) != 0); if (__pyx_t_2) { - /* "View.MemoryView":1312 - * direct_copy = slice_is_contig(dst, 'C', ndim) - * elif slice_is_contig(src, 'F', ndim): - * direct_copy = slice_is_contig(dst, 'F', ndim) # <<<<<<<<<<<<<< + /* "View.MemoryView":866 + * + * if not have_step: + * step = 1 # <<<<<<<<<<<<<< + * * - * if direct_copy: */ - __pyx_v_direct_copy = __pyx_memviewslice_is_contig(__pyx_v_dst, 'F', __pyx_v_ndim); + __pyx_v_step = 1; - /* "View.MemoryView":1311 - * if slice_is_contig(src, 'C', ndim): - * direct_copy = slice_is_contig(dst, 'C', ndim) - * elif slice_is_contig(src, 'F', ndim): # <<<<<<<<<<<<<< - * direct_copy = slice_is_contig(dst, 'F', ndim) + /* "View.MemoryView":865 + * stop = shape + * + * if not have_step: # <<<<<<<<<<<<<< + * step = 1 * */ } - __pyx_L12:; - /* "View.MemoryView":1314 - * direct_copy = slice_is_contig(dst, 'F', ndim) + /* "View.MemoryView":870 * - * if direct_copy: # <<<<<<<<<<<<<< + * with cython.cdivision(True): + * new_shape = (stop - start) // step # <<<<<<<<<<<<<< * - * refcount_copying(&dst, dtype_is_object, ndim, False) + * if (stop - start) - step * new_shape: */ - __pyx_t_2 = (__pyx_v_direct_copy != 0); - if (__pyx_t_2) { + __pyx_v_new_shape = ((__pyx_v_stop - __pyx_v_start) / __pyx_v_step); - /* "View.MemoryView":1316 - * if direct_copy: + /* "View.MemoryView":872 + * new_shape = (stop - start) // step * - * refcount_copying(&dst, dtype_is_object, ndim, False) # <<<<<<<<<<<<<< - * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) - * refcount_copying(&dst, dtype_is_object, ndim, True) - */ - __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 0); - - /* "View.MemoryView":1317 + * if (stop - start) - step * new_shape: # <<<<<<<<<<<<<< + * new_shape += 1 * - * refcount_copying(&dst, dtype_is_object, ndim, False) - * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) # <<<<<<<<<<<<<< - * refcount_copying(&dst, dtype_is_object, ndim, True) - * free(tmpdata) - */ - (void)(memcpy(__pyx_v_dst.data, __pyx_v_src.data, __pyx_memoryview_slice_get_size((&__pyx_v_src), __pyx_v_ndim))); - - /* "View.MemoryView":1318 - * refcount_copying(&dst, dtype_is_object, ndim, False) - * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) - * refcount_copying(&dst, dtype_is_object, ndim, True) # <<<<<<<<<<<<<< - * free(tmpdata) - * return 0 */ - __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1); + __pyx_t_2 = (((__pyx_v_stop - __pyx_v_start) - (__pyx_v_step * __pyx_v_new_shape)) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1319 - * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) - * refcount_copying(&dst, dtype_is_object, ndim, True) - * free(tmpdata) # <<<<<<<<<<<<<< - * return 0 + /* "View.MemoryView":873 * - */ - free(__pyx_v_tmpdata); - - /* "View.MemoryView":1320 - * refcount_copying(&dst, dtype_is_object, ndim, True) - * free(tmpdata) - * return 0 # <<<<<<<<<<<<<< + * if (stop - start) - step * new_shape: + * new_shape += 1 # <<<<<<<<<<<<<< * - * if order == 'F' == get_best_order(&dst, ndim): + * if new_shape < 0: */ - __pyx_r = 0; - goto __pyx_L0; + __pyx_v_new_shape = (__pyx_v_new_shape + 1); - /* "View.MemoryView":1314 - * direct_copy = slice_is_contig(dst, 'F', ndim) + /* "View.MemoryView":872 + * new_shape = (stop - start) // step * - * if direct_copy: # <<<<<<<<<<<<<< + * if (stop - start) - step * new_shape: # <<<<<<<<<<<<<< + * new_shape += 1 * - * refcount_copying(&dst, dtype_is_object, ndim, False) */ } - /* "View.MemoryView":1306 - * src = tmp - * - * if not broadcasting: # <<<<<<<<<<<<<< + /* "View.MemoryView":875 + * new_shape += 1 * + * if new_shape < 0: # <<<<<<<<<<<<<< + * new_shape = 0 * */ - } + __pyx_t_2 = ((__pyx_v_new_shape < 0) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1322 - * return 0 + /* "View.MemoryView":876 * - * if order == 'F' == get_best_order(&dst, ndim): # <<<<<<<<<<<<<< + * if new_shape < 0: + * new_shape = 0 # <<<<<<<<<<<<<< * * */ - __pyx_t_2 = (__pyx_v_order == 'F'); - if (__pyx_t_2) { - __pyx_t_2 = ('F' == __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim)); - } - __pyx_t_8 = (__pyx_t_2 != 0); - if (__pyx_t_8) { + __pyx_v_new_shape = 0; - /* "View.MemoryView":1325 - * + /* "View.MemoryView":875 + * new_shape += 1 * - * transpose_memslice(&src) # <<<<<<<<<<<<<< - * transpose_memslice(&dst) + * if new_shape < 0: # <<<<<<<<<<<<<< + * new_shape = 0 * */ - __pyx_t_5 = __pyx_memslice_transpose((&__pyx_v_src)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(1, 1325, __pyx_L1_error) + } - /* "View.MemoryView":1326 + /* "View.MemoryView":879 * - * transpose_memslice(&src) - * transpose_memslice(&dst) # <<<<<<<<<<<<<< * - * refcount_copying(&dst, dtype_is_object, ndim, False) + * dst.strides[new_ndim] = stride * step # <<<<<<<<<<<<<< + * dst.shape[new_ndim] = new_shape + * dst.suboffsets[new_ndim] = suboffset */ - __pyx_t_5 = __pyx_memslice_transpose((&__pyx_v_dst)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(1, 1326, __pyx_L1_error) + (__pyx_v_dst->strides[__pyx_v_new_ndim]) = (__pyx_v_stride * __pyx_v_step); - /* "View.MemoryView":1322 - * return 0 - * - * if order == 'F' == get_best_order(&dst, ndim): # <<<<<<<<<<<<<< + /* "View.MemoryView":880 * + * dst.strides[new_ndim] = stride * step + * dst.shape[new_ndim] = new_shape # <<<<<<<<<<<<<< + * dst.suboffsets[new_ndim] = suboffset * */ - } + (__pyx_v_dst->shape[__pyx_v_new_ndim]) = __pyx_v_new_shape; - /* "View.MemoryView":1328 - * transpose_memslice(&dst) + /* "View.MemoryView":881 + * dst.strides[new_ndim] = stride * step + * dst.shape[new_ndim] = new_shape + * dst.suboffsets[new_ndim] = suboffset # <<<<<<<<<<<<<< + * * - * refcount_copying(&dst, dtype_is_object, ndim, False) # <<<<<<<<<<<<<< - * copy_strided_to_strided(&src, &dst, ndim, itemsize) - * refcount_copying(&dst, dtype_is_object, ndim, True) */ - __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 0); + (__pyx_v_dst->suboffsets[__pyx_v_new_ndim]) = __pyx_v_suboffset; + } + __pyx_L3:; - /* "View.MemoryView":1329 + /* "View.MemoryView":884 * - * refcount_copying(&dst, dtype_is_object, ndim, False) - * copy_strided_to_strided(&src, &dst, ndim, itemsize) # <<<<<<<<<<<<<< - * refcount_copying(&dst, dtype_is_object, ndim, True) * + * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<< + * dst.data += start * stride + * else: */ - copy_strided_to_strided((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize); + __pyx_t_2 = (((__pyx_v_suboffset_dim[0]) < 0) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1330 - * refcount_copying(&dst, dtype_is_object, ndim, False) - * copy_strided_to_strided(&src, &dst, ndim, itemsize) - * refcount_copying(&dst, dtype_is_object, ndim, True) # <<<<<<<<<<<<<< + /* "View.MemoryView":885 * - * free(tmpdata) + * if suboffset_dim[0] < 0: + * dst.data += start * stride # <<<<<<<<<<<<<< + * else: + * dst.suboffsets[suboffset_dim[0]] += start * stride */ - __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1); + __pyx_v_dst->data = (__pyx_v_dst->data + (__pyx_v_start * __pyx_v_stride)); - /* "View.MemoryView":1332 - * refcount_copying(&dst, dtype_is_object, ndim, True) + /* "View.MemoryView":884 + * + * + * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<< + * dst.data += start * stride + * else: + */ + goto __pyx_L23; + } + + /* "View.MemoryView":887 + * dst.data += start * stride + * else: + * dst.suboffsets[suboffset_dim[0]] += start * stride # <<<<<<<<<<<<<< + * + * if suboffset >= 0: + */ + /*else*/ { + __pyx_t_3 = (__pyx_v_suboffset_dim[0]); + (__pyx_v_dst->suboffsets[__pyx_t_3]) = ((__pyx_v_dst->suboffsets[__pyx_t_3]) + (__pyx_v_start * __pyx_v_stride)); + } + __pyx_L23:; + + /* "View.MemoryView":889 + * dst.suboffsets[suboffset_dim[0]] += start * stride + * + * if suboffset >= 0: # <<<<<<<<<<<<<< + * if not is_slice: + * if new_ndim == 0: + */ + __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":890 + * + * if suboffset >= 0: + * if not is_slice: # <<<<<<<<<<<<<< + * if new_ndim == 0: + * dst.data = ( dst.data)[0] + suboffset + */ + __pyx_t_2 = ((!(__pyx_v_is_slice != 0)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":891 + * if suboffset >= 0: + * if not is_slice: + * if new_ndim == 0: # <<<<<<<<<<<<<< + * dst.data = ( dst.data)[0] + suboffset + * else: + */ + __pyx_t_2 = ((__pyx_v_new_ndim == 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":892 + * if not is_slice: + * if new_ndim == 0: + * dst.data = ( dst.data)[0] + suboffset # <<<<<<<<<<<<<< + * else: + * _err_dim(IndexError, "All dimensions preceding dimension %d " + */ + __pyx_v_dst->data = ((((char **)__pyx_v_dst->data)[0]) + __pyx_v_suboffset); + + /* "View.MemoryView":891 + * if suboffset >= 0: + * if not is_slice: + * if new_ndim == 0: # <<<<<<<<<<<<<< + * dst.data = ( dst.data)[0] + suboffset + * else: + */ + goto __pyx_L26; + } + + /* "View.MemoryView":894 + * dst.data = ( dst.data)[0] + suboffset + * else: + * _err_dim(IndexError, "All dimensions preceding dimension %d " # <<<<<<<<<<<<<< + * "must be indexed and not sliced", dim) + * else: + */ + /*else*/ { + + /* "View.MemoryView":895 + * else: + * _err_dim(IndexError, "All dimensions preceding dimension %d " + * "must be indexed and not sliced", dim) # <<<<<<<<<<<<<< + * else: + * suboffset_dim[0] = new_ndim + */ + __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"All dimensions preceding dimension %d must be indexed and not sliced"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 894, __pyx_L1_error) + } + __pyx_L26:; + + /* "View.MemoryView":890 + * + * if suboffset >= 0: + * if not is_slice: # <<<<<<<<<<<<<< + * if new_ndim == 0: + * dst.data = ( dst.data)[0] + suboffset + */ + goto __pyx_L25; + } + + /* "View.MemoryView":897 + * "must be indexed and not sliced", dim) + * else: + * suboffset_dim[0] = new_ndim # <<<<<<<<<<<<<< * - * free(tmpdata) # <<<<<<<<<<<<<< * return 0 + */ + /*else*/ { + (__pyx_v_suboffset_dim[0]) = __pyx_v_new_ndim; + } + __pyx_L25:; + + /* "View.MemoryView":889 + * dst.suboffsets[suboffset_dim[0]] += start * stride * + * if suboffset >= 0: # <<<<<<<<<<<<<< + * if not is_slice: + * if new_ndim == 0: */ - free(__pyx_v_tmpdata); + } - /* "View.MemoryView":1333 + /* "View.MemoryView":899 + * suboffset_dim[0] = new_ndim * - * free(tmpdata) * return 0 # <<<<<<<<<<<<<< * - * @cname('__pyx_memoryview_broadcast_leading') + * */ __pyx_r = 0; goto __pyx_L0; - /* "View.MemoryView":1264 + /* "View.MemoryView":802 * - * @cname('__pyx_memoryview_copy_contents') - * cdef int memoryview_copy_contents(__Pyx_memviewslice src, # <<<<<<<<<<<<<< - * __Pyx_memviewslice dst, - * int src_ndim, int dst_ndim, + * @cname('__pyx_memoryview_slice_memviewslice') + * cdef int slice_memviewslice( # <<<<<<<<<<<<<< + * __Pyx_memviewslice *dst, + * Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset, */ /* function exit code */ @@ -42981,7 +48969,7 @@ static int __pyx_memoryview_copy_contents(__Pyx_memviewslice __pyx_v_src, __Pyx_ #ifdef WITH_THREAD PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); #endif - __Pyx_AddTraceback("View.MemoryView.memoryview_copy_contents", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("View.MemoryView.slice_memviewslice", __pyx_clineno, __pyx_lineno, __pyx_filename); #ifdef WITH_THREAD __Pyx_PyGILState_Release(__pyx_gilstate_save); #endif @@ -42992,4146 +48980,9772 @@ static int __pyx_memoryview_copy_contents(__Pyx_memviewslice __pyx_v_src, __Pyx_ return __pyx_r; } -/* "View.MemoryView":1336 +/* "View.MemoryView":905 * - * @cname('__pyx_memoryview_broadcast_leading') - * cdef void broadcast_leading(__Pyx_memviewslice *mslice, # <<<<<<<<<<<<<< - * int ndim, - * int ndim_other) nogil: + * @cname('__pyx_pybuffer_index') + * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<< + * Py_ssize_t dim) except NULL: + * cdef Py_ssize_t shape, stride, suboffset = -1 */ -static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *__pyx_v_mslice, int __pyx_v_ndim, int __pyx_v_ndim_other) { - int __pyx_v_i; - int __pyx_v_offset; +static char *__pyx_pybuffer_index(Py_buffer *__pyx_v_view, char *__pyx_v_bufp, Py_ssize_t __pyx_v_index, Py_ssize_t __pyx_v_dim) { + Py_ssize_t __pyx_v_shape; + Py_ssize_t __pyx_v_stride; + Py_ssize_t __pyx_v_suboffset; + Py_ssize_t __pyx_v_itemsize; + char *__pyx_v_resultp; + char *__pyx_r; __Pyx_TraceDeclarations - int __pyx_t_1; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; int __pyx_t_2; - int __pyx_t_3; - __Pyx_TraceCall("broadcast_leading", __pyx_f[1], 1336, 1, __PYX_ERR(1, 1336, __pyx_L1_error)); + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("pybuffer_index", 0); + __Pyx_TraceCall("pybuffer_index", __pyx_f[1], 905, 0, __PYX_ERR(1, 905, __pyx_L1_error)); - /* "View.MemoryView":1340 - * int ndim_other) nogil: - * cdef int i - * cdef int offset = ndim_other - ndim # <<<<<<<<<<<<<< - * - * for i in range(ndim - 1, -1, -1): + /* "View.MemoryView":907 + * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, + * Py_ssize_t dim) except NULL: + * cdef Py_ssize_t shape, stride, suboffset = -1 # <<<<<<<<<<<<<< + * cdef Py_ssize_t itemsize = view.itemsize + * cdef char *resultp */ - __pyx_v_offset = (__pyx_v_ndim_other - __pyx_v_ndim); + __pyx_v_suboffset = -1L; - /* "View.MemoryView":1342 - * cdef int offset = ndim_other - ndim + /* "View.MemoryView":908 + * Py_ssize_t dim) except NULL: + * cdef Py_ssize_t shape, stride, suboffset = -1 + * cdef Py_ssize_t itemsize = view.itemsize # <<<<<<<<<<<<<< + * cdef char *resultp * - * for i in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< - * mslice.shape[i + offset] = mslice.shape[i] - * mslice.strides[i + offset] = mslice.strides[i] */ - for (__pyx_t_1 = (__pyx_v_ndim - 1); __pyx_t_1 > -1; __pyx_t_1-=1) { - __pyx_v_i = __pyx_t_1; + __pyx_t_1 = __pyx_v_view->itemsize; + __pyx_v_itemsize = __pyx_t_1; - /* "View.MemoryView":1343 + /* "View.MemoryView":911 + * cdef char *resultp * - * for i in range(ndim - 1, -1, -1): - * mslice.shape[i + offset] = mslice.shape[i] # <<<<<<<<<<<<<< - * mslice.strides[i + offset] = mslice.strides[i] - * mslice.suboffsets[i + offset] = mslice.suboffsets[i] + * if view.ndim == 0: # <<<<<<<<<<<<<< + * shape = view.len / itemsize + * stride = itemsize */ - (__pyx_v_mslice->shape[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->shape[__pyx_v_i]); + __pyx_t_2 = ((__pyx_v_view->ndim == 0) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1344 - * for i in range(ndim - 1, -1, -1): - * mslice.shape[i + offset] = mslice.shape[i] - * mslice.strides[i + offset] = mslice.strides[i] # <<<<<<<<<<<<<< - * mslice.suboffsets[i + offset] = mslice.suboffsets[i] + /* "View.MemoryView":912 * + * if view.ndim == 0: + * shape = view.len / itemsize # <<<<<<<<<<<<<< + * stride = itemsize + * else: */ - (__pyx_v_mslice->strides[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->strides[__pyx_v_i]); + if (unlikely(__pyx_v_itemsize == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + __PYX_ERR(1, 912, __pyx_L1_error) + } + else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_view->len))) { + PyErr_SetString(PyExc_OverflowError, "value too large to perform division"); + __PYX_ERR(1, 912, __pyx_L1_error) + } + __pyx_v_shape = __Pyx_div_Py_ssize_t(__pyx_v_view->len, __pyx_v_itemsize); - /* "View.MemoryView":1345 - * mslice.shape[i + offset] = mslice.shape[i] - * mslice.strides[i + offset] = mslice.strides[i] - * mslice.suboffsets[i + offset] = mslice.suboffsets[i] # <<<<<<<<<<<<<< + /* "View.MemoryView":913 + * if view.ndim == 0: + * shape = view.len / itemsize + * stride = itemsize # <<<<<<<<<<<<<< + * else: + * shape = view.shape[dim] + */ + __pyx_v_stride = __pyx_v_itemsize; + + /* "View.MemoryView":911 + * cdef char *resultp * - * for i in range(offset): + * if view.ndim == 0: # <<<<<<<<<<<<<< + * shape = view.len / itemsize + * stride = itemsize */ - (__pyx_v_mslice->suboffsets[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->suboffsets[__pyx_v_i]); + goto __pyx_L3; } - /* "View.MemoryView":1347 - * mslice.suboffsets[i + offset] = mslice.suboffsets[i] - * - * for i in range(offset): # <<<<<<<<<<<<<< - * mslice.shape[i] = 1 - * mslice.strides[i] = mslice.strides[0] + /* "View.MemoryView":915 + * stride = itemsize + * else: + * shape = view.shape[dim] # <<<<<<<<<<<<<< + * stride = view.strides[dim] + * if view.suboffsets != NULL: */ - __pyx_t_1 = __pyx_v_offset; - __pyx_t_2 = __pyx_t_1; - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; + /*else*/ { + __pyx_v_shape = (__pyx_v_view->shape[__pyx_v_dim]); - /* "View.MemoryView":1348 - * - * for i in range(offset): - * mslice.shape[i] = 1 # <<<<<<<<<<<<<< - * mslice.strides[i] = mslice.strides[0] - * mslice.suboffsets[i] = -1 + /* "View.MemoryView":916 + * else: + * shape = view.shape[dim] + * stride = view.strides[dim] # <<<<<<<<<<<<<< + * if view.suboffsets != NULL: + * suboffset = view.suboffsets[dim] */ - (__pyx_v_mslice->shape[__pyx_v_i]) = 1; + __pyx_v_stride = (__pyx_v_view->strides[__pyx_v_dim]); - /* "View.MemoryView":1349 - * for i in range(offset): - * mslice.shape[i] = 1 - * mslice.strides[i] = mslice.strides[0] # <<<<<<<<<<<<<< - * mslice.suboffsets[i] = -1 + /* "View.MemoryView":917 + * shape = view.shape[dim] + * stride = view.strides[dim] + * if view.suboffsets != NULL: # <<<<<<<<<<<<<< + * suboffset = view.suboffsets[dim] * */ - (__pyx_v_mslice->strides[__pyx_v_i]) = (__pyx_v_mslice->strides[0]); + __pyx_t_2 = ((__pyx_v_view->suboffsets != NULL) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1350 - * mslice.shape[i] = 1 - * mslice.strides[i] = mslice.strides[0] - * mslice.suboffsets[i] = -1 # <<<<<<<<<<<<<< + /* "View.MemoryView":918 + * stride = view.strides[dim] + * if view.suboffsets != NULL: + * suboffset = view.suboffsets[dim] # <<<<<<<<<<<<<< * + * if index < 0: + */ + __pyx_v_suboffset = (__pyx_v_view->suboffsets[__pyx_v_dim]); + + /* "View.MemoryView":917 + * shape = view.shape[dim] + * stride = view.strides[dim] + * if view.suboffsets != NULL: # <<<<<<<<<<<<<< + * suboffset = view.suboffsets[dim] * */ - (__pyx_v_mslice->suboffsets[__pyx_v_i]) = -1L; + } } + __pyx_L3:; - /* "View.MemoryView":1336 + /* "View.MemoryView":920 + * suboffset = view.suboffsets[dim] * - * @cname('__pyx_memoryview_broadcast_leading') - * cdef void broadcast_leading(__Pyx_memviewslice *mslice, # <<<<<<<<<<<<<< - * int ndim, - * int ndim_other) nogil: + * if index < 0: # <<<<<<<<<<<<<< + * index += view.shape[dim] + * if index < 0: */ + __pyx_t_2 = ((__pyx_v_index < 0) != 0); + if (__pyx_t_2) { - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.broadcast_leading", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); -} - -/* "View.MemoryView":1358 + /* "View.MemoryView":921 * - * @cname('__pyx_memoryview_refcount_copying') - * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object, # <<<<<<<<<<<<<< - * int ndim, bint inc) nogil: + * if index < 0: + * index += view.shape[dim] # <<<<<<<<<<<<<< + * if index < 0: + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) + */ + __pyx_v_index = (__pyx_v_index + (__pyx_v_view->shape[__pyx_v_dim])); + + /* "View.MemoryView":922 + * if index < 0: + * index += view.shape[dim] + * if index < 0: # <<<<<<<<<<<<<< + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) * */ + __pyx_t_2 = ((__pyx_v_index < 0) != 0); + if (unlikely(__pyx_t_2)) { -static void __pyx_memoryview_refcount_copying(__Pyx_memviewslice *__pyx_v_dst, int __pyx_v_dtype_is_object, int __pyx_v_ndim, int __pyx_v_inc) { - __Pyx_TraceDeclarations - int __pyx_t_1; - __Pyx_TraceCall("refcount_copying", __pyx_f[1], 1358, 1, __PYX_ERR(1, 1358, __pyx_L1_error)); + /* "View.MemoryView":923 + * index += view.shape[dim] + * if index < 0: + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<< + * + * if index >= shape: + */ + __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 923, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 923, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 923, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(1, 923, __pyx_L1_error) - /* "View.MemoryView":1362 + /* "View.MemoryView":922 + * if index < 0: + * index += view.shape[dim] + * if index < 0: # <<<<<<<<<<<<<< + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) * + */ + } + + /* "View.MemoryView":920 + * suboffset = view.suboffsets[dim] * - * if dtype_is_object: # <<<<<<<<<<<<<< - * refcount_objects_in_slice_with_gil(dst.data, dst.shape, - * dst.strides, ndim, inc) + * if index < 0: # <<<<<<<<<<<<<< + * index += view.shape[dim] + * if index < 0: */ - __pyx_t_1 = (__pyx_v_dtype_is_object != 0); - if (__pyx_t_1) { + } - /* "View.MemoryView":1363 + /* "View.MemoryView":925 + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) * - * if dtype_is_object: - * refcount_objects_in_slice_with_gil(dst.data, dst.shape, # <<<<<<<<<<<<<< - * dst.strides, ndim, inc) + * if index >= shape: # <<<<<<<<<<<<<< + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) * */ - __pyx_memoryview_refcount_objects_in_slice_with_gil(__pyx_v_dst->data, __pyx_v_dst->shape, __pyx_v_dst->strides, __pyx_v_ndim, __pyx_v_inc); + __pyx_t_2 = ((__pyx_v_index >= __pyx_v_shape) != 0); + if (unlikely(__pyx_t_2)) { - /* "View.MemoryView":1362 + /* "View.MemoryView":926 * + * if index >= shape: + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<< * - * if dtype_is_object: # <<<<<<<<<<<<<< - * refcount_objects_in_slice_with_gil(dst.data, dst.shape, - * dst.strides, ndim, inc) + * resultp = bufp + index * stride */ - } + __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 926, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 926, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 926, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(1, 926, __pyx_L1_error) - /* "View.MemoryView":1358 + /* "View.MemoryView":925 + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) * - * @cname('__pyx_memoryview_refcount_copying') - * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object, # <<<<<<<<<<<<<< - * int ndim, bint inc) nogil: + * if index >= shape: # <<<<<<<<<<<<<< + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) * */ + } - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.refcount_copying", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); -} - -/* "View.MemoryView":1367 + /* "View.MemoryView":928 + * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) * - * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil') - * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< - * Py_ssize_t *strides, int ndim, - * bint inc) with gil: + * resultp = bufp + index * stride # <<<<<<<<<<<<<< + * if suboffset >= 0: + * resultp = ( resultp)[0] + suboffset */ + __pyx_v_resultp = (__pyx_v_bufp + (__pyx_v_index * __pyx_v_stride)); -static void __pyx_memoryview_refcount_objects_in_slice_with_gil(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, int __pyx_v_inc) { - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - #ifdef WITH_THREAD - PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); - #endif - __Pyx_RefNannySetupContext("refcount_objects_in_slice_with_gil", 0); - __Pyx_TraceCall("refcount_objects_in_slice_with_gil", __pyx_f[1], 1367, 0, __PYX_ERR(1, 1367, __pyx_L1_error)); - - /* "View.MemoryView":1370 - * Py_ssize_t *strides, int ndim, - * bint inc) with gil: - * refcount_objects_in_slice(data, shape, strides, ndim, inc) # <<<<<<<<<<<<<< + /* "View.MemoryView":929 + * + * resultp = bufp + index * stride + * if suboffset >= 0: # <<<<<<<<<<<<<< + * resultp = ( resultp)[0] + suboffset * - * @cname('__pyx_memoryview_refcount_objects_in_slice') */ - __pyx_memoryview_refcount_objects_in_slice(__pyx_v_data, __pyx_v_shape, __pyx_v_strides, __pyx_v_ndim, __pyx_v_inc); + __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":1367 + /* "View.MemoryView":930 + * resultp = bufp + index * stride + * if suboffset >= 0: + * resultp = ( resultp)[0] + suboffset # <<<<<<<<<<<<<< * - * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil') - * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< - * Py_ssize_t *strides, int ndim, - * bint inc) with gil: + * return resultp */ + __pyx_v_resultp = ((((char **)__pyx_v_resultp)[0]) + __pyx_v_suboffset); - /* function exit code */ + /* "View.MemoryView":929 + * + * resultp = bufp + index * stride + * if suboffset >= 0: # <<<<<<<<<<<<<< + * resultp = ( resultp)[0] + suboffset + * + */ + } + + /* "View.MemoryView":932 + * resultp = ( resultp)[0] + suboffset + * + * return resultp # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_resultp; goto __pyx_L0; + + /* "View.MemoryView":905 + * + * @cname('__pyx_pybuffer_index') + * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<< + * Py_ssize_t dim) except NULL: + * cdef Py_ssize_t shape, stride, suboffset = -1 + */ + + /* function exit code */ __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.refcount_objects_in_slice_with_gil", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("View.MemoryView.pybuffer_index", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); - #ifdef WITH_THREAD - __Pyx_PyGILState_Release(__pyx_gilstate_save); - #endif + return __pyx_r; } -/* "View.MemoryView":1373 +/* "View.MemoryView":938 + * + * @cname('__pyx_memslice_transpose') + * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<< + * cdef int ndim = memslice.memview.view.ndim * - * @cname('__pyx_memoryview_refcount_objects_in_slice') - * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< - * Py_ssize_t *strides, int ndim, bint inc): - * cdef Py_ssize_t i */ -static void __pyx_memoryview_refcount_objects_in_slice(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, int __pyx_v_inc) { - CYTHON_UNUSED Py_ssize_t __pyx_v_i; +static int __pyx_memslice_transpose(__Pyx_memviewslice *__pyx_v_memslice) { + int __pyx_v_ndim; + Py_ssize_t *__pyx_v_shape; + Py_ssize_t *__pyx_v_strides; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_r; __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - Py_ssize_t __pyx_t_2; - Py_ssize_t __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("refcount_objects_in_slice", 0); - __Pyx_TraceCall("refcount_objects_in_slice", __pyx_f[1], 1373, 0, __PYX_ERR(1, 1373, __pyx_L1_error)); + int __pyx_t_1; + Py_ssize_t *__pyx_t_2; + long __pyx_t_3; + long __pyx_t_4; + Py_ssize_t __pyx_t_5; + Py_ssize_t __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + int __pyx_t_9; + __Pyx_TraceCall("transpose_memslice", __pyx_f[1], 938, 1, __PYX_ERR(1, 938, __pyx_L1_error)); - /* "View.MemoryView":1377 - * cdef Py_ssize_t i + /* "View.MemoryView":939 + * @cname('__pyx_memslice_transpose') + * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: + * cdef int ndim = memslice.memview.view.ndim # <<<<<<<<<<<<<< * - * for i in range(shape[0]): # <<<<<<<<<<<<<< - * if ndim == 1: - * if inc: + * cdef Py_ssize_t *shape = memslice.shape */ - __pyx_t_1 = (__pyx_v_shape[0]); - __pyx_t_2 = __pyx_t_1; - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; + __pyx_t_1 = __pyx_v_memslice->memview->view.ndim; + __pyx_v_ndim = __pyx_t_1; - /* "View.MemoryView":1378 + /* "View.MemoryView":941 + * cdef int ndim = memslice.memview.view.ndim + * + * cdef Py_ssize_t *shape = memslice.shape # <<<<<<<<<<<<<< + * cdef Py_ssize_t *strides = memslice.strides * - * for i in range(shape[0]): - * if ndim == 1: # <<<<<<<<<<<<<< - * if inc: - * Py_INCREF(( data)[0]) */ - __pyx_t_4 = ((__pyx_v_ndim == 1) != 0); - if (__pyx_t_4) { + __pyx_t_2 = __pyx_v_memslice->shape; + __pyx_v_shape = __pyx_t_2; - /* "View.MemoryView":1379 - * for i in range(shape[0]): - * if ndim == 1: - * if inc: # <<<<<<<<<<<<<< - * Py_INCREF(( data)[0]) - * else: + /* "View.MemoryView":942 + * + * cdef Py_ssize_t *shape = memslice.shape + * cdef Py_ssize_t *strides = memslice.strides # <<<<<<<<<<<<<< + * + * */ - __pyx_t_4 = (__pyx_v_inc != 0); - if (__pyx_t_4) { + __pyx_t_2 = __pyx_v_memslice->strides; + __pyx_v_strides = __pyx_t_2; - /* "View.MemoryView":1380 - * if ndim == 1: - * if inc: - * Py_INCREF(( data)[0]) # <<<<<<<<<<<<<< - * else: - * Py_DECREF(( data)[0]) + /* "View.MemoryView":946 + * + * cdef int i, j + * for i in range(ndim / 2): # <<<<<<<<<<<<<< + * j = ndim - 1 - i + * strides[i], strides[j] = strides[j], strides[i] */ - Py_INCREF((((PyObject **)__pyx_v_data)[0])); + __pyx_t_3 = __Pyx_div_long(__pyx_v_ndim, 2); + __pyx_t_4 = __pyx_t_3; + for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_4; __pyx_t_1+=1) { + __pyx_v_i = __pyx_t_1; - /* "View.MemoryView":1379 - * for i in range(shape[0]): - * if ndim == 1: - * if inc: # <<<<<<<<<<<<<< - * Py_INCREF(( data)[0]) - * else: + /* "View.MemoryView":947 + * cdef int i, j + * for i in range(ndim / 2): + * j = ndim - 1 - i # <<<<<<<<<<<<<< + * strides[i], strides[j] = strides[j], strides[i] + * shape[i], shape[j] = shape[j], shape[i] */ - goto __pyx_L6; - } + __pyx_v_j = ((__pyx_v_ndim - 1) - __pyx_v_i); - /* "View.MemoryView":1382 - * Py_INCREF(( data)[0]) - * else: - * Py_DECREF(( data)[0]) # <<<<<<<<<<<<<< - * else: - * refcount_objects_in_slice(data, shape + 1, strides + 1, + /* "View.MemoryView":948 + * for i in range(ndim / 2): + * j = ndim - 1 - i + * strides[i], strides[j] = strides[j], strides[i] # <<<<<<<<<<<<<< + * shape[i], shape[j] = shape[j], shape[i] + * */ - /*else*/ { - Py_DECREF((((PyObject **)__pyx_v_data)[0])); - } - __pyx_L6:; + __pyx_t_5 = (__pyx_v_strides[__pyx_v_j]); + __pyx_t_6 = (__pyx_v_strides[__pyx_v_i]); + (__pyx_v_strides[__pyx_v_i]) = __pyx_t_5; + (__pyx_v_strides[__pyx_v_j]) = __pyx_t_6; - /* "View.MemoryView":1378 + /* "View.MemoryView":949 + * j = ndim - 1 - i + * strides[i], strides[j] = strides[j], strides[i] + * shape[i], shape[j] = shape[j], shape[i] # <<<<<<<<<<<<<< * - * for i in range(shape[0]): - * if ndim == 1: # <<<<<<<<<<<<<< - * if inc: - * Py_INCREF(( data)[0]) + * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: */ - goto __pyx_L5; + __pyx_t_6 = (__pyx_v_shape[__pyx_v_j]); + __pyx_t_5 = (__pyx_v_shape[__pyx_v_i]); + (__pyx_v_shape[__pyx_v_i]) = __pyx_t_6; + (__pyx_v_shape[__pyx_v_j]) = __pyx_t_5; + + /* "View.MemoryView":951 + * shape[i], shape[j] = shape[j], shape[i] + * + * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: # <<<<<<<<<<<<<< + * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") + * + */ + __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_i]) >= 0) != 0); + if (!__pyx_t_8) { + } else { + __pyx_t_7 = __pyx_t_8; + goto __pyx_L6_bool_binop_done; } + __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_j]) >= 0) != 0); + __pyx_t_7 = __pyx_t_8; + __pyx_L6_bool_binop_done:; + if (__pyx_t_7) { - /* "View.MemoryView":1384 - * Py_DECREF(( data)[0]) - * else: - * refcount_objects_in_slice(data, shape + 1, strides + 1, # <<<<<<<<<<<<<< - * ndim - 1, inc) + /* "View.MemoryView":952 * + * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: + * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") # <<<<<<<<<<<<<< + * + * return 1 */ - /*else*/ { + __pyx_t_9 = __pyx_memoryview_err(__pyx_builtin_ValueError, ((char *)"Cannot transpose memoryview with indirect dimensions")); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 952, __pyx_L1_error) - /* "View.MemoryView":1385 - * else: - * refcount_objects_in_slice(data, shape + 1, strides + 1, - * ndim - 1, inc) # <<<<<<<<<<<<<< + /* "View.MemoryView":951 + * shape[i], shape[j] = shape[j], shape[i] + * + * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: # <<<<<<<<<<<<<< + * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") * - * data += strides[0] */ - __pyx_memoryview_refcount_objects_in_slice(__pyx_v_data, (__pyx_v_shape + 1), (__pyx_v_strides + 1), (__pyx_v_ndim - 1), __pyx_v_inc); } - __pyx_L5:; + } - /* "View.MemoryView":1387 - * ndim - 1, inc) + /* "View.MemoryView":954 + * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") * - * data += strides[0] # <<<<<<<<<<<<<< + * return 1 # <<<<<<<<<<<<<< * * */ - __pyx_v_data = (__pyx_v_data + (__pyx_v_strides[0])); - } + __pyx_r = 1; + goto __pyx_L0; - /* "View.MemoryView":1373 + /* "View.MemoryView":938 + * + * @cname('__pyx_memslice_transpose') + * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<< + * cdef int ndim = memslice.memview.view.ndim * - * @cname('__pyx_memoryview_refcount_objects_in_slice') - * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< - * Py_ssize_t *strides, int ndim, bint inc): - * cdef Py_ssize_t i */ /* function exit code */ - goto __pyx_L0; __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.refcount_objects_in_slice", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + { + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_AddTraceback("View.MemoryView.transpose_memslice", __pyx_clineno, __pyx_lineno, __pyx_filename); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + } + __pyx_r = 0; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); + __Pyx_TraceReturn(Py_None, 1); + return __pyx_r; } -/* "View.MemoryView":1393 +/* "View.MemoryView":971 + * cdef int (*to_dtype_func)(char *, object) except 0 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) * - * @cname('__pyx_memoryview_slice_assign_scalar') - * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim, # <<<<<<<<<<<<<< - * size_t itemsize, void *item, - * bint dtype_is_object) nogil: */ -static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *__pyx_v_dst, int __pyx_v_ndim, size_t __pyx_v_itemsize, void *__pyx_v_item, int __pyx_v_dtype_is_object) { - __Pyx_TraceDeclarations - __Pyx_TraceCall("slice_assign_scalar", __pyx_f[1], 1393, 1, __PYX_ERR(1, 1393, __pyx_L1_error)); +/* Python wrapper */ +static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); - /* "View.MemoryView":1396 - * size_t itemsize, void *item, - * bint dtype_is_object) nogil: - * refcount_copying(dst, dtype_is_object, ndim, False) # <<<<<<<<<<<<<< - * _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim, - * itemsize, item) - */ - __pyx_memoryview_refcount_copying(__pyx_v_dst, __pyx_v_dtype_is_object, __pyx_v_ndim, 0); + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} - /* "View.MemoryView":1397 - * bint dtype_is_object) nogil: - * refcount_copying(dst, dtype_is_object, ndim, False) - * _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim, # <<<<<<<<<<<<<< - * itemsize, item) - * refcount_copying(dst, dtype_is_object, ndim, True) - */ - __pyx_memoryview__slice_assign_scalar(__pyx_v_dst->data, __pyx_v_dst->shape, __pyx_v_dst->strides, __pyx_v_ndim, __pyx_v_itemsize, __pyx_v_item); +static void __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self) { + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + __Pyx_TraceCall("__dealloc__", __pyx_f[1], 971, 0, __PYX_ERR(1, 971, __pyx_L1_error)); - /* "View.MemoryView":1399 - * _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim, - * itemsize, item) - * refcount_copying(dst, dtype_is_object, ndim, True) # <<<<<<<<<<<<<< + /* "View.MemoryView":972 * + * def __dealloc__(self): + * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) # <<<<<<<<<<<<<< * + * cdef convert_item_to_object(self, char *itemp): */ - __pyx_memoryview_refcount_copying(__pyx_v_dst, __pyx_v_dtype_is_object, __pyx_v_ndim, 1); + __PYX_XDEC_MEMVIEW((&__pyx_v_self->from_slice), 1); - /* "View.MemoryView":1393 + /* "View.MemoryView":971 + * cdef int (*to_dtype_func)(char *, object) except 0 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) * - * @cname('__pyx_memoryview_slice_assign_scalar') - * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim, # <<<<<<<<<<<<<< - * size_t itemsize, void *item, - * bint dtype_is_object) nogil: */ /* function exit code */ goto __pyx_L0; __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView.slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __Pyx_WriteUnraisable("View.MemoryView._memoryviewslice.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); } -/* "View.MemoryView":1403 +/* "View.MemoryView":974 + * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) * - * @cname('__pyx_memoryview__slice_assign_scalar') - * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< - * Py_ssize_t *strides, int ndim, - * size_t itemsize, void *item) nogil: + * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< + * if self.to_object_func != NULL: + * return self.to_object_func(itemp) */ -static void __pyx_memoryview__slice_assign_scalar(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, size_t __pyx_v_itemsize, void *__pyx_v_item) { - CYTHON_UNUSED Py_ssize_t __pyx_v_i; - Py_ssize_t __pyx_v_stride; - Py_ssize_t __pyx_v_extent; +static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations int __pyx_t_1; - Py_ssize_t __pyx_t_2; - Py_ssize_t __pyx_t_3; - Py_ssize_t __pyx_t_4; - __Pyx_TraceCall("_slice_assign_scalar", __pyx_f[1], 1403, 1, __PYX_ERR(1, 1403, __pyx_L1_error)); - - /* "View.MemoryView":1407 - * size_t itemsize, void *item) nogil: - * cdef Py_ssize_t i - * cdef Py_ssize_t stride = strides[0] # <<<<<<<<<<<<<< - * cdef Py_ssize_t extent = shape[0] - * - */ - __pyx_v_stride = (__pyx_v_strides[0]); - - /* "View.MemoryView":1408 - * cdef Py_ssize_t i - * cdef Py_ssize_t stride = strides[0] - * cdef Py_ssize_t extent = shape[0] # <<<<<<<<<<<<<< - * - * if ndim == 1: - */ - __pyx_v_extent = (__pyx_v_shape[0]); + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("convert_item_to_object", 0); + __Pyx_TraceCall("convert_item_to_object", __pyx_f[1], 974, 0, __PYX_ERR(1, 974, __pyx_L1_error)); - /* "View.MemoryView":1410 - * cdef Py_ssize_t extent = shape[0] + /* "View.MemoryView":975 * - * if ndim == 1: # <<<<<<<<<<<<<< - * for i in range(extent): - * memcpy(data, item, itemsize) + * cdef convert_item_to_object(self, char *itemp): + * if self.to_object_func != NULL: # <<<<<<<<<<<<<< + * return self.to_object_func(itemp) + * else: */ - __pyx_t_1 = ((__pyx_v_ndim == 1) != 0); + __pyx_t_1 = ((__pyx_v_self->to_object_func != NULL) != 0); if (__pyx_t_1) { - /* "View.MemoryView":1411 - * - * if ndim == 1: - * for i in range(extent): # <<<<<<<<<<<<<< - * memcpy(data, item, itemsize) - * data += stride - */ - __pyx_t_2 = __pyx_v_extent; - __pyx_t_3 = __pyx_t_2; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_i = __pyx_t_4; - - /* "View.MemoryView":1412 - * if ndim == 1: - * for i in range(extent): - * memcpy(data, item, itemsize) # <<<<<<<<<<<<<< - * data += stride - * else: - */ - (void)(memcpy(__pyx_v_data, __pyx_v_item, __pyx_v_itemsize)); - - /* "View.MemoryView":1413 - * for i in range(extent): - * memcpy(data, item, itemsize) - * data += stride # <<<<<<<<<<<<<< - * else: - * for i in range(extent): + /* "View.MemoryView":976 + * cdef convert_item_to_object(self, char *itemp): + * if self.to_object_func != NULL: + * return self.to_object_func(itemp) # <<<<<<<<<<<<<< + * else: + * return memoryview.convert_item_to_object(self, itemp) */ - __pyx_v_data = (__pyx_v_data + __pyx_v_stride); - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __pyx_v_self->to_object_func(__pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 976, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "View.MemoryView":1410 - * cdef Py_ssize_t extent = shape[0] + /* "View.MemoryView":975 * - * if ndim == 1: # <<<<<<<<<<<<<< - * for i in range(extent): - * memcpy(data, item, itemsize) + * cdef convert_item_to_object(self, char *itemp): + * if self.to_object_func != NULL: # <<<<<<<<<<<<<< + * return self.to_object_func(itemp) + * else: */ - goto __pyx_L3; } - /* "View.MemoryView":1415 - * data += stride - * else: - * for i in range(extent): # <<<<<<<<<<<<<< - * _slice_assign_scalar(data, shape + 1, strides + 1, - * ndim - 1, itemsize, item) - */ - /*else*/ { - __pyx_t_2 = __pyx_v_extent; - __pyx_t_3 = __pyx_t_2; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_i = __pyx_t_4; - - /* "View.MemoryView":1416 - * else: - * for i in range(extent): - * _slice_assign_scalar(data, shape + 1, strides + 1, # <<<<<<<<<<<<<< - * ndim - 1, itemsize, item) - * data += stride - */ - __pyx_memoryview__slice_assign_scalar(__pyx_v_data, (__pyx_v_shape + 1), (__pyx_v_strides + 1), (__pyx_v_ndim - 1), __pyx_v_itemsize, __pyx_v_item); - - /* "View.MemoryView":1418 - * _slice_assign_scalar(data, shape + 1, strides + 1, - * ndim - 1, itemsize, item) - * data += stride # <<<<<<<<<<<<<< - * + /* "View.MemoryView":978 + * return self.to_object_func(itemp) + * else: + * return memoryview.convert_item_to_object(self, itemp) # <<<<<<<<<<<<<< * + * cdef assign_item_from_object(self, char *itemp, object value): */ - __pyx_v_data = (__pyx_v_data + __pyx_v_stride); - } + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __pyx_memoryview_convert_item_to_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 978, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; } - __pyx_L3:; - /* "View.MemoryView":1403 + /* "View.MemoryView":974 + * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) * - * @cname('__pyx_memoryview__slice_assign_scalar') - * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< - * Py_ssize_t *strides, int ndim, - * size_t itemsize, void *item) nogil: + * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<< + * if self.to_object_func != NULL: + * return self.to_object_func(itemp) */ /* function exit code */ - goto __pyx_L0; __pyx_L1_error:; - __Pyx_WriteUnraisable("View.MemoryView._slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("View.MemoryView._memoryviewslice.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 1); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "(tree fragment)":1 - * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< - * if __pyx_checksum != 0xb068931: - * from pickle import PickleError as __pyx_PickleError +/* "View.MemoryView":980 + * return memoryview.convert_item_to_object(self, itemp) + * + * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< + * if self.to_dtype_func != NULL: + * self.to_dtype_func(itemp, value) */ -/* Python wrapper */ -static PyObject *__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyMethodDef __pyx_mdef_15View_dot_MemoryView_1__pyx_unpickle_Enum = {"__pyx_unpickle_Enum", (PyCFunction)__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum, METH_VARARGS|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v___pyx_type = 0; - long __pyx_v___pyx_checksum; - PyObject *__pyx_v___pyx_state = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__pyx_unpickle_Enum (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_Enum") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - } - __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) - __pyx_v___pyx_state = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_v___pyx_PickleError = NULL; - PyObject *__pyx_v___pyx_result = NULL; +static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; + int __pyx_t_2; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__60) - __Pyx_RefNannySetupContext("__pyx_unpickle_Enum", 0); - __Pyx_TraceCall("__pyx_unpickle_Enum", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_RefNannySetupContext("assign_item_from_object", 0); + __Pyx_TraceCall("assign_item_from_object", __pyx_f[1], 980, 0, __PYX_ERR(1, 980, __pyx_L1_error)); - /* "(tree fragment)":2 - * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): - * if __pyx_checksum != 0xb068931: # <<<<<<<<<<<<<< - * from pickle import PickleError as __pyx_PickleError - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + /* "View.MemoryView":981 + * + * cdef assign_item_from_object(self, char *itemp, object value): + * if self.to_dtype_func != NULL: # <<<<<<<<<<<<<< + * self.to_dtype_func(itemp, value) + * else: */ - __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xb068931) != 0); + __pyx_t_1 = ((__pyx_v_self->to_dtype_func != NULL) != 0); if (__pyx_t_1) { - /* "(tree fragment)":3 - * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): - * if __pyx_checksum != 0xb068931: - * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) - * __pyx_result = Enum.__new__(__pyx_type) - */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_PickleError); - __Pyx_GIVEREF(__pyx_n_s_PickleError); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_2); - __pyx_v___pyx_PickleError = __pyx_t_2; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "(tree fragment)":4 - * if __pyx_checksum != 0xb068931: - * from pickle import PickleError as __pyx_PickleError - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) # <<<<<<<<<<<<<< - * __pyx_result = Enum.__new__(__pyx_type) - * if __pyx_state is not None: + /* "View.MemoryView":982 + * cdef assign_item_from_object(self, char *itemp, object value): + * if self.to_dtype_func != NULL: + * self.to_dtype_func(itemp, value) # <<<<<<<<<<<<<< + * else: + * memoryview.assign_item_from_object(self, itemp, value) */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xb0, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_INCREF(__pyx_v___pyx_PickleError); - __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __pyx_v_self->to_dtype_func(__pyx_v_itemp, __pyx_v_value); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(1, 982, __pyx_L1_error) - /* "(tree fragment)":2 - * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): - * if __pyx_checksum != 0xb068931: # <<<<<<<<<<<<<< - * from pickle import PickleError as __pyx_PickleError - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + /* "View.MemoryView":981 + * + * cdef assign_item_from_object(self, char *itemp, object value): + * if self.to_dtype_func != NULL: # <<<<<<<<<<<<<< + * self.to_dtype_func(itemp, value) + * else: */ + goto __pyx_L3; } - /* "(tree fragment)":5 - * from pickle import PickleError as __pyx_PickleError - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) - * __pyx_result = Enum.__new__(__pyx_type) # <<<<<<<<<<<<<< - * if __pyx_state is not None: - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + /* "View.MemoryView":984 + * self.to_dtype_func(itemp, value) + * else: + * memoryview.assign_item_from_object(self, itemp, value) # <<<<<<<<<<<<<< + * + * @property */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_MemviewEnum_type), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + /*else*/ { + __pyx_t_3 = __pyx_memoryview_assign_item_from_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 984, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; - __Pyx_INCREF(__pyx_v___pyx_type); - __Pyx_GIVEREF(__pyx_v___pyx_type); - PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v___pyx_result = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_L3:; - /* "(tree fragment)":6 - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) - * __pyx_result = Enum.__new__(__pyx_type) - * if __pyx_state is not None: # <<<<<<<<<<<<<< - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - * return __pyx_result + /* "View.MemoryView":980 + * return memoryview.convert_item_to_object(self, itemp) + * + * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<< + * if self.to_dtype_func != NULL: + * self.to_dtype_func(itemp, value) */ - __pyx_t_1 = (__pyx_v___pyx_state != Py_None); - __pyx_t_7 = (__pyx_t_1 != 0); - if (__pyx_t_7) { - /* "(tree fragment)":7 - * __pyx_result = Enum.__new__(__pyx_type) - * if __pyx_state is not None: - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< - * return __pyx_result - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): - */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_unpickle_Enum__set_state(((struct __pyx_MemviewEnum_obj *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView._memoryviewslice.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "(tree fragment)":6 - * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) - * __pyx_result = Enum.__new__(__pyx_type) - * if __pyx_state is not None: # <<<<<<<<<<<<<< - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - * return __pyx_result +/* "View.MemoryView":987 + * + * @property + * def base(self): # <<<<<<<<<<<<<< + * return self.from_object + * */ - } - /* "(tree fragment)":8 - * if __pyx_state is not None: - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - * return __pyx_result # <<<<<<<<<<<<<< - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): - * __pyx_result.name = __pyx_state[0] +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 987, 0, __PYX_ERR(1, 987, __pyx_L1_error)); + + /* "View.MemoryView":988 + * @property + * def base(self): + * return self.from_object # <<<<<<<<<<<<<< + * + * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v___pyx_result); - __pyx_r = __pyx_v___pyx_result; + __Pyx_INCREF(__pyx_v_self->from_object); + __pyx_r = __pyx_v_self->from_object; goto __pyx_L0; - /* "(tree fragment)":1 - * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< - * if __pyx_checksum != 0xb068931: - * from pickle import PickleError as __pyx_PickleError + /* "View.MemoryView":987 + * + * @property + * def base(self): # <<<<<<<<<<<<<< + * return self.from_object + * */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("View.MemoryView._memoryviewslice.base.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v___pyx_PickleError); - __Pyx_XDECREF(__pyx_v___pyx_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":9 - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - * return __pyx_result - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< - * __pyx_result.name = __pyx_state[0] - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): */ -static PyObject *__pyx_unpickle_Enum__set_state(struct __pyx_MemviewEnum_obj *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { +/* Python wrapper */ +static PyObject *__pyx_pw___pyx_memoryviewslice_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw___pyx_memoryviewslice_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf___pyx_memoryviewslice___reduce_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_memoryviewslice___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - Py_ssize_t __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - __Pyx_RefNannySetupContext("__pyx_unpickle_Enum__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_Enum__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); - /* "(tree fragment)":10 - * return __pyx_result - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): - * __pyx_result.name = __pyx_state[0] # <<<<<<<<<<<<<< - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): - * __pyx_result.__dict__.update(__pyx_state[1]) + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) - } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__73, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v___pyx_result->name); - __Pyx_DECREF(__pyx_v___pyx_result->name); - __pyx_v___pyx_result->name = __pyx_t_1; - __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 2, __pyx_L1_error) - /* "(tree fragment)":11 - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): - * __pyx_result.name = __pyx_state[0] - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< - * __pyx_result.__dict__.update(__pyx_state[1]) + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): */ - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) - } - __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) - __pyx_t_4 = ((__pyx_t_3 > 1) != 0); - if (__pyx_t_4) { - } else { - __pyx_t_2 = __pyx_t_4; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) - __pyx_t_5 = (__pyx_t_4 != 0); - __pyx_t_2 = __pyx_t_5; - __pyx_L4_bool_binop_done:; - if (__pyx_t_2) { - /* "(tree fragment)":12 - * __pyx_result.name = __pyx_state[0] - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): - * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView._memoryviewslice.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(__pyx_v___pyx_state == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) - } - __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - if (!__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6); - __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "(tree fragment)":11 - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): - * __pyx_result.name = __pyx_state[0] - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< - * __pyx_result.__dict__.update(__pyx_state[1]) +/* Python wrapper */ +static PyObject *__pyx_pw___pyx_memoryviewslice_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw___pyx_memoryviewslice_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf___pyx_memoryviewslice_2__setstate_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf___pyx_memoryviewslice_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - } + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__74, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) - /* "(tree fragment)":9 - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - * return __pyx_result - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< - * __pyx_result.name = __pyx_state[0] - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; + __Pyx_AddTraceback("View.MemoryView._memoryviewslice.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment __pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment; - -static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment_AlignedSegment(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *p; - PyObject *o; - if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { - o = (*t->tp_alloc)(t, 0); - } else { - o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); - } - if (unlikely(!o)) return 0; - p = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)o); - p->__pyx_vtab = __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment; - p->_alignment_file = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None); - p->cache_query_qualities = Py_None; Py_INCREF(Py_None); - p->cache_query_alignment_qualities = Py_None; Py_INCREF(Py_None); - p->cache_query_sequence = Py_None; Py_INCREF(Py_None); - p->cache_query_alignment_sequence = Py_None; Py_INCREF(Py_None); - return o; -} -static void __pyx_tp_dealloc_5pysam_18libcalignedsegment_AlignedSegment(PyObject *o) { - struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *p = (struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)o; - #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { - if (PyObject_CallFinalizerFromDealloc(o)) return; - } - #endif - PyObject_GC_UnTrack(o); - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3__dealloc__(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - Py_CLEAR(p->_alignment_file); - Py_CLEAR(p->cache_query_qualities); - Py_CLEAR(p->cache_query_alignment_qualities); - Py_CLEAR(p->cache_query_sequence); - Py_CLEAR(p->cache_query_alignment_sequence); - (*Py_TYPE(o)->tp_free)(o); -} +/* "View.MemoryView":994 + * + * @cname('__pyx_memoryview_fromslice') + * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice, # <<<<<<<<<<<<<< + * int ndim, + * object (*to_object_func)(char *), + */ -static int __pyx_tp_traverse_5pysam_18libcalignedsegment_AlignedSegment(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *p = (struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)o; - if (p->_alignment_file) { - e = (*v)(((PyObject *)p->_alignment_file), a); if (e) return e; - } - if (p->cache_query_qualities) { - e = (*v)(p->cache_query_qualities, a); if (e) return e; - } - if (p->cache_query_alignment_qualities) { - e = (*v)(p->cache_query_alignment_qualities, a); if (e) return e; - } - if (p->cache_query_sequence) { - e = (*v)(p->cache_query_sequence, a); if (e) return e; - } - if (p->cache_query_alignment_sequence) { - e = (*v)(p->cache_query_alignment_sequence, a); if (e) return e; - } - return 0; -} +static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice __pyx_v_memviewslice, int __pyx_v_ndim, PyObject *(*__pyx_v_to_object_func)(char *), int (*__pyx_v_to_dtype_func)(char *, PyObject *), int __pyx_v_dtype_is_object) { + struct __pyx_memoryviewslice_obj *__pyx_v_result = 0; + Py_ssize_t __pyx_v_suboffset; + PyObject *__pyx_v_length = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_TypeInfo *__pyx_t_4; + Py_buffer __pyx_t_5; + Py_ssize_t *__pyx_t_6; + Py_ssize_t *__pyx_t_7; + Py_ssize_t *__pyx_t_8; + Py_ssize_t __pyx_t_9; + __Pyx_RefNannySetupContext("memoryview_fromslice", 0); + __Pyx_TraceCall("memoryview_fromslice", __pyx_f[1], 994, 0, __PYX_ERR(1, 994, __pyx_L1_error)); -static int __pyx_tp_clear_5pysam_18libcalignedsegment_AlignedSegment(PyObject *o) { - PyObject* tmp; - struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *p = (struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)o; - tmp = ((PyObject*)p->_alignment_file); - p->_alignment_file = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->cache_query_qualities); - p->cache_query_qualities = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->cache_query_alignment_qualities); - p->cache_query_alignment_qualities = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->cache_query_sequence); - p->cache_query_sequence = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->cache_query_alignment_sequence); - p->cache_query_alignment_sequence = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} + /* "View.MemoryView":1002 + * cdef _memoryviewslice result + * + * if memviewslice.memview == Py_None: # <<<<<<<<<<<<<< + * return None + * + */ + __pyx_t_1 = ((((PyObject *)__pyx_v_memviewslice.memview) == Py_None) != 0); + if (__pyx_t_1) { -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_name(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_1__get__(o); -} + /* "View.MemoryView":1003 + * + * if memviewslice.memview == Py_None: + * return None # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query_name(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1002 + * cdef _memoryviewslice result + * + * if memviewslice.memview == Py_None: # <<<<<<<<<<<<<< + * return None + * + */ } -} -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_flag(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4flag_1__get__(o); -} + /* "View.MemoryView":1008 + * + * + * result = _memoryviewslice(None, 0, dtype_is_object) # <<<<<<<<<<<<<< + * + * result.from_slice = memviewslice + */ + __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1008, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1008, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_3, 0, Py_None); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryviewslice_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1008, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_2); + __pyx_t_2 = 0; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_flag(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4flag_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1010 + * result = _memoryviewslice(None, 0, dtype_is_object) + * + * result.from_slice = memviewslice # <<<<<<<<<<<<<< + * __PYX_INC_MEMVIEW(&memviewslice, 1) + * + */ + __pyx_v_result->from_slice = __pyx_v_memviewslice; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_name(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name_1__get__(o); -} + /* "View.MemoryView":1011 + * + * result.from_slice = memviewslice + * __PYX_INC_MEMVIEW(&memviewslice, 1) # <<<<<<<<<<<<<< + * + * result.from_object = ( memviewslice.memview).base + */ + __PYX_INC_MEMVIEW((&__pyx_v_memviewslice), 1); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_id(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_1__get__(o); -} + /* "View.MemoryView":1013 + * __PYX_INC_MEMVIEW(&memviewslice, 1) + * + * result.from_object = ( memviewslice.memview).base # <<<<<<<<<<<<<< + * result.typeinfo = memviewslice.memview.typeinfo + * + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_memviewslice.memview), __pyx_n_s_base); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1013, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_v_result->from_object); + __Pyx_DECREF(__pyx_v_result->from_object); + __pyx_v_result->from_object = __pyx_t_2; + __pyx_t_2 = 0; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_id(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1014 + * + * result.from_object = ( memviewslice.memview).base + * result.typeinfo = memviewslice.memview.typeinfo # <<<<<<<<<<<<<< + * + * result.view = memviewslice.memview.view + */ + __pyx_t_4 = __pyx_v_memviewslice.memview->typeinfo; + __pyx_v_result->__pyx_base.typeinfo = __pyx_t_4; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_start(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_1__get__(o); -} + /* "View.MemoryView":1016 + * result.typeinfo = memviewslice.memview.typeinfo + * + * result.view = memviewslice.memview.view # <<<<<<<<<<<<<< + * result.view.buf = memviewslice.data + * result.view.ndim = ndim + */ + __pyx_t_5 = __pyx_v_memviewslice.memview->view; + __pyx_v_result->__pyx_base.view = __pyx_t_5; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_start(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1017 + * + * result.view = memviewslice.memview.view + * result.view.buf = memviewslice.data # <<<<<<<<<<<<<< + * result.view.ndim = ndim + * (<__pyx_buffer *> &result.view).obj = Py_None + */ + __pyx_v_result->__pyx_base.view.buf = ((void *)__pyx_v_memviewslice.data); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mapping_quality(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_1__get__(o); -} + /* "View.MemoryView":1018 + * result.view = memviewslice.memview.view + * result.view.buf = memviewslice.data + * result.view.ndim = ndim # <<<<<<<<<<<<<< + * (<__pyx_buffer *> &result.view).obj = Py_None + * Py_INCREF(Py_None) + */ + __pyx_v_result->__pyx_base.view.ndim = __pyx_v_ndim; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mapping_quality(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1019 + * result.view.buf = memviewslice.data + * result.view.ndim = ndim + * (<__pyx_buffer *> &result.view).obj = Py_None # <<<<<<<<<<<<<< + * Py_INCREF(Py_None) + * + */ + ((Py_buffer *)(&__pyx_v_result->__pyx_base.view))->obj = Py_None; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_cigarstring(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_1__get__(o); -} + /* "View.MemoryView":1020 + * result.view.ndim = ndim + * (<__pyx_buffer *> &result.view).obj = Py_None + * Py_INCREF(Py_None) # <<<<<<<<<<<<<< + * + * if (memviewslice.memview).flags & PyBUF_WRITABLE: + */ + Py_INCREF(Py_None); -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_cigarstring(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1022 + * Py_INCREF(Py_None) + * + * if (memviewslice.memview).flags & PyBUF_WRITABLE: # <<<<<<<<<<<<<< + * result.flags = PyBUF_RECORDS + * else: + */ + __pyx_t_1 = ((((struct __pyx_memoryview_obj *)__pyx_v_memviewslice.memview)->flags & PyBUF_WRITABLE) != 0); + if (__pyx_t_1) { -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_id(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_1__get__(o); -} + /* "View.MemoryView":1023 + * + * if (memviewslice.memview).flags & PyBUF_WRITABLE: + * result.flags = PyBUF_RECORDS # <<<<<<<<<<<<<< + * else: + * result.flags = PyBUF_RECORDS_RO + */ + __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_id(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_3__set__(o, v); + /* "View.MemoryView":1022 + * Py_INCREF(Py_None) + * + * if (memviewslice.memview).flags & PyBUF_WRITABLE: # <<<<<<<<<<<<<< + * result.flags = PyBUF_RECORDS + * else: + */ + goto __pyx_L4; } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + + /* "View.MemoryView":1025 + * result.flags = PyBUF_RECORDS + * else: + * result.flags = PyBUF_RECORDS_RO # <<<<<<<<<<<<<< + * + * result.view.shape = result.from_slice.shape + */ + /*else*/ { + __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS_RO; } -} + __pyx_L4:; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_name(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name_1__get__(o); -} + /* "View.MemoryView":1027 + * result.flags = PyBUF_RECORDS_RO + * + * result.view.shape = result.from_slice.shape # <<<<<<<<<<<<<< + * result.view.strides = result.from_slice.strides + * + */ + __pyx_v_result->__pyx_base.view.shape = ((Py_ssize_t *)__pyx_v_result->from_slice.shape); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_start(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_1__get__(o); -} + /* "View.MemoryView":1028 + * + * result.view.shape = result.from_slice.shape + * result.view.strides = result.from_slice.strides # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_result->__pyx_base.view.strides = ((Py_ssize_t *)__pyx_v_result->from_slice.strides); -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_start(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1031 + * + * + * result.view.suboffsets = NULL # <<<<<<<<<<<<<< + * for suboffset in result.from_slice.suboffsets[:ndim]: + * if suboffset >= 0: + */ + __pyx_v_result->__pyx_base.view.suboffsets = NULL; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_length(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12query_length_1__get__(o); -} + /* "View.MemoryView":1032 + * + * result.view.suboffsets = NULL + * for suboffset in result.from_slice.suboffsets[:ndim]: # <<<<<<<<<<<<<< + * if suboffset >= 0: + * result.view.suboffsets = result.from_slice.suboffsets + */ + __pyx_t_7 = (__pyx_v_result->from_slice.suboffsets + __pyx_v_ndim); + for (__pyx_t_8 = __pyx_v_result->from_slice.suboffsets; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) { + __pyx_t_6 = __pyx_t_8; + __pyx_v_suboffset = (__pyx_t_6[0]); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_template_length(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_1__get__(o); -} + /* "View.MemoryView":1033 + * result.view.suboffsets = NULL + * for suboffset in result.from_slice.suboffsets[:ndim]: + * if suboffset >= 0: # <<<<<<<<<<<<<< + * result.view.suboffsets = result.from_slice.suboffsets + * break + */ + __pyx_t_1 = ((__pyx_v_suboffset >= 0) != 0); + if (__pyx_t_1) { -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_template_length(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1034 + * for suboffset in result.from_slice.suboffsets[:ndim]: + * if suboffset >= 0: + * result.view.suboffsets = result.from_slice.suboffsets # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_result->__pyx_base.view.suboffsets = ((Py_ssize_t *)__pyx_v_result->from_slice.suboffsets); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_sequence(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_1__get__(o); -} + /* "View.MemoryView":1035 + * if suboffset >= 0: + * result.view.suboffsets = result.from_slice.suboffsets + * break # <<<<<<<<<<<<<< + * + * result.view.len = result.view.itemsize + */ + goto __pyx_L6_break; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query_sequence(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1033 + * result.view.suboffsets = NULL + * for suboffset in result.from_slice.suboffsets[:ndim]: + * if suboffset >= 0: # <<<<<<<<<<<<<< + * result.view.suboffsets = result.from_slice.suboffsets + * break + */ + } } -} - -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_qualities(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_1__get__(o); -} + __pyx_L6_break:; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query_qualities(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1037 + * break + * + * result.view.len = result.view.itemsize # <<<<<<<<<<<<<< + * for length in result.view.shape[:ndim]: + * result.view.len *= length + */ + __pyx_t_9 = __pyx_v_result->__pyx_base.view.itemsize; + __pyx_v_result->__pyx_base.view.len = __pyx_t_9; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_bin(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3bin_1__get__(o); -} + /* "View.MemoryView":1038 + * + * result.view.len = result.view.itemsize + * for length in result.view.shape[:ndim]: # <<<<<<<<<<<<<< + * result.view.len *= length + * + */ + __pyx_t_7 = (__pyx_v_result->__pyx_base.view.shape + __pyx_v_ndim); + for (__pyx_t_8 = __pyx_v_result->__pyx_base.view.shape; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) { + __pyx_t_6 = __pyx_t_8; + __pyx_t_2 = PyInt_FromSsize_t((__pyx_t_6[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1038, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_2); + __pyx_t_2 = 0; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_bin(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3bin_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1039 + * result.view.len = result.view.itemsize + * for length in result.view.shape[:ndim]: + * result.view.len *= length # <<<<<<<<<<<<<< + * + * result.to_object_func = to_object_func + */ + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_result->__pyx_base.view.len); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1039, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_InPlaceMultiply(__pyx_t_2, __pyx_v_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1039, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 1039, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_result->__pyx_base.view.len = __pyx_t_9; } -} - -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_paired(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_1__get__(o); -} -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_paired(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1041 + * result.view.len *= length + * + * result.to_object_func = to_object_func # <<<<<<<<<<<<<< + * result.to_dtype_func = to_dtype_func + * + */ + __pyx_v_result->to_object_func = __pyx_v_to_object_func; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_proper_pair(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_1__get__(o); -} + /* "View.MemoryView":1042 + * + * result.to_object_func = to_object_func + * result.to_dtype_func = to_dtype_func # <<<<<<<<<<<<<< + * + * return result + */ + __pyx_v_result->to_dtype_func = __pyx_v_to_dtype_func; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_proper_pair(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1044 + * result.to_dtype_func = to_dtype_func + * + * return result # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_get_slice_from_memoryview') + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_unmapped(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_1__get__(o); -} + /* "View.MemoryView":994 + * + * @cname('__pyx_memoryview_fromslice') + * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice, # <<<<<<<<<<<<<< + * int ndim, + * object (*to_object_func)(char *), + */ -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_unmapped(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("View.MemoryView.memoryview_fromslice", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XDECREF(__pyx_v_length); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_unmapped(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_1__get__(o); -} +/* "View.MemoryView":1047 + * + * @cname('__pyx_memoryview_get_slice_from_memoryview') + * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview, # <<<<<<<<<<<<<< + * __Pyx_memviewslice *mslice): + * cdef _memoryviewslice obj + */ -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_unmapped(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} +static __Pyx_memviewslice *__pyx_memoryview_get_slice_from_memoryview(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_mslice) { + struct __pyx_memoryviewslice_obj *__pyx_v_obj = 0; + __Pyx_memviewslice *__pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("get_slice_from_memview", 0); + __Pyx_TraceCall("get_slice_from_memview", __pyx_f[1], 1047, 0, __PYX_ERR(1, 1047, __pyx_L1_error)); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_reverse(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_1__get__(o); -} + /* "View.MemoryView":1050 + * __Pyx_memviewslice *mslice): + * cdef _memoryviewslice obj + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * obj = memview + * return &obj.from_slice + */ + __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_reverse(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1051 + * cdef _memoryviewslice obj + * if isinstance(memview, _memoryviewslice): + * obj = memview # <<<<<<<<<<<<<< + * return &obj.from_slice + * else: + */ + if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(1, 1051, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_v_memview); + __Pyx_INCREF(__pyx_t_3); + __pyx_v_obj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3); + __pyx_t_3 = 0; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_reverse(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_1__get__(o); -} + /* "View.MemoryView":1052 + * if isinstance(memview, _memoryviewslice): + * obj = memview + * return &obj.from_slice # <<<<<<<<<<<<<< + * else: + * slice_copy(memview, mslice) + */ + __pyx_r = (&__pyx_v_obj->from_slice); + goto __pyx_L0; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_reverse(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1050 + * __Pyx_memviewslice *mslice): + * cdef _memoryviewslice obj + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * obj = memview + * return &obj.from_slice + */ } -} -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read1(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_1__get__(o); -} + /* "View.MemoryView":1054 + * return &obj.from_slice + * else: + * slice_copy(memview, mslice) # <<<<<<<<<<<<<< + * return mslice + * + */ + /*else*/ { + __pyx_memoryview_slice_copy(__pyx_v_memview, __pyx_v_mslice); -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read1(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1055 + * else: + * slice_copy(memview, mslice) + * return mslice # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_slice_copy') + */ + __pyx_r = __pyx_v_mslice; + goto __pyx_L0; } -} -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read2(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_1__get__(o); -} + /* "View.MemoryView":1047 + * + * @cname('__pyx_memoryview_get_slice_from_memoryview') + * cdef __Pyx_memviewslice *get_slice_from_memview(memoryview memview, # <<<<<<<<<<<<<< + * __Pyx_memviewslice *mslice): + * cdef _memoryviewslice obj + */ -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read2(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_WriteUnraisable("View.MemoryView.get_slice_from_memview", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_obj); + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_secondary(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_1__get__(o); -} +/* "View.MemoryView":1058 + * + * @cname('__pyx_memoryview_slice_copy') + * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst): # <<<<<<<<<<<<<< + * cdef int dim + * cdef (Py_ssize_t*) shape, strides, suboffsets + */ -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_secondary(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} +static void __pyx_memoryview_slice_copy(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_dst) { + int __pyx_v_dim; + Py_ssize_t *__pyx_v_shape; + Py_ssize_t *__pyx_v_strides; + Py_ssize_t *__pyx_v_suboffsets; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + Py_ssize_t *__pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + __Pyx_RefNannySetupContext("slice_copy", 0); + __Pyx_TraceCall("slice_copy", __pyx_f[1], 1058, 0, __PYX_ERR(1, 1058, __pyx_L1_error)); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_qcfail(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_1__get__(o); -} + /* "View.MemoryView":1062 + * cdef (Py_ssize_t*) shape, strides, suboffsets + * + * shape = memview.view.shape # <<<<<<<<<<<<<< + * strides = memview.view.strides + * suboffsets = memview.view.suboffsets + */ + __pyx_t_1 = __pyx_v_memview->view.shape; + __pyx_v_shape = __pyx_t_1; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_qcfail(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1063 + * + * shape = memview.view.shape + * strides = memview.view.strides # <<<<<<<<<<<<<< + * suboffsets = memview.view.suboffsets + * + */ + __pyx_t_1 = __pyx_v_memview->view.strides; + __pyx_v_strides = __pyx_t_1; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_duplicate(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_1__get__(o); -} + /* "View.MemoryView":1064 + * shape = memview.view.shape + * strides = memview.view.strides + * suboffsets = memview.view.suboffsets # <<<<<<<<<<<<<< + * + * dst.memview = <__pyx_memoryview *> memview + */ + __pyx_t_1 = __pyx_v_memview->view.suboffsets; + __pyx_v_suboffsets = __pyx_t_1; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_duplicate(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1066 + * suboffsets = memview.view.suboffsets + * + * dst.memview = <__pyx_memoryview *> memview # <<<<<<<<<<<<<< + * dst.data = memview.view.buf + * + */ + __pyx_v_dst->memview = ((struct __pyx_memoryview_obj *)__pyx_v_memview); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_supplementary(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_1__get__(o); -} + /* "View.MemoryView":1067 + * + * dst.memview = <__pyx_memoryview *> memview + * dst.data = memview.view.buf # <<<<<<<<<<<<<< + * + * for dim in range(memview.view.ndim): + */ + __pyx_v_dst->data = ((char *)__pyx_v_memview->view.buf); -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_supplementary(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1069 + * dst.data = memview.view.buf + * + * for dim in range(memview.view.ndim): # <<<<<<<<<<<<<< + * dst.shape[dim] = shape[dim] + * dst.strides[dim] = strides[dim] + */ + __pyx_t_2 = __pyx_v_memview->view.ndim; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_dim = __pyx_t_4; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_end(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13reference_end_1__get__(o); -} + /* "View.MemoryView":1070 + * + * for dim in range(memview.view.ndim): + * dst.shape[dim] = shape[dim] # <<<<<<<<<<<<<< + * dst.strides[dim] = strides[dim] + * dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1 + */ + (__pyx_v_dst->shape[__pyx_v_dim]) = (__pyx_v_shape[__pyx_v_dim]); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_length(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16reference_length_1__get__(o); -} + /* "View.MemoryView":1071 + * for dim in range(memview.view.ndim): + * dst.shape[dim] = shape[dim] + * dst.strides[dim] = strides[dim] # <<<<<<<<<<<<<< + * dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1 + * + */ + (__pyx_v_dst->strides[__pyx_v_dim]) = (__pyx_v_strides[__pyx_v_dim]); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_sequence(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_24query_alignment_sequence_1__get__(o); -} + /* "View.MemoryView":1072 + * dst.shape[dim] = shape[dim] + * dst.strides[dim] = strides[dim] + * dst.suboffsets[dim] = suboffsets[dim] if suboffsets else -1 # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_copy_object') + */ + if ((__pyx_v_suboffsets != 0)) { + __pyx_t_5 = (__pyx_v_suboffsets[__pyx_v_dim]); + } else { + __pyx_t_5 = -1L; + } + (__pyx_v_dst->suboffsets[__pyx_v_dim]) = __pyx_t_5; + } -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_qualities(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_25query_alignment_qualities_1__get__(o); -} + /* "View.MemoryView":1058 + * + * @cname('__pyx_memoryview_slice_copy') + * cdef void slice_copy(memoryview memview, __Pyx_memviewslice *dst): # <<<<<<<<<<<<<< + * cdef int dim + * cdef (Py_ssize_t*) shape, strides, suboffsets + */ -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_start(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21query_alignment_start_1__get__(o); + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView.slice_copy", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); } -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_end(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19query_alignment_end_1__get__(o); -} +/* "View.MemoryView":1075 + * + * @cname('__pyx_memoryview_copy_object') + * cdef memoryview_copy(memoryview memview): # <<<<<<<<<<<<<< + * "Create a new memoryview object" + * cdef __Pyx_memviewslice memviewslice + */ -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_length(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_22query_alignment_length_1__get__(o); -} +static PyObject *__pyx_memoryview_copy_object(struct __pyx_memoryview_obj *__pyx_v_memview) { + __Pyx_memviewslice __pyx_v_memviewslice; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("memoryview_copy", 0); + __Pyx_TraceCall("memoryview_copy", __pyx_f[1], 1075, 0, __PYX_ERR(1, 1075, __pyx_L1_error)); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_cigartuples(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_1__get__(o); -} + /* "View.MemoryView":1078 + * "Create a new memoryview object" + * cdef __Pyx_memviewslice memviewslice + * slice_copy(memview, &memviewslice) # <<<<<<<<<<<<<< + * return memoryview_copy_from_slice(memview, &memviewslice) + * + */ + __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_memviewslice)); -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_cigartuples(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1079 + * cdef __Pyx_memviewslice memviewslice + * slice_copy(memview, &memviewslice) + * return memoryview_copy_from_slice(memview, &memviewslice) # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_copy_object_from_slice') + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __pyx_memoryview_copy_object_from_slice(__pyx_v_memview, (&__pyx_v_memviewslice)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1079, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qname(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qname_1__get__(o); -} + /* "View.MemoryView":1075 + * + * @cname('__pyx_memoryview_copy_object') + * cdef memoryview_copy(memoryview memview): # <<<<<<<<<<<<<< + * "Create a new memoryview object" + * cdef __Pyx_memviewslice memviewslice + */ -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qname(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qname_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("View.MemoryView.memoryview_copy", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_tid(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3tid_1__get__(o); -} +/* "View.MemoryView":1082 + * + * @cname('__pyx_memoryview_copy_object_from_slice') + * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice): # <<<<<<<<<<<<<< + * """ + * Create a new memoryview object from a given memoryview object and slice. + */ -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_tid(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3tid_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} +static PyObject *__pyx_memoryview_copy_object_from_slice(struct __pyx_memoryview_obj *__pyx_v_memview, __Pyx_memviewslice *__pyx_v_memviewslice) { + PyObject *(*__pyx_v_to_object_func)(char *); + int (*__pyx_v_to_dtype_func)(char *, PyObject *); + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *(*__pyx_t_3)(char *); + int (*__pyx_t_4)(char *, PyObject *); + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("memoryview_copy_from_slice", 0); + __Pyx_TraceCall("memoryview_copy_from_slice", __pyx_f[1], 1082, 0, __PYX_ERR(1, 1082, __pyx_L1_error)); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_pos(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3pos_1__get__(o); -} + /* "View.MemoryView":1089 + * cdef int (*to_dtype_func)(char *, object) except 0 + * + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * to_object_func = (<_memoryviewslice> memview).to_object_func + * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func + */ + __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_pos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3pos_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1090 + * + * if isinstance(memview, _memoryviewslice): + * to_object_func = (<_memoryviewslice> memview).to_object_func # <<<<<<<<<<<<<< + * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func + * else: + */ + __pyx_t_3 = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_object_func; + __pyx_v_to_object_func = __pyx_t_3; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mapq(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_1__get__(o); -} + /* "View.MemoryView":1091 + * if isinstance(memview, _memoryviewslice): + * to_object_func = (<_memoryviewslice> memview).to_object_func + * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func # <<<<<<<<<<<<<< + * else: + * to_object_func = NULL + */ + __pyx_t_4 = ((struct __pyx_memoryviewslice_obj *)__pyx_v_memview)->to_dtype_func; + __pyx_v_to_dtype_func = __pyx_t_4; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mapq(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1089 + * cdef int (*to_dtype_func)(char *, object) except 0 + * + * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<< + * to_object_func = (<_memoryviewslice> memview).to_object_func + * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func + */ + goto __pyx_L3; } -} -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_rnext(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_1__get__(o); -} + /* "View.MemoryView":1093 + * to_dtype_func = (<_memoryviewslice> memview).to_dtype_func + * else: + * to_object_func = NULL # <<<<<<<<<<<<<< + * to_dtype_func = NULL + * + */ + /*else*/ { + __pyx_v_to_object_func = NULL; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_rnext(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1094 + * else: + * to_object_func = NULL + * to_dtype_func = NULL # <<<<<<<<<<<<<< + * + * return memoryview_fromslice(memviewslice[0], memview.view.ndim, + */ + __pyx_v_to_dtype_func = NULL; } -} - -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_pnext(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_1__get__(o); -} + __pyx_L3:; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_pnext(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1096 + * to_dtype_func = NULL + * + * return memoryview_fromslice(memviewslice[0], memview.view.ndim, # <<<<<<<<<<<<<< + * to_object_func, to_dtype_func, + * memview.dtype_is_object) + */ + __Pyx_XDECREF(__pyx_r); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_cigar(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_1__get__(o); -} + /* "View.MemoryView":1098 + * return memoryview_fromslice(memviewslice[0], memview.view.ndim, + * to_object_func, to_dtype_func, + * memview.dtype_is_object) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_5 = __pyx_memoryview_fromslice((__pyx_v_memviewslice[0]), __pyx_v_memview->view.ndim, __pyx_v_to_object_func, __pyx_v_to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 1096, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_cigar(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1082 + * + * @cname('__pyx_memoryview_copy_object_from_slice') + * cdef memoryview_copy_from_slice(memoryview memview, __Pyx_memviewslice *memviewslice): # <<<<<<<<<<<<<< + * """ + * Create a new memoryview object from a given memoryview object and slice. + */ -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_tlen(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_1__get__(o); + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView.memoryview_copy_from_slice", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_tlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} +/* "View.MemoryView":1104 + * + * + * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: # <<<<<<<<<<<<<< + * if arg < 0: + * return -arg + */ -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_seq(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3seq_1__get__(o); -} +static Py_ssize_t abs_py_ssize_t(Py_ssize_t __pyx_v_arg) { + Py_ssize_t __pyx_r; + __Pyx_TraceDeclarations + int __pyx_t_1; + __Pyx_TraceCall("abs_py_ssize_t", __pyx_f[1], 1104, 1, __PYX_ERR(1, 1104, __pyx_L1_error)); -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_seq(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3seq_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1105 + * + * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: + * if arg < 0: # <<<<<<<<<<<<<< + * return -arg + * else: + */ + __pyx_t_1 = ((__pyx_v_arg < 0) != 0); + if (__pyx_t_1) { -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qual(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qual_1__get__(o); -} + /* "View.MemoryView":1106 + * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: + * if arg < 0: + * return -arg # <<<<<<<<<<<<<< + * else: + * return arg + */ + __pyx_r = (-__pyx_v_arg); + goto __pyx_L0; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qual(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qual_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1105 + * + * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: + * if arg < 0: # <<<<<<<<<<<<<< + * return -arg + * else: + */ } -} - -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_alen(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4alen_1__get__(o); -} -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_alen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4alen_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1108 + * return -arg + * else: + * return arg # <<<<<<<<<<<<<< + * + * @cname('__pyx_get_best_slice_order') + */ + /*else*/ { + __pyx_r = __pyx_v_arg; + goto __pyx_L0; } -} - -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_aend(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4aend_1__get__(o); -} -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_aend(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4aend_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1104 + * + * + * cdef Py_ssize_t abs_py_ssize_t(Py_ssize_t arg) nogil: # <<<<<<<<<<<<<< + * if arg < 0: + * return -arg + */ -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_rlen(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_1__get__(o); + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView.abs_py_ssize_t", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 1); + return __pyx_r; } -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_rlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} +/* "View.MemoryView":1111 + * + * @cname('__pyx_get_best_slice_order') + * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil: # <<<<<<<<<<<<<< + * """ + * Figure out the best memory access order for a given slice. + */ -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5query_1__get__(o); -} +static char __pyx_get_best_slice_order(__Pyx_memviewslice *__pyx_v_mslice, int __pyx_v_ndim) { + int __pyx_v_i; + Py_ssize_t __pyx_v_c_stride; + Py_ssize_t __pyx_v_f_stride; + char __pyx_r; + __Pyx_TraceDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_TraceCall("get_best_order", __pyx_f[1], 1111, 1, __PYX_ERR(1, 1111, __pyx_L1_error)); -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5query_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1116 + * """ + * cdef int i + * cdef Py_ssize_t c_stride = 0 # <<<<<<<<<<<<<< + * cdef Py_ssize_t f_stride = 0 + * + */ + __pyx_v_c_stride = 0; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qqual(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_1__get__(o); -} + /* "View.MemoryView":1117 + * cdef int i + * cdef Py_ssize_t c_stride = 0 + * cdef Py_ssize_t f_stride = 0 # <<<<<<<<<<<<<< + * + * for i in range(ndim - 1, -1, -1): + */ + __pyx_v_f_stride = 0; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qqual(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1119 + * cdef Py_ssize_t f_stride = 0 + * + * for i in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< + * if mslice.shape[i] > 1: + * c_stride = mslice.strides[i] + */ + for (__pyx_t_1 = (__pyx_v_ndim - 1); __pyx_t_1 > -1; __pyx_t_1-=1) { + __pyx_v_i = __pyx_t_1; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qstart(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_1__get__(o); -} + /* "View.MemoryView":1120 + * + * for i in range(ndim - 1, -1, -1): + * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< + * c_stride = mslice.strides[i] + * break + */ + __pyx_t_2 = (((__pyx_v_mslice->shape[__pyx_v_i]) > 1) != 0); + if (__pyx_t_2) { -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qstart(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1121 + * for i in range(ndim - 1, -1, -1): + * if mslice.shape[i] > 1: + * c_stride = mslice.strides[i] # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_c_stride = (__pyx_v_mslice->strides[__pyx_v_i]); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qend(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qend_1__get__(o); -} + /* "View.MemoryView":1122 + * if mslice.shape[i] > 1: + * c_stride = mslice.strides[i] + * break # <<<<<<<<<<<<<< + * + * for i in range(ndim): + */ + goto __pyx_L4_break; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qend(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qend_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1120 + * + * for i in range(ndim - 1, -1, -1): + * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< + * c_stride = mslice.strides[i] + * break + */ + } } -} - -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qlen(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_1__get__(o); -} + __pyx_L4_break:; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1124 + * break + * + * for i in range(ndim): # <<<<<<<<<<<<<< + * if mslice.shape[i] > 1: + * f_stride = mslice.strides[i] + */ + __pyx_t_1 = __pyx_v_ndim; + __pyx_t_3 = __pyx_t_1; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mrnm(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_1__get__(o); -} + /* "View.MemoryView":1125 + * + * for i in range(ndim): + * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< + * f_stride = mslice.strides[i] + * break + */ + __pyx_t_2 = (((__pyx_v_mslice->shape[__pyx_v_i]) > 1) != 0); + if (__pyx_t_2) { -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mrnm(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1126 + * for i in range(ndim): + * if mslice.shape[i] > 1: + * f_stride = mslice.strides[i] # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_f_stride = (__pyx_v_mslice->strides[__pyx_v_i]); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mpos(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_1__get__(o); -} + /* "View.MemoryView":1127 + * if mslice.shape[i] > 1: + * f_stride = mslice.strides[i] + * break # <<<<<<<<<<<<<< + * + * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): + */ + goto __pyx_L7_break; -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mpos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1125 + * + * for i in range(ndim): + * if mslice.shape[i] > 1: # <<<<<<<<<<<<<< + * f_stride = mslice.strides[i] + * break + */ + } } -} + __pyx_L7_break:; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_rname(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rname_1__get__(o); -} + /* "View.MemoryView":1129 + * break + * + * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): # <<<<<<<<<<<<<< + * return 'C' + * else: + */ + __pyx_t_2 = ((abs_py_ssize_t(__pyx_v_c_stride) <= abs_py_ssize_t(__pyx_v_f_stride)) != 0); + if (__pyx_t_2) { -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_rname(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rname_3__set__(o, v); + /* "View.MemoryView":1130 + * + * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): + * return 'C' # <<<<<<<<<<<<<< + * else: + * return 'F' + */ + __pyx_r = 'C'; + goto __pyx_L0; + + /* "View.MemoryView":1129 + * break + * + * if abs_py_ssize_t(c_stride) <= abs_py_ssize_t(f_stride): # <<<<<<<<<<<<<< + * return 'C' + * else: + */ } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + + /* "View.MemoryView":1132 + * return 'C' + * else: + * return 'F' # <<<<<<<<<<<<<< + * + * @cython.cdivision(True) + */ + /*else*/ { + __pyx_r = 'F'; + goto __pyx_L0; } -} -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_isize(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5isize_1__get__(o); -} + /* "View.MemoryView":1111 + * + * @cname('__pyx_get_best_slice_order') + * cdef char get_best_order(__Pyx_memviewslice *mslice, int ndim) nogil: # <<<<<<<<<<<<<< + * """ + * Figure out the best memory access order for a given slice. + */ -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_isize(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5isize_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView.get_best_order", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 1); + return __pyx_r; } -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_blocks(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6blocks_1__get__(o); -} +/* "View.MemoryView":1135 + * + * @cython.cdivision(True) + * cdef void _copy_strided_to_strided(char *src_data, Py_ssize_t *src_strides, # <<<<<<<<<<<<<< + * char *dst_data, Py_ssize_t *dst_strides, + * Py_ssize_t *src_shape, Py_ssize_t *dst_shape, + */ -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_aligned_pairs(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13aligned_pairs_1__get__(o); -} +static void _copy_strided_to_strided(char *__pyx_v_src_data, Py_ssize_t *__pyx_v_src_strides, char *__pyx_v_dst_data, Py_ssize_t *__pyx_v_dst_strides, Py_ssize_t *__pyx_v_src_shape, Py_ssize_t *__pyx_v_dst_shape, int __pyx_v_ndim, size_t __pyx_v_itemsize) { + CYTHON_UNUSED Py_ssize_t __pyx_v_i; + CYTHON_UNUSED Py_ssize_t __pyx_v_src_extent; + Py_ssize_t __pyx_v_dst_extent; + Py_ssize_t __pyx_v_src_stride; + Py_ssize_t __pyx_v_dst_stride; + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + Py_ssize_t __pyx_t_5; + Py_ssize_t __pyx_t_6; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_inferred_length(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15inferred_length_1__get__(o); -} + /* "View.MemoryView":1142 + * + * cdef Py_ssize_t i + * cdef Py_ssize_t src_extent = src_shape[0] # <<<<<<<<<<<<<< + * cdef Py_ssize_t dst_extent = dst_shape[0] + * cdef Py_ssize_t src_stride = src_strides[0] + */ + __pyx_v_src_extent = (__pyx_v_src_shape[0]); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_positions(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9positions_1__get__(o); -} + /* "View.MemoryView":1143 + * cdef Py_ssize_t i + * cdef Py_ssize_t src_extent = src_shape[0] + * cdef Py_ssize_t dst_extent = dst_shape[0] # <<<<<<<<<<<<<< + * cdef Py_ssize_t src_stride = src_strides[0] + * cdef Py_ssize_t dst_stride = dst_strides[0] + */ + __pyx_v_dst_extent = (__pyx_v_dst_shape[0]); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_tags(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tags_1__get__(o); -} + /* "View.MemoryView":1144 + * cdef Py_ssize_t src_extent = src_shape[0] + * cdef Py_ssize_t dst_extent = dst_shape[0] + * cdef Py_ssize_t src_stride = src_strides[0] # <<<<<<<<<<<<<< + * cdef Py_ssize_t dst_stride = dst_strides[0] + * + */ + __pyx_v_src_stride = (__pyx_v_src_strides[0]); -static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_tags(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tags_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1145 + * cdef Py_ssize_t dst_extent = dst_shape[0] + * cdef Py_ssize_t src_stride = src_strides[0] + * cdef Py_ssize_t dst_stride = dst_strides[0] # <<<<<<<<<<<<<< + * + * if ndim == 1: + */ + __pyx_v_dst_stride = (__pyx_v_dst_strides[0]); -static PyMethodDef __pyx_methods_5pysam_18libcalignedsegment_AlignedSegment[] = { - {"__copy__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_7__copy__, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_6__copy__}, - {"__deepcopy__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9__deepcopy__, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_8__deepcopy__}, - {"compare", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11compare, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_10compare}, - {"tostring", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17tostring, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_16tostring}, - {"get_reference_positions", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19get_reference_positions, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_18get_reference_positions}, - {"infer_query_length", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21infer_query_length, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_20infer_query_length}, - {"get_reference_sequence", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_23get_reference_sequence, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_22get_reference_sequence}, - {"get_aligned_pairs", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_25get_aligned_pairs, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_24get_aligned_pairs}, - {"get_blocks", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_27get_blocks, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_26get_blocks}, - {"get_overlap", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_29get_overlap, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_28get_overlap}, - {"get_cigar_stats", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_31get_cigar_stats, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_30get_cigar_stats}, - {"set_tag", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_33set_tag, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_32set_tag}, - {"has_tag", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_35has_tag, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_34has_tag}, - {"get_tag", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_37get_tag, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_36get_tag}, - {"get_tags", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_39get_tags, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_38get_tags}, - {"set_tags", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_41set_tags, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_40set_tags}, - {"overlap", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_43overlap, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_42overlap}, - {"opt", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_45opt, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_44opt}, - {"setTag", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_47setTag, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_46setTag}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_49__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_48__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_51__setstate_cython__, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_50__setstate_cython__}, - {0, 0, 0, 0} -}; + /* "View.MemoryView":1147 + * cdef Py_ssize_t dst_stride = dst_strides[0] + * + * if ndim == 1: # <<<<<<<<<<<<<< + * if (src_stride > 0 and dst_stride > 0 and + * src_stride == itemsize == dst_stride): + */ + __pyx_t_1 = ((__pyx_v_ndim == 1) != 0); + if (__pyx_t_1) { -static struct PyGetSetDef __pyx_getsets_5pysam_18libcalignedsegment_AlignedSegment[] = { - {(char *)"query_name", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_name, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query_name, (char *)"the query template name (None if not present)", 0}, - {(char *)"flag", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_flag, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_flag, (char *)"properties flag", 0}, - {(char *)"reference_name", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_name, 0, (char *)":term:`reference` name (None if no AlignmentFile is associated)", 0}, - {(char *)"reference_id", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_id, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_id, (char *)":term:`reference` ID\n\n .. note::\n\n This field contains the index of the reference sequence in\n the sequence dictionary. To obtain the name of the\n reference sequence, use\n :meth:`pysam.AlignmentFile.getrname()`\n\n ", 0}, - {(char *)"reference_start", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_start, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_start, (char *)"0-based leftmost coordinate", 0}, - {(char *)"mapping_quality", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mapping_quality, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mapping_quality, (char *)"mapping quality", 0}, - {(char *)"cigarstring", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_cigarstring, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_cigarstring, (char *)"the :term:`cigar` alignment as a string.\n\n The cigar string is a string of alternating integers\n and characters denoting the length and the type of\n an operation.\n\n .. note::\n The order length,operation is specified in the\n SAM format. It is different from the order of\n the :attr:`cigar` property.\n\n Returns None if not present.\n\n To unset the cigarstring, assign None or the\n empty string.\n ", 0}, - {(char *)"next_reference_id", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_id, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_id, (char *)"the :term:`reference` id of the mate/next read.", 0}, - {(char *)"next_reference_name", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_name, 0, (char *)":term:`reference` name of the mate/next read (None if no\n AlignmentFile is associated)", 0}, - {(char *)"next_reference_start", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_start, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_start, (char *)"the position of the mate/next read.", 0}, - {(char *)"query_length", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_length, 0, (char *)"the length of the query/read.\n\n This value corresponds to the length of the sequence supplied\n in the BAM/SAM file. The length of a query is 0 if there is no\n sequence in the BAM/SAM file. In those cases, the read length\n can be inferred from the CIGAR alignment, see\n :meth:`pysam.AlignedSegment.infer_query_length`.\n\n The length includes soft-clipped bases and is equal to\n ``len(query_sequence)``.\n\n This property is read-only but can be set by providing a\n sequence.\n\n Returns 0 if not available.\n\n ", 0}, - {(char *)"template_length", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_template_length, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_template_length, (char *)"the observed query template length", 0}, - {(char *)"query_sequence", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_sequence, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query_sequence, (char *)"read sequence bases, including :term:`soft clipped` bases\n (None if not present).\n\n Note that assigning to seq will invalidate any quality scores.\n Thus, to in-place edit the sequence and quality scores, copies of\n the quality scores need to be taken. Consider trimming for example::\n\n q = read.query_qualities\n read.query_squence = read.query_sequence[5:10]\n read.query_qualities = q[5:10]\n\n The sequence is returned as it is stored in the BAM file. Some mappers\n might have stored a reverse complement of the original read\n sequence.\n ", 0}, - {(char *)"query_qualities", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_qualities, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query_qualities, (char *)"read sequence base qualities, including :term:`soft\n clipped` bases (None if not present).\n\n Quality scores are returned as a python array of unsigned\n chars. Note that this is not the ASCII-encoded value typically\n seen in FASTQ or SAM formatted files. Thus, no offset of 33\n needs to be subtracted.\n\n Note that to set quality scores the sequence has to be set\n beforehand as this will determine the expected length of the\n quality score array.\n\n This method raises a ValueError if the length of the\n quality scores and the sequence are not the same.\n\n ", 0}, - {(char *)"bin", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_bin, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_bin, (char *)"properties bin", 0}, - {(char *)"is_paired", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_paired, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_paired, (char *)"true if read is paired in sequencing", 0}, - {(char *)"is_proper_pair", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_proper_pair, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_proper_pair, (char *)"true if read is mapped in a proper pair", 0}, - {(char *)"is_unmapped", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_unmapped, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_unmapped, (char *)"true if read itself is unmapped", 0}, - {(char *)"mate_is_unmapped", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_unmapped, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_unmapped, (char *)"true if the mate is unmapped", 0}, - {(char *)"is_reverse", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_reverse, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_reverse, (char *)"true if read is mapped to reverse strand", 0}, - {(char *)"mate_is_reverse", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_reverse, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_reverse, (char *)"true is read is mapped to reverse strand", 0}, - {(char *)"is_read1", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read1, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read1, (char *)"true if this is read1", 0}, - {(char *)"is_read2", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read2, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read2, (char *)"true if this is read2", 0}, - {(char *)"is_secondary", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_secondary, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_secondary, (char *)"true if not primary alignment", 0}, - {(char *)"is_qcfail", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_qcfail, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_qcfail, (char *)"true if QC failure", 0}, - {(char *)"is_duplicate", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_duplicate, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_duplicate, (char *)"true if optical or PCR duplicate", 0}, - {(char *)"is_supplementary", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_supplementary, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_supplementary, (char *)"true if this is a supplementary alignment", 0}, - {(char *)"reference_end", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_end, 0, (char *)"aligned reference position of the read on the reference genome.\n\n reference_end points to one past the last aligned residue.\n Returns None if not available (read is unmapped or no cigar\n alignment present).\n\n ", 0}, - {(char *)"reference_length", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_length, 0, (char *)"aligned length of the read on the reference genome.\n\n This is equal to `aend - pos`. Returns None if not available.", 0}, - {(char *)"query_alignment_sequence", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_sequence, 0, (char *)"aligned portion of the read.\n\n This is a substring of :attr:`seq` that excludes flanking\n bases that were :term:`soft clipped` (None if not present). It\n is equal to ``seq[qstart:qend]``.\n\n SAM/BAM files may include extra flanking bases that are not\n part of the alignment. These bases may be the result of the\n Smith-Waterman or other algorithms, which may not require\n alignments that begin at the first residue or end at the last.\n In addition, extra sequencing adapters, multiplex identifiers,\n and low-quality bases that were not considered for alignment\n may have been retained.\n\n ", 0}, - {(char *)"query_alignment_qualities", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_qualities, 0, (char *)"aligned query sequence quality values (None if not present). These\n are the quality values that correspond to :attr:`query`, that\n is, they exclude qualities of :term:`soft clipped` bases. This\n is equal to ``qual[qstart:qend]``.\n\n Quality scores are returned as a python array of unsigned\n chars. Note that this is not the ASCII-encoded value typically\n seen in FASTQ or SAM formatted files. Thus, no offset of 33\n needs to be subtracted.\n\n This property is read-only.\n\n ", 0}, - {(char *)"query_alignment_start", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_start, 0, (char *)"start index of the aligned query portion of the sequence (0-based,\n inclusive).\n\n This the index of the first base in :attr:`seq` that is not\n soft-clipped.\n\n ", 0}, - {(char *)"query_alignment_end", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_end, 0, (char *)"end index of the aligned query portion of the sequence (0-based,\n exclusive)", 0}, - {(char *)"query_alignment_length", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_length, 0, (char *)"length of the aligned query sequence.\n\n This is equal to :attr:`qend` - :attr:`qstart`", 0}, - {(char *)"cigartuples", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_cigartuples, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_cigartuples, (char *)"the :term:`cigar` alignment. The alignment\n is returned as a list of tuples of (operation, length).\n\n If the alignment is not present, None is returned.\n\n The operations are:\n\n +-----+--------------+-----+\n |M |BAM_CMATCH |0 |\n +-----+--------------+-----+\n |I |BAM_CINS |1 |\n +-----+--------------+-----+\n |D |BAM_CDEL |2 |\n +-----+--------------+-----+\n |N |BAM_CREF_SKIP |3 |\n +-----+--------------+-----+\n |S |BAM_CSOFT_CLIP|4 |\n +-----+--------------+-----+\n |H |BAM_CHARD_CLIP|5 |\n +-----+--------------+-----+\n |P |BAM_CPAD |6 |\n +-----+--------------+-----+\n |= |BAM_CEQUAL |7 |\n +-----+--------------+-----+\n |X |BAM_CDIFF |8 |\n +-----+--------------+-----+\n\n .. note::\n The output is a list of (operation, length) tuples, such as\n ``[(0, 30)]``.\n This is different from the SAM specification and\n the :attr:`cigarstring` property, which uses a\n (length, operation) order, for example: ``30M``.\n\n To unset the cigar property, assign an empty list\n or None.\n ", 0}, - {(char *)"qname", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qname, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qname, (char *)"deprecated, use query_name instead", 0}, - {(char *)"tid", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_tid, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_tid, (char *)"deprecated, use reference_id instead", 0}, - {(char *)"pos", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_pos, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_pos, (char *)"deprecated, use reference_start instead", 0}, - {(char *)"mapq", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mapq, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mapq, (char *)"deprecated, use mapping_quality instead", 0}, - {(char *)"rnext", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_rnext, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_rnext, (char *)"deprecated, use next_reference_id instead", 0}, - {(char *)"pnext", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_pnext, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_pnext, (char *)"deprecated, use next_reference_start instead", 0}, - {(char *)"cigar", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_cigar, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_cigar, (char *)"deprecated, use cigartuples instead", 0}, - {(char *)"tlen", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_tlen, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_tlen, (char *)"deprecated, use template_length instead", 0}, - {(char *)"seq", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_seq, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_seq, (char *)"deprecated, use query_sequence instead", 0}, - {(char *)"qual", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qual, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qual, (char *)"deprecated, query_qualities instead", 0}, - {(char *)"alen", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_alen, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_alen, (char *)"deprecated, reference_length instead", 0}, - {(char *)"aend", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_aend, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_aend, (char *)"deprecated, reference_end instead", 0}, - {(char *)"rlen", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_rlen, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_rlen, (char *)"deprecated, query_length instead", 0}, - {(char *)"query", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query, (char *)"deprecated, query_alignment_sequence instead", 0}, - {(char *)"qqual", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qqual, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qqual, (char *)"deprecated, query_alignment_qualities instead", 0}, - {(char *)"qstart", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qstart, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qstart, (char *)"deprecated, use query_alignment_start instead", 0}, - {(char *)"qend", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qend, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qend, (char *)"deprecated, use query_alignment_end instead", 0}, - {(char *)"qlen", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qlen, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qlen, (char *)"deprecated, use query_alignment_length instead", 0}, - {(char *)"mrnm", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mrnm, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mrnm, (char *)"deprecated, use next_reference_id instead", 0}, - {(char *)"mpos", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mpos, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mpos, (char *)"deprecated, use next_reference_start instead", 0}, - {(char *)"rname", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_rname, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_rname, (char *)"deprecated, use reference_id instead", 0}, - {(char *)"isize", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_isize, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_isize, (char *)"deprecated, use template_length instead", 0}, - {(char *)"blocks", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_blocks, 0, (char *)"deprecated, use get_blocks() instead", 0}, - {(char *)"aligned_pairs", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_aligned_pairs, 0, (char *)"deprecated, use get_aligned_pairs() instead", 0}, - {(char *)"inferred_length", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_inferred_length, 0, (char *)"deprecated, use infer_query_length() instead", 0}, - {(char *)"positions", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_positions, 0, (char *)"deprecated, use get_reference_positions() instead", 0}, - {(char *)"tags", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_tags, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_tags, (char *)"deprecated, use get_tags() instead", 0}, - {0, 0, 0, 0, 0} -}; + /* "View.MemoryView":1148 + * + * if ndim == 1: + * if (src_stride > 0 and dst_stride > 0 and # <<<<<<<<<<<<<< + * src_stride == itemsize == dst_stride): + * memcpy(dst_data, src_data, itemsize * dst_extent) + */ + __pyx_t_2 = ((__pyx_v_src_stride > 0) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_dst_stride > 0) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L5_bool_binop_done; + } -static PyTypeObject __pyx_type_5pysam_18libcalignedsegment_AlignedSegment = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcalignedsegment.AlignedSegment", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_18libcalignedsegment_AlignedSegment, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ - #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15__hash__, /*tp_hash*/ - 0, /*tp_call*/ - __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5__str__, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "AlignedSegment()\nClass representing an aligned segment.\n\n This class stores a handle to the samtools C-structure representing\n an aligned read. Member read access is forwarded to the C-structure\n and converted into python objects. This implementation should be fast,\n as only the data needed is converted.\n\n For write access, the C-structure is updated in-place. This is\n not the most efficient way to build BAM entries, as the variable\n length data is concatenated and thus needs to be resized if\n a field is updated. Furthermore, the BAM entry might be\n in an inconsistent state.\n\n One issue to look out for is that the sequence should always\n be set *before* the quality scores. Setting the sequence will\n also erase any quality scores that were set previously.\n ", /*tp_doc*/ - __pyx_tp_traverse_5pysam_18libcalignedsegment_AlignedSegment, /*tp_traverse*/ - __pyx_tp_clear_5pysam_18libcalignedsegment_AlignedSegment, /*tp_clear*/ - __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13__richcmp__, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_5pysam_18libcalignedsegment_AlignedSegment, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_5pysam_18libcalignedsegment_AlignedSegment, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_1__init__, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_18libcalignedsegment_AlignedSegment, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ - #endif -}; + /* "View.MemoryView":1149 + * if ndim == 1: + * if (src_stride > 0 and dst_stride > 0 and + * src_stride == itemsize == dst_stride): # <<<<<<<<<<<<<< + * memcpy(dst_data, src_data, itemsize * dst_extent) + * else: + */ + __pyx_t_2 = (((size_t)__pyx_v_src_stride) == __pyx_v_itemsize); + if (__pyx_t_2) { + __pyx_t_2 = (__pyx_v_itemsize == ((size_t)__pyx_v_dst_stride)); + } + __pyx_t_3 = (__pyx_t_2 != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L5_bool_binop_done:; -static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment_PileupColumn(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *p; - PyObject *o; - if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { - o = (*t->tp_alloc)(t, 0); - } else { - o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); - } - if (unlikely(!o)) return 0; - p = ((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)o); - p->_alignment_file = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None); - return o; -} + /* "View.MemoryView":1148 + * + * if ndim == 1: + * if (src_stride > 0 and dst_stride > 0 and # <<<<<<<<<<<<<< + * src_stride == itemsize == dst_stride): + * memcpy(dst_data, src_data, itemsize * dst_extent) + */ + if (__pyx_t_1) { -static void __pyx_tp_dealloc_5pysam_18libcalignedsegment_PileupColumn(PyObject *o) { - struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *p = (struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)o; - #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { - if (PyObject_CallFinalizerFromDealloc(o)) return; - } - #endif - PyObject_GC_UnTrack(o); - Py_CLEAR(p->_alignment_file); - (*Py_TYPE(o)->tp_free)(o); -} + /* "View.MemoryView":1150 + * if (src_stride > 0 and dst_stride > 0 and + * src_stride == itemsize == dst_stride): + * memcpy(dst_data, src_data, itemsize * dst_extent) # <<<<<<<<<<<<<< + * else: + * for i in range(dst_extent): + */ + (void)(memcpy(__pyx_v_dst_data, __pyx_v_src_data, (__pyx_v_itemsize * __pyx_v_dst_extent))); -static int __pyx_tp_traverse_5pysam_18libcalignedsegment_PileupColumn(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *p = (struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)o; - if (p->_alignment_file) { - e = (*v)(((PyObject *)p->_alignment_file), a); if (e) return e; - } - return 0; -} + /* "View.MemoryView":1148 + * + * if ndim == 1: + * if (src_stride > 0 and dst_stride > 0 and # <<<<<<<<<<<<<< + * src_stride == itemsize == dst_stride): + * memcpy(dst_data, src_data, itemsize * dst_extent) + */ + goto __pyx_L4; + } -static int __pyx_tp_clear_5pysam_18libcalignedsegment_PileupColumn(PyObject *o) { - PyObject* tmp; - struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *p = (struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)o; - tmp = ((PyObject*)p->_alignment_file); - p->_alignment_file = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} + /* "View.MemoryView":1152 + * memcpy(dst_data, src_data, itemsize * dst_extent) + * else: + * for i in range(dst_extent): # <<<<<<<<<<<<<< + * memcpy(dst_data, src_data, itemsize) + * src_data += src_stride + */ + /*else*/ { + __pyx_t_4 = __pyx_v_dst_extent; + __pyx_t_5 = __pyx_t_4; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_i = __pyx_t_6; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_reference_id(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_12reference_id_1__get__(o); -} + /* "View.MemoryView":1153 + * else: + * for i in range(dst_extent): + * memcpy(dst_data, src_data, itemsize) # <<<<<<<<<<<<<< + * src_data += src_stride + * dst_data += dst_stride + */ + (void)(memcpy(__pyx_v_dst_data, __pyx_v_src_data, __pyx_v_itemsize)); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_reference_name(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_14reference_name_1__get__(o); -} + /* "View.MemoryView":1154 + * for i in range(dst_extent): + * memcpy(dst_data, src_data, itemsize) + * src_data += src_stride # <<<<<<<<<<<<<< + * dst_data += dst_stride + * else: + */ + __pyx_v_src_data = (__pyx_v_src_data + __pyx_v_src_stride); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_nsegments(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_1__get__(o); -} + /* "View.MemoryView":1155 + * memcpy(dst_data, src_data, itemsize) + * src_data += src_stride + * dst_data += dst_stride # <<<<<<<<<<<<<< + * else: + * for i in range(dst_extent): + */ + __pyx_v_dst_data = (__pyx_v_dst_data + __pyx_v_dst_stride); + } + } + __pyx_L4:; -static int __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_nsegments(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1147 + * cdef Py_ssize_t dst_stride = dst_strides[0] + * + * if ndim == 1: # <<<<<<<<<<<<<< + * if (src_stride > 0 and dst_stride > 0 and + * src_stride == itemsize == dst_stride): + */ + goto __pyx_L3; } -} -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_reference_pos(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_13reference_pos_1__get__(o); -} + /* "View.MemoryView":1157 + * dst_data += dst_stride + * else: + * for i in range(dst_extent): # <<<<<<<<<<<<<< + * _copy_strided_to_strided(src_data, src_strides + 1, + * dst_data, dst_strides + 1, + */ + /*else*/ { + __pyx_t_4 = __pyx_v_dst_extent; + __pyx_t_5 = __pyx_t_4; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_i = __pyx_t_6; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_pileups(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_7pileups_1__get__(o); -} + /* "View.MemoryView":1158 + * else: + * for i in range(dst_extent): + * _copy_strided_to_strided(src_data, src_strides + 1, # <<<<<<<<<<<<<< + * dst_data, dst_strides + 1, + * src_shape + 1, dst_shape + 1, + */ + _copy_strided_to_strided(__pyx_v_src_data, (__pyx_v_src_strides + 1), __pyx_v_dst_data, (__pyx_v_dst_strides + 1), (__pyx_v_src_shape + 1), (__pyx_v_dst_shape + 1), (__pyx_v_ndim - 1), __pyx_v_itemsize); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_pos(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3pos_1__get__(o); -} + /* "View.MemoryView":1162 + * src_shape + 1, dst_shape + 1, + * ndim - 1, itemsize) + * src_data += src_stride # <<<<<<<<<<<<<< + * dst_data += dst_stride + * + */ + __pyx_v_src_data = (__pyx_v_src_data + __pyx_v_src_stride); -static int __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_pos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3pos_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "View.MemoryView":1163 + * ndim - 1, itemsize) + * src_data += src_stride + * dst_data += dst_stride # <<<<<<<<<<<<<< + * + * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, + */ + __pyx_v_dst_data = (__pyx_v_dst_data + __pyx_v_dst_stride); + } } -} - -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_tid(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3tid_1__get__(o); -} + __pyx_L3:; -static int __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_tid(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3tid_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "View.MemoryView":1135 + * + * @cython.cdivision(True) + * cdef void _copy_strided_to_strided(char *src_data, Py_ssize_t *src_strides, # <<<<<<<<<<<<<< + * char *dst_data, Py_ssize_t *dst_strides, + * Py_ssize_t *src_shape, Py_ssize_t *dst_shape, + */ -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_n(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1n_1__get__(o); + /* function exit code */ } -static int __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_n(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1n_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} +/* "View.MemoryView":1165 + * dst_data += dst_stride + * + * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< + * __Pyx_memviewslice *dst, + * int ndim, size_t itemsize) nogil: + */ -static PyMethodDef __pyx_methods_5pysam_18libcalignedsegment_PileupColumn[] = { - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_5__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_4__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_7__setstate_cython__, METH_O, __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_6__setstate_cython__}, - {0, 0, 0, 0} -}; +static void copy_strided_to_strided(__Pyx_memviewslice *__pyx_v_src, __Pyx_memviewslice *__pyx_v_dst, int __pyx_v_ndim, size_t __pyx_v_itemsize) { + __Pyx_TraceDeclarations + __Pyx_TraceCall("copy_strided_to_strided", __pyx_f[1], 1165, 1, __PYX_ERR(1, 1165, __pyx_L1_error)); -static struct PyGetSetDef __pyx_getsets_5pysam_18libcalignedsegment_PileupColumn[] = { - {(char *)"reference_id", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_reference_id, 0, (char *)"the reference sequence number as defined in the header", 0}, - {(char *)"reference_name", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_reference_name, 0, (char *)":term:`reference` name (None if no AlignmentFile is associated)", 0}, - {(char *)"nsegments", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_nsegments, __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_nsegments, (char *)"number of reads mapping to this column.", 0}, - {(char *)"reference_pos", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_reference_pos, 0, (char *)"the position in the reference sequence (0-based).", 0}, - {(char *)"pileups", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_pileups, 0, (char *)"list of reads (:class:`pysam.PileupRead`) aligned to this column", 0}, - {(char *)"pos", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_pos, __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_pos, (char *)0, 0}, - {(char *)"tid", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_tid, __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_tid, (char *)0, 0}, - {(char *)"n", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_n, __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_n, (char *)0, 0}, - {0, 0, 0, 0, 0} -}; + /* "View.MemoryView":1168 + * __Pyx_memviewslice *dst, + * int ndim, size_t itemsize) nogil: + * _copy_strided_to_strided(src.data, src.strides, dst.data, dst.strides, # <<<<<<<<<<<<<< + * src.shape, dst.shape, ndim, itemsize) + * + */ + _copy_strided_to_strided(__pyx_v_src->data, __pyx_v_src->strides, __pyx_v_dst->data, __pyx_v_dst->strides, __pyx_v_src->shape, __pyx_v_dst->shape, __pyx_v_ndim, __pyx_v_itemsize); -static PyTypeObject __pyx_type_5pysam_18libcalignedsegment_PileupColumn = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcalignedsegment.PileupColumn", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_18libcalignedsegment_PileupColumn, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ - #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3__str__, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "PileupColumn()\nA pileup of reads at a particular reference sequence position\n (:term:`column`). A pileup column contains all the reads that map\n to a certain target base.\n\n This class is a proxy for results returned by the samtools pileup\n engine. If the underlying engine iterator advances, the results\n of this column will change.\n\n ", /*tp_doc*/ - __pyx_tp_traverse_5pysam_18libcalignedsegment_PileupColumn, /*tp_traverse*/ - __pyx_tp_clear_5pysam_18libcalignedsegment_PileupColumn, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_5pysam_18libcalignedsegment_PileupColumn, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_5pysam_18libcalignedsegment_PileupColumn, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1__init__, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_18libcalignedsegment_PileupColumn, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ - #endif -}; + /* "View.MemoryView":1165 + * dst_data += dst_stride + * + * cdef void copy_strided_to_strided(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< + * __Pyx_memviewslice *dst, + * int ndim, size_t itemsize) nogil: + */ -static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment_PileupRead(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *p; - PyObject *o; - if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { - o = (*t->tp_alloc)(t, 0); - } else { - o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); - } - if (unlikely(!o)) return 0; - p = ((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)o); - p->_alignment = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)Py_None); Py_INCREF(Py_None); - return o; + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView.copy_strided_to_strided", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 1); } -static void __pyx_tp_dealloc_5pysam_18libcalignedsegment_PileupRead(PyObject *o) { - struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *p = (struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)o; - #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { - if (PyObject_CallFinalizerFromDealloc(o)) return; - } - #endif - PyObject_GC_UnTrack(o); - Py_CLEAR(p->_alignment); - (*Py_TYPE(o)->tp_free)(o); -} +/* "View.MemoryView":1172 + * + * @cname('__pyx_memoryview_slice_get_size') + * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil: # <<<<<<<<<<<<<< + * "Return the size of the memory occupied by the slice in number of bytes" + * cdef int i + */ -static int __pyx_tp_traverse_5pysam_18libcalignedsegment_PileupRead(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *p = (struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)o; - if (p->_alignment) { - e = (*v)(((PyObject *)p->_alignment), a); if (e) return e; - } - return 0; -} +static Py_ssize_t __pyx_memoryview_slice_get_size(__Pyx_memviewslice *__pyx_v_src, int __pyx_v_ndim) { + int __pyx_v_i; + Py_ssize_t __pyx_v_size; + Py_ssize_t __pyx_r; + __Pyx_TraceDeclarations + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_TraceCall("slice_get_size", __pyx_f[1], 1172, 1, __PYX_ERR(1, 1172, __pyx_L1_error)); -static int __pyx_tp_clear_5pysam_18libcalignedsegment_PileupRead(PyObject *o) { - PyObject* tmp; - struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *p = (struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)o; - tmp = ((PyObject*)p->_alignment); - p->_alignment = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} + /* "View.MemoryView":1175 + * "Return the size of the memory occupied by the slice in number of bytes" + * cdef int i + * cdef Py_ssize_t size = src.memview.view.itemsize # <<<<<<<<<<<<<< + * + * for i in range(ndim): + */ + __pyx_t_1 = __pyx_v_src->memview->view.itemsize; + __pyx_v_size = __pyx_t_1; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_alignment(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_9alignment_1__get__(o); -} + /* "View.MemoryView":1177 + * cdef Py_ssize_t size = src.memview.view.itemsize + * + * for i in range(ndim): # <<<<<<<<<<<<<< + * size *= src.shape[i] + * + */ + __pyx_t_2 = __pyx_v_ndim; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_query_position(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_14query_position_1__get__(o); -} + /* "View.MemoryView":1178 + * + * for i in range(ndim): + * size *= src.shape[i] # <<<<<<<<<<<<<< + * + * return size + */ + __pyx_v_size = (__pyx_v_size * (__pyx_v_src->shape[__pyx_v_i])); + } -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_query_position_or_next(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_22query_position_or_next_1__get__(o); -} + /* "View.MemoryView":1180 + * size *= src.shape[i] + * + * return size # <<<<<<<<<<<<<< + * + * @cname('__pyx_fill_contig_strides_array') + */ + __pyx_r = __pyx_v_size; + goto __pyx_L0; -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_indel(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5indel_1__get__(o); -} + /* "View.MemoryView":1172 + * + * @cname('__pyx_memoryview_slice_get_size') + * cdef Py_ssize_t slice_get_size(__Pyx_memviewslice *src, int ndim) nogil: # <<<<<<<<<<<<<< + * "Return the size of the memory occupied by the slice in number of bytes" + * cdef int i + */ -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_level(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5level_1__get__(o); + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView.slice_get_size", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 1); + return __pyx_r; } -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_del(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_6is_del_1__get__(o); -} +/* "View.MemoryView":1183 + * + * @cname('__pyx_fill_contig_strides_array') + * cdef Py_ssize_t fill_contig_strides_array( # <<<<<<<<<<<<<< + * Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride, + * int ndim, char order) nogil: + */ -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_head(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7is_head_1__get__(o); -} +static Py_ssize_t __pyx_fill_contig_strides_array(Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, Py_ssize_t __pyx_v_stride, int __pyx_v_ndim, char __pyx_v_order) { + int __pyx_v_idx; + Py_ssize_t __pyx_r; + __Pyx_TraceDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_TraceCall("fill_contig_strides_array", __pyx_f[1], 1183, 1, __PYX_ERR(1, 1183, __pyx_L1_error)); -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_tail(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7is_tail_1__get__(o); -} + /* "View.MemoryView":1192 + * cdef int idx + * + * if order == 'F': # <<<<<<<<<<<<<< + * for idx in range(ndim): + * strides[idx] = stride + */ + __pyx_t_1 = ((__pyx_v_order == 'F') != 0); + if (__pyx_t_1) { -static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_refskip(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_10is_refskip_1__get__(o); -} + /* "View.MemoryView":1193 + * + * if order == 'F': + * for idx in range(ndim): # <<<<<<<<<<<<<< + * strides[idx] = stride + * stride = stride * shape[idx] + */ + __pyx_t_2 = __pyx_v_ndim; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_idx = __pyx_t_4; -static PyMethodDef __pyx_methods_5pysam_18libcalignedsegment_PileupRead[] = { - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_10PileupRead_4__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7__setstate_cython__, METH_O, __pyx_doc_5pysam_18libcalignedsegment_10PileupRead_6__setstate_cython__}, - {0, 0, 0, 0} -}; + /* "View.MemoryView":1194 + * if order == 'F': + * for idx in range(ndim): + * strides[idx] = stride # <<<<<<<<<<<<<< + * stride = stride * shape[idx] + * else: + */ + (__pyx_v_strides[__pyx_v_idx]) = __pyx_v_stride; -static struct PyGetSetDef __pyx_getsets_5pysam_18libcalignedsegment_PileupRead[] = { - {(char *)"alignment", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_alignment, 0, (char *)"a :class:`pysam.AlignedSegment` object of the aligned read", 0}, - {(char *)"query_position", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_query_position, 0, (char *)"position of the read base at the pileup site, 0-based.\n None if is_del or is_refskip is set.\n\n ", 0}, - {(char *)"query_position_or_next", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_query_position_or_next, 0, (char *)"position of the read base at the pileup site, 0-based.\n\n If the current position is a deletion, returns the next\n aligned base.\n\n ", 0}, - {(char *)"indel", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_indel, 0, (char *)"indel length for the position following the current pileup site.\n\n This quantity peeks ahead to the next cigar operation in this\n alignment. If the next operation is an insertion, indel will\n be positive. If the next operation is a deletion, it will be\n negation. 0 if the next operation is not an indel.\n\n ", 0}, - {(char *)"level", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_level, 0, (char *)"the level of the read in the \"viewer\" mode. Note that this value\n is currently not computed.", 0}, - {(char *)"is_del", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_del, 0, (char *)"1 iff the base on the padded read is a deletion", 0}, - {(char *)"is_head", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_head, 0, (char *)"1 iff the base on the padded read is the left-most base.", 0}, - {(char *)"is_tail", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_tail, 0, (char *)"1 iff the base on the padded read is the right-most base.", 0}, - {(char *)"is_refskip", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_refskip, 0, (char *)"1 iff the base on the padded read is part of CIGAR N op.", 0}, - {0, 0, 0, 0, 0} -}; + /* "View.MemoryView":1195 + * for idx in range(ndim): + * strides[idx] = stride + * stride = stride * shape[idx] # <<<<<<<<<<<<<< + * else: + * for idx in range(ndim - 1, -1, -1): + */ + __pyx_v_stride = (__pyx_v_stride * (__pyx_v_shape[__pyx_v_idx])); + } -static PyTypeObject __pyx_type_5pysam_18libcalignedsegment_PileupRead = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcalignedsegment.PileupRead", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_18libcalignedsegment_PileupRead, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ - #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_3__str__, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "PileupRead()\nRepresentation of a read aligned to a particular position in the\n reference sequence.\n\n ", /*tp_doc*/ - __pyx_tp_traverse_5pysam_18libcalignedsegment_PileupRead, /*tp_traverse*/ - __pyx_tp_clear_5pysam_18libcalignedsegment_PileupRead, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_5pysam_18libcalignedsegment_PileupRead, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_5pysam_18libcalignedsegment_PileupRead, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_1__init__, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_18libcalignedsegment_PileupRead, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ - #endif -}; + /* "View.MemoryView":1192 + * cdef int idx + * + * if order == 'F': # <<<<<<<<<<<<<< + * for idx in range(ndim): + * strides[idx] = stride + */ + goto __pyx_L3; + } -static struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *__pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr[8]; -static int __pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr = 0; + /* "View.MemoryView":1197 + * stride = stride * shape[idx] + * else: + * for idx in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< + * strides[idx] = stride + * stride = stride * shape[idx] + */ + /*else*/ { + for (__pyx_t_2 = (__pyx_v_ndim - 1); __pyx_t_2 > -1; __pyx_t_2-=1) { + __pyx_v_idx = __pyx_t_2; -static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - PyObject *o; - if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr)))) { - o = (PyObject*)__pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr[--__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr]; - memset(o, 0, sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr)); - (void) PyObject_INIT(o, t); - PyObject_GC_Track(o); - } else { - o = (*t->tp_alloc)(t, 0); - if (unlikely(!o)) return 0; - } - return o; -} + /* "View.MemoryView":1198 + * else: + * for idx in range(ndim - 1, -1, -1): + * strides[idx] = stride # <<<<<<<<<<<<<< + * stride = stride * shape[idx] + * + */ + (__pyx_v_strides[__pyx_v_idx]) = __pyx_v_stride; -static void __pyx_tp_dealloc_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr(PyObject *o) { - struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *)o; - PyObject_GC_UnTrack(o); - Py_CLEAR(p->__pyx_v_x); - Py_CLEAR(p->__pyx_v_y); - Py_CLEAR(p->__pyx_t_0); - Py_CLEAR(p->__pyx_t_1); - if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr)))) { - __pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr[__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr++] = ((struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *)o); - } else { - (*Py_TYPE(o)->tp_free)(o); + /* "View.MemoryView":1199 + * for idx in range(ndim - 1, -1, -1): + * strides[idx] = stride + * stride = stride * shape[idx] # <<<<<<<<<<<<<< + * + * return stride + */ + __pyx_v_stride = (__pyx_v_stride * (__pyx_v_shape[__pyx_v_idx])); + } } -} + __pyx_L3:; -static int __pyx_tp_traverse_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *)o; - if (p->__pyx_v_x) { - e = (*v)(p->__pyx_v_x, a); if (e) return e; - } - if (p->__pyx_v_y) { - e = (*v)(p->__pyx_v_y, a); if (e) return e; + /* "View.MemoryView":1201 + * stride = stride * shape[idx] + * + * return stride # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_copy_data_to_temp') + */ + __pyx_r = __pyx_v_stride; + goto __pyx_L0; + + /* "View.MemoryView":1183 + * + * @cname('__pyx_fill_contig_strides_array') + * cdef Py_ssize_t fill_contig_strides_array( # <<<<<<<<<<<<<< + * Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t stride, + * int ndim, char order) nogil: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView.fill_contig_strides_array", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 1); + return __pyx_r; +} + +/* "View.MemoryView":1204 + * + * @cname('__pyx_memoryview_copy_data_to_temp') + * cdef void *copy_data_to_temp(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< + * __Pyx_memviewslice *tmpslice, + * char order, + */ + +static void *__pyx_memoryview_copy_data_to_temp(__Pyx_memviewslice *__pyx_v_src, __Pyx_memviewslice *__pyx_v_tmpslice, char __pyx_v_order, int __pyx_v_ndim) { + int __pyx_v_i; + void *__pyx_v_result; + size_t __pyx_v_itemsize; + size_t __pyx_v_size; + void *__pyx_r; + __Pyx_TraceDeclarations + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + struct __pyx_memoryview_obj *__pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + __Pyx_TraceCall("copy_data_to_temp", __pyx_f[1], 1204, 1, __PYX_ERR(1, 1204, __pyx_L1_error)); + + /* "View.MemoryView":1215 + * cdef void *result + * + * cdef size_t itemsize = src.memview.view.itemsize # <<<<<<<<<<<<<< + * cdef size_t size = slice_get_size(src, ndim) + * + */ + __pyx_t_1 = __pyx_v_src->memview->view.itemsize; + __pyx_v_itemsize = __pyx_t_1; + + /* "View.MemoryView":1216 + * + * cdef size_t itemsize = src.memview.view.itemsize + * cdef size_t size = slice_get_size(src, ndim) # <<<<<<<<<<<<<< + * + * result = malloc(size) + */ + __pyx_v_size = __pyx_memoryview_slice_get_size(__pyx_v_src, __pyx_v_ndim); + + /* "View.MemoryView":1218 + * cdef size_t size = slice_get_size(src, ndim) + * + * result = malloc(size) # <<<<<<<<<<<<<< + * if not result: + * _err(MemoryError, NULL) + */ + __pyx_v_result = malloc(__pyx_v_size); + + /* "View.MemoryView":1219 + * + * result = malloc(size) + * if not result: # <<<<<<<<<<<<<< + * _err(MemoryError, NULL) + * + */ + __pyx_t_2 = ((!(__pyx_v_result != 0)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1220 + * result = malloc(size) + * if not result: + * _err(MemoryError, NULL) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_3 = __pyx_memoryview_err(__pyx_builtin_MemoryError, NULL); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 1220, __pyx_L1_error) + + /* "View.MemoryView":1219 + * + * result = malloc(size) + * if not result: # <<<<<<<<<<<<<< + * _err(MemoryError, NULL) + * + */ } - if (p->__pyx_t_0) { - e = (*v)(p->__pyx_t_0, a); if (e) return e; + + /* "View.MemoryView":1223 + * + * + * tmpslice.data = result # <<<<<<<<<<<<<< + * tmpslice.memview = src.memview + * for i in range(ndim): + */ + __pyx_v_tmpslice->data = ((char *)__pyx_v_result); + + /* "View.MemoryView":1224 + * + * tmpslice.data = result + * tmpslice.memview = src.memview # <<<<<<<<<<<<<< + * for i in range(ndim): + * tmpslice.shape[i] = src.shape[i] + */ + __pyx_t_4 = __pyx_v_src->memview; + __pyx_v_tmpslice->memview = __pyx_t_4; + + /* "View.MemoryView":1225 + * tmpslice.data = result + * tmpslice.memview = src.memview + * for i in range(ndim): # <<<<<<<<<<<<<< + * tmpslice.shape[i] = src.shape[i] + * tmpslice.suboffsets[i] = -1 + */ + __pyx_t_3 = __pyx_v_ndim; + __pyx_t_5 = __pyx_t_3; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_i = __pyx_t_6; + + /* "View.MemoryView":1226 + * tmpslice.memview = src.memview + * for i in range(ndim): + * tmpslice.shape[i] = src.shape[i] # <<<<<<<<<<<<<< + * tmpslice.suboffsets[i] = -1 + * + */ + (__pyx_v_tmpslice->shape[__pyx_v_i]) = (__pyx_v_src->shape[__pyx_v_i]); + + /* "View.MemoryView":1227 + * for i in range(ndim): + * tmpslice.shape[i] = src.shape[i] + * tmpslice.suboffsets[i] = -1 # <<<<<<<<<<<<<< + * + * fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize, + */ + (__pyx_v_tmpslice->suboffsets[__pyx_v_i]) = -1L; } - if (p->__pyx_t_1) { - e = (*v)(p->__pyx_t_1, a); if (e) return e; + + /* "View.MemoryView":1229 + * tmpslice.suboffsets[i] = -1 + * + * fill_contig_strides_array(&tmpslice.shape[0], &tmpslice.strides[0], itemsize, # <<<<<<<<<<<<<< + * ndim, order) + * + */ + (void)(__pyx_fill_contig_strides_array((&(__pyx_v_tmpslice->shape[0])), (&(__pyx_v_tmpslice->strides[0])), __pyx_v_itemsize, __pyx_v_ndim, __pyx_v_order)); + + /* "View.MemoryView":1233 + * + * + * for i in range(ndim): # <<<<<<<<<<<<<< + * if tmpslice.shape[i] == 1: + * tmpslice.strides[i] = 0 + */ + __pyx_t_3 = __pyx_v_ndim; + __pyx_t_5 = __pyx_t_3; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_i = __pyx_t_6; + + /* "View.MemoryView":1234 + * + * for i in range(ndim): + * if tmpslice.shape[i] == 1: # <<<<<<<<<<<<<< + * tmpslice.strides[i] = 0 + * + */ + __pyx_t_2 = (((__pyx_v_tmpslice->shape[__pyx_v_i]) == 1) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1235 + * for i in range(ndim): + * if tmpslice.shape[i] == 1: + * tmpslice.strides[i] = 0 # <<<<<<<<<<<<<< + * + * if slice_is_contig(src[0], order, ndim): + */ + (__pyx_v_tmpslice->strides[__pyx_v_i]) = 0; + + /* "View.MemoryView":1234 + * + * for i in range(ndim): + * if tmpslice.shape[i] == 1: # <<<<<<<<<<<<<< + * tmpslice.strides[i] = 0 + * + */ + } } - return 0; + + /* "View.MemoryView":1237 + * tmpslice.strides[i] = 0 + * + * if slice_is_contig(src[0], order, ndim): # <<<<<<<<<<<<<< + * memcpy(result, src.data, size) + * else: + */ + __pyx_t_2 = (__pyx_memviewslice_is_contig((__pyx_v_src[0]), __pyx_v_order, __pyx_v_ndim) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1238 + * + * if slice_is_contig(src[0], order, ndim): + * memcpy(result, src.data, size) # <<<<<<<<<<<<<< + * else: + * copy_strided_to_strided(src, tmpslice, ndim, itemsize) + */ + (void)(memcpy(__pyx_v_result, __pyx_v_src->data, __pyx_v_size)); + + /* "View.MemoryView":1237 + * tmpslice.strides[i] = 0 + * + * if slice_is_contig(src[0], order, ndim): # <<<<<<<<<<<<<< + * memcpy(result, src.data, size) + * else: + */ + goto __pyx_L9; + } + + /* "View.MemoryView":1240 + * memcpy(result, src.data, size) + * else: + * copy_strided_to_strided(src, tmpslice, ndim, itemsize) # <<<<<<<<<<<<<< + * + * return result + */ + /*else*/ { + copy_strided_to_strided(__pyx_v_src, __pyx_v_tmpslice, __pyx_v_ndim, __pyx_v_itemsize); + } + __pyx_L9:; + + /* "View.MemoryView":1242 + * copy_strided_to_strided(src, tmpslice, ndim, itemsize) + * + * return result # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + /* "View.MemoryView":1204 + * + * @cname('__pyx_memoryview_copy_data_to_temp') + * cdef void *copy_data_to_temp(__Pyx_memviewslice *src, # <<<<<<<<<<<<<< + * __Pyx_memviewslice *tmpslice, + * char order, + */ + + /* function exit code */ + __pyx_L1_error:; + { + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_AddTraceback("View.MemoryView.copy_data_to_temp", __pyx_clineno, __pyx_lineno, __pyx_filename); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + } + __pyx_r = NULL; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 1); + return __pyx_r; } -static PyTypeObject __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcalignedsegment.__pyx_scope_struct__genexpr", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ +/* "View.MemoryView":1247 + * + * @cname('__pyx_memoryview_err_extents') + * cdef int _err_extents(int i, Py_ssize_t extent1, # <<<<<<<<<<<<<< + * Py_ssize_t extent2) except -1 with gil: + * raise ValueError("got differing extents in dimension %d (got %d and %d)" % + */ + +static int __pyx_memoryview_err_extents(int __pyx_v_i, Py_ssize_t __pyx_v_extent1, Py_ssize_t __pyx_v_extent2) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - 0, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ + __Pyx_RefNannySetupContext("_err_extents", 0); + __Pyx_TraceCall("_err_extents", __pyx_f[1], 1247, 0, __PYX_ERR(1, 1247, __pyx_L1_error)); + + /* "View.MemoryView":1250 + * Py_ssize_t extent2) except -1 with gil: + * raise ValueError("got differing extents in dimension %d (got %d and %d)" % + * (i, extent1, extent2)) # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_err_dim') + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_extent1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_extent2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 1250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; + + /* "View.MemoryView":1249 + * cdef int _err_extents(int i, Py_ssize_t extent1, + * Py_ssize_t extent2) except -1 with gil: + * raise ValueError("got differing extents in dimension %d (got %d and %d)" % # <<<<<<<<<<<<<< + * (i, extent1, extent2)) + * + */ + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_got_differing_extents_in_dimensi, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 1249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(1, 1249, __pyx_L1_error) + + /* "View.MemoryView":1247 + * + * @cname('__pyx_memoryview_err_extents') + * cdef int _err_extents(int i, Py_ssize_t extent1, # <<<<<<<<<<<<<< + * Py_ssize_t extent2) except -1 with gil: + * raise ValueError("got differing extents in dimension %d (got %d and %d)" % + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("View.MemoryView._err_extents", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); #endif -}; + return __pyx_r; +} -static struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *__pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr[8]; -static int __pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr = 0; +/* "View.MemoryView":1253 + * + * @cname('__pyx_memoryview_err_dim') + * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil: # <<<<<<<<<<<<<< + * raise error(msg.decode('ascii') % dim) + * + */ -static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - PyObject *o; - if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr)))) { - o = (PyObject*)__pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr[--__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr]; - memset(o, 0, sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr)); - (void) PyObject_INIT(o, t); - PyObject_GC_Track(o); - } else { - o = (*t->tp_alloc)(t, 0); - if (unlikely(!o)) return 0; +static int __pyx_memoryview_err_dim(PyObject *__pyx_v_error, char *__pyx_v_msg, int __pyx_v_dim) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_RefNannySetupContext("_err_dim", 0); + __Pyx_TraceCall("_err_dim", __pyx_f[1], 1253, 0, __PYX_ERR(1, 1253, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_error); + + /* "View.MemoryView":1254 + * @cname('__pyx_memoryview_err_dim') + * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil: + * raise error(msg.decode('ascii') % dim) # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_err') + */ + __pyx_t_2 = __Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyUnicode_Format(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 1254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_v_error); + __pyx_t_3 = __pyx_v_error; __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } } - return o; -} + if (!__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1254, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_4}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1254, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_4}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1254, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 1254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 1254, __pyx_L1_error) + + /* "View.MemoryView":1253 + * + * @cname('__pyx_memoryview_err_dim') + * cdef int _err_dim(object error, char *msg, int dim) except -1 with gil: # <<<<<<<<<<<<<< + * raise error(msg.decode('ascii') % dim) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("View.MemoryView._err_dim", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __Pyx_XDECREF(__pyx_v_error); + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + return __pyx_r; +} + +/* "View.MemoryView":1257 + * + * @cname('__pyx_memoryview_err') + * cdef int _err(object error, char *msg) except -1 with gil: # <<<<<<<<<<<<<< + * if msg != NULL: + * raise error(msg.decode('ascii')) + */ + +static int __pyx_memoryview_err(PyObject *__pyx_v_error, char *__pyx_v_msg) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_RefNannySetupContext("_err", 0); + __Pyx_TraceCall("_err", __pyx_f[1], 1257, 0, __PYX_ERR(1, 1257, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_error); + + /* "View.MemoryView":1258 + * @cname('__pyx_memoryview_err') + * cdef int _err(object error, char *msg) except -1 with gil: + * if msg != NULL: # <<<<<<<<<<<<<< + * raise error(msg.decode('ascii')) + * else: + */ + __pyx_t_1 = ((__pyx_v_msg != NULL) != 0); + if (unlikely(__pyx_t_1)) { + + /* "View.MemoryView":1259 + * cdef int _err(object error, char *msg) except -1 with gil: + * if msg != NULL: + * raise error(msg.decode('ascii')) # <<<<<<<<<<<<<< + * else: + * raise error + */ + __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_msg, 0, strlen(__pyx_v_msg), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1259, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_error); + __pyx_t_4 = __pyx_v_error; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1259, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1259, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1259, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 1259, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1259, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(1, 1259, __pyx_L1_error) + + /* "View.MemoryView":1258 + * @cname('__pyx_memoryview_err') + * cdef int _err(object error, char *msg) except -1 with gil: + * if msg != NULL: # <<<<<<<<<<<<<< + * raise error(msg.decode('ascii')) + * else: + */ + } + + /* "View.MemoryView":1261 + * raise error(msg.decode('ascii')) + * else: + * raise error # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_copy_contents') + */ + /*else*/ { + __Pyx_Raise(__pyx_v_error, 0, 0, 0); + __PYX_ERR(1, 1261, __pyx_L1_error) + } + + /* "View.MemoryView":1257 + * + * @cname('__pyx_memoryview_err') + * cdef int _err(object error, char *msg) except -1 with gil: # <<<<<<<<<<<<<< + * if msg != NULL: + * raise error(msg.decode('ascii')) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("View.MemoryView._err", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __Pyx_XDECREF(__pyx_v_error); + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + return __pyx_r; +} + +/* "View.MemoryView":1264 + * + * @cname('__pyx_memoryview_copy_contents') + * cdef int memoryview_copy_contents(__Pyx_memviewslice src, # <<<<<<<<<<<<<< + * __Pyx_memviewslice dst, + * int src_ndim, int dst_ndim, + */ + +static int __pyx_memoryview_copy_contents(__Pyx_memviewslice __pyx_v_src, __Pyx_memviewslice __pyx_v_dst, int __pyx_v_src_ndim, int __pyx_v_dst_ndim, int __pyx_v_dtype_is_object) { + void *__pyx_v_tmpdata; + size_t __pyx_v_itemsize; + int __pyx_v_i; + char __pyx_v_order; + int __pyx_v_broadcasting; + int __pyx_v_direct_copy; + __Pyx_memviewslice __pyx_v_tmp; + int __pyx_v_ndim; + int __pyx_r; + __Pyx_TraceDeclarations + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + void *__pyx_t_7; + int __pyx_t_8; + __Pyx_TraceCall("memoryview_copy_contents", __pyx_f[1], 1264, 1, __PYX_ERR(1, 1264, __pyx_L1_error)); + + /* "View.MemoryView":1272 + * Check for overlapping memory and verify the shapes. + * """ + * cdef void *tmpdata = NULL # <<<<<<<<<<<<<< + * cdef size_t itemsize = src.memview.view.itemsize + * cdef int i + */ + __pyx_v_tmpdata = NULL; + + /* "View.MemoryView":1273 + * """ + * cdef void *tmpdata = NULL + * cdef size_t itemsize = src.memview.view.itemsize # <<<<<<<<<<<<<< + * cdef int i + * cdef char order = get_best_order(&src, src_ndim) + */ + __pyx_t_1 = __pyx_v_src.memview->view.itemsize; + __pyx_v_itemsize = __pyx_t_1; + + /* "View.MemoryView":1275 + * cdef size_t itemsize = src.memview.view.itemsize + * cdef int i + * cdef char order = get_best_order(&src, src_ndim) # <<<<<<<<<<<<<< + * cdef bint broadcasting = False + * cdef bint direct_copy = False + */ + __pyx_v_order = __pyx_get_best_slice_order((&__pyx_v_src), __pyx_v_src_ndim); + + /* "View.MemoryView":1276 + * cdef int i + * cdef char order = get_best_order(&src, src_ndim) + * cdef bint broadcasting = False # <<<<<<<<<<<<<< + * cdef bint direct_copy = False + * cdef __Pyx_memviewslice tmp + */ + __pyx_v_broadcasting = 0; + + /* "View.MemoryView":1277 + * cdef char order = get_best_order(&src, src_ndim) + * cdef bint broadcasting = False + * cdef bint direct_copy = False # <<<<<<<<<<<<<< + * cdef __Pyx_memviewslice tmp + * + */ + __pyx_v_direct_copy = 0; + + /* "View.MemoryView":1280 + * cdef __Pyx_memviewslice tmp + * + * if src_ndim < dst_ndim: # <<<<<<<<<<<<<< + * broadcast_leading(&src, src_ndim, dst_ndim) + * elif dst_ndim < src_ndim: + */ + __pyx_t_2 = ((__pyx_v_src_ndim < __pyx_v_dst_ndim) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1281 + * + * if src_ndim < dst_ndim: + * broadcast_leading(&src, src_ndim, dst_ndim) # <<<<<<<<<<<<<< + * elif dst_ndim < src_ndim: + * broadcast_leading(&dst, dst_ndim, src_ndim) + */ + __pyx_memoryview_broadcast_leading((&__pyx_v_src), __pyx_v_src_ndim, __pyx_v_dst_ndim); + + /* "View.MemoryView":1280 + * cdef __Pyx_memviewslice tmp + * + * if src_ndim < dst_ndim: # <<<<<<<<<<<<<< + * broadcast_leading(&src, src_ndim, dst_ndim) + * elif dst_ndim < src_ndim: + */ + goto __pyx_L3; + } + + /* "View.MemoryView":1282 + * if src_ndim < dst_ndim: + * broadcast_leading(&src, src_ndim, dst_ndim) + * elif dst_ndim < src_ndim: # <<<<<<<<<<<<<< + * broadcast_leading(&dst, dst_ndim, src_ndim) + * + */ + __pyx_t_2 = ((__pyx_v_dst_ndim < __pyx_v_src_ndim) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1283 + * broadcast_leading(&src, src_ndim, dst_ndim) + * elif dst_ndim < src_ndim: + * broadcast_leading(&dst, dst_ndim, src_ndim) # <<<<<<<<<<<<<< + * + * cdef int ndim = max(src_ndim, dst_ndim) + */ + __pyx_memoryview_broadcast_leading((&__pyx_v_dst), __pyx_v_dst_ndim, __pyx_v_src_ndim); + + /* "View.MemoryView":1282 + * if src_ndim < dst_ndim: + * broadcast_leading(&src, src_ndim, dst_ndim) + * elif dst_ndim < src_ndim: # <<<<<<<<<<<<<< + * broadcast_leading(&dst, dst_ndim, src_ndim) + * + */ + } + __pyx_L3:; + + /* "View.MemoryView":1285 + * broadcast_leading(&dst, dst_ndim, src_ndim) + * + * cdef int ndim = max(src_ndim, dst_ndim) # <<<<<<<<<<<<<< + * + * for i in range(ndim): + */ + __pyx_t_3 = __pyx_v_dst_ndim; + __pyx_t_4 = __pyx_v_src_ndim; + if (((__pyx_t_3 > __pyx_t_4) != 0)) { + __pyx_t_5 = __pyx_t_3; + } else { + __pyx_t_5 = __pyx_t_4; + } + __pyx_v_ndim = __pyx_t_5; + + /* "View.MemoryView":1287 + * cdef int ndim = max(src_ndim, dst_ndim) + * + * for i in range(ndim): # <<<<<<<<<<<<<< + * if src.shape[i] != dst.shape[i]: + * if src.shape[i] == 1: + */ + __pyx_t_5 = __pyx_v_ndim; + __pyx_t_3 = __pyx_t_5; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; + + /* "View.MemoryView":1288 + * + * for i in range(ndim): + * if src.shape[i] != dst.shape[i]: # <<<<<<<<<<<<<< + * if src.shape[i] == 1: + * broadcasting = True + */ + __pyx_t_2 = (((__pyx_v_src.shape[__pyx_v_i]) != (__pyx_v_dst.shape[__pyx_v_i])) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1289 + * for i in range(ndim): + * if src.shape[i] != dst.shape[i]: + * if src.shape[i] == 1: # <<<<<<<<<<<<<< + * broadcasting = True + * src.strides[i] = 0 + */ + __pyx_t_2 = (((__pyx_v_src.shape[__pyx_v_i]) == 1) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1290 + * if src.shape[i] != dst.shape[i]: + * if src.shape[i] == 1: + * broadcasting = True # <<<<<<<<<<<<<< + * src.strides[i] = 0 + * else: + */ + __pyx_v_broadcasting = 1; + + /* "View.MemoryView":1291 + * if src.shape[i] == 1: + * broadcasting = True + * src.strides[i] = 0 # <<<<<<<<<<<<<< + * else: + * _err_extents(i, dst.shape[i], src.shape[i]) + */ + (__pyx_v_src.strides[__pyx_v_i]) = 0; + + /* "View.MemoryView":1289 + * for i in range(ndim): + * if src.shape[i] != dst.shape[i]: + * if src.shape[i] == 1: # <<<<<<<<<<<<<< + * broadcasting = True + * src.strides[i] = 0 + */ + goto __pyx_L7; + } + + /* "View.MemoryView":1293 + * src.strides[i] = 0 + * else: + * _err_extents(i, dst.shape[i], src.shape[i]) # <<<<<<<<<<<<<< + * + * if src.suboffsets[i] >= 0: + */ + /*else*/ { + __pyx_t_6 = __pyx_memoryview_err_extents(__pyx_v_i, (__pyx_v_dst.shape[__pyx_v_i]), (__pyx_v_src.shape[__pyx_v_i])); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 1293, __pyx_L1_error) + } + __pyx_L7:; + + /* "View.MemoryView":1288 + * + * for i in range(ndim): + * if src.shape[i] != dst.shape[i]: # <<<<<<<<<<<<<< + * if src.shape[i] == 1: + * broadcasting = True + */ + } + + /* "View.MemoryView":1295 + * _err_extents(i, dst.shape[i], src.shape[i]) + * + * if src.suboffsets[i] >= 0: # <<<<<<<<<<<<<< + * _err_dim(ValueError, "Dimension %d is not direct", i) + * + */ + __pyx_t_2 = (((__pyx_v_src.suboffsets[__pyx_v_i]) >= 0) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1296 + * + * if src.suboffsets[i] >= 0: + * _err_dim(ValueError, "Dimension %d is not direct", i) # <<<<<<<<<<<<<< + * + * if slices_overlap(&src, &dst, ndim, itemsize): + */ + __pyx_t_6 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Dimension %d is not direct"), __pyx_v_i); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 1296, __pyx_L1_error) + + /* "View.MemoryView":1295 + * _err_extents(i, dst.shape[i], src.shape[i]) + * + * if src.suboffsets[i] >= 0: # <<<<<<<<<<<<<< + * _err_dim(ValueError, "Dimension %d is not direct", i) + * + */ + } + } + + /* "View.MemoryView":1298 + * _err_dim(ValueError, "Dimension %d is not direct", i) + * + * if slices_overlap(&src, &dst, ndim, itemsize): # <<<<<<<<<<<<<< + * + * if not slice_is_contig(src, order, ndim): + */ + __pyx_t_2 = (__pyx_slices_overlap((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1300 + * if slices_overlap(&src, &dst, ndim, itemsize): + * + * if not slice_is_contig(src, order, ndim): # <<<<<<<<<<<<<< + * order = get_best_order(&dst, ndim) + * + */ + __pyx_t_2 = ((!(__pyx_memviewslice_is_contig(__pyx_v_src, __pyx_v_order, __pyx_v_ndim) != 0)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1301 + * + * if not slice_is_contig(src, order, ndim): + * order = get_best_order(&dst, ndim) # <<<<<<<<<<<<<< + * + * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) + */ + __pyx_v_order = __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim); + + /* "View.MemoryView":1300 + * if slices_overlap(&src, &dst, ndim, itemsize): + * + * if not slice_is_contig(src, order, ndim): # <<<<<<<<<<<<<< + * order = get_best_order(&dst, ndim) + * + */ + } + + /* "View.MemoryView":1303 + * order = get_best_order(&dst, ndim) + * + * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) # <<<<<<<<<<<<<< + * src = tmp + * + */ + __pyx_t_7 = __pyx_memoryview_copy_data_to_temp((&__pyx_v_src), (&__pyx_v_tmp), __pyx_v_order, __pyx_v_ndim); if (unlikely(__pyx_t_7 == ((void *)NULL))) __PYX_ERR(1, 1303, __pyx_L1_error) + __pyx_v_tmpdata = __pyx_t_7; + + /* "View.MemoryView":1304 + * + * tmpdata = copy_data_to_temp(&src, &tmp, order, ndim) + * src = tmp # <<<<<<<<<<<<<< + * + * if not broadcasting: + */ + __pyx_v_src = __pyx_v_tmp; + + /* "View.MemoryView":1298 + * _err_dim(ValueError, "Dimension %d is not direct", i) + * + * if slices_overlap(&src, &dst, ndim, itemsize): # <<<<<<<<<<<<<< + * + * if not slice_is_contig(src, order, ndim): + */ + } + + /* "View.MemoryView":1306 + * src = tmp + * + * if not broadcasting: # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = ((!(__pyx_v_broadcasting != 0)) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1309 + * + * + * if slice_is_contig(src, 'C', ndim): # <<<<<<<<<<<<<< + * direct_copy = slice_is_contig(dst, 'C', ndim) + * elif slice_is_contig(src, 'F', ndim): + */ + __pyx_t_2 = (__pyx_memviewslice_is_contig(__pyx_v_src, 'C', __pyx_v_ndim) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1310 + * + * if slice_is_contig(src, 'C', ndim): + * direct_copy = slice_is_contig(dst, 'C', ndim) # <<<<<<<<<<<<<< + * elif slice_is_contig(src, 'F', ndim): + * direct_copy = slice_is_contig(dst, 'F', ndim) + */ + __pyx_v_direct_copy = __pyx_memviewslice_is_contig(__pyx_v_dst, 'C', __pyx_v_ndim); + + /* "View.MemoryView":1309 + * + * + * if slice_is_contig(src, 'C', ndim): # <<<<<<<<<<<<<< + * direct_copy = slice_is_contig(dst, 'C', ndim) + * elif slice_is_contig(src, 'F', ndim): + */ + goto __pyx_L12; + } + + /* "View.MemoryView":1311 + * if slice_is_contig(src, 'C', ndim): + * direct_copy = slice_is_contig(dst, 'C', ndim) + * elif slice_is_contig(src, 'F', ndim): # <<<<<<<<<<<<<< + * direct_copy = slice_is_contig(dst, 'F', ndim) + * + */ + __pyx_t_2 = (__pyx_memviewslice_is_contig(__pyx_v_src, 'F', __pyx_v_ndim) != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1312 + * direct_copy = slice_is_contig(dst, 'C', ndim) + * elif slice_is_contig(src, 'F', ndim): + * direct_copy = slice_is_contig(dst, 'F', ndim) # <<<<<<<<<<<<<< + * + * if direct_copy: + */ + __pyx_v_direct_copy = __pyx_memviewslice_is_contig(__pyx_v_dst, 'F', __pyx_v_ndim); + + /* "View.MemoryView":1311 + * if slice_is_contig(src, 'C', ndim): + * direct_copy = slice_is_contig(dst, 'C', ndim) + * elif slice_is_contig(src, 'F', ndim): # <<<<<<<<<<<<<< + * direct_copy = slice_is_contig(dst, 'F', ndim) + * + */ + } + __pyx_L12:; + + /* "View.MemoryView":1314 + * direct_copy = slice_is_contig(dst, 'F', ndim) + * + * if direct_copy: # <<<<<<<<<<<<<< + * + * refcount_copying(&dst, dtype_is_object, ndim, False) + */ + __pyx_t_2 = (__pyx_v_direct_copy != 0); + if (__pyx_t_2) { + + /* "View.MemoryView":1316 + * if direct_copy: + * + * refcount_copying(&dst, dtype_is_object, ndim, False) # <<<<<<<<<<<<<< + * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) + * refcount_copying(&dst, dtype_is_object, ndim, True) + */ + __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 0); + + /* "View.MemoryView":1317 + * + * refcount_copying(&dst, dtype_is_object, ndim, False) + * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) # <<<<<<<<<<<<<< + * refcount_copying(&dst, dtype_is_object, ndim, True) + * free(tmpdata) + */ + (void)(memcpy(__pyx_v_dst.data, __pyx_v_src.data, __pyx_memoryview_slice_get_size((&__pyx_v_src), __pyx_v_ndim))); + + /* "View.MemoryView":1318 + * refcount_copying(&dst, dtype_is_object, ndim, False) + * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) + * refcount_copying(&dst, dtype_is_object, ndim, True) # <<<<<<<<<<<<<< + * free(tmpdata) + * return 0 + */ + __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1); + + /* "View.MemoryView":1319 + * memcpy(dst.data, src.data, slice_get_size(&src, ndim)) + * refcount_copying(&dst, dtype_is_object, ndim, True) + * free(tmpdata) # <<<<<<<<<<<<<< + * return 0 + * + */ + free(__pyx_v_tmpdata); + + /* "View.MemoryView":1320 + * refcount_copying(&dst, dtype_is_object, ndim, True) + * free(tmpdata) + * return 0 # <<<<<<<<<<<<<< + * + * if order == 'F' == get_best_order(&dst, ndim): + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "View.MemoryView":1314 + * direct_copy = slice_is_contig(dst, 'F', ndim) + * + * if direct_copy: # <<<<<<<<<<<<<< + * + * refcount_copying(&dst, dtype_is_object, ndim, False) + */ + } + + /* "View.MemoryView":1306 + * src = tmp + * + * if not broadcasting: # <<<<<<<<<<<<<< + * + * + */ + } + + /* "View.MemoryView":1322 + * return 0 + * + * if order == 'F' == get_best_order(&dst, ndim): # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = (__pyx_v_order == 'F'); + if (__pyx_t_2) { + __pyx_t_2 = ('F' == __pyx_get_best_slice_order((&__pyx_v_dst), __pyx_v_ndim)); + } + __pyx_t_8 = (__pyx_t_2 != 0); + if (__pyx_t_8) { + + /* "View.MemoryView":1325 + * + * + * transpose_memslice(&src) # <<<<<<<<<<<<<< + * transpose_memslice(&dst) + * + */ + __pyx_t_5 = __pyx_memslice_transpose((&__pyx_v_src)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(1, 1325, __pyx_L1_error) + + /* "View.MemoryView":1326 + * + * transpose_memslice(&src) + * transpose_memslice(&dst) # <<<<<<<<<<<<<< + * + * refcount_copying(&dst, dtype_is_object, ndim, False) + */ + __pyx_t_5 = __pyx_memslice_transpose((&__pyx_v_dst)); if (unlikely(__pyx_t_5 == ((int)0))) __PYX_ERR(1, 1326, __pyx_L1_error) + + /* "View.MemoryView":1322 + * return 0 + * + * if order == 'F' == get_best_order(&dst, ndim): # <<<<<<<<<<<<<< + * + * + */ + } + + /* "View.MemoryView":1328 + * transpose_memslice(&dst) + * + * refcount_copying(&dst, dtype_is_object, ndim, False) # <<<<<<<<<<<<<< + * copy_strided_to_strided(&src, &dst, ndim, itemsize) + * refcount_copying(&dst, dtype_is_object, ndim, True) + */ + __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 0); + + /* "View.MemoryView":1329 + * + * refcount_copying(&dst, dtype_is_object, ndim, False) + * copy_strided_to_strided(&src, &dst, ndim, itemsize) # <<<<<<<<<<<<<< + * refcount_copying(&dst, dtype_is_object, ndim, True) + * + */ + copy_strided_to_strided((&__pyx_v_src), (&__pyx_v_dst), __pyx_v_ndim, __pyx_v_itemsize); + + /* "View.MemoryView":1330 + * refcount_copying(&dst, dtype_is_object, ndim, False) + * copy_strided_to_strided(&src, &dst, ndim, itemsize) + * refcount_copying(&dst, dtype_is_object, ndim, True) # <<<<<<<<<<<<<< + * + * free(tmpdata) + */ + __pyx_memoryview_refcount_copying((&__pyx_v_dst), __pyx_v_dtype_is_object, __pyx_v_ndim, 1); + + /* "View.MemoryView":1332 + * refcount_copying(&dst, dtype_is_object, ndim, True) + * + * free(tmpdata) # <<<<<<<<<<<<<< + * return 0 + * + */ + free(__pyx_v_tmpdata); + + /* "View.MemoryView":1333 + * + * free(tmpdata) + * return 0 # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_broadcast_leading') + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "View.MemoryView":1264 + * + * @cname('__pyx_memoryview_copy_contents') + * cdef int memoryview_copy_contents(__Pyx_memviewslice src, # <<<<<<<<<<<<<< + * __Pyx_memviewslice dst, + * int src_ndim, int dst_ndim, + */ + + /* function exit code */ + __pyx_L1_error:; + { + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_AddTraceback("View.MemoryView.memoryview_copy_contents", __pyx_clineno, __pyx_lineno, __pyx_filename); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif + } + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 1); + return __pyx_r; +} + +/* "View.MemoryView":1336 + * + * @cname('__pyx_memoryview_broadcast_leading') + * cdef void broadcast_leading(__Pyx_memviewslice *mslice, # <<<<<<<<<<<<<< + * int ndim, + * int ndim_other) nogil: + */ + +static void __pyx_memoryview_broadcast_leading(__Pyx_memviewslice *__pyx_v_mslice, int __pyx_v_ndim, int __pyx_v_ndim_other) { + int __pyx_v_i; + int __pyx_v_offset; + __Pyx_TraceDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_TraceCall("broadcast_leading", __pyx_f[1], 1336, 1, __PYX_ERR(1, 1336, __pyx_L1_error)); + + /* "View.MemoryView":1340 + * int ndim_other) nogil: + * cdef int i + * cdef int offset = ndim_other - ndim # <<<<<<<<<<<<<< + * + * for i in range(ndim - 1, -1, -1): + */ + __pyx_v_offset = (__pyx_v_ndim_other - __pyx_v_ndim); + + /* "View.MemoryView":1342 + * cdef int offset = ndim_other - ndim + * + * for i in range(ndim - 1, -1, -1): # <<<<<<<<<<<<<< + * mslice.shape[i + offset] = mslice.shape[i] + * mslice.strides[i + offset] = mslice.strides[i] + */ + for (__pyx_t_1 = (__pyx_v_ndim - 1); __pyx_t_1 > -1; __pyx_t_1-=1) { + __pyx_v_i = __pyx_t_1; + + /* "View.MemoryView":1343 + * + * for i in range(ndim - 1, -1, -1): + * mslice.shape[i + offset] = mslice.shape[i] # <<<<<<<<<<<<<< + * mslice.strides[i + offset] = mslice.strides[i] + * mslice.suboffsets[i + offset] = mslice.suboffsets[i] + */ + (__pyx_v_mslice->shape[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->shape[__pyx_v_i]); + + /* "View.MemoryView":1344 + * for i in range(ndim - 1, -1, -1): + * mslice.shape[i + offset] = mslice.shape[i] + * mslice.strides[i + offset] = mslice.strides[i] # <<<<<<<<<<<<<< + * mslice.suboffsets[i + offset] = mslice.suboffsets[i] + * + */ + (__pyx_v_mslice->strides[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->strides[__pyx_v_i]); + + /* "View.MemoryView":1345 + * mslice.shape[i + offset] = mslice.shape[i] + * mslice.strides[i + offset] = mslice.strides[i] + * mslice.suboffsets[i + offset] = mslice.suboffsets[i] # <<<<<<<<<<<<<< + * + * for i in range(offset): + */ + (__pyx_v_mslice->suboffsets[(__pyx_v_i + __pyx_v_offset)]) = (__pyx_v_mslice->suboffsets[__pyx_v_i]); + } + + /* "View.MemoryView":1347 + * mslice.suboffsets[i + offset] = mslice.suboffsets[i] + * + * for i in range(offset): # <<<<<<<<<<<<<< + * mslice.shape[i] = 1 + * mslice.strides[i] = mslice.strides[0] + */ + __pyx_t_1 = __pyx_v_offset; + __pyx_t_2 = __pyx_t_1; + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "View.MemoryView":1348 + * + * for i in range(offset): + * mslice.shape[i] = 1 # <<<<<<<<<<<<<< + * mslice.strides[i] = mslice.strides[0] + * mslice.suboffsets[i] = -1 + */ + (__pyx_v_mslice->shape[__pyx_v_i]) = 1; + + /* "View.MemoryView":1349 + * for i in range(offset): + * mslice.shape[i] = 1 + * mslice.strides[i] = mslice.strides[0] # <<<<<<<<<<<<<< + * mslice.suboffsets[i] = -1 + * + */ + (__pyx_v_mslice->strides[__pyx_v_i]) = (__pyx_v_mslice->strides[0]); + + /* "View.MemoryView":1350 + * mslice.shape[i] = 1 + * mslice.strides[i] = mslice.strides[0] + * mslice.suboffsets[i] = -1 # <<<<<<<<<<<<<< + * + * + */ + (__pyx_v_mslice->suboffsets[__pyx_v_i]) = -1L; + } + + /* "View.MemoryView":1336 + * + * @cname('__pyx_memoryview_broadcast_leading') + * cdef void broadcast_leading(__Pyx_memviewslice *mslice, # <<<<<<<<<<<<<< + * int ndim, + * int ndim_other) nogil: + */ + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView.broadcast_leading", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 1); +} + +/* "View.MemoryView":1358 + * + * @cname('__pyx_memoryview_refcount_copying') + * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object, # <<<<<<<<<<<<<< + * int ndim, bint inc) nogil: + * + */ + +static void __pyx_memoryview_refcount_copying(__Pyx_memviewslice *__pyx_v_dst, int __pyx_v_dtype_is_object, int __pyx_v_ndim, int __pyx_v_inc) { + __Pyx_TraceDeclarations + int __pyx_t_1; + __Pyx_TraceCall("refcount_copying", __pyx_f[1], 1358, 1, __PYX_ERR(1, 1358, __pyx_L1_error)); + + /* "View.MemoryView":1362 + * + * + * if dtype_is_object: # <<<<<<<<<<<<<< + * refcount_objects_in_slice_with_gil(dst.data, dst.shape, + * dst.strides, ndim, inc) + */ + __pyx_t_1 = (__pyx_v_dtype_is_object != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":1363 + * + * if dtype_is_object: + * refcount_objects_in_slice_with_gil(dst.data, dst.shape, # <<<<<<<<<<<<<< + * dst.strides, ndim, inc) + * + */ + __pyx_memoryview_refcount_objects_in_slice_with_gil(__pyx_v_dst->data, __pyx_v_dst->shape, __pyx_v_dst->strides, __pyx_v_ndim, __pyx_v_inc); + + /* "View.MemoryView":1362 + * + * + * if dtype_is_object: # <<<<<<<<<<<<<< + * refcount_objects_in_slice_with_gil(dst.data, dst.shape, + * dst.strides, ndim, inc) + */ + } + + /* "View.MemoryView":1358 + * + * @cname('__pyx_memoryview_refcount_copying') + * cdef void refcount_copying(__Pyx_memviewslice *dst, bint dtype_is_object, # <<<<<<<<<<<<<< + * int ndim, bint inc) nogil: + * + */ + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView.refcount_copying", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 1); +} + +/* "View.MemoryView":1367 + * + * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil') + * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< + * Py_ssize_t *strides, int ndim, + * bint inc) with gil: + */ + +static void __pyx_memoryview_refcount_objects_in_slice_with_gil(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, int __pyx_v_inc) { + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure(); + #endif + __Pyx_RefNannySetupContext("refcount_objects_in_slice_with_gil", 0); + __Pyx_TraceCall("refcount_objects_in_slice_with_gil", __pyx_f[1], 1367, 0, __PYX_ERR(1, 1367, __pyx_L1_error)); + + /* "View.MemoryView":1370 + * Py_ssize_t *strides, int ndim, + * bint inc) with gil: + * refcount_objects_in_slice(data, shape, strides, ndim, inc) # <<<<<<<<<<<<<< + * + * @cname('__pyx_memoryview_refcount_objects_in_slice') + */ + __pyx_memoryview_refcount_objects_in_slice(__pyx_v_data, __pyx_v_shape, __pyx_v_strides, __pyx_v_ndim, __pyx_v_inc); + + /* "View.MemoryView":1367 + * + * @cname('__pyx_memoryview_refcount_objects_in_slice_with_gil') + * cdef void refcount_objects_in_slice_with_gil(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< + * Py_ssize_t *strides, int ndim, + * bint inc) with gil: + */ + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView.refcount_objects_in_slice_with_gil", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + #ifdef WITH_THREAD + __Pyx_PyGILState_Release(__pyx_gilstate_save); + #endif +} + +/* "View.MemoryView":1373 + * + * @cname('__pyx_memoryview_refcount_objects_in_slice') + * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< + * Py_ssize_t *strides, int ndim, bint inc): + * cdef Py_ssize_t i + */ + +static void __pyx_memoryview_refcount_objects_in_slice(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, int __pyx_v_inc) { + CYTHON_UNUSED Py_ssize_t __pyx_v_i; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + Py_ssize_t __pyx_t_2; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("refcount_objects_in_slice", 0); + __Pyx_TraceCall("refcount_objects_in_slice", __pyx_f[1], 1373, 0, __PYX_ERR(1, 1373, __pyx_L1_error)); + + /* "View.MemoryView":1377 + * cdef Py_ssize_t i + * + * for i in range(shape[0]): # <<<<<<<<<<<<<< + * if ndim == 1: + * if inc: + */ + __pyx_t_1 = (__pyx_v_shape[0]); + __pyx_t_2 = __pyx_t_1; + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "View.MemoryView":1378 + * + * for i in range(shape[0]): + * if ndim == 1: # <<<<<<<<<<<<<< + * if inc: + * Py_INCREF(( data)[0]) + */ + __pyx_t_4 = ((__pyx_v_ndim == 1) != 0); + if (__pyx_t_4) { + + /* "View.MemoryView":1379 + * for i in range(shape[0]): + * if ndim == 1: + * if inc: # <<<<<<<<<<<<<< + * Py_INCREF(( data)[0]) + * else: + */ + __pyx_t_4 = (__pyx_v_inc != 0); + if (__pyx_t_4) { + + /* "View.MemoryView":1380 + * if ndim == 1: + * if inc: + * Py_INCREF(( data)[0]) # <<<<<<<<<<<<<< + * else: + * Py_DECREF(( data)[0]) + */ + Py_INCREF((((PyObject **)__pyx_v_data)[0])); + + /* "View.MemoryView":1379 + * for i in range(shape[0]): + * if ndim == 1: + * if inc: # <<<<<<<<<<<<<< + * Py_INCREF(( data)[0]) + * else: + */ + goto __pyx_L6; + } + + /* "View.MemoryView":1382 + * Py_INCREF(( data)[0]) + * else: + * Py_DECREF(( data)[0]) # <<<<<<<<<<<<<< + * else: + * refcount_objects_in_slice(data, shape + 1, strides + 1, + */ + /*else*/ { + Py_DECREF((((PyObject **)__pyx_v_data)[0])); + } + __pyx_L6:; + + /* "View.MemoryView":1378 + * + * for i in range(shape[0]): + * if ndim == 1: # <<<<<<<<<<<<<< + * if inc: + * Py_INCREF(( data)[0]) + */ + goto __pyx_L5; + } + + /* "View.MemoryView":1384 + * Py_DECREF(( data)[0]) + * else: + * refcount_objects_in_slice(data, shape + 1, strides + 1, # <<<<<<<<<<<<<< + * ndim - 1, inc) + * + */ + /*else*/ { + + /* "View.MemoryView":1385 + * else: + * refcount_objects_in_slice(data, shape + 1, strides + 1, + * ndim - 1, inc) # <<<<<<<<<<<<<< + * + * data += strides[0] + */ + __pyx_memoryview_refcount_objects_in_slice(__pyx_v_data, (__pyx_v_shape + 1), (__pyx_v_strides + 1), (__pyx_v_ndim - 1), __pyx_v_inc); + } + __pyx_L5:; + + /* "View.MemoryView":1387 + * ndim - 1, inc) + * + * data += strides[0] # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_data = (__pyx_v_data + (__pyx_v_strides[0])); + } + + /* "View.MemoryView":1373 + * + * @cname('__pyx_memoryview_refcount_objects_in_slice') + * cdef void refcount_objects_in_slice(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< + * Py_ssize_t *strides, int ndim, bint inc): + * cdef Py_ssize_t i + */ + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView.refcount_objects_in_slice", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); +} + +/* "View.MemoryView":1393 + * + * @cname('__pyx_memoryview_slice_assign_scalar') + * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim, # <<<<<<<<<<<<<< + * size_t itemsize, void *item, + * bint dtype_is_object) nogil: + */ + +static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *__pyx_v_dst, int __pyx_v_ndim, size_t __pyx_v_itemsize, void *__pyx_v_item, int __pyx_v_dtype_is_object) { + __Pyx_TraceDeclarations + __Pyx_TraceCall("slice_assign_scalar", __pyx_f[1], 1393, 1, __PYX_ERR(1, 1393, __pyx_L1_error)); + + /* "View.MemoryView":1396 + * size_t itemsize, void *item, + * bint dtype_is_object) nogil: + * refcount_copying(dst, dtype_is_object, ndim, False) # <<<<<<<<<<<<<< + * _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim, + * itemsize, item) + */ + __pyx_memoryview_refcount_copying(__pyx_v_dst, __pyx_v_dtype_is_object, __pyx_v_ndim, 0); + + /* "View.MemoryView":1397 + * bint dtype_is_object) nogil: + * refcount_copying(dst, dtype_is_object, ndim, False) + * _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim, # <<<<<<<<<<<<<< + * itemsize, item) + * refcount_copying(dst, dtype_is_object, ndim, True) + */ + __pyx_memoryview__slice_assign_scalar(__pyx_v_dst->data, __pyx_v_dst->shape, __pyx_v_dst->strides, __pyx_v_ndim, __pyx_v_itemsize, __pyx_v_item); + + /* "View.MemoryView":1399 + * _slice_assign_scalar(dst.data, dst.shape, dst.strides, ndim, + * itemsize, item) + * refcount_copying(dst, dtype_is_object, ndim, True) # <<<<<<<<<<<<<< + * + * + */ + __pyx_memoryview_refcount_copying(__pyx_v_dst, __pyx_v_dtype_is_object, __pyx_v_ndim, 1); + + /* "View.MemoryView":1393 + * + * @cname('__pyx_memoryview_slice_assign_scalar') + * cdef void slice_assign_scalar(__Pyx_memviewslice *dst, int ndim, # <<<<<<<<<<<<<< + * size_t itemsize, void *item, + * bint dtype_is_object) nogil: + */ + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView.slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 1); +} + +/* "View.MemoryView":1403 + * + * @cname('__pyx_memoryview__slice_assign_scalar') + * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< + * Py_ssize_t *strides, int ndim, + * size_t itemsize, void *item) nogil: + */ + +static void __pyx_memoryview__slice_assign_scalar(char *__pyx_v_data, Py_ssize_t *__pyx_v_shape, Py_ssize_t *__pyx_v_strides, int __pyx_v_ndim, size_t __pyx_v_itemsize, void *__pyx_v_item) { + CYTHON_UNUSED Py_ssize_t __pyx_v_i; + Py_ssize_t __pyx_v_stride; + Py_ssize_t __pyx_v_extent; + __Pyx_TraceDeclarations + int __pyx_t_1; + Py_ssize_t __pyx_t_2; + Py_ssize_t __pyx_t_3; + Py_ssize_t __pyx_t_4; + __Pyx_TraceCall("_slice_assign_scalar", __pyx_f[1], 1403, 1, __PYX_ERR(1, 1403, __pyx_L1_error)); + + /* "View.MemoryView":1407 + * size_t itemsize, void *item) nogil: + * cdef Py_ssize_t i + * cdef Py_ssize_t stride = strides[0] # <<<<<<<<<<<<<< + * cdef Py_ssize_t extent = shape[0] + * + */ + __pyx_v_stride = (__pyx_v_strides[0]); + + /* "View.MemoryView":1408 + * cdef Py_ssize_t i + * cdef Py_ssize_t stride = strides[0] + * cdef Py_ssize_t extent = shape[0] # <<<<<<<<<<<<<< + * + * if ndim == 1: + */ + __pyx_v_extent = (__pyx_v_shape[0]); + + /* "View.MemoryView":1410 + * cdef Py_ssize_t extent = shape[0] + * + * if ndim == 1: # <<<<<<<<<<<<<< + * for i in range(extent): + * memcpy(data, item, itemsize) + */ + __pyx_t_1 = ((__pyx_v_ndim == 1) != 0); + if (__pyx_t_1) { + + /* "View.MemoryView":1411 + * + * if ndim == 1: + * for i in range(extent): # <<<<<<<<<<<<<< + * memcpy(data, item, itemsize) + * data += stride + */ + __pyx_t_2 = __pyx_v_extent; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; + + /* "View.MemoryView":1412 + * if ndim == 1: + * for i in range(extent): + * memcpy(data, item, itemsize) # <<<<<<<<<<<<<< + * data += stride + * else: + */ + (void)(memcpy(__pyx_v_data, __pyx_v_item, __pyx_v_itemsize)); + + /* "View.MemoryView":1413 + * for i in range(extent): + * memcpy(data, item, itemsize) + * data += stride # <<<<<<<<<<<<<< + * else: + * for i in range(extent): + */ + __pyx_v_data = (__pyx_v_data + __pyx_v_stride); + } + + /* "View.MemoryView":1410 + * cdef Py_ssize_t extent = shape[0] + * + * if ndim == 1: # <<<<<<<<<<<<<< + * for i in range(extent): + * memcpy(data, item, itemsize) + */ + goto __pyx_L3; + } + + /* "View.MemoryView":1415 + * data += stride + * else: + * for i in range(extent): # <<<<<<<<<<<<<< + * _slice_assign_scalar(data, shape + 1, strides + 1, + * ndim - 1, itemsize, item) + */ + /*else*/ { + __pyx_t_2 = __pyx_v_extent; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; + + /* "View.MemoryView":1416 + * else: + * for i in range(extent): + * _slice_assign_scalar(data, shape + 1, strides + 1, # <<<<<<<<<<<<<< + * ndim - 1, itemsize, item) + * data += stride + */ + __pyx_memoryview__slice_assign_scalar(__pyx_v_data, (__pyx_v_shape + 1), (__pyx_v_strides + 1), (__pyx_v_ndim - 1), __pyx_v_itemsize, __pyx_v_item); + + /* "View.MemoryView":1418 + * _slice_assign_scalar(data, shape + 1, strides + 1, + * ndim - 1, itemsize, item) + * data += stride # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_data = (__pyx_v_data + __pyx_v_stride); + } + } + __pyx_L3:; + + /* "View.MemoryView":1403 + * + * @cname('__pyx_memoryview__slice_assign_scalar') + * cdef void _slice_assign_scalar(char *data, Py_ssize_t *shape, # <<<<<<<<<<<<<< + * Py_ssize_t *strides, int ndim, + * size_t itemsize, void *item) nogil: + */ + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("View.MemoryView._slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 1); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 1); +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0xb068931: + * from pickle import PickleError as __pyx_PickleError + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_15View_dot_MemoryView_1__pyx_unpickle_Enum = {"__pyx_unpickle_Enum", (PyCFunction)__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_15View_dot_MemoryView_1__pyx_unpickle_Enum(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_Enum (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_Enum") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Enum", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_15View_dot_MemoryView___pyx_unpickle_Enum(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = NULL; + PyObject *__pyx_v___pyx_result = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + __Pyx_TraceFrameInit(__pyx_codeobj__75) + __Pyx_RefNannySetupContext("__pyx_unpickle_Enum", 0); + __Pyx_TraceCall("__pyx_unpickle_Enum", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + + /* "(tree fragment)":2 + * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): + * if __pyx_checksum != 0xb068931: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + */ + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xb068931) != 0); + if (__pyx_t_1) { + + /* "(tree fragment)":3 + * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): + * if __pyx_checksum != 0xb068931: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + * __pyx_result = Enum.__new__(__pyx_type) + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":4 + * if __pyx_checksum != 0xb068931: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = Enum.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xb0, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_5) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) + + /* "(tree fragment)":2 + * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): + * if __pyx_checksum != 0xb068931: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + */ + } + + /* "(tree fragment)":5 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + * __pyx_result = Enum.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_MemviewEnum_type), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_INCREF(__pyx_v___pyx_type); + __Pyx_GIVEREF(__pyx_v___pyx_type); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + * __pyx_result = Enum.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_7 = (__pyx_t_1 != 0); + if (__pyx_t_7) { + + /* "(tree fragment)":7 + * __pyx_result = Enum.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_unpickle_Enum__set_state(((struct __pyx_MemviewEnum_obj *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xb068931 = (name))" % __pyx_checksum) + * __pyx_result = Enum.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":8 + * if __pyx_state is not None: + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): + * __pyx_result.name = __pyx_state[0] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0xb068931: + * from pickle import PickleError as __pyx_PickleError + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":9 + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.name = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + +static PyObject *__pyx_unpickle_Enum__set_state(struct __pyx_MemviewEnum_obj *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("__pyx_unpickle_Enum__set_state", 0); + __Pyx_TraceCall("__pyx_unpickle_Enum__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + + /* "(tree fragment)":10 + * return __pyx_result + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): + * __pyx_result.name = __pyx_state[0] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 10, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->name); + __Pyx_DECREF(__pyx_v___pyx_result->name); + __pyx_v___pyx_result->name = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":11 + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): + * __pyx_result.name = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(1, 11, __pyx_L1_error) + } + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = ((__pyx_t_3 > 1) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = (__pyx_t_4 != 0); + __pyx_t_2 = __pyx_t_5; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "(tree fragment)":12 + * __pyx_result.name = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_8) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":11 + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): + * __pyx_result.name = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + } + + /* "(tree fragment)":9 + * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.name = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("View.MemoryView.__pyx_unpickle_Enum__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment __pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment; + +static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment_AlignedSegment(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)o); + p->__pyx_vtab = __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment; + p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None); + p->cache_query_qualities = Py_None; Py_INCREF(Py_None); + p->cache_query_alignment_qualities = Py_None; Py_INCREF(Py_None); + p->cache_query_sequence = Py_None; Py_INCREF(Py_None); + p->cache_query_alignment_sequence = Py_None; Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_5pysam_18libcalignedsegment_AlignedSegment(PyObject *o) { + struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *p = (struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3__dealloc__(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_CLEAR(p->header); + Py_CLEAR(p->cache_query_qualities); + Py_CLEAR(p->cache_query_alignment_qualities); + Py_CLEAR(p->cache_query_sequence); + Py_CLEAR(p->cache_query_alignment_sequence); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_5pysam_18libcalignedsegment_AlignedSegment(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *p = (struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)o; + if (p->header) { + e = (*v)(((PyObject *)p->header), a); if (e) return e; + } + if (p->cache_query_qualities) { + e = (*v)(p->cache_query_qualities, a); if (e) return e; + } + if (p->cache_query_alignment_qualities) { + e = (*v)(p->cache_query_alignment_qualities, a); if (e) return e; + } + if (p->cache_query_sequence) { + e = (*v)(p->cache_query_sequence, a); if (e) return e; + } + if (p->cache_query_alignment_sequence) { + e = (*v)(p->cache_query_alignment_sequence, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5pysam_18libcalignedsegment_AlignedSegment(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *p = (struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)o; + tmp = ((PyObject*)p->header); + p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->cache_query_qualities); + p->cache_query_qualities = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->cache_query_alignment_qualities); + p->cache_query_alignment_qualities = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->cache_query_sequence); + p->cache_query_sequence = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->cache_query_alignment_sequence); + p->cache_query_alignment_sequence = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_name(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query_name(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10query_name_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_flag(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4flag_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_flag(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4flag_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_name(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_name(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14reference_name_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_id(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_id(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12reference_id_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_start(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_start(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15reference_start_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mapping_quality(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mapping_quality(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mapping_quality_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_cigarstring(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_cigarstring(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigarstring_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_id(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_id(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17next_reference_id_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_name(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_name(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19next_reference_name_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_start(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_start(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_20next_reference_start_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_length(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12query_length_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_template_length(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_template_length(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15template_length_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_sequence(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query_sequence(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14query_sequence_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_qualities(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query_qualities(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15query_qualities_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_bin(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3bin_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_bin(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3bin_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_paired(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_paired(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_paired_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_proper_pair(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_proper_pair(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_14is_proper_pair_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_unmapped(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_unmapped(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11is_unmapped_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_unmapped(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_unmapped(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16mate_is_unmapped_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_reverse(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_reverse(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_10is_reverse_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_reverse(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_reverse(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15mate_is_reverse_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read1(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read1(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read1_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read2(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read2(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_8is_read2_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_secondary(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_secondary(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_secondary_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_qcfail(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_qcfail(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9is_qcfail_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_duplicate(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_duplicate(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_12is_duplicate_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_supplementary(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_supplementary(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16is_supplementary_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_end(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13reference_end_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_length(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_16reference_length_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_sequence(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_24query_alignment_sequence_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_qualities(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_25query_alignment_qualities_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_start(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21query_alignment_start_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_end(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19query_alignment_end_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_length(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_22query_alignment_length_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_cigartuples(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_cigartuples(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11cigartuples_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qname(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qname_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qname(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qname_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_tid(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3tid_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_tid(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3tid_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_pos(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3pos_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_pos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3pos_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mapq(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mapq(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mapq_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_rnext(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_rnext(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rnext_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_pnext(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_pnext(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5pnext_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_cigar(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_cigar(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5cigar_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_tlen(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_tlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tlen_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_seq(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3seq_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_seq(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_3seq_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qual(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qual_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qual(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qual_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_alen(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4alen_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_alen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4alen_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_aend(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4aend_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_aend(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4aend_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_rlen(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_rlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4rlen_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5query_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5query_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qqual(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qqual(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5qqual_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qstart(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qstart(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6qstart_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qend(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qend_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qend(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qend_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qlen(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4qlen_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mrnm(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mrnm(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mrnm_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mpos(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mpos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4mpos_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_rname(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rname_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_rname(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5rname_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_isize(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5isize_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_isize(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5isize_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_blocks(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6blocks_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_aligned_pairs(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13aligned_pairs_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_inferred_length(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15inferred_length_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_positions(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9positions_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_tags(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tags_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_tags(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_4tags_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_header(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_6header_1__get__(o); +} + +static PyMethodDef __pyx_methods_5pysam_18libcalignedsegment_AlignedSegment[] = { + {"__copy__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_7__copy__, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_6__copy__}, + {"__deepcopy__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_9__deepcopy__, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_8__deepcopy__}, + {"compare", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_11compare, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_10compare}, + {"to_string", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_17to_string, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_16to_string}, + {"fromstring", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_19fromstring, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_18fromstring}, + {"tostring", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_21tostring, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_20tostring}, + {"to_dict", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_23to_dict, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_22to_dict}, + {"from_dict", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_25from_dict, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_24from_dict}, + {"get_reference_positions", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_27get_reference_positions, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_26get_reference_positions}, + {"infer_query_length", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_29infer_query_length, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_28infer_query_length}, + {"infer_read_length", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_31infer_read_length, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_30infer_read_length}, + {"get_reference_sequence", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_33get_reference_sequence, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_32get_reference_sequence}, + {"get_forward_sequence", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_35get_forward_sequence, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_34get_forward_sequence}, + {"get_forward_qualities", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_37get_forward_qualities, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_36get_forward_qualities}, + {"get_aligned_pairs", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_39get_aligned_pairs, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_38get_aligned_pairs}, + {"get_blocks", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_41get_blocks, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_40get_blocks}, + {"get_overlap", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_43get_overlap, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_42get_overlap}, + {"get_cigar_stats", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_45get_cigar_stats, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_44get_cigar_stats}, + {"set_tag", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_47set_tag, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_46set_tag}, + {"has_tag", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_49has_tag, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_48has_tag}, + {"get_tag", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_51get_tag, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_50get_tag}, + {"get_tags", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_53get_tags, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_52get_tags}, + {"set_tags", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_55set_tags, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_54set_tags}, + {"overlap", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_57overlap, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_56overlap}, + {"opt", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_59opt, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_58opt}, + {"setTag", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_61setTag, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_60setTag}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_63__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_62__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_65__setstate_cython__, METH_O, __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_64__setstate_cython__}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5pysam_18libcalignedsegment_AlignedSegment[] = { + {(char *)"query_name", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_name, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query_name, (char *)"the query template name (None if not present)", 0}, + {(char *)"flag", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_flag, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_flag, (char *)"properties flag", 0}, + {(char *)"reference_name", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_name, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_name, (char *)":term:`reference` name", 0}, + {(char *)"reference_id", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_id, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_id, (char *)":term:`reference` ID\n\n .. note::\n\n This field contains the index of the reference sequence in\n the sequence dictionary. To obtain the name of the\n reference sequence, use :meth:`get_reference_name()`\n\n ", 0}, + {(char *)"reference_start", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_start, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_start, (char *)"0-based leftmost coordinate", 0}, + {(char *)"mapping_quality", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mapping_quality, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mapping_quality, (char *)"mapping quality", 0}, + {(char *)"cigarstring", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_cigarstring, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_cigarstring, (char *)"the :term:`cigar` alignment as a string.\n\n The cigar string is a string of alternating integers\n and characters denoting the length and the type of\n an operation.\n\n .. note::\n The order length,operation is specified in the\n SAM format. It is different from the order of\n the :attr:`cigar` property.\n\n Returns None if not present.\n\n To unset the cigarstring, assign None or the\n empty string.\n ", 0}, + {(char *)"next_reference_id", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_id, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_id, (char *)"the :term:`reference` id of the mate/next read.", 0}, + {(char *)"next_reference_name", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_name, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_name, (char *)":term:`reference` name of the mate/next read (None if no\n AlignmentFile is associated)", 0}, + {(char *)"next_reference_start", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_start, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_next_reference_start, (char *)"the position of the mate/next read.", 0}, + {(char *)"query_length", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_length, 0, (char *)"the length of the query/read.\n\n This value corresponds to the length of the sequence supplied\n in the BAM/SAM file. The length of a query is 0 if there is no\n sequence in the BAM/SAM file. In those cases, the read length\n can be inferred from the CIGAR alignment, see\n :meth:`pysam.AlignedSegment.infer_query_length`.\n\n The length includes soft-clipped bases and is equal to\n ``len(query_sequence)``.\n\n This property is read-only but can be set by providing a\n sequence.\n\n Returns 0 if not available.\n\n ", 0}, + {(char *)"template_length", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_template_length, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_template_length, (char *)"the observed query template length", 0}, + {(char *)"query_sequence", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_sequence, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query_sequence, (char *)"read sequence bases, including :term:`soft clipped` bases\n (None if not present).\n\n Note that assigning to seq will invalidate any quality scores.\n Thus, to in-place edit the sequence and quality scores, copies of\n the quality scores need to be taken. Consider trimming for example::\n\n q = read.query_qualities\n read.query_squence = read.query_sequence[5:10]\n read.query_qualities = q[5:10]\n\n The sequence is returned as it is stored in the BAM file. Some mappers\n might have stored a reverse complement of the original read\n sequence.\n ", 0}, + {(char *)"query_qualities", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_qualities, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query_qualities, (char *)"read sequence base qualities, including :term:`soft\n clipped` bases (None if not present).\n\n Quality scores are returned as a python array of unsigned\n chars. Note that this is not the ASCII-encoded value typically\n seen in FASTQ or SAM formatted files. Thus, no offset of 33\n needs to be subtracted.\n\n Note that to set quality scores the sequence has to be set\n beforehand as this will determine the expected length of the\n quality score array.\n\n This method raises a ValueError if the length of the\n quality scores and the sequence are not the same.\n\n ", 0}, + {(char *)"bin", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_bin, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_bin, (char *)"properties bin", 0}, + {(char *)"is_paired", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_paired, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_paired, (char *)"true if read is paired in sequencing", 0}, + {(char *)"is_proper_pair", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_proper_pair, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_proper_pair, (char *)"true if read is mapped in a proper pair", 0}, + {(char *)"is_unmapped", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_unmapped, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_unmapped, (char *)"true if read itself is unmapped", 0}, + {(char *)"mate_is_unmapped", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_unmapped, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_unmapped, (char *)"true if the mate is unmapped", 0}, + {(char *)"is_reverse", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_reverse, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_reverse, (char *)"true if read is mapped to reverse strand", 0}, + {(char *)"mate_is_reverse", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_reverse, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mate_is_reverse, (char *)"true is read is mapped to reverse strand", 0}, + {(char *)"is_read1", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read1, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read1, (char *)"true if this is read1", 0}, + {(char *)"is_read2", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read2, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_read2, (char *)"true if this is read2", 0}, + {(char *)"is_secondary", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_secondary, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_secondary, (char *)"true if not primary alignment", 0}, + {(char *)"is_qcfail", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_qcfail, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_qcfail, (char *)"true if QC failure", 0}, + {(char *)"is_duplicate", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_duplicate, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_duplicate, (char *)"true if optical or PCR duplicate", 0}, + {(char *)"is_supplementary", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_is_supplementary, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_is_supplementary, (char *)"true if this is a supplementary alignment", 0}, + {(char *)"reference_end", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_end, 0, (char *)"aligned reference position of the read on the reference genome.\n\n reference_end points to one past the last aligned residue.\n Returns None if not available (read is unmapped or no cigar\n alignment present).\n\n ", 0}, + {(char *)"reference_length", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_reference_length, 0, (char *)"aligned length of the read on the reference genome.\n\n This is equal to `aend - pos`. Returns None if not available.", 0}, + {(char *)"query_alignment_sequence", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_sequence, 0, (char *)"aligned portion of the read.\n\n This is a substring of :attr:`seq` that excludes flanking\n bases that were :term:`soft clipped` (None if not present). It\n is equal to ``seq[qstart:qend]``.\n\n SAM/BAM files may include extra flanking bases that are not\n part of the alignment. These bases may be the result of the\n Smith-Waterman or other algorithms, which may not require\n alignments that begin at the first residue or end at the last.\n In addition, extra sequencing adapters, multiplex identifiers,\n and low-quality bases that were not considered for alignment\n may have been retained.\n\n ", 0}, + {(char *)"query_alignment_qualities", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_qualities, 0, (char *)"aligned query sequence quality values (None if not present). These\n are the quality values that correspond to :attr:`query`, that\n is, they exclude qualities of :term:`soft clipped` bases. This\n is equal to ``qual[qstart:qend]``.\n\n Quality scores are returned as a python array of unsigned\n chars. Note that this is not the ASCII-encoded value typically\n seen in FASTQ or SAM formatted files. Thus, no offset of 33\n needs to be subtracted.\n\n This property is read-only.\n\n ", 0}, + {(char *)"query_alignment_start", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_start, 0, (char *)"start index of the aligned query portion of the sequence (0-based,\n inclusive).\n\n This the index of the first base in :attr:`seq` that is not\n soft-clipped.\n ", 0}, + {(char *)"query_alignment_end", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_end, 0, (char *)"end index of the aligned query portion of the sequence (0-based,\n exclusive)\n\n This the index just past the last base in :attr:`seq` that is not\n soft-clipped.\n ", 0}, + {(char *)"query_alignment_length", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query_alignment_length, 0, (char *)"length of the aligned query sequence.\n\n This is equal to :attr:`qend` - :attr:`qstart`", 0}, + {(char *)"cigartuples", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_cigartuples, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_cigartuples, (char *)"the :term:`cigar` alignment. The alignment\n is returned as a list of tuples of (operation, length).\n\n If the alignment is not present, None is returned.\n\n The operations are:\n\n +-----+--------------+-----+\n |M |BAM_CMATCH |0 |\n +-----+--------------+-----+\n |I |BAM_CINS |1 |\n +-----+--------------+-----+\n |D |BAM_CDEL |2 |\n +-----+--------------+-----+\n |N |BAM_CREF_SKIP |3 |\n +-----+--------------+-----+\n |S |BAM_CSOFT_CLIP|4 |\n +-----+--------------+-----+\n |H |BAM_CHARD_CLIP|5 |\n +-----+--------------+-----+\n |P |BAM_CPAD |6 |\n +-----+--------------+-----+\n |= |BAM_CEQUAL |7 |\n +-----+--------------+-----+\n |X |BAM_CDIFF |8 |\n +-----+--------------+-----+\n |B |BAM_CBACK |9 |\n +-----+--------------+-----+\n\n .. note::\n The output is a list of (operation, length) tuples, such as\n ``[(0, 30)]``.\n This is different from the SAM specification and\n the :attr:`cigarstring` property, which uses a\n (length, operation) order, for example: ``30M``.\n\n To unset the cigar property, assign an empty list\n or None.\n ", 0}, + {(char *)"qname", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qname, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qname, (char *)"deprecated, use query_name instead", 0}, + {(char *)"tid", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_tid, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_tid, (char *)"deprecated, use reference_id instead", 0}, + {(char *)"pos", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_pos, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_pos, (char *)"deprecated, use reference_start instead", 0}, + {(char *)"mapq", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mapq, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mapq, (char *)"deprecated, use mapping_quality instead", 0}, + {(char *)"rnext", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_rnext, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_rnext, (char *)"deprecated, use next_reference_id instead", 0}, + {(char *)"pnext", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_pnext, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_pnext, (char *)"deprecated, use next_reference_start instead", 0}, + {(char *)"cigar", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_cigar, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_cigar, (char *)"deprecated, use cigartuples instead", 0}, + {(char *)"tlen", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_tlen, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_tlen, (char *)"deprecated, use template_length instead", 0}, + {(char *)"seq", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_seq, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_seq, (char *)"deprecated, use query_sequence instead", 0}, + {(char *)"qual", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qual, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qual, (char *)"deprecated, query_qualities instead", 0}, + {(char *)"alen", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_alen, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_alen, (char *)"deprecated, reference_length instead", 0}, + {(char *)"aend", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_aend, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_aend, (char *)"deprecated, reference_end instead", 0}, + {(char *)"rlen", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_rlen, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_rlen, (char *)"deprecated, query_length instead", 0}, + {(char *)"query", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_query, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_query, (char *)"deprecated, query_alignment_sequence instead", 0}, + {(char *)"qqual", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qqual, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qqual, (char *)"deprecated, query_alignment_qualities instead", 0}, + {(char *)"qstart", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qstart, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qstart, (char *)"deprecated, use query_alignment_start instead", 0}, + {(char *)"qend", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qend, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qend, (char *)"deprecated, use query_alignment_end instead", 0}, + {(char *)"qlen", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_qlen, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_qlen, (char *)"deprecated, use query_alignment_length instead", 0}, + {(char *)"mrnm", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mrnm, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mrnm, (char *)"deprecated, use next_reference_id instead", 0}, + {(char *)"mpos", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_mpos, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_mpos, (char *)"deprecated, use next_reference_start instead", 0}, + {(char *)"rname", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_rname, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_rname, (char *)"deprecated, use reference_id instead", 0}, + {(char *)"isize", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_isize, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_isize, (char *)"deprecated, use template_length instead", 0}, + {(char *)"blocks", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_blocks, 0, (char *)"deprecated, use get_blocks() instead", 0}, + {(char *)"aligned_pairs", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_aligned_pairs, 0, (char *)"deprecated, use get_aligned_pairs() instead", 0}, + {(char *)"inferred_length", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_inferred_length, 0, (char *)"deprecated, use infer_query_length() instead", 0}, + {(char *)"positions", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_positions, 0, (char *)"deprecated, use get_reference_positions() instead", 0}, + {(char *)"tags", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_tags, __pyx_setprop_5pysam_18libcalignedsegment_14AlignedSegment_tags, (char *)"deprecated, use get_tags() instead", 0}, + {(char *)"header", __pyx_getprop_5pysam_18libcalignedsegment_14AlignedSegment_header, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_5pysam_18libcalignedsegment_AlignedSegment = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignedsegment.AlignedSegment", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_18libcalignedsegment_AlignedSegment, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_15__hash__, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_5__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "AlignedSegment(AlignmentHeader header=None)\nClass representing an aligned segment.\n\n This class stores a handle to the samtools C-structure representing\n an aligned read. Member read access is forwarded to the C-structure\n and converted into python objects. This implementation should be fast,\n as only the data needed is converted.\n\n For write access, the C-structure is updated in-place. This is\n not the most efficient way to build BAM entries, as the variable\n length data is concatenated and thus needs to be resized if\n a field is updated. Furthermore, the BAM entry might be\n in an inconsistent state.\n\n One issue to look out for is that the sequence should always\n be set *before* the quality scores. Setting the sequence will\n also erase any quality scores that were set previously.\n\n Parameters\n ----------\n\n header -- :class:`~pysam.AlignmentHeader` object to map numerical\n identifiers to chromosome names. If not given, an empty\n header is created.\n ", /*tp_doc*/ + __pyx_tp_traverse_5pysam_18libcalignedsegment_AlignedSegment, /*tp_traverse*/ + __pyx_tp_clear_5pysam_18libcalignedsegment_AlignedSegment, /*tp_clear*/ + __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_13__richcmp__, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5pysam_18libcalignedsegment_AlignedSegment, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5pysam_18libcalignedsegment_AlignedSegment, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_5pysam_18libcalignedsegment_14AlignedSegment_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_18libcalignedsegment_AlignedSegment, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment_PileupColumn(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)o); + p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_5pysam_18libcalignedsegment_PileupColumn(PyObject *o) { + struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *p = (struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_5__dealloc__(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_CLEAR(p->header); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_5pysam_18libcalignedsegment_PileupColumn(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *p = (struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)o; + if (p->header) { + e = (*v)(((PyObject *)p->header), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5pysam_18libcalignedsegment_PileupColumn(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *p = (struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *)o; + tmp = ((PyObject*)p->header); + p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_reference_id(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_12reference_id_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_reference_name(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_14reference_name_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_nsegments(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_nsegments(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9nsegments_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_reference_pos(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_13reference_pos_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_pileups(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_7pileups_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_pos(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3pos_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_pos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3pos_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_tid(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3tid_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_tid(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3tid_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_n(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1n_1__get__(o); +} + +static int __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_n(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1n_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyMethodDef __pyx_methods_5pysam_18libcalignedsegment_PileupColumn[] = { + {"set_min_base_quality", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_7set_min_base_quality, METH_O, __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_6set_min_base_quality}, + {"get_num_aligned", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_11get_num_aligned, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_10get_num_aligned}, + {"get_query_sequences", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_13get_query_sequences, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_12get_query_sequences}, + {"get_query_qualities", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_15get_query_qualities, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_14get_query_qualities}, + {"get_mapping_qualities", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_17get_mapping_qualities, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_16get_mapping_qualities}, + {"get_query_positions", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_19get_query_positions, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_18get_query_positions}, + {"get_query_names", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_21get_query_names, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_20get_query_names}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_23__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_22__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_25__setstate_cython__, METH_O, __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_24__setstate_cython__}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5pysam_18libcalignedsegment_PileupColumn[] = { + {(char *)"reference_id", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_reference_id, 0, (char *)"the reference sequence number as defined in the header", 0}, + {(char *)"reference_name", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_reference_name, 0, (char *)":term:`reference` name (None if no AlignmentFile is associated)", 0}, + {(char *)"nsegments", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_nsegments, __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_nsegments, (char *)"number of reads mapping to this column.\n\n Note that this number ignores the base quality filter.", 0}, + {(char *)"reference_pos", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_reference_pos, 0, (char *)"the position in the reference sequence (0-based).", 0}, + {(char *)"pileups", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_pileups, 0, (char *)"list of reads (:class:`pysam.PileupRead`) aligned to this column", 0}, + {(char *)"pos", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_pos, __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_pos, (char *)"deprecated: use reference_pos", 0}, + {(char *)"tid", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_tid, __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_tid, (char *)"deprecated: use reference_id", 0}, + {(char *)"n", __pyx_getprop_5pysam_18libcalignedsegment_12PileupColumn_n, __pyx_setprop_5pysam_18libcalignedsegment_12PileupColumn_n, (char *)"deprecated: use nsegments", 0}, + {0, 0, 0, 0, 0} +}; + +static PySequenceMethods __pyx_tp_as_sequence_PileupColumn = { + __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_PileupColumn = { + __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_9__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyTypeObject __pyx_type_5pysam_18libcalignedsegment_PileupColumn = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignedsegment.PileupColumn", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_18libcalignedsegment_PileupColumn, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + &__pyx_tp_as_sequence_PileupColumn, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_PileupColumn, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_3__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "PileupColumn()\nA pileup of reads at a particular reference sequence position\n (:term:`column`). A pileup column contains all the reads that map\n to a certain target base.\n\n This class is a proxy for results returned by the samtools pileup\n engine. If the underlying engine iterator advances, the results\n of this column will change.\n ", /*tp_doc*/ + __pyx_tp_traverse_5pysam_18libcalignedsegment_PileupColumn, /*tp_traverse*/ + __pyx_tp_clear_5pysam_18libcalignedsegment_PileupColumn, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5pysam_18libcalignedsegment_PileupColumn, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5pysam_18libcalignedsegment_PileupColumn, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_5pysam_18libcalignedsegment_12PileupColumn_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_18libcalignedsegment_PileupColumn, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment_PileupRead(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)o); + p->_alignment = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)Py_None); Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_5pysam_18libcalignedsegment_PileupRead(PyObject *o) { + struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *p = (struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->_alignment); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_5pysam_18libcalignedsegment_PileupRead(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *p = (struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)o; + if (p->_alignment) { + e = (*v)(((PyObject *)p->_alignment), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5pysam_18libcalignedsegment_PileupRead(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *p = (struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *)o; + tmp = ((PyObject*)p->_alignment); + p->_alignment = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_alignment(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_9alignment_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_query_position(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_14query_position_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_query_position_or_next(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_22query_position_or_next_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_indel(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5indel_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_level(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5level_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_del(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_6is_del_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_head(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7is_head_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_tail(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7is_tail_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_refskip(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_10is_refskip_1__get__(o); +} + +static PyMethodDef __pyx_methods_5pysam_18libcalignedsegment_PileupRead[] = { + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_5__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_18libcalignedsegment_10PileupRead_4__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_18libcalignedsegment_10PileupRead_7__setstate_cython__, METH_O, __pyx_doc_5pysam_18libcalignedsegment_10PileupRead_6__setstate_cython__}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5pysam_18libcalignedsegment_PileupRead[] = { + {(char *)"alignment", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_alignment, 0, (char *)"a :class:`pysam.AlignedSegment` object of the aligned read", 0}, + {(char *)"query_position", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_query_position, 0, (char *)"position of the read base at the pileup site, 0-based.\n None if is_del or is_refskip is set.\n\n ", 0}, + {(char *)"query_position_or_next", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_query_position_or_next, 0, (char *)"position of the read base at the pileup site, 0-based.\n\n If the current position is a deletion, returns the next\n aligned base.\n\n ", 0}, + {(char *)"indel", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_indel, 0, (char *)"indel length for the position following the current pileup site.\n\n This quantity peeks ahead to the next cigar operation in this\n alignment. If the next operation is an insertion, indel will\n be positive. If the next operation is a deletion, it will be\n negation. 0 if the next operation is not an indel.\n\n ", 0}, + {(char *)"level", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_level, 0, (char *)"the level of the read in the \"viewer\" mode. Note that this value\n is currently not computed.", 0}, + {(char *)"is_del", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_del, 0, (char *)"1 iff the base on the padded read is a deletion", 0}, + {(char *)"is_head", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_head, 0, (char *)"1 iff the base on the padded read is the left-most base.", 0}, + {(char *)"is_tail", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_tail, 0, (char *)"1 iff the base on the padded read is the right-most base.", 0}, + {(char *)"is_refskip", __pyx_getprop_5pysam_18libcalignedsegment_10PileupRead_is_refskip, 0, (char *)"1 iff the base on the padded read is part of CIGAR N op.", 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_5pysam_18libcalignedsegment_PileupRead = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignedsegment.PileupRead", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_18libcalignedsegment_PileupRead, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_3__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "PileupRead()\nRepresentation of a read aligned to a particular position in the\n reference sequence.\n\n ", /*tp_doc*/ + __pyx_tp_traverse_5pysam_18libcalignedsegment_PileupRead, /*tp_traverse*/ + __pyx_tp_clear_5pysam_18libcalignedsegment_PileupRead, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5pysam_18libcalignedsegment_PileupRead, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5pysam_18libcalignedsegment_PileupRead, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_5pysam_18libcalignedsegment_10PileupRead_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_18libcalignedsegment_PileupRead, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *__pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr[8]; +static int __pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr = 0; + +static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr)))) { + o = (PyObject*)__pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr[--__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr]; + memset(o, 0, sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr)); + (void) PyObject_INIT(o, t); + PyObject_GC_Track(o); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } + return o; +} + +static void __pyx_tp_dealloc_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr(PyObject *o) { + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *)o; + PyObject_GC_UnTrack(o); + Py_CLEAR(p->__pyx_v_x); + Py_CLEAR(p->__pyx_v_y); + Py_CLEAR(p->__pyx_t_0); + Py_CLEAR(p->__pyx_t_1); + if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr)))) { + __pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr[__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr++] = ((struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); + } +} + +static int __pyx_tp_traverse_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr *)o; + if (p->__pyx_v_x) { + e = (*v)(p->__pyx_v_x, a); if (e) return e; + } + if (p->__pyx_v_y) { + e = (*v)(p->__pyx_v_y, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; + } + if (p->__pyx_t_1) { + e = (*v)(p->__pyx_t_1, a); if (e) return e; + } + return 0; +} + +static PyTypeObject __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignedsegment.__pyx_scope_struct__genexpr", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + 0, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *__pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr[8]; +static int __pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr = 0; + +static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr)))) { + o = (PyObject*)__pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr[--__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr]; + memset(o, 0, sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr)); + (void) PyObject_INIT(o, t); + PyObject_GC_Track(o); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } + return o; +} + +static void __pyx_tp_dealloc_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr(PyObject *o) { + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *)o; + PyObject_GC_UnTrack(o); + Py_CLEAR(p->__pyx_v_x); + Py_CLEAR(p->__pyx_v_y); + Py_CLEAR(p->__pyx_t_0); + Py_CLEAR(p->__pyx_t_1); + if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr)))) { + __pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr[__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr++] = ((struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); + } +} + +static int __pyx_tp_traverse_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *)o; + if (p->__pyx_v_x) { + e = (*v)(p->__pyx_v_x, a); if (e) return e; + } + if (p->__pyx_v_y) { + e = (*v)(p->__pyx_v_y, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; + } + if (p->__pyx_t_1) { + e = (*v)(p->__pyx_t_1, a); if (e) return e; + } + return 0; +} + +static PyTypeObject __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignedsegment.__pyx_scope_struct_1_genexpr", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + 0, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *__pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict[8]; +static int __pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict = 0; + +static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict)))) { + o = (PyObject*)__pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict[--__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict]; + memset(o, 0, sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict)); + (void) PyObject_INIT(o, t); + PyObject_GC_Track(o); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } + return o; +} + +static void __pyx_tp_dealloc_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict(PyObject *o) { + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *)o; + PyObject_GC_UnTrack(o); + Py_CLEAR(p->__pyx_v_sam_dict); + if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict)))) { + __pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict[__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict++] = ((struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); + } +} + +static int __pyx_tp_traverse_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *)o; + if (p->__pyx_v_sam_dict) { + e = (*v)(p->__pyx_v_sam_dict, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict *)o; + tmp = ((PyObject*)p->__pyx_v_sam_dict); + p->__pyx_v_sam_dict = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyTypeObject __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignedsegment.__pyx_scope_struct_2_from_dict", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict, /*tp_traverse*/ + __pyx_tp_clear_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + 0, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr *__pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr[8]; +static int __pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr = 0; + +static PyObject *__pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr)))) { + o = (PyObject*)__pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr[--__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr]; + memset(o, 0, sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr)); + (void) PyObject_INIT(o, t); + PyObject_GC_Track(o); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } + return o; +} + +static void __pyx_tp_dealloc_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr(PyObject *o) { + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr *)o; + PyObject_GC_UnTrack(o); + Py_CLEAR(p->__pyx_outer_scope); + Py_CLEAR(p->__pyx_v_x); + Py_CLEAR(p->__pyx_t_0); + if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr)))) { + __pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr[__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr++] = ((struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); + } +} + +static int __pyx_tp_traverse_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr *)o; + if (p->__pyx_outer_scope) { + e = (*v)(((PyObject *)p->__pyx_outer_scope), a); if (e) return e; + } + if (p->__pyx_v_x) { + e = (*v)(p->__pyx_v_x, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; + } + return 0; +} + +static PyTypeObject __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignedsegment.__pyx_scope_struct_3_genexpr", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + 0, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyObject *__pyx_tp_new___Pyx_EnumMeta(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (&PyType_Type)->tp_new(t, a, k); + if (unlikely(!o)) return 0; + return o; +} + +static void __pyx_tp_dealloc___Pyx_EnumMeta(PyObject *o) { + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + PyObject_GC_Track(o); + (&PyType_Type)->tp_dealloc(o); +} + +static int __pyx_tp_traverse___Pyx_EnumMeta(PyObject *o, visitproc v, void *a) { + int e; + if (!(&PyType_Type)->tp_traverse); else { e = (&PyType_Type)->tp_traverse(o,v,a); if (e) return e; } + return 0; +} + +static int __pyx_tp_clear___Pyx_EnumMeta(PyObject *o) { + if (!(&PyType_Type)->tp_clear); else (&PyType_Type)->tp_clear(o); + return 0; +} +static PyObject *__pyx_sq_item___Pyx_EnumMeta(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static PyMethodDef __pyx_methods___Pyx_EnumMeta[] = { + {"__reduce_cython__", (PyCFunction)__pyx_pw_8EnumBase_14__Pyx_EnumMeta_7__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_8EnumBase_14__Pyx_EnumMeta_9__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static PySequenceMethods __pyx_tp_as_sequence___Pyx_EnumMeta = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item___Pyx_EnumMeta, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping___Pyx_EnumMeta = { + 0, /*mp_length*/ + __pyx_pw_8EnumBase_14__Pyx_EnumMeta_5__getitem__, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyTypeObject __Pyx_EnumMeta = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignedsegment.__Pyx_EnumMeta", /*tp_name*/ + sizeof(struct __pyx_obj___Pyx_EnumMeta), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc___Pyx_EnumMeta, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + &__pyx_tp_as_sequence___Pyx_EnumMeta, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___Pyx_EnumMeta, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse___Pyx_EnumMeta, /*tp_traverse*/ + __pyx_tp_clear___Pyx_EnumMeta, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_8EnumBase_14__Pyx_EnumMeta_3__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods___Pyx_EnumMeta, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_8EnumBase_14__Pyx_EnumMeta_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new___Pyx_EnumMeta, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; +static struct __pyx_vtabstruct_array __pyx_vtable_array; + +static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_array_obj *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_array_obj *)o); + p->__pyx_vtab = __pyx_vtabptr_array; + p->mode = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->_format = ((PyObject*)Py_None); Py_INCREF(Py_None); + if (unlikely(__pyx_array___cinit__(o, a, k) < 0)) goto bad; + return o; + bad: + Py_DECREF(o); o = 0; + return NULL; +} + +static void __pyx_tp_dealloc_array(PyObject *o) { + struct __pyx_array_obj *p = (struct __pyx_array_obj *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_array___dealloc__(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_CLEAR(p->mode); + Py_CLEAR(p->_format); + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_array(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_array(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_array___setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyObject *__pyx_tp_getattro_array(PyObject *o, PyObject *n) { + PyObject *v = __Pyx_PyObject_GenericGetAttr(o, n); + if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + v = __pyx_array___getattr__(o, n); + } + return v; +} + +static PyObject *__pyx_getprop___pyx_array_memview(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(o); +} + +static PyMethodDef __pyx_methods_array[] = { + {"__getattr__", (PyCFunction)__pyx_array___getattr__, METH_O|METH_COEXIST, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_array_1__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_array_3__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_array[] = { + {(char *)"memview", __pyx_getprop___pyx_array_memview, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PySequenceMethods __pyx_tp_as_sequence_array = { + __pyx_array___len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_array, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_array = { + __pyx_array___len__, /*mp_length*/ + __pyx_array___getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_array, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_array = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + __pyx_array_getbuffer, /*bf_getbuffer*/ + 0, /*bf_releasebuffer*/ +}; + +static PyTypeObject __pyx_type___pyx_array = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignedsegment.array", /*tp_name*/ + sizeof(struct __pyx_array_obj), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_array, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + &__pyx_tp_as_sequence_array, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_array, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + __pyx_tp_getattro_array, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_array, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_array, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_array, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_array, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_MemviewEnum_obj *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_MemviewEnum_obj *)o); + p->name = Py_None; Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_Enum(PyObject *o) { + struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->name); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_Enum(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; + if (p->name) { + e = (*v)(p->name, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_Enum(PyObject *o) { + PyObject* tmp; + struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; + tmp = ((PyObject*)p->name); + p->name = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_Enum[] = { + {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_1__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_3__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type___pyx_MemviewEnum = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignedsegment.Enum", /*tp_name*/ + sizeof(struct __pyx_MemviewEnum_obj), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_Enum, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + __pyx_MemviewEnum___repr__, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_Enum, /*tp_traverse*/ + __pyx_tp_clear_Enum, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_Enum, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_MemviewEnum___init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_Enum, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; +static struct __pyx_vtabstruct_memoryview __pyx_vtable_memoryview; + +static PyObject *__pyx_tp_new_memoryview(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_memoryview_obj *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_memoryview_obj *)o); + p->__pyx_vtab = __pyx_vtabptr_memoryview; + p->obj = Py_None; Py_INCREF(Py_None); + p->_size = Py_None; Py_INCREF(Py_None); + p->_array_interface = Py_None; Py_INCREF(Py_None); + p->view.obj = NULL; + if (unlikely(__pyx_memoryview___cinit__(o, a, k) < 0)) goto bad; + return o; + bad: + Py_DECREF(o); o = 0; + return NULL; +} + +static void __pyx_tp_dealloc_memoryview(PyObject *o) { + struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_memoryview___dealloc__(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_CLEAR(p->obj); + Py_CLEAR(p->_size); + Py_CLEAR(p->_array_interface); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_memoryview(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; + if (p->obj) { + e = (*v)(p->obj, a); if (e) return e; + } + if (p->_size) { + e = (*v)(p->_size, a); if (e) return e; + } + if (p->_array_interface) { + e = (*v)(p->_array_interface, a); if (e) return e; + } + if (p->view.obj) { + e = (*v)(p->view.obj, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_memoryview(PyObject *o) { + PyObject* tmp; + struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; + tmp = ((PyObject*)p->obj); + p->obj = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_size); + p->_size = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_array_interface); + p->_array_interface = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + Py_CLEAR(p->view.obj); + return 0; +} +static PyObject *__pyx_sq_item_memoryview(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_memoryview(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_memoryview___setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyObject *__pyx_getprop___pyx_memoryview_T(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_base(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_shape(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_strides(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_suboffsets(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_ndim(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_itemsize(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_nbytes(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(o); +} + +static PyObject *__pyx_getprop___pyx_memoryview_size(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(o); +} + +static PyMethodDef __pyx_methods_memoryview[] = { + {"is_c_contig", (PyCFunction)__pyx_memoryview_is_c_contig, METH_NOARGS, 0}, + {"is_f_contig", (PyCFunction)__pyx_memoryview_is_f_contig, METH_NOARGS, 0}, + {"copy", (PyCFunction)__pyx_memoryview_copy, METH_NOARGS, 0}, + {"copy_fortran", (PyCFunction)__pyx_memoryview_copy_fortran, METH_NOARGS, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_1__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_3__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_memoryview[] = { + {(char *)"T", __pyx_getprop___pyx_memoryview_T, 0, (char *)0, 0}, + {(char *)"base", __pyx_getprop___pyx_memoryview_base, 0, (char *)0, 0}, + {(char *)"shape", __pyx_getprop___pyx_memoryview_shape, 0, (char *)0, 0}, + {(char *)"strides", __pyx_getprop___pyx_memoryview_strides, 0, (char *)0, 0}, + {(char *)"suboffsets", __pyx_getprop___pyx_memoryview_suboffsets, 0, (char *)0, 0}, + {(char *)"ndim", __pyx_getprop___pyx_memoryview_ndim, 0, (char *)0, 0}, + {(char *)"itemsize", __pyx_getprop___pyx_memoryview_itemsize, 0, (char *)0, 0}, + {(char *)"nbytes", __pyx_getprop___pyx_memoryview_nbytes, 0, (char *)0, 0}, + {(char *)"size", __pyx_getprop___pyx_memoryview_size, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PySequenceMethods __pyx_tp_as_sequence_memoryview = { + __pyx_memoryview___len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_memoryview, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_memoryview = { + __pyx_memoryview___len__, /*mp_length*/ + __pyx_memoryview___getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_memoryview, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_memoryview = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + __pyx_memoryview_getbuffer, /*bf_getbuffer*/ + 0, /*bf_releasebuffer*/ +}; + +static PyTypeObject __pyx_type___pyx_memoryview = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignedsegment.memoryview", /*tp_name*/ + sizeof(struct __pyx_memoryview_obj), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_memoryview, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + __pyx_memoryview___repr__, /*tp_repr*/ + 0, /*tp_as_number*/ + &__pyx_tp_as_sequence_memoryview, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_memoryview, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_memoryview___str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_memoryview, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_memoryview, /*tp_traverse*/ + __pyx_tp_clear_memoryview, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_memoryview, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_memoryview, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_memoryview, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; +static struct __pyx_vtabstruct__memoryviewslice __pyx_vtable__memoryviewslice; + +static PyObject *__pyx_tp_new__memoryviewslice(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_memoryviewslice_obj *p; + PyObject *o = __pyx_tp_new_memoryview(t, a, k); + if (unlikely(!o)) return 0; + p = ((struct __pyx_memoryviewslice_obj *)o); + p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_memoryview*)__pyx_vtabptr__memoryviewslice; + p->from_object = Py_None; Py_INCREF(Py_None); + p->from_slice.memview = NULL; + return o; +} + +static void __pyx_tp_dealloc__memoryviewslice(PyObject *o) { + struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_memoryviewslice___dealloc__(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_CLEAR(p->from_object); + PyObject_GC_Track(o); + __pyx_tp_dealloc_memoryview(o); +} + +static int __pyx_tp_traverse__memoryviewslice(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; + e = __pyx_tp_traverse_memoryview(o, v, a); if (e) return e; + if (p->from_object) { + e = (*v)(p->from_object, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear__memoryviewslice(PyObject *o) { + PyObject* tmp; + struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; + __pyx_tp_clear_memoryview(o); + tmp = ((PyObject*)p->from_object); + p->from_object = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + __PYX_XDEC_MEMVIEW(&p->from_slice, 1); + return 0; +} + +static PyObject *__pyx_getprop___pyx_memoryviewslice_base(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(o); +} + +static PyMethodDef __pyx_methods__memoryviewslice[] = { + {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_1__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_3__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets__memoryviewslice[] = { + {(char *)"base", __pyx_getprop___pyx_memoryviewslice_base, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type___pyx_memoryviewslice = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignedsegment._memoryviewslice", /*tp_name*/ + sizeof(struct __pyx_memoryviewslice_obj), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc__memoryviewslice, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + #if CYTHON_COMPILING_IN_PYPY + __pyx_memoryview___repr__, /*tp_repr*/ + #else + 0, /*tp_repr*/ + #endif + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_memoryview___str__, /*tp_str*/ + #else + 0, /*tp_str*/ + #endif + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "Internal class for passing memoryview slices to Python", /*tp_doc*/ + __pyx_tp_traverse__memoryviewslice, /*tp_traverse*/ + __pyx_tp_clear__memoryviewslice, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods__memoryviewslice, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets__memoryviewslice, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new__memoryviewslice, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; + +#if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec_libcalignedsegment(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_libcalignedsegment}, + {0, NULL} +}; +#endif + +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + "libcalignedsegment", + 0, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #else + -1, /* m_size */ + #endif + __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else + NULL, /* m_reload */ + #endif + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ +}; +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_s_2sBBI_i_s, __pyx_k_2sBBI_i_s, sizeof(__pyx_k_2sBBI_i_s), 0, 0, 1, 0}, + {&__pyx_kp_s_2sBBI_is, __pyx_k_2sBBI_is, sizeof(__pyx_k_2sBBI_is), 0, 0, 1, 0}, + {&__pyx_kp_s_2sB_is, __pyx_k_2sB_is, sizeof(__pyx_k_2sB_is), 0, 0, 1, 0}, + {&__pyx_kp_s_2sB_s, __pyx_k_2sB_s, sizeof(__pyx_k_2sB_s), 0, 0, 1, 0}, + {&__pyx_n_s_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 1, 1}, + {&__pyx_n_s_ACGTacgtNnXx, __pyx_k_ACGTacgtNnXx, sizeof(__pyx_k_ACGTacgtNnXx), 0, 0, 1, 1}, + {&__pyx_n_s_ASCII, __pyx_k_ASCII, sizeof(__pyx_k_ASCII), 0, 0, 1, 1}, + {&__pyx_n_s_AlignedSegment, __pyx_k_AlignedSegment, sizeof(__pyx_k_AlignedSegment), 0, 0, 1, 1}, + {&__pyx_n_s_AssertionError, __pyx_k_AssertionError, sizeof(__pyx_k_AssertionError), 0, 0, 1, 1}, + {&__pyx_n_s_B, __pyx_k_B, sizeof(__pyx_k_B), 0, 0, 1, 1}, + {&__pyx_kp_s_Buffer_view_does_not_expose_stri, __pyx_k_Buffer_view_does_not_expose_stri, sizeof(__pyx_k_Buffer_view_does_not_expose_stri), 0, 0, 1, 0}, + {&__pyx_n_s_CBACK, __pyx_k_CBACK, sizeof(__pyx_k_CBACK), 0, 0, 1, 1}, + {&__pyx_n_s_CDEL, __pyx_k_CDEL, sizeof(__pyx_k_CDEL), 0, 0, 1, 1}, + {&__pyx_n_s_CDIFF, __pyx_k_CDIFF, sizeof(__pyx_k_CDIFF), 0, 0, 1, 1}, + {&__pyx_n_s_CEQUAL, __pyx_k_CEQUAL, sizeof(__pyx_k_CEQUAL), 0, 0, 1, 1}, + {&__pyx_n_s_CHARD_CLIP, __pyx_k_CHARD_CLIP, sizeof(__pyx_k_CHARD_CLIP), 0, 0, 1, 1}, + {&__pyx_n_s_CIGAR2CODE, __pyx_k_CIGAR2CODE, sizeof(__pyx_k_CIGAR2CODE), 0, 0, 1, 1}, + {&__pyx_n_s_CIGAR_OPS, __pyx_k_CIGAR_OPS, sizeof(__pyx_k_CIGAR_OPS), 0, 0, 1, 1}, + {&__pyx_n_s_CIGAR_REGEX, __pyx_k_CIGAR_REGEX, sizeof(__pyx_k_CIGAR_REGEX), 0, 0, 1, 1}, + {&__pyx_n_s_CINS, __pyx_k_CINS, sizeof(__pyx_k_CINS), 0, 0, 1, 1}, + {&__pyx_n_s_CMATCH, __pyx_k_CMATCH, sizeof(__pyx_k_CMATCH), 0, 0, 1, 1}, + {&__pyx_n_s_CPAD, __pyx_k_CPAD, sizeof(__pyx_k_CPAD), 0, 0, 1, 1}, + {&__pyx_n_s_CREF_SKIP, __pyx_k_CREF_SKIP, sizeof(__pyx_k_CREF_SKIP), 0, 0, 1, 1}, + {&__pyx_n_s_CSOFT_CLIP, __pyx_k_CSOFT_CLIP, sizeof(__pyx_k_CSOFT_CLIP), 0, 0, 1, 1}, + {&__pyx_kp_s_Can_only_create_a_buffer_that_is, __pyx_k_Can_only_create_a_buffer_that_is, sizeof(__pyx_k_Can_only_create_a_buffer_that_is), 0, 0, 1, 0}, + {&__pyx_kp_s_Cannot_assign_to_read_only_memor, __pyx_k_Cannot_assign_to_read_only_memor, sizeof(__pyx_k_Cannot_assign_to_read_only_memor), 0, 0, 1, 0}, + {&__pyx_kp_s_Cannot_create_writable_memory_vi, __pyx_k_Cannot_create_writable_memory_vi, sizeof(__pyx_k_Cannot_create_writable_memory_vi), 0, 0, 1, 0}, + {&__pyx_kp_s_Cannot_index_with_type_s, __pyx_k_Cannot_index_with_type_s, sizeof(__pyx_k_Cannot_index_with_type_s), 0, 0, 1, 0}, + {&__pyx_n_s_D, __pyx_k_D, sizeof(__pyx_k_D), 0, 0, 1, 1}, + {&__pyx_n_s_DATATYPE2FORMAT, __pyx_k_DATATYPE2FORMAT, sizeof(__pyx_k_DATATYPE2FORMAT), 0, 0, 1, 1}, + {&__pyx_n_s_Ellipsis, __pyx_k_Ellipsis, sizeof(__pyx_k_Ellipsis), 0, 0, 1, 1}, + {&__pyx_kp_s_Empty_shape_tuple_for_cython_arr, __pyx_k_Empty_shape_tuple_for_cython_arr, sizeof(__pyx_k_Empty_shape_tuple_for_cython_arr), 0, 0, 1, 0}, + {&__pyx_n_s_EnumBase, __pyx_k_EnumBase, sizeof(__pyx_k_EnumBase), 0, 0, 1, 1}, + {&__pyx_n_s_EnumType, __pyx_k_EnumType, sizeof(__pyx_k_EnumType), 0, 0, 1, 1}, + {&__pyx_n_s_F, __pyx_k_F, sizeof(__pyx_k_F), 0, 0, 1, 1}, + {&__pyx_n_s_FDUP, __pyx_k_FDUP, sizeof(__pyx_k_FDUP), 0, 0, 1, 1}, + {&__pyx_n_s_FMREVERSE, __pyx_k_FMREVERSE, sizeof(__pyx_k_FMREVERSE), 0, 0, 1, 1}, + {&__pyx_n_s_FMUNMAP, __pyx_k_FMUNMAP, sizeof(__pyx_k_FMUNMAP), 0, 0, 1, 1}, + {&__pyx_n_s_FPAIRED, __pyx_k_FPAIRED, sizeof(__pyx_k_FPAIRED), 0, 0, 1, 1}, + {&__pyx_n_s_FPROPER_PAIR, __pyx_k_FPROPER_PAIR, sizeof(__pyx_k_FPROPER_PAIR), 0, 0, 1, 1}, + {&__pyx_n_s_FQCFAIL, __pyx_k_FQCFAIL, sizeof(__pyx_k_FQCFAIL), 0, 0, 1, 1}, + {&__pyx_n_s_FREAD1, __pyx_k_FREAD1, sizeof(__pyx_k_FREAD1), 0, 0, 1, 1}, + {&__pyx_n_s_FREAD2, __pyx_k_FREAD2, sizeof(__pyx_k_FREAD2), 0, 0, 1, 1}, + {&__pyx_n_s_FREVERSE, __pyx_k_FREVERSE, sizeof(__pyx_k_FREVERSE), 0, 0, 1, 1}, + {&__pyx_n_s_FSECONDARY, __pyx_k_FSECONDARY, sizeof(__pyx_k_FSECONDARY), 0, 0, 1, 1}, + {&__pyx_n_s_FSUPPLEMENTARY, __pyx_k_FSUPPLEMENTARY, sizeof(__pyx_k_FSUPPLEMENTARY), 0, 0, 1, 1}, + {&__pyx_n_s_FUNMAP, __pyx_k_FUNMAP, sizeof(__pyx_k_FUNMAP), 0, 0, 1, 1}, + {&__pyx_n_s_H, __pyx_k_H, sizeof(__pyx_k_H), 0, 0, 1, 1}, + {&__pyx_n_s_I, __pyx_k_I, sizeof(__pyx_k_I), 0, 0, 1, 1}, + {&__pyx_kp_s_Incompatible_checksums_s_vs_0xb0, __pyx_k_Incompatible_checksums_s_vs_0xb0, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xb0), 0, 0, 1, 0}, + {&__pyx_kp_s_Incompatible_checksums_s_vs_0xbb, __pyx_k_Incompatible_checksums_s_vs_0xbb, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xbb), 0, 0, 1, 0}, + {&__pyx_kp_s_Incompatible_checksums_s_vs_0xd4, __pyx_k_Incompatible_checksums_s_vs_0xd4, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xd4), 0, 0, 1, 0}, + {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1}, + {&__pyx_kp_s_Indirect_dimensions_not_supporte, __pyx_k_Indirect_dimensions_not_supporte, sizeof(__pyx_k_Indirect_dimensions_not_supporte), 0, 0, 1, 0}, + {&__pyx_n_s_IntEnum, __pyx_k_IntEnum, sizeof(__pyx_k_IntEnum), 0, 0, 1, 1}, + {&__pyx_kp_s_Invalid_MD_tag_MD_length_mismatc, __pyx_k_Invalid_MD_tag_MD_length_mismatc, sizeof(__pyx_k_Invalid_MD_tag_MD_length_mismatc), 0, 0, 1, 0}, + {&__pyx_kp_s_Invalid_clipping_in_CIGAR_string, __pyx_k_Invalid_clipping_in_CIGAR_string, sizeof(__pyx_k_Invalid_clipping_in_CIGAR_string), 0, 0, 1, 0}, + {&__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_k_Invalid_mode_expected_c_or_fortr, sizeof(__pyx_k_Invalid_mode_expected_c_or_fortr), 0, 0, 1, 0}, + {&__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_k_Invalid_shape_in_axis_d_d, sizeof(__pyx_k_Invalid_shape_in_axis_d_d), 0, 0, 1, 0}, + {&__pyx_kp_s_Invalid_tag_s, __pyx_k_Invalid_tag_s, sizeof(__pyx_k_Invalid_tag_s), 0, 0, 1, 0}, + {&__pyx_n_s_KEY_NAMES, __pyx_k_KEY_NAMES, sizeof(__pyx_k_KEY_NAMES), 0, 0, 1, 1}, + {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1}, + {&__pyx_kp_s_MD_tag_not_present, __pyx_k_MD_tag_not_present, sizeof(__pyx_k_MD_tag_not_present), 0, 0, 1, 0}, + {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, + {&__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_k_MemoryView_of_r_at_0x_x, sizeof(__pyx_k_MemoryView_of_r_at_0x_x), 0, 0, 1, 0}, + {&__pyx_kp_s_MemoryView_of_r_object, __pyx_k_MemoryView_of_r_object, sizeof(__pyx_k_MemoryView_of_r_object), 0, 0, 1, 0}, + {&__pyx_n_s_NotImplemented, __pyx_k_NotImplemented, sizeof(__pyx_k_NotImplemented), 0, 0, 1, 1}, + {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1}, + {&__pyx_n_b_O, __pyx_k_O, sizeof(__pyx_k_O), 0, 0, 0, 1}, + {&__pyx_n_s_OrderedDict, __pyx_k_OrderedDict, sizeof(__pyx_k_OrderedDict), 0, 0, 1, 1}, + {&__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_k_Out_of_bounds_on_buffer_access_a, sizeof(__pyx_k_Out_of_bounds_on_buffer_access_a), 0, 0, 1, 0}, + {&__pyx_kp_s_Padding_BAM_CPAD_6_is_currently, __pyx_k_Padding_BAM_CPAD_6_is_currently, sizeof(__pyx_k_Padding_BAM_CPAD_6_is_currently), 0, 0, 1, 0}, + {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, + {&__pyx_n_s_PileupColumn, __pyx_k_PileupColumn, sizeof(__pyx_k_PileupColumn), 0, 0, 1, 1}, + {&__pyx_kp_s_PileupColumn_accessed_after_iter, __pyx_k_PileupColumn_accessed_after_iter, sizeof(__pyx_k_PileupColumn_accessed_after_iter), 0, 0, 1, 0}, + {&__pyx_n_s_PileupRead, __pyx_k_PileupRead, sizeof(__pyx_k_PileupRead), 0, 0, 1, 1}, + {&__pyx_n_s_Pyx_EnumBase, __pyx_k_Pyx_EnumBase, sizeof(__pyx_k_Pyx_EnumBase), 0, 0, 1, 1}, + {&__pyx_n_s_Pyx_EnumBase___new, __pyx_k_Pyx_EnumBase___new, sizeof(__pyx_k_Pyx_EnumBase___new), 0, 0, 1, 1}, + {&__pyx_n_s_Pyx_EnumBase___repr, __pyx_k_Pyx_EnumBase___repr, sizeof(__pyx_k_Pyx_EnumBase___repr), 0, 0, 1, 1}, + {&__pyx_n_s_Pyx_EnumBase___str, __pyx_k_Pyx_EnumBase___str, sizeof(__pyx_k_Pyx_EnumBase___str), 0, 0, 1, 1}, + {&__pyx_n_s_SAM_FLAGS, __pyx_k_SAM_FLAGS, sizeof(__pyx_k_SAM_FLAGS), 0, 0, 1, 1}, + {&__pyx_n_s_TGCAtgcaNnXx, __pyx_k_TGCAtgcaNnXx, sizeof(__pyx_k_TGCAtgcaNnXx), 0, 0, 1, 1}, + {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, + {&__pyx_kp_s_Unable_to_convert_item_to_object, __pyx_k_Unable_to_convert_item_to_object, sizeof(__pyx_k_Unable_to_convert_item_to_object), 0, 0, 1, 0}, + {&__pyx_kp_s_Unknown_enum_value_s, __pyx_k_Unknown_enum_value_s, sizeof(__pyx_k_Unknown_enum_value_s), 0, 0, 1, 0}, + {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, + {&__pyx_n_s_View_MemoryView, __pyx_k_View_MemoryView, sizeof(__pyx_k_View_MemoryView), 0, 0, 1, 1}, + {&__pyx_n_s_Z, __pyx_k_Z, sizeof(__pyx_k_Z), 0, 0, 1, 1}, + {&__pyx_kp_s__16, __pyx_k__16, sizeof(__pyx_k__16), 0, 0, 1, 0}, + {&__pyx_kp_s__24, __pyx_k__24, sizeof(__pyx_k__24), 0, 0, 1, 0}, + {&__pyx_kp_s__27, __pyx_k__27, sizeof(__pyx_k__27), 0, 0, 1, 0}, + {&__pyx_kp_s__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 0, 1, 0}, + {&__pyx_kp_s__42, __pyx_k__42, sizeof(__pyx_k__42), 0, 0, 1, 0}, + {&__pyx_kp_s__44, __pyx_k__44, sizeof(__pyx_k__44), 0, 0, 1, 0}, + {&__pyx_kp_s__8, __pyx_k__8, sizeof(__pyx_k__8), 0, 0, 1, 0}, + {&__pyx_n_s_a, __pyx_k_a, sizeof(__pyx_k_a), 0, 0, 1, 1}, + {&__pyx_n_s_aAsSIcCZidfH, __pyx_k_aAsSIcCZidfH, sizeof(__pyx_k_aAsSIcCZidfH), 0, 0, 1, 1}, + {&__pyx_n_s_add_indels, __pyx_k_add_indels, sizeof(__pyx_k_add_indels), 0, 0, 1, 1}, + {&__pyx_n_s_alignment, __pyx_k_alignment, sizeof(__pyx_k_alignment), 0, 0, 1, 1}, + {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1}, + {&__pyx_n_s_allocate_buffer, __pyx_k_allocate_buffer, sizeof(__pyx_k_allocate_buffer), 0, 0, 1, 1}, + {&__pyx_n_s_always, __pyx_k_always, sizeof(__pyx_k_always), 0, 0, 1, 1}, + {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1}, + {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1}, + {&__pyx_n_s_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1}, + {&__pyx_kp_s_at_least_one_integer_out_of_rang, __pyx_k_at_least_one_integer_out_of_rang, sizeof(__pyx_k_at_least_one_integer_out_of_rang), 0, 0, 1, 0}, + {&__pyx_kp_s_at_least_one_signed_integer_out, __pyx_k_at_least_one_signed_integer_out, sizeof(__pyx_k_at_least_one_signed_integer_out), 0, 0, 1, 0}, + {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1}, + {&__pyx_n_s_base, __pyx_k_base, sizeof(__pyx_k_base), 0, 0, 1, 1}, + {&__pyx_kp_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 0}, + {&__pyx_n_s_c_2, __pyx_k_c_2, sizeof(__pyx_k_c_2), 0, 0, 1, 1}, + {&__pyx_n_u_c_2, __pyx_k_c_2, sizeof(__pyx_k_c_2), 0, 1, 0, 1}, + {&__pyx_n_s_calcsize, __pyx_k_calcsize, sizeof(__pyx_k_calcsize), 0, 0, 1, 1}, + {&__pyx_kp_s_can_t_guess_type_or_invalid_type, __pyx_k_can_t_guess_type_or_invalid_type, sizeof(__pyx_k_can_t_guess_type_or_invalid_type), 0, 0, 1, 0}, + {&__pyx_n_s_chr, __pyx_k_chr, sizeof(__pyx_k_chr), 0, 0, 1, 1}, + {&__pyx_n_s_cigar, __pyx_k_cigar, sizeof(__pyx_k_cigar), 0, 0, 1, 1}, + {&__pyx_n_s_cigarstring, __pyx_k_cigarstring, sizeof(__pyx_k_cigarstring), 0, 0, 1, 1}, + {&__pyx_n_s_cigartuples, __pyx_k_cigartuples, sizeof(__pyx_k_cigartuples), 0, 0, 1, 1}, + {&__pyx_n_s_class, __pyx_k_class, sizeof(__pyx_k_class), 0, 0, 1, 1}, + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1}, + {&__pyx_n_s_cls, __pyx_k_cls, sizeof(__pyx_k_cls), 0, 0, 1, 1}, + {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1}, + {&__pyx_n_s_compare, __pyx_k_compare, sizeof(__pyx_k_compare), 0, 0, 1, 1}, + {&__pyx_n_s_compile, __pyx_k_compile, sizeof(__pyx_k_compile), 0, 0, 1, 1}, + {&__pyx_kp_s_contiguous_and_direct, __pyx_k_contiguous_and_direct, sizeof(__pyx_k_contiguous_and_direct), 0, 0, 1, 0}, + {&__pyx_kp_s_contiguous_and_indirect, __pyx_k_contiguous_and_indirect, sizeof(__pyx_k_contiguous_and_indirect), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_allocate_memory, __pyx_k_could_not_allocate_memory, sizeof(__pyx_k_could_not_allocate_memory), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_allocate_memory_of_byt, __pyx_k_could_not_allocate_memory_of_byt, sizeof(__pyx_k_could_not_allocate_memory_of_byt), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_allocate_pileup_buffer, __pyx_k_could_not_allocate_pileup_buffer, sizeof(__pyx_k_could_not_allocate_pileup_buffer), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_allocate_sequence_of_l, __pyx_k_could_not_allocate_sequence_of_l, sizeof(__pyx_k_could_not_allocate_sequence_of_l), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_allocated_memory, __pyx_k_could_not_allocated_memory, sizeof(__pyx_k_could_not_allocated_memory), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_allocated_memory_of_by, __pyx_k_could_not_allocated_memory_of_by, sizeof(__pyx_k_could_not_allocated_memory_of_by), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_deduce_typecode_for_va, __pyx_k_could_not_deduce_typecode_for_va, sizeof(__pyx_k_could_not_deduce_typecode_for_va), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_determine_alignment_le, __pyx_k_could_not_determine_alignment_le, sizeof(__pyx_k_could_not_determine_alignment_le), 0, 0, 1, 0}, + {&__pyx_n_s_create_string_buffer, __pyx_k_create_string_buffer, sizeof(__pyx_k_create_string_buffer), 0, 0, 1, 1}, + {&__pyx_n_s_ctypes, __pyx_k_ctypes, sizeof(__pyx_k_ctypes), 0, 0, 1, 1}, + {&__pyx_n_s_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 1, 1}, + {&__pyx_kp_s_d_MIDNSHP_XB, __pyx_k_d_MIDNSHP_XB, sizeof(__pyx_k_d_MIDNSHP_XB), 0, 0, 1, 0}, + {&__pyx_n_s_dct, __pyx_k_dct, sizeof(__pyx_k_dct), 0, 0, 1, 1}, + {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, + {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1}, + {&__pyx_n_s_dtype_is_object, __pyx_k_dtype_is_object, sizeof(__pyx_k_dtype_is_object), 0, 0, 1, 1}, + {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, + {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1}, + {&__pyx_n_s_enum, __pyx_k_enum, sizeof(__pyx_k_enum), 0, 0, 1, 1}, + {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1}, + {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, + {&__pyx_n_s_f, __pyx_k_f, sizeof(__pyx_k_f), 0, 0, 1, 1}, + {&__pyx_n_s_findall, __pyx_k_findall, sizeof(__pyx_k_findall), 0, 0, 1, 1}, + {&__pyx_n_s_flag, __pyx_k_flag, sizeof(__pyx_k_flag), 0, 0, 1, 1}, + {&__pyx_n_s_flags, __pyx_k_flags, sizeof(__pyx_k_flags), 0, 0, 1, 1}, + {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1}, + {&__pyx_n_s_fortran, __pyx_k_fortran, sizeof(__pyx_k_fortran), 0, 0, 1, 1}, + {&__pyx_n_u_fortran, __pyx_k_fortran, sizeof(__pyx_k_fortran), 0, 1, 0, 1}, + {&__pyx_n_s_from_dict, __pyx_k_from_dict, sizeof(__pyx_k_from_dict), 0, 0, 1, 1}, + {&__pyx_n_s_from_dict_locals_genexpr, __pyx_k_from_dict_locals_genexpr, sizeof(__pyx_k_from_dict_locals_genexpr), 0, 0, 1, 1}, + {&__pyx_n_s_fromstring, __pyx_k_fromstring, sizeof(__pyx_k_fromstring), 0, 0, 1, 1}, + {&__pyx_n_s_full_length, __pyx_k_full_length, sizeof(__pyx_k_full_length), 0, 0, 1, 1}, + {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1}, + {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1}, + {&__pyx_n_s_get_aligned_pairs, __pyx_k_get_aligned_pairs, sizeof(__pyx_k_get_aligned_pairs), 0, 0, 1, 1}, + {&__pyx_n_s_get_blocks, __pyx_k_get_blocks, sizeof(__pyx_k_get_blocks), 0, 0, 1, 1}, + {&__pyx_n_s_get_num_aligned, __pyx_k_get_num_aligned, sizeof(__pyx_k_get_num_aligned), 0, 0, 1, 1}, + {&__pyx_n_s_get_overlap, __pyx_k_get_overlap, sizeof(__pyx_k_get_overlap), 0, 0, 1, 1}, + {&__pyx_n_s_get_reference_name, __pyx_k_get_reference_name, sizeof(__pyx_k_get_reference_name), 0, 0, 1, 1}, + {&__pyx_n_s_get_reference_positions, __pyx_k_get_reference_positions, sizeof(__pyx_k_get_reference_positions), 0, 0, 1, 1}, + {&__pyx_n_s_get_tag, __pyx_k_get_tag, sizeof(__pyx_k_get_tag), 0, 0, 1, 1}, + {&__pyx_n_s_get_tags, __pyx_k_get_tags, sizeof(__pyx_k_get_tags), 0, 0, 1, 1}, + {&__pyx_n_s_get_tid, __pyx_k_get_tid, sizeof(__pyx_k_get_tid), 0, 0, 1, 1}, + {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, + {&__pyx_kp_s_got_differing_extents_in_dimensi, __pyx_k_got_differing_extents_in_dimensi, sizeof(__pyx_k_got_differing_extents_in_dimensi), 0, 0, 1, 0}, + {&__pyx_n_s_h, __pyx_k_h, sizeof(__pyx_k_h), 0, 0, 1, 1}, + {&__pyx_n_s_has_tag, __pyx_k_has_tag, sizeof(__pyx_k_has_tag), 0, 0, 1, 1}, + {&__pyx_n_s_header, __pyx_k_header, sizeof(__pyx_k_header), 0, 0, 1, 1}, + {&__pyx_n_s_htsfile, __pyx_k_htsfile, sizeof(__pyx_k_htsfile), 0, 0, 1, 1}, + {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, + {&__pyx_n_s_iIcCsS, __pyx_k_iIcCsS, sizeof(__pyx_k_iIcCsS), 0, 0, 1, 1}, + {&__pyx_kp_s_i_c, __pyx_k_i_c, sizeof(__pyx_k_i_c), 0, 0, 1, 0}, + {&__pyx_n_s_id, __pyx_k_id, sizeof(__pyx_k_id), 0, 0, 1, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_indel, __pyx_k_indel, sizeof(__pyx_k_indel), 0, 0, 1, 1}, + {&__pyx_n_s_infer_query_length, __pyx_k_infer_query_length, sizeof(__pyx_k_infer_query_length), 0, 0, 1, 1}, + {&__pyx_n_s_infer_read_length, __pyx_k_infer_read_length, sizeof(__pyx_k_infer_read_length), 0, 0, 1, 1}, + {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1}, + {&__pyx_kp_s_invalid_value_type, __pyx_k_invalid_value_type, sizeof(__pyx_k_invalid_value_type), 0, 0, 1, 0}, + {&__pyx_kp_s_invalid_value_type_2, __pyx_k_invalid_value_type_2, sizeof(__pyx_k_invalid_value_type_2), 0, 0, 1, 0}, + {&__pyx_n_s_is_del, __pyx_k_is_del, sizeof(__pyx_k_is_del), 0, 0, 1, 1}, + {&__pyx_n_s_is_head, __pyx_k_is_head, sizeof(__pyx_k_is_head), 0, 0, 1, 1}, + {&__pyx_n_s_is_refskip, __pyx_k_is_refskip, sizeof(__pyx_k_is_refskip), 0, 0, 1, 1}, + {&__pyx_n_s_is_reverse, __pyx_k_is_reverse, sizeof(__pyx_k_is_reverse), 0, 0, 1, 1}, + {&__pyx_n_s_is_tail, __pyx_k_is_tail, sizeof(__pyx_k_is_tail), 0, 0, 1, 1}, + {&__pyx_n_s_is_valid_tid, __pyx_k_is_valid_tid, sizeof(__pyx_k_is_valid_tid), 0, 0, 1, 1}, + {&__pyx_n_s_itemsize, __pyx_k_itemsize, sizeof(__pyx_k_itemsize), 0, 0, 1, 1}, + {&__pyx_kp_s_itemsize_0_for_cython_array, __pyx_k_itemsize_0_for_cython_array, sizeof(__pyx_k_itemsize_0_for_cython_array), 0, 0, 1, 0}, + {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1}, + {&__pyx_n_s_json, __pyx_k_json, sizeof(__pyx_k_json), 0, 0, 1, 1}, + {&__pyx_n_s_length, __pyx_k_length, sizeof(__pyx_k_length), 0, 0, 1, 1}, + {&__pyx_n_s_level, __pyx_k_level, sizeof(__pyx_k_level), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_maketrans, __pyx_k_maketrans, sizeof(__pyx_k_maketrans), 0, 0, 1, 1}, + {&__pyx_kp_s_malformatted_tag_s, __pyx_k_malformatted_tag_s, sizeof(__pyx_k_malformatted_tag_s), 0, 0, 1, 0}, + {&__pyx_n_s_map, __pyx_k_map, sizeof(__pyx_k_map), 0, 0, 1, 1}, + {&__pyx_n_s_map_quality, __pyx_k_map_quality, sizeof(__pyx_k_map_quality), 0, 0, 1, 1}, + {&__pyx_n_s_mapping_quality, __pyx_k_mapping_quality, sizeof(__pyx_k_mapping_quality), 0, 0, 1, 1}, + {&__pyx_n_s_mark_ends, __pyx_k_mark_ends, sizeof(__pyx_k_mark_ends), 0, 0, 1, 1}, + {&__pyx_n_s_mark_matches, __pyx_k_mark_matches, sizeof(__pyx_k_mark_matches), 0, 0, 1, 1}, + {&__pyx_n_s_matches_only, __pyx_k_matches_only, sizeof(__pyx_k_matches_only), 0, 0, 1, 1}, + {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1}, + {&__pyx_n_s_members, __pyx_k_members, sizeof(__pyx_k_members), 0, 0, 1, 1}, + {&__pyx_n_s_memview, __pyx_k_memview, sizeof(__pyx_k_memview), 0, 0, 1, 1}, + {&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1}, + {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1}, + {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1}, + {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1}, + {&__pyx_n_s_ndim, __pyx_k_ndim, sizeof(__pyx_k_ndim), 0, 0, 1, 1}, + {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1}, + {&__pyx_n_s_next_ref_name, __pyx_k_next_ref_name, sizeof(__pyx_k_next_ref_name), 0, 0, 1, 1}, + {&__pyx_n_s_next_ref_pos, __pyx_k_next_ref_pos, sizeof(__pyx_k_next_ref_pos), 0, 0, 1, 1}, + {&__pyx_n_s_next_reference_id, __pyx_k_next_reference_id, sizeof(__pyx_k_next_reference_id), 0, 0, 1, 1}, + {&__pyx_kp_s_next_reference_name_can_not_be_s, __pyx_k_next_reference_name_can_not_be_s, sizeof(__pyx_k_next_reference_name_can_not_be_s), 0, 0, 1, 0}, + {&__pyx_kp_s_next_reference_name_unknown_if_n, __pyx_k_next_reference_name_unknown_if_n, sizeof(__pyx_k_next_reference_name_unknown_if_n), 0, 0, 1, 0}, + {&__pyx_n_s_next_reference_start, __pyx_k_next_reference_start, sizeof(__pyx_k_next_reference_start), 0, 0, 1, 1}, + {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0}, + {&__pyx_n_s_nsegments, __pyx_k_nsegments, sizeof(__pyx_k_nsegments), 0, 0, 1, 1}, + {&__pyx_n_s_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 0, 0, 1, 1}, + {&__pyx_n_s_pack, __pyx_k_pack, sizeof(__pyx_k_pack), 0, 0, 1, 1}, + {&__pyx_n_s_pack_into, __pyx_k_pack_into, sizeof(__pyx_k_pack_into), 0, 0, 1, 1}, + {&__pyx_n_s_parents, __pyx_k_parents, sizeof(__pyx_k_parents), 0, 0, 1, 1}, + {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, + {&__pyx_n_s_pileups, __pyx_k_pileups, sizeof(__pyx_k_pileups), 0, 0, 1, 1}, + {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1}, + {&__pyx_n_s_pysam_libcalignedsegment, __pyx_k_pysam_libcalignedsegment, sizeof(__pyx_k_pysam_libcalignedsegment), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_getbuffer, __pyx_k_pyx_getbuffer, sizeof(__pyx_k_pyx_getbuffer), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_Enum, __pyx_k_pyx_unpickle_Enum, sizeof(__pyx_k_pyx_unpickle_Enum), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_PileupRead, __pyx_k_pyx_unpickle_PileupRead, sizeof(__pyx_k_pyx_unpickle_PileupRead), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle___Pyx_EnumMeta, __pyx_k_pyx_unpickle___Pyx_EnumMeta, sizeof(__pyx_k_pyx_unpickle___Pyx_EnumMeta), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1}, + {&__pyx_n_s_qual, __pyx_k_qual, sizeof(__pyx_k_qual), 0, 0, 1, 1}, + {&__pyx_kp_s_quality_and_sequence_mismatch_i, __pyx_k_quality_and_sequence_mismatch_i, sizeof(__pyx_k_quality_and_sequence_mismatch_i), 0, 0, 1, 0}, + {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1}, + {&__pyx_n_s_query_alignment_end, __pyx_k_query_alignment_end, sizeof(__pyx_k_query_alignment_end), 0, 0, 1, 1}, + {&__pyx_n_s_query_alignment_length, __pyx_k_query_alignment_length, sizeof(__pyx_k_query_alignment_length), 0, 0, 1, 1}, + {&__pyx_n_s_query_alignment_qualities, __pyx_k_query_alignment_qualities, sizeof(__pyx_k_query_alignment_qualities), 0, 0, 1, 1}, + {&__pyx_n_s_query_alignment_sequence, __pyx_k_query_alignment_sequence, sizeof(__pyx_k_query_alignment_sequence), 0, 0, 1, 1}, + {&__pyx_n_s_query_alignment_start, __pyx_k_query_alignment_start, sizeof(__pyx_k_query_alignment_start), 0, 0, 1, 1}, + {&__pyx_n_s_query_length, __pyx_k_query_length, sizeof(__pyx_k_query_length), 0, 0, 1, 1}, + {&__pyx_kp_s_query_length_out_of_range_251, __pyx_k_query_length_out_of_range_251, sizeof(__pyx_k_query_length_out_of_range_251), 0, 0, 1, 0}, + {&__pyx_n_s_query_name, __pyx_k_query_name, sizeof(__pyx_k_query_name), 0, 0, 1, 1}, + {&__pyx_n_s_query_position, __pyx_k_query_position, sizeof(__pyx_k_query_position), 0, 0, 1, 1}, + {&__pyx_n_s_query_qualities, __pyx_k_query_qualities, sizeof(__pyx_k_query_qualities), 0, 0, 1, 1}, + {&__pyx_n_s_query_sequence, __pyx_k_query_sequence, sizeof(__pyx_k_query_sequence), 0, 0, 1, 1}, + {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, + {&__pyx_n_s_raw, __pyx_k_raw, sizeof(__pyx_k_raw), 0, 0, 1, 1}, + {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1}, + {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, + {&__pyx_n_s_ref_name, __pyx_k_ref_name, sizeof(__pyx_k_ref_name), 0, 0, 1, 1}, + {&__pyx_n_s_ref_pos, __pyx_k_ref_pos, sizeof(__pyx_k_ref_pos), 0, 0, 1, 1}, + {&__pyx_kp_s_reference_does_not_exist_in_head, __pyx_k_reference_does_not_exist_in_head, sizeof(__pyx_k_reference_does_not_exist_in_head), 0, 0, 1, 0}, + {&__pyx_n_s_reference_end, __pyx_k_reference_end, sizeof(__pyx_k_reference_end), 0, 0, 1, 1}, + {&__pyx_n_s_reference_id, __pyx_k_reference_id, sizeof(__pyx_k_reference_id), 0, 0, 1, 1}, + {&__pyx_kp_s_reference_id_does_not_exist_in_h, __pyx_k_reference_id_does_not_exist_in_h, sizeof(__pyx_k_reference_id_does_not_exist_in_h), 0, 0, 1, 0}, + {&__pyx_n_s_reference_length, __pyx_k_reference_length, sizeof(__pyx_k_reference_length), 0, 0, 1, 1}, + {&__pyx_kp_s_reference_name_can_not_be_set_if, __pyx_k_reference_name_can_not_be_set_if, sizeof(__pyx_k_reference_name_can_not_be_set_if), 0, 0, 1, 0}, + {&__pyx_kp_s_reference_name_unknown_if_no_hea, __pyx_k_reference_name_unknown_if_no_hea, sizeof(__pyx_k_reference_name_unknown_if_no_hea), 0, 0, 1, 0}, + {&__pyx_n_s_reference_pos, __pyx_k_reference_pos, sizeof(__pyx_k_reference_pos), 0, 0, 1, 1}, + {&__pyx_n_s_reference_start, __pyx_k_reference_start, sizeof(__pyx_k_reference_start), 0, 0, 1, 1}, + {&__pyx_n_s_replace, __pyx_k_replace, sizeof(__pyx_k_replace), 0, 0, 1, 1}, + {&__pyx_n_s_repr, __pyx_k_repr, sizeof(__pyx_k_repr), 0, 0, 1, 1}, + {&__pyx_n_s_res, __pyx_k_res, sizeof(__pyx_k_res), 0, 0, 1, 1}, + {&__pyx_kp_s_s_s, __pyx_k_s_s, sizeof(__pyx_k_s_s), 0, 0, 1, 0}, + {&__pyx_kp_s_s_s_d, __pyx_k_s_s_d, sizeof(__pyx_k_s_s_d), 0, 0, 1, 0}, + {&__pyx_n_s_sam, __pyx_k_sam, sizeof(__pyx_k_sam), 0, 0, 1, 1}, + {&__pyx_n_s_sam_dict, __pyx_k_sam_dict, sizeof(__pyx_k_sam_dict), 0, 0, 1, 1}, + {&__pyx_kp_s_sam_format_failed, __pyx_k_sam_format_failed, sizeof(__pyx_k_sam_format_failed), 0, 0, 1, 0}, + {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1}, + {&__pyx_kp_s_self__delegate_cannot_be_convert, __pyx_k_self__delegate_cannot_be_convert, sizeof(__pyx_k_self__delegate_cannot_be_convert), 0, 0, 1, 0}, + {&__pyx_kp_s_self_plp_cannot_be_converted_to, __pyx_k_self_plp_cannot_be_converted_to, sizeof(__pyx_k_self_plp_cannot_be_converted_to), 0, 0, 1, 0}, + {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1}, + {&__pyx_n_s_seq, __pyx_k_seq, sizeof(__pyx_k_seq), 0, 0, 1, 1}, + {&__pyx_n_s_set_tag, __pyx_k_set_tag, sizeof(__pyx_k_set_tag), 0, 0, 1, 1}, + {&__pyx_n_s_set_tags, __pyx_k_set_tags, sizeof(__pyx_k_set_tags), 0, 0, 1, 1}, + {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, + {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, + {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1}, + {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1}, + {&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1}, + {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1}, + {&__pyx_n_s_step, __pyx_k_step, sizeof(__pyx_k_step), 0, 0, 1, 1}, + {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1}, + {&__pyx_n_s_str, __pyx_k_str, sizeof(__pyx_k_str), 0, 0, 1, 1}, + {&__pyx_kp_s_strided_and_direct, __pyx_k_strided_and_direct, sizeof(__pyx_k_strided_and_direct), 0, 0, 1, 0}, + {&__pyx_kp_s_strided_and_direct_or_indirect, __pyx_k_strided_and_direct_or_indirect, sizeof(__pyx_k_strided_and_direct_or_indirect), 0, 0, 1, 0}, + {&__pyx_kp_s_strided_and_indirect, __pyx_k_strided_and_indirect, sizeof(__pyx_k_strided_and_indirect), 0, 0, 1, 0}, + {&__pyx_n_s_string, __pyx_k_string, sizeof(__pyx_k_string), 0, 0, 1, 1}, + {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, + {&__pyx_n_s_struct, __pyx_k_struct, sizeof(__pyx_k_struct), 0, 0, 1, 1}, + {&__pyx_n_s_tag, __pyx_k_tag, sizeof(__pyx_k_tag), 0, 0, 1, 1}, + {&__pyx_kp_s_tag_s_not_present, __pyx_k_tag_s_not_present, sizeof(__pyx_k_tag_s_not_present), 0, 0, 1, 0}, + {&__pyx_n_s_tags, __pyx_k_tags, sizeof(__pyx_k_tags), 0, 0, 1, 1}, + {&__pyx_n_s_template_length, __pyx_k_template_length, sizeof(__pyx_k_template_length), 0, 0, 1, 1}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_kp_s_this_class_cannot_be_instantiate, __pyx_k_this_class_cannot_be_instantiate, sizeof(__pyx_k_this_class_cannot_be_instantiate), 0, 0, 1, 0}, + {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1}, + {&__pyx_n_s_to_string, __pyx_k_to_string, sizeof(__pyx_k_to_string), 0, 0, 1, 1}, + {&__pyx_n_s_todo, __pyx_k_todo, sizeof(__pyx_k_todo), 0, 0, 1, 1}, + {&__pyx_n_s_tostring, __pyx_k_tostring, sizeof(__pyx_k_tostring), 0, 0, 1, 1}, + {&__pyx_n_s_translate, __pyx_k_translate, sizeof(__pyx_k_translate), 0, 0, 1, 1}, + {&__pyx_n_s_typecode, __pyx_k_typecode, sizeof(__pyx_k_typecode), 0, 0, 1, 1}, + {&__pyx_kp_s_unable_to_allocate_array_data, __pyx_k_unable_to_allocate_array_data, sizeof(__pyx_k_unable_to_allocate_array_data), 0, 0, 1, 0}, + {&__pyx_kp_s_unable_to_allocate_shape_and_str, __pyx_k_unable_to_allocate_shape_and_str, sizeof(__pyx_k_unable_to_allocate_shape_and_str), 0, 0, 1, 0}, + {&__pyx_kp_s_unknown_auxiliary_type_s, __pyx_k_unknown_auxiliary_type_s, sizeof(__pyx_k_unknown_auxiliary_type_s), 0, 0, 1, 0}, + {&__pyx_kp_s_unknown_type_s, __pyx_k_unknown_type_s, sizeof(__pyx_k_unknown_type_s), 0, 0, 1, 0}, + {&__pyx_n_s_unpack, __pyx_k_unpack, sizeof(__pyx_k_unpack), 0, 0, 1, 1}, + {&__pyx_kp_s_unsupported_type_code, __pyx_k_unsupported_type_code, sizeof(__pyx_k_unsupported_type_code), 0, 0, 1, 0}, + {&__pyx_kp_s_unsupported_value_type_in_set_op, __pyx_k_unsupported_value_type_in_set_op, sizeof(__pyx_k_unsupported_value_type_in_set_op), 0, 0, 1, 0}, + {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, + {&__pyx_n_s_v, __pyx_k_v, sizeof(__pyx_k_v), 0, 0, 1, 1}, + {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1}, + {&__pyx_n_s_value_type, __pyx_k_value_type, sizeof(__pyx_k_value_type), 0, 0, 1, 1}, + {&__pyx_n_s_values, __pyx_k_values, sizeof(__pyx_k_values), 0, 0, 1, 1}, + {&__pyx_n_s_with_seq, __pyx_k_with_seq, sizeof(__pyx_k_with_seq), 0, 0, 1, 1}, + {&__pyx_n_s_with_value_type, __pyx_k_with_value_type, sizeof(__pyx_k_with_value_type), 0, 0, 1, 1}, + {&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 96, __pyx_L1_error) + __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) __PYX_ERR(0, 211, __pyx_L1_error) + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 297, __pyx_L1_error) + __pyx_builtin_min = __Pyx_GetBuiltinName(__pyx_n_s_min); if (!__pyx_builtin_min) __PYX_ERR(0, 378, __pyx_L1_error) + __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) __PYX_ERR(0, 380, __pyx_L1_error) + __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 630, __pyx_L1_error) + __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 774, __pyx_L1_error) + __pyx_builtin_AssertionError = __Pyx_GetBuiltinName(__pyx_n_s_AssertionError); if (!__pyx_builtin_AssertionError) __PYX_ERR(0, 795, __pyx_L1_error) + __pyx_builtin_map = __Pyx_GetBuiltinName(__pyx_n_s_map); if (!__pyx_builtin_map) __PYX_ERR(0, 971, __pyx_L1_error) + __pyx_builtin_NotImplemented = __Pyx_GetBuiltinName(__pyx_n_s_NotImplemented); if (!__pyx_builtin_NotImplemented) __PYX_ERR(0, 1034, __pyx_L1_error) + __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 1121, __pyx_L1_error) + __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 2425, __pyx_L1_error) + __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(1, 179, __pyx_L1_error) + __pyx_builtin_Ellipsis = __Pyx_GetBuiltinName(__pyx_n_s_Ellipsis); if (!__pyx_builtin_Ellipsis) __PYX_ERR(1, 399, __pyx_L1_error) + __pyx_builtin_id = __Pyx_GetBuiltinName(__pyx_n_s_id); if (!__pyx_builtin_id) __PYX_ERR(1, 608, __pyx_L1_error) + __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(1, 827, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +static int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "pysam/libcalignedsegment.pyx":297 + * typecode = 'i' + * else: + * raise ValueError( # <<<<<<<<<<<<<< + * "at least one signed integer out of range of " + * "BAM/SAM specification") + */ + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_at_least_one_signed_integer_out); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 297, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple_); + __Pyx_GIVEREF(__pyx_tuple_); + + /* "pysam/libcalignedsegment.pyx":309 + * typecode = 'I' + * else: + * raise ValueError( # <<<<<<<<<<<<<< + * "at least one integer out of range of BAM/SAM specification") + * else: + */ + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_at_least_one_integer_out_of_rang); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 309, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__2); + __Pyx_GIVEREF(__pyx_tuple__2); + + /* "pysam/libcalignedsegment.pyx":314 + * # Note: hex strings (H) are not supported yet + * if t is not bytes: + * value = value.encode('ascii') # <<<<<<<<<<<<<< + * if len(value) == 1: + * typecode = 'A' + */ + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); + + /* "pysam/libcalignedsegment.pyx":386 + * + * datafmt = "2sBBI%i%s" % (len(value), DATATYPE2FORMAT[typecode][0]) + * args.extend([pytag[:2], # <<<<<<<<<<<<<< + * ord("B"), + * typecode, + */ + __pyx_slice__5 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__5)) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__5); + __Pyx_GIVEREF(__pyx_slice__5); + + /* "pysam/libcalignedsegment.pyx":405 + * # save as bytes + * datafmt = "2sBBI%is" % (len(value) * DATATYPE2FORMAT[typecode][1]) + * args.extend([pytag[:2], # <<<<<<<<<<<<<< + * ord("B"), + * typecode, + */ + __pyx_slice__6 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__6)) __PYX_ERR(0, 405, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__6); + __Pyx_GIVEREF(__pyx_slice__6); + + /* "pysam/libcalignedsegment.pyx":428 + * datafmt = "2sB%s" % DATATYPE2FORMAT[typecode][0] + * + * args.extend([pytag[:2], # <<<<<<<<<<<<<< + * typecode, + * value]) + */ + __pyx_slice__7 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__7)) __PYX_ERR(0, 428, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__7); + __Pyx_GIVEREF(__pyx_slice__7); + + /* "pysam/libcalignedsegment.pyx":508 + * if op == BAM_CHARD_CLIP: + * if start_offset != 0 and start_offset != src.core.l_qseq: + * raise ValueError('Invalid clipping in CIGAR string') # <<<<<<<<<<<<<< + * elif op == BAM_CSOFT_CLIP: + * start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT + */ + __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_Invalid_clipping_in_CIGAR_string); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 508, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__9); + __Pyx_GIVEREF(__pyx_tuple__9); + + /* "pysam/libcalignedsegment.pyx":538 + * if op == BAM_CHARD_CLIP: + * if end_offset != src.core.l_qseq: + * raise ValueError('Invalid clipping in CIGAR string') # <<<<<<<<<<<<<< + * elif op == BAM_CSOFT_CLIP: + * end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT + */ + __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_Invalid_clipping_in_CIGAR_string); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 538, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__10); + __Pyx_GIVEREF(__pyx_tuple__10); + + /* "pysam/libcalignedsegment.pyx":630 + * dest.buf = calloc(MAX_PILEUP_BUFFER_SIZE, sizeof(uint8_t)) + * if dest.buf == NULL: + * raise MemoryError("could not allocate pileup buffer") # <<<<<<<<<<<<<< + * + * return dest + */ + __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_could_not_allocate_pileup_buffer); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 630, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__11); + __Pyx_GIVEREF(__pyx_tuple__11); + + /* "pysam/libcalignedsegment.pyx":742 + * cdef uint32_t max_len = get_alignment_length(src) + * if max_len == 0: + * raise ValueError("could not determine alignment length") # <<<<<<<<<<<<<< + * + * cdef char * s = calloc(max_len + 1, sizeof(char)) + */ + __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_could_not_determine_alignment_le); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 742, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__12); + __Pyx_GIVEREF(__pyx_tuple__12); + + /* "pysam/libcalignedsegment.pyx":774 + * pass # advances neither + * elif op == BAM_CPAD: + * raise NotImplementedError( # <<<<<<<<<<<<<< + * "Padding (BAM_CPAD, 6) is currently not supported. " + * "Please implement. Sorry about that.") + */ + __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_Padding_BAM_CPAD_6_is_currently); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 774, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__13); + __Pyx_GIVEREF(__pyx_tuple__13); + + /* "pysam/libcalignedsegment.pyx":857 + * ref_seq = build_alignment_sequence(src) + * if ref_seq is None: + * raise ValueError("MD tag not present") # <<<<<<<<<<<<<< + * + * cdef char * s = calloc(len(ref_seq) + 1, sizeof(char)) + */ + __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_MD_tag_not_present); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 857, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__14); + __Pyx_GIVEREF(__pyx_tuple__14); + + /* "pysam/libcalignedsegment.pyx":889 + * pass # advances neither + * elif op == BAM_CPAD: + * raise NotImplementedError( # <<<<<<<<<<<<<< + * "Padding (BAM_CPAD, 6) is currently not supported. " + * "Please implement. Sorry about that.") + */ + __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_Padding_BAM_CPAD_6_is_currently); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 889, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__15); + __Pyx_GIVEREF(__pyx_tuple__15); + + /* "pysam/libcalignedsegment.pyx":1065 + * if line.m: + * free(line.s) + * raise ValueError('sam_format failed') # <<<<<<<<<<<<<< + * else: + * raise NotImplementedError("todo") + */ + __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s_sam_format_failed); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 1065, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__17); + __Pyx_GIVEREF(__pyx_tuple__17); + + /* "pysam/libcalignedsegment.pyx":1067 + * raise ValueError('sam_format failed') + * else: + * raise NotImplementedError("todo") # <<<<<<<<<<<<<< + * + * ret = force_str(line.s[:line.l]) + */ + __pyx_tuple__18 = PyTuple_Pack(1, __pyx_n_s_todo); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 1067, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__18); + __Pyx_GIVEREF(__pyx_tuple__18); + + /* "pysam/libcalignedsegment.pyx":1119 + * """ + * # let htslib do the string conversions, but treat optional field properly as list + * vals = self.to_string().split("\t") # <<<<<<<<<<<<<< + * n = len(KEY_NAMES) - 1 + * return dict(list(zip(KEY_NAMES[:-1], vals[:n])) + [(KEY_NAMES[-1], vals[n:])]) + */ + __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s__16); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 1119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__19); + __Pyx_GIVEREF(__pyx_tuple__19); + + /* "pysam/libcalignedsegment.pyx":1121 + * vals = self.to_string().split("\t") + * n = len(KEY_NAMES) - 1 + * return dict(list(zip(KEY_NAMES[:-1], vals[:n])) + [(KEY_NAMES[-1], vals[n:])]) # <<<<<<<<<<<<<< + * + * @classmethod + */ + __pyx_slice__20 = PySlice_New(Py_None, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__20)) __PYX_ERR(0, 1121, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__20); + __Pyx_GIVEREF(__pyx_slice__20); + + /* "pysam/libcalignedsegment.pyx":1136 + * # the tags field can be missing + * return cls.fromstring( + * "\t".join((sam_dict[x] for x in KEY_NAMES[:-1])) + # <<<<<<<<<<<<<< + * "\t" + + * "\t".join(sam_dict.get(KEY_NAMES[-1], [])), header) + */ + __pyx_slice__21 = PySlice_New(Py_None, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__21)) __PYX_ERR(0, 1136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__21); + __Pyx_GIVEREF(__pyx_slice__21); + + /* "pysam/libcalignedsegment.pyx":1179 + * p) + * if retval == NULL: + * raise MemoryError("could not allocate memory") # <<<<<<<<<<<<<< + * + * src.core.l_extranul = l_extranul + */ + __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_could_not_allocate_memory); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 1179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__22); + __Pyx_GIVEREF(__pyx_tuple__22); + + /* "pysam/libcalignedsegment.pyx":1210 + * return self.header.get_reference_name(self._delegate.core.tid) + * else: + * raise ValueError("reference_name unknown if no header associated with record") # <<<<<<<<<<<<<< + * def __set__(self, reference): + * cdef int tid + */ + __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_reference_name_unknown_if_no_hea); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 1210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__23); + __Pyx_GIVEREF(__pyx_tuple__23); + + /* "pysam/libcalignedsegment.pyx":1222 + * self._delegate.core.tid = tid + * else: + * raise ValueError("reference_name can not be set if no header associated with record") # <<<<<<<<<<<<<< + * + * property reference_id: + */ + __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_s_reference_name_can_not_be_set_if); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 1222, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__25); + __Pyx_GIVEREF(__pyx_tuple__25); + + /* "pysam/libcalignedsegment.pyx":1316 + * return self.header.get_reference_name(self._delegate.core.mtid) + * else: + * raise ValueError("next_reference_name unknown if no header associated with record") # <<<<<<<<<<<<<< + * + * def __set__(self, reference): + */ + __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_next_reference_name_unknown_if_n); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 1316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__26); + __Pyx_GIVEREF(__pyx_tuple__26); + + /* "pysam/libcalignedsegment.pyx":1331 + * self._delegate.core.mtid = mtid + * else: + * raise ValueError("next_reference_name can not be set if no header associated with record") # <<<<<<<<<<<<<< + * + * property next_reference_start: + */ + __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_s_next_reference_name_can_not_be_s); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 1331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__28); + __Pyx_GIVEREF(__pyx_tuple__28); + + /* "pysam/libcalignedsegment.pyx":1432 + * + * if retval == NULL: + * raise MemoryError("could not allocate memory") # <<<<<<<<<<<<<< + * + * if l > 0: + */ + __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_could_not_allocate_memory); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 1432, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__29); + __Pyx_GIVEREF(__pyx_tuple__29); + + /* "pysam/libcalignedsegment.pyx":1836 + * s = force_str(self.query_sequence) + * if self.is_reverse: + * s = s.translate(maketrans("ACGTacgtNnXx", "TGCAtgcaNnXx"))[::-1] # <<<<<<<<<<<<<< + * return s + * + */ + __pyx_tuple__30 = PyTuple_Pack(2, __pyx_n_s_ACGTacgtNnXx, __pyx_n_s_TGCAtgcaNnXx); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 1836, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__30); + __Pyx_GIVEREF(__pyx_tuple__30); + __pyx_slice__31 = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_slice__31)) __PYX_ERR(0, 1836, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__31); + __Pyx_GIVEREF(__pyx_slice__31); + + /* "pysam/libcalignedsegment.pyx":1846 + * """ + * if self.is_reverse: + * return self.query_qualities[::-1] # <<<<<<<<<<<<<< + * else: + * return self.query_qualities + */ + __pyx_slice__32 = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_slice__32)) __PYX_ERR(0, 1846, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__32); + __Pyx_GIVEREF(__pyx_slice__32); + + /* "pysam/libcalignedsegment.pyx":1890 + * ref_seq = force_str(build_reference_sequence(src)) + * if ref_seq is None: + * raise ValueError("MD tag not present") # <<<<<<<<<<<<<< + * + * r_idx = 0 + */ + __pyx_tuple__33 = PyTuple_Pack(1, __pyx_kp_s_MD_tag_not_present); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 1890, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__33); + __Pyx_GIVEREF(__pyx_tuple__33); + + /* "pysam/libcalignedsegment.pyx":1956 + * + * elif op == BAM_CPAD: + * raise NotImplementedError( # <<<<<<<<<<<<<< + * "Padding (BAM_CPAD, 6) is currently not supported. " + * "Please implement. Sorry about that.") + */ + __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_s_Padding_BAM_CPAD_6_is_currently); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 1956, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__34); + __Pyx_GIVEREF(__pyx_tuple__34); + + /* "pysam/libcalignedsegment.pyx":2197 + * + * if retval == NULL: + * raise MemoryError("could not allocate memory") # <<<<<<<<<<<<<< + * + * # length is number of cigar operations, not bytes + */ + __pyx_tuple__35 = PyTuple_Pack(1, __pyx_kp_s_could_not_allocate_memory); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 2197, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__35); + __Pyx_GIVEREF(__pyx_tuple__35); + + /* "pysam/libcalignedsegment.pyx":2351 + * # remove tag and type code as set by bam_aux_append + * # first four chars of format (<2sB) + * fmt = '<' + fmt[4:] # <<<<<<<<<<<<<< + * # first two values to pack + * args = args[2:] + */ + __pyx_slice__36 = PySlice_New(__pyx_int_4, Py_None, Py_None); if (unlikely(!__pyx_slice__36)) __PYX_ERR(0, 2351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__36); + __Pyx_GIVEREF(__pyx_slice__36); + + /* "pysam/libcalignedsegment.pyx":2353 + * fmt = '<' + fmt[4:] + * # first two values to pack + * args = args[2:] # <<<<<<<<<<<<<< + * value_size = struct.calcsize(fmt) + * # buffer will be freed when object goes out of scope + */ + __pyx_slice__37 = PySlice_New(__pyx_int_2, Py_None, Py_None); if (unlikely(!__pyx_slice__37)) __PYX_ERR(0, 2353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__37); + __Pyx_GIVEREF(__pyx_slice__37); + + /* "pysam/libcalignedsegment.pyx":2577 + * pysam_bam_get_aux(src)) + * if retval == NULL: + * raise MemoryError("could not allocated memory") # <<<<<<<<<<<<<< + * + * # copy data only if there is any + */ + __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_s_could_not_allocated_memory); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 2577, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__38); + __Pyx_GIVEREF(__pyx_tuple__38); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") + */ + __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_self__delegate_cannot_be_convert); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__39); + __Pyx_GIVEREF(__pyx_tuple__39); + + /* "(tree fragment)":4 + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self._delegate cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + */ + __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_self__delegate_cannot_be_convert); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__40); + __Pyx_GIVEREF(__pyx_tuple__40); + + /* "pysam/libcalignedsegment.pyx":2773 + * ''' + * def __init__(self): + * raise TypeError("this class cannot be instantiated from Python") # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 2773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__41); + __Pyx_GIVEREF(__pyx_tuple__41); + + /* "pysam/libcalignedsegment.pyx":2829 + * def __get__(self): + * if self.plp == NULL or self.plp[0] == NULL: + * raise ValueError("PileupColumn accessed after iterator finished") # <<<<<<<<<<<<<< + * + * cdef int x + */ + __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_PileupColumn_accessed_after_iter); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 2829, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__43); + __Pyx_GIVEREF(__pyx_tuple__43); + + /* "pysam/libcalignedsegment.pyx":3040 + * # quicker to ensemble all and split than to encode all separately. + * # ignore last ":" + * return force_str(PyBytes_FromStringAndSize(buf, n-1)).split(":") # <<<<<<<<<<<<<< + * + * def get_query_qualities(self): + */ + __pyx_tuple__45 = PyTuple_Pack(1, __pyx_kp_s__44); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 3040, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__45); + __Pyx_GIVEREF(__pyx_tuple__45); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("self.plp cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self.plp cannot be converted to a Python object for pickling") + */ + __pyx_tuple__46 = PyTuple_Pack(1, __pyx_kp_s_self_plp_cannot_be_converted_to); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__46); + __Pyx_GIVEREF(__pyx_tuple__46); + + /* "(tree fragment)":4 + * raise TypeError("self.plp cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self.plp cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + */ + __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_s_self_plp_cannot_be_converted_to); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__47); + __Pyx_GIVEREF(__pyx_tuple__47); + + /* "pysam/libcalignedsegment.pyx":3128 + * + * def __init__(self): + * raise TypeError( # <<<<<<<<<<<<<< + * "this class cannot be instantiated from Python") + * + */ + __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 3128, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__48); + __Pyx_GIVEREF(__pyx_tuple__48); + + /* "View.MemoryView":132 + * + * if not self.ndim: + * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<< + * + * if itemsize <= 0: + */ + __pyx_tuple__54 = PyTuple_Pack(1, __pyx_kp_s_Empty_shape_tuple_for_cython_arr); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(1, 132, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__54); + __Pyx_GIVEREF(__pyx_tuple__54); + + /* "View.MemoryView":135 + * + * if itemsize <= 0: + * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<< + * + * if not isinstance(format, bytes): + */ + __pyx_tuple__55 = PyTuple_Pack(1, __pyx_kp_s_itemsize_0_for_cython_array); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(1, 135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__55); + __Pyx_GIVEREF(__pyx_tuple__55); + + /* "View.MemoryView":138 + * + * if not isinstance(format, bytes): + * format = format.encode('ASCII') # <<<<<<<<<<<<<< + * self._format = format # keep a reference to the byte string + * self.format = self._format + */ + __pyx_tuple__56 = PyTuple_Pack(1, __pyx_n_s_ASCII); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(1, 138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__56); + __Pyx_GIVEREF(__pyx_tuple__56); + + /* "View.MemoryView":147 + * + * if not self._shape: + * raise MemoryError("unable to allocate shape and strides.") # <<<<<<<<<<<<<< + * + * + */ + __pyx_tuple__57 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_shape_and_str); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(1, 147, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__57); + __Pyx_GIVEREF(__pyx_tuple__57); + + /* "View.MemoryView":175 + * self.data = malloc(self.len) + * if not self.data: + * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<< + * + * if self.dtype_is_object: + */ + __pyx_tuple__58 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_array_data); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(1, 175, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__58); + __Pyx_GIVEREF(__pyx_tuple__58); + + /* "View.MemoryView":191 + * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS + * if not (flags & bufmode): + * raise ValueError("Can only create a buffer that is contiguous in memory.") # <<<<<<<<<<<<<< + * info.buf = self.data + * info.len = self.len + */ + __pyx_tuple__59 = PyTuple_Pack(1, __pyx_kp_s_Can_only_create_a_buffer_that_is); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(1, 191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__59); + __Pyx_GIVEREF(__pyx_tuple__59); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + __pyx_tuple__60 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__60); + __Pyx_GIVEREF(__pyx_tuple__60); + + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + */ + __pyx_tuple__61 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__61); + __Pyx_GIVEREF(__pyx_tuple__61); + + /* "View.MemoryView":413 + * def __setitem__(memoryview self, object index, object value): + * if self.view.readonly: + * raise TypeError("Cannot assign to read-only memoryview") # <<<<<<<<<<<<<< + * + * have_slices, index = _unellipsify(index, self.view.ndim) + */ + __pyx_tuple__62 = PyTuple_Pack(1, __pyx_kp_s_Cannot_assign_to_read_only_memor); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(1, 413, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__62); + __Pyx_GIVEREF(__pyx_tuple__62); + + /* "View.MemoryView":490 + * result = struct.unpack(self.view.format, bytesitem) + * except struct.error: + * raise ValueError("Unable to convert item to object") # <<<<<<<<<<<<<< + * else: + * if len(self.view.format) == 1: + */ + __pyx_tuple__63 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_convert_item_to_object); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(1, 490, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__63); + __Pyx_GIVEREF(__pyx_tuple__63); + + /* "View.MemoryView":515 + * def __getbuffer__(self, Py_buffer *info, int flags): + * if flags & PyBUF_WRITABLE and self.view.readonly: + * raise ValueError("Cannot create writable memory view from read-only memoryview") # <<<<<<<<<<<<<< + * + * if flags & PyBUF_STRIDES: + */ + __pyx_tuple__64 = PyTuple_Pack(1, __pyx_kp_s_Cannot_create_writable_memory_vi); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(1, 515, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__64); + __Pyx_GIVEREF(__pyx_tuple__64); + + /* "View.MemoryView":565 + * if self.view.strides == NULL: + * + * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<< + * + * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) + */ + __pyx_tuple__65 = PyTuple_Pack(1, __pyx_kp_s_Buffer_view_does_not_expose_stri); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(1, 565, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__65); + __Pyx_GIVEREF(__pyx_tuple__65); + + /* "View.MemoryView":572 + * def suboffsets(self): + * if self.view.suboffsets == NULL: + * return (-1,) * self.view.ndim # <<<<<<<<<<<<<< + * + * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) + */ + __pyx_tuple__66 = PyTuple_New(1); if (unlikely(!__pyx_tuple__66)) __PYX_ERR(1, 572, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__66); + __Pyx_INCREF(__pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_tuple__66, 0, __pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_tuple__66); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + __pyx_tuple__67 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__67); + __Pyx_GIVEREF(__pyx_tuple__67); + + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + */ + __pyx_tuple__68 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__68)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__68); + __Pyx_GIVEREF(__pyx_tuple__68); + + /* "View.MemoryView":677 + * if item is Ellipsis: + * if not seen_ellipsis: + * result.extend([slice(None)] * (ndim - len(tup) + 1)) # <<<<<<<<<<<<<< + * seen_ellipsis = True + * else: + */ + __pyx_slice__69 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__69)) __PYX_ERR(1, 677, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__69); + __Pyx_GIVEREF(__pyx_slice__69); + + /* "View.MemoryView":680 + * seen_ellipsis = True + * else: + * result.append(slice(None)) # <<<<<<<<<<<<<< + * have_slices = True + * else: + */ + __pyx_slice__70 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__70)) __PYX_ERR(1, 680, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__70); + __Pyx_GIVEREF(__pyx_slice__70); -static void __pyx_tp_dealloc_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr(PyObject *o) { - struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *)o; - PyObject_GC_UnTrack(o); - Py_CLEAR(p->__pyx_v_x); - Py_CLEAR(p->__pyx_v_y); - Py_CLEAR(p->__pyx_t_0); - Py_CLEAR(p->__pyx_t_1); - if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr)))) { - __pyx_freelist_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr[__pyx_freecount_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr++] = ((struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *)o); - } else { - (*Py_TYPE(o)->tp_free)(o); - } -} + /* "View.MemoryView":691 + * nslices = ndim - len(result) + * if nslices: + * result.extend([slice(None)] * nslices) # <<<<<<<<<<<<<< + * + * return have_slices or nslices, tuple(result) + */ + __pyx_slice__71 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__71)) __PYX_ERR(1, 691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__71); + __Pyx_GIVEREF(__pyx_slice__71); -static int __pyx_tp_traverse_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr *)o; - if (p->__pyx_v_x) { - e = (*v)(p->__pyx_v_x, a); if (e) return e; - } - if (p->__pyx_v_y) { - e = (*v)(p->__pyx_v_y, a); if (e) return e; - } - if (p->__pyx_t_0) { - e = (*v)(p->__pyx_t_0, a); if (e) return e; - } - if (p->__pyx_t_1) { - e = (*v)(p->__pyx_t_1, a); if (e) return e; - } - return 0; -} + /* "View.MemoryView":698 + * for suboffset in suboffsets[:ndim]: + * if suboffset >= 0: + * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<< + * + * + */ + __pyx_tuple__72 = PyTuple_Pack(1, __pyx_kp_s_Indirect_dimensions_not_supporte); if (unlikely(!__pyx_tuple__72)) __PYX_ERR(1, 698, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__72); + __Pyx_GIVEREF(__pyx_tuple__72); -static PyTypeObject __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcalignedsegment.__pyx_scope_struct_1_genexpr", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ - #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - 0, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ - #endif -}; -static struct __pyx_vtabstruct_array __pyx_vtable_array; + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + __pyx_tuple__73 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__73); + __Pyx_GIVEREF(__pyx_tuple__73); -static PyObject *__pyx_tp_new_array(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_array_obj *p; - PyObject *o; - if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { - o = (*t->tp_alloc)(t, 0); - } else { - o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); - } - if (unlikely(!o)) return 0; - p = ((struct __pyx_array_obj *)o); - p->__pyx_vtab = __pyx_vtabptr_array; - p->mode = ((PyObject*)Py_None); Py_INCREF(Py_None); - p->_format = ((PyObject*)Py_None); Py_INCREF(Py_None); - if (unlikely(__pyx_array___cinit__(o, a, k) < 0)) goto bad; - return o; - bad: - Py_DECREF(o); o = 0; - return NULL; -} + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + */ + __pyx_tuple__74 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__74)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__74); + __Pyx_GIVEREF(__pyx_tuple__74); -static void __pyx_tp_dealloc_array(PyObject *o) { - struct __pyx_array_obj *p = (struct __pyx_array_obj *)o; - #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { - if (PyObject_CallFinalizerFromDealloc(o)) return; - } - #endif - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_array___dealloc__(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - Py_CLEAR(p->mode); - Py_CLEAR(p->_format); - (*Py_TYPE(o)->tp_free)(o); -} -static PyObject *__pyx_sq_item_array(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} + /* "pysam/libcalignedsegment.pyx":102 + * maketrans = string.maketrans + * + * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=XB])") # <<<<<<<<<<<<<< + * + * # names for keys in dictionary representation of an AlignedSegment + */ + __pyx_tuple__76 = PyTuple_Pack(1, __pyx_kp_s_d_MIDNSHP_XB); if (unlikely(!__pyx_tuple__76)) __PYX_ERR(0, 102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__76); + __Pyx_GIVEREF(__pyx_tuple__76); -static int __pyx_mp_ass_subscript_array(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_array___setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name); - return -1; - } -} + /* "pysam/libcalignedsegment.pyx":325 + * # mapping python array.array and htslib typecodes to struct typecodes + * DATATYPE2FORMAT = { + * ord('c'): ('b', 1), # <<<<<<<<<<<<<< + * ord('C'): ('B', 1), + * ord('s'): ('h', 2), + */ + __pyx_tuple__77 = PyTuple_Pack(2, __pyx_n_s_b, __pyx_int_1); if (unlikely(!__pyx_tuple__77)) __PYX_ERR(0, 325, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__77); + __Pyx_GIVEREF(__pyx_tuple__77); + + /* "pysam/libcalignedsegment.pyx":326 + * DATATYPE2FORMAT = { + * ord('c'): ('b', 1), + * ord('C'): ('B', 1), # <<<<<<<<<<<<<< + * ord('s'): ('h', 2), + * ord('S'): ('H', 2), + */ + __pyx_tuple__78 = PyTuple_Pack(2, __pyx_n_s_B, __pyx_int_1); if (unlikely(!__pyx_tuple__78)) __PYX_ERR(0, 326, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__78); + __Pyx_GIVEREF(__pyx_tuple__78); + + /* "pysam/libcalignedsegment.pyx":327 + * ord('c'): ('b', 1), + * ord('C'): ('B', 1), + * ord('s'): ('h', 2), # <<<<<<<<<<<<<< + * ord('S'): ('H', 2), + * ord('i'): ('i', 4), + */ + __pyx_tuple__79 = PyTuple_Pack(2, __pyx_n_s_h, __pyx_int_2); if (unlikely(!__pyx_tuple__79)) __PYX_ERR(0, 327, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__79); + __Pyx_GIVEREF(__pyx_tuple__79); -static PyObject *__pyx_tp_getattro_array(PyObject *o, PyObject *n) { - PyObject *v = __Pyx_PyObject_GenericGetAttr(o, n); - if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - v = __pyx_array___getattr__(o, n); - } - return v; -} + /* "pysam/libcalignedsegment.pyx":328 + * ord('C'): ('B', 1), + * ord('s'): ('h', 2), + * ord('S'): ('H', 2), # <<<<<<<<<<<<<< + * ord('i'): ('i', 4), + * ord('I'): ('I', 4), + */ + __pyx_tuple__80 = PyTuple_Pack(2, __pyx_n_s_H, __pyx_int_2); if (unlikely(!__pyx_tuple__80)) __PYX_ERR(0, 328, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__80); + __Pyx_GIVEREF(__pyx_tuple__80); + + /* "pysam/libcalignedsegment.pyx":329 + * ord('s'): ('h', 2), + * ord('S'): ('H', 2), + * ord('i'): ('i', 4), # <<<<<<<<<<<<<< + * ord('I'): ('I', 4), + * ord('f'): ('f', 4), + */ + __pyx_tuple__81 = PyTuple_Pack(2, __pyx_n_s_i, __pyx_int_4); if (unlikely(!__pyx_tuple__81)) __PYX_ERR(0, 329, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__81); + __Pyx_GIVEREF(__pyx_tuple__81); + + /* "pysam/libcalignedsegment.pyx":330 + * ord('S'): ('H', 2), + * ord('i'): ('i', 4), + * ord('I'): ('I', 4), # <<<<<<<<<<<<<< + * ord('f'): ('f', 4), + * ord('d'): ('d', 8), + */ + __pyx_tuple__82 = PyTuple_Pack(2, __pyx_n_s_I, __pyx_int_4); if (unlikely(!__pyx_tuple__82)) __PYX_ERR(0, 330, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__82); + __Pyx_GIVEREF(__pyx_tuple__82); + + /* "pysam/libcalignedsegment.pyx":331 + * ord('i'): ('i', 4), + * ord('I'): ('I', 4), + * ord('f'): ('f', 4), # <<<<<<<<<<<<<< + * ord('d'): ('d', 8), + * ord('A'): ('c', 1), + */ + __pyx_tuple__83 = PyTuple_Pack(2, __pyx_n_s_f, __pyx_int_4); if (unlikely(!__pyx_tuple__83)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__83); + __Pyx_GIVEREF(__pyx_tuple__83); + + /* "pysam/libcalignedsegment.pyx":332 + * ord('I'): ('I', 4), + * ord('f'): ('f', 4), + * ord('d'): ('d', 8), # <<<<<<<<<<<<<< + * ord('A'): ('c', 1), + * ord('a'): ('c', 1)} + */ + __pyx_tuple__84 = PyTuple_Pack(2, __pyx_n_s_d, __pyx_int_8); if (unlikely(!__pyx_tuple__84)) __PYX_ERR(0, 332, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__84); + __Pyx_GIVEREF(__pyx_tuple__84); + + /* "pysam/libcalignedsegment.pyx":333 + * ord('f'): ('f', 4), + * ord('d'): ('d', 8), + * ord('A'): ('c', 1), # <<<<<<<<<<<<<< + * ord('a'): ('c', 1)} + * + */ + __pyx_tuple__85 = PyTuple_Pack(2, __pyx_n_s_c_2, __pyx_int_1); if (unlikely(!__pyx_tuple__85)) __PYX_ERR(0, 333, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__85); + __Pyx_GIVEREF(__pyx_tuple__85); -static PyObject *__pyx_getprop___pyx_array_memview(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(o); -} + /* "pysam/libcalignedsegment.pyx":334 + * ord('d'): ('d', 8), + * ord('A'): ('c', 1), + * ord('a'): ('c', 1)} # <<<<<<<<<<<<<< + * + * + */ + __pyx_tuple__86 = PyTuple_Pack(2, __pyx_n_s_c_2, __pyx_int_1); if (unlikely(!__pyx_tuple__86)) __PYX_ERR(0, 334, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__86); + __Pyx_GIVEREF(__pyx_tuple__86); -static PyMethodDef __pyx_methods_array[] = { - {"__getattr__", (PyCFunction)__pyx_array___getattr__, METH_O|METH_COEXIST, 0}, - {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_array_1__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_array_3__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; + /* "(tree fragment)":1 + * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0xbbc0b95: + * from pickle import PickleError as __pyx_PickleError + */ + __pyx_tuple__87 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__87)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__87); + __Pyx_GIVEREF(__pyx_tuple__87); + __pyx_codeobj__49 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__87, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_PileupRead, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__49)) __PYX_ERR(1, 1, __pyx_L1_error) + + /* "EnumBase":28 + * class __Pyx_EnumBase(int): + * __metaclass__ = __Pyx_EnumMeta + * def __new__(cls, value, name=None): # <<<<<<<<<<<<<< + * for v in cls: + * if v == value: + */ + __pyx_tuple__88 = PyTuple_Pack(5, __pyx_n_s_cls, __pyx_n_s_value, __pyx_n_s_name, __pyx_n_s_v, __pyx_n_s_res); if (unlikely(!__pyx_tuple__88)) __PYX_ERR(1, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__88); + __Pyx_GIVEREF(__pyx_tuple__88); + __pyx_codeobj__50 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__88, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_new, 28, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__50)) __PYX_ERR(1, 28, __pyx_L1_error) + __pyx_tuple__89 = PyTuple_Pack(1, ((PyObject *)Py_None)); if (unlikely(!__pyx_tuple__89)) __PYX_ERR(1, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__89); + __Pyx_GIVEREF(__pyx_tuple__89); + + /* "EnumBase":39 + * cls.__members__[name] = res + * return res + * def __repr__(self): # <<<<<<<<<<<<<< + * return "<%s.%s: %d>" % (self.__class__.__name__, self.name, self) + * def __str__(self): + */ + __pyx_tuple__90 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__90)) __PYX_ERR(1, 39, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__90); + __Pyx_GIVEREF(__pyx_tuple__90); + __pyx_codeobj__51 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__90, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_repr, 39, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__51)) __PYX_ERR(1, 39, __pyx_L1_error) -static struct PyGetSetDef __pyx_getsets_array[] = { - {(char *)"memview", __pyx_getprop___pyx_array_memview, 0, (char *)0, 0}, - {0, 0, 0, 0, 0} -}; + /* "EnumBase":41 + * def __repr__(self): + * return "<%s.%s: %d>" % (self.__class__.__name__, self.name, self) + * def __str__(self): # <<<<<<<<<<<<<< + * return "%s.%s" % (self.__class__.__name__, self.name) + * + */ + __pyx_tuple__91 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__91)) __PYX_ERR(1, 41, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__91); + __Pyx_GIVEREF(__pyx_tuple__91); + __pyx_codeobj__52 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__91, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_str, 41, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__52)) __PYX_ERR(1, 41, __pyx_L1_error) -static PySequenceMethods __pyx_tp_as_sequence_array = { - __pyx_array___len__, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - __pyx_sq_item_array, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; + /* "(tree fragment)":1 + * def __pyx_unpickle___Pyx_EnumMeta(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0xd41d8cd: + * from pickle import PickleError as __pyx_PickleError + */ + __pyx_tuple__92 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__92)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__92); + __Pyx_GIVEREF(__pyx_tuple__92); + __pyx_codeobj__53 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__92, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle___Pyx_EnumMeta, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__53)) __PYX_ERR(1, 1, __pyx_L1_error) -static PyMappingMethods __pyx_tp_as_mapping_array = { - __pyx_array___len__, /*mp_length*/ - __pyx_array___getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_array, /*mp_ass_subscript*/ -}; + /* "View.MemoryView":285 + * return self.name + * + * cdef generic = Enum("") # <<<<<<<<<<<<<< + * cdef strided = Enum("") # default + * cdef indirect = Enum("") + */ + __pyx_tuple__93 = PyTuple_Pack(1, __pyx_kp_s_strided_and_direct_or_indirect); if (unlikely(!__pyx_tuple__93)) __PYX_ERR(1, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__93); + __Pyx_GIVEREF(__pyx_tuple__93); -static PyBufferProcs __pyx_tp_as_buffer_array = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - __pyx_array_getbuffer, /*bf_getbuffer*/ - 0, /*bf_releasebuffer*/ -}; + /* "View.MemoryView":286 + * + * cdef generic = Enum("") + * cdef strided = Enum("") # default # <<<<<<<<<<<<<< + * cdef indirect = Enum("") + * + */ + __pyx_tuple__94 = PyTuple_Pack(1, __pyx_kp_s_strided_and_direct); if (unlikely(!__pyx_tuple__94)) __PYX_ERR(1, 286, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__94); + __Pyx_GIVEREF(__pyx_tuple__94); -static PyTypeObject __pyx_type___pyx_array = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcalignedsegment.array", /*tp_name*/ - sizeof(struct __pyx_array_obj), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_array, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ - #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - &__pyx_tp_as_sequence_array, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_array, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - __pyx_tp_getattro_array, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_array, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_array, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_array, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_array, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ - #endif -}; + /* "View.MemoryView":287 + * cdef generic = Enum("") + * cdef strided = Enum("") # default + * cdef indirect = Enum("") # <<<<<<<<<<<<<< + * + * + */ + __pyx_tuple__95 = PyTuple_Pack(1, __pyx_kp_s_strided_and_indirect); if (unlikely(!__pyx_tuple__95)) __PYX_ERR(1, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__95); + __Pyx_GIVEREF(__pyx_tuple__95); -static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - struct __pyx_MemviewEnum_obj *p; - PyObject *o; - if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { - o = (*t->tp_alloc)(t, 0); - } else { - o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); - } - if (unlikely(!o)) return 0; - p = ((struct __pyx_MemviewEnum_obj *)o); - p->name = Py_None; Py_INCREF(Py_None); - return o; -} + /* "View.MemoryView":290 + * + * + * cdef contiguous = Enum("") # <<<<<<<<<<<<<< + * cdef indirect_contiguous = Enum("") + * + */ + __pyx_tuple__96 = PyTuple_Pack(1, __pyx_kp_s_contiguous_and_direct); if (unlikely(!__pyx_tuple__96)) __PYX_ERR(1, 290, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__96); + __Pyx_GIVEREF(__pyx_tuple__96); -static void __pyx_tp_dealloc_Enum(PyObject *o) { - struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; - #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { - if (PyObject_CallFinalizerFromDealloc(o)) return; - } - #endif - PyObject_GC_UnTrack(o); - Py_CLEAR(p->name); - (*Py_TYPE(o)->tp_free)(o); -} + /* "View.MemoryView":291 + * + * cdef contiguous = Enum("") + * cdef indirect_contiguous = Enum("") # <<<<<<<<<<<<<< + * + * + */ + __pyx_tuple__97 = PyTuple_Pack(1, __pyx_kp_s_contiguous_and_indirect); if (unlikely(!__pyx_tuple__97)) __PYX_ERR(1, 291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__97); + __Pyx_GIVEREF(__pyx_tuple__97); -static int __pyx_tp_traverse_Enum(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; - if (p->name) { - e = (*v)(p->name, a); if (e) return e; - } + /* "(tree fragment)":1 + * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0xb068931: + * from pickle import PickleError as __pyx_PickleError + */ + __pyx_tuple__98 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__98)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__98); + __Pyx_GIVEREF(__pyx_tuple__98); + __pyx_codeobj__75 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__98, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_Enum, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__75)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; } -static int __pyx_tp_clear_Enum(PyObject *o) { - PyObject* tmp; - struct __pyx_MemviewEnum_obj *p = (struct __pyx_MemviewEnum_obj *)o; - tmp = ((PyObject*)p->name); - p->name = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); +static int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_65 = PyInt_FromLong(65); if (unlikely(!__pyx_int_65)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_66 = PyInt_FromLong(66); if (unlikely(!__pyx_int_66)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_67 = PyInt_FromLong(67); if (unlikely(!__pyx_int_67)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_73 = PyInt_FromLong(73); if (unlikely(!__pyx_int_73)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_83 = PyInt_FromLong(83); if (unlikely(!__pyx_int_83)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_97 = PyInt_FromLong(97); if (unlikely(!__pyx_int_97)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_99 = PyInt_FromLong(99); if (unlikely(!__pyx_int_99)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_100 = PyInt_FromLong(100); if (unlikely(!__pyx_int_100)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_102 = PyInt_FromLong(102); if (unlikely(!__pyx_int_102)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_105 = PyInt_FromLong(105); if (unlikely(!__pyx_int_105)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_115 = PyInt_FromLong(115); if (unlikely(!__pyx_int_115)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_184977713 = PyInt_FromLong(184977713L); if (unlikely(!__pyx_int_184977713)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_196873109 = PyInt_FromLong(196873109L); if (unlikely(!__pyx_int_196873109)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_222419149 = PyInt_FromLong(222419149L); if (unlikely(!__pyx_int_222419149)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_4294967295 = PyInt_FromString((char *)"4294967295", 0, 0); if (unlikely(!__pyx_int_4294967295)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error) return 0; + __pyx_L1_error:; + return -1; } -static PyMethodDef __pyx_methods_Enum[] = { - {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_1__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_MemviewEnum_3__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; +static int __Pyx_modinit_global_init_code(void); /*proto*/ +static int __Pyx_modinit_variable_export_code(void); /*proto*/ +static int __Pyx_modinit_function_export_code(void); /*proto*/ +static int __Pyx_modinit_type_init_code(void); /*proto*/ +static int __Pyx_modinit_type_import_code(void); /*proto*/ +static int __Pyx_modinit_variable_import_code(void); /*proto*/ +static int __Pyx_modinit_function_import_code(void); /*proto*/ -static PyTypeObject __pyx_type___pyx_MemviewEnum = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcalignedsegment.Enum", /*tp_name*/ - sizeof(struct __pyx_MemviewEnum_obj), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_Enum, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ - #endif - __pyx_MemviewEnum___repr__, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_Enum, /*tp_traverse*/ - __pyx_tp_clear_Enum, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_Enum, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - __pyx_MemviewEnum___init__, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_Enum, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ - #endif -}; -static struct __pyx_vtabstruct_memoryview __pyx_vtable_memoryview; +static int __Pyx_modinit_global_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); + /*--- Global init code ---*/ + __Pyx_OrderedDict = Py_None; Py_INCREF(Py_None); + __Pyx_EnumBase = Py_None; Py_INCREF(Py_None); + generic = Py_None; Py_INCREF(Py_None); + strided = Py_None; Py_INCREF(Py_None); + indirect = Py_None; Py_INCREF(Py_None); + contiguous = Py_None; Py_INCREF(Py_None); + indirect_contiguous = Py_None; Py_INCREF(Py_None); + __Pyx_globals = ((PyObject*)Py_None); Py_INCREF(Py_None); + __Pyx_RefNannyFinishContext(); + return 0; +} -static PyObject *__pyx_tp_new_memoryview(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_memoryview_obj *p; - PyObject *o; - if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { - o = (*t->tp_alloc)(t, 0); - } else { - o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); - } - if (unlikely(!o)) return 0; - p = ((struct __pyx_memoryview_obj *)o); - p->__pyx_vtab = __pyx_vtabptr_memoryview; - p->obj = Py_None; Py_INCREF(Py_None); - p->_size = Py_None; Py_INCREF(Py_None); - p->_array_interface = Py_None; Py_INCREF(Py_None); - p->view.obj = NULL; - if (unlikely(__pyx_memoryview___cinit__(o, a, k) < 0)) goto bad; - return o; - bad: - Py_DECREF(o); o = 0; - return NULL; +static int __Pyx_modinit_variable_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); + /*--- Variable export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); + /*--- Function export code ---*/ + if (__Pyx_ExportFunction("makeAlignedSegment", (void (*)(void))__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment, "struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *(bam1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_ExportFunction("makePileupColumn", (void (*)(void))__pyx_f_5pysam_18libcalignedsegment_makePileupColumn, "struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *(bam_pileup1_t **, int, int, int, uint32_t, char *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_ExportFunction("makePileupRead", (void (*)(void))__pyx_f_5pysam_18libcalignedsegment_makePileupRead, "struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead *(bam_pileup1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_ExportFunction("get_alignment_length", (void (*)(void))__pyx_f_5pysam_18libcalignedsegment_get_alignment_length, "uint32_t (bam1_t *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; } -static void __pyx_tp_dealloc_memoryview(PyObject *o) { - struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; - #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { - if (PyObject_CallFinalizerFromDealloc(o)) return; +static int __Pyx_modinit_type_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment = &__pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment; + __pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment.set_tag = (PyObject *(*)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag *__pyx_optional_args))__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_set_tag; + __pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment.get_tag = (PyObject *(*)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag *__pyx_optional_args))__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_get_tag; + __pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment.has_tag = (PyObject *(*)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch))__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_has_tag; + __pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment.to_string = (PyObject *(*)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch))__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_to_string; + __pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment.tostring = (PyObject *(*)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring *__pyx_optional_args))__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_tostring; + if (PyType_Ready(&__pyx_type_5pysam_18libcalignedsegment_AlignedSegment) < 0) __PYX_ERR(0, 899, __pyx_L1_error) + __pyx_type_5pysam_18libcalignedsegment_AlignedSegment.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_18libcalignedsegment_AlignedSegment.tp_dictoffset && __pyx_type_5pysam_18libcalignedsegment_AlignedSegment.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_18libcalignedsegment_AlignedSegment.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + #if CYTHON_COMPILING_IN_CPYTHON + { + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_18libcalignedsegment_AlignedSegment, "__str__"); if (unlikely(!wrapper)) __PYX_ERR(0, 899, __pyx_L1_error) + if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { + __pyx_wrapperbase_5pysam_18libcalignedsegment_14AlignedSegment_4__str__ = *((PyWrapperDescrObject *)wrapper)->d_base; + __pyx_wrapperbase_5pysam_18libcalignedsegment_14AlignedSegment_4__str__.doc = __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_4__str__; + ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_18libcalignedsegment_14AlignedSegment_4__str__; + } } #endif - PyObject_GC_UnTrack(o); + if (__Pyx_SetVtable(__pyx_type_5pysam_18libcalignedsegment_AlignedSegment.tp_dict, __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment) < 0) __PYX_ERR(0, 899, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "AlignedSegment", (PyObject *)&__pyx_type_5pysam_18libcalignedsegment_AlignedSegment) < 0) __PYX_ERR(0, 899, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_18libcalignedsegment_AlignedSegment) < 0) __PYX_ERR(0, 899, __pyx_L1_error) + __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment = &__pyx_type_5pysam_18libcalignedsegment_AlignedSegment; + if (PyType_Ready(&__pyx_type_5pysam_18libcalignedsegment_PileupColumn) < 0) __PYX_ERR(0, 2763, __pyx_L1_error) + __pyx_type_5pysam_18libcalignedsegment_PileupColumn.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_18libcalignedsegment_PileupColumn.tp_dictoffset && __pyx_type_5pysam_18libcalignedsegment_PileupColumn.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_18libcalignedsegment_PileupColumn.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_memoryview___dealloc__(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_18libcalignedsegment_PileupColumn, "__len__"); if (unlikely(!wrapper)) __PYX_ERR(0, 2763, __pyx_L1_error) + if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { + __pyx_wrapperbase_5pysam_18libcalignedsegment_12PileupColumn_8__len__ = *((PyWrapperDescrObject *)wrapper)->d_base; + __pyx_wrapperbase_5pysam_18libcalignedsegment_12PileupColumn_8__len__.doc = __pyx_doc_5pysam_18libcalignedsegment_12PileupColumn_8__len__; + ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_18libcalignedsegment_12PileupColumn_8__len__; + } } - Py_CLEAR(p->obj); - Py_CLEAR(p->_size); - Py_CLEAR(p->_array_interface); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_memoryview(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; - if (p->obj) { - e = (*v)(p->obj, a); if (e) return e; + #endif + if (PyObject_SetAttrString(__pyx_m, "PileupColumn", (PyObject *)&__pyx_type_5pysam_18libcalignedsegment_PileupColumn) < 0) __PYX_ERR(0, 2763, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_18libcalignedsegment_PileupColumn) < 0) __PYX_ERR(0, 2763, __pyx_L1_error) + __pyx_ptype_5pysam_18libcalignedsegment_PileupColumn = &__pyx_type_5pysam_18libcalignedsegment_PileupColumn; + if (PyType_Ready(&__pyx_type_5pysam_18libcalignedsegment_PileupRead) < 0) __PYX_ERR(0, 3121, __pyx_L1_error) + __pyx_type_5pysam_18libcalignedsegment_PileupRead.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_18libcalignedsegment_PileupRead.tp_dictoffset && __pyx_type_5pysam_18libcalignedsegment_PileupRead.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_18libcalignedsegment_PileupRead.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (p->_size) { - e = (*v)(p->_size, a); if (e) return e; + if (PyObject_SetAttrString(__pyx_m, "PileupRead", (PyObject *)&__pyx_type_5pysam_18libcalignedsegment_PileupRead) < 0) __PYX_ERR(0, 3121, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_18libcalignedsegment_PileupRead) < 0) __PYX_ERR(0, 3121, __pyx_L1_error) + __pyx_ptype_5pysam_18libcalignedsegment_PileupRead = &__pyx_type_5pysam_18libcalignedsegment_PileupRead; + if (PyType_Ready(&__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr) < 0) __PYX_ERR(0, 96, __pyx_L1_error) + __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr.tp_dictoffset && __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } - if (p->_array_interface) { - e = (*v)(p->_array_interface, a); if (e) return e; + __pyx_ptype_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr = &__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr; + if (PyType_Ready(&__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr) < 0) __PYX_ERR(0, 99, __pyx_L1_error) + __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr.tp_dictoffset && __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } - if (p->view.obj) { - e = (*v)(p->view.obj, a); if (e) return e; + __pyx_ptype_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr = &__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr; + if (PyType_Ready(&__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict) < 0) __PYX_ERR(0, 1124, __pyx_L1_error) + __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict.tp_dictoffset && __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + } + __pyx_ptype_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict = &__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_2_from_dict; + if (PyType_Ready(&__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr) < 0) __PYX_ERR(0, 1136, __pyx_L1_error) + __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr.tp_dictoffset && __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + } + __pyx_ptype_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr = &__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_3_genexpr; + __Pyx_EnumMeta.tp_base = (&PyType_Type); + if (PyType_Ready(&__Pyx_EnumMeta) < 0) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_EnumMeta.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__Pyx_EnumMeta.tp_dictoffset && __Pyx_EnumMeta.tp_getattro == PyObject_GenericGetAttr)) { + __Pyx_EnumMeta.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (__Pyx_setup_reduce((PyObject*)&__Pyx_EnumMeta) < 0) __PYX_ERR(1, 15, __pyx_L1_error) + __pyx_ptype___Pyx_EnumMeta = &__Pyx_EnumMeta; + __pyx_vtabptr_array = &__pyx_vtable_array; + __pyx_vtable_array.get_memview = (PyObject *(*)(struct __pyx_array_obj *))__pyx_array_get_memview; + if (PyType_Ready(&__pyx_type___pyx_array) < 0) __PYX_ERR(1, 104, __pyx_L1_error) + __pyx_type___pyx_array.tp_print = 0; + if (__Pyx_SetVtable(__pyx_type___pyx_array.tp_dict, __pyx_vtabptr_array) < 0) __PYX_ERR(1, 104, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_array) < 0) __PYX_ERR(1, 104, __pyx_L1_error) + __pyx_array_type = &__pyx_type___pyx_array; + if (PyType_Ready(&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(1, 278, __pyx_L1_error) + __pyx_type___pyx_MemviewEnum.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_MemviewEnum.tp_dictoffset && __pyx_type___pyx_MemviewEnum.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type___pyx_MemviewEnum.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - return 0; -} - -static int __pyx_tp_clear_memoryview(PyObject *o) { - PyObject* tmp; - struct __pyx_memoryview_obj *p = (struct __pyx_memoryview_obj *)o; - tmp = ((PyObject*)p->obj); - p->obj = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->_size); - p->_size = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->_array_interface); - p->_array_interface = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - Py_CLEAR(p->view.obj); - return 0; -} -static PyObject *__pyx_sq_item_memoryview(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} - -static int __pyx_mp_ass_subscript_memoryview(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_memoryview___setitem__(o, i, v); + if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(1, 278, __pyx_L1_error) + __pyx_MemviewEnum_type = &__pyx_type___pyx_MemviewEnum; + __pyx_vtabptr_memoryview = &__pyx_vtable_memoryview; + __pyx_vtable_memoryview.get_item_pointer = (char *(*)(struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_get_item_pointer; + __pyx_vtable_memoryview.is_slice = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_is_slice; + __pyx_vtable_memoryview.setitem_slice_assignment = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *, PyObject *))__pyx_memoryview_setitem_slice_assignment; + __pyx_vtable_memoryview.setitem_slice_assign_scalar = (PyObject *(*)(struct __pyx_memoryview_obj *, struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_setitem_slice_assign_scalar; + __pyx_vtable_memoryview.setitem_indexed = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *, PyObject *))__pyx_memoryview_setitem_indexed; + __pyx_vtable_memoryview.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryview_convert_item_to_object; + __pyx_vtable_memoryview.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryview_assign_item_from_object; + if (PyType_Ready(&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(1, 329, __pyx_L1_error) + __pyx_type___pyx_memoryview.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryview.tp_dictoffset && __pyx_type___pyx_memoryview.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type___pyx_memoryview.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name); - return -1; + if (__Pyx_SetVtable(__pyx_type___pyx_memoryview.tp_dict, __pyx_vtabptr_memoryview) < 0) __PYX_ERR(1, 329, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(1, 329, __pyx_L1_error) + __pyx_memoryview_type = &__pyx_type___pyx_memoryview; + __pyx_vtabptr__memoryviewslice = &__pyx_vtable__memoryviewslice; + __pyx_vtable__memoryviewslice.__pyx_base = *__pyx_vtabptr_memoryview; + __pyx_vtable__memoryviewslice.__pyx_base.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryviewslice_convert_item_to_object; + __pyx_vtable__memoryviewslice.__pyx_base.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryviewslice_assign_item_from_object; + __pyx_type___pyx_memoryviewslice.tp_base = __pyx_memoryview_type; + if (PyType_Ready(&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(1, 960, __pyx_L1_error) + __pyx_type___pyx_memoryviewslice.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryviewslice.tp_dictoffset && __pyx_type___pyx_memoryviewslice.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type___pyx_memoryviewslice.tp_getattro = __Pyx_PyObject_GenericGetAttr; } + if (__Pyx_SetVtable(__pyx_type___pyx_memoryviewslice.tp_dict, __pyx_vtabptr__memoryviewslice) < 0) __PYX_ERR(1, 960, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(1, 960, __pyx_L1_error) + __pyx_memoryviewslice_type = &__pyx_type___pyx_memoryviewslice; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; } -static PyObject *__pyx_getprop___pyx_memoryview_T(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(o); +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(4, 2590, __pyx_L1_error) + __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(4, 2590, __pyx_L1_error) + __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", + #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 + sizeof(PyTypeObject), + #else + sizeof(PyHeapTypeObject), + #endif + 0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) __PYX_ERR(5, 9, __pyx_L1_error) + __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) __PYX_ERR(6, 8, __pyx_L1_error) + __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) __PYX_ERR(7, 15, __pyx_L1_error) + __pyx_ptype_7cpython_5array_array = __Pyx_ImportType("array", "array", sizeof(arrayobject), 0); if (unlikely(!__pyx_ptype_7cpython_5array_array)) __PYX_ERR(3, 58, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_FastaFile = __Pyx_ImportType("pysam.libcfaidx", "FastaFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastaFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastaFile)) __PYX_ERR(8, 37, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_FastaFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastaFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastaFile)) __PYX_ERR(8, 37, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_FastqProxy = __Pyx_ImportType("pysam.libcfaidx", "FastqProxy", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastqProxy)) __PYX_ERR(8, 45, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_FastqProxy = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy)) __PYX_ERR(8, 45, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_FastxRecord = __Pyx_ImportType("pysam.libcfaidx", "FastxRecord", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastxRecord)) __PYX_ERR(8, 52, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_FastxRecord = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxRecord->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxRecord)) __PYX_ERR(8, 52, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_FastxFile = __Pyx_ImportType("pysam.libcfaidx", "FastxFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(8, 61, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_FastxFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(8, 61, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_FastqFile = __Pyx_ImportType("pysam.libcfaidx", "FastqFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(8, 73, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_FastqFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(8, 73, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_Fastafile = __Pyx_ImportType("pysam.libcfaidx", "Fastafile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_Fastafile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(8, 78, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_Fastafile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_Fastafile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(8, 78, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader = __Pyx_ImportType("pysam.libcalignmentfile", "AlignmentHeader", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader)) __PYX_ERR(9, 41, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile = __Pyx_ImportType("pysam.libcalignmentfile", "AlignmentFile", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile)) __PYX_ERR(9, 44, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile)) __PYX_ERR(9, 44, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_PileupColumn = __Pyx_ImportType("pysam.libcalignmentfile", "PileupColumn", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_PileupColumn), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_PileupColumn)) __PYX_ERR(9, 61, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_PileupRead = __Pyx_ImportType("pysam.libcalignmentfile", "PileupRead", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_PileupRead), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_PileupRead)) __PYX_ERR(9, 68, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRow", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow)) __PYX_ERR(9, 79, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowRegion", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion)) __PYX_ERR(9, 89, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion)) __PYX_ERR(9, 89, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowHead", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead)) __PYX_ERR(9, 95, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead)) __PYX_ERR(9, 95, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowAll", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll)) __PYX_ERR(9, 102, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll)) __PYX_ERR(9, 102, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowAllRefs", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs)) __PYX_ERR(9, 107, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowSelection", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection)) __PYX_ERR(9, 112, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection)) __PYX_ERR(9, 112, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorColumn", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn)) __PYX_ERR(9, 119, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn)) __PYX_ERR(9, 119, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorColumnRegion", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion)) __PYX_ERR(9, 150, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion)) __PYX_ERR(9, 150, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorColumnAllRefs", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs)) __PYX_ERR(9, 156, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs)) __PYX_ERR(9, 156, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads = __Pyx_ImportType("pysam.libcalignmentfile", "IndexedReads", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads)) __PYX_ERR(9, 160, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; } -static PyObject *__pyx_getprop___pyx_memoryview_base(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(o); +static int __Pyx_modinit_variable_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); + /*--- Variable import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; } -static PyObject *__pyx_getprop___pyx_memoryview_shape(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(o); +static int __Pyx_modinit_function_import_code(void) { + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); + /*--- Function import code ---*/ + __pyx_t_1 = __Pyx_ImportModule("pysam.libcutils"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_1, "qualitystring_to_array", (void (**)(void))&__pyx_f_5pysam_9libcutils_qualitystring_to_array, "arrayobject *(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_1, "array_to_qualitystring", (void (**)(void))&__pyx_f_5pysam_9libcutils_array_to_qualitystring, "PyObject *(arrayobject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcutils_array_to_qualitystring *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_1, "qualities_to_qualitystring", (void (**)(void))&__pyx_f_5pysam_9libcutils_qualities_to_qualitystring, "PyObject *(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcutils_qualities_to_qualitystring *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_1, "charptr_to_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_charptr_to_str, "PyObject *(char const *, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_1, "charptr_to_bytes", (void (**)(void))&__pyx_f_5pysam_9libcutils_charptr_to_bytes, "PyObject *(char const *, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_bytes *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_1, "force_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_str, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_1, "force_bytes", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_bytes, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_bytes *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + Py_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_RefNannyFinishContext(); + return -1; } -static PyObject *__pyx_getprop___pyx_memoryview_strides(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(o); -} -static PyObject *__pyx_getprop___pyx_memoryview_suboffsets(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(o); -} +#if PY_MAJOR_VERSION < 3 +#ifdef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC void +#else +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#endif +#else +#ifdef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#endif +#endif +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4))) + #define CYTHON_SMALL_CODE __attribute__((optimize("Os"))) +#else + #define CYTHON_SMALL_CODE +#endif +#endif -static PyObject *__pyx_getprop___pyx_memoryview_ndim(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(o); -} -static PyObject *__pyx_getprop___pyx_memoryview_itemsize(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(o); +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC initlibcalignedsegment(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC initlibcalignedsegment(void) +#else +__Pyx_PyMODINIT_FUNC PyInit_libcalignedsegment(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_libcalignedsegment(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); } - -static PyObject *__pyx_getprop___pyx_memoryview_nbytes(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(o); +static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) { + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + result = PyDict_SetItemString(moddict, to_name, value); + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; } - -static PyObject *__pyx_getprop___pyx_memoryview_size(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(o); +static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + if (__pyx_m) + return __Pyx_NewRef(__pyx_m); + modname = PyObject_GetAttrString(spec, "name"); + if (unlikely(!modname)) goto bad; + module = PyModule_NewObject(modname); + Py_DECREF(modname); + if (unlikely(!module)) goto bad; + moddict = PyModule_GetDict(module); + if (unlikely(!moddict)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; } -static PyMethodDef __pyx_methods_memoryview[] = { - {"is_c_contig", (PyCFunction)__pyx_memoryview_is_c_contig, METH_NOARGS, 0}, - {"is_f_contig", (PyCFunction)__pyx_memoryview_is_f_contig, METH_NOARGS, 0}, - {"copy", (PyCFunction)__pyx_memoryview_copy, METH_NOARGS, 0}, - {"copy_fortran", (PyCFunction)__pyx_memoryview_copy_fortran, METH_NOARGS, 0}, - {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_1__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryview_3__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_memoryview[] = { - {(char *)"T", __pyx_getprop___pyx_memoryview_T, 0, (char *)0, 0}, - {(char *)"base", __pyx_getprop___pyx_memoryview_base, 0, (char *)0, 0}, - {(char *)"shape", __pyx_getprop___pyx_memoryview_shape, 0, (char *)0, 0}, - {(char *)"strides", __pyx_getprop___pyx_memoryview_strides, 0, (char *)0, 0}, - {(char *)"suboffsets", __pyx_getprop___pyx_memoryview_suboffsets, 0, (char *)0, 0}, - {(char *)"ndim", __pyx_getprop___pyx_memoryview_ndim, 0, (char *)0, 0}, - {(char *)"itemsize", __pyx_getprop___pyx_memoryview_itemsize, 0, (char *)0, 0}, - {(char *)"nbytes", __pyx_getprop___pyx_memoryview_nbytes, 0, (char *)0, 0}, - {(char *)"size", __pyx_getprop___pyx_memoryview_size, 0, (char *)0, 0}, - {0, 0, 0, 0, 0} -}; - -static PySequenceMethods __pyx_tp_as_sequence_memoryview = { - __pyx_memoryview___len__, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - __pyx_sq_item_memoryview, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_memoryview = { - __pyx_memoryview___len__, /*mp_length*/ - __pyx_memoryview___getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_memoryview, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_memoryview = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - __pyx_memoryview_getbuffer, /*bf_getbuffer*/ - 0, /*bf_releasebuffer*/ -}; -static PyTypeObject __pyx_type___pyx_memoryview = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcalignedsegment.memoryview", /*tp_name*/ - sizeof(struct __pyx_memoryview_obj), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_memoryview, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ - #endif - __pyx_memoryview___repr__, /*tp_repr*/ - 0, /*tp_as_number*/ - &__pyx_tp_as_sequence_memoryview, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_memoryview, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - __pyx_memoryview___str__, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_memoryview, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_memoryview, /*tp_traverse*/ - __pyx_tp_clear_memoryview, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_memoryview, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_memoryview, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_memoryview, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ +static int __pyx_pymod_exec_libcalignedsegment(PyObject *__pyx_pyinit_module) +#endif +#endif +{ + __Pyx_TraceDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + static PyThread_type_lock __pyx_t_6[8]; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0; + #elif PY_MAJOR_VERSION >= 3 + if (__pyx_m) return __Pyx_NewRef(__pyx_m); #endif -}; -static struct __pyx_vtabstruct__memoryviewslice __pyx_vtable__memoryviewslice; - -static PyObject *__pyx_tp_new__memoryviewslice(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_memoryviewslice_obj *p; - PyObject *o = __pyx_tp_new_memoryview(t, a, k); - if (unlikely(!o)) return 0; - p = ((struct __pyx_memoryviewslice_obj *)o); - p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_memoryview*)__pyx_vtabptr__memoryviewslice; - p->from_object = Py_None; Py_INCREF(Py_None); - p->from_slice.memview = NULL; - return o; + #if CYTHON_REFNANNY +__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); +if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); } - -static void __pyx_tp_dealloc__memoryviewslice(PyObject *o) { - struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; - #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { - if (PyObject_CallFinalizerFromDealloc(o)) return; - } +#endif + __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_libcalignedsegment(void)", 0); + if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif - PyObject_GC_UnTrack(o); - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_memoryviewslice___dealloc__(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - Py_CLEAR(p->from_object); - PyObject_GC_Track(o); - __pyx_tp_dealloc_memoryview(o); -} - -static int __pyx_tp_traverse__memoryviewslice(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; - e = __pyx_tp_traverse_memoryview(o, v, a); if (e) return e; - if (p->from_object) { - e = (*v)(p->from_object, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear__memoryviewslice(PyObject *o) { - PyObject* tmp; - struct __pyx_memoryviewslice_obj *p = (struct __pyx_memoryviewslice_obj *)o; - __pyx_tp_clear_memoryview(o); - tmp = ((PyObject*)p->from_object); - p->from_object = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - __PYX_XDEC_MEMVIEW(&p->from_slice, 1); - return 0; -} - -static PyObject *__pyx_getprop___pyx_memoryviewslice_base(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(o); -} - -static PyMethodDef __pyx_methods__memoryviewslice[] = { - {"__reduce_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_1__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw___pyx_memoryviewslice_3__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets__memoryviewslice[] = { - {(char *)"base", __pyx_getprop___pyx_memoryviewslice_base, 0, (char *)0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyTypeObject __pyx_type___pyx_memoryviewslice = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcalignedsegment._memoryviewslice", /*tp_name*/ - sizeof(struct __pyx_memoryviewslice_obj), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc__memoryviewslice, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif - #if CYTHON_COMPILING_IN_PYPY - __pyx_memoryview___repr__, /*tp_repr*/ - #else - 0, /*tp_repr*/ + #ifdef __Pyx_AsyncGen_USED + if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - #if CYTHON_COMPILING_IN_PYPY - __pyx_memoryview___str__, /*tp_str*/ - #else - 0, /*tp_str*/ + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "Internal class for passing memoryview slices to Python", /*tp_doc*/ - __pyx_tp_traverse__memoryviewslice, /*tp_traverse*/ - __pyx_tp_clear__memoryviewslice, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods__memoryviewslice, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets__memoryviewslice, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new__memoryviewslice, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + #ifdef WITH_THREAD /* Python build with threading support? */ + PyEval_InitThreads(); #endif -}; - -static PyMethodDef __pyx_methods[] = { - {0, 0, 0, 0} -}; - -#if PY_MAJOR_VERSION >= 3 -#if CYTHON_PEP489_MULTI_PHASE_INIT -static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ -static int __pyx_pymod_exec_libcalignedsegment(PyObject* module); /*proto*/ -static PyModuleDef_Slot __pyx_moduledef_slots[] = { - {Py_mod_create, (void*)__pyx_pymod_create}, - {Py_mod_exec, (void*)__pyx_pymod_exec_libcalignedsegment}, - {0, NULL} -}; -#endif - -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - "libcalignedsegment", - 0, /* m_doc */ - #if CYTHON_PEP489_MULTI_PHASE_INIT - 0, /* m_size */ - #else - -1, /* m_size */ #endif - __pyx_methods /* m_methods */, + /*--- Module creation code ---*/ #if CYTHON_PEP489_MULTI_PHASE_INIT - __pyx_moduledef_slots, /* m_slots */ + __pyx_m = __pyx_pyinit_module; + Py_INCREF(__pyx_m); #else - NULL, /* m_reload */ + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("libcalignedsegment", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); #endif - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ -}; -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_s_2sc_is, __pyx_k_2sc_is, sizeof(__pyx_k_2sc_is), 0, 0, 1, 0}, - {&__pyx_kp_s_2sc_s, __pyx_k_2sc_s, sizeof(__pyx_k_2sc_s), 0, 0, 1, 0}, - {&__pyx_kp_s_2sccI_i_s, __pyx_k_2sccI_i_s, sizeof(__pyx_k_2sccI_i_s), 0, 0, 1, 0}, - {&__pyx_kp_s_2sccI_is, __pyx_k_2sccI_is, sizeof(__pyx_k_2sccI_is), 0, 0, 1, 0}, - {&__pyx_n_b_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 0, 1}, - {&__pyx_n_s_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 1, 1}, - {&__pyx_n_s_ASCII, __pyx_k_ASCII, sizeof(__pyx_k_ASCII), 0, 0, 1, 1}, - {&__pyx_n_b_AZ, __pyx_k_AZ, sizeof(__pyx_k_AZ), 0, 0, 0, 1}, - {&__pyx_n_s_AlignedSegment, __pyx_k_AlignedSegment, sizeof(__pyx_k_AlignedSegment), 0, 0, 1, 1}, - {&__pyx_n_b_B, __pyx_k_B, sizeof(__pyx_k_B), 0, 0, 0, 1}, - {&__pyx_n_s_B, __pyx_k_B, sizeof(__pyx_k_B), 0, 0, 1, 1}, - {&__pyx_kp_s_Buffer_view_does_not_expose_stri, __pyx_k_Buffer_view_does_not_expose_stri, sizeof(__pyx_k_Buffer_view_does_not_expose_stri), 0, 0, 1, 0}, - {&__pyx_n_b_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 0, 1}, - {&__pyx_n_s_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 1, 1}, - {&__pyx_n_s_CIGAR2CODE, __pyx_k_CIGAR2CODE, sizeof(__pyx_k_CIGAR2CODE), 0, 0, 1, 1}, - {&__pyx_n_s_CIGAR_REGEX, __pyx_k_CIGAR_REGEX, sizeof(__pyx_k_CIGAR_REGEX), 0, 0, 1, 1}, - {&__pyx_kp_s_Can_only_create_a_buffer_that_is, __pyx_k_Can_only_create_a_buffer_that_is, sizeof(__pyx_k_Can_only_create_a_buffer_that_is), 0, 0, 1, 0}, - {&__pyx_kp_s_Cannot_assign_to_read_only_memor, __pyx_k_Cannot_assign_to_read_only_memor, sizeof(__pyx_k_Cannot_assign_to_read_only_memor), 0, 0, 1, 0}, - {&__pyx_kp_s_Cannot_create_writable_memory_vi, __pyx_k_Cannot_create_writable_memory_vi, sizeof(__pyx_k_Cannot_create_writable_memory_vi), 0, 0, 1, 0}, - {&__pyx_kp_s_Cannot_index_with_type_s, __pyx_k_Cannot_index_with_type_s, sizeof(__pyx_k_Cannot_index_with_type_s), 0, 0, 1, 0}, - {&__pyx_n_s_D, __pyx_k_D, sizeof(__pyx_k_D), 0, 0, 1, 1}, - {&__pyx_n_s_Ellipsis, __pyx_k_Ellipsis, sizeof(__pyx_k_Ellipsis), 0, 0, 1, 1}, - {&__pyx_kp_s_Empty_shape_tuple_for_cython_arr, __pyx_k_Empty_shape_tuple_for_cython_arr, sizeof(__pyx_k_Empty_shape_tuple_for_cython_arr), 0, 0, 1, 0}, - {&__pyx_n_s_F, __pyx_k_F, sizeof(__pyx_k_F), 0, 0, 1, 1}, - {&__pyx_n_s_H, __pyx_k_H, sizeof(__pyx_k_H), 0, 0, 1, 1}, - {&__pyx_n_b_I, __pyx_k_I, sizeof(__pyx_k_I), 0, 0, 0, 1}, - {&__pyx_n_s_I, __pyx_k_I, sizeof(__pyx_k_I), 0, 0, 1, 1}, - {&__pyx_kp_s_Incompatible_checksums_s_vs_0xb0, __pyx_k_Incompatible_checksums_s_vs_0xb0, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xb0), 0, 0, 1, 0}, - {&__pyx_kp_s_Incompatible_checksums_s_vs_0xbb, __pyx_k_Incompatible_checksums_s_vs_0xbb, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xbb), 0, 0, 1, 0}, - {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1}, - {&__pyx_kp_s_Indirect_dimensions_not_supporte, __pyx_k_Indirect_dimensions_not_supporte, sizeof(__pyx_k_Indirect_dimensions_not_supporte), 0, 0, 1, 0}, - {&__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_k_Invalid_mode_expected_c_or_fortr, sizeof(__pyx_k_Invalid_mode_expected_c_or_fortr), 0, 0, 1, 0}, - {&__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_k_Invalid_shape_in_axis_d_d, sizeof(__pyx_k_Invalid_shape_in_axis_d_d), 0, 0, 1, 0}, - {&__pyx_kp_s_Invalid_tag_s, __pyx_k_Invalid_tag_s, sizeof(__pyx_k_Invalid_tag_s), 0, 0, 1, 0}, - {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1}, - {&__pyx_kp_s_MD_tag_not_present, __pyx_k_MD_tag_not_present, sizeof(__pyx_k_MD_tag_not_present), 0, 0, 1, 0}, - {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, - {&__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_k_MemoryView_of_r_at_0x_x, sizeof(__pyx_k_MemoryView_of_r_at_0x_x), 0, 0, 1, 0}, - {&__pyx_kp_s_MemoryView_of_r_object, __pyx_k_MemoryView_of_r_object, sizeof(__pyx_k_MemoryView_of_r_object), 0, 0, 1, 0}, - {&__pyx_n_s_NotImplemented, __pyx_k_NotImplemented, sizeof(__pyx_k_NotImplemented), 0, 0, 1, 1}, - {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1}, - {&__pyx_n_b_O, __pyx_k_O, sizeof(__pyx_k_O), 0, 0, 0, 1}, - {&__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_k_Out_of_bounds_on_buffer_access_a, sizeof(__pyx_k_Out_of_bounds_on_buffer_access_a), 0, 0, 1, 0}, - {&__pyx_kp_s_Padding_BAM_CPAD_6_is_currently, __pyx_k_Padding_BAM_CPAD_6_is_currently, sizeof(__pyx_k_Padding_BAM_CPAD_6_is_currently), 0, 0, 1, 0}, - {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, - {&__pyx_n_s_PileupColumn, __pyx_k_PileupColumn, sizeof(__pyx_k_PileupColumn), 0, 0, 1, 1}, - {&__pyx_kp_s_PileupColumn_accessed_after_iter, __pyx_k_PileupColumn_accessed_after_iter, sizeof(__pyx_k_PileupColumn_accessed_after_iter), 0, 0, 1, 0}, - {&__pyx_n_s_PileupRead, __pyx_k_PileupRead, sizeof(__pyx_k_PileupRead), 0, 0, 1, 1}, - {&__pyx_n_b_S, __pyx_k_S, sizeof(__pyx_k_S), 0, 0, 0, 1}, - {&__pyx_n_s_S, __pyx_k_S, sizeof(__pyx_k_S), 0, 0, 1, 1}, - {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, - {&__pyx_kp_s_Unable_to_convert_item_to_object, __pyx_k_Unable_to_convert_item_to_object, sizeof(__pyx_k_Unable_to_convert_item_to_object), 0, 0, 1, 0}, - {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, - {&__pyx_n_s_View_MemoryView, __pyx_k_View_MemoryView, sizeof(__pyx_k_View_MemoryView), 0, 0, 1, 1}, - {&__pyx_n_b_Z, __pyx_k_Z, sizeof(__pyx_k_Z), 0, 0, 0, 1}, - {&__pyx_n_s_Z, __pyx_k_Z, sizeof(__pyx_k_Z), 0, 0, 1, 1}, - {&__pyx_n_s_Zidf, __pyx_k_Zidf, sizeof(__pyx_k_Zidf), 0, 0, 1, 1}, - {&__pyx_kp_s__16, __pyx_k__16, sizeof(__pyx_k__16), 0, 0, 1, 0}, - {&__pyx_kp_s__19, __pyx_k__19, sizeof(__pyx_k__19), 0, 0, 1, 0}, - {&__pyx_kp_s__33, __pyx_k__33, sizeof(__pyx_k__33), 0, 0, 1, 0}, - {&__pyx_kp_s__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 0, 1, 0}, - {&__pyx_n_s_alignment, __pyx_k_alignment, sizeof(__pyx_k_alignment), 0, 0, 1, 1}, - {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1}, - {&__pyx_n_s_allocate_buffer, __pyx_k_allocate_buffer, sizeof(__pyx_k_allocate_buffer), 0, 0, 1, 1}, - {&__pyx_n_s_always, __pyx_k_always, sizeof(__pyx_k_always), 0, 0, 1, 1}, - {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1}, - {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1}, - {&__pyx_n_s_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1}, - {&__pyx_kp_s_at_least_one_integer_out_of_rang, __pyx_k_at_least_one_integer_out_of_rang, sizeof(__pyx_k_at_least_one_integer_out_of_rang), 0, 0, 1, 0}, - {&__pyx_kp_s_at_least_one_signed_integer_out, __pyx_k_at_least_one_signed_integer_out, sizeof(__pyx_k_at_least_one_signed_integer_out), 0, 0, 1, 0}, - {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1}, - {&__pyx_n_s_base, __pyx_k_base, sizeof(__pyx_k_base), 0, 0, 1, 1}, - {&__pyx_n_b_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 0, 1}, - {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1}, - {&__pyx_n_u_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 1, 0, 1}, - {&__pyx_kp_s_c_2, __pyx_k_c_2, sizeof(__pyx_k_c_2), 0, 0, 1, 0}, - {&__pyx_n_s_calcsize, __pyx_k_calcsize, sizeof(__pyx_k_calcsize), 0, 0, 1, 1}, - {&__pyx_kp_s_can_t_guess_type_or_invalid_type, __pyx_k_can_t_guess_type_or_invalid_type, sizeof(__pyx_k_can_t_guess_type_or_invalid_type), 0, 0, 1, 0}, - {&__pyx_n_s_chr, __pyx_k_chr, sizeof(__pyx_k_chr), 0, 0, 1, 1}, - {&__pyx_n_s_cigarstring, __pyx_k_cigarstring, sizeof(__pyx_k_cigarstring), 0, 0, 1, 1}, - {&__pyx_n_s_cigartuples, __pyx_k_cigartuples, sizeof(__pyx_k_cigartuples), 0, 0, 1, 1}, - {&__pyx_n_s_class, __pyx_k_class, sizeof(__pyx_k_class), 0, 0, 1, 1}, - {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, - {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1}, - {&__pyx_n_s_compare, __pyx_k_compare, sizeof(__pyx_k_compare), 0, 0, 1, 1}, - {&__pyx_n_s_compile, __pyx_k_compile, sizeof(__pyx_k_compile), 0, 0, 1, 1}, - {&__pyx_kp_s_contiguous_and_direct, __pyx_k_contiguous_and_direct, sizeof(__pyx_k_contiguous_and_direct), 0, 0, 1, 0}, - {&__pyx_kp_s_contiguous_and_indirect, __pyx_k_contiguous_and_indirect, sizeof(__pyx_k_contiguous_and_indirect), 0, 0, 1, 0}, - {&__pyx_kp_s_could_not_allocated_sequence_of, __pyx_k_could_not_allocated_sequence_of, sizeof(__pyx_k_could_not_allocated_sequence_of), 0, 0, 1, 0}, - {&__pyx_kp_s_could_not_determine_alignment_le, __pyx_k_could_not_determine_alignment_le, sizeof(__pyx_k_could_not_determine_alignment_le), 0, 0, 1, 0}, - {&__pyx_n_s_create_string_buffer, __pyx_k_create_string_buffer, sizeof(__pyx_k_create_string_buffer), 0, 0, 1, 1}, - {&__pyx_n_s_ctypes, __pyx_k_ctypes, sizeof(__pyx_k_ctypes), 0, 0, 1, 1}, - {&__pyx_n_s_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 1, 1}, - {&__pyx_kp_s_d_MIDNSHP_XB, __pyx_k_d_MIDNSHP_XB, sizeof(__pyx_k_d_MIDNSHP_XB), 0, 0, 1, 0}, - {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, - {&__pyx_n_s_dtype_is_object, __pyx_k_dtype_is_object, sizeof(__pyx_k_dtype_is_object), 0, 0, 1, 1}, - {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, - {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1}, - {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1}, - {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, - {&__pyx_n_b_f, __pyx_k_f, sizeof(__pyx_k_f), 0, 0, 0, 1}, - {&__pyx_n_s_f, __pyx_k_f, sizeof(__pyx_k_f), 0, 0, 1, 1}, - {&__pyx_n_s_findall, __pyx_k_findall, sizeof(__pyx_k_findall), 0, 0, 1, 1}, - {&__pyx_n_s_flag, __pyx_k_flag, sizeof(__pyx_k_flag), 0, 0, 1, 1}, - {&__pyx_n_s_flags, __pyx_k_flags, sizeof(__pyx_k_flags), 0, 0, 1, 1}, - {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1}, - {&__pyx_n_s_fortran, __pyx_k_fortran, sizeof(__pyx_k_fortran), 0, 0, 1, 1}, - {&__pyx_n_u_fortran, __pyx_k_fortran, sizeof(__pyx_k_fortran), 0, 1, 0, 1}, - {&__pyx_n_s_full_length, __pyx_k_full_length, sizeof(__pyx_k_full_length), 0, 0, 1, 1}, - {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1}, - {&__pyx_n_s_get_aligned_pairs, __pyx_k_get_aligned_pairs, sizeof(__pyx_k_get_aligned_pairs), 0, 0, 1, 1}, - {&__pyx_n_s_get_blocks, __pyx_k_get_blocks, sizeof(__pyx_k_get_blocks), 0, 0, 1, 1}, - {&__pyx_n_s_get_overlap, __pyx_k_get_overlap, sizeof(__pyx_k_get_overlap), 0, 0, 1, 1}, - {&__pyx_n_s_get_reference_positions, __pyx_k_get_reference_positions, sizeof(__pyx_k_get_reference_positions), 0, 0, 1, 1}, - {&__pyx_n_s_get_reference_sequence, __pyx_k_get_reference_sequence, sizeof(__pyx_k_get_reference_sequence), 0, 0, 1, 1}, - {&__pyx_n_s_get_tag, __pyx_k_get_tag, sizeof(__pyx_k_get_tag), 0, 0, 1, 1}, - {&__pyx_n_s_get_tags, __pyx_k_get_tags, sizeof(__pyx_k_get_tags), 0, 0, 1, 1}, - {&__pyx_n_s_getrname, __pyx_k_getrname, sizeof(__pyx_k_getrname), 0, 0, 1, 1}, - {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, - {&__pyx_kp_s_got_differing_extents_in_dimensi, __pyx_k_got_differing_extents_in_dimensi, sizeof(__pyx_k_got_differing_extents_in_dimensi), 0, 0, 1, 0}, - {&__pyx_n_s_h, __pyx_k_h, sizeof(__pyx_k_h), 0, 0, 1, 1}, - {&__pyx_n_s_has_tag, __pyx_k_has_tag, sizeof(__pyx_k_has_tag), 0, 0, 1, 1}, - {&__pyx_kp_s_htsfile_does_not_match_aligned_s, __pyx_k_htsfile_does_not_match_aligned_s, sizeof(__pyx_k_htsfile_does_not_match_aligned_s), 0, 0, 1, 0}, - {&__pyx_n_b_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 0, 1}, - {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, - {&__pyx_kp_s_i_c, __pyx_k_i_c, sizeof(__pyx_k_i_c), 0, 0, 1, 0}, - {&__pyx_n_s_id, __pyx_k_id, sizeof(__pyx_k_id), 0, 0, 1, 1}, - {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, - {&__pyx_n_s_indel, __pyx_k_indel, sizeof(__pyx_k_indel), 0, 0, 1, 1}, - {&__pyx_n_s_infer_query_length, __pyx_k_infer_query_length, sizeof(__pyx_k_infer_query_length), 0, 0, 1, 1}, - {&__pyx_kp_s_invalid_value_type_s, __pyx_k_invalid_value_type_s, sizeof(__pyx_k_invalid_value_type_s), 0, 0, 1, 0}, - {&__pyx_kp_s_invalid_value_type_s_s, __pyx_k_invalid_value_type_s_s, sizeof(__pyx_k_invalid_value_type_s_s), 0, 0, 1, 0}, - {&__pyx_n_s_is_del, __pyx_k_is_del, sizeof(__pyx_k_is_del), 0, 0, 1, 1}, - {&__pyx_n_s_is_head, __pyx_k_is_head, sizeof(__pyx_k_is_head), 0, 0, 1, 1}, - {&__pyx_n_s_is_refskip, __pyx_k_is_refskip, sizeof(__pyx_k_is_refskip), 0, 0, 1, 1}, - {&__pyx_n_s_is_tail, __pyx_k_is_tail, sizeof(__pyx_k_is_tail), 0, 0, 1, 1}, - {&__pyx_n_s_itemsize, __pyx_k_itemsize, sizeof(__pyx_k_itemsize), 0, 0, 1, 1}, - {&__pyx_kp_s_itemsize_0_for_cython_array, __pyx_k_itemsize_0_for_cython_array, sizeof(__pyx_k_itemsize_0_for_cython_array), 0, 0, 1, 0}, - {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1}, - {&__pyx_n_s_level, __pyx_k_level, sizeof(__pyx_k_level), 0, 0, 1, 1}, - {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, - {&__pyx_kp_s_malformatted_tag_s, __pyx_k_malformatted_tag_s, sizeof(__pyx_k_malformatted_tag_s), 0, 0, 1, 0}, - {&__pyx_n_s_map, __pyx_k_map, sizeof(__pyx_k_map), 0, 0, 1, 1}, - {&__pyx_n_s_mapping_quality, __pyx_k_mapping_quality, sizeof(__pyx_k_mapping_quality), 0, 0, 1, 1}, - {&__pyx_n_s_matches_only, __pyx_k_matches_only, sizeof(__pyx_k_matches_only), 0, 0, 1, 1}, - {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1}, - {&__pyx_n_s_memview, __pyx_k_memview, sizeof(__pyx_k_memview), 0, 0, 1, 1}, - {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1}, - {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1}, - {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, - {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1}, - {&__pyx_n_s_ndim, __pyx_k_ndim, sizeof(__pyx_k_ndim), 0, 0, 1, 1}, - {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1}, - {&__pyx_n_s_next_reference_id, __pyx_k_next_reference_id, sizeof(__pyx_k_next_reference_id), 0, 0, 1, 1}, - {&__pyx_n_s_next_reference_start, __pyx_k_next_reference_start, sizeof(__pyx_k_next_reference_start), 0, 0, 1, 1}, - {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0}, - {&__pyx_n_s_nsegments, __pyx_k_nsegments, sizeof(__pyx_k_nsegments), 0, 0, 1, 1}, - {&__pyx_n_s_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 0, 0, 1, 1}, - {&__pyx_n_s_pack, __pyx_k_pack, sizeof(__pyx_k_pack), 0, 0, 1, 1}, - {&__pyx_n_s_pack_into, __pyx_k_pack_into, sizeof(__pyx_k_pack_into), 0, 0, 1, 1}, - {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, - {&__pyx_n_s_pileups, __pyx_k_pileups, sizeof(__pyx_k_pileups), 0, 0, 1, 1}, - {&__pyx_n_s_pysam_libcalignedsegment, __pyx_k_pysam_libcalignedsegment, sizeof(__pyx_k_pysam_libcalignedsegment), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_getbuffer, __pyx_k_pyx_getbuffer, sizeof(__pyx_k_pyx_getbuffer), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_unpickle_Enum, __pyx_k_pyx_unpickle_Enum, sizeof(__pyx_k_pyx_unpickle_Enum), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_unpickle_PileupRead, __pyx_k_pyx_unpickle_PileupRead, sizeof(__pyx_k_pyx_unpickle_PileupRead), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1}, - {&__pyx_kp_s_quality_and_sequence_mismatch_i, __pyx_k_quality_and_sequence_mismatch_i, sizeof(__pyx_k_quality_and_sequence_mismatch_i), 0, 0, 1, 0}, - {&__pyx_n_s_query_alignment_end, __pyx_k_query_alignment_end, sizeof(__pyx_k_query_alignment_end), 0, 0, 1, 1}, - {&__pyx_n_s_query_alignment_length, __pyx_k_query_alignment_length, sizeof(__pyx_k_query_alignment_length), 0, 0, 1, 1}, - {&__pyx_n_s_query_alignment_qualities, __pyx_k_query_alignment_qualities, sizeof(__pyx_k_query_alignment_qualities), 0, 0, 1, 1}, - {&__pyx_n_s_query_alignment_sequence, __pyx_k_query_alignment_sequence, sizeof(__pyx_k_query_alignment_sequence), 0, 0, 1, 1}, - {&__pyx_n_s_query_alignment_start, __pyx_k_query_alignment_start, sizeof(__pyx_k_query_alignment_start), 0, 0, 1, 1}, - {&__pyx_n_s_query_length, __pyx_k_query_length, sizeof(__pyx_k_query_length), 0, 0, 1, 1}, - {&__pyx_kp_s_query_length_out_of_range_254, __pyx_k_query_length_out_of_range_254, sizeof(__pyx_k_query_length_out_of_range_254), 0, 0, 1, 0}, - {&__pyx_n_s_query_name, __pyx_k_query_name, sizeof(__pyx_k_query_name), 0, 0, 1, 1}, - {&__pyx_n_s_query_position, __pyx_k_query_position, sizeof(__pyx_k_query_position), 0, 0, 1, 1}, - {&__pyx_n_s_query_qualities, __pyx_k_query_qualities, sizeof(__pyx_k_query_qualities), 0, 0, 1, 1}, - {&__pyx_n_s_query_sequence, __pyx_k_query_sequence, sizeof(__pyx_k_query_sequence), 0, 0, 1, 1}, - {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, - {&__pyx_n_s_raw, __pyx_k_raw, sizeof(__pyx_k_raw), 0, 0, 1, 1}, - {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1}, - {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, - {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, - {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, - {&__pyx_n_s_reference_end, __pyx_k_reference_end, sizeof(__pyx_k_reference_end), 0, 0, 1, 1}, - {&__pyx_n_s_reference_id, __pyx_k_reference_id, sizeof(__pyx_k_reference_id), 0, 0, 1, 1}, - {&__pyx_n_s_reference_length, __pyx_k_reference_length, sizeof(__pyx_k_reference_length), 0, 0, 1, 1}, - {&__pyx_n_s_reference_pos, __pyx_k_reference_pos, sizeof(__pyx_k_reference_pos), 0, 0, 1, 1}, - {&__pyx_n_s_reference_start, __pyx_k_reference_start, sizeof(__pyx_k_reference_start), 0, 0, 1, 1}, - {&__pyx_n_s_replace, __pyx_k_replace, sizeof(__pyx_k_replace), 0, 0, 1, 1}, - {&__pyx_n_b_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 0, 1}, - {&__pyx_n_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 1}, - {&__pyx_kp_s_sam_format_failed, __pyx_k_sam_format_failed, sizeof(__pyx_k_sam_format_failed), 0, 0, 1, 0}, - {&__pyx_kp_s_self__delegate_cannot_be_convert, __pyx_k_self__delegate_cannot_be_convert, sizeof(__pyx_k_self__delegate_cannot_be_convert), 0, 0, 1, 0}, - {&__pyx_kp_s_self_plp_cannot_be_converted_to, __pyx_k_self_plp_cannot_be_converted_to, sizeof(__pyx_k_self_plp_cannot_be_converted_to), 0, 0, 1, 0}, - {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1}, - {&__pyx_n_s_set_tag, __pyx_k_set_tag, sizeof(__pyx_k_set_tag), 0, 0, 1, 1}, - {&__pyx_n_s_set_tags, __pyx_k_set_tags, sizeof(__pyx_k_set_tags), 0, 0, 1, 1}, - {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, - {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, - {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1}, - {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1}, - {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1}, - {&__pyx_n_s_step, __pyx_k_step, sizeof(__pyx_k_step), 0, 0, 1, 1}, - {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1}, - {&__pyx_kp_s_strided_and_direct, __pyx_k_strided_and_direct, sizeof(__pyx_k_strided_and_direct), 0, 0, 1, 0}, - {&__pyx_kp_s_strided_and_direct_or_indirect, __pyx_k_strided_and_direct_or_indirect, sizeof(__pyx_k_strided_and_direct_or_indirect), 0, 0, 1, 0}, - {&__pyx_kp_s_strided_and_indirect, __pyx_k_strided_and_indirect, sizeof(__pyx_k_strided_and_indirect), 0, 0, 1, 0}, - {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, - {&__pyx_n_s_struct, __pyx_k_struct, sizeof(__pyx_k_struct), 0, 0, 1, 1}, - {&__pyx_n_s_tag, __pyx_k_tag, sizeof(__pyx_k_tag), 0, 0, 1, 1}, - {&__pyx_kp_s_tag_s_not_present, __pyx_k_tag_s_not_present, sizeof(__pyx_k_tag_s_not_present), 0, 0, 1, 0}, - {&__pyx_n_s_tags, __pyx_k_tags, sizeof(__pyx_k_tags), 0, 0, 1, 1}, - {&__pyx_n_s_template_length, __pyx_k_template_length, sizeof(__pyx_k_template_length), 0, 0, 1, 1}, - {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, - {&__pyx_kp_s_this_class_cannot_be_instantiate, __pyx_k_this_class_cannot_be_instantiate, sizeof(__pyx_k_this_class_cannot_be_instantiate), 0, 0, 1, 0}, - {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1}, - {&__pyx_n_s_tostring, __pyx_k_tostring, sizeof(__pyx_k_tostring), 0, 0, 1, 1}, - {&__pyx_n_s_typecode, __pyx_k_typecode, sizeof(__pyx_k_typecode), 0, 0, 1, 1}, - {&__pyx_kp_s_unable_to_allocate_array_data, __pyx_k_unable_to_allocate_array_data, sizeof(__pyx_k_unable_to_allocate_array_data), 0, 0, 1, 0}, - {&__pyx_kp_s_unable_to_allocate_shape_and_str, __pyx_k_unable_to_allocate_shape_and_str, sizeof(__pyx_k_unable_to_allocate_shape_and_str), 0, 0, 1, 0}, - {&__pyx_kp_s_unknown_auxiliary_type_s, __pyx_k_unknown_auxiliary_type_s, sizeof(__pyx_k_unknown_auxiliary_type_s), 0, 0, 1, 0}, - {&__pyx_kp_s_unknown_type_s, __pyx_k_unknown_type_s, sizeof(__pyx_k_unknown_type_s), 0, 0, 1, 0}, - {&__pyx_n_s_unpack, __pyx_k_unpack, sizeof(__pyx_k_unpack), 0, 0, 1, 1}, - {&__pyx_kp_s_unsupported_type_code, __pyx_k_unsupported_type_code, sizeof(__pyx_k_unsupported_type_code), 0, 0, 1, 0}, - {&__pyx_kp_s_unsupported_value_type_in_set_op, __pyx_k_unsupported_value_type_in_set_op, sizeof(__pyx_k_unsupported_value_type_in_set_op), 0, 0, 1, 0}, - {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, - {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1}, - {&__pyx_n_s_value_type, __pyx_k_value_type, sizeof(__pyx_k_value_type), 0, 0, 1, 1}, - {&__pyx_n_s_with_seq, __pyx_k_with_seq, sizeof(__pyx_k_with_seq), 0, 0, 1, 1}, - {&__pyx_n_s_with_value_type, __pyx_k_with_value_type, sizeof(__pyx_k_with_value_type), 0, 0, 1, 1}, - {0, 0, 0, 0, 0, 0, 0} -}; -static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 84, __pyx_L1_error) - __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) __PYX_ERR(0, 133, __pyx_L1_error) - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 201, __pyx_L1_error) - __pyx_builtin_min = __Pyx_GetBuiltinName(__pyx_n_s_min); if (!__pyx_builtin_min) __PYX_ERR(0, 272, __pyx_L1_error) - __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) __PYX_ERR(0, 272, __pyx_L1_error) - __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 587, __pyx_L1_error) - __pyx_builtin_map = __Pyx_GetBuiltinName(__pyx_n_s_map); if (!__pyx_builtin_map) __PYX_ERR(0, 706, __pyx_L1_error) - __pyx_builtin_NotImplemented = __Pyx_GetBuiltinName(__pyx_n_s_NotImplemented); if (!__pyx_builtin_NotImplemented) __PYX_ERR(0, 767, __pyx_L1_error) - __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 1980, __pyx_L1_error) - __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) - __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(2, 109, __pyx_L1_error) - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(1, 179, __pyx_L1_error) - __pyx_builtin_Ellipsis = __Pyx_GetBuiltinName(__pyx_n_s_Ellipsis); if (!__pyx_builtin_Ellipsis) __PYX_ERR(1, 399, __pyx_L1_error) - __pyx_builtin_id = __Pyx_GetBuiltinName(__pyx_n_s_id); if (!__pyx_builtin_id) __PYX_ERR(1, 608, __pyx_L1_error) - __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(1, 827, __pyx_L1_error) - return 0; - __pyx_L1_error:; - return -1; -} - -static int __Pyx_InitCachedConstants(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + #if CYTHON_COMPILING_IN_PYPY + Py_INCREF(__pyx_b); + #endif + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main_pysam__libcalignedsegment) { + if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "pysam.libcalignedsegment")) { + if (unlikely(PyDict_SetItemString(modules, "pysam.libcalignedsegment", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) + } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global type/function init code ---*/ + (void)__Pyx_modinit_global_init_code(); + (void)__Pyx_modinit_variable_export_code(); + if (unlikely(__Pyx_modinit_function_export_code() != 0)) goto __pyx_L1_error; + if (unlikely(__Pyx_modinit_type_init_code() != 0)) goto __pyx_L1_error; + if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error; + (void)__Pyx_modinit_variable_import_code(); + if (unlikely(__Pyx_modinit_function_import_code() != 0)) goto __pyx_L1_error; + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + __Pyx_TraceCall("__Pyx_PyMODINIT_FUNC PyInit_libcalignedsegment(void)", __pyx_f[0], 1, 0, __PYX_ERR(0, 1, __pyx_L1_error)); - /* "pysam/libcalignedsegment.pyx":201 - * valuetype = b's' - * elif value < -2147483648 or maximum_value >= 2147483648: - * raise ValueError( # <<<<<<<<<<<<<< - * "at least one signed integer out of range of " - * "BAM/SAM specification") + /* "pysam/libcalignedsegment.pyx":56 + * # + * ############################################################################### + * import re # <<<<<<<<<<<<<< + * import array + * import json */ - __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_at_least_one_signed_integer_out); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 201, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple_); - __Pyx_GIVEREF(__pyx_tuple_); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_re, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_1) < 0) __PYX_ERR(0, 56, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":213 - * valuetype = b'S' - * elif maximum_value >= 4294967296: - * raise ValueError( # <<<<<<<<<<<<<< - * "at least one integer out of range of BAM/SAM specification") - * else: + /* "pysam/libcalignedsegment.pyx":57 + * ############################################################################### + * import re + * import array # <<<<<<<<<<<<<< + * import json + * import string */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_at_least_one_integer_out_of_rang); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 213, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__2); - __Pyx_GIVEREF(__pyx_tuple__2); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_array, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_array, __pyx_t_1) < 0) __PYX_ERR(0, 57, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":220 - * # Note: hex strings (H) are not supported yet - * if t is not bytes: - * value = value.encode('ascii') # <<<<<<<<<<<<<< - * if len(value) == 1: - * valuetype = b'A' + /* "pysam/libcalignedsegment.pyx":58 + * import re + * import array + * import json # <<<<<<<<<<<<<< + * import string + * import ctypes */ - __pyx_tuple__3 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 220, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__3); - __Pyx_GIVEREF(__pyx_tuple__3); - - /* "pysam/libcalignedsegment.pyx":243 - * - * datatype2format = { - * b'c': ('b', 1), # <<<<<<<<<<<<<< - * b'C': ('B', 1), - * b's': ('h', 2), - */ - __pyx_tuple__5 = PyTuple_Pack(2, __pyx_n_s_b, __pyx_int_1); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 243, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__5); - __Pyx_GIVEREF(__pyx_tuple__5); - - /* "pysam/libcalignedsegment.pyx":244 - * datatype2format = { - * b'c': ('b', 1), - * b'C': ('B', 1), # <<<<<<<<<<<<<< - * b's': ('h', 2), - * b'S': ('H', 2), - */ - __pyx_tuple__6 = PyTuple_Pack(2, __pyx_n_s_B, __pyx_int_1); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 244, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__6); - __Pyx_GIVEREF(__pyx_tuple__6); - - /* "pysam/libcalignedsegment.pyx":245 - * b'c': ('b', 1), - * b'C': ('B', 1), - * b's': ('h', 2), # <<<<<<<<<<<<<< - * b'S': ('H', 2), - * b'i': ('i', 4), - */ - __pyx_tuple__7 = PyTuple_Pack(2, __pyx_n_s_h, __pyx_int_2); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__7); - __Pyx_GIVEREF(__pyx_tuple__7); - - /* "pysam/libcalignedsegment.pyx":246 - * b'C': ('B', 1), - * b's': ('h', 2), - * b'S': ('H', 2), # <<<<<<<<<<<<<< - * b'i': ('i', 4), - * b'I': ('I', 4), - */ - __pyx_tuple__8 = PyTuple_Pack(2, __pyx_n_s_H, __pyx_int_2); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__8); - __Pyx_GIVEREF(__pyx_tuple__8); - - /* "pysam/libcalignedsegment.pyx":247 - * b's': ('h', 2), - * b'S': ('H', 2), - * b'i': ('i', 4), # <<<<<<<<<<<<<< - * b'I': ('I', 4), - * b'f': ('f', 4), - */ - __pyx_tuple__9 = PyTuple_Pack(2, __pyx_n_s_i, __pyx_int_4); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__9); - __Pyx_GIVEREF(__pyx_tuple__9); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_json, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_json, __pyx_t_1) < 0) __PYX_ERR(0, 58, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":248 - * b'S': ('H', 2), - * b'i': ('i', 4), - * b'I': ('I', 4), # <<<<<<<<<<<<<< - * b'f': ('f', 4), - * b'A': ('c', 1)} + /* "pysam/libcalignedsegment.pyx":59 + * import array + * import json + * import string # <<<<<<<<<<<<<< + * import ctypes + * import struct */ - __pyx_tuple__10 = PyTuple_Pack(2, __pyx_n_s_I, __pyx_int_4); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 248, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__10); - __Pyx_GIVEREF(__pyx_tuple__10); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_string, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_string, __pyx_t_1) < 0) __PYX_ERR(0, 59, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":249 - * b'i': ('i', 4), - * b'I': ('I', 4), - * b'f': ('f', 4), # <<<<<<<<<<<<<< - * b'A': ('c', 1)} + /* "pysam/libcalignedsegment.pyx":60 + * import json + * import string + * import ctypes # <<<<<<<<<<<<<< + * import struct * */ - __pyx_tuple__11 = PyTuple_Pack(2, __pyx_n_s_f, __pyx_int_4); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 249, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__11); - __Pyx_GIVEREF(__pyx_tuple__11); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_ctypes, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_ctypes, __pyx_t_1) < 0) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":250 - * b'I': ('I', 4), - * b'f': ('f', 4), - * b'A': ('c', 1)} # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":61 + * import string + * import ctypes + * import struct # <<<<<<<<<<<<<< * - * for tag in tags: + * cimport cython */ - __pyx_tuple__12 = PyTuple_Pack(2, __pyx_n_s_c, __pyx_int_1); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__12); - __Pyx_GIVEREF(__pyx_tuple__12); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_struct, __pyx_t_1) < 0) __PYX_ERR(0, 61, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":278 + /* "pysam/libcalignedsegment.pyx":81 + * + * # Constants for binary tag conversion + * cdef char * htslib_types = 'cCsSiIf' # <<<<<<<<<<<<<< + * cdef char * parray_types = 'bBhHiIf' * - * datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0]) - * args.extend([pytag[:2], # <<<<<<<<<<<<<< - * b"B", - * valuetype, */ - __pyx_slice__13 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__13)) __PYX_ERR(0, 278, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__13); - __Pyx_GIVEREF(__pyx_slice__13); + __pyx_v_5pysam_18libcalignedsegment_htslib_types = ((char *)"cCsSiIf"); - /* "pysam/libcalignedsegment.pyx":301 - * # save as bytes - * datafmt = "2sccI%is" % (len(value) * datatype2format[valuetype][1]) - * args.extend([pytag[:2], # <<<<<<<<<<<<<< - * b"B", - * valuetype, + /* "pysam/libcalignedsegment.pyx":82 + * # Constants for binary tag conversion + * cdef char * htslib_types = 'cCsSiIf' + * cdef char * parray_types = 'bBhHiIf' # <<<<<<<<<<<<<< + * + * cdef bint IS_PYTHON3 = PY_MAJOR_VERSION >= 3 */ - __pyx_slice__14 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__14)) __PYX_ERR(0, 301, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__14); - __Pyx_GIVEREF(__pyx_slice__14); + __pyx_v_5pysam_18libcalignedsegment_parray_types = ((char *)"bBhHiIf"); - /* "pysam/libcalignedsegment.pyx":319 - * datafmt = "2sc%s" % datatype2format[valuetype][0] + /* "pysam/libcalignedsegment.pyx":84 + * cdef char * parray_types = 'bBhHiIf' * - * args.extend([pytag[:2], # <<<<<<<<<<<<<< - * valuetype, - * value]) + * cdef bint IS_PYTHON3 = PY_MAJOR_VERSION >= 3 # <<<<<<<<<<<<<< + * + * # translation tables */ - __pyx_slice__15 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__15)) __PYX_ERR(0, 319, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__15); - __Pyx_GIVEREF(__pyx_slice__15); + __pyx_v_5pysam_18libcalignedsegment_IS_PYTHON3 = (PY_MAJOR_VERSION >= 3); - /* "pysam/libcalignedsegment.pyx":555 - * cdef uint32_t max_len = get_alignment_length(src) - * if max_len == 0: - * raise ValueError("could not determine alignment length") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":89 + * + * # cigar code to character and vice versa + * cdef char* CODE2CIGAR= "MIDNSHP=XB" # <<<<<<<<<<<<<< + * cdef int NCIGAR_CODES = 10 * - * cdef char * s = calloc(max_len + 1, sizeof(char)) */ - __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s_could_not_determine_alignment_le); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 555, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__17); - __Pyx_GIVEREF(__pyx_tuple__17); + __pyx_v_5pysam_18libcalignedsegment_CODE2CIGAR = ((char *)"MIDNSHP=XB"); - /* "pysam/libcalignedsegment.pyx":587 - * pass # advances neither - * elif op == BAM_CPAD: - * raise NotImplementedError( # <<<<<<<<<<<<<< - * "Padding (BAM_CPAD, 6) is currently not supported. " - * "Please implement. Sorry about that.") + /* "pysam/libcalignedsegment.pyx":90 + * # cigar code to character and vice versa + * cdef char* CODE2CIGAR= "MIDNSHP=XB" + * cdef int NCIGAR_CODES = 10 # <<<<<<<<<<<<<< + * + * # dimensioned for 8000 pileup limit (+ insertions/deletions) */ - __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_Padding_BAM_CPAD_6_is_currently); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 587, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__18); - __Pyx_GIVEREF(__pyx_tuple__18); + __pyx_v_5pysam_18libcalignedsegment_NCIGAR_CODES = 10; - /* "pysam/libcalignedsegment.pyx":799 - * if self._delegate.core.tid >= n_targets \ - * or self._delegate.core.mtid >= n_targets: - * raise ValueError('htsfile does not match aligned segment') # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":93 * - * cdef kstring_t line + * # dimensioned for 8000 pileup limit (+ insertions/deletions) + * cdef uint32_t MAX_PILEUP_BUFFER_SIZE = 10000 # <<<<<<<<<<<<<< + * + * if IS_PYTHON3: */ - __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_htsfile_does_not_match_aligned_s); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 799, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__20); - __Pyx_GIVEREF(__pyx_tuple__20); + __pyx_v_5pysam_18libcalignedsegment_MAX_PILEUP_BUFFER_SIZE = 0x2710; - /* "pysam/libcalignedsegment.pyx":808 - * if line.m: - * free(line.s) - * raise ValueError('sam_format failed') # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":95 + * cdef uint32_t MAX_PILEUP_BUFFER_SIZE = 10000 * - * ret = force_str(line.s[:line.l]) + * if IS_PYTHON3: # <<<<<<<<<<<<<< + * CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) + * maketrans = str.maketrans */ - __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_sam_format_failed); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__21); - __Pyx_GIVEREF(__pyx_tuple__21); + __pyx_t_2 = (__pyx_v_5pysam_18libcalignedsegment_IS_PYTHON3 != 0); + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":1442 - * ref_seq = force_str(build_alignment_sequence(src)) - * if ref_seq is None: - * raise ValueError("MD tag not present") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":96 * - * cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) + * if IS_PYTHON3: + * CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) # <<<<<<<<<<<<<< + * maketrans = str.maketrans + * else: */ - __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_MD_tag_not_present); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 1442, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__22); - __Pyx_GIVEREF(__pyx_tuple__22); + __pyx_t_1 = __pyx_pf_5pysam_18libcalignedsegment_genexpr(NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 96, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR2CODE, __pyx_t_3) < 0) __PYX_ERR(0, 96, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1467 - * pass # advances neither - * elif op == BAM_CPAD: - * raise NotImplementedError( # <<<<<<<<<<<<<< - * "Padding (BAM_CPAD, 6) is currently not supported. " - * "Please implement. Sorry about that.") + /* "pysam/libcalignedsegment.pyx":97 + * if IS_PYTHON3: + * CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) + * maketrans = str.maketrans # <<<<<<<<<<<<<< + * else: + * CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR)) */ - __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_Padding_BAM_CPAD_6_is_currently); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 1467, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__23); - __Pyx_GIVEREF(__pyx_tuple__23); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)(&PyString_Type)), __pyx_n_s_maketrans); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 97, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_maketrans, __pyx_t_3) < 0) __PYX_ERR(0, 97, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1511 - * ref_seq = force_str(self.get_reference_sequence()) - * if ref_seq is None: - * raise ValueError("MD tag not present") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":95 + * cdef uint32_t MAX_PILEUP_BUFFER_SIZE = 10000 + * + * if IS_PYTHON3: # <<<<<<<<<<<<<< + * CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) + * maketrans = str.maketrans + */ + goto __pyx_L2; + } + + /* "pysam/libcalignedsegment.pyx":99 + * maketrans = str.maketrans + * else: + * CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR)) # <<<<<<<<<<<<<< + * maketrans = string.maketrans * - * r_idx = 0 */ - __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_MD_tag_not_present); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 1511, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__24); - __Pyx_GIVEREF(__pyx_tuple__24); + /*else*/ { + __pyx_t_3 = __pyx_pf_5pysam_18libcalignedsegment_3genexpr(NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 99, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 99, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR2CODE, __pyx_t_1) < 0) __PYX_ERR(0, 99, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignedsegment.pyx":1577 + /* "pysam/libcalignedsegment.pyx":100 + * else: + * CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR)) + * maketrans = string.maketrans # <<<<<<<<<<<<<< * - * elif op == BAM_CPAD: - * raise NotImplementedError( # <<<<<<<<<<<<<< - * "Padding (BAM_CPAD, 6) is currently not supported. " - * "Please implement. Sorry about that.") + * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=XB])") */ - __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_s_Padding_BAM_CPAD_6_is_currently); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 1577, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__25); - __Pyx_GIVEREF(__pyx_tuple__25); + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_string); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 100, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_maketrans); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 100, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_maketrans, __pyx_t_3) < 0) __PYX_ERR(0, 100, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_L2:; - /* "pysam/libcalignedsegment.pyx":1881 - * typecode = get_value_code(value, value_type) - * if typecode == 0: - * raise ValueError("can't guess type or invalid type code specified") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":102 + * maketrans = string.maketrans * - * # Not Endian-safe, but then again neither is samtools! + * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=XB])") # <<<<<<<<<<<<<< + * + * # names for keys in dictionary representation of an AlignedSegment */ - __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_can_t_guess_type_or_invalid_type); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 1881, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__26); - __Pyx_GIVEREF(__pyx_tuple__26); + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_compile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__76, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR_REGEX, __pyx_t_3) < 0) __PYX_ERR(0, 102, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1910 - * # remove tag and type code as set by bam_aux_append - * # first four chars of format (<2sc) - * fmt = '<' + fmt[4:] # <<<<<<<<<<<<<< - * # first two values to pack - * args = args[2:] + /* "pysam/libcalignedsegment.pyx":105 + * + * # names for keys in dictionary representation of an AlignedSegment + * KEY_NAMES = ["name", "flag", "ref_name", "ref_pos", "map_quality", "cigar", # <<<<<<<<<<<<<< + * "next_ref_name", "next_ref_pos", "length", "seq", "qual", "tags"] + * */ - __pyx_slice__27 = PySlice_New(__pyx_int_4, Py_None, Py_None); if (unlikely(!__pyx_slice__27)) __PYX_ERR(0, 1910, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__27); - __Pyx_GIVEREF(__pyx_slice__27); + __pyx_t_3 = PyList_New(12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 105, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_n_s_name); + __Pyx_GIVEREF(__pyx_n_s_name); + PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_name); + __Pyx_INCREF(__pyx_n_s_flag); + __Pyx_GIVEREF(__pyx_n_s_flag); + PyList_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_flag); + __Pyx_INCREF(__pyx_n_s_ref_name); + __Pyx_GIVEREF(__pyx_n_s_ref_name); + PyList_SET_ITEM(__pyx_t_3, 2, __pyx_n_s_ref_name); + __Pyx_INCREF(__pyx_n_s_ref_pos); + __Pyx_GIVEREF(__pyx_n_s_ref_pos); + PyList_SET_ITEM(__pyx_t_3, 3, __pyx_n_s_ref_pos); + __Pyx_INCREF(__pyx_n_s_map_quality); + __Pyx_GIVEREF(__pyx_n_s_map_quality); + PyList_SET_ITEM(__pyx_t_3, 4, __pyx_n_s_map_quality); + __Pyx_INCREF(__pyx_n_s_cigar); + __Pyx_GIVEREF(__pyx_n_s_cigar); + PyList_SET_ITEM(__pyx_t_3, 5, __pyx_n_s_cigar); + __Pyx_INCREF(__pyx_n_s_next_ref_name); + __Pyx_GIVEREF(__pyx_n_s_next_ref_name); + PyList_SET_ITEM(__pyx_t_3, 6, __pyx_n_s_next_ref_name); + __Pyx_INCREF(__pyx_n_s_next_ref_pos); + __Pyx_GIVEREF(__pyx_n_s_next_ref_pos); + PyList_SET_ITEM(__pyx_t_3, 7, __pyx_n_s_next_ref_pos); + __Pyx_INCREF(__pyx_n_s_length); + __Pyx_GIVEREF(__pyx_n_s_length); + PyList_SET_ITEM(__pyx_t_3, 8, __pyx_n_s_length); + __Pyx_INCREF(__pyx_n_s_seq); + __Pyx_GIVEREF(__pyx_n_s_seq); + PyList_SET_ITEM(__pyx_t_3, 9, __pyx_n_s_seq); + __Pyx_INCREF(__pyx_n_s_qual); + __Pyx_GIVEREF(__pyx_n_s_qual); + PyList_SET_ITEM(__pyx_t_3, 10, __pyx_n_s_qual); + __Pyx_INCREF(__pyx_n_s_tags); + __Pyx_GIVEREF(__pyx_n_s_tags); + PyList_SET_ITEM(__pyx_t_3, 11, __pyx_n_s_tags); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_KEY_NAMES, __pyx_t_3) < 0) __PYX_ERR(0, 105, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1912 - * fmt = '<' + fmt[4:] - * # first two values to pack - * args = args[2:] # <<<<<<<<<<<<<< - * value_size = struct.calcsize(fmt) - * # buffer will be freed when object goes out of scope + /* "pysam/libcalignedsegment.pyx":325 + * # mapping python array.array and htslib typecodes to struct typecodes + * DATATYPE2FORMAT = { + * ord('c'): ('b', 1), # <<<<<<<<<<<<<< + * ord('C'): ('B', 1), + * ord('s'): ('h', 2), */ - __pyx_slice__28 = PySlice_New(__pyx_int_2, Py_None, Py_None); if (unlikely(!__pyx_slice__28)) __PYX_ERR(0, 1912, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__28); - __Pyx_GIVEREF(__pyx_slice__28); + __pyx_t_3 = __Pyx_PyDict_NewPresized(10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 325, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_3, __pyx_int_99, __pyx_tuple__77) < 0) __PYX_ERR(0, 325, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":1925 - * return - * else: - * raise ValueError('unsupported value_type in set_option') # <<<<<<<<<<<<<< - * - * bam_aux_append(src, + /* "pysam/libcalignedsegment.pyx":326 + * DATATYPE2FORMAT = { + * ord('c'): ('b', 1), + * ord('C'): ('B', 1), # <<<<<<<<<<<<<< + * ord('s'): ('h', 2), + * ord('S'): ('H', 2), */ - __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_unsupported_value_type_in_set_op); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 1925, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__29); - __Pyx_GIVEREF(__pyx_tuple__29); + if (PyDict_SetItem(__pyx_t_3, __pyx_int_67, __pyx_tuple__78) < 0) __PYX_ERR(0, 325, __pyx_L1_error) - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") + /* "pysam/libcalignedsegment.pyx":327 + * ord('c'): ('b', 1), + * ord('C'): ('B', 1), + * ord('s'): ('h', 2), # <<<<<<<<<<<<<< + * ord('S'): ('H', 2), + * ord('i'): ('i', 4), */ - __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_s_self__delegate_cannot_be_convert); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__30); - __Pyx_GIVEREF(__pyx_tuple__30); + if (PyDict_SetItem(__pyx_t_3, __pyx_int_115, __pyx_tuple__79) < 0) __PYX_ERR(0, 325, __pyx_L1_error) - /* "(tree fragment)":4 - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self._delegate cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":328 + * ord('C'): ('B', 1), + * ord('s'): ('h', 2), + * ord('S'): ('H', 2), # <<<<<<<<<<<<<< + * ord('i'): ('i', 4), + * ord('I'): ('I', 4), */ - __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s_self__delegate_cannot_be_convert); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__31); - __Pyx_GIVEREF(__pyx_tuple__31); + if (PyDict_SetItem(__pyx_t_3, __pyx_int_83, __pyx_tuple__80) < 0) __PYX_ERR(0, 325, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2325 - * ''' - * def __init__(self): - * raise TypeError("this class cannot be instantiated from Python") # <<<<<<<<<<<<<< - * - * def __str__(self): + /* "pysam/libcalignedsegment.pyx":329 + * ord('s'): ('h', 2), + * ord('S'): ('H', 2), + * ord('i'): ('i', 4), # <<<<<<<<<<<<<< + * ord('I'): ('I', 4), + * ord('f'): ('f', 4), */ - __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 2325, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__32); - __Pyx_GIVEREF(__pyx_tuple__32); + if (PyDict_SetItem(__pyx_t_3, __pyx_int_105, __pyx_tuple__81) < 0) __PYX_ERR(0, 325, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2366 - * - * if self.plp == NULL or self.plp[0] == NULL: - * raise ValueError("PileupColumn accessed after iterator finished") # <<<<<<<<<<<<<< - * - * # warning: there could be problems if self.n and self.buf are + /* "pysam/libcalignedsegment.pyx":330 + * ord('S'): ('H', 2), + * ord('i'): ('i', 4), + * ord('I'): ('I', 4), # <<<<<<<<<<<<<< + * ord('f'): ('f', 4), + * ord('d'): ('d', 8), */ - __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_s_PileupColumn_accessed_after_iter); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 2366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__34); - __Pyx_GIVEREF(__pyx_tuple__34); + if (PyDict_SetItem(__pyx_t_3, __pyx_int_73, __pyx_tuple__82) < 0) __PYX_ERR(0, 325, __pyx_L1_error) - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("self.plp cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.plp cannot be converted to a Python object for pickling") + /* "pysam/libcalignedsegment.pyx":331 + * ord('i'): ('i', 4), + * ord('I'): ('I', 4), + * ord('f'): ('f', 4), # <<<<<<<<<<<<<< + * ord('d'): ('d', 8), + * ord('A'): ('c', 1), */ - __pyx_tuple__35 = PyTuple_Pack(1, __pyx_kp_s_self_plp_cannot_be_converted_to); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__35); - __Pyx_GIVEREF(__pyx_tuple__35); + if (PyDict_SetItem(__pyx_t_3, __pyx_int_102, __pyx_tuple__83) < 0) __PYX_ERR(0, 325, __pyx_L1_error) - /* "(tree fragment)":4 - * raise TypeError("self.plp cannot be converted to a Python object for pickling") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.plp cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":332 + * ord('I'): ('I', 4), + * ord('f'): ('f', 4), + * ord('d'): ('d', 8), # <<<<<<<<<<<<<< + * ord('A'): ('c', 1), + * ord('a'): ('c', 1)} */ - __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_s_self_plp_cannot_be_converted_to); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__36); - __Pyx_GIVEREF(__pyx_tuple__36); + if (PyDict_SetItem(__pyx_t_3, __pyx_int_100, __pyx_tuple__84) < 0) __PYX_ERR(0, 325, __pyx_L1_error) - /* "pysam/libcalignedsegment.pyx":2405 - * - * def __init__(self): - * raise TypeError( # <<<<<<<<<<<<<< - * "this class cannot be instantiated from Python") + /* "pysam/libcalignedsegment.pyx":333 + * ord('f'): ('f', 4), + * ord('d'): ('d', 8), + * ord('A'): ('c', 1), # <<<<<<<<<<<<<< + * ord('a'): ('c', 1)} * */ - __pyx_tuple__37 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 2405, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__37); - __Pyx_GIVEREF(__pyx_tuple__37); + if (PyDict_SetItem(__pyx_t_3, __pyx_int_65, __pyx_tuple__85) < 0) __PYX_ERR(0, 325, __pyx_L1_error) - /* "View.MemoryView":132 + /* "pysam/libcalignedsegment.pyx":334 + * ord('d'): ('d', 8), + * ord('A'): ('c', 1), + * ord('a'): ('c', 1)} # <<<<<<<<<<<<<< * - * if not self.ndim: - * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<< * - * if itemsize <= 0: */ - __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_Empty_shape_tuple_for_cython_arr); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(1, 132, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__39); - __Pyx_GIVEREF(__pyx_tuple__39); + if (PyDict_SetItem(__pyx_t_3, __pyx_int_97, __pyx_tuple__86) < 0) __PYX_ERR(0, 325, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_DATATYPE2FORMAT, __pyx_t_3) < 0) __PYX_ERR(0, 324, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "View.MemoryView":135 + /* "pysam/libcalignedsegment.pyx":1077 * - * if itemsize <= 0: - * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<< + * @classmethod + * def fromstring(cls, sam, AlignmentHeader header): # <<<<<<<<<<<<<< + * """parses a string representation of the aligned segment. * - * if not isinstance(format, bytes): */ - __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_itemsize_0_for_cython_array); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(1, 135, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__40); - __Pyx_GIVEREF(__pyx_tuple__40); + __pyx_t_3 = __Pyx_GetNameInClass((PyObject *)__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment, __pyx_n_s_fromstring); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1077, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); - /* "View.MemoryView":138 + /* "pysam/libcalignedsegment.pyx":1076 + * return ret * - * if not isinstance(format, bytes): - * format = format.encode('ASCII') # <<<<<<<<<<<<<< - * self._format = format # keep a reference to the byte string - * self.format = self._format + * @classmethod # <<<<<<<<<<<<<< + * def fromstring(cls, sam, AlignmentHeader header): + * """parses a string representation of the aligned segment. */ - __pyx_tuple__41 = PyTuple_Pack(1, __pyx_n_s_ASCII); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(1, 138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__41); - __Pyx_GIVEREF(__pyx_tuple__41); + __pyx_t_1 = __Pyx_Method_ClassMethod(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1076, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment->tp_dict, __pyx_n_s_fromstring, __pyx_t_1) < 0) __PYX_ERR(0, 1077, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyType_Modified(__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment); - /* "View.MemoryView":147 - * - * if not self._shape: - * raise MemoryError("unable to allocate shape and strides.") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1124 * + * @classmethod + * def from_dict(cls, sam_dict, AlignmentHeader header): # <<<<<<<<<<<<<< + * """parses a dictionary representation of the aligned segment. * */ - __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_shape_and_str); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(1, 147, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__42); - __Pyx_GIVEREF(__pyx_tuple__42); + __pyx_t_1 = __Pyx_GetNameInClass((PyObject *)__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment, __pyx_n_s_from_dict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); - /* "View.MemoryView":175 - * self.data = malloc(self.len) - * if not self.data: - * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1123 + * return dict(list(zip(KEY_NAMES[:-1], vals[:n])) + [(KEY_NAMES[-1], vals[n:])]) * - * if self.dtype_is_object: + * @classmethod # <<<<<<<<<<<<<< + * def from_dict(cls, sam_dict, AlignmentHeader header): + * """parses a dictionary representation of the aligned segment. */ - __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_array_data); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(1, 175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__43); - __Pyx_GIVEREF(__pyx_tuple__43); + __pyx_t_3 = __Pyx_Method_ClassMethod(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment->tp_dict, __pyx_n_s_from_dict, __pyx_t_3) < 0) __PYX_ERR(0, 1124, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + PyType_Modified(__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment); - /* "View.MemoryView":191 - * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS - * if not (flags & bufmode): - * raise ValueError("Can only create a buffer that is contiguous in memory.") # <<<<<<<<<<<<<< - * info.buf = self.data - * info.len = self.len + /* "pysam/libcalignedsegment.pyx":3245 + * + * + * __all__ = [ # <<<<<<<<<<<<<< + * "AlignedSegment", + * "PileupColumn", */ - __pyx_tuple__44 = PyTuple_Pack(1, __pyx_kp_s_Can_only_create_a_buffer_that_is); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(1, 191, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__44); - __Pyx_GIVEREF(__pyx_tuple__44); + __pyx_t_3 = PyList_New(26); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3245, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_n_s_AlignedSegment); + __Pyx_GIVEREF(__pyx_n_s_AlignedSegment); + PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_AlignedSegment); + __Pyx_INCREF(__pyx_n_s_PileupColumn); + __Pyx_GIVEREF(__pyx_n_s_PileupColumn); + PyList_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_PileupColumn); + __Pyx_INCREF(__pyx_n_s_PileupRead); + __Pyx_GIVEREF(__pyx_n_s_PileupRead); + PyList_SET_ITEM(__pyx_t_3, 2, __pyx_n_s_PileupRead); + __Pyx_INCREF(__pyx_n_s_CMATCH); + __Pyx_GIVEREF(__pyx_n_s_CMATCH); + PyList_SET_ITEM(__pyx_t_3, 3, __pyx_n_s_CMATCH); + __Pyx_INCREF(__pyx_n_s_CINS); + __Pyx_GIVEREF(__pyx_n_s_CINS); + PyList_SET_ITEM(__pyx_t_3, 4, __pyx_n_s_CINS); + __Pyx_INCREF(__pyx_n_s_CDEL); + __Pyx_GIVEREF(__pyx_n_s_CDEL); + PyList_SET_ITEM(__pyx_t_3, 5, __pyx_n_s_CDEL); + __Pyx_INCREF(__pyx_n_s_CREF_SKIP); + __Pyx_GIVEREF(__pyx_n_s_CREF_SKIP); + PyList_SET_ITEM(__pyx_t_3, 6, __pyx_n_s_CREF_SKIP); + __Pyx_INCREF(__pyx_n_s_CSOFT_CLIP); + __Pyx_GIVEREF(__pyx_n_s_CSOFT_CLIP); + PyList_SET_ITEM(__pyx_t_3, 7, __pyx_n_s_CSOFT_CLIP); + __Pyx_INCREF(__pyx_n_s_CHARD_CLIP); + __Pyx_GIVEREF(__pyx_n_s_CHARD_CLIP); + PyList_SET_ITEM(__pyx_t_3, 8, __pyx_n_s_CHARD_CLIP); + __Pyx_INCREF(__pyx_n_s_CPAD); + __Pyx_GIVEREF(__pyx_n_s_CPAD); + PyList_SET_ITEM(__pyx_t_3, 9, __pyx_n_s_CPAD); + __Pyx_INCREF(__pyx_n_s_CEQUAL); + __Pyx_GIVEREF(__pyx_n_s_CEQUAL); + PyList_SET_ITEM(__pyx_t_3, 10, __pyx_n_s_CEQUAL); + __Pyx_INCREF(__pyx_n_s_CDIFF); + __Pyx_GIVEREF(__pyx_n_s_CDIFF); + PyList_SET_ITEM(__pyx_t_3, 11, __pyx_n_s_CDIFF); + __Pyx_INCREF(__pyx_n_s_CBACK); + __Pyx_GIVEREF(__pyx_n_s_CBACK); + PyList_SET_ITEM(__pyx_t_3, 12, __pyx_n_s_CBACK); + __Pyx_INCREF(__pyx_n_s_FPAIRED); + __Pyx_GIVEREF(__pyx_n_s_FPAIRED); + PyList_SET_ITEM(__pyx_t_3, 13, __pyx_n_s_FPAIRED); + __Pyx_INCREF(__pyx_n_s_FPROPER_PAIR); + __Pyx_GIVEREF(__pyx_n_s_FPROPER_PAIR); + PyList_SET_ITEM(__pyx_t_3, 14, __pyx_n_s_FPROPER_PAIR); + __Pyx_INCREF(__pyx_n_s_FUNMAP); + __Pyx_GIVEREF(__pyx_n_s_FUNMAP); + PyList_SET_ITEM(__pyx_t_3, 15, __pyx_n_s_FUNMAP); + __Pyx_INCREF(__pyx_n_s_FMUNMAP); + __Pyx_GIVEREF(__pyx_n_s_FMUNMAP); + PyList_SET_ITEM(__pyx_t_3, 16, __pyx_n_s_FMUNMAP); + __Pyx_INCREF(__pyx_n_s_FREVERSE); + __Pyx_GIVEREF(__pyx_n_s_FREVERSE); + PyList_SET_ITEM(__pyx_t_3, 17, __pyx_n_s_FREVERSE); + __Pyx_INCREF(__pyx_n_s_FMREVERSE); + __Pyx_GIVEREF(__pyx_n_s_FMREVERSE); + PyList_SET_ITEM(__pyx_t_3, 18, __pyx_n_s_FMREVERSE); + __Pyx_INCREF(__pyx_n_s_FREAD1); + __Pyx_GIVEREF(__pyx_n_s_FREAD1); + PyList_SET_ITEM(__pyx_t_3, 19, __pyx_n_s_FREAD1); + __Pyx_INCREF(__pyx_n_s_FREAD2); + __Pyx_GIVEREF(__pyx_n_s_FREAD2); + PyList_SET_ITEM(__pyx_t_3, 20, __pyx_n_s_FREAD2); + __Pyx_INCREF(__pyx_n_s_FSECONDARY); + __Pyx_GIVEREF(__pyx_n_s_FSECONDARY); + PyList_SET_ITEM(__pyx_t_3, 21, __pyx_n_s_FSECONDARY); + __Pyx_INCREF(__pyx_n_s_FQCFAIL); + __Pyx_GIVEREF(__pyx_n_s_FQCFAIL); + PyList_SET_ITEM(__pyx_t_3, 22, __pyx_n_s_FQCFAIL); + __Pyx_INCREF(__pyx_n_s_FDUP); + __Pyx_GIVEREF(__pyx_n_s_FDUP); + PyList_SET_ITEM(__pyx_t_3, 23, __pyx_n_s_FDUP); + __Pyx_INCREF(__pyx_n_s_FSUPPLEMENTARY); + __Pyx_GIVEREF(__pyx_n_s_FSUPPLEMENTARY); + PyList_SET_ITEM(__pyx_t_3, 24, __pyx_n_s_FSUPPLEMENTARY); + __Pyx_INCREF(__pyx_n_s_KEY_NAMES); + __Pyx_GIVEREF(__pyx_n_s_KEY_NAMES); + PyList_SET_ITEM(__pyx_t_3, 25, __pyx_n_s_KEY_NAMES); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_3) < 0) __PYX_ERR(0, 3245, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + /* "(tree fragment)":1 + * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0xbbc0b95: + * from pickle import PickleError as __pyx_PickleError */ - __pyx_tuple__45 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__45); - __Pyx_GIVEREF(__pyx_tuple__45); + __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_5pysam_18libcalignedsegment_7__pyx_unpickle_PileupRead, NULL, __pyx_n_s_pysam_libcalignedsegment); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_PileupRead, __pyx_t_3) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "(tree fragment)":4 - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + /* "pysam/libcalignedsegment.pyx":1 + * # cython: embedsignature=True # <<<<<<<<<<<<<< + * # cython: profile=True + * ############################################################################### */ - __pyx_tuple__46 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__46); - __Pyx_GIVEREF(__pyx_tuple__46); + __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "View.MemoryView":413 - * def __setitem__(memoryview self, object index, object value): - * if self.view.readonly: - * raise TypeError("Cannot assign to read-only memoryview") # <<<<<<<<<<<<<< + /* "EnumBase":9 * - * have_slices, index = _unellipsify(index, self.view.ndim) + * cdef object __Pyx_OrderedDict + * if PY_VERSION_HEX >= 0x02070000: # <<<<<<<<<<<<<< + * from collections import OrderedDict as __Pyx_OrderedDict + * else: */ - __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_s_Cannot_assign_to_read_only_memor); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(1, 413, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__47); - __Pyx_GIVEREF(__pyx_tuple__47); + __pyx_t_2 = ((PY_VERSION_HEX >= 0x02070000) != 0); + if (__pyx_t_2) { - /* "View.MemoryView":490 - * result = struct.unpack(self.view.format, bytesitem) - * except struct.error: - * raise ValueError("Unable to convert item to object") # <<<<<<<<<<<<<< - * else: - * if len(self.view.format) == 1: + /* "EnumBase":10 + * cdef object __Pyx_OrderedDict + * if PY_VERSION_HEX >= 0x02070000: + * from collections import OrderedDict as __Pyx_OrderedDict # <<<<<<<<<<<<<< + * else: + * __Pyx_OrderedDict = dict */ - __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_convert_item_to_object); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(1, 490, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__48); - __Pyx_GIVEREF(__pyx_tuple__48); + __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_n_s_OrderedDict); + __Pyx_GIVEREF(__pyx_n_s_OrderedDict); + PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_OrderedDict); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, __pyx_t_3, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_3); + __Pyx_XGOTREF(__Pyx_OrderedDict); + __Pyx_DECREF_SET(__Pyx_OrderedDict, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "View.MemoryView":515 - * def __getbuffer__(self, Py_buffer *info, int flags): - * if flags & PyBUF_WRITABLE and self.view.readonly: - * raise ValueError("Cannot create writable memory view from read-only memoryview") # <<<<<<<<<<<<<< + /* "EnumBase":9 * - * if flags & PyBUF_STRIDES: + * cdef object __Pyx_OrderedDict + * if PY_VERSION_HEX >= 0x02070000: # <<<<<<<<<<<<<< + * from collections import OrderedDict as __Pyx_OrderedDict + * else: */ - __pyx_tuple__49 = PyTuple_Pack(1, __pyx_kp_s_Cannot_create_writable_memory_vi); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(1, 515, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__49); - __Pyx_GIVEREF(__pyx_tuple__49); + goto __pyx_L3; + } - /* "View.MemoryView":565 - * if self.view.strides == NULL: - * - * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<< + /* "EnumBase":12 + * from collections import OrderedDict as __Pyx_OrderedDict + * else: + * __Pyx_OrderedDict = dict # <<<<<<<<<<<<<< * - * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) + * @cython.internal */ - __pyx_tuple__50 = PyTuple_Pack(1, __pyx_kp_s_Buffer_view_does_not_expose_stri); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(1, 565, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__50); - __Pyx_GIVEREF(__pyx_tuple__50); + /*else*/ { + __Pyx_INCREF(((PyObject *)(&PyDict_Type))); + __Pyx_XGOTREF(__Pyx_OrderedDict); + __Pyx_DECREF_SET(__Pyx_OrderedDict, ((PyObject *)(&PyDict_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyDict_Type))); + } + __pyx_L3:; - /* "View.MemoryView":572 - * def suboffsets(self): - * if self.view.suboffsets == NULL: - * return (-1,) * self.view.ndim # <<<<<<<<<<<<<< + /* "EnumBase":26 * - * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) + * cdef object __Pyx_EnumBase + * class __Pyx_EnumBase(int): # <<<<<<<<<<<<<< + * __metaclass__ = __Pyx_EnumMeta + * def __new__(cls, value, name=None): */ - __pyx_tuple__51 = PyTuple_New(1); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(1, 572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__51); - __Pyx_INCREF(__pyx_int_neg_1); - __Pyx_GIVEREF(__pyx_int_neg_1); - PyTuple_SET_ITEM(__pyx_tuple__51, 0, __pyx_int_neg_1); - __Pyx_GIVEREF(__pyx_tuple__51); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)(&PyInt_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyInt_Type))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)(&PyInt_Type))); + __pyx_t_3 = __Pyx_CalculateMetaclass(NULL, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_Py3MetaclassPrepare(__pyx_t_3, __pyx_t_1, __pyx_n_s_Pyx_EnumBase, __pyx_n_s_Pyx_EnumBase, (PyObject *) NULL, __pyx_n_s_EnumBase, (PyObject *) NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + /* "EnumBase":27 + * cdef object __Pyx_EnumBase + * class __Pyx_EnumBase(int): + * __metaclass__ = __Pyx_EnumMeta # <<<<<<<<<<<<<< + * def __new__(cls, value, name=None): + * for v in cls: */ - __pyx_tuple__52 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__52); - __Pyx_GIVEREF(__pyx_tuple__52); + if (__Pyx_SetNameInClass(__pyx_t_4, __pyx_n_s_metaclass, ((PyObject *)__pyx_ptype___Pyx_EnumMeta)) < 0) __PYX_ERR(1, 27, __pyx_L1_error) - /* "(tree fragment)":4 - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + /* "EnumBase":28 + * class __Pyx_EnumBase(int): + * __metaclass__ = __Pyx_EnumMeta + * def __new__(cls, value, name=None): # <<<<<<<<<<<<<< + * for v in cls: + * if v == value: */ - __pyx_tuple__53 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__53); - __Pyx_GIVEREF(__pyx_tuple__53); + __pyx_t_5 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8EnumBase_14__Pyx_EnumBase_1__new__, __Pyx_CYFUNCTION_STATICMETHOD, __pyx_n_s_Pyx_EnumBase___new, NULL, __pyx_n_s_EnumBase, __pyx_d, ((PyObject *)__pyx_codeobj__50)); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_5, __pyx_tuple__89); + if (__Pyx_SetNameInClass(__pyx_t_4, __pyx_n_s_new, __pyx_t_5) < 0) __PYX_ERR(1, 28, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "View.MemoryView":677 - * if item is Ellipsis: - * if not seen_ellipsis: - * result.extend([slice(None)] * (ndim - len(tup) + 1)) # <<<<<<<<<<<<<< - * seen_ellipsis = True - * else: + /* "EnumBase":39 + * cls.__members__[name] = res + * return res + * def __repr__(self): # <<<<<<<<<<<<<< + * return "<%s.%s: %d>" % (self.__class__.__name__, self.name, self) + * def __str__(self): */ - __pyx_slice__54 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__54)) __PYX_ERR(1, 677, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__54); - __Pyx_GIVEREF(__pyx_slice__54); + __pyx_t_5 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8EnumBase_14__Pyx_EnumBase_3__repr__, 0, __pyx_n_s_Pyx_EnumBase___repr, NULL, __pyx_n_s_EnumBase, __pyx_d, ((PyObject *)__pyx_codeobj__51)); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 39, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__Pyx_SetNameInClass(__pyx_t_4, __pyx_n_s_repr, __pyx_t_5) < 0) __PYX_ERR(1, 39, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "View.MemoryView":680 - * seen_ellipsis = True - * else: - * result.append(slice(None)) # <<<<<<<<<<<<<< - * have_slices = True - * else: + /* "EnumBase":41 + * def __repr__(self): + * return "<%s.%s: %d>" % (self.__class__.__name__, self.name, self) + * def __str__(self): # <<<<<<<<<<<<<< + * return "%s.%s" % (self.__class__.__name__, self.name) + * */ - __pyx_slice__55 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__55)) __PYX_ERR(1, 680, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__55); - __Pyx_GIVEREF(__pyx_slice__55); + __pyx_t_5 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8EnumBase_14__Pyx_EnumBase_5__str__, 0, __pyx_n_s_Pyx_EnumBase___str, NULL, __pyx_n_s_EnumBase, __pyx_d, ((PyObject *)__pyx_codeobj__52)); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 41, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__Pyx_SetNameInClass(__pyx_t_4, __pyx_n_s_str, __pyx_t_5) < 0) __PYX_ERR(1, 41, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "View.MemoryView":691 - * nslices = ndim - len(result) - * if nslices: - * result.extend([slice(None)] * nslices) # <<<<<<<<<<<<<< + /* "EnumBase":26 * - * return have_slices or nslices, tuple(result) + * cdef object __Pyx_EnumBase + * class __Pyx_EnumBase(int): # <<<<<<<<<<<<<< + * __metaclass__ = __Pyx_EnumMeta + * def __new__(cls, value, name=None): */ - __pyx_slice__56 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__56)) __PYX_ERR(1, 691, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__56); - __Pyx_GIVEREF(__pyx_slice__56); + __pyx_t_5 = __Pyx_Py3ClassCreate(__pyx_t_3, __pyx_n_s_Pyx_EnumBase, __pyx_t_1, __pyx_t_4, NULL, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_XGOTREF(__Pyx_EnumBase); + __Pyx_DECREF_SET(__Pyx_EnumBase, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "View.MemoryView":698 - * for suboffset in suboffsets[:ndim]: - * if suboffset >= 0: - * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<< + /* "EnumBase":44 + * return "%s.%s" % (self.__class__.__name__, self.name) * + * if PY_VERSION_HEX >= 0x03040000: # <<<<<<<<<<<<<< + * from enum import IntEnum as __Pyx_EnumBase * */ - __pyx_tuple__57 = PyTuple_Pack(1, __pyx_kp_s_Indirect_dimensions_not_supporte); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(1, 698, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__57); - __Pyx_GIVEREF(__pyx_tuple__57); - - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - */ - __pyx_tuple__58 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__58); - __Pyx_GIVEREF(__pyx_tuple__58); + __pyx_t_2 = ((PY_VERSION_HEX >= 0x03040000) != 0); + if (__pyx_t_2) { - /* "(tree fragment)":4 - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + /* "EnumBase":45 + * + * if PY_VERSION_HEX >= 0x03040000: + * from enum import IntEnum as __Pyx_EnumBase # <<<<<<<<<<<<<< + * */ - __pyx_tuple__59 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__59); - __Pyx_GIVEREF(__pyx_tuple__59); + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 45, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_IntEnum); + __Pyx_GIVEREF(__pyx_n_s_IntEnum); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_IntEnum); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_enum, __pyx_t_1, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 45, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_IntEnum); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 45, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_1); + __Pyx_XGOTREF(__Pyx_EnumBase); + __Pyx_DECREF_SET(__Pyx_EnumBase, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":88 - * CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR)) + /* "EnumBase":44 + * return "%s.%s" % (self.__class__.__name__, self.name) * - * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=XB])") # <<<<<<<<<<<<<< + * if PY_VERSION_HEX >= 0x03040000: # <<<<<<<<<<<<<< + * from enum import IntEnum as __Pyx_EnumBase * - * ##################################################################### */ - __pyx_tuple__61 = PyTuple_Pack(1, __pyx_kp_s_d_MIDNSHP_XB); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(0, 88, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__61); - __Pyx_GIVEREF(__pyx_tuple__61); + } /* "(tree fragment)":1 - * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< - * if __pyx_checksum != 0xbbc0b95: + * def __pyx_unpickle___Pyx_EnumMeta(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0xd41d8cd: * from pickle import PickleError as __pyx_PickleError */ - __pyx_tuple__62 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__62); - __Pyx_GIVEREF(__pyx_tuple__62); - __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__62, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_PileupRead, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_8EnumBase_1__pyx_unpickle___Pyx_EnumMeta, NULL, __pyx_n_s_EnumBase); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle___Pyx_EnumMeta, __pyx_t_3) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "View.MemoryView":208 + * info.obj = self + * + * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< + * + * def __dealloc__(array self): + */ + __pyx_t_3 = __pyx_capsule_create(((void *)(&__pyx_array_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 208, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem((PyObject *)__pyx_array_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_3) < 0) __PYX_ERR(1, 208, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + PyType_Modified(__pyx_array_type); /* "View.MemoryView":285 * return self.name @@ -47140,9 +58754,12 @@ static int __Pyx_InitCachedConstants(void) { * cdef strided = Enum("") # default * cdef indirect = Enum("") */ - __pyx_tuple__63 = PyTuple_Pack(1, __pyx_kp_s_strided_and_direct_or_indirect); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(1, 285, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__63); - __Pyx_GIVEREF(__pyx_tuple__63); + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__93, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(generic); + __Pyx_DECREF_SET(generic, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; /* "View.MemoryView":286 * @@ -47151,9 +58768,12 @@ static int __Pyx_InitCachedConstants(void) { * cdef indirect = Enum("") * */ - __pyx_tuple__64 = PyTuple_Pack(1, __pyx_kp_s_strided_and_direct); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(1, 286, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__64); - __Pyx_GIVEREF(__pyx_tuple__64); + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__94, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 286, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(strided); + __Pyx_DECREF_SET(strided, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; /* "View.MemoryView":287 * cdef generic = Enum("") @@ -47162,9 +58782,12 @@ static int __Pyx_InitCachedConstants(void) { * * */ - __pyx_tuple__65 = PyTuple_Pack(1, __pyx_kp_s_strided_and_indirect); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(1, 287, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__65); - __Pyx_GIVEREF(__pyx_tuple__65); + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__95, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(indirect); + __Pyx_DECREF_SET(indirect, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; /* "View.MemoryView":290 * @@ -47173,9 +58796,12 @@ static int __Pyx_InitCachedConstants(void) { * cdef indirect_contiguous = Enum("") * */ - __pyx_tuple__66 = PyTuple_Pack(1, __pyx_kp_s_contiguous_and_direct); if (unlikely(!__pyx_tuple__66)) __PYX_ERR(1, 290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__66); - __Pyx_GIVEREF(__pyx_tuple__66); + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__96, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 290, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(contiguous); + __Pyx_DECREF_SET(contiguous, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; /* "View.MemoryView":291 * @@ -47184,812 +58810,1788 @@ static int __Pyx_InitCachedConstants(void) { * * */ - __pyx_tuple__67 = PyTuple_Pack(1, __pyx_kp_s_contiguous_and_indirect); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(1, 291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__67); - __Pyx_GIVEREF(__pyx_tuple__67); + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__97, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(indirect_contiguous); + __Pyx_DECREF_SET(indirect_contiguous, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + + /* "View.MemoryView":315 + * + * DEF THREAD_LOCKS_PREALLOCATED = 8 + * cdef int __pyx_memoryview_thread_locks_used = 0 # <<<<<<<<<<<<<< + * cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [ + * PyThread_allocate_lock(), + */ + __pyx_memoryview_thread_locks_used = 0; + + /* "View.MemoryView":316 + * DEF THREAD_LOCKS_PREALLOCATED = 8 + * cdef int __pyx_memoryview_thread_locks_used = 0 + * cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [ # <<<<<<<<<<<<<< + * PyThread_allocate_lock(), + * PyThread_allocate_lock(), + */ + __pyx_t_6[0] = PyThread_allocate_lock(); + __pyx_t_6[1] = PyThread_allocate_lock(); + __pyx_t_6[2] = PyThread_allocate_lock(); + __pyx_t_6[3] = PyThread_allocate_lock(); + __pyx_t_6[4] = PyThread_allocate_lock(); + __pyx_t_6[5] = PyThread_allocate_lock(); + __pyx_t_6[6] = PyThread_allocate_lock(); + __pyx_t_6[7] = PyThread_allocate_lock(); + memcpy(&(__pyx_memoryview_thread_locks[0]), __pyx_t_6, sizeof(__pyx_memoryview_thread_locks[0]) * (8)); + + /* "View.MemoryView":544 + * info.obj = self + * + * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_3 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 544, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem((PyObject *)__pyx_memoryview_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_3) < 0) __PYX_ERR(1, 544, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + PyType_Modified(__pyx_memoryview_type); + + /* "View.MemoryView":990 + * return self.from_object + * + * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_3 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 990, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem((PyObject *)__pyx_memoryviewslice_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_3) < 0) __PYX_ERR(1, 990, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + PyType_Modified(__pyx_memoryviewslice_type); /* "(tree fragment)":1 * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0xb068931: * from pickle import PickleError as __pyx_PickleError */ - __pyx_tuple__68 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__68)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__68); - __Pyx_GIVEREF(__pyx_tuple__68); - __pyx_codeobj__60 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__68, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_Enum, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__60)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} + __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_15View_dot_MemoryView_1__pyx_unpickle_Enum, NULL, __pyx_n_s_View_MemoryView); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_Enum, __pyx_t_3) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -static int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); - __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_128 = PyInt_FromLong(128); if (unlikely(!__pyx_int_128)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_256 = PyInt_FromLong(256); if (unlikely(!__pyx_int_256)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_32768 = PyInt_FromLong(32768L); if (unlikely(!__pyx_int_32768)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_65536 = PyInt_FromLong(65536L); if (unlikely(!__pyx_int_65536)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_184977713 = PyInt_FromLong(184977713L); if (unlikely(!__pyx_int_184977713)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_196873109 = PyInt_FromLong(196873109L); if (unlikely(!__pyx_int_196873109)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_2147483648 = PyInt_FromString((char *)"2147483648", 0, 0); if (unlikely(!__pyx_int_2147483648)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_4294967295 = PyInt_FromString((char *)"4294967295", 0, 0); if (unlikely(!__pyx_int_4294967295)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_4294967296 = PyInt_FromString((char *)"4294967296", 0, 0); if (unlikely(!__pyx_int_4294967296)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_neg_128 = PyInt_FromLong(-128); if (unlikely(!__pyx_int_neg_128)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_neg_32768 = PyInt_FromLong(-32768L); if (unlikely(!__pyx_int_neg_32768)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_neg_2147483648 = PyInt_FromLong(-2147483648L); if (unlikely(!__pyx_int_neg_2147483648)) __PYX_ERR(0, 1, __pyx_L1_error) - return 0; - __pyx_L1_error:; - return -1; -} + /* "EnumType":50 + * + * + * cdef dict __Pyx_globals = globals() # <<<<<<<<<<<<<< + * if PY_VERSION_HEX >= 0x03040000: + * + */ + __pyx_t_3 = __Pyx_Globals(); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 50, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(PyDict_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(1, 50, __pyx_L1_error) + __Pyx_XGOTREF(__Pyx_globals); + __Pyx_DECREF_SET(__Pyx_globals, ((PyObject*)__pyx_t_3)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; -static int __Pyx_modinit_global_init_code(void); /*proto*/ -static int __Pyx_modinit_variable_export_code(void); /*proto*/ -static int __Pyx_modinit_function_export_code(void); /*proto*/ -static int __Pyx_modinit_type_init_code(void); /*proto*/ -static int __Pyx_modinit_type_import_code(void); /*proto*/ -static int __Pyx_modinit_variable_import_code(void); /*proto*/ -static int __Pyx_modinit_function_import_code(void); /*proto*/ + /* "EnumType":51 + * + * cdef dict __Pyx_globals = globals() + * if PY_VERSION_HEX >= 0x03040000: # <<<<<<<<<<<<<< + * + * CIGAR_OPS = __Pyx_EnumBase('CIGAR_OPS', __Pyx_OrderedDict([ + */ + __pyx_t_2 = ((PY_VERSION_HEX >= 0x03040000) != 0); + if (__pyx_t_2) { -static int __Pyx_modinit_global_init_code(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); - /*--- Global init code ---*/ - generic = Py_None; Py_INCREF(Py_None); - strided = Py_None; Py_INCREF(Py_None); - indirect = Py_None; Py_INCREF(Py_None); - contiguous = Py_None; Py_INCREF(Py_None); - indirect_contiguous = Py_None; Py_INCREF(Py_None); - __Pyx_RefNannyFinishContext(); - return 0; -} + /* "EnumType":54 + * + * CIGAR_OPS = __Pyx_EnumBase('CIGAR_OPS', __Pyx_OrderedDict([ + * ('CMATCH', CMATCH), # <<<<<<<<<<<<<< + * ('CINS', CINS), + * ('CDEL', CDEL), + */ + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CMATCH); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 54, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 54, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_CMATCH); + __Pyx_GIVEREF(__pyx_n_s_CMATCH); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_CMATCH); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); + __pyx_t_3 = 0; + + /* "EnumType":55 + * CIGAR_OPS = __Pyx_EnumBase('CIGAR_OPS', __Pyx_OrderedDict([ + * ('CMATCH', CMATCH), + * ('CINS', CINS), # <<<<<<<<<<<<<< + * ('CDEL', CDEL), + * ('CREF_SKIP', CREF_SKIP), + */ + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CINS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 55, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 55, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_n_s_CINS); + __Pyx_GIVEREF(__pyx_n_s_CINS); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_CINS); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __pyx_t_3 = 0; + + /* "EnumType":56 + * ('CMATCH', CMATCH), + * ('CINS', CINS), + * ('CDEL', CDEL), # <<<<<<<<<<<<<< + * ('CREF_SKIP', CREF_SKIP), + * ('CSOFT_CLIP', CSOFT_CLIP), + */ + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CDEL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 56, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 56, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_n_s_CDEL); + __Pyx_GIVEREF(__pyx_n_s_CDEL); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_CDEL); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3); + __pyx_t_3 = 0; + + /* "EnumType":57 + * ('CINS', CINS), + * ('CDEL', CDEL), + * ('CREF_SKIP', CREF_SKIP), # <<<<<<<<<<<<<< + * ('CSOFT_CLIP', CSOFT_CLIP), + * ('CHARD_CLIP', CHARD_CLIP), + */ + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CREF_SKIP); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 57, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 57, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_n_s_CREF_SKIP); + __Pyx_GIVEREF(__pyx_n_s_CREF_SKIP); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_CREF_SKIP); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_3); + __pyx_t_3 = 0; + + /* "EnumType":58 + * ('CDEL', CDEL), + * ('CREF_SKIP', CREF_SKIP), + * ('CSOFT_CLIP', CSOFT_CLIP), # <<<<<<<<<<<<<< + * ('CHARD_CLIP', CHARD_CLIP), + * ('CPAD', CPAD), + */ + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CSOFT_CLIP); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 58, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 58, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_n_s_CSOFT_CLIP); + __Pyx_GIVEREF(__pyx_n_s_CSOFT_CLIP); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_n_s_CSOFT_CLIP); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3); + __pyx_t_3 = 0; + + /* "EnumType":59 + * ('CREF_SKIP', CREF_SKIP), + * ('CSOFT_CLIP', CSOFT_CLIP), + * ('CHARD_CLIP', CHARD_CLIP), # <<<<<<<<<<<<<< + * ('CPAD', CPAD), + * ('CEQUAL', CEQUAL), + */ + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CHARD_CLIP); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 59, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 59, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_INCREF(__pyx_n_s_CHARD_CLIP); + __Pyx_GIVEREF(__pyx_n_s_CHARD_CLIP); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_n_s_CHARD_CLIP); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_3); + __pyx_t_3 = 0; + + /* "EnumType":60 + * ('CSOFT_CLIP', CSOFT_CLIP), + * ('CHARD_CLIP', CHARD_CLIP), + * ('CPAD', CPAD), # <<<<<<<<<<<<<< + * ('CEQUAL', CEQUAL), + * ('CDIFF', CDIFF), + */ + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CPAD); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_n_s_CPAD); + __Pyx_GIVEREF(__pyx_n_s_CPAD); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_n_s_CPAD); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3); + __pyx_t_3 = 0; + + /* "EnumType":61 + * ('CHARD_CLIP', CHARD_CLIP), + * ('CPAD', CPAD), + * ('CEQUAL', CEQUAL), # <<<<<<<<<<<<<< + * ('CDIFF', CDIFF), + * ('CBACK', CBACK), + */ + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CEQUAL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 61, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 61, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_n_s_CEQUAL); + __Pyx_GIVEREF(__pyx_n_s_CEQUAL); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_n_s_CEQUAL); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_3); + __pyx_t_3 = 0; + + /* "EnumType":62 + * ('CPAD', CPAD), + * ('CEQUAL', CEQUAL), + * ('CDIFF', CDIFF), # <<<<<<<<<<<<<< + * ('CBACK', CBACK), + * ])) + */ + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CDIFF); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 62, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 62, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(__pyx_n_s_CDIFF); + __Pyx_GIVEREF(__pyx_n_s_CDIFF); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_n_s_CDIFF); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_3); + __pyx_t_3 = 0; + + /* "EnumType":63 + * ('CEQUAL', CEQUAL), + * ('CDIFF', CDIFF), + * ('CBACK', CBACK), # <<<<<<<<<<<<<< + * ])) + * __Pyx_globals['CMATCH'] = CIGAR_OPS.CMATCH + */ + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CBACK); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_INCREF(__pyx_n_s_CBACK); + __Pyx_GIVEREF(__pyx_n_s_CBACK); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_n_s_CBACK); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_3); + __pyx_t_3 = 0; -static int __Pyx_modinit_variable_export_code(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); - /*--- Variable export code ---*/ - __Pyx_RefNannyFinishContext(); - return 0; -} + /* "EnumType":53 + * if PY_VERSION_HEX >= 0x03040000: + * + * CIGAR_OPS = __Pyx_EnumBase('CIGAR_OPS', __Pyx_OrderedDict([ # <<<<<<<<<<<<<< + * ('CMATCH', CMATCH), + * ('CINS', CINS), + */ + __pyx_t_3 = PyList_New(10); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_1); + PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_4); + PyList_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyList_SET_ITEM(__pyx_t_3, 2, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_7); + PyList_SET_ITEM(__pyx_t_3, 3, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); + PyList_SET_ITEM(__pyx_t_3, 4, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_9); + PyList_SET_ITEM(__pyx_t_3, 5, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_10); + PyList_SET_ITEM(__pyx_t_3, 6, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_11); + PyList_SET_ITEM(__pyx_t_3, 7, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_12); + PyList_SET_ITEM(__pyx_t_3, 8, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_13); + PyList_SET_ITEM(__pyx_t_3, 9, __pyx_t_13); + __pyx_t_1 = 0; + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_7 = 0; + __pyx_t_8 = 0; + __pyx_t_9 = 0; + __pyx_t_10 = 0; + __pyx_t_11 = 0; + __pyx_t_12 = 0; + __pyx_t_13 = 0; + __pyx_t_13 = __Pyx_PyObject_CallOneArg(__Pyx_OrderedDict, __pyx_t_3); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_n_s_CIGAR_OPS); + __Pyx_GIVEREF(__pyx_n_s_CIGAR_OPS); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_CIGAR_OPS); + __Pyx_GIVEREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_13); + __pyx_t_13 = 0; + __pyx_t_13 = __Pyx_PyObject_Call(__Pyx_EnumBase, __pyx_t_3, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR_OPS, __pyx_t_13) < 0) __PYX_ERR(1, 53, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + + /* "EnumType":65 + * ('CBACK', CBACK), + * ])) + * __Pyx_globals['CMATCH'] = CIGAR_OPS.CMATCH # <<<<<<<<<<<<<< + * __Pyx_globals['CINS'] = CIGAR_OPS.CINS + * __Pyx_globals['CDEL'] = CIGAR_OPS.CDEL + */ + __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 65, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_CMATCH); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 65, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 65, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CMATCH, __pyx_t_3) < 0)) __PYX_ERR(1, 65, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -static int __Pyx_modinit_function_export_code(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); - /*--- Function export code ---*/ - if (__Pyx_ExportFunction("makeAlignedSegment", (void (*)(void))__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment, "PyObject *(bam1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ExportFunction("makePileupColumn", (void (*)(void))__pyx_f_5pysam_18libcalignedsegment_makePileupColumn, "PyObject *(bam_pileup1_t **, int, int, int, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ExportFunction("makePileupRead", (void (*)(void))__pyx_f_5pysam_18libcalignedsegment_makePileupRead, "PyObject *(bam_pileup1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ExportFunction("get_alignment_length", (void (*)(void))__pyx_f_5pysam_18libcalignedsegment_get_alignment_length, "uint32_t (bam1_t *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} + /* "EnumType":66 + * ])) + * __Pyx_globals['CMATCH'] = CIGAR_OPS.CMATCH + * __Pyx_globals['CINS'] = CIGAR_OPS.CINS # <<<<<<<<<<<<<< + * __Pyx_globals['CDEL'] = CIGAR_OPS.CDEL + * __Pyx_globals['CREF_SKIP'] = CIGAR_OPS.CREF_SKIP + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 66, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_CINS); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 66, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 66, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CINS, __pyx_t_13) < 0)) __PYX_ERR(1, 66, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + + /* "EnumType":67 + * __Pyx_globals['CMATCH'] = CIGAR_OPS.CMATCH + * __Pyx_globals['CINS'] = CIGAR_OPS.CINS + * __Pyx_globals['CDEL'] = CIGAR_OPS.CDEL # <<<<<<<<<<<<<< + * __Pyx_globals['CREF_SKIP'] = CIGAR_OPS.CREF_SKIP + * __Pyx_globals['CSOFT_CLIP'] = CIGAR_OPS.CSOFT_CLIP + */ + __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 67, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_CDEL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 67, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 67, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CDEL, __pyx_t_3) < 0)) __PYX_ERR(1, 67, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -static int __Pyx_modinit_type_init_code(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); - /*--- Type init code ---*/ - __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment = &__pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment; - __pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment.set_tag = (PyObject *(*)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag *__pyx_optional_args))__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_set_tag; - __pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment.get_tag = (PyObject *(*)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag *__pyx_optional_args))__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_get_tag; - __pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment.has_tag = (PyObject *(*)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch))__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_has_tag; - __pyx_vtable_5pysam_18libcalignedsegment_AlignedSegment.tostring = (PyObject *(*)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, __pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t, int __pyx_skip_dispatch))__pyx_f_5pysam_18libcalignedsegment_14AlignedSegment_tostring; - if (PyType_Ready(&__pyx_type_5pysam_18libcalignedsegment_AlignedSegment) < 0) __PYX_ERR(0, 647, __pyx_L1_error) - __pyx_type_5pysam_18libcalignedsegment_AlignedSegment.tp_print = 0; - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_18libcalignedsegment_AlignedSegment.tp_dictoffset && __pyx_type_5pysam_18libcalignedsegment_AlignedSegment.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type_5pysam_18libcalignedsegment_AlignedSegment.tp_getattro = __Pyx_PyObject_GenericGetAttr; - } - #if CYTHON_COMPILING_IN_CPYTHON - { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_18libcalignedsegment_AlignedSegment, "__str__"); if (unlikely(!wrapper)) __PYX_ERR(0, 647, __pyx_L1_error) - if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { - __pyx_wrapperbase_5pysam_18libcalignedsegment_14AlignedSegment_4__str__ = *((PyWrapperDescrObject *)wrapper)->d_base; - __pyx_wrapperbase_5pysam_18libcalignedsegment_14AlignedSegment_4__str__.doc = __pyx_doc_5pysam_18libcalignedsegment_14AlignedSegment_4__str__; - ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_18libcalignedsegment_14AlignedSegment_4__str__; + /* "EnumType":68 + * __Pyx_globals['CINS'] = CIGAR_OPS.CINS + * __Pyx_globals['CDEL'] = CIGAR_OPS.CDEL + * __Pyx_globals['CREF_SKIP'] = CIGAR_OPS.CREF_SKIP # <<<<<<<<<<<<<< + * __Pyx_globals['CSOFT_CLIP'] = CIGAR_OPS.CSOFT_CLIP + * __Pyx_globals['CHARD_CLIP'] = CIGAR_OPS.CHARD_CLIP + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 68, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_CREF_SKIP); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 68, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 68, __pyx_L1_error) } - } - #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_18libcalignedsegment_AlignedSegment.tp_dict, __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment) < 0) __PYX_ERR(0, 647, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "AlignedSegment", (PyObject *)&__pyx_type_5pysam_18libcalignedsegment_AlignedSegment) < 0) __PYX_ERR(0, 647, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_18libcalignedsegment_AlignedSegment) < 0) __PYX_ERR(0, 647, __pyx_L1_error) - __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment = &__pyx_type_5pysam_18libcalignedsegment_AlignedSegment; - if (PyType_Ready(&__pyx_type_5pysam_18libcalignedsegment_PileupColumn) < 0) __PYX_ERR(0, 2314, __pyx_L1_error) - __pyx_type_5pysam_18libcalignedsegment_PileupColumn.tp_print = 0; - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_18libcalignedsegment_PileupColumn.tp_dictoffset && __pyx_type_5pysam_18libcalignedsegment_PileupColumn.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type_5pysam_18libcalignedsegment_PileupColumn.tp_getattro = __Pyx_PyObject_GenericGetAttr; - } - if (PyObject_SetAttrString(__pyx_m, "PileupColumn", (PyObject *)&__pyx_type_5pysam_18libcalignedsegment_PileupColumn) < 0) __PYX_ERR(0, 2314, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_18libcalignedsegment_PileupColumn) < 0) __PYX_ERR(0, 2314, __pyx_L1_error) - __pyx_ptype_5pysam_18libcalignedsegment_PileupColumn = &__pyx_type_5pysam_18libcalignedsegment_PileupColumn; - if (PyType_Ready(&__pyx_type_5pysam_18libcalignedsegment_PileupRead) < 0) __PYX_ERR(0, 2398, __pyx_L1_error) - __pyx_type_5pysam_18libcalignedsegment_PileupRead.tp_print = 0; - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_18libcalignedsegment_PileupRead.tp_dictoffset && __pyx_type_5pysam_18libcalignedsegment_PileupRead.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type_5pysam_18libcalignedsegment_PileupRead.tp_getattro = __Pyx_PyObject_GenericGetAttr; - } - if (PyObject_SetAttrString(__pyx_m, "PileupRead", (PyObject *)&__pyx_type_5pysam_18libcalignedsegment_PileupRead) < 0) __PYX_ERR(0, 2398, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_18libcalignedsegment_PileupRead) < 0) __PYX_ERR(0, 2398, __pyx_L1_error) - __pyx_ptype_5pysam_18libcalignedsegment_PileupRead = &__pyx_type_5pysam_18libcalignedsegment_PileupRead; - if (PyType_Ready(&__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr) < 0) __PYX_ERR(0, 84, __pyx_L1_error) - __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr.tp_print = 0; - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr.tp_dictoffset && __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; - } - __pyx_ptype_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr = &__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct__genexpr; - if (PyType_Ready(&__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr) < 0) __PYX_ERR(0, 86, __pyx_L1_error) - __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr.tp_print = 0; - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr.tp_dictoffset && __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; - } - __pyx_ptype_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr = &__pyx_type_5pysam_18libcalignedsegment___pyx_scope_struct_1_genexpr; - __pyx_vtabptr_array = &__pyx_vtable_array; - __pyx_vtable_array.get_memview = (PyObject *(*)(struct __pyx_array_obj *))__pyx_array_get_memview; - if (PyType_Ready(&__pyx_type___pyx_array) < 0) __PYX_ERR(1, 104, __pyx_L1_error) - __pyx_type___pyx_array.tp_print = 0; - if (__Pyx_SetVtable(__pyx_type___pyx_array.tp_dict, __pyx_vtabptr_array) < 0) __PYX_ERR(1, 104, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_array) < 0) __PYX_ERR(1, 104, __pyx_L1_error) - __pyx_array_type = &__pyx_type___pyx_array; - if (PyType_Ready(&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(1, 278, __pyx_L1_error) - __pyx_type___pyx_MemviewEnum.tp_print = 0; - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_MemviewEnum.tp_dictoffset && __pyx_type___pyx_MemviewEnum.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type___pyx_MemviewEnum.tp_getattro = __Pyx_PyObject_GenericGetAttr; - } - if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(1, 278, __pyx_L1_error) - __pyx_MemviewEnum_type = &__pyx_type___pyx_MemviewEnum; - __pyx_vtabptr_memoryview = &__pyx_vtable_memoryview; - __pyx_vtable_memoryview.get_item_pointer = (char *(*)(struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_get_item_pointer; - __pyx_vtable_memoryview.is_slice = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_is_slice; - __pyx_vtable_memoryview.setitem_slice_assignment = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *, PyObject *))__pyx_memoryview_setitem_slice_assignment; - __pyx_vtable_memoryview.setitem_slice_assign_scalar = (PyObject *(*)(struct __pyx_memoryview_obj *, struct __pyx_memoryview_obj *, PyObject *))__pyx_memoryview_setitem_slice_assign_scalar; - __pyx_vtable_memoryview.setitem_indexed = (PyObject *(*)(struct __pyx_memoryview_obj *, PyObject *, PyObject *))__pyx_memoryview_setitem_indexed; - __pyx_vtable_memoryview.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryview_convert_item_to_object; - __pyx_vtable_memoryview.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryview_assign_item_from_object; - if (PyType_Ready(&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(1, 329, __pyx_L1_error) - __pyx_type___pyx_memoryview.tp_print = 0; - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryview.tp_dictoffset && __pyx_type___pyx_memoryview.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type___pyx_memoryview.tp_getattro = __Pyx_PyObject_GenericGetAttr; - } - if (__Pyx_SetVtable(__pyx_type___pyx_memoryview.tp_dict, __pyx_vtabptr_memoryview) < 0) __PYX_ERR(1, 329, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(1, 329, __pyx_L1_error) - __pyx_memoryview_type = &__pyx_type___pyx_memoryview; - __pyx_vtabptr__memoryviewslice = &__pyx_vtable__memoryviewslice; - __pyx_vtable__memoryviewslice.__pyx_base = *__pyx_vtabptr_memoryview; - __pyx_vtable__memoryviewslice.__pyx_base.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryviewslice_convert_item_to_object; - __pyx_vtable__memoryviewslice.__pyx_base.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryviewslice_assign_item_from_object; - __pyx_type___pyx_memoryviewslice.tp_base = __pyx_memoryview_type; - if (PyType_Ready(&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(1, 960, __pyx_L1_error) - __pyx_type___pyx_memoryviewslice.tp_print = 0; - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryviewslice.tp_dictoffset && __pyx_type___pyx_memoryviewslice.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type___pyx_memoryviewslice.tp_getattro = __Pyx_PyObject_GenericGetAttr; - } - if (__Pyx_SetVtable(__pyx_type___pyx_memoryviewslice.tp_dict, __pyx_vtabptr__memoryviewslice) < 0) __PYX_ERR(1, 960, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(1, 960, __pyx_L1_error) - __pyx_memoryviewslice_type = &__pyx_type___pyx_memoryviewslice; - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CREF_SKIP, __pyx_t_13) < 0)) __PYX_ERR(1, 68, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + + /* "EnumType":69 + * __Pyx_globals['CDEL'] = CIGAR_OPS.CDEL + * __Pyx_globals['CREF_SKIP'] = CIGAR_OPS.CREF_SKIP + * __Pyx_globals['CSOFT_CLIP'] = CIGAR_OPS.CSOFT_CLIP # <<<<<<<<<<<<<< + * __Pyx_globals['CHARD_CLIP'] = CIGAR_OPS.CHARD_CLIP + * __Pyx_globals['CPAD'] = CIGAR_OPS.CPAD + */ + __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 69, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_CSOFT_CLIP); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 69, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 69, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CSOFT_CLIP, __pyx_t_3) < 0)) __PYX_ERR(1, 69, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -static int __Pyx_modinit_type_import_code(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); - /*--- Type import code ---*/ - __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(3, 1904, __pyx_L1_error) - __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(3, 1904, __pyx_L1_error) - __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", - #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 - sizeof(PyTypeObject), - #else - sizeof(PyHeapTypeObject), - #endif - 0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) __PYX_ERR(4, 9, __pyx_L1_error) - __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) __PYX_ERR(5, 8, __pyx_L1_error) - __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) __PYX_ERR(6, 15, __pyx_L1_error) - __pyx_ptype_7cpython_5array_array = __Pyx_ImportType("array", "array", sizeof(arrayobject), 0); if (unlikely(!__pyx_ptype_7cpython_5array_array)) __PYX_ERR(2, 58, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_FastaFile = __Pyx_ImportType("pysam.libcfaidx", "FastaFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastaFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastaFile)) __PYX_ERR(7, 37, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_FastaFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastaFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastaFile)) __PYX_ERR(7, 37, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_FastqProxy = __Pyx_ImportType("pysam.libcfaidx", "FastqProxy", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastqProxy)) __PYX_ERR(7, 45, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_FastqProxy = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy)) __PYX_ERR(7, 45, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy = __Pyx_ImportType("pysam.libcfaidx", "PersistentFastqProxy", sizeof(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy)) __PYX_ERR(7, 51, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy = (struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy)) __PYX_ERR(7, 51, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_FastxFile = __Pyx_ImportType("pysam.libcfaidx", "FastxFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(7, 60, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_FastxFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(7, 60, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_FastqFile = __Pyx_ImportType("pysam.libcfaidx", "FastqFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(7, 72, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_FastqFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(7, 72, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_Fastafile = __Pyx_ImportType("pysam.libcfaidx", "Fastafile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_Fastafile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(7, 77, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_Fastafile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_Fastafile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(7, 77, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile = __Pyx_ImportType("pysam.libcalignmentfile", "AlignmentFile", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile)) __PYX_ERR(8, 39, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile)) __PYX_ERR(8, 39, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_PileupColumn = __Pyx_ImportType("pysam.libcalignmentfile", "PileupColumn", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_PileupColumn), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_PileupColumn)) __PYX_ERR(8, 57, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_PileupRead = __Pyx_ImportType("pysam.libcalignmentfile", "PileupRead", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_PileupRead), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_PileupRead)) __PYX_ERR(8, 64, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRow", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow)) __PYX_ERR(8, 75, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowRegion", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion)) __PYX_ERR(8, 84, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion)) __PYX_ERR(8, 84, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowHead", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead)) __PYX_ERR(8, 89, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead)) __PYX_ERR(8, 89, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowAll", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll)) __PYX_ERR(8, 95, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll)) __PYX_ERR(8, 95, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowAllRefs", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs)) __PYX_ERR(8, 100, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowSelection", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection)) __PYX_ERR(8, 105, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection)) __PYX_ERR(8, 105, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorColumn", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn)) __PYX_ERR(8, 112, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn)) __PYX_ERR(8, 112, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorColumnRegion", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion)) __PYX_ERR(8, 141, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion)) __PYX_ERR(8, 141, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorColumnAllRefs", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs)) __PYX_ERR(8, 147, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs)) __PYX_ERR(8, 147, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads = __Pyx_ImportType("pysam.libcalignmentfile", "IndexedReads", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads)) __PYX_ERR(8, 151, __pyx_L1_error) - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} + /* "EnumType":70 + * __Pyx_globals['CREF_SKIP'] = CIGAR_OPS.CREF_SKIP + * __Pyx_globals['CSOFT_CLIP'] = CIGAR_OPS.CSOFT_CLIP + * __Pyx_globals['CHARD_CLIP'] = CIGAR_OPS.CHARD_CLIP # <<<<<<<<<<<<<< + * __Pyx_globals['CPAD'] = CIGAR_OPS.CPAD + * __Pyx_globals['CEQUAL'] = CIGAR_OPS.CEQUAL + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 70, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_CHARD_CLIP); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 70, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 70, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CHARD_CLIP, __pyx_t_13) < 0)) __PYX_ERR(1, 70, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + + /* "EnumType":71 + * __Pyx_globals['CSOFT_CLIP'] = CIGAR_OPS.CSOFT_CLIP + * __Pyx_globals['CHARD_CLIP'] = CIGAR_OPS.CHARD_CLIP + * __Pyx_globals['CPAD'] = CIGAR_OPS.CPAD # <<<<<<<<<<<<<< + * __Pyx_globals['CEQUAL'] = CIGAR_OPS.CEQUAL + * __Pyx_globals['CDIFF'] = CIGAR_OPS.CDIFF + */ + __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 71, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_CPAD); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 71, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 71, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CPAD, __pyx_t_3) < 0)) __PYX_ERR(1, 71, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -static int __Pyx_modinit_variable_import_code(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); - /*--- Variable import code ---*/ - __Pyx_RefNannyFinishContext(); - return 0; -} + /* "EnumType":72 + * __Pyx_globals['CHARD_CLIP'] = CIGAR_OPS.CHARD_CLIP + * __Pyx_globals['CPAD'] = CIGAR_OPS.CPAD + * __Pyx_globals['CEQUAL'] = CIGAR_OPS.CEQUAL # <<<<<<<<<<<<<< + * __Pyx_globals['CDIFF'] = CIGAR_OPS.CDIFF + * __Pyx_globals['CBACK'] = CIGAR_OPS.CBACK + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 72, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_CEQUAL); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 72, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 72, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CEQUAL, __pyx_t_13) < 0)) __PYX_ERR(1, 72, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + + /* "EnumType":73 + * __Pyx_globals['CPAD'] = CIGAR_OPS.CPAD + * __Pyx_globals['CEQUAL'] = CIGAR_OPS.CEQUAL + * __Pyx_globals['CDIFF'] = CIGAR_OPS.CDIFF # <<<<<<<<<<<<<< + * __Pyx_globals['CBACK'] = CIGAR_OPS.CBACK + * else: + */ + __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 73, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_CDIFF); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 73, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 73, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CDIFF, __pyx_t_3) < 0)) __PYX_ERR(1, 73, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; -static int __Pyx_modinit_function_import_code(void) { - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); - /*--- Function import code ---*/ - __pyx_t_1 = __Pyx_ImportModule("pysam.libcutils"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_1, "qualitystring_to_array", (void (**)(void))&__pyx_f_5pysam_9libcutils_qualitystring_to_array, "arrayobject *(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_1, "array_to_qualitystring", (void (**)(void))&__pyx_f_5pysam_9libcutils_array_to_qualitystring, "PyObject *(arrayobject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcutils_array_to_qualitystring *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_1, "qualities_to_qualitystring", (void (**)(void))&__pyx_f_5pysam_9libcutils_qualities_to_qualitystring, "PyObject *(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcutils_qualities_to_qualitystring *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_1, "charptr_to_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_charptr_to_str, "PyObject *(char const *, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_1, "charptr_to_bytes", (void (**)(void))&__pyx_f_5pysam_9libcutils_charptr_to_bytes, "PyObject *(char const *, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_bytes *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_1, "force_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_str, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_1, "force_bytes", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_bytes, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_bytes *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - Py_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_RefNannyFinishContext(); - return -1; -} + /* "EnumType":74 + * __Pyx_globals['CEQUAL'] = CIGAR_OPS.CEQUAL + * __Pyx_globals['CDIFF'] = CIGAR_OPS.CDIFF + * __Pyx_globals['CBACK'] = CIGAR_OPS.CBACK # <<<<<<<<<<<<<< + * else: + * class CIGAR_OPS(__Pyx_EnumBase): + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 74, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_CBACK); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 74, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 74, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CBACK, __pyx_t_13) < 0)) __PYX_ERR(1, 74, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + /* "EnumType":51 + * + * cdef dict __Pyx_globals = globals() + * if PY_VERSION_HEX >= 0x03040000: # <<<<<<<<<<<<<< + * + * CIGAR_OPS = __Pyx_EnumBase('CIGAR_OPS', __Pyx_OrderedDict([ + */ + goto __pyx_L5; + } -#if PY_MAJOR_VERSION < 3 -#ifdef CYTHON_NO_PYINIT_EXPORT -#define __Pyx_PyMODINIT_FUNC void -#else -#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC -#endif -#else -#ifdef CYTHON_NO_PYINIT_EXPORT -#define __Pyx_PyMODINIT_FUNC PyObject * -#else -#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC -#endif -#endif -#ifndef CYTHON_SMALL_CODE -#if defined(__clang__) - #define CYTHON_SMALL_CODE -#elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4))) - #define CYTHON_SMALL_CODE __attribute__((optimize("Os"))) -#else - #define CYTHON_SMALL_CODE -#endif -#endif + /* "EnumType":76 + * __Pyx_globals['CBACK'] = CIGAR_OPS.CBACK + * else: + * class CIGAR_OPS(__Pyx_EnumBase): # <<<<<<<<<<<<<< + * pass + * __Pyx_globals['CMATCH'] = CIGAR_OPS(CMATCH, 'CMATCH') + */ + /*else*/ { + __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 76, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_INCREF(__Pyx_EnumBase); + __Pyx_GIVEREF(__Pyx_EnumBase); + PyTuple_SET_ITEM(__pyx_t_13, 0, __Pyx_EnumBase); + __pyx_t_3 = __Pyx_CalculateMetaclass(NULL, __pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 76, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = __Pyx_Py3MetaclassPrepare(__pyx_t_3, __pyx_t_13, __pyx_n_s_CIGAR_OPS, __pyx_n_s_CIGAR_OPS, (PyObject *) NULL, __pyx_n_s_EnumType, (PyObject *) NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 76, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_11 = __Pyx_Py3ClassCreate(__pyx_t_3, __pyx_n_s_CIGAR_OPS, __pyx_t_13, __pyx_t_12, NULL, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 76, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR_OPS, __pyx_t_11) < 0) __PYX_ERR(1, 76, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + + /* "EnumType":78 + * class CIGAR_OPS(__Pyx_EnumBase): + * pass + * __Pyx_globals['CMATCH'] = CIGAR_OPS(CMATCH, 'CMATCH') # <<<<<<<<<<<<<< + * __Pyx_globals['CINS'] = CIGAR_OPS(CINS, 'CINS') + * __Pyx_globals['CDEL'] = CIGAR_OPS(CDEL, 'CDEL') + */ + __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 78, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CMATCH); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 78, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 78, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_n_s_CMATCH); + __Pyx_GIVEREF(__pyx_n_s_CMATCH); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_n_s_CMATCH); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 78, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 78, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CMATCH, __pyx_t_3) < 0)) __PYX_ERR(1, 78, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + /* "EnumType":79 + * pass + * __Pyx_globals['CMATCH'] = CIGAR_OPS(CMATCH, 'CMATCH') + * __Pyx_globals['CINS'] = CIGAR_OPS(CINS, 'CINS') # <<<<<<<<<<<<<< + * __Pyx_globals['CDEL'] = CIGAR_OPS(CDEL, 'CDEL') + * __Pyx_globals['CREF_SKIP'] = CIGAR_OPS(CREF_SKIP, 'CREF_SKIP') + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 79, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CINS); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 79, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 79, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); + __Pyx_INCREF(__pyx_n_s_CINS); + __Pyx_GIVEREF(__pyx_n_s_CINS); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_n_s_CINS); + __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 79, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 79, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CINS, __pyx_t_12) < 0)) __PYX_ERR(1, 79, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; -#if PY_MAJOR_VERSION < 3 -__Pyx_PyMODINIT_FUNC initlibcalignedsegment(void) CYTHON_SMALL_CODE; /*proto*/ -__Pyx_PyMODINIT_FUNC initlibcalignedsegment(void) -#else -__Pyx_PyMODINIT_FUNC PyInit_libcalignedsegment(void) CYTHON_SMALL_CODE; /*proto*/ -__Pyx_PyMODINIT_FUNC PyInit_libcalignedsegment(void) -#if CYTHON_PEP489_MULTI_PHASE_INIT -{ - return PyModuleDef_Init(&__pyx_moduledef); -} -static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) { - PyObject *value = PyObject_GetAttrString(spec, from_name); - int result = 0; - if (likely(value)) { - result = PyDict_SetItemString(moddict, to_name, value); - Py_DECREF(value); - } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - } else { - result = -1; + /* "EnumType":80 + * __Pyx_globals['CMATCH'] = CIGAR_OPS(CMATCH, 'CMATCH') + * __Pyx_globals['CINS'] = CIGAR_OPS(CINS, 'CINS') + * __Pyx_globals['CDEL'] = CIGAR_OPS(CDEL, 'CDEL') # <<<<<<<<<<<<<< + * __Pyx_globals['CREF_SKIP'] = CIGAR_OPS(CREF_SKIP, 'CREF_SKIP') + * __Pyx_globals['CSOFT_CLIP'] = CIGAR_OPS(CSOFT_CLIP, 'CSOFT_CLIP') + */ + __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 80, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CDEL); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 80, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 80, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_13); + __Pyx_INCREF(__pyx_n_s_CDEL); + __Pyx_GIVEREF(__pyx_n_s_CDEL); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_CDEL); + __pyx_t_13 = 0; + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_3, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 80, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 80, __pyx_L1_error) } - return result; -} -static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { - PyObject *module = NULL, *moddict, *modname; - if (__pyx_m) - return __Pyx_NewRef(__pyx_m); - modname = PyObject_GetAttrString(spec, "name"); - if (unlikely(!modname)) goto bad; - module = PyModule_NewObject(modname); - Py_DECREF(modname); - if (unlikely(!module)) goto bad; - moddict = PyModule_GetDict(module); - if (unlikely(!moddict)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad; - return module; -bad: - Py_XDECREF(module); - return NULL; -} + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CDEL, __pyx_t_13) < 0)) __PYX_ERR(1, 80, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + + /* "EnumType":81 + * __Pyx_globals['CINS'] = CIGAR_OPS(CINS, 'CINS') + * __Pyx_globals['CDEL'] = CIGAR_OPS(CDEL, 'CDEL') + * __Pyx_globals['CREF_SKIP'] = CIGAR_OPS(CREF_SKIP, 'CREF_SKIP') # <<<<<<<<<<<<<< + * __Pyx_globals['CSOFT_CLIP'] = CIGAR_OPS(CSOFT_CLIP, 'CSOFT_CLIP') + * __Pyx_globals['CHARD_CLIP'] = CIGAR_OPS(CHARD_CLIP, 'CHARD_CLIP') + */ + __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 81, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CREF_SKIP); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 81, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 81, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_n_s_CREF_SKIP); + __Pyx_GIVEREF(__pyx_n_s_CREF_SKIP); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_n_s_CREF_SKIP); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 81, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 81, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CREF_SKIP, __pyx_t_3) < 0)) __PYX_ERR(1, 81, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + /* "EnumType":82 + * __Pyx_globals['CDEL'] = CIGAR_OPS(CDEL, 'CDEL') + * __Pyx_globals['CREF_SKIP'] = CIGAR_OPS(CREF_SKIP, 'CREF_SKIP') + * __Pyx_globals['CSOFT_CLIP'] = CIGAR_OPS(CSOFT_CLIP, 'CSOFT_CLIP') # <<<<<<<<<<<<<< + * __Pyx_globals['CHARD_CLIP'] = CIGAR_OPS(CHARD_CLIP, 'CHARD_CLIP') + * __Pyx_globals['CPAD'] = CIGAR_OPS(CPAD, 'CPAD') + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 82, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CSOFT_CLIP); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 82, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 82, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); + __Pyx_INCREF(__pyx_n_s_CSOFT_CLIP); + __Pyx_GIVEREF(__pyx_n_s_CSOFT_CLIP); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_n_s_CSOFT_CLIP); + __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 82, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 82, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CSOFT_CLIP, __pyx_t_12) < 0)) __PYX_ERR(1, 82, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; -static int __pyx_pymod_exec_libcalignedsegment(PyObject *__pyx_pyinit_module) -#endif -#endif -{ - __Pyx_TraceDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - static PyThread_type_lock __pyx_t_4[8]; - __Pyx_RefNannyDeclarations - #if CYTHON_PEP489_MULTI_PHASE_INIT - if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0; - #elif PY_MAJOR_VERSION >= 3 - if (__pyx_m) return __Pyx_NewRef(__pyx_m); - #endif - #if CYTHON_REFNANNY -__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); -if (!__Pyx_RefNanny) { - PyErr_Clear(); - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); - if (!__Pyx_RefNanny) - Py_FatalError("failed to import 'refnanny' module"); -} -#endif - __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_libcalignedsegment(void)", 0); - if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) - #ifdef __Pyx_CyFunction_USED - if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - #ifdef __Pyx_FusedFunction_USED - if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - #ifdef __Pyx_Coroutine_USED - if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - #ifdef __Pyx_Generator_USED - if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - #ifdef __Pyx_AsyncGen_USED - if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - #ifdef __Pyx_StopAsyncIteration_USED - if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - /*--- Library function declarations ---*/ - /*--- Threads initialization code ---*/ - #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS - #ifdef WITH_THREAD /* Python build with threading support? */ - PyEval_InitThreads(); - #endif - #endif - /*--- Module creation code ---*/ - #if CYTHON_PEP489_MULTI_PHASE_INIT - __pyx_m = __pyx_pyinit_module; - Py_INCREF(__pyx_m); - #else - #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4("libcalignedsegment", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); - #else - __pyx_m = PyModule_Create(&__pyx_moduledef); - #endif - if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) - Py_INCREF(__pyx_d); - __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) - #if CYTHON_COMPILING_IN_PYPY - Py_INCREF(__pyx_b); - #endif - if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); - /*--- Initialize various global constants etc. ---*/ - if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) - if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - if (__pyx_module_is_main_pysam__libcalignedsegment) { - if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - } - #if PY_MAJOR_VERSION >= 3 - { - PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) - if (!PyDict_GetItemString(modules, "pysam.libcalignedsegment")) { - if (unlikely(PyDict_SetItemString(modules, "pysam.libcalignedsegment", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) + /* "EnumType":83 + * __Pyx_globals['CREF_SKIP'] = CIGAR_OPS(CREF_SKIP, 'CREF_SKIP') + * __Pyx_globals['CSOFT_CLIP'] = CIGAR_OPS(CSOFT_CLIP, 'CSOFT_CLIP') + * __Pyx_globals['CHARD_CLIP'] = CIGAR_OPS(CHARD_CLIP, 'CHARD_CLIP') # <<<<<<<<<<<<<< + * __Pyx_globals['CPAD'] = CIGAR_OPS(CPAD, 'CPAD') + * __Pyx_globals['CEQUAL'] = CIGAR_OPS(CEQUAL, 'CEQUAL') + */ + __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 83, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CHARD_CLIP); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 83, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 83, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_13); + __Pyx_INCREF(__pyx_n_s_CHARD_CLIP); + __Pyx_GIVEREF(__pyx_n_s_CHARD_CLIP); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_CHARD_CLIP); + __pyx_t_13 = 0; + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_3, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 83, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 83, __pyx_L1_error) } - } - #endif - /*--- Builtin init code ---*/ - if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - /*--- Constants init code ---*/ - if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - /*--- Global type/function init code ---*/ - (void)__Pyx_modinit_global_init_code(); - (void)__Pyx_modinit_variable_export_code(); - if (unlikely(__Pyx_modinit_function_export_code() != 0)) goto __pyx_L1_error; - if (unlikely(__Pyx_modinit_type_init_code() != 0)) goto __pyx_L1_error; - if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error; - (void)__Pyx_modinit_variable_import_code(); - if (unlikely(__Pyx_modinit_function_import_code() != 0)) goto __pyx_L1_error; - /*--- Execution code ---*/ - #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) - if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - #endif - __Pyx_TraceCall("__Pyx_PyMODINIT_FUNC PyInit_libcalignedsegment(void)", __pyx_f[0], 1, 0, __PYX_ERR(0, 1, __pyx_L1_error)); + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CHARD_CLIP, __pyx_t_13) < 0)) __PYX_ERR(1, 83, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + + /* "EnumType":84 + * __Pyx_globals['CSOFT_CLIP'] = CIGAR_OPS(CSOFT_CLIP, 'CSOFT_CLIP') + * __Pyx_globals['CHARD_CLIP'] = CIGAR_OPS(CHARD_CLIP, 'CHARD_CLIP') + * __Pyx_globals['CPAD'] = CIGAR_OPS(CPAD, 'CPAD') # <<<<<<<<<<<<<< + * __Pyx_globals['CEQUAL'] = CIGAR_OPS(CEQUAL, 'CEQUAL') + * __Pyx_globals['CDIFF'] = CIGAR_OPS(CDIFF, 'CDIFF') + */ + __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 84, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CPAD); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 84, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 84, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_n_s_CPAD); + __Pyx_GIVEREF(__pyx_n_s_CPAD); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_n_s_CPAD); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 84, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 84, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CPAD, __pyx_t_3) < 0)) __PYX_ERR(1, 84, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":56 - * # - * ############################################################################### - * import re # <<<<<<<<<<<<<< - * import array - * import ctypes + /* "EnumType":85 + * __Pyx_globals['CHARD_CLIP'] = CIGAR_OPS(CHARD_CLIP, 'CHARD_CLIP') + * __Pyx_globals['CPAD'] = CIGAR_OPS(CPAD, 'CPAD') + * __Pyx_globals['CEQUAL'] = CIGAR_OPS(CEQUAL, 'CEQUAL') # <<<<<<<<<<<<<< + * __Pyx_globals['CDIFF'] = CIGAR_OPS(CDIFF, 'CDIFF') + * __Pyx_globals['CBACK'] = CIGAR_OPS(CBACK, 'CBACK') */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_re, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_1) < 0) __PYX_ERR(0, 56, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 85, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CEQUAL); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 85, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 85, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); + __Pyx_INCREF(__pyx_n_s_CEQUAL); + __Pyx_GIVEREF(__pyx_n_s_CEQUAL); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_n_s_CEQUAL); + __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 85, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 85, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CEQUAL, __pyx_t_12) < 0)) __PYX_ERR(1, 85, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - /* "pysam/libcalignedsegment.pyx":57 - * ############################################################################### - * import re - * import array # <<<<<<<<<<<<<< - * import ctypes - * import struct + /* "EnumType":86 + * __Pyx_globals['CPAD'] = CIGAR_OPS(CPAD, 'CPAD') + * __Pyx_globals['CEQUAL'] = CIGAR_OPS(CEQUAL, 'CEQUAL') + * __Pyx_globals['CDIFF'] = CIGAR_OPS(CDIFF, 'CDIFF') # <<<<<<<<<<<<<< + * __Pyx_globals['CBACK'] = CIGAR_OPS(CBACK, 'CBACK') + * */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_array, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_array, __pyx_t_1) < 0) __PYX_ERR(0, 57, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 86, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CDIFF); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 86, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 86, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_13); + __Pyx_INCREF(__pyx_n_s_CDIFF); + __Pyx_GIVEREF(__pyx_n_s_CDIFF); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_CDIFF); + __pyx_t_13 = 0; + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_3, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 86, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 86, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CDIFF, __pyx_t_13) < 0)) __PYX_ERR(1, 86, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - /* "pysam/libcalignedsegment.pyx":58 - * import re - * import array - * import ctypes # <<<<<<<<<<<<<< - * import struct + /* "EnumType":87 + * __Pyx_globals['CEQUAL'] = CIGAR_OPS(CEQUAL, 'CEQUAL') + * __Pyx_globals['CDIFF'] = CIGAR_OPS(CDIFF, 'CDIFF') + * __Pyx_globals['CBACK'] = CIGAR_OPS(CBACK, 'CBACK') # <<<<<<<<<<<<<< * */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_ctypes, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_ctypes, __pyx_t_1) < 0) __PYX_ERR(0, 58, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_OPS); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 87, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(__pyx_e_5pysam_18libcalignedsegment_CBACK); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 87, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 87, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_n_s_CBACK); + __Pyx_GIVEREF(__pyx_n_s_CBACK); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_n_s_CBACK); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 87, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 87, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_CBACK, __pyx_t_3) < 0)) __PYX_ERR(1, 87, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_L5:; - /* "pysam/libcalignedsegment.pyx":59 - * import array - * import ctypes - * import struct # <<<<<<<<<<<<<< + /* "EnumType":50 + * + * + * cdef dict __Pyx_globals = globals() # <<<<<<<<<<<<<< + * if PY_VERSION_HEX >= 0x03040000: * - * cimport cython */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_struct, __pyx_t_1) < 0) __PYX_ERR(0, 59, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_Globals(); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 50, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(PyDict_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(1, 50, __pyx_L1_error) + __Pyx_XGOTREF(__Pyx_globals); + __Pyx_DECREF_SET(__Pyx_globals, ((PyObject*)__pyx_t_3)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":74 + /* "EnumType":51 * - * # Constants for binary tag conversion - * cdef char * htslib_types = 'cCsSiIf' # <<<<<<<<<<<<<< - * cdef char * parray_types = 'bBhHiIf' + * cdef dict __Pyx_globals = globals() + * if PY_VERSION_HEX >= 0x03040000: # <<<<<<<<<<<<<< * + * SAM_FLAGS = __Pyx_EnumBase('SAM_FLAGS', __Pyx_OrderedDict([ */ - __pyx_v_5pysam_18libcalignedsegment_htslib_types = ((char *)"cCsSiIf"); + __pyx_t_2 = ((PY_VERSION_HEX >= 0x03040000) != 0); + if (__pyx_t_2) { - /* "pysam/libcalignedsegment.pyx":75 - * # Constants for binary tag conversion - * cdef char * htslib_types = 'cCsSiIf' - * cdef char * parray_types = 'bBhHiIf' # <<<<<<<<<<<<<< + /* "EnumType":54 * - * # translation tables + * SAM_FLAGS = __Pyx_EnumBase('SAM_FLAGS', __Pyx_OrderedDict([ + * ('FPAIRED', FPAIRED), # <<<<<<<<<<<<<< + * ('FPROPER_PAIR', FPROPER_PAIR), + * ('FUNMAP', FUNMAP), */ - __pyx_v_5pysam_18libcalignedsegment_parray_types = ((char *)"bBhHiIf"); + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FPAIRED); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 54, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 54, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(__pyx_n_s_FPAIRED); + __Pyx_GIVEREF(__pyx_n_s_FPAIRED); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_n_s_FPAIRED); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":80 - * - * # cigar code to character and vice versa - * cdef char* CODE2CIGAR= "MIDNSHP=XB" # <<<<<<<<<<<<<< - * cdef int NCIGAR_CODES = 10 - * + /* "EnumType":55 + * SAM_FLAGS = __Pyx_EnumBase('SAM_FLAGS', __Pyx_OrderedDict([ + * ('FPAIRED', FPAIRED), + * ('FPROPER_PAIR', FPROPER_PAIR), # <<<<<<<<<<<<<< + * ('FUNMAP', FUNMAP), + * ('FMUNMAP', FMUNMAP), */ - __pyx_v_5pysam_18libcalignedsegment_CODE2CIGAR = ((char *)"MIDNSHP=XB"); + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FPROPER_PAIR); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 55, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 55, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_INCREF(__pyx_n_s_FPROPER_PAIR); + __Pyx_GIVEREF(__pyx_n_s_FPROPER_PAIR); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_n_s_FPROPER_PAIR); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":81 - * # cigar code to character and vice versa - * cdef char* CODE2CIGAR= "MIDNSHP=XB" - * cdef int NCIGAR_CODES = 10 # <<<<<<<<<<<<<< - * - * if PY_MAJOR_VERSION >= 3: + /* "EnumType":56 + * ('FPAIRED', FPAIRED), + * ('FPROPER_PAIR', FPROPER_PAIR), + * ('FUNMAP', FUNMAP), # <<<<<<<<<<<<<< + * ('FMUNMAP', FMUNMAP), + * ('FREVERSE', FREVERSE), */ - __pyx_v_5pysam_18libcalignedsegment_NCIGAR_CODES = 10; + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FUNMAP); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 56, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 56, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_n_s_FUNMAP); + __Pyx_GIVEREF(__pyx_n_s_FUNMAP); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_n_s_FUNMAP); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":83 - * cdef int NCIGAR_CODES = 10 - * - * if PY_MAJOR_VERSION >= 3: # <<<<<<<<<<<<<< - * CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) - * else: + /* "EnumType":57 + * ('FPROPER_PAIR', FPROPER_PAIR), + * ('FUNMAP', FUNMAP), + * ('FMUNMAP', FMUNMAP), # <<<<<<<<<<<<<< + * ('FREVERSE', FREVERSE), + * ('FMREVERSE', FMREVERSE), */ - __pyx_t_2 = ((PY_MAJOR_VERSION >= 3) != 0); - if (__pyx_t_2) { + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FMUNMAP); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 57, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 57, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_n_s_FMUNMAP); + __Pyx_GIVEREF(__pyx_n_s_FMUNMAP); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_n_s_FMUNMAP); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":84 - * - * if PY_MAJOR_VERSION >= 3: - * CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) # <<<<<<<<<<<<<< - * else: - * CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR)) + /* "EnumType":58 + * ('FUNMAP', FUNMAP), + * ('FMUNMAP', FMUNMAP), + * ('FREVERSE', FREVERSE), # <<<<<<<<<<<<<< + * ('FMREVERSE', FMREVERSE), + * ('FREAD1', FREAD1), */ - __pyx_t_1 = __pyx_pf_5pysam_18libcalignedsegment_genexpr(NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 84, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 84, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FREVERSE); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 58, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR2CODE, __pyx_t_3) < 0) __PYX_ERR(0, 84, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 58, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_INCREF(__pyx_n_s_FREVERSE); + __Pyx_GIVEREF(__pyx_n_s_FREVERSE); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_n_s_FREVERSE); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":83 - * cdef int NCIGAR_CODES = 10 - * - * if PY_MAJOR_VERSION >= 3: # <<<<<<<<<<<<<< - * CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) - * else: + /* "EnumType":59 + * ('FMUNMAP', FMUNMAP), + * ('FREVERSE', FREVERSE), + * ('FMREVERSE', FMREVERSE), # <<<<<<<<<<<<<< + * ('FREAD1', FREAD1), + * ('FREAD2', FREAD2), */ - goto __pyx_L2; - } + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FMREVERSE); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 59, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 59, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_n_s_FMREVERSE); + __Pyx_GIVEREF(__pyx_n_s_FMREVERSE); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_n_s_FMREVERSE); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":86 - * CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) - * else: - * CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR)) # <<<<<<<<<<<<<< - * - * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=XB])") + /* "EnumType":60 + * ('FREVERSE', FREVERSE), + * ('FMREVERSE', FMREVERSE), + * ('FREAD1', FREAD1), # <<<<<<<<<<<<<< + * ('FREAD2', FREAD2), + * ('FSECONDARY', FSECONDARY), */ - /*else*/ { - __pyx_t_3 = __pyx_pf_5pysam_18libcalignedsegment_3genexpr(NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FREAD1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 60, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR2CODE, __pyx_t_1) < 0) __PYX_ERR(0, 86, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __pyx_L2:; + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_n_s_FREAD1); + __Pyx_GIVEREF(__pyx_n_s_FREAD1); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_FREAD1); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":88 - * CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR)) - * - * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=XB])") # <<<<<<<<<<<<<< - * - * ##################################################################### + /* "EnumType":61 + * ('FMREVERSE', FMREVERSE), + * ('FREAD1', FREAD1), + * ('FREAD2', FREAD2), # <<<<<<<<<<<<<< + * ('FSECONDARY', FSECONDARY), + * ('FQCFAIL', FQCFAIL), */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_compile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 88, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__61, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR_REGEX, __pyx_t_1) < 0) __PYX_ERR(0, 88, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FREAD2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 61, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 61, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_n_s_FREAD2); + __Pyx_GIVEREF(__pyx_n_s_FREAD2); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_FREAD2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":2480 - * return self._is_refskip - * - * __all__ = [ # <<<<<<<<<<<<<< - * "AlignedSegment", - * "PileupColumn", + /* "EnumType":62 + * ('FREAD1', FREAD1), + * ('FREAD2', FREAD2), + * ('FSECONDARY', FSECONDARY), # <<<<<<<<<<<<<< + * ('FQCFAIL', FQCFAIL), + * ('FDUP', FDUP), */ - __pyx_t_1 = PyList_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2480, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_AlignedSegment); - __Pyx_GIVEREF(__pyx_n_s_AlignedSegment); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_AlignedSegment); - __Pyx_INCREF(__pyx_n_s_PileupColumn); - __Pyx_GIVEREF(__pyx_n_s_PileupColumn); - PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_PileupColumn); - __Pyx_INCREF(__pyx_n_s_PileupRead); - __Pyx_GIVEREF(__pyx_n_s_PileupRead); - PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_PileupRead); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 2480, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FSECONDARY); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 62, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 62, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_n_s_FSECONDARY); + __Pyx_GIVEREF(__pyx_n_s_FSECONDARY); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_FSECONDARY); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __pyx_t_3 = 0; - /* "(tree fragment)":1 - * def __pyx_unpickle_PileupRead(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< - * if __pyx_checksum != 0xbbc0b95: - * from pickle import PickleError as __pyx_PickleError + /* "EnumType":63 + * ('FREAD2', FREAD2), + * ('FSECONDARY', FSECONDARY), + * ('FQCFAIL', FQCFAIL), # <<<<<<<<<<<<<< + * ('FDUP', FDUP), + * ('FSUPPLEMENTARY', FSUPPLEMENTARY), */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_18libcalignedsegment_7__pyx_unpickle_PileupRead, NULL, __pyx_n_s_pysam_libcalignedsegment); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_PileupRead, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FQCFAIL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_FQCFAIL); + __Pyx_GIVEREF(__pyx_n_s_FQCFAIL); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_FQCFAIL); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignedsegment.pyx":1 - * # cython: embedsignature=True # <<<<<<<<<<<<<< - * # cython: profile=True - * ############################################################################### + /* "EnumType":64 + * ('FSECONDARY', FSECONDARY), + * ('FQCFAIL', FQCFAIL), + * ('FDUP', FDUP), # <<<<<<<<<<<<<< + * ('FSUPPLEMENTARY', FSUPPLEMENTARY), + * ])) */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FDUP); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_INCREF(__pyx_n_s_FDUP); + __Pyx_GIVEREF(__pyx_n_s_FDUP); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_n_s_FDUP); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_3); + __pyx_t_3 = 0; - /* "View.MemoryView":208 - * info.obj = self - * - * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< - * - * def __dealloc__(array self): + /* "EnumType":65 + * ('FQCFAIL', FQCFAIL), + * ('FDUP', FDUP), + * ('FSUPPLEMENTARY', FSUPPLEMENTARY), # <<<<<<<<<<<<<< + * ])) + * __Pyx_globals['FPAIRED'] = SAM_FLAGS.FPAIRED */ - __pyx_t_1 = __pyx_capsule_create(((void *)(&__pyx_array_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 208, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem((PyObject *)__pyx_array_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_1) < 0) __PYX_ERR(1, 208, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - PyType_Modified(__pyx_array_type); + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FSUPPLEMENTARY); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 65, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 65, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__pyx_n_s_FSUPPLEMENTARY); + __Pyx_GIVEREF(__pyx_n_s_FSUPPLEMENTARY); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_n_s_FSUPPLEMENTARY); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_3); + __pyx_t_3 = 0; - /* "View.MemoryView":285 - * return self.name + /* "EnumType":53 + * if PY_VERSION_HEX >= 0x03040000: * - * cdef generic = Enum("") # <<<<<<<<<<<<<< - * cdef strided = Enum("") # default - * cdef indirect = Enum("") + * SAM_FLAGS = __Pyx_EnumBase('SAM_FLAGS', __Pyx_OrderedDict([ # <<<<<<<<<<<<<< + * ('FPAIRED', FPAIRED), + * ('FPROPER_PAIR', FPROPER_PAIR), */ - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__63, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 285, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XGOTREF(generic); - __Pyx_DECREF_SET(generic, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_3 = PyList_New(12); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_12); + PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_13); + PyList_SET_ITEM(__pyx_t_3, 1, __pyx_t_13); + __Pyx_GIVEREF(__pyx_t_11); + PyList_SET_ITEM(__pyx_t_3, 2, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_10); + PyList_SET_ITEM(__pyx_t_3, 3, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_9); + PyList_SET_ITEM(__pyx_t_3, 4, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); + PyList_SET_ITEM(__pyx_t_3, 5, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_7); + PyList_SET_ITEM(__pyx_t_3, 6, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_5); + PyList_SET_ITEM(__pyx_t_3, 7, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyList_SET_ITEM(__pyx_t_3, 8, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyList_SET_ITEM(__pyx_t_3, 9, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_14); + PyList_SET_ITEM(__pyx_t_3, 10, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_15); + PyList_SET_ITEM(__pyx_t_3, 11, __pyx_t_15); + __pyx_t_12 = 0; + __pyx_t_13 = 0; + __pyx_t_11 = 0; + __pyx_t_10 = 0; + __pyx_t_9 = 0; + __pyx_t_8 = 0; + __pyx_t_7 = 0; + __pyx_t_5 = 0; + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_t_14 = 0; + __pyx_t_15 = 0; + __pyx_t_15 = __Pyx_PyObject_CallOneArg(__Pyx_OrderedDict, __pyx_t_3); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_n_s_SAM_FLAGS); + __Pyx_GIVEREF(__pyx_n_s_SAM_FLAGS); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_SAM_FLAGS); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_15); + __pyx_t_15 = 0; + __pyx_t_15 = __Pyx_PyObject_Call(__Pyx_EnumBase, __pyx_t_3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_SAM_FLAGS, __pyx_t_15) < 0) __PYX_ERR(1, 53, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "EnumType":67 + * ('FSUPPLEMENTARY', FSUPPLEMENTARY), + * ])) + * __Pyx_globals['FPAIRED'] = SAM_FLAGS.FPAIRED # <<<<<<<<<<<<<< + * __Pyx_globals['FPROPER_PAIR'] = SAM_FLAGS.FPROPER_PAIR + * __Pyx_globals['FUNMAP'] = SAM_FLAGS.FUNMAP + */ + __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 67, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_FPAIRED); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 67, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 67, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FPAIRED, __pyx_t_3) < 0)) __PYX_ERR(1, 67, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "View.MemoryView":286 - * - * cdef generic = Enum("") - * cdef strided = Enum("") # default # <<<<<<<<<<<<<< - * cdef indirect = Enum("") - * + /* "EnumType":68 + * ])) + * __Pyx_globals['FPAIRED'] = SAM_FLAGS.FPAIRED + * __Pyx_globals['FPROPER_PAIR'] = SAM_FLAGS.FPROPER_PAIR # <<<<<<<<<<<<<< + * __Pyx_globals['FUNMAP'] = SAM_FLAGS.FUNMAP + * __Pyx_globals['FMUNMAP'] = SAM_FLAGS.FMUNMAP */ - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 286, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XGOTREF(strided); - __Pyx_DECREF_SET(strided, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 68, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_FPROPER_PAIR); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 68, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 68, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FPROPER_PAIR, __pyx_t_15) < 0)) __PYX_ERR(1, 68, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "EnumType":69 + * __Pyx_globals['FPAIRED'] = SAM_FLAGS.FPAIRED + * __Pyx_globals['FPROPER_PAIR'] = SAM_FLAGS.FPROPER_PAIR + * __Pyx_globals['FUNMAP'] = SAM_FLAGS.FUNMAP # <<<<<<<<<<<<<< + * __Pyx_globals['FMUNMAP'] = SAM_FLAGS.FMUNMAP + * __Pyx_globals['FREVERSE'] = SAM_FLAGS.FREVERSE + */ + __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 69, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_FUNMAP); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 69, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 69, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FUNMAP, __pyx_t_3) < 0)) __PYX_ERR(1, 69, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "View.MemoryView":287 - * cdef generic = Enum("") - * cdef strided = Enum("") # default - * cdef indirect = Enum("") # <<<<<<<<<<<<<< - * - * + /* "EnumType":70 + * __Pyx_globals['FPROPER_PAIR'] = SAM_FLAGS.FPROPER_PAIR + * __Pyx_globals['FUNMAP'] = SAM_FLAGS.FUNMAP + * __Pyx_globals['FMUNMAP'] = SAM_FLAGS.FMUNMAP # <<<<<<<<<<<<<< + * __Pyx_globals['FREVERSE'] = SAM_FLAGS.FREVERSE + * __Pyx_globals['FMREVERSE'] = SAM_FLAGS.FMREVERSE */ - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__65, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 287, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XGOTREF(indirect); - __Pyx_DECREF_SET(indirect, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 70, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_FMUNMAP); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 70, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 70, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FMUNMAP, __pyx_t_15) < 0)) __PYX_ERR(1, 70, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "EnumType":71 + * __Pyx_globals['FUNMAP'] = SAM_FLAGS.FUNMAP + * __Pyx_globals['FMUNMAP'] = SAM_FLAGS.FMUNMAP + * __Pyx_globals['FREVERSE'] = SAM_FLAGS.FREVERSE # <<<<<<<<<<<<<< + * __Pyx_globals['FMREVERSE'] = SAM_FLAGS.FMREVERSE + * __Pyx_globals['FREAD1'] = SAM_FLAGS.FREAD1 + */ + __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 71, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_FREVERSE); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 71, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 71, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FREVERSE, __pyx_t_3) < 0)) __PYX_ERR(1, 71, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "View.MemoryView":290 - * - * - * cdef contiguous = Enum("") # <<<<<<<<<<<<<< - * cdef indirect_contiguous = Enum("") - * + /* "EnumType":72 + * __Pyx_globals['FMUNMAP'] = SAM_FLAGS.FMUNMAP + * __Pyx_globals['FREVERSE'] = SAM_FLAGS.FREVERSE + * __Pyx_globals['FMREVERSE'] = SAM_FLAGS.FMREVERSE # <<<<<<<<<<<<<< + * __Pyx_globals['FREAD1'] = SAM_FLAGS.FREAD1 + * __Pyx_globals['FREAD2'] = SAM_FLAGS.FREAD2 */ - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__66, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XGOTREF(contiguous); - __Pyx_DECREF_SET(contiguous, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 72, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_FMREVERSE); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 72, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 72, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FMREVERSE, __pyx_t_15) < 0)) __PYX_ERR(1, 72, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "EnumType":73 + * __Pyx_globals['FREVERSE'] = SAM_FLAGS.FREVERSE + * __Pyx_globals['FMREVERSE'] = SAM_FLAGS.FMREVERSE + * __Pyx_globals['FREAD1'] = SAM_FLAGS.FREAD1 # <<<<<<<<<<<<<< + * __Pyx_globals['FREAD2'] = SAM_FLAGS.FREAD2 + * __Pyx_globals['FSECONDARY'] = SAM_FLAGS.FSECONDARY + */ + __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 73, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_FREAD1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 73, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 73, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FREAD1, __pyx_t_3) < 0)) __PYX_ERR(1, 73, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "View.MemoryView":291 - * - * cdef contiguous = Enum("") - * cdef indirect_contiguous = Enum("") # <<<<<<<<<<<<<< - * - * + /* "EnumType":74 + * __Pyx_globals['FMREVERSE'] = SAM_FLAGS.FMREVERSE + * __Pyx_globals['FREAD1'] = SAM_FLAGS.FREAD1 + * __Pyx_globals['FREAD2'] = SAM_FLAGS.FREAD2 # <<<<<<<<<<<<<< + * __Pyx_globals['FSECONDARY'] = SAM_FLAGS.FSECONDARY + * __Pyx_globals['FQCFAIL'] = SAM_FLAGS.FQCFAIL */ - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_MemviewEnum_type), __pyx_tuple__67, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XGOTREF(indirect_contiguous); - __Pyx_DECREF_SET(indirect_contiguous, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 74, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_FREAD2); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 74, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 74, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FREAD2, __pyx_t_15) < 0)) __PYX_ERR(1, 74, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "EnumType":75 + * __Pyx_globals['FREAD1'] = SAM_FLAGS.FREAD1 + * __Pyx_globals['FREAD2'] = SAM_FLAGS.FREAD2 + * __Pyx_globals['FSECONDARY'] = SAM_FLAGS.FSECONDARY # <<<<<<<<<<<<<< + * __Pyx_globals['FQCFAIL'] = SAM_FLAGS.FQCFAIL + * __Pyx_globals['FDUP'] = SAM_FLAGS.FDUP + */ + __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 75, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_FSECONDARY); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 75, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 75, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FSECONDARY, __pyx_t_3) < 0)) __PYX_ERR(1, 75, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "View.MemoryView":315 - * - * DEF THREAD_LOCKS_PREALLOCATED = 8 - * cdef int __pyx_memoryview_thread_locks_used = 0 # <<<<<<<<<<<<<< - * cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [ - * PyThread_allocate_lock(), + /* "EnumType":76 + * __Pyx_globals['FREAD2'] = SAM_FLAGS.FREAD2 + * __Pyx_globals['FSECONDARY'] = SAM_FLAGS.FSECONDARY + * __Pyx_globals['FQCFAIL'] = SAM_FLAGS.FQCFAIL # <<<<<<<<<<<<<< + * __Pyx_globals['FDUP'] = SAM_FLAGS.FDUP + * __Pyx_globals['FSUPPLEMENTARY'] = SAM_FLAGS.FSUPPLEMENTARY */ - __pyx_memoryview_thread_locks_used = 0; + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 76, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_FQCFAIL); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 76, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 76, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FQCFAIL, __pyx_t_15) < 0)) __PYX_ERR(1, 76, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "EnumType":77 + * __Pyx_globals['FSECONDARY'] = SAM_FLAGS.FSECONDARY + * __Pyx_globals['FQCFAIL'] = SAM_FLAGS.FQCFAIL + * __Pyx_globals['FDUP'] = SAM_FLAGS.FDUP # <<<<<<<<<<<<<< + * __Pyx_globals['FSUPPLEMENTARY'] = SAM_FLAGS.FSUPPLEMENTARY + * else: + */ + __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 77, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_FDUP); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 77, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 77, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FDUP, __pyx_t_3) < 0)) __PYX_ERR(1, 77, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "View.MemoryView":316 - * DEF THREAD_LOCKS_PREALLOCATED = 8 - * cdef int __pyx_memoryview_thread_locks_used = 0 - * cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [ # <<<<<<<<<<<<<< - * PyThread_allocate_lock(), - * PyThread_allocate_lock(), + /* "EnumType":78 + * __Pyx_globals['FQCFAIL'] = SAM_FLAGS.FQCFAIL + * __Pyx_globals['FDUP'] = SAM_FLAGS.FDUP + * __Pyx_globals['FSUPPLEMENTARY'] = SAM_FLAGS.FSUPPLEMENTARY # <<<<<<<<<<<<<< + * else: + * class SAM_FLAGS(__Pyx_EnumBase): */ - __pyx_t_4[0] = PyThread_allocate_lock(); - __pyx_t_4[1] = PyThread_allocate_lock(); - __pyx_t_4[2] = PyThread_allocate_lock(); - __pyx_t_4[3] = PyThread_allocate_lock(); - __pyx_t_4[4] = PyThread_allocate_lock(); - __pyx_t_4[5] = PyThread_allocate_lock(); - __pyx_t_4[6] = PyThread_allocate_lock(); - __pyx_t_4[7] = PyThread_allocate_lock(); - memcpy(&(__pyx_memoryview_thread_locks[0]), __pyx_t_4, sizeof(__pyx_memoryview_thread_locks[0]) * (8)); + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 78, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_FSUPPLEMENTARY); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 78, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 78, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FSUPPLEMENTARY, __pyx_t_15) < 0)) __PYX_ERR(1, 78, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - /* "View.MemoryView":544 - * info.obj = self - * - * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< + /* "EnumType":51 * + * cdef dict __Pyx_globals = globals() + * if PY_VERSION_HEX >= 0x03040000: # <<<<<<<<<<<<<< * + * SAM_FLAGS = __Pyx_EnumBase('SAM_FLAGS', __Pyx_OrderedDict([ */ - __pyx_t_1 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem((PyObject *)__pyx_memoryview_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_1) < 0) __PYX_ERR(1, 544, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - PyType_Modified(__pyx_memoryview_type); + goto __pyx_L6; + } - /* "View.MemoryView":990 - * return self.from_object - * - * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") # <<<<<<<<<<<<<< - * - * + /* "EnumType":80 + * __Pyx_globals['FSUPPLEMENTARY'] = SAM_FLAGS.FSUPPLEMENTARY + * else: + * class SAM_FLAGS(__Pyx_EnumBase): # <<<<<<<<<<<<<< + * pass + * __Pyx_globals['FPAIRED'] = SAM_FLAGS(FPAIRED, 'FPAIRED') */ - __pyx_t_1 = __pyx_capsule_create(((void *)(&__pyx_memoryview_getbuffer)), ((char *)"getbuffer(obj, view, flags)")); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 990, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem((PyObject *)__pyx_memoryviewslice_type->tp_dict, __pyx_n_s_pyx_getbuffer, __pyx_t_1) < 0) __PYX_ERR(1, 990, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - PyType_Modified(__pyx_memoryviewslice_type); + /*else*/ { + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 80, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__Pyx_EnumBase); + __Pyx_GIVEREF(__Pyx_EnumBase); + PyTuple_SET_ITEM(__pyx_t_15, 0, __Pyx_EnumBase); + __pyx_t_3 = __Pyx_CalculateMetaclass(NULL, __pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 80, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = __Pyx_Py3MetaclassPrepare(__pyx_t_3, __pyx_t_15, __pyx_n_s_SAM_FLAGS, __pyx_n_s_SAM_FLAGS, (PyObject *) NULL, __pyx_n_s_EnumType, (PyObject *) NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 80, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_1 = __Pyx_Py3ClassCreate(__pyx_t_3, __pyx_n_s_SAM_FLAGS, __pyx_t_15, __pyx_t_14, NULL, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 80, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_SAM_FLAGS, __pyx_t_1) < 0) __PYX_ERR(1, 80, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "EnumType":82 + * class SAM_FLAGS(__Pyx_EnumBase): + * pass + * __Pyx_globals['FPAIRED'] = SAM_FLAGS(FPAIRED, 'FPAIRED') # <<<<<<<<<<<<<< + * __Pyx_globals['FPROPER_PAIR'] = SAM_FLAGS(FPROPER_PAIR, 'FPROPER_PAIR') + * __Pyx_globals['FUNMAP'] = SAM_FLAGS(FUNMAP, 'FUNMAP') + */ + __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 82, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FPAIRED); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 82, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 82, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_n_s_FPAIRED); + __Pyx_GIVEREF(__pyx_n_s_FPAIRED); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_n_s_FPAIRED); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_14, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 82, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 82, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FPAIRED, __pyx_t_3) < 0)) __PYX_ERR(1, 82, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "(tree fragment)":1 - * def __pyx_unpickle_Enum(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< - * if __pyx_checksum != 0xb068931: - * from pickle import PickleError as __pyx_PickleError + /* "EnumType":83 + * pass + * __Pyx_globals['FPAIRED'] = SAM_FLAGS(FPAIRED, 'FPAIRED') + * __Pyx_globals['FPROPER_PAIR'] = SAM_FLAGS(FPROPER_PAIR, 'FPROPER_PAIR') # <<<<<<<<<<<<<< + * __Pyx_globals['FUNMAP'] = SAM_FLAGS(FUNMAP, 'FUNMAP') + * __Pyx_globals['FMUNMAP'] = SAM_FLAGS(FMUNMAP, 'FMUNMAP') */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_15View_dot_MemoryView_1__pyx_unpickle_Enum, NULL, __pyx_n_s_View_MemoryView); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_Enum, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 83, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FPROPER_PAIR); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 83, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 83, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); + __Pyx_INCREF(__pyx_n_s_FPROPER_PAIR); + __Pyx_GIVEREF(__pyx_n_s_FPROPER_PAIR); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_n_s_FPROPER_PAIR); + __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_15, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 83, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 83, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FPROPER_PAIR, __pyx_t_14) < 0)) __PYX_ERR(1, 83, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "EnumType":84 + * __Pyx_globals['FPAIRED'] = SAM_FLAGS(FPAIRED, 'FPAIRED') + * __Pyx_globals['FPROPER_PAIR'] = SAM_FLAGS(FPROPER_PAIR, 'FPROPER_PAIR') + * __Pyx_globals['FUNMAP'] = SAM_FLAGS(FUNMAP, 'FUNMAP') # <<<<<<<<<<<<<< + * __Pyx_globals['FMUNMAP'] = SAM_FLAGS(FMUNMAP, 'FMUNMAP') + * __Pyx_globals['FREVERSE'] = SAM_FLAGS(FREVERSE, 'FREVERSE') + */ + __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 84, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FUNMAP); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 84, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 84, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_15); + __Pyx_INCREF(__pyx_n_s_FUNMAP); + __Pyx_GIVEREF(__pyx_n_s_FUNMAP); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_FUNMAP); + __pyx_t_15 = 0; + __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 84, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 84, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FUNMAP, __pyx_t_15) < 0)) __PYX_ERR(1, 84, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "EnumType":85 + * __Pyx_globals['FPROPER_PAIR'] = SAM_FLAGS(FPROPER_PAIR, 'FPROPER_PAIR') + * __Pyx_globals['FUNMAP'] = SAM_FLAGS(FUNMAP, 'FUNMAP') + * __Pyx_globals['FMUNMAP'] = SAM_FLAGS(FMUNMAP, 'FMUNMAP') # <<<<<<<<<<<<<< + * __Pyx_globals['FREVERSE'] = SAM_FLAGS(FREVERSE, 'FREVERSE') + * __Pyx_globals['FMREVERSE'] = SAM_FLAGS(FMREVERSE, 'FMREVERSE') + */ + __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 85, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FMUNMAP); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 85, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 85, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_n_s_FMUNMAP); + __Pyx_GIVEREF(__pyx_n_s_FMUNMAP); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_n_s_FMUNMAP); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_14, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 85, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 85, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FMUNMAP, __pyx_t_3) < 0)) __PYX_ERR(1, 85, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "(tree fragment)":9 - * __pyx_unpickle_Enum__set_state( __pyx_result, __pyx_state) - * return __pyx_result - * cdef __pyx_unpickle_Enum__set_state(Enum __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< - * __pyx_result.name = __pyx_state[0] - * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + /* "EnumType":86 + * __Pyx_globals['FUNMAP'] = SAM_FLAGS(FUNMAP, 'FUNMAP') + * __Pyx_globals['FMUNMAP'] = SAM_FLAGS(FMUNMAP, 'FMUNMAP') + * __Pyx_globals['FREVERSE'] = SAM_FLAGS(FREVERSE, 'FREVERSE') # <<<<<<<<<<<<<< + * __Pyx_globals['FMREVERSE'] = SAM_FLAGS(FMREVERSE, 'FMREVERSE') + * __Pyx_globals['FREAD1'] = SAM_FLAGS(FREAD1, 'FREAD1') + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 86, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FREVERSE); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 86, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 86, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); + __Pyx_INCREF(__pyx_n_s_FREVERSE); + __Pyx_GIVEREF(__pyx_n_s_FREVERSE); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_n_s_FREVERSE); + __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_15, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 86, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 86, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FREVERSE, __pyx_t_14) < 0)) __PYX_ERR(1, 86, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "EnumType":87 + * __Pyx_globals['FMUNMAP'] = SAM_FLAGS(FMUNMAP, 'FMUNMAP') + * __Pyx_globals['FREVERSE'] = SAM_FLAGS(FREVERSE, 'FREVERSE') + * __Pyx_globals['FMREVERSE'] = SAM_FLAGS(FMREVERSE, 'FMREVERSE') # <<<<<<<<<<<<<< + * __Pyx_globals['FREAD1'] = SAM_FLAGS(FREAD1, 'FREAD1') + * __Pyx_globals['FREAD2'] = SAM_FLAGS(FREAD2, 'FREAD2') + */ + __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 87, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FMREVERSE); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 87, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 87, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_15); + __Pyx_INCREF(__pyx_n_s_FMREVERSE); + __Pyx_GIVEREF(__pyx_n_s_FMREVERSE); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_FMREVERSE); + __pyx_t_15 = 0; + __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 87, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 87, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FMREVERSE, __pyx_t_15) < 0)) __PYX_ERR(1, 87, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "EnumType":88 + * __Pyx_globals['FREVERSE'] = SAM_FLAGS(FREVERSE, 'FREVERSE') + * __Pyx_globals['FMREVERSE'] = SAM_FLAGS(FMREVERSE, 'FMREVERSE') + * __Pyx_globals['FREAD1'] = SAM_FLAGS(FREAD1, 'FREAD1') # <<<<<<<<<<<<<< + * __Pyx_globals['FREAD2'] = SAM_FLAGS(FREAD2, 'FREAD2') + * __Pyx_globals['FSECONDARY'] = SAM_FLAGS(FSECONDARY, 'FSECONDARY') + */ + __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 88, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FREAD1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 88, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 88, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_n_s_FREAD1); + __Pyx_GIVEREF(__pyx_n_s_FREAD1); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_n_s_FREAD1); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_14, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 88, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 88, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FREAD1, __pyx_t_3) < 0)) __PYX_ERR(1, 88, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "EnumType":89 + * __Pyx_globals['FMREVERSE'] = SAM_FLAGS(FMREVERSE, 'FMREVERSE') + * __Pyx_globals['FREAD1'] = SAM_FLAGS(FREAD1, 'FREAD1') + * __Pyx_globals['FREAD2'] = SAM_FLAGS(FREAD2, 'FREAD2') # <<<<<<<<<<<<<< + * __Pyx_globals['FSECONDARY'] = SAM_FLAGS(FSECONDARY, 'FSECONDARY') + * __Pyx_globals['FQCFAIL'] = SAM_FLAGS(FQCFAIL, 'FQCFAIL') + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 89, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FREAD2); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 89, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 89, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); + __Pyx_INCREF(__pyx_n_s_FREAD2); + __Pyx_GIVEREF(__pyx_n_s_FREAD2); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_n_s_FREAD2); + __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_15, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 89, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 89, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FREAD2, __pyx_t_14) < 0)) __PYX_ERR(1, 89, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "EnumType":90 + * __Pyx_globals['FREAD1'] = SAM_FLAGS(FREAD1, 'FREAD1') + * __Pyx_globals['FREAD2'] = SAM_FLAGS(FREAD2, 'FREAD2') + * __Pyx_globals['FSECONDARY'] = SAM_FLAGS(FSECONDARY, 'FSECONDARY') # <<<<<<<<<<<<<< + * __Pyx_globals['FQCFAIL'] = SAM_FLAGS(FQCFAIL, 'FQCFAIL') + * __Pyx_globals['FDUP'] = SAM_FLAGS(FDUP, 'FDUP') + */ + __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 90, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FSECONDARY); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 90, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 90, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_15); + __Pyx_INCREF(__pyx_n_s_FSECONDARY); + __Pyx_GIVEREF(__pyx_n_s_FSECONDARY); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_FSECONDARY); + __pyx_t_15 = 0; + __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 90, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 90, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FSECONDARY, __pyx_t_15) < 0)) __PYX_ERR(1, 90, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "EnumType":91 + * __Pyx_globals['FREAD2'] = SAM_FLAGS(FREAD2, 'FREAD2') + * __Pyx_globals['FSECONDARY'] = SAM_FLAGS(FSECONDARY, 'FSECONDARY') + * __Pyx_globals['FQCFAIL'] = SAM_FLAGS(FQCFAIL, 'FQCFAIL') # <<<<<<<<<<<<<< + * __Pyx_globals['FDUP'] = SAM_FLAGS(FDUP, 'FDUP') + * __Pyx_globals['FSUPPLEMENTARY'] = SAM_FLAGS(FSUPPLEMENTARY, 'FSUPPLEMENTARY') + */ + __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 91, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FQCFAIL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 91, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 91, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_n_s_FQCFAIL); + __Pyx_GIVEREF(__pyx_n_s_FQCFAIL); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_n_s_FQCFAIL); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_14, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 91, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 91, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FQCFAIL, __pyx_t_3) < 0)) __PYX_ERR(1, 91, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "EnumType":92 + * __Pyx_globals['FSECONDARY'] = SAM_FLAGS(FSECONDARY, 'FSECONDARY') + * __Pyx_globals['FQCFAIL'] = SAM_FLAGS(FQCFAIL, 'FQCFAIL') + * __Pyx_globals['FDUP'] = SAM_FLAGS(FDUP, 'FDUP') # <<<<<<<<<<<<<< + * __Pyx_globals['FSUPPLEMENTARY'] = SAM_FLAGS(FSUPPLEMENTARY, 'FSUPPLEMENTARY') + * */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 92, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FDUP); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 92, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 92, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); + __Pyx_INCREF(__pyx_n_s_FDUP); + __Pyx_GIVEREF(__pyx_n_s_FDUP); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_n_s_FDUP); + __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_15, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 92, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 92, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FDUP, __pyx_t_14) < 0)) __PYX_ERR(1, 92, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "EnumType":93 + * __Pyx_globals['FQCFAIL'] = SAM_FLAGS(FQCFAIL, 'FQCFAIL') + * __Pyx_globals['FDUP'] = SAM_FLAGS(FDUP, 'FDUP') + * __Pyx_globals['FSUPPLEMENTARY'] = SAM_FLAGS(FSUPPLEMENTARY, 'FSUPPLEMENTARY') # <<<<<<<<<<<<<< + * + */ + __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_SAM_FLAGS); if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 93, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(__pyx_e_5pysam_18libcalignedsegment_FSUPPLEMENTARY); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 93, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 93, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_15); + __Pyx_INCREF(__pyx_n_s_FSUPPLEMENTARY); + __Pyx_GIVEREF(__pyx_n_s_FSUPPLEMENTARY); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_FSUPPLEMENTARY); + __pyx_t_15 = 0; + __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_3, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(1, 93, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(__Pyx_globals == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 93, __pyx_L1_error) + } + if (unlikely(PyDict_SetItem(__Pyx_globals, __pyx_n_s_FSUPPLEMENTARY, __pyx_t_15) < 0)) __PYX_ERR(1, 93, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + __pyx_L6:; __Pyx_TraceReturn(Py_None, 0); /*--- Wrapped vars code ---*/ @@ -47998,6 +60600,17 @@ if (!__Pyx_RefNanny) { __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_15); if (__pyx_m) { if (__pyx_d) { __Pyx_AddTraceback("init pysam.libcalignedsegment", 0, __pyx_lineno, __pyx_filename); @@ -48667,6 +61280,20 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObjec return 0; } +/* bytes_index */ + static CYTHON_INLINE char __Pyx_PyBytes_GetItemInt(PyObject* bytes, Py_ssize_t index, int check_bounds) { + if (check_bounds) { + Py_ssize_t size = PyBytes_GET_SIZE(bytes); + if (unlikely(index >= size) | ((index < 0) & unlikely(index < -size))) { + PyErr_SetString(PyExc_IndexError, "string index out of range"); + return (char) -1; + } + } + if (index < 0) + index += PyBytes_GET_SIZE(bytes); + return PyBytes_AS_STRING(bytes)[index]; +} + /* RaiseException */ #if PY_MAJOR_VERSION < 3 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, @@ -48886,25 +61513,6 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject return 0; } -/* DictGetItem */ - #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY -static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { - PyObject *value; - value = PyDict_GetItemWithError(d, key); - if (unlikely(!value)) { - if (!PyErr_Occurred()) { - PyObject* args = PyTuple_Pack(1, key); - if (likely(args)) - PyErr_SetObject(PyExc_KeyError, args); - Py_XDECREF(args); - } - return NULL; - } - Py_INCREF(value); - return value; -} -#endif - /* GetItemInt */ static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; @@ -49110,73 +61718,142 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { } #endif -/* BytesEquals */ - static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { -#if CYTHON_COMPILING_IN_PYPY - return PyObject_RichCompareBool(s1, s2, equals); -#else - if (s1 == s2) { - return (equals == Py_EQ); - } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { - const char *ps1, *ps2; - Py_ssize_t length = PyBytes_GET_SIZE(s1); - if (length != PyBytes_GET_SIZE(s2)) - return (equals == Py_NE); - ps1 = PyBytes_AS_STRING(s1); - ps2 = PyBytes_AS_STRING(s2); - if (ps1[0] != ps2[0]) { - return (equals == Py_NE); - } else if (length == 1) { - return (equals == Py_EQ); - } else { - int result; -#if CYTHON_USE_UNICODE_INTERNALS - Py_hash_t hash1, hash2; - hash1 = ((PyBytesObject*)s1)->ob_shash; - hash2 = ((PyBytesObject*)s2)->ob_shash; - if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { - return (equals == Py_NE); +/* StringJoin */ + #if !CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) { + return PyObject_CallMethodObjArgs(sep, __pyx_n_s_join, values, NULL); +} +#endif + +/* None */ + static CYTHON_INLINE long __Pyx_div_long(long a, long b) { + long q = a / b; + long r = a - q*b; + q -= ((r != 0) & ((r ^ b) < 0)); + return q; +} + +/* None */ + static CYTHON_INLINE long __Pyx_mod_long(long a, long b) { + long r = a % b; + r += ((r != 0) & ((r ^ b) < 0)) * b; + return r; +} + +/* RaiseDoubleKeywords */ + static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, + PyObject* kw_name) +{ + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION >= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AsString(kw_name)); + #endif +} + +/* ParseKeywords */ + static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + while (PyDict_Next(kwds, &pos, &key, &value)) { + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; + continue; + } + name = first_kw_arg; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { + while (*name) { + if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) + && _PyString_Eq(**name, key)) { + values[name-argnames] = value; + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + if ((**argname == key) || ( + (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) + && _PyString_Eq(**argname, key))) { + goto arg_passed_twice; + } + argname++; + } + } + } else + #endif + if (likely(PyUnicode_Check(key))) { + while (*name) { + int cmp = (**name == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : + #endif + PyUnicode_Compare(**name, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) { + values[name-argnames] = value; + break; + } + name++; } -#endif - result = memcmp(ps1, ps2, (size_t)length); - return (equals == Py_EQ) ? (result == 0) : (result != 0); + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + int cmp = (**argname == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : + #endif + PyUnicode_Compare(**argname, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) goto arg_passed_twice; + argname++; + } + } + } else + goto invalid_keyword_type; + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; } - } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { - return (equals == Py_NE); - } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { - return (equals == Py_NE); - } else { - int result; - PyObject* py_result = PyObject_RichCompare(s1, s2, equals); - if (!py_result) - return -1; - result = __Pyx_PyObject_IsTrue(py_result); - Py_DECREF(py_result); - return result; } -#endif -} - -/* StringJoin */ - #if !CYTHON_COMPILING_IN_CPYTHON -static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) { - return PyObject_CallMethodObjArgs(sep, __pyx_n_s_join, values, NULL); -} -#endif - -/* None */ - static CYTHON_INLINE long __Pyx_div_long(long a, long b) { - long q = a / b; - long r = a - q*b; - q -= ((r != 0) & ((r ^ b) < 0)); - return q; -} - -/* None */ - static CYTHON_INLINE long __Pyx_mod_long(long a, long b) { - long r = a % b; - r += ((r != 0) & ((r ^ b) < 0)) * b; - return r; + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, key); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; } /* RaiseArgTupleInvalid */ @@ -49205,46 +61882,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* value (num_expected == 1) ? "" : "s", num_found); } -/* KeywordStringCheck */ - static int __Pyx_CheckKeywordStrings( - PyObject *kwdict, - const char* function_name, - int kw_allowed) -{ - PyObject* key = 0; - Py_ssize_t pos = 0; -#if CYTHON_COMPILING_IN_PYPY - if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) - goto invalid_keyword; - return 1; -#else - while (PyDict_Next(kwdict, &pos, &key, 0)) { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_Check(key))) - #endif - if (unlikely(!PyUnicode_Check(key))) - goto invalid_keyword_type; - } - if ((!kw_allowed) && unlikely(key)) - goto invalid_keyword; - return 1; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%.200s() keywords must be strings", function_name); - return 0; -#endif -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%.200s() got an unexpected keyword argument '%.200s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif - return 0; -} - /* ArgTypeTest */ static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) { @@ -49357,135 +61994,199 @@ static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED } #endif -/* PyObjectSetAttrStr */ +/* None */ + static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) { + PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname); +} + +/* ObjectGetItem */ #if CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { - PyTypeObject* tp = Py_TYPE(obj); - if (likely(tp->tp_setattro)) - return tp->tp_setattro(obj, attr_name, value); -#if PY_MAJOR_VERSION < 3 - if (likely(tp->tp_setattr)) - return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value); -#endif - return PyObject_SetAttr(obj, attr_name, value); +static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) { + PyObject *runerr; + Py_ssize_t key_value; + PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence; + if (unlikely(!(m && m->sq_item))) { + PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name); + return NULL; + } + key_value = __Pyx_PyIndex_AsSsize_t(index); + if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) { + return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1); + } + if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) { + PyErr_Clear(); + PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name); + } + return NULL; +} +static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) { + PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping; + if (likely(m && m->mp_subscript)) { + return m->mp_subscript(obj, key); + } + return __Pyx_PyObject_GetIndex(obj, key); } #endif -/* RaiseDoubleKeywords */ - static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, - PyObject* kw_name) -{ - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION >= 3 - "%s() got multiple values for keyword argument '%U'", func_name, kw_name); - #else - "%s() got multiple values for keyword argument '%s'", func_name, - PyString_AsString(kw_name)); - #endif +/* BytesEquals */ + static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif } -/* ParseKeywords */ - static int __Pyx_ParseOptionalKeywords( - PyObject *kwds, - PyObject **argnames[], - PyObject *kwds2, - PyObject *values[], - Py_ssize_t num_pos_args, - const char* function_name) -{ - PyObject *key = 0, *value = 0; - Py_ssize_t pos = 0; - PyObject*** name; - PyObject*** first_kw_arg = argnames + num_pos_args; - while (PyDict_Next(kwds, &pos, &key, &value)) { - name = first_kw_arg; - while (*name && (**name != key)) name++; - if (*name) { - values[name-argnames] = value; - continue; +/* UnicodeEquals */ + static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; } - name = first_kw_arg; - #if PY_MAJOR_VERSION < 3 - if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { - while (*name) { - if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) - && _PyString_Eq(**name, key)) { - values[name-argnames] = value; - break; - } - name++; - } - if (*name) continue; - else { - PyObject*** argname = argnames; - while (argname != first_kw_arg) { - if ((**argname == key) || ( - (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) - && _PyString_Eq(**argname, key))) { - goto arg_passed_twice; - } - argname++; - } - } - } else +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; #endif - if (likely(PyUnicode_Check(key))) { - while (*name) { - int cmp = (**name == key) ? 0 : - #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : - #endif - PyUnicode_Compare(**name, key); - if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; - if (cmp == 0) { - values[name-argnames] = value; - break; - } - name++; - } - if (*name) continue; - else { - PyObject*** argname = argnames; - while (argname != first_kw_arg) { - int cmp = (**argname == key) ? 0 : - #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : - #endif - PyUnicode_Compare(**argname, key); - if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; - if (cmp == 0) goto arg_passed_twice; - argname++; - } + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; } - } else - goto invalid_keyword_type; - if (kwds2) { - if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; } else { - goto invalid_keyword; + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; } - return 0; -arg_passed_twice: - __Pyx_RaiseDoubleKeywordsError(function_name, key); - goto bad; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%.200s() keywords must be strings", function_name); - goto bad; -invalid_keyword: - PyErr_Format(PyExc_TypeError, +return_eq: #if PY_MAJOR_VERSION < 3 - "%.200s() got an unexpected keyword argument '%.200s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); + Py_XDECREF(owned_ref); #endif -bad: - return -1; + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* PyObjectSetAttrStr */ + #if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_setattro)) + return tp->tp_setattro(obj, attr_name, value); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_setattr)) + return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value); +#endif + return PyObject_SetAttr(obj, attr_name, value); } +#endif /* None */ static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { @@ -49627,112 +62328,53 @@ static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *memslice, if (have_gil) { Py_CLEAR(memslice->memview); } else { - PyGILState_STATE _gilstate = PyGILState_Ensure(); - Py_CLEAR(memslice->memview); - PyGILState_Release(_gilstate); - } - } else { - memslice->memview = NULL; - } -} - -/* UnicodeEquals */ - static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { -#if CYTHON_COMPILING_IN_PYPY - return PyObject_RichCompareBool(s1, s2, equals); -#else -#if PY_MAJOR_VERSION < 3 - PyObject* owned_ref = NULL; -#endif - int s1_is_unicode, s2_is_unicode; - if (s1 == s2) { - goto return_eq; - } - s1_is_unicode = PyUnicode_CheckExact(s1); - s2_is_unicode = PyUnicode_CheckExact(s2); -#if PY_MAJOR_VERSION < 3 - if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { - owned_ref = PyUnicode_FromObject(s2); - if (unlikely(!owned_ref)) - return -1; - s2 = owned_ref; - s2_is_unicode = 1; - } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { - owned_ref = PyUnicode_FromObject(s1); - if (unlikely(!owned_ref)) - return -1; - s1 = owned_ref; - s1_is_unicode = 1; - } else if (((!s2_is_unicode) & (!s1_is_unicode))) { - return __Pyx_PyBytes_Equals(s1, s2, equals); - } -#endif - if (s1_is_unicode & s2_is_unicode) { - Py_ssize_t length; - int kind; - void *data1, *data2; - if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) - return -1; - length = __Pyx_PyUnicode_GET_LENGTH(s1); - if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { - goto return_ne; - } -#if CYTHON_USE_UNICODE_INTERNALS - { - Py_hash_t hash1, hash2; - #if CYTHON_PEP393_ENABLED - hash1 = ((PyASCIIObject*)s1)->hash; - hash2 = ((PyASCIIObject*)s2)->hash; - #else - hash1 = ((PyUnicodeObject*)s1)->hash; - hash2 = ((PyUnicodeObject*)s2)->hash; - #endif - if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { - goto return_ne; - } - } -#endif - kind = __Pyx_PyUnicode_KIND(s1); - if (kind != __Pyx_PyUnicode_KIND(s2)) { - goto return_ne; - } - data1 = __Pyx_PyUnicode_DATA(s1); - data2 = __Pyx_PyUnicode_DATA(s2); - if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { - goto return_ne; - } else if (length == 1) { - goto return_eq; - } else { - int result = memcmp(data1, data2, (size_t)(length * kind)); - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_EQ) ? (result == 0) : (result != 0); - } - } else if ((s1 == Py_None) & s2_is_unicode) { - goto return_ne; - } else if ((s2 == Py_None) & s1_is_unicode) { - goto return_ne; - } else { - int result; - PyObject* py_result = PyObject_RichCompare(s1, s2, equals); - if (!py_result) - return -1; - result = __Pyx_PyObject_IsTrue(py_result); - Py_DECREF(py_result); - return result; + PyGILState_STATE _gilstate = PyGILState_Ensure(); + Py_CLEAR(memslice->memview); + PyGILState_Release(_gilstate); + } + } else { + memslice->memview = NULL; } -return_eq: - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_EQ); -return_ne: +} + +/* KeywordStringCheck */ + static int __Pyx_CheckKeywordStrings( + PyObject *kwdict, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; +#if CYTHON_COMPILING_IN_PYPY + if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) + goto invalid_keyword; + return 1; +#else + while (PyDict_Next(kwdict, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_Check(key))) + #endif + if (unlikely(!PyUnicode_Check(key))) + goto invalid_keyword_type; + } + if ((!kw_allowed) && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + return 0; +#endif +invalid_keyword: + PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); #endif - return (equals == Py_NE); -#endif + return 0; } /* PyErrExceptionMatches */ @@ -49893,35 +62535,6 @@ static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject return q; } -/* ObjectGetItem */ - #if CYTHON_USE_TYPE_SLOTS -static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) { - PyObject *runerr; - Py_ssize_t key_value; - PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence; - if (unlikely(!(m && m->sq_item))) { - PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name); - return NULL; - } - key_value = __Pyx_PyIndex_AsSsize_t(index); - if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) { - return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1); - } - if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) { - PyErr_Clear(); - PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name); - } - return NULL; -} -static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) { - PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping; - if (likely(m && m->mp_subscript)) { - return m->mp_subscript(obj, key); - } - return __Pyx_PyObject_GetIndex(obj, key); -} -#endif - /* decode_c_string */ static CYTHON_INLINE PyObject* __Pyx_decode_c_string( const char* cstring, Py_ssize_t start, Py_ssize_t stop, @@ -50124,223 +62737,1070 @@ static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) return 1; } - return 0; + return 0; + } + return __Pyx_InBases(a, b); +} +#if PY_MAJOR_VERSION == 2 +static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { + PyObject *exception, *value, *tb; + int res; + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&exception, &value, &tb); + res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + if (!res) { + res = PyObject_IsSubclass(err, exc_type2); + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + } + __Pyx_ErrRestore(exception, value, tb); + return res; +} +#else +static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { + int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; + if (!res) { + res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + } + return res; +} +#endif +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) { + if (likely(err == exc_type)) return 1; + if (likely(PyExceptionClass_Check(err))) { + return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type); + } + return PyErr_GivenExceptionMatches(err, exc_type); +} +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) { + if (likely(err == exc_type1 || err == exc_type2)) return 1; + if (likely(PyExceptionClass_Check(err))) { + return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2); + } + return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2)); +} +#endif + +/* PyObject_GenericGetAttrNoDict */ + #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'%.50s' object has no attribute '%U'", + tp->tp_name, attr_name); +#else + "'%.50s' object has no attribute '%.400s'", + tp->tp_name, PyString_AS_STRING(attr_name)); +#endif + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { + PyObject *descr; + PyTypeObject *tp = Py_TYPE(obj); + if (unlikely(!PyString_Check(attr_name))) { + return PyObject_GenericGetAttr(obj, attr_name); + } + assert(!tp->tp_dictoffset); + descr = _PyType_Lookup(tp, attr_name); + if (unlikely(!descr)) { + return __Pyx_RaiseGenericGetAttributeError(tp, attr_name); + } + Py_INCREF(descr); + #if PY_MAJOR_VERSION < 3 + if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS))) + #endif + { + descrgetfunc f = Py_TYPE(descr)->tp_descr_get; + if (unlikely(f)) { + PyObject *res = f(descr, obj, (PyObject *)tp); + Py_DECREF(descr); + return res; + } + } + return descr; +} +#endif + +/* PyObject_GenericGetAttr */ + #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) { + if (unlikely(Py_TYPE(obj)->tp_dictoffset)) { + return PyObject_GenericGetAttr(obj, attr_name); + } + return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name); +} +#endif + +/* SetVTable */ + static int __Pyx_SetVtable(PyObject *dict, void *vtable) { +#if PY_VERSION_HEX >= 0x02070000 + PyObject *ob = PyCapsule_New(vtable, 0, 0); +#else + PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); +#endif + if (!ob) + goto bad; + if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0) + goto bad; + Py_DECREF(ob); + return 0; +bad: + Py_XDECREF(ob); + return -1; +} + +/* SetupReduce */ + static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { + int ret; + PyObject *name_attr; + name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name_2); + if (likely(name_attr)) { + ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); + } else { + ret = -1; + } + if (unlikely(ret < 0)) { + PyErr_Clear(); + ret = 0; + } + Py_XDECREF(name_attr); + return ret; +} +static int __Pyx_setup_reduce(PyObject* type_obj) { + int ret = 0; + PyObject *object_reduce = NULL; + PyObject *object_reduce_ex = NULL; + PyObject *reduce = NULL; + PyObject *reduce_ex = NULL; + PyObject *reduce_cython = NULL; + PyObject *setstate = NULL; + PyObject *setstate_cython = NULL; +#if CYTHON_USE_PYTYPE_LOOKUP + if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto GOOD; +#else + if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto GOOD; +#endif +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD; +#else + object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD; +#endif + reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto BAD; + if (reduce_ex == object_reduce_ex) { +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD; +#else + object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD; +#endif + reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto BAD; + if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { + reduce_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_cython); if (unlikely(!reduce_cython)) goto BAD; + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto BAD; + setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate); + if (!setstate) PyErr_Clear(); + if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) { + setstate_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate_cython); if (unlikely(!setstate_cython)) goto BAD; + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto BAD; + } + PyType_Modified((PyTypeObject*)type_obj); + } + } + goto GOOD; +BAD: + if (!PyErr_Occurred()) + PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); + ret = -1; +GOOD: +#if !CYTHON_USE_PYTYPE_LOOKUP + Py_XDECREF(object_reduce); + Py_XDECREF(object_reduce_ex); +#endif + Py_XDECREF(reduce); + Py_XDECREF(reduce_ex); + Py_XDECREF(reduce_cython); + Py_XDECREF(setstate); + Py_XDECREF(setstate_cython); + return ret; +} + +/* GetVTable */ + static void* __Pyx_GetVtable(PyObject *dict) { + void* ptr; + PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable); + if (!ob) + goto bad; +#if PY_VERSION_HEX >= 0x02070000 + ptr = PyCapsule_GetPointer(ob, 0); +#else + ptr = PyCObject_AsVoidPtr(ob); +#endif + if (!ptr && !PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type"); + Py_DECREF(ob); + return ptr; +bad: + Py_XDECREF(ob); + return NULL; +} + +/* ClassMethod */ + static PyObject* __Pyx_Method_ClassMethod(PyObject *method) { +#if CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM <= 0x05080000 + if (PyObject_TypeCheck(method, &PyWrapperDescr_Type)) { + return PyClassMethod_New(method); + } +#else +#if CYTHON_COMPILING_IN_PYSTON || CYTHON_COMPILING_IN_PYPY + if (PyMethodDescr_Check(method)) { +#else + static PyTypeObject *methoddescr_type = NULL; + if (methoddescr_type == NULL) { + PyObject *meth = PyObject_GetAttrString((PyObject*)&PyList_Type, "append"); + if (!meth) return NULL; + methoddescr_type = Py_TYPE(meth); + Py_DECREF(meth); + } + if (__Pyx_TypeCheck(method, methoddescr_type)) { +#endif + PyMethodDescrObject *descr = (PyMethodDescrObject *)method; + #if PY_VERSION_HEX < 0x03020000 + PyTypeObject *d_type = descr->d_type; + #else + PyTypeObject *d_type = descr->d_common.d_type; + #endif + return PyDescr_NewClassMethod(d_type, descr->d_method); + } +#endif + else if (PyMethod_Check(method)) { + return PyClassMethod_New(PyMethod_GET_FUNCTION(method)); + } + else if (PyCFunction_Check(method)) { + return PyClassMethod_New(method); + } +#ifdef __Pyx_CyFunction_USED + else if (__Pyx_TypeCheck(method, __pyx_CyFunctionType)) { + return PyClassMethod_New(method); + } +#endif + PyErr_SetString(PyExc_TypeError, + "Class-level classmethod() can only be called on " + "a method_descriptor or instance method."); + return NULL; +} + +/* GetNameInClass */ + static PyObject *__Pyx_GetGlobalNameAfterAttributeLookup(PyObject *name) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + return NULL; + __Pyx_PyErr_Clear(); + return __Pyx_GetModuleGlobalName(name); +} +static PyObject *__Pyx_GetNameInClass(PyObject *nmspace, PyObject *name) { + PyObject *result; + result = __Pyx_PyObject_GetAttrStr(nmspace, name); + if (!result) { + result = __Pyx_GetGlobalNameAfterAttributeLookup(name); + } + return result; +} + +/* CalculateMetaclass */ + static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) { + Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases); + for (i=0; i < nbases; i++) { + PyTypeObject *tmptype; + PyObject *tmp = PyTuple_GET_ITEM(bases, i); + tmptype = Py_TYPE(tmp); +#if PY_MAJOR_VERSION < 3 + if (tmptype == &PyClass_Type) + continue; +#endif + if (!metaclass) { + metaclass = tmptype; + continue; + } + if (PyType_IsSubtype(metaclass, tmptype)) + continue; + if (PyType_IsSubtype(tmptype, metaclass)) { + metaclass = tmptype; + continue; + } + PyErr_SetString(PyExc_TypeError, + "metaclass conflict: " + "the metaclass of a derived class " + "must be a (non-strict) subclass " + "of the metaclasses of all its bases"); + return NULL; + } + if (!metaclass) { +#if PY_MAJOR_VERSION < 3 + metaclass = &PyClass_Type; +#else + metaclass = &PyType_Type; +#endif + } + Py_INCREF((PyObject*) metaclass); + return (PyObject*) metaclass; +} + +/* FetchCommonType */ + static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { + PyObject* fake_module; + PyTypeObject* cached_type = NULL; + fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI); + if (!fake_module) return NULL; + Py_INCREF(fake_module); + cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name); + if (cached_type) { + if (!PyType_Check((PyObject*)cached_type)) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s is not a type object", + type->tp_name); + goto bad; + } + if (cached_type->tp_basicsize != type->tp_basicsize) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s has the wrong size, try recompiling", + type->tp_name); + goto bad; + } + } else { + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + if (PyType_Ready(type) < 0) goto bad; + if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0) + goto bad; + Py_INCREF(type); + cached_type = type; + } +done: + Py_DECREF(fake_module); + return cached_type; +bad: + Py_XDECREF(cached_type); + cached_type = NULL; + goto done; +} + +/* CythonFunction */ + #include +static PyObject * +__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure) +{ + if (unlikely(op->func_doc == NULL)) { + if (op->func.m_ml->ml_doc) { +#if PY_MAJOR_VERSION >= 3 + op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc); +#else + op->func_doc = PyString_FromString(op->func.m_ml->ml_doc); +#endif + if (unlikely(op->func_doc == NULL)) + return NULL; + } else { + Py_INCREF(Py_None); + return Py_None; + } + } + Py_INCREF(op->func_doc); + return op->func_doc; +} +static int +__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value) +{ + PyObject *tmp = op->func_doc; + if (value == NULL) { + value = Py_None; + } + Py_INCREF(value); + op->func_doc = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op) +{ + if (unlikely(op->func_name == NULL)) { +#if PY_MAJOR_VERSION >= 3 + op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name); +#else + op->func_name = PyString_InternFromString(op->func.m_ml->ml_name); +#endif + if (unlikely(op->func_name == NULL)) + return NULL; + } + Py_INCREF(op->func_name); + return op->func_name; +} +static int +__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value) +{ + PyObject *tmp; +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) { +#else + if (unlikely(value == NULL || !PyString_Check(value))) { +#endif + PyErr_SetString(PyExc_TypeError, + "__name__ must be set to a string object"); + return -1; + } + tmp = op->func_name; + Py_INCREF(value); + op->func_name = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op) +{ + Py_INCREF(op->func_qualname); + return op->func_qualname; +} +static int +__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value) +{ + PyObject *tmp; +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) { +#else + if (unlikely(value == NULL || !PyString_Check(value))) { +#endif + PyErr_SetString(PyExc_TypeError, + "__qualname__ must be set to a string object"); + return -1; + } + tmp = op->func_qualname; + Py_INCREF(value); + op->func_qualname = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure) +{ + PyObject *self; + self = m->func_closure; + if (self == NULL) + self = Py_None; + Py_INCREF(self); + return self; +} +static PyObject * +__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op) +{ + if (unlikely(op->func_dict == NULL)) { + op->func_dict = PyDict_New(); + if (unlikely(op->func_dict == NULL)) + return NULL; + } + Py_INCREF(op->func_dict); + return op->func_dict; +} +static int +__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value) +{ + PyObject *tmp; + if (unlikely(value == NULL)) { + PyErr_SetString(PyExc_TypeError, + "function's dictionary may not be deleted"); + return -1; + } + if (unlikely(!PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "setting function's dictionary to a non-dict"); + return -1; + } + tmp = op->func_dict; + Py_INCREF(value); + op->func_dict = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op) +{ + Py_INCREF(op->func_globals); + return op->func_globals; +} +static PyObject * +__Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op) +{ + Py_INCREF(Py_None); + return Py_None; +} +static PyObject * +__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op) +{ + PyObject* result = (op->func_code) ? op->func_code : Py_None; + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) { + int result = 0; + PyObject *res = op->defaults_getter((PyObject *) op); + if (unlikely(!res)) + return -1; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + op->defaults_tuple = PyTuple_GET_ITEM(res, 0); + Py_INCREF(op->defaults_tuple); + op->defaults_kwdict = PyTuple_GET_ITEM(res, 1); + Py_INCREF(op->defaults_kwdict); + #else + op->defaults_tuple = PySequence_ITEM(res, 0); + if (unlikely(!op->defaults_tuple)) result = -1; + else { + op->defaults_kwdict = PySequence_ITEM(res, 1); + if (unlikely(!op->defaults_kwdict)) result = -1; + } + #endif + Py_DECREF(res); + return result; +} +static int +__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value) { + PyObject* tmp; + if (!value) { + value = Py_None; + } else if (value != Py_None && !PyTuple_Check(value)) { + PyErr_SetString(PyExc_TypeError, + "__defaults__ must be set to a tuple object"); + return -1; + } + Py_INCREF(value); + tmp = op->defaults_tuple; + op->defaults_tuple = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op) { + PyObject* result = op->defaults_tuple; + if (unlikely(!result)) { + if (op->defaults_getter) { + if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL; + result = op->defaults_tuple; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value) { + PyObject* tmp; + if (!value) { + value = Py_None; + } else if (value != Py_None && !PyDict_Check(value)) { + PyErr_SetString(PyExc_TypeError, + "__kwdefaults__ must be set to a dict object"); + return -1; + } + Py_INCREF(value); + tmp = op->defaults_kwdict; + op->defaults_kwdict = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op) { + PyObject* result = op->defaults_kwdict; + if (unlikely(!result)) { + if (op->defaults_getter) { + if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL; + result = op->defaults_kwdict; + } else { + result = Py_None; + } } - return __Pyx_InBases(a, b); + Py_INCREF(result); + return result; } -#if PY_MAJOR_VERSION == 2 -static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { - PyObject *exception, *value, *tb; - int res; - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ErrFetch(&exception, &value, &tb); - res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; - if (unlikely(res == -1)) { - PyErr_WriteUnraisable(err); - res = 0; +static int +__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value) { + PyObject* tmp; + if (!value || value == Py_None) { + value = NULL; + } else if (!PyDict_Check(value)) { + PyErr_SetString(PyExc_TypeError, + "__annotations__ must be set to a dict object"); + return -1; } - if (!res) { - res = PyObject_IsSubclass(err, exc_type2); - if (unlikely(res == -1)) { - PyErr_WriteUnraisable(err); - res = 0; - } + Py_XINCREF(value); + tmp = op->func_annotations; + op->func_annotations = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op) { + PyObject* result = op->func_annotations; + if (unlikely(!result)) { + result = PyDict_New(); + if (unlikely(!result)) return NULL; + op->func_annotations = result; } - __Pyx_ErrRestore(exception, value, tb); - return res; + Py_INCREF(result); + return result; } +static PyGetSetDef __pyx_CyFunction_getsets[] = { + {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0}, + {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0}, + {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0}, + {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0}, + {0, 0, 0, 0, 0} +}; +static PyMemberDef __pyx_CyFunction_members[] = { + {(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), PY_WRITE_RESTRICTED, 0}, + {0, 0, 0, 0, 0} +}; +static PyObject * +__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args) +{ +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromString(m->func.m_ml->ml_name); #else -static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { - int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; - if (!res) { - res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); - } - return res; + return PyString_FromString(m->func.m_ml->ml_name); +#endif } +static PyMethodDef __pyx_CyFunction_methods[] = { + {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0}, + {0, 0, 0, 0} +}; +#if PY_VERSION_HEX < 0x030500A0 +#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist) +#else +#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func.m_weakreflist) #endif -static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) { - if (likely(err == exc_type)) return 1; - if (likely(PyExceptionClass_Check(err))) { - return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type); +static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, PyObject* qualname, + PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { + __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type); + if (op == NULL) + return NULL; + op->flags = flags; + __Pyx_CyFunction_weakreflist(op) = NULL; + op->func.m_ml = ml; + op->func.m_self = (PyObject *) op; + Py_XINCREF(closure); + op->func_closure = closure; + Py_XINCREF(module); + op->func.m_module = module; + op->func_dict = NULL; + op->func_name = NULL; + Py_INCREF(qualname); + op->func_qualname = qualname; + op->func_doc = NULL; + op->func_classobj = NULL; + op->func_globals = globals; + Py_INCREF(op->func_globals); + Py_XINCREF(code); + op->func_code = code; + op->defaults_pyobjects = 0; + op->defaults = NULL; + op->defaults_tuple = NULL; + op->defaults_kwdict = NULL; + op->defaults_getter = NULL; + op->func_annotations = NULL; + PyObject_GC_Track(op); + return (PyObject *) op; +} +static int +__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m) +{ + Py_CLEAR(m->func_closure); + Py_CLEAR(m->func.m_module); + Py_CLEAR(m->func_dict); + Py_CLEAR(m->func_name); + Py_CLEAR(m->func_qualname); + Py_CLEAR(m->func_doc); + Py_CLEAR(m->func_globals); + Py_CLEAR(m->func_code); + Py_CLEAR(m->func_classobj); + Py_CLEAR(m->defaults_tuple); + Py_CLEAR(m->defaults_kwdict); + Py_CLEAR(m->func_annotations); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_XDECREF(pydefaults[i]); + PyObject_Free(m->defaults); + m->defaults = NULL; } - return PyErr_GivenExceptionMatches(err, exc_type); + return 0; } -static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) { - if (likely(err == exc_type1 || err == exc_type2)) return 1; - if (likely(PyExceptionClass_Check(err))) { - return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2); +static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + if (__Pyx_CyFunction_weakreflist(m) != NULL) + PyObject_ClearWeakRefs((PyObject *) m); + __Pyx_CyFunction_clear(m); + PyObject_GC_Del(m); +} +static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + PyObject_GC_UnTrack(m); + __Pyx__CyFunction_dealloc(m); +} +static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg) +{ + Py_VISIT(m->func_closure); + Py_VISIT(m->func.m_module); + Py_VISIT(m->func_dict); + Py_VISIT(m->func_name); + Py_VISIT(m->func_qualname); + Py_VISIT(m->func_doc); + Py_VISIT(m->func_globals); + Py_VISIT(m->func_code); + Py_VISIT(m->func_classobj); + Py_VISIT(m->defaults_tuple); + Py_VISIT(m->defaults_kwdict); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_VISIT(pydefaults[i]); } - return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2)); + return 0; } -#endif - -/* PyObject_GenericGetAttrNoDict */ - #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 -static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { - PyErr_Format(PyExc_AttributeError, +static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type) +{ + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) { + Py_INCREF(func); + return func; + } + if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) { + if (type == NULL) + type = (PyObject *)(Py_TYPE(obj)); + return __Pyx_PyMethod_New(func, type, (PyObject *)(Py_TYPE(type))); + } + if (obj == Py_None) + obj = NULL; + return __Pyx_PyMethod_New(func, obj, type); +} +static PyObject* +__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op) +{ #if PY_MAJOR_VERSION >= 3 - "'%.50s' object has no attribute '%U'", - tp->tp_name, attr_name); + return PyUnicode_FromFormat("", + op->func_qualname, (void *)op); #else - "'%.50s' object has no attribute '%.400s'", - tp->tp_name, PyString_AS_STRING(attr_name)); + return PyString_FromFormat("", + PyString_AsString(op->func_qualname), (void *)op); #endif - return NULL; } -static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { - PyObject *descr; - PyTypeObject *tp = Py_TYPE(obj); - if (unlikely(!PyString_Check(attr_name))) { - return PyObject_GenericGetAttr(obj, attr_name); - } - assert(!tp->tp_dictoffset); - descr = _PyType_Lookup(tp, attr_name); - if (unlikely(!descr)) { - return __Pyx_RaiseGenericGetAttributeError(tp, attr_name); - } - Py_INCREF(descr); - #if PY_MAJOR_VERSION < 3 - if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS))) - #endif - { - descrgetfunc f = Py_TYPE(descr)->tp_descr_get; - if (unlikely(f)) { - PyObject *res = f(descr, obj, (PyObject *)tp); - Py_DECREF(descr); - return res; +static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) { + PyCFunctionObject* f = (PyCFunctionObject*)func; + PyCFunction meth = f->m_ml->ml_meth; + Py_ssize_t size; + switch (f->m_ml->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) { + case METH_VARARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) + return (*meth)(self, arg); + break; + case METH_VARARGS | METH_KEYWORDS: + return (*(PyCFunctionWithKeywords)meth)(self, arg, kw); + case METH_NOARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { + size = PyTuple_GET_SIZE(arg); + if (likely(size == 0)) + return (*meth)(self, NULL); + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); + return NULL; + } + break; + case METH_O: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { + size = PyTuple_GET_SIZE(arg); + if (likely(size == 1)) { + PyObject *result, *arg0; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + arg0 = PyTuple_GET_ITEM(arg, 0); + #else + arg0 = PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL; + #endif + result = (*meth)(self, arg0); + #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) + Py_DECREF(arg0); + #endif + return result; + } + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); + return NULL; } + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags in " + "__Pyx_CyFunction_Call. METH_OLDARGS is no " + "longer supported!"); + return NULL; } - return descr; + PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", + f->m_ml->ml_name); + return NULL; } -#endif - -/* PyObject_GenericGetAttr */ - #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 -static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) { - if (unlikely(Py_TYPE(obj)->tp_dictoffset)) { - return PyObject_GenericGetAttr(obj, attr_name); +static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { + return __Pyx_CyFunction_CallMethod(func, ((PyCFunctionObject*)func)->m_self, arg, kw); +} +static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) { + PyObject *result; + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func; + if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { + Py_ssize_t argc; + PyObject *new_args; + PyObject *self; + argc = PyTuple_GET_SIZE(args); + new_args = PyTuple_GetSlice(args, 1, argc); + if (unlikely(!new_args)) + return NULL; + self = PyTuple_GetItem(args, 0); + if (unlikely(!self)) { + Py_DECREF(new_args); + return NULL; + } + result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); + Py_DECREF(new_args); + } else { + result = __Pyx_CyFunction_Call(func, args, kw); } - return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name); + return result; } +static PyTypeObject __pyx_CyFunctionType_type = { + PyVarObject_HEAD_INIT(0, 0) + "cython_function_or_method", + sizeof(__pyx_CyFunctionObject), + 0, + (destructor) __Pyx_CyFunction_dealloc, + 0, + 0, + 0, +#if PY_MAJOR_VERSION < 3 + 0, +#else + 0, #endif - -/* SetVTable */ - static int __Pyx_SetVtable(PyObject *dict, void *vtable) { -#if PY_VERSION_HEX >= 0x02070000 - PyObject *ob = PyCapsule_New(vtable, 0, 0); + (reprfunc) __Pyx_CyFunction_repr, + 0, + 0, + 0, + 0, + __Pyx_CyFunction_CallAsMethod, + 0, + 0, + 0, + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, + 0, + (traverseproc) __Pyx_CyFunction_traverse, + (inquiry) __Pyx_CyFunction_clear, + 0, +#if PY_VERSION_HEX < 0x030500A0 + offsetof(__pyx_CyFunctionObject, func_weakreflist), #else - PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); + offsetof(PyCFunctionObject, m_weakreflist), #endif - if (!ob) - goto bad; - if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0) - goto bad; - Py_DECREF(ob); + 0, + 0, + __pyx_CyFunction_methods, + __pyx_CyFunction_members, + __pyx_CyFunction_getsets, + 0, + 0, + __Pyx_CyFunction_descr_get, + 0, + offsetof(__pyx_CyFunctionObject, func_dict), + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if PY_VERSION_HEX >= 0x030400a1 + 0, +#endif +}; +static int __pyx_CyFunction_init(void) { + __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type); + if (unlikely(__pyx_CyFunctionType == NULL)) { + return -1; + } return 0; +} +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults = PyObject_Malloc(size); + if (unlikely(!m->defaults)) + return PyErr_NoMemory(); + memset(m->defaults, 0, size); + m->defaults_pyobjects = pyobjects; + return m->defaults; +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_tuple = tuple; + Py_INCREF(tuple); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_kwdict = dict; + Py_INCREF(dict); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->func_annotations = dict; + Py_INCREF(dict); +} + +/* Py3ClassCreate */ + static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, + PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) { + PyObject *ns; + if (metaclass) { + PyObject *prep = __Pyx_PyObject_GetAttrStr(metaclass, __pyx_n_s_prepare); + if (prep) { + PyObject *pargs = PyTuple_Pack(2, name, bases); + if (unlikely(!pargs)) { + Py_DECREF(prep); + return NULL; + } + ns = PyObject_Call(prep, pargs, mkw); + Py_DECREF(prep); + Py_DECREF(pargs); + } else { + if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError))) + return NULL; + PyErr_Clear(); + ns = PyDict_New(); + } + } else { + ns = PyDict_New(); + } + if (unlikely(!ns)) + return NULL; + if (unlikely(PyObject_SetItem(ns, __pyx_n_s_module, modname) < 0)) goto bad; + if (unlikely(PyObject_SetItem(ns, __pyx_n_s_qualname, qualname) < 0)) goto bad; + if (unlikely(doc && PyObject_SetItem(ns, __pyx_n_s_doc, doc) < 0)) goto bad; + return ns; bad: - Py_XDECREF(ob); - return -1; + Py_DECREF(ns); + return NULL; } - -/* SetupReduce */ - static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { - int ret; - PyObject *name_attr; - name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name_2); - if (likely(name_attr)) { - ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); - } else { - ret = -1; - } - if (unlikely(ret < 0)) { - PyErr_Clear(); - ret = 0; - } - Py_XDECREF(name_attr); - return ret; +static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, + PyObject *dict, PyObject *mkw, + int calculate_metaclass, int allow_py2_metaclass) { + PyObject *result, *margs; + PyObject *owned_metaclass = NULL; + if (allow_py2_metaclass) { + owned_metaclass = PyObject_GetItem(dict, __pyx_n_s_metaclass); + if (owned_metaclass) { + metaclass = owned_metaclass; + } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) { + PyErr_Clear(); + } else { + return NULL; + } + } + if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) { + metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases); + Py_XDECREF(owned_metaclass); + if (unlikely(!metaclass)) + return NULL; + owned_metaclass = metaclass; + } + margs = PyTuple_Pack(3, name, bases, dict); + if (unlikely(!margs)) { + result = NULL; + } else { + result = PyObject_Call(metaclass, margs, mkw); + Py_DECREF(margs); + } + Py_XDECREF(owned_metaclass); + return result; } -static int __Pyx_setup_reduce(PyObject* type_obj) { - int ret = 0; - PyObject *object_reduce = NULL; - PyObject *object_reduce_ex = NULL; - PyObject *reduce = NULL; - PyObject *reduce_ex = NULL; - PyObject *reduce_cython = NULL; - PyObject *setstate = NULL; - PyObject *setstate_cython = NULL; -#if CYTHON_USE_PYTYPE_LOOKUP - if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto GOOD; + +/* Globals */ + static PyObject* __Pyx_Globals(void) { + Py_ssize_t i; + PyObject *names; + PyObject *globals = __pyx_d; + Py_INCREF(globals); + names = PyObject_Dir(__pyx_m); + if (!names) + goto bad; + for (i = PyList_GET_SIZE(names)-1; i >= 0; i--) { +#if CYTHON_COMPILING_IN_PYPY + PyObject* name = PySequence_ITEM(names, i); + if (!name) + goto bad; #else - if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto GOOD; + PyObject* name = PyList_GET_ITEM(names, i); #endif -#if CYTHON_USE_PYTYPE_LOOKUP - object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD; -#else - object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD; + if (!PyDict_Contains(globals, name)) { + PyObject* value = __Pyx_GetAttr(__pyx_m, name); + if (!value) { +#if CYTHON_COMPILING_IN_PYPY + Py_DECREF(name); #endif - reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto BAD; - if (reduce_ex == object_reduce_ex) { -#if CYTHON_USE_PYTYPE_LOOKUP - object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD; -#else - object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD; + goto bad; + } + if (PyDict_SetItem(globals, name, value) < 0) { +#if CYTHON_COMPILING_IN_PYPY + Py_DECREF(name); #endif - reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto BAD; - if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { - reduce_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_cython); if (unlikely(!reduce_cython)) goto BAD; - ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto BAD; - ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto BAD; - setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate); - if (!setstate) PyErr_Clear(); - if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) { - setstate_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate_cython); if (unlikely(!setstate_cython)) goto BAD; - ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto BAD; - ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto BAD; + Py_DECREF(value); + goto bad; } - PyType_Modified((PyTypeObject*)type_obj); } - } - goto GOOD; -BAD: - if (!PyErr_Occurred()) - PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); - ret = -1; -GOOD: -#if !CYTHON_USE_PYTYPE_LOOKUP - Py_XDECREF(object_reduce); - Py_XDECREF(object_reduce_ex); -#endif - Py_XDECREF(reduce); - Py_XDECREF(reduce_ex); - Py_XDECREF(reduce_cython); - Py_XDECREF(setstate); - Py_XDECREF(setstate_cython); - return ret; -} - -/* GetVTable */ - static void* __Pyx_GetVtable(PyObject *dict) { - void* ptr; - PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable); - if (!ob) - goto bad; -#if PY_VERSION_HEX >= 0x02070000 - ptr = PyCapsule_GetPointer(ob, 0); -#else - ptr = PyCObject_AsVoidPtr(ob); +#if CYTHON_COMPILING_IN_PYPY + Py_DECREF(name); #endif - if (!ptr && !PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type"); - Py_DECREF(ob); - return ptr; + } + Py_DECREF(names); + return globals; bad: - Py_XDECREF(ob); + Py_XDECREF(names); + Py_XDECREF(globals); return NULL; } /* CLineInTraceback */ - #ifndef CYTHON_CLINE_IN_TRACEBACK + #ifndef CYTHON_CLINE_IN_TRACEBACK static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; @@ -50380,7 +63840,7 @@ static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_li #endif /* CodeObjectCache */ - static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { int start = 0, mid = 0, end = count - 1; if (end >= 0 && code_line > entries[end].code_line) { return count; @@ -50460,7 +63920,7 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { } /* AddTraceback */ - #include "compile.h" + #include "compile.h" #include "frameobject.h" #include "traceback.h" static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( @@ -50568,8 +64028,8 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) { #endif - /* MemviewSliceIsContig */ - static int + /* MemviewSliceIsContig */ + static int __pyx_memviewslice_is_contig(const __Pyx_memviewslice mvs, char order, int ndim) { int i, index, step, start; @@ -50591,7 +64051,7 @@ __pyx_memviewslice_is_contig(const __Pyx_memviewslice mvs, char order, int ndim) } /* OverlappingSlices */ - static void + static void __pyx_get_array_memory_extents(__Pyx_memviewslice *slice, void **out_start, void **out_end, int ndim, size_t itemsize) @@ -50627,7 +64087,7 @@ __pyx_slices_overlap(__Pyx_memviewslice *slice1, } /* Capsule */ - static CYTHON_INLINE PyObject * + static CYTHON_INLINE PyObject * __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) { PyObject *cobj; @@ -50640,7 +64100,7 @@ __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { const int neg_one = (int) -1, const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -50671,7 +64131,7 @@ __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) } /* CIntFromPyVerify */ - #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) @@ -50693,7 +64153,7 @@ __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) { const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -50724,7 +64184,7 @@ __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value) { const int32_t neg_one = (int32_t) -1, const_zero = (int32_t) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -50755,7 +64215,7 @@ __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -50786,7 +64246,7 @@ __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) { const char neg_one = (char) -1, const_zero = (char) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -50817,7 +64277,7 @@ __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint8_t(uint8_t value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint8_t(uint8_t value) { const uint8_t neg_one = (uint8_t) -1, const_zero = (uint8_t) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -50848,7 +64308,69 @@ __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int8_t(int8_t value) { + const int8_t neg_one = (int8_t) -1, const_zero = (int8_t) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(int8_t) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int8_t) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int8_t) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(int8_t) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int8_t) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(int8_t), + little, !is_unsigned); + } +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int16_t(int16_t value) { + const int16_t neg_one = (int16_t) -1, const_zero = (int16_t) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(int16_t) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int16_t) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int16_t) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(int16_t) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int16_t) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(int16_t), + little, !is_unsigned); + } +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value) { const uint16_t neg_one = (uint16_t) -1, const_zero = (uint16_t) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -50878,8 +64400,39 @@ __pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig) } } +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value) { + const int64_t neg_one = (int64_t) -1, const_zero = (int64_t) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(int64_t) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int64_t) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int64_t) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(int64_t) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int64_t) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(int64_t), + little, !is_unsigned); + } +} + /* MemviewSliceCopyTemplate */ - static __Pyx_memviewslice + static __Pyx_memviewslice __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, const char *mode, int ndim, size_t sizeof_dtype, int contig_flag, @@ -50946,7 +64499,7 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, } /* CIntFromPy */ - static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { + static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { const int neg_one = (int) -1, const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -51135,7 +64688,7 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, } /* CIntFromPy */ - static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) { + static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) { const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -51324,7 +64877,7 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, } /* CIntFromPy */ - static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *x) { + static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *x) { const int32_t neg_one = (int32_t) -1, const_zero = (int32_t) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -51513,7 +65066,7 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, } /* CIntFromPy */ - static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { + static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -51702,19 +65255,19 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, } /* CIntFromPy */ - static CYTHON_INLINE uint16_t __Pyx_PyInt_As_uint16_t(PyObject *x) { - const uint16_t neg_one = (uint16_t) -1, const_zero = (uint16_t) 0; + static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) { + const char neg_one = (char) -1, const_zero = (char) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { - if (sizeof(uint16_t) < sizeof(long)) { - __PYX_VERIFY_RETURN_INT(uint16_t, long, PyInt_AS_LONG(x)) + if (sizeof(char) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(char, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } - return (uint16_t) val; + return (char) val; } } else #endif @@ -51723,32 +65276,32 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { - case 0: return (uint16_t) 0; - case 1: __PYX_VERIFY_RETURN_INT(uint16_t, digit, digits[0]) + case 0: return (char) 0; + case 1: __PYX_VERIFY_RETURN_INT(char, digit, digits[0]) case 2: - if (8 * sizeof(uint16_t) > 1 * PyLong_SHIFT) { + if (8 * sizeof(char) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(uint16_t) >= 2 * PyLong_SHIFT) { - return (uint16_t) (((((uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0])); + __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) >= 2 * PyLong_SHIFT) { + return (char) (((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])); } } break; case 3: - if (8 * sizeof(uint16_t) > 2 * PyLong_SHIFT) { + if (8 * sizeof(char) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(uint16_t) >= 3 * PyLong_SHIFT) { - return (uint16_t) (((((((uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0])); + __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) >= 3 * PyLong_SHIFT) { + return (char) (((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])); } } break; case 4: - if (8 * sizeof(uint16_t) > 3 * PyLong_SHIFT) { + if (8 * sizeof(char) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(uint16_t) >= 4 * PyLong_SHIFT) { - return (uint16_t) (((((((((uint16_t)digits[3]) << PyLong_SHIFT) | (uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0])); + __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) >= 4 * PyLong_SHIFT) { + return (char) (((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])); } } break; @@ -51762,86 +65315,86 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) - return (uint16_t) -1; + return (char) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif - if (sizeof(uint16_t) <= sizeof(unsigned long)) { - __PYX_VERIFY_RETURN_INT_EXC(uint16_t, unsigned long, PyLong_AsUnsignedLong(x)) + if (sizeof(char) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(char, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG - } else if (sizeof(uint16_t) <= sizeof(unsigned PY_LONG_LONG)) { - __PYX_VERIFY_RETURN_INT_EXC(uint16_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) + } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(char, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { - case 0: return (uint16_t) 0; - case -1: __PYX_VERIFY_RETURN_INT(uint16_t, sdigit, (sdigit) (-(sdigit)digits[0])) - case 1: __PYX_VERIFY_RETURN_INT(uint16_t, digit, +digits[0]) + case 0: return (char) 0; + case -1: __PYX_VERIFY_RETURN_INT(char, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(char, digit, +digits[0]) case -2: - if (8 * sizeof(uint16_t) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(char) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(uint16_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(uint16_t) - 1 > 2 * PyLong_SHIFT) { - return (uint16_t) (((uint16_t)-1)*(((((uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]))); + __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) { + return (char) (((char)-1)*(((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); } } break; case 2: - if (8 * sizeof(uint16_t) > 1 * PyLong_SHIFT) { + if (8 * sizeof(char) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(uint16_t) - 1 > 2 * PyLong_SHIFT) { - return (uint16_t) ((((((uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]))); + __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) { + return (char) ((((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); } } break; case -3: - if (8 * sizeof(uint16_t) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(uint16_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(uint16_t) - 1 > 3 * PyLong_SHIFT) { - return (uint16_t) (((uint16_t)-1)*(((((((uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]))); + __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) { + return (char) (((char)-1)*(((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); } } break; case 3: - if (8 * sizeof(uint16_t) > 2 * PyLong_SHIFT) { + if (8 * sizeof(char) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(uint16_t) - 1 > 3 * PyLong_SHIFT) { - return (uint16_t) ((((((((uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]))); + __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) { + return (char) ((((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); } } break; case -4: - if (8 * sizeof(uint16_t) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(uint16_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(uint16_t) - 1 > 4 * PyLong_SHIFT) { - return (uint16_t) (((uint16_t)-1)*(((((((((uint16_t)digits[3]) << PyLong_SHIFT) | (uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]))); + __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) { + return (char) (((char)-1)*(((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); } } break; case 4: - if (8 * sizeof(uint16_t) > 3 * PyLong_SHIFT) { + if (8 * sizeof(char) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(uint16_t) - 1 > 4 * PyLong_SHIFT) { - return (uint16_t) ((((((((((uint16_t)digits[3]) << PyLong_SHIFT) | (uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]))); + __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) { + return (char) ((((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); } } break; } #endif - if (sizeof(uint16_t) <= sizeof(long)) { - __PYX_VERIFY_RETURN_INT_EXC(uint16_t, long, PyLong_AsLong(x)) + if (sizeof(char) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(char, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG - } else if (sizeof(uint16_t) <= sizeof(PY_LONG_LONG)) { - __PYX_VERIFY_RETURN_INT_EXC(uint16_t, PY_LONG_LONG, PyLong_AsLongLong(x)) + } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(char, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } @@ -51850,7 +65403,7 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else - uint16_t val; + char val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { @@ -51870,28 +65423,28 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, return val; } #endif - return (uint16_t) -1; + return (char) -1; } } else { - uint16_t val; + char val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); - if (!tmp) return (uint16_t) -1; - val = __Pyx_PyInt_As_uint16_t(tmp); + if (!tmp) return (char) -1; + val = __Pyx_PyInt_As_char(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, - "value too large to convert to uint16_t"); - return (uint16_t) -1; + "value too large to convert to char"); + return (char) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to uint16_t"); - return (uint16_t) -1; + "can't convert negative value to char"); + return (char) -1; } /* CIntFromPy */ - static CYTHON_INLINE uint8_t __Pyx_PyInt_As_uint8_t(PyObject *x) { + static CYTHON_INLINE uint8_t __Pyx_PyInt_As_uint8_t(PyObject *x) { const uint8_t neg_one = (uint8_t) -1, const_zero = (uint8_t) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -52080,19 +65633,19 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, } /* CIntFromPy */ - static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) { - const char neg_one = (char) -1, const_zero = (char) 0; + static CYTHON_INLINE uint16_t __Pyx_PyInt_As_uint16_t(PyObject *x) { + const uint16_t neg_one = (uint16_t) -1, const_zero = (uint16_t) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { - if (sizeof(char) < sizeof(long)) { - __PYX_VERIFY_RETURN_INT(char, long, PyInt_AS_LONG(x)) + if (sizeof(uint16_t) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(uint16_t, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } - return (char) val; + return (uint16_t) val; } } else #endif @@ -52101,32 +65654,32 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { - case 0: return (char) 0; - case 1: __PYX_VERIFY_RETURN_INT(char, digit, digits[0]) + case 0: return (uint16_t) 0; + case 1: __PYX_VERIFY_RETURN_INT(uint16_t, digit, digits[0]) case 2: - if (8 * sizeof(char) > 1 * PyLong_SHIFT) { + if (8 * sizeof(uint16_t) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) >= 2 * PyLong_SHIFT) { - return (char) (((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])); + __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(uint16_t) >= 2 * PyLong_SHIFT) { + return (uint16_t) (((((uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0])); } } break; case 3: - if (8 * sizeof(char) > 2 * PyLong_SHIFT) { + if (8 * sizeof(uint16_t) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) >= 3 * PyLong_SHIFT) { - return (char) (((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])); + __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(uint16_t) >= 3 * PyLong_SHIFT) { + return (uint16_t) (((((((uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0])); } } break; case 4: - if (8 * sizeof(char) > 3 * PyLong_SHIFT) { + if (8 * sizeof(uint16_t) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) >= 4 * PyLong_SHIFT) { - return (char) (((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])); + __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(uint16_t) >= 4 * PyLong_SHIFT) { + return (uint16_t) (((((((((uint16_t)digits[3]) << PyLong_SHIFT) | (uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0])); } } break; @@ -52140,86 +65693,86 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) - return (char) -1; + return (uint16_t) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif - if (sizeof(char) <= sizeof(unsigned long)) { - __PYX_VERIFY_RETURN_INT_EXC(char, unsigned long, PyLong_AsUnsignedLong(x)) + if (sizeof(uint16_t) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(uint16_t, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG - } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) { - __PYX_VERIFY_RETURN_INT_EXC(char, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) + } else if (sizeof(uint16_t) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(uint16_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { - case 0: return (char) 0; - case -1: __PYX_VERIFY_RETURN_INT(char, sdigit, (sdigit) (-(sdigit)digits[0])) - case 1: __PYX_VERIFY_RETURN_INT(char, digit, +digits[0]) + case 0: return (uint16_t) 0; + case -1: __PYX_VERIFY_RETURN_INT(uint16_t, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(uint16_t, digit, +digits[0]) case -2: - if (8 * sizeof(char) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(uint16_t) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) { - return (char) (((char)-1)*(((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); + __PYX_VERIFY_RETURN_INT(uint16_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(uint16_t) - 1 > 2 * PyLong_SHIFT) { + return (uint16_t) (((uint16_t)-1)*(((((uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]))); } } break; case 2: - if (8 * sizeof(char) > 1 * PyLong_SHIFT) { + if (8 * sizeof(uint16_t) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) { - return (char) ((((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); + __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(uint16_t) - 1 > 2 * PyLong_SHIFT) { + return (uint16_t) ((((((uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]))); } } break; case -3: - if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(uint16_t) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) { - return (char) (((char)-1)*(((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); + __PYX_VERIFY_RETURN_INT(uint16_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(uint16_t) - 1 > 3 * PyLong_SHIFT) { + return (uint16_t) (((uint16_t)-1)*(((((((uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]))); } } break; case 3: - if (8 * sizeof(char) > 2 * PyLong_SHIFT) { + if (8 * sizeof(uint16_t) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) { - return (char) ((((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); + __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(uint16_t) - 1 > 3 * PyLong_SHIFT) { + return (uint16_t) ((((((((uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]))); } } break; case -4: - if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(uint16_t) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) { - return (char) (((char)-1)*(((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); + __PYX_VERIFY_RETURN_INT(uint16_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(uint16_t) - 1 > 4 * PyLong_SHIFT) { + return (uint16_t) (((uint16_t)-1)*(((((((((uint16_t)digits[3]) << PyLong_SHIFT) | (uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]))); } } break; case 4: - if (8 * sizeof(char) > 3 * PyLong_SHIFT) { + if (8 * sizeof(uint16_t) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) { - return (char) ((((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]))); + __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(uint16_t) - 1 > 4 * PyLong_SHIFT) { + return (uint16_t) ((((((((((uint16_t)digits[3]) << PyLong_SHIFT) | (uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]))); } } break; } #endif - if (sizeof(char) <= sizeof(long)) { - __PYX_VERIFY_RETURN_INT_EXC(char, long, PyLong_AsLong(x)) + if (sizeof(uint16_t) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(uint16_t, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG - } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) { - __PYX_VERIFY_RETURN_INT_EXC(char, PY_LONG_LONG, PyLong_AsLongLong(x)) + } else if (sizeof(uint16_t) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(uint16_t, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif } } @@ -52228,7 +65781,7 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else - char val; + uint16_t val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { @@ -52248,67 +65801,468 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs, return val; } #endif - return (char) -1; + return (uint16_t) -1; } } else { - char val; + uint16_t val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); - if (!tmp) return (char) -1; - val = __Pyx_PyInt_As_char(tmp); + if (!tmp) return (uint16_t) -1; + val = __Pyx_PyInt_As_uint16_t(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, - "value too large to convert to char"); - return (char) -1; + "value too large to convert to uint16_t"); + return (uint16_t) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to char"); - return (char) -1; + "can't convert negative value to uint16_t"); + return (uint16_t) -1; } -/* FetchCommonType */ - static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { - PyObject* fake_module; - PyTypeObject* cached_type = NULL; - fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI); - if (!fake_module) return NULL; - Py_INCREF(fake_module); - cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name); - if (cached_type) { - if (!PyType_Check((PyObject*)cached_type)) { - PyErr_Format(PyExc_TypeError, - "Shared Cython type %.200s is not a type object", - type->tp_name); - goto bad; +/* CIntFromPy */ + static CYTHON_INLINE int16_t __Pyx_PyInt_As_int16_t(PyObject *x) { + const int16_t neg_one = (int16_t) -1, const_zero = (int16_t) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(int16_t) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(int16_t, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int16_t) val; } - if (cached_type->tp_basicsize != type->tp_basicsize) { - PyErr_Format(PyExc_TypeError, - "Shared Cython type %.200s has the wrong size, try recompiling", - type->tp_name); - goto bad; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int16_t) 0; + case 1: __PYX_VERIFY_RETURN_INT(int16_t, digit, digits[0]) + case 2: + if (8 * sizeof(int16_t) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int16_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int16_t) >= 2 * PyLong_SHIFT) { + return (int16_t) (((((int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(int16_t) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int16_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int16_t) >= 3 * PyLong_SHIFT) { + return (int16_t) (((((((int16_t)digits[2]) << PyLong_SHIFT) | (int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(int16_t) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int16_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int16_t) >= 4 * PyLong_SHIFT) { + return (int16_t) (((((((((int16_t)digits[3]) << PyLong_SHIFT) | (int16_t)digits[2]) << PyLong_SHIFT) | (int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int16_t) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(int16_t) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(int16_t, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int16_t) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int16_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int16_t) 0; + case -1: __PYX_VERIFY_RETURN_INT(int16_t, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(int16_t, digit, +digits[0]) + case -2: + if (8 * sizeof(int16_t) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int16_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int16_t) - 1 > 2 * PyLong_SHIFT) { + return (int16_t) (((int16_t)-1)*(((((int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(int16_t) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int16_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int16_t) - 1 > 2 * PyLong_SHIFT) { + return (int16_t) ((((((int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(int16_t) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int16_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int16_t) - 1 > 3 * PyLong_SHIFT) { + return (int16_t) (((int16_t)-1)*(((((((int16_t)digits[2]) << PyLong_SHIFT) | (int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(int16_t) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int16_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int16_t) - 1 > 3 * PyLong_SHIFT) { + return (int16_t) ((((((((int16_t)digits[2]) << PyLong_SHIFT) | (int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(int16_t) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int16_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int16_t) - 1 > 4 * PyLong_SHIFT) { + return (int16_t) (((int16_t)-1)*(((((((((int16_t)digits[3]) << PyLong_SHIFT) | (int16_t)digits[2]) << PyLong_SHIFT) | (int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(int16_t) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int16_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int16_t) - 1 > 4 * PyLong_SHIFT) { + return (int16_t) ((((((((((int16_t)digits[3]) << PyLong_SHIFT) | (int16_t)digits[2]) << PyLong_SHIFT) | (int16_t)digits[1]) << PyLong_SHIFT) | (int16_t)digits[0]))); + } + } + break; + } +#endif + if (sizeof(int16_t) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(int16_t, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int16_t) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int16_t, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + int16_t val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (int16_t) -1; } } else { - if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; - PyErr_Clear(); - if (PyType_Ready(type) < 0) goto bad; - if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0) - goto bad; - Py_INCREF(type); - cached_type = type; + int16_t val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int16_t) -1; + val = __Pyx_PyInt_As_int16_t(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int16_t"); + return (int16_t) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int16_t"); + return (int16_t) -1; +} + +/* CIntFromPy */ + static CYTHON_INLINE int8_t __Pyx_PyInt_As_int8_t(PyObject *x) { + const int8_t neg_one = (int8_t) -1, const_zero = (int8_t) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(int8_t) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(int8_t, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int8_t) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int8_t) 0; + case 1: __PYX_VERIFY_RETURN_INT(int8_t, digit, digits[0]) + case 2: + if (8 * sizeof(int8_t) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int8_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int8_t) >= 2 * PyLong_SHIFT) { + return (int8_t) (((((int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(int8_t) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int8_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int8_t) >= 3 * PyLong_SHIFT) { + return (int8_t) (((((((int8_t)digits[2]) << PyLong_SHIFT) | (int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(int8_t) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int8_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int8_t) >= 4 * PyLong_SHIFT) { + return (int8_t) (((((((((int8_t)digits[3]) << PyLong_SHIFT) | (int8_t)digits[2]) << PyLong_SHIFT) | (int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int8_t) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(int8_t) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(int8_t, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int8_t) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int8_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int8_t) 0; + case -1: __PYX_VERIFY_RETURN_INT(int8_t, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(int8_t, digit, +digits[0]) + case -2: + if (8 * sizeof(int8_t) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int8_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int8_t) - 1 > 2 * PyLong_SHIFT) { + return (int8_t) (((int8_t)-1)*(((((int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(int8_t) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int8_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int8_t) - 1 > 2 * PyLong_SHIFT) { + return (int8_t) ((((((int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(int8_t) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int8_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int8_t) - 1 > 3 * PyLong_SHIFT) { + return (int8_t) (((int8_t)-1)*(((((((int8_t)digits[2]) << PyLong_SHIFT) | (int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(int8_t) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int8_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int8_t) - 1 > 3 * PyLong_SHIFT) { + return (int8_t) ((((((((int8_t)digits[2]) << PyLong_SHIFT) | (int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(int8_t) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int8_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int8_t) - 1 > 4 * PyLong_SHIFT) { + return (int8_t) (((int8_t)-1)*(((((((((int8_t)digits[3]) << PyLong_SHIFT) | (int8_t)digits[2]) << PyLong_SHIFT) | (int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(int8_t) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int8_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int8_t) - 1 > 4 * PyLong_SHIFT) { + return (int8_t) ((((((((((int8_t)digits[3]) << PyLong_SHIFT) | (int8_t)digits[2]) << PyLong_SHIFT) | (int8_t)digits[1]) << PyLong_SHIFT) | (int8_t)digits[0]))); + } + } + break; + } +#endif + if (sizeof(int8_t) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(int8_t, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int8_t) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int8_t, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + int8_t val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (int8_t) -1; + } + } else { + int8_t val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int8_t) -1; + val = __Pyx_PyInt_As_int8_t(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int8_t"); + return (int8_t) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int8_t"); + return (int8_t) -1; +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS(enum __pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS value) { + const enum __pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS neg_one = (enum __pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS) -1, const_zero = (enum __pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(enum __pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(enum __pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(enum __pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(enum __pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(enum __pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(enum __pyx_t_5pysam_18libcalignedsegment_CIGAR_OPS), + little, !is_unsigned); + } +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum____pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS(enum __pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS value) { + const enum __pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS neg_one = (enum __pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS) -1, const_zero = (enum __pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(enum __pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(enum __pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(enum __pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(enum __pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(enum __pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(enum __pyx_t_5pysam_18libcalignedsegment_SAM_FLAGS), + little, !is_unsigned); } -done: - Py_DECREF(fake_module); - return cached_type; -bad: - Py_XDECREF(cached_type); - cached_type = NULL; - goto done; } /* PyObjectCallMethod1 */ - static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { + static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { PyObject *result = NULL; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(method))) { @@ -52359,7 +66313,7 @@ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name } /* CoroutineBase */ - #include + #include #include #define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom) static int __Pyx_PyGen__FetchStopIterationValue(CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject **pvalue) { @@ -53071,7 +67025,7 @@ static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit( } /* PatchModuleWithCoroutine */ - static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) { + static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) { #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) int result; PyObject *globals, *result_obj; @@ -53111,7 +67065,7 @@ static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit( } /* PatchGeneratorABC */ - #ifndef CYTHON_REGISTER_ABCS + #ifndef CYTHON_REGISTER_ABCS #define CYTHON_REGISTER_ABCS 1 #endif #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) @@ -53168,7 +67122,7 @@ static int __Pyx_patch_abc(void) { } /* Generator */ - static PyMethodDef __pyx_Generator_methods[] = { + static PyMethodDef __pyx_Generator_methods[] = { {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O, (char*) PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")}, {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS, @@ -53260,7 +67214,7 @@ static int __pyx_Generator_init(void) { } /* IsLittleEndian */ - static CYTHON_INLINE int __Pyx_Is_Little_Endian(void) + static CYTHON_INLINE int __Pyx_Is_Little_Endian(void) { union { uint32_t u32; @@ -53271,7 +67225,7 @@ static int __pyx_Generator_init(void) { } /* BufferFormatCheck */ - static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx, + static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx, __Pyx_BufFmt_StackElem* stack, __Pyx_TypeInfo* type) { stack[0].field = &ctx->root; @@ -53773,7 +67727,7 @@ static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const cha } /* TypeInfoCompare */ - static int + static int __pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b) { int i; @@ -53814,7 +67768,7 @@ __pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b) } /* MemviewSliceValidateAndInit */ - static int + static int __pyx_check_strides(Py_buffer *buf, int dim, int ndim, int spec) { if (buf->shape[dim] <= 1) @@ -53996,7 +67950,7 @@ static int __Pyx_ValidateAndInit_memviewslice( } /* ObjectToMemviewSlice */ - static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn_uint32_t(PyObject *obj, int writable_flag) { + static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn_uint32_t(PyObject *obj, int writable_flag) { __Pyx_memviewslice result = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_BufFmt_StackElem stack[1]; int axes_specs[] = { (__Pyx_MEMVIEW_DIRECT | __Pyx_MEMVIEW_STRIDED) }; @@ -54019,7 +67973,7 @@ static int __Pyx_ValidateAndInit_memviewslice( } /* CheckBinaryVersion */ - static int __Pyx_check_binary_version(void) { + static int __Pyx_check_binary_version(void) { char ctversion[4], rtversion[4]; PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); @@ -54035,7 +67989,7 @@ static int __Pyx_ValidateAndInit_memviewslice( } /* FunctionExport */ - static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) { + static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) { PyObject *d = 0; PyObject *cobj = 0; union { @@ -54072,7 +68026,7 @@ static int __Pyx_ValidateAndInit_memviewslice( } /* ModuleImport */ - #ifndef __PYX_HAVE_RT_ImportModule + #ifndef __PYX_HAVE_RT_ImportModule #define __PYX_HAVE_RT_ImportModule static PyObject *__Pyx_ImportModule(const char *name) { PyObject *py_name = 0; @@ -54090,7 +68044,7 @@ static PyObject *__Pyx_ImportModule(const char *name) { #endif /* TypeImport */ - #ifndef __PYX_HAVE_RT_ImportType + #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict) @@ -54155,7 +68109,7 @@ static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class #endif /* FunctionImport */ - #ifndef __PYX_HAVE_RT_ImportFunction + #ifndef __PYX_HAVE_RT_ImportFunction #define __PYX_HAVE_RT_ImportFunction static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) { PyObject *d = 0; @@ -54209,7 +68163,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** #endif /* InitStrings */ - static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { diff --git a/pysam/libcalignedsegment.pxd b/pysam/libcalignedsegment.pxd index f1d59d1cc..48ca93f7a 100644 --- a/pysam/libcalignedsegment.pxd +++ b/pysam/libcalignedsegment.pxd @@ -4,9 +4,9 @@ cdef extern from "htslib_util.h": # add *nbytes* into the variable length data of *src* at *pos* bam1_t * pysam_bam_update(bam1_t * b, - size_t nbytes_old, - size_t nbytes_new, - uint8_t * pos) + size_t nbytes_old, + size_t nbytes_new, + uint8_t * pos) # now: static int aux_type2size(int) @@ -19,20 +19,14 @@ cdef extern from "htslib_util.h": int pysam_bam_get_l_aux(bam1_t * b) char pysam_bam_seqi(uint8_t * s, int i) - uint16_t pysam_get_bin(bam1_t * b) uint8_t pysam_get_qual(bam1_t * b) - uint8_t pysam_get_l_qname(bam1_t * b) - uint16_t pysam_get_flag(bam1_t * b) - uint16_t pysam_get_n_cigar(bam1_t * b) - void pysam_set_bin(bam1_t * b, uint16_t v) + uint32_t pysam_get_n_cigar(bam1_t * b) void pysam_set_qual(bam1_t * b, uint8_t v) - void pysam_set_l_qname(bam1_t * b, uint8_t v) - void pysam_set_flag(bam1_t * b, uint16_t v) - void pysam_set_n_cigar(bam1_t * b, uint16_t v) + void pysam_set_n_cigar(bam1_t * b, uint32_t v) void pysam_update_flag(bam1_t * b, uint16_t v, uint16_t flag) -from pysam.libcalignmentfile cimport AlignmentFile +from pysam.libcalignmentfile cimport AlignmentFile, AlignmentHeader ctypedef AlignmentFile AlignmentFile_t @@ -42,8 +36,8 @@ cdef class AlignedSegment: # object that this AlignedSegment represents cdef bam1_t * _delegate - # the file from which this AlignedSegment originates (can be None) - cdef AlignmentFile _alignment_file + # the header that a read is associated with + cdef readonly AlignmentHeader header # caching of array properties for quick access cdef object cache_query_qualities @@ -63,7 +57,10 @@ cdef class AlignedSegment: cpdef has_tag(self, tag) # returns a valid sam alignment string - cpdef tostring(self, AlignmentFile_t handle) + cpdef to_string(self) + + # returns a valid sam alignment string (deprecated) + cpdef tostring(self, htsfile=*) cdef class PileupColumn: @@ -71,12 +68,14 @@ cdef class PileupColumn: cdef int tid cdef int pos cdef int n_pu - cdef AlignmentFile _alignment_file - + cdef AlignmentHeader header + cdef uint32_t min_base_quality + cdef uint8_t * buf + cdef char * reference_sequence cdef class PileupRead: - cdef AlignedSegment _alignment cdef int32_t _qpos + cdef AlignedSegment _alignment cdef int _indel cdef int _level cdef uint32_t _is_del @@ -84,8 +83,21 @@ cdef class PileupRead: cdef uint32_t _is_tail cdef uint32_t _is_refskip -# factor methods -cdef makeAlignedSegment(bam1_t * src, AlignmentFile alignment_file) -cdef makePileupColumn(bam_pileup1_t ** plp, int tid, int pos, int n_pu, AlignmentFile alignment_file) -cdef inline makePileupRead(bam_pileup1_t * src, AlignmentFile alignment_file) -cdef inline uint32_t get_alignment_length(bam1_t * src) +# factory methods +cdef AlignedSegment makeAlignedSegment( + bam1_t * src, + AlignmentHeader header) + +cdef PileupColumn makePileupColumn( + bam_pileup1_t ** plp, + int tid, + int pos, + int n_pu, + uint32_t min_base_quality, + char * reference_sequence, + AlignmentHeader header) + +cdef PileupRead makePileupRead(bam_pileup1_t * src, + AlignmentHeader header) + +cdef uint32_t get_alignment_length(bam1_t * src) diff --git a/pysam/libcalignedsegment.pyx b/pysam/libcalignedsegment.pyx index c95bb13de..edb5eaa22 100644 --- a/pysam/libcalignedsegment.pyx +++ b/pysam/libcalignedsegment.pyx @@ -55,16 +55,23 @@ ############################################################################### import re import array +import json +import string import ctypes import struct cimport cython from cpython cimport array as c_array from cpython.version cimport PY_MAJOR_VERSION -from cpython cimport PyErr_SetString, PyBytes_FromStringAndSize +from cpython cimport PyBytes_FromStringAndSize from libc.string cimport strchr from cpython cimport array as c_array +from libc.stdint cimport INT8_MIN, INT16_MIN, INT32_MIN, \ + INT8_MAX, INT16_MAX, INT32_MAX, \ + UINT8_MAX, UINT16_MAX, UINT32_MAX +from libc.stdio cimport snprintf +from pysam.libchtslib cimport HTS_IDX_NOCOOR from pysam.libcutils cimport force_bytes, force_str, \ charptr_to_str, charptr_to_bytes from pysam.libcutils cimport qualities_to_qualitystring, qualitystring_to_array, \ @@ -74,27 +81,74 @@ from pysam.libcutils cimport qualities_to_qualitystring, qualitystring_to_array, cdef char * htslib_types = 'cCsSiIf' cdef char * parray_types = 'bBhHiIf' +cdef bint IS_PYTHON3 = PY_MAJOR_VERSION >= 3 + # translation tables # cigar code to character and vice versa cdef char* CODE2CIGAR= "MIDNSHP=XB" cdef int NCIGAR_CODES = 10 -if PY_MAJOR_VERSION >= 3: +# dimensioned for 8000 pileup limit (+ insertions/deletions) +cdef uint32_t MAX_PILEUP_BUFFER_SIZE = 10000 + +if IS_PYTHON3: CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR)) + maketrans = str.maketrans else: CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR)) + maketrans = string.maketrans CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=XB])") +# names for keys in dictionary representation of an AlignedSegment +KEY_NAMES = ["name", "flag", "ref_name", "ref_pos", "map_quality", "cigar", + "next_ref_name", "next_ref_pos", "length", "seq", "qual", "tags"] + ##################################################################### # C multiplication with wrapping around cdef inline uint32_t c_mul(uint32_t a, uint32_t b): return (a * b) & 0xffffffff -##################################################################### -# typecode guessing +cdef inline uint8_t tolower(uint8_t ch): + if ch >= 65 and ch <= 90: + return ch + 32 + else: + return ch + + +cdef inline uint8_t toupper(uint8_t ch): + if ch >= 97 and ch <= 122: + return ch - 32 + else: + return ch + + +cdef inline uint8_t strand_mark_char(uint8_t ch, bam1_t *b): + if ch == '=': + if bam_is_rev(b): + return ',' + else: + return '.' + else: + if bam_is_rev(b): + return tolower(ch) + else: + return toupper(ch) + + +cdef inline bint pileup_base_qual_skip(bam_pileup1_t * p, uint32_t threshold): + cdef uint32_t c + if p.qpos < p.b.core.l_qseq: + c = bam_get_qual(p.b)[p.qpos] + else: + c = 0 + if c < threshold: + return True + return False + + cdef inline char map_typecode_htslib_to_python(uint8_t s): """map an htslib typecode to the corresponding python typecode to be used in the struct or array modules.""" @@ -106,6 +160,7 @@ cdef inline char map_typecode_htslib_to_python(uint8_t s): return 0 return parray_types[f - htslib_types] + cdef inline uint8_t map_typecode_python_to_htslib(char s): """determine value type from type code of array""" cdef char * f = strchr(parray_types, s) @@ -113,6 +168,29 @@ cdef inline uint8_t map_typecode_python_to_htslib(char s): return 0 return htslib_types[f - parray_types] + +cdef inline void update_bin(bam1_t * src): + if src.core.flag & BAM_FUNMAP: + # treat alignment as length of 1 for unmapped reads + src.core.bin = hts_reg2bin( + src.core.pos, + src.core.pos + 1, + 14, + 5) + elif pysam_get_n_cigar(src): + src.core.bin = hts_reg2bin( + src.core.pos, + bam_endpos(src), + 14, + 5) + else: + src.core.bin = hts_reg2bin( + src.core.pos, + src.core.pos + 1, + 14, + 5) + + # optional tag data manipulation cdef convert_binary_tag(uint8_t * tag): """return bytesize, number of values and array of values @@ -142,18 +220,33 @@ cdef convert_binary_tag(uint8_t * tag): return byte_size, nvalues, c_values -cdef inline uint8_t get_value_code(value, value_type=None): - '''guess type code for a *value*. If *value_type* is None, - the type code will be inferred based on the Python type of - *value*''' - cdef uint8_t typecode - cdef char * _char_type +cdef inline uint8_t get_tag_typecode(value, value_type=None): + """guess type code for a *value*. If *value_type* is None, the type + code will be inferred based on the Python type of *value* + """ + # 0 is unknown typecode + cdef char typecode = 0 + if value_type is None: if isinstance(value, int): - typecode = 'i' + if value < 0: + if value >= INT8_MIN: + typecode = 'c' + elif value >= INT16_MIN: + typecode = 's' + elif value >= INT32_MIN: + typecode = 'i' + # unsigned ints + else: + if value <= UINT8_MAX: + typecode = 'C' + elif value <= UINT16_MAX: + typecode = 'S' + elif value <= UINT32_MAX: + typecode = 'I' elif isinstance(value, float): - typecode = 'd' + typecode = 'f' elif isinstance(value, str): typecode = 'Z' elif isinstance(value, bytes): @@ -162,93 +255,98 @@ cdef inline uint8_t get_value_code(value, value_type=None): isinstance(value, list) or \ isinstance(value, tuple): typecode = 'B' - else: - return 0 else: - if value_type not in 'Zidf': - return 0 - value_type = force_bytes(value_type) - _char_type = value_type - typecode = (_char_type)[0] + if value_type in 'aAsSIcCZidfH': + typecode = force_bytes(value_type)[0] return typecode -cdef inline bytes getTypecode(value, maximum_value=None): +cdef inline uint8_t get_btag_typecode(value, min_value=None, max_value=None): '''returns the value typecode of a value. - If max is specified, the approprite type is - returned for a range where value is the minimum. + If max is specified, the appropriate type is returned for a range + where value is the minimum. + + Note that this method returns types from the extended BAM alphabet + of types that includes tags that are not part of the SAM + specification. ''' - if maximum_value is None: - maximum_value = value - cdef bytes valuetype + cdef uint8_t typecode t = type(value) if t is float: - valuetype = b'f' + typecode = 'f' elif t is int: + if max_value is None: + max_value = value + if min_value is None: + min_value = value # signed ints - if value < 0: - if value >= -128 and maximum_value < 128: - valuetype = b'c' - elif value >= -32768 and maximum_value < 32768: - valuetype = b's' - elif value < -2147483648 or maximum_value >= 2147483648: + if min_value < 0: + if min_value >= INT8_MIN and max_value <= INT8_MAX: + typecode = 'c' + elif min_value >= INT16_MIN and max_value <= INT16_MAX: + typecode = 's' + elif min_value >= INT32_MIN or max_value <= INT32_MAX: + typecode = 'i' + else: raise ValueError( "at least one signed integer out of range of " "BAM/SAM specification") - else: - valuetype = b'i' # unsigned ints else: - if maximum_value < 256: - valuetype = b'C' - elif maximum_value < 65536: - valuetype = b'S' - elif maximum_value >= 4294967296: + if max_value <= UINT8_MAX: + typecode = 'C' + elif max_value <= UINT16_MAX: + typecode = 'S' + elif max_value <= UINT32_MAX: + typecode = 'I' + else: raise ValueError( "at least one integer out of range of BAM/SAM specification") - else: - valuetype = b'I' else: # Note: hex strings (H) are not supported yet if t is not bytes: value = value.encode('ascii') if len(value) == 1: - valuetype = b'A' + typecode = 'A' else: - valuetype = b'Z' + typecode = 'Z' + + return typecode - return valuetype +# mapping python array.array and htslib typecodes to struct typecodes +DATATYPE2FORMAT = { + ord('c'): ('b', 1), + ord('C'): ('B', 1), + ord('s'): ('h', 2), + ord('S'): ('H', 2), + ord('i'): ('i', 4), + ord('I'): ('I', 4), + ord('f'): ('f', 4), + ord('d'): ('d', 8), + ord('A'): ('c', 1), + ord('a'): ('c', 1)} -cdef inline packTags(tags): + +cdef inline pack_tags(tags): """pack a list of tags. Each tag is a tuple of (tag, tuple). Values are packed into the most space efficient data structure possible unless the tag contains a third field with the typecode. - Returns a format string and the associated list of arguments - to be used in a call to struct.pack_into. + Returns a format string and the associated list of arguments to be + used in a call to struct.pack_into. """ fmts, args = ["<"], [] - cdef char array_typecode - - datatype2format = { - b'c': ('b', 1), - b'C': ('B', 1), - b's': ('h', 2), - b'S': ('H', 2), - b'i': ('i', 4), - b'I': ('I', 4), - b'f': ('f', 4), - b'A': ('c', 1)} - + # htslib typecode + cdef uint8_t typecode for tag in tags: if len(tag) == 2: @@ -259,65 +357,76 @@ cdef inline packTags(tags): else: raise ValueError("malformatted tag: %s" % str(tag)) + if valuetype is None: + typecode = 0 + else: + # only first character in valuecode matters + if IS_PYTHON3: + typecode = force_bytes(valuetype)[0] + else: + typecode = ord(valuetype[0]) + pytag = force_bytes(pytag) - valuetype = force_bytes(valuetype) - t = type(value) + pytype = type(value) - if t is tuple or t is list: + if pytype is tuple or pytype is list: # binary tags from tuples or lists - if valuetype is None: + if not typecode: # automatically determine value type - first value # determines type. If there is a mix of types, the # result is undefined. - valuetype = getTypecode(min(value), max(value)) + typecode = get_btag_typecode(min(value), + min_value=min(value), + max_value=max(value)) - if valuetype not in datatype2format: - raise ValueError("invalid value type '%s'" % valuetype) + if typecode not in DATATYPE2FORMAT: + raise ValueError("invalid value type '{}'".format(chr(typecode))) - datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0]) + datafmt = "2sBBI%i%s" % (len(value), DATATYPE2FORMAT[typecode][0]) args.extend([pytag[:2], - b"B", - valuetype, + ord("B"), + typecode, len(value)] + list(value)) elif isinstance(value, array.array): # binary tags from arrays - if valuetype is None: - array_typecode = map_typecode_python_to_htslib(ord(value.typecode)) + if typecode == 0: + typecode = map_typecode_python_to_htslib(ord(value.typecode)) - if array_typecode == 0: - raise ValueError("unsupported type code '{}'" - .format(value.typecode)) - - valuetype = force_bytes(chr(array_typecode)) - - if valuetype not in datatype2format: - raise ValueError("invalid value type '%s' (%s)" % - (valuetype, type(valuetype))) + if typecode == 0: + raise ValueError("unsupported type code '{}'".format(value.typecode)) + if typecode not in DATATYPE2FORMAT: + raise ValueError("invalid value type '{}' ({})".format(chr(typecode), array.typecode)) + # use array.tostring() to retrieve byte representation and # save as bytes - datafmt = "2sccI%is" % (len(value) * datatype2format[valuetype][1]) + datafmt = "2sBBI%is" % (len(value) * DATATYPE2FORMAT[typecode][1]) args.extend([pytag[:2], - b"B", - valuetype, + ord("B"), + typecode, len(value), force_bytes(value.tostring())]) else: - if valuetype is None: - valuetype = getTypecode(value) - - if valuetype in b"AZ": + if typecode == 0: + typecode = get_tag_typecode(value) + if typecode == 0: + raise ValueError("could not deduce typecode for value {}".format(value)) + + if typecode == 'a' or typecode == 'A' or typecode == 'Z' or typecode == 'H': value = force_bytes(value) - if valuetype == b"Z": - datafmt = "2sc%is" % (len(value)+1) - else: - datafmt = "2sc%s" % datatype2format[valuetype][0] + if typecode == "a": + typecode = 'A' + if typecode == 'Z' or typecode == 'H': + datafmt = "2sB%is" % (len(value)+1) + else: + datafmt = "2sB%s" % DATATYPE2FORMAT[typecode][0] + args.extend([pytag[:2], - valuetype, + typecode, value]) fmts.append(datafmt) @@ -325,9 +434,41 @@ cdef inline packTags(tags): return "".join(fmts), args -cdef inline int32_t calculateQueryLength(bam1_t * src): +cdef inline int32_t calculateQueryLengthWithoutHardClipping(bam1_t * src): """return query length computed from CIGAR alignment. + Length ignores hard-clipped bases. + + Return 0 if there is no CIGAR alignment. + """ + + cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) + + if cigar_p == NULL: + return 0 + + cdef uint32_t k, qpos + cdef int op + qpos = 0 + + for k from 0 <= k < pysam_get_n_cigar(src): + op = cigar_p[k] & BAM_CIGAR_MASK + + if op == BAM_CMATCH or \ + op == BAM_CINS or \ + op == BAM_CSOFT_CLIP or \ + op == BAM_CEQUAL or \ + op == BAM_CDIFF: + qpos += cigar_p[k] >> BAM_CIGAR_SHIFT + + return qpos + + +cdef inline int32_t calculateQueryLengthWithHardClipping(bam1_t * src): + """return query length computed from CIGAR alignment. + + Length includes hard-clipped bases. + Return 0 if there is no CIGAR alignment. """ @@ -356,44 +497,45 @@ cdef inline int32_t calculateQueryLength(bam1_t * src): cdef inline int32_t getQueryStart(bam1_t *src) except -1: cdef uint32_t * cigar_p - cdef uint32_t k, op cdef uint32_t start_offset = 0 + cdef uint32_t k, op - if pysam_get_n_cigar(src): - cigar_p = pysam_bam_get_cigar(src); - for k from 0 <= k < pysam_get_n_cigar(src): - op = cigar_p[k] & BAM_CIGAR_MASK - if op == BAM_CHARD_CLIP: - if start_offset != 0 and start_offset != src.core.l_qseq: - PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string') - return -1 - elif op == BAM_CSOFT_CLIP: - start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT - else: - break + cigar_p = pysam_bam_get_cigar(src); + for k from 0 <= k < pysam_get_n_cigar(src): + op = cigar_p[k] & BAM_CIGAR_MASK + if op == BAM_CHARD_CLIP: + if start_offset != 0 and start_offset != src.core.l_qseq: + raise ValueError('Invalid clipping in CIGAR string') + elif op == BAM_CSOFT_CLIP: + start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT + else: + break return start_offset cdef inline int32_t getQueryEnd(bam1_t *src) except -1: - cdef uint32_t * cigar_p - cdef uint32_t k, op + cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) cdef uint32_t end_offset = src.core.l_qseq + cdef uint32_t k, op # if there is no sequence, compute length from cigar string if end_offset == 0: - end_offset = calculateQueryLength(src) - - # walk backwards in cigar string - if pysam_get_n_cigar(src) > 1: - cigar_p = pysam_bam_get_cigar(src); + for k from 0 <= k < pysam_get_n_cigar(src): + op = cigar_p[k] & BAM_CIGAR_MASK + if op == BAM_CMATCH or \ + op == BAM_CINS or \ + op == BAM_CEQUAL or \ + op == BAM_CDIFF or \ + (op == BAM_CSOFT_CLIP and end_offset == 0): + end_offset += cigar_p[k] >> BAM_CIGAR_SHIFT + else: + # walk backwards in cigar string for k from pysam_get_n_cigar(src) > k >= 1: op = cigar_p[k] & BAM_CIGAR_MASK if op == BAM_CHARD_CLIP: - if end_offset != 0 and end_offset != src.core.l_qseq: - PyErr_SetString(ValueError, - 'Invalid clipping in CIGAR string') - return -1 + if end_offset != src.core.l_qseq: + raise ValueError('Invalid clipping in CIGAR string') elif op == BAM_CSOFT_CLIP: end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT else: @@ -450,38 +592,53 @@ cdef inline object getQualitiesInRange(bam1_t *src, ##################################################################### -## private factory methods +## factory methods for instantiating extension classes cdef class AlignedSegment -cdef makeAlignedSegment(bam1_t * src, AlignmentFile alignment_file): +cdef AlignedSegment makeAlignedSegment(bam1_t *src, + AlignmentHeader header): '''return an AlignedSegment object constructed from `src`''' # note that the following does not call __init__ cdef AlignedSegment dest = AlignedSegment.__new__(AlignedSegment) dest._delegate = bam_dup1(src) - dest._alignment_file = alignment_file + dest.header = header return dest cdef class PileupColumn -cdef makePileupColumn(bam_pileup1_t ** plp, int tid, int pos, - int n_pu, AlignmentFile alignment_file): +cdef PileupColumn makePileupColumn(bam_pileup1_t ** plp, + int tid, + int pos, + int n_pu, + uint32_t min_base_quality, + char * reference_sequence, + AlignmentHeader header): '''return a PileupColumn object constructed from pileup in `plp` and setting additional attributes. ''' # note that the following does not call __init__ cdef PileupColumn dest = PileupColumn.__new__(PileupColumn) - dest._alignment_file = alignment_file + dest.header = header dest.plp = plp dest.tid = tid dest.pos = pos dest.n_pu = n_pu + dest.min_base_quality = min_base_quality + dest.reference_sequence = reference_sequence + dest.buf = calloc(MAX_PILEUP_BUFFER_SIZE, sizeof(uint8_t)) + if dest.buf == NULL: + raise MemoryError("could not allocate pileup buffer") + return dest + cdef class PileupRead -cdef inline makePileupRead(bam_pileup1_t * src, AlignmentFile alignment_file): +cdef PileupRead makePileupRead(bam_pileup1_t *src, + AlignmentHeader header): '''return a PileupRead object construted from a bam_pileup1_t * object.''' + # note that the following does not call __init__ cdef PileupRead dest = PileupRead.__new__(PileupRead) - dest._alignment = makeAlignedSegment(src.b, alignment_file) + dest._alignment = makeAlignedSegment(src.b, header) dest._qpos = src.qpos dest._indel = src.indel dest._level = src.level @@ -492,8 +649,8 @@ cdef inline makePileupRead(bam_pileup1_t * src, AlignmentFile alignment_file): return dest -cdef inline uint32_t get_alignment_length(bam1_t * src): - cdef int k = 0 +cdef inline uint32_t get_alignment_length(bam1_t *src): + cdef uint32_t k = 0 cdef uint32_t l = 0 if src == NULL: return 0 @@ -501,7 +658,7 @@ cdef inline uint32_t get_alignment_length(bam1_t * src): if cigar_p == NULL: return 0 cdef int op - cdef int n = pysam_get_n_cigar(src) + cdef uint32_t n = pysam_get_n_cigar(src) for k from 0 <= k < n: op = cigar_p[k] & BAM_CIGAR_MASK if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP: @@ -510,6 +667,32 @@ cdef inline uint32_t get_alignment_length(bam1_t * src): return l +cdef inline uint32_t get_md_reference_length(char * md_tag): + cdef int l = 0 + cdef int md_idx = 0 + cdef int nmatches = 0 + + while md_tag[md_idx] != 0: + if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57: + nmatches *= 10 + nmatches += md_tag[md_idx] - 48 + md_idx += 1 + continue + else: + l += nmatches + nmatches = 0 + if md_tag[md_idx] == '^': + md_idx += 1 + while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: + md_idx += 1 + l += 1 + else: + md_idx += 1 + l += 1 + + l += nmatches + return l + # TODO: avoid string copying for getSequenceInRange, reconstituneSequenceFromMD, ... cdef inline bytes build_alignment_sequence(bam1_t * src): """return expanded sequence from MD tag. @@ -535,6 +718,10 @@ cdef inline bytes build_alignment_sequence(bam1_t * src): if src == NULL: return None + cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD") + if md_tag_ptr == NULL: + return None + cdef uint32_t start = getQueryStart(src) cdef uint32_t end = getQueryEnd(src) # get read sequence, taking into account soft-clipping @@ -557,7 +744,7 @@ cdef inline bytes build_alignment_sequence(bam1_t * src): cdef char * s = calloc(max_len + 1, sizeof(char)) if s == NULL: raise ValueError( - "could not allocated sequence of length %i" % max_len) + "could not allocate sequence of length %i" % max_len) for k from 0 <= k < pysam_get_n_cigar(src): op = cigar_p[k] & BAM_CIGAR_MASK @@ -588,16 +775,27 @@ cdef inline bytes build_alignment_sequence(bam1_t * src): "Padding (BAM_CPAD, 6) is currently not supported. " "Please implement. Sorry about that.") - cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD") - if md_tag_ptr == NULL: - seq = PyBytes_FromStringAndSize(s, s_idx) - free(s) - return seq - cdef char * md_tag = bam_aux2Z(md_tag_ptr) cdef int md_idx = 0 s_idx = 0 + # Check if MD tag is valid by matching CIGAR length to MD tag defined length + # Insertions would be in addition to what is described by MD, so we calculate + # the number of insertions seperately. + cdef int insertions = 0 + + while s[s_idx] != 0: + if s[s_idx] >= 'a': + insertions += 1 + s_idx += 1 + s_idx = 0 + + cdef uint32_t md_len = get_md_reference_length(md_tag) + if md_len + insertions > max_len: + raise AssertionError( + "Invalid MD tag: MD length {} mismatch with CIGAR length {} and {} insertions".format( + md_len, max_len, insertions)) + while md_tag[md_idx] != 0: # c is numerical if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57: @@ -619,7 +817,7 @@ cdef inline bytes build_alignment_sequence(bam1_t * src): if md_tag[md_idx] == '^': md_idx += 1 while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90: - assert s[s_idx] == '-' + # assert s[s_idx] == '-' s[s_idx] = md_tag[md_idx] s_idx += 1 md_idx += 1 @@ -644,6 +842,60 @@ cdef inline bytes build_alignment_sequence(bam1_t * src): return seq +cdef inline bytes build_reference_sequence(bam1_t * src): + """return the reference sequence in the region that is covered by the + alignment of the read to the reference. + + This method requires the MD tag to be set. + + """ + cdef uint32_t k, i, l + cdef int op + cdef int s_idx = 0 + ref_seq = build_alignment_sequence(src) + if ref_seq is None: + raise ValueError("MD tag not present") + + cdef char * s = calloc(len(ref_seq) + 1, sizeof(char)) + if s == NULL: + raise ValueError( + "could not allocate sequence of length %i" % len(ref_seq)) + + cdef char * cref_seq = ref_seq + cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) + cdef uint32_t r_idx = 0 + for k from 0 <= k < pysam_get_n_cigar(src): + op = cigar_p[k] & BAM_CIGAR_MASK + l = cigar_p[k] >> BAM_CIGAR_SHIFT + if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: + for i from 0 <= i < l: + s[s_idx] = cref_seq[r_idx] + r_idx += 1 + s_idx += 1 + elif op == BAM_CDEL: + for i from 0 <= i < l: + s[s_idx] = cref_seq[r_idx] + r_idx += 1 + s_idx += 1 + elif op == BAM_CREF_SKIP: + pass + elif op == BAM_CINS: + r_idx += l + elif op == BAM_CSOFT_CLIP: + pass + elif op == BAM_CHARD_CLIP: + pass # advances neither + elif op == BAM_CPAD: + raise NotImplementedError( + "Padding (BAM_CPAD, 6) is currently not supported. " + "Please implement. Sorry about that.") + + seq = PyBytes_FromStringAndSize(s, s_idx) + free(s) + + return seq + + cdef class AlignedSegment: '''Class representing an aligned segment. @@ -661,18 +913,29 @@ cdef class AlignedSegment: One issue to look out for is that the sequence should always be set *before* the quality scores. Setting the sequence will also erase any quality scores that were set previously. + + Parameters + ---------- + + header -- :class:`~pysam.AlignmentHeader` object to map numerical + identifiers to chromosome names. If not given, an empty + header is created. ''' # Now only called when instances are created from Python - def __init__(self): + def __init__(self, AlignmentHeader header=None): # see bam_init1 self._delegate = calloc(1, sizeof(bam1_t)) + if self._delegate == NULL: + raise MemoryError("could not allocated memory of {} bytes".format(sizeof(bam1_t))) # allocate some memory. If size is 0, calloc does not return a # pointer that can be passed to free() so allocate 40 bytes # for a new read self._delegate.m_data = 40 self._delegate.data = calloc( self._delegate.m_data, 1) + if self._delegate.data == NULL: + raise MemoryError("could not allocate memory of {} bytes".format(self._delegate.m_data)) self._delegate.l_data = 0 # set some data to make read approximately legit. # Note, SAM writing fails with q_name of length 0 @@ -687,7 +950,9 @@ cdef class AlignedSegment: self.cache_query_alignment_qualities = None self.cache_query_sequence = None self.cache_query_alignment_sequence = None - + + self.header = header + def __dealloc__(self): bam_destroy1(self._delegate) @@ -699,7 +964,7 @@ cdef class AlignedSegment: As a result :term:`tid` is shown instead of the reference name. Similarly, the tags field is returned in its parsed state. - To get a valid SAM record, use :meth:`tostring`. + To get a valid SAM record, use :meth:`to_string`. """ # sam-parsing is done in sam.c/bam_format1_core which # requires a valid header. @@ -717,15 +982,14 @@ cdef class AlignedSegment: self.tags))) def __copy__(self): - return makeAlignedSegment(self._delegate, self._alignment_file) + return makeAlignedSegment(self._delegate, self.header) def __deepcopy__(self, memo): - return makeAlignedSegment(self._delegate, self._alignment_file) + return makeAlignedSegment(self._delegate, self.header) def compare(self, AlignedSegment other): '''return -1,0,1, if contents in this are binary <,=,> to *other* - ''' cdef int retval, x @@ -748,10 +1012,13 @@ cdef class AlignedSegment: if t == o: return 0 + cdef uint8_t *a = &t.core + cdef uint8_t *b = &o.core + retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t)) - if retval: return retval + # cmp(t.l_data, o.l_data) retval = (t.l_data > o.l_data) - (t.l_data < o.l_data) if retval: @@ -781,32 +1048,24 @@ cdef class AlignedSegment: return hash_value - cpdef tostring(self, AlignmentFile_t htsfile): + cpdef to_string(self): """returns a string representation of the aligned segment. - The output format is valid SAM format. - - Parameters - ---------- - - htsfile -- AlignmentFile object to map numerical - identifiers to chromosome names. + The output format is valid SAM format if a header is associated + with the AlignedSegment. """ - cdef int n_targets = htsfile.header.n_targets - - if self._delegate.core.tid >= n_targets \ - or self._delegate.core.mtid >= n_targets: - raise ValueError('htsfile does not match aligned segment') - cdef kstring_t line line.l = line.m = 0 line.s = NULL - if sam_format1(htsfile.header, self._delegate, &line) < 0: - if line.m: - free(line.s) - raise ValueError('sam_format failed') - + if self.header: + if sam_format1(self.header.ptr, self._delegate, &line) < 0: + if line.m: + free(line.s) + raise ValueError('sam_format failed') + else: + raise NotImplementedError("todo") + ret = force_str(line.s[:line.l]) if line.m: @@ -814,61 +1073,153 @@ cdef class AlignedSegment: return ret + @classmethod + def fromstring(cls, sam, AlignmentHeader header): + """parses a string representation of the aligned segment. + + The input format should be valid SAM format. + + Parameters + ---------- + sam -- :term:`SAM` formatted string + + """ + cdef AlignedSegment dest = cls.__new__(cls) + dest._delegate = calloc(1, sizeof(bam1_t)) + dest.header = header + + cdef kstring_t line + line.l = line.m = len(sam) + _sam = force_bytes(sam) + line.s = _sam + + sam_parse1(&line, dest.header.ptr, dest._delegate) + + return dest + + cpdef tostring(self, htsfile=None): + """deprecated, use :meth:`to_string()` instead. + + Parameters + ---------- + + htsfile -- (deprecated) AlignmentFile object to map numerical + identifiers to chromosome names. This parameter is present + for backwards compatibility and ignored. + """ + + return self.to_string() + + def to_dict(self): + """returns a json representation of the aligned segment. + + Field names are abbreviated versions of the class attributes. + """ + # let htslib do the string conversions, but treat optional field properly as list + vals = self.to_string().split("\t") + n = len(KEY_NAMES) - 1 + return dict(list(zip(KEY_NAMES[:-1], vals[:n])) + [(KEY_NAMES[-1], vals[n:])]) + + @classmethod + def from_dict(cls, sam_dict, AlignmentHeader header): + """parses a dictionary representation of the aligned segment. + + Parameters + ---------- + sam_dict -- dictionary of alignment values, keys corresponding to output from + :meth:`todict()`. + + """ + # let htslib do the parsing + # the tags field can be missing + return cls.fromstring( + "\t".join((sam_dict[x] for x in KEY_NAMES[:-1])) + + "\t" + + "\t".join(sam_dict.get(KEY_NAMES[-1], [])), header) + ######################################################## ## Basic attributes in order of appearance in SAM format property query_name: """the query template name (None if not present)""" def __get__(self): - cdef bam1_t * src - src = self._delegate - if pysam_get_l_qname(src) == 0: + + cdef bam1_t * src = self._delegate + if src.core.l_qname == 0: return None + return charptr_to_str(pysam_bam_get_qname(src)) def __set__(self, qname): + if qname is None or len(qname) == 0: return - if len(qname) >= 255: - raise ValueError("query length out of range {} > 254".format( + # See issue #447 + # (The threshold is 252 chars, but this includes a \0 byte. + if len(qname) > 251: + raise ValueError("query length out of range {} > 251".format( len(qname))) qname = force_bytes(qname) - cdef bam1_t * src - cdef int l - cdef char * p + cdef bam1_t * src = self._delegate + # the qname is \0 terminated + cdef uint8_t l = len(qname) + 1 - src = self._delegate - p = pysam_bam_get_qname(src) + cdef char * p = pysam_bam_get_qname(src) + cdef uint8_t l_extranul = 0 - # the qname is \0 terminated - l = len(qname) + 1 - pysam_bam_update(src, - pysam_get_l_qname(src), - l, - p) + if l % 4 != 0: + l_extranul = 4 - l % 4 - pysam_set_l_qname(src, l) + cdef bam1_t * retval = pysam_bam_update(src, + src.core.l_qname, + l + l_extranul, + p) + if retval == NULL: + raise MemoryError("could not allocate memory") + src.core.l_extranul = l_extranul + src.core.l_qname = l + l_extranul + # re-acquire pointer to location in memory # as it might have moved p = pysam_bam_get_qname(src) strncpy(p, qname, l) + # x might be > 255 + cdef uint16_t x = 0 + + for x from l <= x < l + l_extranul: + p[x] = '\0' property flag: """properties flag""" def __get__(self): - return pysam_get_flag(self._delegate) + return self._delegate.core.flag def __set__(self, flag): - pysam_set_flag(self._delegate, flag) + self._delegate.core.flag = flag property reference_name: - """:term:`reference` name (None if no AlignmentFile is associated)""" + """:term:`reference` name""" def __get__(self): - if self._alignment_file is not None: - return self._alignment_file.getrname(self._delegate.core.tid) - return None + if self._delegate.core.tid == -1: + return None + if self.header: + return self.header.get_reference_name(self._delegate.core.tid) + else: + raise ValueError("reference_name unknown if no header associated with record") + def __set__(self, reference): + cdef int tid + if reference is None or reference == "*": + self._delegate.core.tid = -1 + elif self.header: + tid = self.header.get_tid(reference) + if tid < 0: + raise ValueError("reference {} does not exist in header".format( + reference)) + self._delegate.core.tid = tid + else: + raise ValueError("reference_name can not be set if no header associated with record") property reference_id: """:term:`reference` ID @@ -877,35 +1228,27 @@ cdef class AlignedSegment: This field contains the index of the reference sequence in the sequence dictionary. To obtain the name of the - reference sequence, use - :meth:`pysam.AlignmentFile.getrname()` + reference sequence, use :meth:`get_reference_name()` """ - def __get__(self): return self._delegate.core.tid - def __set__(self, tid): self._delegate.core.tid = tid + def __get__(self): + return self._delegate.core.tid + def __set__(self, tid): + if tid != -1 and self.header and not self.header.is_valid_tid(tid): + raise ValueError("reference id {} does not exist in header".format( + tid)) + self._delegate.core.tid = tid property reference_start: """0-based leftmost coordinate""" - def __get__(self): return self._delegate.core.pos + def __get__(self): + return self._delegate.core.pos def __set__(self, pos): ## setting the position requires updating the "bin" attribute cdef bam1_t * src src = self._delegate src.core.pos = pos - if pysam_get_n_cigar(src): - pysam_set_bin(src, - hts_reg2bin( - src.core.pos, - bam_endpos(src), - 14, - 5)) - else: - pysam_set_bin(src, - hts_reg2bin( - src.core.pos, - src.core.pos + 1, - 14, - 5)) + update_bin(src) property mapping_quality: """mapping quality""" @@ -953,17 +1296,39 @@ cdef class AlignedSegment: property next_reference_id: """the :term:`reference` id of the mate/next read.""" - def __get__(self): return self._delegate.core.mtid + def __get__(self): + return self._delegate.core.mtid def __set__(self, mtid): + if mtid != -1 and self.header and not self.header.is_valid_tid(mtid): + raise ValueError("reference id {} does not exist in header".format( + mtid)) self._delegate.core.mtid = mtid property next_reference_name: """:term:`reference` name of the mate/next read (None if no AlignmentFile is associated)""" def __get__(self): - if self._alignment_file is not None: - return self._alignment_file.getrname(self._delegate.core.mtid) - return None + if self._delegate.core.mtid == -1: + return None + if self.header: + return self.header.get_reference_name(self._delegate.core.mtid) + else: + raise ValueError("next_reference_name unknown if no header associated with record") + + def __set__(self, reference): + cdef int mtid + if reference is None or reference == "*": + self._delegate.core.mtid = -1 + elif reference == "=": + self._delegate.core.mtid = self._delegate.core.tid + elif self.header: + mtid = self.header.get_tid(reference) + if mtid < 0: + raise ValueError("reference {} does not exist in header".format( + reference)) + self._delegate.core.mtid = mtid + else: + raise ValueError("next_reference_name can not be set if no header associated with record") property next_reference_start: """the position of the mate/next read.""" @@ -1058,10 +1423,13 @@ cdef class AlignedSegment: src.core.l_qseq = l # change length of data field - pysam_bam_update(src, - nbytes_old, - nbytes_new, - p) + cdef bam1_t * retval = pysam_bam_update(src, + nbytes_old, + nbytes_new, + p) + + if retval == NULL: + raise MemoryError("could not allocate memory") if l > 0: # re-acquire pointer to location in memory @@ -1156,9 +1524,9 @@ cdef class AlignedSegment: property bin: """properties bin""" def __get__(self): - return pysam_get_bin(self._delegate) + return self._delegate.core.bin def __set__(self, bin): - pysam_set_bin(self._delegate, bin) + self._delegate.core.bin = bin ########################################################## @@ -1186,6 +1554,10 @@ cdef class AlignedSegment: return (self.flag & BAM_FUNMAP) != 0 def __set__(self, val): pysam_update_flag(self._delegate, val, BAM_FUNMAP) + # setting the unmapped flag requires recalculation of + # bin as alignment length is now implicitely 1 + update_bin(self._delegate) + property mate_is_unmapped: """true if the mate is unmapped""" def __get__(self): @@ -1344,14 +1716,17 @@ cdef class AlignedSegment: This the index of the first base in :attr:`seq` that is not soft-clipped. - """ def __get__(self): return getQueryStart(self._delegate) property query_alignment_end: """end index of the aligned query portion of the sequence (0-based, - exclusive)""" + exclusive) + + This the index just past the last base in :attr:`seq` that is not + soft-clipped. + """ def __get__(self): return getQueryEnd(self._delegate) @@ -1377,7 +1752,7 @@ cdef class AlignedSegment: thus be of the same length as the read. """ - cdef uint32_t k, i, pos + cdef uint32_t k, i, l, pos cdef int op cdef uint32_t * cigar_p cdef bam1_t * src @@ -1408,68 +1783,71 @@ cdef class AlignedSegment: return result - def infer_query_length(self, always=True): - """inferred read length from CIGAR string. + def infer_query_length(self, always=False): + """infer query length from CIGAR alignment. - If *always* is set to True, the read length - will be always inferred. If set to False, the length - of the read sequence will be returned if it is - available. + This method deduces the query length from the CIGAR alignment + but does not include hard-clipped bases. - Returns None if CIGAR string is not present. - """ + Returns None if CIGAR alignment is not present. - cdef uint32_t * cigar_p - cdef bam1_t * src + If *always* is set to True, `infer_read_length` is used instead. + This is deprecated and only present for backward compatibility. + """ + if always is True: + return self.infer_read_length() + cdef int32_t l = calculateQueryLengthWithoutHardClipping(self._delegate) + if l > 0: + return l + else: + return None - src = self._delegate + def infer_read_length(self): + """infer read length from CIGAR alignment. - if not always and src.core.l_qseq: - return src.core.l_qseq + This method deduces the read length from the CIGAR alignment + including hard-clipped bases. - return calculateQueryLength(src) + Returns None if CIGAR alignment is not present. + """ + cdef int32_t l = calculateQueryLengthWithHardClipping(self._delegate) + if l > 0: + return l + else: + return None def get_reference_sequence(self): - """return the reference sequence. + """return the reference sequence in the region that is covered by the + alignment of the read to the reference. This method requires the MD tag to be set. - """ - cdef uint32_t k, i - cdef int op - cdef bam1_t * src = self._delegate - ref_seq = force_str(build_alignment_sequence(src)) - if ref_seq is None: - raise ValueError("MD tag not present") - cdef uint32_t * cigar_p = pysam_bam_get_cigar(src) - cdef uint32_t r_idx = 0 - result = [] - for k from 0 <= k < pysam_get_n_cigar(src): - op = cigar_p[k] & BAM_CIGAR_MASK - l = cigar_p[k] >> BAM_CIGAR_SHIFT - if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF: - for i from 0 <= i < l: - result.append(ref_seq[r_idx]) - r_idx += 1 - elif op == BAM_CDEL: - for i from 0 <= i < l: - result.append(ref_seq[r_idx]) - r_idx += 1 - elif op == BAM_CREF_SKIP: - pass - elif op == BAM_CINS: - r_idx += l - elif op == BAM_CSOFT_CLIP: - pass - elif op == BAM_CHARD_CLIP: - pass # advances neither - elif op == BAM_CPAD: - raise NotImplementedError( - "Padding (BAM_CPAD, 6) is currently not supported. " - "Please implement. Sorry about that.") + """ + return force_str(build_reference_sequence(self._delegate)) - return "".join(result) + def get_forward_sequence(self): + """return the original read sequence. + + Reads mapping to the reverse strand will be reverse + complemented. + """ + s = force_str(self.query_sequence) + if self.is_reverse: + s = s.translate(maketrans("ACGTacgtNnXx", "TGCAtgcaNnXx"))[::-1] + return s + + def get_forward_qualities(self): + """return the original read sequence. + + Reads mapping to the reverse strand will be reverse + complemented. + """ + if self.is_reverse: + return self.query_qualities[::-1] + else: + return self.query_qualities + def get_aligned_pairs(self, matches_only=False, with_seq=False): """a list of aligned read (query) and reference positions. @@ -1506,7 +1884,8 @@ cdef class AlignedSegment: # read sequence, cigar and MD tag are consistent. if _with_seq: - ref_seq = force_str(self.get_reference_sequence()) + # force_str required for py2/py3 compatibility + ref_seq = force_str(build_reference_sequence(src)) if ref_seq is None: raise ValueError("MD tag not present") @@ -1677,7 +2056,9 @@ cdef class AlignedSegment: +-----+--------------+-----+ |X |BAM_CDIFF |8 | +-----+--------------+-----+ - |NM |NM tag |9 | + |B |BAM_CBACK |9 | + +-----+--------------+-----+ + |NM |NM tag |10 | +-----+--------------+-----+ If no cigar string is present, empty arrays will be returned. @@ -1756,6 +2137,8 @@ cdef class AlignedSegment: +-----+--------------+-----+ |X |BAM_CDIFF |8 | +-----+--------------+-----+ + |B |BAM_CBACK |9 | + +-----+--------------+-----+ .. note:: The output is a list of (operation, length) tuples, such as @@ -1771,7 +2154,7 @@ cdef class AlignedSegment: cdef uint32_t * cigar_p cdef bam1_t * src cdef uint32_t op, l - cdef int k + cdef uint32_t k src = self._delegate if pysam_get_n_cigar(src) == 0: @@ -1790,7 +2173,7 @@ cdef class AlignedSegment: cdef uint32_t * p cdef bam1_t * src cdef op, l - cdef int k, ncigar + cdef int k k = 0 @@ -1803,12 +2186,15 @@ cdef class AlignedSegment: if values is None: values = [] - ncigar = len(values) - # create space for cigar data within src.data - pysam_bam_update(src, - pysam_get_n_cigar(src) * 4, - ncigar * 4, - p) + cdef uint32_t ncigar = len(values) + + cdef bam1_t * retval = pysam_bam_update(src, + pysam_get_n_cigar(src) * 4, + ncigar * 4, + p) + + if retval == NULL: + raise MemoryError("could not allocate memory") # length is number of cigar operations, not bytes pysam_set_n_cigar(src, ncigar) @@ -1823,13 +2209,7 @@ cdef class AlignedSegment: k += 1 ## setting the cigar string requires updating the bin - pysam_set_bin(src, - hts_reg2bin( - src.core.pos, - bam_endpos(src), - 14, - 5)) - + update_bin(src) cpdef set_tag(self, tag, @@ -1840,24 +2220,56 @@ cdef class AlignedSegment: section. *value_type* describes the type of *value* that is to entered - into the alignment record.. It can be set explicitly to one - of the valid one-letter type codes. If unset, an appropriate - type will be chosen automatically. + into the alignment record. It can be set explicitly to one of + the valid one-letter type codes. If unset, an appropriate type + will be chosen automatically based on the python type of + *value*. An existing value of the same *tag* will be overwritten unless - replace is set to False. This is usually not recommened as a + *replace* is set to False. This is usually not recommened as a tag may only appear once in the optional alignment section. If *value* is None, the tag will be deleted. + + This method accepts valid SAM specification value types, which + are:: + + A: printable char + i: signed int + f: float + Z: printable string + H: Byte array in hex format + B: Integer or numeric array + + Additionally, it will accept the integer BAM types ('cCsSI') + + For htslib compatibility, 'a' is synonymous with 'A' and the + method accepts a 'd' type code for a double precision float. + + When deducing the type code by the python type of *value*, the + following mapping is applied:: + + i: python int + f: python float + Z: python str or bytes + B: python array.array, list or tuple + + Note that a single character string will be output as 'Z' and + not 'A' as the former is the more general type. """ cdef int value_size + cdef uint8_t tc cdef uint8_t * value_ptr cdef uint8_t *existing_ptr - cdef uint8_t typecode cdef float float_value cdef double double_value - cdef int32_t int_value + cdef int32_t int32_t_value + cdef uint32_t uint32_t_value + cdef int16_t int16_t_value + cdef uint16_t uint16_t_value + cdef int8_t int8_t_value + cdef uint8_t uint8_t_value cdef bam1_t * src = self._delegate cdef char * _value_type cdef c_array.array array_value @@ -1876,19 +2288,51 @@ cdef class AlignedSegment: if value is None: return - typecode = get_value_code(value, value_type) + cdef uint8_t typecode = get_tag_typecode(value, value_type) if typecode == 0: - raise ValueError("can't guess type or invalid type code specified") + raise ValueError("can't guess type or invalid type code specified: {} {}".format( + value, value_type)) - # Not Endian-safe, but then again neither is samtools! + # sam_format1 for typecasting if typecode == 'Z': value = force_bytes(value) value_ptr = value value_size = len(value)+1 + elif typecode == 'H': + # Note that hex tags are stored the very same + # way as Z string.s + value = force_bytes(value) + value_ptr = value + value_size = len(value)+1 + elif typecode == 'A' or typecode == 'a': + value = force_bytes(value) + value_ptr = value + value_size = sizeof(char) + typecode = 'A' elif typecode == 'i': - int_value = value - value_ptr = &int_value + int32_t_value = value + value_ptr = &int32_t_value value_size = sizeof(int32_t) + elif typecode == 'I': + uint32_t_value = value + value_ptr = &uint32_t_value + value_size = sizeof(uint32_t) + elif typecode == 's': + int16_t_value = value + value_ptr = &int16_t_value + value_size = sizeof(int16_t) + elif typecode == 'S': + uint16_t_value = value + value_ptr = &uint16_t_value + value_size = sizeof(uint16_t) + elif typecode == 'c': + int8_t_value = value + value_ptr = &int8_t_value + value_size = sizeof(int8_t) + elif typecode == 'C': + uint8_t_value = value + value_ptr = &uint8_t_value + value_size = sizeof(uint8_t) elif typecode == 'd': double_value = value value_ptr = &double_value @@ -1900,13 +2344,10 @@ cdef class AlignedSegment: elif typecode == 'B': # the following goes through python, needs to be cleaned up # pack array using struct - if value_type is None: - fmt, args = packTags([(tag, value)]) - else: - fmt, args = packTags([(tag, value, value_type)]) + fmt, args = pack_tags([(tag, value, value_type)]) # remove tag and type code as set by bam_aux_append - # first four chars of format (<2sc) + # first four chars of format (<2sB) fmt = '<' + fmt[4:] # first two values to pack args = args[2:] @@ -1922,7 +2363,7 @@ cdef class AlignedSegment: buffer.raw) return else: - raise ValueError('unsupported value_type in set_option') + raise ValueError('unsupported value_type {} in set_option'.format(typecode)) bam_aux_append(src, tag, @@ -1949,6 +2390,10 @@ cdef class AlignedSegment: This method is the fastest way to access the optional alignment section if only few tags need to be retrieved. + Possible value types are "AcCsSiIfZHB" (see BAM format + specification) as well as additional value type 'd' as + implemented in htslib. + Parameters ---------- @@ -1983,19 +2428,20 @@ cdef class AlignedSegment: else: auxtype = chr(v[0]) - if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S': - value = bam_aux2i(v) - elif auxtype == 'i' or auxtype == 'I': - value = bam_aux2i(v) + if auxtype in "iIcCsS": + value = bam_aux2i(v) elif auxtype == 'f' or auxtype == 'F': - value = bam_aux2f(v) + value = bam_aux2f(v) elif auxtype == 'd' or auxtype == 'D': - value = bam_aux2f(v) - elif auxtype == 'A': + value = bam_aux2f(v) + elif auxtype == 'A' or auxtype == 'a': + # force A to a + v[0] = 'A' # there might a more efficient way # to convert a char into a string value = '%c' % bam_aux2A(v) - elif auxtype == 'Z': + elif auxtype == 'Z' or auxtype == 'H': + # Z and H are treated equally as strings in htslib value = charptr_to_str(bam_aux2Z(v)) elif auxtype[0] == 'B': bytesize, nvalues, values = convert_binary_tag(v + 1) @@ -2063,7 +2509,7 @@ cdef class AlignedSegment: elif auxtype == 'd': value = bam_aux2f(s) s += 8 - elif auxtype == 'A': + elif auxtype in ('A', 'a'): value = "%c" % bam_aux2A(s) s += 1 elif auxtype in ('Z', 'H'): @@ -2088,7 +2534,7 @@ cdef class AlignedSegment: return result def set_tags(self, tags): - """sets the fields in the optional alignmest section with + """sets the fields in the optional alignment section with a list of (tag, value) tuples. The :term:`value type` of the values is determined from the @@ -2110,7 +2556,7 @@ cdef class AlignedSegment: # convert and pack the data if tags is not None and len(tags) > 0: - fmt, args = packTags(tags) + fmt, args = pack_tags(tags) new_size = struct.calcsize(fmt) buffer = ctypes.create_string_buffer(new_size) struct.pack_into(fmt, @@ -2118,14 +2564,17 @@ cdef class AlignedSegment: 0, *args) + # delete the old data and allocate new space. # If total_size == 0, the aux field will be # empty old_size = pysam_bam_get_l_aux(src) - pysam_bam_update(src, - old_size, - new_size, - pysam_bam_get_aux(src)) + cdef bam1_t * retval = pysam_bam_update(src, + old_size, + new_size, + pysam_bam_get_aux(src)) + if retval == NULL: + raise MemoryError("could not allocated memory") # copy data only if there is any if new_size > 0: @@ -2319,7 +2768,6 @@ cdef class PileupColumn: This class is a proxy for results returned by the samtools pileup engine. If the underlying engine iterator advances, the results of this column will change. - ''' def __init__(self): raise TypeError("this class cannot be instantiated from Python") @@ -2332,6 +2780,22 @@ cdef class PileupColumn: "\n" +\ "\n".join(map(str, self.pileups)) + def __dealloc__(self): + if self.buf is not NULL: + free(self.buf) + + def set_min_base_quality(self, min_base_quality): + """set the minimum base quality for this pileup column. + """ + self.min_base_quality = min_base_quality + + def __len__(self): + """return number of reads aligned to this column. + + see :meth:`get_num_aligned` + """ + return self.get_num_aligned() + property reference_id: '''the reference sequence number as defined in the header''' def __get__(self): @@ -2340,12 +2804,14 @@ cdef class PileupColumn: property reference_name: """:term:`reference` name (None if no AlignmentFile is associated)""" def __get__(self): - if self._alignment_file is not None: - return self._alignment_file.getrname(self.tid) + if self.header is not None: + return self.header.get_reference_name(self.tid) return None property nsegments: - '''number of reads mapping to this column.''' + '''number of reads mapping to this column. + + Note that this number ignores the base quality filter.''' def __get__(self): return self.n_pu def __set__(self, n): @@ -2359,17 +2825,20 @@ cdef class PileupColumn: property pileups: '''list of reads (:class:`pysam.PileupRead`) aligned to this column''' def __get__(self): - cdef int x - pileups = [] - if self.plp == NULL or self.plp[0] == NULL: raise ValueError("PileupColumn accessed after iterator finished") + cdef int x + cdef bam_pileup1_t * p = NULL + pileups = [] + # warning: there could be problems if self.n and self.buf are # out of sync. for x from 0 <= x < self.n_pu: - pileups.append(makePileupRead(&(self.plp[0][x]), - self._alignment_file)) + p = &(self.plp[0][x]) + if pileup_base_qual_skip(p, self.min_base_quality): + continue + pileups.append(makePileupRead(p, self.header)) return pileups ######################################################## @@ -2377,23 +2846,277 @@ cdef class PileupColumn: # Functions, properties for compatibility with pysam < 0.8 ######################################################## property pos: + """deprecated: use reference_pos""" def __get__(self): return self.reference_pos def __set__(self, v): self.reference_pos = v property tid: + """deprecated: use reference_id""" def __get__(self): return self.reference_id def __set__(self, v): self.reference_id = v property n: + """deprecated: use nsegments""" def __get__(self): return self.nsegments def __set__(self, v): self.nsegments = v + def get_num_aligned(self): + """return number of aligned bases at pileup column position. + + This method applies a base quality filter and the number is + equal to the size of :meth:`get_query_sequences`, + :meth:`get_mapping_qualities`, etc. + + """ + cdef uint32_t x = 0 + cdef uint32_t c = 0 + cdef uint32_t cnt = 0 + cdef bam_pileup1_t * p = NULL + for x from 0 <= x < self.n_pu: + p = &(self.plp[0][x]) + if pileup_base_qual_skip(p, self.min_base_quality): + continue + cnt += 1 + return cnt + + def get_query_sequences(self, bint mark_matches=False, bint mark_ends=False, bint add_indels=False): + """query bases/sequences at pileup column position. + + Optionally, the bases/sequences can be annotated according to the samtools + mpileup format. This is the format description from the samtools mpileup tool:: + + Information on match, mismatch, indel, strand, mapping + quality and start and end of a read are all encoded at the + read base column. At this column, a dot stands for a match + to the reference base on the forward strand, a comma for a + match on the reverse strand, a '>' or '<' for a reference + skip, `ACGTN' for a mismatch on the forward strand and + `acgtn' for a mismatch on the reverse strand. A pattern + `\\+[0-9]+[ACGTNacgtn]+' indicates there is an insertion + between this reference position and the next reference + position. The length of the insertion is given by the + integer in the pattern, followed by the inserted + sequence. Similarly, a pattern `-[0-9]+[ACGTNacgtn]+' + represents a deletion from the reference. The deleted bases + will be presented as `*' in the following lines. Also at + the read base column, a symbol `^' marks the start of a + read. The ASCII of the character following `^' minus 33 + gives the mapping quality. A symbol `$' marks the end of a + read segment + + To reproduce samtools mpileup format, set all of mark_matches, + mark_ends and add_indels to True. + + Parameters + ---------- + + mark_matches: bool + + If True, output bases matching the reference as "," or "." + for forward and reverse strand, respectively. This mark + requires the reference sequence. If no reference is + present, this option is ignored. + + mark_ends : bool + + If True, add markers "^" and "$" for read start and end, respectively. + + add_indels : bool + + If True, add bases for bases inserted into the reference and + 'N's for base skipped from the reference. If a reference sequence + is given, add the actual bases. + + Returns + ------- + + list: a list of bases/sequences per read at pileup column position. + + """ + cdef uint32_t x = 0 + cdef uint32_t j = 0 + cdef uint32_t c = 0 + cdef uint32_t n = 0 + cdef uint8_t cc = 0 + cdef uint8_t rb = 0 + cdef uint8_t * buf = self.buf + cdef bam_pileup1_t * p = NULL + + # todo: reference sequence to count matches/mismatches + # todo: convert assertions to exceptions + for x from 0 <= x < self.n_pu: + p = &(self.plp[0][x]) + if pileup_base_qual_skip(p, self.min_base_quality): + continue + # see samtools pileup_seq + if mark_ends and p.is_head: + buf[n] = '^' + n += 1 + assert n < MAX_PILEUP_BUFFER_SIZE + + if p.b.core.qual > 93: + buf[n] = 126 + else: + buf[n] = p.b.core.qual + 33 + n += 1 + assert n < MAX_PILEUP_BUFFER_SIZE + if not p.is_del: + if p.qpos < p.b.core.l_qseq: + cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos)] + else: + cc = 'N' + + if mark_matches and self.reference_sequence != NULL: + rb = self.reference_sequence[self.reference_pos] + if seq_nt16_table[cc] == seq_nt16_table[rb]: + cc = "=" + buf[n] = strand_mark_char(cc, p.b) + n += 1 + assert n < MAX_PILEUP_BUFFER_SIZE + elif add_indels: + if p.is_refskip: + if bam_is_rev(p.b): + buf[n] = '<' + else: + buf[n] = '>' + else: + buf[n] = '*' + n += 1 + assert n < MAX_PILEUP_BUFFER_SIZE + if add_indels: + if p.indel > 0: + buf[n] = '+' + n += 1 + assert n < MAX_PILEUP_BUFFER_SIZE + n += snprintf(&(buf[n]), + MAX_PILEUP_BUFFER_SIZE - n, + "%i", + p.indel) + assert n < MAX_PILEUP_BUFFER_SIZE + for j from 1 <= j <= p.indel: + cc = seq_nt16_str[bam_seqi(bam_get_seq(p.b), p.qpos + j)] + buf[n] = strand_mark_char(cc, p.b) + n += 1 + assert n < MAX_PILEUP_BUFFER_SIZE + elif p.indel < 0: + buf[n] = '-' + n += 1 + assert n < MAX_PILEUP_BUFFER_SIZE + n += snprintf(&(buf[n]), + MAX_PILEUP_BUFFER_SIZE - n, + "%i", + -p.indel) + assert n < MAX_PILEUP_BUFFER_SIZE + for j from 1 <= j <= -p.indel: + # TODO: out-of-range check here? + if self.reference_sequence == NULL: + cc = 'N' + else: + cc = self.reference_sequence[self.reference_pos + j] + buf[n] = strand_mark_char(cc, p.b) + n += 1 + assert n < MAX_PILEUP_BUFFER_SIZE + if mark_ends and p.is_tail: + buf[n] = '$' + n += 1 + assert n < MAX_PILEUP_BUFFER_SIZE + + buf[n] = ':' + n += 1 + assert n < MAX_PILEUP_BUFFER_SIZE + + if n == 0: + # could be zero if all qualities are too low + return "" + else: + # quicker to ensemble all and split than to encode all separately. + # ignore last ":" + return force_str(PyBytes_FromStringAndSize(buf, n-1)).split(":") + + def get_query_qualities(self): + """query base quality scores at pileup column position. + + Returns + ------- + + list: a list of quality scores + """ + cdef uint32_t x = 0 + cdef bam_pileup1_t * p = NULL + cdef uint32_t c = 0 + result = [] + for x from 0 <= x < self.n_pu: + p = &(self.plp[0][x]) + if p.qpos < p.b.core.l_qseq: + c = bam_get_qual(p.b)[p.qpos] + else: + c = 0 + if c < self.min_base_quality: + continue + result.append(c) + return result + + def get_mapping_qualities(self): + """query mapping quality scores at pileup column position. + + Returns + ------- + + list: a list of quality scores + """ + cdef uint32_t x = 0 + cdef bam_pileup1_t * p = NULL + result = [] + for x from 0 <= x < self.n_pu: + p = &(self.plp[0][x]) + if pileup_base_qual_skip(p, self.min_base_quality): + continue + result.append(p.b.core.qual) + return result + + def get_query_positions(self): + """positions in read at pileup column position. + + Returns + ------- + + list: a list of read positions + """ + + cdef uint32_t x = 0 + cdef bam_pileup1_t * p = NULL + result = [] + for x from 0 <= x < self.n_pu: + p = &(self.plp[0][x]) + if pileup_base_qual_skip(p, self.min_base_quality): + continue + result.append(p.qpos) + return result + + def get_query_names(self): + """query/read names aligned at pileup column position. + + Returns + ------- + + list: a list of query names at pileup column position. + """ + cdef uint32_t x = 0 + cdef bam_pileup1_t * p = NULL + result = [] + for x from 0 <= x < self.n_pu: + p = &(self.plp[0][x]) + if pileup_base_qual_skip(p, self.min_base_quality): + continue + result.append(charptr_to_str(pysam_bam_get_qname(p.b))) + return result + cdef class PileupRead: '''Representation of a read aligned to a particular position in the @@ -2477,7 +3200,72 @@ cdef class PileupRead: def __get__(self): return self._is_refskip + + +cpdef enum CIGAR_OPS: + CMATCH = 0 + CINS = 1 + CDEL = 2 + CREF_SKIP = 3 + CSOFT_CLIP = 4 + CHARD_CLIP = 5 + CPAD = 6 + CEQUAL = 7 + CDIFF = 8 + CBACK = 9 + + +cpdef enum SAM_FLAGS: + # the read is paired in sequencing, no matter whether it is mapped in a pair + FPAIRED = 1 + # the read is mapped in a proper pair + FPROPER_PAIR = 2 + # the read itself is unmapped; conflictive with FPROPER_PAIR + FUNMAP = 4 + # the mate is unmapped + FMUNMAP = 8 + # the read is mapped to the reverse strand + FREVERSE = 16 + # the mate is mapped to the reverse strand + FMREVERSE = 32 + # this is read1 + FREAD1 = 64 + # this is read2 + FREAD2 = 128 + # not primary alignment + FSECONDARY = 256 + # QC failure + FQCFAIL = 512 + # optical or PCR duplicate + FDUP = 1024 + # supplementary alignment + FSUPPLEMENTARY = 2048 + + __all__ = [ "AlignedSegment", "PileupColumn", - "PileupRead"] + "PileupRead", + "CMATCH", + "CINS", + "CDEL", + "CREF_SKIP", + "CSOFT_CLIP", + "CHARD_CLIP", + "CPAD", + "CEQUAL", + "CDIFF", + "CBACK", + "FPAIRED", + "FPROPER_PAIR", + "FUNMAP", + "FMUNMAP", + "FREVERSE", + "FMREVERSE", + "FREAD1", + "FREAD2", + "FSECONDARY", + "FQCFAIL", + "FDUP", + "FSUPPLEMENTARY", + "KEY_NAMES"] diff --git a/pysam/libcalignmentfile.c b/pysam/libcalignmentfile.c index 5cbac06cc..a32ccb7a2 100644 --- a/pysam/libcalignmentfile.c +++ b/pysam/libcalignmentfile.c @@ -568,6 +568,7 @@ static CYTHON_INLINE float __PYX_NAN() { #include #include "pythread.h" #include +#include "stdarg.h" #include "htslib/kstring.h" #include "htslib_util.h" #include "htslib/hfile.h" @@ -578,10 +579,9 @@ static CYTHON_INLINE float __PYX_NAN() { #include "htslib/tbx.h" #include "htslib/vcf.h" #include "htslib/vcfutils.h" +#include "htslib/cram.h" #include "pysam_stream.h" -#include "samfile_util.h" #include -#include "pysam_util.h" #ifdef _OPENMP #include #endif /* _OPENMP */ @@ -816,13 +816,14 @@ typedef struct arrayobject arrayobject; struct __pyx_obj_5pysam_10libchtslib_HTSFile; struct __pyx_obj_5pysam_9libcfaidx_FastaFile; struct __pyx_obj_5pysam_9libcfaidx_FastqProxy; -struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy; +struct __pyx_obj_5pysam_9libcfaidx_FastxRecord; struct __pyx_obj_5pysam_9libcfaidx_FastxFile; struct __pyx_obj_5pysam_9libcfaidx_FastqFile; struct __pyx_obj_5pysam_9libcfaidx_Fastafile; struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment; struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn; struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead; +struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader; struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile; struct __pyx_obj_5pysam_17libcalignmentfile_PileupColumn; struct __pyx_obj_5pysam_17libcalignmentfile_PileupRead; @@ -838,10 +839,10 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs; struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads; struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall; struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array; -struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array; +struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array; -/* "pysam/libcfaidx.pxd":48 - * cdef kseq_t * _delegate +/* "pysam/libcfaidx.pxd":49 + * cdef cython.str to_string(self) * cdef cython.str tostring(self) * cpdef array.array get_quality_array(self, int offset=*) # <<<<<<<<<<<<<< * @@ -852,30 +853,31 @@ struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array { int offset; }; -/* "pysam/libcfaidx.pxd":57 - * cdef public str comment, quality, sequence, name +/* "pysam/libcfaidx.pxd":59 + * cdef cython.str to_string(self) * cdef cython.str tostring(self) * cpdef array.array get_quality_array(self, int offset=*) # <<<<<<<<<<<<<< * - * + * cdef class FastxFile: */ -struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array { +struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array { int __pyx_n; int offset; }; struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag; struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag; +struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring; -/* "pysam/libcalignedsegment.pxd":36 +/* "pysam/libcalignedsegment.pxd":30 * - * from pysam.libcalignmentfile cimport AlignmentFile + * from pysam.libcalignmentfile cimport AlignmentFile, AlignmentHeader * ctypedef AlignmentFile AlignmentFile_t # <<<<<<<<<<<<<< * * */ typedef struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t; -/* "pysam/libcalignedsegment.pxd":56 +/* "pysam/libcalignedsegment.pxd":50 * # add an alignment tag with value to the AlignedSegment * # an existing tag of the same name will be replaced. * cpdef set_tag(self, tag, value, value_type=?, replace=?) # <<<<<<<<<<<<<< @@ -888,7 +890,7 @@ struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag { PyObject *replace; }; -/* "pysam/libcalignedsegment.pxd":60 +/* "pysam/libcalignedsegment.pxd":54 * # add an alignment tag with value to the AlignedSegment * # an existing tag of the same name will be replaced. * cpdef get_tag(self, tag, with_value_type=?) # <<<<<<<<<<<<<< @@ -899,6 +901,18 @@ struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag { int __pyx_n; PyObject *with_value_type; }; + +/* "pysam/libcalignedsegment.pxd":63 + * + * # returns a valid sam alignment string (deprecated) + * cpdef tostring(self, htsfile=*) # <<<<<<<<<<<<<< + * + * + */ +struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring { + int __pyx_n; + PyObject *htsfile; +}; struct __pyx_opt_args_5pysam_9libcutils_parse_region; struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array; struct __pyx_opt_args_5pysam_9libcutils_array_to_qualitystring; @@ -1021,9 +1035,10 @@ struct __pyx_opt_args_5pysam_9libcutils_force_bytes { }; struct __pyx_t_5pysam_17libcalignmentfile___iterdata; typedef struct __pyx_t_5pysam_17libcalignmentfile___iterdata __pyx_t_5pysam_17libcalignmentfile___iterdata; -struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData; +struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator; +struct __pyx_opt_args_5pysam_17libcalignmentfile_fill_AlignmentHeader_from_list; -/* "pysam/libcalignmentfile.pxd":29 +/* "pysam/libcalignmentfile.pxd":24 * # Utility types * * ctypedef struct __iterdata: # <<<<<<<<<<<<<< @@ -1038,21 +1053,41 @@ struct __pyx_t_5pysam_17libcalignmentfile___iterdata { int tid; char *seq; int seq_len; + int min_mapping_quality; + int flag_require; + int flag_filter; + int compute_baq; + int redo_baq; + int ignore_orphans; + int adjust_capq_threshold; }; -/* "pysam/libcalignmentfile.pxd":131 - * cdef char * getSequence(self) - * cdef setMask(self, mask) - * cdef setupIteratorData(self, # <<<<<<<<<<<<<< - * int tid, - * int start, +/* "pysam/libcalignmentfile.pxd":138 + * cdef int cnext(self) + * cdef char * get_sequence(self) + * cdef _setup_iterator(self, # <<<<<<<<<<<<<< + * int tid, + * int start, */ -struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData { +struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator { int __pyx_n; int multiple_iterators; }; -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libcalignmentfile.pyx":174 + * # the following should be class-method for VariantHeader, but cdef @classmethods + * # are not implemented in cython. + * cdef int fill_AlignmentHeader_from_list(bam_hdr_t *dest, # <<<<<<<<<<<<<< + * reference_names, + * reference_lengths, + */ +struct __pyx_opt_args_5pysam_17libcalignmentfile_fill_AlignmentHeader_from_list { + int __pyx_n; + PyObject *add_sq_text; + PyObject *text; +}; + +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -1066,6 +1101,7 @@ struct __pyx_obj_5pysam_10libchtslib_HTSFile { int64_t start_offset; PyObject *filename; PyObject *mode; + PyObject *threads; PyObject *index_filename; int is_stream; int is_remote; @@ -1097,7 +1133,7 @@ struct __pyx_obj_5pysam_9libcfaidx_FastaFile { * * cdef class FastqProxy: # <<<<<<<<<<<<<< * cdef kseq_t * _delegate - * cdef cython.str tostring(self) + * cdef cython.str to_string(self) */ struct __pyx_obj_5pysam_9libcfaidx_FastqProxy { PyObject_HEAD @@ -1106,16 +1142,16 @@ struct __pyx_obj_5pysam_9libcfaidx_FastqProxy { }; -/* "pysam/libcfaidx.pxd":51 +/* "pysam/libcfaidx.pxd":52 * * - * cdef class PersistentFastqProxy: # <<<<<<<<<<<<<< + * cdef class FastxRecord: # <<<<<<<<<<<<<< * """ * Python container for pysam.libcfaidx.FastqProxy with persistence. */ -struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy { +struct __pyx_obj_5pysam_9libcfaidx_FastxRecord { PyObject_HEAD - struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_vtab; + struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *__pyx_vtab; PyObject *comment; PyObject *quality; PyObject *sequence; @@ -1123,8 +1159,8 @@ struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy { }; -/* "pysam/libcfaidx.pxd":60 - * +/* "pysam/libcfaidx.pxd":61 + * cpdef array.array get_quality_array(self, int offset=*) * * cdef class FastxFile: # <<<<<<<<<<<<<< * cdef object _filename @@ -1141,7 +1177,7 @@ struct __pyx_obj_5pysam_9libcfaidx_FastxFile { }; -/* "pysam/libcfaidx.pxd":72 +/* "pysam/libcfaidx.pxd":73 * * # Compatibility Layer for pysam 0.8.1 * cdef class FastqFile(FastxFile): # <<<<<<<<<<<<<< @@ -1153,7 +1189,7 @@ struct __pyx_obj_5pysam_9libcfaidx_FastqFile { }; -/* "pysam/libcfaidx.pxd":77 +/* "pysam/libcfaidx.pxd":78 * * # Compatibility Layer for pysam < 0.8 * cdef class Fastafile(FastaFile): # <<<<<<<<<<<<<< @@ -1165,7 +1201,7 @@ struct __pyx_obj_5pysam_9libcfaidx_Fastafile { }; -/* "pysam/libcalignedsegment.pxd":40 +/* "pysam/libcalignedsegment.pxd":34 * * # Note: need to declare all C fields and methods here * cdef class AlignedSegment: # <<<<<<<<<<<<<< @@ -1176,7 +1212,7 @@ struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment { PyObject_HEAD struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *__pyx_vtab; bam1_t *_delegate; - struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *_alignment_file; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; PyObject *cache_query_qualities; PyObject *cache_query_alignment_qualities; PyObject *cache_query_sequence; @@ -1184,7 +1220,7 @@ struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment { }; -/* "pysam/libcalignedsegment.pxd":69 +/* "pysam/libcalignedsegment.pxd":66 * * * cdef class PileupColumn: # <<<<<<<<<<<<<< @@ -1197,21 +1233,24 @@ struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn { int tid; int pos; int n_pu; - struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *_alignment_file; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; + uint32_t min_base_quality; + uint8_t *buf; + char *reference_sequence; }; -/* "pysam/libcalignedsegment.pxd":77 - * +/* "pysam/libcalignedsegment.pxd":76 + * cdef char * reference_sequence * * cdef class PileupRead: # <<<<<<<<<<<<<< - * cdef AlignedSegment _alignment * cdef int32_t _qpos + * cdef AlignedSegment _alignment */ struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead { PyObject_HEAD - struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *_alignment; int32_t _qpos; + struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *_alignment; int _indel; int _level; uint32_t _is_del; @@ -1221,23 +1260,36 @@ struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead { }; -/* "pysam/libcalignmentfile.pxd":39 +/* "pysam/libcalignmentfile.pxd":41 + * * + * cdef class AlignmentHeader(object): # <<<<<<<<<<<<<< + * cdef bam_hdr_t *ptr + * + */ +struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader { + PyObject_HEAD + bam_hdr_t *ptr; +}; + + +/* "pysam/libcalignmentfile.pxd":44 + * cdef bam_hdr_t *ptr * * cdef class AlignmentFile(HTSFile): # <<<<<<<<<<<<<< * cdef readonly object reference_filename - * + * cdef readonly AlignmentHeader header */ struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile { struct __pyx_obj_5pysam_10libchtslib_HTSFile __pyx_base; PyObject *reference_filename; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; hts_idx_t *index; - bam_hdr_t *header; bam1_t *b; }; -/* "pysam/libcalignmentfile.pxd":57 +/* "pysam/libcalignmentfile.pxd":61 * * * cdef class PileupColumn: # <<<<<<<<<<<<<< @@ -1253,7 +1305,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_PileupColumn { }; -/* "pysam/libcalignmentfile.pxd":64 +/* "pysam/libcalignmentfile.pxd":68 * * * cdef class PileupRead: # <<<<<<<<<<<<<< @@ -1273,7 +1325,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_PileupRead { }; -/* "pysam/libcalignmentfile.pxd":75 +/* "pysam/libcalignmentfile.pxd":79 * * * cdef class IteratorRow: # <<<<<<<<<<<<<< @@ -1286,12 +1338,13 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow { bam1_t *b; struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *samfile; htsFile *htsfile; - bam_hdr_t *header; + hts_idx_t *index; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; int owns_samfile; }; -/* "pysam/libcalignmentfile.pxd":84 +/* "pysam/libcalignmentfile.pxd":89 * * * cdef class IteratorRowRegion(IteratorRow): # <<<<<<<<<<<<<< @@ -1305,8 +1358,8 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion { }; -/* "pysam/libcalignmentfile.pxd":89 - * cdef int cnext(self) +/* "pysam/libcalignmentfile.pxd":95 + * * * cdef class IteratorRowHead(IteratorRow): # <<<<<<<<<<<<<< * cdef int max_rows @@ -1320,8 +1373,8 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead { }; -/* "pysam/libcalignmentfile.pxd":95 - * cdef int cnext(self) +/* "pysam/libcalignmentfile.pxd":102 + * * * cdef class IteratorRowAll(IteratorRow): # <<<<<<<<<<<<<< * cdef bam1_t * getCurrent(self) @@ -1333,7 +1386,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll { }; -/* "pysam/libcalignmentfile.pxd":100 +/* "pysam/libcalignmentfile.pxd":107 * * * cdef class IteratorRowAllRefs(IteratorRow): # <<<<<<<<<<<<<< @@ -1347,7 +1400,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs { }; -/* "pysam/libcalignmentfile.pxd":105 +/* "pysam/libcalignmentfile.pxd":112 * * * cdef class IteratorRowSelection(IteratorRow): # <<<<<<<<<<<<<< @@ -1362,7 +1415,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection { }; -/* "pysam/libcalignmentfile.pxd":112 +/* "pysam/libcalignmentfile.pxd":119 * * * cdef class IteratorColumn: # <<<<<<<<<<<<<< @@ -1376,33 +1429,34 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn { int tid; int pos; int n_plp; - int mask; + uint32_t min_base_quality; bam_pileup1_t *plp; - bam_plp_t pileup_iter; + bam_mplp_t pileup_iter; __pyx_t_5pysam_17libcalignmentfile___iterdata iterdata; struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *samfile; - struct __pyx_obj_5pysam_9libcfaidx_Fastafile *fastafile; + struct __pyx_obj_5pysam_9libcfaidx_FastaFile *fastafile; PyObject *stepper; int max_depth; + int ignore_overlaps; }; -/* "pysam/libcalignmentfile.pxd":141 +/* "pysam/libcalignmentfile.pxd":150 * * * cdef class IteratorColumnRegion(IteratorColumn): # <<<<<<<<<<<<<< * cdef int start - * cdef int end + * cdef int stop */ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion { struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn __pyx_base; int start; - int end; + int stop; int truncate; }; -/* "pysam/libcalignmentfile.pxd":147 +/* "pysam/libcalignmentfile.pxd":156 * * * cdef class IteratorColumnAllRefs(IteratorColumn): # <<<<<<<<<<<<<< @@ -1414,7 +1468,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs { }; -/* "pysam/libcalignmentfile.pxd":151 +/* "pysam/libcalignmentfile.pxd":160 * * * cdef class IndexedReads: # <<<<<<<<<<<<<< @@ -1427,11 +1481,11 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads { htsFile *htsfile; PyObject *index; int owns_samfile; - bam_hdr_t *header; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; }; -/* "pysam/libcalignmentfile.pyx":2325 +/* "pysam/libcalignmentfile.pyx":2689 * * * cdef class SNPCall: # <<<<<<<<<<<<<< @@ -1452,7 +1506,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall { -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -1485,33 +1539,35 @@ static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile *__pyx_vtabptr_5pysam * * cdef class FastqProxy: # <<<<<<<<<<<<<< * cdef kseq_t * _delegate - * cdef cython.str tostring(self) + * cdef cython.str to_string(self) */ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy { + PyObject *(*to_string)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *); PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *); arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array *__pyx_optional_args); }; static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy *__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy; -/* "pysam/libcfaidx.pxd":51 +/* "pysam/libcfaidx.pxd":52 * * - * cdef class PersistentFastqProxy: # <<<<<<<<<<<<<< + * cdef class FastxRecord: # <<<<<<<<<<<<<< * """ * Python container for pysam.libcfaidx.FastqProxy with persistence. */ -struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy { - PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *); - arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array *__pyx_optional_args); +struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord { + PyObject *(*to_string)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *); + PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *); + arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array *__pyx_optional_args); }; -static struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy; +static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *__pyx_vtabptr_5pysam_9libcfaidx_FastxRecord; -/* "pysam/libcfaidx.pxd":60 - * +/* "pysam/libcfaidx.pxd":61 + * cpdef array.array get_quality_array(self, int offset=*) * * cdef class FastxFile: # <<<<<<<<<<<<<< * cdef object _filename @@ -1525,7 +1581,7 @@ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile { static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile *__pyx_vtabptr_5pysam_9libcfaidx_FastxFile; -/* "pysam/libcfaidx.pxd":72 +/* "pysam/libcfaidx.pxd":73 * * # Compatibility Layer for pysam 0.8.1 * cdef class FastqFile(FastxFile): # <<<<<<<<<<<<<< @@ -1539,7 +1595,7 @@ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile { static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile *__pyx_vtabptr_5pysam_9libcfaidx_FastqFile; -/* "pysam/libcfaidx.pxd":77 +/* "pysam/libcfaidx.pxd":78 * * # Compatibility Layer for pysam < 0.8 * cdef class Fastafile(FastaFile): # <<<<<<<<<<<<<< @@ -1553,7 +1609,7 @@ struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile { static struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile *__pyx_vtabptr_5pysam_9libcfaidx_Fastafile; -/* "pysam/libcalignedsegment.pxd":40 +/* "pysam/libcalignedsegment.pxd":34 * * # Note: need to declare all C fields and methods here * cdef class AlignedSegment: # <<<<<<<<<<<<<< @@ -1565,12 +1621,13 @@ struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment { PyObject *(*set_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag *__pyx_optional_args); PyObject *(*get_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag *__pyx_optional_args); PyObject *(*has_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch); - PyObject *(*tostring)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, __pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t, int __pyx_skip_dispatch); + PyObject *(*to_string)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch); + PyObject *(*tostring)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring *__pyx_optional_args); }; static struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *__pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment; -/* "pysam/libcalignmentfile.pyx":222 +/* "pysam/libcalignmentfile.pyx":565 * * * cdef class AlignmentFile(HTSFile): # <<<<<<<<<<<<<< @@ -1587,11 +1644,11 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *__pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile; -/* "pysam/libcalignmentfile.pyx":1684 +/* "pysam/libcalignmentfile.pyx":2035 * * * cdef class IteratorRowRegion(IteratorRow): # <<<<<<<<<<<<<< - * """*(AlignmentFile samfile, int tid, int beg, int end, + * """*(AlignmentFile samfile, int tid, int beg, int stop, * int multiple_iterators=False)* */ @@ -1602,7 +1659,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion; -/* "pysam/libcalignmentfile.pyx":1745 +/* "pysam/libcalignmentfile.pyx":2098 * * * cdef class IteratorRowHead(IteratorRow): # <<<<<<<<<<<<<< @@ -1617,7 +1674,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead; -/* "pysam/libcalignmentfile.pyx":1795 +/* "pysam/libcalignmentfile.pyx":2151 * * * cdef class IteratorRowAll(IteratorRow): # <<<<<<<<<<<<<< @@ -1632,7 +1689,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll; -/* "pysam/libcalignmentfile.pyx":1904 +/* "pysam/libcalignmentfile.pyx":2261 * * * cdef class IteratorRowSelection(IteratorRow): # <<<<<<<<<<<<<< @@ -1647,8 +1704,8 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection; -/* "pysam/libcalignmentfile.pyx":2055 - * return ret +/* "pysam/libcalignmentfile.pyx":2405 + * * * cdef class IteratorColumn: # <<<<<<<<<<<<<< * '''abstract base class for iterators over columns. @@ -1657,16 +1714,16 @@ static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection * struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn { int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); - char *(*getSequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); - PyObject *(*setMask)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, PyObject *); - PyObject *(*setupIteratorData)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData *__pyx_optional_args); + char *(*get_sequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); + PyObject *(*_setup_iterator)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args); PyObject *(*reset)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, PyObject *, PyObject *, PyObject *); PyObject *(*_free_pileup_iter)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); + char *(*getSequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); }; static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn; -/* "pysam/libcalignmentfile.pyx":2249 +/* "pysam/libcalignmentfile.pyx":2603 * * * cdef class IteratorColumnRegion(IteratorColumn): # <<<<<<<<<<<<<< @@ -1680,7 +1737,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion; -/* "pysam/libcalignmentfile.pyx":2286 +/* "pysam/libcalignmentfile.pyx":2647 * * * cdef class IteratorColumnAllRefs(IteratorColumn): # <<<<<<<<<<<<<< @@ -2149,17 +2206,31 @@ static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* value /* RaiseException.proto */ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); -/* RaiseTooManyValuesToUnpack.proto */ -static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); - -/* RaiseNeedMoreValuesToUnpack.proto */ -static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); +/* KeywordStringCheck.proto */ +static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); -/* IterFinish.proto */ -static CYTHON_INLINE int __Pyx_IterFinish(void); +/* ListCompAppend.proto */ +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) { + PyListObject* L = (PyListObject*) list; + Py_ssize_t len = Py_SIZE(list); + if (likely(L->allocated > len)) { + Py_INCREF(x); + PyList_SET_ITEM(list, len, x); + Py_SIZE(list) = len+1; + return 0; + } + return PyList_Append(list, x); +} +#else +#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x) +#endif -/* UnpackItemEndCheck.proto */ -static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); +/* SliceObject.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice( + PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, + PyObject** py_start, PyObject** py_stop, PyObject** py_slice, + int has_cstart, int has_cstop, int wraparound); /* DictGetItem.proto */ #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY @@ -2199,13 +2270,45 @@ static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); #endif +/* RaiseTooManyValuesToUnpack.proto */ +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); + +/* RaiseNeedMoreValuesToUnpack.proto */ +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); + +/* IterFinish.proto */ +static CYTHON_INLINE int __Pyx_IterFinish(void); + +/* UnpackItemEndCheck.proto */ +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); + /* WriteUnraisableException.proto */ static void __Pyx_WriteUnraisable(const char *name, int clineno, int lineno, const char *filename, int full_traceback, int nogil); -/* KeywordStringCheck.proto */ -static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); +/* PyObjectCallMethod1.proto */ +static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); +static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg); + +/* append.proto */ +static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); + +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace); +#else +#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\ + (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) +#endif + +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, int inplace); +#else +#define __Pyx_PyInt_EqObjC(op1, op2, intval, inplace)\ + PyObject_RichCompare(op1, op2, Py_EQ) + #endif /* PyDictContains.proto */ static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) { @@ -2225,37 +2328,8 @@ static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); /* HasAttr.proto */ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); -/* ListCompAppend.proto */ -#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS -static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) { - PyListObject* L = (PyListObject*) list; - Py_ssize_t len = Py_SIZE(list); - if (likely(L->allocated > len)) { - Py_INCREF(x); - PyList_SET_ITEM(list, len, x); - Py_SIZE(list) = len+1; - return 0; - } - return PyList_Append(list, x); -} -#else -#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x) -#endif - -/* PyObjectCallMethod1.proto */ -static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); -static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg); - -/* append.proto */ -static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); - -/* PyIntBinop.proto */ -#if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace); -#else -#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace)\ - (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2)) -#endif +/* ExtTypeTest.proto */ +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /* PyObjectCallMethod0.proto */ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); @@ -2287,9 +2361,6 @@ static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t /* MergeKeywords.proto */ static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping); -/* ExtTypeTest.proto */ -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); - /* PyIntBinop.proto */ #if !CYTHON_COMPILING_IN_PYPY static PyObject* __Pyx_PyInt_AndObjC(PyObject *op1, PyObject *op2, long intval, int inplace); @@ -2304,19 +2375,11 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); /* None.proto */ static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); -/* PyIntBinop.proto */ -#if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace); -#else -#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\ - (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) -#endif +/* pyfrozenset_new.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it); -/* SliceObject.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice( - PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, - PyObject** py_start, PyObject** py_stop, PyObject** py_slice, - int has_cstart, int has_cstop, int wraparound); +/* PySetContains.proto */ +static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq); /* dict_getitem_default.proto */ static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value); @@ -2361,9 +2424,6 @@ static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, trav /* CallNextTpClear.proto */ static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_dealloc); -/* GetVTable.proto */ -static void* __Pyx_GetVtable(PyObject *dict); - /* PyObject_GenericGetAttrNoDict.proto */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); @@ -2378,11 +2438,21 @@ static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_nam #define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr #endif +/* SetupReduce.proto */ +static int __Pyx_setup_reduce(PyObject* type_obj); + +/* GetVTable.proto */ +static void* __Pyx_GetVtable(PyObject *dict); + /* SetVTable.proto */ static int __Pyx_SetVtable(PyObject *dict, void *vtable); -/* SetupReduce.proto */ -static int __Pyx_setup_reduce(PyObject* type_obj); +/* ClassMethod.proto */ +#include "descrobject.h" +static PyObject* __Pyx_Method_ClassMethod(PyObject *method); + +/* GetNameInClass.proto */ +static PyObject *__Pyx_GetNameInClass(PyObject *nmspace, PyObject *name); /* CLineInTraceback.proto */ #ifdef CYTHON_CLINE_IN_TRACEBACK @@ -2537,18 +2607,12 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value); -/* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value); - /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value); -/* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value); - /* CIntFromPy.proto */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); @@ -2561,15 +2625,9 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); /* CIntFromPy.proto */ static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *); -/* CIntFromPy.proto */ -static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *); - /* CIntFromPy.proto */ static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *); -/* CIntFromPy.proto */ -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *); - /* CIntFromPy.proto */ static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *); @@ -2622,11 +2680,11 @@ static int __pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext(struct __py static bam1_t *__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self); /* proto*/ static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self); /* proto*/ static int __pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/ -static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/ -static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setMask(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_mask); /* proto*/ -static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData *__pyx_optional_args); /* proto*/ -static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_tid, PyObject *__pyx_v_start, PyObject *__pyx_v_end); /* proto*/ +static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_get_sequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/ +static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_stop, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args); /* proto*/ +static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_tid, PyObject *__pyx_v_start, PyObject *__pyx_v_stop); /* proto*/ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__free_pileup_iter(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/ +static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/ /* Module declarations from 'libc.stdint' */ @@ -2732,7 +2790,7 @@ static PyTypeObject *__pyx_ptype_5pysam_10libchtslib_HTSFile = 0; /* Module declarations from 'pysam.libcfaidx' */ static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastaFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastqProxy = 0; -static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy = 0; +static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastxRecord = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastxFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastqFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_Fastafile = 0; @@ -2741,8 +2799,8 @@ static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_Fastafile = 0; static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment = 0; static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn = 0; static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_PileupRead = 0; -static PyObject *(*__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment)(bam1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *); /*proto*/ -static PyObject *(*__pyx_f_5pysam_18libcalignedsegment_makePileupColumn)(bam_pileup1_t **, int, int, int, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *); /*proto*/ +static struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *(*__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment)(bam1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *); /*proto*/ +static struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *(*__pyx_f_5pysam_18libcalignedsegment_makePileupColumn)(bam_pileup1_t **, int, int, int, uint32_t, char *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *); /*proto*/ /* Module declarations from 'libc.errno' */ @@ -2754,6 +2812,7 @@ static PyObject *(*__pyx_f_5pysam_9libcutils_encode_filename)(PyObject *); /*pro static PyObject *(*__pyx_f_5pysam_9libcutils_from_string_and_size)(char const *, size_t); /*proto*/ /* Module declarations from 'pysam.libcalignmentfile' */ +static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader = 0; static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile = 0; static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_PileupColumn = 0; static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_PileupRead = 0; @@ -2769,10 +2828,10 @@ static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRef static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads = 0; static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_SNPCall = 0; static int __pyx_v_5pysam_17libcalignmentfile_MAX_POS; -static bam_hdr_t *__pyx_f_5pysam_17libcalignmentfile_build_header(PyObject *); /*proto*/ +static struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(bam_hdr_t *); /*proto*/ static int __pyx_f_5pysam_17libcalignmentfile___advance_nofilter(void *, bam1_t *); /*proto*/ static int __pyx_f_5pysam_17libcalignmentfile___advance_all(void *, bam1_t *); /*proto*/ -static int __pyx_f_5pysam_17libcalignmentfile___advance_snpcalls(void *, bam1_t *); /*proto*/ +static int __pyx_f_5pysam_17libcalignmentfile___advance_samtools(void *, bam1_t *); /*proto*/ static PyObject *__pyx_f_5pysam_17libcalignmentfile___pyx_unpickle_SNPCall__set_state(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *, PyObject *); /*proto*/ #define __Pyx_MODULE_NAME "pysam.libcalignmentfile" extern int __pyx_module_is_main_pysam__libcalignmentfile; @@ -2780,18 +2839,19 @@ int __pyx_module_is_main_pysam__libcalignmentfile = 0; /* Implementation of 'pysam.libcalignmentfile' */ static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_MemoryError; +static PyObject *__pyx_builtin_sum; static PyObject *__pyx_builtin_KeyError; +static PyObject *__pyx_builtin_zip; +static PyObject *__pyx_builtin_range; +static PyObject *__pyx_builtin_enumerate; +static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_AttributeError; static PyObject *__pyx_builtin_NotImplementedError; static PyObject *__pyx_builtin_IOError; -static PyObject *__pyx_builtin_OverflowError; -static PyObject *__pyx_builtin_OSError; -static PyObject *__pyx_builtin_enumerate; -static PyObject *__pyx_builtin_zip; static PyObject *__pyx_builtin_StopIteration; -static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_map; -static PyObject *__pyx_builtin_MemoryError; +static PyObject *__pyx_builtin_OSError; static const char __pyx_k_A[] = "A"; static const char __pyx_k_C[] = "C"; static const char __pyx_k_G[] = "G"; @@ -2832,11 +2892,11 @@ static const char __pyx_k_SM[] = "SM"; static const char __pyx_k_SN[] = "SN"; static const char __pyx_k_SO[] = "SO"; static const char __pyx_k_SP[] = "SP"; -static const char __pyx_k_SQ[] = "SQ"; +static const char __pyx_k_SQ[] = "@SQ"; static const char __pyx_k_UR[] = "UR"; static const char __pyx_k_VN[] = "VN"; static const char __pyx_k__2[] = "\t"; -static const char __pyx_k__3[] = "\n"; +static const char __pyx_k__8[] = ":"; static const char __pyx_k_io[] = "io"; static const char __pyx_k_os[] = "os"; static const char __pyx_k_rU[] = "rU"; @@ -2846,74 +2906,79 @@ static const char __pyx_k_re[] = "re"; static const char __pyx_k_wb[] = "wb"; static const char __pyx_k_wc[] = "wc"; static const char __pyx_k_wh[] = "wh"; -static const char __pyx_k__11[] = "-"; +static const char __pyx_k__10[] = "\n"; static const char __pyx_k__12[] = ""; -static const char __pyx_k__16[] = "[:-]"; -static const char __pyx_k__35[] = "@"; -static const char __pyx_k__41[] = ":"; +static const char __pyx_k__14[] = "@"; +static const char __pyx_k__32[] = "-"; static const char __pyx_k_all[] = "all"; -static const char __pyx_k_bai[] = ".bai"; static const char __pyx_k_beg[] = "beg"; -static const char __pyx_k_csi[] = ".csi"; static const char __pyx_k_end[] = "end"; static const char __pyx_k_get[] = "get"; static const char __pyx_k_key[] = "key"; +static const char __pyx_k_len[] = "__len__"; static const char __pyx_k_map[] = "map"; static const char __pyx_k_new[] = "__new__"; static const char __pyx_k_pos[] = "pos"; static const char __pyx_k_s_s[] = "%s:%s"; static const char __pyx_k_seq[] = "seq"; +static const char __pyx_k_str[] = "__str__"; +static const char __pyx_k_sum[] = "sum"; static const char __pyx_k_tid[] = "tid"; static const char __pyx_k_wb0[] = "wb0"; static const char __pyx_k_wbu[] = "wbu"; static const char __pyx_k_zip[] = "zip"; -static const char __pyx_k_crai[] = ".crai"; +static const char __pyx_k_SQ_2[] = "SQ"; +static const char __pyx_k_copy[] = "copy"; static const char __pyx_k_dict[] = "__dict__"; static const char __pyx_k_flag[] = "flag"; static const char __pyx_k_init[] = "__init__"; static const char __pyx_k_join[] = "join"; +static const char __pyx_k_keys[] = "keys"; static const char __pyx_k_line[] = "line"; static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_make[] = "_make"; static const char __pyx_k_mode[] = "mode"; static const char __pyx_k_name[] = "name"; static const char __pyx_k_open[] = "_open"; -static const char __pyx_k_path[] = "path"; static const char __pyx_k_port[] = "port"; +static const char __pyx_k_stop[] = "stop"; static const char __pyx_k_tell[] = "tell"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_text[] = "text"; -static const char __pyx_k_warn[] = "warn"; static const char __pyx_k_all_2[] = "__all__"; static const char __pyx_k_array[] = "array"; -static const char __pyx_k_ascii[] = "ascii"; static const char __pyx_k_close[] = "close"; static const char __pyx_k_fetch[] = "fetch"; static const char __pyx_k_items[] = "items"; +static const char __pyx_k_range[] = "range"; static const char __pyx_k_split[] = "split"; static const char __pyx_k_start[] = "start"; static const char __pyx_k_strip[] = "strip"; +static const char __pyx_k_total[] = "total"; static const char __pyx_k_write[] = "write"; static const char __pyx_k_append[] = "append"; static const char __pyx_k_closed[] = "closed"; -static const char __pyx_k_encode[] = "encode"; -static const char __pyx_k_exists[] = "_exists"; +static const char __pyx_k_contig[] = "contig"; static const char __pyx_k_fields[] = "fields"; static const char __pyx_k_fileno[] = "fileno"; static const char __pyx_k_format[] = "format"; -static const char __pyx_k_gettid[] = "gettid"; static const char __pyx_k_header[] = "header"; static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_is_bam[] = "is_bam"; +static const char __pyx_k_mapped[] = "mapped"; static const char __pyx_k_name_2[] = "__name__"; static const char __pyx_k_pickle[] = "pickle"; static const char __pyx_k_record[] = "record"; static const char __pyx_k_reduce[] = "__reduce__"; static const char __pyx_k_region[] = "region"; static const char __pyx_k_update[] = "update"; +static const char __pyx_k_values[] = "values"; static const char __pyx_k_Counter[] = "Counter"; static const char __pyx_k_IOError[] = "IOError"; +static const char __pyx_k_Mapping[] = "Mapping"; static const char __pyx_k_OSError[] = "OSError"; static const char __pyx_k_get_tid[] = "get_tid"; +static const char __pyx_k_getitem[] = "__getitem__"; static const char __pyx_k_is_cram[] = "is_cram"; static const char __pyx_k_is_open[] = "is_open"; static const char __pyx_k_islower[] = "islower"; @@ -2921,27 +2986,35 @@ static const char __pyx_k_isupper[] = "isupper"; static const char __pyx_k_lengths[] = "lengths"; static const char __pyx_k_samfile[] = "samfile"; static const char __pyx_k_stepper[] = "stepper"; +static const char __pyx_k_threads[] = "threads"; +static const char __pyx_k_to_dict[] = "to_dict"; static const char __pyx_k_KeyError[] = "KeyError"; +static const char __pyx_k_SQ_SN_LN[] = "@SQ\tSN:{}\tLN:{}\n"; +static const char __pyx_k_Sequence[] = "Sequence"; static const char __pyx_k_StringIO[] = "StringIO"; static const char __pyx_k_check_sq[] = "check_sq"; +static const char __pyx_k_contains[] = "__contains__"; static const char __pyx_k_coverage[] = "coverage"; static const char __pyx_k_exc_type[] = "exc_type"; -static const char __pyx_k_exists_2[] = "exists"; static const char __pyx_k_filename[] = "filename"; static const char __pyx_k_genotype[] = "genotype"; static const char __pyx_k_getstate[] = "__getstate__"; static const char __pyx_k_nextiter[] = "nextiter"; static const char __pyx_k_nofilter[] = "nofilter"; static const char __pyx_k_pyx_type[] = "__pyx_type"; +static const char __pyx_k_redo_baq[] = "redo_baq"; static const char __pyx_k_samtools[] = "samtools"; static const char __pyx_k_setstate[] = "__setstate__"; static const char __pyx_k_template[] = "template"; static const char __pyx_k_truncate[] = "truncate"; +static const char __pyx_k_unmapped[] = "unmapped"; static const char __pyx_k_warnings[] = "warnings"; static const char __pyx_k_TypeError[] = "TypeError"; static const char __pyx_k_enumerate[] = "enumerate"; static const char __pyx_k_exc_value[] = "exc_value"; static const char __pyx_k_fastafile[] = "fastafile"; +static const char __pyx_k_from_dict[] = "from_dict"; +static const char __pyx_k_from_text[] = "from_text"; static const char __pyx_k_has_index[] = "has_index"; static const char __pyx_k_max_depth[] = "max_depth"; static const char __pyx_k_positions[] = "positions"; @@ -2950,123 +3023,162 @@ static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; static const char __pyx_k_reference[] = "reference"; static const char __pyx_k_traceback[] = "traceback"; static const char __pyx_k_until_eof[] = "until_eof"; +static const char __pyx_k_IndexStats[] = "IndexStats"; static const char __pyx_k_ValueError[] = "ValueError"; +static const char __pyx_k_namedtuple[] = "namedtuple"; static const char __pyx_k_pyx_result[] = "__pyx_result"; static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; static const char __pyx_k_query_name[] = "query_name"; static const char __pyx_k_references[] = "references"; +static const char __pyx_k_splitlines[] = "splitlines"; static const char __pyx_k_startswith[] = "startswith"; static const char __pyx_k_IteratorRow[] = "IteratorRow"; static const char __pyx_k_MemoryError[] = "MemoryError"; +static const char __pyx_k_OrderedDict[] = "OrderedDict"; static const char __pyx_k_PickleError[] = "PickleError"; static const char __pyx_k_add_sq_text[] = "add_sq_text"; static const char __pyx_k_check_index[] = "check_index"; static const char __pyx_k_cigarstring[] = "cigarstring"; +static const char __pyx_k_cigartuples[] = "cigartuples"; static const char __pyx_k_collections[] = "collections"; +static const char __pyx_k_compute_baq[] = "compute_baq"; static const char __pyx_k_defaultdict[] = "defaultdict"; +static const char __pyx_k_flag_filter[] = "flag_filter"; static const char __pyx_k_nreferences[] = "nreferences"; static const char __pyx_k_snp_quality[] = "snp_quality"; static const char __pyx_k_IndexedReads[] = "IndexedReads"; -static const char __pyx_k_SQ_SN_s_LN_s[] = "@SQ\tSN:%s\tLN:%s\n"; static const char __pyx_k_check_header[] = "check_header"; +static const char __pyx_k_flag_require[] = "flag_require"; +static const char __pyx_k_is_valid_tid[] = "is_valid_tid"; static const char __pyx_k_parse_region[] = "parse_region"; static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; static const char __pyx_k_stringsource[] = "stringsource"; static const char __pyx_k_AlignmentFile[] = "AlignmentFile"; -static const char __pyx_k_OverflowError[] = "OverflowError"; static const char __pyx_k_StopIteration[] = "StopIteration"; static const char __pyx_k_VALID_HEADERS[] = "VALID_HEADERS"; +static const char __pyx_k_add_reference[] = "add_reference"; +static const char __pyx_k_has_reference[] = "has_reference"; static const char __pyx_k_read_callback[] = "read_callback"; static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; +static const char __pyx_k_require_index[] = "require_index"; static const char __pyx_k_AttributeError[] = "AttributeError"; static const char __pyx_k_IteratorColumn[] = "IteratorColumn"; +static const char __pyx_k_add_sam_header[] = "add_sam_header"; static const char __pyx_k_filepath_index[] = "filepath_index"; +static const char __pyx_k_format_options[] = "format_options"; +static const char __pyx_k_ignore_orphans[] = "ignore_orphans"; +static const char __pyx_k_index_filename[] = "index_filename"; static const char __pyx_k_mate_not_found[] = "mate not found"; static const char __pyx_k_reference_base[] = "reference_base"; static const char __pyx_k_referencenames[] = "referencenames"; static const char __pyx_k_truncated_file[] = "truncated file"; +static const char __pyx_k_AlignmentHeader[] = "AlignmentHeader"; +static const char __pyx_k_add_hts_options[] = "add_hts_options"; +static const char __pyx_k_from_references[] = "from_references"; +static const char __pyx_k_ignore_overlaps[] = "ignore_overlaps"; static const char __pyx_k_mapping_quality[] = "mapping_quality"; static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError"; static const char __pyx_k_query_qualities[] = "query_qualities"; static const char __pyx_k_reference_names[] = "reference_names"; static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; -static const char __pyx_k_file_s_not_found[] = "file `%s` not found"; +static const char __pyx_k_check_truncation[] = "check_truncation"; +static const char __pyx_k_min_base_quality[] = "min_base_quality"; static const char __pyx_k_read_s_not_found[] = "read %s not found"; static const char __pyx_k_referencelengths[] = "referencelengths"; static const char __pyx_k_build_header_line[] = "build_header_line"; static const char __pyx_k_consensus_quality[] = "consensus_quality"; static const char __pyx_k_get_aligned_pairs[] = "get_aligned_pairs"; +static const char __pyx_k_ignore_truncation[] = "ignore_truncation"; static const char __pyx_k_quality_threshold[] = "quality_threshold"; static const char __pyx_k_reference_lengths[] = "reference_lengths"; +static const char __pyx_k_unknown_reference[] = "unknown reference {}"; static const char __pyx_k_VALID_HEADER_ORDER[] = "VALID_HEADER_ORDER"; static const char __pyx_k_VALID_HEADER_TYPES[] = "VALID_HEADER_TYPES"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; -static const char __pyx_k_end_out_of_range_i[] = "end out of range (%i)"; static const char __pyx_k_filepath_or_object[] = "filepath_or_object"; static const char __pyx_k_get_reference_name[] = "get_reference_name"; +static const char __pyx_k_interval_of_size_0[] = "interval of size 0"; static const char __pyx_k_mate_s_is_unmapped[] = "mate %s: is unmapped"; static const char __pyx_k_multiple_iterators[] = "multiple_iterators"; static const char __pyx_k_read_s_is_unpaired[] = "read %s: is unpaired"; static const char __pyx_k_reference_filename[] = "reference_filename"; static const char __pyx_k_KNOWN_HEADER_FIELDS[] = "KNOWN_HEADER_FIELDS"; static const char __pyx_k_NotImplementedError[] = "NotImplementedError"; -static const char __pyx_k_invalid_reference_s[] = "invalid reference `%s`"; +static const char __pyx_k_min_mapping_quality[] = "min_mapping_quality"; static const char __pyx_k_duplicate_filehandle[] = "duplicate_filehandle"; +static const char __pyx_k_get_reference_length[] = "get_reference_length"; static const char __pyx_k_pyx_unpickle_SNPCall[] = "__pyx_unpickle_SNPCall"; -static const char __pyx_k_start_out_of_range_i[] = "start out of range (%i)"; +static const char __pyx_k_adjust_capq_threshold[] = "adjust_capq_threshold"; +static const char __pyx_k_from_text_and_lengths[] = "_from_text_and_lengths"; static const char __pyx_k_header_line_without_s[] = "header line without '@': '%s'"; +static const char __pyx_k_build_sequence_section[] = "_build_sequence_section"; static const char __pyx_k_error_during_iteration[] = "error during iteration"; +static const char __pyx_k_could_not_create_header[] = "could not create header"; static const char __pyx_k_pysam_libcalignmentfile[] = "pysam.libcalignmentfile"; -static const char __pyx_k_unable_to_open_index_at_s[] = "unable to open index at %s"; +static const char __pyx_k_could_not_allocate_bytes[] = "could not allocate {} bytes"; +static const char __pyx_k_error_while_reading_file[] = "error while reading file {}: {}"; +static const char __pyx_k_unable_to_reopen_htsfile[] = "unable to reopen htsfile"; +static const char __pyx_k_unable_to_open_index_file[] = "unable to open index file"; static const char __pyx_k_invalid_file_opening_mode_s[] = "invalid file opening mode `%s`"; static const char __pyx_k_pysam_libcalignmentfile_pyx[] = "pysam/libcalignmentfile.pyx"; +static const char __pyx_k_unable_to_open_index_file_s[] = "unable to open index file `%s`"; static const char __pyx_k_I_O_operation_on_closed_file[] = "I/O operation on closed file"; +static const char __pyx_k_interval_of_size_less_than_0[] = "interval of size less than 0"; static const char __pyx_k_no_index_available_for_fetch[] = "no index available for fetch"; +static const char __pyx_k_could_not_open_alignment_file[] = "could not open alignment file `{}`: {}"; static const char __pyx_k_no_index_available_for_pileup[] = "no index available for pileup"; -static const char __pyx_k_error_while_opening_index_for_s[] = "error while opening index for '%s'"; +static const char __pyx_k_could_not_open_alignment_file_2[] = "could not open alignment file `{}`"; static const char __pyx_k_fetch_called_on_bamfile_without[] = "fetch called on bamfile without index"; static const char __pyx_k_file_does_not_contain_alignment[] = "file does not contain alignment data"; -static const char __pyx_k_file_does_not_have_valid_header[] = "file does not have valid header (mode='%s') - is it BAM format?"; static const char __pyx_k_header_line_with_invalid_type_s[] = "header line with invalid type '%s': '%s'"; static const char __pyx_k_incomplete_sequence_information[] = "incomplete sequence information in '%s'"; -static const char __pyx_k_invalid_coordinates_start_i_end[] = "invalid coordinates: start (%i) > end (%i)"; static const char __pyx_k_malformatted_header_no_in_field[] = "malformatted header: no ':' in field"; -static const char __pyx_k_self_b_self_header_self_htsfile[] = "self.b,self.header,self.htsfile cannot be converted to a Python object for pickling"; -static const char __pyx_k_self_header_self_htsfile_cannot[] = "self.header,self.htsfile cannot be converted to a Python object for pickling"; -static const char __pyx_k_unable_to_open_remote_index_for[] = "unable to open remote index for '%s'"; +static const char __pyx_k_wrong_sequence_information_in_s[] = "wrong sequence information in '%s'"; static const char __pyx_k_AlignmentFile_mapped_only_availa[] = "AlignmentFile.mapped only available in bam files"; +static const char __pyx_k_AlignmentHeader_does_not_support[] = "AlignmentHeader does not support item assignment (use header.to_dict()"; +static const char __pyx_k_Cannot_add_extra_threads_when_ig[] = "Cannot add extra threads when \"ignore_truncation\" is True"; static const char __pyx_k_Incompatible_checksums_s_vs_0x50[] = "Incompatible checksums (%s vs 0x50b2281 = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))"; +static const char __pyx_k_SAM_file_does_not_have_a_valid_h[] = "SAM? file does not have a valid header (mode='%s'), please provide reference_names and reference_lengths"; static const char __pyx_k_access_from_StringIO_objects_not[] = "access from StringIO objects not supported"; static const char __pyx_k_can_not_iterate_over_samfile_wit[] = "can not iterate over samfile without header"; -static const char __pyx_k_can_only_IndexReads_on_bam_files[] = "can only IndexReads on bam files"; -static const char __pyx_k_could_not_open_file_mode_s_is_it[] = "could not open file (mode='%s') - is it SAM/BAM format?"; +static const char __pyx_k_can_only_apply_IndexReads_on_bam[] = "can only apply IndexReads on bam files"; +static const char __pyx_k_cannot_create_AlignmentHeader_re[] = "cannot create AlignmentHeader, received NULL pointer"; +static const char __pyx_k_could_not_allocate_memory_of_siz[] = "could not allocate memory of size {}"; static const char __pyx_k_either_supply_options_template_h[] = "either supply options `template`, `header` or both `reference_names` and `reference_lengths` for writing"; -static const char __pyx_k_fetch_called_for_htsfile_without[] = "fetch called for htsfile without header"; -static const char __pyx_k_fetching_by_region_is_not_availa[] = "fetching by region is not available for sam files"; +static const char __pyx_k_fetching_by_region_is_not_availa[] = "fetching by region is not available for SAM files"; +static const char __pyx_k_file_does_not_have_a_valid_heade[] = "file does not have a valid header (mode='%s') - is it BAM/CRAM format?"; static const char __pyx_k_file_has_no_sequences_defined_mo[] = "file has no sequences defined (mode='%s') - is it SAM/BAM format? Consider opening with check_sq=False"; +static const char __pyx_k_header_not_available_in_closed_f[] = "header not available in closed files"; static const char __pyx_k_invalid_type_for_record_s_s_expe[] = "invalid type for record %s: %s, expected %s"; static const char __pyx_k_mapping_information_not_recorded[] = "mapping information not recorded in index or index not available"; +static const char __pyx_k_multiple_iterators_not_implement[] = "multiple iterators not implemented for SAM files"; static const char __pyx_k_multiple_s_lines_are_not_permitt[] = "multiple '%s' lines are not permitted"; static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__"; static const char __pyx_k_no_index_available_for_iteration[] = "no index available for iteration"; +static const char __pyx_k_not_enough_information_to_constr[] = "not enough information to construct header. Please provide template, header, text or reference_names/reference_lengths"; +static const char __pyx_k_number_of_reference_names_and_le[] = "number of reference names and lengths do not match"; static const char __pyx_k_pileup_of_samfiles_not_implement[] = "pileup of samfiles not implemented yet"; static const char __pyx_k_reference_id_i_out_of_range_0_ti[] = "reference_id %i out of range 0<=tid<%i"; -static const char __pyx_k_reference_sequence_for_s_tid_i_n[] = "reference sequence for '%s' (tid=%i) not found"; +static const char __pyx_k_reference_sequence_for_tid_not_f[] = "reference sequence for '{}' (tid={}) not found"; static const char __pyx_k_sam_write1_failed_with_error_cod[] = "sam_write1 failed with error code {}"; -static const char __pyx_k_unequal_names_and_lengths_of_ref[] = "unequal names and lengths of reference sequences"; +static const char __pyx_k_self_b_self_htsfile_self_index_c[] = "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"; +static const char __pyx_k_self_b_self_htsfile_self_index_s[] = "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"; +static const char __pyx_k_self_htsfile_cannot_be_converted[] = "self.htsfile cannot be converted to a Python object for pickling"; +static const char __pyx_k_unable_to_read_header_informatio[] = "unable to read header information"; static const char __pyx_k_unknown_stepper_option_s_in_Iter[] = "unknown stepper option `%s` in IteratorColumn"; -static const char __pyx_k_file_does_not_have_valid_header_2[] = "file does not have valid header (mode='%s') - is it SAM format?"; -static const char __pyx_k_self_b_self_header_self_htsfile_2[] = "self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling"; static PyObject *__pyx_n_s_A; static PyObject *__pyx_n_s_AH; static PyObject *__pyx_n_s_AS; static PyObject *__pyx_n_s_AlignmentFile; static PyObject *__pyx_kp_s_AlignmentFile_mapped_only_availa; +static PyObject *__pyx_n_s_AlignmentHeader; +static PyObject *__pyx_kp_s_AlignmentHeader_does_not_support; static PyObject *__pyx_n_s_AttributeError; static PyObject *__pyx_n_s_C; static PyObject *__pyx_n_s_CL; static PyObject *__pyx_n_s_CN; static PyObject *__pyx_n_s_CO; +static PyObject *__pyx_kp_s_Cannot_add_extra_threads_when_ig; static PyObject *__pyx_n_s_Counter; static PyObject *__pyx_n_s_DS; static PyObject *__pyx_n_s_DT; @@ -3078,6 +3190,7 @@ static PyObject *__pyx_n_s_ID; static PyObject *__pyx_n_s_IOError; static PyObject *__pyx_kp_s_I_O_operation_on_closed_file; static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x50; +static PyObject *__pyx_n_s_IndexStats; static PyObject *__pyx_n_s_IndexedReads; static PyObject *__pyx_n_s_IteratorColumn; static PyObject *__pyx_n_s_IteratorRow; @@ -3088,11 +3201,12 @@ static PyObject *__pyx_n_s_L; static PyObject *__pyx_n_s_LB; static PyObject *__pyx_n_s_LN; static PyObject *__pyx_n_s_M5; +static PyObject *__pyx_n_s_Mapping; static PyObject *__pyx_n_s_MemoryError; static PyObject *__pyx_n_s_N; static PyObject *__pyx_n_s_NotImplementedError; static PyObject *__pyx_n_s_OSError; -static PyObject *__pyx_n_s_OverflowError; +static PyObject *__pyx_n_s_OrderedDict; static PyObject *__pyx_n_s_PG; static PyObject *__pyx_n_s_PI; static PyObject *__pyx_n_s_PL; @@ -3102,12 +3216,15 @@ static PyObject *__pyx_n_s_PP; static PyObject *__pyx_n_s_PU; static PyObject *__pyx_n_s_PickleError; static PyObject *__pyx_n_s_RG; +static PyObject *__pyx_kp_s_SAM_file_does_not_have_a_valid_h; static PyObject *__pyx_n_s_SM; static PyObject *__pyx_n_s_SN; static PyObject *__pyx_n_s_SO; static PyObject *__pyx_n_s_SP; -static PyObject *__pyx_n_s_SQ; -static PyObject *__pyx_kp_s_SQ_SN_s_LN_s; +static PyObject *__pyx_kp_s_SQ; +static PyObject *__pyx_n_s_SQ_2; +static PyObject *__pyx_kp_s_SQ_SN_LN; +static PyObject *__pyx_n_s_Sequence; static PyObject *__pyx_n_s_StopIteration; static PyObject *__pyx_n_s_StringIO; static PyObject *__pyx_n_s_T; @@ -3118,115 +3235,142 @@ static PyObject *__pyx_n_s_VALID_HEADER_ORDER; static PyObject *__pyx_n_s_VALID_HEADER_TYPES; static PyObject *__pyx_n_s_VN; static PyObject *__pyx_n_s_ValueError; -static PyObject *__pyx_kp_b__11; +static PyObject *__pyx_kp_s__10; static PyObject *__pyx_kp_s__12; -static PyObject *__pyx_kp_s__16; +static PyObject *__pyx_kp_s__14; static PyObject *__pyx_kp_s__2; -static PyObject *__pyx_kp_s__3; -static PyObject *__pyx_kp_s__35; -static PyObject *__pyx_kp_s__41; +static PyObject *__pyx_kp_b__32; +static PyObject *__pyx_kp_s__8; static PyObject *__pyx_kp_s_access_from_StringIO_objects_not; +static PyObject *__pyx_n_s_add_hts_options; +static PyObject *__pyx_n_s_add_reference; +static PyObject *__pyx_n_s_add_sam_header; static PyObject *__pyx_n_s_add_sq_text; +static PyObject *__pyx_n_s_adjust_capq_threshold; static PyObject *__pyx_n_s_all; static PyObject *__pyx_n_s_all_2; static PyObject *__pyx_n_s_append; static PyObject *__pyx_n_s_array; -static PyObject *__pyx_n_s_ascii; static PyObject *__pyx_n_s_b; -static PyObject *__pyx_kp_b_bai; static PyObject *__pyx_n_s_beg; static PyObject *__pyx_n_s_build_header_line; +static PyObject *__pyx_n_s_build_sequence_section; static PyObject *__pyx_n_s_c; static PyObject *__pyx_kp_s_can_not_iterate_over_samfile_wit; -static PyObject *__pyx_kp_s_can_only_IndexReads_on_bam_files; +static PyObject *__pyx_kp_s_can_only_apply_IndexReads_on_bam; +static PyObject *__pyx_kp_s_cannot_create_AlignmentHeader_re; static PyObject *__pyx_n_s_check_header; static PyObject *__pyx_n_s_check_index; static PyObject *__pyx_n_s_check_sq; +static PyObject *__pyx_n_s_check_truncation; static PyObject *__pyx_n_s_cigarstring; +static PyObject *__pyx_n_s_cigartuples; static PyObject *__pyx_n_s_cline_in_traceback; static PyObject *__pyx_n_s_close; static PyObject *__pyx_n_s_closed; static PyObject *__pyx_n_s_collections; +static PyObject *__pyx_n_s_compute_baq; static PyObject *__pyx_n_s_consensus_quality; -static PyObject *__pyx_kp_s_could_not_open_file_mode_s_is_it; +static PyObject *__pyx_n_s_contains; +static PyObject *__pyx_n_s_contig; +static PyObject *__pyx_n_s_copy; +static PyObject *__pyx_kp_s_could_not_allocate_bytes; +static PyObject *__pyx_kp_s_could_not_allocate_memory_of_siz; +static PyObject *__pyx_kp_s_could_not_create_header; +static PyObject *__pyx_kp_s_could_not_open_alignment_file; +static PyObject *__pyx_kp_s_could_not_open_alignment_file_2; static PyObject *__pyx_n_s_coverage; -static PyObject *__pyx_kp_b_crai; -static PyObject *__pyx_kp_b_csi; static PyObject *__pyx_n_s_defaultdict; static PyObject *__pyx_n_s_dict; static PyObject *__pyx_n_s_duplicate_filehandle; static PyObject *__pyx_kp_s_either_supply_options_template_h; -static PyObject *__pyx_n_s_encode; static PyObject *__pyx_n_s_end; -static PyObject *__pyx_kp_s_end_out_of_range_i; static PyObject *__pyx_n_s_enumerate; static PyObject *__pyx_kp_s_error_during_iteration; -static PyObject *__pyx_kp_s_error_while_opening_index_for_s; +static PyObject *__pyx_kp_s_error_while_reading_file; static PyObject *__pyx_n_s_exc_type; static PyObject *__pyx_n_s_exc_value; -static PyObject *__pyx_n_s_exists; -static PyObject *__pyx_n_s_exists_2; static PyObject *__pyx_n_s_fastafile; static PyObject *__pyx_n_s_fetch; -static PyObject *__pyx_kp_s_fetch_called_for_htsfile_without; static PyObject *__pyx_kp_s_fetch_called_on_bamfile_without; static PyObject *__pyx_kp_s_fetching_by_region_is_not_availa; static PyObject *__pyx_n_s_fields; static PyObject *__pyx_kp_s_file_does_not_contain_alignment; -static PyObject *__pyx_kp_s_file_does_not_have_valid_header; -static PyObject *__pyx_kp_s_file_does_not_have_valid_header_2; +static PyObject *__pyx_kp_s_file_does_not_have_a_valid_heade; static PyObject *__pyx_kp_s_file_has_no_sequences_defined_mo; -static PyObject *__pyx_kp_s_file_s_not_found; static PyObject *__pyx_n_s_filename; static PyObject *__pyx_n_s_fileno; static PyObject *__pyx_n_s_filepath_index; static PyObject *__pyx_n_s_filepath_or_object; static PyObject *__pyx_n_s_flag; +static PyObject *__pyx_n_s_flag_filter; +static PyObject *__pyx_n_s_flag_require; static PyObject *__pyx_n_s_format; +static PyObject *__pyx_n_s_format_options; +static PyObject *__pyx_n_s_from_dict; +static PyObject *__pyx_n_s_from_references; +static PyObject *__pyx_n_s_from_text; +static PyObject *__pyx_n_s_from_text_and_lengths; static PyObject *__pyx_n_s_genotype; static PyObject *__pyx_n_s_get; static PyObject *__pyx_n_s_get_aligned_pairs; +static PyObject *__pyx_n_s_get_reference_length; static PyObject *__pyx_n_s_get_reference_name; static PyObject *__pyx_n_s_get_tid; +static PyObject *__pyx_n_s_getitem; static PyObject *__pyx_n_s_getstate; -static PyObject *__pyx_n_s_gettid; static PyObject *__pyx_n_s_h; static PyObject *__pyx_n_s_has_index; +static PyObject *__pyx_n_s_has_reference; static PyObject *__pyx_n_s_header; static PyObject *__pyx_kp_s_header_line_with_invalid_type_s; static PyObject *__pyx_kp_s_header_line_without_s; +static PyObject *__pyx_kp_s_header_not_available_in_closed_f; +static PyObject *__pyx_n_s_ignore_orphans; +static PyObject *__pyx_n_s_ignore_overlaps; +static PyObject *__pyx_n_s_ignore_truncation; static PyObject *__pyx_n_s_import; static PyObject *__pyx_kp_s_incomplete_sequence_information; +static PyObject *__pyx_n_s_index_filename; static PyObject *__pyx_n_s_init; -static PyObject *__pyx_kp_s_invalid_coordinates_start_i_end; +static PyObject *__pyx_kp_s_interval_of_size_0; +static PyObject *__pyx_kp_s_interval_of_size_less_than_0; static PyObject *__pyx_kp_s_invalid_file_opening_mode_s; -static PyObject *__pyx_kp_s_invalid_reference_s; static PyObject *__pyx_kp_s_invalid_type_for_record_s_s_expe; static PyObject *__pyx_n_s_io; static PyObject *__pyx_n_s_is_bam; static PyObject *__pyx_n_s_is_cram; static PyObject *__pyx_n_s_is_open; +static PyObject *__pyx_n_s_is_valid_tid; static PyObject *__pyx_n_s_islower; static PyObject *__pyx_n_s_isupper; static PyObject *__pyx_n_s_items; static PyObject *__pyx_n_s_join; static PyObject *__pyx_n_s_key; +static PyObject *__pyx_n_s_keys; +static PyObject *__pyx_n_s_len; static PyObject *__pyx_n_s_lengths; static PyObject *__pyx_n_s_line; static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_make; static PyObject *__pyx_kp_s_malformatted_header_no_in_field; static PyObject *__pyx_n_s_map; +static PyObject *__pyx_n_s_mapped; static PyObject *__pyx_kp_s_mapping_information_not_recorded; static PyObject *__pyx_n_s_mapping_quality; static PyObject *__pyx_kp_s_mate_not_found; static PyObject *__pyx_kp_s_mate_s_is_unmapped; static PyObject *__pyx_n_s_max_depth; +static PyObject *__pyx_n_s_min_base_quality; +static PyObject *__pyx_n_s_min_mapping_quality; static PyObject *__pyx_n_s_mode; static PyObject *__pyx_n_s_multiple_iterators; +static PyObject *__pyx_kp_s_multiple_iterators_not_implement; static PyObject *__pyx_kp_s_multiple_s_lines_are_not_permitt; static PyObject *__pyx_n_s_n; static PyObject *__pyx_n_s_name; static PyObject *__pyx_n_s_name_2; +static PyObject *__pyx_n_s_namedtuple; static PyObject *__pyx_n_s_new; static PyObject *__pyx_n_s_nextiter; static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; @@ -3234,11 +3378,12 @@ static PyObject *__pyx_kp_s_no_index_available_for_fetch; static PyObject *__pyx_kp_s_no_index_available_for_iteration; static PyObject *__pyx_kp_s_no_index_available_for_pileup; static PyObject *__pyx_n_s_nofilter; +static PyObject *__pyx_kp_s_not_enough_information_to_constr; static PyObject *__pyx_n_s_nreferences; +static PyObject *__pyx_kp_s_number_of_reference_names_and_le; static PyObject *__pyx_n_s_open; static PyObject *__pyx_n_s_os; static PyObject *__pyx_n_s_parse_region; -static PyObject *__pyx_n_s_path; static PyObject *__pyx_n_s_pickle; static PyObject *__pyx_kp_s_pileup_of_samfiles_not_implement; static PyObject *__pyx_n_s_port; @@ -3258,6 +3403,7 @@ static PyObject *__pyx_n_s_query_name; static PyObject *__pyx_n_s_query_qualities; static PyObject *__pyx_n_s_r; static PyObject *__pyx_n_s_rU; +static PyObject *__pyx_n_s_range; static PyObject *__pyx_n_s_rb; static PyObject *__pyx_n_s_rc; static PyObject *__pyx_n_s_re; @@ -3265,6 +3411,7 @@ static PyObject *__pyx_n_s_read_callback; static PyObject *__pyx_kp_s_read_s_is_unpaired; static PyObject *__pyx_kp_s_read_s_not_found; static PyObject *__pyx_n_s_record; +static PyObject *__pyx_n_s_redo_baq; static PyObject *__pyx_n_s_reduce; static PyObject *__pyx_n_s_reduce_cython; static PyObject *__pyx_n_s_reduce_ex; @@ -3274,46 +3421,56 @@ static PyObject *__pyx_n_s_reference_filename; static PyObject *__pyx_kp_s_reference_id_i_out_of_range_0_ti; static PyObject *__pyx_n_s_reference_lengths; static PyObject *__pyx_n_s_reference_names; -static PyObject *__pyx_kp_s_reference_sequence_for_s_tid_i_n; +static PyObject *__pyx_kp_s_reference_sequence_for_tid_not_f; static PyObject *__pyx_n_s_referencelengths; static PyObject *__pyx_n_s_referencenames; static PyObject *__pyx_n_s_references; static PyObject *__pyx_n_s_region; +static PyObject *__pyx_n_s_require_index; static PyObject *__pyx_kp_s_s; static PyObject *__pyx_kp_s_s_s; static PyObject *__pyx_kp_s_sam_write1_failed_with_error_cod; static PyObject *__pyx_n_s_samfile; static PyObject *__pyx_n_s_samtools; -static PyObject *__pyx_kp_s_self_b_self_header_self_htsfile; -static PyObject *__pyx_kp_s_self_b_self_header_self_htsfile_2; -static PyObject *__pyx_kp_s_self_header_self_htsfile_cannot; +static PyObject *__pyx_kp_s_self_b_self_htsfile_self_index_c; +static PyObject *__pyx_kp_s_self_b_self_htsfile_self_index_s; +static PyObject *__pyx_kp_s_self_htsfile_cannot_be_converted; static PyObject *__pyx_n_s_seq; static PyObject *__pyx_n_s_setstate; static PyObject *__pyx_n_s_setstate_cython; static PyObject *__pyx_n_s_snp_quality; static PyObject *__pyx_n_s_split; +static PyObject *__pyx_n_s_splitlines; static PyObject *__pyx_n_s_start; -static PyObject *__pyx_kp_s_start_out_of_range_i; static PyObject *__pyx_n_s_startswith; static PyObject *__pyx_n_s_stepper; +static PyObject *__pyx_n_s_stop; +static PyObject *__pyx_n_s_str; static PyObject *__pyx_kp_s_stringsource; static PyObject *__pyx_n_s_strip; +static PyObject *__pyx_n_s_sum; static PyObject *__pyx_n_s_tell; static PyObject *__pyx_n_s_template; static PyObject *__pyx_n_s_test; static PyObject *__pyx_n_s_text; +static PyObject *__pyx_n_s_threads; static PyObject *__pyx_n_s_tid; +static PyObject *__pyx_n_s_to_dict; +static PyObject *__pyx_n_s_total; static PyObject *__pyx_n_s_traceback; static PyObject *__pyx_n_s_truncate; static PyObject *__pyx_kp_s_truncated_file; -static PyObject *__pyx_kp_s_unable_to_open_index_at_s; -static PyObject *__pyx_kp_s_unable_to_open_remote_index_for; -static PyObject *__pyx_kp_s_unequal_names_and_lengths_of_ref; +static PyObject *__pyx_kp_s_unable_to_open_index_file; +static PyObject *__pyx_kp_s_unable_to_open_index_file_s; +static PyObject *__pyx_kp_s_unable_to_read_header_informatio; +static PyObject *__pyx_kp_s_unable_to_reopen_htsfile; +static PyObject *__pyx_kp_s_unknown_reference; static PyObject *__pyx_kp_s_unknown_stepper_option_s_in_Iter; +static PyObject *__pyx_n_s_unmapped; static PyObject *__pyx_n_s_until_eof; static PyObject *__pyx_n_s_update; +static PyObject *__pyx_n_s_values; static PyObject *__pyx_n_s_w; -static PyObject *__pyx_n_s_warn; static PyObject *__pyx_n_s_warnings; static PyObject *__pyx_n_s_wb; static PyObject *__pyx_n_s_wb0; @@ -3321,47 +3478,82 @@ static PyObject *__pyx_n_s_wbu; static PyObject *__pyx_n_s_wc; static PyObject *__pyx_n_s_wh; static PyObject *__pyx_n_s_write; +static PyObject *__pyx_kp_s_wrong_sequence_information_in_s; static PyObject *__pyx_n_s_zip; static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_fields, PyObject *__pyx_v_record); /* proto */ +static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_2__init__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths(CYTHON_UNUSED PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_text, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_text); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_header_dict); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_text, PyObject *__pyx_v_add_sq_text); /* proto */ +static void __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_12__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_14__bool__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_16copy(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, int __pyx_v_tid); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_34__setitem__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_key, CYTHON_UNUSED PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_36__getitem__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_38items(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_42keys(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_44values(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_46get(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_args); /* proto */ +static Py_ssize_t __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_48__len__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_50__contains__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_2has_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4check_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_filepath_or_object, PyObject *__pyx_v_mode, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_template, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_reference_filename, PyObject *__pyx_v_text, PyObject *__pyx_v_header, CYTHON_UNUSED PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq, PyObject *__pyx_v_filepath_index, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths, PyObject *__pyx_v_duplicate_filehandle); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12parse_region(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_tid); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_14fetch(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_multiple_iterators); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_16head(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_n, PyObject *__pyx_v_multiple_iterators); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18mate(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20pileup(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_kwargs); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22count(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_read_callback); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24count_coverage(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_quality_threshold, PyObject *__pyx_v_read_callback); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26find_introns(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28close(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ -static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34__enter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__exit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_filepath_or_object, PyObject *__pyx_v_mode, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_template, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_reference_filename, PyObject *__pyx_v_text, PyObject *__pyx_v_header, CYTHON_UNUSED PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_add_sam_header, CYTHON_UNUSED PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq, PyObject *__pyx_v_index_filename, PyObject *__pyx_v_filepath_index, PyObject *__pyx_v_require_index, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths, PyObject *__pyx_v_duplicate_filehandle, PyObject *__pyx_v_ignore_truncation, PyObject *__pyx_v_format_options, PyObject *__pyx_v_threads); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8fetch(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_multiple_iterators, PyObject *__pyx_v_reference, PyObject *__pyx_v_end); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10head(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_n, PyObject *__pyx_v_multiple_iterators); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12mate(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_14pileup(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reference, PyObject *__pyx_v_end, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_16count(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_read_callback, PyObject *__pyx_v_reference, PyObject *__pyx_v_end); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_quality_threshold, PyObject *__pyx_v_read_callback, PyObject *__pyx_v_reference, PyObject *__pyx_v_end); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24close(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ +static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__next__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, int __pyx_v_tid); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4text___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6header___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40__next__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42gettid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44getrname(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48gettid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_50getrname(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6header___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators); /* proto */ static void __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_2__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ -static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_end, int __pyx_v_multiple_iterators); /* proto */ +static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_stop, int __pyx_v_multiple_iterators); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */ static void __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_6__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */ @@ -3391,12 +3583,14 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_8__s static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_kwargs); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len___get__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4addReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_Fastafile *__pyx_v_fastafile); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6hasReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */ static void __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ -static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, int __pyx_v_truncate, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12addReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_stop, int __pyx_v_truncate, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ @@ -3424,6 +3618,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_10__setstate static PyObject *__pyx_pf_5pysam_17libcalignmentfile_2__pyx_unpickle_SNPCall(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags); /* proto */ static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ +static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_PileupColumn(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_PileupRead(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ @@ -3441,29 +3636,31 @@ static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_SNPCall(PyTypeObject *t static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_get = {0, &__pyx_n_s_get, 0, 0, 0}; static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; +static PyObject *__pyx_int_2; +static PyObject *__pyx_int_7; +static PyObject *__pyx_int_8; +static PyObject *__pyx_int_13; static PyObject *__pyx_int_15; static PyObject *__pyx_int_1796; static PyObject *__pyx_int_8000; static PyObject *__pyx_int_84615809; static PyObject *__pyx_int_536870912; -static int __pyx_k__71; +static PyObject *__pyx_int_neg_1; +static int __pyx_k__85; static PyObject *__pyx_codeobj_; +static PyObject *__pyx_slice__7; +static PyObject *__pyx_tuple__3; static PyObject *__pyx_tuple__4; static PyObject *__pyx_tuple__5; static PyObject *__pyx_tuple__6; -static PyObject *__pyx_tuple__7; -static PyObject *__pyx_tuple__8; static PyObject *__pyx_tuple__9; -static PyObject *__pyx_slice__37; -static PyObject *__pyx_slice__39; -static PyObject *__pyx_slice__40; -static PyObject *__pyx_tuple__10; +static PyObject *__pyx_slice__16; +static PyObject *__pyx_slice__18; +static PyObject *__pyx_slice__19; +static PyObject *__pyx_tuple__11; static PyObject *__pyx_tuple__13; -static PyObject *__pyx_tuple__14; static PyObject *__pyx_tuple__15; static PyObject *__pyx_tuple__17; -static PyObject *__pyx_tuple__18; -static PyObject *__pyx_tuple__19; static PyObject *__pyx_tuple__20; static PyObject *__pyx_tuple__21; static PyObject *__pyx_tuple__22; @@ -3476,11 +3673,15 @@ static PyObject *__pyx_tuple__28; static PyObject *__pyx_tuple__29; static PyObject *__pyx_tuple__30; static PyObject *__pyx_tuple__31; -static PyObject *__pyx_tuple__32; static PyObject *__pyx_tuple__33; static PyObject *__pyx_tuple__34; +static PyObject *__pyx_tuple__35; static PyObject *__pyx_tuple__36; +static PyObject *__pyx_tuple__37; static PyObject *__pyx_tuple__38; +static PyObject *__pyx_tuple__39; +static PyObject *__pyx_tuple__40; +static PyObject *__pyx_tuple__41; static PyObject *__pyx_tuple__42; static PyObject *__pyx_tuple__43; static PyObject *__pyx_tuple__44; @@ -3510,6 +3711,7 @@ static PyObject *__pyx_tuple__67; static PyObject *__pyx_tuple__68; static PyObject *__pyx_tuple__69; static PyObject *__pyx_tuple__70; +static PyObject *__pyx_tuple__71; static PyObject *__pyx_tuple__72; static PyObject *__pyx_tuple__73; static PyObject *__pyx_tuple__74; @@ -3518,17 +3720,34 @@ static PyObject *__pyx_tuple__76; static PyObject *__pyx_tuple__77; static PyObject *__pyx_tuple__78; static PyObject *__pyx_tuple__79; +static PyObject *__pyx_tuple__80; static PyObject *__pyx_tuple__81; static PyObject *__pyx_tuple__82; static PyObject *__pyx_tuple__83; static PyObject *__pyx_tuple__84; -static PyObject *__pyx_tuple__85; static PyObject *__pyx_tuple__86; static PyObject *__pyx_tuple__87; -static PyObject *__pyx_codeobj__80; +static PyObject *__pyx_tuple__88; +static PyObject *__pyx_tuple__89; +static PyObject *__pyx_tuple__90; +static PyObject *__pyx_tuple__91; +static PyObject *__pyx_tuple__92; +static PyObject *__pyx_tuple__93; +static PyObject *__pyx_tuple__94; +static PyObject *__pyx_tuple__95; +static PyObject *__pyx_tuple__97; +static PyObject *__pyx_tuple__98; +static PyObject *__pyx_tuple__99; +static PyObject *__pyx_tuple__100; +static PyObject *__pyx_tuple__101; +static PyObject *__pyx_tuple__102; +static PyObject *__pyx_tuple__103; +static PyObject *__pyx_tuple__104; +static PyObject *__pyx_tuple__105; +static PyObject *__pyx_codeobj__96; /* Late includes */ -/* "pysam/libcalignmentfile.pyx":125 +/* "pysam/libcalignmentfile.pyx":135 * * * def build_header_line(fields, record): # <<<<<<<<<<<<<< @@ -3569,11 +3788,11 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_1build_header_line(PyObject case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_record)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("build_header_line", 1, 2, 2, 1); __PYX_ERR(0, 125, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("build_header_line", 1, 2, 2, 1); __PYX_ERR(0, 135, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "build_header_line") < 0)) __PYX_ERR(0, 125, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "build_header_line") < 0)) __PYX_ERR(0, 135, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -3586,7 +3805,7 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_1build_header_line(PyObject } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("build_header_line", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 125, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("build_header_line", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 135, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcalignmentfile.build_header_line", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -3616,18 +3835,18 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN PyObject *__pyx_t_9 = NULL; __Pyx_TraceFrameInit(__pyx_codeobj_) __Pyx_RefNannySetupContext("build_header_line", 0); - __Pyx_TraceCall("build_header_line", __pyx_f[0], 125, 0, __PYX_ERR(0, 125, __pyx_L1_error)); + __Pyx_TraceCall("build_header_line", __pyx_f[0], 135, 0, __PYX_ERR(0, 135, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":129 + /* "pysam/libcalignmentfile.pyx":139 * * # TODO: add checking for field and sort order * line = ["@%s" % record] # <<<<<<<<<<<<<< * # comment * if record == "CO": */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 129, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_1); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); @@ -3635,26 +3854,26 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN __pyx_v_line = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":131 + /* "pysam/libcalignmentfile.pyx":141 * line = ["@%s" % record] * # comment * if record == "CO": # <<<<<<<<<<<<<< * line.append(fields) * # user tags */ - __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_record, __pyx_n_s_CO, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_record, __pyx_n_s_CO, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 141, __pyx_L1_error) if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":132 + /* "pysam/libcalignmentfile.pyx":142 * # comment * if record == "CO": * line.append(fields) # <<<<<<<<<<<<<< * # user tags * elif record.islower(): */ - __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_v_fields); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 132, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_v_fields); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 142, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":131 + /* "pysam/libcalignmentfile.pyx":141 * line = ["@%s" % record] * # comment * if record == "CO": # <<<<<<<<<<<<<< @@ -3664,14 +3883,14 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN goto __pyx_L3; } - /* "pysam/libcalignmentfile.pyx":134 + /* "pysam/libcalignmentfile.pyx":144 * line.append(fields) * # user tags * elif record.islower(): # <<<<<<<<<<<<<< * for key in sorted(fields): * line.append("%s:%s" % (key, str(fields[key]))) */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_record, __pyx_n_s_islower); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_record, __pyx_n_s_islower); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { @@ -3684,59 +3903,59 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN } } if (__pyx_t_5) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 144, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 144, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 134, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 144, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":135 + /* "pysam/libcalignmentfile.pyx":145 * # user tags * elif record.islower(): * for key in sorted(fields): # <<<<<<<<<<<<<< * line.append("%s:%s" % (key, str(fields[key]))) * # defined tags */ - __pyx_t_1 = PySequence_List(__pyx_v_fields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error) + __pyx_t_1 = PySequence_List(__pyx_v_fields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 145, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = PyList_Sort(__pyx_t_2); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 135, __pyx_L1_error) + __pyx_t_4 = PyList_Sort(__pyx_t_2); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 145, __pyx_L1_error) if (unlikely(__pyx_t_2 == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); - __PYX_ERR(0, 135, __pyx_L1_error) + __PYX_ERR(0, 145, __pyx_L1_error) } __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 135, __pyx_L1_error) + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 145, __pyx_L1_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 135, __pyx_L1_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 145, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":136 + /* "pysam/libcalignmentfile.pyx":146 * elif record.islower(): * for key in sorted(fields): * line.append("%s:%s" % (key, str(fields[key]))) # <<<<<<<<<<<<<< * # defined tags * else: */ - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 146, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 136, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 146, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 146, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_key); __Pyx_GIVEREF(__pyx_v_key); @@ -3744,13 +3963,13 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 136, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 146, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_5); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 136, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_5); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 146, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":135 + /* "pysam/libcalignmentfile.pyx":145 * # user tags * elif record.islower(): * for key in sorted(fields): # <<<<<<<<<<<<<< @@ -3760,7 +3979,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":134 + /* "pysam/libcalignmentfile.pyx":144 * line.append(fields) * # user tags * elif record.islower(): # <<<<<<<<<<<<<< @@ -3770,7 +3989,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN goto __pyx_L3; } - /* "pysam/libcalignmentfile.pyx":140 + /* "pysam/libcalignmentfile.pyx":150 * else: * # write fields of the specification * for key in VALID_HEADER_ORDER[record]: # <<<<<<<<<<<<<< @@ -3778,18 +3997,18 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN * line.append("%s:%s" % (key, str(fields[key]))) */ /*else*/ { - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_ORDER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_ORDER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 150, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 140, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 150, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) { __pyx_t_1 = __pyx_t_5; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0; __pyx_t_7 = NULL; } else { - __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error) + __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 150, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 140, __pyx_L1_error) + __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 150, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; for (;;) { @@ -3797,17 +4016,17 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 140, __pyx_L1_error) + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 150, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 140, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 150, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif } else { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 140, __pyx_L1_error) + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 150, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 140, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 150, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif } @@ -3817,7 +4036,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 140, __pyx_L1_error) + else __PYX_ERR(0, 150, __pyx_L1_error) } break; } @@ -3826,30 +4045,30 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":141 + /* "pysam/libcalignmentfile.pyx":151 * # write fields of the specification * for key in VALID_HEADER_ORDER[record]: * if key in fields: # <<<<<<<<<<<<<< * line.append("%s:%s" % (key, str(fields[key]))) * # write user fields */ - __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_v_key, __pyx_v_fields, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 141, __pyx_L1_error) + __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_v_key, __pyx_v_fields, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 151, __pyx_L1_error) __pyx_t_8 = (__pyx_t_3 != 0); if (__pyx_t_8) { - /* "pysam/libcalignmentfile.pyx":142 + /* "pysam/libcalignmentfile.pyx":152 * for key in VALID_HEADER_ORDER[record]: * if key in fields: * line.append("%s:%s" % (key, str(fields[key]))) # <<<<<<<<<<<<<< * # write user fields * for key in fields: */ - __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_v_key); __Pyx_GIVEREF(__pyx_v_key); @@ -3857,13 +4076,13 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_2); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_2); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":141 + /* "pysam/libcalignmentfile.pyx":151 * # write fields of the specification * for key in VALID_HEADER_ORDER[record]: * if key in fields: # <<<<<<<<<<<<<< @@ -3872,7 +4091,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN */ } - /* "pysam/libcalignmentfile.pyx":140 + /* "pysam/libcalignmentfile.pyx":150 * else: * # write fields of the specification * for key in VALID_HEADER_ORDER[record]: # <<<<<<<<<<<<<< @@ -3882,7 +4101,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":144 + /* "pysam/libcalignmentfile.pyx":154 * line.append("%s:%s" % (key, str(fields[key]))) * # write user fields * for key in fields: # <<<<<<<<<<<<<< @@ -3893,26 +4112,26 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN __pyx_t_1 = __pyx_v_fields; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0; __pyx_t_7 = NULL; } else { - __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_fields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error) + __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_fields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 144, __pyx_L1_error) + __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 154, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_7)) { if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 144, __pyx_L1_error) + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 154, __pyx_L1_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 144, __pyx_L1_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 144, __pyx_L1_error) + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 154, __pyx_L1_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 144, __pyx_L1_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif } @@ -3922,7 +4141,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 144, __pyx_L1_error) + else __PYX_ERR(0, 154, __pyx_L1_error) } break; } @@ -3931,14 +4150,14 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":145 + /* "pysam/libcalignmentfile.pyx":155 * # write user fields * for key in fields: * if not key.isupper(): # <<<<<<<<<<<<<< * line.append("%s:%s" % (key, str(fields[key]))) * */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_key, __pyx_n_s_isupper); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 145, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_key, __pyx_n_s_isupper); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { @@ -3951,31 +4170,31 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN } } if (__pyx_t_9) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 145, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 145, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 155, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 145, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_3 = ((!__pyx_t_8) != 0); if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":146 + /* "pysam/libcalignmentfile.pyx":156 * for key in fields: * if not key.isupper(): * line.append("%s:%s" % (key, str(fields[key]))) # <<<<<<<<<<<<<< * * return "\t".join(line) */ - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 146, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 146, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 146, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_key); __Pyx_GIVEREF(__pyx_v_key); @@ -3983,13 +4202,13 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 146, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_5); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 146, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_5); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":145 + /* "pysam/libcalignmentfile.pyx":155 * # write user fields * for key in fields: * if not key.isupper(): # <<<<<<<<<<<<<< @@ -3998,7 +4217,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN */ } - /* "pysam/libcalignmentfile.pyx":144 + /* "pysam/libcalignmentfile.pyx":154 * line.append("%s:%s" % (key, str(fields[key]))) * # write user fields * for key in fields: # <<<<<<<<<<<<<< @@ -4010,21 +4229,21 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN } __pyx_L3:; - /* "pysam/libcalignmentfile.pyx":148 + /* "pysam/libcalignmentfile.pyx":158 * line.append("%s:%s" % (key, str(fields[key]))) * * return "\t".join(line) # <<<<<<<<<<<<<< * - * cdef bam_hdr_t * build_header(new_header): + * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_v_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_v_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":125 + /* "pysam/libcalignmentfile.pyx":135 * * * def build_header_line(fields, record): # <<<<<<<<<<<<<< @@ -4049,4268 +4268,9647 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UN return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":150 - * return "\t".join(line) +/* "pysam/libcalignmentfile.pyx":161 * - * cdef bam_hdr_t * build_header(new_header): # <<<<<<<<<<<<<< - * '''return a new header built from a dictionary in `new_header`. * + * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr): # <<<<<<<<<<<<<< + * if not hdr: + * raise ValueError('cannot create AlignmentHeader, received NULL pointer') */ -static bam_hdr_t *__pyx_f_5pysam_17libcalignmentfile_build_header(PyObject *__pyx_v_new_header) { - PyObject *__pyx_v_lines = NULL; - bam_hdr_t *__pyx_v_dest; - PyObject *__pyx_v_record = NULL; - PyObject *__pyx_v_ttype = NULL; - PyObject *__pyx_v_data = NULL; - PyObject *__pyx_v_fields = NULL; - PyObject *__pyx_v_text = NULL; - PyObject *__pyx_v_btext = 0; - PyObject *__pyx_v_bseqname = 0; - PyObject *__pyx_v_seqs = NULL; - long __pyx_v_x; - PyObject *__pyx_v_seqname = NULL; - PyObject *__pyx_v_seqlen = NULL; - bam_hdr_t *__pyx_r; +static struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(bam_hdr_t *__pyx_v_hdr) { + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header = 0; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - PyObject *(*__pyx_t_4)(PyObject *); - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - int __pyx_t_11; - Py_ssize_t __pyx_t_12; - PyObject *(*__pyx_t_13)(PyObject *); - PyObject *__pyx_t_14 = NULL; - PyObject *(*__pyx_t_15)(PyObject *); - char const *__pyx_t_16; - PyObject *__pyx_t_17 = NULL; - PyObject *__pyx_t_18 = NULL; - PyObject *__pyx_t_19 = NULL; - int32_t __pyx_t_20; - uint32_t __pyx_t_21; - __Pyx_RefNannySetupContext("build_header", 0); - __Pyx_TraceCall("build_header", __pyx_f[0], 150, 0, __PYX_ERR(0, 150, __pyx_L1_error)); + __Pyx_RefNannySetupContext("makeAlignmentHeader", 0); + __Pyx_TraceCall("makeAlignmentHeader", __pyx_f[0], 161, 0, __PYX_ERR(0, 161, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":156 - * ''' + /* "pysam/libcalignmentfile.pyx":162 * - * lines = [] # <<<<<<<<<<<<<< + * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr): + * if not hdr: # <<<<<<<<<<<<<< + * raise ValueError('cannot create AlignmentHeader, received NULL pointer') * - * # check if hash exists */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_lines = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_1 = ((!(__pyx_v_hdr != 0)) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":163 - * cdef bam_hdr_t * dest + /* "pysam/libcalignmentfile.pyx":163 + * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr): + * if not hdr: + * raise ValueError('cannot create AlignmentHeader, received NULL pointer') # <<<<<<<<<<<<<< + * + * # check: is AlignmetHeader.__cinit__ called? + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 163, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":162 * - * dest = bam_hdr_init() # <<<<<<<<<<<<<< + * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr): + * if not hdr: # <<<<<<<<<<<<<< + * raise ValueError('cannot create AlignmentHeader, received NULL pointer') * - * # first: defined tags */ - __pyx_v_dest = bam_hdr_init(); + } /* "pysam/libcalignmentfile.pyx":166 * - * # first: defined tags - * for record in VALID_HEADERS: # <<<<<<<<<<<<<< - * if record in new_header: - * ttype = VALID_HEADER_TYPES[record] + * # check: is AlignmetHeader.__cinit__ called? + * cdef AlignmentHeader header = AlignmentHeader.__new__(AlignmentHeader) # <<<<<<<<<<<<<< + * header.ptr = hdr + * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADERS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 166, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 166, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 166, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 166, __pyx_L1_error) - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - #endif - } - } else { - __pyx_t_1 = __pyx_t_4(__pyx_t_2); - if (unlikely(!__pyx_t_1)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 166, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_2 = ((PyObject *)__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader(((PyTypeObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 166, __pyx_L1_error) + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_v_header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":167 - * # first: defined tags - * for record in VALID_HEADERS: - * if record in new_header: # <<<<<<<<<<<<<< - * ttype = VALID_HEADER_TYPES[record] - * data = new_header[record] + /* "pysam/libcalignmentfile.pyx":167 + * # check: is AlignmetHeader.__cinit__ called? + * cdef AlignmentHeader header = AlignmentHeader.__new__(AlignmentHeader) + * header.ptr = hdr # <<<<<<<<<<<<<< + * + * return header */ - __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_new_header, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 167, __pyx_L1_error) - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { + __pyx_v_header->ptr = __pyx_v_hdr; - /* "pysam/libcalignmentfile.pyx":168 - * for record in VALID_HEADERS: - * if record in new_header: - * ttype = VALID_HEADER_TYPES[record] # <<<<<<<<<<<<<< - * data = new_header[record] - * if type(data) != type(ttype()): + /* "pysam/libcalignmentfile.pyx":169 + * header.ptr = hdr + * + * return header # <<<<<<<<<<<<<< + * + * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 168, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 168, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_ttype, __pyx_t_7); - __pyx_t_7 = 0; + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_header)); + __pyx_r = __pyx_v_header; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":169 - * if record in new_header: - * ttype = VALID_HEADER_TYPES[record] - * data = new_header[record] # <<<<<<<<<<<<<< - * if type(data) != type(ttype()): - * raise ValueError( + /* "pysam/libcalignmentfile.pyx":161 + * + * + * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr): # <<<<<<<<<<<<<< + * if not hdr: + * raise ValueError('cannot create AlignmentHeader, received NULL pointer') */ - __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 169, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_XDECREF_SET(__pyx_v_data, __pyx_t_7); - __pyx_t_7 = 0; - /* "pysam/libcalignmentfile.pyx":170 - * ttype = VALID_HEADER_TYPES[record] - * data = new_header[record] - * if type(data) != type(ttype()): # <<<<<<<<<<<<<< - * raise ValueError( - * "invalid type for record %s: %s, expected %s" % + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignmentfile.makeAlignmentHeader", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_header); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":174 + * # the following should be class-method for VariantHeader, but cdef @classmethods + * # are not implemented in cython. + * cdef int fill_AlignmentHeader_from_list(bam_hdr_t *dest, # <<<<<<<<<<<<<< + * reference_names, + * reference_lengths, */ - __Pyx_INCREF(__pyx_v_ttype); - __pyx_t_1 = __pyx_v_ttype; __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - if (__pyx_t_8) { - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 170, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else { - __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 170, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_data)), ((PyObject *)Py_TYPE(__pyx_t_7)), Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 170, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 170, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(__pyx_t_6)) { - /* "pysam/libcalignmentfile.pyx":173 - * raise ValueError( - * "invalid type for record %s: %s, expected %s" % - * (record, type(data), type(ttype()))) # <<<<<<<<<<<<<< - * if type(data) is dict: - * lines.append(build_header_line(data, record)) +static int __pyx_f_5pysam_17libcalignmentfile_fill_AlignmentHeader_from_list(CYTHON_UNUSED bam_hdr_t *__pyx_v_dest, CYTHON_UNUSED PyObject *__pyx_v_reference_names, CYTHON_UNUSED PyObject *__pyx_v_reference_lengths, struct __pyx_opt_args_5pysam_17libcalignmentfile_fill_AlignmentHeader_from_list *__pyx_optional_args) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("fill_AlignmentHeader_from_list", 0); + __Pyx_TraceCall("fill_AlignmentHeader_from_list", __pyx_f[0], 174, 0, __PYX_ERR(0, 174, __pyx_L1_error)); + if (__pyx_optional_args) { + } + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignmentfile.fill_AlignmentHeader_from_list", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":215 + * + * # See makeVariantHeader for C constructor + * def __cinit__(self): # <<<<<<<<<<<<<< + * self.ptr = NULL + * */ - __Pyx_INCREF(__pyx_v_ttype); - __pyx_t_7 = __pyx_v_ttype; __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - if (__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 173, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 173, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 173, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_v_record); - __Pyx_GIVEREF(__pyx_v_record); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_record); - __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_data))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_data))); - PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)Py_TYPE(__pyx_v_data))); - __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_t_1))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_t_1))); - PyTuple_SET_ITEM(__pyx_t_7, 2, ((PyObject *)Py_TYPE(__pyx_t_1))); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":172 - * if type(data) != type(ttype()): - * raise ValueError( - * "invalid type for record %s: %s, expected %s" % # <<<<<<<<<<<<<< - * (record, type(data), type(ttype()))) - * if type(data) is dict: +/* Python wrapper */ +static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 215, 0, __PYX_ERR(0, 215, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":216 + * # See makeVariantHeader for C constructor + * def __cinit__(self): + * self.ptr = NULL # <<<<<<<<<<<<<< + * + * # Python constructor */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_invalid_type_for_record_s_s_expe, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 172, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_self->ptr = NULL; - /* "pysam/libcalignmentfile.pyx":171 - * data = new_header[record] - * if type(data) != type(ttype()): - * raise ValueError( # <<<<<<<<<<<<<< - * "invalid type for record %s: %s, expected %s" % - * (record, type(data), type(ttype()))) + /* "pysam/libcalignmentfile.pyx":215 + * + * # See makeVariantHeader for C constructor + * def __cinit__(self): # <<<<<<<<<<<<<< + * self.ptr = NULL + * */ - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 171, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_7, 0, 0, 0); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __PYX_ERR(0, 171, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":170 - * ttype = VALID_HEADER_TYPES[record] - * data = new_header[record] - * if type(data) != type(ttype()): # <<<<<<<<<<<<<< - * raise ValueError( - * "invalid type for record %s: %s, expected %s" % + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":219 + * + * # Python constructor + * def __init__(self): # <<<<<<<<<<<<<< + * self.ptr = bam_hdr_init() + * if self.ptr is NULL: */ - } - /* "pysam/libcalignmentfile.pyx":174 - * "invalid type for record %s: %s, expected %s" % - * (record, type(data), type(ttype()))) - * if type(data) is dict: # <<<<<<<<<<<<<< - * lines.append(build_header_line(data, record)) - * else: +/* Python wrapper */ +static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_2__init__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_2__init__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__init__", 0); + __Pyx_TraceCall("__init__", __pyx_f[0], 219, 0, __PYX_ERR(0, 219, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":220 + * # Python constructor + * def __init__(self): + * self.ptr = bam_hdr_init() # <<<<<<<<<<<<<< + * if self.ptr is NULL: + * raise MemoryError("could not create header") */ - __pyx_t_6 = (((PyObject *)Py_TYPE(__pyx_v_data)) == ((PyObject *)(&PyDict_Type))); - __pyx_t_5 = (__pyx_t_6 != 0); - if (__pyx_t_5) { + __pyx_v_self->ptr = bam_hdr_init(); - /* "pysam/libcalignmentfile.pyx":175 - * (record, type(data), type(ttype()))) - * if type(data) is dict: - * lines.append(build_header_line(data, record)) # <<<<<<<<<<<<<< - * else: - * for fields in new_header[record]: + /* "pysam/libcalignmentfile.pyx":221 + * def __init__(self): + * self.ptr = bam_hdr_init() + * if self.ptr is NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not create header") + * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_build_header_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_data, __pyx_v_record}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 175, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_data, __pyx_v_record}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 175, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - { - __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_INCREF(__pyx_v_data); - __Pyx_GIVEREF(__pyx_v_data); - PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_v_data); - __Pyx_INCREF(__pyx_v_record); - __Pyx_GIVEREF(__pyx_v_record); - PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_v_record); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_10, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_7); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 175, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_1 = ((__pyx_v_self->ptr == NULL) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":174 - * "invalid type for record %s: %s, expected %s" % - * (record, type(data), type(ttype()))) - * if type(data) is dict: # <<<<<<<<<<<<<< - * lines.append(build_header_line(data, record)) - * else: + /* "pysam/libcalignmentfile.pyx":222 + * self.ptr = bam_hdr_init() + * if self.ptr is NULL: + * raise MemoryError("could not create header") # <<<<<<<<<<<<<< + * + * @classmethod */ - goto __pyx_L7; - } + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 222, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 222, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":177 - * lines.append(build_header_line(data, record)) - * else: - * for fields in new_header[record]: # <<<<<<<<<<<<<< - * lines.append(build_header_line(fields, record)) + /* "pysam/libcalignmentfile.pyx":221 + * def __init__(self): + * self.ptr = bam_hdr_init() + * if self.ptr is NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not create header") * */ - /*else*/ { - __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 177, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) { - __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __pyx_t_12 = 0; - __pyx_t_13 = NULL; - } else { - __pyx_t_12 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 177, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_13 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 177, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - for (;;) { - if (likely(!__pyx_t_13)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_7); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 177, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 177, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } else { - if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_7); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 177, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 177, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } - } else { - __pyx_t_7 = __pyx_t_13(__pyx_t_1); - if (unlikely(!__pyx_t_7)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 177, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_7); - } - __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_7); - __pyx_t_7 = 0; + } - /* "pysam/libcalignmentfile.pyx":178 - * else: - * for fields in new_header[record]: - * lines.append(build_header_line(fields, record)) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":219 * - * # then: user tags (lower case), sorted alphabetically + * # Python constructor + * def __init__(self): # <<<<<<<<<<<<<< + * self.ptr = bam_hdr_init() + * if self.ptr is NULL: */ - __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_build_header_line); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 178, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_8 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_fields, __pyx_v_record}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 178, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_fields, __pyx_v_record}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 178, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - { - __pyx_t_14 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 178, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_INCREF(__pyx_v_fields); - __Pyx_GIVEREF(__pyx_v_fields); - PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_9, __pyx_v_fields); - __Pyx_INCREF(__pyx_v_record); - __Pyx_GIVEREF(__pyx_v_record); - PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_9, __pyx_v_record); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_14, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 178, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_7); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 178, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcalignmentfile.pyx":177 - * lines.append(build_header_line(data, record)) - * else: - * for fields in new_header[record]: # <<<<<<<<<<<<<< - * lines.append(build_header_line(fields, record)) + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":225 * + * @classmethod + * def _from_text_and_lengths(cls, text, reference_names, reference_lengths): # <<<<<<<<<<<<<< + * + * cdef AlignmentHeader self = AlignmentHeader() */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_5_from_text_and_lengths(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths[] = "AlignmentHeader._from_text_and_lengths(type cls, text, reference_names, reference_lengths)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_5_from_text_and_lengths(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_text = 0; + PyObject *__pyx_v_reference_names = 0; + PyObject *__pyx_v_reference_lengths = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_from_text_and_lengths (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_text,&__pyx_n_s_reference_names,&__pyx_n_s_reference_lengths,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_text)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_names)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_from_text_and_lengths", 1, 3, 3, 1); __PYX_ERR(0, 225, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_lengths)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_from_text_and_lengths", 1, 3, 3, 2); __PYX_ERR(0, 225, __pyx_L3_error) } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - __pyx_L7:; - - /* "pysam/libcalignmentfile.pyx":167 - * # first: defined tags - * for record in VALID_HEADERS: - * if record in new_header: # <<<<<<<<<<<<<< - * ttype = VALID_HEADER_TYPES[record] - * data = new_header[record] - */ + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_from_text_and_lengths") < 0)) __PYX_ERR(0, 225, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } - - /* "pysam/libcalignmentfile.pyx":166 - * - * # first: defined tags - * for record in VALID_HEADERS: # <<<<<<<<<<<<<< - * if record in new_header: - * ttype = VALID_HEADER_TYPES[record] - */ + __pyx_v_text = values[0]; + __pyx_v_reference_names = values[1]; + __pyx_v_reference_lengths = values[2]; } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("_from_text_and_lengths", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 225, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader._from_text_and_lengths", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths(((PyTypeObject*)__pyx_v_cls), __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths(CYTHON_UNUSED PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_text, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths) { + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self = 0; + char *__pyx_v_ctext; + int __pyx_v_l_text; + int __pyx_v_n; + int __pyx_v_x; + PyObject *__pyx_v_btext = NULL; + PyObject *__pyx_v_name = NULL; + PyObject *__pyx_v_ref = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + char *__pyx_t_4; + Py_ssize_t __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *(*__pyx_t_10)(PyObject *); + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + int32_t __pyx_t_13; + uint32_t __pyx_t_14; + char const *__pyx_t_15; + __Pyx_RefNannySetupContext("_from_text_and_lengths", 0); + __Pyx_TraceCall("_from_text_and_lengths", __pyx_f[0], 225, 0, __PYX_ERR(0, 225, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_reference_names); - /* "pysam/libcalignmentfile.pyx":181 + /* "pysam/libcalignmentfile.pyx":227 + * def _from_text_and_lengths(cls, text, reference_names, reference_lengths): * - * # then: user tags (lower case), sorted alphabetically - * for record, data in sorted(new_header.items()): # <<<<<<<<<<<<<< - * if record in VALID_HEADERS: continue - * if type(data) is dict: + * cdef AlignmentHeader self = AlignmentHeader() # <<<<<<<<<<<<<< + * cdef char *ctext + * cdef int l_text */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_header, __pyx_n_s_items); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 181, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - if (__pyx_t_10) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 181, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 181, __pyx_L1_error) - } + __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 227, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 181, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_2 = ((PyObject*)__pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_11 = PyList_Sort(__pyx_t_2); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 181, __pyx_L1_error) - if (unlikely(__pyx_t_2 == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); - __PYX_ERR(0, 181, __pyx_L1_error) - } - __pyx_t_7 = __pyx_t_2; __Pyx_INCREF(__pyx_t_7); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 181, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 181, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 181, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_10 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_10); - #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 181, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 181, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_14 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 181, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_1)) goto __pyx_L12_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_10 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_10)) goto __pyx_L12_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) __PYX_ERR(0, 181, __pyx_L1_error) - __pyx_t_15 = NULL; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - goto __pyx_L13_unpacking_done; - __pyx_L12_unpacking_failed:; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_15 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 181, __pyx_L1_error) - __pyx_L13_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_1); - __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_data, __pyx_t_10); - __pyx_t_10 = 0; + __pyx_v_self = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":182 - * # then: user tags (lower case), sorted alphabetically - * for record, data in sorted(new_header.items()): - * if record in VALID_HEADERS: continue # <<<<<<<<<<<<<< - * if type(data) is dict: - * lines.append(build_header_line(data, record)) + /* "pysam/libcalignmentfile.pyx":231 + * cdef int l_text + * cdef int n, x + * if text is not None: # <<<<<<<<<<<<<< + * btext = force_bytes(text) + * ctext = btext */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADERS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 182, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { - goto __pyx_L10_continue; - } + __pyx_t_2 = (__pyx_v_text != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":183 - * for record, data in sorted(new_header.items()): - * if record in VALID_HEADERS: continue - * if type(data) is dict: # <<<<<<<<<<<<<< - * lines.append(build_header_line(data, record)) - * else: + /* "pysam/libcalignmentfile.pyx":232 + * cdef int n, x + * if text is not None: + * btext = force_bytes(text) # <<<<<<<<<<<<<< + * ctext = btext + * l_text = len(btext) */ - __pyx_t_6 = (((PyObject *)Py_TYPE(__pyx_v_data)) == ((PyObject *)(&PyDict_Type))); - __pyx_t_5 = (__pyx_t_6 != 0); - if (__pyx_t_5) { + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_text, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 232, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_btext = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":184 - * if record in VALID_HEADERS: continue - * if type(data) is dict: - * lines.append(build_header_line(data, record)) # <<<<<<<<<<<<<< - * else: - * for fields in new_header[record]: + /* "pysam/libcalignmentfile.pyx":233 + * if text is not None: + * btext = force_bytes(text) + * ctext = btext # <<<<<<<<<<<<<< + * l_text = len(btext) + * self.ptr.text = calloc(l_text + 1, sizeof(char)) */ - __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_build_header_line); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 184, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_1 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_1); + if (unlikely(__pyx_v_btext == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 233, __pyx_L1_error) + } + __pyx_t_4 = __Pyx_PyBytes_AsWritableString(__pyx_v_btext); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 233, __pyx_L1_error) + __pyx_v_ctext = __pyx_t_4; + + /* "pysam/libcalignmentfile.pyx":234 + * btext = force_bytes(text) + * ctext = btext + * l_text = len(btext) # <<<<<<<<<<<<<< + * self.ptr.text = calloc(l_text + 1, sizeof(char)) + * if self.ptr.text == NULL: + */ + if (unlikely(__pyx_v_btext == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(0, 234, __pyx_L1_error) + } + __pyx_t_5 = PyBytes_GET_SIZE(__pyx_v_btext); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 234, __pyx_L1_error) + __pyx_v_l_text = __pyx_t_5; + + /* "pysam/libcalignmentfile.pyx":235 + * ctext = btext + * l_text = len(btext) + * self.ptr.text = calloc(l_text + 1, sizeof(char)) # <<<<<<<<<<<<<< + * if self.ptr.text == NULL: + * raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char)) + */ + __pyx_v_self->ptr->text = ((char *)calloc((__pyx_v_l_text + 1), (sizeof(char)))); + + /* "pysam/libcalignmentfile.pyx":236 + * l_text = len(btext) + * self.ptr.text = calloc(l_text + 1, sizeof(char)) + * if self.ptr.text == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char)) + * self.ptr.l_text = l_text + */ + __pyx_t_3 = ((__pyx_v_self->ptr->text == NULL) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcalignmentfile.pyx":237 + * self.ptr.text = calloc(l_text + 1, sizeof(char)) + * if self.ptr.text == NULL: + * raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char)) # <<<<<<<<<<<<<< + * self.ptr.l_text = l_text + * memcpy(self.ptr.text, ctext, l_text + 1) + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyInt_From_long((__pyx_v_l_text + 1)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_8); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_10, function); - __pyx_t_9 = 1; + __Pyx_DECREF_SET(__pyx_t_6, function); } } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_data, __pyx_v_record}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 184, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_data, __pyx_v_record}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 184, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_14 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 184, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - if (__pyx_t_1) { - __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_1); __pyx_t_1 = NULL; + if (!__pyx_t_8) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } - __Pyx_INCREF(__pyx_v_data); - __Pyx_GIVEREF(__pyx_v_data); - PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_9, __pyx_v_data); - __Pyx_INCREF(__pyx_v_record); - __Pyx_GIVEREF(__pyx_v_record); - PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_9, __pyx_v_record); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 184, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_2); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 184, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pysam/libcalignmentfile.pyx":183 - * for record, data in sorted(new_header.items()): - * if record in VALID_HEADERS: continue - * if type(data) is dict: # <<<<<<<<<<<<<< - * lines.append(build_header_line(data, record)) - * else: - */ - goto __pyx_L15; - } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyInt_FromSize_t((sizeof(char))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_6); + __pyx_t_1 = 0; + __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 237, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":186 - * lines.append(build_header_line(data, record)) - * else: - * for fields in new_header[record]: # <<<<<<<<<<<<<< - * lines.append(build_header_line(fields, record)) - * + /* "pysam/libcalignmentfile.pyx":236 + * l_text = len(btext) + * self.ptr.text = calloc(l_text + 1, sizeof(char)) + * if self.ptr.text == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char)) + * self.ptr.l_text = l_text */ - /*else*/ { - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_10 = __pyx_t_2; __Pyx_INCREF(__pyx_t_10); __pyx_t_12 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_12 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_4 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 186, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_10))) { - if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_10)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_12); __Pyx_INCREF(__pyx_t_2); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 186, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_10, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_10)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_12); __Pyx_INCREF(__pyx_t_2); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 186, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_10, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_4(__pyx_t_10); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 186, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_2); - __pyx_t_2 = 0; + } - /* "pysam/libcalignmentfile.pyx":187 - * else: - * for fields in new_header[record]: - * lines.append(build_header_line(fields, record)) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":238 + * if self.ptr.text == NULL: + * raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char)) + * self.ptr.l_text = l_text # <<<<<<<<<<<<<< + * memcpy(self.ptr.text, ctext, l_text + 1) * - * text = "\n".join(lines) + "\n" */ - __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_build_header_line); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 187, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_1 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_9 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_fields, __pyx_v_record}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 187, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_fields, __pyx_v_record}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 187, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 187, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (__pyx_t_1) { - __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); __pyx_t_1 = NULL; - } - __Pyx_INCREF(__pyx_v_fields); - __Pyx_GIVEREF(__pyx_v_fields); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_9, __pyx_v_fields); - __Pyx_INCREF(__pyx_v_record); - __Pyx_GIVEREF(__pyx_v_record); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_9, __pyx_v_record); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 187, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_2); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 187, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_self->ptr->l_text = __pyx_v_l_text; - /* "pysam/libcalignmentfile.pyx":186 - * lines.append(build_header_line(data, record)) - * else: - * for fields in new_header[record]: # <<<<<<<<<<<<<< - * lines.append(build_header_line(fields, record)) + /* "pysam/libcalignmentfile.pyx":239 + * raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char)) + * self.ptr.l_text = l_text + * memcpy(self.ptr.text, ctext, l_text + 1) # <<<<<<<<<<<<<< * + * if reference_names and reference_lengths: */ - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __pyx_L15:; + (void)(memcpy(__pyx_v_self->ptr->text, __pyx_v_ctext, (__pyx_v_l_text + 1))); - /* "pysam/libcalignmentfile.pyx":181 - * - * # then: user tags (lower case), sorted alphabetically - * for record, data in sorted(new_header.items()): # <<<<<<<<<<<<<< - * if record in VALID_HEADERS: continue - * if type(data) is dict: + /* "pysam/libcalignmentfile.pyx":231 + * cdef int l_text + * cdef int n, x + * if text is not None: # <<<<<<<<<<<<<< + * btext = force_bytes(text) + * ctext = btext */ - __pyx_L10_continue:; } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcalignmentfile.pyx":189 - * lines.append(build_header_line(fields, record)) + /* "pysam/libcalignmentfile.pyx":241 + * memcpy(self.ptr.text, ctext, l_text + 1) * - * text = "\n".join(lines) + "\n" # <<<<<<<<<<<<<< - * if dest.text != NULL: free( dest.text ) - * dest.text = calloc(len(text), sizeof(char)) - */ - __pyx_t_7 = __Pyx_PyString_Join(__pyx_kp_s__3, __pyx_v_lines); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = PyNumber_Add(__pyx_t_7, __pyx_kp_s__3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_text = ((PyObject*)__pyx_t_10); - __pyx_t_10 = 0; - - /* "pysam/libcalignmentfile.pyx":190 + * if reference_names and reference_lengths: # <<<<<<<<<<<<<< + * reference_names = [force_bytes(ref) for ref in reference_names] * - * text = "\n".join(lines) + "\n" - * if dest.text != NULL: free( dest.text ) # <<<<<<<<<<<<<< - * dest.text = calloc(len(text), sizeof(char)) - * dest.l_text = len(text) */ - __pyx_t_5 = ((__pyx_v_dest->text != NULL) != 0); - if (__pyx_t_5) { - free(__pyx_v_dest->text); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 241, __pyx_L1_error) + if (__pyx_t_2) { + } else { + __pyx_t_3 = __pyx_t_2; + goto __pyx_L6_bool_binop_done; } + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference_lengths); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 241, __pyx_L1_error) + __pyx_t_3 = __pyx_t_2; + __pyx_L6_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":191 - * text = "\n".join(lines) + "\n" - * if dest.text != NULL: free( dest.text ) - * dest.text = calloc(len(text), sizeof(char)) # <<<<<<<<<<<<<< - * dest.l_text = len(text) - * cdef bytes btext = text.encode('ascii') - */ - __pyx_t_3 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 191, __pyx_L1_error) - __pyx_v_dest->text = ((char *)calloc(__pyx_t_3, (sizeof(char)))); - - /* "pysam/libcalignmentfile.pyx":192 - * if dest.text != NULL: free( dest.text ) - * dest.text = calloc(len(text), sizeof(char)) - * dest.l_text = len(text) # <<<<<<<<<<<<<< - * cdef bytes btext = text.encode('ascii') - * strncpy(dest.text, btext, dest.l_text) - */ - __pyx_t_3 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 192, __pyx_L1_error) - __pyx_v_dest->l_text = __pyx_t_3; - - /* "pysam/libcalignmentfile.pyx":193 - * dest.text = calloc(len(text), sizeof(char)) - * dest.l_text = len(text) - * cdef bytes btext = text.encode('ascii') # <<<<<<<<<<<<<< - * strncpy(dest.text, btext, dest.l_text) + /* "pysam/libcalignmentfile.pyx":242 * - */ - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_text, __pyx_n_s_encode); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 193, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 193, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (!(likely(PyBytes_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_7)->tp_name), 0))) __PYX_ERR(0, 193, __pyx_L1_error) - __pyx_v_btext = ((PyObject*)__pyx_t_7); - __pyx_t_7 = 0; - - /* "pysam/libcalignmentfile.pyx":194 - * dest.l_text = len(text) - * cdef bytes btext = text.encode('ascii') - * strncpy(dest.text, btext, dest.l_text) # <<<<<<<<<<<<<< + * if reference_names and reference_lengths: + * reference_names = [force_bytes(ref) for ref in reference_names] # <<<<<<<<<<<<<< * - * cdef bytes bseqname - */ - if (unlikely(__pyx_v_btext == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 194, __pyx_L1_error) - } - __pyx_t_16 = __Pyx_PyBytes_AsString(__pyx_v_btext); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 194, __pyx_L1_error) - (void)(strncpy(__pyx_v_dest->text, __pyx_t_16, __pyx_v_dest->l_text)); - - /* "pysam/libcalignmentfile.pyx":198 - * cdef bytes bseqname - * # collect targets - * if "SQ" in new_header: # <<<<<<<<<<<<<< - * seqs = [] - * for fields in new_header["SQ"]: - */ - __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_SQ, __pyx_v_new_header, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 198, __pyx_L1_error) - __pyx_t_6 = (__pyx_t_5 != 0); - if (__pyx_t_6) { - - /* "pysam/libcalignmentfile.pyx":199 - * # collect targets - * if "SQ" in new_header: - * seqs = [] # <<<<<<<<<<<<<< - * for fields in new_header["SQ"]: - * try: - */ - __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 199, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_v_seqs = ((PyObject*)__pyx_t_7); - __pyx_t_7 = 0; - - /* "pysam/libcalignmentfile.pyx":200 - * if "SQ" in new_header: - * seqs = [] - * for fields in new_header["SQ"]: # <<<<<<<<<<<<<< - * try: - * seqs.append( (fields["SN"], fields["LN"] ) ) + * self.ptr.n_targets = len(reference_names) */ - __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_new_header, __pyx_n_s_SQ); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) { - __pyx_t_10 = __pyx_t_7; __Pyx_INCREF(__pyx_t_10); __pyx_t_3 = 0; - __pyx_t_4 = NULL; + __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 242, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (likely(PyList_CheckExact(__pyx_v_reference_names)) || PyTuple_CheckExact(__pyx_v_reference_names)) { + __pyx_t_9 = __pyx_v_reference_names; __Pyx_INCREF(__pyx_t_9); __pyx_t_5 = 0; + __pyx_t_10 = NULL; } else { - __pyx_t_3 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_4 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 200, __pyx_L1_error) + __pyx_t_5 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_v_reference_names); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 242, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 242, __pyx_L1_error) } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; for (;;) { - if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_10))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_10)) break; + if (likely(!__pyx_t_10)) { + if (likely(PyList_CheckExact(__pyx_t_9))) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_9)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 200, __pyx_L1_error) + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 242, __pyx_L1_error) #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_10, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 242, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); #endif } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_10)) break; + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_9)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 200, __pyx_L1_error) + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 242, __pyx_L1_error) #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_10, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 200, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 242, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); #endif } } else { - __pyx_t_7 = __pyx_t_4(__pyx_t_10); - if (unlikely(!__pyx_t_7)) { + __pyx_t_1 = __pyx_t_10(__pyx_t_9); + if (unlikely(!__pyx_t_1)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 200, __pyx_L1_error) + else __PYX_ERR(0, 242, __pyx_L1_error) } break; } - __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_1); } - __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_7); - __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_ref, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_ref, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 242, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (unlikely(__Pyx_ListComp_Append(__pyx_t_6, (PyObject*)__pyx_t_1))) __PYX_ERR(0, 242, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF_SET(__pyx_v_reference_names, __pyx_t_6); + __pyx_t_6 = 0; - /* "pysam/libcalignmentfile.pyx":201 - * seqs = [] - * for fields in new_header["SQ"]: - * try: # <<<<<<<<<<<<<< - * seqs.append( (fields["SN"], fields["LN"] ) ) - * except KeyError: + /* "pysam/libcalignmentfile.pyx":244 + * reference_names = [force_bytes(ref) for ref in reference_names] + * + * self.ptr.n_targets = len(reference_names) # <<<<<<<<<<<<<< + * + * n = sum([len(reference_names) + 1]) */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19); - __Pyx_XGOTREF(__pyx_t_17); - __Pyx_XGOTREF(__pyx_t_18); - __Pyx_XGOTREF(__pyx_t_19); - /*try:*/ { + __pyx_t_5 = PyObject_Length(__pyx_v_reference_names); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 244, __pyx_L1_error) + __pyx_v_self->ptr->n_targets = __pyx_t_5; - /* "pysam/libcalignmentfile.pyx":202 - * for fields in new_header["SQ"]: - * try: - * seqs.append( (fields["SN"], fields["LN"] ) ) # <<<<<<<<<<<<<< - * except KeyError: - * raise KeyError( "incomplete sequence information in '%s'" % str(fields)) + /* "pysam/libcalignmentfile.pyx":246 + * self.ptr.n_targets = len(reference_names) + * + * n = sum([len(reference_names) + 1]) # <<<<<<<<<<<<<< + * self.ptr.target_name = calloc(n, sizeof(char*)) + * if self.ptr.target_name == NULL: */ - __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_fields, __pyx_n_s_SN); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 202, __pyx_L22_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_fields, __pyx_n_s_LN); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 202, __pyx_L22_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 202, __pyx_L22_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_2); - __pyx_t_7 = 0; - __pyx_t_2 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_seqs, __pyx_t_14); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 202, __pyx_L22_error) - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_5 = PyObject_Length(__pyx_v_reference_names); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 246, __pyx_L1_error) + __pyx_t_6 = PyInt_FromSsize_t((__pyx_t_5 + 1)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 246, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_9 = PyList_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 246, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_6); + PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_sum, __pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 246, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 246, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_n = __pyx_t_11; - /* "pysam/libcalignmentfile.pyx":201 - * seqs = [] - * for fields in new_header["SQ"]: - * try: # <<<<<<<<<<<<<< - * seqs.append( (fields["SN"], fields["LN"] ) ) - * except KeyError: + /* "pysam/libcalignmentfile.pyx":247 + * + * n = sum([len(reference_names) + 1]) + * self.ptr.target_name = calloc(n, sizeof(char*)) # <<<<<<<<<<<<<< + * if self.ptr.target_name == NULL: + * raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *))) */ - } - __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; - __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - goto __pyx_L29_try_end; - __pyx_L22_error:; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_v_self->ptr->target_name = ((char **)calloc(__pyx_v_n, (sizeof(char *)))); - /* "pysam/libcalignmentfile.pyx":203 - * try: - * seqs.append( (fields["SN"], fields["LN"] ) ) - * except KeyError: # <<<<<<<<<<<<<< - * raise KeyError( "incomplete sequence information in '%s'" % str(fields)) + /* "pysam/libcalignmentfile.pyx":248 + * n = sum([len(reference_names) + 1]) + * self.ptr.target_name = calloc(n, sizeof(char*)) + * if self.ptr.target_name == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *))) * */ - __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); - if (__pyx_t_9) { - __Pyx_AddTraceback("pysam.libcalignmentfile.build_header", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_14, &__pyx_t_2, &__pyx_t_7) < 0) __PYX_ERR(0, 203, __pyx_L24_except_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = ((__pyx_v_self->ptr->target_name == NULL) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":204 - * seqs.append( (fields["SN"], fields["LN"] ) ) - * except KeyError: - * raise KeyError( "incomplete sequence information in '%s'" % str(fields)) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":249 + * self.ptr.target_name = calloc(n, sizeof(char*)) + * if self.ptr.target_name == NULL: + * raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *))) # <<<<<<<<<<<<<< * - * dest.n_targets = len(seqs) + * self.ptr.target_len = calloc(n, sizeof(uint32_t)) */ - __pyx_t_8 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_fields); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 204, __pyx_L24_except_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_incomplete_sequence_information, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 204, __pyx_L24_except_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 204, __pyx_L24_except_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 204, __pyx_L24_except_error) + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyInt_FromSize_t((sizeof(char *))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_11 = 1; } - goto __pyx_L24_except_error; - __pyx_L24_except_error:; - - /* "pysam/libcalignmentfile.pyx":201 - * seqs = [] - * for fields in new_header["SQ"]: - * try: # <<<<<<<<<<<<<< - * seqs.append( (fields["SN"], fields["LN"] ) ) - * except KeyError: - */ - __Pyx_XGIVEREF(__pyx_t_17); - __Pyx_XGIVEREF(__pyx_t_18); - __Pyx_XGIVEREF(__pyx_t_19); - __Pyx_ExceptionReset(__pyx_t_17, __pyx_t_18, __pyx_t_19); - goto __pyx_L1_error; - __pyx_L29_try_end:; } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_1, __pyx_t_7}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 249, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_1, __pyx_t_7}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 249, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_t_7); + __pyx_t_1 = 0; + __pyx_t_7 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 249, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 249, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":200 - * if "SQ" in new_header: - * seqs = [] - * for fields in new_header["SQ"]: # <<<<<<<<<<<<<< - * try: - * seqs.append( (fields["SN"], fields["LN"] ) ) - */ - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "pysam/libcalignmentfile.pyx":206 - * raise KeyError( "incomplete sequence information in '%s'" % str(fields)) + /* "pysam/libcalignmentfile.pyx":248 + * n = sum([len(reference_names) + 1]) + * self.ptr.target_name = calloc(n, sizeof(char*)) + * if self.ptr.target_name == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *))) * - * dest.n_targets = len(seqs) # <<<<<<<<<<<<<< - * dest.target_name = calloc(dest.n_targets, sizeof(char*)) - * dest.target_len = calloc(dest.n_targets, sizeof(uint32_t)) */ - __pyx_t_3 = PyList_GET_SIZE(__pyx_v_seqs); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 206, __pyx_L1_error) - __pyx_v_dest->n_targets = __pyx_t_3; + } - /* "pysam/libcalignmentfile.pyx":207 - * - * dest.n_targets = len(seqs) - * dest.target_name = calloc(dest.n_targets, sizeof(char*)) # <<<<<<<<<<<<<< - * dest.target_len = calloc(dest.n_targets, sizeof(uint32_t)) + /* "pysam/libcalignmentfile.pyx":251 + * raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *))) * + * self.ptr.target_len = calloc(n, sizeof(uint32_t)) # <<<<<<<<<<<<<< + * if self.ptr.target_len == NULL: + * raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t))) */ - __pyx_v_dest->target_name = ((char **)calloc(__pyx_v_dest->n_targets, (sizeof(char *)))); + __pyx_v_self->ptr->target_len = ((uint32_t *)calloc(__pyx_v_n, (sizeof(uint32_t)))); - /* "pysam/libcalignmentfile.pyx":208 - * dest.n_targets = len(seqs) - * dest.target_name = calloc(dest.n_targets, sizeof(char*)) - * dest.target_len = calloc(dest.n_targets, sizeof(uint32_t)) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":252 * - * for x from 0 <= x < dest.n_targets: - */ - __pyx_v_dest->target_len = ((uint32_t *)calloc(__pyx_v_dest->n_targets, (sizeof(uint32_t)))); - - /* "pysam/libcalignmentfile.pyx":210 - * dest.target_len = calloc(dest.n_targets, sizeof(uint32_t)) + * self.ptr.target_len = calloc(n, sizeof(uint32_t)) + * if self.ptr.target_len == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t))) * - * for x from 0 <= x < dest.n_targets: # <<<<<<<<<<<<<< - * seqname, seqlen = seqs[x] - * dest.target_name[x] = calloc( */ - __pyx_t_20 = __pyx_v_dest->n_targets; - for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_20; __pyx_v_x++) { + __pyx_t_3 = ((__pyx_v_self->ptr->target_len == NULL) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":211 + /* "pysam/libcalignmentfile.pyx":253 + * self.ptr.target_len = calloc(n, sizeof(uint32_t)) + * if self.ptr.target_len == NULL: + * raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t))) # <<<<<<<<<<<<<< * - * for x from 0 <= x < dest.n_targets: - * seqname, seqlen = seqs[x] # <<<<<<<<<<<<<< - * dest.target_name[x] = calloc( - * len(seqname) + 1, sizeof(char)) + * for x from 0 <= x < self.ptr.n_targets: */ - __pyx_t_10 = __Pyx_GetItemInt_List(__pyx_v_seqs, __pyx_v_x, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - if ((likely(PyTuple_CheckExact(__pyx_t_10))) || (PyList_CheckExact(__pyx_t_10))) { - PyObject* sequence = __pyx_t_10; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 211, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_7 = PyList_GET_ITEM(sequence, 0); - __pyx_t_2 = PyList_GET_ITEM(sequence, 1); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_7 = __Pyx_PyInt_FromSize_t((sizeof(uint32_t))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_11 = 1; } - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_2); - #else - __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_14 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext; - index = 0; __pyx_t_7 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_7)) goto __pyx_L34_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 1; __pyx_t_2 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_2)) goto __pyx_L34_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) __PYX_ERR(0, 211, __pyx_L1_error) - __pyx_t_15 = NULL; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - goto __pyx_L35_unpacking_done; - __pyx_L34_unpacking_failed:; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_15 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 211, __pyx_L1_error) - __pyx_L35_unpacking_done:; } - __Pyx_XDECREF_SET(__pyx_v_seqname, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_seqlen, __pyx_t_2); - __pyx_t_2 = 0; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_12, __pyx_t_7}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 253, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_12, __pyx_t_7}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 253, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_11, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_11, __pyx_t_7); + __pyx_t_12 = 0; + __pyx_t_7 = 0; + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 253, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":252 + * + * self.ptr.target_len = calloc(n, sizeof(uint32_t)) + * if self.ptr.target_len == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t))) + * + */ + } - /* "pysam/libcalignmentfile.pyx":213 - * seqname, seqlen = seqs[x] - * dest.target_name[x] = calloc( - * len(seqname) + 1, sizeof(char)) # <<<<<<<<<<<<<< - * bseqname = seqname.encode('ascii') - * strncpy(dest.target_name[x], bseqname, + /* "pysam/libcalignmentfile.pyx":255 + * raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t))) + * + * for x from 0 <= x < self.ptr.n_targets: # <<<<<<<<<<<<<< + * self.ptr.target_len[x] = reference_lengths[x] + * name = reference_names[x] */ - __pyx_t_3 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 213, __pyx_L1_error) + __pyx_t_13 = __pyx_v_self->ptr->n_targets; + for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_13; __pyx_v_x++) { - /* "pysam/libcalignmentfile.pyx":212 - * for x from 0 <= x < dest.n_targets: - * seqname, seqlen = seqs[x] - * dest.target_name[x] = calloc( # <<<<<<<<<<<<<< - * len(seqname) + 1, sizeof(char)) - * bseqname = seqname.encode('ascii') + /* "pysam/libcalignmentfile.pyx":256 + * + * for x from 0 <= x < self.ptr.n_targets: + * self.ptr.target_len[x] = reference_lengths[x] # <<<<<<<<<<<<<< + * name = reference_names[x] + * self.ptr.target_name[x] = calloc(len(name) + 1, sizeof(char)) */ - (__pyx_v_dest->target_name[__pyx_v_x]) = ((char *)calloc((__pyx_t_3 + 1), (sizeof(char)))); + __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_reference_lengths, __pyx_v_x, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 256, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_14 = __Pyx_PyInt_As_uint32_t(__pyx_t_6); if (unlikely((__pyx_t_14 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 256, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + (__pyx_v_self->ptr->target_len[__pyx_v_x]) = __pyx_t_14; - /* "pysam/libcalignmentfile.pyx":214 - * dest.target_name[x] = calloc( - * len(seqname) + 1, sizeof(char)) - * bseqname = seqname.encode('ascii') # <<<<<<<<<<<<<< - * strncpy(dest.target_name[x], bseqname, - * len(seqname) + 1) + /* "pysam/libcalignmentfile.pyx":257 + * for x from 0 <= x < self.ptr.n_targets: + * self.ptr.target_len[x] = reference_lengths[x] + * name = reference_names[x] # <<<<<<<<<<<<<< + * self.ptr.target_name[x] = calloc(len(name) + 1, sizeof(char)) + * if self.ptr.target_name[x] == NULL: */ - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_seqname, __pyx_n_s_encode); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_XDECREF_SET(__pyx_v_bseqname, ((PyObject*)__pyx_t_2)); - __pyx_t_2 = 0; + __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_reference_names, __pyx_v_x, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_6); + __pyx_t_6 = 0; - /* "pysam/libcalignmentfile.pyx":215 - * len(seqname) + 1, sizeof(char)) - * bseqname = seqname.encode('ascii') - * strncpy(dest.target_name[x], bseqname, # <<<<<<<<<<<<<< - * len(seqname) + 1) - * dest.target_len[x] = seqlen + /* "pysam/libcalignmentfile.pyx":258 + * self.ptr.target_len[x] = reference_lengths[x] + * name = reference_names[x] + * self.ptr.target_name[x] = calloc(len(name) + 1, sizeof(char)) # <<<<<<<<<<<<<< + * if self.ptr.target_name[x] == NULL: + * raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char))) */ - if (unlikely(__pyx_v_bseqname == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 215, __pyx_L1_error) - } - __pyx_t_16 = __Pyx_PyBytes_AsString(__pyx_v_bseqname); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_t_5 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 258, __pyx_L1_error) + (__pyx_v_self->ptr->target_name[__pyx_v_x]) = ((char *)calloc((__pyx_t_5 + 1), (sizeof(char)))); - /* "pysam/libcalignmentfile.pyx":216 - * bseqname = seqname.encode('ascii') - * strncpy(dest.target_name[x], bseqname, - * len(seqname) + 1) # <<<<<<<<<<<<<< - * dest.target_len[x] = seqlen + /* "pysam/libcalignmentfile.pyx":259 + * name = reference_names[x] + * self.ptr.target_name[x] = calloc(len(name) + 1, sizeof(char)) + * if self.ptr.target_name[x] == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char))) + * strncpy(self.ptr.target_name[x], name, len(name)) + */ + __pyx_t_3 = (((__pyx_v_self->ptr->target_name[__pyx_v_x]) == NULL) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcalignmentfile.pyx":260 + * self.ptr.target_name[x] = calloc(len(name) + 1, sizeof(char)) + * if self.ptr.target_name[x] == NULL: + * raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char))) # <<<<<<<<<<<<<< + * strncpy(self.ptr.target_name[x], name, len(name)) * */ - __pyx_t_3 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 216, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_5 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 260, __pyx_L1_error) + __pyx_t_8 = PyInt_FromSsize_t((__pyx_t_5 + 1)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = __Pyx_PyInt_FromSize_t((sizeof(char))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_t_8, __pyx_t_7}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_t_8, __pyx_t_7}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_12) { + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_12); __pyx_t_12 = NULL; + } + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, __pyx_t_7); + __pyx_t_8 = 0; + __pyx_t_7 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 260, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":215 - * len(seqname) + 1, sizeof(char)) - * bseqname = seqname.encode('ascii') - * strncpy(dest.target_name[x], bseqname, # <<<<<<<<<<<<<< - * len(seqname) + 1) - * dest.target_len[x] = seqlen + /* "pysam/libcalignmentfile.pyx":259 + * name = reference_names[x] + * self.ptr.target_name[x] = calloc(len(name) + 1, sizeof(char)) + * if self.ptr.target_name[x] == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char))) + * strncpy(self.ptr.target_name[x], name, len(name)) */ - (void)(strncpy((__pyx_v_dest->target_name[__pyx_v_x]), __pyx_t_16, (__pyx_t_3 + 1))); + } - /* "pysam/libcalignmentfile.pyx":217 - * strncpy(dest.target_name[x], bseqname, - * len(seqname) + 1) - * dest.target_len[x] = seqlen # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":261 + * if self.ptr.target_name[x] == NULL: + * raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char))) + * strncpy(self.ptr.target_name[x], name, len(name)) # <<<<<<<<<<<<<< * - * return dest + * return self */ - __pyx_t_21 = __Pyx_PyInt_As_uint32_t(__pyx_v_seqlen); if (unlikely((__pyx_t_21 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 217, __pyx_L1_error) - (__pyx_v_dest->target_len[__pyx_v_x]) = __pyx_t_21; + __pyx_t_15 = __Pyx_PyObject_AsString(__pyx_v_name); if (unlikely((!__pyx_t_15) && PyErr_Occurred())) __PYX_ERR(0, 261, __pyx_L1_error) + __pyx_t_5 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 261, __pyx_L1_error) + (void)(strncpy((__pyx_v_self->ptr->target_name[__pyx_v_x]), __pyx_t_15, __pyx_t_5)); } - /* "pysam/libcalignmentfile.pyx":198 - * cdef bytes bseqname - * # collect targets - * if "SQ" in new_header: # <<<<<<<<<<<<<< - * seqs = [] - * for fields in new_header["SQ"]: + /* "pysam/libcalignmentfile.pyx":241 + * memcpy(self.ptr.text, ctext, l_text + 1) + * + * if reference_names and reference_lengths: # <<<<<<<<<<<<<< + * reference_names = [force_bytes(ref) for ref in reference_names] + * */ } - /* "pysam/libcalignmentfile.pyx":219 - * dest.target_len[x] = seqlen - * - * return dest # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":263 + * strncpy(self.ptr.target_name[x], name, len(name)) * + * return self # <<<<<<<<<<<<<< * + * @classmethod */ - __pyx_r = __pyx_v_dest; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":150 - * return "\t".join(line) + /* "pysam/libcalignmentfile.pyx":225 * - * cdef bam_hdr_t * build_header(new_header): # <<<<<<<<<<<<<< - * '''return a new header built from a dictionary in `new_header`. + * @classmethod + * def _from_text_and_lengths(cls, text, reference_names, reference_lengths): # <<<<<<<<<<<<<< * + * cdef AlignmentHeader self = AlignmentHeader() */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_14); - __Pyx_WriteUnraisable("pysam.libcalignmentfile.build_header", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader._from_text_and_lengths", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_lines); - __Pyx_XDECREF(__pyx_v_record); - __Pyx_XDECREF(__pyx_v_ttype); - __Pyx_XDECREF(__pyx_v_data); - __Pyx_XDECREF(__pyx_v_fields); - __Pyx_XDECREF(__pyx_v_text); + __Pyx_XDECREF((PyObject *)__pyx_v_self); __Pyx_XDECREF(__pyx_v_btext); - __Pyx_XDECREF(__pyx_v_bseqname); - __Pyx_XDECREF(__pyx_v_seqs); - __Pyx_XDECREF(__pyx_v_seqname); - __Pyx_XDECREF(__pyx_v_seqlen); - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF(__pyx_v_name); + __Pyx_XDECREF(__pyx_v_ref); + __Pyx_XDECREF(__pyx_v_reference_names); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":339 - * """ +/* "pysam/libcalignmentfile.pyx":266 * - * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< - * self.htsfile = NULL - * self.filename = None + * @classmethod + * def from_text(cls, text): # <<<<<<<<<<<<<< + * + * reference_names, reference_lengths = [], [] */ /* Python wrapper */ -static int __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_args = 0; - PyObject *__pyx_v_kwargs = 0; - int __pyx_r; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7from_text(PyObject *__pyx_v_cls, PyObject *__pyx_v_text); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text[] = "AlignmentHeader.from_text(type cls, text)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7from_text(PyObject *__pyx_v_cls, PyObject *__pyx_v_text) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1; - __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1; - __Pyx_GOTREF(__pyx_v_kwargs); - __Pyx_INCREF(__pyx_args); - __pyx_v_args = __pyx_args; - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); + __Pyx_RefNannySetupContext("from_text (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text(((PyTypeObject*)__pyx_v_cls), ((PyObject *)__pyx_v_text)); /* function exit code */ - __Pyx_XDECREF(__pyx_v_args); - __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_text) { + PyObject *__pyx_v_reference_names = NULL; + PyObject *__pyx_v_reference_lengths = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_fields = NULL; + PyObject *__pyx_v_x = NULL; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[0], 339, 0, __PYX_ERR(0, 339, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_args); + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + int __pyx_t_15; + PyObject *__pyx_t_16 = NULL; + __Pyx_RefNannySetupContext("from_text", 0); + __Pyx_TraceCall("from_text", __pyx_f[0], 266, 0, __PYX_ERR(0, 266, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":340 + /* "pysam/libcalignmentfile.pyx":268 + * def from_text(cls, text): * - * def __cinit__(self, *args, **kwargs): - * self.htsfile = NULL # <<<<<<<<<<<<<< - * self.filename = None - * self.mode = None + * reference_names, reference_lengths = [], [] # <<<<<<<<<<<<<< + * for line in text.splitlines(): + * if line.startswith("@SQ"): */ - __pyx_v_self->__pyx_base.htsfile = NULL; + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 268, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_reference_names = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + __pyx_v_reference_lengths = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":341 - * def __cinit__(self, *args, **kwargs): - * self.htsfile = NULL - * self.filename = None # <<<<<<<<<<<<<< - * self.mode = None - * self.is_stream = False + /* "pysam/libcalignmentfile.pyx":269 + * + * reference_names, reference_lengths = [], [] + * for line in text.splitlines(): # <<<<<<<<<<<<<< + * if line.startswith("@SQ"): + * fields = dict([x.split(":", 1) for x in line.split("\t")[1:]]) */ - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename); - __Pyx_DECREF(__pyx_v_self->__pyx_base.filename); - __pyx_v_self->__pyx_base.filename = Py_None; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_text, __pyx_n_s_splitlines); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + if (__pyx_t_3) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 269, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 269, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 269, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 269, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":342 - * self.htsfile = NULL - * self.filename = None - * self.mode = None # <<<<<<<<<<<<<< - * self.is_stream = False - * self.is_remote = False + /* "pysam/libcalignmentfile.pyx":270 + * reference_names, reference_lengths = [], [] + * for line in text.splitlines(): + * if line.startswith("@SQ"): # <<<<<<<<<<<<<< + * fields = dict([x.split(":", 1) for x in line.split("\t")[1:]]) + * try: */ - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->__pyx_base.mode); - __Pyx_DECREF(__pyx_v_self->__pyx_base.mode); - __pyx_v_self->__pyx_base.mode = Py_None; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_startswith); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 270, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 270, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 270, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_6) { - /* "pysam/libcalignmentfile.pyx":343 - * self.filename = None - * self.mode = None - * self.is_stream = False # <<<<<<<<<<<<<< - * self.is_remote = False - * self.index = NULL + /* "pysam/libcalignmentfile.pyx":271 + * for line in text.splitlines(): + * if line.startswith("@SQ"): + * fields = dict([x.split(":", 1) for x in line.split("\t")[1:]]) # <<<<<<<<<<<<<< + * try: + * reference_names.append(fields["SN"]) */ - __pyx_v_self->__pyx_base.is_stream = 0; + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_split); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_t_7, 1, 0, NULL, NULL, &__pyx_slice__7, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_7 = __pyx_t_2; __Pyx_INCREF(__pyx_t_7); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 271, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_9)) { + if (likely(PyList_CheckExact(__pyx_t_7))) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 271, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 271, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_7); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 271, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_n_s_split); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_10))) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_fields, ((PyObject*)__pyx_t_7)); + __pyx_t_7 = 0; - /* "pysam/libcalignmentfile.pyx":344 - * self.mode = None - * self.is_stream = False - * self.is_remote = False # <<<<<<<<<<<<<< - * self.index = NULL - * + /* "pysam/libcalignmentfile.pyx":272 + * if line.startswith("@SQ"): + * fields = dict([x.split(":", 1) for x in line.split("\t")[1:]]) + * try: # <<<<<<<<<<<<<< + * reference_names.append(fields["SN"]) + * reference_lengths.append(int(fields["LN"])) */ - __pyx_v_self->__pyx_base.is_remote = 0; + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_13); + /*try:*/ { - /* "pysam/libcalignmentfile.pyx":345 - * self.is_stream = False - * self.is_remote = False - * self.index = NULL # <<<<<<<<<<<<<< - * - * if "filename" in kwargs: + /* "pysam/libcalignmentfile.pyx":273 + * fields = dict([x.split(":", 1) for x in line.split("\t")[1:]]) + * try: + * reference_names.append(fields["SN"]) # <<<<<<<<<<<<<< + * reference_lengths.append(int(fields["LN"])) + * except KeyError: */ - __pyx_v_self->index = NULL; + __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_fields, __pyx_n_s_SN); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 273, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_reference_names, __pyx_t_7); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 273, __pyx_L8_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcalignmentfile.pyx":347 - * self.index = NULL - * - * if "filename" in kwargs: # <<<<<<<<<<<<<< - * args = [kwargs["filename"]] - * del kwargs["filename"] + /* "pysam/libcalignmentfile.pyx":274 + * try: + * reference_names.append(fields["SN"]) + * reference_lengths.append(int(fields["LN"])) # <<<<<<<<<<<<<< + * except KeyError: + * raise KeyError("incomplete sequence information in '%s'" % str(fields)) */ - __pyx_t_1 = (__Pyx_PyDict_ContainsTF(__pyx_n_s_filename, __pyx_v_kwargs, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 347, __pyx_L1_error) - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_fields, __pyx_n_s_LN); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 274, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 274, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_reference_lengths, __pyx_t_3); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 274, __pyx_L8_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignmentfile.pyx":348 - * - * if "filename" in kwargs: - * args = [kwargs["filename"]] # <<<<<<<<<<<<<< - * del kwargs["filename"] - * + /* "pysam/libcalignmentfile.pyx":272 + * if line.startswith("@SQ"): + * fields = dict([x.split(":", 1) for x in line.split("\t")[1:]]) + * try: # <<<<<<<<<<<<<< + * reference_names.append(fields["SN"]) + * reference_lengths.append(int(fields["LN"])) */ - __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_kwargs, __pyx_n_s_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 348, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 348, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); - PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); - __pyx_t_3 = 0; - __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_4); - __pyx_t_4 = 0; + } + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L15_try_end; + __pyx_L8_error:; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libcalignmentfile.pyx":275 + * reference_names.append(fields["SN"]) + * reference_lengths.append(int(fields["LN"])) + * except KeyError: # <<<<<<<<<<<<<< + * raise KeyError("incomplete sequence information in '%s'" % str(fields)) + * except ValueError: + */ + __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); + if (__pyx_t_15) { + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_7, &__pyx_t_10) < 0) __PYX_ERR(0, 275, __pyx_L10_except_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_10); - /* "pysam/libcalignmentfile.pyx":349 - * if "filename" in kwargs: - * args = [kwargs["filename"]] - * del kwargs["filename"] # <<<<<<<<<<<<<< - * - * self._open(*args, **kwargs) + /* "pysam/libcalignmentfile.pyx":276 + * reference_lengths.append(int(fields["LN"])) + * except KeyError: + * raise KeyError("incomplete sequence information in '%s'" % str(fields)) # <<<<<<<<<<<<<< + * except ValueError: + * raise ValueError("wrong sequence information in '%s'" % str(fields)) */ - if (unlikely(PyDict_DelItem(__pyx_v_kwargs, __pyx_n_s_filename) < 0)) __PYX_ERR(0, 349, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_fields); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 276, __pyx_L10_except_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_16 = __Pyx_PyString_Format(__pyx_kp_s_incomplete_sequence_information, __pyx_t_2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 276, __pyx_L10_except_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 276, __pyx_L10_except_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 276, __pyx_L10_except_error) + } - /* "pysam/libcalignmentfile.pyx":347 - * self.index = NULL + /* "pysam/libcalignmentfile.pyx":277 + * except KeyError: + * raise KeyError("incomplete sequence information in '%s'" % str(fields)) + * except ValueError: # <<<<<<<<<<<<<< + * raise ValueError("wrong sequence information in '%s'" % str(fields)) * - * if "filename" in kwargs: # <<<<<<<<<<<<<< - * args = [kwargs["filename"]] - * del kwargs["filename"] */ - } + __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError); + if (__pyx_t_15) { + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_10, &__pyx_t_7, &__pyx_t_3) < 0) __PYX_ERR(0, 277, __pyx_L10_except_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_3); - /* "pysam/libcalignmentfile.pyx":351 - * del kwargs["filename"] - * - * self._open(*args, **kwargs) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":278 + * raise KeyError("incomplete sequence information in '%s'" % str(fields)) + * except ValueError: + * raise ValueError("wrong sequence information in '%s'" % str(fields)) # <<<<<<<<<<<<<< * - * # allocate memory for iterator + * return cls._from_text_and_lengths(text, reference_names, reference_lengths) */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_v_kwargs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 351, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_fields); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 278, __pyx_L10_except_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_16 = __Pyx_PyString_Format(__pyx_kp_s_wrong_sequence_information_in_s, __pyx_t_2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 278, __pyx_L10_except_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 278, __pyx_L10_except_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 278, __pyx_L10_except_error) + } + goto __pyx_L10_except_error; + __pyx_L10_except_error:; + + /* "pysam/libcalignmentfile.pyx":272 + * if line.startswith("@SQ"): + * fields = dict([x.split(":", 1) for x in line.split("\t")[1:]]) + * try: # <<<<<<<<<<<<<< + * reference_names.append(fields["SN"]) + * reference_lengths.append(int(fields["LN"])) + */ + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); + goto __pyx_L1_error; + __pyx_L15_try_end:; + } - /* "pysam/libcalignmentfile.pyx":354 - * - * # allocate memory for iterator - * self.b = calloc(1, sizeof(bam1_t)) # <<<<<<<<<<<<<< - * - * def has_index(self): + /* "pysam/libcalignmentfile.pyx":270 + * reference_names, reference_lengths = [], [] + * for line in text.splitlines(): + * if line.startswith("@SQ"): # <<<<<<<<<<<<<< + * fields = dict([x.split(":", 1) for x in line.split("\t")[1:]]) + * try: */ - __pyx_v_self->b = ((bam1_t *)calloc(1, (sizeof(bam1_t)))); + } - /* "pysam/libcalignmentfile.pyx":339 - * """ + /* "pysam/libcalignmentfile.pyx":269 * - * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< - * self.htsfile = NULL - * self.filename = None + * reference_names, reference_lengths = [], [] + * for line in text.splitlines(): # <<<<<<<<<<<<<< + * if line.startswith("@SQ"): + * fields = dict([x.split(":", 1) for x in line.split("\t")[1:]]) */ + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_args); - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignmentfile.pyx":356 - * self.b = calloc(1, sizeof(bam1_t)) + /* "pysam/libcalignmentfile.pyx":280 + * raise ValueError("wrong sequence information in '%s'" % str(fields)) * - * def has_index(self): # <<<<<<<<<<<<<< - * """return true if htsfile has an existing (and opened) index. - * """ - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_3has_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_2has_index[] = "AlignmentFile.has_index(self)\nreturn true if htsfile has an existing (and opened) index.\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_3has_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("has_index (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_2has_index(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_2has_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("has_index", 0); - __Pyx_TraceCall("has_index", __pyx_f[0], 356, 0, __PYX_ERR(0, 356, __pyx_L1_error)); - - /* "pysam/libcalignmentfile.pyx":359 - * """return true if htsfile has an existing (and opened) index. - * """ - * return self.index != NULL # <<<<<<<<<<<<<< + * return cls._from_text_and_lengths(text, reference_names, reference_lengths) # <<<<<<<<<<<<<< * - * def check_index(self): + * @classmethod */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->index != NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_from_text_and_lengths); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 280, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = NULL; + __pyx_t_15 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_15 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_15, 3+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 280, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_15, 3+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 280, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_10 = PyTuple_New(3+__pyx_t_15); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 280, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_text); + __Pyx_GIVEREF(__pyx_v_text); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_15, __pyx_v_text); + __Pyx_INCREF(__pyx_v_reference_names); + __Pyx_GIVEREF(__pyx_v_reference_names); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_15, __pyx_v_reference_names); + __Pyx_INCREF(__pyx_v_reference_lengths); + __Pyx_GIVEREF(__pyx_v_reference_lengths); + PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_15, __pyx_v_reference_lengths); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 280, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":356 - * self.b = calloc(1, sizeof(bam1_t)) + /* "pysam/libcalignmentfile.pyx":266 * - * def has_index(self): # <<<<<<<<<<<<<< - * """return true if htsfile has an existing (and opened) index. - * """ + * @classmethod + * def from_text(cls, text): # <<<<<<<<<<<<<< + * + * reference_names, reference_lengths = [], [] */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.has_index", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_16); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_text", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_reference_names); + __Pyx_XDECREF(__pyx_v_reference_lengths); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_fields); + __Pyx_XDECREF(__pyx_v_x); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":361 - * return self.index != NULL +/* "pysam/libcalignmentfile.pyx":283 * - * def check_index(self): # <<<<<<<<<<<<<< - * """return True if index is present. + * @classmethod + * def from_dict(cls, header_dict): # <<<<<<<<<<<<<< * + * cdef list lines = [] */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_5check_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_4check_index[] = "AlignmentFile.check_index(self)\nreturn True if index is present.\n\n Raises\n ------\n\n AttributeError\n if htsfile is :term:`SAM` formatted and thus has no index.\n\n ValueError\n if htsfile is closed or index could not be opened.\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_5check_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_9from_dict(PyObject *__pyx_v_cls, PyObject *__pyx_v_header_dict); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict[] = "AlignmentHeader.from_dict(type cls, header_dict)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_9from_dict(PyObject *__pyx_v_cls, PyObject *__pyx_v_header_dict) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("check_index (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4check_index(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("from_dict (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict(((PyTypeObject*)__pyx_v_cls), ((PyObject *)__pyx_v_header_dict)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4check_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_header_dict) { + PyObject *__pyx_v_lines = 0; + PyObject *__pyx_v_record = NULL; + PyObject *__pyx_v_data = NULL; + PyObject *__pyx_v_fields = NULL; + PyObject *__pyx_v_text = NULL; + PyObject *__pyx_v_reference_names = NULL; + PyObject *__pyx_v_reference_lengths = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("check_index", 0); - __Pyx_TraceCall("check_index", __pyx_f[0], 361, 0, __PYX_ERR(0, 361, __pyx_L1_error)); - - /* "pysam/libcalignmentfile.pyx":374 - * """ - * - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") - * if not self.is_bam and not self.is_cram: - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 374, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 374, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { - - /* "pysam/libcalignmentfile.pyx":375 - * - * if not self.is_open: - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< - * if not self.is_bam and not self.is_cram: - * raise AttributeError( - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 375, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 375, __pyx_L1_error) + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + int __pyx_t_12; + Py_ssize_t __pyx_t_13; + PyObject *(*__pyx_t_14)(PyObject *); + PyObject *(*__pyx_t_15)(PyObject *); + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; + __Pyx_RefNannySetupContext("from_dict", 0); + __Pyx_TraceCall("from_dict", __pyx_f[0], 283, 0, __PYX_ERR(0, 283, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":374 - * """ + /* "pysam/libcalignmentfile.pyx":285 + * def from_dict(cls, header_dict): * - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") - * if not self.is_bam and not self.is_cram: + * cdef list lines = [] # <<<<<<<<<<<<<< + * # first: defined tags + * for record in VALID_HEADERS: */ - } + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_lines = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":376 - * if not self.is_open: - * raise ValueError("I/O operation on closed file") - * if not self.is_bam and not self.is_cram: # <<<<<<<<<<<<<< - * raise AttributeError( - * "AlignmentFile.mapped only available in bam files") + /* "pysam/libcalignmentfile.pyx":287 + * cdef list lines = [] + * # first: defined tags + * for record in VALID_HEADERS: # <<<<<<<<<<<<<< + * if record in header_dict: + * data = header_dict[record] */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 376, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADERS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 287, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 376, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = ((!__pyx_t_2) != 0); - if (__pyx_t_4) { + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; + __pyx_t_4 = NULL; } else { - __pyx_t_3 = __pyx_t_4; - goto __pyx_L5_bool_binop_done; + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 287, __pyx_L1_error) } - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 376, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 376, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_2 = ((!__pyx_t_4) != 0); - __pyx_t_3 = __pyx_t_2; - __pyx_L5_bool_binop_done:; - if (unlikely(__pyx_t_3)) { - - /* "pysam/libcalignmentfile.pyx":377 - * raise ValueError("I/O operation on closed file") - * if not self.is_bam and not self.is_cram: - * raise AttributeError( # <<<<<<<<<<<<<< - * "AlignmentFile.mapped only available in bam files") - * if self.index == NULL: - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_AttributeError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 377, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 377, __pyx_L1_error) - - /* "pysam/libcalignmentfile.pyx":376 - * if not self.is_open: - * raise ValueError("I/O operation on closed file") - * if not self.is_bam and not self.is_cram: # <<<<<<<<<<<<<< - * raise AttributeError( - * "AlignmentFile.mapped only available in bam files") - */ - } + for (;;) { + if (likely(!__pyx_t_4)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 287, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 287, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_4(__pyx_t_2); + if (unlikely(!__pyx_t_1)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 287, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":379 - * raise AttributeError( - * "AlignmentFile.mapped only available in bam files") - * if self.index == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "mapping information not recorded in index " + /* "pysam/libcalignmentfile.pyx":288 + * # first: defined tags + * for record in VALID_HEADERS: + * if record in header_dict: # <<<<<<<<<<<<<< + * data = header_dict[record] + * if not isinstance(data, VALID_HEADER_TYPES[record]): */ - __pyx_t_3 = ((__pyx_v_self->index == NULL) != 0); - if (unlikely(__pyx_t_3)) { + __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_header_dict, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 288, __pyx_L1_error) + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { - /* "pysam/libcalignmentfile.pyx":380 - * "AlignmentFile.mapped only available in bam files") - * if self.index == NULL: - * raise ValueError( # <<<<<<<<<<<<<< - * "mapping information not recorded in index " - * "or index not available") + /* "pysam/libcalignmentfile.pyx":289 + * for record in VALID_HEADERS: + * if record in header_dict: + * data = header_dict[record] # <<<<<<<<<<<<<< + * if not isinstance(data, VALID_HEADER_TYPES[record]): + * raise ValueError( */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 380, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_header_dict, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 289, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF_SET(__pyx_v_data, __pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":379 - * raise AttributeError( - * "AlignmentFile.mapped only available in bam files") - * if self.index == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "mapping information not recorded in index " + /* "pysam/libcalignmentfile.pyx":290 + * if record in header_dict: + * data = header_dict[record] + * if not isinstance(data, VALID_HEADER_TYPES[record]): # <<<<<<<<<<<<<< + * raise ValueError( + * "invalid type for record %s: %s, expected %s".format( */ - } + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 290, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 290, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = PyObject_IsInstance(__pyx_v_data, __pyx_t_7); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 290, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_5 = ((!(__pyx_t_6 != 0)) != 0); + if (unlikely(__pyx_t_5)) { - /* "pysam/libcalignmentfile.pyx":383 - * "mapping information not recorded in index " - * "or index not available") - * return True # <<<<<<<<<<<<<< - * - * def _open(self, + /* "pysam/libcalignmentfile.pyx":292 + * if not isinstance(data, VALID_HEADER_TYPES[record]): + * raise ValueError( + * "invalid type for record %s: %s, expected %s".format( # <<<<<<<<<<<<<< + * record, type(data), VALID_HEADER_TYPES[record])) + * if isinstance(data, collections.Mapping): */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(Py_True); - __pyx_r = Py_True; - goto __pyx_L0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_type_for_record_s_s_expe, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libcalignmentfile.pyx":361 - * return self.index != NULL - * - * def check_index(self): # <<<<<<<<<<<<<< - * """return True if index is present. - * + /* "pysam/libcalignmentfile.pyx":293 + * raise ValueError( + * "invalid type for record %s: %s, expected %s".format( + * record, type(data), VALID_HEADER_TYPES[record])) # <<<<<<<<<<<<<< + * if isinstance(data, collections.Mapping): + * lines.append(build_header_line(data, record)) */ + __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_v_record); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_v_record, ((PyObject *)Py_TYPE(__pyx_v_data)), __pyx_t_9}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 292, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_v_record, ((PyObject *)Py_TYPE(__pyx_v_data)), __pyx_t_9}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 292, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_11 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_v_record); + __Pyx_GIVEREF(__pyx_v_record); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_v_record); + __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_data))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_data))); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, ((PyObject *)Py_TYPE(__pyx_v_data))); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_10, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.check_index", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignmentfile.pyx":385 - * return True - * - * def _open(self, # <<<<<<<<<<<<<< - * filepath_or_object, - * mode=None, + /* "pysam/libcalignmentfile.pyx":291 + * data = header_dict[record] + * if not isinstance(data, VALID_HEADER_TYPES[record]): + * raise ValueError( # <<<<<<<<<<<<<< + * "invalid type for record %s: %s, expected %s".format( + * record, type(data), VALID_HEADER_TYPES[record])) */ + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 291, __pyx_L1_error) -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_6_open[] = "AlignmentFile._open(self, filepath_or_object, mode=None, AlignmentFile template=None, reference_names=None, reference_lengths=None, reference_filename=None, text=None, header=None, port=None, add_sq_text=True, check_header=True, check_sq=True, filepath_index=None, referencenames=None, referencelengths=None, duplicate_filehandle=True)\nopen a sam, bam or cram formatted file.\n\n If _open is called on an existing file, the current file\n will be closed and a new file will be opened.\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_filepath_or_object = 0; - PyObject *__pyx_v_mode = 0; - struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_template = 0; - PyObject *__pyx_v_reference_names = 0; - PyObject *__pyx_v_reference_lengths = 0; - PyObject *__pyx_v_reference_filename = 0; - PyObject *__pyx_v_text = 0; - PyObject *__pyx_v_header = 0; - CYTHON_UNUSED PyObject *__pyx_v_port = 0; - PyObject *__pyx_v_add_sq_text = 0; - PyObject *__pyx_v_check_header = 0; - PyObject *__pyx_v_check_sq = 0; - PyObject *__pyx_v_filepath_index = 0; - PyObject *__pyx_v_referencenames = 0; - PyObject *__pyx_v_referencelengths = 0; - PyObject *__pyx_v_duplicate_filehandle = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_open (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filepath_or_object,&__pyx_n_s_mode,&__pyx_n_s_template,&__pyx_n_s_reference_names,&__pyx_n_s_reference_lengths,&__pyx_n_s_reference_filename,&__pyx_n_s_text,&__pyx_n_s_header,&__pyx_n_s_port,&__pyx_n_s_add_sq_text,&__pyx_n_s_check_header,&__pyx_n_s_check_sq,&__pyx_n_s_filepath_index,&__pyx_n_s_referencenames,&__pyx_n_s_referencelengths,&__pyx_n_s_duplicate_filehandle,0}; - PyObject* values[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - - /* "pysam/libcalignmentfile.pyx":387 - * def _open(self, - * filepath_or_object, - * mode=None, # <<<<<<<<<<<<<< - * AlignmentFile template=None, - * reference_names=None, + /* "pysam/libcalignmentfile.pyx":290 + * if record in header_dict: + * data = header_dict[record] + * if not isinstance(data, VALID_HEADER_TYPES[record]): # <<<<<<<<<<<<<< + * raise ValueError( + * "invalid type for record %s: %s, expected %s".format( */ - values[1] = ((PyObject *)Py_None); + } - /* "pysam/libcalignmentfile.pyx":388 - * filepath_or_object, - * mode=None, - * AlignmentFile template=None, # <<<<<<<<<<<<<< - * reference_names=None, - * reference_lengths=None, + /* "pysam/libcalignmentfile.pyx":294 + * "invalid type for record %s: %s, expected %s".format( + * record, type(data), VALID_HEADER_TYPES[record])) + * if isinstance(data, collections.Mapping): # <<<<<<<<<<<<<< + * lines.append(build_header_line(data, record)) + * else: */ - values[2] = (PyObject *)((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 294, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 294, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = PyObject_IsInstance(__pyx_v_data, __pyx_t_7); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 294, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { - /* "pysam/libcalignmentfile.pyx":389 - * mode=None, - * AlignmentFile template=None, - * reference_names=None, # <<<<<<<<<<<<<< - * reference_lengths=None, - * reference_filename=None, + /* "pysam/libcalignmentfile.pyx":295 + * record, type(data), VALID_HEADER_TYPES[record])) + * if isinstance(data, collections.Mapping): + * lines.append(build_header_line(data, record)) # <<<<<<<<<<<<<< + * else: + * for fields in header_dict[record]: */ - values[3] = ((PyObject *)Py_None); + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_build_header_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 295, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_11 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_data, __pyx_v_record}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 295, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_data, __pyx_v_record}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 295, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 295, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_11); __pyx_t_11 = NULL; + } + __Pyx_INCREF(__pyx_v_data); + __Pyx_GIVEREF(__pyx_v_data); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_10, __pyx_v_data); + __Pyx_INCREF(__pyx_v_record); + __Pyx_GIVEREF(__pyx_v_record); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_10, __pyx_v_record); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 295, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_7); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 295, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcalignmentfile.pyx":390 - * AlignmentFile template=None, - * reference_names=None, - * reference_lengths=None, # <<<<<<<<<<<<<< - * reference_filename=None, - * text=None, + /* "pysam/libcalignmentfile.pyx":294 + * "invalid type for record %s: %s, expected %s".format( + * record, type(data), VALID_HEADER_TYPES[record])) + * if isinstance(data, collections.Mapping): # <<<<<<<<<<<<<< + * lines.append(build_header_line(data, record)) + * else: */ - values[4] = ((PyObject *)Py_None); + goto __pyx_L7; + } - /* "pysam/libcalignmentfile.pyx":391 - * reference_names=None, - * reference_lengths=None, - * reference_filename=None, # <<<<<<<<<<<<<< - * text=None, - * header=None, + /* "pysam/libcalignmentfile.pyx":297 + * lines.append(build_header_line(data, record)) + * else: + * for fields in header_dict[record]: # <<<<<<<<<<<<<< + * lines.append(build_header_line(fields, record)) + * */ - values[5] = ((PyObject *)Py_None); + /*else*/ { + __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_header_dict, __pyx_v_record); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 297, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) { + __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __pyx_t_13 = 0; + __pyx_t_14 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 297, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 297, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + for (;;) { + if (likely(!__pyx_t_14)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_13); __Pyx_INCREF(__pyx_t_7); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 297, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 297, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } else { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_13); __Pyx_INCREF(__pyx_t_7); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 297, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 297, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } + } else { + __pyx_t_7 = __pyx_t_14(__pyx_t_1); + if (unlikely(!__pyx_t_7)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 297, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_7); + __pyx_t_7 = 0; - /* "pysam/libcalignmentfile.pyx":392 - * reference_lengths=None, - * reference_filename=None, - * text=None, # <<<<<<<<<<<<<< - * header=None, - * port=None, + /* "pysam/libcalignmentfile.pyx":298 + * else: + * for fields in header_dict[record]: + * lines.append(build_header_line(fields, record)) # <<<<<<<<<<<<<< + * + * # then: user tags (lower case), sorted alphabetically */ - values[6] = ((PyObject *)Py_None); + __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_build_header_line); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 298, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_fields, __pyx_v_record}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 298, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_fields, __pyx_v_record}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 298, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 298, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_11); __pyx_t_11 = NULL; + } + __Pyx_INCREF(__pyx_v_fields); + __Pyx_GIVEREF(__pyx_v_fields); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_10, __pyx_v_fields); + __Pyx_INCREF(__pyx_v_record); + __Pyx_GIVEREF(__pyx_v_record); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_10, __pyx_v_record); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 298, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_7); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 298, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcalignmentfile.pyx":393 - * reference_filename=None, - * text=None, - * header=None, # <<<<<<<<<<<<<< - * port=None, - * add_sq_text=True, + /* "pysam/libcalignmentfile.pyx":297 + * lines.append(build_header_line(data, record)) + * else: + * for fields in header_dict[record]: # <<<<<<<<<<<<<< + * lines.append(build_header_line(fields, record)) + * */ - values[7] = ((PyObject *)Py_None); + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __pyx_L7:; - /* "pysam/libcalignmentfile.pyx":394 - * text=None, - * header=None, - * port=None, # <<<<<<<<<<<<<< - * add_sq_text=True, - * check_header=True, + /* "pysam/libcalignmentfile.pyx":288 + * # first: defined tags + * for record in VALID_HEADERS: + * if record in header_dict: # <<<<<<<<<<<<<< + * data = header_dict[record] + * if not isinstance(data, VALID_HEADER_TYPES[record]): */ - values[8] = ((PyObject *)Py_None); + } - /* "pysam/libcalignmentfile.pyx":395 - * header=None, - * port=None, - * add_sq_text=True, # <<<<<<<<<<<<<< - * check_header=True, - * check_sq=True, + /* "pysam/libcalignmentfile.pyx":287 + * cdef list lines = [] + * # first: defined tags + * for record in VALID_HEADERS: # <<<<<<<<<<<<<< + * if record in header_dict: + * data = header_dict[record] */ - values[9] = ((PyObject *)Py_True); + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":396 - * port=None, - * add_sq_text=True, - * check_header=True, # <<<<<<<<<<<<<< - * check_sq=True, - * filepath_index=None, + /* "pysam/libcalignmentfile.pyx":301 + * + * # then: user tags (lower case), sorted alphabetically + * for record, data in sorted(header_dict.items()): # <<<<<<<<<<<<<< + * if record in VALID_HEADERS: + * continue */ - values[10] = ((PyObject *)Py_True); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_header_dict, __pyx_n_s_items); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 301, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (__pyx_t_9) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 301, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 301, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 301, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_12 = PyList_Sort(__pyx_t_2); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 301, __pyx_L1_error) + if (unlikely(__pyx_t_2 == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); + __PYX_ERR(0, 301, __pyx_L1_error) + } + __pyx_t_7 = __pyx_t_2; __Pyx_INCREF(__pyx_t_7); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 301, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 301, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 301, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_9 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_9); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 301, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 301, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 301, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_15 = Py_TYPE(__pyx_t_8)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_15(__pyx_t_8); if (unlikely(!__pyx_t_1)) goto __pyx_L12_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_9 = __pyx_t_15(__pyx_t_8); if (unlikely(!__pyx_t_9)) goto __pyx_L12_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_8), 2) < 0) __PYX_ERR(0, 301, __pyx_L1_error) + __pyx_t_15 = NULL; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L13_unpacking_done; + __pyx_L12_unpacking_failed:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_15 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 301, __pyx_L1_error) + __pyx_L13_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_1); + __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_data, __pyx_t_9); + __pyx_t_9 = 0; - /* "pysam/libcalignmentfile.pyx":397 - * add_sq_text=True, - * check_header=True, - * check_sq=True, # <<<<<<<<<<<<<< - * filepath_index=None, - * referencenames=None, + /* "pysam/libcalignmentfile.pyx":302 + * # then: user tags (lower case), sorted alphabetically + * for record, data in sorted(header_dict.items()): + * if record in VALID_HEADERS: # <<<<<<<<<<<<<< + * continue + * if isinstance(data, collections.Mapping): */ - values[11] = ((PyObject *)Py_True); + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADERS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 302, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 302, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_5 = (__pyx_t_6 != 0); + if (__pyx_t_5) { - /* "pysam/libcalignmentfile.pyx":398 - * check_header=True, - * check_sq=True, - * filepath_index=None, # <<<<<<<<<<<<<< - * referencenames=None, - * referencelengths=None, + /* "pysam/libcalignmentfile.pyx":303 + * for record, data in sorted(header_dict.items()): + * if record in VALID_HEADERS: + * continue # <<<<<<<<<<<<<< + * if isinstance(data, collections.Mapping): + * lines.append(build_header_line(data, record)) */ - values[12] = ((PyObject *)Py_None); + goto __pyx_L10_continue; - /* "pysam/libcalignmentfile.pyx":399 - * check_sq=True, - * filepath_index=None, - * referencenames=None, # <<<<<<<<<<<<<< - * referencelengths=None, - * duplicate_filehandle=True): + /* "pysam/libcalignmentfile.pyx":302 + * # then: user tags (lower case), sorted alphabetically + * for record, data in sorted(header_dict.items()): + * if record in VALID_HEADERS: # <<<<<<<<<<<<<< + * continue + * if isinstance(data, collections.Mapping): */ - values[13] = ((PyObject *)Py_None); + } - /* "pysam/libcalignmentfile.pyx":400 - * filepath_index=None, - * referencenames=None, - * referencelengths=None, # <<<<<<<<<<<<<< - * duplicate_filehandle=True): - * '''open a sam, bam or cram formatted file. + /* "pysam/libcalignmentfile.pyx":304 + * if record in VALID_HEADERS: + * continue + * if isinstance(data, collections.Mapping): # <<<<<<<<<<<<<< + * lines.append(build_header_line(data, record)) + * else: */ - values[14] = ((PyObject *)Py_None); + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_5 = PyObject_IsInstance(__pyx_v_data, __pyx_t_9); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { - /* "pysam/libcalignmentfile.pyx":401 - * referencenames=None, - * referencelengths=None, - * duplicate_filehandle=True): # <<<<<<<<<<<<<< - * '''open a sam, bam or cram formatted file. - * + /* "pysam/libcalignmentfile.pyx":305 + * continue + * if isinstance(data, collections.Mapping): + * lines.append(build_header_line(data, record)) # <<<<<<<<<<<<<< + * else: + * for fields in header_dict[record]: */ - values[15] = ((PyObject *)Py_True); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); - CYTHON_FALLTHROUGH; - case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); - CYTHON_FALLTHROUGH; - case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); - CYTHON_FALLTHROUGH; - case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); - CYTHON_FALLTHROUGH; - case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); - CYTHON_FALLTHROUGH; - case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - CYTHON_FALLTHROUGH; - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - CYTHON_FALLTHROUGH; - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filepath_or_object)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode); - if (value) { values[1] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_template); - if (value) { values[2] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_names); - if (value) { values[3] = value; kw_args--; } + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_build_header_line); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 305, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_10 = 1; } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_lengths); - if (value) { values[4] = value; kw_args--; } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_data, __pyx_v_record}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 305, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_data, __pyx_v_record}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 305, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 305, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); __pyx_t_1 = NULL; } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_filename); - if (value) { values[5] = value; kw_args--; } + __Pyx_INCREF(__pyx_v_data); + __Pyx_GIVEREF(__pyx_v_data); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_10, __pyx_v_data); + __Pyx_INCREF(__pyx_v_record); + __Pyx_GIVEREF(__pyx_v_record); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_10, __pyx_v_record); + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 305, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_9); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 305, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pysam/libcalignmentfile.pyx":304 + * if record in VALID_HEADERS: + * continue + * if isinstance(data, collections.Mapping): # <<<<<<<<<<<<<< + * lines.append(build_header_line(data, record)) + * else: + */ + goto __pyx_L15; + } + + /* "pysam/libcalignmentfile.pyx":307 + * lines.append(build_header_line(data, record)) + * else: + * for fields in header_dict[record]: # <<<<<<<<<<<<<< + * lines.append(build_header_line(fields, record)) + * + */ + /*else*/ { + __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_v_header_dict, __pyx_v_record); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (likely(PyList_CheckExact(__pyx_t_9)) || PyTuple_CheckExact(__pyx_t_9)) { + __pyx_t_2 = __pyx_t_9; __Pyx_INCREF(__pyx_t_2); __pyx_t_13 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 307, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + for (;;) { + if (likely(!__pyx_t_4)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_9 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_13); __Pyx_INCREF(__pyx_t_9); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 307, __pyx_L1_error) + #else + __pyx_t_9 = PySequence_ITEM(__pyx_t_2, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + } else { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_13); __Pyx_INCREF(__pyx_t_9); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 307, __pyx_L1_error) + #else + __pyx_t_9 = PySequence_ITEM(__pyx_t_2, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + } + } else { + __pyx_t_9 = __pyx_t_4(__pyx_t_2); + if (unlikely(!__pyx_t_9)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 307, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_9); } - CYTHON_FALLTHROUGH; - case 6: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_text); - if (value) { values[6] = value; kw_args--; } + __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_9); + __pyx_t_9 = 0; + + /* "pysam/libcalignmentfile.pyx":308 + * else: + * for fields in header_dict[record]: + * lines.append(build_header_line(fields, record)) # <<<<<<<<<<<<<< + * + * text = "\n".join(lines) + "\n" + */ + __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_build_header_line); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 308, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_10 = 1; + } } - CYTHON_FALLTHROUGH; - case 7: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_header); - if (value) { values[7] = value; kw_args--; } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_fields, __pyx_v_record}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 308, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_fields, __pyx_v_record}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 308, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + { + __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 308, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_v_fields); + __Pyx_GIVEREF(__pyx_v_fields); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_v_fields); + __Pyx_INCREF(__pyx_v_record); + __Pyx_GIVEREF(__pyx_v_record); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_v_record); + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 308, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } - CYTHON_FALLTHROUGH; - case 8: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_port); - if (value) { values[8] = value; kw_args--; } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_9); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 308, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pysam/libcalignmentfile.pyx":307 + * lines.append(build_header_line(data, record)) + * else: + * for fields in header_dict[record]: # <<<<<<<<<<<<<< + * lines.append(build_header_line(fields, record)) + * + */ + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_L15:; + + /* "pysam/libcalignmentfile.pyx":301 + * + * # then: user tags (lower case), sorted alphabetically + * for record, data in sorted(header_dict.items()): # <<<<<<<<<<<<<< + * if record in VALID_HEADERS: + * continue + */ + __pyx_L10_continue:; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pysam/libcalignmentfile.pyx":310 + * lines.append(build_header_line(fields, record)) + * + * text = "\n".join(lines) + "\n" # <<<<<<<<<<<<<< + * + * reference_names, reference_lengths = [], [] + */ + __pyx_t_7 = __Pyx_PyString_Join(__pyx_kp_s__10, __pyx_v_lines); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 310, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = PyNumber_Add(__pyx_t_7, __pyx_kp_s__10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 310, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_text = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; + + /* "pysam/libcalignmentfile.pyx":312 + * text = "\n".join(lines) + "\n" + * + * reference_names, reference_lengths = [], [] # <<<<<<<<<<<<<< + * if "SQ" in header_dict: + * for fields in header_dict["SQ"]: + */ + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 312, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 312, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_v_reference_names = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; + __pyx_v_reference_lengths = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; + + /* "pysam/libcalignmentfile.pyx":313 + * + * reference_names, reference_lengths = [], [] + * if "SQ" in header_dict: # <<<<<<<<<<<<<< + * for fields in header_dict["SQ"]: + * try: + */ + __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_SQ_2, __pyx_v_header_dict, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 313, __pyx_L1_error) + __pyx_t_5 = (__pyx_t_6 != 0); + if (__pyx_t_5) { + + /* "pysam/libcalignmentfile.pyx":314 + * reference_names, reference_lengths = [], [] + * if "SQ" in header_dict: + * for fields in header_dict["SQ"]: # <<<<<<<<<<<<<< + * try: + * reference_names.append(fields["SN"]) + */ + __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_header_dict, __pyx_n_s_SQ_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) { + __pyx_t_2 = __pyx_t_7; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 314, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + for (;;) { + if (likely(!__pyx_t_4)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 314, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } else { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 314, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif } - CYTHON_FALLTHROUGH; - case 9: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_add_sq_text); - if (value) { values[9] = value; kw_args--; } + } else { + __pyx_t_7 = __pyx_t_4(__pyx_t_2); + if (unlikely(!__pyx_t_7)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 314, __pyx_L1_error) + } + break; } - CYTHON_FALLTHROUGH; - case 10: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_check_header); - if (value) { values[10] = value; kw_args--; } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pysam/libcalignmentfile.pyx":315 + * if "SQ" in header_dict: + * for fields in header_dict["SQ"]: + * try: # <<<<<<<<<<<<<< + * reference_names.append(fields["SN"]) + * reference_lengths.append(fields["LN"]) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_18); + /*try:*/ { + + /* "pysam/libcalignmentfile.pyx":316 + * for fields in header_dict["SQ"]: + * try: + * reference_names.append(fields["SN"]) # <<<<<<<<<<<<<< + * reference_lengths.append(fields["LN"]) + * except KeyError: + */ + __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_fields, __pyx_n_s_SN); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 316, __pyx_L21_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_reference_names, __pyx_t_7); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 316, __pyx_L21_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pysam/libcalignmentfile.pyx":317 + * try: + * reference_names.append(fields["SN"]) + * reference_lengths.append(fields["LN"]) # <<<<<<<<<<<<<< + * except KeyError: + * raise KeyError("incomplete sequence information in '%s'" % str(fields)) + */ + __pyx_t_7 = __Pyx_PyObject_Dict_GetItem(__pyx_v_fields, __pyx_n_s_LN); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 317, __pyx_L21_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_reference_lengths, __pyx_t_7); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 317, __pyx_L21_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pysam/libcalignmentfile.pyx":315 + * if "SQ" in header_dict: + * for fields in header_dict["SQ"]: + * try: # <<<<<<<<<<<<<< + * reference_names.append(fields["SN"]) + * reference_lengths.append(fields["LN"]) + */ } - CYTHON_FALLTHROUGH; - case 11: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_check_sq); - if (value) { values[11] = value; kw_args--; } + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + goto __pyx_L28_try_end; + __pyx_L21_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pysam/libcalignmentfile.pyx":318 + * reference_names.append(fields["SN"]) + * reference_lengths.append(fields["LN"]) + * except KeyError: # <<<<<<<<<<<<<< + * raise KeyError("incomplete sequence information in '%s'" % str(fields)) + * + */ + __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); + if (__pyx_t_10) { + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_dict", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_9, &__pyx_t_8) < 0) __PYX_ERR(0, 318, __pyx_L23_except_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GOTREF(__pyx_t_8); + + /* "pysam/libcalignmentfile.pyx":319 + * reference_lengths.append(fields["LN"]) + * except KeyError: + * raise KeyError("incomplete sequence information in '%s'" % str(fields)) # <<<<<<<<<<<<<< + * + * return cls._from_text_and_lengths(text, reference_names, reference_lengths) + */ + __pyx_t_11 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_fields); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 319, __pyx_L23_except_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_incomplete_sequence_information, __pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 319, __pyx_L23_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 319, __pyx_L23_except_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_11, 0, 0, 0); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __PYX_ERR(0, 319, __pyx_L23_except_error) } + goto __pyx_L23_except_error; + __pyx_L23_except_error:; + + /* "pysam/libcalignmentfile.pyx":315 + * if "SQ" in header_dict: + * for fields in header_dict["SQ"]: + * try: # <<<<<<<<<<<<<< + * reference_names.append(fields["SN"]) + * reference_lengths.append(fields["LN"]) + */ + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18); + goto __pyx_L1_error; + __pyx_L28_try_end:; + } + + /* "pysam/libcalignmentfile.pyx":314 + * reference_names, reference_lengths = [], [] + * if "SQ" in header_dict: + * for fields in header_dict["SQ"]: # <<<<<<<<<<<<<< + * try: + * reference_names.append(fields["SN"]) + */ + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libcalignmentfile.pyx":313 + * + * reference_names, reference_lengths = [], [] + * if "SQ" in header_dict: # <<<<<<<<<<<<<< + * for fields in header_dict["SQ"]: + * try: + */ + } + + /* "pysam/libcalignmentfile.pyx":321 + * raise KeyError("incomplete sequence information in '%s'" % str(fields)) + * + * return cls._from_text_and_lengths(text, reference_names, reference_lengths) # <<<<<<<<<<<<<< + * + * @classmethod + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_from_text_and_lengths); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_7 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_INCREF(__pyx_v_text); + __Pyx_GIVEREF(__pyx_v_text); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_10, __pyx_v_text); + __Pyx_INCREF(__pyx_v_reference_names); + __Pyx_GIVEREF(__pyx_v_reference_names); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_10, __pyx_v_reference_names); + __Pyx_INCREF(__pyx_v_reference_lengths); + __Pyx_GIVEREF(__pyx_v_reference_lengths); + PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_10, __pyx_v_reference_lengths); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":283 + * + * @classmethod + * def from_dict(cls, header_dict): # <<<<<<<<<<<<<< + * + * cdef list lines = [] + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_dict", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_lines); + __Pyx_XDECREF(__pyx_v_record); + __Pyx_XDECREF(__pyx_v_data); + __Pyx_XDECREF(__pyx_v_fields); + __Pyx_XDECREF(__pyx_v_text); + __Pyx_XDECREF(__pyx_v_reference_names); + __Pyx_XDECREF(__pyx_v_reference_lengths); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":324 + * + * @classmethod + * def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True): # <<<<<<<<<<<<<< + * + * if len(reference_names) != len(reference_lengths): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11from_references(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references[] = "AlignmentHeader.from_references(type cls, reference_names, reference_lengths, text=None, add_sq_text=True)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11from_references(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_reference_names = 0; + PyObject *__pyx_v_reference_lengths = 0; + PyObject *__pyx_v_text = 0; + PyObject *__pyx_v_add_sq_text = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("from_references (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference_names,&__pyx_n_s_reference_lengths,&__pyx_n_s_text,&__pyx_n_s_add_sq_text,0}; + PyObject* values[4] = {0,0,0,0}; + values[2] = ((PyObject *)Py_None); + values[3] = ((PyObject *)Py_True); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; - case 12: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filepath_index); - if (value) { values[12] = value; kw_args--; } - } + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; - case 13: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_referencenames); - if (value) { values[13] = value; kw_args--; } + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_names)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_lengths)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("from_references", 0, 2, 4, 1); __PYX_ERR(0, 324, __pyx_L3_error) } CYTHON_FALLTHROUGH; - case 14: + case 2: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_referencelengths); - if (value) { values[14] = value; kw_args--; } + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_text); + if (value) { values[2] = value; kw_args--; } } CYTHON_FALLTHROUGH; - case 15: + case 3: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_duplicate_filehandle); - if (value) { values[15] = value; kw_args--; } + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_add_sq_text); + if (value) { values[3] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) __PYX_ERR(0, 385, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "from_references") < 0)) __PYX_ERR(0, 324, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { - case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); - CYTHON_FALLTHROUGH; - case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); - CYTHON_FALLTHROUGH; - case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); - CYTHON_FALLTHROUGH; - case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); - CYTHON_FALLTHROUGH; - case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); - CYTHON_FALLTHROUGH; - case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - CYTHON_FALLTHROUGH; - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - CYTHON_FALLTHROUGH; - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - CYTHON_FALLTHROUGH; - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - CYTHON_FALLTHROUGH; - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } - __pyx_v_filepath_or_object = values[0]; - __pyx_v_mode = values[1]; - __pyx_v_template = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[2]); - __pyx_v_reference_names = values[3]; - __pyx_v_reference_lengths = values[4]; - __pyx_v_reference_filename = values[5]; - __pyx_v_text = values[6]; - __pyx_v_header = values[7]; - __pyx_v_port = values[8]; - __pyx_v_add_sq_text = values[9]; - __pyx_v_check_header = values[10]; - __pyx_v_check_sq = values[11]; - __pyx_v_filepath_index = values[12]; - __pyx_v_referencenames = values[13]; - __pyx_v_referencelengths = values[14]; - __pyx_v_duplicate_filehandle = values[15]; + __pyx_v_reference_names = values[0]; + __pyx_v_reference_lengths = values[1]; + __pyx_v_text = values[2]; + __pyx_v_add_sq_text = values[3]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("from_references", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 324, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_references", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references(((PyTypeObject*)__pyx_v_cls), __pyx_v_reference_names, __pyx_v_reference_lengths, __pyx_v_text, __pyx_v_add_sq_text); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_text, PyObject *__pyx_v_add_sq_text) { + PyObject *__pyx_v_x = NULL; + PyObject *__pyx_v_y = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *(*__pyx_t_13)(PyObject *); + int __pyx_t_14; + __Pyx_RefNannySetupContext("from_references", 0); + __Pyx_TraceCall("from_references", __pyx_f[0], 324, 0, __PYX_ERR(0, 324, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_text); + + /* "pysam/libcalignmentfile.pyx":326 + * def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True): + * + * if len(reference_names) != len(reference_lengths): # <<<<<<<<<<<<<< + * raise ValueError("number of reference names and lengths do not match") + * + */ + __pyx_t_1 = PyObject_Length(__pyx_v_reference_names); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 326, __pyx_L1_error) + __pyx_t_2 = PyObject_Length(__pyx_v_reference_lengths); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 326, __pyx_L1_error) + __pyx_t_3 = ((__pyx_t_1 != __pyx_t_2) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcalignmentfile.pyx":327 + * + * if len(reference_names) != len(reference_lengths): + * raise ValueError("number of reference names and lengths do not match") # <<<<<<<<<<<<<< + * + * # optionally, if there is no text, add a SAM compatible header to output file. + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 327, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 327, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":326 + * def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True): + * + * if len(reference_names) != len(reference_lengths): # <<<<<<<<<<<<<< + * raise ValueError("number of reference names and lengths do not match") + * + */ + } + + /* "pysam/libcalignmentfile.pyx":330 + * + * # optionally, if there is no text, add a SAM compatible header to output file. + * if text is None and add_sq_text: # <<<<<<<<<<<<<< + * text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip( + * reference_names, reference_lengths)]) + */ + __pyx_t_5 = (__pyx_v_text == Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + } else { + __pyx_t_3 = __pyx_t_6; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_add_sq_text); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 330, __pyx_L1_error) + __pyx_t_3 = __pyx_t_6; + __pyx_L5_bool_binop_done:; + if (__pyx_t_3) { + + /* "pysam/libcalignmentfile.pyx":331 + * # optionally, if there is no text, add a SAM compatible header to output file. + * if text is None and add_sq_text: + * text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip( # <<<<<<<<<<<<<< + * reference_names, reference_lengths)]) + * + */ + __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pysam/libcalignmentfile.pyx":332 + * if text is None and add_sq_text: + * text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip( + * reference_names, reference_lengths)]) # <<<<<<<<<<<<<< + * + * return cls._from_text_and_lengths(text, reference_names, reference_lengths) + */ + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_v_reference_names); + __Pyx_GIVEREF(__pyx_v_reference_names); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_reference_names); + __Pyx_INCREF(__pyx_v_reference_lengths); + __Pyx_GIVEREF(__pyx_v_reference_lengths); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_reference_lengths); + + /* "pysam/libcalignmentfile.pyx":331 + * # optionally, if there is no text, add a SAM compatible header to output file. + * if text is None and add_sq_text: + * text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip( # <<<<<<<<<<<<<< + * reference_names, reference_lengths)]) + * + */ + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) { + __pyx_t_7 = __pyx_t_8; __Pyx_INCREF(__pyx_t_7); __pyx_t_2 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 331, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + for (;;) { + if (likely(!__pyx_t_9)) { + if (likely(PyList_CheckExact(__pyx_t_7))) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_8 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_2); __Pyx_INCREF(__pyx_t_8); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 331, __pyx_L1_error) + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + } else { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_2); __Pyx_INCREF(__pyx_t_8); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 331, __pyx_L1_error) + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + } + } else { + __pyx_t_8 = __pyx_t_9(__pyx_t_7); + if (unlikely(!__pyx_t_8)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 331, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_8); + } + if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) { + PyObject* sequence = __pyx_t_8; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 331, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_10 = PyList_GET_ITEM(sequence, 0); + __pyx_t_11 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_11); + #else + __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + #endif + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_12 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext; + index = 0; __pyx_t_10 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_10)) goto __pyx_L9_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + index = 1; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L9_unpacking_failed; + __Pyx_GOTREF(__pyx_t_11); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) __PYX_ERR(0, 331, __pyx_L1_error) + __pyx_t_13 = NULL; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L10_unpacking_done; + __pyx_L9_unpacking_failed:; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_13 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 331, __pyx_L1_error) + __pyx_L10_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_10); + __pyx_t_10 = 0; + __Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_11); + __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_SQ_SN_LN, __pyx_n_s_format); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_10 = NULL; + __pyx_t_14 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_14 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_x, __pyx_v_y}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_x, __pyx_v_y}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + { + __pyx_t_12 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_10) { + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL; + } + __Pyx_INCREF(__pyx_v_x); + __Pyx_GIVEREF(__pyx_v_x); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_14, __pyx_v_x); + __Pyx_INCREF(__pyx_v_y); + __Pyx_GIVEREF(__pyx_v_y); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_14, __pyx_v_y); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_8))) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyString_Join(__pyx_kp_s__12, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pysam/libcalignmentfile.pyx":330 + * + * # optionally, if there is no text, add a SAM compatible header to output file. + * if text is None and add_sq_text: # <<<<<<<<<<<<<< + * text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip( + * reference_names, reference_lengths)]) + */ + } + + /* "pysam/libcalignmentfile.pyx":334 + * reference_names, reference_lengths)]) + * + * return cls._from_text_and_lengths(text, reference_names, reference_lengths) # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_from_text_and_lengths); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 334, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = NULL; + __pyx_t_14 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_14 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 334, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_14, 3+__pyx_t_14); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 334, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + { + __pyx_t_11 = PyTuple_New(3+__pyx_t_14); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 334, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_v_text); + __Pyx_GIVEREF(__pyx_v_text); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_14, __pyx_v_text); + __Pyx_INCREF(__pyx_v_reference_names); + __Pyx_GIVEREF(__pyx_v_reference_names); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_14, __pyx_v_reference_names); + __Pyx_INCREF(__pyx_v_reference_lengths); + __Pyx_GIVEREF(__pyx_v_reference_lengths); + PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_14, __pyx_v_reference_lengths); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 334, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":324 + * + * @classmethod + * def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True): # <<<<<<<<<<<<<< + * + * if len(reference_names) != len(reference_lengths): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_references", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_x); + __Pyx_XDECREF(__pyx_v_y); + __Pyx_XDECREF(__pyx_v_text); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":336 + * return cls._from_text_and_lengths(text, reference_names, reference_lengths) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * bam_hdr_destroy(self.ptr) + * self.ptr = NULL + */ + +/* Python wrapper */ +static void __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_13__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_13__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_12__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +static void __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_12__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 336, 0, __PYX_ERR(0, 336, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":337 + * + * def __dealloc__(self): + * bam_hdr_destroy(self.ptr) # <<<<<<<<<<<<<< + * self.ptr = NULL + * + */ + bam_hdr_destroy(__pyx_v_self->ptr); + + /* "pysam/libcalignmentfile.pyx":338 + * def __dealloc__(self): + * bam_hdr_destroy(self.ptr) + * self.ptr = NULL # <<<<<<<<<<<<<< + * + * def __bool__(self): + */ + __pyx_v_self->ptr = NULL; + + /* "pysam/libcalignmentfile.pyx":336 + * return cls._from_text_and_lengths(text, reference_names, reference_lengths) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * bam_hdr_destroy(self.ptr) + * self.ptr = NULL + */ + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("pysam.libcalignmentfile.AlignmentHeader.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); +} + +/* "pysam/libcalignmentfile.pyx":340 + * self.ptr = NULL + * + * def __bool__(self): # <<<<<<<<<<<<<< + * return self.ptr != NULL + * + */ + +/* Python wrapper */ +static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_15__bool__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_15__bool__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__bool__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_14__bool__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_14__bool__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__bool__", 0); + __Pyx_TraceCall("__bool__", __pyx_f[0], 340, 0, __PYX_ERR(0, 340, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":341 + * + * def __bool__(self): + * return self.ptr != NULL # <<<<<<<<<<<<<< + * + * def copy(self): + */ + __pyx_r = (__pyx_v_self->ptr != NULL); + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":340 + * self.ptr = NULL + * + * def __bool__(self): # <<<<<<<<<<<<<< + * return self.ptr != NULL + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":343 + * return self.ptr != NULL + * + * def copy(self): # <<<<<<<<<<<<<< + * return makeAlignmentHeader(bam_hdr_dup(self.ptr)) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_17copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_16copy[] = "AlignmentHeader.copy(self)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_17copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("copy (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_16copy(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_16copy(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("copy", 0); + __Pyx_TraceCall("copy", __pyx_f[0], 343, 0, __PYX_ERR(0, 343, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":344 + * + * def copy(self): + * return makeAlignmentHeader(bam_hdr_dup(self.ptr)) # <<<<<<<<<<<<<< + * + * property nreferences: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(bam_hdr_dup(__pyx_v_self->ptr))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 344, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":343 + * return self.ptr != NULL + * + * def copy(self): # <<<<<<<<<<<<<< + * return makeAlignmentHeader(bam_hdr_dup(self.ptr)) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":350 + * + * This is a read-only attribute.""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.ptr.n_targets + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 350, 0, __PYX_ERR(0, 350, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":351 + * This is a read-only attribute.""" + * def __get__(self): + * return self.ptr.n_targets # <<<<<<<<<<<<<< + * + * property references: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->n_targets); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":350 + * + * This is a read-only attribute.""" + * def __get__(self): # <<<<<<<<<<<<<< + * return self.ptr.n_targets + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.nreferences.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":356 + * """tuple with the names of :term:`reference` sequences. This is a + * read-only attribute""" + * def __get__(self): # <<<<<<<<<<<<<< + * t = [] + * cdef int x + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_10references_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_10references_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10references___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + PyObject *__pyx_v_t = NULL; + int __pyx_v_x; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int32_t __pyx_t_2; + int32_t __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 356, 0, __PYX_ERR(0, 356, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":357 + * read-only attribute""" + * def __get__(self): + * t = [] # <<<<<<<<<<<<<< + * cdef int x + * for x in range(self.ptr.n_targets): + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_t = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":359 + * t = [] + * cdef int x + * for x in range(self.ptr.n_targets): # <<<<<<<<<<<<<< + * t.append(charptr_to_str(self.ptr.target_name[x])) + * return tuple(t) + */ + __pyx_t_2 = __pyx_v_self->ptr->n_targets; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_x = __pyx_t_4; + + /* "pysam/libcalignmentfile.pyx":360 + * cdef int x + * for x in range(self.ptr.n_targets): + * t.append(charptr_to_str(self.ptr.target_name[x])) # <<<<<<<<<<<<<< + * return tuple(t) + * + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_self->ptr->target_name[__pyx_v_x]), NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 360, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_t, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 360, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "pysam/libcalignmentfile.pyx":361 + * for x in range(self.ptr.n_targets): + * t.append(charptr_to_str(self.ptr.target_name[x])) + * return tuple(t) # <<<<<<<<<<<<<< + * + * property lengths: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyList_AsTuple(__pyx_v_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 361, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":356 + * """tuple with the names of :term:`reference` sequences. This is a + * read-only attribute""" + * def __get__(self): # <<<<<<<<<<<<<< + * t = [] + * cdef int x + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.references.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_t); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":368 + * :attr:`pysam.AlignmentFile.references` + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * t = [] + * cdef int x + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + PyObject *__pyx_v_t = NULL; + int __pyx_v_x; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int32_t __pyx_t_2; + int32_t __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 368, 0, __PYX_ERR(0, 368, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":369 + * """ + * def __get__(self): + * t = [] # <<<<<<<<<<<<<< + * cdef int x + * for x in range(self.ptr.n_targets): + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 369, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_t = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":371 + * t = [] + * cdef int x + * for x in range(self.ptr.n_targets): # <<<<<<<<<<<<<< + * t.append(self.ptr.target_len[x]) + * return tuple(t) + */ + __pyx_t_2 = __pyx_v_self->ptr->n_targets; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_x = __pyx_t_4; + + /* "pysam/libcalignmentfile.pyx":372 + * cdef int x + * for x in range(self.ptr.n_targets): + * t.append(self.ptr.target_len[x]) # <<<<<<<<<<<<<< + * return tuple(t) + * + */ + __pyx_t_1 = __Pyx_PyInt_From_uint32_t((__pyx_v_self->ptr->target_len[__pyx_v_x])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 372, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_t, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 372, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "pysam/libcalignmentfile.pyx":373 + * for x in range(self.ptr.n_targets): + * t.append(self.ptr.target_len[x]) + * return tuple(t) # <<<<<<<<<<<<<< + * + * def _build_sequence_section(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyList_AsTuple(__pyx_v_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 373, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":368 + * :attr:`pysam.AlignmentFile.references` + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * t = [] + * cdef int x + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.lengths.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_t); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":375 + * return tuple(t) + * + * def _build_sequence_section(self): # <<<<<<<<<<<<<< + * """return sequence section of header. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_19_build_sequence_section(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section[] = "AlignmentHeader._build_sequence_section(self)\nreturn sequence section of header.\n \n The sequence section is built from the list of reference names and\n lengths stored in the BAM-file and not from any @SQ entries that\n are part of the header's text section.\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_19_build_sequence_section(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_build_sequence_section (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + int __pyx_v_x; + PyObject *__pyx_v_text = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int32_t __pyx_t_2; + int32_t __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + __Pyx_RefNannySetupContext("_build_sequence_section", 0); + __Pyx_TraceCall("_build_sequence_section", __pyx_f[0], 375, 0, __PYX_ERR(0, 375, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":384 + * + * cdef int x + * text = [] # <<<<<<<<<<<<<< + * for x in range(self.ptr.n_targets): + * text.append("@SQ\tSN:{}\tLN:{}\n".format( + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 384, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_text = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":385 + * cdef int x + * text = [] + * for x in range(self.ptr.n_targets): # <<<<<<<<<<<<<< + * text.append("@SQ\tSN:{}\tLN:{}\n".format( + * force_str(self.ptr.target_name[x]), + */ + __pyx_t_2 = __pyx_v_self->ptr->n_targets; + __pyx_t_3 = __pyx_t_2; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_x = __pyx_t_4; + + /* "pysam/libcalignmentfile.pyx":386 + * text = [] + * for x in range(self.ptr.n_targets): + * text.append("@SQ\tSN:{}\tLN:{}\n".format( # <<<<<<<<<<<<<< + * force_str(self.ptr.target_name[x]), + * self.ptr.target_len[x])) + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_SQ_SN_LN, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + + /* "pysam/libcalignmentfile.pyx":387 + * for x in range(self.ptr.n_targets): + * text.append("@SQ\tSN:{}\tLN:{}\n".format( + * force_str(self.ptr.target_name[x]), # <<<<<<<<<<<<<< + * self.ptr.target_len[x])) + * return "".join(text) + */ + __pyx_t_6 = __Pyx_PyBytes_FromString((__pyx_v_self->ptr->target_name[__pyx_v_x])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 387, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 387, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pysam/libcalignmentfile.pyx":388 + * text.append("@SQ\tSN:{}\tLN:{}\n".format( + * force_str(self.ptr.target_name[x]), + * self.ptr.target_len[x])) # <<<<<<<<<<<<<< + * return "".join(text) + * + */ + __pyx_t_6 = __Pyx_PyInt_From_uint32_t((__pyx_v_self->ptr->target_len[__pyx_v_x])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 388, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_7, __pyx_t_6}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_7, __pyx_t_6}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_6); + __pyx_t_7 = 0; + __pyx_t_6 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pysam/libcalignmentfile.pyx":386 + * text = [] + * for x in range(self.ptr.n_targets): + * text.append("@SQ\tSN:{}\tLN:{}\n".format( # <<<<<<<<<<<<<< + * force_str(self.ptr.target_name[x]), + * self.ptr.target_len[x])) + */ + __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_text, __pyx_t_1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 386, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "pysam/libcalignmentfile.pyx":389 + * force_str(self.ptr.target_name[x]), + * self.ptr.target_len[x])) + * return "".join(text) # <<<<<<<<<<<<<< + * + * def to_dict(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__12, __pyx_v_text); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 389, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":375 + * return tuple(t) + * + * def _build_sequence_section(self): # <<<<<<<<<<<<<< + * """return sequence section of header. + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader._build_sequence_section", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_text); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":391 + * return "".join(text) + * + * def to_dict(self): # <<<<<<<<<<<<<< + * """return two-level dictionary with header information from the file. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_21to_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict[] = "AlignmentHeader.to_dict(self)\nreturn two-level dictionary with header information from the file.\n\n The first level contains the record (``HD``, ``SQ``, etc) and\n the second level contains the fields (``VN``, ``LN``, etc).\n\n The parser is validating and will raise an AssertionError if\n if encounters any record or field tags that are not part of\n the SAM specification. Use the\n :attr:`pysam.AlignmentFile.text` attribute to get the unparsed\n header.\n\n The parsing follows the SAM format specification with the\n exception of the ``CL`` field. This option will consume the\n rest of a header line irrespective of any additional fields.\n This behaviour has been added to accommodate command line\n options that contain characters that are not valid field\n separators.\n\n If no @SQ entries are within the text section of the header,\n this will be automatically added from the reference names and\n lengths stored in the binary part of the header.\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_21to_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("to_dict (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_t = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_fields = NULL; + PyObject *__pyx_v_record = NULL; + PyObject *__pyx_v_x = NULL; + PyObject *__pyx_v_idx = NULL; + PyObject *__pyx_v_field = NULL; + PyObject *__pyx_v_key = NULL; + PyObject *__pyx_v_value = NULL; + PyObject *__pyx_v_sq = NULL; + PyObject *__pyx_v_ref = NULL; + PyObject *__pyx_v_length = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + int __pyx_t_8; + int __pyx_t_9; + Py_ssize_t __pyx_t_10; + PyObject *(*__pyx_t_11)(PyObject *); + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *(*__pyx_t_15)(PyObject *); + int __pyx_t_16; + PyObject *__pyx_t_17 = NULL; + __Pyx_RefNannySetupContext("to_dict", 0); + __Pyx_TraceCall("to_dict", __pyx_f[0], 391, 0, __PYX_ERR(0, 391, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":414 + * lengths stored in the binary part of the header. + * """ + * result = collections.OrderedDict() # <<<<<<<<<<<<<< + * + * # convert to python string + */ + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 414, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 414, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 414, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 414, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_result = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":417 + * + * # convert to python string + * t = self.__str__() # <<<<<<<<<<<<<< + * for line in t.split("\n"): + * if not line.strip(): + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 417, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 417, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 417, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_t = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":418 + * # convert to python string + * t = self.__str__() + * for line in t.split("\n"): # <<<<<<<<<<<<<< + * if not line.strip(): + * continue + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_split); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 418, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 418, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 418, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 418, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 418, __pyx_L1_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 418, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 418, __pyx_L1_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 418, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + } + } else { + __pyx_t_3 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 418, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcalignmentfile.pyx":419 + * t = self.__str__() + * for line in t.split("\n"): + * if not line.strip(): # <<<<<<<<<<<<<< + * continue + * assert line.startswith("@"), \ + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_strip); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 419, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 419, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else { + __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 419, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 419, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = ((!__pyx_t_7) != 0); + if (__pyx_t_8) { + + /* "pysam/libcalignmentfile.pyx":420 + * for line in t.split("\n"): + * if not line.strip(): + * continue # <<<<<<<<<<<<<< + * assert line.startswith("@"), \ + * "header line without '@': '%s'" % line + */ + goto __pyx_L3_continue; + + /* "pysam/libcalignmentfile.pyx":419 + * t = self.__str__() + * for line in t.split("\n"): + * if not line.strip(): # <<<<<<<<<<<<<< + * continue + * assert line.startswith("@"), \ + */ + } + + /* "pysam/libcalignmentfile.pyx":421 + * if not line.strip(): + * continue + * assert line.startswith("@"), \ # <<<<<<<<<<<<<< + * "header line without '@': '%s'" % line + * fields = line[1:].split("\t") + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_startswith); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 421, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 421, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 421, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_8)) { + + /* "pysam/libcalignmentfile.pyx":422 + * continue + * assert line.startswith("@"), \ + * "header line without '@': '%s'" % line # <<<<<<<<<<<<<< + * fields = line[1:].split("\t") + * record = fields[0] + */ + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_header_line_without_s, __pyx_v_line); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 422, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + PyErr_SetObject(PyExc_AssertionError, __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 421, __pyx_L1_error) + } + } + #endif + + /* "pysam/libcalignmentfile.pyx":423 + * assert line.startswith("@"), \ + * "header line without '@': '%s'" % line + * fields = line[1:].split("\t") # <<<<<<<<<<<<<< + * record = fields[0] + * assert record in VALID_HEADER_TYPES, \ + */ + __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_line, 1, 0, NULL, NULL, &__pyx_slice__16, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 423, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 423, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 423, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pysam/libcalignmentfile.pyx":424 + * "header line without '@': '%s'" % line + * fields = line[1:].split("\t") + * record = fields[0] # <<<<<<<<<<<<<< + * assert record in VALID_HEADER_TYPES, \ + * "header line with invalid type '%s': '%s'" % (record, line) + */ + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_fields, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 424, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pysam/libcalignmentfile.pyx":425 + * fields = line[1:].split("\t") + * record = fields[0] + * assert record in VALID_HEADER_TYPES, \ # <<<<<<<<<<<<<< + * "header line with invalid type '%s': '%s'" % (record, line) + * + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 425, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_8 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 425, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!(__pyx_t_8 != 0))) { + + /* "pysam/libcalignmentfile.pyx":426 + * record = fields[0] + * assert record in VALID_HEADER_TYPES, \ + * "header line with invalid type '%s': '%s'" % (record, line) # <<<<<<<<<<<<<< + * + * # treat comments + */ + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_record); + __Pyx_GIVEREF(__pyx_v_record); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_record); + __Pyx_INCREF(__pyx_v_line); + __Pyx_GIVEREF(__pyx_v_line); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_line); + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_header_line_with_invalid_type_s, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyErr_SetObject(PyExc_AssertionError, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 425, __pyx_L1_error) + } + } + #endif + + /* "pysam/libcalignmentfile.pyx":429 + * + * # treat comments + * if record == "CO": # <<<<<<<<<<<<<< + * if record not in result: + * result[record] = [] + */ + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_record, __pyx_n_s_CO, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 429, __pyx_L1_error) + if (__pyx_t_8) { + + /* "pysam/libcalignmentfile.pyx":430 + * # treat comments + * if record == "CO": + * if record not in result: # <<<<<<<<<<<<<< + * result[record] = [] + * result[record].append("\t".join( fields[1:])) + */ + __pyx_t_8 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 430, __pyx_L1_error) + __pyx_t_7 = (__pyx_t_8 != 0); + if (__pyx_t_7) { + + /* "pysam/libcalignmentfile.pyx":431 + * if record == "CO": + * if record not in result: + * result[record] = [] # <<<<<<<<<<<<<< + * result[record].append("\t".join( fields[1:])) + * continue + */ + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 431, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(PyObject_SetItem(__pyx_v_result, __pyx_v_record, __pyx_t_3) < 0)) __PYX_ERR(0, 431, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libcalignmentfile.pyx":430 + * # treat comments + * if record == "CO": + * if record not in result: # <<<<<<<<<<<<<< + * result[record] = [] + * result[record].append("\t".join( fields[1:])) + */ + } + + /* "pysam/libcalignmentfile.pyx":432 + * if record not in result: + * result[record] = [] + * result[record].append("\t".join( fields[1:])) # <<<<<<<<<<<<<< + * continue + * # the following is clumsy as generators do not work? + */ + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_result, __pyx_v_record); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 1, 0, NULL, NULL, &__pyx_slice__18, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_3, __pyx_t_6); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pysam/libcalignmentfile.pyx":433 + * result[record] = [] + * result[record].append("\t".join( fields[1:])) + * continue # <<<<<<<<<<<<<< + * # the following is clumsy as generators do not work? + * x = {} + */ + goto __pyx_L3_continue; + + /* "pysam/libcalignmentfile.pyx":429 + * + * # treat comments + * if record == "CO": # <<<<<<<<<<<<<< + * if record not in result: + * result[record] = [] + */ + } + + /* "pysam/libcalignmentfile.pyx":435 + * continue + * # the following is clumsy as generators do not work? + * x = {} # <<<<<<<<<<<<<< + * + * for idx, field in enumerate(fields[1:]): + */ + __pyx_t_6 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 435, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_XDECREF_SET(__pyx_v_x, ((PyObject*)__pyx_t_6)); + __pyx_t_6 = 0; + + /* "pysam/libcalignmentfile.pyx":437 + * x = {} + * + * for idx, field in enumerate(fields[1:]): # <<<<<<<<<<<<<< + * if ":" not in field: + * raise ValueError("malformatted header: no ':' in field" ) + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_6 = __pyx_int_0; + __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 1, 0, NULL, NULL, &__pyx_slice__19, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 437, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (likely(!__pyx_t_11)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 437, __pyx_L1_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + } else { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 437, __pyx_L1_error) + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + } + } else { + __pyx_t_3 = __pyx_t_11(__pyx_t_2); + if (unlikely(!__pyx_t_3)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 437, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF_SET(__pyx_v_field, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_t_6); + __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_6); + __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_6, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); + __pyx_t_6 = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pysam/libcalignmentfile.pyx":438 + * + * for idx, field in enumerate(fields[1:]): + * if ":" not in field: # <<<<<<<<<<<<<< + * raise ValueError("malformatted header: no ':' in field" ) + * key, value = field.split(":", 1) + */ + __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_kp_s__8, __pyx_v_field, Py_NE)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 438, __pyx_L1_error) + __pyx_t_8 = (__pyx_t_7 != 0); + if (unlikely(__pyx_t_8)) { + + /* "pysam/libcalignmentfile.pyx":439 + * for idx, field in enumerate(fields[1:]): + * if ":" not in field: + * raise ValueError("malformatted header: no ':' in field" ) # <<<<<<<<<<<<<< + * key, value = field.split(":", 1) + * if key in ("CL",): + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 439, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":438 + * + * for idx, field in enumerate(fields[1:]): + * if ":" not in field: # <<<<<<<<<<<<<< + * raise ValueError("malformatted header: no ':' in field" ) + * key, value = field.split(":", 1) + */ + } + + /* "pysam/libcalignmentfile.pyx":440 + * if ":" not in field: + * raise ValueError("malformatted header: no ':' in field" ) + * key, value = field.split(":", 1) # <<<<<<<<<<<<<< + * if key in ("CL",): + * # special treatment for command line + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_field, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) { + PyObject* sequence = __pyx_t_12; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 440, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_13 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_13 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_13); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_13 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + #endif + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_14 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_3)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_13 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_13)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_13); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) __PYX_ERR(0, 440, __pyx_L1_error) + __pyx_t_15 = NULL; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L12_unpacking_done; + __pyx_L11_unpacking_failed:; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_15 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 440, __pyx_L1_error) + __pyx_L12_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_13); + __pyx_t_13 = 0; + + /* "pysam/libcalignmentfile.pyx":441 + * raise ValueError("malformatted header: no ':' in field" ) + * key, value = field.split(":", 1) + * if key in ("CL",): # <<<<<<<<<<<<<< + * # special treatment for command line + * # statements (CL). These might contain + */ + __Pyx_INCREF(__pyx_v_key); + __pyx_t_12 = __pyx_v_key; + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_12, __pyx_n_s_CL, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 441, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_7 = (__pyx_t_8 != 0); + if (__pyx_t_7) { + + /* "pysam/libcalignmentfile.pyx":448 + * # header. Thus, in contravention to the + * # SAM API, consume the rest of the line. + * key, value = "\t".join(fields[idx+1:]).split(":", 1) # <<<<<<<<<<<<<< + * x[key] = KNOWN_HEADER_FIELDS[record][key](value) + * break + */ + __pyx_t_12 = __Pyx_PyInt_AddObjC(__pyx_v_idx, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 0, 0, &__pyx_t_12, NULL, NULL, 0, 0, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_t_13); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_split); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) { + PyObject* sequence = __pyx_t_12; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 448, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_13 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_13 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(__pyx_t_3); + #else + __pyx_t_13 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_14 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext; + index = 0; __pyx_t_13 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_13)) goto __pyx_L14_unpacking_failed; + __Pyx_GOTREF(__pyx_t_13); + index = 1; __pyx_t_3 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_3)) goto __pyx_L14_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) __PYX_ERR(0, 448, __pyx_L1_error) + __pyx_t_15 = NULL; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L15_unpacking_done; + __pyx_L14_unpacking_failed:; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_15 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 448, __pyx_L1_error) + __pyx_L15_unpacking_done:; + } + __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_13); + __pyx_t_13 = 0; + __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcalignmentfile.pyx":449 + * # SAM API, consume the rest of the line. + * key, value = "\t".join(fields[idx+1:]).split(":", 1) + * x[key] = KNOWN_HEADER_FIELDS[record][key](value) # <<<<<<<<<<<<<< + * break + * + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_KNOWN_HEADER_FIELDS); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_13 = __Pyx_PyObject_GetItem(__pyx_t_3, __pyx_v_record); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_13, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_13) { + __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_value); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_13, __pyx_v_value}; + __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 449, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_12); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_13, __pyx_v_value}; + __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 449, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_12); + } else + #endif + { + __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_13); __pyx_t_13 = NULL; + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_v_value); + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_14, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_t_12) < 0)) __PYX_ERR(0, 449, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pysam/libcalignmentfile.pyx":450 + * key, value = "\t".join(fields[idx+1:]).split(":", 1) + * x[key] = KNOWN_HEADER_FIELDS[record][key](value) + * break # <<<<<<<<<<<<<< + * + * # interpret type of known header record tags, default to str + */ + goto __pyx_L9_break; + + /* "pysam/libcalignmentfile.pyx":441 + * raise ValueError("malformatted header: no ':' in field" ) + * key, value = field.split(":", 1) + * if key in ("CL",): # <<<<<<<<<<<<<< + * # special treatment for command line + * # statements (CL). These might contain + */ + } + + /* "pysam/libcalignmentfile.pyx":453 + * + * # interpret type of known header record tags, default to str + * x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value) # <<<<<<<<<<<<<< + * + * if VALID_HEADER_TYPES[record] == collections.Mapping: + */ + __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_KNOWN_HEADER_FIELDS); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_13 = __Pyx_PyObject_GetItem(__pyx_t_14, __pyx_v_record); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_get); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + __pyx_t_16 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_16 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_key, ((PyObject *)(&PyString_Type))}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_key, ((PyObject *)(&PyString_Type))}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_17 = PyTuple_New(2+__pyx_t_16); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_17); + if (__pyx_t_13) { + __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_13); __pyx_t_13 = NULL; + } + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_16, __pyx_v_key); + __Pyx_INCREF(((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); + PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_16, ((PyObject *)(&PyString_Type))); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_17, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_14) { + __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_value); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_14, __pyx_v_value}; + __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GOTREF(__pyx_t_12); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_14, __pyx_v_value}; + __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GOTREF(__pyx_t_12); + } else + #endif + { + __pyx_t_17 = PyTuple_New(1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_14); __pyx_t_14 = NULL; + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_17, 0+1, __pyx_v_value); + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_17, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_t_12) < 0)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pysam/libcalignmentfile.pyx":437 + * x = {} + * + * for idx, field in enumerate(fields[1:]): # <<<<<<<<<<<<<< + * if ":" not in field: + * raise ValueError("malformatted header: no ':' in field" ) + */ + } + __pyx_L9_break:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pysam/libcalignmentfile.pyx":455 + * x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value) + * + * if VALID_HEADER_TYPES[record] == collections.Mapping: # <<<<<<<<<<<<<< + * if record in result: + * raise ValueError( + */ + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 455, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_6, __pyx_v_record); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 455, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 455, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 455, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyObject_RichCompare(__pyx_t_2, __pyx_t_12, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 455, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 455, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_7) { + + /* "pysam/libcalignmentfile.pyx":456 + * + * if VALID_HEADER_TYPES[record] == collections.Mapping: + * if record in result: # <<<<<<<<<<<<<< + * raise ValueError( + * "multiple '%s' lines are not permitted" % record) + */ + __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_result, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 456, __pyx_L1_error) + __pyx_t_8 = (__pyx_t_7 != 0); + if (unlikely(__pyx_t_8)) { + + /* "pysam/libcalignmentfile.pyx":458 + * if record in result: + * raise ValueError( + * "multiple '%s' lines are not permitted" % record) # <<<<<<<<<<<<<< + * + * result[record] = x + */ + __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_multiple_s_lines_are_not_permitt, __pyx_v_record); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 458, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + + /* "pysam/libcalignmentfile.pyx":457 + * if VALID_HEADER_TYPES[record] == collections.Mapping: + * if record in result: + * raise ValueError( # <<<<<<<<<<<<<< + * "multiple '%s' lines are not permitted" % record) + * + */ + __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_12, 0, 0, 0); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __PYX_ERR(0, 457, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":456 + * + * if VALID_HEADER_TYPES[record] == collections.Mapping: + * if record in result: # <<<<<<<<<<<<<< + * raise ValueError( + * "multiple '%s' lines are not permitted" % record) + */ + } + + /* "pysam/libcalignmentfile.pyx":460 + * "multiple '%s' lines are not permitted" % record) + * + * result[record] = x # <<<<<<<<<<<<<< + * elif VALID_HEADER_TYPES[record] == collections.Sequence: + * if record not in result: result[record] = [] + */ + if (unlikely(PyObject_SetItem(__pyx_v_result, __pyx_v_record, __pyx_v_x) < 0)) __PYX_ERR(0, 460, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":455 + * x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value) + * + * if VALID_HEADER_TYPES[record] == collections.Mapping: # <<<<<<<<<<<<<< + * if record in result: + * raise ValueError( + */ + goto __pyx_L16; + } + + /* "pysam/libcalignmentfile.pyx":461 + * + * result[record] = x + * elif VALID_HEADER_TYPES[record] == collections.Sequence: # <<<<<<<<<<<<<< + * if record not in result: result[record] = [] + * result[record].append(x) + */ + __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_12, __pyx_v_record); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyObject_RichCompare(__pyx_t_6, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_12); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 461, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 461, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (__pyx_t_8) { + + /* "pysam/libcalignmentfile.pyx":462 + * result[record] = x + * elif VALID_HEADER_TYPES[record] == collections.Sequence: + * if record not in result: result[record] = [] # <<<<<<<<<<<<<< + * result[record].append(x) + * + */ + __pyx_t_8 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 462, __pyx_L1_error) + __pyx_t_7 = (__pyx_t_8 != 0); + if (__pyx_t_7) { + __pyx_t_12 = PyList_New(0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 462, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (unlikely(PyObject_SetItem(__pyx_v_result, __pyx_v_record, __pyx_t_12) < 0)) __PYX_ERR(0, 462, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + + /* "pysam/libcalignmentfile.pyx":463 + * elif VALID_HEADER_TYPES[record] == collections.Sequence: + * if record not in result: result[record] = [] + * result[record].append(x) # <<<<<<<<<<<<<< + * + * # if there are no SQ lines in the header, add the + */ + __pyx_t_12 = __Pyx_PyObject_GetItem(__pyx_v_result, __pyx_v_record); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 463, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_12, __pyx_v_x); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 463, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pysam/libcalignmentfile.pyx":461 + * + * result[record] = x + * elif VALID_HEADER_TYPES[record] == collections.Sequence: # <<<<<<<<<<<<<< + * if record not in result: result[record] = [] + * result[record].append(x) + */ + } + __pyx_L16:; + + /* "pysam/libcalignmentfile.pyx":418 + * # convert to python string + * t = self.__str__() + * for line in t.split("\n"): # <<<<<<<<<<<<<< + * if not line.strip(): + * continue + */ + __pyx_L3_continue:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":474 + * # the SQ information is not part of the textual header + * # and thus are missing from the output. See issue 84. + * if "SQ" not in result: # <<<<<<<<<<<<<< + * sq = [] + * for ref, length in zip(self.references, self.lengths): + */ + __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_SQ_2, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 474, __pyx_L1_error) + __pyx_t_8 = (__pyx_t_7 != 0); + if (__pyx_t_8) { + + /* "pysam/libcalignmentfile.pyx":475 + * # and thus are missing from the output. See issue 84. + * if "SQ" not in result: + * sq = [] # <<<<<<<<<<<<<< + * for ref, length in zip(self.references, self.lengths): + * sq.append({'LN': length, 'SN': ref }) + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 475, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sq = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":476 + * if "SQ" not in result: + * sq = [] + * for ref, length in zip(self.references, self.lengths): # <<<<<<<<<<<<<< + * sq.append({'LN': length, 'SN': ref }) + * result["SQ"] = sq + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_references); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_lengths); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_12); + __pyx_t_1 = 0; + __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_2, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (likely(PyList_CheckExact(__pyx_t_12)) || PyTuple_CheckExact(__pyx_t_12)) { + __pyx_t_2 = __pyx_t_12; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 476, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_12 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_12); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 476, __pyx_L1_error) + #else + __pyx_t_12 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_12 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_12); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 476, __pyx_L1_error) + #else + __pyx_t_12 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + #endif + } + } else { + __pyx_t_12 = __pyx_t_5(__pyx_t_2); + if (unlikely(!__pyx_t_12)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 476, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_12); + } + if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) { + PyObject* sequence = __pyx_t_12; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 476, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_3 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_15 = Py_TYPE(__pyx_t_3)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_15(__pyx_t_3); if (unlikely(!__pyx_t_1)) goto __pyx_L22_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_6 = __pyx_t_15(__pyx_t_3); if (unlikely(!__pyx_t_6)) goto __pyx_L22_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_3), 2) < 0) __PYX_ERR(0, 476, __pyx_L1_error) + __pyx_t_15 = NULL; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L23_unpacking_done; + __pyx_L22_unpacking_failed:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_15 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 476, __pyx_L1_error) + __pyx_L23_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_ref, __pyx_t_1); + __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libcalignmentfile.pyx":477 + * sq = [] + * for ref, length in zip(self.references, self.lengths): + * sq.append({'LN': length, 'SN': ref }) # <<<<<<<<<<<<<< + * result["SQ"] = sq + * + */ + __pyx_t_12 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 477, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_LN, __pyx_v_length) < 0) __PYX_ERR(0, 477, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_SN, __pyx_v_ref) < 0) __PYX_ERR(0, 477, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_sq, __pyx_t_12); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 477, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "pysam/libcalignmentfile.pyx":476 + * if "SQ" not in result: + * sq = [] + * for ref, length in zip(self.references, self.lengths): # <<<<<<<<<<<<<< + * sq.append({'LN': length, 'SN': ref }) + * result["SQ"] = sq + */ + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libcalignmentfile.pyx":478 + * for ref, length in zip(self.references, self.lengths): + * sq.append({'LN': length, 'SN': ref }) + * result["SQ"] = sq # <<<<<<<<<<<<<< + * + * return result + */ + if (unlikely(PyObject_SetItem(__pyx_v_result, __pyx_n_s_SQ_2, __pyx_v_sq) < 0)) __PYX_ERR(0, 478, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":474 + * # the SQ information is not part of the textual header + * # and thus are missing from the output. See issue 84. + * if "SQ" not in result: # <<<<<<<<<<<<<< + * sq = [] + * for ref, length in zip(self.references, self.lengths): + */ + } + + /* "pysam/libcalignmentfile.pyx":480 + * result["SQ"] = sq + * + * return result # <<<<<<<<<<<<<< + * + * def as_dict(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":391 + * return "".join(text) + * + * def to_dict(self): # <<<<<<<<<<<<<< + * """return two-level dictionary with header information from the file. + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_17); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.to_dict", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_t); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_fields); + __Pyx_XDECREF(__pyx_v_record); + __Pyx_XDECREF(__pyx_v_x); + __Pyx_XDECREF(__pyx_v_idx); + __Pyx_XDECREF(__pyx_v_field); + __Pyx_XDECREF(__pyx_v_key); + __Pyx_XDECREF(__pyx_v_value); + __Pyx_XDECREF(__pyx_v_sq); + __Pyx_XDECREF(__pyx_v_ref); + __Pyx_XDECREF(__pyx_v_length); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":482 + * return result + * + * def as_dict(self): # <<<<<<<<<<<<<< + * """deprecated: use :meth:`to_dict()`""" + * return self.to_dict() + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_23as_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict[] = "AlignmentHeader.as_dict(self)\ndeprecated: use :meth:`to_dict()`"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_23as_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("as_dict (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("as_dict", 0); + __Pyx_TraceCall("as_dict", __pyx_f[0], 482, 0, __PYX_ERR(0, 482, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":484 + * def as_dict(self): + * """deprecated: use :meth:`to_dict()`""" + * return self.to_dict() # <<<<<<<<<<<<<< + * + * def get_reference_name(self, tid): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 484, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 484, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 484, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":482 + * return result + * + * def as_dict(self): # <<<<<<<<<<<<<< + * """deprecated: use :meth:`to_dict()`""" + * return self.to_dict() + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.as_dict", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":486 + * return self.to_dict() + * + * def get_reference_name(self, tid): # <<<<<<<<<<<<<< + * if tid == -1: + * return None + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_25get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name[] = "AlignmentHeader.get_reference_name(self, tid)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_25get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_reference_name (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_tid)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_tid) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + __Pyx_RefNannySetupContext("get_reference_name", 0); + __Pyx_TraceCall("get_reference_name", __pyx_f[0], 486, 0, __PYX_ERR(0, 486, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":487 + * + * def get_reference_name(self, tid): + * if tid == -1: # <<<<<<<<<<<<<< + * return None + * if not 0 <= tid < self.ptr.n_targets: + */ + __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_v_tid, __pyx_int_neg_1, -1L, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "pysam/libcalignmentfile.pyx":488 + * def get_reference_name(self, tid): + * if tid == -1: + * return None # <<<<<<<<<<<<<< + * if not 0 <= tid < self.ptr.n_targets: + * raise ValueError("reference_id %i out of range 0<=tid<%i" % + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":487 + * + * def get_reference_name(self, tid): + * if tid == -1: # <<<<<<<<<<<<<< + * return None + * if not 0 <= tid < self.ptr.n_targets: + */ + } + + /* "pysam/libcalignmentfile.pyx":489 + * if tid == -1: + * return None + * if not 0 <= tid < self.ptr.n_targets: # <<<<<<<<<<<<<< + * raise ValueError("reference_id %i out of range 0<=tid<%i" % + * (tid, self.ptr.n_targets)) + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_tid, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 489, __pyx_L1_error) + if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { + __Pyx_DECREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->n_targets); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 489, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_tid, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 489, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 489, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = ((!__pyx_t_2) != 0); + if (unlikely(__pyx_t_4)) { + + /* "pysam/libcalignmentfile.pyx":491 + * if not 0 <= tid < self.ptr.n_targets: + * raise ValueError("reference_id %i out of range 0<=tid<%i" % + * (tid, self.ptr.n_targets)) # <<<<<<<<<<<<<< + * return charptr_to_str(self.ptr.target_name[tid]) + * + */ + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->n_targets); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_tid); + __Pyx_GIVEREF(__pyx_v_tid); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_tid); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":490 + * return None + * if not 0 <= tid < self.ptr.n_targets: + * raise ValueError("reference_id %i out of range 0<=tid<%i" % # <<<<<<<<<<<<<< + * (tid, self.ptr.n_targets)) + * return charptr_to_str(self.ptr.target_name[tid]) + */ + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_reference_id_i_out_of_range_0_ti, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 490, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 490, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":489 + * if tid == -1: + * return None + * if not 0 <= tid < self.ptr.n_targets: # <<<<<<<<<<<<<< + * raise ValueError("reference_id %i out of range 0<=tid<%i" % + * (tid, self.ptr.n_targets)) + */ + } + + /* "pysam/libcalignmentfile.pyx":492 + * raise ValueError("reference_id %i out of range 0<=tid<%i" % + * (tid, self.ptr.n_targets)) + * return charptr_to_str(self.ptr.target_name[tid]) # <<<<<<<<<<<<<< + * + * def get_reference_length(self, reference): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_tid); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 492, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_self->ptr->target_name[__pyx_t_5]), NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 492, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":486 + * return self.to_dict() + * + * def get_reference_name(self, tid): # <<<<<<<<<<<<<< + * if tid == -1: + * return None + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.get_reference_name", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":494 + * return charptr_to_str(self.ptr.target_name[tid]) + * + * def get_reference_length(self, reference): # <<<<<<<<<<<<<< + * cdef int tid = self.get_tid(reference) + * if tid < 0: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_27get_reference_length(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length[] = "AlignmentHeader.get_reference_length(self, reference)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_27get_reference_length(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_reference_length (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_reference)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_reference) { + int __pyx_v_tid; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_t_6; + __Pyx_RefNannySetupContext("get_reference_length", 0); + __Pyx_TraceCall("get_reference_length", __pyx_f[0], 494, 0, __PYX_ERR(0, 494, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":495 + * + * def get_reference_length(self, reference): + * cdef int tid = self.get_tid(reference) # <<<<<<<<<<<<<< + * if tid < 0: + * raise KeyError("unknown reference {}".format(reference)) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 495, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_reference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 495, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_reference}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 495, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_reference}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 495, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 495, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_reference); + __Pyx_GIVEREF(__pyx_v_reference); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_reference); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 495, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 495, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_tid = __pyx_t_5; + + /* "pysam/libcalignmentfile.pyx":496 + * def get_reference_length(self, reference): + * cdef int tid = self.get_tid(reference) + * if tid < 0: # <<<<<<<<<<<<<< + * raise KeyError("unknown reference {}".format(reference)) + * else: + */ + __pyx_t_6 = ((__pyx_v_tid < 0) != 0); + if (unlikely(__pyx_t_6)) { + + /* "pysam/libcalignmentfile.pyx":497 + * cdef int tid = self.get_tid(reference) + * if tid < 0: + * raise KeyError("unknown reference {}".format(reference)) # <<<<<<<<<<<<<< + * else: + * return self.ptr.target_len[tid] + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unknown_reference, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_4) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_reference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_reference}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 497, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_reference}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 497, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_INCREF(__pyx_v_reference); + __Pyx_GIVEREF(__pyx_v_reference); + PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_reference); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 497, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":496 + * def get_reference_length(self, reference): + * cdef int tid = self.get_tid(reference) + * if tid < 0: # <<<<<<<<<<<<<< + * raise KeyError("unknown reference {}".format(reference)) + * else: + */ + } + + /* "pysam/libcalignmentfile.pyx":499 + * raise KeyError("unknown reference {}".format(reference)) + * else: + * return self.ptr.target_len[tid] # <<<<<<<<<<<<<< + * + * def is_valid_tid(self, int tid): + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyInt_From_uint32_t((__pyx_v_self->ptr->target_len[__pyx_v_tid])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 499, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + } + + /* "pysam/libcalignmentfile.pyx":494 + * return charptr_to_str(self.ptr.target_name[tid]) + * + * def get_reference_length(self, reference): # <<<<<<<<<<<<<< + * cdef int tid = self.get_tid(reference) + * if tid < 0: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.get_reference_length", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":501 + * return self.ptr.target_len[tid] + * + * def is_valid_tid(self, int tid): # <<<<<<<<<<<<<< + * """ + * return True if the numerical :term:`tid` is valid; False otherwise. + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_29is_valid_tid(PyObject *__pyx_v_self, PyObject *__pyx_arg_tid); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid[] = "AlignmentHeader.is_valid_tid(self, int tid)\n\n return True if the numerical :term:`tid` is valid; False otherwise.\n\n Note that the unmapped tid code (-1) counts as an invalid.\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_29is_valid_tid(PyObject *__pyx_v_self, PyObject *__pyx_arg_tid) { + int __pyx_v_tid; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_valid_tid (wrapper)", 0); + assert(__pyx_arg_tid); { + __pyx_v_tid = __Pyx_PyInt_As_int(__pyx_arg_tid); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 501, __pyx_L3_error) + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((int)__pyx_v_tid)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, int __pyx_v_tid) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("is_valid_tid", 0); + __Pyx_TraceCall("is_valid_tid", __pyx_f[0], 501, 0, __PYX_ERR(0, 501, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":507 + * Note that the unmapped tid code (-1) counts as an invalid. + * """ + * return 0 <= tid < self.ptr.n_targets # <<<<<<<<<<<<<< + * + * def get_tid(self, reference): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = (0 <= __pyx_v_tid); + if (__pyx_t_1) { + __pyx_t_1 = (__pyx_v_tid < __pyx_v_self->ptr->n_targets); + } + __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 507, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":501 + * return self.ptr.target_len[tid] + * + * def is_valid_tid(self, int tid): # <<<<<<<<<<<<<< + * """ + * return True if the numerical :term:`tid` is valid; False otherwise. + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":509 + * return 0 <= tid < self.ptr.n_targets + * + * def get_tid(self, reference): # <<<<<<<<<<<<<< + * """ + * return the numerical :term:`tid` corresponding to + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_31get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid[] = "AlignmentHeader.get_tid(self, reference)\n\n return the numerical :term:`tid` corresponding to\n :term:`reference`\n\n returns -1 if reference is not known.\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_31get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_tid (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_reference)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_reference) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + char const *__pyx_t_2; + __Pyx_RefNannySetupContext("get_tid", 0); + __Pyx_TraceCall("get_tid", __pyx_f[0], 509, 0, __PYX_ERR(0, 509, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_reference); + + /* "pysam/libcalignmentfile.pyx":516 + * returns -1 if reference is not known. + * """ + * reference = force_bytes(reference) # <<<<<<<<<<<<<< + * return bam_name2id(self.ptr, reference) + * + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_reference, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 516, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF_SET(__pyx_v_reference, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":517 + * """ + * reference = force_bytes(reference) + * return bam_name2id(self.ptr, reference) # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v_reference); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 517, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(bam_name2id(__pyx_v_self->ptr, __pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 517, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":509 + * return 0 <= tid < self.ptr.n_targets + * + * def get_tid(self, reference): # <<<<<<<<<<<<<< + * """ + * return the numerical :term:`tid` corresponding to + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.get_tid", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_reference); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":519 + * return bam_name2id(self.ptr, reference) + * + * def __str__(self): # <<<<<<<<<<<<<< + * '''string with the full contents of the :term:`sam file` header as a + * string. + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_33__str__(PyObject *__pyx_v_self); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__[] = "string with the full contents of the :term:`sam file` header as a\n string.\n\n If no @SQ entries are within the text section of the header,\n this will be automatically added from the reference names and\n lengths stored in the binary part of the header.\n\n See :attr:`pysam.AlignmentFile.header.to_dict()` to get a parsed\n representation of the header.\n "; +#if CYTHON_COMPILING_IN_CPYTHON +struct wrapperbase __pyx_wrapperbase_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__; +#endif +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_33__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + PyObject *__pyx_v_text = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__str__", 0); + __Pyx_TraceCall("__str__", __pyx_f[0], 519, 0, __PYX_ERR(0, 519, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":530 + * representation of the header. + * ''' + * text = from_string_and_size(self.ptr.text, self.ptr.l_text) # <<<<<<<<<<<<<< + * if "@SQ" not in text: + * text += "\n" + self._build_sequence_section() + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_from_string_and_size(__pyx_v_self->ptr->text, __pyx_v_self->ptr->l_text); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 530, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_text = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":531 + * ''' + * text = from_string_and_size(self.ptr.text, self.ptr.l_text) + * if "@SQ" not in text: # <<<<<<<<<<<<<< + * text += "\n" + self._build_sequence_section() + * return text + */ + __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_kp_s_SQ, __pyx_v_text, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 531, __pyx_L1_error) + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignmentfile.pyx":532 + * text = from_string_and_size(self.ptr.text, self.ptr.l_text) + * if "@SQ" not in text: + * text += "\n" + self._build_sequence_section() # <<<<<<<<<<<<<< + * return text + * + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_build_sequence_section); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (__pyx_t_5) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 532, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 532, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Add(__pyx_kp_s__10, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_text, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":531 + * ''' + * text = from_string_and_size(self.ptr.text, self.ptr.l_text) + * if "@SQ" not in text: # <<<<<<<<<<<<<< + * text += "\n" + self._build_sequence_section() + * return text + */ + } + + /* "pysam/libcalignmentfile.pyx":533 + * if "@SQ" not in text: + * text += "\n" + self._build_sequence_section() + * return text # <<<<<<<<<<<<<< + * + * # dictionary access methods, for backwards compatibility. + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_text); + __pyx_r = __pyx_v_text; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":519 + * return bam_name2id(self.ptr, reference) + * + * def __str__(self): # <<<<<<<<<<<<<< + * '''string with the full contents of the :term:`sam file` header as a + * string. + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_text); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":536 + * + * # dictionary access methods, for backwards compatibility. + * def __setitem__(self, key, value): # <<<<<<<<<<<<<< + * raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()") + * + */ + +/* Python wrapper */ +static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_35__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_35__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_34__setitem__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_34__setitem__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_key, CYTHON_UNUSED PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setitem__", 0); + __Pyx_TraceCall("__setitem__", __pyx_f[0], 536, 0, __PYX_ERR(0, 536, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":537 + * # dictionary access methods, for backwards compatibility. + * def __setitem__(self, key, value): + * raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()") # <<<<<<<<<<<<<< + * + * def __getitem__(self, key): + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 537, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":536 + * + * # dictionary access methods, for backwards compatibility. + * def __setitem__(self, key, value): # <<<<<<<<<<<<<< + * raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()") + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":539 + * raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()") + * + * def __getitem__(self, key): # <<<<<<<<<<<<<< + * return self.to_dict().__getitem__(key) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_37__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_37__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_36__getitem__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_36__getitem__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_key) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("__getitem__", 0); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 539, 0, __PYX_ERR(0, 539, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":540 + * + * def __getitem__(self, key): + * return self.to_dict().__getitem__(key) # <<<<<<<<<<<<<< + * + * def items(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 540, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_getitem); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_key}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_key}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_key); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":539 + * raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()") + * + * def __getitem__(self, key): # <<<<<<<<<<<<<< + * return self.to_dict().__getitem__(key) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":542 + * return self.to_dict().__getitem__(key) + * + * def items(self): # <<<<<<<<<<<<<< + * return self.to_dict().items() + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_39items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_38items[] = "AlignmentHeader.items(self)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_39items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("items (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_38items(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_38items(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("items", 0); + __Pyx_TraceCall("items", __pyx_f[0], 542, 0, __PYX_ERR(0, 542, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":543 + * + * def items(self): + * return self.to_dict().items() # <<<<<<<<<<<<<< + * + * # PY2 compatibility + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 543, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 543, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 543, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 543, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 543, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 543, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":542 + * return self.to_dict().__getitem__(key) + * + * def items(self): # <<<<<<<<<<<<<< + * return self.to_dict().items() + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.items", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":546 + * + * # PY2 compatibility + * def iteritems(self): # <<<<<<<<<<<<<< + * return self.to_dict().items() + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_41iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems[] = "AlignmentHeader.iteritems(self)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_41iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("iteritems (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("iteritems", 0); + __Pyx_TraceCall("iteritems", __pyx_f[0], 546, 0, __PYX_ERR(0, 546, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":547 + * # PY2 compatibility + * def iteritems(self): + * return self.to_dict().items() # <<<<<<<<<<<<<< + * + * def keys(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 547, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 547, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 547, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 547, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 547, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 547, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":546 + * + * # PY2 compatibility + * def iteritems(self): # <<<<<<<<<<<<<< + * return self.to_dict().items() + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":549 + * return self.to_dict().items() + * + * def keys(self): # <<<<<<<<<<<<<< + * return self.to_dict().keys() + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_43keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_42keys[] = "AlignmentHeader.keys(self)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_43keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("keys (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_42keys(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_42keys(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("keys", 0); + __Pyx_TraceCall("keys", __pyx_f[0], 549, 0, __PYX_ERR(0, 549, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":550 + * + * def keys(self): + * return self.to_dict().keys() # <<<<<<<<<<<<<< + * + * def values(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 550, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 550, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 550, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_keys); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 550, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 550, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 550, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":549 + * return self.to_dict().items() + * + * def keys(self): # <<<<<<<<<<<<<< + * return self.to_dict().keys() + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":552 + * return self.to_dict().keys() + * + * def values(self): # <<<<<<<<<<<<<< + * return self.to_dict().values() + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_45values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_44values[] = "AlignmentHeader.values(self)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_45values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("values (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_44values(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_44values(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("values", 0); + __Pyx_TraceCall("values", __pyx_f[0], 552, 0, __PYX_ERR(0, 552, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":553 + * + * def values(self): + * return self.to_dict().values() # <<<<<<<<<<<<<< + * + * def get(self, *args): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 553, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 553, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 553, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 553, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":552 + * return self.to_dict().keys() + * + * def values(self): # <<<<<<<<<<<<<< + * return self.to_dict().values() + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":555 + * return self.to_dict().values() + * + * def get(self, *args): # <<<<<<<<<<<<<< + * return self.to_dict().get(*args) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_47get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_46get[] = "AlignmentHeader.get(self, *args)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_47get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_args = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get (wrapper)", 0); + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "get", 0))) return NULL; + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_46get(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), __pyx_v_args); + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_46get(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_args) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("get", 0); + __Pyx_TraceCall("get", __pyx_f[0], 555, 0, __PYX_ERR(0, 555, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":556 + * + * def get(self, *args): + * return self.to_dict().get(*args) # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 556, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_v_args, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":555 + * return self.to_dict().values() + * + * def get(self, *args): # <<<<<<<<<<<<<< + * return self.to_dict().get(*args) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.get", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":558 + * return self.to_dict().get(*args) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.to_dict().__len__() + * + */ + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_48__len__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static Py_ssize_t __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_48__len__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + __Pyx_RefNannySetupContext("__len__", 0); + __Pyx_TraceCall("__len__", __pyx_f[0], 558, 0, __PYX_ERR(0, 558, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":559 + * + * def __len__(self): + * return self.to_dict().__len__() # <<<<<<<<<<<<<< + * + * def __contains__(self, key): + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 559, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 559, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":558 + * return self.to_dict().get(*args) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.to_dict().__len__() + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":561 + * return self.to_dict().__len__() + * + * def __contains__(self, key): # <<<<<<<<<<<<<< + * return self.to_dict().__contains__(key) + * + */ + +/* Python wrapper */ +static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_51__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_51__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_50__contains__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_50__contains__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_key) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + __Pyx_RefNannySetupContext("__contains__", 0); + __Pyx_TraceCall("__contains__", __pyx_f[0], 561, 0, __PYX_ERR(0, 561, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":562 + * + * def __contains__(self, key): + * return self.to_dict().__contains__(key) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 562, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_contains); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_key}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_key}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_key); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":561 + * return self.to_dict().__len__() + * + * def __contains__(self, key): # <<<<<<<<<<<<<< + * return self.to_dict().__contains__(key) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_53__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__[] = "AlignmentHeader.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_53__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 2, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_55__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__[] = "AlignmentHeader.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_55__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":721 + * """ + * + * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< + * self.htsfile = NULL + * self.filename = None + */ + +/* Python wrapper */ +static int __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_args = 0; + PyObject *__pyx_v_kwargs = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1; + __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1; + __Pyx_GOTREF(__pyx_v_kwargs); + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("__cinit__", 0); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 721, 0, __PYX_ERR(0, 721, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_args); + + /* "pysam/libcalignmentfile.pyx":722 + * + * def __cinit__(self, *args, **kwargs): + * self.htsfile = NULL # <<<<<<<<<<<<<< + * self.filename = None + * self.mode = None + */ + __pyx_v_self->__pyx_base.htsfile = NULL; + + /* "pysam/libcalignmentfile.pyx":723 + * def __cinit__(self, *args, **kwargs): + * self.htsfile = NULL + * self.filename = None # <<<<<<<<<<<<<< + * self.mode = None + * self.threads = 1 + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename); + __Pyx_DECREF(__pyx_v_self->__pyx_base.filename); + __pyx_v_self->__pyx_base.filename = Py_None; + + /* "pysam/libcalignmentfile.pyx":724 + * self.htsfile = NULL + * self.filename = None + * self.mode = None # <<<<<<<<<<<<<< + * self.threads = 1 + * self.is_stream = False + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.mode); + __Pyx_DECREF(__pyx_v_self->__pyx_base.mode); + __pyx_v_self->__pyx_base.mode = Py_None; + + /* "pysam/libcalignmentfile.pyx":725 + * self.filename = None + * self.mode = None + * self.threads = 1 # <<<<<<<<<<<<<< + * self.is_stream = False + * self.is_remote = False + */ + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.threads); + __Pyx_DECREF(__pyx_v_self->__pyx_base.threads); + __pyx_v_self->__pyx_base.threads = __pyx_int_1; + + /* "pysam/libcalignmentfile.pyx":726 + * self.mode = None + * self.threads = 1 + * self.is_stream = False # <<<<<<<<<<<<<< + * self.is_remote = False + * self.index = NULL + */ + __pyx_v_self->__pyx_base.is_stream = 0; + + /* "pysam/libcalignmentfile.pyx":727 + * self.threads = 1 + * self.is_stream = False + * self.is_remote = False # <<<<<<<<<<<<<< + * self.index = NULL + * + */ + __pyx_v_self->__pyx_base.is_remote = 0; + + /* "pysam/libcalignmentfile.pyx":728 + * self.is_stream = False + * self.is_remote = False + * self.index = NULL # <<<<<<<<<<<<<< + * + * if "filename" in kwargs: + */ + __pyx_v_self->index = NULL; + + /* "pysam/libcalignmentfile.pyx":730 + * self.index = NULL + * + * if "filename" in kwargs: # <<<<<<<<<<<<<< + * args = [kwargs["filename"]] + * del kwargs["filename"] + */ + __pyx_t_1 = (__Pyx_PyDict_ContainsTF(__pyx_n_s_filename, __pyx_v_kwargs, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 730, __pyx_L1_error) + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignmentfile.pyx":731 + * + * if "filename" in kwargs: + * args = [kwargs["filename"]] # <<<<<<<<<<<<<< + * del kwargs["filename"] + * + */ + __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_kwargs, __pyx_n_s_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 731, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 731, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); + PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pysam/libcalignmentfile.pyx":732 + * if "filename" in kwargs: + * args = [kwargs["filename"]] + * del kwargs["filename"] # <<<<<<<<<<<<<< + * + * self._open(*args, **kwargs) + */ + if (unlikely(PyDict_DelItem(__pyx_v_kwargs, __pyx_n_s_filename) < 0)) __PYX_ERR(0, 732, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":730 + * self.index = NULL + * + * if "filename" in kwargs: # <<<<<<<<<<<<<< + * args = [kwargs["filename"]] + * del kwargs["filename"] + */ + } + + /* "pysam/libcalignmentfile.pyx":734 + * del kwargs["filename"] + * + * self._open(*args, **kwargs) # <<<<<<<<<<<<<< + * + * # allocate memory for iterator + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 734, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 734, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, __pyx_v_kwargs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 734, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pysam/libcalignmentfile.pyx":737 + * + * # allocate memory for iterator + * self.b = calloc(1, sizeof(bam1_t)) # <<<<<<<<<<<<<< + * if self.b == NULL: + * raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t))) + */ + __pyx_v_self->b = ((bam1_t *)calloc(1, (sizeof(bam1_t)))); + + /* "pysam/libcalignmentfile.pyx":738 + * # allocate memory for iterator + * self.b = calloc(1, sizeof(bam1_t)) + * if self.b == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t))) + * + */ + __pyx_t_2 = ((__pyx_v_self->b == NULL) != 0); + if (unlikely(__pyx_t_2)) { + + /* "pysam/libcalignmentfile.pyx":739 + * self.b = calloc(1, sizeof(bam1_t)) + * if self.b == NULL: + * raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t))) # <<<<<<<<<<<<<< + * + * def has_index(self): + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_memory_of_siz, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 739, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_FromSize_t((sizeof(bam1_t))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 739, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_6) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 739, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_4}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 739, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_4}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 739, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 739, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 739, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 739, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 739, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":738 + * # allocate memory for iterator + * self.b = calloc(1, sizeof(bam1_t)) + * if self.b == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t))) + * + */ } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 16, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 385, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_template), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "template", 0))) __PYX_ERR(0, 388, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_filepath_or_object, __pyx_v_mode, __pyx_v_template, __pyx_v_reference_names, __pyx_v_reference_lengths, __pyx_v_reference_filename, __pyx_v_text, __pyx_v_header, __pyx_v_port, __pyx_v_add_sq_text, __pyx_v_check_header, __pyx_v_check_sq, __pyx_v_filepath_index, __pyx_v_referencenames, __pyx_v_referencelengths, __pyx_v_duplicate_filehandle); - /* "pysam/libcalignmentfile.pyx":385 - * return True + /* "pysam/libcalignmentfile.pyx":721 + * """ * - * def _open(self, # <<<<<<<<<<<<<< - * filepath_or_object, - * mode=None, + * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< + * self.htsfile = NULL + * self.filename = None */ /* function exit code */ + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_args); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_filepath_or_object, PyObject *__pyx_v_mode, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_template, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_reference_filename, PyObject *__pyx_v_text, PyObject *__pyx_v_header, CYTHON_UNUSED PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq, PyObject *__pyx_v_filepath_index, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths, PyObject *__pyx_v_duplicate_filehandle) { - char *__pyx_v_cfilename; - char *__pyx_v_creference_filename; - char *__pyx_v_cindexname; - CYTHON_UNUSED char *__pyx_v_cmode; - PyObject *__pyx_v_filename = NULL; - char *__pyx_v_ctext; - PyObject *__pyx_v_n = NULL; - PyObject *__pyx_v_x = NULL; - PyObject *__pyx_v_name = NULL; - int __pyx_v_format_index; - int __pyx_v_has_index; - PyObject *__pyx_v_ref = NULL; +/* "pysam/libcalignmentfile.pyx":741 + * raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t))) + * + * def has_index(self): # <<<<<<<<<<<<<< + * """return true if htsfile has an existing (and opened) index. + * """ + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_3has_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_2has_index[] = "AlignmentFile.has_index(self)\nreturn true if htsfile has an existing (and opened) index.\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_3has_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("has_index (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_2has_index(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_2has_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - char *__pyx_t_9; - int __pyx_t_10; - Py_ssize_t __pyx_t_11; - Py_ssize_t __pyx_t_12; - PyObject *(*__pyx_t_13)(PyObject *); - size_t __pyx_t_14; - int32_t __pyx_t_15; - long __pyx_t_16; - uint32_t __pyx_t_17; - char const *__pyx_t_18; - int __pyx_t_19; - int __pyx_t_20; - htsFile *__pyx_t_21; - char const *__pyx_t_22; - PyObject *__pyx_t_23 = NULL; - PyObject *__pyx_t_24 = NULL; - int64_t __pyx_t_25; - __Pyx_RefNannySetupContext("_open", 0); - __Pyx_TraceCall("_open", __pyx_f[0], 385, 0, __PYX_ERR(0, 385, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_mode); - __Pyx_INCREF(__pyx_v_reference_names); - __Pyx_INCREF(__pyx_v_reference_lengths); - __Pyx_INCREF(__pyx_v_reference_filename); - __Pyx_INCREF(__pyx_v_text); - __Pyx_INCREF(__pyx_v_filepath_index); - - /* "pysam/libcalignmentfile.pyx":407 - * will be closed and a new file will be opened. - * ''' - * cdef char *cfilename = NULL # <<<<<<<<<<<<<< - * cdef char *creference_filename = NULL - * cdef char *cindexname = NULL - */ - __pyx_v_cfilename = NULL; + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("has_index", 0); + __Pyx_TraceCall("has_index", __pyx_f[0], 741, 0, __PYX_ERR(0, 741, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":408 - * ''' - * cdef char *cfilename = NULL - * cdef char *creference_filename = NULL # <<<<<<<<<<<<<< - * cdef char *cindexname = NULL - * cdef char *cmode = NULL + /* "pysam/libcalignmentfile.pyx":744 + * """return true if htsfile has an existing (and opened) index. + * """ + * return self.index != NULL # <<<<<<<<<<<<<< + * + * def check_index(self): */ - __pyx_v_creference_filename = NULL; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->index != NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":409 - * cdef char *cfilename = NULL - * cdef char *creference_filename = NULL - * cdef char *cindexname = NULL # <<<<<<<<<<<<<< - * cdef char *cmode = NULL + /* "pysam/libcalignmentfile.pyx":741 + * raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t))) * + * def has_index(self): # <<<<<<<<<<<<<< + * """return true if htsfile has an existing (and opened) index. + * """ */ - __pyx_v_cindexname = NULL; - /* "pysam/libcalignmentfile.pyx":410 - * cdef char *creference_filename = NULL - * cdef char *cindexname = NULL - * cdef char *cmode = NULL # <<<<<<<<<<<<<< + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.has_index", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":746 + * return self.index != NULL + * + * def check_index(self): # <<<<<<<<<<<<<< + * """return True if index is present. * - * # for backwards compatibility: */ - __pyx_v_cmode = NULL; - /* "pysam/libcalignmentfile.pyx":413 +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_5check_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_4check_index[] = "AlignmentFile.check_index(self)\nreturn True if index is present.\n\n Raises\n ------\n\n AttributeError\n if htsfile is :term:`SAM` formatted and thus has no index.\n\n ValueError\n if htsfile is closed or index could not be opened.\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_5check_index(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("check_index (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4check_index(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4check_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("check_index", 0); + __Pyx_TraceCall("check_index", __pyx_f[0], 746, 0, __PYX_ERR(0, 746, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":759 + * """ * - * # for backwards compatibility: - * if referencenames is not None: # <<<<<<<<<<<<<< - * reference_names = referencenames - * if referencelengths is not None: + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError("I/O operation on closed file") + * if not self.is_bam and not self.is_cram: */ - __pyx_t_1 = (__pyx_v_referencenames != Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 759, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 759, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = ((!__pyx_t_2) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":414 - * # for backwards compatibility: - * if referencenames is not None: - * reference_names = referencenames # <<<<<<<<<<<<<< - * if referencelengths is not None: - * reference_lengths = referencelengths + /* "pysam/libcalignmentfile.pyx":760 + * + * if not self.is_open: + * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< + * if not self.is_bam and not self.is_cram: + * raise AttributeError( */ - __Pyx_INCREF(__pyx_v_referencenames); - __Pyx_DECREF_SET(__pyx_v_reference_names, __pyx_v_referencenames); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 760, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 760, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":413 + /* "pysam/libcalignmentfile.pyx":759 + * """ * - * # for backwards compatibility: - * if referencenames is not None: # <<<<<<<<<<<<<< - * reference_names = referencenames - * if referencelengths is not None: + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError("I/O operation on closed file") + * if not self.is_bam and not self.is_cram: */ } - /* "pysam/libcalignmentfile.pyx":415 - * if referencenames is not None: - * reference_names = referencenames - * if referencelengths is not None: # <<<<<<<<<<<<<< - * reference_lengths = referencelengths - * + /* "pysam/libcalignmentfile.pyx":761 + * if not self.is_open: + * raise ValueError("I/O operation on closed file") + * if not self.is_bam and not self.is_cram: # <<<<<<<<<<<<<< + * raise AttributeError( + * "AlignmentFile.mapped only available in bam files") */ - __pyx_t_2 = (__pyx_v_referencelengths != Py_None); - __pyx_t_1 = (__pyx_t_2 != 0); - if (__pyx_t_1) { - - /* "pysam/libcalignmentfile.pyx":416 - * reference_names = referencenames - * if referencelengths is not None: - * reference_lengths = referencelengths # <<<<<<<<<<<<<< - * - * # close a previously opened file + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 761, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 761, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = ((!__pyx_t_2) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_3 = __pyx_t_4; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 761, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 761, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = ((!__pyx_t_4) != 0); + __pyx_t_3 = __pyx_t_2; + __pyx_L5_bool_binop_done:; + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcalignmentfile.pyx":762 + * raise ValueError("I/O operation on closed file") + * if not self.is_bam and not self.is_cram: + * raise AttributeError( # <<<<<<<<<<<<<< + * "AlignmentFile.mapped only available in bam files") + * if self.index == NULL: */ - __Pyx_INCREF(__pyx_v_referencelengths); - __Pyx_DECREF_SET(__pyx_v_reference_lengths, __pyx_v_referencelengths); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_AttributeError, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 762, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 762, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":415 - * if referencenames is not None: - * reference_names = referencenames - * if referencelengths is not None: # <<<<<<<<<<<<<< - * reference_lengths = referencelengths - * + /* "pysam/libcalignmentfile.pyx":761 + * if not self.is_open: + * raise ValueError("I/O operation on closed file") + * if not self.is_bam and not self.is_cram: # <<<<<<<<<<<<<< + * raise AttributeError( + * "AlignmentFile.mapped only available in bam files") */ } - /* "pysam/libcalignmentfile.pyx":419 - * - * # close a previously opened file - * if self.is_open: # <<<<<<<<<<<<<< - * self.close() - * + /* "pysam/libcalignmentfile.pyx":764 + * raise AttributeError( + * "AlignmentFile.mapped only available in bam files") + * if self.index == NULL: # <<<<<<<<<<<<<< + * raise ValueError( + * "mapping information not recorded in index " */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 419, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 419, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_1) { + __pyx_t_3 = ((__pyx_v_self->index == NULL) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":420 - * # close a previously opened file - * if self.is_open: - * self.close() # <<<<<<<<<<<<<< - * - * # autodetection for read + /* "pysam/libcalignmentfile.pyx":765 + * "AlignmentFile.mapped only available in bam files") + * if self.index == NULL: + * raise ValueError( # <<<<<<<<<<<<<< + * "mapping information not recorded in index " + * "or index not available") */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 420, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 420, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else { - __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 420, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 765, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":419 - * - * # close a previously opened file - * if self.is_open: # <<<<<<<<<<<<<< - * self.close() - * + /* "pysam/libcalignmentfile.pyx":764 + * raise AttributeError( + * "AlignmentFile.mapped only available in bam files") + * if self.index == NULL: # <<<<<<<<<<<<<< + * raise ValueError( + * "mapping information not recorded in index " */ } - /* "pysam/libcalignmentfile.pyx":423 - * - * # autodetection for read - * if mode is None: # <<<<<<<<<<<<<< - * mode = "r" - * - */ - __pyx_t_1 = (__pyx_v_mode == Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - - /* "pysam/libcalignmentfile.pyx":424 - * # autodetection for read - * if mode is None: - * mode = "r" # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":768 + * "mapping information not recorded in index " + * "or index not available") + * return True # <<<<<<<<<<<<<< * - * assert mode in ("r", "w", "rb", "wb", "wh", + * def _open(self, */ - __Pyx_INCREF(__pyx_n_s_r); - __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_r); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_True); + __pyx_r = Py_True; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":423 + /* "pysam/libcalignmentfile.pyx":746 + * return self.index != NULL * - * # autodetection for read - * if mode is None: # <<<<<<<<<<<<<< - * mode = "r" + * def check_index(self): # <<<<<<<<<<<<<< + * """return True if index is present. * */ - } - /* "pysam/libcalignmentfile.pyx":426 - * mode = "r" - * - * assert mode in ("r", "w", "rb", "wb", "wh", # <<<<<<<<<<<<<< - * "wbu", "rU", "wb0", - * "rc", "wc"), \ - */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - __Pyx_INCREF(__pyx_v_mode); - __pyx_t_3 = __pyx_v_mode; - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_r, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 426, __pyx_L1_error) - if (!__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 426, __pyx_L1_error) - if (!__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_rb, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 426, __pyx_L1_error) - if (!__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_wb, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 426, __pyx_L1_error) - if (!__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_wh, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 426, __pyx_L1_error) - if (!__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_wbu, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 426, __pyx_L1_error) - if (!__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_rU, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 426, __pyx_L1_error) - if (!__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_wb0, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 426, __pyx_L1_error) - if (!__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_rc, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 426, __pyx_L1_error) - if (!__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_wc, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 426, __pyx_L1_error) - __pyx_t_2 = __pyx_t_1; - __pyx_L7_bool_binop_done:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!(__pyx_t_2 != 0))) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.check_index", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignmentfile.pyx":429 - * "wbu", "rU", "wb0", - * "rc", "wc"), \ - * "invalid file opening mode `%s`" % mode # <<<<<<<<<<<<<< +/* "pysam/libcalignmentfile.pyx":770 + * return True * - * self.duplicate_filehandle = duplicate_filehandle + * def _open(self, # <<<<<<<<<<<<<< + * filepath_or_object, + * mode=None, */ - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_invalid_file_opening_mode_s, __pyx_v_mode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 429, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - PyErr_SetObject(PyExc_AssertionError, __pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 426, __pyx_L1_error) - } - } - #endif - /* "pysam/libcalignmentfile.pyx":431 - * "invalid file opening mode `%s`" % mode - * - * self.duplicate_filehandle = duplicate_filehandle # <<<<<<<<<<<<<< - * - * # StringIO not supported +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_6_open[] = "AlignmentFile._open(self, filepath_or_object, mode=None, AlignmentFile template=None, reference_names=None, reference_lengths=None, reference_filename=None, text=None, header=None, port=None, add_sq_text=True, add_sam_header=True, check_header=True, check_sq=True, index_filename=None, filepath_index=None, require_index=False, referencenames=None, referencelengths=None, duplicate_filehandle=True, ignore_truncation=False, format_options=None, threads=1)\nopen a sam, bam or cram formatted file.\n\n If _open is called on an existing file, the current file\n will be closed and a new file will be opened.\n\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_filepath_or_object = 0; + PyObject *__pyx_v_mode = 0; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_template = 0; + PyObject *__pyx_v_reference_names = 0; + PyObject *__pyx_v_reference_lengths = 0; + PyObject *__pyx_v_reference_filename = 0; + PyObject *__pyx_v_text = 0; + PyObject *__pyx_v_header = 0; + CYTHON_UNUSED PyObject *__pyx_v_port = 0; + PyObject *__pyx_v_add_sq_text = 0; + PyObject *__pyx_v_add_sam_header = 0; + CYTHON_UNUSED PyObject *__pyx_v_check_header = 0; + PyObject *__pyx_v_check_sq = 0; + PyObject *__pyx_v_index_filename = 0; + PyObject *__pyx_v_filepath_index = 0; + PyObject *__pyx_v_require_index = 0; + PyObject *__pyx_v_referencenames = 0; + PyObject *__pyx_v_referencelengths = 0; + PyObject *__pyx_v_duplicate_filehandle = 0; + PyObject *__pyx_v_ignore_truncation = 0; + PyObject *__pyx_v_format_options = 0; + PyObject *__pyx_v_threads = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_open (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filepath_or_object,&__pyx_n_s_mode,&__pyx_n_s_template,&__pyx_n_s_reference_names,&__pyx_n_s_reference_lengths,&__pyx_n_s_reference_filename,&__pyx_n_s_text,&__pyx_n_s_header,&__pyx_n_s_port,&__pyx_n_s_add_sq_text,&__pyx_n_s_add_sam_header,&__pyx_n_s_check_header,&__pyx_n_s_check_sq,&__pyx_n_s_index_filename,&__pyx_n_s_filepath_index,&__pyx_n_s_require_index,&__pyx_n_s_referencenames,&__pyx_n_s_referencelengths,&__pyx_n_s_duplicate_filehandle,&__pyx_n_s_ignore_truncation,&__pyx_n_s_format_options,&__pyx_n_s_threads,0}; + PyObject* values[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + + /* "pysam/libcalignmentfile.pyx":772 + * def _open(self, + * filepath_or_object, + * mode=None, # <<<<<<<<<<<<<< + * AlignmentFile template=None, + * reference_names=None, */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_duplicate_filehandle); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 431, __pyx_L1_error) - __pyx_v_self->__pyx_base.duplicate_filehandle = __pyx_t_2; + values[1] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":434 - * - * # StringIO not supported - * if isinstance(filepath_or_object, StringIO): # <<<<<<<<<<<<<< - * raise NotImplementedError( - * "access from StringIO objects not supported") + /* "pysam/libcalignmentfile.pyx":773 + * filepath_or_object, + * mode=None, + * AlignmentFile template=None, # <<<<<<<<<<<<<< + * reference_names=None, + * reference_lengths=None, */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_StringIO); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 434, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_IsInstance(__pyx_v_filepath_or_object, __pyx_t_3); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 434, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = (__pyx_t_2 != 0); - if (unlikely(__pyx_t_1)) { + values[2] = (PyObject *)((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); - /* "pysam/libcalignmentfile.pyx":435 - * # StringIO not supported - * if isinstance(filepath_or_object, StringIO): - * raise NotImplementedError( # <<<<<<<<<<<<<< - * "access from StringIO objects not supported") - * # reading from a file descriptor + /* "pysam/libcalignmentfile.pyx":774 + * mode=None, + * AlignmentFile template=None, + * reference_names=None, # <<<<<<<<<<<<<< + * reference_lengths=None, + * reference_filename=None, */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 435, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 435, __pyx_L1_error) + values[3] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":434 - * - * # StringIO not supported - * if isinstance(filepath_or_object, StringIO): # <<<<<<<<<<<<<< - * raise NotImplementedError( - * "access from StringIO objects not supported") + /* "pysam/libcalignmentfile.pyx":775 + * AlignmentFile template=None, + * reference_names=None, + * reference_lengths=None, # <<<<<<<<<<<<<< + * reference_filename=None, + * text=None, + */ + values[4] = ((PyObject *)Py_None); + + /* "pysam/libcalignmentfile.pyx":776 + * reference_names=None, + * reference_lengths=None, + * reference_filename=None, # <<<<<<<<<<<<<< + * text=None, + * header=None, */ - } + values[5] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":438 - * "access from StringIO objects not supported") - * # reading from a file descriptor - * elif isinstance(filepath_or_object, int): # <<<<<<<<<<<<<< - * self.filename = filepath_or_object - * filename = None + /* "pysam/libcalignmentfile.pyx":777 + * reference_lengths=None, + * reference_filename=None, + * text=None, # <<<<<<<<<<<<<< + * header=None, + * port=None, */ - __pyx_t_1 = PyInt_Check(__pyx_v_filepath_or_object); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + values[6] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":439 - * # reading from a file descriptor - * elif isinstance(filepath_or_object, int): - * self.filename = filepath_or_object # <<<<<<<<<<<<<< - * filename = None - * self.is_remote = False + /* "pysam/libcalignmentfile.pyx":778 + * reference_filename=None, + * text=None, + * header=None, # <<<<<<<<<<<<<< + * port=None, + * add_sq_text=True, */ - __Pyx_INCREF(__pyx_v_filepath_or_object); - __Pyx_GIVEREF(__pyx_v_filepath_or_object); - __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename); - __Pyx_DECREF(__pyx_v_self->__pyx_base.filename); - __pyx_v_self->__pyx_base.filename = __pyx_v_filepath_or_object; + values[7] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":440 - * elif isinstance(filepath_or_object, int): - * self.filename = filepath_or_object - * filename = None # <<<<<<<<<<<<<< - * self.is_remote = False - * self.is_stream = True + /* "pysam/libcalignmentfile.pyx":779 + * text=None, + * header=None, + * port=None, # <<<<<<<<<<<<<< + * add_sq_text=True, + * add_sam_header=True, */ - __Pyx_INCREF(Py_None); - __pyx_v_filename = ((PyObject*)Py_None); + values[8] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":441 - * self.filename = filepath_or_object - * filename = None - * self.is_remote = False # <<<<<<<<<<<<<< - * self.is_stream = True - * # reading from a File object or other object with fileno + /* "pysam/libcalignmentfile.pyx":780 + * header=None, + * port=None, + * add_sq_text=True, # <<<<<<<<<<<<<< + * add_sam_header=True, + * check_header=True, */ - __pyx_v_self->__pyx_base.is_remote = 0; + values[9] = ((PyObject *)Py_True); - /* "pysam/libcalignmentfile.pyx":442 - * filename = None - * self.is_remote = False - * self.is_stream = True # <<<<<<<<<<<<<< - * # reading from a File object or other object with fileno - * elif hasattr(filepath_or_object, "fileno"): + /* "pysam/libcalignmentfile.pyx":781 + * port=None, + * add_sq_text=True, + * add_sam_header=True, # <<<<<<<<<<<<<< + * check_header=True, + * check_sq=True, */ - __pyx_v_self->__pyx_base.is_stream = 1; + values[10] = ((PyObject *)Py_True); - /* "pysam/libcalignmentfile.pyx":438 - * "access from StringIO objects not supported") - * # reading from a file descriptor - * elif isinstance(filepath_or_object, int): # <<<<<<<<<<<<<< - * self.filename = filepath_or_object - * filename = None + /* "pysam/libcalignmentfile.pyx":782 + * add_sq_text=True, + * add_sam_header=True, + * check_header=True, # <<<<<<<<<<<<<< + * check_sq=True, + * index_filename=None, */ - goto __pyx_L17; - } + values[11] = ((PyObject *)Py_True); - /* "pysam/libcalignmentfile.pyx":444 - * self.is_stream = True - * # reading from a File object or other object with fileno - * elif hasattr(filepath_or_object, "fileno"): # <<<<<<<<<<<<<< - * if filepath_or_object.closed: - * raise ValueError('I/O operation on closed file') + /* "pysam/libcalignmentfile.pyx":783 + * add_sam_header=True, + * check_header=True, + * check_sq=True, # <<<<<<<<<<<<<< + * index_filename=None, + * filepath_index=None, */ - __pyx_t_2 = __Pyx_HasAttr(__pyx_v_filepath_or_object, __pyx_n_s_fileno); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 444, __pyx_L1_error) - __pyx_t_1 = (__pyx_t_2 != 0); - if (__pyx_t_1) { + values[12] = ((PyObject *)Py_True); - /* "pysam/libcalignmentfile.pyx":445 - * # reading from a File object or other object with fileno - * elif hasattr(filepath_or_object, "fileno"): - * if filepath_or_object.closed: # <<<<<<<<<<<<<< - * raise ValueError('I/O operation on closed file') - * self.filename = filepath_or_object + /* "pysam/libcalignmentfile.pyx":784 + * check_header=True, + * check_sq=True, + * index_filename=None, # <<<<<<<<<<<<<< + * filepath_index=None, + * require_index=False, */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_filepath_or_object, __pyx_n_s_closed); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 445, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 445, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(__pyx_t_1)) { + values[13] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":446 - * elif hasattr(filepath_or_object, "fileno"): - * if filepath_or_object.closed: - * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< - * self.filename = filepath_or_object - * # .name can be TextIOWrapper + /* "pysam/libcalignmentfile.pyx":785 + * check_sq=True, + * index_filename=None, + * filepath_index=None, # <<<<<<<<<<<<<< + * require_index=False, + * referencenames=None, */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 446, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 446, __pyx_L1_error) + values[14] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":445 - * # reading from a File object or other object with fileno - * elif hasattr(filepath_or_object, "fileno"): - * if filepath_or_object.closed: # <<<<<<<<<<<<<< - * raise ValueError('I/O operation on closed file') - * self.filename = filepath_or_object + /* "pysam/libcalignmentfile.pyx":786 + * index_filename=None, + * filepath_index=None, + * require_index=False, # <<<<<<<<<<<<<< + * referencenames=None, + * referencelengths=None, */ - } + values[15] = ((PyObject *)Py_False); - /* "pysam/libcalignmentfile.pyx":447 - * if filepath_or_object.closed: - * raise ValueError('I/O operation on closed file') - * self.filename = filepath_or_object # <<<<<<<<<<<<<< - * # .name can be TextIOWrapper - * try: + /* "pysam/libcalignmentfile.pyx":787 + * filepath_index=None, + * require_index=False, + * referencenames=None, # <<<<<<<<<<<<<< + * referencelengths=None, + * duplicate_filehandle=True, */ - __Pyx_INCREF(__pyx_v_filepath_or_object); - __Pyx_GIVEREF(__pyx_v_filepath_or_object); - __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename); - __Pyx_DECREF(__pyx_v_self->__pyx_base.filename); - __pyx_v_self->__pyx_base.filename = __pyx_v_filepath_or_object; + values[16] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":449 - * self.filename = filepath_or_object - * # .name can be TextIOWrapper - * try: # <<<<<<<<<<<<<< - * filename = encode_filename(str(filepath_or_object.name)) - * cfilename = filename + /* "pysam/libcalignmentfile.pyx":788 + * require_index=False, + * referencenames=None, + * referencelengths=None, # <<<<<<<<<<<<<< + * duplicate_filehandle=True, + * ignore_truncation=False, */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_8); - /*try:*/ { + values[17] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":450 - * # .name can be TextIOWrapper - * try: - * filename = encode_filename(str(filepath_or_object.name)) # <<<<<<<<<<<<<< - * cfilename = filename - * except AttributeError: + /* "pysam/libcalignmentfile.pyx":789 + * referencenames=None, + * referencelengths=None, + * duplicate_filehandle=True, # <<<<<<<<<<<<<< + * ignore_truncation=False, + * format_options=None, */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_filepath_or_object, __pyx_n_s_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 450, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 450, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 450, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_filename = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + values[18] = ((PyObject *)Py_True); - /* "pysam/libcalignmentfile.pyx":451 - * try: - * filename = encode_filename(str(filepath_or_object.name)) - * cfilename = filename # <<<<<<<<<<<<<< - * except AttributeError: - * filename = None + /* "pysam/libcalignmentfile.pyx":790 + * referencelengths=None, + * duplicate_filehandle=True, + * ignore_truncation=False, # <<<<<<<<<<<<<< + * format_options=None, + * threads=1): + */ + values[19] = ((PyObject *)Py_False); + + /* "pysam/libcalignmentfile.pyx":791 + * duplicate_filehandle=True, + * ignore_truncation=False, + * format_options=None, # <<<<<<<<<<<<<< + * threads=1): + * '''open a sam, bam or cram formatted file. */ - if (unlikely(__pyx_v_filename == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 451, __pyx_L19_error) + values[20] = ((PyObject *)Py_None); + values[21] = ((PyObject *)__pyx_int_1); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 22: values[21] = PyTuple_GET_ITEM(__pyx_args, 21); + CYTHON_FALLTHROUGH; + case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20); + CYTHON_FALLTHROUGH; + case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19); + CYTHON_FALLTHROUGH; + case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18); + CYTHON_FALLTHROUGH; + case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17); + CYTHON_FALLTHROUGH; + case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); + CYTHON_FALLTHROUGH; + case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); + CYTHON_FALLTHROUGH; + case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); + CYTHON_FALLTHROUGH; + case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); + CYTHON_FALLTHROUGH; + case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); + CYTHON_FALLTHROUGH; + case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); + CYTHON_FALLTHROUGH; + case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); + CYTHON_FALLTHROUGH; + case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); + CYTHON_FALLTHROUGH; + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + CYTHON_FALLTHROUGH; + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filepath_or_object)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode); + if (value) { values[1] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_template); + if (value) { values[2] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_names); + if (value) { values[3] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 4: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_lengths); + if (value) { values[4] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 5: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference_filename); + if (value) { values[5] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 6: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_text); + if (value) { values[6] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 7: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_header); + if (value) { values[7] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 8: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_port); + if (value) { values[8] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 9: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_add_sq_text); + if (value) { values[9] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 10: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_add_sam_header); + if (value) { values[10] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 11: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_check_header); + if (value) { values[11] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 12: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_check_sq); + if (value) { values[12] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 13: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_index_filename); + if (value) { values[13] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 14: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filepath_index); + if (value) { values[14] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 15: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_require_index); + if (value) { values[15] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 16: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_referencenames); + if (value) { values[16] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 17: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_referencelengths); + if (value) { values[17] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 18: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_duplicate_filehandle); + if (value) { values[18] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 19: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ignore_truncation); + if (value) { values[19] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 20: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format_options); + if (value) { values[20] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 21: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_threads); + if (value) { values[21] = value; kw_args--; } } - __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_v_filename); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 451, __pyx_L19_error) - __pyx_v_cfilename = __pyx_t_9; - - /* "pysam/libcalignmentfile.pyx":449 - * self.filename = filepath_or_object - * # .name can be TextIOWrapper - * try: # <<<<<<<<<<<<<< - * filename = encode_filename(str(filepath_or_object.name)) - * cfilename = filename - */ } - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L24_try_end; - __pyx_L19_error:; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pysam/libcalignmentfile.pyx":452 - * filename = encode_filename(str(filepath_or_object.name)) - * cfilename = filename - * except AttributeError: # <<<<<<<<<<<<<< - * filename = None - * self.is_remote = False - */ - __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError); - if (__pyx_t_10) { - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 452, __pyx_L21_except_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_5); - - /* "pysam/libcalignmentfile.pyx":453 - * cfilename = filename - * except AttributeError: - * filename = None # <<<<<<<<<<<<<< - * self.is_remote = False - * self.is_stream = True - */ - __Pyx_INCREF(Py_None); - __Pyx_XDECREF_SET(__pyx_v_filename, ((PyObject*)Py_None)); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L20_exception_handled; + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) __PYX_ERR(0, 770, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 22: values[21] = PyTuple_GET_ITEM(__pyx_args, 21); + CYTHON_FALLTHROUGH; + case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20); + CYTHON_FALLTHROUGH; + case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19); + CYTHON_FALLTHROUGH; + case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18); + CYTHON_FALLTHROUGH; + case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17); + CYTHON_FALLTHROUGH; + case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); + CYTHON_FALLTHROUGH; + case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); + CYTHON_FALLTHROUGH; + case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); + CYTHON_FALLTHROUGH; + case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); + CYTHON_FALLTHROUGH; + case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); + CYTHON_FALLTHROUGH; + case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); + CYTHON_FALLTHROUGH; + case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); + CYTHON_FALLTHROUGH; + case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); + CYTHON_FALLTHROUGH; + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + CYTHON_FALLTHROUGH; + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; } - goto __pyx_L21_except_error; - __pyx_L21_except_error:; - - /* "pysam/libcalignmentfile.pyx":449 - * self.filename = filepath_or_object - * # .name can be TextIOWrapper - * try: # <<<<<<<<<<<<<< - * filename = encode_filename(str(filepath_or_object.name)) - * cfilename = filename - */ - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_XGIVEREF(__pyx_t_8); - __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8); - goto __pyx_L1_error; - __pyx_L20_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_XGIVEREF(__pyx_t_8); - __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8); - __pyx_L24_try_end:; } + __pyx_v_filepath_or_object = values[0]; + __pyx_v_mode = values[1]; + __pyx_v_template = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[2]); + __pyx_v_reference_names = values[3]; + __pyx_v_reference_lengths = values[4]; + __pyx_v_reference_filename = values[5]; + __pyx_v_text = values[6]; + __pyx_v_header = values[7]; + __pyx_v_port = values[8]; + __pyx_v_add_sq_text = values[9]; + __pyx_v_add_sam_header = values[10]; + __pyx_v_check_header = values[11]; + __pyx_v_check_sq = values[12]; + __pyx_v_index_filename = values[13]; + __pyx_v_filepath_index = values[14]; + __pyx_v_require_index = values[15]; + __pyx_v_referencenames = values[16]; + __pyx_v_referencelengths = values[17]; + __pyx_v_duplicate_filehandle = values[18]; + __pyx_v_ignore_truncation = values[19]; + __pyx_v_format_options = values[20]; + __pyx_v_threads = values[21]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 22, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 770, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_template), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "template", 0))) __PYX_ERR(0, 773, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_filepath_or_object, __pyx_v_mode, __pyx_v_template, __pyx_v_reference_names, __pyx_v_reference_lengths, __pyx_v_reference_filename, __pyx_v_text, __pyx_v_header, __pyx_v_port, __pyx_v_add_sq_text, __pyx_v_add_sam_header, __pyx_v_check_header, __pyx_v_check_sq, __pyx_v_index_filename, __pyx_v_filepath_index, __pyx_v_require_index, __pyx_v_referencenames, __pyx_v_referencelengths, __pyx_v_duplicate_filehandle, __pyx_v_ignore_truncation, __pyx_v_format_options, __pyx_v_threads); - /* "pysam/libcalignmentfile.pyx":454 - * except AttributeError: - * filename = None - * self.is_remote = False # <<<<<<<<<<<<<< - * self.is_stream = True - * # what remains is a filename + /* "pysam/libcalignmentfile.pyx":770 + * return True + * + * def _open(self, # <<<<<<<<<<<<<< + * filepath_or_object, + * mode=None, */ - __pyx_v_self->__pyx_base.is_remote = 0; - /* "pysam/libcalignmentfile.pyx":455 - * filename = None - * self.is_remote = False - * self.is_stream = True # <<<<<<<<<<<<<< - * # what remains is a filename - * else: - */ - __pyx_v_self->__pyx_base.is_stream = 1; + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignmentfile.pyx":444 - * self.is_stream = True - * # reading from a File object or other object with fileno - * elif hasattr(filepath_or_object, "fileno"): # <<<<<<<<<<<<<< - * if filepath_or_object.closed: - * raise ValueError('I/O operation on closed file') +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_filepath_or_object, PyObject *__pyx_v_mode, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_template, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_reference_filename, PyObject *__pyx_v_text, PyObject *__pyx_v_header, CYTHON_UNUSED PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_add_sam_header, CYTHON_UNUSED PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq, PyObject *__pyx_v_index_filename, PyObject *__pyx_v_filepath_index, PyObject *__pyx_v_require_index, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths, PyObject *__pyx_v_duplicate_filehandle, PyObject *__pyx_v_ignore_truncation, PyObject *__pyx_v_format_options, PyObject *__pyx_v_threads) { + char *__pyx_v_cfilename; + char *__pyx_v_creference_filename; + char *__pyx_v_cindexname; + CYTHON_UNUSED char *__pyx_v_cmode; + bam_hdr_t *__pyx_v_hdr; + PyObject *__pyx_v_filename = NULL; + CYTHON_UNUSED PyObject *__pyx_v_bfile_name = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + char *__pyx_t_9; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + htsFile *__pyx_t_12; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + Py_ssize_t __pyx_t_16; + int __pyx_t_17; + char const *__pyx_t_18; + bam_hdr_t *__pyx_t_19; + int64_t __pyx_t_20; + __Pyx_RefNannySetupContext("_open", 0); + __Pyx_TraceCall("_open", __pyx_f[0], 770, 0, __PYX_ERR(0, 770, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_mode); + __Pyx_INCREF(__pyx_v_reference_names); + __Pyx_INCREF(__pyx_v_reference_lengths); + __Pyx_INCREF(__pyx_v_reference_filename); + + /* "pysam/libcalignmentfile.pyx":799 + * + * ''' + * cdef char *cfilename = NULL # <<<<<<<<<<<<<< + * cdef char *creference_filename = NULL + * cdef char *cindexname = NULL */ - goto __pyx_L17; - } + __pyx_v_cfilename = NULL; - /* "pysam/libcalignmentfile.pyx":458 - * # what remains is a filename - * else: - * self.filename = filename = encode_filename(filepath_or_object) # <<<<<<<<<<<<<< - * cfilename = filename - * self.is_remote = hisremote(cfilename) + /* "pysam/libcalignmentfile.pyx":800 + * ''' + * cdef char *cfilename = NULL + * cdef char *creference_filename = NULL # <<<<<<<<<<<<<< + * cdef char *cindexname = NULL + * cdef char *cmode = NULL */ - /*else*/ { - __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filepath_or_object); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 458, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename); - __Pyx_DECREF(__pyx_v_self->__pyx_base.filename); - __pyx_v_self->__pyx_base.filename = __pyx_t_5; - __Pyx_INCREF(__pyx_t_5); - __pyx_v_filename = ((PyObject*)__pyx_t_5); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_creference_filename = NULL; - /* "pysam/libcalignmentfile.pyx":459 - * else: - * self.filename = filename = encode_filename(filepath_or_object) - * cfilename = filename # <<<<<<<<<<<<<< - * self.is_remote = hisremote(cfilename) - * self.is_stream = self.filename == b'-' + /* "pysam/libcalignmentfile.pyx":801 + * cdef char *cfilename = NULL + * cdef char *creference_filename = NULL + * cdef char *cindexname = NULL # <<<<<<<<<<<<<< + * cdef char *cmode = NULL + * cdef bam_hdr_t * hdr = NULL */ - if (unlikely(__pyx_v_filename == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 459, __pyx_L1_error) - } - __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_v_filename); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 459, __pyx_L1_error) - __pyx_v_cfilename = __pyx_t_9; + __pyx_v_cindexname = NULL; - /* "pysam/libcalignmentfile.pyx":460 - * self.filename = filename = encode_filename(filepath_or_object) - * cfilename = filename - * self.is_remote = hisremote(cfilename) # <<<<<<<<<<<<<< - * self.is_stream = self.filename == b'-' + /* "pysam/libcalignmentfile.pyx":802 + * cdef char *creference_filename = NULL + * cdef char *cindexname = NULL + * cdef char *cmode = NULL # <<<<<<<<<<<<<< + * cdef bam_hdr_t * hdr = NULL * */ - __pyx_v_self->__pyx_base.is_remote = hisremote(__pyx_v_cfilename); + __pyx_v_cmode = NULL; - /* "pysam/libcalignmentfile.pyx":461 - * cfilename = filename - * self.is_remote = hisremote(cfilename) - * self.is_stream = self.filename == b'-' # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":803 + * cdef char *cindexname = NULL + * cdef char *cmode = NULL + * cdef bam_hdr_t * hdr = NULL # <<<<<<<<<<<<<< * - * # for htslib, wbu seems to not work + * if threads > 1 and ignore_truncation: */ - __pyx_t_5 = PyObject_RichCompare(__pyx_v_self->__pyx_base.filename, __pyx_kp_b__11, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 461, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 461, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_self->__pyx_base.is_stream = __pyx_t_1; - } - __pyx_L17:; + __pyx_v_hdr = NULL; - /* "pysam/libcalignmentfile.pyx":464 - * - * # for htslib, wbu seems to not work - * if mode == "wbu": # <<<<<<<<<<<<<< - * mode = "wb0" + /* "pysam/libcalignmentfile.pyx":805 + * cdef bam_hdr_t * hdr = NULL * + * if threads > 1 and ignore_truncation: # <<<<<<<<<<<<<< + * # This won't raise errors if reaching a truncated alignment, + * # because bgzf_mt_reader in htslib does not deal with */ - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_wbu, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 464, __pyx_L1_error) - if (__pyx_t_1) { + __pyx_t_2 = PyObject_RichCompare(__pyx_v_threads, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 805, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 805, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_ignore_truncation); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 805, __pyx_L1_error) + __pyx_t_1 = __pyx_t_3; + __pyx_L4_bool_binop_done:; + if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":465 - * # for htslib, wbu seems to not work - * if mode == "wbu": - * mode = "wb0" # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":811 + * # to bgzf_read (https://github.com/samtools/htslib/blob/1.7/bgzf.c#L888) + * # Better to avoid this (for now) than to produce seemingly correct results. + * raise ValueError('Cannot add extra threads when "ignore_truncation" is True') # <<<<<<<<<<<<<< + * self.threads = threads * - * self.mode = force_bytes(mode) */ - __Pyx_INCREF(__pyx_n_s_wb0); - __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_wb0); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 811, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 811, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":464 - * - * # for htslib, wbu seems to not work - * if mode == "wbu": # <<<<<<<<<<<<<< - * mode = "wb0" + /* "pysam/libcalignmentfile.pyx":805 + * cdef bam_hdr_t * hdr = NULL * + * if threads > 1 and ignore_truncation: # <<<<<<<<<<<<<< + * # This won't raise errors if reaching a truncated alignment, + * # because bgzf_mt_reader in htslib does not deal with */ } - /* "pysam/libcalignmentfile.pyx":467 - * mode = "wb0" + /* "pysam/libcalignmentfile.pyx":812 + * # Better to avoid this (for now) than to produce seemingly correct results. + * raise ValueError('Cannot add extra threads when "ignore_truncation" is True') + * self.threads = threads # <<<<<<<<<<<<<< * - * self.mode = force_bytes(mode) # <<<<<<<<<<<<<< - * self.reference_filename = reference_filename = encode_filename( - * reference_filename) + * # for backwards compatibility: */ - __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_mode, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 467, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_v_self->__pyx_base.mode); - __Pyx_DECREF(__pyx_v_self->__pyx_base.mode); - __pyx_v_self->__pyx_base.mode = __pyx_t_5; - __pyx_t_5 = 0; + __Pyx_INCREF(__pyx_v_threads); + __Pyx_GIVEREF(__pyx_v_threads); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.threads); + __Pyx_DECREF(__pyx_v_self->__pyx_base.threads); + __pyx_v_self->__pyx_base.threads = __pyx_v_threads; - /* "pysam/libcalignmentfile.pyx":468 - * - * self.mode = force_bytes(mode) - * self.reference_filename = reference_filename = encode_filename( # <<<<<<<<<<<<<< - * reference_filename) + /* "pysam/libcalignmentfile.pyx":815 * + * # for backwards compatibility: + * if referencenames is not None: # <<<<<<<<<<<<<< + * reference_names = referencenames + * if referencelengths is not None: */ - __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_reference_filename); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 468, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_v_self->reference_filename); - __Pyx_DECREF(__pyx_v_self->reference_filename); - __pyx_v_self->reference_filename = __pyx_t_5; - __Pyx_INCREF(__pyx_t_5); - __Pyx_DECREF_SET(__pyx_v_reference_filename, __pyx_t_5); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_1 = (__pyx_v_referencenames != Py_None); + __pyx_t_3 = (__pyx_t_1 != 0); + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":473 - * cdef char * ctext - * cdef hFILE * fp - * ctext = NULL # <<<<<<<<<<<<<< - * - * if mode[0] == 'w': + /* "pysam/libcalignmentfile.pyx":816 + * # for backwards compatibility: + * if referencenames is not None: + * reference_names = referencenames # <<<<<<<<<<<<<< + * if referencelengths is not None: + * reference_lengths = referencelengths */ - __pyx_v_ctext = NULL; + __Pyx_INCREF(__pyx_v_referencenames); + __Pyx_DECREF_SET(__pyx_v_reference_names, __pyx_v_referencenames); - /* "pysam/libcalignmentfile.pyx":475 - * ctext = NULL - * - * if mode[0] == 'w': # <<<<<<<<<<<<<< - * # open file for writing + /* "pysam/libcalignmentfile.pyx":815 * + * # for backwards compatibility: + * if referencenames is not None: # <<<<<<<<<<<<<< + * reference_names = referencenames + * if referencelengths is not None: */ - __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 475, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_5, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 475, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_1) { + } - /* "pysam/libcalignmentfile.pyx":479 + /* "pysam/libcalignmentfile.pyx":817 + * if referencenames is not None: + * reference_names = referencenames + * if referencelengths is not None: # <<<<<<<<<<<<<< + * reference_lengths = referencelengths * - * # header structure (used for writing) - * if template: # <<<<<<<<<<<<<< - * self.header = bam_hdr_dup(template.header) - * elif header: */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 479, __pyx_L1_error) - if (__pyx_t_1) { - - /* "pysam/libcalignmentfile.pyx":480 - * # header structure (used for writing) - * if template: - * self.header = bam_hdr_dup(template.header) # <<<<<<<<<<<<<< - * elif header: - * self.header = build_header(header) - */ - __pyx_v_self->header = bam_hdr_dup(__pyx_v_template->header); + __pyx_t_3 = (__pyx_v_referencelengths != Py_None); + __pyx_t_1 = (__pyx_t_3 != 0); + if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":479 + /* "pysam/libcalignmentfile.pyx":818 + * reference_names = referencenames + * if referencelengths is not None: + * reference_lengths = referencelengths # <<<<<<<<<<<<<< * - * # header structure (used for writing) - * if template: # <<<<<<<<<<<<<< - * self.header = bam_hdr_dup(template.header) - * elif header: - */ - goto __pyx_L29; - } - - /* "pysam/libcalignmentfile.pyx":481 - * if template: - * self.header = bam_hdr_dup(template.header) - * elif header: # <<<<<<<<<<<<<< - * self.header = build_header(header) - * else: - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_header); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 481, __pyx_L1_error) - if (__pyx_t_1) { - - /* "pysam/libcalignmentfile.pyx":482 - * self.header = bam_hdr_dup(template.header) - * elif header: - * self.header = build_header(header) # <<<<<<<<<<<<<< - * else: - * # build header from a target names and lengths - */ - __pyx_v_self->header = __pyx_f_5pysam_17libcalignmentfile_build_header(__pyx_v_header); - - /* "pysam/libcalignmentfile.pyx":481 - * if template: - * self.header = bam_hdr_dup(template.header) - * elif header: # <<<<<<<<<<<<<< - * self.header = build_header(header) - * else: + * # close a previously opened file */ - goto __pyx_L29; - } + __Pyx_INCREF(__pyx_v_referencelengths); + __Pyx_DECREF_SET(__pyx_v_reference_lengths, __pyx_v_referencelengths); - /* "pysam/libcalignmentfile.pyx":485 - * else: - * # build header from a target names and lengths - * assert reference_names and reference_lengths, \ # <<<<<<<<<<<<<< - * ("either supply options `template`, `header` " - * "or both `reference_names` and `reference_lengths` " + /* "pysam/libcalignmentfile.pyx":817 + * if referencenames is not None: + * reference_names = referencenames + * if referencelengths is not None: # <<<<<<<<<<<<<< + * reference_lengths = referencelengths + * */ - /*else*/ { - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 485, __pyx_L1_error) - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L30_bool_binop_done; - } - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference_lengths); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 485, __pyx_L1_error) - __pyx_t_1 = __pyx_t_2; - __pyx_L30_bool_binop_done:; - if (unlikely(!__pyx_t_1)) { - PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_either_supply_options_template_h); - __PYX_ERR(0, 485, __pyx_L1_error) - } - } - #endif + } - /* "pysam/libcalignmentfile.pyx":489 - * "or both `reference_names` and `reference_lengths` " - * "for writing") - * assert len(reference_names) == len(reference_lengths), \ # <<<<<<<<<<<<<< - * "unequal names and lengths of reference sequences" + /* "pysam/libcalignmentfile.pyx":821 + * + * # close a previously opened file + * if self.is_open: # <<<<<<<<<<<<<< + * self.close() * */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - __pyx_t_11 = PyObject_Length(__pyx_v_reference_names); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 489, __pyx_L1_error) - __pyx_t_12 = PyObject_Length(__pyx_v_reference_lengths); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 489, __pyx_L1_error) - if (unlikely(!((__pyx_t_11 == __pyx_t_12) != 0))) { - PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_unequal_names_and_lengths_of_ref); - __PYX_ERR(0, 489, __pyx_L1_error) - } - } - #endif + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 821, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 821, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":493 + /* "pysam/libcalignmentfile.pyx":822 + * # close a previously opened file + * if self.is_open: + * self.close() # <<<<<<<<<<<<<< * - * # allocate and fill header - * reference_names = [force_bytes(ref) for ref in reference_names] # <<<<<<<<<<<<<< - * self.header = bam_hdr_init() - * self.header.n_targets = len(reference_names) + * # autodetection for read */ - __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 493, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (likely(PyList_CheckExact(__pyx_v_reference_names)) || PyTuple_CheckExact(__pyx_v_reference_names)) { - __pyx_t_4 = __pyx_v_reference_names; __Pyx_INCREF(__pyx_t_4); __pyx_t_12 = 0; - __pyx_t_13 = NULL; - } else { - __pyx_t_12 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_reference_names); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 493, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_13 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 493, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_13)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_12); __Pyx_INCREF(__pyx_t_3); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 493, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 493, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } else { - if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_12); __Pyx_INCREF(__pyx_t_3); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 493, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 493, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } - } else { - __pyx_t_3 = __pyx_t_13(__pyx_t_4); - if (unlikely(!__pyx_t_3)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 493, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF_SET(__pyx_v_ref, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_ref, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 493, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 493, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF_SET(__pyx_v_reference_names, __pyx_t_5); - __pyx_t_5 = 0; - - /* "pysam/libcalignmentfile.pyx":494 - * # allocate and fill header - * reference_names = [force_bytes(ref) for ref in reference_names] - * self.header = bam_hdr_init() # <<<<<<<<<<<<<< - * self.header.n_targets = len(reference_names) - * n = 0 - */ - __pyx_v_self->header = bam_hdr_init(); - - /* "pysam/libcalignmentfile.pyx":495 - * reference_names = [force_bytes(ref) for ref in reference_names] - * self.header = bam_hdr_init() - * self.header.n_targets = len(reference_names) # <<<<<<<<<<<<<< - * n = 0 - * for x in reference_names: - */ - __pyx_t_12 = PyObject_Length(__pyx_v_reference_names); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 495, __pyx_L1_error) - __pyx_v_self->header->n_targets = __pyx_t_12; - - /* "pysam/libcalignmentfile.pyx":496 - * self.header = bam_hdr_init() - * self.header.n_targets = len(reference_names) - * n = 0 # <<<<<<<<<<<<<< - * for x in reference_names: - * n += len(x) + 1 - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_n = __pyx_int_0; - - /* "pysam/libcalignmentfile.pyx":497 - * self.header.n_targets = len(reference_names) - * n = 0 - * for x in reference_names: # <<<<<<<<<<<<<< - * n += len(x) + 1 - * self.header.target_name = calloc(n, sizeof(char*)) - */ - if (likely(PyList_CheckExact(__pyx_v_reference_names)) || PyTuple_CheckExact(__pyx_v_reference_names)) { - __pyx_t_5 = __pyx_v_reference_names; __Pyx_INCREF(__pyx_t_5); __pyx_t_12 = 0; - __pyx_t_13 = NULL; - } else { - __pyx_t_12 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_reference_names); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 497, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_13 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 497, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 822, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); } - for (;;) { - if (likely(!__pyx_t_13)) { - if (likely(PyList_CheckExact(__pyx_t_5))) { - if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_5)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_12); __Pyx_INCREF(__pyx_t_4); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 497, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 497, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_5)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_12); __Pyx_INCREF(__pyx_t_4); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 497, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 497, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_13(__pyx_t_5); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 497, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_4); - __pyx_t_4 = 0; + } + if (__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 822, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 822, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":498 - * n = 0 - * for x in reference_names: - * n += len(x) + 1 # <<<<<<<<<<<<<< - * self.header.target_name = calloc(n, sizeof(char*)) - * self.header.target_len = calloc(n, sizeof(uint32_t)) + /* "pysam/libcalignmentfile.pyx":821 + * + * # close a previously opened file + * if self.is_open: # <<<<<<<<<<<<<< + * self.close() + * */ - __pyx_t_11 = PyObject_Length(__pyx_v_x); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 498, __pyx_L1_error) - __pyx_t_4 = PyInt_FromSsize_t((__pyx_t_11 + 1)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 498, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_n, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 498, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF_SET(__pyx_v_n, __pyx_t_3); - __pyx_t_3 = 0; + } - /* "pysam/libcalignmentfile.pyx":497 - * self.header.n_targets = len(reference_names) - * n = 0 - * for x in reference_names: # <<<<<<<<<<<<<< - * n += len(x) + 1 - * self.header.target_name = calloc(n, sizeof(char*)) + /* "pysam/libcalignmentfile.pyx":825 + * + * # autodetection for read + * if mode is None: # <<<<<<<<<<<<<< + * mode = "r" + * */ - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "pysam/libcalignmentfile.pyx":499 - * for x in reference_names: - * n += len(x) + 1 - * self.header.target_name = calloc(n, sizeof(char*)) # <<<<<<<<<<<<<< - * self.header.target_len = calloc(n, sizeof(uint32_t)) - * for x from 0 <= x < self.header.n_targets: - */ - __pyx_t_14 = __Pyx_PyInt_As_size_t(__pyx_v_n); if (unlikely((__pyx_t_14 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 499, __pyx_L1_error) - __pyx_v_self->header->target_name = ((char **)calloc(__pyx_t_14, (sizeof(char *)))); - - /* "pysam/libcalignmentfile.pyx":500 - * n += len(x) + 1 - * self.header.target_name = calloc(n, sizeof(char*)) - * self.header.target_len = calloc(n, sizeof(uint32_t)) # <<<<<<<<<<<<<< - * for x from 0 <= x < self.header.n_targets: - * self.header.target_len[x] = reference_lengths[x] - */ - __pyx_t_14 = __Pyx_PyInt_As_size_t(__pyx_v_n); if (unlikely((__pyx_t_14 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 500, __pyx_L1_error) - __pyx_v_self->header->target_len = ((uint32_t *)calloc(__pyx_t_14, (sizeof(uint32_t)))); - - /* "pysam/libcalignmentfile.pyx":501 - * self.header.target_name = calloc(n, sizeof(char*)) - * self.header.target_len = calloc(n, sizeof(uint32_t)) - * for x from 0 <= x < self.header.n_targets: # <<<<<<<<<<<<<< - * self.header.target_len[x] = reference_lengths[x] - * name = reference_names[x] - */ - __pyx_t_15 = __pyx_v_self->header->n_targets; - for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16++) { - __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_5); - __pyx_t_5 = 0; + __pyx_t_1 = (__pyx_v_mode == Py_None); + __pyx_t_3 = (__pyx_t_1 != 0); + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":502 - * self.header.target_len = calloc(n, sizeof(uint32_t)) - * for x from 0 <= x < self.header.n_targets: - * self.header.target_len[x] = reference_lengths[x] # <<<<<<<<<<<<<< - * name = reference_names[x] - * self.header.target_name[x] = calloc( + /* "pysam/libcalignmentfile.pyx":826 + * # autodetection for read + * if mode is None: + * mode = "r" # <<<<<<<<<<<<<< + * + * if add_sam_header and mode == "w": */ - __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_reference_lengths, __pyx_v_x); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_17 = __Pyx_PyInt_As_uint32_t(__pyx_t_5); if (unlikely((__pyx_t_17 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 502, __pyx_L1_error) - (__pyx_v_self->header->target_len[__pyx_t_12]) = __pyx_t_17; + __Pyx_INCREF(__pyx_n_s_r); + __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_r); - /* "pysam/libcalignmentfile.pyx":503 - * for x from 0 <= x < self.header.n_targets: - * self.header.target_len[x] = reference_lengths[x] - * name = reference_names[x] # <<<<<<<<<<<<<< - * self.header.target_name[x] = calloc( - * len(name) + 1, sizeof(char)) + /* "pysam/libcalignmentfile.pyx":825 + * + * # autodetection for read + * if mode is None: # <<<<<<<<<<<<<< + * mode = "r" + * */ - __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_reference_names, __pyx_v_x); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_5); - __pyx_t_5 = 0; + } - /* "pysam/libcalignmentfile.pyx":505 - * name = reference_names[x] - * self.header.target_name[x] = calloc( - * len(name) + 1, sizeof(char)) # <<<<<<<<<<<<<< - * strncpy(self.header.target_name[x], name, len(name)) + /* "pysam/libcalignmentfile.pyx":828 + * mode = "r" + * + * if add_sam_header and mode == "w": # <<<<<<<<<<<<<< + * mode = "wh" * */ - __pyx_t_12 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 505, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_add_sam_header); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 828, __pyx_L1_error) + if (__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L11_bool_binop_done; + } + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 828, __pyx_L1_error) + __pyx_t_3 = __pyx_t_1; + __pyx_L11_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":504 - * self.header.target_len[x] = reference_lengths[x] - * name = reference_names[x] - * self.header.target_name[x] = calloc( # <<<<<<<<<<<<<< - * len(name) + 1, sizeof(char)) - * strncpy(self.header.target_name[x], name, len(name)) + /* "pysam/libcalignmentfile.pyx":829 + * + * if add_sam_header and mode == "w": + * mode = "wh" # <<<<<<<<<<<<<< + * + * assert mode in ("r", "w", "rb", "wb", "wh", */ - __pyx_t_11 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_11 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 504, __pyx_L1_error) - (__pyx_v_self->header->target_name[__pyx_t_11]) = ((char *)calloc((__pyx_t_12 + 1), (sizeof(char)))); + __Pyx_INCREF(__pyx_n_s_wh); + __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_wh); - /* "pysam/libcalignmentfile.pyx":506 - * self.header.target_name[x] = calloc( - * len(name) + 1, sizeof(char)) - * strncpy(self.header.target_name[x], name, len(name)) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":828 + * mode = "r" + * + * if add_sam_header and mode == "w": # <<<<<<<<<<<<<< + * mode = "wh" * - * # Optionally, if there is no text, add a SAM */ - __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 506, __pyx_L1_error) - __pyx_t_18 = __Pyx_PyObject_AsString(__pyx_v_name); if (unlikely((!__pyx_t_18) && PyErr_Occurred())) __PYX_ERR(0, 506, __pyx_L1_error) - __pyx_t_11 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 506, __pyx_L1_error) - (void)(strncpy((__pyx_v_self->header->target_name[__pyx_t_12]), __pyx_t_18, __pyx_t_11)); - __pyx_t_16 = __Pyx_PyInt_As_long(__pyx_v_x); if (unlikely((__pyx_t_16 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 501, __pyx_L1_error) - } + } - /* "pysam/libcalignmentfile.pyx":501 - * self.header.target_name = calloc(n, sizeof(char*)) - * self.header.target_len = calloc(n, sizeof(uint32_t)) - * for x from 0 <= x < self.header.n_targets: # <<<<<<<<<<<<<< - * self.header.target_len[x] = reference_lengths[x] - * name = reference_names[x] + /* "pysam/libcalignmentfile.pyx":831 + * mode = "wh" + * + * assert mode in ("r", "w", "rb", "wb", "wh", # <<<<<<<<<<<<<< + * "wbu", "rU", "wb0", + * "rc", "wc"), \ */ - __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_5); - __pyx_t_5 = 0; + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + __Pyx_INCREF(__pyx_v_mode); + __pyx_t_2 = __pyx_v_mode; + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_r, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 831, __pyx_L1_error) + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 831, __pyx_L1_error) + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_rb, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 831, __pyx_L1_error) + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_wb, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 831, __pyx_L1_error) + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_wh, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 831, __pyx_L1_error) + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_wbu, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 831, __pyx_L1_error) + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_rU, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 831, __pyx_L1_error) + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_wb0, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 831, __pyx_L1_error) + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_rc, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 831, __pyx_L1_error) + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_wc, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 831, __pyx_L1_error) + __pyx_t_3 = __pyx_t_1; + __pyx_L13_bool_binop_done:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!(__pyx_t_3 != 0))) { - /* "pysam/libcalignmentfile.pyx":510 - * # Optionally, if there is no text, add a SAM - * # compatible header to output file. - * if text is None and add_sq_text: # <<<<<<<<<<<<<< - * text = [] - * for x from 0 <= x < self.header.n_targets: + /* "pysam/libcalignmentfile.pyx":834 + * "wbu", "rU", "wb0", + * "rc", "wc"), \ + * "invalid file opening mode `%s`" % mode # <<<<<<<<<<<<<< + * + * self.duplicate_filehandle = duplicate_filehandle */ - __pyx_t_2 = (__pyx_v_text == Py_None); - __pyx_t_19 = (__pyx_t_2 != 0); - if (__pyx_t_19) { - } else { - __pyx_t_1 = __pyx_t_19; - goto __pyx_L39_bool_binop_done; - } - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_add_sq_text); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 510, __pyx_L1_error) - __pyx_t_1 = __pyx_t_19; - __pyx_L39_bool_binop_done:; - if (__pyx_t_1) { + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_invalid_file_opening_mode_s, __pyx_v_mode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 834, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + PyErr_SetObject(PyExc_AssertionError, __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 831, __pyx_L1_error) + } + } + #endif - /* "pysam/libcalignmentfile.pyx":511 - * # compatible header to output file. - * if text is None and add_sq_text: - * text = [] # <<<<<<<<<<<<<< - * for x from 0 <= x < self.header.n_targets: - * text.append("@SQ\tSN:%s\tLN:%s\n" % \ + /* "pysam/libcalignmentfile.pyx":836 + * "invalid file opening mode `%s`" % mode + * + * self.duplicate_filehandle = duplicate_filehandle # <<<<<<<<<<<<<< + * + * # StringIO not supported */ - __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 511, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_5); - __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_duplicate_filehandle); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 836, __pyx_L1_error) + __pyx_v_self->__pyx_base.duplicate_filehandle = __pyx_t_3; - /* "pysam/libcalignmentfile.pyx":512 - * if text is None and add_sq_text: - * text = [] - * for x from 0 <= x < self.header.n_targets: # <<<<<<<<<<<<<< - * text.append("@SQ\tSN:%s\tLN:%s\n" % \ - * (force_str(reference_names[x]), + /* "pysam/libcalignmentfile.pyx":839 + * + * # StringIO not supported + * if isinstance(filepath_or_object, StringIO): # <<<<<<<<<<<<<< + * raise NotImplementedError( + * "access from StringIO objects not supported") */ - __pyx_t_15 = __pyx_v_self->header->n_targets; - for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16++) { - __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_5); - __pyx_t_5 = 0; + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_StringIO); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 839, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_IsInstance(__pyx_v_filepath_or_object, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 839, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = (__pyx_t_3 != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":514 - * for x from 0 <= x < self.header.n_targets: - * text.append("@SQ\tSN:%s\tLN:%s\n" % \ - * (force_str(reference_names[x]), # <<<<<<<<<<<<<< - * reference_lengths[x])) - * text = ''.join(text) + /* "pysam/libcalignmentfile.pyx":840 + * # StringIO not supported + * if isinstance(filepath_or_object, StringIO): + * raise NotImplementedError( # <<<<<<<<<<<<<< + * "access from StringIO objects not supported") + * # reading from a file descriptor */ - __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_reference_names, __pyx_v_x); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 514, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 514, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 840, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 840, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":515 - * text.append("@SQ\tSN:%s\tLN:%s\n" % \ - * (force_str(reference_names[x]), - * reference_lengths[x])) # <<<<<<<<<<<<<< - * text = ''.join(text) + /* "pysam/libcalignmentfile.pyx":839 * + * # StringIO not supported + * if isinstance(filepath_or_object, StringIO): # <<<<<<<<<<<<<< + * raise NotImplementedError( + * "access from StringIO objects not supported") */ - __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_reference_lengths, __pyx_v_x); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 515, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + } - /* "pysam/libcalignmentfile.pyx":514 - * for x from 0 <= x < self.header.n_targets: - * text.append("@SQ\tSN:%s\tLN:%s\n" % \ - * (force_str(reference_names[x]), # <<<<<<<<<<<<<< - * reference_lengths[x])) - * text = ''.join(text) + /* "pysam/libcalignmentfile.pyx":843 + * "access from StringIO objects not supported") + * # reading from a file descriptor + * elif isinstance(filepath_or_object, int): # <<<<<<<<<<<<<< + * self.filename = filepath_or_object + * filename = None */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 514, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5); - __pyx_t_3 = 0; - __pyx_t_5 = 0; + __pyx_t_1 = PyInt_Check(__pyx_v_filepath_or_object); + __pyx_t_3 = (__pyx_t_1 != 0); + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":513 - * text = [] - * for x from 0 <= x < self.header.n_targets: - * text.append("@SQ\tSN:%s\tLN:%s\n" % \ # <<<<<<<<<<<<<< - * (force_str(reference_names[x]), - * reference_lengths[x])) + /* "pysam/libcalignmentfile.pyx":844 + * # reading from a file descriptor + * elif isinstance(filepath_or_object, int): + * self.filename = filepath_or_object # <<<<<<<<<<<<<< + * filename = None + * self.is_remote = False */ - __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_SQ_SN_s_LN_s, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 513, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_20 = __Pyx_PyObject_Append(__pyx_v_text, __pyx_t_5); if (unlikely(__pyx_t_20 == ((int)-1))) __PYX_ERR(0, 513, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_16 = __Pyx_PyInt_As_long(__pyx_v_x); if (unlikely((__pyx_t_16 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 512, __pyx_L1_error) - } + __Pyx_INCREF(__pyx_v_filepath_or_object); + __Pyx_GIVEREF(__pyx_v_filepath_or_object); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename); + __Pyx_DECREF(__pyx_v_self->__pyx_base.filename); + __pyx_v_self->__pyx_base.filename = __pyx_v_filepath_or_object; - /* "pysam/libcalignmentfile.pyx":512 - * if text is None and add_sq_text: - * text = [] - * for x from 0 <= x < self.header.n_targets: # <<<<<<<<<<<<<< - * text.append("@SQ\tSN:%s\tLN:%s\n" % \ - * (force_str(reference_names[x]), + /* "pysam/libcalignmentfile.pyx":845 + * elif isinstance(filepath_or_object, int): + * self.filename = filepath_or_object + * filename = None # <<<<<<<<<<<<<< + * self.is_remote = False + * self.is_stream = True */ - __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_5); - __pyx_t_5 = 0; + __Pyx_INCREF(Py_None); + __pyx_v_filename = ((PyObject*)Py_None); - /* "pysam/libcalignmentfile.pyx":516 - * (force_str(reference_names[x]), - * reference_lengths[x])) - * text = ''.join(text) # <<<<<<<<<<<<<< - * - * if text is not None: + /* "pysam/libcalignmentfile.pyx":846 + * self.filename = filepath_or_object + * filename = None + * self.is_remote = False # <<<<<<<<<<<<<< + * self.is_stream = True + * # reading from a File object or other object with fileno */ - __pyx_t_5 = __Pyx_PyString_Join(__pyx_kp_s__12, __pyx_v_text); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 516, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_5); - __pyx_t_5 = 0; + __pyx_v_self->__pyx_base.is_remote = 0; - /* "pysam/libcalignmentfile.pyx":510 - * # Optionally, if there is no text, add a SAM - * # compatible header to output file. - * if text is None and add_sq_text: # <<<<<<<<<<<<<< - * text = [] - * for x from 0 <= x < self.header.n_targets: + /* "pysam/libcalignmentfile.pyx":847 + * filename = None + * self.is_remote = False + * self.is_stream = True # <<<<<<<<<<<<<< + * # reading from a File object or other object with fileno + * elif hasattr(filepath_or_object, "fileno"): */ - } + __pyx_v_self->__pyx_base.is_stream = 1; - /* "pysam/libcalignmentfile.pyx":518 - * text = ''.join(text) - * - * if text is not None: # <<<<<<<<<<<<<< - * # copy without \0 - * text = force_bytes(text) + /* "pysam/libcalignmentfile.pyx":843 + * "access from StringIO objects not supported") + * # reading from a file descriptor + * elif isinstance(filepath_or_object, int): # <<<<<<<<<<<<<< + * self.filename = filepath_or_object + * filename = None */ - __pyx_t_1 = (__pyx_v_text != Py_None); - __pyx_t_19 = (__pyx_t_1 != 0); - if (__pyx_t_19) { + goto __pyx_L23; + } - /* "pysam/libcalignmentfile.pyx":520 - * if text is not None: - * # copy without \0 - * text = force_bytes(text) # <<<<<<<<<<<<<< - * ctext = text - * self.header.l_text = strlen(ctext) + /* "pysam/libcalignmentfile.pyx":849 + * self.is_stream = True + * # reading from a File object or other object with fileno + * elif hasattr(filepath_or_object, "fileno"): # <<<<<<<<<<<<<< + * if filepath_or_object.closed: + * raise ValueError('I/O operation on closed file') */ - __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_text, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 520, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_5); - __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_HasAttr(__pyx_v_filepath_or_object, __pyx_n_s_fileno); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 849, __pyx_L1_error) + __pyx_t_1 = (__pyx_t_3 != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignmentfile.pyx":850 + * # reading from a File object or other object with fileno + * elif hasattr(filepath_or_object, "fileno"): + * if filepath_or_object.closed: # <<<<<<<<<<<<<< + * raise ValueError('I/O operation on closed file') + * self.filename = filepath_or_object + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_filepath_or_object, __pyx_n_s_closed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 850, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 850, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcalignmentfile.pyx":851 + * elif hasattr(filepath_or_object, "fileno"): + * if filepath_or_object.closed: + * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< + * self.filename = filepath_or_object + * # .name can be TextIOWrapper + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 851, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 851, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":850 + * # reading from a File object or other object with fileno + * elif hasattr(filepath_or_object, "fileno"): + * if filepath_or_object.closed: # <<<<<<<<<<<<<< + * raise ValueError('I/O operation on closed file') + * self.filename = filepath_or_object + */ + } + + /* "pysam/libcalignmentfile.pyx":852 + * if filepath_or_object.closed: + * raise ValueError('I/O operation on closed file') + * self.filename = filepath_or_object # <<<<<<<<<<<<<< + * # .name can be TextIOWrapper + * try: + */ + __Pyx_INCREF(__pyx_v_filepath_or_object); + __Pyx_GIVEREF(__pyx_v_filepath_or_object); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename); + __Pyx_DECREF(__pyx_v_self->__pyx_base.filename); + __pyx_v_self->__pyx_base.filename = __pyx_v_filepath_or_object; + + /* "pysam/libcalignmentfile.pyx":854 + * self.filename = filepath_or_object + * # .name can be TextIOWrapper + * try: # <<<<<<<<<<<<<< + * filename = encode_filename(str(filepath_or_object.name)) + * cfilename = filename + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_8); + /*try:*/ { - /* "pysam/libcalignmentfile.pyx":521 - * # copy without \0 - * text = force_bytes(text) - * ctext = text # <<<<<<<<<<<<<< - * self.header.l_text = strlen(ctext) - * self.header.text = calloc( + /* "pysam/libcalignmentfile.pyx":855 + * # .name can be TextIOWrapper + * try: + * filename = encode_filename(str(filepath_or_object.name)) # <<<<<<<<<<<<<< + * cfilename = filename + * except AttributeError: */ - __pyx_t_9 = __Pyx_PyObject_AsWritableString(__pyx_v_text); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 521, __pyx_L1_error) - __pyx_v_ctext = __pyx_t_9; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_filepath_or_object, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 855, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 855, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 855, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_filename = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":522 - * text = force_bytes(text) - * ctext = text - * self.header.l_text = strlen(ctext) # <<<<<<<<<<<<<< - * self.header.text = calloc( - * strlen(ctext), sizeof(char)) + /* "pysam/libcalignmentfile.pyx":856 + * try: + * filename = encode_filename(str(filepath_or_object.name)) + * cfilename = filename # <<<<<<<<<<<<<< + * except AttributeError: + * filename = None */ - __pyx_v_self->header->l_text = strlen(__pyx_v_ctext); + if (unlikely(__pyx_v_filename == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 856, __pyx_L25_error) + } + __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_v_filename); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 856, __pyx_L25_error) + __pyx_v_cfilename = __pyx_t_9; - /* "pysam/libcalignmentfile.pyx":523 - * ctext = text - * self.header.l_text = strlen(ctext) - * self.header.text = calloc( # <<<<<<<<<<<<<< - * strlen(ctext), sizeof(char)) - * memcpy(self.header.text, ctext, strlen(ctext)) + /* "pysam/libcalignmentfile.pyx":854 + * self.filename = filepath_or_object + * # .name can be TextIOWrapper + * try: # <<<<<<<<<<<<<< + * filename = encode_filename(str(filepath_or_object.name)) + * cfilename = filename */ - __pyx_v_self->header->text = ((char *)calloc(strlen(__pyx_v_ctext), (sizeof(char)))); + } + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L30_try_end; + __pyx_L25_error:; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":525 - * self.header.text = calloc( - * strlen(ctext), sizeof(char)) - * memcpy(self.header.text, ctext, strlen(ctext)) # <<<<<<<<<<<<<< - * - * self.htsfile = self._open_htsfile() + /* "pysam/libcalignmentfile.pyx":857 + * filename = encode_filename(str(filepath_or_object.name)) + * cfilename = filename + * except AttributeError: # <<<<<<<<<<<<<< + * filename = None + * self.is_remote = False */ - (void)(memcpy(__pyx_v_self->header->text, __pyx_v_ctext, strlen(__pyx_v_ctext))); + __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError); + if (__pyx_t_10) { + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 857, __pyx_L27_except_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_5); - /* "pysam/libcalignmentfile.pyx":518 - * text = ''.join(text) - * - * if text is not None: # <<<<<<<<<<<<<< - * # copy without \0 - * text = force_bytes(text) + /* "pysam/libcalignmentfile.pyx":858 + * cfilename = filename + * except AttributeError: + * filename = None # <<<<<<<<<<<<<< + * self.is_remote = False + * self.is_stream = True */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_filename, ((PyObject*)Py_None)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L26_exception_handled; } - } - __pyx_L29:; + goto __pyx_L27_except_error; + __pyx_L27_except_error:; - /* "pysam/libcalignmentfile.pyx":527 - * memcpy(self.header.text, ctext, strlen(ctext)) - * - * self.htsfile = self._open_htsfile() # <<<<<<<<<<<<<< - * - * # set filename with reference sequences. If no filename - */ - __pyx_t_21 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_21 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 527, __pyx_L1_error) - __pyx_v_self->__pyx_base.htsfile = __pyx_t_21; - - /* "pysam/libcalignmentfile.pyx":532 - * # is given, the CRAM reference arrays will be built from - * # the @SQ header in the header - * if "c" in mode and reference_filename: # <<<<<<<<<<<<<< - * # note that fn_aux takes ownership, so create a copy - * self.htsfile.fn_aux = strdup(self.reference_filename) + /* "pysam/libcalignmentfile.pyx":854 + * self.filename = filepath_or_object + * # .name can be TextIOWrapper + * try: # <<<<<<<<<<<<<< + * filename = encode_filename(str(filepath_or_object.name)) + * cfilename = filename */ - __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_c, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 532, __pyx_L1_error) - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - } else { - __pyx_t_19 = __pyx_t_2; - goto __pyx_L45_bool_binop_done; + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8); + goto __pyx_L1_error; + __pyx_L26_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8); + __pyx_L30_try_end:; } - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference_filename); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 532, __pyx_L1_error) - __pyx_t_19 = __pyx_t_2; - __pyx_L45_bool_binop_done:; - if (__pyx_t_19) { - /* "pysam/libcalignmentfile.pyx":534 - * if "c" in mode and reference_filename: - * # note that fn_aux takes ownership, so create a copy - * self.htsfile.fn_aux = strdup(self.reference_filename) # <<<<<<<<<<<<<< - * - * # write header to htsfile + /* "pysam/libcalignmentfile.pyx":859 + * except AttributeError: + * filename = None + * self.is_remote = False # <<<<<<<<<<<<<< + * self.is_stream = True + * # what remains is a filename */ - __pyx_t_22 = __Pyx_PyObject_AsString(__pyx_v_self->reference_filename); if (unlikely((!__pyx_t_22) && PyErr_Occurred())) __PYX_ERR(0, 534, __pyx_L1_error) - __pyx_v_self->__pyx_base.htsfile->fn_aux = strdup(__pyx_t_22); + __pyx_v_self->__pyx_base.is_remote = 0; - /* "pysam/libcalignmentfile.pyx":532 - * # is given, the CRAM reference arrays will be built from - * # the @SQ header in the header - * if "c" in mode and reference_filename: # <<<<<<<<<<<<<< - * # note that fn_aux takes ownership, so create a copy - * self.htsfile.fn_aux = strdup(self.reference_filename) + /* "pysam/libcalignmentfile.pyx":860 + * filename = None + * self.is_remote = False + * self.is_stream = True # <<<<<<<<<<<<<< + * # what remains is a filename + * else: */ - } + __pyx_v_self->__pyx_base.is_stream = 1; - /* "pysam/libcalignmentfile.pyx":537 - * - * # write header to htsfile - * if "b" in mode or "c" in mode or "h" in mode: # <<<<<<<<<<<<<< - * with nogil: - * sam_hdr_write(self.htsfile, self.header) + /* "pysam/libcalignmentfile.pyx":849 + * self.is_stream = True + * # reading from a File object or other object with fileno + * elif hasattr(filepath_or_object, "fileno"): # <<<<<<<<<<<<<< + * if filepath_or_object.closed: + * raise ValueError('I/O operation on closed file') */ - __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_b, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 537, __pyx_L1_error) - __pyx_t_1 = (__pyx_t_2 != 0); - if (!__pyx_t_1) { - } else { - __pyx_t_19 = __pyx_t_1; - goto __pyx_L48_bool_binop_done; - } - __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_c, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 537, __pyx_L1_error) - __pyx_t_2 = (__pyx_t_1 != 0); - if (!__pyx_t_2) { - } else { - __pyx_t_19 = __pyx_t_2; - goto __pyx_L48_bool_binop_done; - } - __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_h, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 537, __pyx_L1_error) - __pyx_t_1 = (__pyx_t_2 != 0); - __pyx_t_19 = __pyx_t_1; - __pyx_L48_bool_binop_done:; - if (__pyx_t_19) { + goto __pyx_L23; + } - /* "pysam/libcalignmentfile.pyx":538 - * # write header to htsfile - * if "b" in mode or "c" in mode or "h" in mode: - * with nogil: # <<<<<<<<<<<<<< - * sam_hdr_write(self.htsfile, self.header) - * + /* "pysam/libcalignmentfile.pyx":863 + * # what remains is a filename + * else: + * self.filename = filename = encode_filename(filepath_or_object) # <<<<<<<<<<<<<< + * cfilename = filename + * self.is_remote = hisremote(cfilename) */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + /*else*/ { + __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filepath_or_object); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 863, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename); + __Pyx_DECREF(__pyx_v_self->__pyx_base.filename); + __pyx_v_self->__pyx_base.filename = __pyx_t_5; + __Pyx_INCREF(__pyx_t_5); + __pyx_v_filename = ((PyObject*)__pyx_t_5); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":539 - * if "b" in mode or "c" in mode or "h" in mode: - * with nogil: - * sam_hdr_write(self.htsfile, self.header) # <<<<<<<<<<<<<< - * - * elif mode[0] == "r": + /* "pysam/libcalignmentfile.pyx":864 + * else: + * self.filename = filename = encode_filename(filepath_or_object) + * cfilename = filename # <<<<<<<<<<<<<< + * self.is_remote = hisremote(cfilename) + * self.is_stream = self.filename == b'-' */ - (void)(sam_hdr_write(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->header)); - } + if (unlikely(__pyx_v_filename == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 864, __pyx_L1_error) + } + __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_v_filename); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 864, __pyx_L1_error) + __pyx_v_cfilename = __pyx_t_9; - /* "pysam/libcalignmentfile.pyx":538 - * # write header to htsfile - * if "b" in mode or "c" in mode or "h" in mode: - * with nogil: # <<<<<<<<<<<<<< - * sam_hdr_write(self.htsfile, self.header) + /* "pysam/libcalignmentfile.pyx":865 + * self.filename = filename = encode_filename(filepath_or_object) + * cfilename = filename + * self.is_remote = hisremote(cfilename) # <<<<<<<<<<<<<< + * self.is_stream = self.filename == b'-' * */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L53; - } - __pyx_L53:; - } - } + __pyx_v_self->__pyx_base.is_remote = hisremote(__pyx_v_cfilename); - /* "pysam/libcalignmentfile.pyx":537 + /* "pysam/libcalignmentfile.pyx":866 + * cfilename = filename + * self.is_remote = hisremote(cfilename) + * self.is_stream = self.filename == b'-' # <<<<<<<<<<<<<< * - * # write header to htsfile - * if "b" in mode or "c" in mode or "h" in mode: # <<<<<<<<<<<<<< - * with nogil: - * sam_hdr_write(self.htsfile, self.header) + * # for htslib, wbu seems to not work */ - } + __pyx_t_5 = PyObject_RichCompare(__pyx_v_self->__pyx_base.filename, __pyx_kp_b__32, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 866, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 866, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_self->__pyx_base.is_stream = __pyx_t_1; + } + __pyx_L23:; - /* "pysam/libcalignmentfile.pyx":475 - * ctext = NULL + /* "pysam/libcalignmentfile.pyx":869 * - * if mode[0] == 'w': # <<<<<<<<<<<<<< - * # open file for writing + * # for htslib, wbu seems to not work + * if mode == "wbu": # <<<<<<<<<<<<<< + * mode = "wb0" * */ - goto __pyx_L28; - } + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_wbu, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 869, __pyx_L1_error) + if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":541 - * sam_hdr_write(self.htsfile, self.header) + /* "pysam/libcalignmentfile.pyx":870 + * # for htslib, wbu seems to not work + * if mode == "wbu": + * mode = "wb0" # <<<<<<<<<<<<<< * - * elif mode[0] == "r": # <<<<<<<<<<<<<< - * # open file for reading - * if not self._exists(): + * self.mode = force_bytes(mode) */ - __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 541, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_t_5, __pyx_n_s_r, Py_EQ)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 541, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_19) { + __Pyx_INCREF(__pyx_n_s_wb0); + __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_wb0); - /* "pysam/libcalignmentfile.pyx":543 - * elif mode[0] == "r": - * # open file for reading - * if not self._exists(): # <<<<<<<<<<<<<< - * raise IOError("file `%s` not found" % self.filename) + /* "pysam/libcalignmentfile.pyx":869 * - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_exists); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 543, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (__pyx_t_3) { - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 543, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 543, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 543, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_1 = ((!__pyx_t_19) != 0); - if (unlikely(__pyx_t_1)) { - - /* "pysam/libcalignmentfile.pyx":544 - * # open file for reading - * if not self._exists(): - * raise IOError("file `%s` not found" % self.filename) # <<<<<<<<<<<<<< + * # for htslib, wbu seems to not work + * if mode == "wbu": # <<<<<<<<<<<<<< + * mode = "wb0" * - * self.htsfile = self._open_htsfile() - */ - __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_file_s_not_found, __pyx_v_self->__pyx_base.filename); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 544, __pyx_L1_error) + */ + } - /* "pysam/libcalignmentfile.pyx":543 - * elif mode[0] == "r": - * # open file for reading - * if not self._exists(): # <<<<<<<<<<<<<< - * raise IOError("file `%s` not found" % self.filename) + /* "pysam/libcalignmentfile.pyx":872 + * mode = "wb0" * + * self.mode = force_bytes(mode) # <<<<<<<<<<<<<< + * self.reference_filename = reference_filename = encode_filename( + * reference_filename) */ - } + __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_mode, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 872, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.mode); + __Pyx_DECREF(__pyx_v_self->__pyx_base.mode); + __pyx_v_self->__pyx_base.mode = __pyx_t_5; + __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":546 - * raise IOError("file `%s` not found" % self.filename) + /* "pysam/libcalignmentfile.pyx":873 * - * self.htsfile = self._open_htsfile() # <<<<<<<<<<<<<< + * self.mode = force_bytes(mode) + * self.reference_filename = reference_filename = encode_filename( # <<<<<<<<<<<<<< + * reference_filename) * - * if self.htsfile == NULL: */ - __pyx_t_21 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_21 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 546, __pyx_L1_error) - __pyx_v_self->__pyx_base.htsfile = __pyx_t_21; + __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_reference_filename); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 873, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->reference_filename); + __Pyx_DECREF(__pyx_v_self->reference_filename); + __pyx_v_self->reference_filename = __pyx_t_5; + __Pyx_INCREF(__pyx_t_5); + __Pyx_DECREF_SET(__pyx_v_reference_filename, __pyx_t_5); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":548 - * self.htsfile = self._open_htsfile() + /* "pysam/libcalignmentfile.pyx":876 + * reference_filename) + * + * if mode[0] == 'w': # <<<<<<<<<<<<<< + * # open file for writing * - * if self.htsfile == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "could not open file (mode='%s') - " */ - __pyx_t_1 = ((__pyx_v_self->__pyx_base.htsfile == NULL) != 0); - if (unlikely(__pyx_t_1)) { + __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 876, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_5, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 876, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":551 - * raise ValueError( - * "could not open file (mode='%s') - " - * "is it SAM/BAM format?" % mode) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":879 + * # open file for writing * - * if self.htsfile.format.category != sequence_data: + * if not (template or header or reference_names): # <<<<<<<<<<<<<< + * raise ValueError( + * "either supply options `template`, `header` or both `reference_names` " */ - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_file_mode_s_is_it, __pyx_v_mode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 551, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 879, __pyx_L1_error) + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L36_bool_binop_done; + } + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_header); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 879, __pyx_L1_error) + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L36_bool_binop_done; + } + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 879, __pyx_L1_error) + __pyx_t_1 = __pyx_t_3; + __pyx_L36_bool_binop_done:; + __pyx_t_3 = ((!__pyx_t_1) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":549 + /* "pysam/libcalignmentfile.pyx":880 * - * if self.htsfile == NULL: + * if not (template or header or reference_names): * raise ValueError( # <<<<<<<<<<<<<< - * "could not open file (mode='%s') - " - * "is it SAM/BAM format?" % mode) + * "either supply options `template`, `header` or both `reference_names` " + * "and `reference_lengths` for writing") */ - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 549, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 880, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 549, __pyx_L1_error) + __PYX_ERR(0, 880, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":548 - * self.htsfile = self._open_htsfile() + /* "pysam/libcalignmentfile.pyx":879 + * # open file for writing * - * if self.htsfile == NULL: # <<<<<<<<<<<<<< + * if not (template or header or reference_names): # <<<<<<<<<<<<<< * raise ValueError( - * "could not open file (mode='%s') - " + * "either supply options `template`, `header` or both `reference_names` " */ } - /* "pysam/libcalignmentfile.pyx":553 - * "is it SAM/BAM format?" % mode) - * - * if self.htsfile.format.category != sequence_data: # <<<<<<<<<<<<<< - * raise ValueError("file does not contain alignment data") + /* "pysam/libcalignmentfile.pyx":884 + * "and `reference_lengths` for writing") * + * if template: # <<<<<<<<<<<<<< + * # header is copied, though at the moment not strictly + * # necessary as AlignmentHeader is immutable. */ - __pyx_t_1 = ((__pyx_v_self->__pyx_base.htsfile->format.category != sequence_data) != 0); - if (unlikely(__pyx_t_1)) { + __pyx_t_3 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 884, __pyx_L1_error) + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":554 - * - * if self.htsfile.format.category != sequence_data: - * raise ValueError("file does not contain alignment data") # <<<<<<<<<<<<<< - * - * # bam files require a valid header + /* "pysam/libcalignmentfile.pyx":887 + * # header is copied, though at the moment not strictly + * # necessary as AlignmentHeader is immutable. + * self.header = template.header.copy() # <<<<<<<<<<<<<< + * elif isinstance(header, AlignmentHeader): + * self.header = header.copy() */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 554, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_template->header), __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (__pyx_t_2) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 887, __pyx_L1_error) + } __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 554, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5); + __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":553 - * "is it SAM/BAM format?" % mode) - * - * if self.htsfile.format.category != sequence_data: # <<<<<<<<<<<<<< - * raise ValueError("file does not contain alignment data") + /* "pysam/libcalignmentfile.pyx":884 + * "and `reference_lengths` for writing") * + * if template: # <<<<<<<<<<<<<< + * # header is copied, though at the moment not strictly + * # necessary as AlignmentHeader is immutable. */ + goto __pyx_L39; } - /* "pysam/libcalignmentfile.pyx":557 - * - * # bam files require a valid header - * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< - * with nogil: - * self.header = sam_hdr_read(self.htsfile) + /* "pysam/libcalignmentfile.pyx":888 + * # necessary as AlignmentHeader is immutable. + * self.header = template.header.copy() + * elif isinstance(header, AlignmentHeader): # <<<<<<<<<<<<<< + * self.header = header.copy() + * elif isinstance(header, collections.Mapping): */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (!__pyx_t_19) { - } else { - __pyx_t_1 = __pyx_t_19; - goto __pyx_L58_bool_binop_done; - } - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 557, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_1 = __pyx_t_19; - __pyx_L58_bool_binop_done:; + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_header, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader); + __pyx_t_1 = (__pyx_t_3 != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":558 - * # bam files require a valid header - * if self.is_bam or self.is_cram: - * with nogil: # <<<<<<<<<<<<<< - * self.header = sam_hdr_read(self.htsfile) - * if self.header == NULL: - */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { - - /* "pysam/libcalignmentfile.pyx":559 - * if self.is_bam or self.is_cram: - * with nogil: - * self.header = sam_hdr_read(self.htsfile) # <<<<<<<<<<<<<< - * if self.header == NULL: - * raise ValueError( - */ - __pyx_v_self->header = sam_hdr_read(__pyx_v_self->__pyx_base.htsfile); - } - - /* "pysam/libcalignmentfile.pyx":558 - * # bam files require a valid header - * if self.is_bam or self.is_cram: - * with nogil: # <<<<<<<<<<<<<< - * self.header = sam_hdr_read(self.htsfile) - * if self.header == NULL: + /* "pysam/libcalignmentfile.pyx":889 + * self.header = template.header.copy() + * elif isinstance(header, AlignmentHeader): + * self.header = header.copy() # <<<<<<<<<<<<<< + * elif isinstance(header, collections.Mapping): + * self.header = AlignmentHeader.from_dict(header) */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L62; - } - __pyx_L62:; - } + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_header, __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 889, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } } + if (__pyx_t_2) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 889, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 889, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 889, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5); + __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":560 - * with nogil: - * self.header = sam_hdr_read(self.htsfile) - * if self.header == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "file does not have valid header (mode='%s') " + /* "pysam/libcalignmentfile.pyx":888 + * # necessary as AlignmentHeader is immutable. + * self.header = template.header.copy() + * elif isinstance(header, AlignmentHeader): # <<<<<<<<<<<<<< + * self.header = header.copy() + * elif isinstance(header, collections.Mapping): */ - __pyx_t_1 = ((__pyx_v_self->header == NULL) != 0); - if (unlikely(__pyx_t_1)) { + goto __pyx_L39; + } - /* "pysam/libcalignmentfile.pyx":563 - * raise ValueError( - * "file does not have valid header (mode='%s') " - * "- is it BAM format?" % mode ) # <<<<<<<<<<<<<< - * else: - * # in sam files it is optional (htsfile full of + /* "pysam/libcalignmentfile.pyx":890 + * elif isinstance(header, AlignmentHeader): + * self.header = header.copy() + * elif isinstance(header, collections.Mapping): # <<<<<<<<<<<<<< + * self.header = AlignmentHeader.from_dict(header) + * elif reference_names and reference_lengths: */ - __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_file_does_not_have_valid_header, __pyx_v_mode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 563, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 890, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 890, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_1 = PyObject_IsInstance(__pyx_v_header, __pyx_t_4); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 890, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = (__pyx_t_1 != 0); + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":561 - * self.header = sam_hdr_read(self.htsfile) - * if self.header == NULL: - * raise ValueError( # <<<<<<<<<<<<<< - * "file does not have valid header (mode='%s') " - * "- is it BAM format?" % mode ) + /* "pysam/libcalignmentfile.pyx":891 + * self.header = header.copy() + * elif isinstance(header, collections.Mapping): + * self.header = AlignmentHeader.from_dict(header) # <<<<<<<<<<<<<< + * elif reference_names and reference_lengths: + * self.header = AlignmentHeader.from_references( */ - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 561, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_n_s_from_dict); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 891, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (!__pyx_t_2) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_header); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 891, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 561, __pyx_L1_error) - - /* "pysam/libcalignmentfile.pyx":560 - * with nogil: - * self.header = sam_hdr_read(self.htsfile) - * if self.header == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "file does not have valid header (mode='%s') " - */ + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_header}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 891, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_header}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 891, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 891, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_2); __pyx_t_2 = NULL; + __Pyx_INCREF(__pyx_v_header); + __Pyx_GIVEREF(__pyx_v_header); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_header); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 891, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 891, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":557 - * - * # bam files require a valid header - * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< - * with nogil: - * self.header = sam_hdr_read(self.htsfile) + /* "pysam/libcalignmentfile.pyx":890 + * elif isinstance(header, AlignmentHeader): + * self.header = header.copy() + * elif isinstance(header, collections.Mapping): # <<<<<<<<<<<<<< + * self.header = AlignmentHeader.from_dict(header) + * elif reference_names and reference_lengths: */ - goto __pyx_L57; + goto __pyx_L39; } - /* "pysam/libcalignmentfile.pyx":567 - * # in sam files it is optional (htsfile full of - * # unmapped reads) - * if check_header: # <<<<<<<<<<<<<< - * with nogil: - * self.header = sam_hdr_read(self.htsfile) + /* "pysam/libcalignmentfile.pyx":892 + * elif isinstance(header, collections.Mapping): + * self.header = AlignmentHeader.from_dict(header) + * elif reference_names and reference_lengths: # <<<<<<<<<<<<<< + * self.header = AlignmentHeader.from_references( + * reference_names, */ - /*else*/ { - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_check_header); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 567, __pyx_L1_error) - if (__pyx_t_1) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 892, __pyx_L1_error) + if (__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L40_bool_binop_done; + } + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference_lengths); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 892, __pyx_L1_error) + __pyx_t_3 = __pyx_t_1; + __pyx_L40_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":568 - * # unmapped reads) - * if check_header: - * with nogil: # <<<<<<<<<<<<<< - * self.header = sam_hdr_read(self.htsfile) - * if self.header == NULL: + /* "pysam/libcalignmentfile.pyx":893 + * self.header = AlignmentHeader.from_dict(header) + * elif reference_names and reference_lengths: + * self.header = AlignmentHeader.from_references( # <<<<<<<<<<<<<< + * reference_names, + * reference_lengths, */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_n_s_from_references); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 893, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libcalignmentfile.pyx":569 - * if check_header: - * with nogil: - * self.header = sam_hdr_read(self.htsfile) # <<<<<<<<<<<<<< - * if self.header == NULL: - * raise ValueError( + /* "pysam/libcalignmentfile.pyx":895 + * self.header = AlignmentHeader.from_references( + * reference_names, + * reference_lengths, # <<<<<<<<<<<<<< + * add_sq_text=add_sq_text, + * text=text) */ - __pyx_v_self->header = sam_hdr_read(__pyx_v_self->__pyx_base.htsfile); - } + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 893, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_reference_names); + __Pyx_GIVEREF(__pyx_v_reference_names); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_reference_names); + __Pyx_INCREF(__pyx_v_reference_lengths); + __Pyx_GIVEREF(__pyx_v_reference_lengths); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_reference_lengths); + + /* "pysam/libcalignmentfile.pyx":896 + * reference_names, + * reference_lengths, + * add_sq_text=add_sq_text, # <<<<<<<<<<<<<< + * text=text) + * elif text: + */ + __pyx_t_11 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_add_sq_text, __pyx_v_add_sq_text) < 0) __PYX_ERR(0, 896, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":897 + * reference_lengths, + * add_sq_text=add_sq_text, + * text=text) # <<<<<<<<<<<<<< + * elif text: + * self.header = AlignmentHeader.from_text(text) + */ + if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_text, __pyx_v_text) < 0) __PYX_ERR(0, 896, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":893 + * self.header = AlignmentHeader.from_dict(header) + * elif reference_names and reference_lengths: + * self.header = AlignmentHeader.from_references( # <<<<<<<<<<<<<< + * reference_names, + * reference_lengths, + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 893, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 893, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":568 - * # unmapped reads) - * if check_header: - * with nogil: # <<<<<<<<<<<<<< - * self.header = sam_hdr_read(self.htsfile) - * if self.header == NULL: + /* "pysam/libcalignmentfile.pyx":892 + * elif isinstance(header, collections.Mapping): + * self.header = AlignmentHeader.from_dict(header) + * elif reference_names and reference_lengths: # <<<<<<<<<<<<<< + * self.header = AlignmentHeader.from_references( + * reference_names, */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L67; - } - __pyx_L67:; - } - } + goto __pyx_L39; + } - /* "pysam/libcalignmentfile.pyx":570 - * with nogil: - * self.header = sam_hdr_read(self.htsfile) - * if self.header == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "file does not have valid header (mode='%s') " + /* "pysam/libcalignmentfile.pyx":898 + * add_sq_text=add_sq_text, + * text=text) + * elif text: # <<<<<<<<<<<<<< + * self.header = AlignmentHeader.from_text(text) + * else: */ - __pyx_t_1 = ((__pyx_v_self->header == NULL) != 0); - if (unlikely(__pyx_t_1)) { + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_text); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 898, __pyx_L1_error) + if (likely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":573 - * raise ValueError( - * "file does not have valid header (mode='%s') " - * "- is it SAM format?" % mode ) # <<<<<<<<<<<<<< - * # self.header.ignore_sam_err = True - * + /* "pysam/libcalignmentfile.pyx":899 + * text=text) + * elif text: + * self.header = AlignmentHeader.from_text(text) # <<<<<<<<<<<<<< + * else: + * raise ValueError("not enough information to construct header. Please provide template, " */ - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_file_does_not_have_valid_header_2, __pyx_v_mode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 573, __pyx_L1_error) + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_n_s_from_text); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 899, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + if (!__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_text); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 899, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_text}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 899, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_text}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 899, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 899, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - - /* "pysam/libcalignmentfile.pyx":571 - * self.header = sam_hdr_read(self.htsfile) - * if self.header == NULL: - * raise ValueError( # <<<<<<<<<<<<<< - * "file does not have valid header (mode='%s') " - * "- is it SAM format?" % mode ) - */ - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_text); + __Pyx_GIVEREF(__pyx_v_text); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_text); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 899, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 571, __pyx_L1_error) - - /* "pysam/libcalignmentfile.pyx":570 - * with nogil: - * self.header = sam_hdr_read(self.htsfile) - * if self.header == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "file does not have valid header (mode='%s') " - */ } + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 899, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":567 - * # in sam files it is optional (htsfile full of - * # unmapped reads) - * if check_header: # <<<<<<<<<<<<<< - * with nogil: - * self.header = sam_hdr_read(self.htsfile) + /* "pysam/libcalignmentfile.pyx":898 + * add_sq_text=add_sq_text, + * text=text) + * elif text: # <<<<<<<<<<<<<< + * self.header = AlignmentHeader.from_text(text) + * else: */ - } + goto __pyx_L39; } - __pyx_L57:; - /* "pysam/libcalignmentfile.pyx":577 - * - * # set filename with reference sequences - * if self.is_cram and reference_filename: # <<<<<<<<<<<<<< - * creference_filename = self.reference_filename - * hts_set_opt(self.htsfile, + /* "pysam/libcalignmentfile.pyx":901 + * self.header = AlignmentHeader.from_text(text) + * else: + * raise ValueError("not enough information to construct header. Please provide template, " # <<<<<<<<<<<<<< + * "header, text or reference_names/reference_lengths") + * self.htsfile = self._open_htsfile() */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 577, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 577, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_19) { - } else { - __pyx_t_1 = __pyx_t_19; - goto __pyx_L70_bool_binop_done; + /*else*/ { + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 901, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 901, __pyx_L1_error) } - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_reference_filename); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 577, __pyx_L1_error) - __pyx_t_1 = __pyx_t_19; - __pyx_L70_bool_binop_done:; - if (__pyx_t_1) { + __pyx_L39:; - /* "pysam/libcalignmentfile.pyx":578 - * # set filename with reference sequences - * if self.is_cram and reference_filename: - * creference_filename = self.reference_filename # <<<<<<<<<<<<<< - * hts_set_opt(self.htsfile, - * CRAM_OPT_REFERENCE, + /* "pysam/libcalignmentfile.pyx":903 + * raise ValueError("not enough information to construct header. Please provide template, " + * "header, text or reference_names/reference_lengths") + * self.htsfile = self._open_htsfile() # <<<<<<<<<<<<<< + * + * if self.htsfile == NULL: */ - __pyx_t_9 = __Pyx_PyObject_AsWritableString(__pyx_v_self->reference_filename); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 578, __pyx_L1_error) - __pyx_v_creference_filename = __pyx_t_9; + __pyx_t_12 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_12 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 903, __pyx_L1_error) + __pyx_v_self->__pyx_base.htsfile = __pyx_t_12; - /* "pysam/libcalignmentfile.pyx":579 - * if self.is_cram and reference_filename: - * creference_filename = self.reference_filename - * hts_set_opt(self.htsfile, # <<<<<<<<<<<<<< - * CRAM_OPT_REFERENCE, - * creference_filename) + /* "pysam/libcalignmentfile.pyx":905 + * self.htsfile = self._open_htsfile() + * + * if self.htsfile == NULL: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, "could not open alignment file `{}`: {}".format( */ - (void)(hts_set_opt(__pyx_v_self->__pyx_base.htsfile, CRAM_OPT_REFERENCE, __pyx_v_creference_filename)); + __pyx_t_3 = ((__pyx_v_self->__pyx_base.htsfile == NULL) != 0); + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":577 + /* "pysam/libcalignmentfile.pyx":906 * - * # set filename with reference sequences - * if self.is_cram and reference_filename: # <<<<<<<<<<<<<< - * creference_filename = self.reference_filename - * hts_set_opt(self.htsfile, + * if self.htsfile == NULL: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, "could not open alignment file `{}`: {}".format( + * force_str(filename), */ - } + __pyx_t_3 = (errno != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":583 - * creference_filename) - * - * if check_sq and self.header.n_targets == 0: # <<<<<<<<<<<<<< - * raise ValueError( - * ("file has no sequences defined (mode='%s') - " + /* "pysam/libcalignmentfile.pyx":907 + * if self.htsfile == NULL: + * if errno: + * raise IOError(errno, "could not open alignment file `{}`: {}".format( # <<<<<<<<<<<<<< + * force_str(filename), + * force_str(strerror(errno)))) */ - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_check_sq); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 583, __pyx_L1_error) - if (__pyx_t_19) { - } else { - __pyx_t_1 = __pyx_t_19; - goto __pyx_L73_bool_binop_done; - } - __pyx_t_19 = ((__pyx_v_self->header->n_targets == 0) != 0); - __pyx_t_1 = __pyx_t_19; - __pyx_L73_bool_binop_done:; - if (unlikely(__pyx_t_1)) { + __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 907, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_alignment_file, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 907, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libcalignmentfile.pyx":587 - * ("file has no sequences defined (mode='%s') - " - * "is it SAM/BAM format? Consider opening with " - * "check_sq=False") % mode) # <<<<<<<<<<<<<< - * - * assert self.htsfile != NULL + /* "pysam/libcalignmentfile.pyx":908 + * if errno: + * raise IOError(errno, "could not open alignment file `{}`: {}".format( + * force_str(filename), # <<<<<<<<<<<<<< + * force_str(strerror(errno)))) + * else: */ - __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_file_has_no_sequences_defined_mo, __pyx_v_mode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 587, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); - /* "pysam/libcalignmentfile.pyx":584 - * - * if check_sq and self.header.n_targets == 0: - * raise ValueError( # <<<<<<<<<<<<<< - * ("file has no sequences defined (mode='%s') - " - * "is it SAM/BAM format? Consider opening with " + /* "pysam/libcalignmentfile.pyx":909 + * raise IOError(errno, "could not open alignment file `{}`: {}".format( + * force_str(filename), + * force_str(strerror(errno)))) # <<<<<<<<<<<<<< + * else: + * raise ValueError("could not open alignment file `{}`".format(force_str(filename))) */ - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 584, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 584, __pyx_L1_error) + __pyx_t_13 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 909, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_13, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 909, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_t_5, __pyx_t_14}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 907, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_t_5, __pyx_t_14}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 907, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } else + #endif + { + __pyx_t_15 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 907, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + if (__pyx_t_13) { + __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_13); __pyx_t_13 = NULL; + } + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_10, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_10, __pyx_t_14); + __pyx_t_5 = 0; + __pyx_t_14 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_15, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 907, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":583 - * creference_filename) - * - * if check_sq and self.header.n_targets == 0: # <<<<<<<<<<<<<< - * raise ValueError( - * ("file has no sequences defined (mode='%s') - " + /* "pysam/libcalignmentfile.pyx":907 + * if self.htsfile == NULL: + * if errno: + * raise IOError(errno, "could not open alignment file `{}`: {}".format( # <<<<<<<<<<<<<< + * force_str(filename), + * force_str(strerror(errno)))) */ - } + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 907, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_11); + __pyx_t_2 = 0; + __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 907, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_11, 0, 0, 0); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __PYX_ERR(0, 907, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":541 - * sam_hdr_write(self.htsfile, self.header) + /* "pysam/libcalignmentfile.pyx":906 * - * elif mode[0] == "r": # <<<<<<<<<<<<<< - * # open file for reading - * if not self._exists(): + * if self.htsfile == NULL: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, "could not open alignment file `{}`: {}".format( + * force_str(filename), */ - } - __pyx_L28:; + } - /* "pysam/libcalignmentfile.pyx":589 - * "check_sq=False") % mode) - * - * assert self.htsfile != NULL # <<<<<<<<<<<<<< - * - * # check for index and open if present + /* "pysam/libcalignmentfile.pyx":911 + * force_str(strerror(errno)))) + * else: + * raise ValueError("could not open alignment file `{}`".format(force_str(filename))) # <<<<<<<<<<<<<< + * if format_options and len(format_options): + * self.add_hts_options(format_options) */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - if (unlikely(!((__pyx_v_self->__pyx_base.htsfile != NULL) != 0))) { - PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 589, __pyx_L1_error) - } - } - #endif + /*else*/ { + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_alignment_file_2, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_15) { + __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_11); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_15, __pyx_t_2}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_15, __pyx_t_2}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_15); __pyx_t_15 = NULL; + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_14, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 911, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 911, __pyx_L1_error) + } - /* "pysam/libcalignmentfile.pyx":592 + /* "pysam/libcalignmentfile.pyx":905 + * self.htsfile = self._open_htsfile() * - * # check for index and open if present - * cdef int format_index = -1 # <<<<<<<<<<<<<< - * if self.is_bam: - * format_index = HTS_FMT_BAI + * if self.htsfile == NULL: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, "could not open alignment file `{}`: {}".format( */ - __pyx_v_format_index = -1; + } - /* "pysam/libcalignmentfile.pyx":593 - * # check for index and open if present - * cdef int format_index = -1 - * if self.is_bam: # <<<<<<<<<<<<<< - * format_index = HTS_FMT_BAI - * elif self.is_cram: + /* "pysam/libcalignmentfile.pyx":912 + * else: + * raise ValueError("could not open alignment file `{}`".format(force_str(filename))) + * if format_options and len(format_options): # <<<<<<<<<<<<<< + * self.add_hts_options(format_options) + * # set filename with reference sequences. If no filename */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 593, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 593, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_1) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_format_options); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 912, __pyx_L1_error) + if (__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L45_bool_binop_done; + } + __pyx_t_16 = PyObject_Length(__pyx_v_format_options); if (unlikely(__pyx_t_16 == ((Py_ssize_t)-1))) __PYX_ERR(0, 912, __pyx_L1_error) + __pyx_t_1 = (__pyx_t_16 != 0); + __pyx_t_3 = __pyx_t_1; + __pyx_L45_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":594 - * cdef int format_index = -1 - * if self.is_bam: - * format_index = HTS_FMT_BAI # <<<<<<<<<<<<<< - * elif self.is_cram: - * format_index = HTS_FMT_CRAI + /* "pysam/libcalignmentfile.pyx":913 + * raise ValueError("could not open alignment file `{}`".format(force_str(filename))) + * if format_options and len(format_options): + * self.add_hts_options(format_options) # <<<<<<<<<<<<<< + * # set filename with reference sequences. If no filename + * # is given, the CRAM reference arrays will be built from */ - __pyx_v_format_index = HTS_FMT_BAI; + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_hts_options); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 913, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + if (!__pyx_t_14) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_format_options); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 913, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[2] = {__pyx_t_14, __pyx_v_format_options}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 913, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[2] = {__pyx_t_14, __pyx_v_format_options}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 913, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 913, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_14); __pyx_t_14 = NULL; + __Pyx_INCREF(__pyx_v_format_options); + __Pyx_GIVEREF(__pyx_v_format_options); + PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_format_options); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 913, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":593 - * # check for index and open if present - * cdef int format_index = -1 - * if self.is_bam: # <<<<<<<<<<<<<< - * format_index = HTS_FMT_BAI - * elif self.is_cram: + /* "pysam/libcalignmentfile.pyx":912 + * else: + * raise ValueError("could not open alignment file `{}`".format(force_str(filename))) + * if format_options and len(format_options): # <<<<<<<<<<<<<< + * self.add_hts_options(format_options) + * # set filename with reference sequences. If no filename */ - goto __pyx_L75; - } + } - /* "pysam/libcalignmentfile.pyx":595 - * if self.is_bam: - * format_index = HTS_FMT_BAI - * elif self.is_cram: # <<<<<<<<<<<<<< - * format_index = HTS_FMT_CRAI - * + /* "pysam/libcalignmentfile.pyx":917 + * # is given, the CRAM reference arrays will be built from + * # the @SQ header in the header + * if "c" in mode and reference_filename: # <<<<<<<<<<<<<< + * # note that fn_aux takes ownership, so create a copy + * self.htsfile.fn_aux = strdup(self.reference_filename) */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 595, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 595, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_1) { + __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_c, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 917, __pyx_L1_error) + __pyx_t_17 = (__pyx_t_1 != 0); + if (__pyx_t_17) { + } else { + __pyx_t_3 = __pyx_t_17; + goto __pyx_L48_bool_binop_done; + } + __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_v_reference_filename); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 917, __pyx_L1_error) + __pyx_t_3 = __pyx_t_17; + __pyx_L48_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":596 - * format_index = HTS_FMT_BAI - * elif self.is_cram: - * format_index = HTS_FMT_CRAI # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":919 + * if "c" in mode and reference_filename: + * # note that fn_aux takes ownership, so create a copy + * self.htsfile.fn_aux = strdup(self.reference_filename) # <<<<<<<<<<<<<< * - * if mode[0] == "r" and (self.is_bam or self.is_cram): + * # write header to htsfile */ - __pyx_v_format_index = HTS_FMT_CRAI; + __pyx_t_18 = __Pyx_PyObject_AsString(__pyx_v_self->reference_filename); if (unlikely((!__pyx_t_18) && PyErr_Occurred())) __PYX_ERR(0, 919, __pyx_L1_error) + __pyx_v_self->__pyx_base.htsfile->fn_aux = strdup(__pyx_t_18); - /* "pysam/libcalignmentfile.pyx":595 - * if self.is_bam: - * format_index = HTS_FMT_BAI - * elif self.is_cram: # <<<<<<<<<<<<<< - * format_index = HTS_FMT_CRAI - * + /* "pysam/libcalignmentfile.pyx":917 + * # is given, the CRAM reference arrays will be built from + * # the @SQ header in the header + * if "c" in mode and reference_filename: # <<<<<<<<<<<<<< + * # note that fn_aux takes ownership, so create a copy + * self.htsfile.fn_aux = strdup(self.reference_filename) */ - } - __pyx_L75:; + } - /* "pysam/libcalignmentfile.pyx":598 - * format_index = HTS_FMT_CRAI + /* "pysam/libcalignmentfile.pyx":922 * - * if mode[0] == "r" and (self.is_bam or self.is_cram): # <<<<<<<<<<<<<< - * # open index for remote files - * if self.is_remote and not filepath_index: - */ - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_19 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_r, Py_EQ)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_19) { - } else { - __pyx_t_1 = __pyx_t_19; - goto __pyx_L77_bool_binop_done; - } - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!__pyx_t_19) { - } else { - __pyx_t_1 = __pyx_t_19; - goto __pyx_L77_bool_binop_done; - } - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_1 = __pyx_t_19; - __pyx_L77_bool_binop_done:; - if (__pyx_t_1) { - - /* "pysam/libcalignmentfile.pyx":600 - * if mode[0] == "r" and (self.is_bam or self.is_cram): - * # open index for remote files - * if self.is_remote and not filepath_index: # <<<<<<<<<<<<<< + * # write header to htsfile + * if "b" in mode or "c" in mode or "h" in mode: # <<<<<<<<<<<<<< + * hdr = self.header.ptr * with nogil: - * self.index = hts_idx_load(cfilename, format_index) */ - __pyx_t_19 = (__pyx_v_self->__pyx_base.is_remote != 0); - if (__pyx_t_19) { + __pyx_t_17 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_b, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 922, __pyx_L1_error) + __pyx_t_1 = (__pyx_t_17 != 0); + if (!__pyx_t_1) { } else { - __pyx_t_1 = __pyx_t_19; - goto __pyx_L81_bool_binop_done; + __pyx_t_3 = __pyx_t_1; + goto __pyx_L51_bool_binop_done; } - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_v_filepath_index); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 600, __pyx_L1_error) - __pyx_t_2 = ((!__pyx_t_19) != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L81_bool_binop_done:; - if (__pyx_t_1) { + __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_c, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 922, __pyx_L1_error) + __pyx_t_17 = (__pyx_t_1 != 0); + if (!__pyx_t_17) { + } else { + __pyx_t_3 = __pyx_t_17; + goto __pyx_L51_bool_binop_done; + } + __pyx_t_17 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_h, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 922, __pyx_L1_error) + __pyx_t_1 = (__pyx_t_17 != 0); + __pyx_t_3 = __pyx_t_1; + __pyx_L51_bool_binop_done:; + if (__pyx_t_3) { + + /* "pysam/libcalignmentfile.pyx":923 + * # write header to htsfile + * if "b" in mode or "c" in mode or "h" in mode: + * hdr = self.header.ptr # <<<<<<<<<<<<<< + * with nogil: + * sam_hdr_write(self.htsfile, hdr) + */ + __pyx_t_19 = __pyx_v_self->header->ptr; + __pyx_v_hdr = __pyx_t_19; - /* "pysam/libcalignmentfile.pyx":601 - * # open index for remote files - * if self.is_remote and not filepath_index: + /* "pysam/libcalignmentfile.pyx":924 + * if "b" in mode or "c" in mode or "h" in mode: + * hdr = self.header.ptr * with nogil: # <<<<<<<<<<<<<< - * self.index = hts_idx_load(cfilename, format_index) - * if self.index == NULL: + * sam_hdr_write(self.htsfile, hdr) + * */ { #ifdef WITH_THREAD @@ -8320,22 +13918,22 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(stru #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":602 - * if self.is_remote and not filepath_index: + /* "pysam/libcalignmentfile.pyx":925 + * hdr = self.header.ptr * with nogil: - * self.index = hts_idx_load(cfilename, format_index) # <<<<<<<<<<<<<< - * if self.index == NULL: - * warnings.warn( + * sam_hdr_write(self.htsfile, hdr) # <<<<<<<<<<<<<< + * + * elif mode[0] == "r": */ - __pyx_v_self->index = hts_idx_load(__pyx_v_cfilename, __pyx_v_format_index); + (void)(sam_hdr_write(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr)); } - /* "pysam/libcalignmentfile.pyx":601 - * # open index for remote files - * if self.is_remote and not filepath_index: + /* "pysam/libcalignmentfile.pyx":924 + * if "b" in mode or "c" in mode or "h" in mode: + * hdr = self.header.ptr * with nogil: # <<<<<<<<<<<<<< - * self.index = hts_idx_load(cfilename, format_index) - * if self.index == NULL: + * sam_hdr_write(self.htsfile, hdr) + * */ /*finally:*/ { /*normal exit:*/{ @@ -8343,1554 +13941,1372 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(stru __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif - goto __pyx_L85; + goto __pyx_L56; } - __pyx_L85:; + __pyx_L56:; } } - /* "pysam/libcalignmentfile.pyx":603 + /* "pysam/libcalignmentfile.pyx":922 + * + * # write header to htsfile + * if "b" in mode or "c" in mode or "h" in mode: # <<<<<<<<<<<<<< + * hdr = self.header.ptr * with nogil: - * self.index = hts_idx_load(cfilename, format_index) - * if self.index == NULL: # <<<<<<<<<<<<<< - * warnings.warn( - * "unable to open remote index for '%s'" % cfilename) */ - __pyx_t_1 = ((__pyx_v_self->index == NULL) != 0); - if (__pyx_t_1) { + } - /* "pysam/libcalignmentfile.pyx":604 - * self.index = hts_idx_load(cfilename, format_index) - * if self.index == NULL: - * warnings.warn( # <<<<<<<<<<<<<< - * "unable to open remote index for '%s'" % cfilename) - * else: + /* "pysam/libcalignmentfile.pyx":876 + * reference_filename) + * + * if mode[0] == 'w': # <<<<<<<<<<<<<< + * # open file for writing + * */ - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 604, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_warn); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 604, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L34; + } - /* "pysam/libcalignmentfile.pyx":605 - * if self.index == NULL: - * warnings.warn( - * "unable to open remote index for '%s'" % cfilename) # <<<<<<<<<<<<<< - * else: - * has_index = True + /* "pysam/libcalignmentfile.pyx":927 + * sam_hdr_write(self.htsfile, hdr) + * + * elif mode[0] == "r": # <<<<<<<<<<<<<< + * # open file for reading + * self.htsfile = self._open_htsfile() + */ + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_r, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 927, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_3) { + + /* "pysam/libcalignmentfile.pyx":929 + * elif mode[0] == "r": + * # open file for reading + * self.htsfile = self._open_htsfile() # <<<<<<<<<<<<<< + * + * if self.htsfile == NULL: + */ + __pyx_t_12 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_12 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 929, __pyx_L1_error) + __pyx_v_self->__pyx_base.htsfile = __pyx_t_12; + + /* "pysam/libcalignmentfile.pyx":931 + * self.htsfile = self._open_htsfile() + * + * if self.htsfile == NULL: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename), + */ + __pyx_t_3 = ((__pyx_v_self->__pyx_base.htsfile == NULL) != 0); + if (__pyx_t_3) { + + /* "pysam/libcalignmentfile.pyx":932 + * + * if self.htsfile == NULL: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename), + * force_str(strerror(errno)))) + */ + __pyx_t_3 = (errno != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcalignmentfile.pyx":933 + * if self.htsfile == NULL: + * if errno: + * raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename), # <<<<<<<<<<<<<< + * force_str(strerror(errno)))) + * else: + */ + __pyx_t_4 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_alignment_file, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + + /* "pysam/libcalignmentfile.pyx":934 + * if errno: + * raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename), + * force_str(strerror(errno)))) # <<<<<<<<<<<<<< + * else: + * raise ValueError("could not open alignment file `{}`".format(force_str(filename))) */ - __pyx_t_5 = __Pyx_PyBytes_FromString(__pyx_v_cfilename); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 605, __pyx_L1_error) + __pyx_t_15 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 934, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_15, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 934, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_23 = __Pyx_PyString_Format(__pyx_kp_s_unable_to_open_remote_index_for, __pyx_t_5); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 605, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_15); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_10 = 1; } } - if (!__pyx_t_5) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_23); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 604, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __Pyx_GOTREF(__pyx_t_4); + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_t_14, __pyx_t_5}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_t_14, __pyx_t_5}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_13 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + if (__pyx_t_15) { + __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_15); __pyx_t_15 = NULL; + } + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_10, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_10, __pyx_t_5); + __pyx_t_14 = 0; + __pyx_t_5 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_13, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libcalignmentfile.pyx":933 + * if self.htsfile == NULL: + * if errno: + * raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename), # <<<<<<<<<<<<<< + * force_str(strerror(errno)))) + * else: + */ + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_11); + __pyx_t_4 = 0; + __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 933, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_11, 0, 0, 0); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __PYX_ERR(0, 933, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":932 + * + * if self.htsfile == NULL: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename), + * force_str(strerror(errno)))) + */ + } + + /* "pysam/libcalignmentfile.pyx":936 + * force_str(strerror(errno)))) + * else: + * raise ValueError("could not open alignment file `{}`".format(force_str(filename))) # <<<<<<<<<<<<<< + * + * if self.htsfile.format.category != sequence_data: + */ + /*else*/ { + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_alignment_file_2, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_13) { + __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_11); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_23}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 604, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_13, __pyx_t_4}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_23}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 604, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_13, __pyx_t_4}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_24 = PyTuple_New(1+1); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 604, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_24, 0, __pyx_t_5); __pyx_t_5 = NULL; - __Pyx_GIVEREF(__pyx_t_23); - PyTuple_SET_ITEM(__pyx_t_24, 0+1, __pyx_t_23); - __pyx_t_23 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_24, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 604, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_13); __pyx_t_13 = NULL; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pysam/libcalignmentfile.pyx":603 - * with nogil: - * self.index = hts_idx_load(cfilename, format_index) - * if self.index == NULL: # <<<<<<<<<<<<<< - * warnings.warn( - * "unable to open remote index for '%s'" % cfilename) - */ + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 936, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 936, __pyx_L1_error) } - /* "pysam/libcalignmentfile.pyx":600 - * if mode[0] == "r" and (self.is_bam or self.is_cram): - * # open index for remote files - * if self.is_remote and not filepath_index: # <<<<<<<<<<<<<< - * with nogil: - * self.index = hts_idx_load(cfilename, format_index) + /* "pysam/libcalignmentfile.pyx":931 + * self.htsfile = self._open_htsfile() + * + * if self.htsfile == NULL: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename), */ - goto __pyx_L80; } - /* "pysam/libcalignmentfile.pyx":607 - * "unable to open remote index for '%s'" % cfilename) - * else: - * has_index = True # <<<<<<<<<<<<<< - * if filepath_index: - * if not os.path.exists(filepath_index): + /* "pysam/libcalignmentfile.pyx":938 + * raise ValueError("could not open alignment file `{}`".format(force_str(filename))) + * + * if self.htsfile.format.category != sequence_data: # <<<<<<<<<<<<<< + * raise ValueError("file does not contain alignment data") + * */ - /*else*/ { - __pyx_v_has_index = 1; + __pyx_t_3 = ((__pyx_v_self->__pyx_base.htsfile->format.category != sequence_data) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":608 - * else: - * has_index = True - * if filepath_index: # <<<<<<<<<<<<<< - * if not os.path.exists(filepath_index): - * warnings.warn( + /* "pysam/libcalignmentfile.pyx":939 + * + * if self.htsfile.format.category != sequence_data: + * raise ValueError("file does not contain alignment data") # <<<<<<<<<<<<<< + * + * if format_options and len(format_options): */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_filepath_index); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 608, __pyx_L1_error) - if (__pyx_t_1) { + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 939, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 939, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":609 - * has_index = True - * if filepath_index: - * if not os.path.exists(filepath_index): # <<<<<<<<<<<<<< - * warnings.warn( - * "unable to open index at %s" % cfilename) + /* "pysam/libcalignmentfile.pyx":938 + * raise ValueError("could not open alignment file `{}`".format(force_str(filename))) + * + * if self.htsfile.format.category != sequence_data: # <<<<<<<<<<<<<< + * raise ValueError("file does not contain alignment data") + * */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 609, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_24 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 609, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_24, __pyx_n_s_exists_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 609, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __pyx_t_24 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_24 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_24)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_24); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } + } + + /* "pysam/libcalignmentfile.pyx":941 + * raise ValueError("file does not contain alignment data") + * + * if format_options and len(format_options): # <<<<<<<<<<<<<< + * self.add_hts_options(format_options) + * + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_format_options); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 941, __pyx_L1_error) + if (__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L61_bool_binop_done; + } + __pyx_t_16 = PyObject_Length(__pyx_v_format_options); if (unlikely(__pyx_t_16 == ((Py_ssize_t)-1))) __PYX_ERR(0, 941, __pyx_L1_error) + __pyx_t_1 = (__pyx_t_16 != 0); + __pyx_t_3 = __pyx_t_1; + __pyx_L61_bool_binop_done:; + if (__pyx_t_3) { + + /* "pysam/libcalignmentfile.pyx":942 + * + * if format_options and len(format_options): + * self.add_hts_options(format_options) # <<<<<<<<<<<<<< + * + * self.check_truncation(ignore_truncation) + */ + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_hts_options); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 942, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); } - if (!__pyx_t_24) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_filepath_index); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 609, __pyx_L1_error) + } + if (!__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_format_options); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 942, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_format_options}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 942, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_format_options}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 942, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 942, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_24, __pyx_v_filepath_index}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 609, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_24, __pyx_v_filepath_index}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 609, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else - #endif - { - __pyx_t_23 = PyTuple_New(1+1); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 609, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __Pyx_GIVEREF(__pyx_t_24); PyTuple_SET_ITEM(__pyx_t_23, 0, __pyx_t_24); __pyx_t_24 = NULL; - __Pyx_INCREF(__pyx_v_filepath_index); - __Pyx_GIVEREF(__pyx_v_filepath_index); - PyTuple_SET_ITEM(__pyx_t_23, 0+1, __pyx_v_filepath_index); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_23, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 609, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - } + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_format_options); + __Pyx_GIVEREF(__pyx_v_format_options); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_format_options); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 942, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 609, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_2 = ((!__pyx_t_1) != 0); - if (__pyx_t_2) { + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":610 - * if filepath_index: - * if not os.path.exists(filepath_index): - * warnings.warn( # <<<<<<<<<<<<<< - * "unable to open index at %s" % cfilename) - * self.index = NULL + /* "pysam/libcalignmentfile.pyx":941 + * raise ValueError("file does not contain alignment data") + * + * if format_options and len(format_options): # <<<<<<<<<<<<<< + * self.add_hts_options(format_options) + * */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_23 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_warn); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } - /* "pysam/libcalignmentfile.pyx":611 - * if not os.path.exists(filepath_index): - * warnings.warn( - * "unable to open index at %s" % cfilename) # <<<<<<<<<<<<<< - * self.index = NULL - * has_index = False + /* "pysam/libcalignmentfile.pyx":944 + * self.add_hts_options(format_options) + * + * self.check_truncation(ignore_truncation) # <<<<<<<<<<<<<< + * + * # bam/cram files require a valid header */ - __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_cfilename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 611, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_24 = __Pyx_PyString_Format(__pyx_kp_s_unable_to_open_index_at_s, __pyx_t_3); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 611, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_23))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_23); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_23); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_23, function); - } - } - if (!__pyx_t_3) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_23, __pyx_t_24); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_24}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_24}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - } else - #endif - { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_GIVEREF(__pyx_t_24); - PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_24); - __pyx_t_24 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_23, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - } - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_truncation); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 944, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + if (!__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_ignore_truncation); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 944, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_ignore_truncation}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 944, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_ignore_truncation}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 944, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 944, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_INCREF(__pyx_v_ignore_truncation); + __Pyx_GIVEREF(__pyx_v_ignore_truncation); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_ignore_truncation); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 944, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":612 - * warnings.warn( - * "unable to open index at %s" % cfilename) - * self.index = NULL # <<<<<<<<<<<<<< - * has_index = False - * elif filename is not None: + /* "pysam/libcalignmentfile.pyx":947 + * + * # bam/cram files require a valid header + * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< + * with nogil: + * hdr = sam_hdr_read(self.htsfile) */ - __pyx_v_self->index = NULL; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 947, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 947, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L64_bool_binop_done; + } + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 947, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 947, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = __pyx_t_1; + __pyx_L64_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":613 - * "unable to open index at %s" % cfilename) - * self.index = NULL - * has_index = False # <<<<<<<<<<<<<< - * elif filename is not None: - * if self.is_bam \ + /* "pysam/libcalignmentfile.pyx":948 + * # bam/cram files require a valid header + * if self.is_bam or self.is_cram: + * with nogil: # <<<<<<<<<<<<<< + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: */ - __pyx_v_has_index = 0; + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libcalignmentfile.pyx":609 - * has_index = True - * if filepath_index: - * if not os.path.exists(filepath_index): # <<<<<<<<<<<<<< - * warnings.warn( - * "unable to open index at %s" % cfilename) + /* "pysam/libcalignmentfile.pyx":949 + * if self.is_bam or self.is_cram: + * with nogil: + * hdr = sam_hdr_read(self.htsfile) # <<<<<<<<<<<<<< + * if hdr == NULL: + * raise ValueError( */ - } + __pyx_v_hdr = sam_hdr_read(__pyx_v_self->__pyx_base.htsfile); + } - /* "pysam/libcalignmentfile.pyx":608 - * else: - * has_index = True - * if filepath_index: # <<<<<<<<<<<<<< - * if not os.path.exists(filepath_index): - * warnings.warn( + /* "pysam/libcalignmentfile.pyx":948 + * # bam/cram files require a valid header + * if self.is_bam or self.is_cram: + * with nogil: # <<<<<<<<<<<<<< + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: */ - goto __pyx_L87; + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L68; + } + __pyx_L68:; + } } - /* "pysam/libcalignmentfile.pyx":614 - * self.index = NULL - * has_index = False - * elif filename is not None: # <<<<<<<<<<<<<< - * if self.is_bam \ - * and not os.path.exists(filename + b".bai") \ + /* "pysam/libcalignmentfile.pyx":950 + * with nogil: + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: # <<<<<<<<<<<<<< + * raise ValueError( + * "file does not have a valid header (mode='%s') " */ - __pyx_t_2 = (__pyx_v_filename != ((PyObject*)Py_None)); - __pyx_t_1 = (__pyx_t_2 != 0); - if (__pyx_t_1) { + __pyx_t_3 = ((__pyx_v_hdr == NULL) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":615 - * has_index = False - * elif filename is not None: - * if self.is_bam \ # <<<<<<<<<<<<<< - * and not os.path.exists(filename + b".bai") \ - * and not os.path.exists(filename[:-4] + b".bai") \ + /* "pysam/libcalignmentfile.pyx":953 + * raise ValueError( + * "file does not have a valid header (mode='%s') " + * "- is it BAM/CRAM format?" % mode) # <<<<<<<<<<<<<< + * self.header = makeAlignmentHeader(hdr) + * else: */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 615, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 615, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L90_bool_binop_done; - } + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_file_does_not_have_a_valid_heade, __pyx_v_mode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 953, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); - /* "pysam/libcalignmentfile.pyx":616 - * elif filename is not None: - * if self.is_bam \ - * and not os.path.exists(filename + b".bai") \ # <<<<<<<<<<<<<< - * and not os.path.exists(filename[:-4] + b".bai") \ - * and not os.path.exists(filename + b".csi") \ + /* "pysam/libcalignmentfile.pyx":951 + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: + * raise ValueError( # <<<<<<<<<<<<<< + * "file does not have a valid header (mode='%s') " + * "- is it BAM/CRAM format?" % mode) */ - __pyx_t_23 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_23, __pyx_n_s_path); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_23 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_exists_2); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Add(__pyx_v_filename, __pyx_kp_b_bai); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_24 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_23))) { - __pyx_t_24 = PyMethod_GET_SELF(__pyx_t_23); - if (likely(__pyx_t_24)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_23); - __Pyx_INCREF(__pyx_t_24); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_23, function); - } - } - if (!__pyx_t_24) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_23, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_24, __pyx_t_5}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_24, __pyx_t_5}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_24); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_24); __pyx_t_24 = NULL; - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_23, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - } - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 616, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_19 = ((!__pyx_t_2) != 0); - if (__pyx_t_19) { - } else { - __pyx_t_1 = __pyx_t_19; - goto __pyx_L90_bool_binop_done; - } + __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 951, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_11, 0, 0, 0); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __PYX_ERR(0, 951, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":617 - * if self.is_bam \ - * and not os.path.exists(filename + b".bai") \ - * and not os.path.exists(filename[:-4] + b".bai") \ # <<<<<<<<<<<<<< - * and not os.path.exists(filename + b".csi") \ - * and not os.path.exists(filename[:-4] + b".csi"): + /* "pysam/libcalignmentfile.pyx":950 + * with nogil: + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: # <<<<<<<<<<<<<< + * raise ValueError( + * "file does not have a valid header (mode='%s') " */ - __pyx_t_23 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 617, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_23, __pyx_n_s_path); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 617, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_23 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_exists_2); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 617, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(__pyx_v_filename == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 617, __pyx_L1_error) - } - __pyx_t_3 = PySequence_GetSlice(__pyx_v_filename, 0, -4L); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 617, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyNumber_Add(__pyx_t_3, __pyx_kp_b_bai); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 617, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_23))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_23); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_23); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_23, function); - } - } - if (!__pyx_t_3) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_23, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 617, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_5}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 617, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_5}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 617, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_24 = PyTuple_New(1+1); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 617, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_24, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_24, 0+1, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_23, __pyx_t_24, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 617, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - } - } - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 617, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_2 = ((!__pyx_t_19) != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L90_bool_binop_done; - } - - /* "pysam/libcalignmentfile.pyx":618 - * and not os.path.exists(filename + b".bai") \ - * and not os.path.exists(filename[:-4] + b".bai") \ - * and not os.path.exists(filename + b".csi") \ # <<<<<<<<<<<<<< - * and not os.path.exists(filename[:-4] + b".csi"): - * self.index = NULL - */ - __pyx_t_23 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __pyx_t_24 = __Pyx_PyObject_GetAttrStr(__pyx_t_23, __pyx_n_s_path); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_23 = __Pyx_PyObject_GetAttrStr(__pyx_t_24, __pyx_n_s_exists_2); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __pyx_t_24 = PyNumber_Add(__pyx_v_filename, __pyx_kp_b_csi); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_23))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_23); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_23); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_23, function); - } - } - if (!__pyx_t_5) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_23, __pyx_t_24); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_24}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_24}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL; - __Pyx_GIVEREF(__pyx_t_24); - PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_24); - __pyx_t_24 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_23, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - } - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_19 = ((!__pyx_t_2) != 0); - if (__pyx_t_19) { - } else { - __pyx_t_1 = __pyx_t_19; - goto __pyx_L90_bool_binop_done; - } + } - /* "pysam/libcalignmentfile.pyx":619 - * and not os.path.exists(filename[:-4] + b".bai") \ - * and not os.path.exists(filename + b".csi") \ - * and not os.path.exists(filename[:-4] + b".csi"): # <<<<<<<<<<<<<< - * self.index = NULL - * has_index = False + /* "pysam/libcalignmentfile.pyx":954 + * "file does not have a valid header (mode='%s') " + * "- is it BAM/CRAM format?" % mode) + * self.header = makeAlignmentHeader(hdr) # <<<<<<<<<<<<<< + * else: + * # in sam files a header is optional. If not given, */ - __pyx_t_23 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 619, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_23, __pyx_n_s_path); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 619, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_23 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_exists_2); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 619, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(__pyx_v_filename == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 619, __pyx_L1_error) - } - __pyx_t_3 = PySequence_GetSlice(__pyx_v_filename, 0, -4L); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 619, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_24 = PyNumber_Add(__pyx_t_3, __pyx_kp_b_csi); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 619, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_23))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_23); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_23); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_23, function); - } - } - if (!__pyx_t_3) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_23, __pyx_t_24); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 619, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_24}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 619, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_24}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 619, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - } else - #endif - { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 619, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_GIVEREF(__pyx_t_24); - PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_24); - __pyx_t_24 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_23, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 619, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - } - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 619, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_2 = ((!__pyx_t_19) != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L90_bool_binop_done:; + __pyx_t_11 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 954, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_11); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_11); + __pyx_t_11 = 0; - /* "pysam/libcalignmentfile.pyx":615 - * has_index = False - * elif filename is not None: - * if self.is_bam \ # <<<<<<<<<<<<<< - * and not os.path.exists(filename + b".bai") \ - * and not os.path.exists(filename[:-4] + b".bai") \ + /* "pysam/libcalignmentfile.pyx":947 + * + * # bam/cram files require a valid header + * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< + * with nogil: + * hdr = sam_hdr_read(self.htsfile) */ - if (__pyx_t_1) { + goto __pyx_L63; + } - /* "pysam/libcalignmentfile.pyx":620 - * and not os.path.exists(filename + b".csi") \ - * and not os.path.exists(filename[:-4] + b".csi"): - * self.index = NULL # <<<<<<<<<<<<<< - * has_index = False - * elif self.is_cram \ + /* "pysam/libcalignmentfile.pyx":959 + * # user may provide reference names and lengths to built + * # an on-the-fly header. + * if reference_names and reference_lengths: # <<<<<<<<<<<<<< + * # build header from a target names and lengths + * self.header = AlignmentHeader.from_references( */ - __pyx_v_self->index = NULL; + /*else*/ { + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 959, __pyx_L1_error) + if (__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L71_bool_binop_done; + } + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference_lengths); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 959, __pyx_L1_error) + __pyx_t_3 = __pyx_t_1; + __pyx_L71_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":621 - * and not os.path.exists(filename[:-4] + b".csi"): - * self.index = NULL - * has_index = False # <<<<<<<<<<<<<< - * elif self.is_cram \ - * and not os.path.exists(filename + b".crai") \ + /* "pysam/libcalignmentfile.pyx":961 + * if reference_names and reference_lengths: + * # build header from a target names and lengths + * self.header = AlignmentHeader.from_references( # <<<<<<<<<<<<<< + * reference_names=reference_names, + * reference_lengths=reference_lengths, */ - __pyx_v_has_index = 0; + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_n_s_from_references); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 961, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); - /* "pysam/libcalignmentfile.pyx":615 - * has_index = False - * elif filename is not None: - * if self.is_bam \ # <<<<<<<<<<<<<< - * and not os.path.exists(filename + b".bai") \ - * and not os.path.exists(filename[:-4] + b".bai") \ + /* "pysam/libcalignmentfile.pyx":962 + * # build header from a target names and lengths + * self.header = AlignmentHeader.from_references( + * reference_names=reference_names, # <<<<<<<<<<<<<< + * reference_lengths=reference_lengths, + * add_sq_text=add_sq_text, */ - goto __pyx_L89; - } - - /* "pysam/libcalignmentfile.pyx":622 - * self.index = NULL - * has_index = False - * elif self.is_cram \ # <<<<<<<<<<<<<< - * and not os.path.exists(filename + b".crai") \ - * and not os.path.exists(filename[:-5] + b".crai"): + __pyx_t_2 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 962, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_reference_names, __pyx_v_reference_names) < 0) __PYX_ERR(0, 962, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":963 + * self.header = AlignmentHeader.from_references( + * reference_names=reference_names, + * reference_lengths=reference_lengths, # <<<<<<<<<<<<<< + * add_sq_text=add_sq_text, + * text=text) + */ + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_reference_lengths, __pyx_v_reference_lengths) < 0) __PYX_ERR(0, 962, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":964 + * reference_names=reference_names, + * reference_lengths=reference_lengths, + * add_sq_text=add_sq_text, # <<<<<<<<<<<<<< + * text=text) + * else: */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 622, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 622, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L95_bool_binop_done; - } + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_add_sq_text, __pyx_v_add_sq_text) < 0) __PYX_ERR(0, 962, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":623 - * has_index = False - * elif self.is_cram \ - * and not os.path.exists(filename + b".crai") \ # <<<<<<<<<<<<<< - * and not os.path.exists(filename[:-5] + b".crai"): - * self.index = NULL + /* "pysam/libcalignmentfile.pyx":965 + * reference_lengths=reference_lengths, + * add_sq_text=add_sq_text, + * text=text) # <<<<<<<<<<<<<< + * else: + * with nogil: */ - __pyx_t_23 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 623, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_23, __pyx_n_s_path); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 623, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_23 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_exists_2); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 623, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Add(__pyx_v_filename, __pyx_kp_b_crai); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 623, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_24 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_23))) { - __pyx_t_24 = PyMethod_GET_SELF(__pyx_t_23); - if (likely(__pyx_t_24)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_23); - __Pyx_INCREF(__pyx_t_24); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_23, function); - } - } - if (!__pyx_t_24) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_23, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 623, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_24, __pyx_t_5}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 623, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_24, __pyx_t_5}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 623, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 623, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_24); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_24); __pyx_t_24 = NULL; - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_23, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 623, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - } - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 623, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_19 = ((!__pyx_t_2) != 0); - if (__pyx_t_19) { - } else { - __pyx_t_1 = __pyx_t_19; - goto __pyx_L95_bool_binop_done; - } + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_text, __pyx_v_text) < 0) __PYX_ERR(0, 962, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":624 - * elif self.is_cram \ - * and not os.path.exists(filename + b".crai") \ - * and not os.path.exists(filename[:-5] + b".crai"): # <<<<<<<<<<<<<< - * self.index = NULL - * has_index = False + /* "pysam/libcalignmentfile.pyx":961 + * if reference_names and reference_lengths: + * # build header from a target names and lengths + * self.header = AlignmentHeader.from_references( # <<<<<<<<<<<<<< + * reference_names=reference_names, + * reference_lengths=reference_lengths, */ - __pyx_t_23 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_23, __pyx_n_s_path); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_23 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_exists_2); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(__pyx_v_filename == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 624, __pyx_L1_error) - } - __pyx_t_3 = PySequence_GetSlice(__pyx_v_filename, 0, -5L); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyNumber_Add(__pyx_t_3, __pyx_kp_b_crai); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 624, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 961, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_23))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_23); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_23); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_23, function); - } - } - if (!__pyx_t_3) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_23, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_5}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_23)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_5}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_23, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_24 = PyTuple_New(1+1); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_24); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_24, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_24, 0+1, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_23, __pyx_t_24, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - } - } - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_2 = ((!__pyx_t_19) != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L95_bool_binop_done:; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 961, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5); + __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":622 - * self.index = NULL - * has_index = False - * elif self.is_cram \ # <<<<<<<<<<<<<< - * and not os.path.exists(filename + b".crai") \ - * and not os.path.exists(filename[:-5] + b".crai"): + /* "pysam/libcalignmentfile.pyx":959 + * # user may provide reference names and lengths to built + * # an on-the-fly header. + * if reference_names and reference_lengths: # <<<<<<<<<<<<<< + * # build header from a target names and lengths + * self.header = AlignmentHeader.from_references( */ - if (__pyx_t_1) { + goto __pyx_L70; + } - /* "pysam/libcalignmentfile.pyx":625 - * and not os.path.exists(filename + b".crai") \ - * and not os.path.exists(filename[:-5] + b".crai"): - * self.index = NULL # <<<<<<<<<<<<<< - * has_index = False + /* "pysam/libcalignmentfile.pyx":967 + * text=text) * else: + * with nogil: # <<<<<<<<<<<<<< + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: */ - __pyx_v_self->index = NULL; + /*else*/ { + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libcalignmentfile.pyx":626 - * and not os.path.exists(filename[:-5] + b".crai"): - * self.index = NULL - * has_index = False # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":968 * else: - * self.index = NULL + * with nogil: + * hdr = sam_hdr_read(self.htsfile) # <<<<<<<<<<<<<< + * if hdr == NULL: + * raise ValueError( */ - __pyx_v_has_index = 0; + __pyx_v_hdr = sam_hdr_read(__pyx_v_self->__pyx_base.htsfile); + } - /* "pysam/libcalignmentfile.pyx":622 - * self.index = NULL - * has_index = False - * elif self.is_cram \ # <<<<<<<<<<<<<< - * and not os.path.exists(filename + b".crai") \ - * and not os.path.exists(filename[:-5] + b".crai"): + /* "pysam/libcalignmentfile.pyx":967 + * text=text) + * else: + * with nogil: # <<<<<<<<<<<<<< + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L75; + } + __pyx_L75:; + } } - __pyx_L89:; - /* "pysam/libcalignmentfile.pyx":614 - * self.index = NULL - * has_index = False - * elif filename is not None: # <<<<<<<<<<<<<< - * if self.is_bam \ - * and not os.path.exists(filename + b".bai") \ + /* "pysam/libcalignmentfile.pyx":969 + * with nogil: + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: # <<<<<<<<<<<<<< + * raise ValueError( + * "SAM? file does not have a valid header (mode='%s'), " */ - goto __pyx_L87; - } + __pyx_t_3 = ((__pyx_v_hdr == NULL) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":628 - * has_index = False - * else: - * self.index = NULL # <<<<<<<<<<<<<< - * has_index = False - * + /* "pysam/libcalignmentfile.pyx":970 + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: + * raise ValueError( # <<<<<<<<<<<<<< + * "SAM? file does not have a valid header (mode='%s'), " + * "please provide reference_names and reference_lengths") + */ + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 970, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 970, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":969 + * with nogil: + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: # <<<<<<<<<<<<<< + * raise ValueError( + * "SAM? file does not have a valid header (mode='%s'), " */ - /*else*/ { - __pyx_v_self->index = NULL; + } - /* "pysam/libcalignmentfile.pyx":629 - * else: - * self.index = NULL - * has_index = False # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":973 + * "SAM? file does not have a valid header (mode='%s'), " + * "please provide reference_names and reference_lengths") + * self.header = makeAlignmentHeader(hdr) # <<<<<<<<<<<<<< * - * if has_index: + * # set filename with reference sequences */ - __pyx_v_has_index = 0; + __pyx_t_5 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 973, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5); + __pyx_t_5 = 0; } - __pyx_L87:; + __pyx_L70:; + } + __pyx_L63:; - /* "pysam/libcalignmentfile.pyx":631 - * has_index = False + /* "pysam/libcalignmentfile.pyx":976 * - * if has_index: # <<<<<<<<<<<<<< - * # returns NULL if there is no index or index could - * # not be opened + * # set filename with reference sequences + * if self.is_cram and reference_filename: # <<<<<<<<<<<<<< + * creference_filename = self.reference_filename + * hts_set_opt(self.htsfile, */ - __pyx_t_1 = (__pyx_v_has_index != 0); - if (__pyx_t_1) { + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 976, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 976, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L78_bool_binop_done; + } + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference_filename); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 976, __pyx_L1_error) + __pyx_t_3 = __pyx_t_1; + __pyx_L78_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":634 - * # returns NULL if there is no index or index could - * # not be opened - * if filepath_index: # <<<<<<<<<<<<<< - * cindexname = filepath_index = encode_filename(filepath_index) - * with nogil: + /* "pysam/libcalignmentfile.pyx":977 + * # set filename with reference sequences + * if self.is_cram and reference_filename: + * creference_filename = self.reference_filename # <<<<<<<<<<<<<< + * hts_set_opt(self.htsfile, + * CRAM_OPT_REFERENCE, */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_filepath_index); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 634, __pyx_L1_error) - if (__pyx_t_1) { + __pyx_t_9 = __Pyx_PyObject_AsWritableString(__pyx_v_self->reference_filename); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 977, __pyx_L1_error) + __pyx_v_creference_filename = __pyx_t_9; - /* "pysam/libcalignmentfile.pyx":635 - * # not be opened - * if filepath_index: - * cindexname = filepath_index = encode_filename(filepath_index) # <<<<<<<<<<<<<< - * with nogil: - * self.index = sam_index_load2(self.htsfile, + /* "pysam/libcalignmentfile.pyx":978 + * if self.is_cram and reference_filename: + * creference_filename = self.reference_filename + * hts_set_opt(self.htsfile, # <<<<<<<<<<<<<< + * CRAM_OPT_REFERENCE, + * creference_filename) */ - __pyx_t_4 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filepath_index); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 635, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (unlikely(__pyx_t_4 == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 635, __pyx_L1_error) - } - __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_t_4); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 635, __pyx_L1_error) - __pyx_v_cindexname = __pyx_t_9; - __Pyx_INCREF(__pyx_t_4); - __Pyx_DECREF_SET(__pyx_v_filepath_index, __pyx_t_4); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + (void)(hts_set_opt(__pyx_v_self->__pyx_base.htsfile, CRAM_OPT_REFERENCE, __pyx_v_creference_filename)); - /* "pysam/libcalignmentfile.pyx":636 - * if filepath_index: - * cindexname = filepath_index = encode_filename(filepath_index) - * with nogil: # <<<<<<<<<<<<<< - * self.index = sam_index_load2(self.htsfile, - * cfilename, + /* "pysam/libcalignmentfile.pyx":976 + * + * # set filename with reference sequences + * if self.is_cram and reference_filename: # <<<<<<<<<<<<<< + * creference_filename = self.reference_filename + * hts_set_opt(self.htsfile, */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + } - /* "pysam/libcalignmentfile.pyx":637 - * cindexname = filepath_index = encode_filename(filepath_index) - * with nogil: - * self.index = sam_index_load2(self.htsfile, # <<<<<<<<<<<<<< - * cfilename, - * cindexname) + /* "pysam/libcalignmentfile.pyx":982 + * creference_filename) + * + * if check_sq and self.header.nreferences == 0: # <<<<<<<<<<<<<< + * raise ValueError( + * ("file has no sequences defined (mode='%s') - " */ - __pyx_v_self->index = sam_index_load2(__pyx_v_self->__pyx_base.htsfile, __pyx_v_cfilename, __pyx_v_cindexname); - } - - /* "pysam/libcalignmentfile.pyx":636 - * if filepath_index: - * cindexname = filepath_index = encode_filename(filepath_index) - * with nogil: # <<<<<<<<<<<<<< - * self.index = sam_index_load2(self.htsfile, - * cfilename, - */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L102; - } - __pyx_L102:; - } - } + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_check_sq); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 982, __pyx_L1_error) + if (__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L81_bool_binop_done; + } + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 982, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 982, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 982, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = __pyx_t_1; + __pyx_L81_bool_binop_done:; + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":634 - * # returns NULL if there is no index or index could - * # not be opened - * if filepath_index: # <<<<<<<<<<<<<< - * cindexname = filepath_index = encode_filename(filepath_index) - * with nogil: + /* "pysam/libcalignmentfile.pyx":986 + * ("file has no sequences defined (mode='%s') - " + * "is it SAM/BAM format? Consider opening with " + * "check_sq=False") % mode) # <<<<<<<<<<<<<< + * + * if self.is_bam or self.is_cram: */ - goto __pyx_L99; - } + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_file_has_no_sequences_defined_mo, __pyx_v_mode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 986, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); - /* "pysam/libcalignmentfile.pyx":641 - * cindexname) - * else: - * with nogil: # <<<<<<<<<<<<<< - * self.index = sam_index_load(self.htsfile, - * cfilename) + /* "pysam/libcalignmentfile.pyx":983 + * + * if check_sq and self.header.nreferences == 0: + * raise ValueError( # <<<<<<<<<<<<<< + * ("file has no sequences defined (mode='%s') - " + * "is it SAM/BAM format? Consider opening with " */ - /*else*/ { - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 983, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 983, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":642 - * else: - * with nogil: - * self.index = sam_index_load(self.htsfile, # <<<<<<<<<<<<<< - * cfilename) - * if self.index == NULL: + /* "pysam/libcalignmentfile.pyx":982 + * creference_filename) + * + * if check_sq and self.header.nreferences == 0: # <<<<<<<<<<<<<< + * raise ValueError( + * ("file has no sequences defined (mode='%s') - " */ - __pyx_v_self->index = sam_index_load(__pyx_v_self->__pyx_base.htsfile, __pyx_v_cfilename); - } - - /* "pysam/libcalignmentfile.pyx":641 - * cindexname) - * else: - * with nogil: # <<<<<<<<<<<<<< - * self.index = sam_index_load(self.htsfile, - * cfilename) - */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L105; - } - __pyx_L105:; - } - } - } - __pyx_L99:; + } - /* "pysam/libcalignmentfile.pyx":644 - * self.index = sam_index_load(self.htsfile, - * cfilename) - * if self.index == NULL: # <<<<<<<<<<<<<< - * raise IOError( - * "error while opening index for '%s'" % + /* "pysam/libcalignmentfile.pyx":988 + * "check_sq=False") % mode) + * + * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< + * self.index_filename = index_filename or filepath_index + * if self.index_filename: */ - __pyx_t_1 = ((__pyx_v_self->index == NULL) != 0); - if (unlikely(__pyx_t_1)) { + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 988, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 988, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L84_bool_binop_done; + } + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 988, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 988, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __pyx_t_1; + __pyx_L84_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":646 - * if self.index == NULL: - * raise IOError( - * "error while opening index for '%s'" % # <<<<<<<<<<<<<< - * filename) + /* "pysam/libcalignmentfile.pyx":989 * + * if self.is_bam or self.is_cram: + * self.index_filename = index_filename or filepath_index # <<<<<<<<<<<<<< + * if self.index_filename: + * cindexname = bfile_name = encode_filename(self.index_filename) */ - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_error_while_opening_index_for_s, __pyx_v_filename); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 646, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_index_filename); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 989, __pyx_L1_error) + if (!__pyx_t_3) { + } else { + __Pyx_INCREF(__pyx_v_index_filename); + __pyx_t_5 = __pyx_v_index_filename; + goto __pyx_L86_bool_binop_done; + } + __Pyx_INCREF(__pyx_v_filepath_index); + __pyx_t_5 = __pyx_v_filepath_index; + __pyx_L86_bool_binop_done:; + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.index_filename); + __Pyx_DECREF(__pyx_v_self->__pyx_base.index_filename); + __pyx_v_self->__pyx_base.index_filename = __pyx_t_5; + __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":645 - * cfilename) - * if self.index == NULL: - * raise IOError( # <<<<<<<<<<<<<< - * "error while opening index for '%s'" % - * filename) + /* "pysam/libcalignmentfile.pyx":990 + * if self.is_bam or self.is_cram: + * self.index_filename = index_filename or filepath_index + * if self.index_filename: # <<<<<<<<<<<<<< + * cindexname = bfile_name = encode_filename(self.index_filename) + * */ - __pyx_t_23 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 645, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_23); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_23, 0, 0, 0); - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __PYX_ERR(0, 645, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_self->__pyx_base.index_filename); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 990, __pyx_L1_error) + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":644 - * self.index = sam_index_load(self.htsfile, - * cfilename) - * if self.index == NULL: # <<<<<<<<<<<<<< - * raise IOError( - * "error while opening index for '%s'" % + /* "pysam/libcalignmentfile.pyx":991 + * self.index_filename = index_filename or filepath_index + * if self.index_filename: + * cindexname = bfile_name = encode_filename(self.index_filename) # <<<<<<<<<<<<<< + * + * if cfilename or cindexname: */ + __pyx_t_5 = __pyx_v_self->__pyx_base.index_filename; + __Pyx_INCREF(__pyx_t_5); + __pyx_t_2 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 991, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(__pyx_t_2 == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 991, __pyx_L1_error) } + __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_t_2); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 991, __pyx_L1_error) + __pyx_v_cindexname = __pyx_t_9; + __Pyx_INCREF(__pyx_t_2); + __pyx_v_bfile_name = ((PyObject*)__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":631 - * has_index = False + /* "pysam/libcalignmentfile.pyx":990 + * if self.is_bam or self.is_cram: + * self.index_filename = index_filename or filepath_index + * if self.index_filename: # <<<<<<<<<<<<<< + * cindexname = bfile_name = encode_filename(self.index_filename) * - * if has_index: # <<<<<<<<<<<<<< - * # returns NULL if there is no index or index could - * # not be opened */ } - } - __pyx_L80:; - - /* "pysam/libcalignmentfile.pyx":650 - * - * # save start of data section - * if not self.is_stream: # <<<<<<<<<<<<<< - * self.start_offset = self.tell() - * - */ - __pyx_t_1 = ((!(__pyx_v_self->__pyx_base.is_stream != 0)) != 0); - if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":651 - * # save start of data section - * if not self.is_stream: - * self.start_offset = self.tell() # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":993 + * cindexname = bfile_name = encode_filename(self.index_filename) * - * def get_tid(self, reference): + * if cfilename or cindexname: # <<<<<<<<<<<<<< + * with nogil: + * self.index = sam_index_load2(self.htsfile, cfilename, cindexname) */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tell); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 651, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_24 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_24 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_24)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_24); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (__pyx_t_24) { - __pyx_t_23 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_24); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 651, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + __pyx_t_1 = (__pyx_v_cfilename != 0); + if (!__pyx_t_1) { } else { - __pyx_t_23 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 651, __pyx_L1_error) + __pyx_t_3 = __pyx_t_1; + goto __pyx_L90_bool_binop_done; } - __Pyx_GOTREF(__pyx_t_23); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_25 = __Pyx_PyInt_As_int64_t(__pyx_t_23); if (unlikely((__pyx_t_25 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 651, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; - __pyx_v_self->__pyx_base.start_offset = __pyx_t_25; + __pyx_t_1 = (__pyx_v_cindexname != 0); + __pyx_t_3 = __pyx_t_1; + __pyx_L90_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":650 + /* "pysam/libcalignmentfile.pyx":994 * - * # save start of data section - * if not self.is_stream: # <<<<<<<<<<<<<< - * self.start_offset = self.tell() + * if cfilename or cindexname: + * with nogil: # <<<<<<<<<<<<<< + * self.index = sam_index_load2(self.htsfile, cfilename, cindexname) * */ - } + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libcalignmentfile.pyx":598 - * format_index = HTS_FMT_CRAI + /* "pysam/libcalignmentfile.pyx":995 + * if cfilename or cindexname: + * with nogil: + * self.index = sam_index_load2(self.htsfile, cfilename, cindexname) # <<<<<<<<<<<<<< * - * if mode[0] == "r" and (self.is_bam or self.is_cram): # <<<<<<<<<<<<<< - * # open index for remote files - * if self.is_remote and not filepath_index: + * if not self.index and (cindexname or require_index): */ - } + __pyx_v_self->index = sam_index_load2(__pyx_v_self->__pyx_base.htsfile, __pyx_v_cfilename, __pyx_v_cindexname); + } - /* "pysam/libcalignmentfile.pyx":385 - * return True + /* "pysam/libcalignmentfile.pyx":994 * - * def _open(self, # <<<<<<<<<<<<<< - * filepath_or_object, - * mode=None, - */ - - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_23); - __Pyx_XDECREF(__pyx_t_24); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_filename); - __Pyx_XDECREF(__pyx_v_n); - __Pyx_XDECREF(__pyx_v_x); - __Pyx_XDECREF(__pyx_v_name); - __Pyx_XDECREF(__pyx_v_ref); - __Pyx_XDECREF(__pyx_v_mode); - __Pyx_XDECREF(__pyx_v_reference_names); - __Pyx_XDECREF(__pyx_v_reference_lengths); - __Pyx_XDECREF(__pyx_v_reference_filename); - __Pyx_XDECREF(__pyx_v_text); - __Pyx_XDECREF(__pyx_v_filepath_index); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignmentfile.pyx":653 - * self.start_offset = self.tell() + * if cfilename or cindexname: + * with nogil: # <<<<<<<<<<<<<< + * self.index = sam_index_load2(self.htsfile, cfilename, cindexname) * - * def get_tid(self, reference): # <<<<<<<<<<<<<< - * """ - * return the numerical :term:`tid` corresponding to */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L94; + } + __pyx_L94:; + } + } -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_8get_tid[] = "AlignmentFile.get_tid(self, reference)\n\n return the numerical :term:`tid` corresponding to\n :term:`reference`\n\n returns -1 if reference is not known.\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_tid (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8get_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_reference)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - char const *__pyx_t_4; - __Pyx_RefNannySetupContext("get_tid", 0); - __Pyx_TraceCall("get_tid", __pyx_f[0], 653, 0, __PYX_ERR(0, 653, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_reference); - - /* "pysam/libcalignmentfile.pyx":660 - * returns -1 if reference is not known. - * """ - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") - * reference = force_bytes(reference) + /* "pysam/libcalignmentfile.pyx":997 + * self.index = sam_index_load2(self.htsfile, cfilename, cindexname) + * + * if not self.index and (cindexname or require_index): # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, force_str(strerror(errno))) */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 660, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { + __pyx_t_1 = ((!(__pyx_v_self->index != 0)) != 0); + if (__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L96_bool_binop_done; + } + __pyx_t_1 = (__pyx_v_cindexname != 0); + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L96_bool_binop_done; + } + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_require_index); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 997, __pyx_L1_error) + __pyx_t_3 = __pyx_t_1; + __pyx_L96_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":661 - * """ - * if not self.is_open: - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< - * reference = force_bytes(reference) - * return bam_name2id(self.header, reference) + /* "pysam/libcalignmentfile.pyx":998 + * + * if not self.index and (cindexname or require_index): + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, force_str(strerror(errno))) + * else: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 661, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 661, __pyx_L1_error) + __pyx_t_3 = (errno != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":660 - * returns -1 if reference is not known. - * """ - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") - * reference = force_bytes(reference) + /* "pysam/libcalignmentfile.pyx":999 + * if not self.index and (cindexname or require_index): + * if errno: + * raise IOError(errno, force_str(strerror(errno))) # <<<<<<<<<<<<<< + * else: + * raise IOError('unable to open index file `%s`' % self.index_filename) */ - } - - /* "pysam/libcalignmentfile.pyx":662 - * if not self.is_open: - * raise ValueError("I/O operation on closed file") - * reference = force_bytes(reference) # <<<<<<<<<<<<<< - * return bam_name2id(self.header, reference) + __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 999, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 999, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_11 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_5, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 999, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 999, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_11); + __pyx_t_2 = 0; + __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 999, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_11, 0, 0, 0); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __PYX_ERR(0, 999, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":998 * + * if not self.index and (cindexname or require_index): + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, force_str(strerror(errno))) + * else: */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_reference, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 662, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF_SET(__pyx_v_reference, __pyx_t_1); - __pyx_t_1 = 0; + } - /* "pysam/libcalignmentfile.pyx":663 - * raise ValueError("I/O operation on closed file") - * reference = force_bytes(reference) - * return bam_name2id(self.header, reference) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1001 + * raise IOError(errno, force_str(strerror(errno))) + * else: + * raise IOError('unable to open index file `%s`' % self.index_filename) # <<<<<<<<<<<<<< * - * def get_reference_name(self, tid): + * elif require_index: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_v_reference); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 663, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyInt_From_int(bam_name2id(__pyx_v_self->header, __pyx_t_4)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 663, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + /*else*/ { + __pyx_t_11 = __Pyx_PyString_Format(__pyx_kp_s_unable_to_open_index_file_s, __pyx_v_self->__pyx_base.index_filename); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1001, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1001, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 1001, __pyx_L1_error) + } - /* "pysam/libcalignmentfile.pyx":653 - * self.start_offset = self.tell() + /* "pysam/libcalignmentfile.pyx":997 + * self.index = sam_index_load2(self.htsfile, cfilename, cindexname) * - * def get_tid(self, reference): # <<<<<<<<<<<<<< - * """ - * return the numerical :term:`tid` corresponding to + * if not self.index and (cindexname or require_index): # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, force_str(strerror(errno))) */ + } - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_tid", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_reference); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignmentfile.pyx":665 - * return bam_name2id(self.header, reference) + /* "pysam/libcalignmentfile.pyx":993 + * cindexname = bfile_name = encode_filename(self.index_filename) * - * def get_reference_name(self, tid): # <<<<<<<<<<<<<< - * """ - * return :term:`reference` name corresponding to numerical :term:`tid` + * if cfilename or cindexname: # <<<<<<<<<<<<<< + * with nogil: + * self.index = sam_index_load2(self.htsfile, cfilename, cindexname) */ + goto __pyx_L89; + } -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_10get_reference_name[] = "AlignmentFile.get_reference_name(self, tid)\n\n return :term:`reference` name corresponding to numerical :term:`tid`\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_reference_name (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10get_reference_name(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_tid)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - Py_ssize_t __pyx_t_5; - __Pyx_RefNannySetupContext("get_reference_name", 0); - __Pyx_TraceCall("get_reference_name", __pyx_f[0], 665, 0, __PYX_ERR(0, 665, __pyx_L1_error)); - - /* "pysam/libcalignmentfile.pyx":669 - * return :term:`reference` name corresponding to numerical :term:`tid` - * """ - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") - * if not 0 <= tid < self.header.n_targets: + /* "pysam/libcalignmentfile.pyx":1003 + * raise IOError('unable to open index file `%s`' % self.index_filename) + * + * elif require_index: # <<<<<<<<<<<<<< + * raise IOError('unable to open index file') + * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_require_index); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1003, __pyx_L1_error) + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":670 - * """ - * if not self.is_open: - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< - * if not 0 <= tid < self.header.n_targets: - * raise ValueError("reference_id %i out of range 0<=tid<%i" % + /* "pysam/libcalignmentfile.pyx":1004 + * + * elif require_index: + * raise IOError('unable to open index file') # <<<<<<<<<<<<<< + * + * # save start of data section */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 670, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 670, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1004, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 1004, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":669 - * return :term:`reference` name corresponding to numerical :term:`tid` - * """ - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") - * if not 0 <= tid < self.header.n_targets: + /* "pysam/libcalignmentfile.pyx":1003 + * raise IOError('unable to open index file `%s`' % self.index_filename) + * + * elif require_index: # <<<<<<<<<<<<<< + * raise IOError('unable to open index file') + * */ - } + } + __pyx_L89:; - /* "pysam/libcalignmentfile.pyx":671 - * if not self.is_open: - * raise ValueError("I/O operation on closed file") - * if not 0 <= tid < self.header.n_targets: # <<<<<<<<<<<<<< - * raise ValueError("reference_id %i out of range 0<=tid<%i" % - * (tid, self.header.n_targets)) + /* "pysam/libcalignmentfile.pyx":1007 + * + * # save start of data section + * if not self.is_stream: # <<<<<<<<<<<<<< + * self.start_offset = self.tell() + * */ - __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_tid, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 671, __pyx_L1_error) - if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { - __Pyx_DECREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_self->header->n_targets); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 671, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyObject_RichCompare(__pyx_v_tid, __pyx_t_4, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 671, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 671, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_2 = ((!__pyx_t_3) != 0); - if (unlikely(__pyx_t_2)) { + __pyx_t_3 = ((!(__pyx_v_self->__pyx_base.is_stream != 0)) != 0); + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":673 - * if not 0 <= tid < self.header.n_targets: - * raise ValueError("reference_id %i out of range 0<=tid<%i" % - * (tid, self.header.n_targets)) # <<<<<<<<<<<<<< - * return charptr_to_str(self.header.target_name[tid]) + /* "pysam/libcalignmentfile.pyx":1008 + * # save start of data section + * if not self.is_stream: + * self.start_offset = self.tell() # <<<<<<<<<<<<<< * + * def fetch(self, */ - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->header->n_targets); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 673, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 673, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_tid); - __Pyx_GIVEREF(__pyx_v_tid); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_tid); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tell); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1008, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + if (__pyx_t_2) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1008, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1008, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_20 = __Pyx_PyInt_As_int64_t(__pyx_t_5); if (unlikely((__pyx_t_20 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1008, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_self->__pyx_base.start_offset = __pyx_t_20; - /* "pysam/libcalignmentfile.pyx":672 - * raise ValueError("I/O operation on closed file") - * if not 0 <= tid < self.header.n_targets: - * raise ValueError("reference_id %i out of range 0<=tid<%i" % # <<<<<<<<<<<<<< - * (tid, self.header.n_targets)) - * return charptr_to_str(self.header.target_name[tid]) + /* "pysam/libcalignmentfile.pyx":1007 + * + * # save start of data section + * if not self.is_stream: # <<<<<<<<<<<<<< + * self.start_offset = self.tell() + * */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_reference_id_i_out_of_range_0_ti, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 672, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 672, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 672, __pyx_L1_error) + } - /* "pysam/libcalignmentfile.pyx":671 - * if not self.is_open: - * raise ValueError("I/O operation on closed file") - * if not 0 <= tid < self.header.n_targets: # <<<<<<<<<<<<<< - * raise ValueError("reference_id %i out of range 0<=tid<%i" % - * (tid, self.header.n_targets)) + /* "pysam/libcalignmentfile.pyx":988 + * "check_sq=False") % mode) + * + * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< + * self.index_filename = index_filename or filepath_index + * if self.index_filename: */ - } + } - /* "pysam/libcalignmentfile.pyx":674 - * raise ValueError("reference_id %i out of range 0<=tid<%i" % - * (tid, self.header.n_targets)) - * return charptr_to_str(self.header.target_name[tid]) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":927 + * sam_hdr_write(self.htsfile, hdr) * - * def parse_region(self, + * elif mode[0] == "r": # <<<<<<<<<<<<<< + * # open file for reading + * self.htsfile = self._open_htsfile() */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_tid); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 674, __pyx_L1_error) - __pyx_t_4 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_self->header->target_name[__pyx_t_5]), NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; + } + __pyx_L34:; - /* "pysam/libcalignmentfile.pyx":665 - * return bam_name2id(self.header, reference) + /* "pysam/libcalignmentfile.pyx":770 + * return True * - * def get_reference_name(self, tid): # <<<<<<<<<<<<<< - * """ - * return :term:`reference` name corresponding to numerical :term:`tid` + * def _open(self, # <<<<<<<<<<<<<< + * filepath_or_object, + * mode=None, */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_reference_name", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_15); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_filename); + __Pyx_XDECREF(__pyx_v_bfile_name); + __Pyx_XDECREF(__pyx_v_mode); + __Pyx_XDECREF(__pyx_v_reference_names); + __Pyx_XDECREF(__pyx_v_reference_lengths); + __Pyx_XDECREF(__pyx_v_reference_filename); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":676 - * return charptr_to_str(self.header.target_name[tid]) +/* "pysam/libcalignmentfile.pyx":1010 + * self.start_offset = self.tell() * - * def parse_region(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * def fetch(self, # <<<<<<<<<<<<<< + * contig=None, + * start=None, */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13parse_region(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_12parse_region[] = "AlignmentFile.parse_region(self, reference=None, start=None, end=None, region=None, tid=None)\nparse alternative ways to specify a genomic region. A region can\n either be specified by :term:`reference`, `start` and\n `end`. `start` and `end` denote 0-based, half-open\n intervals.\n\n Alternatively, a samtools :term:`region` string can be\n supplied.\n \n If any of the coordinates are missing they will be replaced by the\n minimum (`start`) or maximum (`end`) coordinate.\n\n Note that region strings are 1-based, while `start` and `end` denote\n an interval in python coordinates.\n\n Returns\n -------\n \n tuple : a tuple of `flag`, :term:`tid`, `start` and `end`. The\n flag indicates whether no coordinates were supplied and the\n genomic region is the complete genomic space.\n\n Raises\n ------\n \n ValueError\n for invalid or out of bounds regions.\n\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13parse_region(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_reference = 0; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_8fetch[] = "AlignmentFile.fetch(self, contig=None, start=None, stop=None, region=None, tid=None, until_eof=False, multiple_iterators=False, reference=None, end=None)\nfetch reads aligned in a :term:`region`.\n\n See :meth:`AlignmentFile.parse_region` for more information\n on genomic regions. :term:`reference` and `end` are also accepted for\n backward compatiblity as synonyms for :term:`contig` and `stop`,\n respectively.\n\n Without a `contig` or `region` all mapped reads in the file\n will be fetched. The reads will be returned ordered by reference\n sequence, which will not necessarily be the order within the\n file. This mode of iteration still requires an index. If there is\n no index, use `until_eof=True`.\n\n If only `reference` is set, all reads aligned to `reference`\n will be fetched.\n\n A :term:`SAM` file does not allow random access. If `region`\n or `contig` are given, an exception is raised.\n\n :class:`~pysam.FastaFile`\n :class:`~pysam.IteratorRow`\n :class:`~pysam.IteratorRow`\n :class:`~IteratorRow`\n :class:`IteratorRow`\n\n Parameters\n ----------\n\n until_eof : bool\n\n If `until_eof` is True, all reads from the current file\n position will be returned in order as they are within the\n file. Using this option will also fetch unmapped reads.\n\n multiple_iterators : bool\n\n If `multiple_iterators` is True, multiple\n iterators on the same file can be used at the same time. The\n iterator returned will receive its own copy of a filehandle to\n the file effectively re-opening the file. Re-opening a file\n creates some overhead, so beware.\n\n Returns\n -------\n\n An iterator over a collection of reads.\n\n Raises\n ------\n\n ValueError\n if the genomic coordinates are out"" of range or invalid or the\n file does not permit random access to genomic coordinates.\n\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_contig = 0; PyObject *__pyx_v_start = 0; - PyObject *__pyx_v_end = 0; + PyObject *__pyx_v_stop = 0; PyObject *__pyx_v_region = 0; PyObject *__pyx_v_tid = 0; + PyObject *__pyx_v_until_eof = 0; + PyObject *__pyx_v_multiple_iterators = 0; + PyObject *__pyx_v_reference = 0; + PyObject *__pyx_v_end = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("parse_region (wrapper)", 0); + __Pyx_RefNannySetupContext("fetch (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,&__pyx_n_s_tid,0}; - PyObject* values[5] = {0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_tid,&__pyx_n_s_until_eof,&__pyx_n_s_multiple_iterators,&__pyx_n_s_reference,&__pyx_n_s_end,0}; + PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; - /* "pysam/libcalignmentfile.pyx":677 + /* "pysam/libcalignmentfile.pyx":1011 * - * def parse_region(self, - * reference=None, # <<<<<<<<<<<<<< - * start=None, - * end=None, + * def fetch(self, + * contig=None, # <<<<<<<<<<<<<< + * start=None, + * stop=None, */ values[0] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":678 - * def parse_region(self, - * reference=None, - * start=None, # <<<<<<<<<<<<<< - * end=None, - * region=None, + /* "pysam/libcalignmentfile.pyx":1012 + * def fetch(self, + * contig=None, + * start=None, # <<<<<<<<<<<<<< + * stop=None, + * region=None, */ values[1] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":679 - * reference=None, - * start=None, - * end=None, # <<<<<<<<<<<<<< - * region=None, - * tid=None): + /* "pysam/libcalignmentfile.pyx":1013 + * contig=None, + * start=None, + * stop=None, # <<<<<<<<<<<<<< + * region=None, + * tid=None, */ values[2] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":680 - * start=None, - * end=None, - * region=None, # <<<<<<<<<<<<<< - * tid=None): - * """parse alternative ways to specify a genomic region. A region can + /* "pysam/libcalignmentfile.pyx":1014 + * start=None, + * stop=None, + * region=None, # <<<<<<<<<<<<<< + * tid=None, + * until_eof=False, */ values[3] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":681 - * end=None, - * region=None, - * tid=None): # <<<<<<<<<<<<<< - * """parse alternative ways to specify a genomic region. A region can - * either be specified by :term:`reference`, `start` and + /* "pysam/libcalignmentfile.pyx":1015 + * stop=None, + * region=None, + * tid=None, # <<<<<<<<<<<<<< + * until_eof=False, + * multiple_iterators=False, */ values[4] = ((PyObject *)Py_None); + + /* "pysam/libcalignmentfile.pyx":1016 + * region=None, + * tid=None, + * until_eof=False, # <<<<<<<<<<<<<< + * multiple_iterators=False, + * reference=None, + */ + values[5] = ((PyObject *)Py_False); + + /* "pysam/libcalignmentfile.pyx":1017 + * tid=None, + * until_eof=False, + * multiple_iterators=False, # <<<<<<<<<<<<<< + * reference=None, + * end=None): + */ + values[6] = ((PyObject *)Py_False); + + /* "pysam/libcalignmentfile.pyx":1018 + * until_eof=False, + * multiple_iterators=False, + * reference=None, # <<<<<<<<<<<<<< + * end=None): + * """fetch reads aligned in a :term:`region`. + */ + values[7] = ((PyObject *)Py_None); + + /* "pysam/libcalignmentfile.pyx":1019 + * multiple_iterators=False, + * reference=None, + * end=None): # <<<<<<<<<<<<<< + * """fetch reads aligned in a :term:`region`. + * + */ + values[8] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + CYTHON_FALLTHROUGH; + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -9908,7 +15324,7 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13parse_reg switch (pos_args) { case 0: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_contig); if (value) { values[0] = value; kw_args--; } } CYTHON_FALLTHROUGH; @@ -9920,7 +15336,7 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13parse_reg CYTHON_FALLTHROUGH; case 2: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop); if (value) { values[2] = value; kw_args--; } } CYTHON_FALLTHROUGH; @@ -9932,15 +15348,47 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13parse_reg CYTHON_FALLTHROUGH; case 4: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tid); - if (value) { values[4] = value; kw_args--; } + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tid); + if (value) { values[4] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 5: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_until_eof); + if (value) { values[5] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 6: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators); + if (value) { values[6] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 7: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); + if (value) { values[7] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 8: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); + if (value) { values[8] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "parse_region") < 0)) __PYX_ERR(0, 676, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 1010, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + CYTHON_FALLTHROUGH; + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -9955,28 +15403,32 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13parse_reg default: goto __pyx_L5_argtuple_error; } } - __pyx_v_reference = values[0]; + __pyx_v_contig = values[0]; __pyx_v_start = values[1]; - __pyx_v_end = values[2]; + __pyx_v_stop = values[2]; __pyx_v_region = values[3]; __pyx_v_tid = values[4]; + __pyx_v_until_eof = values[5]; + __pyx_v_multiple_iterators = values[6]; + __pyx_v_reference = values[7]; + __pyx_v_end = values[8]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("parse_region", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 676, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 9, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1010, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.parse_region", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12parse_region(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_tid); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8fetch(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_tid, __pyx_v_until_eof, __pyx_v_multiple_iterators, __pyx_v_reference, __pyx_v_end); - /* "pysam/libcalignmentfile.pyx":676 - * return charptr_to_str(self.header.target_name[tid]) + /* "pysam/libcalignmentfile.pyx":1010 + * self.start_offset = self.tell() * - * def parse_region(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * def fetch(self, # <<<<<<<<<<<<<< + * contig=None, + * start=None, */ /* function exit code */ @@ -9984,929 +15436,711 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13parse_reg return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12parse_region(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_tid) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8fetch(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_multiple_iterators, PyObject *__pyx_v_reference, PyObject *__pyx_v_end) { int __pyx_v_rtid; - PY_LONG_LONG __pyx_v_rstart; - PY_LONG_LONG __pyx_v_rend; - PyObject *__pyx_v_parts = NULL; + int __pyx_v_rstart; + int __pyx_v_rstop; + int __pyx_v_has_coord; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; + int __pyx_t_3; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; - PY_LONG_LONG __pyx_t_6; - int __pyx_t_7; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - Py_ssize_t __pyx_t_12; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_t_10; + int __pyx_t_11; + int __pyx_t_12; int __pyx_t_13; - __Pyx_RefNannySetupContext("parse_region", 0); - __Pyx_TraceCall("parse_region", __pyx_f[0], 676, 0, __PYX_ERR(0, 676, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_reference); - __Pyx_INCREF(__pyx_v_region); + int __pyx_t_14; + __Pyx_RefNannySetupContext("fetch", 0); + __Pyx_TraceCall("fetch", __pyx_f[0], 1010, 0, __PYX_ERR(0, 1010, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_multiple_iterators); - /* "pysam/libcalignmentfile.pyx":714 - * cdef long long rend + /* "pysam/libcalignmentfile.pyx":1077 + * cdef int rtid, rstart, rstop, has_coord * - * rtid = -1 # <<<<<<<<<<<<<< - * rstart = 0 - * rend = MAX_POS - */ - __pyx_v_rtid = -1; - - /* "pysam/libcalignmentfile.pyx":715 + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError( "I/O operation on closed file" ) * - * rtid = -1 - * rstart = 0 # <<<<<<<<<<<<<< - * rend = MAX_POS - * if start != None: - */ - __pyx_v_rstart = 0; - - /* "pysam/libcalignmentfile.pyx":716 - * rtid = -1 - * rstart = 0 - * rend = MAX_POS # <<<<<<<<<<<<<< - * if start != None: - * try: - */ - __pyx_v_rend = __pyx_v_5pysam_17libcalignmentfile_MAX_POS; - - /* "pysam/libcalignmentfile.pyx":717 - * rstart = 0 - * rend = MAX_POS - * if start != None: # <<<<<<<<<<<<<< - * try: - * rstart = start */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 717, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 717, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1077, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1077, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "pysam/libcalignmentfile.pyx":718 - * rend = MAX_POS - * if start != None: - * try: # <<<<<<<<<<<<<< - * rstart = start - * except OverflowError: - */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_4); - __Pyx_XGOTREF(__pyx_t_5); - /*try:*/ { - - /* "pysam/libcalignmentfile.pyx":719 - * if start != None: - * try: - * rstart = start # <<<<<<<<<<<<<< - * except OverflowError: - * raise ValueError('start out of range (%i)' % start) - */ - __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_start); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 719, __pyx_L4_error) - __pyx_v_rstart = __pyx_t_6; - - /* "pysam/libcalignmentfile.pyx":718 - * rend = MAX_POS - * if start != None: - * try: # <<<<<<<<<<<<<< - * rstart = start - * except OverflowError: - */ - } - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L9_try_end; - __pyx_L4_error:; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = ((!__pyx_t_2) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":720 - * try: - * rstart = start - * except OverflowError: # <<<<<<<<<<<<<< - * raise ValueError('start out of range (%i)' % start) + /* "pysam/libcalignmentfile.pyx":1078 * - */ - __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError); - if (__pyx_t_7) { - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.parse_region", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_8, &__pyx_t_9) < 0) __PYX_ERR(0, 720, __pyx_L6_except_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GOTREF(__pyx_t_9); - - /* "pysam/libcalignmentfile.pyx":721 - * rstart = start - * except OverflowError: - * raise ValueError('start out of range (%i)' % start) # <<<<<<<<<<<<<< + * if not self.is_open: + * raise ValueError( "I/O operation on closed file" ) # <<<<<<<<<<<<<< * - * if end != None: - */ - __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_v_start); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 721, __pyx_L6_except_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 721, __pyx_L6_except_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_Raise(__pyx_t_11, 0, 0, 0); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __PYX_ERR(0, 721, __pyx_L6_except_error) - } - goto __pyx_L6_except_error; - __pyx_L6_except_error:; - - /* "pysam/libcalignmentfile.pyx":718 - * rend = MAX_POS - * if start != None: - * try: # <<<<<<<<<<<<<< - * rstart = start - * except OverflowError: + * has_coord, rtid, rstart, rstop = self.parse_region( */ - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5); - goto __pyx_L1_error; - __pyx_L9_try_end:; - } + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1078, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 1078, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":717 - * rstart = 0 - * rend = MAX_POS - * if start != None: # <<<<<<<<<<<<<< - * try: - * rstart = start + /* "pysam/libcalignmentfile.pyx":1077 + * cdef int rtid, rstart, rstop, has_coord + * + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError( "I/O operation on closed file" ) + * */ } - /* "pysam/libcalignmentfile.pyx":723 - * raise ValueError('start out of range (%i)' % start) + /* "pysam/libcalignmentfile.pyx":1080 + * raise ValueError( "I/O operation on closed file" ) * - * if end != None: # <<<<<<<<<<<<<< - * try: - * rend = end + * has_coord, rtid, rstart, rstop = self.parse_region( # <<<<<<<<<<<<<< + * contig, start, stop, region, tid, + * end=end, reference=reference) */ - __pyx_t_9 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 723, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 723, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_parse_region); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libcalignmentfile.pyx":724 + /* "pysam/libcalignmentfile.pyx":1081 + * + * has_coord, rtid, rstart, rstop = self.parse_region( + * contig, start, stop, region, tid, # <<<<<<<<<<<<<< + * end=end, reference=reference) * - * if end != None: - * try: # <<<<<<<<<<<<<< - * rend = end - * except OverflowError: */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_4, &__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_4); - __Pyx_XGOTREF(__pyx_t_3); - /*try:*/ { + __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_contig); + __Pyx_GIVEREF(__pyx_v_contig); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_contig); + __Pyx_INCREF(__pyx_v_start); + __Pyx_GIVEREF(__pyx_v_start); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_start); + __Pyx_INCREF(__pyx_v_stop); + __Pyx_GIVEREF(__pyx_v_stop); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_stop); + __Pyx_INCREF(__pyx_v_region); + __Pyx_GIVEREF(__pyx_v_region); + PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_region); + __Pyx_INCREF(__pyx_v_tid); + __Pyx_GIVEREF(__pyx_v_tid); + PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_tid); - /* "pysam/libcalignmentfile.pyx":725 - * if end != None: - * try: - * rend = end # <<<<<<<<<<<<<< - * except OverflowError: - * raise ValueError('end out of range (%i)' % end) + /* "pysam/libcalignmentfile.pyx":1082 + * has_coord, rtid, rstart, rstop = self.parse_region( + * contig, start, stop, region, tid, + * end=end, reference=reference) # <<<<<<<<<<<<<< + * + * # Turn of re-opening if htsfile is a stream */ - __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_end); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 725, __pyx_L13_error) - __pyx_v_rend = __pyx_t_6; + __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1082, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1082, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1082, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":724 + /* "pysam/libcalignmentfile.pyx":1080 + * raise ValueError( "I/O operation on closed file" ) * - * if end != None: - * try: # <<<<<<<<<<<<<< - * rend = end - * except OverflowError: + * has_coord, rtid, rstart, rstop = self.parse_region( # <<<<<<<<<<<<<< + * contig, start, stop, region, tid, + * end=end, reference=reference) */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { + PyObject* sequence = __pyx_t_6; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 4)) { + if (size > 4) __Pyx_RaiseTooManyValuesError(4); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1080, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_4 = PyList_GET_ITEM(sequence, 1); + __pyx_t_1 = PyList_GET_ITEM(sequence, 2); + __pyx_t_7 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_7); + #else + { + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_1,&__pyx_t_7}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1080, __pyx_L1_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L18_try_end; - __pyx_L13_error:; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + } + #endif + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else { + Py_ssize_t index = -1; + PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_1,&__pyx_t_7}; + __pyx_t_8 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; + for (index=0; index < 4; index++) { + PyObject* item = __pyx_t_9(__pyx_t_8); if (unlikely(!item)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) __PYX_ERR(0, 1080, __pyx_L1_error) + __pyx_t_9 = NULL; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L5_unpacking_done; + __pyx_L4_unpacking_failed:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1080, __pyx_L1_error) + __pyx_L5_unpacking_done:; + } + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1080, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1080, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1080, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1080, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_has_coord = __pyx_t_10; + __pyx_v_rtid = __pyx_t_11; + __pyx_v_rstart = __pyx_t_12; + __pyx_v_rstop = __pyx_t_13; - /* "pysam/libcalignmentfile.pyx":726 - * try: - * rend = end - * except OverflowError: # <<<<<<<<<<<<<< - * raise ValueError('end out of range (%i)' % end) + /* "pysam/libcalignmentfile.pyx":1085 * - */ - __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError); - if (__pyx_t_7) { - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.parse_region", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_8, &__pyx_t_1) < 0) __PYX_ERR(0, 726, __pyx_L15_except_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GOTREF(__pyx_t_1); - - /* "pysam/libcalignmentfile.pyx":727 - * rend = end - * except OverflowError: - * raise ValueError('end out of range (%i)' % end) # <<<<<<<<<<<<<< + * # Turn of re-opening if htsfile is a stream + * if self.is_stream: # <<<<<<<<<<<<<< + * multiple_iterators = False * - * if region: */ - __pyx_t_11 = __Pyx_PyString_Format(__pyx_kp_s_end_out_of_range_i, __pyx_v_end); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 727, __pyx_L15_except_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 727, __pyx_L15_except_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_Raise(__pyx_t_10, 0, 0, 0); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __PYX_ERR(0, 727, __pyx_L15_except_error) - } - goto __pyx_L15_except_error; - __pyx_L15_except_error:; + __pyx_t_3 = (__pyx_v_self->__pyx_base.is_stream != 0); + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":724 + /* "pysam/libcalignmentfile.pyx":1086 + * # Turn of re-opening if htsfile is a stream + * if self.is_stream: + * multiple_iterators = False # <<<<<<<<<<<<<< * - * if end != None: - * try: # <<<<<<<<<<<<<< - * rend = end - * except OverflowError: + * if self.is_bam or self.is_cram: */ - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_4); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_4, __pyx_t_3); - goto __pyx_L1_error; - __pyx_L18_try_end:; - } + __Pyx_INCREF(Py_False); + __Pyx_DECREF_SET(__pyx_v_multiple_iterators, Py_False); - /* "pysam/libcalignmentfile.pyx":723 - * raise ValueError('start out of range (%i)' % start) + /* "pysam/libcalignmentfile.pyx":1085 + * + * # Turn of re-opening if htsfile is a stream + * if self.is_stream: # <<<<<<<<<<<<<< + * multiple_iterators = False * - * if end != None: # <<<<<<<<<<<<<< - * try: - * rend = end */ } - /* "pysam/libcalignmentfile.pyx":729 - * raise ValueError('end out of range (%i)' % end) + /* "pysam/libcalignmentfile.pyx":1088 + * multiple_iterators = False * - * if region: # <<<<<<<<<<<<<< - * region = force_str(region) - * parts = re.split("[:-]", region) + * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< + * if not until_eof and not self.is_remote: + * if not self.has_index(): */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 729, __pyx_L1_error) - if (__pyx_t_2) { + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1088, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1088, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!__pyx_t_2) { + } else { + __pyx_t_3 = __pyx_t_2; + goto __pyx_L8_bool_binop_done; + } + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1088, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1088, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_3 = __pyx_t_2; + __pyx_L8_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":730 + /* "pysam/libcalignmentfile.pyx":1089 * - * if region: - * region = force_str(region) # <<<<<<<<<<<<<< - * parts = re.split("[:-]", region) - * reference = parts[0] - */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_region, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 730, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF_SET(__pyx_v_region, __pyx_t_1); - __pyx_t_1 = 0; - - /* "pysam/libcalignmentfile.pyx":731 - * if region: - * region = force_str(region) - * parts = re.split("[:-]", region) # <<<<<<<<<<<<<< - * reference = parts[0] - * if len(parts) >= 2: + * if self.is_bam or self.is_cram: + * if not until_eof and not self.is_remote: # <<<<<<<<<<<<<< + * if not self.has_index(): + * raise ValueError( */ - __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_split); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_kp_s__16, __pyx_v_region}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_kp_s__16, __pyx_v_region}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_10 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_INCREF(__pyx_kp_s__16); - __Pyx_GIVEREF(__pyx_kp_s__16); - PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_7, __pyx_kp_s__16); - __Pyx_INCREF(__pyx_v_region); - __Pyx_GIVEREF(__pyx_v_region); - PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_7, __pyx_v_region); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 731, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1089, __pyx_L1_error) + __pyx_t_14 = ((!__pyx_t_2) != 0); + if (__pyx_t_14) { + } else { + __pyx_t_3 = __pyx_t_14; + goto __pyx_L11_bool_binop_done; } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_parts = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_14 = ((!(__pyx_v_self->__pyx_base.is_remote != 0)) != 0); + __pyx_t_3 = __pyx_t_14; + __pyx_L11_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":732 - * region = force_str(region) - * parts = re.split("[:-]", region) - * reference = parts[0] # <<<<<<<<<<<<<< - * if len(parts) >= 2: - * rstart = int(parts[1]) - 1 + /* "pysam/libcalignmentfile.pyx":1090 + * if self.is_bam or self.is_cram: + * if not until_eof and not self.is_remote: + * if not self.has_index(): # <<<<<<<<<<<<<< + * raise ValueError( + * "fetch called on bamfile without index") */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF_SET(__pyx_v_reference, __pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1090, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (__pyx_t_1) { + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1090, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1090, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1090, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_14 = ((!__pyx_t_3) != 0); + if (unlikely(__pyx_t_14)) { - /* "pysam/libcalignmentfile.pyx":733 - * parts = re.split("[:-]", region) - * reference = parts[0] - * if len(parts) >= 2: # <<<<<<<<<<<<<< - * rstart = int(parts[1]) - 1 - * if len(parts) >= 3: + /* "pysam/libcalignmentfile.pyx":1091 + * if not until_eof and not self.is_remote: + * if not self.has_index(): + * raise ValueError( # <<<<<<<<<<<<<< + * "fetch called on bamfile without index") + * */ - __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 733, __pyx_L1_error) - __pyx_t_2 = ((__pyx_t_12 >= 2) != 0); - if (__pyx_t_2) { + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 1091, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":734 - * reference = parts[0] - * if len(parts) >= 2: - * rstart = int(parts[1]) - 1 # <<<<<<<<<<<<<< - * if len(parts) >= 3: - * rend = int(parts[2]) + /* "pysam/libcalignmentfile.pyx":1090 + * if self.is_bam or self.is_cram: + * if not until_eof and not self.is_remote: + * if not self.has_index(): # <<<<<<<<<<<<<< + * raise ValueError( + * "fetch called on bamfile without index") */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 734, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 734, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_t_9, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 734, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 734, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_rstart = __pyx_t_6; + } - /* "pysam/libcalignmentfile.pyx":733 - * parts = re.split("[:-]", region) - * reference = parts[0] - * if len(parts) >= 2: # <<<<<<<<<<<<<< - * rstart = int(parts[1]) - 1 - * if len(parts) >= 3: + /* "pysam/libcalignmentfile.pyx":1089 + * + * if self.is_bam or self.is_cram: + * if not until_eof and not self.is_remote: # <<<<<<<<<<<<<< + * if not self.has_index(): + * raise ValueError( */ } - /* "pysam/libcalignmentfile.pyx":735 - * if len(parts) >= 2: - * rstart = int(parts[1]) - 1 - * if len(parts) >= 3: # <<<<<<<<<<<<<< - * rend = int(parts[2]) + /* "pysam/libcalignmentfile.pyx":1094 + * "fetch called on bamfile without index") * + * if has_coord: # <<<<<<<<<<<<<< + * return IteratorRowRegion( + * self, rtid, rstart, rstop, */ - __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 735, __pyx_L1_error) - __pyx_t_2 = ((__pyx_t_12 >= 3) != 0); - if (__pyx_t_2) { + __pyx_t_14 = (__pyx_v_has_coord != 0); + if (__pyx_t_14) { - /* "pysam/libcalignmentfile.pyx":736 - * rstart = int(parts[1]) - 1 - * if len(parts) >= 3: - * rend = int(parts[2]) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1095 * - * if not reference: + * if has_coord: + * return IteratorRowRegion( # <<<<<<<<<<<<<< + * self, rtid, rstart, rstop, + * multiple_iterators=multiple_iterators) + */ + __Pyx_XDECREF(__pyx_r); + + /* "pysam/libcalignmentfile.pyx":1096 + * if has_coord: + * return IteratorRowRegion( + * self, rtid, rstart, rstop, # <<<<<<<<<<<<<< + * multiple_iterators=multiple_iterators) + * else: */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 736, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1096, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_rstart); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1096, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rstop); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1096, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 736, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_9); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 736, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_rend = __pyx_t_6; - /* "pysam/libcalignmentfile.pyx":735 - * if len(parts) >= 2: - * rstart = int(parts[1]) - 1 - * if len(parts) >= 3: # <<<<<<<<<<<<<< - * rend = int(parts[2]) + /* "pysam/libcalignmentfile.pyx":1095 * + * if has_coord: + * return IteratorRowRegion( # <<<<<<<<<<<<<< + * self, rtid, rstart, rstop, + * multiple_iterators=multiple_iterators) */ - } + __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1095, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_1); + __pyx_t_6 = 0; + __pyx_t_7 = 0; + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":729 - * raise ValueError('end out of range (%i)' % end) - * - * if region: # <<<<<<<<<<<<<< - * region = force_str(region) - * parts = re.split("[:-]", region) + /* "pysam/libcalignmentfile.pyx":1097 + * return IteratorRowRegion( + * self, rtid, rstart, rstop, + * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< + * else: + * if until_eof: */ - } + __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1097, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1097, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":738 - * rend = int(parts[2]) - * - * if not reference: # <<<<<<<<<<<<<< - * return 0, 0, 0, 0 + /* "pysam/libcalignmentfile.pyx":1095 * + * if has_coord: + * return IteratorRowRegion( # <<<<<<<<<<<<<< + * self, rtid, rstart, rstop, + * multiple_iterators=multiple_iterators) */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 738, __pyx_L1_error) - __pyx_t_13 = ((!__pyx_t_2) != 0); - if (__pyx_t_13) { + __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1095, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":739 - * - * if not reference: - * return 0, 0, 0, 0 # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1094 + * "fetch called on bamfile without index") * - * if tid is not None: + * if has_coord: # <<<<<<<<<<<<<< + * return IteratorRowRegion( + * self, rtid, rstart, rstop, */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_tuple__17); - __pyx_r = __pyx_tuple__17; - goto __pyx_L0; + } - /* "pysam/libcalignmentfile.pyx":738 - * rend = int(parts[2]) - * - * if not reference: # <<<<<<<<<<<<<< - * return 0, 0, 0, 0 - * + /* "pysam/libcalignmentfile.pyx":1099 + * multiple_iterators=multiple_iterators) + * else: + * if until_eof: # <<<<<<<<<<<<<< + * return IteratorRowAll( + * self, */ - } + /*else*/ { + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1099, __pyx_L1_error) + if (__pyx_t_14) { - /* "pysam/libcalignmentfile.pyx":741 - * return 0, 0, 0, 0 - * - * if tid is not None: # <<<<<<<<<<<<<< - * rtid = tid - * else: + /* "pysam/libcalignmentfile.pyx":1100 + * else: + * if until_eof: + * return IteratorRowAll( # <<<<<<<<<<<<<< + * self, + * multiple_iterators=multiple_iterators) */ - __pyx_t_13 = (__pyx_v_tid != Py_None); - __pyx_t_2 = (__pyx_t_13 != 0); - if (__pyx_t_2) { + __Pyx_XDECREF(__pyx_r); - /* "pysam/libcalignmentfile.pyx":742 - * - * if tid is not None: - * rtid = tid # <<<<<<<<<<<<<< - * else: - * rtid = self.gettid(reference) + /* "pysam/libcalignmentfile.pyx":1101 + * if until_eof: + * return IteratorRowAll( + * self, # <<<<<<<<<<<<<< + * multiple_iterators=multiple_iterators) + * else: */ - __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_v_tid); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 742, __pyx_L1_error) - __pyx_v_rtid = __pyx_t_7; + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1100, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self)); - /* "pysam/libcalignmentfile.pyx":741 - * return 0, 0, 0, 0 - * - * if tid is not None: # <<<<<<<<<<<<<< - * rtid = tid - * else: + /* "pysam/libcalignmentfile.pyx":1102 + * return IteratorRowAll( + * self, + * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< + * else: + * # AH: check - reason why no multiple_iterators for */ - goto __pyx_L25; - } + __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1102, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":744 - * rtid = tid - * else: - * rtid = self.gettid(reference) # <<<<<<<<<<<<<< - * - * if rtid < 0: + /* "pysam/libcalignmentfile.pyx":1100 + * else: + * if until_eof: + * return IteratorRowAll( # <<<<<<<<<<<<<< + * self, + * multiple_iterators=multiple_iterators) */ - /*else*/ { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_gettid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - if (!__pyx_t_10) { - __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_reference); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_reference}; - __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_9); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_reference}; - __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_9); - } else - #endif - { - __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_10); __pyx_t_10 = NULL; - __Pyx_INCREF(__pyx_v_reference); - __Pyx_GIVEREF(__pyx_v_reference); - PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_reference); - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_rtid = __pyx_t_7; - } - __pyx_L25:; + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll), __pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1100, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":746 - * rtid = self.gettid(reference) - * - * if rtid < 0: # <<<<<<<<<<<<<< - * raise ValueError( - * "invalid reference `%s`" % reference) + /* "pysam/libcalignmentfile.pyx":1099 + * multiple_iterators=multiple_iterators) + * else: + * if until_eof: # <<<<<<<<<<<<<< + * return IteratorRowAll( + * self, */ - __pyx_t_2 = ((__pyx_v_rtid < 0) != 0); - if (unlikely(__pyx_t_2)) { + } - /* "pysam/libcalignmentfile.pyx":748 - * if rtid < 0: - * raise ValueError( - * "invalid reference `%s`" % reference) # <<<<<<<<<<<<<< - * if rstart > rend: - * raise ValueError( + /* "pysam/libcalignmentfile.pyx":1106 + * # AH: check - reason why no multiple_iterators for + * # AllRefs? + * return IteratorRowAllRefs( # <<<<<<<<<<<<<< + * self, + * multiple_iterators=multiple_iterators) */ - __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_invalid_reference_s, __pyx_v_reference); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); + /*else*/ { + __Pyx_XDECREF(__pyx_r); - /* "pysam/libcalignmentfile.pyx":747 - * - * if rtid < 0: - * raise ValueError( # <<<<<<<<<<<<<< - * "invalid reference `%s`" % reference) - * if rstart > rend: + /* "pysam/libcalignmentfile.pyx":1107 + * # AllRefs? + * return IteratorRowAllRefs( + * self, # <<<<<<<<<<<<<< + * multiple_iterators=multiple_iterators) + * else: */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 747, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 747, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1106, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_self)); - /* "pysam/libcalignmentfile.pyx":746 - * rtid = self.gettid(reference) - * - * if rtid < 0: # <<<<<<<<<<<<<< - * raise ValueError( - * "invalid reference `%s`" % reference) + /* "pysam/libcalignmentfile.pyx":1108 + * return IteratorRowAllRefs( + * self, + * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< + * else: + * if has_coord: */ - } + __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1108, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1108, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":749 - * raise ValueError( - * "invalid reference `%s`" % reference) - * if rstart > rend: # <<<<<<<<<<<<<< - * raise ValueError( - * 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend)) + /* "pysam/libcalignmentfile.pyx":1106 + * # AH: check - reason why no multiple_iterators for + * # AllRefs? + * return IteratorRowAllRefs( # <<<<<<<<<<<<<< + * self, + * multiple_iterators=multiple_iterators) */ - __pyx_t_2 = ((__pyx_v_rstart > __pyx_v_rend) != 0); - if (unlikely(__pyx_t_2)) { + __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs), __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1106, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; + goto __pyx_L0; + } + } - /* "pysam/libcalignmentfile.pyx":751 - * if rstart > rend: - * raise ValueError( - * 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend)) # <<<<<<<<<<<<<< - * if not 0 <= rstart < MAX_POS: - * raise ValueError('start out of range (%i)' % rstart) + /* "pysam/libcalignmentfile.pyx":1088 + * multiple_iterators = False + * + * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< + * if not until_eof and not self.is_remote: + * if not self.has_index(): */ - __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 751, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 751, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 751, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9); - __pyx_t_1 = 0; - __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_invalid_coordinates_start_i_end, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 751, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } - /* "pysam/libcalignmentfile.pyx":750 - * "invalid reference `%s`" % reference) - * if rstart > rend: - * raise ValueError( # <<<<<<<<<<<<<< - * 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend)) - * if not 0 <= rstart < MAX_POS: + /* "pysam/libcalignmentfile.pyx":1110 + * multiple_iterators=multiple_iterators) + * else: + * if has_coord: # <<<<<<<<<<<<<< + * raise ValueError( + * "fetching by region is not available for SAM files") */ - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 750, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 750, __pyx_L1_error) + /*else*/ { + __pyx_t_14 = (__pyx_v_has_coord != 0); + if (unlikely(__pyx_t_14)) { - /* "pysam/libcalignmentfile.pyx":749 - * raise ValueError( - * "invalid reference `%s`" % reference) - * if rstart > rend: # <<<<<<<<<<<<<< - * raise ValueError( - * 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend)) + /* "pysam/libcalignmentfile.pyx":1111 + * else: + * if has_coord: + * raise ValueError( # <<<<<<<<<<<<<< + * "fetching by region is not available for SAM files") + * */ - } + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 1111, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":752 - * raise ValueError( - * 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend)) - * if not 0 <= rstart < MAX_POS: # <<<<<<<<<<<<<< - * raise ValueError('start out of range (%i)' % rstart) - * if not 0 <= rend <= MAX_POS: + /* "pysam/libcalignmentfile.pyx":1110 + * multiple_iterators=multiple_iterators) + * else: + * if has_coord: # <<<<<<<<<<<<<< + * raise ValueError( + * "fetching by region is not available for SAM files") */ - __pyx_t_2 = (0 <= __pyx_v_rstart); - if (__pyx_t_2) { - __pyx_t_2 = (__pyx_v_rstart < __pyx_v_5pysam_17libcalignmentfile_MAX_POS); - } - __pyx_t_13 = ((!(__pyx_t_2 != 0)) != 0); - if (unlikely(__pyx_t_13)) { + } - /* "pysam/libcalignmentfile.pyx":753 - * 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend)) - * if not 0 <= rstart < MAX_POS: - * raise ValueError('start out of range (%i)' % rstart) # <<<<<<<<<<<<<< - * if not 0 <= rend <= MAX_POS: - * raise ValueError('end out of range (%i)' % rend) + /* "pysam/libcalignmentfile.pyx":1114 + * "fetching by region is not available for SAM files") + * + * if multiple_iterators == True: # <<<<<<<<<<<<<< + * raise ValueError( + * "multiple iterators not implemented for SAM files") */ - __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 753, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 753, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 753, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 753, __pyx_L1_error) + __pyx_t_7 = PyObject_RichCompare(__pyx_v_multiple_iterators, Py_True, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1114, __pyx_L1_error) + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1114, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_14)) { - /* "pysam/libcalignmentfile.pyx":752 - * raise ValueError( - * 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend)) - * if not 0 <= rstart < MAX_POS: # <<<<<<<<<<<<<< - * raise ValueError('start out of range (%i)' % rstart) - * if not 0 <= rend <= MAX_POS: + /* "pysam/libcalignmentfile.pyx":1115 + * + * if multiple_iterators == True: + * raise ValueError( # <<<<<<<<<<<<<< + * "multiple iterators not implemented for SAM files") + * */ - } + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 1115, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":754 - * if not 0 <= rstart < MAX_POS: - * raise ValueError('start out of range (%i)' % rstart) - * if not 0 <= rend <= MAX_POS: # <<<<<<<<<<<<<< - * raise ValueError('end out of range (%i)' % rend) + /* "pysam/libcalignmentfile.pyx":1114 + * "fetching by region is not available for SAM files") * + * if multiple_iterators == True: # <<<<<<<<<<<<<< + * raise ValueError( + * "multiple iterators not implemented for SAM files") */ - __pyx_t_13 = (0 <= __pyx_v_rend); - if (__pyx_t_13) { - __pyx_t_13 = (__pyx_v_rend <= __pyx_v_5pysam_17libcalignmentfile_MAX_POS); - } - __pyx_t_2 = ((!(__pyx_t_13 != 0)) != 0); - if (unlikely(__pyx_t_2)) { + } - /* "pysam/libcalignmentfile.pyx":755 - * raise ValueError('start out of range (%i)' % rstart) - * if not 0 <= rend <= MAX_POS: - * raise ValueError('end out of range (%i)' % rend) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1118 + * "multiple iterators not implemented for SAM files") + * + * return IteratorRowAll(self, # <<<<<<<<<<<<<< + * multiple_iterators=multiple_iterators) * - * return 1, rtid, rstart, rend */ - __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_end_out_of_range_i, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 755, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self)); - /* "pysam/libcalignmentfile.pyx":754 - * if not 0 <= rstart < MAX_POS: - * raise ValueError('start out of range (%i)' % rstart) - * if not 0 <= rend <= MAX_POS: # <<<<<<<<<<<<<< - * raise ValueError('end out of range (%i)' % rend) + /* "pysam/libcalignmentfile.pyx":1119 * + * return IteratorRowAll(self, + * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< + * + * def head(self, n, multiple_iterators=True): */ - } + __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1119, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":757 - * raise ValueError('end out of range (%i)' % rend) + /* "pysam/libcalignmentfile.pyx":1118 + * "multiple iterators not implemented for SAM files") * - * return 1, rtid, rstart, rend # <<<<<<<<<<<<<< + * return IteratorRowAll(self, # <<<<<<<<<<<<<< + * multiple_iterators=multiple_iterators) * - * def fetch(self, */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyTuple_New(4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_int_1); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_1); - __pyx_t_8 = 0; - __pyx_t_9 = 0; - __pyx_t_1 = 0; - __pyx_r = __pyx_t_10; - __pyx_t_10 = 0; - goto __pyx_L0; + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll), __pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1118, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + } - /* "pysam/libcalignmentfile.pyx":676 - * return charptr_to_str(self.header.target_name[tid]) + /* "pysam/libcalignmentfile.pyx":1010 + * self.start_offset = self.tell() * - * def parse_region(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * def fetch(self, # <<<<<<<<<<<<<< + * contig=None, + * start=None, */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.parse_region", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_parts); - __Pyx_XDECREF(__pyx_v_reference); - __Pyx_XDECREF(__pyx_v_region); + __Pyx_XDECREF(__pyx_v_multiple_iterators); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":759 - * return 1, rtid, rstart, rend +/* "pysam/libcalignmentfile.pyx":1121 + * multiple_iterators=multiple_iterators) + * + * def head(self, n, multiple_iterators=True): # <<<<<<<<<<<<<< + * '''return an iterator over the first n alignments. * - * def fetch(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_14fetch[] = "AlignmentFile.fetch(self, reference=None, start=None, end=None, region=None, tid=None, until_eof=False, multiple_iterators=False)\nfetch reads aligned in a :term:`region`. \n\n See :meth:`AlignmentFile.parse_region` for more information\n on genomic regions.\n\n Without a `reference` or `region` all mapped reads in the file\n will be fetched. The reads will be returned ordered by reference\n sequence, which will not necessarily be the order within the\n file. This mode of iteration still requires an index. If there is\n no index, use `until_eof=True`.\n\n If only `reference` is set, all reads aligned to `reference`\n will be fetched.\n\n A :term:`SAM` file does not allow random access. If `region`\n or `reference` are given, an exception is raised.\n\n :class:`~pysam.FastaFile`\n :class:`~pysam.IteratorRow`\n :class:`~pysam.IteratorRow`\n :class:`~IteratorRow`\n :class:`IteratorRow`\n\n Parameters\n ----------\n \n until_eof : bool\n\n If `until_eof` is True, all reads from the current file\n position will be returned in order as they are within the\n file. Using this option will also fetch unmapped reads.\n\n multiple_iterators : bool\n \n If `multiple_iterators` is True, multiple\n iterators on the same file can be used at the same time. The\n iterator returned will receive its own copy of a filehandle to\n the file effectively re-opening the file. Re-opening a file\n creates some overhead, so beware.\n\n Returns\n -------\n\n An iterator over a collection of reads.\n\n Raises\n ------\n\n ValueError\n if the genomic coordinates are out of range or invalid or the\n file does not permit random access to genomic coordinates.\n\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_reference = 0; - PyObject *__pyx_v_start = 0; - PyObject *__pyx_v_end = 0; - PyObject *__pyx_v_region = 0; - PyObject *__pyx_v_tid = 0; - PyObject *__pyx_v_until_eof = 0; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11head(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_10head[] = "AlignmentFile.head(self, n, multiple_iterators=True)\nreturn an iterator over the first n alignments.\n\n This iterator is is useful for inspecting the bam-file.\n\n Parameters\n ----------\n\n multiple_iterators : bool\n\n is set to True by default in order to\n avoid changing the current file position.\n\n Returns\n -------\n\n an iterator over a collection of reads\n\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11head(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_n = 0; PyObject *__pyx_v_multiple_iterators = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fetch (wrapper)", 0); + __Pyx_RefNannySetupContext("head (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,&__pyx_n_s_tid,&__pyx_n_s_until_eof,&__pyx_n_s_multiple_iterators,0}; - PyObject* values[7] = {0,0,0,0,0,0,0}; - - /* "pysam/libcalignmentfile.pyx":760 - * - * def fetch(self, - * reference=None, # <<<<<<<<<<<<<< - * start=None, - * end=None, - */ - values[0] = ((PyObject *)Py_None); - - /* "pysam/libcalignmentfile.pyx":761 - * def fetch(self, - * reference=None, - * start=None, # <<<<<<<<<<<<<< - * end=None, - * region=None, - */ - values[1] = ((PyObject *)Py_None); - - /* "pysam/libcalignmentfile.pyx":762 - * reference=None, - * start=None, - * end=None, # <<<<<<<<<<<<<< - * region=None, - * tid=None, - */ - values[2] = ((PyObject *)Py_None); - - /* "pysam/libcalignmentfile.pyx":763 - * start=None, - * end=None, - * region=None, # <<<<<<<<<<<<<< - * tid=None, - * until_eof=False, - */ - values[3] = ((PyObject *)Py_None); - - /* "pysam/libcalignmentfile.pyx":764 - * end=None, - * region=None, - * tid=None, # <<<<<<<<<<<<<< - * until_eof=False, - * multiple_iterators=False): - */ - values[4] = ((PyObject *)Py_None); - - /* "pysam/libcalignmentfile.pyx":765 - * region=None, - * tid=None, - * until_eof=False, # <<<<<<<<<<<<<< - * multiple_iterators=False): - * """fetch reads aligned in a :term:`region`. - */ - values[5] = ((PyObject *)Py_False); - - /* "pysam/libcalignmentfile.pyx":766 - * tid=None, - * until_eof=False, - * multiple_iterators=False): # <<<<<<<<<<<<<< - * """fetch reads aligned in a :term:`region`. - * - */ - values[6] = ((PyObject *)Py_False); + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_n,&__pyx_n_s_multiple_iterators,0}; + PyObject* values[2] = {0,0}; + values[1] = ((PyObject *)Py_True); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -10917,860 +16151,644 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15fetch(PyO kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); - if (value) { values[0] = value; kw_args--; } - } + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start); - if (value) { values[1] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); - if (value) { values[2] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region); - if (value) { values[3] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tid); - if (value) { values[4] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_until_eof); - if (value) { values[5] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 6: if (kw_args > 0) { PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators); - if (value) { values[6] = value; kw_args--; } + if (value) { values[1] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 759, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "head") < 0)) __PYX_ERR(0, 1121, __pyx_L3_error) } } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - CYTHON_FALLTHROUGH; - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; + switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; + break; default: goto __pyx_L5_argtuple_error; } } - __pyx_v_reference = values[0]; - __pyx_v_start = values[1]; - __pyx_v_end = values[2]; - __pyx_v_region = values[3]; - __pyx_v_tid = values[4]; - __pyx_v_until_eof = values[5]; - __pyx_v_multiple_iterators = values[6]; + __pyx_v_n = values[0]; + __pyx_v_multiple_iterators = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 759, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("head", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1121, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.head", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_14fetch(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_tid, __pyx_v_until_eof, __pyx_v_multiple_iterators); - - /* "pysam/libcalignmentfile.pyx":759 - * return 1, rtid, rstart, rend - * - * def fetch(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, - */ + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10head(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_n, __pyx_v_multiple_iterators); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_14fetch(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_multiple_iterators) { - int __pyx_v_rtid; - int __pyx_v_rstart; - int __pyx_v_rend; - int __pyx_v_has_coord; +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10head(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_n, PyObject *__pyx_v_multiple_iterators) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *(*__pyx_t_10)(PyObject *); - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - int __pyx_t_14; - __Pyx_RefNannySetupContext("fetch", 0); - __Pyx_TraceCall("fetch", __pyx_f[0], 759, 0, __PYX_ERR(0, 759, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_multiple_iterators); + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("head", 0); + __Pyx_TraceCall("head", __pyx_f[0], 1121, 0, __PYX_ERR(0, 1121, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":822 - * cdef int rtid, rstart, rend, has_coord + /* "pysam/libcalignmentfile.pyx":1140 * - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError( "I/O operation on closed file" ) + * ''' + * return IteratorRowHead(self, n, # <<<<<<<<<<<<<< + * multiple_iterators=multiple_iterators) * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 822, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1140, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 822, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { - - /* "pysam/libcalignmentfile.pyx":823 - * - * if not self.is_open: - * raise ValueError( "I/O operation on closed file" ) # <<<<<<<<<<<<<< - * - * has_coord, rtid, rstart, rend = self.parse_region( - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 823, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 823, __pyx_L1_error) - - /* "pysam/libcalignmentfile.pyx":822 - * cdef int rtid, rstart, rend, has_coord - * - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError( "I/O operation on closed file" ) - * - */ - } - - /* "pysam/libcalignmentfile.pyx":825 - * raise ValueError( "I/O operation on closed file" ) - * - * has_coord, rtid, rstart, rend = self.parse_region( # <<<<<<<<<<<<<< - * reference, - * start, - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_parse_region); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - - /* "pysam/libcalignmentfile.pyx":830 - * end, - * region, - * tid) # <<<<<<<<<<<<<< - * - * # Turn of re-opening if htsfile is a stream - */ - __pyx_t_5 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[6] = {__pyx_t_5, __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_tid}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 5+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[6] = {__pyx_t_5, __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_tid}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 5+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_7 = PyTuple_New(5+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_INCREF(__pyx_v_reference); - __Pyx_GIVEREF(__pyx_v_reference); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_reference); - __Pyx_INCREF(__pyx_v_start); - __Pyx_GIVEREF(__pyx_v_start); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_start); - __Pyx_INCREF(__pyx_v_end); - __Pyx_GIVEREF(__pyx_v_end); - PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_v_end); - __Pyx_INCREF(__pyx_v_region); - __Pyx_GIVEREF(__pyx_v_region); - PyTuple_SET_ITEM(__pyx_t_7, 3+__pyx_t_6, __pyx_v_region); - __Pyx_INCREF(__pyx_v_tid); - __Pyx_GIVEREF(__pyx_v_tid); - PyTuple_SET_ITEM(__pyx_t_7, 4+__pyx_t_6, __pyx_v_tid); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 4)) { - if (size > 4) __Pyx_RaiseTooManyValuesError(4); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 825, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 3); - } else { - __pyx_t_4 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - __pyx_t_5 = PyList_GET_ITEM(sequence, 2); - __pyx_t_8 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); - #else - { - Py_ssize_t i; - PyObject** temps[4] = {&__pyx_t_4,&__pyx_t_7,&__pyx_t_5,&__pyx_t_8}; - for (i=0; i < 4; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_GOTREF(item); - *(temps[i]) = item; - } - } - #endif - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - PyObject** temps[4] = {&__pyx_t_4,&__pyx_t_7,&__pyx_t_5,&__pyx_t_8}; - __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; - for (index=0; index < 4; index++) { - PyObject* item = __pyx_t_10(__pyx_t_9); if (unlikely(!item)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 4) < 0) __PYX_ERR(0, 825, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L5_unpacking_done; - __pyx_L4_unpacking_failed:; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 825, __pyx_L1_error) - __pyx_L5_unpacking_done:; - } - - /* "pysam/libcalignmentfile.pyx":825 - * raise ValueError( "I/O operation on closed file" ) - * - * has_coord, rtid, rstart, rend = self.parse_region( # <<<<<<<<<<<<<< - * reference, - * start, - */ - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_has_coord = __pyx_t_6; - __pyx_v_rtid = __pyx_t_11; - __pyx_v_rstart = __pyx_t_12; - __pyx_v_rend = __pyx_t_13; - - /* "pysam/libcalignmentfile.pyx":833 - * - * # Turn of re-opening if htsfile is a stream - * if self.is_stream: # <<<<<<<<<<<<<< - * multiple_iterators = False - * - */ - __pyx_t_3 = (__pyx_v_self->__pyx_base.is_stream != 0); - if (__pyx_t_3) { + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); + __Pyx_INCREF(__pyx_v_n); + __Pyx_GIVEREF(__pyx_v_n); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_n); - /* "pysam/libcalignmentfile.pyx":834 - * # Turn of re-opening if htsfile is a stream - * if self.is_stream: - * multiple_iterators = False # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1141 + * ''' + * return IteratorRowHead(self, n, + * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< * - * if self.is_bam or self.is_cram: + * def mate(self, AlignedSegment read): */ - __Pyx_INCREF(Py_False); - __Pyx_DECREF_SET(__pyx_v_multiple_iterators, Py_False); + __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1141, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":833 + /* "pysam/libcalignmentfile.pyx":1140 * - * # Turn of re-opening if htsfile is a stream - * if self.is_stream: # <<<<<<<<<<<<<< - * multiple_iterators = False - * - */ - } - - /* "pysam/libcalignmentfile.pyx":836 - * multiple_iterators = False + * ''' + * return IteratorRowHead(self, n, # <<<<<<<<<<<<<< + * multiple_iterators=multiple_iterators) * - * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< - * if not until_eof and not self.is_remote: - * if not self.has_index(): */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 836, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 836, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!__pyx_t_2) { - } else { - __pyx_t_3 = __pyx_t_2; - goto __pyx_L8_bool_binop_done; - } - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 836, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 836, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1140, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = __pyx_t_2; - __pyx_L8_bool_binop_done:; - if (__pyx_t_3) { - - /* "pysam/libcalignmentfile.pyx":837 - * - * if self.is_bam or self.is_cram: - * if not until_eof and not self.is_remote: # <<<<<<<<<<<<<< - * if not self.has_index(): - * raise ValueError( - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 837, __pyx_L1_error) - __pyx_t_14 = ((!__pyx_t_2) != 0); - if (__pyx_t_14) { - } else { - __pyx_t_3 = __pyx_t_14; - goto __pyx_L11_bool_binop_done; - } - __pyx_t_14 = ((!(__pyx_v_self->__pyx_base.is_remote != 0)) != 0); - __pyx_t_3 = __pyx_t_14; - __pyx_L11_bool_binop_done:; - if (__pyx_t_3) { - - /* "pysam/libcalignmentfile.pyx":838 - * if self.is_bam or self.is_cram: - * if not until_eof and not self.is_remote: - * if not self.has_index(): # <<<<<<<<<<<<<< - * raise ValueError( - * "fetch called on bamfile without index") - */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 838, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - if (__pyx_t_5) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 838, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 838, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 838, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_14 = ((!__pyx_t_3) != 0); - if (unlikely(__pyx_t_14)) { + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":839 - * if not until_eof and not self.is_remote: - * if not self.has_index(): - * raise ValueError( # <<<<<<<<<<<<<< - * "fetch called on bamfile without index") + /* "pysam/libcalignmentfile.pyx":1121 + * multiple_iterators=multiple_iterators) + * + * def head(self, n, multiple_iterators=True): # <<<<<<<<<<<<<< + * '''return an iterator over the first n alignments. * */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 839, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 839, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":838 - * if self.is_bam or self.is_cram: - * if not until_eof and not self.is_remote: - * if not self.has_index(): # <<<<<<<<<<<<<< - * raise ValueError( - * "fetch called on bamfile without index") - */ - } + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.head", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignmentfile.pyx":837 +/* "pysam/libcalignmentfile.pyx":1143 + * multiple_iterators=multiple_iterators) + * + * def mate(self, AlignedSegment read): # <<<<<<<<<<<<<< + * '''return the mate of :class:`~pysam.AlignedSegment` `read`. * - * if self.is_bam or self.is_cram: - * if not until_eof and not self.is_remote: # <<<<<<<<<<<<<< - * if not self.has_index(): - * raise ValueError( */ - } - /* "pysam/libcalignmentfile.pyx":842 - * "fetch called on bamfile without index") +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_12mate[] = "AlignmentFile.mate(self, AlignedSegment read)\nreturn the mate of :class:`~pysam.AlignedSegment` `read`.\n\n .. note::\n\n Calling this method will change the file position.\n This might interfere with any iterators that have\n not re-opened the file.\n\n .. note::\n\n This method is too slow for high-throughput processing.\n If a read needs to be processed with its mate, work\n from a read name sorted file or, better, cache reads.\n\n Returns\n -------\n\n :class:`~pysam.AlignedSegment` : the mate\n\n Raises\n ------\n\n ValueError\n if the read is unpaired or the mate is unmapped\n\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("mate (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment, 1, "read", 0))) __PYX_ERR(0, 1143, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12mate(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_read)); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12mate(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read) { + uint32_t __pyx_v_flag; + int __pyx_v_x; + PyObject *__pyx_v_mate = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + uint16_t __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + Py_ssize_t __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + __Pyx_RefNannySetupContext("mate", 0); + __Pyx_TraceCall("mate", __pyx_f[0], 1143, 0, __PYX_ERR(0, 1143, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":1170 * - * if has_coord: # <<<<<<<<<<<<<< - * return IteratorRowRegion( - * self, rtid, rstart, rend, + * ''' + * cdef uint32_t flag = read._delegate.core.flag # <<<<<<<<<<<<<< + * + * if flag & BAM_FPAIRED == 0: */ - __pyx_t_14 = (__pyx_v_has_coord != 0); - if (__pyx_t_14) { + __pyx_t_1 = __pyx_v_read->_delegate->core.flag; + __pyx_v_flag = __pyx_t_1; - /* "pysam/libcalignmentfile.pyx":843 + /* "pysam/libcalignmentfile.pyx":1172 + * cdef uint32_t flag = read._delegate.core.flag * - * if has_coord: - * return IteratorRowRegion( # <<<<<<<<<<<<<< - * self, rtid, rstart, rend, - * multiple_iterators=multiple_iterators) + * if flag & BAM_FPAIRED == 0: # <<<<<<<<<<<<<< + * raise ValueError("read %s: is unpaired" % + * (read.query_name)) */ - __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = (((__pyx_v_flag & BAM_FPAIRED) == 0) != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcalignmentfile.pyx":844 - * if has_coord: - * return IteratorRowRegion( - * self, rtid, rstart, rend, # <<<<<<<<<<<<<< - * multiple_iterators=multiple_iterators) - * else: + /* "pysam/libcalignmentfile.pyx":1174 + * if flag & BAM_FPAIRED == 0: + * raise ValueError("read %s: is unpaired" % + * (read.query_name)) # <<<<<<<<<<<<<< + * if flag & BAM_FMUNMAP != 0: + * raise ValueError("mate %s: is unmapped" % */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 844, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_rstart); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 844, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_rend); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 844, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1174, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); - /* "pysam/libcalignmentfile.pyx":843 + /* "pysam/libcalignmentfile.pyx":1173 * - * if has_coord: - * return IteratorRowRegion( # <<<<<<<<<<<<<< - * self, rtid, rstart, rend, - * multiple_iterators=multiple_iterators) + * if flag & BAM_FPAIRED == 0: + * raise ValueError("read %s: is unpaired" % # <<<<<<<<<<<<<< + * (read.query_name)) + * if flag & BAM_FMUNMAP != 0: */ - __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 843, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_t_5); - __pyx_t_1 = 0; - __pyx_t_8 = 0; - __pyx_t_5 = 0; + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_read_s_is_unpaired, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1173, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1173, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 1173, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":845 - * return IteratorRowRegion( - * self, rtid, rstart, rend, - * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< - * else: - * if until_eof: + /* "pysam/libcalignmentfile.pyx":1172 + * cdef uint32_t flag = read._delegate.core.flag + * + * if flag & BAM_FPAIRED == 0: # <<<<<<<<<<<<<< + * raise ValueError("read %s: is unpaired" % + * (read.query_name)) */ - __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 845, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 845, __pyx_L1_error) + } + + /* "pysam/libcalignmentfile.pyx":1175 + * raise ValueError("read %s: is unpaired" % + * (read.query_name)) + * if flag & BAM_FMUNMAP != 0: # <<<<<<<<<<<<<< + * raise ValueError("mate %s: is unmapped" % + * (read.query_name)) + */ + __pyx_t_2 = (((__pyx_v_flag & BAM_FMUNMAP) != 0) != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcalignmentfile.pyx":843 + /* "pysam/libcalignmentfile.pyx":1177 + * if flag & BAM_FMUNMAP != 0: + * raise ValueError("mate %s: is unmapped" % + * (read.query_name)) # <<<<<<<<<<<<<< * - * if has_coord: - * return IteratorRowRegion( # <<<<<<<<<<<<<< - * self, rtid, rstart, rend, - * multiple_iterators=multiple_iterators) + * # xor flags to get the other mate */ - __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 843, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; - goto __pyx_L0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1177, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); - /* "pysam/libcalignmentfile.pyx":842 - * "fetch called on bamfile without index") + /* "pysam/libcalignmentfile.pyx":1176 + * (read.query_name)) + * if flag & BAM_FMUNMAP != 0: + * raise ValueError("mate %s: is unmapped" % # <<<<<<<<<<<<<< + * (read.query_name)) * - * if has_coord: # <<<<<<<<<<<<<< - * return IteratorRowRegion( - * self, rtid, rstart, rend, */ - } + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_mate_s_is_unmapped, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1176, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1176, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 1176, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":847 - * multiple_iterators=multiple_iterators) - * else: - * if until_eof: # <<<<<<<<<<<<<< - * return IteratorRowAll( - * self, + /* "pysam/libcalignmentfile.pyx":1175 + * raise ValueError("read %s: is unpaired" % + * (read.query_name)) + * if flag & BAM_FMUNMAP != 0: # <<<<<<<<<<<<<< + * raise ValueError("mate %s: is unmapped" % + * (read.query_name)) */ - /*else*/ { - __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 847, __pyx_L1_error) - if (__pyx_t_14) { + } - /* "pysam/libcalignmentfile.pyx":848 - * else: - * if until_eof: - * return IteratorRowAll( # <<<<<<<<<<<<<< - * self, - * multiple_iterators=multiple_iterators) + /* "pysam/libcalignmentfile.pyx":1180 + * + * # xor flags to get the other mate + * cdef int x = BAM_FREAD1 + BAM_FREAD2 # <<<<<<<<<<<<<< + * flag = (flag ^ x) & x + * */ - __Pyx_XDECREF(__pyx_r); + __pyx_v_x = (BAM_FREAD1 + BAM_FREAD2); - /* "pysam/libcalignmentfile.pyx":849 - * if until_eof: - * return IteratorRowAll( - * self, # <<<<<<<<<<<<<< - * multiple_iterators=multiple_iterators) - * else: + /* "pysam/libcalignmentfile.pyx":1181 + * # xor flags to get the other mate + * cdef int x = BAM_FREAD1 + BAM_FREAD2 + * flag = (flag ^ x) & x # <<<<<<<<<<<<<< + * + * # Make sure to use a separate file to jump around */ - __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 848, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_v_self)); + __pyx_v_flag = ((__pyx_v_flag ^ __pyx_v_x) & __pyx_v_x); - /* "pysam/libcalignmentfile.pyx":850 - * return IteratorRowAll( - * self, - * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< - * else: - * # AH: check - reason why no multiple_iterators for + /* "pysam/libcalignmentfile.pyx":1189 + * # could thus be made much quicker, for example + * # by using tell and seek. + * for mate in self.fetch( # <<<<<<<<<<<<<< + * read._delegate.core.mpos, + * read._delegate.core.mpos + 1, */ - __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 850, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 850, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); - /* "pysam/libcalignmentfile.pyx":848 - * else: - * if until_eof: - * return IteratorRowAll( # <<<<<<<<<<<<<< - * self, - * multiple_iterators=multiple_iterators) + /* "pysam/libcalignmentfile.pyx":1190 + * # by using tell and seek. + * for mate in self.fetch( + * read._delegate.core.mpos, # <<<<<<<<<<<<<< + * read._delegate.core.mpos + 1, + * tid=read._delegate.core.mtid, */ - __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll), __pyx_t_8, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 848, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_r = __pyx_t_7; - __pyx_t_7 = 0; - goto __pyx_L0; + __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_read->_delegate->core.mpos); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libcalignmentfile.pyx":847 - * multiple_iterators=multiple_iterators) - * else: - * if until_eof: # <<<<<<<<<<<<<< - * return IteratorRowAll( - * self, + /* "pysam/libcalignmentfile.pyx":1191 + * for mate in self.fetch( + * read._delegate.core.mpos, + * read._delegate.core.mpos + 1, # <<<<<<<<<<<<<< + * tid=read._delegate.core.mtid, + * multiple_iterators=True): */ - } + __pyx_t_5 = __Pyx_PyInt_From_long((__pyx_v_read->_delegate->core.mpos + 1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); - /* "pysam/libcalignmentfile.pyx":854 - * # AH: check - reason why no multiple_iterators for - * # AllRefs? - * return IteratorRowAllRefs( # <<<<<<<<<<<<<< - * self, - * multiple_iterators=multiple_iterators) + /* "pysam/libcalignmentfile.pyx":1189 + * # could thus be made much quicker, for example + * # by using tell and seek. + * for mate in self.fetch( # <<<<<<<<<<<<<< + * read._delegate.core.mpos, + * read._delegate.core.mpos + 1, */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __pyx_t_4 = 0; + __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":855 - * # AllRefs? - * return IteratorRowAllRefs( - * self, # <<<<<<<<<<<<<< - * multiple_iterators=multiple_iterators) - * else: + /* "pysam/libcalignmentfile.pyx":1192 + * read._delegate.core.mpos, + * read._delegate.core.mpos + 1, + * tid=read._delegate.core.mtid, # <<<<<<<<<<<<<< + * multiple_iterators=True): + * if mate.flag & flag != 0 and \ */ - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 854, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self)); + __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_read->_delegate->core.mtid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_tid, __pyx_t_4) < 0) __PYX_ERR(0, 1192, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":856 - * return IteratorRowAllRefs( - * self, - * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< - * else: - * if has_coord: + /* "pysam/libcalignmentfile.pyx":1193 + * read._delegate.core.mpos + 1, + * tid=read._delegate.core.mtid, + * multiple_iterators=True): # <<<<<<<<<<<<<< + * if mate.flag & flag != 0 and \ + * mate.query_name == read.query_name: */ - __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 856, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 856, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_multiple_iterators, Py_True) < 0) __PYX_ERR(0, 1192, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":854 - * # AH: check - reason why no multiple_iterators for - * # AllRefs? - * return IteratorRowAllRefs( # <<<<<<<<<<<<<< - * self, - * multiple_iterators=multiple_iterators) + /* "pysam/libcalignmentfile.pyx":1189 + * # could thus be made much quicker, for example + * # by using tell and seek. + * for mate in self.fetch( # <<<<<<<<<<<<<< + * read._delegate.core.mpos, + * read._delegate.core.mpos + 1, */ - __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs), __pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 854, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; - goto __pyx_L0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_5 = __pyx_t_4; __Pyx_INCREF(__pyx_t_5); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + } else { + __pyx_t_7 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1189, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + for (;;) { + if (likely(!__pyx_t_8)) { + if (likely(PyList_CheckExact(__pyx_t_5))) { + if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_5)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 1189, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 1189, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } + } else { + __pyx_t_4 = __pyx_t_8(__pyx_t_5); + if (unlikely(!__pyx_t_4)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1189, __pyx_L1_error) + } + break; } + __Pyx_GOTREF(__pyx_t_4); } + __Pyx_XDECREF_SET(__pyx_v_mate, __pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":836 - * multiple_iterators = False - * - * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< - * if not until_eof and not self.is_remote: - * if not self.has_index(): + /* "pysam/libcalignmentfile.pyx":1194 + * tid=read._delegate.core.mtid, + * multiple_iterators=True): + * if mate.flag & flag != 0 and \ # <<<<<<<<<<<<<< + * mate.query_name == read.query_name: + * break */ - } + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_mate, __pyx_n_s_flag); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_flag); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = PyNumber_And(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1194, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1194, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_9) { + } else { + __pyx_t_2 = __pyx_t_9; + goto __pyx_L8_bool_binop_done; + } - /* "pysam/libcalignmentfile.pyx":858 - * multiple_iterators=multiple_iterators) + /* "pysam/libcalignmentfile.pyx":1195 + * multiple_iterators=True): + * if mate.flag & flag != 0 and \ + * mate.query_name == read.query_name: # <<<<<<<<<<<<<< + * break * else: - * if has_coord: # <<<<<<<<<<<<<< - * raise ValueError( - * "fetching by region is not available for sam files") */ - /*else*/ { - __pyx_t_14 = (__pyx_v_has_coord != 0); - if (unlikely(__pyx_t_14)) { + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_mate, __pyx_n_s_query_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1195, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1195, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_2 = __pyx_t_9; + __pyx_L8_bool_binop_done:; - /* "pysam/libcalignmentfile.pyx":859 - * else: - * if has_coord: - * raise ValueError( # <<<<<<<<<<<<<< - * "fetching by region is not available for sam files") - * + /* "pysam/libcalignmentfile.pyx":1194 + * tid=read._delegate.core.mtid, + * multiple_iterators=True): + * if mate.flag & flag != 0 and \ # <<<<<<<<<<<<<< + * mate.query_name == read.query_name: + * break */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 859, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 859, __pyx_L1_error) + if (__pyx_t_2) { - /* "pysam/libcalignmentfile.pyx":858 - * multiple_iterators=multiple_iterators) + /* "pysam/libcalignmentfile.pyx":1196 + * if mate.flag & flag != 0 and \ + * mate.query_name == read.query_name: + * break # <<<<<<<<<<<<<< * else: - * if has_coord: # <<<<<<<<<<<<<< - * raise ValueError( - * "fetching by region is not available for sam files") - */ - } - - /* "pysam/libcalignmentfile.pyx":862 - * "fetching by region is not available for sam files") - * - * if self.header == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "fetch called for htsfile without header") - */ - __pyx_t_14 = ((__pyx_v_self->header == NULL) != 0); - if (unlikely(__pyx_t_14)) { - - /* "pysam/libcalignmentfile.pyx":863 - * - * if self.header == NULL: - * raise ValueError( # <<<<<<<<<<<<<< - * "fetch called for htsfile without header") - * + * raise ValueError("mate not found") */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 863, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 863, __pyx_L1_error) + goto __pyx_L6_break; - /* "pysam/libcalignmentfile.pyx":862 - * "fetching by region is not available for sam files") - * - * if self.header == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "fetch called for htsfile without header") + /* "pysam/libcalignmentfile.pyx":1194 + * tid=read._delegate.core.mtid, + * multiple_iterators=True): + * if mate.flag & flag != 0 and \ # <<<<<<<<<<<<<< + * mate.query_name == read.query_name: + * break */ } - /* "pysam/libcalignmentfile.pyx":868 - * # check if targets are defined - * # give warning, sam_read1 segfaults - * if self.header.n_targets == 0: # <<<<<<<<<<<<<< - * warnings.warn("fetch called for htsfile without header") - * - */ - __pyx_t_14 = ((__pyx_v_self->header->n_targets == 0) != 0); - if (__pyx_t_14) { - - /* "pysam/libcalignmentfile.pyx":869 - * # give warning, sam_read1 segfaults - * if self.header.n_targets == 0: - * warnings.warn("fetch called for htsfile without header") # <<<<<<<<<<<<<< - * - * return IteratorRowAll(self, + /* "pysam/libcalignmentfile.pyx":1189 + * # could thus be made much quicker, for example + * # by using tell and seek. + * for mate in self.fetch( # <<<<<<<<<<<<<< + * read._delegate.core.mpos, + * read._delegate.core.mpos + 1, */ - __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 869, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_warn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 869, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 869, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + /*else*/ { - /* "pysam/libcalignmentfile.pyx":868 - * # check if targets are defined - * # give warning, sam_read1 segfaults - * if self.header.n_targets == 0: # <<<<<<<<<<<<<< - * warnings.warn("fetch called for htsfile without header") + /* "pysam/libcalignmentfile.pyx":1198 + * break + * else: + * raise ValueError("mate not found") # <<<<<<<<<<<<<< * + * return mate */ - } + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1198, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 1198, __pyx_L1_error) + } - /* "pysam/libcalignmentfile.pyx":871 - * warnings.warn("fetch called for htsfile without header") - * - * return IteratorRowAll(self, # <<<<<<<<<<<<<< - * multiple_iterators=multiple_iterators) - * + /* "pysam/libcalignmentfile.pyx":1189 + * # could thus be made much quicker, for example + * # by using tell and seek. + * for mate in self.fetch( # <<<<<<<<<<<<<< + * read._delegate.core.mpos, + * read._delegate.core.mpos + 1, */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 871, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_v_self)); + __pyx_L6_break:; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":872 + /* "pysam/libcalignmentfile.pyx":1200 + * raise ValueError("mate not found") * - * return IteratorRowAll(self, - * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< + * return mate # <<<<<<<<<<<<<< * - * def head(self, n, multiple_iterators=True): + * def pileup(self, */ - __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 872, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 872, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_mate); + __pyx_r = __pyx_v_mate; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":871 - * warnings.warn("fetch called for htsfile without header") - * - * return IteratorRowAll(self, # <<<<<<<<<<<<<< - * multiple_iterators=multiple_iterators) + /* "pysam/libcalignmentfile.pyx":1143 + * multiple_iterators=multiple_iterators) * - */ - __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll), __pyx_t_8, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 871, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_r = __pyx_t_7; - __pyx_t_7 = 0; - goto __pyx_L0; - } - - /* "pysam/libcalignmentfile.pyx":759 - * return 1, rtid, rstart, rend + * def mate(self, AlignedSegment read): # <<<<<<<<<<<<<< + * '''return the mate of :class:`~pysam.AlignedSegment` `read`. * - * def fetch(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.mate", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_multiple_iterators); + __Pyx_XDECREF(__pyx_v_mate); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":874 - * multiple_iterators=multiple_iterators) - * - * def head(self, n, multiple_iterators=True): # <<<<<<<<<<<<<< - * '''return an iterator over the first n alignments. +/* "pysam/libcalignmentfile.pyx":1202 + * return mate * + * def pileup(self, # <<<<<<<<<<<<<< + * contig=None, + * start=None, */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17head(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_16head[] = "AlignmentFile.head(self, n, multiple_iterators=True)\nreturn an iterator over the first n alignments. \n\n This iterator is is useful for inspecting the bam-file.\n\n Parameters\n ----------\n\n multiple_iterators : bool\n \n is set to True by default in order to\n avoid changing the current file position.\n \n Returns\n -------\n \n an iterator over a collection of reads\n \n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17head(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_n = 0; - PyObject *__pyx_v_multiple_iterators = 0; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_14pileup[] = "AlignmentFile.pileup(self, contig=None, start=None, stop=None, region=None, reference=None, end=None, **kwargs)\nperform a :term:`pileup` within a :term:`region`. The region is\n specified by :term:`contig`, `start` and `stop` (using\n 0-based indexing). :term:`reference` and `end` are also accepted for\n backward compatiblity as synonyms for :term:`contig` and `stop`,\n respectively. Alternatively, a samtools 'region' string\n can be supplied.\n\n Without 'contig' or 'region' all reads will be used for the\n pileup. The reads will be returned ordered by\n :term:`contig` sequence, which will not necessarily be the\n order within the file.\n\n Note that :term:`SAM` formatted files do not allow random\n access. In these files, if a 'region' or 'contig' are\n given an exception is raised.\n\n .. note::\n\n 'all' reads which overlap the region are returned. The\n first base returned will be the first base of the first\n read 'not' necessarily the first base of the region used\n in the query.\n\n Parameters\n ----------\n\n truncate : bool\n\n By default, the samtools pileup engine outputs all reads\n overlapping a region. If truncate is True and a region is\n given, only columns in the exact region specificied are\n returned.\n\n max_depth : int\n Maximum read depth permitted. The default limit is '8000'.\n\n stepper : string\n The stepper controls how the iterator advances.\n Possible options for the stepper are\n\n ``all``\n skip reads in which any of the following flags are set:\n BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL, BAM_FDUP\n\n ``nofilter``\n uses every single read turning off any filtering.\n\n ``samtools``\n same filter and read processing ""as in :term:`csamtools`\n pileup. For full compatibility, this requires a\n 'fastafile' to be given. The following options all pertain\n to filtering of the ``samtools`` stepper.\n\n fastafile : :class:`~pysam.FastaFile` object.\n\n This is required for some of the steppers.\n\n ignore_overlaps: bool\n\n If set to True, detect if read pairs overlap and only take\n the higher quality base. This is the default.\n\n flag_filter : int\n\n ignore reads where any of the bits in the flag are set. The default is\n BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP.\n\n flag_require : int\n\n only use reads where certain flags are set. The default is 0.\n\n ignore_orphans: bool\n\n ignore orphans (paired reads that are not in a proper pair).\n The default is to ignore orphans.\n \n min_base_quality: int\n\n Minimum base quality. Bases below the minimum quality will\n not be output.\n\n adjust_capq_threshold: int\n\n adjust mapping quality. The default is 0 for no\n adjustment. The recommended value for adjustment is 50.\n\n min_mapping_quality : int\n\n only use reads above a minimum mapping quality. The default is 0.\n\n compute_baq: bool\n\n re-alignment computing per-Base Alignment Qualities (BAQ). The\n default is to do re-alignment. Realignment requires a reference\n sequence. If none is present, no realignment will be performed.\n\n redo_baq: bool\n\n recompute per-Base Alignment Quality on the fly ignoring\n existing base qualities. The default is False (use existing\n base qualities).\n\n adjust_capq_threshold: int\n\n adjust mapping quality. The default is 0 for no\n adjustment. The recommended value for adjustment is 50.\n\n Retur""ns\n -------\n\n an iterator over genomic positions.\n\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_contig = 0; + PyObject *__pyx_v_start = 0; + PyObject *__pyx_v_stop = 0; + PyObject *__pyx_v_region = 0; + PyObject *__pyx_v_reference = 0; + PyObject *__pyx_v_end = 0; + PyObject *__pyx_v_kwargs = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("head (wrapper)", 0); + __Pyx_RefNannySetupContext("pileup (wrapper)", 0); + __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_n,&__pyx_n_s_multiple_iterators,0}; - PyObject* values[2] = {0,0}; - values[1] = ((PyObject *)Py_True); + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_reference,&__pyx_n_s_end,0}; + PyObject* values[6] = {0,0,0,0,0,0}; + + /* "pysam/libcalignmentfile.pyx":1203 + * + * def pileup(self, + * contig=None, # <<<<<<<<<<<<<< + * start=None, + * stop=None, + */ + values[0] = ((PyObject *)Py_None); + + /* "pysam/libcalignmentfile.pyx":1204 + * def pileup(self, + * contig=None, + * start=None, # <<<<<<<<<<<<<< + * stop=None, + * region=None, + */ + values[1] = ((PyObject *)Py_None); + + /* "pysam/libcalignmentfile.pyx":1205 + * contig=None, + * start=None, + * stop=None, # <<<<<<<<<<<<<< + * region=None, + * reference=None, + */ + values[2] = ((PyObject *)Py_None); + + /* "pysam/libcalignmentfile.pyx":1206 + * start=None, + * stop=None, + * region=None, # <<<<<<<<<<<<<< + * reference=None, + * end=None, + */ + values[3] = ((PyObject *)Py_None); + + /* "pysam/libcalignmentfile.pyx":1207 + * stop=None, + * region=None, + * reference=None, # <<<<<<<<<<<<<< + * end=None, + * **kwargs): + */ + values[4] = ((PyObject *)Py_None); + + /* "pysam/libcalignmentfile.pyx":1208 + * region=None, + * reference=None, + * end=None, # <<<<<<<<<<<<<< + * **kwargs): + * """perform a :term:`pileup` within a :term:`region`. The region is + */ + values[5] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -11781,616 +16799,622 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17head(PyOb kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_contig); + if (value) { values[0] = value; kw_args--; } + } CYTHON_FALLTHROUGH; case 1: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start); if (value) { values[1] = value; kw_args--; } } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop); + if (value) { values[2] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region); + if (value) { values[3] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 4: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); + if (value) { values[4] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 5: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); + if (value) { values[5] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "head") < 0)) __PYX_ERR(0, 874, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "pileup") < 0)) __PYX_ERR(0, 1202, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; + CYTHON_FALLTHROUGH; + case 0: break; default: goto __pyx_L5_argtuple_error; } } - __pyx_v_n = values[0]; - __pyx_v_multiple_iterators = values[1]; + __pyx_v_contig = values[0]; + __pyx_v_start = values[1]; + __pyx_v_stop = values[2]; + __pyx_v_region = values[3]; + __pyx_v_reference = values[4]; + __pyx_v_end = values[5]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("head", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 874, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("pileup", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1202, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.head", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_16head(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_n, __pyx_v_multiple_iterators); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_16head(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_n, PyObject *__pyx_v_multiple_iterators) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("head", 0); - __Pyx_TraceCall("head", __pyx_f[0], 874, 0, __PYX_ERR(0, 874, __pyx_L1_error)); - - /* "pysam/libcalignmentfile.pyx":893 - * - * ''' - * return IteratorRowHead(self, n, # <<<<<<<<<<<<<< - * multiple_iterators=multiple_iterators) - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 893, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); - __Pyx_INCREF(__pyx_v_n); - __Pyx_GIVEREF(__pyx_v_n); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_n); - - /* "pysam/libcalignmentfile.pyx":894 - * ''' - * return IteratorRowHead(self, n, - * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< - * - * def mate(self, AlignedSegment read): - */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 894, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 894, __pyx_L1_error) - - /* "pysam/libcalignmentfile.pyx":893 - * - * ''' - * return IteratorRowHead(self, n, # <<<<<<<<<<<<<< - * multiple_iterators=multiple_iterators) - * - */ - __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 893, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - /* "pysam/libcalignmentfile.pyx":874 - * multiple_iterators=multiple_iterators) - * - * def head(self, n, multiple_iterators=True): # <<<<<<<<<<<<<< - * '''return an iterator over the first n alignments. - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.head", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_14pileup(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_reference, __pyx_v_end, __pyx_v_kwargs); -/* "pysam/libcalignmentfile.pyx":896 - * multiple_iterators=multiple_iterators) - * - * def mate(self, AlignedSegment read): # <<<<<<<<<<<<<< - * '''return the mate of :class:`~pysam.AlignedSegment` `read`. + /* "pysam/libcalignmentfile.pyx":1202 + * return mate * + * def pileup(self, # <<<<<<<<<<<<<< + * contig=None, + * start=None, */ -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_18mate[] = "AlignmentFile.mate(self, AlignedSegment read)\nreturn the mate of :class:`~pysam.AlignedSegment` `read`.\n\n .. note::\n\n Calling this method will change the file position.\n This might interfere with any iterators that have\n not re-opened the file.\n\n .. note::\n \n This method is too slow for high-throughput processing.\n If a read needs to be processed with its mate, work\n from a read name sorted file or, better, cache reads.\n\n Returns\n -------\n \n :class:`~pysam.AlignedSegment` : the mate\n\n Raises\n ------\n\n ValueError\n if the read is unpaired or the mate is unmapped\n\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("mate (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment, 1, "read", 0))) __PYX_ERR(0, 896, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18mate(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_read)); - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; + __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18mate(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read) { - uint32_t __pyx_v_flag; - int __pyx_v_x; - PyObject *__pyx_v_mate = NULL; +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_14pileup(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reference, PyObject *__pyx_v_end, PyObject *__pyx_v_kwargs) { + int __pyx_v_rtid; + int __pyx_v_rstart; + int __pyx_v_rstop; + int __pyx_v_has_coord; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - uint16_t __pyx_t_1; + PyObject *__pyx_t_1 = NULL; int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; + int __pyx_t_3; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; - Py_ssize_t __pyx_t_7; - PyObject *(*__pyx_t_8)(PyObject *); - int __pyx_t_9; - __Pyx_RefNannySetupContext("mate", 0); - __Pyx_TraceCall("mate", __pyx_f[0], 896, 0, __PYX_ERR(0, 896, __pyx_L1_error)); - - /* "pysam/libcalignmentfile.pyx":923 - * - * ''' - * cdef uint32_t flag = read._delegate.core.flag # <<<<<<<<<<<<<< - * - * if flag & BAM_FPAIRED == 0: - */ - __pyx_t_1 = __pyx_v_read->_delegate->core.flag; - __pyx_v_flag = __pyx_t_1; - - /* "pysam/libcalignmentfile.pyx":925 - * cdef uint32_t flag = read._delegate.core.flag - * - * if flag & BAM_FPAIRED == 0: # <<<<<<<<<<<<<< - * raise ValueError("read %s: is unpaired" % - * (read.query_name)) - */ - __pyx_t_2 = (((__pyx_v_flag & BAM_FPAIRED) == 0) != 0); - if (unlikely(__pyx_t_2)) { - - /* "pysam/libcalignmentfile.pyx":927 - * if flag & BAM_FPAIRED == 0: - * raise ValueError("read %s: is unpaired" % - * (read.query_name)) # <<<<<<<<<<<<<< - * if flag & BAM_FMUNMAP != 0: - * raise ValueError("mate %s: is unmapped" % - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 927, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_t_10; + int __pyx_t_11; + int __pyx_t_12; + int __pyx_t_13; + __Pyx_RefNannySetupContext("pileup", 0); + __Pyx_TraceCall("pileup", __pyx_f[0], 1202, 0, __PYX_ERR(0, 1202, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":926 + /* "pysam/libcalignmentfile.pyx":1325 + * cdef int rtid, rstart, rstop, has_coord * - * if flag & BAM_FPAIRED == 0: - * raise ValueError("read %s: is unpaired" % # <<<<<<<<<<<<<< - * (read.query_name)) - * if flag & BAM_FMUNMAP != 0: - */ - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_read_s_is_unpaired, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 926, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 926, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 926, __pyx_L1_error) - - /* "pysam/libcalignmentfile.pyx":925 - * cdef uint32_t flag = read._delegate.core.flag + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError("I/O operation on closed file") * - * if flag & BAM_FPAIRED == 0: # <<<<<<<<<<<<<< - * raise ValueError("read %s: is unpaired" % - * (read.query_name)) - */ - } - - /* "pysam/libcalignmentfile.pyx":928 - * raise ValueError("read %s: is unpaired" % - * (read.query_name)) - * if flag & BAM_FMUNMAP != 0: # <<<<<<<<<<<<<< - * raise ValueError("mate %s: is unmapped" % - * (read.query_name)) */ - __pyx_t_2 = (((__pyx_v_flag & BAM_FMUNMAP) != 0) != 0); - if (unlikely(__pyx_t_2)) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1325, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1325, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = ((!__pyx_t_2) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":930 - * if flag & BAM_FMUNMAP != 0: - * raise ValueError("mate %s: is unmapped" % - * (read.query_name)) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1326 * - * # xor flags to get the other mate - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 930, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pysam/libcalignmentfile.pyx":929 - * (read.query_name)) - * if flag & BAM_FMUNMAP != 0: - * raise ValueError("mate %s: is unmapped" % # <<<<<<<<<<<<<< - * (read.query_name)) + * if not self.is_open: + * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< * + * has_coord, rtid, rstart, rstop = self.parse_region( */ - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_mate_s_is_unmapped, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 929, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 929, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1326, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 1326, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":928 - * raise ValueError("read %s: is unpaired" % - * (read.query_name)) - * if flag & BAM_FMUNMAP != 0: # <<<<<<<<<<<<<< - * raise ValueError("mate %s: is unmapped" % - * (read.query_name)) + /* "pysam/libcalignmentfile.pyx":1325 + * cdef int rtid, rstart, rstop, has_coord + * + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError("I/O operation on closed file") + * */ } - /* "pysam/libcalignmentfile.pyx":933 + /* "pysam/libcalignmentfile.pyx":1328 + * raise ValueError("I/O operation on closed file") * - * # xor flags to get the other mate - * cdef int x = BAM_FREAD1 + BAM_FREAD2 # <<<<<<<<<<<<<< - * flag = (flag ^ x) & x + * has_coord, rtid, rstart, rstop = self.parse_region( # <<<<<<<<<<<<<< + * contig, start, stop, region, reference=reference, end=end) * */ - __pyx_v_x = (BAM_FREAD1 + BAM_FREAD2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_parse_region); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1328, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libcalignmentfile.pyx":934 - * # xor flags to get the other mate - * cdef int x = BAM_FREAD1 + BAM_FREAD2 - * flag = (flag ^ x) & x # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1329 * - * # Make sure to use a separate file to jump around - */ - __pyx_v_flag = ((__pyx_v_flag ^ __pyx_v_x) & __pyx_v_x); - - /* "pysam/libcalignmentfile.pyx":942 - * # could thus be made much quicker, for example - * # by using tell and seek. - * for mate in self.fetch( # <<<<<<<<<<<<<< - * read._delegate.core.mpos, - * read._delegate.core.mpos + 1, - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 942, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - - /* "pysam/libcalignmentfile.pyx":943 - * # by using tell and seek. - * for mate in self.fetch( - * read._delegate.core.mpos, # <<<<<<<<<<<<<< - * read._delegate.core.mpos + 1, - * tid=read._delegate.core.mtid, + * has_coord, rtid, rstart, rstop = self.parse_region( + * contig, start, stop, region, reference=reference, end=end) # <<<<<<<<<<<<<< + * + * if self.is_bam or self.is_cram: */ - __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_read->_delegate->core.mpos); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 943, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1328, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - - /* "pysam/libcalignmentfile.pyx":944 - * for mate in self.fetch( - * read._delegate.core.mpos, - * read._delegate.core.mpos + 1, # <<<<<<<<<<<<<< - * tid=read._delegate.core.mtid, - * multiple_iterators=True): - */ - __pyx_t_5 = __Pyx_PyInt_From_long((__pyx_v_read->_delegate->core.mpos + 1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 944, __pyx_L1_error) + __Pyx_INCREF(__pyx_v_contig); + __Pyx_GIVEREF(__pyx_v_contig); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_contig); + __Pyx_INCREF(__pyx_v_start); + __Pyx_GIVEREF(__pyx_v_start); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_start); + __Pyx_INCREF(__pyx_v_stop); + __Pyx_GIVEREF(__pyx_v_stop); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_stop); + __Pyx_INCREF(__pyx_v_region); + __Pyx_GIVEREF(__pyx_v_region); + PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_region); + __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1329, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1329, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1329, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":942 - * # could thus be made much quicker, for example - * # by using tell and seek. - * for mate in self.fetch( # <<<<<<<<<<<<<< - * read._delegate.core.mpos, - * read._delegate.core.mpos + 1, + /* "pysam/libcalignmentfile.pyx":1328 + * raise ValueError("I/O operation on closed file") + * + * has_coord, rtid, rstart, rstop = self.parse_region( # <<<<<<<<<<<<<< + * contig, start, stop, region, reference=reference, end=end) + * */ - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 942, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1328, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); - __pyx_t_4 = 0; - __pyx_t_5 = 0; - - /* "pysam/libcalignmentfile.pyx":945 - * read._delegate.core.mpos, - * read._delegate.core.mpos + 1, - * tid=read._delegate.core.mtid, # <<<<<<<<<<<<<< - * multiple_iterators=True): - * if mate.flag & flag != 0 and \ - */ - __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 945, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_read->_delegate->core.mtid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 945, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_tid, __pyx_t_4) < 0) __PYX_ERR(0, 945, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { + PyObject* sequence = __pyx_t_6; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 4)) { + if (size > 4) __Pyx_RaiseTooManyValuesError(4); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1328, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_4 = PyList_GET_ITEM(sequence, 1); + __pyx_t_1 = PyList_GET_ITEM(sequence, 2); + __pyx_t_7 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_7); + #else + { + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_1,&__pyx_t_7}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1328, __pyx_L1_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; + } + } + #endif + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else { + Py_ssize_t index = -1; + PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_1,&__pyx_t_7}; + __pyx_t_8 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1328, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; + for (index=0; index < 4; index++) { + PyObject* item = __pyx_t_9(__pyx_t_8); if (unlikely(!item)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) __PYX_ERR(0, 1328, __pyx_L1_error) + __pyx_t_9 = NULL; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L5_unpacking_done; + __pyx_L4_unpacking_failed:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1328, __pyx_L1_error) + __pyx_L5_unpacking_done:; + } + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1328, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1328, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1328, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1328, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_has_coord = __pyx_t_10; + __pyx_v_rtid = __pyx_t_11; + __pyx_v_rstart = __pyx_t_12; + __pyx_v_rstop = __pyx_t_13; - /* "pysam/libcalignmentfile.pyx":946 - * read._delegate.core.mpos + 1, - * tid=read._delegate.core.mtid, - * multiple_iterators=True): # <<<<<<<<<<<<<< - * if mate.flag & flag != 0 and \ - * mate.query_name == read.query_name: - */ - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_multiple_iterators, Py_True) < 0) __PYX_ERR(0, 945, __pyx_L1_error) - - /* "pysam/libcalignmentfile.pyx":942 - * # could thus be made much quicker, for example - * # by using tell and seek. - * for mate in self.fetch( # <<<<<<<<<<<<<< - * read._delegate.core.mpos, - * read._delegate.core.mpos + 1, + /* "pysam/libcalignmentfile.pyx":1331 + * contig, start, stop, region, reference=reference, end=end) + * + * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< + * if not self.has_index(): + * raise ValueError("no index available for pileup") */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 942, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1331, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_5 = __pyx_t_4; __Pyx_INCREF(__pyx_t_5); __pyx_t_7 = 0; - __pyx_t_8 = NULL; + if (!__pyx_t_2) { } else { - __pyx_t_7 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 942, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 942, __pyx_L1_error) + __pyx_t_3 = __pyx_t_2; + goto __pyx_L7_bool_binop_done; } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (likely(!__pyx_t_8)) { - if (likely(PyList_CheckExact(__pyx_t_5))) { - if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_5)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 942, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 942, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_5)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 942, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 942, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_8(__pyx_t_5); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 942, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF_SET(__pyx_v_mate, __pyx_t_4); - __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1331, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1331, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_3 = __pyx_t_2; + __pyx_L7_bool_binop_done:; + if (likely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":947 - * tid=read._delegate.core.mtid, - * multiple_iterators=True): - * if mate.flag & flag != 0 and \ # <<<<<<<<<<<<<< - * mate.query_name == read.query_name: - * break + /* "pysam/libcalignmentfile.pyx":1332 + * + * if self.is_bam or self.is_cram: + * if not self.has_index(): # <<<<<<<<<<<<<< + * raise ValueError("no index available for pileup") + * */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_mate, __pyx_n_s_flag); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_flag); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = PyNumber_And(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 947, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 947, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (__pyx_t_9) { + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1332, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (__pyx_t_1) { + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1332, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { - __pyx_t_2 = __pyx_t_9; - goto __pyx_L8_bool_binop_done; + __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1332, __pyx_L1_error) } - - /* "pysam/libcalignmentfile.pyx":948 - * multiple_iterators=True): - * if mate.flag & flag != 0 and \ - * mate.query_name == read.query_name: # <<<<<<<<<<<<<< - * break - * else: - */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_mate, __pyx_n_s_query_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 948, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 948, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1332, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 948, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_2 = __pyx_t_9; - __pyx_L8_bool_binop_done:; + __pyx_t_2 = ((!__pyx_t_3) != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcalignmentfile.pyx":947 - * tid=read._delegate.core.mtid, - * multiple_iterators=True): - * if mate.flag & flag != 0 and \ # <<<<<<<<<<<<<< - * mate.query_name == read.query_name: - * break + /* "pysam/libcalignmentfile.pyx":1333 + * if self.is_bam or self.is_cram: + * if not self.has_index(): + * raise ValueError("no index available for pileup") # <<<<<<<<<<<<<< + * + * if has_coord: + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1333, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 1333, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1332 + * + * if self.is_bam or self.is_cram: + * if not self.has_index(): # <<<<<<<<<<<<<< + * raise ValueError("no index available for pileup") + * + */ + } + + /* "pysam/libcalignmentfile.pyx":1335 + * raise ValueError("no index available for pileup") + * + * if has_coord: # <<<<<<<<<<<<<< + * return IteratorColumnRegion(self, + * tid=rtid, */ + __pyx_t_2 = (__pyx_v_has_coord != 0); if (__pyx_t_2) { - /* "pysam/libcalignmentfile.pyx":949 - * if mate.flag & flag != 0 and \ - * mate.query_name == read.query_name: - * break # <<<<<<<<<<<<<< - * else: - * raise ValueError("mate not found") + /* "pysam/libcalignmentfile.pyx":1336 + * + * if has_coord: + * return IteratorColumnRegion(self, # <<<<<<<<<<<<<< + * tid=rtid, + * start=rstart, */ - goto __pyx_L6_break; + __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1336, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_self)); - /* "pysam/libcalignmentfile.pyx":947 - * tid=read._delegate.core.mtid, - * multiple_iterators=True): - * if mate.flag & flag != 0 and \ # <<<<<<<<<<<<<< - * mate.query_name == read.query_name: - * break + /* "pysam/libcalignmentfile.pyx":1337 + * if has_coord: + * return IteratorColumnRegion(self, + * tid=rtid, # <<<<<<<<<<<<<< + * start=rstart, + * stop=rstop, */ - } + __pyx_t_1 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1337, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1337, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_tid, __pyx_t_4) < 0) __PYX_ERR(0, 1337, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":942 - * # could thus be made much quicker, for example - * # by using tell and seek. - * for mate in self.fetch( # <<<<<<<<<<<<<< - * read._delegate.core.mpos, - * read._delegate.core.mpos + 1, + /* "pysam/libcalignmentfile.pyx":1338 + * return IteratorColumnRegion(self, + * tid=rtid, + * start=rstart, # <<<<<<<<<<<<<< + * stop=rstop, + * **kwargs) */ - } - /*else*/ { + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_rstart); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1338, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_start, __pyx_t_4) < 0) __PYX_ERR(0, 1337, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":951 - * break - * else: - * raise ValueError("mate not found") # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1339 + * tid=rtid, + * start=rstart, + * stop=rstop, # <<<<<<<<<<<<<< + * **kwargs) + * else: + */ + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_rstop); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1339, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_stop, __pyx_t_4) < 0) __PYX_ERR(0, 1337, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_7 = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":1340 + * start=rstart, + * stop=rstop, + * **kwargs) # <<<<<<<<<<<<<< + * else: + * return IteratorColumnAllRefs(self, **kwargs) + */ + if (__Pyx_MergeKeywords(__pyx_t_7, __pyx_v_kwargs) < 0) __PYX_ERR(0, 1340, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1336 * - * return mate + * if has_coord: + * return IteratorColumnRegion(self, # <<<<<<<<<<<<<< + * tid=rtid, + * start=rstart, */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 951, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 951, __pyx_L1_error) - } + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion), __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1336, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":942 - * # could thus be made much quicker, for example - * # by using tell and seek. - * for mate in self.fetch( # <<<<<<<<<<<<<< - * read._delegate.core.mpos, - * read._delegate.core.mpos + 1, + /* "pysam/libcalignmentfile.pyx":1335 + * raise ValueError("no index available for pileup") + * + * if has_coord: # <<<<<<<<<<<<<< + * return IteratorColumnRegion(self, + * tid=rtid, */ - __pyx_L6_break:; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } - /* "pysam/libcalignmentfile.pyx":953 - * raise ValueError("mate not found") + /* "pysam/libcalignmentfile.pyx":1342 + * **kwargs) + * else: + * return IteratorColumnAllRefs(self, **kwargs) # <<<<<<<<<<<<<< * - * return mate # <<<<<<<<<<<<<< + * else: + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1342, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); + __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs), __pyx_t_1, __pyx_v_kwargs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1342, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; + goto __pyx_L0; + } + + /* "pysam/libcalignmentfile.pyx":1331 + * contig, start, stop, region, reference=reference, end=end) * - * def pileup(self, + * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< + * if not self.has_index(): + * raise ValueError("no index available for pileup") */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_mate); - __pyx_r = __pyx_v_mate; - goto __pyx_L0; + } - /* "pysam/libcalignmentfile.pyx":896 - * multiple_iterators=multiple_iterators) + /* "pysam/libcalignmentfile.pyx":1345 * - * def mate(self, AlignedSegment read): # <<<<<<<<<<<<<< - * '''return the mate of :class:`~pysam.AlignedSegment` `read`. + * else: + * raise NotImplementedError( # <<<<<<<<<<<<<< + * "pileup of samfiles not implemented yet") + * + */ + /*else*/ { + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__45, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1345, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 1345, __pyx_L1_error) + } + + /* "pysam/libcalignmentfile.pyx":1202 + * return mate * + * def pileup(self, # <<<<<<<<<<<<<< + * contig=None, + * start=None, */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.mate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_mate); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":955 - * return mate +/* "pysam/libcalignmentfile.pyx":1348 + * "pileup of samfiles not implemented yet") * - * def pileup(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * def count(self, # <<<<<<<<<<<<<< + * contig=None, + * start=None, */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_20pileup[] = "AlignmentFile.pileup(self, reference=None, start=None, end=None, region=None, **kwargs)\nperform a :term:`pileup` within a :term:`region`. The region is\n specified by :term:`reference`, 'start' and 'end' (using\n 0-based indexing). Alternatively, a samtools 'region' string\n can be supplied.\n\n Without 'reference' or 'region' all reads will be used for the\n pileup. The reads will be returned ordered by\n :term:`reference` sequence, which will not necessarily be the\n order within the file.\n\n Note that :term:`SAM` formatted files do not allow random\n access. In these files, if a 'region' or 'reference' are\n given an exception is raised.\n\n .. note::\n\n 'all' reads which overlap the region are returned. The\n first base returned will be the first base of the first\n read 'not' necessarily the first base of the region used\n in the query.\n\n Parameters\n ----------\n\n stepper : string\n The stepper controls how the iterator advances.\n Possible options for the stepper are\n\n ``all``\n skip reads in which any of the following flags are set:\n BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL, BAM_FDUP\n\n ``nofilter``\n uses every single read\n\n ``samtools``\n same filter and read processing as in :term:`csamtools`\n pileup. This requires a 'fastafile' to be given.\n\n\n fastafile : :class:`~pysam.FastaFile` object.\n\n This is required for some of the steppers.\n\n max_depth : int\n Maximum read depth permitted. The default limit is '8000'.\n\n truncate : bool\n\n By default, the samtools pileup engine outputs all reads\n overlapping a region. If truncate is True and a region is\n given, only columns in the exact region specificied are\n "" returned.\n\n Returns\n -------\n\n an iterator over genomic positions.\n\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_reference = 0; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17count(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_16count[] = "AlignmentFile.count(self, contig=None, start=None, stop=None, region=None, until_eof=False, read_callback='nofilter', reference=None, end=None)\ncount the number of reads in :term:`region`\n\n The region is specified by :term:`contig`, `start` and `stop`.\n :term:`reference` and `end` are also accepted for backward\n compatiblity as synonyms for :term:`contig` and `stop`,\n respectively. Alternatively, a :term:`samtools` :term:`region`\n string can be supplied.\n\n A :term:`SAM` file does not allow random access and if\n `region` or `contig` are given, an exception is raised.\n\n Parameters\n ----------\n\n contig : string\n reference_name of the genomic region (chromosome)\n\n start : int\n start of the genomic region (0-based inclusive)\n\n stop : int\n end of the genomic region (0-based exclusive)\n\n region : string\n a region string in samtools format.\n\n until_eof : bool\n count until the end of the file, possibly including\n unmapped reads as well.\n\n read_callback: string or function\n\n select a call-back to ignore reads when counting. It can\n be either a string with the following values:\n\n ``all``\n skip reads in which any of the following\n flags are set: BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL,\n BAM_FDUP\n\n ``nofilter``\n uses every single read\n\n Alternatively, `read_callback` can be a function\n ``check_read(read)`` that should return True only for\n those reads that shall be included in the counting.\n\n reference : string\n backward compatible synonym for `contig`\n\n end : int\n backward compatible synonym for `stop`\n\n Raises\n ------\n\n ValueError\n if the genomic coo""rdinates are out of range or invalid.\n\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17count(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_contig = 0; PyObject *__pyx_v_start = 0; - PyObject *__pyx_v_end = 0; + PyObject *__pyx_v_stop = 0; PyObject *__pyx_v_region = 0; - PyObject *__pyx_v_kwargs = 0; + PyObject *__pyx_v_until_eof = 0; + PyObject *__pyx_v_read_callback = 0; + PyObject *__pyx_v_reference = 0; + PyObject *__pyx_v_end = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("pileup (wrapper)", 0); - __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; - __Pyx_GOTREF(__pyx_v_kwargs); + __Pyx_RefNannySetupContext("count (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,0}; - PyObject* values[4] = {0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_until_eof,&__pyx_n_s_read_callback,&__pyx_n_s_reference,&__pyx_n_s_end,0}; + PyObject* values[8] = {0,0,0,0,0,0,0,0}; - /* "pysam/libcalignmentfile.pyx":956 + /* "pysam/libcalignmentfile.pyx":1349 * - * def pileup(self, - * reference=None, # <<<<<<<<<<<<<< - * start=None, - * end=None, + * def count(self, + * contig=None, # <<<<<<<<<<<<<< + * start=None, + * stop=None, */ values[0] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":957 - * def pileup(self, - * reference=None, - * start=None, # <<<<<<<<<<<<<< - * end=None, - * region=None, + /* "pysam/libcalignmentfile.pyx":1350 + * def count(self, + * contig=None, + * start=None, # <<<<<<<<<<<<<< + * stop=None, + * region=None, */ values[1] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":958 - * reference=None, - * start=None, - * end=None, # <<<<<<<<<<<<<< - * region=None, - * **kwargs): + /* "pysam/libcalignmentfile.pyx":1351 + * contig=None, + * start=None, + * stop=None, # <<<<<<<<<<<<<< + * region=None, + * until_eof=False, */ values[2] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":959 - * start=None, - * end=None, - * region=None, # <<<<<<<<<<<<<< - * **kwargs): - * """perform a :term:`pileup` within a :term:`region`. The region is + /* "pysam/libcalignmentfile.pyx":1352 + * start=None, + * stop=None, + * region=None, # <<<<<<<<<<<<<< + * until_eof=False, + * read_callback="nofilter", + */ + values[3] = ((PyObject *)Py_None); + + /* "pysam/libcalignmentfile.pyx":1353 + * stop=None, + * region=None, + * until_eof=False, # <<<<<<<<<<<<<< + * read_callback="nofilter", + * reference=None, + */ + values[4] = ((PyObject *)Py_False); + values[5] = ((PyObject *)__pyx_n_s_nofilter); + + /* "pysam/libcalignmentfile.pyx":1355 + * until_eof=False, + * read_callback="nofilter", + * reference=None, # <<<<<<<<<<<<<< + * end=None): + * '''count the number of reads in :term:`region` + */ + values[6] = ((PyObject *)Py_None); + + /* "pysam/libcalignmentfile.pyx":1356 + * read_callback="nofilter", + * reference=None, + * end=None): # <<<<<<<<<<<<<< + * '''count the number of reads in :term:`region` + * */ - values[3] = ((PyObject *)Py_None); + values[7] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); @@ -12406,7 +17430,7 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21pileup(Py switch (pos_args) { case 0: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_contig); if (value) { values[0] = value; kw_args--; } } CYTHON_FALLTHROUGH; @@ -12418,7 +17442,7 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21pileup(Py CYTHON_FALLTHROUGH; case 2: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop); if (value) { values[2] = value; kw_args--; } } CYTHON_FALLTHROUGH; @@ -12427,12 +17451,44 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21pileup(Py PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region); if (value) { values[3] = value; kw_args--; } } + CYTHON_FALLTHROUGH; + case 4: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_until_eof); + if (value) { values[4] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 5: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_read_callback); + if (value) { values[5] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 6: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); + if (value) { values[6] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 7: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); + if (value) { values[7] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "pileup") < 0)) __PYX_ERR(0, 955, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count") < 0)) __PYX_ERR(0, 1348, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); @@ -12445,41 +17501,42 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21pileup(Py default: goto __pyx_L5_argtuple_error; } } - __pyx_v_reference = values[0]; + __pyx_v_contig = values[0]; __pyx_v_start = values[1]; - __pyx_v_end = values[2]; + __pyx_v_stop = values[2]; __pyx_v_region = values[3]; + __pyx_v_until_eof = values[4]; + __pyx_v_read_callback = values[5]; + __pyx_v_reference = values[6]; + __pyx_v_end = values[7]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("pileup", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 955, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("count", 0, 0, 8, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1348, __pyx_L3_error) __pyx_L3_error:; - __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20pileup(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_kwargs); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_16count(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_until_eof, __pyx_v_read_callback, __pyx_v_reference, __pyx_v_end); - /* "pysam/libcalignmentfile.pyx":955 - * return mate + /* "pysam/libcalignmentfile.pyx":1348 + * "pileup of samfiles not implemented yet") * - * def pileup(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * def count(self, # <<<<<<<<<<<<<< + * contig=None, + * start=None, */ /* function exit code */ - __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20pileup(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_kwargs) { - int __pyx_v_rtid; - int __pyx_v_rstart; - int __pyx_v_rend; - int __pyx_v_has_coord; +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_16count(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_read_callback, PyObject *__pyx_v_reference, PyObject *__pyx_v_end) { + struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read = 0; + long __pyx_v_counter; + int __pyx_v_filter_method; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -12488,46 +17545,51 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20pileup(st int __pyx_t_3; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_6; + PyObject *(*__pyx_t_7)(PyObject *); PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; - PyObject *(*__pyx_t_10)(PyObject *); - int __pyx_t_11; - int __pyx_t_12; - int __pyx_t_13; - __Pyx_RefNannySetupContext("pileup", 0); - __Pyx_TraceCall("pileup", __pyx_f[0], 955, 0, __PYX_ERR(0, 955, __pyx_L1_error)); + __Pyx_RefNannySetupContext("count", 0); + __Pyx_TraceCall("count", __pyx_f[0], 1348, 0, __PYX_ERR(0, 1348, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":1418 + * ''' + * cdef AlignedSegment read + * cdef long counter = 0 # <<<<<<<<<<<<<< + * + * if not self.is_open: + */ + __pyx_v_counter = 0; - /* "pysam/libcalignmentfile.pyx":1023 - * cdef int rtid, rstart, rend, has_coord + /* "pysam/libcalignmentfile.pyx":1420 + * cdef long counter = 0 * * if not self.is_open: # <<<<<<<<<<<<<< * raise ValueError("I/O operation on closed file") * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1023, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1420, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1023, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1420, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = ((!__pyx_t_2) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":1024 + /* "pysam/libcalignmentfile.pyx":1421 * * if not self.is_open: * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< * - * has_coord, rtid, rstart, rend = self.parse_region( + * cdef int filter_method = 0 */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1024, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1421, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1024, __pyx_L1_error) + __PYX_ERR(0, 1421, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1023 - * cdef int rtid, rstart, rend, has_coord + /* "pysam/libcalignmentfile.pyx":1420 + * cdef long counter = 0 * * if not self.is_open: # <<<<<<<<<<<<<< * raise ValueError("I/O operation on closed file") @@ -12535,381 +17597,375 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20pileup(st */ } - /* "pysam/libcalignmentfile.pyx":1026 + /* "pysam/libcalignmentfile.pyx":1423 * raise ValueError("I/O operation on closed file") * - * has_coord, rtid, rstart, rend = self.parse_region( # <<<<<<<<<<<<<< - * reference, start, end, region) - * + * cdef int filter_method = 0 # <<<<<<<<<<<<<< + * if read_callback == "all": + * filter_method = 1 */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_parse_region); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1026, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_v_filter_method = 0; - /* "pysam/libcalignmentfile.pyx":1027 + /* "pysam/libcalignmentfile.pyx":1424 * - * has_coord, rtid, rstart, rend = self.parse_region( - * reference, start, end, region) # <<<<<<<<<<<<<< + * cdef int filter_method = 0 + * if read_callback == "all": # <<<<<<<<<<<<<< + * filter_method = 1 + * elif read_callback == "nofilter": + */ + __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1424, __pyx_L1_error) + if (__pyx_t_3) { + + /* "pysam/libcalignmentfile.pyx":1425 + * cdef int filter_method = 0 + * if read_callback == "all": + * filter_method = 1 # <<<<<<<<<<<<<< + * elif read_callback == "nofilter": + * filter_method = 2 + */ + __pyx_v_filter_method = 1; + + /* "pysam/libcalignmentfile.pyx":1424 * - * if self.is_bam or self.is_cram: + * cdef int filter_method = 0 + * if read_callback == "all": # <<<<<<<<<<<<<< + * filter_method = 1 + * elif read_callback == "nofilter": */ - __pyx_t_5 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[5] = {__pyx_t_5, __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 4+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1026, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[5] = {__pyx_t_5, __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 4+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1026, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_7 = PyTuple_New(4+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1026, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_INCREF(__pyx_v_reference); - __Pyx_GIVEREF(__pyx_v_reference); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_reference); - __Pyx_INCREF(__pyx_v_start); - __Pyx_GIVEREF(__pyx_v_start); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_start); - __Pyx_INCREF(__pyx_v_end); - __Pyx_GIVEREF(__pyx_v_end); - PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_v_end); - __Pyx_INCREF(__pyx_v_region); - __Pyx_GIVEREF(__pyx_v_region); - PyTuple_SET_ITEM(__pyx_t_7, 3+__pyx_t_6, __pyx_v_region); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1026, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 4)) { - if (size > 4) __Pyx_RaiseTooManyValuesError(4); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 1026, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 3); - } else { - __pyx_t_4 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - __pyx_t_5 = PyList_GET_ITEM(sequence, 2); - __pyx_t_8 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); - #else - { - Py_ssize_t i; - PyObject** temps[4] = {&__pyx_t_4,&__pyx_t_7,&__pyx_t_5,&__pyx_t_8}; - for (i=0; i < 4; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1026, __pyx_L1_error) - __Pyx_GOTREF(item); - *(temps[i]) = item; - } - } - #endif - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - PyObject** temps[4] = {&__pyx_t_4,&__pyx_t_7,&__pyx_t_5,&__pyx_t_8}; - __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1026, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; - for (index=0; index < 4; index++) { - PyObject* item = __pyx_t_10(__pyx_t_9); if (unlikely(!item)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 4) < 0) __PYX_ERR(0, 1026, __pyx_L1_error) - __pyx_t_10 = NULL; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L5_unpacking_done; - __pyx_L4_unpacking_failed:; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_10 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1026, __pyx_L1_error) - __pyx_L5_unpacking_done:; + goto __pyx_L4; } - /* "pysam/libcalignmentfile.pyx":1026 - * raise ValueError("I/O operation on closed file") + /* "pysam/libcalignmentfile.pyx":1426 + * if read_callback == "all": + * filter_method = 1 + * elif read_callback == "nofilter": # <<<<<<<<<<<<<< + * filter_method = 2 * - * has_coord, rtid, rstart, rend = self.parse_region( # <<<<<<<<<<<<<< - * reference, start, end, region) + */ + __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_nofilter, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1426, __pyx_L1_error) + if (__pyx_t_3) { + + /* "pysam/libcalignmentfile.pyx":1427 + * filter_method = 1 + * elif read_callback == "nofilter": + * filter_method = 2 # <<<<<<<<<<<<<< * + * for read in self.fetch(contig=contig, */ - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1026, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1026, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1026, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1026, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_has_coord = __pyx_t_6; - __pyx_v_rtid = __pyx_t_11; - __pyx_v_rstart = __pyx_t_12; - __pyx_v_rend = __pyx_t_13; + __pyx_v_filter_method = 2; - /* "pysam/libcalignmentfile.pyx":1029 - * reference, start, end, region) + /* "pysam/libcalignmentfile.pyx":1426 + * if read_callback == "all": + * filter_method = 1 + * elif read_callback == "nofilter": # <<<<<<<<<<<<<< + * filter_method = 2 * - * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< - * if not self.has_index(): - * raise ValueError("no index available for pileup") */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1029, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1029, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!__pyx_t_2) { - } else { - __pyx_t_3 = __pyx_t_2; - goto __pyx_L7_bool_binop_done; } - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1029, __pyx_L1_error) + __pyx_L4:; + + /* "pysam/libcalignmentfile.pyx":1429 + * filter_method = 2 + * + * for read in self.fetch(contig=contig, # <<<<<<<<<<<<<< + * start=start, + * stop=stop, + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1429, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1029, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = __pyx_t_2; - __pyx_L7_bool_binop_done:; - if (likely(__pyx_t_3)) { + __pyx_t_4 = __Pyx_PyDict_NewPresized(7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_contig, __pyx_v_contig) < 0) __PYX_ERR(0, 1429, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1430 + * + * for read in self.fetch(contig=contig, + * start=start, # <<<<<<<<<<<<<< + * stop=stop, + * reference=reference, + */ + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_start, __pyx_v_start) < 0) __PYX_ERR(0, 1429, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1431 + * for read in self.fetch(contig=contig, + * start=start, + * stop=stop, # <<<<<<<<<<<<<< + * reference=reference, + * end=end, + */ + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_stop, __pyx_v_stop) < 0) __PYX_ERR(0, 1429, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1432 + * start=start, + * stop=stop, + * reference=reference, # <<<<<<<<<<<<<< + * end=end, + * region=region, + */ + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1429, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1433 + * stop=stop, + * reference=reference, + * end=end, # <<<<<<<<<<<<<< + * region=region, + * until_eof=until_eof): + */ + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1429, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1434 + * reference=reference, + * end=end, + * region=region, # <<<<<<<<<<<<<< + * until_eof=until_eof): + * # apply filter + */ + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_region, __pyx_v_region) < 0) __PYX_ERR(0, 1429, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1435 + * end=end, + * region=region, + * until_eof=until_eof): # <<<<<<<<<<<<<< + * # apply filter + * if filter_method == 1: + */ + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_until_eof, __pyx_v_until_eof) < 0) __PYX_ERR(0, 1429, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1030 - * - * if self.is_bam or self.is_cram: - * if not self.has_index(): # <<<<<<<<<<<<<< - * raise ValueError("no index available for pileup") + /* "pysam/libcalignmentfile.pyx":1429 + * filter_method = 2 * + * for read in self.fetch(contig=contig, # <<<<<<<<<<<<<< + * start=start, + * stop=stop, */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_index); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) { + __pyx_t_4 = __pyx_t_5; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0; + __pyx_t_7 = NULL; + } else { + __pyx_t_6 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1429, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + for (;;) { + if (likely(!__pyx_t_7)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1429, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } else { + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1429, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1429, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif } - } - if (__pyx_t_5) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1030, __pyx_L1_error) + __pyx_t_5 = __pyx_t_7(__pyx_t_4); + if (unlikely(!__pyx_t_5)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1429, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_5); } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1030, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_2 = ((!__pyx_t_3) != 0); - if (unlikely(__pyx_t_2)) { + if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(0, 1429, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_read, ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_5)); + __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":1031 - * if self.is_bam or self.is_cram: - * if not self.has_index(): - * raise ValueError("no index available for pileup") # <<<<<<<<<<<<<< - * - * if has_coord: + /* "pysam/libcalignmentfile.pyx":1437 + * until_eof=until_eof): + * # apply filter + * if filter_method == 1: # <<<<<<<<<<<<<< + * # filter = "all" + * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1031, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1031, __pyx_L1_error) + switch (__pyx_v_filter_method) { + case 1: - /* "pysam/libcalignmentfile.pyx":1030 - * - * if self.is_bam or self.is_cram: - * if not self.has_index(): # <<<<<<<<<<<<<< - * raise ValueError("no index available for pileup") - * + /* "pysam/libcalignmentfile.pyx":1439 + * if filter_method == 1: + * # filter = "all" + * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): # <<<<<<<<<<<<<< + * continue + * elif filter_method == 2: */ - } + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_flag); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyInt_AndObjC(__pyx_t_5, __pyx_int_1796, 0x704, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1439, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":1033 - * raise ValueError("no index available for pileup") - * - * if has_coord: # <<<<<<<<<<<<<< - * return IteratorColumnRegion(self, - * tid=rtid, + /* "pysam/libcalignmentfile.pyx":1440 + * # filter = "all" + * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): + * continue # <<<<<<<<<<<<<< + * elif filter_method == 2: + * # filter = "nofilter" */ - __pyx_t_2 = (__pyx_v_has_coord != 0); - if (__pyx_t_2) { + goto __pyx_L5_continue; - /* "pysam/libcalignmentfile.pyx":1034 - * - * if has_coord: - * return IteratorColumnRegion(self, # <<<<<<<<<<<<<< - * tid=rtid, - * start=rstart, + /* "pysam/libcalignmentfile.pyx":1439 + * if filter_method == 1: + * # filter = "all" + * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): # <<<<<<<<<<<<<< + * continue + * elif filter_method == 2: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1034, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); + } - /* "pysam/libcalignmentfile.pyx":1035 - * if has_coord: - * return IteratorColumnRegion(self, - * tid=rtid, # <<<<<<<<<<<<<< - * start=rstart, - * end=rend, + /* "pysam/libcalignmentfile.pyx":1437 + * until_eof=until_eof): + * # apply filter + * if filter_method == 1: # <<<<<<<<<<<<<< + * # filter = "all" + * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): */ - __pyx_t_5 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1035, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1035, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_tid, __pyx_t_7) < 0) __PYX_ERR(0, 1035, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + break; - /* "pysam/libcalignmentfile.pyx":1036 - * return IteratorColumnRegion(self, - * tid=rtid, - * start=rstart, # <<<<<<<<<<<<<< - * end=rend, - * **kwargs ) + /* "pysam/libcalignmentfile.pyx":1441 + * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): + * continue + * elif filter_method == 2: # <<<<<<<<<<<<<< + * # filter = "nofilter" + * pass */ - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_rstart); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1036, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_start, __pyx_t_7) < 0) __PYX_ERR(0, 1035, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + case 2: + break; + default: - /* "pysam/libcalignmentfile.pyx":1037 - * tid=rtid, - * start=rstart, - * end=rend, # <<<<<<<<<<<<<< - * **kwargs ) + /* "pysam/libcalignmentfile.pyx":1445 + * pass * else: + * if not read_callback(read): # <<<<<<<<<<<<<< + * continue + * counter += 1 */ - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_rend); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1037, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_end, __pyx_t_7) < 0) __PYX_ERR(0, 1035, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_8 = __pyx_t_5; - __pyx_t_5 = 0; + __Pyx_INCREF(__pyx_v_read_callback); + __pyx_t_5 = __pyx_v_read_callback; __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (!__pyx_t_8) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, ((PyObject *)__pyx_v_read)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1445, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, ((PyObject *)__pyx_v_read)}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1445, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, ((PyObject *)__pyx_v_read)}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1445, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1445, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_INCREF(((PyObject *)__pyx_v_read)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_read)); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, ((PyObject *)__pyx_v_read)); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1445, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1445, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = ((!__pyx_t_3) != 0); + if (__pyx_t_2) { - /* "pysam/libcalignmentfile.pyx":1038 - * start=rstart, - * end=rend, - * **kwargs ) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1446 * else: - * return IteratorColumnAllRefs(self, **kwargs ) - */ - if (__Pyx_MergeKeywords(__pyx_t_8, __pyx_v_kwargs) < 0) __PYX_ERR(0, 1038, __pyx_L1_error) - - /* "pysam/libcalignmentfile.pyx":1034 + * if not read_callback(read): + * continue # <<<<<<<<<<<<<< + * counter += 1 * - * if has_coord: - * return IteratorColumnRegion(self, # <<<<<<<<<<<<<< - * tid=rtid, - * start=rstart, */ - __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion), __pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1034, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; + goto __pyx_L5_continue; - /* "pysam/libcalignmentfile.pyx":1033 - * raise ValueError("no index available for pileup") - * - * if has_coord: # <<<<<<<<<<<<<< - * return IteratorColumnRegion(self, - * tid=rtid, + /* "pysam/libcalignmentfile.pyx":1445 + * pass + * else: + * if not read_callback(read): # <<<<<<<<<<<<<< + * continue + * counter += 1 */ + } + break; } - /* "pysam/libcalignmentfile.pyx":1040 - * **kwargs ) - * else: - * return IteratorColumnAllRefs(self, **kwargs ) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1447 + * if not read_callback(read): + * continue + * counter += 1 # <<<<<<<<<<<<<< * - * else: + * return counter */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1040, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_self)); - __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs), __pyx_t_5, __pyx_v_kwargs); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1040, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; - goto __pyx_L0; - } + __pyx_v_counter = (__pyx_v_counter + 1); - /* "pysam/libcalignmentfile.pyx":1029 - * reference, start, end, region) + /* "pysam/libcalignmentfile.pyx":1429 + * filter_method = 2 * - * if self.is_bam or self.is_cram: # <<<<<<<<<<<<<< - * if not self.has_index(): - * raise ValueError("no index available for pileup") + * for read in self.fetch(contig=contig, # <<<<<<<<<<<<<< + * start=start, + * stop=stop, */ + __pyx_L5_continue:; } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":1043 + /* "pysam/libcalignmentfile.pyx":1449 + * counter += 1 * - * else: - * raise NotImplementedError( # <<<<<<<<<<<<<< - * "pileup of samfiles not implemented yet") + * return counter # <<<<<<<<<<<<<< * + * @cython.boundscheck(False) # we do manual bounds checking */ - /*else*/ { - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1043, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 1043, __pyx_L1_error) - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_counter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":955 - * return mate + /* "pysam/libcalignmentfile.pyx":1348 + * "pileup of samfiles not implemented yet") * - * def pileup(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * def count(self, # <<<<<<<<<<<<<< + * contig=None, + * start=None, */ /* function exit code */ @@ -12917,92 +17973,99 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20pileup(st __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_read); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1046 - * "pileup of samfiles not implemented yet") +/* "pysam/libcalignmentfile.pyx":1452 * - * def count(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * @cython.boundscheck(False) # we do manual bounds checking + * def count_coverage(self, # <<<<<<<<<<<<<< + * contig, + * start=None, */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23count(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_22count[] = "AlignmentFile.count(self, reference=None, start=None, end=None, region=None, until_eof=False, read_callback='nofilter')\ncount the number of reads in :term:`region`\n\n The region is specified by :term:`reference`, `start` and\n `end`. Alternatively, a :term:`samtools` :term:`region` string\n can be supplied.\n\n A :term:`SAM` file does not allow random access and if\n `region` or `reference` are given, an exception is raised.\n\n Parameters\n ----------\n \n reference : string\n reference_name of the genomic region (chromosome)\n\n start : int\n start of the genomic region\n\n end : int\n end of the genomic region\n \n region : string\n a region string in samtools format.\n\n until_eof : bool\n count until the end of the file, possibly including \n unmapped reads as well.\n\n read_callback: string or function\n\n select a call-back to ignore reads when counting. It can\n be either a string with the following values:\n\n ``all``\n skip reads in which any of the following\n flags are set: BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL,\n BAM_FDUP\n\n ``nofilter``\n uses every single read\n\n Alternatively, `read_callback` can be a function\n ``check_read(read)`` that should return True only for\n those reads that shall be included in the counting.\n\n Raises\n ------\n\n ValueError\n if the genomic coordinates are out of range or invalid.\n\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23count(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_reference = 0; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19count_coverage(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage[] = "AlignmentFile.count_coverage(self, contig, start=None, stop=None, region=None, quality_threshold=15, read_callback='all', reference=None, end=None)\ncount the coverage of genomic positions by reads in :term:`region`.\n\n The region is specified by :term:`contig`, `start` and `stop`.\n :term:`reference` and `end` are also accepted for backward\n compatiblity as synonyms for :term:`contig` and `stop`,\n respectively. Alternatively, a :term:`samtools` :term:`region`\n string can be supplied. The coverage is computed per-base [ACGT].\n\n Parameters\n ----------\n\n contig : string\n reference_name of the genomic region (chromosome)\n\n start : int\n start of the genomic region (0-based inclusive). If not\n given, count from the start of the chromosome.\n\n stop : int\n end of the genomic region (0-based exclusive). If not given,\n count to the end of the chromosome.\n\n region : int\n a region string.\n\n quality_threshold : int\n quality_threshold is the minimum quality score (in phred) a\n base has to reach to be counted.\n\n read_callback: string or function\n\n select a call-back to ignore reads when counting. It can\n be either a string with the following values:\n\n ``all``\n skip reads in which any of the following\n flags are set: BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL,\n BAM_FDUP\n\n ``nofilter``\n uses every single read\n\n Alternatively, `read_callback` can be a function\n ``check_read(read)`` that should return True only for\n those reads that shall be included in the counting.\n\n reference : string\n backward compatible synonym for `contig`\n\n end : int\n backward compatible synonym for `stop`\n\n Ra""ises\n ------\n\n ValueError\n if the genomic coordinates are out of range or invalid.\n\n Returns\n -------\n\n four array.arrays of the same length in order A C G T : tuple\n\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19count_coverage(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_contig = 0; PyObject *__pyx_v_start = 0; - PyObject *__pyx_v_end = 0; + PyObject *__pyx_v_stop = 0; PyObject *__pyx_v_region = 0; - PyObject *__pyx_v_until_eof = 0; + PyObject *__pyx_v_quality_threshold = 0; PyObject *__pyx_v_read_callback = 0; + PyObject *__pyx_v_reference = 0; + PyObject *__pyx_v_end = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("count (wrapper)", 0); + __Pyx_RefNannySetupContext("count_coverage (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,&__pyx_n_s_until_eof,&__pyx_n_s_read_callback,0}; - PyObject* values[6] = {0,0,0,0,0,0}; - - /* "pysam/libcalignmentfile.pyx":1047 - * - * def count(self, - * reference=None, # <<<<<<<<<<<<<< - * start=None, - * end=None, - */ - values[0] = ((PyObject *)Py_None); + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_quality_threshold,&__pyx_n_s_read_callback,&__pyx_n_s_reference,&__pyx_n_s_end,0}; + PyObject* values[8] = {0,0,0,0,0,0,0,0}; - /* "pysam/libcalignmentfile.pyx":1048 - * def count(self, - * reference=None, - * start=None, # <<<<<<<<<<<<<< - * end=None, - * region=None, + /* "pysam/libcalignmentfile.pyx":1454 + * def count_coverage(self, + * contig, + * start=None, # <<<<<<<<<<<<<< + * stop=None, + * region=None, */ values[1] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":1049 - * reference=None, - * start=None, - * end=None, # <<<<<<<<<<<<<< - * region=None, - * until_eof=False, + /* "pysam/libcalignmentfile.pyx":1455 + * contig, + * start=None, + * stop=None, # <<<<<<<<<<<<<< + * region=None, + * quality_threshold=15, */ values[2] = ((PyObject *)Py_None); - /* "pysam/libcalignmentfile.pyx":1050 - * start=None, - * end=None, - * region=None, # <<<<<<<<<<<<<< - * until_eof=False, - * read_callback="nofilter"): + /* "pysam/libcalignmentfile.pyx":1456 + * start=None, + * stop=None, + * region=None, # <<<<<<<<<<<<<< + * quality_threshold=15, + * read_callback='all', */ values[3] = ((PyObject *)Py_None); + values[4] = ((PyObject *)__pyx_int_15); + values[5] = ((PyObject *)__pyx_n_s_all); - /* "pysam/libcalignmentfile.pyx":1051 - * end=None, - * region=None, - * until_eof=False, # <<<<<<<<<<<<<< - * read_callback="nofilter"): - * '''count the number of reads in :term:`region` + /* "pysam/libcalignmentfile.pyx":1459 + * quality_threshold=15, + * read_callback='all', + * reference=None, # <<<<<<<<<<<<<< + * end=None): + * """count the coverage of genomic positions by reads in :term:`region`. */ - values[4] = ((PyObject *)Py_False); - values[5] = ((PyObject *)__pyx_n_s_nofilter); + values[6] = ((PyObject *)Py_None); + + /* "pysam/libcalignmentfile.pyx":1460 + * read_callback='all', + * reference=None, + * end=None): # <<<<<<<<<<<<<< + * """count the coverage of genomic positions by reads in :term:`region`. + * + */ + values[7] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); @@ -13021,10 +18084,8 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23count(PyO kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); - if (value) { values[0] = value; kw_args--; } - } + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_contig)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (kw_args > 0) { @@ -13034,7 +18095,7 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23count(PyO CYTHON_FALLTHROUGH; case 2: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop); if (value) { values[2] = value; kw_args--; } } CYTHON_FALLTHROUGH; @@ -13046,7 +18107,7 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23count(PyO CYTHON_FALLTHROUGH; case 4: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_until_eof); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quality_threshold); if (value) { values[4] = value; kw_args--; } } CYTHON_FALLTHROUGH; @@ -13055,12 +18116,28 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23count(PyO PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_read_callback); if (value) { values[5] = value; kw_args--; } } + CYTHON_FALLTHROUGH; + case 6: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); + if (value) { values[6] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 7: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); + if (value) { values[7] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count") < 0)) __PYX_ERR(0, 1046, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count_coverage") < 0)) __PYX_ERR(0, 1452, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); @@ -13072,34 +18149,35 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23count(PyO case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; + break; default: goto __pyx_L5_argtuple_error; } } - __pyx_v_reference = values[0]; + __pyx_v_contig = values[0]; __pyx_v_start = values[1]; - __pyx_v_end = values[2]; + __pyx_v_stop = values[2]; __pyx_v_region = values[3]; - __pyx_v_until_eof = values[4]; + __pyx_v_quality_threshold = values[4]; __pyx_v_read_callback = values[5]; + __pyx_v_reference = values[6]; + __pyx_v_end = values[7]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("count", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1046, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("count_coverage", 0, 1, 8, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1452, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22count(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_until_eof, __pyx_v_read_callback); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_quality_threshold, __pyx_v_read_callback, __pyx_v_reference, __pyx_v_end); - /* "pysam/libcalignmentfile.pyx":1046 - * "pileup of samfiles not implemented yet") + /* "pysam/libcalignmentfile.pyx":1452 * - * def count(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * @cython.boundscheck(False) # we do manual bounds checking + * def count_coverage(self, # <<<<<<<<<<<<<< + * contig, + * start=None, */ /* function exit code */ @@ -13107,91 +18185,323 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23count(PyO return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22count(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_read_callback) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_quality_threshold, PyObject *__pyx_v_read_callback, PyObject *__pyx_v_reference, PyObject *__pyx_v_end) { + uint32_t __pyx_v_contig_length; + int __pyx_v__start; + int __pyx_v__stop; + int __pyx_v_length; + arrayobject *__pyx_v_int_array_template = 0; + arrayobject *__pyx_v_count_a = 0; + arrayobject *__pyx_v_count_c = 0; + arrayobject *__pyx_v_count_g = 0; + arrayobject *__pyx_v_count_t = 0; struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read = 0; - long __pyx_v_counter; + PyObject *__pyx_v_seq = 0; + arrayobject *__pyx_v_quality = 0; + int __pyx_v_qpos; + int __pyx_v_refpos; + CYTHON_UNUSED int __pyx_v_c; int __pyx_v_filter_method; + int __pyx_v__threshold; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - Py_ssize_t __pyx_t_6; - PyObject *(*__pyx_t_7)(PyObject *); - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - __Pyx_RefNannySetupContext("count", 0); - __Pyx_TraceCall("count", __pyx_f[0], 1046, 0, __PYX_ERR(0, 1046, __pyx_L1_error)); + uint32_t __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + Py_ssize_t __pyx_t_9; + PyObject *(*__pyx_t_10)(PyObject *); + PyObject *__pyx_t_11 = NULL; + int __pyx_t_12; + Py_ssize_t __pyx_t_13; + PyObject *(*__pyx_t_14)(PyObject *); + PyObject *__pyx_t_15 = NULL; + PyObject *(*__pyx_t_16)(PyObject *); + int __pyx_t_17; + __Pyx_RefNannySetupContext("count_coverage", 0); + __Pyx_TraceCall("count_coverage", __pyx_f[0], 1452, 0, __PYX_ERR(0, 1452, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":1526 + * """ + * + * cdef uint32_t contig_length = self.get_reference_length(contig) # <<<<<<<<<<<<<< + * cdef int _start = start if start is not None else 0 + * cdef int _stop = stop if stop is not None else contig_length + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_length); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1526, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_contig); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1526, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_contig}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1526, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_contig}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1526, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1526, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_contig); + __Pyx_GIVEREF(__pyx_v_contig); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_contig); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1526, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_5 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_5 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1526, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_contig_length = __pyx_t_5; + + /* "pysam/libcalignmentfile.pyx":1527 + * + * cdef uint32_t contig_length = self.get_reference_length(contig) + * cdef int _start = start if start is not None else 0 # <<<<<<<<<<<<<< + * cdef int _stop = stop if stop is not None else contig_length + * _stop = _stop if _stop < contig_length else contig_length + */ + __pyx_t_7 = (__pyx_v_start != Py_None); + if ((__pyx_t_7 != 0)) { + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_start); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1527, __pyx_L1_error) + __pyx_t_6 = __pyx_t_8; + } else { + __pyx_t_6 = 0; + } + __pyx_v__start = __pyx_t_6; + + /* "pysam/libcalignmentfile.pyx":1528 + * cdef uint32_t contig_length = self.get_reference_length(contig) + * cdef int _start = start if start is not None else 0 + * cdef int _stop = stop if stop is not None else contig_length # <<<<<<<<<<<<<< + * _stop = _stop if _stop < contig_length else contig_length + * + */ + __pyx_t_7 = (__pyx_v_stop != Py_None); + if ((__pyx_t_7 != 0)) { + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_stop); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1528, __pyx_L1_error) + __pyx_t_6 = __pyx_t_8; + } else { + __pyx_t_6 = __pyx_v_contig_length; + } + __pyx_v__stop = __pyx_t_6; + + /* "pysam/libcalignmentfile.pyx":1529 + * cdef int _start = start if start is not None else 0 + * cdef int _stop = stop if stop is not None else contig_length + * _stop = _stop if _stop < contig_length else contig_length # <<<<<<<<<<<<<< + * + * if _stop == _start: + */ + if (((__pyx_v__stop < __pyx_v_contig_length) != 0)) { + __pyx_t_5 = __pyx_v__stop; + } else { + __pyx_t_5 = __pyx_v_contig_length; + } + __pyx_v__stop = __pyx_t_5; + + /* "pysam/libcalignmentfile.pyx":1531 + * _stop = _stop if _stop < contig_length else contig_length + * + * if _stop == _start: # <<<<<<<<<<<<<< + * raise ValueError("interval of size 0") + * if _stop < _start: + */ + __pyx_t_7 = ((__pyx_v__stop == __pyx_v__start) != 0); + if (unlikely(__pyx_t_7)) { + + /* "pysam/libcalignmentfile.pyx":1532 + * + * if _stop == _start: + * raise ValueError("interval of size 0") # <<<<<<<<<<<<<< + * if _stop < _start: + * raise ValueError("interval of size less than 0") + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 1532, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1531 + * _stop = _stop if _stop < contig_length else contig_length + * + * if _stop == _start: # <<<<<<<<<<<<<< + * raise ValueError("interval of size 0") + * if _stop < _start: + */ + } + + /* "pysam/libcalignmentfile.pyx":1533 + * if _stop == _start: + * raise ValueError("interval of size 0") + * if _stop < _start: # <<<<<<<<<<<<<< + * raise ValueError("interval of size less than 0") + * + */ + __pyx_t_7 = ((__pyx_v__stop < __pyx_v__start) != 0); + if (unlikely(__pyx_t_7)) { + + /* "pysam/libcalignmentfile.pyx":1534 + * raise ValueError("interval of size 0") + * if _stop < _start: + * raise ValueError("interval of size less than 0") # <<<<<<<<<<<<<< + * + * cdef int length = _stop - _start + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1534, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 1534, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1533 + * if _stop == _start: + * raise ValueError("interval of size 0") + * if _stop < _start: # <<<<<<<<<<<<<< + * raise ValueError("interval of size less than 0") + * + */ + } + + /* "pysam/libcalignmentfile.pyx":1536 + * raise ValueError("interval of size less than 0") + * + * cdef int length = _stop - _start # <<<<<<<<<<<<<< + * cdef c_array.array int_array_template = array.array('L', []) + * cdef c_array.array count_a + */ + __pyx_v_length = (__pyx_v__stop - __pyx_v__start); + + /* "pysam/libcalignmentfile.pyx":1537 + * + * cdef int length = _stop - _start + * cdef c_array.array int_array_template = array.array('L', []) # <<<<<<<<<<<<<< + * cdef c_array.array count_a + * cdef c_array.array count_c + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_L); + __Pyx_GIVEREF(__pyx_n_s_L); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_L); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_int_array_template = ((arrayobject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":1542 + * cdef c_array.array count_g + * cdef c_array.array count_t + * count_a = c_array.clone(int_array_template, length, zero=True) # <<<<<<<<<<<<<< + * count_c = c_array.clone(int_array_template, length, zero=True) + * count_g = c_array.clone(int_array_template, length, zero=True) + */ + __pyx_t_1 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1542, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_count_a = ((arrayobject *)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1106 - * ''' - * cdef AlignedSegment read - * cdef long counter = 0 # <<<<<<<<<<<<<< - * - * if not self.is_open: + /* "pysam/libcalignmentfile.pyx":1543 + * cdef c_array.array count_t + * count_a = c_array.clone(int_array_template, length, zero=True) + * count_c = c_array.clone(int_array_template, length, zero=True) # <<<<<<<<<<<<<< + * count_g = c_array.clone(int_array_template, length, zero=True) + * count_t = c_array.clone(int_array_template, length, zero=True) */ - __pyx_v_counter = 0; + __pyx_t_1 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1543, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_count_c = ((arrayobject *)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1108 - * cdef long counter = 0 - * - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") + /* "pysam/libcalignmentfile.pyx":1544 + * count_a = c_array.clone(int_array_template, length, zero=True) + * count_c = c_array.clone(int_array_template, length, zero=True) + * count_g = c_array.clone(int_array_template, length, zero=True) # <<<<<<<<<<<<<< + * count_t = c_array.clone(int_array_template, length, zero=True) * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1108, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1544, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1108, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { + __pyx_v_count_g = ((arrayobject *)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1109 - * - * if not self.is_open: - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1545 + * count_c = c_array.clone(int_array_template, length, zero=True) + * count_g = c_array.clone(int_array_template, length, zero=True) + * count_t = c_array.clone(int_array_template, length, zero=True) # <<<<<<<<<<<<<< * - * cdef int filter_method = 0 + * cdef AlignedSegment read */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1109, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1109, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1545, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_count_t = ((arrayobject *)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1108 - * cdef long counter = 0 - * - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") + /* "pysam/libcalignmentfile.pyx":1552 + * cdef int qpos + * cdef int refpos + * cdef int c = 0 # <<<<<<<<<<<<<< + * cdef int filter_method = 0 * */ - } + __pyx_v_c = 0; - /* "pysam/libcalignmentfile.pyx":1111 - * raise ValueError("I/O operation on closed file") - * + /* "pysam/libcalignmentfile.pyx":1553 + * cdef int refpos + * cdef int c = 0 * cdef int filter_method = 0 # <<<<<<<<<<<<<< - * if read_callback == "all": - * filter_method = 1 + * + * */ __pyx_v_filter_method = 0; - /* "pysam/libcalignmentfile.pyx":1112 + /* "pysam/libcalignmentfile.pyx":1556 + * * - * cdef int filter_method = 0 * if read_callback == "all": # <<<<<<<<<<<<<< * filter_method = 1 * elif read_callback == "nofilter": */ - __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1112, __pyx_L1_error) - if (__pyx_t_3) { + __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1556, __pyx_L1_error) + if (__pyx_t_7) { - /* "pysam/libcalignmentfile.pyx":1113 - * cdef int filter_method = 0 + /* "pysam/libcalignmentfile.pyx":1557 + * * if read_callback == "all": * filter_method = 1 # <<<<<<<<<<<<<< * elif read_callback == "nofilter": @@ -13199,36 +18509,36 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22count(str */ __pyx_v_filter_method = 1; - /* "pysam/libcalignmentfile.pyx":1112 + /* "pysam/libcalignmentfile.pyx":1556 + * * - * cdef int filter_method = 0 * if read_callback == "all": # <<<<<<<<<<<<<< * filter_method = 1 * elif read_callback == "nofilter": */ - goto __pyx_L4; + goto __pyx_L5; } - /* "pysam/libcalignmentfile.pyx":1114 + /* "pysam/libcalignmentfile.pyx":1558 * if read_callback == "all": * filter_method = 1 * elif read_callback == "nofilter": # <<<<<<<<<<<<<< * filter_method = 2 * */ - __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_nofilter, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1114, __pyx_L1_error) - if (__pyx_t_3) { + __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_nofilter, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1558, __pyx_L1_error) + if (__pyx_t_7) { - /* "pysam/libcalignmentfile.pyx":1115 + /* "pysam/libcalignmentfile.pyx":1559 * filter_method = 1 * elif read_callback == "nofilter": * filter_method = 2 # <<<<<<<<<<<<<< * - * for read in self.fetch(reference=reference, + * cdef int _threshold = quality_threshold or 0 */ __pyx_v_filter_method = 2; - /* "pysam/libcalignmentfile.pyx":1114 + /* "pysam/libcalignmentfile.pyx":1558 * if read_callback == "all": * filter_method = 1 * elif read_callback == "nofilter": # <<<<<<<<<<<<<< @@ -13236,114 +18546,141 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22count(str * */ } - __pyx_L4:; + __pyx_L5:; - /* "pysam/libcalignmentfile.pyx":1117 + /* "pysam/libcalignmentfile.pyx":1561 * filter_method = 2 * - * for read in self.fetch(reference=reference, # <<<<<<<<<<<<<< + * cdef int _threshold = quality_threshold or 0 # <<<<<<<<<<<<<< + * for read in self.fetch(contig=contig, + * reference=reference, + */ + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_quality_threshold); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1561, __pyx_L1_error) + if (!__pyx_t_7) { + } else { + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_quality_threshold); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1561, __pyx_L1_error) + __pyx_t_6 = __pyx_t_8; + goto __pyx_L6_bool_binop_done; + } + __pyx_t_6 = 0; + __pyx_L6_bool_binop_done:; + __pyx_v__threshold = __pyx_t_6; + + /* "pysam/libcalignmentfile.pyx":1562 + * + * cdef int _threshold = quality_threshold or 0 + * for read in self.fetch(contig=contig, # <<<<<<<<<<<<<< + * reference=reference, * start=start, - * end=end, */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1117, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1562, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1117, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_contig, __pyx_v_contig) < 0) __PYX_ERR(0, 1562, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1118 - * - * for read in self.fetch(reference=reference, + /* "pysam/libcalignmentfile.pyx":1563 + * cdef int _threshold = quality_threshold or 0 + * for read in self.fetch(contig=contig, + * reference=reference, # <<<<<<<<<<<<<< + * start=start, + * stop=stop, + */ + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1562, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1564 + * for read in self.fetch(contig=contig, + * reference=reference, * start=start, # <<<<<<<<<<<<<< + * stop=stop, * end=end, - * region=region, */ - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_start, __pyx_v_start) < 0) __PYX_ERR(0, 1117, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_start, __pyx_v_start) < 0) __PYX_ERR(0, 1562, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1119 - * for read in self.fetch(reference=reference, + /* "pysam/libcalignmentfile.pyx":1565 + * reference=reference, * start=start, - * end=end, # <<<<<<<<<<<<<< - * region=region, - * until_eof=until_eof): + * stop=stop, # <<<<<<<<<<<<<< + * end=end, + * region=region): */ - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1117, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_stop, __pyx_v_stop) < 0) __PYX_ERR(0, 1562, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1120 + /* "pysam/libcalignmentfile.pyx":1566 * start=start, - * end=end, - * region=region, # <<<<<<<<<<<<<< - * until_eof=until_eof): + * stop=stop, + * end=end, # <<<<<<<<<<<<<< + * region=region): * # apply filter */ - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_region, __pyx_v_region) < 0) __PYX_ERR(0, 1117, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1562, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1121 + /* "pysam/libcalignmentfile.pyx":1567 + * stop=stop, * end=end, - * region=region, - * until_eof=until_eof): # <<<<<<<<<<<<<< + * region=region): # <<<<<<<<<<<<<< * # apply filter * if filter_method == 1: */ - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_until_eof, __pyx_v_until_eof) < 0) __PYX_ERR(0, 1117, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_region, __pyx_v_region) < 0) __PYX_ERR(0, 1562, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1117 - * filter_method = 2 + /* "pysam/libcalignmentfile.pyx":1562 * - * for read in self.fetch(reference=reference, # <<<<<<<<<<<<<< + * cdef int _threshold = quality_threshold or 0 + * for read in self.fetch(contig=contig, # <<<<<<<<<<<<<< + * reference=reference, * start=start, - * end=end, */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) { - __pyx_t_4 = __pyx_t_5; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0; - __pyx_t_7 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_2 = __pyx_t_4; __Pyx_INCREF(__pyx_t_2); __pyx_t_9 = 0; + __pyx_t_10 = NULL; } else { - __pyx_t_6 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1117, __pyx_L1_error) + __pyx_t_9 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1562, __pyx_L1_error) } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; for (;;) { - if (likely(!__pyx_t_7)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_4)) break; + if (likely(!__pyx_t_10)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_2)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1117, __pyx_L1_error) + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1562, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); #endif } else { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_2)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1117, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1562, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); #endif } } else { - __pyx_t_5 = __pyx_t_7(__pyx_t_4); - if (unlikely(!__pyx_t_5)) { + __pyx_t_4 = __pyx_t_10(__pyx_t_2); + if (unlikely(!__pyx_t_4)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1117, __pyx_L1_error) + else __PYX_ERR(0, 1562, __pyx_L1_error) } break; } - __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_4); } - if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(0, 1117, __pyx_L1_error) - __Pyx_XDECREF_SET(__pyx_v_read, ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_5)); - __pyx_t_5 = 0; + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(0, 1562, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_read, ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_4)); + __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":1123 - * until_eof=until_eof): + /* "pysam/libcalignmentfile.pyx":1569 + * region=region): * # apply filter * if filter_method == 1: # <<<<<<<<<<<<<< * # filter = "all" @@ -13352,32 +18689,32 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22count(str switch (__pyx_v_filter_method) { case 1: - /* "pysam/libcalignmentfile.pyx":1125 + /* "pysam/libcalignmentfile.pyx":1571 * if filter_method == 1: * # filter = "all" * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): # <<<<<<<<<<<<<< * continue * elif filter_method == 2: */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_flag); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1125, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = __Pyx_PyInt_AndObjC(__pyx_t_5, __pyx_int_1796, 0x704, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1125, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_flag); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1571, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyInt_AndObjC(__pyx_t_4, __pyx_int_1796, 0x704, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1571, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1125, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1571, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_3) { + if (__pyx_t_7) { - /* "pysam/libcalignmentfile.pyx":1126 + /* "pysam/libcalignmentfile.pyx":1572 * # filter = "all" * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): * continue # <<<<<<<<<<<<<< * elif filter_method == 2: * # filter = "nofilter" */ - goto __pyx_L5_continue; + goto __pyx_L8_continue; - /* "pysam/libcalignmentfile.pyx":1125 + /* "pysam/libcalignmentfile.pyx":1571 * if filter_method == 1: * # filter = "all" * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): # <<<<<<<<<<<<<< @@ -13386,8 +18723,8 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22count(str */ } - /* "pysam/libcalignmentfile.pyx":1123 - * until_eof=until_eof): + /* "pysam/libcalignmentfile.pyx":1569 + * region=region): * # apply filter * if filter_method == 1: # <<<<<<<<<<<<<< * # filter = "all" @@ -13395,7 +18732,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22count(str */ break; - /* "pysam/libcalignmentfile.pyx":1127 + /* "pysam/libcalignmentfile.pyx":1573 * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): * continue * elif filter_method == 2: # <<<<<<<<<<<<<< @@ -13406,1197 +18743,1022 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22count(str break; default: - /* "pysam/libcalignmentfile.pyx":1131 + /* "pysam/libcalignmentfile.pyx":1577 * pass * else: * if not read_callback(read): # <<<<<<<<<<<<<< * continue - * counter += 1 + * */ __Pyx_INCREF(__pyx_v_read_callback); - __pyx_t_5 = __pyx_v_read_callback; __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); + __pyx_t_4 = __pyx_v_read_callback; __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); + __Pyx_DECREF_SET(__pyx_t_4, function); } } - if (!__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, ((PyObject *)__pyx_v_read)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1131, __pyx_L1_error) + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)__pyx_v_read)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, ((PyObject *)__pyx_v_read)}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1131, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_read)}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1577, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, ((PyObject *)__pyx_v_read)}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1131, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1131, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; - __Pyx_INCREF(((PyObject *)__pyx_v_read)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_read)); - PyTuple_SET_ITEM(__pyx_t_9, 0+1, ((PyObject *)__pyx_v_read)); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1131, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1131, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_2 = ((!__pyx_t_3) != 0); - if (__pyx_t_2) { - - /* "pysam/libcalignmentfile.pyx":1132 - * else: - * if not read_callback(read): - * continue # <<<<<<<<<<<<<< - * counter += 1 - * - */ - goto __pyx_L5_continue; - - /* "pysam/libcalignmentfile.pyx":1131 - * pass - * else: - * if not read_callback(read): # <<<<<<<<<<<<<< - * continue - * counter += 1 - */ - } - break; - } - - /* "pysam/libcalignmentfile.pyx":1133 - * if not read_callback(read): - * continue - * counter += 1 # <<<<<<<<<<<<<< - * - * return counter - */ - __pyx_v_counter = (__pyx_v_counter + 1); - - /* "pysam/libcalignmentfile.pyx":1117 - * filter_method = 2 - * - * for read in self.fetch(reference=reference, # <<<<<<<<<<<<<< - * start=start, - * end=end, - */ - __pyx_L5_continue:; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pysam/libcalignmentfile.pyx":1135 - * counter += 1 - * - * return counter # <<<<<<<<<<<<<< - * - * @cython.boundscheck(False) # we do manual bounds checking - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_counter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1135, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - - /* "pysam/libcalignmentfile.pyx":1046 - * "pileup of samfiles not implemented yet") - * - * def count(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_read); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_read)}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1577, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1577, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(((PyObject *)__pyx_v_read)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_read)); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, ((PyObject *)__pyx_v_read)); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1577, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1577, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = ((!__pyx_t_7) != 0); + if (__pyx_t_12) { -/* "pysam/libcalignmentfile.pyx":1138 + /* "pysam/libcalignmentfile.pyx":1578 + * else: + * if not read_callback(read): + * continue # <<<<<<<<<<<<<< * - * @cython.boundscheck(False) # we do manual bounds checking - * def count_coverage(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * # count */ + goto __pyx_L8_continue; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25count_coverage(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_24count_coverage[] = "AlignmentFile.count_coverage(self, reference=None, start=None, end=None, region=None, quality_threshold=15, read_callback='all')\ncount the coverage of genomic positions by reads in :term:`region`.\n\n The region is specified by :term:`reference`, `start` and\n `end`. Alternatively, a :term:`samtools` :term:`region` string\n can be supplied. The coverage is computed per-base [ACGT].\n\n Parameters\n ----------\n \n reference : string\n reference_name of the genomic region (chromosome)\n\n start : int\n start of the genomic region\n\n end : int\n end of the genomic region\n\n region : int\n a region string.\n\n quality_threshold : int\n quality_threshold is the minimum quality score (in phred) a\n base has to reach to be counted. \n\n read_callback: string or function\n\n select a call-back to ignore reads when counting. It can\n be either a string with the following values:\n\n ``all``\n skip reads in which any of the following\n flags are set: BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL,\n BAM_FDUP\n\n ``nofilter``\n uses every single read\n\n Alternatively, `read_callback` can be a function\n ``check_read(read)`` that should return True only for\n those reads that shall be included in the counting.\n\n Raises\n ------\n\n ValueError\n if the genomic coordinates are out of range or invalid.\n\n Returns\n -------\n\n four array.arrays of the same length in order A C G T : tuple\n\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25count_coverage(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_reference = 0; - PyObject *__pyx_v_start = 0; - PyObject *__pyx_v_end = 0; - PyObject *__pyx_v_region = 0; - PyObject *__pyx_v_quality_threshold = 0; - PyObject *__pyx_v_read_callback = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("count_coverage (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,&__pyx_n_s_quality_threshold,&__pyx_n_s_read_callback,0}; - PyObject* values[6] = {0,0,0,0,0,0}; - - /* "pysam/libcalignmentfile.pyx":1139 - * @cython.boundscheck(False) # we do manual bounds checking - * def count_coverage(self, - * reference=None, # <<<<<<<<<<<<<< - * start=None, - * end=None, + /* "pysam/libcalignmentfile.pyx":1577 + * pass + * else: + * if not read_callback(read): # <<<<<<<<<<<<<< + * continue + * */ - values[0] = ((PyObject *)Py_None); + } + break; + } - /* "pysam/libcalignmentfile.pyx":1140 - * def count_coverage(self, - * reference=None, - * start=None, # <<<<<<<<<<<<<< - * end=None, - * region=None, + /* "pysam/libcalignmentfile.pyx":1581 + * + * # count + * seq = read.seq # <<<<<<<<<<<<<< + * quality = read.query_qualities + * */ - values[1] = ((PyObject *)Py_None); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_seq); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1581, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 1581, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_seq, ((PyObject*)__pyx_t_1)); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1141 - * reference=None, - * start=None, - * end=None, # <<<<<<<<<<<<<< - * region=None, - * quality_threshold=15, + /* "pysam/libcalignmentfile.pyx":1582 + * # count + * seq = read.seq + * quality = read.query_qualities # <<<<<<<<<<<<<< + * + * for qpos, refpos in read.get_aligned_pairs(True): */ - values[2] = ((PyObject *)Py_None); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1582, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 1582, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_quality, ((arrayobject *)__pyx_t_1)); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1142 - * start=None, - * end=None, - * region=None, # <<<<<<<<<<<<<< - * quality_threshold=15, - * read_callback='all'): + /* "pysam/libcalignmentfile.pyx":1584 + * quality = read.query_qualities + * + * for qpos, refpos in read.get_aligned_pairs(True): # <<<<<<<<<<<<<< + * if qpos is not None and refpos is not None and \ + * _start <= refpos < _stop: */ - values[3] = ((PyObject *)Py_None); - values[4] = ((PyObject *)__pyx_int_15); - values[5] = ((PyObject *)__pyx_n_s_all); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); - if (value) { values[0] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start); - if (value) { values[1] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); - if (value) { values[2] = value; kw_args--; } + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__49, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_1 = __pyx_t_4; __Pyx_INCREF(__pyx_t_1); __pyx_t_13 = 0; + __pyx_t_14 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1584, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + for (;;) { + if (likely(!__pyx_t_14)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_13); __Pyx_INCREF(__pyx_t_4); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 1584, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_13); __Pyx_INCREF(__pyx_t_4); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 1584, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region); - if (value) { values[3] = value; kw_args--; } + } else { + __pyx_t_4 = __pyx_t_14(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1584, __pyx_L1_error) + } + break; } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quality_threshold); - if (value) { values[4] = value; kw_args--; } + __Pyx_GOTREF(__pyx_t_4); + } + if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { + PyObject* sequence = __pyx_t_4; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1584, __pyx_L1_error) } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_read_callback); - if (value) { values[5] = value; kw_args--; } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_11 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); } + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(__pyx_t_3); + #else + __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_15 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_16 = Py_TYPE(__pyx_t_15)->tp_iternext; + index = 0; __pyx_t_11 = __pyx_t_16(__pyx_t_15); if (unlikely(!__pyx_t_11)) goto __pyx_L14_unpacking_failed; + __Pyx_GOTREF(__pyx_t_11); + index = 1; __pyx_t_3 = __pyx_t_16(__pyx_t_15); if (unlikely(!__pyx_t_3)) goto __pyx_L14_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_16(__pyx_t_15), 2) < 0) __PYX_ERR(0, 1584, __pyx_L1_error) + __pyx_t_16 = NULL; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + goto __pyx_L15_unpacking_done; + __pyx_L14_unpacking_failed:; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_16 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1584, __pyx_L1_error) + __pyx_L15_unpacking_done:; } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count_coverage") < 0)) __PYX_ERR(0, 1138, __pyx_L3_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1584, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1584, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_qpos = __pyx_t_6; + __pyx_v_refpos = __pyx_t_8; + + /* "pysam/libcalignmentfile.pyx":1585 + * + * for qpos, refpos in read.get_aligned_pairs(True): + * if qpos is not None and refpos is not None and \ # <<<<<<<<<<<<<< + * _start <= refpos < _stop: + * + */ + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_qpos); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = (__pyx_t_4 != Py_None); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_17 = (__pyx_t_7 != 0); + if (__pyx_t_17) { + } else { + __pyx_t_12 = __pyx_t_17; + goto __pyx_L17_bool_binop_done; } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_refpos); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_17 = (__pyx_t_4 != Py_None); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_7 = (__pyx_t_17 != 0); + if (__pyx_t_7) { + } else { + __pyx_t_12 = __pyx_t_7; + goto __pyx_L17_bool_binop_done; } - } - __pyx_v_reference = values[0]; - __pyx_v_start = values[1]; - __pyx_v_end = values[2]; - __pyx_v_region = values[3]; - __pyx_v_quality_threshold = values[4]; - __pyx_v_read_callback = values[5]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("count_coverage", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1138, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24count_coverage(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_quality_threshold, __pyx_v_read_callback); - /* "pysam/libcalignmentfile.pyx":1138 + /* "pysam/libcalignmentfile.pyx":1586 + * for qpos, refpos in read.get_aligned_pairs(True): + * if qpos is not None and refpos is not None and \ + * _start <= refpos < _stop: # <<<<<<<<<<<<<< * - * @cython.boundscheck(False) # we do manual bounds checking - * def count_coverage(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * # only check base quality if _threshold > 0 + */ + __pyx_t_7 = (__pyx_v__start <= __pyx_v_refpos); + if (__pyx_t_7) { + __pyx_t_7 = (__pyx_v_refpos < __pyx_v__stop); + } + __pyx_t_17 = (__pyx_t_7 != 0); + __pyx_t_12 = __pyx_t_17; + __pyx_L17_bool_binop_done:; + + /* "pysam/libcalignmentfile.pyx":1585 + * + * for qpos, refpos in read.get_aligned_pairs(True): + * if qpos is not None and refpos is not None and \ # <<<<<<<<<<<<<< + * _start <= refpos < _stop: + * + */ + if (__pyx_t_12) { + + /* "pysam/libcalignmentfile.pyx":1589 + * + * # only check base quality if _threshold > 0 + * if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold: # <<<<<<<<<<<<<< + * if seq[qpos] == 'A': + * count_a.data.as_ulongs[refpos - _start] += 1 + */ + __pyx_t_17 = (__pyx_v__threshold != 0); + if (!__pyx_t_17) { + goto __pyx_L22_next_or; + } else { + } + __pyx_t_17 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_quality)); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 1589, __pyx_L1_error) + if (!__pyx_t_17) { + goto __pyx_L22_next_or; + } else { + } + __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_quality), __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1589, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v__threshold); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1589, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_11 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_GE); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1589, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 1589, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (!__pyx_t_17) { + } else { + __pyx_t_12 = __pyx_t_17; + goto __pyx_L21_bool_binop_done; + } + __pyx_L22_next_or:; + __pyx_t_17 = ((!(__pyx_v__threshold != 0)) != 0); + __pyx_t_12 = __pyx_t_17; + __pyx_L21_bool_binop_done:; + if (__pyx_t_12) { + + /* "pysam/libcalignmentfile.pyx":1590 + * # only check base quality if _threshold > 0 + * if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold: + * if seq[qpos] == 'A': # <<<<<<<<<<<<<< + * count_a.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'C': */ + __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1590, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_t_11, __pyx_n_s_A, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1590, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (__pyx_t_12) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcalignmentfile.pyx":1591 + * if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold: + * if seq[qpos] == 'A': + * count_a.data.as_ulongs[refpos - _start] += 1 # <<<<<<<<<<<<<< + * if seq[qpos] == 'C': + * count_c.data.as_ulongs[refpos - _start] += 1 + */ + __pyx_t_8 = (__pyx_v_refpos - __pyx_v__start); + (__pyx_v_count_a->data.as_ulongs[__pyx_t_8]) = ((__pyx_v_count_a->data.as_ulongs[__pyx_t_8]) + 1); -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24count_coverage(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_quality_threshold, PyObject *__pyx_v_read_callback) { - int __pyx_v__start; - int __pyx_v__stop; - int __pyx_v_length; - arrayobject *__pyx_v_int_array_template = 0; - arrayobject *__pyx_v_count_a = 0; - arrayobject *__pyx_v_count_c = 0; - arrayobject *__pyx_v_count_g = 0; - arrayobject *__pyx_v_count_t = 0; - struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read = 0; - PyObject *__pyx_v_seq = 0; - arrayobject *__pyx_v_quality = 0; - int __pyx_v_qpos; - int __pyx_v_refpos; - CYTHON_UNUSED int __pyx_v_c; - int __pyx_v_filter_method; - CYTHON_UNUSED int __pyx_v__threshold; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - Py_ssize_t __pyx_t_6; - PyObject *(*__pyx_t_7)(PyObject *); - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - int __pyx_t_10; - Py_ssize_t __pyx_t_11; - PyObject *(*__pyx_t_12)(PyObject *); - PyObject *__pyx_t_13 = NULL; - PyObject *(*__pyx_t_14)(PyObject *); - int __pyx_t_15; - int __pyx_t_16; - __Pyx_RefNannySetupContext("count_coverage", 0); - __Pyx_TraceCall("count_coverage", __pyx_f[0], 1138, 0, __PYX_ERR(0, 1138, __pyx_L1_error)); + /* "pysam/libcalignmentfile.pyx":1590 + * # only check base quality if _threshold > 0 + * if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold: + * if seq[qpos] == 'A': # <<<<<<<<<<<<<< + * count_a.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'C': + */ + } - /* "pysam/libcalignmentfile.pyx":1200 - * """ - * - * cdef int _start = start # <<<<<<<<<<<<<< - * cdef int _stop = end - * cdef int length = _stop - _start + /* "pysam/libcalignmentfile.pyx":1592 + * if seq[qpos] == 'A': + * count_a.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'C': # <<<<<<<<<<<<<< + * count_c.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'G': */ - __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_start); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1200, __pyx_L1_error) - __pyx_v__start = __pyx_t_1; + __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1592, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_t_11, __pyx_n_s_C, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1592, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (__pyx_t_12) { - /* "pysam/libcalignmentfile.pyx":1201 - * - * cdef int _start = start - * cdef int _stop = end # <<<<<<<<<<<<<< - * cdef int length = _stop - _start - * cdef c_array.array int_array_template = array.array('L', []) + /* "pysam/libcalignmentfile.pyx":1593 + * count_a.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'C': + * count_c.data.as_ulongs[refpos - _start] += 1 # <<<<<<<<<<<<<< + * if seq[qpos] == 'G': + * count_g.data.as_ulongs[refpos - _start] += 1 */ - __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_end); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1201, __pyx_L1_error) - __pyx_v__stop = __pyx_t_1; + __pyx_t_8 = (__pyx_v_refpos - __pyx_v__start); + (__pyx_v_count_c->data.as_ulongs[__pyx_t_8]) = ((__pyx_v_count_c->data.as_ulongs[__pyx_t_8]) + 1); - /* "pysam/libcalignmentfile.pyx":1202 - * cdef int _start = start - * cdef int _stop = end - * cdef int length = _stop - _start # <<<<<<<<<<<<<< - * cdef c_array.array int_array_template = array.array('L', []) - * cdef c_array.array count_a + /* "pysam/libcalignmentfile.pyx":1592 + * if seq[qpos] == 'A': + * count_a.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'C': # <<<<<<<<<<<<<< + * count_c.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'G': */ - __pyx_v_length = (__pyx_v__stop - __pyx_v__start); + } - /* "pysam/libcalignmentfile.pyx":1203 - * cdef int _stop = end - * cdef int length = _stop - _start - * cdef c_array.array int_array_template = array.array('L', []) # <<<<<<<<<<<<<< - * cdef c_array.array count_a - * cdef c_array.array count_c + /* "pysam/libcalignmentfile.pyx":1594 + * if seq[qpos] == 'C': + * count_c.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'G': # <<<<<<<<<<<<<< + * count_g.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'T': */ - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1203, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1203, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_n_s_L); - __Pyx_GIVEREF(__pyx_n_s_L); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_L); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1203, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_int_array_template = ((arrayobject *)__pyx_t_2); - __pyx_t_2 = 0; + __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1594, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_t_11, __pyx_n_s_G, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1594, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (__pyx_t_12) { - /* "pysam/libcalignmentfile.pyx":1208 - * cdef c_array.array count_g - * cdef c_array.array count_t - * count_a = c_array.clone(int_array_template, length, zero=True) # <<<<<<<<<<<<<< - * count_c = c_array.clone(int_array_template, length, zero=True) - * count_g = c_array.clone(int_array_template, length, zero=True) + /* "pysam/libcalignmentfile.pyx":1595 + * count_c.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'G': + * count_g.data.as_ulongs[refpos - _start] += 1 # <<<<<<<<<<<<<< + * if seq[qpos] == 'T': + * count_t.data.as_ulongs[refpos - _start] += 1 */ - __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1208, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_count_a = ((arrayobject *)__pyx_t_2); - __pyx_t_2 = 0; + __pyx_t_8 = (__pyx_v_refpos - __pyx_v__start); + (__pyx_v_count_g->data.as_ulongs[__pyx_t_8]) = ((__pyx_v_count_g->data.as_ulongs[__pyx_t_8]) + 1); - /* "pysam/libcalignmentfile.pyx":1209 - * cdef c_array.array count_t - * count_a = c_array.clone(int_array_template, length, zero=True) - * count_c = c_array.clone(int_array_template, length, zero=True) # <<<<<<<<<<<<<< - * count_g = c_array.clone(int_array_template, length, zero=True) - * count_t = c_array.clone(int_array_template, length, zero=True) + /* "pysam/libcalignmentfile.pyx":1594 + * if seq[qpos] == 'C': + * count_c.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'G': # <<<<<<<<<<<<<< + * count_g.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'T': */ - __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1209, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_count_c = ((arrayobject *)__pyx_t_2); - __pyx_t_2 = 0; + } - /* "pysam/libcalignmentfile.pyx":1210 - * count_a = c_array.clone(int_array_template, length, zero=True) - * count_c = c_array.clone(int_array_template, length, zero=True) - * count_g = c_array.clone(int_array_template, length, zero=True) # <<<<<<<<<<<<<< - * count_t = c_array.clone(int_array_template, length, zero=True) + /* "pysam/libcalignmentfile.pyx":1596 + * if seq[qpos] == 'G': + * count_g.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'T': # <<<<<<<<<<<<<< + * count_t.data.as_ulongs[refpos - _start] += 1 * */ - __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1210, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_count_g = ((arrayobject *)__pyx_t_2); - __pyx_t_2 = 0; + __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1596, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_t_11, __pyx_n_s_T, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1596, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (__pyx_t_12) { - /* "pysam/libcalignmentfile.pyx":1211 - * count_c = c_array.clone(int_array_template, length, zero=True) - * count_g = c_array.clone(int_array_template, length, zero=True) - * count_t = c_array.clone(int_array_template, length, zero=True) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1597 + * count_g.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'T': + * count_t.data.as_ulongs[refpos - _start] += 1 # <<<<<<<<<<<<<< * - * cdef AlignedSegment read + * return count_a, count_c, count_g, count_t */ - __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1211, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_count_t = ((arrayobject *)__pyx_t_2); - __pyx_t_2 = 0; + __pyx_t_8 = (__pyx_v_refpos - __pyx_v__start); + (__pyx_v_count_t->data.as_ulongs[__pyx_t_8]) = ((__pyx_v_count_t->data.as_ulongs[__pyx_t_8]) + 1); - /* "pysam/libcalignmentfile.pyx":1218 - * cdef int qpos - * cdef int refpos - * cdef int c = 0 # <<<<<<<<<<<<<< - * cdef int filter_method = 0 - * if read_callback == "all": + /* "pysam/libcalignmentfile.pyx":1596 + * if seq[qpos] == 'G': + * count_g.data.as_ulongs[refpos - _start] += 1 + * if seq[qpos] == 'T': # <<<<<<<<<<<<<< + * count_t.data.as_ulongs[refpos - _start] += 1 + * */ - __pyx_v_c = 0; + } - /* "pysam/libcalignmentfile.pyx":1219 - * cdef int refpos - * cdef int c = 0 - * cdef int filter_method = 0 # <<<<<<<<<<<<<< - * if read_callback == "all": - * filter_method = 1 + /* "pysam/libcalignmentfile.pyx":1589 + * + * # only check base quality if _threshold > 0 + * if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold: # <<<<<<<<<<<<<< + * if seq[qpos] == 'A': + * count_a.data.as_ulongs[refpos - _start] += 1 */ - __pyx_v_filter_method = 0; + } - /* "pysam/libcalignmentfile.pyx":1220 - * cdef int c = 0 - * cdef int filter_method = 0 - * if read_callback == "all": # <<<<<<<<<<<<<< - * filter_method = 1 - * elif read_callback == "nofilter": + /* "pysam/libcalignmentfile.pyx":1585 + * + * for qpos, refpos in read.get_aligned_pairs(True): + * if qpos is not None and refpos is not None and \ # <<<<<<<<<<<<<< + * _start <= refpos < _stop: + * */ - __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1220, __pyx_L1_error) - if (__pyx_t_4) { + } - /* "pysam/libcalignmentfile.pyx":1221 - * cdef int filter_method = 0 - * if read_callback == "all": - * filter_method = 1 # <<<<<<<<<<<<<< - * elif read_callback == "nofilter": - * filter_method = 2 + /* "pysam/libcalignmentfile.pyx":1584 + * quality = read.query_qualities + * + * for qpos, refpos in read.get_aligned_pairs(True): # <<<<<<<<<<<<<< + * if qpos is not None and refpos is not None and \ + * _start <= refpos < _stop: */ - __pyx_v_filter_method = 1; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1220 - * cdef int c = 0 - * cdef int filter_method = 0 - * if read_callback == "all": # <<<<<<<<<<<<<< - * filter_method = 1 - * elif read_callback == "nofilter": + /* "pysam/libcalignmentfile.pyx":1562 + * + * cdef int _threshold = quality_threshold or 0 + * for read in self.fetch(contig=contig, # <<<<<<<<<<<<<< + * reference=reference, + * start=start, */ - goto __pyx_L3; + __pyx_L8_continue:; } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":1222 - * if read_callback == "all": - * filter_method = 1 - * elif read_callback == "nofilter": # <<<<<<<<<<<<<< - * filter_method = 2 + /* "pysam/libcalignmentfile.pyx":1599 + * count_t.data.as_ulongs[refpos - _start] += 1 + * + * return count_a, count_c, count_g, count_t # <<<<<<<<<<<<<< * + * def find_introns_slow(self, read_iterator): */ - __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_nofilter, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1222, __pyx_L1_error) - if (__pyx_t_4) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1599, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_v_count_a)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_count_a)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_count_a)); + __Pyx_INCREF(((PyObject *)__pyx_v_count_c)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_count_c)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_count_c)); + __Pyx_INCREF(((PyObject *)__pyx_v_count_g)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_count_g)); + PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_count_g)); + __Pyx_INCREF(((PyObject *)__pyx_v_count_t)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_count_t)); + PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_count_t)); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1223 - * filter_method = 1 - * elif read_callback == "nofilter": - * filter_method = 2 # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1452 * - * cdef int _threshold = quality_threshold + * @cython.boundscheck(False) # we do manual bounds checking + * def count_coverage(self, # <<<<<<<<<<<<<< + * contig, + * start=None, */ - __pyx_v_filter_method = 2; - /* "pysam/libcalignmentfile.pyx":1222 - * if read_callback == "all": - * filter_method = 1 - * elif read_callback == "nofilter": # <<<<<<<<<<<<<< - * filter_method = 2 + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_15); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_int_array_template); + __Pyx_XDECREF((PyObject *)__pyx_v_count_a); + __Pyx_XDECREF((PyObject *)__pyx_v_count_c); + __Pyx_XDECREF((PyObject *)__pyx_v_count_g); + __Pyx_XDECREF((PyObject *)__pyx_v_count_t); + __Pyx_XDECREF((PyObject *)__pyx_v_read); + __Pyx_XDECREF(__pyx_v_seq); + __Pyx_XDECREF((PyObject *)__pyx_v_quality); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":1601 + * return count_a, count_c, count_g, count_t * + * def find_introns_slow(self, read_iterator): # <<<<<<<<<<<<<< + * """Return a dictionary {(start, stop): count} + * Listing the intronic sites in the reads (identified by 'N' in the cigar strings), */ - } - __pyx_L3:; - /* "pysam/libcalignmentfile.pyx":1225 - * filter_method = 2 - * - * cdef int _threshold = quality_threshold # <<<<<<<<<<<<<< - * for read in self.fetch(reference=reference, - * start=start, - */ - __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_quality_threshold); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1225, __pyx_L1_error) - __pyx_v__threshold = __pyx_t_1; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21find_introns_slow(PyObject *__pyx_v_self, PyObject *__pyx_v_read_iterator); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow[] = "AlignmentFile.find_introns_slow(self, read_iterator)\nReturn a dictionary {(start, stop): count}\n Listing the intronic sites in the reads (identified by 'N' in the cigar strings),\n and their support ( = number of reads ).\n\n read_iterator can be the result of a .fetch(...) call.\n Or it can be a generator filtering such reads. Example\n samfile.find_introns((read for read in samfile.fetch(...) if read.is_reverse)\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21find_introns_slow(PyObject *__pyx_v_self, PyObject *__pyx_v_read_iterator) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("find_introns_slow (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_read_iterator)); - /* "pysam/libcalignmentfile.pyx":1226 - * - * cdef int _threshold = quality_threshold - * for read in self.fetch(reference=reference, # <<<<<<<<<<<<<< - * start=start, - * end=end, - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1226, __pyx_L1_error) + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignmentfile.pyx":1227 - * cdef int _threshold = quality_threshold - * for read in self.fetch(reference=reference, - * start=start, # <<<<<<<<<<<<<< - * end=end, - * region=region): - */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_start, __pyx_v_start) < 0) __PYX_ERR(0, 1226, __pyx_L1_error) +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator) { + PyObject *__pyx_v_collections = NULL; + PyObject *__pyx_v_res = NULL; + PyObject *__pyx_v_r = NULL; + PyObject *__pyx_v_last_read_pos = NULL; + PyObject *__pyx_v_read_loc = NULL; + PyObject *__pyx_v_genome_loc = NULL; + PyObject *__pyx_v_start = NULL; + PyObject *__pyx_v_stop = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + int __pyx_t_6; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + Py_ssize_t __pyx_t_9; + PyObject *(*__pyx_t_10)(PyObject *); + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *(*__pyx_t_13)(PyObject *); + int __pyx_t_14; + __Pyx_RefNannySetupContext("find_introns_slow", 0); + __Pyx_TraceCall("find_introns_slow", __pyx_f[0], 1601, 0, __PYX_ERR(0, 1601, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1228 - * for read in self.fetch(reference=reference, - * start=start, - * end=end, # <<<<<<<<<<<<<< - * region=region): - * # apply filter + /* "pysam/libcalignmentfile.pyx":1610 + * samfile.find_introns((read for read in samfile.fetch(...) if read.is_reverse) + * """ + * import collections # <<<<<<<<<<<<<< + * res = collections.Counter() + * for r in read_iterator: */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1226, __pyx_L1_error) + __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1610, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_collections = __pyx_t_1; + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1229 - * start=start, - * end=end, - * region=region): # <<<<<<<<<<<<<< - * # apply filter - * if filter_method == 1: + /* "pysam/libcalignmentfile.pyx":1611 + * """ + * import collections + * res = collections.Counter() # <<<<<<<<<<<<<< + * for r in read_iterator: + * if 'N' in r.cigarstring: */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_region, __pyx_v_region) < 0) __PYX_ERR(0, 1226, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_collections, __pyx_n_s_Counter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1611, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1611, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1611, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_res = __pyx_t_1; + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1226 - * - * cdef int _threshold = quality_threshold - * for read in self.fetch(reference=reference, # <<<<<<<<<<<<<< - * start=start, - * end=end, + /* "pysam/libcalignmentfile.pyx":1612 + * import collections + * res = collections.Counter() + * for r in read_iterator: # <<<<<<<<<<<<<< + * if 'N' in r.cigarstring: + * last_read_pos = False */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) { - __pyx_t_3 = __pyx_t_5; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; - __pyx_t_7 = NULL; + if (likely(PyList_CheckExact(__pyx_v_read_iterator)) || PyTuple_CheckExact(__pyx_v_read_iterator)) { + __pyx_t_1 = __pyx_v_read_iterator; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; + __pyx_t_5 = NULL; } else { - __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1226, __pyx_L1_error) + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_read_iterator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1612, __pyx_L1_error) } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; for (;;) { - if (likely(!__pyx_t_7)) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break; + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1226, __pyx_L1_error) + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1612, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); #endif } else { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1226, __pyx_L1_error) + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1612, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } - } else { - __pyx_t_5 = __pyx_t_7(__pyx_t_3); - if (unlikely(!__pyx_t_5)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1226, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(0, 1226, __pyx_L1_error) - __Pyx_XDECREF_SET(__pyx_v_read, ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_5)); - __pyx_t_5 = 0; - - /* "pysam/libcalignmentfile.pyx":1231 - * region=region): - * # apply filter - * if filter_method == 1: # <<<<<<<<<<<<<< - * # filter = "all" - * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): - */ - switch (__pyx_v_filter_method) { - case 1: - - /* "pysam/libcalignmentfile.pyx":1233 - * if filter_method == 1: - * # filter = "all" - * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): # <<<<<<<<<<<<<< - * continue - * elif filter_method == 2: - */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_flag); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = __Pyx_PyInt_AndObjC(__pyx_t_5, __pyx_int_1796, 0x704, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1233, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1233, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_4) { - - /* "pysam/libcalignmentfile.pyx":1234 - * # filter = "all" - * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): - * continue # <<<<<<<<<<<<<< - * elif filter_method == 2: - * # filter = "nofilter" - */ - goto __pyx_L4_continue; - - /* "pysam/libcalignmentfile.pyx":1233 - * if filter_method == 1: - * # filter = "all" - * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): # <<<<<<<<<<<<<< - * continue - * elif filter_method == 2: - */ - } - - /* "pysam/libcalignmentfile.pyx":1231 - * region=region): - * # apply filter - * if filter_method == 1: # <<<<<<<<<<<<<< - * # filter = "all" - * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): - */ - break; - - /* "pysam/libcalignmentfile.pyx":1235 - * if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)): - * continue - * elif filter_method == 2: # <<<<<<<<<<<<<< - * # filter = "nofilter" - * pass - */ - case 2: - break; - default: - - /* "pysam/libcalignmentfile.pyx":1239 - * pass - * else: - * if not read_callback(read): # <<<<<<<<<<<<<< - * continue - * - */ - __Pyx_INCREF(__pyx_v_read_callback); - __pyx_t_5 = __pyx_v_read_callback; __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - if (!__pyx_t_8) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, ((PyObject *)__pyx_v_read)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1239, __pyx_L1_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1612, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, ((PyObject *)__pyx_v_read)}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1239, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, ((PyObject *)__pyx_v_read)}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1239, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else #endif - { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; - __Pyx_INCREF(((PyObject *)__pyx_v_read)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_read)); - PyTuple_SET_ITEM(__pyx_t_9, 0+1, ((PyObject *)__pyx_v_read)); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1239, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_10 = ((!__pyx_t_4) != 0); - if (__pyx_t_10) { - - /* "pysam/libcalignmentfile.pyx":1240 - * else: - * if not read_callback(read): - * continue # <<<<<<<<<<<<<< - * - * # count - */ - goto __pyx_L4_continue; - - /* "pysam/libcalignmentfile.pyx":1239 - * pass - * else: - * if not read_callback(read): # <<<<<<<<<<<<<< - * continue - * - */ + } else { + __pyx_t_2 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1612, __pyx_L1_error) + } + break; } - break; + __Pyx_GOTREF(__pyx_t_2); } + __Pyx_XDECREF_SET(__pyx_v_r, __pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":1243 - * - * # count - * seq = read.seq # <<<<<<<<<<<<<< - * quality = read.query_qualities - * for qpos, refpos in read.get_aligned_pairs(True): + /* "pysam/libcalignmentfile.pyx":1613 + * res = collections.Counter() + * for r in read_iterator: + * if 'N' in r.cigarstring: # <<<<<<<<<<<<<< + * last_read_pos = False + * for read_loc, genome_loc in r.get_aligned_pairs(): */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_seq); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1243, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_r, __pyx_n_s_cigarstring); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1613, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (!(likely(PyString_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 1243, __pyx_L1_error) - __Pyx_XDECREF_SET(__pyx_v_seq, ((PyObject*)__pyx_t_2)); - __pyx_t_2 = 0; + __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_N, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1613, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_7 = (__pyx_t_6 != 0); + if (__pyx_t_7) { - /* "pysam/libcalignmentfile.pyx":1244 - * # count - * seq = read.seq - * quality = read.query_qualities # <<<<<<<<<<<<<< - * for qpos, refpos in read.get_aligned_pairs(True): - * if qpos is not None and refpos is not None and \ + /* "pysam/libcalignmentfile.pyx":1614 + * for r in read_iterator: + * if 'N' in r.cigarstring: + * last_read_pos = False # <<<<<<<<<<<<<< + * for read_loc, genome_loc in r.get_aligned_pairs(): + * if read_loc is None and last_read_pos: */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1244, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 1244, __pyx_L1_error) - __Pyx_XDECREF_SET(__pyx_v_quality, ((arrayobject *)__pyx_t_2)); - __pyx_t_2 = 0; + __Pyx_INCREF(Py_False); + __Pyx_XDECREF_SET(__pyx_v_last_read_pos, Py_False); - /* "pysam/libcalignmentfile.pyx":1245 - * seq = read.seq - * quality = read.query_qualities - * for qpos, refpos in read.get_aligned_pairs(True): # <<<<<<<<<<<<<< - * if qpos is not None and refpos is not None and \ - * _start <= refpos < _stop: + /* "pysam/libcalignmentfile.pyx":1615 + * if 'N' in r.cigarstring: + * last_read_pos = False + * for read_loc, genome_loc in r.get_aligned_pairs(): # <<<<<<<<<<<<<< + * if read_loc is None and last_read_pos: + * start = genome_loc */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) { - __pyx_t_2 = __pyx_t_5; __Pyx_INCREF(__pyx_t_2); __pyx_t_11 = 0; - __pyx_t_12 = NULL; - } else { - __pyx_t_11 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_12 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1245, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - for (;;) { - if (likely(!__pyx_t_12)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_11); __Pyx_INCREF(__pyx_t_5); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1245, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } else { - if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_11); __Pyx_INCREF(__pyx_t_5); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1245, __pyx_L1_error) - #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - } - } else { - __pyx_t_5 = __pyx_t_12(__pyx_t_2); - if (unlikely(!__pyx_t_5)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1245, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { - PyObject* sequence = __pyx_t_5; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 1245, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_9 = PyList_GET_ITEM(sequence, 0); - __pyx_t_8 = PyList_GET_ITEM(sequence, 1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_r, __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1615, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); } - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(__pyx_t_8); - #else - __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - #endif - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_13 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_14 = Py_TYPE(__pyx_t_13)->tp_iternext; - index = 0; __pyx_t_9 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_9)) goto __pyx_L10_unpacking_failed; - __Pyx_GOTREF(__pyx_t_9); - index = 1; __pyx_t_8 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_8)) goto __pyx_L10_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_13), 2) < 0) __PYX_ERR(0, 1245, __pyx_L1_error) - __pyx_t_14 = NULL; - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - goto __pyx_L11_unpacking_done; - __pyx_L10_unpacking_failed:; - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_14 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1245, __pyx_L1_error) - __pyx_L11_unpacking_done:; } - __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1245, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_15 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_15 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1245, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_v_qpos = __pyx_t_1; - __pyx_v_refpos = __pyx_t_15; - - /* "pysam/libcalignmentfile.pyx":1246 - * quality = read.query_qualities - * for qpos, refpos in read.get_aligned_pairs(True): - * if qpos is not None and refpos is not None and \ # <<<<<<<<<<<<<< - * _start <= refpos < _stop: - * if quality[qpos] >= quality_threshold: - */ - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_qpos); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = (__pyx_t_5 != Py_None); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_16 = (__pyx_t_4 != 0); - if (__pyx_t_16) { + if (__pyx_t_8) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1615, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } else { - __pyx_t_10 = __pyx_t_16; - goto __pyx_L13_bool_binop_done; + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1615, __pyx_L1_error) } - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_refpos); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_16 = (__pyx_t_5 != Py_None); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_4 = (__pyx_t_16 != 0); - if (__pyx_t_4) { + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_9 = 0; + __pyx_t_10 = NULL; } else { - __pyx_t_10 = __pyx_t_4; - goto __pyx_L13_bool_binop_done; - } - - /* "pysam/libcalignmentfile.pyx":1247 - * for qpos, refpos in read.get_aligned_pairs(True): - * if qpos is not None and refpos is not None and \ - * _start <= refpos < _stop: # <<<<<<<<<<<<<< - * if quality[qpos] >= quality_threshold: - * if seq[qpos] == 'A': - */ - __pyx_t_4 = (__pyx_v__start <= __pyx_v_refpos); - if (__pyx_t_4) { - __pyx_t_4 = (__pyx_v_refpos < __pyx_v__stop); + __pyx_t_9 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1615, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1615, __pyx_L1_error) } - __pyx_t_16 = (__pyx_t_4 != 0); - __pyx_t_10 = __pyx_t_16; - __pyx_L13_bool_binop_done:; - - /* "pysam/libcalignmentfile.pyx":1246 - * quality = read.query_qualities - * for qpos, refpos in read.get_aligned_pairs(True): - * if qpos is not None and refpos is not None and \ # <<<<<<<<<<<<<< - * _start <= refpos < _stop: - * if quality[qpos] >= quality_threshold: - */ - if (__pyx_t_10) { - - /* "pysam/libcalignmentfile.pyx":1248 - * if qpos is not None and refpos is not None and \ - * _start <= refpos < _stop: - * if quality[qpos] >= quality_threshold: # <<<<<<<<<<<<<< - * if seq[qpos] == 'A': - * count_a.data.as_ulongs[refpos - _start] += 1 - */ - __pyx_t_5 = __Pyx_GetItemInt(((PyObject *)__pyx_v_quality), __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1248, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, __pyx_v_quality_threshold, Py_GE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1248, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 1248, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__pyx_t_10) { - - /* "pysam/libcalignmentfile.pyx":1249 - * _start <= refpos < _stop: - * if quality[qpos] >= quality_threshold: - * if seq[qpos] == 'A': # <<<<<<<<<<<<<< - * count_a.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'C': - */ - __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1249, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_t_8, __pyx_n_s_A, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 1249, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__pyx_t_10) { - - /* "pysam/libcalignmentfile.pyx":1250 - * if quality[qpos] >= quality_threshold: - * if seq[qpos] == 'A': - * count_a.data.as_ulongs[refpos - _start] += 1 # <<<<<<<<<<<<<< - * if seq[qpos] == 'C': - * count_c.data.as_ulongs[refpos - _start] += 1 - */ - __pyx_t_15 = (__pyx_v_refpos - __pyx_v__start); - (__pyx_v_count_a->data.as_ulongs[__pyx_t_15]) = ((__pyx_v_count_a->data.as_ulongs[__pyx_t_15]) + 1); - - /* "pysam/libcalignmentfile.pyx":1249 - * _start <= refpos < _stop: - * if quality[qpos] >= quality_threshold: - * if seq[qpos] == 'A': # <<<<<<<<<<<<<< - * count_a.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'C': - */ + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_10)) { + if (likely(PyList_CheckExact(__pyx_t_3))) { + if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_2); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1615, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1615, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_2); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1615, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1615, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif } - - /* "pysam/libcalignmentfile.pyx":1251 - * if seq[qpos] == 'A': - * count_a.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'C': # <<<<<<<<<<<<<< - * count_c.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'G': - */ - __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1251, __pyx_L1_error) + } else { + __pyx_t_2 = __pyx_t_10(__pyx_t_3); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1615, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1615, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_8 = PyList_GET_ITEM(sequence, 0); + __pyx_t_11 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_11); + #else + __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1615, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); - __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_t_8, __pyx_n_s_C, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 1251, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__pyx_t_10) { + __pyx_t_11 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1615, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_12 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1615, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext; + index = 0; __pyx_t_8 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_8)) goto __pyx_L8_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + index = 1; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L8_unpacking_failed; + __Pyx_GOTREF(__pyx_t_11); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) __PYX_ERR(0, 1615, __pyx_L1_error) + __pyx_t_13 = NULL; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L9_unpacking_done; + __pyx_L8_unpacking_failed:; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_13 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1615, __pyx_L1_error) + __pyx_L9_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_read_loc, __pyx_t_8); + __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_genome_loc, __pyx_t_11); + __pyx_t_11 = 0; - /* "pysam/libcalignmentfile.pyx":1252 - * count_a.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'C': - * count_c.data.as_ulongs[refpos - _start] += 1 # <<<<<<<<<<<<<< - * if seq[qpos] == 'G': - * count_g.data.as_ulongs[refpos - _start] += 1 + /* "pysam/libcalignmentfile.pyx":1616 + * last_read_pos = False + * for read_loc, genome_loc in r.get_aligned_pairs(): + * if read_loc is None and last_read_pos: # <<<<<<<<<<<<<< + * start = genome_loc + * elif read_loc and last_read_pos is None: */ - __pyx_t_15 = (__pyx_v_refpos - __pyx_v__start); - (__pyx_v_count_c->data.as_ulongs[__pyx_t_15]) = ((__pyx_v_count_c->data.as_ulongs[__pyx_t_15]) + 1); + __pyx_t_6 = (__pyx_v_read_loc == Py_None); + __pyx_t_14 = (__pyx_t_6 != 0); + if (__pyx_t_14) { + } else { + __pyx_t_7 = __pyx_t_14; + goto __pyx_L11_bool_binop_done; + } + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_last_read_pos); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1616, __pyx_L1_error) + __pyx_t_7 = __pyx_t_14; + __pyx_L11_bool_binop_done:; + if (__pyx_t_7) { - /* "pysam/libcalignmentfile.pyx":1251 - * if seq[qpos] == 'A': - * count_a.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'C': # <<<<<<<<<<<<<< - * count_c.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'G': + /* "pysam/libcalignmentfile.pyx":1617 + * for read_loc, genome_loc in r.get_aligned_pairs(): + * if read_loc is None and last_read_pos: + * start = genome_loc # <<<<<<<<<<<<<< + * elif read_loc and last_read_pos is None: + * stop = genome_loc # we are right exclusive ,so this is correct */ - } + __Pyx_INCREF(__pyx_v_genome_loc); + __Pyx_XDECREF_SET(__pyx_v_start, __pyx_v_genome_loc); - /* "pysam/libcalignmentfile.pyx":1253 - * if seq[qpos] == 'C': - * count_c.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'G': # <<<<<<<<<<<<<< - * count_g.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'T': + /* "pysam/libcalignmentfile.pyx":1616 + * last_read_pos = False + * for read_loc, genome_loc in r.get_aligned_pairs(): + * if read_loc is None and last_read_pos: # <<<<<<<<<<<<<< + * start = genome_loc + * elif read_loc and last_read_pos is None: */ - __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1253, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_t_8, __pyx_n_s_G, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 1253, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__pyx_t_10) { + goto __pyx_L10; + } - /* "pysam/libcalignmentfile.pyx":1254 - * count_c.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'G': - * count_g.data.as_ulongs[refpos - _start] += 1 # <<<<<<<<<<<<<< - * if seq[qpos] == 'T': - * count_t.data.as_ulongs[refpos - _start] += 1 + /* "pysam/libcalignmentfile.pyx":1618 + * if read_loc is None and last_read_pos: + * start = genome_loc + * elif read_loc and last_read_pos is None: # <<<<<<<<<<<<<< + * stop = genome_loc # we are right exclusive ,so this is correct + * res[(start, stop)] += 1 */ - __pyx_t_15 = (__pyx_v_refpos - __pyx_v__start); - (__pyx_v_count_g->data.as_ulongs[__pyx_t_15]) = ((__pyx_v_count_g->data.as_ulongs[__pyx_t_15]) + 1); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_read_loc); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1618, __pyx_L1_error) + if (__pyx_t_14) { + } else { + __pyx_t_7 = __pyx_t_14; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_14 = (__pyx_v_last_read_pos == Py_None); + __pyx_t_6 = (__pyx_t_14 != 0); + __pyx_t_7 = __pyx_t_6; + __pyx_L13_bool_binop_done:; + if (__pyx_t_7) { - /* "pysam/libcalignmentfile.pyx":1253 - * if seq[qpos] == 'C': - * count_c.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'G': # <<<<<<<<<<<<<< - * count_g.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'T': + /* "pysam/libcalignmentfile.pyx":1619 + * start = genome_loc + * elif read_loc and last_read_pos is None: + * stop = genome_loc # we are right exclusive ,so this is correct # <<<<<<<<<<<<<< + * res[(start, stop)] += 1 + * del start */ - } + __Pyx_INCREF(__pyx_v_genome_loc); + __pyx_v_stop = __pyx_v_genome_loc; - /* "pysam/libcalignmentfile.pyx":1255 - * if seq[qpos] == 'G': - * count_g.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'T': # <<<<<<<<<<<<<< - * count_t.data.as_ulongs[refpos - _start] += 1 - * + /* "pysam/libcalignmentfile.pyx":1620 + * elif read_loc and last_read_pos is None: + * stop = genome_loc # we are right exclusive ,so this is correct + * res[(start, stop)] += 1 # <<<<<<<<<<<<<< + * del start + * del stop */ - __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1255, __pyx_L1_error) + if (unlikely(!__pyx_v_start)) { __Pyx_RaiseUnboundLocalError("start"); __PYX_ERR(0, 1620, __pyx_L1_error) } + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1620, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_start); + __Pyx_GIVEREF(__pyx_v_start); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_start); + __Pyx_INCREF(__pyx_v_stop); + __Pyx_GIVEREF(__pyx_v_stop); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_stop); + __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_v_res, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1620, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_11, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1620, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); - __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_t_8, __pyx_n_s_T, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 1255, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(PyObject_SetItem(__pyx_v_res, __pyx_t_2, __pyx_t_8) < 0)) __PYX_ERR(0, 1620, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__pyx_t_10) { + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":1256 - * count_g.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'T': - * count_t.data.as_ulongs[refpos - _start] += 1 # <<<<<<<<<<<<<< - * - * return count_a, count_c, count_g, count_t + /* "pysam/libcalignmentfile.pyx":1621 + * stop = genome_loc # we are right exclusive ,so this is correct + * res[(start, stop)] += 1 + * del start # <<<<<<<<<<<<<< + * del stop + * last_read_pos = read_loc */ - __pyx_t_15 = (__pyx_v_refpos - __pyx_v__start); - (__pyx_v_count_t->data.as_ulongs[__pyx_t_15]) = ((__pyx_v_count_t->data.as_ulongs[__pyx_t_15]) + 1); + if (unlikely(!__pyx_v_start)) { __Pyx_RaiseUnboundLocalError("start"); __PYX_ERR(0, 1621, __pyx_L1_error) } + __Pyx_DECREF(__pyx_v_start); + __pyx_v_start = NULL; - /* "pysam/libcalignmentfile.pyx":1255 - * if seq[qpos] == 'G': - * count_g.data.as_ulongs[refpos - _start] += 1 - * if seq[qpos] == 'T': # <<<<<<<<<<<<<< - * count_t.data.as_ulongs[refpos - _start] += 1 - * + /* "pysam/libcalignmentfile.pyx":1622 + * res[(start, stop)] += 1 + * del start + * del stop # <<<<<<<<<<<<<< + * last_read_pos = read_loc + * return res */ - } + __Pyx_DECREF(__pyx_v_stop); + __pyx_v_stop = NULL; - /* "pysam/libcalignmentfile.pyx":1248 - * if qpos is not None and refpos is not None and \ - * _start <= refpos < _stop: - * if quality[qpos] >= quality_threshold: # <<<<<<<<<<<<<< - * if seq[qpos] == 'A': - * count_a.data.as_ulongs[refpos - _start] += 1 + /* "pysam/libcalignmentfile.pyx":1618 + * if read_loc is None and last_read_pos: + * start = genome_loc + * elif read_loc and last_read_pos is None: # <<<<<<<<<<<<<< + * stop = genome_loc # we are right exclusive ,so this is correct + * res[(start, stop)] += 1 */ } + __pyx_L10:; - /* "pysam/libcalignmentfile.pyx":1246 - * quality = read.query_qualities - * for qpos, refpos in read.get_aligned_pairs(True): - * if qpos is not None and refpos is not None and \ # <<<<<<<<<<<<<< - * _start <= refpos < _stop: - * if quality[qpos] >= quality_threshold: + /* "pysam/libcalignmentfile.pyx":1623 + * del start + * del stop + * last_read_pos = read_loc # <<<<<<<<<<<<<< + * return res + * + */ + __Pyx_INCREF(__pyx_v_read_loc); + __Pyx_DECREF_SET(__pyx_v_last_read_pos, __pyx_v_read_loc); + + /* "pysam/libcalignmentfile.pyx":1615 + * if 'N' in r.cigarstring: + * last_read_pos = False + * for read_loc, genome_loc in r.get_aligned_pairs(): # <<<<<<<<<<<<<< + * if read_loc is None and last_read_pos: + * start = genome_loc */ } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignmentfile.pyx":1245 - * seq = read.seq - * quality = read.query_qualities - * for qpos, refpos in read.get_aligned_pairs(True): # <<<<<<<<<<<<<< - * if qpos is not None and refpos is not None and \ - * _start <= refpos < _stop: + /* "pysam/libcalignmentfile.pyx":1613 + * res = collections.Counter() + * for r in read_iterator: + * if 'N' in r.cigarstring: # <<<<<<<<<<<<<< + * last_read_pos = False + * for read_loc, genome_loc in r.get_aligned_pairs(): */ } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":1226 - * - * cdef int _threshold = quality_threshold - * for read in self.fetch(reference=reference, # <<<<<<<<<<<<<< - * start=start, - * end=end, + /* "pysam/libcalignmentfile.pyx":1612 + * import collections + * res = collections.Counter() + * for r in read_iterator: # <<<<<<<<<<<<<< + * if 'N' in r.cigarstring: + * last_read_pos = False */ - __pyx_L4_continue:; } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1258 - * count_t.data.as_ulongs[refpos - _start] += 1 - * - * return count_a, count_c, count_g, count_t # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1624 + * del stop + * last_read_pos = read_loc + * return res # <<<<<<<<<<<<<< * * def find_introns(self, read_iterator): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1258, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_v_count_a)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_count_a)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_count_a)); - __Pyx_INCREF(((PyObject *)__pyx_v_count_c)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_count_c)); - PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_count_c)); - __Pyx_INCREF(((PyObject *)__pyx_v_count_g)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_count_g)); - PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_count_g)); - __Pyx_INCREF(((PyObject *)__pyx_v_count_t)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_count_t)); - PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_count_t)); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_v_res); + __pyx_r = __pyx_v_res; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1138 + /* "pysam/libcalignmentfile.pyx":1601 + * return count_a, count_c, count_g, count_t * - * @cython.boundscheck(False) # we do manual bounds checking - * def count_coverage(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * def find_introns_slow(self, read_iterator): # <<<<<<<<<<<<<< + * """Return a dictionary {(start, stop): count} + * Listing the intronic sites in the reads (identified by 'N' in the cigar strings), */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.find_introns_slow", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_int_array_template); - __Pyx_XDECREF((PyObject *)__pyx_v_count_a); - __Pyx_XDECREF((PyObject *)__pyx_v_count_c); - __Pyx_XDECREF((PyObject *)__pyx_v_count_g); - __Pyx_XDECREF((PyObject *)__pyx_v_count_t); - __Pyx_XDECREF((PyObject *)__pyx_v_read); - __Pyx_XDECREF(__pyx_v_seq); - __Pyx_XDECREF((PyObject *)__pyx_v_quality); + __Pyx_XDECREF(__pyx_v_collections); + __Pyx_XDECREF(__pyx_v_res); + __Pyx_XDECREF(__pyx_v_r); + __Pyx_XDECREF(__pyx_v_last_read_pos); + __Pyx_XDECREF(__pyx_v_read_loc); + __Pyx_XDECREF(__pyx_v_genome_loc); + __Pyx_XDECREF(__pyx_v_start); + __Pyx_XDECREF(__pyx_v_stop); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1260 - * return count_a, count_c, count_g, count_t +/* "pysam/libcalignmentfile.pyx":1626 + * return res * * def find_introns(self, read_iterator): # <<<<<<<<<<<<<< * """Return a dictionary {(start, stop): count} @@ -14604,28 +19766,29 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24count_cov */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_27find_introns(PyObject *__pyx_v_self, PyObject *__pyx_v_read_iterator); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_26find_introns[] = "AlignmentFile.find_introns(self, read_iterator)\nReturn a dictionary {(start, stop): count}\n Listing the intronic sites in the reads (identified by 'N' in the cigar strings),\n and their support ( = number of reads ).\n\n read_iterator can be the result of a .fetch(...) call.\n Or it can be a generator filtering such reads. Example\n samfile.find_introns((read for read in samfile.fetch(...) if read.is_reverse)\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_27find_introns(PyObject *__pyx_v_self, PyObject *__pyx_v_read_iterator) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23find_introns(PyObject *__pyx_v_self, PyObject *__pyx_v_read_iterator); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns[] = "AlignmentFile.find_introns(self, read_iterator)\nReturn a dictionary {(start, stop): count}\n Listing the intronic sites in the reads (identified by 'N' in the cigar strings),\n and their support ( = number of reads ).\n\n read_iterator can be the result of a .fetch(...) call.\n Or it can be a generator filtering such reads. Example\n samfile.find_introns((read for read in samfile.fetch(...) if read.is_reverse)\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23find_introns(PyObject *__pyx_v_self, PyObject *__pyx_v_read_iterator) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("find_introns (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26find_introns(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_read_iterator)); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_read_iterator)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26find_introns(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator) { + uint32_t __pyx_v_base_position; + uint32_t __pyx_v_junc_start; + uint32_t __pyx_v_nt; + int __pyx_v_op; + struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_r = 0; + int __pyx_v_BAM_CREF_SKIP; PyObject *__pyx_v_collections = NULL; PyObject *__pyx_v_res = NULL; - PyObject *__pyx_v_r = NULL; - PyObject *__pyx_v_last_read_pos = NULL; - PyObject *__pyx_v_read_loc = NULL; - PyObject *__pyx_v_genome_loc = NULL; - PyObject *__pyx_v_start = NULL; - PyObject *__pyx_v_stop = NULL; + PyObject *__pyx_v_match_or_deletion = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -14634,38 +19797,48 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26find_intr PyObject *__pyx_t_3 = NULL; Py_ssize_t __pyx_t_4; PyObject *(*__pyx_t_5)(PyObject *); - int __pyx_t_6; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - Py_ssize_t __pyx_t_9; - PyObject *(*__pyx_t_10)(PyObject *); + uint32_t __pyx_t_6; + Py_ssize_t __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyObject *(*__pyx_t_13)(PyObject *); + PyObject *(*__pyx_t_12)(PyObject *); + int __pyx_t_13; int __pyx_t_14; + int __pyx_t_15; __Pyx_RefNannySetupContext("find_introns", 0); - __Pyx_TraceCall("find_introns", __pyx_f[0], 1260, 0, __PYX_ERR(0, 1260, __pyx_L1_error)); + __Pyx_TraceCall("find_introns", __pyx_f[0], 1626, 0, __PYX_ERR(0, 1626, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1269 - * samfile.find_introns((read for read in samfile.fetch(...) if read.is_reverse) - * """ + /* "pysam/libcalignmentfile.pyx":1639 + * int op + * AlignedSegment r + * int BAM_CREF_SKIP = 3 #BAM_CREF_SKIP # <<<<<<<<<<<<<< + * + * import collections + */ + __pyx_v_BAM_CREF_SKIP = 3; + + /* "pysam/libcalignmentfile.pyx":1641 + * int BAM_CREF_SKIP = 3 #BAM_CREF_SKIP + * * import collections # <<<<<<<<<<<<<< * res = collections.Counter() - * for r in read_iterator: + * */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1269, __pyx_L1_error) + __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1641, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_collections = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1270 - * """ + /* "pysam/libcalignmentfile.pyx":1642 + * * import collections * res = collections.Counter() # <<<<<<<<<<<<<< - * for r in read_iterator: - * if 'N' in r.cigarstring: + * + * match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_collections, __pyx_n_s_Counter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1270, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_collections, __pyx_n_s_Counter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1642, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -14678,47 +19851,63 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26find_intr } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1270, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1642, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1270, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1642, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_res = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1271 - * import collections + /* "pysam/libcalignmentfile.pyx":1644 * res = collections.Counter() + * + * match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position # <<<<<<<<<<<<<< + * for r in read_iterator: + * base_position = r.pos + */ + __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1644, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PySet_Add(__pyx_t_1, __pyx_int_0) < 0) __PYX_ERR(0, 1644, __pyx_L1_error) + if (PySet_Add(__pyx_t_1, __pyx_int_2) < 0) __PYX_ERR(0, 1644, __pyx_L1_error) + if (PySet_Add(__pyx_t_1, __pyx_int_7) < 0) __PYX_ERR(0, 1644, __pyx_L1_error) + if (PySet_Add(__pyx_t_1, __pyx_int_8) < 0) __PYX_ERR(0, 1644, __pyx_L1_error) + __pyx_v_match_or_deletion = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":1645 + * + * match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position * for r in read_iterator: # <<<<<<<<<<<<<< - * if 'N' in r.cigarstring: - * last_read_pos = False + * base_position = r.pos + * */ if (likely(PyList_CheckExact(__pyx_v_read_iterator)) || PyTuple_CheckExact(__pyx_v_read_iterator)) { __pyx_t_1 = __pyx_v_read_iterator; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; __pyx_t_5 = NULL; } else { - __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_read_iterator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1271, __pyx_L1_error) + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_read_iterator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1645, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1271, __pyx_L1_error) + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1645, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_5)) { if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1271, __pyx_L1_error) + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1645, __pyx_L1_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1271, __pyx_L1_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1645, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1271, __pyx_L1_error) + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1645, __pyx_L1_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1271, __pyx_L1_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1645, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif } @@ -14728,334 +19917,264 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26find_intr PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1271, __pyx_L1_error) + else __PYX_ERR(0, 1645, __pyx_L1_error) } break; } __Pyx_GOTREF(__pyx_t_2); } - __Pyx_XDECREF_SET(__pyx_v_r, __pyx_t_2); + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(0, 1645, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_r, ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_2)); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":1272 - * res = collections.Counter() + /* "pysam/libcalignmentfile.pyx":1646 + * match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position * for r in read_iterator: - * if 'N' in r.cigarstring: # <<<<<<<<<<<<<< - * last_read_pos = False - * for read_loc, genome_loc in r.get_aligned_pairs(): + * base_position = r.pos # <<<<<<<<<<<<<< + * + * for op, nt in r.cigartuples: */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_r, __pyx_n_s_cigarstring); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1272, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_r), __pyx_n_s_pos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1646, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_N, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1272, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_uint32_t(__pyx_t_2); if (unlikely((__pyx_t_6 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1646, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = (__pyx_t_6 != 0); - if (__pyx_t_7) { - - /* "pysam/libcalignmentfile.pyx":1273 - * for r in read_iterator: - * if 'N' in r.cigarstring: - * last_read_pos = False # <<<<<<<<<<<<<< - * for read_loc, genome_loc in r.get_aligned_pairs(): - * if read_loc is None and last_read_pos: - */ - __Pyx_INCREF(Py_False); - __Pyx_XDECREF_SET(__pyx_v_last_read_pos, Py_False); + __pyx_v_base_position = __pyx_t_6; - /* "pysam/libcalignmentfile.pyx":1274 - * if 'N' in r.cigarstring: - * last_read_pos = False - * for read_loc, genome_loc in r.get_aligned_pairs(): # <<<<<<<<<<<<<< - * if read_loc is None and last_read_pos: - * start = genome_loc + /* "pysam/libcalignmentfile.pyx":1648 + * base_position = r.pos + * + * for op, nt in r.cigartuples: # <<<<<<<<<<<<<< + * if op in match_or_deletion: + * base_position += nt */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_r, __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_r), __pyx_n_s_cigartuples); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1648, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0; __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (__pyx_t_8) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1274, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1274, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_9 = 0; - __pyx_t_10 = NULL; - } else { - __pyx_t_9 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1274, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_10)) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_2); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1274, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_2); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1274, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_10(__pyx_t_3); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1274, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 1274, __pyx_L1_error) - } + } else { + __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1648, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1648, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_8)) { + if (likely(PyList_CheckExact(__pyx_t_3))) { + if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_8 = PyList_GET_ITEM(sequence, 0); - __pyx_t_11 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_11); + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 1648, __pyx_L1_error) #else - __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_11 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1648, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { - Py_ssize_t index = -1; - __pyx_t_12 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1274, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext; - index = 0; __pyx_t_8 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_8)) goto __pyx_L8_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - index = 1; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L8_unpacking_failed; - __Pyx_GOTREF(__pyx_t_11); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) __PYX_ERR(0, 1274, __pyx_L1_error) - __pyx_t_13 = NULL; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - goto __pyx_L9_unpacking_done; - __pyx_L8_unpacking_failed:; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_13 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1274, __pyx_L1_error) - __pyx_L9_unpacking_done:; + if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 1648, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1648, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif } - __Pyx_XDECREF_SET(__pyx_v_read_loc, __pyx_t_8); - __pyx_t_8 = 0; - __Pyx_XDECREF_SET(__pyx_v_genome_loc, __pyx_t_11); - __pyx_t_11 = 0; - - /* "pysam/libcalignmentfile.pyx":1275 - * last_read_pos = False - * for read_loc, genome_loc in r.get_aligned_pairs(): - * if read_loc is None and last_read_pos: # <<<<<<<<<<<<<< - * start = genome_loc - * elif read_loc and last_read_pos is None: - */ - __pyx_t_6 = (__pyx_v_read_loc == Py_None); - __pyx_t_14 = (__pyx_t_6 != 0); - if (__pyx_t_14) { - } else { - __pyx_t_7 = __pyx_t_14; - goto __pyx_L11_bool_binop_done; + } else { + __pyx_t_2 = __pyx_t_8(__pyx_t_3); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1648, __pyx_L1_error) + } + break; } - __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_last_read_pos); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1275, __pyx_L1_error) - __pyx_t_7 = __pyx_t_14; - __pyx_L11_bool_binop_done:; - if (__pyx_t_7) { - - /* "pysam/libcalignmentfile.pyx":1276 - * for read_loc, genome_loc in r.get_aligned_pairs(): - * if read_loc is None and last_read_pos: - * start = genome_loc # <<<<<<<<<<<<<< - * elif read_loc and last_read_pos is None: - * stop = genome_loc # we are right exclusive ,so this is correct - */ - __Pyx_INCREF(__pyx_v_genome_loc); - __Pyx_XDECREF_SET(__pyx_v_start, __pyx_v_genome_loc); - - /* "pysam/libcalignmentfile.pyx":1275 - * last_read_pos = False - * for read_loc, genome_loc in r.get_aligned_pairs(): - * if read_loc is None and last_read_pos: # <<<<<<<<<<<<<< - * start = genome_loc - * elif read_loc and last_read_pos is None: - */ - goto __pyx_L10; + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1648, __pyx_L1_error) } - - /* "pysam/libcalignmentfile.pyx":1277 - * if read_loc is None and last_read_pos: - * start = genome_loc - * elif read_loc and last_read_pos is None: # <<<<<<<<<<<<<< - * stop = genome_loc # we are right exclusive ,so this is correct - * res[(start, stop)] += 1 - */ - __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_read_loc); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1277, __pyx_L1_error) - if (__pyx_t_14) { + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); } else { - __pyx_t_7 = __pyx_t_14; - goto __pyx_L13_bool_binop_done; + __pyx_t_9 = PyList_GET_ITEM(sequence, 0); + __pyx_t_10 = PyList_GET_ITEM(sequence, 1); } - __pyx_t_14 = (__pyx_v_last_read_pos == Py_None); - __pyx_t_6 = (__pyx_t_14 != 0); - __pyx_t_7 = __pyx_t_6; - __pyx_L13_bool_binop_done:; - if (__pyx_t_7) { + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + #else + __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1648, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1648, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_11 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1648, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; + index = 0; __pyx_t_9 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L7_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L7_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) __PYX_ERR(0, 1648, __pyx_L1_error) + __pyx_t_12 = NULL; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L8_unpacking_done; + __pyx_L7_unpacking_failed:; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_12 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1648, __pyx_L1_error) + __pyx_L8_unpacking_done:; + } + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1648, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_6 = __Pyx_PyInt_As_uint32_t(__pyx_t_10); if (unlikely((__pyx_t_6 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1648, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_v_op = __pyx_t_13; + __pyx_v_nt = __pyx_t_6; - /* "pysam/libcalignmentfile.pyx":1278 - * start = genome_loc - * elif read_loc and last_read_pos is None: - * stop = genome_loc # we are right exclusive ,so this is correct # <<<<<<<<<<<<<< - * res[(start, stop)] += 1 - * del start + /* "pysam/libcalignmentfile.pyx":1649 + * + * for op, nt in r.cigartuples: + * if op in match_or_deletion: # <<<<<<<<<<<<<< + * base_position += nt + * elif op == BAM_CREF_SKIP: */ - __Pyx_INCREF(__pyx_v_genome_loc); - __pyx_v_stop = __pyx_v_genome_loc; + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_op); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1649, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = (__Pyx_PySet_ContainsTF(__pyx_t_2, __pyx_v_match_or_deletion, Py_EQ)); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1649, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_15 = (__pyx_t_14 != 0); + if (__pyx_t_15) { - /* "pysam/libcalignmentfile.pyx":1279 - * elif read_loc and last_read_pos is None: - * stop = genome_loc # we are right exclusive ,so this is correct - * res[(start, stop)] += 1 # <<<<<<<<<<<<<< - * del start - * del stop + /* "pysam/libcalignmentfile.pyx":1650 + * for op, nt in r.cigartuples: + * if op in match_or_deletion: + * base_position += nt # <<<<<<<<<<<<<< + * elif op == BAM_CREF_SKIP: + * junc_start = base_position */ - if (unlikely(!__pyx_v_start)) { __Pyx_RaiseUnboundLocalError("start"); __PYX_ERR(0, 1279, __pyx_L1_error) } - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1279, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_start); - __Pyx_GIVEREF(__pyx_v_start); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_start); - __Pyx_INCREF(__pyx_v_stop); - __Pyx_GIVEREF(__pyx_v_stop); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_stop); - __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_v_res, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1279, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_11, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1279, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (unlikely(PyObject_SetItem(__pyx_v_res, __pyx_t_2, __pyx_t_8) < 0)) __PYX_ERR(0, 1279, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_base_position = (__pyx_v_base_position + __pyx_v_nt); - /* "pysam/libcalignmentfile.pyx":1280 - * stop = genome_loc # we are right exclusive ,so this is correct - * res[(start, stop)] += 1 - * del start # <<<<<<<<<<<<<< - * del stop - * last_read_pos = read_loc + /* "pysam/libcalignmentfile.pyx":1649 + * + * for op, nt in r.cigartuples: + * if op in match_or_deletion: # <<<<<<<<<<<<<< + * base_position += nt + * elif op == BAM_CREF_SKIP: */ - if (unlikely(!__pyx_v_start)) { __Pyx_RaiseUnboundLocalError("start"); __PYX_ERR(0, 1280, __pyx_L1_error) } - __Pyx_DECREF(__pyx_v_start); - __pyx_v_start = NULL; + goto __pyx_L9; + } - /* "pysam/libcalignmentfile.pyx":1281 - * res[(start, stop)] += 1 - * del start - * del stop # <<<<<<<<<<<<<< - * last_read_pos = read_loc - * return res + /* "pysam/libcalignmentfile.pyx":1651 + * if op in match_or_deletion: + * base_position += nt + * elif op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< + * junc_start = base_position + * base_position += nt */ - __Pyx_DECREF(__pyx_v_stop); - __pyx_v_stop = NULL; + __pyx_t_15 = ((__pyx_v_op == __pyx_v_BAM_CREF_SKIP) != 0); + if (__pyx_t_15) { - /* "pysam/libcalignmentfile.pyx":1277 - * if read_loc is None and last_read_pos: - * start = genome_loc - * elif read_loc and last_read_pos is None: # <<<<<<<<<<<<<< - * stop = genome_loc # we are right exclusive ,so this is correct - * res[(start, stop)] += 1 + /* "pysam/libcalignmentfile.pyx":1652 + * base_position += nt + * elif op == BAM_CREF_SKIP: + * junc_start = base_position # <<<<<<<<<<<<<< + * base_position += nt + * res[(junc_start, base_position)] += 1 + */ + __pyx_v_junc_start = __pyx_v_base_position; + + /* "pysam/libcalignmentfile.pyx":1653 + * elif op == BAM_CREF_SKIP: + * junc_start = base_position + * base_position += nt # <<<<<<<<<<<<<< + * res[(junc_start, base_position)] += 1 + * return res */ - } - __pyx_L10:; + __pyx_v_base_position = (__pyx_v_base_position + __pyx_v_nt); - /* "pysam/libcalignmentfile.pyx":1282 - * del start - * del stop - * last_read_pos = read_loc # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1654 + * junc_start = base_position + * base_position += nt + * res[(junc_start, base_position)] += 1 # <<<<<<<<<<<<<< * return res * */ - __Pyx_INCREF(__pyx_v_read_loc); - __Pyx_DECREF_SET(__pyx_v_last_read_pos, __pyx_v_read_loc); + __pyx_t_2 = __Pyx_PyInt_From_uint32_t(__pyx_v_junc_start); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1654, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = __Pyx_PyInt_From_uint32_t(__pyx_v_base_position); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1654, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1654, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_10); + __pyx_t_2 = 0; + __pyx_t_10 = 0; + __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_v_res, __pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1654, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_10, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1654, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(PyObject_SetItem(__pyx_v_res, __pyx_t_9, __pyx_t_2) < 0)) __PYX_ERR(0, 1654, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - /* "pysam/libcalignmentfile.pyx":1274 - * if 'N' in r.cigarstring: - * last_read_pos = False - * for read_loc, genome_loc in r.get_aligned_pairs(): # <<<<<<<<<<<<<< - * if read_loc is None and last_read_pos: - * start = genome_loc + /* "pysam/libcalignmentfile.pyx":1651 + * if op in match_or_deletion: + * base_position += nt + * elif op == BAM_CREF_SKIP: # <<<<<<<<<<<<<< + * junc_start = base_position + * base_position += nt */ } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_L9:; - /* "pysam/libcalignmentfile.pyx":1272 - * res = collections.Counter() - * for r in read_iterator: - * if 'N' in r.cigarstring: # <<<<<<<<<<<<<< - * last_read_pos = False - * for read_loc, genome_loc in r.get_aligned_pairs(): + /* "pysam/libcalignmentfile.pyx":1648 + * base_position = r.pos + * + * for op, nt in r.cigartuples: # <<<<<<<<<<<<<< + * if op in match_or_deletion: + * base_position += nt */ } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignmentfile.pyx":1271 - * import collections - * res = collections.Counter() + /* "pysam/libcalignmentfile.pyx":1645 + * + * match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position * for r in read_iterator: # <<<<<<<<<<<<<< - * if 'N' in r.cigarstring: - * last_read_pos = False + * base_position = r.pos + * */ } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1283 - * del stop - * last_read_pos = read_loc + /* "pysam/libcalignmentfile.pyx":1655 + * base_position += nt + * res[(junc_start, base_position)] += 1 * return res # <<<<<<<<<<<<<< * - * def close(self): + * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_res); __pyx_r = __pyx_v_res; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1260 - * return count_a, count_c, count_g, count_t + /* "pysam/libcalignmentfile.pyx":1626 + * return res * * def find_introns(self, read_iterator): # <<<<<<<<<<<<<< * """Return a dictionary {(start, stop): count} @@ -15067,49 +20186,45 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26find_intr __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.find_introns", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_r); __Pyx_XDECREF(__pyx_v_collections); __Pyx_XDECREF(__pyx_v_res); - __Pyx_XDECREF(__pyx_v_r); - __Pyx_XDECREF(__pyx_v_last_read_pos); - __Pyx_XDECREF(__pyx_v_read_loc); - __Pyx_XDECREF(__pyx_v_genome_loc); - __Pyx_XDECREF(__pyx_v_start); - __Pyx_XDECREF(__pyx_v_stop); + __Pyx_XDECREF(__pyx_v_match_or_deletion); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1285 - * return res +/* "pysam/libcalignmentfile.pyx":1658 + * * * def close(self): # <<<<<<<<<<<<<< - * ''' - * closes the :class:`pysam.AlignmentFile`.''' + * '''closes the :class:`pysam.AlignmentFile`.''' + * */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_28close[] = "AlignmentFile.close(self)\n\n closes the :class:`pysam.AlignmentFile`."; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_24close[] = "AlignmentFile.close(self)\ncloses the :class:`pysam.AlignmentFile`."; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("close (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28close(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24close(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28close(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24close(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { int __pyx_v_ret; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations @@ -15119,10 +20234,10 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28close(str PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("close", 0); - __Pyx_TraceCall("close", __pyx_f[0], 1285, 0, __PYX_ERR(0, 1285, __pyx_L1_error)); + __Pyx_TraceCall("close", __pyx_f[0], 1658, 0, __PYX_ERR(0, 1658, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1289 - * closes the :class:`pysam.AlignmentFile`.''' + /* "pysam/libcalignmentfile.pyx":1661 + * '''closes the :class:`pysam.AlignmentFile`.''' * * if self.htsfile == NULL: # <<<<<<<<<<<<<< * return @@ -15131,7 +20246,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28close(str __pyx_t_1 = ((__pyx_v_self->__pyx_base.htsfile == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1290 + /* "pysam/libcalignmentfile.pyx":1662 * * if self.htsfile == NULL: * return # <<<<<<<<<<<<<< @@ -15142,8 +20257,8 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28close(str __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1289 - * closes the :class:`pysam.AlignmentFile`.''' + /* "pysam/libcalignmentfile.pyx":1661 + * '''closes the :class:`pysam.AlignmentFile`.''' * * if self.htsfile == NULL: # <<<<<<<<<<<<<< * return @@ -15151,36 +20266,77 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28close(str */ } - /* "pysam/libcalignmentfile.pyx":1292 + /* "pysam/libcalignmentfile.pyx":1664 * return * * cdef int ret = hts_close(self.htsfile) # <<<<<<<<<<<<<< - * hts_idx_destroy(self.index) * self.htsfile = NULL + * */ __pyx_v_ret = hts_close(__pyx_v_self->__pyx_base.htsfile); - /* "pysam/libcalignmentfile.pyx":1293 + /* "pysam/libcalignmentfile.pyx":1665 * * cdef int ret = hts_close(self.htsfile) - * hts_idx_destroy(self.index) # <<<<<<<<<<<<<< + * self.htsfile = NULL # <<<<<<<<<<<<<< + * + * if self.index != NULL: + */ + __pyx_v_self->__pyx_base.htsfile = NULL; + + /* "pysam/libcalignmentfile.pyx":1667 * self.htsfile = NULL * + * if self.index != NULL: # <<<<<<<<<<<<<< + * hts_idx_destroy(self.index) + * self.index = NULL */ - hts_idx_destroy(__pyx_v_self->index); + __pyx_t_1 = ((__pyx_v_self->index != NULL) != 0); + if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1294 - * cdef int ret = hts_close(self.htsfile) - * hts_idx_destroy(self.index) - * self.htsfile = NULL # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1668 + * + * if self.index != NULL: + * hts_idx_destroy(self.index) # <<<<<<<<<<<<<< + * self.index = NULL * - * if ret < 0: */ - __pyx_v_self->__pyx_base.htsfile = NULL; + hts_idx_destroy(__pyx_v_self->index); + + /* "pysam/libcalignmentfile.pyx":1669 + * if self.index != NULL: + * hts_idx_destroy(self.index) + * self.index = NULL # <<<<<<<<<<<<<< + * + * self.header = None + */ + __pyx_v_self->index = NULL; - /* "pysam/libcalignmentfile.pyx":1296 + /* "pysam/libcalignmentfile.pyx":1667 * self.htsfile = NULL * + * if self.index != NULL: # <<<<<<<<<<<<<< + * hts_idx_destroy(self.index) + * self.index = NULL + */ + } + + /* "pysam/libcalignmentfile.pyx":1671 + * self.index = NULL + * + * self.header = None # <<<<<<<<<<<<<< + * + * if ret < 0: + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); + + /* "pysam/libcalignmentfile.pyx":1673 + * self.header = None + * * if ret < 0: # <<<<<<<<<<<<<< * global errno * if errno == EPIPE: @@ -15188,7 +20344,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28close(str __pyx_t_1 = ((__pyx_v_ret < 0) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1298 + /* "pysam/libcalignmentfile.pyx":1675 * if ret < 0: * global errno * if errno == EPIPE: # <<<<<<<<<<<<<< @@ -15198,41 +20354,41 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28close(str __pyx_t_1 = ((errno == EPIPE) != 0); if (likely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":1299 + /* "pysam/libcalignmentfile.pyx":1676 * global errno * if errno == EPIPE: * errno = 0 # <<<<<<<<<<<<<< * else: - * raise OSError(errno, force_str(strerror(errno))) + * raise IOError(errno, force_str(strerror(errno))) */ errno = 0; - /* "pysam/libcalignmentfile.pyx":1298 + /* "pysam/libcalignmentfile.pyx":1675 * if ret < 0: * global errno * if errno == EPIPE: # <<<<<<<<<<<<<< * errno = 0 * else: */ - goto __pyx_L5; + goto __pyx_L6; } - /* "pysam/libcalignmentfile.pyx":1301 + /* "pysam/libcalignmentfile.pyx":1678 * errno = 0 * else: - * raise OSError(errno, force_str(strerror(errno))) # <<<<<<<<<<<<<< + * raise IOError(errno, force_str(strerror(errno))) # <<<<<<<<<<<<<< * * def __dealloc__(self): */ /*else*/ { - __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1301, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1678, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1301, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1678, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1301, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1678, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1301, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1678, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); @@ -15240,17 +20396,17 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28close(str PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); __pyx_t_2 = 0; __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1301, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1678, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1301, __pyx_L1_error) + __PYX_ERR(0, 1678, __pyx_L1_error) } - __pyx_L5:; + __pyx_L6:; - /* "pysam/libcalignmentfile.pyx":1296 - * self.htsfile = NULL + /* "pysam/libcalignmentfile.pyx":1673 + * self.header = None * * if ret < 0: # <<<<<<<<<<<<<< * global errno @@ -15258,12 +20414,12 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28close(str */ } - /* "pysam/libcalignmentfile.pyx":1285 - * return res + /* "pysam/libcalignmentfile.pyx":1658 + * * * def close(self): # <<<<<<<<<<<<<< - * ''' - * closes the :class:`pysam.AlignmentFile`.''' + * '''closes the :class:`pysam.AlignmentFile`.''' + * */ /* function exit code */ @@ -15282,26 +20438,26 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28close(str return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1303 - * raise OSError(errno, force_str(strerror(errno))) +/* "pysam/libcalignmentfile.pyx":1680 + * raise IOError(errno, force_str(strerror(errno))) * * def __dealloc__(self): # <<<<<<<<<<<<<< - * # remember: dealloc cannot call other methods - * # note: no doc string + * cdef int ret = 0 + * */ /* Python wrapper */ -static void __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__dealloc__(PyObject *__pyx_v_self) { +static void __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_27__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_27__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); } -static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { +static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { int __pyx_v_ret; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -15310,102 +20466,143 @@ static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__dealloc__(st PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1303, 0, __PYX_ERR(0, 1303, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1680, 0, __PYX_ERR(0, 1680, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1315 - * # it seems to be dangerous according to the documentation as the - * # object be partially deconstructed already. + /* "pysam/libcalignmentfile.pyx":1681 + * + * def __dealloc__(self): * cdef int ret = 0 # <<<<<<<<<<<<<< * * if self.htsfile != NULL: */ __pyx_v_ret = 0; - /* "pysam/libcalignmentfile.pyx":1317 + /* "pysam/libcalignmentfile.pyx":1683 * cdef int ret = 0 * * if self.htsfile != NULL: # <<<<<<<<<<<<<< * ret = hts_close(self.htsfile) - * hts_idx_destroy(self.index); + * self.htsfile = NULL */ __pyx_t_1 = ((__pyx_v_self->__pyx_base.htsfile != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1318 + /* "pysam/libcalignmentfile.pyx":1684 * * if self.htsfile != NULL: * ret = hts_close(self.htsfile) # <<<<<<<<<<<<<< - * hts_idx_destroy(self.index); * self.htsfile = NULL + * */ __pyx_v_ret = hts_close(__pyx_v_self->__pyx_base.htsfile); - /* "pysam/libcalignmentfile.pyx":1319 + /* "pysam/libcalignmentfile.pyx":1685 * if self.htsfile != NULL: * ret = hts_close(self.htsfile) - * hts_idx_destroy(self.index); # <<<<<<<<<<<<<< - * self.htsfile = NULL - * - */ - hts_idx_destroy(__pyx_v_self->index); - - /* "pysam/libcalignmentfile.pyx":1320 - * ret = hts_close(self.htsfile) - * hts_idx_destroy(self.index); * self.htsfile = NULL # <<<<<<<<<<<<<< * - * bam_destroy1(self.b) + * if self.index != NULL: */ __pyx_v_self->__pyx_base.htsfile = NULL; - /* "pysam/libcalignmentfile.pyx":1317 + /* "pysam/libcalignmentfile.pyx":1683 * cdef int ret = 0 * * if self.htsfile != NULL: # <<<<<<<<<<<<<< * ret = hts_close(self.htsfile) - * hts_idx_destroy(self.index); + * self.htsfile = NULL */ } - /* "pysam/libcalignmentfile.pyx":1322 + /* "pysam/libcalignmentfile.pyx":1687 * self.htsfile = NULL * - * bam_destroy1(self.b) # <<<<<<<<<<<<<< - * if self.header != NULL: - * bam_hdr_destroy(self.header) + * if self.index != NULL: # <<<<<<<<<<<<<< + * hts_idx_destroy(self.index) + * self.index = NULL */ - bam_destroy1(__pyx_v_self->b); + __pyx_t_1 = ((__pyx_v_self->index != NULL) != 0); + if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1323 + /* "pysam/libcalignmentfile.pyx":1688 * - * bam_destroy1(self.b) - * if self.header != NULL: # <<<<<<<<<<<<<< - * bam_hdr_destroy(self.header) + * if self.index != NULL: + * hts_idx_destroy(self.index) # <<<<<<<<<<<<<< + * self.index = NULL + * + */ + hts_idx_destroy(__pyx_v_self->index); + + /* "pysam/libcalignmentfile.pyx":1689 + * if self.index != NULL: + * hts_idx_destroy(self.index) + * self.index = NULL # <<<<<<<<<<<<<< + * + * self.header = None + */ + __pyx_v_self->index = NULL; + + /* "pysam/libcalignmentfile.pyx":1687 + * self.htsfile = NULL + * + * if self.index != NULL: # <<<<<<<<<<<<<< + * hts_idx_destroy(self.index) + * self.index = NULL + */ + } + + /* "pysam/libcalignmentfile.pyx":1691 + * self.index = NULL + * + * self.header = None # <<<<<<<<<<<<<< + * + * if self.b: + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); + + /* "pysam/libcalignmentfile.pyx":1693 + * self.header = None * + * if self.b: # <<<<<<<<<<<<<< + * bam_destroy1(self.b) + * self.b = NULL */ - __pyx_t_1 = ((__pyx_v_self->header != NULL) != 0); + __pyx_t_1 = (__pyx_v_self->b != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1324 - * bam_destroy1(self.b) - * if self.header != NULL: - * bam_hdr_destroy(self.header) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1694 * + * if self.b: + * bam_destroy1(self.b) # <<<<<<<<<<<<<< + * self.b = NULL * */ - bam_hdr_destroy(__pyx_v_self->header); + bam_destroy1(__pyx_v_self->b); - /* "pysam/libcalignmentfile.pyx":1323 + /* "pysam/libcalignmentfile.pyx":1695 + * if self.b: + * bam_destroy1(self.b) + * self.b = NULL # <<<<<<<<<<<<<< * - * bam_destroy1(self.b) - * if self.header != NULL: # <<<<<<<<<<<<<< - * bam_hdr_destroy(self.header) + * if ret < 0: + */ + __pyx_v_self->b = NULL; + + /* "pysam/libcalignmentfile.pyx":1693 + * self.header = None * + * if self.b: # <<<<<<<<<<<<<< + * bam_destroy1(self.b) + * self.b = NULL */ } - /* "pysam/libcalignmentfile.pyx":1327 - * + /* "pysam/libcalignmentfile.pyx":1697 + * self.b = NULL * * if ret < 0: # <<<<<<<<<<<<<< * global errno @@ -15414,7 +20611,7 @@ static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__dealloc__(st __pyx_t_1 = ((__pyx_v_ret < 0) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1329 + /* "pysam/libcalignmentfile.pyx":1699 * if ret < 0: * global errno * if errno == EPIPE: # <<<<<<<<<<<<<< @@ -15424,41 +20621,41 @@ static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__dealloc__(st __pyx_t_1 = ((errno == EPIPE) != 0); if (likely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":1330 + /* "pysam/libcalignmentfile.pyx":1700 * global errno * if errno == EPIPE: * errno = 0 # <<<<<<<<<<<<<< * else: - * raise OSError(errno, force_str(strerror(errno))) + * raise IOError(errno, force_str(strerror(errno))) */ errno = 0; - /* "pysam/libcalignmentfile.pyx":1329 + /* "pysam/libcalignmentfile.pyx":1699 * if ret < 0: * global errno * if errno == EPIPE: # <<<<<<<<<<<<<< * errno = 0 * else: */ - goto __pyx_L6; + goto __pyx_L7; } - /* "pysam/libcalignmentfile.pyx":1332 + /* "pysam/libcalignmentfile.pyx":1702 * errno = 0 * else: - * raise OSError(errno, force_str(strerror(errno))) # <<<<<<<<<<<<<< + * raise IOError(errno, force_str(strerror(errno))) # <<<<<<<<<<<<<< * * cpdef int write(self, AlignedSegment read) except -1: */ /*else*/ { - __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1332, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1702, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1332, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1702, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1332, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1702, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1332, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1702, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); @@ -15466,17 +20663,17 @@ static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__dealloc__(st PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); __pyx_t_2 = 0; __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1332, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1702, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1332, __pyx_L1_error) + __PYX_ERR(0, 1702, __pyx_L1_error) } - __pyx_L6:; + __pyx_L7:; - /* "pysam/libcalignmentfile.pyx":1327 - * + /* "pysam/libcalignmentfile.pyx":1697 + * self.b = NULL * * if ret < 0: # <<<<<<<<<<<<<< * global errno @@ -15484,12 +20681,12 @@ static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__dealloc__(st */ } - /* "pysam/libcalignmentfile.pyx":1303 - * raise OSError(errno, force_str(strerror(errno))) + /* "pysam/libcalignmentfile.pyx":1680 + * raise IOError(errno, force_str(strerror(errno))) * * def __dealloc__(self): # <<<<<<<<<<<<<< - * # remember: dealloc cannot call other methods - * # note: no doc string + * cdef int ret = 0 + * */ /* function exit code */ @@ -15504,15 +20701,15 @@ static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__dealloc__(st __Pyx_RefNannyFinishContext(); } -/* "pysam/libcalignmentfile.pyx":1334 - * raise OSError(errno, force_str(strerror(errno))) +/* "pysam/libcalignmentfile.pyx":1704 + * raise IOError(errno, force_str(strerror(errno))) * * cpdef int write(self, AlignedSegment read) except -1: # <<<<<<<<<<<<<< * ''' * write a single :class:`pysam.AlignedSegment` to disk. */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read, int __pyx_skip_dispatch) { int __pyx_v_ret; int __pyx_r; @@ -15527,14 +20724,14 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx int __pyx_t_7; int __pyx_t_8; __Pyx_RefNannySetupContext("write", 0); - __Pyx_TraceCall("write", __pyx_f[0], 1334, 0, __PYX_ERR(0, 1334, __pyx_L1_error)); + __Pyx_TraceCall("write", __pyx_f[0], 1704, 0, __PYX_ERR(0, 1704, __pyx_L1_error)); /* Check if called by wrapper */ if (unlikely(__pyx_skip_dispatch)) ; /* Check if overridden in Python */ else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1334, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1704, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33write)) { + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write)) { __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { @@ -15547,13 +20744,13 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx } } if (!__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_read)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1334, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_read)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1704, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_read)}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1334, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1704, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_2); } else @@ -15561,25 +20758,25 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_read)}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1334, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1704, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1334, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1704, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_INCREF(((PyObject *)__pyx_v_read)); __Pyx_GIVEREF(((PyObject *)__pyx_v_read)); PyTuple_SET_ITEM(__pyx_t_5, 0+1, ((PyObject *)__pyx_v_read)); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1334, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1704, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1334, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1704, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_6; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -15588,21 +20785,21 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - /* "pysam/libcalignmentfile.pyx":1349 + /* "pysam/libcalignmentfile.pyx":1719 * this will be 0. * ''' * if not self.is_open: # <<<<<<<<<<<<<< * return 0 * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1349, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1719, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1349, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1719, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_8 = ((!__pyx_t_7) != 0); if (__pyx_t_8) { - /* "pysam/libcalignmentfile.pyx":1350 + /* "pysam/libcalignmentfile.pyx":1720 * ''' * if not self.is_open: * return 0 # <<<<<<<<<<<<<< @@ -15612,7 +20809,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1349 + /* "pysam/libcalignmentfile.pyx":1719 * this will be 0. * ''' * if not self.is_open: # <<<<<<<<<<<<<< @@ -15621,12 +20818,12 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx */ } - /* "pysam/libcalignmentfile.pyx":1354 + /* "pysam/libcalignmentfile.pyx":1724 * cdef int ret * * with nogil: # <<<<<<<<<<<<<< * ret = sam_write1(self.htsfile, - * self.header, + * self.header.ptr, */ { #ifdef WITH_THREAD @@ -15636,22 +20833,22 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1355 + /* "pysam/libcalignmentfile.pyx":1725 * * with nogil: * ret = sam_write1(self.htsfile, # <<<<<<<<<<<<<< - * self.header, + * self.header.ptr, * read._delegate) */ - __pyx_v_ret = sam_write1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->header, __pyx_v_read->_delegate); + __pyx_v_ret = sam_write1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->header->ptr, __pyx_v_read->_delegate); } - /* "pysam/libcalignmentfile.pyx":1354 + /* "pysam/libcalignmentfile.pyx":1724 * cdef int ret * * with nogil: # <<<<<<<<<<<<<< * ret = sam_write1(self.htsfile, - * self.header, + * self.header.ptr, */ /*finally:*/ { /*normal exit:*/{ @@ -15665,7 +20862,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx } } - /* "pysam/libcalignmentfile.pyx":1362 + /* "pysam/libcalignmentfile.pyx":1732 * # when ret == -1 we get a "SystemError: error return without * # exception set". * if ret < 0: # <<<<<<<<<<<<<< @@ -15675,16 +20872,16 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx __pyx_t_8 = ((__pyx_v_ret < 0) != 0); if (unlikely(__pyx_t_8)) { - /* "pysam/libcalignmentfile.pyx":1364 + /* "pysam/libcalignmentfile.pyx":1734 * if ret < 0: * raise IOError( * "sam_write1 failed with error code {}".format(ret)) # <<<<<<<<<<<<<< * * return ret */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_sam_write1_failed_with_error_cod, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1364, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_sam_write1_failed_with_error_cod, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1364, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -15697,14 +20894,14 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx } } if (!__pyx_t_5) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1364, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1734, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1364, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1734, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -15713,41 +20910,41 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1364, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1734, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1364, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1364, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":1363 + /* "pysam/libcalignmentfile.pyx":1733 * # exception set". * if ret < 0: * raise IOError( # <<<<<<<<<<<<<< * "sam_write1 failed with error code {}".format(ret)) * */ - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1363, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1733, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 1363, __pyx_L1_error) + __PYX_ERR(0, 1733, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1362 + /* "pysam/libcalignmentfile.pyx":1732 * # when ret == -1 we get a "SystemError: error return without * # exception set". * if ret < 0: # <<<<<<<<<<<<<< @@ -15756,7 +20953,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx */ } - /* "pysam/libcalignmentfile.pyx":1366 + /* "pysam/libcalignmentfile.pyx":1736 * "sam_write1 failed with error code {}".format(ret)) * * return ret # <<<<<<<<<<<<<< @@ -15766,8 +20963,8 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1334 - * raise OSError(errno, force_str(strerror(errno))) + /* "pysam/libcalignmentfile.pyx":1704 + * raise IOError(errno, force_str(strerror(errno))) * * cpdef int write(self, AlignedSegment read) except -1: # <<<<<<<<<<<<<< * ''' @@ -15790,14 +20987,14 @@ static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx } /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_32write[] = "AlignmentFile.write(self, AlignedSegment read) -> int\n\n write a single :class:`pysam.AlignedSegment` to disk.\n\n Raises\n ------\n ValueError\n if the writing failed\n\n Returns\n -------\n \n int : the number of bytes written. If the file is closed,\n this will be 0.\n "; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33write(PyObject *__pyx_v_self, PyObject *__pyx_v_read) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_28write[] = "AlignmentFile.write(self, AlignedSegment read) -> int\n\n write a single :class:`pysam.AlignedSegment` to disk.\n\n Raises\n ------\n ValueError\n if the writing failed\n\n Returns\n -------\n\n int : the number of bytes written. If the file is closed,\n this will be 0.\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write(PyObject *__pyx_v_self, PyObject *__pyx_v_read) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment, 1, "read", 0))) __PYX_ERR(0, 1334, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32write(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_read)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment, 1, "read", 0))) __PYX_ERR(0, 1704, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28write(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_v_read)); /* function exit code */ goto __pyx_L0; @@ -15808,17 +21005,17 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33write(PyO return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("write", 0); - __Pyx_TraceCall("write (wrapper)", __pyx_f[0], 1334, 0, __PYX_ERR(0, 1334, __pyx_L1_error)); + __Pyx_TraceCall("write (wrapper)", __pyx_f[0], 1704, 0, __PYX_ERR(0, 1704, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(__pyx_v_self, __pyx_v_read, 1); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 1334, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1334, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(__pyx_v_self, __pyx_v_read, 1); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 1704, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1704, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; @@ -15836,7 +21033,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32write(str return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1369 +/* "pysam/libcalignmentfile.pyx":1739 * * # context manager interface * def __enter__(self): # <<<<<<<<<<<<<< @@ -15845,27 +21042,27 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32write(str */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_34__enter__[] = "AlignmentFile.__enter__(self)"; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__[] = "AlignmentFile.__enter__(self)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__enter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34__enter__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34__enter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__enter__", 0); - __Pyx_TraceCall("__enter__", __pyx_f[0], 1369, 0, __PYX_ERR(0, 1369, __pyx_L1_error)); + __Pyx_TraceCall("__enter__", __pyx_f[0], 1739, 0, __PYX_ERR(0, 1739, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1370 + /* "pysam/libcalignmentfile.pyx":1740 * # context manager interface * def __enter__(self): * return self # <<<<<<<<<<<<<< @@ -15877,7 +21074,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34__enter__ __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1369 + /* "pysam/libcalignmentfile.pyx":1739 * * # context manager interface * def __enter__(self): # <<<<<<<<<<<<<< @@ -15896,7 +21093,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34__enter__ return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1372 +/* "pysam/libcalignmentfile.pyx":1742 * return self * * def __exit__(self, exc_type, exc_value, traceback): # <<<<<<<<<<<<<< @@ -15905,9 +21102,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34__enter__ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_36__exit__[] = "AlignmentFile.__exit__(self, exc_type, exc_value, traceback)"; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__[] = "AlignmentFile.__exit__(self, exc_type, exc_value, traceback)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { CYTHON_UNUSED PyObject *__pyx_v_exc_type = 0; CYTHON_UNUSED PyObject *__pyx_v_exc_value = 0; CYTHON_UNUSED PyObject *__pyx_v_traceback = 0; @@ -15939,17 +21136,17 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__exit__( case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_exc_value)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 1372, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 1742, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_traceback)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 1372, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 1742, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 1372, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 1742, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -15964,20 +21161,20 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__exit__( } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1372, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1742, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__exit__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_exc_type, __pyx_v_exc_value, __pyx_v_traceback); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_exc_type, __pyx_v_exc_value, __pyx_v_traceback); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__exit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -15985,16 +21182,16 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__exit__( PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__exit__", 0); - __Pyx_TraceCall("__exit__", __pyx_f[0], 1372, 0, __PYX_ERR(0, 1372, __pyx_L1_error)); + __Pyx_TraceCall("__exit__", __pyx_f[0], 1742, 0, __PYX_ERR(0, 1742, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1373 + /* "pysam/libcalignmentfile.pyx":1743 * * def __exit__(self, exc_type, exc_value, traceback): * self.close() # <<<<<<<<<<<<<< * return False * */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1373, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1743, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -16007,16 +21204,16 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__exit__( } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1373, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1743, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1373, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1743, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1374 + /* "pysam/libcalignmentfile.pyx":1744 * def __exit__(self, exc_type, exc_value, traceback): * self.close() * return False # <<<<<<<<<<<<<< @@ -16028,7 +21225,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__exit__( __pyx_r = Py_False; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1372 + /* "pysam/libcalignmentfile.pyx":1742 * return self * * def __exit__(self, exc_type, exc_value, traceback): # <<<<<<<<<<<<<< @@ -16050,417 +21247,400 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__exit__( return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1384 - * """"int with the number of :term:`reference` sequences in the file. - * This is a read-only attribute.""" - * def __get__(self): # <<<<<<<<<<<<<< - * if not self.is_open: - * raise ValueError("I/O operation on closed file") - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1384, 0, __PYX_ERR(0, 1384, __pyx_L1_error)); - - /* "pysam/libcalignmentfile.pyx":1385 - * This is a read-only attribute.""" - * def __get__(self): - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") - * return self.header.n_targets - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1385, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1385, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { - - /* "pysam/libcalignmentfile.pyx":1386 - * def __get__(self): - * if not self.is_open: - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< - * return self.header.n_targets - * - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1386, __pyx_L1_error) - - /* "pysam/libcalignmentfile.pyx":1385 - * This is a read-only attribute.""" - * def __get__(self): - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") - * return self.header.n_targets - */ - } - - /* "pysam/libcalignmentfile.pyx":1387 - * if not self.is_open: - * raise ValueError("I/O operation on closed file") - * return self.header.n_targets # <<<<<<<<<<<<<< - * - * property references: - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->header->n_targets); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1387, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "pysam/libcalignmentfile.pyx":1384 - * """"int with the number of :term:`reference` sequences in the file. - * This is a read-only attribute.""" - * def __get__(self): # <<<<<<<<<<<<<< - * if not self.is_open: - * raise ValueError("I/O operation on closed file") - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.nreferences.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignmentfile.pyx":1392 - * """tuple with the names of :term:`reference` sequences. This is a - * read-only attribute""" +/* "pysam/libcalignmentfile.pyx":1756 + * attribute. + * """ * def __get__(self): # <<<<<<<<<<<<<< - * if not self.is_open: raise ValueError( "I/O operation on closed file" ) - * t = [] + * self.check_index() + * cdef int tid */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_10references_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_10references_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6mapped_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6mapped_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10references___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } - -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { - PyObject *__pyx_v_t = NULL; - long __pyx_v_x; + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { + int __pyx_v_tid; + uint64_t __pyx_v_total; + uint64_t __pyx_v_mapped; + uint64_t __pyx_v_unmapped; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int32_t __pyx_t_4; - int __pyx_t_5; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1392, 0, __PYX_ERR(0, 1392, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1756, 0, __PYX_ERR(0, 1756, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1393 - * read-only attribute""" + /* "pysam/libcalignmentfile.pyx":1757 + * """ * def __get__(self): - * if not self.is_open: raise ValueError( "I/O operation on closed file" ) # <<<<<<<<<<<<<< - * t = [] - * for x from 0 <= x < self.header.n_targets: + * self.check_index() # <<<<<<<<<<<<<< + * cdef int tid + * cdef uint64_t total = 0 */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1393, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1757, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1757, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1757, __pyx_L1_error) + } __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1393, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1393, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1393, __pyx_L1_error) - } - /* "pysam/libcalignmentfile.pyx":1394 - * def __get__(self): - * if not self.is_open: raise ValueError( "I/O operation on closed file" ) - * t = [] # <<<<<<<<<<<<<< - * for x from 0 <= x < self.header.n_targets: - * t.append(charptr_to_str(self.header.target_name[x])) + /* "pysam/libcalignmentfile.pyx":1759 + * self.check_index() + * cdef int tid + * cdef uint64_t total = 0 # <<<<<<<<<<<<<< + * cdef uint64_t mapped, unmapped + * for tid from 0 <= tid < self.header.nreferences: + */ + __pyx_v_total = 0; + + /* "pysam/libcalignmentfile.pyx":1761 + * cdef uint64_t total = 0 + * cdef uint64_t mapped, unmapped + * for tid from 0 <= tid < self.header.nreferences: # <<<<<<<<<<<<<< + * with nogil: + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1394, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1761, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_v_t = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1761, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_4; __pyx_v_tid++) { - /* "pysam/libcalignmentfile.pyx":1395 - * if not self.is_open: raise ValueError( "I/O operation on closed file" ) - * t = [] - * for x from 0 <= x < self.header.n_targets: # <<<<<<<<<<<<<< - * t.append(charptr_to_str(self.header.target_name[x])) - * return tuple(t) + /* "pysam/libcalignmentfile.pyx":1762 + * cdef uint64_t mapped, unmapped + * for tid from 0 <= tid < self.header.nreferences: + * with nogil: # <<<<<<<<<<<<<< + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + * total += mapped */ - __pyx_t_4 = __pyx_v_self->header->n_targets; - for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_4; __pyx_v_x++) { + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1396 - * t = [] - * for x from 0 <= x < self.header.n_targets: - * t.append(charptr_to_str(self.header.target_name[x])) # <<<<<<<<<<<<<< - * return tuple(t) + /* "pysam/libcalignmentfile.pyx":1763 + * for tid from 0 <= tid < self.header.nreferences: + * with nogil: + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) # <<<<<<<<<<<<<< + * total += mapped + * return total + */ + (void)(hts_idx_get_stat(__pyx_v_self->index, __pyx_v_tid, (&__pyx_v_mapped), (&__pyx_v_unmapped))); + } + + /* "pysam/libcalignmentfile.pyx":1762 + * cdef uint64_t mapped, unmapped + * for tid from 0 <= tid < self.header.nreferences: + * with nogil: # <<<<<<<<<<<<<< + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + * total += mapped + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L9; + } + __pyx_L9:; + } + } + + /* "pysam/libcalignmentfile.pyx":1764 + * with nogil: + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + * total += mapped # <<<<<<<<<<<<<< + * return total * */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_self->header->target_name[__pyx_v_x]), NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1396, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_t, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 1396, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_total = (__pyx_v_total + __pyx_v_mapped); } - /* "pysam/libcalignmentfile.pyx":1397 - * for x from 0 <= x < self.header.n_targets: - * t.append(charptr_to_str(self.header.target_name[x])) - * return tuple(t) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1765 + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + * total += mapped + * return total # <<<<<<<<<<<<<< * - * property lengths: + * property unmapped: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyList_AsTuple(__pyx_v_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1397, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_total); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1765, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1392 - * """tuple with the names of :term:`reference` sequences. This is a - * read-only attribute""" + /* "pysam/libcalignmentfile.pyx":1756 + * attribute. + * """ * def __get__(self): # <<<<<<<<<<<<<< - * if not self.is_open: raise ValueError( "I/O operation on closed file" ) - * t = [] + * self.check_index() + * cdef int tid */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.references.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.mapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_t); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1405 - * +/* "pysam/libcalignmentfile.pyx":1772 + * without coordinates. This is a read-only attribute. * """ * def __get__(self): # <<<<<<<<<<<<<< - * if not self.is_open: - * raise ValueError("I/O operation on closed file") + * self.check_index() + * cdef int tid */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7lengths_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7lengths_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_7lengths___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { - PyObject *__pyx_v_t = NULL; - long __pyx_v_x; +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { + int __pyx_v_tid; + uint64_t __pyx_v_total; + uint64_t __pyx_v_mapped; + uint64_t __pyx_v_unmapped; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int32_t __pyx_t_4; - int __pyx_t_5; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1405, 0, __PYX_ERR(0, 1405, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1772, 0, __PYX_ERR(0, 1772, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1406 + /* "pysam/libcalignmentfile.pyx":1773 * """ * def __get__(self): - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") - * t = [] + * self.check_index() # <<<<<<<<<<<<<< + * cdef int tid + * cdef uint64_t total = hts_idx_get_n_no_coor(self.index) */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1406, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1773, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1773, __pyx_L1_error) + } __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1406, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":1407 - * def __get__(self): - * if not self.is_open: - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< - * t = [] - * for x from 0 <= x < self.header.n_targets: + /* "pysam/libcalignmentfile.pyx":1775 + * self.check_index() + * cdef int tid + * cdef uint64_t total = hts_idx_get_n_no_coor(self.index) # <<<<<<<<<<<<<< + * cdef uint64_t mapped, unmapped + * for tid from 0 <= tid < self.header.nreferences: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1407, __pyx_L1_error) + __pyx_v_total = hts_idx_get_n_no_coor(__pyx_v_self->index); - /* "pysam/libcalignmentfile.pyx":1406 - * """ - * def __get__(self): - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") - * t = [] + /* "pysam/libcalignmentfile.pyx":1777 + * cdef uint64_t total = hts_idx_get_n_no_coor(self.index) + * cdef uint64_t mapped, unmapped + * for tid from 0 <= tid < self.header.nreferences: # <<<<<<<<<<<<<< + * with nogil: + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) */ - } + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1777, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1777, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_4; __pyx_v_tid++) { - /* "pysam/libcalignmentfile.pyx":1408 - * if not self.is_open: - * raise ValueError("I/O operation on closed file") - * t = [] # <<<<<<<<<<<<<< - * for x from 0 <= x < self.header.n_targets: - * t.append(self.header.target_len[x]) + /* "pysam/libcalignmentfile.pyx":1778 + * cdef uint64_t mapped, unmapped + * for tid from 0 <= tid < self.header.nreferences: + * with nogil: # <<<<<<<<<<<<<< + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + * total += unmapped */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1408, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_t = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1409 - * raise ValueError("I/O operation on closed file") - * t = [] - * for x from 0 <= x < self.header.n_targets: # <<<<<<<<<<<<<< - * t.append(self.header.target_len[x]) - * return tuple(t) + /* "pysam/libcalignmentfile.pyx":1779 + * for tid from 0 <= tid < self.header.nreferences: + * with nogil: + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) # <<<<<<<<<<<<<< + * total += unmapped + * return total */ - __pyx_t_4 = __pyx_v_self->header->n_targets; - for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_4; __pyx_v_x++) { + (void)(hts_idx_get_stat(__pyx_v_self->index, __pyx_v_tid, (&__pyx_v_mapped), (&__pyx_v_unmapped))); + } - /* "pysam/libcalignmentfile.pyx":1410 - * t = [] - * for x from 0 <= x < self.header.n_targets: - * t.append(self.header.target_len[x]) # <<<<<<<<<<<<<< - * return tuple(t) + /* "pysam/libcalignmentfile.pyx":1778 + * cdef uint64_t mapped, unmapped + * for tid from 0 <= tid < self.header.nreferences: + * with nogil: # <<<<<<<<<<<<<< + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + * total += unmapped + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L9; + } + __pyx_L9:; + } + } + + /* "pysam/libcalignmentfile.pyx":1780 + * with nogil: + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + * total += unmapped # <<<<<<<<<<<<<< + * return total * */ - __pyx_t_1 = __Pyx_PyInt_From_uint32_t((__pyx_v_self->header->target_len[__pyx_v_x])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1410, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_t, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 1410, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_total = (__pyx_v_total + __pyx_v_unmapped); } - /* "pysam/libcalignmentfile.pyx":1411 - * for x from 0 <= x < self.header.n_targets: - * t.append(self.header.target_len[x]) - * return tuple(t) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1781 + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + * total += unmapped + * return total # <<<<<<<<<<<<<< * - * property mapped: + * property nocoordinate: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyList_AsTuple(__pyx_v_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1411, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_total); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1781, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1405 - * + /* "pysam/libcalignmentfile.pyx":1772 + * without coordinates. This is a read-only attribute. * """ * def __get__(self): # <<<<<<<<<<<<<< - * if not self.is_open: - * raise ValueError("I/O operation on closed file") + * self.check_index() + * cdef int tid */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.lengths.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_t); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1418 - * attribute. +/* "pysam/libcalignmentfile.pyx":1787 + * statistics recorded in the index. This is a read-only attribute. * """ * def __get__(self): # <<<<<<<<<<<<<< * self.check_index() - * cdef int tid + * cdef uint64_t n */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6mapped_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6mapped_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { - int __pyx_v_tid; - uint64_t __pyx_v_total; - uint64_t __pyx_v_mapped; - uint64_t __pyx_v_unmapped; +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { + uint64_t __pyx_v_n; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - int32_t __pyx_t_4; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1418, 0, __PYX_ERR(0, 1418, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1787, 0, __PYX_ERR(0, 1787, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1419 + /* "pysam/libcalignmentfile.pyx":1788 * """ * def __get__(self): * self.check_index() # <<<<<<<<<<<<<< - * cdef int tid - * cdef uint64_t total = 0 + * cdef uint64_t n + * with nogil: */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1419, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1788, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -16473,108 +21653,79 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___g } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1419, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1788, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1419, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1788, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1421 + /* "pysam/libcalignmentfile.pyx":1790 * self.check_index() - * cdef int tid - * cdef uint64_t total = 0 # <<<<<<<<<<<<<< - * cdef uint64_t mapped, unmapped - * for tid from 0 <= tid < self.header.n_targets: - */ - __pyx_v_total = 0; - - /* "pysam/libcalignmentfile.pyx":1423 - * cdef uint64_t total = 0 - * cdef uint64_t mapped, unmapped - * for tid from 0 <= tid < self.header.n_targets: # <<<<<<<<<<<<<< - * with nogil: - * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) - */ - __pyx_t_4 = __pyx_v_self->header->n_targets; - for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_4; __pyx_v_tid++) { - - /* "pysam/libcalignmentfile.pyx":1424 - * cdef uint64_t mapped, unmapped - * for tid from 0 <= tid < self.header.n_targets: - * with nogil: # <<<<<<<<<<<<<< - * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) - * total += mapped + * cdef uint64_t n + * with nogil: # <<<<<<<<<<<<<< + * n = hts_idx_get_n_no_coor(self.index) + * return n */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1425 - * for tid from 0 <= tid < self.header.n_targets: - * with nogil: - * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) # <<<<<<<<<<<<<< - * total += mapped - * return total + /* "pysam/libcalignmentfile.pyx":1791 + * cdef uint64_t n + * with nogil: + * n = hts_idx_get_n_no_coor(self.index) # <<<<<<<<<<<<<< + * return n + * */ - (void)(hts_idx_get_stat(__pyx_v_self->index, __pyx_v_tid, (&__pyx_v_mapped), (&__pyx_v_unmapped))); - } + __pyx_v_n = hts_idx_get_n_no_coor(__pyx_v_self->index); + } - /* "pysam/libcalignmentfile.pyx":1424 - * cdef uint64_t mapped, unmapped - * for tid from 0 <= tid < self.header.n_targets: - * with nogil: # <<<<<<<<<<<<<< - * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) - * total += mapped + /* "pysam/libcalignmentfile.pyx":1790 + * self.check_index() + * cdef uint64_t n + * with nogil: # <<<<<<<<<<<<<< + * n = hts_idx_get_n_no_coor(self.index) + * return n */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L9; - } - __pyx_L9:; + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L5; } - } - - /* "pysam/libcalignmentfile.pyx":1426 - * with nogil: - * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) - * total += mapped # <<<<<<<<<<<<<< - * return total - * - */ - __pyx_v_total = (__pyx_v_total + __pyx_v_mapped); + __pyx_L5:; + } } - /* "pysam/libcalignmentfile.pyx":1427 - * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) - * total += mapped - * return total # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1792 + * with nogil: + * n = hts_idx_get_n_no_coor(self.index) + * return n # <<<<<<<<<<<<<< * - * property unmapped: + * def get_index_statistics(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_total); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1427, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1792, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1418 - * attribute. + /* "pysam/libcalignmentfile.pyx":1787 + * statistics recorded in the index. This is a read-only attribute. * """ * def __get__(self): # <<<<<<<<<<<<<< * self.check_index() - * cdef int tid + * cdef uint64_t n */ /* function exit code */ @@ -16582,7 +21733,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___g __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.mapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.nocoordinate.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -16591,50 +21742,56 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___g return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1434 - * without coordinates. This is a read-only attribute. - * """ - * def __get__(self): # <<<<<<<<<<<<<< - * self.check_index() - * cdef int tid +/* "pysam/libcalignmentfile.pyx":1794 + * return n + * + * def get_index_statistics(self): # <<<<<<<<<<<<<< + * """return statistics about mapped/unmapped reads per chromosome as + * they are stored in the index. */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35get_index_statistics(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics[] = "AlignmentFile.get_index_statistics(self)\nreturn statistics about mapped/unmapped reads per chromosome as\n they are stored in the index.\n\n Returns\n -------\n list : a list of records for each chromosome. Each record has the attributes 'contig',\n 'mapped', 'unmapped' and 'total'.\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35get_index_statistics(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("get_index_statistics (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { int __pyx_v_tid; - uint64_t __pyx_v_total; uint64_t __pyx_v_mapped; uint64_t __pyx_v_unmapped; + PyObject *__pyx_v_results = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - int32_t __pyx_t_4; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1434, 0, __PYX_ERR(0, 1434, __pyx_L1_error)); + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + __Pyx_RefNannySetupContext("get_index_statistics", 0); + __Pyx_TraceCall("get_index_statistics", __pyx_f[0], 1794, 0, __PYX_ERR(0, 1794, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1435 + /* "pysam/libcalignmentfile.pyx":1804 * """ - * def __get__(self): - * self.check_index() # <<<<<<<<<<<<<< - * cdef int tid - * cdef uint64_t total = hts_idx_get_n_no_coor(self.index) + * + * self.check_index() # <<<<<<<<<<<<<< + * cdef int tid + * cdef uint64_t mapped, unmapped */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1435, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1804, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -16647,40 +21804,46 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped__ } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1435, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1804, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1435, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1804, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1437 - * self.check_index() - * cdef int tid - * cdef uint64_t total = hts_idx_get_n_no_coor(self.index) # <<<<<<<<<<<<<< - * cdef uint64_t mapped, unmapped - * for tid from 0 <= tid < self.header.n_targets: + /* "pysam/libcalignmentfile.pyx":1807 + * cdef int tid + * cdef uint64_t mapped, unmapped + * results = [] # <<<<<<<<<<<<<< + * # TODO: use header + * for tid from 0 <= tid < self.nreferences: */ - __pyx_v_total = hts_idx_get_n_no_coor(__pyx_v_self->index); + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1807, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_results = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1439 - * cdef uint64_t total = hts_idx_get_n_no_coor(self.index) - * cdef uint64_t mapped, unmapped - * for tid from 0 <= tid < self.header.n_targets: # <<<<<<<<<<<<<< - * with nogil: - * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + /* "pysam/libcalignmentfile.pyx":1809 + * results = [] + * # TODO: use header + * for tid from 0 <= tid < self.nreferences: # <<<<<<<<<<<<<< + * with nogil: + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) */ - __pyx_t_4 = __pyx_v_self->header->n_targets; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1809, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1809, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_4; __pyx_v_tid++) { - /* "pysam/libcalignmentfile.pyx":1440 - * cdef uint64_t mapped, unmapped - * for tid from 0 <= tid < self.header.n_targets: - * with nogil: # <<<<<<<<<<<<<< - * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) - * total += unmapped + /* "pysam/libcalignmentfile.pyx":1810 + * # TODO: use header + * for tid from 0 <= tid < self.nreferences: + * with nogil: # <<<<<<<<<<<<<< + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + * results.append( */ { #ifdef WITH_THREAD @@ -16690,22 +21853,22 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped__ #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1441 - * for tid from 0 <= tid < self.header.n_targets: - * with nogil: - * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) # <<<<<<<<<<<<<< - * total += unmapped - * return total + /* "pysam/libcalignmentfile.pyx":1811 + * for tid from 0 <= tid < self.nreferences: + * with nogil: + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) # <<<<<<<<<<<<<< + * results.append( + * IndexStats._make(( */ (void)(hts_idx_get_stat(__pyx_v_self->index, __pyx_v_tid, (&__pyx_v_mapped), (&__pyx_v_unmapped))); } - /* "pysam/libcalignmentfile.pyx":1440 - * cdef uint64_t mapped, unmapped - * for tid from 0 <= tid < self.header.n_targets: - * with nogil: # <<<<<<<<<<<<<< - * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) - * total += unmapped + /* "pysam/libcalignmentfile.pyx":1810 + * # TODO: use header + * for tid from 0 <= tid < self.nreferences: + * with nogil: # <<<<<<<<<<<<<< + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + * results.append( */ /*finally:*/ { /*normal exit:*/{ @@ -16719,36 +21882,204 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped__ } } - /* "pysam/libcalignmentfile.pyx":1442 - * with nogil: - * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) - * total += unmapped # <<<<<<<<<<<<<< - * return total - * + /* "pysam/libcalignmentfile.pyx":1813 + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + * results.append( + * IndexStats._make(( # <<<<<<<<<<<<<< + * self.get_reference_name(tid), + * mapped, + */ + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_IndexStats); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1813, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_make); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1813, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libcalignmentfile.pyx":1814 + * results.append( + * IndexStats._make(( + * self.get_reference_name(tid), # <<<<<<<<<<<<<< + * mapped, + * unmapped, + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1814, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1814, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (!__pyx_t_7) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1814, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_6}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1814, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_6}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1814, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1814, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL; + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1814, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pysam/libcalignmentfile.pyx":1815 + * IndexStats._make(( + * self.get_reference_name(tid), + * mapped, # <<<<<<<<<<<<<< + * unmapped, + * mapped + unmapped))) + */ + __pyx_t_5 = __Pyx_PyInt_From_uint64_t(__pyx_v_mapped); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1815, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + + /* "pysam/libcalignmentfile.pyx":1816 + * self.get_reference_name(tid), + * mapped, + * unmapped, # <<<<<<<<<<<<<< + * mapped + unmapped))) + * + */ + __pyx_t_8 = __Pyx_PyInt_From_uint64_t(__pyx_v_unmapped); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1816, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + + /* "pysam/libcalignmentfile.pyx":1817 + * mapped, + * unmapped, + * mapped + unmapped))) # <<<<<<<<<<<<<< + * + * return results + */ + __pyx_t_6 = __Pyx_PyInt_From_uint64_t((__pyx_v_mapped + __pyx_v_unmapped)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1817, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + + /* "pysam/libcalignmentfile.pyx":1814 + * results.append( + * IndexStats._make(( + * self.get_reference_name(tid), # <<<<<<<<<<<<<< + * mapped, + * unmapped, + */ + __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1814, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_t_6); + __pyx_t_2 = 0; + __pyx_t_5 = 0; + __pyx_t_8 = 0; + __pyx_t_6 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_6) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1813, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_7}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1813, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_7}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1813, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1813, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1813, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libcalignmentfile.pyx":1812 + * with nogil: + * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + * results.append( # <<<<<<<<<<<<<< + * IndexStats._make(( + * self.get_reference_name(tid), */ - __pyx_v_total = (__pyx_v_total + __pyx_v_unmapped); + __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_results, __pyx_t_1); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 1812, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - /* "pysam/libcalignmentfile.pyx":1443 - * hts_idx_get_stat(self.index, tid, &mapped, &unmapped) - * total += unmapped - * return total # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1819 + * mapped + unmapped))) * - * property nocoordinate: + * return results # <<<<<<<<<<<<<< + * + * ############################################################### */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_total); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1443, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __Pyx_INCREF(__pyx_v_results); + __pyx_r = __pyx_v_results; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1434 - * without coordinates. This is a read-only attribute. - * """ - * def __get__(self): # <<<<<<<<<<<<<< - * self.check_index() - * cdef int tid + /* "pysam/libcalignmentfile.pyx":1794 + * return n + * + * def get_index_statistics(self): # <<<<<<<<<<<<<< + * """return statistics about mapped/unmapped reads per chromosome as + * they are stored in the index. */ /* function exit code */ @@ -16756,148 +22087,164 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped__ __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_index_statistics", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_results); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1449 - * statistics recorded in the index. This is a read-only attribute. - * """ - * def __get__(self): # <<<<<<<<<<<<<< - * self.check_index() - * cdef uint64_t n +/* "pysam/libcalignmentfile.pyx":1826 + * ## and multiple_iterators) + * ## Possible solutions: deprecate or open new file handle + * def __iter__(self): # <<<<<<<<<<<<<< + * if not self.is_open: + * raise ValueError("I/O operation on closed file") */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { - uint64_t __pyx_v_n; +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1449, 0, __PYX_ERR(0, 1449, __pyx_L1_error)); + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__iter__", 0); + __Pyx_TraceCall("__iter__", __pyx_f[0], 1826, 0, __PYX_ERR(0, 1826, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1450 - * """ - * def __get__(self): - * self.check_index() # <<<<<<<<<<<<<< - * cdef uint64_t n - * with nogil: + /* "pysam/libcalignmentfile.pyx":1827 + * ## Possible solutions: deprecate or open new file handle + * def __iter__(self): + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError("I/O operation on closed file") + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1827, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1827, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = ((!__pyx_t_2) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcalignmentfile.pyx":1828 + * def __iter__(self): + * if not self.is_open: + * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< + * + * if not self.is_bam and self.header.nreferences == 0: + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__50, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1828, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 1828, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1827 + * ## Possible solutions: deprecate or open new file handle + * def __iter__(self): + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError("I/O operation on closed file") + * */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1450, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1450, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libcalignmentfile.pyx":1830 + * raise ValueError("I/O operation on closed file") + * + * if not self.is_bam and self.header.nreferences == 0: # <<<<<<<<<<<<<< + * raise NotImplementedError( + * "can not iterate over samfile without header") + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1830, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1830, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = ((!__pyx_t_2) != 0); + if (__pyx_t_4) { } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1450, __pyx_L1_error) + __pyx_t_3 = __pyx_t_4; + goto __pyx_L5_bool_binop_done; } + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1830, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_5 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1830, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1830, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __pyx_t_4; + __pyx_L5_bool_binop_done:; + if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":1452 - * self.check_index() - * cdef uint64_t n - * with nogil: # <<<<<<<<<<<<<< - * n = hts_idx_get_n_no_coor(self.index) - * return n - */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { - - /* "pysam/libcalignmentfile.pyx":1453 - * cdef uint64_t n - * with nogil: - * n = hts_idx_get_n_no_coor(self.index) # <<<<<<<<<<<<<< - * return n + /* "pysam/libcalignmentfile.pyx":1831 * + * if not self.is_bam and self.header.nreferences == 0: + * raise NotImplementedError( # <<<<<<<<<<<<<< + * "can not iterate over samfile without header") + * return self */ - __pyx_v_n = hts_idx_get_n_no_coor(__pyx_v_self->index); - } + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__51, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1831, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 1831, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1452 - * self.check_index() - * cdef uint64_t n - * with nogil: # <<<<<<<<<<<<<< - * n = hts_idx_get_n_no_coor(self.index) - * return n + /* "pysam/libcalignmentfile.pyx":1830 + * raise ValueError("I/O operation on closed file") + * + * if not self.is_bam and self.header.nreferences == 0: # <<<<<<<<<<<<<< + * raise NotImplementedError( + * "can not iterate over samfile without header") */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L5; - } - __pyx_L5:; - } } - /* "pysam/libcalignmentfile.pyx":1454 - * with nogil: - * n = hts_idx_get_n_no_coor(self.index) - * return n # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1833 + * raise NotImplementedError( + * "can not iterate over samfile without header") + * return self # <<<<<<<<<<<<<< * - * property text: + * cdef bam1_t * getCurrent(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1449 - * statistics recorded in the index. This is a read-only attribute. - * """ - * def __get__(self): # <<<<<<<<<<<<<< - * self.check_index() - * cdef uint64_t n + /* "pysam/libcalignmentfile.pyx":1826 + * ## and multiple_iterators) + * ## Possible solutions: deprecate or open new file handle + * def __iter__(self): # <<<<<<<<<<<<<< + * if not self.is_open: + * raise ValueError("I/O operation on closed file") */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.nocoordinate.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -16906,1481 +22253,1088 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordin return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1465 - * representation of the header. - * ''' - * def __get__(self): # <<<<<<<<<<<<<< - * if not self.is_open: - * raise ValueError( "I/O operation on closed file" ) +/* "pysam/libcalignmentfile.pyx":1835 + * return self + * + * cdef bam1_t * getCurrent(self): # <<<<<<<<<<<<<< + * return self.b + * */ -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_4text_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_4text_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static bam1_t *__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { + bam1_t *__pyx_r; + __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4text___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("getCurrent", 0); + __Pyx_TraceCall("getCurrent", __pyx_f[0], 1835, 0, __PYX_ERR(0, 1835, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":1836 + * + * cdef bam1_t * getCurrent(self): + * return self.b # <<<<<<<<<<<<<< + * + * cdef int cnext(self): + */ + __pyx_r = __pyx_v_self->b; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":1835 + * return self + * + * cdef bam1_t * getCurrent(self): # <<<<<<<<<<<<<< + * return self.b + * + */ /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("pysam.libcalignmentfile.AlignmentFile.getCurrent", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4text___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1465, 0, __PYX_ERR(0, 1465, __pyx_L1_error)); +/* "pysam/libcalignmentfile.pyx":1838 + * return self.b + * + * cdef int cnext(self): # <<<<<<<<<<<<<< + * ''' + * cversion of iterator. Used by :class:`pysam.AlignmentFile.IteratorColumn`. + */ + +static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { + int __pyx_v_ret; + bam_hdr_t *__pyx_v_hdr; + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + bam_hdr_t *__pyx_t_1; + __Pyx_RefNannySetupContext("cnext", 0); + __Pyx_TraceCall("cnext", __pyx_f[0], 1838, 0, __PYX_ERR(0, 1838, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1466 + /* "pysam/libcalignmentfile.pyx":1843 * ''' - * def __get__(self): - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError( "I/O operation on closed file" ) - * return from_string_and_size(self.header.text, self.header.l_text) + * cdef int ret + * cdef bam_hdr_t * hdr = self.header.ptr # <<<<<<<<<<<<<< + * with nogil: + * ret = sam_read1(self.htsfile, */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1466, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1466, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { + __pyx_t_1 = __pyx_v_self->header->ptr; + __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcalignmentfile.pyx":1467 - * def __get__(self): - * if not self.is_open: - * raise ValueError( "I/O operation on closed file" ) # <<<<<<<<<<<<<< - * return from_string_and_size(self.header.text, self.header.l_text) - * + /* "pysam/libcalignmentfile.pyx":1844 + * cdef int ret + * cdef bam_hdr_t * hdr = self.header.ptr + * with nogil: # <<<<<<<<<<<<<< + * ret = sam_read1(self.htsfile, + * hdr, */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1467, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1467, __pyx_L1_error) + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1466 - * ''' - * def __get__(self): - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError( "I/O operation on closed file" ) - * return from_string_and_size(self.header.text, self.header.l_text) + /* "pysam/libcalignmentfile.pyx":1845 + * cdef bam_hdr_t * hdr = self.header.ptr + * with nogil: + * ret = sam_read1(self.htsfile, # <<<<<<<<<<<<<< + * hdr, + * self.b) */ + __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr, __pyx_v_self->b); + } + + /* "pysam/libcalignmentfile.pyx":1844 + * cdef int ret + * cdef bam_hdr_t * hdr = self.header.ptr + * with nogil: # <<<<<<<<<<<<<< + * ret = sam_read1(self.htsfile, + * hdr, + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L5; + } + __pyx_L5:; + } } - /* "pysam/libcalignmentfile.pyx":1468 - * if not self.is_open: - * raise ValueError( "I/O operation on closed file" ) - * return from_string_and_size(self.header.text, self.header.l_text) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1848 + * hdr, + * self.b) + * return ret # <<<<<<<<<<<<<< * - * property header: + * def __next__(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_9libcutils_from_string_and_size(__pyx_v_self->header->text, __pyx_v_self->header->l_text); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1468, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1465 - * representation of the header. + /* "pysam/libcalignmentfile.pyx":1838 + * return self.b + * + * cdef int cnext(self): # <<<<<<<<<<<<<< * ''' - * def __get__(self): # <<<<<<<<<<<<<< - * if not self.is_open: - * raise ValueError( "I/O operation on closed file" ) + * cversion of iterator. Used by :class:`pysam.AlignmentFile.IteratorColumn`. */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.text.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_WriteUnraisable("pysam.libcalignmentfile.AlignmentFile.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1492 +/* "pysam/libcalignmentfile.pyx":1850 + * return ret * - * """ - * def __get__(self): # <<<<<<<<<<<<<< - * if not self.is_open: - * raise ValueError( "I/O operation on closed file" ) + * def __next__(self): # <<<<<<<<<<<<<< + * cdef int ret = self.cnext() + * if (ret >= 0): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6header_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6header___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__next__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6header___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_t = NULL; - PyObject *__pyx_v_line = NULL; - PyObject *__pyx_v_fields = NULL; - PyObject *__pyx_v_record = NULL; - PyObject *__pyx_v_x = NULL; - PyObject *__pyx_v_idx = NULL; - PyObject *__pyx_v_field = NULL; - PyObject *__pyx_v_key = NULL; - PyObject *__pyx_v_value = NULL; - PyObject *__pyx_v_sq = NULL; - PyObject *__pyx_v_ref = NULL; - PyObject *__pyx_v_length = NULL; +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__next__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { + int __pyx_v_ret; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - Py_ssize_t __pyx_t_5; - PyObject *(*__pyx_t_6)(PyObject *); - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; - Py_ssize_t __pyx_t_10; - PyObject *(*__pyx_t_11)(PyObject *); - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - PyObject *(*__pyx_t_15)(PyObject *); - int __pyx_t_16; - PyObject *__pyx_t_17 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1492, 0, __PYX_ERR(0, 1492, __pyx_L1_error)); - - /* "pysam/libcalignmentfile.pyx":1493 - * """ - * def __get__(self): - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError( "I/O operation on closed file" ) - * - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1493, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1493, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { - - /* "pysam/libcalignmentfile.pyx":1494 - * def __get__(self): - * if not self.is_open: - * raise ValueError( "I/O operation on closed file" ) # <<<<<<<<<<<<<< - * - * result = {} - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1494, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1494, __pyx_L1_error) - - /* "pysam/libcalignmentfile.pyx":1493 - * """ - * def __get__(self): - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError( "I/O operation on closed file" ) - * - */ - } - - /* "pysam/libcalignmentfile.pyx":1496 - * raise ValueError( "I/O operation on closed file" ) - * - * result = {} # <<<<<<<<<<<<<< - * - * if self.header.text != NULL: - */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1496, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_result = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__next__", 0); + __Pyx_TraceCall("__next__", __pyx_f[0], 1850, 0, __PYX_ERR(0, 1850, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1498 - * result = {} + /* "pysam/libcalignmentfile.pyx":1851 * - * if self.header.text != NULL: # <<<<<<<<<<<<<< - * # convert to python string (note: call self.text to - * # create 0-terminated string) - */ - __pyx_t_3 = ((__pyx_v_self->header->text != NULL) != 0); - if (__pyx_t_3) { - - /* "pysam/libcalignmentfile.pyx":1501 - * # convert to python string (note: call self.text to - * # create 0-terminated string) - * t = self.text # <<<<<<<<<<<<<< - * for line in t.split("\n"): - * if not line.strip(): continue - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_text); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_t = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pysam/libcalignmentfile.pyx":1502 - * # create 0-terminated string) - * t = self.text - * for line in t.split("\n"): # <<<<<<<<<<<<<< - * if not line.strip(): continue - * assert line.startswith("@"), \ + * def __next__(self): + * cdef int ret = self.cnext() # <<<<<<<<<<<<<< + * if (ret >= 0): + * return makeAlignedSegment(self.b, self.header) */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_split); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_1 = __pyx_t_4; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; - __pyx_t_6 = NULL; - } else { - __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1502, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (likely(!__pyx_t_6)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1502, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1502, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_6(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1502, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_4); - __pyx_t_4 = 0; + __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->cnext(__pyx_v_self); - /* "pysam/libcalignmentfile.pyx":1503 - * t = self.text - * for line in t.split("\n"): - * if not line.strip(): continue # <<<<<<<<<<<<<< - * assert line.startswith("@"), \ - * "header line without '@': '%s'" % line + /* "pysam/libcalignmentfile.pyx":1852 + * def __next__(self): + * cdef int ret = self.cnext() + * if (ret >= 0): # <<<<<<<<<<<<<< + * return makeAlignedSegment(self.b, self.header) + * elif ret == -2: */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_strip); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - if (__pyx_t_8) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1503, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } else { - __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1503, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1503, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_2 = ((!__pyx_t_3) != 0); - if (__pyx_t_2) { - goto __pyx_L5_continue; - } + __pyx_t_1 = ((__pyx_v_ret >= 0) != 0); + if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1504 - * for line in t.split("\n"): - * if not line.strip(): continue - * assert line.startswith("@"), \ # <<<<<<<<<<<<<< - * "header line without '@': '%s'" % line - * fields = line[1:].split("\t") + /* "pysam/libcalignmentfile.pyx":1853 + * cdef int ret = self.cnext() + * if (ret >= 0): + * return makeAlignedSegment(self.b, self.header) # <<<<<<<<<<<<<< + * elif ret == -2: + * raise IOError('truncated file') */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_startswith); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1504, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1504, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1504, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!__pyx_t_2)) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = ((PyObject *)__pyx_v_self->header); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1853, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1505 - * if not line.strip(): continue - * assert line.startswith("@"), \ - * "header line without '@': '%s'" % line # <<<<<<<<<<<<<< - * fields = line[1:].split("\t") - * record = fields[0] + /* "pysam/libcalignmentfile.pyx":1852 + * def __next__(self): + * cdef int ret = self.cnext() + * if (ret >= 0): # <<<<<<<<<<<<<< + * return makeAlignedSegment(self.b, self.header) + * elif ret == -2: */ - __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_header_line_without_s, __pyx_v_line); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1505, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - PyErr_SetObject(PyExc_AssertionError, __pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __PYX_ERR(0, 1504, __pyx_L1_error) - } - } - #endif + } - /* "pysam/libcalignmentfile.pyx":1506 - * assert line.startswith("@"), \ - * "header line without '@': '%s'" % line - * fields = line[1:].split("\t") # <<<<<<<<<<<<<< - * record = fields[0] - * assert record in VALID_HEADER_TYPES, \ + /* "pysam/libcalignmentfile.pyx":1854 + * if (ret >= 0): + * return makeAlignedSegment(self.b, self.header) + * elif ret == -2: # <<<<<<<<<<<<<< + * raise IOError('truncated file') + * else: */ - __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_v_line, 1, 0, NULL, NULL, &__pyx_slice__37, 1, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_split); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_7); - __pyx_t_7 = 0; + __pyx_t_1 = ((__pyx_v_ret == -2L) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":1507 - * "header line without '@': '%s'" % line - * fields = line[1:].split("\t") - * record = fields[0] # <<<<<<<<<<<<<< - * assert record in VALID_HEADER_TYPES, \ - * "header line with invalid type '%s': '%s'" % (record, line) + /* "pysam/libcalignmentfile.pyx":1855 + * return makeAlignedSegment(self.b, self.header) + * elif ret == -2: + * raise IOError('truncated file') # <<<<<<<<<<<<<< + * else: + * raise StopIteration */ - __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_fields, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_7); - __pyx_t_7 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1855, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 1855, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1508 - * fields = line[1:].split("\t") - * record = fields[0] - * assert record in VALID_HEADER_TYPES, \ # <<<<<<<<<<<<<< - * "header line with invalid type '%s': '%s'" % (record, line) - * + /* "pysam/libcalignmentfile.pyx":1854 + * if (ret >= 0): + * return makeAlignedSegment(self.b, self.header) + * elif ret == -2: # <<<<<<<<<<<<<< + * raise IOError('truncated file') + * else: */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1508, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_t_7, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1508, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(!(__pyx_t_2 != 0))) { + } - /* "pysam/libcalignmentfile.pyx":1509 - * record = fields[0] - * assert record in VALID_HEADER_TYPES, \ - * "header line with invalid type '%s': '%s'" % (record, line) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1857 + * raise IOError('truncated file') + * else: + * raise StopIteration # <<<<<<<<<<<<<< * - * # treat comments + * ########################################### */ - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1509, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_v_record); - __Pyx_GIVEREF(__pyx_v_record); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_record); - __Pyx_INCREF(__pyx_v_line); - __Pyx_GIVEREF(__pyx_v_line); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_line); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_header_line_with_invalid_type_s, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1509, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - PyErr_SetObject(PyExc_AssertionError, __pyx_t_4); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1508, __pyx_L1_error) - } - } - #endif + /*else*/ { + __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); + __PYX_ERR(0, 1857, __pyx_L1_error) + } - /* "pysam/libcalignmentfile.pyx":1512 + /* "pysam/libcalignmentfile.pyx":1850 + * return ret * - * # treat comments - * if record == "CO": # <<<<<<<<<<<<<< - * if record not in result: - * result[record] = [] + * def __next__(self): # <<<<<<<<<<<<<< + * cdef int ret = self.cnext() + * if (ret >= 0): */ - __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_record, __pyx_n_s_CO, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1512, __pyx_L1_error) - if (__pyx_t_2) { - /* "pysam/libcalignmentfile.pyx":1513 - * # treat comments - * if record == "CO": - * if record not in result: # <<<<<<<<<<<<<< - * result[record] = [] - * result[record].append("\t".join( fields[1:])) - */ - __pyx_t_2 = (__Pyx_PyDict_ContainsTF(__pyx_v_record, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1513, __pyx_L1_error) - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignmentfile.pyx":1514 - * if record == "CO": - * if record not in result: - * result[record] = [] # <<<<<<<<<<<<<< - * result[record].append("\t".join( fields[1:])) - * continue +/* "pysam/libcalignmentfile.pyx":1861 + * ########################################### + * # methods/properties referencing the header + * def is_valid_tid(self, int tid): # <<<<<<<<<<<<<< + * """ + * return True if the numerical :term:`tid` is valid; False otherwise. */ - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1514, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_v_record, __pyx_t_4) < 0)) __PYX_ERR(0, 1514, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":1513 - * # treat comments - * if record == "CO": - * if record not in result: # <<<<<<<<<<<<<< - * result[record] = [] - * result[record].append("\t".join( fields[1:])) - */ - } +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41is_valid_tid(PyObject *__pyx_v_self, PyObject *__pyx_arg_tid); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid[] = "AlignmentFile.is_valid_tid(self, int tid)\n\n return True if the numerical :term:`tid` is valid; False otherwise.\n\n Note that the unmapped tid code (-1) counts as an invalid.\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41is_valid_tid(PyObject *__pyx_v_self, PyObject *__pyx_arg_tid) { + int __pyx_v_tid; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_valid_tid (wrapper)", 0); + assert(__pyx_arg_tid); { + __pyx_v_tid = __Pyx_PyInt_As_int(__pyx_arg_tid); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1861, __pyx_L3_error) + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((int)__pyx_v_tid)); - /* "pysam/libcalignmentfile.pyx":1515 - * if record not in result: - * result[record] = [] - * result[record].append("\t".join( fields[1:])) # <<<<<<<<<<<<<< - * continue - * # the following is clumsy as generators do not work? - */ - __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_result, __pyx_v_record); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1515, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 1, 0, NULL, NULL, &__pyx_slice__39, 1, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1515, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1515, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_4, __pyx_t_8); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 1515, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignmentfile.pyx":1516 - * result[record] = [] - * result[record].append("\t".join( fields[1:])) - * continue # <<<<<<<<<<<<<< - * # the following is clumsy as generators do not work? - * x = {} - */ - goto __pyx_L5_continue; +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, int __pyx_v_tid) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("is_valid_tid", 0); + __Pyx_TraceCall("is_valid_tid", __pyx_f[0], 1861, 0, __PYX_ERR(0, 1861, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1512 - * - * # treat comments - * if record == "CO": # <<<<<<<<<<<<<< - * if record not in result: - * result[record] = [] + /* "pysam/libcalignmentfile.pyx":1867 + * Note that the unmapped tid code (-1) counts as an invalid. + * """ + * if self.header is None: # <<<<<<<<<<<<<< + * raise ValueError("header not available in closed files") + * return self.header.is_valid_tid(tid) */ - } + __pyx_t_1 = (((PyObject *)__pyx_v_self->header) == Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcalignmentfile.pyx":1518 - * continue - * # the following is clumsy as generators do not work? - * x = {} # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1868 + * """ + * if self.header is None: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< + * return self.header.is_valid_tid(tid) * - * for idx, field in enumerate(fields[1:]): */ - __pyx_t_8 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1518, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_XDECREF_SET(__pyx_v_x, ((PyObject*)__pyx_t_8)); - __pyx_t_8 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__53, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1868, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 1868, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1520 - * x = {} - * - * for idx, field in enumerate(fields[1:]): # <<<<<<<<<<<<<< - * if ":" not in field: - * raise ValueError("malformatted header: no ':' in field" ) + /* "pysam/libcalignmentfile.pyx":1867 + * Note that the unmapped tid code (-1) counts as an invalid. + * """ + * if self.header is None: # <<<<<<<<<<<<<< + * raise ValueError("header not available in closed files") + * return self.header.is_valid_tid(tid) */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_8 = __pyx_int_0; - __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 1, 0, NULL, NULL, &__pyx_slice__40, 1, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1520, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_7 = __pyx_t_4; __Pyx_INCREF(__pyx_t_7); __pyx_t_10 = 0; - __pyx_t_11 = NULL; - } else { - __pyx_t_10 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1520, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1520, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (likely(!__pyx_t_11)) { - if (likely(PyList_CheckExact(__pyx_t_7))) { - if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_10); __Pyx_INCREF(__pyx_t_4); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 1520, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1520, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_7)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_10); __Pyx_INCREF(__pyx_t_4); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 1520, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_7, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1520, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_11(__pyx_t_7); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1520, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF_SET(__pyx_v_field, __pyx_t_4); - __pyx_t_4 = 0; - __Pyx_INCREF(__pyx_t_8); - __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_8); - __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_8, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1520, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); - __pyx_t_8 = __pyx_t_4; - __pyx_t_4 = 0; + } - /* "pysam/libcalignmentfile.pyx":1521 + /* "pysam/libcalignmentfile.pyx":1869 + * if self.header is None: + * raise ValueError("header not available in closed files") + * return self.header.is_valid_tid(tid) # <<<<<<<<<<<<<< * - * for idx, field in enumerate(fields[1:]): - * if ":" not in field: # <<<<<<<<<<<<<< - * raise ValueError("malformatted header: no ':' in field" ) - * key, value = field.split(":", 1) + * def get_tid(self, reference): */ - __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_kp_s__41, __pyx_v_field, Py_NE)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1521, __pyx_L1_error) - __pyx_t_2 = (__pyx_t_3 != 0); - if (unlikely(__pyx_t_2)) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_is_valid_tid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1869, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1869, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1869, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1869, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1869, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1869, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1869, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1522 - * for idx, field in enumerate(fields[1:]): - * if ":" not in field: - * raise ValueError("malformatted header: no ':' in field" ) # <<<<<<<<<<<<<< - * key, value = field.split(":", 1) - * if key in ("CL",): + /* "pysam/libcalignmentfile.pyx":1861 + * ########################################### + * # methods/properties referencing the header + * def is_valid_tid(self, int tid): # <<<<<<<<<<<<<< + * """ + * return True if the numerical :term:`tid` is valid; False otherwise. */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1522, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1522, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1521 + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":1871 + * return self.header.is_valid_tid(tid) * - * for idx, field in enumerate(fields[1:]): - * if ":" not in field: # <<<<<<<<<<<<<< - * raise ValueError("malformatted header: no ':' in field" ) - * key, value = field.split(":", 1) + * def get_tid(self, reference): # <<<<<<<<<<<<<< + * """ + * return the numerical :term:`tid` corresponding to */ - } - /* "pysam/libcalignmentfile.pyx":1523 - * if ":" not in field: - * raise ValueError("malformatted header: no ':' in field" ) - * key, value = field.split(":", 1) # <<<<<<<<<<<<<< - * if key in ("CL",): - * # special treatment for command line - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_field, __pyx_n_s_split); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) { - PyObject* sequence = __pyx_t_12; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 1523, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_13 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_4 = PyList_GET_ITEM(sequence, 0); - __pyx_t_13 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_13); - #else - __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_13 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - #endif - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_14 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext; - index = 0; __pyx_t_4 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_4)) goto __pyx_L13_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - index = 1; __pyx_t_13 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_13)) goto __pyx_L13_unpacking_failed; - __Pyx_GOTREF(__pyx_t_13); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) __PYX_ERR(0, 1523, __pyx_L1_error) - __pyx_t_15 = NULL; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - goto __pyx_L14_unpacking_done; - __pyx_L13_unpacking_failed:; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_15 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1523, __pyx_L1_error) - __pyx_L14_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_4); - __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_13); - __pyx_t_13 = 0; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid[] = "AlignmentFile.get_tid(self, reference)\n\n return the numerical :term:`tid` corresponding to\n :term:`reference`\n\n returns -1 if reference is not known.\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_tid (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_reference)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannySetupContext("get_tid", 0); + __Pyx_TraceCall("get_tid", __pyx_f[0], 1871, 0, __PYX_ERR(0, 1871, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":1878 + * returns -1 if reference is not known. + * """ + * if self.header is None: # <<<<<<<<<<<<<< + * raise ValueError("header not available in closed files") + * return self.header.get_tid(reference) + */ + __pyx_t_1 = (((PyObject *)__pyx_v_self->header) == Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcalignmentfile.pyx":1524 - * raise ValueError("malformatted header: no ':' in field" ) - * key, value = field.split(":", 1) - * if key in ("CL",): # <<<<<<<<<<<<<< - * # special treatment for command line - * # statements (CL). These might contain + /* "pysam/libcalignmentfile.pyx":1879 + * """ + * if self.header is None: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< + * return self.header.get_tid(reference) + * */ - __Pyx_INCREF(__pyx_v_key); - __pyx_t_12 = __pyx_v_key; - __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_12, __pyx_n_s_CL, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1524, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1879, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 1879, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1531 - * # header. Thus, in contravention to the - * # SAM API, consume the rest of the line. - * key, value = "\t".join(fields[idx+1:]).split(":", 1) # <<<<<<<<<<<<<< - * x[key] = KNOWN_HEADER_FIELDS[record][key](value) - * break + /* "pysam/libcalignmentfile.pyx":1878 + * returns -1 if reference is not known. + * """ + * if self.header is None: # <<<<<<<<<<<<<< + * raise ValueError("header not available in closed files") + * return self.header.get_tid(reference) */ - __pyx_t_12 = __Pyx_PyInt_AddObjC(__pyx_v_idx, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 0, 0, &__pyx_t_12, NULL, NULL, 0, 0, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_t_13); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_split); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) { - PyObject* sequence = __pyx_t_12; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 1531, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_13 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_13 = PyList_GET_ITEM(sequence, 0); - __pyx_t_4 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(__pyx_t_4); - #else - __pyx_t_13 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_14 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext; - index = 0; __pyx_t_13 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_13)) goto __pyx_L16_unpacking_failed; - __Pyx_GOTREF(__pyx_t_13); - index = 1; __pyx_t_4 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_4)) goto __pyx_L16_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) __PYX_ERR(0, 1531, __pyx_L1_error) - __pyx_t_15 = NULL; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - goto __pyx_L17_unpacking_done; - __pyx_L16_unpacking_failed:; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_15 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1531, __pyx_L1_error) - __pyx_L17_unpacking_done:; - } - __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_13); - __pyx_t_13 = 0; - __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_4); - __pyx_t_4 = 0; + } - /* "pysam/libcalignmentfile.pyx":1532 - * # SAM API, consume the rest of the line. - * key, value = "\t".join(fields[idx+1:]).split(":", 1) - * x[key] = KNOWN_HEADER_FIELDS[record][key](value) # <<<<<<<<<<<<<< - * break + /* "pysam/libcalignmentfile.pyx":1880 + * if self.header is None: + * raise ValueError("header not available in closed files") + * return self.header.get_tid(reference) # <<<<<<<<<<<<<< * + * def get_reference_name(self, tid): */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_KNOWN_HEADER_FIELDS); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1532, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_13 = __Pyx_PyObject_GetItem(__pyx_t_4, __pyx_v_record); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1532, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_13, __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1532, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (!__pyx_t_13) { - __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_value); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1532, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_13, __pyx_v_value}; - __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1532, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_GOTREF(__pyx_t_12); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_13, __pyx_v_value}; - __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1532, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_GOTREF(__pyx_t_12); - } else - #endif - { - __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1532, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_13); __pyx_t_13 = NULL; - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_v_value); - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_14, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1532, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_t_12) < 0)) __PYX_ERR(0, 1532, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_5) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_reference); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_reference}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1880, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_reference}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1880, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_reference); + __Pyx_GIVEREF(__pyx_v_reference); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_reference); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1533 - * key, value = "\t".join(fields[idx+1:]).split(":", 1) - * x[key] = KNOWN_HEADER_FIELDS[record][key](value) - * break # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1871 + * return self.header.is_valid_tid(tid) * - * # interpret type of known header record tags, default to str + * def get_tid(self, reference): # <<<<<<<<<<<<<< + * """ + * return the numerical :term:`tid` corresponding to */ - goto __pyx_L11_break; - /* "pysam/libcalignmentfile.pyx":1524 - * raise ValueError("malformatted header: no ':' in field" ) - * key, value = field.split(":", 1) - * if key in ("CL",): # <<<<<<<<<<<<<< - * # special treatment for command line - * # statements (CL). These might contain - */ - } + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_tid", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignmentfile.pyx":1536 +/* "pysam/libcalignmentfile.pyx":1882 + * return self.header.get_tid(reference) * - * # interpret type of known header record tags, default to str - * x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value) # <<<<<<<<<<<<<< - * - * if VALID_HEADER_TYPES[record] == dict: + * def get_reference_name(self, tid): # <<<<<<<<<<<<<< + * """ + * return :term:`reference` name corresponding to numerical :term:`tid` */ - __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_KNOWN_HEADER_FIELDS); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_13 = __Pyx_PyObject_GetItem(__pyx_t_14, __pyx_v_record); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_get); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = NULL; - __pyx_t_16 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { - __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_14); - if (likely(__pyx_t_13)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_14, function); - __pyx_t_16 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_key, ((PyObject *)(&PyString_Type))}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { - PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_key, ((PyObject *)(&PyString_Type))}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else - #endif - { - __pyx_t_17 = PyTuple_New(2+__pyx_t_16); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_17); - if (__pyx_t_13) { - __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_13); __pyx_t_13 = NULL; - } - __Pyx_INCREF(__pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_16, __pyx_v_key); - __Pyx_INCREF(((PyObject *)(&PyString_Type))); - __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_16, ((PyObject *)(&PyString_Type))); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_17, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_14)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (!__pyx_t_14) { - __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_value); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_14, __pyx_v_value}; - __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_GOTREF(__pyx_t_12); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_14, __pyx_v_value}; - __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_GOTREF(__pyx_t_12); - } else - #endif - { - __pyx_t_17 = PyTuple_New(1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_17); - __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_14); __pyx_t_14 = NULL; - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_17, 0+1, __pyx_v_value); - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_17, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - } - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_t_12) < 0)) __PYX_ERR(0, 1536, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - /* "pysam/libcalignmentfile.pyx":1520 - * x = {} +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name[] = "AlignmentFile.get_reference_name(self, tid)\n\n return :term:`reference` name corresponding to numerical :term:`tid`\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_reference_name (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_tid)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannySetupContext("get_reference_name", 0); + __Pyx_TraceCall("get_reference_name", __pyx_f[0], 1882, 0, __PYX_ERR(0, 1882, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":1886 + * return :term:`reference` name corresponding to numerical :term:`tid` + * """ + * if self.header is None: # <<<<<<<<<<<<<< + * raise ValueError("header not available in closed files") + * return self.header.get_reference_name(tid) + */ + __pyx_t_1 = (((PyObject *)__pyx_v_self->header) == Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (unlikely(__pyx_t_2)) { + + /* "pysam/libcalignmentfile.pyx":1887 + * """ + * if self.header is None: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< + * return self.header.get_reference_name(tid) * - * for idx, field in enumerate(fields[1:]): # <<<<<<<<<<<<<< - * if ":" not in field: - * raise ValueError("malformatted header: no ':' in field" ) */ - } - __pyx_L11_break:; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__55, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 1887, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":1886 + * return :term:`reference` name corresponding to numerical :term:`tid` + * """ + * if self.header is None: # <<<<<<<<<<<<<< + * raise ValueError("header not available in closed files") + * return self.header.get_reference_name(tid) + */ + } - /* "pysam/libcalignmentfile.pyx":1538 - * x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value) + /* "pysam/libcalignmentfile.pyx":1888 + * if self.header is None: + * raise ValueError("header not available in closed files") + * return self.header.get_reference_name(tid) # <<<<<<<<<<<<<< * - * if VALID_HEADER_TYPES[record] == dict: # <<<<<<<<<<<<<< - * if record in result: - * raise ValueError( + * def get_reference_length(self, reference): */ - __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1538, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_v_record); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1538, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyObject_RichCompare(__pyx_t_7, ((PyObject *)(&PyDict_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1538, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1538, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__pyx_t_3) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_5) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_tid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_tid}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1888, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_tid}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1888, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_tid); + __Pyx_GIVEREF(__pyx_v_tid); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_tid); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1539 + /* "pysam/libcalignmentfile.pyx":1882 + * return self.header.get_tid(reference) * - * if VALID_HEADER_TYPES[record] == dict: - * if record in result: # <<<<<<<<<<<<<< - * raise ValueError( - * "multiple '%s' lines are not permitted" % record) + * def get_reference_name(self, tid): # <<<<<<<<<<<<<< + * """ + * return :term:`reference` name corresponding to numerical :term:`tid` */ - __pyx_t_3 = (__Pyx_PyDict_ContainsTF(__pyx_v_record, __pyx_v_result, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1539, __pyx_L1_error) - __pyx_t_2 = (__pyx_t_3 != 0); - if (unlikely(__pyx_t_2)) { - /* "pysam/libcalignmentfile.pyx":1541 - * if record in result: - * raise ValueError( - * "multiple '%s' lines are not permitted" % record) # <<<<<<<<<<<<<< - * - * result[record] = x - */ - __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_multiple_s_lines_are_not_permitt, __pyx_v_record); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1541, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_reference_name", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignmentfile.pyx":1540 - * if VALID_HEADER_TYPES[record] == dict: - * if record in result: - * raise ValueError( # <<<<<<<<<<<<<< - * "multiple '%s' lines are not permitted" % record) +/* "pysam/libcalignmentfile.pyx":1890 + * return self.header.get_reference_name(tid) * + * def get_reference_length(self, reference): # <<<<<<<<<<<<<< + * """ + * return :term:`reference` name corresponding to numerical :term:`tid` */ - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1540, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_Raise(__pyx_t_7, 0, 0, 0); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __PYX_ERR(0, 1540, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1539 - * - * if VALID_HEADER_TYPES[record] == dict: - * if record in result: # <<<<<<<<<<<<<< - * raise ValueError( - * "multiple '%s' lines are not permitted" % record) - */ - } +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47get_reference_length(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length[] = "AlignmentFile.get_reference_length(self, reference)\n\n return :term:`reference` name corresponding to numerical :term:`tid`\n "; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47get_reference_length(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_reference_length (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_reference)); - /* "pysam/libcalignmentfile.pyx":1543 - * "multiple '%s' lines are not permitted" % record) - * - * result[record] = x # <<<<<<<<<<<<<< - * elif VALID_HEADER_TYPES[record] == list: - * if record not in result: result[record] = [] - */ - if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_v_record, __pyx_v_x) < 0)) __PYX_ERR(0, 1543, __pyx_L1_error) + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignmentfile.pyx":1538 - * x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value) - * - * if VALID_HEADER_TYPES[record] == dict: # <<<<<<<<<<<<<< - * if record in result: - * raise ValueError( - */ - goto __pyx_L18; - } +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannySetupContext("get_reference_length", 0); + __Pyx_TraceCall("get_reference_length", __pyx_f[0], 1890, 0, __PYX_ERR(0, 1890, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1544 - * - * result[record] = x - * elif VALID_HEADER_TYPES[record] == list: # <<<<<<<<<<<<<< - * if record not in result: result[record] = [] - * result[record].append(x) + /* "pysam/libcalignmentfile.pyx":1894 + * return :term:`reference` name corresponding to numerical :term:`tid` + * """ + * if self.header is None: # <<<<<<<<<<<<<< + * raise ValueError("header not available in closed files") + * return self.header.get_reference_length(reference) */ - __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_7, __pyx_v_record); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyObject_RichCompare(__pyx_t_8, ((PyObject *)(&PyList_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1544, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1544, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (__pyx_t_2) { + __pyx_t_1 = (((PyObject *)__pyx_v_self->header) == Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcalignmentfile.pyx":1545 - * result[record] = x - * elif VALID_HEADER_TYPES[record] == list: - * if record not in result: result[record] = [] # <<<<<<<<<<<<<< - * result[record].append(x) + /* "pysam/libcalignmentfile.pyx":1895 + * """ + * if self.header is None: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< + * return self.header.get_reference_length(reference) * */ - __pyx_t_2 = (__Pyx_PyDict_ContainsTF(__pyx_v_record, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1545, __pyx_L1_error) - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { - __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1545, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_v_record, __pyx_t_7) < 0)) __PYX_ERR(0, 1545, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__56, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1895, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 1895, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1546 - * elif VALID_HEADER_TYPES[record] == list: - * if record not in result: result[record] = [] - * result[record].append(x) # <<<<<<<<<<<<<< - * - * # if there are no SQ lines in the header, add the + /* "pysam/libcalignmentfile.pyx":1894 + * return :term:`reference` name corresponding to numerical :term:`tid` + * """ + * if self.header is None: # <<<<<<<<<<<<<< + * raise ValueError("header not available in closed files") + * return self.header.get_reference_length(reference) */ - __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_result, __pyx_v_record); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1546, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_v_x); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 1546, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } - /* "pysam/libcalignmentfile.pyx":1544 + /* "pysam/libcalignmentfile.pyx":1896 + * if self.header is None: + * raise ValueError("header not available in closed files") + * return self.header.get_reference_length(reference) # <<<<<<<<<<<<<< * - * result[record] = x - * elif VALID_HEADER_TYPES[record] == list: # <<<<<<<<<<<<<< - * if record not in result: result[record] = [] - * result[record].append(x) + * property nreferences: */ - } - __pyx_L18:; + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_reference_length); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_5) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_reference); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_reference}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1896, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_reference}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1896, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_reference); + __Pyx_GIVEREF(__pyx_v_reference); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_reference); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1502 - * # create 0-terminated string) - * t = self.text - * for line in t.split("\n"): # <<<<<<<<<<<<<< - * if not line.strip(): continue - * assert line.startswith("@"), \ + /* "pysam/libcalignmentfile.pyx":1890 + * return self.header.get_reference_name(tid) + * + * def get_reference_length(self, reference): # <<<<<<<<<<<<<< + * """ + * return :term:`reference` name corresponding to numerical :term:`tid` */ - __pyx_L5_continue:; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1557 - * # the SQ information is not part of the textual header - * # and thus are missing from the output. See issue 84. - * if "SQ" not in result: # <<<<<<<<<<<<<< - * sq = [] - * for ref, length in zip(self.references, self.lengths): - */ - __pyx_t_3 = (__Pyx_PyDict_ContainsTF(__pyx_n_s_SQ, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1557, __pyx_L1_error) - __pyx_t_2 = (__pyx_t_3 != 0); - if (__pyx_t_2) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_reference_length", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignmentfile.pyx":1558 - * # and thus are missing from the output. See issue 84. - * if "SQ" not in result: - * sq = [] # <<<<<<<<<<<<<< - * for ref, length in zip(self.references, self.lengths): - * sq.append({'LN': length, 'SN': ref }) +/* "pysam/libcalignmentfile.pyx":1901 + * """"int with the number of :term:`reference` sequences in the file. + * This is a read-only attribute.""" + * def __get__(self): # <<<<<<<<<<<<<< + * if self.header: + * return self.header.nreferences */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_sq = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1559 - * if "SQ" not in result: - * sq = [] - * for ref, length in zip(self.references, self.lengths): # <<<<<<<<<<<<<< - * sq.append({'LN': length, 'SN': ref }) - * result["SQ"] = sq - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_references); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_lengths); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7); - __pyx_t_1 = 0; - __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) { - __pyx_t_8 = __pyx_t_7; __Pyx_INCREF(__pyx_t_8); __pyx_t_5 = 0; - __pyx_t_6 = NULL; - } else { - __pyx_t_5 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_6 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1559, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - for (;;) { - if (likely(!__pyx_t_6)) { - if (likely(PyList_CheckExact(__pyx_t_8))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1559, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } else { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_8)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1559, __pyx_L1_error) - #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - } - } else { - __pyx_t_7 = __pyx_t_6(__pyx_t_8); - if (unlikely(!__pyx_t_7)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1559, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_7); - } - if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { - PyObject* sequence = __pyx_t_7; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 1559, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_12 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_12 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_12); - #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_12 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - #endif - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_4 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_15 = Py_TYPE(__pyx_t_4)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_15(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L24_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_12 = __pyx_t_15(__pyx_t_4); if (unlikely(!__pyx_t_12)) goto __pyx_L24_unpacking_failed; - __Pyx_GOTREF(__pyx_t_12); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_4), 2) < 0) __PYX_ERR(0, 1559, __pyx_L1_error) - __pyx_t_15 = NULL; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L25_unpacking_done; - __pyx_L24_unpacking_failed:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_15 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1559, __pyx_L1_error) - __pyx_L25_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_ref, __pyx_t_1); - __pyx_t_1 = 0; - __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_12); - __pyx_t_12 = 0; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); - /* "pysam/libcalignmentfile.pyx":1560 - * sq = [] - * for ref, length in zip(self.references, self.lengths): - * sq.append({'LN': length, 'SN': ref }) # <<<<<<<<<<<<<< - * result["SQ"] = sq - * - */ - __pyx_t_7 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1560, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_LN, __pyx_v_length) < 0) __PYX_ERR(0, 1560, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_SN, __pyx_v_ref) < 0) __PYX_ERR(0, 1560, __pyx_L1_error) - __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_sq, __pyx_t_7); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 1560, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcalignmentfile.pyx":1559 - * if "SQ" not in result: - * sq = [] - * for ref, length in zip(self.references, self.lengths): # <<<<<<<<<<<<<< - * sq.append({'LN': length, 'SN': ref }) - * result["SQ"] = sq - */ - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1901, 0, __PYX_ERR(0, 1901, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1561 - * for ref, length in zip(self.references, self.lengths): - * sq.append({'LN': length, 'SN': ref }) - * result["SQ"] = sq # <<<<<<<<<<<<<< - * - * return result + /* "pysam/libcalignmentfile.pyx":1902 + * This is a read-only attribute.""" + * def __get__(self): + * if self.header: # <<<<<<<<<<<<<< + * return self.header.nreferences + * else: */ - if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_n_s_SQ, __pyx_v_sq) < 0)) __PYX_ERR(0, 1561, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1902, __pyx_L1_error) + if (likely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":1557 - * # the SQ information is not part of the textual header - * # and thus are missing from the output. See issue 84. - * if "SQ" not in result: # <<<<<<<<<<<<<< - * sq = [] - * for ref, length in zip(self.references, self.lengths): + /* "pysam/libcalignmentfile.pyx":1903 + * def __get__(self): + * if self.header: + * return self.header.nreferences # <<<<<<<<<<<<<< + * else: + * raise ValueError("header not available in closed files") */ - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1903, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1498 - * result = {} - * - * if self.header.text != NULL: # <<<<<<<<<<<<<< - * # convert to python string (note: call self.text to - * # create 0-terminated string) + /* "pysam/libcalignmentfile.pyx":1902 + * This is a read-only attribute.""" + * def __get__(self): + * if self.header: # <<<<<<<<<<<<<< + * return self.header.nreferences + * else: */ } - /* "pysam/libcalignmentfile.pyx":1563 - * result["SQ"] = sq - * - * return result # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1905 + * return self.header.nreferences + * else: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< * - * ############################################################### + * property references: */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result); - __pyx_r = __pyx_v_result; - goto __pyx_L0; + /*else*/ { + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__57, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1905, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 1905, __pyx_L1_error) + } - /* "pysam/libcalignmentfile.pyx":1492 - * - * """ + /* "pysam/libcalignmentfile.pyx":1901 + * """"int with the number of :term:`reference` sequences in the file. + * This is a read-only attribute.""" * def __get__(self): # <<<<<<<<<<<<<< - * if not self.is_open: - * raise ValueError( "I/O operation on closed file" ) + * if self.header: + * return self.header.nreferences */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_14); - __Pyx_XDECREF(__pyx_t_17); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.nreferences.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_t); - __Pyx_XDECREF(__pyx_v_line); - __Pyx_XDECREF(__pyx_v_fields); - __Pyx_XDECREF(__pyx_v_record); - __Pyx_XDECREF(__pyx_v_x); - __Pyx_XDECREF(__pyx_v_idx); - __Pyx_XDECREF(__pyx_v_field); - __Pyx_XDECREF(__pyx_v_key); - __Pyx_XDECREF(__pyx_v_value); - __Pyx_XDECREF(__pyx_v_sq); - __Pyx_XDECREF(__pyx_v_ref); - __Pyx_XDECREF(__pyx_v_length); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1570 - * ## and multiple_iterators) - * ## Possible solutions: deprecate or open new file handle - * def __iter__(self): # <<<<<<<<<<<<<< - * if not self.is_open: - * raise ValueError("I/O operation on closed file") +/* "pysam/libcalignmentfile.pyx":1910 + * """tuple with the names of :term:`reference` sequences. This is a + * read-only attribute""" + * def __get__(self): # <<<<<<<<<<<<<< + * if self.header: + * return self.header.references */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_10references_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_10references_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10references___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1570, 0, __PYX_ERR(0, 1570, __pyx_L1_error)); - - /* "pysam/libcalignmentfile.pyx":1571 - * ## Possible solutions: deprecate or open new file handle - * def __iter__(self): - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") - * - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1571, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1571, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1910, 0, __PYX_ERR(0, 1910, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1572 - * def __iter__(self): - * if not self.is_open: - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< - * - * if not self.is_bam and self.header.n_targets == 0: + /* "pysam/libcalignmentfile.pyx":1911 + * read-only attribute""" + * def __get__(self): + * if self.header: # <<<<<<<<<<<<<< + * return self.header.references + * else: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__45, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1572, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1911, __pyx_L1_error) + if (likely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":1571 - * ## Possible solutions: deprecate or open new file handle - * def __iter__(self): - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") - * + /* "pysam/libcalignmentfile.pyx":1912 + * def __get__(self): + * if self.header: + * return self.header.references # <<<<<<<<<<<<<< + * else: + * raise ValueError("header not available in closed files") */ - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_references); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1912, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1574 - * raise ValueError("I/O operation on closed file") - * - * if not self.is_bam and self.header.n_targets == 0: # <<<<<<<<<<<<<< - * raise NotImplementedError( - * "can not iterate over samfile without header") + /* "pysam/libcalignmentfile.pyx":1911 + * read-only attribute""" + * def __get__(self): + * if self.header: # <<<<<<<<<<<<<< + * return self.header.references + * else: */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1574, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1574, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = ((!__pyx_t_2) != 0); - if (__pyx_t_4) { - } else { - __pyx_t_3 = __pyx_t_4; - goto __pyx_L5_bool_binop_done; } - __pyx_t_4 = ((__pyx_v_self->header->n_targets == 0) != 0); - __pyx_t_3 = __pyx_t_4; - __pyx_L5_bool_binop_done:; - if (unlikely(__pyx_t_3)) { - - /* "pysam/libcalignmentfile.pyx":1575 - * - * if not self.is_bam and self.header.n_targets == 0: - * raise NotImplementedError( # <<<<<<<<<<<<<< - * "can not iterate over samfile without header") - * return self - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1575, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1575, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1574 - * raise ValueError("I/O operation on closed file") + /* "pysam/libcalignmentfile.pyx":1914 + * return self.header.references + * else: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< * - * if not self.is_bam and self.header.n_targets == 0: # <<<<<<<<<<<<<< - * raise NotImplementedError( - * "can not iterate over samfile without header") + * property lengths: */ + /*else*/ { + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__58, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 1914, __pyx_L1_error) } - /* "pysam/libcalignmentfile.pyx":1577 - * raise NotImplementedError( - * "can not iterate over samfile without header") - * return self # <<<<<<<<<<<<<< - * - * cdef bam1_t * getCurrent( self ): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __pyx_r = ((PyObject *)__pyx_v_self); - goto __pyx_L0; - - /* "pysam/libcalignmentfile.pyx":1570 - * ## and multiple_iterators) - * ## Possible solutions: deprecate or open new file handle - * def __iter__(self): # <<<<<<<<<<<<<< - * if not self.is_open: - * raise ValueError("I/O operation on closed file") + /* "pysam/libcalignmentfile.pyx":1910 + * """tuple with the names of :term:`reference` sequences. This is a + * read-only attribute""" + * def __get__(self): # <<<<<<<<<<<<<< + * if self.header: + * return self.header.references */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.references.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -18389,266 +23343,216 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__iter__( return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1579 - * return self - * - * cdef bam1_t * getCurrent( self ): # <<<<<<<<<<<<<< - * return self.b +/* "pysam/libcalignmentfile.pyx":1922 * + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * if self.header: + * return self.header.lengths */ -static bam1_t *__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { - bam1_t *__pyx_r; - __Pyx_TraceDeclarations +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7lengths_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7lengths_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getCurrent", 0); - __Pyx_TraceCall("getCurrent", __pyx_f[0], 1579, 0, __PYX_ERR(0, 1579, __pyx_L1_error)); - - /* "pysam/libcalignmentfile.pyx":1580 - * - * cdef bam1_t * getCurrent( self ): - * return self.b # <<<<<<<<<<<<<< - * - * cdef int cnext(self): - */ - __pyx_r = __pyx_v_self->b; - goto __pyx_L0; - - /* "pysam/libcalignmentfile.pyx":1579 - * return self - * - * cdef bam1_t * getCurrent( self ): # <<<<<<<<<<<<<< - * return self.b - * - */ + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_7lengths___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ - __pyx_L1_error:; - __Pyx_WriteUnraisable("pysam.libcalignmentfile.AlignmentFile.getCurrent", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_r = 0; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1582 - * return self.b - * - * cdef int cnext(self): # <<<<<<<<<<<<<< - * ''' - * cversion of iterator. Used by :class:`pysam.AlignmentFile.IteratorColumn`. - */ - -static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { - int __pyx_v_ret; - int __pyx_r; +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("cnext", 0); - __Pyx_TraceCall("cnext", __pyx_f[0], 1582, 0, __PYX_ERR(0, 1582, __pyx_L1_error)); + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1922, 0, __PYX_ERR(0, 1922, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1587 - * ''' - * cdef int ret - * with nogil: # <<<<<<<<<<<<<< - * ret = sam_read1(self.htsfile, - * self.header, + /* "pysam/libcalignmentfile.pyx":1923 + * """ + * def __get__(self): + * if self.header: # <<<<<<<<<<<<<< + * return self.header.lengths + * else: */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1923, __pyx_L1_error) + if (likely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":1588 - * cdef int ret - * with nogil: - * ret = sam_read1(self.htsfile, # <<<<<<<<<<<<<< - * self.header, - * self.b) + /* "pysam/libcalignmentfile.pyx":1924 + * def __get__(self): + * if self.header: + * return self.header.lengths # <<<<<<<<<<<<<< + * else: + * raise ValueError("header not available in closed files") */ - __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->header, __pyx_v_self->b); - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_lengths); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1924, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1587 - * ''' - * cdef int ret - * with nogil: # <<<<<<<<<<<<<< - * ret = sam_read1(self.htsfile, - * self.header, + /* "pysam/libcalignmentfile.pyx":1923 + * """ + * def __get__(self): + * if self.header: # <<<<<<<<<<<<<< + * return self.header.lengths + * else: */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L5; - } - __pyx_L5:; - } } - /* "pysam/libcalignmentfile.pyx":1591 - * self.header, - * self.b) - * return ret # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1926 + * return self.header.lengths + * else: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< * - * def __next__(self): + * # Compatibility functions for pysam < 0.14 */ - __pyx_r = __pyx_v_ret; - goto __pyx_L0; + /*else*/ { + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__59, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1926, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 1926, __pyx_L1_error) + } - /* "pysam/libcalignmentfile.pyx":1582 - * return self.b + /* "pysam/libcalignmentfile.pyx":1922 * - * cdef int cnext(self): # <<<<<<<<<<<<<< - * ''' - * cversion of iterator. Used by :class:`pysam.AlignmentFile.IteratorColumn`. + * """ + * def __get__(self): # <<<<<<<<<<<<<< + * if self.header: + * return self.header.lengths */ /* function exit code */ __pyx_L1_error:; - __Pyx_WriteUnraisable("pysam.libcalignmentfile.AlignmentFile.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.lengths.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1593 - * return ret - * - * def __next__(self): # <<<<<<<<<<<<<< - * cdef int ret = self.cnext() - * if (ret >= 0): +/* "pysam/libcalignmentfile.pyx":1931 + * property text: + * """deprecated, use .header directly""" + * def __get__(self): # <<<<<<<<<<<<<< + * if self.header: + * return self.header.__str__() */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41__next__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41__next__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_4text_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_4text_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__next__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4text___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40__next__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { - int __pyx_v_ret; +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4text___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 1593, 0, __PYX_ERR(0, 1593, __pyx_L1_error)); - - /* "pysam/libcalignmentfile.pyx":1594 - * - * def __next__(self): - * cdef int ret = self.cnext() # <<<<<<<<<<<<<< - * if (ret >= 0): - * return makeAlignedSegment(self.b, self) - */ - __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->cnext(__pyx_v_self); + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 1931, 0, __PYX_ERR(0, 1931, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1595 - * def __next__(self): - * cdef int ret = self.cnext() - * if (ret >= 0): # <<<<<<<<<<<<<< - * return makeAlignedSegment(self.b, self) - * elif ret == -2: + /* "pysam/libcalignmentfile.pyx":1932 + * """deprecated, use .header directly""" + * def __get__(self): + * if self.header: # <<<<<<<<<<<<<< + * return self.header.__str__() + * else: */ - __pyx_t_1 = ((__pyx_v_ret >= 0) != 0); - if (__pyx_t_1) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1932, __pyx_L1_error) + if (likely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":1596 - * cdef int ret = self.cnext() - * if (ret >= 0): - * return makeAlignedSegment(self.b, self) # <<<<<<<<<<<<<< - * elif ret == -2: - * raise IOError('truncated file') + /* "pysam/libcalignmentfile.pyx":1933 + * def __get__(self): + * if self.header: + * return self.header.__str__() # <<<<<<<<<<<<<< + * else: + * raise ValueError("header not available in closed files") */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->b, __pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1596, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1933, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1933, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1933, __pyx_L1_error) + } __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1595 - * def __next__(self): - * cdef int ret = self.cnext() - * if (ret >= 0): # <<<<<<<<<<<<<< - * return makeAlignedSegment(self.b, self) - * elif ret == -2: - */ - } - - /* "pysam/libcalignmentfile.pyx":1597 - * if (ret >= 0): - * return makeAlignedSegment(self.b, self) - * elif ret == -2: # <<<<<<<<<<<<<< - * raise IOError('truncated file') - * else: - */ - __pyx_t_1 = ((__pyx_v_ret == -2L) != 0); - if (unlikely(__pyx_t_1)) { - - /* "pysam/libcalignmentfile.pyx":1598 - * return makeAlignedSegment(self.b, self) - * elif ret == -2: - * raise IOError('truncated file') # <<<<<<<<<<<<<< - * else: - * raise StopIteration - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 1598, __pyx_L1_error) - - /* "pysam/libcalignmentfile.pyx":1597 - * if (ret >= 0): - * return makeAlignedSegment(self.b, self) - * elif ret == -2: # <<<<<<<<<<<<<< - * raise IOError('truncated file') - * else: + /* "pysam/libcalignmentfile.pyx":1932 + * """deprecated, use .header directly""" + * def __get__(self): + * if self.header: # <<<<<<<<<<<<<< + * return self.header.__str__() + * else: */ } - /* "pysam/libcalignmentfile.pyx":1600 - * raise IOError('truncated file') - * else: - * raise StopIteration # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1935 + * return self.header.__str__() + * else: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< * * # Compatibility functions for pysam < 0.8.3 */ /*else*/ { - __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 1600, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__60, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1935, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 1935, __pyx_L1_error) } - /* "pysam/libcalignmentfile.pyx":1593 - * return ret - * - * def __next__(self): # <<<<<<<<<<<<<< - * cdef int ret = self.cnext() - * if (ret >= 0): + /* "pysam/libcalignmentfile.pyx":1931 + * property text: + * """deprecated, use .header directly""" + * def __get__(self): # <<<<<<<<<<<<<< + * if self.header: + * return self.header.__str__() */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.text.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -18657,7 +23561,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40__next__( return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1603 +/* "pysam/libcalignmentfile.pyx":1938 * * # Compatibility functions for pysam < 0.8.3 * def gettid(self, reference): # <<<<<<<<<<<<<< @@ -18666,20 +23570,20 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40__next__( */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43gettid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_42gettid[] = "AlignmentFile.gettid(self, reference)\ndeprecated, use get_tid() instead"; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43gettid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49gettid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_48gettid[] = "AlignmentFile.gettid(self, reference)\ndeprecated, use get_tid() instead"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49gettid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("gettid (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42gettid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_reference)); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48gettid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_reference)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42gettid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48gettid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -18688,9 +23592,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42gettid(st PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("gettid", 0); - __Pyx_TraceCall("gettid", __pyx_f[0], 1603, 0, __PYX_ERR(0, 1603, __pyx_L1_error)); + __Pyx_TraceCall("gettid", __pyx_f[0], 1938, 0, __PYX_ERR(0, 1938, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1605 + /* "pysam/libcalignmentfile.pyx":1940 * def gettid(self, reference): * """deprecated, use get_tid() instead""" * return self.get_tid(reference) # <<<<<<<<<<<<<< @@ -18698,7 +23602,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42gettid(st * def getrname(self, tid): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1605, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1940, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -18711,13 +23615,13 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42gettid(st } } if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_reference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1605, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_reference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1940, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_reference}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1605, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1940, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -18725,19 +23629,19 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42gettid(st #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_reference}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1605, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1940, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1605, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1940, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_reference); __Pyx_GIVEREF(__pyx_v_reference); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_reference); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1605, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1940, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -18747,7 +23651,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42gettid(st __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1603 + /* "pysam/libcalignmentfile.pyx":1938 * * # Compatibility functions for pysam < 0.8.3 * def gettid(self, reference): # <<<<<<<<<<<<<< @@ -18770,7 +23674,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42gettid(st return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1607 +/* "pysam/libcalignmentfile.pyx":1942 * return self.get_tid(reference) * * def getrname(self, tid): # <<<<<<<<<<<<<< @@ -18779,20 +23683,20 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42gettid(st */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_44getrname[] = "AlignmentFile.getrname(self, tid)\ndeprecated, use get_reference_name() instead"; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_51getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_50getrname[] = "AlignmentFile.getrname(self, tid)\ndeprecated, use get_reference_name() instead"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_51getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getrname (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44getrname(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_tid)); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_50getrname(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_tid)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44getrname(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_50getrname(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -18801,9 +23705,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44getrname( PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("getrname", 0); - __Pyx_TraceCall("getrname", __pyx_f[0], 1607, 0, __PYX_ERR(0, 1607, __pyx_L1_error)); + __Pyx_TraceCall("getrname", __pyx_f[0], 1942, 0, __PYX_ERR(0, 1942, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1609 + /* "pysam/libcalignmentfile.pyx":1944 * def getrname(self, tid): * """deprecated, use get_reference_name() instead""" * return self.get_reference_name(tid) # <<<<<<<<<<<<<< @@ -18811,7 +23715,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44getrname( * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1609, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1944, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -18824,13 +23728,13 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44getrname( } } if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1609, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1944, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_tid}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1609, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1944, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -18838,19 +23742,19 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44getrname( #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_tid}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1609, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1944, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1609, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1944, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_tid); __Pyx_GIVEREF(__pyx_v_tid); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_tid); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1609, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1944, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -18860,7 +23764,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44getrname( __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1607 + /* "pysam/libcalignmentfile.pyx":1942 * return self.get_tid(reference) * * def getrname(self, tid): # <<<<<<<<<<<<<< @@ -18883,12 +23787,12 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44getrname( return __pyx_r; } -/* "pysam/libcalignmentfile.pxd":40 +/* "pysam/libcalignmentfile.pxd":45 * * cdef class AlignmentFile(HTSFile): * cdef readonly object reference_filename # <<<<<<<<<<<<<< + * cdef readonly AlignmentHeader header * - * # pointer to index */ /* Python wrapper */ @@ -18909,7 +23813,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18reference __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 40, 0, __PYX_ERR(2, 40, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[2], 45, 0, __PYX_ERR(2, 45, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->reference_filename); __pyx_r = __pyx_v_self->reference_filename; @@ -18926,6 +23830,49 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18reference return __pyx_r; } +/* "pysam/libcalignmentfile.pxd":46 + * cdef class AlignmentFile(HTSFile): + * cdef readonly object reference_filename + * cdef readonly AlignmentHeader header # <<<<<<<<<<<<<< + * + * # pointer to index + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6header_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6header___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6header___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[2], 46, 0, __PYX_ERR(2, 46, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); + __pyx_r = ((PyObject *)__pyx_v_self->header); + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * raise TypeError("no default __reduce__ due to non-trivial __cinit__") @@ -18933,20 +23880,20 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18reference */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_46__reduce_cython__[] = "AlignmentFile.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_53__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__[] = "AlignmentFile.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_53__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -18960,7 +23907,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46__reduce_ * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__61, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -18991,20 +23938,20 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46__reduce_ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_48__setstate_cython__[] = "AlignmentFile.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_55__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__[] = "AlignmentFile.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_55__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -19017,7 +23964,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48__setstat * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__49, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -19041,7 +23988,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48__setstat return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1637 +/* "pysam/libcalignmentfile.pyx":1972 * ''' * * def __init__(self, AlignmentFile samfile, int multiple_iterators=False): # <<<<<<<<<<<<<< @@ -19084,7 +24031,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_1__init__(PyObject } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1637, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1972, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -19097,20 +24044,20 @@ static int __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_1__init__(PyObject } __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]); if (values[1]) { - __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1637, __pyx_L3_error) + __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1972, __pyx_L3_error) } else { __pyx_v_multiple_iterators = ((int)0); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1637, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1972, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRow.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 1637, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 1972, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators); /* function exit code */ @@ -19125,6 +24072,8 @@ static int __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_1__init__(PyObject static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators) { char *__pyx_v_cfilename; char *__pyx_v_creference_filename; + char *__pyx_v_cindexname; + bam_hdr_t *__pyx_v_hdr; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -19132,40 +24081,51 @@ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __p int __pyx_t_2; int __pyx_t_3; char *__pyx_t_4; - htsFile *__pyx_t_5; - bam_hdr_t *__pyx_t_6; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + htsFile *__pyx_t_7; + hts_idx_t *__pyx_t_8; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1637, 0, __PYX_ERR(0, 1637, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 1972, 0, __PYX_ERR(0, 1972, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1641 + /* "pysam/libcalignmentfile.pyx":1975 + * cdef char *cfilename * cdef char *creference_filename + * cdef char *cindexname = NULL # <<<<<<<<<<<<<< + * + * if not samfile.is_open: + */ + __pyx_v_cindexname = NULL; + + /* "pysam/libcalignmentfile.pyx":1977 + * cdef char *cindexname = NULL * * if not samfile.is_open: # <<<<<<<<<<<<<< * raise ValueError("I/O operation on closed file") * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1641, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1977, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1641, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1977, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = ((!__pyx_t_2) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":1642 + /* "pysam/libcalignmentfile.pyx":1978 * * if not samfile.is_open: * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< * * # makes sure that samfile stays alive as long as the */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__50, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1642, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__63, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1978, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1642, __pyx_L1_error) + __PYX_ERR(0, 1978, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1641 - * cdef char *creference_filename + /* "pysam/libcalignmentfile.pyx":1977 + * cdef char *cindexname = NULL * * if not samfile.is_open: # <<<<<<<<<<<<<< * raise ValueError("I/O operation on closed file") @@ -19173,7 +24133,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __p */ } - /* "pysam/libcalignmentfile.pyx":1646 + /* "pysam/libcalignmentfile.pyx":1982 * # makes sure that samfile stays alive as long as the * # iterator is alive * self.samfile = samfile # <<<<<<<<<<<<<< @@ -19186,28 +24146,28 @@ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __p __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile)); __pyx_v_self->samfile = __pyx_v_samfile; - /* "pysam/libcalignmentfile.pyx":1650 + /* "pysam/libcalignmentfile.pyx":1986 * # reopen the file - note that this makes the iterator * # slow and causes pileup to slow down significantly. * if multiple_iterators: # <<<<<<<<<<<<<< + * * cfilename = samfile.filename - * with nogil: */ __pyx_t_3 = (__pyx_v_multiple_iterators != 0); if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":1651 - * # slow and causes pileup to slow down significantly. + /* "pysam/libcalignmentfile.pyx":1988 * if multiple_iterators: + * * cfilename = samfile.filename # <<<<<<<<<<<<<< * with nogil: * self.htsfile = hts_open(cfilename, 'r') */ - __pyx_t_4 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->__pyx_base.filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 1651, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->__pyx_base.filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 1988, __pyx_L1_error) __pyx_v_cfilename = __pyx_t_4; - /* "pysam/libcalignmentfile.pyx":1652 - * if multiple_iterators: + /* "pysam/libcalignmentfile.pyx":1989 + * * cfilename = samfile.filename * with nogil: # <<<<<<<<<<<<<< * self.htsfile = hts_open(cfilename, 'r') @@ -19221,57 +24181,183 @@ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __p #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1653 + /* "pysam/libcalignmentfile.pyx":1990 * cfilename = samfile.filename * with nogil: * self.htsfile = hts_open(cfilename, 'r') # <<<<<<<<<<<<<< * assert self.htsfile != NULL - * # read header - required for accurate positioning + * */ __pyx_v_self->htsfile = hts_open(__pyx_v_cfilename, ((char const *)"r")); } - /* "pysam/libcalignmentfile.pyx":1652 - * if multiple_iterators: + /* "pysam/libcalignmentfile.pyx":1989 + * * cfilename = samfile.filename * with nogil: # <<<<<<<<<<<<<< * self.htsfile = hts_open(cfilename, 'r') * assert self.htsfile != NULL */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L7; - } - __pyx_L7:; - } + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L7; + } + __pyx_L7:; + } + } + + /* "pysam/libcalignmentfile.pyx":1991 + * with nogil: + * self.htsfile = hts_open(cfilename, 'r') + * assert self.htsfile != NULL # <<<<<<<<<<<<<< + * + * if samfile.has_index(): + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(!((__pyx_v_self->htsfile != NULL) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 1991, __pyx_L1_error) + } + } + #endif + + /* "pysam/libcalignmentfile.pyx":1993 + * assert self.htsfile != NULL + * + * if samfile.has_index(): # <<<<<<<<<<<<<< + * if samfile.index_filename: + * cindexname = samfile.index_filename + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_has_index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1993, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (__pyx_t_6) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1993, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1993, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1993, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { + + /* "pysam/libcalignmentfile.pyx":1994 + * + * if samfile.has_index(): + * if samfile.index_filename: # <<<<<<<<<<<<<< + * cindexname = samfile.index_filename + * with nogil: + */ + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_samfile->__pyx_base.index_filename); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1994, __pyx_L1_error) + if (__pyx_t_3) { + + /* "pysam/libcalignmentfile.pyx":1995 + * if samfile.has_index(): + * if samfile.index_filename: + * cindexname = samfile.index_filename # <<<<<<<<<<<<<< + * with nogil: + * self.index = sam_index_load2(self.htsfile, cfilename, cindexname) + */ + __pyx_t_4 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->__pyx_base.index_filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 1995, __pyx_L1_error) + __pyx_v_cindexname = __pyx_t_4; + + /* "pysam/libcalignmentfile.pyx":1994 + * + * if samfile.has_index(): + * if samfile.index_filename: # <<<<<<<<<<<<<< + * cindexname = samfile.index_filename + * with nogil: + */ + } + + /* "pysam/libcalignmentfile.pyx":1996 + * if samfile.index_filename: + * cindexname = samfile.index_filename + * with nogil: # <<<<<<<<<<<<<< + * self.index = sam_index_load2(self.htsfile, cfilename, cindexname) + * else: + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libcalignmentfile.pyx":1997 + * cindexname = samfile.index_filename + * with nogil: + * self.index = sam_index_load2(self.htsfile, cfilename, cindexname) # <<<<<<<<<<<<<< + * else: + * self.index = NULL + */ + __pyx_v_self->index = sam_index_load2(__pyx_v_self->htsfile, __pyx_v_cfilename, __pyx_v_cindexname); + } + + /* "pysam/libcalignmentfile.pyx":1996 + * if samfile.index_filename: + * cindexname = samfile.index_filename + * with nogil: # <<<<<<<<<<<<<< + * self.index = sam_index_load2(self.htsfile, cfilename, cindexname) + * else: + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L12; + } + __pyx_L12:; + } + } + + /* "pysam/libcalignmentfile.pyx":1993 + * assert self.htsfile != NULL + * + * if samfile.has_index(): # <<<<<<<<<<<<<< + * if samfile.index_filename: + * cindexname = samfile.index_filename + */ + goto __pyx_L8; } - /* "pysam/libcalignmentfile.pyx":1654 - * with nogil: - * self.htsfile = hts_open(cfilename, 'r') - * assert self.htsfile != NULL # <<<<<<<<<<<<<< - * # read header - required for accurate positioning - * # could a tell/seek work? + /* "pysam/libcalignmentfile.pyx":1999 + * self.index = sam_index_load2(self.htsfile, cfilename, cindexname) + * else: + * self.index = NULL # <<<<<<<<<<<<<< + * + * # need to advance in newly opened file to position after header */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - if (unlikely(!((__pyx_v_self->htsfile != NULL) != 0))) { - PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 1654, __pyx_L1_error) - } + /*else*/ { + __pyx_v_self->index = NULL; } - #endif + __pyx_L8:; - /* "pysam/libcalignmentfile.pyx":1657 - * # read header - required for accurate positioning - * # could a tell/seek work? + /* "pysam/libcalignmentfile.pyx":2003 + * # need to advance in newly opened file to position after header + * # better: use seek/tell? * with nogil: # <<<<<<<<<<<<<< - * self.header = sam_hdr_read(self.htsfile) - * assert self.header != NULL + * hdr = sam_hdr_read(self.htsfile) + * if hdr is NULL: */ { #ifdef WITH_THREAD @@ -19281,22 +24367,22 @@ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __p #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1658 - * # could a tell/seek work? + /* "pysam/libcalignmentfile.pyx":2004 + * # better: use seek/tell? * with nogil: - * self.header = sam_hdr_read(self.htsfile) # <<<<<<<<<<<<<< - * assert self.header != NULL - * self.owns_samfile = True + * hdr = sam_hdr_read(self.htsfile) # <<<<<<<<<<<<<< + * if hdr is NULL: + * raise IOError("unable to read header information") */ - __pyx_v_self->header = sam_hdr_read(__pyx_v_self->htsfile); + __pyx_v_hdr = sam_hdr_read(__pyx_v_self->htsfile); } - /* "pysam/libcalignmentfile.pyx":1657 - * # read header - required for accurate positioning - * # could a tell/seek work? + /* "pysam/libcalignmentfile.pyx":2003 + * # need to advance in newly opened file to position after header + * # better: use seek/tell? * with nogil: # <<<<<<<<<<<<<< - * self.header = sam_hdr_read(self.htsfile) - * assert self.header != NULL + * hdr = sam_hdr_read(self.htsfile) + * if hdr is NULL: */ /*finally:*/ { /*normal exit:*/{ @@ -19304,69 +24390,100 @@ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __p __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif - goto __pyx_L10; + goto __pyx_L15; } - __pyx_L10:; + __pyx_L15:; } } - /* "pysam/libcalignmentfile.pyx":1659 + /* "pysam/libcalignmentfile.pyx":2005 * with nogil: - * self.header = sam_hdr_read(self.htsfile) - * assert self.header != NULL # <<<<<<<<<<<<<< - * self.owns_samfile = True - * # options specific to CRAM files + * hdr = sam_hdr_read(self.htsfile) + * if hdr is NULL: # <<<<<<<<<<<<<< + * raise IOError("unable to read header information") + * self.header = makeAlignmentHeader(hdr) + */ + __pyx_t_3 = ((__pyx_v_hdr == NULL) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcalignmentfile.pyx":2006 + * hdr = sam_hdr_read(self.htsfile) + * if hdr is NULL: + * raise IOError("unable to read header information") # <<<<<<<<<<<<<< + * self.header = makeAlignmentHeader(hdr) + * + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2006, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2006, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":2005 + * with nogil: + * hdr = sam_hdr_read(self.htsfile) + * if hdr is NULL: # <<<<<<<<<<<<<< + * raise IOError("unable to read header information") + * self.header = makeAlignmentHeader(hdr) */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - if (unlikely(!((__pyx_v_self->header != NULL) != 0))) { - PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 1659, __pyx_L1_error) - } } - #endif - /* "pysam/libcalignmentfile.pyx":1660 - * self.header = sam_hdr_read(self.htsfile) - * assert self.header != NULL + /* "pysam/libcalignmentfile.pyx":2007 + * if hdr is NULL: + * raise IOError("unable to read header information") + * self.header = makeAlignmentHeader(hdr) # <<<<<<<<<<<<<< + * + * self.owns_samfile = True + */ + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2007, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":2009 + * self.header = makeAlignmentHeader(hdr) + * * self.owns_samfile = True # <<<<<<<<<<<<<< + * * # options specific to CRAM files - * if samfile.is_cram and samfile.reference_filename: */ __pyx_v_self->owns_samfile = 1; - /* "pysam/libcalignmentfile.pyx":1662 - * self.owns_samfile = True + /* "pysam/libcalignmentfile.pyx":2012 + * * # options specific to CRAM files * if samfile.is_cram and samfile.reference_filename: # <<<<<<<<<<<<<< * creference_filename = samfile.reference_filename * hts_set_opt(self.htsfile, */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1662, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2012, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1662, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2012, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { } else { __pyx_t_3 = __pyx_t_2; - goto __pyx_L12_bool_binop_done; + goto __pyx_L18_bool_binop_done; } - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_samfile->reference_filename); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1662, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_samfile->reference_filename); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2012, __pyx_L1_error) __pyx_t_3 = __pyx_t_2; - __pyx_L12_bool_binop_done:; + __pyx_L18_bool_binop_done:; if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":1663 + /* "pysam/libcalignmentfile.pyx":2013 * # options specific to CRAM files * if samfile.is_cram and samfile.reference_filename: * creference_filename = samfile.reference_filename # <<<<<<<<<<<<<< * hts_set_opt(self.htsfile, * CRAM_OPT_REFERENCE, */ - __pyx_t_4 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->reference_filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 1663, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->reference_filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2013, __pyx_L1_error) __pyx_v_creference_filename = __pyx_t_4; - /* "pysam/libcalignmentfile.pyx":1664 + /* "pysam/libcalignmentfile.pyx":2014 * if samfile.is_cram and samfile.reference_filename: * creference_filename = samfile.reference_filename * hts_set_opt(self.htsfile, # <<<<<<<<<<<<<< @@ -19375,8 +24492,8 @@ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __p */ (void)(hts_set_opt(__pyx_v_self->htsfile, CRAM_OPT_REFERENCE, __pyx_v_creference_filename)); - /* "pysam/libcalignmentfile.pyx":1662 - * self.owns_samfile = True + /* "pysam/libcalignmentfile.pyx":2012 + * * # options specific to CRAM files * if samfile.is_cram and samfile.reference_filename: # <<<<<<<<<<<<<< * creference_filename = samfile.reference_filename @@ -19384,50 +24501,65 @@ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __p */ } - /* "pysam/libcalignmentfile.pyx":1650 + /* "pysam/libcalignmentfile.pyx":1986 * # reopen the file - note that this makes the iterator * # slow and causes pileup to slow down significantly. * if multiple_iterators: # <<<<<<<<<<<<<< + * * cfilename = samfile.filename - * with nogil: */ goto __pyx_L4; } - /* "pysam/libcalignmentfile.pyx":1669 + /* "pysam/libcalignmentfile.pyx":2019 * * else: - * self.htsfile = self.samfile.htsfile # <<<<<<<<<<<<<< + * self.htsfile = samfile.htsfile # <<<<<<<<<<<<<< + * self.index = samfile.index * self.owns_samfile = False - * self.header = self.samfile.header */ /*else*/ { - __pyx_t_5 = __pyx_v_self->samfile->__pyx_base.htsfile; - __pyx_v_self->htsfile = __pyx_t_5; + __pyx_t_7 = __pyx_v_samfile->__pyx_base.htsfile; + __pyx_v_self->htsfile = __pyx_t_7; - /* "pysam/libcalignmentfile.pyx":1670 + /* "pysam/libcalignmentfile.pyx":2020 * else: - * self.htsfile = self.samfile.htsfile + * self.htsfile = samfile.htsfile + * self.index = samfile.index # <<<<<<<<<<<<<< + * self.owns_samfile = False + * self.header = samfile.header + */ + __pyx_t_8 = __pyx_v_samfile->index; + __pyx_v_self->index = __pyx_t_8; + + /* "pysam/libcalignmentfile.pyx":2021 + * self.htsfile = samfile.htsfile + * self.index = samfile.index * self.owns_samfile = False # <<<<<<<<<<<<<< - * self.header = self.samfile.header + * self.header = samfile.header * */ __pyx_v_self->owns_samfile = 0; - /* "pysam/libcalignmentfile.pyx":1671 - * self.htsfile = self.samfile.htsfile + /* "pysam/libcalignmentfile.pyx":2022 + * self.index = samfile.index * self.owns_samfile = False - * self.header = self.samfile.header # <<<<<<<<<<<<<< + * self.header = samfile.header # <<<<<<<<<<<<<< * * self.retval = 0 */ - __pyx_t_6 = __pyx_v_self->samfile->header; - __pyx_v_self->header = __pyx_t_6; + __pyx_t_1 = ((PyObject *)__pyx_v_samfile->header); + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1); + __pyx_t_1 = 0; } __pyx_L4:; - /* "pysam/libcalignmentfile.pyx":1673 - * self.header = self.samfile.header + /* "pysam/libcalignmentfile.pyx":2024 + * self.header = samfile.header * * self.retval = 0 # <<<<<<<<<<<<<< * @@ -19435,7 +24567,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __p */ __pyx_v_self->retval = 0; - /* "pysam/libcalignmentfile.pyx":1675 + /* "pysam/libcalignmentfile.pyx":2026 * self.retval = 0 * * self.b = bam_init1() # <<<<<<<<<<<<<< @@ -19444,7 +24576,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __p */ __pyx_v_self->b = bam_init1(); - /* "pysam/libcalignmentfile.pyx":1637 + /* "pysam/libcalignmentfile.pyx":1972 * ''' * * def __init__(self, AlignmentFile samfile, int multiple_iterators=False): # <<<<<<<<<<<<<< @@ -19457,6 +24589,8 @@ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __p goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRow.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -19465,7 +24599,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __p return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1677 +/* "pysam/libcalignmentfile.pyx":2028 * self.b = bam_init1() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -19489,9 +24623,9 @@ static void __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_2__dealloc__(struc __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1677, 0, __PYX_ERR(0, 1677, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2028, 0, __PYX_ERR(0, 2028, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1678 + /* "pysam/libcalignmentfile.pyx":2029 * * def __dealloc__(self): * bam_destroy1(self.b) # <<<<<<<<<<<<<< @@ -19500,44 +24634,44 @@ static void __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_2__dealloc__(struc */ bam_destroy1(__pyx_v_self->b); - /* "pysam/libcalignmentfile.pyx":1679 + /* "pysam/libcalignmentfile.pyx":2030 * def __dealloc__(self): * bam_destroy1(self.b) * if self.owns_samfile: # <<<<<<<<<<<<<< * hts_close(self.htsfile) - * bam_hdr_destroy(self.header) + * hts_idx_destroy(self.index) */ __pyx_t_1 = (__pyx_v_self->owns_samfile != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1680 + /* "pysam/libcalignmentfile.pyx":2031 * bam_destroy1(self.b) * if self.owns_samfile: * hts_close(self.htsfile) # <<<<<<<<<<<<<< - * bam_hdr_destroy(self.header) + * hts_idx_destroy(self.index) * */ (void)(hts_close(__pyx_v_self->htsfile)); - /* "pysam/libcalignmentfile.pyx":1681 + /* "pysam/libcalignmentfile.pyx":2032 * if self.owns_samfile: * hts_close(self.htsfile) - * bam_hdr_destroy(self.header) # <<<<<<<<<<<<<< + * hts_idx_destroy(self.index) # <<<<<<<<<<<<<< * * */ - bam_hdr_destroy(__pyx_v_self->header); + hts_idx_destroy(__pyx_v_self->index); - /* "pysam/libcalignmentfile.pyx":1679 + /* "pysam/libcalignmentfile.pyx":2030 * def __dealloc__(self): * bam_destroy1(self.b) * if self.owns_samfile: # <<<<<<<<<<<<<< * hts_close(self.htsfile) - * bam_hdr_destroy(self.header) + * hts_idx_destroy(self.index) */ } - /* "pysam/libcalignmentfile.pyx":1677 + /* "pysam/libcalignmentfile.pyx":2028 * self.b = bam_init1() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -19556,7 +24690,7 @@ static void __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_2__dealloc__(struc /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -19584,11 +24718,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cyt /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__51, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__65, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -19596,7 +24730,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cyt /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -19613,9 +24747,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cyt /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ /* Python wrapper */ @@ -19641,11 +24775,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_c __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__66, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -19653,9 +24787,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_c /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ /* function exit code */ @@ -19669,11 +24803,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_c return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1698 +/* "pysam/libcalignmentfile.pyx":2049 * """ * * def __init__(self, AlignmentFile samfile, # <<<<<<<<<<<<<< - * int tid, int beg, int end, + * int tid, int beg, int stop, * int multiple_iterators=False): */ @@ -19683,13 +24817,13 @@ static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_1__init__(PyO struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0; int __pyx_v_tid; int __pyx_v_beg; - int __pyx_v_end; + int __pyx_v_stop; int __pyx_v_multiple_iterators; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_tid,&__pyx_n_s_beg,&__pyx_n_s_end,&__pyx_n_s_multiple_iterators,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_tid,&__pyx_n_s_beg,&__pyx_n_s_stop,&__pyx_n_s_multiple_iterators,0}; PyObject* values[5] = {0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; @@ -19717,19 +24851,19 @@ static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_1__init__(PyO case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tid)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 1); __PYX_ERR(0, 1698, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 1); __PYX_ERR(0, 2049, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_beg)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 2); __PYX_ERR(0, 1698, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 2); __PYX_ERR(0, 2049, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: - if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end)) != 0)) kw_args--; + if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 3); __PYX_ERR(0, 1698, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 3); __PYX_ERR(0, 2049, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: @@ -19739,7 +24873,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_1__init__(PyO } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1698, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 2049, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -19754,39 +24888,39 @@ static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_1__init__(PyO } } __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]); - __pyx_v_tid = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1699, __pyx_L3_error) - __pyx_v_beg = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1699, __pyx_L3_error) - __pyx_v_end = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1699, __pyx_L3_error) + __pyx_v_tid = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2050, __pyx_L3_error) + __pyx_v_beg = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2050, __pyx_L3_error) + __pyx_v_stop = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_stop == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2050, __pyx_L3_error) if (values[4]) { - __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1700, __pyx_L3_error) + __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2051, __pyx_L3_error) } else { - /* "pysam/libcalignmentfile.pyx":1700 + /* "pysam/libcalignmentfile.pyx":2051 * def __init__(self, AlignmentFile samfile, - * int tid, int beg, int end, + * int tid, int beg, int stop, * int multiple_iterators=False): # <<<<<<<<<<<<<< * - * IteratorRow.__init__(self, samfile, + * if not samfile.has_index(): */ __pyx_v_multiple_iterators = ((int)0); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1698, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2049, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 1698, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_beg, __pyx_v_end, __pyx_v_multiple_iterators); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2049, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_beg, __pyx_v_stop, __pyx_v_multiple_iterators); - /* "pysam/libcalignmentfile.pyx":1698 + /* "pysam/libcalignmentfile.pyx":2049 * """ * * def __init__(self, AlignmentFile samfile, # <<<<<<<<<<<<<< - * int tid, int beg, int end, + * int tid, int beg, int stop, * int multiple_iterators=False): */ @@ -19799,29 +24933,83 @@ static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_1__init__(PyO return __pyx_r; } -static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_end, int __pyx_v_multiple_iterators) { +static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_stop, int __pyx_v_multiple_iterators) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; + int __pyx_t_4; int __pyx_t_5; - int __pyx_t_6; + PyObject *__pyx_t_6 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1698, 0, __PYX_ERR(0, 1698, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 2049, 0, __PYX_ERR(0, 2049, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":2053 + * int multiple_iterators=False): + * + * if not samfile.has_index(): # <<<<<<<<<<<<<< + * raise ValueError("no index available for iteration") + * + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_has_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2053, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2053, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2053, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2053, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = ((!__pyx_t_4) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcalignmentfile.pyx":2054 + * + * if not samfile.has_index(): + * raise ValueError("no index available for iteration") # <<<<<<<<<<<<<< + * + * IteratorRow.__init__(self, samfile, + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__67, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2054, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2054, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1702 + /* "pysam/libcalignmentfile.pyx":2053 * int multiple_iterators=False): * + * if not samfile.has_index(): # <<<<<<<<<<<<<< + * raise ValueError("no index available for iteration") + * + */ + } + + /* "pysam/libcalignmentfile.pyx":2056 + * raise ValueError("no index available for iteration") + * * IteratorRow.__init__(self, samfile, # <<<<<<<<<<<<<< * multiple_iterators=multiple_iterators) * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1702, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2056, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1702, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2056, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); @@ -19830,94 +25018,40 @@ static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(stru __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile)); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile)); - /* "pysam/libcalignmentfile.pyx":1703 + /* "pysam/libcalignmentfile.pyx":2057 * * IteratorRow.__init__(self, samfile, * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< * - * if not samfile.has_index(): + * with nogil: */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1703, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2057, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1703, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 1703, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2057, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_6) < 0) __PYX_ERR(0, 2057, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libcalignmentfile.pyx":1702 - * int multiple_iterators=False): + /* "pysam/libcalignmentfile.pyx":2056 + * raise ValueError("no index available for iteration") * * IteratorRow.__init__(self, samfile, # <<<<<<<<<<<<<< * multiple_iterators=multiple_iterators) * */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1702, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2056, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pysam/libcalignmentfile.pyx":1705 - * multiple_iterators=multiple_iterators) - * - * if not samfile.has_index(): # <<<<<<<<<<<<<< - * raise ValueError("no index available for iteration") - * - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_has_index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1705, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (__pyx_t_2) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1705, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1705, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1705, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_6 = ((!__pyx_t_5) != 0); - if (unlikely(__pyx_t_6)) { - - /* "pysam/libcalignmentfile.pyx":1706 - * - * if not samfile.has_index(): - * raise ValueError("no index available for iteration") # <<<<<<<<<<<<<< - * - * with nogil: - */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__53, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libcalignmentfile.pyx":1705 + /* "pysam/libcalignmentfile.pyx":2059 * multiple_iterators=multiple_iterators) * - * if not samfile.has_index(): # <<<<<<<<<<<<<< - * raise ValueError("no index available for iteration") - * - */ - } - - /* "pysam/libcalignmentfile.pyx":1708 - * raise ValueError("no index available for iteration") - * * with nogil: # <<<<<<<<<<<<<< * self.iter = sam_itr_queryi( - * self.samfile.index, + * self.index, */ { #ifdef WITH_THREAD @@ -19927,22 +25061,22 @@ static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(stru #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1709 + /* "pysam/libcalignmentfile.pyx":2060 * * with nogil: * self.iter = sam_itr_queryi( # <<<<<<<<<<<<<< - * self.samfile.index, + * self.index, * tid, */ - __pyx_v_self->iter = sam_itr_queryi(__pyx_v_self->__pyx_base.samfile->index, __pyx_v_tid, __pyx_v_beg, __pyx_v_end); + __pyx_v_self->iter = sam_itr_queryi(__pyx_v_self->__pyx_base.index, __pyx_v_tid, __pyx_v_beg, __pyx_v_stop); } - /* "pysam/libcalignmentfile.pyx":1708 - * raise ValueError("no index available for iteration") + /* "pysam/libcalignmentfile.pyx":2059 + * multiple_iterators=multiple_iterators) * * with nogil: # <<<<<<<<<<<<<< * self.iter = sam_itr_queryi( - * self.samfile.index, + * self.index, */ /*finally:*/ { /*normal exit:*/{ @@ -19956,11 +25090,11 @@ static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(stru } } - /* "pysam/libcalignmentfile.pyx":1698 + /* "pysam/libcalignmentfile.pyx":2049 * """ * * def __init__(self, AlignmentFile samfile, # <<<<<<<<<<<<<< - * int tid, int beg, int end, + * int tid, int beg, int stop, * int multiple_iterators=False): */ @@ -19971,7 +25105,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(stru __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -19980,8 +25114,8 @@ static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(stru return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1715 - * end) +/* "pysam/libcalignmentfile.pyx":2066 + * stop) * * def __iter__(self): # <<<<<<<<<<<<<< * return self @@ -20006,9 +25140,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_2__iter __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1715, 0, __PYX_ERR(0, 1715, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 2066, 0, __PYX_ERR(0, 2066, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1716 + /* "pysam/libcalignmentfile.pyx":2067 * * def __iter__(self): * return self # <<<<<<<<<<<<<< @@ -20020,8 +25154,8 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_2__iter __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1715 - * end) + /* "pysam/libcalignmentfile.pyx":2066 + * stop) * * def __iter__(self): # <<<<<<<<<<<<<< * return self @@ -20039,7 +25173,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_2__iter return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1718 +/* "pysam/libcalignmentfile.pyx":2069 * return self * * cdef bam1_t * getCurrent(self): # <<<<<<<<<<<<<< @@ -20052,9 +25186,9 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_getCurrent __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCurrent", 0); - __Pyx_TraceCall("getCurrent", __pyx_f[0], 1718, 0, __PYX_ERR(0, 1718, __pyx_L1_error)); + __Pyx_TraceCall("getCurrent", __pyx_f[0], 2069, 0, __PYX_ERR(0, 2069, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1719 + /* "pysam/libcalignmentfile.pyx":2070 * * cdef bam1_t * getCurrent(self): * return self.b # <<<<<<<<<<<<<< @@ -20064,7 +25198,7 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_getCurrent __pyx_r = __pyx_v_self->__pyx_base.b; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1718 + /* "pysam/libcalignmentfile.pyx":2069 * return self * * cdef bam1_t * getCurrent(self): # <<<<<<<<<<<<<< @@ -20082,7 +25216,7 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_getCurrent return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1721 +/* "pysam/libcalignmentfile.pyx":2072 * return self.b * * cdef int cnext(self): # <<<<<<<<<<<<<< @@ -20095,9 +25229,9 @@ static int __pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_cnext(struct _ __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("cnext", 0); - __Pyx_TraceCall("cnext", __pyx_f[0], 1721, 0, __PYX_ERR(0, 1721, __pyx_L1_error)); + __Pyx_TraceCall("cnext", __pyx_f[0], 2072, 0, __PYX_ERR(0, 2072, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1723 + /* "pysam/libcalignmentfile.pyx":2074 * cdef int cnext(self): * '''cversion of iterator. Used by IteratorColumn''' * with nogil: # <<<<<<<<<<<<<< @@ -20112,7 +25246,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_cnext(struct _ #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1724 + /* "pysam/libcalignmentfile.pyx":2075 * '''cversion of iterator. Used by IteratorColumn''' * with nogil: * self.retval = hts_itr_next(hts_get_bgzfp(self.htsfile), # <<<<<<<<<<<<<< @@ -20122,7 +25256,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_cnext(struct _ __pyx_v_self->__pyx_base.retval = hts_itr_next(hts_get_bgzfp(__pyx_v_self->__pyx_base.htsfile), __pyx_v_self->iter, __pyx_v_self->__pyx_base.b, __pyx_v_self->__pyx_base.htsfile); } - /* "pysam/libcalignmentfile.pyx":1723 + /* "pysam/libcalignmentfile.pyx":2074 * cdef int cnext(self): * '''cversion of iterator. Used by IteratorColumn''' * with nogil: # <<<<<<<<<<<<<< @@ -20141,7 +25275,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_cnext(struct _ } } - /* "pysam/libcalignmentfile.pyx":1721 + /* "pysam/libcalignmentfile.pyx":2072 * return self.b * * cdef int cnext(self): # <<<<<<<<<<<<<< @@ -20161,7 +25295,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_cnext(struct _ return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1729 +/* "pysam/libcalignmentfile.pyx":2080 * self.htsfile) * * def __next__(self): # <<<<<<<<<<<<<< @@ -20189,57 +25323,90 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_4__next int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 1729, 0, __PYX_ERR(0, 1729, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 2080, 0, __PYX_ERR(0, 2080, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1730 + /* "pysam/libcalignmentfile.pyx":2081 * * def __next__(self): * self.cnext() # <<<<<<<<<<<<<< * if self.retval >= 0: - * return makeAlignedSegment(self.b, self.samfile) + * return makeAlignedSegment(self.b, self.header) */ (void)(((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self)); - /* "pysam/libcalignmentfile.pyx":1731 + /* "pysam/libcalignmentfile.pyx":2082 * def __next__(self): * self.cnext() * if self.retval >= 0: # <<<<<<<<<<<<<< - * return makeAlignedSegment(self.b, self.samfile) - * elif self.retval == -2: + * return makeAlignedSegment(self.b, self.header) + * elif self.retval == -1: */ __pyx_t_1 = ((__pyx_v_self->__pyx_base.retval >= 0) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1732 + /* "pysam/libcalignmentfile.pyx":2083 * self.cnext() * if self.retval >= 0: - * return makeAlignedSegment(self.b, self.samfile) # <<<<<<<<<<<<<< - * elif self.retval == -2: - * # Note: it is currently not the case that hts_iter_next + * return makeAlignedSegment(self.b, self.header) # <<<<<<<<<<<<<< + * elif self.retval == -1: + * raise StopIteration */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.samfile); + __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header); __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1732, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2083, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1731 + /* "pysam/libcalignmentfile.pyx":2082 * def __next__(self): * self.cnext() * if self.retval >= 0: # <<<<<<<<<<<<<< - * return makeAlignedSegment(self.b, self.samfile) - * elif self.retval == -2: + * return makeAlignedSegment(self.b, self.header) + * elif self.retval == -1: */ } - /* "pysam/libcalignmentfile.pyx":1733 + /* "pysam/libcalignmentfile.pyx":2084 + * if self.retval >= 0: + * return makeAlignedSegment(self.b, self.header) + * elif self.retval == -1: # <<<<<<<<<<<<<< + * raise StopIteration + * elif self.retval == -2: + */ + __pyx_t_1 = ((__pyx_v_self->__pyx_base.retval == -1L) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcalignmentfile.pyx":2085 + * return makeAlignedSegment(self.b, self.header) + * elif self.retval == -1: + * raise StopIteration # <<<<<<<<<<<<<< + * elif self.retval == -2: + * # Note: it is currently not the case that hts_iter_next + */ + __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); + __PYX_ERR(0, 2085, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":2084 * if self.retval >= 0: - * return makeAlignedSegment(self.b, self.samfile) + * return makeAlignedSegment(self.b, self.header) + * elif self.retval == -1: # <<<<<<<<<<<<<< + * raise StopIteration + * elif self.retval == -2: + */ + } + + /* "pysam/libcalignmentfile.pyx":2086 + * elif self.retval == -1: + * raise StopIteration * elif self.retval == -2: # <<<<<<<<<<<<<< * # Note: it is currently not the case that hts_iter_next * # returns -2 for a truncated file. @@ -20247,41 +25414,96 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_4__next __pyx_t_1 = ((__pyx_v_self->__pyx_base.retval == -2L) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":1737 + /* "pysam/libcalignmentfile.pyx":2090 * # returns -2 for a truncated file. * # See https://github.com/pysam-developers/pysam/pull/50#issuecomment-64928625 * raise IOError('truncated file') # <<<<<<<<<<<<<< * else: - * raise StopIteration + * raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval)) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1737, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__68, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2090, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1737, __pyx_L1_error) + __PYX_ERR(0, 2090, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1733 - * if self.retval >= 0: - * return makeAlignedSegment(self.b, self.samfile) + /* "pysam/libcalignmentfile.pyx":2086 + * elif self.retval == -1: + * raise StopIteration * elif self.retval == -2: # <<<<<<<<<<<<<< * # Note: it is currently not the case that hts_iter_next * # returns -2 for a truncated file. */ } - /* "pysam/libcalignmentfile.pyx":1739 + /* "pysam/libcalignmentfile.pyx":2092 * raise IOError('truncated file') * else: - * raise StopIteration # <<<<<<<<<<<<<< + * raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval)) # <<<<<<<<<<<<<< * * def __dealloc__(self): */ /*else*/ { - __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 1739, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_error_while_reading_file, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2092, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->__pyx_base.retval); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2092, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_self->__pyx_base.samfile->__pyx_base.filename, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2092, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_self->__pyx_base.samfile->__pyx_base.filename, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2092, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2092, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_v_self->__pyx_base.samfile->__pyx_base.filename); + __Pyx_GIVEREF(__pyx_v_self->__pyx_base.samfile->__pyx_base.filename); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_self->__pyx_base.samfile->__pyx_base.filename); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2092, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2092, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 2092, __pyx_L1_error) } - /* "pysam/libcalignmentfile.pyx":1729 + /* "pysam/libcalignmentfile.pyx":2080 * self.htsfile) * * def __next__(self): # <<<<<<<<<<<<<< @@ -20293,6 +25515,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_4__next __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -20302,8 +25527,8 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_4__next return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1741 - * raise StopIteration +/* "pysam/libcalignmentfile.pyx":2094 + * raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval)) * * def __dealloc__(self): # <<<<<<<<<<<<<< * hts_itr_destroy(self.iter) @@ -20325,9 +25550,9 @@ static void __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_6__dealloc__ __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1741, 0, __PYX_ERR(0, 1741, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2094, 0, __PYX_ERR(0, 2094, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1742 + /* "pysam/libcalignmentfile.pyx":2095 * * def __dealloc__(self): * hts_itr_destroy(self.iter) # <<<<<<<<<<<<<< @@ -20336,8 +25561,8 @@ static void __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_6__dealloc__ */ hts_itr_destroy(__pyx_v_self->iter); - /* "pysam/libcalignmentfile.pyx":1741 - * raise StopIteration + /* "pysam/libcalignmentfile.pyx":2094 + * raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval)) * * def __dealloc__(self): # <<<<<<<<<<<<<< * hts_itr_destroy(self.iter) @@ -20355,7 +25580,7 @@ static void __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_6__dealloc__ /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -20383,11 +25608,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_8__redu /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__55, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__69, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -20395,7 +25620,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_8__redu /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -20412,9 +25637,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_8__redu /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") */ /* Python wrapper */ @@ -20440,11 +25665,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_10__set __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__56, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__70, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -20452,9 +25677,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_10__set /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") */ /* function exit code */ @@ -20468,12 +25693,12 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_10__set return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1757 +/* "pysam/libcalignmentfile.pyx":2110 * """ * - * def __init__(self, AlignmentFile samfile, int n, # <<<<<<<<<<<<<< - * int multiple_iterators=False): - * + * def __init__(self, # <<<<<<<<<<<<<< + * AlignmentFile samfile, + * int n, */ /* Python wrapper */ @@ -20510,7 +25735,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_1__init__(PyObj case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); __PYX_ERR(0, 1757, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); __PYX_ERR(0, 2110, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: @@ -20520,7 +25745,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_1__init__(PyObj } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1757, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 2110, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -20533,14 +25758,14 @@ static int __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_1__init__(PyObj } } __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]); - __pyx_v_n = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1757, __pyx_L3_error) + __pyx_v_n = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2112, __pyx_L3_error) if (values[2]) { - __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1758, __pyx_L3_error) + __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2113, __pyx_L3_error) } else { - /* "pysam/libcalignmentfile.pyx":1758 - * - * def __init__(self, AlignmentFile samfile, int n, + /* "pysam/libcalignmentfile.pyx":2113 + * AlignmentFile samfile, + * int n, * int multiple_iterators=False): # <<<<<<<<<<<<<< * * IteratorRow.__init__(self, samfile, @@ -20550,21 +25775,21 @@ static int __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_1__init__(PyObj } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1757, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2110, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowHead.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 1757, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2111, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self), __pyx_v_samfile, __pyx_v_n, __pyx_v_multiple_iterators); - /* "pysam/libcalignmentfile.pyx":1757 + /* "pysam/libcalignmentfile.pyx":2110 * """ * - * def __init__(self, AlignmentFile samfile, int n, # <<<<<<<<<<<<<< - * int multiple_iterators=False): - * + * def __init__(self, # <<<<<<<<<<<<<< + * AlignmentFile samfile, + * int n, */ /* function exit code */ @@ -20585,18 +25810,18 @@ static int __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead___init__(struct PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1757, 0, __PYX_ERR(0, 1757, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 2110, 0, __PYX_ERR(0, 2110, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1760 + /* "pysam/libcalignmentfile.pyx":2115 * int multiple_iterators=False): * * IteratorRow.__init__(self, samfile, # <<<<<<<<<<<<<< * multiple_iterators=multiple_iterators) * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1760, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2115, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1760, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2115, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); @@ -20605,35 +25830,35 @@ static int __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead___init__(struct __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile)); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile)); - /* "pysam/libcalignmentfile.pyx":1761 + /* "pysam/libcalignmentfile.pyx":2116 * * IteratorRow.__init__(self, samfile, * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< * * self.max_rows = n */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1761, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2116, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1761, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2116, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 1761, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 2116, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":1760 + /* "pysam/libcalignmentfile.pyx":2115 * int multiple_iterators=False): * * IteratorRow.__init__(self, samfile, # <<<<<<<<<<<<<< * multiple_iterators=multiple_iterators) * */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1760, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2115, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":1763 + /* "pysam/libcalignmentfile.pyx":2118 * multiple_iterators=multiple_iterators) * * self.max_rows = n # <<<<<<<<<<<<<< @@ -20642,7 +25867,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead___init__(struct */ __pyx_v_self->max_rows = __pyx_v_n; - /* "pysam/libcalignmentfile.pyx":1764 + /* "pysam/libcalignmentfile.pyx":2119 * * self.max_rows = n * self.current_row = 0 # <<<<<<<<<<<<<< @@ -20651,12 +25876,12 @@ static int __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead___init__(struct */ __pyx_v_self->current_row = 0; - /* "pysam/libcalignmentfile.pyx":1757 + /* "pysam/libcalignmentfile.pyx":2110 * """ * - * def __init__(self, AlignmentFile samfile, int n, # <<<<<<<<<<<<<< - * int multiple_iterators=False): - * + * def __init__(self, # <<<<<<<<<<<<<< + * AlignmentFile samfile, + * int n, */ /* function exit code */ @@ -20675,7 +25900,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead___init__(struct return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1766 +/* "pysam/libcalignmentfile.pyx":2121 * self.current_row = 0 * * def __iter__(self): # <<<<<<<<<<<<<< @@ -20701,21 +25926,21 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_2__iter__ __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1766, 0, __PYX_ERR(0, 1766, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 2121, 0, __PYX_ERR(0, 2121, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1767 + /* "pysam/libcalignmentfile.pyx":2122 * * def __iter__(self): * return self # <<<<<<<<<<<<<< * - * cdef bam1_t * getCurrent( self ): + * cdef bam1_t * getCurrent(self): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1766 + /* "pysam/libcalignmentfile.pyx":2121 * self.current_row = 0 * * def __iter__(self): # <<<<<<<<<<<<<< @@ -20734,10 +25959,10 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_2__iter__ return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1769 +/* "pysam/libcalignmentfile.pyx":2124 * return self * - * cdef bam1_t * getCurrent( self ): # <<<<<<<<<<<<<< + * cdef bam1_t * getCurrent(self): # <<<<<<<<<<<<<< * return self.b * */ @@ -20747,11 +25972,11 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_getCurrent(s __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCurrent", 0); - __Pyx_TraceCall("getCurrent", __pyx_f[0], 1769, 0, __PYX_ERR(0, 1769, __pyx_L1_error)); + __Pyx_TraceCall("getCurrent", __pyx_f[0], 2124, 0, __PYX_ERR(0, 2124, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1770 + /* "pysam/libcalignmentfile.pyx":2125 * - * cdef bam1_t * getCurrent( self ): + * cdef bam1_t * getCurrent(self): * return self.b # <<<<<<<<<<<<<< * * cdef int cnext(self): @@ -20759,10 +25984,10 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_getCurrent(s __pyx_r = __pyx_v_self->__pyx_base.b; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1769 + /* "pysam/libcalignmentfile.pyx":2124 * return self * - * cdef bam1_t * getCurrent( self ): # <<<<<<<<<<<<<< + * cdef bam1_t * getCurrent(self): # <<<<<<<<<<<<<< * return self.b * */ @@ -20777,7 +26002,7 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_getCurrent(s return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1772 +/* "pysam/libcalignmentfile.pyx":2127 * return self.b * * cdef int cnext(self): # <<<<<<<<<<<<<< @@ -20787,18 +26012,30 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_getCurrent(s static int __pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self) { int __pyx_v_ret; + bam_hdr_t *__pyx_v_hdr; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations + bam_hdr_t *__pyx_t_1; __Pyx_RefNannySetupContext("cnext", 0); - __Pyx_TraceCall("cnext", __pyx_f[0], 1772, 0, __PYX_ERR(0, 1772, __pyx_L1_error)); + __Pyx_TraceCall("cnext", __pyx_f[0], 2127, 0, __PYX_ERR(0, 2127, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1775 + /* "pysam/libcalignmentfile.pyx":2130 * '''cversion of iterator. Used by IteratorColumn''' * cdef int ret + * cdef bam_hdr_t * hdr = self.header.ptr # <<<<<<<<<<<<<< + * with nogil: + * ret = sam_read1(self.htsfile, + */ + __pyx_t_1 = __pyx_v_self->__pyx_base.header->ptr; + __pyx_v_hdr = __pyx_t_1; + + /* "pysam/libcalignmentfile.pyx":2131 + * cdef int ret + * cdef bam_hdr_t * hdr = self.header.ptr * with nogil: # <<<<<<<<<<<<<< * ret = sam_read1(self.htsfile, - * self.samfile.header, + * hdr, */ { #ifdef WITH_THREAD @@ -20808,22 +26045,22 @@ static int __pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_cnext(struct __p #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1776 - * cdef int ret + /* "pysam/libcalignmentfile.pyx":2132 + * cdef bam_hdr_t * hdr = self.header.ptr * with nogil: * ret = sam_read1(self.htsfile, # <<<<<<<<<<<<<< - * self.samfile.header, + * hdr, * self.b) */ - __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->__pyx_base.samfile->header, __pyx_v_self->__pyx_base.b); + __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr, __pyx_v_self->__pyx_base.b); } - /* "pysam/libcalignmentfile.pyx":1775 - * '''cversion of iterator. Used by IteratorColumn''' + /* "pysam/libcalignmentfile.pyx":2131 * cdef int ret + * cdef bam_hdr_t * hdr = self.header.ptr * with nogil: # <<<<<<<<<<<<<< * ret = sam_read1(self.htsfile, - * self.samfile.header, + * hdr, */ /*finally:*/ { /*normal exit:*/{ @@ -20837,8 +26074,8 @@ static int __pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_cnext(struct __p } } - /* "pysam/libcalignmentfile.pyx":1779 - * self.samfile.header, + /* "pysam/libcalignmentfile.pyx":2135 + * hdr, * self.b) * return ret # <<<<<<<<<<<<<< * @@ -20847,7 +26084,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_cnext(struct __p __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1772 + /* "pysam/libcalignmentfile.pyx":2127 * return self.b * * cdef int cnext(self): # <<<<<<<<<<<<<< @@ -20865,7 +26102,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_cnext(struct __p return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1781 +/* "pysam/libcalignmentfile.pyx":2137 * return ret * * def __next__(self): # <<<<<<<<<<<<<< @@ -20895,9 +26132,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__ PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 1781, 0, __PYX_ERR(0, 1781, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 2137, 0, __PYX_ERR(0, 2137, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1782 + /* "pysam/libcalignmentfile.pyx":2138 * * def __next__(self): * if self.current_row >= self.max_rows: # <<<<<<<<<<<<<< @@ -20907,7 +26144,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__ __pyx_t_1 = ((__pyx_v_self->current_row >= __pyx_v_self->max_rows) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":1783 + /* "pysam/libcalignmentfile.pyx":2139 * def __next__(self): * if self.current_row >= self.max_rows: * raise StopIteration # <<<<<<<<<<<<<< @@ -20915,9 +26152,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__ * cdef int ret = self.cnext() */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 1783, __pyx_L1_error) + __PYX_ERR(0, 2139, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1782 + /* "pysam/libcalignmentfile.pyx":2138 * * def __next__(self): * if self.current_row >= self.max_rows: # <<<<<<<<<<<<<< @@ -20926,7 +26163,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__ */ } - /* "pysam/libcalignmentfile.pyx":1785 + /* "pysam/libcalignmentfile.pyx":2141 * raise StopIteration * * cdef int ret = self.cnext() # <<<<<<<<<<<<<< @@ -20935,54 +26172,54 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__ */ __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self); - /* "pysam/libcalignmentfile.pyx":1786 + /* "pysam/libcalignmentfile.pyx":2142 * * cdef int ret = self.cnext() * if ret >= 0: # <<<<<<<<<<<<<< * self.current_row += 1 - * return makeAlignedSegment(self.b, self.samfile) + * return makeAlignedSegment(self.b, self.header) */ __pyx_t_1 = ((__pyx_v_ret >= 0) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1787 + /* "pysam/libcalignmentfile.pyx":2143 * cdef int ret = self.cnext() * if ret >= 0: * self.current_row += 1 # <<<<<<<<<<<<<< - * return makeAlignedSegment(self.b, self.samfile) + * return makeAlignedSegment(self.b, self.header) * elif ret == -2: */ __pyx_v_self->current_row = (__pyx_v_self->current_row + 1); - /* "pysam/libcalignmentfile.pyx":1788 + /* "pysam/libcalignmentfile.pyx":2144 * if ret >= 0: * self.current_row += 1 - * return makeAlignedSegment(self.b, self.samfile) # <<<<<<<<<<<<<< + * return makeAlignedSegment(self.b, self.header) # <<<<<<<<<<<<<< * elif ret == -2: * raise IOError('truncated file') */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.samfile); + __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header); __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1788, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2144, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1786 + /* "pysam/libcalignmentfile.pyx":2142 * * cdef int ret = self.cnext() * if ret >= 0: # <<<<<<<<<<<<<< * self.current_row += 1 - * return makeAlignedSegment(self.b, self.samfile) + * return makeAlignedSegment(self.b, self.header) */ } - /* "pysam/libcalignmentfile.pyx":1789 + /* "pysam/libcalignmentfile.pyx":2145 * self.current_row += 1 - * return makeAlignedSegment(self.b, self.samfile) + * return makeAlignedSegment(self.b, self.header) * elif ret == -2: # <<<<<<<<<<<<<< * raise IOError('truncated file') * else: @@ -20990,29 +26227,29 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__ __pyx_t_1 = ((__pyx_v_ret == -2L) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":1790 - * return makeAlignedSegment(self.b, self.samfile) + /* "pysam/libcalignmentfile.pyx":2146 + * return makeAlignedSegment(self.b, self.header) * elif ret == -2: * raise IOError('truncated file') # <<<<<<<<<<<<<< * else: * raise StopIteration */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__57, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1790, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__71, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2146, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1790, __pyx_L1_error) + __PYX_ERR(0, 2146, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1789 + /* "pysam/libcalignmentfile.pyx":2145 * self.current_row += 1 - * return makeAlignedSegment(self.b, self.samfile) + * return makeAlignedSegment(self.b, self.header) * elif ret == -2: # <<<<<<<<<<<<<< * raise IOError('truncated file') * else: */ } - /* "pysam/libcalignmentfile.pyx":1792 + /* "pysam/libcalignmentfile.pyx":2148 * raise IOError('truncated file') * else: * raise StopIteration # <<<<<<<<<<<<<< @@ -21021,10 +26258,10 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__ */ /*else*/ { __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 1792, __pyx_L1_error) + __PYX_ERR(0, 2148, __pyx_L1_error) } - /* "pysam/libcalignmentfile.pyx":1781 + /* "pysam/libcalignmentfile.pyx":2137 * return ret * * def __next__(self): # <<<<<<<<<<<<<< @@ -21047,7 +26284,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__ /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -21075,11 +26312,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__58, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__72, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -21087,7 +26324,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -21104,9 +26341,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ /* Python wrapper */ @@ -21132,11 +26369,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_8__setsta __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__59, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__73, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -21144,9 +26381,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_8__setsta /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ /* function exit code */ @@ -21160,7 +26397,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_8__setsta return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1808 +/* "pysam/libcalignmentfile.pyx":2164 * """ * * def __init__(self, AlignmentFile samfile, # <<<<<<<<<<<<<< @@ -21203,7 +26440,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_1__init__(PyObje } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1808, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 2164, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -21216,10 +26453,10 @@ static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_1__init__(PyObje } __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]); if (values[1]) { - __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1809, __pyx_L3_error) + __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2165, __pyx_L3_error) } else { - /* "pysam/libcalignmentfile.pyx":1809 + /* "pysam/libcalignmentfile.pyx":2165 * * def __init__(self, AlignmentFile samfile, * int multiple_iterators=False): # <<<<<<<<<<<<<< @@ -21231,16 +26468,16 @@ static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_1__init__(PyObje } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1808, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2164, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAll.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 1808, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2164, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators); - /* "pysam/libcalignmentfile.pyx":1808 + /* "pysam/libcalignmentfile.pyx":2164 * """ * * def __init__(self, AlignmentFile samfile, # <<<<<<<<<<<<<< @@ -21266,18 +26503,18 @@ static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll___init__(struct PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1808, 0, __PYX_ERR(0, 1808, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 2164, 0, __PYX_ERR(0, 2164, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1811 + /* "pysam/libcalignmentfile.pyx":2167 * int multiple_iterators=False): * * IteratorRow.__init__(self, samfile, # <<<<<<<<<<<<<< * multiple_iterators=multiple_iterators) * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1811, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2167, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1811, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2167, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); @@ -21286,35 +26523,35 @@ static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll___init__(struct __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile)); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile)); - /* "pysam/libcalignmentfile.pyx":1812 + /* "pysam/libcalignmentfile.pyx":2168 * * IteratorRow.__init__(self, samfile, * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< * * def __iter__(self): */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1812, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2168, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1812, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2168, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 1812, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 2168, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":1811 + /* "pysam/libcalignmentfile.pyx":2167 * int multiple_iterators=False): * * IteratorRow.__init__(self, samfile, # <<<<<<<<<<<<<< * multiple_iterators=multiple_iterators) * */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1811, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2167, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":1808 + /* "pysam/libcalignmentfile.pyx":2164 * """ * * def __init__(self, AlignmentFile samfile, # <<<<<<<<<<<<<< @@ -21338,7 +26575,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll___init__(struct return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1814 +/* "pysam/libcalignmentfile.pyx":2170 * multiple_iterators=multiple_iterators) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -21364,21 +26601,21 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_2__iter__( __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1814, 0, __PYX_ERR(0, 1814, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 2170, 0, __PYX_ERR(0, 2170, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1815 + /* "pysam/libcalignmentfile.pyx":2171 * * def __iter__(self): * return self # <<<<<<<<<<<<<< * - * cdef bam1_t * getCurrent( self ): + * cdef bam1_t * getCurrent(self): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1814 + /* "pysam/libcalignmentfile.pyx":2170 * multiple_iterators=multiple_iterators) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -21397,10 +26634,10 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_2__iter__( return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1817 +/* "pysam/libcalignmentfile.pyx":2173 * return self * - * cdef bam1_t * getCurrent( self ): # <<<<<<<<<<<<<< + * cdef bam1_t * getCurrent(self): # <<<<<<<<<<<<<< * return self.b * */ @@ -21410,11 +26647,11 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_getCurrent(st __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCurrent", 0); - __Pyx_TraceCall("getCurrent", __pyx_f[0], 1817, 0, __PYX_ERR(0, 1817, __pyx_L1_error)); + __Pyx_TraceCall("getCurrent", __pyx_f[0], 2173, 0, __PYX_ERR(0, 2173, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1818 + /* "pysam/libcalignmentfile.pyx":2174 * - * cdef bam1_t * getCurrent( self ): + * cdef bam1_t * getCurrent(self): * return self.b # <<<<<<<<<<<<<< * * cdef int cnext(self): @@ -21422,10 +26659,10 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_getCurrent(st __pyx_r = __pyx_v_self->__pyx_base.b; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1817 + /* "pysam/libcalignmentfile.pyx":2173 * return self * - * cdef bam1_t * getCurrent( self ): # <<<<<<<<<<<<<< + * cdef bam1_t * getCurrent(self): # <<<<<<<<<<<<<< * return self.b * */ @@ -21440,7 +26677,7 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_getCurrent(st return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1820 +/* "pysam/libcalignmentfile.pyx":2176 * return self.b * * cdef int cnext(self): # <<<<<<<<<<<<<< @@ -21450,18 +26687,30 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_getCurrent(st static int __pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self) { int __pyx_v_ret; + bam_hdr_t *__pyx_v_hdr; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations + bam_hdr_t *__pyx_t_1; __Pyx_RefNannySetupContext("cnext", 0); - __Pyx_TraceCall("cnext", __pyx_f[0], 1820, 0, __PYX_ERR(0, 1820, __pyx_L1_error)); + __Pyx_TraceCall("cnext", __pyx_f[0], 2176, 0, __PYX_ERR(0, 2176, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1823 + /* "pysam/libcalignmentfile.pyx":2179 * '''cversion of iterator. Used by IteratorColumn''' * cdef int ret + * cdef bam_hdr_t * hdr = self.header.ptr # <<<<<<<<<<<<<< + * with nogil: + * ret = sam_read1(self.htsfile, + */ + __pyx_t_1 = __pyx_v_self->__pyx_base.header->ptr; + __pyx_v_hdr = __pyx_t_1; + + /* "pysam/libcalignmentfile.pyx":2180 + * cdef int ret + * cdef bam_hdr_t * hdr = self.header.ptr * with nogil: # <<<<<<<<<<<<<< * ret = sam_read1(self.htsfile, - * self.samfile.header, + * hdr, */ { #ifdef WITH_THREAD @@ -21471,22 +26720,22 @@ static int __pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext(struct __py #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1824 - * cdef int ret + /* "pysam/libcalignmentfile.pyx":2181 + * cdef bam_hdr_t * hdr = self.header.ptr * with nogil: * ret = sam_read1(self.htsfile, # <<<<<<<<<<<<<< - * self.samfile.header, + * hdr, * self.b) */ - __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->__pyx_base.samfile->header, __pyx_v_self->__pyx_base.b); + __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr, __pyx_v_self->__pyx_base.b); } - /* "pysam/libcalignmentfile.pyx":1823 - * '''cversion of iterator. Used by IteratorColumn''' + /* "pysam/libcalignmentfile.pyx":2180 * cdef int ret + * cdef bam_hdr_t * hdr = self.header.ptr * with nogil: # <<<<<<<<<<<<<< * ret = sam_read1(self.htsfile, - * self.samfile.header, + * hdr, */ /*finally:*/ { /*normal exit:*/{ @@ -21500,8 +26749,8 @@ static int __pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext(struct __py } } - /* "pysam/libcalignmentfile.pyx":1827 - * self.samfile.header, + /* "pysam/libcalignmentfile.pyx":2184 + * hdr, * self.b) * return ret # <<<<<<<<<<<<<< * @@ -21510,7 +26759,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext(struct __py __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1820 + /* "pysam/libcalignmentfile.pyx":2176 * return self.b * * cdef int cnext(self): # <<<<<<<<<<<<<< @@ -21528,7 +26777,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext(struct __py return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1829 +/* "pysam/libcalignmentfile.pyx":2186 * return ret * * def __next__(self): # <<<<<<<<<<<<<< @@ -21558,56 +26807,56 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_4__next__( PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 1829, 0, __PYX_ERR(0, 1829, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 2186, 0, __PYX_ERR(0, 2186, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1830 + /* "pysam/libcalignmentfile.pyx":2187 * * def __next__(self): * cdef int ret = self.cnext() # <<<<<<<<<<<<<< * if ret >= 0: - * return makeAlignedSegment(self.b, self.samfile) + * return makeAlignedSegment(self.b, self.header) */ __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self); - /* "pysam/libcalignmentfile.pyx":1831 + /* "pysam/libcalignmentfile.pyx":2188 * def __next__(self): * cdef int ret = self.cnext() * if ret >= 0: # <<<<<<<<<<<<<< - * return makeAlignedSegment(self.b, self.samfile) + * return makeAlignedSegment(self.b, self.header) * elif ret == -2: */ __pyx_t_1 = ((__pyx_v_ret >= 0) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1832 + /* "pysam/libcalignmentfile.pyx":2189 * cdef int ret = self.cnext() * if ret >= 0: - * return makeAlignedSegment(self.b, self.samfile) # <<<<<<<<<<<<<< + * return makeAlignedSegment(self.b, self.header) # <<<<<<<<<<<<<< * elif ret == -2: * raise IOError('truncated file') */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.samfile); + __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header); __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1832, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2189, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1831 + /* "pysam/libcalignmentfile.pyx":2188 * def __next__(self): * cdef int ret = self.cnext() * if ret >= 0: # <<<<<<<<<<<<<< - * return makeAlignedSegment(self.b, self.samfile) + * return makeAlignedSegment(self.b, self.header) * elif ret == -2: */ } - /* "pysam/libcalignmentfile.pyx":1833 + /* "pysam/libcalignmentfile.pyx":2190 * if ret >= 0: - * return makeAlignedSegment(self.b, self.samfile) + * return makeAlignedSegment(self.b, self.header) * elif ret == -2: # <<<<<<<<<<<<<< * raise IOError('truncated file') * else: @@ -21615,29 +26864,29 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_4__next__( __pyx_t_1 = ((__pyx_v_ret == -2L) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":1834 - * return makeAlignedSegment(self.b, self.samfile) + /* "pysam/libcalignmentfile.pyx":2191 + * return makeAlignedSegment(self.b, self.header) * elif ret == -2: * raise IOError('truncated file') # <<<<<<<<<<<<<< * else: * raise StopIteration */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__60, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1834, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__74, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2191, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1834, __pyx_L1_error) + __PYX_ERR(0, 2191, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1833 + /* "pysam/libcalignmentfile.pyx":2190 * if ret >= 0: - * return makeAlignedSegment(self.b, self.samfile) + * return makeAlignedSegment(self.b, self.header) * elif ret == -2: # <<<<<<<<<<<<<< * raise IOError('truncated file') * else: */ } - /* "pysam/libcalignmentfile.pyx":1836 + /* "pysam/libcalignmentfile.pyx":2193 * raise IOError('truncated file') * else: * raise StopIteration # <<<<<<<<<<<<<< @@ -21646,10 +26895,10 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_4__next__( */ /*else*/ { __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 1836, __pyx_L1_error) + __PYX_ERR(0, 2193, __pyx_L1_error) } - /* "pysam/libcalignmentfile.pyx":1829 + /* "pysam/libcalignmentfile.pyx":2186 * return ret * * def __next__(self): # <<<<<<<<<<<<<< @@ -21672,7 +26921,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_4__next__( /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -21700,11 +26949,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_ /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__61, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -21712,7 +26961,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_ /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -21729,9 +26978,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_ /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ /* Python wrapper */ @@ -21757,11 +27006,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstat __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__76, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -21769,9 +27018,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstat /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ /* function exit code */ @@ -21785,7 +27034,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstat return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1850 +/* "pysam/libcalignmentfile.pyx":2207 * """ * * def __init__(self, AlignmentFile samfile, # <<<<<<<<<<<<<< @@ -21805,7 +27054,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_1__init__(Py static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_multiple_iterators,0}; PyObject* values[2] = {0,0}; - /* "pysam/libcalignmentfile.pyx":1851 + /* "pysam/libcalignmentfile.pyx":2208 * * def __init__(self, AlignmentFile samfile, * multiple_iterators=False): # <<<<<<<<<<<<<< @@ -21837,7 +27086,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_1__init__(Py } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1850, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 2207, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -21853,16 +27102,16 @@ static int __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_1__init__(Py } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1850, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2207, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAllRefs.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 1850, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2207, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators); - /* "pysam/libcalignmentfile.pyx":1850 + /* "pysam/libcalignmentfile.pyx":2207 * """ * * def __init__(self, AlignmentFile samfile, # <<<<<<<<<<<<<< @@ -21890,18 +27139,18 @@ static int __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(str int __pyx_t_5; int __pyx_t_6; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1850, 0, __PYX_ERR(0, 1850, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 2207, 0, __PYX_ERR(0, 2207, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1853 + /* "pysam/libcalignmentfile.pyx":2210 * multiple_iterators=False): * * IteratorRow.__init__(self, samfile, # <<<<<<<<<<<<<< * multiple_iterators=multiple_iterators) * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1853, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2210, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1853, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2210, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); @@ -21910,39 +27159,39 @@ static int __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(str __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile)); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile)); - /* "pysam/libcalignmentfile.pyx":1854 + /* "pysam/libcalignmentfile.pyx":2211 * * IteratorRow.__init__(self, samfile, * multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< * * if not samfile.has_index(): */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1854, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2211, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1854, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 2211, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1853 + /* "pysam/libcalignmentfile.pyx":2210 * multiple_iterators=False): * * IteratorRow.__init__(self, samfile, # <<<<<<<<<<<<<< * multiple_iterators=multiple_iterators) * */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1853, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2210, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":1856 + /* "pysam/libcalignmentfile.pyx":2213 * multiple_iterators=multiple_iterators) * * if not samfile.has_index(): # <<<<<<<<<<<<<< * raise ValueError("no index available for fetch") * */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_has_index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1856, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_has_index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2213, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { @@ -21955,32 +27204,32 @@ static int __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(str } } if (__pyx_t_2) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1856, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2213, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { - __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1856, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2213, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1856, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2213, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_6 = ((!__pyx_t_5) != 0); if (unlikely(__pyx_t_6)) { - /* "pysam/libcalignmentfile.pyx":1857 + /* "pysam/libcalignmentfile.pyx":2214 * * if not samfile.has_index(): * raise ValueError("no index available for fetch") # <<<<<<<<<<<<<< * * self.tid = -1 */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__63, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1857, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__77, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1857, __pyx_L1_error) + __PYX_ERR(0, 2214, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1856 + /* "pysam/libcalignmentfile.pyx":2213 * multiple_iterators=multiple_iterators) * * if not samfile.has_index(): # <<<<<<<<<<<<<< @@ -21989,7 +27238,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(str */ } - /* "pysam/libcalignmentfile.pyx":1859 + /* "pysam/libcalignmentfile.pyx":2216 * raise ValueError("no index available for fetch") * * self.tid = -1 # <<<<<<<<<<<<<< @@ -21998,7 +27247,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(str */ __pyx_v_self->tid = -1; - /* "pysam/libcalignmentfile.pyx":1850 + /* "pysam/libcalignmentfile.pyx":2207 * """ * * def __init__(self, AlignmentFile samfile, # <<<<<<<<<<<<<< @@ -22022,7 +27271,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(str return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1861 +/* "pysam/libcalignmentfile.pyx":2218 * self.tid = -1 * * def nextiter(self): # <<<<<<<<<<<<<< @@ -22051,28 +27300,27 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nexti PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; htsFile *__pyx_t_3; - bam_hdr_t *__pyx_t_4; __Pyx_RefNannySetupContext("nextiter", 0); - __Pyx_TraceCall("nextiter", __pyx_f[0], 1861, 0, __PYX_ERR(0, 1861, __pyx_L1_error)); + __Pyx_TraceCall("nextiter", __pyx_f[0], 2218, 0, __PYX_ERR(0, 2218, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1865 + /* "pysam/libcalignmentfile.pyx":2222 * # will not be re-opened. * self.rowiter = IteratorRowRegion(self.samfile, * self.tid, # <<<<<<<<<<<<<< * 0, * 1<<29) */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1865, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2222, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libcalignmentfile.pyx":1864 + /* "pysam/libcalignmentfile.pyx":2221 * # get a new iterator for a chromosome. The file * # will not be re-opened. * self.rowiter = IteratorRowRegion(self.samfile, # <<<<<<<<<<<<<< * self.tid, * 0, */ - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1864, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2221, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self->__pyx_base.samfile)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self->__pyx_base.samfile)); @@ -22086,7 +27334,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nexti __Pyx_GIVEREF(__pyx_int_536870912); PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_int_536870912); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1864, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2221, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GIVEREF(__pyx_t_1); @@ -22095,7 +27343,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nexti __pyx_v_self->rowiter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1870 + /* "pysam/libcalignmentfile.pyx":2227 * # set htsfile and header of the rowiter * # to the values in this iterator to reflect multiple_iterators * self.rowiter.htsfile = self.htsfile # <<<<<<<<<<<<<< @@ -22105,17 +27353,22 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nexti __pyx_t_3 = __pyx_v_self->__pyx_base.htsfile; __pyx_v_self->rowiter->__pyx_base.htsfile = __pyx_t_3; - /* "pysam/libcalignmentfile.pyx":1871 + /* "pysam/libcalignmentfile.pyx":2228 * # to the values in this iterator to reflect multiple_iterators * self.rowiter.htsfile = self.htsfile * self.rowiter.header = self.header # <<<<<<<<<<<<<< * * # make sure the iterator understand that IteratorRowAllRefs */ - __pyx_t_4 = __pyx_v_self->__pyx_base.header; - __pyx_v_self->rowiter->__pyx_base.header = __pyx_t_4; + __pyx_t_1 = ((PyObject *)__pyx_v_self->__pyx_base.header); + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->rowiter->__pyx_base.header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->rowiter->__pyx_base.header)); + __pyx_v_self->rowiter->__pyx_base.header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1875 + /* "pysam/libcalignmentfile.pyx":2232 * # make sure the iterator understand that IteratorRowAllRefs * # has ownership * self.rowiter.owns_samfile = False # <<<<<<<<<<<<<< @@ -22124,7 +27377,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nexti */ __pyx_v_self->rowiter->__pyx_base.owns_samfile = 0; - /* "pysam/libcalignmentfile.pyx":1861 + /* "pysam/libcalignmentfile.pyx":2218 * self.tid = -1 * * def nextiter(self): # <<<<<<<<<<<<<< @@ -22147,7 +27400,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nexti return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1877 +/* "pysam/libcalignmentfile.pyx":2234 * self.rowiter.owns_samfile = False * * def __iter__(self): # <<<<<<<<<<<<<< @@ -22173,9 +27426,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_4__ite __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1877, 0, __PYX_ERR(0, 1877, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 2234, 0, __PYX_ERR(0, 2234, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1878 + /* "pysam/libcalignmentfile.pyx":2235 * * def __iter__(self): * return self # <<<<<<<<<<<<<< @@ -22187,7 +27440,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_4__ite __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1877 + /* "pysam/libcalignmentfile.pyx":2234 * self.rowiter.owns_samfile = False * * def __iter__(self): # <<<<<<<<<<<<<< @@ -22206,7 +27459,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_4__ite return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1880 +/* "pysam/libcalignmentfile.pyx":2237 * return self * * def __next__(self): # <<<<<<<<<<<<<< @@ -22237,9 +27490,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 1880, 0, __PYX_ERR(0, 1880, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 2237, 0, __PYX_ERR(0, 2237, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1882 + /* "pysam/libcalignmentfile.pyx":2239 * def __next__(self): * # Create an initial iterator * if self.tid == -1: # <<<<<<<<<<<<<< @@ -22249,21 +27502,21 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex __pyx_t_1 = ((__pyx_v_self->tid == -1L) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1883 + /* "pysam/libcalignmentfile.pyx":2240 * # Create an initial iterator * if self.tid == -1: * if not self.samfile.nreferences: # <<<<<<<<<<<<<< * raise StopIteration * self.tid = 0 */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1883, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2240, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1883, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2240, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_3 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":1884 + /* "pysam/libcalignmentfile.pyx":2241 * if self.tid == -1: * if not self.samfile.nreferences: * raise StopIteration # <<<<<<<<<<<<<< @@ -22271,9 +27524,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex * self.nextiter() */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 1884, __pyx_L1_error) + __PYX_ERR(0, 2241, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1883 + /* "pysam/libcalignmentfile.pyx":2240 * # Create an initial iterator * if self.tid == -1: * if not self.samfile.nreferences: # <<<<<<<<<<<<<< @@ -22282,7 +27535,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex */ } - /* "pysam/libcalignmentfile.pyx":1885 + /* "pysam/libcalignmentfile.pyx":2242 * if not self.samfile.nreferences: * raise StopIteration * self.tid = 0 # <<<<<<<<<<<<<< @@ -22291,14 +27544,14 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex */ __pyx_v_self->tid = 0; - /* "pysam/libcalignmentfile.pyx":1886 + /* "pysam/libcalignmentfile.pyx":2243 * raise StopIteration * self.tid = 0 * self.nextiter() # <<<<<<<<<<<<<< * * while 1: */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nextiter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1886, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nextiter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2243, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { @@ -22311,16 +27564,16 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex } } if (__pyx_t_5) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1886, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2243, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1886, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2243, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcalignmentfile.pyx":1882 + /* "pysam/libcalignmentfile.pyx":2239 * def __next__(self): * # Create an initial iterator * if self.tid == -1: # <<<<<<<<<<<<<< @@ -22329,7 +27582,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex */ } - /* "pysam/libcalignmentfile.pyx":1888 + /* "pysam/libcalignmentfile.pyx":2245 * self.nextiter() * * while 1: # <<<<<<<<<<<<<< @@ -22338,7 +27591,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex */ while (1) { - /* "pysam/libcalignmentfile.pyx":1889 + /* "pysam/libcalignmentfile.pyx":2246 * * while 1: * self.rowiter.cnext() # <<<<<<<<<<<<<< @@ -22347,44 +27600,44 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex */ (void)(((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self->rowiter->__pyx_vtab)->cnext(__pyx_v_self->rowiter)); - /* "pysam/libcalignmentfile.pyx":1892 + /* "pysam/libcalignmentfile.pyx":2249 * * # If current iterator is not exhausted, return aligned read * if self.rowiter.retval > 0: # <<<<<<<<<<<<<< - * return makeAlignedSegment(self.rowiter.b, self.samfile) + * return makeAlignedSegment(self.rowiter.b, self.header) * */ __pyx_t_3 = ((__pyx_v_self->rowiter->__pyx_base.retval > 0) != 0); if (__pyx_t_3) { - /* "pysam/libcalignmentfile.pyx":1893 + /* "pysam/libcalignmentfile.pyx":2250 * # If current iterator is not exhausted, return aligned read * if self.rowiter.retval > 0: - * return makeAlignedSegment(self.rowiter.b, self.samfile) # <<<<<<<<<<<<<< + * return makeAlignedSegment(self.rowiter.b, self.header) # <<<<<<<<<<<<<< * * self.tid += 1 */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.samfile); + __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header); __Pyx_INCREF(__pyx_t_2); - __pyx_t_4 = __pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->rowiter->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1893, __pyx_L1_error) + __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->rowiter->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2250, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1892 + /* "pysam/libcalignmentfile.pyx":2249 * * # If current iterator is not exhausted, return aligned read * if self.rowiter.retval > 0: # <<<<<<<<<<<<<< - * return makeAlignedSegment(self.rowiter.b, self.samfile) + * return makeAlignedSegment(self.rowiter.b, self.header) * */ } - /* "pysam/libcalignmentfile.pyx":1895 - * return makeAlignedSegment(self.rowiter.b, self.samfile) + /* "pysam/libcalignmentfile.pyx":2252 + * return makeAlignedSegment(self.rowiter.b, self.header) * * self.tid += 1 # <<<<<<<<<<<<<< * @@ -22392,32 +27645,32 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex */ __pyx_v_self->tid = (__pyx_v_self->tid + 1); - /* "pysam/libcalignmentfile.pyx":1898 + /* "pysam/libcalignmentfile.pyx":2255 * * # Otherwise, proceed to next reference or stop * if self.tid < self.samfile.nreferences: # <<<<<<<<<<<<<< * self.nextiter() * else: */ - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1898, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2255, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1898, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2255, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1898, __pyx_L1_error) + __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2255, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1898, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2255, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (likely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":1899 + /* "pysam/libcalignmentfile.pyx":2256 * # Otherwise, proceed to next reference or stop * if self.tid < self.samfile.nreferences: * self.nextiter() # <<<<<<<<<<<<<< * else: * raise StopIteration */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nextiter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1899, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nextiter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2256, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -22430,16 +27683,16 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex } } if (__pyx_t_4) { - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1899, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2256, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { - __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1899, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2256, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":1898 + /* "pysam/libcalignmentfile.pyx":2255 * * # Otherwise, proceed to next reference or stop * if self.tid < self.samfile.nreferences: # <<<<<<<<<<<<<< @@ -22449,7 +27702,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex goto __pyx_L8; } - /* "pysam/libcalignmentfile.pyx":1901 + /* "pysam/libcalignmentfile.pyx":2258 * self.nextiter() * else: * raise StopIteration # <<<<<<<<<<<<<< @@ -22458,12 +27711,12 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex */ /*else*/ { __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 1901, __pyx_L1_error) + __PYX_ERR(0, 2258, __pyx_L1_error) } __pyx_L8:; } - /* "pysam/libcalignmentfile.pyx":1880 + /* "pysam/libcalignmentfile.pyx":2237 * return self * * def __next__(self): # <<<<<<<<<<<<<< @@ -22489,7 +27742,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__nex /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -22517,11 +27770,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__red /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__78, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -22529,7 +27782,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__red /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -22546,9 +27799,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__red /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ /* Python wrapper */ @@ -22574,11 +27827,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__se __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__65, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__79, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -22586,9 +27839,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__se /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ /* function exit code */ @@ -22602,7 +27855,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__se return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1914 +/* "pysam/libcalignmentfile.pyx":2271 * """ * * def __init__(self, AlignmentFile samfile, positions, int multiple_iterators=True): # <<<<<<<<<<<<<< @@ -22644,7 +27897,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_1__init__( case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_positions)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); __PYX_ERR(0, 1914, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); __PYX_ERR(0, 2271, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: @@ -22654,7 +27907,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_1__init__( } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1914, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 2271, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -22669,20 +27922,20 @@ static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_1__init__( __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]); __pyx_v_positions = values[1]; if (values[2]) { - __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1914, __pyx_L3_error) + __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2271, __pyx_L3_error) } else { __pyx_v_multiple_iterators = ((int)1); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1914, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2271, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowSelection.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 1914, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2271, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self), __pyx_v_samfile, __pyx_v_positions, __pyx_v_multiple_iterators); /* function exit code */ @@ -22703,18 +27956,18 @@ static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection___init__(s PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1914, 0, __PYX_ERR(0, 1914, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 2271, 0, __PYX_ERR(0, 2271, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1916 + /* "pysam/libcalignmentfile.pyx":2273 * def __init__(self, AlignmentFile samfile, positions, int multiple_iterators=True): * * IteratorRow.__init__(self, samfile, multiple_iterators=multiple_iterators) # <<<<<<<<<<<<<< * * self.positions = positions */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1916, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2273, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1916, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2273, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); @@ -22722,20 +27975,20 @@ static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection___init__(s __Pyx_INCREF(((PyObject *)__pyx_v_samfile)); __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile)); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile)); - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1916, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2273, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1916, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2273, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 1916, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 2273, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1916, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2273, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":1918 + /* "pysam/libcalignmentfile.pyx":2275 * IteratorRow.__init__(self, samfile, multiple_iterators=multiple_iterators) * * self.positions = positions # <<<<<<<<<<<<<< @@ -22748,7 +28001,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection___init__(s __Pyx_DECREF(__pyx_v_self->positions); __pyx_v_self->positions = __pyx_v_positions; - /* "pysam/libcalignmentfile.pyx":1919 + /* "pysam/libcalignmentfile.pyx":2276 * * self.positions = positions * self.current_pos = 0 # <<<<<<<<<<<<<< @@ -22757,7 +28010,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection___init__(s */ __pyx_v_self->current_pos = 0; - /* "pysam/libcalignmentfile.pyx":1914 + /* "pysam/libcalignmentfile.pyx":2271 * """ * * def __init__(self, AlignmentFile samfile, positions, int multiple_iterators=True): # <<<<<<<<<<<<<< @@ -22781,7 +28034,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection___init__(s return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1921 +/* "pysam/libcalignmentfile.pyx":2278 * self.current_pos = 0 * * def __iter__(self): # <<<<<<<<<<<<<< @@ -22807,9 +28060,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_2__i __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1921, 0, __PYX_ERR(0, 1921, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 2278, 0, __PYX_ERR(0, 2278, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1922 + /* "pysam/libcalignmentfile.pyx":2279 * * def __iter__(self): * return self # <<<<<<<<<<<<<< @@ -22821,7 +28074,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_2__i __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1921 + /* "pysam/libcalignmentfile.pyx":2278 * self.current_pos = 0 * * def __iter__(self): # <<<<<<<<<<<<<< @@ -22840,7 +28093,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_2__i return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1924 +/* "pysam/libcalignmentfile.pyx":2281 * return self * * cdef bam1_t * getCurrent(self): # <<<<<<<<<<<<<< @@ -22853,9 +28106,9 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_getCurr __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCurrent", 0); - __Pyx_TraceCall("getCurrent", __pyx_f[0], 1924, 0, __PYX_ERR(0, 1924, __pyx_L1_error)); + __Pyx_TraceCall("getCurrent", __pyx_f[0], 2281, 0, __PYX_ERR(0, 2281, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1925 + /* "pysam/libcalignmentfile.pyx":2282 * * cdef bam1_t * getCurrent(self): * return self.b # <<<<<<<<<<<<<< @@ -22865,7 +28118,7 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_getCurr __pyx_r = __pyx_v_self->__pyx_base.b; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1924 + /* "pysam/libcalignmentfile.pyx":2281 * return self * * cdef bam1_t * getCurrent(self): # <<<<<<<<<<<<<< @@ -22883,7 +28136,7 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_getCurr return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1927 +/* "pysam/libcalignmentfile.pyx":2284 * return self.b * * cdef int cnext(self): # <<<<<<<<<<<<<< @@ -22894,6 +28147,7 @@ static bam1_t *__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_getCurr static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self) { uint64_t __pyx_v_pos; int __pyx_v_ret; + bam_hdr_t *__pyx_v_hdr; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -22901,10 +28155,11 @@ static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struc Py_ssize_t __pyx_t_2; int __pyx_t_3; uint64_t __pyx_t_4; + bam_hdr_t *__pyx_t_5; __Pyx_RefNannySetupContext("cnext", 0); - __Pyx_TraceCall("cnext", __pyx_f[0], 1927, 0, __PYX_ERR(0, 1927, __pyx_L1_error)); + __Pyx_TraceCall("cnext", __pyx_f[0], 2284, 0, __PYX_ERR(0, 2284, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1930 + /* "pysam/libcalignmentfile.pyx":2287 * '''cversion of iterator''' * # end iteration if out of positions * if self.current_pos >= len(self.positions): return -1 # <<<<<<<<<<<<<< @@ -22913,7 +28168,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struc */ __pyx_t_1 = __pyx_v_self->positions; __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1930, __pyx_L1_error) + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2287, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = ((__pyx_v_self->current_pos >= __pyx_t_2) != 0); if (__pyx_t_3) { @@ -22921,20 +28176,20 @@ static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struc goto __pyx_L0; } - /* "pysam/libcalignmentfile.pyx":1932 + /* "pysam/libcalignmentfile.pyx":2289 * if self.current_pos >= len(self.positions): return -1 * * cdef uint64_t pos = self.positions[self.current_pos] # <<<<<<<<<<<<<< * with nogil: * bgzf_seek(hts_get_bgzfp(self.htsfile), */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->positions, __pyx_v_self->current_pos, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1932, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->positions, __pyx_v_self->current_pos, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2289, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyInt_As_uint64_t(__pyx_t_1); if (unlikely((__pyx_t_4 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1932, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_As_uint64_t(__pyx_t_1); if (unlikely((__pyx_t_4 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2289, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_pos = __pyx_t_4; - /* "pysam/libcalignmentfile.pyx":1933 + /* "pysam/libcalignmentfile.pyx":2290 * * cdef uint64_t pos = self.positions[self.current_pos] * with nogil: # <<<<<<<<<<<<<< @@ -22949,7 +28204,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struc #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1934 + /* "pysam/libcalignmentfile.pyx":2291 * cdef uint64_t pos = self.positions[self.current_pos] * with nogil: * bgzf_seek(hts_get_bgzfp(self.htsfile), # <<<<<<<<<<<<<< @@ -22959,7 +28214,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struc (void)(bgzf_seek(hts_get_bgzfp(__pyx_v_self->__pyx_base.htsfile), __pyx_v_pos, 0)); } - /* "pysam/libcalignmentfile.pyx":1933 + /* "pysam/libcalignmentfile.pyx":2290 * * cdef uint64_t pos = self.positions[self.current_pos] * with nogil: # <<<<<<<<<<<<<< @@ -22978,7 +28233,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struc } } - /* "pysam/libcalignmentfile.pyx":1937 + /* "pysam/libcalignmentfile.pyx":2294 * pos, * 0) * self.current_pos += 1 # <<<<<<<<<<<<<< @@ -22987,12 +28242,22 @@ static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struc */ __pyx_v_self->current_pos = (__pyx_v_self->current_pos + 1); - /* "pysam/libcalignmentfile.pyx":1940 + /* "pysam/libcalignmentfile.pyx":2297 * * cdef int ret + * cdef bam_hdr_t * hdr = self.header.ptr # <<<<<<<<<<<<<< + * with nogil: + * ret = sam_read1(self.htsfile, + */ + __pyx_t_5 = __pyx_v_self->__pyx_base.header->ptr; + __pyx_v_hdr = __pyx_t_5; + + /* "pysam/libcalignmentfile.pyx":2298 + * cdef int ret + * cdef bam_hdr_t * hdr = self.header.ptr * with nogil: # <<<<<<<<<<<<<< * ret = sam_read1(self.htsfile, - * self.samfile.header, + * hdr, */ { #ifdef WITH_THREAD @@ -23002,22 +28267,22 @@ static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struc #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1941 - * cdef int ret + /* "pysam/libcalignmentfile.pyx":2299 + * cdef bam_hdr_t * hdr = self.header.ptr * with nogil: * ret = sam_read1(self.htsfile, # <<<<<<<<<<<<<< - * self.samfile.header, + * hdr, * self.b) */ - __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->__pyx_base.samfile->header, __pyx_v_self->__pyx_base.b); + __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr, __pyx_v_self->__pyx_base.b); } - /* "pysam/libcalignmentfile.pyx":1940 - * + /* "pysam/libcalignmentfile.pyx":2298 * cdef int ret + * cdef bam_hdr_t * hdr = self.header.ptr * with nogil: # <<<<<<<<<<<<<< * ret = sam_read1(self.htsfile, - * self.samfile.header, + * hdr, */ /*finally:*/ { /*normal exit:*/{ @@ -23031,8 +28296,8 @@ static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struc } } - /* "pysam/libcalignmentfile.pyx":1944 - * self.samfile.header, + /* "pysam/libcalignmentfile.pyx":2302 + * hdr, * self.b) * return ret # <<<<<<<<<<<<<< * @@ -23041,7 +28306,7 @@ static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struc __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1927 + /* "pysam/libcalignmentfile.pyx":2284 * return self.b * * cdef int cnext(self): # <<<<<<<<<<<<<< @@ -23060,12 +28325,12 @@ static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struc return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1946 +/* "pysam/libcalignmentfile.pyx":2304 * return ret * * def __next__(self): # <<<<<<<<<<<<<< * cdef int ret = self.cnext() - * if (ret >= 0): + * if ret >= 0: */ /* Python wrapper */ @@ -23090,86 +28355,86 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_4__n PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 1946, 0, __PYX_ERR(0, 1946, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 2304, 0, __PYX_ERR(0, 2304, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1947 + /* "pysam/libcalignmentfile.pyx":2305 * * def __next__(self): * cdef int ret = self.cnext() # <<<<<<<<<<<<<< - * if (ret >= 0): - * return makeAlignedSegment(self.b, self.samfile) + * if ret >= 0: + * return makeAlignedSegment(self.b, self.header) */ __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self); - /* "pysam/libcalignmentfile.pyx":1948 + /* "pysam/libcalignmentfile.pyx":2306 * def __next__(self): * cdef int ret = self.cnext() - * if (ret >= 0): # <<<<<<<<<<<<<< - * return makeAlignedSegment(self.b, self.samfile) - * elif (ret == -2): + * if ret >= 0: # <<<<<<<<<<<<<< + * return makeAlignedSegment(self.b, self.header) + * elif ret == -2: */ __pyx_t_1 = ((__pyx_v_ret >= 0) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":1949 + /* "pysam/libcalignmentfile.pyx":2307 * cdef int ret = self.cnext() - * if (ret >= 0): - * return makeAlignedSegment(self.b, self.samfile) # <<<<<<<<<<<<<< - * elif (ret == -2): + * if ret >= 0: + * return makeAlignedSegment(self.b, self.header) # <<<<<<<<<<<<<< + * elif ret == -2: * raise IOError('truncated file') */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.samfile); + __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header); __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1949, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1948 + /* "pysam/libcalignmentfile.pyx":2306 * def __next__(self): * cdef int ret = self.cnext() - * if (ret >= 0): # <<<<<<<<<<<<<< - * return makeAlignedSegment(self.b, self.samfile) - * elif (ret == -2): + * if ret >= 0: # <<<<<<<<<<<<<< + * return makeAlignedSegment(self.b, self.header) + * elif ret == -2: */ } - /* "pysam/libcalignmentfile.pyx":1950 - * if (ret >= 0): - * return makeAlignedSegment(self.b, self.samfile) - * elif (ret == -2): # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2308 + * if ret >= 0: + * return makeAlignedSegment(self.b, self.header) + * elif ret == -2: # <<<<<<<<<<<<<< * raise IOError('truncated file') * else: */ __pyx_t_1 = ((__pyx_v_ret == -2L) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":1951 - * return makeAlignedSegment(self.b, self.samfile) - * elif (ret == -2): + /* "pysam/libcalignmentfile.pyx":2309 + * return makeAlignedSegment(self.b, self.header) + * elif ret == -2: * raise IOError('truncated file') # <<<<<<<<<<<<<< * else: * raise StopIteration */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__66, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1951, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__80, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2309, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1951, __pyx_L1_error) + __PYX_ERR(0, 2309, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":1950 - * if (ret >= 0): - * return makeAlignedSegment(self.b, self.samfile) - * elif (ret == -2): # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2308 + * if ret >= 0: + * return makeAlignedSegment(self.b, self.header) + * elif ret == -2: # <<<<<<<<<<<<<< * raise IOError('truncated file') * else: */ } - /* "pysam/libcalignmentfile.pyx":1953 + /* "pysam/libcalignmentfile.pyx":2311 * raise IOError('truncated file') * else: * raise StopIteration # <<<<<<<<<<<<<< @@ -23178,15 +28443,15 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_4__n */ /*else*/ { __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 1953, __pyx_L1_error) + __PYX_ERR(0, 2311, __pyx_L1_error) } - /* "pysam/libcalignmentfile.pyx":1946 + /* "pysam/libcalignmentfile.pyx":2304 * return ret * * def __next__(self): # <<<<<<<<<<<<<< * cdef int ret = self.cnext() - * if (ret >= 0): + * if ret >= 0: */ /* function exit code */ @@ -23204,7 +28469,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_4__n /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -23232,11 +28497,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_6__r /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__67, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__81, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -23244,7 +28509,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_6__r /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -23261,9 +28526,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_6__r /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ /* Python wrapper */ @@ -23289,11 +28554,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_8__s __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__68, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__82, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -23301,9 +28566,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_8__s /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ /* function exit code */ @@ -23317,7 +28582,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_8__s return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1956 +/* "pysam/libcalignmentfile.pyx":2314 * * * cdef int __advance_nofilter(void *data, bam1_t *b): # <<<<<<<<<<<<<< @@ -23332,19 +28597,19 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_nofilter(void *__pyx_v_d __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__advance_nofilter", 0); - __Pyx_TraceCall("__advance_nofilter", __pyx_f[0], 1956, 0, __PYX_ERR(0, 1956, __pyx_L1_error)); + __Pyx_TraceCall("__advance_nofilter", __pyx_f[0], 2314, 0, __PYX_ERR(0, 2314, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1960 + /* "pysam/libcalignmentfile.pyx":2317 + * '''advance without any read filtering. * ''' - * cdef __iterdata * d - * d = <__iterdata*>data # <<<<<<<<<<<<<< + * cdef __iterdata * d = <__iterdata*>data # <<<<<<<<<<<<<< * cdef int ret * with nogil: */ __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data); - /* "pysam/libcalignmentfile.pyx":1962 - * d = <__iterdata*>data + /* "pysam/libcalignmentfile.pyx":2319 + * cdef __iterdata * d = <__iterdata*>data * cdef int ret * with nogil: # <<<<<<<<<<<<<< * ret = sam_itr_next(d.htsfile, d.iter, b) @@ -23358,7 +28623,7 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_nofilter(void *__pyx_v_d #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1963 + /* "pysam/libcalignmentfile.pyx":2320 * cdef int ret * with nogil: * ret = sam_itr_next(d.htsfile, d.iter, b) # <<<<<<<<<<<<<< @@ -23368,8 +28633,8 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_nofilter(void *__pyx_v_d __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b); } - /* "pysam/libcalignmentfile.pyx":1962 - * d = <__iterdata*>data + /* "pysam/libcalignmentfile.pyx":2319 + * cdef __iterdata * d = <__iterdata*>data * cdef int ret * with nogil: # <<<<<<<<<<<<<< * ret = sam_itr_next(d.htsfile, d.iter, b) @@ -23387,7 +28652,7 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_nofilter(void *__pyx_v_d } } - /* "pysam/libcalignmentfile.pyx":1964 + /* "pysam/libcalignmentfile.pyx":2321 * with nogil: * ret = sam_itr_next(d.htsfile, d.iter, b) * return ret # <<<<<<<<<<<<<< @@ -23397,7 +28662,7 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_nofilter(void *__pyx_v_d __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1956 + /* "pysam/libcalignmentfile.pyx":2314 * * * cdef int __advance_nofilter(void *data, bam1_t *b): # <<<<<<<<<<<<<< @@ -23415,166 +28680,171 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_nofilter(void *__pyx_v_d return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1967 +/* "pysam/libcalignmentfile.pyx":2324 * * * cdef int __advance_all(void *data, bam1_t *b): # <<<<<<<<<<<<<< - * '''only use reads for pileup passing basic - * filters: + * '''only use reads for pileup passing basic filters such as + * */ static int __pyx_f_5pysam_17libcalignmentfile___advance_all(void *__pyx_v_data, bam1_t *__pyx_v_b) { __pyx_t_5pysam_17libcalignmentfile___iterdata *__pyx_v_d; - PyObject *__pyx_v_mask = 0; + CYTHON_UNUSED PyObject *__pyx_v_mask = 0; int __pyx_v_ret; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__advance_all", 0); - __Pyx_TraceCall("__advance_all", __pyx_f[0], 1967, 0, __PYX_ERR(0, 1967, __pyx_L1_error)); + __Pyx_TraceCall("__advance_all", __pyx_f[0], 2324, 0, __PYX_ERR(0, 2324, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":1975 + /* "pysam/libcalignmentfile.pyx":2330 + * ''' + * + * cdef __iterdata * d = <__iterdata*>data # <<<<<<<<<<<<<< + * cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP + * cdef int ret + */ + __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data); + + /* "pysam/libcalignmentfile.pyx":2331 * - * cdef __iterdata * d + * cdef __iterdata * d = <__iterdata*>data * cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP # <<<<<<<<<<<<<< - * d = <__iterdata*>data * cdef int ret + * while 1: */ - __pyx_t_1 = __Pyx_PyInt_From_int((((BAM_FUNMAP | BAM_FSECONDARY) | BAM_FQCFAIL) | BAM_FDUP)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1975, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int((((BAM_FUNMAP | BAM_FSECONDARY) | BAM_FQCFAIL) | BAM_FDUP)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2331, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_mask = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1976 - * cdef __iterdata * d + /* "pysam/libcalignmentfile.pyx":2333 * cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP - * d = <__iterdata*>data # <<<<<<<<<<<<<< * cdef int ret - * with nogil: + * while 1: # <<<<<<<<<<<<<< + * with nogil: + * ret = sam_itr_next(d.htsfile, d.iter, b) */ - __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data); + while (1) { - /* "pysam/libcalignmentfile.pyx":1978 - * d = <__iterdata*>data + /* "pysam/libcalignmentfile.pyx":2334 * cdef int ret - * with nogil: # <<<<<<<<<<<<<< - * ret = sam_itr_next(d.htsfile, d.iter, b) - * while ret >= 0 and b.core.flag & mask: + * while 1: + * with nogil: # <<<<<<<<<<<<<< + * ret = sam_itr_next(d.htsfile, d.iter, b) + * if ret < 0: */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libcalignmentfile.pyx":1979 - * cdef int ret - * with nogil: - * ret = sam_itr_next(d.htsfile, d.iter, b) # <<<<<<<<<<<<<< - * while ret >= 0 and b.core.flag & mask: + /* "pysam/libcalignmentfile.pyx":2335 + * while 1: * with nogil: + * ret = sam_itr_next(d.htsfile, d.iter, b) # <<<<<<<<<<<<<< + * if ret < 0: + * break */ - __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b); - } + __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b); + } - /* "pysam/libcalignmentfile.pyx":1978 - * d = <__iterdata*>data + /* "pysam/libcalignmentfile.pyx":2334 * cdef int ret - * with nogil: # <<<<<<<<<<<<<< - * ret = sam_itr_next(d.htsfile, d.iter, b) - * while ret >= 0 and b.core.flag & mask: + * while 1: + * with nogil: # <<<<<<<<<<<<<< + * ret = sam_itr_next(d.htsfile, d.iter, b) + * if ret < 0: */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L5; + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L9; + } + __pyx_L9:; } - __pyx_L5:; - } - } + } - /* "pysam/libcalignmentfile.pyx":1980 - * with nogil: - * ret = sam_itr_next(d.htsfile, d.iter, b) - * while ret >= 0 and b.core.flag & mask: # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2336 + * with nogil: + * ret = sam_itr_next(d.htsfile, d.iter, b) + * if ret < 0: # <<<<<<<<<<<<<< + * break + * if b.core.flag & d.flag_filter: + */ + __pyx_t_2 = ((__pyx_v_ret < 0) != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignmentfile.pyx":2337 + * ret = sam_itr_next(d.htsfile, d.iter, b) + * if ret < 0: + * break # <<<<<<<<<<<<<< + * if b.core.flag & d.flag_filter: + * continue + */ + goto __pyx_L4_break; + + /* "pysam/libcalignmentfile.pyx":2336 * with nogil: * ret = sam_itr_next(d.htsfile, d.iter, b) + * if ret < 0: # <<<<<<<<<<<<<< + * break + * if b.core.flag & d.flag_filter: */ - while (1) { - __pyx_t_3 = ((__pyx_v_ret >= 0) != 0); - if (__pyx_t_3) { - } else { - __pyx_t_2 = __pyx_t_3; - goto __pyx_L8_bool_binop_done; } - __pyx_t_1 = __Pyx_PyInt_From_uint16_t(__pyx_v_b->core.flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1980, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyNumber_And(__pyx_t_1, __pyx_v_mask); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1980, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1980, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_2 = __pyx_t_3; - __pyx_L8_bool_binop_done:; - if (!__pyx_t_2) break; - /* "pysam/libcalignmentfile.pyx":1981 - * ret = sam_itr_next(d.htsfile, d.iter, b) - * while ret >= 0 and b.core.flag & mask: - * with nogil: # <<<<<<<<<<<<<< - * ret = sam_itr_next(d.htsfile, d.iter, b) + /* "pysam/libcalignmentfile.pyx":2338 + * if ret < 0: + * break + * if b.core.flag & d.flag_filter: # <<<<<<<<<<<<<< + * continue + * break + */ + __pyx_t_2 = ((__pyx_v_b->core.flag & __pyx_v_d->flag_filter) != 0); + if (__pyx_t_2) { + + /* "pysam/libcalignmentfile.pyx":2339 + * break + * if b.core.flag & d.flag_filter: + * continue # <<<<<<<<<<<<<< + * break * return ret */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + goto __pyx_L3_continue; - /* "pysam/libcalignmentfile.pyx":1982 - * while ret >= 0 and b.core.flag & mask: - * with nogil: - * ret = sam_itr_next(d.htsfile, d.iter, b) # <<<<<<<<<<<<<< - * return ret - * + /* "pysam/libcalignmentfile.pyx":2338 + * if ret < 0: + * break + * if b.core.flag & d.flag_filter: # <<<<<<<<<<<<<< + * continue + * break */ - __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b); - } + } - /* "pysam/libcalignmentfile.pyx":1981 - * ret = sam_itr_next(d.htsfile, d.iter, b) - * while ret >= 0 and b.core.flag & mask: - * with nogil: # <<<<<<<<<<<<<< - * ret = sam_itr_next(d.htsfile, d.iter, b) + /* "pysam/libcalignmentfile.pyx":2340 + * if b.core.flag & d.flag_filter: + * continue + * break # <<<<<<<<<<<<<< * return ret + * */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L14; - } - __pyx_L14:; - } - } + goto __pyx_L4_break; + __pyx_L3_continue:; } + __pyx_L4_break:; - /* "pysam/libcalignmentfile.pyx":1983 - * with nogil: - * ret = sam_itr_next(d.htsfile, d.iter, b) + /* "pysam/libcalignmentfile.pyx":2341 + * continue + * break * return ret # <<<<<<<<<<<<<< * * @@ -23582,18 +28852,17 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_all(void *__pyx_v_data, __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1967 + /* "pysam/libcalignmentfile.pyx":2324 * * * cdef int __advance_all(void *data, bam1_t *b): # <<<<<<<<<<<<<< - * '''only use reads for pileup passing basic - * filters: + * '''only use reads for pileup passing basic filters such as + * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); __Pyx_WriteUnraisable("pysam.libcalignmentfile.__advance_all", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_r = 0; __pyx_L0:; @@ -23603,22 +28872,18 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_all(void *__pyx_v_data, return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":1986 +/* "pysam/libcalignmentfile.pyx":2344 * * - * cdef int __advance_snpcalls(void * data, bam1_t * b): # <<<<<<<<<<<<<< + * cdef int __advance_samtools(void * data, bam1_t * b): # <<<<<<<<<<<<<< * '''advance using same filter and read processing as in * the samtools pileup. */ -static int __pyx_f_5pysam_17libcalignmentfile___advance_snpcalls(void *__pyx_v_data, bam1_t *__pyx_v_b) { +static int __pyx_f_5pysam_17libcalignmentfile___advance_samtools(void *__pyx_v_data, bam1_t *__pyx_v_b) { __pyx_t_5pysam_17libcalignmentfile___iterdata *__pyx_v_d; int __pyx_v_ret; - int __pyx_v_skip; int __pyx_v_q; - int __pyx_v_is_cns; - int __pyx_v_is_nobaq; - int __pyx_v_capQ_thres; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -23628,160 +28893,37 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_snpcalls(void *__pyx_v_d PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; - __Pyx_RefNannySetupContext("__advance_snpcalls", 0); - __Pyx_TraceCall("__advance_snpcalls", __pyx_f[0], 1986, 0, __PYX_ERR(0, 1986, __pyx_L1_error)); - - /* "pysam/libcalignmentfile.pyx":1998 - * # 2. bam_cap_mapQ - * cdef __iterdata * d - * d = <__iterdata*>data # <<<<<<<<<<<<<< - * - * cdef int ret - */ - __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data); + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + __Pyx_RefNannySetupContext("__advance_samtools", 0); + __Pyx_TraceCall("__advance_samtools", __pyx_f[0], 2344, 0, __PYX_ERR(0, 2344, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2001 - * + /* "pysam/libcalignmentfile.pyx":2348 + * the samtools pileup. + * ''' + * cdef __iterdata * d = <__iterdata*>data # <<<<<<<<<<<<<< * cdef int ret - * cdef int skip = 0 # <<<<<<<<<<<<<< - * cdef int q - * cdef int is_cns = 1 - */ - __pyx_v_skip = 0; - - /* "pysam/libcalignmentfile.pyx":2003 - * cdef int skip = 0 * cdef int q - * cdef int is_cns = 1 # <<<<<<<<<<<<<< - * cdef int is_nobaq = 0 - * cdef int capQ_thres = 0 */ - __pyx_v_is_cns = 1; + __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data); - /* "pysam/libcalignmentfile.pyx":2004 + /* "pysam/libcalignmentfile.pyx":2352 * cdef int q - * cdef int is_cns = 1 - * cdef int is_nobaq = 0 # <<<<<<<<<<<<<< - * cdef int capQ_thres = 0 - * - */ - __pyx_v_is_nobaq = 0; - - /* "pysam/libcalignmentfile.pyx":2005 - * cdef int is_cns = 1 - * cdef int is_nobaq = 0 - * cdef int capQ_thres = 0 # <<<<<<<<<<<<<< - * - * with nogil: - */ - __pyx_v_capQ_thres = 0; - - /* "pysam/libcalignmentfile.pyx":2007 - * cdef int capQ_thres = 0 - * - * with nogil: # <<<<<<<<<<<<<< - * ret = sam_itr_next(d.htsfile, d.iter, b) - * - */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { - - /* "pysam/libcalignmentfile.pyx":2008 - * - * with nogil: - * ret = sam_itr_next(d.htsfile, d.iter, b) # <<<<<<<<<<<<<< - * - * # reload sequence - */ - __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b); - } - - /* "pysam/libcalignmentfile.pyx":2007 - * cdef int capQ_thres = 0 - * - * with nogil: # <<<<<<<<<<<<<< - * ret = sam_itr_next(d.htsfile, d.iter, b) - * - */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L5; - } - __pyx_L5:; - } - } - - /* "pysam/libcalignmentfile.pyx":2011 * - * # reload sequence - * if d.fastafile != NULL and b.core.tid != d.tid: # <<<<<<<<<<<<<< - * if d.seq != NULL: - * free(d.seq) - */ - __pyx_t_2 = ((__pyx_v_d->fastafile != NULL) != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_2 = ((__pyx_v_b->core.tid != __pyx_v_d->tid) != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L7_bool_binop_done:; - if (__pyx_t_1) { - - /* "pysam/libcalignmentfile.pyx":2012 - * # reload sequence - * if d.fastafile != NULL and b.core.tid != d.tid: - * if d.seq != NULL: # <<<<<<<<<<<<<< - * free(d.seq) - * d.tid = b.core.tid - */ - __pyx_t_1 = ((__pyx_v_d->seq != NULL) != 0); - if (__pyx_t_1) { - - /* "pysam/libcalignmentfile.pyx":2013 - * if d.fastafile != NULL and b.core.tid != d.tid: - * if d.seq != NULL: - * free(d.seq) # <<<<<<<<<<<<<< - * d.tid = b.core.tid - * with nogil: - */ - free(__pyx_v_d->seq); - - /* "pysam/libcalignmentfile.pyx":2012 - * # reload sequence - * if d.fastafile != NULL and b.core.tid != d.tid: - * if d.seq != NULL: # <<<<<<<<<<<<<< - * free(d.seq) - * d.tid = b.core.tid - */ - } - - /* "pysam/libcalignmentfile.pyx":2014 - * if d.seq != NULL: - * free(d.seq) - * d.tid = b.core.tid # <<<<<<<<<<<<<< + * while 1: # <<<<<<<<<<<<<< * with nogil: - * d.seq = faidx_fetch_seq( + * ret = sam_itr_next(d.htsfile, d.iter, b) */ - __pyx_t_3 = __pyx_v_b->core.tid; - __pyx_v_d->tid = __pyx_t_3; + while (1) { - /* "pysam/libcalignmentfile.pyx":2015 - * free(d.seq) - * d.tid = b.core.tid + /* "pysam/libcalignmentfile.pyx":2353 + * + * while 1: * with nogil: # <<<<<<<<<<<<<< - * d.seq = faidx_fetch_seq( - * d.fastafile, + * ret = sam_itr_next(d.htsfile, d.iter, b) + * if ret < 0: */ { #ifdef WITH_THREAD @@ -23791,22 +28933,22 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_snpcalls(void *__pyx_v_d #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":2016 - * d.tid = b.core.tid + /* "pysam/libcalignmentfile.pyx":2354 + * while 1: * with nogil: - * d.seq = faidx_fetch_seq( # <<<<<<<<<<<<<< - * d.fastafile, - * d.header.target_name[d.tid], + * ret = sam_itr_next(d.htsfile, d.iter, b) # <<<<<<<<<<<<<< + * if ret < 0: + * break */ - __pyx_v_d->seq = faidx_fetch_seq(__pyx_v_d->fastafile, (__pyx_v_d->header->target_name[__pyx_v_d->tid]), 0, __pyx_v_5pysam_17libcalignmentfile_MAX_POS, (&__pyx_v_d->seq_len)); + __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b); } - /* "pysam/libcalignmentfile.pyx":2015 - * free(d.seq) - * d.tid = b.core.tid + /* "pysam/libcalignmentfile.pyx":2353 + * + * while 1: * with nogil: # <<<<<<<<<<<<<< - * d.seq = faidx_fetch_seq( - * d.fastafile, + * ret = sam_itr_next(d.htsfile, d.iter, b) + * if ret < 0: */ /*finally:*/ { /*normal exit:*/{ @@ -23814,411 +28956,573 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_snpcalls(void *__pyx_v_d __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif - goto __pyx_L12; + goto __pyx_L9; } - __pyx_L12:; + __pyx_L9:; } } - /* "pysam/libcalignmentfile.pyx":2022 - * &d.seq_len) + /* "pysam/libcalignmentfile.pyx":2355 + * with nogil: + * ret = sam_itr_next(d.htsfile, d.iter, b) + * if ret < 0: # <<<<<<<<<<<<<< + * break + * if b.core.flag & d.flag_filter: + */ + __pyx_t_1 = ((__pyx_v_ret < 0) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignmentfile.pyx":2356 + * ret = sam_itr_next(d.htsfile, d.iter, b) + * if ret < 0: + * break # <<<<<<<<<<<<<< + * if b.core.flag & d.flag_filter: + * continue + */ + goto __pyx_L4_break; + + /* "pysam/libcalignmentfile.pyx":2355 + * with nogil: + * ret = sam_itr_next(d.htsfile, d.iter, b) + * if ret < 0: # <<<<<<<<<<<<<< + * break + * if b.core.flag & d.flag_filter: + */ + } + + /* "pysam/libcalignmentfile.pyx":2357 + * if ret < 0: + * break + * if b.core.flag & d.flag_filter: # <<<<<<<<<<<<<< + * continue + * if d.flag_require and not (b.core.flag & d.flag_require): + */ + __pyx_t_1 = ((__pyx_v_b->core.flag & __pyx_v_d->flag_filter) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignmentfile.pyx":2358 + * break + * if b.core.flag & d.flag_filter: + * continue # <<<<<<<<<<<<<< + * if d.flag_require and not (b.core.flag & d.flag_require): + * continue + */ + goto __pyx_L3_continue; + + /* "pysam/libcalignmentfile.pyx":2357 + * if ret < 0: + * break + * if b.core.flag & d.flag_filter: # <<<<<<<<<<<<<< + * continue + * if d.flag_require and not (b.core.flag & d.flag_require): + */ + } + + /* "pysam/libcalignmentfile.pyx":2359 + * if b.core.flag & d.flag_filter: + * continue + * if d.flag_require and not (b.core.flag & d.flag_require): # <<<<<<<<<<<<<< + * continue * - * if d.seq == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "reference sequence for '%s' (tid=%i) not found" % \ */ - __pyx_t_1 = ((__pyx_v_d->seq == NULL) != 0); - if (unlikely(__pyx_t_1)) { + __pyx_t_2 = (__pyx_v_d->flag_require != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L13_bool_binop_done; + } + __pyx_t_2 = ((!((__pyx_v_b->core.flag & __pyx_v_d->flag_require) != 0)) != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L13_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2025 - * raise ValueError( - * "reference sequence for '%s' (tid=%i) not found" % \ - * (d.header.target_name[d.tid], # <<<<<<<<<<<<<< - * d.tid)) + /* "pysam/libcalignmentfile.pyx":2360 + * continue + * if d.flag_require and not (b.core.flag & d.flag_require): + * continue # <<<<<<<<<<<<<< * + * # reload sequence */ - __pyx_t_4 = __Pyx_PyBytes_FromString((__pyx_v_d->header->target_name[__pyx_v_d->tid])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + goto __pyx_L3_continue; - /* "pysam/libcalignmentfile.pyx":2026 - * "reference sequence for '%s' (tid=%i) not found" % \ - * (d.header.target_name[d.tid], - * d.tid)) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2359 + * if b.core.flag & d.flag_filter: + * continue + * if d.flag_require and not (b.core.flag & d.flag_require): # <<<<<<<<<<<<<< + * continue * - * while ret >= 0: */ - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_d->tid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2026, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + } - /* "pysam/libcalignmentfile.pyx":2025 - * raise ValueError( - * "reference sequence for '%s' (tid=%i) not found" % \ - * (d.header.target_name[d.tid], # <<<<<<<<<<<<<< - * d.tid)) + /* "pysam/libcalignmentfile.pyx":2363 * + * # reload sequence + * if d.fastafile != NULL and b.core.tid != d.tid: # <<<<<<<<<<<<<< + * if d.seq != NULL: + * free(d.seq) */ - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); - __pyx_t_4 = 0; - __pyx_t_5 = 0; + __pyx_t_2 = ((__pyx_v_d->fastafile != NULL) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L16_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_b->core.tid != __pyx_v_d->tid) != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L16_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2024 - * if d.seq == NULL: - * raise ValueError( - * "reference sequence for '%s' (tid=%i) not found" % \ # <<<<<<<<<<<<<< - * (d.header.target_name[d.tid], - * d.tid)) + /* "pysam/libcalignmentfile.pyx":2364 + * # reload sequence + * if d.fastafile != NULL and b.core.tid != d.tid: + * if d.seq != NULL: # <<<<<<<<<<<<<< + * free(d.seq) + * d.tid = b.core.tid */ - __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_reference_sequence_for_s_tid_i_n, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2024, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_1 = ((__pyx_v_d->seq != NULL) != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignmentfile.pyx":2365 + * if d.fastafile != NULL and b.core.tid != d.tid: + * if d.seq != NULL: + * free(d.seq) # <<<<<<<<<<<<<< + * d.tid = b.core.tid + * with nogil: + */ + free(__pyx_v_d->seq); + + /* "pysam/libcalignmentfile.pyx":2364 + * # reload sequence + * if d.fastafile != NULL and b.core.tid != d.tid: + * if d.seq != NULL: # <<<<<<<<<<<<<< + * free(d.seq) + * d.tid = b.core.tid + */ + } + + /* "pysam/libcalignmentfile.pyx":2366 + * if d.seq != NULL: + * free(d.seq) + * d.tid = b.core.tid # <<<<<<<<<<<<<< + * with nogil: + * d.seq = faidx_fetch_seq( + */ + __pyx_t_3 = __pyx_v_b->core.tid; + __pyx_v_d->tid = __pyx_t_3; + + /* "pysam/libcalignmentfile.pyx":2367 + * free(d.seq) + * d.tid = b.core.tid + * with nogil: # <<<<<<<<<<<<<< + * d.seq = faidx_fetch_seq( + * d.fastafile, + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libcalignmentfile.pyx":2368 + * d.tid = b.core.tid + * with nogil: + * d.seq = faidx_fetch_seq( # <<<<<<<<<<<<<< + * d.fastafile, + * d.header.target_name[d.tid], + */ + __pyx_v_d->seq = faidx_fetch_seq(__pyx_v_d->fastafile, (__pyx_v_d->header->target_name[__pyx_v_d->tid]), 0, __pyx_v_5pysam_17libcalignmentfile_MAX_POS, (&__pyx_v_d->seq_len)); + } + + /* "pysam/libcalignmentfile.pyx":2367 + * free(d.seq) + * d.tid = b.core.tid + * with nogil: # <<<<<<<<<<<<<< + * d.seq = faidx_fetch_seq( + * d.fastafile, + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L23; + } + __pyx_L23:; + } + } - /* "pysam/libcalignmentfile.pyx":2023 + /* "pysam/libcalignmentfile.pyx":2374 + * &d.seq_len) * - * if d.seq == NULL: - * raise ValueError( # <<<<<<<<<<<<<< - * "reference sequence for '%s' (tid=%i) not found" % \ - * (d.header.target_name[d.tid], + * if d.seq == NULL: # <<<<<<<<<<<<<< + * raise ValueError( + * "reference sequence for '{}' (tid={}) not found".format( */ - __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2023, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 2023, __pyx_L1_error) + __pyx_t_1 = ((__pyx_v_d->seq == NULL) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":2022 - * &d.seq_len) + /* "pysam/libcalignmentfile.pyx":2376 + * if d.seq == NULL: + * raise ValueError( + * "reference sequence for '{}' (tid={}) not found".format( # <<<<<<<<<<<<<< + * d.header.target_name[d.tid], d.tid)) * - * if d.seq == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "reference sequence for '%s' (tid=%i) not found" % \ */ - } + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_reference_sequence_for_tid_not_f, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2376, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + + /* "pysam/libcalignmentfile.pyx":2377 + * raise ValueError( + * "reference sequence for '{}' (tid={}) not found".format( + * d.header.target_name[d.tid], d.tid)) # <<<<<<<<<<<<<< + * + * # realign read - changes base qualities + */ + __pyx_t_6 = __Pyx_PyBytes_FromString((__pyx_v_d->header->target_name[__pyx_v_d->tid])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2377, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_d->tid); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2377, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_6, __pyx_t_7}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2376, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_6, __pyx_t_7}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2376, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2376, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_7); + __pyx_t_6 = 0; + __pyx_t_7 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2376, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcalignmentfile.pyx":2011 + /* "pysam/libcalignmentfile.pyx":2375 * - * # reload sequence - * if d.fastafile != NULL and b.core.tid != d.tid: # <<<<<<<<<<<<<< - * if d.seq != NULL: - * free(d.seq) + * if d.seq == NULL: + * raise ValueError( # <<<<<<<<<<<<<< + * "reference sequence for '{}' (tid={}) not found".format( + * d.header.target_name[d.tid], d.tid)) */ - } + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2375, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 2375, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":2028 - * d.tid)) - * - * while ret >= 0: # <<<<<<<<<<<<<< - * skip = 0 + /* "pysam/libcalignmentfile.pyx":2374 + * &d.seq_len) * + * if d.seq == NULL: # <<<<<<<<<<<<<< + * raise ValueError( + * "reference sequence for '{}' (tid={}) not found".format( */ - while (1) { - __pyx_t_1 = ((__pyx_v_ret >= 0) != 0); - if (!__pyx_t_1) break; + } - /* "pysam/libcalignmentfile.pyx":2029 - * - * while ret >= 0: - * skip = 0 # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2363 * - * # realign read - changes base qualities + * # reload sequence + * if d.fastafile != NULL and b.core.tid != d.tid: # <<<<<<<<<<<<<< + * if d.seq != NULL: + * free(d.seq) */ - __pyx_v_skip = 0; + } - /* "pysam/libcalignmentfile.pyx":2032 + /* "pysam/libcalignmentfile.pyx":2380 * * # realign read - changes base qualities - * if d.seq != NULL and is_cns and not is_nobaq: # <<<<<<<<<<<<<< - * bam_prob_realn(b, d.seq) - * + * if d.seq != NULL and d.compute_baq: # <<<<<<<<<<<<<< + * # 4th option to realign is flag: + * # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4 */ __pyx_t_2 = ((__pyx_v_d->seq != NULL) != 0); if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; - goto __pyx_L17_bool_binop_done; - } - __pyx_t_2 = (__pyx_v_is_cns != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L17_bool_binop_done; + goto __pyx_L26_bool_binop_done; } - __pyx_t_2 = ((!(__pyx_v_is_nobaq != 0)) != 0); + __pyx_t_2 = (__pyx_v_d->compute_baq != 0); __pyx_t_1 = __pyx_t_2; - __pyx_L17_bool_binop_done:; + __pyx_L26_bool_binop_done:; if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2033 - * # realign read - changes base qualities - * if d.seq != NULL and is_cns and not is_nobaq: - * bam_prob_realn(b, d.seq) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2383 + * # 4th option to realign is flag: + * # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4 + * if d.redo_baq: # <<<<<<<<<<<<<< + * sam_prob_realn(b, d.seq, d.seq_len, 7) + * else: + */ + __pyx_t_1 = (__pyx_v_d->redo_baq != 0); + if (__pyx_t_1) { + + /* "pysam/libcalignmentfile.pyx":2384 + * # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4 + * if d.redo_baq: + * sam_prob_realn(b, d.seq, d.seq_len, 7) # <<<<<<<<<<<<<< + * else: + * sam_prob_realn(b, d.seq, d.seq_len, 3) + */ + (void)(sam_prob_realn(__pyx_v_b, __pyx_v_d->seq, __pyx_v_d->seq_len, 7)); + + /* "pysam/libcalignmentfile.pyx":2383 + * # 4th option to realign is flag: + * # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4 + * if d.redo_baq: # <<<<<<<<<<<<<< + * sam_prob_realn(b, d.seq, d.seq_len, 7) + * else: + */ + goto __pyx_L28; + } + + /* "pysam/libcalignmentfile.pyx":2386 + * sam_prob_realn(b, d.seq, d.seq_len, 7) + * else: + * sam_prob_realn(b, d.seq, d.seq_len, 3) # <<<<<<<<<<<<<< * - * if d.seq != NULL and capQ_thres > 10: + * if d.seq != NULL and d.adjust_capq_threshold > 10: */ - (void)(bam_prob_realn(__pyx_v_b, __pyx_v_d->seq)); + /*else*/ { + (void)(sam_prob_realn(__pyx_v_b, __pyx_v_d->seq, __pyx_v_d->seq_len, 3)); + } + __pyx_L28:; - /* "pysam/libcalignmentfile.pyx":2032 + /* "pysam/libcalignmentfile.pyx":2380 * * # realign read - changes base qualities - * if d.seq != NULL and is_cns and not is_nobaq: # <<<<<<<<<<<<<< - * bam_prob_realn(b, d.seq) - * + * if d.seq != NULL and d.compute_baq: # <<<<<<<<<<<<<< + * # 4th option to realign is flag: + * # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4 */ } - /* "pysam/libcalignmentfile.pyx":2035 - * bam_prob_realn(b, d.seq) + /* "pysam/libcalignmentfile.pyx":2388 + * sam_prob_realn(b, d.seq, d.seq_len, 3) * - * if d.seq != NULL and capQ_thres > 10: # <<<<<<<<<<<<<< - * q = bam_cap_mapQ(b, d.seq, capQ_thres) + * if d.seq != NULL and d.adjust_capq_threshold > 10: # <<<<<<<<<<<<<< + * q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold) * if q < 0: */ __pyx_t_2 = ((__pyx_v_d->seq != NULL) != 0); if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; - goto __pyx_L21_bool_binop_done; + goto __pyx_L30_bool_binop_done; } - __pyx_t_2 = ((__pyx_v_capQ_thres > 10) != 0); + __pyx_t_2 = ((__pyx_v_d->adjust_capq_threshold > 10) != 0); __pyx_t_1 = __pyx_t_2; - __pyx_L21_bool_binop_done:; + __pyx_L30_bool_binop_done:; if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2036 + /* "pysam/libcalignmentfile.pyx":2389 * - * if d.seq != NULL and capQ_thres > 10: - * q = bam_cap_mapQ(b, d.seq, capQ_thres) # <<<<<<<<<<<<<< + * if d.seq != NULL and d.adjust_capq_threshold > 10: + * q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold) # <<<<<<<<<<<<<< * if q < 0: - * skip = 1 + * continue */ - __pyx_v_q = bam_cap_mapQ(__pyx_v_b, __pyx_v_d->seq, __pyx_v_capQ_thres); + __pyx_v_q = sam_cap_mapq(__pyx_v_b, __pyx_v_d->seq, __pyx_v_d->seq_len, __pyx_v_d->adjust_capq_threshold); - /* "pysam/libcalignmentfile.pyx":2037 - * if d.seq != NULL and capQ_thres > 10: - * q = bam_cap_mapQ(b, d.seq, capQ_thres) + /* "pysam/libcalignmentfile.pyx":2390 + * if d.seq != NULL and d.adjust_capq_threshold > 10: + * q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold) * if q < 0: # <<<<<<<<<<<<<< - * skip = 1 + * continue * elif b.core.qual > q: */ __pyx_t_1 = ((__pyx_v_q < 0) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2038 - * q = bam_cap_mapQ(b, d.seq, capQ_thres) + /* "pysam/libcalignmentfile.pyx":2391 + * q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold) * if q < 0: - * skip = 1 # <<<<<<<<<<<<<< + * continue # <<<<<<<<<<<<<< * elif b.core.qual > q: * b.core.qual = q */ - __pyx_v_skip = 1; + goto __pyx_L3_continue; - /* "pysam/libcalignmentfile.pyx":2037 - * if d.seq != NULL and capQ_thres > 10: - * q = bam_cap_mapQ(b, d.seq, capQ_thres) + /* "pysam/libcalignmentfile.pyx":2390 + * if d.seq != NULL and d.adjust_capq_threshold > 10: + * q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold) * if q < 0: # <<<<<<<<<<<<<< - * skip = 1 + * continue * elif b.core.qual > q: */ - goto __pyx_L23; } - /* "pysam/libcalignmentfile.pyx":2039 + /* "pysam/libcalignmentfile.pyx":2392 * if q < 0: - * skip = 1 + * continue * elif b.core.qual > q: # <<<<<<<<<<<<<< * b.core.qual = q - * if b.core.flag & BAM_FUNMAP: + * */ __pyx_t_1 = ((__pyx_v_b->core.qual > __pyx_v_q) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2040 - * skip = 1 + /* "pysam/libcalignmentfile.pyx":2393 + * continue * elif b.core.qual > q: * b.core.qual = q # <<<<<<<<<<<<<< - * if b.core.flag & BAM_FUNMAP: - * skip = 1 + * + * if b.core.qual < d.min_mapping_quality: */ __pyx_v_b->core.qual = __pyx_v_q; - /* "pysam/libcalignmentfile.pyx":2039 + /* "pysam/libcalignmentfile.pyx":2392 * if q < 0: - * skip = 1 + * continue * elif b.core.qual > q: # <<<<<<<<<<<<<< * b.core.qual = q - * if b.core.flag & BAM_FUNMAP: + * */ } - __pyx_L23:; - /* "pysam/libcalignmentfile.pyx":2035 - * bam_prob_realn(b, d.seq) + /* "pysam/libcalignmentfile.pyx":2388 + * sam_prob_realn(b, d.seq, d.seq_len, 3) * - * if d.seq != NULL and capQ_thres > 10: # <<<<<<<<<<<<<< - * q = bam_cap_mapQ(b, d.seq, capQ_thres) + * if d.seq != NULL and d.adjust_capq_threshold > 10: # <<<<<<<<<<<<<< + * q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold) * if q < 0: */ } - /* "pysam/libcalignmentfile.pyx":2041 - * elif b.core.qual > q: + /* "pysam/libcalignmentfile.pyx":2395 * b.core.qual = q - * if b.core.flag & BAM_FUNMAP: # <<<<<<<<<<<<<< - * skip = 1 - * elif b.core.flag & 1 and not b.core.flag & 2: + * + * if b.core.qual < d.min_mapping_quality: # <<<<<<<<<<<<<< + * continue + * if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR): */ - __pyx_t_1 = ((__pyx_v_b->core.flag & BAM_FUNMAP) != 0); + __pyx_t_1 = ((__pyx_v_b->core.qual < __pyx_v_d->min_mapping_quality) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2042 - * b.core.qual = q - * if b.core.flag & BAM_FUNMAP: - * skip = 1 # <<<<<<<<<<<<<< - * elif b.core.flag & 1 and not b.core.flag & 2: - * skip = 1 + /* "pysam/libcalignmentfile.pyx":2396 + * + * if b.core.qual < d.min_mapping_quality: + * continue # <<<<<<<<<<<<<< + * if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR): + * continue */ - __pyx_v_skip = 1; + goto __pyx_L3_continue; - /* "pysam/libcalignmentfile.pyx":2041 - * elif b.core.qual > q: + /* "pysam/libcalignmentfile.pyx":2395 * b.core.qual = q - * if b.core.flag & BAM_FUNMAP: # <<<<<<<<<<<<<< - * skip = 1 - * elif b.core.flag & 1 and not b.core.flag & 2: + * + * if b.core.qual < d.min_mapping_quality: # <<<<<<<<<<<<<< + * continue + * if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR): */ - goto __pyx_L24; } - /* "pysam/libcalignmentfile.pyx":2043 - * if b.core.flag & BAM_FUNMAP: - * skip = 1 - * elif b.core.flag & 1 and not b.core.flag & 2: # <<<<<<<<<<<<<< - * skip = 1 + /* "pysam/libcalignmentfile.pyx":2397 + * if b.core.qual < d.min_mapping_quality: + * continue + * if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR): # <<<<<<<<<<<<<< + * continue * */ - __pyx_t_2 = ((__pyx_v_b->core.flag & 1) != 0); + __pyx_t_2 = (__pyx_v_d->ignore_orphans != 0); if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; - goto __pyx_L25_bool_binop_done; + goto __pyx_L35_bool_binop_done; } - __pyx_t_2 = ((!((__pyx_v_b->core.flag & 2) != 0)) != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L25_bool_binop_done:; - if (__pyx_t_1) { - - /* "pysam/libcalignmentfile.pyx":2044 - * skip = 1 - * elif b.core.flag & 1 and not b.core.flag & 2: - * skip = 1 # <<<<<<<<<<<<<< - * - * if not skip: - */ - __pyx_v_skip = 1; - - /* "pysam/libcalignmentfile.pyx":2043 - * if b.core.flag & BAM_FUNMAP: - * skip = 1 - * elif b.core.flag & 1 and not b.core.flag & 2: # <<<<<<<<<<<<<< - * skip = 1 - * - */ + __pyx_t_2 = ((__pyx_v_b->core.flag & BAM_FPAIRED) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L35_bool_binop_done; } - __pyx_L24:; - - /* "pysam/libcalignmentfile.pyx":2046 - * skip = 1 - * - * if not skip: # <<<<<<<<<<<<<< - * break - * # additional filters - */ - __pyx_t_1 = ((!(__pyx_v_skip != 0)) != 0); + __pyx_t_2 = ((!((__pyx_v_b->core.flag & BAM_FPROPER_PAIR) != 0)) != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L35_bool_binop_done:; if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2047 - * - * if not skip: - * break # <<<<<<<<<<<<<< - * # additional filters + /* "pysam/libcalignmentfile.pyx":2398 + * continue + * if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR): + * continue # <<<<<<<<<<<<<< * + * break */ - goto __pyx_L15_break; + goto __pyx_L3_continue; - /* "pysam/libcalignmentfile.pyx":2046 - * skip = 1 + /* "pysam/libcalignmentfile.pyx":2397 + * if b.core.qual < d.min_mapping_quality: + * continue + * if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR): # <<<<<<<<<<<<<< + * continue * - * if not skip: # <<<<<<<<<<<<<< - * break - * # additional filters */ } - /* "pysam/libcalignmentfile.pyx":2050 - * # additional filters - * - * with nogil: # <<<<<<<<<<<<<< - * ret = sam_itr_next(d.htsfile, d.iter, b) - * - */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { - - /* "pysam/libcalignmentfile.pyx":2051 + /* "pysam/libcalignmentfile.pyx":2400 + * continue * - * with nogil: - * ret = sam_itr_next(d.htsfile, d.iter, b) # <<<<<<<<<<<<<< + * break # <<<<<<<<<<<<<< * * return ret */ - __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b); - } - - /* "pysam/libcalignmentfile.pyx":2050 - * # additional filters - * - * with nogil: # <<<<<<<<<<<<<< - * ret = sam_itr_next(d.htsfile, d.iter, b) - * - */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L32; - } - __pyx_L32:; - } - } + goto __pyx_L4_break; + __pyx_L3_continue:; } - __pyx_L15_break:; + __pyx_L4_break:; - /* "pysam/libcalignmentfile.pyx":2053 - * ret = sam_itr_next(d.htsfile, d.iter, b) + /* "pysam/libcalignmentfile.pyx":2402 + * break * * return ret # <<<<<<<<<<<<<< * - * cdef class IteratorColumn: + * */ __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":1986 + /* "pysam/libcalignmentfile.pyx":2344 * * - * cdef int __advance_snpcalls(void * data, bam1_t * b): # <<<<<<<<<<<<<< + * cdef int __advance_samtools(void * data, bam1_t * b): # <<<<<<<<<<<<<< * '''advance using same filter and read processing as in * the samtools pileup. */ @@ -24228,7 +29532,10 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_snpcalls(void *__pyx_v_d __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_WriteUnraisable("pysam.libcalignmentfile.__advance_snpcalls", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_WriteUnraisable("pysam.libcalignmentfile.__advance_samtools", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_r = 0; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -24236,10 +29543,10 @@ static int __pyx_f_5pysam_17libcalignmentfile___advance_snpcalls(void *__pyx_v_d return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2101 +/* "pysam/libcalignmentfile.pyx":2437 * ''' * - * def __cinit__( self, AlignmentFile samfile, **kwargs ): # <<<<<<<<<<<<<< + * def __cinit__( self, AlignmentFile samfile, **kwargs): # <<<<<<<<<<<<<< * self.samfile = samfile * self.fastafile = kwargs.get("fastafile", None) */ @@ -24273,7 +29580,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_1__cinit__(PyObj else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 2101, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 2437, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -24284,14 +29591,14 @@ static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_1__cinit__(PyObj } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2101, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2437, __pyx_L3_error) __pyx_L3_error:; __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2101, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2437, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_samfile, __pyx_v_kwargs); /* function exit code */ @@ -24310,15 +29617,18 @@ static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(struct __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; + int __pyx_t_3; + uint32_t __pyx_t_4; + PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[0], 2101, 0, __PYX_ERR(0, 2101, __pyx_L1_error)); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 2437, 0, __PYX_ERR(0, 2437, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2102 + /* "pysam/libcalignmentfile.pyx":2438 * - * def __cinit__( self, AlignmentFile samfile, **kwargs ): + * def __cinit__( self, AlignmentFile samfile, **kwargs): * self.samfile = samfile # <<<<<<<<<<<<<< * self.fastafile = kwargs.get("fastafile", None) - * self.stepper = kwargs.get("stepper", None) + * self.stepper = kwargs.get("stepper", "samtools") */ __Pyx_INCREF(((PyObject *)__pyx_v_samfile)); __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile)); @@ -24326,30 +29636,30 @@ static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(struct __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile)); __pyx_v_self->samfile = __pyx_v_samfile; - /* "pysam/libcalignmentfile.pyx":2103 - * def __cinit__( self, AlignmentFile samfile, **kwargs ): + /* "pysam/libcalignmentfile.pyx":2439 + * def __cinit__( self, AlignmentFile samfile, **kwargs): * self.samfile = samfile * self.fastafile = kwargs.get("fastafile", None) # <<<<<<<<<<<<<< - * self.stepper = kwargs.get("stepper", None) + * self.stepper = kwargs.get("stepper", "samtools") * self.max_depth = kwargs.get("max_depth", 8000) */ - __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_fastafile, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2103, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_fastafile, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2439, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9libcfaidx_Fastafile))))) __PYX_ERR(0, 2103, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9libcfaidx_FastaFile))))) __PYX_ERR(0, 2439, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->fastafile); __Pyx_DECREF(((PyObject *)__pyx_v_self->fastafile)); - __pyx_v_self->fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_Fastafile *)__pyx_t_1); + __pyx_v_self->fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":2104 + /* "pysam/libcalignmentfile.pyx":2440 * self.samfile = samfile * self.fastafile = kwargs.get("fastafile", None) - * self.stepper = kwargs.get("stepper", None) # <<<<<<<<<<<<<< + * self.stepper = kwargs.get("stepper", "samtools") # <<<<<<<<<<<<<< * self.max_depth = kwargs.get("max_depth", 8000) - * self.iterdata.seq = NULL + * self.ignore_overlaps = kwargs.get("ignore_overlaps", True) */ - __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_stepper, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2104, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_stepper, __pyx_n_s_samtools); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2440, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->stepper); @@ -24357,39 +29667,159 @@ static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(struct __pyx_v_self->stepper = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":2105 + /* "pysam/libcalignmentfile.pyx":2441 * self.fastafile = kwargs.get("fastafile", None) - * self.stepper = kwargs.get("stepper", None) + * self.stepper = kwargs.get("stepper", "samtools") * self.max_depth = kwargs.get("max_depth", 8000) # <<<<<<<<<<<<<< - * self.iterdata.seq = NULL - * self.tid = 0 + * self.ignore_overlaps = kwargs.get("ignore_overlaps", True) + * self.min_base_quality = kwargs.get("min_base_quality", 13) */ - __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_max_depth, __pyx_int_8000); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2105, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_max_depth, __pyx_int_8000); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2441, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2105, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2441, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_self->max_depth = __pyx_t_2; - /* "pysam/libcalignmentfile.pyx":2106 - * self.stepper = kwargs.get("stepper", None) + /* "pysam/libcalignmentfile.pyx":2442 + * self.stepper = kwargs.get("stepper", "samtools") + * self.max_depth = kwargs.get("max_depth", 8000) + * self.ignore_overlaps = kwargs.get("ignore_overlaps", True) # <<<<<<<<<<<<<< + * self.min_base_quality = kwargs.get("min_base_quality", 13) + * self.iterdata.seq = NULL + */ + __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_ignore_overlaps, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2442, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2442, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_self->ignore_overlaps = __pyx_t_3; + + /* "pysam/libcalignmentfile.pyx":2443 * self.max_depth = kwargs.get("max_depth", 8000) + * self.ignore_overlaps = kwargs.get("ignore_overlaps", True) + * self.min_base_quality = kwargs.get("min_base_quality", 13) # <<<<<<<<<<<<<< + * self.iterdata.seq = NULL + * self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0) + */ + __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_min_base_quality, __pyx_int_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_4 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2443, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_self->min_base_quality = __pyx_t_4; + + /* "pysam/libcalignmentfile.pyx":2444 + * self.ignore_overlaps = kwargs.get("ignore_overlaps", True) + * self.min_base_quality = kwargs.get("min_base_quality", 13) * self.iterdata.seq = NULL # <<<<<<<<<<<<<< - * self.tid = 0 - * self.pos = 0 + * self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0) + * self.iterdata.flag_require = kwargs.get("flag_require", 0) */ __pyx_v_self->iterdata.seq = NULL; - /* "pysam/libcalignmentfile.pyx":2107 - * self.max_depth = kwargs.get("max_depth", 8000) + /* "pysam/libcalignmentfile.pyx":2445 + * self.min_base_quality = kwargs.get("min_base_quality", 13) + * self.iterdata.seq = NULL + * self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0) # <<<<<<<<<<<<<< + * self.iterdata.flag_require = kwargs.get("flag_require", 0) + * self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP) + */ + __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_min_mapping_quality, __pyx_int_0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2445, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2445, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_self->iterdata.min_mapping_quality = __pyx_t_2; + + /* "pysam/libcalignmentfile.pyx":2446 * self.iterdata.seq = NULL + * self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0) + * self.iterdata.flag_require = kwargs.get("flag_require", 0) # <<<<<<<<<<<<<< + * self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP) + * self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0) + */ + __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_flag_require, __pyx_int_0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2446, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2446, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_self->iterdata.flag_require = __pyx_t_2; + + /* "pysam/libcalignmentfile.pyx":2447 + * self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0) + * self.iterdata.flag_require = kwargs.get("flag_require", 0) + * self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP) # <<<<<<<<<<<<<< + * self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0) + * self.iterdata.compute_baq = kwargs.get("compute_baq", True) + */ + __pyx_t_1 = __Pyx_PyInt_From_int((((BAM_FUNMAP | BAM_FSECONDARY) | BAM_FQCFAIL) | BAM_FDUP)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_flag_filter, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2447, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2447, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_self->iterdata.flag_filter = __pyx_t_2; + + /* "pysam/libcalignmentfile.pyx":2448 + * self.iterdata.flag_require = kwargs.get("flag_require", 0) + * self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP) + * self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0) # <<<<<<<<<<<<<< + * self.iterdata.compute_baq = kwargs.get("compute_baq", True) + * self.iterdata.redo_baq = kwargs.get("redo_baq", False) + */ + __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_adjust_capq_threshold, __pyx_int_0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2448, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_self->iterdata.adjust_capq_threshold = __pyx_t_2; + + /* "pysam/libcalignmentfile.pyx":2449 + * self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP) + * self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0) + * self.iterdata.compute_baq = kwargs.get("compute_baq", True) # <<<<<<<<<<<<<< + * self.iterdata.redo_baq = kwargs.get("redo_baq", False) + * self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True) + */ + __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_compute_baq, Py_True); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2449, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2449, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_self->iterdata.compute_baq = __pyx_t_3; + + /* "pysam/libcalignmentfile.pyx":2450 + * self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0) + * self.iterdata.compute_baq = kwargs.get("compute_baq", True) + * self.iterdata.redo_baq = kwargs.get("redo_baq", False) # <<<<<<<<<<<<<< + * self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True) + * + */ + __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_redo_baq, Py_False); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2450, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2450, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_self->iterdata.redo_baq = __pyx_t_3; + + /* "pysam/libcalignmentfile.pyx":2451 + * self.iterdata.compute_baq = kwargs.get("compute_baq", True) + * self.iterdata.redo_baq = kwargs.get("redo_baq", False) + * self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True) # <<<<<<<<<<<<<< + * + * self.tid = 0 + */ + __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_ignore_orphans, Py_True); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2451, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2451, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_self->iterdata.ignore_orphans = __pyx_t_3; + + /* "pysam/libcalignmentfile.pyx":2453 + * self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True) + * * self.tid = 0 # <<<<<<<<<<<<<< * self.pos = 0 * self.n_plp = 0 */ __pyx_v_self->tid = 0; - /* "pysam/libcalignmentfile.pyx":2108 - * self.iterdata.seq = NULL + /* "pysam/libcalignmentfile.pyx":2454 + * * self.tid = 0 * self.pos = 0 # <<<<<<<<<<<<<< * self.n_plp = 0 @@ -24397,37 +29827,37 @@ static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(struct */ __pyx_v_self->pos = 0; - /* "pysam/libcalignmentfile.pyx":2109 + /* "pysam/libcalignmentfile.pyx":2455 * self.tid = 0 * self.pos = 0 * self.n_plp = 0 # <<<<<<<<<<<<<< * self.plp = NULL - * self.pileup_iter = NULL + * self.pileup_iter = NULL */ __pyx_v_self->n_plp = 0; - /* "pysam/libcalignmentfile.pyx":2110 + /* "pysam/libcalignmentfile.pyx":2456 * self.pos = 0 * self.n_plp = 0 * self.plp = NULL # <<<<<<<<<<<<<< - * self.pileup_iter = NULL + * self.pileup_iter = NULL * */ __pyx_v_self->plp = NULL; - /* "pysam/libcalignmentfile.pyx":2111 + /* "pysam/libcalignmentfile.pyx":2457 * self.n_plp = 0 * self.plp = NULL - * self.pileup_iter = NULL # <<<<<<<<<<<<<< + * self.pileup_iter = NULL # <<<<<<<<<<<<<< * * def __iter__(self): */ - __pyx_v_self->pileup_iter = ((bam_plp_t)NULL); + __pyx_v_self->pileup_iter = ((bam_mplp_t)NULL); - /* "pysam/libcalignmentfile.pyx":2101 + /* "pysam/libcalignmentfile.pyx":2437 * ''' * - * def __cinit__( self, AlignmentFile samfile, **kwargs ): # <<<<<<<<<<<<<< + * def __cinit__( self, AlignmentFile samfile, **kwargs): # <<<<<<<<<<<<<< * self.samfile = samfile * self.fastafile = kwargs.get("fastafile", None) */ @@ -24437,6 +29867,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(struct goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -24445,8 +29876,8 @@ static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(struct return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2113 - * self.pileup_iter = NULL +/* "pysam/libcalignmentfile.pyx":2459 + * self.pileup_iter = NULL * * def __iter__(self): # <<<<<<<<<<<<<< * return self @@ -24471,9 +29902,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_2__iter__( __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 2113, 0, __PYX_ERR(0, 2113, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 2459, 0, __PYX_ERR(0, 2459, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2114 + /* "pysam/libcalignmentfile.pyx":2460 * * def __iter__(self): * return self # <<<<<<<<<<<<<< @@ -24485,8 +29916,8 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_2__iter__( __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":2113 - * self.pileup_iter = NULL + /* "pysam/libcalignmentfile.pyx":2459 + * self.pileup_iter = NULL * * def __iter__(self): # <<<<<<<<<<<<<< * return self @@ -24504,7 +29935,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_2__iter__( return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2116 +/* "pysam/libcalignmentfile.pyx":2462 * return self * * cdef int cnext(self): # <<<<<<<<<<<<<< @@ -24513,22 +29944,33 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_2__iter__( */ static int __pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) { + int __pyx_v_ret; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("cnext", 0); - __Pyx_TraceCall("cnext", __pyx_f[0], 2116, 0, __PYX_ERR(0, 2116, __pyx_L1_error)); + __Pyx_TraceCall("cnext", __pyx_f[0], 2462, 0, __PYX_ERR(0, 2462, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2120 + /* "pysam/libcalignmentfile.pyx":2466 * ''' * # do not release gil here because of call-backs - * self.plp = bam_plp_auto(self.pileup_iter, # <<<<<<<<<<<<<< - * &self.tid, - * &self.pos, + * cdef int ret = bam_mplp_auto(self.pileup_iter, # <<<<<<<<<<<<<< + * &self.tid, + * &self.pos, */ - __pyx_v_self->plp = bam_plp_auto(__pyx_v_self->pileup_iter, (&__pyx_v_self->tid), (&__pyx_v_self->pos), (&__pyx_v_self->n_plp)); + __pyx_v_ret = bam_mplp_auto(__pyx_v_self->pileup_iter, (&__pyx_v_self->tid), (&__pyx_v_self->pos), (&__pyx_v_self->n_plp), (&__pyx_v_self->plp)); - /* "pysam/libcalignmentfile.pyx":2116 + /* "pysam/libcalignmentfile.pyx":2471 + * &self.n_plp, + * &self.plp) + * return ret # <<<<<<<<<<<<<< + * + * cdef char * get_sequence(self): + */ + __pyx_r = __pyx_v_ret; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":2462 * return self * * cdef int cnext(self): # <<<<<<<<<<<<<< @@ -24537,8 +29979,6 @@ static int __pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_cnext(struct __py */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorColumn.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_r = 0; @@ -24548,22 +29988,22 @@ static int __pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_cnext(struct __py return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2125 - * &self.n_plp) +/* "pysam/libcalignmentfile.pyx":2473 + * return ret * - * cdef char * getSequence(self): # <<<<<<<<<<<<<< + * cdef char * get_sequence(self): # <<<<<<<<<<<<<< * '''return current reference sequence underlying the iterator. * ''' */ -static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) { +static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_get_sequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) { char *__pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getSequence", 0); - __Pyx_TraceCall("getSequence", __pyx_f[0], 2125, 0, __PYX_ERR(0, 2125, __pyx_L1_error)); + __Pyx_RefNannySetupContext("get_sequence", 0); + __Pyx_TraceCall("get_sequence", __pyx_f[0], 2473, 0, __PYX_ERR(0, 2473, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2128 + /* "pysam/libcalignmentfile.pyx":2476 * '''return current reference sequence underlying the iterator. * ''' * return self.iterdata.seq # <<<<<<<<<<<<<< @@ -24573,17 +30013,17 @@ static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence(str __pyx_r = __pyx_v_self->iterdata.seq; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":2125 - * &self.n_plp) + /* "pysam/libcalignmentfile.pyx":2473 + * return ret * - * cdef char * getSequence(self): # <<<<<<<<<<<<<< + * cdef char * get_sequence(self): # <<<<<<<<<<<<<< * '''return current reference sequence underlying the iterator. * ''' */ /* function exit code */ __pyx_L1_error:; - __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorColumn.getSequence", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorColumn.get_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_r = 0; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -24591,7 +30031,7 @@ static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence(str return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2132 +/* "pysam/libcalignmentfile.pyx":2480 * property seq_len: * '''current sequence length.''' * def __get__(self): # <<<<<<<<<<<<<< @@ -24618,23 +30058,23 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len__ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2132, 0, __PYX_ERR(0, 2132, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2480, 0, __PYX_ERR(0, 2480, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2133 + /* "pysam/libcalignmentfile.pyx":2481 * '''current sequence length.''' * def __get__(self): * return self.iterdata.seq_len # <<<<<<<<<<<<<< * - * def addReference(self, Fastafile fastafile): + * def add_reference(self, FastaFile fastafile): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->iterdata.seq_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2133, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->iterdata.seq_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2481, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":2132 + /* "pysam/libcalignmentfile.pyx":2480 * property seq_len: * '''current sequence length.''' * def __get__(self): # <<<<<<<<<<<<<< @@ -24654,23 +30094,23 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len__ return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2135 +/* "pysam/libcalignmentfile.pyx":2483 * return self.iterdata.seq_len * - * def addReference(self, Fastafile fastafile): # <<<<<<<<<<<<<< + * def add_reference(self, FastaFile fastafile): # <<<<<<<<<<<<<< * ''' * add reference sequences in `fastafile` to iterator.''' */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_4addReference[] = "IteratorColumn.addReference(self, Fastafile fastafile)\n\n add reference sequences in `fastafile` to iterator."; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5add_reference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference[] = "IteratorColumn.add_reference(self, FastaFile fastafile)\n\n add reference sequences in `fastafile` to iterator."; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5add_reference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("addReference (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fastafile), __pyx_ptype_5pysam_9libcfaidx_Fastafile, 1, "fastafile", 0))) __PYX_ERR(0, 2135, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4addReference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), ((struct __pyx_obj_5pysam_9libcfaidx_Fastafile *)__pyx_v_fastafile)); + __Pyx_RefNannySetupContext("add_reference (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fastafile), __pyx_ptype_5pysam_9libcfaidx_FastaFile, 1, "fastafile", 0))) __PYX_ERR(0, 2483, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), ((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)__pyx_v_fastafile)); /* function exit code */ goto __pyx_L0; @@ -24681,16 +30121,16 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5addRefere return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4addReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_Fastafile *__pyx_v_fastafile) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; faidx_t *__pyx_t_2; - __Pyx_RefNannySetupContext("addReference", 0); - __Pyx_TraceCall("addReference", __pyx_f[0], 2135, 0, __PYX_ERR(0, 2135, __pyx_L1_error)); + __Pyx_RefNannySetupContext("add_reference", 0); + __Pyx_TraceCall("add_reference", __pyx_f[0], 2483, 0, __PYX_ERR(0, 2483, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2138 + /* "pysam/libcalignmentfile.pyx":2486 * ''' * add reference sequences in `fastafile` to iterator.''' * self.fastafile = fastafile # <<<<<<<<<<<<<< @@ -24703,7 +30143,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4addRefere __Pyx_DECREF(((PyObject *)__pyx_v_self->fastafile)); __pyx_v_self->fastafile = __pyx_v_fastafile; - /* "pysam/libcalignmentfile.pyx":2139 + /* "pysam/libcalignmentfile.pyx":2487 * add reference sequences in `fastafile` to iterator.''' * self.fastafile = fastafile * if self.iterdata.seq != NULL: # <<<<<<<<<<<<<< @@ -24713,7 +30153,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4addRefere __pyx_t_1 = ((__pyx_v_self->iterdata.seq != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2140 + /* "pysam/libcalignmentfile.pyx":2488 * self.fastafile = fastafile * if self.iterdata.seq != NULL: * free(self.iterdata.seq) # <<<<<<<<<<<<<< @@ -24722,7 +30162,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4addRefere */ free(__pyx_v_self->iterdata.seq); - /* "pysam/libcalignmentfile.pyx":2139 + /* "pysam/libcalignmentfile.pyx":2487 * add reference sequences in `fastafile` to iterator.''' * self.fastafile = fastafile * if self.iterdata.seq != NULL: # <<<<<<<<<<<<<< @@ -24731,7 +30171,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4addRefere */ } - /* "pysam/libcalignmentfile.pyx":2141 + /* "pysam/libcalignmentfile.pyx":2489 * if self.iterdata.seq != NULL: * free(self.iterdata.seq) * self.iterdata.tid = -1 # <<<<<<<<<<<<<< @@ -24740,20 +30180,20 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4addRefere */ __pyx_v_self->iterdata.tid = -1; - /* "pysam/libcalignmentfile.pyx":2142 + /* "pysam/libcalignmentfile.pyx":2490 * free(self.iterdata.seq) * self.iterdata.tid = -1 * self.iterdata.fastafile = self.fastafile.fastafile # <<<<<<<<<<<<<< * - * def hasReference(self): + * def has_reference(self): */ - __pyx_t_2 = __pyx_v_self->fastafile->__pyx_base.fastafile; + __pyx_t_2 = __pyx_v_self->fastafile->fastafile; __pyx_v_self->iterdata.fastafile = __pyx_t_2; - /* "pysam/libcalignmentfile.pyx":2135 + /* "pysam/libcalignmentfile.pyx":2483 * return self.iterdata.seq_len * - * def addReference(self, Fastafile fastafile): # <<<<<<<<<<<<<< + * def add_reference(self, FastaFile fastafile): # <<<<<<<<<<<<<< * ''' * add reference sequences in `fastafile` to iterator.''' */ @@ -24762,7 +30202,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4addRefere __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.addReference", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.add_reference", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -24771,58 +30211,58 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4addRefere return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2144 +/* "pysam/libcalignmentfile.pyx":2492 * self.iterdata.fastafile = self.fastafile.fastafile * - * def hasReference(self): # <<<<<<<<<<<<<< + * def has_reference(self): # <<<<<<<<<<<<<< * ''' * return true if iterator is associated with a reference''' */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_6hasReference[] = "IteratorColumn.hasReference(self)\n\n return true if iterator is associated with a reference"; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7has_reference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference[] = "IteratorColumn.has_reference(self)\n\n return true if iterator is associated with a reference"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7has_reference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("hasReference (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6hasReference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self)); + __Pyx_RefNannySetupContext("has_reference (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6hasReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("hasReference", 0); - __Pyx_TraceCall("hasReference", __pyx_f[0], 2144, 0, __PYX_ERR(0, 2144, __pyx_L1_error)); + __Pyx_RefNannySetupContext("has_reference", 0); + __Pyx_TraceCall("has_reference", __pyx_f[0], 2492, 0, __PYX_ERR(0, 2492, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2147 + /* "pysam/libcalignmentfile.pyx":2495 * ''' * return true if iterator is associated with a reference''' * return self.fastafile # <<<<<<<<<<<<<< * - * cdef setMask(self, mask): + * cdef _setup_iterator(self, */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_self->fastafile)); __pyx_r = ((PyObject *)__pyx_v_self->fastafile); goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":2144 + /* "pysam/libcalignmentfile.pyx":2492 * self.iterdata.fastafile = self.fastafile.fastafile * - * def hasReference(self): # <<<<<<<<<<<<<< + * def has_reference(self): # <<<<<<<<<<<<<< * ''' * return true if iterator is associated with a reference''' */ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.hasReference", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.has_reference", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -24831,64 +30271,17 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6hasRefere return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2149 - * return self.fastafile - * - * cdef setMask(self, mask): # <<<<<<<<<<<<<< - * '''set masking flag in iterator. - * - */ - -static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setMask(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_mask) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("setMask", 0); - __Pyx_TraceCall("setMask", __pyx_f[0], 2149, 0, __PYX_ERR(0, 2149, __pyx_L1_error)); - - /* "pysam/libcalignmentfile.pyx":2154 - * reads with bits set in `mask` will be skipped. - * ''' - * raise NotImplementedError() # <<<<<<<<<<<<<< - * # self.mask = mask - * # bam_plp_set_mask( self.pileup_iter, self.mask ) - */ - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_NotImplementedError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 2154, __pyx_L1_error) - - /* "pysam/libcalignmentfile.pyx":2149 +/* "pysam/libcalignmentfile.pyx":2497 * return self.fastafile * - * cdef setMask(self, mask): # <<<<<<<<<<<<<< - * '''set masking flag in iterator. - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.setMask", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcalignmentfile.pyx":2158 - * # bam_plp_set_mask( self.pileup_iter, self.mask ) - * - * cdef setupIteratorData( self, # <<<<<<<<<<<<<< - * int tid, - * int start, + * cdef _setup_iterator(self, # <<<<<<<<<<<<<< + * int tid, + * int start, */ -static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData *__pyx_optional_args) { +static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_stop, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args) { int __pyx_v_multiple_iterators = ((int)0); + void *__pyx_v_data[1]; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -24904,30 +30297,30 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat int __pyx_t_10; faidx_t *__pyx_t_11; int __pyx_t_12; - __Pyx_RefNannySetupContext("setupIteratorData", 0); - __Pyx_TraceCall("setupIteratorData", __pyx_f[0], 2158, 0, __PYX_ERR(0, 2158, __pyx_L1_error)); + __Pyx_RefNannySetupContext("_setup_iterator", 0); + __Pyx_TraceCall("_setup_iterator", __pyx_f[0], 2497, 0, __PYX_ERR(0, 2497, __pyx_L1_error)); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_multiple_iterators = __pyx_optional_args->multiple_iterators; } } - /* "pysam/libcalignmentfile.pyx":2165 + /* "pysam/libcalignmentfile.pyx":2504 * '''setup the iterator structure''' * - * self.iter = IteratorRowRegion(self.samfile, tid, start, end, multiple_iterators) # <<<<<<<<<<<<<< + * self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators) # <<<<<<<<<<<<<< * self.iterdata.htsfile = self.samfile.htsfile * self.iterdata.iter = self.iter.iter */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2165, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_start); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2165, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_start); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_end); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2165, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_stop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2165, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2165, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile)); @@ -24944,7 +30337,7 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2165, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GIVEREF(__pyx_t_4); @@ -24953,9 +30346,9 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat __pyx_v_self->iter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":2166 + /* "pysam/libcalignmentfile.pyx":2505 * - * self.iter = IteratorRowRegion(self.samfile, tid, start, end, multiple_iterators) + * self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators) * self.iterdata.htsfile = self.samfile.htsfile # <<<<<<<<<<<<<< * self.iterdata.iter = self.iter.iter * self.iterdata.seq = NULL @@ -24963,8 +30356,8 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat __pyx_t_6 = __pyx_v_self->samfile->__pyx_base.htsfile; __pyx_v_self->iterdata.htsfile = __pyx_t_6; - /* "pysam/libcalignmentfile.pyx":2167 - * self.iter = IteratorRowRegion(self.samfile, tid, start, end, multiple_iterators) + /* "pysam/libcalignmentfile.pyx":2506 + * self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators) * self.iterdata.htsfile = self.samfile.htsfile * self.iterdata.iter = self.iter.iter # <<<<<<<<<<<<<< * self.iterdata.seq = NULL @@ -24973,36 +30366,36 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat __pyx_t_7 = __pyx_v_self->iter->iter; __pyx_v_self->iterdata.iter = __pyx_t_7; - /* "pysam/libcalignmentfile.pyx":2168 + /* "pysam/libcalignmentfile.pyx":2507 * self.iterdata.htsfile = self.samfile.htsfile * self.iterdata.iter = self.iter.iter * self.iterdata.seq = NULL # <<<<<<<<<<<<<< * self.iterdata.tid = -1 - * self.iterdata.header = self.samfile.header + * self.iterdata.header = self.samfile.header.ptr */ __pyx_v_self->iterdata.seq = NULL; - /* "pysam/libcalignmentfile.pyx":2169 + /* "pysam/libcalignmentfile.pyx":2508 * self.iterdata.iter = self.iter.iter * self.iterdata.seq = NULL * self.iterdata.tid = -1 # <<<<<<<<<<<<<< - * self.iterdata.header = self.samfile.header + * self.iterdata.header = self.samfile.header.ptr * */ __pyx_v_self->iterdata.tid = -1; - /* "pysam/libcalignmentfile.pyx":2170 + /* "pysam/libcalignmentfile.pyx":2509 * self.iterdata.seq = NULL * self.iterdata.tid = -1 - * self.iterdata.header = self.samfile.header # <<<<<<<<<<<<<< + * self.iterdata.header = self.samfile.header.ptr # <<<<<<<<<<<<<< * * if self.fastafile is not None: */ - __pyx_t_8 = __pyx_v_self->samfile->header; + __pyx_t_8 = __pyx_v_self->samfile->header->ptr; __pyx_v_self->iterdata.header = __pyx_t_8; - /* "pysam/libcalignmentfile.pyx":2172 - * self.iterdata.header = self.samfile.header + /* "pysam/libcalignmentfile.pyx":2511 + * self.iterdata.header = self.samfile.header.ptr * * if self.fastafile is not None: # <<<<<<<<<<<<<< * self.iterdata.fastafile = self.fastafile.fastafile @@ -25012,18 +30405,18 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat __pyx_t_10 = (__pyx_t_9 != 0); if (__pyx_t_10) { - /* "pysam/libcalignmentfile.pyx":2173 + /* "pysam/libcalignmentfile.pyx":2512 * * if self.fastafile is not None: * self.iterdata.fastafile = self.fastafile.fastafile # <<<<<<<<<<<<<< * else: * self.iterdata.fastafile = NULL */ - __pyx_t_11 = __pyx_v_self->fastafile->__pyx_base.fastafile; + __pyx_t_11 = __pyx_v_self->fastafile->fastafile; __pyx_v_self->iterdata.fastafile = __pyx_t_11; - /* "pysam/libcalignmentfile.pyx":2172 - * self.iterdata.header = self.samfile.header + /* "pysam/libcalignmentfile.pyx":2511 + * self.iterdata.header = self.samfile.header.ptr * * if self.fastafile is not None: # <<<<<<<<<<<<<< * self.iterdata.fastafile = self.fastafile.fastafile @@ -25032,7 +30425,7 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat goto __pyx_L3; } - /* "pysam/libcalignmentfile.pyx":2175 + /* "pysam/libcalignmentfile.pyx":2514 * self.iterdata.fastafile = self.fastafile.fastafile * else: * self.iterdata.fastafile = NULL # <<<<<<<<<<<<<< @@ -25044,23 +30437,32 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat } __pyx_L3:; - /* "pysam/libcalignmentfile.pyx":2179 + /* "pysam/libcalignmentfile.pyx":2518 * # Free any previously allocated memory before reassigning * # pileup_iter * self._free_pileup_iter() # <<<<<<<<<<<<<< * - * if self.stepper is None or self.stepper == "all": + * cdef void * data[1] */ - __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->_free_pileup_iter(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2179, __pyx_L1_error) + __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->_free_pileup_iter(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2518, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":2181 - * self._free_pileup_iter() + /* "pysam/libcalignmentfile.pyx":2521 + * + * cdef void * data[1] + * data[0] = &self.iterdata # <<<<<<<<<<<<<< + * + * if self.stepper is None or self.stepper == "all": + */ + (__pyx_v_data[0]) = ((void *)(&__pyx_v_self->iterdata)); + + /* "pysam/libcalignmentfile.pyx":2523 + * data[0] = &self.iterdata * * if self.stepper is None or self.stepper == "all": # <<<<<<<<<<<<<< * with nogil: - * self.pileup_iter = bam_plp_init( + * self.pileup_iter = bam_mplp_init(1, */ __pyx_t_9 = (__pyx_v_self->stepper == Py_None); __pyx_t_12 = (__pyx_t_9 != 0); @@ -25069,17 +30471,17 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat __pyx_t_10 = __pyx_t_12; goto __pyx_L5_bool_binop_done; } - __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2181, __pyx_L1_error) + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2523, __pyx_L1_error) __pyx_t_10 = __pyx_t_12; __pyx_L5_bool_binop_done:; if (__pyx_t_10) { - /* "pysam/libcalignmentfile.pyx":2182 + /* "pysam/libcalignmentfile.pyx":2524 * * if self.stepper is None or self.stepper == "all": * with nogil: # <<<<<<<<<<<<<< - * self.pileup_iter = bam_plp_init( - * &__advance_all, + * self.pileup_iter = bam_mplp_init(1, + * &__advance_all, */ { #ifdef WITH_THREAD @@ -25089,22 +30491,22 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":2183 + /* "pysam/libcalignmentfile.pyx":2525 * if self.stepper is None or self.stepper == "all": * with nogil: - * self.pileup_iter = bam_plp_init( # <<<<<<<<<<<<<< - * &__advance_all, - * &self.iterdata) + * self.pileup_iter = bam_mplp_init(1, # <<<<<<<<<<<<<< + * &__advance_all, + * data) */ - __pyx_v_self->pileup_iter = bam_plp_init(((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_all)), (&__pyx_v_self->iterdata)); + __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_all)), __pyx_v_data); } - /* "pysam/libcalignmentfile.pyx":2182 + /* "pysam/libcalignmentfile.pyx":2524 * * if self.stepper is None or self.stepper == "all": * with nogil: # <<<<<<<<<<<<<< - * self.pileup_iter = bam_plp_init( - * &__advance_all, + * self.pileup_iter = bam_mplp_init(1, + * &__advance_all, */ /*finally:*/ { /*normal exit:*/{ @@ -25118,32 +30520,32 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat } } - /* "pysam/libcalignmentfile.pyx":2181 - * self._free_pileup_iter() + /* "pysam/libcalignmentfile.pyx":2523 + * data[0] = &self.iterdata * * if self.stepper is None or self.stepper == "all": # <<<<<<<<<<<<<< * with nogil: - * self.pileup_iter = bam_plp_init( + * self.pileup_iter = bam_mplp_init(1, */ goto __pyx_L4; } - /* "pysam/libcalignmentfile.pyx":2186 - * &__advance_all, - * &self.iterdata) + /* "pysam/libcalignmentfile.pyx":2528 + * &__advance_all, + * data) * elif self.stepper == "nofilter": # <<<<<<<<<<<<<< * with nogil: - * self.pileup_iter = bam_plp_init( + * self.pileup_iter = bam_mplp_init(1, */ - __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_nofilter, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 2186, __pyx_L1_error) + __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_nofilter, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 2528, __pyx_L1_error) if (__pyx_t_10) { - /* "pysam/libcalignmentfile.pyx":2187 - * &self.iterdata) + /* "pysam/libcalignmentfile.pyx":2529 + * data) * elif self.stepper == "nofilter": * with nogil: # <<<<<<<<<<<<<< - * self.pileup_iter = bam_plp_init( - * &__advance_nofilter, + * self.pileup_iter = bam_mplp_init(1, + * &__advance_nofilter, */ { #ifdef WITH_THREAD @@ -25153,22 +30555,22 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":2188 + /* "pysam/libcalignmentfile.pyx":2530 * elif self.stepper == "nofilter": * with nogil: - * self.pileup_iter = bam_plp_init( # <<<<<<<<<<<<<< - * &__advance_nofilter, - * &self.iterdata) + * self.pileup_iter = bam_mplp_init(1, # <<<<<<<<<<<<<< + * &__advance_nofilter, + * data) */ - __pyx_v_self->pileup_iter = bam_plp_init(((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_nofilter)), (&__pyx_v_self->iterdata)); + __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_nofilter)), __pyx_v_data); } - /* "pysam/libcalignmentfile.pyx":2187 - * &self.iterdata) + /* "pysam/libcalignmentfile.pyx":2529 + * data) * elif self.stepper == "nofilter": * with nogil: # <<<<<<<<<<<<<< - * self.pileup_iter = bam_plp_init( - * &__advance_nofilter, + * self.pileup_iter = bam_mplp_init(1, + * &__advance_nofilter, */ /*finally:*/ { /*normal exit:*/{ @@ -25182,32 +30584,32 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat } } - /* "pysam/libcalignmentfile.pyx":2186 - * &__advance_all, - * &self.iterdata) + /* "pysam/libcalignmentfile.pyx":2528 + * &__advance_all, + * data) * elif self.stepper == "nofilter": # <<<<<<<<<<<<<< * with nogil: - * self.pileup_iter = bam_plp_init( + * self.pileup_iter = bam_mplp_init(1, */ goto __pyx_L4; } - /* "pysam/libcalignmentfile.pyx":2191 - * &__advance_nofilter, - * &self.iterdata) + /* "pysam/libcalignmentfile.pyx":2533 + * &__advance_nofilter, + * data) * elif self.stepper == "samtools": # <<<<<<<<<<<<<< * with nogil: - * self.pileup_iter = bam_plp_init( + * self.pileup_iter = bam_mplp_init(1, */ - __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_samtools, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 2191, __pyx_L1_error) + __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_samtools, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 2533, __pyx_L1_error) if (likely(__pyx_t_10)) { - /* "pysam/libcalignmentfile.pyx":2192 - * &self.iterdata) + /* "pysam/libcalignmentfile.pyx":2534 + * data) * elif self.stepper == "samtools": * with nogil: # <<<<<<<<<<<<<< - * self.pileup_iter = bam_plp_init( - * &__advance_snpcalls, + * self.pileup_iter = bam_mplp_init(1, + * &__advance_samtools, */ { #ifdef WITH_THREAD @@ -25217,22 +30619,22 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":2193 + /* "pysam/libcalignmentfile.pyx":2535 * elif self.stepper == "samtools": * with nogil: - * self.pileup_iter = bam_plp_init( # <<<<<<<<<<<<<< - * &__advance_snpcalls, - * &self.iterdata) + * self.pileup_iter = bam_mplp_init(1, # <<<<<<<<<<<<<< + * &__advance_samtools, + * data) */ - __pyx_v_self->pileup_iter = bam_plp_init(((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_snpcalls)), (&__pyx_v_self->iterdata)); + __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_samtools)), __pyx_v_data); } - /* "pysam/libcalignmentfile.pyx":2192 - * &self.iterdata) + /* "pysam/libcalignmentfile.pyx":2534 + * data) * elif self.stepper == "samtools": * with nogil: # <<<<<<<<<<<<<< - * self.pileup_iter = bam_plp_init( - * &__advance_snpcalls, + * self.pileup_iter = bam_mplp_init(1, + * &__advance_samtools, */ /*finally:*/ { /*normal exit:*/{ @@ -25246,18 +30648,18 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat } } - /* "pysam/libcalignmentfile.pyx":2191 - * &__advance_nofilter, - * &self.iterdata) + /* "pysam/libcalignmentfile.pyx":2533 + * &__advance_nofilter, + * data) * elif self.stepper == "samtools": # <<<<<<<<<<<<<< * with nogil: - * self.pileup_iter = bam_plp_init( + * self.pileup_iter = bam_mplp_init(1, */ goto __pyx_L4; } - /* "pysam/libcalignmentfile.pyx":2197 - * &self.iterdata) + /* "pysam/libcalignmentfile.pyx":2539 + * data) * else: * raise ValueError( # <<<<<<<<<<<<<< * "unknown stepper option `%s` in IteratorColumn" % self.stepper) @@ -25265,47 +30667,47 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat */ /*else*/ { - /* "pysam/libcalignmentfile.pyx":2198 + /* "pysam/libcalignmentfile.pyx":2540 * else: * raise ValueError( * "unknown stepper option `%s` in IteratorColumn" % self.stepper) # <<<<<<<<<<<<<< * * if self.max_depth: */ - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_unknown_stepper_option_s_in_Iter, __pyx_v_self->stepper); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2198, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_unknown_stepper_option_s_in_Iter, __pyx_v_self->stepper); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2540, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libcalignmentfile.pyx":2197 - * &self.iterdata) + /* "pysam/libcalignmentfile.pyx":2539 + * data) * else: * raise ValueError( # <<<<<<<<<<<<<< * "unknown stepper option `%s` in IteratorColumn" % self.stepper) * */ - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2197, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2539, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 2197, __pyx_L1_error) + __PYX_ERR(0, 2539, __pyx_L1_error) } __pyx_L4:; - /* "pysam/libcalignmentfile.pyx":2200 + /* "pysam/libcalignmentfile.pyx":2542 * "unknown stepper option `%s` in IteratorColumn" % self.stepper) * * if self.max_depth: # <<<<<<<<<<<<<< * with nogil: - * bam_plp_set_maxcnt(self.pileup_iter, self.max_depth) + * bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth) */ __pyx_t_10 = (__pyx_v_self->max_depth != 0); if (__pyx_t_10) { - /* "pysam/libcalignmentfile.pyx":2201 + /* "pysam/libcalignmentfile.pyx":2543 * * if self.max_depth: * with nogil: # <<<<<<<<<<<<<< - * bam_plp_set_maxcnt(self.pileup_iter, self.max_depth) + * bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth) * */ { @@ -25316,21 +30718,21 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":2202 + /* "pysam/libcalignmentfile.pyx":2544 * if self.max_depth: * with nogil: - * bam_plp_set_maxcnt(self.pileup_iter, self.max_depth) # <<<<<<<<<<<<<< + * bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth) # <<<<<<<<<<<<<< * - * # bam_plp_set_mask( self.pileup_iter, self.mask ) + * if self.ignore_overlaps: */ - bam_plp_set_maxcnt(__pyx_v_self->pileup_iter, __pyx_v_self->max_depth); + bam_mplp_set_maxcnt(__pyx_v_self->pileup_iter, __pyx_v_self->max_depth); } - /* "pysam/libcalignmentfile.pyx":2201 + /* "pysam/libcalignmentfile.pyx":2543 * * if self.max_depth: * with nogil: # <<<<<<<<<<<<<< - * bam_plp_set_maxcnt(self.pileup_iter, self.max_depth) + * bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth) * */ /*finally:*/ { @@ -25345,21 +30747,84 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat } } - /* "pysam/libcalignmentfile.pyx":2200 + /* "pysam/libcalignmentfile.pyx":2542 * "unknown stepper option `%s` in IteratorColumn" % self.stepper) * * if self.max_depth: # <<<<<<<<<<<<<< * with nogil: - * bam_plp_set_maxcnt(self.pileup_iter, self.max_depth) + * bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth) + */ + } + + /* "pysam/libcalignmentfile.pyx":2546 + * bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth) + * + * if self.ignore_overlaps: # <<<<<<<<<<<<<< + * with nogil: + * bam_mplp_init_overlaps(self.pileup_iter) + */ + __pyx_t_10 = (__pyx_v_self->ignore_overlaps != 0); + if (__pyx_t_10) { + + /* "pysam/libcalignmentfile.pyx":2547 + * + * if self.ignore_overlaps: + * with nogil: # <<<<<<<<<<<<<< + * bam_mplp_init_overlaps(self.pileup_iter) + * + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libcalignmentfile.pyx":2548 + * if self.ignore_overlaps: + * with nogil: + * bam_mplp_init_overlaps(self.pileup_iter) # <<<<<<<<<<<<<< + * + * cdef reset(self, tid, start, stop): + */ + bam_mplp_init_overlaps(__pyx_v_self->pileup_iter); + } + + /* "pysam/libcalignmentfile.pyx":2547 + * + * if self.ignore_overlaps: + * with nogil: # <<<<<<<<<<<<<< + * bam_mplp_init_overlaps(self.pileup_iter) + * + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L23; + } + __pyx_L23:; + } + } + + /* "pysam/libcalignmentfile.pyx":2546 + * bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth) + * + * if self.ignore_overlaps: # <<<<<<<<<<<<<< + * with nogil: + * bam_mplp_init_overlaps(self.pileup_iter) */ } - /* "pysam/libcalignmentfile.pyx":2158 - * # bam_plp_set_mask( self.pileup_iter, self.mask ) + /* "pysam/libcalignmentfile.pyx":2497 + * return self.fastafile * - * cdef setupIteratorData( self, # <<<<<<<<<<<<<< - * int tid, - * int start, + * cdef _setup_iterator(self, # <<<<<<<<<<<<<< + * int tid, + * int start, */ /* function exit code */ @@ -25371,7 +30836,7 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.setupIteratorData", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn._setup_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -25380,15 +30845,15 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIterat return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2206 - * # bam_plp_set_mask( self.pileup_iter, self.mask ) +/* "pysam/libcalignmentfile.pyx":2550 + * bam_mplp_init_overlaps(self.pileup_iter) * - * cdef reset( self, tid, start, end ): # <<<<<<<<<<<<<< + * cdef reset(self, tid, start, stop): # <<<<<<<<<<<<<< * '''reset iterator position. * */ -static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_tid, PyObject *__pyx_v_start, PyObject *__pyx_v_end) { +static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_tid, PyObject *__pyx_v_start, PyObject *__pyx_v_stop) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -25398,16 +30863,16 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struc hts_itr_t *__pyx_t_4; int __pyx_t_5; __Pyx_RefNannySetupContext("reset", 0); - __Pyx_TraceCall("reset", __pyx_f[0], 2206, 0, __PYX_ERR(0, 2206, __pyx_L1_error)); + __Pyx_TraceCall("reset", __pyx_f[0], 2550, 0, __PYX_ERR(0, 2550, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2212 + /* "pysam/libcalignmentfile.pyx":2556 * having to incur the full set-up costs. * ''' - * self.iter = IteratorRowRegion( self.samfile, tid, start, end, multiple_iterators = 0 ) # <<<<<<<<<<<<<< + * self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators=0) # <<<<<<<<<<<<<< * self.iterdata.iter = self.iter.iter * */ - __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2212, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2556, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile)); @@ -25418,13 +30883,13 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struc __Pyx_INCREF(__pyx_v_start); __Pyx_GIVEREF(__pyx_v_start); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_start); - __Pyx_INCREF(__pyx_v_end); - __Pyx_GIVEREF(__pyx_v_end); - PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_end); - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2212, __pyx_L1_error) + __Pyx_INCREF(__pyx_v_stop); + __Pyx_GIVEREF(__pyx_v_stop); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_stop); + __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2556, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_multiple_iterators, __pyx_int_0) < 0) __PYX_ERR(0, 2212, __pyx_L1_error) - __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2212, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_multiple_iterators, __pyx_int_0) < 0) __PYX_ERR(0, 2556, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2556, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -25434,9 +30899,9 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struc __pyx_v_self->iter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignmentfile.pyx":2213 + /* "pysam/libcalignmentfile.pyx":2557 * ''' - * self.iter = IteratorRowRegion( self.samfile, tid, start, end, multiple_iterators = 0 ) + * self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators=0) * self.iterdata.iter = self.iter.iter # <<<<<<<<<<<<<< * * # invalidate sequence if different tid @@ -25444,22 +30909,22 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struc __pyx_t_4 = __pyx_v_self->iter->iter; __pyx_v_self->iterdata.iter = __pyx_t_4; - /* "pysam/libcalignmentfile.pyx":2216 + /* "pysam/libcalignmentfile.pyx":2560 * * # invalidate sequence if different tid * if self.tid != tid: # <<<<<<<<<<<<<< * if self.iterdata.seq != NULL: * free(self.iterdata.seq) */ - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2216, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_v_tid, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2216, __pyx_L1_error) + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_v_tid, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2560, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2216, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2560, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_5) { - /* "pysam/libcalignmentfile.pyx":2217 + /* "pysam/libcalignmentfile.pyx":2561 * # invalidate sequence if different tid * if self.tid != tid: * if self.iterdata.seq != NULL: # <<<<<<<<<<<<<< @@ -25469,7 +30934,7 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struc __pyx_t_5 = ((__pyx_v_self->iterdata.seq != NULL) != 0); if (__pyx_t_5) { - /* "pysam/libcalignmentfile.pyx":2218 + /* "pysam/libcalignmentfile.pyx":2562 * if self.tid != tid: * if self.iterdata.seq != NULL: * free(self.iterdata.seq) # <<<<<<<<<<<<<< @@ -25478,7 +30943,7 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struc */ free(__pyx_v_self->iterdata.seq); - /* "pysam/libcalignmentfile.pyx":2217 + /* "pysam/libcalignmentfile.pyx":2561 * # invalidate sequence if different tid * if self.tid != tid: * if self.iterdata.seq != NULL: # <<<<<<<<<<<<<< @@ -25487,7 +30952,7 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struc */ } - /* "pysam/libcalignmentfile.pyx":2219 + /* "pysam/libcalignmentfile.pyx":2563 * if self.iterdata.seq != NULL: * free(self.iterdata.seq) * self.iterdata.seq = NULL # <<<<<<<<<<<<<< @@ -25496,16 +30961,16 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struc */ __pyx_v_self->iterdata.seq = NULL; - /* "pysam/libcalignmentfile.pyx":2220 + /* "pysam/libcalignmentfile.pyx":2564 * free(self.iterdata.seq) * self.iterdata.seq = NULL * self.iterdata.tid = -1 # <<<<<<<<<<<<<< * - * # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata ) + * # self.pileup_iter = bam_mplp_init(1 */ __pyx_v_self->iterdata.tid = -1; - /* "pysam/libcalignmentfile.pyx":2216 + /* "pysam/libcalignmentfile.pyx":2560 * * # invalidate sequence if different tid * if self.tid != tid: # <<<<<<<<<<<<<< @@ -25514,11 +30979,11 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struc */ } - /* "pysam/libcalignmentfile.pyx":2223 - * - * # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata ) + /* "pysam/libcalignmentfile.pyx":2569 + * # &__advancepileup, + * # &self.iterdata) * with nogil: # <<<<<<<<<<<<<< - * bam_plp_reset(self.pileup_iter) + * bam_mplp_reset(self.pileup_iter) * */ { @@ -25529,21 +30994,21 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struc #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":2224 - * # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata ) + /* "pysam/libcalignmentfile.pyx":2570 + * # &self.iterdata) * with nogil: - * bam_plp_reset(self.pileup_iter) # <<<<<<<<<<<<<< + * bam_mplp_reset(self.pileup_iter) # <<<<<<<<<<<<<< * * cdef _free_pileup_iter(self): */ - bam_plp_reset(__pyx_v_self->pileup_iter); + bam_mplp_reset(__pyx_v_self->pileup_iter); } - /* "pysam/libcalignmentfile.pyx":2223 - * - * # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata ) + /* "pysam/libcalignmentfile.pyx":2569 + * # &__advancepileup, + * # &self.iterdata) * with nogil: # <<<<<<<<<<<<<< - * bam_plp_reset(self.pileup_iter) + * bam_mplp_reset(self.pileup_iter) * */ /*finally:*/ { @@ -25558,10 +31023,10 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struc } } - /* "pysam/libcalignmentfile.pyx":2206 - * # bam_plp_set_mask( self.pileup_iter, self.mask ) + /* "pysam/libcalignmentfile.pyx":2550 + * bam_mplp_init_overlaps(self.pileup_iter) * - * cdef reset( self, tid, start, end ): # <<<<<<<<<<<<<< + * cdef reset(self, tid, start, stop): # <<<<<<<<<<<<<< * '''reset iterator position. * */ @@ -25582,8 +31047,8 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struc return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2226 - * bam_plp_reset(self.pileup_iter) +/* "pysam/libcalignmentfile.pyx":2572 + * bam_mplp_reset(self.pileup_iter) * * cdef _free_pileup_iter(self): # <<<<<<<<<<<<<< * '''free the memory alloc'd by bam_plp_init. @@ -25596,24 +31061,24 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__free_pileu __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("_free_pileup_iter", 0); - __Pyx_TraceCall("_free_pileup_iter", __pyx_f[0], 2226, 0, __PYX_ERR(0, 2226, __pyx_L1_error)); + __Pyx_TraceCall("_free_pileup_iter", __pyx_f[0], 2572, 0, __PYX_ERR(0, 2572, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2232 - * another pileup_iter, or else memory will be lost. - * ''' - * if self.pileup_iter != NULL: # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2577 + * This is needed before setup_iterator allocates another + * pileup_iter, or else memory will be lost. ''' + * if self.pileup_iter != NULL: # <<<<<<<<<<<<<< * with nogil: - * bam_plp_reset(self.pileup_iter) + * bam_mplp_reset(self.pileup_iter) */ - __pyx_t_1 = ((__pyx_v_self->pileup_iter != ((bam_plp_t)NULL)) != 0); + __pyx_t_1 = ((__pyx_v_self->pileup_iter != ((bam_mplp_t)NULL)) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2233 - * ''' - * if self.pileup_iter != NULL: + /* "pysam/libcalignmentfile.pyx":2578 + * pileup_iter, or else memory will be lost. ''' + * if self.pileup_iter != NULL: * with nogil: # <<<<<<<<<<<<<< - * bam_plp_reset(self.pileup_iter) - * bam_plp_destroy(self.pileup_iter) + * bam_mplp_reset(self.pileup_iter) + * bam_mplp_destroy(self.pileup_iter) */ { #ifdef WITH_THREAD @@ -25623,40 +31088,40 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__free_pileu #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":2234 - * if self.pileup_iter != NULL: + /* "pysam/libcalignmentfile.pyx":2579 + * if self.pileup_iter != NULL: * with nogil: - * bam_plp_reset(self.pileup_iter) # <<<<<<<<<<<<<< - * bam_plp_destroy(self.pileup_iter) - * self.pileup_iter = NULL + * bam_mplp_reset(self.pileup_iter) # <<<<<<<<<<<<<< + * bam_mplp_destroy(self.pileup_iter) + * self.pileup_iter = NULL */ - bam_plp_reset(__pyx_v_self->pileup_iter); + bam_mplp_reset(__pyx_v_self->pileup_iter); - /* "pysam/libcalignmentfile.pyx":2235 + /* "pysam/libcalignmentfile.pyx":2580 * with nogil: - * bam_plp_reset(self.pileup_iter) - * bam_plp_destroy(self.pileup_iter) # <<<<<<<<<<<<<< - * self.pileup_iter = NULL + * bam_mplp_reset(self.pileup_iter) + * bam_mplp_destroy(self.pileup_iter) # <<<<<<<<<<<<<< + * self.pileup_iter = NULL * */ - bam_plp_destroy(__pyx_v_self->pileup_iter); + bam_mplp_destroy(__pyx_v_self->pileup_iter); - /* "pysam/libcalignmentfile.pyx":2236 - * bam_plp_reset(self.pileup_iter) - * bam_plp_destroy(self.pileup_iter) - * self.pileup_iter = NULL # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2581 + * bam_mplp_reset(self.pileup_iter) + * bam_mplp_destroy(self.pileup_iter) + * self.pileup_iter = NULL # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __pyx_v_self->pileup_iter = ((bam_plp_t)NULL); + __pyx_v_self->pileup_iter = ((bam_mplp_t)NULL); } - /* "pysam/libcalignmentfile.pyx":2233 - * ''' - * if self.pileup_iter != NULL: + /* "pysam/libcalignmentfile.pyx":2578 + * pileup_iter, or else memory will be lost. ''' + * if self.pileup_iter != NULL: * with nogil: # <<<<<<<<<<<<<< - * bam_plp_reset(self.pileup_iter) - * bam_plp_destroy(self.pileup_iter) + * bam_mplp_reset(self.pileup_iter) + * bam_mplp_destroy(self.pileup_iter) */ /*finally:*/ { /*normal exit:*/{ @@ -25670,17 +31135,17 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__free_pileu } } - /* "pysam/libcalignmentfile.pyx":2232 - * another pileup_iter, or else memory will be lost. - * ''' - * if self.pileup_iter != NULL: # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2577 + * This is needed before setup_iterator allocates another + * pileup_iter, or else memory will be lost. ''' + * if self.pileup_iter != NULL: # <<<<<<<<<<<<<< * with nogil: - * bam_plp_reset(self.pileup_iter) + * bam_mplp_reset(self.pileup_iter) */ } - /* "pysam/libcalignmentfile.pyx":2226 - * bam_plp_reset(self.pileup_iter) + /* "pysam/libcalignmentfile.pyx":2572 + * bam_mplp_reset(self.pileup_iter) * * cdef _free_pileup_iter(self): # <<<<<<<<<<<<<< * '''free the memory alloc'd by bam_plp_init. @@ -25700,8 +31165,8 @@ static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__free_pileu return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2238 - * self.pileup_iter = NULL +/* "pysam/libcalignmentfile.pyx":2583 + * self.pileup_iter = NULL * * def __dealloc__(self): # <<<<<<<<<<<<<< * # reset in order to avoid memory leak messages for iterators @@ -25725,20 +31190,20 @@ static void __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(st PyObject *__pyx_t_1 = NULL; int __pyx_t_2; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2238, 0, __PYX_ERR(0, 2238, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2583, 0, __PYX_ERR(0, 2583, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2241 + /* "pysam/libcalignmentfile.pyx":2586 * # reset in order to avoid memory leak messages for iterators * # that have not been fully consumed * self._free_pileup_iter() # <<<<<<<<<<<<<< * self.plp = NULL * */ - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->_free_pileup_iter(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2241, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->_free_pileup_iter(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2586, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":2242 + /* "pysam/libcalignmentfile.pyx":2587 * # that have not been fully consumed * self._free_pileup_iter() * self.plp = NULL # <<<<<<<<<<<<<< @@ -25747,7 +31212,7 @@ static void __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(st */ __pyx_v_self->plp = ((bam_pileup1_t *)NULL); - /* "pysam/libcalignmentfile.pyx":2244 + /* "pysam/libcalignmentfile.pyx":2589 * self.plp = NULL * * if self.iterdata.seq != NULL: # <<<<<<<<<<<<<< @@ -25757,7 +31222,7 @@ static void __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(st __pyx_t_2 = ((__pyx_v_self->iterdata.seq != NULL) != 0); if (__pyx_t_2) { - /* "pysam/libcalignmentfile.pyx":2245 + /* "pysam/libcalignmentfile.pyx":2590 * * if self.iterdata.seq != NULL: * free(self.iterdata.seq) # <<<<<<<<<<<<<< @@ -25766,16 +31231,16 @@ static void __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(st */ free(__pyx_v_self->iterdata.seq); - /* "pysam/libcalignmentfile.pyx":2246 + /* "pysam/libcalignmentfile.pyx":2591 * if self.iterdata.seq != NULL: * free(self.iterdata.seq) * self.iterdata.seq = NULL # <<<<<<<<<<<<<< * - * + * # backwards compatibility */ __pyx_v_self->iterdata.seq = NULL; - /* "pysam/libcalignmentfile.pyx":2244 + /* "pysam/libcalignmentfile.pyx":2589 * self.plp = NULL * * if self.iterdata.seq != NULL: # <<<<<<<<<<<<<< @@ -25784,8 +31249,8 @@ static void __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(st */ } - /* "pysam/libcalignmentfile.pyx":2238 - * self.pileup_iter = NULL + /* "pysam/libcalignmentfile.pyx":2583 + * self.pileup_iter = NULL * * def __dealloc__(self): # <<<<<<<<<<<<<< * # reset in order to avoid memory leak messages for iterators @@ -25802,6 +31267,253 @@ static void __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(st __Pyx_RefNannyFinishContext(); } +/* "pysam/libcalignmentfile.pyx":2595 + * # backwards compatibility + * + * def hasReference(self): # <<<<<<<<<<<<<< + * return self.has_reference() + * cdef char * getSequence(self): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference[] = "IteratorColumn.hasReference(self)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("hasReference (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("hasReference", 0); + __Pyx_TraceCall("hasReference", __pyx_f[0], 2595, 0, __PYX_ERR(0, 2595, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":2596 + * + * def hasReference(self): + * return self.has_reference() # <<<<<<<<<<<<<< + * cdef char * getSequence(self): + * return self.get_sequence() + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_reference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2596, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2596, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2596, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":2595 + * # backwards compatibility + * + * def hasReference(self): # <<<<<<<<<<<<<< + * return self.has_reference() + * cdef char * getSequence(self): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.hasReference", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":2597 + * def hasReference(self): + * return self.has_reference() + * cdef char * getSequence(self): # <<<<<<<<<<<<<< + * return self.get_sequence() + * def addReference(self, FastaFile fastafile): + */ + +static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) { + char *__pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSequence", 0); + __Pyx_TraceCall("getSequence", __pyx_f[0], 2597, 0, __PYX_ERR(0, 2597, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":2598 + * return self.has_reference() + * cdef char * getSequence(self): + * return self.get_sequence() # <<<<<<<<<<<<<< + * def addReference(self, FastaFile fastafile): + * return self.add_reference(fastafile) + */ + __pyx_r = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->get_sequence(__pyx_v_self); + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":2597 + * def hasReference(self): + * return self.has_reference() + * cdef char * getSequence(self): # <<<<<<<<<<<<<< + * return self.get_sequence() + * def addReference(self, FastaFile fastafile): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorColumn.getSequence", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcalignmentfile.pyx":2599 + * cdef char * getSequence(self): + * return self.get_sequence() + * def addReference(self, FastaFile fastafile): # <<<<<<<<<<<<<< + * return self.add_reference(fastafile) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_12addReference[] = "IteratorColumn.addReference(self, FastaFile fastafile)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("addReference (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fastafile), __pyx_ptype_5pysam_9libcfaidx_FastaFile, 1, "fastafile", 0))) __PYX_ERR(0, 2599, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12addReference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), ((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)__pyx_v_fastafile)); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12addReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("addReference", 0); + __Pyx_TraceCall("addReference", __pyx_f[0], 2599, 0, __PYX_ERR(0, 2599, __pyx_L1_error)); + + /* "pysam/libcalignmentfile.pyx":2600 + * return self.get_sequence() + * def addReference(self, FastaFile fastafile): + * return self.add_reference(fastafile) # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_reference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2600, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_fastafile)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2600, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_fastafile)}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2600, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_fastafile)}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2600, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2600, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(((PyObject *)__pyx_v_fastafile)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fastafile)); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_fastafile)); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2600, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcalignmentfile.pyx":2599 + * cdef char * getSequence(self): + * return self.get_sequence() + * def addReference(self, FastaFile fastafile): # <<<<<<<<<<<<<< + * return self.add_reference(fastafile) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.addReference", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * raise TypeError("no default __reduce__ due to non-trivial __cinit__") @@ -25809,20 +31521,20 @@ static void __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(st */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_10__reduce_cython__[] = "IteratorColumn.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_15__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__[] = "IteratorColumn.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_15__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -25836,7 +31548,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10__reduce * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__69, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__83, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -25867,20 +31579,20 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10__reduce */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_12__setstate_cython__[] = "IteratorColumn.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_17__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__[] = "IteratorColumn.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_17__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -25893,7 +31605,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12__setsta * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__70, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__84, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -25917,12 +31629,12 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12__setsta return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2252 +/* "pysam/libcalignmentfile.pyx":2606 * '''iterates over a region only. * ''' - * def __cinit__(self, AlignmentFile samfile, # <<<<<<<<<<<<<< + * def __cinit__(self, # <<<<<<<<<<<<<< + * AlignmentFile samfile, * int tid = 0, - * int start = 0, */ /* Python wrapper */ @@ -25931,7 +31643,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__ CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0; int __pyx_v_tid; int __pyx_v_start; - int __pyx_v_end; + int __pyx_v_stop; int __pyx_v_truncate; CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0; int __pyx_r; @@ -25940,7 +31652,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__ __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1; __Pyx_GOTREF(__pyx_v_kwargs); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_tid,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_truncate,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_tid,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_truncate,0}; PyObject* values[5] = {0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; @@ -25979,7 +31691,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__ CYTHON_FALLTHROUGH; case 3: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop); if (value) { values[3] = value; kw_args--; } } CYTHON_FALLTHROUGH; @@ -25990,7 +31702,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__ } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 2252, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 2606, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -26009,27 +31721,27 @@ static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__ } __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]); if (values[1]) { - __pyx_v_tid = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2253, __pyx_L3_error) + __pyx_v_tid = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2608, __pyx_L3_error) } else { __pyx_v_tid = ((int)0); } if (values[2]) { - __pyx_v_start = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2254, __pyx_L3_error) + __pyx_v_start = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2609, __pyx_L3_error) } else { __pyx_v_start = ((int)0); } if (values[3]) { - __pyx_v_end = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2255, __pyx_L3_error) + __pyx_v_stop = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_stop == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2610, __pyx_L3_error) } else { - __pyx_v_end = __pyx_k__71; + __pyx_v_stop = __pyx_k__85; } if (values[4]) { - __pyx_v_truncate = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_truncate == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2256, __pyx_L3_error) + __pyx_v_truncate = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_truncate == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2611, __pyx_L3_error) } else { - /* "pysam/libcalignmentfile.pyx":2256 + /* "pysam/libcalignmentfile.pyx":2611 * int start = 0, - * int end = MAX_POS, + * int stop = MAX_POS, * int truncate = False, # <<<<<<<<<<<<<< * **kwargs ): * @@ -26039,22 +31751,22 @@ static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__ } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2252, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2606, __pyx_L3_error) __pyx_L3_error:; __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnRegion.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2252, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_start, __pyx_v_end, __pyx_v_truncate, __pyx_v_kwargs); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2607, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_start, __pyx_v_stop, __pyx_v_truncate, __pyx_v_kwargs); - /* "pysam/libcalignmentfile.pyx":2252 + /* "pysam/libcalignmentfile.pyx":2606 * '''iterates over a region only. * ''' - * def __cinit__(self, AlignmentFile samfile, # <<<<<<<<<<<<<< + * def __cinit__(self, # <<<<<<<<<<<<<< + * AlignmentFile samfile, * int tid = 0, - * int start = 0, */ /* function exit code */ @@ -26067,61 +31779,61 @@ static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__ return __pyx_r; } -static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, int __pyx_v_truncate, CYTHON_UNUSED PyObject *__pyx_v_kwargs) { +static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_stop, int __pyx_v_truncate, CYTHON_UNUSED PyObject *__pyx_v_kwargs) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData __pyx_t_2; + struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator __pyx_t_2; __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[0], 2252, 0, __PYX_ERR(0, 2252, __pyx_L1_error)); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 2606, 0, __PYX_ERR(0, 2606, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2260 + /* "pysam/libcalignmentfile.pyx":2615 * * # initialize iterator - * self.setupIteratorData(tid, start, end, 1) # <<<<<<<<<<<<<< + * self._setup_iterator(tid, start, stop, 1) # <<<<<<<<<<<<<< * self.start = start - * self.end = end + * self.stop = stop */ __pyx_t_2.__pyx_n = 1; __pyx_t_2.multiple_iterators = 1; - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_tid, __pyx_v_start, __pyx_v_end, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2260, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._setup_iterator(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_tid, __pyx_v_start, __pyx_v_stop, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2615, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":2261 + /* "pysam/libcalignmentfile.pyx":2616 * # initialize iterator - * self.setupIteratorData(tid, start, end, 1) + * self._setup_iterator(tid, start, stop, 1) * self.start = start # <<<<<<<<<<<<<< - * self.end = end + * self.stop = stop * self.truncate = truncate */ __pyx_v_self->start = __pyx_v_start; - /* "pysam/libcalignmentfile.pyx":2262 - * self.setupIteratorData(tid, start, end, 1) + /* "pysam/libcalignmentfile.pyx":2617 + * self._setup_iterator(tid, start, stop, 1) * self.start = start - * self.end = end # <<<<<<<<<<<<<< + * self.stop = stop # <<<<<<<<<<<<<< * self.truncate = truncate * */ - __pyx_v_self->end = __pyx_v_end; + __pyx_v_self->stop = __pyx_v_stop; - /* "pysam/libcalignmentfile.pyx":2263 + /* "pysam/libcalignmentfile.pyx":2618 * self.start = start - * self.end = end + * self.stop = stop * self.truncate = truncate # <<<<<<<<<<<<<< * * def __next__(self): */ __pyx_v_self->truncate = __pyx_v_truncate; - /* "pysam/libcalignmentfile.pyx":2252 + /* "pysam/libcalignmentfile.pyx":2606 * '''iterates over a region only. * ''' - * def __cinit__(self, AlignmentFile samfile, # <<<<<<<<<<<<<< + * def __cinit__(self, # <<<<<<<<<<<<<< + * AlignmentFile samfile, * int tid = 0, - * int start = 0, */ /* function exit code */ @@ -26137,12 +31849,12 @@ static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion___cinit__( return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2265 +/* "pysam/libcalignmentfile.pyx":2620 * self.truncate = truncate * * def __next__(self): # <<<<<<<<<<<<<< * - * while 1: + * cdef int n */ /* Python wrapper */ @@ -26159,6 +31871,7 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__n } static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self) { + int __pyx_v_n; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -26166,158 +31879,190 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_2__n PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 2265, 0, __PYX_ERR(0, 2265, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 2620, 0, __PYX_ERR(0, 2620, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2267 - * def __next__(self): + /* "pysam/libcalignmentfile.pyx":2624 + * cdef int n * * while 1: # <<<<<<<<<<<<<< - * self.cnext() - * if self.n_plp < 0: + * n = self.cnext() + * if n < 0: */ while (1) { - /* "pysam/libcalignmentfile.pyx":2268 + /* "pysam/libcalignmentfile.pyx":2625 * * while 1: - * self.cnext() # <<<<<<<<<<<<<< - * if self.n_plp < 0: + * n = self.cnext() # <<<<<<<<<<<<<< + * if n < 0: * raise ValueError("error during iteration" ) */ - (void)(((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self))); + __pyx_v_n = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self)); - /* "pysam/libcalignmentfile.pyx":2269 + /* "pysam/libcalignmentfile.pyx":2626 * while 1: - * self.cnext() - * if self.n_plp < 0: # <<<<<<<<<<<<<< + * n = self.cnext() + * if n < 0: # <<<<<<<<<<<<<< * raise ValueError("error during iteration" ) * */ - __pyx_t_1 = ((__pyx_v_self->__pyx_base.n_plp < 0) != 0); + __pyx_t_1 = ((__pyx_v_n < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":2270 - * self.cnext() - * if self.n_plp < 0: + /* "pysam/libcalignmentfile.pyx":2627 + * n = self.cnext() + * if n < 0: * raise ValueError("error during iteration" ) # <<<<<<<<<<<<<< * - * if self.plp == NULL: + * if n == 0: */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__72, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2270, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__86, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2627, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 2270, __pyx_L1_error) + __PYX_ERR(0, 2627, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":2269 + /* "pysam/libcalignmentfile.pyx":2626 * while 1: - * self.cnext() - * if self.n_plp < 0: # <<<<<<<<<<<<<< + * n = self.cnext() + * if n < 0: # <<<<<<<<<<<<<< * raise ValueError("error during iteration" ) * */ } - /* "pysam/libcalignmentfile.pyx":2272 + /* "pysam/libcalignmentfile.pyx":2629 * raise ValueError("error during iteration" ) * - * if self.plp == NULL: # <<<<<<<<<<<<<< + * if n == 0: # <<<<<<<<<<<<<< * raise StopIteration * */ - __pyx_t_1 = ((__pyx_v_self->__pyx_base.plp == NULL) != 0); + __pyx_t_1 = ((__pyx_v_n == 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":2273 + /* "pysam/libcalignmentfile.pyx":2630 * - * if self.plp == NULL: + * if n == 0: * raise StopIteration # <<<<<<<<<<<<<< * * if self.truncate: */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 2273, __pyx_L1_error) + __PYX_ERR(0, 2630, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":2272 + /* "pysam/libcalignmentfile.pyx":2629 * raise ValueError("error during iteration" ) * - * if self.plp == NULL: # <<<<<<<<<<<<<< + * if n == 0: # <<<<<<<<<<<<<< * raise StopIteration * */ } - /* "pysam/libcalignmentfile.pyx":2275 + /* "pysam/libcalignmentfile.pyx":2632 * raise StopIteration * * if self.truncate: # <<<<<<<<<<<<<< - * if self.start > self.pos: continue - * if self.pos >= self.end: raise StopIteration + * if self.start > self.pos: + * continue */ __pyx_t_1 = (__pyx_v_self->truncate != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2276 + /* "pysam/libcalignmentfile.pyx":2633 * * if self.truncate: - * if self.start > self.pos: continue # <<<<<<<<<<<<<< - * if self.pos >= self.end: raise StopIteration - * + * if self.start > self.pos: # <<<<<<<<<<<<<< + * continue + * if self.pos >= self.stop: */ __pyx_t_1 = ((__pyx_v_self->start > __pyx_v_self->__pyx_base.pos) != 0); if (__pyx_t_1) { + + /* "pysam/libcalignmentfile.pyx":2634 + * if self.truncate: + * if self.start > self.pos: + * continue # <<<<<<<<<<<<<< + * if self.pos >= self.stop: + * raise StopIteration + */ goto __pyx_L3_continue; - } - /* "pysam/libcalignmentfile.pyx":2277 + /* "pysam/libcalignmentfile.pyx":2633 + * * if self.truncate: - * if self.start > self.pos: continue - * if self.pos >= self.end: raise StopIteration # <<<<<<<<<<<<<< + * if self.start > self.pos: # <<<<<<<<<<<<<< + * continue + * if self.pos >= self.stop: + */ + } + + /* "pysam/libcalignmentfile.pyx":2635 + * if self.start > self.pos: + * continue + * if self.pos >= self.stop: # <<<<<<<<<<<<<< + * raise StopIteration * - * return makePileupColumn(&self.plp, */ - __pyx_t_1 = ((__pyx_v_self->__pyx_base.pos >= __pyx_v_self->end) != 0); + __pyx_t_1 = ((__pyx_v_self->__pyx_base.pos >= __pyx_v_self->stop) != 0); if (unlikely(__pyx_t_1)) { + + /* "pysam/libcalignmentfile.pyx":2636 + * continue + * if self.pos >= self.stop: + * raise StopIteration # <<<<<<<<<<<<<< + * + * return makePileupColumn(&self.plp, + */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 2277, __pyx_L1_error) + __PYX_ERR(0, 2636, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":2635 + * if self.start > self.pos: + * continue + * if self.pos >= self.stop: # <<<<<<<<<<<<<< + * raise StopIteration + * + */ } - /* "pysam/libcalignmentfile.pyx":2275 + /* "pysam/libcalignmentfile.pyx":2632 * raise StopIteration * * if self.truncate: # <<<<<<<<<<<<<< - * if self.start > self.pos: continue - * if self.pos >= self.end: raise StopIteration + * if self.start > self.pos: + * continue */ } - /* "pysam/libcalignmentfile.pyx":2279 - * if self.pos >= self.end: raise StopIteration + /* "pysam/libcalignmentfile.pyx":2638 + * raise StopIteration * * return makePileupColumn(&self.plp, # <<<<<<<<<<<<<< - * self.tid, - * self.pos, + * self.tid, + * self.pos, */ __Pyx_XDECREF(__pyx_r); - /* "pysam/libcalignmentfile.pyx":2283 - * self.pos, - * self.n_plp, - * self.samfile) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2644 + * self.min_base_quality, + * self.iterdata.seq, + * self.samfile.header) # <<<<<<<<<<<<<< * * */ - __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.samfile); + __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.samfile->header); __Pyx_INCREF(__pyx_t_2); - /* "pysam/libcalignmentfile.pyx":2279 - * if self.pos >= self.end: raise StopIteration + /* "pysam/libcalignmentfile.pyx":2638 + * raise StopIteration * * return makePileupColumn(&self.plp, # <<<<<<<<<<<<<< - * self.tid, - * self.pos, + * self.tid, + * self.pos, */ - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_makePileupColumn((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2279, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makePileupColumn((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp, __pyx_v_self->__pyx_base.min_base_quality, __pyx_v_self->__pyx_base.iterdata.seq, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2638, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; @@ -26326,12 +32071,12 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_2__n __pyx_L3_continue:; } - /* "pysam/libcalignmentfile.pyx":2265 + /* "pysam/libcalignmentfile.pyx":2620 * self.truncate = truncate * * def __next__(self): # <<<<<<<<<<<<<< * - * while 1: + * cdef int n */ /* function exit code */ @@ -26383,7 +32128,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__r * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__73, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__87, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -26440,7 +32185,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__s * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__74, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__88, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -26464,7 +32209,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__s return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2290 +/* "pysam/libcalignmentfile.pyx":2651 * """ * * def __cinit__(self, # <<<<<<<<<<<<<< @@ -26501,7 +32246,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_1__cinit_ else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 2290, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 2651, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -26512,14 +32257,14 @@ static int __pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_1__cinit_ } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2290, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2651, __pyx_L3_error) __pyx_L3_error:; __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2291, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2652, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self), __pyx_v_samfile, __pyx_v_kwargs); /* function exit code */ @@ -26539,25 +32284,25 @@ static int __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs___cinit__ PyObject *__pyx_t_1 = NULL; int __pyx_t_2; int __pyx_t_3; - struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData __pyx_t_4; + struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator __pyx_t_4; __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[0], 2290, 0, __PYX_ERR(0, 2290, __pyx_L1_error)); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 2651, 0, __PYX_ERR(0, 2651, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2295 + /* "pysam/libcalignmentfile.pyx":2656 * * # no iteration over empty files * if not samfile.nreferences: # <<<<<<<<<<<<<< * raise StopIteration * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2295, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2656, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2295, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2656, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = ((!__pyx_t_2) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcalignmentfile.pyx":2296 + /* "pysam/libcalignmentfile.pyx":2657 * # no iteration over empty files * if not samfile.nreferences: * raise StopIteration # <<<<<<<<<<<<<< @@ -26565,9 +32310,9 @@ static int __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs___cinit__ * # initialize iterator */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 2296, __pyx_L1_error) + __PYX_ERR(0, 2657, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":2295 + /* "pysam/libcalignmentfile.pyx":2656 * * # no iteration over empty files * if not samfile.nreferences: # <<<<<<<<<<<<<< @@ -26576,20 +32321,20 @@ static int __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs___cinit__ */ } - /* "pysam/libcalignmentfile.pyx":2299 + /* "pysam/libcalignmentfile.pyx":2660 * * # initialize iterator - * self.setupIteratorData(self.tid, 0, MAX_POS, 1) # <<<<<<<<<<<<<< + * self._setup_iterator(self.tid, 0, MAX_POS, 1) # <<<<<<<<<<<<<< * * def __next__(self): */ __pyx_t_4.__pyx_n = 1; __pyx_t_4.multiple_iterators = 1; - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_17libcalignmentfile_MAX_POS, &__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2299, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._setup_iterator(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_17libcalignmentfile_MAX_POS, &__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2660, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":2290 + /* "pysam/libcalignmentfile.pyx":2651 * """ * * def __cinit__(self, # <<<<<<<<<<<<<< @@ -26610,12 +32355,12 @@ static int __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs___cinit__ return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2301 - * self.setupIteratorData(self.tid, 0, MAX_POS, 1) +/* "pysam/libcalignmentfile.pyx":2662 + * self._setup_iterator(self.tid, 0, MAX_POS, 1) * * def __next__(self): # <<<<<<<<<<<<<< * - * while 1: + * cdef int n */ /* Python wrapper */ @@ -26632,6 +32377,7 @@ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__ } static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self) { + int __pyx_v_n; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -26639,182 +32385,192 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_2__ PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData __pyx_t_5; + struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator __pyx_t_5; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 2301, 0, __PYX_ERR(0, 2301, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 2662, 0, __PYX_ERR(0, 2662, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2303 - * def __next__(self): + /* "pysam/libcalignmentfile.pyx":2665 * + * cdef int n * while 1: # <<<<<<<<<<<<<< - * self.cnext() - * + * n = self.cnext() + * if n < 0: */ while (1) { - /* "pysam/libcalignmentfile.pyx":2304 - * + /* "pysam/libcalignmentfile.pyx":2666 + * cdef int n * while 1: - * self.cnext() # <<<<<<<<<<<<<< - * - * if self.n_plp < 0: + * n = self.cnext() # <<<<<<<<<<<<<< + * if n < 0: + * raise ValueError("error during iteration") */ - (void)(((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self))); + __pyx_v_n = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self)); - /* "pysam/libcalignmentfile.pyx":2306 - * self.cnext() - * - * if self.n_plp < 0: # <<<<<<<<<<<<<< - * raise ValueError("error during iteration" ) + /* "pysam/libcalignmentfile.pyx":2667 + * while 1: + * n = self.cnext() + * if n < 0: # <<<<<<<<<<<<<< + * raise ValueError("error during iteration") * */ - __pyx_t_1 = ((__pyx_v_self->__pyx_base.n_plp < 0) != 0); + __pyx_t_1 = ((__pyx_v_n < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":2307 - * - * if self.n_plp < 0: - * raise ValueError("error during iteration" ) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2668 + * n = self.cnext() + * if n < 0: + * raise ValueError("error during iteration") # <<<<<<<<<<<<<< * - * # return result, if within same reference + * # proceed to next reference or stop */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2307, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__89, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2668, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 2307, __pyx_L1_error) + __PYX_ERR(0, 2668, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":2306 - * self.cnext() - * - * if self.n_plp < 0: # <<<<<<<<<<<<<< - * raise ValueError("error during iteration" ) + /* "pysam/libcalignmentfile.pyx":2667 + * while 1: + * n = self.cnext() + * if n < 0: # <<<<<<<<<<<<<< + * raise ValueError("error during iteration") * */ } - /* "pysam/libcalignmentfile.pyx":2310 + /* "pysam/libcalignmentfile.pyx":2671 * - * # return result, if within same reference - * if self.plp != NULL: # <<<<<<<<<<<<<< - * return makePileupColumn(&self.plp, - * self.tid, + * # proceed to next reference or stop + * if n == 0: # <<<<<<<<<<<<<< + * self.tid += 1 + * if self.tid < self.samfile.nreferences: */ - __pyx_t_1 = ((__pyx_v_self->__pyx_base.plp != NULL) != 0); + __pyx_t_1 = ((__pyx_v_n == 0) != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2311 - * # return result, if within same reference - * if self.plp != NULL: - * return makePileupColumn(&self.plp, # <<<<<<<<<<<<<< - * self.tid, - * self.pos, - */ - __Pyx_XDECREF(__pyx_r); - - /* "pysam/libcalignmentfile.pyx":2315 - * self.pos, - * self.n_plp, - * self.samfile) # <<<<<<<<<<<<<< - * - * # otherwise, proceed to next reference or stop + /* "pysam/libcalignmentfile.pyx":2672 + * # proceed to next reference or stop + * if n == 0: + * self.tid += 1 # <<<<<<<<<<<<<< + * if self.tid < self.samfile.nreferences: + * self._setup_iterator(self.tid, 0, MAX_POS, 0) */ - __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.samfile); - __Pyx_INCREF(__pyx_t_2); + __pyx_v_self->__pyx_base.tid = (__pyx_v_self->__pyx_base.tid + 1); - /* "pysam/libcalignmentfile.pyx":2311 - * # return result, if within same reference - * if self.plp != NULL: - * return makePileupColumn(&self.plp, # <<<<<<<<<<<<<< - * self.tid, - * self.pos, + /* "pysam/libcalignmentfile.pyx":2673 + * if n == 0: + * self.tid += 1 + * if self.tid < self.samfile.nreferences: # <<<<<<<<<<<<<< + * self._setup_iterator(self.tid, 0, MAX_POS, 0) + * else: */ - __pyx_t_3 = __pyx_f_5pysam_18libcalignedsegment_makePileupColumn((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2311, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->__pyx_base.tid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2673, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2673, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2673, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (likely(__pyx_t_1)) { - /* "pysam/libcalignmentfile.pyx":2310 - * - * # return result, if within same reference - * if self.plp != NULL: # <<<<<<<<<<<<<< - * return makePileupColumn(&self.plp, - * self.tid, + /* "pysam/libcalignmentfile.pyx":2674 + * self.tid += 1 + * if self.tid < self.samfile.nreferences: + * self._setup_iterator(self.tid, 0, MAX_POS, 0) # <<<<<<<<<<<<<< + * else: + * raise StopIteration */ - } + __pyx_t_5.__pyx_n = 1; + __pyx_t_5.multiple_iterators = 0; + __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._setup_iterator(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_17libcalignmentfile_MAX_POS, &__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":2318 - * - * # otherwise, proceed to next reference or stop - * self.tid += 1 # <<<<<<<<<<<<<< - * if self.tid < self.samfile.nreferences: - * self.setupIteratorData(self.tid, 0, MAX_POS, 0) + /* "pysam/libcalignmentfile.pyx":2673 + * if n == 0: + * self.tid += 1 + * if self.tid < self.samfile.nreferences: # <<<<<<<<<<<<<< + * self._setup_iterator(self.tid, 0, MAX_POS, 0) + * else: */ - __pyx_v_self->__pyx_base.tid = (__pyx_v_self->__pyx_base.tid + 1); + goto __pyx_L7; + } - /* "pysam/libcalignmentfile.pyx":2319 - * # otherwise, proceed to next reference or stop - * self.tid += 1 - * if self.tid < self.samfile.nreferences: # <<<<<<<<<<<<<< - * self.setupIteratorData(self.tid, 0, MAX_POS, 0) - * else: + /* "pysam/libcalignmentfile.pyx":2676 + * self._setup_iterator(self.tid, 0, MAX_POS, 0) + * else: + * raise StopIteration # <<<<<<<<<<<<<< + * continue + * */ - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->__pyx_base.tid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2319, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2319, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2319, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2319, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (likely(__pyx_t_1)) { + /*else*/ { + __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); + __PYX_ERR(0, 2676, __pyx_L1_error) + } + __pyx_L7:; - /* "pysam/libcalignmentfile.pyx":2320 - * self.tid += 1 - * if self.tid < self.samfile.nreferences: - * self.setupIteratorData(self.tid, 0, MAX_POS, 0) # <<<<<<<<<<<<<< - * else: - * raise StopIteration + /* "pysam/libcalignmentfile.pyx":2677 + * else: + * raise StopIteration + * continue # <<<<<<<<<<<<<< + * + * # return result, if within same reference */ - __pyx_t_5.__pyx_n = 1; - __pyx_t_5.multiple_iterators = 0; - __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_17libcalignmentfile_MAX_POS, &__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2320, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L3_continue; - /* "pysam/libcalignmentfile.pyx":2319 - * # otherwise, proceed to next reference or stop - * self.tid += 1 - * if self.tid < self.samfile.nreferences: # <<<<<<<<<<<<<< - * self.setupIteratorData(self.tid, 0, MAX_POS, 0) - * else: + /* "pysam/libcalignmentfile.pyx":2671 + * + * # proceed to next reference or stop + * if n == 0: # <<<<<<<<<<<<<< + * self.tid += 1 + * if self.tid < self.samfile.nreferences: */ - goto __pyx_L7; } - /* "pysam/libcalignmentfile.pyx":2322 - * self.setupIteratorData(self.tid, 0, MAX_POS, 0) - * else: - * raise StopIteration # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2680 + * + * # return result, if within same reference + * return makePileupColumn(&self.plp, # <<<<<<<<<<<<<< + * self.tid, + * self.pos, + */ + __Pyx_XDECREF(__pyx_r); + + /* "pysam/libcalignmentfile.pyx":2686 + * self.min_base_quality, + * self.iterdata.seq, + * self.samfile.header) # <<<<<<<<<<<<<< * * */ - /*else*/ { - __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 2322, __pyx_L1_error) - } - __pyx_L7:; + __pyx_t_4 = ((PyObject *)__pyx_v_self->__pyx_base.samfile->header); + __Pyx_INCREF(__pyx_t_4); + + /* "pysam/libcalignmentfile.pyx":2680 + * + * # return result, if within same reference + * return makePileupColumn(&self.plp, # <<<<<<<<<<<<<< + * self.tid, + * self.pos, + */ + __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makePileupColumn((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp, __pyx_v_self->__pyx_base.min_base_quality, __pyx_v_self->__pyx_base.iterdata.seq, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_4))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2680, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + __pyx_L3_continue:; } - /* "pysam/libcalignmentfile.pyx":2301 - * self.setupIteratorData(self.tid, 0, MAX_POS, 1) + /* "pysam/libcalignmentfile.pyx":2662 + * self._setup_iterator(self.tid, 0, MAX_POS, 1) * * def __next__(self): # <<<<<<<<<<<<<< * - * while 1: + * cdef int n */ /* function exit code */ @@ -26867,7 +32623,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_4__ * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__76, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__90, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -26924,7 +32680,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__ * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__77, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__91, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -26948,7 +32704,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__ return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2338 +/* "pysam/libcalignmentfile.pyx":2702 * property tid: * '''the chromosome ID as is defined in the header''' * def __get__(self): # <<<<<<<<<<<<<< @@ -26975,9 +32731,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3tid___get__(struc __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2338, 0, __PYX_ERR(0, 2338, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2702, 0, __PYX_ERR(0, 2702, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2339 + /* "pysam/libcalignmentfile.pyx":2703 * '''the chromosome ID as is defined in the header''' * def __get__(self): * return self._tid # <<<<<<<<<<<<<< @@ -26985,13 +32741,13 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3tid___get__(struc * property pos: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2339, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2703, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":2338 + /* "pysam/libcalignmentfile.pyx":2702 * property tid: * '''the chromosome ID as is defined in the header''' * def __get__(self): # <<<<<<<<<<<<<< @@ -27011,7 +32767,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3tid___get__(struc return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2343 +/* "pysam/libcalignmentfile.pyx":2707 * property pos: * '''nucleotide position of SNP.''' * def __get__(self): return self._pos # <<<<<<<<<<<<<< @@ -27038,9 +32794,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3pos___get__(struc __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2343, 0, __PYX_ERR(0, 2343, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2707, 0, __PYX_ERR(0, 2707, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2343, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2707, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -27058,7 +32814,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3pos___get__(struc return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2347 +/* "pysam/libcalignmentfile.pyx":2711 * property reference_base: * '''reference base at pos. ``N`` if no reference sequence supplied.''' * def __get__(self): return from_string_and_size( &self._reference_base, 1 ) # <<<<<<<<<<<<<< @@ -27085,9 +32841,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_14reference_base__ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2347, 0, __PYX_ERR(0, 2347, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2711, 0, __PYX_ERR(0, 2711, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_9libcutils_from_string_and_size((&__pyx_v_self->_reference_base), 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2347, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_from_string_and_size((&__pyx_v_self->_reference_base), 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2711, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -27105,7 +32861,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_14reference_base__ return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2351 +/* "pysam/libcalignmentfile.pyx":2715 * property genotype: * '''the genotype called.''' * def __get__(self): return from_string_and_size( &self._genotype, 1 ) # <<<<<<<<<<<<<< @@ -27132,9 +32888,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8genotype___get__( __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2351, 0, __PYX_ERR(0, 2351, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2715, 0, __PYX_ERR(0, 2715, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_9libcutils_from_string_and_size((&__pyx_v_self->_genotype), 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2351, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_from_string_and_size((&__pyx_v_self->_genotype), 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2715, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -27152,7 +32908,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8genotype___get__( return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2355 +/* "pysam/libcalignmentfile.pyx":2719 * property consensus_quality: * '''the genotype quality (Phred-scaled).''' * def __get__(self): return self._consensus_quality # <<<<<<<<<<<<<< @@ -27179,9 +32935,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_17consensus_qualit __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2355, 0, __PYX_ERR(0, 2355, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2719, 0, __PYX_ERR(0, 2719, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_consensus_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2355, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_consensus_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2719, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -27199,7 +32955,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_17consensus_qualit return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2360 +/* "pysam/libcalignmentfile.pyx":2724 * '''the snp quality (Phred scaled) - probability of consensus being * identical to reference sequence.''' * def __get__(self): return self._snp_quality # <<<<<<<<<<<<<< @@ -27226,9 +32982,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_11snp_quality___ge __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2360, 0, __PYX_ERR(0, 2360, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2724, 0, __PYX_ERR(0, 2724, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_snp_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2360, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_snp_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2724, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -27246,7 +33002,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_11snp_quality___ge return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2365 +/* "pysam/libcalignmentfile.pyx":2729 * '''the root mean square (rms) of the mapping quality of all reads * involved in the call.''' * def __get__(self): return self._rms_mapping_quality # <<<<<<<<<<<<<< @@ -27273,9 +33029,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_15mapping_quality_ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2365, 0, __PYX_ERR(0, 2365, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2729, 0, __PYX_ERR(0, 2729, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_rms_mapping_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2365, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_rms_mapping_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2729, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -27293,7 +33049,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_15mapping_quality_ return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2369 +/* "pysam/libcalignmentfile.pyx":2733 * property coverage: * '''coverage or read depth - the number of reads involved in the call.''' * def __get__(self): return self._coverage # <<<<<<<<<<<<<< @@ -27320,9 +33076,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8coverage___get__( __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2369, 0, __PYX_ERR(0, 2369, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2733, 0, __PYX_ERR(0, 2733, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_coverage); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2369, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_coverage); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2733, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -27340,7 +33096,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8coverage___get__( return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2371 +/* "pysam/libcalignmentfile.pyx":2735 * def __get__(self): return self._coverage * * def __str__(self): # <<<<<<<<<<<<<< @@ -27375,9 +33131,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall___str__(struct __p PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("__str__", 0); - __Pyx_TraceCall("__str__", __pyx_f[0], 2371, 0, __PYX_ERR(0, 2371, __pyx_L1_error)); + __Pyx_TraceCall("__str__", __pyx_f[0], 2735, 0, __PYX_ERR(0, 2735, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2373 + /* "pysam/libcalignmentfile.pyx":2737 * def __str__(self): * * return "\t".join( map(str, ( # <<<<<<<<<<<<<< @@ -27386,94 +33142,94 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall___str__(struct __p */ __Pyx_XDECREF(__pyx_r); - /* "pysam/libcalignmentfile.pyx":2374 + /* "pysam/libcalignmentfile.pyx":2738 * * return "\t".join( map(str, ( * self.tid, # <<<<<<<<<<<<<< * self.pos, * self.reference_base, */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2374, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2738, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libcalignmentfile.pyx":2375 + /* "pysam/libcalignmentfile.pyx":2739 * return "\t".join( map(str, ( * self.tid, * self.pos, # <<<<<<<<<<<<<< * self.reference_base, * self.genotype, */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_pos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2375, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_pos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2739, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - /* "pysam/libcalignmentfile.pyx":2376 + /* "pysam/libcalignmentfile.pyx":2740 * self.tid, * self.pos, * self.reference_base, # <<<<<<<<<<<<<< * self.genotype, * self.consensus_quality, */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2376, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2740, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - /* "pysam/libcalignmentfile.pyx":2377 + /* "pysam/libcalignmentfile.pyx":2741 * self.pos, * self.reference_base, * self.genotype, # <<<<<<<<<<<<<< * self.consensus_quality, * self.snp_quality, */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_genotype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2377, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_genotype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2741, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libcalignmentfile.pyx":2378 + /* "pysam/libcalignmentfile.pyx":2742 * self.reference_base, * self.genotype, * self.consensus_quality, # <<<<<<<<<<<<<< * self.snp_quality, * self.mapping_quality, */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_consensus_quality); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2378, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_consensus_quality); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2742, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - /* "pysam/libcalignmentfile.pyx":2379 + /* "pysam/libcalignmentfile.pyx":2743 * self.genotype, * self.consensus_quality, * self.snp_quality, # <<<<<<<<<<<<<< * self.mapping_quality, * self.coverage ) ) ) */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_snp_quality); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2379, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_snp_quality); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2743, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - /* "pysam/libcalignmentfile.pyx":2380 + /* "pysam/libcalignmentfile.pyx":2744 * self.consensus_quality, * self.snp_quality, * self.mapping_quality, # <<<<<<<<<<<<<< * self.coverage ) ) ) * */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2380, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2744, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcalignmentfile.pyx":2381 + /* "pysam/libcalignmentfile.pyx":2745 * self.snp_quality, * self.mapping_quality, * self.coverage ) ) ) # <<<<<<<<<<<<<< * * */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_coverage); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2381, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_coverage); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2745, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); - /* "pysam/libcalignmentfile.pyx":2374 + /* "pysam/libcalignmentfile.pyx":2738 * * return "\t".join( map(str, ( * self.tid, # <<<<<<<<<<<<<< * self.pos, * self.reference_base, */ - __pyx_t_9 = PyTuple_New(8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2374, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2738, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); @@ -27500,14 +33256,14 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall___str__(struct __p __pyx_t_7 = 0; __pyx_t_8 = 0; - /* "pysam/libcalignmentfile.pyx":2373 + /* "pysam/libcalignmentfile.pyx":2737 * def __str__(self): * * return "\t".join( map(str, ( # <<<<<<<<<<<<<< * self.tid, * self.pos, */ - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2373, __pyx_L1_error) + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2737, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); @@ -27515,17 +33271,17 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall___str__(struct __p __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2373, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2737, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2373, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2737, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_r = __pyx_t_8; __pyx_t_8 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":2371 + /* "pysam/libcalignmentfile.pyx":2735 * def __get__(self): return self._coverage * * def __str__(self): # <<<<<<<<<<<<<< @@ -27896,7 +33652,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_4__setstate_cython return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2408 +/* "pysam/libcalignmentfile.pyx":2772 * """ * * def __init__(self, AlignmentFile samfile, int multiple_iterators=True): # <<<<<<<<<<<<<< @@ -27939,7 +33695,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_1__init__(PyObject } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 2408, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 2772, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -27952,20 +33708,20 @@ static int __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_1__init__(PyObject } __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]); if (values[1]) { - __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2408, __pyx_L3_error) + __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2772, __pyx_L3_error) } else { __pyx_v_multiple_iterators = ((int)1); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2408, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2772, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcalignmentfile.IndexedReads.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2408, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2772, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators); /* function exit code */ @@ -27979,6 +33735,7 @@ static int __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_1__init__(PyObject static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators) { char *__pyx_v_cfilename; + bam_hdr_t *__pyx_v_hdr; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -27986,16 +33743,15 @@ static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __ int __pyx_t_2; char *__pyx_t_3; htsFile *__pyx_t_4; - bam_hdr_t *__pyx_t_5; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 2408, 0, __PYX_ERR(0, 2408, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 2772, 0, __PYX_ERR(0, 2772, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2413 + /* "pysam/libcalignmentfile.pyx":2777 * # makes sure that samfile stays alive as long as this * # object is alive. * self.samfile = samfile # <<<<<<<<<<<<<< - * - * assert samfile.is_bam, "can only IndexReads on bam files" + * cdef bam_hdr_t * hdr = NULL + * assert samfile.is_bam, "can only apply IndexReads on bam files" */ __Pyx_INCREF(((PyObject *)__pyx_v_samfile)); __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile)); @@ -28003,27 +33759,36 @@ static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __ __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile)); __pyx_v_self->samfile = __pyx_v_samfile; - /* "pysam/libcalignmentfile.pyx":2415 + /* "pysam/libcalignmentfile.pyx":2778 + * # object is alive. * self.samfile = samfile + * cdef bam_hdr_t * hdr = NULL # <<<<<<<<<<<<<< + * assert samfile.is_bam, "can only apply IndexReads on bam files" * - * assert samfile.is_bam, "can only IndexReads on bam files" # <<<<<<<<<<<<<< + */ + __pyx_v_hdr = NULL; + + /* "pysam/libcalignmentfile.pyx":2779 + * self.samfile = samfile + * cdef bam_hdr_t * hdr = NULL + * assert samfile.is_bam, "can only apply IndexReads on bam files" # <<<<<<<<<<<<<< * * # multiple_iterators the file - note that this makes the iterator */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2415, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2779, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2415, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2779, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_2)) { - PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_can_only_IndexReads_on_bam_files); - __PYX_ERR(0, 2415, __pyx_L1_error) + PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_can_only_apply_IndexReads_on_bam); + __PYX_ERR(0, 2779, __pyx_L1_error) } } #endif - /* "pysam/libcalignmentfile.pyx":2419 + /* "pysam/libcalignmentfile.pyx":2783 * # multiple_iterators the file - note that this makes the iterator * # slow and causes pileup to slow down significantly. * if multiple_iterators: # <<<<<<<<<<<<<< @@ -28033,22 +33798,22 @@ static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __ __pyx_t_2 = (__pyx_v_multiple_iterators != 0); if (__pyx_t_2) { - /* "pysam/libcalignmentfile.pyx":2420 + /* "pysam/libcalignmentfile.pyx":2784 * # slow and causes pileup to slow down significantly. * if multiple_iterators: * cfilename = samfile.filename # <<<<<<<<<<<<<< * with nogil: * self.htsfile = hts_open(cfilename, 'r') */ - __pyx_t_3 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->__pyx_base.filename); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 2420, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->__pyx_base.filename); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 2784, __pyx_L1_error) __pyx_v_cfilename = __pyx_t_3; - /* "pysam/libcalignmentfile.pyx":2421 + /* "pysam/libcalignmentfile.pyx":2785 * if multiple_iterators: * cfilename = samfile.filename * with nogil: # <<<<<<<<<<<<<< * self.htsfile = hts_open(cfilename, 'r') - * assert self.htsfile != NULL + * if self.htsfile == NULL: */ { #ifdef WITH_THREAD @@ -28058,22 +33823,22 @@ static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __ #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":2422 + /* "pysam/libcalignmentfile.pyx":2786 * cfilename = samfile.filename * with nogil: * self.htsfile = hts_open(cfilename, 'r') # <<<<<<<<<<<<<< - * assert self.htsfile != NULL - * # read header - required for accurate positioning + * if self.htsfile == NULL: + * raise OSError("unable to reopen htsfile") */ __pyx_v_self->htsfile = hts_open(__pyx_v_cfilename, ((char const *)"r")); } - /* "pysam/libcalignmentfile.pyx":2421 + /* "pysam/libcalignmentfile.pyx":2785 * if multiple_iterators: * cfilename = samfile.filename * with nogil: # <<<<<<<<<<<<<< * self.htsfile = hts_open(cfilename, 'r') - * assert self.htsfile != NULL + * if self.htsfile == NULL: */ /*finally:*/ { /*normal exit:*/{ @@ -28087,28 +33852,44 @@ static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __ } } - /* "pysam/libcalignmentfile.pyx":2423 + /* "pysam/libcalignmentfile.pyx":2787 * with nogil: * self.htsfile = hts_open(cfilename, 'r') - * assert self.htsfile != NULL # <<<<<<<<<<<<<< - * # read header - required for accurate positioning + * if self.htsfile == NULL: # <<<<<<<<<<<<<< + * raise OSError("unable to reopen htsfile") + * + */ + __pyx_t_2 = ((__pyx_v_self->htsfile == NULL) != 0); + if (unlikely(__pyx_t_2)) { + + /* "pysam/libcalignmentfile.pyx":2788 + * self.htsfile = hts_open(cfilename, 'r') + * if self.htsfile == NULL: + * raise OSError("unable to reopen htsfile") # <<<<<<<<<<<<<< + * + * # need to advance in newly opened file to position after header + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_tuple__92, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2788, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2788, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":2787 * with nogil: + * self.htsfile = hts_open(cfilename, 'r') + * if self.htsfile == NULL: # <<<<<<<<<<<<<< + * raise OSError("unable to reopen htsfile") + * */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!Py_OptimizeFlag)) { - if (unlikely(!((__pyx_v_self->htsfile != NULL) != 0))) { - PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 2423, __pyx_L1_error) - } } - #endif - /* "pysam/libcalignmentfile.pyx":2425 - * assert self.htsfile != NULL - * # read header - required for accurate positioning + /* "pysam/libcalignmentfile.pyx":2792 + * # need to advance in newly opened file to position after header + * # better: use seek/tell? * with nogil: # <<<<<<<<<<<<<< - * self.header = sam_hdr_read(self.htsfile) - * self.owns_samfile = True + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: */ { #ifdef WITH_THREAD @@ -28118,22 +33899,22 @@ static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __ #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":2426 - * # read header - required for accurate positioning + /* "pysam/libcalignmentfile.pyx":2793 + * # better: use seek/tell? * with nogil: - * self.header = sam_hdr_read(self.htsfile) # <<<<<<<<<<<<<< - * self.owns_samfile = True - * else: + * hdr = sam_hdr_read(self.htsfile) # <<<<<<<<<<<<<< + * if hdr == NULL: + * raise OSError("unable to read header information") */ - __pyx_v_self->header = sam_hdr_read(__pyx_v_self->htsfile); + __pyx_v_hdr = sam_hdr_read(__pyx_v_self->htsfile); } - /* "pysam/libcalignmentfile.pyx":2425 - * assert self.htsfile != NULL - * # read header - required for accurate positioning + /* "pysam/libcalignmentfile.pyx":2792 + * # need to advance in newly opened file to position after header + * # better: use seek/tell? * with nogil: # <<<<<<<<<<<<<< - * self.header = sam_hdr_read(self.htsfile) - * self.owns_samfile = True + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: */ /*finally:*/ { /*normal exit:*/{ @@ -28141,22 +33922,69 @@ static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __ __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif - goto __pyx_L9; + goto __pyx_L10; } - __pyx_L9:; + __pyx_L10:; } } - /* "pysam/libcalignmentfile.pyx":2427 + /* "pysam/libcalignmentfile.pyx":2794 + * with nogil: + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: # <<<<<<<<<<<<<< + * raise OSError("unable to read header information") + * self.header = makeAlignmentHeader(hdr) + */ + __pyx_t_2 = ((__pyx_v_hdr == NULL) != 0); + if (unlikely(__pyx_t_2)) { + + /* "pysam/libcalignmentfile.pyx":2795 + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: + * raise OSError("unable to read header information") # <<<<<<<<<<<<<< + * self.header = makeAlignmentHeader(hdr) + * self.owns_samfile = True + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_tuple__93, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2795, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2795, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":2794 * with nogil: - * self.header = sam_hdr_read(self.htsfile) + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: # <<<<<<<<<<<<<< + * raise OSError("unable to read header information") + * self.header = makeAlignmentHeader(hdr) + */ + } + + /* "pysam/libcalignmentfile.pyx":2796 + * if hdr == NULL: + * raise OSError("unable to read header information") + * self.header = makeAlignmentHeader(hdr) # <<<<<<<<<<<<<< + * self.owns_samfile = True + * else: + */ + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2796, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":2797 + * raise OSError("unable to read header information") + * self.header = makeAlignmentHeader(hdr) * self.owns_samfile = True # <<<<<<<<<<<<<< * else: * self.htsfile = self.samfile.htsfile */ __pyx_v_self->owns_samfile = 1; - /* "pysam/libcalignmentfile.pyx":2419 + /* "pysam/libcalignmentfile.pyx":2783 * # multiple_iterators the file - note that this makes the iterator * # slow and causes pileup to slow down significantly. * if multiple_iterators: # <<<<<<<<<<<<<< @@ -28166,30 +33994,35 @@ static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __ goto __pyx_L3; } - /* "pysam/libcalignmentfile.pyx":2429 + /* "pysam/libcalignmentfile.pyx":2799 * self.owns_samfile = True * else: * self.htsfile = self.samfile.htsfile # <<<<<<<<<<<<<< - * self.header = self.samfile.header + * self.header = samfile.header * self.owns_samfile = False */ /*else*/ { __pyx_t_4 = __pyx_v_self->samfile->__pyx_base.htsfile; __pyx_v_self->htsfile = __pyx_t_4; - /* "pysam/libcalignmentfile.pyx":2430 + /* "pysam/libcalignmentfile.pyx":2800 * else: * self.htsfile = self.samfile.htsfile - * self.header = self.samfile.header # <<<<<<<<<<<<<< + * self.header = samfile.header # <<<<<<<<<<<<<< * self.owns_samfile = False * */ - __pyx_t_5 = __pyx_v_self->samfile->header; - __pyx_v_self->header = __pyx_t_5; + __pyx_t_1 = ((PyObject *)__pyx_v_samfile->header); + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":2431 + /* "pysam/libcalignmentfile.pyx":2801 * self.htsfile = self.samfile.htsfile - * self.header = self.samfile.header + * self.header = samfile.header * self.owns_samfile = False # <<<<<<<<<<<<<< * * def build(self): @@ -28198,7 +34031,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __ } __pyx_L3:; - /* "pysam/libcalignmentfile.pyx":2408 + /* "pysam/libcalignmentfile.pyx":2772 * """ * * def __init__(self, AlignmentFile samfile, int multiple_iterators=True): # <<<<<<<<<<<<<< @@ -28219,7 +34052,7 @@ static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __ return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2433 +/* "pysam/libcalignmentfile.pyx":2803 * self.owns_samfile = False * * def build(self): # <<<<<<<<<<<<<< @@ -28245,6 +34078,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc int __pyx_v_ret; bam1_t *__pyx_v_b; uint64_t __pyx_v_pos; + bam_hdr_t *__pyx_v_hdr; PyObject *__pyx_v_qname = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations @@ -28254,20 +34088,22 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_t_5; - int __pyx_t_6; + PyObject *__pyx_t_6 = NULL; + bam_hdr_t *__pyx_t_7; + int __pyx_t_8; __Pyx_RefNannySetupContext("build", 0); - __Pyx_TraceCall("build", __pyx_f[0], 2433, 0, __PYX_ERR(0, 2433, __pyx_L1_error)); + __Pyx_TraceCall("build", __pyx_f[0], 2803, 0, __PYX_ERR(0, 2803, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2436 + /* "pysam/libcalignmentfile.pyx":2806 * '''build the index.''' * * self.index = collections.defaultdict(list) # <<<<<<<<<<<<<< * - * # this method will start indexing from the current file + * # this method will start indexing from the current file position */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2436, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2806, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2436, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2806, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = NULL; @@ -28281,13 +34117,13 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc } } if (!__pyx_t_2) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)(&PyList_Type))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2436, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)(&PyList_Type))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2806, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_2, ((PyObject *)(&PyList_Type))}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2436, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2806, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -28295,19 +34131,19 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_2, ((PyObject *)(&PyList_Type))}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2436, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2806, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2436, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2806, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL; __Pyx_INCREF(((PyObject *)(&PyList_Type))); __Pyx_GIVEREF(((PyObject *)(&PyList_Type))); PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)(&PyList_Type))); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2436, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2806, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -28319,26 +34155,119 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc __pyx_v_self->index = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":2440 - * # this method will start indexing from the current file - * # position if you decide + /* "pysam/libcalignmentfile.pyx":2809 + * + * # this method will start indexing from the current file position * cdef int ret = 1 # <<<<<<<<<<<<<< * cdef bam1_t * b = calloc(1, sizeof( bam1_t)) - * + * if b == NULL: */ __pyx_v_ret = 1; - /* "pysam/libcalignmentfile.pyx":2441 - * # position if you decide + /* "pysam/libcalignmentfile.pyx":2810 + * # this method will start indexing from the current file position * cdef int ret = 1 * cdef bam1_t * b = calloc(1, sizeof( bam1_t)) # <<<<<<<<<<<<<< + * if b == NULL: + * raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t))) + */ + __pyx_v_b = ((bam1_t *)calloc(1, (sizeof(bam1_t)))); + + /* "pysam/libcalignmentfile.pyx":2811 + * cdef int ret = 1 + * cdef bam1_t * b = calloc(1, sizeof( bam1_t)) + * if b == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t))) + * + */ + __pyx_t_5 = ((__pyx_v_b == NULL) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcalignmentfile.pyx":2812 + * cdef bam1_t * b = calloc(1, sizeof( bam1_t)) + * if b == NULL: + * raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t))) # <<<<<<<<<<<<<< + * + * cdef uint64_t pos + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2812, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_FromSize_t((sizeof(bam1_t))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2812, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2812, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_4}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2812, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_4}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2812, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2812, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2812, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2812, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 2812, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":2811 + * cdef int ret = 1 + * cdef bam1_t * b = calloc(1, sizeof( bam1_t)) + * if b == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t))) + * + */ + } + + /* "pysam/libcalignmentfile.pyx":2815 * * cdef uint64_t pos + * cdef bam_hdr_t * hdr = self.header.ptr # <<<<<<<<<<<<<< + * + * while ret > 0: */ - __pyx_v_b = ((bam1_t *)calloc(1, (sizeof(bam1_t)))); + __pyx_t_7 = __pyx_v_self->header->ptr; + __pyx_v_hdr = __pyx_t_7; - /* "pysam/libcalignmentfile.pyx":2445 - * cdef uint64_t pos + /* "pysam/libcalignmentfile.pyx":2817 + * cdef bam_hdr_t * hdr = self.header.ptr * * while ret > 0: # <<<<<<<<<<<<<< * with nogil: @@ -28348,7 +34277,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc __pyx_t_5 = ((__pyx_v_ret > 0) != 0); if (!__pyx_t_5) break; - /* "pysam/libcalignmentfile.pyx":2446 + /* "pysam/libcalignmentfile.pyx":2818 * * while ret > 0: * with nogil: # <<<<<<<<<<<<<< @@ -28363,26 +34292,26 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc #endif /*try:*/ { - /* "pysam/libcalignmentfile.pyx":2447 + /* "pysam/libcalignmentfile.pyx":2819 * while ret > 0: * with nogil: * pos = bgzf_tell(hts_get_bgzfp(self.htsfile)) # <<<<<<<<<<<<<< * ret = sam_read1(self.htsfile, - * self.samfile.header, + * hdr, */ __pyx_v_pos = bgzf_tell(hts_get_bgzfp(__pyx_v_self->htsfile)); - /* "pysam/libcalignmentfile.pyx":2448 + /* "pysam/libcalignmentfile.pyx":2820 * with nogil: * pos = bgzf_tell(hts_get_bgzfp(self.htsfile)) * ret = sam_read1(self.htsfile, # <<<<<<<<<<<<<< - * self.samfile.header, + * hdr, * b) */ - __pyx_v_ret = sam_read1(__pyx_v_self->htsfile, __pyx_v_self->samfile->header, __pyx_v_b); + __pyx_v_ret = sam_read1(__pyx_v_self->htsfile, __pyx_v_hdr, __pyx_v_b); } - /* "pysam/libcalignmentfile.pyx":2446 + /* "pysam/libcalignmentfile.pyx":2818 * * while ret > 0: * with nogil: # <<<<<<<<<<<<<< @@ -28395,15 +34324,15 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif - goto __pyx_L9; + goto __pyx_L10; } - __pyx_L9:; + __pyx_L10:; } } - /* "pysam/libcalignmentfile.pyx":2451 - * self.samfile.header, + /* "pysam/libcalignmentfile.pyx":2824 * b) + * * if ret > 0: # <<<<<<<<<<<<<< * qname = charptr_to_str(pysam_bam_get_qname(b)) * self.index[qname].append(pos) @@ -28411,36 +34340,36 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc __pyx_t_5 = ((__pyx_v_ret > 0) != 0); if (__pyx_t_5) { - /* "pysam/libcalignmentfile.pyx":2452 - * b) + /* "pysam/libcalignmentfile.pyx":2825 + * * if ret > 0: * qname = charptr_to_str(pysam_bam_get_qname(b)) # <<<<<<<<<<<<<< * self.index[qname].append(pos) * */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str(pysam_bam_get_qname(__pyx_v_b), NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2452, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XDECREF_SET(__pyx_v_qname, __pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str(pysam_bam_get_qname(__pyx_v_b), NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2825, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF_SET(__pyx_v_qname, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcalignmentfile.pyx":2453 + /* "pysam/libcalignmentfile.pyx":2826 * if ret > 0: * qname = charptr_to_str(pysam_bam_get_qname(b)) * self.index[qname].append(pos) # <<<<<<<<<<<<<< * * bam_destroy1(b) */ - __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2453, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_From_uint64_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2453, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2826, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_t_3); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 2453, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2826, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_Append(__pyx_t_3, __pyx_t_1); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 2826, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":2451 - * self.samfile.header, + /* "pysam/libcalignmentfile.pyx":2824 * b) + * * if ret > 0: # <<<<<<<<<<<<<< * qname = charptr_to_str(pysam_bam_get_qname(b)) * self.index[qname].append(pos) @@ -28448,7 +34377,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc } } - /* "pysam/libcalignmentfile.pyx":2455 + /* "pysam/libcalignmentfile.pyx":2828 * self.index[qname].append(pos) * * bam_destroy1(b) # <<<<<<<<<<<<<< @@ -28457,7 +34386,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc */ bam_destroy1(__pyx_v_b); - /* "pysam/libcalignmentfile.pyx":2433 + /* "pysam/libcalignmentfile.pyx":2803 * self.owns_samfile = False * * def build(self): # <<<<<<<<<<<<<< @@ -28473,6 +34402,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("pysam.libcalignmentfile.IndexedReads.build", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -28483,7 +34413,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2457 +/* "pysam/libcalignmentfile.pyx":2830 * bam_destroy1(b) * * def find(self, query_name): # <<<<<<<<<<<<<< @@ -28493,7 +34423,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struc /* Python wrapper */ static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_5find(PyObject *__pyx_v_self, PyObject *__pyx_v_query_name); /*proto*/ -static char __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_4find[] = "IndexedReads.find(self, query_name)\nfind `query_name` in index.\n\n Returns\n -------\n\n IteratorRowSelection\n Returns an iterator over all reads with query_name.\n\n Raises\n ------\n \n KeyError\n if the `query_name` is not in the index.\n\n "; +static char __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_4find[] = "IndexedReads.find(self, query_name)\nfind `query_name` in index.\n\n Returns\n -------\n\n IteratorRowSelection\n Returns an iterator over all reads with query_name.\n\n Raises\n ------\n\n KeyError\n if the `query_name` is not in the index.\n\n "; static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_5find(PyObject *__pyx_v_self, PyObject *__pyx_v_query_name) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations @@ -28515,20 +34445,20 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(struct PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("find", 0); - __Pyx_TraceCall("find", __pyx_f[0], 2457, 0, __PYX_ERR(0, 2457, __pyx_L1_error)); + __Pyx_TraceCall("find", __pyx_f[0], 2830, 0, __PYX_ERR(0, 2830, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2473 + /* "pysam/libcalignmentfile.pyx":2846 * * ''' * if query_name in self.index: # <<<<<<<<<<<<<< * return IteratorRowSelection( * self.samfile, */ - __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_query_name, __pyx_v_self->index, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2473, __pyx_L1_error) + __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_query_name, __pyx_v_self->index, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2846, __pyx_L1_error) __pyx_t_2 = (__pyx_t_1 != 0); if (likely(__pyx_t_2)) { - /* "pysam/libcalignmentfile.pyx":2474 + /* "pysam/libcalignmentfile.pyx":2847 * ''' * if query_name in self.index: * return IteratorRowSelection( # <<<<<<<<<<<<<< @@ -28537,24 +34467,24 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(struct */ __Pyx_XDECREF(__pyx_r); - /* "pysam/libcalignmentfile.pyx":2476 + /* "pysam/libcalignmentfile.pyx":2849 * return IteratorRowSelection( * self.samfile, * self.index[query_name], # <<<<<<<<<<<<<< * multiple_iterators = False) * else: */ - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_self->index, __pyx_v_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2476, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_self->index, __pyx_v_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2849, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - /* "pysam/libcalignmentfile.pyx":2474 + /* "pysam/libcalignmentfile.pyx":2847 * ''' * if query_name in self.index: * return IteratorRowSelection( # <<<<<<<<<<<<<< * self.samfile, * self.index[query_name], */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2474, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2847, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile)); @@ -28563,25 +34493,25 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(struct PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignmentfile.pyx":2477 + /* "pysam/libcalignmentfile.pyx":2850 * self.samfile, * self.index[query_name], * multiple_iterators = False) # <<<<<<<<<<<<<< * else: * raise KeyError("read %s not found" % query_name) */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2477, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2850, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, Py_False) < 0) __PYX_ERR(0, 2477, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, Py_False) < 0) __PYX_ERR(0, 2850, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":2474 + /* "pysam/libcalignmentfile.pyx":2847 * ''' * if query_name in self.index: * return IteratorRowSelection( # <<<<<<<<<<<<<< * self.samfile, * self.index[query_name], */ - __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection), __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2474, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection), __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2847, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -28589,7 +34519,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(struct __pyx_t_5 = 0; goto __pyx_L0; - /* "pysam/libcalignmentfile.pyx":2473 + /* "pysam/libcalignmentfile.pyx":2846 * * ''' * if query_name in self.index: # <<<<<<<<<<<<<< @@ -28598,7 +34528,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(struct */ } - /* "pysam/libcalignmentfile.pyx":2479 + /* "pysam/libcalignmentfile.pyx":2852 * multiple_iterators = False) * else: * raise KeyError("read %s not found" % query_name) # <<<<<<<<<<<<<< @@ -28606,17 +34536,17 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(struct * def __dealloc__(self): */ /*else*/ { - __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_read_s_not_found, __pyx_v_query_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2479, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_read_s_not_found, __pyx_v_query_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2852, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2479, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2852, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2479, __pyx_L1_error) + __PYX_ERR(0, 2852, __pyx_L1_error) } - /* "pysam/libcalignmentfile.pyx":2457 + /* "pysam/libcalignmentfile.pyx":2830 * bam_destroy1(b) * * def find(self, query_name): # <<<<<<<<<<<<<< @@ -28638,7 +34568,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(struct return __pyx_r; } -/* "pysam/libcalignmentfile.pyx":2481 +/* "pysam/libcalignmentfile.pyx":2854 * raise KeyError("read %s not found" % query_name) * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -28662,46 +34592,33 @@ static void __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_6__dealloc__(stru __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2481, 0, __PYX_ERR(0, 2481, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2854, 0, __PYX_ERR(0, 2854, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":2482 + /* "pysam/libcalignmentfile.pyx":2855 * * def __dealloc__(self): * if self.owns_samfile: # <<<<<<<<<<<<<< * hts_close(self.htsfile) - * bam_hdr_destroy(self.header) */ __pyx_t_1 = (__pyx_v_self->owns_samfile != 0); if (__pyx_t_1) { - /* "pysam/libcalignmentfile.pyx":2483 + /* "pysam/libcalignmentfile.pyx":2856 * def __dealloc__(self): * if self.owns_samfile: * hts_close(self.htsfile) # <<<<<<<<<<<<<< - * bam_hdr_destroy(self.header) - * */ (void)(hts_close(__pyx_v_self->htsfile)); - /* "pysam/libcalignmentfile.pyx":2484 - * if self.owns_samfile: - * hts_close(self.htsfile) - * bam_hdr_destroy(self.header) # <<<<<<<<<<<<<< - * - * __all__ = [ - */ - bam_hdr_destroy(__pyx_v_self->header); - - /* "pysam/libcalignmentfile.pyx":2482 + /* "pysam/libcalignmentfile.pyx":2855 * * def __dealloc__(self): * if self.owns_samfile: # <<<<<<<<<<<<<< * hts_close(self.htsfile) - * bam_hdr_destroy(self.header) */ } - /* "pysam/libcalignmentfile.pyx":2481 + /* "pysam/libcalignmentfile.pyx":2854 * raise KeyError("read %s not found" % query_name) * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -28720,7 +34637,7 @@ static void __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_6__dealloc__(stru /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -28748,11 +34665,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cy /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__78, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__94, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -28760,7 +34677,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cy /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -28777,9 +34694,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cy /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") */ /* Python wrapper */ @@ -28805,11 +34722,11 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_10__setstate __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); /* "(tree fragment)":4 - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__79, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__95, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -28817,9 +34734,9 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_10__setstate /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") */ /* function exit code */ @@ -28926,7 +34843,7 @@ static PyObject *__pyx_pf_5pysam_17libcalignmentfile_2__pyx_unpickle_SNPCall(CYT PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__80) + __Pyx_TraceFrameInit(__pyx_codeobj__96) __Pyx_RefNannySetupContext("__pyx_unpickle_SNPCall", 0); __Pyx_TraceCall("__pyx_unpickle_SNPCall", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); @@ -30046,6 +35963,237 @@ static CYTHON_INLINE void __pyx_f_7cpython_5array_zero(arrayobject *__pyx_v_self __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); } + +static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) goto bad; + return o; + bad: + Py_DECREF(o); o = 0; + return NULL; +} + +static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentHeader(PyObject *o) { + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_13__dealloc__(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5pysam_17libcalignmentfile_AlignmentHeader(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5pysam_17libcalignmentfile_AlignmentHeader(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_35__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_nreferences(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_references(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_10references_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_lengths(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths_1__get__(o); +} + +static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_AlignmentHeader[] = { + {"_from_text_and_lengths", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_5_from_text_and_lengths, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths}, + {"from_text", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7from_text, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text}, + {"from_dict", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_9from_dict, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict}, + {"from_references", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11from_references, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references}, + {"copy", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_17copy, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_16copy}, + {"_build_sequence_section", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_19_build_sequence_section, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section}, + {"to_dict", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_21to_dict, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict}, + {"as_dict", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_23as_dict, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict}, + {"get_reference_name", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_25get_reference_name, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name}, + {"get_reference_length", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_27get_reference_length, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length}, + {"is_valid_tid", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_29is_valid_tid, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid}, + {"get_tid", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_31get_tid, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid}, + {"items", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_39items, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_38items}, + {"iteritems", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_41iteritems, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems}, + {"keys", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_43keys, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_42keys}, + {"values", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_45values, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_44values}, + {"get", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_47get, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_46get}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_53__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_55__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5pysam_17libcalignmentfile_AlignmentHeader[] = { + {(char *)"nreferences", __pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_nreferences, 0, (char *)"\"int with the number of :term:`reference` sequences in the file.\n\n This is a read-only attribute.", 0}, + {(char *)"references", __pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_references, 0, (char *)"tuple with the names of :term:`reference` sequences. This is a\n read-only attribute", 0}, + {(char *)"lengths", __pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_lengths, 0, (char *)"tuple of the lengths of the :term:`reference` sequences. This is a\n read-only attribute. The lengths are in the same order as\n :attr:`pysam.AlignmentFile.references`\n ", 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_AlignmentHeader = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000) + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_15__bool__, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000) + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_long*/ + #else + 0, /*reserved*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000) + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000) + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000) + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + 0, /*nb_index*/ + #if PY_VERSION_HEX >= 0x03050000 + 0, /*nb_matrix_multiply*/ + #endif + #if PY_VERSION_HEX >= 0x03050000 + 0, /*nb_inplace_matrix_multiply*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_AlignmentHeader = { + __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5pysam_17libcalignmentfile_AlignmentHeader, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_51__contains__, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_AlignmentHeader = { + __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__, /*mp_length*/ + __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_37__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5pysam_17libcalignmentfile_AlignmentHeader, /*mp_ass_subscript*/ +}; + +static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcalignmentfile.AlignmentHeader", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentHeader, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_AlignmentHeader, /*tp_as_number*/ + &__pyx_tp_as_sequence_AlignmentHeader, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_AlignmentHeader, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_33__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "AlignmentHeader()\nheader information for a :class:`AlignmentFile` object\n\n Parameters\n ----------\n header_dict : dict\n build header from a multi-level dictionary. The\n first level are the four types ('HD', 'SQ', ...). The second\n level are a list of lines, with each line being a list of\n tag-value pairs. The header is constructed first from all the\n defined fields, followed by user tags in alphabetical\n order. Alternatively, an :class:`~pysam.AlignmentHeader`\n object can be passed directly.\n\n text : string\n use the string provided as the header\n\n reference_names : list\n see reference_lengths\n\n reference_lengths : list\n build header from list of chromosome names and lengths. By\n default, 'SQ' and 'LN' tags will be added to the header\n text. This option can be changed by unsetting the flag\n `add_sq_text`.\n\n add_sq_text : bool\n do not add 'SQ' and 'LN' tags to header. This option permits\n construction :term:`SAM` formatted files without a header.\n\n ", /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5pysam_17libcalignmentfile_AlignmentHeader, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5pysam_17libcalignmentfile_AlignmentHeader, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_3__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile; static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentFile(PyTypeObject *t, PyObject *a, PyObject *k) { @@ -30055,6 +36203,7 @@ static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentFile(PyTypeObj p = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)o); p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile; p->reference_filename = Py_None; Py_INCREF(Py_None); + p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None); if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_1__cinit__(o, a, k) < 0)) goto bad; return o; bad: @@ -30074,11 +36223,12 @@ static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentFile(PyObject * PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__dealloc__(o); + __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_27__dealloc__(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } Py_CLEAR(p->reference_filename); + Py_CLEAR(p->header); PyObject_GC_Track(o); if (likely(__pyx_ptype_5pysam_10libchtslib_HTSFile)) __pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dealloc(o); else __Pyx_call_next_tp_dealloc(o, __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentFile); } @@ -30090,6 +36240,9 @@ static int __pyx_tp_traverse_5pysam_17libcalignmentfile_AlignmentFile(PyObject * if (p->reference_filename) { e = (*v)(p->reference_filename, a); if (e) return e; } + if (p->header) { + e = (*v)(((PyObject *)p->header), a); if (e) return e; + } return 0; } @@ -30100,21 +36253,12 @@ static int __pyx_tp_clear_5pysam_17libcalignmentfile_AlignmentFile(PyObject *o) tmp = ((PyObject*)p->reference_filename); p->reference_filename = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); + tmp = ((PyObject*)p->header); + p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); return 0; } -static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nreferences(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences_1__get__(o); -} - -static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_references(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_10references_1__get__(o); -} - -static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_lengths(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7lengths_1__get__(o); -} - static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_mapped(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6mapped_1__get__(o); } @@ -30127,54 +36271,69 @@ static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nocoor return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate_1__get__(o); } -static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_text(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_4text_1__get__(o); +static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nreferences(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences_1__get__(o); } -static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_header(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6header_1__get__(o); +static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_references(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_10references_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_lengths(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7lengths_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_text(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_4text_1__get__(o); } static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_reference_filename(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename_1__get__(o); } +static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_header(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6header_1__get__(o); +} + static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_AlignmentFile[] = { {"has_index", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_3has_index, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_2has_index}, {"check_index", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_5check_index, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_4check_index}, {"_open", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7_open, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_6_open}, - {"get_tid", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9get_tid, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_8get_tid}, - {"get_reference_name", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11get_reference_name, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_10get_reference_name}, - {"parse_region", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13parse_region, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_12parse_region}, - {"fetch", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15fetch, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_14fetch}, - {"head", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17head, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_16head}, - {"mate", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19mate, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_18mate}, - {"pileup", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21pileup, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_20pileup}, - {"count", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23count, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_22count}, - {"count_coverage", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25count_coverage, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_24count_coverage}, - {"find_introns", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_27find_introns, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_26find_introns}, - {"close", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29close, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_28close}, - {"write", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33write, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_32write}, - {"__enter__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35__enter__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_34__enter__}, - {"__exit__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__exit__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_36__exit__}, - {"__next__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41__next__, METH_NOARGS|METH_COEXIST, 0}, - {"gettid", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43gettid, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_42gettid}, - {"getrname", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45getrname, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_44getrname}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_46__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_48__setstate_cython__}, + {"fetch", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9fetch, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_8fetch}, + {"head", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11head, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_10head}, + {"mate", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13mate, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_12mate}, + {"pileup", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15pileup, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_14pileup}, + {"count", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17count, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_16count}, + {"count_coverage", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19count_coverage, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage}, + {"find_introns_slow", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21find_introns_slow, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow}, + {"find_introns", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23find_introns, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns}, + {"close", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25close, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_24close}, + {"write", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_28write}, + {"__enter__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__enter__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__}, + {"__exit__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33__exit__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__}, + {"get_index_statistics", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35get_index_statistics, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics}, + {"__next__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__, METH_NOARGS|METH_COEXIST, 0}, + {"is_valid_tid", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41is_valid_tid, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid}, + {"get_tid", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43get_tid, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid}, + {"get_reference_name", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45get_reference_name, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name}, + {"get_reference_length", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47get_reference_length, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length}, + {"gettid", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49gettid, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_48gettid}, + {"getrname", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_51getrname, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_50getrname}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_53__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_55__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__}, {0, 0, 0, 0} }; static struct PyGetSetDef __pyx_getsets_5pysam_17libcalignmentfile_AlignmentFile[] = { - {(char *)"nreferences", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nreferences, 0, (char *)"\"int with the number of :term:`reference` sequences in the file.\n This is a read-only attribute.", 0}, - {(char *)"references", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_references, 0, (char *)"tuple with the names of :term:`reference` sequences. This is a \n read-only attribute", 0}, - {(char *)"lengths", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_lengths, 0, (char *)"tuple of the lengths of the :term:`reference` sequences. This is a\n read-only attribute. The lengths are in the same order as\n :attr:`pysam.AlignmentFile.references`\n\n ", 0}, {(char *)"mapped", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_mapped, 0, (char *)"int with total number of mapped alignments according to the\n statistics recorded in the index. This is a read-only\n attribute.\n ", 0}, {(char *)"unmapped", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_unmapped, 0, (char *)"int with total number of unmapped reads according to the statistics\n recorded in the index. This number of reads includes the number of reads\n without coordinates. This is a read-only attribute.\n ", 0}, {(char *)"nocoordinate", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nocoordinate, 0, (char *)"int with total number of reads without coordinates according to the\n statistics recorded in the index. This is a read-only attribute.\n ", 0}, - {(char *)"text", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_text, 0, (char *)"string with the full contents of the :term:`sam file` header as a\n string. \n\n This is a read-only attribute.\n \n See :attr:`pysam.AlignmentFile.header` to get a parsed\n representation of the header.\n ", 0}, - {(char *)"header", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_header, 0, (char *)"two-level dictionay with header information from the file. \n \n This is a read-only attribute.\n\n The first level contains the record (``HD``, ``SQ``, etc) and\n the second level contains the fields (``VN``, ``LN``, etc).\n \n The parser is validating and will raise an AssertionError if\n if encounters any record or field tags that are not part of\n the SAM specification. Use the\n :attr:`pysam.AlignmentFile.text` attribute to get the unparsed\n header.\n\n The parsing follows the SAM format specification with the\n exception of the ``CL`` field. This option will consume the\n rest of a header line irrespective of any additional fields.\n This behaviour has been added to accommodate command line\n options that contain characters that are not valid field\n separators.\n\n ", 0}, + {(char *)"nreferences", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nreferences, 0, (char *)"\"int with the number of :term:`reference` sequences in the file.\n This is a read-only attribute.", 0}, + {(char *)"references", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_references, 0, (char *)"tuple with the names of :term:`reference` sequences. This is a\n read-only attribute", 0}, + {(char *)"lengths", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_lengths, 0, (char *)"tuple of the lengths of the :term:`reference` sequences. This is a\n read-only attribute. The lengths are in the same order as\n :attr:`pysam.AlignmentFile.references`\n\n ", 0}, + {(char *)"text", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_text, 0, (char *)"deprecated, use .header directly", 0}, {(char *)"reference_filename", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_reference_filename, 0, (char *)0, 0}, + {(char *)"header", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_header, 0, (char *)0, 0}, {0, 0, 0, 0, 0} }; @@ -30204,13 +36363,13 @@ static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_AlignmentFile = { 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "AlignmentFile(filepath_or_object, mode=None, template=None,\n reference_names=None, reference_lengths=None, text=NULL,\n header=None, add_sq_text=False, check_header=True, check_sq=True,\n reference_filename=None, filename=None, duplicate_filehandle=True)\n\n A :term:`SAM`/:term:`BAM` formatted file. \n\n If `filepath_or_object` is a string, the file is automatically\n opened. If `filepath_or_object` is a python File object, the\n already opened file will be used.\n\n If the file is opened for reading an index for a BAM file exists\n (.bai), it will be opened automatically. Without an index random\n access via :meth:`~pysam.AlignmentFile.fetch` and\n :meth:`~pysam.AlignmentFile.pileup` is disabled.\n\n For writing, the header of a :term:`SAM` file/:term:`BAM` file can\n be constituted from several sources (see also the samtools format\n specification):\n\n 1. If `template` is given, the header is copied from a another\n `AlignmentFile` (`template` must be a\n :class:`~pysam.AlignmentFile`).\n\n 2. If `header` is given, the header is built from a\n multi-level dictionary. \n\n 3. If `text` is given, new header text is copied from raw\n text.\n\n 4. The names (`reference_names`) and lengths\n (`reference_lengths`) are supplied directly as lists.\n\n When reading or writing a CRAM file, the filename of a FASTA-formatted\n reference can be specified with `reference_filename`.\n\n By default, if a file is opened in mode 'r', it is checked\n for a valid header (`check_header` = True) and a definition of\n chromosome names (`check_sq` = True).\n\n Parameters\n ----------\n mode : string\n `mode` should be ``r`` for reading or ``w`` for writing. The\n default is text mode (:term:`SAM`). For binary (:term:`BAM`)\n I/O you should append ``b`` for compressed or ``u`` for\n uncompressed :term:`BAM` output. U""se ``h`` to output header\n information in text (:term:`TAM`) mode. Use ``c`` for\n :term:`CRAM` formatted files.\n\n If ``b`` is present, it must immediately follow ``r`` or\n ``w``. Valid modes are ``r``, ``w``, ``wh``, ``rb``, ``wb``,\n ``wbu``, ``wb0``, ``rc`` and ``wc``. For instance, to open a\n :term:`BAM` formatted file for reading, type::\n\n f = pysam.AlignmentFile('ex1.bam','rb')\n\n If mode is not specified, the method will try to auto-detect\n in the order 'rb', 'r', thus both the following should work::\n\n f1 = pysam.AlignmentFile('ex1.bam')\n f2 = pysam.AlignmentFile('ex1.sam')\n\n template : AlignmentFile\n when writing, copy header frem `template`.\n\n header : dict\n when writing, build header from a multi-level dictionary. The\n first level are the four types ('HD', 'SQ', ...). The second\n level are a list of lines, with each line being a list of\n tag-value pairs. The header is constructed first from all the\n defined fields, followed by user tags in alphabetical order.\n\n text : string\n when writing, use the string provided as the header\n\n reference_names : list\n see referece_lengths\n\n reference_lengths : list\n when writing, build header from list of chromosome names and\n lengths. By default, 'SQ' and 'LN' tags will be added to the\n header text. This option can be changed by unsetting the flag\n `add_sq_text`.\n\n add_sq_text : bool\n do not add 'SQ' and 'LN' tags to header. This option permits\n construction :term:`SAM` formatted files without a header.\n\n check_header : bool\n when reading, check if header is present (default=True)\n\n check_sq : bool\n when reading, check if SQ entries are present in header\n (default=True)\n\n reference_filename : string\n Path to a FASTA-formatted refere""nce file. Valid only for CRAM files.\n When reading a CRAM file, this overrides both ``$REF_PATH`` and the URL\n specified in the header (``UR`` tag), which are normally used to find\n the reference.\n\n filename : string\n Alternative to filepath_or_object. Filename of the file\n to be opened.\n\n duplicate_filehandle: bool \n By default, file handles passed either directly or through\n File-like objects will be duplicated before passing them to\n htslib. The duplication prevents issues where the same stream\n will be closed by htslib and through destruction of the\n high-level python object. Set to False to turn off\n duplication.\n\n ", /*tp_doc*/ + "AlignmentFile(filepath_or_object, mode=None, template=None,\n reference_names=None, reference_lengths=None, text=NULL,\n header=None, add_sq_text=False, check_header=True, check_sq=True,\n reference_filename=None, filename=None, index_filename=None,\n filepath_index=None, require_index=False, duplicate_filehandle=True,\n ignore_truncation=False, threads=1)\n\n A :term:`SAM`/:term:`BAM`/:term:`CRAM` formatted file.\n\n If `filepath_or_object` is a string, the file is automatically\n opened. If `filepath_or_object` is a python File object, the\n already opened file will be used.\n\n If the file is opened for reading and an index exists (if file is BAM, a\n .bai file or if CRAM a .crai file), it will be opened automatically.\n `index_filename` may be specified explicitly. If the index is not named\n in the standard manner, not located in the same directory as the\n BAM/CRAM file, or is remote. Without an index, random access via\n :meth:`~pysam.AlignmentFile.fetch` and :meth:`~pysam.AlignmentFile.pileup`\n is disabled.\n\n For writing, the header of a :term:`SAM` file/:term:`BAM` file can\n be constituted from several sources (see also the samtools format\n specification):\n\n 1. If `template` is given, the header is copied from a another\n `AlignmentFile` (`template` must be a\n :class:`~pysam.AlignmentFile`).\n\n 2. If `header` is given, the header is built from a\n multi-level dictionary.\n\n 3. If `text` is given, new header text is copied from raw\n text.\n\n 4. The names (`reference_names`) and lengths\n (`reference_lengths`) are supplied directly as lists.\n\n When reading or writing a CRAM file, the filename of a FASTA-formatted\n reference can be specified with `reference_filename`.\n\n By default, if a file is opened in mode 'r', it is checked\n for a valid header (`check_header` = True) and a definition of\n c""hromosome names (`check_sq` = True).\n\n Parameters\n ----------\n mode : string\n `mode` should be ``r`` for reading or ``w`` for writing. The\n default is text mode (:term:`SAM`). For binary (:term:`BAM`)\n I/O you should append ``b`` for compressed or ``u`` for\n uncompressed :term:`BAM` output. Use ``h`` to output header\n information in text (:term:`TAM`) mode. Use ``c`` for\n :term:`CRAM` formatted files.\n\n If ``b`` is present, it must immediately follow ``r`` or\n ``w``. Valid modes are ``r``, ``w``, ``wh``, ``rb``, ``wb``,\n ``wbu``, ``wb0``, ``rc`` and ``wc``. For instance, to open a\n :term:`BAM` formatted file for reading, type::\n\n f = pysam.AlignmentFile('ex1.bam','rb')\n\n If mode is not specified, the method will try to auto-detect\n in the order 'rb', 'r', thus both the following should work::\n\n f1 = pysam.AlignmentFile('ex1.bam')\n f2 = pysam.AlignmentFile('ex1.sam')\n\n template : AlignmentFile\n when writing, copy header from file `template`.\n\n header : dict or AlignmentHeader\n when writing, build header from a multi-level dictionary. The\n first level are the four types ('HD', 'SQ', ...). The second\n level are a list of lines, with each line being a list of\n tag-value pairs. The header is constructed first from all the\n defined fields, followed by user tags in alphabetical\n order. Alternatively, an :class:`~pysam.AlignmentHeader`\n object can be passed directly.\n\n text : string\n when writing, use the string provided as the header\n\n reference_names : list\n see reference_lengths\n\n reference_lengths : list\n when writing or opening a SAM file without header build header\n from list of chromosome names and lengths. By default, 'SQ'\n and 'LN' tags will be added to the header text. This option\n "" can be changed by unsetting the flag `add_sq_text`.\n\n add_sq_text : bool\n do not add 'SQ' and 'LN' tags to header. This option permits\n construction :term:`SAM` formatted files without a header.\n\n add_sam_header : bool\n when outputting SAM the default is to output a header. This is\n equivalent to opening the file in 'wh' mode. If this option is\n set to False, no header will be output. To read such a file,\n set `check_header=False`.\n\n check_header : bool\n obsolete: when reading a SAM file, check if header is present\n (default=True)\n\n check_sq : bool\n when reading, check if SQ entries are present in header\n (default=True)\n\n reference_filename : string\n Path to a FASTA-formatted reference file. Valid only for CRAM files.\n When reading a CRAM file, this overrides both ``$REF_PATH`` and the URL\n specified in the header (``UR`` tag), which are normally used to find\n the reference.\n\n index_filename : string\n Explicit path to the index file. Only needed if the index is not\n named in the standard manner, not located in the same directory as\n the BAM/CRAM file, or is remote. An IOError is raised if the index\n cannot be found or is invalid.\n\n filepath_index : string\n Alias for `index_filename`.\n\n require_index : bool\n When reading, require that an index file is present and is valid or\n raise an IOError. (default=False)\n\n filename : string\n Alternative to filepath_or_object. Filename of the file\n to be opened.\n\n duplicate_filehandle: bool\n By default, file handles passed either directly or through\n File-like objects will be duplicated before passing them to\n htslib. The duplication prevents issues where the same stream\n will be closed by htslib and through destruction of the\n high-level python object. Se""t to False to turn off\n duplication.\n\n ignore_truncation: bool\n Issue a warning, instead of raising an error if the current file\n appears to be truncated due to a missing EOF marker. Only applies\n to bgzipped formats. (Default=False)\n\n format_options: list\n A list of key=value strings, as accepted by --input-fmt-option and\n --output-fmt-option in samtools.\n threads: integer\n Number of threads to use for compressing/decompressing BAM/CRAM files.\n Setting threads to > 1 cannot be combined with `ignore_truncation`.\n (Default=1)\n ", /*tp_doc*/ __pyx_tp_traverse_5pysam_17libcalignmentfile_AlignmentFile, /*tp_traverse*/ __pyx_tp_clear_5pysam_17libcalignmentfile_AlignmentFile, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__iter__, /*tp_iter*/ - __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41__next__, /*tp_iternext*/ + __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__iter__, /*tp_iter*/ + __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__, /*tp_iternext*/ __pyx_methods_5pysam_17libcalignmentfile_AlignmentFile, /*tp_methods*/ 0, /*tp_members*/ __pyx_getsets_5pysam_17libcalignmentfile_AlignmentFile, /*tp_getset*/ @@ -30427,6 +36586,7 @@ static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(PyTypeObjec if (unlikely(!o)) return 0; p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)o); p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None); + p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None); return o; } @@ -30447,6 +36607,7 @@ static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow(PyObject *o) PyErr_Restore(etype, eval, etb); } Py_CLEAR(p->samfile); + Py_CLEAR(p->header); (*Py_TYPE(o)->tp_free)(o); } @@ -30456,6 +36617,9 @@ static int __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow(PyObject *o, if (p->samfile) { e = (*v)(((PyObject *)p->samfile), a); if (e) return e; } + if (p->header) { + e = (*v)(((PyObject *)p->header), a); if (e) return e; + } return 0; } @@ -30465,6 +36629,9 @@ static int __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow(PyObject *o) { tmp = ((PyObject*)p->samfile); p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); + tmp = ((PyObject*)p->header); + p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); return 0; } @@ -30594,7 +36761,7 @@ static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion = { 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "IteratorRowRegion(AlignmentFile samfile, int tid, int beg, int end, int multiple_iterators=False)\n*(AlignmentFile samfile, int tid, int beg, int end,\n int multiple_iterators=False)*\n\n iterate over mapped reads in a region.\n\n .. note::\n\n It is usually not necessary to create an object of this class\n explicitly. It is returned as a result of call to a\n :meth:`AlignmentFile.fetch`.\n\n ", /*tp_doc*/ + "IteratorRowRegion(AlignmentFile samfile, int tid, int beg, int stop, int multiple_iterators=False)\n*(AlignmentFile samfile, int tid, int beg, int stop,\n int multiple_iterators=False)*\n\n iterate over mapped reads in a region.\n\n .. note::\n\n It is usually not necessary to create an object of this class\n explicitly. It is returned as a result of call to a\n :meth:`AlignmentFile.fetch`.\n\n ", /*tp_doc*/ __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow, /*tp_traverse*/ __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow, /*tp_clear*/ 0, /*tp_richcompare*/ @@ -31007,7 +37174,7 @@ static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn(PyTypeOb p->__pyx_vtab = __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn; p->iter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None); p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None); - p->fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_Fastafile *)Py_None); Py_INCREF(Py_None); + p->fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)Py_None); Py_INCREF(Py_None); p->stepper = Py_None; Py_INCREF(Py_None); if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_1__cinit__(o, a, k) < 0)) goto bad; return o; @@ -31067,7 +37234,7 @@ static int __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn(PyObject *o) p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->fastafile); - p->fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_Fastafile *)Py_None); Py_INCREF(Py_None); + p->fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->stepper); p->stepper = Py_None; Py_INCREF(Py_None); @@ -31080,10 +37247,12 @@ static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_14IteratorColumn_seq_l } static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorColumn[] = { - {"addReference", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5addReference, METH_O, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_4addReference}, - {"hasReference", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7hasReference, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_6hasReference}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_10__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_12__setstate_cython__}, + {"add_reference", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5add_reference, METH_O, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference}, + {"has_reference", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7has_reference, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference}, + {"hasReference", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11hasReference, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference}, + {"addReference", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13addReference, METH_O, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_12addReference}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_15__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_17__setstate_cython__, METH_O, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__}, {0, 0, 0, 0} }; @@ -31118,7 +37287,7 @@ static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorColumn = { 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "abstract base class for iterators over columns.\n\n IteratorColumn objects wrap the pileup functionality of samtools.\n\n For reasons of efficiency, the iterator points to the current\n pileup buffer. The pileup buffer is updated at every iteration.\n This might cause some unexpected behavious. For example,\n consider the conversion to a list::\n\n f = AlignmentFile(\"file.bam\", \"rb\")\n result = list( f.pileup() )\n\n Here, ``result`` will contain ``n`` objects of type\n :class:`~pysam.PileupColumn` for ``n`` columns, but each object in\n ``result`` will contain the same information.\n\n The desired behaviour can be achieved by list comprehension::\n\n result = [ x.pileups() for x in f.pileup() ]\n\n ``result`` will be a list of ``n`` lists of objects of type\n :class:`~pysam.PileupRead`.\n\n If the iterator is associated with a :class:`~pysam.Fastafile` using the\n :meth:`addReference` method, then the iterator will export the\n current sequence via the methods :meth:`getSequence` and\n :meth:`seq_len`.\n\n Optional kwargs to the iterator:\n\n stepper\n The stepper controls how the iterator advances.\n\n Valid values are None, \"all\" (default), \"nofilter\" or \"samtools\".\n\n See AlignmentFile.pileup for description.\n \n fastafile\n A :class:`~pysam.FastaFile` object\n\n max_depth\n maximum read depth. The default is 8000.\n\n ", /*tp_doc*/ + "abstract base class for iterators over columns.\n\n IteratorColumn objects wrap the pileup functionality of samtools.\n\n For reasons of efficiency, the iterator points to the current\n pileup buffer. The pileup buffer is updated at every iteration.\n This might cause some unexpected behavious. For example,\n consider the conversion to a list::\n\n f = AlignmentFile(\"file.bam\", \"rb\")\n result = list(f.pileup())\n\n Here, ``result`` will contain ``n`` objects of type\n :class:`~pysam.PileupColumn` for ``n`` columns, but each object in\n ``result`` will contain the same information.\n\n The desired behaviour can be achieved by list comprehension::\n\n result = [x.pileups() for x in f.pileup()]\n\n ``result`` will be a list of ``n`` lists of objects of type\n :class:`~pysam.PileupRead`.\n\n If the iterator is associated with a :class:`~pysam.Fastafile`\n using the :meth:`add_reference` method, then the iterator will\n export the current sequence via the methods :meth:`get_sequence`\n and :meth:`seq_len`.\n\n See :class:`~AlignmentFile.pileup` for kwargs to the iterator.\n ", /*tp_doc*/ __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn, /*tp_traverse*/ __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn, /*tp_clear*/ 0, /*tp_richcompare*/ @@ -31328,6 +37497,7 @@ static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IndexedReads(PyTypeObje p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)o); p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None); p->index = Py_None; Py_INCREF(Py_None); + p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None); return o; } @@ -31349,6 +37519,7 @@ static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IndexedReads(PyObject *o } Py_CLEAR(p->samfile); Py_CLEAR(p->index); + Py_CLEAR(p->header); (*Py_TYPE(o)->tp_free)(o); } @@ -31361,6 +37532,9 @@ static int __pyx_tp_traverse_5pysam_17libcalignmentfile_IndexedReads(PyObject *o if (p->index) { e = (*v)(p->index, a); if (e) return e; } + if (p->header) { + e = (*v)(((PyObject *)p->header), a); if (e) return e; + } return 0; } @@ -31373,6 +37547,9 @@ static int __pyx_tp_clear_5pysam_17libcalignmentfile_IndexedReads(PyObject *o) { tmp = ((PyObject*)p->index); p->index = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); + tmp = ((PyObject*)p->header); + p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); return 0; } @@ -31612,11 +37789,14 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_AS, __pyx_k_AS, sizeof(__pyx_k_AS), 0, 0, 1, 1}, {&__pyx_n_s_AlignmentFile, __pyx_k_AlignmentFile, sizeof(__pyx_k_AlignmentFile), 0, 0, 1, 1}, {&__pyx_kp_s_AlignmentFile_mapped_only_availa, __pyx_k_AlignmentFile_mapped_only_availa, sizeof(__pyx_k_AlignmentFile_mapped_only_availa), 0, 0, 1, 0}, + {&__pyx_n_s_AlignmentHeader, __pyx_k_AlignmentHeader, sizeof(__pyx_k_AlignmentHeader), 0, 0, 1, 1}, + {&__pyx_kp_s_AlignmentHeader_does_not_support, __pyx_k_AlignmentHeader_does_not_support, sizeof(__pyx_k_AlignmentHeader_does_not_support), 0, 0, 1, 0}, {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1}, {&__pyx_n_s_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 1, 1}, {&__pyx_n_s_CL, __pyx_k_CL, sizeof(__pyx_k_CL), 0, 0, 1, 1}, {&__pyx_n_s_CN, __pyx_k_CN, sizeof(__pyx_k_CN), 0, 0, 1, 1}, {&__pyx_n_s_CO, __pyx_k_CO, sizeof(__pyx_k_CO), 0, 0, 1, 1}, + {&__pyx_kp_s_Cannot_add_extra_threads_when_ig, __pyx_k_Cannot_add_extra_threads_when_ig, sizeof(__pyx_k_Cannot_add_extra_threads_when_ig), 0, 0, 1, 0}, {&__pyx_n_s_Counter, __pyx_k_Counter, sizeof(__pyx_k_Counter), 0, 0, 1, 1}, {&__pyx_n_s_DS, __pyx_k_DS, sizeof(__pyx_k_DS), 0, 0, 1, 1}, {&__pyx_n_s_DT, __pyx_k_DT, sizeof(__pyx_k_DT), 0, 0, 1, 1}, @@ -31628,6 +37808,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 0, 0, 1, 1}, {&__pyx_kp_s_I_O_operation_on_closed_file, __pyx_k_I_O_operation_on_closed_file, sizeof(__pyx_k_I_O_operation_on_closed_file), 0, 0, 1, 0}, {&__pyx_kp_s_Incompatible_checksums_s_vs_0x50, __pyx_k_Incompatible_checksums_s_vs_0x50, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x50), 0, 0, 1, 0}, + {&__pyx_n_s_IndexStats, __pyx_k_IndexStats, sizeof(__pyx_k_IndexStats), 0, 0, 1, 1}, {&__pyx_n_s_IndexedReads, __pyx_k_IndexedReads, sizeof(__pyx_k_IndexedReads), 0, 0, 1, 1}, {&__pyx_n_s_IteratorColumn, __pyx_k_IteratorColumn, sizeof(__pyx_k_IteratorColumn), 0, 0, 1, 1}, {&__pyx_n_s_IteratorRow, __pyx_k_IteratorRow, sizeof(__pyx_k_IteratorRow), 0, 0, 1, 1}, @@ -31638,11 +37819,12 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_LB, __pyx_k_LB, sizeof(__pyx_k_LB), 0, 0, 1, 1}, {&__pyx_n_s_LN, __pyx_k_LN, sizeof(__pyx_k_LN), 0, 0, 1, 1}, {&__pyx_n_s_M5, __pyx_k_M5, sizeof(__pyx_k_M5), 0, 0, 1, 1}, + {&__pyx_n_s_Mapping, __pyx_k_Mapping, sizeof(__pyx_k_Mapping), 0, 0, 1, 1}, {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, {&__pyx_n_s_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 0, 1, 1}, {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1}, {&__pyx_n_s_OSError, __pyx_k_OSError, sizeof(__pyx_k_OSError), 0, 0, 1, 1}, - {&__pyx_n_s_OverflowError, __pyx_k_OverflowError, sizeof(__pyx_k_OverflowError), 0, 0, 1, 1}, + {&__pyx_n_s_OrderedDict, __pyx_k_OrderedDict, sizeof(__pyx_k_OrderedDict), 0, 0, 1, 1}, {&__pyx_n_s_PG, __pyx_k_PG, sizeof(__pyx_k_PG), 0, 0, 1, 1}, {&__pyx_n_s_PI, __pyx_k_PI, sizeof(__pyx_k_PI), 0, 0, 1, 1}, {&__pyx_n_s_PL, __pyx_k_PL, sizeof(__pyx_k_PL), 0, 0, 1, 1}, @@ -31652,12 +37834,15 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_PU, __pyx_k_PU, sizeof(__pyx_k_PU), 0, 0, 1, 1}, {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, {&__pyx_n_s_RG, __pyx_k_RG, sizeof(__pyx_k_RG), 0, 0, 1, 1}, + {&__pyx_kp_s_SAM_file_does_not_have_a_valid_h, __pyx_k_SAM_file_does_not_have_a_valid_h, sizeof(__pyx_k_SAM_file_does_not_have_a_valid_h), 0, 0, 1, 0}, {&__pyx_n_s_SM, __pyx_k_SM, sizeof(__pyx_k_SM), 0, 0, 1, 1}, {&__pyx_n_s_SN, __pyx_k_SN, sizeof(__pyx_k_SN), 0, 0, 1, 1}, {&__pyx_n_s_SO, __pyx_k_SO, sizeof(__pyx_k_SO), 0, 0, 1, 1}, {&__pyx_n_s_SP, __pyx_k_SP, sizeof(__pyx_k_SP), 0, 0, 1, 1}, - {&__pyx_n_s_SQ, __pyx_k_SQ, sizeof(__pyx_k_SQ), 0, 0, 1, 1}, - {&__pyx_kp_s_SQ_SN_s_LN_s, __pyx_k_SQ_SN_s_LN_s, sizeof(__pyx_k_SQ_SN_s_LN_s), 0, 0, 1, 0}, + {&__pyx_kp_s_SQ, __pyx_k_SQ, sizeof(__pyx_k_SQ), 0, 0, 1, 0}, + {&__pyx_n_s_SQ_2, __pyx_k_SQ_2, sizeof(__pyx_k_SQ_2), 0, 0, 1, 1}, + {&__pyx_kp_s_SQ_SN_LN, __pyx_k_SQ_SN_LN, sizeof(__pyx_k_SQ_SN_LN), 0, 0, 1, 0}, + {&__pyx_n_s_Sequence, __pyx_k_Sequence, sizeof(__pyx_k_Sequence), 0, 0, 1, 1}, {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1}, {&__pyx_n_s_StringIO, __pyx_k_StringIO, sizeof(__pyx_k_StringIO), 0, 0, 1, 1}, {&__pyx_n_s_T, __pyx_k_T, sizeof(__pyx_k_T), 0, 0, 1, 1}, @@ -31668,115 +37853,142 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_VALID_HEADER_TYPES, __pyx_k_VALID_HEADER_TYPES, sizeof(__pyx_k_VALID_HEADER_TYPES), 0, 0, 1, 1}, {&__pyx_n_s_VN, __pyx_k_VN, sizeof(__pyx_k_VN), 0, 0, 1, 1}, {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, - {&__pyx_kp_b__11, __pyx_k__11, sizeof(__pyx_k__11), 0, 0, 0, 0}, + {&__pyx_kp_s__10, __pyx_k__10, sizeof(__pyx_k__10), 0, 0, 1, 0}, {&__pyx_kp_s__12, __pyx_k__12, sizeof(__pyx_k__12), 0, 0, 1, 0}, - {&__pyx_kp_s__16, __pyx_k__16, sizeof(__pyx_k__16), 0, 0, 1, 0}, + {&__pyx_kp_s__14, __pyx_k__14, sizeof(__pyx_k__14), 0, 0, 1, 0}, {&__pyx_kp_s__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 1, 0}, - {&__pyx_kp_s__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 1, 0}, - {&__pyx_kp_s__35, __pyx_k__35, sizeof(__pyx_k__35), 0, 0, 1, 0}, - {&__pyx_kp_s__41, __pyx_k__41, sizeof(__pyx_k__41), 0, 0, 1, 0}, + {&__pyx_kp_b__32, __pyx_k__32, sizeof(__pyx_k__32), 0, 0, 0, 0}, + {&__pyx_kp_s__8, __pyx_k__8, sizeof(__pyx_k__8), 0, 0, 1, 0}, {&__pyx_kp_s_access_from_StringIO_objects_not, __pyx_k_access_from_StringIO_objects_not, sizeof(__pyx_k_access_from_StringIO_objects_not), 0, 0, 1, 0}, + {&__pyx_n_s_add_hts_options, __pyx_k_add_hts_options, sizeof(__pyx_k_add_hts_options), 0, 0, 1, 1}, + {&__pyx_n_s_add_reference, __pyx_k_add_reference, sizeof(__pyx_k_add_reference), 0, 0, 1, 1}, + {&__pyx_n_s_add_sam_header, __pyx_k_add_sam_header, sizeof(__pyx_k_add_sam_header), 0, 0, 1, 1}, {&__pyx_n_s_add_sq_text, __pyx_k_add_sq_text, sizeof(__pyx_k_add_sq_text), 0, 0, 1, 1}, + {&__pyx_n_s_adjust_capq_threshold, __pyx_k_adjust_capq_threshold, sizeof(__pyx_k_adjust_capq_threshold), 0, 0, 1, 1}, {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1}, {&__pyx_n_s_all_2, __pyx_k_all_2, sizeof(__pyx_k_all_2), 0, 0, 1, 1}, {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1}, {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1}, - {&__pyx_n_s_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1}, {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1}, - {&__pyx_kp_b_bai, __pyx_k_bai, sizeof(__pyx_k_bai), 0, 0, 0, 0}, {&__pyx_n_s_beg, __pyx_k_beg, sizeof(__pyx_k_beg), 0, 0, 1, 1}, {&__pyx_n_s_build_header_line, __pyx_k_build_header_line, sizeof(__pyx_k_build_header_line), 0, 0, 1, 1}, + {&__pyx_n_s_build_sequence_section, __pyx_k_build_sequence_section, sizeof(__pyx_k_build_sequence_section), 0, 0, 1, 1}, {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1}, {&__pyx_kp_s_can_not_iterate_over_samfile_wit, __pyx_k_can_not_iterate_over_samfile_wit, sizeof(__pyx_k_can_not_iterate_over_samfile_wit), 0, 0, 1, 0}, - {&__pyx_kp_s_can_only_IndexReads_on_bam_files, __pyx_k_can_only_IndexReads_on_bam_files, sizeof(__pyx_k_can_only_IndexReads_on_bam_files), 0, 0, 1, 0}, + {&__pyx_kp_s_can_only_apply_IndexReads_on_bam, __pyx_k_can_only_apply_IndexReads_on_bam, sizeof(__pyx_k_can_only_apply_IndexReads_on_bam), 0, 0, 1, 0}, + {&__pyx_kp_s_cannot_create_AlignmentHeader_re, __pyx_k_cannot_create_AlignmentHeader_re, sizeof(__pyx_k_cannot_create_AlignmentHeader_re), 0, 0, 1, 0}, {&__pyx_n_s_check_header, __pyx_k_check_header, sizeof(__pyx_k_check_header), 0, 0, 1, 1}, {&__pyx_n_s_check_index, __pyx_k_check_index, sizeof(__pyx_k_check_index), 0, 0, 1, 1}, {&__pyx_n_s_check_sq, __pyx_k_check_sq, sizeof(__pyx_k_check_sq), 0, 0, 1, 1}, + {&__pyx_n_s_check_truncation, __pyx_k_check_truncation, sizeof(__pyx_k_check_truncation), 0, 0, 1, 1}, {&__pyx_n_s_cigarstring, __pyx_k_cigarstring, sizeof(__pyx_k_cigarstring), 0, 0, 1, 1}, + {&__pyx_n_s_cigartuples, __pyx_k_cigartuples, sizeof(__pyx_k_cigartuples), 0, 0, 1, 1}, {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1}, {&__pyx_n_s_closed, __pyx_k_closed, sizeof(__pyx_k_closed), 0, 0, 1, 1}, {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1}, + {&__pyx_n_s_compute_baq, __pyx_k_compute_baq, sizeof(__pyx_k_compute_baq), 0, 0, 1, 1}, {&__pyx_n_s_consensus_quality, __pyx_k_consensus_quality, sizeof(__pyx_k_consensus_quality), 0, 0, 1, 1}, - {&__pyx_kp_s_could_not_open_file_mode_s_is_it, __pyx_k_could_not_open_file_mode_s_is_it, sizeof(__pyx_k_could_not_open_file_mode_s_is_it), 0, 0, 1, 0}, + {&__pyx_n_s_contains, __pyx_k_contains, sizeof(__pyx_k_contains), 0, 0, 1, 1}, + {&__pyx_n_s_contig, __pyx_k_contig, sizeof(__pyx_k_contig), 0, 0, 1, 1}, + {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1}, + {&__pyx_kp_s_could_not_allocate_bytes, __pyx_k_could_not_allocate_bytes, sizeof(__pyx_k_could_not_allocate_bytes), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_allocate_memory_of_siz, __pyx_k_could_not_allocate_memory_of_siz, sizeof(__pyx_k_could_not_allocate_memory_of_siz), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_create_header, __pyx_k_could_not_create_header, sizeof(__pyx_k_could_not_create_header), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_open_alignment_file, __pyx_k_could_not_open_alignment_file, sizeof(__pyx_k_could_not_open_alignment_file), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_open_alignment_file_2, __pyx_k_could_not_open_alignment_file_2, sizeof(__pyx_k_could_not_open_alignment_file_2), 0, 0, 1, 0}, {&__pyx_n_s_coverage, __pyx_k_coverage, sizeof(__pyx_k_coverage), 0, 0, 1, 1}, - {&__pyx_kp_b_crai, __pyx_k_crai, sizeof(__pyx_k_crai), 0, 0, 0, 0}, - {&__pyx_kp_b_csi, __pyx_k_csi, sizeof(__pyx_k_csi), 0, 0, 0, 0}, {&__pyx_n_s_defaultdict, __pyx_k_defaultdict, sizeof(__pyx_k_defaultdict), 0, 0, 1, 1}, {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, {&__pyx_n_s_duplicate_filehandle, __pyx_k_duplicate_filehandle, sizeof(__pyx_k_duplicate_filehandle), 0, 0, 1, 1}, {&__pyx_kp_s_either_supply_options_template_h, __pyx_k_either_supply_options_template_h, sizeof(__pyx_k_either_supply_options_template_h), 0, 0, 1, 0}, - {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1}, - {&__pyx_kp_s_end_out_of_range_i, __pyx_k_end_out_of_range_i, sizeof(__pyx_k_end_out_of_range_i), 0, 0, 1, 0}, {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1}, {&__pyx_kp_s_error_during_iteration, __pyx_k_error_during_iteration, sizeof(__pyx_k_error_during_iteration), 0, 0, 1, 0}, - {&__pyx_kp_s_error_while_opening_index_for_s, __pyx_k_error_while_opening_index_for_s, sizeof(__pyx_k_error_while_opening_index_for_s), 0, 0, 1, 0}, + {&__pyx_kp_s_error_while_reading_file, __pyx_k_error_while_reading_file, sizeof(__pyx_k_error_while_reading_file), 0, 0, 1, 0}, {&__pyx_n_s_exc_type, __pyx_k_exc_type, sizeof(__pyx_k_exc_type), 0, 0, 1, 1}, {&__pyx_n_s_exc_value, __pyx_k_exc_value, sizeof(__pyx_k_exc_value), 0, 0, 1, 1}, - {&__pyx_n_s_exists, __pyx_k_exists, sizeof(__pyx_k_exists), 0, 0, 1, 1}, - {&__pyx_n_s_exists_2, __pyx_k_exists_2, sizeof(__pyx_k_exists_2), 0, 0, 1, 1}, {&__pyx_n_s_fastafile, __pyx_k_fastafile, sizeof(__pyx_k_fastafile), 0, 0, 1, 1}, {&__pyx_n_s_fetch, __pyx_k_fetch, sizeof(__pyx_k_fetch), 0, 0, 1, 1}, - {&__pyx_kp_s_fetch_called_for_htsfile_without, __pyx_k_fetch_called_for_htsfile_without, sizeof(__pyx_k_fetch_called_for_htsfile_without), 0, 0, 1, 0}, {&__pyx_kp_s_fetch_called_on_bamfile_without, __pyx_k_fetch_called_on_bamfile_without, sizeof(__pyx_k_fetch_called_on_bamfile_without), 0, 0, 1, 0}, {&__pyx_kp_s_fetching_by_region_is_not_availa, __pyx_k_fetching_by_region_is_not_availa, sizeof(__pyx_k_fetching_by_region_is_not_availa), 0, 0, 1, 0}, {&__pyx_n_s_fields, __pyx_k_fields, sizeof(__pyx_k_fields), 0, 0, 1, 1}, {&__pyx_kp_s_file_does_not_contain_alignment, __pyx_k_file_does_not_contain_alignment, sizeof(__pyx_k_file_does_not_contain_alignment), 0, 0, 1, 0}, - {&__pyx_kp_s_file_does_not_have_valid_header, __pyx_k_file_does_not_have_valid_header, sizeof(__pyx_k_file_does_not_have_valid_header), 0, 0, 1, 0}, - {&__pyx_kp_s_file_does_not_have_valid_header_2, __pyx_k_file_does_not_have_valid_header_2, sizeof(__pyx_k_file_does_not_have_valid_header_2), 0, 0, 1, 0}, + {&__pyx_kp_s_file_does_not_have_a_valid_heade, __pyx_k_file_does_not_have_a_valid_heade, sizeof(__pyx_k_file_does_not_have_a_valid_heade), 0, 0, 1, 0}, {&__pyx_kp_s_file_has_no_sequences_defined_mo, __pyx_k_file_has_no_sequences_defined_mo, sizeof(__pyx_k_file_has_no_sequences_defined_mo), 0, 0, 1, 0}, - {&__pyx_kp_s_file_s_not_found, __pyx_k_file_s_not_found, sizeof(__pyx_k_file_s_not_found), 0, 0, 1, 0}, {&__pyx_n_s_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 0, 1, 1}, {&__pyx_n_s_fileno, __pyx_k_fileno, sizeof(__pyx_k_fileno), 0, 0, 1, 1}, {&__pyx_n_s_filepath_index, __pyx_k_filepath_index, sizeof(__pyx_k_filepath_index), 0, 0, 1, 1}, {&__pyx_n_s_filepath_or_object, __pyx_k_filepath_or_object, sizeof(__pyx_k_filepath_or_object), 0, 0, 1, 1}, {&__pyx_n_s_flag, __pyx_k_flag, sizeof(__pyx_k_flag), 0, 0, 1, 1}, + {&__pyx_n_s_flag_filter, __pyx_k_flag_filter, sizeof(__pyx_k_flag_filter), 0, 0, 1, 1}, + {&__pyx_n_s_flag_require, __pyx_k_flag_require, sizeof(__pyx_k_flag_require), 0, 0, 1, 1}, {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1}, + {&__pyx_n_s_format_options, __pyx_k_format_options, sizeof(__pyx_k_format_options), 0, 0, 1, 1}, + {&__pyx_n_s_from_dict, __pyx_k_from_dict, sizeof(__pyx_k_from_dict), 0, 0, 1, 1}, + {&__pyx_n_s_from_references, __pyx_k_from_references, sizeof(__pyx_k_from_references), 0, 0, 1, 1}, + {&__pyx_n_s_from_text, __pyx_k_from_text, sizeof(__pyx_k_from_text), 0, 0, 1, 1}, + {&__pyx_n_s_from_text_and_lengths, __pyx_k_from_text_and_lengths, sizeof(__pyx_k_from_text_and_lengths), 0, 0, 1, 1}, {&__pyx_n_s_genotype, __pyx_k_genotype, sizeof(__pyx_k_genotype), 0, 0, 1, 1}, {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1}, {&__pyx_n_s_get_aligned_pairs, __pyx_k_get_aligned_pairs, sizeof(__pyx_k_get_aligned_pairs), 0, 0, 1, 1}, + {&__pyx_n_s_get_reference_length, __pyx_k_get_reference_length, sizeof(__pyx_k_get_reference_length), 0, 0, 1, 1}, {&__pyx_n_s_get_reference_name, __pyx_k_get_reference_name, sizeof(__pyx_k_get_reference_name), 0, 0, 1, 1}, {&__pyx_n_s_get_tid, __pyx_k_get_tid, sizeof(__pyx_k_get_tid), 0, 0, 1, 1}, + {&__pyx_n_s_getitem, __pyx_k_getitem, sizeof(__pyx_k_getitem), 0, 0, 1, 1}, {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, - {&__pyx_n_s_gettid, __pyx_k_gettid, sizeof(__pyx_k_gettid), 0, 0, 1, 1}, {&__pyx_n_s_h, __pyx_k_h, sizeof(__pyx_k_h), 0, 0, 1, 1}, {&__pyx_n_s_has_index, __pyx_k_has_index, sizeof(__pyx_k_has_index), 0, 0, 1, 1}, + {&__pyx_n_s_has_reference, __pyx_k_has_reference, sizeof(__pyx_k_has_reference), 0, 0, 1, 1}, {&__pyx_n_s_header, __pyx_k_header, sizeof(__pyx_k_header), 0, 0, 1, 1}, {&__pyx_kp_s_header_line_with_invalid_type_s, __pyx_k_header_line_with_invalid_type_s, sizeof(__pyx_k_header_line_with_invalid_type_s), 0, 0, 1, 0}, {&__pyx_kp_s_header_line_without_s, __pyx_k_header_line_without_s, sizeof(__pyx_k_header_line_without_s), 0, 0, 1, 0}, + {&__pyx_kp_s_header_not_available_in_closed_f, __pyx_k_header_not_available_in_closed_f, sizeof(__pyx_k_header_not_available_in_closed_f), 0, 0, 1, 0}, + {&__pyx_n_s_ignore_orphans, __pyx_k_ignore_orphans, sizeof(__pyx_k_ignore_orphans), 0, 0, 1, 1}, + {&__pyx_n_s_ignore_overlaps, __pyx_k_ignore_overlaps, sizeof(__pyx_k_ignore_overlaps), 0, 0, 1, 1}, + {&__pyx_n_s_ignore_truncation, __pyx_k_ignore_truncation, sizeof(__pyx_k_ignore_truncation), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_kp_s_incomplete_sequence_information, __pyx_k_incomplete_sequence_information, sizeof(__pyx_k_incomplete_sequence_information), 0, 0, 1, 0}, + {&__pyx_n_s_index_filename, __pyx_k_index_filename, sizeof(__pyx_k_index_filename), 0, 0, 1, 1}, {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1}, - {&__pyx_kp_s_invalid_coordinates_start_i_end, __pyx_k_invalid_coordinates_start_i_end, sizeof(__pyx_k_invalid_coordinates_start_i_end), 0, 0, 1, 0}, + {&__pyx_kp_s_interval_of_size_0, __pyx_k_interval_of_size_0, sizeof(__pyx_k_interval_of_size_0), 0, 0, 1, 0}, + {&__pyx_kp_s_interval_of_size_less_than_0, __pyx_k_interval_of_size_less_than_0, sizeof(__pyx_k_interval_of_size_less_than_0), 0, 0, 1, 0}, {&__pyx_kp_s_invalid_file_opening_mode_s, __pyx_k_invalid_file_opening_mode_s, sizeof(__pyx_k_invalid_file_opening_mode_s), 0, 0, 1, 0}, - {&__pyx_kp_s_invalid_reference_s, __pyx_k_invalid_reference_s, sizeof(__pyx_k_invalid_reference_s), 0, 0, 1, 0}, {&__pyx_kp_s_invalid_type_for_record_s_s_expe, __pyx_k_invalid_type_for_record_s_s_expe, sizeof(__pyx_k_invalid_type_for_record_s_s_expe), 0, 0, 1, 0}, {&__pyx_n_s_io, __pyx_k_io, sizeof(__pyx_k_io), 0, 0, 1, 1}, {&__pyx_n_s_is_bam, __pyx_k_is_bam, sizeof(__pyx_k_is_bam), 0, 0, 1, 1}, {&__pyx_n_s_is_cram, __pyx_k_is_cram, sizeof(__pyx_k_is_cram), 0, 0, 1, 1}, {&__pyx_n_s_is_open, __pyx_k_is_open, sizeof(__pyx_k_is_open), 0, 0, 1, 1}, + {&__pyx_n_s_is_valid_tid, __pyx_k_is_valid_tid, sizeof(__pyx_k_is_valid_tid), 0, 0, 1, 1}, {&__pyx_n_s_islower, __pyx_k_islower, sizeof(__pyx_k_islower), 0, 0, 1, 1}, {&__pyx_n_s_isupper, __pyx_k_isupper, sizeof(__pyx_k_isupper), 0, 0, 1, 1}, {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1}, {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1}, {&__pyx_n_s_key, __pyx_k_key, sizeof(__pyx_k_key), 0, 0, 1, 1}, + {&__pyx_n_s_keys, __pyx_k_keys, sizeof(__pyx_k_keys), 0, 0, 1, 1}, + {&__pyx_n_s_len, __pyx_k_len, sizeof(__pyx_k_len), 0, 0, 1, 1}, {&__pyx_n_s_lengths, __pyx_k_lengths, sizeof(__pyx_k_lengths), 0, 0, 1, 1}, {&__pyx_n_s_line, __pyx_k_line, sizeof(__pyx_k_line), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_make, __pyx_k_make, sizeof(__pyx_k_make), 0, 0, 1, 1}, {&__pyx_kp_s_malformatted_header_no_in_field, __pyx_k_malformatted_header_no_in_field, sizeof(__pyx_k_malformatted_header_no_in_field), 0, 0, 1, 0}, {&__pyx_n_s_map, __pyx_k_map, sizeof(__pyx_k_map), 0, 0, 1, 1}, + {&__pyx_n_s_mapped, __pyx_k_mapped, sizeof(__pyx_k_mapped), 0, 0, 1, 1}, {&__pyx_kp_s_mapping_information_not_recorded, __pyx_k_mapping_information_not_recorded, sizeof(__pyx_k_mapping_information_not_recorded), 0, 0, 1, 0}, {&__pyx_n_s_mapping_quality, __pyx_k_mapping_quality, sizeof(__pyx_k_mapping_quality), 0, 0, 1, 1}, {&__pyx_kp_s_mate_not_found, __pyx_k_mate_not_found, sizeof(__pyx_k_mate_not_found), 0, 0, 1, 0}, {&__pyx_kp_s_mate_s_is_unmapped, __pyx_k_mate_s_is_unmapped, sizeof(__pyx_k_mate_s_is_unmapped), 0, 0, 1, 0}, {&__pyx_n_s_max_depth, __pyx_k_max_depth, sizeof(__pyx_k_max_depth), 0, 0, 1, 1}, + {&__pyx_n_s_min_base_quality, __pyx_k_min_base_quality, sizeof(__pyx_k_min_base_quality), 0, 0, 1, 1}, + {&__pyx_n_s_min_mapping_quality, __pyx_k_min_mapping_quality, sizeof(__pyx_k_min_mapping_quality), 0, 0, 1, 1}, {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1}, {&__pyx_n_s_multiple_iterators, __pyx_k_multiple_iterators, sizeof(__pyx_k_multiple_iterators), 0, 0, 1, 1}, + {&__pyx_kp_s_multiple_iterators_not_implement, __pyx_k_multiple_iterators_not_implement, sizeof(__pyx_k_multiple_iterators_not_implement), 0, 0, 1, 0}, {&__pyx_kp_s_multiple_s_lines_are_not_permitt, __pyx_k_multiple_s_lines_are_not_permitt, sizeof(__pyx_k_multiple_s_lines_are_not_permitt), 0, 0, 1, 0}, {&__pyx_n_s_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 0, 1, 1}, {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1}, + {&__pyx_n_s_namedtuple, __pyx_k_namedtuple, sizeof(__pyx_k_namedtuple), 0, 0, 1, 1}, {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1}, {&__pyx_n_s_nextiter, __pyx_k_nextiter, sizeof(__pyx_k_nextiter), 0, 0, 1, 1}, {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0}, @@ -31784,11 +37996,12 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_no_index_available_for_iteration, __pyx_k_no_index_available_for_iteration, sizeof(__pyx_k_no_index_available_for_iteration), 0, 0, 1, 0}, {&__pyx_kp_s_no_index_available_for_pileup, __pyx_k_no_index_available_for_pileup, sizeof(__pyx_k_no_index_available_for_pileup), 0, 0, 1, 0}, {&__pyx_n_s_nofilter, __pyx_k_nofilter, sizeof(__pyx_k_nofilter), 0, 0, 1, 1}, + {&__pyx_kp_s_not_enough_information_to_constr, __pyx_k_not_enough_information_to_constr, sizeof(__pyx_k_not_enough_information_to_constr), 0, 0, 1, 0}, {&__pyx_n_s_nreferences, __pyx_k_nreferences, sizeof(__pyx_k_nreferences), 0, 0, 1, 1}, + {&__pyx_kp_s_number_of_reference_names_and_le, __pyx_k_number_of_reference_names_and_le, sizeof(__pyx_k_number_of_reference_names_and_le), 0, 0, 1, 0}, {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1}, {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1}, {&__pyx_n_s_parse_region, __pyx_k_parse_region, sizeof(__pyx_k_parse_region), 0, 0, 1, 1}, - {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1}, {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, {&__pyx_kp_s_pileup_of_samfiles_not_implement, __pyx_k_pileup_of_samfiles_not_implement, sizeof(__pyx_k_pileup_of_samfiles_not_implement), 0, 0, 1, 0}, {&__pyx_n_s_port, __pyx_k_port, sizeof(__pyx_k_port), 0, 0, 1, 1}, @@ -31808,6 +38021,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_query_qualities, __pyx_k_query_qualities, sizeof(__pyx_k_query_qualities), 0, 0, 1, 1}, {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1}, {&__pyx_n_s_rU, __pyx_k_rU, sizeof(__pyx_k_rU), 0, 0, 1, 1}, + {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, {&__pyx_n_s_rb, __pyx_k_rb, sizeof(__pyx_k_rb), 0, 0, 1, 1}, {&__pyx_n_s_rc, __pyx_k_rc, sizeof(__pyx_k_rc), 0, 0, 1, 1}, {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1}, @@ -31815,6 +38029,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_read_s_is_unpaired, __pyx_k_read_s_is_unpaired, sizeof(__pyx_k_read_s_is_unpaired), 0, 0, 1, 0}, {&__pyx_kp_s_read_s_not_found, __pyx_k_read_s_not_found, sizeof(__pyx_k_read_s_not_found), 0, 0, 1, 0}, {&__pyx_n_s_record, __pyx_k_record, sizeof(__pyx_k_record), 0, 0, 1, 1}, + {&__pyx_n_s_redo_baq, __pyx_k_redo_baq, sizeof(__pyx_k_redo_baq), 0, 0, 1, 1}, {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, @@ -31824,46 +38039,56 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_reference_id_i_out_of_range_0_ti, __pyx_k_reference_id_i_out_of_range_0_ti, sizeof(__pyx_k_reference_id_i_out_of_range_0_ti), 0, 0, 1, 0}, {&__pyx_n_s_reference_lengths, __pyx_k_reference_lengths, sizeof(__pyx_k_reference_lengths), 0, 0, 1, 1}, {&__pyx_n_s_reference_names, __pyx_k_reference_names, sizeof(__pyx_k_reference_names), 0, 0, 1, 1}, - {&__pyx_kp_s_reference_sequence_for_s_tid_i_n, __pyx_k_reference_sequence_for_s_tid_i_n, sizeof(__pyx_k_reference_sequence_for_s_tid_i_n), 0, 0, 1, 0}, + {&__pyx_kp_s_reference_sequence_for_tid_not_f, __pyx_k_reference_sequence_for_tid_not_f, sizeof(__pyx_k_reference_sequence_for_tid_not_f), 0, 0, 1, 0}, {&__pyx_n_s_referencelengths, __pyx_k_referencelengths, sizeof(__pyx_k_referencelengths), 0, 0, 1, 1}, {&__pyx_n_s_referencenames, __pyx_k_referencenames, sizeof(__pyx_k_referencenames), 0, 0, 1, 1}, {&__pyx_n_s_references, __pyx_k_references, sizeof(__pyx_k_references), 0, 0, 1, 1}, {&__pyx_n_s_region, __pyx_k_region, sizeof(__pyx_k_region), 0, 0, 1, 1}, + {&__pyx_n_s_require_index, __pyx_k_require_index, sizeof(__pyx_k_require_index), 0, 0, 1, 1}, {&__pyx_kp_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 0}, {&__pyx_kp_s_s_s, __pyx_k_s_s, sizeof(__pyx_k_s_s), 0, 0, 1, 0}, {&__pyx_kp_s_sam_write1_failed_with_error_cod, __pyx_k_sam_write1_failed_with_error_cod, sizeof(__pyx_k_sam_write1_failed_with_error_cod), 0, 0, 1, 0}, {&__pyx_n_s_samfile, __pyx_k_samfile, sizeof(__pyx_k_samfile), 0, 0, 1, 1}, {&__pyx_n_s_samtools, __pyx_k_samtools, sizeof(__pyx_k_samtools), 0, 0, 1, 1}, - {&__pyx_kp_s_self_b_self_header_self_htsfile, __pyx_k_self_b_self_header_self_htsfile, sizeof(__pyx_k_self_b_self_header_self_htsfile), 0, 0, 1, 0}, - {&__pyx_kp_s_self_b_self_header_self_htsfile_2, __pyx_k_self_b_self_header_self_htsfile_2, sizeof(__pyx_k_self_b_self_header_self_htsfile_2), 0, 0, 1, 0}, - {&__pyx_kp_s_self_header_self_htsfile_cannot, __pyx_k_self_header_self_htsfile_cannot, sizeof(__pyx_k_self_header_self_htsfile_cannot), 0, 0, 1, 0}, + {&__pyx_kp_s_self_b_self_htsfile_self_index_c, __pyx_k_self_b_self_htsfile_self_index_c, sizeof(__pyx_k_self_b_self_htsfile_self_index_c), 0, 0, 1, 0}, + {&__pyx_kp_s_self_b_self_htsfile_self_index_s, __pyx_k_self_b_self_htsfile_self_index_s, sizeof(__pyx_k_self_b_self_htsfile_self_index_s), 0, 0, 1, 0}, + {&__pyx_kp_s_self_htsfile_cannot_be_converted, __pyx_k_self_htsfile_cannot_be_converted, sizeof(__pyx_k_self_htsfile_cannot_be_converted), 0, 0, 1, 0}, {&__pyx_n_s_seq, __pyx_k_seq, sizeof(__pyx_k_seq), 0, 0, 1, 1}, {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, {&__pyx_n_s_snp_quality, __pyx_k_snp_quality, sizeof(__pyx_k_snp_quality), 0, 0, 1, 1}, {&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1}, + {&__pyx_n_s_splitlines, __pyx_k_splitlines, sizeof(__pyx_k_splitlines), 0, 0, 1, 1}, {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1}, - {&__pyx_kp_s_start_out_of_range_i, __pyx_k_start_out_of_range_i, sizeof(__pyx_k_start_out_of_range_i), 0, 0, 1, 0}, {&__pyx_n_s_startswith, __pyx_k_startswith, sizeof(__pyx_k_startswith), 0, 0, 1, 1}, {&__pyx_n_s_stepper, __pyx_k_stepper, sizeof(__pyx_k_stepper), 0, 0, 1, 1}, + {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1}, + {&__pyx_n_s_str, __pyx_k_str, sizeof(__pyx_k_str), 0, 0, 1, 1}, {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, {&__pyx_n_s_strip, __pyx_k_strip, sizeof(__pyx_k_strip), 0, 0, 1, 1}, + {&__pyx_n_s_sum, __pyx_k_sum, sizeof(__pyx_k_sum), 0, 0, 1, 1}, {&__pyx_n_s_tell, __pyx_k_tell, sizeof(__pyx_k_tell), 0, 0, 1, 1}, {&__pyx_n_s_template, __pyx_k_template, sizeof(__pyx_k_template), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_n_s_text, __pyx_k_text, sizeof(__pyx_k_text), 0, 0, 1, 1}, + {&__pyx_n_s_threads, __pyx_k_threads, sizeof(__pyx_k_threads), 0, 0, 1, 1}, {&__pyx_n_s_tid, __pyx_k_tid, sizeof(__pyx_k_tid), 0, 0, 1, 1}, + {&__pyx_n_s_to_dict, __pyx_k_to_dict, sizeof(__pyx_k_to_dict), 0, 0, 1, 1}, + {&__pyx_n_s_total, __pyx_k_total, sizeof(__pyx_k_total), 0, 0, 1, 1}, {&__pyx_n_s_traceback, __pyx_k_traceback, sizeof(__pyx_k_traceback), 0, 0, 1, 1}, {&__pyx_n_s_truncate, __pyx_k_truncate, sizeof(__pyx_k_truncate), 0, 0, 1, 1}, {&__pyx_kp_s_truncated_file, __pyx_k_truncated_file, sizeof(__pyx_k_truncated_file), 0, 0, 1, 0}, - {&__pyx_kp_s_unable_to_open_index_at_s, __pyx_k_unable_to_open_index_at_s, sizeof(__pyx_k_unable_to_open_index_at_s), 0, 0, 1, 0}, - {&__pyx_kp_s_unable_to_open_remote_index_for, __pyx_k_unable_to_open_remote_index_for, sizeof(__pyx_k_unable_to_open_remote_index_for), 0, 0, 1, 0}, - {&__pyx_kp_s_unequal_names_and_lengths_of_ref, __pyx_k_unequal_names_and_lengths_of_ref, sizeof(__pyx_k_unequal_names_and_lengths_of_ref), 0, 0, 1, 0}, + {&__pyx_kp_s_unable_to_open_index_file, __pyx_k_unable_to_open_index_file, sizeof(__pyx_k_unable_to_open_index_file), 0, 0, 1, 0}, + {&__pyx_kp_s_unable_to_open_index_file_s, __pyx_k_unable_to_open_index_file_s, sizeof(__pyx_k_unable_to_open_index_file_s), 0, 0, 1, 0}, + {&__pyx_kp_s_unable_to_read_header_informatio, __pyx_k_unable_to_read_header_informatio, sizeof(__pyx_k_unable_to_read_header_informatio), 0, 0, 1, 0}, + {&__pyx_kp_s_unable_to_reopen_htsfile, __pyx_k_unable_to_reopen_htsfile, sizeof(__pyx_k_unable_to_reopen_htsfile), 0, 0, 1, 0}, + {&__pyx_kp_s_unknown_reference, __pyx_k_unknown_reference, sizeof(__pyx_k_unknown_reference), 0, 0, 1, 0}, {&__pyx_kp_s_unknown_stepper_option_s_in_Iter, __pyx_k_unknown_stepper_option_s_in_Iter, sizeof(__pyx_k_unknown_stepper_option_s_in_Iter), 0, 0, 1, 0}, + {&__pyx_n_s_unmapped, __pyx_k_unmapped, sizeof(__pyx_k_unmapped), 0, 0, 1, 1}, {&__pyx_n_s_until_eof, __pyx_k_until_eof, sizeof(__pyx_k_until_eof), 0, 0, 1, 1}, {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, + {&__pyx_n_s_values, __pyx_k_values, sizeof(__pyx_k_values), 0, 0, 1, 1}, {&__pyx_n_s_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 0, 1, 1}, - {&__pyx_n_s_warn, __pyx_k_warn, sizeof(__pyx_k_warn), 0, 0, 1, 1}, {&__pyx_n_s_warnings, __pyx_k_warnings, sizeof(__pyx_k_warnings), 0, 0, 1, 1}, {&__pyx_n_s_wb, __pyx_k_wb, sizeof(__pyx_k_wb), 0, 0, 1, 1}, {&__pyx_n_s_wb0, __pyx_k_wb0, sizeof(__pyx_k_wb0), 0, 0, 1, 1}, @@ -31871,23 +38096,25 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_wc, __pyx_k_wc, sizeof(__pyx_k_wc), 0, 0, 1, 1}, {&__pyx_n_s_wh, __pyx_k_wh, sizeof(__pyx_k_wh), 0, 0, 1, 1}, {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1}, + {&__pyx_kp_s_wrong_sequence_information_in_s, __pyx_k_wrong_sequence_information_in_s, sizeof(__pyx_k_wrong_sequence_information_in_s), 0, 0, 1, 0}, {&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 171, __pyx_L1_error) - __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 203, __pyx_L1_error) - __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 377, __pyx_L1_error) - __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 435, __pyx_L1_error) - __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 544, __pyx_L1_error) - __pyx_builtin_OverflowError = __Pyx_GetBuiltinName(__pyx_n_s_OverflowError); if (!__pyx_builtin_OverflowError) __PYX_ERR(0, 720, __pyx_L1_error) - __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 1301, __pyx_L1_error) - __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 1520, __pyx_L1_error) - __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 1559, __pyx_L1_error) - __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 1600, __pyx_L1_error) - __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) - __pyx_builtin_map = __Pyx_GetBuiltinName(__pyx_n_s_map); if (!__pyx_builtin_map) __PYX_ERR(0, 2373, __pyx_L1_error) - __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(3, 109, __pyx_L1_error) + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 163, __pyx_L1_error) + __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 222, __pyx_L1_error) + __pyx_builtin_sum = __Pyx_GetBuiltinName(__pyx_n_s_sum); if (!__pyx_builtin_sum) __PYX_ERR(0, 246, __pyx_L1_error) + __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 275, __pyx_L1_error) + __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 331, __pyx_L1_error) + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 359, __pyx_L1_error) + __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 437, __pyx_L1_error) + __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 537, __pyx_L1_error) + __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 762, __pyx_L1_error) + __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 840, __pyx_L1_error) + __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 907, __pyx_L1_error) + __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 1857, __pyx_L1_error) + __pyx_builtin_map = __Pyx_GetBuiltinName(__pyx_n_s_map); if (!__pyx_builtin_map) __PYX_ERR(0, 2737, __pyx_L1_error) + __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 2788, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; @@ -31897,426 +38124,561 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "pysam/libcalignmentfile.pyx":193 - * dest.text = calloc(len(text), sizeof(char)) - * dest.l_text = len(text) - * cdef bytes btext = text.encode('ascii') # <<<<<<<<<<<<<< - * strncpy(dest.text, btext, dest.l_text) + /* "pysam/libcalignmentfile.pyx":163 + * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr): + * if not hdr: + * raise ValueError('cannot create AlignmentHeader, received NULL pointer') # <<<<<<<<<<<<<< + * + * # check: is AlignmetHeader.__cinit__ called? + */ + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_cannot_create_AlignmentHeader_re); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 163, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); + + /* "pysam/libcalignmentfile.pyx":222 + * self.ptr = bam_hdr_init() + * if self.ptr is NULL: + * raise MemoryError("could not create header") # <<<<<<<<<<<<<< * + * @classmethod */ - __pyx_tuple__4 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 193, __pyx_L1_error) + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_could_not_create_header); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 222, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__4); __Pyx_GIVEREF(__pyx_tuple__4); - /* "pysam/libcalignmentfile.pyx":214 - * dest.target_name[x] = calloc( - * len(seqname) + 1, sizeof(char)) - * bseqname = seqname.encode('ascii') # <<<<<<<<<<<<<< - * strncpy(dest.target_name[x], bseqname, - * len(seqname) + 1) + /* "pysam/libcalignmentfile.pyx":270 + * reference_names, reference_lengths = [], [] + * for line in text.splitlines(): + * if line.startswith("@SQ"): # <<<<<<<<<<<<<< + * fields = dict([x.split(":", 1) for x in line.split("\t")[1:]]) + * try: */ - __pyx_tuple__5 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 214, __pyx_L1_error) + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_SQ); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__5); __Pyx_GIVEREF(__pyx_tuple__5); - /* "pysam/libcalignmentfile.pyx":375 + /* "pysam/libcalignmentfile.pyx":271 + * for line in text.splitlines(): + * if line.startswith("@SQ"): + * fields = dict([x.split(":", 1) for x in line.split("\t")[1:]]) # <<<<<<<<<<<<<< + * try: + * reference_names.append(fields["SN"]) + */ + __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s__2); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); + __pyx_slice__7 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__7)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__7); + __Pyx_GIVEREF(__pyx_slice__7); + __pyx_tuple__9 = PyTuple_Pack(2, __pyx_kp_s__8, __pyx_int_1); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__9); + __Pyx_GIVEREF(__pyx_tuple__9); + + /* "pysam/libcalignmentfile.pyx":327 + * + * if len(reference_names) != len(reference_lengths): + * raise ValueError("number of reference names and lengths do not match") # <<<<<<<<<<<<<< + * + * # optionally, if there is no text, add a SAM compatible header to output file. + */ + __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_number_of_reference_names_and_le); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 327, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__11); + __Pyx_GIVEREF(__pyx_tuple__11); + + /* "pysam/libcalignmentfile.pyx":418 + * # convert to python string + * t = self.__str__() + * for line in t.split("\n"): # <<<<<<<<<<<<<< + * if not line.strip(): + * continue + */ + __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s__10); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 418, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__13); + __Pyx_GIVEREF(__pyx_tuple__13); + + /* "pysam/libcalignmentfile.pyx":421 + * if not line.strip(): + * continue + * assert line.startswith("@"), \ # <<<<<<<<<<<<<< + * "header line without '@': '%s'" % line + * fields = line[1:].split("\t") + */ + __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s__14); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 421, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__15); + __Pyx_GIVEREF(__pyx_tuple__15); + + /* "pysam/libcalignmentfile.pyx":423 + * assert line.startswith("@"), \ + * "header line without '@': '%s'" % line + * fields = line[1:].split("\t") # <<<<<<<<<<<<<< + * record = fields[0] + * assert record in VALID_HEADER_TYPES, \ + */ + __pyx_slice__16 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__16)) __PYX_ERR(0, 423, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__16); + __Pyx_GIVEREF(__pyx_slice__16); + __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s__2); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 423, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__17); + __Pyx_GIVEREF(__pyx_tuple__17); + + /* "pysam/libcalignmentfile.pyx":432 + * if record not in result: + * result[record] = [] + * result[record].append("\t".join( fields[1:])) # <<<<<<<<<<<<<< + * continue + * # the following is clumsy as generators do not work? + */ + __pyx_slice__18 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__18)) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__18); + __Pyx_GIVEREF(__pyx_slice__18); + + /* "pysam/libcalignmentfile.pyx":437 + * x = {} + * + * for idx, field in enumerate(fields[1:]): # <<<<<<<<<<<<<< + * if ":" not in field: + * raise ValueError("malformatted header: no ':' in field" ) + */ + __pyx_slice__19 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__19)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__19); + __Pyx_GIVEREF(__pyx_slice__19); + + /* "pysam/libcalignmentfile.pyx":439 + * for idx, field in enumerate(fields[1:]): + * if ":" not in field: + * raise ValueError("malformatted header: no ':' in field" ) # <<<<<<<<<<<<<< + * key, value = field.split(":", 1) + * if key in ("CL",): + */ + __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_malformatted_header_no_in_field); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__20); + __Pyx_GIVEREF(__pyx_tuple__20); + + /* "pysam/libcalignmentfile.pyx":440 + * if ":" not in field: + * raise ValueError("malformatted header: no ':' in field" ) + * key, value = field.split(":", 1) # <<<<<<<<<<<<<< + * if key in ("CL",): + * # special treatment for command line + */ + __pyx_tuple__21 = PyTuple_Pack(2, __pyx_kp_s__8, __pyx_int_1); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__21); + __Pyx_GIVEREF(__pyx_tuple__21); + + /* "pysam/libcalignmentfile.pyx":448 + * # header. Thus, in contravention to the + * # SAM API, consume the rest of the line. + * key, value = "\t".join(fields[idx+1:]).split(":", 1) # <<<<<<<<<<<<<< + * x[key] = KNOWN_HEADER_FIELDS[record][key](value) + * break + */ + __pyx_tuple__22 = PyTuple_Pack(2, __pyx_kp_s__8, __pyx_int_1); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__22); + __Pyx_GIVEREF(__pyx_tuple__22); + + /* "pysam/libcalignmentfile.pyx":537 + * # dictionary access methods, for backwards compatibility. + * def __setitem__(self, key, value): + * raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()") # <<<<<<<<<<<<<< + * + * def __getitem__(self, key): + */ + __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_AlignmentHeader_does_not_support); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__23); + __Pyx_GIVEREF(__pyx_tuple__23); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__24); + __Pyx_GIVEREF(__pyx_tuple__24); + + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + */ + __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__25); + __Pyx_GIVEREF(__pyx_tuple__25); + + /* "pysam/libcalignmentfile.pyx":760 * * if not self.is_open: * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< * if not self.is_bam and not self.is_cram: * raise AttributeError( */ - __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 375, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__6); - __Pyx_GIVEREF(__pyx_tuple__6); + __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 760, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__26); + __Pyx_GIVEREF(__pyx_tuple__26); - /* "pysam/libcalignmentfile.pyx":377 + /* "pysam/libcalignmentfile.pyx":762 * raise ValueError("I/O operation on closed file") * if not self.is_bam and not self.is_cram: * raise AttributeError( # <<<<<<<<<<<<<< * "AlignmentFile.mapped only available in bam files") * if self.index == NULL: */ - __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_AlignmentFile_mapped_only_availa); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 377, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__7); - __Pyx_GIVEREF(__pyx_tuple__7); + __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_s_AlignmentFile_mapped_only_availa); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 762, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__27); + __Pyx_GIVEREF(__pyx_tuple__27); - /* "pysam/libcalignmentfile.pyx":380 + /* "pysam/libcalignmentfile.pyx":765 * "AlignmentFile.mapped only available in bam files") * if self.index == NULL: * raise ValueError( # <<<<<<<<<<<<<< * "mapping information not recorded in index " * "or index not available") */ - __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_mapping_information_not_recorded); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__8); - __Pyx_GIVEREF(__pyx_tuple__8); + __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_s_mapping_information_not_recorded); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 765, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__28); + __Pyx_GIVEREF(__pyx_tuple__28); + + /* "pysam/libcalignmentfile.pyx":811 + * # to bgzf_read (https://github.com/samtools/htslib/blob/1.7/bgzf.c#L888) + * # Better to avoid this (for now) than to produce seemingly correct results. + * raise ValueError('Cannot add extra threads when "ignore_truncation" is True') # <<<<<<<<<<<<<< + * self.threads = threads + * + */ + __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_Cannot_add_extra_threads_when_ig); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 811, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__29); + __Pyx_GIVEREF(__pyx_tuple__29); - /* "pysam/libcalignmentfile.pyx":435 + /* "pysam/libcalignmentfile.pyx":840 * # StringIO not supported * if isinstance(filepath_or_object, StringIO): * raise NotImplementedError( # <<<<<<<<<<<<<< * "access from StringIO objects not supported") * # reading from a file descriptor */ - __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_access_from_StringIO_objects_not); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 435, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__9); - __Pyx_GIVEREF(__pyx_tuple__9); + __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_s_access_from_StringIO_objects_not); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 840, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__30); + __Pyx_GIVEREF(__pyx_tuple__30); - /* "pysam/libcalignmentfile.pyx":446 + /* "pysam/libcalignmentfile.pyx":851 * elif hasattr(filepath_or_object, "fileno"): * if filepath_or_object.closed: * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< * self.filename = filepath_or_object * # .name can be TextIOWrapper */ - __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 446, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__10); - __Pyx_GIVEREF(__pyx_tuple__10); + __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 851, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__31); + __Pyx_GIVEREF(__pyx_tuple__31); + + /* "pysam/libcalignmentfile.pyx":880 + * + * if not (template or header or reference_names): + * raise ValueError( # <<<<<<<<<<<<<< + * "either supply options `template`, `header` or both `reference_names` " + * "and `reference_lengths` for writing") + */ + __pyx_tuple__33 = PyTuple_Pack(1, __pyx_kp_s_either_supply_options_template_h); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__33); + __Pyx_GIVEREF(__pyx_tuple__33); + + /* "pysam/libcalignmentfile.pyx":901 + * self.header = AlignmentHeader.from_text(text) + * else: + * raise ValueError("not enough information to construct header. Please provide template, " # <<<<<<<<<<<<<< + * "header, text or reference_names/reference_lengths") + * self.htsfile = self._open_htsfile() + */ + __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_s_not_enough_information_to_constr); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 901, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__34); + __Pyx_GIVEREF(__pyx_tuple__34); - /* "pysam/libcalignmentfile.pyx":554 + /* "pysam/libcalignmentfile.pyx":939 * * if self.htsfile.format.category != sequence_data: * raise ValueError("file does not contain alignment data") # <<<<<<<<<<<<<< * - * # bam files require a valid header - */ - __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_file_does_not_contain_alignment); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 554, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__13); - __Pyx_GIVEREF(__pyx_tuple__13); - - /* "pysam/libcalignmentfile.pyx":661 - * """ - * if not self.is_open: - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< - * reference = force_bytes(reference) - * return bam_name2id(self.header, reference) + * if format_options and len(format_options): */ - __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 661, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__14); - __Pyx_GIVEREF(__pyx_tuple__14); + __pyx_tuple__35 = PyTuple_Pack(1, __pyx_kp_s_file_does_not_contain_alignment); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 939, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__35); + __Pyx_GIVEREF(__pyx_tuple__35); - /* "pysam/libcalignmentfile.pyx":670 - * """ - * if not self.is_open: - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< - * if not 0 <= tid < self.header.n_targets: - * raise ValueError("reference_id %i out of range 0<=tid<%i" % + /* "pysam/libcalignmentfile.pyx":970 + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: + * raise ValueError( # <<<<<<<<<<<<<< + * "SAM? file does not have a valid header (mode='%s'), " + * "please provide reference_names and reference_lengths") */ - __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 670, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__15); - __Pyx_GIVEREF(__pyx_tuple__15); + __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_s_SAM_file_does_not_have_a_valid_h); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 970, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__36); + __Pyx_GIVEREF(__pyx_tuple__36); - /* "pysam/libcalignmentfile.pyx":739 + /* "pysam/libcalignmentfile.pyx":1004 * - * if not reference: - * return 0, 0, 0, 0 # <<<<<<<<<<<<<< + * elif require_index: + * raise IOError('unable to open index file') # <<<<<<<<<<<<<< * - * if tid is not None: + * # save start of data section */ - __pyx_tuple__17 = PyTuple_Pack(4, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_int_0); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 739, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__17); - __Pyx_GIVEREF(__pyx_tuple__17); + __pyx_tuple__37 = PyTuple_Pack(1, __pyx_kp_s_unable_to_open_index_file); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 1004, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__37); + __Pyx_GIVEREF(__pyx_tuple__37); - /* "pysam/libcalignmentfile.pyx":823 + /* "pysam/libcalignmentfile.pyx":1078 * * if not self.is_open: * raise ValueError( "I/O operation on closed file" ) # <<<<<<<<<<<<<< * - * has_coord, rtid, rstart, rend = self.parse_region( + * has_coord, rtid, rstart, rstop = self.parse_region( */ - __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 823, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__18); - __Pyx_GIVEREF(__pyx_tuple__18); + __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 1078, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__38); + __Pyx_GIVEREF(__pyx_tuple__38); - /* "pysam/libcalignmentfile.pyx":839 + /* "pysam/libcalignmentfile.pyx":1091 * if not until_eof and not self.is_remote: * if not self.has_index(): * raise ValueError( # <<<<<<<<<<<<<< * "fetch called on bamfile without index") * */ - __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_fetch_called_on_bamfile_without); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 839, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__19); - __Pyx_GIVEREF(__pyx_tuple__19); + __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_fetch_called_on_bamfile_without); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 1091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__39); + __Pyx_GIVEREF(__pyx_tuple__39); - /* "pysam/libcalignmentfile.pyx":859 + /* "pysam/libcalignmentfile.pyx":1111 * else: * if has_coord: * raise ValueError( # <<<<<<<<<<<<<< - * "fetching by region is not available for sam files") + * "fetching by region is not available for SAM files") * */ - __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_fetching_by_region_is_not_availa); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 859, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__20); - __Pyx_GIVEREF(__pyx_tuple__20); + __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_fetching_by_region_is_not_availa); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(0, 1111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__40); + __Pyx_GIVEREF(__pyx_tuple__40); - /* "pysam/libcalignmentfile.pyx":863 + /* "pysam/libcalignmentfile.pyx":1115 * - * if self.header == NULL: + * if multiple_iterators == True: * raise ValueError( # <<<<<<<<<<<<<< - * "fetch called for htsfile without header") - * - */ - __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_fetch_called_for_htsfile_without); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 863, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__21); - __Pyx_GIVEREF(__pyx_tuple__21); - - /* "pysam/libcalignmentfile.pyx":869 - * # give warning, sam_read1 segfaults - * if self.header.n_targets == 0: - * warnings.warn("fetch called for htsfile without header") # <<<<<<<<<<<<<< + * "multiple iterators not implemented for SAM files") * - * return IteratorRowAll(self, */ - __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_fetch_called_for_htsfile_without); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 869, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__22); - __Pyx_GIVEREF(__pyx_tuple__22); + __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_multiple_iterators_not_implement); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 1115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__41); + __Pyx_GIVEREF(__pyx_tuple__41); - /* "pysam/libcalignmentfile.pyx":951 + /* "pysam/libcalignmentfile.pyx":1198 * break * else: * raise ValueError("mate not found") # <<<<<<<<<<<<<< * * return mate */ - __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_mate_not_found); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 951, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__23); - __Pyx_GIVEREF(__pyx_tuple__23); + __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s_mate_not_found); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 1198, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__42); + __Pyx_GIVEREF(__pyx_tuple__42); - /* "pysam/libcalignmentfile.pyx":1024 + /* "pysam/libcalignmentfile.pyx":1326 * * if not self.is_open: * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< * - * has_coord, rtid, rstart, rend = self.parse_region( + * has_coord, rtid, rstart, rstop = self.parse_region( */ - __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 1024, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__24); - __Pyx_GIVEREF(__pyx_tuple__24); + __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 1326, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__43); + __Pyx_GIVEREF(__pyx_tuple__43); - /* "pysam/libcalignmentfile.pyx":1031 + /* "pysam/libcalignmentfile.pyx":1333 * if self.is_bam or self.is_cram: * if not self.has_index(): * raise ValueError("no index available for pileup") # <<<<<<<<<<<<<< * * if has_coord: */ - __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_pileup); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 1031, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__25); - __Pyx_GIVEREF(__pyx_tuple__25); + __pyx_tuple__44 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_pileup); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 1333, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__44); + __Pyx_GIVEREF(__pyx_tuple__44); - /* "pysam/libcalignmentfile.pyx":1043 + /* "pysam/libcalignmentfile.pyx":1345 * * else: * raise NotImplementedError( # <<<<<<<<<<<<<< * "pileup of samfiles not implemented yet") * */ - __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_pileup_of_samfiles_not_implement); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 1043, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__26); - __Pyx_GIVEREF(__pyx_tuple__26); + __pyx_tuple__45 = PyTuple_Pack(1, __pyx_kp_s_pileup_of_samfiles_not_implement); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 1345, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__45); + __Pyx_GIVEREF(__pyx_tuple__45); - /* "pysam/libcalignmentfile.pyx":1109 + /* "pysam/libcalignmentfile.pyx":1421 * * if not self.is_open: * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< * * cdef int filter_method = 0 */ - __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 1109, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__27); - __Pyx_GIVEREF(__pyx_tuple__27); - - /* "pysam/libcalignmentfile.pyx":1245 - * seq = read.seq - * quality = read.query_qualities - * for qpos, refpos in read.get_aligned_pairs(True): # <<<<<<<<<<<<<< - * if qpos is not None and refpos is not None and \ - * _start <= refpos < _stop: - */ - __pyx_tuple__28 = PyTuple_Pack(1, Py_True); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 1245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__28); - __Pyx_GIVEREF(__pyx_tuple__28); + __pyx_tuple__46 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 1421, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__46); + __Pyx_GIVEREF(__pyx_tuple__46); - /* "pysam/libcalignmentfile.pyx":1386 - * def __get__(self): - * if not self.is_open: - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< - * return self.header.n_targets + /* "pysam/libcalignmentfile.pyx":1532 * + * if _stop == _start: + * raise ValueError("interval of size 0") # <<<<<<<<<<<<<< + * if _stop < _start: + * raise ValueError("interval of size less than 0") */ - __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 1386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__29); - __Pyx_GIVEREF(__pyx_tuple__29); - - /* "pysam/libcalignmentfile.pyx":1393 - * read-only attribute""" - * def __get__(self): - * if not self.is_open: raise ValueError( "I/O operation on closed file" ) # <<<<<<<<<<<<<< - * t = [] - * for x from 0 <= x < self.header.n_targets: - */ - __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 1393, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__30); - __Pyx_GIVEREF(__pyx_tuple__30); + __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_s_interval_of_size_0); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 1532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__47); + __Pyx_GIVEREF(__pyx_tuple__47); - /* "pysam/libcalignmentfile.pyx":1407 - * def __get__(self): - * if not self.is_open: - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< - * t = [] - * for x from 0 <= x < self.header.n_targets: + /* "pysam/libcalignmentfile.pyx":1534 + * raise ValueError("interval of size 0") + * if _stop < _start: + * raise ValueError("interval of size less than 0") # <<<<<<<<<<<<<< + * + * cdef int length = _stop - _start */ - __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 1407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__31); - __Pyx_GIVEREF(__pyx_tuple__31); + __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_s_interval_of_size_less_than_0); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 1534, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__48); + __Pyx_GIVEREF(__pyx_tuple__48); - /* "pysam/libcalignmentfile.pyx":1467 - * def __get__(self): - * if not self.is_open: - * raise ValueError( "I/O operation on closed file" ) # <<<<<<<<<<<<<< - * return from_string_and_size(self.header.text, self.header.l_text) + /* "pysam/libcalignmentfile.pyx":1584 + * quality = read.query_qualities * + * for qpos, refpos in read.get_aligned_pairs(True): # <<<<<<<<<<<<<< + * if qpos is not None and refpos is not None and \ + * _start <= refpos < _stop: */ - __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 1467, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__32); - __Pyx_GIVEREF(__pyx_tuple__32); + __pyx_tuple__49 = PyTuple_Pack(1, Py_True); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 1584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__49); + __Pyx_GIVEREF(__pyx_tuple__49); - /* "pysam/libcalignmentfile.pyx":1494 - * def __get__(self): - * if not self.is_open: - * raise ValueError( "I/O operation on closed file" ) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1828 + * def __iter__(self): + * if not self.is_open: + * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< * - * result = {} + * if not self.is_bam and self.header.nreferences == 0: */ - __pyx_tuple__33 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 1494, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__33); - __Pyx_GIVEREF(__pyx_tuple__33); + __pyx_tuple__50 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 1828, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__50); + __Pyx_GIVEREF(__pyx_tuple__50); - /* "pysam/libcalignmentfile.pyx":1502 - * # create 0-terminated string) - * t = self.text - * for line in t.split("\n"): # <<<<<<<<<<<<<< - * if not line.strip(): continue - * assert line.startswith("@"), \ + /* "pysam/libcalignmentfile.pyx":1831 + * + * if not self.is_bam and self.header.nreferences == 0: + * raise NotImplementedError( # <<<<<<<<<<<<<< + * "can not iterate over samfile without header") + * return self */ - __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_s__3); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 1502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__34); - __Pyx_GIVEREF(__pyx_tuple__34); + __pyx_tuple__51 = PyTuple_Pack(1, __pyx_kp_s_can_not_iterate_over_samfile_wit); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 1831, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__51); + __Pyx_GIVEREF(__pyx_tuple__51); - /* "pysam/libcalignmentfile.pyx":1504 - * for line in t.split("\n"): - * if not line.strip(): continue - * assert line.startswith("@"), \ # <<<<<<<<<<<<<< - * "header line without '@': '%s'" % line - * fields = line[1:].split("\t") + /* "pysam/libcalignmentfile.pyx":1855 + * return makeAlignedSegment(self.b, self.header) + * elif ret == -2: + * raise IOError('truncated file') # <<<<<<<<<<<<<< + * else: + * raise StopIteration */ - __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_s__35); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 1504, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__36); - __Pyx_GIVEREF(__pyx_tuple__36); - - /* "pysam/libcalignmentfile.pyx":1506 - * assert line.startswith("@"), \ - * "header line without '@': '%s'" % line - * fields = line[1:].split("\t") # <<<<<<<<<<<<<< - * record = fields[0] - * assert record in VALID_HEADER_TYPES, \ - */ - __pyx_slice__37 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__37)) __PYX_ERR(0, 1506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__37); - __Pyx_GIVEREF(__pyx_slice__37); - __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_s__2); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 1506, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__38); - __Pyx_GIVEREF(__pyx_tuple__38); + __pyx_tuple__52 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(0, 1855, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__52); + __Pyx_GIVEREF(__pyx_tuple__52); - /* "pysam/libcalignmentfile.pyx":1515 - * if record not in result: - * result[record] = [] - * result[record].append("\t".join( fields[1:])) # <<<<<<<<<<<<<< - * continue - * # the following is clumsy as generators do not work? + /* "pysam/libcalignmentfile.pyx":1868 + * """ + * if self.header is None: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< + * return self.header.is_valid_tid(tid) + * */ - __pyx_slice__39 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__39)) __PYX_ERR(0, 1515, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__39); - __Pyx_GIVEREF(__pyx_slice__39); + __pyx_tuple__53 = PyTuple_Pack(1, __pyx_kp_s_header_not_available_in_closed_f); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 1868, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__53); + __Pyx_GIVEREF(__pyx_tuple__53); - /* "pysam/libcalignmentfile.pyx":1520 - * x = {} + /* "pysam/libcalignmentfile.pyx":1879 + * """ + * if self.header is None: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< + * return self.header.get_tid(reference) * - * for idx, field in enumerate(fields[1:]): # <<<<<<<<<<<<<< - * if ":" not in field: - * raise ValueError("malformatted header: no ':' in field" ) */ - __pyx_slice__40 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__40)) __PYX_ERR(0, 1520, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__40); - __Pyx_GIVEREF(__pyx_slice__40); + __pyx_tuple__54 = PyTuple_Pack(1, __pyx_kp_s_header_not_available_in_closed_f); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(0, 1879, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__54); + __Pyx_GIVEREF(__pyx_tuple__54); - /* "pysam/libcalignmentfile.pyx":1522 - * for idx, field in enumerate(fields[1:]): - * if ":" not in field: - * raise ValueError("malformatted header: no ':' in field" ) # <<<<<<<<<<<<<< - * key, value = field.split(":", 1) - * if key in ("CL",): + /* "pysam/libcalignmentfile.pyx":1887 + * """ + * if self.header is None: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< + * return self.header.get_reference_name(tid) + * */ - __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s_malformatted_header_no_in_field); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 1522, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__42); - __Pyx_GIVEREF(__pyx_tuple__42); + __pyx_tuple__55 = PyTuple_Pack(1, __pyx_kp_s_header_not_available_in_closed_f); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 1887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__55); + __Pyx_GIVEREF(__pyx_tuple__55); - /* "pysam/libcalignmentfile.pyx":1523 - * if ":" not in field: - * raise ValueError("malformatted header: no ':' in field" ) - * key, value = field.split(":", 1) # <<<<<<<<<<<<<< - * if key in ("CL",): - * # special treatment for command line + /* "pysam/libcalignmentfile.pyx":1895 + * """ + * if self.header is None: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< + * return self.header.get_reference_length(reference) + * */ - __pyx_tuple__43 = PyTuple_Pack(2, __pyx_kp_s__41, __pyx_int_1); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 1523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__43); - __Pyx_GIVEREF(__pyx_tuple__43); + __pyx_tuple__56 = PyTuple_Pack(1, __pyx_kp_s_header_not_available_in_closed_f); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(0, 1895, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__56); + __Pyx_GIVEREF(__pyx_tuple__56); - /* "pysam/libcalignmentfile.pyx":1531 - * # header. Thus, in contravention to the - * # SAM API, consume the rest of the line. - * key, value = "\t".join(fields[idx+1:]).split(":", 1) # <<<<<<<<<<<<<< - * x[key] = KNOWN_HEADER_FIELDS[record][key](value) - * break + /* "pysam/libcalignmentfile.pyx":1905 + * return self.header.nreferences + * else: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< + * + * property references: */ - __pyx_tuple__44 = PyTuple_Pack(2, __pyx_kp_s__41, __pyx_int_1); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 1531, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__44); - __Pyx_GIVEREF(__pyx_tuple__44); + __pyx_tuple__57 = PyTuple_Pack(1, __pyx_kp_s_header_not_available_in_closed_f); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(0, 1905, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__57); + __Pyx_GIVEREF(__pyx_tuple__57); - /* "pysam/libcalignmentfile.pyx":1572 - * def __iter__(self): - * if not self.is_open: - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":1914 + * return self.header.references + * else: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< * - * if not self.is_bam and self.header.n_targets == 0: + * property lengths: */ - __pyx_tuple__45 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 1572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__45); - __Pyx_GIVEREF(__pyx_tuple__45); + __pyx_tuple__58 = PyTuple_Pack(1, __pyx_kp_s_header_not_available_in_closed_f); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(0, 1914, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__58); + __Pyx_GIVEREF(__pyx_tuple__58); - /* "pysam/libcalignmentfile.pyx":1575 + /* "pysam/libcalignmentfile.pyx":1926 + * return self.header.lengths + * else: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< * - * if not self.is_bam and self.header.n_targets == 0: - * raise NotImplementedError( # <<<<<<<<<<<<<< - * "can not iterate over samfile without header") - * return self + * # Compatibility functions for pysam < 0.14 */ - __pyx_tuple__46 = PyTuple_Pack(1, __pyx_kp_s_can_not_iterate_over_samfile_wit); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 1575, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__46); - __Pyx_GIVEREF(__pyx_tuple__46); + __pyx_tuple__59 = PyTuple_Pack(1, __pyx_kp_s_header_not_available_in_closed_f); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(0, 1926, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__59); + __Pyx_GIVEREF(__pyx_tuple__59); - /* "pysam/libcalignmentfile.pyx":1598 - * return makeAlignedSegment(self.b, self) - * elif ret == -2: - * raise IOError('truncated file') # <<<<<<<<<<<<<< - * else: - * raise StopIteration + /* "pysam/libcalignmentfile.pyx":1935 + * return self.header.__str__() + * else: + * raise ValueError("header not available in closed files") # <<<<<<<<<<<<<< + * + * # Compatibility functions for pysam < 0.8.3 */ - __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 1598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__47); - __Pyx_GIVEREF(__pyx_tuple__47); + __pyx_tuple__60 = PyTuple_Pack(1, __pyx_kp_s_header_not_available_in_closed_f); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(0, 1935, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__60); + __Pyx_GIVEREF(__pyx_tuple__60); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -32324,209 +38686,220 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__48); - __Pyx_GIVEREF(__pyx_tuple__48); + __pyx_tuple__61 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__61); + __Pyx_GIVEREF(__pyx_tuple__61); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__49 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__49); - __Pyx_GIVEREF(__pyx_tuple__49); + __pyx_tuple__62 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__62); + __Pyx_GIVEREF(__pyx_tuple__62); - /* "pysam/libcalignmentfile.pyx":1642 + /* "pysam/libcalignmentfile.pyx":1978 * * if not samfile.is_open: * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< * * # makes sure that samfile stays alive as long as the */ - __pyx_tuple__50 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 1642, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__50); - __Pyx_GIVEREF(__pyx_tuple__50); + __pyx_tuple__63 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(0, 1978, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__63); + __Pyx_GIVEREF(__pyx_tuple__63); + + /* "pysam/libcalignmentfile.pyx":2006 + * hdr = sam_hdr_read(self.htsfile) + * if hdr is NULL: + * raise IOError("unable to read header information") # <<<<<<<<<<<<<< + * self.header = makeAlignmentHeader(hdr) + * + */ + __pyx_tuple__64 = PyTuple_Pack(1, __pyx_kp_s_unable_to_read_header_informatio); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(0, 2006, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__64); + __Pyx_GIVEREF(__pyx_tuple__64); /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ - __pyx_tuple__51 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__51); - __Pyx_GIVEREF(__pyx_tuple__51); + __pyx_tuple__65 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__65); + __Pyx_GIVEREF(__pyx_tuple__65); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__52 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__52); - __Pyx_GIVEREF(__pyx_tuple__52); + __pyx_tuple__66 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__66)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__66); + __Pyx_GIVEREF(__pyx_tuple__66); - /* "pysam/libcalignmentfile.pyx":1706 + /* "pysam/libcalignmentfile.pyx":2054 * * if not samfile.has_index(): * raise ValueError("no index available for iteration") # <<<<<<<<<<<<<< * - * with nogil: + * IteratorRow.__init__(self, samfile, */ - __pyx_tuple__53 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_iteration); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 1706, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__53); - __Pyx_GIVEREF(__pyx_tuple__53); + __pyx_tuple__67 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_iteration); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(0, 2054, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__67); + __Pyx_GIVEREF(__pyx_tuple__67); - /* "pysam/libcalignmentfile.pyx":1737 + /* "pysam/libcalignmentfile.pyx":2090 * # returns -2 for a truncated file. * # See https://github.com/pysam-developers/pysam/pull/50#issuecomment-64928625 * raise IOError('truncated file') # <<<<<<<<<<<<<< * else: - * raise StopIteration + * raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval)) */ - __pyx_tuple__54 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(0, 1737, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__54); - __Pyx_GIVEREF(__pyx_tuple__54); + __pyx_tuple__68 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__68)) __PYX_ERR(0, 2090, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__68); + __Pyx_GIVEREF(__pyx_tuple__68); /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") */ - __pyx_tuple__55 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile_2); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__55); - __Pyx_GIVEREF(__pyx_tuple__55); + __pyx_tuple__69 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_s); if (unlikely(!__pyx_tuple__69)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__69); + __Pyx_GIVEREF(__pyx_tuple__69); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile,self.iter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__56 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile_2); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__56); - __Pyx_GIVEREF(__pyx_tuple__56); + __pyx_tuple__70 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_s); if (unlikely(!__pyx_tuple__70)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__70); + __Pyx_GIVEREF(__pyx_tuple__70); - /* "pysam/libcalignmentfile.pyx":1790 - * return makeAlignedSegment(self.b, self.samfile) + /* "pysam/libcalignmentfile.pyx":2146 + * return makeAlignedSegment(self.b, self.header) * elif ret == -2: * raise IOError('truncated file') # <<<<<<<<<<<<<< * else: * raise StopIteration */ - __pyx_tuple__57 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(0, 1790, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__57); - __Pyx_GIVEREF(__pyx_tuple__57); + __pyx_tuple__71 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__71)) __PYX_ERR(0, 2146, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__71); + __Pyx_GIVEREF(__pyx_tuple__71); /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ - __pyx_tuple__58 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__58); - __Pyx_GIVEREF(__pyx_tuple__58); + __pyx_tuple__72 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__72)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__72); + __Pyx_GIVEREF(__pyx_tuple__72); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__59 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__59); - __Pyx_GIVEREF(__pyx_tuple__59); + __pyx_tuple__73 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__73); + __Pyx_GIVEREF(__pyx_tuple__73); - /* "pysam/libcalignmentfile.pyx":1834 - * return makeAlignedSegment(self.b, self.samfile) + /* "pysam/libcalignmentfile.pyx":2191 + * return makeAlignedSegment(self.b, self.header) * elif ret == -2: * raise IOError('truncated file') # <<<<<<<<<<<<<< * else: * raise StopIteration */ - __pyx_tuple__60 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(0, 1834, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__60); - __Pyx_GIVEREF(__pyx_tuple__60); + __pyx_tuple__74 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__74)) __PYX_ERR(0, 2191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__74); + __Pyx_GIVEREF(__pyx_tuple__74); /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ - __pyx_tuple__61 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__61); - __Pyx_GIVEREF(__pyx_tuple__61); + __pyx_tuple__75 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__75)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__75); + __Pyx_GIVEREF(__pyx_tuple__75); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__62 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__62); - __Pyx_GIVEREF(__pyx_tuple__62); + __pyx_tuple__76 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__76)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__76); + __Pyx_GIVEREF(__pyx_tuple__76); - /* "pysam/libcalignmentfile.pyx":1857 + /* "pysam/libcalignmentfile.pyx":2214 * * if not samfile.has_index(): * raise ValueError("no index available for fetch") # <<<<<<<<<<<<<< * * self.tid = -1 */ - __pyx_tuple__63 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_fetch); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(0, 1857, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__63); - __Pyx_GIVEREF(__pyx_tuple__63); + __pyx_tuple__77 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_fetch); if (unlikely(!__pyx_tuple__77)) __PYX_ERR(0, 2214, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__77); + __Pyx_GIVEREF(__pyx_tuple__77); /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ - __pyx_tuple__64 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__64); - __Pyx_GIVEREF(__pyx_tuple__64); + __pyx_tuple__78 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__78)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__78); + __Pyx_GIVEREF(__pyx_tuple__78); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__65 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__65); - __Pyx_GIVEREF(__pyx_tuple__65); + __pyx_tuple__79 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__79)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__79); + __Pyx_GIVEREF(__pyx_tuple__79); - /* "pysam/libcalignmentfile.pyx":1951 - * return makeAlignedSegment(self.b, self.samfile) - * elif (ret == -2): + /* "pysam/libcalignmentfile.pyx":2309 + * return makeAlignedSegment(self.b, self.header) + * elif ret == -2: * raise IOError('truncated file') # <<<<<<<<<<<<<< * else: * raise StopIteration */ - __pyx_tuple__66 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__66)) __PYX_ERR(0, 1951, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__66); - __Pyx_GIVEREF(__pyx_tuple__66); + __pyx_tuple__80 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__80)) __PYX_ERR(0, 2309, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__80); + __Pyx_GIVEREF(__pyx_tuple__80); /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ - __pyx_tuple__67 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__67); - __Pyx_GIVEREF(__pyx_tuple__67); + __pyx_tuple__81 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__81)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__81); + __Pyx_GIVEREF(__pyx_tuple__81); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__68 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile); if (unlikely(!__pyx_tuple__68)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__68); - __Pyx_GIVEREF(__pyx_tuple__68); + __pyx_tuple__82 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__82)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__82); + __Pyx_GIVEREF(__pyx_tuple__82); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -32534,29 +38907,29 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__69 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__69)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__69); - __Pyx_GIVEREF(__pyx_tuple__69); + __pyx_tuple__83 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__83)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__83); + __Pyx_GIVEREF(__pyx_tuple__83); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__70 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__70)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__70); - __Pyx_GIVEREF(__pyx_tuple__70); + __pyx_tuple__84 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__84)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__84); + __Pyx_GIVEREF(__pyx_tuple__84); - /* "pysam/libcalignmentfile.pyx":2270 - * self.cnext() - * if self.n_plp < 0: + /* "pysam/libcalignmentfile.pyx":2627 + * n = self.cnext() + * if n < 0: * raise ValueError("error during iteration" ) # <<<<<<<<<<<<<< * - * if self.plp == NULL: + * if n == 0: */ - __pyx_tuple__72 = PyTuple_Pack(1, __pyx_kp_s_error_during_iteration); if (unlikely(!__pyx_tuple__72)) __PYX_ERR(0, 2270, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__72); - __Pyx_GIVEREF(__pyx_tuple__72); + __pyx_tuple__86 = PyTuple_Pack(1, __pyx_kp_s_error_during_iteration); if (unlikely(!__pyx_tuple__86)) __PYX_ERR(0, 2627, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__86); + __Pyx_GIVEREF(__pyx_tuple__86); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -32564,29 +38937,29 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__73 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__73); - __Pyx_GIVEREF(__pyx_tuple__73); + __pyx_tuple__87 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__87)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__87); + __Pyx_GIVEREF(__pyx_tuple__87); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__74 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__74)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__74); - __Pyx_GIVEREF(__pyx_tuple__74); + __pyx_tuple__88 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__88)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__88); + __Pyx_GIVEREF(__pyx_tuple__88); - /* "pysam/libcalignmentfile.pyx":2307 - * - * if self.n_plp < 0: - * raise ValueError("error during iteration" ) # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":2668 + * n = self.cnext() + * if n < 0: + * raise ValueError("error during iteration") # <<<<<<<<<<<<<< * - * # return result, if within same reference + * # proceed to next reference or stop */ - __pyx_tuple__75 = PyTuple_Pack(1, __pyx_kp_s_error_during_iteration); if (unlikely(!__pyx_tuple__75)) __PYX_ERR(0, 2307, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__75); - __Pyx_GIVEREF(__pyx_tuple__75); + __pyx_tuple__89 = PyTuple_Pack(1, __pyx_kp_s_error_during_iteration); if (unlikely(!__pyx_tuple__89)) __PYX_ERR(0, 2668, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__89); + __Pyx_GIVEREF(__pyx_tuple__89); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -32594,114 +38967,158 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__76 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__76)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__76); - __Pyx_GIVEREF(__pyx_tuple__76); + __pyx_tuple__90 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__90)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__90); + __Pyx_GIVEREF(__pyx_tuple__90); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__77 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__77)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__77); - __Pyx_GIVEREF(__pyx_tuple__77); + __pyx_tuple__91 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__91)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__91); + __Pyx_GIVEREF(__pyx_tuple__91); + + /* "pysam/libcalignmentfile.pyx":2788 + * self.htsfile = hts_open(cfilename, 'r') + * if self.htsfile == NULL: + * raise OSError("unable to reopen htsfile") # <<<<<<<<<<<<<< + * + * # need to advance in newly opened file to position after header + */ + __pyx_tuple__92 = PyTuple_Pack(1, __pyx_kp_s_unable_to_reopen_htsfile); if (unlikely(!__pyx_tuple__92)) __PYX_ERR(0, 2788, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__92); + __Pyx_GIVEREF(__pyx_tuple__92); + + /* "pysam/libcalignmentfile.pyx":2795 + * hdr = sam_hdr_read(self.htsfile) + * if hdr == NULL: + * raise OSError("unable to read header information") # <<<<<<<<<<<<<< + * self.header = makeAlignmentHeader(hdr) + * self.owns_samfile = True + */ + __pyx_tuple__93 = PyTuple_Pack(1, __pyx_kp_s_unable_to_read_header_informatio); if (unlikely(!__pyx_tuple__93)) __PYX_ERR(0, 2795, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__93); + __Pyx_GIVEREF(__pyx_tuple__93); /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") */ - __pyx_tuple__78 = PyTuple_Pack(1, __pyx_kp_s_self_header_self_htsfile_cannot); if (unlikely(!__pyx_tuple__78)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__78); - __Pyx_GIVEREF(__pyx_tuple__78); + __pyx_tuple__94 = PyTuple_Pack(1, __pyx_kp_s_self_htsfile_cannot_be_converted); if (unlikely(!__pyx_tuple__94)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__94); + __Pyx_GIVEREF(__pyx_tuple__94); /* "(tree fragment)":4 - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.header,self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.htsfile cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__79 = PyTuple_Pack(1, __pyx_kp_s_self_header_self_htsfile_cannot); if (unlikely(!__pyx_tuple__79)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__79); - __Pyx_GIVEREF(__pyx_tuple__79); + __pyx_tuple__95 = PyTuple_Pack(1, __pyx_kp_s_self_htsfile_cannot_be_converted); if (unlikely(!__pyx_tuple__95)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__95); + __Pyx_GIVEREF(__pyx_tuple__95); - /* "pysam/libcalignmentfile.pyx":97 + /* "pysam/libcalignmentfile.pyx":89 + * + * IndexStats = collections.namedtuple("IndexStats", + * ("contig", # <<<<<<<<<<<<<< + * "mapped", + * "unmapped", + */ + __pyx_tuple__97 = PyTuple_Pack(4, __pyx_n_s_contig, __pyx_n_s_mapped, __pyx_n_s_unmapped, __pyx_n_s_total); if (unlikely(!__pyx_tuple__97)) __PYX_ERR(0, 89, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__97); + __Pyx_GIVEREF(__pyx_tuple__97); + + /* "pysam/libcalignmentfile.pyx":88 + * "IndexedReads"] + * + * IndexStats = collections.namedtuple("IndexStats", # <<<<<<<<<<<<<< + * ("contig", + * "mapped", + */ + __pyx_tuple__98 = PyTuple_Pack(2, __pyx_n_s_IndexStats, __pyx_tuple__97); if (unlikely(!__pyx_tuple__98)) __PYX_ERR(0, 88, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__98); + __Pyx_GIVEREF(__pyx_tuple__98); + + /* "pysam/libcalignmentfile.pyx":107 * * # order of records within SAM headers * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO") # <<<<<<<<<<<<<< * * # default type conversions within SAM header records */ - __pyx_tuple__81 = PyTuple_Pack(5, __pyx_n_s_HD, __pyx_n_s_SQ, __pyx_n_s_RG, __pyx_n_s_PG, __pyx_n_s_CO); if (unlikely(!__pyx_tuple__81)) __PYX_ERR(0, 97, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__81); - __Pyx_GIVEREF(__pyx_tuple__81); + __pyx_tuple__99 = PyTuple_Pack(5, __pyx_n_s_HD, __pyx_n_s_SQ_2, __pyx_n_s_RG, __pyx_n_s_PG, __pyx_n_s_CO); if (unlikely(!__pyx_tuple__99)) __PYX_ERR(0, 107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__99); + __Pyx_GIVEREF(__pyx_tuple__99); - /* "pysam/libcalignmentfile.pyx":114 + /* "pysam/libcalignmentfile.pyx":124 * # output order of fields within records. Ensure that CL is at * # the end as parsing a CL will ignore any subsequent records. * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"), # <<<<<<<<<<<<<< * "SQ" : ("SN", "LN", "AS", "M5", * "UR", "SP", "AH"), */ - __pyx_tuple__82 = PyTuple_Pack(3, __pyx_n_s_VN, __pyx_n_s_SO, __pyx_n_s_GO); if (unlikely(!__pyx_tuple__82)) __PYX_ERR(0, 114, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__82); - __Pyx_GIVEREF(__pyx_tuple__82); + __pyx_tuple__100 = PyTuple_Pack(3, __pyx_n_s_VN, __pyx_n_s_SO, __pyx_n_s_GO); if (unlikely(!__pyx_tuple__100)) __PYX_ERR(0, 124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__100); + __Pyx_GIVEREF(__pyx_tuple__100); - /* "pysam/libcalignmentfile.pyx":115 + /* "pysam/libcalignmentfile.pyx":125 * # the end as parsing a CL will ignore any subsequent records. * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"), * "SQ" : ("SN", "LN", "AS", "M5", # <<<<<<<<<<<<<< * "UR", "SP", "AH"), * "RG" : ("ID", "CN", "SM", "LB", */ - __pyx_tuple__83 = PyTuple_Pack(7, __pyx_n_s_SN, __pyx_n_s_LN, __pyx_n_s_AS, __pyx_n_s_M5, __pyx_n_s_UR, __pyx_n_s_SP, __pyx_n_s_AH); if (unlikely(!__pyx_tuple__83)) __PYX_ERR(0, 115, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__83); - __Pyx_GIVEREF(__pyx_tuple__83); + __pyx_tuple__101 = PyTuple_Pack(7, __pyx_n_s_SN, __pyx_n_s_LN, __pyx_n_s_AS, __pyx_n_s_M5, __pyx_n_s_UR, __pyx_n_s_SP, __pyx_n_s_AH); if (unlikely(!__pyx_tuple__101)) __PYX_ERR(0, 125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__101); + __Pyx_GIVEREF(__pyx_tuple__101); - /* "pysam/libcalignmentfile.pyx":117 + /* "pysam/libcalignmentfile.pyx":127 * "SQ" : ("SN", "LN", "AS", "M5", * "UR", "SP", "AH"), * "RG" : ("ID", "CN", "SM", "LB", # <<<<<<<<<<<<<< * "PU", "PI", "DT", "DS", * "PL", "FO", "KS", "PG", */ - __pyx_tuple__84 = PyTuple_Pack(13, __pyx_n_s_ID, __pyx_n_s_CN, __pyx_n_s_SM, __pyx_n_s_LB, __pyx_n_s_PU, __pyx_n_s_PI, __pyx_n_s_DT, __pyx_n_s_DS, __pyx_n_s_PL, __pyx_n_s_FO, __pyx_n_s_KS, __pyx_n_s_PG, __pyx_n_s_PM); if (unlikely(!__pyx_tuple__84)) __PYX_ERR(0, 117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__84); - __Pyx_GIVEREF(__pyx_tuple__84); + __pyx_tuple__102 = PyTuple_Pack(13, __pyx_n_s_ID, __pyx_n_s_CN, __pyx_n_s_SM, __pyx_n_s_LB, __pyx_n_s_PU, __pyx_n_s_PI, __pyx_n_s_DT, __pyx_n_s_DS, __pyx_n_s_PL, __pyx_n_s_FO, __pyx_n_s_KS, __pyx_n_s_PG, __pyx_n_s_PM); if (unlikely(!__pyx_tuple__102)) __PYX_ERR(0, 127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__102); + __Pyx_GIVEREF(__pyx_tuple__102); - /* "pysam/libcalignmentfile.pyx":121 + /* "pysam/libcalignmentfile.pyx":131 * "PL", "FO", "KS", "PG", * "PM"), * "PG" : ("PN", "ID", "VN", "PP", # <<<<<<<<<<<<<< * "DS", "CL"),} * */ - __pyx_tuple__85 = PyTuple_Pack(6, __pyx_n_s_PN, __pyx_n_s_ID, __pyx_n_s_VN, __pyx_n_s_PP, __pyx_n_s_DS, __pyx_n_s_CL); if (unlikely(!__pyx_tuple__85)) __PYX_ERR(0, 121, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__85); - __Pyx_GIVEREF(__pyx_tuple__85); + __pyx_tuple__103 = PyTuple_Pack(6, __pyx_n_s_PN, __pyx_n_s_ID, __pyx_n_s_VN, __pyx_n_s_PP, __pyx_n_s_DS, __pyx_n_s_CL); if (unlikely(!__pyx_tuple__103)) __PYX_ERR(0, 131, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__103); + __Pyx_GIVEREF(__pyx_tuple__103); - /* "pysam/libcalignmentfile.pyx":125 + /* "pysam/libcalignmentfile.pyx":135 * * * def build_header_line(fields, record): # <<<<<<<<<<<<<< * '''build a header line from `fields` dictionary for `record`''' * */ - __pyx_tuple__86 = PyTuple_Pack(4, __pyx_n_s_fields, __pyx_n_s_record, __pyx_n_s_line, __pyx_n_s_key); if (unlikely(!__pyx_tuple__86)) __PYX_ERR(0, 125, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__86); - __Pyx_GIVEREF(__pyx_tuple__86); - __pyx_codeobj_ = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__86, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_build_header_line, 125, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 125, __pyx_L1_error) + __pyx_tuple__104 = PyTuple_Pack(4, __pyx_n_s_fields, __pyx_n_s_record, __pyx_n_s_line, __pyx_n_s_key); if (unlikely(!__pyx_tuple__104)) __PYX_ERR(0, 135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__104); + __Pyx_GIVEREF(__pyx_tuple__104); + __pyx_codeobj_ = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__104, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_build_header_line, 135, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 135, __pyx_L1_error) /* "(tree fragment)":1 * def __pyx_unpickle_SNPCall(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x50b2281: * from pickle import PickleError as __pyx_PickleError */ - __pyx_tuple__87 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__87)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__87); - __Pyx_GIVEREF(__pyx_tuple__87); - __pyx_codeobj__80 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__87, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_SNPCall, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__80)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_tuple__105 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__105)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__105); + __Pyx_GIVEREF(__pyx_tuple__105); + __pyx_codeobj__96 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__105, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_SNPCall, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__96)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -32711,14 +39128,19 @@ static int __Pyx_InitCachedConstants(void) { static int __Pyx_InitGlobals(void) { __pyx_umethod_PyDict_Type_get.type = (PyObject*)&PyDict_Type; - if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); - __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_1796 = PyInt_FromLong(1796); if (unlikely(!__pyx_int_1796)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_8000 = PyInt_FromLong(8000); if (unlikely(!__pyx_int_8000)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_84615809 = PyInt_FromLong(84615809L); if (unlikely(!__pyx_int_84615809)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_536870912 = PyInt_FromLong(536870912L); if (unlikely(!__pyx_int_536870912)) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 2, __pyx_L1_error); + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_int_7 = PyInt_FromLong(7); if (unlikely(!__pyx_int_7)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_int_13 = PyInt_FromLong(13); if (unlikely(!__pyx_int_13)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_int_1796 = PyInt_FromLong(1796); if (unlikely(!__pyx_int_1796)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_int_8000 = PyInt_FromLong(8000); if (unlikely(!__pyx_int_8000)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_int_84615809 = PyInt_FromLong(84615809L); if (unlikely(!__pyx_int_84615809)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_int_536870912 = PyInt_FromLong(536870912L); if (unlikely(!__pyx_int_536870912)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 2, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; @@ -32760,161 +39182,179 @@ static int __Pyx_modinit_type_init_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); /*--- Type init code ---*/ - __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(0, 1, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader) < 0) __PYX_ERR(0, 182, __pyx_L1_error) + __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + #if CYTHON_COMPILING_IN_CPYTHON + { + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader, "__str__"); if (unlikely(!wrapper)) __PYX_ERR(0, 182, __pyx_L1_error) + if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { + __pyx_wrapperbase_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__ = *((PyWrapperDescrObject *)wrapper)->d_base; + __pyx_wrapperbase_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__.doc = __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__; + ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__; + } + } + #endif + if (PyObject_SetAttrString(__pyx_m, "AlignmentHeader", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader) < 0) __PYX_ERR(0, 182, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader) < 0) __PYX_ERR(0, 182, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader = &__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader; + __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(0, 2, __pyx_L1_error) __pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile = &__pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile; __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile.__pyx_base = *__pyx_vtabptr_5pysam_10libchtslib_HTSFile; __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *))__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_getCurrent; __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *))__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_cnext; __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile.write = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch))__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write; __pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_base = __pyx_ptype_5pysam_10libchtslib_HTSFile; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 222, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 565, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 222, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "AlignmentFile", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 222, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 222, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_AlignmentFile.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 565, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "AlignmentFile", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 565, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 565, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile = &__pyx_type_5pysam_17libcalignmentfile_AlignmentFile; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_PileupColumn) < 0) __PYX_ERR(2, 57, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_PileupColumn) < 0) __PYX_ERR(2, 61, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_PileupColumn.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_PileupColumn.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_PileupColumn.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_PileupColumn.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "PileupColumn", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_PileupColumn) < 0) __PYX_ERR(2, 57, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "PileupColumn", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_PileupColumn) < 0) __PYX_ERR(2, 61, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_PileupColumn = &__pyx_type_5pysam_17libcalignmentfile_PileupColumn; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_PileupRead) < 0) __PYX_ERR(2, 64, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_PileupRead) < 0) __PYX_ERR(2, 68, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_PileupRead.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_PileupRead.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_PileupRead.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_PileupRead.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "PileupRead", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_PileupRead) < 0) __PYX_ERR(2, 64, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "PileupRead", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_PileupRead) < 0) __PYX_ERR(2, 68, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_PileupRead = &__pyx_type_5pysam_17libcalignmentfile_PileupRead; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1612, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1947, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_IteratorRow.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorRow.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorRow.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_IteratorRow.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "IteratorRow", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1612, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1612, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "IteratorRow", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1947, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1947, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow = &__pyx_type_5pysam_17libcalignmentfile_IteratorRow; __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorRowRegion; __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowRegion.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *))__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_getCurrent; __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowRegion.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *))__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_cnext; __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 1684, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2035, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 1684, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "IteratorRowRegion", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 1684, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 1684, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2035, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "IteratorRowRegion", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2035, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2035, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion; __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorRowHead; __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowHead.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *))__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_getCurrent; __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowHead.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *))__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_cnext; __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 1745, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2098, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 1745, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "IteratorRowHead", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 1745, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 1745, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2098, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "IteratorRowHead", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2098, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2098, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead; __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorRowAll; __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowAll.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *))__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_getCurrent; __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowAll.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *))__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext; __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 1795, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2151, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 1795, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "IteratorRowAll", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 1795, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 1795, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2151, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "IteratorRowAll", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2151, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2151, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll; __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 1839, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 2196, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "IteratorRowAllRefs", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 1839, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 1839, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "IteratorRowAllRefs", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 2196, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 2196, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs; __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorRowSelection; __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowSelection.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *))__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_getCurrent; __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowSelection.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *))__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext; __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 1904, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2261, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 1904, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "IteratorRowSelection", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 1904, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 1904, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2261, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "IteratorRowSelection", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2261, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2261, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection; __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn; __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_cnext; - __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.getSequence = (char *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence; - __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.setMask = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, PyObject *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setMask; - __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.setupIteratorData = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData *__pyx_optional_args))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData; + __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.get_sequence = (char *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_get_sequence; + __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn._setup_iterator = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator; __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.reset = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, PyObject *, PyObject *, PyObject *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset; __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn._free_pileup_iter = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__free_pileup_iter; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2055, __pyx_L1_error) + __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.getSequence = (char *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence; + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2405, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_IteratorColumn.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorColumn.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorColumn.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_IteratorColumn.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorColumn.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2055, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "IteratorColumn", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2055, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2055, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorColumn.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2405, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "IteratorColumn", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2405, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2405, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn = &__pyx_type_5pysam_17libcalignmentfile_IteratorColumn; __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnRegion; __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnRegion.__pyx_base = *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn; __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2249, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2603, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2249, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "IteratorColumnRegion", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2249, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2249, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2603, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "IteratorColumnRegion", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2603, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2603, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion = &__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion; __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAllRefs; __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAllRefs.__pyx_base = *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn; __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2286, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2647, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2286, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "IteratorColumnAllRefs", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2286, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2286, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs.tp_dict, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2647, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "IteratorColumnAllRefs", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2647, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2647, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs = &__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2384, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2748, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_IndexedReads.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_IndexedReads.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_IndexedReads.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_IndexedReads.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "IndexedReads", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2384, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2384, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "IndexedReads", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2748, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2748, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads = &__pyx_type_5pysam_17libcalignmentfile_IndexedReads; - if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2325, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2689, __pyx_L1_error) __pyx_type_5pysam_17libcalignmentfile_SNPCall.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_17libcalignmentfile_SNPCall.tp_dictoffset && __pyx_type_5pysam_17libcalignmentfile_SNPCall.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_17libcalignmentfile_SNPCall.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "SNPCall", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2325, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2325, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "SNPCall", (PyObject *)&__pyx_type_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2689, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2689, __pyx_L1_error) __pyx_ptype_5pysam_17libcalignmentfile_SNPCall = &__pyx_type_5pysam_17libcalignmentfile_SNPCall; __Pyx_RefNannyFinishContext(); return 0; @@ -32941,18 +39381,18 @@ static int __Pyx_modinit_type_import_code(void) { __pyx_vtabptr_5pysam_9libcfaidx_FastaFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastaFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastaFile)) __PYX_ERR(7, 37, __pyx_L1_error) __pyx_ptype_5pysam_9libcfaidx_FastqProxy = __Pyx_ImportType("pysam.libcfaidx", "FastqProxy", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastqProxy)) __PYX_ERR(7, 45, __pyx_L1_error) __pyx_vtabptr_5pysam_9libcfaidx_FastqProxy = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy)) __PYX_ERR(7, 45, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy = __Pyx_ImportType("pysam.libcfaidx", "PersistentFastqProxy", sizeof(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy)) __PYX_ERR(7, 51, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy = (struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy)) __PYX_ERR(7, 51, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_FastxFile = __Pyx_ImportType("pysam.libcfaidx", "FastxFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(7, 60, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_FastxFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(7, 60, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_FastqFile = __Pyx_ImportType("pysam.libcfaidx", "FastqFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(7, 72, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_FastqFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(7, 72, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_Fastafile = __Pyx_ImportType("pysam.libcfaidx", "Fastafile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_Fastafile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(7, 77, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_Fastafile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_Fastafile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(7, 77, __pyx_L1_error) - __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment = __Pyx_ImportType("pysam.libcalignedsegment", "AlignedSegment", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment), 1); if (unlikely(!__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment)) __PYX_ERR(8, 40, __pyx_L1_error) - __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment = (struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment*)__Pyx_GetVtable(__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment)) __PYX_ERR(8, 40, __pyx_L1_error) - __pyx_ptype_5pysam_18libcalignedsegment_PileupColumn = __Pyx_ImportType("pysam.libcalignedsegment", "PileupColumn", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn), 1); if (unlikely(!__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn)) __PYX_ERR(8, 69, __pyx_L1_error) - __pyx_ptype_5pysam_18libcalignedsegment_PileupRead = __Pyx_ImportType("pysam.libcalignedsegment", "PileupRead", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead), 1); if (unlikely(!__pyx_ptype_5pysam_18libcalignedsegment_PileupRead)) __PYX_ERR(8, 77, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_FastxRecord = __Pyx_ImportType("pysam.libcfaidx", "FastxRecord", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastxRecord)) __PYX_ERR(7, 52, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_FastxRecord = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxRecord->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxRecord)) __PYX_ERR(7, 52, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_FastxFile = __Pyx_ImportType("pysam.libcfaidx", "FastxFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(7, 61, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_FastxFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(7, 61, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_FastqFile = __Pyx_ImportType("pysam.libcfaidx", "FastqFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(7, 73, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_FastqFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(7, 73, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_Fastafile = __Pyx_ImportType("pysam.libcfaidx", "Fastafile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_Fastafile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(7, 78, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_Fastafile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_Fastafile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(7, 78, __pyx_L1_error) + __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment = __Pyx_ImportType("pysam.libcalignedsegment", "AlignedSegment", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment), 1); if (unlikely(!__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment)) __PYX_ERR(8, 34, __pyx_L1_error) + __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment = (struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment*)__Pyx_GetVtable(__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment)) __PYX_ERR(8, 34, __pyx_L1_error) + __pyx_ptype_5pysam_18libcalignedsegment_PileupColumn = __Pyx_ImportType("pysam.libcalignedsegment", "PileupColumn", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn), 1); if (unlikely(!__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn)) __PYX_ERR(8, 66, __pyx_L1_error) + __pyx_ptype_5pysam_18libcalignedsegment_PileupRead = __Pyx_ImportType("pysam.libcalignedsegment", "PileupRead", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead), 1); if (unlikely(!__pyx_ptype_5pysam_18libcalignedsegment_PileupRead)) __PYX_ERR(8, 76, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -32974,16 +39414,16 @@ static int __Pyx_modinit_function_import_code(void) { PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); /*--- Function import code ---*/ - __pyx_t_1 = __Pyx_ImportModule("pysam.libcalignedsegment"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_1, "makeAlignedSegment", (void (**)(void))&__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment, "PyObject *(bam1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_1, "makePileupColumn", (void (**)(void))&__pyx_f_5pysam_18libcalignedsegment_makePileupColumn, "PyObject *(bam_pileup1_t **, int, int, int, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_t_1 = __Pyx_ImportModule("pysam.libcalignedsegment"); if (!__pyx_t_1) __PYX_ERR(0, 2, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_1, "makeAlignedSegment", (void (**)(void))&__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment, "struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *(bam1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)") < 0) __PYX_ERR(0, 2, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_1, "makePileupColumn", (void (**)(void))&__pyx_f_5pysam_18libcalignedsegment_makePileupColumn, "struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *(bam_pileup1_t **, int, int, int, uint32_t, char *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)") < 0) __PYX_ERR(0, 2, __pyx_L1_error) Py_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_2 = __Pyx_ImportModule("pysam.libcutils"); if (!__pyx_t_2) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_2, "charptr_to_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_charptr_to_str, "PyObject *(char const *, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_2, "force_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_str, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_2, "force_bytes", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_bytes, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_bytes *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_2, "encode_filename", (void (**)(void))&__pyx_f_5pysam_9libcutils_encode_filename, "PyObject *(PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_2, "from_string_and_size", (void (**)(void))&__pyx_f_5pysam_9libcutils_from_string_and_size, "PyObject *(char const *, size_t)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportModule("pysam.libcutils"); if (!__pyx_t_2) __PYX_ERR(0, 2, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_2, "charptr_to_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_charptr_to_str, "PyObject *(char const *, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 2, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_2, "force_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_str, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 2, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_2, "force_bytes", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_bytes, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_bytes *__pyx_optional_args)") < 0) __PYX_ERR(0, 2, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_2, "encode_filename", (void (**)(void))&__pyx_f_5pysam_9libcutils_encode_filename, "PyObject *(PyObject *)") < 0) __PYX_ERR(0, 2, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_2, "from_string_and_size", (void (**)(void))&__pyx_f_5pysam_9libcutils_from_string_and_size, "PyObject *(char const *, size_t)") < 0) __PYX_ERR(0, 2, __pyx_L1_error) Py_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_RefNannyFinishContext(); return 0; @@ -33072,6 +39512,7 @@ static int __pyx_pymod_exec_libcalignmentfile(PyObject *__pyx_pyinit_module) PyObject *__pyx_t_1 = NULL; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations #if CYTHON_PEP489_MULTI_PHASE_INIT if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0; @@ -33088,27 +39529,27 @@ if (!__Pyx_RefNanny) { } #endif __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_libcalignmentfile(void)", 0); - if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 2, __pyx_L1_error) #ifdef __Pyx_CyFunction_USED - if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 2, __pyx_L1_error) #endif #ifdef __Pyx_FusedFunction_USED - if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 2, __pyx_L1_error) #endif #ifdef __Pyx_Coroutine_USED - if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 2, __pyx_L1_error) #endif #ifdef __Pyx_Generator_USED - if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__pyx_Generator_init() < 0) __PYX_ERR(0, 2, __pyx_L1_error) #endif #ifdef __Pyx_AsyncGen_USED - if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 2, __pyx_L1_error) #endif #ifdef __Pyx_StopAsyncIteration_USED - if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 2, __pyx_L1_error) #endif /*--- Library function declarations ---*/ /*--- Threads initialization code ---*/ @@ -33127,36 +39568,36 @@ if (!__Pyx_RefNanny) { #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif - if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + if (unlikely(!__pyx_m)) __PYX_ERR(0, 2, __pyx_L1_error) #endif - __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 2, __pyx_L1_error) Py_INCREF(__pyx_d); - __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 2, __pyx_L1_error) #if CYTHON_COMPILING_IN_PYPY Py_INCREF(__pyx_b); #endif - if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 2, __pyx_L1_error); /*--- Initialize various global constants etc. ---*/ - if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 2, __pyx_L1_error) #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) - if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 2, __pyx_L1_error) #endif if (__pyx_module_is_main_pysam__libcalignmentfile) { - if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 2, __pyx_L1_error) } #if PY_MAJOR_VERSION >= 3 { - PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 2, __pyx_L1_error) if (!PyDict_GetItemString(modules, "pysam.libcalignmentfile")) { - if (unlikely(PyDict_SetItemString(modules, "pysam.libcalignmentfile", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) + if (unlikely(PyDict_SetItemString(modules, "pysam.libcalignmentfile", __pyx_m) < 0)) __PYX_ERR(0, 2, __pyx_L1_error) } } #endif /*--- Builtin init code ---*/ - if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 2, __pyx_L1_error) /*--- Constants init code ---*/ - if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 2, __pyx_L1_error) /*--- Global type/function init code ---*/ (void)__Pyx_modinit_global_init_code(); (void)__Pyx_modinit_variable_export_code(); @@ -33167,71 +39608,71 @@ if (!__Pyx_RefNanny) { if (unlikely(__Pyx_modinit_function_import_code() != 0)) goto __pyx_L1_error; /*--- Execution code ---*/ #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) - if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 2, __pyx_L1_error) #endif - __Pyx_TraceCall("__Pyx_PyMODINIT_FUNC PyInit_libcalignmentfile(void)", __pyx_f[0], 1, 0, __PYX_ERR(0, 1, __pyx_L1_error)); + __Pyx_TraceCall("__Pyx_PyMODINIT_FUNC PyInit_libcalignmentfile(void)", __pyx_f[0], 2, 0, __PYX_ERR(0, 2, __pyx_L1_error)); - /* "pysam/libcalignmentfile.pyx":55 + /* "pysam/libcalignmentfile.pyx":58 * # * ######################################################## * import os # <<<<<<<<<<<<<< * import collections * import re */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error) + __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 55, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 58, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":56 + /* "pysam/libcalignmentfile.pyx":59 * ######################################################## * import os * import collections # <<<<<<<<<<<<<< * import re * import warnings */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error) + __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_collections, __pyx_t_1) < 0) __PYX_ERR(0, 56, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_collections, __pyx_t_1) < 0) __PYX_ERR(0, 59, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":57 + /* "pysam/libcalignmentfile.pyx":60 * import os * import collections * import re # <<<<<<<<<<<<<< * import warnings * import array */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_re, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error) + __pyx_t_1 = __Pyx_Import(__pyx_n_s_re, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_1) < 0) __PYX_ERR(0, 57, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_1) < 0) __PYX_ERR(0, 60, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":58 + /* "pysam/libcalignmentfile.pyx":61 * import collections * import re * import warnings # <<<<<<<<<<<<<< * import array - * + * from libc.errno cimport errno, EPIPE */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_warnings, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error) + __pyx_t_1 = __Pyx_Import(__pyx_n_s_warnings, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_warnings, __pyx_t_1) < 0) __PYX_ERR(0, 58, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_warnings, __pyx_t_1) < 0) __PYX_ERR(0, 61, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":59 + /* "pysam/libcalignmentfile.pyx":62 * import re * import warnings * import array # <<<<<<<<<<<<<< - * * from libc.errno cimport errno, EPIPE + * from libc.string cimport strcmp, strpbrk, strerror */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_array, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error) + __pyx_t_1 = __Pyx_Import(__pyx_n_s_array, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_array, __pyx_t_1) < 0) __PYX_ERR(0, 59, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_array, __pyx_t_1) < 0) __PYX_ERR(0, 62, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":71 + /* "pysam/libcalignmentfile.pyx":73 * from pysam.libchtslib cimport HTSFile, hisremote * * if PY_MAJOR_VERSION >= 3: # <<<<<<<<<<<<<< @@ -33241,28 +39682,28 @@ if (!__Pyx_RefNanny) { __pyx_t_2 = ((PY_MAJOR_VERSION >= 3) != 0); if (__pyx_t_2) { - /* "pysam/libcalignmentfile.pyx":72 + /* "pysam/libcalignmentfile.pyx":74 * * if PY_MAJOR_VERSION >= 3: * from io import StringIO # <<<<<<<<<<<<<< * else: * from StringIO import StringIO */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_StringIO); __Pyx_GIVEREF(__pyx_n_s_StringIO); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_StringIO); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_io, __pyx_t_1, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_io, __pyx_t_1, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 74, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_StringIO); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_StringIO); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_StringIO, __pyx_t_1) < 0) __PYX_ERR(0, 72, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_StringIO, __pyx_t_1) < 0) __PYX_ERR(0, 74, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignmentfile.pyx":71 + /* "pysam/libcalignmentfile.pyx":73 * from pysam.libchtslib cimport HTSFile, hisremote * * if PY_MAJOR_VERSION >= 3: # <<<<<<<<<<<<<< @@ -33272,7 +39713,7 @@ if (!__Pyx_RefNanny) { goto __pyx_L2; } - /* "pysam/libcalignmentfile.pyx":74 + /* "pysam/libcalignmentfile.pyx":76 * from io import StringIO * else: * from StringIO import StringIO # <<<<<<<<<<<<<< @@ -33280,310 +39721,465 @@ if (!__Pyx_RefNanny) { * cimport cython */ /*else*/ { - __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 74, __pyx_L1_error) + __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_n_s_StringIO); __Pyx_GIVEREF(__pyx_n_s_StringIO); PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_StringIO); - __pyx_t_1 = __Pyx_Import(__pyx_n_s_StringIO, __pyx_t_3, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error) + __pyx_t_1 = __Pyx_Import(__pyx_n_s_StringIO, __pyx_t_3, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_StringIO); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 74, __pyx_L1_error) + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_StringIO); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_StringIO, __pyx_t_3) < 0) __PYX_ERR(0, 74, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_StringIO, __pyx_t_3) < 0) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L2:; - /* "pysam/libcalignmentfile.pyx":87 + /* "pysam/libcalignmentfile.pyx":81 + * + * + * __all__ = [ # <<<<<<<<<<<<<< + * "AlignmentFile", + * "AlignmentHeader", + */ + __pyx_t_1 = PyList_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 81, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_AlignmentFile); + __Pyx_GIVEREF(__pyx_n_s_AlignmentFile); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_AlignmentFile); + __Pyx_INCREF(__pyx_n_s_AlignmentHeader); + __Pyx_GIVEREF(__pyx_n_s_AlignmentHeader); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_AlignmentHeader); + __Pyx_INCREF(__pyx_n_s_IteratorRow); + __Pyx_GIVEREF(__pyx_n_s_IteratorRow); + PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_IteratorRow); + __Pyx_INCREF(__pyx_n_s_IteratorColumn); + __Pyx_GIVEREF(__pyx_n_s_IteratorColumn); + PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_IteratorColumn); + __Pyx_INCREF(__pyx_n_s_IndexedReads); + __Pyx_GIVEREF(__pyx_n_s_IndexedReads); + PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_s_IndexedReads); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_all_2, __pyx_t_1) < 0) __PYX_ERR(0, 81, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":88 + * "IndexedReads"] + * + * IndexStats = collections.namedtuple("IndexStats", # <<<<<<<<<<<<<< + * ("contig", + * "mapped", + */ + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_namedtuple); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 88, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":89 * + * IndexStats = collections.namedtuple("IndexStats", + * ("contig", # <<<<<<<<<<<<<< + * "mapped", + * "unmapped", + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__98, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_IndexStats, __pyx_t_1) < 0) __PYX_ERR(0, 88, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":97 + * ## global variables * # maximum genomic coordinace - * cdef int MAX_POS = 2 << 29 # <<<<<<<<<<<<<< + * cdef int MAX_POS = 2 << 29 # <<<<<<<<<<<<<< * * # valid types for SAM headers */ __pyx_v_5pysam_17libcalignmentfile_MAX_POS = 0x40000000; - /* "pysam/libcalignmentfile.pyx":90 + /* "pysam/libcalignmentfile.pyx":100 * * # valid types for SAM headers - * VALID_HEADER_TYPES = {"HD" : dict, # <<<<<<<<<<<<<< - * "SQ" : list, - * "RG" : list, + * VALID_HEADER_TYPES = {"HD" : collections.Mapping, # <<<<<<<<<<<<<< + * "SQ" : collections.Sequence, + * "RG" : collections.Sequence, */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 100, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_HD, ((PyObject *)(&PyDict_Type))) < 0) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 100, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 100, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_HD, __pyx_t_4) < 0) __PYX_ERR(0, 100, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":91 + /* "pysam/libcalignmentfile.pyx":101 * # valid types for SAM headers - * VALID_HEADER_TYPES = {"HD" : dict, - * "SQ" : list, # <<<<<<<<<<<<<< - * "RG" : list, - * "PG" : list, + * VALID_HEADER_TYPES = {"HD" : collections.Mapping, + * "SQ" : collections.Sequence, # <<<<<<<<<<<<<< + * "RG" : collections.Sequence, + * "PG" : collections.Sequence, */ - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SQ, ((PyObject *)(&PyList_Type))) < 0) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 101, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 101, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SQ_2, __pyx_t_3) < 0) __PYX_ERR(0, 100, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignmentfile.pyx":92 - * VALID_HEADER_TYPES = {"HD" : dict, - * "SQ" : list, - * "RG" : list, # <<<<<<<<<<<<<< - * "PG" : list, - * "CO" : list} + /* "pysam/libcalignmentfile.pyx":102 + * VALID_HEADER_TYPES = {"HD" : collections.Mapping, + * "SQ" : collections.Sequence, + * "RG" : collections.Sequence, # <<<<<<<<<<<<<< + * "PG" : collections.Sequence, + * "CO" : collections.Sequence} */ - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_RG, ((PyObject *)(&PyList_Type))) < 0) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_RG, __pyx_t_4) < 0) __PYX_ERR(0, 100, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":93 - * "SQ" : list, - * "RG" : list, - * "PG" : list, # <<<<<<<<<<<<<< - * "CO" : list} + /* "pysam/libcalignmentfile.pyx":103 + * "SQ" : collections.Sequence, + * "RG" : collections.Sequence, + * "PG" : collections.Sequence, # <<<<<<<<<<<<<< + * "CO" : collections.Sequence} * */ - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, ((PyObject *)(&PyList_Type))) < 0) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 103, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 103, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, __pyx_t_3) < 0) __PYX_ERR(0, 100, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcalignmentfile.pyx":94 - * "RG" : list, - * "PG" : list, - * "CO" : list} # <<<<<<<<<<<<<< + /* "pysam/libcalignmentfile.pyx":104 + * "RG" : collections.Sequence, + * "PG" : collections.Sequence, + * "CO" : collections.Sequence} # <<<<<<<<<<<<<< * * # order of records within SAM headers */ - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_CO, ((PyObject *)(&PyList_Type))) < 0) __PYX_ERR(0, 90, __pyx_L1_error) - if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_TYPES, __pyx_t_1) < 0) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 104, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 104, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_CO, __pyx_t_4) < 0) __PYX_ERR(0, 100, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_TYPES, __pyx_t_1) < 0) __PYX_ERR(0, 100, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":97 + /* "pysam/libcalignmentfile.pyx":107 * * # order of records within SAM headers * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO") # <<<<<<<<<<<<<< * * # default type conversions within SAM header records */ - if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADERS, __pyx_tuple__81) < 0) __PYX_ERR(0, 97, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADERS, __pyx_tuple__99) < 0) __PYX_ERR(0, 107, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":100 + /* "pysam/libcalignmentfile.pyx":110 * * # default type conversions within SAM header records * KNOWN_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str}, # <<<<<<<<<<<<<< * "SQ" : {"SN" : str, "LN" : int, "AS" : str, * "M5" : str, "SP" : str, "UR" : str, */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 100, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 100, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_VN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 100, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_SO, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 100, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_GO, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 100, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_HD, __pyx_t_3) < 0) __PYX_ERR(0, 100, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 110, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_VN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 110, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_SO, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 110, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_GO, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 110, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_HD, __pyx_t_4) < 0) __PYX_ERR(0, 110, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":101 + /* "pysam/libcalignmentfile.pyx":111 * # default type conversions within SAM header records * KNOWN_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str}, * "SQ" : {"SN" : str, "LN" : int, "AS" : str, # <<<<<<<<<<<<<< * "M5" : str, "SP" : str, "UR" : str, * "AH" : str,}, */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 101, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_SN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 101, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_LN, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 101, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_AS, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 101, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyDict_NewPresized(7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_SN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 111, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_LN, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 111, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_AS, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 111, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":102 + /* "pysam/libcalignmentfile.pyx":112 * KNOWN_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str}, * "SQ" : {"SN" : str, "LN" : int, "AS" : str, * "M5" : str, "SP" : str, "UR" : str, # <<<<<<<<<<<<<< * "AH" : str,}, * "RG" : {"ID" : str, "CN" : str, "DS" : str, */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_M5, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 101, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_SP, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 101, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_UR, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 101, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_M5, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 111, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_SP, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 111, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_UR, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 111, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":103 + /* "pysam/libcalignmentfile.pyx":113 * "SQ" : {"SN" : str, "LN" : int, "AS" : str, * "M5" : str, "SP" : str, "UR" : str, * "AH" : str,}, # <<<<<<<<<<<<<< * "RG" : {"ID" : str, "CN" : str, "DS" : str, * "DT" : str, "FO" : str, "KS" : str, */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_AH, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 101, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SQ, __pyx_t_3) < 0) __PYX_ERR(0, 100, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_AH, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 111, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SQ_2, __pyx_t_4) < 0) __PYX_ERR(0, 110, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":104 + /* "pysam/libcalignmentfile.pyx":114 * "M5" : str, "SP" : str, "UR" : str, * "AH" : str,}, * "RG" : {"ID" : str, "CN" : str, "DS" : str, # <<<<<<<<<<<<<< * "DT" : str, "FO" : str, "KS" : str, * "LB" : str, "PG" : str, "PI" : str, */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 104, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_ID, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_CN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_DS, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyDict_NewPresized(13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 114, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_ID, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_CN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_DS, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":105 + /* "pysam/libcalignmentfile.pyx":115 * "AH" : str,}, * "RG" : {"ID" : str, "CN" : str, "DS" : str, * "DT" : str, "FO" : str, "KS" : str, # <<<<<<<<<<<<<< * "LB" : str, "PG" : str, "PI" : str, * "PL" : str, "PM" : str, "PU" : str, */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_DT, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_FO, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_KS, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_DT, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_FO, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_KS, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":106 + /* "pysam/libcalignmentfile.pyx":116 * "RG" : {"ID" : str, "CN" : str, "DS" : str, * "DT" : str, "FO" : str, "KS" : str, * "LB" : str, "PG" : str, "PI" : str, # <<<<<<<<<<<<<< * "PL" : str, "PM" : str, "PU" : str, * "SM" : str,}, */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_LB, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_PG, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_PI, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_LB, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_PG, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_PI, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":107 + /* "pysam/libcalignmentfile.pyx":117 * "DT" : str, "FO" : str, "KS" : str, * "LB" : str, "PG" : str, "PI" : str, * "PL" : str, "PM" : str, "PU" : str, # <<<<<<<<<<<<<< * "SM" : str,}, * "PG" : {"ID" : str, "PN" : str, "CL" : str, */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_PL, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_PM, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_PU, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_PL, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_PM, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_PU, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":108 + /* "pysam/libcalignmentfile.pyx":118 * "LB" : str, "PG" : str, "PI" : str, * "PL" : str, "PM" : str, "PU" : str, * "SM" : str,}, # <<<<<<<<<<<<<< * "PG" : {"ID" : str, "PN" : str, "CL" : str, * "PP" : str, "DS" : str, "VN" : str,},} */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_SM, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 104, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_RG, __pyx_t_3) < 0) __PYX_ERR(0, 100, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_SM, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_RG, __pyx_t_4) < 0) __PYX_ERR(0, 110, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcalignmentfile.pyx":109 + /* "pysam/libcalignmentfile.pyx":119 * "PL" : str, "PM" : str, "PU" : str, * "SM" : str,}, * "PG" : {"ID" : str, "PN" : str, "CL" : str, # <<<<<<<<<<<<<< * "PP" : str, "DS" : str, "VN" : str,},} * */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 109, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_ID, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 109, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_PN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 109, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_CL, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 109, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_ID, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 119, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_PN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 119, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_CL, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 119, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":110 + /* "pysam/libcalignmentfile.pyx":120 * "SM" : str,}, * "PG" : {"ID" : str, "PN" : str, "CL" : str, * "PP" : str, "DS" : str, "VN" : str,},} # <<<<<<<<<<<<<< * * # output order of fields within records. Ensure that CL is at */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_PP, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 109, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_DS, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 109, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_VN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 109, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, __pyx_t_3) < 0) __PYX_ERR(0, 100, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_KNOWN_HEADER_FIELDS, __pyx_t_1) < 0) __PYX_ERR(0, 100, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_PP, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 119, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_DS, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 119, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_VN, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 119, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, __pyx_t_4) < 0) __PYX_ERR(0, 110, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_KNOWN_HEADER_FIELDS, __pyx_t_1) < 0) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":114 + /* "pysam/libcalignmentfile.pyx":124 * # output order of fields within records. Ensure that CL is at * # the end as parsing a CL will ignore any subsequent records. * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"), # <<<<<<<<<<<<<< * "SQ" : ("SN", "LN", "AS", "M5", * "UR", "SP", "AH"), */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_HD, __pyx_tuple__100) < 0) __PYX_ERR(0, 124, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":125 + * # the end as parsing a CL will ignore any subsequent records. + * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"), + * "SQ" : ("SN", "LN", "AS", "M5", # <<<<<<<<<<<<<< + * "UR", "SP", "AH"), + * "RG" : ("ID", "CN", "SM", "LB", + */ + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SQ_2, __pyx_tuple__101) < 0) __PYX_ERR(0, 124, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":127 + * "SQ" : ("SN", "LN", "AS", "M5", + * "UR", "SP", "AH"), + * "RG" : ("ID", "CN", "SM", "LB", # <<<<<<<<<<<<<< + * "PU", "PI", "DT", "DS", + * "PL", "FO", "KS", "PG", + */ + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_RG, __pyx_tuple__102) < 0) __PYX_ERR(0, 124, __pyx_L1_error) + + /* "pysam/libcalignmentfile.pyx":131 + * "PL", "FO", "KS", "PG", + * "PM"), + * "PG" : ("PN", "ID", "VN", "PP", # <<<<<<<<<<<<<< + * "DS", "CL"),} + * + */ + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, __pyx_tuple__103) < 0) __PYX_ERR(0, 124, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_ORDER, __pyx_t_1) < 0) __PYX_ERR(0, 124, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":135 + * + * + * def build_header_line(fields, record): # <<<<<<<<<<<<<< + * '''build a header line from `fields` dictionary for `record`''' + * + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_17libcalignmentfile_1build_header_line, NULL, __pyx_n_s_pysam_libcalignmentfile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_header_line, __pyx_t_1) < 0) __PYX_ERR(0, 135, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcalignmentfile.pyx":225 + * + * @classmethod + * def _from_text_and_lengths(cls, text, reference_names, reference_lengths): # <<<<<<<<<<<<<< + * + * cdef AlignmentHeader self = AlignmentHeader() + */ + __pyx_t_1 = __Pyx_GetNameInClass((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_text_and_lengths); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 225, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_HD, __pyx_tuple__82) < 0) __PYX_ERR(0, 114, __pyx_L1_error) - /* "pysam/libcalignmentfile.pyx":115 - * # the end as parsing a CL will ignore any subsequent records. - * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"), - * "SQ" : ("SN", "LN", "AS", "M5", # <<<<<<<<<<<<<< - * "UR", "SP", "AH"), - * "RG" : ("ID", "CN", "SM", "LB", + /* "pysam/libcalignmentfile.pyx":224 + * raise MemoryError("could not create header") + * + * @classmethod # <<<<<<<<<<<<<< + * def _from_text_and_lengths(cls, text, reference_names, reference_lengths): + * + */ + __pyx_t_4 = __Pyx_Method_ClassMethod(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 224, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader->tp_dict, __pyx_n_s_from_text_and_lengths, __pyx_t_4) < 0) __PYX_ERR(0, 225, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader); + + /* "pysam/libcalignmentfile.pyx":266 + * + * @classmethod + * def from_text(cls, text): # <<<<<<<<<<<<<< + * + * reference_names, reference_lengths = [], [] + */ + __pyx_t_4 = __Pyx_GetNameInClass((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_text); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 266, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pysam/libcalignmentfile.pyx":265 + * return self + * + * @classmethod # <<<<<<<<<<<<<< + * def from_text(cls, text): + * */ - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SQ, __pyx_tuple__83) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + __pyx_t_1 = __Pyx_Method_ClassMethod(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 265, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader->tp_dict, __pyx_n_s_from_text, __pyx_t_1) < 0) __PYX_ERR(0, 266, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader); - /* "pysam/libcalignmentfile.pyx":117 - * "SQ" : ("SN", "LN", "AS", "M5", - * "UR", "SP", "AH"), - * "RG" : ("ID", "CN", "SM", "LB", # <<<<<<<<<<<<<< - * "PU", "PI", "DT", "DS", - * "PL", "FO", "KS", "PG", + /* "pysam/libcalignmentfile.pyx":283 + * + * @classmethod + * def from_dict(cls, header_dict): # <<<<<<<<<<<<<< + * + * cdef list lines = [] */ - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_RG, __pyx_tuple__84) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetNameInClass((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_dict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libcalignmentfile.pyx":121 - * "PL", "FO", "KS", "PG", - * "PM"), - * "PG" : ("PN", "ID", "VN", "PP", # <<<<<<<<<<<<<< - * "DS", "CL"),} + /* "pysam/libcalignmentfile.pyx":282 + * return cls._from_text_and_lengths(text, reference_names, reference_lengths) + * + * @classmethod # <<<<<<<<<<<<<< + * def from_dict(cls, header_dict): * */ - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, __pyx_tuple__85) < 0) __PYX_ERR(0, 114, __pyx_L1_error) - if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_ORDER, __pyx_t_1) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + __pyx_t_4 = __Pyx_Method_ClassMethod(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 282, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader->tp_dict, __pyx_n_s_from_dict, __pyx_t_4) < 0) __PYX_ERR(0, 283, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader); - /* "pysam/libcalignmentfile.pyx":125 + /* "pysam/libcalignmentfile.pyx":324 * + * @classmethod + * def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True): # <<<<<<<<<<<<<< * - * def build_header_line(fields, record): # <<<<<<<<<<<<<< - * '''build a header line from `fields` dictionary for `record`''' + * if len(reference_names) != len(reference_lengths): + */ + __pyx_t_4 = __Pyx_GetNameInClass((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_references); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 324, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pysam/libcalignmentfile.pyx":323 + * return cls._from_text_and_lengths(text, reference_names, reference_lengths) + * + * @classmethod # <<<<<<<<<<<<<< + * def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True): * */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_17libcalignmentfile_1build_header_line, NULL, __pyx_n_s_pysam_libcalignmentfile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error) + __pyx_t_1 = __Pyx_Method_ClassMethod(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 323, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_header_line, __pyx_t_1) < 0) __PYX_ERR(0, 125, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader->tp_dict, __pyx_n_s_from_references, __pyx_t_1) < 0) __PYX_ERR(0, 324, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader); - /* "pysam/libcalignmentfile.pyx":2255 + /* "pysam/libcalignmentfile.pyx":2610 * int tid = 0, * int start = 0, - * int end = MAX_POS, # <<<<<<<<<<<<<< + * int stop = MAX_POS, # <<<<<<<<<<<<<< * int truncate = False, * **kwargs ): */ - __pyx_k__71 = __pyx_v_5pysam_17libcalignmentfile_MAX_POS; - - /* "pysam/libcalignmentfile.pyx":2486 - * bam_hdr_destroy(self.header) - * - * __all__ = [ # <<<<<<<<<<<<<< - * "AlignmentFile", - * "IteratorRow", - */ - __pyx_t_1 = PyList_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2486, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_AlignmentFile); - __Pyx_GIVEREF(__pyx_n_s_AlignmentFile); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_AlignmentFile); - __Pyx_INCREF(__pyx_n_s_IteratorRow); - __Pyx_GIVEREF(__pyx_n_s_IteratorRow); - PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_IteratorRow); - __Pyx_INCREF(__pyx_n_s_IteratorColumn); - __Pyx_GIVEREF(__pyx_n_s_IteratorColumn); - PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_IteratorColumn); - __Pyx_INCREF(__pyx_n_s_IndexedReads); - __Pyx_GIVEREF(__pyx_n_s_IndexedReads); - PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_IndexedReads); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_all_2, __pyx_t_1) < 0) __PYX_ERR(0, 2486, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_k__85 = __pyx_v_5pysam_17libcalignmentfile_MAX_POS; /* "(tree fragment)":1 * def __pyx_unpickle_SNPCall(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< @@ -33595,14 +40191,15 @@ if (!__Pyx_RefNanny) { if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_SNPCall, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcalignmentfile.pyx":1 + /* "pysam/libcalignmentfile.pyx":2 + * * # cython: embedsignature=True # <<<<<<<<<<<<<< * # cython: profile=True * ######################################################## */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "array.pxd":161 @@ -33620,6 +40217,7 @@ if (!__Pyx_RefNanny) { __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); if (__pyx_m) { if (__pyx_d) { __Pyx_AddTraceback("init pysam.libcalignmentfile", 0, __pyx_lineno, __pyx_filename); @@ -34643,64 +41241,141 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject } #endif -/* RaiseTooManyValuesToUnpack */ - static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { - PyErr_Format(PyExc_ValueError, - "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected); -} - -/* RaiseNeedMoreValuesToUnpack */ - static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { - PyErr_Format(PyExc_ValueError, - "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack", - index, (index == 1) ? "" : "s"); +/* KeywordStringCheck */ + static int __Pyx_CheckKeywordStrings( + PyObject *kwdict, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; +#if CYTHON_COMPILING_IN_PYPY + if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) + goto invalid_keyword; + return 1; +#else + while (PyDict_Next(kwdict, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_Check(key))) + #endif + if (unlikely(!PyUnicode_Check(key))) + goto invalid_keyword_type; + } + if ((!kw_allowed) && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + return 0; +#endif +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif + return 0; } -/* IterFinish */ - static CYTHON_INLINE int __Pyx_IterFinish(void) { -#if CYTHON_FAST_THREAD_STATE - PyThreadState *tstate = __Pyx_PyThreadState_Current; - PyObject* exc_type = tstate->curexc_type; - if (unlikely(exc_type)) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) { - PyObject *exc_value, *exc_tb; - exc_value = tstate->curexc_value; - exc_tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; - Py_DECREF(exc_type); - Py_XDECREF(exc_value); - Py_XDECREF(exc_tb); - return 0; - } else { - return -1; +/* SliceObject */ + static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj, + Py_ssize_t cstart, Py_ssize_t cstop, + PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice, + int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) { +#if CYTHON_USE_TYPE_SLOTS + PyMappingMethods* mp; +#if PY_MAJOR_VERSION < 3 + PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence; + if (likely(ms && ms->sq_slice)) { + if (!has_cstart) { + if (_py_start && (*_py_start != Py_None)) { + cstart = __Pyx_PyIndex_AsSsize_t(*_py_start); + if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; + } else + cstart = 0; + } + if (!has_cstop) { + if (_py_stop && (*_py_stop != Py_None)) { + cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop); + if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; + } else + cstop = PY_SSIZE_T_MAX; + } + if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) { + Py_ssize_t l = ms->sq_length(obj); + if (likely(l >= 0)) { + if (cstop < 0) { + cstop += l; + if (cstop < 0) cstop = 0; + } + if (cstart < 0) { + cstart += l; + if (cstart < 0) cstart = 0; + } + } else { + if (!PyErr_ExceptionMatches(PyExc_OverflowError)) + goto bad; + PyErr_Clear(); + } } + return ms->sq_slice(obj, cstart, cstop); } - return 0; -#else - if (unlikely(PyErr_Occurred())) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { - PyErr_Clear(); - return 0; +#endif + mp = Py_TYPE(obj)->tp_as_mapping; + if (likely(mp && mp->mp_subscript)) +#endif + { + PyObject* result; + PyObject *py_slice, *py_start, *py_stop; + if (_py_slice) { + py_slice = *_py_slice; } else { - return -1; + PyObject* owned_start = NULL; + PyObject* owned_stop = NULL; + if (_py_start) { + py_start = *_py_start; + } else { + if (has_cstart) { + owned_start = py_start = PyInt_FromSsize_t(cstart); + if (unlikely(!py_start)) goto bad; + } else + py_start = Py_None; + } + if (_py_stop) { + py_stop = *_py_stop; + } else { + if (has_cstop) { + owned_stop = py_stop = PyInt_FromSsize_t(cstop); + if (unlikely(!py_stop)) { + Py_XDECREF(owned_start); + goto bad; + } + } else + py_stop = Py_None; + } + py_slice = PySlice_New(py_start, py_stop, Py_None); + Py_XDECREF(owned_start); + Py_XDECREF(owned_stop); + if (unlikely(!py_slice)) goto bad; } - } - return 0; +#if CYTHON_USE_TYPE_SLOTS + result = mp->mp_subscript(obj, py_slice); +#else + result = PyObject_GetItem(obj, py_slice); #endif -} - -/* UnpackItemEndCheck */ - static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { - if (unlikely(retval)) { - Py_DECREF(retval); - __Pyx_RaiseTooManyValuesError(expected); - return -1; - } else { - return __Pyx_IterFinish(); + if (!_py_slice) { + Py_DECREF(py_slice); + } + return result; } - return 0; + PyErr_Format(PyExc_TypeError, + "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name); +bad: + return NULL; } /* DictGetItem */ @@ -34843,17 +41518,77 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); #else - PyErr_SetExcInfo(local_type, local_value, local_tb); + PyErr_SetExcInfo(local_type, local_value, local_tb); +#endif + return 0; +bad: + *type = 0; + *value = 0; + *tb = 0; + Py_XDECREF(local_type); + Py_XDECREF(local_value); + Py_XDECREF(local_tb); + return -1; +} + +/* RaiseTooManyValuesToUnpack */ + static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { + PyErr_Format(PyExc_ValueError, + "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected); +} + +/* RaiseNeedMoreValuesToUnpack */ + static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { + PyErr_Format(PyExc_ValueError, + "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack", + index, (index == 1) ? "" : "s"); +} + +/* IterFinish */ + static CYTHON_INLINE int __Pyx_IterFinish(void) { +#if CYTHON_FAST_THREAD_STATE + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject* exc_type = tstate->curexc_type; + if (unlikely(exc_type)) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) { + PyObject *exc_value, *exc_tb; + exc_value = tstate->curexc_value; + exc_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; + Py_DECREF(exc_type); + Py_XDECREF(exc_value); + Py_XDECREF(exc_tb); + return 0; + } else { + return -1; + } + } + return 0; +#else + if (unlikely(PyErr_Occurred())) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { + PyErr_Clear(); + return 0; + } else { + return -1; + } + } + return 0; #endif +} + +/* UnpackItemEndCheck */ + static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { + if (unlikely(retval)) { + Py_DECREF(retval); + __Pyx_RaiseTooManyValuesError(expected); + return -1; + } else { + return __Pyx_IterFinish(); + } return 0; -bad: - *type = 0; - *value = 0; - *tb = 0; - Py_XDECREF(local_type); - Py_XDECREF(local_value); - Py_XDECREF(local_tb); - return -1; } /* WriteUnraisableException */ @@ -34898,98 +41633,6 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) #endif } -/* KeywordStringCheck */ - static int __Pyx_CheckKeywordStrings( - PyObject *kwdict, - const char* function_name, - int kw_allowed) -{ - PyObject* key = 0; - Py_ssize_t pos = 0; -#if CYTHON_COMPILING_IN_PYPY - if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) - goto invalid_keyword; - return 1; -#else - while (PyDict_Next(kwdict, &pos, &key, 0)) { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_Check(key))) - #endif - if (unlikely(!PyUnicode_Check(key))) - goto invalid_keyword_type; - } - if ((!kw_allowed) && unlikely(key)) - goto invalid_keyword; - return 1; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%.200s() keywords must be strings", function_name); - return 0; -#endif -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%.200s() got an unexpected keyword argument '%.200s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif - return 0; -} - -/* ArgTypeTest */ - static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) -{ - if (unlikely(!type)) { - PyErr_SetString(PyExc_SystemError, "Missing type object"); - return 0; - } - else if (exact) { - #if PY_MAJOR_VERSION == 2 - if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; - #endif - } - else { - if (likely(__Pyx_TypeCheck(obj, type))) return 1; - } - PyErr_Format(PyExc_TypeError, - "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", - name, type->tp_name, Py_TYPE(obj)->tp_name); - return 0; -} - -/* GetAttr */ - static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { -#if CYTHON_USE_TYPE_SLOTS -#if PY_MAJOR_VERSION >= 3 - if (likely(PyUnicode_Check(n))) -#else - if (likely(PyString_Check(n))) -#endif - return __Pyx_PyObject_GetAttrStr(o, n); -#endif - return PyObject_GetAttr(o, n); -} - -/* HasAttr */ - static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) { - PyObject *r; - if (unlikely(!__Pyx_PyBaseString_Check(n))) { - PyErr_SetString(PyExc_TypeError, - "hasattr(): attribute name must be string"); - return -1; - } - r = __Pyx_GetAttr(o, n); - if (unlikely(!r)) { - PyErr_Clear(); - return 0; - } else { - Py_DECREF(r); - return 1; - } -} - /* PyObjectCallMethod1 */ static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { PyObject *result = NULL; @@ -35056,16 +41699,16 @@ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name /* PyIntBinop */ #if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { #if PY_MAJOR_VERSION < 3 if (likely(PyInt_CheckExact(op1))) { const long b = intval; long x; long a = PyInt_AS_LONG(op1); - x = (long)((unsigned long)a - b); - if (likely((x^a) >= 0 || (x^~b) >= 0)) + x = (long)((unsigned long)a + b); + if (likely((x^a) >= 0 || (x^b) >= 0)) return PyInt_FromLong(x); - return PyLong_Type.tp_as_number->nb_subtract(op1, op2); + return PyLong_Type.tp_as_number->nb_add(op1, op2); } #endif #if CYTHON_USE_PYLONG_INTERNALS @@ -35149,32 +41792,188 @@ static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_U #endif } CYTHON_FALLTHROUGH; - default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2); + default: return PyLong_Type.tp_as_number->nb_add(op1, op2); } } - x = a - b; + x = a + b; return PyLong_FromLong(x); #ifdef HAVE_LONG_LONG long_long: - llx = lla - llb; + llx = lla + llb; return PyLong_FromLongLong(llx); #endif - - + + + } + #endif + if (PyFloat_CheckExact(op1)) { + const long b = intval; + double a = PyFloat_AS_DOUBLE(op1); + double result; + PyFPE_START_PROTECT("add", return NULL) + result = ((double)a) + (double)b; + PyFPE_END_PROTECT(result) + return PyFloat_FromDouble(result); + } + return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2); +} +#endif + +/* PyIntBinop */ + #if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { + if (op1 == op2) { + Py_RETURN_TRUE; + } + #if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(op1))) { + const long b = intval; + long a = PyInt_AS_LONG(op1); + if (a == b) { + Py_RETURN_TRUE; + } else { + Py_RETURN_FALSE; + } + } + #endif + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(PyLong_CheckExact(op1))) { + const long b = intval; + long a; + const digit* digits = ((PyLongObject*)op1)->ob_digit; + const Py_ssize_t size = Py_SIZE(op1); + if (likely(__Pyx_sst_abs(size) <= 1)) { + a = likely(size) ? digits[0] : 0; + if (size == -1) a = -a; + } else { + switch (size) { + case -2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + } + CYTHON_FALLTHROUGH; + case 2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + } + CYTHON_FALLTHROUGH; + case -3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + } + CYTHON_FALLTHROUGH; + case 3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + } + CYTHON_FALLTHROUGH; + case -4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + } + CYTHON_FALLTHROUGH; + case 4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + } + CYTHON_FALLTHROUGH; + #if PyLong_SHIFT < 30 && PyLong_SHIFT != 15 + default: return PyLong_Type.tp_richcompare(op1, op2, Py_EQ); + #else + default: Py_RETURN_FALSE; + #endif + } + } + if (a == b) { + Py_RETURN_TRUE; + } else { + Py_RETURN_FALSE; + } + } + #endif + if (PyFloat_CheckExact(op1)) { + const long b = intval; + double a = PyFloat_AS_DOUBLE(op1); + if ((double)a == (double)b) { + Py_RETURN_TRUE; + } else { + Py_RETURN_FALSE; + } + } + return PyObject_RichCompare(op1, op2, Py_EQ); +} +#endif + +/* ArgTypeTest */ + static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) +{ + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + else if (exact) { + #if PY_MAJOR_VERSION == 2 + if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif + } + else { + if (likely(__Pyx_TypeCheck(obj, type))) return 1; + } + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); + return 0; +} + +/* GetAttr */ + static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { +#if CYTHON_USE_TYPE_SLOTS +#if PY_MAJOR_VERSION >= 3 + if (likely(PyUnicode_Check(n))) +#else + if (likely(PyString_Check(n))) +#endif + return __Pyx_PyObject_GetAttrStr(o, n); +#endif + return PyObject_GetAttr(o, n); +} + +/* HasAttr */ + static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) { + PyObject *r; + if (unlikely(!__Pyx_PyBaseString_Check(n))) { + PyErr_SetString(PyExc_TypeError, + "hasattr(): attribute name must be string"); + return -1; } - #endif - if (PyFloat_CheckExact(op1)) { - const long b = intval; - double a = PyFloat_AS_DOUBLE(op1); - double result; - PyFPE_START_PROTECT("subtract", return NULL) - result = ((double)a) - (double)b; - PyFPE_END_PROTECT(result) - return PyFloat_FromDouble(result); + r = __Pyx_GetAttr(o, n); + if (unlikely(!r)) { + PyErr_Clear(); + return 0; + } else { + Py_DECREF(r); + return 1; } - return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2); } -#endif + +/* ExtTypeTest */ + static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + if (likely(__Pyx_TypeCheck(obj, type))) + return 1; + PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", + Py_TYPE(obj)->tp_name, type->tp_name); + return 0; +} /* PyObjectCallMethod0 */ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { @@ -35421,19 +42220,6 @@ static CYTHON_INLINE int __Pyx_dict_iter_next( return -1; } -/* ExtTypeTest */ - static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { - if (unlikely(!type)) { - PyErr_SetString(PyExc_SystemError, "Missing type object"); - return 0; - } - if (likely(__Pyx_TypeCheck(obj, type))) - return 1; - PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", - Py_TYPE(obj)->tp_name, type->tp_name); - return 0; -} - /* PyIntBinop */ #if !CYTHON_COMPILING_IN_PYPY static PyObject* __Pyx_PyInt_AndObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { @@ -35573,263 +42359,98 @@ static PyObject* __Pyx_PyInt_AndObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED { #if PY_MAJOR_VERSION >= 3 if (level == -1) { - if (strchr(__Pyx_MODULE_NAME, '.')) { - module = PyImport_ImportModuleLevelObject( - name, global_dict, empty_dict, list, 1); - if (!module) { - if (!PyErr_ExceptionMatches(PyExc_ImportError)) - goto bad; - PyErr_Clear(); - } - } - level = 0; - } - #endif - if (!module) { - #if PY_MAJOR_VERSION < 3 - PyObject *py_level = PyInt_FromLong(level); - if (!py_level) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); - Py_DECREF(py_level); - #else - module = PyImport_ImportModuleLevelObject( - name, global_dict, empty_dict, list, level); - #endif - } - } -bad: - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(py_import); - #endif - Py_XDECREF(empty_list); - Py_XDECREF(empty_dict); - return module; -} - -/* None */ - static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { - PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); -} - -/* PyIntBinop */ - #if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { - #if PY_MAJOR_VERSION < 3 - if (likely(PyInt_CheckExact(op1))) { - const long b = intval; - long x; - long a = PyInt_AS_LONG(op1); - x = (long)((unsigned long)a + b); - if (likely((x^a) >= 0 || (x^b) >= 0)) - return PyInt_FromLong(x); - return PyLong_Type.tp_as_number->nb_add(op1, op2); - } - #endif - #if CYTHON_USE_PYLONG_INTERNALS - if (likely(PyLong_CheckExact(op1))) { - const long b = intval; - long a, x; -#ifdef HAVE_LONG_LONG - const PY_LONG_LONG llb = intval; - PY_LONG_LONG lla, llx; -#endif - const digit* digits = ((PyLongObject*)op1)->ob_digit; - const Py_ssize_t size = Py_SIZE(op1); - if (likely(__Pyx_sst_abs(size) <= 1)) { - a = likely(size) ? digits[0] : 0; - if (size == -1) a = -a; - } else { - switch (size) { - case -2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { - a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { - a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case -3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { - a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { - a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case -4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { - a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { - a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - default: return PyLong_Type.tp_as_number->nb_add(op1, op2); - } - } - x = a + b; - return PyLong_FromLong(x); -#ifdef HAVE_LONG_LONG - long_long: - llx = lla + llb; - return PyLong_FromLongLong(llx); -#endif - - - } - #endif - if (PyFloat_CheckExact(op1)) { - const long b = intval; - double a = PyFloat_AS_DOUBLE(op1); - double result; - PyFPE_START_PROTECT("add", return NULL) - result = ((double)a) + (double)b; - PyFPE_END_PROTECT(result) - return PyFloat_FromDouble(result); - } - return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2); -} -#endif - -/* SliceObject */ - static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj, - Py_ssize_t cstart, Py_ssize_t cstop, - PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice, - int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) { -#if CYTHON_USE_TYPE_SLOTS - PyMappingMethods* mp; -#if PY_MAJOR_VERSION < 3 - PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence; - if (likely(ms && ms->sq_slice)) { - if (!has_cstart) { - if (_py_start && (*_py_start != Py_None)) { - cstart = __Pyx_PyIndex_AsSsize_t(*_py_start); - if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; - } else - cstart = 0; - } - if (!has_cstop) { - if (_py_stop && (*_py_stop != Py_None)) { - cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop); - if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; - } else - cstop = PY_SSIZE_T_MAX; - } - if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) { - Py_ssize_t l = ms->sq_length(obj); - if (likely(l >= 0)) { - if (cstop < 0) { - cstop += l; - if (cstop < 0) cstop = 0; - } - if (cstart < 0) { - cstart += l; - if (cstart < 0) cstart = 0; + if (strchr(__Pyx_MODULE_NAME, '.')) { + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, 1); + if (!module) { + if (!PyErr_ExceptionMatches(PyExc_ImportError)) + goto bad; + PyErr_Clear(); } - } else { - if (!PyErr_ExceptionMatches(PyExc_OverflowError)) - goto bad; - PyErr_Clear(); } + level = 0; + } + #endif + if (!module) { + #if PY_MAJOR_VERSION < 3 + PyObject *py_level = PyInt_FromLong(level); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, level); + #endif } - return ms->sq_slice(obj, cstart, cstop); } -#endif - mp = Py_TYPE(obj)->tp_as_mapping; - if (likely(mp && mp->mp_subscript)) -#endif - { +bad: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_import); + #endif + Py_XDECREF(empty_list); + Py_XDECREF(empty_dict); + return module; +} + +/* None */ + static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { + PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); +} + +/* pyfrozenset_new */ + static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it) { + if (it) { PyObject* result; - PyObject *py_slice, *py_start, *py_stop; - if (_py_slice) { - py_slice = *_py_slice; - } else { - PyObject* owned_start = NULL; - PyObject* owned_stop = NULL; - if (_py_start) { - py_start = *_py_start; - } else { - if (has_cstart) { - owned_start = py_start = PyInt_FromSsize_t(cstart); - if (unlikely(!py_start)) goto bad; - } else - py_start = Py_None; - } - if (_py_stop) { - py_stop = *_py_stop; - } else { - if (has_cstop) { - owned_stop = py_stop = PyInt_FromSsize_t(cstop); - if (unlikely(!py_stop)) { - Py_XDECREF(owned_start); - goto bad; - } - } else - py_stop = Py_None; - } - py_slice = PySlice_New(py_start, py_stop, Py_None); - Py_XDECREF(owned_start); - Py_XDECREF(owned_stop); - if (unlikely(!py_slice)) goto bad; +#if CYTHON_COMPILING_IN_PYPY + PyObject* args; + args = PyTuple_Pack(1, it); + if (unlikely(!args)) + return NULL; + result = PyObject_Call((PyObject*)&PyFrozenSet_Type, args, NULL); + Py_DECREF(args); + return result; +#else + if (PyFrozenSet_CheckExact(it)) { + Py_INCREF(it); + return it; } + result = PyFrozenSet_New(it); + if (unlikely(!result)) + return NULL; + if (likely(PySet_GET_SIZE(result))) + return result; + Py_DECREF(result); +#endif + } #if CYTHON_USE_TYPE_SLOTS - result = mp->mp_subscript(obj, py_slice); + return PyFrozenSet_Type.tp_new(&PyFrozenSet_Type, __pyx_empty_tuple, NULL); #else - result = PyObject_GetItem(obj, py_slice); + return PyObject_Call((PyObject*)&PyFrozenSet_Type, __pyx_empty_tuple, NULL); #endif - if (!_py_slice) { - Py_DECREF(py_slice); +} + +/* PySetContains */ + static int __Pyx_PySet_ContainsUnhashable(PyObject *set, PyObject *key) { + int result = -1; + if (PySet_Check(key) && PyErr_ExceptionMatches(PyExc_TypeError)) { + PyObject *tmpkey; + PyErr_Clear(); + tmpkey = __Pyx_PyFrozenSet_New(key); + if (tmpkey != NULL) { + result = PySet_Contains(set, tmpkey); + Py_DECREF(tmpkey); } - return result; } - PyErr_Format(PyExc_TypeError, - "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name); -bad: - return NULL; + return result; +} +static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq) { + int result = PySet_Contains(set, key); + if (unlikely(result < 0)) { + result = __Pyx_PySet_ContainsUnhashable(set, key); + } + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); } /* UnpackUnboundCMethod */ @@ -36053,26 +42674,6 @@ static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject type->tp_clear(obj); } -/* GetVTable */ - static void* __Pyx_GetVtable(PyObject *dict) { - void* ptr; - PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable); - if (!ob) - goto bad; -#if PY_VERSION_HEX >= 0x02070000 - ptr = PyCapsule_GetPointer(ob, 0); -#else - ptr = PyCObject_AsVoidPtr(ob); -#endif - if (!ptr && !PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type"); - Py_DECREF(ob); - return ptr; -bad: - Py_XDECREF(ob); - return NULL; -} - /* PyObject_GenericGetAttrNoDict */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { @@ -36123,24 +42724,6 @@ static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_nam } #endif -/* SetVTable */ - static int __Pyx_SetVtable(PyObject *dict, void *vtable) { -#if PY_VERSION_HEX >= 0x02070000 - PyObject *ob = PyCapsule_New(vtable, 0, 0); -#else - PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); -#endif - if (!ob) - goto bad; - if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0) - goto bad; - Py_DECREF(ob); - return 0; -bad: - Py_XDECREF(ob); - return -1; -} - /* SetupReduce */ static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { int ret; @@ -36217,8 +42800,109 @@ static int __Pyx_setup_reduce(PyObject* type_obj) { return ret; } +/* GetVTable */ + static void* __Pyx_GetVtable(PyObject *dict) { + void* ptr; + PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable); + if (!ob) + goto bad; +#if PY_VERSION_HEX >= 0x02070000 + ptr = PyCapsule_GetPointer(ob, 0); +#else + ptr = PyCObject_AsVoidPtr(ob); +#endif + if (!ptr && !PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type"); + Py_DECREF(ob); + return ptr; +bad: + Py_XDECREF(ob); + return NULL; +} + +/* SetVTable */ + static int __Pyx_SetVtable(PyObject *dict, void *vtable) { +#if PY_VERSION_HEX >= 0x02070000 + PyObject *ob = PyCapsule_New(vtable, 0, 0); +#else + PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); +#endif + if (!ob) + goto bad; + if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0) + goto bad; + Py_DECREF(ob); + return 0; +bad: + Py_XDECREF(ob); + return -1; +} + +/* ClassMethod */ + static PyObject* __Pyx_Method_ClassMethod(PyObject *method) { +#if CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM <= 0x05080000 + if (PyObject_TypeCheck(method, &PyWrapperDescr_Type)) { + return PyClassMethod_New(method); + } +#else +#if CYTHON_COMPILING_IN_PYSTON || CYTHON_COMPILING_IN_PYPY + if (PyMethodDescr_Check(method)) { +#else + static PyTypeObject *methoddescr_type = NULL; + if (methoddescr_type == NULL) { + PyObject *meth = PyObject_GetAttrString((PyObject*)&PyList_Type, "append"); + if (!meth) return NULL; + methoddescr_type = Py_TYPE(meth); + Py_DECREF(meth); + } + if (__Pyx_TypeCheck(method, methoddescr_type)) { +#endif + PyMethodDescrObject *descr = (PyMethodDescrObject *)method; + #if PY_VERSION_HEX < 0x03020000 + PyTypeObject *d_type = descr->d_type; + #else + PyTypeObject *d_type = descr->d_common.d_type; + #endif + return PyDescr_NewClassMethod(d_type, descr->d_method); + } +#endif + else if (PyMethod_Check(method)) { + return PyClassMethod_New(PyMethod_GET_FUNCTION(method)); + } + else if (PyCFunction_Check(method)) { + return PyClassMethod_New(method); + } +#ifdef __Pyx_CyFunction_USED + else if (__Pyx_TypeCheck(method, __pyx_CyFunctionType)) { + return PyClassMethod_New(method); + } +#endif + PyErr_SetString(PyExc_TypeError, + "Class-level classmethod() can only be called on " + "a method_descriptor or instance method."); + return NULL; +} + +/* GetNameInClass */ + static PyObject *__Pyx_GetGlobalNameAfterAttributeLookup(PyObject *name) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + return NULL; + __Pyx_PyErr_Clear(); + return __Pyx_GetModuleGlobalName(name); +} +static PyObject *__Pyx_GetNameInClass(PyObject *nmspace, PyObject *name) { + PyObject *result; + result = __Pyx_PyObject_GetAttrStr(nmspace, name); + if (!result) { + result = __Pyx_GetGlobalNameAfterAttributeLookup(name); + } + return result; +} + /* CLineInTraceback */ - #ifndef CYTHON_CLINE_IN_TRACEBACK + #ifndef CYTHON_CLINE_IN_TRACEBACK static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; @@ -36258,7 +42942,7 @@ static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_li #endif /* CodeObjectCache */ - static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { int start = 0, mid = 0, end = count - 1; if (end >= 0 && code_line > entries[end].code_line) { return count; @@ -36338,7 +43022,7 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { } /* AddTraceback */ - #include "compile.h" + #include "compile.h" #include "frameobject.h" #include "traceback.h" static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( @@ -36423,7 +43107,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { const int neg_one = (int) -1, const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -36454,7 +43138,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPyVerify */ - #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) @@ -36476,7 +43160,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) { const char neg_one = (char) -1, const_zero = (char) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -36507,7 +43191,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -36538,7 +43222,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value) { const int32_t neg_one = (int32_t) -1, const_zero = (int32_t) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -36569,38 +43253,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value) { - const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0; - const int is_unsigned = neg_one > const_zero; - if (is_unsigned) { - if (sizeof(PY_LONG_LONG) < sizeof(long)) { - return PyInt_FromLong((long) value); - } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) { - return PyLong_FromUnsignedLong((unsigned long) value); -#ifdef HAVE_LONG_LONG - } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); -#endif - } - } else { - if (sizeof(PY_LONG_LONG) <= sizeof(long)) { - return PyInt_FromLong((long) value); -#ifdef HAVE_LONG_LONG - } else if (sizeof(PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { - return PyLong_FromLongLong((PY_LONG_LONG) value); -#endif - } - } - { - int one = 1; int little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(PY_LONG_LONG), - little, !is_unsigned); - } -} - -/* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) { const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -36631,55 +43284,24 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value) { const uint64_t neg_one = (uint64_t) -1, const_zero = (uint64_t) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(uint64_t) < sizeof(long)) { return PyInt_FromLong((long) value); - } else if (sizeof(uint64_t) <= sizeof(unsigned long)) { - return PyLong_FromUnsignedLong((unsigned long) value); -#ifdef HAVE_LONG_LONG - } else if (sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG)) { - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); -#endif - } - } else { - if (sizeof(uint64_t) <= sizeof(long)) { - return PyInt_FromLong((long) value); -#ifdef HAVE_LONG_LONG - } else if (sizeof(uint64_t) <= sizeof(PY_LONG_LONG)) { - return PyLong_FromLongLong((PY_LONG_LONG) value); -#endif - } - } - { - int one = 1; int little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(uint64_t), - little, !is_unsigned); - } -} - -/* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value) { - const uint16_t neg_one = (uint16_t) -1, const_zero = (uint16_t) 0; - const int is_unsigned = neg_one > const_zero; - if (is_unsigned) { - if (sizeof(uint16_t) < sizeof(long)) { - return PyInt_FromLong((long) value); - } else if (sizeof(uint16_t) <= sizeof(unsigned long)) { + } else if (sizeof(uint64_t) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(uint16_t) <= sizeof(unsigned PY_LONG_LONG)) { + } else if (sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { - if (sizeof(uint16_t) <= sizeof(long)) { + if (sizeof(uint64_t) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(uint16_t) <= sizeof(PY_LONG_LONG)) { + } else if (sizeof(uint64_t) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } @@ -36687,13 +43309,13 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(uint16_t), + return _PyLong_FromByteArray(bytes, sizeof(uint64_t), little, !is_unsigned); } } /* CIntFromPy */ - static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { + static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { const int neg_one = (int) -1, const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -36882,7 +43504,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPy */ - static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) { + static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) { const char neg_one = (char) -1, const_zero = (char) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -37071,7 +43693,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPy */ - static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { + static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -37260,7 +43882,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPy */ - static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) { + static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) { const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -37449,196 +44071,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPy */ - static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { - const size_t neg_one = (size_t) -1, const_zero = (size_t) 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - if (sizeof(size_t) < sizeof(long)) { - __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG(x)) - } else { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - goto raise_neg_overflow; - } - return (size_t) val; - } - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_USE_PYLONG_INTERNALS - const digit* digits = ((PyLongObject*)x)->ob_digit; - switch (Py_SIZE(x)) { - case 0: return (size_t) 0; - case 1: __PYX_VERIFY_RETURN_INT(size_t, digit, digits[0]) - case 2: - if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(size_t) >= 2 * PyLong_SHIFT) { - return (size_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); - } - } - break; - case 3: - if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(size_t) >= 3 * PyLong_SHIFT) { - return (size_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); - } - } - break; - case 4: - if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(size_t) >= 4 * PyLong_SHIFT) { - return (size_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); - } - } - break; - } -#endif -#if CYTHON_COMPILING_IN_CPYTHON - if (unlikely(Py_SIZE(x) < 0)) { - goto raise_neg_overflow; - } -#else - { - int result = PyObject_RichCompareBool(x, Py_False, Py_LT); - if (unlikely(result < 0)) - return (size_t) -1; - if (unlikely(result == 1)) - goto raise_neg_overflow; - } -#endif - if (sizeof(size_t) <= sizeof(unsigned long)) { - __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned long, PyLong_AsUnsignedLong(x)) -#ifdef HAVE_LONG_LONG - } else if (sizeof(size_t) <= sizeof(unsigned PY_LONG_LONG)) { - __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) -#endif - } - } else { -#if CYTHON_USE_PYLONG_INTERNALS - const digit* digits = ((PyLongObject*)x)->ob_digit; - switch (Py_SIZE(x)) { - case 0: return (size_t) 0; - case -1: __PYX_VERIFY_RETURN_INT(size_t, sdigit, (sdigit) (-(sdigit)digits[0])) - case 1: __PYX_VERIFY_RETURN_INT(size_t, digit, +digits[0]) - case -2: - if (8 * sizeof(size_t) - 1 > 1 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) { - return (size_t) (((size_t)-1)*(((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]))); - } - } - break; - case 2: - if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) { - return (size_t) ((((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]))); - } - } - break; - case -3: - if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) { - return (size_t) (((size_t)-1)*(((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]))); - } - } - break; - case 3: - if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) { - return (size_t) ((((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]))); - } - } - break; - case -4: - if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) { - return (size_t) (((size_t)-1)*(((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]))); - } - } - break; - case 4: - if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) { - return (size_t) ((((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]))); - } - } - break; - } -#endif - if (sizeof(size_t) <= sizeof(long)) { - __PYX_VERIFY_RETURN_INT_EXC(size_t, long, PyLong_AsLong(x)) -#ifdef HAVE_LONG_LONG - } else if (sizeof(size_t) <= sizeof(PY_LONG_LONG)) { - __PYX_VERIFY_RETURN_INT_EXC(size_t, PY_LONG_LONG, PyLong_AsLongLong(x)) -#endif - } - } - { -#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) - PyErr_SetString(PyExc_RuntimeError, - "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); -#else - size_t val; - PyObject *v = __Pyx_PyNumber_IntOrLong(x); - #if PY_MAJOR_VERSION < 3 - if (likely(v) && !PyLong_Check(v)) { - PyObject *tmp = v; - v = PyNumber_Long(tmp); - Py_DECREF(tmp); - } - #endif - if (likely(v)) { - int one = 1; int is_little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - int ret = _PyLong_AsByteArray((PyLongObject *)v, - bytes, sizeof(val), - is_little, !is_unsigned); - Py_DECREF(v); - if (likely(!ret)) - return val; - } -#endif - return (size_t) -1; - } - } else { - size_t val; - PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); - if (!tmp) return (size_t) -1; - val = __Pyx_PyInt_As_size_t(tmp); - Py_DECREF(tmp); - return val; - } -raise_overflow: - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to size_t"); - return (size_t) -1; -raise_neg_overflow: - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to size_t"); - return (size_t) -1; -} - -/* CIntFromPy */ - static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *x) { + static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *x) { const int64_t neg_one = (int64_t) -1, const_zero = (int64_t) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -37827,196 +44260,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPy */ - static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *x) { - const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - if (sizeof(PY_LONG_LONG) < sizeof(long)) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, PyInt_AS_LONG(x)) - } else { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - goto raise_neg_overflow; - } - return (PY_LONG_LONG) val; - } - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_USE_PYLONG_INTERNALS - const digit* digits = ((PyLongObject*)x)->ob_digit; - switch (Py_SIZE(x)) { - case 0: return (PY_LONG_LONG) 0; - case 1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, digit, digits[0]) - case 2: - if (8 * sizeof(PY_LONG_LONG) > 1 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) >= 2 * PyLong_SHIFT) { - return (PY_LONG_LONG) (((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])); - } - } - break; - case 3: - if (8 * sizeof(PY_LONG_LONG) > 2 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) >= 3 * PyLong_SHIFT) { - return (PY_LONG_LONG) (((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])); - } - } - break; - case 4: - if (8 * sizeof(PY_LONG_LONG) > 3 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) >= 4 * PyLong_SHIFT) { - return (PY_LONG_LONG) (((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])); - } - } - break; - } -#endif -#if CYTHON_COMPILING_IN_CPYTHON - if (unlikely(Py_SIZE(x) < 0)) { - goto raise_neg_overflow; - } -#else - { - int result = PyObject_RichCompareBool(x, Py_False, Py_LT); - if (unlikely(result < 0)) - return (PY_LONG_LONG) -1; - if (unlikely(result == 1)) - goto raise_neg_overflow; - } -#endif - if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) { - __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x)) -#ifdef HAVE_LONG_LONG - } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { - __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) -#endif - } - } else { -#if CYTHON_USE_PYLONG_INTERNALS - const digit* digits = ((PyLongObject*)x)->ob_digit; - switch (Py_SIZE(x)) { - case 0: return (PY_LONG_LONG) 0; - case -1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, sdigit, (sdigit) (-(sdigit)digits[0])) - case 1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, digit, +digits[0]) - case -2: - if (8 * sizeof(PY_LONG_LONG) - 1 > 1 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); - } - } - break; - case 2: - if (8 * sizeof(PY_LONG_LONG) > 1 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - return (PY_LONG_LONG) ((((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); - } - } - break; - case -3: - if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); - } - } - break; - case 3: - if (8 * sizeof(PY_LONG_LONG) > 2 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - return (PY_LONG_LONG) ((((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); - } - } - break; - case -4: - if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); - } - } - break; - case 4: - if (8 * sizeof(PY_LONG_LONG) > 3 * PyLong_SHIFT) { - if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { - __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - return (PY_LONG_LONG) ((((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); - } - } - break; - } -#endif - if (sizeof(PY_LONG_LONG) <= sizeof(long)) { - __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, long, PyLong_AsLong(x)) -#ifdef HAVE_LONG_LONG - } else if (sizeof(PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { - __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, PY_LONG_LONG, PyLong_AsLongLong(x)) -#endif - } - } - { -#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) - PyErr_SetString(PyExc_RuntimeError, - "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); -#else - PY_LONG_LONG val; - PyObject *v = __Pyx_PyNumber_IntOrLong(x); - #if PY_MAJOR_VERSION < 3 - if (likely(v) && !PyLong_Check(v)) { - PyObject *tmp = v; - v = PyNumber_Long(tmp); - Py_DECREF(tmp); - } - #endif - if (likely(v)) { - int one = 1; int is_little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - int ret = _PyLong_AsByteArray((PyLongObject *)v, - bytes, sizeof(val), - is_little, !is_unsigned); - Py_DECREF(v); - if (likely(!ret)) - return val; - } -#endif - return (PY_LONG_LONG) -1; - } - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); - if (!tmp) return (PY_LONG_LONG) -1; - val = __Pyx_PyInt_As_PY_LONG_LONG(tmp); - Py_DECREF(tmp); - return val; - } -raise_overflow: - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to PY_LONG_LONG"); - return (PY_LONG_LONG) -1; -raise_neg_overflow: - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG) -1; -} - -/* CIntFromPy */ - static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) { + static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) { const uint64_t neg_one = (uint64_t) -1, const_zero = (uint64_t) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -38205,7 +44449,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* FastTypeChecks */ - #if CYTHON_COMPILING_IN_CPYTHON + #if CYTHON_COMPILING_IN_CPYTHON static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { while (a) { a = a->tp_base; @@ -38277,7 +44521,7 @@ static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObj #endif /* CheckBinaryVersion */ - static int __Pyx_check_binary_version(void) { + static int __Pyx_check_binary_version(void) { char ctversion[4], rtversion[4]; PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); @@ -38293,7 +44537,7 @@ static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObj } /* ModuleImport */ - #ifndef __PYX_HAVE_RT_ImportModule + #ifndef __PYX_HAVE_RT_ImportModule #define __PYX_HAVE_RT_ImportModule static PyObject *__Pyx_ImportModule(const char *name) { PyObject *py_name = 0; @@ -38311,7 +44555,7 @@ static PyObject *__Pyx_ImportModule(const char *name) { #endif /* TypeImport */ - #ifndef __PYX_HAVE_RT_ImportType + #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict) @@ -38376,7 +44620,7 @@ static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class #endif /* FunctionImport */ - #ifndef __PYX_HAVE_RT_ImportFunction + #ifndef __PYX_HAVE_RT_ImportFunction #define __PYX_HAVE_RT_ImportFunction static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) { PyObject *d = 0; @@ -38430,7 +44674,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** #endif /* InitStrings */ - static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { diff --git a/pysam/libcalignmentfile.pxd b/pysam/libcalignmentfile.pxd index 6f32f47cd..741023096 100644 --- a/pysam/libcalignmentfile.pxd +++ b/pysam/libcalignmentfile.pxd @@ -4,7 +4,7 @@ from libc.stdlib cimport malloc, calloc, realloc, free from libc.string cimport memcpy, memcmp, strncpy, strlen, strdup from libc.stdio cimport FILE, printf -from pysam.libcfaidx cimport faidx_t, Fastafile +from pysam.libcfaidx cimport faidx_t, FastaFile from pysam.libcalignedsegment cimport AlignedSegment from pysam.libchtslib cimport * @@ -18,11 +18,6 @@ cdef extern from "htslib_util.h": char * pysam_bam_get_qname(bam1_t * b) -cdef extern from "samfile_util.h": - - int bam_cap_mapQ(bam1_t *b, char *ref, int thres) - int bam_prob_realn(bam1_t *b, const char *ref) - #################################################################### # Utility types @@ -34,15 +29,24 @@ ctypedef struct __iterdata: int tid char * seq int seq_len + int min_mapping_quality + int flag_require + int flag_filter + bint compute_baq + bint redo_baq + bint ignore_orphans + int adjust_capq_threshold +cdef class AlignmentHeader(object): + cdef bam_hdr_t *ptr + cdef class AlignmentFile(HTSFile): cdef readonly object reference_filename + cdef readonly AlignmentHeader header # pointer to index cdef hts_idx_t *index - # header structure - cdef bam_hdr_t * header # current read within iteration cdef bam1_t * b @@ -77,7 +81,8 @@ cdef class IteratorRow: cdef bam1_t * b cdef AlignmentFile samfile cdef htsFile * htsfile - cdef bam_hdr_t * header + cdef hts_idx_t * index + cdef AlignmentHeader header cdef int owns_samfile @@ -86,12 +91,14 @@ cdef class IteratorRowRegion(IteratorRow): cdef bam1_t * getCurrent(self) cdef int cnext(self) + cdef class IteratorRowHead(IteratorRow): cdef int max_rows cdef int current_row cdef bam1_t * getCurrent(self) cdef int cnext(self) + cdef class IteratorRowAll(IteratorRow): cdef bam1_t * getCurrent(self) cdef int cnext(self) @@ -116,31 +123,33 @@ cdef class IteratorColumn: cdef int tid cdef int pos cdef int n_plp - cdef int mask + cdef uint32_t min_base_quality cdef bam_pileup1_t * plp - cdef bam_plp_t pileup_iter + cdef bam_mplp_t pileup_iter cdef __iterdata iterdata cdef AlignmentFile samfile - cdef Fastafile fastafile + cdef FastaFile fastafile cdef stepper cdef int max_depth + cdef bint ignore_overlaps cdef int cnext(self) - cdef char * getSequence(self) - cdef setMask(self, mask) - cdef setupIteratorData(self, - int tid, - int start, - int end, - int multiple_iterators=?) - - cdef reset(self, tid, start, end) + cdef char * get_sequence(self) + cdef _setup_iterator(self, + int tid, + int start, + int stop, + int multiple_iterators=?) + + cdef reset(self, tid, start, stop) cdef _free_pileup_iter(self) - + # backwards compatibility + cdef char * getSequence(self) + cdef class IteratorColumnRegion(IteratorColumn): cdef int start - cdef int end + cdef int stop cdef int truncate @@ -151,6 +160,6 @@ cdef class IteratorColumnAllRefs(IteratorColumn): cdef class IndexedReads: cdef AlignmentFile samfile cdef htsFile * htsfile - cdef index + cdef object index cdef int owns_samfile - cdef bam_hdr_t * header + cdef AlignmentHeader header diff --git a/pysam/libcalignmentfile.pyx b/pysam/libcalignmentfile.pyx index 2161f87f1..30400b10a 100644 --- a/pysam/libcalignmentfile.pyx +++ b/pysam/libcalignmentfile.pyx @@ -1,3 +1,4 @@ + # cython: embedsignature=True # cython: profile=True ######################################################## @@ -7,16 +8,18 @@ # The principal classes defined in this module are: # # class AlignmentFile read/write access to SAM/BAM/CRAM formatted files -# +# +# class AlignmentHeader manage SAM/BAM/CRAM header data +# # class IndexedReads index a SAM/BAM/CRAM file by query name while keeping # the original sort order intact -# +# # Additionally this module defines numerous additional classes that # are part of the internal API. These are: -# +# # Various iterator classes to iterate over alignments in sequential # (IteratorRow) or in a stacked fashion (IteratorColumn): -# +# # class IteratorRow # class IteratorRowRegion # class IteratorRowHead @@ -57,7 +60,6 @@ import collections import re import warnings import array - from libc.errno cimport errno, EPIPE from libc.string cimport strcmp, strpbrk, strerror from cpython cimport array as c_array @@ -75,30 +77,38 @@ else: cimport cython -######################################################## -## Constants and global variables -# defines imported from samtools -DEF SEEK_SET = 0 -DEF SEEK_CUR = 1 -DEF SEEK_END = 2 +__all__ = [ + "AlignmentFile", + "AlignmentHeader", + "IteratorRow", + "IteratorColumn", + "IndexedReads"] +IndexStats = collections.namedtuple("IndexStats", + ("contig", + "mapped", + "unmapped", + "total")) + +######################################################## +## global variables # maximum genomic coordinace -cdef int MAX_POS = 2 << 29 +cdef int MAX_POS = 2 << 29 # valid types for SAM headers -VALID_HEADER_TYPES = {"HD" : dict, - "SQ" : list, - "RG" : list, - "PG" : list, - "CO" : list} +VALID_HEADER_TYPES = {"HD" : collections.Mapping, + "SQ" : collections.Sequence, + "RG" : collections.Sequence, + "PG" : collections.Sequence, + "CO" : collections.Sequence} # order of records within SAM headers VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO") # default type conversions within SAM header records KNOWN_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str}, - "SQ" : {"SN" : str, "LN" : int, "AS" : str, + "SQ" : {"SN" : str, "LN" : int, "AS" : str, "M5" : str, "SP" : str, "UR" : str, "AH" : str,}, "RG" : {"ID" : str, "CN" : str, "DS" : str, @@ -106,7 +116,7 @@ KNOWN_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str}, "LB" : str, "PG" : str, "PI" : str, "PL" : str, "PM" : str, "PU" : str, "SM" : str,}, - "PG" : {"ID" : str, "PN" : str, "CL" : str, + "PG" : {"ID" : str, "PN" : str, "CL" : str, "PP" : str, "DS" : str, "VN" : str,},} # output order of fields within records. Ensure that CL is at @@ -147,94 +157,432 @@ def build_header_line(fields, record): return "\t".join(line) -cdef bam_hdr_t * build_header(new_header): - '''return a new header built from a dictionary in `new_header`. - This method inserts the text field, target_name and target_len. - ''' +cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr): + if not hdr: + raise ValueError('cannot create AlignmentHeader, received NULL pointer') + + # check: is AlignmetHeader.__cinit__ called? + cdef AlignmentHeader header = AlignmentHeader.__new__(AlignmentHeader) + header.ptr = hdr - lines = [] + return header - # check if hash exists - # create new header and copy old data - cdef bam_hdr_t * dest +# the following should be class-method for VariantHeader, but cdef @classmethods +# are not implemented in cython. +cdef int fill_AlignmentHeader_from_list(bam_hdr_t *dest, + reference_names, + reference_lengths, + add_sq_text=True, + text=None) except -1: + """build header from list of reference names and lengths. + """ - dest = bam_hdr_init() +cdef class AlignmentHeader(object): + """header information for a :class:`AlignmentFile` object - # first: defined tags - for record in VALID_HEADERS: - if record in new_header: - ttype = VALID_HEADER_TYPES[record] - data = new_header[record] - if type(data) != type(ttype()): - raise ValueError( - "invalid type for record %s: %s, expected %s" % - (record, type(data), type(ttype()))) - if type(data) is dict: + Parameters + ---------- + header_dict : dict + build header from a multi-level dictionary. The + first level are the four types ('HD', 'SQ', ...). The second + level are a list of lines, with each line being a list of + tag-value pairs. The header is constructed first from all the + defined fields, followed by user tags in alphabetical + order. Alternatively, an :class:`~pysam.AlignmentHeader` + object can be passed directly. + + text : string + use the string provided as the header + + reference_names : list + see reference_lengths + + reference_lengths : list + build header from list of chromosome names and lengths. By + default, 'SQ' and 'LN' tags will be added to the header + text. This option can be changed by unsetting the flag + `add_sq_text`. + + add_sq_text : bool + do not add 'SQ' and 'LN' tags to header. This option permits + construction :term:`SAM` formatted files without a header. + + """ + + # See makeVariantHeader for C constructor + def __cinit__(self): + self.ptr = NULL + + # Python constructor + def __init__(self): + self.ptr = bam_hdr_init() + if self.ptr is NULL: + raise MemoryError("could not create header") + + @classmethod + def _from_text_and_lengths(cls, text, reference_names, reference_lengths): + + cdef AlignmentHeader self = AlignmentHeader() + cdef char *ctext + cdef int l_text + cdef int n, x + if text is not None: + btext = force_bytes(text) + ctext = btext + l_text = len(btext) + self.ptr.text = calloc(l_text + 1, sizeof(char)) + if self.ptr.text == NULL: + raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char)) + self.ptr.l_text = l_text + memcpy(self.ptr.text, ctext, l_text + 1) + + if reference_names and reference_lengths: + reference_names = [force_bytes(ref) for ref in reference_names] + + self.ptr.n_targets = len(reference_names) + + n = sum([len(reference_names) + 1]) + self.ptr.target_name = calloc(n, sizeof(char*)) + if self.ptr.target_name == NULL: + raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *))) + + self.ptr.target_len = calloc(n, sizeof(uint32_t)) + if self.ptr.target_len == NULL: + raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t))) + + for x from 0 <= x < self.ptr.n_targets: + self.ptr.target_len[x] = reference_lengths[x] + name = reference_names[x] + self.ptr.target_name[x] = calloc(len(name) + 1, sizeof(char)) + if self.ptr.target_name[x] == NULL: + raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char))) + strncpy(self.ptr.target_name[x], name, len(name)) + + return self + + @classmethod + def from_text(cls, text): + + reference_names, reference_lengths = [], [] + for line in text.splitlines(): + if line.startswith("@SQ"): + fields = dict([x.split(":", 1) for x in line.split("\t")[1:]]) + try: + reference_names.append(fields["SN"]) + reference_lengths.append(int(fields["LN"])) + except KeyError: + raise KeyError("incomplete sequence information in '%s'" % str(fields)) + except ValueError: + raise ValueError("wrong sequence information in '%s'" % str(fields)) + + return cls._from_text_and_lengths(text, reference_names, reference_lengths) + + @classmethod + def from_dict(cls, header_dict): + + cdef list lines = [] + # first: defined tags + for record in VALID_HEADERS: + if record in header_dict: + data = header_dict[record] + if not isinstance(data, VALID_HEADER_TYPES[record]): + raise ValueError( + "invalid type for record %s: %s, expected %s".format( + record, type(data), VALID_HEADER_TYPES[record])) + if isinstance(data, collections.Mapping): + lines.append(build_header_line(data, record)) + else: + for fields in header_dict[record]: + lines.append(build_header_line(fields, record)) + + # then: user tags (lower case), sorted alphabetically + for record, data in sorted(header_dict.items()): + if record in VALID_HEADERS: + continue + if isinstance(data, collections.Mapping): lines.append(build_header_line(data, record)) else: - for fields in new_header[record]: + for fields in header_dict[record]: lines.append(build_header_line(fields, record)) - # then: user tags (lower case), sorted alphabetically - for record, data in sorted(new_header.items()): - if record in VALID_HEADERS: continue - if type(data) is dict: - lines.append(build_header_line(data, record)) + text = "\n".join(lines) + "\n" + + reference_names, reference_lengths = [], [] + if "SQ" in header_dict: + for fields in header_dict["SQ"]: + try: + reference_names.append(fields["SN"]) + reference_lengths.append(fields["LN"]) + except KeyError: + raise KeyError("incomplete sequence information in '%s'" % str(fields)) + + return cls._from_text_and_lengths(text, reference_names, reference_lengths) + + @classmethod + def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True): + + if len(reference_names) != len(reference_lengths): + raise ValueError("number of reference names and lengths do not match") + + # optionally, if there is no text, add a SAM compatible header to output file. + if text is None and add_sq_text: + text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip( + reference_names, reference_lengths)]) + + return cls._from_text_and_lengths(text, reference_names, reference_lengths) + + def __dealloc__(self): + bam_hdr_destroy(self.ptr) + self.ptr = NULL + + def __bool__(self): + return self.ptr != NULL + + def copy(self): + return makeAlignmentHeader(bam_hdr_dup(self.ptr)) + + property nreferences: + """"int with the number of :term:`reference` sequences in the file. + + This is a read-only attribute.""" + def __get__(self): + return self.ptr.n_targets + + property references: + """tuple with the names of :term:`reference` sequences. This is a + read-only attribute""" + def __get__(self): + t = [] + cdef int x + for x in range(self.ptr.n_targets): + t.append(charptr_to_str(self.ptr.target_name[x])) + return tuple(t) + + property lengths: + """tuple of the lengths of the :term:`reference` sequences. This is a + read-only attribute. The lengths are in the same order as + :attr:`pysam.AlignmentFile.references` + """ + def __get__(self): + t = [] + cdef int x + for x in range(self.ptr.n_targets): + t.append(self.ptr.target_len[x]) + return tuple(t) + + def _build_sequence_section(self): + """return sequence section of header. + + The sequence section is built from the list of reference names and + lengths stored in the BAM-file and not from any @SQ entries that + are part of the header's text section. + """ + + cdef int x + text = [] + for x in range(self.ptr.n_targets): + text.append("@SQ\tSN:{}\tLN:{}\n".format( + force_str(self.ptr.target_name[x]), + self.ptr.target_len[x])) + return "".join(text) + + def to_dict(self): + """return two-level dictionary with header information from the file. + + The first level contains the record (``HD``, ``SQ``, etc) and + the second level contains the fields (``VN``, ``LN``, etc). + + The parser is validating and will raise an AssertionError if + if encounters any record or field tags that are not part of + the SAM specification. Use the + :attr:`pysam.AlignmentFile.text` attribute to get the unparsed + header. + + The parsing follows the SAM format specification with the + exception of the ``CL`` field. This option will consume the + rest of a header line irrespective of any additional fields. + This behaviour has been added to accommodate command line + options that contain characters that are not valid field + separators. + + If no @SQ entries are within the text section of the header, + this will be automatically added from the reference names and + lengths stored in the binary part of the header. + """ + result = collections.OrderedDict() + + # convert to python string + t = self.__str__() + for line in t.split("\n"): + if not line.strip(): + continue + assert line.startswith("@"), \ + "header line without '@': '%s'" % line + fields = line[1:].split("\t") + record = fields[0] + assert record in VALID_HEADER_TYPES, \ + "header line with invalid type '%s': '%s'" % (record, line) + + # treat comments + if record == "CO": + if record not in result: + result[record] = [] + result[record].append("\t".join( fields[1:])) + continue + # the following is clumsy as generators do not work? + x = {} + + for idx, field in enumerate(fields[1:]): + if ":" not in field: + raise ValueError("malformatted header: no ':' in field" ) + key, value = field.split(":", 1) + if key in ("CL",): + # special treatment for command line + # statements (CL). These might contain + # characters that are non-conformant with + # the valid field separators in the SAM + # header. Thus, in contravention to the + # SAM API, consume the rest of the line. + key, value = "\t".join(fields[idx+1:]).split(":", 1) + x[key] = KNOWN_HEADER_FIELDS[record][key](value) + break + + # interpret type of known header record tags, default to str + x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value) + + if VALID_HEADER_TYPES[record] == collections.Mapping: + if record in result: + raise ValueError( + "multiple '%s' lines are not permitted" % record) + + result[record] = x + elif VALID_HEADER_TYPES[record] == collections.Sequence: + if record not in result: result[record] = [] + result[record].append(x) + + # if there are no SQ lines in the header, add the + # reference names from the information in the bam + # file. + # + # Background: c-samtools keeps the textual part of the + # header separate from the list of reference names and + # lengths. Thus, if a header contains only SQ lines, + # the SQ information is not part of the textual header + # and thus are missing from the output. See issue 84. + if "SQ" not in result: + sq = [] + for ref, length in zip(self.references, self.lengths): + sq.append({'LN': length, 'SN': ref }) + result["SQ"] = sq + + return result + + def as_dict(self): + """deprecated: use :meth:`to_dict()`""" + return self.to_dict() + + def get_reference_name(self, tid): + if tid == -1: + return None + if not 0 <= tid < self.ptr.n_targets: + raise ValueError("reference_id %i out of range 0<=tid<%i" % + (tid, self.ptr.n_targets)) + return charptr_to_str(self.ptr.target_name[tid]) + + def get_reference_length(self, reference): + cdef int tid = self.get_tid(reference) + if tid < 0: + raise KeyError("unknown reference {}".format(reference)) else: - for fields in new_header[record]: - lines.append(build_header_line(fields, record)) - - text = "\n".join(lines) + "\n" - if dest.text != NULL: free( dest.text ) - dest.text = calloc(len(text), sizeof(char)) - dest.l_text = len(text) - cdef bytes btext = text.encode('ascii') - strncpy(dest.text, btext, dest.l_text) - - cdef bytes bseqname - # collect targets - if "SQ" in new_header: - seqs = [] - for fields in new_header["SQ"]: - try: - seqs.append( (fields["SN"], fields["LN"] ) ) - except KeyError: - raise KeyError( "incomplete sequence information in '%s'" % str(fields)) + return self.ptr.target_len[tid] + + def is_valid_tid(self, int tid): + """ + return True if the numerical :term:`tid` is valid; False otherwise. - dest.n_targets = len(seqs) - dest.target_name = calloc(dest.n_targets, sizeof(char*)) - dest.target_len = calloc(dest.n_targets, sizeof(uint32_t)) + Note that the unmapped tid code (-1) counts as an invalid. + """ + return 0 <= tid < self.ptr.n_targets - for x from 0 <= x < dest.n_targets: - seqname, seqlen = seqs[x] - dest.target_name[x] = calloc( - len(seqname) + 1, sizeof(char)) - bseqname = seqname.encode('ascii') - strncpy(dest.target_name[x], bseqname, - len(seqname) + 1) - dest.target_len[x] = seqlen + def get_tid(self, reference): + """ + return the numerical :term:`tid` corresponding to + :term:`reference` - return dest + returns -1 if reference is not known. + """ + reference = force_bytes(reference) + return bam_name2id(self.ptr, reference) + + def __str__(self): + '''string with the full contents of the :term:`sam file` header as a + string. + + If no @SQ entries are within the text section of the header, + this will be automatically added from the reference names and + lengths stored in the binary part of the header. + + See :attr:`pysam.AlignmentFile.header.to_dict()` to get a parsed + representation of the header. + ''' + text = from_string_and_size(self.ptr.text, self.ptr.l_text) + if "@SQ" not in text: + text += "\n" + self._build_sequence_section() + return text + + # dictionary access methods, for backwards compatibility. + def __setitem__(self, key, value): + raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()") + + def __getitem__(self, key): + return self.to_dict().__getitem__(key) + + def items(self): + return self.to_dict().items() + + # PY2 compatibility + def iteritems(self): + return self.to_dict().items() + + def keys(self): + return self.to_dict().keys() + + def values(self): + return self.to_dict().values() + + def get(self, *args): + return self.to_dict().get(*args) + + def __len__(self): + return self.to_dict().__len__() + + def __contains__(self, key): + return self.to_dict().__contains__(key) cdef class AlignmentFile(HTSFile): """AlignmentFile(filepath_or_object, mode=None, template=None, reference_names=None, reference_lengths=None, text=NULL, header=None, add_sq_text=False, check_header=True, check_sq=True, - reference_filename=None, filename=None, duplicate_filehandle=True) + reference_filename=None, filename=None, index_filename=None, + filepath_index=None, require_index=False, duplicate_filehandle=True, + ignore_truncation=False, threads=1) - A :term:`SAM`/:term:`BAM` formatted file. + A :term:`SAM`/:term:`BAM`/:term:`CRAM` formatted file. If `filepath_or_object` is a string, the file is automatically opened. If `filepath_or_object` is a python File object, the already opened file will be used. - If the file is opened for reading an index for a BAM file exists - (.bai), it will be opened automatically. Without an index random - access via :meth:`~pysam.AlignmentFile.fetch` and - :meth:`~pysam.AlignmentFile.pileup` is disabled. + If the file is opened for reading and an index exists (if file is BAM, a + .bai file or if CRAM a .crai file), it will be opened automatically. + `index_filename` may be specified explicitly. If the index is not named + in the standard manner, not located in the same directory as the + BAM/CRAM file, or is remote. Without an index, random access via + :meth:`~pysam.AlignmentFile.fetch` and :meth:`~pysam.AlignmentFile.pileup` + is disabled. For writing, the header of a :term:`SAM` file/:term:`BAM` file can be constituted from several sources (see also the samtools format @@ -245,7 +593,7 @@ cdef class AlignmentFile(HTSFile): :class:`~pysam.AlignmentFile`). 2. If `header` is given, the header is built from a - multi-level dictionary. + multi-level dictionary. 3. If `text` is given, new header text is copied from raw text. @@ -284,33 +632,42 @@ cdef class AlignmentFile(HTSFile): f2 = pysam.AlignmentFile('ex1.sam') template : AlignmentFile - when writing, copy header frem `template`. + when writing, copy header from file `template`. - header : dict + header : dict or AlignmentHeader when writing, build header from a multi-level dictionary. The first level are the four types ('HD', 'SQ', ...). The second level are a list of lines, with each line being a list of tag-value pairs. The header is constructed first from all the - defined fields, followed by user tags in alphabetical order. + defined fields, followed by user tags in alphabetical + order. Alternatively, an :class:`~pysam.AlignmentHeader` + object can be passed directly. text : string when writing, use the string provided as the header reference_names : list - see referece_lengths + see reference_lengths reference_lengths : list - when writing, build header from list of chromosome names and - lengths. By default, 'SQ' and 'LN' tags will be added to the - header text. This option can be changed by unsetting the flag - `add_sq_text`. + when writing or opening a SAM file without header build header + from list of chromosome names and lengths. By default, 'SQ' + and 'LN' tags will be added to the header text. This option + can be changed by unsetting the flag `add_sq_text`. add_sq_text : bool do not add 'SQ' and 'LN' tags to header. This option permits construction :term:`SAM` formatted files without a header. + add_sam_header : bool + when outputting SAM the default is to output a header. This is + equivalent to opening the file in 'wh' mode. If this option is + set to False, no header will be output. To read such a file, + set `check_header=False`. + check_header : bool - when reading, check if header is present (default=True) + obsolete: when reading a SAM file, check if header is present + (default=True) check_sq : bool when reading, check if SQ entries are present in header @@ -322,11 +679,24 @@ cdef class AlignmentFile(HTSFile): specified in the header (``UR`` tag), which are normally used to find the reference. + index_filename : string + Explicit path to the index file. Only needed if the index is not + named in the standard manner, not located in the same directory as + the BAM/CRAM file, or is remote. An IOError is raised if the index + cannot be found or is invalid. + + filepath_index : string + Alias for `index_filename`. + + require_index : bool + When reading, require that an index file is present and is valid or + raise an IOError. (default=False) + filename : string Alternative to filepath_or_object. Filename of the file to be opened. - duplicate_filehandle: bool + duplicate_filehandle: bool By default, file handles passed either directly or through File-like objects will be duplicated before passing them to htslib. The duplication prevents issues where the same stream @@ -334,12 +704,25 @@ cdef class AlignmentFile(HTSFile): high-level python object. Set to False to turn off duplication. + ignore_truncation: bool + Issue a warning, instead of raising an error if the current file + appears to be truncated due to a missing EOF marker. Only applies + to bgzipped formats. (Default=False) + + format_options: list + A list of key=value strings, as accepted by --input-fmt-option and + --output-fmt-option in samtools. + threads: integer + Number of threads to use for compressing/decompressing BAM/CRAM files. + Setting threads to > 1 cannot be combined with `ignore_truncation`. + (Default=1) """ def __cinit__(self, *args, **kwargs): self.htsfile = NULL self.filename = None self.mode = None + self.threads = 1 self.is_stream = False self.is_remote = False self.index = NULL @@ -352,6 +735,8 @@ cdef class AlignmentFile(HTSFile): # allocate memory for iterator self.b = calloc(1, sizeof(bam1_t)) + if self.b == NULL: + raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t))) def has_index(self): """return true if htsfile has an existing (and opened) index. @@ -393,21 +778,38 @@ cdef class AlignmentFile(HTSFile): header=None, port=None, add_sq_text=True, + add_sam_header=True, check_header=True, check_sq=True, + index_filename=None, filepath_index=None, + require_index=False, referencenames=None, referencelengths=None, - duplicate_filehandle=True): + duplicate_filehandle=True, + ignore_truncation=False, + format_options=None, + threads=1): '''open a sam, bam or cram formatted file. If _open is called on an existing file, the current file will be closed and a new file will be opened. + ''' cdef char *cfilename = NULL cdef char *creference_filename = NULL cdef char *cindexname = NULL cdef char *cmode = NULL + cdef bam_hdr_t * hdr = NULL + + if threads > 1 and ignore_truncation: + # This won't raise errors if reaching a truncated alignment, + # because bgzf_mt_reader in htslib does not deal with + # bgzf_mt_read_block returning non-zero values, contrary + # to bgzf_read (https://github.com/samtools/htslib/blob/1.7/bgzf.c#L888) + # Better to avoid this (for now) than to produce seemingly correct results. + raise ValueError('Cannot add extra threads when "ignore_truncation" is True') + self.threads = threads # for backwards compatibility: if referencenames is not None: @@ -423,6 +825,9 @@ cdef class AlignmentFile(HTSFile): if mode is None: mode = "r" + if add_sam_header and mode == "w": + mode = "wh" + assert mode in ("r", "w", "rb", "wb", "wh", "wbu", "rU", "wb0", "rc", "wc"), \ @@ -468,64 +873,44 @@ cdef class AlignmentFile(HTSFile): self.reference_filename = reference_filename = encode_filename( reference_filename) - cdef char * ctext - cdef hFILE * fp - ctext = NULL - if mode[0] == 'w': # open file for writing - # header structure (used for writing) + if not (template or header or reference_names): + raise ValueError( + "either supply options `template`, `header` or both `reference_names` " + "and `reference_lengths` for writing") + if template: - self.header = bam_hdr_dup(template.header) - elif header: - self.header = build_header(header) + # header is copied, though at the moment not strictly + # necessary as AlignmentHeader is immutable. + self.header = template.header.copy() + elif isinstance(header, AlignmentHeader): + self.header = header.copy() + elif isinstance(header, collections.Mapping): + self.header = AlignmentHeader.from_dict(header) + elif reference_names and reference_lengths: + self.header = AlignmentHeader.from_references( + reference_names, + reference_lengths, + add_sq_text=add_sq_text, + text=text) + elif text: + self.header = AlignmentHeader.from_text(text) else: - # build header from a target names and lengths - assert reference_names and reference_lengths, \ - ("either supply options `template`, `header` " - "or both `reference_names` and `reference_lengths` " - "for writing") - assert len(reference_names) == len(reference_lengths), \ - "unequal names and lengths of reference sequences" - - # allocate and fill header - reference_names = [force_bytes(ref) for ref in reference_names] - self.header = bam_hdr_init() - self.header.n_targets = len(reference_names) - n = 0 - for x in reference_names: - n += len(x) + 1 - self.header.target_name = calloc(n, sizeof(char*)) - self.header.target_len = calloc(n, sizeof(uint32_t)) - for x from 0 <= x < self.header.n_targets: - self.header.target_len[x] = reference_lengths[x] - name = reference_names[x] - self.header.target_name[x] = calloc( - len(name) + 1, sizeof(char)) - strncpy(self.header.target_name[x], name, len(name)) - - # Optionally, if there is no text, add a SAM - # compatible header to output file. - if text is None and add_sq_text: - text = [] - for x from 0 <= x < self.header.n_targets: - text.append("@SQ\tSN:%s\tLN:%s\n" % \ - (force_str(reference_names[x]), - reference_lengths[x])) - text = ''.join(text) - - if text is not None: - # copy without \0 - text = force_bytes(text) - ctext = text - self.header.l_text = strlen(ctext) - self.header.text = calloc( - strlen(ctext), sizeof(char)) - memcpy(self.header.text, ctext, strlen(ctext)) - + raise ValueError("not enough information to construct header. Please provide template, " + "header, text or reference_names/reference_lengths") self.htsfile = self._open_htsfile() + if self.htsfile == NULL: + if errno: + raise IOError(errno, "could not open alignment file `{}`: {}".format( + force_str(filename), + force_str(strerror(errno)))) + else: + raise ValueError("could not open alignment file `{}`".format(force_str(filename))) + if format_options and len(format_options): + self.add_hts_options(format_options) # set filename with reference sequences. If no filename # is given, the CRAM reference arrays will be built from # the @SQ header in the header @@ -535,44 +920,58 @@ cdef class AlignmentFile(HTSFile): # write header to htsfile if "b" in mode or "c" in mode or "h" in mode: + hdr = self.header.ptr with nogil: - sam_hdr_write(self.htsfile, self.header) + sam_hdr_write(self.htsfile, hdr) elif mode[0] == "r": # open file for reading - if not self._exists(): - raise IOError("file `%s` not found" % self.filename) - self.htsfile = self._open_htsfile() if self.htsfile == NULL: - raise ValueError( - "could not open file (mode='%s') - " - "is it SAM/BAM format?" % mode) + if errno: + raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename), + force_str(strerror(errno)))) + else: + raise ValueError("could not open alignment file `{}`".format(force_str(filename))) if self.htsfile.format.category != sequence_data: raise ValueError("file does not contain alignment data") - # bam files require a valid header + if format_options and len(format_options): + self.add_hts_options(format_options) + + self.check_truncation(ignore_truncation) + + # bam/cram files require a valid header if self.is_bam or self.is_cram: with nogil: - self.header = sam_hdr_read(self.htsfile) - if self.header == NULL: + hdr = sam_hdr_read(self.htsfile) + if hdr == NULL: raise ValueError( - "file does not have valid header (mode='%s') " - "- is it BAM format?" % mode ) + "file does not have a valid header (mode='%s') " + "- is it BAM/CRAM format?" % mode) + self.header = makeAlignmentHeader(hdr) else: - # in sam files it is optional (htsfile full of - # unmapped reads) - if check_header: + # in sam files a header is optional. If not given, + # user may provide reference names and lengths to built + # an on-the-fly header. + if reference_names and reference_lengths: + # build header from a target names and lengths + self.header = AlignmentHeader.from_references( + reference_names=reference_names, + reference_lengths=reference_lengths, + add_sq_text=add_sq_text, + text=text) + else: with nogil: - self.header = sam_hdr_read(self.htsfile) - if self.header == NULL: + hdr = sam_hdr_read(self.htsfile) + if hdr == NULL: raise ValueError( - "file does not have valid header (mode='%s') " - "- is it SAM format?" % mode ) - # self.header.ignore_sam_err = True - + "SAM? file does not have a valid header (mode='%s'), " + "please provide reference_names and reference_lengths") + self.header = makeAlignmentHeader(hdr) + # set filename with reference sequences if self.is_cram and reference_filename: creference_filename = self.reference_filename @@ -580,196 +979,52 @@ cdef class AlignmentFile(HTSFile): CRAM_OPT_REFERENCE, creference_filename) - if check_sq and self.header.n_targets == 0: + if check_sq and self.header.nreferences == 0: raise ValueError( ("file has no sequences defined (mode='%s') - " "is it SAM/BAM format? Consider opening with " "check_sq=False") % mode) - assert self.htsfile != NULL - - # check for index and open if present - cdef int format_index = -1 - if self.is_bam: - format_index = HTS_FMT_BAI - elif self.is_cram: - format_index = HTS_FMT_CRAI - - if mode[0] == "r" and (self.is_bam or self.is_cram): - # open index for remote files - if self.is_remote and not filepath_index: - with nogil: - self.index = hts_idx_load(cfilename, format_index) - if self.index == NULL: - warnings.warn( - "unable to open remote index for '%s'" % cfilename) - else: - has_index = True - if filepath_index: - if not os.path.exists(filepath_index): - warnings.warn( - "unable to open index at %s" % cfilename) - self.index = NULL - has_index = False - elif filename is not None: - if self.is_bam \ - and not os.path.exists(filename + b".bai") \ - and not os.path.exists(filename[:-4] + b".bai") \ - and not os.path.exists(filename + b".csi") \ - and not os.path.exists(filename[:-4] + b".csi"): - self.index = NULL - has_index = False - elif self.is_cram \ - and not os.path.exists(filename + b".crai") \ - and not os.path.exists(filename[:-5] + b".crai"): - self.index = NULL - has_index = False - else: - self.index = NULL - has_index = False - - if has_index: - # returns NULL if there is no index or index could - # not be opened - if filepath_index: - cindexname = filepath_index = encode_filename(filepath_index) - with nogil: - self.index = sam_index_load2(self.htsfile, - cfilename, - cindexname) - else: - with nogil: - self.index = sam_index_load(self.htsfile, - cfilename) - if self.index == NULL: - raise IOError( - "error while opening index for '%s'" % - filename) - - # save start of data section - if not self.is_stream: - self.start_offset = self.tell() - - def get_tid(self, reference): - """ - return the numerical :term:`tid` corresponding to - :term:`reference` - - returns -1 if reference is not known. - """ - if not self.is_open: - raise ValueError("I/O operation on closed file") - reference = force_bytes(reference) - return bam_name2id(self.header, reference) - - def get_reference_name(self, tid): - """ - return :term:`reference` name corresponding to numerical :term:`tid` - """ - if not self.is_open: - raise ValueError("I/O operation on closed file") - if not 0 <= tid < self.header.n_targets: - raise ValueError("reference_id %i out of range 0<=tid<%i" % - (tid, self.header.n_targets)) - return charptr_to_str(self.header.target_name[tid]) - - def parse_region(self, - reference=None, - start=None, - end=None, - region=None, - tid=None): - """parse alternative ways to specify a genomic region. A region can - either be specified by :term:`reference`, `start` and - `end`. `start` and `end` denote 0-based, half-open - intervals. - - Alternatively, a samtools :term:`region` string can be - supplied. - - If any of the coordinates are missing they will be replaced by the - minimum (`start`) or maximum (`end`) coordinate. - - Note that region strings are 1-based, while `start` and `end` denote - an interval in python coordinates. - - Returns - ------- - - tuple : a tuple of `flag`, :term:`tid`, `start` and `end`. The - flag indicates whether no coordinates were supplied and the - genomic region is the complete genomic space. - - Raises - ------ - - ValueError - for invalid or out of bounds regions. + if self.is_bam or self.is_cram: + self.index_filename = index_filename or filepath_index + if self.index_filename: + cindexname = bfile_name = encode_filename(self.index_filename) - """ - cdef int rtid - cdef long long rstart - cdef long long rend - - rtid = -1 - rstart = 0 - rend = MAX_POS - if start != None: - try: - rstart = start - except OverflowError: - raise ValueError('start out of range (%i)' % start) + if cfilename or cindexname: + with nogil: + self.index = sam_index_load2(self.htsfile, cfilename, cindexname) - if end != None: - try: - rend = end - except OverflowError: - raise ValueError('end out of range (%i)' % end) - - if region: - region = force_str(region) - parts = re.split("[:-]", region) - reference = parts[0] - if len(parts) >= 2: - rstart = int(parts[1]) - 1 - if len(parts) >= 3: - rend = int(parts[2]) - - if not reference: - return 0, 0, 0, 0 - - if tid is not None: - rtid = tid - else: - rtid = self.gettid(reference) + if not self.index and (cindexname or require_index): + if errno: + raise IOError(errno, force_str(strerror(errno))) + else: + raise IOError('unable to open index file `%s`' % self.index_filename) - if rtid < 0: - raise ValueError( - "invalid reference `%s`" % reference) - if rstart > rend: - raise ValueError( - 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend)) - if not 0 <= rstart < MAX_POS: - raise ValueError('start out of range (%i)' % rstart) - if not 0 <= rend <= MAX_POS: - raise ValueError('end out of range (%i)' % rend) + elif require_index: + raise IOError('unable to open index file') - return 1, rtid, rstart, rend + # save start of data section + if not self.is_stream: + self.start_offset = self.tell() def fetch(self, - reference=None, + contig=None, start=None, - end=None, + stop=None, region=None, tid=None, until_eof=False, - multiple_iterators=False): - """fetch reads aligned in a :term:`region`. + multiple_iterators=False, + reference=None, + end=None): + """fetch reads aligned in a :term:`region`. See :meth:`AlignmentFile.parse_region` for more information - on genomic regions. + on genomic regions. :term:`reference` and `end` are also accepted for + backward compatiblity as synonyms for :term:`contig` and `stop`, + respectively. - Without a `reference` or `region` all mapped reads in the file + Without a `contig` or `region` all mapped reads in the file will be fetched. The reads will be returned ordered by reference sequence, which will not necessarily be the order within the file. This mode of iteration still requires an index. If there is @@ -779,7 +1034,7 @@ cdef class AlignmentFile(HTSFile): will be fetched. A :term:`SAM` file does not allow random access. If `region` - or `reference` are given, an exception is raised. + or `contig` are given, an exception is raised. :class:`~pysam.FastaFile` :class:`~pysam.IteratorRow` @@ -789,7 +1044,7 @@ cdef class AlignmentFile(HTSFile): Parameters ---------- - + until_eof : bool If `until_eof` is True, all reads from the current file @@ -797,7 +1052,7 @@ cdef class AlignmentFile(HTSFile): file. Using this option will also fetch unmapped reads. multiple_iterators : bool - + If `multiple_iterators` is True, multiple iterators on the same file can be used at the same time. The iterator returned will receive its own copy of a filehandle to @@ -817,19 +1072,16 @@ cdef class AlignmentFile(HTSFile): file does not permit random access to genomic coordinates. """ - cdef int rtid, rstart, rend, has_coord + cdef int rtid, rstart, rstop, has_coord if not self.is_open: raise ValueError( "I/O operation on closed file" ) - has_coord, rtid, rstart, rend = self.parse_region( - reference, - start, - end, - region, - tid) + has_coord, rtid, rstart, rstop = self.parse_region( + contig, start, stop, region, tid, + end=end, reference=reference) - # Turn of re-opening if htsfile is a stream + # Turn of re-opening if htsfile is a stream if self.is_stream: multiple_iterators = False @@ -841,7 +1093,7 @@ cdef class AlignmentFile(HTSFile): if has_coord: return IteratorRowRegion( - self, rtid, rstart, rend, + self, rtid, rstart, rstop, multiple_iterators=multiple_iterators) else: if until_eof: @@ -857,22 +1109,17 @@ cdef class AlignmentFile(HTSFile): else: if has_coord: raise ValueError( - "fetching by region is not available for sam files") + "fetching by region is not available for SAM files") - if self.header == NULL: + if multiple_iterators == True: raise ValueError( - "fetch called for htsfile without header") + "multiple iterators not implemented for SAM files") - # check if targets are defined - # give warning, sam_read1 segfaults - if self.header.n_targets == 0: - warnings.warn("fetch called for htsfile without header") - return IteratorRowAll(self, multiple_iterators=multiple_iterators) def head(self, n, multiple_iterators=True): - '''return an iterator over the first n alignments. + '''return an iterator over the first n alignments. This iterator is is useful for inspecting the bam-file. @@ -880,15 +1127,15 @@ cdef class AlignmentFile(HTSFile): ---------- multiple_iterators : bool - + is set to True by default in order to avoid changing the current file position. - + Returns ------- - + an iterator over a collection of reads - + ''' return IteratorRowHead(self, n, multiple_iterators=multiple_iterators) @@ -903,14 +1150,14 @@ cdef class AlignmentFile(HTSFile): not re-opened the file. .. note:: - + This method is too slow for high-throughput processing. If a read needs to be processed with its mate, work from a read name sorted file or, better, cache reads. Returns ------- - + :class:`~pysam.AlignedSegment` : the mate Raises @@ -953,23 +1200,27 @@ cdef class AlignmentFile(HTSFile): return mate def pileup(self, - reference=None, + contig=None, start=None, - end=None, + stop=None, region=None, + reference=None, + end=None, **kwargs): """perform a :term:`pileup` within a :term:`region`. The region is - specified by :term:`reference`, 'start' and 'end' (using - 0-based indexing). Alternatively, a samtools 'region' string + specified by :term:`contig`, `start` and `stop` (using + 0-based indexing). :term:`reference` and `end` are also accepted for + backward compatiblity as synonyms for :term:`contig` and `stop`, + respectively. Alternatively, a samtools 'region' string can be supplied. - Without 'reference' or 'region' all reads will be used for the + Without 'contig' or 'region' all reads will be used for the pileup. The reads will be returned ordered by - :term:`reference` sequence, which will not necessarily be the + :term:`contig` sequence, which will not necessarily be the order within the file. Note that :term:`SAM` formatted files do not allow random - access. In these files, if a 'region' or 'reference' are + access. In these files, if a 'region' or 'contig' are given an exception is raised. .. note:: @@ -982,6 +1233,16 @@ cdef class AlignmentFile(HTSFile): Parameters ---------- + truncate : bool + + By default, the samtools pileup engine outputs all reads + overlapping a region. If truncate is True and a region is + given, only columns in the exact region specificied are + returned. + + max_depth : int + Maximum read depth permitted. The default limit is '8000'. + stepper : string The stepper controls how the iterator advances. Possible options for the stepper are @@ -991,26 +1252,67 @@ cdef class AlignmentFile(HTSFile): BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL, BAM_FDUP ``nofilter`` - uses every single read + uses every single read turning off any filtering. ``samtools`` same filter and read processing as in :term:`csamtools` - pileup. This requires a 'fastafile' to be given. - + pileup. For full compatibility, this requires a + 'fastafile' to be given. The following options all pertain + to filtering of the ``samtools`` stepper. fastafile : :class:`~pysam.FastaFile` object. This is required for some of the steppers. - max_depth : int - Maximum read depth permitted. The default limit is '8000'. + ignore_overlaps: bool - truncate : bool + If set to True, detect if read pairs overlap and only take + the higher quality base. This is the default. - By default, the samtools pileup engine outputs all reads - overlapping a region. If truncate is True and a region is - given, only columns in the exact region specificied are - returned. + flag_filter : int + + ignore reads where any of the bits in the flag are set. The default is + BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP. + + flag_require : int + + only use reads where certain flags are set. The default is 0. + + ignore_orphans: bool + + ignore orphans (paired reads that are not in a proper pair). + The default is to ignore orphans. + + min_base_quality: int + + Minimum base quality. Bases below the minimum quality will + not be output. + + adjust_capq_threshold: int + + adjust mapping quality. The default is 0 for no + adjustment. The recommended value for adjustment is 50. + + min_mapping_quality : int + + only use reads above a minimum mapping quality. The default is 0. + + compute_baq: bool + + re-alignment computing per-Base Alignment Qualities (BAQ). The + default is to do re-alignment. Realignment requires a reference + sequence. If none is present, no realignment will be performed. + + redo_baq: bool + + recompute per-Base Alignment Quality on the fly ignoring + existing base qualities. The default is False (use existing + base qualities). + + adjust_capq_threshold: int + + adjust mapping quality. The default is 0 for no + adjustment. The recommended value for adjustment is 50. Returns ------- @@ -1018,13 +1320,13 @@ cdef class AlignmentFile(HTSFile): an iterator over genomic positions. """ - cdef int rtid, rstart, rend, has_coord + cdef int rtid, rstart, rstop, has_coord if not self.is_open: raise ValueError("I/O operation on closed file") - has_coord, rtid, rstart, rend = self.parse_region( - reference, start, end, region) + has_coord, rtid, rstart, rstop = self.parse_region( + contig, start, stop, region, reference=reference, end=end) if self.is_bam or self.is_cram: if not self.has_index(): @@ -1034,48 +1336,52 @@ cdef class AlignmentFile(HTSFile): return IteratorColumnRegion(self, tid=rtid, start=rstart, - end=rend, - **kwargs ) + stop=rstop, + **kwargs) else: - return IteratorColumnAllRefs(self, **kwargs ) + return IteratorColumnAllRefs(self, **kwargs) else: raise NotImplementedError( "pileup of samfiles not implemented yet") def count(self, - reference=None, + contig=None, start=None, - end=None, + stop=None, region=None, until_eof=False, - read_callback="nofilter"): + read_callback="nofilter", + reference=None, + end=None): '''count the number of reads in :term:`region` - The region is specified by :term:`reference`, `start` and - `end`. Alternatively, a :term:`samtools` :term:`region` string - can be supplied. + The region is specified by :term:`contig`, `start` and `stop`. + :term:`reference` and `end` are also accepted for backward + compatiblity as synonyms for :term:`contig` and `stop`, + respectively. Alternatively, a :term:`samtools` :term:`region` + string can be supplied. A :term:`SAM` file does not allow random access and if - `region` or `reference` are given, an exception is raised. + `region` or `contig` are given, an exception is raised. Parameters ---------- - - reference : string + + contig : string reference_name of the genomic region (chromosome) start : int - start of the genomic region + start of the genomic region (0-based inclusive) + + stop : int + end of the genomic region (0-based exclusive) - end : int - end of the genomic region - region : string a region string in samtools format. until_eof : bool - count until the end of the file, possibly including + count until the end of the file, possibly including unmapped reads as well. read_callback: string or function @@ -1095,6 +1401,12 @@ cdef class AlignmentFile(HTSFile): ``check_read(read)`` that should return True only for those reads that shall be included in the counting. + reference : string + backward compatible synonym for `contig` + + end : int + backward compatible synonym for `stop` + Raises ------ @@ -1114,8 +1426,10 @@ cdef class AlignmentFile(HTSFile): elif read_callback == "nofilter": filter_method = 2 - for read in self.fetch(reference=reference, + for read in self.fetch(contig=contig, start=start, + stop=stop, + reference=reference, end=end, region=region, until_eof=until_eof): @@ -1135,37 +1449,43 @@ cdef class AlignmentFile(HTSFile): return counter @cython.boundscheck(False) # we do manual bounds checking - def count_coverage(self, - reference=None, + def count_coverage(self, + contig, start=None, - end=None, + stop=None, region=None, quality_threshold=15, - read_callback='all'): + read_callback='all', + reference=None, + end=None): """count the coverage of genomic positions by reads in :term:`region`. - The region is specified by :term:`reference`, `start` and - `end`. Alternatively, a :term:`samtools` :term:`region` string - can be supplied. The coverage is computed per-base [ACGT]. + The region is specified by :term:`contig`, `start` and `stop`. + :term:`reference` and `end` are also accepted for backward + compatiblity as synonyms for :term:`contig` and `stop`, + respectively. Alternatively, a :term:`samtools` :term:`region` + string can be supplied. The coverage is computed per-base [ACGT]. Parameters ---------- - - reference : string + + contig : string reference_name of the genomic region (chromosome) start : int - start of the genomic region + start of the genomic region (0-based inclusive). If not + given, count from the start of the chromosome. - end : int - end of the genomic region + stop : int + end of the genomic region (0-based exclusive). If not given, + count to the end of the chromosome. region : int a region string. quality_threshold : int quality_threshold is the minimum quality score (in phred) a - base has to reach to be counted. + base has to reach to be counted. read_callback: string or function @@ -1184,6 +1504,12 @@ cdef class AlignmentFile(HTSFile): ``check_read(read)`` that should return True only for those reads that shall be included in the counting. + reference : string + backward compatible synonym for `contig` + + end : int + backward compatible synonym for `stop` + Raises ------ @@ -1196,9 +1522,17 @@ cdef class AlignmentFile(HTSFile): four array.arrays of the same length in order A C G T : tuple """ + + cdef uint32_t contig_length = self.get_reference_length(contig) + cdef int _start = start if start is not None else 0 + cdef int _stop = stop if stop is not None else contig_length + _stop = _stop if _stop < contig_length else contig_length + + if _stop == _start: + raise ValueError("interval of size 0") + if _stop < _start: + raise ValueError("interval of size less than 0") - cdef int _start = start - cdef int _stop = end cdef int length = _stop - _start cdef c_array.array int_array_template = array.array('L', []) cdef c_array.array count_a @@ -1217,14 +1551,18 @@ cdef class AlignmentFile(HTSFile): cdef int refpos cdef int c = 0 cdef int filter_method = 0 + + if read_callback == "all": filter_method = 1 elif read_callback == "nofilter": filter_method = 2 - - cdef int _threshold = quality_threshold - for read in self.fetch(reference=reference, + + cdef int _threshold = quality_threshold or 0 + for read in self.fetch(contig=contig, + reference=reference, start=start, + stop=stop, end=end, region=region): # apply filter @@ -1242,10 +1580,13 @@ cdef class AlignmentFile(HTSFile): # count seq = read.seq quality = read.query_qualities + for qpos, refpos in read.get_aligned_pairs(True): if qpos is not None and refpos is not None and \ _start <= refpos < _stop: - if quality[qpos] >= quality_threshold: + + # only check base quality if _threshold > 0 + if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold: if seq[qpos] == 'A': count_a.data.as_ulongs[refpos - _start] += 1 if seq[qpos] == 'C': @@ -1257,7 +1598,7 @@ cdef class AlignmentFile(HTSFile): return count_a, count_c, count_g, count_t - def find_introns(self, read_iterator): + def find_introns_slow(self, read_iterator): """Return a dictionary {(start, stop): count} Listing the intronic sites in the reads (identified by 'N' in the cigar strings), and their support ( = number of reads ). @@ -1282,55 +1623,84 @@ cdef class AlignmentFile(HTSFile): last_read_pos = read_loc return res + def find_introns(self, read_iterator): + """Return a dictionary {(start, stop): count} + Listing the intronic sites in the reads (identified by 'N' in the cigar strings), + and their support ( = number of reads ). + + read_iterator can be the result of a .fetch(...) call. + Or it can be a generator filtering such reads. Example + samfile.find_introns((read for read in samfile.fetch(...) if read.is_reverse) + """ + cdef: + uint32_t base_position, junc_start, nt + int op + AlignedSegment r + int BAM_CREF_SKIP = 3 #BAM_CREF_SKIP + + import collections + res = collections.Counter() + + match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position + for r in read_iterator: + base_position = r.pos + + for op, nt in r.cigartuples: + if op in match_or_deletion: + base_position += nt + elif op == BAM_CREF_SKIP: + junc_start = base_position + base_position += nt + res[(junc_start, base_position)] += 1 + return res + + def close(self): - ''' - closes the :class:`pysam.AlignmentFile`.''' + '''closes the :class:`pysam.AlignmentFile`.''' if self.htsfile == NULL: return cdef int ret = hts_close(self.htsfile) - hts_idx_destroy(self.index) self.htsfile = NULL + if self.index != NULL: + hts_idx_destroy(self.index) + self.index = NULL + + self.header = None + if ret < 0: global errno if errno == EPIPE: errno = 0 else: - raise OSError(errno, force_str(strerror(errno))) + raise IOError(errno, force_str(strerror(errno))) def __dealloc__(self): - # remember: dealloc cannot call other methods - # note: no doc string - # note: __del__ is not called. - - # FIXME[kbj]: isn't self.close a method? I've been duplicating - # close within __dealloc__ (see BCFFile.__dealloc__). Not a pretty - # solution and perhaps unnecessary given that calling self.close has - # been working for years. - # AH: I have removed the call to close. Even though it is working, - # it seems to be dangerous according to the documentation as the - # object be partially deconstructed already. cdef int ret = 0 if self.htsfile != NULL: ret = hts_close(self.htsfile) - hts_idx_destroy(self.index); self.htsfile = NULL - bam_destroy1(self.b) - if self.header != NULL: - bam_hdr_destroy(self.header) + if self.index != NULL: + hts_idx_destroy(self.index) + self.index = NULL + self.header = None + + if self.b: + bam_destroy1(self.b) + self.b = NULL if ret < 0: global errno if errno == EPIPE: errno = 0 else: - raise OSError(errno, force_str(strerror(errno))) - + raise IOError(errno, force_str(strerror(errno))) + cpdef int write(self, AlignedSegment read) except -1: ''' write a single :class:`pysam.AlignedSegment` to disk. @@ -1342,7 +1712,7 @@ cdef class AlignmentFile(HTSFile): Returns ------- - + int : the number of bytes written. If the file is closed, this will be 0. ''' @@ -1353,7 +1723,7 @@ cdef class AlignmentFile(HTSFile): with nogil: ret = sam_write1(self.htsfile, - self.header, + self.header.ptr, read._delegate) # kbj: Still need to raise an exception with except -1. Otherwise @@ -1378,38 +1748,6 @@ cdef class AlignmentFile(HTSFile): ############################################################### ## properties ############################################################### - property nreferences: - """"int with the number of :term:`reference` sequences in the file. - This is a read-only attribute.""" - def __get__(self): - if not self.is_open: - raise ValueError("I/O operation on closed file") - return self.header.n_targets - - property references: - """tuple with the names of :term:`reference` sequences. This is a - read-only attribute""" - def __get__(self): - if not self.is_open: raise ValueError( "I/O operation on closed file" ) - t = [] - for x from 0 <= x < self.header.n_targets: - t.append(charptr_to_str(self.header.target_name[x])) - return tuple(t) - - property lengths: - """tuple of the lengths of the :term:`reference` sequences. This is a - read-only attribute. The lengths are in the same order as - :attr:`pysam.AlignmentFile.references` - - """ - def __get__(self): - if not self.is_open: - raise ValueError("I/O operation on closed file") - t = [] - for x from 0 <= x < self.header.n_targets: - t.append(self.header.target_len[x]) - return tuple(t) - property mapped: """int with total number of mapped alignments according to the statistics recorded in the index. This is a read-only @@ -1420,7 +1758,7 @@ cdef class AlignmentFile(HTSFile): cdef int tid cdef uint64_t total = 0 cdef uint64_t mapped, unmapped - for tid from 0 <= tid < self.header.n_targets: + for tid from 0 <= tid < self.header.nreferences: with nogil: hts_idx_get_stat(self.index, tid, &mapped, &unmapped) total += mapped @@ -1436,7 +1774,7 @@ cdef class AlignmentFile(HTSFile): cdef int tid cdef uint64_t total = hts_idx_get_n_no_coor(self.index) cdef uint64_t mapped, unmapped - for tid from 0 <= tid < self.header.n_targets: + for tid from 0 <= tid < self.header.nreferences: with nogil: hts_idx_get_stat(self.index, tid, &mapped, &unmapped) total += unmapped @@ -1453,114 +1791,32 @@ cdef class AlignmentFile(HTSFile): n = hts_idx_get_n_no_coor(self.index) return n - property text: - '''string with the full contents of the :term:`sam file` header as a - string. - - This is a read-only attribute. - - See :attr:`pysam.AlignmentFile.header` to get a parsed - representation of the header. - ''' - def __get__(self): - if not self.is_open: - raise ValueError( "I/O operation on closed file" ) - return from_string_and_size(self.header.text, self.header.l_text) - - property header: - """two-level dictionay with header information from the file. - - This is a read-only attribute. - - The first level contains the record (``HD``, ``SQ``, etc) and - the second level contains the fields (``VN``, ``LN``, etc). - - The parser is validating and will raise an AssertionError if - if encounters any record or field tags that are not part of - the SAM specification. Use the - :attr:`pysam.AlignmentFile.text` attribute to get the unparsed - header. - - The parsing follows the SAM format specification with the - exception of the ``CL`` field. This option will consume the - rest of a header line irrespective of any additional fields. - This behaviour has been added to accommodate command line - options that contain characters that are not valid field - separators. + def get_index_statistics(self): + """return statistics about mapped/unmapped reads per chromosome as + they are stored in the index. + Returns + ------- + list : a list of records for each chromosome. Each record has the attributes 'contig', + 'mapped', 'unmapped' and 'total'. """ - def __get__(self): - if not self.is_open: - raise ValueError( "I/O operation on closed file" ) - - result = {} - - if self.header.text != NULL: - # convert to python string (note: call self.text to - # create 0-terminated string) - t = self.text - for line in t.split("\n"): - if not line.strip(): continue - assert line.startswith("@"), \ - "header line without '@': '%s'" % line - fields = line[1:].split("\t") - record = fields[0] - assert record in VALID_HEADER_TYPES, \ - "header line with invalid type '%s': '%s'" % (record, line) - - # treat comments - if record == "CO": - if record not in result: - result[record] = [] - result[record].append("\t".join( fields[1:])) - continue - # the following is clumsy as generators do not work? - x = {} - - for idx, field in enumerate(fields[1:]): - if ":" not in field: - raise ValueError("malformatted header: no ':' in field" ) - key, value = field.split(":", 1) - if key in ("CL",): - # special treatment for command line - # statements (CL). These might contain - # characters that are non-conformant with - # the valid field separators in the SAM - # header. Thus, in contravention to the - # SAM API, consume the rest of the line. - key, value = "\t".join(fields[idx+1:]).split(":", 1) - x[key] = KNOWN_HEADER_FIELDS[record][key](value) - break - - # interpret type of known header record tags, default to str - x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value) - - if VALID_HEADER_TYPES[record] == dict: - if record in result: - raise ValueError( - "multiple '%s' lines are not permitted" % record) - - result[record] = x - elif VALID_HEADER_TYPES[record] == list: - if record not in result: result[record] = [] - result[record].append(x) - - # if there are no SQ lines in the header, add the - # reference names from the information in the bam - # file. - # - # Background: c-samtools keeps the textual part of the - # header separate from the list of reference names and - # lengths. Thus, if a header contains only SQ lines, - # the SQ information is not part of the textual header - # and thus are missing from the output. See issue 84. - if "SQ" not in result: - sq = [] - for ref, length in zip(self.references, self.lengths): - sq.append({'LN': length, 'SN': ref }) - result["SQ"] = sq - - return result + + self.check_index() + cdef int tid + cdef uint64_t mapped, unmapped + results = [] + # TODO: use header + for tid from 0 <= tid < self.nreferences: + with nogil: + hts_idx_get_stat(self.index, tid, &mapped, &unmapped) + results.append( + IndexStats._make(( + self.get_reference_name(tid), + mapped, + unmapped, + mapped + unmapped))) + + return results ############################################################### ## file-object like iterator access @@ -1571,12 +1827,12 @@ cdef class AlignmentFile(HTSFile): if not self.is_open: raise ValueError("I/O operation on closed file") - if not self.is_bam and self.header.n_targets == 0: + if not self.is_bam and self.header.nreferences == 0: raise NotImplementedError( "can not iterate over samfile without header") return self - cdef bam1_t * getCurrent( self ): + cdef bam1_t * getCurrent(self): return self.b cdef int cnext(self): @@ -1584,26 +1840,105 @@ cdef class AlignmentFile(HTSFile): cversion of iterator. Used by :class:`pysam.AlignmentFile.IteratorColumn`. ''' cdef int ret + cdef bam_hdr_t * hdr = self.header.ptr with nogil: ret = sam_read1(self.htsfile, - self.header, + hdr, self.b) return ret def __next__(self): cdef int ret = self.cnext() if (ret >= 0): - return makeAlignedSegment(self.b, self) + return makeAlignedSegment(self.b, self.header) elif ret == -2: raise IOError('truncated file') else: raise StopIteration - + + ########################################### + # methods/properties referencing the header + def is_valid_tid(self, int tid): + """ + return True if the numerical :term:`tid` is valid; False otherwise. + + Note that the unmapped tid code (-1) counts as an invalid. + """ + if self.header is None: + raise ValueError("header not available in closed files") + return self.header.is_valid_tid(tid) + + def get_tid(self, reference): + """ + return the numerical :term:`tid` corresponding to + :term:`reference` + + returns -1 if reference is not known. + """ + if self.header is None: + raise ValueError("header not available in closed files") + return self.header.get_tid(reference) + + def get_reference_name(self, tid): + """ + return :term:`reference` name corresponding to numerical :term:`tid` + """ + if self.header is None: + raise ValueError("header not available in closed files") + return self.header.get_reference_name(tid) + + def get_reference_length(self, reference): + """ + return :term:`reference` name corresponding to numerical :term:`tid` + """ + if self.header is None: + raise ValueError("header not available in closed files") + return self.header.get_reference_length(reference) + + property nreferences: + """"int with the number of :term:`reference` sequences in the file. + This is a read-only attribute.""" + def __get__(self): + if self.header: + return self.header.nreferences + else: + raise ValueError("header not available in closed files") + + property references: + """tuple with the names of :term:`reference` sequences. This is a + read-only attribute""" + def __get__(self): + if self.header: + return self.header.references + else: + raise ValueError("header not available in closed files") + + property lengths: + """tuple of the lengths of the :term:`reference` sequences. This is a + read-only attribute. The lengths are in the same order as + :attr:`pysam.AlignmentFile.references` + + """ + def __get__(self): + if self.header: + return self.header.lengths + else: + raise ValueError("header not available in closed files") + + # Compatibility functions for pysam < 0.14 + property text: + """deprecated, use .header directly""" + def __get__(self): + if self.header: + return self.header.__str__() + else: + raise ValueError("header not available in closed files") + # Compatibility functions for pysam < 0.8.3 def gettid(self, reference): """deprecated, use get_tid() instead""" return self.get_tid(reference) - + def getrname(self, tid): """deprecated, use get_reference_name() instead""" return self.get_reference_name(tid) @@ -1637,6 +1972,7 @@ cdef class IteratorRow: def __init__(self, AlignmentFile samfile, int multiple_iterators=False): cdef char *cfilename cdef char *creference_filename + cdef char *cindexname = NULL if not samfile.is_open: raise ValueError("I/O operation on closed file") @@ -1648,16 +1984,30 @@ cdef class IteratorRow: # reopen the file - note that this makes the iterator # slow and causes pileup to slow down significantly. if multiple_iterators: + cfilename = samfile.filename with nogil: self.htsfile = hts_open(cfilename, 'r') assert self.htsfile != NULL - # read header - required for accurate positioning - # could a tell/seek work? + + if samfile.has_index(): + if samfile.index_filename: + cindexname = samfile.index_filename + with nogil: + self.index = sam_index_load2(self.htsfile, cfilename, cindexname) + else: + self.index = NULL + + # need to advance in newly opened file to position after header + # better: use seek/tell? with nogil: - self.header = sam_hdr_read(self.htsfile) - assert self.header != NULL + hdr = sam_hdr_read(self.htsfile) + if hdr is NULL: + raise IOError("unable to read header information") + self.header = makeAlignmentHeader(hdr) + self.owns_samfile = True + # options specific to CRAM files if samfile.is_cram and samfile.reference_filename: creference_filename = samfile.reference_filename @@ -1666,9 +2016,10 @@ cdef class IteratorRow: creference_filename) else: - self.htsfile = self.samfile.htsfile + self.htsfile = samfile.htsfile + self.index = samfile.index self.owns_samfile = False - self.header = self.samfile.header + self.header = samfile.header self.retval = 0 @@ -1678,11 +2029,11 @@ cdef class IteratorRow: bam_destroy1(self.b) if self.owns_samfile: hts_close(self.htsfile) - bam_hdr_destroy(self.header) + hts_idx_destroy(self.index) cdef class IteratorRowRegion(IteratorRow): - """*(AlignmentFile samfile, int tid, int beg, int end, + """*(AlignmentFile samfile, int tid, int beg, int stop, int multiple_iterators=False)* iterate over mapped reads in a region. @@ -1696,22 +2047,22 @@ cdef class IteratorRowRegion(IteratorRow): """ def __init__(self, AlignmentFile samfile, - int tid, int beg, int end, + int tid, int beg, int stop, int multiple_iterators=False): - IteratorRow.__init__(self, samfile, - multiple_iterators=multiple_iterators) - if not samfile.has_index(): raise ValueError("no index available for iteration") + IteratorRow.__init__(self, samfile, + multiple_iterators=multiple_iterators) + with nogil: self.iter = sam_itr_queryi( - self.samfile.index, + self.index, tid, beg, - end) - + stop) + def __iter__(self): return self @@ -1729,15 +2080,17 @@ cdef class IteratorRowRegion(IteratorRow): def __next__(self): self.cnext() if self.retval >= 0: - return makeAlignedSegment(self.b, self.samfile) + return makeAlignedSegment(self.b, self.header) + elif self.retval == -1: + raise StopIteration elif self.retval == -2: # Note: it is currently not the case that hts_iter_next # returns -2 for a truncated file. # See https://github.com/pysam-developers/pysam/pull/50#issuecomment-64928625 raise IOError('truncated file') else: - raise StopIteration - + raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval)) + def __dealloc__(self): hts_itr_destroy(self.iter) @@ -1754,7 +2107,9 @@ cdef class IteratorRowHead(IteratorRow): """ - def __init__(self, AlignmentFile samfile, int n, + def __init__(self, + AlignmentFile samfile, + int n, int multiple_iterators=False): IteratorRow.__init__(self, samfile, @@ -1766,15 +2121,16 @@ cdef class IteratorRowHead(IteratorRow): def __iter__(self): return self - cdef bam1_t * getCurrent( self ): + cdef bam1_t * getCurrent(self): return self.b cdef int cnext(self): '''cversion of iterator. Used by IteratorColumn''' cdef int ret + cdef bam_hdr_t * hdr = self.header.ptr with nogil: ret = sam_read1(self.htsfile, - self.samfile.header, + hdr, self.b) return ret @@ -1785,7 +2141,7 @@ cdef class IteratorRowHead(IteratorRow): cdef int ret = self.cnext() if ret >= 0: self.current_row += 1 - return makeAlignedSegment(self.b, self.samfile) + return makeAlignedSegment(self.b, self.header) elif ret == -2: raise IOError('truncated file') else: @@ -1814,22 +2170,23 @@ cdef class IteratorRowAll(IteratorRow): def __iter__(self): return self - cdef bam1_t * getCurrent( self ): + cdef bam1_t * getCurrent(self): return self.b cdef int cnext(self): '''cversion of iterator. Used by IteratorColumn''' cdef int ret + cdef bam_hdr_t * hdr = self.header.ptr with nogil: ret = sam_read1(self.htsfile, - self.samfile.header, + hdr, self.b) return ret def __next__(self): cdef int ret = self.cnext() if ret >= 0: - return makeAlignedSegment(self.b, self.samfile) + return makeAlignedSegment(self.b, self.header) elif ret == -2: raise IOError('truncated file') else: @@ -1890,7 +2247,7 @@ cdef class IteratorRowAllRefs(IteratorRow): # If current iterator is not exhausted, return aligned read if self.rowiter.retval > 0: - return makeAlignedSegment(self.rowiter.b, self.samfile) + return makeAlignedSegment(self.rowiter.b, self.header) self.tid += 1 @@ -1937,17 +2294,18 @@ cdef class IteratorRowSelection(IteratorRow): self.current_pos += 1 cdef int ret + cdef bam_hdr_t * hdr = self.header.ptr with nogil: ret = sam_read1(self.htsfile, - self.samfile.header, + hdr, self.b) return ret def __next__(self): cdef int ret = self.cnext() - if (ret >= 0): - return makeAlignedSegment(self.b, self.samfile) - elif (ret == -2): + if ret >= 0: + return makeAlignedSegment(self.b, self.header) + elif ret == -2: raise IOError('truncated file') else: raise StopIteration @@ -1956,8 +2314,7 @@ cdef class IteratorRowSelection(IteratorRow): cdef int __advance_nofilter(void *data, bam1_t *b): '''advance without any read filtering. ''' - cdef __iterdata * d - d = <__iterdata*>data + cdef __iterdata * d = <__iterdata*>data cdef int ret with nogil: ret = sam_itr_next(d.htsfile, d.iter, b) @@ -1965,93 +2322,86 @@ cdef int __advance_nofilter(void *data, bam1_t *b): cdef int __advance_all(void *data, bam1_t *b): - '''only use reads for pileup passing basic - filters: + '''only use reads for pileup passing basic filters such as BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL, BAM_FDUP ''' - cdef __iterdata * d + cdef __iterdata * d = <__iterdata*>data cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP - d = <__iterdata*>data cdef int ret - with nogil: - ret = sam_itr_next(d.htsfile, d.iter, b) - while ret >= 0 and b.core.flag & mask: + while 1: with nogil: ret = sam_itr_next(d.htsfile, d.iter, b) + if ret < 0: + break + if b.core.flag & d.flag_filter: + continue + break return ret -cdef int __advance_snpcalls(void * data, bam1_t * b): +cdef int __advance_samtools(void * data, bam1_t * b): '''advance using same filter and read processing as in the samtools pileup. ''' - - # Note that this method requries acces to some - # functions in the samtools code base and is thus - # not htslib only. - # The functions accessed in samtools are: - # 1. bam_prob_realn - # 2. bam_cap_mapQ - cdef __iterdata * d - d = <__iterdata*>data - + cdef __iterdata * d = <__iterdata*>data cdef int ret - cdef int skip = 0 cdef int q - cdef int is_cns = 1 - cdef int is_nobaq = 0 - cdef int capQ_thres = 0 - - with nogil: - ret = sam_itr_next(d.htsfile, d.iter, b) - # reload sequence - if d.fastafile != NULL and b.core.tid != d.tid: - if d.seq != NULL: - free(d.seq) - d.tid = b.core.tid + while 1: with nogil: - d.seq = faidx_fetch_seq( - d.fastafile, - d.header.target_name[d.tid], - 0, MAX_POS, - &d.seq_len) - - if d.seq == NULL: - raise ValueError( - "reference sequence for '%s' (tid=%i) not found" % \ - (d.header.target_name[d.tid], - d.tid)) + ret = sam_itr_next(d.htsfile, d.iter, b) + if ret < 0: + break + if b.core.flag & d.flag_filter: + continue + if d.flag_require and not (b.core.flag & d.flag_require): + continue + + # reload sequence + if d.fastafile != NULL and b.core.tid != d.tid: + if d.seq != NULL: + free(d.seq) + d.tid = b.core.tid + with nogil: + d.seq = faidx_fetch_seq( + d.fastafile, + d.header.target_name[d.tid], + 0, MAX_POS, + &d.seq_len) - while ret >= 0: - skip = 0 + if d.seq == NULL: + raise ValueError( + "reference sequence for '{}' (tid={}) not found".format( + d.header.target_name[d.tid], d.tid)) # realign read - changes base qualities - if d.seq != NULL and is_cns and not is_nobaq: - bam_prob_realn(b, d.seq) - - if d.seq != NULL and capQ_thres > 10: - q = bam_cap_mapQ(b, d.seq, capQ_thres) + if d.seq != NULL and d.compute_baq: + # 4th option to realign is flag: + # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4 + if d.redo_baq: + sam_prob_realn(b, d.seq, d.seq_len, 7) + else: + sam_prob_realn(b, d.seq, d.seq_len, 3) + + if d.seq != NULL and d.adjust_capq_threshold > 10: + q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold) if q < 0: - skip = 1 + continue elif b.core.qual > q: b.core.qual = q - if b.core.flag & BAM_FUNMAP: - skip = 1 - elif b.core.flag & 1 and not b.core.flag & 2: - skip = 1 - - if not skip: - break - # additional filters - - with nogil: - ret = sam_itr_next(d.htsfile, d.iter, b) - + + if b.core.qual < d.min_mapping_quality: + continue + if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR): + continue + + break + return ret + cdef class IteratorColumn: '''abstract base class for iterators over columns. @@ -2063,7 +2413,7 @@ cdef class IteratorColumn: consider the conversion to a list:: f = AlignmentFile("file.bam", "rb") - result = list( f.pileup() ) + result = list(f.pileup()) Here, ``result`` will contain ``n`` objects of type :class:`~pysam.PileupColumn` for ``n`` columns, but each object in @@ -2071,44 +2421,40 @@ cdef class IteratorColumn: The desired behaviour can be achieved by list comprehension:: - result = [ x.pileups() for x in f.pileup() ] + result = [x.pileups() for x in f.pileup()] ``result`` will be a list of ``n`` lists of objects of type :class:`~pysam.PileupRead`. - If the iterator is associated with a :class:`~pysam.Fastafile` using the - :meth:`addReference` method, then the iterator will export the - current sequence via the methods :meth:`getSequence` and - :meth:`seq_len`. - - Optional kwargs to the iterator: - - stepper - The stepper controls how the iterator advances. - - Valid values are None, "all" (default), "nofilter" or "samtools". - - See AlignmentFile.pileup for description. - - fastafile - A :class:`~pysam.FastaFile` object - - max_depth - maximum read depth. The default is 8000. + If the iterator is associated with a :class:`~pysam.Fastafile` + using the :meth:`add_reference` method, then the iterator will + export the current sequence via the methods :meth:`get_sequence` + and :meth:`seq_len`. + See :class:`~AlignmentFile.pileup` for kwargs to the iterator. ''' - def __cinit__( self, AlignmentFile samfile, **kwargs ): + def __cinit__( self, AlignmentFile samfile, **kwargs): self.samfile = samfile self.fastafile = kwargs.get("fastafile", None) - self.stepper = kwargs.get("stepper", None) + self.stepper = kwargs.get("stepper", "samtools") self.max_depth = kwargs.get("max_depth", 8000) + self.ignore_overlaps = kwargs.get("ignore_overlaps", True) + self.min_base_quality = kwargs.get("min_base_quality", 13) self.iterdata.seq = NULL + self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0) + self.iterdata.flag_require = kwargs.get("flag_require", 0) + self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP) + self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0) + self.iterdata.compute_baq = kwargs.get("compute_baq", True) + self.iterdata.redo_baq = kwargs.get("redo_baq", False) + self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True) + self.tid = 0 self.pos = 0 self.n_plp = 0 self.plp = NULL - self.pileup_iter = NULL + self.pileup_iter = NULL def __iter__(self): return self @@ -2117,12 +2463,14 @@ cdef class IteratorColumn: '''perform next iteration. ''' # do not release gil here because of call-backs - self.plp = bam_plp_auto(self.pileup_iter, - &self.tid, - &self.pos, - &self.n_plp) + cdef int ret = bam_mplp_auto(self.pileup_iter, + &self.tid, + &self.pos, + &self.n_plp, + &self.plp) + return ret - cdef char * getSequence(self): + cdef char * get_sequence(self): '''return current reference sequence underlying the iterator. ''' return self.iterdata.seq @@ -2132,7 +2480,7 @@ cdef class IteratorColumn: def __get__(self): return self.iterdata.seq_len - def addReference(self, Fastafile fastafile): + def add_reference(self, FastaFile fastafile): ''' add reference sequences in `fastafile` to iterator.''' self.fastafile = fastafile @@ -2141,33 +2489,24 @@ cdef class IteratorColumn: self.iterdata.tid = -1 self.iterdata.fastafile = self.fastafile.fastafile - def hasReference(self): + def has_reference(self): ''' return true if iterator is associated with a reference''' return self.fastafile - - cdef setMask(self, mask): - '''set masking flag in iterator. - - reads with bits set in `mask` will be skipped. - ''' - raise NotImplementedError() - # self.mask = mask - # bam_plp_set_mask( self.pileup_iter, self.mask ) - - cdef setupIteratorData( self, - int tid, - int start, - int end, - int multiple_iterators=0 ): + + cdef _setup_iterator(self, + int tid, + int start, + int stop, + int multiple_iterators=0): '''setup the iterator structure''' - self.iter = IteratorRowRegion(self.samfile, tid, start, end, multiple_iterators) + self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators) self.iterdata.htsfile = self.samfile.htsfile self.iterdata.iter = self.iter.iter self.iterdata.seq = NULL self.iterdata.tid = -1 - self.iterdata.header = self.samfile.header + self.iterdata.header = self.samfile.header.ptr if self.fastafile is not None: self.iterdata.fastafile = self.fastafile.fastafile @@ -2178,38 +2517,43 @@ cdef class IteratorColumn: # pileup_iter self._free_pileup_iter() + cdef void * data[1] + data[0] = &self.iterdata + if self.stepper is None or self.stepper == "all": with nogil: - self.pileup_iter = bam_plp_init( - &__advance_all, - &self.iterdata) + self.pileup_iter = bam_mplp_init(1, + &__advance_all, + data) elif self.stepper == "nofilter": with nogil: - self.pileup_iter = bam_plp_init( - &__advance_nofilter, - &self.iterdata) + self.pileup_iter = bam_mplp_init(1, + &__advance_nofilter, + data) elif self.stepper == "samtools": with nogil: - self.pileup_iter = bam_plp_init( - &__advance_snpcalls, - &self.iterdata) + self.pileup_iter = bam_mplp_init(1, + &__advance_samtools, + data) else: raise ValueError( "unknown stepper option `%s` in IteratorColumn" % self.stepper) if self.max_depth: with nogil: - bam_plp_set_maxcnt(self.pileup_iter, self.max_depth) + bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth) - # bam_plp_set_mask( self.pileup_iter, self.mask ) - - cdef reset( self, tid, start, end ): + if self.ignore_overlaps: + with nogil: + bam_mplp_init_overlaps(self.pileup_iter) + + cdef reset(self, tid, start, stop): '''reset iterator position. This permits using the iterator multiple times without having to incur the full set-up costs. ''' - self.iter = IteratorRowRegion( self.samfile, tid, start, end, multiple_iterators = 0 ) + self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators=0) self.iterdata.iter = self.iter.iter # invalidate sequence if different tid @@ -2219,21 +2563,22 @@ cdef class IteratorColumn: self.iterdata.seq = NULL self.iterdata.tid = -1 - # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata ) + # self.pileup_iter = bam_mplp_init(1 + # &__advancepileup, + # &self.iterdata) with nogil: - bam_plp_reset(self.pileup_iter) - + bam_mplp_reset(self.pileup_iter) + cdef _free_pileup_iter(self): '''free the memory alloc'd by bam_plp_init. - This is needed before setupIteratorData allocates - another pileup_iter, or else memory will be lost. - ''' - if self.pileup_iter != NULL: + This is needed before setup_iterator allocates another + pileup_iter, or else memory will be lost. ''' + if self.pileup_iter != NULL: with nogil: - bam_plp_reset(self.pileup_iter) - bam_plp_destroy(self.pileup_iter) - self.pileup_iter = NULL + bam_mplp_reset(self.pileup_iter) + bam_mplp_destroy(self.pileup_iter) + self.pileup_iter = NULL def __dealloc__(self): # reset in order to avoid memory leak messages for iterators @@ -2244,43 +2589,59 @@ cdef class IteratorColumn: if self.iterdata.seq != NULL: free(self.iterdata.seq) self.iterdata.seq = NULL + + # backwards compatibility + + def hasReference(self): + return self.has_reference() + cdef char * getSequence(self): + return self.get_sequence() + def addReference(self, FastaFile fastafile): + return self.add_reference(fastafile) - + cdef class IteratorColumnRegion(IteratorColumn): '''iterates over a region only. ''' - def __cinit__(self, AlignmentFile samfile, + def __cinit__(self, + AlignmentFile samfile, int tid = 0, int start = 0, - int end = MAX_POS, + int stop = MAX_POS, int truncate = False, **kwargs ): # initialize iterator - self.setupIteratorData(tid, start, end, 1) + self._setup_iterator(tid, start, stop, 1) self.start = start - self.end = end + self.stop = stop self.truncate = truncate def __next__(self): + cdef int n + while 1: - self.cnext() - if self.n_plp < 0: + n = self.cnext() + if n < 0: raise ValueError("error during iteration" ) - if self.plp == NULL: + if n == 0: raise StopIteration - + if self.truncate: - if self.start > self.pos: continue - if self.pos >= self.end: raise StopIteration + if self.start > self.pos: + continue + if self.pos >= self.stop: + raise StopIteration return makePileupColumn(&self.plp, - self.tid, - self.pos, - self.n_plp, - self.samfile) + self.tid, + self.pos, + self.n_plp, + self.min_base_quality, + self.iterdata.seq, + self.samfile.header) cdef class IteratorColumnAllRefs(IteratorColumn): @@ -2296,30 +2657,33 @@ cdef class IteratorColumnAllRefs(IteratorColumn): raise StopIteration # initialize iterator - self.setupIteratorData(self.tid, 0, MAX_POS, 1) + self._setup_iterator(self.tid, 0, MAX_POS, 1) def __next__(self): + cdef int n while 1: - self.cnext() - - if self.n_plp < 0: - raise ValueError("error during iteration" ) + n = self.cnext() + if n < 0: + raise ValueError("error during iteration") + + # proceed to next reference or stop + if n == 0: + self.tid += 1 + if self.tid < self.samfile.nreferences: + self._setup_iterator(self.tid, 0, MAX_POS, 0) + else: + raise StopIteration + continue # return result, if within same reference - if self.plp != NULL: - return makePileupColumn(&self.plp, - self.tid, - self.pos, - self.n_plp, - self.samfile) - - # otherwise, proceed to next reference or stop - self.tid += 1 - if self.tid < self.samfile.nreferences: - self.setupIteratorData(self.tid, 0, MAX_POS, 0) - else: - raise StopIteration + return makePileupColumn(&self.plp, + self.tid, + self.pos, + self.n_plp, + self.min_base_quality, + self.iterdata.seq, + self.samfile.header) cdef class SNPCall: @@ -2411,8 +2775,8 @@ cdef class IndexedReads: # makes sure that samfile stays alive as long as this # object is alive. self.samfile = samfile - - assert samfile.is_bam, "can only IndexReads on bam files" + cdef bam_hdr_t * hdr = NULL + assert samfile.is_bam, "can only apply IndexReads on bam files" # multiple_iterators the file - note that this makes the iterator # slow and causes pileup to slow down significantly. @@ -2420,14 +2784,20 @@ cdef class IndexedReads: cfilename = samfile.filename with nogil: self.htsfile = hts_open(cfilename, 'r') - assert self.htsfile != NULL - # read header - required for accurate positioning + if self.htsfile == NULL: + raise OSError("unable to reopen htsfile") + + # need to advance in newly opened file to position after header + # better: use seek/tell? with nogil: - self.header = sam_hdr_read(self.htsfile) + hdr = sam_hdr_read(self.htsfile) + if hdr == NULL: + raise OSError("unable to read header information") + self.header = makeAlignmentHeader(hdr) self.owns_samfile = True else: self.htsfile = self.samfile.htsfile - self.header = self.samfile.header + self.header = samfile.header self.owns_samfile = False def build(self): @@ -2435,19 +2805,22 @@ cdef class IndexedReads: self.index = collections.defaultdict(list) - # this method will start indexing from the current file - # position if you decide + # this method will start indexing from the current file position cdef int ret = 1 cdef bam1_t * b = calloc(1, sizeof( bam1_t)) + if b == NULL: + raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t))) cdef uint64_t pos - + cdef bam_hdr_t * hdr = self.header.ptr + while ret > 0: with nogil: pos = bgzf_tell(hts_get_bgzfp(self.htsfile)) ret = sam_read1(self.htsfile, - self.samfile.header, + hdr, b) + if ret > 0: qname = charptr_to_str(pysam_bam_get_qname(b)) self.index[qname].append(pos) @@ -2465,7 +2838,7 @@ cdef class IndexedReads: Raises ------ - + KeyError if the `query_name` is not in the index. @@ -2481,10 +2854,3 @@ cdef class IndexedReads: def __dealloc__(self): if self.owns_samfile: hts_close(self.htsfile) - bam_hdr_destroy(self.header) - -__all__ = [ - "AlignmentFile", - "IteratorRow", - "IteratorColumn", - "IndexedReads"] diff --git a/pysam/libcbcf.c b/pysam/libcbcf.c index fd92364e5..e45987647 100644 --- a/pysam/libcbcf.c +++ b/pysam/libcbcf.c @@ -567,6 +567,7 @@ static CYTHON_INLINE float __PYX_NAN() { #include #include #include +#include "stdarg.h" #include "htslib/kstring.h" #include "htslib_util.h" #include "htslib/hfile.h" @@ -577,9 +578,9 @@ static CYTHON_INLINE float __PYX_NAN() { #include "htslib/tbx.h" #include "htslib/vcf.h" #include "htslib/vcfutils.h" +#include "htslib/cram.h" #include #include "pythread.h" -#include "pysam_util.h" #ifdef _OPENMP #include #endif /* _OPENMP */ @@ -784,8 +785,8 @@ static const char *__pyx_filename; static const char *__pyx_f[] = { "pysam/libcbcf.pyx", - "stringsource", "pysam/libcbcf.pxd", + "stringsource", "array.pxd", "type.pxd", "bool.pxd", @@ -991,7 +992,7 @@ struct __pyx_opt_args_5pysam_9libcutils_force_bytes { }; struct __pyx_opt_args_5pysam_7libcbcf_char_array_to_tuple; -/* "pysam/libcbcf.pyx":171 +/* "pysam/libcbcf.pyx":250 * * * cdef tuple char_array_to_tuple(const char **a, ssize_t n, int free_after=0): # <<<<<<<<<<<<<< @@ -1003,7 +1004,7 @@ struct __pyx_opt_args_5pysam_7libcbcf_char_array_to_tuple { int free_after; }; -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -1017,6 +1018,7 @@ struct __pyx_obj_5pysam_10libchtslib_HTSFile { int64_t start_offset; PyObject *filename; PyObject *mode; + PyObject *threads; PyObject *index_filename; int is_stream; int is_remote; @@ -1038,11 +1040,11 @@ struct __pyx_obj_5pysam_7libcbcf_VariantHeader { }; -/* "pysam/libcbcf.pxd":45 +/* "pysam/libcbcf.pxd":44 * * * cdef class VariantHeaderRecord(object): # <<<<<<<<<<<<<< - * cdef VariantHeader header + * cdef readonly VariantHeader header * cdef bcf_hrec_t *ptr */ struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord { @@ -1052,11 +1054,11 @@ struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord { }; -/* "pysam/libcbcf.pxd":50 +/* "pysam/libcbcf.pxd":49 * * * cdef class VariantHeaderRecords(object): # <<<<<<<<<<<<<< - * cdef VariantHeader header + * cdef readonly VariantHeader header * */ struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords { @@ -1065,11 +1067,11 @@ struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords { }; -/* "pysam/libcbcf.pxd":54 +/* "pysam/libcbcf.pxd":53 * * * cdef class VariantHeaderContigs(object): # <<<<<<<<<<<<<< - * cdef VariantHeader header + * cdef readonly VariantHeader header * */ struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs { @@ -1078,11 +1080,11 @@ struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs { }; -/* "pysam/libcbcf.pxd":58 +/* "pysam/libcbcf.pxd":57 * * * cdef class VariantHeaderSamples(object): # <<<<<<<<<<<<<< - * cdef VariantHeader header + * cdef readonly VariantHeader header * */ struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples { @@ -1091,11 +1093,11 @@ struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples { }; -/* "pysam/libcbcf.pxd":62 +/* "pysam/libcbcf.pxd":61 * * * cdef class VariantContig(object): # <<<<<<<<<<<<<< - * cdef VariantHeader header + * cdef readonly VariantHeader header * cdef int id */ struct __pyx_obj_5pysam_7libcbcf_VariantContig { @@ -1105,11 +1107,11 @@ struct __pyx_obj_5pysam_7libcbcf_VariantContig { }; -/* "pysam/libcbcf.pxd":67 +/* "pysam/libcbcf.pxd":66 * * * cdef class VariantMetadata(object): # <<<<<<<<<<<<<< - * cdef VariantHeader header + * cdef readonly VariantHeader header * cdef int type */ struct __pyx_obj_5pysam_7libcbcf_VariantMetadata { @@ -1120,11 +1122,11 @@ struct __pyx_obj_5pysam_7libcbcf_VariantMetadata { }; -/* "pysam/libcbcf.pxd":73 +/* "pysam/libcbcf.pxd":72 * * * cdef class VariantHeaderMetadata(object): # <<<<<<<<<<<<<< - * cdef VariantHeader header + * cdef readonly VariantHeader header * cdef int32_t type */ struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata { @@ -1134,11 +1136,11 @@ struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata { }; -/* "pysam/libcbcf.pxd":78 +/* "pysam/libcbcf.pxd":77 * * * cdef class VariantRecord(object): # <<<<<<<<<<<<<< - * cdef VariantHeader header + * cdef readonly VariantHeader header * cdef bcf1_t *ptr */ struct __pyx_obj_5pysam_7libcbcf_VariantRecord { @@ -1148,7 +1150,7 @@ struct __pyx_obj_5pysam_7libcbcf_VariantRecord { }; -/* "pysam/libcbcf.pxd":83 +/* "pysam/libcbcf.pxd":82 * * * cdef class VariantRecordFilter(object): # <<<<<<<<<<<<<< @@ -1161,7 +1163,7 @@ struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter { }; -/* "pysam/libcbcf.pxd":87 +/* "pysam/libcbcf.pxd":86 * * * cdef class VariantRecordFormat(object): # <<<<<<<<<<<<<< @@ -1174,7 +1176,7 @@ struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat { }; -/* "pysam/libcbcf.pxd":91 +/* "pysam/libcbcf.pxd":90 * * * cdef class VariantRecordInfo(object): # <<<<<<<<<<<<<< @@ -1187,7 +1189,7 @@ struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo { }; -/* "pysam/libcbcf.pxd":95 +/* "pysam/libcbcf.pxd":94 * * * cdef class VariantRecordSamples(object): # <<<<<<<<<<<<<< @@ -1200,7 +1202,7 @@ struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples { }; -/* "pysam/libcbcf.pxd":99 +/* "pysam/libcbcf.pxd":98 * * * cdef class VariantRecordSample(object): # <<<<<<<<<<<<<< @@ -1214,7 +1216,7 @@ struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample { }; -/* "pysam/libcbcf.pxd":104 +/* "pysam/libcbcf.pxd":103 * * * cdef class BaseIndex(object): # <<<<<<<<<<<<<< @@ -1228,11 +1230,11 @@ struct __pyx_obj_5pysam_7libcbcf_BaseIndex { }; -/* "pysam/libcbcf.pxd":109 +/* "pysam/libcbcf.pxd":108 * * * cdef class BCFIndex(BaseIndex): # <<<<<<<<<<<<<< - * cdef VariantHeader header + * cdef readonly VariantHeader header * cdef hts_idx_t *ptr */ struct __pyx_obj_5pysam_7libcbcf_BCFIndex { @@ -1242,7 +1244,7 @@ struct __pyx_obj_5pysam_7libcbcf_BCFIndex { }; -/* "pysam/libcbcf.pxd":114 +/* "pysam/libcbcf.pxd":113 * * * cdef class TabixIndex(BaseIndex): # <<<<<<<<<<<<<< @@ -1255,7 +1257,7 @@ struct __pyx_obj_5pysam_7libcbcf_TabixIndex { }; -/* "pysam/libcbcf.pxd":118 +/* "pysam/libcbcf.pxd":117 * * * cdef class BaseIterator(object): # <<<<<<<<<<<<<< @@ -1269,7 +1271,7 @@ struct __pyx_obj_5pysam_7libcbcf_BaseIterator { }; -/* "pysam/libcbcf.pxd":123 +/* "pysam/libcbcf.pxd":122 * * * cdef class BCFIterator(BaseIterator): # <<<<<<<<<<<<<< @@ -1282,7 +1284,7 @@ struct __pyx_obj_5pysam_7libcbcf_BCFIterator { }; -/* "pysam/libcbcf.pxd":127 +/* "pysam/libcbcf.pxd":126 * * * cdef class TabixIterator(BaseIterator): # <<<<<<<<<<<<<< @@ -1296,7 +1298,7 @@ struct __pyx_obj_5pysam_7libcbcf_TabixIterator { }; -/* "pysam/libcbcf.pxd":132 +/* "pysam/libcbcf.pxd":131 * * * cdef class VariantFile(HTSFile): # <<<<<<<<<<<<<< @@ -1313,7 +1315,7 @@ struct __pyx_obj_5pysam_7libcbcf_VariantFile { }; -/* "pysam/libcbcf.pyx":171 +/* "pysam/libcbcf.pyx":250 * * * cdef tuple char_array_to_tuple(const char **a, ssize_t n, int free_after=0): # <<<<<<<<<<<<<< @@ -1327,7 +1329,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysam_7libcbcf_cha }; -/* "pysam/libcbcf.pyx":175 +/* "pysam/libcbcf.pyx":254 * return None * try: * return tuple(charptr_to_str(a[i]) for i in range(n)) # <<<<<<<<<<<<<< @@ -1344,7 +1346,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr { }; -/* "pysam/libcbcf.pyx":181 +/* "pysam/libcbcf.pyx":260 * * * cdef bcf_array_to_object(void *data, int type, ssize_t n, ssize_t count, int scalar): # <<<<<<<<<<<<<< @@ -1353,16 +1355,16 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr { */ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object { PyObject_HEAD - PyObject *__pyx_v_value; + PyObject *__pyx_v_b; }; -/* "pysam/libcbcf.pyx":199 - * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. - * - * value = tuple(v or None for v in value.split(',')) if value else () # <<<<<<<<<<<<<< - * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. +/* "pysam/libcbcf.pyx":285 + * # Otherwise, copy the entire block + * b = datac[:n] + * value = tuple(v.decode('ascii') if v and v != bcf_str_missing else None for v in b.split(b',')) # <<<<<<<<<<<<<< * else: + * value = [] */ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_3_genexpr { PyObject_HEAD @@ -1374,7 +1376,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_3_genexpr { }; -/* "pysam/libcbcf.pyx":246 +/* "pysam/libcbcf.pyx":331 * * * cdef bcf_object_to_array(values, void *data, int bt_type, ssize_t n, int vlen): # <<<<<<<<<<<<<< @@ -1387,12 +1389,12 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_4___pyx_f_5pysam_7libcbcf_bc }; -/* "pysam/libcbcf.pyx":258 +/* "pysam/libcbcf.pyx":343 * if bt_type == BCF_BT_CHAR: * if not isinstance(values, (str, bytes)): - * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) # <<<<<<<<<<<<<< + * values = b','.join(force_bytes(v) if v else bcf_str_missing for v in values) # <<<<<<<<<<<<<< * value_count = len(values) - * assert(value_count <= n) + * assert value_count <= n */ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_5_genexpr { PyObject_HEAD @@ -1404,12 +1406,12 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_5_genexpr { }; -/* "pysam/libcbcf.pyx":469 +/* "pysam/libcbcf.pyx":554 * * - * cdef object bcf_check_values(VariantRecord record, value, int hl_type, int ht_type, # <<<<<<<<<<<<<< + * cdef object bcf_check_values(VariantRecord record, value, int sample, # <<<<<<<<<<<<<< + * int hl_type, int ht_type, * int id, int bt_type, ssize_t bt_len, - * ssize_t *value_count, int *scalar, int *realloc): */ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values { PyObject_HEAD @@ -1417,7 +1419,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bc }; -/* "pysam/libcbcf.pyx":506 +/* "pysam/libcbcf.pyx":593 * raise ValueError('Integer value too small/large to store in VCF/BCF') * elif ht_type == BCF_HT_STR: * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) # <<<<<<<<<<<<<< @@ -1434,7 +1436,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_7_genexpr { }; -/* "pysam/libcbcf.pyx":1119 +/* "pysam/libcbcf.pyx":1255 * * @property * def attrs(self): # <<<<<<<<<<<<<< @@ -1447,7 +1449,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_8___get__ { }; -/* "pysam/libcbcf.pyx":1125 +/* "pysam/libcbcf.pyx":1261 * return () * cdef int i * return tuple((bcf_str_cache_get_charptr(r.keys[i]) if r.keys[i] else None, # <<<<<<<<<<<<<< @@ -1464,7 +1466,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_9_genexpr { }; -/* "pysam/libcbcf.pyx":1148 +/* "pysam/libcbcf.pyx":1284 * raise KeyError('cannot find metadata key') * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1482,7 +1484,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_10___iter__ { }; -/* "pysam/libcbcf.pyx":1176 +/* "pysam/libcbcf.pyx":1312 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -1500,7 +1502,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_11_itervalues { }; -/* "pysam/libcbcf.pyx":1186 +/* "pysam/libcbcf.pyx":1322 * yield charptr_to_str(r.vals[i]) if r.vals[i] else None * * def iteritems(self): # <<<<<<<<<<<<<< @@ -1518,7 +1520,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_12_iteritems { }; -/* "pysam/libcbcf.pyx":1276 +/* "pysam/libcbcf.pyx":1433 * return makeVariantHeaderRecord(self.header, self.header.ptr.hrec[i]) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1535,7 +1537,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_13___iter__ { }; -/* "pysam/libcbcf.pyx":1466 +/* "pysam/libcbcf.pyx":1623 * #bcf_hdr_sync(hdr) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1554,7 +1556,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_14___iter__ { }; -/* "pysam/libcbcf.pyx":1495 +/* "pysam/libcbcf.pyx":1652 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -1571,7 +1573,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_15_itervalues { }; -/* "pysam/libcbcf.pyx":1500 +/* "pysam/libcbcf.pyx":1657 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -1588,7 +1590,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_16_iteritems { }; -/* "pysam/libcbcf.pyx":1646 +/* "pysam/libcbcf.pyx":1803 * #bcf_hdr_sync(hdr) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1608,7 +1610,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_17___iter__ { }; -/* "pysam/libcbcf.pyx":1675 +/* "pysam/libcbcf.pyx":1832 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -1625,7 +1627,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_18_itervalues { }; -/* "pysam/libcbcf.pyx":1680 +/* "pysam/libcbcf.pyx":1837 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -1642,7 +1644,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_19_iteritems { }; -/* "pysam/libcbcf.pyx":1742 +/* "pysam/libcbcf.pyx":1900 * return charptr_to_str(hdr.samples[i]) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1661,7 +1663,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_20___iter__ { }; -/* "pysam/libcbcf.pyx":2056 +/* "pysam/libcbcf.pyx":2273 * r.d.n_flt = 0 * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1680,7 +1682,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_21___iter__ { }; -/* "pysam/libcbcf.pyx":2081 +/* "pysam/libcbcf.pyx":2298 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -1697,7 +1699,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_22_itervalues { }; -/* "pysam/libcbcf.pyx":2086 +/* "pysam/libcbcf.pyx":2303 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -1714,7 +1716,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_23_iteritems { }; -/* "pysam/libcbcf.pyx":2186 +/* "pysam/libcbcf.pyx":2417 * raise ValueError('Unable to delete FORMAT') * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1734,7 +1736,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_24___iter__ { }; -/* "pysam/libcbcf.pyx":2215 +/* "pysam/libcbcf.pyx":2446 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -1751,7 +1753,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_25_itervalues { }; -/* "pysam/libcbcf.pyx":2220 +/* "pysam/libcbcf.pyx":2451 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -1768,7 +1770,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_26_iteritems { }; -/* "pysam/libcbcf.pyx":2339 +/* "pysam/libcbcf.pyx":2623 * raise ValueError('Unable to delete INFO') * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1780,6 +1782,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_27___iter__ { bcf_hdr_t *__pyx_v_hdr; int __pyx_v_i; bcf_info_t *__pyx_v_info; + char const *__pyx_v_key; bcf1_t *__pyx_v_r; struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self; uint32_t __pyx_t_0; @@ -1788,17 +1791,19 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_27___iter__ { }; -/* "pysam/libcbcf.pyx":2373 +/* "pysam/libcbcf.pyx":2690 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< * """D.itervalues() -> an iterator over the values of D""" - * cdef bcf1_t *r = self.record.ptr + * cdef bcf_hdr_t *hdr = self.record.header.ptr */ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_28_itervalues { PyObject_HEAD + bcf_hdr_t *__pyx_v_hdr; int __pyx_v_i; bcf_info_t *__pyx_v_info; + char const *__pyx_v_key; bcf1_t *__pyx_v_r; struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self; uint32_t __pyx_t_0; @@ -1807,8 +1812,8 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_28_itervalues { }; -/* "pysam/libcbcf.pyx":2384 - * yield bcf_info_get_value(self.record, info) +/* "pysam/libcbcf.pyx":2708 + * yield bcf_info_get_value(self.record, info) * * def iteritems(self): # <<<<<<<<<<<<<< * """D.iteritems() -> an iterator over the (key, value) items of D""" @@ -1829,7 +1834,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_29_iteritems { }; -/* "pysam/libcbcf.pyx":2458 +/* "pysam/libcbcf.pyx":2851 * return makeVariantRecordSample(self.record, sample_index) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1849,7 +1854,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_30___iter__ { }; -/* "pysam/libcbcf.pyx":2495 +/* "pysam/libcbcf.pyx":2888 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -1869,7 +1874,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_31_itervalues { }; -/* "pysam/libcbcf.pyx":2504 +/* "pysam/libcbcf.pyx":2897 * yield makeVariantRecordSample(self.record, i) * * def iteritems(self): # <<<<<<<<<<<<<< @@ -1889,7 +1894,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_32_iteritems { }; -/* "pysam/libcbcf.pyx":2988 +/* "pysam/libcbcf.pyx":3459 * bcf_format_del_value(self, bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1909,7 +1914,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_33___iter__ { }; -/* "pysam/libcbcf.pyx":3017 +/* "pysam/libcbcf.pyx":3488 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -1926,7 +1931,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_34_itervalues { }; -/* "pysam/libcbcf.pyx":3022 +/* "pysam/libcbcf.pyx":3493 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -1943,7 +1948,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_35_iteritems { }; -/* "pysam/libcbcf.pyx":3101 +/* "pysam/libcbcf.pyx":3603 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -1960,7 +1965,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_36_itervalues { }; -/* "pysam/libcbcf.pyx":3106 +/* "pysam/libcbcf.pyx":3608 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -1978,7 +1983,7 @@ struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_37_iteritems { -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -1992,7 +1997,7 @@ struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile { static struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile *__pyx_vtabptr_5pysam_10libchtslib_HTSFile; -/* "pysam/libcbcf.pyx":1777 +/* "pysam/libcbcf.pyx":1935 * * * cdef class VariantHeader(object): # <<<<<<<<<<<<<< @@ -2001,23 +2006,21 @@ static struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile *__pyx_vtabptr_5pysam */ struct __pyx_vtabstruct_5pysam_7libcbcf_VariantHeader { - struct __pyx_obj_5pysam_7libcbcf_VariantRecord *(*new_record)(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *, int __pyx_skip_dispatch); PyObject *(*_subset_samples)(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *, PyObject *); }; static struct __pyx_vtabstruct_5pysam_7libcbcf_VariantHeader *__pyx_vtabptr_5pysam_7libcbcf_VariantHeader; -/* "pysam/libcbcf.pyx":3410 +/* "pysam/libcbcf.pyx":3935 * * * cdef class VariantFile(HTSFile): # <<<<<<<<<<<<<< * """*(filename, mode=None, index_filename=None, header=None, drop_samples=False, - * duplicate_filehandle=True)* + * duplicate_filehandle=True, ignore_truncation=False, threads=1)* */ struct __pyx_vtabstruct_5pysam_7libcbcf_VariantFile { struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile __pyx_base; - struct __pyx_obj_5pysam_7libcbcf_VariantRecord *(*new_record)(struct __pyx_obj_5pysam_7libcbcf_VariantFile *, int __pyx_skip_dispatch); int (*write)(struct __pyx_obj_5pysam_7libcbcf_VariantFile *, struct __pyx_obj_5pysam_7libcbcf_VariantRecord *, int __pyx_skip_dispatch); }; static struct __pyx_vtabstruct_5pysam_7libcbcf_VariantFile *__pyx_vtabptr_5pysam_7libcbcf_VariantFile; @@ -2334,11 +2337,32 @@ static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject #define __Pyx_TraceLine(lineno, nogil, goto_error) if ((1)); else goto_error; #endif +/* None.proto */ +static CYTHON_INLINE long __Pyx_div_long(long, long); + +/* PyObjectCall.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); +#else +#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#endif + +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace); +#else +#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\ + (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) +#endif + /* WriteUnraisableException.proto */ static void __Pyx_WriteUnraisable(const char *name, int clineno, int lineno, const char *filename, int full_traceback, int nogil); +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + /* GetException.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb) @@ -2369,11 +2393,21 @@ static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject /* None.proto */ static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname); -/* PyObjectCall.proto */ +/* UnpackUnboundCMethod.proto */ +typedef struct { + PyObject *type; + PyObject **method_name; + PyCFunction func; + PyObject *method; + int flag; +} __Pyx_CachedCFunction; + +/* CallUnboundCMethod1.proto */ +static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg); #if CYTHON_COMPILING_IN_CPYTHON -static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); +static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg); #else -#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#define __Pyx_CallUnboundCMethod1(cfunc, self, arg) __Pyx__CallUnboundCMethod1(cfunc, self, arg) #endif /* ListAppend.proto */ @@ -2426,9 +2460,6 @@ static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg); /* append.proto */ static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); -/* RaiseException.proto */ -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); - /* GetItemInt.proto */ #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ @@ -2469,18 +2500,34 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values); #endif -/* None.proto */ -static CYTHON_INLINE long __Pyx_div_long(long, long); - -/* KeywordStringCheck.proto */ -static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); - /* IncludeStringH.proto */ #include /* BytesEquals.proto */ static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* StrEquals.proto */ +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals +#else +#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals +#endif + +/* PyObjectSetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL) +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value); +#else +#define __Pyx_PyObject_DelAttrStr(o,n) PyObject_DelAttr(o,n) +#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v) +#endif + +/* KeywordStringCheck.proto */ +static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); + /* RaiseDoubleKeywords.proto */ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); @@ -2515,33 +2562,21 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL) #endif -/* GetAttr.proto */ -static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); +/* RaiseTooManyValuesToUnpack.proto */ +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); -/* GetAttr3.proto */ -static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); +/* RaiseNeedMoreValuesToUnpack.proto */ +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); -/* GetModuleGlobalName.proto */ -static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); +/* IterFinish.proto */ +static CYTHON_INLINE int __Pyx_IterFinish(void); -/* PySequenceContains.proto */ -static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) { - int result = PySequence_Contains(seq, item); - return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); -} +/* UnpackItemEndCheck.proto */ +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /* py_dict_items.proto */ static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d); -/* UnpackUnboundCMethod.proto */ -typedef struct { - PyObject *type; - PyObject **method_name; - PyCFunction func; - PyObject *method; - int flag; -} __Pyx_CachedCFunction; - /* CallUnboundCMethod0.proto */ static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self); #if CYTHON_COMPILING_IN_CPYTHON @@ -2562,22 +2597,27 @@ static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObje #define __Pyx_CallUnboundCMethod0(cfunc, self) __Pyx__CallUnboundCMethod0(cfunc, self) #endif +/* GetAttr.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); + +/* GetAttr3.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); + +/* GetModuleGlobalName.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); + +/* PySequenceContains.proto */ +static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) { + int result = PySequence_Contains(seq, item); + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); +} + /* ArgTypeTest.proto */ #define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\ ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\ __Pyx__ArgTypeTest(obj, type, name, exact)) static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); -/* UnicodeEquals.proto */ -static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); - -/* StrEquals.proto */ -#if PY_MAJOR_VERSION >= 3 -#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals -#else -#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals -#endif - /* DictGetItem.proto */ #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key); @@ -2589,20 +2629,22 @@ static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key); #define __Pyx_PyObject_Dict_GetItem(obj, name) PyObject_GetItem(obj, name) #endif -/* ExtTypeTest.proto */ -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); - -/* RaiseTooManyValuesToUnpack.proto */ -static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); - -/* RaiseNeedMoreValuesToUnpack.proto */ -static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); +/* PyDictContains.proto */ +static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) { + int result = PyDict_Contains(dict, item); + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); +} -/* IterFinish.proto */ -static CYTHON_INLINE int __Pyx_IterFinish(void); +/* py_dict_pop.proto */ +static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value); -/* UnpackItemEndCheck.proto */ -static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); +/* CallUnboundCMethod2.proto */ +static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2); +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1 +static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2); +#else +#define __Pyx_CallUnboundCMethod2(cfunc, self, arg1, arg2) __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2) +#endif /* ListCompAppend.proto */ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS @@ -2631,15 +2673,6 @@ static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v); static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list, int wraparound, int boundscheck); -/* PyObjectSetAttrStr.proto */ -#if CYTHON_USE_TYPE_SLOTS -#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL) -static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value); -#else -#define __Pyx_PyObject_DelAttrStr(o,n) PyObject_DelAttr(o,n) -#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v) -#endif - /* PyIntBinop.proto */ #if !CYTHON_COMPILING_IN_PYPY static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace); @@ -2648,32 +2681,8 @@ static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long int (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2)) #endif -/* PyIntBinop.proto */ -#if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace); -#else -#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\ - (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) -#endif - -/* dict_getitem_default.proto */ -static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value); - -/* CallUnboundCMethod1.proto */ -static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg); -#if CYTHON_COMPILING_IN_CPYTHON -static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg); -#else -#define __Pyx_CallUnboundCMethod1(cfunc, self, arg) __Pyx__CallUnboundCMethod1(cfunc, self, arg) -#endif - -/* CallUnboundCMethod2.proto */ -static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2); -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1 -static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2); -#else -#define __Pyx_CallUnboundCMethod2(cfunc, self, arg1, arg2) __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2) -#endif +/* ExtTypeTest.proto */ +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /* SliceObject.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice( @@ -2755,13 +2764,13 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value); /* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int8_t(int8_t value); +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); /* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int16_t(int16_t value); +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int8_t(int8_t value); /* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int16_t(int16_t value); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value); @@ -3011,8 +3020,6 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); static PyObject *__pyx_f_5pysam_7libcbcf_13VariantHeader__subset_samples(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, PyObject *__pyx_v_include_samples); /* proto*/ -static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_13VariantHeader_new_record(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ -static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_11VariantFile_new_record(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record, int __pyx_skip_dispatch); /* proto*/ /* Module declarations from 'libc.stdint' */ @@ -3189,18 +3196,22 @@ static int __pyx_v_5pysam_7libcbcf_MAX_POS; static PyObject *__pyx_v_5pysam_7libcbcf_VALUE_TYPES = 0; static PyObject *__pyx_v_5pysam_7libcbcf_METADATA_TYPES = 0; static PyObject *__pyx_v_5pysam_7libcbcf_METADATA_LENGTHS = 0; +static PyObject *__pyx_v_5pysam_7libcbcf__nothing = 0; static PyObject *__pyx_v_5pysam_7libcbcf_bcf_str_cache = 0; static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(char const *); /*proto*/ +static int __pyx_f_5pysam_7libcbcf_comb(int, int); /*proto*/ +static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_bcf_geno_combinations(int, int); /*proto*/ static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_check_header_id(bcf_hdr_t *, int, int); /*proto*/ static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_is_gt_fmt(bcf_hdr_t *, int); /*proto*/ +static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_bcf_genotype_count(bcf_hdr_t *, bcf1_t *, int); /*proto*/ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **, Py_ssize_t, struct __pyx_opt_args_5pysam_7libcbcf_char_array_to_tuple *__pyx_optional_args); /*proto*/ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *, int, Py_ssize_t, Py_ssize_t, int); /*proto*/ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *, void *, int, Py_ssize_t, int); /*proto*/ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int, Py_ssize_t, int); /*proto*/ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *, int, Py_ssize_t, void *, int, Py_ssize_t, int); /*proto*/ -static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *, int, int, Py_ssize_t *, int *); /*proto*/ +static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *, int, int, Py_ssize_t *, int *, int); /*proto*/ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *, bcf_info_t const *); /*proto*/ -static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *, PyObject *, int, int, int, int, Py_ssize_t, Py_ssize_t *, int *, int *); /*proto*/ +static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *, PyObject *, int, int, int, int, int, Py_ssize_t, Py_ssize_t *, int *, int *); /*proto*/ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *, PyObject *); /*proto*/ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *, PyObject *, PyObject *); /*proto*/ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *, PyObject *); /*proto*/ @@ -3210,6 +3221,8 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *); /*proto*/ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *); /*proto*/ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *, int); /*proto*/ +static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_sync_end(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *); /*proto*/ +static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_has_symbolic_allele(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *); /*proto*/ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_f_5pysam_7libcbcf_makeVariantHeaderRecord(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *, bcf_hrec_t *); /*proto*/ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_f_5pysam_7libcbcf_makeVariantHeaderRecords(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *); /*proto*/ static struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_f_5pysam_7libcbcf_makeVariantMetadata(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *, int, int); /*proto*/ @@ -3218,6 +3231,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_f_5pysam_7libcbcf_m static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_f_5pysam_7libcbcf_makeVariantHeaderContigs(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *); /*proto*/ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_f_5pysam_7libcbcf_makeVariantHeaderSamples(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *); /*proto*/ static struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_f_5pysam_7libcbcf_makeVariantHeader(bcf_hdr_t *); /*proto*/ +static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_bcf_header_get_info_id(bcf_hdr_t *, PyObject *); /*proto*/ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_f_5pysam_7libcbcf_makeVariantRecordFilter(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *); /*proto*/ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_f_5pysam_7libcbcf_makeVariantRecordFormat(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *); /*proto*/ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_f_5pysam_7libcbcf_makeVariantRecordInfo(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *); /*proto*/ @@ -3244,20 +3258,19 @@ extern int __pyx_module_is_main_pysam__libcbcf; int __pyx_module_is_main_pysam__libcbcf = 0; /* Implementation of 'pysam.libcbcf' */ +static PyObject *__pyx_builtin_object; static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_chr; static PyObject *__pyx_builtin_KeyError; -static PyObject *__pyx_builtin_print; static PyObject *__pyx_builtin_IndexError; -static PyObject *__pyx_builtin_reversed; +static PyObject *__pyx_builtin_MemoryError; static PyObject *__pyx_builtin_enumerate; -static PyObject *__pyx_builtin_StopIteration; -static PyObject *__pyx_builtin_OSError; +static PyObject *__pyx_builtin_NotImplemented; +static PyObject *__pyx_builtin_reversed; static PyObject *__pyx_builtin_IOError; -static PyObject *__pyx_builtin_MemoryError; -static const char __pyx_k_[] = ","; +static PyObject *__pyx_builtin_StopIteration; static const char __pyx_k_A[] = "A"; static const char __pyx_k_G[] = "G"; static const char __pyx_k_R[] = "R"; @@ -3265,7 +3278,7 @@ static const char __pyx_k_r[] = "r"; static const char __pyx_k_w[] = "w"; static const char __pyx_k_GT[] = "GT"; static const char __pyx_k_ID[] = "ID"; -static const char __pyx_k__5[] = ""; +static const char __pyx_k__2[] = ","; static const char __pyx_k_gz[] = ".gz"; static const char __pyx_k_id[] = "id"; static const char __pyx_k_os[] = "os"; @@ -3273,14 +3286,18 @@ static const char __pyx_k_wb[] = "wb"; static const char __pyx_k_wz[] = "wz"; static const char __pyx_k_ALT[] = "ALT"; static const char __pyx_k_END[] = "END"; +static const char __pyx_k__15[] = ""; static const char __pyx_k__71[] = "."; static const char __pyx_k__74[] = "\""; +static const char __pyx_k_add[] = "add"; static const char __pyx_k_all[] = "__all__"; static const char __pyx_k_bcf[] = "bcf"; static const char __pyx_k_chr[] = "chr"; +static const char __pyx_k_end[] = "end"; static const char __pyx_k_get[] = "get"; static const char __pyx_k_key[] = "key"; static const char __pyx_k_new[] = "__new__"; +static const char __pyx_k_pop[] = "pop"; static const char __pyx_k_ref[] = "ref"; static const char __pyx_k_rwa[] = "rwa"; static const char __pyx_k_sys[] = "sys"; @@ -3290,8 +3307,8 @@ static const char __pyx_k_Flag[] = "Flag"; static const char __pyx_k_INFO[] = "INFO"; static const char __pyx_k_PASS[] = "PASS"; static const char __pyx_k_Type[] = "Type"; -static const char __pyx_k__167[] = ", "; -static const char __pyx_k__207[] = "-"; +static const char __pyx_k__175[] = ", "; +static const char __pyx_k__221[] = "-"; static const char __pyx_k_args[] = "args"; static const char __pyx_k_copy[] = "copy"; static const char __pyx_k_dict[] = "__dict__"; @@ -3304,21 +3321,21 @@ static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_mode[] = "mode"; static const char __pyx_k_name[] = "__name__"; static const char __pyx_k_open[] = "open"; +static const char __pyx_k_qual[] = "qual"; static const char __pyx_k_seek[] = "seek"; static const char __pyx_k_send[] = "send"; static const char __pyx_k_stop[] = "stop"; static const char __pyx_k_tell[] = "tell"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_type[] = "type"; -static const char __pyx_k_warn[] = "warn"; static const char __pyx_k_FIXED[] = "FIXED"; static const char __pyx_k_Float[] = "Float"; +static const char __pyx_k_ascii[] = "ascii"; static const char __pyx_k_bcf_2[] = ".bcf"; static const char __pyx_k_bcguz[] = "bcguz"; static const char __pyx_k_close[] = "close"; static const char __pyx_k_fetch[] = "fetch"; static const char __pyx_k_items[] = "items"; -static const char __pyx_k_print[] = "print"; static const char __pyx_k_range[] = "range"; static const char __pyx_k_remap[] = "remap"; static const char __pyx_k_split[] = "split"; @@ -3335,27 +3352,32 @@ static const char __pyx_k_Number[] = "Number"; static const char __pyx_k_String[] = "String"; static const char __pyx_k_append[] = "append"; static const char __pyx_k_contig[] = "contig"; -static const char __pyx_k_exists[] = "_exists"; +static const char __pyx_k_decode[] = "decode"; +static const char __pyx_k_filter[] = "filter"; static const char __pyx_k_format[] = "format"; static const char __pyx_k_header[] = "header"; static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_number[] = "number"; +static const char __pyx_k_object[] = "object"; +static const char __pyx_k_phased[] = "phased"; static const char __pyx_k_pickle[] = "pickle"; static const char __pyx_k_record[] = "record"; static const char __pyx_k_reduce[] = "__reduce__"; static const char __pyx_k_region[] = "region"; static const char __pyx_k_reopen[] = "reopen"; static const char __pyx_k_update[] = "update"; +static const char __pyx_k_values[] = "values"; static const char __pyx_k_GENERIC[] = "GENERIC"; static const char __pyx_k_IOError[] = "IOError"; static const char __pyx_k_Integer[] = "Integer"; -static const char __pyx_k_OSError[] = "OSError"; +static const char __pyx_k_NON_REF[] = ""; static const char __pyx_k_alleles[] = "alleles"; static const char __pyx_k_default[] = "default"; static const char __pyx_k_genexpr[] = "genexpr"; static const char __pyx_k_is_open[] = "is_open"; static const char __pyx_k_records[] = "records"; static const char __pyx_k_samples[] = "samples"; +static const char __pyx_k_threads[] = "threads"; static const char __pyx_k_KeyError[] = "KeyError"; static const char __pyx_k_VARIABLE[] = "VARIABLE"; static const char __pyx_k_add_meta[] = "add_meta"; @@ -3365,12 +3387,12 @@ static const char __pyx_k_getstate[] = "__getstate__"; static const char __pyx_k_pyx_type[] = "__pyx_type"; static const char __pyx_k_reversed[] = "reversed"; static const char __pyx_k_setstate[] = "__setstate__"; -static const char __pyx_k_warnings[] = "warnings"; static const char __pyx_k_TypeError[] = "TypeError"; static const char __pyx_k_enumerate[] = "enumerate"; static const char __pyx_k_iteritems[] = "iteritems"; static const char __pyx_k_pyx_state[] = "__pyx_state"; static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_reference[] = "reference"; static const char __pyx_k_IndexError[] = "IndexError"; static const char __pyx_k_STRUCTURED[] = "STRUCTURED"; static const char __pyx_k_ValueError[] = "ValueError"; @@ -3381,38 +3403,44 @@ static const char __pyx_k_pyx_result[] = "__pyx_result"; static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; static const char __pyx_k_startswith[] = "startswith"; static const char __pyx_k_Description[] = "Description"; +static const char __pyx_k_Invalid_tid[] = "Invalid tid"; static const char __pyx_k_MemoryError[] = "MemoryError"; static const char __pyx_k_PickleError[] = "PickleError"; static const char __pyx_k_VariantFile[] = "VariantFile"; static const char __pyx_k_description[] = "description"; -static const char __pyx_k_invalid_key[] = "invalid key"; +static const char __pyx_k_invalid_key[] = "invalid key: {}"; static const char __pyx_k_invalid_tag[] = "invalid tag"; static const char __pyx_k_drop_samples[] = "drop_samples"; +static const char __pyx_k_parse_region[] = "parse_region"; static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; static const char __pyx_k_stringsource[] = "stringsource"; -static const char __pyx_k_unknown_INFO[] = "unknown INFO"; +static const char __pyx_k_unknown_INFO[] = "unknown INFO: {}"; static const char __pyx_k_unknown_mode[] = "unknown mode {}"; static const char __pyx_k_StopIteration[] = "StopIteration"; static const char __pyx_k_VariantHeader[] = "VariantHeader"; static const char __pyx_k_VariantRecord[] = "VariantRecord"; static const char __pyx_k_pysam_libcbcf[] = "pysam.libcbcf"; static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; -static const char __pyx_k_Invalid_filter[] = "Invalid filter"; +static const char __pyx_k_Invalid_filter[] = "Invalid filter: {}"; static const char __pyx_k_Invalid_header[] = "Invalid header"; +static const char __pyx_k_NotImplemented[] = "NotImplemented"; static const char __pyx_k_Unknown_allele[] = "Unknown allele"; -static const char __pyx_k_file_not_found[] = "file `{}` not found"; static const char __pyx_k_index_filename[] = "index_filename"; -static const char __pyx_k_invalid_FORMAT[] = "invalid FORMAT"; -static const char __pyx_k_invalid_contig[] = "invalid contig"; +static const char __pyx_k_invalid_FORMAT[] = "invalid FORMAT: {}"; +static const char __pyx_k_invalid_contig[] = "invalid contig: {}"; static const char __pyx_k_truncated_file[] = "truncated file"; -static const char __pyx_k_unknown_format[] = "unknown format"; +static const char __pyx_k_unknown_format[] = "unknown format: {}"; static const char __pyx_k_limits_violated[] = "limits violated"; static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError"; static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; +static const char __pyx_k_unable_to_fetch[] = "unable to fetch {}:{}-{}"; +static const char __pyx_k_check_truncation[] = "check_truncation"; +static const char __pyx_k_invalid_contig_2[] = "invalid contig"; static const char __pyx_k_unsupported_type[] = "unsupported type"; static const char __pyx_k_Error_updating_id[] = "Error updating id"; static const char __pyx_k_Invalid_header_id[] = "Invalid header id"; static const char __pyx_k_bcguz0123456789ex[] = "bcguz0123456789ex"; +static const char __pyx_k_ignore_truncation[] = "ignore_truncation"; static const char __pyx_k_invalid_contig_id[] = "invalid contig id"; static const char __pyx_k_unsupported_types[] = "unsupported types"; static const char __pyx_k_vcf_format_failed[] = "vcf_format failed"; @@ -3421,15 +3449,16 @@ static const char __pyx_k_Unknown_INFO_field[] = "Unknown INFO field: {}"; static const char __pyx_k_bcf_index_required[] = "bcf index required"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_error_in_vcf_parse[] = "error in vcf_parse"; +static const char __pyx_k_get_reference_name[] = "get_reference_name"; static const char __pyx_k_BaseIndex_iteritems[] = "BaseIndex.iteritems"; static const char __pyx_k_VariantHeaderRecord[] = "VariantHeaderRecord"; -static const char __pyx_k_Variant_read_failed[] = "Variant read failed"; static const char __pyx_k_invalid_header_line[] = "invalid header line"; static const char __pyx_k_invalid_metadata_id[] = "invalid metadata id"; -static const char __pyx_k_invalid_sample_name[] = "invalid sample name"; +static const char __pyx_k_invalid_sample_name[] = "invalid sample name: {}"; static const char __pyx_k_BaseIndex_itervalues[] = "BaseIndex.itervalues"; static const char __pyx_k_Invalid_allele_index[] = "Invalid allele index"; static const char __pyx_k_Invalid_index_object[] = "Invalid index object"; +static const char __pyx_k_Unable_to_delete_END[] = "Unable to delete END"; static const char __pyx_k_bcf_must_not_be_None[] = "bcf must not be None"; static const char __pyx_k_duplicate_filehandle[] = "duplicate_filehandle"; static const char __pyx_k_invalid_contig_index[] = "invalid contig index"; @@ -3449,7 +3478,6 @@ static const char __pyx_k_Duplicated_sample_name[] = "Duplicated sample name: {} static const char __pyx_k_Error_s_reading_record[] = "Error(s) reading record: {}"; static const char __pyx_k_Error_updating_alleles[] = "Error updating alleles"; static const char __pyx_k_cannot_set_null_allele[] = "cannot set null allele"; -static const char __pyx_k_error_reading_BCF_file[] = "error reading BCF file"; static const char __pyx_k_pyx_unpickle_BaseIndex[] = "__pyx_unpickle_BaseIndex"; static const char __pyx_k_unknown_type_specified[] = "unknown type specified: {}"; static const char __pyx_k_Unable_to_delete_FORMAT[] = "Unable to delete FORMAT"; @@ -3459,9 +3487,9 @@ static const char __pyx_k_header_must_not_be_None[] = "header must not be None"; static const char __pyx_k_invalid_character_found[] = "invalid character found"; static const char __pyx_k_record_must_not_be_None[] = "record must not be None"; static const char __pyx_k_sample_must_not_be_None[] = "sample must not be None"; -static const char __pyx_k_Unknown_contig_specified[] = "Unknown contig specified"; static const char __pyx_k_VariantRecordInfo___iter[] = "VariantRecordInfo.__iter__"; static const char __pyx_k_cannot_find_metadata_key[] = "cannot find metadata key"; +static const char __pyx_k_contig_must_be_specified[] = "contig must be specified"; static const char __pyx_k_could_not_open_file_mode[] = "could not open file `{}` (mode='{}')"; static const char __pyx_k_Cannot_create_empty_array[] = "Cannot create empty array"; static const char __pyx_k_Invalid_chromosome_contig[] = "Invalid chromosome/contig"; @@ -3483,11 +3511,13 @@ static const char __pyx_k_VariantRecordInfo_iteritems[] = "VariantRecordInfo.ite static const char __pyx_k_VariantRecordSamples___iter[] = "VariantRecordSamples.__iter__"; static const char __pyx_k_cannot_create_VariantHeader[] = "cannot create VariantHeader"; static const char __pyx_k_cannot_create_VariantRecord[] = "cannot create VariantRecord"; +static const char __pyx_k_could_not_open_variant_file[] = "could not open variant file `{}`: {}"; static const char __pyx_k_dst_header_must_not_be_None[] = "dst_header must not be None"; static const char __pyx_k_invalid_header_record_index[] = "invalid header record index"; static const char __pyx_k_missing_d_requested_samples[] = "missing {:d} requested samples"; +static const char __pyx_k_must_set_at_least_2_alleles[] = "must set at least 2 alleles"; static const char __pyx_k_ref_allele_must_not_be_null[] = "ref allele must not be null"; -static const char __pyx_k_value_expected_to_be_scalar[] = "value expected to be scalar"; +static const char __pyx_k_unable_to_fetch_next_record[] = "unable to fetch next record"; static const char __pyx_k_Header_already_exists_for_id[] = "Header already exists for id={}"; static const char __pyx_k_I_O_operation_on_closed_file[] = "I/O operation on closed file"; static const char __pyx_k_Unable_to_update_INFO_values[] = "Unable to update INFO values"; @@ -3496,12 +3526,14 @@ static const char __pyx_k_VariantRecordInfo_itervalues[] = "VariantRecordInfo.it static const char __pyx_k_pyx_unpickle_VariantMetadata[] = "__pyx_unpickle_VariantMetadata"; static const char __pyx_k_unsupported_header_type_code[] = "unsupported header type code"; static const char __pyx_k_Error_unpacking_VariantRecord[] = "Error unpacking VariantRecord"; +static const char __pyx_k_Stop_position_of_the_interval[] = "Stop position of the interval"; static const char __pyx_k_VariantHeaderRecord_iteritems[] = "VariantHeaderRecord.iteritems"; static const char __pyx_k_VariantRecordFilter_iteritems[] = "VariantRecordFilter.iteritems"; static const char __pyx_k_VariantRecordFormat_iteritems[] = "VariantRecordFormat.iteritems"; static const char __pyx_k_VariantRecordSample_iteritems[] = "VariantRecordSample.iteritems"; +static const char __pyx_k_could_not_open_variant_file_2[] = "could not open variant file `{}`"; static const char __pyx_k_mode_must_begin_with_r_w_or_a[] = "mode must begin with r, w or a"; -static const char __pyx_k_values_expected_to_be_d_tuple[] = "values expected to be {:d}-tuple"; +static const char __pyx_k_unable_to_allocate_BCF_record[] = "unable to allocate BCF record"; static const char __pyx_k_Unable_to_update_format_values[] = "Unable to update format values"; static const char __pyx_k_VariantHeaderContigs_iteritems[] = "VariantHeaderContigs.iteritems"; static const char __pyx_k_VariantHeaderRecord_itervalues[] = "VariantHeaderRecord.itervalues"; @@ -3510,7 +3542,6 @@ static const char __pyx_k_VariantRecordFormat_itervalues[] = "VariantRecordForma static const char __pyx_k_VariantRecordSample_itervalues[] = "VariantRecordSample.itervalues"; static const char __pyx_k_VariantRecordSamples_iteritems[] = "VariantRecordSamples.iteritems"; static const char __pyx_k_bcf_hdr_set_samples_failed_ret[] = "bcf_hdr_set_samples failed: ret = {}"; -static const char __pyx_k_error_reading_indexed_VCF_file[] = "error reading indexed VCF file"; static const char __pyx_k_invalid_value_for_Float_format[] = "invalid value for Float format"; static const char __pyx_k_pyx_unpickle_VariantHeaderCont[] = "__pyx_unpickle_VariantHeaderContigs"; static const char __pyx_k_pyx_unpickle_VariantHeaderMeta[] = "__pyx_unpickle_VariantHeaderMetadata"; @@ -3522,21 +3553,21 @@ static const char __pyx_k_pyx_unpickle_VariantRecordInfo[] = "__pyx_unpickle_Var static const char __pyx_k_pyx_unpickle_VariantRecordSamp[] = "__pyx_unpickle_VariantRecordSamples"; static const char __pyx_k_Invalid_VariantRecord_Number_of[] = "Invalid VariantRecord. Number of samples does not match header ({} vs {})"; static const char __pyx_k_Number_must_be_None_when_adding[] = "Number must be None when adding a filter"; -static const char __pyx_k_Stop_coordinate_must_be_greater[] = "Stop coordinate must be greater than or equal to start"; static const char __pyx_k_Type_must_be_None_when_adding_a[] = "Type must be None when adding a filter"; static const char __pyx_k_VariantHeaderContigs_itervalues[] = "VariantHeaderContigs.itervalues"; static const char __pyx_k_VariantHeaderMetadata_iteritems[] = "VariantHeaderMetadata.iteritems"; static const char __pyx_k_VariantRecordSamples_itervalues[] = "VariantRecordSamples.itervalues"; static const char __pyx_k_bcf_check_values_locals_genexpr[] = "bcf_check_values..genexpr"; static const char __pyx_k_cannot_iterate_over_Variantfile[] = "cannot iterate over Variantfile opened for writing"; -static const char __pyx_k_file_does_not_have_valid_header[] = "file `{}` does not have valid header (mode='{}') - is it VCF/BCF format?"; -static const char __pyx_k_invalid_file_mode_is_it_VCF_BCF[] = "invalid file `{}` (mode='{}') - is it VCF/BCF format?"; -static const char __pyx_k_s_Warning_no_BGZF_EOF_marker_fi[] = "[%s] Warning: no BGZF EOF marker; file may be truncated"; +static const char __pyx_k_file_does_not_have_valid_header[] = "file `{}` does not have valid header (mode=`{}`) - is it VCF/BCF format?"; +static const char __pyx_k_invalid_file_mode_is_it_VCF_BCF[] = "invalid file `{}` (mode=`{}`) - is it VCF/BCF format?"; static const char __pyx_k_self_ptr_cannot_be_converted_to[] = "self.ptr cannot be converted to a Python object for pickling"; +static const char __pyx_k_Cannot_add_extra_threads_when_ig[] = "Cannot add extra threads when \"ignore_truncation\" is True"; static const char __pyx_k_Cannot_copy_arrays_with_src_valu[] = "Cannot copy arrays with src_values={} > dst_values={}"; static const char __pyx_k_Cannot_set_phased_before_genotyp[] = "Cannot set phased before genotype is set"; static const char __pyx_k_Cannot_specify_an_index_filename[] = "Cannot specify an index filename when writing a VCF/BCF file"; static const char __pyx_k_Cannot_translate_record_Number_o[] = "Cannot translate record. Number of samples does not match header ({} vs {})"; +static const char __pyx_k_END_is_a_reserved_attribute_acce[] = "END is a reserved attribute; access is via record.stop"; static const char __pyx_k_Flag_types_are_not_allowed_on_FO[] = "Flag types are not allowed on FORMATs"; static const char __pyx_k_Flag_values_must_be_True_False_N[] = "Flag values must be: True, False, None, 1, 0"; static const char __pyx_k_Header_already_exists_for_contig[] = "Header already exists for contig {}"; @@ -3548,9 +3579,8 @@ static const char __pyx_k_Incompatible_checksums_s_vs_0xd9[] = "Incompatible che static const char __pyx_k_Incompatible_checksums_s_vs_0xde[] = "Incompatible checksums (%s vs 0xde17f0f = (record))"; static const char __pyx_k_Incompatible_checksums_s_vs_0xed[] = "Incompatible checksums (%s vs 0xed5e66b = (header, type))"; static const char __pyx_k_Integer_value_too_small_large_to[] = "Integer value too small/large to store in VCF/BCF"; -static const char __pyx_k_Reference_length_must_be_non_neg[] = "Reference length must be non-negative"; -static const char __pyx_k_Removing_header_type_key_value_h[] = "Removing header type={} key={} value={} hdr={}"; static const char __pyx_k_Start_coordinate_must_be_non_neg[] = "Start coordinate must be non-negative"; +static const char __pyx_k_Stop_coordinate_must_be_non_nega[] = "Stop coordinate must be non-negative"; static const char __pyx_k_VariantHeaderMetadata_itervalues[] = "VariantHeaderMetadata.itervalues"; static const char __pyx_k_VariantHeaderRecord___get___loca[] = "VariantHeaderRecord.__get__..genexpr"; static const char __pyx_k_bcf_array_to_object_locals_genex[] = "bcf_array_to_object..genexpr"; @@ -3562,21 +3592,22 @@ static const char __pyx_k_cannot_subset_samples_after_fetc[] = "cannot subset sa static const char __pyx_k_cannot_subset_samples_from_Varia[] = "cannot subset samples from Variantfile opened for writing"; static const char __pyx_k_cannot_write_to_a_Variantfile_op[] = "cannot write to a Variantfile opened for reading"; static const char __pyx_k_char_array_to_tuple_locals_genex[] = "char_array_to_tuple..genexpr"; -static const char __pyx_k_could_not_open_file_mode_is_it_V[] = "could not open file `{}` (mode='{}') - is it VCF/BCF format?"; static const char __pyx_k_either_value_or_items_must_be_sp[] = "either value or items must be specified"; +static const char __pyx_k_genotype_is_only_valid_as_a_form[] = "genotype is only valid as a format field"; static const char __pyx_k_invalid_value_for_Integer_format[] = "invalid value for Integer format"; static const char __pyx_k_mode_contains_conflicting_format[] = "mode contains conflicting format specifiers: {}"; static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__"; static const char __pyx_k_pyx_unpickle_VariantRecordSamp_2[] = "__pyx_unpickle_VariantRecordSample"; static const char __pyx_k_self_iter_cannot_be_converted_to[] = "self.iter cannot be converted to a Python object for pickling"; static const char __pyx_k_this_class_cannot_be_instantiate[] = "this class cannot be instantiated from Python"; -static PyObject *__pyx_kp_b_; -static PyObject *__pyx_kp_s_; +static const char __pyx_k_value_expected_to_be_scalar_give[] = "value expected to be scalar, given len={}"; +static const char __pyx_k_values_expected_to_be_tuple_give[] = "values expected to be {}-tuple, given len={}"; static PyObject *__pyx_n_s_A; static PyObject *__pyx_n_s_ALT; static PyObject *__pyx_n_s_BaseIndex_iteritems; static PyObject *__pyx_n_s_BaseIndex_itervalues; static PyObject *__pyx_n_s_CONTIG; +static PyObject *__pyx_kp_s_Cannot_add_extra_threads_when_ig; static PyObject *__pyx_kp_s_Cannot_copy_arrays_with_src_valu; static PyObject *__pyx_kp_s_Cannot_create_empty_array; static PyObject *__pyx_kp_s_Cannot_re_open_htsfile; @@ -3585,7 +3616,9 @@ static PyObject *__pyx_kp_s_Cannot_specify_an_index_filename; static PyObject *__pyx_kp_s_Cannot_translate_record_Number_o; static PyObject *__pyx_n_s_Description; static PyObject *__pyx_kp_s_Duplicated_sample_name; +static PyObject *__pyx_n_b_END; static PyObject *__pyx_n_s_END; +static PyObject *__pyx_kp_s_END_is_a_reserved_attribute_acce; static PyObject *__pyx_kp_s_Error_s_reading_record; static PyObject *__pyx_kp_s_Error_unpacking_VariantRecord; static PyObject *__pyx_kp_s_Error_updating_alleles; @@ -3625,32 +3658,33 @@ static PyObject *__pyx_kp_s_Invalid_header; static PyObject *__pyx_kp_s_Invalid_header_id; static PyObject *__pyx_kp_s_Invalid_header_record_index; static PyObject *__pyx_kp_s_Invalid_index_object; +static PyObject *__pyx_kp_s_Invalid_tid; static PyObject *__pyx_n_s_KeyError; static PyObject *__pyx_n_s_MemoryError; +static PyObject *__pyx_kp_s_NON_REF; +static PyObject *__pyx_n_s_NotImplemented; static PyObject *__pyx_n_s_Number; static PyObject *__pyx_kp_s_Number_must_be_None_when_adding; -static PyObject *__pyx_n_s_OSError; static PyObject *__pyx_n_s_PASS; static PyObject *__pyx_n_s_PickleError; static PyObject *__pyx_kp_s_Position_must_be_positive; static PyObject *__pyx_n_s_R; -static PyObject *__pyx_kp_s_Reference_length_must_be_non_neg; -static PyObject *__pyx_kp_s_Removing_header_type_key_value_h; static PyObject *__pyx_n_s_STRUCTURED; static PyObject *__pyx_kp_s_Start_coordinate_must_be_non_neg; static PyObject *__pyx_n_s_StopIteration; -static PyObject *__pyx_kp_s_Stop_coordinate_must_be_greater; +static PyObject *__pyx_kp_s_Stop_coordinate_must_be_non_nega; +static PyObject *__pyx_kp_s_Stop_position_of_the_interval; static PyObject *__pyx_n_s_String; static PyObject *__pyx_n_s_Type; static PyObject *__pyx_n_s_TypeError; static PyObject *__pyx_kp_s_Type_must_be_None_when_adding_a; +static PyObject *__pyx_kp_s_Unable_to_delete_END; static PyObject *__pyx_kp_s_Unable_to_delete_FORMAT; static PyObject *__pyx_kp_s_Unable_to_delete_INFO; static PyObject *__pyx_kp_s_Unable_to_update_INFO_values; static PyObject *__pyx_kp_s_Unable_to_update_format_values; static PyObject *__pyx_kp_s_Unknown_INFO_field; static PyObject *__pyx_kp_s_Unknown_allele; -static PyObject *__pyx_kp_s_Unknown_contig_specified; static PyObject *__pyx_kp_s_Unknown_format_length; static PyObject *__pyx_kp_s_Unsupported_FORMAT_type; static PyObject *__pyx_kp_s_Unsupported_INFO_type; @@ -3687,20 +3721,23 @@ static PyObject *__pyx_n_s_VariantRecordSample_itervalues; static PyObject *__pyx_n_s_VariantRecordSamples___iter; static PyObject *__pyx_n_s_VariantRecordSamples_iteritems; static PyObject *__pyx_n_s_VariantRecordSamples_itervalues; -static PyObject *__pyx_kp_s_Variant_read_failed; -static PyObject *__pyx_kp_s__167; -static PyObject *__pyx_kp_b__207; -static PyObject *__pyx_kp_b__5; -static PyObject *__pyx_kp_s__5; +static PyObject *__pyx_kp_b__15; +static PyObject *__pyx_kp_s__15; +static PyObject *__pyx_kp_s__175; +static PyObject *__pyx_kp_b__2; +static PyObject *__pyx_kp_s__2; +static PyObject *__pyx_kp_b__221; static PyObject *__pyx_kp_b__71; static PyObject *__pyx_kp_s__71; static PyObject *__pyx_kp_s__74; +static PyObject *__pyx_n_s_add; static PyObject *__pyx_n_s_add_meta; static PyObject *__pyx_n_s_add_sample; static PyObject *__pyx_n_s_all; static PyObject *__pyx_n_s_alleles; static PyObject *__pyx_n_s_append; static PyObject *__pyx_n_s_args; +static PyObject *__pyx_n_s_ascii; static PyObject *__pyx_n_s_bcf; static PyObject *__pyx_kp_s_bcf_2; static PyObject *__pyx_n_s_bcf_array_to_object_locals_genex; @@ -3724,13 +3761,17 @@ static PyObject *__pyx_kp_s_cannot_subset_samples_after_fetc; static PyObject *__pyx_kp_s_cannot_subset_samples_from_Varia; static PyObject *__pyx_kp_s_cannot_write_to_a_Variantfile_op; static PyObject *__pyx_n_s_char_array_to_tuple_locals_genex; +static PyObject *__pyx_n_s_check_truncation; static PyObject *__pyx_n_s_chr; static PyObject *__pyx_n_s_cline_in_traceback; static PyObject *__pyx_n_s_close; static PyObject *__pyx_n_s_contig; +static PyObject *__pyx_kp_s_contig_must_be_specified; static PyObject *__pyx_n_s_copy; static PyObject *__pyx_kp_s_could_not_open_file_mode; -static PyObject *__pyx_kp_s_could_not_open_file_mode_is_it_V; +static PyObject *__pyx_kp_s_could_not_open_variant_file; +static PyObject *__pyx_kp_s_could_not_open_variant_file_2; +static PyObject *__pyx_n_s_decode; static PyObject *__pyx_n_s_default; static PyObject *__pyx_n_s_description; static PyObject *__pyx_n_s_dict; @@ -3738,27 +3779,28 @@ static PyObject *__pyx_n_s_drop_samples; static PyObject *__pyx_kp_s_dst_header_must_not_be_None; static PyObject *__pyx_n_s_duplicate_filehandle; static PyObject *__pyx_kp_s_either_value_or_items_must_be_sp; +static PyObject *__pyx_n_s_end; static PyObject *__pyx_n_s_endswith; static PyObject *__pyx_n_s_enumerate; static PyObject *__pyx_kp_s_error_in_bcf_subset_format; static PyObject *__pyx_kp_s_error_in_vcf_parse; -static PyObject *__pyx_kp_s_error_reading_BCF_file; -static PyObject *__pyx_kp_s_error_reading_indexed_VCF_file; -static PyObject *__pyx_n_s_exists; static PyObject *__pyx_n_s_fetch; static PyObject *__pyx_kp_s_fetch_requires_an_index; static PyObject *__pyx_kp_s_file_does_not_have_valid_header; -static PyObject *__pyx_kp_s_file_not_found; static PyObject *__pyx_n_s_filename; +static PyObject *__pyx_n_s_filter; static PyObject *__pyx_n_s_format; static PyObject *__pyx_n_s_genexpr; +static PyObject *__pyx_kp_s_genotype_is_only_valid_as_a_form; static PyObject *__pyx_n_s_get; +static PyObject *__pyx_n_s_get_reference_name; static PyObject *__pyx_n_s_getstate; static PyObject *__pyx_kp_s_gz; static PyObject *__pyx_n_s_hash; static PyObject *__pyx_n_s_header; static PyObject *__pyx_kp_s_header_must_not_be_None; static PyObject *__pyx_n_s_id; +static PyObject *__pyx_n_s_ignore_truncation; static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_index_filename; static PyObject *__pyx_n_s_info; @@ -3768,6 +3810,7 @@ static PyObject *__pyx_kp_s_invalid_VariantHeader; static PyObject *__pyx_kp_s_invalid_VariantRecord; static PyObject *__pyx_kp_s_invalid_character_found; static PyObject *__pyx_kp_s_invalid_contig; +static PyObject *__pyx_kp_s_invalid_contig_2; static PyObject *__pyx_kp_s_invalid_contig_id; static PyObject *__pyx_kp_s_invalid_contig_index; static PyObject *__pyx_kp_s_invalid_file_mode_is_it_VCF_BCF; @@ -3798,15 +3841,19 @@ static PyObject *__pyx_kp_s_missing_d_requested_samples; static PyObject *__pyx_n_s_mode; static PyObject *__pyx_kp_s_mode_contains_conflicting_format; static PyObject *__pyx_kp_s_mode_must_begin_with_r_w_or_a; +static PyObject *__pyx_kp_s_must_set_at_least_2_alleles; static PyObject *__pyx_n_s_name; static PyObject *__pyx_n_s_new; static PyObject *__pyx_n_s_new_record; static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; static PyObject *__pyx_n_s_number; +static PyObject *__pyx_n_s_object; static PyObject *__pyx_n_s_open; static PyObject *__pyx_n_s_os; +static PyObject *__pyx_n_s_parse_region; +static PyObject *__pyx_n_s_phased; static PyObject *__pyx_n_s_pickle; -static PyObject *__pyx_n_s_print; +static PyObject *__pyx_n_s_pop; static PyObject *__pyx_n_s_pysam_libcbcf; static PyObject *__pyx_n_s_pyx_PickleError; static PyObject *__pyx_n_s_pyx_checksum; @@ -3826,6 +3873,7 @@ static PyObject *__pyx_n_s_pyx_unpickle_VariantRecordInfo; static PyObject *__pyx_n_s_pyx_unpickle_VariantRecordSamp; static PyObject *__pyx_n_s_pyx_unpickle_VariantRecordSamp_2; static PyObject *__pyx_n_s_pyx_vtable; +static PyObject *__pyx_n_s_qual; static PyObject *__pyx_n_b_r; static PyObject *__pyx_n_s_r; static PyObject *__pyx_n_s_range; @@ -3837,12 +3885,12 @@ static PyObject *__pyx_n_s_reduce_cython; static PyObject *__pyx_n_s_reduce_ex; static PyObject *__pyx_n_s_ref; static PyObject *__pyx_kp_s_ref_allele_must_not_be_null; +static PyObject *__pyx_n_s_reference; static PyObject *__pyx_n_s_region; static PyObject *__pyx_n_s_remap; static PyObject *__pyx_n_s_reopen; static PyObject *__pyx_n_s_reversed; static PyObject *__pyx_n_s_rwa; -static PyObject *__pyx_kp_s_s_Warning_no_BGZF_EOF_marker_fi; static PyObject *__pyx_kp_s_sample_must_not_be_None; static PyObject *__pyx_n_s_samples; static PyObject *__pyx_n_s_seek; @@ -3862,9 +3910,13 @@ static PyObject *__pyx_kp_s_tabix_index_required; static PyObject *__pyx_n_s_tell; static PyObject *__pyx_n_s_test; static PyObject *__pyx_kp_s_this_class_cannot_be_instantiate; +static PyObject *__pyx_n_s_threads; static PyObject *__pyx_n_s_throw; static PyObject *__pyx_kp_s_truncated_file; static PyObject *__pyx_n_s_type; +static PyObject *__pyx_kp_s_unable_to_allocate_BCF_record; +static PyObject *__pyx_kp_s_unable_to_fetch; +static PyObject *__pyx_kp_s_unable_to_fetch_next_record; static PyObject *__pyx_kp_s_unknown_INFO; static PyObject *__pyx_kp_s_unknown_format; static PyObject *__pyx_kp_s_unknown_mode; @@ -3876,13 +3928,12 @@ static PyObject *__pyx_kp_s_unsupported_types; static PyObject *__pyx_n_s_update; static PyObject *__pyx_n_s_upper; static PyObject *__pyx_n_s_value; -static PyObject *__pyx_kp_s_value_expected_to_be_scalar; -static PyObject *__pyx_kp_s_values_expected_to_be_d_tuple; +static PyObject *__pyx_kp_s_value_expected_to_be_scalar_give; +static PyObject *__pyx_n_s_values; +static PyObject *__pyx_kp_s_values_expected_to_be_tuple_give; static PyObject *__pyx_kp_s_vcf_format_failed; static PyObject *__pyx_n_b_w; static PyObject *__pyx_n_s_w; -static PyObject *__pyx_n_s_warn; -static PyObject *__pyx_n_s_warnings; static PyObject *__pyx_n_s_wb; static PyObject *__pyx_n_s_wb0; static PyObject *__pyx_n_s_wbu; @@ -3910,15 +3961,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_20iteritems(stru static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_23keys(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_25items(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_27values(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31remove(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_33__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_35__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29update(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self, PyObject *__pyx_v_items, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31pop(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_33__str__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_35remove(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_37__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_39__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_2__len__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_4__bool__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_6__getitem__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_v_self, PyObject *__pyx_v_index); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_8__iter__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_11__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_13__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_15VariantMetadata___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ @@ -3929,6 +3984,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4type___get__(struct static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_11description___get__(struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6record___get__(struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_2remove_header(struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ @@ -3947,14 +4003,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_26iteritems(st static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_29keys(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_31items(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_33values(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_35__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_37__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_13VariantContig___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4name___get__(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_2id___get__(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6length___get__(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_13header_record___get__(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_2remove_header(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ @@ -3973,6 +4031,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_27keys(struct _ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_29items(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_31values(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_33add(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_v_self, PyObject *__pyx_v_id, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_35__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_37__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ @@ -3982,6 +4041,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_6__getitem__(st static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_8__iter__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_11__contains__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_13add(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_v_self, PyObject *__pyx_v_name); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_15__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_17__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_13VariantHeader___cinit__(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self); /* proto */ @@ -3999,7 +4059,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4info___get__(struct _ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7formats___get__(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4alts___get__(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_12__str__(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_14new_record(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_14new_record(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_alleles, PyObject *__pyx_v_id, PyObject *__pyx_v_qual, PyObject *__pyx_v_filter, PyObject *__pyx_v_info, PyObject *__pyx_v_samples, PyObject *__pyx_v_kwargs); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_16add_record(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_record); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_18add_line(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, PyObject *__pyx_v_line); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_20add_meta(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value, PyObject *__pyx_v_items); /* proto */ @@ -4022,8 +4082,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_26iteritems(stru static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_29keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_31items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_33values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_35__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_37__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_35__richcmp__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_other, int __pyx_v_op); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_37__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_39__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_2__len__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_4__bool__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self); /* proto */ @@ -4057,8 +4118,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_26iteritems(struct static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_29keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_31items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_33values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_37__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35update(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_items, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_37pop(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_39__richcmp__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_other, int __pyx_v_op); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_41__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_43__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_2__len__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_4__bool__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self); /* proto */ @@ -4072,8 +4136,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_20iteritems(str static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_23keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_25items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_27values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_31__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29update(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self, PyObject *__pyx_v_items, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_31pop(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_33__richcmp__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_other, int __pyx_v_op); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_35__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_37__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ static void __pyx_pf_5pysam_7libcbcf_13VariantRecord_2__dealloc__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4copy(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ @@ -4099,16 +4166,18 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_2id_2__set__(struct __pyx_ob static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref_2__set__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles_2__set__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles_2__set__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, PyObject *__pyx_v_values); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts_2__set__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6filter___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4info___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6format___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7samples___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_10__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__richcmp__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_other, int __pyx_v_op); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_10__str__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_12__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_14__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4name___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_14allele_indices___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self); /* proto */ @@ -4134,9 +4203,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_26iteritems(stru static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_29keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_31items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_33values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35update(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self, PyObject *__pyx_v_items, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_37pop(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_39__richcmp__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_other, int __pyx_v_op); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_5index___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_37__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_41__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_43__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex___init__(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self); /* proto */ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_9BaseIndex_2__len__(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self); /* proto */ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex_4__bool__(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self); /* proto */ @@ -4150,28 +4222,31 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_19iteritems(struct __pyx_ob static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_22keys(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_24items(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_26values(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_30__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28update(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self, PyObject *__pyx_v_items, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_30pop(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_32__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_34__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_v_self); /* proto */ static void __pyx_pf_5pysam_7libcbcf_8BCFIndex_2__dealloc__(struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_4fetch(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_v_self, PyObject *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reopen); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_4fetch(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_v_self, PyObject *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_reopen); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_6header___get__(struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_v_self); /* proto */ static void __pyx_pf_5pysam_7libcbcf_10TabixIndex_2__dealloc__(struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_10TabixIndex_4fetch(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_v_self, PyObject *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reopen); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_10TabixIndex_4fetch(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_v_self, PyObject *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_reopen); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_10TabixIndex_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_10TabixIndex_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_12BaseIterator___reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_BaseIterator *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_12BaseIterator_2__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_BaseIterator *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ -static int __pyx_pf_5pysam_7libcbcf_11BCFIterator___init__(struct __pyx_obj_5pysam_7libcbcf_BCFIterator *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reopen); /* proto */ +static int __pyx_pf_5pysam_7libcbcf_11BCFIterator___init__(struct __pyx_obj_5pysam_7libcbcf_BCFIterator *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_reopen); /* proto */ static void __pyx_pf_5pysam_7libcbcf_11BCFIterator_2__dealloc__(struct __pyx_obj_5pysam_7libcbcf_BCFIterator *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_4__iter__(struct __pyx_obj_5pysam_7libcbcf_BCFIterator *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_obj_5pysam_7libcbcf_BCFIterator *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_BCFIterator *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_BCFIterator *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_13TabixIterator___cinit__(struct __pyx_obj_5pysam_7libcbcf_TabixIterator *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ -static int __pyx_pf_5pysam_7libcbcf_13TabixIterator_2__init__(struct __pyx_obj_5pysam_7libcbcf_TabixIterator *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reopen); /* proto */ +static int __pyx_pf_5pysam_7libcbcf_13TabixIterator_2__init__(struct __pyx_obj_5pysam_7libcbcf_TabixIterator *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_reopen); /* proto */ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_obj_5pysam_7libcbcf_TabixIterator *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_6__iter__(struct __pyx_obj_5pysam_7libcbcf_TabixIterator *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx_obj_5pysam_7libcbcf_TabixIterator *__pyx_v_self); /* proto */ @@ -4179,23 +4254,27 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_10__reduce_cython__(CY static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_TabixIterator *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_7libcbcf_11VariantFile___cinit__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_4close(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6__iter__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_index_filename, struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_header, PyObject *__pyx_v_drop_samples, PyObject *__pyx_v_duplicate_filehandle); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_14reset(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reopen); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_18new_record(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_20write(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_22subset_samples(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_include_samples); /* proto */ +static void __pyx_pf_5pysam_7libcbcf_11VariantFile_4__dealloc__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6close(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__iter__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10__next__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12copy(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_14open(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_index_filename, struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_header, PyObject *__pyx_v_drop_samples, PyObject *__pyx_v_duplicate_filehandle, PyObject *__pyx_v_ignore_truncation, PyObject *__pyx_v_threads); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16reset(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_18is_valid_tid(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_20get_tid(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_22get_reference_name(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_24fetch(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reopen, PyObject *__pyx_v_end, PyObject *__pyx_v_reference); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_26new_record(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_28write(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_30subset_samples(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_include_samples); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_5index___get__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12drop_samples___get__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10is_reading___get__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_14header_written___get__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_24__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_26__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_32__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_34__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_2__pyx_unpickle_VariantMetadata(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_7libcbcf_4__pyx_unpickle_VariantHeaderMetadata(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ @@ -4269,10 +4348,12 @@ static PyObject *__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_34_itervalues(P static PyObject *__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_35_iteritems(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_36_itervalues(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_37_iteritems(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_get = {0, &__pyx_n_s_get, 0, 0, 0}; +static __Pyx_CachedCFunction __pyx_umethod_PyBytes_Type_split = {0, &__pyx_n_s_split, 0, 0, 0}; static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_items = {0, &__pyx_n_s_items, 0, 0, 0}; +static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_pop = {0, &__pyx_n_s_pop, 0, 0, 0}; static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; +static PyObject *__pyx_int_2; static PyObject *__pyx_int_10091417; static PyObject *__pyx_int_97976187; static PyObject *__pyx_int_164668780; @@ -4282,9 +4363,15 @@ static PyObject *__pyx_int_232881935; static PyObject *__pyx_int_248899179; static PyObject *__pyx_int_4294967294; static PyObject *__pyx_int_neg_1; -static PyObject *__pyx_tuple__2; +static PyObject *__pyx_k__61; +static PyObject *__pyx_k__133; +static PyObject *__pyx_k__140; +static PyObject *__pyx_k__180; +static PyObject *__pyx_k__182; +static PyObject *__pyx_tuple_; static PyObject *__pyx_tuple__3; static PyObject *__pyx_tuple__4; +static PyObject *__pyx_tuple__5; static PyObject *__pyx_tuple__6; static PyObject *__pyx_tuple__7; static PyObject *__pyx_tuple__8; @@ -4294,7 +4381,6 @@ static PyObject *__pyx_tuple__11; static PyObject *__pyx_tuple__12; static PyObject *__pyx_tuple__13; static PyObject *__pyx_tuple__14; -static PyObject *__pyx_tuple__15; static PyObject *__pyx_tuple__16; static PyObject *__pyx_tuple__17; static PyObject *__pyx_tuple__18; @@ -4340,7 +4426,6 @@ static PyObject *__pyx_tuple__57; static PyObject *__pyx_tuple__58; static PyObject *__pyx_tuple__59; static PyObject *__pyx_tuple__60; -static PyObject *__pyx_tuple__61; static PyObject *__pyx_tuple__62; static PyObject *__pyx_tuple__63; static PyObject *__pyx_tuple__64; @@ -4377,8 +4462,8 @@ static PyObject *__pyx_tuple__96; static PyObject *__pyx_tuple__97; static PyObject *__pyx_tuple__98; static PyObject *__pyx_tuple__99; -static PyObject *__pyx_slice__203; -static PyObject *__pyx_slice__204; +static PyObject *__pyx_slice__217; +static PyObject *__pyx_slice__218; static PyObject *__pyx_tuple__100; static PyObject *__pyx_tuple__101; static PyObject *__pyx_tuple__102; @@ -4412,14 +4497,12 @@ static PyObject *__pyx_tuple__129; static PyObject *__pyx_tuple__130; static PyObject *__pyx_tuple__131; static PyObject *__pyx_tuple__132; -static PyObject *__pyx_tuple__133; static PyObject *__pyx_tuple__134; static PyObject *__pyx_tuple__135; static PyObject *__pyx_tuple__136; static PyObject *__pyx_tuple__137; static PyObject *__pyx_tuple__138; static PyObject *__pyx_tuple__139; -static PyObject *__pyx_tuple__140; static PyObject *__pyx_tuple__141; static PyObject *__pyx_tuple__142; static PyObject *__pyx_tuple__143; @@ -4446,6 +4529,7 @@ static PyObject *__pyx_tuple__163; static PyObject *__pyx_tuple__164; static PyObject *__pyx_tuple__165; static PyObject *__pyx_tuple__166; +static PyObject *__pyx_tuple__167; static PyObject *__pyx_tuple__168; static PyObject *__pyx_tuple__169; static PyObject *__pyx_tuple__170; @@ -4453,14 +4537,11 @@ static PyObject *__pyx_tuple__171; static PyObject *__pyx_tuple__172; static PyObject *__pyx_tuple__173; static PyObject *__pyx_tuple__174; -static PyObject *__pyx_tuple__175; static PyObject *__pyx_tuple__176; static PyObject *__pyx_tuple__177; static PyObject *__pyx_tuple__178; static PyObject *__pyx_tuple__179; -static PyObject *__pyx_tuple__180; static PyObject *__pyx_tuple__181; -static PyObject *__pyx_tuple__182; static PyObject *__pyx_tuple__183; static PyObject *__pyx_tuple__184; static PyObject *__pyx_tuple__185; @@ -4481,8 +4562,11 @@ static PyObject *__pyx_tuple__199; static PyObject *__pyx_tuple__200; static PyObject *__pyx_tuple__201; static PyObject *__pyx_tuple__202; +static PyObject *__pyx_tuple__203; +static PyObject *__pyx_tuple__204; static PyObject *__pyx_tuple__205; static PyObject *__pyx_tuple__206; +static PyObject *__pyx_tuple__207; static PyObject *__pyx_tuple__208; static PyObject *__pyx_tuple__209; static PyObject *__pyx_tuple__210; @@ -4492,41 +4576,56 @@ static PyObject *__pyx_tuple__213; static PyObject *__pyx_tuple__214; static PyObject *__pyx_tuple__215; static PyObject *__pyx_tuple__216; -static PyObject *__pyx_tuple__217; -static PyObject *__pyx_tuple__218; static PyObject *__pyx_tuple__219; static PyObject *__pyx_tuple__220; -static PyObject *__pyx_tuple__221; +static PyObject *__pyx_tuple__222; +static PyObject *__pyx_tuple__223; +static PyObject *__pyx_tuple__224; +static PyObject *__pyx_tuple__225; +static PyObject *__pyx_tuple__226; +static PyObject *__pyx_tuple__227; +static PyObject *__pyx_tuple__228; +static PyObject *__pyx_tuple__229; +static PyObject *__pyx_tuple__230; +static PyObject *__pyx_tuple__231; +static PyObject *__pyx_tuple__232; +static PyObject *__pyx_tuple__233; static PyObject *__pyx_tuple__234; static PyObject *__pyx_tuple__235; static PyObject *__pyx_tuple__236; static PyObject *__pyx_tuple__237; static PyObject *__pyx_tuple__238; static PyObject *__pyx_tuple__239; -static PyObject *__pyx_tuple__240; -static PyObject *__pyx_tuple__241; -static PyObject *__pyx_tuple__242; -static PyObject *__pyx_tuple__243; -static PyObject *__pyx_tuple__244; -static PyObject *__pyx_tuple__245; -static PyObject *__pyx_tuple__246; -static PyObject *__pyx_tuple__247; -static PyObject *__pyx_tuple__248; -static PyObject *__pyx_codeobj__222; -static PyObject *__pyx_codeobj__223; -static PyObject *__pyx_codeobj__224; -static PyObject *__pyx_codeobj__225; -static PyObject *__pyx_codeobj__226; -static PyObject *__pyx_codeobj__227; -static PyObject *__pyx_codeobj__228; -static PyObject *__pyx_codeobj__229; -static PyObject *__pyx_codeobj__230; -static PyObject *__pyx_codeobj__231; -static PyObject *__pyx_codeobj__232; -static PyObject *__pyx_codeobj__233; +static PyObject *__pyx_tuple__252; +static PyObject *__pyx_tuple__253; +static PyObject *__pyx_tuple__254; +static PyObject *__pyx_tuple__255; +static PyObject *__pyx_tuple__256; +static PyObject *__pyx_tuple__257; +static PyObject *__pyx_tuple__258; +static PyObject *__pyx_tuple__259; +static PyObject *__pyx_tuple__260; +static PyObject *__pyx_tuple__261; +static PyObject *__pyx_tuple__262; +static PyObject *__pyx_tuple__263; +static PyObject *__pyx_tuple__264; +static PyObject *__pyx_tuple__265; +static PyObject *__pyx_tuple__266; +static PyObject *__pyx_codeobj__240; +static PyObject *__pyx_codeobj__241; +static PyObject *__pyx_codeobj__242; +static PyObject *__pyx_codeobj__243; +static PyObject *__pyx_codeobj__244; +static PyObject *__pyx_codeobj__245; +static PyObject *__pyx_codeobj__246; +static PyObject *__pyx_codeobj__247; +static PyObject *__pyx_codeobj__248; +static PyObject *__pyx_codeobj__249; +static PyObject *__pyx_codeobj__250; +static PyObject *__pyx_codeobj__251; /* Late includes */ -/* "pysam/libcbcf.pyx":139 +/* "pysam/libcbcf.pyx":143 * cdef dict bcf_str_cache = {} * * cdef inline bcf_str_cache_get_charptr(const char* s): # <<<<<<<<<<<<<< @@ -4544,9 +4643,9 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr PyObject *__pyx_t_2 = NULL; int __pyx_t_3; __Pyx_RefNannySetupContext("bcf_str_cache_get_charptr", 0); - __Pyx_TraceCall("bcf_str_cache_get_charptr", __pyx_f[0], 139, 0, __PYX_ERR(0, 139, __pyx_L1_error)); + __Pyx_TraceCall("bcf_str_cache_get_charptr", __pyx_f[0], 143, 0, __PYX_ERR(0, 143, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":140 + /* "pysam/libcbcf.pyx":144 * * cdef inline bcf_str_cache_get_charptr(const char* s): * if s == NULL: # <<<<<<<<<<<<<< @@ -4556,7 +4655,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr __pyx_t_1 = ((__pyx_v_s == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":141 + /* "pysam/libcbcf.pyx":145 * cdef inline bcf_str_cache_get_charptr(const char* s): * if s == NULL: * return None # <<<<<<<<<<<<<< @@ -4567,7 +4666,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":140 + /* "pysam/libcbcf.pyx":144 * * cdef inline bcf_str_cache_get_charptr(const char* s): * if s == NULL: # <<<<<<<<<<<<<< @@ -4576,7 +4675,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr */ } - /* "pysam/libcbcf.pyx":143 + /* "pysam/libcbcf.pyx":147 * return None * * cdef PyObject *pystr = PyDict_GetItemString(bcf_str_cache, s) # <<<<<<<<<<<<<< @@ -4588,7 +4687,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr __pyx_v_pystr = PyDict_GetItemString(__pyx_t_2, __pyx_v_s); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":144 + /* "pysam/libcbcf.pyx":148 * * cdef PyObject *pystr = PyDict_GetItemString(bcf_str_cache, s) * if pystr: # <<<<<<<<<<<<<< @@ -4598,7 +4697,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr __pyx_t_1 = (__pyx_v_pystr != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":145 + /* "pysam/libcbcf.pyx":149 * cdef PyObject *pystr = PyDict_GetItemString(bcf_str_cache, s) * if pystr: * return pystr # <<<<<<<<<<<<<< @@ -4610,7 +4709,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr __pyx_r = ((PyObject *)__pyx_v_pystr); goto __pyx_L0; - /* "pysam/libcbcf.pyx":144 + /* "pysam/libcbcf.pyx":148 * * cdef PyObject *pystr = PyDict_GetItemString(bcf_str_cache, s) * if pystr: # <<<<<<<<<<<<<< @@ -4619,7 +4718,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr */ } - /* "pysam/libcbcf.pyx":147 + /* "pysam/libcbcf.pyx":151 * return pystr * * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< @@ -4629,19 +4728,19 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr __pyx_t_1 = ((PY_MAJOR_VERSION < 3) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":148 + /* "pysam/libcbcf.pyx":152 * * if PY_MAJOR_VERSION < 3: * val = s # <<<<<<<<<<<<<< * else: * val = PyUnicode_DecodeASCII(s, strlen(s), NULL) */ - __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_val = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":147 + /* "pysam/libcbcf.pyx":151 * return pystr * * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< @@ -4651,7 +4750,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr goto __pyx_L5; } - /* "pysam/libcbcf.pyx":150 + /* "pysam/libcbcf.pyx":154 * val = s * else: * val = PyUnicode_DecodeASCII(s, strlen(s), NULL) # <<<<<<<<<<<<<< @@ -4659,14 +4758,14 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr * PyDict_SetItemString(bcf_str_cache, s, val) */ /*else*/ { - __pyx_t_2 = PyUnicode_DecodeASCII(__pyx_v_s, strlen(__pyx_v_s), NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 150, __pyx_L1_error) + __pyx_t_2 = PyUnicode_DecodeASCII(__pyx_v_s, strlen(__pyx_v_s), NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_val = __pyx_t_2; __pyx_t_2 = 0; } __pyx_L5:; - /* "pysam/libcbcf.pyx":152 + /* "pysam/libcbcf.pyx":156 * val = PyUnicode_DecodeASCII(s, strlen(s), NULL) * * PyDict_SetItemString(bcf_str_cache, s, val) # <<<<<<<<<<<<<< @@ -4675,10 +4774,10 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr */ __pyx_t_2 = __pyx_v_5pysam_7libcbcf_bcf_str_cache; __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = PyDict_SetItemString(__pyx_t_2, __pyx_v_s, __pyx_v_val); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 152, __pyx_L1_error) + __pyx_t_3 = PyDict_SetItemString(__pyx_t_2, __pyx_v_s, __pyx_v_val); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":154 + /* "pysam/libcbcf.pyx":158 * PyDict_SetItemString(bcf_str_cache, s, val) * * return val # <<<<<<<<<<<<<< @@ -4690,7 +4789,7 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr __pyx_r = __pyx_v_val; goto __pyx_L0; - /* "pysam/libcbcf.pyx":139 + /* "pysam/libcbcf.pyx":143 * cdef dict bcf_str_cache = {} * * cdef inline bcf_str_cache_get_charptr(const char* s): # <<<<<<<<<<<<<< @@ -4711,7 +4810,320 @@ static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr return __pyx_r; } -/* "pysam/libcbcf.pyx":163 +/* "pysam/libcbcf.pyx":166 + * ######################################################################## + * + * cdef int comb(int n, int k) except -1: # <<<<<<<<<<<<<< + * """Return binomial coeffient: n choose k + * + */ + +static int __pyx_f_5pysam_7libcbcf_comb(int __pyx_v_n, int __pyx_v_k) { + PyObject *__pyx_v_d = 0; + PyObject *__pyx_v_result = 0; + PyObject *__pyx_v_i = NULL; + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + int __pyx_t_6; + __Pyx_RefNannySetupContext("comb", 0); + __Pyx_TraceCall("comb", __pyx_f[0], 166, 0, __PYX_ERR(0, 166, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":178 + * 4950 + * """ + * if k > n: # <<<<<<<<<<<<<< + * return 0 + * elif k == n: + */ + __pyx_t_1 = ((__pyx_v_k > __pyx_v_n) != 0); + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":179 + * """ + * if k > n: + * return 0 # <<<<<<<<<<<<<< + * elif k == n: + * return 1 + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":178 + * 4950 + * """ + * if k > n: # <<<<<<<<<<<<<< + * return 0 + * elif k == n: + */ + } + + /* "pysam/libcbcf.pyx":180 + * if k > n: + * return 0 + * elif k == n: # <<<<<<<<<<<<<< + * return 1 + * elif k > n // 2: + */ + __pyx_t_1 = ((__pyx_v_k == __pyx_v_n) != 0); + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":181 + * return 0 + * elif k == n: + * return 1 # <<<<<<<<<<<<<< + * elif k > n // 2: + * k = n - k + */ + __pyx_r = 1; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":180 + * if k > n: + * return 0 + * elif k == n: # <<<<<<<<<<<<<< + * return 1 + * elif k > n // 2: + */ + } + + /* "pysam/libcbcf.pyx":182 + * elif k == n: + * return 1 + * elif k > n // 2: # <<<<<<<<<<<<<< + * k = n - k + * + */ + __pyx_t_1 = ((__pyx_v_k > __Pyx_div_long(__pyx_v_n, 2)) != 0); + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":183 + * return 1 + * elif k > n // 2: + * k = n - k # <<<<<<<<<<<<<< + * + * cdef d, result + */ + __pyx_v_k = (__pyx_v_n - __pyx_v_k); + + /* "pysam/libcbcf.pyx":182 + * elif k == n: + * return 1 + * elif k > n // 2: # <<<<<<<<<<<<<< + * k = n - k + * + */ + } + + /* "pysam/libcbcf.pyx":187 + * cdef d, result + * + * d = result = n - k + 1 # <<<<<<<<<<<<<< + * for i in range(2, k + 1): + * d += 1 + */ + __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_n - __pyx_v_k) + 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 187, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v_d = __pyx_t_2; + __Pyx_INCREF(__pyx_t_2); + __pyx_v_result = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libcbcf.pyx":188 + * + * d = result = n - k + 1 + * for i in range(2, k + 1): # <<<<<<<<<<<<<< + * d += 1 + * result *= d + */ + __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_k + 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_int_2); + __Pyx_GIVEREF(__pyx_int_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 188, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_3))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 188, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 188, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_5(__pyx_t_3); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 188, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pysam/libcbcf.pyx":189 + * d = result = n - k + 1 + * for i in range(2, k + 1): + * d += 1 # <<<<<<<<<<<<<< + * result *= d + * result //= i + */ + __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_d, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF_SET(__pyx_v_d, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pysam/libcbcf.pyx":190 + * for i in range(2, k + 1): + * d += 1 + * result *= d # <<<<<<<<<<<<<< + * result //= i + * return result + */ + __pyx_t_2 = PyNumber_InPlaceMultiply(__pyx_v_result, __pyx_v_d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF_SET(__pyx_v_result, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pysam/libcbcf.pyx":191 + * d += 1 + * result *= d + * result //= i # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_result, __pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF_SET(__pyx_v_result, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pysam/libcbcf.pyx":188 + * + * d = result = n - k + 1 + * for i in range(2, k + 1): # <<<<<<<<<<<<<< + * d += 1 + * result *= d + */ + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":192 + * result *= d + * result //= i + * return result # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_result); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 192, __pyx_L1_error) + __pyx_r = __pyx_t_6; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":166 + * ######################################################################## + * + * cdef int comb(int n, int k) except -1: # <<<<<<<<<<<<<< + * """Return binomial coeffient: n choose k + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.comb", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_d); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":195 + * + * + * cdef inline int bcf_geno_combinations(int ploidy, int alleles) except -1: # <<<<<<<<<<<<<< + * """Return the count of genotypes expected for the given ploidy and number of alleles. + * + */ + +static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_bcf_geno_combinations(int __pyx_v_ploidy, int __pyx_v_alleles) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("bcf_geno_combinations", 0); + __Pyx_TraceCall("bcf_geno_combinations", __pyx_f[0], 195, 0, __PYX_ERR(0, 195, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":207 + * 4 + * """ + * return comb(alleles + ploidy - 1, ploidy) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_1 = __pyx_f_5pysam_7libcbcf_comb(((__pyx_v_alleles + __pyx_v_ploidy) - 1), __pyx_v_ploidy); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 207, __pyx_L1_error) + __pyx_r = __pyx_t_1; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":195 + * + * + * cdef inline int bcf_geno_combinations(int ploidy, int alleles) except -1: # <<<<<<<<<<<<<< + * """Return the count of genotypes expected for the given ploidy and number of alleles. + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.bcf_geno_combinations", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":216 * * * cdef inline bint check_header_id(bcf_hdr_t *hdr, int hl_type, int id): # <<<<<<<<<<<<<< @@ -4726,9 +5138,9 @@ static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_check_header_id(bcf_hdr_t *__py int __pyx_t_1; int __pyx_t_2; __Pyx_RefNannySetupContext("check_header_id", 0); - __Pyx_TraceCall("check_header_id", __pyx_f[0], 163, 0, __PYX_ERR(0, 163, __pyx_L1_error)); + __Pyx_TraceCall("check_header_id", __pyx_f[0], 216, 0, __PYX_ERR(0, 216, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":164 + /* "pysam/libcbcf.pyx":217 * * cdef inline bint check_header_id(bcf_hdr_t *hdr, int hl_type, int id): * return id >= 0 and id < hdr.n[BCF_DT_ID] and bcf_hdr_idinfo_exists(hdr, hl_type, id) # <<<<<<<<<<<<<< @@ -4753,7 +5165,7 @@ static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_check_header_id(bcf_hdr_t *__py __pyx_r = __pyx_t_1; goto __pyx_L0; - /* "pysam/libcbcf.pyx":163 + /* "pysam/libcbcf.pyx":216 * * * cdef inline bint check_header_id(bcf_hdr_t *hdr, int hl_type, int id): # <<<<<<<<<<<<<< @@ -4771,11 +5183,11 @@ static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_check_header_id(bcf_hdr_t *__py return __pyx_r; } -/* "pysam/libcbcf.pyx":167 +/* "pysam/libcbcf.pyx":220 * * * cdef inline int is_gt_fmt(bcf_hdr_t *hdr, int fmt_id): # <<<<<<<<<<<<<< - * return strcmp(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt_id), "GT") == 0 + * return strcmp(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt_id), 'GT') == 0 * */ @@ -4784,23 +5196,23 @@ static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_is_gt_fmt(bcf_hdr_t *__pyx_v_hd __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("is_gt_fmt", 0); - __Pyx_TraceCall("is_gt_fmt", __pyx_f[0], 167, 0, __PYX_ERR(0, 167, __pyx_L1_error)); + __Pyx_TraceCall("is_gt_fmt", __pyx_f[0], 220, 0, __PYX_ERR(0, 220, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":168 + /* "pysam/libcbcf.pyx":221 * * cdef inline int is_gt_fmt(bcf_hdr_t *hdr, int fmt_id): - * return strcmp(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt_id), "GT") == 0 # <<<<<<<<<<<<<< + * return strcmp(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt_id), 'GT') == 0 # <<<<<<<<<<<<<< * * */ __pyx_r = (strcmp(bcf_hdr_int2id(__pyx_v_hdr, BCF_DT_ID, __pyx_v_fmt_id), ((char const *)"GT")) == 0); goto __pyx_L0; - /* "pysam/libcbcf.pyx":167 + /* "pysam/libcbcf.pyx":220 * * * cdef inline int is_gt_fmt(bcf_hdr_t *hdr, int fmt_id): # <<<<<<<<<<<<<< - * return strcmp(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt_id), "GT") == 0 + * return strcmp(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt_id), 'GT') == 0 * */ @@ -4813,9 +5225,257 @@ static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_is_gt_fmt(bcf_hdr_t *__pyx_v_hd __Pyx_RefNannyFinishContext(); return __pyx_r; } + +/* "pysam/libcbcf.pyx":224 + * + * + * cdef inline int bcf_genotype_count(bcf_hdr_t *hdr, bcf1_t *rec, int sample) except -1: # <<<<<<<<<<<<<< + * + * if sample < 0: + */ + +static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_bcf_genotype_count(bcf_hdr_t *__pyx_v_hdr, bcf1_t *__pyx_v_rec, int __pyx_v_sample) { + int32_t *__pyx_v_gt_arr; + int __pyx_v_ngt; + int __pyx_v_max_ploidy; + int32_t *__pyx_v_gt; + int __pyx_v_ploidy; + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("bcf_genotype_count", 0); + __Pyx_TraceCall("bcf_genotype_count", __pyx_f[0], 224, 0, __PYX_ERR(0, 224, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":226 + * cdef inline int bcf_genotype_count(bcf_hdr_t *hdr, bcf1_t *rec, int sample) except -1: + * + * if sample < 0: # <<<<<<<<<<<<<< + * raise ValueError('genotype is only valid as a format field') + * + */ + __pyx_t_1 = ((__pyx_v_sample < 0) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbcf.pyx":227 + * + * if sample < 0: + * raise ValueError('genotype is only valid as a format field') # <<<<<<<<<<<<<< + * + * cdef int32_t *gt_arr = NULL + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 227, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 227, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":226 + * cdef inline int bcf_genotype_count(bcf_hdr_t *hdr, bcf1_t *rec, int sample) except -1: + * + * if sample < 0: # <<<<<<<<<<<<<< + * raise ValueError('genotype is only valid as a format field') + * + */ + } + + /* "pysam/libcbcf.pyx":229 + * raise ValueError('genotype is only valid as a format field') + * + * cdef int32_t *gt_arr = NULL # <<<<<<<<<<<<<< + * cdef int ngt = 0 + * ngt = bcf_get_genotypes(hdr, rec, >_arr, &ngt) + */ + __pyx_v_gt_arr = NULL; + + /* "pysam/libcbcf.pyx":230 + * + * cdef int32_t *gt_arr = NULL + * cdef int ngt = 0 # <<<<<<<<<<<<<< + * ngt = bcf_get_genotypes(hdr, rec, >_arr, &ngt) + * + */ + __pyx_v_ngt = 0; + + /* "pysam/libcbcf.pyx":231 + * cdef int32_t *gt_arr = NULL + * cdef int ngt = 0 + * ngt = bcf_get_genotypes(hdr, rec, >_arr, &ngt) # <<<<<<<<<<<<<< + * + * if ngt <= 0 or not gt_arr: + */ + __pyx_v_ngt = bcf_get_genotypes(__pyx_v_hdr, __pyx_v_rec, (&__pyx_v_gt_arr), (&__pyx_v_ngt)); + + /* "pysam/libcbcf.pyx":233 + * ngt = bcf_get_genotypes(hdr, rec, >_arr, &ngt) + * + * if ngt <= 0 or not gt_arr: # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_t_3 = ((__pyx_v_ngt <= 0) != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_3 = ((!(__pyx_v_gt_arr != 0)) != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L5_bool_binop_done:; + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":234 + * + * if ngt <= 0 or not gt_arr: + * return 0 # <<<<<<<<<<<<<< + * + * assert ngt % rec.n_sample == 0 + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":233 + * ngt = bcf_get_genotypes(hdr, rec, >_arr, &ngt) + * + * if ngt <= 0 or not gt_arr: # <<<<<<<<<<<<<< + * return 0 + * + */ + } + + /* "pysam/libcbcf.pyx":236 + * return 0 + * + * assert ngt % rec.n_sample == 0 # <<<<<<<<<<<<<< + * cdef int max_ploidy = ngt // rec.n_sample + * cdef int32_t *gt = gt_arr + sample * max_ploidy + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + if (unlikely(__pyx_v_rec->n_sample == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + __PYX_ERR(0, 236, __pyx_L1_error) + } + if (unlikely(!(((__pyx_v_ngt % __pyx_v_rec->n_sample) == 0) != 0))) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 236, __pyx_L1_error) + } + } + #endif + + /* "pysam/libcbcf.pyx":237 + * + * assert ngt % rec.n_sample == 0 + * cdef int max_ploidy = ngt // rec.n_sample # <<<<<<<<<<<<<< + * cdef int32_t *gt = gt_arr + sample * max_ploidy + * cdef int ploidy = 0 + */ + if (unlikely(__pyx_v_rec->n_sample == 0)) { + PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + __PYX_ERR(0, 237, __pyx_L1_error) + } + __pyx_v_max_ploidy = (__pyx_v_ngt / __pyx_v_rec->n_sample); + + /* "pysam/libcbcf.pyx":238 + * assert ngt % rec.n_sample == 0 + * cdef int max_ploidy = ngt // rec.n_sample + * cdef int32_t *gt = gt_arr + sample * max_ploidy # <<<<<<<<<<<<<< + * cdef int ploidy = 0 + * + */ + __pyx_v_gt = (__pyx_v_gt_arr + (__pyx_v_sample * __pyx_v_max_ploidy)); + + /* "pysam/libcbcf.pyx":239 + * cdef int max_ploidy = ngt // rec.n_sample + * cdef int32_t *gt = gt_arr + sample * max_ploidy + * cdef int ploidy = 0 # <<<<<<<<<<<<<< + * + * while ploidy < max_ploidy and gt[0] != bcf_int32_vector_end: + */ + __pyx_v_ploidy = 0; + + /* "pysam/libcbcf.pyx":241 + * cdef int ploidy = 0 + * + * while ploidy < max_ploidy and gt[0] != bcf_int32_vector_end: # <<<<<<<<<<<<<< + * gt += 1 + * ploidy += 1 + */ + while (1) { + __pyx_t_3 = ((__pyx_v_ploidy < __pyx_v_max_ploidy) != 0); + if (__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L9_bool_binop_done; + } + __pyx_t_3 = (((__pyx_v_gt[0]) != bcf_int32_vector_end) != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L9_bool_binop_done:; + if (!__pyx_t_1) break; + + /* "pysam/libcbcf.pyx":242 + * + * while ploidy < max_ploidy and gt[0] != bcf_int32_vector_end: + * gt += 1 # <<<<<<<<<<<<<< + * ploidy += 1 + * + */ + __pyx_v_gt = (__pyx_v_gt + 1); + + /* "pysam/libcbcf.pyx":243 + * while ploidy < max_ploidy and gt[0] != bcf_int32_vector_end: + * gt += 1 + * ploidy += 1 # <<<<<<<<<<<<<< + * + * free(gt_arr) + */ + __pyx_v_ploidy = (__pyx_v_ploidy + 1); + } + + /* "pysam/libcbcf.pyx":245 + * ploidy += 1 + * + * free(gt_arr) # <<<<<<<<<<<<<< + * + * return bcf_geno_combinations(ploidy, rec.n_allele) + */ + free(((void *)__pyx_v_gt_arr)); + + /* "pysam/libcbcf.pyx":247 + * free(gt_arr) + * + * return bcf_geno_combinations(ploidy, rec.n_allele) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_4 = __pyx_f_5pysam_7libcbcf_bcf_geno_combinations(__pyx_v_ploidy, __pyx_v_rec->n_allele); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 247, __pyx_L1_error) + __pyx_r = __pyx_t_4; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":224 + * + * + * cdef inline int bcf_genotype_count(bcf_hdr_t *hdr, bcf1_t *rec, int sample) except -1: # <<<<<<<<<<<<<< + * + * if sample < 0: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcbcf.bcf_genotype_count", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} static PyObject *__pyx_gb_5pysam_7libcbcf_19char_array_to_tuple_2generator28(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":175 +/* "pysam/libcbcf.pyx":254 * return None * try: * return tuple(charptr_to_str(a[i]) for i in range(n)) # <<<<<<<<<<<<<< @@ -4832,7 +5492,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19char_array_to_tuple_genexpr(PyObject if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 175, __pyx_L1_error) + __PYX_ERR(0, 254, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -4840,7 +5500,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19char_array_to_tuple_genexpr(PyObject __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19char_array_to_tuple_2generator28, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_char_array_to_tuple_locals_genex, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 175, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19char_array_to_tuple_2generator28, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_char_array_to_tuple_locals_genex, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 254, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -4867,7 +5527,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19char_array_to_tuple_2generator28(__p PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("genexpr", 0); - __Pyx_TraceCall("genexpr", __pyx_f[0], 175, 0, __PYX_ERR(0, 175, __pyx_L1_error)); + __Pyx_TraceCall("genexpr", __pyx_f[0], 254, 0, __PYX_ERR(0, 254, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -4877,12 +5537,12 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19char_array_to_tuple_2generator28(__p return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 175, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 254, __pyx_L1_error) __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_n; __pyx_t_2 = __pyx_t_1; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_3; - __pyx_t_4 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_outer_scope->__pyx_v_a[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 175, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_outer_scope->__pyx_v_a[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 254, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; @@ -4900,7 +5560,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19char_array_to_tuple_2generator28(__p __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 175, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 254, __pyx_L1_error) } CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); @@ -4920,7 +5580,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19char_array_to_tuple_2generator28(__p return __pyx_r; } -/* "pysam/libcbcf.pyx":171 +/* "pysam/libcbcf.pyx":250 * * * cdef tuple char_array_to_tuple(const char **a, ssize_t n, int free_after=0): # <<<<<<<<<<<<<< @@ -4953,11 +5613,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysam_7libcbcf_char_array_to_tuple *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 171, __pyx_L1_error) + __PYX_ERR(0, 250, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } - __Pyx_TraceCall("char_array_to_tuple", __pyx_f[0], 171, 0, __PYX_ERR(0, 171, __pyx_L1_error)); + __Pyx_TraceCall("char_array_to_tuple", __pyx_f[0], 250, 0, __PYX_ERR(0, 250, __pyx_L1_error)); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_free_after = __pyx_optional_args->free_after; @@ -4966,7 +5626,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ __pyx_cur_scope->__pyx_v_a = __pyx_v_a; __pyx_cur_scope->__pyx_v_n = __pyx_v_n; - /* "pysam/libcbcf.pyx":172 + /* "pysam/libcbcf.pyx":251 * * cdef tuple char_array_to_tuple(const char **a, ssize_t n, int free_after=0): * if not a: # <<<<<<<<<<<<<< @@ -4976,7 +5636,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ __pyx_t_1 = ((!(__pyx_cur_scope->__pyx_v_a != 0)) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":173 + /* "pysam/libcbcf.pyx":252 * cdef tuple char_array_to_tuple(const char **a, ssize_t n, int free_after=0): * if not a: * return None # <<<<<<<<<<<<<< @@ -4987,7 +5647,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":172 + /* "pysam/libcbcf.pyx":251 * * cdef tuple char_array_to_tuple(const char **a, ssize_t n, int free_after=0): * if not a: # <<<<<<<<<<<<<< @@ -4996,7 +5656,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ */ } - /* "pysam/libcbcf.pyx":174 + /* "pysam/libcbcf.pyx":253 * if not a: * return None * try: # <<<<<<<<<<<<<< @@ -5005,7 +5665,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ */ /*try:*/ { - /* "pysam/libcbcf.pyx":175 + /* "pysam/libcbcf.pyx":254 * return None * try: * return tuple(charptr_to_str(a[i]) for i in range(n)) # <<<<<<<<<<<<<< @@ -5013,9 +5673,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ * if free_after and a: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_pf_5pysam_7libcbcf_19char_array_to_tuple_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 175, __pyx_L5_error) + __pyx_t_2 = __pyx_pf_5pysam_7libcbcf_19char_array_to_tuple_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 254, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 175, __pyx_L5_error) + __pyx_t_3 = __Pyx_PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 254, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = ((PyObject*)__pyx_t_3); @@ -5023,7 +5683,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ goto __pyx_L4_return; } - /* "pysam/libcbcf.pyx":177 + /* "pysam/libcbcf.pyx":256 * return tuple(charptr_to_str(a[i]) for i in range(n)) * finally: * if free_after and a: # <<<<<<<<<<<<<< @@ -5059,7 +5719,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ __pyx_L10_bool_binop_done:; if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":178 + /* "pysam/libcbcf.pyx":257 * finally: * if free_after and a: * free(a) # <<<<<<<<<<<<<< @@ -5068,7 +5728,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ */ free(__pyx_cur_scope->__pyx_v_a); - /* "pysam/libcbcf.pyx":177 + /* "pysam/libcbcf.pyx":256 * return tuple(charptr_to_str(a[i]) for i in range(n)) * finally: * if free_after and a: # <<<<<<<<<<<<<< @@ -5105,7 +5765,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ __pyx_L13_bool_binop_done:; if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":178 + /* "pysam/libcbcf.pyx":257 * finally: * if free_after and a: * free(a) # <<<<<<<<<<<<<< @@ -5114,7 +5774,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ */ free(__pyx_cur_scope->__pyx_v_a); - /* "pysam/libcbcf.pyx":177 + /* "pysam/libcbcf.pyx":256 * return tuple(charptr_to_str(a[i]) for i in range(n)) * finally: * if free_after and a: # <<<<<<<<<<<<<< @@ -5128,7 +5788,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ } } - /* "pysam/libcbcf.pyx":171 + /* "pysam/libcbcf.pyx":250 * * * cdef tuple char_array_to_tuple(const char **a, ssize_t n, int free_after=0): # <<<<<<<<<<<<<< @@ -5151,12 +5811,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_char_array_to_tuple(char const **__pyx_ } static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_array_to_object_2generator29(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":199 - * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. - * - * value = tuple(v or None for v in value.split(',')) if value else () # <<<<<<<<<<<<<< - * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. +/* "pysam/libcbcf.pyx":285 + * # Otherwise, copy the entire block + * b = datac[:n] + * value = tuple(v.decode('ascii') if v and v != bcf_str_missing else None for v in b.split(b',')) # <<<<<<<<<<<<<< * else: + * value = [] */ static PyObject *__pyx_pf_5pysam_7libcbcf_19bcf_array_to_object_genexpr(PyObject *__pyx_self) { @@ -5168,7 +5828,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19bcf_array_to_object_genexpr(PyObject if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_3_genexpr *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 199, __pyx_L1_error) + __PYX_ERR(0, 285, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -5176,7 +5836,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19bcf_array_to_object_genexpr(PyObject __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19bcf_array_to_object_2generator29, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_bcf_array_to_object_locals_genex, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 199, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19bcf_array_to_object_2generator29, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_bcf_array_to_object_locals_genex, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 285, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -5202,9 +5862,12 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_array_to_object_2generator29(__p Py_ssize_t __pyx_t_3; PyObject *(*__pyx_t_4)(PyObject *); int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("genexpr", 0); - __Pyx_TraceCall("genexpr", __pyx_f[0], 199, 0, __PYX_ERR(0, 199, __pyx_L1_error)); + __Pyx_TraceCall("genexpr", __pyx_f[0], 285, 0, __PYX_ERR(0, 285, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L8_resume_from_yield; @@ -5214,71 +5877,84 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_array_to_object_2generator29(__p return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 199, __pyx_L1_error) - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_value)) { __Pyx_RaiseClosureNameError("value"); __PYX_ERR(0, 199, __pyx_L1_error) } - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_value, __pyx_n_s_split); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 199, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 285, __pyx_L1_error) + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_b)) { __Pyx_RaiseClosureNameError("b"); __PYX_ERR(0, 285, __pyx_L1_error) } + __pyx_t_1 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyBytes_Type_split, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_b, __pyx_kp_b__2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 285, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 199, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; __pyx_t_4 = NULL; } else { - __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 199, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 199, __pyx_L1_error) + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 285, __pyx_L1_error) } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; for (;;) { if (likely(!__pyx_t_4)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 199, __pyx_L1_error) + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 285, __pyx_L1_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 199, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); #endif } else { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 199, __pyx_L1_error) + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 285, __pyx_L1_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 199, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); #endif } } else { - __pyx_t_2 = __pyx_t_4(__pyx_t_1); - if (unlikely(!__pyx_t_2)) { + __pyx_t_1 = __pyx_t_4(__pyx_t_2); + if (unlikely(!__pyx_t_1)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 199, __pyx_L1_error) + else __PYX_ERR(0, 285, __pyx_L1_error) } break; } - __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); } __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_v); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_v, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_v); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 199, __pyx_L1_error) - if (!__pyx_t_5) { + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_v, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_v); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 285, __pyx_L1_error) + if (__pyx_t_6) { } else { - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_v); - __pyx_t_2 = __pyx_cur_scope->__pyx_v_v; + __pyx_t_5 = __pyx_t_6; goto __pyx_L6_bool_binop_done; } - __Pyx_INCREF(Py_None); - __pyx_t_2 = Py_None; + __pyx_t_7 = __Pyx_PyInt_From_int32_t(bcf_str_missing); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_v, __pyx_t_7, Py_NE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_5 = __pyx_t_6; __pyx_L6_bool_binop_done:; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + if (__pyx_t_5) { + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_v, __pyx_n_s_decode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_1 = __pyx_t_7; + __pyx_t_7 = 0; + } else { + __Pyx_INCREF(Py_None); + __pyx_t_1 = Py_None; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; __Pyx_XGIVEREF(__pyx_r); @@ -5289,14 +5965,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_array_to_object_2generator29(__p __pyx_generator->resume_label = 1; return __pyx_r; __pyx_L8_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 199, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 285, __pyx_L1_error) } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); /* function exit code */ @@ -5305,6 +5981,8 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_array_to_object_2generator29(__p __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_r = 0; @@ -5316,7 +5994,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_array_to_object_2generator29(__p return __pyx_r; } -/* "pysam/libcbcf.pyx":181 +/* "pysam/libcbcf.pyx":260 * * * cdef bcf_array_to_object(void *data, int type, ssize_t n, ssize_t count, int scalar): # <<<<<<<<<<<<<< @@ -5332,6 +6010,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, int32_t *__pyx_v_data32; float *__pyx_v_dataf; int __pyx_v_i; + PyObject *__pyx_v_value = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -5339,25 +6018,24 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_5; Py_ssize_t __pyx_t_6; - Py_ssize_t __pyx_t_7; + int __pyx_t_7; int __pyx_t_8; - int __pyx_t_9; - Py_ssize_t __pyx_t_10; + Py_ssize_t __pyx_t_9; __Pyx_RefNannySetupContext("bcf_array_to_object", 0); __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 181, __pyx_L1_error) + __PYX_ERR(0, 260, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } - __Pyx_TraceCall("bcf_array_to_object", __pyx_f[0], 181, 0, __PYX_ERR(0, 181, __pyx_L1_error)); + __Pyx_TraceCall("bcf_array_to_object", __pyx_f[0], 260, 0, __PYX_ERR(0, 260, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":189 - * cdef int i + /* "pysam/libcbcf.pyx":269 + * cdef bytes b * * if not data or n <= 0: # <<<<<<<<<<<<<< * return None @@ -5374,7 +6052,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_L4_bool_binop_done:; if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":190 + /* "pysam/libcbcf.pyx":270 * * if not data or n <= 0: * return None # <<<<<<<<<<<<<< @@ -5385,8 +6063,8 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":189 - * cdef int i + /* "pysam/libcbcf.pyx":269 + * cdef bytes b * * if not data or n <= 0: # <<<<<<<<<<<<<< * return None @@ -5394,124 +6072,146 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, */ } - /* "pysam/libcbcf.pyx":192 + /* "pysam/libcbcf.pyx":272 * return None * * if type == BCF_BT_CHAR: # <<<<<<<<<<<<<< * datac = data - * while n and datac[n-1] == bcf_str_vector_end: + * */ __pyx_t_1 = ((__pyx_v_type == BCF_BT_CHAR) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":193 + /* "pysam/libcbcf.pyx":273 * * if type == BCF_BT_CHAR: * datac = data # <<<<<<<<<<<<<< - * while n and datac[n-1] == bcf_str_vector_end: - * n -= 1 + * + * if not n: */ __pyx_v_datac = ((char *)__pyx_v_data); - /* "pysam/libcbcf.pyx":194 - * if type == BCF_BT_CHAR: + /* "pysam/libcbcf.pyx":275 * datac = data - * while n and datac[n-1] == bcf_str_vector_end: # <<<<<<<<<<<<<< - * n -= 1 - * value = charptr_to_str_w_len(datac, n) if datac[0] != bcf_str_missing else None + * + * if not n: # <<<<<<<<<<<<<< + * value = () + * else: */ - while (1) { - __pyx_t_2 = (__pyx_v_n != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_2 = (((__pyx_v_datac[(__pyx_v_n - 1)]) == bcf_str_vector_end) != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L9_bool_binop_done:; - if (!__pyx_t_1) break; + __pyx_t_1 = ((!(__pyx_v_n != 0)) != 0); + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":195 - * datac = data - * while n and datac[n-1] == bcf_str_vector_end: - * n -= 1 # <<<<<<<<<<<<<< - * value = charptr_to_str_w_len(datac, n) if datac[0] != bcf_str_missing else None - * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. + /* "pysam/libcbcf.pyx":276 + * + * if not n: + * value = () # <<<<<<<<<<<<<< + * else: + * # Check if at least one null terminator is present */ - __pyx_v_n = (__pyx_v_n - 1); - } + __Pyx_INCREF(__pyx_empty_tuple); + __pyx_v_value = __pyx_empty_tuple; - /* "pysam/libcbcf.pyx":196 - * while n and datac[n-1] == bcf_str_vector_end: - * n -= 1 - * value = charptr_to_str_w_len(datac, n) if datac[0] != bcf_str_missing else None # <<<<<<<<<<<<<< - * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. + /* "pysam/libcbcf.pyx":275 + * datac = data * + * if not n: # <<<<<<<<<<<<<< + * value = () + * else: */ - if ((((__pyx_v_datac[0]) != bcf_str_missing) != 0)) { - __pyx_t_4 = __pyx_f_5pysam_9libcutils_charptr_to_str_w_len(__pyx_v_datac, __pyx_v_n, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 196, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __pyx_t_4; - __pyx_t_4 = 0; - } else { - __Pyx_INCREF(Py_None); - __pyx_t_3 = Py_None; + goto __pyx_L7; } - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_value = __pyx_t_3; - __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":199 - * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. - * - * value = tuple(v or None for v in value.split(',')) if value else () # <<<<<<<<<<<<<< - * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. + /* "pysam/libcbcf.pyx":279 + * else: + * # Check if at least one null terminator is present + * if datac[n-1] == bcf_str_vector_end: # <<<<<<<<<<<<<< + * # If so, create a string up to the first null terminator + * b = datac + */ + /*else*/ { + __pyx_t_1 = (((__pyx_v_datac[(__pyx_v_n - 1)]) == bcf_str_vector_end) != 0); + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":281 + * if datac[n-1] == bcf_str_vector_end: + * # If so, create a string up to the first null terminator + * b = datac # <<<<<<<<<<<<<< + * else: + * # Otherwise, copy the entire block + */ + __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_datac); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 281, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_b = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":279 + * else: + * # Check if at least one null terminator is present + * if datac[n-1] == bcf_str_vector_end: # <<<<<<<<<<<<<< + * # If so, create a string up to the first null terminator + * b = datac + */ + goto __pyx_L8; + } + + /* "pysam/libcbcf.pyx":284 + * else: + * # Otherwise, copy the entire block + * b = datac[:n] # <<<<<<<<<<<<<< + * value = tuple(v.decode('ascii') if v and v != bcf_str_missing else None for v in b.split(b',')) * else: */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_value); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 199, __pyx_L1_error) - if (__pyx_t_1) { - __pyx_t_4 = __pyx_pf_5pysam_7libcbcf_19bcf_array_to_object_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 199, __pyx_L1_error) + /*else*/ { + __pyx_t_3 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_datac + 0, __pyx_v_n - 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_b = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + } + __pyx_L8:; + + /* "pysam/libcbcf.pyx":285 + * # Otherwise, copy the entire block + * b = datac[:n] + * value = tuple(v.decode('ascii') if v and v != bcf_str_missing else None for v in b.split(b',')) # <<<<<<<<<<<<<< + * else: + * value = [] + */ + __pyx_t_3 = __pyx_pf_5pysam_7libcbcf_19bcf_array_to_object_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 285, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PySequence_Tuple(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 199, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __pyx_t_5; - __pyx_t_5 = 0; - } else { - __Pyx_INCREF(__pyx_empty_tuple); - __pyx_t_3 = __pyx_empty_tuple; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_value = __pyx_t_4; + __pyx_t_4 = 0; } - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_value); - __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_value, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; + __pyx_L7:; - /* "pysam/libcbcf.pyx":192 + /* "pysam/libcbcf.pyx":272 * return None * * if type == BCF_BT_CHAR: # <<<<<<<<<<<<<< * datac = data - * while n and datac[n-1] == bcf_str_vector_end: + * */ goto __pyx_L6; } - /* "pysam/libcbcf.pyx":202 - * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. + /* "pysam/libcbcf.pyx":287 + * value = tuple(v.decode('ascii') if v and v != bcf_str_missing else None for v in b.split(b',')) * else: * value = [] # <<<<<<<<<<<<<< * if type == BCF_BT_INT8: * data8 = data */ /*else*/ { - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_value = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_value = __pyx_t_4; + __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":203 + /* "pysam/libcbcf.pyx":288 * else: * value = [] * if type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -5521,7 +6221,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_t_1 = ((__pyx_v_type == BCF_BT_INT8) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":204 + /* "pysam/libcbcf.pyx":289 * value = [] * if type == BCF_BT_INT8: * data8 = data # <<<<<<<<<<<<<< @@ -5530,19 +6230,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, */ __pyx_v_data8 = ((int8_t *)__pyx_v_data); - /* "pysam/libcbcf.pyx":205 + /* "pysam/libcbcf.pyx":290 * if type == BCF_BT_INT8: * data8 = data * for i in range(n): # <<<<<<<<<<<<<< * if data8[i] == bcf_int8_vector_end: * break */ - __pyx_t_6 = __pyx_v_n; - __pyx_t_7 = __pyx_t_6; - for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { - __pyx_v_i = __pyx_t_8; + __pyx_t_5 = __pyx_v_n; + __pyx_t_6 = __pyx_t_5; + for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { + __pyx_v_i = __pyx_t_7; - /* "pysam/libcbcf.pyx":206 + /* "pysam/libcbcf.pyx":291 * data8 = data * for i in range(n): * if data8[i] == bcf_int8_vector_end: # <<<<<<<<<<<<<< @@ -5552,16 +6252,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_t_1 = (((__pyx_v_data8[__pyx_v_i]) == bcf_int8_vector_end) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":207 + /* "pysam/libcbcf.pyx":292 * for i in range(n): * if data8[i] == bcf_int8_vector_end: * break # <<<<<<<<<<<<<< * value.append(data8[i] if data8[i] != bcf_int8_missing else None) * elif type == BCF_BT_INT16: */ - goto __pyx_L13_break; + goto __pyx_L11_break; - /* "pysam/libcbcf.pyx":206 + /* "pysam/libcbcf.pyx":291 * data8 = data * for i in range(n): * if data8[i] == bcf_int8_vector_end: # <<<<<<<<<<<<<< @@ -5570,7 +6270,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, */ } - /* "pysam/libcbcf.pyx":208 + /* "pysam/libcbcf.pyx":293 * if data8[i] == bcf_int8_vector_end: * break * value.append(data8[i] if data8[i] != bcf_int8_missing else None) # <<<<<<<<<<<<<< @@ -5578,30 +6278,30 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, * data16 = data */ if ((((__pyx_v_data8[__pyx_v_i]) != bcf_int8_missing) != 0)) { - __pyx_t_5 = __Pyx_PyInt_From_int8_t((__pyx_v_data8[__pyx_v_i])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 208, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __pyx_t_5; - __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyInt_From_int8_t((__pyx_v_data8[__pyx_v_i])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_t_3; + __pyx_t_3 = 0; } else { __Pyx_INCREF(Py_None); - __pyx_t_3 = Py_None; + __pyx_t_4 = Py_None; } - __pyx_t_9 = __Pyx_PyObject_Append(__pyx_cur_scope->__pyx_v_value, __pyx_t_3); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 208, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = __Pyx_PyObject_Append(__pyx_v_value, __pyx_t_4); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 293, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - __pyx_L13_break:; + __pyx_L11_break:; - /* "pysam/libcbcf.pyx":203 + /* "pysam/libcbcf.pyx":288 * else: * value = [] * if type == BCF_BT_INT8: # <<<<<<<<<<<<<< * data8 = data * for i in range(n): */ - goto __pyx_L11; + goto __pyx_L9; } - /* "pysam/libcbcf.pyx":209 + /* "pysam/libcbcf.pyx":294 * break * value.append(data8[i] if data8[i] != bcf_int8_missing else None) * elif type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -5611,7 +6311,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_t_1 = ((__pyx_v_type == BCF_BT_INT16) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":210 + /* "pysam/libcbcf.pyx":295 * value.append(data8[i] if data8[i] != bcf_int8_missing else None) * elif type == BCF_BT_INT16: * data16 = data # <<<<<<<<<<<<<< @@ -5620,19 +6320,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, */ __pyx_v_data16 = ((int16_t *)__pyx_v_data); - /* "pysam/libcbcf.pyx":211 + /* "pysam/libcbcf.pyx":296 * elif type == BCF_BT_INT16: * data16 = data * for i in range(n): # <<<<<<<<<<<<<< * if data16[i] == bcf_int16_vector_end: * break */ - __pyx_t_6 = __pyx_v_n; - __pyx_t_7 = __pyx_t_6; - for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { - __pyx_v_i = __pyx_t_8; + __pyx_t_5 = __pyx_v_n; + __pyx_t_6 = __pyx_t_5; + for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { + __pyx_v_i = __pyx_t_7; - /* "pysam/libcbcf.pyx":212 + /* "pysam/libcbcf.pyx":297 * data16 = data * for i in range(n): * if data16[i] == bcf_int16_vector_end: # <<<<<<<<<<<<<< @@ -5642,16 +6342,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_t_1 = (((__pyx_v_data16[__pyx_v_i]) == bcf_int16_vector_end) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":213 + /* "pysam/libcbcf.pyx":298 * for i in range(n): * if data16[i] == bcf_int16_vector_end: * break # <<<<<<<<<<<<<< * value.append(data16[i] if data16[i] != bcf_int16_missing else None) * elif type == BCF_BT_INT32: */ - goto __pyx_L16_break; + goto __pyx_L14_break; - /* "pysam/libcbcf.pyx":212 + /* "pysam/libcbcf.pyx":297 * data16 = data * for i in range(n): * if data16[i] == bcf_int16_vector_end: # <<<<<<<<<<<<<< @@ -5660,7 +6360,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, */ } - /* "pysam/libcbcf.pyx":214 + /* "pysam/libcbcf.pyx":299 * if data16[i] == bcf_int16_vector_end: * break * value.append(data16[i] if data16[i] != bcf_int16_missing else None) # <<<<<<<<<<<<<< @@ -5668,30 +6368,30 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, * data32 = data */ if ((((__pyx_v_data16[__pyx_v_i]) != bcf_int16_missing) != 0)) { - __pyx_t_5 = __Pyx_PyInt_From_int16_t((__pyx_v_data16[__pyx_v_i])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __pyx_t_5; - __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyInt_From_int16_t((__pyx_v_data16[__pyx_v_i])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 299, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_t_3; + __pyx_t_3 = 0; } else { __Pyx_INCREF(Py_None); - __pyx_t_3 = Py_None; + __pyx_t_4 = Py_None; } - __pyx_t_9 = __Pyx_PyObject_Append(__pyx_cur_scope->__pyx_v_value, __pyx_t_3); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = __Pyx_PyObject_Append(__pyx_v_value, __pyx_t_4); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 299, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - __pyx_L16_break:; + __pyx_L14_break:; - /* "pysam/libcbcf.pyx":209 + /* "pysam/libcbcf.pyx":294 * break * value.append(data8[i] if data8[i] != bcf_int8_missing else None) * elif type == BCF_BT_INT16: # <<<<<<<<<<<<<< * data16 = data * for i in range(n): */ - goto __pyx_L11; + goto __pyx_L9; } - /* "pysam/libcbcf.pyx":215 + /* "pysam/libcbcf.pyx":300 * break * value.append(data16[i] if data16[i] != bcf_int16_missing else None) * elif type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -5701,7 +6401,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_t_1 = ((__pyx_v_type == BCF_BT_INT32) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":216 + /* "pysam/libcbcf.pyx":301 * value.append(data16[i] if data16[i] != bcf_int16_missing else None) * elif type == BCF_BT_INT32: * data32 = data # <<<<<<<<<<<<<< @@ -5710,19 +6410,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, */ __pyx_v_data32 = ((int32_t *)__pyx_v_data); - /* "pysam/libcbcf.pyx":217 + /* "pysam/libcbcf.pyx":302 * elif type == BCF_BT_INT32: * data32 = data * for i in range(n): # <<<<<<<<<<<<<< * if data32[i] == bcf_int32_vector_end: * break */ - __pyx_t_6 = __pyx_v_n; - __pyx_t_7 = __pyx_t_6; - for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { - __pyx_v_i = __pyx_t_8; + __pyx_t_5 = __pyx_v_n; + __pyx_t_6 = __pyx_t_5; + for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { + __pyx_v_i = __pyx_t_7; - /* "pysam/libcbcf.pyx":218 + /* "pysam/libcbcf.pyx":303 * data32 = data * for i in range(n): * if data32[i] == bcf_int32_vector_end: # <<<<<<<<<<<<<< @@ -5732,16 +6432,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_t_1 = (((__pyx_v_data32[__pyx_v_i]) == bcf_int32_vector_end) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":219 + /* "pysam/libcbcf.pyx":304 * for i in range(n): * if data32[i] == bcf_int32_vector_end: * break # <<<<<<<<<<<<<< * value.append(data32[i] if data32[i] != bcf_int32_missing else None) * elif type == BCF_BT_FLOAT: */ - goto __pyx_L19_break; + goto __pyx_L17_break; - /* "pysam/libcbcf.pyx":218 + /* "pysam/libcbcf.pyx":303 * data32 = data * for i in range(n): * if data32[i] == bcf_int32_vector_end: # <<<<<<<<<<<<<< @@ -5750,7 +6450,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, */ } - /* "pysam/libcbcf.pyx":220 + /* "pysam/libcbcf.pyx":305 * if data32[i] == bcf_int32_vector_end: * break * value.append(data32[i] if data32[i] != bcf_int32_missing else None) # <<<<<<<<<<<<<< @@ -5758,30 +6458,30 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, * dataf = data */ if ((((__pyx_v_data32[__pyx_v_i]) != bcf_int32_missing) != 0)) { - __pyx_t_5 = __Pyx_PyInt_From_int32_t((__pyx_v_data32[__pyx_v_i])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 220, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __pyx_t_5; - __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyInt_From_int32_t((__pyx_v_data32[__pyx_v_i])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 305, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_t_3; + __pyx_t_3 = 0; } else { __Pyx_INCREF(Py_None); - __pyx_t_3 = Py_None; + __pyx_t_4 = Py_None; } - __pyx_t_9 = __Pyx_PyObject_Append(__pyx_cur_scope->__pyx_v_value, __pyx_t_3); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 220, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = __Pyx_PyObject_Append(__pyx_v_value, __pyx_t_4); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 305, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - __pyx_L19_break:; + __pyx_L17_break:; - /* "pysam/libcbcf.pyx":215 + /* "pysam/libcbcf.pyx":300 * break * value.append(data16[i] if data16[i] != bcf_int16_missing else None) * elif type == BCF_BT_INT32: # <<<<<<<<<<<<<< * data32 = data * for i in range(n): */ - goto __pyx_L11; + goto __pyx_L9; } - /* "pysam/libcbcf.pyx":221 + /* "pysam/libcbcf.pyx":306 * break * value.append(data32[i] if data32[i] != bcf_int32_missing else None) * elif type == BCF_BT_FLOAT: # <<<<<<<<<<<<<< @@ -5791,7 +6491,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_t_1 = ((__pyx_v_type == BCF_BT_FLOAT) != 0); if (likely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":222 + /* "pysam/libcbcf.pyx":307 * value.append(data32[i] if data32[i] != bcf_int32_missing else None) * elif type == BCF_BT_FLOAT: * dataf = data # <<<<<<<<<<<<<< @@ -5800,19 +6500,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, */ __pyx_v_dataf = ((float *)__pyx_v_data); - /* "pysam/libcbcf.pyx":223 + /* "pysam/libcbcf.pyx":308 * elif type == BCF_BT_FLOAT: * dataf = data * for i in range(n): # <<<<<<<<<<<<<< * if bcf_float_is_vector_end(dataf[i]): * break */ - __pyx_t_6 = __pyx_v_n; - __pyx_t_7 = __pyx_t_6; - for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { - __pyx_v_i = __pyx_t_8; + __pyx_t_5 = __pyx_v_n; + __pyx_t_6 = __pyx_t_5; + for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { + __pyx_v_i = __pyx_t_7; - /* "pysam/libcbcf.pyx":224 + /* "pysam/libcbcf.pyx":309 * dataf = data * for i in range(n): * if bcf_float_is_vector_end(dataf[i]): # <<<<<<<<<<<<<< @@ -5822,16 +6522,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_t_1 = (bcf_float_is_vector_end((__pyx_v_dataf[__pyx_v_i])) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":225 + /* "pysam/libcbcf.pyx":310 * for i in range(n): * if bcf_float_is_vector_end(dataf[i]): * break # <<<<<<<<<<<<<< * value.append(dataf[i] if not bcf_float_is_missing(dataf[i]) else None) * else: */ - goto __pyx_L22_break; + goto __pyx_L20_break; - /* "pysam/libcbcf.pyx":224 + /* "pysam/libcbcf.pyx":309 * dataf = data * for i in range(n): * if bcf_float_is_vector_end(dataf[i]): # <<<<<<<<<<<<<< @@ -5840,7 +6540,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, */ } - /* "pysam/libcbcf.pyx":226 + /* "pysam/libcbcf.pyx":311 * if bcf_float_is_vector_end(dataf[i]): * break * value.append(dataf[i] if not bcf_float_is_missing(dataf[i]) else None) # <<<<<<<<<<<<<< @@ -5848,30 +6548,30 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, * raise TypeError('unsupported info type code') */ if (((!(bcf_float_is_missing((__pyx_v_dataf[__pyx_v_i])) != 0)) != 0)) { - __pyx_t_5 = PyFloat_FromDouble((__pyx_v_dataf[__pyx_v_i])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __pyx_t_5; - __pyx_t_5 = 0; + __pyx_t_3 = PyFloat_FromDouble((__pyx_v_dataf[__pyx_v_i])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 311, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_t_3; + __pyx_t_3 = 0; } else { __Pyx_INCREF(Py_None); - __pyx_t_3 = Py_None; + __pyx_t_4 = Py_None; } - __pyx_t_9 = __Pyx_PyObject_Append(__pyx_cur_scope->__pyx_v_value, __pyx_t_3); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 226, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = __Pyx_PyObject_Append(__pyx_v_value, __pyx_t_4); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 311, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - __pyx_L22_break:; + __pyx_L20_break:; - /* "pysam/libcbcf.pyx":221 + /* "pysam/libcbcf.pyx":306 * break * value.append(data32[i] if data32[i] != bcf_int32_missing else None) * elif type == BCF_BT_FLOAT: # <<<<<<<<<<<<<< * dataf = data * for i in range(n): */ - goto __pyx_L11; + goto __pyx_L9; } - /* "pysam/libcbcf.pyx":228 + /* "pysam/libcbcf.pyx":313 * value.append(dataf[i] if not bcf_float_is_missing(dataf[i]) else None) * else: * raise TypeError('unsupported info type code') # <<<<<<<<<<<<<< @@ -5879,28 +6579,28 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. */ /*else*/ { - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 228, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 313, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 313, __pyx_L1_error) } - __pyx_L11:; + __pyx_L9:; } __pyx_L6:; - /* "pysam/libcbcf.pyx":231 + /* "pysam/libcbcf.pyx":316 * * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. * if not value: # <<<<<<<<<<<<<< * if scalar: * value = None */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_value); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 231, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 316, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":232 + /* "pysam/libcbcf.pyx":317 * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. * if not value: * if scalar: # <<<<<<<<<<<<<< @@ -5910,7 +6610,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_t_2 = (__pyx_v_scalar != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":233 + /* "pysam/libcbcf.pyx":318 * if not value: * if scalar: * value = None # <<<<<<<<<<<<<< @@ -5918,21 +6618,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, * value = () */ __Pyx_INCREF(Py_None); - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_value); - __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_value, Py_None); - __Pyx_GIVEREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_value, Py_None); - /* "pysam/libcbcf.pyx":232 + /* "pysam/libcbcf.pyx":317 * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. * if not value: * if scalar: # <<<<<<<<<<<<<< * value = None * elif count <= 0: */ - goto __pyx_L25; + goto __pyx_L23; } - /* "pysam/libcbcf.pyx":234 + /* "pysam/libcbcf.pyx":319 * if scalar: * value = None * elif count <= 0: # <<<<<<<<<<<<<< @@ -5942,7 +6640,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_t_2 = ((__pyx_v_count <= 0) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":235 + /* "pysam/libcbcf.pyx":320 * value = None * elif count <= 0: * value = () # <<<<<<<<<<<<<< @@ -5950,21 +6648,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, * value = (None,)*count */ __Pyx_INCREF(__pyx_empty_tuple); - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_value); - __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_value, __pyx_empty_tuple); - __Pyx_GIVEREF(__pyx_empty_tuple); + __Pyx_DECREF_SET(__pyx_v_value, __pyx_empty_tuple); - /* "pysam/libcbcf.pyx":234 + /* "pysam/libcbcf.pyx":319 * if scalar: * value = None * elif count <= 0: # <<<<<<<<<<<<<< * value = () * else: */ - goto __pyx_L25; + goto __pyx_L23; } - /* "pysam/libcbcf.pyx":237 + /* "pysam/libcbcf.pyx":322 * value = () * else: * value = (None,)*count # <<<<<<<<<<<<<< @@ -5972,29 +6668,27 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, * value = value[0] */ /*else*/ { - __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_count); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 237, __pyx_L1_error) + __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_count); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 322, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyNumber_Multiply(__pyx_tuple__5, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 322, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyNumber_Multiply(__pyx_tuple__4, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_value); - __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_value, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); + __pyx_t_3 = 0; } - __pyx_L25:; + __pyx_L23:; - /* "pysam/libcbcf.pyx":231 + /* "pysam/libcbcf.pyx":316 * * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. * if not value: # <<<<<<<<<<<<<< * if scalar: * value = None */ - goto __pyx_L24; + goto __pyx_L22; } - /* "pysam/libcbcf.pyx":238 + /* "pysam/libcbcf.pyx":323 * else: * value = (None,)*count * elif scalar and len(value) == 1: # <<<<<<<<<<<<<< @@ -6005,42 +6699,37 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, if (__pyx_t_1) { } else { __pyx_t_2 = __pyx_t_1; - goto __pyx_L26_bool_binop_done; + goto __pyx_L24_bool_binop_done; } - __pyx_t_5 = __pyx_cur_scope->__pyx_v_value; - __Pyx_INCREF(__pyx_t_5); - __pyx_t_10 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_10 == ((Py_ssize_t)-1))) __PYX_ERR(0, 238, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_1 = ((__pyx_t_10 == 1) != 0); + __pyx_t_9 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 323, __pyx_L1_error) + __pyx_t_1 = ((__pyx_t_9 == 1) != 0); __pyx_t_2 = __pyx_t_1; - __pyx_L26_bool_binop_done:; + __pyx_L24_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":239 + /* "pysam/libcbcf.pyx":324 * value = (None,)*count * elif scalar and len(value) == 1: * value = value[0] # <<<<<<<<<<<<<< * else: * value = tuple(value) */ - __pyx_t_5 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_value, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_value); - __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_value, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_value, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 324, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":238 + /* "pysam/libcbcf.pyx":323 * else: * value = (None,)*count * elif scalar and len(value) == 1: # <<<<<<<<<<<<<< * value = value[0] * else: */ - goto __pyx_L24; + goto __pyx_L22; } - /* "pysam/libcbcf.pyx":241 + /* "pysam/libcbcf.pyx":326 * value = value[0] * else: * value = tuple(value) # <<<<<<<<<<<<<< @@ -6048,16 +6737,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, * return value */ /*else*/ { - __pyx_t_5 = __Pyx_PySequence_Tuple(__pyx_cur_scope->__pyx_v_value); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 241, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_value); - __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_value, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PySequence_Tuple(__pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 326, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); + __pyx_t_3 = 0; } - __pyx_L24:; + __pyx_L22:; - /* "pysam/libcbcf.pyx":243 + /* "pysam/libcbcf.pyx":328 * value = tuple(value) * * return value # <<<<<<<<<<<<<< @@ -6065,11 +6752,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, * */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_value); - __pyx_r = __pyx_cur_scope->__pyx_v_value; + __Pyx_INCREF(__pyx_v_value); + __pyx_r = __pyx_v_value; goto __pyx_L0; - /* "pysam/libcbcf.pyx":181 + /* "pysam/libcbcf.pyx":260 * * * cdef bcf_array_to_object(void *data, int type, ssize_t n, ssize_t count, int scalar): # <<<<<<<<<<<<<< @@ -6081,10 +6768,10 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("pysam.libcbcf.bcf_array_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_value); __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); @@ -6093,12 +6780,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_array_to_object(void *__pyx_v_data, } static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_object_to_array_2generator30(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":258 +/* "pysam/libcbcf.pyx":343 * if bt_type == BCF_BT_CHAR: * if not isinstance(values, (str, bytes)): - * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) # <<<<<<<<<<<<<< + * values = b','.join(force_bytes(v) if v else bcf_str_missing for v in values) # <<<<<<<<<<<<<< * value_count = len(values) - * assert(value_count <= n) + * assert value_count <= n */ static PyObject *__pyx_pf_5pysam_7libcbcf_19bcf_object_to_array_genexpr(PyObject *__pyx_self) { @@ -6110,7 +6797,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19bcf_object_to_array_genexpr(PyObject if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_5_genexpr *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 258, __pyx_L1_error) + __PYX_ERR(0, 343, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -6118,7 +6805,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19bcf_object_to_array_genexpr(PyObject __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19bcf_object_to_array_2generator30, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_bcf_object_to_array_locals_genex, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19bcf_object_to_array_2generator30, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_bcf_object_to_array_locals_genex, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 343, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -6147,7 +6834,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_object_to_array_2generator30(__p PyObject *__pyx_t_6 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("genexpr", 0); - __Pyx_TraceCall("genexpr", __pyx_f[0], 258, 0, __PYX_ERR(0, 258, __pyx_L1_error)); + __Pyx_TraceCall("genexpr", __pyx_f[0], 343, 0, __PYX_ERR(0, 343, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -6157,32 +6844,32 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_object_to_array_2generator30(__p return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 258, __pyx_L1_error) - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_values)) { __Pyx_RaiseClosureNameError("values"); __PYX_ERR(0, 258, __pyx_L1_error) } + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 343, __pyx_L1_error) + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_values)) { __Pyx_RaiseClosureNameError("values"); __PYX_ERR(0, 343, __pyx_L1_error) } if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_values)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_values)) { __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_values; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 343, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 343, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_3)) { if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 343, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 343, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } else { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 343, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 343, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } @@ -6192,7 +6879,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_object_to_array_2generator30(__p PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 258, __pyx_L1_error) + else __PYX_ERR(0, 343, __pyx_L1_error) } break; } @@ -6202,15 +6889,17 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_object_to_array_2generator30(__p __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_v, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = (__pyx_cur_scope->__pyx_v_v != Py_None); - if ((__pyx_t_5 != 0)) { - __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_cur_scope->__pyx_v_v, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_v); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 343, __pyx_L1_error) + if (__pyx_t_5) { + __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_cur_scope->__pyx_v_v, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 343, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_4 = __pyx_t_6; __pyx_t_6 = 0; } else { - __Pyx_INCREF(__pyx_kp_b__5); - __pyx_t_4 = __pyx_kp_b__5; + __pyx_t_6 = __Pyx_PyInt_From_int32_t(bcf_str_missing); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 343, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = __pyx_t_6; + __pyx_t_6 = 0; } __pyx_r = __pyx_t_4; __pyx_t_4 = 0; @@ -6231,7 +6920,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_object_to_array_2generator30(__p __Pyx_XGOTREF(__pyx_t_1); __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 258, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 343, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); @@ -6254,7 +6943,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19bcf_object_to_array_2generator30(__p return __pyx_r; } -/* "pysam/libcbcf.pyx":246 +/* "pysam/libcbcf.pyx":331 * * * cdef bcf_object_to_array(values, void *data, int bt_type, ssize_t n, int vlen): # <<<<<<<<<<<<<< @@ -6297,32 +6986,32 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_4___pyx_f_5pysam_7libcbcf_bcf_object_to_array *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 246, __pyx_L1_error) + __PYX_ERR(0, 331, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } - __Pyx_TraceCall("bcf_object_to_array", __pyx_f[0], 246, 0, __PYX_ERR(0, 246, __pyx_L1_error)); + __Pyx_TraceCall("bcf_object_to_array", __pyx_f[0], 331, 0, __PYX_ERR(0, 331, __pyx_L1_error)); __pyx_cur_scope->__pyx_v_values = __pyx_v_values; __Pyx_INCREF(__pyx_cur_scope->__pyx_v_values); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_values); - /* "pysam/libcbcf.pyx":252 + /* "pysam/libcbcf.pyx":337 * cdef int32_t *data32 * cdef float *dataf * cdef ssize_t i, value_count = len(values) # <<<<<<<<<<<<<< * - * assert(value_count <= n) + * assert value_count <= n */ __pyx_t_1 = __pyx_cur_scope->__pyx_v_values; __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 252, __pyx_L1_error) + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 337, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_value_count = __pyx_t_2; - /* "pysam/libcbcf.pyx":254 + /* "pysam/libcbcf.pyx":339 * cdef ssize_t i, value_count = len(values) * - * assert(value_count <= n) # <<<<<<<<<<<<<< + * assert value_count <= n # <<<<<<<<<<<<<< * * if bt_type == BCF_BT_CHAR: */ @@ -6330,26 +7019,26 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((__pyx_v_value_count <= __pyx_v_n) != 0))) { PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 254, __pyx_L1_error) + __PYX_ERR(0, 339, __pyx_L1_error) } } #endif - /* "pysam/libcbcf.pyx":256 - * assert(value_count <= n) + /* "pysam/libcbcf.pyx":341 + * assert value_count <= n * * if bt_type == BCF_BT_CHAR: # <<<<<<<<<<<<<< * if not isinstance(values, (str, bytes)): - * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) + * values = b','.join(force_bytes(v) if v else bcf_str_missing for v in values) */ __pyx_t_3 = ((__pyx_v_bt_type == BCF_BT_CHAR) != 0); if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":257 + /* "pysam/libcbcf.pyx":342 * * if bt_type == BCF_BT_CHAR: * if not isinstance(values, (str, bytes)): # <<<<<<<<<<<<<< - * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) + * values = b','.join(force_bytes(v) if v else bcf_str_missing for v in values) * value_count = len(values) */ __pyx_t_1 = __pyx_cur_scope->__pyx_v_values; @@ -6372,16 +7061,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v __pyx_t_4 = ((!(__pyx_t_3 != 0)) != 0); if (__pyx_t_4) { - /* "pysam/libcbcf.pyx":258 + /* "pysam/libcbcf.pyx":343 * if bt_type == BCF_BT_CHAR: * if not isinstance(values, (str, bytes)): - * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) # <<<<<<<<<<<<<< + * values = b','.join(force_bytes(v) if v else bcf_str_missing for v in values) # <<<<<<<<<<<<<< * value_count = len(values) - * assert(value_count <= n) + * assert value_count <= n */ - __pyx_t_1 = __pyx_pf_5pysam_7libcbcf_19bcf_object_to_array_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_1 = __pyx_pf_5pysam_7libcbcf_19bcf_object_to_array_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 343, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_PyBytes_Join(__pyx_kp_b_, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyBytes_Join(__pyx_kp_b__2, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 343, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_values); @@ -6389,32 +7078,32 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libcbcf.pyx":259 + /* "pysam/libcbcf.pyx":344 * if not isinstance(values, (str, bytes)): - * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) + * values = b','.join(force_bytes(v) if v else bcf_str_missing for v in values) * value_count = len(values) # <<<<<<<<<<<<<< - * assert(value_count <= n) + * assert value_count <= n * datac = data */ __pyx_t_6 = __pyx_cur_scope->__pyx_v_values; __Pyx_INCREF(__pyx_t_6); - __pyx_t_2 = PyObject_Length(__pyx_t_6); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 259, __pyx_L1_error) + __pyx_t_2 = PyObject_Length(__pyx_t_6); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 344, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_value_count = __pyx_t_2; - /* "pysam/libcbcf.pyx":257 + /* "pysam/libcbcf.pyx":342 * * if bt_type == BCF_BT_CHAR: * if not isinstance(values, (str, bytes)): # <<<<<<<<<<<<<< - * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) + * values = b','.join(force_bytes(v) if v else bcf_str_missing for v in values) * value_count = len(values) */ } - /* "pysam/libcbcf.pyx":260 - * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) + /* "pysam/libcbcf.pyx":345 + * values = b','.join(force_bytes(v) if v else bcf_str_missing for v in values) * value_count = len(values) - * assert(value_count <= n) # <<<<<<<<<<<<<< + * assert value_count <= n # <<<<<<<<<<<<<< * datac = data * memcpy(datac, values, value_count) */ @@ -6422,31 +7111,31 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((__pyx_v_value_count <= __pyx_v_n) != 0))) { PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 260, __pyx_L1_error) + __PYX_ERR(0, 345, __pyx_L1_error) } } #endif - /* "pysam/libcbcf.pyx":261 + /* "pysam/libcbcf.pyx":346 * value_count = len(values) - * assert(value_count <= n) + * assert value_count <= n * datac = data # <<<<<<<<<<<<<< * memcpy(datac, values, value_count) * for i in range(value_count, n): */ __pyx_v_datac = ((char *)__pyx_v_data); - /* "pysam/libcbcf.pyx":262 - * assert(value_count <= n) + /* "pysam/libcbcf.pyx":347 + * assert value_count <= n * datac = data * memcpy(datac, values, value_count) # <<<<<<<<<<<<<< * for i in range(value_count, n): * datac[i] = 0 */ - __pyx_t_7 = __Pyx_PyObject_AsWritableString(__pyx_cur_scope->__pyx_v_values); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 262, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_AsWritableString(__pyx_cur_scope->__pyx_v_values); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 347, __pyx_L1_error) (void)(memcpy(__pyx_v_datac, ((char *)__pyx_t_7), __pyx_v_value_count)); - /* "pysam/libcbcf.pyx":263 + /* "pysam/libcbcf.pyx":348 * datac = data * memcpy(datac, values, value_count) * for i in range(value_count, n): # <<<<<<<<<<<<<< @@ -6458,7 +7147,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v for (__pyx_t_10 = __pyx_v_value_count; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":264 + /* "pysam/libcbcf.pyx":349 * memcpy(datac, values, value_count) * for i in range(value_count, n): * datac[i] = 0 # <<<<<<<<<<<<<< @@ -6468,17 +7157,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v (__pyx_v_datac[__pyx_v_i]) = 0; } - /* "pysam/libcbcf.pyx":256 - * assert(value_count <= n) + /* "pysam/libcbcf.pyx":341 + * assert value_count <= n * * if bt_type == BCF_BT_CHAR: # <<<<<<<<<<<<<< * if not isinstance(values, (str, bytes)): - * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) + * values = b','.join(force_bytes(v) if v else bcf_str_missing for v in values) */ goto __pyx_L3; } - /* "pysam/libcbcf.pyx":265 + /* "pysam/libcbcf.pyx":350 * for i in range(value_count, n): * datac[i] = 0 * elif bt_type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -6488,7 +7177,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v __pyx_t_4 = ((__pyx_v_bt_type == BCF_BT_INT8) != 0); if (__pyx_t_4) { - /* "pysam/libcbcf.pyx":266 + /* "pysam/libcbcf.pyx":351 * datac[i] = 0 * elif bt_type == BCF_BT_INT8: * datai8 = data # <<<<<<<<<<<<<< @@ -6497,7 +7186,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v */ __pyx_v_datai8 = ((int8_t *)__pyx_v_data); - /* "pysam/libcbcf.pyx":267 + /* "pysam/libcbcf.pyx":352 * elif bt_type == BCF_BT_INT8: * datai8 = data * for i in range(value_count): # <<<<<<<<<<<<<< @@ -6509,19 +7198,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":268 + /* "pysam/libcbcf.pyx":353 * datai8 = data * for i in range(value_count): * val = values[i] # <<<<<<<<<<<<<< * datai8[i] = val if val is not None else bcf_int8_missing * for i in range(value_count, n): */ - __pyx_t_6 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_values, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 268, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_values, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 353, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_XDECREF_SET(__pyx_v_val, __pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libcbcf.pyx":269 + /* "pysam/libcbcf.pyx":354 * for i in range(value_count): * val = values[i] * datai8[i] = val if val is not None else bcf_int8_missing # <<<<<<<<<<<<<< @@ -6530,7 +7219,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v */ __pyx_t_4 = (__pyx_v_val != Py_None); if ((__pyx_t_4 != 0)) { - __pyx_t_12 = __Pyx_PyInt_As_int8_t(__pyx_v_val); if (unlikely((__pyx_t_12 == ((int8_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 269, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyInt_As_int8_t(__pyx_v_val); if (unlikely((__pyx_t_12 == ((int8_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 354, __pyx_L1_error) __pyx_t_11 = __pyx_t_12; } else { __pyx_t_11 = bcf_int8_missing; @@ -6538,7 +7227,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v (__pyx_v_datai8[__pyx_v_i]) = __pyx_t_11; } - /* "pysam/libcbcf.pyx":270 + /* "pysam/libcbcf.pyx":355 * val = values[i] * datai8[i] = val if val is not None else bcf_int8_missing * for i in range(value_count, n): # <<<<<<<<<<<<<< @@ -6550,7 +7239,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v for (__pyx_t_10 = __pyx_v_value_count; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":271 + /* "pysam/libcbcf.pyx":356 * datai8[i] = val if val is not None else bcf_int8_missing * for i in range(value_count, n): * datai8[i] = bcf_int8_vector_end # <<<<<<<<<<<<<< @@ -6560,7 +7249,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v (__pyx_v_datai8[__pyx_v_i]) = bcf_int8_vector_end; } - /* "pysam/libcbcf.pyx":265 + /* "pysam/libcbcf.pyx":350 * for i in range(value_count, n): * datac[i] = 0 * elif bt_type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -6570,7 +7259,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v goto __pyx_L3; } - /* "pysam/libcbcf.pyx":272 + /* "pysam/libcbcf.pyx":357 * for i in range(value_count, n): * datai8[i] = bcf_int8_vector_end * elif bt_type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -6580,7 +7269,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v __pyx_t_4 = ((__pyx_v_bt_type == BCF_BT_INT16) != 0); if (__pyx_t_4) { - /* "pysam/libcbcf.pyx":273 + /* "pysam/libcbcf.pyx":358 * datai8[i] = bcf_int8_vector_end * elif bt_type == BCF_BT_INT16: * datai16 = data # <<<<<<<<<<<<<< @@ -6589,7 +7278,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v */ __pyx_v_datai16 = ((int16_t *)__pyx_v_data); - /* "pysam/libcbcf.pyx":274 + /* "pysam/libcbcf.pyx":359 * elif bt_type == BCF_BT_INT16: * datai16 = data * for i in range(value_count): # <<<<<<<<<<<<<< @@ -6601,19 +7290,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":275 + /* "pysam/libcbcf.pyx":360 * datai16 = data * for i in range(value_count): * val = values[i] # <<<<<<<<<<<<<< * datai16[i] = val if val is not None else bcf_int16_missing * for i in range(value_count, n): */ - __pyx_t_6 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_values, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 275, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_values, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 360, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_XDECREF_SET(__pyx_v_val, __pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libcbcf.pyx":276 + /* "pysam/libcbcf.pyx":361 * for i in range(value_count): * val = values[i] * datai16[i] = val if val is not None else bcf_int16_missing # <<<<<<<<<<<<<< @@ -6622,7 +7311,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v */ __pyx_t_4 = (__pyx_v_val != Py_None); if ((__pyx_t_4 != 0)) { - __pyx_t_14 = __Pyx_PyInt_As_int16_t(__pyx_v_val); if (unlikely((__pyx_t_14 == ((int16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 276, __pyx_L1_error) + __pyx_t_14 = __Pyx_PyInt_As_int16_t(__pyx_v_val); if (unlikely((__pyx_t_14 == ((int16_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 361, __pyx_L1_error) __pyx_t_13 = __pyx_t_14; } else { __pyx_t_13 = bcf_int16_missing; @@ -6630,7 +7319,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v (__pyx_v_datai16[__pyx_v_i]) = __pyx_t_13; } - /* "pysam/libcbcf.pyx":277 + /* "pysam/libcbcf.pyx":362 * val = values[i] * datai16[i] = val if val is not None else bcf_int16_missing * for i in range(value_count, n): # <<<<<<<<<<<<<< @@ -6642,7 +7331,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v for (__pyx_t_10 = __pyx_v_value_count; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":278 + /* "pysam/libcbcf.pyx":363 * datai16[i] = val if val is not None else bcf_int16_missing * for i in range(value_count, n): * datai16[i] = bcf_int16_vector_end # <<<<<<<<<<<<<< @@ -6652,7 +7341,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v (__pyx_v_datai16[__pyx_v_i]) = bcf_int16_vector_end; } - /* "pysam/libcbcf.pyx":272 + /* "pysam/libcbcf.pyx":357 * for i in range(value_count, n): * datai8[i] = bcf_int8_vector_end * elif bt_type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -6662,7 +7351,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v goto __pyx_L3; } - /* "pysam/libcbcf.pyx":279 + /* "pysam/libcbcf.pyx":364 * for i in range(value_count, n): * datai16[i] = bcf_int16_vector_end * elif bt_type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -6672,7 +7361,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v __pyx_t_4 = ((__pyx_v_bt_type == BCF_BT_INT32) != 0); if (__pyx_t_4) { - /* "pysam/libcbcf.pyx":280 + /* "pysam/libcbcf.pyx":365 * datai16[i] = bcf_int16_vector_end * elif bt_type == BCF_BT_INT32: * datai32 = data # <<<<<<<<<<<<<< @@ -6681,7 +7370,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v */ __pyx_v_datai32 = ((int32_t *)__pyx_v_data); - /* "pysam/libcbcf.pyx":281 + /* "pysam/libcbcf.pyx":366 * elif bt_type == BCF_BT_INT32: * datai32 = data * for i in range(value_count): # <<<<<<<<<<<<<< @@ -6693,19 +7382,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":282 + /* "pysam/libcbcf.pyx":367 * datai32 = data * for i in range(value_count): * val = values[i] # <<<<<<<<<<<<<< * datai32[i] = val if val is not None else bcf_int32_missing * for i in range(value_count, n): */ - __pyx_t_6 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_values, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 282, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_values, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 367, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_XDECREF_SET(__pyx_v_val, __pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libcbcf.pyx":283 + /* "pysam/libcbcf.pyx":368 * for i in range(value_count): * val = values[i] * datai32[i] = val if val is not None else bcf_int32_missing # <<<<<<<<<<<<<< @@ -6714,7 +7403,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v */ __pyx_t_4 = (__pyx_v_val != Py_None); if ((__pyx_t_4 != 0)) { - __pyx_t_16 = __Pyx_PyInt_As_int32_t(__pyx_v_val); if (unlikely((__pyx_t_16 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 283, __pyx_L1_error) + __pyx_t_16 = __Pyx_PyInt_As_int32_t(__pyx_v_val); if (unlikely((__pyx_t_16 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 368, __pyx_L1_error) __pyx_t_15 = __pyx_t_16; } else { __pyx_t_15 = bcf_int32_missing; @@ -6722,7 +7411,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v (__pyx_v_datai32[__pyx_v_i]) = __pyx_t_15; } - /* "pysam/libcbcf.pyx":284 + /* "pysam/libcbcf.pyx":369 * val = values[i] * datai32[i] = val if val is not None else bcf_int32_missing * for i in range(value_count, n): # <<<<<<<<<<<<<< @@ -6734,7 +7423,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v for (__pyx_t_10 = __pyx_v_value_count; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":285 + /* "pysam/libcbcf.pyx":370 * datai32[i] = val if val is not None else bcf_int32_missing * for i in range(value_count, n): * datai32[i] = bcf_int32_vector_end # <<<<<<<<<<<<<< @@ -6744,7 +7433,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v (__pyx_v_datai32[__pyx_v_i]) = bcf_int32_vector_end; } - /* "pysam/libcbcf.pyx":279 + /* "pysam/libcbcf.pyx":364 * for i in range(value_count, n): * datai16[i] = bcf_int16_vector_end * elif bt_type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -6754,7 +7443,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v goto __pyx_L3; } - /* "pysam/libcbcf.pyx":286 + /* "pysam/libcbcf.pyx":371 * for i in range(value_count, n): * datai32[i] = bcf_int32_vector_end * elif bt_type == BCF_BT_FLOAT: # <<<<<<<<<<<<<< @@ -6764,7 +7453,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v __pyx_t_4 = ((__pyx_v_bt_type == BCF_BT_FLOAT) != 0); if (likely(__pyx_t_4)) { - /* "pysam/libcbcf.pyx":287 + /* "pysam/libcbcf.pyx":372 * datai32[i] = bcf_int32_vector_end * elif bt_type == BCF_BT_FLOAT: * dataf = data # <<<<<<<<<<<<<< @@ -6773,7 +7462,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v */ __pyx_v_dataf = ((float *)__pyx_v_data); - /* "pysam/libcbcf.pyx":288 + /* "pysam/libcbcf.pyx":373 * elif bt_type == BCF_BT_FLOAT: * dataf = data * for i in range(value_count): # <<<<<<<<<<<<<< @@ -6785,19 +7474,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":289 + /* "pysam/libcbcf.pyx":374 * dataf = data * for i in range(value_count): * val = values[i] # <<<<<<<<<<<<<< * if val is None: * bcf_float_set(dataf + i, bcf_float_missing) */ - __pyx_t_6 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_values, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 289, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_values, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 374, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_XDECREF_SET(__pyx_v_val, __pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libcbcf.pyx":290 + /* "pysam/libcbcf.pyx":375 * for i in range(value_count): * val = values[i] * if val is None: # <<<<<<<<<<<<<< @@ -6808,7 +7497,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v __pyx_t_3 = (__pyx_t_4 != 0); if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":291 + /* "pysam/libcbcf.pyx":376 * val = values[i] * if val is None: * bcf_float_set(dataf + i, bcf_float_missing) # <<<<<<<<<<<<<< @@ -6817,7 +7506,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v */ bcf_float_set((__pyx_v_dataf + __pyx_v_i), bcf_float_missing); - /* "pysam/libcbcf.pyx":290 + /* "pysam/libcbcf.pyx":375 * for i in range(value_count): * val = values[i] * if val is None: # <<<<<<<<<<<<<< @@ -6827,7 +7516,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v goto __pyx_L23; } - /* "pysam/libcbcf.pyx":293 + /* "pysam/libcbcf.pyx":378 * bcf_float_set(dataf + i, bcf_float_missing) * else: * dataf[i] = val # <<<<<<<<<<<<<< @@ -6835,13 +7524,13 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v * bcf_float_set(dataf + i, bcf_float_vector_end) */ /*else*/ { - __pyx_t_17 = __pyx_PyFloat_AsFloat(__pyx_v_val); if (unlikely((__pyx_t_17 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 293, __pyx_L1_error) + __pyx_t_17 = __pyx_PyFloat_AsFloat(__pyx_v_val); if (unlikely((__pyx_t_17 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 378, __pyx_L1_error) (__pyx_v_dataf[__pyx_v_i]) = __pyx_t_17; } __pyx_L23:; } - /* "pysam/libcbcf.pyx":294 + /* "pysam/libcbcf.pyx":379 * else: * dataf[i] = val * for i in range(value_count, n): # <<<<<<<<<<<<<< @@ -6853,7 +7542,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v for (__pyx_t_10 = __pyx_v_value_count; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":295 + /* "pysam/libcbcf.pyx":380 * dataf[i] = val * for i in range(value_count, n): * bcf_float_set(dataf + i, bcf_float_vector_end) # <<<<<<<<<<<<<< @@ -6863,7 +7552,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v bcf_float_set((__pyx_v_dataf + __pyx_v_i), bcf_float_vector_end); } - /* "pysam/libcbcf.pyx":286 + /* "pysam/libcbcf.pyx":371 * for i in range(value_count, n): * datai32[i] = bcf_int32_vector_end * elif bt_type == BCF_BT_FLOAT: # <<<<<<<<<<<<<< @@ -6873,7 +7562,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v goto __pyx_L3; } - /* "pysam/libcbcf.pyx":297 + /* "pysam/libcbcf.pyx":382 * bcf_float_set(dataf + i, bcf_float_vector_end) * else: * raise TypeError('unsupported type') # <<<<<<<<<<<<<< @@ -6881,15 +7570,15 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v * */ /*else*/ { - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 297, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 382, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_Raise(__pyx_t_6, 0, 0, 0); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 297, __pyx_L1_error) + __PYX_ERR(0, 382, __pyx_L1_error) } __pyx_L3:; - /* "pysam/libcbcf.pyx":246 + /* "pysam/libcbcf.pyx":331 * * * cdef bcf_object_to_array(values, void *data, int bt_type, ssize_t n, int vlen): # <<<<<<<<<<<<<< @@ -6914,7 +7603,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_object_to_array(PyObject *__pyx_v_v return __pyx_r; } -/* "pysam/libcbcf.pyx":300 +/* "pysam/libcbcf.pyx":385 * * * cdef bcf_empty_array(int type, ssize_t n, int vlen): # <<<<<<<<<<<<<< @@ -6940,9 +7629,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss int32_t __pyx_t_7; uint32_t __pyx_t_8; __Pyx_RefNannySetupContext("bcf_empty_array", 0); - __Pyx_TraceCall("bcf_empty_array", __pyx_f[0], 300, 0, __PYX_ERR(0, 300, __pyx_L1_error)); + __Pyx_TraceCall("bcf_empty_array", __pyx_f[0], 385, 0, __PYX_ERR(0, 385, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":306 + /* "pysam/libcbcf.pyx":391 * cdef int i * * if n <= 0: # <<<<<<<<<<<<<< @@ -6952,20 +7641,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss __pyx_t_1 = ((__pyx_v_n <= 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":307 + /* "pysam/libcbcf.pyx":392 * * if n <= 0: * raise ValueError('Cannot create empty array') # <<<<<<<<<<<<<< * * if type == BCF_HT_STR: */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 392, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 307, __pyx_L1_error) + __PYX_ERR(0, 392, __pyx_L1_error) - /* "pysam/libcbcf.pyx":306 + /* "pysam/libcbcf.pyx":391 * cdef int i * * if n <= 0: # <<<<<<<<<<<<<< @@ -6974,7 +7663,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss */ } - /* "pysam/libcbcf.pyx":309 + /* "pysam/libcbcf.pyx":394 * raise ValueError('Cannot create empty array') * * if type == BCF_HT_STR: # <<<<<<<<<<<<<< @@ -6984,19 +7673,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss __pyx_t_1 = ((__pyx_v_type == BCF_HT_STR) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":310 + /* "pysam/libcbcf.pyx":395 * * if type == BCF_HT_STR: * value = PyBytes_FromStringAndSize(NULL, sizeof(char)*n) # <<<<<<<<<<<<<< * datac = value * for i in range(n): */ - __pyx_t_2 = PyBytes_FromStringAndSize(NULL, ((sizeof(char)) * __pyx_v_n)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 310, __pyx_L1_error) + __pyx_t_2 = PyBytes_FromStringAndSize(NULL, ((sizeof(char)) * __pyx_v_n)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 395, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_value = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":311 + /* "pysam/libcbcf.pyx":396 * if type == BCF_HT_STR: * value = PyBytes_FromStringAndSize(NULL, sizeof(char)*n) * datac = value # <<<<<<<<<<<<<< @@ -7005,12 +7694,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss */ if (unlikely(__pyx_v_value == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 311, __pyx_L1_error) + __PYX_ERR(0, 396, __pyx_L1_error) } - __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v_value); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 311, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v_value); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 396, __pyx_L1_error) __pyx_v_datac = ((char *)__pyx_t_3); - /* "pysam/libcbcf.pyx":312 + /* "pysam/libcbcf.pyx":397 * value = PyBytes_FromStringAndSize(NULL, sizeof(char)*n) * datac = value * for i in range(n): # <<<<<<<<<<<<<< @@ -7022,7 +7711,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; - /* "pysam/libcbcf.pyx":313 + /* "pysam/libcbcf.pyx":398 * datac = value * for i in range(n): * datac[i] = bcf_str_missing if not vlen else bcf_str_vector_end # <<<<<<<<<<<<<< @@ -7037,7 +7726,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss (__pyx_v_datac[__pyx_v_i]) = __pyx_t_7; } - /* "pysam/libcbcf.pyx":309 + /* "pysam/libcbcf.pyx":394 * raise ValueError('Cannot create empty array') * * if type == BCF_HT_STR: # <<<<<<<<<<<<<< @@ -7047,7 +7736,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss goto __pyx_L4; } - /* "pysam/libcbcf.pyx":314 + /* "pysam/libcbcf.pyx":399 * for i in range(n): * datac[i] = bcf_str_missing if not vlen else bcf_str_vector_end * elif type == BCF_HT_INT: # <<<<<<<<<<<<<< @@ -7057,19 +7746,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss __pyx_t_1 = ((__pyx_v_type == BCF_HT_INT) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":315 + /* "pysam/libcbcf.pyx":400 * datac[i] = bcf_str_missing if not vlen else bcf_str_vector_end * elif type == BCF_HT_INT: * value = PyBytes_FromStringAndSize(NULL, sizeof(int32_t)*n) # <<<<<<<<<<<<<< * data32 = value * for i in range(n): */ - __pyx_t_2 = PyBytes_FromStringAndSize(NULL, ((sizeof(int32_t)) * __pyx_v_n)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 315, __pyx_L1_error) + __pyx_t_2 = PyBytes_FromStringAndSize(NULL, ((sizeof(int32_t)) * __pyx_v_n)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 400, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_value = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":316 + /* "pysam/libcbcf.pyx":401 * elif type == BCF_HT_INT: * value = PyBytes_FromStringAndSize(NULL, sizeof(int32_t)*n) * data32 = value # <<<<<<<<<<<<<< @@ -7078,12 +7767,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss */ if (unlikely(__pyx_v_value == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 316, __pyx_L1_error) + __PYX_ERR(0, 401, __pyx_L1_error) } - __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v_value); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 316, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v_value); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 401, __pyx_L1_error) __pyx_v_data32 = ((int32_t *)((char *)__pyx_t_3)); - /* "pysam/libcbcf.pyx":317 + /* "pysam/libcbcf.pyx":402 * value = PyBytes_FromStringAndSize(NULL, sizeof(int32_t)*n) * data32 = value * for i in range(n): # <<<<<<<<<<<<<< @@ -7095,7 +7784,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; - /* "pysam/libcbcf.pyx":318 + /* "pysam/libcbcf.pyx":403 * data32 = value * for i in range(n): * data32[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end # <<<<<<<<<<<<<< @@ -7110,7 +7799,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss (__pyx_v_data32[__pyx_v_i]) = __pyx_t_7; } - /* "pysam/libcbcf.pyx":314 + /* "pysam/libcbcf.pyx":399 * for i in range(n): * datac[i] = bcf_str_missing if not vlen else bcf_str_vector_end * elif type == BCF_HT_INT: # <<<<<<<<<<<<<< @@ -7120,7 +7809,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss goto __pyx_L4; } - /* "pysam/libcbcf.pyx":319 + /* "pysam/libcbcf.pyx":404 * for i in range(n): * data32[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end * elif type == BCF_HT_REAL: # <<<<<<<<<<<<<< @@ -7130,19 +7819,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss __pyx_t_1 = ((__pyx_v_type == BCF_HT_REAL) != 0); if (likely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":320 + /* "pysam/libcbcf.pyx":405 * data32[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end * elif type == BCF_HT_REAL: * value = PyBytes_FromStringAndSize(NULL, sizeof(float)*n) # <<<<<<<<<<<<<< * dataf = value * for i in range(n): */ - __pyx_t_2 = PyBytes_FromStringAndSize(NULL, ((sizeof(float)) * __pyx_v_n)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error) + __pyx_t_2 = PyBytes_FromStringAndSize(NULL, ((sizeof(float)) * __pyx_v_n)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 405, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_value = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":321 + /* "pysam/libcbcf.pyx":406 * elif type == BCF_HT_REAL: * value = PyBytes_FromStringAndSize(NULL, sizeof(float)*n) * dataf = value # <<<<<<<<<<<<<< @@ -7151,12 +7840,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss */ if (unlikely(__pyx_v_value == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 321, __pyx_L1_error) + __PYX_ERR(0, 406, __pyx_L1_error) } - __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v_value); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 321, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v_value); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 406, __pyx_L1_error) __pyx_v_dataf = ((float *)((char *)__pyx_t_3)); - /* "pysam/libcbcf.pyx":322 + /* "pysam/libcbcf.pyx":407 * value = PyBytes_FromStringAndSize(NULL, sizeof(float)*n) * dataf = value * for i in range(n): # <<<<<<<<<<<<<< @@ -7168,7 +7857,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; - /* "pysam/libcbcf.pyx":323 + /* "pysam/libcbcf.pyx":408 * dataf = value * for i in range(n): * bcf_float_set(dataf + i, bcf_float_missing if not vlen else bcf_float_vector_end) # <<<<<<<<<<<<<< @@ -7183,7 +7872,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss bcf_float_set((__pyx_v_dataf + __pyx_v_i), __pyx_t_8); } - /* "pysam/libcbcf.pyx":319 + /* "pysam/libcbcf.pyx":404 * for i in range(n): * data32[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end * elif type == BCF_HT_REAL: # <<<<<<<<<<<<<< @@ -7193,7 +7882,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss goto __pyx_L4; } - /* "pysam/libcbcf.pyx":325 + /* "pysam/libcbcf.pyx":410 * bcf_float_set(dataf + i, bcf_float_missing if not vlen else bcf_float_vector_end) * else: * raise TypeError('unsupported header type code') # <<<<<<<<<<<<<< @@ -7201,15 +7890,15 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss * return value */ /*else*/ { - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 325, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 410, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 325, __pyx_L1_error) + __PYX_ERR(0, 410, __pyx_L1_error) } __pyx_L4:; - /* "pysam/libcbcf.pyx":327 + /* "pysam/libcbcf.pyx":412 * raise TypeError('unsupported header type code') * * return value # <<<<<<<<<<<<<< @@ -7221,7 +7910,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss __pyx_r = __pyx_v_value; goto __pyx_L0; - /* "pysam/libcbcf.pyx":300 + /* "pysam/libcbcf.pyx":385 * * * cdef bcf_empty_array(int type, ssize_t n, int vlen): # <<<<<<<<<<<<<< @@ -7242,7 +7931,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_empty_array(int __pyx_v_type, Py_ss return __pyx_r; } -/* "pysam/libcbcf.pyx":330 +/* "pysam/libcbcf.pyx":415 * * * cdef bcf_copy_expand_array(void *src_data, int src_type, ssize_t src_values, # <<<<<<<<<<<<<< @@ -7279,9 +7968,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src int32_t __pyx_t_13; uint32_t __pyx_t_14; __Pyx_RefNannySetupContext("bcf_copy_expand_array", 0); - __Pyx_TraceCall("bcf_copy_expand_array", __pyx_f[0], 330, 0, __PYX_ERR(0, 330, __pyx_L1_error)); + __Pyx_TraceCall("bcf_copy_expand_array", __pyx_f[0], 415, 0, __PYX_ERR(0, 415, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":344 + /* "pysam/libcbcf.pyx":429 * cdef int val * * if src_values > dst_values: # <<<<<<<<<<<<<< @@ -7291,18 +7980,18 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src __pyx_t_1 = ((__pyx_v_src_values > __pyx_v_dst_values) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":345 + /* "pysam/libcbcf.pyx":430 * * if src_values > dst_values: * raise ValueError('Cannot copy arrays with src_values={} > dst_values={}'.format(src_values, dst_values)) # <<<<<<<<<<<<<< * * if src_type == dst_type == BCF_BT_CHAR: */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Cannot_copy_arrays_with_src_valu, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Cannot_copy_arrays_with_src_valu, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 430, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_src_values); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_src_values); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 430, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_dst_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_dst_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 430, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = NULL; __pyx_t_7 = 0; @@ -7319,7 +8008,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_4, __pyx_t_5}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 430, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -7329,7 +8018,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_4, __pyx_t_5}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 430, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -7337,7 +8026,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src } else #endif { - __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 430, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); if (__pyx_t_6) { __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; @@ -7348,19 +8037,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5); __pyx_t_4 = 0; __pyx_t_5 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 430, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 430, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 345, __pyx_L1_error) + __PYX_ERR(0, 430, __pyx_L1_error) - /* "pysam/libcbcf.pyx":344 + /* "pysam/libcbcf.pyx":429 * cdef int val * * if src_values > dst_values: # <<<<<<<<<<<<<< @@ -7369,7 +8058,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ } - /* "pysam/libcbcf.pyx":347 + /* "pysam/libcbcf.pyx":432 * raise ValueError('Cannot copy arrays with src_values={} > dst_values={}'.format(src_values, dst_values)) * * if src_type == dst_type == BCF_BT_CHAR: # <<<<<<<<<<<<<< @@ -7383,7 +8072,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src __pyx_t_9 = (__pyx_t_1 != 0); if (__pyx_t_9) { - /* "pysam/libcbcf.pyx":348 + /* "pysam/libcbcf.pyx":433 * * if src_type == dst_type == BCF_BT_CHAR: * src_datac = src_data # <<<<<<<<<<<<<< @@ -7392,7 +8081,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_src_datac = ((char *)__pyx_v_src_data); - /* "pysam/libcbcf.pyx":349 + /* "pysam/libcbcf.pyx":434 * if src_type == dst_type == BCF_BT_CHAR: * src_datac = src_data * dst_datac = dst_data # <<<<<<<<<<<<<< @@ -7401,7 +8090,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_dst_datac = ((char *)__pyx_v_dst_data); - /* "pysam/libcbcf.pyx":350 + /* "pysam/libcbcf.pyx":435 * src_datac = src_data * dst_datac = dst_data * memcpy(src_datac, dst_datac, src_values) # <<<<<<<<<<<<<< @@ -7410,7 +8099,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ (void)(memcpy(__pyx_v_src_datac, __pyx_v_dst_datac, __pyx_v_src_values)); - /* "pysam/libcbcf.pyx":351 + /* "pysam/libcbcf.pyx":436 * dst_datac = dst_data * memcpy(src_datac, dst_datac, src_values) * for i in range(src_values, dst_values): # <<<<<<<<<<<<<< @@ -7422,7 +8111,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src for (__pyx_t_12 = __pyx_v_src_values; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_i = __pyx_t_12; - /* "pysam/libcbcf.pyx":352 + /* "pysam/libcbcf.pyx":437 * memcpy(src_datac, dst_datac, src_values) * for i in range(src_values, dst_values): * dst_datac[i] = 0 # <<<<<<<<<<<<<< @@ -7432,7 +8121,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src (__pyx_v_dst_datac[__pyx_v_i]) = 0; } - /* "pysam/libcbcf.pyx":347 + /* "pysam/libcbcf.pyx":432 * raise ValueError('Cannot copy arrays with src_values={} > dst_values={}'.format(src_values, dst_values)) * * if src_type == dst_type == BCF_BT_CHAR: # <<<<<<<<<<<<<< @@ -7442,7 +8131,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src goto __pyx_L4; } - /* "pysam/libcbcf.pyx":353 + /* "pysam/libcbcf.pyx":438 * for i in range(src_values, dst_values): * dst_datac[i] = 0 * elif src_type == BCF_BT_INT8 and dst_type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -7460,7 +8149,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src __pyx_L7_bool_binop_done:; if (__pyx_t_9) { - /* "pysam/libcbcf.pyx":354 + /* "pysam/libcbcf.pyx":439 * dst_datac[i] = 0 * elif src_type == BCF_BT_INT8 and dst_type == BCF_BT_INT32: * src_datai8 = src_data # <<<<<<<<<<<<<< @@ -7469,7 +8158,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_src_datai8 = ((int8_t *)__pyx_v_src_data); - /* "pysam/libcbcf.pyx":355 + /* "pysam/libcbcf.pyx":440 * elif src_type == BCF_BT_INT8 and dst_type == BCF_BT_INT32: * src_datai8 = src_data * dst_datai = dst_data # <<<<<<<<<<<<<< @@ -7478,7 +8167,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_dst_datai = ((int32_t *)__pyx_v_dst_data); - /* "pysam/libcbcf.pyx":356 + /* "pysam/libcbcf.pyx":441 * src_datai8 = src_data * dst_datai = dst_data * for i in range(src_values): # <<<<<<<<<<<<<< @@ -7490,7 +8179,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_i = __pyx_t_12; - /* "pysam/libcbcf.pyx":357 + /* "pysam/libcbcf.pyx":442 * dst_datai = dst_data * for i in range(src_values): * val = src_datai8[i] # <<<<<<<<<<<<<< @@ -7499,7 +8188,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_val = (__pyx_v_src_datai8[__pyx_v_i]); - /* "pysam/libcbcf.pyx":358 + /* "pysam/libcbcf.pyx":443 * for i in range(src_values): * val = src_datai8[i] * if val == bcf_int8_missing: # <<<<<<<<<<<<<< @@ -7509,7 +8198,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src __pyx_t_9 = ((__pyx_v_val == bcf_int8_missing) != 0); if (__pyx_t_9) { - /* "pysam/libcbcf.pyx":359 + /* "pysam/libcbcf.pyx":444 * val = src_datai8[i] * if val == bcf_int8_missing: * val = bcf_int32_missing # <<<<<<<<<<<<<< @@ -7518,7 +8207,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_val = bcf_int32_missing; - /* "pysam/libcbcf.pyx":358 + /* "pysam/libcbcf.pyx":443 * for i in range(src_values): * val = src_datai8[i] * if val == bcf_int8_missing: # <<<<<<<<<<<<<< @@ -7528,7 +8217,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src goto __pyx_L11; } - /* "pysam/libcbcf.pyx":360 + /* "pysam/libcbcf.pyx":445 * if val == bcf_int8_missing: * val = bcf_int32_missing * elif val == bcf_int8_vector_end: # <<<<<<<<<<<<<< @@ -7538,7 +8227,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src __pyx_t_9 = ((__pyx_v_val == bcf_int8_vector_end) != 0); if (__pyx_t_9) { - /* "pysam/libcbcf.pyx":361 + /* "pysam/libcbcf.pyx":446 * val = bcf_int32_missing * elif val == bcf_int8_vector_end: * val = bcf_int32_vector_end # <<<<<<<<<<<<<< @@ -7547,7 +8236,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_val = bcf_int32_vector_end; - /* "pysam/libcbcf.pyx":360 + /* "pysam/libcbcf.pyx":445 * if val == bcf_int8_missing: * val = bcf_int32_missing * elif val == bcf_int8_vector_end: # <<<<<<<<<<<<<< @@ -7557,7 +8246,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src } __pyx_L11:; - /* "pysam/libcbcf.pyx":362 + /* "pysam/libcbcf.pyx":447 * elif val == bcf_int8_vector_end: * val = bcf_int32_vector_end * dst_datai[i] = val # <<<<<<<<<<<<<< @@ -7567,7 +8256,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src (__pyx_v_dst_datai[__pyx_v_i]) = __pyx_v_val; } - /* "pysam/libcbcf.pyx":363 + /* "pysam/libcbcf.pyx":448 * val = bcf_int32_vector_end * dst_datai[i] = val * for i in range(src_values, dst_values): # <<<<<<<<<<<<<< @@ -7579,7 +8268,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src for (__pyx_t_12 = __pyx_v_src_values; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_i = __pyx_t_12; - /* "pysam/libcbcf.pyx":364 + /* "pysam/libcbcf.pyx":449 * dst_datai[i] = val * for i in range(src_values, dst_values): * dst_datai[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end # <<<<<<<<<<<<<< @@ -7594,7 +8283,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src (__pyx_v_dst_datai[__pyx_v_i]) = __pyx_t_13; } - /* "pysam/libcbcf.pyx":353 + /* "pysam/libcbcf.pyx":438 * for i in range(src_values, dst_values): * dst_datac[i] = 0 * elif src_type == BCF_BT_INT8 and dst_type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -7604,7 +8293,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src goto __pyx_L4; } - /* "pysam/libcbcf.pyx":365 + /* "pysam/libcbcf.pyx":450 * for i in range(src_values, dst_values): * dst_datai[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end * elif src_type == BCF_BT_INT16 and dst_type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -7622,7 +8311,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src __pyx_L14_bool_binop_done:; if (__pyx_t_9) { - /* "pysam/libcbcf.pyx":366 + /* "pysam/libcbcf.pyx":451 * dst_datai[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end * elif src_type == BCF_BT_INT16 and dst_type == BCF_BT_INT32: * src_datai16 = src_data # <<<<<<<<<<<<<< @@ -7631,7 +8320,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_src_datai16 = ((int16_t *)__pyx_v_src_data); - /* "pysam/libcbcf.pyx":367 + /* "pysam/libcbcf.pyx":452 * elif src_type == BCF_BT_INT16 and dst_type == BCF_BT_INT32: * src_datai16 = src_data * dst_datai = dst_data # <<<<<<<<<<<<<< @@ -7640,7 +8329,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_dst_datai = ((int32_t *)__pyx_v_dst_data); - /* "pysam/libcbcf.pyx":368 + /* "pysam/libcbcf.pyx":453 * src_datai16 = src_data * dst_datai = dst_data * for i in range(src_values): # <<<<<<<<<<<<<< @@ -7652,7 +8341,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_i = __pyx_t_12; - /* "pysam/libcbcf.pyx":369 + /* "pysam/libcbcf.pyx":454 * dst_datai = dst_data * for i in range(src_values): * val = src_datai16[i] # <<<<<<<<<<<<<< @@ -7661,7 +8350,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_val = (__pyx_v_src_datai16[__pyx_v_i]); - /* "pysam/libcbcf.pyx":370 + /* "pysam/libcbcf.pyx":455 * for i in range(src_values): * val = src_datai16[i] * if val == bcf_int16_missing: # <<<<<<<<<<<<<< @@ -7671,7 +8360,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src __pyx_t_9 = ((__pyx_v_val == bcf_int16_missing) != 0); if (__pyx_t_9) { - /* "pysam/libcbcf.pyx":371 + /* "pysam/libcbcf.pyx":456 * val = src_datai16[i] * if val == bcf_int16_missing: * val = bcf_int32_missing # <<<<<<<<<<<<<< @@ -7680,7 +8369,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_val = bcf_int32_missing; - /* "pysam/libcbcf.pyx":370 + /* "pysam/libcbcf.pyx":455 * for i in range(src_values): * val = src_datai16[i] * if val == bcf_int16_missing: # <<<<<<<<<<<<<< @@ -7690,7 +8379,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src goto __pyx_L18; } - /* "pysam/libcbcf.pyx":372 + /* "pysam/libcbcf.pyx":457 * if val == bcf_int16_missing: * val = bcf_int32_missing * elif val == bcf_int16_vector_end: # <<<<<<<<<<<<<< @@ -7700,7 +8389,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src __pyx_t_9 = ((__pyx_v_val == bcf_int16_vector_end) != 0); if (__pyx_t_9) { - /* "pysam/libcbcf.pyx":373 + /* "pysam/libcbcf.pyx":458 * val = bcf_int32_missing * elif val == bcf_int16_vector_end: * val = bcf_int32_vector_end # <<<<<<<<<<<<<< @@ -7709,7 +8398,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_val = bcf_int32_vector_end; - /* "pysam/libcbcf.pyx":372 + /* "pysam/libcbcf.pyx":457 * if val == bcf_int16_missing: * val = bcf_int32_missing * elif val == bcf_int16_vector_end: # <<<<<<<<<<<<<< @@ -7719,7 +8408,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src } __pyx_L18:; - /* "pysam/libcbcf.pyx":374 + /* "pysam/libcbcf.pyx":459 * elif val == bcf_int16_vector_end: * val = bcf_int32_vector_end * dst_datai[i] = val # <<<<<<<<<<<<<< @@ -7729,7 +8418,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src (__pyx_v_dst_datai[__pyx_v_i]) = __pyx_v_val; } - /* "pysam/libcbcf.pyx":375 + /* "pysam/libcbcf.pyx":460 * val = bcf_int32_vector_end * dst_datai[i] = val * for i in range(src_values, dst_values): # <<<<<<<<<<<<<< @@ -7741,7 +8430,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src for (__pyx_t_12 = __pyx_v_src_values; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_i = __pyx_t_12; - /* "pysam/libcbcf.pyx":376 + /* "pysam/libcbcf.pyx":461 * dst_datai[i] = val * for i in range(src_values, dst_values): * dst_datai[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end # <<<<<<<<<<<<<< @@ -7756,7 +8445,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src (__pyx_v_dst_datai[__pyx_v_i]) = __pyx_t_13; } - /* "pysam/libcbcf.pyx":365 + /* "pysam/libcbcf.pyx":450 * for i in range(src_values, dst_values): * dst_datai[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end * elif src_type == BCF_BT_INT16 and dst_type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -7766,7 +8455,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src goto __pyx_L4; } - /* "pysam/libcbcf.pyx":377 + /* "pysam/libcbcf.pyx":462 * for i in range(src_values, dst_values): * dst_datai[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end * elif src_type == BCF_BT_INT32 and dst_type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -7784,7 +8473,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src __pyx_L21_bool_binop_done:; if (__pyx_t_9) { - /* "pysam/libcbcf.pyx":378 + /* "pysam/libcbcf.pyx":463 * dst_datai[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end * elif src_type == BCF_BT_INT32 and dst_type == BCF_BT_INT32: * src_datai32 = src_data # <<<<<<<<<<<<<< @@ -7793,7 +8482,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_src_datai32 = ((int32_t *)__pyx_v_src_data); - /* "pysam/libcbcf.pyx":379 + /* "pysam/libcbcf.pyx":464 * elif src_type == BCF_BT_INT32 and dst_type == BCF_BT_INT32: * src_datai32 = src_data * dst_datai = dst_data # <<<<<<<<<<<<<< @@ -7802,7 +8491,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_dst_datai = ((int32_t *)__pyx_v_dst_data); - /* "pysam/libcbcf.pyx":380 + /* "pysam/libcbcf.pyx":465 * src_datai32 = src_data * dst_datai = dst_data * for i in range(src_values): # <<<<<<<<<<<<<< @@ -7814,7 +8503,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_i = __pyx_t_12; - /* "pysam/libcbcf.pyx":381 + /* "pysam/libcbcf.pyx":466 * dst_datai = dst_data * for i in range(src_values): * dst_datai[i] = src_datai32[i] # <<<<<<<<<<<<<< @@ -7824,7 +8513,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src (__pyx_v_dst_datai[__pyx_v_i]) = (__pyx_v_src_datai32[__pyx_v_i]); } - /* "pysam/libcbcf.pyx":382 + /* "pysam/libcbcf.pyx":467 * for i in range(src_values): * dst_datai[i] = src_datai32[i] * for i in range(src_values, dst_values): # <<<<<<<<<<<<<< @@ -7836,7 +8525,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src for (__pyx_t_12 = __pyx_v_src_values; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_i = __pyx_t_12; - /* "pysam/libcbcf.pyx":383 + /* "pysam/libcbcf.pyx":468 * dst_datai[i] = src_datai32[i] * for i in range(src_values, dst_values): * dst_datai[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end # <<<<<<<<<<<<<< @@ -7851,7 +8540,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src (__pyx_v_dst_datai[__pyx_v_i]) = __pyx_t_13; } - /* "pysam/libcbcf.pyx":377 + /* "pysam/libcbcf.pyx":462 * for i in range(src_values, dst_values): * dst_datai[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end * elif src_type == BCF_BT_INT32 and dst_type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -7861,7 +8550,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src goto __pyx_L4; } - /* "pysam/libcbcf.pyx":384 + /* "pysam/libcbcf.pyx":469 * for i in range(src_values, dst_values): * dst_datai[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end * elif src_type == BCF_BT_FLOAT and dst_type == BCF_BT_FLOAT: # <<<<<<<<<<<<<< @@ -7879,7 +8568,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src __pyx_L27_bool_binop_done:; if (likely(__pyx_t_9)) { - /* "pysam/libcbcf.pyx":385 + /* "pysam/libcbcf.pyx":470 * dst_datai[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end * elif src_type == BCF_BT_FLOAT and dst_type == BCF_BT_FLOAT: * src_dataf = src_data # <<<<<<<<<<<<<< @@ -7888,7 +8577,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_src_dataf = ((float *)__pyx_v_src_data); - /* "pysam/libcbcf.pyx":386 + /* "pysam/libcbcf.pyx":471 * elif src_type == BCF_BT_FLOAT and dst_type == BCF_BT_FLOAT: * src_dataf = src_data * dst_dataf = dst_data # <<<<<<<<<<<<<< @@ -7897,7 +8586,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src */ __pyx_v_dst_dataf = ((float *)__pyx_v_dst_data); - /* "pysam/libcbcf.pyx":387 + /* "pysam/libcbcf.pyx":472 * src_dataf = src_data * dst_dataf = dst_data * for i in range(src_values): # <<<<<<<<<<<<<< @@ -7909,7 +8598,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_i = __pyx_t_12; - /* "pysam/libcbcf.pyx":388 + /* "pysam/libcbcf.pyx":473 * dst_dataf = dst_data * for i in range(src_values): * dst_dataf[i] = src_dataf[i] # <<<<<<<<<<<<<< @@ -7919,7 +8608,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src (__pyx_v_dst_dataf[__pyx_v_i]) = (__pyx_v_src_dataf[__pyx_v_i]); } - /* "pysam/libcbcf.pyx":389 + /* "pysam/libcbcf.pyx":474 * for i in range(src_values): * dst_dataf[i] = src_dataf[i] * for i in range(src_values, dst_values): # <<<<<<<<<<<<<< @@ -7931,7 +8620,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src for (__pyx_t_12 = __pyx_v_src_values; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_i = __pyx_t_12; - /* "pysam/libcbcf.pyx":390 + /* "pysam/libcbcf.pyx":475 * dst_dataf[i] = src_dataf[i] * for i in range(src_values, dst_values): * bcf_float_set(dst_dataf + i, bcf_float_missing if not vlen else bcf_float_vector_end) # <<<<<<<<<<<<<< @@ -7946,7 +8635,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src bcf_float_set((__pyx_v_dst_dataf + __pyx_v_i), __pyx_t_14); } - /* "pysam/libcbcf.pyx":384 + /* "pysam/libcbcf.pyx":469 * for i in range(src_values, dst_values): * dst_datai[i] = bcf_int32_missing if not vlen else bcf_int32_vector_end * elif src_type == BCF_BT_FLOAT and dst_type == BCF_BT_FLOAT: # <<<<<<<<<<<<<< @@ -7956,7 +8645,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src goto __pyx_L4; } - /* "pysam/libcbcf.pyx":392 + /* "pysam/libcbcf.pyx":477 * bcf_float_set(dst_dataf + i, bcf_float_missing if not vlen else bcf_float_vector_end) * else: * raise TypeError('unsupported types') # <<<<<<<<<<<<<< @@ -7964,15 +8653,15 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src * */ /*else*/ { - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 392, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 477, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 392, __pyx_L1_error) + __PYX_ERR(0, 477, __pyx_L1_error) } __pyx_L4:; - /* "pysam/libcbcf.pyx":330 + /* "pysam/libcbcf.pyx":415 * * * cdef bcf_copy_expand_array(void *src_data, int src_type, ssize_t src_values, # <<<<<<<<<<<<<< @@ -7999,15 +8688,15 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_copy_expand_array(void *__pyx_v_src return __pyx_r; } -/* "pysam/libcbcf.pyx":395 +/* "pysam/libcbcf.pyx":480 * * - * cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar): # <<<<<<<<<<<<<< + * cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar, int sample): # <<<<<<<<<<<<<< * if record is None: * raise ValueError('record must not be None') */ -static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record, int __pyx_v_hl_type, int __pyx_v_id, Py_ssize_t *__pyx_v_count, int *__pyx_v_scalar) { +static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record, int __pyx_v_hl_type, int __pyx_v_id, Py_ssize_t *__pyx_v_count, int *__pyx_v_scalar, int __pyx_v_sample) { bcf_hdr_t *__pyx_v_hdr; bcf1_t *__pyx_v_r; int __pyx_v_length; @@ -8021,12 +8710,13 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p bcf_hdr_t *__pyx_t_4; bcf1_t *__pyx_t_5; uint32_t __pyx_t_6; + int __pyx_t_7; __Pyx_RefNannySetupContext("bcf_get_value_count", 0); - __Pyx_TraceCall("bcf_get_value_count", __pyx_f[0], 395, 0, __PYX_ERR(0, 395, __pyx_L1_error)); + __Pyx_TraceCall("bcf_get_value_count", __pyx_f[0], 480, 0, __PYX_ERR(0, 480, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":396 + /* "pysam/libcbcf.pyx":481 * - * cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar): + * cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar, int sample): * if record is None: # <<<<<<<<<<<<<< * raise ValueError('record must not be None') * @@ -8035,29 +8725,29 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":397 - * cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar): + /* "pysam/libcbcf.pyx":482 + * cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar, int sample): * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = record.header.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 397, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 482, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 397, __pyx_L1_error) + __PYX_ERR(0, 482, __pyx_L1_error) - /* "pysam/libcbcf.pyx":396 + /* "pysam/libcbcf.pyx":481 * - * cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar): + * cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar, int sample): * if record is None: # <<<<<<<<<<<<<< * raise ValueError('record must not be None') * */ } - /* "pysam/libcbcf.pyx":399 + /* "pysam/libcbcf.pyx":484 * raise ValueError('record must not be None') * * cdef bcf_hdr_t *hdr = record.header.ptr # <<<<<<<<<<<<<< @@ -8067,7 +8757,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p __pyx_t_4 = __pyx_v_record->header->ptr; __pyx_v_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":400 + /* "pysam/libcbcf.pyx":485 * * cdef bcf_hdr_t *hdr = record.header.ptr * cdef bcf1_t *r = record.ptr # <<<<<<<<<<<<<< @@ -8077,7 +8767,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p __pyx_t_5 = __pyx_v_record->ptr; __pyx_v_r = __pyx_t_5; - /* "pysam/libcbcf.pyx":402 + /* "pysam/libcbcf.pyx":487 * cdef bcf1_t *r = record.ptr * * if not check_header_id(hdr, hl_type, id): # <<<<<<<<<<<<<< @@ -8087,20 +8777,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p __pyx_t_2 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, __pyx_v_hl_type, __pyx_v_id) != 0)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":403 + /* "pysam/libcbcf.pyx":488 * * if not check_header_id(hdr, hl_type, id): * raise ValueError('Invalid header') # <<<<<<<<<<<<<< * * cdef int length = bcf_hdr_id2length(hdr, hl_type, id) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 403, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 403, __pyx_L1_error) + __PYX_ERR(0, 488, __pyx_L1_error) - /* "pysam/libcbcf.pyx":402 + /* "pysam/libcbcf.pyx":487 * cdef bcf1_t *r = record.ptr * * if not check_header_id(hdr, hl_type, id): # <<<<<<<<<<<<<< @@ -8109,7 +8799,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p */ } - /* "pysam/libcbcf.pyx":405 + /* "pysam/libcbcf.pyx":490 * raise ValueError('Invalid header') * * cdef int length = bcf_hdr_id2length(hdr, hl_type, id) # <<<<<<<<<<<<<< @@ -8118,7 +8808,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p */ __pyx_v_length = bcf_hdr_id2length(__pyx_v_hdr, __pyx_v_hl_type, __pyx_v_id); - /* "pysam/libcbcf.pyx":406 + /* "pysam/libcbcf.pyx":491 * * cdef int length = bcf_hdr_id2length(hdr, hl_type, id) * cdef int number = bcf_hdr_id2number(hdr, hl_type, id) # <<<<<<<<<<<<<< @@ -8127,7 +8817,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p */ __pyx_v_number = bcf_hdr_id2number(__pyx_v_hdr, __pyx_v_hl_type, __pyx_v_id); - /* "pysam/libcbcf.pyx":408 + /* "pysam/libcbcf.pyx":493 * cdef int number = bcf_hdr_id2number(hdr, hl_type, id) * * scalar[0] = 0 # <<<<<<<<<<<<<< @@ -8136,7 +8826,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p */ (__pyx_v_scalar[0]) = 0; - /* "pysam/libcbcf.pyx":410 + /* "pysam/libcbcf.pyx":495 * scalar[0] = 0 * * if hl_type == BCF_HL_FMT and is_gt_fmt(hdr, id): # <<<<<<<<<<<<<< @@ -8154,7 +8844,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p __pyx_L6_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":411 + /* "pysam/libcbcf.pyx":496 * * if hl_type == BCF_HL_FMT and is_gt_fmt(hdr, id): * count[0] = number # <<<<<<<<<<<<<< @@ -8163,7 +8853,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p */ (__pyx_v_count[0]) = __pyx_v_number; - /* "pysam/libcbcf.pyx":410 + /* "pysam/libcbcf.pyx":495 * scalar[0] = 0 * * if hl_type == BCF_HL_FMT and is_gt_fmt(hdr, id): # <<<<<<<<<<<<<< @@ -8173,7 +8863,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p goto __pyx_L5; } - /* "pysam/libcbcf.pyx":412 + /* "pysam/libcbcf.pyx":497 * if hl_type == BCF_HL_FMT and is_gt_fmt(hdr, id): * count[0] = number * elif length == BCF_VL_FIXED: # <<<<<<<<<<<<<< @@ -8183,7 +8873,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p __pyx_t_2 = ((__pyx_v_length == BCF_VL_FIXED) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":413 + /* "pysam/libcbcf.pyx":498 * count[0] = number * elif length == BCF_VL_FIXED: * if number == 1: # <<<<<<<<<<<<<< @@ -8193,7 +8883,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p __pyx_t_2 = ((__pyx_v_number == 1) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":414 + /* "pysam/libcbcf.pyx":499 * elif length == BCF_VL_FIXED: * if number == 1: * scalar[0] = 1 # <<<<<<<<<<<<<< @@ -8202,7 +8892,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p */ (__pyx_v_scalar[0]) = 1; - /* "pysam/libcbcf.pyx":413 + /* "pysam/libcbcf.pyx":498 * count[0] = number * elif length == BCF_VL_FIXED: * if number == 1: # <<<<<<<<<<<<<< @@ -8211,7 +8901,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p */ } - /* "pysam/libcbcf.pyx":415 + /* "pysam/libcbcf.pyx":500 * if number == 1: * scalar[0] = 1 * count[0] = number # <<<<<<<<<<<<<< @@ -8220,7 +8910,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p */ (__pyx_v_count[0]) = __pyx_v_number; - /* "pysam/libcbcf.pyx":412 + /* "pysam/libcbcf.pyx":497 * if hl_type == BCF_HL_FMT and is_gt_fmt(hdr, id): * count[0] = number * elif length == BCF_VL_FIXED: # <<<<<<<<<<<<<< @@ -8230,7 +8920,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p goto __pyx_L5; } - /* "pysam/libcbcf.pyx":416 + /* "pysam/libcbcf.pyx":501 * scalar[0] = 1 * count[0] = number * elif length == BCF_VL_R: # <<<<<<<<<<<<<< @@ -8240,7 +8930,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p __pyx_t_2 = ((__pyx_v_length == BCF_VL_R) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":417 + /* "pysam/libcbcf.pyx":502 * count[0] = number * elif length == BCF_VL_R: * count[0] = r.n_allele # <<<<<<<<<<<<<< @@ -8250,7 +8940,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p __pyx_t_6 = __pyx_v_r->n_allele; (__pyx_v_count[0]) = __pyx_t_6; - /* "pysam/libcbcf.pyx":416 + /* "pysam/libcbcf.pyx":501 * scalar[0] = 1 * count[0] = number * elif length == BCF_VL_R: # <<<<<<<<<<<<<< @@ -8260,7 +8950,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p goto __pyx_L5; } - /* "pysam/libcbcf.pyx":418 + /* "pysam/libcbcf.pyx":503 * elif length == BCF_VL_R: * count[0] = r.n_allele * elif length == BCF_VL_A: # <<<<<<<<<<<<<< @@ -8270,16 +8960,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p __pyx_t_2 = ((__pyx_v_length == BCF_VL_A) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":419 + /* "pysam/libcbcf.pyx":504 * count[0] = r.n_allele * elif length == BCF_VL_A: * count[0] = r.n_allele - 1 # <<<<<<<<<<<<<< * elif length == BCF_VL_G: - * count[0] = r.n_allele * (r.n_allele + 1) // 2 + * count[0] = bcf_genotype_count(hdr, r, sample) */ (__pyx_v_count[0]) = (__pyx_v_r->n_allele - 1); - /* "pysam/libcbcf.pyx":418 + /* "pysam/libcbcf.pyx":503 * elif length == BCF_VL_R: * count[0] = r.n_allele * elif length == BCF_VL_A: # <<<<<<<<<<<<<< @@ -8289,38 +8979,39 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p goto __pyx_L5; } - /* "pysam/libcbcf.pyx":420 + /* "pysam/libcbcf.pyx":505 * elif length == BCF_VL_A: * count[0] = r.n_allele - 1 * elif length == BCF_VL_G: # <<<<<<<<<<<<<< - * count[0] = r.n_allele * (r.n_allele + 1) // 2 + * count[0] = bcf_genotype_count(hdr, r, sample) * elif length == BCF_VL_VAR: */ __pyx_t_2 = ((__pyx_v_length == BCF_VL_G) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":421 + /* "pysam/libcbcf.pyx":506 * count[0] = r.n_allele - 1 * elif length == BCF_VL_G: - * count[0] = r.n_allele * (r.n_allele + 1) // 2 # <<<<<<<<<<<<<< + * count[0] = bcf_genotype_count(hdr, r, sample) # <<<<<<<<<<<<<< * elif length == BCF_VL_VAR: * count[0] = -1 */ - (__pyx_v_count[0]) = __Pyx_div_long((__pyx_v_r->n_allele * (__pyx_v_r->n_allele + 1)), 2); + __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_genotype_count(__pyx_v_hdr, __pyx_v_r, __pyx_v_sample); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 506, __pyx_L1_error) + (__pyx_v_count[0]) = __pyx_t_7; - /* "pysam/libcbcf.pyx":420 + /* "pysam/libcbcf.pyx":505 * elif length == BCF_VL_A: * count[0] = r.n_allele - 1 * elif length == BCF_VL_G: # <<<<<<<<<<<<<< - * count[0] = r.n_allele * (r.n_allele + 1) // 2 + * count[0] = bcf_genotype_count(hdr, r, sample) * elif length == BCF_VL_VAR: */ goto __pyx_L5; } - /* "pysam/libcbcf.pyx":422 + /* "pysam/libcbcf.pyx":507 * elif length == BCF_VL_G: - * count[0] = r.n_allele * (r.n_allele + 1) // 2 + * count[0] = bcf_genotype_count(hdr, r, sample) * elif length == BCF_VL_VAR: # <<<<<<<<<<<<<< * count[0] = -1 * else: @@ -8328,8 +9019,8 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p __pyx_t_2 = ((__pyx_v_length == BCF_VL_VAR) != 0); if (likely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":423 - * count[0] = r.n_allele * (r.n_allele + 1) // 2 + /* "pysam/libcbcf.pyx":508 + * count[0] = bcf_genotype_count(hdr, r, sample) * elif length == BCF_VL_VAR: * count[0] = -1 # <<<<<<<<<<<<<< * else: @@ -8337,9 +9028,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p */ (__pyx_v_count[0]) = -1L; - /* "pysam/libcbcf.pyx":422 + /* "pysam/libcbcf.pyx":507 * elif length == BCF_VL_G: - * count[0] = r.n_allele * (r.n_allele + 1) // 2 + * count[0] = bcf_genotype_count(hdr, r, sample) * elif length == BCF_VL_VAR: # <<<<<<<<<<<<<< * count[0] = -1 * else: @@ -8347,7 +9038,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p goto __pyx_L5; } - /* "pysam/libcbcf.pyx":425 + /* "pysam/libcbcf.pyx":510 * count[0] = -1 * else: * raise ValueError('Unknown format length') # <<<<<<<<<<<<<< @@ -8355,18 +9046,18 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p * */ /*else*/ { - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 425, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 510, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 425, __pyx_L1_error) + __PYX_ERR(0, 510, __pyx_L1_error) } __pyx_L5:; - /* "pysam/libcbcf.pyx":395 + /* "pysam/libcbcf.pyx":480 * * - * cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar): # <<<<<<<<<<<<<< + * cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar, int sample): # <<<<<<<<<<<<<< * if record is None: * raise ValueError('record must not be None') */ @@ -8385,7 +9076,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_get_value_count(struct __pyx_obj_5p return __pyx_r; } -/* "pysam/libcbcf.pyx":428 +/* "pysam/libcbcf.pyx":513 * * * cdef object bcf_info_get_value(VariantRecord record, const bcf_info_t *z): # <<<<<<<<<<<<<< @@ -8407,9 +9098,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py bcf_hdr_t *__pyx_t_4; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("bcf_info_get_value", 0); - __Pyx_TraceCall("bcf_info_get_value", __pyx_f[0], 428, 0, __PYX_ERR(0, 428, __pyx_L1_error)); + __Pyx_TraceCall("bcf_info_get_value", __pyx_f[0], 513, 0, __PYX_ERR(0, 513, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":429 + /* "pysam/libcbcf.pyx":514 * * cdef object bcf_info_get_value(VariantRecord record, const bcf_info_t *z): * if record is None: # <<<<<<<<<<<<<< @@ -8420,20 +9111,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":430 + /* "pysam/libcbcf.pyx":515 * cdef object bcf_info_get_value(VariantRecord record, const bcf_info_t *z): * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = record.header.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 430, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 515, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 430, __pyx_L1_error) + __PYX_ERR(0, 515, __pyx_L1_error) - /* "pysam/libcbcf.pyx":429 + /* "pysam/libcbcf.pyx":514 * * cdef object bcf_info_get_value(VariantRecord record, const bcf_info_t *z): * if record is None: # <<<<<<<<<<<<<< @@ -8442,7 +9133,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":432 + /* "pysam/libcbcf.pyx":517 * raise ValueError('record must not be None') * * cdef bcf_hdr_t *hdr = record.header.ptr # <<<<<<<<<<<<<< @@ -8452,19 +9143,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_t_4 = __pyx_v_record->header->ptr; __pyx_v_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":438 + /* "pysam/libcbcf.pyx":523 * cdef int scalar * - * bcf_get_value_count(record, BCF_HL_INFO, z.key, &count, &scalar) # <<<<<<<<<<<<<< + * bcf_get_value_count(record, BCF_HL_INFO, z.key, &count, &scalar, -1) # <<<<<<<<<<<<<< * * if z.len == 0: */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_get_value_count(__pyx_v_record, BCF_HL_INFO, __pyx_v_z->key, (&__pyx_v_count), (&__pyx_v_scalar)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 438, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_get_value_count(__pyx_v_record, BCF_HL_INFO, __pyx_v_z->key, (&__pyx_v_count), (&__pyx_v_scalar), -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 523, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":440 - * bcf_get_value_count(record, BCF_HL_INFO, z.key, &count, &scalar) + /* "pysam/libcbcf.pyx":525 + * bcf_get_value_count(record, BCF_HL_INFO, z.key, &count, &scalar, -1) * * if z.len == 0: # <<<<<<<<<<<<<< * if bcf_hdr_id2type(hdr, BCF_HL_INFO, z.key) == BCF_HT_FLAG: @@ -8473,7 +9164,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py switch (__pyx_v_z->len) { case 0: - /* "pysam/libcbcf.pyx":441 + /* "pysam/libcbcf.pyx":526 * * if z.len == 0: * if bcf_hdr_id2type(hdr, BCF_HL_INFO, z.key) == BCF_HT_FLAG: # <<<<<<<<<<<<<< @@ -8483,7 +9174,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_t_2 = ((bcf_hdr_id2type(__pyx_v_hdr, BCF_HL_INFO, __pyx_v_z->key) == BCF_HT_FLAG) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":442 + /* "pysam/libcbcf.pyx":527 * if z.len == 0: * if bcf_hdr_id2type(hdr, BCF_HL_INFO, z.key) == BCF_HT_FLAG: * value = True # <<<<<<<<<<<<<< @@ -8493,7 +9184,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __Pyx_INCREF(Py_True); __pyx_v_value = Py_True; - /* "pysam/libcbcf.pyx":441 + /* "pysam/libcbcf.pyx":526 * * if z.len == 0: * if bcf_hdr_id2type(hdr, BCF_HL_INFO, z.key) == BCF_HT_FLAG: # <<<<<<<<<<<<<< @@ -8503,7 +9194,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py goto __pyx_L4; } - /* "pysam/libcbcf.pyx":443 + /* "pysam/libcbcf.pyx":528 * if bcf_hdr_id2type(hdr, BCF_HL_INFO, z.key) == BCF_HT_FLAG: * value = True * elif scalar: # <<<<<<<<<<<<<< @@ -8513,7 +9204,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_t_2 = (__pyx_v_scalar != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":444 + /* "pysam/libcbcf.pyx":529 * value = True * elif scalar: * value = None # <<<<<<<<<<<<<< @@ -8523,7 +9214,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __Pyx_INCREF(Py_None); __pyx_v_value = Py_None; - /* "pysam/libcbcf.pyx":443 + /* "pysam/libcbcf.pyx":528 * if bcf_hdr_id2type(hdr, BCF_HL_INFO, z.key) == BCF_HT_FLAG: * value = True * elif scalar: # <<<<<<<<<<<<<< @@ -8533,7 +9224,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py goto __pyx_L4; } - /* "pysam/libcbcf.pyx":446 + /* "pysam/libcbcf.pyx":531 * value = None * else: * value = () # <<<<<<<<<<<<<< @@ -8546,8 +9237,8 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py } __pyx_L4:; - /* "pysam/libcbcf.pyx":440 - * bcf_get_value_count(record, BCF_HL_INFO, z.key, &count, &scalar) + /* "pysam/libcbcf.pyx":525 + * bcf_get_value_count(record, BCF_HL_INFO, z.key, &count, &scalar, -1) * * if z.len == 0: # <<<<<<<<<<<<<< * if bcf_hdr_id2type(hdr, BCF_HL_INFO, z.key) == BCF_HT_FLAG: @@ -8555,7 +9246,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py */ break; - /* "pysam/libcbcf.pyx":447 + /* "pysam/libcbcf.pyx":532 * else: * value = () * elif z.len == 1: # <<<<<<<<<<<<<< @@ -8564,7 +9255,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py */ case 1: - /* "pysam/libcbcf.pyx":448 + /* "pysam/libcbcf.pyx":533 * value = () * elif z.len == 1: * if z.type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -8574,7 +9265,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_t_2 = ((__pyx_v_z->type == BCF_BT_INT8) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":449 + /* "pysam/libcbcf.pyx":534 * elif z.len == 1: * if z.type == BCF_BT_INT8: * value = z.v1.i if z.v1.i != bcf_int8_missing else None # <<<<<<<<<<<<<< @@ -8582,7 +9273,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py * value = z.v1.i if z.v1.i != bcf_int16_missing else None */ if (((__pyx_v_z->v1.i != bcf_int8_missing) != 0)) { - __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_z->v1.i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 449, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_z->v1.i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 534, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __pyx_t_5; __pyx_t_5 = 0; @@ -8593,7 +9284,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_v_value = __pyx_t_3; __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":448 + /* "pysam/libcbcf.pyx":533 * value = () * elif z.len == 1: * if z.type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -8603,7 +9294,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py goto __pyx_L5; } - /* "pysam/libcbcf.pyx":450 + /* "pysam/libcbcf.pyx":535 * if z.type == BCF_BT_INT8: * value = z.v1.i if z.v1.i != bcf_int8_missing else None * elif z.type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -8613,7 +9304,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_t_2 = ((__pyx_v_z->type == BCF_BT_INT16) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":451 + /* "pysam/libcbcf.pyx":536 * value = z.v1.i if z.v1.i != bcf_int8_missing else None * elif z.type == BCF_BT_INT16: * value = z.v1.i if z.v1.i != bcf_int16_missing else None # <<<<<<<<<<<<<< @@ -8621,7 +9312,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py * value = z.v1.i if z.v1.i != bcf_int32_missing else None */ if (((__pyx_v_z->v1.i != bcf_int16_missing) != 0)) { - __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_z->v1.i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 451, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_z->v1.i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 536, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __pyx_t_5; __pyx_t_5 = 0; @@ -8632,7 +9323,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_v_value = __pyx_t_3; __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":450 + /* "pysam/libcbcf.pyx":535 * if z.type == BCF_BT_INT8: * value = z.v1.i if z.v1.i != bcf_int8_missing else None * elif z.type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -8642,7 +9333,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py goto __pyx_L5; } - /* "pysam/libcbcf.pyx":452 + /* "pysam/libcbcf.pyx":537 * elif z.type == BCF_BT_INT16: * value = z.v1.i if z.v1.i != bcf_int16_missing else None * elif z.type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -8652,7 +9343,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_t_2 = ((__pyx_v_z->type == BCF_BT_INT32) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":453 + /* "pysam/libcbcf.pyx":538 * value = z.v1.i if z.v1.i != bcf_int16_missing else None * elif z.type == BCF_BT_INT32: * value = z.v1.i if z.v1.i != bcf_int32_missing else None # <<<<<<<<<<<<<< @@ -8660,7 +9351,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py * value = z.v1.f if not bcf_float_is_missing(z.v1.f) else None */ if (((__pyx_v_z->v1.i != bcf_int32_missing) != 0)) { - __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_z->v1.i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 453, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_z->v1.i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 538, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __pyx_t_5; __pyx_t_5 = 0; @@ -8671,7 +9362,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_v_value = __pyx_t_3; __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":452 + /* "pysam/libcbcf.pyx":537 * elif z.type == BCF_BT_INT16: * value = z.v1.i if z.v1.i != bcf_int16_missing else None * elif z.type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -8681,7 +9372,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py goto __pyx_L5; } - /* "pysam/libcbcf.pyx":454 + /* "pysam/libcbcf.pyx":539 * elif z.type == BCF_BT_INT32: * value = z.v1.i if z.v1.i != bcf_int32_missing else None * elif z.type == BCF_BT_FLOAT: # <<<<<<<<<<<<<< @@ -8691,7 +9382,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_t_2 = ((__pyx_v_z->type == BCF_BT_FLOAT) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":455 + /* "pysam/libcbcf.pyx":540 * value = z.v1.i if z.v1.i != bcf_int32_missing else None * elif z.type == BCF_BT_FLOAT: * value = z.v1.f if not bcf_float_is_missing(z.v1.f) else None # <<<<<<<<<<<<<< @@ -8699,7 +9390,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py * value = force_str(chr(z.v1.i)) */ if (((!(bcf_float_is_missing(__pyx_v_z->v1.f) != 0)) != 0)) { - __pyx_t_5 = PyFloat_FromDouble(__pyx_v_z->v1.f); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 455, __pyx_L1_error) + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_z->v1.f); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 540, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __pyx_t_5; __pyx_t_5 = 0; @@ -8710,7 +9401,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_v_value = __pyx_t_3; __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":454 + /* "pysam/libcbcf.pyx":539 * elif z.type == BCF_BT_INT32: * value = z.v1.i if z.v1.i != bcf_int32_missing else None * elif z.type == BCF_BT_FLOAT: # <<<<<<<<<<<<<< @@ -8720,7 +9411,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py goto __pyx_L5; } - /* "pysam/libcbcf.pyx":456 + /* "pysam/libcbcf.pyx":541 * elif z.type == BCF_BT_FLOAT: * value = z.v1.f if not bcf_float_is_missing(z.v1.f) else None * elif z.type == BCF_BT_CHAR: # <<<<<<<<<<<<<< @@ -8730,25 +9421,25 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_t_2 = ((__pyx_v_z->type == BCF_BT_CHAR) != 0); if (likely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":457 + /* "pysam/libcbcf.pyx":542 * value = z.v1.f if not bcf_float_is_missing(z.v1.f) else None * elif z.type == BCF_BT_CHAR: * value = force_str(chr(z.v1.i)) # <<<<<<<<<<<<<< * else: * raise TypeError('unsupported info type code') */ - __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_z->v1.i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 457, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_z->v1.i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 542, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 457, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 542, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 457, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 542, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_value = __pyx_t_3; __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":456 + /* "pysam/libcbcf.pyx":541 * elif z.type == BCF_BT_FLOAT: * value = z.v1.f if not bcf_float_is_missing(z.v1.f) else None * elif z.type == BCF_BT_CHAR: # <<<<<<<<<<<<<< @@ -8758,7 +9449,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py goto __pyx_L5; } - /* "pysam/libcbcf.pyx":459 + /* "pysam/libcbcf.pyx":544 * value = force_str(chr(z.v1.i)) * else: * raise TypeError('unsupported info type code') # <<<<<<<<<<<<<< @@ -8766,15 +9457,15 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py * if not scalar and value != (): */ /*else*/ { - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 459, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 544, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 459, __pyx_L1_error) + __PYX_ERR(0, 544, __pyx_L1_error) } __pyx_L5:; - /* "pysam/libcbcf.pyx":461 + /* "pysam/libcbcf.pyx":546 * raise TypeError('unsupported info type code') * * if not scalar and value != (): # <<<<<<<<<<<<<< @@ -8787,21 +9478,21 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_t_2 = __pyx_t_1; goto __pyx_L7_bool_binop_done; } - __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_empty_tuple, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 461, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 461, __pyx_L1_error) + __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_empty_tuple, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 546, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 546, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_2 = __pyx_t_1; __pyx_L7_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":462 + /* "pysam/libcbcf.pyx":547 * * if not scalar and value != (): * value = (value,) # <<<<<<<<<<<<<< * else: * value = bcf_array_to_object(z.vptr, z.type, z.len, count, scalar) */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 462, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 547, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); @@ -8809,7 +9500,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":461 + /* "pysam/libcbcf.pyx":546 * raise TypeError('unsupported info type code') * * if not scalar and value != (): # <<<<<<<<<<<<<< @@ -8818,7 +9509,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":447 + /* "pysam/libcbcf.pyx":532 * else: * value = () * elif z.len == 1: # <<<<<<<<<<<<<< @@ -8828,21 +9519,21 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py break; default: - /* "pysam/libcbcf.pyx":464 + /* "pysam/libcbcf.pyx":549 * value = (value,) * else: * value = bcf_array_to_object(z.vptr, z.type, z.len, count, scalar) # <<<<<<<<<<<<<< * * return value */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_array_to_object(__pyx_v_z->vptr, __pyx_v_z->type, __pyx_v_z->len, __pyx_v_count, __pyx_v_scalar); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 464, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_array_to_object(__pyx_v_z->vptr, __pyx_v_z->type, __pyx_v_z->len, __pyx_v_count, __pyx_v_scalar); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 549, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_value = __pyx_t_3; __pyx_t_3 = 0; break; } - /* "pysam/libcbcf.pyx":466 + /* "pysam/libcbcf.pyx":551 * value = bcf_array_to_object(z.vptr, z.type, z.len, count, scalar) * * return value # <<<<<<<<<<<<<< @@ -8854,7 +9545,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py __pyx_r = __pyx_v_value; goto __pyx_L0; - /* "pysam/libcbcf.pyx":428 + /* "pysam/libcbcf.pyx":513 * * * cdef object bcf_info_get_value(VariantRecord record, const bcf_info_t *z): # <<<<<<<<<<<<<< @@ -8877,7 +9568,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_get_value(struct __pyx_obj_5py } static PyObject *__pyx_gb_5pysam_7libcbcf_16bcf_check_values_2generator31(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":506 +/* "pysam/libcbcf.pyx":593 * raise ValueError('Integer value too small/large to store in VCF/BCF') * elif ht_type == BCF_HT_STR: * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) # <<<<<<<<<<<<<< @@ -8894,7 +9585,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_16bcf_check_values_genexpr(PyObject *_ if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_7_genexpr *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 506, __pyx_L1_error) + __PYX_ERR(0, 593, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -8902,7 +9593,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_16bcf_check_values_genexpr(PyObject *_ __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_16bcf_check_values_2generator31, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_bcf_check_values_locals_genexpr, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 506, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_16bcf_check_values_2generator31, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_bcf_check_values_locals_genexpr, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 593, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -8931,7 +9622,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_16bcf_check_values_2generator31(__pyx_ PyObject *__pyx_t_6 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("genexpr", 0); - __Pyx_TraceCall("genexpr", __pyx_f[0], 506, 0, __PYX_ERR(0, 506, __pyx_L1_error)); + __Pyx_TraceCall("genexpr", __pyx_f[0], 593, 0, __PYX_ERR(0, 593, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -8941,32 +9632,32 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_16bcf_check_values_2generator31(__pyx_ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 506, __pyx_L1_error) - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_values)) { __Pyx_RaiseClosureNameError("values"); __PYX_ERR(0, 506, __pyx_L1_error) } + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 593, __pyx_L1_error) + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_values)) { __Pyx_RaiseClosureNameError("values"); __PYX_ERR(0, 593, __pyx_L1_error) } if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_values)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_values)) { __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_values; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 506, __pyx_L1_error) + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 593, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 506, __pyx_L1_error) + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 593, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_3)) { if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 506, __pyx_L1_error) + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 593, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 506, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 593, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } else { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 506, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 593, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 506, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 593, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } @@ -8976,7 +9667,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_16bcf_check_values_2generator31(__pyx_ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 506, __pyx_L1_error) + else __PYX_ERR(0, 593, __pyx_L1_error) } break; } @@ -8988,13 +9679,13 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_16bcf_check_values_2generator31(__pyx_ __pyx_t_4 = 0; __pyx_t_5 = (__pyx_cur_scope->__pyx_v_v != Py_None); if ((__pyx_t_5 != 0)) { - __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_cur_scope->__pyx_v_v, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 506, __pyx_L1_error) + __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_cur_scope->__pyx_v_v, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 593, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_4 = __pyx_t_6; __pyx_t_6 = 0; } else { - __Pyx_INCREF(__pyx_kp_b__5); - __pyx_t_4 = __pyx_kp_b__5; + __Pyx_INCREF(__pyx_kp_b__15); + __pyx_t_4 = __pyx_kp_b__15; } __pyx_r = __pyx_t_4; __pyx_t_4 = 0; @@ -9015,7 +9706,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_16bcf_check_values_2generator31(__pyx_ __Pyx_XGOTREF(__pyx_t_1); __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 506, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 593, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); @@ -9038,16 +9729,17 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_16bcf_check_values_2generator31(__pyx_ return __pyx_r; } -/* "pysam/libcbcf.pyx":469 +/* "pysam/libcbcf.pyx":554 * * - * cdef object bcf_check_values(VariantRecord record, value, int hl_type, int ht_type, # <<<<<<<<<<<<<< + * cdef object bcf_check_values(VariantRecord record, value, int sample, # <<<<<<<<<<<<<< + * int hl_type, int ht_type, * int id, int bt_type, ssize_t bt_len, - * ssize_t *value_count, int *scalar, int *realloc): */ -static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record, PyObject *__pyx_v_value, int __pyx_v_hl_type, int __pyx_v_ht_type, int __pyx_v_id, int __pyx_v_bt_type, Py_ssize_t __pyx_v_bt_len, Py_ssize_t *__pyx_v_value_count, int *__pyx_v_scalar, int *__pyx_v_realloc) { +static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record, PyObject *__pyx_v_value, int __pyx_v_sample, int __pyx_v_hl_type, int __pyx_v_ht_type, int __pyx_v_id, int __pyx_v_bt_type, Py_ssize_t __pyx_v_bt_len, Py_ssize_t *__pyx_v_value_count, int *__pyx_v_scalar, int *__pyx_v_realloc) { struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values *__pyx_cur_scope; + int __pyx_v_given; PyObject *__pyx_v_v = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations @@ -9061,20 +9753,22 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; - PyObject *(*__pyx_t_10)(PyObject *); - int __pyx_t_11; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + PyObject *(*__pyx_t_12)(PyObject *); + int __pyx_t_13; __Pyx_RefNannySetupContext("bcf_check_values", 0); __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 469, __pyx_L1_error) + __PYX_ERR(0, 554, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } - __Pyx_TraceCall("bcf_check_values", __pyx_f[0], 469, 0, __PYX_ERR(0, 469, __pyx_L1_error)); + __Pyx_TraceCall("bcf_check_values", __pyx_f[0], 554, 0, __PYX_ERR(0, 554, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":473 + /* "pysam/libcbcf.pyx":559 * ssize_t *value_count, int *scalar, int *realloc): * * if record is None: # <<<<<<<<<<<<<< @@ -9085,20 +9779,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":474 + /* "pysam/libcbcf.pyx":560 * * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * - * bcf_get_value_count(record, hl_type, id, value_count, scalar) + * bcf_get_value_count(record, hl_type, id, value_count, scalar, sample) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 474, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 474, __pyx_L1_error) + __PYX_ERR(0, 560, __pyx_L1_error) - /* "pysam/libcbcf.pyx":473 + /* "pysam/libcbcf.pyx":559 * ssize_t *value_count, int *scalar, int *realloc): * * if record is None: # <<<<<<<<<<<<<< @@ -9107,18 +9801,18 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ } - /* "pysam/libcbcf.pyx":476 + /* "pysam/libcbcf.pyx":562 * raise ValueError('record must not be None') * - * bcf_get_value_count(record, hl_type, id, value_count, scalar) # <<<<<<<<<<<<<< + * bcf_get_value_count(record, hl_type, id, value_count, scalar, sample) # <<<<<<<<<<<<<< * * # Validate values now that we know the type and size */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_get_value_count(__pyx_v_record, __pyx_v_hl_type, __pyx_v_id, __pyx_v_value_count, __pyx_v_scalar); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 476, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_get_value_count(__pyx_v_record, __pyx_v_hl_type, __pyx_v_id, __pyx_v_value_count, __pyx_v_scalar, __pyx_v_sample); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 562, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":479 + /* "pysam/libcbcf.pyx":565 * * # Validate values now that we know the type and size * values = (value,) if not isinstance(value, (list, tuple)) else value # <<<<<<<<<<<<<< @@ -9137,7 +9831,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_2 = __pyx_t_1; __pyx_L4_bool_binop_done:; if (((!(__pyx_t_2 != 0)) != 0)) { - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 479, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 565, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); @@ -9152,7 +9846,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_cur_scope->__pyx_v_values = __pyx_t_3; __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":482 + /* "pysam/libcbcf.pyx":568 * * # Validate values now that we know the type and size * if ht_type == BCF_HT_FLAG: # <<<<<<<<<<<<<< @@ -9162,7 +9856,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_2 = ((__pyx_v_ht_type == BCF_HT_FLAG) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":483 + /* "pysam/libcbcf.pyx":569 * # Validate values now that we know the type and size * if ht_type == BCF_HT_FLAG: * value_count[0] = 1 # <<<<<<<<<<<<<< @@ -9171,7 +9865,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ (__pyx_v_value_count[0]) = 1; - /* "pysam/libcbcf.pyx":482 + /* "pysam/libcbcf.pyx":568 * * # Validate values now that we know the type and size * if ht_type == BCF_HT_FLAG: # <<<<<<<<<<<<<< @@ -9181,7 +9875,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa goto __pyx_L6; } - /* "pysam/libcbcf.pyx":484 + /* "pysam/libcbcf.pyx":570 * if ht_type == BCF_HT_FLAG: * value_count[0] = 1 * elif hl_type == BCF_HL_FMT and is_gt_fmt(record.header.ptr, id): # <<<<<<<<<<<<<< @@ -9199,16 +9893,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_L7_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":486 + /* "pysam/libcbcf.pyx":572 * elif hl_type == BCF_HL_FMT and is_gt_fmt(record.header.ptr, id): * # KBJ: htslib lies about the cardinality of GT fields-- they're really VLEN (-1) * value_count[0] = -1 # <<<<<<<<<<<<<< * - * if value_count[0] != -1 and value_count[0] != len(values): + * cdef int given = len(values) */ (__pyx_v_value_count[0]) = -1L; - /* "pysam/libcbcf.pyx":484 + /* "pysam/libcbcf.pyx":570 * if ht_type == BCF_HT_FLAG: * value_count[0] = 1 * elif hl_type == BCF_HL_FMT and is_gt_fmt(record.header.ptr, id): # <<<<<<<<<<<<<< @@ -9218,12 +9912,25 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa } __pyx_L6:; - /* "pysam/libcbcf.pyx":488 + /* "pysam/libcbcf.pyx":574 * value_count[0] = -1 * - * if value_count[0] != -1 and value_count[0] != len(values): # <<<<<<<<<<<<<< + * cdef int given = len(values) # <<<<<<<<<<<<<< + * if value_count[0] != -1 and value_count[0] != given: + * if scalar[0]: + */ + __pyx_t_3 = __pyx_cur_scope->__pyx_v_values; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_6 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 574, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_given = __pyx_t_6; + + /* "pysam/libcbcf.pyx":575 + * + * cdef int given = len(values) + * if value_count[0] != -1 and value_count[0] != given: # <<<<<<<<<<<<<< * if scalar[0]: - * raise TypeError('value expected to be scalar'.format(value_count[0])) + * raise TypeError('value expected to be scalar, given len={}'.format(value_count[0], given)) */ __pyx_t_1 = (((__pyx_v_value_count[0]) != -1L) != 0); if (__pyx_t_1) { @@ -9231,111 +9938,115 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_2 = __pyx_t_1; goto __pyx_L10_bool_binop_done; } - __pyx_t_3 = __pyx_cur_scope->__pyx_v_values; - __Pyx_INCREF(__pyx_t_3); - __pyx_t_6 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 488, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = (((__pyx_v_value_count[0]) != __pyx_t_6) != 0); + __pyx_t_1 = (((__pyx_v_value_count[0]) != __pyx_v_given) != 0); __pyx_t_2 = __pyx_t_1; __pyx_L10_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":489 - * - * if value_count[0] != -1 and value_count[0] != len(values): + /* "pysam/libcbcf.pyx":576 + * cdef int given = len(values) + * if value_count[0] != -1 and value_count[0] != given: * if scalar[0]: # <<<<<<<<<<<<<< - * raise TypeError('value expected to be scalar'.format(value_count[0])) + * raise TypeError('value expected to be scalar, given len={}'.format(value_count[0], given)) * else: */ __pyx_t_2 = ((__pyx_v_scalar[0]) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":490 - * if value_count[0] != -1 and value_count[0] != len(values): + /* "pysam/libcbcf.pyx":577 + * if value_count[0] != -1 and value_count[0] != given: * if scalar[0]: - * raise TypeError('value expected to be scalar'.format(value_count[0])) # <<<<<<<<<<<<<< + * raise TypeError('value expected to be scalar, given len={}'.format(value_count[0], given)) # <<<<<<<<<<<<<< * else: - * raise TypeError('values expected to be {:d}-tuple'.format(value_count[0])) + * raise TypeError('values expected to be {}-tuple, given len={}'.format(value_count[0], given)) */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_value_expected_to_be_scalar, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 490, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_value_expected_to_be_scalar_give, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = PyInt_FromSsize_t((__pyx_v_value_count[0])); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 490, __pyx_L1_error) + __pyx_t_7 = PyInt_FromSsize_t((__pyx_v_value_count[0])); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = NULL; + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_given); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 577, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = NULL; + __pyx_t_10 = 0; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_8)) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_9)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_10 = 1; } } - if (!__pyx_t_8) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 490, __pyx_L1_error) + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 577, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 577, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 490, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 490, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 490, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 490, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 577, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL; } + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_8); + __pyx_t_7 = 0; + __pyx_t_8 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 577, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 490, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 490, __pyx_L1_error) + __PYX_ERR(0, 577, __pyx_L1_error) - /* "pysam/libcbcf.pyx":489 - * - * if value_count[0] != -1 and value_count[0] != len(values): + /* "pysam/libcbcf.pyx":576 + * cdef int given = len(values) + * if value_count[0] != -1 and value_count[0] != given: * if scalar[0]: # <<<<<<<<<<<<<< - * raise TypeError('value expected to be scalar'.format(value_count[0])) + * raise TypeError('value expected to be scalar, given len={}'.format(value_count[0], given)) * else: */ } - /* "pysam/libcbcf.pyx":492 - * raise TypeError('value expected to be scalar'.format(value_count[0])) + /* "pysam/libcbcf.pyx":579 + * raise TypeError('value expected to be scalar, given len={}'.format(value_count[0], given)) * else: - * raise TypeError('values expected to be {:d}-tuple'.format(value_count[0])) # <<<<<<<<<<<<<< + * raise TypeError('values expected to be {}-tuple, given len={}'.format(value_count[0], given)) # <<<<<<<<<<<<<< * * if ht_type == BCF_HT_REAL: */ /*else*/ { - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_values_expected_to_be_d_tuple, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 492, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_values_expected_to_be_tuple_give, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 579, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = PyInt_FromSsize_t((__pyx_v_value_count[0])); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 492, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = PyInt_FromSsize_t((__pyx_v_value_count[0])); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_given); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); __pyx_t_7 = NULL; + __pyx_t_10 = 0; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_7)) { @@ -9343,63 +10054,65 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_10 = 1; } } - if (!__pyx_t_7) { - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 492, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_11, __pyx_t_8}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_5); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_9}; - __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 492, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_9}; - __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 492, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - { - __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 492, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL; - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 492, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_11, __pyx_t_8}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; } + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_10, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_10, __pyx_t_8); + __pyx_t_11 = 0; + __pyx_t_8 = 0; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 492, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 579, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 492, __pyx_L1_error) + __PYX_ERR(0, 579, __pyx_L1_error) } - /* "pysam/libcbcf.pyx":488 - * value_count[0] = -1 + /* "pysam/libcbcf.pyx":575 * - * if value_count[0] != -1 and value_count[0] != len(values): # <<<<<<<<<<<<<< + * cdef int given = len(values) + * if value_count[0] != -1 and value_count[0] != given: # <<<<<<<<<<<<<< * if scalar[0]: - * raise TypeError('value expected to be scalar'.format(value_count[0])) + * raise TypeError('value expected to be scalar, given len={}'.format(value_count[0], given)) */ } - /* "pysam/libcbcf.pyx":494 - * raise TypeError('values expected to be {:d}-tuple'.format(value_count[0])) + /* "pysam/libcbcf.pyx":581 + * raise TypeError('values expected to be {}-tuple, given len={}'.format(value_count[0], given)) * * if ht_type == BCF_HT_REAL: # <<<<<<<<<<<<<< * for v in values: @@ -9408,7 +10121,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_2 = ((__pyx_v_ht_type == BCF_HT_REAL) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":495 + /* "pysam/libcbcf.pyx":582 * * if ht_type == BCF_HT_REAL: * for v in values: # <<<<<<<<<<<<<< @@ -9417,38 +10130,38 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_values)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_values)) { __pyx_t_3 = __pyx_cur_scope->__pyx_v_values; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; - __pyx_t_10 = NULL; + __pyx_t_12 = NULL; } else { - __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 495, __pyx_L1_error) + __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 495, __pyx_L1_error) + __pyx_t_12 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 582, __pyx_L1_error) } for (;;) { - if (likely(!__pyx_t_10)) { + if (likely(!__pyx_t_12)) { if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 495, __pyx_L1_error) + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 582, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 495, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif } else { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 495, __pyx_L1_error) + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 582, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 495, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif } } else { - __pyx_t_5 = __pyx_t_10(__pyx_t_3); + __pyx_t_5 = __pyx_t_12(__pyx_t_3); if (unlikely(!__pyx_t_5)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 495, __pyx_L1_error) + else __PYX_ERR(0, 582, __pyx_L1_error) } break; } @@ -9457,7 +10170,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcbcf.pyx":496 + /* "pysam/libcbcf.pyx":583 * if ht_type == BCF_HT_REAL: * for v in values: * if not(v is None or isinstance(v, (float, int))): # <<<<<<<<<<<<<< @@ -9472,14 +10185,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa goto __pyx_L17_bool_binop_done; } __pyx_t_1 = PyFloat_Check(__pyx_v_v); - __pyx_t_11 = (__pyx_t_1 != 0); - if (!__pyx_t_11) { + __pyx_t_13 = (__pyx_t_1 != 0); + if (!__pyx_t_13) { } else { - __pyx_t_4 = __pyx_t_11; + __pyx_t_4 = __pyx_t_13; goto __pyx_L19_bool_binop_done; } - __pyx_t_11 = PyInt_Check(__pyx_v_v); - __pyx_t_1 = (__pyx_t_11 != 0); + __pyx_t_13 = PyInt_Check(__pyx_v_v); + __pyx_t_1 = (__pyx_t_13 != 0); __pyx_t_4 = __pyx_t_1; __pyx_L19_bool_binop_done:; __pyx_t_1 = (__pyx_t_4 != 0); @@ -9488,20 +10201,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_1 = ((!__pyx_t_2) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":497 + /* "pysam/libcbcf.pyx":584 * for v in values: * if not(v is None or isinstance(v, (float, int))): * raise TypeError('invalid value for Float format') # <<<<<<<<<<<<<< * elif ht_type == BCF_HT_INT: * for v in values: */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 497, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 497, __pyx_L1_error) + __PYX_ERR(0, 584, __pyx_L1_error) - /* "pysam/libcbcf.pyx":496 + /* "pysam/libcbcf.pyx":583 * if ht_type == BCF_HT_REAL: * for v in values: * if not(v is None or isinstance(v, (float, int))): # <<<<<<<<<<<<<< @@ -9510,7 +10223,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ } - /* "pysam/libcbcf.pyx":495 + /* "pysam/libcbcf.pyx":582 * * if ht_type == BCF_HT_REAL: * for v in values: # <<<<<<<<<<<<<< @@ -9520,8 +10233,8 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":494 - * raise TypeError('values expected to be {:d}-tuple'.format(value_count[0])) + /* "pysam/libcbcf.pyx":581 + * raise TypeError('values expected to be {}-tuple, given len={}'.format(value_count[0], given)) * * if ht_type == BCF_HT_REAL: # <<<<<<<<<<<<<< * for v in values: @@ -9530,7 +10243,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa goto __pyx_L13; } - /* "pysam/libcbcf.pyx":498 + /* "pysam/libcbcf.pyx":585 * if not(v is None or isinstance(v, (float, int))): * raise TypeError('invalid value for Float format') * elif ht_type == BCF_HT_INT: # <<<<<<<<<<<<<< @@ -9540,7 +10253,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_1 = ((__pyx_v_ht_type == BCF_HT_INT) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":499 + /* "pysam/libcbcf.pyx":586 * raise TypeError('invalid value for Float format') * elif ht_type == BCF_HT_INT: * for v in values: # <<<<<<<<<<<<<< @@ -9549,38 +10262,38 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_values)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_values)) { __pyx_t_3 = __pyx_cur_scope->__pyx_v_values; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; - __pyx_t_10 = NULL; + __pyx_t_12 = NULL; } else { - __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 499, __pyx_L1_error) + __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 586, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 499, __pyx_L1_error) + __pyx_t_12 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 586, __pyx_L1_error) } for (;;) { - if (likely(!__pyx_t_10)) { + if (likely(!__pyx_t_12)) { if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 499, __pyx_L1_error) + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 586, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 499, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 586, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif } else { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 499, __pyx_L1_error) + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 586, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 499, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 586, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif } } else { - __pyx_t_5 = __pyx_t_10(__pyx_t_3); + __pyx_t_5 = __pyx_t_12(__pyx_t_3); if (unlikely(!__pyx_t_5)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 499, __pyx_L1_error) + else __PYX_ERR(0, 586, __pyx_L1_error) } break; } @@ -9589,7 +10302,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcbcf.pyx":500 + /* "pysam/libcbcf.pyx":587 * elif ht_type == BCF_HT_INT: * for v in values: * if not(v is None or (isinstance(v, (float, int)) and int(v) == v)): # <<<<<<<<<<<<<< @@ -9604,14 +10317,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa goto __pyx_L24_bool_binop_done; } __pyx_t_2 = PyFloat_Check(__pyx_v_v); - __pyx_t_11 = (__pyx_t_2 != 0); - if (!__pyx_t_11) { + __pyx_t_13 = (__pyx_t_2 != 0); + if (!__pyx_t_13) { } else { - __pyx_t_4 = __pyx_t_11; + __pyx_t_4 = __pyx_t_13; goto __pyx_L27_bool_binop_done; } - __pyx_t_11 = PyInt_Check(__pyx_v_v); - __pyx_t_2 = (__pyx_t_11 != 0); + __pyx_t_13 = PyInt_Check(__pyx_v_v); + __pyx_t_2 = (__pyx_t_13 != 0); __pyx_t_4 = __pyx_t_2; __pyx_L27_bool_binop_done:; __pyx_t_2 = (__pyx_t_4 != 0); @@ -9620,31 +10333,31 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_1 = __pyx_t_2; goto __pyx_L24_bool_binop_done; } - __pyx_t_5 = __Pyx_PyNumber_Int(__pyx_v_v); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 500, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyNumber_Int(__pyx_v_v); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 587, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, __pyx_v_v, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 500, __pyx_L1_error) + __pyx_t_9 = PyObject_RichCompare(__pyx_t_5, __pyx_v_v, Py_EQ); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 587, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 587, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_1 = __pyx_t_2; __pyx_L24_bool_binop_done:; __pyx_t_2 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":501 + /* "pysam/libcbcf.pyx":588 * for v in values: * if not(v is None or (isinstance(v, (float, int)) and int(v) == v)): * raise TypeError('invalid value for Integer format') # <<<<<<<<<<<<<< * for v in values: * if not(v is None or bcf_int32_missing < v <= INT32_MAX): */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 501, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 588, __pyx_L1_error) - /* "pysam/libcbcf.pyx":500 + /* "pysam/libcbcf.pyx":587 * elif ht_type == BCF_HT_INT: * for v in values: * if not(v is None or (isinstance(v, (float, int)) and int(v) == v)): # <<<<<<<<<<<<<< @@ -9653,7 +10366,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ } - /* "pysam/libcbcf.pyx":499 + /* "pysam/libcbcf.pyx":586 * raise TypeError('invalid value for Float format') * elif ht_type == BCF_HT_INT: * for v in values: # <<<<<<<<<<<<<< @@ -9663,7 +10376,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":502 + /* "pysam/libcbcf.pyx":589 * if not(v is None or (isinstance(v, (float, int)) and int(v) == v)): * raise TypeError('invalid value for Integer format') * for v in values: # <<<<<<<<<<<<<< @@ -9672,47 +10385,47 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_values)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_values)) { __pyx_t_3 = __pyx_cur_scope->__pyx_v_values; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; - __pyx_t_10 = NULL; + __pyx_t_12 = NULL; } else { - __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 502, __pyx_L1_error) + __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 589, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 502, __pyx_L1_error) + __pyx_t_12 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 589, __pyx_L1_error) } for (;;) { - if (likely(!__pyx_t_10)) { + if (likely(!__pyx_t_12)) { if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 502, __pyx_L1_error) + __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_9); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 589, __pyx_L1_error) #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 589, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); #endif } else { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 502, __pyx_L1_error) + __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_9); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 589, __pyx_L1_error) #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 589, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); #endif } } else { - __pyx_t_8 = __pyx_t_10(__pyx_t_3); - if (unlikely(!__pyx_t_8)) { + __pyx_t_9 = __pyx_t_12(__pyx_t_3); + if (unlikely(!__pyx_t_9)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 502, __pyx_L1_error) + else __PYX_ERR(0, 589, __pyx_L1_error) } break; } - __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_9); } - __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_8); - __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_9); + __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":503 + /* "pysam/libcbcf.pyx":590 * raise TypeError('invalid value for Integer format') * for v in values: * if not(v is None or bcf_int32_missing < v <= INT32_MAX): # <<<<<<<<<<<<<< @@ -9726,38 +10439,38 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_2 = __pyx_t_4; goto __pyx_L32_bool_binop_done; } - __pyx_t_8 = __Pyx_PyInt_From_int32_t(bcf_int32_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = PyObject_RichCompare(__pyx_t_8, __pyx_v_v, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 503, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_From_int32_t(bcf_int32_missing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 590, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_9, __pyx_v_v, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 590, __pyx_L1_error) if (__Pyx_PyObject_IsTrue(__pyx_t_5)) { __Pyx_DECREF(__pyx_t_5); - __pyx_t_9 = __Pyx_PyInt_From_int32_t(INT32_MAX); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 503, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_v, __pyx_t_9, Py_LE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 503, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_8 = __Pyx_PyInt_From_int32_t(INT32_MAX); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 590, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_v, __pyx_t_8, Py_LE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 590, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 503, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 590, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_2 = __pyx_t_4; __pyx_L32_bool_binop_done:; __pyx_t_4 = ((!__pyx_t_2) != 0); if (unlikely(__pyx_t_4)) { - /* "pysam/libcbcf.pyx":504 + /* "pysam/libcbcf.pyx":591 * for v in values: * if not(v is None or bcf_int32_missing < v <= INT32_MAX): * raise ValueError('Integer value too small/large to store in VCF/BCF') # <<<<<<<<<<<<<< * elif ht_type == BCF_HT_STR: * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 504, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 591, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 504, __pyx_L1_error) + __PYX_ERR(0, 591, __pyx_L1_error) - /* "pysam/libcbcf.pyx":503 + /* "pysam/libcbcf.pyx":590 * raise TypeError('invalid value for Integer format') * for v in values: * if not(v is None or bcf_int32_missing < v <= INT32_MAX): # <<<<<<<<<<<<<< @@ -9766,7 +10479,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ } - /* "pysam/libcbcf.pyx":502 + /* "pysam/libcbcf.pyx":589 * if not(v is None or (isinstance(v, (float, int)) and int(v) == v)): * raise TypeError('invalid value for Integer format') * for v in values: # <<<<<<<<<<<<<< @@ -9776,7 +10489,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":498 + /* "pysam/libcbcf.pyx":585 * if not(v is None or isinstance(v, (float, int))): * raise TypeError('invalid value for Float format') * elif ht_type == BCF_HT_INT: # <<<<<<<<<<<<<< @@ -9786,7 +10499,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa goto __pyx_L13; } - /* "pysam/libcbcf.pyx":505 + /* "pysam/libcbcf.pyx":592 * if not(v is None or bcf_int32_missing < v <= INT32_MAX): * raise ValueError('Integer value too small/large to store in VCF/BCF') * elif ht_type == BCF_HT_STR: # <<<<<<<<<<<<<< @@ -9796,16 +10509,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_4 = ((__pyx_v_ht_type == BCF_HT_STR) != 0); if (__pyx_t_4) { - /* "pysam/libcbcf.pyx":506 + /* "pysam/libcbcf.pyx":593 * raise ValueError('Integer value too small/large to store in VCF/BCF') * elif ht_type == BCF_HT_STR: * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) # <<<<<<<<<<<<<< * elif ht_type == BCF_HT_FLAG: * if values[0] not in (True, False, None, 1, 0): */ - __pyx_t_3 = __pyx_pf_5pysam_7libcbcf_16bcf_check_values_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 506, __pyx_L1_error) + __pyx_t_3 = __pyx_pf_5pysam_7libcbcf_16bcf_check_values_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 593, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyBytes_Join(__pyx_kp_b_, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 506, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyBytes_Join(__pyx_kp_b__2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 593, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_values); @@ -9813,7 +10526,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcbcf.pyx":505 + /* "pysam/libcbcf.pyx":592 * if not(v is None or bcf_int32_missing < v <= INT32_MAX): * raise ValueError('Integer value too small/large to store in VCF/BCF') * elif ht_type == BCF_HT_STR: # <<<<<<<<<<<<<< @@ -9823,7 +10536,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa goto __pyx_L13; } - /* "pysam/libcbcf.pyx":507 + /* "pysam/libcbcf.pyx":594 * elif ht_type == BCF_HT_STR: * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) * elif ht_type == BCF_HT_FLAG: # <<<<<<<<<<<<<< @@ -9833,49 +10546,49 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_4 = ((__pyx_v_ht_type == BCF_HT_FLAG) != 0); if (likely(__pyx_t_4)) { - /* "pysam/libcbcf.pyx":508 + /* "pysam/libcbcf.pyx":595 * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) * elif ht_type == BCF_HT_FLAG: * if values[0] not in (True, False, None, 1, 0): # <<<<<<<<<<<<<< * raise ValueError('Flag values must be: True, False, None, 1, 0') * else: */ - __pyx_t_5 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_values, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 508, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_values, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, Py_True, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 508, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 508, __pyx_L1_error) + __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, Py_True, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { } else { __pyx_t_4 = __pyx_t_2; goto __pyx_L35_bool_binop_done; } - __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, Py_False, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 508, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 508, __pyx_L1_error) + __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, Py_False, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { } else { __pyx_t_4 = __pyx_t_2; goto __pyx_L35_bool_binop_done; } - __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 508, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 508, __pyx_L1_error) + __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { } else { __pyx_t_4 = __pyx_t_2; goto __pyx_L35_bool_binop_done; } - __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_int_1, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 508, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 508, __pyx_L1_error) + __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_int_1, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { } else { __pyx_t_4 = __pyx_t_2; goto __pyx_L35_bool_binop_done; } - __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 508, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 508, __pyx_L1_error) + __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_4 = __pyx_t_2; __pyx_L35_bool_binop_done:; @@ -9883,20 +10596,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_2 = (__pyx_t_4 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":509 + /* "pysam/libcbcf.pyx":596 * elif ht_type == BCF_HT_FLAG: * if values[0] not in (True, False, None, 1, 0): * raise ValueError('Flag values must be: True, False, None, 1, 0') # <<<<<<<<<<<<<< * else: * raise TypeError('unsupported type') */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 509, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 596, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 509, __pyx_L1_error) + __PYX_ERR(0, 596, __pyx_L1_error) - /* "pysam/libcbcf.pyx":508 + /* "pysam/libcbcf.pyx":595 * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) * elif ht_type == BCF_HT_FLAG: * if values[0] not in (True, False, None, 1, 0): # <<<<<<<<<<<<<< @@ -9905,7 +10618,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ } - /* "pysam/libcbcf.pyx":507 + /* "pysam/libcbcf.pyx":594 * elif ht_type == BCF_HT_STR: * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) * elif ht_type == BCF_HT_FLAG: # <<<<<<<<<<<<<< @@ -9915,7 +10628,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa goto __pyx_L13; } - /* "pysam/libcbcf.pyx":511 + /* "pysam/libcbcf.pyx":598 * raise ValueError('Flag values must be: True, False, None, 1, 0') * else: * raise TypeError('unsupported type') # <<<<<<<<<<<<<< @@ -9923,15 +10636,15 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa * realloc[0] = 0 */ /*else*/ { - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 511, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 598, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 511, __pyx_L1_error) + __PYX_ERR(0, 598, __pyx_L1_error) } __pyx_L13:; - /* "pysam/libcbcf.pyx":513 + /* "pysam/libcbcf.pyx":600 * raise TypeError('unsupported type') * * realloc[0] = 0 # <<<<<<<<<<<<<< @@ -9940,7 +10653,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ (__pyx_v_realloc[0]) = 0; - /* "pysam/libcbcf.pyx":514 + /* "pysam/libcbcf.pyx":601 * * realloc[0] = 0 * if len(values) <= 1 and hl_type == BCF_HL_INFO: # <<<<<<<<<<<<<< @@ -9949,7 +10662,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ __pyx_t_5 = __pyx_cur_scope->__pyx_v_values; __Pyx_INCREF(__pyx_t_5); - __pyx_t_6 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 514, __pyx_L1_error) + __pyx_t_6 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_4 = ((__pyx_t_6 <= 1) != 0); if (__pyx_t_4) { @@ -9962,7 +10675,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_L41_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":515 + /* "pysam/libcbcf.pyx":602 * realloc[0] = 0 * if len(values) <= 1 and hl_type == BCF_HL_INFO: * realloc[0] = 0 # <<<<<<<<<<<<<< @@ -9971,7 +10684,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ (__pyx_v_realloc[0]) = 0; - /* "pysam/libcbcf.pyx":514 + /* "pysam/libcbcf.pyx":601 * * realloc[0] = 0 * if len(values) <= 1 and hl_type == BCF_HL_INFO: # <<<<<<<<<<<<<< @@ -9981,7 +10694,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa goto __pyx_L40; } - /* "pysam/libcbcf.pyx":516 + /* "pysam/libcbcf.pyx":603 * if len(values) <= 1 and hl_type == BCF_HL_INFO: * realloc[0] = 0 * elif len(values) > bt_len: # <<<<<<<<<<<<<< @@ -9990,12 +10703,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ __pyx_t_5 = __pyx_cur_scope->__pyx_v_values; __Pyx_INCREF(__pyx_t_5); - __pyx_t_6 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 516, __pyx_L1_error) + __pyx_t_6 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 603, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_2 = ((__pyx_t_6 > __pyx_v_bt_len) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":517 + /* "pysam/libcbcf.pyx":604 * realloc[0] = 0 * elif len(values) > bt_len: * realloc[0] = 1 # <<<<<<<<<<<<<< @@ -10004,7 +10717,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ (__pyx_v_realloc[0]) = 1; - /* "pysam/libcbcf.pyx":516 + /* "pysam/libcbcf.pyx":603 * if len(values) <= 1 and hl_type == BCF_HL_INFO: * realloc[0] = 0 * elif len(values) > bt_len: # <<<<<<<<<<<<<< @@ -10014,7 +10727,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa goto __pyx_L40; } - /* "pysam/libcbcf.pyx":518 + /* "pysam/libcbcf.pyx":605 * elif len(values) > bt_len: * realloc[0] = 1 * elif bt_type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -10024,7 +10737,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_2 = ((__pyx_v_bt_type == BCF_BT_INT8) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":519 + /* "pysam/libcbcf.pyx":606 * realloc[0] = 1 * elif bt_type == BCF_BT_INT8: * for v in values: # <<<<<<<<<<<<<< @@ -10033,38 +10746,38 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_values)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_values)) { __pyx_t_5 = __pyx_cur_scope->__pyx_v_values; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; - __pyx_t_10 = NULL; + __pyx_t_12 = NULL; } else { - __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 519, __pyx_L1_error) + __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 606, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_10 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 519, __pyx_L1_error) + __pyx_t_12 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 606, __pyx_L1_error) } for (;;) { - if (likely(!__pyx_t_10)) { + if (likely(!__pyx_t_12)) { if (likely(PyList_CheckExact(__pyx_t_5))) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 519, __pyx_L1_error) + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 606, __pyx_L1_error) #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 519, __pyx_L1_error) + __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 606, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); #endif } else { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 519, __pyx_L1_error) + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 606, __pyx_L1_error) #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 519, __pyx_L1_error) + __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 606, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); #endif } } else { - __pyx_t_3 = __pyx_t_10(__pyx_t_5); + __pyx_t_3 = __pyx_t_12(__pyx_t_5); if (unlikely(!__pyx_t_3)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 519, __pyx_L1_error) + else __PYX_ERR(0, 606, __pyx_L1_error) } break; } @@ -10073,7 +10786,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":520 + /* "pysam/libcbcf.pyx":607 * elif bt_type == BCF_BT_INT8: * for v in values: * if v is not None and not(bcf_int8_missing < v <= INT8_MAX): # <<<<<<<<<<<<<< @@ -10087,25 +10800,25 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_2 = __pyx_t_1; goto __pyx_L46_bool_binop_done; } - __pyx_t_3 = __Pyx_PyInt_From_int32_t(bcf_int8_missing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 520, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int32_t(bcf_int8_missing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 607, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = PyObject_RichCompare(__pyx_t_3, __pyx_v_v, Py_LT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 520, __pyx_L1_error) - if (__Pyx_PyObject_IsTrue(__pyx_t_8)) { - __Pyx_DECREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyInt_From_int8_t(INT8_MAX); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 520, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = PyObject_RichCompare(__pyx_v_v, __pyx_t_9, Py_LE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 520, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyObject_RichCompare(__pyx_t_3, __pyx_v_v, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 607, __pyx_L1_error) + if (__Pyx_PyObject_IsTrue(__pyx_t_9)) { + __Pyx_DECREF(__pyx_t_9); + __pyx_t_8 = __Pyx_PyInt_From_int8_t(INT8_MAX); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 607, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyObject_RichCompare(__pyx_v_v, __pyx_t_8, Py_LE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 607, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 520, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 607, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_4 = ((!__pyx_t_1) != 0); __pyx_t_2 = __pyx_t_4; __pyx_L46_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":521 + /* "pysam/libcbcf.pyx":608 * for v in values: * if v is not None and not(bcf_int8_missing < v <= INT8_MAX): * realloc[0] = 1 # <<<<<<<<<<<<<< @@ -10114,7 +10827,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ (__pyx_v_realloc[0]) = 1; - /* "pysam/libcbcf.pyx":522 + /* "pysam/libcbcf.pyx":609 * if v is not None and not(bcf_int8_missing < v <= INT8_MAX): * realloc[0] = 1 * break # <<<<<<<<<<<<<< @@ -10123,7 +10836,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ goto __pyx_L44_break; - /* "pysam/libcbcf.pyx":520 + /* "pysam/libcbcf.pyx":607 * elif bt_type == BCF_BT_INT8: * for v in values: * if v is not None and not(bcf_int8_missing < v <= INT8_MAX): # <<<<<<<<<<<<<< @@ -10132,7 +10845,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ } - /* "pysam/libcbcf.pyx":519 + /* "pysam/libcbcf.pyx":606 * realloc[0] = 1 * elif bt_type == BCF_BT_INT8: * for v in values: # <<<<<<<<<<<<<< @@ -10143,7 +10856,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_L44_break:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcbcf.pyx":518 + /* "pysam/libcbcf.pyx":605 * elif len(values) > bt_len: * realloc[0] = 1 * elif bt_type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -10153,7 +10866,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa goto __pyx_L40; } - /* "pysam/libcbcf.pyx":523 + /* "pysam/libcbcf.pyx":610 * realloc[0] = 1 * break * elif bt_type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -10163,7 +10876,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_2 = ((__pyx_v_bt_type == BCF_BT_INT16) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":524 + /* "pysam/libcbcf.pyx":611 * break * elif bt_type == BCF_BT_INT16: * for v in values: # <<<<<<<<<<<<<< @@ -10172,47 +10885,47 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_values)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_values)) { __pyx_t_5 = __pyx_cur_scope->__pyx_v_values; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; - __pyx_t_10 = NULL; + __pyx_t_12 = NULL; } else { - __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 524, __pyx_L1_error) + __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 611, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_10 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 524, __pyx_L1_error) + __pyx_t_12 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 611, __pyx_L1_error) } for (;;) { - if (likely(!__pyx_t_10)) { + if (likely(!__pyx_t_12)) { if (likely(PyList_CheckExact(__pyx_t_5))) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 524, __pyx_L1_error) + __pyx_t_9 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_9); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 611, __pyx_L1_error) #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 611, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); #endif } else { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 524, __pyx_L1_error) + __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_9); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 611, __pyx_L1_error) #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 524, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 611, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); #endif } } else { - __pyx_t_8 = __pyx_t_10(__pyx_t_5); - if (unlikely(!__pyx_t_8)) { + __pyx_t_9 = __pyx_t_12(__pyx_t_5); + if (unlikely(!__pyx_t_9)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 524, __pyx_L1_error) + else __PYX_ERR(0, 611, __pyx_L1_error) } break; } - __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_9); } - __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_8); - __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_9); + __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":525 + /* "pysam/libcbcf.pyx":612 * elif bt_type == BCF_BT_INT16: * for v in values: * if v is not None and not(bcf_int16_missing < v <= INT16_MAX): # <<<<<<<<<<<<<< @@ -10226,25 +10939,25 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_t_2 = __pyx_t_1; goto __pyx_L51_bool_binop_done; } - __pyx_t_8 = __Pyx_PyInt_From_int32_t(bcf_int16_missing); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_8, __pyx_v_v, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 525, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_From_int32_t(bcf_int16_missing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_3 = PyObject_RichCompare(__pyx_t_9, __pyx_v_v, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 612, __pyx_L1_error) if (__Pyx_PyObject_IsTrue(__pyx_t_3)) { __Pyx_DECREF(__pyx_t_3); - __pyx_t_9 = __Pyx_PyInt_From_int16_t(INT16_MAX); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_v, __pyx_t_9, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 525, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_8 = __Pyx_PyInt_From_int16_t(INT16_MAX); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_v, __pyx_t_8, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 612, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 525, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 612, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_4 = ((!__pyx_t_1) != 0); __pyx_t_2 = __pyx_t_4; __pyx_L51_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":526 + /* "pysam/libcbcf.pyx":613 * for v in values: * if v is not None and not(bcf_int16_missing < v <= INT16_MAX): * realloc[0] = 1 # <<<<<<<<<<<<<< @@ -10253,7 +10966,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ (__pyx_v_realloc[0]) = 1; - /* "pysam/libcbcf.pyx":527 + /* "pysam/libcbcf.pyx":614 * if v is not None and not(bcf_int16_missing < v <= INT16_MAX): * realloc[0] = 1 * break # <<<<<<<<<<<<<< @@ -10262,7 +10975,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ goto __pyx_L49_break; - /* "pysam/libcbcf.pyx":525 + /* "pysam/libcbcf.pyx":612 * elif bt_type == BCF_BT_INT16: * for v in values: * if v is not None and not(bcf_int16_missing < v <= INT16_MAX): # <<<<<<<<<<<<<< @@ -10271,7 +10984,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa */ } - /* "pysam/libcbcf.pyx":524 + /* "pysam/libcbcf.pyx":611 * break * elif bt_type == BCF_BT_INT16: * for v in values: # <<<<<<<<<<<<<< @@ -10282,7 +10995,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_L49_break:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcbcf.pyx":523 + /* "pysam/libcbcf.pyx":610 * realloc[0] = 1 * break * elif bt_type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -10292,7 +11005,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa } __pyx_L40:; - /* "pysam/libcbcf.pyx":529 + /* "pysam/libcbcf.pyx":616 * break * * return values # <<<<<<<<<<<<<< @@ -10304,12 +11017,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __pyx_r = __pyx_cur_scope->__pyx_v_values; goto __pyx_L0; - /* "pysam/libcbcf.pyx":469 + /* "pysam/libcbcf.pyx":554 * * - * cdef object bcf_check_values(VariantRecord record, value, int hl_type, int ht_type, # <<<<<<<<<<<<<< + * cdef object bcf_check_values(VariantRecord record, value, int sample, # <<<<<<<<<<<<<< + * int hl_type, int ht_type, * int id, int bt_type, ssize_t bt_len, - * ssize_t *value_count, int *scalar, int *realloc): */ /* function exit code */ @@ -10319,6 +11032,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_11); __Pyx_AddTraceback("pysam.libcbcf.bcf_check_values", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; @@ -10330,7 +11044,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_check_values(struct __pyx_obj_5pysa return __pyx_r; } -/* "pysam/libcbcf.pyx":532 +/* "pysam/libcbcf.pyx":619 * * * cdef bcf_encode_alleles(VariantRecord record, values): # <<<<<<<<<<<<<< @@ -10363,10 +11077,10 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py uint32_t __pyx_t_12; int __pyx_t_13; __Pyx_RefNannySetupContext("bcf_encode_alleles", 0); - __Pyx_TraceCall("bcf_encode_alleles", __pyx_f[0], 532, 0, __PYX_ERR(0, 532, __pyx_L1_error)); + __Pyx_TraceCall("bcf_encode_alleles", __pyx_f[0], 619, 0, __PYX_ERR(0, 619, __pyx_L1_error)); __Pyx_INCREF(__pyx_v_values); - /* "pysam/libcbcf.pyx":533 + /* "pysam/libcbcf.pyx":620 * * cdef bcf_encode_alleles(VariantRecord record, values): * if record is None: # <<<<<<<<<<<<<< @@ -10377,20 +11091,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":534 + /* "pysam/libcbcf.pyx":621 * cdef bcf_encode_alleles(VariantRecord record, values): * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * cdef bcf1_t *r = record.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 534, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 621, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 534, __pyx_L1_error) + __PYX_ERR(0, 621, __pyx_L1_error) - /* "pysam/libcbcf.pyx":533 + /* "pysam/libcbcf.pyx":620 * * cdef bcf_encode_alleles(VariantRecord record, values): * if record is None: # <<<<<<<<<<<<<< @@ -10399,7 +11113,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":536 + /* "pysam/libcbcf.pyx":623 * raise ValueError('record must not be None') * * cdef bcf1_t *r = record.ptr # <<<<<<<<<<<<<< @@ -10409,7 +11123,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __pyx_t_4 = __pyx_v_record->ptr; __pyx_v_r = __pyx_t_4; - /* "pysam/libcbcf.pyx":537 + /* "pysam/libcbcf.pyx":624 * * cdef bcf1_t *r = record.ptr * cdef int32_t nalleles = r.n_allele # <<<<<<<<<<<<<< @@ -10419,19 +11133,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __pyx_t_5 = __pyx_v_r->n_allele; __pyx_v_nalleles = __pyx_t_5; - /* "pysam/libcbcf.pyx":538 + /* "pysam/libcbcf.pyx":625 * cdef bcf1_t *r = record.ptr * cdef int32_t nalleles = r.n_allele * cdef list gt_values = [] # <<<<<<<<<<<<<< * cdef char *s * cdef int i */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 538, __pyx_L1_error) + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 625, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_gt_values = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":542 + /* "pysam/libcbcf.pyx":629 * cdef int i * * if values is None: # <<<<<<<<<<<<<< @@ -10442,7 +11156,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __pyx_t_1 = (__pyx_t_2 != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":543 + /* "pysam/libcbcf.pyx":630 * * if values is None: * return () # <<<<<<<<<<<<<< @@ -10454,7 +11168,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __pyx_r = __pyx_empty_tuple; goto __pyx_L0; - /* "pysam/libcbcf.pyx":542 + /* "pysam/libcbcf.pyx":629 * cdef int i * * if values is None: # <<<<<<<<<<<<<< @@ -10463,7 +11177,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":545 + /* "pysam/libcbcf.pyx":632 * return () * * if not isinstance(values, (list, tuple)): # <<<<<<<<<<<<<< @@ -10484,14 +11198,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":546 + /* "pysam/libcbcf.pyx":633 * * if not isinstance(values, (list, tuple)): * values = (values,) # <<<<<<<<<<<<<< * * for value in values: */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 546, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 633, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_values); __Pyx_GIVEREF(__pyx_v_values); @@ -10499,7 +11213,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __Pyx_DECREF_SET(__pyx_v_values, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":545 + /* "pysam/libcbcf.pyx":632 * return () * * if not isinstance(values, (list, tuple)): # <<<<<<<<<<<<<< @@ -10508,7 +11222,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":548 + /* "pysam/libcbcf.pyx":635 * values = (values,) * * for value in values: # <<<<<<<<<<<<<< @@ -10519,26 +11233,26 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __pyx_t_3 = __pyx_v_values; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0; __pyx_t_8 = NULL; } else { - __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 548, __pyx_L1_error) + __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 635, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 548, __pyx_L1_error) + __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 635, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_8)) { if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 548, __pyx_L1_error) + __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 635, __pyx_L1_error) #else - __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 548, __pyx_L1_error) + __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 635, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); #endif } else { if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 548, __pyx_L1_error) + __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 635, __pyx_L1_error) #else - __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 548, __pyx_L1_error) + __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 635, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); #endif } @@ -10548,7 +11262,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 548, __pyx_L1_error) + else __PYX_ERR(0, 635, __pyx_L1_error) } break; } @@ -10557,7 +11271,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_9); __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":549 + /* "pysam/libcbcf.pyx":636 * * for value in values: * if value is None: # <<<<<<<<<<<<<< @@ -10568,19 +11282,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __pyx_t_1 = (__pyx_t_2 != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":550 + /* "pysam/libcbcf.pyx":637 * for value in values: * if value is None: * gt_values.append(bcf_gt_missing) # <<<<<<<<<<<<<< * elif isinstance(value, (str, bytes)): * bvalue = force_bytes(value) */ - __pyx_t_9 = __Pyx_PyInt_From_uint32_t(bcf_gt_missing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 550, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_From_uint32_t(bcf_gt_missing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 637, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_gt_values, __pyx_t_9); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 550, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_gt_values, __pyx_t_9); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 637, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":549 + /* "pysam/libcbcf.pyx":636 * * for value in values: * if value is None: # <<<<<<<<<<<<<< @@ -10590,7 +11304,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py goto __pyx_L10; } - /* "pysam/libcbcf.pyx":551 + /* "pysam/libcbcf.pyx":638 * if value is None: * gt_values.append(bcf_gt_missing) * elif isinstance(value, (str, bytes)): # <<<<<<<<<<<<<< @@ -10611,19 +11325,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":552 + /* "pysam/libcbcf.pyx":639 * gt_values.append(bcf_gt_missing) * elif isinstance(value, (str, bytes)): * bvalue = force_bytes(value) # <<<<<<<<<<<<<< * s = bvalue * for i in range(r.n_allele): */ - __pyx_t_9 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 552, __pyx_L1_error) + __pyx_t_9 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 639, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XDECREF_SET(__pyx_v_bvalue, ((PyObject*)__pyx_t_9)); __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":553 + /* "pysam/libcbcf.pyx":640 * elif isinstance(value, (str, bytes)): * bvalue = force_bytes(value) * s = bvalue # <<<<<<<<<<<<<< @@ -10632,12 +11346,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py */ if (unlikely(__pyx_v_bvalue == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 553, __pyx_L1_error) + __PYX_ERR(0, 640, __pyx_L1_error) } - __pyx_t_11 = __Pyx_PyBytes_AsWritableString(__pyx_v_bvalue); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) __PYX_ERR(0, 553, __pyx_L1_error) + __pyx_t_11 = __Pyx_PyBytes_AsWritableString(__pyx_v_bvalue); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) __PYX_ERR(0, 640, __pyx_L1_error) __pyx_v_s = __pyx_t_11; - /* "pysam/libcbcf.pyx":554 + /* "pysam/libcbcf.pyx":641 * bvalue = force_bytes(value) * s = bvalue * for i in range(r.n_allele): # <<<<<<<<<<<<<< @@ -10649,7 +11363,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) { __pyx_v_i = __pyx_t_13; - /* "pysam/libcbcf.pyx":555 + /* "pysam/libcbcf.pyx":642 * s = bvalue * for i in range(r.n_allele): * if strcmp(r.d.allele[i], s) != 0: # <<<<<<<<<<<<<< @@ -10659,19 +11373,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __pyx_t_2 = ((strcmp((__pyx_v_r->d.allele[__pyx_v_i]), __pyx_v_s) != 0) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":556 + /* "pysam/libcbcf.pyx":643 * for i in range(r.n_allele): * if strcmp(r.d.allele[i], s) != 0: * gt_values.append(bcf_gt_unphased(i)) # <<<<<<<<<<<<<< * break * else: */ - __pyx_t_9 = __Pyx_PyInt_From_uint32_t(bcf_gt_unphased(__pyx_v_i)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 556, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_From_uint32_t(bcf_gt_unphased(__pyx_v_i)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 643, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_gt_values, __pyx_t_9); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 556, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_gt_values, __pyx_t_9); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 643, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":557 + /* "pysam/libcbcf.pyx":644 * if strcmp(r.d.allele[i], s) != 0: * gt_values.append(bcf_gt_unphased(i)) * break # <<<<<<<<<<<<<< @@ -10680,7 +11394,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py */ goto __pyx_L14_break; - /* "pysam/libcbcf.pyx":555 + /* "pysam/libcbcf.pyx":642 * s = bvalue * for i in range(r.n_allele): * if strcmp(r.d.allele[i], s) != 0: # <<<<<<<<<<<<<< @@ -10691,22 +11405,22 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py } /*else*/ { - /* "pysam/libcbcf.pyx":559 + /* "pysam/libcbcf.pyx":646 * break * else: * raise ValueError('Unknown allele') # <<<<<<<<<<<<<< * else: * i = value */ - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 559, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 646, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_Raise(__pyx_t_9, 0, 0, 0); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __PYX_ERR(0, 559, __pyx_L1_error) + __PYX_ERR(0, 646, __pyx_L1_error) } __pyx_L14_break:; - /* "pysam/libcbcf.pyx":551 + /* "pysam/libcbcf.pyx":638 * if value is None: * gt_values.append(bcf_gt_missing) * elif isinstance(value, (str, bytes)): # <<<<<<<<<<<<<< @@ -10716,7 +11430,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py goto __pyx_L10; } - /* "pysam/libcbcf.pyx":561 + /* "pysam/libcbcf.pyx":648 * raise ValueError('Unknown allele') * else: * i = value # <<<<<<<<<<<<<< @@ -10724,10 +11438,10 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py * raise ValueError('Invalid allele index') */ /*else*/ { - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 561, __pyx_L1_error) + __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 648, __pyx_L1_error) __pyx_v_i = __pyx_t_13; - /* "pysam/libcbcf.pyx":562 + /* "pysam/libcbcf.pyx":649 * else: * i = value * if not (0 <= i < nalleles): # <<<<<<<<<<<<<< @@ -10741,20 +11455,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __pyx_t_1 = ((!(__pyx_t_2 != 0)) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":563 + /* "pysam/libcbcf.pyx":650 * i = value * if not (0 <= i < nalleles): * raise ValueError('Invalid allele index') # <<<<<<<<<<<<<< * gt_values.append(bcf_gt_unphased(i)) * */ - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 563, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 650, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_Raise(__pyx_t_9, 0, 0, 0); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __PYX_ERR(0, 563, __pyx_L1_error) + __PYX_ERR(0, 650, __pyx_L1_error) - /* "pysam/libcbcf.pyx":562 + /* "pysam/libcbcf.pyx":649 * else: * i = value * if not (0 <= i < nalleles): # <<<<<<<<<<<<<< @@ -10763,21 +11477,21 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":564 + /* "pysam/libcbcf.pyx":651 * if not (0 <= i < nalleles): * raise ValueError('Invalid allele index') * gt_values.append(bcf_gt_unphased(i)) # <<<<<<<<<<<<<< * * return gt_values */ - __pyx_t_9 = __Pyx_PyInt_From_uint32_t(bcf_gt_unphased(__pyx_v_i)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 564, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_From_uint32_t(bcf_gt_unphased(__pyx_v_i)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 651, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_gt_values, __pyx_t_9); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 564, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_gt_values, __pyx_t_9); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 651, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } __pyx_L10:; - /* "pysam/libcbcf.pyx":548 + /* "pysam/libcbcf.pyx":635 * values = (values,) * * for value in values: # <<<<<<<<<<<<<< @@ -10787,7 +11501,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":566 + /* "pysam/libcbcf.pyx":653 * gt_values.append(bcf_gt_unphased(i)) * * return gt_values # <<<<<<<<<<<<<< @@ -10799,7 +11513,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py __pyx_r = __pyx_v_gt_values; goto __pyx_L0; - /* "pysam/libcbcf.pyx":532 + /* "pysam/libcbcf.pyx":619 * * * cdef bcf_encode_alleles(VariantRecord record, values): # <<<<<<<<<<<<<< @@ -10824,7 +11538,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py return __pyx_r; } -/* "pysam/libcbcf.pyx":569 +/* "pysam/libcbcf.pyx":656 * * * cdef bcf_info_set_value(VariantRecord record, key, value): # <<<<<<<<<<<<<< @@ -10835,8 +11549,6 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_encode_alleles(struct __pyx_obj_5py static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { bcf_hdr_t *__pyx_v_hdr; bcf1_t *__pyx_v_r; - vdict_t *__pyx_v_d; - khiter_t __pyx_v_k; int __pyx_v_info_id; int __pyx_v_info_type; int __pyx_v_scalar; @@ -10845,7 +11557,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py int __pyx_v_vlen; Py_ssize_t __pyx_v_value_count; Py_ssize_t __pyx_v_alloc_len; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; bcf_info_t *__pyx_v_info; PyObject *__pyx_v_values = NULL; PyObject *__pyx_v_new_values = NULL; @@ -10860,17 +11572,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py bcf1_t *__pyx_t_5; char const *__pyx_t_6; int __pyx_t_7; - char const *__pyx_t_8; - Py_ssize_t __pyx_t_9; - char const *__pyx_t_10; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; Py_ssize_t __pyx_t_11; - long __pyx_t_12; + char const *__pyx_t_12; Py_ssize_t __pyx_t_13; - char *__pyx_t_14; + long __pyx_t_14; + Py_ssize_t __pyx_t_15; + char *__pyx_t_16; __Pyx_RefNannySetupContext("bcf_info_set_value", 0); - __Pyx_TraceCall("bcf_info_set_value", __pyx_f[0], 569, 0, __PYX_ERR(0, 569, __pyx_L1_error)); + __Pyx_TraceCall("bcf_info_set_value", __pyx_f[0], 656, 0, __PYX_ERR(0, 656, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":570 + /* "pysam/libcbcf.pyx":657 * * cdef bcf_info_set_value(VariantRecord record, key, value): * if record is None: # <<<<<<<<<<<<<< @@ -10881,20 +11595,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":571 + /* "pysam/libcbcf.pyx":658 * cdef bcf_info_set_value(VariantRecord record, key, value): * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = record.header.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 571, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 658, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 571, __pyx_L1_error) + __PYX_ERR(0, 658, __pyx_L1_error) - /* "pysam/libcbcf.pyx":570 + /* "pysam/libcbcf.pyx":657 * * cdef bcf_info_set_value(VariantRecord record, key, value): * if record is None: # <<<<<<<<<<<<<< @@ -10903,36 +11617,36 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":573 + /* "pysam/libcbcf.pyx":660 * raise ValueError('record must not be None') * * cdef bcf_hdr_t *hdr = record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = record.ptr - * cdef vdict_t *d + * cdef int info_id, info_type, scalar, dst_type, realloc, vlen = 0 */ __pyx_t_4 = __pyx_v_record->header->ptr; __pyx_v_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":574 + /* "pysam/libcbcf.pyx":661 * * cdef bcf_hdr_t *hdr = record.header.ptr * cdef bcf1_t *r = record.ptr # <<<<<<<<<<<<<< - * cdef vdict_t *d - * cdef khiter_t k + * cdef int info_id, info_type, scalar, dst_type, realloc, vlen = 0 + * cdef ssize_t i, value_count, alloc_len, alloc_size, dst_size */ __pyx_t_5 = __pyx_v_record->ptr; __pyx_v_r = __pyx_t_5; - /* "pysam/libcbcf.pyx":577 - * cdef vdict_t *d - * cdef khiter_t k + /* "pysam/libcbcf.pyx":662 + * cdef bcf_hdr_t *hdr = record.header.ptr + * cdef bcf1_t *r = record.ptr * cdef int info_id, info_type, scalar, dst_type, realloc, vlen = 0 # <<<<<<<<<<<<<< * cdef ssize_t i, value_count, alloc_len, alloc_size, dst_size * */ __pyx_v_vlen = 0; - /* "pysam/libcbcf.pyx":580 + /* "pysam/libcbcf.pyx":665 * cdef ssize_t i, value_count, alloc_len, alloc_size, dst_size * * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< @@ -10942,20 +11656,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_INFO) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":581 + /* "pysam/libcbcf.pyx":666 * * if bcf_unpack(r, BCF_UN_INFO) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 581, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 666, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 581, __pyx_L1_error) + __PYX_ERR(0, 666, __pyx_L1_error) - /* "pysam/libcbcf.pyx":580 + /* "pysam/libcbcf.pyx":665 * cdef ssize_t i, value_count, alloc_len, alloc_size, dst_size * * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< @@ -10964,33 +11678,33 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":583 + /* "pysam/libcbcf.pyx":668 * raise ValueError('Error unpacking VariantRecord') * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) * */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 583, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 668, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_bkey = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":584 + /* "pysam/libcbcf.pyx":669 * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) # <<<<<<<<<<<<<< * * if info: */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 584, __pyx_L1_error) + __PYX_ERR(0, 669, __pyx_L1_error) } - __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 584, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 669, __pyx_L1_error) __pyx_v_info = bcf_get_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_6); - /* "pysam/libcbcf.pyx":586 + /* "pysam/libcbcf.pyx":671 * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) * * if info: # <<<<<<<<<<<<<< @@ -11000,17 +11714,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py __pyx_t_2 = (__pyx_v_info != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":587 + /* "pysam/libcbcf.pyx":672 * * if info: * info_id = info.key # <<<<<<<<<<<<<< * else: - * d = hdr.dict[BCF_DT_ID] + * info_id = bcf_header_get_info_id(hdr, bkey) */ __pyx_t_7 = __pyx_v_info->key; __pyx_v_info_id = __pyx_t_7; - /* "pysam/libcbcf.pyx":586 + /* "pysam/libcbcf.pyx":671 * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) * * if info: # <<<<<<<<<<<<<< @@ -11020,84 +11734,99 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py goto __pyx_L5; } - /* "pysam/libcbcf.pyx":589 + /* "pysam/libcbcf.pyx":674 * info_id = info.key * else: - * d = hdr.dict[BCF_DT_ID] # <<<<<<<<<<<<<< - * k = kh_get_vdict(d, bkey) + * info_id = bcf_header_get_info_id(hdr, bkey) # <<<<<<<<<<<<<< * + * if info_id < 0: */ /*else*/ { - __pyx_v_d = ((vdict_t *)(__pyx_v_hdr->dict[BCF_DT_ID])); - - /* "pysam/libcbcf.pyx":590 - * else: - * d = hdr.dict[BCF_DT_ID] - * k = kh_get_vdict(d, bkey) # <<<<<<<<<<<<<< - * - * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: - */ - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 590, __pyx_L1_error) - } - __pyx_t_8 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 590, __pyx_L1_error) - __pyx_v_k = kh_get_vdict(__pyx_v_d, __pyx_t_8); + __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_header_get_info_id(__pyx_v_hdr, __pyx_v_bkey); if (unlikely(__pyx_t_7 == ((int)-2) && PyErr_Occurred())) __PYX_ERR(0, 674, __pyx_L1_error) + __pyx_v_info_id = __pyx_t_7; + } + __pyx_L5:; - /* "pysam/libcbcf.pyx":592 - * k = kh_get_vdict(d, bkey) + /* "pysam/libcbcf.pyx":676 + * info_id = bcf_header_get_info_id(hdr, bkey) * - * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: # <<<<<<<<<<<<<< - * raise KeyError('unknown INFO') + * if info_id < 0: # <<<<<<<<<<<<<< + * raise KeyError('unknown INFO: {}'.format(key)) * */ - __pyx_t_1 = ((__pyx_v_k == kh_end(__pyx_v_d)) != 0); - if (!__pyx_t_1) { - } else { - __pyx_t_2 = __pyx_t_1; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_1 = ((((kh_val(__pyx_v_d, __pyx_v_k).info[BCF_HL_INFO]) & 0xF) == 0xF) != 0); - __pyx_t_2 = __pyx_t_1; - __pyx_L7_bool_binop_done:; - if (unlikely(__pyx_t_2)) { + __pyx_t_2 = ((__pyx_v_info_id < 0) != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":593 + /* "pysam/libcbcf.pyx":677 * - * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: - * raise KeyError('unknown INFO') # <<<<<<<<<<<<<< + * if info_id < 0: + * raise KeyError('unknown INFO: {}'.format(key)) # <<<<<<<<<<<<<< * - * info_id = kh_val_vdict(d, k).id + * if not check_header_id(hdr, BCF_HL_INFO, info_id): */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 593, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unknown_INFO, __pyx_n_s_format); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 677, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + if (!__pyx_t_9) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 677, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 593, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":592 - * k = kh_get_vdict(d, bkey) - * - * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: # <<<<<<<<<<<<<< - * raise KeyError('unknown INFO') - * - */ + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_key}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 677, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_key}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 677, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 677, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_key); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 677, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 677, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_8, 0, 0, 0); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __PYX_ERR(0, 677, __pyx_L1_error) - /* "pysam/libcbcf.pyx":595 - * raise KeyError('unknown INFO') + /* "pysam/libcbcf.pyx":676 + * info_id = bcf_header_get_info_id(hdr, bkey) * - * info_id = kh_val_vdict(d, k).id # <<<<<<<<<<<<<< + * if info_id < 0: # <<<<<<<<<<<<<< + * raise KeyError('unknown INFO: {}'.format(key)) * - * if not check_header_id(hdr, BCF_HL_INFO, info_id): */ - __pyx_t_7 = kh_val(__pyx_v_d, __pyx_v_k).id; - __pyx_v_info_id = __pyx_t_7; } - __pyx_L5:; - /* "pysam/libcbcf.pyx":597 - * info_id = kh_val_vdict(d, k).id + /* "pysam/libcbcf.pyx":679 + * raise KeyError('unknown INFO: {}'.format(key)) * * if not check_header_id(hdr, BCF_HL_INFO, info_id): # <<<<<<<<<<<<<< * raise ValueError('Invalid header') @@ -11106,21 +11835,21 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py __pyx_t_2 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_INFO, __pyx_v_info_id) != 0)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":598 + /* "pysam/libcbcf.pyx":680 * * if not check_header_id(hdr, BCF_HL_INFO, info_id): * raise ValueError('Invalid header') # <<<<<<<<<<<<<< * * info_type = bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 598, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 680, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_Raise(__pyx_t_8, 0, 0, 0); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __PYX_ERR(0, 680, __pyx_L1_error) - /* "pysam/libcbcf.pyx":597 - * info_id = kh_val_vdict(d, k).id + /* "pysam/libcbcf.pyx":679 + * raise KeyError('unknown INFO: {}'.format(key)) * * if not check_header_id(hdr, BCF_HL_INFO, info_id): # <<<<<<<<<<<<<< * raise ValueError('Invalid header') @@ -11128,18 +11857,18 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":600 + /* "pysam/libcbcf.pyx":682 * raise ValueError('Invalid header') * * info_type = bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) # <<<<<<<<<<<<<< - * values = bcf_check_values(record, value, BCF_HL_INFO, info_type, info_id, - * info.type if info else -1, + * values = bcf_check_values(record, value, -1, + * BCF_HL_INFO, info_type, info_id, */ __pyx_v_info_type = bcf_hdr_id2type(__pyx_v_hdr, BCF_HL_INFO, __pyx_v_info_id); - /* "pysam/libcbcf.pyx":602 - * info_type = bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) - * values = bcf_check_values(record, value, BCF_HL_INFO, info_type, info_id, + /* "pysam/libcbcf.pyx":685 + * values = bcf_check_values(record, value, -1, + * BCF_HL_INFO, info_type, info_id, * info.type if info else -1, # <<<<<<<<<<<<<< * info.len if info else -1, * &value_count, &scalar, &realloc) @@ -11150,32 +11879,32 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py __pyx_t_7 = -1; } - /* "pysam/libcbcf.pyx":603 - * values = bcf_check_values(record, value, BCF_HL_INFO, info_type, info_id, + /* "pysam/libcbcf.pyx":686 + * BCF_HL_INFO, info_type, info_id, * info.type if info else -1, * info.len if info else -1, # <<<<<<<<<<<<<< * &value_count, &scalar, &realloc) * */ if ((__pyx_v_info != 0)) { - __pyx_t_9 = __pyx_v_info->len; + __pyx_t_11 = __pyx_v_info->len; } else { - __pyx_t_9 = -1L; + __pyx_t_11 = -1L; } - /* "pysam/libcbcf.pyx":601 + /* "pysam/libcbcf.pyx":683 * * info_type = bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) - * values = bcf_check_values(record, value, BCF_HL_INFO, info_type, info_id, # <<<<<<<<<<<<<< + * values = bcf_check_values(record, value, -1, # <<<<<<<<<<<<<< + * BCF_HL_INFO, info_type, info_id, * info.type if info else -1, - * info.len if info else -1, */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_check_values(__pyx_v_record, __pyx_v_value, BCF_HL_INFO, __pyx_v_info_type, __pyx_v_info_id, __pyx_t_7, __pyx_t_9, (&__pyx_v_value_count), (&__pyx_v_scalar), (&__pyx_v_realloc)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 601, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_values = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_8 = __pyx_f_5pysam_7libcbcf_bcf_check_values(__pyx_v_record, __pyx_v_value, -1, BCF_HL_INFO, __pyx_v_info_type, __pyx_v_info_id, __pyx_t_7, __pyx_t_11, (&__pyx_v_value_count), (&__pyx_v_scalar), (&__pyx_v_realloc)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 683, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_v_values = __pyx_t_8; + __pyx_t_8 = 0; - /* "pysam/libcbcf.pyx":606 + /* "pysam/libcbcf.pyx":689 * &value_count, &scalar, &realloc) * * if info_type == BCF_HT_FLAG: # <<<<<<<<<<<<<< @@ -11185,7 +11914,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py __pyx_t_2 = ((__pyx_v_info_type == BCF_HT_FLAG) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":607 + /* "pysam/libcbcf.pyx":690 * * if info_type == BCF_HT_FLAG: * if bcf_update_info(hdr, r, bkey, NULL, bool(values[0]), info_type) < 0: # <<<<<<<<<<<<<< @@ -11194,30 +11923,30 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 607, __pyx_L1_error) + __PYX_ERR(0, 690, __pyx_L1_error) } - __pyx_t_10 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 607, __pyx_L1_error) - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_values, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 607, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 607, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = ((bcf_update_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_10, NULL, (!(!__pyx_t_2)), __pyx_v_info_type) < 0) != 0); + __pyx_t_12 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 690, __pyx_L1_error) + __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_values, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 690, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_1 = ((bcf_update_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_12, NULL, (!(!__pyx_t_2)), __pyx_v_info_type) < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":608 + /* "pysam/libcbcf.pyx":691 * if info_type == BCF_HT_FLAG: * if bcf_update_info(hdr, r, bkey, NULL, bool(values[0]), info_type) < 0: * raise ValueError('Unable to update INFO values') # <<<<<<<<<<<<<< * return * */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 608, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 608, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 691, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_Raise(__pyx_t_8, 0, 0, 0); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __PYX_ERR(0, 691, __pyx_L1_error) - /* "pysam/libcbcf.pyx":607 + /* "pysam/libcbcf.pyx":690 * * if info_type == BCF_HT_FLAG: * if bcf_update_info(hdr, r, bkey, NULL, bool(values[0]), info_type) < 0: # <<<<<<<<<<<<<< @@ -11226,7 +11955,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":609 + /* "pysam/libcbcf.pyx":692 * if bcf_update_info(hdr, r, bkey, NULL, bool(values[0]), info_type) < 0: * raise ValueError('Unable to update INFO values') * return # <<<<<<<<<<<<<< @@ -11237,7 +11966,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":606 + /* "pysam/libcbcf.pyx":689 * &value_count, &scalar, &realloc) * * if info_type == BCF_HT_FLAG: # <<<<<<<<<<<<<< @@ -11246,7 +11975,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":611 + /* "pysam/libcbcf.pyx":694 * return * * vlen = value_count < 0 # <<<<<<<<<<<<<< @@ -11255,241 +11984,33 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ __pyx_v_vlen = (__pyx_v_value_count < 0); - /* "pysam/libcbcf.pyx":612 + /* "pysam/libcbcf.pyx":695 * * vlen = value_count < 0 * value_count = len(values) # <<<<<<<<<<<<<< * - * # If we can, write updated values to existing allocated storage - */ - __pyx_t_11 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 612, __pyx_L1_error) - __pyx_v_value_count = __pyx_t_11; - - /* "pysam/libcbcf.pyx":615 - * - * # If we can, write updated values to existing allocated storage - * if info and not realloc: # <<<<<<<<<<<<<< - * r.d.shared_dirty |= BCF1_DIRTY_INF - * - */ - __pyx_t_2 = (__pyx_v_info != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L13_bool_binop_done; - } - __pyx_t_2 = ((!(__pyx_v_realloc != 0)) != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L13_bool_binop_done:; - if (__pyx_t_1) { - - /* "pysam/libcbcf.pyx":616 - * # If we can, write updated values to existing allocated storage - * if info and not realloc: - * r.d.shared_dirty |= BCF1_DIRTY_INF # <<<<<<<<<<<<<< - * - * if value_count == 0: - */ - __pyx_v_r->d.shared_dirty = (__pyx_v_r->d.shared_dirty | BCF1_DIRTY_INF); - - /* "pysam/libcbcf.pyx":618 - * r.d.shared_dirty |= BCF1_DIRTY_INF - * - * if value_count == 0: # <<<<<<<<<<<<<< - * info.len = 0 - * # FIXME: Check if need to free vptr if info.len > 0? - */ - switch (__pyx_v_value_count) { - case 0: - - /* "pysam/libcbcf.pyx":619 - * - * if value_count == 0: - * info.len = 0 # <<<<<<<<<<<<<< - * # FIXME: Check if need to free vptr if info.len > 0? - * elif value_count == 1: - */ - __pyx_v_info->len = 0; - - /* "pysam/libcbcf.pyx":618 - * r.d.shared_dirty |= BCF1_DIRTY_INF - * - * if value_count == 0: # <<<<<<<<<<<<<< - * info.len = 0 - * # FIXME: Check if need to free vptr if info.len > 0? - */ - break; - - /* "pysam/libcbcf.pyx":621 - * info.len = 0 - * # FIXME: Check if need to free vptr if info.len > 0? - * elif value_count == 1: # <<<<<<<<<<<<<< - * # FIXME: Check if need to free vptr if info.len > 0? - * if info.type == BCF_BT_INT8 or info.type == BCF_BT_INT16 or info.type == BCF_BT_INT32: + * # DISABLED DUE TO ISSUES WITH THE CRAZY POINTERS */ - case 1: + __pyx_t_13 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 695, __pyx_L1_error) + __pyx_v_value_count = __pyx_t_13; - /* "pysam/libcbcf.pyx":623 - * elif value_count == 1: - * # FIXME: Check if need to free vptr if info.len > 0? - * if info.type == BCF_BT_INT8 or info.type == BCF_BT_INT16 or info.type == BCF_BT_INT32: # <<<<<<<<<<<<<< - * bcf_object_to_array(values, &info.v1.i, BCF_BT_INT32, 1, vlen) - * elif info.type == BCF_BT_FLOAT: - */ - __pyx_t_2 = ((__pyx_v_info->type == BCF_BT_INT8) != 0); - if (!__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L16_bool_binop_done; - } - __pyx_t_2 = ((__pyx_v_info->type == BCF_BT_INT16) != 0); - if (!__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L16_bool_binop_done; - } - __pyx_t_2 = ((__pyx_v_info->type == BCF_BT_INT32) != 0); - __pyx_t_1 = __pyx_t_2; - __pyx_L16_bool_binop_done:; - if (__pyx_t_1) { - - /* "pysam/libcbcf.pyx":624 - * # FIXME: Check if need to free vptr if info.len > 0? - * if info.type == BCF_BT_INT8 or info.type == BCF_BT_INT16 or info.type == BCF_BT_INT32: - * bcf_object_to_array(values, &info.v1.i, BCF_BT_INT32, 1, vlen) # <<<<<<<<<<<<<< - * elif info.type == BCF_BT_FLOAT: - * bcf_object_to_array(values, &info.v1.f, BCF_BT_FLOAT, 1, vlen) - */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_object_to_array(__pyx_v_values, (&__pyx_v_info->v1.i), BCF_BT_INT32, 1, __pyx_v_vlen); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 624, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pysam/libcbcf.pyx":623 - * elif value_count == 1: - * # FIXME: Check if need to free vptr if info.len > 0? - * if info.type == BCF_BT_INT8 or info.type == BCF_BT_INT16 or info.type == BCF_BT_INT32: # <<<<<<<<<<<<<< - * bcf_object_to_array(values, &info.v1.i, BCF_BT_INT32, 1, vlen) - * elif info.type == BCF_BT_FLOAT: - */ - goto __pyx_L15; - } - - /* "pysam/libcbcf.pyx":625 - * if info.type == BCF_BT_INT8 or info.type == BCF_BT_INT16 or info.type == BCF_BT_INT32: - * bcf_object_to_array(values, &info.v1.i, BCF_BT_INT32, 1, vlen) - * elif info.type == BCF_BT_FLOAT: # <<<<<<<<<<<<<< - * bcf_object_to_array(values, &info.v1.f, BCF_BT_FLOAT, 1, vlen) - * else: - */ - __pyx_t_1 = ((__pyx_v_info->type == BCF_BT_FLOAT) != 0); - if (likely(__pyx_t_1)) { - - /* "pysam/libcbcf.pyx":626 - * bcf_object_to_array(values, &info.v1.i, BCF_BT_INT32, 1, vlen) - * elif info.type == BCF_BT_FLOAT: - * bcf_object_to_array(values, &info.v1.f, BCF_BT_FLOAT, 1, vlen) # <<<<<<<<<<<<<< - * else: - * raise TypeError('unsupported info type code') - */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_object_to_array(__pyx_v_values, (&__pyx_v_info->v1.f), BCF_BT_FLOAT, 1, __pyx_v_vlen); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 626, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pysam/libcbcf.pyx":625 - * if info.type == BCF_BT_INT8 or info.type == BCF_BT_INT16 or info.type == BCF_BT_INT32: - * bcf_object_to_array(values, &info.v1.i, BCF_BT_INT32, 1, vlen) - * elif info.type == BCF_BT_FLOAT: # <<<<<<<<<<<<<< - * bcf_object_to_array(values, &info.v1.f, BCF_BT_FLOAT, 1, vlen) - * else: - */ - goto __pyx_L15; - } - - /* "pysam/libcbcf.pyx":628 - * bcf_object_to_array(values, &info.v1.f, BCF_BT_FLOAT, 1, vlen) - * else: - * raise TypeError('unsupported info type code') # <<<<<<<<<<<<<< - * info.len = 1 - * else: - */ - /*else*/ { - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 628, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 628, __pyx_L1_error) - } - __pyx_L15:; - - /* "pysam/libcbcf.pyx":629 - * else: - * raise TypeError('unsupported info type code') - * info.len = 1 # <<<<<<<<<<<<<< - * else: - * bcf_object_to_array(values, info.vptr, info.type, info.len, vlen) - */ - __pyx_v_info->len = 1; - - /* "pysam/libcbcf.pyx":621 - * info.len = 0 - * # FIXME: Check if need to free vptr if info.len > 0? - * elif value_count == 1: # <<<<<<<<<<<<<< - * # FIXME: Check if need to free vptr if info.len > 0? - * if info.type == BCF_BT_INT8 or info.type == BCF_BT_INT16 or info.type == BCF_BT_INT32: - */ - break; - default: - - /* "pysam/libcbcf.pyx":631 - * info.len = 1 - * else: - * bcf_object_to_array(values, info.vptr, info.type, info.len, vlen) # <<<<<<<<<<<<<< - * return - * - */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_object_to_array(__pyx_v_values, __pyx_v_info->vptr, __pyx_v_info->type, __pyx_v_info->len, __pyx_v_vlen); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 631, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - break; - } - - /* "pysam/libcbcf.pyx":632 - * else: - * bcf_object_to_array(values, info.vptr, info.type, info.len, vlen) - * return # <<<<<<<<<<<<<< - * - * alloc_len = max(1, value_count) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "pysam/libcbcf.pyx":615 - * - * # If we can, write updated values to existing allocated storage - * if info and not realloc: # <<<<<<<<<<<<<< - * r.d.shared_dirty |= BCF1_DIRTY_INF - * - */ - } - - /* "pysam/libcbcf.pyx":634 + /* "pysam/libcbcf.pyx":724 * return * * alloc_len = max(1, value_count) # <<<<<<<<<<<<<< * if info and info.len > alloc_len: * alloc_len = info.len */ - __pyx_t_9 = __pyx_v_value_count; - __pyx_t_12 = 1; - if (((__pyx_t_9 > __pyx_t_12) != 0)) { - __pyx_t_13 = __pyx_t_9; + __pyx_t_11 = __pyx_v_value_count; + __pyx_t_14 = 1; + if (((__pyx_t_11 > __pyx_t_14) != 0)) { + __pyx_t_15 = __pyx_t_11; } else { - __pyx_t_13 = __pyx_t_12; + __pyx_t_15 = __pyx_t_14; } - __pyx_v_alloc_len = __pyx_t_13; + __pyx_v_alloc_len = __pyx_t_15; - /* "pysam/libcbcf.pyx":635 + /* "pysam/libcbcf.pyx":725 * * alloc_len = max(1, value_count) * if info and info.len > alloc_len: # <<<<<<<<<<<<<< @@ -11500,14 +12021,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; - goto __pyx_L20_bool_binop_done; + goto __pyx_L11_bool_binop_done; } __pyx_t_2 = ((__pyx_v_info->len > __pyx_v_alloc_len) != 0); __pyx_t_1 = __pyx_t_2; - __pyx_L20_bool_binop_done:; + __pyx_L11_bool_binop_done:; if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":636 + /* "pysam/libcbcf.pyx":726 * alloc_len = max(1, value_count) * if info and info.len > alloc_len: * alloc_len = info.len # <<<<<<<<<<<<<< @@ -11517,7 +12038,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py __pyx_t_7 = __pyx_v_info->len; __pyx_v_alloc_len = __pyx_t_7; - /* "pysam/libcbcf.pyx":635 + /* "pysam/libcbcf.pyx":725 * * alloc_len = max(1, value_count) * if info and info.len > alloc_len: # <<<<<<<<<<<<<< @@ -11526,29 +12047,29 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":638 + /* "pysam/libcbcf.pyx":728 * alloc_len = info.len * * new_values = bcf_empty_array(info_type, alloc_len, vlen) # <<<<<<<<<<<<<< * cdef char *valp = new_values * */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_empty_array(__pyx_v_info_type, __pyx_v_alloc_len, __pyx_v_vlen); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 638, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_new_values = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_8 = __pyx_f_5pysam_7libcbcf_bcf_empty_array(__pyx_v_info_type, __pyx_v_alloc_len, __pyx_v_vlen); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 728, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_v_new_values = __pyx_t_8; + __pyx_t_8 = 0; - /* "pysam/libcbcf.pyx":639 + /* "pysam/libcbcf.pyx":729 * * new_values = bcf_empty_array(info_type, alloc_len, vlen) * cdef char *valp = new_values # <<<<<<<<<<<<<< * * if info_type == BCF_HT_INT: */ - __pyx_t_14 = __Pyx_PyObject_AsWritableString(__pyx_v_new_values); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) __PYX_ERR(0, 639, __pyx_L1_error) - __pyx_v_valp = ((char *)__pyx_t_14); + __pyx_t_16 = __Pyx_PyObject_AsWritableString(__pyx_v_new_values); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 729, __pyx_L1_error) + __pyx_v_valp = ((char *)__pyx_t_16); - /* "pysam/libcbcf.pyx":641 + /* "pysam/libcbcf.pyx":731 * cdef char *valp = new_values * * if info_type == BCF_HT_INT: # <<<<<<<<<<<<<< @@ -11558,7 +12079,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py __pyx_t_1 = ((__pyx_v_info_type == BCF_HT_INT) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":642 + /* "pysam/libcbcf.pyx":732 * * if info_type == BCF_HT_INT: * dst_type = BCF_BT_INT32 # <<<<<<<<<<<<<< @@ -11567,17 +12088,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ __pyx_v_dst_type = BCF_BT_INT32; - /* "pysam/libcbcf.pyx":641 + /* "pysam/libcbcf.pyx":731 * cdef char *valp = new_values * * if info_type == BCF_HT_INT: # <<<<<<<<<<<<<< * dst_type = BCF_BT_INT32 * elif info_type == BCF_HT_REAL: */ - goto __pyx_L22; + goto __pyx_L13; } - /* "pysam/libcbcf.pyx":643 + /* "pysam/libcbcf.pyx":733 * if info_type == BCF_HT_INT: * dst_type = BCF_BT_INT32 * elif info_type == BCF_HT_REAL: # <<<<<<<<<<<<<< @@ -11587,7 +12108,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py __pyx_t_1 = ((__pyx_v_info_type == BCF_HT_REAL) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":644 + /* "pysam/libcbcf.pyx":734 * dst_type = BCF_BT_INT32 * elif info_type == BCF_HT_REAL: * dst_type = BCF_BT_FLOAT # <<<<<<<<<<<<<< @@ -11596,17 +12117,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ __pyx_v_dst_type = BCF_BT_FLOAT; - /* "pysam/libcbcf.pyx":643 + /* "pysam/libcbcf.pyx":733 * if info_type == BCF_HT_INT: * dst_type = BCF_BT_INT32 * elif info_type == BCF_HT_REAL: # <<<<<<<<<<<<<< * dst_type = BCF_BT_FLOAT * elif info_type == BCF_HT_STR: */ - goto __pyx_L22; + goto __pyx_L13; } - /* "pysam/libcbcf.pyx":645 + /* "pysam/libcbcf.pyx":735 * elif info_type == BCF_HT_REAL: * dst_type = BCF_BT_FLOAT * elif info_type == BCF_HT_STR: # <<<<<<<<<<<<<< @@ -11616,7 +12137,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py __pyx_t_1 = ((__pyx_v_info_type == BCF_HT_STR) != 0); if (likely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":646 + /* "pysam/libcbcf.pyx":736 * dst_type = BCF_BT_FLOAT * elif info_type == BCF_HT_STR: * dst_type = BCF_BT_CHAR # <<<<<<<<<<<<<< @@ -11625,17 +12146,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ __pyx_v_dst_type = BCF_BT_CHAR; - /* "pysam/libcbcf.pyx":645 + /* "pysam/libcbcf.pyx":735 * elif info_type == BCF_HT_REAL: * dst_type = BCF_BT_FLOAT * elif info_type == BCF_HT_STR: # <<<<<<<<<<<<<< * dst_type = BCF_BT_CHAR * else: */ - goto __pyx_L22; + goto __pyx_L13; } - /* "pysam/libcbcf.pyx":648 + /* "pysam/libcbcf.pyx":738 * dst_type = BCF_BT_CHAR * else: * raise ValueError('Unsupported INFO type') # <<<<<<<<<<<<<< @@ -11643,26 +12164,26 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py * bcf_object_to_array(values, valp, dst_type, alloc_len, vlen) */ /*else*/ { - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 648, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 648, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 738, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_Raise(__pyx_t_8, 0, 0, 0); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __PYX_ERR(0, 738, __pyx_L1_error) } - __pyx_L22:; + __pyx_L13:; - /* "pysam/libcbcf.pyx":650 + /* "pysam/libcbcf.pyx":740 * raise ValueError('Unsupported INFO type') * * bcf_object_to_array(values, valp, dst_type, alloc_len, vlen) # <<<<<<<<<<<<<< * * if bcf_update_info(hdr, r, bkey, valp, alloc_len, info_type) < 0: */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_object_to_array(__pyx_v_values, __pyx_v_valp, __pyx_v_dst_type, __pyx_v_alloc_len, __pyx_v_vlen); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 650, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = __pyx_f_5pysam_7libcbcf_bcf_object_to_array(__pyx_v_values, __pyx_v_valp, __pyx_v_dst_type, __pyx_v_alloc_len, __pyx_v_vlen); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 740, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - /* "pysam/libcbcf.pyx":652 + /* "pysam/libcbcf.pyx":742 * bcf_object_to_array(values, valp, dst_type, alloc_len, vlen) * * if bcf_update_info(hdr, r, bkey, valp, alloc_len, info_type) < 0: # <<<<<<<<<<<<<< @@ -11671,26 +12192,26 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 652, __pyx_L1_error) + __PYX_ERR(0, 742, __pyx_L1_error) } - __pyx_t_10 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 652, __pyx_L1_error) - __pyx_t_1 = ((bcf_update_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_10, __pyx_v_valp, ((int)__pyx_v_alloc_len), __pyx_v_info_type) < 0) != 0); + __pyx_t_12 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 742, __pyx_L1_error) + __pyx_t_1 = ((bcf_update_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_12, __pyx_v_valp, ((int)__pyx_v_alloc_len), __pyx_v_info_type) < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":653 + /* "pysam/libcbcf.pyx":743 * * if bcf_update_info(hdr, r, bkey, valp, alloc_len, info_type) < 0: * raise ValueError('Unable to update INFO values') # <<<<<<<<<<<<<< * * */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 653, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 653, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 743, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_Raise(__pyx_t_8, 0, 0, 0); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __PYX_ERR(0, 743, __pyx_L1_error) - /* "pysam/libcbcf.pyx":652 + /* "pysam/libcbcf.pyx":742 * bcf_object_to_array(values, valp, dst_type, alloc_len, vlen) * * if bcf_update_info(hdr, r, bkey, valp, alloc_len, info_type) < 0: # <<<<<<<<<<<<<< @@ -11699,7 +12220,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":569 + /* "pysam/libcbcf.pyx":656 * * * cdef bcf_info_set_value(VariantRecord record, key, value): # <<<<<<<<<<<<<< @@ -11712,6 +12233,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); __Pyx_AddTraceback("pysam.libcbcf.bcf_info_set_value", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; @@ -11724,7 +12248,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_set_value(struct __pyx_obj_5py return __pyx_r; } -/* "pysam/libcbcf.pyx":656 +/* "pysam/libcbcf.pyx":746 * * * cdef bcf_info_del_value(VariantRecord record, key): # <<<<<<<<<<<<<< @@ -11737,7 +12261,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py bcf1_t *__pyx_v_r; Py_ssize_t __pyx_v_value_count; int __pyx_v_scalar; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; bcf_info_t *__pyx_v_info; PyObject *__pyx_v_null_value = NULL; PyObject *__pyx_r = NULL; @@ -11751,9 +12275,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py char const *__pyx_t_6; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("bcf_info_del_value", 0); - __Pyx_TraceCall("bcf_info_del_value", __pyx_f[0], 656, 0, __PYX_ERR(0, 656, __pyx_L1_error)); + __Pyx_TraceCall("bcf_info_del_value", __pyx_f[0], 746, 0, __PYX_ERR(0, 746, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":657 + /* "pysam/libcbcf.pyx":747 * * cdef bcf_info_del_value(VariantRecord record, key): * if record is None: # <<<<<<<<<<<<<< @@ -11764,20 +12288,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":658 + /* "pysam/libcbcf.pyx":748 * cdef bcf_info_del_value(VariantRecord record, key): * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = record.header.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 658, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 748, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 658, __pyx_L1_error) + __PYX_ERR(0, 748, __pyx_L1_error) - /* "pysam/libcbcf.pyx":657 + /* "pysam/libcbcf.pyx":747 * * cdef bcf_info_del_value(VariantRecord record, key): * if record is None: # <<<<<<<<<<<<<< @@ -11786,7 +12310,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":660 + /* "pysam/libcbcf.pyx":750 * raise ValueError('record must not be None') * * cdef bcf_hdr_t *hdr = record.header.ptr # <<<<<<<<<<<<<< @@ -11796,7 +12320,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py __pyx_t_4 = __pyx_v_record->header->ptr; __pyx_v_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":661 + /* "pysam/libcbcf.pyx":751 * * cdef bcf_hdr_t *hdr = record.header.ptr * cdef bcf1_t *r = record.ptr # <<<<<<<<<<<<<< @@ -11806,7 +12330,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py __pyx_t_5 = __pyx_v_record->ptr; __pyx_v_r = __pyx_t_5; - /* "pysam/libcbcf.pyx":665 + /* "pysam/libcbcf.pyx":755 * cdef int scalar * * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< @@ -11816,20 +12340,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_INFO) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":666 + /* "pysam/libcbcf.pyx":756 * * if bcf_unpack(r, BCF_UN_INFO) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 666, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 756, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 666, __pyx_L1_error) + __PYX_ERR(0, 756, __pyx_L1_error) - /* "pysam/libcbcf.pyx":665 + /* "pysam/libcbcf.pyx":755 * cdef int scalar * * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< @@ -11838,33 +12362,33 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":668 + /* "pysam/libcbcf.pyx":758 * raise ValueError('Error unpacking VariantRecord') * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) * */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 668, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 758, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_bkey = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":669 + /* "pysam/libcbcf.pyx":759 * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) # <<<<<<<<<<<<<< * * if not info: */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 669, __pyx_L1_error) + __PYX_ERR(0, 759, __pyx_L1_error) } - __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 669, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 759, __pyx_L1_error) __pyx_v_info = bcf_get_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_6); - /* "pysam/libcbcf.pyx":671 + /* "pysam/libcbcf.pyx":761 * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) * * if not info: # <<<<<<<<<<<<<< @@ -11874,20 +12398,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py __pyx_t_2 = ((!(__pyx_v_info != 0)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":672 + /* "pysam/libcbcf.pyx":762 * * if not info: * raise KeyError(key) # <<<<<<<<<<<<<< * - * bcf_get_value_count(record, BCF_HL_INFO, info.key, &value_count, &scalar) + * bcf_get_value_count(record, BCF_HL_INFO, info.key, &value_count, &scalar, -1) */ - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 672, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 762, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 672, __pyx_L1_error) + __PYX_ERR(0, 762, __pyx_L1_error) - /* "pysam/libcbcf.pyx":671 + /* "pysam/libcbcf.pyx":761 * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) * * if not info: # <<<<<<<<<<<<<< @@ -11896,19 +12420,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":674 + /* "pysam/libcbcf.pyx":764 * raise KeyError(key) * - * bcf_get_value_count(record, BCF_HL_INFO, info.key, &value_count, &scalar) # <<<<<<<<<<<<<< + * bcf_get_value_count(record, BCF_HL_INFO, info.key, &value_count, &scalar, -1) # <<<<<<<<<<<<<< * * if value_count <= 0: */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_get_value_count(__pyx_v_record, BCF_HL_INFO, __pyx_v_info->key, (&__pyx_v_value_count), (&__pyx_v_scalar)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 674, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_get_value_count(__pyx_v_record, BCF_HL_INFO, __pyx_v_info->key, (&__pyx_v_value_count), (&__pyx_v_scalar), -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 764, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":676 - * bcf_get_value_count(record, BCF_HL_INFO, info.key, &value_count, &scalar) + /* "pysam/libcbcf.pyx":766 + * bcf_get_value_count(record, BCF_HL_INFO, info.key, &value_count, &scalar, -1) * * if value_count <= 0: # <<<<<<<<<<<<<< * null_value = () @@ -11917,7 +12441,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py __pyx_t_2 = ((__pyx_v_value_count <= 0) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":677 + /* "pysam/libcbcf.pyx":767 * * if value_count <= 0: * null_value = () # <<<<<<<<<<<<<< @@ -11927,8 +12451,8 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py __Pyx_INCREF(__pyx_empty_tuple); __pyx_v_null_value = __pyx_empty_tuple; - /* "pysam/libcbcf.pyx":676 - * bcf_get_value_count(record, BCF_HL_INFO, info.key, &value_count, &scalar) + /* "pysam/libcbcf.pyx":766 + * bcf_get_value_count(record, BCF_HL_INFO, info.key, &value_count, &scalar, -1) * * if value_count <= 0: # <<<<<<<<<<<<<< * null_value = () @@ -11937,7 +12461,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py goto __pyx_L6; } - /* "pysam/libcbcf.pyx":678 + /* "pysam/libcbcf.pyx":768 * if value_count <= 0: * null_value = () * elif scalar: # <<<<<<<<<<<<<< @@ -11947,7 +12471,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py __pyx_t_2 = (__pyx_v_scalar != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":679 + /* "pysam/libcbcf.pyx":769 * null_value = () * elif scalar: * null_value = None # <<<<<<<<<<<<<< @@ -11957,7 +12481,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py __Pyx_INCREF(Py_None); __pyx_v_null_value = ((PyObject*)Py_None); - /* "pysam/libcbcf.pyx":678 + /* "pysam/libcbcf.pyx":768 * if value_count <= 0: * null_value = () * elif scalar: # <<<<<<<<<<<<<< @@ -11967,7 +12491,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py goto __pyx_L6; } - /* "pysam/libcbcf.pyx":681 + /* "pysam/libcbcf.pyx":771 * null_value = None * else: * null_value = (None,)*value_count # <<<<<<<<<<<<<< @@ -11975,9 +12499,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py * bcf_info_set_value(record, bkey, null_value) */ /*else*/ { - __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_value_count); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 681, __pyx_L1_error) + __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_value_count); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 771, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PyNumber_Multiply(__pyx_tuple__34, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 681, __pyx_L1_error) + __pyx_t_7 = PyNumber_Multiply(__pyx_tuple__33, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 771, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_null_value = ((PyObject*)__pyx_t_7); @@ -11985,18 +12509,18 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py } __pyx_L6:; - /* "pysam/libcbcf.pyx":683 + /* "pysam/libcbcf.pyx":773 * null_value = (None,)*value_count * * bcf_info_set_value(record, bkey, null_value) # <<<<<<<<<<<<<< * * */ - __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_info_set_value(__pyx_v_record, __pyx_v_bkey, __pyx_v_null_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 683, __pyx_L1_error) + __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_info_set_value(__pyx_v_record, __pyx_v_bkey, __pyx_v_null_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 773, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcbcf.pyx":656 + /* "pysam/libcbcf.pyx":746 * * * cdef bcf_info_del_value(VariantRecord record, key): # <<<<<<<<<<<<<< @@ -12021,7 +12545,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_info_del_value(struct __pyx_obj_5py return __pyx_r; } -/* "pysam/libcbcf.pyx":686 +/* "pysam/libcbcf.pyx":776 * * * cdef bcf_format_get_value(VariantRecordSample sample, key): # <<<<<<<<<<<<<< @@ -12034,7 +12558,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 bcf1_t *__pyx_v_r; Py_ssize_t __pyx_v_count; int __pyx_v_scalar; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; bcf_fmt_t *__pyx_v_fmt; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations @@ -12046,10 +12570,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 bcf1_t *__pyx_t_5; char const *__pyx_t_6; PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("bcf_format_get_value", 0); - __Pyx_TraceCall("bcf_format_get_value", __pyx_f[0], 686, 0, __PYX_ERR(0, 686, __pyx_L1_error)); + __Pyx_TraceCall("bcf_format_get_value", __pyx_f[0], 776, 0, __PYX_ERR(0, 776, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":687 + /* "pysam/libcbcf.pyx":777 * * cdef bcf_format_get_value(VariantRecordSample sample, key): * if sample is None: # <<<<<<<<<<<<<< @@ -12060,20 +12586,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":688 + /* "pysam/libcbcf.pyx":778 * cdef bcf_format_get_value(VariantRecordSample sample, key): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = sample.record.header.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 688, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 778, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 688, __pyx_L1_error) + __PYX_ERR(0, 778, __pyx_L1_error) - /* "pysam/libcbcf.pyx":687 + /* "pysam/libcbcf.pyx":777 * * cdef bcf_format_get_value(VariantRecordSample sample, key): * if sample is None: # <<<<<<<<<<<<<< @@ -12082,7 +12608,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":690 + /* "pysam/libcbcf.pyx":780 * raise ValueError('sample must not be None') * * cdef bcf_hdr_t *hdr = sample.record.header.ptr # <<<<<<<<<<<<<< @@ -12092,7 +12618,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 __pyx_t_4 = __pyx_v_sample->record->header->ptr; __pyx_v_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":691 + /* "pysam/libcbcf.pyx":781 * * cdef bcf_hdr_t *hdr = sample.record.header.ptr * cdef bcf1_t *r = sample.record.ptr # <<<<<<<<<<<<<< @@ -12102,7 +12628,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 __pyx_t_5 = __pyx_v_sample->record->ptr; __pyx_v_r = __pyx_t_5; - /* "pysam/libcbcf.pyx":695 + /* "pysam/libcbcf.pyx":785 * cdef int scalar * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< @@ -12112,20 +12638,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_ALL) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":696 + /* "pysam/libcbcf.pyx":786 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 696, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 786, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 696, __pyx_L1_error) + __PYX_ERR(0, 786, __pyx_L1_error) - /* "pysam/libcbcf.pyx":695 + /* "pysam/libcbcf.pyx":785 * cdef int scalar * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< @@ -12134,37 +12660,37 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":698 + /* "pysam/libcbcf.pyx":788 * raise ValueError('Error unpacking VariantRecord') * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 698, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 788, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_bkey = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":699 + /* "pysam/libcbcf.pyx":789 * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) # <<<<<<<<<<<<<< * * if not fmt or not fmt.p: */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 699, __pyx_L1_error) + __PYX_ERR(0, 789, __pyx_L1_error) } - __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 699, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 789, __pyx_L1_error) __pyx_v_fmt = bcf_get_fmt(__pyx_v_hdr, __pyx_v_r, __pyx_t_6); - /* "pysam/libcbcf.pyx":701 + /* "pysam/libcbcf.pyx":791 * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * * if not fmt or not fmt.p: # <<<<<<<<<<<<<< - * raise KeyError('invalid FORMAT') + * raise KeyError('invalid FORMAT: {}'.format(key)) * */ __pyx_t_1 = ((!(__pyx_v_fmt != 0)) != 0); @@ -12178,30 +12704,76 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 __pyx_L6_bool_binop_done:; if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":702 + /* "pysam/libcbcf.pyx":792 * * if not fmt or not fmt.p: - * raise KeyError('invalid FORMAT') # <<<<<<<<<<<<<< + * raise KeyError('invalid FORMAT: {}'.format(key)) # <<<<<<<<<<<<<< * * if is_gt_fmt(hdr, fmt.id): */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 702, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_FORMAT, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 792, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_8) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 792, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_key}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 792, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_key}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 792, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 792, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_key); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 792, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 792, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 702, __pyx_L1_error) + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 792, __pyx_L1_error) - /* "pysam/libcbcf.pyx":701 + /* "pysam/libcbcf.pyx":791 * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * * if not fmt or not fmt.p: # <<<<<<<<<<<<<< - * raise KeyError('invalid FORMAT') + * raise KeyError('invalid FORMAT: {}'.format(key)) * */ } - /* "pysam/libcbcf.pyx":704 - * raise KeyError('invalid FORMAT') + /* "pysam/libcbcf.pyx":794 + * raise KeyError('invalid FORMAT: {}'.format(key)) * * if is_gt_fmt(hdr, fmt.id): # <<<<<<<<<<<<<< * return bcf_format_get_allele_indices(sample) @@ -12210,22 +12782,22 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 __pyx_t_2 = (__pyx_f_5pysam_7libcbcf_is_gt_fmt(__pyx_v_hdr, __pyx_v_fmt->id) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":705 + /* "pysam/libcbcf.pyx":795 * * if is_gt_fmt(hdr, fmt.id): * return bcf_format_get_allele_indices(sample) # <<<<<<<<<<<<<< * - * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &count, &scalar) + * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &count, &scalar, sample.index) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(__pyx_v_sample); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 705, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(__pyx_v_sample); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 795, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":704 - * raise KeyError('invalid FORMAT') + /* "pysam/libcbcf.pyx":794 + * raise KeyError('invalid FORMAT: {}'.format(key)) * * if is_gt_fmt(hdr, fmt.id): # <<<<<<<<<<<<<< * return bcf_format_get_allele_indices(sample) @@ -12233,22 +12805,22 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":707 + /* "pysam/libcbcf.pyx":797 * return bcf_format_get_allele_indices(sample) * - * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &count, &scalar) # <<<<<<<<<<<<<< + * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &count, &scalar, sample.index) # <<<<<<<<<<<<<< * * if fmt.p and fmt.n and fmt.size: */ - __pyx_t_3 = ((PyObject *)__pyx_v_sample->record); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_get_value_count(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_3), BCF_HL_FMT, __pyx_v_fmt->id, (&__pyx_v_count), (&__pyx_v_scalar)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 707, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_7 = ((PyObject *)__pyx_v_sample->record); + __Pyx_INCREF(__pyx_t_7); + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_get_value_count(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_7), BCF_HL_FMT, __pyx_v_fmt->id, (&__pyx_v_count), (&__pyx_v_scalar), __pyx_v_sample->index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 797, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":709 - * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &count, &scalar) + /* "pysam/libcbcf.pyx":799 + * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &count, &scalar, sample.index) * * if fmt.p and fmt.n and fmt.size: # <<<<<<<<<<<<<< * return bcf_array_to_object(fmt.p + sample.index * fmt.size, fmt.type, fmt.n, count, scalar) @@ -12271,7 +12843,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 __pyx_L10_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":710 + /* "pysam/libcbcf.pyx":800 * * if fmt.p and fmt.n and fmt.size: * return bcf_array_to_object(fmt.p + sample.index * fmt.size, fmt.type, fmt.n, count, scalar) # <<<<<<<<<<<<<< @@ -12279,14 +12851,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 * return None */ __Pyx_XDECREF(__pyx_r); - __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_array_to_object((__pyx_v_fmt->p + (__pyx_v_sample->index * __pyx_v_fmt->size)), __pyx_v_fmt->type, __pyx_v_fmt->n, __pyx_v_count, __pyx_v_scalar); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 710, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_r = __pyx_t_7; - __pyx_t_7 = 0; + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_array_to_object((__pyx_v_fmt->p + (__pyx_v_sample->index * __pyx_v_fmt->size)), __pyx_v_fmt->type, __pyx_v_fmt->n, __pyx_v_count, __pyx_v_scalar); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 800, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":709 - * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &count, &scalar) + /* "pysam/libcbcf.pyx":799 + * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &count, &scalar, sample.index) * * if fmt.p and fmt.n and fmt.size: # <<<<<<<<<<<<<< * return bcf_array_to_object(fmt.p + sample.index * fmt.size, fmt.type, fmt.n, count, scalar) @@ -12294,7 +12866,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":711 + /* "pysam/libcbcf.pyx":801 * if fmt.p and fmt.n and fmt.size: * return bcf_array_to_object(fmt.p + sample.index * fmt.size, fmt.type, fmt.n, count, scalar) * elif scalar: # <<<<<<<<<<<<<< @@ -12304,7 +12876,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 __pyx_t_2 = (__pyx_v_scalar != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":712 + /* "pysam/libcbcf.pyx":802 * return bcf_array_to_object(fmt.p + sample.index * fmt.size, fmt.type, fmt.n, count, scalar) * elif scalar: * return None # <<<<<<<<<<<<<< @@ -12315,7 +12887,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":711 + /* "pysam/libcbcf.pyx":801 * if fmt.p and fmt.n and fmt.size: * return bcf_array_to_object(fmt.p + sample.index * fmt.size, fmt.type, fmt.n, count, scalar) * elif scalar: # <<<<<<<<<<<<<< @@ -12324,7 +12896,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":713 + /* "pysam/libcbcf.pyx":803 * elif scalar: * return None * elif count <= 0: # <<<<<<<<<<<<<< @@ -12334,7 +12906,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 __pyx_t_2 = ((__pyx_v_count <= 0) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":714 + /* "pysam/libcbcf.pyx":804 * return None * elif count <= 0: * return () # <<<<<<<<<<<<<< @@ -12346,7 +12918,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 __pyx_r = __pyx_empty_tuple; goto __pyx_L0; - /* "pysam/libcbcf.pyx":713 + /* "pysam/libcbcf.pyx":803 * elif scalar: * return None * elif count <= 0: # <<<<<<<<<<<<<< @@ -12355,7 +12927,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":716 + /* "pysam/libcbcf.pyx":806 * return () * else: * return (None,)*count # <<<<<<<<<<<<<< @@ -12364,17 +12936,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_count); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 716, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = PyNumber_Multiply(__pyx_tuple__38, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 716, __pyx_L1_error) + __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_count); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 806, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_7 = PyNumber_Multiply(__pyx_tuple__36, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; goto __pyx_L0; } - /* "pysam/libcbcf.pyx":686 + /* "pysam/libcbcf.pyx":776 * * * cdef bcf_format_get_value(VariantRecordSample sample, key): # <<<<<<<<<<<<<< @@ -12386,6 +12958,8 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); __Pyx_AddTraceback("pysam.libcbcf.bcf_format_get_value", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; @@ -12396,7 +12970,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_value(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libcbcf.pyx":719 +/* "pysam/libcbcf.pyx":809 * * * cdef bcf_format_set_value(VariantRecordSample sample, key, value): # <<<<<<<<<<<<<< @@ -12420,7 +12994,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 Py_ssize_t __pyx_v_value_count; Py_ssize_t __pyx_v_alloc_len; Py_ssize_t __pyx_v_dst_size; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; bcf_fmt_t *__pyx_v_fmt; PyObject *__pyx_v_values = NULL; PyObject *__pyx_v_new_values = NULL; @@ -12437,18 +13011,21 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 int __pyx_t_7; char const *__pyx_t_8; PyObject *__pyx_t_9 = NULL; - Py_ssize_t __pyx_t_10; - Py_ssize_t __pyx_t_11; - long __pyx_t_12; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + Py_ssize_t __pyx_t_12; Py_ssize_t __pyx_t_13; - char *__pyx_t_14; + long __pyx_t_14; Py_ssize_t __pyx_t_15; - char const *__pyx_t_16; + uint32_t __pyx_t_16; + char *__pyx_t_17; + Py_ssize_t __pyx_t_18; + char const *__pyx_t_19; __Pyx_RefNannySetupContext("bcf_format_set_value", 0); - __Pyx_TraceCall("bcf_format_set_value", __pyx_f[0], 719, 0, __PYX_ERR(0, 719, __pyx_L1_error)); + __Pyx_TraceCall("bcf_format_set_value", __pyx_f[0], 809, 0, __PYX_ERR(0, 809, __pyx_L1_error)); __Pyx_INCREF(__pyx_v_value); - /* "pysam/libcbcf.pyx":720 + /* "pysam/libcbcf.pyx":810 * * cdef bcf_format_set_value(VariantRecordSample sample, key, value): * if sample is None: # <<<<<<<<<<<<<< @@ -12459,20 +13036,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":721 + /* "pysam/libcbcf.pyx":811 * cdef bcf_format_set_value(VariantRecordSample sample, key, value): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * - * cdef bcf_hdr_t *hdr = sample.record.header.ptr + * if key == 'phased': */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 721, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 811, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 721, __pyx_L1_error) + __PYX_ERR(0, 811, __pyx_L1_error) - /* "pysam/libcbcf.pyx":720 + /* "pysam/libcbcf.pyx":810 * * cdef bcf_format_set_value(VariantRecordSample sample, key, value): * if sample is None: # <<<<<<<<<<<<<< @@ -12481,9 +13058,52 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":723 + /* "pysam/libcbcf.pyx":813 * raise ValueError('sample must not be None') * + * if key == 'phased': # <<<<<<<<<<<<<< + * sample.phased = bool(value) + * return + */ + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_n_s_phased, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 813, __pyx_L1_error) + if (__pyx_t_2) { + + /* "pysam/libcbcf.pyx":814 + * + * if key == 'phased': + * sample.phased = bool(value) # <<<<<<<<<<<<<< + * return + * + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 814, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBool_FromLong((!(!__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 814, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_sample), __pyx_n_s_phased, __pyx_t_3) < 0) __PYX_ERR(0, 814, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":815 + * if key == 'phased': + * sample.phased = bool(value) + * return # <<<<<<<<<<<<<< + * + * cdef bcf_hdr_t *hdr = sample.record.header.ptr + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":813 + * raise ValueError('sample must not be None') + * + * if key == 'phased': # <<<<<<<<<<<<<< + * sample.phased = bool(value) + * return + */ + } + + /* "pysam/libcbcf.pyx":817 + * return + * * cdef bcf_hdr_t *hdr = sample.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = sample.record.ptr * cdef int fmt_id @@ -12491,7 +13111,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_4 = __pyx_v_sample->record->header->ptr; __pyx_v_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":724 + /* "pysam/libcbcf.pyx":818 * * cdef bcf_hdr_t *hdr = sample.record.header.ptr * cdef bcf1_t *r = sample.record.ptr # <<<<<<<<<<<<<< @@ -12501,7 +13121,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_5 = __pyx_v_sample->record->ptr; __pyx_v_r = __pyx_t_5; - /* "pysam/libcbcf.pyx":728 + /* "pysam/libcbcf.pyx":822 * cdef vdict_t *d * cdef khiter_t k * cdef int fmt_type, scalar, realloc, dst_type, vlen = 0 # <<<<<<<<<<<<<< @@ -12510,7 +13130,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ __pyx_v_vlen = 0; - /* "pysam/libcbcf.pyx":731 + /* "pysam/libcbcf.pyx":825 * cdef ssize_t i, n, value_count, alloc_size, alloc_len, dst_size * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< @@ -12520,20 +13140,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_ALL) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":732 + /* "pysam/libcbcf.pyx":826 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 732, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 826, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 732, __pyx_L1_error) + __PYX_ERR(0, 826, __pyx_L1_error) - /* "pysam/libcbcf.pyx":731 + /* "pysam/libcbcf.pyx":825 * cdef ssize_t i, n, value_count, alloc_size, alloc_len, dst_size * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< @@ -12542,33 +13162,33 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":734 + /* "pysam/libcbcf.pyx":828 * raise ValueError('Error unpacking VariantRecord') * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 734, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 828, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_bkey = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":735 + /* "pysam/libcbcf.pyx":829 * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) # <<<<<<<<<<<<<< * * if fmt: */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 735, __pyx_L1_error) + __PYX_ERR(0, 829, __pyx_L1_error) } - __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 735, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 829, __pyx_L1_error) __pyx_v_fmt = bcf_get_fmt(__pyx_v_hdr, __pyx_v_r, __pyx_t_6); - /* "pysam/libcbcf.pyx":737 + /* "pysam/libcbcf.pyx":831 * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * * if fmt: # <<<<<<<<<<<<<< @@ -12578,7 +13198,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_2 = (__pyx_v_fmt != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":738 + /* "pysam/libcbcf.pyx":832 * * if fmt: * fmt_id = fmt.id # <<<<<<<<<<<<<< @@ -12588,17 +13208,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_7 = __pyx_v_fmt->id; __pyx_v_fmt_id = __pyx_t_7; - /* "pysam/libcbcf.pyx":737 + /* "pysam/libcbcf.pyx":831 * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * * if fmt: # <<<<<<<<<<<<<< * fmt_id = fmt.id * else: */ - goto __pyx_L5; + goto __pyx_L6; } - /* "pysam/libcbcf.pyx":740 + /* "pysam/libcbcf.pyx":834 * fmt_id = fmt.id * else: * d = hdr.dict[BCF_DT_ID] # <<<<<<<<<<<<<< @@ -12608,7 +13228,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 /*else*/ { __pyx_v_d = ((vdict_t *)(__pyx_v_hdr->dict[BCF_DT_ID])); - /* "pysam/libcbcf.pyx":741 + /* "pysam/libcbcf.pyx":835 * else: * d = hdr.dict[BCF_DT_ID] * k = kh_get_vdict(d, bkey) # <<<<<<<<<<<<<< @@ -12617,53 +13237,99 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 741, __pyx_L1_error) + __PYX_ERR(0, 835, __pyx_L1_error) } - __pyx_t_8 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 741, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 835, __pyx_L1_error) __pyx_v_k = kh_get_vdict(__pyx_v_d, __pyx_t_8); - /* "pysam/libcbcf.pyx":743 + /* "pysam/libcbcf.pyx":837 * k = kh_get_vdict(d, bkey) * * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_FMT] & 0xF == 0xF: # <<<<<<<<<<<<<< - * raise KeyError('unknown format') + * raise KeyError('unknown format: {}'.format(key)) * */ __pyx_t_1 = ((__pyx_v_k == kh_end(__pyx_v_d)) != 0); if (!__pyx_t_1) { } else { __pyx_t_2 = __pyx_t_1; - goto __pyx_L7_bool_binop_done; + goto __pyx_L8_bool_binop_done; } __pyx_t_1 = ((((kh_val(__pyx_v_d, __pyx_v_k).info[BCF_HL_FMT]) & 0xF) == 0xF) != 0); __pyx_t_2 = __pyx_t_1; - __pyx_L7_bool_binop_done:; + __pyx_L8_bool_binop_done:; if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":744 + /* "pysam/libcbcf.pyx":838 * * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_FMT] & 0xF == 0xF: - * raise KeyError('unknown format') # <<<<<<<<<<<<<< + * raise KeyError('unknown format: {}'.format(key)) # <<<<<<<<<<<<<< * * fmt_id = kh_val_vdict(d, k).id */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unknown_format, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + if (!__pyx_t_10) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_key); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 838, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 744, __pyx_L1_error) + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 838, __pyx_L1_error) - /* "pysam/libcbcf.pyx":743 + /* "pysam/libcbcf.pyx":837 * k = kh_get_vdict(d, bkey) * * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_FMT] & 0xF == 0xF: # <<<<<<<<<<<<<< - * raise KeyError('unknown format') + * raise KeyError('unknown format: {}'.format(key)) * */ } - /* "pysam/libcbcf.pyx":746 - * raise KeyError('unknown format') + /* "pysam/libcbcf.pyx":840 + * raise KeyError('unknown format: {}'.format(key)) * * fmt_id = kh_val_vdict(d, k).id # <<<<<<<<<<<<<< * @@ -12672,9 +13338,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_7 = kh_val(__pyx_v_d, __pyx_v_k).id; __pyx_v_fmt_id = __pyx_t_7; } - __pyx_L5:; + __pyx_L6:; - /* "pysam/libcbcf.pyx":748 + /* "pysam/libcbcf.pyx":842 * fmt_id = kh_val_vdict(d, k).id * * if not check_header_id(hdr, BCF_HL_FMT, fmt_id): # <<<<<<<<<<<<<< @@ -12684,20 +13350,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_2 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_FMT, __pyx_v_fmt_id) != 0)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":749 + /* "pysam/libcbcf.pyx":843 * * if not check_header_id(hdr, BCF_HL_FMT, fmt_id): * raise ValueError('Invalid header') # <<<<<<<<<<<<<< * * fmt_type = bcf_hdr_id2type(hdr, BCF_HL_FMT, fmt_id) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 749, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 749, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 843, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 843, __pyx_L1_error) - /* "pysam/libcbcf.pyx":748 + /* "pysam/libcbcf.pyx":842 * fmt_id = kh_val_vdict(d, k).id * * if not check_header_id(hdr, BCF_HL_FMT, fmt_id): # <<<<<<<<<<<<<< @@ -12706,7 +13372,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":751 + /* "pysam/libcbcf.pyx":845 * raise ValueError('Invalid header') * * fmt_type = bcf_hdr_id2type(hdr, BCF_HL_FMT, fmt_id) # <<<<<<<<<<<<<< @@ -12715,7 +13381,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ __pyx_v_fmt_type = bcf_hdr_id2type(__pyx_v_hdr, BCF_HL_FMT, __pyx_v_fmt_id); - /* "pysam/libcbcf.pyx":753 + /* "pysam/libcbcf.pyx":847 * fmt_type = bcf_hdr_id2type(hdr, BCF_HL_FMT, fmt_id) * * if fmt_type == BCF_HT_FLAG: # <<<<<<<<<<<<<< @@ -12725,20 +13391,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_2 = ((__pyx_v_fmt_type == BCF_HT_FLAG) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":754 + /* "pysam/libcbcf.pyx":848 * * if fmt_type == BCF_HT_FLAG: * raise ValueError('Flag types are not allowed on FORMATs') # <<<<<<<<<<<<<< * * if is_gt_fmt(hdr, fmt_id): */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 754, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 754, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 848, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 848, __pyx_L1_error) - /* "pysam/libcbcf.pyx":753 + /* "pysam/libcbcf.pyx":847 * fmt_type = bcf_hdr_id2type(hdr, BCF_HL_FMT, fmt_id) * * if fmt_type == BCF_HT_FLAG: # <<<<<<<<<<<<<< @@ -12747,7 +13413,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":756 + /* "pysam/libcbcf.pyx":850 * raise ValueError('Flag types are not allowed on FORMATs') * * if is_gt_fmt(hdr, fmt_id): # <<<<<<<<<<<<<< @@ -12757,31 +13423,31 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_2 = (__pyx_f_5pysam_7libcbcf_is_gt_fmt(__pyx_v_hdr, __pyx_v_fmt_id) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":757 + /* "pysam/libcbcf.pyx":851 * * if is_gt_fmt(hdr, fmt_id): * value = bcf_encode_alleles(sample.record, value) # <<<<<<<<<<<<<< * # KBJ: GT field is considered to be a string by the VCF header but BCF represents it as INT. * fmt_type = BCF_HT_INT */ - __pyx_t_3 = ((PyObject *)__pyx_v_sample->record); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_encode_alleles(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_3), __pyx_v_value); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 757, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_9); - __pyx_t_9 = 0; + __pyx_t_9 = ((PyObject *)__pyx_v_sample->record); + __Pyx_INCREF(__pyx_t_9); + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_encode_alleles(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_9), __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 851, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":759 + /* "pysam/libcbcf.pyx":853 * value = bcf_encode_alleles(sample.record, value) * # KBJ: GT field is considered to be a string by the VCF header but BCF represents it as INT. * fmt_type = BCF_HT_INT # <<<<<<<<<<<<<< * - * values = bcf_check_values(sample.record, value, BCF_HL_FMT, fmt_type, fmt_id, + * values = bcf_check_values(sample.record, value, sample.index, */ __pyx_v_fmt_type = BCF_HT_INT; - /* "pysam/libcbcf.pyx":756 + /* "pysam/libcbcf.pyx":850 * raise ValueError('Flag types are not allowed on FORMATs') * * if is_gt_fmt(hdr, fmt_id): # <<<<<<<<<<<<<< @@ -12790,19 +13456,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":761 + /* "pysam/libcbcf.pyx":855 * fmt_type = BCF_HT_INT * - * values = bcf_check_values(sample.record, value, BCF_HL_FMT, fmt_type, fmt_id, # <<<<<<<<<<<<<< + * values = bcf_check_values(sample.record, value, sample.index, # <<<<<<<<<<<<<< + * BCF_HL_FMT, fmt_type, fmt_id, * fmt.type if fmt else -1, - * fmt.n if fmt else -1, */ - __pyx_t_9 = ((PyObject *)__pyx_v_sample->record); - __Pyx_INCREF(__pyx_t_9); + __pyx_t_3 = ((PyObject *)__pyx_v_sample->record); + __Pyx_INCREF(__pyx_t_3); - /* "pysam/libcbcf.pyx":762 - * - * values = bcf_check_values(sample.record, value, BCF_HL_FMT, fmt_type, fmt_id, + /* "pysam/libcbcf.pyx":857 + * values = bcf_check_values(sample.record, value, sample.index, + * BCF_HL_FMT, fmt_type, fmt_id, * fmt.type if fmt else -1, # <<<<<<<<<<<<<< * fmt.n if fmt else -1, * &value_count, &scalar, &realloc) @@ -12813,33 +13479,33 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_7 = -1; } - /* "pysam/libcbcf.pyx":763 - * values = bcf_check_values(sample.record, value, BCF_HL_FMT, fmt_type, fmt_id, + /* "pysam/libcbcf.pyx":858 + * BCF_HL_FMT, fmt_type, fmt_id, * fmt.type if fmt else -1, * fmt.n if fmt else -1, # <<<<<<<<<<<<<< * &value_count, &scalar, &realloc) * */ if ((__pyx_v_fmt != 0)) { - __pyx_t_10 = __pyx_v_fmt->n; + __pyx_t_12 = __pyx_v_fmt->n; } else { - __pyx_t_10 = -1L; + __pyx_t_12 = -1L; } - /* "pysam/libcbcf.pyx":761 + /* "pysam/libcbcf.pyx":855 * fmt_type = BCF_HT_INT * - * values = bcf_check_values(sample.record, value, BCF_HL_FMT, fmt_type, fmt_id, # <<<<<<<<<<<<<< + * values = bcf_check_values(sample.record, value, sample.index, # <<<<<<<<<<<<<< + * BCF_HL_FMT, fmt_type, fmt_id, * fmt.type if fmt else -1, - * fmt.n if fmt else -1, */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_check_values(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_9), __pyx_v_value, BCF_HL_FMT, __pyx_v_fmt_type, __pyx_v_fmt_id, __pyx_t_7, __pyx_t_10, (&__pyx_v_value_count), (&__pyx_v_scalar), (&__pyx_v_realloc)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 761, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_v_values = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_check_values(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_3), __pyx_v_value, __pyx_v_sample->index, BCF_HL_FMT, __pyx_v_fmt_type, __pyx_v_fmt_id, __pyx_t_7, __pyx_t_12, (&__pyx_v_value_count), (&__pyx_v_scalar), (&__pyx_v_realloc)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 855, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_values = __pyx_t_9; + __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":766 + /* "pysam/libcbcf.pyx":861 * &value_count, &scalar, &realloc) * * vlen = value_count < 0 # <<<<<<<<<<<<<< @@ -12848,17 +13514,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ __pyx_v_vlen = (__pyx_v_value_count < 0); - /* "pysam/libcbcf.pyx":767 + /* "pysam/libcbcf.pyx":862 * * vlen = value_count < 0 * value_count = len(values) # <<<<<<<<<<<<<< * * # If we can, write updated values to existing allocated storage */ - __pyx_t_11 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 767, __pyx_L1_error) - __pyx_v_value_count = __pyx_t_11; + __pyx_t_13 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 862, __pyx_L1_error) + __pyx_v_value_count = __pyx_t_13; - /* "pysam/libcbcf.pyx":770 + /* "pysam/libcbcf.pyx":865 * * # If we can, write updated values to existing allocated storage * if fmt and not realloc: # <<<<<<<<<<<<<< @@ -12869,14 +13535,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 if (__pyx_t_1) { } else { __pyx_t_2 = __pyx_t_1; - goto __pyx_L13_bool_binop_done; + goto __pyx_L14_bool_binop_done; } __pyx_t_1 = ((!(__pyx_v_realloc != 0)) != 0); __pyx_t_2 = __pyx_t_1; - __pyx_L13_bool_binop_done:; + __pyx_L14_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":771 + /* "pysam/libcbcf.pyx":866 * # If we can, write updated values to existing allocated storage * if fmt and not realloc: * r.d.indiv_dirty = 1 # <<<<<<<<<<<<<< @@ -12885,18 +13551,18 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ __pyx_v_r->d.indiv_dirty = 1; - /* "pysam/libcbcf.pyx":772 + /* "pysam/libcbcf.pyx":867 * if fmt and not realloc: * r.d.indiv_dirty = 1 * bcf_object_to_array(values, fmt.p + sample.index * fmt.size, fmt.type, fmt.n, vlen) # <<<<<<<<<<<<<< * return * */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_object_to_array(__pyx_v_values, (__pyx_v_fmt->p + (__pyx_v_sample->index * __pyx_v_fmt->size)), __pyx_v_fmt->type, __pyx_v_fmt->n, __pyx_v_vlen); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 772, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_object_to_array(__pyx_v_values, (__pyx_v_fmt->p + (__pyx_v_sample->index * __pyx_v_fmt->size)), __pyx_v_fmt->type, __pyx_v_fmt->n, __pyx_v_vlen); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 867, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":773 + /* "pysam/libcbcf.pyx":868 * r.d.indiv_dirty = 1 * bcf_object_to_array(values, fmt.p + sample.index * fmt.size, fmt.type, fmt.n, vlen) * return # <<<<<<<<<<<<<< @@ -12907,7 +13573,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":770 + /* "pysam/libcbcf.pyx":865 * * # If we can, write updated values to existing allocated storage * if fmt and not realloc: # <<<<<<<<<<<<<< @@ -12916,23 +13582,23 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":775 + /* "pysam/libcbcf.pyx":870 * return * * alloc_len = max(1, value_count) # <<<<<<<<<<<<<< * if fmt and fmt.n > alloc_len: * alloc_len = fmt.n */ - __pyx_t_10 = __pyx_v_value_count; - __pyx_t_12 = 1; - if (((__pyx_t_10 > __pyx_t_12) != 0)) { - __pyx_t_13 = __pyx_t_10; + __pyx_t_12 = __pyx_v_value_count; + __pyx_t_14 = 1; + if (((__pyx_t_12 > __pyx_t_14) != 0)) { + __pyx_t_15 = __pyx_t_12; } else { - __pyx_t_13 = __pyx_t_12; + __pyx_t_15 = __pyx_t_14; } - __pyx_v_alloc_len = __pyx_t_13; + __pyx_v_alloc_len = __pyx_t_15; - /* "pysam/libcbcf.pyx":776 + /* "pysam/libcbcf.pyx":871 * * alloc_len = max(1, value_count) * if fmt and fmt.n > alloc_len: # <<<<<<<<<<<<<< @@ -12943,24 +13609,24 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 if (__pyx_t_1) { } else { __pyx_t_2 = __pyx_t_1; - goto __pyx_L16_bool_binop_done; + goto __pyx_L17_bool_binop_done; } __pyx_t_1 = ((__pyx_v_fmt->n > __pyx_v_alloc_len) != 0); __pyx_t_2 = __pyx_t_1; - __pyx_L16_bool_binop_done:; + __pyx_L17_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":777 + /* "pysam/libcbcf.pyx":872 * alloc_len = max(1, value_count) * if fmt and fmt.n > alloc_len: * alloc_len = fmt.n # <<<<<<<<<<<<<< * - * n = bcf_hdr_nsamples(hdr) + * n = r.n_sample */ __pyx_t_7 = __pyx_v_fmt->n; __pyx_v_alloc_len = __pyx_t_7; - /* "pysam/libcbcf.pyx":776 + /* "pysam/libcbcf.pyx":871 * * alloc_len = max(1, value_count) * if fmt and fmt.n > alloc_len: # <<<<<<<<<<<<<< @@ -12969,38 +13635,39 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":779 + /* "pysam/libcbcf.pyx":874 * alloc_len = fmt.n * - * n = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< + * n = r.n_sample # <<<<<<<<<<<<<< * new_values = bcf_empty_array(fmt_type, n*alloc_len, vlen) * cdef char *valp = new_values */ - __pyx_v_n = bcf_hdr_nsamples(__pyx_v_hdr); + __pyx_t_16 = __pyx_v_r->n_sample; + __pyx_v_n = __pyx_t_16; - /* "pysam/libcbcf.pyx":780 + /* "pysam/libcbcf.pyx":875 * - * n = bcf_hdr_nsamples(hdr) + * n = r.n_sample * new_values = bcf_empty_array(fmt_type, n*alloc_len, vlen) # <<<<<<<<<<<<<< * cdef char *valp = new_values * */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_empty_array(__pyx_v_fmt_type, (__pyx_v_n * __pyx_v_alloc_len), __pyx_v_vlen); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 780, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_new_values = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_empty_array(__pyx_v_fmt_type, (__pyx_v_n * __pyx_v_alloc_len), __pyx_v_vlen); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 875, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_v_new_values = __pyx_t_9; + __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":781 - * n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":876 + * n = r.n_sample * new_values = bcf_empty_array(fmt_type, n*alloc_len, vlen) * cdef char *valp = new_values # <<<<<<<<<<<<<< * * if fmt_type == BCF_HT_INT: */ - __pyx_t_14 = __Pyx_PyObject_AsWritableString(__pyx_v_new_values); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) __PYX_ERR(0, 781, __pyx_L1_error) - __pyx_v_valp = ((char *)__pyx_t_14); + __pyx_t_17 = __Pyx_PyObject_AsWritableString(__pyx_v_new_values); if (unlikely((!__pyx_t_17) && PyErr_Occurred())) __PYX_ERR(0, 876, __pyx_L1_error) + __pyx_v_valp = ((char *)__pyx_t_17); - /* "pysam/libcbcf.pyx":783 + /* "pysam/libcbcf.pyx":878 * cdef char *valp = new_values * * if fmt_type == BCF_HT_INT: # <<<<<<<<<<<<<< @@ -13010,7 +13677,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_2 = ((__pyx_v_fmt_type == BCF_HT_INT) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":784 + /* "pysam/libcbcf.pyx":879 * * if fmt_type == BCF_HT_INT: * dst_type = BCF_BT_INT32 # <<<<<<<<<<<<<< @@ -13019,7 +13686,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ __pyx_v_dst_type = BCF_BT_INT32; - /* "pysam/libcbcf.pyx":785 + /* "pysam/libcbcf.pyx":880 * if fmt_type == BCF_HT_INT: * dst_type = BCF_BT_INT32 * dst_size = sizeof(int32_t) * alloc_len # <<<<<<<<<<<<<< @@ -13028,17 +13695,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ __pyx_v_dst_size = ((sizeof(int32_t)) * __pyx_v_alloc_len); - /* "pysam/libcbcf.pyx":783 + /* "pysam/libcbcf.pyx":878 * cdef char *valp = new_values * * if fmt_type == BCF_HT_INT: # <<<<<<<<<<<<<< * dst_type = BCF_BT_INT32 * dst_size = sizeof(int32_t) * alloc_len */ - goto __pyx_L18; + goto __pyx_L19; } - /* "pysam/libcbcf.pyx":786 + /* "pysam/libcbcf.pyx":881 * dst_type = BCF_BT_INT32 * dst_size = sizeof(int32_t) * alloc_len * elif fmt_type == BCF_HT_REAL: # <<<<<<<<<<<<<< @@ -13048,7 +13715,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_2 = ((__pyx_v_fmt_type == BCF_HT_REAL) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":787 + /* "pysam/libcbcf.pyx":882 * dst_size = sizeof(int32_t) * alloc_len * elif fmt_type == BCF_HT_REAL: * dst_type = BCF_BT_FLOAT # <<<<<<<<<<<<<< @@ -13057,7 +13724,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ __pyx_v_dst_type = BCF_BT_FLOAT; - /* "pysam/libcbcf.pyx":788 + /* "pysam/libcbcf.pyx":883 * elif fmt_type == BCF_HT_REAL: * dst_type = BCF_BT_FLOAT * dst_size = sizeof(float) * alloc_len # <<<<<<<<<<<<<< @@ -13066,17 +13733,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ __pyx_v_dst_size = ((sizeof(float)) * __pyx_v_alloc_len); - /* "pysam/libcbcf.pyx":786 + /* "pysam/libcbcf.pyx":881 * dst_type = BCF_BT_INT32 * dst_size = sizeof(int32_t) * alloc_len * elif fmt_type == BCF_HT_REAL: # <<<<<<<<<<<<<< * dst_type = BCF_BT_FLOAT * dst_size = sizeof(float) * alloc_len */ - goto __pyx_L18; + goto __pyx_L19; } - /* "pysam/libcbcf.pyx":789 + /* "pysam/libcbcf.pyx":884 * dst_type = BCF_BT_FLOAT * dst_size = sizeof(float) * alloc_len * elif fmt_type == BCF_HT_STR: # <<<<<<<<<<<<<< @@ -13086,7 +13753,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_t_2 = ((__pyx_v_fmt_type == BCF_HT_STR) != 0); if (likely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":790 + /* "pysam/libcbcf.pyx":885 * dst_size = sizeof(float) * alloc_len * elif fmt_type == BCF_HT_STR: * dst_type = BCF_BT_CHAR # <<<<<<<<<<<<<< @@ -13095,7 +13762,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ __pyx_v_dst_type = BCF_BT_CHAR; - /* "pysam/libcbcf.pyx":791 + /* "pysam/libcbcf.pyx":886 * elif fmt_type == BCF_HT_STR: * dst_type = BCF_BT_CHAR * dst_size = sizeof(char) * alloc_len # <<<<<<<<<<<<<< @@ -13104,17 +13771,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ __pyx_v_dst_size = ((sizeof(char)) * __pyx_v_alloc_len); - /* "pysam/libcbcf.pyx":789 + /* "pysam/libcbcf.pyx":884 * dst_type = BCF_BT_FLOAT * dst_size = sizeof(float) * alloc_len * elif fmt_type == BCF_HT_STR: # <<<<<<<<<<<<<< * dst_type = BCF_BT_CHAR * dst_size = sizeof(char) * alloc_len */ - goto __pyx_L18; + goto __pyx_L19; } - /* "pysam/libcbcf.pyx":793 + /* "pysam/libcbcf.pyx":888 * dst_size = sizeof(char) * alloc_len * else: * raise ValueError('Unsupported FORMAT type') # <<<<<<<<<<<<<< @@ -13122,15 +13789,15 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 * if fmt and n > 1: */ /*else*/ { - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 793, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 793, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 888, __pyx_L1_error) } - __pyx_L18:; + __pyx_L19:; - /* "pysam/libcbcf.pyx":795 + /* "pysam/libcbcf.pyx":890 * raise ValueError('Unsupported FORMAT type') * * if fmt and n > 1: # <<<<<<<<<<<<<< @@ -13141,38 +13808,38 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 if (__pyx_t_1) { } else { __pyx_t_2 = __pyx_t_1; - goto __pyx_L20_bool_binop_done; + goto __pyx_L21_bool_binop_done; } __pyx_t_1 = ((__pyx_v_n > 1) != 0); __pyx_t_2 = __pyx_t_1; - __pyx_L20_bool_binop_done:; + __pyx_L21_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":796 + /* "pysam/libcbcf.pyx":891 * * if fmt and n > 1: * for i in range(n): # <<<<<<<<<<<<<< * bcf_copy_expand_array(fmt.p + i*fmt.size, fmt.type, fmt.n, * valp + i*dst_size, dst_type, alloc_len, */ - __pyx_t_13 = __pyx_v_n; - __pyx_t_10 = __pyx_t_13; - for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_10; __pyx_t_15+=1) { - __pyx_v_i = __pyx_t_15; + __pyx_t_15 = __pyx_v_n; + __pyx_t_12 = __pyx_t_15; + for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_12; __pyx_t_18+=1) { + __pyx_v_i = __pyx_t_18; - /* "pysam/libcbcf.pyx":797 + /* "pysam/libcbcf.pyx":892 * if fmt and n > 1: * for i in range(n): * bcf_copy_expand_array(fmt.p + i*fmt.size, fmt.type, fmt.n, # <<<<<<<<<<<<<< * valp + i*dst_size, dst_type, alloc_len, * vlen) */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_copy_expand_array((__pyx_v_fmt->p + (__pyx_v_i * __pyx_v_fmt->size)), __pyx_v_fmt->type, __pyx_v_fmt->n, (__pyx_v_valp + (__pyx_v_i * __pyx_v_dst_size)), __pyx_v_dst_type, __pyx_v_alloc_len, __pyx_v_vlen); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 797, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_copy_expand_array((__pyx_v_fmt->p + (__pyx_v_i * __pyx_v_fmt->size)), __pyx_v_fmt->type, __pyx_v_fmt->n, (__pyx_v_valp + (__pyx_v_i * __pyx_v_dst_size)), __pyx_v_dst_type, __pyx_v_alloc_len, __pyx_v_vlen); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 892, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } - /* "pysam/libcbcf.pyx":795 + /* "pysam/libcbcf.pyx":890 * raise ValueError('Unsupported FORMAT type') * * if fmt and n > 1: # <<<<<<<<<<<<<< @@ -13181,18 +13848,18 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":801 + /* "pysam/libcbcf.pyx":896 * vlen) * * bcf_object_to_array(values, valp + sample.index*dst_size, dst_type, alloc_len, vlen) # <<<<<<<<<<<<<< * * if bcf_update_format(hdr, r, bkey, valp, (n*alloc_len), fmt_type) < 0: */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_object_to_array(__pyx_v_values, (__pyx_v_valp + (__pyx_v_sample->index * __pyx_v_dst_size)), __pyx_v_dst_type, __pyx_v_alloc_len, __pyx_v_vlen); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_object_to_array(__pyx_v_values, (__pyx_v_valp + (__pyx_v_sample->index * __pyx_v_dst_size)), __pyx_v_dst_type, __pyx_v_alloc_len, __pyx_v_vlen); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":803 + /* "pysam/libcbcf.pyx":898 * bcf_object_to_array(values, valp + sample.index*dst_size, dst_type, alloc_len, vlen) * * if bcf_update_format(hdr, r, bkey, valp, (n*alloc_len), fmt_type) < 0: # <<<<<<<<<<<<<< @@ -13201,26 +13868,26 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 803, __pyx_L1_error) + __PYX_ERR(0, 898, __pyx_L1_error) } - __pyx_t_16 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 803, __pyx_L1_error) - __pyx_t_2 = ((bcf_update_format(__pyx_v_hdr, __pyx_v_r, __pyx_t_16, __pyx_v_valp, ((int)(__pyx_v_n * __pyx_v_alloc_len)), __pyx_v_fmt_type) < 0) != 0); + __pyx_t_19 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 898, __pyx_L1_error) + __pyx_t_2 = ((bcf_update_format(__pyx_v_hdr, __pyx_v_r, __pyx_t_19, __pyx_v_valp, ((int)(__pyx_v_n * __pyx_v_alloc_len)), __pyx_v_fmt_type) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":804 + /* "pysam/libcbcf.pyx":899 * * if bcf_update_format(hdr, r, bkey, valp, (n*alloc_len), fmt_type) < 0: * raise ValueError('Unable to update format values') # <<<<<<<<<<<<<< * * */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__45, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 804, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 804, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 899, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 899, __pyx_L1_error) - /* "pysam/libcbcf.pyx":803 + /* "pysam/libcbcf.pyx":898 * bcf_object_to_array(values, valp + sample.index*dst_size, dst_type, alloc_len, vlen) * * if bcf_update_format(hdr, r, bkey, valp, (n*alloc_len), fmt_type) < 0: # <<<<<<<<<<<<<< @@ -13229,7 +13896,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":719 + /* "pysam/libcbcf.pyx":809 * * * cdef bcf_format_set_value(VariantRecordSample sample, key, value): # <<<<<<<<<<<<<< @@ -13243,6 +13910,8 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); __Pyx_AddTraceback("pysam.libcbcf.bcf_format_set_value", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; @@ -13256,7 +13925,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_set_value(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libcbcf.pyx":807 +/* "pysam/libcbcf.pyx":902 * * * cdef bcf_format_del_value(VariantRecordSample sample, key): # <<<<<<<<<<<<<< @@ -13269,7 +13938,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 bcf1_t *__pyx_v_r; Py_ssize_t __pyx_v_value_count; int __pyx_v_scalar; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; bcf_fmt_t *__pyx_v_fmt; PyObject *__pyx_v_null_value = NULL; PyObject *__pyx_r = NULL; @@ -13283,9 +13952,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 char const *__pyx_t_6; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("bcf_format_del_value", 0); - __Pyx_TraceCall("bcf_format_del_value", __pyx_f[0], 807, 0, __PYX_ERR(0, 807, __pyx_L1_error)); + __Pyx_TraceCall("bcf_format_del_value", __pyx_f[0], 902, 0, __PYX_ERR(0, 902, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":808 + /* "pysam/libcbcf.pyx":903 * * cdef bcf_format_del_value(VariantRecordSample sample, key): * if sample is None: # <<<<<<<<<<<<<< @@ -13296,20 +13965,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":809 + /* "pysam/libcbcf.pyx":904 * cdef bcf_format_del_value(VariantRecordSample sample, key): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = sample.record.header.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 809, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 904, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 809, __pyx_L1_error) + __PYX_ERR(0, 904, __pyx_L1_error) - /* "pysam/libcbcf.pyx":808 + /* "pysam/libcbcf.pyx":903 * * cdef bcf_format_del_value(VariantRecordSample sample, key): * if sample is None: # <<<<<<<<<<<<<< @@ -13318,7 +13987,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":811 + /* "pysam/libcbcf.pyx":906 * raise ValueError('sample must not be None') * * cdef bcf_hdr_t *hdr = sample.record.header.ptr # <<<<<<<<<<<<<< @@ -13328,7 +13997,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 __pyx_t_4 = __pyx_v_sample->record->header->ptr; __pyx_v_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":812 + /* "pysam/libcbcf.pyx":907 * * cdef bcf_hdr_t *hdr = sample.record.header.ptr * cdef bcf1_t *r = sample.record.ptr # <<<<<<<<<<<<<< @@ -13338,7 +14007,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 __pyx_t_5 = __pyx_v_sample->record->ptr; __pyx_v_r = __pyx_t_5; - /* "pysam/libcbcf.pyx":816 + /* "pysam/libcbcf.pyx":911 * cdef int scalar * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< @@ -13348,20 +14017,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_ALL) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":817 + /* "pysam/libcbcf.pyx":912 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 817, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 912, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 817, __pyx_L1_error) + __PYX_ERR(0, 912, __pyx_L1_error) - /* "pysam/libcbcf.pyx":816 + /* "pysam/libcbcf.pyx":911 * cdef int scalar * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< @@ -13370,33 +14039,33 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":819 + /* "pysam/libcbcf.pyx":914 * raise ValueError('Error unpacking VariantRecord') * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 819, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 914, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_bkey = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":820 + /* "pysam/libcbcf.pyx":915 * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) # <<<<<<<<<<<<<< * * if not fmt or not fmt.p: */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 820, __pyx_L1_error) + __PYX_ERR(0, 915, __pyx_L1_error) } - __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 820, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 915, __pyx_L1_error) __pyx_v_fmt = bcf_get_fmt(__pyx_v_hdr, __pyx_v_r, __pyx_t_6); - /* "pysam/libcbcf.pyx":822 + /* "pysam/libcbcf.pyx":917 * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * * if not fmt or not fmt.p: # <<<<<<<<<<<<<< @@ -13414,20 +14083,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 __pyx_L6_bool_binop_done:; if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":823 + /* "pysam/libcbcf.pyx":918 * * if not fmt or not fmt.p: * raise KeyError(key) # <<<<<<<<<<<<<< * - * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &value_count, &scalar) + * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &value_count, &scalar, sample.index) */ - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 823, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 918, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 823, __pyx_L1_error) + __PYX_ERR(0, 918, __pyx_L1_error) - /* "pysam/libcbcf.pyx":822 + /* "pysam/libcbcf.pyx":917 * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * * if not fmt or not fmt.p: # <<<<<<<<<<<<<< @@ -13436,22 +14105,22 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":825 + /* "pysam/libcbcf.pyx":920 * raise KeyError(key) * - * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &value_count, &scalar) # <<<<<<<<<<<<<< + * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &value_count, &scalar, sample.index) # <<<<<<<<<<<<<< * * if value_count <= 0: */ __pyx_t_3 = ((PyObject *)__pyx_v_sample->record); __Pyx_INCREF(__pyx_t_3); - __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_get_value_count(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_3), BCF_HL_FMT, __pyx_v_fmt->id, (&__pyx_v_value_count), (&__pyx_v_scalar)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 825, __pyx_L1_error) + __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_get_value_count(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_3), BCF_HL_FMT, __pyx_v_fmt->id, (&__pyx_v_value_count), (&__pyx_v_scalar), __pyx_v_sample->index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 920, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcbcf.pyx":827 - * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &value_count, &scalar) + /* "pysam/libcbcf.pyx":922 + * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &value_count, &scalar, sample.index) * * if value_count <= 0: # <<<<<<<<<<<<<< * null_value = () @@ -13460,7 +14129,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 __pyx_t_2 = ((__pyx_v_value_count <= 0) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":828 + /* "pysam/libcbcf.pyx":923 * * if value_count <= 0: * null_value = () # <<<<<<<<<<<<<< @@ -13470,8 +14139,8 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 __Pyx_INCREF(__pyx_empty_tuple); __pyx_v_null_value = __pyx_empty_tuple; - /* "pysam/libcbcf.pyx":827 - * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &value_count, &scalar) + /* "pysam/libcbcf.pyx":922 + * bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &value_count, &scalar, sample.index) * * if value_count <= 0: # <<<<<<<<<<<<<< * null_value = () @@ -13480,7 +14149,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 goto __pyx_L8; } - /* "pysam/libcbcf.pyx":829 + /* "pysam/libcbcf.pyx":924 * if value_count <= 0: * null_value = () * elif scalar: # <<<<<<<<<<<<<< @@ -13490,7 +14159,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 __pyx_t_2 = (__pyx_v_scalar != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":830 + /* "pysam/libcbcf.pyx":925 * null_value = () * elif scalar: * null_value = None # <<<<<<<<<<<<<< @@ -13500,7 +14169,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 __Pyx_INCREF(Py_None); __pyx_v_null_value = ((PyObject*)Py_None); - /* "pysam/libcbcf.pyx":829 + /* "pysam/libcbcf.pyx":924 * if value_count <= 0: * null_value = () * elif scalar: # <<<<<<<<<<<<<< @@ -13510,7 +14179,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 goto __pyx_L8; } - /* "pysam/libcbcf.pyx":832 + /* "pysam/libcbcf.pyx":927 * null_value = None * else: * null_value = (None,)*value_count # <<<<<<<<<<<<<< @@ -13518,9 +14187,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 * bcf_format_set_value(sample, bkey, null_value) */ /*else*/ { - __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_value_count); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 832, __pyx_L1_error) + __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_value_count); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 927, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = PyNumber_Multiply(__pyx_tuple__48, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 832, __pyx_L1_error) + __pyx_t_3 = PyNumber_Multiply(__pyx_tuple__45, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 927, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_v_null_value = ((PyObject*)__pyx_t_3); @@ -13528,18 +14197,18 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 } __pyx_L8:; - /* "pysam/libcbcf.pyx":834 + /* "pysam/libcbcf.pyx":929 * null_value = (None,)*value_count * * bcf_format_set_value(sample, bkey, null_value) # <<<<<<<<<<<<<< * * */ - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_format_set_value(__pyx_v_sample, __pyx_v_bkey, __pyx_v_null_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 834, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_format_set_value(__pyx_v_sample, __pyx_v_bkey, __pyx_v_null_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 929, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":807 + /* "pysam/libcbcf.pyx":902 * * * cdef bcf_format_del_value(VariantRecordSample sample, key): # <<<<<<<<<<<<<< @@ -13564,7 +14233,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_del_value(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libcbcf.pyx":837 +/* "pysam/libcbcf.pyx":932 * * * cdef bcf_format_get_allele_indices(VariantRecordSample sample): # <<<<<<<<<<<<<< @@ -13593,17 +14262,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ PyObject *__pyx_t_3 = NULL; bcf_hdr_t *__pyx_t_4; bcf1_t *__pyx_t_5; - bcf_fmt_t *__pyx_t_6; - uint32_t __pyx_t_7; + uint32_t __pyx_t_6; + bcf_fmt_t *__pyx_t_7; int __pyx_t_8; int __pyx_t_9; int __pyx_t_10; PyObject *__pyx_t_11 = NULL; int __pyx_t_12; __Pyx_RefNannySetupContext("bcf_format_get_allele_indices", 0); - __Pyx_TraceCall("bcf_format_get_allele_indices", __pyx_f[0], 837, 0, __PYX_ERR(0, 837, __pyx_L1_error)); + __Pyx_TraceCall("bcf_format_get_allele_indices", __pyx_f[0], 932, 0, __PYX_ERR(0, 932, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":838 + /* "pysam/libcbcf.pyx":933 * * cdef bcf_format_get_allele_indices(VariantRecordSample sample): * if sample is None: # <<<<<<<<<<<<<< @@ -13614,20 +14283,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":839 + /* "pysam/libcbcf.pyx":934 * cdef bcf_format_get_allele_indices(VariantRecordSample sample): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = sample.record.header.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__49, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 839, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 934, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 839, __pyx_L1_error) + __PYX_ERR(0, 934, __pyx_L1_error) - /* "pysam/libcbcf.pyx":838 + /* "pysam/libcbcf.pyx":933 * * cdef bcf_format_get_allele_indices(VariantRecordSample sample): * if sample is None: # <<<<<<<<<<<<<< @@ -13636,37 +14305,38 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ } - /* "pysam/libcbcf.pyx":841 + /* "pysam/libcbcf.pyx":936 * raise ValueError('sample must not be None') * * cdef bcf_hdr_t *hdr = sample.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = sample.record.ptr - * cdef int32_t n = bcf_hdr_nsamples(hdr) + * cdef int32_t n = r.n_sample */ __pyx_t_4 = __pyx_v_sample->record->header->ptr; __pyx_v_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":842 + /* "pysam/libcbcf.pyx":937 * * cdef bcf_hdr_t *hdr = sample.record.header.ptr * cdef bcf1_t *r = sample.record.ptr # <<<<<<<<<<<<<< - * cdef int32_t n = bcf_hdr_nsamples(hdr) + * cdef int32_t n = r.n_sample * */ __pyx_t_5 = __pyx_v_sample->record->ptr; __pyx_v_r = __pyx_t_5; - /* "pysam/libcbcf.pyx":843 + /* "pysam/libcbcf.pyx":938 * cdef bcf_hdr_t *hdr = sample.record.header.ptr * cdef bcf1_t *r = sample.record.ptr - * cdef int32_t n = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< + * cdef int32_t n = r.n_sample # <<<<<<<<<<<<<< * * if bcf_unpack(r, BCF_UN_ALL) < 0: */ - __pyx_v_n = bcf_hdr_nsamples(__pyx_v_hdr); + __pyx_t_6 = __pyx_v_r->n_sample; + __pyx_v_n = __pyx_t_6; - /* "pysam/libcbcf.pyx":845 - * cdef int32_t n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":940 + * cdef int32_t n = r.n_sample * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') @@ -13675,21 +14345,21 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_ALL) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":846 + /* "pysam/libcbcf.pyx":941 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * if sample.index < 0 or sample.index >= n or not r.n_fmt: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__50, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 846, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 941, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 846, __pyx_L1_error) + __PYX_ERR(0, 941, __pyx_L1_error) - /* "pysam/libcbcf.pyx":845 - * cdef int32_t n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":940 + * cdef int32_t n = r.n_sample * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') @@ -13697,7 +14367,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ } - /* "pysam/libcbcf.pyx":848 + /* "pysam/libcbcf.pyx":943 * raise ValueError('Error unpacking VariantRecord') * * if sample.index < 0 or sample.index >= n or not r.n_fmt: # <<<<<<<<<<<<<< @@ -13721,7 +14391,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_L6_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":849 + /* "pysam/libcbcf.pyx":944 * * if sample.index < 0 or sample.index >= n or not r.n_fmt: * return () # <<<<<<<<<<<<<< @@ -13733,7 +14403,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_r = __pyx_empty_tuple; goto __pyx_L0; - /* "pysam/libcbcf.pyx":848 + /* "pysam/libcbcf.pyx":943 * raise ValueError('Error unpacking VariantRecord') * * if sample.index < 0 or sample.index >= n or not r.n_fmt: # <<<<<<<<<<<<<< @@ -13742,17 +14412,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ } - /* "pysam/libcbcf.pyx":851 + /* "pysam/libcbcf.pyx":946 * return () * * cdef bcf_fmt_t *fmt0 = r.d.fmt # <<<<<<<<<<<<<< * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) * */ - __pyx_t_6 = __pyx_v_r->d.fmt; - __pyx_v_fmt0 = __pyx_t_6; + __pyx_t_7 = __pyx_v_r->d.fmt; + __pyx_v_fmt0 = __pyx_t_7; - /* "pysam/libcbcf.pyx":852 + /* "pysam/libcbcf.pyx":947 * * cdef bcf_fmt_t *fmt0 = r.d.fmt * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) # <<<<<<<<<<<<<< @@ -13761,7 +14431,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ __pyx_v_gt0 = __pyx_f_5pysam_7libcbcf_is_gt_fmt(__pyx_v_hdr, __pyx_v_fmt0->id); - /* "pysam/libcbcf.pyx":854 + /* "pysam/libcbcf.pyx":949 * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) * * if not gt0 or not fmt0.n: # <<<<<<<<<<<<<< @@ -13779,7 +14449,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_L10_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":855 + /* "pysam/libcbcf.pyx":950 * * if not gt0 or not fmt0.n: * return () # <<<<<<<<<<<<<< @@ -13791,7 +14461,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_r = __pyx_empty_tuple; goto __pyx_L0; - /* "pysam/libcbcf.pyx":854 + /* "pysam/libcbcf.pyx":949 * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) * * if not gt0 or not fmt0.n: # <<<<<<<<<<<<<< @@ -13800,29 +14470,29 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ } - /* "pysam/libcbcf.pyx":860 + /* "pysam/libcbcf.pyx":955 * cdef int16_t *data16 * cdef int32_t *data32 * cdef int32_t a, nalleles = r.n_allele # <<<<<<<<<<<<<< * cdef list alleles = [] * */ - __pyx_t_7 = __pyx_v_r->n_allele; - __pyx_v_nalleles = __pyx_t_7; + __pyx_t_6 = __pyx_v_r->n_allele; + __pyx_v_nalleles = __pyx_t_6; - /* "pysam/libcbcf.pyx":861 + /* "pysam/libcbcf.pyx":956 * cdef int32_t *data32 * cdef int32_t a, nalleles = r.n_allele * cdef list alleles = [] # <<<<<<<<<<<<<< * * if fmt0.type == BCF_BT_INT8: */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 861, __pyx_L1_error) + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 956, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_alleles = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":863 + /* "pysam/libcbcf.pyx":958 * cdef list alleles = [] * * if fmt0.type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -13832,7 +14502,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = ((__pyx_v_fmt0->type == BCF_BT_INT8) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":864 + /* "pysam/libcbcf.pyx":959 * * if fmt0.type == BCF_BT_INT8: * data8 = (fmt0.p + sample.index * fmt0.size) # <<<<<<<<<<<<<< @@ -13841,7 +14511,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ __pyx_v_data8 = ((int8_t *)(__pyx_v_fmt0->p + (__pyx_v_sample->index * __pyx_v_fmt0->size))); - /* "pysam/libcbcf.pyx":865 + /* "pysam/libcbcf.pyx":960 * if fmt0.type == BCF_BT_INT8: * data8 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): # <<<<<<<<<<<<<< @@ -13853,7 +14523,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":866 + /* "pysam/libcbcf.pyx":961 * data8 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data8[i] == bcf_int8_vector_end: # <<<<<<<<<<<<<< @@ -13863,7 +14533,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = (((__pyx_v_data8[__pyx_v_i]) == bcf_int8_vector_end) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":867 + /* "pysam/libcbcf.pyx":962 * for i in range(fmt0.n): * if data8[i] == bcf_int8_vector_end: * break # <<<<<<<<<<<<<< @@ -13872,7 +14542,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ goto __pyx_L14_break; - /* "pysam/libcbcf.pyx":866 + /* "pysam/libcbcf.pyx":961 * data8 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data8[i] == bcf_int8_vector_end: # <<<<<<<<<<<<<< @@ -13881,7 +14551,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ } - /* "pysam/libcbcf.pyx":868 + /* "pysam/libcbcf.pyx":963 * if data8[i] == bcf_int8_vector_end: * break * elif data8[i] == bcf_gt_missing: # <<<<<<<<<<<<<< @@ -13891,7 +14561,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = (((__pyx_v_data8[__pyx_v_i]) == bcf_gt_missing) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":869 + /* "pysam/libcbcf.pyx":964 * break * elif data8[i] == bcf_gt_missing: * a = -1 # <<<<<<<<<<<<<< @@ -13900,7 +14570,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ __pyx_v_a = -1; - /* "pysam/libcbcf.pyx":868 + /* "pysam/libcbcf.pyx":963 * if data8[i] == bcf_int8_vector_end: * break * elif data8[i] == bcf_gt_missing: # <<<<<<<<<<<<<< @@ -13910,7 +14580,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ goto __pyx_L15; } - /* "pysam/libcbcf.pyx":871 + /* "pysam/libcbcf.pyx":966 * a = -1 * else: * a = bcf_gt_allele(data8[i]) # <<<<<<<<<<<<<< @@ -13922,7 +14592,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ } __pyx_L15:; - /* "pysam/libcbcf.pyx":872 + /* "pysam/libcbcf.pyx":967 * else: * a = bcf_gt_allele(data8[i]) * alleles.append(a if 0 <= a < nalleles else None) # <<<<<<<<<<<<<< @@ -13934,7 +14604,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = (__pyx_v_a < __pyx_v_nalleles); } if ((__pyx_t_2 != 0)) { - __pyx_t_11 = __Pyx_PyInt_From_int32_t(__pyx_v_a); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 872, __pyx_L1_error) + __pyx_t_11 = __Pyx_PyInt_From_int32_t(__pyx_v_a); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 967, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_3 = __pyx_t_11; __pyx_t_11 = 0; @@ -13942,12 +14612,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __Pyx_INCREF(Py_None); __pyx_t_3 = Py_None; } - __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_alleles, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 872, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_alleles, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 967, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L14_break:; - /* "pysam/libcbcf.pyx":863 + /* "pysam/libcbcf.pyx":958 * cdef list alleles = [] * * if fmt0.type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -13957,7 +14627,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ goto __pyx_L12; } - /* "pysam/libcbcf.pyx":873 + /* "pysam/libcbcf.pyx":968 * a = bcf_gt_allele(data8[i]) * alleles.append(a if 0 <= a < nalleles else None) * elif fmt0.type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -13967,7 +14637,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = ((__pyx_v_fmt0->type == BCF_BT_INT16) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":874 + /* "pysam/libcbcf.pyx":969 * alleles.append(a if 0 <= a < nalleles else None) * elif fmt0.type == BCF_BT_INT16: * data16 = (fmt0.p + sample.index * fmt0.size) # <<<<<<<<<<<<<< @@ -13976,7 +14646,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ __pyx_v_data16 = ((int16_t *)(__pyx_v_fmt0->p + (__pyx_v_sample->index * __pyx_v_fmt0->size))); - /* "pysam/libcbcf.pyx":875 + /* "pysam/libcbcf.pyx":970 * elif fmt0.type == BCF_BT_INT16: * data16 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): # <<<<<<<<<<<<<< @@ -13988,7 +14658,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":876 + /* "pysam/libcbcf.pyx":971 * data16 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data16[i] == bcf_int16_vector_end: # <<<<<<<<<<<<<< @@ -13998,7 +14668,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = (((__pyx_v_data16[__pyx_v_i]) == bcf_int16_vector_end) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":877 + /* "pysam/libcbcf.pyx":972 * for i in range(fmt0.n): * if data16[i] == bcf_int16_vector_end: * break # <<<<<<<<<<<<<< @@ -14007,7 +14677,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ goto __pyx_L17_break; - /* "pysam/libcbcf.pyx":876 + /* "pysam/libcbcf.pyx":971 * data16 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data16[i] == bcf_int16_vector_end: # <<<<<<<<<<<<<< @@ -14016,7 +14686,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ } - /* "pysam/libcbcf.pyx":878 + /* "pysam/libcbcf.pyx":973 * if data16[i] == bcf_int16_vector_end: * break * elif data16[i] == bcf_gt_missing: # <<<<<<<<<<<<<< @@ -14026,7 +14696,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = (((__pyx_v_data16[__pyx_v_i]) == bcf_gt_missing) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":879 + /* "pysam/libcbcf.pyx":974 * break * elif data16[i] == bcf_gt_missing: * a = -1 # <<<<<<<<<<<<<< @@ -14035,7 +14705,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ __pyx_v_a = -1; - /* "pysam/libcbcf.pyx":878 + /* "pysam/libcbcf.pyx":973 * if data16[i] == bcf_int16_vector_end: * break * elif data16[i] == bcf_gt_missing: # <<<<<<<<<<<<<< @@ -14045,7 +14715,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ goto __pyx_L18; } - /* "pysam/libcbcf.pyx":881 + /* "pysam/libcbcf.pyx":976 * a = -1 * else: * a = bcf_gt_allele(data16[i]) # <<<<<<<<<<<<<< @@ -14057,7 +14727,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ } __pyx_L18:; - /* "pysam/libcbcf.pyx":882 + /* "pysam/libcbcf.pyx":977 * else: * a = bcf_gt_allele(data16[i]) * alleles.append(a if 0 <= a < nalleles else None) # <<<<<<<<<<<<<< @@ -14069,7 +14739,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = (__pyx_v_a < __pyx_v_nalleles); } if ((__pyx_t_2 != 0)) { - __pyx_t_11 = __Pyx_PyInt_From_int32_t(__pyx_v_a); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 882, __pyx_L1_error) + __pyx_t_11 = __Pyx_PyInt_From_int32_t(__pyx_v_a); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 977, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_3 = __pyx_t_11; __pyx_t_11 = 0; @@ -14077,12 +14747,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __Pyx_INCREF(Py_None); __pyx_t_3 = Py_None; } - __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_alleles, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 882, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_alleles, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 977, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L17_break:; - /* "pysam/libcbcf.pyx":873 + /* "pysam/libcbcf.pyx":968 * a = bcf_gt_allele(data8[i]) * alleles.append(a if 0 <= a < nalleles else None) * elif fmt0.type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -14092,7 +14762,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ goto __pyx_L12; } - /* "pysam/libcbcf.pyx":883 + /* "pysam/libcbcf.pyx":978 * a = bcf_gt_allele(data16[i]) * alleles.append(a if 0 <= a < nalleles else None) * elif fmt0.type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -14102,7 +14772,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = ((__pyx_v_fmt0->type == BCF_BT_INT32) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":884 + /* "pysam/libcbcf.pyx":979 * alleles.append(a if 0 <= a < nalleles else None) * elif fmt0.type == BCF_BT_INT32: * data32 = (fmt0.p + sample.index * fmt0.size) # <<<<<<<<<<<<<< @@ -14111,7 +14781,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ __pyx_v_data32 = ((int32_t *)(__pyx_v_fmt0->p + (__pyx_v_sample->index * __pyx_v_fmt0->size))); - /* "pysam/libcbcf.pyx":885 + /* "pysam/libcbcf.pyx":980 * elif fmt0.type == BCF_BT_INT32: * data32 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): # <<<<<<<<<<<<<< @@ -14123,7 +14793,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":886 + /* "pysam/libcbcf.pyx":981 * data32 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data32[i] == bcf_int32_vector_end: # <<<<<<<<<<<<<< @@ -14133,7 +14803,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = (((__pyx_v_data32[__pyx_v_i]) == bcf_int32_vector_end) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":887 + /* "pysam/libcbcf.pyx":982 * for i in range(fmt0.n): * if data32[i] == bcf_int32_vector_end: * break # <<<<<<<<<<<<<< @@ -14142,7 +14812,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ goto __pyx_L20_break; - /* "pysam/libcbcf.pyx":886 + /* "pysam/libcbcf.pyx":981 * data32 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data32[i] == bcf_int32_vector_end: # <<<<<<<<<<<<<< @@ -14151,7 +14821,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ } - /* "pysam/libcbcf.pyx":888 + /* "pysam/libcbcf.pyx":983 * if data32[i] == bcf_int32_vector_end: * break * elif data32[i] == bcf_gt_missing: # <<<<<<<<<<<<<< @@ -14161,7 +14831,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = (((__pyx_v_data32[__pyx_v_i]) == bcf_gt_missing) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":889 + /* "pysam/libcbcf.pyx":984 * break * elif data32[i] == bcf_gt_missing: * a = -1 # <<<<<<<<<<<<<< @@ -14170,7 +14840,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ */ __pyx_v_a = -1; - /* "pysam/libcbcf.pyx":888 + /* "pysam/libcbcf.pyx":983 * if data32[i] == bcf_int32_vector_end: * break * elif data32[i] == bcf_gt_missing: # <<<<<<<<<<<<<< @@ -14180,7 +14850,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ goto __pyx_L21; } - /* "pysam/libcbcf.pyx":891 + /* "pysam/libcbcf.pyx":986 * a = -1 * else: * a = bcf_gt_allele(data32[i]) # <<<<<<<<<<<<<< @@ -14192,7 +14862,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ } __pyx_L21:; - /* "pysam/libcbcf.pyx":892 + /* "pysam/libcbcf.pyx":987 * else: * a = bcf_gt_allele(data32[i]) * alleles.append(a if 0 <= a < nalleles else None) # <<<<<<<<<<<<<< @@ -14204,7 +14874,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __pyx_t_2 = (__pyx_v_a < __pyx_v_nalleles); } if ((__pyx_t_2 != 0)) { - __pyx_t_11 = __Pyx_PyInt_From_int32_t(__pyx_v_a); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 892, __pyx_L1_error) + __pyx_t_11 = __Pyx_PyInt_From_int32_t(__pyx_v_a); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 987, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_3 = __pyx_t_11; __pyx_t_11 = 0; @@ -14212,12 +14882,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ __Pyx_INCREF(Py_None); __pyx_t_3 = Py_None; } - __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_alleles, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 892, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_alleles, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 987, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L20_break:; - /* "pysam/libcbcf.pyx":883 + /* "pysam/libcbcf.pyx":978 * a = bcf_gt_allele(data16[i]) * alleles.append(a if 0 <= a < nalleles else None) * elif fmt0.type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -14227,7 +14897,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ } __pyx_L12:; - /* "pysam/libcbcf.pyx":894 + /* "pysam/libcbcf.pyx":989 * alleles.append(a if 0 <= a < nalleles else None) * * return tuple(alleles) # <<<<<<<<<<<<<< @@ -14235,13 +14905,13 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyList_AsTuple(__pyx_v_alleles); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 894, __pyx_L1_error) + __pyx_t_3 = PyList_AsTuple(__pyx_v_alleles); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 989, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":837 + /* "pysam/libcbcf.pyx":932 * * * cdef bcf_format_get_allele_indices(VariantRecordSample sample): # <<<<<<<<<<<<<< @@ -14263,7 +14933,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(struct __ return __pyx_r; } -/* "pysam/libcbcf.pyx":897 +/* "pysam/libcbcf.pyx":992 * * * cdef bcf_format_get_alleles(VariantRecordSample sample): # <<<<<<<<<<<<<< @@ -14300,9 +14970,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj PyObject *__pyx_t_11 = NULL; int __pyx_t_12; __Pyx_RefNannySetupContext("bcf_format_get_alleles", 0); - __Pyx_TraceCall("bcf_format_get_alleles", __pyx_f[0], 897, 0, __PYX_ERR(0, 897, __pyx_L1_error)); + __Pyx_TraceCall("bcf_format_get_alleles", __pyx_f[0], 992, 0, __PYX_ERR(0, 992, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":898 + /* "pysam/libcbcf.pyx":993 * * cdef bcf_format_get_alleles(VariantRecordSample sample): * if sample is None: # <<<<<<<<<<<<<< @@ -14313,20 +14983,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":899 + /* "pysam/libcbcf.pyx":994 * cdef bcf_format_get_alleles(VariantRecordSample sample): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = sample.record.header.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__51, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 899, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 994, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 899, __pyx_L1_error) + __PYX_ERR(0, 994, __pyx_L1_error) - /* "pysam/libcbcf.pyx":898 + /* "pysam/libcbcf.pyx":993 * * cdef bcf_format_get_alleles(VariantRecordSample sample): * if sample is None: # <<<<<<<<<<<<<< @@ -14335,37 +15005,38 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":901 + /* "pysam/libcbcf.pyx":996 * raise ValueError('sample must not be None') * * cdef bcf_hdr_t *hdr = sample.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = sample.record.ptr - * cdef int32_t nsamples = bcf_hdr_nsamples(hdr) + * cdef int32_t nsamples = r.n_sample */ __pyx_t_4 = __pyx_v_sample->record->header->ptr; __pyx_v_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":902 + /* "pysam/libcbcf.pyx":997 * * cdef bcf_hdr_t *hdr = sample.record.header.ptr * cdef bcf1_t *r = sample.record.ptr # <<<<<<<<<<<<<< - * cdef int32_t nsamples = bcf_hdr_nsamples(hdr) + * cdef int32_t nsamples = r.n_sample * */ __pyx_t_5 = __pyx_v_sample->record->ptr; __pyx_v_r = __pyx_t_5; - /* "pysam/libcbcf.pyx":903 + /* "pysam/libcbcf.pyx":998 * cdef bcf_hdr_t *hdr = sample.record.header.ptr * cdef bcf1_t *r = sample.record.ptr - * cdef int32_t nsamples = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< + * cdef int32_t nsamples = r.n_sample # <<<<<<<<<<<<<< * * if bcf_unpack(r, BCF_UN_ALL) < 0: */ - __pyx_v_nsamples = bcf_hdr_nsamples(__pyx_v_hdr); + __pyx_t_6 = __pyx_v_r->n_sample; + __pyx_v_nsamples = __pyx_t_6; - /* "pysam/libcbcf.pyx":905 - * cdef int32_t nsamples = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":1000 + * cdef int32_t nsamples = r.n_sample * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') @@ -14374,21 +15045,21 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_ALL) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":906 + /* "pysam/libcbcf.pyx":1001 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * cdef int32_t nalleles = r.n_allele */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 906, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__49, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1001, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 906, __pyx_L1_error) + __PYX_ERR(0, 1001, __pyx_L1_error) - /* "pysam/libcbcf.pyx":905 - * cdef int32_t nsamples = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":1000 + * cdef int32_t nsamples = r.n_sample * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') @@ -14396,7 +15067,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":908 + /* "pysam/libcbcf.pyx":1003 * raise ValueError('Error unpacking VariantRecord') * * cdef int32_t nalleles = r.n_allele # <<<<<<<<<<<<<< @@ -14406,7 +15077,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_6 = __pyx_v_r->n_allele; __pyx_v_nalleles = __pyx_t_6; - /* "pysam/libcbcf.pyx":910 + /* "pysam/libcbcf.pyx":1005 * cdef int32_t nalleles = r.n_allele * * if sample.index < 0 or sample.index >= nsamples or not r.n_fmt: # <<<<<<<<<<<<<< @@ -14430,7 +15101,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_L6_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":911 + /* "pysam/libcbcf.pyx":1006 * * if sample.index < 0 or sample.index >= nsamples or not r.n_fmt: * return () # <<<<<<<<<<<<<< @@ -14442,7 +15113,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_r = __pyx_empty_tuple; goto __pyx_L0; - /* "pysam/libcbcf.pyx":910 + /* "pysam/libcbcf.pyx":1005 * cdef int32_t nalleles = r.n_allele * * if sample.index < 0 or sample.index >= nsamples or not r.n_fmt: # <<<<<<<<<<<<<< @@ -14451,7 +15122,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":913 + /* "pysam/libcbcf.pyx":1008 * return () * * cdef bcf_fmt_t *fmt0 = r.d.fmt # <<<<<<<<<<<<<< @@ -14461,7 +15132,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_7 = __pyx_v_r->d.fmt; __pyx_v_fmt0 = __pyx_t_7; - /* "pysam/libcbcf.pyx":914 + /* "pysam/libcbcf.pyx":1009 * * cdef bcf_fmt_t *fmt0 = r.d.fmt * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) # <<<<<<<<<<<<<< @@ -14470,7 +15141,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ __pyx_v_gt0 = __pyx_f_5pysam_7libcbcf_is_gt_fmt(__pyx_v_hdr, __pyx_v_fmt0->id); - /* "pysam/libcbcf.pyx":916 + /* "pysam/libcbcf.pyx":1011 * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) * * if not gt0 or not fmt0.n: # <<<<<<<<<<<<<< @@ -14488,7 +15159,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_L10_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":917 + /* "pysam/libcbcf.pyx":1012 * * if not gt0 or not fmt0.n: * return () # <<<<<<<<<<<<<< @@ -14500,7 +15171,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_r = __pyx_empty_tuple; goto __pyx_L0; - /* "pysam/libcbcf.pyx":916 + /* "pysam/libcbcf.pyx":1011 * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) * * if not gt0 or not fmt0.n: # <<<<<<<<<<<<<< @@ -14509,19 +15180,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":923 + /* "pysam/libcbcf.pyx":1018 * cdef int16_t *data16 * cdef int32_t *data32 * alleles = [] # <<<<<<<<<<<<<< * if fmt0.type == BCF_BT_INT8: * data8 = (fmt0.p + sample.index * fmt0.size) */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 923, __pyx_L1_error) + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1018, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_alleles = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":924 + /* "pysam/libcbcf.pyx":1019 * cdef int32_t *data32 * alleles = [] * if fmt0.type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -14531,7 +15202,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_2 = ((__pyx_v_fmt0->type == BCF_BT_INT8) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":925 + /* "pysam/libcbcf.pyx":1020 * alleles = [] * if fmt0.type == BCF_BT_INT8: * data8 = (fmt0.p + sample.index * fmt0.size) # <<<<<<<<<<<<<< @@ -14540,7 +15211,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ __pyx_v_data8 = ((int8_t *)(__pyx_v_fmt0->p + (__pyx_v_sample->index * __pyx_v_fmt0->size))); - /* "pysam/libcbcf.pyx":926 + /* "pysam/libcbcf.pyx":1021 * if fmt0.type == BCF_BT_INT8: * data8 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): # <<<<<<<<<<<<<< @@ -14552,7 +15223,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":927 + /* "pysam/libcbcf.pyx":1022 * data8 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data8[i] == bcf_int8_vector_end: # <<<<<<<<<<<<<< @@ -14562,7 +15233,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_2 = (((__pyx_v_data8[__pyx_v_i]) == bcf_int8_vector_end) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":928 + /* "pysam/libcbcf.pyx":1023 * for i in range(fmt0.n): * if data8[i] == bcf_int8_vector_end: * break # <<<<<<<<<<<<<< @@ -14571,7 +15242,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ goto __pyx_L14_break; - /* "pysam/libcbcf.pyx":927 + /* "pysam/libcbcf.pyx":1022 * data8 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data8[i] == bcf_int8_vector_end: # <<<<<<<<<<<<<< @@ -14580,7 +15251,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":929 + /* "pysam/libcbcf.pyx":1024 * if data8[i] == bcf_int8_vector_end: * break * a = bcf_gt_allele(data8[i]) # <<<<<<<<<<<<<< @@ -14589,7 +15260,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ __pyx_v_a = bcf_gt_allele((__pyx_v_data8[__pyx_v_i])); - /* "pysam/libcbcf.pyx":930 + /* "pysam/libcbcf.pyx":1025 * break * a = bcf_gt_allele(data8[i]) * alleles.append(charptr_to_str(r.d.allele[a]) if 0 <= a < nalleles else None) # <<<<<<<<<<<<<< @@ -14601,7 +15272,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_2 = (__pyx_v_a < __pyx_v_nalleles); } if ((__pyx_t_2 != 0)) { - __pyx_t_11 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->d.allele[__pyx_v_a]), NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 930, __pyx_L1_error) + __pyx_t_11 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->d.allele[__pyx_v_a]), NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1025, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_3 = __pyx_t_11; __pyx_t_11 = 0; @@ -14609,12 +15280,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __Pyx_INCREF(Py_None); __pyx_t_3 = Py_None; } - __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_alleles, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 930, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_alleles, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 1025, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L14_break:; - /* "pysam/libcbcf.pyx":924 + /* "pysam/libcbcf.pyx":1019 * cdef int32_t *data32 * alleles = [] * if fmt0.type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -14624,7 +15295,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj goto __pyx_L12; } - /* "pysam/libcbcf.pyx":931 + /* "pysam/libcbcf.pyx":1026 * a = bcf_gt_allele(data8[i]) * alleles.append(charptr_to_str(r.d.allele[a]) if 0 <= a < nalleles else None) * elif fmt0.type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -14634,7 +15305,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_2 = ((__pyx_v_fmt0->type == BCF_BT_INT16) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":932 + /* "pysam/libcbcf.pyx":1027 * alleles.append(charptr_to_str(r.d.allele[a]) if 0 <= a < nalleles else None) * elif fmt0.type == BCF_BT_INT16: * data16 = (fmt0.p + sample.index * fmt0.size) # <<<<<<<<<<<<<< @@ -14643,7 +15314,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ __pyx_v_data16 = ((int16_t *)(__pyx_v_fmt0->p + (__pyx_v_sample->index * __pyx_v_fmt0->size))); - /* "pysam/libcbcf.pyx":933 + /* "pysam/libcbcf.pyx":1028 * elif fmt0.type == BCF_BT_INT16: * data16 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): # <<<<<<<<<<<<<< @@ -14655,7 +15326,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":934 + /* "pysam/libcbcf.pyx":1029 * data16 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data16[i] == bcf_int16_vector_end: # <<<<<<<<<<<<<< @@ -14665,7 +15336,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_2 = (((__pyx_v_data16[__pyx_v_i]) == bcf_int16_vector_end) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":935 + /* "pysam/libcbcf.pyx":1030 * for i in range(fmt0.n): * if data16[i] == bcf_int16_vector_end: * break # <<<<<<<<<<<<<< @@ -14674,7 +15345,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ goto __pyx_L17_break; - /* "pysam/libcbcf.pyx":934 + /* "pysam/libcbcf.pyx":1029 * data16 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data16[i] == bcf_int16_vector_end: # <<<<<<<<<<<<<< @@ -14683,7 +15354,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":936 + /* "pysam/libcbcf.pyx":1031 * if data16[i] == bcf_int16_vector_end: * break * a = bcf_gt_allele(data16[i]) # <<<<<<<<<<<<<< @@ -14692,7 +15363,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ __pyx_v_a = bcf_gt_allele((__pyx_v_data16[__pyx_v_i])); - /* "pysam/libcbcf.pyx":937 + /* "pysam/libcbcf.pyx":1032 * break * a = bcf_gt_allele(data16[i]) * alleles.append(charptr_to_str(r.d.allele[a]) if 0 <= a < nalleles else None) # <<<<<<<<<<<<<< @@ -14704,7 +15375,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_2 = (__pyx_v_a < __pyx_v_nalleles); } if ((__pyx_t_2 != 0)) { - __pyx_t_11 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->d.allele[__pyx_v_a]), NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 937, __pyx_L1_error) + __pyx_t_11 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->d.allele[__pyx_v_a]), NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1032, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_3 = __pyx_t_11; __pyx_t_11 = 0; @@ -14712,12 +15383,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __Pyx_INCREF(Py_None); __pyx_t_3 = Py_None; } - __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_alleles, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 937, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_alleles, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 1032, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L17_break:; - /* "pysam/libcbcf.pyx":931 + /* "pysam/libcbcf.pyx":1026 * a = bcf_gt_allele(data8[i]) * alleles.append(charptr_to_str(r.d.allele[a]) if 0 <= a < nalleles else None) * elif fmt0.type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -14727,7 +15398,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj goto __pyx_L12; } - /* "pysam/libcbcf.pyx":938 + /* "pysam/libcbcf.pyx":1033 * a = bcf_gt_allele(data16[i]) * alleles.append(charptr_to_str(r.d.allele[a]) if 0 <= a < nalleles else None) * elif fmt0.type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -14737,7 +15408,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_2 = ((__pyx_v_fmt0->type == BCF_BT_INT32) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":939 + /* "pysam/libcbcf.pyx":1034 * alleles.append(charptr_to_str(r.d.allele[a]) if 0 <= a < nalleles else None) * elif fmt0.type == BCF_BT_INT32: * data32 = (fmt0.p + sample.index * fmt0.size) # <<<<<<<<<<<<<< @@ -14746,7 +15417,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ __pyx_v_data32 = ((int32_t *)(__pyx_v_fmt0->p + (__pyx_v_sample->index * __pyx_v_fmt0->size))); - /* "pysam/libcbcf.pyx":940 + /* "pysam/libcbcf.pyx":1035 * elif fmt0.type == BCF_BT_INT32: * data32 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): # <<<<<<<<<<<<<< @@ -14758,7 +15429,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":941 + /* "pysam/libcbcf.pyx":1036 * data32 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data32[i] == bcf_int32_vector_end: # <<<<<<<<<<<<<< @@ -14768,7 +15439,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_2 = (((__pyx_v_data32[__pyx_v_i]) == bcf_int32_vector_end) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":942 + /* "pysam/libcbcf.pyx":1037 * for i in range(fmt0.n): * if data32[i] == bcf_int32_vector_end: * break # <<<<<<<<<<<<<< @@ -14777,7 +15448,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ goto __pyx_L20_break; - /* "pysam/libcbcf.pyx":941 + /* "pysam/libcbcf.pyx":1036 * data32 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data32[i] == bcf_int32_vector_end: # <<<<<<<<<<<<<< @@ -14786,7 +15457,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":943 + /* "pysam/libcbcf.pyx":1038 * if data32[i] == bcf_int32_vector_end: * break * a = bcf_gt_allele(data32[i]) # <<<<<<<<<<<<<< @@ -14795,7 +15466,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj */ __pyx_v_a = bcf_gt_allele((__pyx_v_data32[__pyx_v_i])); - /* "pysam/libcbcf.pyx":944 + /* "pysam/libcbcf.pyx":1039 * break * a = bcf_gt_allele(data32[i]) * alleles.append(charptr_to_str(r.d.allele[a]) if 0 <= a < nalleles else None) # <<<<<<<<<<<<<< @@ -14807,7 +15478,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __pyx_t_2 = (__pyx_v_a < __pyx_v_nalleles); } if ((__pyx_t_2 != 0)) { - __pyx_t_11 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->d.allele[__pyx_v_a]), NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 944, __pyx_L1_error) + __pyx_t_11 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->d.allele[__pyx_v_a]), NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1039, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_3 = __pyx_t_11; __pyx_t_11 = 0; @@ -14815,12 +15486,12 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj __Pyx_INCREF(Py_None); __pyx_t_3 = Py_None; } - __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_alleles, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 944, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_alleles, __pyx_t_3); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 1039, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L20_break:; - /* "pysam/libcbcf.pyx":938 + /* "pysam/libcbcf.pyx":1033 * a = bcf_gt_allele(data16[i]) * alleles.append(charptr_to_str(r.d.allele[a]) if 0 <= a < nalleles else None) * elif fmt0.type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -14830,7 +15501,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj } __pyx_L12:; - /* "pysam/libcbcf.pyx":945 + /* "pysam/libcbcf.pyx":1040 * a = bcf_gt_allele(data32[i]) * alleles.append(charptr_to_str(r.d.allele[a]) if 0 <= a < nalleles else None) * return tuple(alleles) # <<<<<<<<<<<<<< @@ -14838,13 +15509,13 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyList_AsTuple(__pyx_v_alleles); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 945, __pyx_L1_error) + __pyx_t_3 = PyList_AsTuple(__pyx_v_alleles); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1040, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":897 + /* "pysam/libcbcf.pyx":992 * * * cdef bcf_format_get_alleles(VariantRecordSample sample): # <<<<<<<<<<<<<< @@ -14866,7 +15537,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(struct __pyx_obj return __pyx_r; } -/* "pysam/libcbcf.pyx":948 +/* "pysam/libcbcf.pyx":1043 * * * cdef bint bcf_sample_get_phased(VariantRecordSample sample): # <<<<<<<<<<<<<< @@ -14893,14 +15564,15 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam PyObject *__pyx_t_3 = NULL; bcf_hdr_t *__pyx_t_4; bcf1_t *__pyx_t_5; - bcf_fmt_t *__pyx_t_6; - int __pyx_t_7; + uint32_t __pyx_t_6; + bcf_fmt_t *__pyx_t_7; int __pyx_t_8; int __pyx_t_9; + int __pyx_t_10; __Pyx_RefNannySetupContext("bcf_sample_get_phased", 0); - __Pyx_TraceCall("bcf_sample_get_phased", __pyx_f[0], 948, 0, __PYX_ERR(0, 948, __pyx_L1_error)); + __Pyx_TraceCall("bcf_sample_get_phased", __pyx_f[0], 1043, 0, __PYX_ERR(0, 1043, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":949 + /* "pysam/libcbcf.pyx":1044 * * cdef bint bcf_sample_get_phased(VariantRecordSample sample): * if sample is None: # <<<<<<<<<<<<<< @@ -14911,20 +15583,20 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":950 + /* "pysam/libcbcf.pyx":1045 * cdef bint bcf_sample_get_phased(VariantRecordSample sample): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = sample.record.header.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__53, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 950, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__50, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1045, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 950, __pyx_L1_error) + __PYX_ERR(0, 1045, __pyx_L1_error) - /* "pysam/libcbcf.pyx":949 + /* "pysam/libcbcf.pyx":1044 * * cdef bint bcf_sample_get_phased(VariantRecordSample sample): * if sample is None: # <<<<<<<<<<<<<< @@ -14933,37 +15605,38 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":952 + /* "pysam/libcbcf.pyx":1047 * raise ValueError('sample must not be None') * * cdef bcf_hdr_t *hdr = sample.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = sample.record.ptr - * cdef int32_t n = bcf_hdr_nsamples(hdr) + * cdef int32_t n = r.n_sample */ __pyx_t_4 = __pyx_v_sample->record->header->ptr; __pyx_v_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":953 + /* "pysam/libcbcf.pyx":1048 * * cdef bcf_hdr_t *hdr = sample.record.header.ptr * cdef bcf1_t *r = sample.record.ptr # <<<<<<<<<<<<<< - * cdef int32_t n = bcf_hdr_nsamples(hdr) + * cdef int32_t n = r.n_sample * */ __pyx_t_5 = __pyx_v_sample->record->ptr; __pyx_v_r = __pyx_t_5; - /* "pysam/libcbcf.pyx":954 + /* "pysam/libcbcf.pyx":1049 * cdef bcf_hdr_t *hdr = sample.record.header.ptr * cdef bcf1_t *r = sample.record.ptr - * cdef int32_t n = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< + * cdef int32_t n = r.n_sample # <<<<<<<<<<<<<< * * if bcf_unpack(r, BCF_UN_ALL) < 0: */ - __pyx_v_n = bcf_hdr_nsamples(__pyx_v_hdr); + __pyx_t_6 = __pyx_v_r->n_sample; + __pyx_v_n = __pyx_t_6; - /* "pysam/libcbcf.pyx":956 - * cdef int32_t n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":1051 + * cdef int32_t n = r.n_sample * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') @@ -14972,21 +15645,21 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_ALL) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":957 + /* "pysam/libcbcf.pyx":1052 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * if sample.index < 0 or sample.index >= n or not r.n_fmt: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 957, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__51, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1052, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 957, __pyx_L1_error) + __PYX_ERR(0, 1052, __pyx_L1_error) - /* "pysam/libcbcf.pyx":956 - * cdef int32_t n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":1051 + * cdef int32_t n = r.n_sample * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') @@ -14994,7 +15667,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":959 + /* "pysam/libcbcf.pyx":1054 * raise ValueError('Error unpacking VariantRecord') * * if sample.index < 0 or sample.index >= n or not r.n_fmt: # <<<<<<<<<<<<<< @@ -15018,7 +15691,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_L6_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":960 + /* "pysam/libcbcf.pyx":1055 * * if sample.index < 0 or sample.index >= n or not r.n_fmt: * return False # <<<<<<<<<<<<<< @@ -15028,7 +15701,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":959 + /* "pysam/libcbcf.pyx":1054 * raise ValueError('Error unpacking VariantRecord') * * if sample.index < 0 or sample.index >= n or not r.n_fmt: # <<<<<<<<<<<<<< @@ -15037,17 +15710,17 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":962 + /* "pysam/libcbcf.pyx":1057 * return False * * cdef bcf_fmt_t *fmt0 = r.d.fmt # <<<<<<<<<<<<<< * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) * */ - __pyx_t_6 = __pyx_v_r->d.fmt; - __pyx_v_fmt0 = __pyx_t_6; + __pyx_t_7 = __pyx_v_r->d.fmt; + __pyx_v_fmt0 = __pyx_t_7; - /* "pysam/libcbcf.pyx":963 + /* "pysam/libcbcf.pyx":1058 * * cdef bcf_fmt_t *fmt0 = r.d.fmt * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) # <<<<<<<<<<<<<< @@ -15056,7 +15729,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ __pyx_v_gt0 = __pyx_f_5pysam_7libcbcf_is_gt_fmt(__pyx_v_hdr, __pyx_v_fmt0->id); - /* "pysam/libcbcf.pyx":965 + /* "pysam/libcbcf.pyx":1060 * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) * * if not gt0 or not fmt0.n: # <<<<<<<<<<<<<< @@ -15074,7 +15747,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_L10_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":966 + /* "pysam/libcbcf.pyx":1061 * * if not gt0 or not fmt0.n: * return False # <<<<<<<<<<<<<< @@ -15084,7 +15757,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":965 + /* "pysam/libcbcf.pyx":1060 * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) * * if not gt0 or not fmt0.n: # <<<<<<<<<<<<<< @@ -15093,7 +15766,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":972 + /* "pysam/libcbcf.pyx":1067 * cdef int32_t *data32 * * cdef bint phased = False # <<<<<<<<<<<<<< @@ -15102,7 +15775,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ __pyx_v_phased = 0; - /* "pysam/libcbcf.pyx":974 + /* "pysam/libcbcf.pyx":1069 * cdef bint phased = False * * if fmt0.type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -15112,7 +15785,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_t_2 = ((__pyx_v_fmt0->type == BCF_BT_INT8) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":975 + /* "pysam/libcbcf.pyx":1070 * * if fmt0.type == BCF_BT_INT8: * data8 = (fmt0.p + sample.index * fmt0.size) # <<<<<<<<<<<<<< @@ -15121,19 +15794,19 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ __pyx_v_data8 = ((int8_t *)(__pyx_v_fmt0->p + (__pyx_v_sample->index * __pyx_v_fmt0->size))); - /* "pysam/libcbcf.pyx":976 + /* "pysam/libcbcf.pyx":1071 * if fmt0.type == BCF_BT_INT8: * data8 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): # <<<<<<<<<<<<<< * if data8[i] == bcf_int8_vector_end: * break */ - __pyx_t_7 = __pyx_v_fmt0->n; - __pyx_t_8 = __pyx_t_7; - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { - __pyx_v_i = __pyx_t_9; + __pyx_t_8 = __pyx_v_fmt0->n; + __pyx_t_9 = __pyx_t_8; + for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { + __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":977 + /* "pysam/libcbcf.pyx":1072 * data8 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data8[i] == bcf_int8_vector_end: # <<<<<<<<<<<<<< @@ -15143,7 +15816,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_t_2 = (((__pyx_v_data8[__pyx_v_i]) == bcf_int8_vector_end) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":978 + /* "pysam/libcbcf.pyx":1073 * for i in range(fmt0.n): * if data8[i] == bcf_int8_vector_end: * break # <<<<<<<<<<<<<< @@ -15152,7 +15825,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ goto __pyx_L14_break; - /* "pysam/libcbcf.pyx":977 + /* "pysam/libcbcf.pyx":1072 * data8 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data8[i] == bcf_int8_vector_end: # <<<<<<<<<<<<<< @@ -15161,7 +15834,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":979 + /* "pysam/libcbcf.pyx":1074 * if data8[i] == bcf_int8_vector_end: * break * elif data8[i] == bcf_int8_missing: # <<<<<<<<<<<<<< @@ -15171,7 +15844,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_t_2 = (((__pyx_v_data8[__pyx_v_i]) == bcf_int8_missing) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":980 + /* "pysam/libcbcf.pyx":1075 * break * elif data8[i] == bcf_int8_missing: * continue # <<<<<<<<<<<<<< @@ -15180,7 +15853,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ goto __pyx_L13_continue; - /* "pysam/libcbcf.pyx":979 + /* "pysam/libcbcf.pyx":1074 * if data8[i] == bcf_int8_vector_end: * break * elif data8[i] == bcf_int8_missing: # <<<<<<<<<<<<<< @@ -15189,7 +15862,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":981 + /* "pysam/libcbcf.pyx":1076 * elif data8[i] == bcf_int8_missing: * continue * elif i and not bcf_gt_is_phased(data8[i]): # <<<<<<<<<<<<<< @@ -15207,7 +15880,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_L16_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":982 + /* "pysam/libcbcf.pyx":1077 * continue * elif i and not bcf_gt_is_phased(data8[i]): * return False # <<<<<<<<<<<<<< @@ -15217,7 +15890,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":981 + /* "pysam/libcbcf.pyx":1076 * elif data8[i] == bcf_int8_missing: * continue * elif i and not bcf_gt_is_phased(data8[i]): # <<<<<<<<<<<<<< @@ -15226,7 +15899,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":984 + /* "pysam/libcbcf.pyx":1079 * return False * else: * phased = True # <<<<<<<<<<<<<< @@ -15240,7 +15913,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam } __pyx_L14_break:; - /* "pysam/libcbcf.pyx":974 + /* "pysam/libcbcf.pyx":1069 * cdef bint phased = False * * if fmt0.type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -15250,7 +15923,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam goto __pyx_L12; } - /* "pysam/libcbcf.pyx":985 + /* "pysam/libcbcf.pyx":1080 * else: * phased = True * elif fmt0.type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -15260,7 +15933,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_t_2 = ((__pyx_v_fmt0->type == BCF_BT_INT16) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":986 + /* "pysam/libcbcf.pyx":1081 * phased = True * elif fmt0.type == BCF_BT_INT16: * data16 = (fmt0.p + sample.index * fmt0.size) # <<<<<<<<<<<<<< @@ -15269,19 +15942,19 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ __pyx_v_data16 = ((int16_t *)(__pyx_v_fmt0->p + (__pyx_v_sample->index * __pyx_v_fmt0->size))); - /* "pysam/libcbcf.pyx":987 + /* "pysam/libcbcf.pyx":1082 * elif fmt0.type == BCF_BT_INT16: * data16 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): # <<<<<<<<<<<<<< * if data16[i] == bcf_int16_vector_end: * break */ - __pyx_t_7 = __pyx_v_fmt0->n; - __pyx_t_8 = __pyx_t_7; - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { - __pyx_v_i = __pyx_t_9; + __pyx_t_8 = __pyx_v_fmt0->n; + __pyx_t_9 = __pyx_t_8; + for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { + __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":988 + /* "pysam/libcbcf.pyx":1083 * data16 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data16[i] == bcf_int16_vector_end: # <<<<<<<<<<<<<< @@ -15291,7 +15964,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_t_2 = (((__pyx_v_data16[__pyx_v_i]) == bcf_int16_vector_end) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":989 + /* "pysam/libcbcf.pyx":1084 * for i in range(fmt0.n): * if data16[i] == bcf_int16_vector_end: * break # <<<<<<<<<<<<<< @@ -15300,7 +15973,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ goto __pyx_L19_break; - /* "pysam/libcbcf.pyx":988 + /* "pysam/libcbcf.pyx":1083 * data16 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data16[i] == bcf_int16_vector_end: # <<<<<<<<<<<<<< @@ -15309,7 +15982,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":990 + /* "pysam/libcbcf.pyx":1085 * if data16[i] == bcf_int16_vector_end: * break * elif data16[i] == bcf_int16_missing: # <<<<<<<<<<<<<< @@ -15319,7 +15992,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_t_2 = (((__pyx_v_data16[__pyx_v_i]) == bcf_int16_missing) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":991 + /* "pysam/libcbcf.pyx":1086 * break * elif data16[i] == bcf_int16_missing: * continue # <<<<<<<<<<<<<< @@ -15328,7 +16001,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ goto __pyx_L18_continue; - /* "pysam/libcbcf.pyx":990 + /* "pysam/libcbcf.pyx":1085 * if data16[i] == bcf_int16_vector_end: * break * elif data16[i] == bcf_int16_missing: # <<<<<<<<<<<<<< @@ -15337,7 +16010,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":992 + /* "pysam/libcbcf.pyx":1087 * elif data16[i] == bcf_int16_missing: * continue * elif i and not bcf_gt_is_phased(data16[i]): # <<<<<<<<<<<<<< @@ -15355,7 +16028,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_L21_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":993 + /* "pysam/libcbcf.pyx":1088 * continue * elif i and not bcf_gt_is_phased(data16[i]): * return False # <<<<<<<<<<<<<< @@ -15365,7 +16038,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":992 + /* "pysam/libcbcf.pyx":1087 * elif data16[i] == bcf_int16_missing: * continue * elif i and not bcf_gt_is_phased(data16[i]): # <<<<<<<<<<<<<< @@ -15374,7 +16047,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":995 + /* "pysam/libcbcf.pyx":1090 * return False * else: * phased = True # <<<<<<<<<<<<<< @@ -15388,7 +16061,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam } __pyx_L19_break:; - /* "pysam/libcbcf.pyx":985 + /* "pysam/libcbcf.pyx":1080 * else: * phased = True * elif fmt0.type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -15398,7 +16071,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam goto __pyx_L12; } - /* "pysam/libcbcf.pyx":996 + /* "pysam/libcbcf.pyx":1091 * else: * phased = True * elif fmt0.type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -15408,7 +16081,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_t_2 = ((__pyx_v_fmt0->type == BCF_BT_INT32) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":997 + /* "pysam/libcbcf.pyx":1092 * phased = True * elif fmt0.type == BCF_BT_INT32: * data32 = (fmt0.p + sample.index * fmt0.size) # <<<<<<<<<<<<<< @@ -15417,19 +16090,19 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ __pyx_v_data32 = ((int32_t *)(__pyx_v_fmt0->p + (__pyx_v_sample->index * __pyx_v_fmt0->size))); - /* "pysam/libcbcf.pyx":998 + /* "pysam/libcbcf.pyx":1093 * elif fmt0.type == BCF_BT_INT32: * data32 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): # <<<<<<<<<<<<<< * if data32[i] == bcf_int32_vector_end: * break */ - __pyx_t_7 = __pyx_v_fmt0->n; - __pyx_t_8 = __pyx_t_7; - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { - __pyx_v_i = __pyx_t_9; + __pyx_t_8 = __pyx_v_fmt0->n; + __pyx_t_9 = __pyx_t_8; + for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { + __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":999 + /* "pysam/libcbcf.pyx":1094 * data32 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data32[i] == bcf_int32_vector_end: # <<<<<<<<<<<<<< @@ -15439,7 +16112,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_t_2 = (((__pyx_v_data32[__pyx_v_i]) == bcf_int32_vector_end) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1000 + /* "pysam/libcbcf.pyx":1095 * for i in range(fmt0.n): * if data32[i] == bcf_int32_vector_end: * break # <<<<<<<<<<<<<< @@ -15448,7 +16121,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ goto __pyx_L24_break; - /* "pysam/libcbcf.pyx":999 + /* "pysam/libcbcf.pyx":1094 * data32 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data32[i] == bcf_int32_vector_end: # <<<<<<<<<<<<<< @@ -15457,7 +16130,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":1001 + /* "pysam/libcbcf.pyx":1096 * if data32[i] == bcf_int32_vector_end: * break * elif data32[i] == bcf_int32_missing: # <<<<<<<<<<<<<< @@ -15467,7 +16140,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_t_2 = (((__pyx_v_data32[__pyx_v_i]) == bcf_int32_missing) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1002 + /* "pysam/libcbcf.pyx":1097 * break * elif data32[i] == bcf_int32_missing: * continue # <<<<<<<<<<<<<< @@ -15476,7 +16149,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ goto __pyx_L23_continue; - /* "pysam/libcbcf.pyx":1001 + /* "pysam/libcbcf.pyx":1096 * if data32[i] == bcf_int32_vector_end: * break * elif data32[i] == bcf_int32_missing: # <<<<<<<<<<<<<< @@ -15485,7 +16158,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":1003 + /* "pysam/libcbcf.pyx":1098 * elif data32[i] == bcf_int32_missing: * continue * elif i and not bcf_gt_is_phased(data32[i]): # <<<<<<<<<<<<<< @@ -15503,7 +16176,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_L26_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1004 + /* "pysam/libcbcf.pyx":1099 * continue * elif i and not bcf_gt_is_phased(data32[i]): * return False # <<<<<<<<<<<<<< @@ -15513,7 +16186,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1003 + /* "pysam/libcbcf.pyx":1098 * elif data32[i] == bcf_int32_missing: * continue * elif i and not bcf_gt_is_phased(data32[i]): # <<<<<<<<<<<<<< @@ -15522,7 +16195,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam */ } - /* "pysam/libcbcf.pyx":1006 + /* "pysam/libcbcf.pyx":1101 * return False * else: * phased = True # <<<<<<<<<<<<<< @@ -15536,7 +16209,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam } __pyx_L24_break:; - /* "pysam/libcbcf.pyx":996 + /* "pysam/libcbcf.pyx":1091 * else: * phased = True * elif fmt0.type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -15546,7 +16219,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam } __pyx_L12:; - /* "pysam/libcbcf.pyx":1008 + /* "pysam/libcbcf.pyx":1103 * phased = True * * return phased # <<<<<<<<<<<<<< @@ -15556,7 +16229,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam __pyx_r = __pyx_v_phased; goto __pyx_L0; - /* "pysam/libcbcf.pyx":948 + /* "pysam/libcbcf.pyx":1043 * * * cdef bint bcf_sample_get_phased(VariantRecordSample sample): # <<<<<<<<<<<<<< @@ -15575,7 +16248,7 @@ static int __pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(struct __pyx_obj_5pysam return __pyx_r; } -/* "pysam/libcbcf.pyx":1011 +/* "pysam/libcbcf.pyx":1106 * * * cdef bcf_sample_set_phased(VariantRecordSample sample, bint phased): # <<<<<<<<<<<<<< @@ -15601,17 +16274,18 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ PyObject *__pyx_t_3 = NULL; bcf_hdr_t *__pyx_t_4; bcf1_t *__pyx_t_5; - bcf_fmt_t *__pyx_t_6; - int __pyx_t_7; + uint32_t __pyx_t_6; + bcf_fmt_t *__pyx_t_7; int __pyx_t_8; int __pyx_t_9; - PyObject *__pyx_t_10 = NULL; + int __pyx_t_10; PyObject *__pyx_t_11 = NULL; - int32_t __pyx_t_12; + PyObject *__pyx_t_12 = NULL; + int32_t __pyx_t_13; __Pyx_RefNannySetupContext("bcf_sample_set_phased", 0); - __Pyx_TraceCall("bcf_sample_set_phased", __pyx_f[0], 1011, 0, __PYX_ERR(0, 1011, __pyx_L1_error)); + __Pyx_TraceCall("bcf_sample_set_phased", __pyx_f[0], 1106, 0, __PYX_ERR(0, 1106, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1012 + /* "pysam/libcbcf.pyx":1107 * * cdef bcf_sample_set_phased(VariantRecordSample sample, bint phased): * if sample is None: # <<<<<<<<<<<<<< @@ -15622,20 +16296,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1013 + /* "pysam/libcbcf.pyx":1108 * cdef bcf_sample_set_phased(VariantRecordSample sample, bint phased): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = sample.record.header.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__55, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1013, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1013, __pyx_L1_error) + __PYX_ERR(0, 1108, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1012 + /* "pysam/libcbcf.pyx":1107 * * cdef bcf_sample_set_phased(VariantRecordSample sample, bint phased): * if sample is None: # <<<<<<<<<<<<<< @@ -15644,37 +16318,38 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":1015 + /* "pysam/libcbcf.pyx":1110 * raise ValueError('sample must not be None') * * cdef bcf_hdr_t *hdr = sample.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = sample.record.ptr - * cdef int32_t n = bcf_hdr_nsamples(hdr) + * cdef int32_t n = r.n_sample */ __pyx_t_4 = __pyx_v_sample->record->header->ptr; __pyx_v_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":1016 + /* "pysam/libcbcf.pyx":1111 * * cdef bcf_hdr_t *hdr = sample.record.header.ptr * cdef bcf1_t *r = sample.record.ptr # <<<<<<<<<<<<<< - * cdef int32_t n = bcf_hdr_nsamples(hdr) + * cdef int32_t n = r.n_sample * */ __pyx_t_5 = __pyx_v_sample->record->ptr; __pyx_v_r = __pyx_t_5; - /* "pysam/libcbcf.pyx":1017 + /* "pysam/libcbcf.pyx":1112 * cdef bcf_hdr_t *hdr = sample.record.header.ptr * cdef bcf1_t *r = sample.record.ptr - * cdef int32_t n = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< + * cdef int32_t n = r.n_sample # <<<<<<<<<<<<<< * * if bcf_unpack(r, BCF_UN_ALL) < 0: */ - __pyx_v_n = bcf_hdr_nsamples(__pyx_v_hdr); + __pyx_t_6 = __pyx_v_r->n_sample; + __pyx_v_n = __pyx_t_6; - /* "pysam/libcbcf.pyx":1019 - * cdef int32_t n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":1114 + * cdef int32_t n = r.n_sample * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') @@ -15683,21 +16358,21 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_ALL) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1020 + /* "pysam/libcbcf.pyx":1115 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * if sample.index < 0 or sample.index >= n or not r.n_fmt: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__56, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1020, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__53, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1115, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1020, __pyx_L1_error) + __PYX_ERR(0, 1115, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1019 - * cdef int32_t n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":1114 + * cdef int32_t n = r.n_sample * * if bcf_unpack(r, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') @@ -15705,7 +16380,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":1022 + /* "pysam/libcbcf.pyx":1117 * raise ValueError('Error unpacking VariantRecord') * * if sample.index < 0 or sample.index >= n or not r.n_fmt: # <<<<<<<<<<<<<< @@ -15729,7 +16404,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_L6_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1023 + /* "pysam/libcbcf.pyx":1118 * * if sample.index < 0 or sample.index >= n or not r.n_fmt: * return # <<<<<<<<<<<<<< @@ -15740,7 +16415,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1022 + /* "pysam/libcbcf.pyx":1117 * raise ValueError('Error unpacking VariantRecord') * * if sample.index < 0 or sample.index >= n or not r.n_fmt: # <<<<<<<<<<<<<< @@ -15749,17 +16424,17 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":1025 + /* "pysam/libcbcf.pyx":1120 * return * * cdef bcf_fmt_t *fmt0 = r.d.fmt # <<<<<<<<<<<<<< * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) * */ - __pyx_t_6 = __pyx_v_r->d.fmt; - __pyx_v_fmt0 = __pyx_t_6; + __pyx_t_7 = __pyx_v_r->d.fmt; + __pyx_v_fmt0 = __pyx_t_7; - /* "pysam/libcbcf.pyx":1026 + /* "pysam/libcbcf.pyx":1121 * * cdef bcf_fmt_t *fmt0 = r.d.fmt * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) # <<<<<<<<<<<<<< @@ -15768,7 +16443,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ __pyx_v_gt0 = __pyx_f_5pysam_7libcbcf_is_gt_fmt(__pyx_v_hdr, __pyx_v_fmt0->id); - /* "pysam/libcbcf.pyx":1028 + /* "pysam/libcbcf.pyx":1123 * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) * * if not gt0 or not fmt0.n: # <<<<<<<<<<<<<< @@ -15786,20 +16461,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_L10_bool_binop_done:; if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1029 + /* "pysam/libcbcf.pyx":1124 * * if not gt0 or not fmt0.n: * raise ValueError('Cannot set phased before genotype is set') # <<<<<<<<<<<<<< * * cdef int8_t *data8 */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__57, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1029, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1029, __pyx_L1_error) + __PYX_ERR(0, 1124, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1028 + /* "pysam/libcbcf.pyx":1123 * cdef int gt0 = is_gt_fmt(hdr, fmt0.id) * * if not gt0 or not fmt0.n: # <<<<<<<<<<<<<< @@ -15808,7 +16483,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":1035 + /* "pysam/libcbcf.pyx":1130 * cdef int32_t *data32 * * if fmt0.type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -15818,7 +16493,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = ((__pyx_v_fmt0->type == BCF_BT_INT8) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1036 + /* "pysam/libcbcf.pyx":1131 * * if fmt0.type == BCF_BT_INT8: * data8 = (fmt0.p + sample.index * fmt0.size) # <<<<<<<<<<<<<< @@ -15827,19 +16502,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ __pyx_v_data8 = ((int8_t *)(__pyx_v_fmt0->p + (__pyx_v_sample->index * __pyx_v_fmt0->size))); - /* "pysam/libcbcf.pyx":1037 + /* "pysam/libcbcf.pyx":1132 * if fmt0.type == BCF_BT_INT8: * data8 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): # <<<<<<<<<<<<<< * if data8[i] == bcf_int8_vector_end: * break */ - __pyx_t_7 = __pyx_v_fmt0->n; - __pyx_t_8 = __pyx_t_7; - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { - __pyx_v_i = __pyx_t_9; + __pyx_t_8 = __pyx_v_fmt0->n; + __pyx_t_9 = __pyx_t_8; + for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { + __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":1038 + /* "pysam/libcbcf.pyx":1133 * data8 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data8[i] == bcf_int8_vector_end: # <<<<<<<<<<<<<< @@ -15849,7 +16524,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = (((__pyx_v_data8[__pyx_v_i]) == bcf_int8_vector_end) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1039 + /* "pysam/libcbcf.pyx":1134 * for i in range(fmt0.n): * if data8[i] == bcf_int8_vector_end: * break # <<<<<<<<<<<<<< @@ -15858,7 +16533,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ goto __pyx_L14_break; - /* "pysam/libcbcf.pyx":1038 + /* "pysam/libcbcf.pyx":1133 * data8 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data8[i] == bcf_int8_vector_end: # <<<<<<<<<<<<<< @@ -15867,7 +16542,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":1040 + /* "pysam/libcbcf.pyx":1135 * if data8[i] == bcf_int8_vector_end: * break * elif data8[i] == bcf_int8_missing: # <<<<<<<<<<<<<< @@ -15877,7 +16552,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = (((__pyx_v_data8[__pyx_v_i]) == bcf_int8_missing) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1041 + /* "pysam/libcbcf.pyx":1136 * break * elif data8[i] == bcf_int8_missing: * continue # <<<<<<<<<<<<<< @@ -15886,7 +16561,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ goto __pyx_L13_continue; - /* "pysam/libcbcf.pyx":1040 + /* "pysam/libcbcf.pyx":1135 * if data8[i] == bcf_int8_vector_end: * break * elif data8[i] == bcf_int8_missing: # <<<<<<<<<<<<<< @@ -15895,7 +16570,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":1042 + /* "pysam/libcbcf.pyx":1137 * elif data8[i] == bcf_int8_missing: * continue * elif i: # <<<<<<<<<<<<<< @@ -15905,7 +16580,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = (__pyx_v_i != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1043 + /* "pysam/libcbcf.pyx":1138 * continue * elif i: * data8[i] = (data8[i] & 0xFE) | phased # <<<<<<<<<<<<<< @@ -15914,7 +16589,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ (__pyx_v_data8[__pyx_v_i]) = (((__pyx_v_data8[__pyx_v_i]) & 0xFE) | __pyx_v_phased); - /* "pysam/libcbcf.pyx":1042 + /* "pysam/libcbcf.pyx":1137 * elif data8[i] == bcf_int8_missing: * continue * elif i: # <<<<<<<<<<<<<< @@ -15926,7 +16601,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ } __pyx_L14_break:; - /* "pysam/libcbcf.pyx":1035 + /* "pysam/libcbcf.pyx":1130 * cdef int32_t *data32 * * if fmt0.type == BCF_BT_INT8: # <<<<<<<<<<<<<< @@ -15936,7 +16611,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ goto __pyx_L12; } - /* "pysam/libcbcf.pyx":1044 + /* "pysam/libcbcf.pyx":1139 * elif i: * data8[i] = (data8[i] & 0xFE) | phased * elif fmt0.type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -15946,7 +16621,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = ((__pyx_v_fmt0->type == BCF_BT_INT16) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1045 + /* "pysam/libcbcf.pyx":1140 * data8[i] = (data8[i] & 0xFE) | phased * elif fmt0.type == BCF_BT_INT16: * data16 = (fmt0.p + sample.index * fmt0.size) # <<<<<<<<<<<<<< @@ -15955,19 +16630,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ __pyx_v_data16 = ((int16_t *)(__pyx_v_fmt0->p + (__pyx_v_sample->index * __pyx_v_fmt0->size))); - /* "pysam/libcbcf.pyx":1046 + /* "pysam/libcbcf.pyx":1141 * elif fmt0.type == BCF_BT_INT16: * data16 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): # <<<<<<<<<<<<<< * if data16[i] == bcf_int16_vector_end: * break */ - __pyx_t_7 = __pyx_v_fmt0->n; - __pyx_t_8 = __pyx_t_7; - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { - __pyx_v_i = __pyx_t_9; + __pyx_t_8 = __pyx_v_fmt0->n; + __pyx_t_9 = __pyx_t_8; + for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { + __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":1047 + /* "pysam/libcbcf.pyx":1142 * data16 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data16[i] == bcf_int16_vector_end: # <<<<<<<<<<<<<< @@ -15977,7 +16652,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = (((__pyx_v_data16[__pyx_v_i]) == bcf_int16_vector_end) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1048 + /* "pysam/libcbcf.pyx":1143 * for i in range(fmt0.n): * if data16[i] == bcf_int16_vector_end: * break # <<<<<<<<<<<<<< @@ -15986,7 +16661,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ goto __pyx_L17_break; - /* "pysam/libcbcf.pyx":1047 + /* "pysam/libcbcf.pyx":1142 * data16 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data16[i] == bcf_int16_vector_end: # <<<<<<<<<<<<<< @@ -15995,7 +16670,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":1049 + /* "pysam/libcbcf.pyx":1144 * if data16[i] == bcf_int16_vector_end: * break * elif data16[i] == bcf_int16_missing: # <<<<<<<<<<<<<< @@ -16005,7 +16680,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = (((__pyx_v_data16[__pyx_v_i]) == bcf_int16_missing) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1050 + /* "pysam/libcbcf.pyx":1145 * break * elif data16[i] == bcf_int16_missing: * continue # <<<<<<<<<<<<<< @@ -16014,7 +16689,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ goto __pyx_L16_continue; - /* "pysam/libcbcf.pyx":1049 + /* "pysam/libcbcf.pyx":1144 * if data16[i] == bcf_int16_vector_end: * break * elif data16[i] == bcf_int16_missing: # <<<<<<<<<<<<<< @@ -16023,7 +16698,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":1051 + /* "pysam/libcbcf.pyx":1146 * elif data16[i] == bcf_int16_missing: * continue * elif i: # <<<<<<<<<<<<<< @@ -16033,7 +16708,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = (__pyx_v_i != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1052 + /* "pysam/libcbcf.pyx":1147 * continue * elif i: * data16[i] = (data16[i] & 0xFFFE) | phased # <<<<<<<<<<<<<< @@ -16042,7 +16717,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ (__pyx_v_data16[__pyx_v_i]) = (((__pyx_v_data16[__pyx_v_i]) & 0xFFFE) | __pyx_v_phased); - /* "pysam/libcbcf.pyx":1051 + /* "pysam/libcbcf.pyx":1146 * elif data16[i] == bcf_int16_missing: * continue * elif i: # <<<<<<<<<<<<<< @@ -16054,7 +16729,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ } __pyx_L17_break:; - /* "pysam/libcbcf.pyx":1044 + /* "pysam/libcbcf.pyx":1139 * elif i: * data8[i] = (data8[i] & 0xFE) | phased * elif fmt0.type == BCF_BT_INT16: # <<<<<<<<<<<<<< @@ -16064,7 +16739,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ goto __pyx_L12; } - /* "pysam/libcbcf.pyx":1053 + /* "pysam/libcbcf.pyx":1148 * elif i: * data16[i] = (data16[i] & 0xFFFE) | phased * elif fmt0.type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -16074,7 +16749,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = ((__pyx_v_fmt0->type == BCF_BT_INT32) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1054 + /* "pysam/libcbcf.pyx":1149 * data16[i] = (data16[i] & 0xFFFE) | phased * elif fmt0.type == BCF_BT_INT32: * data32 = (fmt0.p + sample.index * fmt0.size) # <<<<<<<<<<<<<< @@ -16083,19 +16758,19 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ __pyx_v_data32 = ((int32_t *)(__pyx_v_fmt0->p + (__pyx_v_sample->index * __pyx_v_fmt0->size))); - /* "pysam/libcbcf.pyx":1055 + /* "pysam/libcbcf.pyx":1150 * elif fmt0.type == BCF_BT_INT32: * data32 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): # <<<<<<<<<<<<<< * if data32[i] == bcf_int32_vector_end: * break */ - __pyx_t_7 = __pyx_v_fmt0->n; - __pyx_t_8 = __pyx_t_7; - for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { - __pyx_v_i = __pyx_t_9; + __pyx_t_8 = __pyx_v_fmt0->n; + __pyx_t_9 = __pyx_t_8; + for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { + __pyx_v_i = __pyx_t_10; - /* "pysam/libcbcf.pyx":1056 + /* "pysam/libcbcf.pyx":1151 * data32 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data32[i] == bcf_int32_vector_end: # <<<<<<<<<<<<<< @@ -16105,7 +16780,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = (((__pyx_v_data32[__pyx_v_i]) == bcf_int32_vector_end) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1057 + /* "pysam/libcbcf.pyx":1152 * for i in range(fmt0.n): * if data32[i] == bcf_int32_vector_end: * break # <<<<<<<<<<<<<< @@ -16114,7 +16789,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ goto __pyx_L20_break; - /* "pysam/libcbcf.pyx":1056 + /* "pysam/libcbcf.pyx":1151 * data32 = (fmt0.p + sample.index * fmt0.size) * for i in range(fmt0.n): * if data32[i] == bcf_int32_vector_end: # <<<<<<<<<<<<<< @@ -16123,7 +16798,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":1058 + /* "pysam/libcbcf.pyx":1153 * if data32[i] == bcf_int32_vector_end: * break * elif data32[i] == bcf_int32_missing: # <<<<<<<<<<<<<< @@ -16133,7 +16808,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = (((__pyx_v_data32[__pyx_v_i]) == bcf_int32_missing) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1059 + /* "pysam/libcbcf.pyx":1154 * break * elif data32[i] == bcf_int32_missing: * continue # <<<<<<<<<<<<<< @@ -16142,7 +16817,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ goto __pyx_L19_continue; - /* "pysam/libcbcf.pyx":1058 + /* "pysam/libcbcf.pyx":1153 * if data32[i] == bcf_int32_vector_end: * break * elif data32[i] == bcf_int32_missing: # <<<<<<<<<<<<<< @@ -16151,7 +16826,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":1060 + /* "pysam/libcbcf.pyx":1155 * elif data32[i] == bcf_int32_missing: * continue * elif i: # <<<<<<<<<<<<<< @@ -16161,29 +16836,29 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ __pyx_t_2 = (__pyx_v_i != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1061 + /* "pysam/libcbcf.pyx":1156 * continue * elif i: * data32[i] = (data32[i] & 0xFFFFFFFE) | phased # <<<<<<<<<<<<<< * * */ - __pyx_t_3 = __Pyx_PyInt_From_int32_t((__pyx_v_data32[__pyx_v_i])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1061, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int32_t((__pyx_v_data32[__pyx_v_i])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = PyNumber_And(__pyx_t_3, __pyx_int_4294967294); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1061, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_phased); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1061, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_11 = PyNumber_Or(__pyx_t_10, __pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1061, __pyx_L1_error) + __pyx_t_11 = PyNumber_And(__pyx_t_3, __pyx_int_4294967294); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_12 = __Pyx_PyInt_As_int32_t(__pyx_t_11); if (unlikely((__pyx_t_12 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1061, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_phased); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyNumber_Or(__pyx_t_11, __pyx_t_3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - (__pyx_v_data32[__pyx_v_i]) = __pyx_t_12; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_13 = __Pyx_PyInt_As_int32_t(__pyx_t_12); if (unlikely((__pyx_t_13 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1156, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + (__pyx_v_data32[__pyx_v_i]) = __pyx_t_13; - /* "pysam/libcbcf.pyx":1060 + /* "pysam/libcbcf.pyx":1155 * elif data32[i] == bcf_int32_missing: * continue * elif i: # <<<<<<<<<<<<<< @@ -16195,7 +16870,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ } __pyx_L20_break:; - /* "pysam/libcbcf.pyx":1053 + /* "pysam/libcbcf.pyx":1148 * elif i: * data16[i] = (data16[i] & 0xFFFE) | phased * elif fmt0.type == BCF_BT_INT32: # <<<<<<<<<<<<<< @@ -16205,7 +16880,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ } __pyx_L12:; - /* "pysam/libcbcf.pyx":1011 + /* "pysam/libcbcf.pyx":1106 * * * cdef bcf_sample_set_phased(VariantRecordSample sample, bint phased): # <<<<<<<<<<<<<< @@ -16218,8 +16893,8 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_10); __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); __Pyx_AddTraceback("pysam.libcbcf.bcf_sample_set_phased", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; @@ -16229,7 +16904,418 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libcbcf.pyx":1070 +/* "pysam/libcbcf.pyx":1159 + * + * + * cdef inline bcf_sync_end(VariantRecord record): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = record.header.ptr + * cdef bcf_info_t *info + */ + +static CYTHON_INLINE PyObject *__pyx_f_5pysam_7libcbcf_bcf_sync_end(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record) { + bcf_hdr_t *__pyx_v_hdr; + bcf_info_t *__pyx_v_info; + int __pyx_v_end_id; + int __pyx_v_ref_len; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + bcf_hdr_t *__pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + Py_ssize_t __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + __Pyx_RefNannySetupContext("bcf_sync_end", 0); + __Pyx_TraceCall("bcf_sync_end", __pyx_f[0], 1159, 0, __PYX_ERR(0, 1159, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":1160 + * + * cdef inline bcf_sync_end(VariantRecord record): + * cdef bcf_hdr_t *hdr = record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf_info_t *info + * cdef int end_id = bcf_header_get_info_id(record.header.ptr, b'END') + */ + __pyx_t_1 = __pyx_v_record->header->ptr; + __pyx_v_hdr = __pyx_t_1; + + /* "pysam/libcbcf.pyx":1162 + * cdef bcf_hdr_t *hdr = record.header.ptr + * cdef bcf_info_t *info + * cdef int end_id = bcf_header_get_info_id(record.header.ptr, b'END') # <<<<<<<<<<<<<< + * cdef int ref_len + * + */ + __pyx_t_2 = __pyx_f_5pysam_7libcbcf_bcf_header_get_info_id(__pyx_v_record->header->ptr, __pyx_n_b_END); if (unlikely(__pyx_t_2 == ((int)-2) && PyErr_Occurred())) __PYX_ERR(0, 1162, __pyx_L1_error) + __pyx_v_end_id = __pyx_t_2; + + /* "pysam/libcbcf.pyx":1166 + * + * # allow missing ref when instantiating a new record + * if record.ref is not None: # <<<<<<<<<<<<<< + * ref_len = len(record.ref) + * else: + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_record), __pyx_n_s_ref); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1166, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = (__pyx_t_3 != Py_None); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { + + /* "pysam/libcbcf.pyx":1167 + * # allow missing ref when instantiating a new record + * if record.ref is not None: + * ref_len = len(record.ref) # <<<<<<<<<<<<<< + * else: + * ref_len = 0 + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_record), __pyx_n_s_ref); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1167, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1167, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_ref_len = __pyx_t_6; + + /* "pysam/libcbcf.pyx":1166 + * + * # allow missing ref when instantiating a new record + * if record.ref is not None: # <<<<<<<<<<<<<< + * ref_len = len(record.ref) + * else: + */ + goto __pyx_L3; + } + + /* "pysam/libcbcf.pyx":1169 + * ref_len = len(record.ref) + * else: + * ref_len = 0 # <<<<<<<<<<<<<< + * + * # Delete INFO/END if no alleles are present or if rlen is equal to len(ref) + */ + /*else*/ { + __pyx_v_ref_len = 0; + } + __pyx_L3:; + + /* "pysam/libcbcf.pyx":1173 + * # Delete INFO/END if no alleles are present or if rlen is equal to len(ref) + * # Always keep END for symbolic alleles + * if not has_symbolic_allele(record) and (not record.ptr.n_allele or record.ptr.rlen == ref_len): # <<<<<<<<<<<<<< + * # If INFO/END is not defined in the header, it doesn't exist in the record + * if end_id >= 0: + */ + __pyx_t_4 = ((!(__pyx_f_5pysam_7libcbcf_has_symbolic_allele(__pyx_v_record) != 0)) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_5 = __pyx_t_4; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_4 = ((!(__pyx_v_record->ptr->n_allele != 0)) != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_5 = __pyx_t_4; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_4 = ((__pyx_v_record->ptr->rlen == __pyx_v_ref_len) != 0); + __pyx_t_5 = __pyx_t_4; + __pyx_L5_bool_binop_done:; + if (__pyx_t_5) { + + /* "pysam/libcbcf.pyx":1175 + * if not has_symbolic_allele(record) and (not record.ptr.n_allele or record.ptr.rlen == ref_len): + * # If INFO/END is not defined in the header, it doesn't exist in the record + * if end_id >= 0: # <<<<<<<<<<<<<< + * info = bcf_get_info(hdr, record.ptr, b'END') + * if info and info.vptr: + */ + __pyx_t_5 = ((__pyx_v_end_id >= 0) != 0); + if (__pyx_t_5) { + + /* "pysam/libcbcf.pyx":1176 + * # If INFO/END is not defined in the header, it doesn't exist in the record + * if end_id >= 0: + * info = bcf_get_info(hdr, record.ptr, b'END') # <<<<<<<<<<<<<< + * if info and info.vptr: + * if bcf_update_info(hdr, record.ptr, b'END', NULL, 0, info.type) < 0: + */ + __pyx_v_info = bcf_get_info(__pyx_v_hdr, __pyx_v_record->ptr, ((char const *)"END")); + + /* "pysam/libcbcf.pyx":1177 + * if end_id >= 0: + * info = bcf_get_info(hdr, record.ptr, b'END') + * if info and info.vptr: # <<<<<<<<<<<<<< + * if bcf_update_info(hdr, record.ptr, b'END', NULL, 0, info.type) < 0: + * raise ValueError('Unable to delete END') + */ + __pyx_t_4 = (__pyx_v_info != 0); + if (__pyx_t_4) { + } else { + __pyx_t_5 = __pyx_t_4; + goto __pyx_L10_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_info->vptr != 0); + __pyx_t_5 = __pyx_t_4; + __pyx_L10_bool_binop_done:; + if (__pyx_t_5) { + + /* "pysam/libcbcf.pyx":1178 + * info = bcf_get_info(hdr, record.ptr, b'END') + * if info and info.vptr: + * if bcf_update_info(hdr, record.ptr, b'END', NULL, 0, info.type) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Unable to delete END') + * else: + */ + __pyx_t_5 = ((bcf_update_info(__pyx_v_hdr, __pyx_v_record->ptr, ((char const *)"END"), NULL, 0, __pyx_v_info->type) < 0) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcbcf.pyx":1179 + * if info and info.vptr: + * if bcf_update_info(hdr, record.ptr, b'END', NULL, 0, info.type) < 0: + * raise ValueError('Unable to delete END') # <<<<<<<<<<<<<< + * else: + * # Create END header, if not present + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__55, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 1179, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":1178 + * info = bcf_get_info(hdr, record.ptr, b'END') + * if info and info.vptr: + * if bcf_update_info(hdr, record.ptr, b'END', NULL, 0, info.type) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Unable to delete END') + * else: + */ + } + + /* "pysam/libcbcf.pyx":1177 + * if end_id >= 0: + * info = bcf_get_info(hdr, record.ptr, b'END') + * if info and info.vptr: # <<<<<<<<<<<<<< + * if bcf_update_info(hdr, record.ptr, b'END', NULL, 0, info.type) < 0: + * raise ValueError('Unable to delete END') + */ + } + + /* "pysam/libcbcf.pyx":1175 + * if not has_symbolic_allele(record) and (not record.ptr.n_allele or record.ptr.rlen == ref_len): + * # If INFO/END is not defined in the header, it doesn't exist in the record + * if end_id >= 0: # <<<<<<<<<<<<<< + * info = bcf_get_info(hdr, record.ptr, b'END') + * if info and info.vptr: + */ + } + + /* "pysam/libcbcf.pyx":1173 + * # Delete INFO/END if no alleles are present or if rlen is equal to len(ref) + * # Always keep END for symbolic alleles + * if not has_symbolic_allele(record) and (not record.ptr.n_allele or record.ptr.rlen == ref_len): # <<<<<<<<<<<<<< + * # If INFO/END is not defined in the header, it doesn't exist in the record + * if end_id >= 0: + */ + goto __pyx_L4; + } + + /* "pysam/libcbcf.pyx":1182 + * else: + * # Create END header, if not present + * if end_id < 0: # <<<<<<<<<<<<<< + * record.header.info.add('END', number=1, type='Integer', description='Stop position of the interval') + * + */ + /*else*/ { + __pyx_t_5 = ((__pyx_v_end_id < 0) != 0); + if (__pyx_t_5) { + + /* "pysam/libcbcf.pyx":1183 + * # Create END header, if not present + * if end_id < 0: + * record.header.info.add('END', number=1, type='Integer', description='Stop position of the interval') # <<<<<<<<<<<<<< + * + * # Update to reflect stop position + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_record->header), __pyx_n_s_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_add); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_number, __pyx_int_1) < 0) __PYX_ERR(0, 1183, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_type, __pyx_n_s_Integer) < 0) __PYX_ERR(0, 1183, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_description, __pyx_kp_s_Stop_position_of_the_interval) < 0) __PYX_ERR(0, 1183, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__56, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "pysam/libcbcf.pyx":1182 + * else: + * # Create END header, if not present + * if end_id < 0: # <<<<<<<<<<<<<< + * record.header.info.add('END', number=1, type='Integer', description='Stop position of the interval') + * + */ + } + + /* "pysam/libcbcf.pyx":1186 + * + * # Update to reflect stop position + * bcf_info_set_value(record, b'END', record.ptr.pos + record.ptr.rlen) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_8 = __Pyx_PyInt_From_int32_t((__pyx_v_record->ptr->pos + __pyx_v_record->ptr->rlen)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_info_set_value(__pyx_v_record, __pyx_n_b_END, __pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_L4:; + + /* "pysam/libcbcf.pyx":1159 + * + * + * cdef inline bcf_sync_end(VariantRecord record): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = record.header.ptr + * cdef bcf_info_t *info + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pysam.libcbcf.bcf_sync_end", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":1189 + * + * + * cdef inline int has_symbolic_allele(VariantRecord record): # <<<<<<<<<<<<<< + * """Return index of first symbolic allele. 0 if no symbolic alleles.""" + * + */ + +static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_has_symbolic_allele(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record) { + long __pyx_v_i; + char *__pyx_v_alt; + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + uint32_t __pyx_t_1; + uint32_t __pyx_t_2; + long __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + size_t __pyx_t_6; + __Pyx_RefNannySetupContext("has_symbolic_allele", 0); + __Pyx_TraceCall("has_symbolic_allele", __pyx_f[0], 1189, 0, __PYX_ERR(0, 1189, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":1192 + * """Return index of first symbolic allele. 0 if no symbolic alleles.""" + * + * for i in range(1, record.ptr.n_allele): # <<<<<<<<<<<<<< + * alt = record.ptr.d.allele[i] + * if alt[0] == b'<' and alt[len(alt) - 1] == b'>': + */ + __pyx_t_1 = __pyx_v_record->ptr->n_allele; + __pyx_t_2 = __pyx_t_1; + for (__pyx_t_3 = 1; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "pysam/libcbcf.pyx":1193 + * + * for i in range(1, record.ptr.n_allele): + * alt = record.ptr.d.allele[i] # <<<<<<<<<<<<<< + * if alt[0] == b'<' and alt[len(alt) - 1] == b'>': + * return i + */ + __pyx_v_alt = (__pyx_v_record->ptr->d.allele[__pyx_v_i]); + + /* "pysam/libcbcf.pyx":1194 + * for i in range(1, record.ptr.n_allele): + * alt = record.ptr.d.allele[i] + * if alt[0] == b'<' and alt[len(alt) - 1] == b'>': # <<<<<<<<<<<<<< + * return i + * + */ + __pyx_t_5 = (((__pyx_v_alt[0]) == '<') != 0); + if (__pyx_t_5) { + } else { + __pyx_t_4 = __pyx_t_5; + goto __pyx_L6_bool_binop_done; + } + __pyx_t_6 = strlen(__pyx_v_alt); + __pyx_t_5 = (((__pyx_v_alt[(__pyx_t_6 - 1)]) == '>') != 0); + __pyx_t_4 = __pyx_t_5; + __pyx_L6_bool_binop_done:; + if (__pyx_t_4) { + + /* "pysam/libcbcf.pyx":1195 + * alt = record.ptr.d.allele[i] + * if alt[0] == b'<' and alt[len(alt) - 1] == b'>': + * return i # <<<<<<<<<<<<<< + * + * return 0 + */ + __pyx_r = __pyx_v_i; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":1194 + * for i in range(1, record.ptr.n_allele): + * alt = record.ptr.d.allele[i] + * if alt[0] == b'<' and alt[len(alt) - 1] == b'>': # <<<<<<<<<<<<<< + * return i + * + */ + } + } + + /* "pysam/libcbcf.pyx":1197 + * return i + * + * return 0 # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":1189 + * + * + * cdef inline int has_symbolic_allele(VariantRecord record): # <<<<<<<<<<<<<< + * """Return index of first symbolic allele. 0 if no symbolic alleles.""" + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_WriteUnraisable("pysam.libcbcf.has_symbolic_allele", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":1206 * * * cdef bcf_header_remove_hrec(VariantHeader header, int i): # <<<<<<<<<<<<<< @@ -16248,9 +17334,9 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj PyObject *__pyx_t_3 = NULL; bcf_hdr_t *__pyx_t_4; __Pyx_RefNannySetupContext("bcf_header_remove_hrec", 0); - __Pyx_TraceCall("bcf_header_remove_hrec", __pyx_f[0], 1070, 0, __PYX_ERR(0, 1070, __pyx_L1_error)); + __Pyx_TraceCall("bcf_header_remove_hrec", __pyx_f[0], 1206, 0, __PYX_ERR(0, 1206, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1071 + /* "pysam/libcbcf.pyx":1207 * * cdef bcf_header_remove_hrec(VariantHeader header, int i): * if header is None: # <<<<<<<<<<<<<< @@ -16261,20 +17347,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1072 + /* "pysam/libcbcf.pyx":1208 * cdef bcf_header_remove_hrec(VariantHeader header, int i): * if header is None: * raise ValueError('header must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = header.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__58, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1072, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__57, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1208, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1072, __pyx_L1_error) + __PYX_ERR(0, 1208, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1071 + /* "pysam/libcbcf.pyx":1207 * * cdef bcf_header_remove_hrec(VariantHeader header, int i): * if header is None: # <<<<<<<<<<<<<< @@ -16283,7 +17369,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":1074 + /* "pysam/libcbcf.pyx":1210 * raise ValueError('header must not be None') * * cdef bcf_hdr_t *hdr = header.ptr # <<<<<<<<<<<<<< @@ -16293,7 +17379,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj __pyx_t_4 = __pyx_v_header->ptr; __pyx_v_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":1076 + /* "pysam/libcbcf.pyx":1212 * cdef bcf_hdr_t *hdr = header.ptr * * if i < 0 or i >= hdr.nhrec: # <<<<<<<<<<<<<< @@ -16311,20 +17397,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj __pyx_L5_bool_binop_done:; if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1077 + /* "pysam/libcbcf.pyx":1213 * * if i < 0 or i >= hdr.nhrec: * raise ValueError('Invalid header record index') # <<<<<<<<<<<<<< * * cdef bcf_hrec_t *hrec = hdr.hrec[i] */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__59, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1077, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__58, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1213, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1077, __pyx_L1_error) + __PYX_ERR(0, 1213, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1076 + /* "pysam/libcbcf.pyx":1212 * cdef bcf_hdr_t *hdr = header.ptr * * if i < 0 or i >= hdr.nhrec: # <<<<<<<<<<<<<< @@ -16333,7 +17419,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":1079 + /* "pysam/libcbcf.pyx":1215 * raise ValueError('Invalid header record index') * * cdef bcf_hrec_t *hrec = hdr.hrec[i] # <<<<<<<<<<<<<< @@ -16342,7 +17428,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj */ __pyx_v_hrec = (__pyx_v_hdr->hrec[__pyx_v_i]); - /* "pysam/libcbcf.pyx":1080 + /* "pysam/libcbcf.pyx":1216 * * cdef bcf_hrec_t *hrec = hdr.hrec[i] * hdr.nhrec -= 1 # <<<<<<<<<<<<<< @@ -16351,7 +17437,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj */ __pyx_v_hdr->nhrec = (__pyx_v_hdr->nhrec - 1); - /* "pysam/libcbcf.pyx":1082 + /* "pysam/libcbcf.pyx":1218 * hdr.nhrec -= 1 * * if i < hdr.nhrec: # <<<<<<<<<<<<<< @@ -16361,7 +17447,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj __pyx_t_2 = ((__pyx_v_i < __pyx_v_hdr->nhrec) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1083 + /* "pysam/libcbcf.pyx":1219 * * if i < hdr.nhrec: * memmove(&hdr.hrec[i], &hdr.hrec[i+1], (hdr.nhrec-i)*sizeof(bcf_hrec_t*)) # <<<<<<<<<<<<<< @@ -16370,7 +17456,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj */ (void)(memmove((&(__pyx_v_hdr->hrec[__pyx_v_i])), (&(__pyx_v_hdr->hrec[(__pyx_v_i + 1)])), ((__pyx_v_hdr->nhrec - __pyx_v_i) * (sizeof(bcf_hrec_t *))))); - /* "pysam/libcbcf.pyx":1082 + /* "pysam/libcbcf.pyx":1218 * hdr.nhrec -= 1 * * if i < hdr.nhrec: # <<<<<<<<<<<<<< @@ -16379,7 +17465,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":1085 + /* "pysam/libcbcf.pyx":1221 * memmove(&hdr.hrec[i], &hdr.hrec[i+1], (hdr.nhrec-i)*sizeof(bcf_hrec_t*)) * * bcf_hrec_destroy(hrec) # <<<<<<<<<<<<<< @@ -16388,7 +17474,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj */ bcf_hrec_destroy(__pyx_v_hrec); - /* "pysam/libcbcf.pyx":1086 + /* "pysam/libcbcf.pyx":1222 * * bcf_hrec_destroy(hrec) * hdr.hrec[hdr.nhrec] = NULL # <<<<<<<<<<<<<< @@ -16397,7 +17483,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj */ (__pyx_v_hdr->hrec[__pyx_v_hdr->nhrec]) = NULL; - /* "pysam/libcbcf.pyx":1087 + /* "pysam/libcbcf.pyx":1223 * bcf_hrec_destroy(hrec) * hdr.hrec[hdr.nhrec] = NULL * hdr.dirty = 1 # <<<<<<<<<<<<<< @@ -16406,7 +17492,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj */ __pyx_v_hdr->dirty = 1; - /* "pysam/libcbcf.pyx":1070 + /* "pysam/libcbcf.pyx":1206 * * * cdef bcf_header_remove_hrec(VariantHeader header, int i): # <<<<<<<<<<<<<< @@ -16428,7 +17514,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_bcf_header_remove_hrec(struct __pyx_obj return __pyx_r; } -/* "pysam/libcbcf.pyx":1095 +/* "pysam/libcbcf.pyx":1231 * cdef class VariantHeaderRecord(object): * """header record from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -16462,22 +17548,22 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord___init__(CYTHON_UNUSED __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1095, 0, __PYX_ERR(0, 1095, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 1231, 0, __PYX_ERR(0, 1231, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1096 + /* "pysam/libcbcf.pyx":1232 * """header record from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * @property */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__60, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1096, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__59, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1096, __pyx_L1_error) + __PYX_ERR(0, 1232, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1095 + /* "pysam/libcbcf.pyx":1231 * cdef class VariantHeaderRecord(object): * """header record from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -16495,7 +17581,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord___init__(CYTHON_UNUSED return __pyx_r; } -/* "pysam/libcbcf.pyx":1099 +/* "pysam/libcbcf.pyx":1235 * * @property * def type(self): # <<<<<<<<<<<<<< @@ -16525,9 +17611,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_4type___get__(st int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1099, 0, __PYX_ERR(0, 1099, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1235, 0, __PYX_ERR(0, 1235, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1101 + /* "pysam/libcbcf.pyx":1237 * def type(self): * """header type: FILTER, INFO, FORMAT, CONTIG, STRUCTURED, or GENERIC""" * cdef bcf_hrec_t *r = self.ptr # <<<<<<<<<<<<<< @@ -16537,7 +17623,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_4type___get__(st __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":1102 + /* "pysam/libcbcf.pyx":1238 * """header type: FILTER, INFO, FORMAT, CONTIG, STRUCTURED, or GENERIC""" * cdef bcf_hrec_t *r = self.ptr * if not r: # <<<<<<<<<<<<<< @@ -16547,7 +17633,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_4type___get__(st __pyx_t_2 = ((!(__pyx_v_r != 0)) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1103 + /* "pysam/libcbcf.pyx":1239 * cdef bcf_hrec_t *r = self.ptr * if not r: * return None # <<<<<<<<<<<<<< @@ -16558,7 +17644,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_4type___get__(st __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1102 + /* "pysam/libcbcf.pyx":1238 * """header type: FILTER, INFO, FORMAT, CONTIG, STRUCTURED, or GENERIC""" * cdef bcf_hrec_t *r = self.ptr * if not r: # <<<<<<<<<<<<<< @@ -16567,7 +17653,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_4type___get__(st */ } - /* "pysam/libcbcf.pyx":1104 + /* "pysam/libcbcf.pyx":1240 * if not r: * return None * return METADATA_TYPES[r.type] # <<<<<<<<<<<<<< @@ -16577,15 +17663,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_4type___get__(st __Pyx_XDECREF(__pyx_r); if (unlikely(__pyx_v_5pysam_7libcbcf_METADATA_TYPES == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 1104, __pyx_L1_error) + __PYX_ERR(0, 1240, __pyx_L1_error) } - __pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_5pysam_7libcbcf_METADATA_TYPES, __pyx_v_r->type, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1104, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_5pysam_7libcbcf_METADATA_TYPES, __pyx_v_r->type, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1240, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1099 + /* "pysam/libcbcf.pyx":1235 * * @property * def type(self): # <<<<<<<<<<<<<< @@ -16605,7 +17691,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_4type___get__(st return __pyx_r; } -/* "pysam/libcbcf.pyx":1107 +/* "pysam/libcbcf.pyx":1243 * * @property * def key(self): # <<<<<<<<<<<<<< @@ -16637,9 +17723,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_3key___get__(str int __pyx_t_4; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1107, 0, __PYX_ERR(0, 1107, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1243, 0, __PYX_ERR(0, 1243, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1109 + /* "pysam/libcbcf.pyx":1245 * def key(self): * """header key (the part before '=', in FILTER/INFO/FORMAT/contig/fileformat etc.)""" * cdef bcf_hrec_t *r = self.ptr # <<<<<<<<<<<<<< @@ -16649,7 +17735,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_3key___get__(str __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":1110 + /* "pysam/libcbcf.pyx":1246 * """header key (the part before '=', in FILTER/INFO/FORMAT/contig/fileformat etc.)""" * cdef bcf_hrec_t *r = self.ptr * return bcf_str_cache_get_charptr(r.key) if r and r.key else None # <<<<<<<<<<<<<< @@ -16667,7 +17753,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_3key___get__(str __pyx_t_3 = __pyx_t_4; __pyx_L3_bool_binop_done:; if (__pyx_t_3) { - __pyx_t_5 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(__pyx_v_r->key); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1110, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(__pyx_v_r->key); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1246, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = __pyx_t_5; __pyx_t_5 = 0; @@ -16679,7 +17765,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_3key___get__(str __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1107 + /* "pysam/libcbcf.pyx":1243 * * @property * def key(self): # <<<<<<<<<<<<<< @@ -16700,7 +17786,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_3key___get__(str return __pyx_r; } -/* "pysam/libcbcf.pyx":1113 +/* "pysam/libcbcf.pyx":1249 * * @property * def value(self): # <<<<<<<<<<<<<< @@ -16732,9 +17818,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5value___get__(s int __pyx_t_4; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1113, 0, __PYX_ERR(0, 1113, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1249, 0, __PYX_ERR(0, 1249, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1115 + /* "pysam/libcbcf.pyx":1251 * def value(self): * """header value. Set only for generic lines, None for FILTER/INFO, etc.""" * cdef bcf_hrec_t *r = self.ptr # <<<<<<<<<<<<<< @@ -16744,7 +17830,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5value___get__(s __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":1116 + /* "pysam/libcbcf.pyx":1252 * """header value. Set only for generic lines, None for FILTER/INFO, etc.""" * cdef bcf_hrec_t *r = self.ptr * return charptr_to_str(r.value) if r and r.value else None # <<<<<<<<<<<<<< @@ -16762,7 +17848,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5value___get__(s __pyx_t_3 = __pyx_t_4; __pyx_L3_bool_binop_done:; if (__pyx_t_3) { - __pyx_t_5 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_r->value, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1116, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_r->value, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1252, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = __pyx_t_5; __pyx_t_5 = 0; @@ -16774,7 +17860,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5value___get__(s __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1113 + /* "pysam/libcbcf.pyx":1249 * * @property * def value(self): # <<<<<<<<<<<<<< @@ -16795,7 +17881,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5value___get__(s return __pyx_r; } -/* "pysam/libcbcf.pyx":1119 +/* "pysam/libcbcf.pyx":1255 * * @property * def attrs(self): # <<<<<<<<<<<<<< @@ -16817,7 +17903,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_1__get__( } static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___2generator32(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1125 +/* "pysam/libcbcf.pyx":1261 * return () * cdef int i * return tuple((bcf_str_cache_get_charptr(r.keys[i]) if r.keys[i] else None, # <<<<<<<<<<<<<< @@ -16834,7 +17920,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___ if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_9_genexpr *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1125, __pyx_L1_error) + __PYX_ERR(0, 1261, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -16842,7 +17928,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___ __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___2generator32, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_VariantHeaderRecord___get___loca, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1125, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___2generator32, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_VariantHeaderRecord___get___loca, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1261, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -16871,7 +17957,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___ PyObject *__pyx_t_6 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("genexpr", 0); - __Pyx_TraceCall("genexpr", __pyx_f[0], 1125, 0, __PYX_ERR(0, 1125, __pyx_L1_error)); + __Pyx_TraceCall("genexpr", __pyx_f[0], 1261, 0, __PYX_ERR(0, 1261, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -16881,9 +17967,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1125, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1261, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1127 + /* "pysam/libcbcf.pyx":1263 * return tuple((bcf_str_cache_get_charptr(r.keys[i]) if r.keys[i] else None, * charptr_to_str(r.vals[i]) if r.vals[i] else None) * for i in range(r.nkeys)) # <<<<<<<<<<<<<< @@ -16895,7 +17981,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___ for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_3; - /* "pysam/libcbcf.pyx":1125 + /* "pysam/libcbcf.pyx":1261 * return () * cdef int i * return tuple((bcf_str_cache_get_charptr(r.keys[i]) if r.keys[i] else None, # <<<<<<<<<<<<<< @@ -16903,7 +17989,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___ * for i in range(r.nkeys)) */ if (((__pyx_cur_scope->__pyx_outer_scope->__pyx_v_r->keys[__pyx_cur_scope->__pyx_v_i]) != 0)) { - __pyx_t_5 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr((__pyx_cur_scope->__pyx_outer_scope->__pyx_v_r->keys[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1125, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr((__pyx_cur_scope->__pyx_outer_scope->__pyx_v_r->keys[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1261, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = __pyx_t_5; __pyx_t_5 = 0; @@ -16912,7 +17998,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___ __pyx_t_4 = Py_None; } - /* "pysam/libcbcf.pyx":1126 + /* "pysam/libcbcf.pyx":1262 * cdef int i * return tuple((bcf_str_cache_get_charptr(r.keys[i]) if r.keys[i] else None, * charptr_to_str(r.vals[i]) if r.vals[i] else None) # <<<<<<<<<<<<<< @@ -16920,7 +18006,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___ * */ if (((__pyx_cur_scope->__pyx_outer_scope->__pyx_v_r->vals[__pyx_cur_scope->__pyx_v_i]) != 0)) { - __pyx_t_6 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_outer_scope->__pyx_v_r->vals[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1126, __pyx_L1_error) + __pyx_t_6 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_outer_scope->__pyx_v_r->vals[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1262, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_5 = __pyx_t_6; __pyx_t_6 = 0; @@ -16929,14 +18015,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___ __pyx_t_5 = Py_None; } - /* "pysam/libcbcf.pyx":1125 + /* "pysam/libcbcf.pyx":1261 * return () * cdef int i * return tuple((bcf_str_cache_get_charptr(r.keys[i]) if r.keys[i] else None, # <<<<<<<<<<<<<< * charptr_to_str(r.vals[i]) if r.vals[i] else None) * for i in range(r.nkeys)) */ - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1125, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1261, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); @@ -16960,7 +18046,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___ __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1125, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1261, __pyx_L1_error) } CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); @@ -16982,7 +18068,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___ return __pyx_r; } -/* "pysam/libcbcf.pyx":1119 +/* "pysam/libcbcf.pyx":1255 * * @property * def attrs(self): # <<<<<<<<<<<<<< @@ -17004,13 +18090,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5attrs___get__(s if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_8___get__ *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1119, __pyx_L1_error) + __PYX_ERR(0, 1255, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } - __Pyx_TraceCall("__get__", __pyx_f[0], 1119, 0, __PYX_ERR(0, 1119, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1255, 0, __PYX_ERR(0, 1255, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1121 + /* "pysam/libcbcf.pyx":1257 * def attrs(self): * """sequence of additional header attributes""" * cdef bcf_hrec_t *r = self.ptr # <<<<<<<<<<<<<< @@ -17020,7 +18106,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5attrs___get__(s __pyx_t_1 = __pyx_v_self->ptr; __pyx_cur_scope->__pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":1122 + /* "pysam/libcbcf.pyx":1258 * """sequence of additional header attributes""" * cdef bcf_hrec_t *r = self.ptr * if not r: # <<<<<<<<<<<<<< @@ -17030,7 +18116,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5attrs___get__(s __pyx_t_2 = ((!(__pyx_cur_scope->__pyx_v_r != 0)) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1123 + /* "pysam/libcbcf.pyx":1259 * cdef bcf_hrec_t *r = self.ptr * if not r: * return () # <<<<<<<<<<<<<< @@ -17042,7 +18128,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5attrs___get__(s __pyx_r = __pyx_empty_tuple; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1122 + /* "pysam/libcbcf.pyx":1258 * """sequence of additional header attributes""" * cdef bcf_hrec_t *r = self.ptr * if not r: # <<<<<<<<<<<<<< @@ -17051,7 +18137,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5attrs___get__(s */ } - /* "pysam/libcbcf.pyx":1125 + /* "pysam/libcbcf.pyx":1261 * return () * cdef int i * return tuple((bcf_str_cache_get_charptr(r.keys[i]) if r.keys[i] else None, # <<<<<<<<<<<<<< @@ -17059,16 +18145,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5attrs___get__(s * for i in range(r.nkeys)) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1125, __pyx_L1_error) + __pyx_t_3 = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_7__get___genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1261, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1125, __pyx_L1_error) + __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1261, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1119 + /* "pysam/libcbcf.pyx":1255 * * @property * def attrs(self): # <<<<<<<<<<<<<< @@ -17090,7 +18176,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_5attrs___get__(s return __pyx_r; } -/* "pysam/libcbcf.pyx":1129 +/* "pysam/libcbcf.pyx":1265 * for i in range(r.nkeys)) * * def __len__(self): # <<<<<<<<<<<<<< @@ -17119,9 +18205,9 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_2__len__(struct bcf_hrec_t *__pyx_t_1; Py_ssize_t __pyx_t_2; __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[0], 1129, 0, __PYX_ERR(0, 1129, __pyx_L1_error)); + __Pyx_TraceCall("__len__", __pyx_f[0], 1265, 0, __PYX_ERR(0, 1265, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1130 + /* "pysam/libcbcf.pyx":1266 * * def __len__(self): * cdef bcf_hrec_t *r = self.ptr # <<<<<<<<<<<<<< @@ -17131,7 +18217,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_2__len__(struct __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":1131 + /* "pysam/libcbcf.pyx":1267 * def __len__(self): * cdef bcf_hrec_t *r = self.ptr * return r.nkeys if r else 0 # <<<<<<<<<<<<<< @@ -17146,7 +18232,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_2__len__(struct __pyx_r = __pyx_t_2; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1129 + /* "pysam/libcbcf.pyx":1265 * for i in range(r.nkeys)) * * def __len__(self): # <<<<<<<<<<<<<< @@ -17164,7 +18250,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_2__len__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1133 +/* "pysam/libcbcf.pyx":1269 * return r.nkeys if r else 0 * * def __bool__(self): # <<<<<<<<<<<<<< @@ -17194,9 +18280,9 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_4__bool__(struct __pyx int __pyx_t_2; int __pyx_t_3; __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 1133, 0, __PYX_ERR(0, 1133, __pyx_L1_error)); + __Pyx_TraceCall("__bool__", __pyx_f[0], 1269, 0, __PYX_ERR(0, 1269, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1134 + /* "pysam/libcbcf.pyx":1270 * * def __bool__(self): * cdef bcf_hrec_t *r = self.ptr # <<<<<<<<<<<<<< @@ -17206,7 +18292,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_4__bool__(struct __pyx __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":1135 + /* "pysam/libcbcf.pyx":1271 * def __bool__(self): * cdef bcf_hrec_t *r = self.ptr * return r != NULL and r.nkeys != 0 # <<<<<<<<<<<<<< @@ -17225,7 +18311,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_4__bool__(struct __pyx __pyx_r = __pyx_t_2; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1133 + /* "pysam/libcbcf.pyx":1269 * return r.nkeys if r else 0 * * def __bool__(self): # <<<<<<<<<<<<<< @@ -17243,7 +18329,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_4__bool__(struct __pyx return __pyx_r; } -/* "pysam/libcbcf.pyx":1137 +/* "pysam/libcbcf.pyx":1273 * return r != NULL and r.nkeys != 0 * * def __getitem__(self, key): # <<<<<<<<<<<<<< @@ -17284,9 +18370,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__(str int __pyx_t_7; PyObject *__pyx_t_8 = NULL; __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[0], 1137, 0, __PYX_ERR(0, 1137, __pyx_L1_error)); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 1273, 0, __PYX_ERR(0, 1273, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1139 + /* "pysam/libcbcf.pyx":1275 * def __getitem__(self, key): * """get attribute value""" * cdef bcf_hrec_t *r = self.ptr # <<<<<<<<<<<<<< @@ -17296,7 +18382,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__(str __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":1141 + /* "pysam/libcbcf.pyx":1277 * cdef bcf_hrec_t *r = self.ptr * cdef int i * if r: # <<<<<<<<<<<<<< @@ -17306,19 +18392,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__(str __pyx_t_2 = (__pyx_v_r != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1142 + /* "pysam/libcbcf.pyx":1278 * cdef int i * if r: * bkey = force_bytes(key) # <<<<<<<<<<<<<< * for i in range(r.nkeys): * if r.keys[i] and r.keys[i] == bkey: */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1142, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1278, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_bkey = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":1143 + /* "pysam/libcbcf.pyx":1279 * if r: * bkey = force_bytes(key) * for i in range(r.nkeys): # <<<<<<<<<<<<<< @@ -17330,7 +18416,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__(str for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; - /* "pysam/libcbcf.pyx":1144 + /* "pysam/libcbcf.pyx":1280 * bkey = force_bytes(key) * for i in range(r.nkeys): * if r.keys[i] and r.keys[i] == bkey: # <<<<<<<<<<<<<< @@ -17343,15 +18429,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__(str __pyx_t_2 = __pyx_t_7; goto __pyx_L7_bool_binop_done; } - __pyx_t_3 = __Pyx_PyBytes_FromString((__pyx_v_r->keys[__pyx_v_i])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1144, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_FromString((__pyx_v_r->keys[__pyx_v_i])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1280, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = (__Pyx_PyBytes_Equals(__pyx_t_3, __pyx_v_bkey, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1144, __pyx_L1_error) + __pyx_t_7 = (__Pyx_PyBytes_Equals(__pyx_t_3, __pyx_v_bkey, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1280, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_2 = __pyx_t_7; __pyx_L7_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1145 + /* "pysam/libcbcf.pyx":1281 * for i in range(r.nkeys): * if r.keys[i] and r.keys[i] == bkey: * return charptr_to_str(r.vals[i]) if r.vals[i] else None # <<<<<<<<<<<<<< @@ -17360,7 +18446,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__(str */ __Pyx_XDECREF(__pyx_r); if (((__pyx_v_r->vals[__pyx_v_i]) != 0)) { - __pyx_t_8 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->vals[__pyx_v_i]), NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1145, __pyx_L1_error) + __pyx_t_8 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->vals[__pyx_v_i]), NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1281, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_3 = __pyx_t_8; __pyx_t_8 = 0; @@ -17372,7 +18458,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__(str __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1144 + /* "pysam/libcbcf.pyx":1280 * bkey = force_bytes(key) * for i in range(r.nkeys): * if r.keys[i] and r.keys[i] == bkey: # <<<<<<<<<<<<<< @@ -17382,7 +18468,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__(str } } - /* "pysam/libcbcf.pyx":1141 + /* "pysam/libcbcf.pyx":1277 * cdef bcf_hrec_t *r = self.ptr * cdef int i * if r: # <<<<<<<<<<<<<< @@ -17391,20 +18477,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__(str */ } - /* "pysam/libcbcf.pyx":1146 + /* "pysam/libcbcf.pyx":1282 * if r.keys[i] and r.keys[i] == bkey: * return charptr_to_str(r.vals[i]) if r.vals[i] else None * raise KeyError('cannot find metadata key') # <<<<<<<<<<<<<< * * def __iter__(self): */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__61, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1146, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__60, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1146, __pyx_L1_error) + __PYX_ERR(0, 1282, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1137 + /* "pysam/libcbcf.pyx":1273 * return r != NULL and r.nkeys != 0 * * def __getitem__(self, key): # <<<<<<<<<<<<<< @@ -17427,7 +18513,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__(str } static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1148 +/* "pysam/libcbcf.pyx":1284 * raise KeyError('cannot find metadata key') * * def __iter__(self): # <<<<<<<<<<<<<< @@ -17457,7 +18543,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_8__iter__(struct if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_10___iter__ *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1148, __pyx_L1_error) + __PYX_ERR(0, 1284, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -17465,7 +18551,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_8__iter__(struct __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantHeaderRecord___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1148, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantHeaderRecord___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1284, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -17494,7 +18580,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator(__py PyObject *__pyx_t_6 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1148, 0, __PYX_ERR(0, 1148, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 1284, 0, __PYX_ERR(0, 1284, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L8_resume_from_yield; @@ -17504,9 +18590,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator(__py return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1148, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1284, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1149 + /* "pysam/libcbcf.pyx":1285 * * def __iter__(self): * cdef bcf_hrec_t *r = self.ptr # <<<<<<<<<<<<<< @@ -17516,7 +18602,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator(__py __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->ptr; __pyx_cur_scope->__pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":1150 + /* "pysam/libcbcf.pyx":1286 * def __iter__(self): * cdef bcf_hrec_t *r = self.ptr * if not r: # <<<<<<<<<<<<<< @@ -17526,7 +18612,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator(__py __pyx_t_2 = ((!(__pyx_cur_scope->__pyx_v_r != 0)) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1151 + /* "pysam/libcbcf.pyx":1287 * cdef bcf_hrec_t *r = self.ptr * if not r: * return # <<<<<<<<<<<<<< @@ -17537,7 +18623,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator(__py __pyx_r = NULL; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1150 + /* "pysam/libcbcf.pyx":1286 * def __iter__(self): * cdef bcf_hrec_t *r = self.ptr * if not r: # <<<<<<<<<<<<<< @@ -17546,7 +18632,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator(__py */ } - /* "pysam/libcbcf.pyx":1153 + /* "pysam/libcbcf.pyx":1289 * return * cdef int i * for i in range(r.nkeys): # <<<<<<<<<<<<<< @@ -17558,7 +18644,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator(__py for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_5; - /* "pysam/libcbcf.pyx":1154 + /* "pysam/libcbcf.pyx":1290 * cdef int i * for i in range(r.nkeys): * if r.keys[i]: # <<<<<<<<<<<<<< @@ -17568,14 +18654,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator(__py __pyx_t_2 = ((__pyx_cur_scope->__pyx_v_r->keys[__pyx_cur_scope->__pyx_v_i]) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1155 + /* "pysam/libcbcf.pyx":1291 * for i in range(r.nkeys): * if r.keys[i]: * yield bcf_str_cache_get_charptr(r.keys[i]) # <<<<<<<<<<<<<< * * def get(self, key, default=None): */ - __pyx_t_6 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr((__pyx_cur_scope->__pyx_v_r->keys[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1155, __pyx_L1_error) + __pyx_t_6 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr((__pyx_cur_scope->__pyx_v_r->keys[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1291, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_r = __pyx_t_6; __pyx_t_6 = 0; @@ -17593,9 +18679,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator(__py __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1155, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1291, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1154 + /* "pysam/libcbcf.pyx":1290 * cdef int i * for i in range(r.nkeys): * if r.keys[i]: # <<<<<<<<<<<<<< @@ -17606,7 +18692,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator(__py } CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1148 + /* "pysam/libcbcf.pyx":1284 * raise KeyError('cannot find metadata key') * * def __iter__(self): # <<<<<<<<<<<<<< @@ -17630,7 +18716,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_10generator(__py return __pyx_r; } -/* "pysam/libcbcf.pyx":1157 +/* "pysam/libcbcf.pyx":1293 * yield bcf_str_cache_get_charptr(r.keys[i]) * * def get(self, key, default=None): # <<<<<<<<<<<<<< @@ -17675,7 +18761,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_12get(PyObject * } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 1157, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 1293, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -17691,7 +18777,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_12get(PyObject * } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1157, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1293, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderRecord.get", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -17716,9 +18802,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_11get(struct __p PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("get", 0); - __Pyx_TraceCall("get", __pyx_f[0], 1157, 0, __PYX_ERR(0, 1157, __pyx_L1_error)); + __Pyx_TraceCall("get", __pyx_f[0], 1293, 0, __PYX_ERR(0, 1293, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1159 + /* "pysam/libcbcf.pyx":1295 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -17734,7 +18820,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_11get(struct __p __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "pysam/libcbcf.pyx":1160 + /* "pysam/libcbcf.pyx":1296 * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: * return self[key] # <<<<<<<<<<<<<< @@ -17742,13 +18828,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_11get(struct __p * return default */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1160, __pyx_L3_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1296, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L7_try_return; - /* "pysam/libcbcf.pyx":1159 + /* "pysam/libcbcf.pyx":1295 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -17759,7 +18845,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_11get(struct __p __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1161 + /* "pysam/libcbcf.pyx":1297 * try: * return self[key] * except KeyError: # <<<<<<<<<<<<<< @@ -17769,12 +18855,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_11get(struct __p __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); if (__pyx_t_5) { __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderRecord.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1161, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1297, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcbcf.pyx":1162 + /* "pysam/libcbcf.pyx":1298 * return self[key] * except KeyError: * return default # <<<<<<<<<<<<<< @@ -17792,7 +18878,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_11get(struct __p goto __pyx_L5_except_error; __pyx_L5_except_error:; - /* "pysam/libcbcf.pyx":1159 + /* "pysam/libcbcf.pyx":1295 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -17818,7 +18904,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_11get(struct __p goto __pyx_L0; } - /* "pysam/libcbcf.pyx":1157 + /* "pysam/libcbcf.pyx":1293 * yield bcf_str_cache_get_charptr(r.keys[i]) * * def get(self, key, default=None): # <<<<<<<<<<<<<< @@ -17840,7 +18926,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_11get(struct __p return __pyx_r; } -/* "pysam/libcbcf.pyx":1164 +/* "pysam/libcbcf.pyx":1300 * return default * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -17873,9 +18959,9 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_13__contains__(struct PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("__contains__", 0); - __Pyx_TraceCall("__contains__", __pyx_f[0], 1164, 0, __PYX_ERR(0, 1164, __pyx_L1_error)); + __Pyx_TraceCall("__contains__", __pyx_f[0], 1300, 0, __PYX_ERR(0, 1300, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1165 + /* "pysam/libcbcf.pyx":1301 * * def __contains__(self, key): * try: # <<<<<<<<<<<<<< @@ -17891,18 +18977,18 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_13__contains__(struct __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "pysam/libcbcf.pyx":1166 + /* "pysam/libcbcf.pyx":1302 * def __contains__(self, key): * try: * self[key] # <<<<<<<<<<<<<< * except KeyError: * return False */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1166, __pyx_L3_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1302, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1165 + /* "pysam/libcbcf.pyx":1301 * * def __contains__(self, key): * try: # <<<<<<<<<<<<<< @@ -17911,7 +18997,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_13__contains__(struct */ } - /* "pysam/libcbcf.pyx":1170 + /* "pysam/libcbcf.pyx":1306 * return False * else: * return True # <<<<<<<<<<<<<< @@ -17925,7 +19011,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_13__contains__(struct __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1167 + /* "pysam/libcbcf.pyx":1303 * try: * self[key] * except KeyError: # <<<<<<<<<<<<<< @@ -17935,12 +19021,12 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_13__contains__(struct __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); if (__pyx_t_5) { __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderRecord.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1167, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1303, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcbcf.pyx":1168 + /* "pysam/libcbcf.pyx":1304 * self[key] * except KeyError: * return False # <<<<<<<<<<<<<< @@ -17956,7 +19042,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_13__contains__(struct goto __pyx_L5_except_error; __pyx_L5_except_error:; - /* "pysam/libcbcf.pyx":1165 + /* "pysam/libcbcf.pyx":1301 * * def __contains__(self, key): * try: # <<<<<<<<<<<<<< @@ -17976,7 +19062,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_13__contains__(struct goto __pyx_L0; } - /* "pysam/libcbcf.pyx":1164 + /* "pysam/libcbcf.pyx":1300 * return default * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -17997,7 +19083,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_13__contains__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1172 +/* "pysam/libcbcf.pyx":1308 * return True * * def iterkeys(self): # <<<<<<<<<<<<<< @@ -18025,9 +19111,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_15iterkeys(struc __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("iterkeys", 0); - __Pyx_TraceCall("iterkeys", __pyx_f[0], 1172, 0, __PYX_ERR(0, 1172, __pyx_L1_error)); + __Pyx_TraceCall("iterkeys", __pyx_f[0], 1308, 0, __PYX_ERR(0, 1308, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1174 + /* "pysam/libcbcf.pyx":1310 * def iterkeys(self): * """D.iterkeys() -> an iterator over the keys of D""" * return iter(self) # <<<<<<<<<<<<<< @@ -18035,13 +19121,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_15iterkeys(struc * def itervalues(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1174, __pyx_L1_error) + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1310, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1172 + /* "pysam/libcbcf.pyx":1308 * return True * * def iterkeys(self): # <<<<<<<<<<<<<< @@ -18062,7 +19148,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_15iterkeys(struc } static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1176 +/* "pysam/libcbcf.pyx":1312 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -18093,7 +19179,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_17itervalues(str if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_11_itervalues *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1176, __pyx_L1_error) + __PYX_ERR(0, 1312, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -18101,7 +19187,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_17itervalues(str __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantHeaderRecord_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1176, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantHeaderRecord_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1312, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -18131,7 +19217,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__p PyObject *__pyx_t_7 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("itervalues", 0); - __Pyx_TraceCall("itervalues", __pyx_f[0], 1176, 0, __PYX_ERR(0, 1176, __pyx_L1_error)); + __Pyx_TraceCall("itervalues", __pyx_f[0], 1312, 0, __PYX_ERR(0, 1312, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L8_resume_from_yield; @@ -18141,9 +19227,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__p return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1176, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1312, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1178 + /* "pysam/libcbcf.pyx":1314 * def itervalues(self): * """D.itervalues() -> an iterator over the values of D""" * cdef bcf_hrec_t *r = self.ptr # <<<<<<<<<<<<<< @@ -18153,7 +19239,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__p __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->ptr; __pyx_cur_scope->__pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":1179 + /* "pysam/libcbcf.pyx":1315 * """D.itervalues() -> an iterator over the values of D""" * cdef bcf_hrec_t *r = self.ptr * if not r: # <<<<<<<<<<<<<< @@ -18163,7 +19249,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__p __pyx_t_2 = ((!(__pyx_cur_scope->__pyx_v_r != 0)) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1180 + /* "pysam/libcbcf.pyx":1316 * cdef bcf_hrec_t *r = self.ptr * if not r: * return # <<<<<<<<<<<<<< @@ -18174,7 +19260,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__p __pyx_r = NULL; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1179 + /* "pysam/libcbcf.pyx":1315 * """D.itervalues() -> an iterator over the values of D""" * cdef bcf_hrec_t *r = self.ptr * if not r: # <<<<<<<<<<<<<< @@ -18183,7 +19269,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__p */ } - /* "pysam/libcbcf.pyx":1182 + /* "pysam/libcbcf.pyx":1318 * return * cdef int i * for i in range(r.nkeys): # <<<<<<<<<<<<<< @@ -18195,7 +19281,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__p for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_5; - /* "pysam/libcbcf.pyx":1183 + /* "pysam/libcbcf.pyx":1319 * cdef int i * for i in range(r.nkeys): * if r.keys[i]: # <<<<<<<<<<<<<< @@ -18205,7 +19291,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__p __pyx_t_2 = ((__pyx_cur_scope->__pyx_v_r->keys[__pyx_cur_scope->__pyx_v_i]) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1184 + /* "pysam/libcbcf.pyx":1320 * for i in range(r.nkeys): * if r.keys[i]: * yield charptr_to_str(r.vals[i]) if r.vals[i] else None # <<<<<<<<<<<<<< @@ -18213,7 +19299,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__p * def iteritems(self): */ if (((__pyx_cur_scope->__pyx_v_r->vals[__pyx_cur_scope->__pyx_v_i]) != 0)) { - __pyx_t_7 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_v_r->vals[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1184, __pyx_L1_error) + __pyx_t_7 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_v_r->vals[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1320, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_6 = __pyx_t_7; __pyx_t_7 = 0; @@ -18237,9 +19323,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__p __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1184, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1320, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1183 + /* "pysam/libcbcf.pyx":1319 * cdef int i * for i in range(r.nkeys): * if r.keys[i]: # <<<<<<<<<<<<<< @@ -18250,7 +19336,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__p } CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1176 + /* "pysam/libcbcf.pyx":1312 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -18276,7 +19362,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_19generator1(__p } static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1186 +/* "pysam/libcbcf.pyx":1322 * yield charptr_to_str(r.vals[i]) if r.vals[i] else None * * def iteritems(self): # <<<<<<<<<<<<<< @@ -18307,7 +19393,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_20iteritems(stru if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_12_iteritems *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1186, __pyx_L1_error) + __PYX_ERR(0, 1322, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -18315,7 +19401,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_20iteritems(stru __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantHeaderRecord_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1186, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantHeaderRecord_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1322, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -18346,7 +19432,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__p PyObject *__pyx_t_8 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("iteritems", 0); - __Pyx_TraceCall("iteritems", __pyx_f[0], 1186, 0, __PYX_ERR(0, 1186, __pyx_L1_error)); + __Pyx_TraceCall("iteritems", __pyx_f[0], 1322, 0, __PYX_ERR(0, 1322, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L8_resume_from_yield; @@ -18356,9 +19442,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__p return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1186, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1322, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1188 + /* "pysam/libcbcf.pyx":1324 * def iteritems(self): * """D.iteritems() -> an iterator over the (key, value) items of D""" * cdef bcf_hrec_t *r = self.ptr # <<<<<<<<<<<<<< @@ -18368,7 +19454,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__p __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->ptr; __pyx_cur_scope->__pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":1189 + /* "pysam/libcbcf.pyx":1325 * """D.iteritems() -> an iterator over the (key, value) items of D""" * cdef bcf_hrec_t *r = self.ptr * if not r: # <<<<<<<<<<<<<< @@ -18378,7 +19464,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__p __pyx_t_2 = ((!(__pyx_cur_scope->__pyx_v_r != 0)) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1190 + /* "pysam/libcbcf.pyx":1326 * cdef bcf_hrec_t *r = self.ptr * if not r: * return # <<<<<<<<<<<<<< @@ -18389,7 +19475,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__p __pyx_r = NULL; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1189 + /* "pysam/libcbcf.pyx":1325 * """D.iteritems() -> an iterator over the (key, value) items of D""" * cdef bcf_hrec_t *r = self.ptr * if not r: # <<<<<<<<<<<<<< @@ -18398,7 +19484,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__p */ } - /* "pysam/libcbcf.pyx":1192 + /* "pysam/libcbcf.pyx":1328 * return * cdef int i * for i in range(r.nkeys): # <<<<<<<<<<<<<< @@ -18410,7 +19496,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__p for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_5; - /* "pysam/libcbcf.pyx":1193 + /* "pysam/libcbcf.pyx":1329 * cdef int i * for i in range(r.nkeys): * if r.keys[i]: # <<<<<<<<<<<<<< @@ -18420,17 +19506,17 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__p __pyx_t_2 = ((__pyx_cur_scope->__pyx_v_r->keys[__pyx_cur_scope->__pyx_v_i]) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1194 + /* "pysam/libcbcf.pyx":1330 * for i in range(r.nkeys): * if r.keys[i]: * yield (bcf_str_cache_get_charptr(r.keys[i]), charptr_to_str(r.vals[i]) if r.vals[i] else None) # <<<<<<<<<<<<<< * * def keys(self): */ - __pyx_t_6 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr((__pyx_cur_scope->__pyx_v_r->keys[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1194, __pyx_L1_error) + __pyx_t_6 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr((__pyx_cur_scope->__pyx_v_r->keys[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1330, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); if (((__pyx_cur_scope->__pyx_v_r->vals[__pyx_cur_scope->__pyx_v_i]) != 0)) { - __pyx_t_8 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_v_r->vals[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1194, __pyx_L1_error) + __pyx_t_8 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_v_r->vals[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1330, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_7 = __pyx_t_8; __pyx_t_8 = 0; @@ -18438,7 +19524,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__p __Pyx_INCREF(Py_None); __pyx_t_7 = Py_None; } - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1194, __pyx_L1_error) + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1330, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); @@ -18462,9 +19548,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__p __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1194, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1330, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1193 + /* "pysam/libcbcf.pyx":1329 * cdef int i * for i in range(r.nkeys): * if r.keys[i]: # <<<<<<<<<<<<<< @@ -18475,7 +19561,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__p } CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1186 + /* "pysam/libcbcf.pyx":1322 * yield charptr_to_str(r.vals[i]) if r.vals[i] else None * * def iteritems(self): # <<<<<<<<<<<<<< @@ -18501,7 +19587,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantHeaderRecord_22generator2(__p return __pyx_r; } -/* "pysam/libcbcf.pyx":1196 +/* "pysam/libcbcf.pyx":1332 * yield (bcf_str_cache_get_charptr(r.keys[i]), charptr_to_str(r.vals[i]) if r.vals[i] else None) * * def keys(self): # <<<<<<<<<<<<<< @@ -18529,9 +19615,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_23keys(struct __ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("keys", 0); - __Pyx_TraceCall("keys", __pyx_f[0], 1196, 0, __PYX_ERR(0, 1196, __pyx_L1_error)); + __Pyx_TraceCall("keys", __pyx_f[0], 1332, 0, __PYX_ERR(0, 1332, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1198 + /* "pysam/libcbcf.pyx":1334 * def keys(self): * """D.keys() -> list of D's keys""" * return list(self) # <<<<<<<<<<<<<< @@ -18539,13 +19625,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_23keys(struct __ * def items(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1198, __pyx_L1_error) + __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1334, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1196 + /* "pysam/libcbcf.pyx":1332 * yield (bcf_str_cache_get_charptr(r.keys[i]), charptr_to_str(r.vals[i]) if r.vals[i] else None) * * def keys(self): # <<<<<<<<<<<<<< @@ -18565,7 +19651,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_23keys(struct __ return __pyx_r; } -/* "pysam/libcbcf.pyx":1200 +/* "pysam/libcbcf.pyx":1336 * return list(self) * * def items(self): # <<<<<<<<<<<<<< @@ -18595,9 +19681,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_25items(struct _ PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("items", 0); - __Pyx_TraceCall("items", __pyx_f[0], 1200, 0, __PYX_ERR(0, 1200, __pyx_L1_error)); + __Pyx_TraceCall("items", __pyx_f[0], 1336, 0, __PYX_ERR(0, 1336, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1202 + /* "pysam/libcbcf.pyx":1338 * def items(self): * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" * return list(self.iteritems()) # <<<<<<<<<<<<<< @@ -18605,7 +19691,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_25items(struct _ * def values(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1202, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1338, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -18618,21 +19704,21 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_25items(struct _ } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1202, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1338, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1202, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1338, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1202, __pyx_L1_error) + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1338, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1200 + /* "pysam/libcbcf.pyx":1336 * return list(self) * * def items(self): # <<<<<<<<<<<<<< @@ -18654,7 +19740,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_25items(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":1204 +/* "pysam/libcbcf.pyx":1340 * return list(self.iteritems()) * * def values(self): # <<<<<<<<<<<<<< @@ -18684,17 +19770,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_27values(struct PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("values", 0); - __Pyx_TraceCall("values", __pyx_f[0], 1204, 0, __PYX_ERR(0, 1204, __pyx_L1_error)); + __Pyx_TraceCall("values", __pyx_f[0], 1340, 0, __PYX_ERR(0, 1340, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1206 + /* "pysam/libcbcf.pyx":1342 * def values(self): * """D.values() -> list of D's values""" * return list(self.itervalues()) # <<<<<<<<<<<<<< * - * # Mappings are not hashable by default, but subclasses can change this + * def update(self, items=None, **kwargs): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1206, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -18707,21 +19793,21 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_27values(struct } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1206, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1342, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1206, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1342, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1206, __pyx_L1_error) + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1204 + /* "pysam/libcbcf.pyx":1340 * return list(self.iteritems()) * * def values(self): # <<<<<<<<<<<<<< @@ -18743,7 +19829,665 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_27values(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1213 +/* "pysam/libcbcf.pyx":1344 + * return list(self.itervalues()) + * + * def update(self, items=None, **kwargs): # <<<<<<<<<<<<<< + * """D.update([E, ]**F) -> None. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_30update(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_29update[] = "VariantHeaderRecord.update(self, items=None, **kwargs)\nD.update([E, ]**F) -> None.\n\n Update D from dict/iterable E and F.\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_30update(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_items = 0; + PyObject *__pyx_v_kwargs = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("update (wrapper)", 0); + __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,0}; + PyObject* values[1] = {0}; + values[0] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "update") < 0)) __PYX_ERR(0, 1344, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_items = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("update", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1344, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderRecord.update", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29update(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_self), __pyx_v_items, __pyx_v_kwargs); + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29update(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self, PyObject *__pyx_v_items, PyObject *__pyx_v_kwargs) { + PyObject *__pyx_v_k = NULL; + PyObject *__pyx_v_v = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + __Pyx_RefNannySetupContext("update", 0); + __Pyx_TraceCall("update", __pyx_f[0], 1344, 0, __PYX_ERR(0, 1344, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":1349 + * Update D from dict/iterable E and F. + * """ + * for k, v in items.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_items, __pyx_n_s_items); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1349, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1349, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1349, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1349, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1349, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_5(__pyx_t_2); + if (unlikely(!__pyx_t_1)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1349, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1349, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 1349, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1349, __pyx_L1_error) + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libcbcf.pyx":1350 + * """ + * for k, v in items.items(): + * self[k] = v # <<<<<<<<<<<<<< + * + * if kwargs: + */ + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_k, __pyx_v_v) < 0)) __PYX_ERR(0, 1350, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":1349 + * Update D from dict/iterable E and F. + * """ + * for k, v in items.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libcbcf.pyx":1352 + * self[k] = v + * + * if kwargs: # <<<<<<<<<<<<<< + * for k, v in kwargs.items(): + * self[k] = v + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_kwargs); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1352, __pyx_L1_error) + if (__pyx_t_9) { + + /* "pysam/libcbcf.pyx":1353 + * + * if kwargs: + * for k, v in kwargs.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1353, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1353, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1353, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1353, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1353, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_3); + #else + __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1353, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L10_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L10_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 1353, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L11_unpacking_done; + __pyx_L10_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1353, __pyx_L1_error) + __pyx_L11_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":1354 + * if kwargs: + * for k, v in kwargs.items(): + * self[k] = v # <<<<<<<<<<<<<< + * + * def pop(self, key, default=_nothing): + */ + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_k, __pyx_v_v) < 0)) __PYX_ERR(0, 1354, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":1353 + * + * if kwargs: + * for k, v in kwargs.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":1352 + * self[k] = v + * + * if kwargs: # <<<<<<<<<<<<<< + * for k, v in kwargs.items(): + * self[k] = v + */ + } + + /* "pysam/libcbcf.pyx":1344 + * return list(self.itervalues()) + * + * def update(self, items=None, **kwargs): # <<<<<<<<<<<<<< + * """D.update([E, ]**F) -> None. + * + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderRecord.update", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_k); + __Pyx_XDECREF(__pyx_v_v); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":1356 + * self[k] = v + * + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * try: + * value = self[key] + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_32pop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_31pop[] = "VariantHeaderRecord.pop(self, key, default=_nothing)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_32pop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_key = 0; + PyObject *__pyx_v_default = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("pop (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_default,0}; + PyObject* values[2] = {0,0}; + values[1] = __pyx_k__61; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_default); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "pop") < 0)) __PYX_ERR(0, 1356, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_key = values[0]; + __pyx_v_default = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("pop", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1356, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderRecord.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31pop(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_self), __pyx_v_key, __pyx_v_default); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31pop(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default) { + PyObject *__pyx_v_value = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + int __pyx_t_9; + __Pyx_RefNannySetupContext("pop", 0); + __Pyx_TraceCall("pop", __pyx_f[0], 1356, 0, __PYX_ERR(0, 1356, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":1357 + * + * def pop(self, key, default=_nothing): + * try: # <<<<<<<<<<<<<< + * value = self[key] + * del self[key] + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "pysam/libcbcf.pyx":1358 + * def pop(self, key, default=_nothing): + * try: + * value = self[key] # <<<<<<<<<<<<<< + * del self[key] + * return value + */ + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1358, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_value = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pysam/libcbcf.pyx":1359 + * try: + * value = self[key] + * del self[key] # <<<<<<<<<<<<<< + * return value + * except KeyError: + */ + if (unlikely(PyObject_DelItem(((PyObject *)__pyx_v_self), __pyx_v_key) < 0)) __PYX_ERR(0, 1359, __pyx_L3_error) + + /* "pysam/libcbcf.pyx":1360 + * value = self[key] + * del self[key] + * return value # <<<<<<<<<<<<<< + * except KeyError: + * if default is not _nothing: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_value); + __pyx_r = __pyx_v_value; + goto __pyx_L7_try_return; + + /* "pysam/libcbcf.pyx":1357 + * + * def pop(self, key, default=_nothing): + * try: # <<<<<<<<<<<<<< + * value = self[key] + * del self[key] + */ + } + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libcbcf.pyx":1361 + * del self[key] + * return value + * except KeyError: # <<<<<<<<<<<<<< + * if default is not _nothing: + * return default + */ + __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); + if (__pyx_t_5) { + __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderRecord.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1361, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); + + /* "pysam/libcbcf.pyx":1362 + * return value + * except KeyError: + * if default is not _nothing: # <<<<<<<<<<<<<< + * return default + * raise + */ + __pyx_t_8 = (__pyx_v_default != __pyx_v_5pysam_7libcbcf__nothing); + __pyx_t_9 = (__pyx_t_8 != 0); + if (__pyx_t_9) { + + /* "pysam/libcbcf.pyx":1363 + * except KeyError: + * if default is not _nothing: + * return default # <<<<<<<<<<<<<< + * raise + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_default); + __pyx_r = __pyx_v_default; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_except_return; + + /* "pysam/libcbcf.pyx":1362 + * return value + * except KeyError: + * if default is not _nothing: # <<<<<<<<<<<<<< + * return default + * raise + */ + } + + /* "pysam/libcbcf.pyx":1364 + * if default is not _nothing: + * return default + * raise # <<<<<<<<<<<<<< + * + * # Mappings are not hashable by default, but subclasses can change this + */ + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_6, __pyx_t_7); + __pyx_t_4 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0; + __PYX_ERR(0, 1364, __pyx_L5_except_error) + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "pysam/libcbcf.pyx":1357 + * + * def pop(self, key, default=_nothing): + * try: # <<<<<<<<<<<<<< + * value = self[key] + * del self[key] + */ + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L7_try_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + __pyx_L6_except_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + } + + /* "pysam/libcbcf.pyx":1356 + * self[k] = v + * + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * try: + * value = self[key] + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderRecord.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_value); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":1371 * #TODO: implement __richcmp__ * * def __str__(self): # <<<<<<<<<<<<<< @@ -18752,19 +20496,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_27values(struct */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_30__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_30__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_34__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_34__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_33__str__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_33__str__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self) { bcf_hrec_t *__pyx_v_r; kstring_t __pyx_v_hrec_str; PyObject *__pyx_v_ret = NULL; @@ -18775,9 +20519,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__str__", 0); - __Pyx_TraceCall("__str__", __pyx_f[0], 1213, 0, __PYX_ERR(0, 1213, __pyx_L1_error)); + __Pyx_TraceCall("__str__", __pyx_f[0], 1371, 0, __PYX_ERR(0, 1371, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1214 + /* "pysam/libcbcf.pyx":1372 * * def __str__(self): * cdef bcf_hrec_t *r = self.ptr # <<<<<<<<<<<<<< @@ -18787,7 +20531,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":1216 + /* "pysam/libcbcf.pyx":1374 * cdef bcf_hrec_t *r = self.ptr * * if not r: # <<<<<<<<<<<<<< @@ -18797,20 +20541,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct __pyx_t_2 = ((!(__pyx_v_r != 0)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1217 + /* "pysam/libcbcf.pyx":1375 * * if not r: * raise ValueError('cannot convert deleted record to str') # <<<<<<<<<<<<<< * * cdef kstring_t hrec_str */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1217, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1375, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1217, __pyx_L1_error) + __PYX_ERR(0, 1375, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1216 + /* "pysam/libcbcf.pyx":1374 * cdef bcf_hrec_t *r = self.ptr * * if not r: # <<<<<<<<<<<<<< @@ -18819,7 +20563,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct */ } - /* "pysam/libcbcf.pyx":1220 + /* "pysam/libcbcf.pyx":1378 * * cdef kstring_t hrec_str * hrec_str.l = hrec_str.m = 0 # <<<<<<<<<<<<<< @@ -18829,7 +20573,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct __pyx_v_hrec_str.l = 0; __pyx_v_hrec_str.m = 0; - /* "pysam/libcbcf.pyx":1221 + /* "pysam/libcbcf.pyx":1379 * cdef kstring_t hrec_str * hrec_str.l = hrec_str.m = 0 * hrec_str.s = NULL # <<<<<<<<<<<<<< @@ -18838,7 +20582,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct */ __pyx_v_hrec_str.s = NULL; - /* "pysam/libcbcf.pyx":1223 + /* "pysam/libcbcf.pyx":1381 * hrec_str.s = NULL * * bcf_hrec_format(r, &hrec_str) # <<<<<<<<<<<<<< @@ -18847,19 +20591,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct */ bcf_hrec_format(__pyx_v_r, (&__pyx_v_hrec_str)); - /* "pysam/libcbcf.pyx":1225 + /* "pysam/libcbcf.pyx":1383 * bcf_hrec_format(r, &hrec_str) * * ret = charptr_to_str_w_len(hrec_str.s, hrec_str.l) # <<<<<<<<<<<<<< * * if hrec_str.m: */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str_w_len(__pyx_v_hrec_str.s, __pyx_v_hrec_str.l, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1225, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str_w_len(__pyx_v_hrec_str.s, __pyx_v_hrec_str.l, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1383, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_ret = __pyx_t_3; __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":1227 + /* "pysam/libcbcf.pyx":1385 * ret = charptr_to_str_w_len(hrec_str.s, hrec_str.l) * * if hrec_str.m: # <<<<<<<<<<<<<< @@ -18869,7 +20613,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct __pyx_t_2 = (__pyx_v_hrec_str.m != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1228 + /* "pysam/libcbcf.pyx":1386 * * if hrec_str.m: * free(hrec_str.s) # <<<<<<<<<<<<<< @@ -18878,7 +20622,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct */ free(__pyx_v_hrec_str.s); - /* "pysam/libcbcf.pyx":1227 + /* "pysam/libcbcf.pyx":1385 * ret = charptr_to_str_w_len(hrec_str.s, hrec_str.l) * * if hrec_str.m: # <<<<<<<<<<<<<< @@ -18887,7 +20631,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct */ } - /* "pysam/libcbcf.pyx":1230 + /* "pysam/libcbcf.pyx":1388 * free(hrec_str.s) * * return ret # <<<<<<<<<<<<<< @@ -18899,7 +20643,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1213 + /* "pysam/libcbcf.pyx":1371 * #TODO: implement __richcmp__ * * def __str__(self): # <<<<<<<<<<<<<< @@ -18920,7 +20664,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1233 +/* "pysam/libcbcf.pyx":1391 * * # FIXME: Not safe -- causes trivial segfaults at the moment * def remove(self): # <<<<<<<<<<<<<< @@ -18929,20 +20673,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_29__str__(struct */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_32remove(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_31remove[] = "VariantHeaderRecord.remove(self)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_32remove(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_36remove(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_35remove[] = "VariantHeaderRecord.remove(self)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_36remove(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("remove (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31remove(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_35remove(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31remove(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_35remove(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self) { bcf_hdr_t *__pyx_v_hdr; bcf_hrec_t *__pyx_v_r; char *__pyx_v_key; @@ -18953,19 +20697,10 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31remove(struct bcf_hrec_t *__pyx_t_2; int __pyx_t_3; char *__pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - int __pyx_t_12; - PyObject *__pyx_t_13 = NULL; __Pyx_RefNannySetupContext("remove", 0); - __Pyx_TraceCall("remove", __pyx_f[0], 1233, 0, __PYX_ERR(0, 1233, __pyx_L1_error)); + __Pyx_TraceCall("remove", __pyx_f[0], 1391, 0, __PYX_ERR(0, 1391, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1234 + /* "pysam/libcbcf.pyx":1392 * # FIXME: Not safe -- causes trivial segfaults at the moment * def remove(self): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -18975,7 +20710,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31remove(struct __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1235 + /* "pysam/libcbcf.pyx":1393 * def remove(self): * cdef bcf_hdr_t *hdr = self.header.ptr * cdef bcf_hrec_t *r = self.ptr # <<<<<<<<<<<<<< @@ -18985,58 +20720,58 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31remove(struct __pyx_t_2 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":1236 + /* "pysam/libcbcf.pyx":1394 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef bcf_hrec_t *r = self.ptr * if not r: # <<<<<<<<<<<<<< * return - * assert(r.key) + * assert r.key */ __pyx_t_3 = ((!(__pyx_v_r != 0)) != 0); if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":1237 + /* "pysam/libcbcf.pyx":1395 * cdef bcf_hrec_t *r = self.ptr * if not r: * return # <<<<<<<<<<<<<< - * assert(r.key) + * assert r.key * cdef char *key = r.key if r.type == BCF_HL_GEN else r.value */ __Pyx_XDECREF(__pyx_r); __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1236 + /* "pysam/libcbcf.pyx":1394 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef bcf_hrec_t *r = self.ptr * if not r: # <<<<<<<<<<<<<< * return - * assert(r.key) + * assert r.key */ } - /* "pysam/libcbcf.pyx":1238 + /* "pysam/libcbcf.pyx":1396 * if not r: * return - * assert(r.key) # <<<<<<<<<<<<<< + * assert r.key # <<<<<<<<<<<<<< * cdef char *key = r.key if r.type == BCF_HL_GEN else r.value - * print('Removing header type={} key={} value={} hdr={}'.format(METADATA_TYPES[r.type], r.key, r.value, key)) + * bcf_hdr_remove(hdr, r.type, key) */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!(__pyx_v_r->key != 0))) { PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 1238, __pyx_L1_error) + __PYX_ERR(0, 1396, __pyx_L1_error) } } #endif - /* "pysam/libcbcf.pyx":1239 + /* "pysam/libcbcf.pyx":1397 * return - * assert(r.key) + * assert r.key * cdef char *key = r.key if r.type == BCF_HL_GEN else r.value # <<<<<<<<<<<<<< - * print('Removing header type={} key={} value={} hdr={}'.format(METADATA_TYPES[r.type], r.key, r.value, key)) * bcf_hdr_remove(hdr, r.type, key) + * self.ptr = NULL */ if (((__pyx_v_r->type == BCF_HL_GEN) != 0)) { __pyx_t_4 = __pyx_v_r->key; @@ -19045,102 +20780,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31remove(struct } __pyx_v_key = __pyx_t_4; - /* "pysam/libcbcf.pyx":1240 - * assert(r.key) - * cdef char *key = r.key if r.type == BCF_HL_GEN else r.value - * print('Removing header type={} key={} value={} hdr={}'.format(METADATA_TYPES[r.type], r.key, r.value, key)) # <<<<<<<<<<<<<< - * bcf_hdr_remove(hdr, r.type, key) - * self.ptr = NULL - */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Removing_header_type_key_value_h, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (unlikely(__pyx_v_5pysam_7libcbcf_METADATA_TYPES == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 1240, __pyx_L1_error) - } - __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v_5pysam_7libcbcf_METADATA_TYPES, __pyx_v_r->type, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyBytes_FromString(__pyx_v_r->key); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyBytes_FromString(__pyx_v_r->value); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = __Pyx_PyBytes_FromString(__pyx_v_key); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_11 = NULL; - __pyx_t_12 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - __pyx_t_12 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[5] = {__pyx_t_11, __pyx_t_7, __pyx_t_8, __pyx_t_9, __pyx_t_10}; - __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_12, 4+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[5] = {__pyx_t_11, __pyx_t_7, __pyx_t_8, __pyx_t_9, __pyx_t_10}; - __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_12, 4+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else - #endif - { - __pyx_t_13 = PyTuple_New(4+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - if (__pyx_t_11) { - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL; - } - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_12, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_12, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_13, 2+__pyx_t_12, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_13, 3+__pyx_t_12, __pyx_t_10); - __pyx_t_7 = 0; - __pyx_t_8 = 0; - __pyx_t_9 = 0; - __pyx_t_10 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_13, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1240, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pysam/libcbcf.pyx":1241 + /* "pysam/libcbcf.pyx":1398 + * assert r.key * cdef char *key = r.key if r.type == BCF_HL_GEN else r.value - * print('Removing header type={} key={} value={} hdr={}'.format(METADATA_TYPES[r.type], r.key, r.value, key)) * bcf_hdr_remove(hdr, r.type, key) # <<<<<<<<<<<<<< * self.ptr = NULL * */ bcf_hdr_remove(__pyx_v_hdr, __pyx_v_r->type, __pyx_v_key); - /* "pysam/libcbcf.pyx":1242 - * print('Removing header type={} key={} value={} hdr={}'.format(METADATA_TYPES[r.type], r.key, r.value, key)) + /* "pysam/libcbcf.pyx":1399 + * cdef char *key = r.key if r.type == BCF_HL_GEN else r.value * bcf_hdr_remove(hdr, r.type, key) * self.ptr = NULL # <<<<<<<<<<<<<< * @@ -19148,7 +20798,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31remove(struct */ __pyx_v_self->ptr = NULL; - /* "pysam/libcbcf.pyx":1233 + /* "pysam/libcbcf.pyx":1391 * * # FIXME: Not safe -- causes trivial segfaults at the moment * def remove(self): # <<<<<<<<<<<<<< @@ -19160,14 +20810,6 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31remove(struct __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_13); __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderRecord.remove", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -19177,6 +20819,49 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31remove(struct return __pyx_r; } +/* "pysam/libcbcf.pxd":45 + * + * cdef class VariantHeaderRecord(object): + * cdef readonly VariantHeader header # <<<<<<<<<<<<<< + * cdef bcf_hrec_t *ptr + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_6header_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6header___get__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 45, 0, __PYX_ERR(1, 45, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); + __pyx_r = ((PyObject *)__pyx_v_self->header); + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderRecord.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * raise TypeError("self.ptr cannot be converted to a Python object for pickling") @@ -19184,26 +20869,26 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_31remove(struct */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_34__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_33__reduce_cython__[] = "VariantHeaderRecord.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_34__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_38__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_37__reduce_cython__[] = "VariantHeaderRecord.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_38__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_33__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_37__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_33__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_37__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -19211,11 +20896,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_33__reduce_cytho * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__63, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__63, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + __PYX_ERR(2, 2, __pyx_L1_error) /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< @@ -19242,37 +20927,37 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_33__reduce_cytho */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_36__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_35__setstate_cython__[] = "VariantHeaderRecord.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_36__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_40__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_39__setstate_cython__[] = "VariantHeaderRecord.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_40__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_35__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_39__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_35__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_39__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 3, 0, __PYX_ERR(2, 3, __pyx_L1_error)); /* "(tree fragment)":4 * raise TypeError("self.ptr cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -19292,7 +20977,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantHeaderRecord_35__setstate_cyt return __pyx_r; } -/* "pysam/libcbcf.pyx":1245 +/* "pysam/libcbcf.pyx":1402 * * * cdef VariantHeaderRecord makeVariantHeaderRecord(VariantHeader header, bcf_hrec_t *hdr): # <<<<<<<<<<<<<< @@ -19309,33 +20994,33 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_f_5pysam_7lib int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("makeVariantHeaderRecord", 0); - __Pyx_TraceCall("makeVariantHeaderRecord", __pyx_f[0], 1245, 0, __PYX_ERR(0, 1245, __pyx_L1_error)); + __Pyx_TraceCall("makeVariantHeaderRecord", __pyx_f[0], 1402, 0, __PYX_ERR(0, 1402, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1246 + /* "pysam/libcbcf.pyx":1403 * * cdef VariantHeaderRecord makeVariantHeaderRecord(VariantHeader header, bcf_hrec_t *hdr): * if not header: # <<<<<<<<<<<<<< * raise ValueError('invalid VariantHeader') * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1246, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1403, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1247 + /* "pysam/libcbcf.pyx":1404 * cdef VariantHeaderRecord makeVariantHeaderRecord(VariantHeader header, bcf_hrec_t *hdr): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * if not hdr: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__65, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1247, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__65, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1247, __pyx_L1_error) + __PYX_ERR(0, 1404, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1246 + /* "pysam/libcbcf.pyx":1403 * * cdef VariantHeaderRecord makeVariantHeaderRecord(VariantHeader header, bcf_hrec_t *hdr): * if not header: # <<<<<<<<<<<<<< @@ -19344,7 +21029,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_f_5pysam_7lib */ } - /* "pysam/libcbcf.pyx":1249 + /* "pysam/libcbcf.pyx":1406 * raise ValueError('invalid VariantHeader') * * if not hdr: # <<<<<<<<<<<<<< @@ -19354,7 +21039,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_f_5pysam_7lib __pyx_t_2 = ((!(__pyx_v_hdr != 0)) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1250 + /* "pysam/libcbcf.pyx":1407 * * if not hdr: * return None # <<<<<<<<<<<<<< @@ -19365,7 +21050,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_f_5pysam_7lib __pyx_r = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1249 + /* "pysam/libcbcf.pyx":1406 * raise ValueError('invalid VariantHeader') * * if not hdr: # <<<<<<<<<<<<<< @@ -19374,19 +21059,19 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_f_5pysam_7lib */ } - /* "pysam/libcbcf.pyx":1252 + /* "pysam/libcbcf.pyx":1409 * return None * * cdef VariantHeaderRecord record = VariantHeaderRecord.__new__(VariantHeaderRecord) # <<<<<<<<<<<<<< * record.header = header * record.ptr = hdr */ - __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantHeaderRecord(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderRecord), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1252, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantHeaderRecord(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderRecord), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1409, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_v_record = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":1253 + /* "pysam/libcbcf.pyx":1410 * * cdef VariantHeaderRecord record = VariantHeaderRecord.__new__(VariantHeaderRecord) * record.header = header # <<<<<<<<<<<<<< @@ -19399,7 +21084,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_f_5pysam_7lib __Pyx_DECREF(((PyObject *)__pyx_v_record->header)); __pyx_v_record->header = __pyx_v_header; - /* "pysam/libcbcf.pyx":1254 + /* "pysam/libcbcf.pyx":1411 * cdef VariantHeaderRecord record = VariantHeaderRecord.__new__(VariantHeaderRecord) * record.header = header * record.ptr = hdr # <<<<<<<<<<<<<< @@ -19408,7 +21093,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_f_5pysam_7lib */ __pyx_v_record->ptr = __pyx_v_hdr; - /* "pysam/libcbcf.pyx":1256 + /* "pysam/libcbcf.pyx":1413 * record.ptr = hdr * * return record # <<<<<<<<<<<<<< @@ -19420,7 +21105,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_f_5pysam_7lib __pyx_r = __pyx_v_record; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1245 + /* "pysam/libcbcf.pyx":1402 * * * cdef VariantHeaderRecord makeVariantHeaderRecord(VariantHeader header, bcf_hrec_t *hdr): # <<<<<<<<<<<<<< @@ -19441,7 +21126,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_f_5pysam_7lib return __pyx_r; } -/* "pysam/libcbcf.pyx":1261 +/* "pysam/libcbcf.pyx":1418 * cdef class VariantHeaderRecords(object): * """sequence of :class:`VariantHeaderRecord` object from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -19475,22 +21160,22 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords___init__(CYTHON_UNUSE __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1261, 0, __PYX_ERR(0, 1261, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 1418, 0, __PYX_ERR(0, 1418, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1262 + /* "pysam/libcbcf.pyx":1419 * """sequence of :class:`VariantHeaderRecord` object from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__66, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1262, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__66, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1419, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1262, __pyx_L1_error) + __PYX_ERR(0, 1419, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1261 + /* "pysam/libcbcf.pyx":1418 * cdef class VariantHeaderRecords(object): * """sequence of :class:`VariantHeaderRecord` object from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -19508,7 +21193,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords___init__(CYTHON_UNUSE return __pyx_r; } -/* "pysam/libcbcf.pyx":1264 +/* "pysam/libcbcf.pyx":1421 * raise TypeError('this class cannot be instantiated from Python') * * def __len__(self): # <<<<<<<<<<<<<< @@ -19534,9 +21219,9 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_2__len__(struc __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[0], 1264, 0, __PYX_ERR(0, 1264, __pyx_L1_error)); + __Pyx_TraceCall("__len__", __pyx_f[0], 1421, 0, __PYX_ERR(0, 1421, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1265 + /* "pysam/libcbcf.pyx":1422 * * def __len__(self): * return self.header.ptr.nhrec # <<<<<<<<<<<<<< @@ -19546,7 +21231,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_2__len__(struc __pyx_r = __pyx_v_self->header->ptr->nhrec; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1264 + /* "pysam/libcbcf.pyx":1421 * raise TypeError('this class cannot be instantiated from Python') * * def __len__(self): # <<<<<<<<<<<<<< @@ -19564,7 +21249,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_2__len__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":1267 +/* "pysam/libcbcf.pyx":1424 * return self.header.ptr.nhrec * * def __bool__(self): # <<<<<<<<<<<<<< @@ -19590,9 +21275,9 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_4__bool__(struct __py __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 1267, 0, __PYX_ERR(0, 1267, __pyx_L1_error)); + __Pyx_TraceCall("__bool__", __pyx_f[0], 1424, 0, __PYX_ERR(0, 1424, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1268 + /* "pysam/libcbcf.pyx":1425 * * def __bool__(self): * return self.header.ptr.nhrec != 0 # <<<<<<<<<<<<<< @@ -19602,7 +21287,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_4__bool__(struct __py __pyx_r = (__pyx_v_self->header->ptr->nhrec != 0); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1267 + /* "pysam/libcbcf.pyx":1424 * return self.header.ptr.nhrec * * def __bool__(self): # <<<<<<<<<<<<<< @@ -19620,7 +21305,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_4__bool__(struct __py return __pyx_r; } -/* "pysam/libcbcf.pyx":1270 +/* "pysam/libcbcf.pyx":1427 * return self.header.ptr.nhrec != 0 * * def __getitem__(self, index): # <<<<<<<<<<<<<< @@ -19652,19 +21337,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_6__getitem__(st PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[0], 1270, 0, __PYX_ERR(0, 1270, __pyx_L1_error)); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 1427, 0, __PYX_ERR(0, 1427, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1271 + /* "pysam/libcbcf.pyx":1428 * * def __getitem__(self, index): * cdef int32_t i = index # <<<<<<<<<<<<<< * if i < 0 or i >= self.header.ptr.nhrec: * raise IndexError('invalid header record index') */ - __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_index); if (unlikely((__pyx_t_1 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1271, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_index); if (unlikely((__pyx_t_1 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1428, __pyx_L1_error) __pyx_v_i = __pyx_t_1; - /* "pysam/libcbcf.pyx":1272 + /* "pysam/libcbcf.pyx":1429 * def __getitem__(self, index): * cdef int32_t i = index * if i < 0 or i >= self.header.ptr.nhrec: # <<<<<<<<<<<<<< @@ -19682,20 +21367,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_6__getitem__(st __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1273 + /* "pysam/libcbcf.pyx":1430 * cdef int32_t i = index * if i < 0 or i >= self.header.ptr.nhrec: * raise IndexError('invalid header record index') # <<<<<<<<<<<<<< * return makeVariantHeaderRecord(self.header, self.header.ptr.hrec[i]) * */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__67, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1273, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__67, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1430, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1273, __pyx_L1_error) + __PYX_ERR(0, 1430, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1272 + /* "pysam/libcbcf.pyx":1429 * def __getitem__(self, index): * cdef int32_t i = index * if i < 0 or i >= self.header.ptr.nhrec: # <<<<<<<<<<<<<< @@ -19704,7 +21389,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_6__getitem__(st */ } - /* "pysam/libcbcf.pyx":1274 + /* "pysam/libcbcf.pyx":1431 * if i < 0 or i >= self.header.ptr.nhrec: * raise IndexError('invalid header record index') * return makeVariantHeaderRecord(self.header, self.header.ptr.hrec[i]) # <<<<<<<<<<<<<< @@ -19714,14 +21399,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_6__getitem__(st __Pyx_XDECREF(__pyx_r); __pyx_t_4 = ((PyObject *)__pyx_v_self->header); __Pyx_INCREF(__pyx_t_4); - __pyx_t_5 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_4), (__pyx_v_self->header->ptr->hrec[__pyx_v_i]))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1274, __pyx_L1_error) + __pyx_t_5 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_4), (__pyx_v_self->header->ptr->hrec[__pyx_v_i]))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1431, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1270 + /* "pysam/libcbcf.pyx":1427 * return self.header.ptr.nhrec != 0 * * def __getitem__(self, index): # <<<<<<<<<<<<<< @@ -19743,7 +21428,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_6__getitem__(st } static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderRecords_10generator3(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1276 +/* "pysam/libcbcf.pyx":1433 * return makeVariantHeaderRecord(self.header, self.header.ptr.hrec[i]) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -19773,7 +21458,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_8__iter__(struc if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_13___iter__ *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1276, __pyx_L1_error) + __PYX_ERR(0, 1433, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -19781,7 +21466,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_8__iter__(struc __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantHeaderRecords_10generator3, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantHeaderRecords___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1276, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantHeaderRecords_10generator3, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantHeaderRecords___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1433, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -19809,7 +21494,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderRecords_10generator3(__ PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1276, 0, __PYX_ERR(0, 1276, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 1433, 0, __PYX_ERR(0, 1433, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -19819,9 +21504,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderRecords_10generator3(__ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1276, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1433, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1278 + /* "pysam/libcbcf.pyx":1435 * def __iter__(self): * cdef int32_t i * for i in range(self.header.ptr.nhrec): # <<<<<<<<<<<<<< @@ -19833,7 +21518,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderRecords_10generator3(__ for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_3; - /* "pysam/libcbcf.pyx":1279 + /* "pysam/libcbcf.pyx":1436 * cdef int32_t i * for i in range(self.header.ptr.nhrec): * yield makeVariantHeaderRecord(self.header, self.header.ptr.hrec[i]) # <<<<<<<<<<<<<< @@ -19842,7 +21527,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderRecords_10generator3(__ */ __pyx_t_4 = ((PyObject *)__pyx_cur_scope->__pyx_v_self->header); __Pyx_INCREF(__pyx_t_4); - __pyx_t_5 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_4), (__pyx_cur_scope->__pyx_v_self->header->ptr->hrec[__pyx_cur_scope->__pyx_v_i]))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1279, __pyx_L1_error) + __pyx_t_5 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_4), (__pyx_cur_scope->__pyx_v_self->header->ptr->hrec[__pyx_cur_scope->__pyx_v_i]))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_r = __pyx_t_5; @@ -19861,11 +21546,11 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderRecords_10generator3(__ __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1279, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1436, __pyx_L1_error) } CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1276 + /* "pysam/libcbcf.pyx":1433 * return makeVariantHeaderRecord(self.header, self.header.ptr.hrec[i]) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -19890,6 +21575,49 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderRecords_10generator3(__ return __pyx_r; } +/* "pysam/libcbcf.pxd":50 + * + * cdef class VariantHeaderRecords(object): + * cdef readonly VariantHeader header # <<<<<<<<<<<<<< + * + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantHeaderRecords_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantHeaderRecords_6header_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_6header___get__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 50, 0, __PYX_ERR(1, 50, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); + __pyx_r = ((PyObject *)__pyx_v_self->header); + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderRecords.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef bint use_setstate @@ -19923,7 +21651,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_11__reduce_cyth PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -19932,7 +21660,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_11__reduce_cyth * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self->header)); @@ -19947,7 +21675,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_11__reduce_cyth * if _dict is not None: * state += (_dict,) */ - __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v__dict = __pyx_t_1; __pyx_t_1 = 0; @@ -19970,12 +21698,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_11__reduce_cyth * use_setstate = True * else: */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); @@ -20031,9 +21759,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_11__reduce_cyth * return __pyx_unpickle_VariantHeaderRecords, (type(self), 0x099fb99, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderReco); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderReco); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -20044,7 +21772,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_11__reduce_cyth __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); @@ -20077,9 +21805,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_11__reduce_cyth */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderReco); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderReco); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -20090,7 +21818,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_11__reduce_cyth __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); @@ -20152,15 +21880,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_13__setstate_cy __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 14, 0, __PYX_ERR(2, 14, __pyx_L1_error)); /* "(tree fragment)":15 * return __pyx_unpickle_VariantHeaderRecords, (type(self), 0x099fb99, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_VariantHeaderRecords__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -20185,7 +21913,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderRecords_13__setstate_cy return __pyx_r; } -/* "pysam/libcbcf.pyx":1284 +/* "pysam/libcbcf.pyx":1441 * * * cdef VariantHeaderRecords makeVariantHeaderRecords(VariantHeader header): # <<<<<<<<<<<<<< @@ -20202,33 +21930,33 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_f_5pysam_7li int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("makeVariantHeaderRecords", 0); - __Pyx_TraceCall("makeVariantHeaderRecords", __pyx_f[0], 1284, 0, __PYX_ERR(0, 1284, __pyx_L1_error)); + __Pyx_TraceCall("makeVariantHeaderRecords", __pyx_f[0], 1441, 0, __PYX_ERR(0, 1441, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1285 + /* "pysam/libcbcf.pyx":1442 * * cdef VariantHeaderRecords makeVariantHeaderRecords(VariantHeader header): * if not header: # <<<<<<<<<<<<<< * raise ValueError('invalid VariantHeader') * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1285, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1442, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1286 + /* "pysam/libcbcf.pyx":1443 * cdef VariantHeaderRecords makeVariantHeaderRecords(VariantHeader header): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * cdef VariantHeaderRecords records = VariantHeaderRecords.__new__(VariantHeaderRecords) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__68, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1286, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__68, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1443, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1286, __pyx_L1_error) + __PYX_ERR(0, 1443, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1285 + /* "pysam/libcbcf.pyx":1442 * * cdef VariantHeaderRecords makeVariantHeaderRecords(VariantHeader header): * if not header: # <<<<<<<<<<<<<< @@ -20237,19 +21965,19 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_f_5pysam_7li */ } - /* "pysam/libcbcf.pyx":1288 + /* "pysam/libcbcf.pyx":1445 * raise ValueError('invalid VariantHeader') * * cdef VariantHeaderRecords records = VariantHeaderRecords.__new__(VariantHeaderRecords) # <<<<<<<<<<<<<< * records.header = header * return records */ - __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantHeaderRecords(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderRecords), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1288, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantHeaderRecords(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderRecords), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1445, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_v_records = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":1289 + /* "pysam/libcbcf.pyx":1446 * * cdef VariantHeaderRecords records = VariantHeaderRecords.__new__(VariantHeaderRecords) * records.header = header # <<<<<<<<<<<<<< @@ -20262,7 +21990,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_f_5pysam_7li __Pyx_DECREF(((PyObject *)__pyx_v_records->header)); __pyx_v_records->header = __pyx_v_header; - /* "pysam/libcbcf.pyx":1290 + /* "pysam/libcbcf.pyx":1447 * cdef VariantHeaderRecords records = VariantHeaderRecords.__new__(VariantHeaderRecords) * records.header = header * return records # <<<<<<<<<<<<<< @@ -20274,7 +22002,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_f_5pysam_7li __pyx_r = __pyx_v_records; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1284 + /* "pysam/libcbcf.pyx":1441 * * * cdef VariantHeaderRecords makeVariantHeaderRecords(VariantHeader header): # <<<<<<<<<<<<<< @@ -20295,7 +22023,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *__pyx_f_5pysam_7li return __pyx_r; } -/* "pysam/libcbcf.pyx":1295 +/* "pysam/libcbcf.pyx":1452 * cdef class VariantMetadata(object): * """filter, info or format metadata record from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -20329,22 +22057,22 @@ static int __pyx_pf_5pysam_7libcbcf_15VariantMetadata___init__(CYTHON_UNUSED str __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1295, 0, __PYX_ERR(0, 1295, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 1452, 0, __PYX_ERR(0, 1452, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1296 + /* "pysam/libcbcf.pyx":1453 * """filter, info or format metadata record from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * @property */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__69, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1296, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__69, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1453, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1296, __pyx_L1_error) + __PYX_ERR(0, 1453, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1295 + /* "pysam/libcbcf.pyx":1452 * cdef class VariantMetadata(object): * """filter, info or format metadata record from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -20362,7 +22090,7 @@ static int __pyx_pf_5pysam_7libcbcf_15VariantMetadata___init__(CYTHON_UNUSED str return __pyx_r; } -/* "pysam/libcbcf.pyx":1299 +/* "pysam/libcbcf.pyx":1456 * * @property * def name(self): # <<<<<<<<<<<<<< @@ -20391,9 +22119,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4name___get__(struct bcf_hdr_t *__pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1299, 0, __PYX_ERR(0, 1299, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1456, 0, __PYX_ERR(0, 1456, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1301 + /* "pysam/libcbcf.pyx":1458 * def name(self): * """metadata name""" * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -20403,7 +22131,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4name___get__(struct __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1302 + /* "pysam/libcbcf.pyx":1459 * """metadata name""" * cdef bcf_hdr_t *hdr = self.header.ptr * return bcf_str_cache_get_charptr(hdr.id[BCF_DT_ID][self.id].key) # <<<<<<<<<<<<<< @@ -20411,13 +22139,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4name___get__(struct * # Q: Should this be exposed? */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(((__pyx_v_hdr->id[BCF_DT_ID])[__pyx_v_self->id]).key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1302, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(((__pyx_v_hdr->id[BCF_DT_ID])[__pyx_v_self->id]).key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1459, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1299 + /* "pysam/libcbcf.pyx":1456 * * @property * def name(self): # <<<<<<<<<<<<<< @@ -20437,7 +22165,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4name___get__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1306 +/* "pysam/libcbcf.pyx":1463 * # Q: Should this be exposed? * @property * def id(self): # <<<<<<<<<<<<<< @@ -20464,9 +22192,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_2id___get__(struct _ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1306, 0, __PYX_ERR(0, 1306, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1463, 0, __PYX_ERR(0, 1463, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1308 + /* "pysam/libcbcf.pyx":1465 * def id(self): * """metadata internal header id number""" * return self.id # <<<<<<<<<<<<<< @@ -20474,13 +22202,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_2id___get__(struct _ * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1308, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1465, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1306 + /* "pysam/libcbcf.pyx":1463 * # Q: Should this be exposed? * @property * def id(self): # <<<<<<<<<<<<<< @@ -20500,7 +22228,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_2id___get__(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":1311 +/* "pysam/libcbcf.pyx":1468 * * @property * def number(self): # <<<<<<<<<<<<<< @@ -20531,9 +22259,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1311, 0, __PYX_ERR(0, 1311, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1468, 0, __PYX_ERR(0, 1468, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1313 + /* "pysam/libcbcf.pyx":1470 * def number(self): * """metadata number (i.e. cardinality)""" * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -20543,7 +22271,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1315 + /* "pysam/libcbcf.pyx":1472 * cdef bcf_hdr_t *hdr = self.header.ptr * * if not check_header_id(hdr, self.type, self.id): # <<<<<<<<<<<<<< @@ -20553,20 +22281,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru __pyx_t_2 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, __pyx_v_self->type, __pyx_v_self->id) != 0)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1316 + /* "pysam/libcbcf.pyx":1473 * * if not check_header_id(hdr, self.type, self.id): * raise ValueError('Invalid header id') # <<<<<<<<<<<<<< * * if self.type == BCF_HL_FLT: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__70, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1316, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__70, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1473, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1316, __pyx_L1_error) + __PYX_ERR(0, 1473, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1315 + /* "pysam/libcbcf.pyx":1472 * cdef bcf_hdr_t *hdr = self.header.ptr * * if not check_header_id(hdr, self.type, self.id): # <<<<<<<<<<<<<< @@ -20575,7 +22303,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru */ } - /* "pysam/libcbcf.pyx":1318 + /* "pysam/libcbcf.pyx":1475 * raise ValueError('Invalid header id') * * if self.type == BCF_HL_FLT: # <<<<<<<<<<<<<< @@ -20585,7 +22313,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru __pyx_t_2 = ((__pyx_v_self->type == BCF_HL_FLT) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1319 + /* "pysam/libcbcf.pyx":1476 * * if self.type == BCF_HL_FLT: * return None # <<<<<<<<<<<<<< @@ -20596,7 +22324,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1318 + /* "pysam/libcbcf.pyx":1475 * raise ValueError('Invalid header id') * * if self.type == BCF_HL_FLT: # <<<<<<<<<<<<<< @@ -20605,7 +22333,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru */ } - /* "pysam/libcbcf.pyx":1321 + /* "pysam/libcbcf.pyx":1478 * return None * * cdef int l = bcf_hdr_id2length(hdr, self.type, self.id) # <<<<<<<<<<<<<< @@ -20614,7 +22342,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru */ __pyx_v_l = bcf_hdr_id2length(__pyx_v_hdr, __pyx_v_self->type, __pyx_v_self->id); - /* "pysam/libcbcf.pyx":1322 + /* "pysam/libcbcf.pyx":1479 * * cdef int l = bcf_hdr_id2length(hdr, self.type, self.id) * if l == BCF_VL_FIXED: # <<<<<<<<<<<<<< @@ -20624,7 +22352,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru __pyx_t_2 = ((__pyx_v_l == BCF_VL_FIXED) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1323 + /* "pysam/libcbcf.pyx":1480 * cdef int l = bcf_hdr_id2length(hdr, self.type, self.id) * if l == BCF_VL_FIXED: * return bcf_hdr_id2number(hdr, self.type, self.id) # <<<<<<<<<<<<<< @@ -20632,13 +22360,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru * return '.' */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyInt_From_int(bcf_hdr_id2number(__pyx_v_hdr, __pyx_v_self->type, __pyx_v_self->id)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1323, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(bcf_hdr_id2number(__pyx_v_hdr, __pyx_v_self->type, __pyx_v_self->id)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1480, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1322 + /* "pysam/libcbcf.pyx":1479 * * cdef int l = bcf_hdr_id2length(hdr, self.type, self.id) * if l == BCF_VL_FIXED: # <<<<<<<<<<<<<< @@ -20647,7 +22375,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru */ } - /* "pysam/libcbcf.pyx":1324 + /* "pysam/libcbcf.pyx":1481 * if l == BCF_VL_FIXED: * return bcf_hdr_id2number(hdr, self.type, self.id) * elif l == BCF_VL_VAR: # <<<<<<<<<<<<<< @@ -20657,7 +22385,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru __pyx_t_2 = ((__pyx_v_l == BCF_VL_VAR) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1325 + /* "pysam/libcbcf.pyx":1482 * return bcf_hdr_id2number(hdr, self.type, self.id) * elif l == BCF_VL_VAR: * return '.' # <<<<<<<<<<<<<< @@ -20669,7 +22397,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru __pyx_r = __pyx_kp_s__71; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1324 + /* "pysam/libcbcf.pyx":1481 * if l == BCF_VL_FIXED: * return bcf_hdr_id2number(hdr, self.type, self.id) * elif l == BCF_VL_VAR: # <<<<<<<<<<<<<< @@ -20678,7 +22406,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru */ } - /* "pysam/libcbcf.pyx":1327 + /* "pysam/libcbcf.pyx":1484 * return '.' * else: * return METADATA_LENGTHS[l] # <<<<<<<<<<<<<< @@ -20689,16 +22417,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru __Pyx_XDECREF(__pyx_r); if (unlikely(__pyx_v_5pysam_7libcbcf_METADATA_LENGTHS == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 1327, __pyx_L1_error) + __PYX_ERR(0, 1484, __pyx_L1_error) } - __pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_5pysam_7libcbcf_METADATA_LENGTHS, __pyx_v_l, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1327, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_5pysam_7libcbcf_METADATA_LENGTHS, __pyx_v_l, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1484, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; } - /* "pysam/libcbcf.pyx":1311 + /* "pysam/libcbcf.pyx":1468 * * @property * def number(self): # <<<<<<<<<<<<<< @@ -20718,7 +22446,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6number___get__(stru return __pyx_r; } -/* "pysam/libcbcf.pyx":1330 +/* "pysam/libcbcf.pyx":1487 * * @property * def type(self): # <<<<<<<<<<<<<< @@ -20749,9 +22477,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4type___get__(struct PyObject *__pyx_t_3 = NULL; int __pyx_t_4; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1330, 0, __PYX_ERR(0, 1330, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1487, 0, __PYX_ERR(0, 1487, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1332 + /* "pysam/libcbcf.pyx":1489 * def type(self): * """metadata value type""" * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -20761,7 +22489,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4type___get__(struct __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1333 + /* "pysam/libcbcf.pyx":1490 * """metadata value type""" * cdef bcf_hdr_t *hdr = self.header.ptr * if not check_header_id(hdr, self.type, self.id): # <<<<<<<<<<<<<< @@ -20771,20 +22499,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4type___get__(struct __pyx_t_2 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, __pyx_v_self->type, __pyx_v_self->id) != 0)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1334 + /* "pysam/libcbcf.pyx":1491 * cdef bcf_hdr_t *hdr = self.header.ptr * if not check_header_id(hdr, self.type, self.id): * raise ValueError('Invalid header id') # <<<<<<<<<<<<<< * * if self.type == BCF_HL_FLT: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__72, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1334, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__72, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1491, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1334, __pyx_L1_error) + __PYX_ERR(0, 1491, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1333 + /* "pysam/libcbcf.pyx":1490 * """metadata value type""" * cdef bcf_hdr_t *hdr = self.header.ptr * if not check_header_id(hdr, self.type, self.id): # <<<<<<<<<<<<<< @@ -20793,7 +22521,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4type___get__(struct */ } - /* "pysam/libcbcf.pyx":1336 + /* "pysam/libcbcf.pyx":1493 * raise ValueError('Invalid header id') * * if self.type == BCF_HL_FLT: # <<<<<<<<<<<<<< @@ -20803,7 +22531,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4type___get__(struct __pyx_t_2 = ((__pyx_v_self->type == BCF_HL_FLT) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1337 + /* "pysam/libcbcf.pyx":1494 * * if self.type == BCF_HL_FLT: * return None # <<<<<<<<<<<<<< @@ -20814,7 +22542,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4type___get__(struct __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1336 + /* "pysam/libcbcf.pyx":1493 * raise ValueError('Invalid header id') * * if self.type == BCF_HL_FLT: # <<<<<<<<<<<<<< @@ -20823,7 +22551,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4type___get__(struct */ } - /* "pysam/libcbcf.pyx":1338 + /* "pysam/libcbcf.pyx":1495 * if self.type == BCF_HL_FLT: * return None * return VALUE_TYPES[bcf_hdr_id2type(hdr, self.type, self.id)] # <<<<<<<<<<<<<< @@ -20833,16 +22561,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4type___get__(struct __Pyx_XDECREF(__pyx_r); if (unlikely(__pyx_v_5pysam_7libcbcf_VALUE_TYPES == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 1338, __pyx_L1_error) + __PYX_ERR(0, 1495, __pyx_L1_error) } __pyx_t_4 = bcf_hdr_id2type(__pyx_v_hdr, __pyx_v_self->type, __pyx_v_self->id); - __pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_5pysam_7libcbcf_VALUE_TYPES, __pyx_t_4, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1338, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_5pysam_7libcbcf_VALUE_TYPES, __pyx_t_4, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1495, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1330 + /* "pysam/libcbcf.pyx":1487 * * @property * def type(self): # <<<<<<<<<<<<<< @@ -20862,7 +22590,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4type___get__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1341 +/* "pysam/libcbcf.pyx":1498 * * @property * def description(self): # <<<<<<<<<<<<<< @@ -20892,52 +22620,52 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_11description___get_ PyObject *__pyx_t_2 = NULL; int __pyx_t_3; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1341, 0, __PYX_ERR(0, 1341, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1498, 0, __PYX_ERR(0, 1498, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1343 + /* "pysam/libcbcf.pyx":1500 * def description(self): * """metadata description (or None if not set)""" * descr = self.record.get('Description') # <<<<<<<<<<<<<< * if descr: * descr = descr.strip('"') */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1343, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1500, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1343, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1500, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__73, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1343, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__73, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1500, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_descr = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":1344 + /* "pysam/libcbcf.pyx":1501 * """metadata description (or None if not set)""" * descr = self.record.get('Description') * if descr: # <<<<<<<<<<<<<< * descr = descr.strip('"') * return force_str(descr) */ - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_descr); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1344, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_descr); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1501, __pyx_L1_error) if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":1345 + /* "pysam/libcbcf.pyx":1502 * descr = self.record.get('Description') * if descr: * descr = descr.strip('"') # <<<<<<<<<<<<<< * return force_str(descr) * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_descr, __pyx_n_s_strip); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1345, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_descr, __pyx_n_s_strip); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1502, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1345, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1502, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_descr, __pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":1344 + /* "pysam/libcbcf.pyx":1501 * """metadata description (or None if not set)""" * descr = self.record.get('Description') * if descr: # <<<<<<<<<<<<<< @@ -20946,7 +22674,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_11description___get_ */ } - /* "pysam/libcbcf.pyx":1346 + /* "pysam/libcbcf.pyx":1503 * if descr: * descr = descr.strip('"') * return force_str(descr) # <<<<<<<<<<<<<< @@ -20954,13 +22682,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_11description___get_ * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_descr, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1346, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_descr, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1503, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1341 + /* "pysam/libcbcf.pyx":1498 * * @property * def description(self): # <<<<<<<<<<<<<< @@ -20982,7 +22710,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_11description___get_ return __pyx_r; } -/* "pysam/libcbcf.pyx":1349 +/* "pysam/libcbcf.pyx":1506 * * @property * def record(self): # <<<<<<<<<<<<<< @@ -21014,9 +22742,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6record___get__(stru PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1349, 0, __PYX_ERR(0, 1349, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1506, 0, __PYX_ERR(0, 1506, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1351 + /* "pysam/libcbcf.pyx":1508 * def record(self): * """:class:`VariantHeaderRecord` associated with this :class:`VariantMetadata` object""" * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -21026,7 +22754,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6record___get__(stru __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1352 + /* "pysam/libcbcf.pyx":1509 * """:class:`VariantHeaderRecord` associated with this :class:`VariantMetadata` object""" * cdef bcf_hdr_t *hdr = self.header.ptr * if not check_header_id(hdr, self.type, self.id): # <<<<<<<<<<<<<< @@ -21036,20 +22764,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6record___get__(stru __pyx_t_2 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, __pyx_v_self->type, __pyx_v_self->id) != 0)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1353 + /* "pysam/libcbcf.pyx":1510 * cdef bcf_hdr_t *hdr = self.header.ptr * if not check_header_id(hdr, self.type, self.id): * raise ValueError('Invalid header id') # <<<<<<<<<<<<<< * cdef bcf_hrec_t *hrec = hdr.id[BCF_DT_ID][self.id].val.hrec[self.type] * if not hrec: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__76, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1353, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__76, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1510, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1353, __pyx_L1_error) + __PYX_ERR(0, 1510, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1352 + /* "pysam/libcbcf.pyx":1509 * """:class:`VariantHeaderRecord` associated with this :class:`VariantMetadata` object""" * cdef bcf_hdr_t *hdr = self.header.ptr * if not check_header_id(hdr, self.type, self.id): # <<<<<<<<<<<<<< @@ -21058,7 +22786,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6record___get__(stru */ } - /* "pysam/libcbcf.pyx":1354 + /* "pysam/libcbcf.pyx":1511 * if not check_header_id(hdr, self.type, self.id): * raise ValueError('Invalid header id') * cdef bcf_hrec_t *hrec = hdr.id[BCF_DT_ID][self.id].val.hrec[self.type] # <<<<<<<<<<<<<< @@ -21067,7 +22795,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6record___get__(stru */ __pyx_v_hrec = (((__pyx_v_hdr->id[BCF_DT_ID])[__pyx_v_self->id]).val->hrec[__pyx_v_self->type]); - /* "pysam/libcbcf.pyx":1355 + /* "pysam/libcbcf.pyx":1512 * raise ValueError('Invalid header id') * cdef bcf_hrec_t *hrec = hdr.id[BCF_DT_ID][self.id].val.hrec[self.type] * if not hrec: # <<<<<<<<<<<<<< @@ -21077,7 +22805,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6record___get__(stru __pyx_t_2 = ((!(__pyx_v_hrec != 0)) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1356 + /* "pysam/libcbcf.pyx":1513 * cdef bcf_hrec_t *hrec = hdr.id[BCF_DT_ID][self.id].val.hrec[self.type] * if not hrec: * return None # <<<<<<<<<<<<<< @@ -21088,7 +22816,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6record___get__(stru __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1355 + /* "pysam/libcbcf.pyx":1512 * raise ValueError('Invalid header id') * cdef bcf_hrec_t *hrec = hdr.id[BCF_DT_ID][self.id].val.hrec[self.type] * if not hrec: # <<<<<<<<<<<<<< @@ -21097,7 +22825,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6record___get__(stru */ } - /* "pysam/libcbcf.pyx":1357 + /* "pysam/libcbcf.pyx":1514 * if not hrec: * return None * return makeVariantHeaderRecord(self.header, hrec) # <<<<<<<<<<<<<< @@ -21107,14 +22835,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6record___get__(stru __Pyx_XDECREF(__pyx_r); __pyx_t_3 = ((PyObject *)__pyx_v_self->header); __Pyx_INCREF(__pyx_t_3); - __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_3), __pyx_v_hrec)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1357, __pyx_L1_error) + __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_3), __pyx_v_hrec)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1514, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1349 + /* "pysam/libcbcf.pyx":1506 * * @property * def record(self): # <<<<<<<<<<<<<< @@ -21135,12 +22863,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6record___get__(stru return __pyx_r; } -/* "pysam/libcbcf.pyx":1359 +/* "pysam/libcbcf.pyx":1516 * return makeVariantHeaderRecord(self.header, hrec) * * def remove_header(self): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.header.ptr - * cdef const char *bkey = hdr.id[BCF_DT_ID][self.id].key + * cdef const char *key = hdr.id[BCF_DT_ID][self.id].key */ /* Python wrapper */ @@ -21159,50 +22887,50 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_15VariantMetadata_3remove_header(PyObj static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_2remove_header(struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_v_self) { bcf_hdr_t *__pyx_v_hdr; - char const *__pyx_v_bkey; + char const *__pyx_v_key; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; char const *__pyx_t_2; __Pyx_RefNannySetupContext("remove_header", 0); - __Pyx_TraceCall("remove_header", __pyx_f[0], 1359, 0, __PYX_ERR(0, 1359, __pyx_L1_error)); + __Pyx_TraceCall("remove_header", __pyx_f[0], 1516, 0, __PYX_ERR(0, 1516, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1360 + /* "pysam/libcbcf.pyx":1517 * * def remove_header(self): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< - * cdef const char *bkey = hdr.id[BCF_DT_ID][self.id].key - * bcf_hdr_remove(hdr, self.type, bkey) + * cdef const char *key = hdr.id[BCF_DT_ID][self.id].key + * bcf_hdr_remove(hdr, self.type, key) */ __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1361 + /* "pysam/libcbcf.pyx":1518 * def remove_header(self): * cdef bcf_hdr_t *hdr = self.header.ptr - * cdef const char *bkey = hdr.id[BCF_DT_ID][self.id].key # <<<<<<<<<<<<<< - * bcf_hdr_remove(hdr, self.type, bkey) + * cdef const char *key = hdr.id[BCF_DT_ID][self.id].key # <<<<<<<<<<<<<< + * bcf_hdr_remove(hdr, self.type, key) * */ __pyx_t_2 = ((__pyx_v_hdr->id[BCF_DT_ID])[__pyx_v_self->id]).key; - __pyx_v_bkey = __pyx_t_2; + __pyx_v_key = __pyx_t_2; - /* "pysam/libcbcf.pyx":1362 + /* "pysam/libcbcf.pyx":1519 * cdef bcf_hdr_t *hdr = self.header.ptr - * cdef const char *bkey = hdr.id[BCF_DT_ID][self.id].key - * bcf_hdr_remove(hdr, self.type, bkey) # <<<<<<<<<<<<<< + * cdef const char *key = hdr.id[BCF_DT_ID][self.id].key + * bcf_hdr_remove(hdr, self.type, key) # <<<<<<<<<<<<<< * * */ - bcf_hdr_remove(__pyx_v_hdr, __pyx_v_self->type, __pyx_v_bkey); + bcf_hdr_remove(__pyx_v_hdr, __pyx_v_self->type, __pyx_v_key); - /* "pysam/libcbcf.pyx":1359 + /* "pysam/libcbcf.pyx":1516 * return makeVariantHeaderRecord(self.header, hrec) * * def remove_header(self): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.header.ptr - * cdef const char *bkey = hdr.id[BCF_DT_ID][self.id].key + * cdef const char *key = hdr.id[BCF_DT_ID][self.id].key */ /* function exit code */ @@ -21218,6 +22946,49 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_2remove_header(struc return __pyx_r; } +/* "pysam/libcbcf.pxd":67 + * + * cdef class VariantMetadata(object): + * cdef readonly VariantHeader header # <<<<<<<<<<<<<< + * cdef int type + * cdef int id + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_15VariantMetadata_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_15VariantMetadata_6header_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_15VariantMetadata_6header___get__(((struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 67, 0, __PYX_ERR(1, 67, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); + __pyx_r = ((PyObject *)__pyx_v_self->header); + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantMetadata.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef bint use_setstate @@ -21251,7 +23022,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4__reduce_cython__(s int __pyx_t_4; int __pyx_t_5; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -21260,11 +23031,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4__reduce_cython__(s * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->id); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->id); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->type); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->type); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self->header)); @@ -21285,7 +23056,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4__reduce_cython__(s * if _dict is not None: * state += (_dict,) */ - __pyx_t_3 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v__dict = __pyx_t_3; __pyx_t_3 = 0; @@ -21308,12 +23079,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4__reduce_cython__(s * use_setstate = True * else: */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v__dict); - __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_2)); @@ -21369,9 +23140,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4__reduce_cython__(s * return __pyx_unpickle_VariantMetadata, (type(self), 0x9d0a56c, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantMetadata); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantMetadata); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -21382,7 +23153,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4__reduce_cython__(s __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_3, 2, Py_None); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); @@ -21415,9 +23186,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4__reduce_cython__(s */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantMetadata); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantMetadata); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -21428,7 +23199,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_4__reduce_cython__(s __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_state); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); @@ -21490,15 +23261,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6__setstate_cython__ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 14, 0, __PYX_ERR(2, 14, __pyx_L1_error)); /* "(tree fragment)":15 * return __pyx_unpickle_VariantMetadata, (type(self), 0x9d0a56c, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_VariantMetadata__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantMetadata__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantMetadata__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -21523,7 +23294,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_15VariantMetadata_6__setstate_cython__ return __pyx_r; } -/* "pysam/libcbcf.pyx":1365 +/* "pysam/libcbcf.pyx":1522 * * * cdef VariantMetadata makeVariantMetadata(VariantHeader header, int type, int id): # <<<<<<<<<<<<<< @@ -21540,33 +23311,33 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_f_5pysam_7libcbcf int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("makeVariantMetadata", 0); - __Pyx_TraceCall("makeVariantMetadata", __pyx_f[0], 1365, 0, __PYX_ERR(0, 1365, __pyx_L1_error)); + __Pyx_TraceCall("makeVariantMetadata", __pyx_f[0], 1522, 0, __PYX_ERR(0, 1522, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1366 + /* "pysam/libcbcf.pyx":1523 * * cdef VariantMetadata makeVariantMetadata(VariantHeader header, int type, int id): * if not header: # <<<<<<<<<<<<<< * raise ValueError('invalid VariantHeader') * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1366, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1523, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1367 + /* "pysam/libcbcf.pyx":1524 * cdef VariantMetadata makeVariantMetadata(VariantHeader header, int type, int id): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * if type != BCF_HL_FLT and type != BCF_HL_INFO and type != BCF_HL_FMT: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__77, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1367, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__77, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1524, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1367, __pyx_L1_error) + __PYX_ERR(0, 1524, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1366 + /* "pysam/libcbcf.pyx":1523 * * cdef VariantMetadata makeVariantMetadata(VariantHeader header, int type, int id): * if not header: # <<<<<<<<<<<<<< @@ -21575,7 +23346,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_f_5pysam_7libcbcf */ } - /* "pysam/libcbcf.pyx":1369 + /* "pysam/libcbcf.pyx":1526 * raise ValueError('invalid VariantHeader') * * if type != BCF_HL_FLT and type != BCF_HL_INFO and type != BCF_HL_FMT: # <<<<<<<<<<<<<< @@ -21599,20 +23370,20 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_f_5pysam_7libcbcf __pyx_L5_bool_binop_done:; if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1370 + /* "pysam/libcbcf.pyx":1527 * * if type != BCF_HL_FLT and type != BCF_HL_INFO and type != BCF_HL_FMT: * raise ValueError('invalid metadata type') # <<<<<<<<<<<<<< * * if id < 0 or id >= header.ptr.n[BCF_DT_ID]: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__78, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1370, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__78, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1527, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1370, __pyx_L1_error) + __PYX_ERR(0, 1527, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1369 + /* "pysam/libcbcf.pyx":1526 * raise ValueError('invalid VariantHeader') * * if type != BCF_HL_FLT and type != BCF_HL_INFO and type != BCF_HL_FMT: # <<<<<<<<<<<<<< @@ -21621,7 +23392,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_f_5pysam_7libcbcf */ } - /* "pysam/libcbcf.pyx":1372 + /* "pysam/libcbcf.pyx":1529 * raise ValueError('invalid metadata type') * * if id < 0 or id >= header.ptr.n[BCF_DT_ID]: # <<<<<<<<<<<<<< @@ -21639,20 +23410,20 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_f_5pysam_7libcbcf __pyx_L9_bool_binop_done:; if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1373 + /* "pysam/libcbcf.pyx":1530 * * if id < 0 or id >= header.ptr.n[BCF_DT_ID]: * raise ValueError('invalid metadata id') # <<<<<<<<<<<<<< * * cdef VariantMetadata meta = VariantMetadata.__new__(VariantMetadata) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__79, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1373, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__79, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1530, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1373, __pyx_L1_error) + __PYX_ERR(0, 1530, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1372 + /* "pysam/libcbcf.pyx":1529 * raise ValueError('invalid metadata type') * * if id < 0 or id >= header.ptr.n[BCF_DT_ID]: # <<<<<<<<<<<<<< @@ -21661,19 +23432,19 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_f_5pysam_7libcbcf */ } - /* "pysam/libcbcf.pyx":1375 + /* "pysam/libcbcf.pyx":1532 * raise ValueError('invalid metadata id') * * cdef VariantMetadata meta = VariantMetadata.__new__(VariantMetadata) # <<<<<<<<<<<<<< * meta.header = header * meta.type = type */ - __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantMetadata(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantMetadata), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1375, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantMetadata(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantMetadata), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1532, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_v_meta = ((struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":1376 + /* "pysam/libcbcf.pyx":1533 * * cdef VariantMetadata meta = VariantMetadata.__new__(VariantMetadata) * meta.header = header # <<<<<<<<<<<<<< @@ -21686,7 +23457,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_f_5pysam_7libcbcf __Pyx_DECREF(((PyObject *)__pyx_v_meta->header)); __pyx_v_meta->header = __pyx_v_header; - /* "pysam/libcbcf.pyx":1377 + /* "pysam/libcbcf.pyx":1534 * cdef VariantMetadata meta = VariantMetadata.__new__(VariantMetadata) * meta.header = header * meta.type = type # <<<<<<<<<<<<<< @@ -21695,7 +23466,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_f_5pysam_7libcbcf */ __pyx_v_meta->type = __pyx_v_type; - /* "pysam/libcbcf.pyx":1378 + /* "pysam/libcbcf.pyx":1535 * meta.header = header * meta.type = type * meta.id = id # <<<<<<<<<<<<<< @@ -21704,7 +23475,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_f_5pysam_7libcbcf */ __pyx_v_meta->id = __pyx_v_id; - /* "pysam/libcbcf.pyx":1380 + /* "pysam/libcbcf.pyx":1537 * meta.id = id * * return meta # <<<<<<<<<<<<<< @@ -21716,7 +23487,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_f_5pysam_7libcbcf __pyx_r = __pyx_v_meta; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1365 + /* "pysam/libcbcf.pyx":1522 * * * cdef VariantMetadata makeVariantMetadata(VariantHeader header, int type, int id): # <<<<<<<<<<<<<< @@ -21737,7 +23508,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *__pyx_f_5pysam_7libcbcf return __pyx_r; } -/* "pysam/libcbcf.pyx":1385 +/* "pysam/libcbcf.pyx":1542 * cdef class VariantHeaderMetadata(object): * """mapping from filter, info or format name to :class:`VariantMetadata` object""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -21771,22 +23542,22 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata___init__(CYTHON_UNUS __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1385, 0, __PYX_ERR(0, 1385, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 1542, 0, __PYX_ERR(0, 1542, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1386 + /* "pysam/libcbcf.pyx":1543 * """mapping from filter, info or format name to :class:`VariantMetadata` object""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def add(self, id, number, type, description, **kwargs): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__80, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1386, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__80, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1543, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1386, __pyx_L1_error) + __PYX_ERR(0, 1543, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1385 + /* "pysam/libcbcf.pyx":1542 * cdef class VariantHeaderMetadata(object): * """mapping from filter, info or format name to :class:`VariantMetadata` object""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -21804,7 +23575,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata___init__(CYTHON_UNUS return __pyx_r; } -/* "pysam/libcbcf.pyx":1388 +/* "pysam/libcbcf.pyx":1545 * raise TypeError('this class cannot be instantiated from Python') * * def add(self, id, number, type, description, **kwargs): # <<<<<<<<<<<<<< @@ -21853,23 +23624,23 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_21VariantHeaderMetadata_3add(PyObject case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_number)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("add", 1, 4, 4, 1); __PYX_ERR(0, 1388, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("add", 1, 4, 4, 1); __PYX_ERR(0, 1545, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_type)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("add", 1, 4, 4, 2); __PYX_ERR(0, 1388, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("add", 1, 4, 4, 2); __PYX_ERR(0, 1545, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_description)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("add", 1, 4, 4, 3); __PYX_ERR(0, 1388, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("add", 1, 4, 4, 3); __PYX_ERR(0, 1545, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "add") < 0)) __PYX_ERR(0, 1388, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "add") < 0)) __PYX_ERR(0, 1545, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { goto __pyx_L5_argtuple_error; @@ -21886,7 +23657,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_21VariantHeaderMetadata_3add(PyObject } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("add", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1388, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("add", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1545, __pyx_L3_error) __pyx_L3_error:; __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderMetadata.add", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -21914,28 +23685,28 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("add", 0); - __Pyx_TraceCall("add", __pyx_f[0], 1388, 0, __PYX_ERR(0, 1388, __pyx_L1_error)); + __Pyx_TraceCall("add", __pyx_f[0], 1545, 0, __PYX_ERR(0, 1545, __pyx_L1_error)); __Pyx_INCREF(__pyx_v_number); - /* "pysam/libcbcf.pyx":1390 + /* "pysam/libcbcf.pyx":1547 * def add(self, id, number, type, description, **kwargs): * """Add a new filter, info or format record""" * if id in self: # <<<<<<<<<<<<<< * raise ValueError('Header already exists for id={}'.format(id)) * */ - __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_id, ((PyObject *)__pyx_v_self), Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1390, __pyx_L1_error) + __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_id, ((PyObject *)__pyx_v_self), Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1547, __pyx_L1_error) __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1391 + /* "pysam/libcbcf.pyx":1548 * """Add a new filter, info or format record""" * if id in self: * raise ValueError('Header already exists for id={}'.format(id)) # <<<<<<<<<<<<<< * * if self.type == BCF_HL_FLT: */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Header_already_exists_for_id, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1391, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Header_already_exists_for_id, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1548, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { @@ -21948,13 +23719,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1391, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1548, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_id}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1391, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1548, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -21962,32 +23733,32 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_id}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1391, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1548, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1391, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1548, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_INCREF(__pyx_v_id); __Pyx_GIVEREF(__pyx_v_id); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_id); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1391, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1548, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1391, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1548, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1391, __pyx_L1_error) + __PYX_ERR(0, 1548, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1390 + /* "pysam/libcbcf.pyx":1547 * def add(self, id, number, type, description, **kwargs): * """Add a new filter, info or format record""" * if id in self: # <<<<<<<<<<<<<< @@ -21996,7 +23767,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ */ } - /* "pysam/libcbcf.pyx":1393 + /* "pysam/libcbcf.pyx":1550 * raise ValueError('Header already exists for id={}'.format(id)) * * if self.type == BCF_HL_FLT: # <<<<<<<<<<<<<< @@ -22006,7 +23777,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ __pyx_t_2 = ((__pyx_v_self->type == BCF_HL_FLT) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1394 + /* "pysam/libcbcf.pyx":1551 * * if self.type == BCF_HL_FLT: * if number is not None: # <<<<<<<<<<<<<< @@ -22017,20 +23788,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ __pyx_t_1 = (__pyx_t_2 != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":1395 + /* "pysam/libcbcf.pyx":1552 * if self.type == BCF_HL_FLT: * if number is not None: * raise ValueError('Number must be None when adding a filter') # <<<<<<<<<<<<<< * if type is not None: * raise ValueError('Type must be None when adding a filter') */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__81, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1395, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__81, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1552, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1395, __pyx_L1_error) + __PYX_ERR(0, 1552, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1394 + /* "pysam/libcbcf.pyx":1551 * * if self.type == BCF_HL_FLT: * if number is not None: # <<<<<<<<<<<<<< @@ -22039,7 +23810,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ */ } - /* "pysam/libcbcf.pyx":1396 + /* "pysam/libcbcf.pyx":1553 * if number is not None: * raise ValueError('Number must be None when adding a filter') * if type is not None: # <<<<<<<<<<<<<< @@ -22050,20 +23821,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1397 + /* "pysam/libcbcf.pyx":1554 * raise ValueError('Number must be None when adding a filter') * if type is not None: * raise ValueError('Type must be None when adding a filter') # <<<<<<<<<<<<<< * * items = [('ID', id), ('Description', description)] */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__82, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1397, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__82, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1554, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1397, __pyx_L1_error) + __PYX_ERR(0, 1554, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1396 + /* "pysam/libcbcf.pyx":1553 * if number is not None: * raise ValueError('Number must be None when adding a filter') * if type is not None: # <<<<<<<<<<<<<< @@ -22072,14 +23843,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ */ } - /* "pysam/libcbcf.pyx":1399 + /* "pysam/libcbcf.pyx":1556 * raise ValueError('Type must be None when adding a filter') * * items = [('ID', id), ('Description', description)] # <<<<<<<<<<<<<< * else: * if type not in VALUE_TYPES: */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1399, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1556, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_n_s_ID); __Pyx_GIVEREF(__pyx_n_s_ID); @@ -22087,7 +23858,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ __Pyx_INCREF(__pyx_v_id); __Pyx_GIVEREF(__pyx_v_id); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_id); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1399, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1556, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_n_s_Description); __Pyx_GIVEREF(__pyx_n_s_Description); @@ -22095,7 +23866,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ __Pyx_INCREF(__pyx_v_description); __Pyx_GIVEREF(__pyx_v_description); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_description); - __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1399, __pyx_L1_error) + __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1556, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_4); PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); @@ -22106,7 +23877,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ __pyx_v_items = __pyx_t_6; __pyx_t_6 = 0; - /* "pysam/libcbcf.pyx":1393 + /* "pysam/libcbcf.pyx":1550 * raise ValueError('Header already exists for id={}'.format(id)) * * if self.type == BCF_HL_FLT: # <<<<<<<<<<<<<< @@ -22116,7 +23887,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ goto __pyx_L4; } - /* "pysam/libcbcf.pyx":1401 + /* "pysam/libcbcf.pyx":1558 * items = [('ID', id), ('Description', description)] * else: * if type not in VALUE_TYPES: # <<<<<<<<<<<<<< @@ -22124,18 +23895,18 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ * if number is None: */ /*else*/ { - __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_type, __pyx_v_5pysam_7libcbcf_VALUE_TYPES, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1401, __pyx_L1_error) + __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_type, __pyx_v_5pysam_7libcbcf_VALUE_TYPES, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1558, __pyx_L1_error) __pyx_t_1 = (__pyx_t_2 != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":1402 + /* "pysam/libcbcf.pyx":1559 * else: * if type not in VALUE_TYPES: * raise ValueError('unknown type specified: {}'.format(type)) # <<<<<<<<<<<<<< * if number is None: * number = '.' */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unknown_type_specified, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1402, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unknown_type_specified, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1559, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { @@ -22148,13 +23919,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ } } if (!__pyx_t_4) { - __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_type); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1402, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_type); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1559, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_type}; - __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1402, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1559, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_6); } else @@ -22162,32 +23933,32 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_type}; - __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1402, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1559, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_6); } else #endif { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1402, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1559, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_INCREF(__pyx_v_type); __Pyx_GIVEREF(__pyx_v_type); PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_type); - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1402, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1559, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1402, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1559, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1402, __pyx_L1_error) + __PYX_ERR(0, 1559, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1401 + /* "pysam/libcbcf.pyx":1558 * items = [('ID', id), ('Description', description)] * else: * if type not in VALUE_TYPES: # <<<<<<<<<<<<<< @@ -22196,7 +23967,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ */ } - /* "pysam/libcbcf.pyx":1403 + /* "pysam/libcbcf.pyx":1560 * if type not in VALUE_TYPES: * raise ValueError('unknown type specified: {}'.format(type)) * if number is None: # <<<<<<<<<<<<<< @@ -22207,7 +23978,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1404 + /* "pysam/libcbcf.pyx":1561 * raise ValueError('unknown type specified: {}'.format(type)) * if number is None: * number = '.' # <<<<<<<<<<<<<< @@ -22217,7 +23988,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ __Pyx_INCREF(__pyx_kp_s__71); __Pyx_DECREF_SET(__pyx_v_number, __pyx_kp_s__71); - /* "pysam/libcbcf.pyx":1403 + /* "pysam/libcbcf.pyx":1560 * if type not in VALUE_TYPES: * raise ValueError('unknown type specified: {}'.format(type)) * if number is None: # <<<<<<<<<<<<<< @@ -22226,14 +23997,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ */ } - /* "pysam/libcbcf.pyx":1406 + /* "pysam/libcbcf.pyx":1563 * number = '.' * * items = [('ID', id), # <<<<<<<<<<<<<< * ('Number', number), * ('Type', type), */ - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1406, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1563, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_n_s_ID); __Pyx_GIVEREF(__pyx_n_s_ID); @@ -22242,14 +24013,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ __Pyx_GIVEREF(__pyx_v_id); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_id); - /* "pysam/libcbcf.pyx":1407 + /* "pysam/libcbcf.pyx":1564 * * items = [('ID', id), * ('Number', number), # <<<<<<<<<<<<<< * ('Type', type), * ('Description', description)] */ - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1407, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1564, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_INCREF(__pyx_n_s_Number); __Pyx_GIVEREF(__pyx_n_s_Number); @@ -22258,14 +24029,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ __Pyx_GIVEREF(__pyx_v_number); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_number); - /* "pysam/libcbcf.pyx":1408 + /* "pysam/libcbcf.pyx":1565 * items = [('ID', id), * ('Number', number), * ('Type', type), # <<<<<<<<<<<<<< * ('Description', description)] * */ - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1408, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1565, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_n_s_Type); __Pyx_GIVEREF(__pyx_n_s_Type); @@ -22274,14 +24045,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ __Pyx_GIVEREF(__pyx_v_type); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_type); - /* "pysam/libcbcf.pyx":1409 + /* "pysam/libcbcf.pyx":1566 * ('Number', number), * ('Type', type), * ('Description', description)] # <<<<<<<<<<<<<< * * items += kwargs.items() */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1409, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1566, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_n_s_Description); __Pyx_GIVEREF(__pyx_n_s_Description); @@ -22290,14 +24061,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ __Pyx_GIVEREF(__pyx_v_description); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_description); - /* "pysam/libcbcf.pyx":1406 + /* "pysam/libcbcf.pyx":1563 * number = '.' * * items = [('ID', id), # <<<<<<<<<<<<<< * ('Number', number), * ('Type', type), */ - __pyx_t_7 = PyList_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1406, __pyx_L1_error) + __pyx_t_7 = PyList_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1563, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_3); PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); @@ -22316,52 +24087,52 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ } __pyx_L4:; - /* "pysam/libcbcf.pyx":1411 + /* "pysam/libcbcf.pyx":1568 * ('Description', description)] * * items += kwargs.items() # <<<<<<<<<<<<<< * self.header.add_meta(METADATA_TYPES[self.type], items=items) * */ - __pyx_t_7 = __Pyx_PyDict_Items(__pyx_v_kwargs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1411, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyDict_Items(__pyx_v_kwargs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1568, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_items, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1411, __pyx_L1_error) + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_items, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1568, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF_SET(__pyx_v_items, __pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1412 + /* "pysam/libcbcf.pyx":1569 * * items += kwargs.items() * self.header.add_meta(METADATA_TYPES[self.type], items=items) # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_add_meta); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1412, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_add_meta); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1569, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (unlikely(__pyx_v_5pysam_7libcbcf_METADATA_TYPES == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 1412, __pyx_L1_error) + __PYX_ERR(0, 1569, __pyx_L1_error) } - __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v_5pysam_7libcbcf_METADATA_TYPES, __pyx_v_self->type, int32_t, 1, __Pyx_PyInt_From_int32_t, 0, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1412, __pyx_L1_error) + __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v_5pysam_7libcbcf_METADATA_TYPES, __pyx_v_self->type, int32_t, 1, __Pyx_PyInt_From_int32_t, 0, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1569, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1412, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1569, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1412, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1569, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_items, __pyx_v_items) < 0) __PYX_ERR(0, 1412, __pyx_L1_error) - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1412, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_items, __pyx_v_items) < 0) __PYX_ERR(0, 1569, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1569, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libcbcf.pyx":1388 + /* "pysam/libcbcf.pyx":1545 * raise TypeError('this class cannot be instantiated from Python') * * def add(self, id, number, type, description, **kwargs): # <<<<<<<<<<<<<< @@ -22389,7 +24160,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_2add(struct __ return __pyx_r; } -/* "pysam/libcbcf.pyx":1414 +/* "pysam/libcbcf.pyx":1571 * self.header.add_meta(METADATA_TYPES[self.type], items=items) * * def __len__(self): # <<<<<<<<<<<<<< @@ -22425,9 +24196,9 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_4__len__(stru int __pyx_t_5; int __pyx_t_6; __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[0], 1414, 0, __PYX_ERR(0, 1414, __pyx_L1_error)); + __Pyx_TraceCall("__len__", __pyx_f[0], 1571, 0, __PYX_ERR(0, 1571, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1415 + /* "pysam/libcbcf.pyx":1572 * * def __len__(self): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -22437,7 +24208,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_4__len__(stru __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1417 + /* "pysam/libcbcf.pyx":1574 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef bcf_idpair_t *idpair * cdef int32_t i, n = 0 # <<<<<<<<<<<<<< @@ -22446,7 +24217,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_4__len__(stru */ __pyx_v_n = 0; - /* "pysam/libcbcf.pyx":1419 + /* "pysam/libcbcf.pyx":1576 * cdef int32_t i, n = 0 * * for i in range(hdr.n[BCF_DT_ID]): # <<<<<<<<<<<<<< @@ -22458,7 +24229,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_4__len__(stru for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; - /* "pysam/libcbcf.pyx":1420 + /* "pysam/libcbcf.pyx":1577 * * for i in range(hdr.n[BCF_DT_ID]): * idpair = hdr.id[BCF_DT_ID] + i # <<<<<<<<<<<<<< @@ -22467,7 +24238,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_4__len__(stru */ __pyx_v_idpair = ((__pyx_v_hdr->id[BCF_DT_ID]) + __pyx_v_i); - /* "pysam/libcbcf.pyx":1421 + /* "pysam/libcbcf.pyx":1578 * for i in range(hdr.n[BCF_DT_ID]): * idpair = hdr.id[BCF_DT_ID] + i * if idpair.key and idpair.val and idpair.val.info[self.type] & 0xF != 0xF: # <<<<<<<<<<<<<< @@ -22491,7 +24262,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_4__len__(stru __pyx_L6_bool_binop_done:; if (__pyx_t_5) { - /* "pysam/libcbcf.pyx":1422 + /* "pysam/libcbcf.pyx":1579 * idpair = hdr.id[BCF_DT_ID] + i * if idpair.key and idpair.val and idpair.val.info[self.type] & 0xF != 0xF: * n += 1 # <<<<<<<<<<<<<< @@ -22500,7 +24271,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_4__len__(stru */ __pyx_v_n = (__pyx_v_n + 1); - /* "pysam/libcbcf.pyx":1421 + /* "pysam/libcbcf.pyx":1578 * for i in range(hdr.n[BCF_DT_ID]): * idpair = hdr.id[BCF_DT_ID] + i * if idpair.key and idpair.val and idpair.val.info[self.type] & 0xF != 0xF: # <<<<<<<<<<<<<< @@ -22510,7 +24281,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_4__len__(stru } } - /* "pysam/libcbcf.pyx":1423 + /* "pysam/libcbcf.pyx":1580 * if idpair.key and idpair.val and idpair.val.info[self.type] & 0xF != 0xF: * n += 1 * return n # <<<<<<<<<<<<<< @@ -22520,7 +24291,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_4__len__(stru __pyx_r = __pyx_v_n; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1414 + /* "pysam/libcbcf.pyx":1571 * self.header.add_meta(METADATA_TYPES[self.type], items=items) * * def __len__(self): # <<<<<<<<<<<<<< @@ -22538,7 +24309,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_4__len__(stru return __pyx_r; } -/* "pysam/libcbcf.pyx":1425 +/* "pysam/libcbcf.pyx":1582 * return n * * def __bool__(self): # <<<<<<<<<<<<<< @@ -22573,9 +24344,9 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_6__bool__(struct __p int __pyx_t_5; int __pyx_t_6; __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 1425, 0, __PYX_ERR(0, 1425, __pyx_L1_error)); + __Pyx_TraceCall("__bool__", __pyx_f[0], 1582, 0, __PYX_ERR(0, 1582, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1426 + /* "pysam/libcbcf.pyx":1583 * * def __bool__(self): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -22585,7 +24356,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_6__bool__(struct __p __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1430 + /* "pysam/libcbcf.pyx":1587 * cdef int32_t i * * for i in range(hdr.n[BCF_DT_ID]): # <<<<<<<<<<<<<< @@ -22597,7 +24368,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_6__bool__(struct __p for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_v_i = __pyx_t_4; - /* "pysam/libcbcf.pyx":1431 + /* "pysam/libcbcf.pyx":1588 * * for i in range(hdr.n[BCF_DT_ID]): * idpair = hdr.id[BCF_DT_ID] + i # <<<<<<<<<<<<<< @@ -22606,7 +24377,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_6__bool__(struct __p */ __pyx_v_idpair = ((__pyx_v_hdr->id[BCF_DT_ID]) + __pyx_v_i); - /* "pysam/libcbcf.pyx":1432 + /* "pysam/libcbcf.pyx":1589 * for i in range(hdr.n[BCF_DT_ID]): * idpair = hdr.id[BCF_DT_ID] + i * if idpair.key and idpair.val and idpair.val.info[self.type] & 0xF != 0xF: # <<<<<<<<<<<<<< @@ -22630,7 +24401,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_6__bool__(struct __p __pyx_L6_bool_binop_done:; if (__pyx_t_5) { - /* "pysam/libcbcf.pyx":1433 + /* "pysam/libcbcf.pyx":1590 * idpair = hdr.id[BCF_DT_ID] + i * if idpair.key and idpair.val and idpair.val.info[self.type] & 0xF != 0xF: * return True # <<<<<<<<<<<<<< @@ -22640,7 +24411,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_6__bool__(struct __p __pyx_r = 1; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1432 + /* "pysam/libcbcf.pyx":1589 * for i in range(hdr.n[BCF_DT_ID]): * idpair = hdr.id[BCF_DT_ID] + i * if idpair.key and idpair.val and idpair.val.info[self.type] & 0xF != 0xF: # <<<<<<<<<<<<<< @@ -22650,7 +24421,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_6__bool__(struct __p } } - /* "pysam/libcbcf.pyx":1434 + /* "pysam/libcbcf.pyx":1591 * if idpair.key and idpair.val and idpair.val.info[self.type] & 0xF != 0xF: * return True * return False # <<<<<<<<<<<<<< @@ -22660,7 +24431,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_6__bool__(struct __p __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1425 + /* "pysam/libcbcf.pyx":1582 * return n * * def __bool__(self): # <<<<<<<<<<<<<< @@ -22678,7 +24449,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_6__bool__(struct __p return __pyx_r; } -/* "pysam/libcbcf.pyx":1436 +/* "pysam/libcbcf.pyx":1593 * return False * * def __getitem__(self, key): # <<<<<<<<<<<<<< @@ -22702,7 +24473,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_21VariantHeaderMetadata_9__getitem__(P static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_8__getitem__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_v_self, PyObject *__pyx_v_key) { bcf_hdr_t *__pyx_v_hdr; vdict_t *__pyx_v_d; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; khiter_t __pyx_v_k; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations @@ -22713,10 +24484,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_8__getitem__(s int __pyx_t_4; int __pyx_t_5; PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[0], 1436, 0, __PYX_ERR(0, 1436, __pyx_L1_error)); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 1593, 0, __PYX_ERR(0, 1593, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1437 + /* "pysam/libcbcf.pyx":1594 * * def __getitem__(self, key): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -22726,46 +24499,46 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_8__getitem__(s __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1438 + /* "pysam/libcbcf.pyx":1595 * def __getitem__(self, key): * cdef bcf_hdr_t *hdr = self.header.ptr * cdef vdict_t *d = hdr.dict[BCF_DT_ID] # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ __pyx_v_d = ((vdict_t *)(__pyx_v_hdr->dict[BCF_DT_ID])); - /* "pysam/libcbcf.pyx":1440 + /* "pysam/libcbcf.pyx":1597 * cdef vdict_t *d = hdr.dict[BCF_DT_ID] * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * cdef khiter_t k = kh_get_vdict(d, bkey) * */ - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1440, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1597, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_bkey = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":1441 + /* "pysam/libcbcf.pyx":1598 * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef khiter_t k = kh_get_vdict(d, bkey) # <<<<<<<<<<<<<< * * if k == kh_end(d) or kh_val_vdict(d, k).info[self.type] & 0xF == 0xF: */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 1441, __pyx_L1_error) + __PYX_ERR(0, 1598, __pyx_L1_error) } - __pyx_t_3 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 1441, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 1598, __pyx_L1_error) __pyx_v_k = kh_get_vdict(__pyx_v_d, __pyx_t_3); - /* "pysam/libcbcf.pyx":1443 + /* "pysam/libcbcf.pyx":1600 * cdef khiter_t k = kh_get_vdict(d, bkey) * * if k == kh_end(d) or kh_val_vdict(d, k).info[self.type] & 0xF == 0xF: # <<<<<<<<<<<<<< - * raise KeyError('invalid key') + * raise KeyError('invalid key: {}'.format(key)) * */ __pyx_t_5 = ((__pyx_v_k == kh_end(__pyx_v_d)) != 0); @@ -22779,46 +24552,92 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_8__getitem__(s __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_4)) { - /* "pysam/libcbcf.pyx":1444 + /* "pysam/libcbcf.pyx":1601 * * if k == kh_end(d) or kh_val_vdict(d, k).info[self.type] & 0xF == 0xF: - * raise KeyError('invalid key') # <<<<<<<<<<<<<< + * raise KeyError('invalid key: {}'.format(key)) # <<<<<<<<<<<<<< * * return makeVariantMetadata(self.header, self.type, kh_val_vdict(d, k).id) */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__83, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1444, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_key, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1601, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + if (!__pyx_t_7) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1601, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_key}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1601, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_key}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1601, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1601, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_key); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1601, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1601, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 1444, __pyx_L1_error) + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 1601, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1443 + /* "pysam/libcbcf.pyx":1600 * cdef khiter_t k = kh_get_vdict(d, bkey) * * if k == kh_end(d) or kh_val_vdict(d, k).info[self.type] & 0xF == 0xF: # <<<<<<<<<<<<<< - * raise KeyError('invalid key') + * raise KeyError('invalid key: {}'.format(key)) * */ } - /* "pysam/libcbcf.pyx":1446 - * raise KeyError('invalid key') + /* "pysam/libcbcf.pyx":1603 + * raise KeyError('invalid key: {}'.format(key)) * * return makeVariantMetadata(self.header, self.type, kh_val_vdict(d, k).id) # <<<<<<<<<<<<<< * * def remove_header(self, key): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_v_self->header); - __Pyx_INCREF(__pyx_t_2); - __pyx_t_6 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantMetadata(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_2), __pyx_v_self->type, kh_val(__pyx_v_d, __pyx_v_k).id)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1446, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_6; - __pyx_t_6 = 0; + __pyx_t_6 = ((PyObject *)__pyx_v_self->header); + __Pyx_INCREF(__pyx_t_6); + __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantMetadata(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_6), __pyx_v_self->type, kh_val(__pyx_v_d, __pyx_v_k).id)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1603, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1436 + /* "pysam/libcbcf.pyx":1593 * return False * * def __getitem__(self, key): # <<<<<<<<<<<<<< @@ -22830,6 +24649,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_8__getitem__(s __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderMetadata.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -22840,7 +24661,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_8__getitem__(s return __pyx_r; } -/* "pysam/libcbcf.pyx":1448 +/* "pysam/libcbcf.pyx":1605 * return makeVariantMetadata(self.header, self.type, kh_val_vdict(d, k).id) * * def remove_header(self, key): # <<<<<<<<<<<<<< @@ -22865,7 +24686,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_21VariantHeaderMetadata_11remove_heade static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_10remove_header(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_v_self, PyObject *__pyx_v_key) { bcf_hdr_t *__pyx_v_hdr; vdict_t *__pyx_v_d; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; khiter_t __pyx_v_k; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations @@ -22875,11 +24696,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_10remove_heade char const *__pyx_t_3; int __pyx_t_4; int __pyx_t_5; - char const *__pyx_t_6; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + char const *__pyx_t_9; __Pyx_RefNannySetupContext("remove_header", 0); - __Pyx_TraceCall("remove_header", __pyx_f[0], 1448, 0, __PYX_ERR(0, 1448, __pyx_L1_error)); + __Pyx_TraceCall("remove_header", __pyx_f[0], 1605, 0, __PYX_ERR(0, 1605, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1449 + /* "pysam/libcbcf.pyx":1606 * * def remove_header(self, key): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -22889,46 +24713,46 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_10remove_heade __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1450 + /* "pysam/libcbcf.pyx":1607 * def remove_header(self, key): * cdef bcf_hdr_t *hdr = self.header.ptr * cdef vdict_t *d = hdr.dict[BCF_DT_ID] # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ __pyx_v_d = ((vdict_t *)(__pyx_v_hdr->dict[BCF_DT_ID])); - /* "pysam/libcbcf.pyx":1452 + /* "pysam/libcbcf.pyx":1609 * cdef vdict_t *d = hdr.dict[BCF_DT_ID] * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * cdef khiter_t k = kh_get_vdict(d, bkey) * */ - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1452, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1609, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_bkey = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":1453 + /* "pysam/libcbcf.pyx":1610 * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef khiter_t k = kh_get_vdict(d, bkey) # <<<<<<<<<<<<<< * * if k == kh_end(d) or kh_val_vdict(d, k).info[self.type] & 0xF == 0xF: */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 1453, __pyx_L1_error) + __PYX_ERR(0, 1610, __pyx_L1_error) } - __pyx_t_3 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 1453, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 1610, __pyx_L1_error) __pyx_v_k = kh_get_vdict(__pyx_v_d, __pyx_t_3); - /* "pysam/libcbcf.pyx":1455 + /* "pysam/libcbcf.pyx":1612 * cdef khiter_t k = kh_get_vdict(d, bkey) * * if k == kh_end(d) or kh_val_vdict(d, k).info[self.type] & 0xF == 0xF: # <<<<<<<<<<<<<< - * raise KeyError('invalid key') + * raise KeyError('invalid key: {}'.format(key)) * */ __pyx_t_5 = ((__pyx_v_k == kh_end(__pyx_v_d)) != 0); @@ -22942,30 +24766,76 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_10remove_heade __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_4)) { - /* "pysam/libcbcf.pyx":1456 + /* "pysam/libcbcf.pyx":1613 * * if k == kh_end(d) or kh_val_vdict(d, k).info[self.type] & 0xF == 0xF: - * raise KeyError('invalid key') # <<<<<<<<<<<<<< + * raise KeyError('invalid key: {}'.format(key)) # <<<<<<<<<<<<<< * * bcf_hdr_remove(hdr, self.type, bkey) */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__84, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1456, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_key, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1613, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + if (!__pyx_t_7) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1613, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_key}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1613, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_key}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1613, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1613, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_key); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1613, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1613, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 1456, __pyx_L1_error) + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 1613, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1455 + /* "pysam/libcbcf.pyx":1612 * cdef khiter_t k = kh_get_vdict(d, bkey) * * if k == kh_end(d) or kh_val_vdict(d, k).info[self.type] & 0xF == 0xF: # <<<<<<<<<<<<<< - * raise KeyError('invalid key') + * raise KeyError('invalid key: {}'.format(key)) * */ } - /* "pysam/libcbcf.pyx":1458 - * raise KeyError('invalid key') + /* "pysam/libcbcf.pyx":1615 + * raise KeyError('invalid key: {}'.format(key)) * * bcf_hdr_remove(hdr, self.type, bkey) # <<<<<<<<<<<<<< * #bcf_hdr_sync(hdr) @@ -22973,12 +24843,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_10remove_heade */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 1458, __pyx_L1_error) + __PYX_ERR(0, 1615, __pyx_L1_error) } - __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 1458, __pyx_L1_error) - bcf_hdr_remove(__pyx_v_hdr, __pyx_v_self->type, __pyx_t_6); + __pyx_t_9 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 1615, __pyx_L1_error) + bcf_hdr_remove(__pyx_v_hdr, __pyx_v_self->type, __pyx_t_9); - /* "pysam/libcbcf.pyx":1448 + /* "pysam/libcbcf.pyx":1605 * return makeVariantMetadata(self.header, self.type, kh_val_vdict(d, k).id) * * def remove_header(self, key): # <<<<<<<<<<<<<< @@ -22991,6 +24861,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_10remove_heade goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderMetadata.remove_header", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -23001,7 +24874,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_10remove_heade return __pyx_r; } -/* "pysam/libcbcf.pyx":1461 +/* "pysam/libcbcf.pyx":1618 * #bcf_hdr_sync(hdr) * * def clear_header(self): # <<<<<<<<<<<<<< @@ -23030,9 +24903,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_12clear_header __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; __Pyx_RefNannySetupContext("clear_header", 0); - __Pyx_TraceCall("clear_header", __pyx_f[0], 1461, 0, __PYX_ERR(0, 1461, __pyx_L1_error)); + __Pyx_TraceCall("clear_header", __pyx_f[0], 1618, 0, __PYX_ERR(0, 1618, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1462 + /* "pysam/libcbcf.pyx":1619 * * def clear_header(self): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -23042,7 +24915,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_12clear_header __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1463 + /* "pysam/libcbcf.pyx":1620 * def clear_header(self): * cdef bcf_hdr_t *hdr = self.header.ptr * bcf_hdr_remove(hdr, self.type, NULL) # <<<<<<<<<<<<<< @@ -23051,7 +24924,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_12clear_header */ bcf_hdr_remove(__pyx_v_hdr, __pyx_v_self->type, NULL); - /* "pysam/libcbcf.pyx":1461 + /* "pysam/libcbcf.pyx":1618 * #bcf_hdr_sync(hdr) * * def clear_header(self): # <<<<<<<<<<<<<< @@ -23073,7 +24946,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_12clear_header } static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_16generator4(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1466 +/* "pysam/libcbcf.pyx":1623 * #bcf_hdr_sync(hdr) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -23103,7 +24976,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_14__iter__(str if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_14___iter__ *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1466, __pyx_L1_error) + __PYX_ERR(0, 1623, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -23111,7 +24984,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_14__iter__(str __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_16generator4, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantHeaderMetadata___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1466, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_16generator4, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantHeaderMetadata___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1623, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -23141,7 +25014,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_16generator4(_ PyObject *__pyx_t_7 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1466, 0, __PYX_ERR(0, 1466, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 1623, 0, __PYX_ERR(0, 1623, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L10_resume_from_yield; @@ -23151,9 +25024,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_16generator4(_ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1466, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1623, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1467 + /* "pysam/libcbcf.pyx":1624 * * def __iter__(self): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -23163,7 +25036,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_16generator4(_ __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->header->ptr; __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1471 + /* "pysam/libcbcf.pyx":1628 * cdef int32_t i * * for i in range(hdr.n[BCF_DT_ID]): # <<<<<<<<<<<<<< @@ -23175,7 +25048,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_16generator4(_ for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_4; - /* "pysam/libcbcf.pyx":1472 + /* "pysam/libcbcf.pyx":1629 * * for i in range(hdr.n[BCF_DT_ID]): * idpair = hdr.id[BCF_DT_ID] + i # <<<<<<<<<<<<<< @@ -23184,7 +25057,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_16generator4(_ */ __pyx_cur_scope->__pyx_v_idpair = ((__pyx_cur_scope->__pyx_v_hdr->id[BCF_DT_ID]) + __pyx_cur_scope->__pyx_v_i); - /* "pysam/libcbcf.pyx":1473 + /* "pysam/libcbcf.pyx":1630 * for i in range(hdr.n[BCF_DT_ID]): * idpair = hdr.id[BCF_DT_ID] + i * if idpair.key and idpair.val and idpair.val.info[self.type] & 0xF != 0xF: # <<<<<<<<<<<<<< @@ -23208,14 +25081,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_16generator4(_ __pyx_L7_bool_binop_done:; if (__pyx_t_5) { - /* "pysam/libcbcf.pyx":1474 + /* "pysam/libcbcf.pyx":1631 * idpair = hdr.id[BCF_DT_ID] + i * if idpair.key and idpair.val and idpair.val.info[self.type] & 0xF != 0xF: * yield bcf_str_cache_get_charptr(idpair.key) # <<<<<<<<<<<<<< * * def get(self, key, default=None): */ - __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(__pyx_cur_scope->__pyx_v_idpair->key); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1474, __pyx_L1_error) + __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(__pyx_cur_scope->__pyx_v_idpair->key); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1631, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_r = __pyx_t_7; __pyx_t_7 = 0; @@ -23233,9 +25106,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_16generator4(_ __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1474, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1631, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1473 + /* "pysam/libcbcf.pyx":1630 * for i in range(hdr.n[BCF_DT_ID]): * idpair = hdr.id[BCF_DT_ID] + i * if idpair.key and idpair.val and idpair.val.info[self.type] & 0xF != 0xF: # <<<<<<<<<<<<<< @@ -23246,7 +25119,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_16generator4(_ } CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1466 + /* "pysam/libcbcf.pyx":1623 * #bcf_hdr_sync(hdr) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -23270,7 +25143,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_16generator4(_ return __pyx_r; } -/* "pysam/libcbcf.pyx":1476 +/* "pysam/libcbcf.pyx":1633 * yield bcf_str_cache_get_charptr(idpair.key) * * def get(self, key, default=None): # <<<<<<<<<<<<<< @@ -23315,7 +25188,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_21VariantHeaderMetadata_18get(PyObject } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 1476, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 1633, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -23331,7 +25204,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_21VariantHeaderMetadata_18get(PyObject } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1476, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1633, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderMetadata.get", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -23356,9 +25229,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_17get(struct _ PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("get", 0); - __Pyx_TraceCall("get", __pyx_f[0], 1476, 0, __PYX_ERR(0, 1476, __pyx_L1_error)); + __Pyx_TraceCall("get", __pyx_f[0], 1633, 0, __PYX_ERR(0, 1633, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1478 + /* "pysam/libcbcf.pyx":1635 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -23374,7 +25247,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_17get(struct _ __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "pysam/libcbcf.pyx":1479 + /* "pysam/libcbcf.pyx":1636 * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: * return self[key] # <<<<<<<<<<<<<< @@ -23382,13 +25255,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_17get(struct _ * return default */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1479, __pyx_L3_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1636, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L7_try_return; - /* "pysam/libcbcf.pyx":1478 + /* "pysam/libcbcf.pyx":1635 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -23399,7 +25272,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_17get(struct _ __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1480 + /* "pysam/libcbcf.pyx":1637 * try: * return self[key] * except KeyError: # <<<<<<<<<<<<<< @@ -23409,12 +25282,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_17get(struct _ __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); if (__pyx_t_5) { __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderMetadata.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1480, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1637, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcbcf.pyx":1481 + /* "pysam/libcbcf.pyx":1638 * return self[key] * except KeyError: * return default # <<<<<<<<<<<<<< @@ -23432,7 +25305,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_17get(struct _ goto __pyx_L5_except_error; __pyx_L5_except_error:; - /* "pysam/libcbcf.pyx":1478 + /* "pysam/libcbcf.pyx":1635 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -23458,7 +25331,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_17get(struct _ goto __pyx_L0; } - /* "pysam/libcbcf.pyx":1476 + /* "pysam/libcbcf.pyx":1633 * yield bcf_str_cache_get_charptr(idpair.key) * * def get(self, key, default=None): # <<<<<<<<<<<<<< @@ -23480,7 +25353,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_17get(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":1483 +/* "pysam/libcbcf.pyx":1640 * return default * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -23513,9 +25386,9 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_19__contains__(struc PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("__contains__", 0); - __Pyx_TraceCall("__contains__", __pyx_f[0], 1483, 0, __PYX_ERR(0, 1483, __pyx_L1_error)); + __Pyx_TraceCall("__contains__", __pyx_f[0], 1640, 0, __PYX_ERR(0, 1640, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1484 + /* "pysam/libcbcf.pyx":1641 * * def __contains__(self, key): * try: # <<<<<<<<<<<<<< @@ -23531,18 +25404,18 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_19__contains__(struc __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "pysam/libcbcf.pyx":1485 + /* "pysam/libcbcf.pyx":1642 * def __contains__(self, key): * try: * self[key] # <<<<<<<<<<<<<< * except KeyError: * return False */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1485, __pyx_L3_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1642, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1484 + /* "pysam/libcbcf.pyx":1641 * * def __contains__(self, key): * try: # <<<<<<<<<<<<<< @@ -23551,7 +25424,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_19__contains__(struc */ } - /* "pysam/libcbcf.pyx":1489 + /* "pysam/libcbcf.pyx":1646 * return False * else: * return True # <<<<<<<<<<<<<< @@ -23565,7 +25438,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_19__contains__(struc __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1486 + /* "pysam/libcbcf.pyx":1643 * try: * self[key] * except KeyError: # <<<<<<<<<<<<<< @@ -23575,12 +25448,12 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_19__contains__(struc __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); if (__pyx_t_5) { __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderMetadata.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1486, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1643, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcbcf.pyx":1487 + /* "pysam/libcbcf.pyx":1644 * self[key] * except KeyError: * return False # <<<<<<<<<<<<<< @@ -23596,7 +25469,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_19__contains__(struc goto __pyx_L5_except_error; __pyx_L5_except_error:; - /* "pysam/libcbcf.pyx":1484 + /* "pysam/libcbcf.pyx":1641 * * def __contains__(self, key): * try: # <<<<<<<<<<<<<< @@ -23616,7 +25489,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_19__contains__(struc goto __pyx_L0; } - /* "pysam/libcbcf.pyx":1483 + /* "pysam/libcbcf.pyx":1640 * return default * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -23637,7 +25510,7 @@ static int __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_19__contains__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":1491 +/* "pysam/libcbcf.pyx":1648 * return True * * def iterkeys(self): # <<<<<<<<<<<<<< @@ -23665,9 +25538,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_21iterkeys(str __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("iterkeys", 0); - __Pyx_TraceCall("iterkeys", __pyx_f[0], 1491, 0, __PYX_ERR(0, 1491, __pyx_L1_error)); + __Pyx_TraceCall("iterkeys", __pyx_f[0], 1648, 0, __PYX_ERR(0, 1648, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1493 + /* "pysam/libcbcf.pyx":1650 * def iterkeys(self): * """D.iterkeys() -> an iterator over the keys of D""" * return iter(self) # <<<<<<<<<<<<<< @@ -23675,13 +25548,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_21iterkeys(str * def itervalues(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1493, __pyx_L1_error) + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1650, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1491 + /* "pysam/libcbcf.pyx":1648 * return True * * def iterkeys(self): # <<<<<<<<<<<<<< @@ -23702,7 +25575,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_21iterkeys(str } static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_25generator5(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1495 +/* "pysam/libcbcf.pyx":1652 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -23733,7 +25606,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_23itervalues(s if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_15_itervalues *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1495, __pyx_L1_error) + __PYX_ERR(0, 1652, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -23741,7 +25614,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_23itervalues(s __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_25generator5, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantHeaderMetadata_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1495, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_25generator5, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantHeaderMetadata_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1652, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -23768,7 +25641,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_25generator5(_ PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("itervalues", 0); - __Pyx_TraceCall("itervalues", __pyx_f[0], 1495, 0, __PYX_ERR(0, 1495, __pyx_L1_error)); + __Pyx_TraceCall("itervalues", __pyx_f[0], 1652, 0, __PYX_ERR(0, 1652, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -23778,9 +25651,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_25generator5(_ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1495, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1652, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1497 + /* "pysam/libcbcf.pyx":1654 * def itervalues(self): * """D.itervalues() -> an iterator over the values of D""" * for key in self: # <<<<<<<<<<<<<< @@ -23791,26 +25664,26 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_25generator5(_ __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1497, __pyx_L1_error) + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1654, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1497, __pyx_L1_error) + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1654, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_3)) { if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1497, __pyx_L1_error) + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1654, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1497, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1654, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } else { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1497, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1654, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1497, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1654, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } @@ -23820,7 +25693,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_25generator5(_ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1497, __pyx_L1_error) + else __PYX_ERR(0, 1654, __pyx_L1_error) } break; } @@ -23831,14 +25704,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_25generator5(_ __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1498 + /* "pysam/libcbcf.pyx":1655 * """D.itervalues() -> an iterator over the values of D""" * for key in self: * yield self[key] # <<<<<<<<<<<<<< * * def iteritems(self): */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1498, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1655, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; @@ -23859,9 +25732,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_25generator5(_ __Pyx_XGOTREF(__pyx_t_1); __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1498, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1655, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1497 + /* "pysam/libcbcf.pyx":1654 * def itervalues(self): * """D.itervalues() -> an iterator over the values of D""" * for key in self: # <<<<<<<<<<<<<< @@ -23872,7 +25745,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_25generator5(_ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1495 + /* "pysam/libcbcf.pyx":1652 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -23898,7 +25771,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_25generator5(_ } static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_28generator6(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1500 +/* "pysam/libcbcf.pyx":1657 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -23929,7 +25802,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_26iteritems(st if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_16_iteritems *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1500, __pyx_L1_error) + __PYX_ERR(0, 1657, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -23937,7 +25810,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_26iteritems(st __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_28generator6, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantHeaderMetadata_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1500, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_28generator6, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantHeaderMetadata_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1657, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -23965,7 +25838,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_28generator6(_ PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("iteritems", 0); - __Pyx_TraceCall("iteritems", __pyx_f[0], 1500, 0, __PYX_ERR(0, 1500, __pyx_L1_error)); + __Pyx_TraceCall("iteritems", __pyx_f[0], 1657, 0, __PYX_ERR(0, 1657, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -23975,9 +25848,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_28generator6(_ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1500, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1657, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1502 + /* "pysam/libcbcf.pyx":1659 * def iteritems(self): * """D.iteritems() -> an iterator over the (key, value) items of D""" * for key in self: # <<<<<<<<<<<<<< @@ -23988,26 +25861,26 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_28generator6(_ __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1502, __pyx_L1_error) + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1659, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1502, __pyx_L1_error) + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1659, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_3)) { if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1502, __pyx_L1_error) + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1659, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1502, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1659, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } else { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1502, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1659, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1502, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1659, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } @@ -24017,7 +25890,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_28generator6(_ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1502, __pyx_L1_error) + else __PYX_ERR(0, 1659, __pyx_L1_error) } break; } @@ -24028,16 +25901,16 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_28generator6(_ __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1503 + /* "pysam/libcbcf.pyx":1660 * """D.iteritems() -> an iterator over the (key, value) items of D""" * for key in self: * yield (key, self[key]) # <<<<<<<<<<<<<< * * def keys(self): */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1503, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1660, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1503, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1660, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); @@ -24064,9 +25937,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_28generator6(_ __Pyx_XGOTREF(__pyx_t_1); __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1503, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1660, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1502 + /* "pysam/libcbcf.pyx":1659 * def iteritems(self): * """D.iteritems() -> an iterator over the (key, value) items of D""" * for key in self: # <<<<<<<<<<<<<< @@ -24077,7 +25950,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_28generator6(_ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1500 + /* "pysam/libcbcf.pyx":1657 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -24103,7 +25976,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_21VariantHeaderMetadata_28generator6(_ return __pyx_r; } -/* "pysam/libcbcf.pyx":1505 +/* "pysam/libcbcf.pyx":1662 * yield (key, self[key]) * * def keys(self): # <<<<<<<<<<<<<< @@ -24131,9 +26004,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_29keys(struct __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("keys", 0); - __Pyx_TraceCall("keys", __pyx_f[0], 1505, 0, __PYX_ERR(0, 1505, __pyx_L1_error)); + __Pyx_TraceCall("keys", __pyx_f[0], 1662, 0, __PYX_ERR(0, 1662, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1507 + /* "pysam/libcbcf.pyx":1664 * def keys(self): * """D.keys() -> list of D's keys""" * return list(self) # <<<<<<<<<<<<<< @@ -24141,13 +26014,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_29keys(struct * def items(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1507, __pyx_L1_error) + __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1664, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1505 + /* "pysam/libcbcf.pyx":1662 * yield (key, self[key]) * * def keys(self): # <<<<<<<<<<<<<< @@ -24167,7 +26040,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_29keys(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1509 +/* "pysam/libcbcf.pyx":1666 * return list(self) * * def items(self): # <<<<<<<<<<<<<< @@ -24197,9 +26070,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_31items(struct PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("items", 0); - __Pyx_TraceCall("items", __pyx_f[0], 1509, 0, __PYX_ERR(0, 1509, __pyx_L1_error)); + __Pyx_TraceCall("items", __pyx_f[0], 1666, 0, __PYX_ERR(0, 1666, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1511 + /* "pysam/libcbcf.pyx":1668 * def items(self): * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" * return list(self.iteritems()) # <<<<<<<<<<<<<< @@ -24207,7 +26080,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_31items(struct * def values(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1511, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1668, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -24220,21 +26093,21 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_31items(struct } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1511, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1668, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1511, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1668, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1511, __pyx_L1_error) + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1668, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1509 + /* "pysam/libcbcf.pyx":1666 * return list(self) * * def items(self): # <<<<<<<<<<<<<< @@ -24256,7 +26129,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_31items(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1513 +/* "pysam/libcbcf.pyx":1670 * return list(self.iteritems()) * * def values(self): # <<<<<<<<<<<<<< @@ -24286,9 +26159,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_33values(struc PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("values", 0); - __Pyx_TraceCall("values", __pyx_f[0], 1513, 0, __PYX_ERR(0, 1513, __pyx_L1_error)); + __Pyx_TraceCall("values", __pyx_f[0], 1670, 0, __PYX_ERR(0, 1670, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1515 + /* "pysam/libcbcf.pyx":1672 * def values(self): * """D.values() -> list of D's values""" * return list(self.itervalues()) # <<<<<<<<<<<<<< @@ -24296,7 +26169,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_33values(struc * # Mappings are not hashable by default, but subclasses can change this */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1515, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1672, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -24309,21 +26182,21 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_33values(struc } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1515, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1672, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1515, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1672, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1515, __pyx_L1_error) + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1672, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1513 + /* "pysam/libcbcf.pyx":1670 * return list(self.iteritems()) * * def values(self): # <<<<<<<<<<<<<< @@ -24345,6 +26218,49 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_33values(struc return __pyx_r; } +/* "pysam/libcbcf.pxd":73 + * + * cdef class VariantHeaderMetadata(object): + * cdef readonly VariantHeader header # <<<<<<<<<<<<<< + * cdef int32_t type + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_21VariantHeaderMetadata_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_21VariantHeaderMetadata_6header_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_6header___get__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 73, 0, __PYX_ERR(1, 73, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); + __pyx_r = ((PyObject *)__pyx_v_self->header); + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderMetadata.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef bint use_setstate @@ -24378,7 +26294,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_35__reduce_cyt int __pyx_t_4; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -24387,9 +26303,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_35__reduce_cyt * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->type); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->type); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self->header)); @@ -24407,7 +26323,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_35__reduce_cyt * if _dict is not None: * state += (_dict,) */ - __pyx_t_2 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v__dict = __pyx_t_2; __pyx_t_2 = 0; @@ -24430,12 +26346,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_35__reduce_cyt * use_setstate = True * else: */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v__dict); - __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_1)); @@ -24491,9 +26407,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_35__reduce_cyt * return __pyx_unpickle_VariantHeaderMetadata, (type(self), 0xed5e66b, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderMeta); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderMeta); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -24504,7 +26420,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_35__reduce_cyt __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_2, 2, Py_None); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); @@ -24537,9 +26453,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_35__reduce_cyt */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderMeta); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderMeta); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -24550,7 +26466,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_35__reduce_cyt __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_state); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); @@ -24612,15 +26528,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_37__setstate_c __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 14, 0, __PYX_ERR(2, 14, __pyx_L1_error)); /* "(tree fragment)":15 * return __pyx_unpickle_VariantHeaderMetadata, (type(self), 0xed5e66b, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_VariantHeaderMetadata__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderMetadata__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderMetadata__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -24645,7 +26561,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_21VariantHeaderMetadata_37__setstate_c return __pyx_r; } -/* "pysam/libcbcf.pyx":1523 +/* "pysam/libcbcf.pyx":1680 * * * cdef VariantHeaderMetadata makeVariantHeaderMetadata(VariantHeader header, int32_t type): # <<<<<<<<<<<<<< @@ -24662,33 +26578,33 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_f_5pysam_7l int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("makeVariantHeaderMetadata", 0); - __Pyx_TraceCall("makeVariantHeaderMetadata", __pyx_f[0], 1523, 0, __PYX_ERR(0, 1523, __pyx_L1_error)); + __Pyx_TraceCall("makeVariantHeaderMetadata", __pyx_f[0], 1680, 0, __PYX_ERR(0, 1680, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1524 + /* "pysam/libcbcf.pyx":1681 * * cdef VariantHeaderMetadata makeVariantHeaderMetadata(VariantHeader header, int32_t type): * if not header: # <<<<<<<<<<<<<< * raise ValueError('invalid VariantHeader') * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1524, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1681, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1525 + /* "pysam/libcbcf.pyx":1682 * cdef VariantHeaderMetadata makeVariantHeaderMetadata(VariantHeader header, int32_t type): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * cdef VariantHeaderMetadata meta = VariantHeaderMetadata.__new__(VariantHeaderMetadata) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__85, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1525, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__83, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1682, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1525, __pyx_L1_error) + __PYX_ERR(0, 1682, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1524 + /* "pysam/libcbcf.pyx":1681 * * cdef VariantHeaderMetadata makeVariantHeaderMetadata(VariantHeader header, int32_t type): * if not header: # <<<<<<<<<<<<<< @@ -24697,19 +26613,19 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_f_5pysam_7l */ } - /* "pysam/libcbcf.pyx":1527 + /* "pysam/libcbcf.pyx":1684 * raise ValueError('invalid VariantHeader') * * cdef VariantHeaderMetadata meta = VariantHeaderMetadata.__new__(VariantHeaderMetadata) # <<<<<<<<<<<<<< * meta.header = header * meta.type = type */ - __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantHeaderMetadata(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderMetadata), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1527, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantHeaderMetadata(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderMetadata), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1684, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_v_meta = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":1528 + /* "pysam/libcbcf.pyx":1685 * * cdef VariantHeaderMetadata meta = VariantHeaderMetadata.__new__(VariantHeaderMetadata) * meta.header = header # <<<<<<<<<<<<<< @@ -24722,7 +26638,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_f_5pysam_7l __Pyx_DECREF(((PyObject *)__pyx_v_meta->header)); __pyx_v_meta->header = __pyx_v_header; - /* "pysam/libcbcf.pyx":1529 + /* "pysam/libcbcf.pyx":1686 * cdef VariantHeaderMetadata meta = VariantHeaderMetadata.__new__(VariantHeaderMetadata) * meta.header = header * meta.type = type # <<<<<<<<<<<<<< @@ -24731,7 +26647,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_f_5pysam_7l */ __pyx_v_meta->type = __pyx_v_type; - /* "pysam/libcbcf.pyx":1531 + /* "pysam/libcbcf.pyx":1688 * meta.type = type * * return meta # <<<<<<<<<<<<<< @@ -24743,7 +26659,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_f_5pysam_7l __pyx_r = __pyx_v_meta; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1523 + /* "pysam/libcbcf.pyx":1680 * * * cdef VariantHeaderMetadata makeVariantHeaderMetadata(VariantHeader header, int32_t type): # <<<<<<<<<<<<<< @@ -24764,7 +26680,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *__pyx_f_5pysam_7l return __pyx_r; } -/* "pysam/libcbcf.pyx":1536 +/* "pysam/libcbcf.pyx":1693 * cdef class VariantContig(object): * """contig metadata from a :class:`VariantHeader`""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -24798,22 +26714,22 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantContig___init__(CYTHON_UNUSED struc __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1536, 0, __PYX_ERR(0, 1536, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 1693, 0, __PYX_ERR(0, 1693, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1537 + /* "pysam/libcbcf.pyx":1694 * """contig metadata from a :class:`VariantHeader`""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * @property */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__86, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1537, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__84, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1694, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1537, __pyx_L1_error) + __PYX_ERR(0, 1694, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1536 + /* "pysam/libcbcf.pyx":1693 * cdef class VariantContig(object): * """contig metadata from a :class:`VariantHeader`""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -24831,7 +26747,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantContig___init__(CYTHON_UNUSED struc return __pyx_r; } -/* "pysam/libcbcf.pyx":1540 +/* "pysam/libcbcf.pyx":1697 * * @property * def name(self): # <<<<<<<<<<<<<< @@ -24860,9 +26776,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4name___get__(struct _ bcf_hdr_t *__pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1540, 0, __PYX_ERR(0, 1540, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1697, 0, __PYX_ERR(0, 1697, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1542 + /* "pysam/libcbcf.pyx":1699 * def name(self): * """contig name""" * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -24872,7 +26788,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4name___get__(struct _ __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1543 + /* "pysam/libcbcf.pyx":1700 * """contig name""" * cdef bcf_hdr_t *hdr = self.header.ptr * return bcf_str_cache_get_charptr(hdr.id[BCF_DT_CTG][self.id].key) # <<<<<<<<<<<<<< @@ -24880,13 +26796,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4name___get__(struct _ * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(((__pyx_v_hdr->id[BCF_DT_CTG])[__pyx_v_self->id]).key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1543, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(((__pyx_v_hdr->id[BCF_DT_CTG])[__pyx_v_self->id]).key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1700, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1540 + /* "pysam/libcbcf.pyx":1697 * * @property * def name(self): # <<<<<<<<<<<<<< @@ -24906,7 +26822,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4name___get__(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":1546 +/* "pysam/libcbcf.pyx":1703 * * @property * def id(self): # <<<<<<<<<<<<<< @@ -24933,9 +26849,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_2id___get__(struct __p __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1546, 0, __PYX_ERR(0, 1546, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1703, 0, __PYX_ERR(0, 1703, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1548 + /* "pysam/libcbcf.pyx":1705 * def id(self): * """contig internal id number""" * return self.id # <<<<<<<<<<<<<< @@ -24943,13 +26859,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_2id___get__(struct __p * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1548, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1705, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1546 + /* "pysam/libcbcf.pyx":1703 * * @property * def id(self): # <<<<<<<<<<<<<< @@ -24969,7 +26885,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_2id___get__(struct __p return __pyx_r; } -/* "pysam/libcbcf.pyx":1551 +/* "pysam/libcbcf.pyx":1708 * * @property * def length(self): # <<<<<<<<<<<<<< @@ -25000,9 +26916,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6length___get__(struct PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1551, 0, __PYX_ERR(0, 1551, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1708, 0, __PYX_ERR(0, 1708, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1553 + /* "pysam/libcbcf.pyx":1710 * def length(self): * """contig length or None if not available""" * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -25012,7 +26928,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6length___get__(struct __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1554 + /* "pysam/libcbcf.pyx":1711 * """contig length or None if not available""" * cdef bcf_hdr_t *hdr = self.header.ptr * cdef uint32_t length = hdr.id[BCF_DT_CTG][self.id].val.info[0] # <<<<<<<<<<<<<< @@ -25021,7 +26937,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6length___get__(struct */ __pyx_v_length = (((__pyx_v_hdr->id[BCF_DT_CTG])[__pyx_v_self->id]).val->info[0]); - /* "pysam/libcbcf.pyx":1555 + /* "pysam/libcbcf.pyx":1712 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef uint32_t length = hdr.id[BCF_DT_CTG][self.id].val.info[0] * return length if length else None # <<<<<<<<<<<<<< @@ -25030,7 +26946,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6length___get__(struct */ __Pyx_XDECREF(__pyx_r); if ((__pyx_v_length != 0)) { - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1555, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1712, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __pyx_t_3; __pyx_t_3 = 0; @@ -25042,7 +26958,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6length___get__(struct __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1551 + /* "pysam/libcbcf.pyx":1708 * * @property * def length(self): # <<<<<<<<<<<<<< @@ -25063,28 +26979,28 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6length___get__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1558 +/* "pysam/libcbcf.pyx":1715 * * @property - * def header(self): # <<<<<<<<<<<<<< + * def header_record(self): # <<<<<<<<<<<<<< * """:class:`VariantHeaderRecord` associated with this :class:`VariantContig` object""" * cdef bcf_hdr_t *hdr = self.header.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantContig_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantContig_6header_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantContig_13header_record_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantContig_13header_record_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantContig_6header___get__(((struct __pyx_obj_5pysam_7libcbcf_VariantContig *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantContig_13header_record___get__(((struct __pyx_obj_5pysam_7libcbcf_VariantContig *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_13header_record___get__(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self) { bcf_hdr_t *__pyx_v_hdr; bcf_hrec_t *__pyx_v_hrec; PyObject *__pyx_r = NULL; @@ -25094,10 +27010,10 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6header___get__(struct PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1558, 0, __PYX_ERR(0, 1558, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1715, 0, __PYX_ERR(0, 1715, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1560 - * def header(self): + /* "pysam/libcbcf.pyx":1717 + * def header_record(self): * """:class:`VariantHeaderRecord` associated with this :class:`VariantContig` object""" * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< * cdef bcf_hrec_t *hrec = hdr.id[BCF_DT_CTG][self.id].val.hrec[0] @@ -25106,7 +27022,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6header___get__(struct __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1561 + /* "pysam/libcbcf.pyx":1718 * """:class:`VariantHeaderRecord` associated with this :class:`VariantContig` object""" * cdef bcf_hdr_t *hdr = self.header.ptr * cdef bcf_hrec_t *hrec = hdr.id[BCF_DT_CTG][self.id].val.hrec[0] # <<<<<<<<<<<<<< @@ -25115,7 +27031,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6header___get__(struct */ __pyx_v_hrec = (((__pyx_v_hdr->id[BCF_DT_CTG])[__pyx_v_self->id]).val->hrec[0]); - /* "pysam/libcbcf.pyx":1562 + /* "pysam/libcbcf.pyx":1719 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef bcf_hrec_t *hrec = hdr.id[BCF_DT_CTG][self.id].val.hrec[0] * return makeVariantHeaderRecord(self.header, hrec) # <<<<<<<<<<<<<< @@ -25125,17 +27041,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6header___get__(struct __Pyx_XDECREF(__pyx_r); __pyx_t_2 = ((PyObject *)__pyx_v_self->header); __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_2), __pyx_v_hrec)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1562, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_2), __pyx_v_hrec)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1719, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1558 + /* "pysam/libcbcf.pyx":1715 * * @property - * def header(self): # <<<<<<<<<<<<<< + * def header_record(self): # <<<<<<<<<<<<<< * """:class:`VariantHeaderRecord` associated with this :class:`VariantContig` object""" * cdef bcf_hdr_t *hdr = self.header.ptr */ @@ -25144,7 +27060,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6header___get__(struct __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantContig.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantContig.header_record.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -25153,12 +27069,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6header___get__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1564 +/* "pysam/libcbcf.pyx":1721 * return makeVariantHeaderRecord(self.header, hrec) * * def remove_header(self): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.header.ptr - * cdef const char *bkey = hdr.id[BCF_DT_CTG][self.id].key + * cdef const char *key = hdr.id[BCF_DT_CTG][self.id].key */ /* Python wrapper */ @@ -25177,50 +27093,50 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantContig_3remove_header(PyObjec static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_2remove_header(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self) { bcf_hdr_t *__pyx_v_hdr; - char const *__pyx_v_bkey; + char const *__pyx_v_key; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; char const *__pyx_t_2; __Pyx_RefNannySetupContext("remove_header", 0); - __Pyx_TraceCall("remove_header", __pyx_f[0], 1564, 0, __PYX_ERR(0, 1564, __pyx_L1_error)); + __Pyx_TraceCall("remove_header", __pyx_f[0], 1721, 0, __PYX_ERR(0, 1721, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1565 + /* "pysam/libcbcf.pyx":1722 * * def remove_header(self): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< - * cdef const char *bkey = hdr.id[BCF_DT_CTG][self.id].key - * bcf_hdr_remove(hdr, BCF_HL_CTG, bkey) + * cdef const char *key = hdr.id[BCF_DT_CTG][self.id].key + * bcf_hdr_remove(hdr, BCF_HL_CTG, key) */ __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1566 + /* "pysam/libcbcf.pyx":1723 * def remove_header(self): * cdef bcf_hdr_t *hdr = self.header.ptr - * cdef const char *bkey = hdr.id[BCF_DT_CTG][self.id].key # <<<<<<<<<<<<<< - * bcf_hdr_remove(hdr, BCF_HL_CTG, bkey) + * cdef const char *key = hdr.id[BCF_DT_CTG][self.id].key # <<<<<<<<<<<<<< + * bcf_hdr_remove(hdr, BCF_HL_CTG, key) * */ __pyx_t_2 = ((__pyx_v_hdr->id[BCF_DT_CTG])[__pyx_v_self->id]).key; - __pyx_v_bkey = __pyx_t_2; + __pyx_v_key = __pyx_t_2; - /* "pysam/libcbcf.pyx":1567 + /* "pysam/libcbcf.pyx":1724 * cdef bcf_hdr_t *hdr = self.header.ptr - * cdef const char *bkey = hdr.id[BCF_DT_CTG][self.id].key - * bcf_hdr_remove(hdr, BCF_HL_CTG, bkey) # <<<<<<<<<<<<<< + * cdef const char *key = hdr.id[BCF_DT_CTG][self.id].key + * bcf_hdr_remove(hdr, BCF_HL_CTG, key) # <<<<<<<<<<<<<< * * */ - bcf_hdr_remove(__pyx_v_hdr, BCF_HL_CTG, __pyx_v_bkey); + bcf_hdr_remove(__pyx_v_hdr, BCF_HL_CTG, __pyx_v_key); - /* "pysam/libcbcf.pyx":1564 + /* "pysam/libcbcf.pyx":1721 * return makeVariantHeaderRecord(self.header, hrec) * * def remove_header(self): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.header.ptr - * cdef const char *bkey = hdr.id[BCF_DT_CTG][self.id].key + * cdef const char *key = hdr.id[BCF_DT_CTG][self.id].key */ /* function exit code */ @@ -25236,6 +27152,49 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_2remove_header(struct return __pyx_r; } +/* "pysam/libcbcf.pxd":62 + * + * cdef class VariantContig(object): + * cdef readonly VariantHeader header # <<<<<<<<<<<<<< + * cdef int id + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantContig_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantContig_6header_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantContig_6header___get__(((struct __pyx_obj_5pysam_7libcbcf_VariantContig *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 62, 0, __PYX_ERR(1, 62, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); + __pyx_r = ((PyObject *)__pyx_v_self->header); + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantContig.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef bint use_setstate @@ -25269,7 +27228,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4__reduce_cython__(str int __pyx_t_4; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -25278,9 +27237,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4__reduce_cython__(str * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->id); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->id); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self->header)); @@ -25298,7 +27257,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4__reduce_cython__(str * if _dict is not None: * state += (_dict,) */ - __pyx_t_2 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v__dict = __pyx_t_2; __pyx_t_2 = 0; @@ -25321,12 +27280,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4__reduce_cython__(str * use_setstate = True * else: */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v__dict); - __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_1)); @@ -25382,9 +27341,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4__reduce_cython__(str * return __pyx_unpickle_VariantContig, (type(self), 0xbe66ecb, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantContig); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantContig); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -25395,7 +27354,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4__reduce_cython__(str __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_2, 2, Py_None); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); @@ -25428,9 +27387,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4__reduce_cython__(str */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantContig); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantContig); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -25441,7 +27400,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_4__reduce_cython__(str __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_state); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); @@ -25503,15 +27462,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6__setstate_cython__(s __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 14, 0, __PYX_ERR(2, 14, __pyx_L1_error)); /* "(tree fragment)":15 * return __pyx_unpickle_VariantContig, (type(self), 0xbe66ecb, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_VariantContig__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantContig__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantContig__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -25536,7 +27495,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantContig_6__setstate_cython__(s return __pyx_r; } -/* "pysam/libcbcf.pyx":1570 +/* "pysam/libcbcf.pyx":1727 * * * cdef VariantContig makeVariantContig(VariantHeader header, int id): # <<<<<<<<<<<<<< @@ -25553,33 +27512,33 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_f_5pysam_7libcbcf_m int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("makeVariantContig", 0); - __Pyx_TraceCall("makeVariantContig", __pyx_f[0], 1570, 0, __PYX_ERR(0, 1570, __pyx_L1_error)); + __Pyx_TraceCall("makeVariantContig", __pyx_f[0], 1727, 0, __PYX_ERR(0, 1727, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1571 + /* "pysam/libcbcf.pyx":1728 * * cdef VariantContig makeVariantContig(VariantHeader header, int id): * if not header: # <<<<<<<<<<<<<< * raise ValueError('invalid VariantHeader') * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1571, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1728, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1572 + /* "pysam/libcbcf.pyx":1729 * cdef VariantContig makeVariantContig(VariantHeader header, int id): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * if id < 0 or id >= header.ptr.n[BCF_DT_CTG]: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__87, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1572, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__85, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1729, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1572, __pyx_L1_error) + __PYX_ERR(0, 1729, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1571 + /* "pysam/libcbcf.pyx":1728 * * cdef VariantContig makeVariantContig(VariantHeader header, int id): * if not header: # <<<<<<<<<<<<<< @@ -25588,7 +27547,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_f_5pysam_7libcbcf_m */ } - /* "pysam/libcbcf.pyx":1574 + /* "pysam/libcbcf.pyx":1731 * raise ValueError('invalid VariantHeader') * * if id < 0 or id >= header.ptr.n[BCF_DT_CTG]: # <<<<<<<<<<<<<< @@ -25606,20 +27565,20 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_f_5pysam_7libcbcf_m __pyx_L5_bool_binop_done:; if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1575 + /* "pysam/libcbcf.pyx":1732 * * if id < 0 or id >= header.ptr.n[BCF_DT_CTG]: * raise ValueError('invalid contig id') # <<<<<<<<<<<<<< * * cdef VariantContig contig = VariantContig.__new__(VariantContig) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__88, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1575, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__86, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1732, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1575, __pyx_L1_error) + __PYX_ERR(0, 1732, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1574 + /* "pysam/libcbcf.pyx":1731 * raise ValueError('invalid VariantHeader') * * if id < 0 or id >= header.ptr.n[BCF_DT_CTG]: # <<<<<<<<<<<<<< @@ -25628,19 +27587,19 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_f_5pysam_7libcbcf_m */ } - /* "pysam/libcbcf.pyx":1577 + /* "pysam/libcbcf.pyx":1734 * raise ValueError('invalid contig id') * * cdef VariantContig contig = VariantContig.__new__(VariantContig) # <<<<<<<<<<<<<< * contig.header = header * contig.id = id */ - __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantContig(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantContig), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1577, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantContig(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantContig), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1734, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_v_contig = ((struct __pyx_obj_5pysam_7libcbcf_VariantContig *)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":1578 + /* "pysam/libcbcf.pyx":1735 * * cdef VariantContig contig = VariantContig.__new__(VariantContig) * contig.header = header # <<<<<<<<<<<<<< @@ -25653,7 +27612,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_f_5pysam_7libcbcf_m __Pyx_DECREF(((PyObject *)__pyx_v_contig->header)); __pyx_v_contig->header = __pyx_v_header; - /* "pysam/libcbcf.pyx":1579 + /* "pysam/libcbcf.pyx":1736 * cdef VariantContig contig = VariantContig.__new__(VariantContig) * contig.header = header * contig.id = id # <<<<<<<<<<<<<< @@ -25662,7 +27621,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_f_5pysam_7libcbcf_m */ __pyx_v_contig->id = __pyx_v_id; - /* "pysam/libcbcf.pyx":1581 + /* "pysam/libcbcf.pyx":1738 * contig.id = id * * return contig # <<<<<<<<<<<<<< @@ -25674,7 +27633,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_f_5pysam_7libcbcf_m __pyx_r = __pyx_v_contig; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1570 + /* "pysam/libcbcf.pyx":1727 * * * cdef VariantContig makeVariantContig(VariantHeader header, int id): # <<<<<<<<<<<<<< @@ -25695,7 +27654,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantContig *__pyx_f_5pysam_7libcbcf_m return __pyx_r; } -/* "pysam/libcbcf.pyx":1586 +/* "pysam/libcbcf.pyx":1743 * cdef class VariantHeaderContigs(object): * """mapping from contig name or index to :class:`VariantContig` object.""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -25729,22 +27688,22 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs___init__(CYTHON_UNUSE __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1586, 0, __PYX_ERR(0, 1586, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 1743, 0, __PYX_ERR(0, 1743, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1587 + /* "pysam/libcbcf.pyx":1744 * """mapping from contig name or index to :class:`VariantContig` object.""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__89, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1587, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__87, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1744, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1587, __pyx_L1_error) + __PYX_ERR(0, 1744, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1586 + /* "pysam/libcbcf.pyx":1743 * cdef class VariantHeaderContigs(object): * """mapping from contig name or index to :class:`VariantContig` object.""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -25762,7 +27721,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs___init__(CYTHON_UNUSE return __pyx_r; } -/* "pysam/libcbcf.pyx":1589 +/* "pysam/libcbcf.pyx":1746 * raise TypeError('this class cannot be instantiated from Python') * * def __len__(self): # <<<<<<<<<<<<<< @@ -25790,9 +27749,9 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_2__len__(struc __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[0], 1589, 0, __PYX_ERR(0, 1589, __pyx_L1_error)); + __Pyx_TraceCall("__len__", __pyx_f[0], 1746, 0, __PYX_ERR(0, 1746, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1590 + /* "pysam/libcbcf.pyx":1747 * * def __len__(self): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -25802,7 +27761,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_2__len__(struc __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1591 + /* "pysam/libcbcf.pyx":1748 * def __len__(self): * cdef bcf_hdr_t *hdr = self.header.ptr * assert kh_size(hdr.dict[BCF_DT_CTG]) == hdr.n[BCF_DT_CTG] # <<<<<<<<<<<<<< @@ -25813,12 +27772,12 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_2__len__(struc if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((kh_size(((vdict_t *)(__pyx_v_hdr->dict[BCF_DT_CTG]))) == (__pyx_v_hdr->n[BCF_DT_CTG])) != 0))) { PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 1591, __pyx_L1_error) + __PYX_ERR(0, 1748, __pyx_L1_error) } } #endif - /* "pysam/libcbcf.pyx":1592 + /* "pysam/libcbcf.pyx":1749 * cdef bcf_hdr_t *hdr = self.header.ptr * assert kh_size(hdr.dict[BCF_DT_CTG]) == hdr.n[BCF_DT_CTG] * return hdr.n[BCF_DT_CTG] # <<<<<<<<<<<<<< @@ -25828,7 +27787,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_2__len__(struc __pyx_r = (__pyx_v_hdr->n[BCF_DT_CTG]); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1589 + /* "pysam/libcbcf.pyx":1746 * raise TypeError('this class cannot be instantiated from Python') * * def __len__(self): # <<<<<<<<<<<<<< @@ -25846,7 +27805,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_2__len__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":1594 +/* "pysam/libcbcf.pyx":1751 * return hdr.n[BCF_DT_CTG] * * def __bool__(self): # <<<<<<<<<<<<<< @@ -25874,9 +27833,9 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_4__bool__(struct __py __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 1594, 0, __PYX_ERR(0, 1594, __pyx_L1_error)); + __Pyx_TraceCall("__bool__", __pyx_f[0], 1751, 0, __PYX_ERR(0, 1751, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1595 + /* "pysam/libcbcf.pyx":1752 * * def __bool__(self): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -25886,7 +27845,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_4__bool__(struct __py __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1596 + /* "pysam/libcbcf.pyx":1753 * def __bool__(self): * cdef bcf_hdr_t *hdr = self.header.ptr * assert kh_size(hdr.dict[BCF_DT_CTG]) == hdr.n[BCF_DT_CTG] # <<<<<<<<<<<<<< @@ -25897,12 +27856,12 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_4__bool__(struct __py if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((kh_size(((vdict_t *)(__pyx_v_hdr->dict[BCF_DT_CTG]))) == (__pyx_v_hdr->n[BCF_DT_CTG])) != 0))) { PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 1596, __pyx_L1_error) + __PYX_ERR(0, 1753, __pyx_L1_error) } } #endif - /* "pysam/libcbcf.pyx":1597 + /* "pysam/libcbcf.pyx":1754 * cdef bcf_hdr_t *hdr = self.header.ptr * assert kh_size(hdr.dict[BCF_DT_CTG]) == hdr.n[BCF_DT_CTG] * return hdr.n[BCF_DT_CTG] != 0 # <<<<<<<<<<<<<< @@ -25912,7 +27871,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_4__bool__(struct __py __pyx_r = ((__pyx_v_hdr->n[BCF_DT_CTG]) != 0); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1594 + /* "pysam/libcbcf.pyx":1751 * return hdr.n[BCF_DT_CTG] * * def __bool__(self): # <<<<<<<<<<<<<< @@ -25930,7 +27889,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_4__bool__(struct __py return __pyx_r; } -/* "pysam/libcbcf.pyx":1599 +/* "pysam/libcbcf.pyx":1756 * return hdr.n[BCF_DT_CTG] != 0 * * def __getitem__(self, key): # <<<<<<<<<<<<<< @@ -25955,7 +27914,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6__getitem__(st bcf_hdr_t *__pyx_v_hdr; int __pyx_v_index; vdict_t *__pyx_v_d; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; khiter_t __pyx_v_k; int __pyx_v_id; PyObject *__pyx_r = NULL; @@ -25968,10 +27927,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6__getitem__(st PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; char const *__pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[0], 1599, 0, __PYX_ERR(0, 1599, __pyx_L1_error)); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 1756, 0, __PYX_ERR(0, 1756, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1600 + /* "pysam/libcbcf.pyx":1757 * * def __getitem__(self, key): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -25981,7 +27942,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6__getitem__(st __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1603 + /* "pysam/libcbcf.pyx":1760 * cdef int index * * if isinstance(key, int): # <<<<<<<<<<<<<< @@ -25992,17 +27953,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6__getitem__(st __pyx_t_3 = (__pyx_t_2 != 0); if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":1604 + /* "pysam/libcbcf.pyx":1761 * * if isinstance(key, int): * index = key # <<<<<<<<<<<<<< * if index < 0 or index >= hdr.n[BCF_DT_CTG]: * raise IndexError('invalid contig index') */ - __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_v_key); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1604, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_v_key); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1761, __pyx_L1_error) __pyx_v_index = __pyx_t_4; - /* "pysam/libcbcf.pyx":1605 + /* "pysam/libcbcf.pyx":1762 * if isinstance(key, int): * index = key * if index < 0 or index >= hdr.n[BCF_DT_CTG]: # <<<<<<<<<<<<<< @@ -26020,20 +27981,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6__getitem__(st __pyx_L5_bool_binop_done:; if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":1606 + /* "pysam/libcbcf.pyx":1763 * index = key * if index < 0 or index >= hdr.n[BCF_DT_CTG]: * raise IndexError('invalid contig index') # <<<<<<<<<<<<<< * return makeVariantContig(self.header, index) * */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__90, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1606, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__88, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1763, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 1606, __pyx_L1_error) + __PYX_ERR(0, 1763, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1605 + /* "pysam/libcbcf.pyx":1762 * if isinstance(key, int): * index = key * if index < 0 or index >= hdr.n[BCF_DT_CTG]: # <<<<<<<<<<<<<< @@ -26042,7 +28003,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6__getitem__(st */ } - /* "pysam/libcbcf.pyx":1607 + /* "pysam/libcbcf.pyx":1764 * if index < 0 or index >= hdr.n[BCF_DT_CTG]: * raise IndexError('invalid contig index') * return makeVariantContig(self.header, index) # <<<<<<<<<<<<<< @@ -26052,14 +28013,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6__getitem__(st __Pyx_XDECREF(__pyx_r); __pyx_t_5 = ((PyObject *)__pyx_v_self->header); __Pyx_INCREF(__pyx_t_5); - __pyx_t_6 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantContig(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_5), __pyx_v_index)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1607, __pyx_L1_error) + __pyx_t_6 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantContig(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_5), __pyx_v_index)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1764, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1603 + /* "pysam/libcbcf.pyx":1760 * cdef int index * * if isinstance(key, int): # <<<<<<<<<<<<<< @@ -26068,75 +28029,121 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6__getitem__(st */ } - /* "pysam/libcbcf.pyx":1609 + /* "pysam/libcbcf.pyx":1766 * return makeVariantContig(self.header, index) * * cdef vdict_t *d = hdr.dict[BCF_DT_CTG] # <<<<<<<<<<<<<< - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef khiter_t k = kh_get_vdict(d, bkey) */ __pyx_v_d = ((vdict_t *)(__pyx_v_hdr->dict[BCF_DT_CTG])); - /* "pysam/libcbcf.pyx":1610 + /* "pysam/libcbcf.pyx":1767 * * cdef vdict_t *d = hdr.dict[BCF_DT_CTG] - * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * cdef khiter_t k = kh_get_vdict(d, bkey) * */ - __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1610, __pyx_L1_error) + __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1767, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_v_bkey = ((PyObject*)__pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libcbcf.pyx":1611 + /* "pysam/libcbcf.pyx":1768 * cdef vdict_t *d = hdr.dict[BCF_DT_CTG] - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef khiter_t k = kh_get_vdict(d, bkey) # <<<<<<<<<<<<<< * * if k == kh_end(d): */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 1611, __pyx_L1_error) + __PYX_ERR(0, 1768, __pyx_L1_error) } - __pyx_t_7 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 1611, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 1768, __pyx_L1_error) __pyx_v_k = kh_get_vdict(__pyx_v_d, __pyx_t_7); - /* "pysam/libcbcf.pyx":1613 + /* "pysam/libcbcf.pyx":1770 * cdef khiter_t k = kh_get_vdict(d, bkey) * * if k == kh_end(d): # <<<<<<<<<<<<<< - * raise KeyError('invalid contig') + * raise KeyError('invalid contig: {}'.format(key)) * */ __pyx_t_3 = ((__pyx_v_k == kh_end(__pyx_v_d)) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":1614 + /* "pysam/libcbcf.pyx":1771 * * if k == kh_end(d): - * raise KeyError('invalid contig') # <<<<<<<<<<<<<< + * raise KeyError('invalid contig: {}'.format(key)) # <<<<<<<<<<<<<< * * cdef int id = kh_val_vdict(d, k).id */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__91, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1614, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_contig, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1771, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (!__pyx_t_8) { + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_key); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1771, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_key}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1771, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_key}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1771, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1771, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_key); + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1771, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1771, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 1614, __pyx_L1_error) + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 1771, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1613 + /* "pysam/libcbcf.pyx":1770 * cdef khiter_t k = kh_get_vdict(d, bkey) * * if k == kh_end(d): # <<<<<<<<<<<<<< - * raise KeyError('invalid contig') + * raise KeyError('invalid contig: {}'.format(key)) * */ } - /* "pysam/libcbcf.pyx":1616 - * raise KeyError('invalid contig') + /* "pysam/libcbcf.pyx":1773 + * raise KeyError('invalid contig: {}'.format(key)) * * cdef int id = kh_val_vdict(d, k).id # <<<<<<<<<<<<<< * @@ -26145,7 +28152,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6__getitem__(st __pyx_t_4 = kh_val(__pyx_v_d, __pyx_v_k).id; __pyx_v_id = __pyx_t_4; - /* "pysam/libcbcf.pyx":1618 + /* "pysam/libcbcf.pyx":1775 * cdef int id = kh_val_vdict(d, k).id * * return makeVariantContig(self.header, id) # <<<<<<<<<<<<<< @@ -26153,16 +28160,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6__getitem__(st * def remove_header(self, key): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_6 = ((PyObject *)__pyx_v_self->header); - __Pyx_INCREF(__pyx_t_6); - __pyx_t_5 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantContig(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_6), __pyx_v_id)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; + __pyx_t_5 = ((PyObject *)__pyx_v_self->header); + __Pyx_INCREF(__pyx_t_5); + __pyx_t_6 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantContig(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_5), __pyx_v_id)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1775, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1599 + /* "pysam/libcbcf.pyx":1756 * return hdr.n[BCF_DT_CTG] != 0 * * def __getitem__(self, key): # <<<<<<<<<<<<<< @@ -26174,6 +28181,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6__getitem__(st __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderContigs.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -26184,7 +28193,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6__getitem__(st return __pyx_r; } -/* "pysam/libcbcf.pyx":1620 +/* "pysam/libcbcf.pyx":1777 * return makeVariantContig(self.header, id) * * def remove_header(self, key): # <<<<<<<<<<<<<< @@ -26209,7 +28218,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantHeaderContigs_9remove_header( static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_8remove_header(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_v_self, PyObject *__pyx_v_key) { bcf_hdr_t *__pyx_v_hdr; int __pyx_v_index; - char const *__pyx_v_bkey; + char const *__pyx_v_ckey; vdict_t *__pyx_v_d; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations @@ -26222,22 +28231,25 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_8remove_header( Py_ssize_t __pyx_t_6; char const *__pyx_t_7; char const *__pyx_t_8; - char const *__pyx_t_9; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + char const *__pyx_t_12; __Pyx_RefNannySetupContext("remove_header", 0); - __Pyx_TraceCall("remove_header", __pyx_f[0], 1620, 0, __PYX_ERR(0, 1620, __pyx_L1_error)); + __Pyx_TraceCall("remove_header", __pyx_f[0], 1777, 0, __PYX_ERR(0, 1777, __pyx_L1_error)); __Pyx_INCREF(__pyx_v_key); - /* "pysam/libcbcf.pyx":1621 + /* "pysam/libcbcf.pyx":1778 * * def remove_header(self, key): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< * cdef int index - * cdef const char *bkey + * cdef const char *ckey */ __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1627 + /* "pysam/libcbcf.pyx":1784 * cdef khiter_t k * * if isinstance(key, int): # <<<<<<<<<<<<<< @@ -26248,22 +28260,22 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_8remove_header( __pyx_t_3 = (__pyx_t_2 != 0); if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":1628 + /* "pysam/libcbcf.pyx":1785 * * if isinstance(key, int): * index = key # <<<<<<<<<<<<<< * if index < 0 or index >= hdr.n[BCF_DT_CTG]: * raise IndexError('invalid contig index') */ - __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_v_key); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1628, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_v_key); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1785, __pyx_L1_error) __pyx_v_index = __pyx_t_4; - /* "pysam/libcbcf.pyx":1629 + /* "pysam/libcbcf.pyx":1786 * if isinstance(key, int): * index = key * if index < 0 or index >= hdr.n[BCF_DT_CTG]: # <<<<<<<<<<<<<< * raise IndexError('invalid contig index') - * bkey = hdr.id[BCF_DT_CTG][self.id].key + * ckey = hdr.id[BCF_DT_CTG][self.id].key */ __pyx_t_2 = ((__pyx_v_index < 0) != 0); if (!__pyx_t_2) { @@ -26276,43 +28288,43 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_8remove_header( __pyx_L5_bool_binop_done:; if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":1630 + /* "pysam/libcbcf.pyx":1787 * index = key * if index < 0 or index >= hdr.n[BCF_DT_CTG]: * raise IndexError('invalid contig index') # <<<<<<<<<<<<<< - * bkey = hdr.id[BCF_DT_CTG][self.id].key + * ckey = hdr.id[BCF_DT_CTG][self.id].key * else: */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__92, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1630, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__89, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1787, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 1630, __pyx_L1_error) + __PYX_ERR(0, 1787, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1629 + /* "pysam/libcbcf.pyx":1786 * if isinstance(key, int): * index = key * if index < 0 or index >= hdr.n[BCF_DT_CTG]: # <<<<<<<<<<<<<< * raise IndexError('invalid contig index') - * bkey = hdr.id[BCF_DT_CTG][self.id].key + * ckey = hdr.id[BCF_DT_CTG][self.id].key */ } - /* "pysam/libcbcf.pyx":1631 + /* "pysam/libcbcf.pyx":1788 * if index < 0 or index >= hdr.n[BCF_DT_CTG]: * raise IndexError('invalid contig index') - * bkey = hdr.id[BCF_DT_CTG][self.id].key # <<<<<<<<<<<<<< + * ckey = hdr.id[BCF_DT_CTG][self.id].key # <<<<<<<<<<<<<< * else: * d = hdr.dict[BCF_DT_CTG] */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1631, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1788, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 1631, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 1788, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_7 = ((__pyx_v_hdr->id[BCF_DT_CTG])[__pyx_t_6]).key; - __pyx_v_bkey = __pyx_t_7; + __pyx_v_ckey = __pyx_t_7; - /* "pysam/libcbcf.pyx":1627 + /* "pysam/libcbcf.pyx":1784 * cdef khiter_t k * * if isinstance(key, int): # <<<<<<<<<<<<<< @@ -26322,8 +28334,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_8remove_header( goto __pyx_L3; } - /* "pysam/libcbcf.pyx":1633 - * bkey = hdr.id[BCF_DT_CTG][self.id].key + /* "pysam/libcbcf.pyx":1790 + * ckey = hdr.id[BCF_DT_CTG][self.id].key * else: * d = hdr.dict[BCF_DT_CTG] # <<<<<<<<<<<<<< * key = force_bytes(key) @@ -26332,73 +28344,119 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_8remove_header( /*else*/ { __pyx_v_d = ((vdict_t *)(__pyx_v_hdr->dict[BCF_DT_CTG])); - /* "pysam/libcbcf.pyx":1634 + /* "pysam/libcbcf.pyx":1791 * else: * d = hdr.dict[BCF_DT_CTG] * key = force_bytes(key) # <<<<<<<<<<<<<< * if kh_get_vdict(d, key) == kh_end(d): - * raise KeyError('invalid contig') + * raise KeyError('invalid contig: {}'.format(key)) */ - __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1634, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1791, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcbcf.pyx":1635 + /* "pysam/libcbcf.pyx":1792 * d = hdr.dict[BCF_DT_CTG] * key = force_bytes(key) * if kh_get_vdict(d, key) == kh_end(d): # <<<<<<<<<<<<<< - * raise KeyError('invalid contig') - * bkey = key + * raise KeyError('invalid contig: {}'.format(key)) + * ckey = key */ - __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_key); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 1635, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_key); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 1792, __pyx_L1_error) __pyx_t_3 = ((kh_get_vdict(__pyx_v_d, __pyx_t_8) == kh_end(__pyx_v_d)) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":1636 + /* "pysam/libcbcf.pyx":1793 * key = force_bytes(key) * if kh_get_vdict(d, key) == kh_end(d): - * raise KeyError('invalid contig') # <<<<<<<<<<<<<< - * bkey = key + * raise KeyError('invalid contig: {}'.format(key)) # <<<<<<<<<<<<<< + * ckey = key * */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__93, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1636, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_contig, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + if (!__pyx_t_10) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_key); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_key); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1793, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 1636, __pyx_L1_error) + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 1793, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1635 + /* "pysam/libcbcf.pyx":1792 * d = hdr.dict[BCF_DT_CTG] * key = force_bytes(key) * if kh_get_vdict(d, key) == kh_end(d): # <<<<<<<<<<<<<< - * raise KeyError('invalid contig') - * bkey = key + * raise KeyError('invalid contig: {}'.format(key)) + * ckey = key */ } - /* "pysam/libcbcf.pyx":1637 + /* "pysam/libcbcf.pyx":1794 * if kh_get_vdict(d, key) == kh_end(d): - * raise KeyError('invalid contig') - * bkey = key # <<<<<<<<<<<<<< + * raise KeyError('invalid contig: {}'.format(key)) + * ckey = key # <<<<<<<<<<<<<< * - * bcf_hdr_remove(hdr, BCF_HL_CTG, bkey) + * bcf_hdr_remove(hdr, BCF_HL_CTG, ckey) */ - __pyx_t_9 = __Pyx_PyObject_AsString(__pyx_v_key); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 1637, __pyx_L1_error) - __pyx_v_bkey = __pyx_t_9; + __pyx_t_12 = __Pyx_PyObject_AsString(__pyx_v_key); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 1794, __pyx_L1_error) + __pyx_v_ckey = __pyx_t_12; } __pyx_L3:; - /* "pysam/libcbcf.pyx":1639 - * bkey = key + /* "pysam/libcbcf.pyx":1796 + * ckey = key * - * bcf_hdr_remove(hdr, BCF_HL_CTG, bkey) # <<<<<<<<<<<<<< + * bcf_hdr_remove(hdr, BCF_HL_CTG, ckey) # <<<<<<<<<<<<<< * * def clear_header(self): */ - bcf_hdr_remove(__pyx_v_hdr, BCF_HL_CTG, __pyx_v_bkey); + bcf_hdr_remove(__pyx_v_hdr, BCF_HL_CTG, __pyx_v_ckey); - /* "pysam/libcbcf.pyx":1620 + /* "pysam/libcbcf.pyx":1777 * return makeVariantContig(self.header, id) * * def remove_header(self, key): # <<<<<<<<<<<<<< @@ -26411,6 +28469,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_8remove_header( goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderContigs.remove_header", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -26421,8 +28482,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_8remove_header( return __pyx_r; } -/* "pysam/libcbcf.pyx":1641 - * bcf_hdr_remove(hdr, BCF_HL_CTG, bkey) +/* "pysam/libcbcf.pyx":1798 + * bcf_hdr_remove(hdr, BCF_HL_CTG, ckey) * * def clear_header(self): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.header.ptr @@ -26450,9 +28511,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_10clear_header( __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; __Pyx_RefNannySetupContext("clear_header", 0); - __Pyx_TraceCall("clear_header", __pyx_f[0], 1641, 0, __PYX_ERR(0, 1641, __pyx_L1_error)); + __Pyx_TraceCall("clear_header", __pyx_f[0], 1798, 0, __PYX_ERR(0, 1798, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1642 + /* "pysam/libcbcf.pyx":1799 * * def clear_header(self): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -26462,7 +28523,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_10clear_header( __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1643 + /* "pysam/libcbcf.pyx":1800 * def clear_header(self): * cdef bcf_hdr_t *hdr = self.header.ptr * bcf_hdr_remove(hdr, BCF_HL_CTG, NULL) # <<<<<<<<<<<<<< @@ -26471,8 +28532,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_10clear_header( */ bcf_hdr_remove(__pyx_v_hdr, BCF_HL_CTG, NULL); - /* "pysam/libcbcf.pyx":1641 - * bcf_hdr_remove(hdr, BCF_HL_CTG, bkey) + /* "pysam/libcbcf.pyx":1798 + * bcf_hdr_remove(hdr, BCF_HL_CTG, ckey) * * def clear_header(self): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.header.ptr @@ -26493,7 +28554,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_10clear_header( } static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_14generator7(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1646 +/* "pysam/libcbcf.pyx":1803 * #bcf_hdr_sync(hdr) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -26523,7 +28584,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_12__iter__(stru if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_17___iter__ *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1646, __pyx_L1_error) + __PYX_ERR(0, 1803, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -26531,7 +28592,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_12__iter__(stru __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_14generator7, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantHeaderContigs___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1646, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_14generator7, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantHeaderContigs___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1803, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -26559,7 +28620,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_14generator7(__ PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1646, 0, __PYX_ERR(0, 1646, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 1803, 0, __PYX_ERR(0, 1803, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -26569,9 +28630,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_14generator7(__ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1646, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1803, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1647 + /* "pysam/libcbcf.pyx":1804 * * def __iter__(self): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -26581,7 +28642,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_14generator7(__ __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->header->ptr; __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1648 + /* "pysam/libcbcf.pyx":1805 * def __iter__(self): * cdef bcf_hdr_t *hdr = self.header.ptr * cdef vdict_t *d = hdr.dict[BCF_DT_CTG] # <<<<<<<<<<<<<< @@ -26590,7 +28651,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_14generator7(__ */ __pyx_cur_scope->__pyx_v_d = ((vdict_t *)(__pyx_cur_scope->__pyx_v_hdr->dict[BCF_DT_CTG])); - /* "pysam/libcbcf.pyx":1649 + /* "pysam/libcbcf.pyx":1806 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef vdict_t *d = hdr.dict[BCF_DT_CTG] * cdef uint32_t n = kh_size(d) # <<<<<<<<<<<<<< @@ -26599,7 +28660,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_14generator7(__ */ __pyx_cur_scope->__pyx_v_n = kh_size(__pyx_cur_scope->__pyx_v_d); - /* "pysam/libcbcf.pyx":1651 + /* "pysam/libcbcf.pyx":1808 * cdef uint32_t n = kh_size(d) * * assert n == hdr.n[BCF_DT_CTG] # <<<<<<<<<<<<<< @@ -26610,12 +28671,12 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_14generator7(__ if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((__pyx_cur_scope->__pyx_v_n == (__pyx_cur_scope->__pyx_v_hdr->n[BCF_DT_CTG])) != 0))) { PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 1651, __pyx_L1_error) + __PYX_ERR(0, 1808, __pyx_L1_error) } } #endif - /* "pysam/libcbcf.pyx":1653 + /* "pysam/libcbcf.pyx":1810 * assert n == hdr.n[BCF_DT_CTG] * * for i in range(n): # <<<<<<<<<<<<<< @@ -26627,14 +28688,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_14generator7(__ for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_4; - /* "pysam/libcbcf.pyx":1654 + /* "pysam/libcbcf.pyx":1811 * * for i in range(n): * yield bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, i)) # <<<<<<<<<<<<<< * * def get(self, key, default=None): */ - __pyx_t_5 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_id2name(__pyx_cur_scope->__pyx_v_hdr, __pyx_cur_scope->__pyx_v_i)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1654, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_id2name(__pyx_cur_scope->__pyx_v_hdr, __pyx_cur_scope->__pyx_v_i)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1811, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; @@ -26652,11 +28713,11 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_14generator7(__ __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1654, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1811, __pyx_L1_error) } CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1646 + /* "pysam/libcbcf.pyx":1803 * #bcf_hdr_sync(hdr) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -26680,7 +28741,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_14generator7(__ return __pyx_r; } -/* "pysam/libcbcf.pyx":1656 +/* "pysam/libcbcf.pyx":1813 * yield bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, i)) * * def get(self, key, default=None): # <<<<<<<<<<<<<< @@ -26725,7 +28786,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantHeaderContigs_16get(PyObject } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 1656, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 1813, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -26741,7 +28802,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantHeaderContigs_16get(PyObject } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1656, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1813, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderContigs.get", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -26766,9 +28827,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_15get(struct __ PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("get", 0); - __Pyx_TraceCall("get", __pyx_f[0], 1656, 0, __PYX_ERR(0, 1656, __pyx_L1_error)); + __Pyx_TraceCall("get", __pyx_f[0], 1813, 0, __PYX_ERR(0, 1813, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1658 + /* "pysam/libcbcf.pyx":1815 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -26784,7 +28845,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_15get(struct __ __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "pysam/libcbcf.pyx":1659 + /* "pysam/libcbcf.pyx":1816 * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: * return self[key] # <<<<<<<<<<<<<< @@ -26792,13 +28853,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_15get(struct __ * return default */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1659, __pyx_L3_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1816, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L7_try_return; - /* "pysam/libcbcf.pyx":1658 + /* "pysam/libcbcf.pyx":1815 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -26809,7 +28870,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_15get(struct __ __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1660 + /* "pysam/libcbcf.pyx":1817 * try: * return self[key] * except KeyError: # <<<<<<<<<<<<<< @@ -26819,12 +28880,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_15get(struct __ __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); if (__pyx_t_5) { __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderContigs.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1660, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1817, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcbcf.pyx":1661 + /* "pysam/libcbcf.pyx":1818 * return self[key] * except KeyError: * return default # <<<<<<<<<<<<<< @@ -26842,7 +28903,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_15get(struct __ goto __pyx_L5_except_error; __pyx_L5_except_error:; - /* "pysam/libcbcf.pyx":1658 + /* "pysam/libcbcf.pyx":1815 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -26868,7 +28929,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_15get(struct __ goto __pyx_L0; } - /* "pysam/libcbcf.pyx":1656 + /* "pysam/libcbcf.pyx":1813 * yield bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, i)) * * def get(self, key, default=None): # <<<<<<<<<<<<<< @@ -26890,7 +28951,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_15get(struct __ return __pyx_r; } -/* "pysam/libcbcf.pyx":1663 +/* "pysam/libcbcf.pyx":1820 * return default * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -26923,9 +28984,9 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_17__contains__(struct PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("__contains__", 0); - __Pyx_TraceCall("__contains__", __pyx_f[0], 1663, 0, __PYX_ERR(0, 1663, __pyx_L1_error)); + __Pyx_TraceCall("__contains__", __pyx_f[0], 1820, 0, __PYX_ERR(0, 1820, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1664 + /* "pysam/libcbcf.pyx":1821 * * def __contains__(self, key): * try: # <<<<<<<<<<<<<< @@ -26941,18 +29002,18 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_17__contains__(struct __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "pysam/libcbcf.pyx":1665 + /* "pysam/libcbcf.pyx":1822 * def __contains__(self, key): * try: * self[key] # <<<<<<<<<<<<<< * except KeyError: * return False */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1665, __pyx_L3_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1822, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1664 + /* "pysam/libcbcf.pyx":1821 * * def __contains__(self, key): * try: # <<<<<<<<<<<<<< @@ -26961,7 +29022,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_17__contains__(struct */ } - /* "pysam/libcbcf.pyx":1669 + /* "pysam/libcbcf.pyx":1826 * return False * else: * return True # <<<<<<<<<<<<<< @@ -26975,7 +29036,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_17__contains__(struct __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1666 + /* "pysam/libcbcf.pyx":1823 * try: * self[key] * except KeyError: # <<<<<<<<<<<<<< @@ -26985,12 +29046,12 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_17__contains__(struct __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); if (__pyx_t_5) { __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderContigs.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1666, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 1823, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcbcf.pyx":1667 + /* "pysam/libcbcf.pyx":1824 * self[key] * except KeyError: * return False # <<<<<<<<<<<<<< @@ -27006,7 +29067,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_17__contains__(struct goto __pyx_L5_except_error; __pyx_L5_except_error:; - /* "pysam/libcbcf.pyx":1664 + /* "pysam/libcbcf.pyx":1821 * * def __contains__(self, key): * try: # <<<<<<<<<<<<<< @@ -27026,7 +29087,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_17__contains__(struct goto __pyx_L0; } - /* "pysam/libcbcf.pyx":1663 + /* "pysam/libcbcf.pyx":1820 * return default * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -27047,7 +29108,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_17__contains__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1671 +/* "pysam/libcbcf.pyx":1828 * return True * * def iterkeys(self): # <<<<<<<<<<<<<< @@ -27075,9 +29136,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_19iterkeys(stru __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("iterkeys", 0); - __Pyx_TraceCall("iterkeys", __pyx_f[0], 1671, 0, __PYX_ERR(0, 1671, __pyx_L1_error)); + __Pyx_TraceCall("iterkeys", __pyx_f[0], 1828, 0, __PYX_ERR(0, 1828, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1673 + /* "pysam/libcbcf.pyx":1830 * def iterkeys(self): * """D.iterkeys() -> an iterator over the keys of D""" * return iter(self) # <<<<<<<<<<<<<< @@ -27085,13 +29146,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_19iterkeys(stru * def itervalues(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1673, __pyx_L1_error) + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1830, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1671 + /* "pysam/libcbcf.pyx":1828 * return True * * def iterkeys(self): # <<<<<<<<<<<<<< @@ -27112,7 +29173,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_19iterkeys(stru } static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_23generator8(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1675 +/* "pysam/libcbcf.pyx":1832 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -27143,7 +29204,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_21itervalues(st if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_18_itervalues *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1675, __pyx_L1_error) + __PYX_ERR(0, 1832, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -27151,7 +29212,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_21itervalues(st __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_23generator8, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantHeaderContigs_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1675, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_23generator8, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantHeaderContigs_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1832, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -27178,7 +29239,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_23generator8(__ PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("itervalues", 0); - __Pyx_TraceCall("itervalues", __pyx_f[0], 1675, 0, __PYX_ERR(0, 1675, __pyx_L1_error)); + __Pyx_TraceCall("itervalues", __pyx_f[0], 1832, 0, __PYX_ERR(0, 1832, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -27188,9 +29249,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_23generator8(__ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1675, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1832, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1677 + /* "pysam/libcbcf.pyx":1834 * def itervalues(self): * """D.itervalues() -> an iterator over the values of D""" * for key in self: # <<<<<<<<<<<<<< @@ -27201,26 +29262,26 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_23generator8(__ __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1677, __pyx_L1_error) + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1834, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1677, __pyx_L1_error) + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1834, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_3)) { if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1677, __pyx_L1_error) + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1834, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1677, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1834, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } else { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1677, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1834, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1677, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1834, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } @@ -27230,7 +29291,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_23generator8(__ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1677, __pyx_L1_error) + else __PYX_ERR(0, 1834, __pyx_L1_error) } break; } @@ -27241,14 +29302,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_23generator8(__ __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1678 + /* "pysam/libcbcf.pyx":1835 * """D.itervalues() -> an iterator over the values of D""" * for key in self: * yield self[key] # <<<<<<<<<<<<<< * * def iteritems(self): */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1678, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1835, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; @@ -27269,9 +29330,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_23generator8(__ __Pyx_XGOTREF(__pyx_t_1); __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1678, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1835, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1677 + /* "pysam/libcbcf.pyx":1834 * def itervalues(self): * """D.itervalues() -> an iterator over the values of D""" * for key in self: # <<<<<<<<<<<<<< @@ -27282,7 +29343,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_23generator8(__ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1675 + /* "pysam/libcbcf.pyx":1832 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -27308,7 +29369,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_23generator8(__ } static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_26generator9(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1680 +/* "pysam/libcbcf.pyx":1837 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -27339,7 +29400,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_24iteritems(str if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_19_iteritems *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1680, __pyx_L1_error) + __PYX_ERR(0, 1837, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -27347,7 +29408,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_24iteritems(str __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_26generator9, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantHeaderContigs_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1680, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_26generator9, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantHeaderContigs_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1837, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -27375,7 +29436,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_26generator9(__ PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("iteritems", 0); - __Pyx_TraceCall("iteritems", __pyx_f[0], 1680, 0, __PYX_ERR(0, 1680, __pyx_L1_error)); + __Pyx_TraceCall("iteritems", __pyx_f[0], 1837, 0, __PYX_ERR(0, 1837, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -27385,9 +29446,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_26generator9(__ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1680, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1837, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1682 + /* "pysam/libcbcf.pyx":1839 * def iteritems(self): * """D.iteritems() -> an iterator over the (key, value) items of D""" * for key in self: # <<<<<<<<<<<<<< @@ -27398,26 +29459,26 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_26generator9(__ __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1682, __pyx_L1_error) + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1839, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1682, __pyx_L1_error) + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1839, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_3)) { if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1682, __pyx_L1_error) + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1839, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1682, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1839, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } else { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1682, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1839, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1682, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1839, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } @@ -27427,7 +29488,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_26generator9(__ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1682, __pyx_L1_error) + else __PYX_ERR(0, 1839, __pyx_L1_error) } break; } @@ -27438,16 +29499,16 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_26generator9(__ __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1683 + /* "pysam/libcbcf.pyx":1840 * """D.iteritems() -> an iterator over the (key, value) items of D""" * for key in self: * yield (key, self[key]) # <<<<<<<<<<<<<< * * def keys(self): */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1683, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1840, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1683, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1840, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); @@ -27474,9 +29535,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_26generator9(__ __Pyx_XGOTREF(__pyx_t_1); __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1683, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1840, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1682 + /* "pysam/libcbcf.pyx":1839 * def iteritems(self): * """D.iteritems() -> an iterator over the (key, value) items of D""" * for key in self: # <<<<<<<<<<<<<< @@ -27487,7 +29548,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_26generator9(__ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1680 + /* "pysam/libcbcf.pyx":1837 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -27513,7 +29574,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderContigs_26generator9(__ return __pyx_r; } -/* "pysam/libcbcf.pyx":1685 +/* "pysam/libcbcf.pyx":1842 * yield (key, self[key]) * * def keys(self): # <<<<<<<<<<<<<< @@ -27541,9 +29602,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_27keys(struct _ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("keys", 0); - __Pyx_TraceCall("keys", __pyx_f[0], 1685, 0, __PYX_ERR(0, 1685, __pyx_L1_error)); + __Pyx_TraceCall("keys", __pyx_f[0], 1842, 0, __PYX_ERR(0, 1842, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1687 + /* "pysam/libcbcf.pyx":1844 * def keys(self): * """D.keys() -> list of D's keys""" * return list(self) # <<<<<<<<<<<<<< @@ -27551,13 +29612,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_27keys(struct _ * def items(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1687, __pyx_L1_error) + __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1844, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1685 + /* "pysam/libcbcf.pyx":1842 * yield (key, self[key]) * * def keys(self): # <<<<<<<<<<<<<< @@ -27577,7 +29638,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_27keys(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":1689 +/* "pysam/libcbcf.pyx":1846 * return list(self) * * def items(self): # <<<<<<<<<<<<<< @@ -27607,9 +29668,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_29items(struct PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("items", 0); - __Pyx_TraceCall("items", __pyx_f[0], 1689, 0, __PYX_ERR(0, 1689, __pyx_L1_error)); + __Pyx_TraceCall("items", __pyx_f[0], 1846, 0, __PYX_ERR(0, 1846, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1691 + /* "pysam/libcbcf.pyx":1848 * def items(self): * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" * return list(self.iteritems()) # <<<<<<<<<<<<<< @@ -27617,7 +29678,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_29items(struct * def values(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1691, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1848, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -27630,21 +29691,21 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_29items(struct } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1691, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1848, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1691, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1848, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1691, __pyx_L1_error) + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1848, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1689 + /* "pysam/libcbcf.pyx":1846 * return list(self) * * def items(self): # <<<<<<<<<<<<<< @@ -27666,7 +29727,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_29items(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1693 +/* "pysam/libcbcf.pyx":1850 * return list(self.iteritems()) * * def values(self): # <<<<<<<<<<<<<< @@ -27696,9 +29757,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_31values(struct PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("values", 0); - __Pyx_TraceCall("values", __pyx_f[0], 1693, 0, __PYX_ERR(0, 1693, __pyx_L1_error)); + __Pyx_TraceCall("values", __pyx_f[0], 1850, 0, __PYX_ERR(0, 1850, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1695 + /* "pysam/libcbcf.pyx":1852 * def values(self): * """D.values() -> list of D's values""" * return list(self.itervalues()) # <<<<<<<<<<<<<< @@ -27706,7 +29767,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_31values(struct * # Mappings are not hashable by default, but subclasses can change this */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1695, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1852, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -27719,21 +29780,21 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_31values(struct } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1695, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1852, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1695, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1852, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1695, __pyx_L1_error) + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1852, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1693 + /* "pysam/libcbcf.pyx":1850 * return list(self.iteritems()) * * def values(self): # <<<<<<<<<<<<<< @@ -27755,7 +29816,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_31values(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1702 +/* "pysam/libcbcf.pyx":1859 * #TODO: implement __richcmp__ * * def add(self, id, **kwargs): # <<<<<<<<<<<<<< @@ -27793,7 +29854,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantHeaderContigs_34add(PyObject else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "add") < 0)) __PYX_ERR(0, 1702, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "add") < 0)) __PYX_ERR(0, 1859, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -27804,7 +29865,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantHeaderContigs_34add(PyObject } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("add", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1702, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("add", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1859, __pyx_L3_error) __pyx_L3_error:; __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderContigs.add", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -27831,27 +29892,27 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_33add(struct __ PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; __Pyx_RefNannySetupContext("add", 0); - __Pyx_TraceCall("add", __pyx_f[0], 1702, 0, __PYX_ERR(0, 1702, __pyx_L1_error)); + __Pyx_TraceCall("add", __pyx_f[0], 1859, 0, __PYX_ERR(0, 1859, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1704 + /* "pysam/libcbcf.pyx":1861 * def add(self, id, **kwargs): * """Add a new contig record""" * if id in self: # <<<<<<<<<<<<<< * raise ValueError('Header already exists for contig {}'.format(id)) * */ - __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_id, ((PyObject *)__pyx_v_self), Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1704, __pyx_L1_error) + __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_id, ((PyObject *)__pyx_v_self), Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1861, __pyx_L1_error) __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1705 + /* "pysam/libcbcf.pyx":1862 * """Add a new contig record""" * if id in self: * raise ValueError('Header already exists for contig {}'.format(id)) # <<<<<<<<<<<<<< * - * items = [('ID', id)] + kwargs.items() + * items = [('ID', id)] */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Header_already_exists_for_contig, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1705, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Header_already_exists_for_contig, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1862, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { @@ -27864,13 +29925,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_33add(struct __ } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1705, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1862, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_id}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1705, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1862, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -27878,32 +29939,32 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_33add(struct __ #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_id}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1705, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1862, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1705, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1862, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_INCREF(__pyx_v_id); __Pyx_GIVEREF(__pyx_v_id); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_id); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1705, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1862, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1705, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1862, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1705, __pyx_L1_error) + __PYX_ERR(0, 1862, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1704 + /* "pysam/libcbcf.pyx":1861 * def add(self, id, **kwargs): * """Add a new contig record""" * if id in self: # <<<<<<<<<<<<<< @@ -27912,14 +29973,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_33add(struct __ */ } - /* "pysam/libcbcf.pyx":1707 + /* "pysam/libcbcf.pyx":1864 * raise ValueError('Header already exists for contig {}'.format(id)) * - * items = [('ID', id)] + kwargs.items() # <<<<<<<<<<<<<< + * items = [('ID', id)] # <<<<<<<<<<<<<< + * items += kwargs.items() * self.header.add_meta('contig', items=items) - * */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1707, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1864, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_n_s_ID); __Pyx_GIVEREF(__pyx_n_s_ID); @@ -27927,39 +29988,48 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_33add(struct __ __Pyx_INCREF(__pyx_v_id); __Pyx_GIVEREF(__pyx_v_id); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_id); - __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1707, __pyx_L1_error) + __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1864, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyDict_Items(__pyx_v_kwargs); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1707, __pyx_L1_error) + __pyx_v_items = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":1865 + * + * items = [('ID', id)] + * items += kwargs.items() # <<<<<<<<<<<<<< + * self.header.add_meta('contig', items=items) + * + */ + __pyx_t_3 = __Pyx_PyDict_Items(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1865, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_items, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1865, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1707, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_items = __pyx_t_6; - __pyx_t_6 = 0; + __Pyx_DECREF_SET(__pyx_v_items, __pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1708 - * - * items = [('ID', id)] + kwargs.items() + /* "pysam/libcbcf.pyx":1866 + * items = [('ID', id)] + * items += kwargs.items() * self.header.add_meta('contig', items=items) # <<<<<<<<<<<<<< * * */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_add_meta); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1708, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1708, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_add_meta); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1866, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_items, __pyx_v_items) < 0) __PYX_ERR(0, 1708, __pyx_L1_error) - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__94, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1708, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1866, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_items, __pyx_v_items) < 0) __PYX_ERR(0, 1866, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__90, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1866, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libcbcf.pyx":1702 + /* "pysam/libcbcf.pyx":1859 * #TODO: implement __richcmp__ * * def add(self, id, **kwargs): # <<<<<<<<<<<<<< @@ -27985,6 +30055,49 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_33add(struct __ return __pyx_r; } +/* "pysam/libcbcf.pxd":54 + * + * cdef class VariantHeaderContigs(object): + * cdef readonly VariantHeader header # <<<<<<<<<<<<<< + * + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantHeaderContigs_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantHeaderContigs_6header_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6header___get__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 54, 0, __PYX_ERR(1, 54, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); + __pyx_r = ((PyObject *)__pyx_v_self->header); + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderContigs.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef bint use_setstate @@ -28018,7 +30131,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_35__reduce_cyth PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -28027,7 +30140,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_35__reduce_cyth * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self->header)); @@ -28042,7 +30155,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_35__reduce_cyth * if _dict is not None: * state += (_dict,) */ - __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v__dict = __pyx_t_1; __pyx_t_1 = 0; @@ -28065,12 +30178,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_35__reduce_cyth * use_setstate = True * else: */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); @@ -28126,9 +30239,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_35__reduce_cyth * return __pyx_unpickle_VariantHeaderContigs, (type(self), 0x099fb99, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderCont); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderCont); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -28139,7 +30252,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_35__reduce_cyth __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); @@ -28172,9 +30285,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_35__reduce_cyth */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderCont); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderCont); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -28185,7 +30298,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_35__reduce_cyth __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); @@ -28247,15 +30360,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_37__setstate_cy __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 14, 0, __PYX_ERR(2, 14, __pyx_L1_error)); /* "(tree fragment)":15 * return __pyx_unpickle_VariantHeaderContigs, (type(self), 0x099fb99, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_VariantHeaderContigs__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderContigs__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderContigs__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -28280,7 +30393,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderContigs_37__setstate_cy return __pyx_r; } -/* "pysam/libcbcf.pyx":1711 +/* "pysam/libcbcf.pyx":1869 * * * cdef VariantHeaderContigs makeVariantHeaderContigs(VariantHeader header): # <<<<<<<<<<<<<< @@ -28297,33 +30410,33 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_f_5pysam_7li int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("makeVariantHeaderContigs", 0); - __Pyx_TraceCall("makeVariantHeaderContigs", __pyx_f[0], 1711, 0, __PYX_ERR(0, 1711, __pyx_L1_error)); + __Pyx_TraceCall("makeVariantHeaderContigs", __pyx_f[0], 1869, 0, __PYX_ERR(0, 1869, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1712 + /* "pysam/libcbcf.pyx":1870 * * cdef VariantHeaderContigs makeVariantHeaderContigs(VariantHeader header): * if not header: # <<<<<<<<<<<<<< * raise ValueError('invalid VariantHeader') * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1712, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1870, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1713 + /* "pysam/libcbcf.pyx":1871 * cdef VariantHeaderContigs makeVariantHeaderContigs(VariantHeader header): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * cdef VariantHeaderContigs contigs = VariantHeaderContigs.__new__(VariantHeaderContigs) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__95, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1713, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__91, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1871, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1713, __pyx_L1_error) + __PYX_ERR(0, 1871, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1712 + /* "pysam/libcbcf.pyx":1870 * * cdef VariantHeaderContigs makeVariantHeaderContigs(VariantHeader header): * if not header: # <<<<<<<<<<<<<< @@ -28332,19 +30445,19 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_f_5pysam_7li */ } - /* "pysam/libcbcf.pyx":1715 + /* "pysam/libcbcf.pyx":1873 * raise ValueError('invalid VariantHeader') * * cdef VariantHeaderContigs contigs = VariantHeaderContigs.__new__(VariantHeaderContigs) # <<<<<<<<<<<<<< * contigs.header = header * */ - __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantHeaderContigs(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderContigs), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1715, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantHeaderContigs(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderContigs), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1873, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_v_contigs = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":1716 + /* "pysam/libcbcf.pyx":1874 * * cdef VariantHeaderContigs contigs = VariantHeaderContigs.__new__(VariantHeaderContigs) * contigs.header = header # <<<<<<<<<<<<<< @@ -28357,7 +30470,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_f_5pysam_7li __Pyx_DECREF(((PyObject *)__pyx_v_contigs->header)); __pyx_v_contigs->header = __pyx_v_header; - /* "pysam/libcbcf.pyx":1718 + /* "pysam/libcbcf.pyx":1876 * contigs.header = header * * return contigs # <<<<<<<<<<<<<< @@ -28369,7 +30482,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_f_5pysam_7li __pyx_r = __pyx_v_contigs; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1711 + /* "pysam/libcbcf.pyx":1869 * * * cdef VariantHeaderContigs makeVariantHeaderContigs(VariantHeader header): # <<<<<<<<<<<<<< @@ -28390,7 +30503,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *__pyx_f_5pysam_7li return __pyx_r; } -/* "pysam/libcbcf.pyx":1723 +/* "pysam/libcbcf.pyx":1881 * cdef class VariantHeaderSamples(object): * """sequence of sample names from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -28424,22 +30537,22 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples___init__(CYTHON_UNUSE __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1723, 0, __PYX_ERR(0, 1723, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 1881, 0, __PYX_ERR(0, 1881, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1724 + /* "pysam/libcbcf.pyx":1882 * """sequence of sample names from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__96, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1724, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__92, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1882, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1724, __pyx_L1_error) + __PYX_ERR(0, 1882, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1723 + /* "pysam/libcbcf.pyx":1881 * cdef class VariantHeaderSamples(object): * """sequence of sample names from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -28457,7 +30570,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples___init__(CYTHON_UNUSE return __pyx_r; } -/* "pysam/libcbcf.pyx":1726 +/* "pysam/libcbcf.pyx":1884 * raise TypeError('this class cannot be instantiated from Python') * * def __len__(self): # <<<<<<<<<<<<<< @@ -28483,9 +30596,9 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_2__len__(struc __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[0], 1726, 0, __PYX_ERR(0, 1726, __pyx_L1_error)); + __Pyx_TraceCall("__len__", __pyx_f[0], 1884, 0, __PYX_ERR(0, 1884, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1727 + /* "pysam/libcbcf.pyx":1885 * * def __len__(self): * return bcf_hdr_nsamples(self.header.ptr) # <<<<<<<<<<<<<< @@ -28495,7 +30608,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_2__len__(struc __pyx_r = bcf_hdr_nsamples(__pyx_v_self->header->ptr); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1726 + /* "pysam/libcbcf.pyx":1884 * raise TypeError('this class cannot be instantiated from Python') * * def __len__(self): # <<<<<<<<<<<<<< @@ -28513,7 +30626,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_2__len__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":1729 +/* "pysam/libcbcf.pyx":1887 * return bcf_hdr_nsamples(self.header.ptr) * * def __bool__(self): # <<<<<<<<<<<<<< @@ -28539,9 +30652,9 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_4__bool__(struct __py __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 1729, 0, __PYX_ERR(0, 1729, __pyx_L1_error)); + __Pyx_TraceCall("__bool__", __pyx_f[0], 1887, 0, __PYX_ERR(0, 1887, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1730 + /* "pysam/libcbcf.pyx":1888 * * def __bool__(self): * return bcf_hdr_nsamples(self.header.ptr) != 0 # <<<<<<<<<<<<<< @@ -28551,7 +30664,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_4__bool__(struct __py __pyx_r = (bcf_hdr_nsamples(__pyx_v_self->header->ptr) != 0); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1729 + /* "pysam/libcbcf.pyx":1887 * return bcf_hdr_nsamples(self.header.ptr) * * def __bool__(self): # <<<<<<<<<<<<<< @@ -28569,7 +30682,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_4__bool__(struct __py return __pyx_r; } -/* "pysam/libcbcf.pyx":1732 +/* "pysam/libcbcf.pyx":1890 * return bcf_hdr_nsamples(self.header.ptr) != 0 * * def __getitem__(self, index): # <<<<<<<<<<<<<< @@ -28603,9 +30716,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_6__getitem__(st int __pyx_t_4; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[0], 1732, 0, __PYX_ERR(0, 1732, __pyx_L1_error)); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 1890, 0, __PYX_ERR(0, 1890, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1733 + /* "pysam/libcbcf.pyx":1891 * * def __getitem__(self, index): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -28615,7 +30728,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_6__getitem__(st __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1734 + /* "pysam/libcbcf.pyx":1892 * def __getitem__(self, index): * cdef bcf_hdr_t *hdr = self.header.ptr * cdef int32_t n = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< @@ -28624,17 +30737,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_6__getitem__(st */ __pyx_v_n = bcf_hdr_nsamples(__pyx_v_hdr); - /* "pysam/libcbcf.pyx":1735 + /* "pysam/libcbcf.pyx":1893 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef int32_t n = bcf_hdr_nsamples(hdr) * cdef int32_t i = index # <<<<<<<<<<<<<< * * if i < 0 or i >= n: */ - __pyx_t_2 = __Pyx_PyInt_As_int32_t(__pyx_v_index); if (unlikely((__pyx_t_2 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1735, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_As_int32_t(__pyx_v_index); if (unlikely((__pyx_t_2 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1893, __pyx_L1_error) __pyx_v_i = __pyx_t_2; - /* "pysam/libcbcf.pyx":1737 + /* "pysam/libcbcf.pyx":1895 * cdef int32_t i = index * * if i < 0 or i >= n: # <<<<<<<<<<<<<< @@ -28652,20 +30765,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_6__getitem__(st __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":1738 + /* "pysam/libcbcf.pyx":1896 * * if i < 0 or i >= n: * raise IndexError('invalid sample index') # <<<<<<<<<<<<<< * * return charptr_to_str(hdr.samples[i]) */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__97, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1738, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__93, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1896, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 1738, __pyx_L1_error) + __PYX_ERR(0, 1896, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1737 + /* "pysam/libcbcf.pyx":1895 * cdef int32_t i = index * * if i < 0 or i >= n: # <<<<<<<<<<<<<< @@ -28674,7 +30787,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_6__getitem__(st */ } - /* "pysam/libcbcf.pyx":1740 + /* "pysam/libcbcf.pyx":1898 * raise IndexError('invalid sample index') * * return charptr_to_str(hdr.samples[i]) # <<<<<<<<<<<<<< @@ -28682,13 +30795,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_6__getitem__(st * def __iter__(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_hdr->samples[__pyx_v_i]), NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1740, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_hdr->samples[__pyx_v_i]), NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1898, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1732 + /* "pysam/libcbcf.pyx":1890 * return bcf_hdr_nsamples(self.header.ptr) != 0 * * def __getitem__(self, index): # <<<<<<<<<<<<<< @@ -28709,7 +30822,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_6__getitem__(st } static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderSamples_10generator10(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1742 +/* "pysam/libcbcf.pyx":1900 * return charptr_to_str(hdr.samples[i]) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -28739,7 +30852,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_8__iter__(struc if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_20___iter__ *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 1742, __pyx_L1_error) + __PYX_ERR(0, 1900, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -28747,7 +30860,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_8__iter__(struc __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantHeaderSamples_10generator10, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantHeaderSamples___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1742, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantHeaderSamples_10generator10, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantHeaderSamples___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 1900, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -28775,7 +30888,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderSamples_10generator10(_ PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1742, 0, __PYX_ERR(0, 1742, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 1900, 0, __PYX_ERR(0, 1900, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -28785,9 +30898,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderSamples_10generator10(_ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1742, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1900, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1743 + /* "pysam/libcbcf.pyx":1901 * * def __iter__(self): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -28797,7 +30910,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderSamples_10generator10(_ __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->header->ptr; __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1744 + /* "pysam/libcbcf.pyx":1902 * def __iter__(self): * cdef bcf_hdr_t *hdr = self.header.ptr * cdef int32_t i, n = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< @@ -28806,7 +30919,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderSamples_10generator10(_ */ __pyx_cur_scope->__pyx_v_n = bcf_hdr_nsamples(__pyx_cur_scope->__pyx_v_hdr); - /* "pysam/libcbcf.pyx":1746 + /* "pysam/libcbcf.pyx":1904 * cdef int32_t i, n = bcf_hdr_nsamples(hdr) * * for i in range(n): # <<<<<<<<<<<<<< @@ -28818,14 +30931,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderSamples_10generator10(_ for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_4; - /* "pysam/libcbcf.pyx":1747 + /* "pysam/libcbcf.pyx":1905 * * for i in range(n): * yield charptr_to_str(hdr.samples[i]) # <<<<<<<<<<<<<< * * def __contains__(self, key): */ - __pyx_t_5 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_v_hdr->samples[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1747, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_v_hdr->samples[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1905, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; @@ -28843,11 +30956,11 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderSamples_10generator10(_ __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1747, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1905, __pyx_L1_error) } CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1742 + /* "pysam/libcbcf.pyx":1900 * return charptr_to_str(hdr.samples[i]) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -28871,7 +30984,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantHeaderSamples_10generator10(_ return __pyx_r; } -/* "pysam/libcbcf.pyx":1749 +/* "pysam/libcbcf.pyx":1907 * yield charptr_to_str(hdr.samples[i]) * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -28895,7 +31008,7 @@ static int __pyx_pw_5pysam_7libcbcf_20VariantHeaderSamples_12__contains__(PyObje static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_11__contains__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_v_self, PyObject *__pyx_v_key) { bcf_hdr_t *__pyx_v_hdr; vdict_t *__pyx_v_d; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; khiter_t __pyx_v_k; int __pyx_r; __Pyx_TraceDeclarations @@ -28904,54 +31017,54 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_11__contains__(struct PyObject *__pyx_t_2 = NULL; char const *__pyx_t_3; __Pyx_RefNannySetupContext("__contains__", 0); - __Pyx_TraceCall("__contains__", __pyx_f[0], 1749, 0, __PYX_ERR(0, 1749, __pyx_L1_error)); + __Pyx_TraceCall("__contains__", __pyx_f[0], 1907, 0, __PYX_ERR(0, 1907, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1750 + /* "pysam/libcbcf.pyx":1908 * * def __contains__(self, key): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< * cdef vdict_t *d = hdr.dict[BCF_DT_SAMPLE] - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1751 + /* "pysam/libcbcf.pyx":1909 * def __contains__(self, key): * cdef bcf_hdr_t *hdr = self.header.ptr * cdef vdict_t *d = hdr.dict[BCF_DT_SAMPLE] # <<<<<<<<<<<<<< - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef khiter_t k = kh_get_vdict(d, bkey) */ __pyx_v_d = ((vdict_t *)(__pyx_v_hdr->dict[BCF_DT_SAMPLE])); - /* "pysam/libcbcf.pyx":1752 + /* "pysam/libcbcf.pyx":1910 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef vdict_t *d = hdr.dict[BCF_DT_SAMPLE] - * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * cdef khiter_t k = kh_get_vdict(d, bkey) * */ - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1752, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1910, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_bkey = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":1753 + /* "pysam/libcbcf.pyx":1911 * cdef vdict_t *d = hdr.dict[BCF_DT_SAMPLE] - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef khiter_t k = kh_get_vdict(d, bkey) # <<<<<<<<<<<<<< * * return k != kh_end(d) */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 1753, __pyx_L1_error) + __PYX_ERR(0, 1911, __pyx_L1_error) } - __pyx_t_3 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 1753, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 1911, __pyx_L1_error) __pyx_v_k = kh_get_vdict(__pyx_v_d, __pyx_t_3); - /* "pysam/libcbcf.pyx":1755 + /* "pysam/libcbcf.pyx":1913 * cdef khiter_t k = kh_get_vdict(d, bkey) * * return k != kh_end(d) # <<<<<<<<<<<<<< @@ -28961,7 +31074,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_11__contains__(struct __pyx_r = (__pyx_v_k != kh_end(__pyx_v_d)); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1749 + /* "pysam/libcbcf.pyx":1907 * yield charptr_to_str(hdr.samples[i]) * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -28981,7 +31094,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_11__contains__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1762 +/* "pysam/libcbcf.pyx":1920 * #TODO: implement __richcmp__ * * def add(self, name): # <<<<<<<<<<<<<< @@ -29012,16 +31125,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_13add(struct __ PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("add", 0); - __Pyx_TraceCall("add", __pyx_f[0], 1762, 0, __PYX_ERR(0, 1762, __pyx_L1_error)); + __Pyx_TraceCall("add", __pyx_f[0], 1920, 0, __PYX_ERR(0, 1920, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1764 + /* "pysam/libcbcf.pyx":1922 * def add(self, name): * """Add a new sample""" * self.header.add_sample(name) # <<<<<<<<<<<<<< * * */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_add_sample); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1764, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_add_sample); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1922, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -29034,13 +31147,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_13add(struct __ } } if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1764, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1922, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_name}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1764, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1922, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -29048,19 +31161,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_13add(struct __ #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_name}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1764, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1922, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1764, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1922, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_name); __Pyx_GIVEREF(__pyx_v_name); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_name); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1764, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1922, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -29068,7 +31181,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_13add(struct __ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":1762 + /* "pysam/libcbcf.pyx":1920 * #TODO: implement __richcmp__ * * def add(self, name): # <<<<<<<<<<<<<< @@ -29093,6 +31206,49 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_13add(struct __ return __pyx_r; } +/* "pysam/libcbcf.pxd":58 + * + * cdef class VariantHeaderSamples(object): + * cdef readonly VariantHeader header # <<<<<<<<<<<<<< + * + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantHeaderSamples_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantHeaderSamples_6header_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_6header___get__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 58, 0, __PYX_ERR(1, 58, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); + __pyx_r = ((PyObject *)__pyx_v_self->header); + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantHeaderSamples.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * cdef bint use_setstate @@ -29126,7 +31282,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_15__reduce_cyth PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -29135,7 +31291,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_15__reduce_cyth * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self->header)); @@ -29150,7 +31306,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_15__reduce_cyth * if _dict is not None: * state += (_dict,) */ - __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v__dict = __pyx_t_1; __pyx_t_1 = 0; @@ -29173,12 +31329,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_15__reduce_cyth * use_setstate = True * else: */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); @@ -29234,9 +31390,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_15__reduce_cyth * return __pyx_unpickle_VariantHeaderSamples, (type(self), 0x099fb99, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderSamp); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderSamp); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -29247,7 +31403,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_15__reduce_cyth __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); @@ -29280,9 +31436,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_15__reduce_cyth */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderSamp); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantHeaderSamp); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -29293,7 +31449,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_15__reduce_cyth __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); @@ -29355,15 +31511,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_17__setstate_cy __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 14, 0, __PYX_ERR(2, 14, __pyx_L1_error)); /* "(tree fragment)":15 * return __pyx_unpickle_VariantHeaderSamples, (type(self), 0x099fb99, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_VariantHeaderSamples__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderSamples__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderSamples__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -29388,7 +31544,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantHeaderSamples_17__setstate_cy return __pyx_r; } -/* "pysam/libcbcf.pyx":1767 +/* "pysam/libcbcf.pyx":1925 * * * cdef VariantHeaderSamples makeVariantHeaderSamples(VariantHeader header): # <<<<<<<<<<<<<< @@ -29405,33 +31561,33 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_f_5pysam_7li int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("makeVariantHeaderSamples", 0); - __Pyx_TraceCall("makeVariantHeaderSamples", __pyx_f[0], 1767, 0, __PYX_ERR(0, 1767, __pyx_L1_error)); + __Pyx_TraceCall("makeVariantHeaderSamples", __pyx_f[0], 1925, 0, __PYX_ERR(0, 1925, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1768 + /* "pysam/libcbcf.pyx":1926 * * cdef VariantHeaderSamples makeVariantHeaderSamples(VariantHeader header): * if not header: # <<<<<<<<<<<<<< * raise ValueError('invalid VariantHeader') * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1768, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1926, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1769 + /* "pysam/libcbcf.pyx":1927 * cdef VariantHeaderSamples makeVariantHeaderSamples(VariantHeader header): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * cdef VariantHeaderSamples samples = VariantHeaderSamples.__new__(VariantHeaderSamples) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__98, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1769, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__94, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1927, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1769, __pyx_L1_error) + __PYX_ERR(0, 1927, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1768 + /* "pysam/libcbcf.pyx":1926 * * cdef VariantHeaderSamples makeVariantHeaderSamples(VariantHeader header): * if not header: # <<<<<<<<<<<<<< @@ -29440,19 +31596,19 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_f_5pysam_7li */ } - /* "pysam/libcbcf.pyx":1771 + /* "pysam/libcbcf.pyx":1929 * raise ValueError('invalid VariantHeader') * * cdef VariantHeaderSamples samples = VariantHeaderSamples.__new__(VariantHeaderSamples) # <<<<<<<<<<<<<< * samples.header = header * */ - __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantHeaderSamples(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderSamples), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1771, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantHeaderSamples(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderSamples), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1929, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_v_samples = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":1772 + /* "pysam/libcbcf.pyx":1930 * * cdef VariantHeaderSamples samples = VariantHeaderSamples.__new__(VariantHeaderSamples) * samples.header = header # <<<<<<<<<<<<<< @@ -29465,7 +31621,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_f_5pysam_7li __Pyx_DECREF(((PyObject *)__pyx_v_samples->header)); __pyx_v_samples->header = __pyx_v_header; - /* "pysam/libcbcf.pyx":1774 + /* "pysam/libcbcf.pyx":1932 * samples.header = header * * return samples # <<<<<<<<<<<<<< @@ -29477,7 +31633,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_f_5pysam_7li __pyx_r = __pyx_v_samples; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1767 + /* "pysam/libcbcf.pyx":1925 * * * cdef VariantHeaderSamples makeVariantHeaderSamples(VariantHeader header): # <<<<<<<<<<<<<< @@ -29498,7 +31654,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *__pyx_f_5pysam_7li return __pyx_r; } -/* "pysam/libcbcf.pyx":1784 +/* "pysam/libcbcf.pyx":1942 * * # See makeVariantHeader for C constructor * def __cinit__(self): # <<<<<<<<<<<<<< @@ -29527,9 +31683,9 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantHeader___cinit__(struct __pyx_obj_5 __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[0], 1784, 0, __PYX_ERR(0, 1784, __pyx_L1_error)); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 1942, 0, __PYX_ERR(0, 1942, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1785 + /* "pysam/libcbcf.pyx":1943 * # See makeVariantHeader for C constructor * def __cinit__(self): * self.ptr = NULL # <<<<<<<<<<<<<< @@ -29538,7 +31694,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantHeader___cinit__(struct __pyx_obj_5 */ __pyx_v_self->ptr = NULL; - /* "pysam/libcbcf.pyx":1784 + /* "pysam/libcbcf.pyx":1942 * * # See makeVariantHeader for C constructor * def __cinit__(self): # <<<<<<<<<<<<<< @@ -29558,7 +31714,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantHeader___cinit__(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libcbcf.pyx":1788 +/* "pysam/libcbcf.pyx":1946 * * # Python constructor * def __init__(self): # <<<<<<<<<<<<<< @@ -29589,9 +31745,9 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantHeader_2__init__(struct __pyx_obj_5 int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1788, 0, __PYX_ERR(0, 1788, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 1946, 0, __PYX_ERR(0, 1946, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1789 + /* "pysam/libcbcf.pyx":1947 * # Python constructor * def __init__(self): * self.ptr = bcf_hdr_init(b'w') # <<<<<<<<<<<<<< @@ -29600,7 +31756,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantHeader_2__init__(struct __pyx_obj_5 */ __pyx_v_self->ptr = bcf_hdr_init(((char const *)"w")); - /* "pysam/libcbcf.pyx":1790 + /* "pysam/libcbcf.pyx":1948 * def __init__(self): * self.ptr = bcf_hdr_init(b'w') * if not self.ptr: # <<<<<<<<<<<<<< @@ -29610,20 +31766,20 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantHeader_2__init__(struct __pyx_obj_5 __pyx_t_1 = ((!(__pyx_v_self->ptr != 0)) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":1791 + /* "pysam/libcbcf.pyx":1949 * self.ptr = bcf_hdr_init(b'w') * if not self.ptr: * raise ValueError('cannot create VariantHeader') # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__99, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1791, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__95, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1949, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 1791, __pyx_L1_error) + __PYX_ERR(0, 1949, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1790 + /* "pysam/libcbcf.pyx":1948 * def __init__(self): * self.ptr = bcf_hdr_init(b'w') * if not self.ptr: # <<<<<<<<<<<<<< @@ -29632,7 +31788,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantHeader_2__init__(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":1788 + /* "pysam/libcbcf.pyx":1946 * * # Python constructor * def __init__(self): # <<<<<<<<<<<<<< @@ -29653,7 +31809,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantHeader_2__init__(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libcbcf.pyx":1793 +/* "pysam/libcbcf.pyx":1951 * raise ValueError('cannot create VariantHeader') * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -29677,9 +31833,9 @@ static void __pyx_pf_5pysam_7libcbcf_13VariantHeader_4__dealloc__(struct __pyx_o __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1793, 0, __PYX_ERR(0, 1793, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1951, 0, __PYX_ERR(0, 1951, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1794 + /* "pysam/libcbcf.pyx":1952 * * def __dealloc__(self): * if self.ptr: # <<<<<<<<<<<<<< @@ -29689,7 +31845,7 @@ static void __pyx_pf_5pysam_7libcbcf_13VariantHeader_4__dealloc__(struct __pyx_o __pyx_t_1 = (__pyx_v_self->ptr != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":1795 + /* "pysam/libcbcf.pyx":1953 * def __dealloc__(self): * if self.ptr: * bcf_hdr_destroy(self.ptr) # <<<<<<<<<<<<<< @@ -29698,7 +31854,7 @@ static void __pyx_pf_5pysam_7libcbcf_13VariantHeader_4__dealloc__(struct __pyx_o */ bcf_hdr_destroy(__pyx_v_self->ptr); - /* "pysam/libcbcf.pyx":1796 + /* "pysam/libcbcf.pyx":1954 * if self.ptr: * bcf_hdr_destroy(self.ptr) * self.ptr = NULL # <<<<<<<<<<<<<< @@ -29707,7 +31863,7 @@ static void __pyx_pf_5pysam_7libcbcf_13VariantHeader_4__dealloc__(struct __pyx_o */ __pyx_v_self->ptr = NULL; - /* "pysam/libcbcf.pyx":1794 + /* "pysam/libcbcf.pyx":1952 * * def __dealloc__(self): * if self.ptr: # <<<<<<<<<<<<<< @@ -29716,7 +31872,7 @@ static void __pyx_pf_5pysam_7libcbcf_13VariantHeader_4__dealloc__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":1793 + /* "pysam/libcbcf.pyx":1951 * raise ValueError('cannot create VariantHeader') * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -29733,12 +31889,12 @@ static void __pyx_pf_5pysam_7libcbcf_13VariantHeader_4__dealloc__(struct __pyx_o __Pyx_RefNannyFinishContext(); } -/* "pysam/libcbcf.pyx":1798 +/* "pysam/libcbcf.pyx":1956 * self.ptr = NULL * * def __bool__(self): # <<<<<<<<<<<<<< - * # self.ptr == NULL should be impossible * return self.ptr != NULL + * */ /* Python wrapper */ @@ -29759,11 +31915,11 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantHeader_6__bool__(struct __pyx_obj_5 __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 1798, 0, __PYX_ERR(0, 1798, __pyx_L1_error)); + __Pyx_TraceCall("__bool__", __pyx_f[0], 1956, 0, __PYX_ERR(0, 1956, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1800 + /* "pysam/libcbcf.pyx":1957 + * * def __bool__(self): - * # self.ptr == NULL should be impossible * return self.ptr != NULL # <<<<<<<<<<<<<< * * def copy(self): @@ -29771,12 +31927,12 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantHeader_6__bool__(struct __pyx_obj_5 __pyx_r = (__pyx_v_self->ptr != NULL); goto __pyx_L0; - /* "pysam/libcbcf.pyx":1798 + /* "pysam/libcbcf.pyx":1956 * self.ptr = NULL * * def __bool__(self): # <<<<<<<<<<<<<< - * # self.ptr == NULL should be impossible * return self.ptr != NULL + * */ /* function exit code */ @@ -29789,7 +31945,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantHeader_6__bool__(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libcbcf.pyx":1802 +/* "pysam/libcbcf.pyx":1959 * return self.ptr != NULL * * def copy(self): # <<<<<<<<<<<<<< @@ -29817,9 +31973,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_8copy(struct __pyx_obj __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("copy", 0); - __Pyx_TraceCall("copy", __pyx_f[0], 1802, 0, __PYX_ERR(0, 1802, __pyx_L1_error)); + __Pyx_TraceCall("copy", __pyx_f[0], 1959, 0, __PYX_ERR(0, 1959, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1803 + /* "pysam/libcbcf.pyx":1960 * * def copy(self): * return makeVariantHeader(bcf_hdr_dup(self.ptr)) # <<<<<<<<<<<<<< @@ -29827,13 +31983,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_8copy(struct __pyx_obj * def merge(self, VariantHeader header): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeader(bcf_hdr_dup(__pyx_v_self->ptr))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1803, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeader(bcf_hdr_dup(__pyx_v_self->ptr))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1960, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1802 + /* "pysam/libcbcf.pyx":1959 * return self.ptr != NULL * * def copy(self): # <<<<<<<<<<<<<< @@ -29853,7 +32009,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_8copy(struct __pyx_obj return __pyx_r; } -/* "pysam/libcbcf.pyx":1805 +/* "pysam/libcbcf.pyx":1962 * return makeVariantHeader(bcf_hdr_dup(self.ptr)) * * def merge(self, VariantHeader header): # <<<<<<<<<<<<<< @@ -29868,7 +32024,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_11merge(PyObject *__py PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("merge (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_header), __pyx_ptype_5pysam_7libcbcf_VariantHeader, 1, "header", 0))) __PYX_ERR(0, 1805, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_header), __pyx_ptype_5pysam_7libcbcf_VariantHeader, 1, "header", 0))) __PYX_ERR(0, 1962, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_10merge(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self), ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_header)); /* function exit code */ @@ -29888,9 +32044,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_10merge(struct __pyx_o int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("merge", 0); - __Pyx_TraceCall("merge", __pyx_f[0], 1805, 0, __PYX_ERR(0, 1805, __pyx_L1_error)); + __Pyx_TraceCall("merge", __pyx_f[0], 1962, 0, __PYX_ERR(0, 1962, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1806 + /* "pysam/libcbcf.pyx":1963 * * def merge(self, VariantHeader header): * if header is None: # <<<<<<<<<<<<<< @@ -29901,20 +32057,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_10merge(struct __pyx_o __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":1807 + /* "pysam/libcbcf.pyx":1964 * def merge(self, VariantHeader header): * if header is None: * raise ValueError('header must not be None') # <<<<<<<<<<<<<< * bcf_hdr_merge(self.ptr, header.ptr) * */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__100, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1807, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__96, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1964, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1807, __pyx_L1_error) + __PYX_ERR(0, 1964, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1806 + /* "pysam/libcbcf.pyx":1963 * * def merge(self, VariantHeader header): * if header is None: # <<<<<<<<<<<<<< @@ -29923,7 +32079,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_10merge(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":1808 + /* "pysam/libcbcf.pyx":1965 * if header is None: * raise ValueError('header must not be None') * bcf_hdr_merge(self.ptr, header.ptr) # <<<<<<<<<<<<<< @@ -29932,7 +32088,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_10merge(struct __pyx_o */ (void)(bcf_hdr_merge(__pyx_v_self->ptr, __pyx_v_header->ptr)); - /* "pysam/libcbcf.pyx":1805 + /* "pysam/libcbcf.pyx":1962 * return makeVariantHeader(bcf_hdr_dup(self.ptr)) * * def merge(self, VariantHeader header): # <<<<<<<<<<<<<< @@ -29954,7 +32110,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_10merge(struct __pyx_o return __pyx_r; } -/* "pysam/libcbcf.pyx":1811 +/* "pysam/libcbcf.pyx":1968 * * @property * def version(self): # <<<<<<<<<<<<<< @@ -29982,9 +32138,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7version___get__(struc PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1811, 0, __PYX_ERR(0, 1811, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1968, 0, __PYX_ERR(0, 1968, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1813 + /* "pysam/libcbcf.pyx":1970 * def version(self): * """VCF version""" * return force_str(bcf_hdr_get_version(self.ptr)) # <<<<<<<<<<<<<< @@ -29992,16 +32148,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7version___get__(struc * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBytes_FromString(bcf_hdr_get_version(__pyx_v_self->ptr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1813, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBytes_FromString(bcf_hdr_get_version(__pyx_v_self->ptr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1970, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1813, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1970, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1811 + /* "pysam/libcbcf.pyx":1968 * * @property * def version(self): # <<<<<<<<<<<<<< @@ -30022,7 +32178,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7version___get__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":1816 +/* "pysam/libcbcf.pyx":1973 * * @property * def samples(self): # <<<<<<<<<<<<<< @@ -30049,9 +32205,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7samples___get__(struc __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1816, 0, __PYX_ERR(0, 1816, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1973, 0, __PYX_ERR(0, 1973, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1818 + /* "pysam/libcbcf.pyx":1975 * def samples(self): * """samples (:class:`VariantHeaderSamples`)""" * return makeVariantHeaderSamples(self) # <<<<<<<<<<<<<< @@ -30059,13 +32215,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7samples___get__(struc * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderSamples(__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1818, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderSamples(__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1975, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1816 + /* "pysam/libcbcf.pyx":1973 * * @property * def samples(self): # <<<<<<<<<<<<<< @@ -30085,7 +32241,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7samples___get__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":1821 +/* "pysam/libcbcf.pyx":1978 * * @property * def records(self): # <<<<<<<<<<<<<< @@ -30112,9 +32268,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7records___get__(struc __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1821, 0, __PYX_ERR(0, 1821, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1978, 0, __PYX_ERR(0, 1978, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1823 + /* "pysam/libcbcf.pyx":1980 * def records(self): * """header records (:class:`VariantHeaderRecords`)""" * return makeVariantHeaderRecords(self) # <<<<<<<<<<<<<< @@ -30122,13 +32278,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7records___get__(struc * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderRecords(__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1823, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderRecords(__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1980, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1821 + /* "pysam/libcbcf.pyx":1978 * * @property * def records(self): # <<<<<<<<<<<<<< @@ -30148,7 +32304,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7records___get__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":1826 +/* "pysam/libcbcf.pyx":1983 * * @property * def contigs(self): # <<<<<<<<<<<<<< @@ -30175,9 +32331,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7contigs___get__(struc __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1826, 0, __PYX_ERR(0, 1826, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1983, 0, __PYX_ERR(0, 1983, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1828 + /* "pysam/libcbcf.pyx":1985 * def contigs(self): * """contig information (:class:`VariantHeaderContigs`)""" * return makeVariantHeaderContigs(self) # <<<<<<<<<<<<<< @@ -30185,13 +32341,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7contigs___get__(struc * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderContigs(__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1828, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderContigs(__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1985, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1826 + /* "pysam/libcbcf.pyx":1983 * * @property * def contigs(self): # <<<<<<<<<<<<<< @@ -30211,7 +32367,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7contigs___get__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":1831 +/* "pysam/libcbcf.pyx":1988 * * @property * def filters(self): # <<<<<<<<<<<<<< @@ -30238,9 +32394,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7filters___get__(struc __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1831, 0, __PYX_ERR(0, 1831, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1988, 0, __PYX_ERR(0, 1988, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1833 + /* "pysam/libcbcf.pyx":1990 * def filters(self): * """filter metadata (:class:`VariantHeaderMetadata`)""" * return makeVariantHeaderMetadata(self, BCF_HL_FLT) # <<<<<<<<<<<<<< @@ -30248,13 +32404,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7filters___get__(struc * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderMetadata(__pyx_v_self, BCF_HL_FLT)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1833, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderMetadata(__pyx_v_self, BCF_HL_FLT)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1990, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1831 + /* "pysam/libcbcf.pyx":1988 * * @property * def filters(self): # <<<<<<<<<<<<<< @@ -30274,7 +32430,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7filters___get__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":1836 +/* "pysam/libcbcf.pyx":1993 * * @property * def info(self): # <<<<<<<<<<<<<< @@ -30301,9 +32457,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4info___get__(struct _ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1836, 0, __PYX_ERR(0, 1836, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1993, 0, __PYX_ERR(0, 1993, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1838 + /* "pysam/libcbcf.pyx":1995 * def info(self): * """info metadata (:class:`VariantHeaderMetadata`)""" * return makeVariantHeaderMetadata(self, BCF_HL_INFO) # <<<<<<<<<<<<<< @@ -30311,13 +32467,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4info___get__(struct _ * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderMetadata(__pyx_v_self, BCF_HL_INFO)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1838, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderMetadata(__pyx_v_self, BCF_HL_INFO)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1995, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1836 + /* "pysam/libcbcf.pyx":1993 * * @property * def info(self): # <<<<<<<<<<<<<< @@ -30337,7 +32493,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4info___get__(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":1841 +/* "pysam/libcbcf.pyx":1998 * * @property * def formats(self): # <<<<<<<<<<<<<< @@ -30364,9 +32520,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7formats___get__(struc __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1841, 0, __PYX_ERR(0, 1841, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 1998, 0, __PYX_ERR(0, 1998, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1843 + /* "pysam/libcbcf.pyx":2000 * def formats(self): * """format metadata (:class:`VariantHeaderMetadata`)""" * return makeVariantHeaderMetadata(self, BCF_HL_FMT) # <<<<<<<<<<<<<< @@ -30374,13 +32530,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7formats___get__(struc * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderMetadata(__pyx_v_self, BCF_HL_FMT)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1843, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeaderMetadata(__pyx_v_self, BCF_HL_FMT)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2000, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1841 + /* "pysam/libcbcf.pyx":1998 * * @property * def formats(self): # <<<<<<<<<<<<<< @@ -30400,7 +32556,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_7formats___get__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":1846 +/* "pysam/libcbcf.pyx":2003 * * @property * def alts(self): # <<<<<<<<<<<<<< @@ -30435,9 +32591,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4alts___get__(struct _ PyObject *__pyx_t_7 = NULL; int __pyx_t_8; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 1846, 0, __PYX_ERR(0, 1846, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2003, 0, __PYX_ERR(0, 2003, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1856 + /* "pysam/libcbcf.pyx":2013 * at the time it is created. * """ * return {record['ID']:record for record in self.records # <<<<<<<<<<<<<< @@ -30446,17 +32602,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4alts___get__(struct _ */ __Pyx_XDECREF(__pyx_r); { /* enter inner scope */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1856, __pyx_L5_error) + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2013, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_records); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1856, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_records); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2013, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; __pyx_t_5 = NULL; } else { - __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1856, __pyx_L5_error) + __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2013, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1856, __pyx_L5_error) + __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2013, __pyx_L5_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { @@ -30464,17 +32620,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4alts___get__(struct _ if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1856, __pyx_L5_error) + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2013, __pyx_L5_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1856, __pyx_L5_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2013, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1856, __pyx_L5_error) + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2013, __pyx_L5_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1856, __pyx_L5_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2013, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); #endif } @@ -30484,7 +32640,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4alts___get__(struct _ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1856, __pyx_L5_error) + else __PYX_ERR(0, 2013, __pyx_L5_error) } break; } @@ -30493,16 +32649,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4alts___get__(struct _ __Pyx_XDECREF_SET(__pyx_8genexpr5__pyx_v_record, __pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":1857 + /* "pysam/libcbcf.pyx":2014 * """ * return {record['ID']:record for record in self.records * if record.key.upper() == 'ALT' } # <<<<<<<<<<<<<< * * # only safe to do when opening an htsfile */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr5__pyx_v_record, __pyx_n_s_key); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1857, __pyx_L5_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr5__pyx_v_record, __pyx_n_s_key); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2014, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_upper); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1857, __pyx_L5_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_upper); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2014, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = NULL; @@ -30516,30 +32672,30 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4alts___get__(struct _ } } if (__pyx_t_6) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1857, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2014, __pyx_L5_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1857, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2014, __pyx_L5_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_ALT, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1857, __pyx_L5_error) + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_ALT, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2014, __pyx_L5_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_8) { - /* "pysam/libcbcf.pyx":1856 + /* "pysam/libcbcf.pyx":2013 * at the time it is created. * """ * return {record['ID']:record for record in self.records # <<<<<<<<<<<<<< * if record.key.upper() == 'ALT' } * */ - __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_8genexpr5__pyx_v_record, __pyx_n_s_ID); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1856, __pyx_L5_error) + __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_8genexpr5__pyx_v_record, __pyx_n_s_ID); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2013, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_2); - if (unlikely(PyDict_SetItem(__pyx_t_1, (PyObject*)__pyx_t_2, (PyObject*)__pyx_8genexpr5__pyx_v_record))) __PYX_ERR(0, 1856, __pyx_L5_error) + if (unlikely(PyDict_SetItem(__pyx_t_1, (PyObject*)__pyx_t_2, (PyObject*)__pyx_8genexpr5__pyx_v_record))) __PYX_ERR(0, 2013, __pyx_L5_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":1857 + /* "pysam/libcbcf.pyx":2014 * """ * return {record['ID']:record for record in self.records * if record.key.upper() == 'ALT' } # <<<<<<<<<<<<<< @@ -30548,7 +32704,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4alts___get__(struct _ */ } - /* "pysam/libcbcf.pyx":1856 + /* "pysam/libcbcf.pyx":2013 * at the time it is created. * """ * return {record['ID']:record for record in self.records # <<<<<<<<<<<<<< @@ -30568,7 +32724,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4alts___get__(struct _ __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1846 + /* "pysam/libcbcf.pyx":2003 * * @property * def alts(self): # <<<<<<<<<<<<<< @@ -30593,7 +32749,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_4alts___get__(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":1860 +/* "pysam/libcbcf.pyx":2017 * * # only safe to do when opening an htsfile * cdef _subset_samples(self, include_samples): # <<<<<<<<<<<<<< @@ -30619,89 +32775,89 @@ static PyObject *__pyx_f_5pysam_7libcbcf_13VariantHeader__subset_samples(struct char *__pyx_t_8; char *__pyx_t_9; __Pyx_RefNannySetupContext("_subset_samples", 0); - __Pyx_TraceCall("_subset_samples", __pyx_f[0], 1860, 0, __PYX_ERR(0, 1860, __pyx_L1_error)); + __Pyx_TraceCall("_subset_samples", __pyx_f[0], 2017, 0, __PYX_ERR(0, 2017, __pyx_L1_error)); __Pyx_INCREF(__pyx_v_include_samples); - /* "pysam/libcbcf.pyx":1861 + /* "pysam/libcbcf.pyx":2018 * # only safe to do when opening an htsfile * cdef _subset_samples(self, include_samples): * keep_samples = set(self.samples) # <<<<<<<<<<<<<< * include_samples = set(include_samples) * missing_samples = include_samples - keep_samples */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_samples); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1861, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_samples); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2018, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PySet_New(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1861, __pyx_L1_error) + __pyx_t_2 = PySet_New(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2018, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_keep_samples = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":1862 + /* "pysam/libcbcf.pyx":2019 * cdef _subset_samples(self, include_samples): * keep_samples = set(self.samples) * include_samples = set(include_samples) # <<<<<<<<<<<<<< * missing_samples = include_samples - keep_samples * keep_samples &= include_samples */ - __pyx_t_2 = PySet_New(__pyx_v_include_samples); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1862, __pyx_L1_error) + __pyx_t_2 = PySet_New(__pyx_v_include_samples); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2019, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_include_samples, __pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":1863 + /* "pysam/libcbcf.pyx":2020 * keep_samples = set(self.samples) * include_samples = set(include_samples) * missing_samples = include_samples - keep_samples # <<<<<<<<<<<<<< * keep_samples &= include_samples * */ - __pyx_t_2 = PyNumber_Subtract(__pyx_v_include_samples, __pyx_v_keep_samples); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1863, __pyx_L1_error) + __pyx_t_2 = PyNumber_Subtract(__pyx_v_include_samples, __pyx_v_keep_samples); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2020, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_missing_samples = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":1864 + /* "pysam/libcbcf.pyx":2021 * include_samples = set(include_samples) * missing_samples = include_samples - keep_samples * keep_samples &= include_samples # <<<<<<<<<<<<<< * * if missing_samples: */ - __pyx_t_2 = PyNumber_InPlaceAnd(__pyx_v_keep_samples, __pyx_v_include_samples); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1864, __pyx_L1_error) + __pyx_t_2 = PyNumber_InPlaceAnd(__pyx_v_keep_samples, __pyx_v_include_samples); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2021, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_keep_samples, __pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":1866 + /* "pysam/libcbcf.pyx":2023 * keep_samples &= include_samples * * if missing_samples: # <<<<<<<<<<<<<< * # FIXME: add specialized exception with payload * raise ValueError( */ - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_missing_samples); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1866, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_missing_samples); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2023, __pyx_L1_error) if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":1869 + /* "pysam/libcbcf.pyx":2026 * # FIXME: add specialized exception with payload * raise ValueError( * 'missing {:d} requested samples'.format( # <<<<<<<<<<<<<< * len(missing_samples))) * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_missing_d_requested_samples, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1869, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_missing_d_requested_samples, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2026, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libcbcf.pyx":1870 + /* "pysam/libcbcf.pyx":2027 * raise ValueError( * 'missing {:d} requested samples'.format( * len(missing_samples))) # <<<<<<<<<<<<<< * * keep_samples = force_bytes(','.join(keep_samples)) */ - __pyx_t_4 = PyObject_Length(__pyx_v_missing_samples); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1870, __pyx_L1_error) - __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1870, __pyx_L1_error) + __pyx_t_4 = PyObject_Length(__pyx_v_missing_samples); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2027, __pyx_L1_error) + __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2027, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { @@ -30714,14 +32870,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf_13VariantHeader__subset_samples(struct } } if (!__pyx_t_6) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1869, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2026, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1869, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2026, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; @@ -30730,41 +32886,41 @@ static PyObject *__pyx_f_5pysam_7libcbcf_13VariantHeader__subset_samples(struct #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1869, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2026, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { - __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1869, __pyx_L1_error) + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2026, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); __pyx_t_5 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1869, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2026, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":1868 + /* "pysam/libcbcf.pyx":2025 * if missing_samples: * # FIXME: add specialized exception with payload * raise ValueError( # <<<<<<<<<<<<<< * 'missing {:d} requested samples'.format( * len(missing_samples))) */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1868, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2025, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1868, __pyx_L1_error) + __PYX_ERR(0, 2025, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1866 + /* "pysam/libcbcf.pyx":2023 * keep_samples &= include_samples * * if missing_samples: # <<<<<<<<<<<<<< @@ -30773,69 +32929,69 @@ static PyObject *__pyx_f_5pysam_7libcbcf_13VariantHeader__subset_samples(struct */ } - /* "pysam/libcbcf.pyx":1872 + /* "pysam/libcbcf.pyx":2029 * len(missing_samples))) * * keep_samples = force_bytes(','.join(keep_samples)) # <<<<<<<<<<<<<< * cdef char *keep = keep_samples if keep_samples else NULL * cdef ret = bcf_hdr_set_samples(self.ptr, keep, 0) */ - __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s_, __pyx_v_keep_samples); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1872, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_v_keep_samples); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2029, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1872, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2029, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_keep_samples, __pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":1873 + /* "pysam/libcbcf.pyx":2030 * * keep_samples = force_bytes(','.join(keep_samples)) * cdef char *keep = keep_samples if keep_samples else NULL # <<<<<<<<<<<<<< * cdef ret = bcf_hdr_set_samples(self.ptr, keep, 0) * */ - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_keep_samples); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1873, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_keep_samples); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2030, __pyx_L1_error) if (__pyx_t_3) { - __pyx_t_9 = __Pyx_PyObject_AsWritableString(__pyx_v_keep_samples); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 1873, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_AsWritableString(__pyx_v_keep_samples); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 2030, __pyx_L1_error) __pyx_t_8 = ((char *)__pyx_t_9); } else { __pyx_t_8 = NULL; } __pyx_v_keep = __pyx_t_8; - /* "pysam/libcbcf.pyx":1874 + /* "pysam/libcbcf.pyx":2031 * keep_samples = force_bytes(','.join(keep_samples)) * cdef char *keep = keep_samples if keep_samples else NULL * cdef ret = bcf_hdr_set_samples(self.ptr, keep, 0) # <<<<<<<<<<<<<< * * if ret != 0: */ - __pyx_t_2 = __Pyx_PyInt_From_int(bcf_hdr_set_samples(__pyx_v_self->ptr, __pyx_v_keep, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1874, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(bcf_hdr_set_samples(__pyx_v_self->ptr, __pyx_v_keep, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2031, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_ret = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":1876 + /* "pysam/libcbcf.pyx":2033 * cdef ret = bcf_hdr_set_samples(self.ptr, keep, 0) * * if ret != 0: # <<<<<<<<<<<<<< * raise ValueError( * 'bcf_hdr_set_samples failed: ret = {}'.format(ret)) */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_ret, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1876, __pyx_L1_error) - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1876, __pyx_L1_error) + __pyx_t_2 = PyObject_RichCompare(__pyx_v_ret, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2033, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2033, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":1878 + /* "pysam/libcbcf.pyx":2035 * if ret != 0: * raise ValueError( * 'bcf_hdr_set_samples failed: ret = {}'.format(ret)) # <<<<<<<<<<<<<< * * def __str__(self): */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_bcf_hdr_set_samples_failed_ret, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1878, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_bcf_hdr_set_samples_failed_ret, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2035, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { @@ -30848,13 +33004,13 @@ static PyObject *__pyx_f_5pysam_7libcbcf_13VariantHeader__subset_samples(struct } } if (!__pyx_t_7) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_ret); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1878, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_ret); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2035, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_ret}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1878, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2035, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_2); } else @@ -30862,40 +33018,40 @@ static PyObject *__pyx_f_5pysam_7libcbcf_13VariantHeader__subset_samples(struct #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_ret}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1878, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2035, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1878, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2035, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); __pyx_t_7 = NULL; __Pyx_INCREF(__pyx_v_ret); __Pyx_GIVEREF(__pyx_v_ret); PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_ret); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1878, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2035, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":1877 + /* "pysam/libcbcf.pyx":2034 * * if ret != 0: * raise ValueError( # <<<<<<<<<<<<<< * 'bcf_hdr_set_samples failed: ret = {}'.format(ret)) * */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1877, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2034, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1877, __pyx_L1_error) + __PYX_ERR(0, 2034, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1876 + /* "pysam/libcbcf.pyx":2033 * cdef ret = bcf_hdr_set_samples(self.ptr, keep, 0) * * if ret != 0: # <<<<<<<<<<<<<< @@ -30904,7 +33060,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_13VariantHeader__subset_samples(struct */ } - /* "pysam/libcbcf.pyx":1860 + /* "pysam/libcbcf.pyx":2017 * * # only safe to do when opening an htsfile * cdef _subset_samples(self, include_samples): # <<<<<<<<<<<<<< @@ -30934,7 +33090,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf_13VariantHeader__subset_samples(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":1880 +/* "pysam/libcbcf.pyx":2037 * 'bcf_hdr_set_samples failed: ret = {}'.format(ret)) * * def __str__(self): # <<<<<<<<<<<<<< @@ -30972,9 +33128,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_12__str__(struct __pyx PyObject *__pyx_t_9 = NULL; PyObject *__pyx_t_10 = NULL; __Pyx_RefNannySetupContext("__str__", 0); - __Pyx_TraceCall("__str__", __pyx_f[0], 1880, 0, __PYX_ERR(0, 1880, __pyx_L1_error)); + __Pyx_TraceCall("__str__", __pyx_f[0], 2037, 0, __PYX_ERR(0, 2037, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1882 + /* "pysam/libcbcf.pyx":2039 * def __str__(self): * cdef int hlen * cdef char *hstr = bcf_hdr_fmt_text(self.ptr, 0, &hlen) # <<<<<<<<<<<<<< @@ -30983,7 +33139,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_12__str__(struct __pyx */ __pyx_v_hstr = bcf_hdr_fmt_text(__pyx_v_self->ptr, 0, (&__pyx_v_hlen)); - /* "pysam/libcbcf.pyx":1884 + /* "pysam/libcbcf.pyx":2041 * cdef char *hstr = bcf_hdr_fmt_text(self.ptr, 0, &hlen) * * try: # <<<<<<<<<<<<<< @@ -30992,7 +33148,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_12__str__(struct __pyx */ /*try:*/ { - /* "pysam/libcbcf.pyx":1885 + /* "pysam/libcbcf.pyx":2042 * * try: * return charptr_to_str_w_len(hstr, hlen) # <<<<<<<<<<<<<< @@ -31000,19 +33156,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_12__str__(struct __pyx * free(hstr) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str_w_len(__pyx_v_hstr, __pyx_v_hlen, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1885, __pyx_L4_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str_w_len(__pyx_v_hstr, __pyx_v_hlen, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2042, __pyx_L4_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L3_return; } - /* "pysam/libcbcf.pyx":1887 + /* "pysam/libcbcf.pyx":2044 * return charptr_to_str_w_len(hstr, hlen) * finally: * free(hstr) # <<<<<<<<<<<<<< * - * cpdef VariantRecord new_record(self): + * def new_record(self, contig=None, start=0, stop=0, alleles=None, */ /*finally:*/ { __pyx_L4_error:; @@ -31057,7 +33213,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_12__str__(struct __pyx } } - /* "pysam/libcbcf.pyx":1880 + /* "pysam/libcbcf.pyx":2037 * 'bcf_hdr_set_samples failed: ret = {}'.format(ret)) * * def __str__(self): # <<<<<<<<<<<<<< @@ -31077,460 +33233,3749 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_12__str__(struct __pyx return __pyx_r; } -/* "pysam/libcbcf.pyx":1889 +/* "pysam/libcbcf.pyx":2046 * free(hstr) * - * cpdef VariantRecord new_record(self): # <<<<<<<<<<<<<< - * """Create a new empty VariantRecord""" - * r = makeVariantRecord(self, bcf_init()) + * def new_record(self, contig=None, start=0, stop=0, alleles=None, # <<<<<<<<<<<<<< + * id=None, qual=None, filter=None, info=None, samples=None, + * **kwargs): */ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_15new_record(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_13VariantHeader_new_record(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, int __pyx_skip_dispatch) { - struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_r = NULL; - struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_r = NULL; - __Pyx_TraceDeclarations +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_15new_record(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_14new_record[] = "VariantHeader.new_record(self, contig=None, start=0, stop=0, alleles=None, id=None, qual=None, filter=None, info=None, samples=None, **kwargs)\nCreate a new empty VariantRecord.\n\n Arguments are currently experimental. Use with caution and expect\n changes in upcoming releases.\n\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_15new_record(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_contig = 0; + PyObject *__pyx_v_start = 0; + PyObject *__pyx_v_stop = 0; + PyObject *__pyx_v_alleles = 0; + PyObject *__pyx_v_id = 0; + PyObject *__pyx_v_qual = 0; + PyObject *__pyx_v_filter = 0; + PyObject *__pyx_v_info = 0; + PyObject *__pyx_v_samples = 0; + PyObject *__pyx_v_kwargs = 0; + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannySetupContext("new_record", 0); - __Pyx_TraceCall("new_record", __pyx_f[0], 1889, 0, __PYX_ERR(0, 1889, __pyx_L1_error)); - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_new_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1889, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantHeader_15new_record)) { - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); + __Pyx_RefNannySetupContext("new_record (wrapper)", 0); + __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_alleles,&__pyx_n_s_id,&__pyx_n_s_qual,&__pyx_n_s_filter,&__pyx_n_s_info,&__pyx_n_s_samples,0}; + PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)__pyx_int_0); + values[2] = ((PyObject *)__pyx_int_0); + values[3] = ((PyObject *)Py_None); + + /* "pysam/libcbcf.pyx":2047 + * + * def new_record(self, contig=None, start=0, stop=0, alleles=None, + * id=None, qual=None, filter=None, info=None, samples=None, # <<<<<<<<<<<<<< + * **kwargs): + * """Create a new empty VariantRecord. + */ + values[4] = ((PyObject *)Py_None); + values[5] = ((PyObject *)Py_None); + values[6] = ((PyObject *)Py_None); + values[7] = ((PyObject *)Py_None); + values[8] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + CYTHON_FALLTHROUGH; + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_contig); + if (value) { values[0] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start); + if (value) { values[1] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop); + if (value) { values[2] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_alleles); + if (value) { values[3] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 4: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id); + if (value) { values[4] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 5: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_qual); + if (value) { values[5] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 6: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filter); + if (value) { values[6] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 7: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_info); + if (value) { values[7] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 8: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_samples); + if (value) { values[8] = value; kw_args--; } } } - if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1889, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1889, __pyx_L1_error) + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "new_record") < 0)) __PYX_ERR(0, 2046, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + CYTHON_FALLTHROUGH; + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5pysam_7libcbcf_VariantRecord))))) __PYX_ERR(0, 1889, __pyx_L1_error) - __pyx_r = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_2); - __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_contig = values[0]; + __pyx_v_start = values[1]; + __pyx_v_stop = values[2]; + __pyx_v_alleles = values[3]; + __pyx_v_id = values[4]; + __pyx_v_qual = values[5]; + __pyx_v_filter = values[6]; + __pyx_v_info = values[7]; + __pyx_v_samples = values[8]; } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("new_record", 0, 0, 9, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2046, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.new_record", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_14new_record(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_alleles, __pyx_v_id, __pyx_v_qual, __pyx_v_filter, __pyx_v_info, __pyx_v_samples, __pyx_v_kwargs); - /* "pysam/libcbcf.pyx":1891 - * cpdef VariantRecord new_record(self): - * """Create a new empty VariantRecord""" - * r = makeVariantRecord(self, bcf_init()) # <<<<<<<<<<<<<< - * r.ptr.n_sample = bcf_hdr_nsamples(self.ptr) - * return r - */ - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecord(__pyx_v_self, bcf_init())); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1891, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_r = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pysam/libcbcf.pyx":1892 - * """Create a new empty VariantRecord""" - * r = makeVariantRecord(self, bcf_init()) - * r.ptr.n_sample = bcf_hdr_nsamples(self.ptr) # <<<<<<<<<<<<<< - * return r - * - */ - __pyx_v_r->ptr->n_sample = bcf_hdr_nsamples(__pyx_v_self->ptr); - - /* "pysam/libcbcf.pyx":1893 - * r = makeVariantRecord(self, bcf_init()) - * r.ptr.n_sample = bcf_hdr_nsamples(self.ptr) - * return r # <<<<<<<<<<<<<< - * - * def add_record(self, VariantHeaderRecord record): - */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_r)); - __pyx_r = __pyx_v_r; - goto __pyx_L0; - - /* "pysam/libcbcf.pyx":1889 + /* "pysam/libcbcf.pyx":2046 * free(hstr) * - * cpdef VariantRecord new_record(self): # <<<<<<<<<<<<<< - * """Create a new empty VariantRecord""" - * r = makeVariantRecord(self, bcf_init()) + * def new_record(self, contig=None, start=0, stop=0, alleles=None, # <<<<<<<<<<<<<< + * id=None, qual=None, filter=None, info=None, samples=None, + * **kwargs): */ /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.new_record", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_r); - __Pyx_XGIVEREF((PyObject *)__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_15new_record(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_14new_record[] = "VariantHeader.new_record(self) -> VariantRecord\nCreate a new empty VariantRecord"; -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_15new_record(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("new_record (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_14new_record(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self)); - - /* function exit code */ + __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_14new_record(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_14new_record(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_alleles, PyObject *__pyx_v_id, PyObject *__pyx_v_qual, PyObject *__pyx_v_filter, PyObject *__pyx_v_info, PyObject *__pyx_v_samples, PyObject *__pyx_v_kwargs) { + struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_rec = NULL; + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_sample = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + PyObject *(*__pyx_t_6)(PyObject *); + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; __Pyx_RefNannySetupContext("new_record", 0); - __Pyx_TraceCall("new_record (wrapper)", __pyx_f[0], 1889, 0, __PYX_ERR(0, 1889, __pyx_L1_error)); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_13VariantHeader_new_record(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1889, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.new_record", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + __Pyx_TraceCall("new_record", __pyx_f[0], 2046, 0, __PYX_ERR(0, 2046, __pyx_L1_error)); -/* "pysam/libcbcf.pyx":1895 - * return r + /* "pysam/libcbcf.pyx":2055 * - * def add_record(self, VariantHeaderRecord record): # <<<<<<<<<<<<<< - * """Add an existing :class:`VariantHeaderRecord` to this header""" - * if record is None: - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_17add_record(PyObject *__pyx_v_self, PyObject *__pyx_v_record); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_16add_record[] = "VariantHeader.add_record(self, VariantHeaderRecord record)\nAdd an existing :class:`VariantHeaderRecord` to this header"; -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_17add_record(PyObject *__pyx_v_self, PyObject *__pyx_v_record) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("add_record (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_record), __pyx_ptype_5pysam_7libcbcf_VariantHeaderRecord, 1, "record", 0))) __PYX_ERR(0, 1895, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_16add_record(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self), ((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_record)); - - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_16add_record(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_record) { - bcf_hrec_t *__pyx_v_hrec; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("add_record", 0); - __Pyx_TraceCall("add_record", __pyx_f[0], 1895, 0, __PYX_ERR(0, 1895, __pyx_L1_error)); - - /* "pysam/libcbcf.pyx":1897 - * def add_record(self, VariantHeaderRecord record): - * """Add an existing :class:`VariantHeaderRecord` to this header""" - * if record is None: # <<<<<<<<<<<<<< - * raise ValueError('record must not be None') + * """ + * rec = makeVariantRecord(self, bcf_init()) # <<<<<<<<<<<<<< * + * if not rec: */ - __pyx_t_1 = (((PyObject *)__pyx_v_record) == Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (unlikely(__pyx_t_2)) { + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecord(__pyx_v_self, bcf_init())); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2055, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_rec = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":1898 - * """Add an existing :class:`VariantHeaderRecord` to this header""" - * if record is None: - * raise ValueError('record must not be None') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2057 + * rec = makeVariantRecord(self, bcf_init()) + * + * if not rec: # <<<<<<<<<<<<<< + * raise MemoryError('unable to allocate BCF record') * - * cdef bcf_hrec_t *hrec = bcf_hrec_dup(record.ptr) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__101, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1898, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1898, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_rec)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2057, __pyx_L1_error) + __pyx_t_3 = ((!__pyx_t_2) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":1897 - * def add_record(self, VariantHeaderRecord record): - * """Add an existing :class:`VariantHeaderRecord` to this header""" - * if record is None: # <<<<<<<<<<<<<< - * raise ValueError('record must not be None') + /* "pysam/libcbcf.pyx":2058 + * + * if not rec: + * raise MemoryError('unable to allocate BCF record') # <<<<<<<<<<<<<< * + * rec.ptr.n_sample = bcf_hdr_nsamples(self.ptr) */ - } + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__97, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2058, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2058, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1900 - * raise ValueError('record must not be None') + /* "pysam/libcbcf.pyx":2057 + * rec = makeVariantRecord(self, bcf_init()) * - * cdef bcf_hrec_t *hrec = bcf_hrec_dup(record.ptr) # <<<<<<<<<<<<<< + * if not rec: # <<<<<<<<<<<<<< + * raise MemoryError('unable to allocate BCF record') * - * bcf_hdr_add_hrec(self.ptr, hrec) */ - __pyx_v_hrec = bcf_hrec_dup(__pyx_v_record->ptr); + } - /* "pysam/libcbcf.pyx":1902 - * cdef bcf_hrec_t *hrec = bcf_hrec_dup(record.ptr) + /* "pysam/libcbcf.pyx":2060 + * raise MemoryError('unable to allocate BCF record') * - * bcf_hdr_add_hrec(self.ptr, hrec) # <<<<<<<<<<<<<< + * rec.ptr.n_sample = bcf_hdr_nsamples(self.ptr) # <<<<<<<<<<<<<< * - * if self.ptr.dirty: + * if contig is not None: */ - (void)(bcf_hdr_add_hrec(__pyx_v_self->ptr, __pyx_v_hrec)); + __pyx_v_rec->ptr->n_sample = bcf_hdr_nsamples(__pyx_v_self->ptr); - /* "pysam/libcbcf.pyx":1904 - * bcf_hdr_add_hrec(self.ptr, hrec) - * - * if self.ptr.dirty: # <<<<<<<<<<<<<< - * bcf_hdr_sync(self.ptr) + /* "pysam/libcbcf.pyx":2062 + * rec.ptr.n_sample = bcf_hdr_nsamples(self.ptr) * + * if contig is not None: # <<<<<<<<<<<<<< + * rec.contig = contig + * if alleles is not None: */ - __pyx_t_2 = (__pyx_v_self->ptr->dirty != 0); + __pyx_t_3 = (__pyx_v_contig != Py_None); + __pyx_t_2 = (__pyx_t_3 != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1905 - * - * if self.ptr.dirty: - * bcf_hdr_sync(self.ptr) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2063 * - * def add_line(self, line): + * if contig is not None: + * rec.contig = contig # <<<<<<<<<<<<<< + * if alleles is not None: + * rec.alleles = alleles */ - (void)(bcf_hdr_sync(__pyx_v_self->ptr)); + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_contig, __pyx_v_contig) < 0) __PYX_ERR(0, 2063, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1904 - * bcf_hdr_add_hrec(self.ptr, hrec) - * - * if self.ptr.dirty: # <<<<<<<<<<<<<< - * bcf_hdr_sync(self.ptr) + /* "pysam/libcbcf.pyx":2062 + * rec.ptr.n_sample = bcf_hdr_nsamples(self.ptr) * + * if contig is not None: # <<<<<<<<<<<<<< + * rec.contig = contig + * if alleles is not None: */ } - /* "pysam/libcbcf.pyx":1895 - * return r + /* "pysam/libcbcf.pyx":2064 + * if contig is not None: + * rec.contig = contig + * if alleles is not None: # <<<<<<<<<<<<<< + * rec.alleles = alleles * - * def add_record(self, VariantHeaderRecord record): # <<<<<<<<<<<<<< - * """Add an existing :class:`VariantHeaderRecord` to this header""" - * if record is None: */ + __pyx_t_2 = (__pyx_v_alleles != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.add_record", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcbcf.pyx":1907 - * bcf_hdr_sync(self.ptr) + /* "pysam/libcbcf.pyx":2065 + * rec.contig = contig + * if alleles is not None: + * rec.alleles = alleles # <<<<<<<<<<<<<< * - * def add_line(self, line): # <<<<<<<<<<<<<< - * """Add a metadata line to this header""" - * bline = force_bytes(line) - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_19add_line(PyObject *__pyx_v_self, PyObject *__pyx_v_line); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_18add_line[] = "VariantHeader.add_line(self, line)\nAdd a metadata line to this header"; -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_19add_line(PyObject *__pyx_v_self, PyObject *__pyx_v_line) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("add_line (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_18add_line(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self), ((PyObject *)__pyx_v_line)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_18add_line(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, PyObject *__pyx_v_line) { - PyObject *__pyx_v_bline = NULL; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - char const *__pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("add_line", 0); - __Pyx_TraceCall("add_line", __pyx_f[0], 1907, 0, __PYX_ERR(0, 1907, __pyx_L1_error)); - - /* "pysam/libcbcf.pyx":1909 - * def add_line(self, line): - * """Add a metadata line to this header""" - * bline = force_bytes(line) # <<<<<<<<<<<<<< - * if bcf_hdr_append(self.ptr, bline) < 0: - * raise ValueError('invalid header line') + * rec.start = start */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_line, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1909, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_bline = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_alleles, __pyx_v_alleles) < 0) __PYX_ERR(0, 2065, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1910 - * """Add a metadata line to this header""" - * bline = force_bytes(line) - * if bcf_hdr_append(self.ptr, bline) < 0: # <<<<<<<<<<<<<< - * raise ValueError('invalid header line') + /* "pysam/libcbcf.pyx":2064 + * if contig is not None: + * rec.contig = contig + * if alleles is not None: # <<<<<<<<<<<<<< + * rec.alleles = alleles * */ - if (unlikely(__pyx_v_bline == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 1910, __pyx_L1_error) } - __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_bline); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 1910, __pyx_L1_error) - __pyx_t_3 = ((bcf_hdr_append(__pyx_v_self->ptr, __pyx_t_2) < 0) != 0); - if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":1911 - * bline = force_bytes(line) - * if bcf_hdr_append(self.ptr, bline) < 0: - * raise ValueError('invalid header line') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2067 + * rec.alleles = alleles * - * if self.ptr.dirty: + * rec.start = start # <<<<<<<<<<<<<< + * rec.stop = stop + * rec.id = id */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__102, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1911, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1911, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_start, __pyx_v_start) < 0) __PYX_ERR(0, 2067, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1910 - * """Add a metadata line to this header""" - * bline = force_bytes(line) - * if bcf_hdr_append(self.ptr, bline) < 0: # <<<<<<<<<<<<<< - * raise ValueError('invalid header line') + /* "pysam/libcbcf.pyx":2068 * + * rec.start = start + * rec.stop = stop # <<<<<<<<<<<<<< + * rec.id = id + * rec.qual = qual */ - } + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_stop, __pyx_v_stop) < 0) __PYX_ERR(0, 2068, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1913 - * raise ValueError('invalid header line') - * - * if self.ptr.dirty: # <<<<<<<<<<<<<< - * bcf_hdr_sync(self.ptr) + /* "pysam/libcbcf.pyx":2069 + * rec.start = start + * rec.stop = stop + * rec.id = id # <<<<<<<<<<<<<< + * rec.qual = qual * */ - __pyx_t_3 = (__pyx_v_self->ptr->dirty != 0); - if (__pyx_t_3) { + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_id, __pyx_v_id) < 0) __PYX_ERR(0, 2069, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1914 - * - * if self.ptr.dirty: - * bcf_hdr_sync(self.ptr) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2070 + * rec.stop = stop + * rec.id = id + * rec.qual = qual # <<<<<<<<<<<<<< * - * def add_meta(self, key, value=None, items=None): + * if filter is not None: */ - (void)(bcf_hdr_sync(__pyx_v_self->ptr)); + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_qual, __pyx_v_qual) < 0) __PYX_ERR(0, 2070, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1913 - * raise ValueError('invalid header line') - * - * if self.ptr.dirty: # <<<<<<<<<<<<<< - * bcf_hdr_sync(self.ptr) + /* "pysam/libcbcf.pyx":2072 + * rec.qual = qual * + * if filter is not None: # <<<<<<<<<<<<<< + * if isinstance(filter, (list, tuple, VariantRecordFilter)): + * for f in filter: */ - } + __pyx_t_3 = (__pyx_v_filter != Py_None); + __pyx_t_2 = (__pyx_t_3 != 0); + if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1907 - * bcf_hdr_sync(self.ptr) + /* "pysam/libcbcf.pyx":2073 + * + * if filter is not None: + * if isinstance(filter, (list, tuple, VariantRecordFilter)): # <<<<<<<<<<<<<< + * for f in filter: + * rec.filter.add(f) + */ + __pyx_t_3 = PyList_Check(__pyx_v_filter); + __pyx_t_4 = (__pyx_t_3 != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L8_bool_binop_done; + } + __pyx_t_4 = PyTuple_Check(__pyx_v_filter); + __pyx_t_3 = (__pyx_t_4 != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_2 = __pyx_t_3; + goto __pyx_L8_bool_binop_done; + } + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_filter, __pyx_ptype_5pysam_7libcbcf_VariantRecordFilter); + __pyx_t_4 = (__pyx_t_3 != 0); + __pyx_t_2 = __pyx_t_4; + __pyx_L8_bool_binop_done:; + __pyx_t_4 = (__pyx_t_2 != 0); + if (__pyx_t_4) { + + /* "pysam/libcbcf.pyx":2074 + * if filter is not None: + * if isinstance(filter, (list, tuple, VariantRecordFilter)): + * for f in filter: # <<<<<<<<<<<<<< + * rec.filter.add(f) + * else: + */ + if (likely(PyList_CheckExact(__pyx_v_filter)) || PyTuple_CheckExact(__pyx_v_filter)) { + __pyx_t_1 = __pyx_v_filter; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_filter); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2074, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2074, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_6)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 2074, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2074, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } else { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 2074, __pyx_L1_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2074, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } + } else { + __pyx_t_7 = __pyx_t_6(__pyx_t_1); + if (unlikely(!__pyx_t_7)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2074, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF_SET(__pyx_v_f, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pysam/libcbcf.pyx":2075 + * if isinstance(filter, (list, tuple, VariantRecordFilter)): + * for f in filter: + * rec.filter.add(f) # <<<<<<<<<<<<<< + * else: + * rec.filter.add(filter) + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_filter); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2075, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_add); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2075, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + if (!__pyx_t_8) { + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_f); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2075, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_f}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2075, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_f}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2075, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + { + __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2075, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_INCREF(__pyx_v_f); + __Pyx_GIVEREF(__pyx_v_f); + PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_f); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2075, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pysam/libcbcf.pyx":2074 + * if filter is not None: + * if isinstance(filter, (list, tuple, VariantRecordFilter)): + * for f in filter: # <<<<<<<<<<<<<< + * rec.filter.add(f) + * else: + */ + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":2073 + * + * if filter is not None: + * if isinstance(filter, (list, tuple, VariantRecordFilter)): # <<<<<<<<<<<<<< + * for f in filter: + * rec.filter.add(f) + */ + goto __pyx_L7; + } + + /* "pysam/libcbcf.pyx":2077 + * rec.filter.add(f) + * else: + * rec.filter.add(filter) # <<<<<<<<<<<<<< + * + * if info: + */ + /*else*/ { + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_filter); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2077, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_add); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2077, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + if (!__pyx_t_7) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_filter); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2077, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_filter}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2077, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_filter}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2077, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2077, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7); __pyx_t_7 = NULL; + __Pyx_INCREF(__pyx_v_filter); + __Pyx_GIVEREF(__pyx_v_filter); + PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_filter); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2077, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __pyx_L7:; + + /* "pysam/libcbcf.pyx":2072 + * rec.qual = qual + * + * if filter is not None: # <<<<<<<<<<<<<< + * if isinstance(filter, (list, tuple, VariantRecordFilter)): + * for f in filter: + */ + } + + /* "pysam/libcbcf.pyx":2079 + * rec.filter.add(filter) + * + * if info: # <<<<<<<<<<<<<< + * rec.info.update(info) + * + */ + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_info); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2079, __pyx_L1_error) + if (__pyx_t_4) { + + /* "pysam/libcbcf.pyx":2080 + * + * if info: + * rec.info.update(info) # <<<<<<<<<<<<<< + * + * if kwargs: + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_info); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_update); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + } + } + if (!__pyx_t_9) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_v_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_10)) { + PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_info}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { + PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_info}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); __pyx_t_9 = NULL; + __Pyx_INCREF(__pyx_v_info); + __Pyx_GIVEREF(__pyx_v_info); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_info); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2080, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":2079 + * rec.filter.add(filter) + * + * if info: # <<<<<<<<<<<<<< + * rec.info.update(info) + * + */ + } + + /* "pysam/libcbcf.pyx":2082 + * rec.info.update(info) + * + * if kwargs: # <<<<<<<<<<<<<< + * if 'GT' in kwargs: + * rec.samples[0]['GT'] = kwargs.pop('GT') + */ + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_kwargs); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2082, __pyx_L1_error) + if (__pyx_t_4) { + + /* "pysam/libcbcf.pyx":2083 + * + * if kwargs: + * if 'GT' in kwargs: # <<<<<<<<<<<<<< + * rec.samples[0]['GT'] = kwargs.pop('GT') + * rec.samples[0].update(kwargs) + */ + __pyx_t_4 = (__Pyx_PyDict_ContainsTF(__pyx_n_s_GT, __pyx_v_kwargs, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2083, __pyx_L1_error) + __pyx_t_2 = (__pyx_t_4 != 0); + if (__pyx_t_2) { + + /* "pysam/libcbcf.pyx":2084 + * if kwargs: + * if 'GT' in kwargs: + * rec.samples[0]['GT'] = kwargs.pop('GT') # <<<<<<<<<<<<<< + * rec.samples[0].update(kwargs) + * + */ + __pyx_t_1 = __Pyx_PyDict_Pop(__pyx_v_kwargs, __pyx_n_s_GT, ((PyObject *)NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_samples); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_10, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2084, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(PyObject_SetItem(__pyx_t_7, __pyx_n_s_GT, __pyx_t_1) < 0)) __PYX_ERR(0, 2084, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":2083 + * + * if kwargs: + * if 'GT' in kwargs: # <<<<<<<<<<<<<< + * rec.samples[0]['GT'] = kwargs.pop('GT') + * rec.samples[0].update(kwargs) + */ + } + + /* "pysam/libcbcf.pyx":2085 + * if 'GT' in kwargs: + * rec.samples[0]['GT'] = kwargs.pop('GT') + * rec.samples[0].update(kwargs) # <<<<<<<<<<<<<< + * + * if samples: + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_samples); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2085, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2085, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2085, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_10) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_kwargs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2085, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_kwargs}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2085, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_kwargs}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2085, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2085, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_INCREF(__pyx_v_kwargs); + __Pyx_GIVEREF(__pyx_v_kwargs); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_kwargs); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2085, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":2082 + * rec.info.update(info) + * + * if kwargs: # <<<<<<<<<<<<<< + * if 'GT' in kwargs: + * rec.samples[0]['GT'] = kwargs.pop('GT') + */ + } + + /* "pysam/libcbcf.pyx":2087 + * rec.samples[0].update(kwargs) + * + * if samples: # <<<<<<<<<<<<<< + * for i, sample in enumerate(samples): + * if 'GT' in sample: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_samples); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2087, __pyx_L1_error) + if (__pyx_t_2) { + + /* "pysam/libcbcf.pyx":2088 + * + * if samples: + * for i, sample in enumerate(samples): # <<<<<<<<<<<<<< + * if 'GT' in sample: + * rec.samples[i]['GT'] = sample.pop('GT') + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (likely(PyList_CheckExact(__pyx_v_samples)) || PyTuple_CheckExact(__pyx_v_samples)) { + __pyx_t_7 = __pyx_v_samples; __Pyx_INCREF(__pyx_t_7); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_samples); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2088, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2088, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_6)) { + if (likely(PyList_CheckExact(__pyx_t_7))) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_9 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_9); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 2088, __pyx_L1_error) + #else + __pyx_t_9 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2088, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + } else { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_9); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 2088, __pyx_L1_error) + #else + __pyx_t_9 = PySequence_ITEM(__pyx_t_7, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2088, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + #endif + } + } else { + __pyx_t_9 = __pyx_t_6(__pyx_t_7); + if (unlikely(!__pyx_t_9)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2088, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_9); + } + __Pyx_XDECREF_SET(__pyx_v_sample, __pyx_t_9); + __pyx_t_9 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1); + __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2088, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_9; + __pyx_t_9 = 0; + + /* "pysam/libcbcf.pyx":2089 + * if samples: + * for i, sample in enumerate(samples): + * if 'GT' in sample: # <<<<<<<<<<<<<< + * rec.samples[i]['GT'] = sample.pop('GT') + * rec.samples[i].update(sample) + */ + __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_GT, __pyx_v_sample, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2089, __pyx_L1_error) + __pyx_t_4 = (__pyx_t_2 != 0); + if (__pyx_t_4) { + + /* "pysam/libcbcf.pyx":2090 + * for i, sample in enumerate(samples): + * if 'GT' in sample: + * rec.samples[i]['GT'] = sample.pop('GT') # <<<<<<<<<<<<<< + * rec.samples[i].update(sample) + * + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_sample, __pyx_n_s_pop); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2090, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__98, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2090, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_samples); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2090, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_9, __pyx_v_i); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2090, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(PyObject_SetItem(__pyx_t_8, __pyx_n_s_GT, __pyx_t_10) < 0)) __PYX_ERR(0, 2090, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pysam/libcbcf.pyx":2089 + * if samples: + * for i, sample in enumerate(samples): + * if 'GT' in sample: # <<<<<<<<<<<<<< + * rec.samples[i]['GT'] = sample.pop('GT') + * rec.samples[i].update(sample) + */ + } + + /* "pysam/libcbcf.pyx":2091 + * if 'GT' in sample: + * rec.samples[i]['GT'] = sample.pop('GT') + * rec.samples[i].update(sample) # <<<<<<<<<<<<<< + * + * return rec + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_rec), __pyx_n_s_samples); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_v_i); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + if (!__pyx_t_9) { + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_sample); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_sample}; + __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2091, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_10); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_sample}; + __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2091, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_10); + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL; + __Pyx_INCREF(__pyx_v_sample); + __Pyx_GIVEREF(__pyx_v_sample); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_sample); + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "pysam/libcbcf.pyx":2088 + * + * if samples: + * for i, sample in enumerate(samples): # <<<<<<<<<<<<<< + * if 'GT' in sample: + * rec.samples[i]['GT'] = sample.pop('GT') + */ + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":2087 + * rec.samples[0].update(kwargs) + * + * if samples: # <<<<<<<<<<<<<< + * for i, sample in enumerate(samples): + * if 'GT' in sample: + */ + } + + /* "pysam/libcbcf.pyx":2093 + * rec.samples[i].update(sample) + * + * return rec # <<<<<<<<<<<<<< + * + * def add_record(self, VariantHeaderRecord record): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_rec)); + __pyx_r = ((PyObject *)__pyx_v_rec); + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2046 + * free(hstr) + * + * def new_record(self, contig=None, start=0, stop=0, alleles=None, # <<<<<<<<<<<<<< + * id=None, qual=None, filter=None, info=None, samples=None, + * **kwargs): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.new_record", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_rec); + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_sample); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2095 + * return rec + * + * def add_record(self, VariantHeaderRecord record): # <<<<<<<<<<<<<< + * """Add an existing :class:`VariantHeaderRecord` to this header""" + * if record is None: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_17add_record(PyObject *__pyx_v_self, PyObject *__pyx_v_record); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_16add_record[] = "VariantHeader.add_record(self, VariantHeaderRecord record)\nAdd an existing :class:`VariantHeaderRecord` to this header"; +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_17add_record(PyObject *__pyx_v_self, PyObject *__pyx_v_record) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_record (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_record), __pyx_ptype_5pysam_7libcbcf_VariantHeaderRecord, 1, "record", 0))) __PYX_ERR(0, 2095, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_16add_record(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self), ((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *)__pyx_v_record)); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_16add_record(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecord *__pyx_v_record) { + bcf_hrec_t *__pyx_v_hrec; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("add_record", 0); + __Pyx_TraceCall("add_record", __pyx_f[0], 2095, 0, __PYX_ERR(0, 2095, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2097 + * def add_record(self, VariantHeaderRecord record): + * """Add an existing :class:`VariantHeaderRecord` to this header""" + * if record is None: # <<<<<<<<<<<<<< + * raise ValueError('record must not be None') + * + */ + __pyx_t_1 = (((PyObject *)__pyx_v_record) == Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (unlikely(__pyx_t_2)) { + + /* "pysam/libcbcf.pyx":2098 + * """Add an existing :class:`VariantHeaderRecord` to this header""" + * if record is None: + * raise ValueError('record must not be None') # <<<<<<<<<<<<<< + * + * cdef bcf_hrec_t *hrec = bcf_hrec_dup(record.ptr) + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__99, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2098, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 2098, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2097 + * def add_record(self, VariantHeaderRecord record): + * """Add an existing :class:`VariantHeaderRecord` to this header""" + * if record is None: # <<<<<<<<<<<<<< + * raise ValueError('record must not be None') + * + */ + } + + /* "pysam/libcbcf.pyx":2100 + * raise ValueError('record must not be None') + * + * cdef bcf_hrec_t *hrec = bcf_hrec_dup(record.ptr) # <<<<<<<<<<<<<< + * + * bcf_hdr_add_hrec(self.ptr, hrec) + */ + __pyx_v_hrec = bcf_hrec_dup(__pyx_v_record->ptr); + + /* "pysam/libcbcf.pyx":2102 + * cdef bcf_hrec_t *hrec = bcf_hrec_dup(record.ptr) + * + * bcf_hdr_add_hrec(self.ptr, hrec) # <<<<<<<<<<<<<< + * + * if self.ptr.dirty: + */ + (void)(bcf_hdr_add_hrec(__pyx_v_self->ptr, __pyx_v_hrec)); + + /* "pysam/libcbcf.pyx":2104 + * bcf_hdr_add_hrec(self.ptr, hrec) + * + * if self.ptr.dirty: # <<<<<<<<<<<<<< + * bcf_hdr_sync(self.ptr) + * + */ + __pyx_t_2 = (__pyx_v_self->ptr->dirty != 0); + if (__pyx_t_2) { + + /* "pysam/libcbcf.pyx":2105 + * + * if self.ptr.dirty: + * bcf_hdr_sync(self.ptr) # <<<<<<<<<<<<<< + * + * def add_line(self, line): + */ + (void)(bcf_hdr_sync(__pyx_v_self->ptr)); + + /* "pysam/libcbcf.pyx":2104 + * bcf_hdr_add_hrec(self.ptr, hrec) + * + * if self.ptr.dirty: # <<<<<<<<<<<<<< + * bcf_hdr_sync(self.ptr) + * + */ + } + + /* "pysam/libcbcf.pyx":2095 + * return rec + * + * def add_record(self, VariantHeaderRecord record): # <<<<<<<<<<<<<< + * """Add an existing :class:`VariantHeaderRecord` to this header""" + * if record is None: + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.add_record", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2107 + * bcf_hdr_sync(self.ptr) * * def add_line(self, line): # <<<<<<<<<<<<<< * """Add a metadata line to this header""" * bline = force_bytes(line) */ +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_19add_line(PyObject *__pyx_v_self, PyObject *__pyx_v_line); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_18add_line[] = "VariantHeader.add_line(self, line)\nAdd a metadata line to this header"; +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_19add_line(PyObject *__pyx_v_self, PyObject *__pyx_v_line) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_line (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_18add_line(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self), ((PyObject *)__pyx_v_line)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_18add_line(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, PyObject *__pyx_v_line) { + PyObject *__pyx_v_bline = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + char const *__pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("add_line", 0); + __Pyx_TraceCall("add_line", __pyx_f[0], 2107, 0, __PYX_ERR(0, 2107, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2109 + * def add_line(self, line): + * """Add a metadata line to this header""" + * bline = force_bytes(line) # <<<<<<<<<<<<<< + * if bcf_hdr_append(self.ptr, bline) < 0: + * raise ValueError('invalid header line') + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_line, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2109, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_bline = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":2110 + * """Add a metadata line to this header""" + * bline = force_bytes(line) + * if bcf_hdr_append(self.ptr, bline) < 0: # <<<<<<<<<<<<<< + * raise ValueError('invalid header line') + * + */ + if (unlikely(__pyx_v_bline == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2110, __pyx_L1_error) + } + __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_bline); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 2110, __pyx_L1_error) + __pyx_t_3 = ((bcf_hdr_append(__pyx_v_self->ptr, __pyx_t_2) < 0) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcbcf.pyx":2111 + * bline = force_bytes(line) + * if bcf_hdr_append(self.ptr, bline) < 0: + * raise ValueError('invalid header line') # <<<<<<<<<<<<<< + * + * if self.ptr.dirty: + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__100, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2111, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2110 + * """Add a metadata line to this header""" + * bline = force_bytes(line) + * if bcf_hdr_append(self.ptr, bline) < 0: # <<<<<<<<<<<<<< + * raise ValueError('invalid header line') + * + */ + } + + /* "pysam/libcbcf.pyx":2113 + * raise ValueError('invalid header line') + * + * if self.ptr.dirty: # <<<<<<<<<<<<<< + * bcf_hdr_sync(self.ptr) + * + */ + __pyx_t_3 = (__pyx_v_self->ptr->dirty != 0); + if (__pyx_t_3) { + + /* "pysam/libcbcf.pyx":2114 + * + * if self.ptr.dirty: + * bcf_hdr_sync(self.ptr) # <<<<<<<<<<<<<< + * + * def add_meta(self, key, value=None, items=None): + */ + (void)(bcf_hdr_sync(__pyx_v_self->ptr)); + + /* "pysam/libcbcf.pyx":2113 + * raise ValueError('invalid header line') + * + * if self.ptr.dirty: # <<<<<<<<<<<<<< + * bcf_hdr_sync(self.ptr) + * + */ + } + + /* "pysam/libcbcf.pyx":2107 + * bcf_hdr_sync(self.ptr) + * + * def add_line(self, line): # <<<<<<<<<<<<<< + * """Add a metadata line to this header""" + * bline = force_bytes(line) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.add_line", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_bline); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2116 + * bcf_hdr_sync(self.ptr) + * + * def add_meta(self, key, value=None, items=None): # <<<<<<<<<<<<<< + * """Add metadata to this header""" + * if not ((value is not None) ^ (items is not None)): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_21add_meta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_20add_meta[] = "VariantHeader.add_meta(self, key, value=None, items=None)\nAdd metadata to this header"; +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_21add_meta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_key = 0; + PyObject *__pyx_v_value = 0; + PyObject *__pyx_v_items = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_meta (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_value,&__pyx_n_s_items,0}; + PyObject* values[3] = {0,0,0}; + values[1] = ((PyObject *)Py_None); + values[2] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value); + if (value) { values[1] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_meta") < 0)) __PYX_ERR(0, 2116, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_key = values[0]; + __pyx_v_value = values[1]; + __pyx_v_items = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("add_meta", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2116, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.add_meta", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_20add_meta(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self), __pyx_v_key, __pyx_v_value, __pyx_v_items); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_20add_meta(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value, PyObject *__pyx_v_items) { + bcf_hrec_t *__pyx_v_hrec; + int __pyx_v_quoted; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + char const *__pyx_t_8; + Py_ssize_t __pyx_t_9; + PyObject *(*__pyx_t_10)(PyObject *); + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *(*__pyx_t_15)(PyObject *); + char const *__pyx_t_16; + Py_ssize_t __pyx_t_17; + char const *__pyx_t_18; + char const *__pyx_t_19; + __Pyx_RefNannySetupContext("add_meta", 0); + __Pyx_TraceCall("add_meta", __pyx_f[0], 2116, 0, __PYX_ERR(0, 2116, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_key); + __Pyx_INCREF(__pyx_v_value); + + /* "pysam/libcbcf.pyx":2118 + * def add_meta(self, key, value=None, items=None): + * """Add metadata to this header""" + * if not ((value is not None) ^ (items is not None)): # <<<<<<<<<<<<<< + * raise ValueError('either value or items must be specified') + * + */ + __pyx_t_1 = (__pyx_v_value != Py_None); + __pyx_t_2 = (__pyx_v_items != Py_None); + __pyx_t_3 = ((!((__pyx_t_1 ^ __pyx_t_2) != 0)) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcbcf.pyx":2119 + * """Add metadata to this header""" + * if not ((value is not None) ^ (items is not None)): + * raise ValueError('either value or items must be specified') # <<<<<<<<<<<<<< + * + * cdef bcf_hrec_t *hrec = calloc(1, sizeof(bcf_hrec_t)) + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__101, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2119, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2118 + * def add_meta(self, key, value=None, items=None): + * """Add metadata to this header""" + * if not ((value is not None) ^ (items is not None)): # <<<<<<<<<<<<<< + * raise ValueError('either value or items must be specified') + * + */ + } + + /* "pysam/libcbcf.pyx":2121 + * raise ValueError('either value or items must be specified') + * + * cdef bcf_hrec_t *hrec = calloc(1, sizeof(bcf_hrec_t)) # <<<<<<<<<<<<<< + * cdef int quoted + * + */ + __pyx_v_hrec = ((bcf_hrec_t *)calloc(1, (sizeof(bcf_hrec_t)))); + + /* "pysam/libcbcf.pyx":2124 + * cdef int quoted + * + * try: # <<<<<<<<<<<<<< + * key = force_bytes(key) + * hrec.key = strdup(key) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + + /* "pysam/libcbcf.pyx":2125 + * + * try: + * key = force_bytes(key) # <<<<<<<<<<<<<< + * hrec.key = strdup(key) + * + */ + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2125, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pysam/libcbcf.pyx":2126 + * try: + * key = force_bytes(key) + * hrec.key = strdup(key) # <<<<<<<<<<<<<< + * + * if value is not None: + */ + __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_key); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 2126, __pyx_L4_error) + __pyx_v_hrec->key = strdup(__pyx_t_8); + + /* "pysam/libcbcf.pyx":2128 + * hrec.key = strdup(key) + * + * if value is not None: # <<<<<<<<<<<<<< + * hrec.value = strdup(force_bytes(value)) + * else: + */ + __pyx_t_3 = (__pyx_v_value != Py_None); + __pyx_t_2 = (__pyx_t_3 != 0); + if (__pyx_t_2) { + + /* "pysam/libcbcf.pyx":2129 + * + * if value is not None: + * hrec.value = strdup(force_bytes(value)) # <<<<<<<<<<<<<< + * else: + * for key, value in items: + */ + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2129, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + if (unlikely(__pyx_t_4 == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2129, __pyx_L4_error) + } + __pyx_t_8 = __Pyx_PyBytes_AsString(__pyx_t_4); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 2129, __pyx_L4_error) + __pyx_v_hrec->value = strdup(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libcbcf.pyx":2128 + * hrec.key = strdup(key) + * + * if value is not None: # <<<<<<<<<<<<<< + * hrec.value = strdup(force_bytes(value)) + * else: + */ + goto __pyx_L10; + } + + /* "pysam/libcbcf.pyx":2131 + * hrec.value = strdup(force_bytes(value)) + * else: + * for key, value in items: # <<<<<<<<<<<<<< + * key = force_bytes(key) + * bcf_hrec_add_key(hrec, key, len(key)) + */ + /*else*/ { + if (likely(PyList_CheckExact(__pyx_v_items)) || PyTuple_CheckExact(__pyx_v_items)) { + __pyx_t_4 = __pyx_v_items; __Pyx_INCREF(__pyx_t_4); __pyx_t_9 = 0; + __pyx_t_10 = NULL; + } else { + __pyx_t_9 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_items); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2131, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_10 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2131, __pyx_L4_error) + } + for (;;) { + if (likely(!__pyx_t_10)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_11 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_9); __Pyx_INCREF(__pyx_t_11); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 2131, __pyx_L4_error) + #else + __pyx_t_11 = PySequence_ITEM(__pyx_t_4, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2131, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_11); + #endif + } else { + if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_9); __Pyx_INCREF(__pyx_t_11); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 2131, __pyx_L4_error) + #else + __pyx_t_11 = PySequence_ITEM(__pyx_t_4, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2131, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_11); + #endif + } + } else { + __pyx_t_11 = __pyx_t_10(__pyx_t_4); + if (unlikely(!__pyx_t_11)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2131, __pyx_L4_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_11); + } + if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) { + PyObject* sequence = __pyx_t_11; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 2131, __pyx_L4_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_12 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_13 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_12 = PyList_GET_ITEM(sequence, 0); + __pyx_t_13 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(__pyx_t_13); + #else + __pyx_t_12 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2131, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2131, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_13); + #endif + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_14 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2131, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext; + index = 0; __pyx_t_12 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_12)) goto __pyx_L13_unpacking_failed; + __Pyx_GOTREF(__pyx_t_12); + index = 1; __pyx_t_13 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_13)) goto __pyx_L13_unpacking_failed; + __Pyx_GOTREF(__pyx_t_13); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) __PYX_ERR(0, 2131, __pyx_L4_error) + __pyx_t_15 = NULL; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L14_unpacking_done; + __pyx_L13_unpacking_failed:; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_15 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2131, __pyx_L4_error) + __pyx_L14_unpacking_done:; + } + __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_12); + __pyx_t_12 = 0; + __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_13); + __pyx_t_13 = 0; + + /* "pysam/libcbcf.pyx":2132 + * else: + * for key, value in items: + * key = force_bytes(key) # <<<<<<<<<<<<<< + * bcf_hrec_add_key(hrec, key, len(key)) + * + */ + __pyx_t_11 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2132, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_11); + __pyx_t_11 = 0; + + /* "pysam/libcbcf.pyx":2133 + * for key, value in items: + * key = force_bytes(key) + * bcf_hrec_add_key(hrec, key, len(key)) # <<<<<<<<<<<<<< + * + * value = force_bytes(str(value)) + */ + __pyx_t_16 = __Pyx_PyObject_AsString(__pyx_v_key); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 2133, __pyx_L4_error) + __pyx_t_17 = PyObject_Length(__pyx_v_key); if (unlikely(__pyx_t_17 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2133, __pyx_L4_error) + bcf_hrec_add_key(__pyx_v_hrec, __pyx_t_16, ((int)__pyx_t_17)); + + /* "pysam/libcbcf.pyx":2135 + * bcf_hrec_add_key(hrec, key, len(key)) + * + * value = force_bytes(str(value)) # <<<<<<<<<<<<<< + * quoted = strpbrk(value, ' ;,"\t<>') != NULL + * bcf_hrec_set_val(hrec, hrec.nkeys-1, value, len(value), quoted) + */ + __pyx_t_11 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_value); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2135, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_13 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_11, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2135, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_13); + __pyx_t_13 = 0; + + /* "pysam/libcbcf.pyx":2136 + * + * value = force_bytes(str(value)) + * quoted = strpbrk(value, ' ;,"\t<>') != NULL # <<<<<<<<<<<<<< + * bcf_hrec_set_val(hrec, hrec.nkeys-1, value, len(value), quoted) + * except: + */ + __pyx_t_18 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_18) && PyErr_Occurred())) __PYX_ERR(0, 2136, __pyx_L4_error) + __pyx_v_quoted = (strpbrk(__pyx_t_18, ((char const *)" ;,\"\t<>")) != NULL); + + /* "pysam/libcbcf.pyx":2137 + * value = force_bytes(str(value)) + * quoted = strpbrk(value, ' ;,"\t<>') != NULL + * bcf_hrec_set_val(hrec, hrec.nkeys-1, value, len(value), quoted) # <<<<<<<<<<<<<< + * except: + * bcf_hrec_destroy(hrec) + */ + __pyx_t_19 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 2137, __pyx_L4_error) + __pyx_t_17 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_17 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2137, __pyx_L4_error) + bcf_hrec_set_val(__pyx_v_hrec, (__pyx_v_hrec->nkeys - 1), __pyx_t_19, ((int)__pyx_t_17), __pyx_v_quoted); + + /* "pysam/libcbcf.pyx":2131 + * hrec.value = strdup(force_bytes(value)) + * else: + * for key, value in items: # <<<<<<<<<<<<<< + * key = force_bytes(key) + * bcf_hrec_add_key(hrec, key, len(key)) + */ + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_L10:; + + /* "pysam/libcbcf.pyx":2124 + * cdef int quoted + * + * try: # <<<<<<<<<<<<<< + * key = force_bytes(key) + * hrec.key = strdup(key) + */ + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L9_try_end; + __pyx_L4_error:; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libcbcf.pyx":2138 + * quoted = strpbrk(value, ' ;,"\t<>') != NULL + * bcf_hrec_set_val(hrec, hrec.nkeys-1, value, len(value), quoted) + * except: # <<<<<<<<<<<<<< + * bcf_hrec_destroy(hrec) + * raise + */ + /*except:*/ { + __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.add_meta", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_13, &__pyx_t_11) < 0) __PYX_ERR(0, 2138, __pyx_L6_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_13); + __Pyx_GOTREF(__pyx_t_11); + + /* "pysam/libcbcf.pyx":2139 + * bcf_hrec_set_val(hrec, hrec.nkeys-1, value, len(value), quoted) + * except: + * bcf_hrec_destroy(hrec) # <<<<<<<<<<<<<< + * raise + * + */ + bcf_hrec_destroy(__pyx_v_hrec); + + /* "pysam/libcbcf.pyx":2140 + * except: + * bcf_hrec_destroy(hrec) + * raise # <<<<<<<<<<<<<< + * + * bcf_hdr_add_hrec(self.ptr, hrec) + */ + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_13); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_13, __pyx_t_11); + __pyx_t_4 = 0; __pyx_t_13 = 0; __pyx_t_11 = 0; + __PYX_ERR(0, 2140, __pyx_L6_except_error) + } + __pyx_L6_except_error:; + + /* "pysam/libcbcf.pyx":2124 + * cdef int quoted + * + * try: # <<<<<<<<<<<<<< + * key = force_bytes(key) + * hrec.key = strdup(key) + */ + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L9_try_end:; + } + + /* "pysam/libcbcf.pyx":2142 + * raise + * + * bcf_hdr_add_hrec(self.ptr, hrec) # <<<<<<<<<<<<<< + * + * if self.ptr.dirty: + */ + (void)(bcf_hdr_add_hrec(__pyx_v_self->ptr, __pyx_v_hrec)); + + /* "pysam/libcbcf.pyx":2144 + * bcf_hdr_add_hrec(self.ptr, hrec) + * + * if self.ptr.dirty: # <<<<<<<<<<<<<< + * bcf_hdr_sync(self.ptr) + * + */ + __pyx_t_2 = (__pyx_v_self->ptr->dirty != 0); + if (__pyx_t_2) { + + /* "pysam/libcbcf.pyx":2145 + * + * if self.ptr.dirty: + * bcf_hdr_sync(self.ptr) # <<<<<<<<<<<<<< + * + * def add_sample(self, name): + */ + (void)(bcf_hdr_sync(__pyx_v_self->ptr)); + + /* "pysam/libcbcf.pyx":2144 + * bcf_hdr_add_hrec(self.ptr, hrec) + * + * if self.ptr.dirty: # <<<<<<<<<<<<<< + * bcf_hdr_sync(self.ptr) + * + */ + } + + /* "pysam/libcbcf.pyx":2116 + * bcf_hdr_sync(self.ptr) + * + * def add_meta(self, key, value=None, items=None): # <<<<<<<<<<<<<< + * """Add metadata to this header""" + * if not ((value is not None) ^ (items is not None)): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.add_meta", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_key); + __Pyx_XDECREF(__pyx_v_value); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2147 + * bcf_hdr_sync(self.ptr) + * + * def add_sample(self, name): # <<<<<<<<<<<<<< + * """Add a new sample to this header""" + * bname = force_bytes(name) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_23add_sample(PyObject *__pyx_v_self, PyObject *__pyx_v_name); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_22add_sample[] = "VariantHeader.add_sample(self, name)\nAdd a new sample to this header"; +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_23add_sample(PyObject *__pyx_v_self, PyObject *__pyx_v_name) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_sample (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_22add_sample(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self), ((PyObject *)__pyx_v_name)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_22add_sample(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, PyObject *__pyx_v_name) { + PyObject *__pyx_v_bname = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + char const *__pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannySetupContext("add_sample", 0); + __Pyx_TraceCall("add_sample", __pyx_f[0], 2147, 0, __PYX_ERR(0, 2147, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2149 + * def add_sample(self, name): + * """Add a new sample to this header""" + * bname = force_bytes(name) # <<<<<<<<<<<<<< + * if bcf_hdr_add_sample(self.ptr, bname) < 0: + * raise ValueError('Duplicated sample name: {}'.format(name)) + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_name, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2149, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_bname = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":2150 + * """Add a new sample to this header""" + * bname = force_bytes(name) + * if bcf_hdr_add_sample(self.ptr, bname) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Duplicated sample name: {}'.format(name)) + * if self.ptr.dirty: + */ + if (unlikely(__pyx_v_bname == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2150, __pyx_L1_error) + } + __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_bname); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 2150, __pyx_L1_error) + __pyx_t_3 = ((bcf_hdr_add_sample(__pyx_v_self->ptr, __pyx_t_2) < 0) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcbcf.pyx":2151 + * bname = force_bytes(name) + * if bcf_hdr_add_sample(self.ptr, bname) < 0: + * raise ValueError('Duplicated sample name: {}'.format(name)) # <<<<<<<<<<<<<< + * if self.ptr.dirty: + * bcf_hdr_sync(self.ptr) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Duplicated_sample_name, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2151, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_5) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2151, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_name}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2151, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_name}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2151, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2151, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_name); + __Pyx_GIVEREF(__pyx_v_name); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_name); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2151, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2151, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2151, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2150 + * """Add a new sample to this header""" + * bname = force_bytes(name) + * if bcf_hdr_add_sample(self.ptr, bname) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Duplicated sample name: {}'.format(name)) + * if self.ptr.dirty: + */ + } + + /* "pysam/libcbcf.pyx":2152 + * if bcf_hdr_add_sample(self.ptr, bname) < 0: + * raise ValueError('Duplicated sample name: {}'.format(name)) + * if self.ptr.dirty: # <<<<<<<<<<<<<< + * bcf_hdr_sync(self.ptr) + * + */ + __pyx_t_3 = (__pyx_v_self->ptr->dirty != 0); + if (__pyx_t_3) { + + /* "pysam/libcbcf.pyx":2153 + * raise ValueError('Duplicated sample name: {}'.format(name)) + * if self.ptr.dirty: + * bcf_hdr_sync(self.ptr) # <<<<<<<<<<<<<< + * + * + */ + (void)(bcf_hdr_sync(__pyx_v_self->ptr)); + + /* "pysam/libcbcf.pyx":2152 + * if bcf_hdr_add_sample(self.ptr, bname) < 0: + * raise ValueError('Duplicated sample name: {}'.format(name)) + * if self.ptr.dirty: # <<<<<<<<<<<<<< + * bcf_hdr_sync(self.ptr) + * + */ + } + + /* "pysam/libcbcf.pyx":2147 + * bcf_hdr_sync(self.ptr) + * + * def add_sample(self, name): # <<<<<<<<<<<<<< + * """Add a new sample to this header""" + * bname = force_bytes(name) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.add_sample", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_bname); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_25__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_24__reduce_cython__[] = "VariantHeader.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_25__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_24__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_24__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__102, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(2, 2, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_27__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_26__setstate_cython__[] = "VariantHeader.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_27__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_26__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_26__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 3, 0, __PYX_ERR(2, 3, __pyx_L1_error)); + + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__103, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(2, 4, __pyx_L1_error) + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2156 + * + * + * cdef VariantHeader makeVariantHeader(bcf_hdr_t *hdr): # <<<<<<<<<<<<<< + * if not hdr: + * raise ValueError('cannot create VariantHeader') + */ + +static struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_f_5pysam_7libcbcf_makeVariantHeader(bcf_hdr_t *__pyx_v_hdr) { + struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_header = 0; + struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("makeVariantHeader", 0); + __Pyx_TraceCall("makeVariantHeader", __pyx_f[0], 2156, 0, __PYX_ERR(0, 2156, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2157 + * + * cdef VariantHeader makeVariantHeader(bcf_hdr_t *hdr): + * if not hdr: # <<<<<<<<<<<<<< + * raise ValueError('cannot create VariantHeader') + * + */ + __pyx_t_1 = ((!(__pyx_v_hdr != 0)) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbcf.pyx":2158 + * cdef VariantHeader makeVariantHeader(bcf_hdr_t *hdr): + * if not hdr: + * raise ValueError('cannot create VariantHeader') # <<<<<<<<<<<<<< + * + * cdef VariantHeader header = VariantHeader.__new__(VariantHeader) + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__104, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 2158, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2157 + * + * cdef VariantHeader makeVariantHeader(bcf_hdr_t *hdr): + * if not hdr: # <<<<<<<<<<<<<< + * raise ValueError('cannot create VariantHeader') + * + */ + } + + /* "pysam/libcbcf.pyx":2160 + * raise ValueError('cannot create VariantHeader') + * + * cdef VariantHeader header = VariantHeader.__new__(VariantHeader) # <<<<<<<<<<<<<< + * header.ptr = hdr + * + */ + __pyx_t_2 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantHeader(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeader), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2160, __pyx_L1_error) + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_v_header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "pysam/libcbcf.pyx":2161 + * + * cdef VariantHeader header = VariantHeader.__new__(VariantHeader) + * header.ptr = hdr # <<<<<<<<<<<<<< + * + * return header + */ + __pyx_v_header->ptr = __pyx_v_hdr; + + /* "pysam/libcbcf.pyx":2163 + * header.ptr = hdr + * + * return header # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_header)); + __pyx_r = __pyx_v_header; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2156 + * + * + * cdef VariantHeader makeVariantHeader(bcf_hdr_t *hdr): # <<<<<<<<<<<<<< + * if not hdr: + * raise ValueError('cannot create VariantHeader') + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcbcf.makeVariantHeader", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_header); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2166 + * + * + * cdef inline int bcf_header_get_info_id(bcf_hdr_t *hdr, key) except? -2: # <<<<<<<<<<<<<< + * cdef vdict_t *d + * cdef khiter_t k + */ + +static CYTHON_INLINE int __pyx_f_5pysam_7libcbcf_bcf_header_get_info_id(bcf_hdr_t *__pyx_v_hdr, PyObject *__pyx_v_key) { + vdict_t *__pyx_v_d; + khiter_t __pyx_v_k; + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char const *__pyx_t_4; + __Pyx_RefNannySetupContext("bcf_header_get_info_id", 0); + __Pyx_TraceCall("bcf_header_get_info_id", __pyx_f[0], 2166, 0, __PYX_ERR(0, 2166, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_key); + + /* "pysam/libcbcf.pyx":2171 + * cdef int info_id + * + * if isinstance(key, str): # <<<<<<<<<<<<<< + * key = force_bytes(key) + * + */ + __pyx_t_1 = PyString_Check(__pyx_v_key); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "pysam/libcbcf.pyx":2172 + * + * if isinstance(key, str): + * key = force_bytes(key) # <<<<<<<<<<<<<< + * + * d = hdr.dict[BCF_DT_ID] + */ + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":2171 + * cdef int info_id + * + * if isinstance(key, str): # <<<<<<<<<<<<<< + * key = force_bytes(key) + * + */ + } + + /* "pysam/libcbcf.pyx":2174 + * key = force_bytes(key) + * + * d = hdr.dict[BCF_DT_ID] # <<<<<<<<<<<<<< + * k = kh_get_vdict(d, key) + * + */ + __pyx_v_d = ((vdict_t *)(__pyx_v_hdr->dict[BCF_DT_ID])); + + /* "pysam/libcbcf.pyx":2175 + * + * d = hdr.dict[BCF_DT_ID] + * k = kh_get_vdict(d, key) # <<<<<<<<<<<<<< + * + * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: + */ + __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_v_key); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2175, __pyx_L1_error) + __pyx_v_k = kh_get_vdict(__pyx_v_d, __pyx_t_4); + + /* "pysam/libcbcf.pyx":2177 + * k = kh_get_vdict(d, key) + * + * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: # <<<<<<<<<<<<<< + * return -1 + * + */ + __pyx_t_1 = ((__pyx_v_k == kh_end(__pyx_v_d)) != 0); + if (!__pyx_t_1) { + } else { + __pyx_t_2 = __pyx_t_1; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_1 = ((((kh_val(__pyx_v_d, __pyx_v_k).info[BCF_HL_INFO]) & 0xF) == 0xF) != 0); + __pyx_t_2 = __pyx_t_1; + __pyx_L5_bool_binop_done:; + if (__pyx_t_2) { + + /* "pysam/libcbcf.pyx":2178 + * + * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: + * return -1 # <<<<<<<<<<<<<< + * + * return kh_val_vdict(d, k).id + */ + __pyx_r = -1; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2177 + * k = kh_get_vdict(d, key) + * + * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: # <<<<<<<<<<<<<< + * return -1 + * + */ + } + + /* "pysam/libcbcf.pyx":2180 + * return -1 + * + * return kh_val_vdict(d, k).id # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = kh_val(__pyx_v_d, __pyx_v_k).id; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2166 + * + * + * cdef inline int bcf_header_get_info_id(bcf_hdr_t *hdr, key) except? -2: # <<<<<<<<<<<<<< + * cdef vdict_t *d + * cdef khiter_t k + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.bcf_header_get_info_id", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -2; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_key); + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2191 + * """Filters set on a :class:`VariantRecord` object, presented as a mapping from + * filter index or name to :class:`VariantMetadata` object""" + * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< + * raise TypeError('this class cannot be instantiated from Python') + * + */ + +/* Python wrapper */ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + CYTHON_UNUSED PyObject *__pyx_v_args = 0; + CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1; + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter___init__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__init__", 0); + __Pyx_TraceCall("__init__", __pyx_f[0], 2191, 0, __PYX_ERR(0, 2191, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2192 + * filter index or name to :class:`VariantMetadata` object""" + * def __init__(self, *args, **kwargs): + * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__105, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2192, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2191 + * """Filters set on a :class:`VariantRecord` object, presented as a mapping from + * filter index or name to :class:`VariantMetadata` object""" + * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< + * raise TypeError('this class cannot be instantiated from Python') + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2194 + * raise TypeError('this class cannot be instantiated from Python') + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.record.ptr.d.n_flt + * + */ + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_3__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_3__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_2__len__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_2__len__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + __Pyx_TraceCall("__len__", __pyx_f[0], 2194, 0, __PYX_ERR(0, 2194, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2195 + * + * def __len__(self): + * return self.record.ptr.d.n_flt # <<<<<<<<<<<<<< + * + * def __bool__(self): + */ + __pyx_r = __pyx_v_self->record->ptr->d.n_flt; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2194 + * raise TypeError('this class cannot be instantiated from Python') + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.record.ptr.d.n_flt + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2197 + * return self.record.ptr.d.n_flt + * + * def __bool__(self): # <<<<<<<<<<<<<< + * return self.record.ptr.d.n_flt != 0 + * + */ + +/* Python wrapper */ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_5__bool__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_5__bool__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__bool__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_4__bool__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_4__bool__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__bool__", 0); + __Pyx_TraceCall("__bool__", __pyx_f[0], 2197, 0, __PYX_ERR(0, 2197, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2198 + * + * def __bool__(self): + * return self.record.ptr.d.n_flt != 0 # <<<<<<<<<<<<<< + * + * def __getitem__(self, key): + */ + __pyx_r = (__pyx_v_self->record->ptr->d.n_flt != 0); + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2197 + * return self.record.ptr.d.n_flt + * + * def __bool__(self): # <<<<<<<<<<<<<< + * return self.record.ptr.d.n_flt != 0 + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2200 + * return self.record.ptr.d.n_flt != 0 + * + * def __getitem__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_6__getitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_6__getitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v_key) { + bcf_hdr_t *__pyx_v_hdr; + bcf1_t *__pyx_v_r; + int __pyx_v_index; + int __pyx_v_id; + int __pyx_v_n; + PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + char const *__pyx_t_7; + char *__pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + __Pyx_RefNannySetupContext("__getitem__", 0); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 2200, 0, __PYX_ERR(0, 2200, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_key); + + /* "pysam/libcbcf.pyx":2201 + * + * def __getitem__(self, key): + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef int index, id + */ + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; + + /* "pysam/libcbcf.pyx":2202 + * def __getitem__(self, key): + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef int index, id + * cdef int n = r.d.n_flt + */ + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; + + /* "pysam/libcbcf.pyx":2204 + * cdef bcf1_t *r = self.record.ptr + * cdef int index, id + * cdef int n = r.d.n_flt # <<<<<<<<<<<<<< + * + * if isinstance(key, int): + */ + __pyx_t_3 = __pyx_v_r->d.n_flt; + __pyx_v_n = __pyx_t_3; + + /* "pysam/libcbcf.pyx":2206 + * cdef int n = r.d.n_flt + * + * if isinstance(key, int): # <<<<<<<<<<<<<< + * index = key + * + */ + __pyx_t_4 = PyInt_Check(__pyx_v_key); + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { + + /* "pysam/libcbcf.pyx":2207 + * + * if isinstance(key, int): + * index = key # <<<<<<<<<<<<<< + * + * if index < 0 or index >= n: + */ + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_key); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2207, __pyx_L1_error) + __pyx_v_index = __pyx_t_3; + + /* "pysam/libcbcf.pyx":2209 + * index = key + * + * if index < 0 or index >= n: # <<<<<<<<<<<<<< + * raise IndexError('invalid filter index') + * + */ + __pyx_t_4 = ((__pyx_v_index < 0) != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_5 = __pyx_t_4; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_4 = ((__pyx_v_index >= __pyx_v_n) != 0); + __pyx_t_5 = __pyx_t_4; + __pyx_L5_bool_binop_done:; + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcbcf.pyx":2210 + * + * if index < 0 or index >= n: + * raise IndexError('invalid filter index') # <<<<<<<<<<<<<< + * + * id = r.d.flt[index] + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__106, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 2210, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2209 + * index = key + * + * if index < 0 or index >= n: # <<<<<<<<<<<<<< + * raise IndexError('invalid filter index') + * + */ + } + + /* "pysam/libcbcf.pyx":2212 + * raise IndexError('invalid filter index') + * + * id = r.d.flt[index] # <<<<<<<<<<<<<< + * else: + * if key == '.': + */ + __pyx_v_id = (__pyx_v_r->d.flt[__pyx_v_index]); + + /* "pysam/libcbcf.pyx":2206 + * cdef int n = r.d.n_flt + * + * if isinstance(key, int): # <<<<<<<<<<<<<< + * index = key + * + */ + goto __pyx_L3; + } + + /* "pysam/libcbcf.pyx":2214 + * id = r.d.flt[index] + * else: + * if key == '.': # <<<<<<<<<<<<<< + * key = 'PASS' + * + */ + /*else*/ { + __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_kp_s__71, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2214, __pyx_L1_error) + if (__pyx_t_5) { + + /* "pysam/libcbcf.pyx":2215 + * else: + * if key == '.': + * key = 'PASS' # <<<<<<<<<<<<<< + * + * bkey = force_bytes(key) + */ + __Pyx_INCREF(__pyx_n_s_PASS); + __Pyx_DECREF_SET(__pyx_v_key, __pyx_n_s_PASS); + + /* "pysam/libcbcf.pyx":2214 + * id = r.d.flt[index] + * else: + * if key == '.': # <<<<<<<<<<<<<< + * key = 'PASS' + * + */ + } + + /* "pysam/libcbcf.pyx":2217 + * key = 'PASS' + * + * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) + * + */ + __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2217, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_v_bkey = ((PyObject*)__pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libcbcf.pyx":2218 + * + * bkey = force_bytes(key) + * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) # <<<<<<<<<<<<<< + * + * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): + */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2218, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 2218, __pyx_L1_error) + __pyx_v_id = bcf_hdr_id2int(__pyx_v_hdr, BCF_DT_ID, __pyx_t_7); + + /* "pysam/libcbcf.pyx":2220 + * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) + * + * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): # <<<<<<<<<<<<<< + * raise KeyError('Invalid filter: {}'.format(key)) + * + */ + __pyx_t_4 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_FLT, __pyx_v_id) != 0)) != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_5 = __pyx_t_4; + goto __pyx_L9_bool_binop_done; + } + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2220, __pyx_L1_error) + } + __pyx_t_8 = __Pyx_PyBytes_AsWritableString(__pyx_v_bkey); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 2220, __pyx_L1_error) + __pyx_t_4 = ((!(bcf_has_filter(__pyx_v_hdr, __pyx_v_r, __pyx_t_8) != 0)) != 0); + __pyx_t_5 = __pyx_t_4; + __pyx_L9_bool_binop_done:; + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcbcf.pyx":2221 + * + * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): + * raise KeyError('Invalid filter: {}'.format(key)) # <<<<<<<<<<<<<< + * + * return makeVariantMetadata(self.record.header, BCF_HL_FLT, id) + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_filter, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2221, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + if (!__pyx_t_10) { + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_key); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2221, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2221, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2221, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2221, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_key); + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2221, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2221, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 2221, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2220 + * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) + * + * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): # <<<<<<<<<<<<<< + * raise KeyError('Invalid filter: {}'.format(key)) + * + */ + } + } + __pyx_L3:; + + /* "pysam/libcbcf.pyx":2223 + * raise KeyError('Invalid filter: {}'.format(key)) + * + * return makeVariantMetadata(self.record.header, BCF_HL_FLT, id) # <<<<<<<<<<<<<< + * + * def add(self, key): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_9 = ((PyObject *)__pyx_v_self->record->header); + __Pyx_INCREF(__pyx_t_9); + __pyx_t_6 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantMetadata(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_9), BCF_HL_FLT, __pyx_v_id)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2223, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2200 + * return self.record.ptr.d.n_flt != 0 + * + * def __getitem__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_bkey); + __Pyx_XDECREF(__pyx_v_key); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2225 + * return makeVariantMetadata(self.record.header, BCF_HL_FLT, id) + * + * def add(self, key): # <<<<<<<<<<<<<< + * """Add a new filter""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_9add(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_8add[] = "VariantRecordFilter.add(self, key)\nAdd a new filter"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_9add(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_8add(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_8add(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v_key) { + bcf_hdr_t *__pyx_v_hdr; + bcf1_t *__pyx_v_r; + int __pyx_v_id; + PyObject *__pyx_v_bkey = 0; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + char const *__pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + __Pyx_RefNannySetupContext("add", 0); + __Pyx_TraceCall("add", __pyx_f[0], 2225, 0, __PYX_ERR(0, 2225, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_key); + + /* "pysam/libcbcf.pyx":2227 + * def add(self, key): + * """Add a new filter""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef int id + */ + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; + + /* "pysam/libcbcf.pyx":2228 + * """Add a new filter""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef int id + * + */ + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; + + /* "pysam/libcbcf.pyx":2231 + * cdef int id + * + * if key == '.': # <<<<<<<<<<<<<< + * key = 'PASS' + * + */ + __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_kp_s__71, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2231, __pyx_L1_error) + if (__pyx_t_3) { + + /* "pysam/libcbcf.pyx":2232 + * + * if key == '.': + * key = 'PASS' # <<<<<<<<<<<<<< + * + * cdef bytes bkey = force_bytes(key) + */ + __Pyx_INCREF(__pyx_n_s_PASS); + __Pyx_DECREF_SET(__pyx_v_key, __pyx_n_s_PASS); + + /* "pysam/libcbcf.pyx":2231 + * cdef int id + * + * if key == '.': # <<<<<<<<<<<<<< + * key = 'PASS' + * + */ + } + + /* "pysam/libcbcf.pyx":2234 + * key = 'PASS' + * + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< + * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) + * + */ + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_bkey = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "pysam/libcbcf.pyx":2235 + * + * cdef bytes bkey = force_bytes(key) + * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) # <<<<<<<<<<<<<< + * + * if not check_header_id(hdr, BCF_HL_FLT, id): + */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2235, __pyx_L1_error) + } + __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 2235, __pyx_L1_error) + __pyx_v_id = bcf_hdr_id2int(__pyx_v_hdr, BCF_DT_ID, __pyx_t_5); + + /* "pysam/libcbcf.pyx":2237 + * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) + * + * if not check_header_id(hdr, BCF_HL_FLT, id): # <<<<<<<<<<<<<< + * raise KeyError('Invalid filter: {}'.format(key)) + * + */ + __pyx_t_3 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_FLT, __pyx_v_id) != 0)) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcbcf.pyx":2238 + * + * if not check_header_id(hdr, BCF_HL_FLT, id): + * raise KeyError('Invalid filter: {}'.format(key)) # <<<<<<<<<<<<<< + * + * bcf_add_filter(hdr, r, id) + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_filter, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + if (!__pyx_t_7) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_key}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2238, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_key}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2238, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_key); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 2238, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2237 + * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) + * + * if not check_header_id(hdr, BCF_HL_FLT, id): # <<<<<<<<<<<<<< + * raise KeyError('Invalid filter: {}'.format(key)) + * + */ + } + + /* "pysam/libcbcf.pyx":2240 + * raise KeyError('Invalid filter: {}'.format(key)) + * + * bcf_add_filter(hdr, r, id) # <<<<<<<<<<<<<< + * + * def __delitem__(self, key): + */ + (void)(bcf_add_filter(__pyx_v_hdr, __pyx_v_r, __pyx_v_id)); + + /* "pysam/libcbcf.pyx":2225 + * return makeVariantMetadata(self.record.header, BCF_HL_FLT, id) + * + * def add(self, key): # <<<<<<<<<<<<<< + * """Add a new filter""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.add", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_bkey); + __Pyx_XDECREF(__pyx_v_key); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2242 + * bcf_add_filter(hdr, r, id) + * + * def __delitem__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr + */ + +/* Python wrapper */ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_11__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_11__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__delitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_10__delitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_10__delitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v_key) { + bcf_hdr_t *__pyx_v_hdr; + bcf1_t *__pyx_v_r; + int __pyx_v_index; + int __pyx_v_id; + int __pyx_v_n; + PyObject *__pyx_v_bkey = NULL; + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + char const *__pyx_t_7; + char *__pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + __Pyx_RefNannySetupContext("__delitem__", 0); + __Pyx_TraceCall("__delitem__", __pyx_f[0], 2242, 0, __PYX_ERR(0, 2242, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_key); + + /* "pysam/libcbcf.pyx":2243 + * + * def __delitem__(self, key): + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef int index, id + */ + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; + + /* "pysam/libcbcf.pyx":2244 + * def __delitem__(self, key): + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef int index, id + * cdef int n = r.d.n_flt + */ + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; + + /* "pysam/libcbcf.pyx":2246 + * cdef bcf1_t *r = self.record.ptr + * cdef int index, id + * cdef int n = r.d.n_flt # <<<<<<<<<<<<<< + * + * if isinstance(key, int): + */ + __pyx_t_3 = __pyx_v_r->d.n_flt; + __pyx_v_n = __pyx_t_3; + + /* "pysam/libcbcf.pyx":2248 + * cdef int n = r.d.n_flt + * + * if isinstance(key, int): # <<<<<<<<<<<<<< + * index = key + * + */ + __pyx_t_4 = PyInt_Check(__pyx_v_key); + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { + + /* "pysam/libcbcf.pyx":2249 + * + * if isinstance(key, int): + * index = key # <<<<<<<<<<<<<< + * + * if index < 0 or index >= n: + */ + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_key); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2249, __pyx_L1_error) + __pyx_v_index = __pyx_t_3; + + /* "pysam/libcbcf.pyx":2251 + * index = key + * + * if index < 0 or index >= n: # <<<<<<<<<<<<<< + * raise IndexError('invalid filter index') + * + */ + __pyx_t_4 = ((__pyx_v_index < 0) != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_5 = __pyx_t_4; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_4 = ((__pyx_v_index >= __pyx_v_n) != 0); + __pyx_t_5 = __pyx_t_4; + __pyx_L5_bool_binop_done:; + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcbcf.pyx":2252 + * + * if index < 0 or index >= n: + * raise IndexError('invalid filter index') # <<<<<<<<<<<<<< + * + * id = r.d.flt[index] + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__107, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2252, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 2252, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2251 + * index = key + * + * if index < 0 or index >= n: # <<<<<<<<<<<<<< + * raise IndexError('invalid filter index') + * + */ + } + + /* "pysam/libcbcf.pyx":2254 + * raise IndexError('invalid filter index') + * + * id = r.d.flt[index] # <<<<<<<<<<<<<< + * else: + * if key == '.': + */ + __pyx_v_id = (__pyx_v_r->d.flt[__pyx_v_index]); + + /* "pysam/libcbcf.pyx":2248 + * cdef int n = r.d.n_flt + * + * if isinstance(key, int): # <<<<<<<<<<<<<< + * index = key + * + */ + goto __pyx_L3; + } + + /* "pysam/libcbcf.pyx":2256 + * id = r.d.flt[index] + * else: + * if key == '.': # <<<<<<<<<<<<<< + * key = 'PASS' + * + */ + /*else*/ { + __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_kp_s__71, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2256, __pyx_L1_error) + if (__pyx_t_5) { + + /* "pysam/libcbcf.pyx":2257 + * else: + * if key == '.': + * key = 'PASS' # <<<<<<<<<<<<<< + * + * bkey = force_bytes(key) + */ + __Pyx_INCREF(__pyx_n_s_PASS); + __Pyx_DECREF_SET(__pyx_v_key, __pyx_n_s_PASS); + + /* "pysam/libcbcf.pyx":2256 + * id = r.d.flt[index] + * else: + * if key == '.': # <<<<<<<<<<<<<< + * key = 'PASS' + * + */ + } + + /* "pysam/libcbcf.pyx":2259 + * key = 'PASS' + * + * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) + * + */ + __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2259, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_v_bkey = ((PyObject*)__pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libcbcf.pyx":2260 + * + * bkey = force_bytes(key) + * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) # <<<<<<<<<<<<<< + * + * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): + */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2260, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 2260, __pyx_L1_error) + __pyx_v_id = bcf_hdr_id2int(__pyx_v_hdr, BCF_DT_ID, __pyx_t_7); + + /* "pysam/libcbcf.pyx":2262 + * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) + * + * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): # <<<<<<<<<<<<<< + * raise KeyError('Invalid filter: {}'.format(key)) + * + */ + __pyx_t_4 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_FLT, __pyx_v_id) != 0)) != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_5 = __pyx_t_4; + goto __pyx_L9_bool_binop_done; + } + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2262, __pyx_L1_error) + } + __pyx_t_8 = __Pyx_PyBytes_AsWritableString(__pyx_v_bkey); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 2262, __pyx_L1_error) + __pyx_t_4 = ((!(bcf_has_filter(__pyx_v_hdr, __pyx_v_r, __pyx_t_8) != 0)) != 0); + __pyx_t_5 = __pyx_t_4; + __pyx_L9_bool_binop_done:; + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcbcf.pyx":2263 + * + * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): + * raise KeyError('Invalid filter: {}'.format(key)) # <<<<<<<<<<<<<< + * + * bcf_remove_filter(hdr, r, id, 0) + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_filter, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + if (!__pyx_t_10) { + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_key); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2263, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2263, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_key); + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 2263, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2262 + * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) + * + * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): # <<<<<<<<<<<<<< + * raise KeyError('Invalid filter: {}'.format(key)) + * + */ + } + } + __pyx_L3:; + + /* "pysam/libcbcf.pyx":2265 + * raise KeyError('Invalid filter: {}'.format(key)) + * + * bcf_remove_filter(hdr, r, id, 0) # <<<<<<<<<<<<<< + * + * def clear(self): + */ + (void)(bcf_remove_filter(__pyx_v_hdr, __pyx_v_r, __pyx_v_id, 0)); + + /* "pysam/libcbcf.pyx":2242 + * bcf_add_filter(hdr, r, id) + * + * def __delitem__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__delitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_bkey); + __Pyx_XDECREF(__pyx_v_key); + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2267 + * bcf_remove_filter(hdr, r, id, 0) + * + * def clear(self): # <<<<<<<<<<<<<< + * """Clear all filters""" + * cdef bcf1_t *r = self.record.ptr + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_13clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_12clear[] = "VariantRecordFilter.clear(self)\nClear all filters"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_13clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("clear (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_12clear(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_12clear(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { + bcf1_t *__pyx_v_r; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + bcf1_t *__pyx_t_1; + __Pyx_RefNannySetupContext("clear", 0); + __Pyx_TraceCall("clear", __pyx_f[0], 2267, 0, __PYX_ERR(0, 2267, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2269 + * def clear(self): + * """Clear all filters""" + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * r.d.shared_dirty |= BCF1_DIRTY_FLT + * r.d.n_flt = 0 + */ + __pyx_t_1 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_1; + + /* "pysam/libcbcf.pyx":2270 + * """Clear all filters""" + * cdef bcf1_t *r = self.record.ptr + * r.d.shared_dirty |= BCF1_DIRTY_FLT # <<<<<<<<<<<<<< + * r.d.n_flt = 0 + * + */ + __pyx_v_r->d.shared_dirty = (__pyx_v_r->d.shared_dirty | BCF1_DIRTY_FLT); + + /* "pysam/libcbcf.pyx":2271 + * cdef bcf1_t *r = self.record.ptr + * r.d.shared_dirty |= BCF1_DIRTY_FLT + * r.d.n_flt = 0 # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __pyx_v_r->d.n_flt = 0; + + /* "pysam/libcbcf.pyx":2267 + * bcf_remove_filter(hdr, r, id, 0) + * + * def clear(self): # <<<<<<<<<<<<<< + * """Clear all filters""" + * cdef bcf1_t *r = self.record.ptr + */ + /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.add_line", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.clear", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_bline); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_16generator11(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":1916 - * bcf_hdr_sync(self.ptr) +/* "pysam/libcbcf.pyx":2273 + * r.d.n_flt = 0 * - * def add_meta(self, key, value=None, items=None): # <<<<<<<<<<<<<< - * """Add metadata to this header""" - * if not ((value is not None) ^ (items is not None)): + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_21add_meta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_20add_meta[] = "VariantHeader.add_meta(self, key, value=None, items=None)\nAdd metadata to this header"; -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_21add_meta(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_15__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_15__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_14__iter__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_14__iter__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_21___iter__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_21___iter__ *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_21___iter__(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_21___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_21___iter__ *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 2273, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_16generator11, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantRecordFilter___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2273, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_16generator11(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_21___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_21___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__", 0); + __Pyx_TraceCall("__iter__", __pyx_f[0], 2273, 0, __PYX_ERR(0, 2273, __pyx_L1_error)); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2273, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2274 + * + * def __iter__(self): + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef int i + */ + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; + __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; + + /* "pysam/libcbcf.pyx":2275 + * def __iter__(self): + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef int i + * + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; + __pyx_cur_scope->__pyx_v_r = __pyx_t_2; + + /* "pysam/libcbcf.pyx":2278 + * cdef int i + * + * for i in range(r.d.n_flt): # <<<<<<<<<<<<<< + * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, r.d.flt[i])) + * + */ + __pyx_t_3 = __pyx_cur_scope->__pyx_v_r->d.n_flt; + __pyx_t_4 = __pyx_t_3; + for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_5; + + /* "pysam/libcbcf.pyx":2279 + * + * for i in range(r.d.n_flt): + * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, r.d.flt[i])) # <<<<<<<<<<<<<< + * + * def get(self, key, default=None): + */ + __pyx_t_6 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_int2id(__pyx_cur_scope->__pyx_v_hdr, BCF_DT_ID, (__pyx_cur_scope->__pyx_v_r->d.flt[__pyx_cur_scope->__pyx_v_i]))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2279, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2279, __pyx_L1_error) + } + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); + + /* "pysam/libcbcf.pyx":2273 + * r.d.n_flt = 0 + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr + */ + + /* function exit code */ + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2281 + * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, r.d.flt[i])) + * + * def get(self, key, default=None): # <<<<<<<<<<<<<< + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" + * try: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_18get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_17get[] = "VariantRecordFilter.get(self, key, default=None)\nD.get(k[,d]) -> D[k] if k in D, else d. d defaults to None."; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_18get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_key = 0; - PyObject *__pyx_v_value = 0; - PyObject *__pyx_v_items = 0; + PyObject *__pyx_v_default = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("add_meta (wrapper)", 0); + __Pyx_RefNannySetupContext("get (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_value,&__pyx_n_s_items,0}; - PyObject* values[3] = {0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_default,0}; + PyObject* values[2] = {0,0}; values[1] = ((PyObject *)Py_None); - values[2] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -31546,23 +36991,15 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_21add_meta(PyObject *_ CYTHON_FALLTHROUGH; case 1: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_default); if (value) { values[1] = value; kw_args--; } } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items); - if (value) { values[2] = value; kw_args--; } - } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_meta") < 0)) __PYX_ERR(0, 1916, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 2281, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -31571,2376 +37008,2340 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_21add_meta(PyObject *_ } } __pyx_v_key = values[0]; - __pyx_v_value = values[1]; - __pyx_v_items = values[2]; + __pyx_v_default = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("add_meta", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1916, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2281, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.add_meta", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.get", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_20add_meta(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self), __pyx_v_key, __pyx_v_value, __pyx_v_items); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_20add_meta(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value, PyObject *__pyx_v_items) { - bcf_hrec_t *__pyx_v_hrec; - int __pyx_v_quoted; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - char const *__pyx_t_8; - Py_ssize_t __pyx_t_9; - PyObject *(*__pyx_t_10)(PyObject *); - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - PyObject *(*__pyx_t_15)(PyObject *); - char const *__pyx_t_16; - Py_ssize_t __pyx_t_17; - char const *__pyx_t_18; - char const *__pyx_t_19; - __Pyx_RefNannySetupContext("add_meta", 0); - __Pyx_TraceCall("add_meta", __pyx_f[0], 1916, 0, __PYX_ERR(0, 1916, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_key); - __Pyx_INCREF(__pyx_v_value); - - /* "pysam/libcbcf.pyx":1918 - * def add_meta(self, key, value=None, items=None): - * """Add metadata to this header""" - * if not ((value is not None) ^ (items is not None)): # <<<<<<<<<<<<<< - * raise ValueError('either value or items must be specified') - * - */ - __pyx_t_1 = (__pyx_v_value != Py_None); - __pyx_t_2 = (__pyx_v_items != Py_None); - __pyx_t_3 = ((!((__pyx_t_1 ^ __pyx_t_2) != 0)) != 0); - if (unlikely(__pyx_t_3)) { - - /* "pysam/libcbcf.pyx":1919 - * """Add metadata to this header""" - * if not ((value is not None) ^ (items is not None)): - * raise ValueError('either value or items must be specified') # <<<<<<<<<<<<<< - * - * cdef bcf_hrec_t *hrec = calloc(1, sizeof(bcf_hrec_t)) - */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__103, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1919, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1919, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":1918 - * def add_meta(self, key, value=None, items=None): - * """Add metadata to this header""" - * if not ((value is not None) ^ (items is not None)): # <<<<<<<<<<<<<< - * raise ValueError('either value or items must be specified') - * - */ - } - - /* "pysam/libcbcf.pyx":1921 - * raise ValueError('either value or items must be specified') - * - * cdef bcf_hrec_t *hrec = calloc(1, sizeof(bcf_hrec_t)) # <<<<<<<<<<<<<< - * cdef int quoted - * - */ - __pyx_v_hrec = ((bcf_hrec_t *)calloc(1, (sizeof(bcf_hrec_t)))); - - /* "pysam/libcbcf.pyx":1924 - * cdef int quoted - * - * try: # <<<<<<<<<<<<<< - * key = force_bytes(key) - * hrec.key = strdup(key) - */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - - /* "pysam/libcbcf.pyx":1925 - * - * try: - * key = force_bytes(key) # <<<<<<<<<<<<<< - * hrec.key = strdup(key) - * - */ - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1925, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_4); - __pyx_t_4 = 0; - - /* "pysam/libcbcf.pyx":1926 - * try: - * key = force_bytes(key) - * hrec.key = strdup(key) # <<<<<<<<<<<<<< - * - * if value is not None: - */ - __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_key); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 1926, __pyx_L4_error) - __pyx_v_hrec->key = strdup(__pyx_t_8); - - /* "pysam/libcbcf.pyx":1928 - * hrec.key = strdup(key) - * - * if value is not None: # <<<<<<<<<<<<<< - * hrec.value = strdup(force_bytes(value)) - * else: - */ - __pyx_t_3 = (__pyx_v_value != Py_None); - __pyx_t_2 = (__pyx_t_3 != 0); - if (__pyx_t_2) { - - /* "pysam/libcbcf.pyx":1929 - * - * if value is not None: - * hrec.value = strdup(force_bytes(value)) # <<<<<<<<<<<<<< - * else: - * for key, value in items: - */ - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1929, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_4); - if (unlikely(__pyx_t_4 == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 1929, __pyx_L4_error) - } - __pyx_t_8 = __Pyx_PyBytes_AsString(__pyx_t_4); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 1929, __pyx_L4_error) - __pyx_v_hrec->value = strdup(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pysam/libcbcf.pyx":1928 - * hrec.key = strdup(key) - * - * if value is not None: # <<<<<<<<<<<<<< - * hrec.value = strdup(force_bytes(value)) - * else: - */ - goto __pyx_L10; - } - - /* "pysam/libcbcf.pyx":1931 - * hrec.value = strdup(force_bytes(value)) - * else: - * for key, value in items: # <<<<<<<<<<<<<< - * key = force_bytes(key) - * bcf_hrec_add_key(hrec, key, len(key)) - */ - /*else*/ { - if (likely(PyList_CheckExact(__pyx_v_items)) || PyTuple_CheckExact(__pyx_v_items)) { - __pyx_t_4 = __pyx_v_items; __Pyx_INCREF(__pyx_t_4); __pyx_t_9 = 0; - __pyx_t_10 = NULL; - } else { - __pyx_t_9 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_items); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1931, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_10 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1931, __pyx_L4_error) - } - for (;;) { - if (likely(!__pyx_t_10)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_11 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_9); __Pyx_INCREF(__pyx_t_11); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1931, __pyx_L4_error) - #else - __pyx_t_11 = PySequence_ITEM(__pyx_t_4, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1931, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_11); - #endif - } else { - if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_9); __Pyx_INCREF(__pyx_t_11); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1931, __pyx_L4_error) - #else - __pyx_t_11 = PySequence_ITEM(__pyx_t_4, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1931, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_11); - #endif - } - } else { - __pyx_t_11 = __pyx_t_10(__pyx_t_4); - if (unlikely(!__pyx_t_11)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 1931, __pyx_L4_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_11); - } - if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) { - PyObject* sequence = __pyx_t_11; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 1931, __pyx_L4_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_12 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_13 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_12 = PyList_GET_ITEM(sequence, 0); - __pyx_t_13 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(__pyx_t_13); - #else - __pyx_t_12 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1931, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1931, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_13); - #endif - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_14 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1931, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext; - index = 0; __pyx_t_12 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_12)) goto __pyx_L13_unpacking_failed; - __Pyx_GOTREF(__pyx_t_12); - index = 1; __pyx_t_13 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_13)) goto __pyx_L13_unpacking_failed; - __Pyx_GOTREF(__pyx_t_13); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) __PYX_ERR(0, 1931, __pyx_L4_error) - __pyx_t_15 = NULL; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - goto __pyx_L14_unpacking_done; - __pyx_L13_unpacking_failed:; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_15 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 1931, __pyx_L4_error) - __pyx_L14_unpacking_done:; - } - __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_12); - __pyx_t_12 = 0; - __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_13); - __pyx_t_13 = 0; - - /* "pysam/libcbcf.pyx":1932 - * else: - * for key, value in items: - * key = force_bytes(key) # <<<<<<<<<<<<<< - * bcf_hrec_add_key(hrec, key, len(key)) - * - */ - __pyx_t_11 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1932, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_11); - __pyx_t_11 = 0; - - /* "pysam/libcbcf.pyx":1933 - * for key, value in items: - * key = force_bytes(key) - * bcf_hrec_add_key(hrec, key, len(key)) # <<<<<<<<<<<<<< - * - * value = force_bytes(str(value)) - */ - __pyx_t_16 = __Pyx_PyObject_AsString(__pyx_v_key); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 1933, __pyx_L4_error) - __pyx_t_17 = PyObject_Length(__pyx_v_key); if (unlikely(__pyx_t_17 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1933, __pyx_L4_error) - bcf_hrec_add_key(__pyx_v_hrec, __pyx_t_16, ((int)__pyx_t_17)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_17get(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), __pyx_v_key, __pyx_v_default); - /* "pysam/libcbcf.pyx":1935 - * bcf_hrec_add_key(hrec, key, len(key)) - * - * value = force_bytes(str(value)) # <<<<<<<<<<<<<< - * quoted = strpbrk(value, ' ;,"\t<>') != NULL - * bcf_hrec_set_val(hrec, hrec.nkeys-1, value, len(value), quoted) - */ - __pyx_t_11 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_value); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1935, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_13 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_11, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1935, __pyx_L4_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_13); - __pyx_t_13 = 0; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcbcf.pyx":1936 - * - * value = force_bytes(str(value)) - * quoted = strpbrk(value, ' ;,"\t<>') != NULL # <<<<<<<<<<<<<< - * bcf_hrec_set_val(hrec, hrec.nkeys-1, value, len(value), quoted) - * except: - */ - __pyx_t_18 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_18) && PyErr_Occurred())) __PYX_ERR(0, 1936, __pyx_L4_error) - __pyx_v_quoted = (strpbrk(__pyx_t_18, ((char const *)" ;,\"\t<>")) != NULL); +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_17get(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("get", 0); + __Pyx_TraceCall("get", __pyx_f[0], 2281, 0, __PYX_ERR(0, 2281, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1937 - * value = force_bytes(str(value)) - * quoted = strpbrk(value, ' ;,"\t<>') != NULL - * bcf_hrec_set_val(hrec, hrec.nkeys-1, value, len(value), quoted) # <<<<<<<<<<<<<< - * except: - * bcf_hrec_destroy(hrec) + /* "pysam/libcbcf.pyx":2283 + * def get(self, key, default=None): + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" + * try: # <<<<<<<<<<<<<< + * return self[key] + * except KeyError: */ - __pyx_t_19 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 1937, __pyx_L4_error) - __pyx_t_17 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_17 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1937, __pyx_L4_error) - bcf_hrec_set_val(__pyx_v_hrec, (__pyx_v_hrec->nkeys - 1), __pyx_t_19, ((int)__pyx_t_17), __pyx_v_quoted); + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { - /* "pysam/libcbcf.pyx":1931 - * hrec.value = strdup(force_bytes(value)) - * else: - * for key, value in items: # <<<<<<<<<<<<<< - * key = force_bytes(key) - * bcf_hrec_add_key(hrec, key, len(key)) + /* "pysam/libcbcf.pyx":2284 + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" + * try: + * return self[key] # <<<<<<<<<<<<<< + * except KeyError: + * return default */ - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __pyx_L10:; + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2284, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L7_try_return; - /* "pysam/libcbcf.pyx":1924 - * cdef int quoted - * + /* "pysam/libcbcf.pyx":2283 + * def get(self, key, default=None): + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< - * key = force_bytes(key) - * hrec.key = strdup(key) + * return self[key] + * except KeyError: */ } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L9_try_end; - __pyx_L4_error:; - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1938 - * quoted = strpbrk(value, ' ;,"\t<>') != NULL - * bcf_hrec_set_val(hrec, hrec.nkeys-1, value, len(value), quoted) - * except: # <<<<<<<<<<<<<< - * bcf_hrec_destroy(hrec) - * raise - */ - /*except:*/ { - __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.add_meta", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_13, &__pyx_t_11) < 0) __PYX_ERR(0, 1938, __pyx_L6_except_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_13); - __Pyx_GOTREF(__pyx_t_11); - - /* "pysam/libcbcf.pyx":1939 - * bcf_hrec_set_val(hrec, hrec.nkeys-1, value, len(value), quoted) - * except: - * bcf_hrec_destroy(hrec) # <<<<<<<<<<<<<< - * raise + /* "pysam/libcbcf.pyx":2285 + * try: + * return self[key] + * except KeyError: # <<<<<<<<<<<<<< + * return default * */ - bcf_hrec_destroy(__pyx_v_hrec); + __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); + if (__pyx_t_5) { + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.get", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 2285, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcbcf.pyx":1940 - * except: - * bcf_hrec_destroy(hrec) - * raise # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2286 + * return self[key] + * except KeyError: + * return default # <<<<<<<<<<<<<< * - * bcf_hdr_add_hrec(self.ptr, hrec) + * def __contains__(self, key): */ - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_13); - __Pyx_XGIVEREF(__pyx_t_11); - __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_13, __pyx_t_11); - __pyx_t_4 = 0; __pyx_t_13 = 0; __pyx_t_11 = 0; - __PYX_ERR(0, 1940, __pyx_L6_except_error) + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_default); + __pyx_r = __pyx_v_default; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_except_return; } - __pyx_L6_except_error:; + goto __pyx_L5_except_error; + __pyx_L5_except_error:; - /* "pysam/libcbcf.pyx":1924 - * cdef int quoted - * + /* "pysam/libcbcf.pyx":2283 + * def get(self, key, default=None): + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< - * key = force_bytes(key) - * hrec.key = strdup(key) + * return self[key] + * except KeyError: */ - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); goto __pyx_L1_error; - __pyx_L9_try_end:; + __pyx_L7_try_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + __pyx_L6_except_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; } - /* "pysam/libcbcf.pyx":1942 - * raise - * - * bcf_hdr_add_hrec(self.ptr, hrec) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2281 + * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, r.d.flt[i])) * - * if self.ptr.dirty: + * def get(self, key, default=None): # <<<<<<<<<<<<<< + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" + * try: */ - (void)(bcf_hdr_add_hrec(__pyx_v_self->ptr, __pyx_v_hrec)); - /* "pysam/libcbcf.pyx":1944 - * bcf_hdr_add_hrec(self.ptr, hrec) - * - * if self.ptr.dirty: # <<<<<<<<<<<<<< - * bcf_hdr_sync(self.ptr) + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.get", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2288 + * return default * + * def __contains__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ - __pyx_t_2 = (__pyx_v_self->ptr->dirty != 0); - if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":1945 - * - * if self.ptr.dirty: - * bcf_hdr_sync(self.ptr) # <<<<<<<<<<<<<< +/* Python wrapper */ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_20__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_20__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_19__contains__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_19__contains__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v_key) { + bcf_hdr_t *__pyx_v_hdr; + bcf1_t *__pyx_v_r; + PyObject *__pyx_v_bkey = 0; + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; + __Pyx_RefNannySetupContext("__contains__", 0); + __Pyx_TraceCall("__contains__", __pyx_f[0], 2288, 0, __PYX_ERR(0, 2288, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2289 * - * def add_sample(self, name): + * def __contains__(self, key): + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef bytes bkey = force_bytes(key) */ - (void)(bcf_hdr_sync(__pyx_v_self->ptr)); + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":1944 - * bcf_hdr_add_hrec(self.ptr, hrec) + /* "pysam/libcbcf.pyx":2290 + * def __contains__(self, key): + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) + * return bcf_has_filter(hdr, r, bkey) == 1 + */ + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; + + /* "pysam/libcbcf.pyx":2291 + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< + * return bcf_has_filter(hdr, r, bkey) == 1 * - * if self.ptr.dirty: # <<<<<<<<<<<<<< - * bcf_hdr_sync(self.ptr) + */ + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2291, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_bkey = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":2292 + * cdef bcf1_t *r = self.record.ptr + * cdef bytes bkey = force_bytes(key) + * return bcf_has_filter(hdr, r, bkey) == 1 # <<<<<<<<<<<<<< * + * def iterkeys(self): */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2292, __pyx_L1_error) } + __pyx_t_4 = __Pyx_PyBytes_AsWritableString(__pyx_v_bkey); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2292, __pyx_L1_error) + __pyx_r = (bcf_has_filter(__pyx_v_hdr, __pyx_v_r, __pyx_t_4) == 1); + goto __pyx_L0; - /* "pysam/libcbcf.pyx":1916 - * bcf_hdr_sync(self.ptr) + /* "pysam/libcbcf.pyx":2288 + * return default * - * def add_meta(self, key, value=None, items=None): # <<<<<<<<<<<<<< - * """Add metadata to this header""" - * if not ((value is not None) ^ (items is not None)): + * def __contains__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_14); - __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.add_meta", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_key); - __Pyx_XDECREF(__pyx_v_value); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_XDECREF(__pyx_v_bkey); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":1947 - * bcf_hdr_sync(self.ptr) +/* "pysam/libcbcf.pyx":2294 + * return bcf_has_filter(hdr, r, bkey) == 1 * - * def add_sample(self, name): # <<<<<<<<<<<<<< - * """Add a new sample to this header""" - * bname = force_bytes(name) + * def iterkeys(self): # <<<<<<<<<<<<<< + * """D.iterkeys() -> an iterator over the keys of D""" + * return iter(self) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_23add_sample(PyObject *__pyx_v_self, PyObject *__pyx_v_name); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_22add_sample[] = "VariantHeader.add_sample(self, name)\nAdd a new sample to this header"; -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_23add_sample(PyObject *__pyx_v_self, PyObject *__pyx_v_name) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_22iterkeys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_21iterkeys[] = "VariantRecordFilter.iterkeys(self)\nD.iterkeys() -> an iterator over the keys of D"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_22iterkeys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("add_sample (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_22add_sample(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self), ((PyObject *)__pyx_v_name)); + __Pyx_RefNannySetupContext("iterkeys (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_21iterkeys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_22add_sample(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, PyObject *__pyx_v_name) { - PyObject *__pyx_v_bname = NULL; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_21iterkeys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - char const *__pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - __Pyx_RefNannySetupContext("add_sample", 0); - __Pyx_TraceCall("add_sample", __pyx_f[0], 1947, 0, __PYX_ERR(0, 1947, __pyx_L1_error)); + __Pyx_RefNannySetupContext("iterkeys", 0); + __Pyx_TraceCall("iterkeys", __pyx_f[0], 2294, 0, __PYX_ERR(0, 2294, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1949 - * def add_sample(self, name): - * """Add a new sample to this header""" - * bname = force_bytes(name) # <<<<<<<<<<<<<< - * if bcf_hdr_add_sample(self.ptr, bname) < 0: - * raise ValueError('Duplicated sample name: {}'.format(name)) + /* "pysam/libcbcf.pyx":2296 + * def iterkeys(self): + * """D.iterkeys() -> an iterator over the keys of D""" + * return iter(self) # <<<<<<<<<<<<<< + * + * def itervalues(self): */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_name, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1949, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2296, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_v_bname = ((PyObject*)__pyx_t_1); + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":1950 - * """Add a new sample to this header""" - * bname = force_bytes(name) - * if bcf_hdr_add_sample(self.ptr, bname) < 0: # <<<<<<<<<<<<<< - * raise ValueError('Duplicated sample name: {}'.format(name)) - * if self.ptr.dirty: + /* "pysam/libcbcf.pyx":2294 + * return bcf_has_filter(hdr, r, bkey) == 1 + * + * def iterkeys(self): # <<<<<<<<<<<<<< + * """D.iterkeys() -> an iterator over the keys of D""" + * return iter(self) */ - if (unlikely(__pyx_v_bname == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 1950, __pyx_L1_error) + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.iterkeys", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_25generator12(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ + +/* "pysam/libcbcf.pyx":2298 + * return iter(self) + * + * def itervalues(self): # <<<<<<<<<<<<<< + * """D.itervalues() -> an iterator over the values of D""" + * for key in self: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_24itervalues(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_23itervalues[] = "VariantRecordFilter.itervalues(self)\nD.itervalues() -> an iterator over the values of D"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_24itervalues(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("itervalues (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_23itervalues(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_23itervalues(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_22_itervalues *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("itervalues", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_22_itervalues *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_22_itervalues(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_22_itervalues, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_22_itervalues *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 2298, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_25generator12, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantRecordFilter_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2298, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; } - __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_bname); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 1950, __pyx_L1_error) - __pyx_t_3 = ((bcf_hdr_add_sample(__pyx_v_self->ptr, __pyx_t_2) < 0) != 0); - if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":1951 - * bname = force_bytes(name) - * if bcf_hdr_add_sample(self.ptr, bname) < 0: - * raise ValueError('Duplicated sample name: {}'.format(name)) # <<<<<<<<<<<<<< - * if self.ptr.dirty: - * bcf_hdr_sync(self.ptr) + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_25generator12(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_22_itervalues *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_22_itervalues *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("itervalues", 0); + __Pyx_TraceCall("itervalues", __pyx_f[0], 2298, 0, __PYX_ERR(0, 2298, __pyx_L1_error)); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2298, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2300 + * def itervalues(self): + * """D.itervalues() -> an iterator over the values of D""" + * for key in self: # <<<<<<<<<<<<<< + * yield self[key] + * */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Duplicated_sample_name, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1951, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); + if (likely(PyList_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) { + __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2300, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2300, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_3)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2300, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2300, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2300, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2300, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif } - } - if (!__pyx_t_5) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1951, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_name}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1951, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_name}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1951, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1951, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; - __Pyx_INCREF(__pyx_v_name); - __Pyx_GIVEREF(__pyx_v_name); - PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_name); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1951, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2300, __pyx_L1_error) + } + break; } + __Pyx_GOTREF(__pyx_t_4); } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1951, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 1951, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":1950 - * """Add a new sample to this header""" - * bname = force_bytes(name) - * if bcf_hdr_add_sample(self.ptr, bname) < 0: # <<<<<<<<<<<<<< - * raise ValueError('Duplicated sample name: {}'.format(name)) - * if self.ptr.dirty: - */ - } - - /* "pysam/libcbcf.pyx":1952 - * if bcf_hdr_add_sample(self.ptr, bname) < 0: - * raise ValueError('Duplicated sample name: {}'.format(name)) - * if self.ptr.dirty: # <<<<<<<<<<<<<< - * bcf_hdr_sync(self.ptr) - * - */ - __pyx_t_3 = (__pyx_v_self->ptr->dirty != 0); - if (__pyx_t_3) { + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1953 - * raise ValueError('Duplicated sample name: {}'.format(name)) - * if self.ptr.dirty: - * bcf_hdr_sync(self.ptr) # <<<<<<<<<<<<<< - * + /* "pysam/libcbcf.pyx":2301 + * """D.itervalues() -> an iterator over the values of D""" + * for key in self: + * yield self[key] # <<<<<<<<<<<<<< * + * def iteritems(self): */ - (void)(bcf_hdr_sync(__pyx_v_self->ptr)); + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2301, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2301, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1952 - * if bcf_hdr_add_sample(self.ptr, bname) < 0: - * raise ValueError('Duplicated sample name: {}'.format(name)) - * if self.ptr.dirty: # <<<<<<<<<<<<<< - * bcf_hdr_sync(self.ptr) + /* "pysam/libcbcf.pyx":2300 + * def itervalues(self): + * """D.itervalues() -> an iterator over the values of D""" + * for key in self: # <<<<<<<<<<<<<< + * yield self[key] * */ } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1947 - * bcf_hdr_sync(self.ptr) + /* "pysam/libcbcf.pyx":2298 + * return iter(self) * - * def add_sample(self, name): # <<<<<<<<<<<<<< - * """Add a new sample to this header""" - * bname = force_bytes(name) + * def itervalues(self): # <<<<<<<<<<<<<< + * """D.itervalues() -> an iterator over the values of D""" + * for key in self: */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.add_sample", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_bname); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_28generator13(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): +/* "pysam/libcbcf.pyx":2303 + * yield self[key] + * + * def iteritems(self): # <<<<<<<<<<<<<< + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_25__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_24__reduce_cython__[] = "VariantHeader.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_25__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_27iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_26iteritems[] = "VariantRecordFilter.iteritems(self)\nD.iteritems() -> an iterator over the (key, value) items of D"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_27iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_24__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self)); + __Pyx_RefNannySetupContext("iteritems (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_26iteritems(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_24__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_26iteritems(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_23_iteritems *__pyx_cur_scope; PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); - - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__104, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) - - /* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): - */ + __Pyx_RefNannySetupContext("iteritems", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_23_iteritems *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_23_iteritems(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_23_iteritems, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_23_iteritems *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 2303, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_28generator13, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantRecordFilter_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2303, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_27__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_13VariantHeader_26__setstate_cython__[] = "VariantHeader.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantHeader_27__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantHeader_26__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); - - /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantHeader_26__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_28generator13(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_23_iteritems *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_23_iteritems *)__pyx_generator->closure); PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); - - /* "(tree fragment)":4 - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__105, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) - - /* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantHeader.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcbcf.pyx":1956 - * - * - * cdef VariantHeader makeVariantHeader(bcf_hdr_t *hdr): # <<<<<<<<<<<<<< - * if not hdr: - * raise ValueError('cannot create VariantHeader') - */ - -static struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_f_5pysam_7libcbcf_makeVariantHeader(bcf_hdr_t *__pyx_v_hdr) { - struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_header = 0; - struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_r = NULL; - __Pyx_TraceDeclarations + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("makeVariantHeader", 0); - __Pyx_TraceCall("makeVariantHeader", __pyx_f[0], 1956, 0, __PYX_ERR(0, 1956, __pyx_L1_error)); - - /* "pysam/libcbcf.pyx":1957 - * - * cdef VariantHeader makeVariantHeader(bcf_hdr_t *hdr): - * if not hdr: # <<<<<<<<<<<<<< - * raise ValueError('cannot create VariantHeader') - * - */ - __pyx_t_1 = ((!(__pyx_v_hdr != 0)) != 0); - if (unlikely(__pyx_t_1)) { - - /* "pysam/libcbcf.pyx":1958 - * cdef VariantHeader makeVariantHeader(bcf_hdr_t *hdr): - * if not hdr: - * raise ValueError('cannot create VariantHeader') # <<<<<<<<<<<<<< - * - * cdef VariantHeader header = VariantHeader.__new__(VariantHeader) - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__106, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1958, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 1958, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":1957 - * - * cdef VariantHeader makeVariantHeader(bcf_hdr_t *hdr): - * if not hdr: # <<<<<<<<<<<<<< - * raise ValueError('cannot create VariantHeader') - * - */ + __Pyx_RefNannySetupContext("iteritems", 0); + __Pyx_TraceCall("iteritems", __pyx_f[0], 2303, 0, __PYX_ERR(0, 2303, __pyx_L1_error)); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return NULL; } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2303, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1960 - * raise ValueError('cannot create VariantHeader') - * - * cdef VariantHeader header = VariantHeader.__new__(VariantHeader) # <<<<<<<<<<<<<< - * header.ptr = hdr + /* "pysam/libcbcf.pyx":2305 + * def iteritems(self): + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: # <<<<<<<<<<<<<< + * yield (key, self[key]) * */ - __pyx_t_2 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantHeader(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeader), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1960, __pyx_L1_error) - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_v_header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_2); - __pyx_t_2 = 0; + if (likely(PyList_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) { + __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2305, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2305, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_3)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2305, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2305, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2305, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2305, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2305, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":1961 - * - * cdef VariantHeader header = VariantHeader.__new__(VariantHeader) - * header.ptr = hdr # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2306 + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: + * yield (key, self[key]) # <<<<<<<<<<<<<< * - * return header + * def keys(self): */ - __pyx_v_header->ptr = __pyx_v_hdr; + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2306, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2306, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2306, __pyx_L1_error) - /* "pysam/libcbcf.pyx":1963 - * header.ptr = hdr - * - * return header # <<<<<<<<<<<<<< - * + /* "pysam/libcbcf.pyx":2305 + * def iteritems(self): + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: # <<<<<<<<<<<<<< + * yield (key, self[key]) * */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_header)); - __pyx_r = __pyx_v_header; - goto __pyx_L0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":1956 - * + /* "pysam/libcbcf.pyx":2303 + * yield self[key] * - * cdef VariantHeader makeVariantHeader(bcf_hdr_t *hdr): # <<<<<<<<<<<<<< - * if not hdr: - * raise ValueError('cannot create VariantHeader') + * def iteritems(self): # <<<<<<<<<<<<<< + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: */ /* function exit code */ + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libcbcf.makeVariantHeader", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_header); - __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":1974 - * """Filters set on a :class:`VariantRecord` object, presented as a mapping from - * filter index or name to :class:`VariantMetadata` object""" - * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< - * raise TypeError('this class cannot be instantiated from Python') +/* "pysam/libcbcf.pyx":2308 + * yield (key, self[key]) * + * def keys(self): # <<<<<<<<<<<<<< + * """D.keys() -> list of D's keys""" + * return list(self) */ /* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - CYTHON_UNUSED PyObject *__pyx_v_args = 0; - CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0; - int __pyx_r; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_30keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_29keys[] = "VariantRecordFilter.keys(self)\nD.keys() -> list of D's keys"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_30keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1; - __Pyx_INCREF(__pyx_args); - __pyx_v_args = __pyx_args; - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter___init__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); + __Pyx_RefNannySetupContext("keys (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_29keys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); /* function exit code */ - __Pyx_XDECREF(__pyx_v_args); - __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_29keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1974, 0, __PYX_ERR(0, 1974, __pyx_L1_error)); + __Pyx_RefNannySetupContext("keys", 0); + __Pyx_TraceCall("keys", __pyx_f[0], 2308, 0, __PYX_ERR(0, 2308, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1975 - * filter index or name to :class:`VariantMetadata` object""" - * def __init__(self, *args, **kwargs): - * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2310 + * def keys(self): + * """D.keys() -> list of D's keys""" + * return list(self) # <<<<<<<<<<<<<< * - * def __len__(self): + * def items(self): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__107, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1975, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2310, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1975, __pyx_L1_error) + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":1974 - * """Filters set on a :class:`VariantRecord` object, presented as a mapping from - * filter index or name to :class:`VariantMetadata` object""" - * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< - * raise TypeError('this class cannot be instantiated from Python') + /* "pysam/libcbcf.pyx":2308 + * yield (key, self[key]) * + * def keys(self): # <<<<<<<<<<<<<< + * """D.keys() -> list of D's keys""" + * return list(self) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":1977 - * raise TypeError('this class cannot be instantiated from Python') - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.record.ptr.d.n_flt +/* "pysam/libcbcf.pyx":2312 + * return list(self) * + * def items(self): # <<<<<<<<<<<<<< + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) */ /* Python wrapper */ -static Py_ssize_t __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_3__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_3__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_32items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_31items[] = "VariantRecordFilter.items(self)\nD.items() -> list of D's (key, value) pairs, as 2-tuples"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_32items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_2__len__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + __Pyx_RefNannySetupContext("items (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_31items(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_2__len__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { - Py_ssize_t __pyx_r; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_31items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[0], 1977, 0, __PYX_ERR(0, 1977, __pyx_L1_error)); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("items", 0); + __Pyx_TraceCall("items", __pyx_f[0], 2312, 0, __PYX_ERR(0, 2312, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1978 - * - * def __len__(self): - * return self.record.ptr.d.n_flt # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2314 + * def items(self): + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) # <<<<<<<<<<<<<< * - * def __bool__(self): + * def values(self): */ - __pyx_r = __pyx_v_self->record->ptr->d.n_flt; + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2314, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2314, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1977 - * raise TypeError('this class cannot be instantiated from Python') - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.record.ptr.d.n_flt + /* "pysam/libcbcf.pyx":2312 + * return list(self) * + * def items(self): # <<<<<<<<<<<<<< + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) */ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.items", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":1980 - * return self.record.ptr.d.n_flt - * - * def __bool__(self): # <<<<<<<<<<<<<< - * return self.record.ptr.d.n_flt != 0 +/* "pysam/libcbcf.pyx":2316 + * return list(self.iteritems()) * + * def values(self): # <<<<<<<<<<<<<< + * """D.values() -> list of D's values""" + * return list(self.itervalues()) */ /* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_5__bool__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_5__bool__(PyObject *__pyx_v_self) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_34values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_33values[] = "VariantRecordFilter.values(self)\nD.values() -> list of D's values"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_34values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__bool__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_4__bool__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + __Pyx_RefNannySetupContext("values (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_33values(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_4__bool__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_33values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 1980, 0, __PYX_ERR(0, 1980, __pyx_L1_error)); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("values", 0); + __Pyx_TraceCall("values", __pyx_f[0], 2316, 0, __PYX_ERR(0, 2316, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1981 - * - * def __bool__(self): - * return self.record.ptr.d.n_flt != 0 # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2318 + * def values(self): + * """D.values() -> list of D's values""" + * return list(self.itervalues()) # <<<<<<<<<<<<<< * - * def __getitem__(self, key): + * def __richcmp__(VariantRecordFilter self not None, VariantRecordFilter other not None, int op): */ - __pyx_r = (__pyx_v_self->record->ptr->d.n_flt != 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2318, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2318, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2318, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2318, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1980 - * return self.record.ptr.d.n_flt - * - * def __bool__(self): # <<<<<<<<<<<<<< - * return self.record.ptr.d.n_flt != 0 + /* "pysam/libcbcf.pyx":2316 + * return list(self.iteritems()) * + * def values(self): # <<<<<<<<<<<<<< + * """D.values() -> list of D's values""" + * return list(self.itervalues()) */ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":1983 - * return self.record.ptr.d.n_flt != 0 +/* "pysam/libcbcf.pyx":2320 + * return list(self.itervalues()) * - * def __getitem__(self, key): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr + * def __richcmp__(VariantRecordFilter self not None, VariantRecordFilter other not None, int op): # <<<<<<<<<<<<<< + * if op != 2 and op != 3: + * return NotImplemented */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_36__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_36__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_6__getitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); + if (unlikely(((PyObject *)__pyx_v_self) == Py_None)) { + PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "self"); __PYX_ERR(0, 2320, __pyx_L1_error) + } + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_7libcbcf_VariantRecordFilter, 0, "other", 0))) __PYX_ERR(0, 2320, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_35__richcmp__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), ((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_other), ((int)__pyx_v_op)); /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_6__getitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v_key) { - bcf_hdr_t *__pyx_v_hdr; - bcf1_t *__pyx_v_r; - int __pyx_v_index; - int __pyx_v_id; - int __pyx_v_n; - PyObject *__pyx_v_bkey = NULL; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_35__richcmp__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_other, int __pyx_v_op) { + bcf1_t *__pyx_v_s; + bcf1_t *__pyx_v_o; + int __pyx_v_cmp; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bcf_hdr_t *__pyx_t_1; + int __pyx_t_1; bcf1_t *__pyx_t_2; int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; - char const *__pyx_t_7; - char *__pyx_t_8; - PyObject *__pyx_t_9 = NULL; - __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[0], 1983, 0, __PYX_ERR(0, 1983, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_key); - - /* "pysam/libcbcf.pyx":1984 - * - * def __getitem__(self, key): - * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< - * cdef bcf1_t *r = self.record.ptr - * cdef int index, id - */ - __pyx_t_1 = __pyx_v_self->record->header->ptr; - __pyx_v_hdr = __pyx_t_1; - - /* "pysam/libcbcf.pyx":1985 - * def __getitem__(self, key): - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef int index, id - * cdef int n = r.d.n_flt - */ - __pyx_t_2 = __pyx_v_self->record->ptr; - __pyx_v_r = __pyx_t_2; - - /* "pysam/libcbcf.pyx":1987 - * cdef bcf1_t *r = self.record.ptr - * cdef int index, id - * cdef int n = r.d.n_flt # <<<<<<<<<<<<<< - * - * if isinstance(key, int): - */ - __pyx_t_3 = __pyx_v_r->d.n_flt; - __pyx_v_n = __pyx_t_3; - - /* "pysam/libcbcf.pyx":1989 - * cdef int n = r.d.n_flt - * - * if isinstance(key, int): # <<<<<<<<<<<<<< - * index = key - * - */ - __pyx_t_4 = PyInt_Check(__pyx_v_key); - __pyx_t_5 = (__pyx_t_4 != 0); - if (__pyx_t_5) { - - /* "pysam/libcbcf.pyx":1990 - * - * if isinstance(key, int): - * index = key # <<<<<<<<<<<<<< - * - * if index < 0 or index >= n: - */ - __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_key); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1990, __pyx_L1_error) - __pyx_v_index = __pyx_t_3; - - /* "pysam/libcbcf.pyx":1992 - * index = key - * - * if index < 0 or index >= n: # <<<<<<<<<<<<<< - * raise IndexError('invalid filter index') - * - */ - __pyx_t_4 = ((__pyx_v_index < 0) != 0); - if (!__pyx_t_4) { - } else { - __pyx_t_5 = __pyx_t_4; - goto __pyx_L5_bool_binop_done; - } - __pyx_t_4 = ((__pyx_v_index >= __pyx_v_n) != 0); - __pyx_t_5 = __pyx_t_4; - __pyx_L5_bool_binop_done:; - if (unlikely(__pyx_t_5)) { - - /* "pysam/libcbcf.pyx":1993 - * - * if index < 0 or index >= n: - * raise IndexError('invalid filter index') # <<<<<<<<<<<<<< - * - * id = r.d.flt[index] - */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__108, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1993, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 1993, __pyx_L1_error) + __Pyx_RefNannySetupContext("__richcmp__", 0); + __Pyx_TraceCall("__richcmp__", __pyx_f[0], 2320, 0, __PYX_ERR(0, 2320, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":1992 - * index = key + /* "pysam/libcbcf.pyx":2321 * - * if index < 0 or index >= n: # <<<<<<<<<<<<<< - * raise IndexError('invalid filter index') + * def __richcmp__(VariantRecordFilter self not None, VariantRecordFilter other not None, int op): + * if op != 2 and op != 3: # <<<<<<<<<<<<<< + * return NotImplemented * */ - } + switch (__pyx_v_op) { + case 2: + case 3: + __pyx_t_1 = 0; + break; + default: + __pyx_t_1 = 1; + break; + } + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":1995 - * raise IndexError('invalid filter index') + /* "pysam/libcbcf.pyx":2322 + * def __richcmp__(VariantRecordFilter self not None, VariantRecordFilter other not None, int op): + * if op != 2 and op != 3: + * return NotImplemented # <<<<<<<<<<<<<< * - * id = r.d.flt[index] # <<<<<<<<<<<<<< - * else: - * if key == '.': + * cdef bcf1_t *s = self.record.ptr */ - __pyx_v_id = (__pyx_v_r->d.flt[__pyx_v_index]); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_builtin_NotImplemented); + __pyx_r = __pyx_builtin_NotImplemented; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":1989 - * cdef int n = r.d.n_flt + /* "pysam/libcbcf.pyx":2321 * - * if isinstance(key, int): # <<<<<<<<<<<<<< - * index = key + * def __richcmp__(VariantRecordFilter self not None, VariantRecordFilter other not None, int op): + * if op != 2 and op != 3: # <<<<<<<<<<<<<< + * return NotImplemented * */ - goto __pyx_L3; } - /* "pysam/libcbcf.pyx":1997 - * id = r.d.flt[index] - * else: - * if key == '.': # <<<<<<<<<<<<<< - * key = 'PASS' - * - */ - /*else*/ { - __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_kp_s__71, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1997, __pyx_L1_error) - if (__pyx_t_5) { - - /* "pysam/libcbcf.pyx":1998 - * else: - * if key == '.': - * key = 'PASS' # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2324 + * return NotImplemented * - * bkey = force_bytes(key) - */ - __Pyx_INCREF(__pyx_n_s_PASS); - __Pyx_DECREF_SET(__pyx_v_key, __pyx_n_s_PASS); - - /* "pysam/libcbcf.pyx":1997 - * id = r.d.flt[index] - * else: - * if key == '.': # <<<<<<<<<<<<<< - * key = 'PASS' + * cdef bcf1_t *s = self.record.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *o = other.record.ptr * */ - } + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_s = __pyx_t_2; - /* "pysam/libcbcf.pyx":2000 - * key = 'PASS' + /* "pysam/libcbcf.pyx":2325 * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< - * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) + * cdef bcf1_t *s = self.record.ptr + * cdef bcf1_t *o = other.record.ptr # <<<<<<<<<<<<<< * + * cdef bint cmp = (s.d.n_flt == o.d.n_flt and list(self) == list(other)) */ - __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2000, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_v_bkey = ((PyObject*)__pyx_t_6); - __pyx_t_6 = 0; + __pyx_t_2 = __pyx_v_other->record->ptr; + __pyx_v_o = __pyx_t_2; - /* "pysam/libcbcf.pyx":2001 + /* "pysam/libcbcf.pyx":2327 + * cdef bcf1_t *o = other.record.ptr * - * bkey = force_bytes(key) - * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) # <<<<<<<<<<<<<< + * cdef bint cmp = (s.d.n_flt == o.d.n_flt and list(self) == list(other)) # <<<<<<<<<<<<<< * - * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): + * if op == 3: */ - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2001, __pyx_L1_error) - } - __pyx_t_7 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 2001, __pyx_L1_error) - __pyx_v_id = bcf_hdr_id2int(__pyx_v_hdr, BCF_DT_ID, __pyx_t_7); + __pyx_t_3 = ((__pyx_v_s->d.n_flt == __pyx_v_o->d.n_flt) != 0); + if (__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2327, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PySequence_List(((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2327, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2327, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2327, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_1 = __pyx_t_3; + __pyx_L4_bool_binop_done:; + __pyx_v_cmp = __pyx_t_1; - /* "pysam/libcbcf.pyx":2003 - * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) + /* "pysam/libcbcf.pyx":2329 + * cdef bint cmp = (s.d.n_flt == o.d.n_flt and list(self) == list(other)) * - * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): # <<<<<<<<<<<<<< - * raise KeyError('Invalid filter') + * if op == 3: # <<<<<<<<<<<<<< + * cmp = not cmp * */ - __pyx_t_4 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_FLT, __pyx_v_id) != 0)) != 0); - if (!__pyx_t_4) { - } else { - __pyx_t_5 = __pyx_t_4; - goto __pyx_L9_bool_binop_done; - } - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2003, __pyx_L1_error) - } - __pyx_t_8 = __Pyx_PyBytes_AsWritableString(__pyx_v_bkey); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 2003, __pyx_L1_error) - __pyx_t_4 = ((!(bcf_has_filter(__pyx_v_hdr, __pyx_v_r, __pyx_t_8) != 0)) != 0); - __pyx_t_5 = __pyx_t_4; - __pyx_L9_bool_binop_done:; - if (unlikely(__pyx_t_5)) { + __pyx_t_1 = ((__pyx_v_op == 3) != 0); + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":2004 + /* "pysam/libcbcf.pyx":2330 * - * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): - * raise KeyError('Invalid filter') # <<<<<<<<<<<<<< + * if op == 3: + * cmp = not cmp # <<<<<<<<<<<<<< * - * return makeVariantMetadata(self.record.header, BCF_HL_FLT, id) + * return cmp */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__109, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2004, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 2004, __pyx_L1_error) + __pyx_v_cmp = (!(__pyx_v_cmp != 0)); - /* "pysam/libcbcf.pyx":2003 - * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) + /* "pysam/libcbcf.pyx":2329 + * cdef bint cmp = (s.d.n_flt == o.d.n_flt and list(self) == list(other)) * - * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): # <<<<<<<<<<<<<< - * raise KeyError('Invalid filter') + * if op == 3: # <<<<<<<<<<<<<< + * cmp = not cmp * */ - } } - __pyx_L3:; - /* "pysam/libcbcf.pyx":2006 - * raise KeyError('Invalid filter') + /* "pysam/libcbcf.pyx":2332 + * cmp = not cmp * - * return makeVariantMetadata(self.record.header, BCF_HL_FLT, id) # <<<<<<<<<<<<<< + * return cmp # <<<<<<<<<<<<<< * - * def add(self, key): + * # Mappings are not hashable by default, but subclasses can change this */ __Pyx_XDECREF(__pyx_r); - __pyx_t_6 = ((PyObject *)__pyx_v_self->record->header); - __Pyx_INCREF(__pyx_t_6); - __pyx_t_9 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantMetadata(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_6), BCF_HL_FLT, __pyx_v_id)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2006, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_r = __pyx_t_9; - __pyx_t_9 = 0; + __pyx_t_6 = __Pyx_PyBool_FromLong(__pyx_v_cmp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2332, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":1983 - * return self.record.ptr.d.n_flt != 0 + /* "pysam/libcbcf.pyx":2320 + * return list(self.itervalues()) * - * def __getitem__(self, key): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr + * def __richcmp__(VariantRecordFilter self not None, VariantRecordFilter other not None, int op): # <<<<<<<<<<<<<< + * if op != 2 and op != 3: + * return NotImplemented */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_bkey); - __Pyx_XDECREF(__pyx_v_key); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2008 - * return makeVariantMetadata(self.record.header, BCF_HL_FLT, id) - * - * def add(self, key): # <<<<<<<<<<<<<< - * """Add a new filter""" - * cdef bcf_hdr_t *hdr = self.record.header.ptr +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef bint use_setstate + * state = (self.record,) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_9add(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_8add[] = "VariantRecordFilter.add(self, key)\nAdd a new filter"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_9add(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_38__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_37__reduce_cython__[] = "VariantRecordFilter.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_38__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("add (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_8add(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_37__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_8add(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v_key) { - bcf_hdr_t *__pyx_v_hdr; - bcf1_t *__pyx_v_r; - int __pyx_v_id; - PyObject *__pyx_v_bkey = NULL; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_37__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { + int __pyx_v_use_setstate; + PyObject *__pyx_v_state = NULL; + PyObject *__pyx_v__dict = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bcf_hdr_t *__pyx_t_1; - bcf1_t *__pyx_t_2; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; int __pyx_t_3; PyObject *__pyx_t_4 = NULL; - char const *__pyx_t_5; - __Pyx_RefNannySetupContext("add", 0); - __Pyx_TraceCall("add", __pyx_f[0], 2008, 0, __PYX_ERR(0, 2008, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_key); + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2010 - * def add(self, key): - * """Add a new filter""" - * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< - * cdef bcf1_t *r = self.record.ptr - * cdef int id + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * cdef bint use_setstate + * state = (self.record,) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: */ - __pyx_t_1 = __pyx_v_self->record->header->ptr; - __pyx_v_hdr = __pyx_t_1; + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self->record)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->record)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->record)); + __pyx_v_state = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":2011 - * """Add a new filter""" - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef int id - * + /* "(tree fragment)":4 + * cdef bint use_setstate + * state = (self.record,) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) */ - __pyx_t_2 = __pyx_v_self->record->ptr; - __pyx_v_r = __pyx_t_2; + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v__dict = __pyx_t_1; + __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":2014 - * cdef int id - * - * if key == '.': # <<<<<<<<<<<<<< - * key = 'PASS' - * + /* "(tree fragment)":5 + * state = (self.record,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True */ - __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_kp_s__71, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2014, __pyx_L1_error) + __pyx_t_2 = (__pyx_v__dict != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2015 - * - * if key == '.': - * key = 'PASS' # <<<<<<<<<<<<<< - * - * bkey = force_bytes(key) + /* "(tree fragment)":6 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: */ - __Pyx_INCREF(__pyx_n_s_PASS); - __Pyx_DECREF_SET(__pyx_v_key, __pyx_n_s_PASS); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2014 - * cdef int id - * - * if key == '.': # <<<<<<<<<<<<<< - * key = 'PASS' - * + /* "(tree fragment)":7 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self.record is not None */ - } + __pyx_v_use_setstate = 1; - /* "pysam/libcbcf.pyx":2017 - * key = 'PASS' - * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< - * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) - * + /* "(tree fragment)":5 + * state = (self.record,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True */ - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2017, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_v_bkey = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; + goto __pyx_L3; + } - /* "pysam/libcbcf.pyx":2018 - * - * bkey = force_bytes(key) - * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) # <<<<<<<<<<<<<< - * - * if not check_header_id(hdr, BCF_HL_FLT, id): + /* "(tree fragment)":9 + * use_setstate = True + * else: + * use_setstate = self.record is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, None), state */ - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2018, __pyx_L1_error) + /*else*/ { + __pyx_t_3 = (((PyObject *)__pyx_v_self->record) != Py_None); + __pyx_v_use_setstate = __pyx_t_3; } - __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 2018, __pyx_L1_error) - __pyx_v_id = bcf_hdr_id2int(__pyx_v_hdr, BCF_DT_ID, __pyx_t_5); + __pyx_L3:; + + /* "(tree fragment)":10 + * else: + * use_setstate = self.record is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, None), state + * else: + */ + __pyx_t_3 = (__pyx_v_use_setstate != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":11 + * use_setstate = self.record is not None + * if use_setstate: + * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, state) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordFilt); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_232881935); + __Pyx_GIVEREF(__pyx_int_232881935); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_232881935); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":2020 - * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) - * - * if not check_header_id(hdr, BCF_HL_FLT, id): # <<<<<<<<<<<<<< - * raise KeyError('Invalid filter') - * + /* "(tree fragment)":10 + * else: + * use_setstate = self.record is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, None), state + * else: */ - __pyx_t_3 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_FLT, __pyx_v_id) != 0)) != 0); - if (unlikely(__pyx_t_3)) { + } - /* "pysam/libcbcf.pyx":2021 - * - * if not check_header_id(hdr, BCF_HL_FLT, id): - * raise KeyError('Invalid filter') # <<<<<<<<<<<<<< - * - * bcf_add_filter(hdr, r, id) + /* "(tree fragment)":13 + * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, None), state + * else: + * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_VariantRecordFilter__set_state(self, __pyx_state) */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__110, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2021, __pyx_L1_error) + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordFilt); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_232881935); + __Pyx_GIVEREF(__pyx_int_232881935); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_232881935); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 2021, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":2020 - * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) - * - * if not check_header_id(hdr, BCF_HL_FLT, id): # <<<<<<<<<<<<<< - * raise KeyError('Invalid filter') - * - */ + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __pyx_t_5 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; } - /* "pysam/libcbcf.pyx":2023 - * raise KeyError('Invalid filter') - * - * bcf_add_filter(hdr, r, id) # <<<<<<<<<<<<<< - * - * def __delitem__(self, key): - */ - (void)(bcf_add_filter(__pyx_v_hdr, __pyx_v_r, __pyx_v_id)); - - /* "pysam/libcbcf.pyx":2008 - * return makeVariantMetadata(self.record.header, BCF_HL_FLT, id) - * - * def add(self, key): # <<<<<<<<<<<<<< - * """Add a new filter""" - * cdef bcf_hdr_t *hdr = self.record.header.ptr + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef bint use_setstate + * state = (self.record,) */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.add", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_bkey); - __Pyx_XDECREF(__pyx_v_key); + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2025 - * bcf_add_filter(hdr, r, id) - * - * def __delitem__(self, key): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr +/* "(tree fragment)":14 + * else: + * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_VariantRecordFilter__set_state(self, __pyx_state) */ /* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_11__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_11__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_40__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_39__setstate_cython__[] = "VariantRecordFilter.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_40__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__delitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_10__delitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_39__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_10__delitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v_key) { - bcf_hdr_t *__pyx_v_hdr; - bcf1_t *__pyx_v_r; - int __pyx_v_index; - int __pyx_v_id; - int __pyx_v_n; - PyObject *__pyx_v_bkey = NULL; - int __pyx_r; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_39__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bcf_hdr_t *__pyx_t_1; - bcf1_t *__pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - char const *__pyx_t_7; - char *__pyx_t_8; - __Pyx_RefNannySetupContext("__delitem__", 0); - __Pyx_TraceCall("__delitem__", __pyx_f[0], 2025, 0, __PYX_ERR(0, 2025, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_key); + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 14, 0, __PYX_ERR(2, 14, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2026 - * - * def __delitem__(self, key): - * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< - * cdef bcf1_t *r = self.record.ptr - * cdef int index, id + /* "(tree fragment)":15 + * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_VariantRecordFilter__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - __pyx_t_1 = __pyx_v_self->record->header->ptr; - __pyx_v_hdr = __pyx_t_1; + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFilter__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":2027 - * def __delitem__(self, key): - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef int index, id - * cdef int n = r.d.n_flt + /* "(tree fragment)":14 + * else: + * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_VariantRecordFilter__set_state(self, __pyx_state) */ - __pyx_t_2 = __pyx_v_self->record->ptr; - __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2029 - * cdef bcf1_t *r = self.record.ptr - * cdef int index, id - * cdef int n = r.d.n_flt # <<<<<<<<<<<<<< - * - * if isinstance(key, int): - */ - __pyx_t_3 = __pyx_v_r->d.n_flt; - __pyx_v_n = __pyx_t_3; + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcbcf.pyx":2031 - * cdef int n = r.d.n_flt +/* "pysam/libcbcf.pyx":2340 * - * if isinstance(key, int): # <<<<<<<<<<<<<< - * index = key * + * cdef VariantRecordFilter makeVariantRecordFilter(VariantRecord record): # <<<<<<<<<<<<<< + * if not record: + * raise ValueError('invalid VariantRecord') */ - __pyx_t_4 = PyInt_Check(__pyx_v_key); - __pyx_t_5 = (__pyx_t_4 != 0); - if (__pyx_t_5) { - /* "pysam/libcbcf.pyx":2032 - * - * if isinstance(key, int): - * index = key # <<<<<<<<<<<<<< - * - * if index < 0 or index >= n: - */ - __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_key); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2032, __pyx_L1_error) - __pyx_v_index = __pyx_t_3; +static struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_f_5pysam_7libcbcf_makeVariantRecordFilter(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record) { + struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_filter = 0; + struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("makeVariantRecordFilter", 0); + __Pyx_TraceCall("makeVariantRecordFilter", __pyx_f[0], 2340, 0, __PYX_ERR(0, 2340, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2034 - * index = key + /* "pysam/libcbcf.pyx":2341 * - * if index < 0 or index >= n: # <<<<<<<<<<<<<< - * raise IndexError('invalid filter index') + * cdef VariantRecordFilter makeVariantRecordFilter(VariantRecord record): + * if not record: # <<<<<<<<<<<<<< + * raise ValueError('invalid VariantRecord') * */ - __pyx_t_4 = ((__pyx_v_index < 0) != 0); - if (!__pyx_t_4) { - } else { - __pyx_t_5 = __pyx_t_4; - goto __pyx_L5_bool_binop_done; - } - __pyx_t_4 = ((__pyx_v_index >= __pyx_v_n) != 0); - __pyx_t_5 = __pyx_t_4; - __pyx_L5_bool_binop_done:; - if (unlikely(__pyx_t_5)) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_record)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2341, __pyx_L1_error) + __pyx_t_2 = ((!__pyx_t_1) != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2035 - * - * if index < 0 or index >= n: - * raise IndexError('invalid filter index') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2342 + * cdef VariantRecordFilter makeVariantRecordFilter(VariantRecord record): + * if not record: + * raise ValueError('invalid VariantRecord') # <<<<<<<<<<<<<< * - * id = r.d.flt[index] + * cdef VariantRecordFilter filter = VariantRecordFilter.__new__(VariantRecordFilter) */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__111, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2035, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 2035, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__108, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2342, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 2342, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2034 - * index = key - * - * if index < 0 or index >= n: # <<<<<<<<<<<<<< - * raise IndexError('invalid filter index') + /* "pysam/libcbcf.pyx":2341 * - */ - } - - /* "pysam/libcbcf.pyx":2037 - * raise IndexError('invalid filter index') + * cdef VariantRecordFilter makeVariantRecordFilter(VariantRecord record): + * if not record: # <<<<<<<<<<<<<< + * raise ValueError('invalid VariantRecord') * - * id = r.d.flt[index] # <<<<<<<<<<<<<< - * else: - * if key == '.': */ - __pyx_v_id = (__pyx_v_r->d.flt[__pyx_v_index]); + } - /* "pysam/libcbcf.pyx":2031 - * cdef int n = r.d.n_flt + /* "pysam/libcbcf.pyx":2344 + * raise ValueError('invalid VariantRecord') * - * if isinstance(key, int): # <<<<<<<<<<<<<< - * index = key + * cdef VariantRecordFilter filter = VariantRecordFilter.__new__(VariantRecordFilter) # <<<<<<<<<<<<<< + * filter.record = record * */ - goto __pyx_L3; - } + __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantRecordFilter(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordFilter), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2344, __pyx_L1_error) + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_v_filter = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2039 - * id = r.d.flt[index] - * else: - * if key == '.': # <<<<<<<<<<<<<< - * key = 'PASS' + /* "pysam/libcbcf.pyx":2345 * - */ - /*else*/ { - __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_kp_s__71, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2039, __pyx_L1_error) - if (__pyx_t_5) { - - /* "pysam/libcbcf.pyx":2040 - * else: - * if key == '.': - * key = 'PASS' # <<<<<<<<<<<<<< + * cdef VariantRecordFilter filter = VariantRecordFilter.__new__(VariantRecordFilter) + * filter.record = record # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * return filter */ - __Pyx_INCREF(__pyx_n_s_PASS); - __Pyx_DECREF_SET(__pyx_v_key, __pyx_n_s_PASS); + __Pyx_INCREF(((PyObject *)__pyx_v_record)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_record)); + __Pyx_GOTREF(__pyx_v_filter->record); + __Pyx_DECREF(((PyObject *)__pyx_v_filter->record)); + __pyx_v_filter->record = __pyx_v_record; - /* "pysam/libcbcf.pyx":2039 - * id = r.d.flt[index] - * else: - * if key == '.': # <<<<<<<<<<<<<< - * key = 'PASS' + /* "pysam/libcbcf.pyx":2347 + * filter.record = record * - */ - } - - /* "pysam/libcbcf.pyx":2042 - * key = 'PASS' + * return filter # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< - * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) * */ - __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2042, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_v_bkey = ((PyObject*)__pyx_t_6); - __pyx_t_6 = 0; + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_filter)); + __pyx_r = __pyx_v_filter; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":2043 + /* "pysam/libcbcf.pyx":2340 * - * bkey = force_bytes(key) - * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) # <<<<<<<<<<<<<< * - * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): + * cdef VariantRecordFilter makeVariantRecordFilter(VariantRecord record): # <<<<<<<<<<<<<< + * if not record: + * raise ValueError('invalid VariantRecord') */ - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2043, __pyx_L1_error) - } - __pyx_t_7 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 2043, __pyx_L1_error) - __pyx_v_id = bcf_hdr_id2int(__pyx_v_hdr, BCF_DT_ID, __pyx_t_7); - /* "pysam/libcbcf.pyx":2045 - * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) - * - * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): # <<<<<<<<<<<<<< - * raise KeyError('Invalid filter') - * - */ - __pyx_t_4 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_FLT, __pyx_v_id) != 0)) != 0); - if (!__pyx_t_4) { - } else { - __pyx_t_5 = __pyx_t_4; - goto __pyx_L9_bool_binop_done; - } - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2045, __pyx_L1_error) - } - __pyx_t_8 = __Pyx_PyBytes_AsWritableString(__pyx_v_bkey); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 2045, __pyx_L1_error) - __pyx_t_4 = ((!(bcf_has_filter(__pyx_v_hdr, __pyx_v_r, __pyx_t_8) != 0)) != 0); - __pyx_t_5 = __pyx_t_4; - __pyx_L9_bool_binop_done:; - if (unlikely(__pyx_t_5)) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.makeVariantRecordFilter", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_filter); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcbcf.pyx":2046 - * - * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): - * raise KeyError('Invalid filter') # <<<<<<<<<<<<<< +/* "pysam/libcbcf.pyx":2353 + * """Format data present for each sample in a :class:`VariantRecord` object, + * presented as mapping from format name to :class:`VariantMetadata` object.""" + * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< + * raise TypeError('this class cannot be instantiated from Python') * - * bcf_remove_filter(hdr, r, id, 0) */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__112, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2046, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 2046, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2045 - * id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) - * - * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): # <<<<<<<<<<<<<< - * raise KeyError('Invalid filter') - * - */ - } - } - __pyx_L3:; +/* Python wrapper */ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + CYTHON_UNUSED PyObject *__pyx_v_args = 0; + CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1; + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat___init__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); - /* "pysam/libcbcf.pyx":2048 - * raise KeyError('Invalid filter') - * - * bcf_remove_filter(hdr, r, id, 0) # <<<<<<<<<<<<<< + /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__init__", 0); + __Pyx_TraceCall("__init__", __pyx_f[0], 2353, 0, __PYX_ERR(0, 2353, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2354 + * presented as mapping from format name to :class:`VariantMetadata` object.""" + * def __init__(self, *args, **kwargs): + * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * - * def clear(self): + * def __len__(self): */ - (void)(bcf_remove_filter(__pyx_v_hdr, __pyx_v_r, __pyx_v_id, 0)); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__109, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2354, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2354, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2025 - * bcf_add_filter(hdr, r, id) + /* "pysam/libcbcf.pyx":2353 + * """Format data present for each sample in a :class:`VariantRecord` object, + * presented as mapping from format name to :class:`VariantMetadata` object.""" + * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< + * raise TypeError('this class cannot be instantiated from Python') * - * def __delitem__(self, key): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__delitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_bkey); - __Pyx_XDECREF(__pyx_v_key); __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2050 - * bcf_remove_filter(hdr, r, id, 0) +/* "pysam/libcbcf.pyx":2356 + * raise TypeError('this class cannot be instantiated from Python') * - * def clear(self): # <<<<<<<<<<<<<< - * """Clear all filters""" + * def __len__(self): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_13clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_12clear[] = "VariantRecordFilter.clear(self)\nClear all filters"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_13clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; +static Py_ssize_t __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_3__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_3__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("clear (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_12clear(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_2__len__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_12clear(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { +static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_2__len__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { + CYTHON_UNUSED bcf_hdr_t *__pyx_v_hdr; bcf1_t *__pyx_v_r; - PyObject *__pyx_r = NULL; + int __pyx_v_i; + int __pyx_v_n; + Py_ssize_t __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bcf1_t *__pyx_t_1; - __Pyx_RefNannySetupContext("clear", 0); - __Pyx_TraceCall("clear", __pyx_f[0], 2050, 0, __PYX_ERR(0, 2050, __pyx_L1_error)); + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; + uint32_t __pyx_t_3; + uint32_t __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__len__", 0); + __Pyx_TraceCall("__len__", __pyx_f[0], 2356, 0, __PYX_ERR(0, 2356, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2052 - * def clear(self): - * """Clear all filters""" + /* "pysam/libcbcf.pyx":2357 + * + * def __len__(self): + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef int i, n = 0 + */ + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; + + /* "pysam/libcbcf.pyx":2358 + * def __len__(self): + * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * r.d.shared_dirty |= BCF1_DIRTY_FLT - * r.d.n_flt = 0 + * cdef int i, n = 0 + * */ - __pyx_t_1 = __pyx_v_self->record->ptr; - __pyx_v_r = __pyx_t_1; + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2053 - * """Clear all filters""" + /* "pysam/libcbcf.pyx":2359 + * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr - * r.d.shared_dirty |= BCF1_DIRTY_FLT # <<<<<<<<<<<<<< - * r.d.n_flt = 0 + * cdef int i, n = 0 # <<<<<<<<<<<<<< + * + * for i in range(r.n_fmt): + */ + __pyx_v_n = 0; + + /* "pysam/libcbcf.pyx":2361 + * cdef int i, n = 0 + * + * for i in range(r.n_fmt): # <<<<<<<<<<<<<< + * if r.d.fmt[i].p: + * n += 1 + */ + __pyx_t_3 = __pyx_v_r->n_fmt; + __pyx_t_4 = __pyx_t_3; + for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { + __pyx_v_i = __pyx_t_5; + + /* "pysam/libcbcf.pyx":2362 + * + * for i in range(r.n_fmt): + * if r.d.fmt[i].p: # <<<<<<<<<<<<<< + * n += 1 + * return n + */ + __pyx_t_6 = ((__pyx_v_r->d.fmt[__pyx_v_i]).p != 0); + if (__pyx_t_6) { + + /* "pysam/libcbcf.pyx":2363 + * for i in range(r.n_fmt): + * if r.d.fmt[i].p: + * n += 1 # <<<<<<<<<<<<<< + * return n + * + */ + __pyx_v_n = (__pyx_v_n + 1); + + /* "pysam/libcbcf.pyx":2362 * + * for i in range(r.n_fmt): + * if r.d.fmt[i].p: # <<<<<<<<<<<<<< + * n += 1 + * return n */ - __pyx_v_r->d.shared_dirty = (__pyx_v_r->d.shared_dirty | BCF1_DIRTY_FLT); + } + } - /* "pysam/libcbcf.pyx":2054 - * cdef bcf1_t *r = self.record.ptr - * r.d.shared_dirty |= BCF1_DIRTY_FLT - * r.d.n_flt = 0 # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2364 + * if r.d.fmt[i].p: + * n += 1 + * return n # <<<<<<<<<<<<<< * - * def __iter__(self): + * def __bool__(self): */ - __pyx_v_r->d.n_flt = 0; + __pyx_r = __pyx_v_n; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":2050 - * bcf_remove_filter(hdr, r, id, 0) + /* "pysam/libcbcf.pyx":2356 + * raise TypeError('this class cannot be instantiated from Python') * - * def clear(self): # <<<<<<<<<<<<<< - * """Clear all filters""" + * def __len__(self): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.clear", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_16generator11(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":2056 - * r.d.n_flt = 0 +/* "pysam/libcbcf.pyx":2366 + * return n * - * def __iter__(self): # <<<<<<<<<<<<<< + * def __bool__(self): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_15__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_15__iter__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_14__iter__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_14__iter__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_21___iter__ *__pyx_cur_scope; - PyObject *__pyx_r = NULL; +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_5__bool__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_5__bool__(PyObject *__pyx_v_self) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_21___iter__ *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_21___iter__(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_21___iter__, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_21___iter__ *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2056, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_16generator11, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantRecordFilter___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2056, __pyx_L1_error) - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__bool__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_4__bool__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_16generator11(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_21___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_21___iter__ *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_4__bool__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { + CYTHON_UNUSED bcf_hdr_t *__pyx_v_hdr; + bcf1_t *__pyx_v_r; + int __pyx_v_i; + int __pyx_r; __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; bcf1_t *__pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; + uint32_t __pyx_t_3; + uint32_t __pyx_t_4; int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 2056, 0, __PYX_ERR(0, 2056, __pyx_L1_error)); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return NULL; - } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2056, __pyx_L1_error) + int __pyx_t_6; + __Pyx_RefNannySetupContext("__bool__", 0); + __Pyx_TraceCall("__bool__", __pyx_f[0], 2366, 0, __PYX_ERR(0, 2366, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2057 + /* "pysam/libcbcf.pyx":2367 * - * def __iter__(self): + * def __bool__(self): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr * cdef int i */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; - __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2058 - * def __iter__(self): + /* "pysam/libcbcf.pyx":2368 + * def __bool__(self): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< * cdef int i * */ - __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; - __pyx_cur_scope->__pyx_v_r = __pyx_t_2; + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2061 + /* "pysam/libcbcf.pyx":2371 * cdef int i * - * for i in range(r.d.n_flt): # <<<<<<<<<<<<<< - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, r.d.flt[i])) - * + * for i in range(r.n_fmt): # <<<<<<<<<<<<<< + * if r.d.fmt[i].p: + * return True */ - __pyx_t_3 = __pyx_cur_scope->__pyx_v_r->d.n_flt; + __pyx_t_3 = __pyx_v_r->n_fmt; __pyx_t_4 = __pyx_t_3; for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_5; + __pyx_v_i = __pyx_t_5; - /* "pysam/libcbcf.pyx":2062 + /* "pysam/libcbcf.pyx":2372 * - * for i in range(r.d.n_flt): - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, r.d.flt[i])) # <<<<<<<<<<<<<< + * for i in range(r.n_fmt): + * if r.d.fmt[i].p: # <<<<<<<<<<<<<< + * return True + * return False + */ + __pyx_t_6 = ((__pyx_v_r->d.fmt[__pyx_v_i]).p != 0); + if (__pyx_t_6) { + + /* "pysam/libcbcf.pyx":2373 + * for i in range(r.n_fmt): + * if r.d.fmt[i].p: + * return True # <<<<<<<<<<<<<< + * return False * - * def get(self, key, default=None): */ - __pyx_t_6 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_int2id(__pyx_cur_scope->__pyx_v_hdr, BCF_DT_ID, (__pyx_cur_scope->__pyx_v_r->d.flt[__pyx_cur_scope->__pyx_v_i]))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2062, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_r = __pyx_t_6; - __pyx_t_6 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2062, __pyx_L1_error) + __pyx_r = 1; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2372 + * + * for i in range(r.n_fmt): + * if r.d.fmt[i].p: # <<<<<<<<<<<<<< + * return True + * return False + */ + } } - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2056 - * r.d.n_flt = 0 + /* "pysam/libcbcf.pyx":2374 + * if r.d.fmt[i].p: + * return True + * return False # <<<<<<<<<<<<<< * - * def __iter__(self): # <<<<<<<<<<<<<< + * def __getitem__(self, key): + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2366 + * return n + * + * def __bool__(self): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2064 - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, r.d.flt[i])) +/* "pysam/libcbcf.pyx":2376 + * return False * - * def get(self, key, default=None): # <<<<<<<<<<<<<< - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: + * def __getitem__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_18get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_17get[] = "VariantRecordFilter.get(self, key, default=None)\nD.get(k[,d]) -> D[k] if k in D, else d. d defaults to None."; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_18get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_key = 0; - PyObject *__pyx_v_default = 0; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_default,0}; - PyObject* values[2] = {0,0}; - values[1] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_default); - if (value) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 2064, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_key = values[0]; - __pyx_v_default = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2064, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_17get(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), __pyx_v_key, __pyx_v_default); + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_6__getitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self), ((PyObject *)__pyx_v_key)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_17get(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_6__getitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, PyObject *__pyx_v_key) { + bcf_hdr_t *__pyx_v_hdr; + bcf1_t *__pyx_v_r; + PyObject *__pyx_v_bkey = 0; + bcf_fmt_t *__pyx_v_fmt; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; + char const *__pyx_t_4; int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; + int __pyx_t_6; PyObject *__pyx_t_7 = NULL; - __Pyx_RefNannySetupContext("get", 0); - __Pyx_TraceCall("get", __pyx_f[0], 2064, 0, __PYX_ERR(0, 2064, __pyx_L1_error)); + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("__getitem__", 0); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 2376, 0, __PYX_ERR(0, 2376, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2066 - * def get(self, key, default=None): - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: # <<<<<<<<<<<<<< - * return self[key] - * except KeyError: + /* "pysam/libcbcf.pyx":2377 + * + * def __getitem__(self, key): + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_1); - __Pyx_XGOTREF(__pyx_t_2); - __Pyx_XGOTREF(__pyx_t_3); - /*try:*/ { + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2067 - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: - * return self[key] # <<<<<<<<<<<<<< - * except KeyError: - * return default + /* "pysam/libcbcf.pyx":2378 + * def __getitem__(self, key): + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * + * cdef bytes bkey = force_bytes(key) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2067, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L7_try_return; + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2066 - * def get(self, key, default=None): - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: # <<<<<<<<<<<<<< - * return self[key] - * except KeyError: + /* "pysam/libcbcf.pyx":2380 + * cdef bcf1_t *r = self.record.ptr + * + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) + * */ - } - __pyx_L3_error:; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2380, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_bkey = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2068 - * try: - * return self[key] - * except KeyError: # <<<<<<<<<<<<<< - * return default + /* "pysam/libcbcf.pyx":2381 + * + * cdef bytes bkey = force_bytes(key) + * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) # <<<<<<<<<<<<<< * + * if not fmt or not fmt.p: */ - __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); - if (__pyx_t_5) { - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 2068, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2381, __pyx_L1_error) + } + __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2381, __pyx_L1_error) + __pyx_v_fmt = bcf_get_fmt(__pyx_v_hdr, __pyx_v_r, __pyx_t_4); - /* "pysam/libcbcf.pyx":2069 - * return self[key] - * except KeyError: - * return default # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2383 + * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) + * + * if not fmt or not fmt.p: # <<<<<<<<<<<<<< + * raise KeyError('unknown format: {}'.format(key)) * - * def __contains__(self, key): */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_default); - __pyx_r = __pyx_v_default; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L6_except_return; + __pyx_t_6 = ((!(__pyx_v_fmt != 0)) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_6 = ((!(__pyx_v_fmt->p != 0)) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L4_bool_binop_done:; + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcbcf.pyx":2384 + * + * if not fmt or not fmt.p: + * raise KeyError('unknown format: {}'.format(key)) # <<<<<<<<<<<<<< + * + * return makeVariantMetadata(self.record.header, BCF_HL_FMT, fmt.id) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unknown_format, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2384, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; + if (!__pyx_t_8) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2384, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_key}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2384, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_key}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2384, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2384, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_key); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2384, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2384, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 2384, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2066 - * def get(self, key, default=None): - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: # <<<<<<<<<<<<<< - * return self[key] - * except KeyError: + /* "pysam/libcbcf.pyx":2383 + * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) + * + * if not fmt or not fmt.p: # <<<<<<<<<<<<<< + * raise KeyError('unknown format: {}'.format(key)) + * */ - __Pyx_XGIVEREF(__pyx_t_1); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); - goto __pyx_L1_error; - __pyx_L7_try_return:; - __Pyx_XGIVEREF(__pyx_t_1); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); - goto __pyx_L0; - __pyx_L6_except_return:; - __Pyx_XGIVEREF(__pyx_t_1); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); - goto __pyx_L0; } - /* "pysam/libcbcf.pyx":2064 - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, r.d.flt[i])) + /* "pysam/libcbcf.pyx":2386 + * raise KeyError('unknown format: {}'.format(key)) * - * def get(self, key, default=None): # <<<<<<<<<<<<<< - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: + * return makeVariantMetadata(self.record.header, BCF_HL_FMT, fmt.id) # <<<<<<<<<<<<<< + * + * def __delitem__(self, key): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_7 = ((PyObject *)__pyx_v_self->record->header); + __Pyx_INCREF(__pyx_t_7); + __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantMetadata(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_7), BCF_HL_FMT, __pyx_v_fmt->id)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2386, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2376 + * return False + * + * def __getitem__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.get", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_bkey); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2071 - * return default +/* "pysam/libcbcf.pyx":2388 + * return makeVariantMetadata(self.record.header, BCF_HL_FMT, fmt.id) * - * def __contains__(self, key): # <<<<<<<<<<<<<< + * def __delitem__(self, key): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_20__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_20__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_9__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_9__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_19__contains__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + __Pyx_RefNannySetupContext("__delitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_8__delitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self), ((PyObject *)__pyx_v_key)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_19__contains__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v_key) { +static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_8__delitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, PyObject *__pyx_v_key) { bcf_hdr_t *__pyx_v_hdr; bcf1_t *__pyx_v_r; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; + bcf_fmt_t *__pyx_v_fmt; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; bcf1_t *__pyx_t_2; PyObject *__pyx_t_3 = NULL; - char *__pyx_t_4; - __Pyx_RefNannySetupContext("__contains__", 0); - __Pyx_TraceCall("__contains__", __pyx_f[0], 2071, 0, __PYX_ERR(0, 2071, __pyx_L1_error)); + char const *__pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + char const *__pyx_t_10; + __Pyx_RefNannySetupContext("__delitem__", 0); + __Pyx_TraceCall("__delitem__", __pyx_f[0], 2388, 0, __PYX_ERR(0, 2388, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2072 + /* "pysam/libcbcf.pyx":2389 * - * def __contains__(self, key): + * def __delitem__(self, key): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr - * bkey = force_bytes(key) + * */ __pyx_t_1 = __pyx_v_self->record->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2073 - * def __contains__(self, key): + /* "pysam/libcbcf.pyx":2390 + * def __delitem__(self, key): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * bkey = force_bytes(key) - * return bcf_has_filter(hdr, r, bkey) == 1 + * + * cdef bytes bkey = force_bytes(key) */ __pyx_t_2 = __pyx_v_self->record->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2074 - * cdef bcf_hdr_t *hdr = self.record.header.ptr + /* "pysam/libcbcf.pyx":2392 * cdef bcf1_t *r = self.record.ptr - * bkey = force_bytes(key) # <<<<<<<<<<<<<< - * return bcf_has_filter(hdr, r, bkey) == 1 + * + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2074, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2392, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_bkey = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2075 - * cdef bcf1_t *r = self.record.ptr - * bkey = force_bytes(key) - * return bcf_has_filter(hdr, r, bkey) == 1 # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2393 * - * def iterkeys(self): + * cdef bytes bkey = force_bytes(key) + * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) # <<<<<<<<<<<<<< + * + * if not fmt or not fmt.p: */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2075, __pyx_L1_error) + __PYX_ERR(0, 2393, __pyx_L1_error) } - __pyx_t_4 = __Pyx_PyBytes_AsWritableString(__pyx_v_bkey); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2075, __pyx_L1_error) - __pyx_r = (bcf_has_filter(__pyx_v_hdr, __pyx_v_r, __pyx_t_4) == 1); - goto __pyx_L0; + __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2393, __pyx_L1_error) + __pyx_v_fmt = bcf_get_fmt(__pyx_v_hdr, __pyx_v_r, __pyx_t_4); - /* "pysam/libcbcf.pyx":2071 - * return default + /* "pysam/libcbcf.pyx":2395 + * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * - * def __contains__(self, key): # <<<<<<<<<<<<<< + * if not fmt or not fmt.p: # <<<<<<<<<<<<<< + * raise KeyError('unknown format: {}'.format(key)) + * + */ + __pyx_t_6 = ((!(__pyx_v_fmt != 0)) != 0); + if (!__pyx_t_6) { + } else { + __pyx_t_5 = __pyx_t_6; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_6 = ((!(__pyx_v_fmt->p != 0)) != 0); + __pyx_t_5 = __pyx_t_6; + __pyx_L4_bool_binop_done:; + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcbcf.pyx":2396 + * + * if not fmt or not fmt.p: + * raise KeyError('unknown format: {}'.format(key)) # <<<<<<<<<<<<<< + * + * if bcf_update_format(hdr, r, bkey, fmt.p, 0, fmt.type) < 0: + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unknown_format, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2396, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_8) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2396, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_key}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2396, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_key}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2396, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2396, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_key); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2396, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2396, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 2396, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2395 + * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) + * + * if not fmt or not fmt.p: # <<<<<<<<<<<<<< + * raise KeyError('unknown format: {}'.format(key)) + * + */ + } + + /* "pysam/libcbcf.pyx":2398 + * raise KeyError('unknown format: {}'.format(key)) + * + * if bcf_update_format(hdr, r, bkey, fmt.p, 0, fmt.type) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Unable to delete FORMAT') + * + */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2398, __pyx_L1_error) + } + __pyx_t_10 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 2398, __pyx_L1_error) + __pyx_t_5 = ((bcf_update_format(__pyx_v_hdr, __pyx_v_r, __pyx_t_10, __pyx_v_fmt->p, 0, __pyx_v_fmt->type) < 0) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcbcf.pyx":2399 + * + * if bcf_update_format(hdr, r, bkey, fmt.p, 0, fmt.type) < 0: + * raise ValueError('Unable to delete FORMAT') # <<<<<<<<<<<<<< + * + * def clear(self): + */ + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__110, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2399, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 2399, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2398 + * raise KeyError('unknown format: {}'.format(key)) + * + * if bcf_update_format(hdr, r, bkey, fmt.p, 0, fmt.type) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Unable to delete FORMAT') + * + */ + } + + /* "pysam/libcbcf.pyx":2388 + * return makeVariantMetadata(self.record.header, BCF_HL_FMT, fmt.id) + * + * def __delitem__(self, key): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__delitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_bkey); @@ -33949,299 +39350,199 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_19__contains__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":2077 - * return bcf_has_filter(hdr, r, bkey) == 1 +/* "pysam/libcbcf.pyx":2401 + * raise ValueError('Unable to delete FORMAT') * - * def iterkeys(self): # <<<<<<<<<<<<<< - * """D.iterkeys() -> an iterator over the keys of D""" - * return iter(self) + * def clear(self): # <<<<<<<<<<<<<< + * """Clear all formats for all samples within the associated + * :class:`VariantRecord` instance""" */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_22iterkeys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_21iterkeys[] = "VariantRecordFilter.iterkeys(self)\nD.iterkeys() -> an iterator over the keys of D"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_22iterkeys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_10clear[] = "VariantRecordFormat.clear(self)\nClear all formats for all samples within the associated\n :class:`VariantRecord` instance"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("iterkeys (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_21iterkeys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + __Pyx_RefNannySetupContext("clear (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_10clear(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_21iterkeys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_10clear(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { + bcf_hdr_t *__pyx_v_hdr; + bcf1_t *__pyx_v_r; + bcf_fmt_t *__pyx_v_fmt; + char const *__pyx_v_key; + int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("iterkeys", 0); - __Pyx_TraceCall("iterkeys", __pyx_f[0], 2077, 0, __PYX_ERR(0, 2077, __pyx_L1_error)); + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("clear", 0); + __Pyx_TraceCall("clear", __pyx_f[0], 2401, 0, __PYX_ERR(0, 2401, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2079 - * def iterkeys(self): - * """D.iterkeys() -> an iterator over the keys of D""" - * return iter(self) # <<<<<<<<<<<<<< - * - * def itervalues(self): + /* "pysam/libcbcf.pyx":2404 + * """Clear all formats for all samples within the associated + * :class:`VariantRecord` instance""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef bcf_fmt_t *fmt */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2079, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2077 - * return bcf_has_filter(hdr, r, bkey) == 1 - * - * def iterkeys(self): # <<<<<<<<<<<<<< - * """D.iterkeys() -> an iterator over the keys of D""" - * return iter(self) + /* "pysam/libcbcf.pyx":2405 + * :class:`VariantRecord` instance""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef bcf_fmt_t *fmt + * cdef const char *key */ + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.iterkeys", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_25generator12(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ - -/* "pysam/libcbcf.pyx":2081 - * return iter(self) + /* "pysam/libcbcf.pyx":2410 + * cdef int i * - * def itervalues(self): # <<<<<<<<<<<<<< - * """D.itervalues() -> an iterator over the values of D""" - * for key in self: + * for i in reversed(range(r.n_fmt)): # <<<<<<<<<<<<<< + * fmt = &r.d.fmt[i] + * if fmt.p: */ + for (__pyx_t_3 = __pyx_v_r->n_fmt-1; __pyx_t_3 >= 0; __pyx_t_3-=1) { + __pyx_v_i = __pyx_t_3; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_24itervalues(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_23itervalues[] = "VariantRecordFilter.itervalues(self)\nD.itervalues() -> an iterator over the values of D"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_24itervalues(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("itervalues (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_23itervalues(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_23itervalues(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_22_itervalues *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("itervalues", 0); - __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_22_itervalues *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_22_itervalues(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_22_itervalues, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_22_itervalues *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2081, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_25generator12, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantRecordFilter_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2081, __pyx_L1_error) - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + /* "pysam/libcbcf.pyx":2411 + * + * for i in reversed(range(r.n_fmt)): + * fmt = &r.d.fmt[i] # <<<<<<<<<<<<<< + * if fmt.p: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) + */ + __pyx_v_fmt = (&(__pyx_v_r->d.fmt[__pyx_v_i])); - /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2412 + * for i in reversed(range(r.n_fmt)): + * fmt = &r.d.fmt[i] + * if fmt.p: # <<<<<<<<<<<<<< + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) + * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: + */ + __pyx_t_4 = (__pyx_v_fmt->p != 0); + if (__pyx_t_4) { -static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_25generator12(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_22_itervalues *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_22_itervalues *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *(*__pyx_t_3)(PyObject *); - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("itervalues", 0); - __Pyx_TraceCall("itervalues", __pyx_f[0], 2081, 0, __PYX_ERR(0, 2081, __pyx_L1_error)); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return NULL; - } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2081, __pyx_L1_error) + /* "pysam/libcbcf.pyx":2413 + * fmt = &r.d.fmt[i] + * if fmt.p: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) # <<<<<<<<<<<<<< + * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: + * raise ValueError('Unable to delete FORMAT') + */ + __pyx_v_key = bcf_hdr_int2id(__pyx_v_hdr, BCF_DT_ID, __pyx_v_fmt->id); - /* "pysam/libcbcf.pyx":2083 - * def itervalues(self): - * """D.itervalues() -> an iterator over the values of D""" - * for key in self: # <<<<<<<<<<<<<< - * yield self[key] + /* "pysam/libcbcf.pyx":2414 + * if fmt.p: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) + * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Unable to delete FORMAT') * */ - if (likely(PyList_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) { - __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2083, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2083, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_3)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2083, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2083, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2083, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2083, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 2083, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; + __pyx_t_4 = ((bcf_update_format(__pyx_v_hdr, __pyx_v_r, __pyx_v_key, __pyx_v_fmt->p, 0, __pyx_v_fmt->type) < 0) != 0); + if (unlikely(__pyx_t_4)) { - /* "pysam/libcbcf.pyx":2084 - * """D.itervalues() -> an iterator over the values of D""" - * for key in self: - * yield self[key] # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2415 + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) + * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: + * raise ValueError('Unable to delete FORMAT') # <<<<<<<<<<<<<< * - * def iteritems(self): + * def __iter__(self): */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2084, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2084, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__111, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2415, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 2415, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2083 - * def itervalues(self): - * """D.itervalues() -> an iterator over the values of D""" - * for key in self: # <<<<<<<<<<<<<< - * yield self[key] + /* "pysam/libcbcf.pyx":2414 + * if fmt.p: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) + * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Unable to delete FORMAT') * */ + } + + /* "pysam/libcbcf.pyx":2412 + * for i in reversed(range(r.n_fmt)): + * fmt = &r.d.fmt[i] + * if fmt.p: # <<<<<<<<<<<<<< + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) + * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: + */ + } } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2081 - * return iter(self) + /* "pysam/libcbcf.pyx":2401 + * raise ValueError('Unable to delete FORMAT') * - * def itervalues(self): # <<<<<<<<<<<<<< - * """D.itervalues() -> an iterator over the values of D""" - * for key in self: + * def clear(self): # <<<<<<<<<<<<<< + * """Clear all formats for all samples within the associated + * :class:`VariantRecord` instance""" */ /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.clear", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_28generator13(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_14generator14(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":2086 - * yield self[key] +/* "pysam/libcbcf.pyx":2417 + * raise ValueError('Unable to delete FORMAT') * - * def iteritems(self): # <<<<<<<<<<<<<< - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_27iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_26iteritems[] = "VariantRecordFilter.iteritems(self)\nD.iteritems() -> an iterator over the (key, value) items of D"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_27iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_13__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_13__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("iteritems (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_26iteritems(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_12__iter__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_26iteritems(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_23_iteritems *__pyx_cur_scope; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_12__iter__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_24___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("iteritems", 0); - __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_23_iteritems *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_23_iteritems(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_23_iteritems, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_24___iter__ *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_24___iter__(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_24___iter__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_23_iteritems *)Py_None); + __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_24___iter__ *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2086, __pyx_L1_error) + __PYX_ERR(0, 2417, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -34249,7 +39550,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_26iteritems(stru __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_28generator13, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantRecordFilter_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2086, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_14generator14, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantRecordFormat___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2417, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -34257,7 +39558,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_26iteritems(stru /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); @@ -34265,146 +39566,135 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_26iteritems(stru return __pyx_r; } -static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_28generator13(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_14generator14(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_23_iteritems *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_23_iteritems *)__pyx_generator->closure); + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_24___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_24___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *(*__pyx_t_3)(PyObject *); - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; + uint32_t __pyx_t_3; + uint32_t __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("iteritems", 0); - __Pyx_TraceCall("iteritems", __pyx_f[0], 2086, 0, __PYX_ERR(0, 2086, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__iter__", 0); + __Pyx_TraceCall("__iter__", __pyx_f[0], 2417, 0, __PYX_ERR(0, 2417, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; + case 1: goto __pyx_L7_resume_from_yield; default: /* CPython raises the right error here */ __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2086, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2417, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2418 + * + * def __iter__(self): + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef bcf_fmt_t *fmt + */ + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; + __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; + + /* "pysam/libcbcf.pyx":2419 + * def __iter__(self): + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef bcf_fmt_t *fmt + * cdef int i + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; + __pyx_cur_scope->__pyx_v_r = __pyx_t_2; + + /* "pysam/libcbcf.pyx":2423 + * cdef int i + * + * for i in range(r.n_fmt): # <<<<<<<<<<<<<< + * fmt = &r.d.fmt[i] + * if fmt.p: + */ + __pyx_t_3 = __pyx_cur_scope->__pyx_v_r->n_fmt; + __pyx_t_4 = __pyx_t_3; + for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_5; + + /* "pysam/libcbcf.pyx":2424 + * + * for i in range(r.n_fmt): + * fmt = &r.d.fmt[i] # <<<<<<<<<<<<<< + * if fmt.p: + * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) + */ + __pyx_cur_scope->__pyx_v_fmt = (&(__pyx_cur_scope->__pyx_v_r->d.fmt[__pyx_cur_scope->__pyx_v_i])); - /* "pysam/libcbcf.pyx":2088 - * def iteritems(self): - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: # <<<<<<<<<<<<<< - * yield (key, self[key]) + /* "pysam/libcbcf.pyx":2425 + * for i in range(r.n_fmt): + * fmt = &r.d.fmt[i] + * if fmt.p: # <<<<<<<<<<<<<< + * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) * */ - if (likely(PyList_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) { - __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2088, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2088, __pyx_L1_error) - } - for (;;) { - if (likely(!__pyx_t_3)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2088, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2088, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2088, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2088, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 2088, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; + __pyx_t_6 = (__pyx_cur_scope->__pyx_v_fmt->p != 0); + if (__pyx_t_6) { - /* "pysam/libcbcf.pyx":2089 - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: - * yield (key, self[key]) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2426 + * fmt = &r.d.fmt[i] + * if fmt.p: + * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) # <<<<<<<<<<<<<< * - * def keys(self): + * def get(self, key, default=None): */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2089, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2089, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_cur_scope->__pyx_v_key); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2089, __pyx_L1_error) + __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_int2id(__pyx_cur_scope->__pyx_v_hdr, BCF_DT_ID, __pyx_cur_scope->__pyx_v_fmt->id)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L7_resume_from_yield:; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2426, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2088 - * def iteritems(self): - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: # <<<<<<<<<<<<<< - * yield (key, self[key]) + /* "pysam/libcbcf.pyx":2425 + * for i in range(r.n_fmt): + * fmt = &r.d.fmt[i] + * if fmt.p: # <<<<<<<<<<<<<< + * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) * */ + } } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2086 - * yield self[key] + /* "pysam/libcbcf.pyx":2417 + * raise ValueError('Unable to delete FORMAT') * - * def iteritems(self): # <<<<<<<<<<<<<< - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_r = 0; __Pyx_Coroutine_ResetAndClearException(__pyx_generator); @@ -34415,62 +39705,208 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFilter_28generator13(__ return __pyx_r; } -/* "pysam/libcbcf.pyx":2091 - * yield (key, self[key]) +/* "pysam/libcbcf.pyx":2428 + * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) * - * def keys(self): # <<<<<<<<<<<<<< - * """D.keys() -> list of D's keys""" - * return list(self) + * def get(self, key, default=None): # <<<<<<<<<<<<<< + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" + * try: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_30keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_29keys[] = "VariantRecordFilter.keys(self)\nD.keys() -> list of D's keys"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_30keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_16get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_15get[] = "VariantRecordFormat.get(self, key, default=None)\nD.get(k[,d]) -> D[k] if k in D, else d. d defaults to None."; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_16get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_key = 0; + PyObject *__pyx_v_default = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("keys (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_29keys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + __Pyx_RefNannySetupContext("get (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_default,0}; + PyObject* values[2] = {0,0}; + values[1] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_default); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 2428, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_key = values[0]; + __pyx_v_default = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2428, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.get", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_15get(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self), __pyx_v_key, __pyx_v_default); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_29keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_15get(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("keys", 0); - __Pyx_TraceCall("keys", __pyx_f[0], 2091, 0, __PYX_ERR(0, 2091, __pyx_L1_error)); + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("get", 0); + __Pyx_TraceCall("get", __pyx_f[0], 2428, 0, __PYX_ERR(0, 2428, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2093 - * def keys(self): - * """D.keys() -> list of D's keys""" - * return list(self) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2430 + * def get(self, key, default=None): + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" + * try: # <<<<<<<<<<<<<< + * return self[key] + * except KeyError: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "pysam/libcbcf.pyx":2431 + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" + * try: + * return self[key] # <<<<<<<<<<<<<< + * except KeyError: + * return default + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2431, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L7_try_return; + + /* "pysam/libcbcf.pyx":2430 + * def get(self, key, default=None): + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" + * try: # <<<<<<<<<<<<<< + * return self[key] + * except KeyError: + */ + } + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libcbcf.pyx":2432 + * try: + * return self[key] + * except KeyError: # <<<<<<<<<<<<<< + * return default * - * def items(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2093, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); + if (__pyx_t_5) { + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.get", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 2432, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcbcf.pyx":2091 - * yield (key, self[key]) + /* "pysam/libcbcf.pyx":2433 + * return self[key] + * except KeyError: + * return default # <<<<<<<<<<<<<< * - * def keys(self): # <<<<<<<<<<<<<< - * """D.keys() -> list of D's keys""" - * return list(self) + * def __contains__(self, key): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_default); + __pyx_r = __pyx_v_default; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_except_return; + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "pysam/libcbcf.pyx":2430 + * def get(self, key, default=None): + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" + * try: # <<<<<<<<<<<<<< + * return self[key] + * except KeyError: + */ + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L7_try_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + __pyx_L6_except_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + } + + /* "pysam/libcbcf.pyx":2428 + * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) + * + * def get(self, key, default=None): # <<<<<<<<<<<<<< + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" + * try: */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.get", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -34479,176 +39915,185 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_29keys(struct __ return __pyx_r; } -/* "pysam/libcbcf.pyx":2095 - * return list(self) +/* "pysam/libcbcf.pyx":2435 + * return default * - * def items(self): # <<<<<<<<<<<<<< - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) + * def __contains__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_32items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_31items[] = "VariantRecordFilter.items(self)\nD.items() -> list of D's (key, value) pairs, as 2-tuples"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_32items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_18__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_18__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("items (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_31items(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_17__contains__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self), ((PyObject *)__pyx_v_key)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_31items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_17__contains__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, PyObject *__pyx_v_key) { + bcf_hdr_t *__pyx_v_hdr; + bcf1_t *__pyx_v_r; + PyObject *__pyx_v_bkey = 0; + bcf_fmt_t *__pyx_v_fmt; + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("items", 0); - __Pyx_TraceCall("items", __pyx_f[0], 2095, 0, __PYX_ERR(0, 2095, __pyx_L1_error)); + char const *__pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__contains__", 0); + __Pyx_TraceCall("__contains__", __pyx_f[0], 2435, 0, __PYX_ERR(0, 2435, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2097 - * def items(self): - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2436 * - * def values(self): + * def __contains__(self, key): + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef bytes bkey = force_bytes(key) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2097, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; + + /* "pysam/libcbcf.pyx":2437 + * def __contains__(self, key): + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) + * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) + */ + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; + + /* "pysam/libcbcf.pyx":2438 + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) + * return fmt != NULL and fmt.p != NULL + */ + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_bkey = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":2439 + * cdef bcf1_t *r = self.record.ptr + * cdef bytes bkey = force_bytes(key) + * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) # <<<<<<<<<<<<<< + * return fmt != NULL and fmt.p != NULL + * + */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2439, __pyx_L1_error) } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2097, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2439, __pyx_L1_error) + __pyx_v_fmt = bcf_get_fmt(__pyx_v_hdr, __pyx_v_r, __pyx_t_4); + + /* "pysam/libcbcf.pyx":2440 + * cdef bytes bkey = force_bytes(key) + * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) + * return fmt != NULL and fmt.p != NULL # <<<<<<<<<<<<<< + * + * def iterkeys(self): + */ + __pyx_t_6 = (__pyx_v_fmt != NULL); + if (__pyx_t_6) { } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2097, __pyx_L1_error) + __pyx_t_5 = __pyx_t_6; + goto __pyx_L3_bool_binop_done; } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2097, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_t_6 = (__pyx_v_fmt->p != NULL); + __pyx_t_5 = __pyx_t_6; + __pyx_L3_bool_binop_done:; + __pyx_r = __pyx_t_5; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2095 - * return list(self) + /* "pysam/libcbcf.pyx":2435 + * return default * - * def items(self): # <<<<<<<<<<<<<< - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) + * def __contains__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.items", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_XDECREF(__pyx_v_bkey); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2099 - * return list(self.iteritems()) +/* "pysam/libcbcf.pyx":2442 + * return fmt != NULL and fmt.p != NULL * - * def values(self): # <<<<<<<<<<<<<< - * """D.values() -> list of D's values""" - * return list(self.itervalues()) + * def iterkeys(self): # <<<<<<<<<<<<<< + * """D.iterkeys() -> an iterator over the keys of D""" + * return iter(self) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_34values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_33values[] = "VariantRecordFilter.values(self)\nD.values() -> list of D's values"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_34values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_20iterkeys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_19iterkeys[] = "VariantRecordFormat.iterkeys(self)\nD.iterkeys() -> an iterator over the keys of D"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_20iterkeys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("values (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_33values(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + __Pyx_RefNannySetupContext("iterkeys (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_19iterkeys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_33values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_19iterkeys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("values", 0); - __Pyx_TraceCall("values", __pyx_f[0], 2099, 0, __PYX_ERR(0, 2099, __pyx_L1_error)); + __Pyx_RefNannySetupContext("iterkeys", 0); + __Pyx_TraceCall("iterkeys", __pyx_f[0], 2442, 0, __PYX_ERR(0, 2442, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2101 - * def values(self): - * """D.values() -> list of D's values""" - * return list(self.itervalues()) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2444 + * def iterkeys(self): + * """D.iterkeys() -> an iterator over the keys of D""" + * return iter(self) # <<<<<<<<<<<<<< * - * # Mappings are not hashable by default, but subclasses can change this + * def itervalues(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2101, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2101, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2101, __pyx_L1_error) - } + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2444, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2101, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2099 - * return list(self.iteritems()) + /* "pysam/libcbcf.pyx":2442 + * return fmt != NULL and fmt.p != NULL * - * def values(self): # <<<<<<<<<<<<<< - * """D.values() -> list of D's values""" - * return list(self.itervalues()) + * def iterkeys(self): # <<<<<<<<<<<<<< + * """D.iterkeys() -> an iterator over the keys of D""" + * return iter(self) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.iterkeys", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -34656,3099 +40101,3188 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_33values(struct __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_23generator15(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * cdef bint use_setstate - * state = (self.record,) +/* "pysam/libcbcf.pyx":2446 + * return iter(self) + * + * def itervalues(self): # <<<<<<<<<<<<<< + * """D.itervalues() -> an iterator over the values of D""" + * for key in self: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_36__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_35__reduce_cython__[] = "VariantRecordFilter.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_36__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_22itervalues(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_21itervalues[] = "VariantRecordFormat.itervalues(self)\nD.itervalues() -> an iterator over the values of D"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_22itervalues(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_35__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self)); + __Pyx_RefNannySetupContext("itervalues (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_21itervalues(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_35__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self) { - int __pyx_v_use_setstate; - PyObject *__pyx_v_state = NULL; - PyObject *__pyx_v__dict = NULL; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_21itervalues(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_25_itervalues *__pyx_cur_scope; PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); - - /* "(tree fragment)":3 - * def __reduce_cython__(self): - * cdef bint use_setstate - * state = (self.record,) # <<<<<<<<<<<<<< - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_self->record)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->record)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->record)); - __pyx_v_state = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "(tree fragment)":4 - * cdef bint use_setstate - * state = (self.record,) - * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< - * if _dict is not None: - * state += (_dict,) - */ - __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v__dict = __pyx_t_1; - __pyx_t_1 = 0; - - /* "(tree fragment)":5 - * state = (self.record,) - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: # <<<<<<<<<<<<<< - * state += (_dict,) - * use_setstate = True - */ - __pyx_t_2 = (__pyx_v__dict != Py_None); - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { - - /* "(tree fragment)":6 - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: - * state += (_dict,) # <<<<<<<<<<<<<< - * use_setstate = True - * else: - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v__dict); - __Pyx_GIVEREF(__pyx_v__dict); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); - __pyx_t_4 = 0; - - /* "(tree fragment)":7 - * if _dict is not None: - * state += (_dict,) - * use_setstate = True # <<<<<<<<<<<<<< - * else: - * use_setstate = self.record is not None - */ - __pyx_v_use_setstate = 1; - - /* "(tree fragment)":5 - * state = (self.record,) - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: # <<<<<<<<<<<<<< - * state += (_dict,) - * use_setstate = True - */ - goto __pyx_L3; + __Pyx_RefNannySetupContext("itervalues", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_25_itervalues *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_25_itervalues(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_25_itervalues, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_25_itervalues *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 2446, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); } - - /* "(tree fragment)":9 - * use_setstate = True - * else: - * use_setstate = self.record is not None # <<<<<<<<<<<<<< - * if use_setstate: - * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, None), state - */ - /*else*/ { - __pyx_t_3 = (((PyObject *)__pyx_v_self->record) != Py_None); - __pyx_v_use_setstate = __pyx_t_3; + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_23generator15, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantRecordFormat_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2446, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; } - __pyx_L3:; - /* "(tree fragment)":10 - * else: - * use_setstate = self.record is not None - * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, None), state - * else: - */ - __pyx_t_3 = (__pyx_v_use_setstate != 0); - if (__pyx_t_3) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "(tree fragment)":11 - * use_setstate = self.record is not None - * if use_setstate: - * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, None), state # <<<<<<<<<<<<<< - * else: - * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, state) +static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_23generator15(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_25_itervalues *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_25_itervalues *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("itervalues", 0); + __Pyx_TraceCall("itervalues", __pyx_f[0], 2446, 0, __PYX_ERR(0, 2446, __pyx_L1_error)); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2446, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2448 + * def itervalues(self): + * """D.itervalues() -> an iterator over the values of D""" + * for key in self: # <<<<<<<<<<<<<< + * yield self[key] + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordFilt); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + if (likely(PyList_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) { + __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2448, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_INCREF(__pyx_int_232881935); - __Pyx_GIVEREF(__pyx_int_232881935); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_232881935); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2448, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_3)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2448, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2448, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2448, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); - __Pyx_INCREF(__pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); __pyx_t_4 = 0; - __pyx_t_1 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; - - /* "(tree fragment)":10 - * else: - * use_setstate = self.record is not None - * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, None), state - * else: - */ - } - /* "(tree fragment)":13 - * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, None), state - * else: - * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, state) # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_VariantRecordFilter__set_state(self, __pyx_state) + /* "pysam/libcbcf.pyx":2449 + * """D.itervalues() -> an iterator over the values of D""" + * for key in self: + * yield self[key] # <<<<<<<<<<<<<< + * + * def iteritems(self): */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordFilt); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_INCREF(__pyx_int_232881935); - __Pyx_GIVEREF(__pyx_int_232881935); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_232881935); - __Pyx_INCREF(__pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2449, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); - __pyx_t_5 = 0; - __pyx_t_1 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; - goto __pyx_L0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2449, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2448 + * def itervalues(self): + * """D.itervalues() -> an iterator over the values of D""" + * for key in self: # <<<<<<<<<<<<<< + * yield self[key] + * + */ } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * cdef bint use_setstate - * state = (self.record,) + /* "pysam/libcbcf.pyx":2446 + * return iter(self) + * + * def itervalues(self): # <<<<<<<<<<<<<< + * """D.itervalues() -> an iterator over the values of D""" + * for key in self: */ /* function exit code */ + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_state); - __Pyx_XDECREF(__pyx_v__dict); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_26generator16(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "(tree fragment)":14 - * else: - * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, state) - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_VariantRecordFilter__set_state(self, __pyx_state) +/* "pysam/libcbcf.pyx":2451 + * yield self[key] + * + * def iteritems(self): # <<<<<<<<<<<<<< + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_38__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_37__setstate_cython__[] = "VariantRecordFilter.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_38__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_25iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_24iteritems[] = "VariantRecordFormat.iteritems(self)\nD.iteritems() -> an iterator over the (key, value) items of D"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_25iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_37__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __Pyx_RefNannySetupContext("iteritems (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_24iteritems(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFilter_37__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_24iteritems(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_26_iteritems *__pyx_cur_scope; PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); - - /* "(tree fragment)":15 - * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, state) - * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_VariantRecordFilter__set_state(self, __pyx_state) # <<<<<<<<<<<<<< - */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFilter__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "(tree fragment)":14 - * else: - * return __pyx_unpickle_VariantRecordFilter, (type(self), 0xde17f0f, state) - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_VariantRecordFilter__set_state(self, __pyx_state) - */ + __Pyx_RefNannySetupContext("iteritems", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_26_iteritems *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_26_iteritems(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_26_iteritems, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_26_iteritems *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 2451, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_26generator16, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantRecordFormat_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2451, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFilter.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; - __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2109 - * - * - * cdef VariantRecordFilter makeVariantRecordFilter(VariantRecord record): # <<<<<<<<<<<<<< - * if not record: - * raise ValueError('invalid VariantRecord') - */ - -static struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_f_5pysam_7libcbcf_makeVariantRecordFilter(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record) { - struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_v_filter = 0; - struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *__pyx_r = NULL; +static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_26generator16(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_26_iteritems *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_26_iteritems *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("makeVariantRecordFilter", 0); - __Pyx_TraceCall("makeVariantRecordFilter", __pyx_f[0], 2109, 0, __PYX_ERR(0, 2109, __pyx_L1_error)); - - /* "pysam/libcbcf.pyx":2110 - * - * cdef VariantRecordFilter makeVariantRecordFilter(VariantRecord record): - * if not record: # <<<<<<<<<<<<<< - * raise ValueError('invalid VariantRecord') - * - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_record)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2110, __pyx_L1_error) - __pyx_t_2 = ((!__pyx_t_1) != 0); - if (unlikely(__pyx_t_2)) { - - /* "pysam/libcbcf.pyx":2111 - * cdef VariantRecordFilter makeVariantRecordFilter(VariantRecord record): - * if not record: - * raise ValueError('invalid VariantRecord') # <<<<<<<<<<<<<< - * - * cdef VariantRecordFilter filter = VariantRecordFilter.__new__(VariantRecordFilter) - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__113, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2111, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2111, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":2110 - * - * cdef VariantRecordFilter makeVariantRecordFilter(VariantRecord record): - * if not record: # <<<<<<<<<<<<<< - * raise ValueError('invalid VariantRecord') - * - */ + __Pyx_RefNannySetupContext("iteritems", 0); + __Pyx_TraceCall("iteritems", __pyx_f[0], 2451, 0, __PYX_ERR(0, 2451, __pyx_L1_error)); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return NULL; } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2451, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2113 - * raise ValueError('invalid VariantRecord') - * - * cdef VariantRecordFilter filter = VariantRecordFilter.__new__(VariantRecordFilter) # <<<<<<<<<<<<<< - * filter.record = record + /* "pysam/libcbcf.pyx":2453 + * def iteritems(self): + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: # <<<<<<<<<<<<<< + * yield (key, self[key]) * */ - __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantRecordFilter(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordFilter), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2113, __pyx_L1_error) - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_v_filter = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_t_3); - __pyx_t_3 = 0; + if (likely(PyList_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) { + __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2453, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_3)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2453, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2453, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2453, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2114 - * - * cdef VariantRecordFilter filter = VariantRecordFilter.__new__(VariantRecordFilter) - * filter.record = record # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2454 + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: + * yield (key, self[key]) # <<<<<<<<<<<<<< * - * return filter + * def keys(self): */ - __Pyx_INCREF(((PyObject *)__pyx_v_record)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_record)); - __Pyx_GOTREF(__pyx_v_filter->record); - __Pyx_DECREF(((PyObject *)__pyx_v_filter->record)); - __pyx_v_filter->record = __pyx_v_record; + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2454, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2454, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2454, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2116 - * filter.record = record - * - * return filter # <<<<<<<<<<<<<< - * + /* "pysam/libcbcf.pyx":2453 + * def iteritems(self): + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: # <<<<<<<<<<<<<< + * yield (key, self[key]) * */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_filter)); - __pyx_r = __pyx_v_filter; - goto __pyx_L0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2109 - * + /* "pysam/libcbcf.pyx":2451 + * yield self[key] * - * cdef VariantRecordFilter makeVariantRecordFilter(VariantRecord record): # <<<<<<<<<<<<<< - * if not record: - * raise ValueError('invalid VariantRecord') + * def iteritems(self): # <<<<<<<<<<<<<< + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: */ /* function exit code */ + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.makeVariantRecordFilter", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_filter); - __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2122 - * """Format data present for each sample in a :class:`VariantRecord` object, - * presented as mapping from format name to :class:`VariantMetadata` object.""" - * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< - * raise TypeError('this class cannot be instantiated from Python') +/* "pysam/libcbcf.pyx":2456 + * yield (key, self[key]) * + * def keys(self): # <<<<<<<<<<<<<< + * """D.keys() -> list of D's keys""" + * return list(self) */ /* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - CYTHON_UNUSED PyObject *__pyx_v_args = 0; - CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0; - int __pyx_r; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_28keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_27keys[] = "VariantRecordFormat.keys(self)\nD.keys() -> list of D's keys"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_28keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1; - __Pyx_INCREF(__pyx_args); - __pyx_v_args = __pyx_args; - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat___init__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); + __Pyx_RefNannySetupContext("keys (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_27keys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); /* function exit code */ - __Pyx_XDECREF(__pyx_v_args); - __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_27keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 2122, 0, __PYX_ERR(0, 2122, __pyx_L1_error)); + __Pyx_RefNannySetupContext("keys", 0); + __Pyx_TraceCall("keys", __pyx_f[0], 2456, 0, __PYX_ERR(0, 2456, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2123 - * presented as mapping from format name to :class:`VariantMetadata` object.""" - * def __init__(self, *args, **kwargs): - * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2458 + * def keys(self): + * """D.keys() -> list of D's keys""" + * return list(self) # <<<<<<<<<<<<<< * - * def __len__(self): + * def items(self): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__114, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2123, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2458, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 2123, __pyx_L1_error) + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":2122 - * """Format data present for each sample in a :class:`VariantRecord` object, - * presented as mapping from format name to :class:`VariantMetadata` object.""" - * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< - * raise TypeError('this class cannot be instantiated from Python') + /* "pysam/libcbcf.pyx":2456 + * yield (key, self[key]) * + * def keys(self): # <<<<<<<<<<<<<< + * """D.keys() -> list of D's keys""" + * return list(self) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2125 - * raise TypeError('this class cannot be instantiated from Python') +/* "pysam/libcbcf.pyx":2460 + * return list(self) * - * def __len__(self): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr + * def items(self): # <<<<<<<<<<<<<< + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) */ /* Python wrapper */ -static Py_ssize_t __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_3__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_3__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_30items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_29items[] = "VariantRecordFormat.items(self)\nD.items() -> list of D's (key, value) pairs, as 2-tuples"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_30items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_2__len__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); + __Pyx_RefNannySetupContext("items (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_29items(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_2__len__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { - CYTHON_UNUSED bcf_hdr_t *__pyx_v_hdr; - bcf1_t *__pyx_v_r; - int __pyx_v_i; - int __pyx_v_n; - Py_ssize_t __pyx_r; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_29items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bcf_hdr_t *__pyx_t_1; - bcf1_t *__pyx_t_2; - uint32_t __pyx_t_3; - uint32_t __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[0], 2125, 0, __PYX_ERR(0, 2125, __pyx_L1_error)); - - /* "pysam/libcbcf.pyx":2126 - * - * def __len__(self): - * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< - * cdef bcf1_t *r = self.record.ptr - * cdef int i, n = 0 - */ - __pyx_t_1 = __pyx_v_self->record->header->ptr; - __pyx_v_hdr = __pyx_t_1; - - /* "pysam/libcbcf.pyx":2127 - * def __len__(self): - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef int i, n = 0 - * - */ - __pyx_t_2 = __pyx_v_self->record->ptr; - __pyx_v_r = __pyx_t_2; - - /* "pysam/libcbcf.pyx":2128 - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr - * cdef int i, n = 0 # <<<<<<<<<<<<<< - * - * for i in range(r.n_fmt): - */ - __pyx_v_n = 0; - - /* "pysam/libcbcf.pyx":2130 - * cdef int i, n = 0 - * - * for i in range(r.n_fmt): # <<<<<<<<<<<<<< - * if r.d.fmt[i].p: - * n += 1 - */ - __pyx_t_3 = __pyx_v_r->n_fmt; - __pyx_t_4 = __pyx_t_3; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_i = __pyx_t_5; - - /* "pysam/libcbcf.pyx":2131 - * - * for i in range(r.n_fmt): - * if r.d.fmt[i].p: # <<<<<<<<<<<<<< - * n += 1 - * return n - */ - __pyx_t_6 = ((__pyx_v_r->d.fmt[__pyx_v_i]).p != 0); - if (__pyx_t_6) { - - /* "pysam/libcbcf.pyx":2132 - * for i in range(r.n_fmt): - * if r.d.fmt[i].p: - * n += 1 # <<<<<<<<<<<<<< - * return n - * - */ - __pyx_v_n = (__pyx_v_n + 1); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("items", 0); + __Pyx_TraceCall("items", __pyx_f[0], 2460, 0, __PYX_ERR(0, 2460, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2131 + /* "pysam/libcbcf.pyx":2462 + * def items(self): + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) # <<<<<<<<<<<<<< * - * for i in range(r.n_fmt): - * if r.d.fmt[i].p: # <<<<<<<<<<<<<< - * n += 1 - * return n + * def values(self): */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2462, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); } } - - /* "pysam/libcbcf.pyx":2133 - * if r.d.fmt[i].p: - * n += 1 - * return n # <<<<<<<<<<<<<< - * - * def __bool__(self): - */ - __pyx_r = __pyx_v_n; + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2462, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2462, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2462, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2125 - * raise TypeError('this class cannot be instantiated from Python') + /* "pysam/libcbcf.pyx":2460 + * return list(self) * - * def __len__(self): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr + * def items(self): # <<<<<<<<<<<<<< + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) */ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.items", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2135 - * return n +/* "pysam/libcbcf.pyx":2464 + * return list(self.iteritems()) * - * def __bool__(self): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr + * def values(self): # <<<<<<<<<<<<<< + * """D.values() -> list of D's values""" + * return list(self.itervalues()) */ /* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_5__bool__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_5__bool__(PyObject *__pyx_v_self) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_32values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_31values[] = "VariantRecordFormat.values(self)\nD.values() -> list of D's values"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_32values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__bool__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_4__bool__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); + __Pyx_RefNannySetupContext("values (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_31values(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_4__bool__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { - CYTHON_UNUSED bcf_hdr_t *__pyx_v_hdr; - bcf1_t *__pyx_v_r; - int __pyx_v_i; - int __pyx_r; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_31values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bcf_hdr_t *__pyx_t_1; - bcf1_t *__pyx_t_2; - uint32_t __pyx_t_3; - uint32_t __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 2135, 0, __PYX_ERR(0, 2135, __pyx_L1_error)); - - /* "pysam/libcbcf.pyx":2136 - * - * def __bool__(self): - * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< - * cdef bcf1_t *r = self.record.ptr - * cdef int i - */ - __pyx_t_1 = __pyx_v_self->record->header->ptr; - __pyx_v_hdr = __pyx_t_1; - - /* "pysam/libcbcf.pyx":2137 - * def __bool__(self): - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef int i - * - */ - __pyx_t_2 = __pyx_v_self->record->ptr; - __pyx_v_r = __pyx_t_2; - - /* "pysam/libcbcf.pyx":2140 - * cdef int i - * - * for i in range(r.n_fmt): # <<<<<<<<<<<<<< - * if r.d.fmt[i].p: - * return True - */ - __pyx_t_3 = __pyx_v_r->n_fmt; - __pyx_t_4 = __pyx_t_3; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_v_i = __pyx_t_5; - - /* "pysam/libcbcf.pyx":2141 - * - * for i in range(r.n_fmt): - * if r.d.fmt[i].p: # <<<<<<<<<<<<<< - * return True - * return False - */ - __pyx_t_6 = ((__pyx_v_r->d.fmt[__pyx_v_i]).p != 0); - if (__pyx_t_6) { - - /* "pysam/libcbcf.pyx":2142 - * for i in range(r.n_fmt): - * if r.d.fmt[i].p: - * return True # <<<<<<<<<<<<<< - * return False - * - */ - __pyx_r = 1; - goto __pyx_L0; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("values", 0); + __Pyx_TraceCall("values", __pyx_f[0], 2464, 0, __PYX_ERR(0, 2464, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2141 + /* "pysam/libcbcf.pyx":2466 + * def values(self): + * """D.values() -> list of D's values""" + * return list(self.itervalues()) # <<<<<<<<<<<<<< * - * for i in range(r.n_fmt): - * if r.d.fmt[i].p: # <<<<<<<<<<<<<< - * return True - * return False + * # Mappings are not hashable by default, but subclasses can change this */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2466, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); } } - - /* "pysam/libcbcf.pyx":2143 - * if r.d.fmt[i].p: - * return True - * return False # <<<<<<<<<<<<<< - * - * def __getitem__(self, key): - */ - __pyx_r = 0; + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2466, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2466, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2466, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2135 - * return n + /* "pysam/libcbcf.pyx":2464 + * return list(self.iteritems()) * - * def __bool__(self): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr + * def values(self): # <<<<<<<<<<<<<< + * """D.values() -> list of D's values""" + * return list(self.itervalues()) */ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2145 - * return False - * - * def __getitem__(self, key): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef bint use_setstate + * state = (self.record,) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_34__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_33__reduce_cython__[] = "VariantRecordFormat.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_34__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_6__getitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_33__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_6__getitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, PyObject *__pyx_v_key) { - bcf_hdr_t *__pyx_v_hdr; - bcf1_t *__pyx_v_r; - PyObject *__pyx_v_bkey = NULL; - bcf_fmt_t *__pyx_v_fmt; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_33__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { + int __pyx_v_use_setstate; + PyObject *__pyx_v_state = NULL; + PyObject *__pyx_v__dict = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bcf_hdr_t *__pyx_t_1; - bcf1_t *__pyx_t_2; - PyObject *__pyx_t_3 = NULL; - char const *__pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[0], 2145, 0, __PYX_ERR(0, 2145, __pyx_L1_error)); + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2146 - * - * def __getitem__(self, key): - * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< - * cdef bcf1_t *r = self.record.ptr - * + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * cdef bint use_setstate + * state = (self.record,) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: */ - __pyx_t_1 = __pyx_v_self->record->header->ptr; - __pyx_v_hdr = __pyx_t_1; + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self->record)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->record)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->record)); + __pyx_v_state = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":4 + * cdef bint use_setstate + * state = (self.record,) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v__dict = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":5 + * state = (self.record,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_2 = (__pyx_v__dict != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":6 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2147 - * def __getitem__(self, key): - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * - * bkey = force_bytes(key) + /* "(tree fragment)":7 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self.record is not None */ - __pyx_t_2 = __pyx_v_self->record->ptr; - __pyx_v_r = __pyx_t_2; + __pyx_v_use_setstate = 1; - /* "pysam/libcbcf.pyx":2149 - * cdef bcf1_t *r = self.record.ptr - * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< - * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) - * + /* "(tree fragment)":5 + * state = (self.record,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2149, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_bkey = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + goto __pyx_L3; + } - /* "pysam/libcbcf.pyx":2150 - * - * bkey = force_bytes(key) - * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) # <<<<<<<<<<<<<< - * - * if not fmt or not fmt.p: + /* "(tree fragment)":9 + * use_setstate = True + * else: + * use_setstate = self.record is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, None), state */ - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2150, __pyx_L1_error) + /*else*/ { + __pyx_t_3 = (((PyObject *)__pyx_v_self->record) != Py_None); + __pyx_v_use_setstate = __pyx_t_3; } - __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2150, __pyx_L1_error) - __pyx_v_fmt = bcf_get_fmt(__pyx_v_hdr, __pyx_v_r, __pyx_t_4); + __pyx_L3:; - /* "pysam/libcbcf.pyx":2152 - * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) - * - * if not fmt or not fmt.p: # <<<<<<<<<<<<<< - * raise KeyError('unknown format') - * + /* "(tree fragment)":10 + * else: + * use_setstate = self.record is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, None), state + * else: */ - __pyx_t_6 = ((!(__pyx_v_fmt != 0)) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_6 = ((!(__pyx_v_fmt->p != 0)) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L4_bool_binop_done:; - if (unlikely(__pyx_t_5)) { + __pyx_t_3 = (__pyx_v_use_setstate != 0); + if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2153 - * - * if not fmt or not fmt.p: - * raise KeyError('unknown format') # <<<<<<<<<<<<<< - * - * return makeVariantMetadata(self.record.header, BCF_HL_FMT, fmt.id) + /* "(tree fragment)":11 + * use_setstate = self.record is not None + * if use_setstate: + * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, state) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__115, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2153, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2153, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordForm); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_232881935); + __Pyx_GIVEREF(__pyx_int_232881935); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_232881935); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":2152 - * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) - * - * if not fmt or not fmt.p: # <<<<<<<<<<<<<< - * raise KeyError('unknown format') - * + /* "(tree fragment)":10 + * else: + * use_setstate = self.record is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, None), state + * else: */ } - /* "pysam/libcbcf.pyx":2155 - * raise KeyError('unknown format') - * - * return makeVariantMetadata(self.record.header, BCF_HL_FMT, fmt.id) # <<<<<<<<<<<<<< - * - * def __delitem__(self, key): + /* "(tree fragment)":13 + * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, None), state + * else: + * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_VariantRecordFormat__set_state(self, __pyx_state) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = ((PyObject *)__pyx_v_self->record->header); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_7 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantMetadata(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_3), BCF_HL_FMT, __pyx_v_fmt->id)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_7; - __pyx_t_7 = 0; - goto __pyx_L0; + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordForm); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_232881935); + __Pyx_GIVEREF(__pyx_int_232881935); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_232881935); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __pyx_t_5 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + } - /* "pysam/libcbcf.pyx":2145 - * return False - * - * def __getitem__(self, key): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef bint use_setstate + * state = (self.record,) */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_bkey); + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2157 - * return makeVariantMetadata(self.record.header, BCF_HL_FMT, fmt.id) - * - * def __delitem__(self, key): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr +/* "(tree fragment)":14 + * else: + * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_VariantRecordFormat__set_state(self, __pyx_state) */ /* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_9__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_9__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_36__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_35__setstate_cython__[] = "VariantRecordFormat.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_36__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__delitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_8__delitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_35__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_8__delitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, PyObject *__pyx_v_key) { - bcf_hdr_t *__pyx_v_hdr; - bcf1_t *__pyx_v_r; - PyObject *__pyx_v_bkey = NULL; - bcf_fmt_t *__pyx_v_fmt; - int __pyx_r; +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_35__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bcf_hdr_t *__pyx_t_1; - bcf1_t *__pyx_t_2; - PyObject *__pyx_t_3 = NULL; - char const *__pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - char const *__pyx_t_7; - __Pyx_RefNannySetupContext("__delitem__", 0); - __Pyx_TraceCall("__delitem__", __pyx_f[0], 2157, 0, __PYX_ERR(0, 2157, __pyx_L1_error)); + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 14, 0, __PYX_ERR(2, 14, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2158 - * - * def __delitem__(self, key): - * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< - * cdef bcf1_t *r = self.record.ptr - * + /* "(tree fragment)":15 + * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_VariantRecordFormat__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - __pyx_t_1 = __pyx_v_self->record->header->ptr; - __pyx_v_hdr = __pyx_t_1; + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFormat__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":2159 - * def __delitem__(self, key): - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * - * bkey = force_bytes(key) + /* "(tree fragment)":14 + * else: + * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_VariantRecordFormat__set_state(self, __pyx_state) */ - __pyx_t_2 = __pyx_v_self->record->ptr; - __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2161 - * cdef bcf1_t *r = self.record.ptr - * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< - * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) - * - */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2161, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_bkey = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libcbcf.pyx":2162 +/* "pysam/libcbcf.pyx":2474 * - * bkey = force_bytes(key) - * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) # <<<<<<<<<<<<<< * - * if not fmt or not fmt.p: + * cdef VariantRecordFormat makeVariantRecordFormat(VariantRecord record): # <<<<<<<<<<<<<< + * if not record: + * raise ValueError('invalid VariantRecord') */ - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2162, __pyx_L1_error) - } - __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2162, __pyx_L1_error) - __pyx_v_fmt = bcf_get_fmt(__pyx_v_hdr, __pyx_v_r, __pyx_t_4); - /* "pysam/libcbcf.pyx":2164 - * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) +static struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_f_5pysam_7libcbcf_makeVariantRecordFormat(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record) { + struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_format = 0; + struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("makeVariantRecordFormat", 0); + __Pyx_TraceCall("makeVariantRecordFormat", __pyx_f[0], 2474, 0, __PYX_ERR(0, 2474, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2475 * - * if not fmt or not fmt.p: # <<<<<<<<<<<<<< - * raise KeyError('unknown format') + * cdef VariantRecordFormat makeVariantRecordFormat(VariantRecord record): + * if not record: # <<<<<<<<<<<<<< + * raise ValueError('invalid VariantRecord') * */ - __pyx_t_6 = ((!(__pyx_v_fmt != 0)) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_6 = ((!(__pyx_v_fmt->p != 0)) != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L4_bool_binop_done:; - if (unlikely(__pyx_t_5)) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_record)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2475, __pyx_L1_error) + __pyx_t_2 = ((!__pyx_t_1) != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2165 - * - * if not fmt or not fmt.p: - * raise KeyError('unknown format') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2476 + * cdef VariantRecordFormat makeVariantRecordFormat(VariantRecord record): + * if not record: + * raise ValueError('invalid VariantRecord') # <<<<<<<<<<<<<< * - * if bcf_update_format(hdr, r, bkey, fmt.p, 0, fmt.type) < 0: + * cdef VariantRecordFormat format = VariantRecordFormat.__new__(VariantRecordFormat) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__116, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2165, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__112, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2476, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2165, __pyx_L1_error) + __PYX_ERR(0, 2476, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2164 - * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) + /* "pysam/libcbcf.pyx":2475 * - * if not fmt or not fmt.p: # <<<<<<<<<<<<<< - * raise KeyError('unknown format') + * cdef VariantRecordFormat makeVariantRecordFormat(VariantRecord record): + * if not record: # <<<<<<<<<<<<<< + * raise ValueError('invalid VariantRecord') * */ } - /* "pysam/libcbcf.pyx":2167 - * raise KeyError('unknown format') + /* "pysam/libcbcf.pyx":2478 + * raise ValueError('invalid VariantRecord') * - * if bcf_update_format(hdr, r, bkey, fmt.p, 0, fmt.type) < 0: # <<<<<<<<<<<<<< - * raise ValueError('Unable to delete FORMAT') + * cdef VariantRecordFormat format = VariantRecordFormat.__new__(VariantRecordFormat) # <<<<<<<<<<<<<< + * format.record = record * */ - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2167, __pyx_L1_error) - } - __pyx_t_7 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 2167, __pyx_L1_error) - __pyx_t_5 = ((bcf_update_format(__pyx_v_hdr, __pyx_v_r, __pyx_t_7, __pyx_v_fmt->p, 0, __pyx_v_fmt->type) < 0) != 0); - if (unlikely(__pyx_t_5)) { + __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantRecordFormat(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordFormat), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2478, __pyx_L1_error) + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_v_format = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2168 + /* "pysam/libcbcf.pyx":2479 * - * if bcf_update_format(hdr, r, bkey, fmt.p, 0, fmt.type) < 0: - * raise ValueError('Unable to delete FORMAT') # <<<<<<<<<<<<<< + * cdef VariantRecordFormat format = VariantRecordFormat.__new__(VariantRecordFormat) + * format.record = record # <<<<<<<<<<<<<< * - * def clear(self): + * return format */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__117, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2168, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2168, __pyx_L1_error) + __Pyx_INCREF(((PyObject *)__pyx_v_record)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_record)); + __Pyx_GOTREF(__pyx_v_format->record); + __Pyx_DECREF(((PyObject *)__pyx_v_format->record)); + __pyx_v_format->record = __pyx_v_record; - /* "pysam/libcbcf.pyx":2167 - * raise KeyError('unknown format') + /* "pysam/libcbcf.pyx":2481 + * format.record = record + * + * return format # <<<<<<<<<<<<<< * - * if bcf_update_format(hdr, r, bkey, fmt.p, 0, fmt.type) < 0: # <<<<<<<<<<<<<< - * raise ValueError('Unable to delete FORMAT') * */ - } + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_format)); + __pyx_r = __pyx_v_format; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":2157 - * return makeVariantMetadata(self.record.header, BCF_HL_FMT, fmt.id) + /* "pysam/libcbcf.pyx":2474 * - * def __delitem__(self, key): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr + * + * cdef VariantRecordFormat makeVariantRecordFormat(VariantRecord record): # <<<<<<<<<<<<<< + * if not record: + * raise ValueError('invalid VariantRecord') */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__delitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("pysam.libcbcf.makeVariantRecordFormat", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_bkey); - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF((PyObject *)__pyx_v_format); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2170 - * raise ValueError('Unable to delete FORMAT') +/* "pysam/libcbcf.pyx":2489 + * mapping from info metadata name to value.""" + * + * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< + * raise TypeError('this class cannot be instantiated from Python') * - * def clear(self): # <<<<<<<<<<<<<< - * """Clear all formats for all samples within the associated - * :class:`VariantRecord` instance""" */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_10clear[] = "VariantRecordFormat.clear(self)\nClear all formats for all samples within the associated\n :class:`VariantRecord` instance"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + CYTHON_UNUSED PyObject *__pyx_v_args = 0; + CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("clear (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_10clear(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1; + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo___init__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_10clear(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { - bcf_hdr_t *__pyx_v_hdr; - bcf1_t *__pyx_v_r; - bcf_fmt_t *__pyx_v_fmt; - char const *__pyx_v_key; - int __pyx_v_i; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - bcf_hdr_t *__pyx_t_1; - bcf1_t *__pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("clear", 0); - __Pyx_TraceCall("clear", __pyx_f[0], 2170, 0, __PYX_ERR(0, 2170, __pyx_L1_error)); - - /* "pysam/libcbcf.pyx":2173 - * """Clear all formats for all samples within the associated - * :class:`VariantRecord` instance""" - * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< - * cdef bcf1_t *r = self.record.ptr - * cdef bcf_fmt_t *fmt - */ - __pyx_t_1 = __pyx_v_self->record->header->ptr; - __pyx_v_hdr = __pyx_t_1; - - /* "pysam/libcbcf.pyx":2174 - * :class:`VariantRecord` instance""" - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef bcf_fmt_t *fmt - * cdef const char *key - */ - __pyx_t_2 = __pyx_v_self->record->ptr; - __pyx_v_r = __pyx_t_2; - - /* "pysam/libcbcf.pyx":2179 - * cdef int i - * - * for i in reversed(range(r.n_fmt)): # <<<<<<<<<<<<<< - * fmt = &r.d.fmt[i] - * if fmt.p: - */ - for (__pyx_t_3 = __pyx_v_r->n_fmt-1; __pyx_t_3 >= 0; __pyx_t_3-=1) { - __pyx_v_i = __pyx_t_3; - - /* "pysam/libcbcf.pyx":2180 - * - * for i in reversed(range(r.n_fmt)): - * fmt = &r.d.fmt[i] # <<<<<<<<<<<<<< - * if fmt.p: - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) - */ - __pyx_v_fmt = (&(__pyx_v_r->d.fmt[__pyx_v_i])); - - /* "pysam/libcbcf.pyx":2181 - * for i in reversed(range(r.n_fmt)): - * fmt = &r.d.fmt[i] - * if fmt.p: # <<<<<<<<<<<<<< - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) - * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: - */ - __pyx_t_4 = (__pyx_v_fmt->p != 0); - if (__pyx_t_4) { - - /* "pysam/libcbcf.pyx":2182 - * fmt = &r.d.fmt[i] - * if fmt.p: - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) # <<<<<<<<<<<<<< - * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: - * raise ValueError('Unable to delete FORMAT') - */ - __pyx_v_key = bcf_hdr_int2id(__pyx_v_hdr, BCF_DT_ID, __pyx_v_fmt->id); - - /* "pysam/libcbcf.pyx":2183 - * if fmt.p: - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) - * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: # <<<<<<<<<<<<<< - * raise ValueError('Unable to delete FORMAT') - * - */ - __pyx_t_4 = ((bcf_update_format(__pyx_v_hdr, __pyx_v_r, __pyx_v_key, __pyx_v_fmt->p, 0, __pyx_v_fmt->type) < 0) != 0); - if (unlikely(__pyx_t_4)) { + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__init__", 0); + __Pyx_TraceCall("__init__", __pyx_f[0], 2489, 0, __PYX_ERR(0, 2489, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2184 - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) - * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: - * raise ValueError('Unable to delete FORMAT') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2490 * - * def __iter__(self): - */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__118, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2184, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 2184, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":2183 - * if fmt.p: - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) - * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: # <<<<<<<<<<<<<< - * raise ValueError('Unable to delete FORMAT') + * def __init__(self, *args, **kwargs): + * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * + * def __len__(self): */ - } - - /* "pysam/libcbcf.pyx":2181 - * for i in reversed(range(r.n_fmt)): - * fmt = &r.d.fmt[i] - * if fmt.p: # <<<<<<<<<<<<<< - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) - * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: - */ - } - } + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__113, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2490, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2490, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2170 - * raise ValueError('Unable to delete FORMAT') + /* "pysam/libcbcf.pyx":2489 + * mapping from info metadata name to value.""" + * + * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< + * raise TypeError('this class cannot be instantiated from Python') * - * def clear(self): # <<<<<<<<<<<<<< - * """Clear all formats for all samples within the associated - * :class:`VariantRecord` instance""" */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.clear", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_14generator14(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":2186 - * raise ValueError('Unable to delete FORMAT') +/* "pysam/libcbcf.pyx":2492 + * raise TypeError('this class cannot be instantiated from Python') * - * def __iter__(self): # <<<<<<<<<<<<<< + * def __len__(self): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_13__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_13__iter__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_12__iter__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_12__iter__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_24___iter__ *__pyx_cur_scope; - PyObject *__pyx_r = NULL; +static Py_ssize_t __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_3__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_3__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_24___iter__ *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_24___iter__(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_24___iter__, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_24___iter__ *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2186, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_14generator14, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantRecordFormat___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2186, __pyx_L1_error) - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_2__len__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_14generator14(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_24___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_24___iter__ *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; +static Py_ssize_t __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_2__len__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { + bcf_hdr_t *__pyx_v_hdr; + bcf1_t *__pyx_v_r; + bcf_info_t *__pyx_v_info; + char const *__pyx_v_key; + int __pyx_v_i; + int __pyx_v_count; + Py_ssize_t __pyx_r; __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; bcf1_t *__pyx_t_2; - uint32_t __pyx_t_3; - uint32_t __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 2186, 0, __PYX_ERR(0, 2186, __pyx_L1_error)); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L7_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return NULL; - } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2186, __pyx_L1_error) + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + uint32_t __pyx_t_5; + uint32_t __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + __Pyx_RefNannySetupContext("__len__", 0); + __Pyx_TraceCall("__len__", __pyx_f[0], 2492, 0, __PYX_ERR(0, 2492, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2187 + /* "pysam/libcbcf.pyx":2493 * - * def __iter__(self): + * def __len__(self): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr - * cdef bcf_fmt_t *fmt + * cdef bcf_info_t *info */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; - __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2188 - * def __iter__(self): + /* "pysam/libcbcf.pyx":2494 + * def __len__(self): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef bcf_fmt_t *fmt - * cdef int i + * cdef bcf_info_t *info + * cdef const char *key */ - __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; - __pyx_cur_scope->__pyx_v_r = __pyx_t_2; + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2192 - * cdef int i + /* "pysam/libcbcf.pyx":2497 + * cdef bcf_info_t *info + * cdef const char *key + * cdef int i, count = 0 # <<<<<<<<<<<<<< * - * for i in range(r.n_fmt): # <<<<<<<<<<<<<< - * fmt = &r.d.fmt[i] - * if fmt.p: + * if bcf_unpack(r, BCF_UN_INFO) < 0: */ - __pyx_t_3 = __pyx_cur_scope->__pyx_v_r->n_fmt; - __pyx_t_4 = __pyx_t_3; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_5; + __pyx_v_count = 0; - /* "pysam/libcbcf.pyx":2193 + /* "pysam/libcbcf.pyx":2499 + * cdef int i, count = 0 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') * - * for i in range(r.n_fmt): - * fmt = &r.d.fmt[i] # <<<<<<<<<<<<<< - * if fmt.p: - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) */ - __pyx_cur_scope->__pyx_v_fmt = (&(__pyx_cur_scope->__pyx_v_r->d.fmt[__pyx_cur_scope->__pyx_v_i])); + __pyx_t_3 = ((bcf_unpack(__pyx_v_r, BCF_UN_INFO) < 0) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2194 - * for i in range(r.n_fmt): - * fmt = &r.d.fmt[i] - * if fmt.p: # <<<<<<<<<<<<<< - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) + /* "pysam/libcbcf.pyx":2500 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * + * for i in range(r.n_info): */ - __pyx_t_6 = (__pyx_cur_scope->__pyx_v_fmt->p != 0); - if (__pyx_t_6) { + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__114, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2500, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2500, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2195 - * fmt = &r.d.fmt[i] - * if fmt.p: - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2499 + * cdef int i, count = 0 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') * - * def get(self, key, default=None): */ - __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_int2id(__pyx_cur_scope->__pyx_v_hdr, BCF_DT_ID, __pyx_cur_scope->__pyx_v_fmt->id)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2195, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_r = __pyx_t_7; - __pyx_t_7 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L7_resume_from_yield:; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2195, __pyx_L1_error) + } - /* "pysam/libcbcf.pyx":2194 - * for i in range(r.n_fmt): - * fmt = &r.d.fmt[i] - * if fmt.p: # <<<<<<<<<<<<<< - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) + /* "pysam/libcbcf.pyx":2502 + * raise ValueError('Error unpacking VariantRecord') + * + * for i in range(r.n_info): # <<<<<<<<<<<<<< + * info = &r.d.info[i] + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + */ + __pyx_t_5 = __pyx_v_r->n_info; + __pyx_t_6 = __pyx_t_5; + for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { + __pyx_v_i = __pyx_t_7; + + /* "pysam/libcbcf.pyx":2503 + * + * for i in range(r.n_info): + * info = &r.d.info[i] # <<<<<<<<<<<<<< + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if info != NULL and info.vptr != NULL and strcmp(key, b'END') != 0: + */ + __pyx_v_info = (&(__pyx_v_r->d.info[__pyx_v_i])); + + /* "pysam/libcbcf.pyx":2504 + * for i in range(r.n_info): + * info = &r.d.info[i] + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) # <<<<<<<<<<<<<< + * if info != NULL and info.vptr != NULL and strcmp(key, b'END') != 0: + * count += 1 + */ + __pyx_v_key = bcf_hdr_int2id(__pyx_v_hdr, BCF_DT_ID, __pyx_v_info->key); + + /* "pysam/libcbcf.pyx":2505 + * info = &r.d.info[i] + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if info != NULL and info.vptr != NULL and strcmp(key, b'END') != 0: # <<<<<<<<<<<<<< + * count += 1 + * + */ + __pyx_t_8 = ((__pyx_v_info != NULL) != 0); + if (__pyx_t_8) { + } else { + __pyx_t_3 = __pyx_t_8; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_8 = ((__pyx_v_info->vptr != NULL) != 0); + if (__pyx_t_8) { + } else { + __pyx_t_3 = __pyx_t_8; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_8 = ((strcmp(__pyx_v_key, ((char const *)"END")) != 0) != 0); + __pyx_t_3 = __pyx_t_8; + __pyx_L7_bool_binop_done:; + if (__pyx_t_3) { + + /* "pysam/libcbcf.pyx":2506 + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if info != NULL and info.vptr != NULL and strcmp(key, b'END') != 0: + * count += 1 # <<<<<<<<<<<<<< + * + * return count + */ + __pyx_v_count = (__pyx_v_count + 1); + + /* "pysam/libcbcf.pyx":2505 + * info = &r.d.info[i] + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if info != NULL and info.vptr != NULL and strcmp(key, b'END') != 0: # <<<<<<<<<<<<<< + * count += 1 * */ } } - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2186 - * raise ValueError('Unable to delete FORMAT') + /* "pysam/libcbcf.pyx":2508 + * count += 1 * - * def __iter__(self): # <<<<<<<<<<<<<< + * return count # <<<<<<<<<<<<<< + * + * def __bool__(self): + */ + __pyx_r = __pyx_v_count; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2492 + * raise TypeError('this class cannot be instantiated from Python') + * + * def __len__(self): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2197 - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) +/* "pysam/libcbcf.pyx":2510 + * return count * - * def get(self, key, default=None): # <<<<<<<<<<<<<< - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: + * def __bool__(self): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_16get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_15get[] = "VariantRecordFormat.get(self, key, default=None)\nD.get(k[,d]) -> D[k] if k in D, else d. d defaults to None."; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_16get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_key = 0; - PyObject *__pyx_v_default = 0; - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_5__bool__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_5__bool__(PyObject *__pyx_v_self) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_default,0}; - PyObject* values[2] = {0,0}; - values[1] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_default); - if (value) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 2197, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_key = values[0]; - __pyx_v_default = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2197, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_15get(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self), __pyx_v_key, __pyx_v_default); + __Pyx_RefNannySetupContext("__bool__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_4__bool__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_15get(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_4__bool__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { + bcf_hdr_t *__pyx_v_hdr; + bcf1_t *__pyx_v_r; + bcf_info_t *__pyx_v_info; + char const *__pyx_v_key; + int __pyx_v_i; + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; + int __pyx_t_3; PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - __Pyx_RefNannySetupContext("get", 0); - __Pyx_TraceCall("get", __pyx_f[0], 2197, 0, __PYX_ERR(0, 2197, __pyx_L1_error)); + uint32_t __pyx_t_5; + uint32_t __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + __Pyx_RefNannySetupContext("__bool__", 0); + __Pyx_TraceCall("__bool__", __pyx_f[0], 2510, 0, __PYX_ERR(0, 2510, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2199 - * def get(self, key, default=None): - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: # <<<<<<<<<<<<<< - * return self[key] - * except KeyError: + /* "pysam/libcbcf.pyx":2511 + * + * def __bool__(self): + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef bcf_info_t *info */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_1); - __Pyx_XGOTREF(__pyx_t_2); - __Pyx_XGOTREF(__pyx_t_3); - /*try:*/ { + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2200 - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: - * return self[key] # <<<<<<<<<<<<<< - * except KeyError: - * return default + /* "pysam/libcbcf.pyx":2512 + * def __bool__(self): + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef bcf_info_t *info + * cdef const char *key */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2200, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L7_try_return; + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2199 - * def get(self, key, default=None): - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: # <<<<<<<<<<<<<< - * return self[key] - * except KeyError: + /* "pysam/libcbcf.pyx":2517 + * cdef int i + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') + * */ - } - __pyx_L3_error:; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = ((bcf_unpack(__pyx_v_r, BCF_UN_INFO) < 0) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2201 - * try: - * return self[key] - * except KeyError: # <<<<<<<<<<<<<< - * return default + /* "pysam/libcbcf.pyx":2518 * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * + * for i in range(r.n_info): */ - __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); - if (__pyx_t_5) { - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 2201, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__115, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2518, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2518, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2202 - * return self[key] - * except KeyError: - * return default # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2517 + * cdef int i + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') * - * def __contains__(self, key): */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_default); - __pyx_r = __pyx_v_default; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L6_except_return; + } + + /* "pysam/libcbcf.pyx":2520 + * raise ValueError('Error unpacking VariantRecord') + * + * for i in range(r.n_info): # <<<<<<<<<<<<<< + * info = &r.d.info[i] + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + */ + __pyx_t_5 = __pyx_v_r->n_info; + __pyx_t_6 = __pyx_t_5; + for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { + __pyx_v_i = __pyx_t_7; + + /* "pysam/libcbcf.pyx":2521 + * + * for i in range(r.n_info): + * info = &r.d.info[i] # <<<<<<<<<<<<<< + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if info != NULL and info.vptr != NULL and strcmp(key, b'END') != 0: + */ + __pyx_v_info = (&(__pyx_v_r->d.info[__pyx_v_i])); + + /* "pysam/libcbcf.pyx":2522 + * for i in range(r.n_info): + * info = &r.d.info[i] + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) # <<<<<<<<<<<<<< + * if info != NULL and info.vptr != NULL and strcmp(key, b'END') != 0: + * return True + */ + __pyx_v_key = bcf_hdr_int2id(__pyx_v_hdr, BCF_DT_ID, __pyx_v_info->key); + + /* "pysam/libcbcf.pyx":2523 + * info = &r.d.info[i] + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if info != NULL and info.vptr != NULL and strcmp(key, b'END') != 0: # <<<<<<<<<<<<<< + * return True + * + */ + __pyx_t_8 = ((__pyx_v_info != NULL) != 0); + if (__pyx_t_8) { + } else { + __pyx_t_3 = __pyx_t_8; + goto __pyx_L7_bool_binop_done; } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; + __pyx_t_8 = ((__pyx_v_info->vptr != NULL) != 0); + if (__pyx_t_8) { + } else { + __pyx_t_3 = __pyx_t_8; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_8 = ((strcmp(__pyx_v_key, ((char const *)"END")) != 0) != 0); + __pyx_t_3 = __pyx_t_8; + __pyx_L7_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2199 - * def get(self, key, default=None): - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: # <<<<<<<<<<<<<< - * return self[key] - * except KeyError: + /* "pysam/libcbcf.pyx":2524 + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if info != NULL and info.vptr != NULL and strcmp(key, b'END') != 0: + * return True # <<<<<<<<<<<<<< + * + * return False */ - __Pyx_XGIVEREF(__pyx_t_1); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); - goto __pyx_L1_error; - __pyx_L7_try_return:; - __Pyx_XGIVEREF(__pyx_t_1); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); - goto __pyx_L0; - __pyx_L6_except_return:; - __Pyx_XGIVEREF(__pyx_t_1); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); - goto __pyx_L0; + __pyx_r = 1; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2523 + * info = &r.d.info[i] + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if info != NULL and info.vptr != NULL and strcmp(key, b'END') != 0: # <<<<<<<<<<<<<< + * return True + * + */ + } } - /* "pysam/libcbcf.pyx":2197 - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) + /* "pysam/libcbcf.pyx":2526 + * return True + * + * return False # <<<<<<<<<<<<<< + * + * def __getitem__(self, key): + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2510 + * return count * - * def get(self, key, default=None): # <<<<<<<<<<<<<< - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: + * def __bool__(self): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2204 - * return default +/* "pysam/libcbcf.pyx":2528 + * return False * - * def __contains__(self, key): # <<<<<<<<<<<<<< + * def __getitem__(self, key): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_18__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_18__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_17__contains__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_6__getitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), ((PyObject *)__pyx_v_key)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_17__contains__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, PyObject *__pyx_v_key) { +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_6__getitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_key) { bcf_hdr_t *__pyx_v_hdr; bcf1_t *__pyx_v_r; - PyObject *__pyx_v_bkey = NULL; - bcf_fmt_t *__pyx_v_fmt; - int __pyx_r; + PyObject *__pyx_v_bkey = 0; + bcf_info_t *__pyx_v_info; + int __pyx_v_info_id; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; bcf1_t *__pyx_t_2; - PyObject *__pyx_t_3 = NULL; - char const *__pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - __Pyx_RefNannySetupContext("__contains__", 0); - __Pyx_TraceCall("__contains__", __pyx_f[0], 2204, 0, __PYX_ERR(0, 2204, __pyx_L1_error)); + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + char const *__pyx_t_5; + char const *__pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + int __pyx_t_12; + __Pyx_RefNannySetupContext("__getitem__", 0); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 2528, 0, __PYX_ERR(0, 2528, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2205 + /* "pysam/libcbcf.pyx":2529 * - * def __contains__(self, key): + * def __getitem__(self, key): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr - * bkey = force_bytes(key) + * */ __pyx_t_1 = __pyx_v_self->record->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2206 - * def __contains__(self, key): + /* "pysam/libcbcf.pyx":2530 + * def __getitem__(self, key): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * bkey = force_bytes(key) - * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: */ __pyx_t_2 = __pyx_v_self->record->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2207 - * cdef bcf_hdr_t *hdr = self.record.header.ptr + /* "pysam/libcbcf.pyx":2532 * cdef bcf1_t *r = self.record.ptr - * bkey = force_bytes(key) # <<<<<<<<<<<<<< - * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) - * return fmt != NULL and fmt.p != NULL + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') + * */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2207, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_bkey = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_3 = ((bcf_unpack(__pyx_v_r, BCF_UN_INFO) < 0) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2208 - * cdef bcf1_t *r = self.record.ptr - * bkey = force_bytes(key) - * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) # <<<<<<<<<<<<<< - * return fmt != NULL and fmt.p != NULL + /* "pysam/libcbcf.pyx":2533 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * + * cdef bytes bkey = force_bytes(key) */ - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2208, __pyx_L1_error) - } - __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2208, __pyx_L1_error) - __pyx_v_fmt = bcf_get_fmt(__pyx_v_hdr, __pyx_v_r, __pyx_t_4); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__116, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2533, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2533, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2209 - * bkey = force_bytes(key) - * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) - * return fmt != NULL and fmt.p != NULL # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2532 + * cdef bcf1_t *r = self.record.ptr + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') * - * def iterkeys(self): */ - __pyx_t_6 = (__pyx_v_fmt != NULL); - if (__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L3_bool_binop_done; } - __pyx_t_6 = (__pyx_v_fmt->p != NULL); - __pyx_t_5 = __pyx_t_6; - __pyx_L3_bool_binop_done:; - __pyx_r = __pyx_t_5; - goto __pyx_L0; - /* "pysam/libcbcf.pyx":2204 - * return default + /* "pysam/libcbcf.pyx":2535 + * raise ValueError('Error unpacking VariantRecord') * - * def __contains__(self, key): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< + * + * if strcmp(bkey, b'END') == 0: */ + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2535, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_bkey = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_bkey); - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcbcf.pyx":2211 - * return fmt != NULL and fmt.p != NULL + /* "pysam/libcbcf.pyx":2537 + * cdef bytes bkey = force_bytes(key) + * + * if strcmp(bkey, b'END') == 0: # <<<<<<<<<<<<<< + * raise KeyError('END is a reserved attribute; access is via record.stop') * - * def iterkeys(self): # <<<<<<<<<<<<<< - * """D.iterkeys() -> an iterator over the keys of D""" - * return iter(self) */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2537, __pyx_L1_error) + } + __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 2537, __pyx_L1_error) + __pyx_t_3 = ((strcmp(__pyx_t_5, ((char const *)"END")) == 0) != 0); + if (unlikely(__pyx_t_3)) { -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_20iterkeys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_19iterkeys[] = "VariantRecordFormat.iterkeys(self)\nD.iterkeys() -> an iterator over the keys of D"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_20iterkeys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("iterkeys (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_19iterkeys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); + /* "pysam/libcbcf.pyx":2538 + * + * if strcmp(bkey, b'END') == 0: + * raise KeyError('END is a reserved attribute; access is via record.stop') # <<<<<<<<<<<<<< + * + * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__117, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2538, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2538, __pyx_L1_error) - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2537 + * cdef bytes bkey = force_bytes(key) + * + * if strcmp(bkey, b'END') == 0: # <<<<<<<<<<<<<< + * raise KeyError('END is a reserved attribute; access is via record.stop') + * + */ + } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_19iterkeys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("iterkeys", 0); - __Pyx_TraceCall("iterkeys", __pyx_f[0], 2211, 0, __PYX_ERR(0, 2211, __pyx_L1_error)); + /* "pysam/libcbcf.pyx":2540 + * raise KeyError('END is a reserved attribute; access is via record.stop') + * + * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) # <<<<<<<<<<<<<< + * + * # Cannot stop here if info == NULL, since flags must return False + */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2540, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 2540, __pyx_L1_error) + __pyx_v_info = bcf_get_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_6); - /* "pysam/libcbcf.pyx":2213 - * def iterkeys(self): - * """D.iterkeys() -> an iterator over the keys of D""" - * return iter(self) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2543 * - * def itervalues(self): + * # Cannot stop here if info == NULL, since flags must return False + * cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key # <<<<<<<<<<<<<< + * + * if info_id < 0: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2213, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + if (((!(__pyx_v_info != 0)) != 0)) { + __pyx_t_8 = __pyx_f_5pysam_7libcbcf_bcf_header_get_info_id(__pyx_v_hdr, __pyx_v_bkey); if (unlikely(__pyx_t_8 == ((int)-2) && PyErr_Occurred())) __PYX_ERR(0, 2543, __pyx_L1_error) + __pyx_t_7 = __pyx_t_8; + } else { + __pyx_t_7 = __pyx_v_info->key; + } + __pyx_v_info_id = __pyx_t_7; - /* "pysam/libcbcf.pyx":2211 - * return fmt != NULL and fmt.p != NULL + /* "pysam/libcbcf.pyx":2545 + * cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key + * + * if info_id < 0: # <<<<<<<<<<<<<< + * raise KeyError('Unknown INFO field: {}'.format(key)) * - * def iterkeys(self): # <<<<<<<<<<<<<< - * """D.iterkeys() -> an iterator over the keys of D""" - * return iter(self) */ + __pyx_t_3 = ((__pyx_v_info_id < 0) != 0); + if (unlikely(__pyx_t_3)) { - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.iterkeys", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_23generator15(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ + /* "pysam/libcbcf.pyx":2546 + * + * if info_id < 0: + * raise KeyError('Unknown INFO field: {}'.format(key)) # <<<<<<<<<<<<<< + * + * if not check_header_id(hdr, BCF_HL_INFO, info_id): + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Unknown_INFO_field, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2546, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + if (!__pyx_t_10) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2546, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2546, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2546, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2546, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_key); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2546, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2546, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 2546, __pyx_L1_error) -/* "pysam/libcbcf.pyx":2215 - * return iter(self) + /* "pysam/libcbcf.pyx":2545 + * cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key + * + * if info_id < 0: # <<<<<<<<<<<<<< + * raise KeyError('Unknown INFO field: {}'.format(key)) * - * def itervalues(self): # <<<<<<<<<<<<<< - * """D.itervalues() -> an iterator over the values of D""" - * for key in self: */ + } -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_22itervalues(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_21itervalues[] = "VariantRecordFormat.itervalues(self)\nD.itervalues() -> an iterator over the values of D"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_22itervalues(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("itervalues (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_21itervalues(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); + /* "pysam/libcbcf.pyx":2548 + * raise KeyError('Unknown INFO field: {}'.format(key)) + * + * if not check_header_id(hdr, BCF_HL_INFO, info_id): # <<<<<<<<<<<<<< + * raise ValueError('Invalid header') + * + */ + __pyx_t_3 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_INFO, __pyx_v_info_id) != 0)) != 0); + if (unlikely(__pyx_t_3)) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2549 + * + * if not check_header_id(hdr, BCF_HL_INFO, info_id): + * raise ValueError('Invalid header') # <<<<<<<<<<<<<< + * + * # Handle type=Flag values + */ + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__118, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2549, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 2549, __pyx_L1_error) -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_21itervalues(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_25_itervalues *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("itervalues", 0); - __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_25_itervalues *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_25_itervalues(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_25_itervalues, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_25_itervalues *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2215, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_23generator15, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantRecordFormat_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2215, __pyx_L1_error) - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; + /* "pysam/libcbcf.pyx":2548 + * raise KeyError('Unknown INFO field: {}'.format(key)) + * + * if not check_header_id(hdr, BCF_HL_INFO, info_id): # <<<<<<<<<<<<<< + * raise ValueError('Invalid header') + * + */ } - /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2552 + * + * # Handle type=Flag values + * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG: # <<<<<<<<<<<<<< + * return info != NULL and info.vptr != NULL + * + */ + __pyx_t_3 = ((bcf_hdr_id2type(__pyx_v_hdr, BCF_HL_INFO, __pyx_v_info_id) == BCF_HT_FLAG) != 0); + if (__pyx_t_3) { -static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_23generator15(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_25_itervalues *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_25_itervalues *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *(*__pyx_t_3)(PyObject *); - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("itervalues", 0); - __Pyx_TraceCall("itervalues", __pyx_f[0], 2215, 0, __PYX_ERR(0, 2215, __pyx_L1_error)); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return NULL; + /* "pysam/libcbcf.pyx":2553 + * # Handle type=Flag values + * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG: + * return info != NULL and info.vptr != NULL # <<<<<<<<<<<<<< + * + * if not info or not info.vptr: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = (__pyx_v_info != NULL); + if (__pyx_t_3) { + } else { + __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L8_bool_binop_done; + } + __pyx_t_3 = (__pyx_v_info->vptr != NULL); + __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2553, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_L8_bool_binop_done:; + __pyx_r = __pyx_t_9; + __pyx_t_9 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2552 + * + * # Handle type=Flag values + * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG: # <<<<<<<<<<<<<< + * return info != NULL and info.vptr != NULL + * + */ } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2215, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2217 - * def itervalues(self): - * """D.itervalues() -> an iterator over the values of D""" - * for key in self: # <<<<<<<<<<<<<< - * yield self[key] + /* "pysam/libcbcf.pyx":2555 + * return info != NULL and info.vptr != NULL + * + * if not info or not info.vptr: # <<<<<<<<<<<<<< + * raise KeyError('Invalid INFO field: {}'.format(key)) * */ - if (likely(PyList_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) { - __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_3 = NULL; + __pyx_t_12 = ((!(__pyx_v_info != 0)) != 0); + if (!__pyx_t_12) { } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2217, __pyx_L1_error) + __pyx_t_3 = __pyx_t_12; + goto __pyx_L11_bool_binop_done; } - for (;;) { - if (likely(!__pyx_t_3)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2217, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2217, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2217, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif + __pyx_t_12 = ((!(__pyx_v_info->vptr != 0)) != 0); + __pyx_t_3 = __pyx_t_12; + __pyx_L11_bool_binop_done:; + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcbcf.pyx":2556 + * + * if not info or not info.vptr: + * raise KeyError('Invalid INFO field: {}'.format(key)) # <<<<<<<<<<<<<< + * + * return bcf_info_get_value(self.record, info) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_INFO_field, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); } + } + if (!__pyx_t_11) { + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_key); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 2217, __pyx_L1_error) - } - break; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_key}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2556, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_key}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2556, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + { + __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_11); __pyx_t_11 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_key); + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_10, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } - __Pyx_GOTREF(__pyx_t_4); } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2556, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2556, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2218 - * """D.itervalues() -> an iterator over the values of D""" - * for key in self: - * yield self[key] # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2555 + * return info != NULL and info.vptr != NULL + * + * if not info or not info.vptr: # <<<<<<<<<<<<<< + * raise KeyError('Invalid INFO field: {}'.format(key)) * - * def iteritems(self): */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2218, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2218, __pyx_L1_error) + } - /* "pysam/libcbcf.pyx":2217 - * def itervalues(self): - * """D.itervalues() -> an iterator over the values of D""" - * for key in self: # <<<<<<<<<<<<<< - * yield self[key] + /* "pysam/libcbcf.pyx":2558 + * raise KeyError('Invalid INFO field: {}'.format(key)) * + * return bcf_info_get_value(self.record, info) # <<<<<<<<<<<<<< + * + * def __setitem__(self, key, value): */ - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = ((PyObject *)__pyx_v_self->record); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_info_get_value(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_4), __pyx_v_info); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2558, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_9; + __pyx_t_9 = 0; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":2215 - * return iter(self) + /* "pysam/libcbcf.pyx":2528 + * return False * - * def itervalues(self): # <<<<<<<<<<<<<< - * """D.itervalues() -> an iterator over the values of D""" - * for key in self: + * def __getitem__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_XDECREF(__pyx_v_bkey); + __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_26generator16(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":2220 - * yield self[key] +/* "pysam/libcbcf.pyx":2560 + * return bcf_info_get_value(self.record, info) + * + * def __setitem__(self, key, value): # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) * - * def iteritems(self): # <<<<<<<<<<<<<< - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_25iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_24iteritems[] = "VariantRecordFormat.iteritems(self)\nD.iteritems() -> an iterator over the (key, value) items of D"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_25iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("iteritems (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_24iteritems(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_24iteritems(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_26_iteritems *__pyx_cur_scope; - PyObject *__pyx_r = NULL; +static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_9__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_9__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("iteritems", 0); - __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_26_iteritems *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_26_iteritems(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_26_iteritems, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_26_iteritems *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2220, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_26generator16, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantRecordFormat_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2220, __pyx_L1_error) - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_8__setitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_value)); /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordFormat_26generator16(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_26_iteritems *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_26_iteritems *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_8__setitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { + PyObject *__pyx_v_bkey = 0; + int __pyx_r; __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *(*__pyx_t_3)(PyObject *); + char const *__pyx_t_2; + int __pyx_t_3; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("iteritems", 0); - __Pyx_TraceCall("iteritems", __pyx_f[0], 2220, 0, __PYX_ERR(0, 2220, __pyx_L1_error)); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return NULL; + __Pyx_RefNannySetupContext("__setitem__", 0); + __Pyx_TraceCall("__setitem__", __pyx_f[0], 2560, 0, __PYX_ERR(0, 2560, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2561 + * + * def __setitem__(self, key, value): + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< + * + * if strcmp(bkey, b'END') == 0: + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_bkey = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":2563 + * cdef bytes bkey = force_bytes(key) + * + * if strcmp(bkey, b'END') == 0: # <<<<<<<<<<<<<< + * raise KeyError('END is a reserved attribute; access is via record.stop') + * + */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2563, __pyx_L1_error) } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2220, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 2563, __pyx_L1_error) + __pyx_t_3 = ((strcmp(__pyx_t_2, ((char const *)"END")) == 0) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2222 - * def iteritems(self): - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: # <<<<<<<<<<<<<< - * yield (key, self[key]) + /* "pysam/libcbcf.pyx":2564 + * + * if strcmp(bkey, b'END') == 0: + * raise KeyError('END is a reserved attribute; access is via record.stop') # <<<<<<<<<<<<<< * + * if bcf_unpack(self.record.ptr, BCF_UN_INFO) < 0: */ - if (likely(PyList_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) { - __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2222, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__119, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2564, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2222, __pyx_L1_error) + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2564, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2563 + * cdef bytes bkey = force_bytes(key) + * + * if strcmp(bkey, b'END') == 0: # <<<<<<<<<<<<<< + * raise KeyError('END is a reserved attribute; access is via record.stop') + * + */ } - for (;;) { - if (likely(!__pyx_t_3)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2222, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2222, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 2222, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2222, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 2222, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2223 - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: - * yield (key, self[key]) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2566 + * raise KeyError('END is a reserved attribute; access is via record.stop') + * + * if bcf_unpack(self.record.ptr, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') * - * def keys(self): */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2223, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2223, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_cur_scope->__pyx_v_key); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2223, __pyx_L1_error) + __pyx_t_3 = ((bcf_unpack(__pyx_v_self->record->ptr, BCF_UN_INFO) < 0) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2222 - * def iteritems(self): - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: # <<<<<<<<<<<<<< - * yield (key, self[key]) + /* "pysam/libcbcf.pyx":2567 + * + * if bcf_unpack(self.record.ptr, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * + * bcf_info_set_value(self.record, key, value) + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__120, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2567, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 2567, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2566 + * raise KeyError('END is a reserved attribute; access is via record.stop') + * + * if bcf_unpack(self.record.ptr, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') * */ } + + /* "pysam/libcbcf.pyx":2569 + * raise ValueError('Error unpacking VariantRecord') + * + * bcf_info_set_value(self.record, key, value) # <<<<<<<<<<<<<< + * + * def __delitem__(self, key): + */ + __pyx_t_1 = ((PyObject *)__pyx_v_self->record); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_4 = __pyx_f_5pysam_7libcbcf_bcf_info_set_value(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_1), __pyx_v_key, __pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2569, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2220 - * yield self[key] + /* "pysam/libcbcf.pyx":2560 + * return bcf_info_get_value(self.record, info) + * + * def __setitem__(self, key, value): # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) * - * def iteritems(self): # <<<<<<<<<<<<<< - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: */ /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_XDECREF(__pyx_v_bkey); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2225 - * yield (key, self[key]) +/* "pysam/libcbcf.pyx":2571 + * bcf_info_set_value(self.record, key, value) * - * def keys(self): # <<<<<<<<<<<<<< - * """D.keys() -> list of D's keys""" - * return list(self) + * def __delitem__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_28keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_27keys[] = "VariantRecordFormat.keys(self)\nD.keys() -> list of D's keys"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_28keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_11__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_11__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("keys (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_27keys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__delitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_10__delitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), ((PyObject *)__pyx_v_key)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_27keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_10__delitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_key) { + bcf_hdr_t *__pyx_v_hdr; + bcf1_t *__pyx_v_r; + PyObject *__pyx_v_bkey = 0; + bcf_info_t *__pyx_v_info; + int __pyx_v_info_id; + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("keys", 0); - __Pyx_TraceCall("keys", __pyx_f[0], 2225, 0, __PYX_ERR(0, 2225, __pyx_L1_error)); + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char const *__pyx_t_4; + int __pyx_t_5; + char const *__pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + int __pyx_t_12; + char const *__pyx_t_13; + __Pyx_RefNannySetupContext("__delitem__", 0); + __Pyx_TraceCall("__delitem__", __pyx_f[0], 2571, 0, __PYX_ERR(0, 2571, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2227 - * def keys(self): - * """D.keys() -> list of D's keys""" - * return list(self) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2572 + * + * def __delitem__(self, key): + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr * - * def items(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2227, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2225 - * yield (key, self[key]) + /* "pysam/libcbcf.pyx":2573 + * def __delitem__(self, key): + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< * - * def keys(self): # <<<<<<<<<<<<<< - * """D.keys() -> list of D's keys""" - * return list(self) + * cdef bytes bkey = force_bytes(key) */ + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2575 + * cdef bcf1_t *r = self.record.ptr + * + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< + * if strcmp(bkey, b'END') == 0: + * raise KeyError('END is a reserved attribute; access is via record.stop') + */ + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2575, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_bkey = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; -/* "pysam/libcbcf.pyx":2229 - * return list(self) + /* "pysam/libcbcf.pyx":2576 + * + * cdef bytes bkey = force_bytes(key) + * if strcmp(bkey, b'END') == 0: # <<<<<<<<<<<<<< + * raise KeyError('END is a reserved attribute; access is via record.stop') * - * def items(self): # <<<<<<<<<<<<<< - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2576, __pyx_L1_error) + } + __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2576, __pyx_L1_error) + __pyx_t_5 = ((strcmp(__pyx_t_4, ((char const *)"END")) == 0) != 0); + if (unlikely(__pyx_t_5)) { -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_30items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_29items[] = "VariantRecordFormat.items(self)\nD.items() -> list of D's (key, value) pairs, as 2-tuples"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_30items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("items (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_29items(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); + /* "pysam/libcbcf.pyx":2577 + * cdef bytes bkey = force_bytes(key) + * if strcmp(bkey, b'END') == 0: + * raise KeyError('END is a reserved attribute; access is via record.stop') # <<<<<<<<<<<<<< + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__121, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2577, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 2577, __pyx_L1_error) - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2576 + * + * cdef bytes bkey = force_bytes(key) + * if strcmp(bkey, b'END') == 0: # <<<<<<<<<<<<<< + * raise KeyError('END is a reserved attribute; access is via record.stop') + * + */ + } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_29items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("items", 0); - __Pyx_TraceCall("items", __pyx_f[0], 2229, 0, __PYX_ERR(0, 2229, __pyx_L1_error)); + /* "pysam/libcbcf.pyx":2579 + * raise KeyError('END is a reserved attribute; access is via record.stop') + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') + * + */ + __pyx_t_5 = ((bcf_unpack(__pyx_v_r, BCF_UN_INFO) < 0) != 0); + if (unlikely(__pyx_t_5)) { - /* "pysam/libcbcf.pyx":2231 - * def items(self): - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2580 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * + * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__122, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2580, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 2580, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2579 + * raise KeyError('END is a reserved attribute; access is via record.stop') + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') * - * def values(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2231, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2231, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2582 + * raise ValueError('Error unpacking VariantRecord') + * + * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) # <<<<<<<<<<<<<< + * + * # Cannot stop here if info == NULL, since flags must return False + */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2582, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 2582, __pyx_L1_error) + __pyx_v_info = bcf_get_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_6); + + /* "pysam/libcbcf.pyx":2585 + * + * # Cannot stop here if info == NULL, since flags must return False + * cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key # <<<<<<<<<<<<<< + * + * if info_id < 0: + */ + if (((!(__pyx_v_info != 0)) != 0)) { + __pyx_t_8 = __pyx_f_5pysam_7libcbcf_bcf_header_get_info_id(__pyx_v_hdr, __pyx_v_bkey); if (unlikely(__pyx_t_8 == ((int)-2) && PyErr_Occurred())) __PYX_ERR(0, 2585, __pyx_L1_error) + __pyx_t_7 = __pyx_t_8; + } else { + __pyx_t_7 = __pyx_v_info->key; + } + __pyx_v_info_id = __pyx_t_7; + + /* "pysam/libcbcf.pyx":2587 + * cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key + * + * if info_id < 0: # <<<<<<<<<<<<<< + * raise KeyError('Unknown INFO field: {}'.format(key)) + * + */ + __pyx_t_5 = ((__pyx_v_info_id < 0) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcbcf.pyx":2588 + * + * if info_id < 0: + * raise KeyError('Unknown INFO field: {}'.format(key)) # <<<<<<<<<<<<<< + * + * if not check_header_id(hdr, BCF_HL_INFO, info_id): + */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Unknown_INFO_field, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + if (!__pyx_t_10) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2588, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2588, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_key); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 2588, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2587 + * cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key + * + * if info_id < 0: # <<<<<<<<<<<<<< + * raise KeyError('Unknown INFO field: {}'.format(key)) + * + */ + } + + /* "pysam/libcbcf.pyx":2590 + * raise KeyError('Unknown INFO field: {}'.format(key)) + * + * if not check_header_id(hdr, BCF_HL_INFO, info_id): # <<<<<<<<<<<<<< + * raise ValueError('Invalid header') + * + */ + __pyx_t_5 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_INFO, __pyx_v_info_id) != 0)) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcbcf.pyx":2591 + * + * if not check_header_id(hdr, BCF_HL_INFO, info_id): + * raise ValueError('Invalid header') # <<<<<<<<<<<<<< + * + * # Handle flags + */ + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__123, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2591, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 2591, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2590 + * raise KeyError('Unknown INFO field: {}'.format(key)) + * + * if not check_header_id(hdr, BCF_HL_INFO, info_id): # <<<<<<<<<<<<<< + * raise ValueError('Invalid header') + * + */ + } + + /* "pysam/libcbcf.pyx":2594 + * + * # Handle flags + * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG and (not info or not info.vptr): # <<<<<<<<<<<<<< + * return + * + */ + __pyx_t_12 = ((bcf_hdr_id2type(__pyx_v_hdr, BCF_HL_INFO, __pyx_v_info_id) == BCF_HT_FLAG) != 0); + if (__pyx_t_12) { } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2231, __pyx_L1_error) + __pyx_t_5 = __pyx_t_12; + goto __pyx_L8_bool_binop_done; } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2231, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_t_12 = ((!(__pyx_v_info != 0)) != 0); + if (!__pyx_t_12) { + } else { + __pyx_t_5 = __pyx_t_12; + goto __pyx_L8_bool_binop_done; + } + __pyx_t_12 = ((!(__pyx_v_info->vptr != 0)) != 0); + __pyx_t_5 = __pyx_t_12; + __pyx_L8_bool_binop_done:; + if (__pyx_t_5) { - /* "pysam/libcbcf.pyx":2229 - * return list(self) + /* "pysam/libcbcf.pyx":2595 + * # Handle flags + * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG and (not info or not info.vptr): + * return # <<<<<<<<<<<<<< * - * def items(self): # <<<<<<<<<<<<<< - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) + * if not info or not info.vptr: */ + __pyx_r = 0; + goto __pyx_L0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.items", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcbcf.pyx":2233 - * return list(self.iteritems()) + /* "pysam/libcbcf.pyx":2594 + * + * # Handle flags + * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG and (not info or not info.vptr): # <<<<<<<<<<<<<< + * return * - * def values(self): # <<<<<<<<<<<<<< - * """D.values() -> list of D's values""" - * return list(self.itervalues()) */ + } -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_32values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_31values[] = "VariantRecordFormat.values(self)\nD.values() -> list of D's values"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_32values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("values (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_31values(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); + /* "pysam/libcbcf.pyx":2597 + * return + * + * if not info or not info.vptr: # <<<<<<<<<<<<<< + * raise KeyError('Unknown INFO field: {}'.format(key)) + * + */ + __pyx_t_12 = ((!(__pyx_v_info != 0)) != 0); + if (!__pyx_t_12) { + } else { + __pyx_t_5 = __pyx_t_12; + goto __pyx_L12_bool_binop_done; + } + __pyx_t_12 = ((!(__pyx_v_info->vptr != 0)) != 0); + __pyx_t_5 = __pyx_t_12; + __pyx_L12_bool_binop_done:; + if (unlikely(__pyx_t_5)) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2598 + * + * if not info or not info.vptr: + * raise KeyError('Unknown INFO field: {}'.format(key)) # <<<<<<<<<<<<<< + * + * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Unknown_INFO_field, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2598, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_11) { + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_key); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2598, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_key}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2598, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_key}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2598, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + { + __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2598, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_11); __pyx_t_11 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_key); + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2598, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2598, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 2598, __pyx_L1_error) -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_31values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("values", 0); - __Pyx_TraceCall("values", __pyx_f[0], 2233, 0, __PYX_ERR(0, 2233, __pyx_L1_error)); + /* "pysam/libcbcf.pyx":2597 + * return + * + * if not info or not info.vptr: # <<<<<<<<<<<<<< + * raise KeyError('Unknown INFO field: {}'.format(key)) + * + */ + } - /* "pysam/libcbcf.pyx":2235 - * def values(self): - * """D.values() -> list of D's values""" - * return list(self.itervalues()) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2600 + * raise KeyError('Unknown INFO field: {}'.format(key)) + * + * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Unable to delete INFO') * - * # Mappings are not hashable by default, but subclasses can change this */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2235, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2600, __pyx_L1_error) } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2235, __pyx_L1_error) + __pyx_t_13 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) __PYX_ERR(0, 2600, __pyx_L1_error) + __pyx_t_5 = ((bcf_update_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_13, NULL, 0, __pyx_v_info->type) < 0) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcbcf.pyx":2601 + * + * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: + * raise ValueError('Unable to delete INFO') # <<<<<<<<<<<<<< + * + * def clear(self): + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__124, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2601, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2235, __pyx_L1_error) + __PYX_ERR(0, 2601, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2600 + * raise KeyError('Unknown INFO field: {}'.format(key)) + * + * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Unable to delete INFO') + * + */ } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2235, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - /* "pysam/libcbcf.pyx":2233 - * return list(self.iteritems()) + /* "pysam/libcbcf.pyx":2571 + * bcf_info_set_value(self.record, key, value) * - * def values(self): # <<<<<<<<<<<<<< - * """D.values() -> list of D's values""" - * return list(self.itervalues()) + * def __delitem__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.values", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__delitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_XDECREF(__pyx_v_bkey); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * cdef bint use_setstate - * state = (self.record,) +/* "pysam/libcbcf.pyx":2603 + * raise ValueError('Unable to delete INFO') + * + * def clear(self): # <<<<<<<<<<<<<< + * """Clear all info data""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_34__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_33__reduce_cython__[] = "VariantRecordFormat.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_34__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_13clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_12clear[] = "VariantRecordInfo.clear(self)\nClear all info data"; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_13clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_33__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self)); + __Pyx_RefNannySetupContext("clear (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_12clear(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_33__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self) { - int __pyx_v_use_setstate; - PyObject *__pyx_v_state = NULL; - PyObject *__pyx_v__dict = NULL; +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_12clear(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { + bcf_hdr_t *__pyx_v_hdr; + bcf1_t *__pyx_v_r; + bcf_info_t *__pyx_v_info; + char const *__pyx_v_key; + int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; int __pyx_t_3; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); - - /* "(tree fragment)":3 - * def __reduce_cython__(self): - * cdef bint use_setstate - * state = (self.record,) # <<<<<<<<<<<<<< - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_self->record)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->record)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->record)); - __pyx_v_state = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "(tree fragment)":4 - * cdef bint use_setstate - * state = (self.record,) - * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< - * if _dict is not None: - * state += (_dict,) - */ - __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v__dict = __pyx_t_1; - __pyx_t_1 = 0; - - /* "(tree fragment)":5 - * state = (self.record,) - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: # <<<<<<<<<<<<<< - * state += (_dict,) - * use_setstate = True - */ - __pyx_t_2 = (__pyx_v__dict != Py_None); - __pyx_t_3 = (__pyx_t_2 != 0); - if (__pyx_t_3) { - - /* "(tree fragment)":6 - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: - * state += (_dict,) # <<<<<<<<<<<<<< - * use_setstate = True - * else: - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v__dict); - __Pyx_GIVEREF(__pyx_v__dict); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); - __pyx_t_4 = 0; - - /* "(tree fragment)":7 - * if _dict is not None: - * state += (_dict,) - * use_setstate = True # <<<<<<<<<<<<<< - * else: - * use_setstate = self.record is not None - */ - __pyx_v_use_setstate = 1; + uint32_t __pyx_t_5; + uint32_t __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + __Pyx_RefNannySetupContext("clear", 0); + __Pyx_TraceCall("clear", __pyx_f[0], 2603, 0, __PYX_ERR(0, 2603, __pyx_L1_error)); - /* "(tree fragment)":5 - * state = (self.record,) - * _dict = getattr(self, '__dict__', None) - * if _dict is not None: # <<<<<<<<<<<<<< - * state += (_dict,) - * use_setstate = True + /* "pysam/libcbcf.pyx":2605 + * def clear(self): + * """Clear all info data""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef bcf_info_t *info */ - goto __pyx_L3; - } + __pyx_t_1 = __pyx_v_self->record->header->ptr; + __pyx_v_hdr = __pyx_t_1; - /* "(tree fragment)":9 - * use_setstate = True - * else: - * use_setstate = self.record is not None # <<<<<<<<<<<<<< - * if use_setstate: - * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, None), state + /* "pysam/libcbcf.pyx":2606 + * """Clear all info data""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef bcf_info_t *info + * cdef const char *key */ - /*else*/ { - __pyx_t_3 = (((PyObject *)__pyx_v_self->record) != Py_None); - __pyx_v_use_setstate = __pyx_t_3; - } - __pyx_L3:; + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_r = __pyx_t_2; - /* "(tree fragment)":10 - * else: - * use_setstate = self.record is not None - * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, None), state - * else: + /* "pysam/libcbcf.pyx":2611 + * cdef int i + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') + * */ - __pyx_t_3 = (__pyx_v_use_setstate != 0); - if (__pyx_t_3) { + __pyx_t_3 = ((bcf_unpack(__pyx_v_r, BCF_UN_INFO) < 0) != 0); + if (unlikely(__pyx_t_3)) { - /* "(tree fragment)":11 - * use_setstate = self.record is not None - * if use_setstate: - * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, None), state # <<<<<<<<<<<<<< - * else: - * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, state) + /* "pysam/libcbcf.pyx":2612 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * + * for i in range(r.n_info): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordForm); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__125, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2612, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_INCREF(__pyx_int_232881935); - __Pyx_GIVEREF(__pyx_int_232881935); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_232881935); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); - __Pyx_INCREF(__pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); - __pyx_t_4 = 0; - __pyx_t_1 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; - - /* "(tree fragment)":10 - * else: - * use_setstate = self.record is not None - * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, None), state - * else: - */ - } + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2612, __pyx_L1_error) - /* "(tree fragment)":13 - * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, None), state - * else: - * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, state) # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_VariantRecordFormat__set_state(self, __pyx_state) + /* "pysam/libcbcf.pyx":2611 + * cdef int i + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') + * */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordForm); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); - __Pyx_INCREF(__pyx_int_232881935); - __Pyx_GIVEREF(__pyx_int_232881935); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_232881935); - __Pyx_INCREF(__pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); - __pyx_t_5 = 0; - __pyx_t_1 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; } - /* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * cdef bint use_setstate - * state = (self.record,) - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_state); - __Pyx_XDECREF(__pyx_v__dict); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "(tree fragment)":14 - * else: - * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, state) - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_VariantRecordFormat__set_state(self, __pyx_state) + /* "pysam/libcbcf.pyx":2614 + * raise ValueError('Error unpacking VariantRecord') + * + * for i in range(r.n_info): # <<<<<<<<<<<<<< + * info = &r.d.info[i] + * if info and info.vptr: */ + __pyx_t_5 = __pyx_v_r->n_info; + __pyx_t_6 = __pyx_t_5; + for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { + __pyx_v_i = __pyx_t_7; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_36__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordFormat_35__setstate_cython__[] = "VariantRecordFormat.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordFormat_36__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_35__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordFormat_35__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_self, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); - - /* "(tree fragment)":15 - * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, state) - * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_VariantRecordFormat__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2615 + * + * for i in range(r.n_info): + * info = &r.d.info[i] # <<<<<<<<<<<<<< + * if info and info.vptr: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFormat__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_info = (&(__pyx_v_r->d.info[__pyx_v_i])); - /* "(tree fragment)":14 - * else: - * return __pyx_unpickle_VariantRecordFormat, (type(self), 0xde17f0f, state) - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_VariantRecordFormat__set_state(self, __pyx_state) + /* "pysam/libcbcf.pyx":2616 + * for i in range(r.n_info): + * info = &r.d.info[i] + * if info and info.vptr: # <<<<<<<<<<<<<< + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') == 0: */ + __pyx_t_8 = (__pyx_v_info != 0); + if (__pyx_t_8) { + } else { + __pyx_t_3 = __pyx_t_8; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_8 = (__pyx_v_info->vptr != 0); + __pyx_t_3 = __pyx_t_8; + __pyx_L7_bool_binop_done:; + if (__pyx_t_3) { - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordFormat.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcbcf.pyx":2243 - * - * - * cdef VariantRecordFormat makeVariantRecordFormat(VariantRecord record): # <<<<<<<<<<<<<< - * if not record: - * raise ValueError('invalid VariantRecord') + /* "pysam/libcbcf.pyx":2617 + * info = &r.d.info[i] + * if info and info.vptr: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) # <<<<<<<<<<<<<< + * if strcmp(key, b'END') == 0: + * continue */ + __pyx_v_key = bcf_hdr_int2id(__pyx_v_hdr, BCF_DT_ID, __pyx_v_info->key); -static struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_f_5pysam_7libcbcf_makeVariantRecordFormat(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record) { - struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_v_format = 0; - struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("makeVariantRecordFormat", 0); - __Pyx_TraceCall("makeVariantRecordFormat", __pyx_f[0], 2243, 0, __PYX_ERR(0, 2243, __pyx_L1_error)); + /* "pysam/libcbcf.pyx":2618 + * if info and info.vptr: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') == 0: # <<<<<<<<<<<<<< + * continue + * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: + */ + __pyx_t_3 = ((strcmp(__pyx_v_key, ((char const *)"END")) == 0) != 0); + if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2244 - * - * cdef VariantRecordFormat makeVariantRecordFormat(VariantRecord record): - * if not record: # <<<<<<<<<<<<<< - * raise ValueError('invalid VariantRecord') - * + /* "pysam/libcbcf.pyx":2619 + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') == 0: + * continue # <<<<<<<<<<<<<< + * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: + * raise ValueError('Unable to delete INFO') */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_record)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2244, __pyx_L1_error) - __pyx_t_2 = ((!__pyx_t_1) != 0); - if (unlikely(__pyx_t_2)) { + goto __pyx_L4_continue; - /* "pysam/libcbcf.pyx":2245 - * cdef VariantRecordFormat makeVariantRecordFormat(VariantRecord record): - * if not record: - * raise ValueError('invalid VariantRecord') # <<<<<<<<<<<<<< - * - * cdef VariantRecordFormat format = VariantRecordFormat.__new__(VariantRecordFormat) + /* "pysam/libcbcf.pyx":2618 + * if info and info.vptr: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') == 0: # <<<<<<<<<<<<<< + * continue + * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__119, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2245, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2245, __pyx_L1_error) + } - /* "pysam/libcbcf.pyx":2244 - * - * cdef VariantRecordFormat makeVariantRecordFormat(VariantRecord record): - * if not record: # <<<<<<<<<<<<<< - * raise ValueError('invalid VariantRecord') + /* "pysam/libcbcf.pyx":2620 + * if strcmp(key, b'END') == 0: + * continue + * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Unable to delete INFO') * */ - } + __pyx_t_3 = ((bcf_update_info(__pyx_v_hdr, __pyx_v_r, __pyx_v_key, NULL, 0, __pyx_v_info->type) < 0) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2247 - * raise ValueError('invalid VariantRecord') - * - * cdef VariantRecordFormat format = VariantRecordFormat.__new__(VariantRecordFormat) # <<<<<<<<<<<<<< - * format.record = record + /* "pysam/libcbcf.pyx":2621 + * continue + * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: + * raise ValueError('Unable to delete INFO') # <<<<<<<<<<<<<< * + * def __iter__(self): */ - __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantRecordFormat(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordFormat), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2247, __pyx_L1_error) - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_v_format = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__126, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2621, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2621, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2248 - * - * cdef VariantRecordFormat format = VariantRecordFormat.__new__(VariantRecordFormat) - * format.record = record # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2620 + * if strcmp(key, b'END') == 0: + * continue + * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Unable to delete INFO') * - * return format */ - __Pyx_INCREF(((PyObject *)__pyx_v_record)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_record)); - __Pyx_GOTREF(__pyx_v_format->record); - __Pyx_DECREF(((PyObject *)__pyx_v_format->record)); - __pyx_v_format->record = __pyx_v_record; + } - /* "pysam/libcbcf.pyx":2250 - * format.record = record - * - * return format # <<<<<<<<<<<<<< - * - * + /* "pysam/libcbcf.pyx":2616 + * for i in range(r.n_info): + * info = &r.d.info[i] + * if info and info.vptr: # <<<<<<<<<<<<<< + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') == 0: */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_format)); - __pyx_r = __pyx_v_format; - goto __pyx_L0; + } + __pyx_L4_continue:; + } - /* "pysam/libcbcf.pyx":2243 - * + /* "pysam/libcbcf.pyx":2603 + * raise ValueError('Unable to delete INFO') * - * cdef VariantRecordFormat makeVariantRecordFormat(VariantRecord record): # <<<<<<<<<<<<<< - * if not record: - * raise ValueError('invalid VariantRecord') + * def clear(self): # <<<<<<<<<<<<<< + * """Clear all info data""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.makeVariantRecordFormat", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.clear", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_format); - __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_16generator17(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":2258 - * mapping from info metadata name to value.""" - * - * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< - * raise TypeError('this class cannot be instantiated from Python') +/* "pysam/libcbcf.pyx":2623 + * raise ValueError('Unable to delete INFO') * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - CYTHON_UNUSED PyObject *__pyx_v_args = 0; - CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0; - int __pyx_r; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_15__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_15__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1; - __Pyx_INCREF(__pyx_args); - __pyx_v_args = __pyx_args; - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo___init__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_14__iter__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); /* function exit code */ - __Pyx_XDECREF(__pyx_v_args); - __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) { - int __pyx_r; - __Pyx_TraceDeclarations +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_14__iter__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_27___iter__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 2258, 0, __PYX_ERR(0, 2258, __pyx_L1_error)); - - /* "pysam/libcbcf.pyx":2259 - * - * def __init__(self, *args, **kwargs): - * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< - * - * def __len__(self): - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__120, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2259, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 2259, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":2258 - * mapping from info metadata name to value.""" - * - * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< - * raise TypeError('this class cannot be instantiated from Python') - * - */ + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_27___iter__ *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_27___iter__(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_27___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_27___iter__ *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 2623, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_16generator17, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantRecordInfo___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2623, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2261 - * raise TypeError('this class cannot be instantiated from Python') - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.record.ptr.n_info - * - */ - -/* Python wrapper */ -static Py_ssize_t __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_3__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_3__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; +static PyObject *__pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_16generator17(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_27___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_27___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + uint32_t __pyx_t_5; + uint32_t __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_2__len__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__iter__", 0); + __Pyx_TraceCall("__iter__", __pyx_f[0], 2623, 0, __PYX_ERR(0, 2623, __pyx_L1_error)); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L11_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2623, __pyx_L1_error) - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2624 + * + * def __iter__(self): + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef bcf_info_t *info + */ + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; + __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; -static Py_ssize_t __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_2__len__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[0], 2261, 0, __PYX_ERR(0, 2261, __pyx_L1_error)); + /* "pysam/libcbcf.pyx":2625 + * def __iter__(self): + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef bcf_info_t *info + * cdef const char *key + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; + __pyx_cur_scope->__pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2262 + /* "pysam/libcbcf.pyx":2630 + * cdef int i * - * def __len__(self): - * return self.record.ptr.n_info # <<<<<<<<<<<<<< + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') * - * def __bool__(self): */ - __pyx_r = __pyx_v_self->record->ptr->n_info; - goto __pyx_L0; + __pyx_t_3 = ((bcf_unpack(__pyx_cur_scope->__pyx_v_r, BCF_UN_INFO) < 0) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2261 - * raise TypeError('this class cannot be instantiated from Python') + /* "pysam/libcbcf.pyx":2631 * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.record.ptr.n_info + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * + * for i in range(r.n_info): */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__127, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2631, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2631, __pyx_L1_error) - /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2630 + * cdef int i + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') + * + */ + } -/* "pysam/libcbcf.pyx":2264 - * return self.record.ptr.n_info + /* "pysam/libcbcf.pyx":2633 + * raise ValueError('Error unpacking VariantRecord') * - * def __bool__(self): # <<<<<<<<<<<<<< - * return self.record.ptr.n_info != 0 + * for i in range(r.n_info): # <<<<<<<<<<<<<< + * info = &r.d.info[i] + * if info and info.vptr: + */ + __pyx_t_5 = __pyx_cur_scope->__pyx_v_r->n_info; + __pyx_t_6 = __pyx_t_5; + for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_7; + + /* "pysam/libcbcf.pyx":2634 * + * for i in range(r.n_info): + * info = &r.d.info[i] # <<<<<<<<<<<<<< + * if info and info.vptr: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) */ + __pyx_cur_scope->__pyx_v_info = (&(__pyx_cur_scope->__pyx_v_r->d.info[__pyx_cur_scope->__pyx_v_i])); -/* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_5__bool__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_5__bool__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__bool__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_4__bool__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + /* "pysam/libcbcf.pyx":2635 + * for i in range(r.n_info): + * info = &r.d.info[i] + * if info and info.vptr: # <<<<<<<<<<<<<< + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') != 0: + */ + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_info != 0); + if (__pyx_t_8) { + } else { + __pyx_t_3 = __pyx_t_8; + goto __pyx_L8_bool_binop_done; + } + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_info->vptr != 0); + __pyx_t_3 = __pyx_t_8; + __pyx_L8_bool_binop_done:; + if (__pyx_t_3) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2636 + * info = &r.d.info[i] + * if info and info.vptr: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) # <<<<<<<<<<<<<< + * if strcmp(key, b'END') != 0: + * yield bcf_str_cache_get_charptr(key) + */ + __pyx_cur_scope->__pyx_v_key = bcf_hdr_int2id(__pyx_cur_scope->__pyx_v_hdr, BCF_DT_ID, __pyx_cur_scope->__pyx_v_info->key); -static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_4__bool__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 2264, 0, __PYX_ERR(0, 2264, __pyx_L1_error)); + /* "pysam/libcbcf.pyx":2637 + * if info and info.vptr: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') != 0: # <<<<<<<<<<<<<< + * yield bcf_str_cache_get_charptr(key) + * + */ + __pyx_t_3 = ((strcmp(__pyx_cur_scope->__pyx_v_key, ((char const *)"END")) != 0) != 0); + if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2265 + /* "pysam/libcbcf.pyx":2638 + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') != 0: + * yield bcf_str_cache_get_charptr(key) # <<<<<<<<<<<<<< * - * def __bool__(self): - * return self.record.ptr.n_info != 0 # <<<<<<<<<<<<<< + * def get(self, key, default=None): + */ + __pyx_t_4 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(__pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2638, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_5; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_6; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_7; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L11_resume_from_yield:; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_6 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_7 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2638, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2637 + * if info and info.vptr: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') != 0: # <<<<<<<<<<<<<< + * yield bcf_str_cache_get_charptr(key) * - * def __getitem__(self, key): */ - __pyx_r = (__pyx_v_self->record->ptr->n_info != 0); - goto __pyx_L0; + } - /* "pysam/libcbcf.pyx":2264 - * return self.record.ptr.n_info - * - * def __bool__(self): # <<<<<<<<<<<<<< - * return self.record.ptr.n_info != 0 + /* "pysam/libcbcf.pyx":2635 + * for i in range(r.n_info): + * info = &r.d.info[i] + * if info and info.vptr: # <<<<<<<<<<<<<< + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') != 0: + */ + } + } + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); + + /* "pysam/libcbcf.pyx":2623 + * raise ValueError('Unable to delete INFO') * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2267 - * return self.record.ptr.n_info != 0 +/* "pysam/libcbcf.pyx":2640 + * yield bcf_str_cache_get_charptr(key) * - * def __getitem__(self, key): # <<<<<<<<<<<<<< + * def get(self, key, default=None): # <<<<<<<<<<<<<< + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_18get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_17get[] = "VariantRecordInfo.get(self, key, default=None)\nD.get(k[,d]) -> D[k] if k in D, else d. d defaults to None."; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_18get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_key = 0; + PyObject *__pyx_v_default = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_6__getitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + __Pyx_RefNannySetupContext("get (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_default,0}; + PyObject* values[2] = {0,0}; + values[1] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_default); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 2640, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_key = values[0]; + __pyx_v_default = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2640, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.get", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_17get(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), __pyx_v_key, __pyx_v_default); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_6__getitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_key) { +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_17get(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default) { bcf_hdr_t *__pyx_v_hdr; bcf1_t *__pyx_v_r; - vdict_t *__pyx_v_d; - khiter_t __pyx_v_k; - PyObject *__pyx_v_info_id = 0; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; bcf_info_t *__pyx_v_info; + int __pyx_v_info_id; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -37759,35 +43293,34 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_6__getitem__(struc char const *__pyx_t_5; char const *__pyx_t_6; int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; + int __pyx_t_8; PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - int __pyx_t_11; - __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[0], 2267, 0, __PYX_ERR(0, 2267, __pyx_L1_error)); + int __pyx_t_10; + __Pyx_RefNannySetupContext("get", 0); + __Pyx_TraceCall("get", __pyx_f[0], 2640, 0, __PYX_ERR(0, 2640, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2268 - * - * def __getitem__(self, key): + /* "pysam/libcbcf.pyx":2642 + * def get(self, key, default=None): + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr - * cdef vdict_t *d + * */ __pyx_t_1 = __pyx_v_self->record->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2269 - * def __getitem__(self, key): + /* "pysam/libcbcf.pyx":2643 + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef vdict_t *d - * cdef khiter_t k + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: */ __pyx_t_2 = __pyx_v_self->record->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2274 - * cdef info_id + /* "pysam/libcbcf.pyx":2645 + * cdef bcf1_t *r = self.record.ptr * * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') @@ -37796,21 +43329,21 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_6__getitem__(struc __pyx_t_3 = ((bcf_unpack(__pyx_v_r, BCF_UN_INFO) < 0) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2275 + /* "pysam/libcbcf.pyx":2646 * * if bcf_unpack(r, BCF_UN_INFO) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__121, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2275, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__128, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2646, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 2275, __pyx_L1_error) + __PYX_ERR(0, 2646, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2274 - * cdef info_id + /* "pysam/libcbcf.pyx":2645 + * cdef bcf1_t *r = self.record.ptr * * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') @@ -37818,214 +43351,108 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_6__getitem__(struc */ } - /* "pysam/libcbcf.pyx":2277 + /* "pysam/libcbcf.pyx":2648 * raise ValueError('Error unpacking VariantRecord') * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< - * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * + * if strcmp(bkey, b'END') == 0: */ - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2277, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2648, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_bkey = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2278 - * - * bkey = force_bytes(key) - * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) # <<<<<<<<<<<<<< - * - * if not info: - */ - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2278, __pyx_L1_error) - } - __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 2278, __pyx_L1_error) - __pyx_v_info = bcf_get_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_5); - - /* "pysam/libcbcf.pyx":2280 - * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) - * - * if not info: # <<<<<<<<<<<<<< - * d = hdr.dict[BCF_DT_ID] - * k = kh_get_vdict(d, bkey) - */ - __pyx_t_3 = ((!(__pyx_v_info != 0)) != 0); - if (__pyx_t_3) { - - /* "pysam/libcbcf.pyx":2281 - * - * if not info: - * d = hdr.dict[BCF_DT_ID] # <<<<<<<<<<<<<< - * k = kh_get_vdict(d, bkey) - * - */ - __pyx_v_d = ((vdict_t *)(__pyx_v_hdr->dict[BCF_DT_ID])); - - /* "pysam/libcbcf.pyx":2282 - * if not info: - * d = hdr.dict[BCF_DT_ID] - * k = kh_get_vdict(d, bkey) # <<<<<<<<<<<<<< - * - * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: - */ - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2282, __pyx_L1_error) - } - __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 2282, __pyx_L1_error) - __pyx_v_k = kh_get_vdict(__pyx_v_d, __pyx_t_6); - - /* "pysam/libcbcf.pyx":2284 - * k = kh_get_vdict(d, bkey) - * - * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: # <<<<<<<<<<<<<< - * raise KeyError('Unknown INFO field: {}'.format(key)) - * - */ - __pyx_t_7 = ((__pyx_v_k == kh_end(__pyx_v_d)) != 0); - if (!__pyx_t_7) { - } else { - __pyx_t_3 = __pyx_t_7; - goto __pyx_L6_bool_binop_done; - } - __pyx_t_7 = ((((kh_val(__pyx_v_d, __pyx_v_k).info[BCF_HL_INFO]) & 0xF) == 0xF) != 0); - __pyx_t_3 = __pyx_t_7; - __pyx_L6_bool_binop_done:; - if (unlikely(__pyx_t_3)) { - - /* "pysam/libcbcf.pyx":2285 + /* "pysam/libcbcf.pyx":2650 + * cdef bytes bkey = force_bytes(key) * - * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: - * raise KeyError('Unknown INFO field: {}'.format(key)) # <<<<<<<<<<<<<< + * if strcmp(bkey, b'END') == 0: # <<<<<<<<<<<<<< + * return default * - * info_id = kh_val_vdict(d, k).id */ - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Unknown_INFO_field, __pyx_n_s_format); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2285, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - } - } - if (!__pyx_t_9) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2285, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_key}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2285, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_key}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2285, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else - #endif - { - __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2285, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; - __Pyx_INCREF(__pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_key); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2285, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2285, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 2285, __pyx_L1_error) + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2650, __pyx_L1_error) + } + __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 2650, __pyx_L1_error) + __pyx_t_3 = ((strcmp(__pyx_t_5, ((char const *)"END")) == 0) != 0); + if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2284 - * k = kh_get_vdict(d, bkey) + /* "pysam/libcbcf.pyx":2651 * - * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: # <<<<<<<<<<<<<< - * raise KeyError('Unknown INFO field: {}'.format(key)) + * if strcmp(bkey, b'END') == 0: + * return default # <<<<<<<<<<<<<< * + * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) */ - } + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_default); + __pyx_r = __pyx_v_default; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":2287 - * raise KeyError('Unknown INFO field: {}'.format(key)) + /* "pysam/libcbcf.pyx":2650 + * cdef bytes bkey = force_bytes(key) + * + * if strcmp(bkey, b'END') == 0: # <<<<<<<<<<<<<< + * return default * - * info_id = kh_val_vdict(d, k).id # <<<<<<<<<<<<<< - * else: - * info_id = info.key */ - __pyx_t_8 = __Pyx_PyInt_From_int(kh_val(__pyx_v_d, __pyx_v_k).id); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2287, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_v_info_id = __pyx_t_8; - __pyx_t_8 = 0; + } - /* "pysam/libcbcf.pyx":2280 - * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) + /* "pysam/libcbcf.pyx":2653 + * return default + * + * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) # <<<<<<<<<<<<<< * - * if not info: # <<<<<<<<<<<<<< - * d = hdr.dict[BCF_DT_ID] - * k = kh_get_vdict(d, bkey) + * # Cannot stop here if info == NULL, since flags must return False */ - goto __pyx_L4; + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2653, __pyx_L1_error) } + __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 2653, __pyx_L1_error) + __pyx_v_info = bcf_get_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_6); - /* "pysam/libcbcf.pyx":2289 - * info_id = kh_val_vdict(d, k).id - * else: - * info_id = info.key # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2656 + * + * # Cannot stop here if info == NULL, since flags must return False + * cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key # <<<<<<<<<<<<<< * * if not check_header_id(hdr, BCF_HL_INFO, info_id): */ - /*else*/ { - __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_info->key); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2289, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_v_info_id = __pyx_t_8; - __pyx_t_8 = 0; + if (((!(__pyx_v_info != 0)) != 0)) { + __pyx_t_8 = __pyx_f_5pysam_7libcbcf_bcf_header_get_info_id(__pyx_v_hdr, __pyx_v_bkey); if (unlikely(__pyx_t_8 == ((int)-2) && PyErr_Occurred())) __PYX_ERR(0, 2656, __pyx_L1_error) + __pyx_t_7 = __pyx_t_8; + } else { + __pyx_t_7 = __pyx_v_info->key; } - __pyx_L4:; + __pyx_v_info_id = __pyx_t_7; - /* "pysam/libcbcf.pyx":2291 - * info_id = info.key + /* "pysam/libcbcf.pyx":2658 + * cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key * * if not check_header_id(hdr, BCF_HL_INFO, info_id): # <<<<<<<<<<<<<< * raise ValueError('Invalid header') * */ - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_info_id); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2291, __pyx_L1_error) - __pyx_t_3 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_INFO, __pyx_t_11) != 0)) != 0); + __pyx_t_3 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_INFO, __pyx_v_info_id) != 0)) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2292 + /* "pysam/libcbcf.pyx":2659 * * if not check_header_id(hdr, BCF_HL_INFO, info_id): * raise ValueError('Invalid header') # <<<<<<<<<<<<<< * - * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG: + * # Handle flags */ - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__122, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_Raise(__pyx_t_8, 0, 0, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __PYX_ERR(0, 2292, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__129, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2659, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2659, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2291 - * info_id = info.key + /* "pysam/libcbcf.pyx":2658 + * cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key * * if not check_header_id(hdr, BCF_HL_INFO, info_id): # <<<<<<<<<<<<<< * raise ValueError('Invalid header') @@ -38033,19 +43460,18 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_6__getitem__(struc */ } - /* "pysam/libcbcf.pyx":2294 - * raise ValueError('Invalid header') + /* "pysam/libcbcf.pyx":2662 * + * # Handle flags * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG: # <<<<<<<<<<<<<< * return info != NULL and info.vptr != NULL * */ - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_info_id); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2294, __pyx_L1_error) - __pyx_t_3 = ((bcf_hdr_id2type(__pyx_v_hdr, BCF_HL_INFO, __pyx_t_11) == BCF_HT_FLAG) != 0); + __pyx_t_3 = ((bcf_hdr_id2type(__pyx_v_hdr, BCF_HL_INFO, __pyx_v_info_id) == BCF_HT_FLAG) != 0); if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2295 - * + /* "pysam/libcbcf.pyx":2663 + * # Handle flags * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG: * return info != NULL and info.vptr != NULL # <<<<<<<<<<<<<< * @@ -38055,152 +43481,102 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_6__getitem__(struc __pyx_t_3 = (__pyx_v_info != NULL); if (__pyx_t_3) { } else { - __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L10_bool_binop_done; + __pyx_t_9 = __Pyx_PyBool_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_4 = __pyx_t_9; + __pyx_t_9 = 0; + goto __pyx_L7_bool_binop_done; } __pyx_t_3 = (__pyx_v_info->vptr != NULL); - __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __pyx_t_4; + __pyx_t_9 = __Pyx_PyBool_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_4 = __pyx_t_9; + __pyx_t_9 = 0; + __pyx_L7_bool_binop_done:; + __pyx_r = __pyx_t_4; __pyx_t_4 = 0; - __pyx_L10_bool_binop_done:; - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2294 - * raise ValueError('Invalid header') + /* "pysam/libcbcf.pyx":2662 * + * # Handle flags * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG: # <<<<<<<<<<<<<< * return info != NULL and info.vptr != NULL * */ } - /* "pysam/libcbcf.pyx":2297 + /* "pysam/libcbcf.pyx":2665 * return info != NULL and info.vptr != NULL * * if not info or not info.vptr: # <<<<<<<<<<<<<< - * raise KeyError('Invalid INFO field: {}'.format(key)) + * return default * */ - __pyx_t_7 = ((!(__pyx_v_info != 0)) != 0); - if (!__pyx_t_7) { + __pyx_t_10 = ((!(__pyx_v_info != 0)) != 0); + if (!__pyx_t_10) { } else { - __pyx_t_3 = __pyx_t_7; - goto __pyx_L13_bool_binop_done; + __pyx_t_3 = __pyx_t_10; + goto __pyx_L10_bool_binop_done; } - __pyx_t_7 = ((!(__pyx_v_info->vptr != 0)) != 0); - __pyx_t_3 = __pyx_t_7; - __pyx_L13_bool_binop_done:; - if (unlikely(__pyx_t_3)) { + __pyx_t_10 = ((!(__pyx_v_info->vptr != 0)) != 0); + __pyx_t_3 = __pyx_t_10; + __pyx_L10_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2298 + /* "pysam/libcbcf.pyx":2666 * * if not info or not info.vptr: - * raise KeyError('Invalid INFO field: {}'.format(key)) # <<<<<<<<<<<<<< + * return default # <<<<<<<<<<<<<< * * return bcf_info_get_value(self.record, info) */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_INFO_field, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2298, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (!__pyx_t_10) { - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_key); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2298, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2298, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2298, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else - #endif - { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2298, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10); __pyx_t_10 = NULL; - __Pyx_INCREF(__pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_key); - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2298, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2298, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 2298, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_default); + __pyx_r = __pyx_v_default; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":2297 + /* "pysam/libcbcf.pyx":2665 * return info != NULL and info.vptr != NULL * * if not info or not info.vptr: # <<<<<<<<<<<<<< - * raise KeyError('Invalid INFO field: {}'.format(key)) + * return default * */ } - /* "pysam/libcbcf.pyx":2300 - * raise KeyError('Invalid INFO field: {}'.format(key)) + /* "pysam/libcbcf.pyx":2668 + * return default * * return bcf_info_get_value(self.record, info) # <<<<<<<<<<<<<< * - * def __setitem__(self, key, value): + * def __contains__(self, key): */ __Pyx_XDECREF(__pyx_r); __pyx_t_4 = ((PyObject *)__pyx_v_self->record); __Pyx_INCREF(__pyx_t_4); - __pyx_t_8 = __pyx_f_5pysam_7libcbcf_bcf_info_get_value(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_4), __pyx_v_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2300, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_info_get_value(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_4), __pyx_v_info); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2668, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; + __pyx_r = __pyx_t_9; + __pyx_t_9 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2267 - * return self.record.ptr.n_info != 0 + /* "pysam/libcbcf.pyx":2640 + * yield bcf_str_cache_get_charptr(key) * - * def __getitem__(self, key): # <<<<<<<<<<<<<< + * def get(self, key, default=None): # <<<<<<<<<<<<<< + * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.get", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_info_id); __Pyx_XDECREF(__pyx_v_bkey); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); @@ -38208,97 +43584,31 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_6__getitem__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":2302 - * return bcf_info_get_value(self.record, info) - * - * def __setitem__(self, key, value): # <<<<<<<<<<<<<< - * bcf_info_set_value(self.record, key, value) - * - */ - -/* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_9__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_9__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_8__setitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_value)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_8__setitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__setitem__", 0); - __Pyx_TraceCall("__setitem__", __pyx_f[0], 2302, 0, __PYX_ERR(0, 2302, __pyx_L1_error)); - - /* "pysam/libcbcf.pyx":2303 - * - * def __setitem__(self, key, value): - * bcf_info_set_value(self.record, key, value) # <<<<<<<<<<<<<< - * - * def __delitem__(self, key): - */ - __pyx_t_1 = ((PyObject *)__pyx_v_self->record); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __pyx_f_5pysam_7libcbcf_bcf_info_set_value(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_1), __pyx_v_key, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2303, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pysam/libcbcf.pyx":2302 +/* "pysam/libcbcf.pyx":2670 * return bcf_info_get_value(self.record, info) * - * def __setitem__(self, key, value): # <<<<<<<<<<<<<< - * bcf_info_set_value(self.record, key, value) - * - */ - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcbcf.pyx":2305 - * bcf_info_set_value(self.record, key, value) - * - * def __delitem__(self, key): # <<<<<<<<<<<<<< + * def __contains__(self, key): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_11__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_11__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { +static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_20__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_20__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__delitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_10__delitem__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_19__contains__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), ((PyObject *)__pyx_v_key)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_10__delitem__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_key) { +static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_19__contains__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_key) { bcf_hdr_t *__pyx_v_hdr; bcf1_t *__pyx_v_r; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; bcf_info_t *__pyx_v_info; int __pyx_r; __Pyx_TraceDeclarations @@ -38308,17 +43618,14 @@ static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_10__delitem__(struct __p int __pyx_t_3; PyObject *__pyx_t_4 = NULL; char const *__pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - char const *__pyx_t_10; - __Pyx_RefNannySetupContext("__delitem__", 0); - __Pyx_TraceCall("__delitem__", __pyx_f[0], 2305, 0, __PYX_ERR(0, 2305, __pyx_L1_error)); + char const *__pyx_t_6; + int __pyx_t_7; + __Pyx_RefNannySetupContext("__contains__", 0); + __Pyx_TraceCall("__contains__", __pyx_f[0], 2670, 0, __PYX_ERR(0, 2670, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2306 + /* "pysam/libcbcf.pyx":2671 * - * def __delitem__(self, key): + * def __contains__(self, key): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr * @@ -38326,8 +43633,8 @@ static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_10__delitem__(struct __p __pyx_t_1 = __pyx_v_self->record->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2307 - * def __delitem__(self, key): + /* "pysam/libcbcf.pyx":2672 + * def __contains__(self, key): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< * @@ -38336,7 +43643,7 @@ static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_10__delitem__(struct __p __pyx_t_2 = __pyx_v_self->record->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2309 + /* "pysam/libcbcf.pyx":2674 * cdef bcf1_t *r = self.record.ptr * * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< @@ -38346,20 +43653,20 @@ static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_10__delitem__(struct __p __pyx_t_3 = ((bcf_unpack(__pyx_v_r, BCF_UN_INFO) < 0) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2310 + /* "pysam/libcbcf.pyx":2675 * * if bcf_unpack(r, BCF_UN_INFO) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__123, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2310, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__130, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2675, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 2310, __pyx_L1_error) + __PYX_ERR(0, 2675, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2309 + /* "pysam/libcbcf.pyx":2674 * cdef bcf1_t *r = self.record.ptr * * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< @@ -38368,211 +43675,499 @@ static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_10__delitem__(struct __p */ } - /* "pysam/libcbcf.pyx":2312 + /* "pysam/libcbcf.pyx":2677 * raise ValueError('Error unpacking VariantRecord') * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< - * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * + * if strcmp(bkey, b'END') == 0: */ - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2312, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2677, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_bkey = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2313 + /* "pysam/libcbcf.pyx":2679 + * cdef bytes bkey = force_bytes(key) + * + * if strcmp(bkey, b'END') == 0: # <<<<<<<<<<<<<< + * return False + * + */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2679, __pyx_L1_error) + } + __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 2679, __pyx_L1_error) + __pyx_t_3 = ((strcmp(__pyx_t_5, ((char const *)"END")) == 0) != 0); + if (__pyx_t_3) { + + /* "pysam/libcbcf.pyx":2680 + * + * if strcmp(bkey, b'END') == 0: + * return False # <<<<<<<<<<<<<< + * + * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2679 + * cdef bytes bkey = force_bytes(key) + * + * if strcmp(bkey, b'END') == 0: # <<<<<<<<<<<<<< + * return False + * + */ + } + + /* "pysam/libcbcf.pyx":2682 + * return False * - * bkey = force_bytes(key) * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) # <<<<<<<<<<<<<< * - * if not info or not info.vptr: + * return info != NULL and info.vptr != NULL */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2313, __pyx_L1_error) + __PYX_ERR(0, 2682, __pyx_L1_error) } - __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 2313, __pyx_L1_error) - __pyx_v_info = bcf_get_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_5); + __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 2682, __pyx_L1_error) + __pyx_v_info = bcf_get_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_6); - /* "pysam/libcbcf.pyx":2315 + /* "pysam/libcbcf.pyx":2684 * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) * - * if not info or not info.vptr: # <<<<<<<<<<<<<< - * raise KeyError('Unknown INFO field: {}'.format(key)) + * return info != NULL and info.vptr != NULL # <<<<<<<<<<<<<< + * + * def iterkeys(self): + */ + __pyx_t_3 = (__pyx_v_info != NULL); + if (__pyx_t_3) { + } else { + __pyx_t_7 = __pyx_t_3; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_3 = (__pyx_v_info->vptr != NULL); + __pyx_t_7 = __pyx_t_3; + __pyx_L5_bool_binop_done:; + __pyx_r = __pyx_t_7; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2670 + * return bcf_info_get_value(self.record, info) + * + * def __contains__(self, key): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_bkey); + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2686 + * return info != NULL and info.vptr != NULL + * + * def iterkeys(self): # <<<<<<<<<<<<<< + * """D.iterkeys() -> an iterator over the keys of D""" + * return iter(self) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_22iterkeys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_21iterkeys[] = "VariantRecordInfo.iterkeys(self)\nD.iterkeys() -> an iterator over the keys of D"; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_22iterkeys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("iterkeys (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_21iterkeys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_21iterkeys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("iterkeys", 0); + __Pyx_TraceCall("iterkeys", __pyx_f[0], 2686, 0, __PYX_ERR(0, 2686, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2688 + * def iterkeys(self): + * """D.iterkeys() -> an iterator over the keys of D""" + * return iter(self) # <<<<<<<<<<<<<< + * + * def itervalues(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2686 + * return info != NULL and info.vptr != NULL + * + * def iterkeys(self): # <<<<<<<<<<<<<< + * """D.iterkeys() -> an iterator over the keys of D""" + * return iter(self) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.iterkeys", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_25generator18(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ + +/* "pysam/libcbcf.pyx":2690 + * return iter(self) + * + * def itervalues(self): # <<<<<<<<<<<<<< + * """D.itervalues() -> an iterator over the values of D""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_24itervalues(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_23itervalues[] = "VariantRecordInfo.itervalues(self)\nD.itervalues() -> an iterator over the values of D"; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_24itervalues(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("itervalues (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_23itervalues(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_23itervalues(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_28_itervalues *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("itervalues", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_28_itervalues *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_28_itervalues(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_28_itervalues, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_28_itervalues *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 2690, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_25generator18, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantRecordInfo_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2690, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_25generator18(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_28_itervalues *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_28_itervalues *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + bcf_hdr_t *__pyx_t_1; + bcf1_t *__pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + uint32_t __pyx_t_5; + uint32_t __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("itervalues", 0); + __Pyx_TraceCall("itervalues", __pyx_f[0], 2690, 0, __PYX_ERR(0, 2690, __pyx_L1_error)); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L11_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2690, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2692 + * def itervalues(self): + * """D.itervalues() -> an iterator over the values of D""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *r = self.record.ptr + * cdef bcf_info_t *info + */ + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; + __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; + + /* "pysam/libcbcf.pyx":2693 + * """D.itervalues() -> an iterator over the values of D""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef bcf_info_t *info + * cdef const char *key + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; + __pyx_cur_scope->__pyx_v_r = __pyx_t_2; + + /* "pysam/libcbcf.pyx":2698 + * cdef int i + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') + * + */ + __pyx_t_3 = ((bcf_unpack(__pyx_cur_scope->__pyx_v_r, BCF_UN_INFO) < 0) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcbcf.pyx":2699 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * + * for i in range(r.n_info): + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__131, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2699, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2699, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2698 + * cdef int i + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Error unpacking VariantRecord') * */ - __pyx_t_6 = ((!(__pyx_v_info != 0)) != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_3 = __pyx_t_6; - goto __pyx_L5_bool_binop_done; } - __pyx_t_6 = ((!(__pyx_v_info->vptr != 0)) != 0); - __pyx_t_3 = __pyx_t_6; - __pyx_L5_bool_binop_done:; - if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2316 + /* "pysam/libcbcf.pyx":2701 + * raise ValueError('Error unpacking VariantRecord') * - * if not info or not info.vptr: - * raise KeyError('Unknown INFO field: {}'.format(key)) # <<<<<<<<<<<<<< + * for i in range(r.n_info): # <<<<<<<<<<<<<< + * info = &r.d.info[i] + * if info and info.vptr: + */ + __pyx_t_5 = __pyx_cur_scope->__pyx_v_r->n_info; + __pyx_t_6 = __pyx_t_5; + for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_7; + + /* "pysam/libcbcf.pyx":2702 * - * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: + * for i in range(r.n_info): + * info = &r.d.info[i] # <<<<<<<<<<<<<< + * if info and info.vptr: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Unknown_INFO_field, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2316, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - if (!__pyx_t_8) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2316, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_cur_scope->__pyx_v_info = (&(__pyx_cur_scope->__pyx_v_r->d.info[__pyx_cur_scope->__pyx_v_i])); + + /* "pysam/libcbcf.pyx":2703 + * for i in range(r.n_info): + * info = &r.d.info[i] + * if info and info.vptr: # <<<<<<<<<<<<<< + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') != 0: + */ + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_info != 0); + if (__pyx_t_8) { } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_key}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2316, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { - PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_key}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2316, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else - #endif - { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2316, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; - __Pyx_INCREF(__pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_key); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2316, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } + __pyx_t_3 = __pyx_t_8; + goto __pyx_L8_bool_binop_done; } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2316, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_7, 0, 0, 0); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __PYX_ERR(0, 2316, __pyx_L1_error) + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_info->vptr != 0); + __pyx_t_3 = __pyx_t_8; + __pyx_L8_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2315 - * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) - * - * if not info or not info.vptr: # <<<<<<<<<<<<<< - * raise KeyError('Unknown INFO field: {}'.format(key)) - * + /* "pysam/libcbcf.pyx":2704 + * info = &r.d.info[i] + * if info and info.vptr: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) # <<<<<<<<<<<<<< + * if strcmp(key, b'END') != 0: + * yield bcf_info_get_value(self.record, info) */ - } + __pyx_cur_scope->__pyx_v_key = bcf_hdr_int2id(__pyx_cur_scope->__pyx_v_hdr, BCF_DT_ID, __pyx_cur_scope->__pyx_v_info->key); - /* "pysam/libcbcf.pyx":2318 - * raise KeyError('Unknown INFO field: {}'.format(key)) - * - * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: # <<<<<<<<<<<<<< - * raise ValueError('Unable to delete INFO') + /* "pysam/libcbcf.pyx":2705 + * if info and info.vptr: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') != 0: # <<<<<<<<<<<<<< + * yield bcf_info_get_value(self.record, info) * */ - if (unlikely(__pyx_v_bkey == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2318, __pyx_L1_error) - } - __pyx_t_10 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 2318, __pyx_L1_error) - __pyx_t_3 = ((bcf_update_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_10, NULL, 0, __pyx_v_info->type) < 0) != 0); - if (unlikely(__pyx_t_3)) { + __pyx_t_3 = ((strcmp(__pyx_cur_scope->__pyx_v_key, ((char const *)"END")) != 0) != 0); + if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2319 + /* "pysam/libcbcf.pyx":2706 + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') != 0: + * yield bcf_info_get_value(self.record, info) # <<<<<<<<<<<<<< * - * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: - * raise ValueError('Unable to delete INFO') # <<<<<<<<<<<<<< + * def iteritems(self): + */ + __pyx_t_4 = ((PyObject *)__pyx_cur_scope->__pyx_v_self->record); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_info_get_value(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_4), __pyx_cur_scope->__pyx_v_info); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_9; + __pyx_t_9 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_5; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_6; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_7; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L11_resume_from_yield:; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_6 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_7 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2706, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2705 + * if info and info.vptr: + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') != 0: # <<<<<<<<<<<<<< + * yield bcf_info_get_value(self.record, info) * - * def clear(self): */ - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__124, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2319, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_Raise(__pyx_t_7, 0, 0, 0); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __PYX_ERR(0, 2319, __pyx_L1_error) + } - /* "pysam/libcbcf.pyx":2318 - * raise KeyError('Unknown INFO field: {}'.format(key)) - * - * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: # <<<<<<<<<<<<<< - * raise ValueError('Unable to delete INFO') - * + /* "pysam/libcbcf.pyx":2703 + * for i in range(r.n_info): + * info = &r.d.info[i] + * if info and info.vptr: # <<<<<<<<<<<<<< + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + * if strcmp(key, b'END') != 0: */ + } } + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2305 - * bcf_info_set_value(self.record, key, value) + /* "pysam/libcbcf.pyx":2690 + * return iter(self) * - * def __delitem__(self, key): # <<<<<<<<<<<<<< + * def itervalues(self): # <<<<<<<<<<<<<< + * """D.itervalues() -> an iterator over the values of D""" * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ - __pyx_r = 0; + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__delitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_bkey); - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_28generator19(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":2321 - * raise ValueError('Unable to delete INFO') +/* "pysam/libcbcf.pyx":2708 + * yield bcf_info_get_value(self.record, info) * - * def clear(self): # <<<<<<<<<<<<<< - * """Clear all info data""" + * def iteritems(self): # <<<<<<<<<<<<<< + * """D.iteritems() -> an iterator over the (key, value) items of D""" * cdef bcf_hdr_t *hdr = self.record.header.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_13clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_12clear[] = "VariantRecordInfo.clear(self)\nClear all info data"; -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_13clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_27iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_26iteritems[] = "VariantRecordInfo.iteritems(self)\nD.iteritems() -> an iterator over the (key, value) items of D"; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_27iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("clear (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_12clear(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + __Pyx_RefNannySetupContext("iteritems (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_26iteritems(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_12clear(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { - bcf_hdr_t *__pyx_v_hdr; - bcf1_t *__pyx_v_r; - bcf_info_t *__pyx_v_info; - char const *__pyx_v_key; - int __pyx_v_i; +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_26iteritems(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_29_iteritems *__pyx_cur_scope; PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("iteritems", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_29_iteritems *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_29_iteritems(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_29_iteritems, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_29_iteritems *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 2708, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_28generator19, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantRecordInfo_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2708, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_28generator19(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_29_iteritems *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_29_iteritems *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations bcf_hdr_t *__pyx_t_1; bcf1_t *__pyx_t_2; int __pyx_t_3; @@ -38581,53 +44176,65 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_12clear(struct __p uint32_t __pyx_t_6; int __pyx_t_7; int __pyx_t_8; - __Pyx_RefNannySetupContext("clear", 0); - __Pyx_TraceCall("clear", __pyx_f[0], 2321, 0, __PYX_ERR(0, 2321, __pyx_L1_error)); + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("iteritems", 0); + __Pyx_TraceCall("iteritems", __pyx_f[0], 2708, 0, __PYX_ERR(0, 2708, __pyx_L1_error)); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L11_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2708, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2323 - * def clear(self): - * """Clear all info data""" + /* "pysam/libcbcf.pyx":2710 + * def iteritems(self): + * """D.iteritems() -> an iterator over the (key, value) items of D""" * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr * cdef bcf_info_t *info */ - __pyx_t_1 = __pyx_v_self->record->header->ptr; - __pyx_v_hdr = __pyx_t_1; + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; + __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2324 - * """Clear all info data""" + /* "pysam/libcbcf.pyx":2711 + * """D.iteritems() -> an iterator over the (key, value) items of D""" * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< * cdef bcf_info_t *info * cdef const char *key */ - __pyx_t_2 = __pyx_v_self->record->ptr; - __pyx_v_r = __pyx_t_2; + __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; + __pyx_cur_scope->__pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2329 + /* "pysam/libcbcf.pyx":2716 * cdef int i * * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') * */ - __pyx_t_3 = ((bcf_unpack(__pyx_v_r, BCF_UN_INFO) < 0) != 0); + __pyx_t_3 = ((bcf_unpack(__pyx_cur_scope->__pyx_v_r, BCF_UN_INFO) < 0) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2330 + /* "pysam/libcbcf.pyx":2717 * * if bcf_unpack(r, BCF_UN_INFO) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * for i in range(r.n_info): */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__125, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2330, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__132, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2717, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 2330, __pyx_L1_error) + __PYX_ERR(0, 2717, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2329 + /* "pysam/libcbcf.pyx":2716 * cdef int i * * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< @@ -38636,110 +44243,395 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_12clear(struct __p */ } - /* "pysam/libcbcf.pyx":2332 + /* "pysam/libcbcf.pyx":2719 * raise ValueError('Error unpacking VariantRecord') * * for i in range(r.n_info): # <<<<<<<<<<<<<< * info = &r.d.info[i] * if info and info.vptr: */ - __pyx_t_5 = __pyx_v_r->n_info; + __pyx_t_5 = __pyx_cur_scope->__pyx_v_r->n_info; __pyx_t_6 = __pyx_t_5; for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { - __pyx_v_i = __pyx_t_7; + __pyx_cur_scope->__pyx_v_i = __pyx_t_7; - /* "pysam/libcbcf.pyx":2333 + /* "pysam/libcbcf.pyx":2720 * * for i in range(r.n_info): * info = &r.d.info[i] # <<<<<<<<<<<<<< * if info and info.vptr: * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) */ - __pyx_v_info = (&(__pyx_v_r->d.info[__pyx_v_i])); + __pyx_cur_scope->__pyx_v_info = (&(__pyx_cur_scope->__pyx_v_r->d.info[__pyx_cur_scope->__pyx_v_i])); - /* "pysam/libcbcf.pyx":2334 + /* "pysam/libcbcf.pyx":2721 * for i in range(r.n_info): * info = &r.d.info[i] * if info and info.vptr: # <<<<<<<<<<<<<< * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) - * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: + * if strcmp(key, b'END') != 0: */ - __pyx_t_8 = (__pyx_v_info != 0); + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_info != 0); if (__pyx_t_8) { } else { __pyx_t_3 = __pyx_t_8; - goto __pyx_L7_bool_binop_done; + goto __pyx_L8_bool_binop_done; } - __pyx_t_8 = (__pyx_v_info->vptr != 0); + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_info->vptr != 0); __pyx_t_3 = __pyx_t_8; - __pyx_L7_bool_binop_done:; + __pyx_L8_bool_binop_done:; if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2335 + /* "pysam/libcbcf.pyx":2722 * info = &r.d.info[i] * if info and info.vptr: * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) # <<<<<<<<<<<<<< - * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: - * raise ValueError('Unable to delete INFO') + * if strcmp(key, b'END') != 0: + * value = bcf_info_get_value(self.record, info) */ - __pyx_v_key = bcf_hdr_int2id(__pyx_v_hdr, BCF_DT_ID, __pyx_v_info->key); + __pyx_cur_scope->__pyx_v_key = bcf_hdr_int2id(__pyx_cur_scope->__pyx_v_hdr, BCF_DT_ID, __pyx_cur_scope->__pyx_v_info->key); - /* "pysam/libcbcf.pyx":2336 + /* "pysam/libcbcf.pyx":2723 * if info and info.vptr: * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) - * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: # <<<<<<<<<<<<<< - * raise ValueError('Unable to delete INFO') - * + * if strcmp(key, b'END') != 0: # <<<<<<<<<<<<<< + * value = bcf_info_get_value(self.record, info) + * yield bcf_str_cache_get_charptr(key), value */ - __pyx_t_3 = ((bcf_update_info(__pyx_v_hdr, __pyx_v_r, __pyx_v_key, NULL, 0, __pyx_v_info->type) < 0) != 0); - if (unlikely(__pyx_t_3)) { + __pyx_t_3 = ((strcmp(__pyx_cur_scope->__pyx_v_key, ((char const *)"END")) != 0) != 0); + if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2337 + /* "pysam/libcbcf.pyx":2724 * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) - * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: - * raise ValueError('Unable to delete INFO') # <<<<<<<<<<<<<< + * if strcmp(key, b'END') != 0: + * value = bcf_info_get_value(self.record, info) # <<<<<<<<<<<<<< + * yield bcf_str_cache_get_charptr(key), value * - * def __iter__(self): */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__126, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __pyx_t_4 = ((PyObject *)__pyx_cur_scope->__pyx_v_self->record); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_info_get_value(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_4), __pyx_cur_scope->__pyx_v_info); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2724, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 2337, __pyx_L1_error) + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_value); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_value, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":2336 + /* "pysam/libcbcf.pyx":2725 + * if strcmp(key, b'END') != 0: + * value = bcf_info_get_value(self.record, info) + * yield bcf_str_cache_get_charptr(key), value # <<<<<<<<<<<<<< + * + * def keys(self): + */ + __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(__pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2725, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2725, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_value); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_cur_scope->__pyx_v_value); + __pyx_t_9 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_5; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_6; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_7; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L11_resume_from_yield:; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_6 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_7 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2725, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2723 * if info and info.vptr: * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) - * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: # <<<<<<<<<<<<<< - * raise ValueError('Unable to delete INFO') - * + * if strcmp(key, b'END') != 0: # <<<<<<<<<<<<<< + * value = bcf_info_get_value(self.record, info) + * yield bcf_str_cache_get_charptr(key), value */ } - /* "pysam/libcbcf.pyx":2334 + /* "pysam/libcbcf.pyx":2721 * for i in range(r.n_info): * info = &r.d.info[i] * if info and info.vptr: # <<<<<<<<<<<<<< * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) - * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: + * if strcmp(key, b'END') != 0: */ } } + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2321 - * raise ValueError('Unable to delete INFO') + /* "pysam/libcbcf.pyx":2708 + * yield bcf_info_get_value(self.record, info) * - * def clear(self): # <<<<<<<<<<<<<< - * """Clear all info data""" + * def iteritems(self): # <<<<<<<<<<<<<< + * """D.iteritems() -> an iterator over the (key, value) items of D""" * cdef bcf_hdr_t *hdr = self.record.header.ptr */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.clear", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2727 + * yield bcf_str_cache_get_charptr(key), value + * + * def keys(self): # <<<<<<<<<<<<<< + * """D.keys() -> list of D's keys""" + * return list(self) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_30keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_29keys[] = "VariantRecordInfo.keys(self)\nD.keys() -> list of D's keys"; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_30keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("keys (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_29keys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_29keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("keys", 0); + __Pyx_TraceCall("keys", __pyx_f[0], 2727, 0, __PYX_ERR(0, 2727, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2729 + * def keys(self): + * """D.keys() -> list of D's keys""" + * return list(self) # <<<<<<<<<<<<<< + * + * def items(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2729, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2727 + * yield bcf_str_cache_get_charptr(key), value + * + * def keys(self): # <<<<<<<<<<<<<< + * """D.keys() -> list of D's keys""" + * return list(self) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2731 + * return list(self) + * + * def items(self): # <<<<<<<<<<<<<< + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_32items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_31items[] = "VariantRecordInfo.items(self)\nD.items() -> list of D's (key, value) pairs, as 2-tuples"; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_32items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("items (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_31items(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_31items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("items", 0); + __Pyx_TraceCall("items", __pyx_f[0], 2731, 0, __PYX_ERR(0, 2731, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2733 + * def items(self): + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) # <<<<<<<<<<<<<< + * + * def values(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2733, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2733, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2733, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2733, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2731 + * return list(self) + * + * def items(self): # <<<<<<<<<<<<<< + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.items", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2735 + * return list(self.iteritems()) + * + * def values(self): # <<<<<<<<<<<<<< + * """D.values() -> list of D's values""" + * return list(self.itervalues()) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_34values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_33values[] = "VariantRecordInfo.values(self)\nD.values() -> list of D's values"; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_34values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("values (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_33values(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_33values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("values", 0); + __Pyx_TraceCall("values", __pyx_f[0], 2735, 0, __PYX_ERR(0, 2735, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2737 + * def values(self): + * """D.values() -> list of D's values""" + * return list(self.itervalues()) # <<<<<<<<<<<<<< + * + * def update(self, items=None, **kwargs): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2737, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2737, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2737, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2737, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2735 + * return list(self.iteritems()) + * + * def values(self): # <<<<<<<<<<<<<< + * """D.values() -> list of D's values""" + * return list(self.itervalues()) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.values", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -38747,231 +44639,449 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_12clear(struct __p __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_16generator17(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":2339 - * raise ValueError('Unable to delete INFO') +/* "pysam/libcbcf.pyx":2739 + * return list(self.itervalues()) + * + * def update(self, items=None, **kwargs): # <<<<<<<<<<<<<< + * """D.update([E, ]**F) -> None. * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_15__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_15__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_36update(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_35update[] = "VariantRecordInfo.update(self, items=None, **kwargs)\nD.update([E, ]**F) -> None.\n\n Update D from dict/iterable E and F.\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_36update(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_items = 0; + PyObject *__pyx_v_kwargs = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_14__iter__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + __Pyx_RefNannySetupContext("update (wrapper)", 0); + __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,0}; + PyObject* values[1] = {0}; + values[0] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "update") < 0)) __PYX_ERR(0, 2739, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_items = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("update", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2739, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.update", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35update(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), __pyx_v_items, __pyx_v_kwargs); /* function exit code */ + __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_14__iter__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_27___iter__ *__pyx_cur_scope; +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35update(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_items, PyObject *__pyx_v_kwargs) { + PyObject *__pyx_v_k = NULL; + PyObject *__pyx_v_v = NULL; PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_27___iter__ *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_27___iter__(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_27___iter__, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_27___iter__ *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2339, __pyx_L1_error) + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + __Pyx_RefNannySetupContext("update", 0); + __Pyx_TraceCall("update", __pyx_f[0], 2739, 0, __PYX_ERR(0, 2739, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2744 + * Update D from dict/iterable E and F. + * """ + * for k, v in items.items(): # <<<<<<<<<<<<<< + * if k != 'END': + * self[k] = v + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_items, __pyx_n_s_items); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2744, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __Pyx_GOTREF(__pyx_cur_scope); + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2744, __pyx_L1_error) } - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_16generator17, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantRecordInfo___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2339, __pyx_L1_error) - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2744, __pyx_L1_error) } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2744, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2744, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_5(__pyx_t_2); + if (unlikely(!__pyx_t_1)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2744, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 2744, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 2744, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2744, __pyx_L1_error) + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_6); + __pyx_t_6 = 0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2745 + * """ + * for k, v in items.items(): + * if k != 'END': # <<<<<<<<<<<<<< + * self[k] = v + * + */ + __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_k, __pyx_n_s_END, Py_NE)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 2745, __pyx_L1_error) + if (__pyx_t_9) { -static PyObject *__pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_16generator17(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_27___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_27___iter__ *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - bcf_hdr_t *__pyx_t_1; - bcf1_t *__pyx_t_2; - uint32_t __pyx_t_3; - uint32_t __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 2339, 0, __PYX_ERR(0, 2339, __pyx_L1_error)); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L9_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return NULL; - } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2339, __pyx_L1_error) + /* "pysam/libcbcf.pyx":2746 + * for k, v in items.items(): + * if k != 'END': + * self[k] = v # <<<<<<<<<<<<<< + * + * if kwargs: + */ + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_k, __pyx_v_v) < 0)) __PYX_ERR(0, 2746, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2340 + /* "pysam/libcbcf.pyx":2745 + * """ + * for k, v in items.items(): + * if k != 'END': # <<<<<<<<<<<<<< + * self[k] = v * - * def __iter__(self): - * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< - * cdef bcf1_t *r = self.record.ptr - * cdef bcf_info_t *info */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; - __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; + } - /* "pysam/libcbcf.pyx":2341 - * def __iter__(self): - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef bcf_info_t *info - * cdef int i + /* "pysam/libcbcf.pyx":2744 + * Update D from dict/iterable E and F. + * """ + * for k, v in items.items(): # <<<<<<<<<<<<<< + * if k != 'END': + * self[k] = v */ - __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; - __pyx_cur_scope->__pyx_v_r = __pyx_t_2; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":2345 - * cdef int i + /* "pysam/libcbcf.pyx":2748 + * self[k] = v * - * for i in range(r.n_info): # <<<<<<<<<<<<<< - * info = &r.d.info[i] - * if info and info.vptr: + * if kwargs: # <<<<<<<<<<<<<< + * kwargs.pop('END', None) + * for k, v in kwargs.items(): */ - __pyx_t_3 = __pyx_cur_scope->__pyx_v_r->n_info; - __pyx_t_4 = __pyx_t_3; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_5; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_kwargs); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 2748, __pyx_L1_error) + if (__pyx_t_9) { - /* "pysam/libcbcf.pyx":2346 + /* "pysam/libcbcf.pyx":2749 * - * for i in range(r.n_info): - * info = &r.d.info[i] # <<<<<<<<<<<<<< - * if info and info.vptr: - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, info.key)) + * if kwargs: + * kwargs.pop('END', None) # <<<<<<<<<<<<<< + * for k, v in kwargs.items(): + * self[k] = v */ - __pyx_cur_scope->__pyx_v_info = (&(__pyx_cur_scope->__pyx_v_r->d.info[__pyx_cur_scope->__pyx_v_i])); + __pyx_t_2 = __Pyx_PyDict_Pop(__pyx_v_kwargs, __pyx_n_s_END, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2749, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":2347 - * for i in range(r.n_info): - * info = &r.d.info[i] - * if info and info.vptr: # <<<<<<<<<<<<<< - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, info.key)) + /* "pysam/libcbcf.pyx":2750 + * if kwargs: + * kwargs.pop('END', None) + * for k, v in kwargs.items(): # <<<<<<<<<<<<<< + * self[k] = v * */ - __pyx_t_7 = (__pyx_cur_scope->__pyx_v_info != 0); - if (__pyx_t_7) { + __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; + __pyx_t_5 = NULL; } else { - __pyx_t_6 = __pyx_t_7; - goto __pyx_L7_bool_binop_done; + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2750, __pyx_L1_error) } - __pyx_t_7 = (__pyx_cur_scope->__pyx_v_info->vptr != 0); - __pyx_t_6 = __pyx_t_7; - __pyx_L7_bool_binop_done:; - if (__pyx_t_6) { + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2750, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2750, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2750, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 2750, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_3); + #else + __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 2750, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L12_unpacking_done; + __pyx_L11_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2750, __pyx_L1_error) + __pyx_L12_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2348 - * info = &r.d.info[i] - * if info and info.vptr: - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, info.key)) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2751 + * kwargs.pop('END', None) + * for k, v in kwargs.items(): + * self[k] = v # <<<<<<<<<<<<<< * - * def get(self, key, default=None): + * def pop(self, key, default=_nothing): */ - __pyx_t_8 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_int2id(__pyx_cur_scope->__pyx_v_hdr, BCF_DT_ID, __pyx_cur_scope->__pyx_v_info->key)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2348, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L9_resume_from_yield:; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2348, __pyx_L1_error) + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_k, __pyx_v_v) < 0)) __PYX_ERR(0, 2751, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2347 - * for i in range(r.n_info): - * info = &r.d.info[i] - * if info and info.vptr: # <<<<<<<<<<<<<< - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, info.key)) + /* "pysam/libcbcf.pyx":2750 + * if kwargs: + * kwargs.pop('END', None) + * for k, v in kwargs.items(): # <<<<<<<<<<<<<< + * self[k] = v * */ } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":2748 + * self[k] = v + * + * if kwargs: # <<<<<<<<<<<<<< + * kwargs.pop('END', None) + * for k, v in kwargs.items(): + */ } - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2339 - * raise ValueError('Unable to delete INFO') + /* "pysam/libcbcf.pyx":2739 + * return list(self.itervalues()) + * + * def update(self, items=None, **kwargs): # <<<<<<<<<<<<<< + * """D.update([E, ]**F) -> None. * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.update", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_XDECREF(__pyx_v_k); + __Pyx_XDECREF(__pyx_v_v); + __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2350 - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, info.key)) +/* "pysam/libcbcf.pyx":2753 + * self[k] = v * - * def get(self, key, default=None): # <<<<<<<<<<<<<< - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_18get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_17get[] = "VariantRecordInfo.get(self, key, default=None)\nD.get(k[,d]) -> D[k] if k in D, else d. d defaults to None."; -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_18get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_38pop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_37pop[] = "VariantRecordInfo.pop(self, key, default=_nothing)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_38pop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_key = 0; PyObject *__pyx_v_default = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get (wrapper)", 0); + __Pyx_RefNannySetupContext("pop (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_default,0}; PyObject* values[2] = {0,0}; - values[1] = ((PyObject *)Py_None); + values[1] = __pyx_k__133; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); @@ -38996,7 +45106,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_18get(PyObject *__ } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 2350, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "pop") < 0)) __PYX_ERR(0, 2753, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -39012,182 +45122,27 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_18get(PyObject *__ } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2350, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("pop", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2753, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.get", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_17get(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), __pyx_v_key, __pyx_v_default); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_17get(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - __Pyx_RefNannySetupContext("get", 0); - __Pyx_TraceCall("get", __pyx_f[0], 2350, 0, __PYX_ERR(0, 2350, __pyx_L1_error)); - - /* "pysam/libcbcf.pyx":2352 - * def get(self, key, default=None): - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: # <<<<<<<<<<<<<< - * return self[key] - * except KeyError: - */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); - __Pyx_XGOTREF(__pyx_t_1); - __Pyx_XGOTREF(__pyx_t_2); - __Pyx_XGOTREF(__pyx_t_3); - /*try:*/ { - - /* "pysam/libcbcf.pyx":2353 - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: - * return self[key] # <<<<<<<<<<<<<< - * except KeyError: - * return default - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2353, __pyx_L3_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L7_try_return; - - /* "pysam/libcbcf.pyx":2352 - * def get(self, key, default=None): - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: # <<<<<<<<<<<<<< - * return self[key] - * except KeyError: - */ - } - __pyx_L3_error:; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pysam/libcbcf.pyx":2354 - * try: - * return self[key] - * except KeyError: # <<<<<<<<<<<<<< - * return default - * - */ - __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); - if (__pyx_t_5) { - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 2354, __pyx_L5_except_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); - - /* "pysam/libcbcf.pyx":2355 - * return self[key] - * except KeyError: - * return default # <<<<<<<<<<<<<< - * - * def __contains__(self, key): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_default); - __pyx_r = __pyx_v_default; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L6_except_return; - } - goto __pyx_L5_except_error; - __pyx_L5_except_error:; - - /* "pysam/libcbcf.pyx":2352 - * def get(self, key, default=None): - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: # <<<<<<<<<<<<<< - * return self[key] - * except KeyError: - */ - __Pyx_XGIVEREF(__pyx_t_1); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); - goto __pyx_L1_error; - __pyx_L7_try_return:; - __Pyx_XGIVEREF(__pyx_t_1); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); - goto __pyx_L0; - __pyx_L6_except_return:; - __Pyx_XGIVEREF(__pyx_t_1); - __Pyx_XGIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_3); - __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); - goto __pyx_L0; - } - - /* "pysam/libcbcf.pyx":2350 - * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, info.key)) - * - * def get(self, key, default=None): # <<<<<<<<<<<<<< - * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - * try: - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcbcf.pyx":2357 - * return default - * - * def __contains__(self, key): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr - */ - -/* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_20__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_20__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_19__contains__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_37pop(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), __pyx_v_key, __pyx_v_default); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_19__contains__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_key) { +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_37pop(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default) { bcf_hdr_t *__pyx_v_hdr; bcf1_t *__pyx_v_r; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; bcf_info_t *__pyx_v_info; - int __pyx_r; + int __pyx_v_info_id; + PyObject *__pyx_v_value = NULL; + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; @@ -39195,12 +45150,19 @@ static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_19__contains__(struct __ int __pyx_t_3; PyObject *__pyx_t_4 = NULL; char const *__pyx_t_5; - __Pyx_RefNannySetupContext("__contains__", 0); - __Pyx_TraceCall("__contains__", __pyx_f[0], 2357, 0, __PYX_ERR(0, 2357, __pyx_L1_error)); + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + char const *__pyx_t_12; + __Pyx_RefNannySetupContext("pop", 0); + __Pyx_TraceCall("pop", __pyx_f[0], 2753, 0, __PYX_ERR(0, 2753, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2358 + /* "pysam/libcbcf.pyx":2754 * - * def __contains__(self, key): + * def pop(self, key, default=_nothing): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr * @@ -39208,8 +45170,8 @@ static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_19__contains__(struct __ __pyx_t_1 = __pyx_v_self->record->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2359 - * def __contains__(self, key): + /* "pysam/libcbcf.pyx":2755 + * def pop(self, key, default=_nothing): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< * @@ -39218,7 +45180,7 @@ static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_19__contains__(struct __ __pyx_t_2 = __pyx_v_self->record->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2361 + /* "pysam/libcbcf.pyx":2757 * cdef bcf1_t *r = self.record.ptr * * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< @@ -39228,20 +45190,20 @@ static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_19__contains__(struct __ __pyx_t_3 = ((bcf_unpack(__pyx_v_r, BCF_UN_INFO) < 0) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2362 + /* "pysam/libcbcf.pyx":2758 * * if bcf_unpack(r, BCF_UN_INFO) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__127, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2362, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__134, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2758, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 2362, __pyx_L1_error) + __PYX_ERR(0, 2758, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2361 + /* "pysam/libcbcf.pyx":2757 * cdef bcf1_t *r = self.record.ptr * * if bcf_unpack(r, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< @@ -39250,798 +45212,617 @@ static int __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_19__contains__(struct __ */ } - /* "pysam/libcbcf.pyx":2364 + /* "pysam/libcbcf.pyx":2760 * raise ValueError('Error unpacking VariantRecord') * - * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) * */ - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2364, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2760, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_bkey = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2365 + /* "pysam/libcbcf.pyx":2761 * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) # <<<<<<<<<<<<<< * - * return info != NULL + * # Cannot stop here if info == NULL, since flags must return False */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2365, __pyx_L1_error) + __PYX_ERR(0, 2761, __pyx_L1_error) } - __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 2365, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 2761, __pyx_L1_error) __pyx_v_info = bcf_get_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_5); - /* "pysam/libcbcf.pyx":2367 - * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) + /* "pysam/libcbcf.pyx":2764 * - * return info != NULL # <<<<<<<<<<<<<< + * # Cannot stop here if info == NULL, since flags must return False + * cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key # <<<<<<<<<<<<<< * - * def iterkeys(self): + * if info_id < 0: */ - __pyx_r = (__pyx_v_info != NULL); - goto __pyx_L0; + if (((!(__pyx_v_info != 0)) != 0)) { + __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_header_get_info_id(__pyx_v_hdr, __pyx_v_bkey); if (unlikely(__pyx_t_7 == ((int)-2) && PyErr_Occurred())) __PYX_ERR(0, 2764, __pyx_L1_error) + __pyx_t_6 = __pyx_t_7; + } else { + __pyx_t_6 = __pyx_v_info->key; + } + __pyx_v_info_id = __pyx_t_6; - /* "pysam/libcbcf.pyx":2357 - * return default + /* "pysam/libcbcf.pyx":2766 + * cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key * - * def __contains__(self, key): # <<<<<<<<<<<<<< - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr + * if info_id < 0: # <<<<<<<<<<<<<< + * if default is _nothing: + * raise KeyError('Unknown INFO field: {}'.format(key)) */ + __pyx_t_3 = ((__pyx_v_info_id < 0) != 0); + if (__pyx_t_3) { - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_bkey); - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcbcf.pyx":2369 - * return info != NULL + /* "pysam/libcbcf.pyx":2767 * - * def iterkeys(self): # <<<<<<<<<<<<<< - * """D.iterkeys() -> an iterator over the keys of D""" - * return iter(self) + * if info_id < 0: + * if default is _nothing: # <<<<<<<<<<<<<< + * raise KeyError('Unknown INFO field: {}'.format(key)) + * return default */ + __pyx_t_3 = (__pyx_v_default == __pyx_v_5pysam_7libcbcf__nothing); + __pyx_t_8 = (__pyx_t_3 != 0); + if (unlikely(__pyx_t_8)) { -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_22iterkeys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_21iterkeys[] = "VariantRecordInfo.iterkeys(self)\nD.iterkeys() -> an iterator over the keys of D"; -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_22iterkeys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("iterkeys (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_21iterkeys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_21iterkeys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("iterkeys", 0); - __Pyx_TraceCall("iterkeys", __pyx_f[0], 2369, 0, __PYX_ERR(0, 2369, __pyx_L1_error)); - - /* "pysam/libcbcf.pyx":2371 - * def iterkeys(self): - * """D.iterkeys() -> an iterator over the keys of D""" - * return iter(self) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2768 + * if info_id < 0: + * if default is _nothing: + * raise KeyError('Unknown INFO field: {}'.format(key)) # <<<<<<<<<<<<<< + * return default * - * def itervalues(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2371, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Unknown_INFO_field, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + if (!__pyx_t_10) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2768, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2768, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_key); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2768, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 2768, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2369 - * return info != NULL + /* "pysam/libcbcf.pyx":2767 * - * def iterkeys(self): # <<<<<<<<<<<<<< - * """D.iterkeys() -> an iterator over the keys of D""" - * return iter(self) + * if info_id < 0: + * if default is _nothing: # <<<<<<<<<<<<<< + * raise KeyError('Unknown INFO field: {}'.format(key)) + * return default */ + } - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.iterkeys", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_25generator18(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ - -/* "pysam/libcbcf.pyx":2373 - * return iter(self) + /* "pysam/libcbcf.pyx":2769 + * if default is _nothing: + * raise KeyError('Unknown INFO field: {}'.format(key)) + * return default # <<<<<<<<<<<<<< * - * def itervalues(self): # <<<<<<<<<<<<<< - * """D.itervalues() -> an iterator over the values of D""" - * cdef bcf1_t *r = self.record.ptr - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_24itervalues(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_23itervalues[] = "VariantRecordInfo.itervalues(self)\nD.itervalues() -> an iterator over the values of D"; -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_24itervalues(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("itervalues (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_23itervalues(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_23itervalues(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_28_itervalues *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("itervalues", 0); - __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_28_itervalues *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_28_itervalues(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_28_itervalues, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_28_itervalues *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2373, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_25generator18, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantRecordInfo_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2373, __pyx_L1_error) - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } - - /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_25generator18(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_28_itervalues *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_28_itervalues *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - bcf1_t *__pyx_t_1; - uint32_t __pyx_t_2; - uint32_t __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("itervalues", 0); - __Pyx_TraceCall("itervalues", __pyx_f[0], 2373, 0, __PYX_ERR(0, 2373, __pyx_L1_error)); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L9_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return NULL; - } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2373, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":2375 - * def itervalues(self): - * """D.itervalues() -> an iterator over the values of D""" - * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef bcf_info_t *info - * cdef int i + * if not check_header_id(hdr, BCF_HL_INFO, info_id): */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->ptr; - __pyx_cur_scope->__pyx_v_r = __pyx_t_1; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_default); + __pyx_r = __pyx_v_default; + goto __pyx_L0; - /* "pysam/libcbcf.pyx":2379 - * cdef int i + /* "pysam/libcbcf.pyx":2766 + * cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key * - * for i in range(r.n_info): # <<<<<<<<<<<<<< - * info = &r.d.info[i] - * if info and info.vptr: + * if info_id < 0: # <<<<<<<<<<<<<< + * if default is _nothing: + * raise KeyError('Unknown INFO field: {}'.format(key)) */ - __pyx_t_2 = __pyx_cur_scope->__pyx_v_r->n_info; - __pyx_t_3 = __pyx_t_2; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_4; + } - /* "pysam/libcbcf.pyx":2380 + /* "pysam/libcbcf.pyx":2771 + * return default * - * for i in range(r.n_info): - * info = &r.d.info[i] # <<<<<<<<<<<<<< - * if info and info.vptr: - * yield bcf_info_get_value(self.record, info) - */ - __pyx_cur_scope->__pyx_v_info = (&(__pyx_cur_scope->__pyx_v_r->d.info[__pyx_cur_scope->__pyx_v_i])); - - /* "pysam/libcbcf.pyx":2381 - * for i in range(r.n_info): - * info = &r.d.info[i] - * if info and info.vptr: # <<<<<<<<<<<<<< - * yield bcf_info_get_value(self.record, info) + * if not check_header_id(hdr, BCF_HL_INFO, info_id): # <<<<<<<<<<<<<< + * raise ValueError('Invalid header') * */ - __pyx_t_6 = (__pyx_cur_scope->__pyx_v_info != 0); - if (__pyx_t_6) { - } else { - __pyx_t_5 = __pyx_t_6; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_6 = (__pyx_cur_scope->__pyx_v_info->vptr != 0); - __pyx_t_5 = __pyx_t_6; - __pyx_L7_bool_binop_done:; - if (__pyx_t_5) { + __pyx_t_8 = ((!(__pyx_f_5pysam_7libcbcf_check_header_id(__pyx_v_hdr, BCF_HL_INFO, __pyx_v_info_id) != 0)) != 0); + if (unlikely(__pyx_t_8)) { - /* "pysam/libcbcf.pyx":2382 - * info = &r.d.info[i] - * if info and info.vptr: - * yield bcf_info_get_value(self.record, info) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2772 * - * def iteritems(self): + * if not check_header_id(hdr, BCF_HL_INFO, info_id): + * raise ValueError('Invalid header') # <<<<<<<<<<<<<< + * + * # Handle flags */ - __pyx_t_7 = ((PyObject *)__pyx_cur_scope->__pyx_v_self->record); - __Pyx_INCREF(__pyx_t_7); - __pyx_t_8 = __pyx_f_5pysam_7libcbcf_bcf_info_get_value(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_7), __pyx_cur_scope->__pyx_v_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2382, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L9_resume_from_yield:; - __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2382, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__135, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2772, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 2772, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2381 - * for i in range(r.n_info): - * info = &r.d.info[i] - * if info and info.vptr: # <<<<<<<<<<<<<< - * yield bcf_info_get_value(self.record, info) + /* "pysam/libcbcf.pyx":2771 + * return default + * + * if not check_header_id(hdr, BCF_HL_INFO, info_id): # <<<<<<<<<<<<<< + * raise ValueError('Invalid header') * */ - } } - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2373 - * return iter(self) + /* "pysam/libcbcf.pyx":2775 * - * def itervalues(self): # <<<<<<<<<<<<<< - * """D.itervalues() -> an iterator over the values of D""" - * cdef bcf1_t *r = self.record.ptr - */ - - /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_28generator19(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ - -/* "pysam/libcbcf.pyx":2384 - * yield bcf_info_get_value(self.record, info) + * # Handle flags + * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG and (not info or not info.vptr): # <<<<<<<<<<<<<< + * return * - * def iteritems(self): # <<<<<<<<<<<<<< - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * cdef bcf_hdr_t *hdr = self.record.header.ptr */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_27iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_26iteritems[] = "VariantRecordInfo.iteritems(self)\nD.iteritems() -> an iterator over the (key, value) items of D"; -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_27iteritems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("iteritems (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_26iteritems(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_26iteritems(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_29_iteritems *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("iteritems", 0); - __pyx_cur_scope = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_29_iteritems *)__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_29_iteritems(__pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_29_iteritems, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_29_iteritems *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2384, __pyx_L1_error) + __pyx_t_3 = ((bcf_hdr_id2type(__pyx_v_hdr, BCF_HL_INFO, __pyx_v_info_id) == BCF_HT_FLAG) != 0); + if (__pyx_t_3) { } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_28generator19, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantRecordInfo_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2384, __pyx_L1_error) - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; + __pyx_t_8 = __pyx_t_3; + goto __pyx_L8_bool_binop_done; } - - /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_gb_5pysam_7libcbcf_17VariantRecordInfo_28generator19(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_29_iteritems *__pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_29_iteritems *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - bcf_hdr_t *__pyx_t_1; - bcf1_t *__pyx_t_2; - uint32_t __pyx_t_3; - uint32_t __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("iteritems", 0); - __Pyx_TraceCall("iteritems", __pyx_f[0], 2384, 0, __PYX_ERR(0, 2384, __pyx_L1_error)); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L9_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return NULL; + __pyx_t_3 = ((!(__pyx_v_info != 0)) != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_8 = __pyx_t_3; + goto __pyx_L8_bool_binop_done; } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2384, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":2386 - * def iteritems(self): - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< - * cdef bcf1_t *r = self.record.ptr - * cdef bcf_info_t *info - */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; - __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; - - /* "pysam/libcbcf.pyx":2387 - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef bcf_info_t *info - * cdef int i - */ - __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; - __pyx_cur_scope->__pyx_v_r = __pyx_t_2; + __pyx_t_3 = ((!(__pyx_v_info->vptr != 0)) != 0); + __pyx_t_8 = __pyx_t_3; + __pyx_L8_bool_binop_done:; + if (__pyx_t_8) { - /* "pysam/libcbcf.pyx":2391 - * cdef int i + /* "pysam/libcbcf.pyx":2776 + * # Handle flags + * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG and (not info or not info.vptr): + * return # <<<<<<<<<<<<<< * - * for i in range(r.n_info): # <<<<<<<<<<<<<< - * info = &r.d.info[i] - * if info and info.vptr: + * if not info or not info.vptr: */ - __pyx_t_3 = __pyx_cur_scope->__pyx_v_r->n_info; - __pyx_t_4 = __pyx_t_3; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_5; + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; - /* "pysam/libcbcf.pyx":2392 + /* "pysam/libcbcf.pyx":2775 + * + * # Handle flags + * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG and (not info or not info.vptr): # <<<<<<<<<<<<<< + * return * - * for i in range(r.n_info): - * info = &r.d.info[i] # <<<<<<<<<<<<<< - * if info and info.vptr: - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) - */ - __pyx_cur_scope->__pyx_v_info = (&(__pyx_cur_scope->__pyx_v_r->d.info[__pyx_cur_scope->__pyx_v_i])); - - /* "pysam/libcbcf.pyx":2393 - * for i in range(r.n_info): - * info = &r.d.info[i] - * if info and info.vptr: # <<<<<<<<<<<<<< - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) - * value = bcf_info_get_value(self.record, info) */ - __pyx_t_7 = (__pyx_cur_scope->__pyx_v_info != 0); - if (__pyx_t_7) { - } else { - __pyx_t_6 = __pyx_t_7; - goto __pyx_L7_bool_binop_done; - } - __pyx_t_7 = (__pyx_cur_scope->__pyx_v_info->vptr != 0); - __pyx_t_6 = __pyx_t_7; - __pyx_L7_bool_binop_done:; - if (__pyx_t_6) { + } - /* "pysam/libcbcf.pyx":2394 - * info = &r.d.info[i] - * if info and info.vptr: - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) # <<<<<<<<<<<<<< - * value = bcf_info_get_value(self.record, info) - * yield bcf_str_cache_get_charptr(key), value + /* "pysam/libcbcf.pyx":2778 + * return + * + * if not info or not info.vptr: # <<<<<<<<<<<<<< + * if default is _nothing: + * raise KeyError('Unknown INFO field: {}'.format(key)) */ - __pyx_cur_scope->__pyx_v_key = bcf_hdr_int2id(__pyx_cur_scope->__pyx_v_hdr, BCF_DT_ID, __pyx_cur_scope->__pyx_v_info->key); + __pyx_t_3 = ((!(__pyx_v_info != 0)) != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_8 = __pyx_t_3; + goto __pyx_L12_bool_binop_done; + } + __pyx_t_3 = ((!(__pyx_v_info->vptr != 0)) != 0); + __pyx_t_8 = __pyx_t_3; + __pyx_L12_bool_binop_done:; + if (__pyx_t_8) { - /* "pysam/libcbcf.pyx":2395 - * if info and info.vptr: - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) - * value = bcf_info_get_value(self.record, info) # <<<<<<<<<<<<<< - * yield bcf_str_cache_get_charptr(key), value + /* "pysam/libcbcf.pyx":2779 * + * if not info or not info.vptr: + * if default is _nothing: # <<<<<<<<<<<<<< + * raise KeyError('Unknown INFO field: {}'.format(key)) + * return default */ - __pyx_t_8 = ((PyObject *)__pyx_cur_scope->__pyx_v_self->record); - __Pyx_INCREF(__pyx_t_8); - __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_info_get_value(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_8), __pyx_cur_scope->__pyx_v_info); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2395, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_value); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_value, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_t_9 = 0; + __pyx_t_8 = (__pyx_v_default == __pyx_v_5pysam_7libcbcf__nothing); + __pyx_t_3 = (__pyx_t_8 != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2396 - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) - * value = bcf_info_get_value(self.record, info) - * yield bcf_str_cache_get_charptr(key), value # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2780 + * if not info or not info.vptr: + * if default is _nothing: + * raise KeyError('Unknown INFO field: {}'.format(key)) # <<<<<<<<<<<<<< + * return default * - * def keys(self): */ - __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(__pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2396, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2396, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_value); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_cur_scope->__pyx_v_value); - __pyx_t_9 = 0; - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L9_resume_from_yield:; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2396, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Unknown_INFO_field, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_11) { + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_key); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_key}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2780, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_key}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2780, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + { + __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_11); __pyx_t_11 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_key); + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_10, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2780, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 2780, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2393 - * for i in range(r.n_info): - * info = &r.d.info[i] - * if info and info.vptr: # <<<<<<<<<<<<<< - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) - * value = bcf_info_get_value(self.record, info) + /* "pysam/libcbcf.pyx":2779 + * + * if not info or not info.vptr: + * if default is _nothing: # <<<<<<<<<<<<<< + * raise KeyError('Unknown INFO field: {}'.format(key)) + * return default */ } - } - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2384 - * yield bcf_info_get_value(self.record, info) + /* "pysam/libcbcf.pyx":2781 + * if default is _nothing: + * raise KeyError('Unknown INFO field: {}'.format(key)) + * return default # <<<<<<<<<<<<<< * - * def iteritems(self): # <<<<<<<<<<<<<< - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * cdef bcf_hdr_t *hdr = self.record.header.ptr + * value = bcf_info_get_value(self.record, info) */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_default); + __pyx_r = __pyx_v_default; + goto __pyx_L0; - /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2778 + * return + * + * if not info or not info.vptr: # <<<<<<<<<<<<<< + * if default is _nothing: + * raise KeyError('Unknown INFO field: {}'.format(key)) + */ + } -/* "pysam/libcbcf.pyx":2398 - * yield bcf_str_cache_get_charptr(key), value + /* "pysam/libcbcf.pyx":2783 + * return default * - * def keys(self): # <<<<<<<<<<<<<< - * """D.keys() -> list of D's keys""" - * return list(self) + * value = bcf_info_get_value(self.record, info) # <<<<<<<<<<<<<< + * + * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: */ + __pyx_t_4 = ((PyObject *)__pyx_v_self->record); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_9 = __pyx_f_5pysam_7libcbcf_bcf_info_get_value(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_4), __pyx_v_info); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2783, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_value = __pyx_t_9; + __pyx_t_9 = 0; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_30keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_29keys[] = "VariantRecordInfo.keys(self)\nD.keys() -> list of D's keys"; -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_30keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("keys (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_29keys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + /* "pysam/libcbcf.pyx":2785 + * value = bcf_info_get_value(self.record, info) + * + * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Unable to delete INFO') + * + */ + if (unlikely(__pyx_v_bkey == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 2785, __pyx_L1_error) + } + __pyx_t_12 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 2785, __pyx_L1_error) + __pyx_t_3 = ((bcf_update_info(__pyx_v_hdr, __pyx_v_r, __pyx_t_12, NULL, 0, __pyx_v_info->type) < 0) != 0); + if (unlikely(__pyx_t_3)) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2786 + * + * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: + * raise ValueError('Unable to delete INFO') # <<<<<<<<<<<<<< + * + * return value + */ + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__136, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2786, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 2786, __pyx_L1_error) -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_29keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("keys", 0); - __Pyx_TraceCall("keys", __pyx_f[0], 2398, 0, __PYX_ERR(0, 2398, __pyx_L1_error)); + /* "pysam/libcbcf.pyx":2785 + * value = bcf_info_get_value(self.record, info) + * + * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: # <<<<<<<<<<<<<< + * raise ValueError('Unable to delete INFO') + * + */ + } - /* "pysam/libcbcf.pyx":2400 - * def keys(self): - * """D.keys() -> list of D's keys""" - * return list(self) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2788 + * raise ValueError('Unable to delete INFO') * - * def items(self): + * return value # <<<<<<<<<<<<<< + * + * def __richcmp__(VariantRecordInfo self not None, VariantRecordInfo other not None, int op): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2400, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __Pyx_INCREF(__pyx_v_value); + __pyx_r = __pyx_v_value; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2398 - * yield bcf_str_cache_get_charptr(key), value + /* "pysam/libcbcf.pyx":2753 + * self[k] = v * - * def keys(self): # <<<<<<<<<<<<<< - * """D.keys() -> list of D's keys""" - * return list(self) + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_bkey); + __Pyx_XDECREF(__pyx_v_value); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2402 - * return list(self) +/* "pysam/libcbcf.pyx":2790 + * return value * - * def items(self): # <<<<<<<<<<<<<< - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) + * def __richcmp__(VariantRecordInfo self not None, VariantRecordInfo other not None, int op): # <<<<<<<<<<<<<< + * if op != 2 and op != 3: + * return NotImplemented */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_32items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_31items[] = "VariantRecordInfo.items(self)\nD.items() -> list of D's (key, value) pairs, as 2-tuples"; -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_32items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_40__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_40__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("items (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_31items(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); + if (unlikely(((PyObject *)__pyx_v_self) == Py_None)) { + PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "self"); __PYX_ERR(0, 2790, __pyx_L1_error) + } + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_7libcbcf_VariantRecordInfo, 0, "other", 0))) __PYX_ERR(0, 2790, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_39__richcmp__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), ((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_other), ((int)__pyx_v_op)); /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_31items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_39__richcmp__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_other, int __pyx_v_op) { + CYTHON_UNUSED bcf1_t *__pyx_v_s; + CYTHON_UNUSED bcf1_t *__pyx_v_o; + int __pyx_v_cmp; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + int __pyx_t_1; + bcf1_t *__pyx_t_2; PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("items", 0); - __Pyx_TraceCall("items", __pyx_f[0], 2402, 0, __PYX_ERR(0, 2402, __pyx_L1_error)); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__richcmp__", 0); + __Pyx_TraceCall("__richcmp__", __pyx_f[0], 2790, 0, __PYX_ERR(0, 2790, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2404 - * def items(self): - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2791 + * + * def __richcmp__(VariantRecordInfo self not None, VariantRecordInfo other not None, int op): + * if op != 2 and op != 3: # <<<<<<<<<<<<<< + * return NotImplemented * - * def values(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } + switch (__pyx_v_op) { + case 2: + case 3: + __pyx_t_1 = 0; + break; + default: + __pyx_t_1 = 1; + break; } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2404, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2404, __pyx_L1_error) + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":2792 + * def __richcmp__(VariantRecordInfo self not None, VariantRecordInfo other not None, int op): + * if op != 2 and op != 3: + * return NotImplemented # <<<<<<<<<<<<<< + * + * cdef bcf1_t *s = self.record.ptr + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_builtin_NotImplemented); + __pyx_r = __pyx_builtin_NotImplemented; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2791 + * + * def __richcmp__(VariantRecordInfo self not None, VariantRecordInfo other not None, int op): + * if op != 2 and op != 3: # <<<<<<<<<<<<<< + * return NotImplemented + * + */ } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2404, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - /* "pysam/libcbcf.pyx":2402 - * return list(self) + /* "pysam/libcbcf.pyx":2794 + * return NotImplemented + * + * cdef bcf1_t *s = self.record.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *o = other.record.ptr * - * def items(self): # <<<<<<<<<<<<<< - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) */ + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_s = __pyx_t_2; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.items", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2795 + * + * cdef bcf1_t *s = self.record.ptr + * cdef bcf1_t *o = other.record.ptr # <<<<<<<<<<<<<< + * + * # Cannot use n_info as shortcut logic, since null values may remain + */ + __pyx_t_2 = __pyx_v_other->record->ptr; + __pyx_v_o = __pyx_t_2; -/* "pysam/libcbcf.pyx":2406 - * return list(self.iteritems()) + /* "pysam/libcbcf.pyx":2798 * - * def values(self): # <<<<<<<<<<<<<< - * """D.values() -> list of D's values""" - * return list(self.itervalues()) + * # Cannot use n_info as shortcut logic, since null values may remain + * cdef bint cmp = dict(self) == dict(other) # <<<<<<<<<<<<<< + * + * if op == 3: */ + __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2798, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2798, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2798, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2798, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_cmp = __pyx_t_1; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_34values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_33values[] = "VariantRecordInfo.values(self)\nD.values() -> list of D's values"; -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_34values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("values (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_33values(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + /* "pysam/libcbcf.pyx":2800 + * cdef bint cmp = dict(self) == dict(other) + * + * if op == 3: # <<<<<<<<<<<<<< + * cmp = not cmp + * + */ + __pyx_t_1 = ((__pyx_v_op == 3) != 0); + if (__pyx_t_1) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2801 + * + * if op == 3: + * cmp = not cmp # <<<<<<<<<<<<<< + * + * return cmp + */ + __pyx_v_cmp = (!(__pyx_v_cmp != 0)); -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_33values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("values", 0); - __Pyx_TraceCall("values", __pyx_f[0], 2406, 0, __PYX_ERR(0, 2406, __pyx_L1_error)); + /* "pysam/libcbcf.pyx":2800 + * cdef bint cmp = dict(self) == dict(other) + * + * if op == 3: # <<<<<<<<<<<<<< + * cmp = not cmp + * + */ + } - /* "pysam/libcbcf.pyx":2408 - * def values(self): - * """D.values() -> list of D's values""" - * return list(self.itervalues()) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2803 + * cmp = not cmp + * + * return cmp # <<<<<<<<<<<<<< * * # Mappings are not hashable by default, but subclasses can change this */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2408, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2408, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2408, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2408, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_v_cmp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2803, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2406 - * return list(self.iteritems()) + /* "pysam/libcbcf.pyx":2790 + * return value * - * def values(self): # <<<<<<<<<<<<<< - * """D.values() -> list of D's values""" - * return list(self.itervalues()) + * def __richcmp__(VariantRecordInfo self not None, VariantRecordInfo other not None, int op): # <<<<<<<<<<<<<< + * if op != 2 and op != 3: + * return NotImplemented */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordInfo.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -40057,20 +45838,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_33values(struct __ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_36__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython__[] = "VariantRecordInfo.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_36__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_42__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_41__reduce_cython__[] = "VariantRecordInfo.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_42__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_41__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_41__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self) { int __pyx_v_use_setstate; PyObject *__pyx_v_state = NULL; PyObject *__pyx_v__dict = NULL; @@ -40083,7 +45864,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython_ PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -40092,7 +45873,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython_ * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_v_self->record)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self->record)); @@ -40107,7 +45888,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython_ * if _dict is not None: * state += (_dict,) */ - __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v__dict = __pyx_t_1; __pyx_t_1 = 0; @@ -40130,12 +45911,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython_ * use_setstate = True * else: */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); @@ -40191,9 +45972,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython_ * return __pyx_unpickle_VariantRecordInfo, (type(self), 0xde17f0f, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordInfo); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordInfo); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -40204,7 +45985,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython_ __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); @@ -40237,9 +46018,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython_ */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordInfo); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordInfo); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -40250,7 +46031,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython_ __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); @@ -40293,34 +46074,34 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython_ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_38__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_37__setstate_cython__[] = "VariantRecordInfo.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_38__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_44__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_43__setstate_cython__[] = "VariantRecordInfo.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_44__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_37__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_43__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_37__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_43__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 14, 0, __PYX_ERR(2, 14, __pyx_L1_error)); /* "(tree fragment)":15 * return __pyx_unpickle_VariantRecordInfo, (type(self), 0xde17f0f, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_VariantRecordInfo__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordInfo__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordInfo__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -40345,7 +46126,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_17VariantRecordInfo_37__setstate_cytho return __pyx_r; } -/* "pysam/libcbcf.pyx":2416 +/* "pysam/libcbcf.pyx":2809 * * * cdef VariantRecordInfo makeVariantRecordInfo(VariantRecord record): # <<<<<<<<<<<<<< @@ -40362,33 +46143,33 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_f_5pysam_7libcb int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("makeVariantRecordInfo", 0); - __Pyx_TraceCall("makeVariantRecordInfo", __pyx_f[0], 2416, 0, __PYX_ERR(0, 2416, __pyx_L1_error)); + __Pyx_TraceCall("makeVariantRecordInfo", __pyx_f[0], 2809, 0, __PYX_ERR(0, 2809, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2417 + /* "pysam/libcbcf.pyx":2810 * * cdef VariantRecordInfo makeVariantRecordInfo(VariantRecord record): * if not record: # <<<<<<<<<<<<<< * raise ValueError('invalid VariantRecord') * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_record)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2417, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_record)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2810, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2418 + /* "pysam/libcbcf.pyx":2811 * cdef VariantRecordInfo makeVariantRecordInfo(VariantRecord record): * if not record: * raise ValueError('invalid VariantRecord') # <<<<<<<<<<<<<< * * cdef VariantRecordInfo info = VariantRecordInfo.__new__(VariantRecordInfo) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__128, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2418, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__137, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2811, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2418, __pyx_L1_error) + __PYX_ERR(0, 2811, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2417 + /* "pysam/libcbcf.pyx":2810 * * cdef VariantRecordInfo makeVariantRecordInfo(VariantRecord record): * if not record: # <<<<<<<<<<<<<< @@ -40397,19 +46178,19 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_f_5pysam_7libcb */ } - /* "pysam/libcbcf.pyx":2420 + /* "pysam/libcbcf.pyx":2813 * raise ValueError('invalid VariantRecord') * * cdef VariantRecordInfo info = VariantRecordInfo.__new__(VariantRecordInfo) # <<<<<<<<<<<<<< * info.record = record * */ - __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantRecordInfo(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordInfo), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2420, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantRecordInfo(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordInfo), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2813, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_v_info = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2421 + /* "pysam/libcbcf.pyx":2814 * * cdef VariantRecordInfo info = VariantRecordInfo.__new__(VariantRecordInfo) * info.record = record # <<<<<<<<<<<<<< @@ -40422,7 +46203,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_f_5pysam_7libcb __Pyx_DECREF(((PyObject *)__pyx_v_info->record)); __pyx_v_info->record = __pyx_v_record; - /* "pysam/libcbcf.pyx":2423 + /* "pysam/libcbcf.pyx":2816 * info.record = record * * return info # <<<<<<<<<<<<<< @@ -40434,7 +46215,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_f_5pysam_7libcb __pyx_r = __pyx_v_info; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2416 + /* "pysam/libcbcf.pyx":2809 * * * cdef VariantRecordInfo makeVariantRecordInfo(VariantRecord record): # <<<<<<<<<<<<<< @@ -40455,7 +46236,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *__pyx_f_5pysam_7libcb return __pyx_r; } -/* "pysam/libcbcf.pyx":2428 +/* "pysam/libcbcf.pyx":2821 * cdef class VariantRecordSamples(object): * """mapping from sample index or name to :class:`VariantRecordSample` object.""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -40489,22 +46270,22 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples___init__(CYTHON_UNUSE __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 2428, 0, __PYX_ERR(0, 2428, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 2821, 0, __PYX_ERR(0, 2821, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2429 + /* "pysam/libcbcf.pyx":2822 * """mapping from sample index or name to :class:`VariantRecordSample` object.""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__129, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2429, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__138, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2822, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 2429, __pyx_L1_error) + __PYX_ERR(0, 2822, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2428 + /* "pysam/libcbcf.pyx":2821 * cdef class VariantRecordSamples(object): * """mapping from sample index or name to :class:`VariantRecordSample` object.""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -40522,11 +46303,11 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples___init__(CYTHON_UNUSE return __pyx_r; } -/* "pysam/libcbcf.pyx":2431 +/* "pysam/libcbcf.pyx":2824 * raise TypeError('this class cannot be instantiated from Python') * * def __len__(self): # <<<<<<<<<<<<<< - * return bcf_hdr_nsamples(self.record.header.ptr) + * return self.record.ptr.n_sample # bcf_hdr_nsamples(self.record.header.ptr) * */ @@ -40548,23 +46329,23 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_2__len__(struc __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[0], 2431, 0, __PYX_ERR(0, 2431, __pyx_L1_error)); + __Pyx_TraceCall("__len__", __pyx_f[0], 2824, 0, __PYX_ERR(0, 2824, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2432 + /* "pysam/libcbcf.pyx":2825 * * def __len__(self): - * return bcf_hdr_nsamples(self.record.header.ptr) # <<<<<<<<<<<<<< + * return self.record.ptr.n_sample # bcf_hdr_nsamples(self.record.header.ptr) # <<<<<<<<<<<<<< * * def __bool__(self): */ - __pyx_r = bcf_hdr_nsamples(__pyx_v_self->record->header->ptr); + __pyx_r = __pyx_v_self->record->ptr->n_sample; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2431 + /* "pysam/libcbcf.pyx":2824 * raise TypeError('this class cannot be instantiated from Python') * * def __len__(self): # <<<<<<<<<<<<<< - * return bcf_hdr_nsamples(self.record.header.ptr) + * return self.record.ptr.n_sample # bcf_hdr_nsamples(self.record.header.ptr) * */ @@ -40578,11 +46359,11 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_2__len__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":2434 - * return bcf_hdr_nsamples(self.record.header.ptr) +/* "pysam/libcbcf.pyx":2827 + * return self.record.ptr.n_sample # bcf_hdr_nsamples(self.record.header.ptr) * * def __bool__(self): # <<<<<<<<<<<<<< - * return bcf_hdr_nsamples(self.record.header.ptr) != 0 + * return self.record.ptr.n_sample != 0 # bcf_hdr_nsamples(self.record.header.ptr) != 0 * */ @@ -40604,23 +46385,23 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_4__bool__(struct __py __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 2434, 0, __PYX_ERR(0, 2434, __pyx_L1_error)); + __Pyx_TraceCall("__bool__", __pyx_f[0], 2827, 0, __PYX_ERR(0, 2827, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2435 + /* "pysam/libcbcf.pyx":2828 * * def __bool__(self): - * return bcf_hdr_nsamples(self.record.header.ptr) != 0 # <<<<<<<<<<<<<< + * return self.record.ptr.n_sample != 0 # bcf_hdr_nsamples(self.record.header.ptr) != 0 # <<<<<<<<<<<<<< * * def __getitem__(self, key): */ - __pyx_r = (bcf_hdr_nsamples(__pyx_v_self->record->header->ptr) != 0); + __pyx_r = (__pyx_v_self->record->ptr->n_sample != 0); goto __pyx_L0; - /* "pysam/libcbcf.pyx":2434 - * return bcf_hdr_nsamples(self.record.header.ptr) + /* "pysam/libcbcf.pyx":2827 + * return self.record.ptr.n_sample # bcf_hdr_nsamples(self.record.header.ptr) * * def __bool__(self): # <<<<<<<<<<<<<< - * return bcf_hdr_nsamples(self.record.header.ptr) != 0 + * return self.record.ptr.n_sample != 0 # bcf_hdr_nsamples(self.record.header.ptr) != 0 * */ @@ -40634,8 +46415,8 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_4__bool__(struct __py return __pyx_r; } -/* "pysam/libcbcf.pyx":2437 - * return bcf_hdr_nsamples(self.record.header.ptr) != 0 +/* "pysam/libcbcf.pyx":2830 + * return self.record.ptr.n_sample != 0 # bcf_hdr_nsamples(self.record.header.ptr) != 0 * * def __getitem__(self, key): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.record.header.ptr @@ -40666,66 +46447,70 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_6__getitem__(st __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; bcf1_t *__pyx_t_2; - int __pyx_t_3; + uint32_t __pyx_t_3; int __pyx_t_4; int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - char const *__pyx_t_7; - PyObject *__pyx_t_8 = NULL; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + char const *__pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[0], 2437, 0, __PYX_ERR(0, 2437, __pyx_L1_error)); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 2830, 0, __PYX_ERR(0, 2830, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2438 + /* "pysam/libcbcf.pyx":2831 * * def __getitem__(self, key): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr - * cdef int n = bcf_hdr_nsamples(hdr) + * cdef int n = self.record.ptr.n_sample */ __pyx_t_1 = __pyx_v_self->record->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2439 + /* "pysam/libcbcf.pyx":2832 * def __getitem__(self, key): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef int n = bcf_hdr_nsamples(hdr) + * cdef int n = self.record.ptr.n_sample * cdef int sample_index */ __pyx_t_2 = __pyx_v_self->record->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2440 + /* "pysam/libcbcf.pyx":2833 * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr - * cdef int n = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< + * cdef int n = self.record.ptr.n_sample # <<<<<<<<<<<<<< * cdef int sample_index * cdef vdict_t *d */ - __pyx_v_n = bcf_hdr_nsamples(__pyx_v_hdr); + __pyx_t_3 = __pyx_v_self->record->ptr->n_sample; + __pyx_v_n = __pyx_t_3; - /* "pysam/libcbcf.pyx":2445 + /* "pysam/libcbcf.pyx":2838 * cdef khiter_t k * * if isinstance(key, int): # <<<<<<<<<<<<<< * sample_index = key * else: */ - __pyx_t_3 = PyInt_Check(__pyx_v_key); - __pyx_t_4 = (__pyx_t_3 != 0); - if (__pyx_t_4) { + __pyx_t_4 = PyInt_Check(__pyx_v_key); + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { - /* "pysam/libcbcf.pyx":2446 + /* "pysam/libcbcf.pyx":2839 * * if isinstance(key, int): * sample_index = key # <<<<<<<<<<<<<< * else: * bkey = force_bytes(key) */ - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_v_key); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2446, __pyx_L1_error) - __pyx_v_sample_index = __pyx_t_5; + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_key); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2839, __pyx_L1_error) + __pyx_v_sample_index = __pyx_t_6; - /* "pysam/libcbcf.pyx":2445 + /* "pysam/libcbcf.pyx":2838 * cdef khiter_t k * * if isinstance(key, int): # <<<<<<<<<<<<<< @@ -40735,7 +46520,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_6__getitem__(st goto __pyx_L3; } - /* "pysam/libcbcf.pyx":2448 + /* "pysam/libcbcf.pyx":2841 * sample_index = key * else: * bkey = force_bytes(key) # <<<<<<<<<<<<<< @@ -40743,92 +46528,138 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_6__getitem__(st * if sample_index < 0: */ /*else*/ { - __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_v_bkey = ((PyObject*)__pyx_t_6); - __pyx_t_6 = 0; + __pyx_t_7 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2841, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_v_bkey = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; - /* "pysam/libcbcf.pyx":2449 + /* "pysam/libcbcf.pyx":2842 * else: * bkey = force_bytes(key) * sample_index = bcf_hdr_id2int(hdr, BCF_DT_SAMPLE, bkey) # <<<<<<<<<<<<<< * if sample_index < 0: - * raise KeyError('invalid sample name') + * raise KeyError('invalid sample name: {}'.format(key)) */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2449, __pyx_L1_error) + __PYX_ERR(0, 2842, __pyx_L1_error) } - __pyx_t_7 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 2449, __pyx_L1_error) - __pyx_v_sample_index = bcf_hdr_id2int(__pyx_v_hdr, BCF_DT_SAMPLE, __pyx_t_7); + __pyx_t_8 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 2842, __pyx_L1_error) + __pyx_v_sample_index = bcf_hdr_id2int(__pyx_v_hdr, BCF_DT_SAMPLE, __pyx_t_8); - /* "pysam/libcbcf.pyx":2450 + /* "pysam/libcbcf.pyx":2843 * bkey = force_bytes(key) * sample_index = bcf_hdr_id2int(hdr, BCF_DT_SAMPLE, bkey) * if sample_index < 0: # <<<<<<<<<<<<<< - * raise KeyError('invalid sample name') + * raise KeyError('invalid sample name: {}'.format(key)) * */ - __pyx_t_4 = ((__pyx_v_sample_index < 0) != 0); - if (unlikely(__pyx_t_4)) { + __pyx_t_5 = ((__pyx_v_sample_index < 0) != 0); + if (unlikely(__pyx_t_5)) { - /* "pysam/libcbcf.pyx":2451 + /* "pysam/libcbcf.pyx":2844 * sample_index = bcf_hdr_id2int(hdr, BCF_DT_SAMPLE, bkey) * if sample_index < 0: - * raise KeyError('invalid sample name') # <<<<<<<<<<<<<< + * raise KeyError('invalid sample name: {}'.format(key)) # <<<<<<<<<<<<<< * * if sample_index < 0 or sample_index >= n: */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__130, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2451, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 2451, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_sample_name, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2844, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + if (!__pyx_t_10) { + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_key); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2844, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2844, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2844, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2844, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_key); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2844, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2844, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 2844, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2450 + /* "pysam/libcbcf.pyx":2843 * bkey = force_bytes(key) * sample_index = bcf_hdr_id2int(hdr, BCF_DT_SAMPLE, bkey) * if sample_index < 0: # <<<<<<<<<<<<<< - * raise KeyError('invalid sample name') + * raise KeyError('invalid sample name: {}'.format(key)) * */ } } __pyx_L3:; - /* "pysam/libcbcf.pyx":2453 - * raise KeyError('invalid sample name') + /* "pysam/libcbcf.pyx":2846 + * raise KeyError('invalid sample name: {}'.format(key)) * * if sample_index < 0 or sample_index >= n: # <<<<<<<<<<<<<< * raise IndexError('invalid sample index') * */ - __pyx_t_3 = ((__pyx_v_sample_index < 0) != 0); - if (!__pyx_t_3) { + __pyx_t_4 = ((__pyx_v_sample_index < 0) != 0); + if (!__pyx_t_4) { } else { - __pyx_t_4 = __pyx_t_3; + __pyx_t_5 = __pyx_t_4; goto __pyx_L6_bool_binop_done; } - __pyx_t_3 = ((__pyx_v_sample_index >= __pyx_v_n) != 0); - __pyx_t_4 = __pyx_t_3; + __pyx_t_4 = ((__pyx_v_sample_index >= __pyx_v_n) != 0); + __pyx_t_5 = __pyx_t_4; __pyx_L6_bool_binop_done:; - if (unlikely(__pyx_t_4)) { + if (unlikely(__pyx_t_5)) { - /* "pysam/libcbcf.pyx":2454 + /* "pysam/libcbcf.pyx":2847 * * if sample_index < 0 or sample_index >= n: * raise IndexError('invalid sample index') # <<<<<<<<<<<<<< * * return makeVariantRecordSample(self.record, sample_index) */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__131, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 2454, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__139, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2847, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 2847, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2453 - * raise KeyError('invalid sample name') + /* "pysam/libcbcf.pyx":2846 + * raise KeyError('invalid sample name: {}'.format(key)) * * if sample_index < 0 or sample_index >= n: # <<<<<<<<<<<<<< * raise IndexError('invalid sample index') @@ -40836,7 +46667,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_6__getitem__(st */ } - /* "pysam/libcbcf.pyx":2456 + /* "pysam/libcbcf.pyx":2849 * raise IndexError('invalid sample index') * * return makeVariantRecordSample(self.record, sample_index) # <<<<<<<<<<<<<< @@ -40844,17 +46675,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_6__getitem__(st * def __iter__(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_6 = ((PyObject *)__pyx_v_self->record); - __Pyx_INCREF(__pyx_t_6); - __pyx_t_8 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordSample(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_6), __pyx_v_sample_index)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2456, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_r = __pyx_t_8; - __pyx_t_8 = 0; + __pyx_t_9 = ((PyObject *)__pyx_v_self->record); + __Pyx_INCREF(__pyx_t_9); + __pyx_t_7 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordSample(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_9), __pyx_v_sample_index)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2849, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2437 - * return bcf_hdr_nsamples(self.record.header.ptr) != 0 + /* "pysam/libcbcf.pyx":2830 + * return self.record.ptr.n_sample != 0 # bcf_hdr_nsamples(self.record.header.ptr) != 0 * * def __getitem__(self, key): # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr = self.record.header.ptr @@ -40863,8 +46694,10 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_6__getitem__(st /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -40876,7 +46709,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_6__getitem__(st } static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_10generator20(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":2458 +/* "pysam/libcbcf.pyx":2851 * return makeVariantRecordSample(self.record, sample_index) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -40906,7 +46739,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_8__iter__(struc if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_30___iter__ *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2458, __pyx_L1_error) + __PYX_ERR(0, 2851, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -40914,7 +46747,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_8__iter__(struc __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_10generator20, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantRecordSamples___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2458, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_10generator20, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantRecordSamples___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2851, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -40937,13 +46770,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_10generator20(_ __Pyx_TraceDeclarations bcf_hdr_t *__pyx_t_1; bcf1_t *__pyx_t_2; - int32_t __pyx_t_3; + uint32_t __pyx_t_3; int32_t __pyx_t_4; int32_t __pyx_t_5; - PyObject *__pyx_t_6 = NULL; + int32_t __pyx_t_6; + PyObject *__pyx_t_7 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 2458, 0, __PYX_ERR(0, 2458, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 2851, 0, __PYX_ERR(0, 2851, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -40953,63 +46787,64 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_10generator20(_ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2458, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2851, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2459 + /* "pysam/libcbcf.pyx":2852 * * def __iter__(self): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr - * cdef int32_t i, n = bcf_hdr_nsamples(hdr) + * cdef int32_t i, n = self.record.ptr.n_sample */ __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2460 + /* "pysam/libcbcf.pyx":2853 * def __iter__(self): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef int32_t i, n = bcf_hdr_nsamples(hdr) + * cdef int32_t i, n = self.record.ptr.n_sample * */ __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; __pyx_cur_scope->__pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2461 + /* "pysam/libcbcf.pyx":2854 * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr - * cdef int32_t i, n = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< + * cdef int32_t i, n = self.record.ptr.n_sample # <<<<<<<<<<<<<< * * for i in range(n): */ - __pyx_cur_scope->__pyx_v_n = bcf_hdr_nsamples(__pyx_cur_scope->__pyx_v_hdr); + __pyx_t_3 = __pyx_cur_scope->__pyx_v_self->record->ptr->n_sample; + __pyx_cur_scope->__pyx_v_n = __pyx_t_3; - /* "pysam/libcbcf.pyx":2463 - * cdef int32_t i, n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":2856 + * cdef int32_t i, n = self.record.ptr.n_sample * * for i in range(n): # <<<<<<<<<<<<<< * yield charptr_to_str(hdr.samples[i]) * */ - __pyx_t_3 = __pyx_cur_scope->__pyx_v_n; - __pyx_t_4 = __pyx_t_3; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_5; + __pyx_t_4 = __pyx_cur_scope->__pyx_v_n; + __pyx_t_5 = __pyx_t_4; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_6; - /* "pysam/libcbcf.pyx":2464 + /* "pysam/libcbcf.pyx":2857 * * for i in range(n): * yield charptr_to_str(hdr.samples[i]) # <<<<<<<<<<<<<< * * def get(self, key, default=None): */ - __pyx_t_6 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_v_hdr->samples[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2464, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_r = __pyx_t_6; - __pyx_t_6 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; + __pyx_t_7 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_v_hdr->samples[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2857, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_5; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_6; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); @@ -41018,14 +46853,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_10generator20(_ __pyx_generator->resume_label = 1; return __pyx_r; __pyx_L6_resume_from_yield:; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2464, __pyx_L1_error) + __pyx_t_4 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_6 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2857, __pyx_L1_error) } CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2458 + /* "pysam/libcbcf.pyx":2851 * return makeVariantRecordSample(self.record, sample_index) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -41037,7 +46872,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_10generator20(_ PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_r = 0; @@ -41049,7 +46884,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_10generator20(_ return __pyx_r; } -/* "pysam/libcbcf.pyx":2466 +/* "pysam/libcbcf.pyx":2859 * yield charptr_to_str(hdr.samples[i]) * * def get(self, key, default=None): # <<<<<<<<<<<<<< @@ -41094,7 +46929,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_12get(PyObject } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 2466, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 2859, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -41110,7 +46945,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_12get(PyObject } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2466, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2859, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.get", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -41135,9 +46970,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_11get(struct __ PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("get", 0); - __Pyx_TraceCall("get", __pyx_f[0], 2466, 0, __PYX_ERR(0, 2466, __pyx_L1_error)); + __Pyx_TraceCall("get", __pyx_f[0], 2859, 0, __PYX_ERR(0, 2859, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2468 + /* "pysam/libcbcf.pyx":2861 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -41153,7 +46988,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_11get(struct __ __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "pysam/libcbcf.pyx":2469 + /* "pysam/libcbcf.pyx":2862 * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: * return self[key] # <<<<<<<<<<<<<< @@ -41161,13 +46996,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_11get(struct __ * return default */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2469, __pyx_L3_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2862, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L7_try_return; - /* "pysam/libcbcf.pyx":2468 + /* "pysam/libcbcf.pyx":2861 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -41178,7 +47013,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_11get(struct __ __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2470 + /* "pysam/libcbcf.pyx":2863 * try: * return self[key] * except KeyError: # <<<<<<<<<<<<<< @@ -41188,12 +47023,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_11get(struct __ __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); if (__pyx_t_5) { __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 2470, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 2863, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcbcf.pyx":2471 + /* "pysam/libcbcf.pyx":2864 * return self[key] * except KeyError: * return default # <<<<<<<<<<<<<< @@ -41211,7 +47046,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_11get(struct __ goto __pyx_L5_except_error; __pyx_L5_except_error:; - /* "pysam/libcbcf.pyx":2468 + /* "pysam/libcbcf.pyx":2861 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -41237,7 +47072,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_11get(struct __ goto __pyx_L0; } - /* "pysam/libcbcf.pyx":2466 + /* "pysam/libcbcf.pyx":2859 * yield charptr_to_str(hdr.samples[i]) * * def get(self, key, default=None): # <<<<<<<<<<<<<< @@ -41259,7 +47094,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_11get(struct __ return __pyx_r; } -/* "pysam/libcbcf.pyx":2473 +/* "pysam/libcbcf.pyx":2866 * return default * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -41291,65 +47126,70 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_13__contains__(struct __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; bcf1_t *__pyx_t_2; - int __pyx_t_3; + uint32_t __pyx_t_3; int __pyx_t_4; int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - char const *__pyx_t_7; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + char const *__pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; __Pyx_RefNannySetupContext("__contains__", 0); - __Pyx_TraceCall("__contains__", __pyx_f[0], 2473, 0, __PYX_ERR(0, 2473, __pyx_L1_error)); + __Pyx_TraceCall("__contains__", __pyx_f[0], 2866, 0, __PYX_ERR(0, 2866, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2474 + /* "pysam/libcbcf.pyx":2867 * * def __contains__(self, key): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr - * cdef int n = bcf_hdr_nsamples(hdr) + * cdef int n = self.record.ptr.n_sample */ __pyx_t_1 = __pyx_v_self->record->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2475 + /* "pysam/libcbcf.pyx":2868 * def __contains__(self, key): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef int n = bcf_hdr_nsamples(hdr) + * cdef int n = self.record.ptr.n_sample * cdef int sample_index */ __pyx_t_2 = __pyx_v_self->record->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2476 + /* "pysam/libcbcf.pyx":2869 * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr - * cdef int n = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< + * cdef int n = self.record.ptr.n_sample # <<<<<<<<<<<<<< * cdef int sample_index * cdef vdict_t *d */ - __pyx_v_n = bcf_hdr_nsamples(__pyx_v_hdr); + __pyx_t_3 = __pyx_v_self->record->ptr->n_sample; + __pyx_v_n = __pyx_t_3; - /* "pysam/libcbcf.pyx":2481 + /* "pysam/libcbcf.pyx":2874 * cdef khiter_t k * * if isinstance(key, int): # <<<<<<<<<<<<<< * sample_index = key * else: */ - __pyx_t_3 = PyInt_Check(__pyx_v_key); - __pyx_t_4 = (__pyx_t_3 != 0); - if (__pyx_t_4) { + __pyx_t_4 = PyInt_Check(__pyx_v_key); + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { - /* "pysam/libcbcf.pyx":2482 + /* "pysam/libcbcf.pyx":2875 * * if isinstance(key, int): * sample_index = key # <<<<<<<<<<<<<< * else: * bkey = force_bytes(key) */ - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_v_key); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2482, __pyx_L1_error) - __pyx_v_sample_index = __pyx_t_5; + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_key); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2875, __pyx_L1_error) + __pyx_v_sample_index = __pyx_t_6; - /* "pysam/libcbcf.pyx":2481 + /* "pysam/libcbcf.pyx":2874 * cdef khiter_t k * * if isinstance(key, int): # <<<<<<<<<<<<<< @@ -41359,7 +47199,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_13__contains__(struct goto __pyx_L3; } - /* "pysam/libcbcf.pyx":2484 + /* "pysam/libcbcf.pyx":2877 * sample_index = key * else: * bkey = force_bytes(key) # <<<<<<<<<<<<<< @@ -41367,74 +47207,120 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_13__contains__(struct * if sample_index < 0: */ /*else*/ { - __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2484, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_v_bkey = ((PyObject*)__pyx_t_6); - __pyx_t_6 = 0; + __pyx_t_7 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2877, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_v_bkey = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; - /* "pysam/libcbcf.pyx":2485 + /* "pysam/libcbcf.pyx":2878 * else: * bkey = force_bytes(key) * sample_index = bcf_hdr_id2int(hdr, BCF_DT_SAMPLE, bkey) # <<<<<<<<<<<<<< * if sample_index < 0: - * raise KeyError('invalid sample name') + * raise KeyError('invalid sample name: {}'.format(key)) */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2485, __pyx_L1_error) + __PYX_ERR(0, 2878, __pyx_L1_error) } - __pyx_t_7 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 2485, __pyx_L1_error) - __pyx_v_sample_index = bcf_hdr_id2int(__pyx_v_hdr, BCF_DT_SAMPLE, __pyx_t_7); + __pyx_t_8 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 2878, __pyx_L1_error) + __pyx_v_sample_index = bcf_hdr_id2int(__pyx_v_hdr, BCF_DT_SAMPLE, __pyx_t_8); - /* "pysam/libcbcf.pyx":2486 + /* "pysam/libcbcf.pyx":2879 * bkey = force_bytes(key) * sample_index = bcf_hdr_id2int(hdr, BCF_DT_SAMPLE, bkey) * if sample_index < 0: # <<<<<<<<<<<<<< - * raise KeyError('invalid sample name') + * raise KeyError('invalid sample name: {}'.format(key)) * */ - __pyx_t_4 = ((__pyx_v_sample_index < 0) != 0); - if (unlikely(__pyx_t_4)) { + __pyx_t_5 = ((__pyx_v_sample_index < 0) != 0); + if (unlikely(__pyx_t_5)) { - /* "pysam/libcbcf.pyx":2487 + /* "pysam/libcbcf.pyx":2880 * sample_index = bcf_hdr_id2int(hdr, BCF_DT_SAMPLE, bkey) * if sample_index < 0: - * raise KeyError('invalid sample name') # <<<<<<<<<<<<<< + * raise KeyError('invalid sample name: {}'.format(key)) # <<<<<<<<<<<<<< * * return 0 <= sample_index < n */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__132, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 2487, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_sample_name, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + if (!__pyx_t_10) { + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_key); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2880, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_key}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2880, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_key); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 2880, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2486 + /* "pysam/libcbcf.pyx":2879 * bkey = force_bytes(key) * sample_index = bcf_hdr_id2int(hdr, BCF_DT_SAMPLE, bkey) * if sample_index < 0: # <<<<<<<<<<<<<< - * raise KeyError('invalid sample name') + * raise KeyError('invalid sample name: {}'.format(key)) * */ } } __pyx_L3:; - /* "pysam/libcbcf.pyx":2489 - * raise KeyError('invalid sample name') + /* "pysam/libcbcf.pyx":2882 + * raise KeyError('invalid sample name: {}'.format(key)) * * return 0 <= sample_index < n # <<<<<<<<<<<<<< * * def iterkeys(self): */ - __pyx_t_4 = (0 <= __pyx_v_sample_index); - if (__pyx_t_4) { - __pyx_t_4 = (__pyx_v_sample_index < __pyx_v_n); + __pyx_t_5 = (0 <= __pyx_v_sample_index); + if (__pyx_t_5) { + __pyx_t_5 = (__pyx_v_sample_index < __pyx_v_n); } - __pyx_r = __pyx_t_4; + __pyx_r = __pyx_t_5; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2473 + /* "pysam/libcbcf.pyx":2866 * return default * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -41444,7 +47330,10 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_13__contains__(struct /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -41454,7 +47343,7 @@ static int __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_13__contains__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":2491 +/* "pysam/libcbcf.pyx":2884 * return 0 <= sample_index < n * * def iterkeys(self): # <<<<<<<<<<<<<< @@ -41482,9 +47371,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_15iterkeys(stru __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("iterkeys", 0); - __Pyx_TraceCall("iterkeys", __pyx_f[0], 2491, 0, __PYX_ERR(0, 2491, __pyx_L1_error)); + __Pyx_TraceCall("iterkeys", __pyx_f[0], 2884, 0, __PYX_ERR(0, 2884, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2493 + /* "pysam/libcbcf.pyx":2886 * def iterkeys(self): * """D.iterkeys() -> an iterator over the keys of D""" * return iter(self) # <<<<<<<<<<<<<< @@ -41492,13 +47381,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_15iterkeys(stru * def itervalues(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2493, __pyx_L1_error) + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2886, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2491 + /* "pysam/libcbcf.pyx":2884 * return 0 <= sample_index < n * * def iterkeys(self): # <<<<<<<<<<<<<< @@ -41519,7 +47408,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_15iterkeys(stru } static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_19generator21(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":2495 +/* "pysam/libcbcf.pyx":2888 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -41550,7 +47439,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_17itervalues(st if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_31_itervalues *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2495, __pyx_L1_error) + __PYX_ERR(0, 2888, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -41558,7 +47447,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_17itervalues(st __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_19generator21, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantRecordSamples_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2495, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_19generator21, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantRecordSamples_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2888, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -41581,14 +47470,15 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_19generator21(_ __Pyx_TraceDeclarations bcf_hdr_t *__pyx_t_1; bcf1_t *__pyx_t_2; - int32_t __pyx_t_3; + uint32_t __pyx_t_3; int32_t __pyx_t_4; int32_t __pyx_t_5; - PyObject *__pyx_t_6 = NULL; + int32_t __pyx_t_6; PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("itervalues", 0); - __Pyx_TraceCall("itervalues", __pyx_f[0], 2495, 0, __PYX_ERR(0, 2495, __pyx_L1_error)); + __Pyx_TraceCall("itervalues", __pyx_f[0], 2888, 0, __PYX_ERR(0, 2888, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -41598,66 +47488,67 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_19generator21(_ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2495, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2888, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2497 + /* "pysam/libcbcf.pyx":2890 * def itervalues(self): * """D.itervalues() -> an iterator over the values of D""" * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr - * cdef int32_t i, n = bcf_hdr_nsamples(hdr) + * cdef int32_t i, n = self.record.ptr.n_sample */ __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2498 + /* "pysam/libcbcf.pyx":2891 * """D.itervalues() -> an iterator over the values of D""" * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef int32_t i, n = bcf_hdr_nsamples(hdr) + * cdef int32_t i, n = self.record.ptr.n_sample * */ __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; __pyx_cur_scope->__pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2499 + /* "pysam/libcbcf.pyx":2892 * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr - * cdef int32_t i, n = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< + * cdef int32_t i, n = self.record.ptr.n_sample # <<<<<<<<<<<<<< * * for i in range(n): */ - __pyx_cur_scope->__pyx_v_n = bcf_hdr_nsamples(__pyx_cur_scope->__pyx_v_hdr); + __pyx_t_3 = __pyx_cur_scope->__pyx_v_self->record->ptr->n_sample; + __pyx_cur_scope->__pyx_v_n = __pyx_t_3; - /* "pysam/libcbcf.pyx":2501 - * cdef int32_t i, n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":2894 + * cdef int32_t i, n = self.record.ptr.n_sample * * for i in range(n): # <<<<<<<<<<<<<< * yield makeVariantRecordSample(self.record, i) * */ - __pyx_t_3 = __pyx_cur_scope->__pyx_v_n; - __pyx_t_4 = __pyx_t_3; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_5; + __pyx_t_4 = __pyx_cur_scope->__pyx_v_n; + __pyx_t_5 = __pyx_t_4; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_6; - /* "pysam/libcbcf.pyx":2502 + /* "pysam/libcbcf.pyx":2895 * * for i in range(n): * yield makeVariantRecordSample(self.record, i) # <<<<<<<<<<<<<< * * def iteritems(self): */ - __pyx_t_6 = ((PyObject *)__pyx_cur_scope->__pyx_v_self->record); - __Pyx_INCREF(__pyx_t_6); - __pyx_t_7 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordSample(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_6), __pyx_cur_scope->__pyx_v_i)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_r = __pyx_t_7; - __pyx_t_7 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; + __pyx_t_7 = ((PyObject *)__pyx_cur_scope->__pyx_v_self->record); + __Pyx_INCREF(__pyx_t_7); + __pyx_t_8 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordSample(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_7), __pyx_cur_scope->__pyx_v_i)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2895, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_5; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_6; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); @@ -41666,14 +47557,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_19generator21(_ __pyx_generator->resume_label = 1; return __pyx_r; __pyx_L6_resume_from_yield:; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2502, __pyx_L1_error) + __pyx_t_4 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_6 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2895, __pyx_L1_error) } CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2495 + /* "pysam/libcbcf.pyx":2888 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -41685,8 +47576,8 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_19generator21(_ PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("itervalues", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_r = 0; @@ -41699,7 +47590,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_19generator21(_ } static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_22generator22(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":2504 +/* "pysam/libcbcf.pyx":2897 * yield makeVariantRecordSample(self.record, i) * * def iteritems(self): # <<<<<<<<<<<<<< @@ -41730,7 +47621,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_20iteritems(str if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_32_iteritems *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2504, __pyx_L1_error) + __PYX_ERR(0, 2897, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -41738,7 +47629,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_20iteritems(str __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_22generator22, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantRecordSamples_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2504, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_22generator22, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantRecordSamples_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2897, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -41761,15 +47652,16 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_22generator22(_ __Pyx_TraceDeclarations bcf_hdr_t *__pyx_t_1; bcf1_t *__pyx_t_2; - int32_t __pyx_t_3; + uint32_t __pyx_t_3; int32_t __pyx_t_4; int32_t __pyx_t_5; - PyObject *__pyx_t_6 = NULL; + int32_t __pyx_t_6; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("iteritems", 0); - __Pyx_TraceCall("iteritems", __pyx_f[0], 2504, 0, __PYX_ERR(0, 2504, __pyx_L1_error)); + __Pyx_TraceCall("iteritems", __pyx_f[0], 2897, 0, __PYX_ERR(0, 2897, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -41779,351 +47671,1242 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_20VariantRecordSamples_22generator22(_ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2504, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2897, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2506 + /* "pysam/libcbcf.pyx":2899 * def iteritems(self): * """D.iteritems() -> an iterator over the (key, value) items of D""" * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr - * cdef int32_t i, n = bcf_hdr_nsamples(hdr) + * cdef int32_t i, n = self.record.ptr.n_sample */ __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2507 - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef int32_t i, n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":2900 + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< + * cdef int32_t i, n = self.record.ptr.n_sample + * + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; + __pyx_cur_scope->__pyx_v_r = __pyx_t_2; + + /* "pysam/libcbcf.pyx":2901 + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr + * cdef int32_t i, n = self.record.ptr.n_sample # <<<<<<<<<<<<<< + * + * for i in range(n): + */ + __pyx_t_3 = __pyx_cur_scope->__pyx_v_self->record->ptr->n_sample; + __pyx_cur_scope->__pyx_v_n = __pyx_t_3; + + /* "pysam/libcbcf.pyx":2903 + * cdef int32_t i, n = self.record.ptr.n_sample + * + * for i in range(n): # <<<<<<<<<<<<<< + * yield (charptr_to_str(hdr.samples[i]), makeVariantRecordSample(self.record, i)) + * + */ + __pyx_t_4 = __pyx_cur_scope->__pyx_v_n; + __pyx_t_5 = __pyx_t_4; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_6; + + /* "pysam/libcbcf.pyx":2904 + * + * for i in range(n): + * yield (charptr_to_str(hdr.samples[i]), makeVariantRecordSample(self.record, i)) # <<<<<<<<<<<<<< + * + * def keys(self): + */ + __pyx_t_7 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_v_hdr->samples[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2904, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = ((PyObject *)__pyx_cur_scope->__pyx_v_self->record); + __Pyx_INCREF(__pyx_t_8); + __pyx_t_9 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordSample(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_8), __pyx_cur_scope->__pyx_v_i)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2904, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2904, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9); + __pyx_t_7 = 0; + __pyx_t_9 = 0; + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_5; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_6; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_6 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2904, __pyx_L1_error) + } + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); + + /* "pysam/libcbcf.pyx":2897 + * yield makeVariantRecordSample(self.record, i) + * + * def iteritems(self): # <<<<<<<<<<<<<< + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * cdef bcf_hdr_t *hdr = self.record.header.ptr + */ + + /* function exit code */ + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2906 + * yield (charptr_to_str(hdr.samples[i]), makeVariantRecordSample(self.record, i)) + * + * def keys(self): # <<<<<<<<<<<<<< + * """D.keys() -> list of D's keys""" + * return list(self) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_24keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_23keys[] = "VariantRecordSamples.keys(self)\nD.keys() -> list of D's keys"; +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_24keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("keys (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_23keys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_23keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("keys", 0); + __Pyx_TraceCall("keys", __pyx_f[0], 2906, 0, __PYX_ERR(0, 2906, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2908 + * def keys(self): + * """D.keys() -> list of D's keys""" + * return list(self) # <<<<<<<<<<<<<< + * + * def items(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2906 + * yield (charptr_to_str(hdr.samples[i]), makeVariantRecordSample(self.record, i)) + * + * def keys(self): # <<<<<<<<<<<<<< + * """D.keys() -> list of D's keys""" + * return list(self) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2910 + * return list(self) + * + * def items(self): # <<<<<<<<<<<<<< + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_26items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_25items[] = "VariantRecordSamples.items(self)\nD.items() -> list of D's (key, value) pairs, as 2-tuples"; +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_26items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("items (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_25items(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_25items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("items", 0); + __Pyx_TraceCall("items", __pyx_f[0], 2910, 0, __PYX_ERR(0, 2910, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2912 + * def items(self): + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) # <<<<<<<<<<<<<< + * + * def values(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2912, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2912, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2912, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2912, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2910 + * return list(self) + * + * def items(self): # <<<<<<<<<<<<<< + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.items", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2914 + * return list(self.iteritems()) + * + * def values(self): # <<<<<<<<<<<<<< + * """D.values() -> list of D's values""" + * return list(self.itervalues()) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_28values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_27values[] = "VariantRecordSamples.values(self)\nD.values() -> list of D's values"; +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_28values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("values (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_27values(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_27values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("values", 0); + __Pyx_TraceCall("values", __pyx_f[0], 2914, 0, __PYX_ERR(0, 2914, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2916 + * def values(self): + * """D.values() -> list of D's values""" + * return list(self.itervalues()) # <<<<<<<<<<<<<< + * + * def update(self, items=None, **kwargs): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2916, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2916, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2916, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2916, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2914 + * return list(self.iteritems()) + * + * def values(self): # <<<<<<<<<<<<<< + * """D.values() -> list of D's values""" + * return list(self.itervalues()) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":2918 + * return list(self.itervalues()) + * + * def update(self, items=None, **kwargs): # <<<<<<<<<<<<<< + * """D.update([E, ]**F) -> None. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_30update(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_29update[] = "VariantRecordSamples.update(self, items=None, **kwargs)\nD.update([E, ]**F) -> None.\n\n Update D from dict/iterable E and F.\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_30update(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_items = 0; + PyObject *__pyx_v_kwargs = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("update (wrapper)", 0); + __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,0}; + PyObject* values[1] = {0}; + values[0] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "update") < 0)) __PYX_ERR(0, 2918, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_items = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("update", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2918, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.update", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29update(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self), __pyx_v_items, __pyx_v_kwargs); + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29update(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self, PyObject *__pyx_v_items, PyObject *__pyx_v_kwargs) { + PyObject *__pyx_v_k = NULL; + PyObject *__pyx_v_v = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + __Pyx_RefNannySetupContext("update", 0); + __Pyx_TraceCall("update", __pyx_f[0], 2918, 0, __PYX_ERR(0, 2918, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":2923 + * Update D from dict/iterable E and F. + * """ + * for k, v in items.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_items, __pyx_n_s_items); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2923, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2923, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2923, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2923, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2923, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2923, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2923, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2923, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2923, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_5(__pyx_t_2); + if (unlikely(!__pyx_t_1)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2923, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 2923, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2923, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2923, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2923, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 2923, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2923, __pyx_L1_error) + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libcbcf.pyx":2924 + * """ + * for k, v in items.items(): + * self[k] = v # <<<<<<<<<<<<<< + * + * if kwargs: + */ + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_k, __pyx_v_v) < 0)) __PYX_ERR(0, 2924, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":2923 + * Update D from dict/iterable E and F. + * """ + * for k, v in items.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libcbcf.pyx":2926 + * self[k] = v + * + * if kwargs: # <<<<<<<<<<<<<< + * for k, v in kwargs.items(): + * self[k] = v + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_kwargs); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 2926, __pyx_L1_error) + if (__pyx_t_9) { + + /* "pysam/libcbcf.pyx":2927 + * + * if kwargs: + * for k, v in kwargs.items(): # <<<<<<<<<<<<<< + * self[k] = v * */ - __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; - __pyx_cur_scope->__pyx_v_r = __pyx_t_2; + __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2927, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2927, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2927, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 2927, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 2927, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_3); + #else + __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L10_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L10_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 2927, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L11_unpacking_done; + __pyx_L10_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 2927, __pyx_L1_error) + __pyx_L11_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2508 - * cdef bcf_hdr_t *hdr = self.record.header.ptr - * cdef bcf1_t *r = self.record.ptr - * cdef int32_t i, n = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2928 + * if kwargs: + * for k, v in kwargs.items(): + * self[k] = v # <<<<<<<<<<<<<< * - * for i in range(n): + * def pop(self, key, default=_nothing): */ - __pyx_cur_scope->__pyx_v_n = bcf_hdr_nsamples(__pyx_cur_scope->__pyx_v_hdr); + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_k, __pyx_v_v) < 0)) __PYX_ERR(0, 2928, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2510 - * cdef int32_t i, n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":2927 * - * for i in range(n): # <<<<<<<<<<<<<< - * yield (charptr_to_str(hdr.samples[i]), makeVariantRecordSample(self.record, i)) + * if kwargs: + * for k, v in kwargs.items(): # <<<<<<<<<<<<<< + * self[k] = v * */ - __pyx_t_3 = __pyx_cur_scope->__pyx_v_n; - __pyx_t_4 = __pyx_t_3; - for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_5; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":2511 - * - * for i in range(n): - * yield (charptr_to_str(hdr.samples[i]), makeVariantRecordSample(self.record, i)) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2926 + * self[k] = v * - * def keys(self): + * if kwargs: # <<<<<<<<<<<<<< + * for k, v in kwargs.items(): + * self[k] = v */ - __pyx_t_6 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_cur_scope->__pyx_v_hdr->samples[__pyx_cur_scope->__pyx_v_i]), NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2511, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = ((PyObject *)__pyx_cur_scope->__pyx_v_self->record); - __Pyx_INCREF(__pyx_t_7); - __pyx_t_8 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordSample(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_7), __pyx_cur_scope->__pyx_v_i)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2511, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2511, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8); - __pyx_t_6 = 0; - __pyx_t_8 = 0; - __pyx_r = __pyx_t_7; - __pyx_t_7 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2511, __pyx_L1_error) } - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2504 - * yield makeVariantRecordSample(self.record, i) + /* "pysam/libcbcf.pyx":2918 + * return list(self.itervalues()) + * + * def update(self, items=None, **kwargs): # <<<<<<<<<<<<<< + * """D.update([E, ]**F) -> None. * - * def iteritems(self): # <<<<<<<<<<<<<< - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * cdef bcf_hdr_t *hdr = self.record.header.ptr */ /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.update", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_XDECREF(__pyx_v_k); + __Pyx_XDECREF(__pyx_v_v); + __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2513 - * yield (charptr_to_str(hdr.samples[i]), makeVariantRecordSample(self.record, i)) +/* "pysam/libcbcf.pyx":2930 + * self[k] = v * - * def keys(self): # <<<<<<<<<<<<<< - * """D.keys() -> list of D's keys""" - * return list(self) + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * try: + * value = self[key] */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_24keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_23keys[] = "VariantRecordSamples.keys(self)\nD.keys() -> list of D's keys"; -static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_24keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_32pop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_31pop[] = "VariantRecordSamples.pop(self, key, default=_nothing)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_32pop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_key = 0; + PyObject *__pyx_v_default = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("keys (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_23keys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self)); + __Pyx_RefNannySetupContext("pop (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_default,0}; + PyObject* values[2] = {0,0}; + values[1] = __pyx_k__140; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_default); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "pop") < 0)) __PYX_ERR(0, 2930, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_key = values[0]; + __pyx_v_default = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("pop", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2930, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_31pop(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self), __pyx_v_key, __pyx_v_default); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_23keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_31pop(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default) { + PyObject *__pyx_v_value = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("keys", 0); - __Pyx_TraceCall("keys", __pyx_f[0], 2513, 0, __PYX_ERR(0, 2513, __pyx_L1_error)); + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + int __pyx_t_9; + __Pyx_RefNannySetupContext("pop", 0); + __Pyx_TraceCall("pop", __pyx_f[0], 2930, 0, __PYX_ERR(0, 2930, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2515 - * def keys(self): - * """D.keys() -> list of D's keys""" - * return list(self) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2931 * - * def items(self): + * def pop(self, key, default=_nothing): + * try: # <<<<<<<<<<<<<< + * value = self[key] + * del self[key] */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2515, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { - /* "pysam/libcbcf.pyx":2513 - * yield (charptr_to_str(hdr.samples[i]), makeVariantRecordSample(self.record, i)) - * - * def keys(self): # <<<<<<<<<<<<<< - * """D.keys() -> list of D's keys""" - * return list(self) + /* "pysam/libcbcf.pyx":2932 + * def pop(self, key, default=_nothing): + * try: + * value = self[key] # <<<<<<<<<<<<<< + * del self[key] + * return value */ + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2932, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_value = __pyx_t_4; + __pyx_t_4 = 0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2933 + * try: + * value = self[key] + * del self[key] # <<<<<<<<<<<<<< + * return value + * except KeyError: + */ + if (unlikely(PyObject_DelItem(((PyObject *)__pyx_v_self), __pyx_v_key) < 0)) __PYX_ERR(0, 2933, __pyx_L3_error) -/* "pysam/libcbcf.pyx":2517 - * return list(self) + /* "pysam/libcbcf.pyx":2934 + * value = self[key] + * del self[key] + * return value # <<<<<<<<<<<<<< + * except KeyError: + * if default is not _nothing: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_value); + __pyx_r = __pyx_v_value; + goto __pyx_L7_try_return; + + /* "pysam/libcbcf.pyx":2931 * - * def items(self): # <<<<<<<<<<<<<< - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) + * def pop(self, key, default=_nothing): + * try: # <<<<<<<<<<<<<< + * value = self[key] + * del self[key] */ + } + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_26items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_25items[] = "VariantRecordSamples.items(self)\nD.items() -> list of D's (key, value) pairs, as 2-tuples"; -static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_26items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("items (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_25items(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self)); + /* "pysam/libcbcf.pyx":2935 + * del self[key] + * return value + * except KeyError: # <<<<<<<<<<<<<< + * if default is not _nothing: + * return default + */ + __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); + if (__pyx_t_5) { + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 2935, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":2936 + * return value + * except KeyError: + * if default is not _nothing: # <<<<<<<<<<<<<< + * return default + * raise + */ + __pyx_t_8 = (__pyx_v_default != __pyx_v_5pysam_7libcbcf__nothing); + __pyx_t_9 = (__pyx_t_8 != 0); + if (__pyx_t_9) { -static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_25items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("items", 0); - __Pyx_TraceCall("items", __pyx_f[0], 2517, 0, __PYX_ERR(0, 2517, __pyx_L1_error)); + /* "pysam/libcbcf.pyx":2937 + * except KeyError: + * if default is not _nothing: + * return default # <<<<<<<<<<<<<< + * raise + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_default); + __pyx_r = __pyx_v_default; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_except_return; - /* "pysam/libcbcf.pyx":2519 - * def items(self): - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2936 + * return value + * except KeyError: + * if default is not _nothing: # <<<<<<<<<<<<<< + * return default + * raise + */ + } + + /* "pysam/libcbcf.pyx":2938 + * if default is not _nothing: + * return default + * raise # <<<<<<<<<<<<<< * - * def values(self): + * def __richcmp__(VariantRecordSamples self not None, VariantRecordSamples other not None, int op): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2519, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_6, __pyx_t_7); + __pyx_t_4 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0; + __PYX_ERR(0, 2938, __pyx_L5_except_error) } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "pysam/libcbcf.pyx":2931 + * + * def pop(self, key, default=_nothing): + * try: # <<<<<<<<<<<<<< + * value = self[key] + * del self[key] + */ + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L7_try_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + __pyx_L6_except_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2519, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2519, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2519, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - /* "pysam/libcbcf.pyx":2517 - * return list(self) + /* "pysam/libcbcf.pyx":2930 + * self[k] = v * - * def items(self): # <<<<<<<<<<<<<< - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * try: + * value = self[key] */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.items", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_value); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2521 - * return list(self.iteritems()) +/* "pysam/libcbcf.pyx":2940 + * raise * - * def values(self): # <<<<<<<<<<<<<< - * """D.values() -> list of D's values""" - * return list(self.itervalues()) + * def __richcmp__(VariantRecordSamples self not None, VariantRecordSamples other not None, int op): # <<<<<<<<<<<<<< + * if op != 2 and op != 3: + * return NotImplemented */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_28values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_27values[] = "VariantRecordSamples.values(self)\nD.values() -> list of D's values"; -static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_28values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_34__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_34__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("values (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_27values(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); + if (unlikely(((PyObject *)__pyx_v_self) == Py_None)) { + PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "self"); __PYX_ERR(0, 2940, __pyx_L1_error) + } + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_7libcbcf_VariantRecordSamples, 0, "other", 0))) __PYX_ERR(0, 2940, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_33__richcmp__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self), ((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_other), ((int)__pyx_v_op)); /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_27values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_33__richcmp__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_other, int __pyx_v_op) { + bcf1_t *__pyx_v_s; + bcf1_t *__pyx_v_o; + int __pyx_v_cmp; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("values", 0); - __Pyx_TraceCall("values", __pyx_f[0], 2521, 0, __PYX_ERR(0, 2521, __pyx_L1_error)); + int __pyx_t_1; + bcf1_t *__pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("__richcmp__", 0); + __Pyx_TraceCall("__richcmp__", __pyx_f[0], 2940, 0, __PYX_ERR(0, 2940, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2523 - * def values(self): - * """D.values() -> list of D's values""" - * return list(self.itervalues()) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2941 + * + * def __richcmp__(VariantRecordSamples self not None, VariantRecordSamples other not None, int op): + * if op != 2 and op != 3: # <<<<<<<<<<<<<< + * return NotImplemented * - * # Mappings are not hashable by default, but subclasses can change this */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); + switch (__pyx_v_op) { + case 2: + case 3: + __pyx_t_1 = 0; + break; + default: + __pyx_t_1 = 1; + break; + } + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":2942 + * def __richcmp__(VariantRecordSamples self not None, VariantRecordSamples other not None, int op): + * if op != 2 and op != 3: + * return NotImplemented # <<<<<<<<<<<<<< + * + * cdef bcf1_t *s = self.record.ptr + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_builtin_NotImplemented); + __pyx_r = __pyx_builtin_NotImplemented; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":2941 + * + * def __richcmp__(VariantRecordSamples self not None, VariantRecordSamples other not None, int op): + * if op != 2 and op != 3: # <<<<<<<<<<<<<< + * return NotImplemented + * + */ + } + + /* "pysam/libcbcf.pyx":2944 + * return NotImplemented + * + * cdef bcf1_t *s = self.record.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *o = other.record.ptr + * + */ + __pyx_t_2 = __pyx_v_self->record->ptr; + __pyx_v_s = __pyx_t_2; + + /* "pysam/libcbcf.pyx":2945 + * + * cdef bcf1_t *s = self.record.ptr + * cdef bcf1_t *o = other.record.ptr # <<<<<<<<<<<<<< + * + * cdef bint cmp = (s.n_sample == o.n_sample and self.values() == other.values()) + */ + __pyx_t_2 = __pyx_v_other->record->ptr; + __pyx_v_o = __pyx_t_2; + + /* "pysam/libcbcf.pyx":2947 + * cdef bcf1_t *o = other.record.ptr + * + * cdef bint cmp = (s.n_sample == o.n_sample and self.values() == other.values()) # <<<<<<<<<<<<<< + * + * if op == 3: + */ + __pyx_t_3 = ((__pyx_v_s->n_sample == __pyx_v_o->n_sample) != 0); + if (__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2947, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); + __Pyx_DECREF_SET(__pyx_t_5, function); } } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2523, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_6) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2947, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2523, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2947, __pyx_L1_error) } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2523, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_values); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2947, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + if (__pyx_t_7) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2947, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else { + __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2947, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2947, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2947, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_1 = __pyx_t_3; + __pyx_L4_bool_binop_done:; + __pyx_v_cmp = __pyx_t_1; + + /* "pysam/libcbcf.pyx":2949 + * cdef bint cmp = (s.n_sample == o.n_sample and self.values() == other.values()) + * + * if op == 3: # <<<<<<<<<<<<<< + * cmp = not cmp + * + */ + __pyx_t_1 = ((__pyx_v_op == 3) != 0); + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":2950 + * + * if op == 3: + * cmp = not cmp # <<<<<<<<<<<<<< + * + * return cmp + */ + __pyx_v_cmp = (!(__pyx_v_cmp != 0)); + + /* "pysam/libcbcf.pyx":2949 + * cdef bint cmp = (s.n_sample == o.n_sample and self.values() == other.values()) + * + * if op == 3: # <<<<<<<<<<<<<< + * cmp = not cmp + * + */ + } + + /* "pysam/libcbcf.pyx":2952 + * cmp = not cmp + * + * return cmp # <<<<<<<<<<<<<< + * + * # Mappings are not hashable by default, but subclasses can change this + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = __Pyx_PyBool_FromLong(__pyx_v_cmp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2952, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2521 - * return list(self.iteritems()) + /* "pysam/libcbcf.pyx":2940 + * raise * - * def values(self): # <<<<<<<<<<<<<< - * """D.values() -> list of D's values""" - * return list(self.itervalues()) + * def __richcmp__(VariantRecordSamples self not None, VariantRecordSamples other not None, int op): # <<<<<<<<<<<<<< + * if op != 2 and op != 3: + * return NotImplemented */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSamples.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -42139,20 +48922,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_27values(struct */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_30__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cython__[] = "VariantRecordSamples.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_30__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_36__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_35__reduce_cython__[] = "VariantRecordSamples.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_36__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_35__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_35__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self) { int __pyx_v_use_setstate; PyObject *__pyx_v_state = NULL; PyObject *__pyx_v__dict = NULL; @@ -42165,7 +48948,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cyth PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -42174,7 +48957,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cyth * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_v_self->record)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self->record)); @@ -42189,7 +48972,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cyth * if _dict is not None: * state += (_dict,) */ - __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v__dict = __pyx_t_1; __pyx_t_1 = 0; @@ -42212,12 +48995,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cyth * use_setstate = True * else: */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); @@ -42273,9 +49056,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cyth * return __pyx_unpickle_VariantRecordSamples, (type(self), 0xde17f0f, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordSamp); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordSamp); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -42286,7 +49069,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cyth __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); @@ -42319,9 +49102,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cyth */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordSamp); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordSamp); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -42332,7 +49115,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cyth __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); @@ -42375,34 +49158,34 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cyth */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_32__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_31__setstate_cython__[] = "VariantRecordSamples.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_32__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_38__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_37__setstate_cython__[] = "VariantRecordSamples.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_38__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_31__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_37__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_31__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_37__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 14, 0, __PYX_ERR(2, 14, __pyx_L1_error)); /* "(tree fragment)":15 * return __pyx_unpickle_VariantRecordSamples, (type(self), 0xde17f0f, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_VariantRecordSamples__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSamples__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSamples__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -42427,7 +49210,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20VariantRecordSamples_31__setstate_cy return __pyx_r; } -/* "pysam/libcbcf.pyx":2531 +/* "pysam/libcbcf.pyx":2958 * * * cdef VariantRecordSamples makeVariantRecordSamples(VariantRecord record): # <<<<<<<<<<<<<< @@ -42444,33 +49227,33 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_f_5pysam_7li int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("makeVariantRecordSamples", 0); - __Pyx_TraceCall("makeVariantRecordSamples", __pyx_f[0], 2531, 0, __PYX_ERR(0, 2531, __pyx_L1_error)); + __Pyx_TraceCall("makeVariantRecordSamples", __pyx_f[0], 2958, 0, __PYX_ERR(0, 2958, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2532 + /* "pysam/libcbcf.pyx":2959 * * cdef VariantRecordSamples makeVariantRecordSamples(VariantRecord record): * if not record: # <<<<<<<<<<<<<< * raise ValueError('invalid VariantRecord') * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_record)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2532, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_record)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2959, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2533 + /* "pysam/libcbcf.pyx":2960 * cdef VariantRecordSamples makeVariantRecordSamples(VariantRecord record): * if not record: * raise ValueError('invalid VariantRecord') # <<<<<<<<<<<<<< * * cdef VariantRecordSamples samples = VariantRecordSamples.__new__( */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__133, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2533, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__141, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2960, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2533, __pyx_L1_error) + __PYX_ERR(0, 2960, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2532 + /* "pysam/libcbcf.pyx":2959 * * cdef VariantRecordSamples makeVariantRecordSamples(VariantRecord record): * if not record: # <<<<<<<<<<<<<< @@ -42479,19 +49262,19 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_f_5pysam_7li */ } - /* "pysam/libcbcf.pyx":2535 + /* "pysam/libcbcf.pyx":2962 * raise ValueError('invalid VariantRecord') * * cdef VariantRecordSamples samples = VariantRecordSamples.__new__( # <<<<<<<<<<<<<< * VariantRecordSamples) * samples.record = record */ - __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantRecordSamples(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordSamples), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2535, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantRecordSamples(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordSamples), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2962, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_v_samples = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2537 + /* "pysam/libcbcf.pyx":2964 * cdef VariantRecordSamples samples = VariantRecordSamples.__new__( * VariantRecordSamples) * samples.record = record # <<<<<<<<<<<<<< @@ -42504,7 +49287,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_f_5pysam_7li __Pyx_DECREF(((PyObject *)__pyx_v_samples->record)); __pyx_v_samples->record = __pyx_v_record; - /* "pysam/libcbcf.pyx":2539 + /* "pysam/libcbcf.pyx":2966 * samples.record = record * * return samples # <<<<<<<<<<<<<< @@ -42516,7 +49299,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_f_5pysam_7li __pyx_r = __pyx_v_samples; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2531 + /* "pysam/libcbcf.pyx":2958 * * * cdef VariantRecordSamples makeVariantRecordSamples(VariantRecord record): # <<<<<<<<<<<<<< @@ -42537,7 +49320,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *__pyx_f_5pysam_7li return __pyx_r; } -/* "pysam/libcbcf.pyx":2544 +/* "pysam/libcbcf.pyx":2971 * cdef class VariantRecord(object): * """Variant record""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -42571,22 +49354,22 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord___init__(CYTHON_UNUSED struc __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 2544, 0, __PYX_ERR(0, 2544, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 2971, 0, __PYX_ERR(0, 2971, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2545 + /* "pysam/libcbcf.pyx":2972 * """Variant record""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__134, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2545, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__142, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2972, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 2545, __pyx_L1_error) + __PYX_ERR(0, 2972, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2544 + /* "pysam/libcbcf.pyx":2971 * cdef class VariantRecord(object): * """Variant record""" * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -42604,7 +49387,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord___init__(CYTHON_UNUSED struc return __pyx_r; } -/* "pysam/libcbcf.pyx":2547 +/* "pysam/libcbcf.pyx":2974 * raise TypeError('this class cannot be instantiated from Python') * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -42628,9 +49411,9 @@ static void __pyx_pf_5pysam_7libcbcf_13VariantRecord_2__dealloc__(struct __pyx_o __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2547, 0, __PYX_ERR(0, 2547, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2974, 0, __PYX_ERR(0, 2974, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2548 + /* "pysam/libcbcf.pyx":2975 * * def __dealloc__(self): * if self.ptr: # <<<<<<<<<<<<<< @@ -42640,7 +49423,7 @@ static void __pyx_pf_5pysam_7libcbcf_13VariantRecord_2__dealloc__(struct __pyx_o __pyx_t_1 = (__pyx_v_self->ptr != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":2549 + /* "pysam/libcbcf.pyx":2976 * def __dealloc__(self): * if self.ptr: * bcf_destroy1(self.ptr) # <<<<<<<<<<<<<< @@ -42649,7 +49432,7 @@ static void __pyx_pf_5pysam_7libcbcf_13VariantRecord_2__dealloc__(struct __pyx_o */ bcf_destroy1(__pyx_v_self->ptr); - /* "pysam/libcbcf.pyx":2550 + /* "pysam/libcbcf.pyx":2977 * if self.ptr: * bcf_destroy1(self.ptr) * self.ptr = NULL # <<<<<<<<<<<<<< @@ -42658,7 +49441,7 @@ static void __pyx_pf_5pysam_7libcbcf_13VariantRecord_2__dealloc__(struct __pyx_o */ __pyx_v_self->ptr = NULL; - /* "pysam/libcbcf.pyx":2548 + /* "pysam/libcbcf.pyx":2975 * * def __dealloc__(self): * if self.ptr: # <<<<<<<<<<<<<< @@ -42667,7 +49450,7 @@ static void __pyx_pf_5pysam_7libcbcf_13VariantRecord_2__dealloc__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":2547 + /* "pysam/libcbcf.pyx":2974 * raise TypeError('this class cannot be instantiated from Python') * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -42684,7 +49467,7 @@ static void __pyx_pf_5pysam_7libcbcf_13VariantRecord_2__dealloc__(struct __pyx_o __Pyx_RefNannyFinishContext(); } -/* "pysam/libcbcf.pyx":2552 +/* "pysam/libcbcf.pyx":2979 * self.ptr = NULL * * def copy(self): # <<<<<<<<<<<<<< @@ -42713,9 +49496,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4copy(struct __pyx_obj PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("copy", 0); - __Pyx_TraceCall("copy", __pyx_f[0], 2552, 0, __PYX_ERR(0, 2552, __pyx_L1_error)); + __Pyx_TraceCall("copy", __pyx_f[0], 2979, 0, __PYX_ERR(0, 2979, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2554 + /* "pysam/libcbcf.pyx":2981 * def copy(self): * """return a copy of this VariantRecord object""" * return makeVariantRecord(self.header, bcf_dup(self.ptr)) # <<<<<<<<<<<<<< @@ -42725,14 +49508,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4copy(struct __pyx_obj __Pyx_XDECREF(__pyx_r); __pyx_t_1 = ((PyObject *)__pyx_v_self->header); __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_1), bcf_dup(__pyx_v_self->ptr))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2554, __pyx_L1_error) + __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_1), bcf_dup(__pyx_v_self->ptr))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2981, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2552 + /* "pysam/libcbcf.pyx":2979 * self.ptr = NULL * * def copy(self): # <<<<<<<<<<<<<< @@ -42753,7 +49536,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4copy(struct __pyx_obj return __pyx_r; } -/* "pysam/libcbcf.pyx":2556 +/* "pysam/libcbcf.pyx":2983 * return makeVariantRecord(self.header, bcf_dup(self.ptr)) * * def translate(self, VariantHeader dst_header): # <<<<<<<<<<<<<< @@ -42768,7 +49551,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_7translate(PyObject *_ PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("translate (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dst_header), __pyx_ptype_5pysam_7libcbcf_VariantHeader, 1, "dst_header", 0))) __PYX_ERR(0, 2556, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dst_header), __pyx_ptype_5pysam_7libcbcf_VariantHeader, 1, "dst_header", 0))) __PYX_ERR(0, 2983, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_self), ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_v_dst_header)); /* function exit code */ @@ -42798,9 +49581,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py int __pyx_t_9; PyObject *__pyx_t_10 = NULL; __Pyx_RefNannySetupContext("translate", 0); - __Pyx_TraceCall("translate", __pyx_f[0], 2556, 0, __PYX_ERR(0, 2556, __pyx_L1_error)); + __Pyx_TraceCall("translate", __pyx_f[0], 2983, 0, __PYX_ERR(0, 2983, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2557 + /* "pysam/libcbcf.pyx":2984 * * def translate(self, VariantHeader dst_header): * if dst_header is None: # <<<<<<<<<<<<<< @@ -42811,20 +49594,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2558 + /* "pysam/libcbcf.pyx":2985 * def translate(self, VariantHeader dst_header): * if dst_header is None: * raise ValueError('dst_header must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *src_hdr = self.header.ptr */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__135, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2558, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__143, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2985, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2558, __pyx_L1_error) + __PYX_ERR(0, 2985, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2557 + /* "pysam/libcbcf.pyx":2984 * * def translate(self, VariantHeader dst_header): * if dst_header is None: # <<<<<<<<<<<<<< @@ -42833,7 +49616,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py */ } - /* "pysam/libcbcf.pyx":2560 + /* "pysam/libcbcf.pyx":2987 * raise ValueError('dst_header must not be None') * * cdef bcf_hdr_t *src_hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -42843,7 +49626,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py __pyx_t_4 = __pyx_v_self->header->ptr; __pyx_v_src_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":2561 + /* "pysam/libcbcf.pyx":2988 * * cdef bcf_hdr_t *src_hdr = self.header.ptr * cdef bcf_hdr_t *dst_hdr = dst_header.ptr # <<<<<<<<<<<<<< @@ -42853,7 +49636,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py __pyx_t_4 = __pyx_v_dst_header->ptr; __pyx_v_dst_hdr = __pyx_t_4; - /* "pysam/libcbcf.pyx":2563 + /* "pysam/libcbcf.pyx":2990 * cdef bcf_hdr_t *dst_hdr = dst_header.ptr * * if src_hdr != dst_hdr: # <<<<<<<<<<<<<< @@ -42863,7 +49646,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py __pyx_t_2 = ((__pyx_v_src_hdr != __pyx_v_dst_hdr) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":2564 + /* "pysam/libcbcf.pyx":2991 * * if src_hdr != dst_hdr: * if self.ptr.n_sample != bcf_hdr_nsamples(dst_hdr): # <<<<<<<<<<<<<< @@ -42873,7 +49656,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py __pyx_t_2 = ((__pyx_v_self->ptr->n_sample != bcf_hdr_nsamples(__pyx_v_dst_hdr)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2565 + /* "pysam/libcbcf.pyx":2992 * if src_hdr != dst_hdr: * if self.ptr.n_sample != bcf_hdr_nsamples(dst_hdr): * msg = 'Cannot translate record. Number of samples does not match header ({} vs {})' # <<<<<<<<<<<<<< @@ -42883,18 +49666,18 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py __Pyx_INCREF(__pyx_kp_s_Cannot_translate_record_Number_o); __pyx_v_msg = __pyx_kp_s_Cannot_translate_record_Number_o; - /* "pysam/libcbcf.pyx":2566 + /* "pysam/libcbcf.pyx":2993 * if self.ptr.n_sample != bcf_hdr_nsamples(dst_hdr): * msg = 'Cannot translate record. Number of samples does not match header ({} vs {})' * raise ValueError(msg.format(self.ptr.n_sample, bcf_hdr_nsamples(dst_hdr))) # <<<<<<<<<<<<<< * * bcf_translate(dst_hdr, src_hdr, self.ptr) */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_msg, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2566, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_msg, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2993, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->ptr->n_sample); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2566, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->ptr->n_sample); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2993, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyInt_From_int32_t(bcf_hdr_nsamples(__pyx_v_dst_hdr)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2566, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyInt_From_int32_t(bcf_hdr_nsamples(__pyx_v_dst_hdr)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2993, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = NULL; __pyx_t_9 = 0; @@ -42911,7 +49694,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_6, __pyx_t_7}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2566, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2993, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -42921,7 +49704,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_6, __pyx_t_7}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2566, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2993, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -42929,7 +49712,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py } else #endif { - __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2566, __pyx_L1_error) + __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2993, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); if (__pyx_t_8) { __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL; @@ -42940,19 +49723,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_7); __pyx_t_6 = 0; __pyx_t_7 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2566, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2993, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2566, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2993, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 2566, __pyx_L1_error) + __PYX_ERR(0, 2993, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2564 + /* "pysam/libcbcf.pyx":2991 * * if src_hdr != dst_hdr: * if self.ptr.n_sample != bcf_hdr_nsamples(dst_hdr): # <<<<<<<<<<<<<< @@ -42961,16 +49744,29 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py */ } - /* "pysam/libcbcf.pyx":2568 + /* "pysam/libcbcf.pyx":2995 * raise ValueError(msg.format(self.ptr.n_sample, bcf_hdr_nsamples(dst_hdr))) * * bcf_translate(dst_hdr, src_hdr, self.ptr) # <<<<<<<<<<<<<< + * self.header = dst_header * - * @property */ (void)(bcf_translate(__pyx_v_dst_hdr, __pyx_v_src_hdr, __pyx_v_self->ptr)); - /* "pysam/libcbcf.pyx":2563 + /* "pysam/libcbcf.pyx":2996 + * + * bcf_translate(dst_hdr, src_hdr, self.ptr) + * self.header = dst_header # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_INCREF(((PyObject *)__pyx_v_dst_header)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_dst_header)); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = __pyx_v_dst_header; + + /* "pysam/libcbcf.pyx":2990 * cdef bcf_hdr_t *dst_hdr = dst_header.ptr * * if src_hdr != dst_hdr: # <<<<<<<<<<<<<< @@ -42979,7 +49775,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py */ } - /* "pysam/libcbcf.pyx":2556 + /* "pysam/libcbcf.pyx":2983 * return makeVariantRecord(self.header, bcf_dup(self.ptr)) * * def translate(self, VariantHeader dst_header): # <<<<<<<<<<<<<< @@ -43007,7 +49803,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6translate(struct __py return __pyx_r; } -/* "pysam/libcbcf.pyx":2571 +/* "pysam/libcbcf.pyx":2999 * * @property * def rid(self): # <<<<<<<<<<<<<< @@ -43034,9 +49830,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3rid___get__(struct __ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2571, 0, __PYX_ERR(0, 2571, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 2999, 0, __PYX_ERR(0, 2999, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2573 + /* "pysam/libcbcf.pyx":3001 * def rid(self): * """internal reference id number""" * return self.ptr.rid # <<<<<<<<<<<<<< @@ -43044,13 +49840,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3rid___get__(struct __ * @rid.setter */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->rid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2573, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->rid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3001, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2571 + /* "pysam/libcbcf.pyx":2999 * * @property * def rid(self): # <<<<<<<<<<<<<< @@ -43070,7 +49866,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3rid___get__(struct __ return __pyx_r; } -/* "pysam/libcbcf.pyx":2576 +/* "pysam/libcbcf.pyx":3004 * * @rid.setter * def rid(self, value): # <<<<<<<<<<<<<< @@ -43103,9 +49899,9 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3rid_2__set__(struct __pyx_o int __pyx_t_4; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2576, 0, __PYX_ERR(0, 2576, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3004, 0, __PYX_ERR(0, 3004, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2577 + /* "pysam/libcbcf.pyx":3005 * @rid.setter * def rid(self, value): * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -43115,17 +49911,17 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3rid_2__set__(struct __pyx_o __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2578 + /* "pysam/libcbcf.pyx":3006 * def rid(self, value): * cdef bcf_hdr_t *hdr = self.header.ptr * cdef int r = value # <<<<<<<<<<<<<< * if r < 0 or r >= hdr.n[BCF_DT_CTG] or not hdr.id[BCF_DT_CTG][r].val: * raise ValueError('invalid reference id') */ - __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2578, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3006, __pyx_L1_error) __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2579 + /* "pysam/libcbcf.pyx":3007 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef int r = value * if r < 0 or r >= hdr.n[BCF_DT_CTG] or not hdr.id[BCF_DT_CTG][r].val: # <<<<<<<<<<<<<< @@ -43149,20 +49945,20 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3rid_2__set__(struct __pyx_o __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2580 + /* "pysam/libcbcf.pyx":3008 * cdef int r = value * if r < 0 or r >= hdr.n[BCF_DT_CTG] or not hdr.id[BCF_DT_CTG][r].val: * raise ValueError('invalid reference id') # <<<<<<<<<<<<<< * self.ptr.rid = r * */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__136, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2580, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__144, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3008, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 2580, __pyx_L1_error) + __PYX_ERR(0, 3008, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2579 + /* "pysam/libcbcf.pyx":3007 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef int r = value * if r < 0 or r >= hdr.n[BCF_DT_CTG] or not hdr.id[BCF_DT_CTG][r].val: # <<<<<<<<<<<<<< @@ -43171,7 +49967,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3rid_2__set__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":2581 + /* "pysam/libcbcf.pyx":3009 * if r < 0 or r >= hdr.n[BCF_DT_CTG] or not hdr.id[BCF_DT_CTG][r].val: * raise ValueError('invalid reference id') * self.ptr.rid = r # <<<<<<<<<<<<<< @@ -43180,7 +49976,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3rid_2__set__(struct __pyx_o */ __pyx_v_self->ptr->rid = __pyx_v_r; - /* "pysam/libcbcf.pyx":2576 + /* "pysam/libcbcf.pyx":3004 * * @rid.setter * def rid(self, value): # <<<<<<<<<<<<<< @@ -43201,7 +49997,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3rid_2__set__(struct __pyx_o return __pyx_r; } -/* "pysam/libcbcf.pyx":2584 +/* "pysam/libcbcf.pyx":3012 * * @property * def chrom(self): # <<<<<<<<<<<<<< @@ -43234,9 +50030,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom___get__(struct int __pyx_t_4; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2584, 0, __PYX_ERR(0, 2584, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3012, 0, __PYX_ERR(0, 3012, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2586 + /* "pysam/libcbcf.pyx":3014 * def chrom(self): * """chromosome/contig name""" * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -43246,7 +50042,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom___get__(struct __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2587 + /* "pysam/libcbcf.pyx":3015 * """chromosome/contig name""" * cdef bcf_hdr_t *hdr = self.header.ptr * cdef int rid = self.ptr.rid # <<<<<<<<<<<<<< @@ -43256,7 +50052,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom___get__(struct __pyx_t_2 = __pyx_v_self->ptr->rid; __pyx_v_rid = __pyx_t_2; - /* "pysam/libcbcf.pyx":2588 + /* "pysam/libcbcf.pyx":3016 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef int rid = self.ptr.rid * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: # <<<<<<<<<<<<<< @@ -43274,20 +50070,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom___get__(struct __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2589 + /* "pysam/libcbcf.pyx":3017 * cdef int rid = self.ptr.rid * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: * raise ValueError('Invalid header') # <<<<<<<<<<<<<< * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) * */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__137, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2589, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__145, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3017, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 2589, __pyx_L1_error) + __PYX_ERR(0, 3017, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2588 + /* "pysam/libcbcf.pyx":3016 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef int rid = self.ptr.rid * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: # <<<<<<<<<<<<<< @@ -43296,7 +50092,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom___get__(struct */ } - /* "pysam/libcbcf.pyx":2590 + /* "pysam/libcbcf.pyx":3018 * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: * raise ValueError('Invalid header') * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) # <<<<<<<<<<<<<< @@ -43304,13 +50100,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom___get__(struct * @chrom.setter */ __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_id2name(__pyx_v_hdr, __pyx_v_rid)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2590, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_id2name(__pyx_v_hdr, __pyx_v_rid)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3018, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2584 + /* "pysam/libcbcf.pyx":3012 * * @property * def chrom(self): # <<<<<<<<<<<<<< @@ -43330,7 +50126,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom___get__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":2593 +/* "pysam/libcbcf.pyx":3021 * * @chrom.setter * def chrom(self, value): # <<<<<<<<<<<<<< @@ -43363,9 +50159,9 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom_2__set__(struct __pyx int __pyx_t_3; int __pyx_t_4; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2593, 0, __PYX_ERR(0, 2593, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3021, 0, __PYX_ERR(0, 3021, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2594 + /* "pysam/libcbcf.pyx":3022 * @chrom.setter * def chrom(self, value): * cdef vdict_t *d = self.header.ptr.dict[BCF_DT_CTG] # <<<<<<<<<<<<<< @@ -43374,19 +50170,19 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom_2__set__(struct __pyx */ __pyx_v_d = ((vdict_t *)(__pyx_v_self->header->ptr->dict[BCF_DT_CTG])); - /* "pysam/libcbcf.pyx":2595 + /* "pysam/libcbcf.pyx":3023 * def chrom(self, value): * cdef vdict_t *d = self.header.ptr.dict[BCF_DT_CTG] * bchrom = force_bytes(value) # <<<<<<<<<<<<<< * cdef khint_t k = kh_get_vdict(d, bchrom) * if k == kh_end(d): */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2595, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3023, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_bchrom = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":2596 + /* "pysam/libcbcf.pyx":3024 * cdef vdict_t *d = self.header.ptr.dict[BCF_DT_CTG] * bchrom = force_bytes(value) * cdef khint_t k = kh_get_vdict(d, bchrom) # <<<<<<<<<<<<<< @@ -43395,12 +50191,12 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom_2__set__(struct __pyx */ if (unlikely(__pyx_v_bchrom == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2596, __pyx_L1_error) + __PYX_ERR(0, 3024, __pyx_L1_error) } - __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_bchrom); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 2596, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_bchrom); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 3024, __pyx_L1_error) __pyx_v_k = kh_get_vdict(__pyx_v_d, __pyx_t_2); - /* "pysam/libcbcf.pyx":2597 + /* "pysam/libcbcf.pyx":3025 * bchrom = force_bytes(value) * cdef khint_t k = kh_get_vdict(d, bchrom) * if k == kh_end(d): # <<<<<<<<<<<<<< @@ -43410,20 +50206,20 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom_2__set__(struct __pyx __pyx_t_3 = ((__pyx_v_k == kh_end(__pyx_v_d)) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2598 + /* "pysam/libcbcf.pyx":3026 * cdef khint_t k = kh_get_vdict(d, bchrom) * if k == kh_end(d): * raise ValueError('Invalid chromosome/contig') # <<<<<<<<<<<<<< * self.ptr.rid = kh_val_vdict(d, k).id * */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__138, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2598, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__146, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3026, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 2598, __pyx_L1_error) + __PYX_ERR(0, 3026, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2597 + /* "pysam/libcbcf.pyx":3025 * bchrom = force_bytes(value) * cdef khint_t k = kh_get_vdict(d, bchrom) * if k == kh_end(d): # <<<<<<<<<<<<<< @@ -43432,7 +50228,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom_2__set__(struct __pyx */ } - /* "pysam/libcbcf.pyx":2599 + /* "pysam/libcbcf.pyx":3027 * if k == kh_end(d): * raise ValueError('Invalid chromosome/contig') * self.ptr.rid = kh_val_vdict(d, k).id # <<<<<<<<<<<<<< @@ -43442,7 +50238,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom_2__set__(struct __pyx __pyx_t_4 = kh_val(__pyx_v_d, __pyx_v_k).id; __pyx_v_self->ptr->rid = __pyx_t_4; - /* "pysam/libcbcf.pyx":2593 + /* "pysam/libcbcf.pyx":3021 * * @chrom.setter * def chrom(self, value): # <<<<<<<<<<<<<< @@ -43464,7 +50260,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_5chrom_2__set__(struct __pyx return __pyx_r; } -/* "pysam/libcbcf.pyx":2602 +/* "pysam/libcbcf.pyx":3030 * * @property * def contig(self): # <<<<<<<<<<<<<< @@ -43497,9 +50293,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig___get__(struct int __pyx_t_4; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2602, 0, __PYX_ERR(0, 2602, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3030, 0, __PYX_ERR(0, 3030, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2604 + /* "pysam/libcbcf.pyx":3032 * def contig(self): * """chromosome/contig name""" * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< @@ -43509,7 +50305,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig___get__(struct __pyx_t_1 = __pyx_v_self->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2605 + /* "pysam/libcbcf.pyx":3033 * """chromosome/contig name""" * cdef bcf_hdr_t *hdr = self.header.ptr * cdef int rid = self.ptr.rid # <<<<<<<<<<<<<< @@ -43519,7 +50315,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig___get__(struct __pyx_t_2 = __pyx_v_self->ptr->rid; __pyx_v_rid = __pyx_t_2; - /* "pysam/libcbcf.pyx":2606 + /* "pysam/libcbcf.pyx":3034 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef int rid = self.ptr.rid * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: # <<<<<<<<<<<<<< @@ -43537,20 +50333,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig___get__(struct __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2607 + /* "pysam/libcbcf.pyx":3035 * cdef int rid = self.ptr.rid * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: * raise ValueError('Invalid header') # <<<<<<<<<<<<<< * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) * */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__139, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2607, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__147, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3035, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 2607, __pyx_L1_error) + __PYX_ERR(0, 3035, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2606 + /* "pysam/libcbcf.pyx":3034 * cdef bcf_hdr_t *hdr = self.header.ptr * cdef int rid = self.ptr.rid * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: # <<<<<<<<<<<<<< @@ -43559,7 +50355,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig___get__(struct */ } - /* "pysam/libcbcf.pyx":2608 + /* "pysam/libcbcf.pyx":3036 * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: * raise ValueError('Invalid header') * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) # <<<<<<<<<<<<<< @@ -43567,13 +50363,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig___get__(struct * @contig.setter */ __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_id2name(__pyx_v_hdr, __pyx_v_rid)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2608, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_id2name(__pyx_v_hdr, __pyx_v_rid)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3036, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2602 + /* "pysam/libcbcf.pyx":3030 * * @property * def contig(self): # <<<<<<<<<<<<<< @@ -43593,7 +50389,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig___get__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":2611 +/* "pysam/libcbcf.pyx":3039 * * @contig.setter * def contig(self, value): # <<<<<<<<<<<<<< @@ -43626,9 +50422,9 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig_2__set__(struct __py int __pyx_t_3; int __pyx_t_4; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2611, 0, __PYX_ERR(0, 2611, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3039, 0, __PYX_ERR(0, 3039, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2612 + /* "pysam/libcbcf.pyx":3040 * @contig.setter * def contig(self, value): * cdef vdict_t *d = self.header.ptr.dict[BCF_DT_CTG] # <<<<<<<<<<<<<< @@ -43637,19 +50433,19 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig_2__set__(struct __py */ __pyx_v_d = ((vdict_t *)(__pyx_v_self->header->ptr->dict[BCF_DT_CTG])); - /* "pysam/libcbcf.pyx":2613 + /* "pysam/libcbcf.pyx":3041 * def contig(self, value): * cdef vdict_t *d = self.header.ptr.dict[BCF_DT_CTG] * bchrom = force_bytes(value) # <<<<<<<<<<<<<< * cdef khint_t k = kh_get_vdict(d, bchrom) * if k == kh_end(d): */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2613, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3041, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_bchrom = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":2614 + /* "pysam/libcbcf.pyx":3042 * cdef vdict_t *d = self.header.ptr.dict[BCF_DT_CTG] * bchrom = force_bytes(value) * cdef khint_t k = kh_get_vdict(d, bchrom) # <<<<<<<<<<<<<< @@ -43658,12 +50454,12 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig_2__set__(struct __py */ if (unlikely(__pyx_v_bchrom == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2614, __pyx_L1_error) + __PYX_ERR(0, 3042, __pyx_L1_error) } - __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_bchrom); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 2614, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_bchrom); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 3042, __pyx_L1_error) __pyx_v_k = kh_get_vdict(__pyx_v_d, __pyx_t_2); - /* "pysam/libcbcf.pyx":2615 + /* "pysam/libcbcf.pyx":3043 * bchrom = force_bytes(value) * cdef khint_t k = kh_get_vdict(d, bchrom) * if k == kh_end(d): # <<<<<<<<<<<<<< @@ -43673,20 +50469,20 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig_2__set__(struct __py __pyx_t_3 = ((__pyx_v_k == kh_end(__pyx_v_d)) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2616 + /* "pysam/libcbcf.pyx":3044 * cdef khint_t k = kh_get_vdict(d, bchrom) * if k == kh_end(d): * raise ValueError('Invalid chromosome/contig') # <<<<<<<<<<<<<< * self.ptr.rid = kh_val_vdict(d, k).id * */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__140, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2616, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__148, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3044, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 2616, __pyx_L1_error) + __PYX_ERR(0, 3044, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2615 + /* "pysam/libcbcf.pyx":3043 * bchrom = force_bytes(value) * cdef khint_t k = kh_get_vdict(d, bchrom) * if k == kh_end(d): # <<<<<<<<<<<<<< @@ -43695,7 +50491,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig_2__set__(struct __py */ } - /* "pysam/libcbcf.pyx":2617 + /* "pysam/libcbcf.pyx":3045 * if k == kh_end(d): * raise ValueError('Invalid chromosome/contig') * self.ptr.rid = kh_val_vdict(d, k).id # <<<<<<<<<<<<<< @@ -43705,7 +50501,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig_2__set__(struct __py __pyx_t_4 = kh_val(__pyx_v_d, __pyx_v_k).id; __pyx_v_self->ptr->rid = __pyx_t_4; - /* "pysam/libcbcf.pyx":2611 + /* "pysam/libcbcf.pyx":3039 * * @contig.setter * def contig(self, value): # <<<<<<<<<<<<<< @@ -43727,7 +50523,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_6contig_2__set__(struct __py return __pyx_r; } -/* "pysam/libcbcf.pyx":2620 +/* "pysam/libcbcf.pyx":3048 * * @property * def pos(self): # <<<<<<<<<<<<<< @@ -43754,9 +50550,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3pos___get__(struct __ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2620, 0, __PYX_ERR(0, 2620, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3048, 0, __PYX_ERR(0, 3048, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2622 + /* "pysam/libcbcf.pyx":3050 * def pos(self): * """record start position on chrom/contig (1-based inclusive)""" * return self.ptr.pos + 1 # <<<<<<<<<<<<<< @@ -43764,13 +50560,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3pos___get__(struct __ * @pos.setter */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_self->ptr->pos + 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2622, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_self->ptr->pos + 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3050, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2620 + /* "pysam/libcbcf.pyx":3048 * * @property * def pos(self): # <<<<<<<<<<<<<< @@ -43790,7 +50586,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3pos___get__(struct __ return __pyx_r; } -/* "pysam/libcbcf.pyx":2625 +/* "pysam/libcbcf.pyx":3053 * * @pos.setter * def pos(self, value): # <<<<<<<<<<<<<< @@ -43820,19 +50616,19 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3pos_2__set__(struct __pyx_o int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2625, 0, __PYX_ERR(0, 2625, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3053, 0, __PYX_ERR(0, 3053, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2626 + /* "pysam/libcbcf.pyx":3054 * @pos.setter * def pos(self, value): * cdef int p = value # <<<<<<<<<<<<<< * if p < 1: * raise ValueError('Position must be positive') */ - __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2626, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3054, __pyx_L1_error) __pyx_v_p = __pyx_t_1; - /* "pysam/libcbcf.pyx":2627 + /* "pysam/libcbcf.pyx":3055 * def pos(self, value): * cdef int p = value * if p < 1: # <<<<<<<<<<<<<< @@ -43842,20 +50638,20 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3pos_2__set__(struct __pyx_o __pyx_t_2 = ((__pyx_v_p < 1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2628 + /* "pysam/libcbcf.pyx":3056 * cdef int p = value * if p < 1: * raise ValueError('Position must be positive') # <<<<<<<<<<<<<< * self.ptr.pos = p - 1 - * + * bcf_sync_end(self) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__141, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2628, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__149, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3056, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2628, __pyx_L1_error) + __PYX_ERR(0, 3056, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2627 + /* "pysam/libcbcf.pyx":3055 * def pos(self, value): * cdef int p = value * if p < 1: # <<<<<<<<<<<<<< @@ -43864,16 +50660,27 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3pos_2__set__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":2629 + /* "pysam/libcbcf.pyx":3057 * if p < 1: * raise ValueError('Position must be positive') * self.ptr.pos = p - 1 # <<<<<<<<<<<<<< + * bcf_sync_end(self) * - * @property */ __pyx_v_self->ptr->pos = (__pyx_v_p - 1); - /* "pysam/libcbcf.pyx":2625 + /* "pysam/libcbcf.pyx":3058 + * raise ValueError('Position must be positive') + * self.ptr.pos = p - 1 + * bcf_sync_end(self) # <<<<<<<<<<<<<< + * + * @property + */ + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_sync_end(__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3058, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":3053 * * @pos.setter * def pos(self, value): # <<<<<<<<<<<<<< @@ -43894,7 +50701,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3pos_2__set__(struct __pyx_o return __pyx_r; } -/* "pysam/libcbcf.pyx":2632 +/* "pysam/libcbcf.pyx":3061 * * @property * def start(self): # <<<<<<<<<<<<<< @@ -43921,9 +50728,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_5start___get__(struct __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2632, 0, __PYX_ERR(0, 2632, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3061, 0, __PYX_ERR(0, 3061, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2634 + /* "pysam/libcbcf.pyx":3063 * def start(self): * """record start position on chrom/contig (0-based inclusive)""" * return self.ptr.pos # <<<<<<<<<<<<<< @@ -43931,13 +50738,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_5start___get__(struct * @start.setter */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2634, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3063, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2632 + /* "pysam/libcbcf.pyx":3061 * * @property * def start(self): # <<<<<<<<<<<<<< @@ -43957,7 +50764,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_5start___get__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":2637 +/* "pysam/libcbcf.pyx":3066 * * @start.setter * def start(self, value): # <<<<<<<<<<<<<< @@ -43987,19 +50794,19 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_5start_2__set__(struct __pyx int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2637, 0, __PYX_ERR(0, 2637, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3066, 0, __PYX_ERR(0, 3066, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2638 + /* "pysam/libcbcf.pyx":3067 * @start.setter * def start(self, value): * cdef int s = value # <<<<<<<<<<<<<< * if s < 0: * raise ValueError('Start coordinate must be non-negative') */ - __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2638, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3067, __pyx_L1_error) __pyx_v_s = __pyx_t_1; - /* "pysam/libcbcf.pyx":2639 + /* "pysam/libcbcf.pyx":3068 * def start(self, value): * cdef int s = value * if s < 0: # <<<<<<<<<<<<<< @@ -44009,20 +50816,20 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_5start_2__set__(struct __pyx __pyx_t_2 = ((__pyx_v_s < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2640 + /* "pysam/libcbcf.pyx":3069 * cdef int s = value * if s < 0: * raise ValueError('Start coordinate must be non-negative') # <<<<<<<<<<<<<< * self.ptr.pos = s - * + * bcf_sync_end(self) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__142, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2640, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__150, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3069, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2640, __pyx_L1_error) + __PYX_ERR(0, 3069, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2639 + /* "pysam/libcbcf.pyx":3068 * def start(self, value): * cdef int s = value * if s < 0: # <<<<<<<<<<<<<< @@ -44031,16 +50838,27 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_5start_2__set__(struct __pyx */ } - /* "pysam/libcbcf.pyx":2641 + /* "pysam/libcbcf.pyx":3070 * if s < 0: * raise ValueError('Start coordinate must be non-negative') * self.ptr.pos = s # <<<<<<<<<<<<<< + * bcf_sync_end(self) * - * @property */ __pyx_v_self->ptr->pos = __pyx_v_s; - /* "pysam/libcbcf.pyx":2637 + /* "pysam/libcbcf.pyx":3071 + * raise ValueError('Start coordinate must be non-negative') + * self.ptr.pos = s + * bcf_sync_end(self) # <<<<<<<<<<<<<< + * + * @property + */ + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_sync_end(__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3071, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":3066 * * @start.setter * def start(self, value): # <<<<<<<<<<<<<< @@ -44061,7 +50879,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_5start_2__set__(struct __pyx return __pyx_r; } -/* "pysam/libcbcf.pyx":2644 +/* "pysam/libcbcf.pyx":3074 * * @property * def stop(self): # <<<<<<<<<<<<<< @@ -44088,9 +50906,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4stop___get__(struct _ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2644, 0, __PYX_ERR(0, 2644, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3074, 0, __PYX_ERR(0, 3074, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2646 + /* "pysam/libcbcf.pyx":3076 * def stop(self): * """record stop position on chrom/contig (0-based exclusive)""" * return self.ptr.pos + self.ptr.rlen # <<<<<<<<<<<<<< @@ -44098,13 +50916,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4stop___get__(struct _ * @stop.setter */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t((__pyx_v_self->ptr->pos + __pyx_v_self->ptr->rlen)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2646, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int32_t((__pyx_v_self->ptr->pos + __pyx_v_self->ptr->rlen)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3076, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2644 + /* "pysam/libcbcf.pyx":3074 * * @property * def stop(self): # <<<<<<<<<<<<<< @@ -44124,12 +50942,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4stop___get__(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":2649 +/* "pysam/libcbcf.pyx":3079 * * @stop.setter * def stop(self, value): # <<<<<<<<<<<<<< * cdef int s = value - * if s < self.ptr.pos: + * if s < 0: */ /* Python wrapper */ @@ -44153,120 +50971,77 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4stop_2__set__(struct __pyx_ int __pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2649, 0, __PYX_ERR(0, 2649, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3079, 0, __PYX_ERR(0, 3079, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2650 + /* "pysam/libcbcf.pyx":3080 * @stop.setter * def stop(self, value): * cdef int s = value # <<<<<<<<<<<<<< - * if s < self.ptr.pos: - * raise ValueError('Stop coordinate must be greater than or equal to start') + * if s < 0: + * raise ValueError('Stop coordinate must be non-negative') */ - __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2650, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3080, __pyx_L1_error) __pyx_v_s = __pyx_t_1; - /* "pysam/libcbcf.pyx":2651 + /* "pysam/libcbcf.pyx":3081 * def stop(self, value): * cdef int s = value - * if s < self.ptr.pos: # <<<<<<<<<<<<<< - * raise ValueError('Stop coordinate must be greater than or equal to start') + * if s < 0: # <<<<<<<<<<<<<< + * raise ValueError('Stop coordinate must be non-negative') * self.ptr.rlen = s - self.ptr.pos */ - __pyx_t_2 = ((__pyx_v_s < __pyx_v_self->ptr->pos) != 0); + __pyx_t_2 = ((__pyx_v_s < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2652 + /* "pysam/libcbcf.pyx":3082 * cdef int s = value - * if s < self.ptr.pos: - * raise ValueError('Stop coordinate must be greater than or equal to start') # <<<<<<<<<<<<<< + * if s < 0: + * raise ValueError('Stop coordinate must be non-negative') # <<<<<<<<<<<<<< * self.ptr.rlen = s - self.ptr.pos - * if self.ptr.rlen != len(self.ref) or 'END' in self.info: + * bcf_sync_end(self) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__143, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2652, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__151, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3082, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2652, __pyx_L1_error) + __PYX_ERR(0, 3082, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2651 + /* "pysam/libcbcf.pyx":3081 * def stop(self, value): * cdef int s = value - * if s < self.ptr.pos: # <<<<<<<<<<<<<< - * raise ValueError('Stop coordinate must be greater than or equal to start') + * if s < 0: # <<<<<<<<<<<<<< + * raise ValueError('Stop coordinate must be non-negative') * self.ptr.rlen = s - self.ptr.pos */ } - /* "pysam/libcbcf.pyx":2653 - * if s < self.ptr.pos: - * raise ValueError('Stop coordinate must be greater than or equal to start') + /* "pysam/libcbcf.pyx":3083 + * if s < 0: + * raise ValueError('Stop coordinate must be non-negative') * self.ptr.rlen = s - self.ptr.pos # <<<<<<<<<<<<<< - * if self.ptr.rlen != len(self.ref) or 'END' in self.info: - * self.info['END'] = s + * bcf_sync_end(self) + * */ __pyx_v_self->ptr->rlen = (__pyx_v_s - __pyx_v_self->ptr->pos); - /* "pysam/libcbcf.pyx":2654 - * raise ValueError('Stop coordinate must be greater than or equal to start') + /* "pysam/libcbcf.pyx":3084 + * raise ValueError('Stop coordinate must be non-negative') * self.ptr.rlen = s - self.ptr.pos - * if self.ptr.rlen != len(self.ref) or 'END' in self.info: # <<<<<<<<<<<<<< - * self.info['END'] = s + * bcf_sync_end(self) # <<<<<<<<<<<<<< * + * @property */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ref); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2654, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2654, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = ((__pyx_v_self->ptr->rlen != __pyx_t_4) != 0); - if (!__pyx_t_5) { - } else { - __pyx_t_2 = __pyx_t_5; - goto __pyx_L5_bool_binop_done; - } - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2654, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_sync_end(__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3084, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_END, __pyx_t_3, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2654, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = (__pyx_t_5 != 0); - __pyx_t_2 = __pyx_t_6; - __pyx_L5_bool_binop_done:; - if (__pyx_t_2) { - - /* "pysam/libcbcf.pyx":2655 - * self.ptr.rlen = s - self.ptr.pos - * if self.ptr.rlen != len(self.ref) or 'END' in self.info: - * self.info['END'] = s # <<<<<<<<<<<<<< - * - * @property - */ - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2655, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2655, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (unlikely(PyObject_SetItem(__pyx_t_7, __pyx_n_s_END, __pyx_t_3) < 0)) __PYX_ERR(0, 2655, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pysam/libcbcf.pyx":2654 - * raise ValueError('Stop coordinate must be greater than or equal to start') - * self.ptr.rlen = s - self.ptr.pos - * if self.ptr.rlen != len(self.ref) or 'END' in self.info: # <<<<<<<<<<<<<< - * self.info['END'] = s - * - */ - } - /* "pysam/libcbcf.pyx":2649 + /* "pysam/libcbcf.pyx":3079 * * @stop.setter * def stop(self, value): # <<<<<<<<<<<<<< * cdef int s = value - * if s < self.ptr.pos: + * if s < 0: */ /* function exit code */ @@ -44274,7 +51049,6 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4stop_2__set__(struct __pyx_ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("pysam.libcbcf.VariantRecord.stop.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -44283,11 +51057,11 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4stop_2__set__(struct __pyx_ return __pyx_r; } -/* "pysam/libcbcf.pyx":2658 +/* "pysam/libcbcf.pyx":3087 * * @property * def rlen(self): # <<<<<<<<<<<<<< - * """record length on chrom/contig (typically rec.stop - rec.start unless END info is supplied)""" + * """record length on chrom/contig (aka rec.stop - rec.start)""" * return self.ptr.rlen */ @@ -44310,27 +51084,27 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4rlen___get__(struct _ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2658, 0, __PYX_ERR(0, 2658, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3087, 0, __PYX_ERR(0, 3087, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2660 + /* "pysam/libcbcf.pyx":3089 * def rlen(self): - * """record length on chrom/contig (typically rec.stop - rec.start unless END info is supplied)""" + * """record length on chrom/contig (aka rec.stop - rec.start)""" * return self.ptr.rlen # <<<<<<<<<<<<<< * * @rlen.setter */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->rlen); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2660, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->rlen); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3089, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2658 + /* "pysam/libcbcf.pyx":3087 * * @property * def rlen(self): # <<<<<<<<<<<<<< - * """record length on chrom/contig (typically rec.stop - rec.start unless END info is supplied)""" + * """record length on chrom/contig (aka rec.stop - rec.start)""" * return self.ptr.rlen */ @@ -44346,12 +51120,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4rlen___get__(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":2663 +/* "pysam/libcbcf.pyx":3092 * * @rlen.setter * def rlen(self, value): # <<<<<<<<<<<<<< * cdef int r = value - * if r < 0: + * self.ptr.rlen = r */ /* Python wrapper */ @@ -44373,130 +51147,53 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4rlen_2__set__(struct __pyx_ __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2663, 0, __PYX_ERR(0, 2663, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3092, 0, __PYX_ERR(0, 3092, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2664 + /* "pysam/libcbcf.pyx":3093 * @rlen.setter * def rlen(self, value): * cdef int r = value # <<<<<<<<<<<<<< - * if r < 0: - * raise ValueError('Reference length must be non-negative') - */ - __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2664, __pyx_L1_error) - __pyx_v_r = __pyx_t_1; - - /* "pysam/libcbcf.pyx":2665 - * def rlen(self, value): - * cdef int r = value - * if r < 0: # <<<<<<<<<<<<<< - * raise ValueError('Reference length must be non-negative') - * self.ptr.rlen = r - */ - __pyx_t_2 = ((__pyx_v_r < 0) != 0); - if (unlikely(__pyx_t_2)) { - - /* "pysam/libcbcf.pyx":2666 - * cdef int r = value - * if r < 0: - * raise ValueError('Reference length must be non-negative') # <<<<<<<<<<<<<< * self.ptr.rlen = r - * if r != len(self.ref) or 'END' in self.info: + * bcf_sync_end(self) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__144, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2666, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2666, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3093, __pyx_L1_error) + __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":2665 + /* "pysam/libcbcf.pyx":3094 * def rlen(self, value): * cdef int r = value - * if r < 0: # <<<<<<<<<<<<<< - * raise ValueError('Reference length must be non-negative') - * self.ptr.rlen = r - */ - } - - /* "pysam/libcbcf.pyx":2667 - * if r < 0: - * raise ValueError('Reference length must be non-negative') * self.ptr.rlen = r # <<<<<<<<<<<<<< - * if r != len(self.ref) or 'END' in self.info: - * self.info['END'] = self.ptr.pos + r - */ - __pyx_v_self->ptr->rlen = __pyx_v_r; - - /* "pysam/libcbcf.pyx":2668 - * raise ValueError('Reference length must be non-negative') - * self.ptr.rlen = r - * if r != len(self.ref) or 'END' in self.info: # <<<<<<<<<<<<<< - * self.info['END'] = self.ptr.pos + r + * bcf_sync_end(self) * */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ref); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2668, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2668, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = ((__pyx_v_r != __pyx_t_4) != 0); - if (!__pyx_t_5) { - } else { - __pyx_t_2 = __pyx_t_5; - goto __pyx_L5_bool_binop_done; - } - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2668, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_END, __pyx_t_3, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2668, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = (__pyx_t_5 != 0); - __pyx_t_2 = __pyx_t_6; - __pyx_L5_bool_binop_done:; - if (__pyx_t_2) { + __pyx_v_self->ptr->rlen = __pyx_v_r; - /* "pysam/libcbcf.pyx":2669 + /* "pysam/libcbcf.pyx":3095 + * cdef int r = value * self.ptr.rlen = r - * if r != len(self.ref) or 'END' in self.info: - * self.info['END'] = self.ptr.pos + r # <<<<<<<<<<<<<< + * bcf_sync_end(self) # <<<<<<<<<<<<<< * * @property */ - __pyx_t_3 = __Pyx_PyInt_From_int32_t((__pyx_v_self->ptr->pos + __pyx_v_r)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (unlikely(PyObject_SetItem(__pyx_t_7, __pyx_n_s_END, __pyx_t_3) < 0)) __PYX_ERR(0, 2669, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pysam/libcbcf.pyx":2668 - * raise ValueError('Reference length must be non-negative') - * self.ptr.rlen = r - * if r != len(self.ref) or 'END' in self.info: # <<<<<<<<<<<<<< - * self.info['END'] = self.ptr.pos + r - * - */ - } + __pyx_t_2 = __pyx_f_5pysam_7libcbcf_bcf_sync_end(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3095, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":2663 + /* "pysam/libcbcf.pyx":3092 * * @rlen.setter * def rlen(self, value): # <<<<<<<<<<<<<< * cdef int r = value - * if r < 0: + * self.ptr.rlen = r */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("pysam.libcbcf.VariantRecord.rlen.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -44505,7 +51202,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4rlen_2__set__(struct __pyx_ return __pyx_r; } -/* "pysam/libcbcf.pyx":2672 +/* "pysam/libcbcf.pyx":3098 * * @property * def qual(self): # <<<<<<<<<<<<<< @@ -44533,9 +51230,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4qual___get__(struct _ PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2672, 0, __PYX_ERR(0, 2672, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3098, 0, __PYX_ERR(0, 3098, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2674 + /* "pysam/libcbcf.pyx":3100 * def qual(self): * """phred scaled quality score or None if not available""" * return self.ptr.qual if not bcf_float_is_missing(self.ptr.qual) else None # <<<<<<<<<<<<<< @@ -44544,7 +51241,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4qual___get__(struct _ */ __Pyx_XDECREF(__pyx_r); if (((!(bcf_float_is_missing(__pyx_v_self->ptr->qual) != 0)) != 0)) { - __pyx_t_2 = PyFloat_FromDouble(__pyx_v_self->ptr->qual); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2674, __pyx_L1_error) + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_self->ptr->qual); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3100, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; __pyx_t_2 = 0; @@ -44556,7 +51253,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4qual___get__(struct _ __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2672 + /* "pysam/libcbcf.pyx":3098 * * @property * def qual(self): # <<<<<<<<<<<<<< @@ -44577,7 +51274,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4qual___get__(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":2677 +/* "pysam/libcbcf.pyx":3103 * * @qual.setter * def qual(self, value): # <<<<<<<<<<<<<< @@ -44606,9 +51303,9 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4qual_2__set__(struct __pyx_ int __pyx_t_2; float __pyx_t_3; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2677, 0, __PYX_ERR(0, 2677, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3103, 0, __PYX_ERR(0, 3103, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2678 + /* "pysam/libcbcf.pyx":3104 * @qual.setter * def qual(self, value): * if value is not None: # <<<<<<<<<<<<<< @@ -44619,17 +51316,17 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4qual_2__set__(struct __pyx_ __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":2679 + /* "pysam/libcbcf.pyx":3105 * def qual(self, value): * if value is not None: * self.ptr.qual = value # <<<<<<<<<<<<<< * else: * bcf_float_set(&self.ptr.qual, bcf_float_missing) */ - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 2679, __pyx_L1_error) + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 3105, __pyx_L1_error) __pyx_v_self->ptr->qual = __pyx_t_3; - /* "pysam/libcbcf.pyx":2678 + /* "pysam/libcbcf.pyx":3104 * @qual.setter * def qual(self, value): * if value is not None: # <<<<<<<<<<<<<< @@ -44639,7 +51336,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4qual_2__set__(struct __pyx_ goto __pyx_L3; } - /* "pysam/libcbcf.pyx":2681 + /* "pysam/libcbcf.pyx":3107 * self.ptr.qual = value * else: * bcf_float_set(&self.ptr.qual, bcf_float_missing) # <<<<<<<<<<<<<< @@ -44651,7 +51348,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4qual_2__set__(struct __pyx_ } __pyx_L3:; - /* "pysam/libcbcf.pyx":2677 + /* "pysam/libcbcf.pyx":3103 * * @qual.setter * def qual(self, value): # <<<<<<<<<<<<<< @@ -44671,7 +51368,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4qual_2__set__(struct __pyx_ return __pyx_r; } -/* "pysam/libcbcf.pyx":2693 +/* "pysam/libcbcf.pyx":3119 * * @property * def id(self): # <<<<<<<<<<<<<< @@ -44702,9 +51399,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_2id___get__(struct __p PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2693, 0, __PYX_ERR(0, 2693, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3119, 0, __PYX_ERR(0, 3119, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2695 + /* "pysam/libcbcf.pyx":3121 * def id(self): * """record identifier or None if not available""" * cdef bcf1_t *r = self.ptr # <<<<<<<<<<<<<< @@ -44714,7 +51411,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_2id___get__(struct __p __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":2696 + /* "pysam/libcbcf.pyx":3122 * """record identifier or None if not available""" * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -44724,20 +51421,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_2id___get__(struct __p __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_STR) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2697 + /* "pysam/libcbcf.pyx":3123 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * return bcf_str_cache_get_charptr(r.d.id) if r.d.id != b'.' else None * */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__145, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2697, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__152, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2697, __pyx_L1_error) + __PYX_ERR(0, 3123, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2696 + /* "pysam/libcbcf.pyx":3122 * """record identifier or None if not available""" * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -44746,7 +51443,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_2id___get__(struct __p */ } - /* "pysam/libcbcf.pyx":2698 + /* "pysam/libcbcf.pyx":3124 * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') * return bcf_str_cache_get_charptr(r.d.id) if r.d.id != b'.' else None # <<<<<<<<<<<<<< @@ -44754,12 +51451,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_2id___get__(struct __p * @id.setter */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_r->d.id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2698, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_r->d.id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = (__Pyx_PyBytes_Equals(__pyx_t_4, __pyx_kp_b__71, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2698, __pyx_L1_error) + __pyx_t_2 = (__Pyx_PyBytes_Equals(__pyx_t_4, __pyx_kp_b__71, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3124, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_2) { - __pyx_t_4 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(__pyx_v_r->d.id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2698, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(__pyx_v_r->d.id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __pyx_t_4; __pyx_t_4 = 0; @@ -44771,7 +51468,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_2id___get__(struct __p __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2693 + /* "pysam/libcbcf.pyx":3119 * * @property * def id(self): # <<<<<<<<<<<<<< @@ -44792,7 +51489,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_2id___get__(struct __p return __pyx_r; } -/* "pysam/libcbcf.pyx":2701 +/* "pysam/libcbcf.pyx":3127 * * @id.setter * def id(self, value): # <<<<<<<<<<<<<< @@ -44826,9 +51523,9 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_2id_2__set__(struct __pyx_ob int __pyx_t_4; char *__pyx_t_5; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2701, 0, __PYX_ERR(0, 2701, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3127, 0, __PYX_ERR(0, 3127, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2702 + /* "pysam/libcbcf.pyx":3128 * @id.setter * def id(self, value): * cdef bcf1_t *r = self.ptr # <<<<<<<<<<<<<< @@ -44838,7 +51535,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_2id_2__set__(struct __pyx_ob __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":2703 + /* "pysam/libcbcf.pyx":3129 * def id(self, value): * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -44848,20 +51545,20 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_2id_2__set__(struct __pyx_ob __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_STR) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2704 + /* "pysam/libcbcf.pyx":3130 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * cdef char *idstr = NULL * if value is not None: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__146, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2704, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__153, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3130, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2704, __pyx_L1_error) + __PYX_ERR(0, 3130, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2703 + /* "pysam/libcbcf.pyx":3129 * def id(self, value): * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -44870,7 +51567,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_2id_2__set__(struct __pyx_ob */ } - /* "pysam/libcbcf.pyx":2705 + /* "pysam/libcbcf.pyx":3131 * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') * cdef char *idstr = NULL # <<<<<<<<<<<<<< @@ -44879,7 +51576,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_2id_2__set__(struct __pyx_ob */ __pyx_v_idstr = NULL; - /* "pysam/libcbcf.pyx":2706 + /* "pysam/libcbcf.pyx":3132 * raise ValueError('Error unpacking VariantRecord') * cdef char *idstr = NULL * if value is not None: # <<<<<<<<<<<<<< @@ -44890,19 +51587,19 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_2id_2__set__(struct __pyx_ob __pyx_t_4 = (__pyx_t_2 != 0); if (__pyx_t_4) { - /* "pysam/libcbcf.pyx":2707 + /* "pysam/libcbcf.pyx":3133 * cdef char *idstr = NULL * if value is not None: * bid = force_bytes(value) # <<<<<<<<<<<<<< * idstr = bid * if bcf_update_id(self.header.ptr, self.ptr, idstr) < 0: */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2707, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_bid = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2708 + /* "pysam/libcbcf.pyx":3134 * if value is not None: * bid = force_bytes(value) * idstr = bid # <<<<<<<<<<<<<< @@ -44911,12 +51608,12 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_2id_2__set__(struct __pyx_ob */ if (unlikely(__pyx_v_bid == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 2708, __pyx_L1_error) + __PYX_ERR(0, 3134, __pyx_L1_error) } - __pyx_t_5 = __Pyx_PyBytes_AsWritableString(__pyx_v_bid); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 2708, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyBytes_AsWritableString(__pyx_v_bid); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 3134, __pyx_L1_error) __pyx_v_idstr = __pyx_t_5; - /* "pysam/libcbcf.pyx":2706 + /* "pysam/libcbcf.pyx":3132 * raise ValueError('Error unpacking VariantRecord') * cdef char *idstr = NULL * if value is not None: # <<<<<<<<<<<<<< @@ -44925,7 +51622,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_2id_2__set__(struct __pyx_ob */ } - /* "pysam/libcbcf.pyx":2709 + /* "pysam/libcbcf.pyx":3135 * bid = force_bytes(value) * idstr = bid * if bcf_update_id(self.header.ptr, self.ptr, idstr) < 0: # <<<<<<<<<<<<<< @@ -44935,20 +51632,20 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_2id_2__set__(struct __pyx_ob __pyx_t_4 = ((bcf_update_id(__pyx_v_self->header->ptr, __pyx_v_self->ptr, __pyx_v_idstr) < 0) != 0); if (unlikely(__pyx_t_4)) { - /* "pysam/libcbcf.pyx":2710 + /* "pysam/libcbcf.pyx":3136 * idstr = bid * if bcf_update_id(self.header.ptr, self.ptr, idstr) < 0: * raise ValueError('Error updating id') # <<<<<<<<<<<<<< * * @property */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__147, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2710, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__154, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3136, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2710, __pyx_L1_error) + __PYX_ERR(0, 3136, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2709 + /* "pysam/libcbcf.pyx":3135 * bid = force_bytes(value) * idstr = bid * if bcf_update_id(self.header.ptr, self.ptr, idstr) < 0: # <<<<<<<<<<<<<< @@ -44957,7 +51654,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_2id_2__set__(struct __pyx_ob */ } - /* "pysam/libcbcf.pyx":2701 + /* "pysam/libcbcf.pyx":3127 * * @id.setter * def id(self, value): # <<<<<<<<<<<<<< @@ -44979,7 +51676,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_2id_2__set__(struct __pyx_ob return __pyx_r; } -/* "pysam/libcbcf.pyx":2713 +/* "pysam/libcbcf.pyx":3139 * * @property * def ref(self): # <<<<<<<<<<<<<< @@ -45010,9 +51707,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref___get__(struct __ PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2713, 0, __PYX_ERR(0, 2713, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3139, 0, __PYX_ERR(0, 3139, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2715 + /* "pysam/libcbcf.pyx":3141 * def ref(self): * """reference allele""" * cdef bcf1_t *r = self.ptr # <<<<<<<<<<<<<< @@ -45022,7 +51719,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref___get__(struct __ __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":2716 + /* "pysam/libcbcf.pyx":3142 * """reference allele""" * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -45032,20 +51729,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref___get__(struct __ __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_STR) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2717 + /* "pysam/libcbcf.pyx":3143 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * return charptr_to_str(r.d.allele[0]) if r.d.allele else None * */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__148, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2717, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__155, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2717, __pyx_L1_error) + __PYX_ERR(0, 3143, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2716 + /* "pysam/libcbcf.pyx":3142 * """reference allele""" * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -45054,7 +51751,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref___get__(struct __ */ } - /* "pysam/libcbcf.pyx":2718 + /* "pysam/libcbcf.pyx":3144 * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') * return charptr_to_str(r.d.allele[0]) if r.d.allele else None # <<<<<<<<<<<<<< @@ -45063,7 +51760,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref___get__(struct __ */ __Pyx_XDECREF(__pyx_r); if ((__pyx_v_r->d.allele != 0)) { - __pyx_t_4 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->d.allele[0]), NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2718, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->d.allele[0]), NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3144, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __pyx_t_4; __pyx_t_4 = 0; @@ -45075,7 +51772,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref___get__(struct __ __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2713 + /* "pysam/libcbcf.pyx":3139 * * @property * def ref(self): # <<<<<<<<<<<<<< @@ -45096,7 +51793,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref___get__(struct __ return __pyx_r; } -/* "pysam/libcbcf.pyx":2721 +/* "pysam/libcbcf.pyx":3147 * * @ref.setter * def ref(self, value): # <<<<<<<<<<<<<< @@ -45133,10 +51830,10 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref_2__set__(struct __pyx_o uint32_t __pyx_t_7; PyObject *__pyx_t_8 = NULL; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2721, 0, __PYX_ERR(0, 2721, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3147, 0, __PYX_ERR(0, 3147, __pyx_L1_error)); __Pyx_INCREF(__pyx_v_value); - /* "pysam/libcbcf.pyx":2722 + /* "pysam/libcbcf.pyx":3148 * @ref.setter * def ref(self, value): * cdef bcf1_t *r = self.ptr # <<<<<<<<<<<<<< @@ -45146,7 +51843,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref_2__set__(struct __pyx_o __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":2723 + /* "pysam/libcbcf.pyx":3149 * def ref(self, value): * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -45156,20 +51853,20 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref_2__set__(struct __pyx_o __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_STR) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2724 + /* "pysam/libcbcf.pyx":3150 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * #FIXME: Set alleles directly -- this is stupid * if not value: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__149, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2724, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__156, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3150, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2724, __pyx_L1_error) + __PYX_ERR(0, 3150, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2723 + /* "pysam/libcbcf.pyx":3149 * def ref(self, value): * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -45178,31 +51875,31 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref_2__set__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":2726 + /* "pysam/libcbcf.pyx":3152 * raise ValueError('Error unpacking VariantRecord') * #FIXME: Set alleles directly -- this is stupid * if not value: # <<<<<<<<<<<<<< * raise ValueError('ref allele must not be null') * value = force_bytes(value) */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2726, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3152, __pyx_L1_error) __pyx_t_4 = ((!__pyx_t_2) != 0); if (unlikely(__pyx_t_4)) { - /* "pysam/libcbcf.pyx":2727 + /* "pysam/libcbcf.pyx":3153 * #FIXME: Set alleles directly -- this is stupid * if not value: * raise ValueError('ref allele must not be null') # <<<<<<<<<<<<<< * value = force_bytes(value) * if r.d.allele and r.n_allele: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__150, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2727, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__157, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3153, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2727, __pyx_L1_error) + __PYX_ERR(0, 3153, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2726 + /* "pysam/libcbcf.pyx":3152 * raise ValueError('Error unpacking VariantRecord') * #FIXME: Set alleles directly -- this is stupid * if not value: # <<<<<<<<<<<<<< @@ -45211,19 +51908,19 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref_2__set__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":2728 + /* "pysam/libcbcf.pyx":3154 * if not value: * raise ValueError('ref allele must not be null') * value = force_bytes(value) # <<<<<<<<<<<<<< * if r.d.allele and r.n_allele: * alleles = [r.d.allele[i] for i in range(r.n_allele)] */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2728, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2729 + /* "pysam/libcbcf.pyx":3155 * raise ValueError('ref allele must not be null') * value = force_bytes(value) * if r.d.allele and r.n_allele: # <<<<<<<<<<<<<< @@ -45241,37 +51938,37 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref_2__set__(struct __pyx_o __pyx_L6_bool_binop_done:; if (__pyx_t_4) { - /* "pysam/libcbcf.pyx":2730 + /* "pysam/libcbcf.pyx":3156 * value = force_bytes(value) * if r.d.allele and r.n_allele: * alleles = [r.d.allele[i] for i in range(r.n_allele)] # <<<<<<<<<<<<<< * alleles[0] = value * else: */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2730, __pyx_L1_error) + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = __pyx_v_r->n_allele; __pyx_t_6 = __pyx_t_5; for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { __pyx_v_i = __pyx_t_7; - __pyx_t_8 = __Pyx_PyBytes_FromString((__pyx_v_r->d.allele[__pyx_v_i])); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2730, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyBytes_FromString((__pyx_v_r->d.allele[__pyx_v_i])); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_8))) __PYX_ERR(0, 2730, __pyx_L1_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_8))) __PYX_ERR(0, 3156, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } __pyx_v_alleles = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2731 + /* "pysam/libcbcf.pyx":3157 * if r.d.allele and r.n_allele: * alleles = [r.d.allele[i] for i in range(r.n_allele)] * alleles[0] = value # <<<<<<<<<<<<<< * else: - * alleles = [value] + * alleles = [value, ''] */ - if (unlikely(__Pyx_SetItemInt(__pyx_v_alleles, 0, __pyx_v_value, long, 1, __Pyx_PyInt_From_long, 1, 0, 1) < 0)) __PYX_ERR(0, 2731, __pyx_L1_error) + if (unlikely(__Pyx_SetItemInt(__pyx_v_alleles, 0, __pyx_v_value, long, 1, __Pyx_PyInt_From_long, 1, 0, 1) < 0)) __PYX_ERR(0, 3157, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2729 + /* "pysam/libcbcf.pyx":3155 * raise ValueError('ref allele must not be null') * value = force_bytes(value) * if r.d.allele and r.n_allele: # <<<<<<<<<<<<<< @@ -45281,34 +51978,48 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref_2__set__(struct __pyx_o goto __pyx_L5; } - /* "pysam/libcbcf.pyx":2733 + /* "pysam/libcbcf.pyx":3159 * alleles[0] = value * else: - * alleles = [value] # <<<<<<<<<<<<<< + * alleles = [value, ''] # <<<<<<<<<<<<<< * self.alleles = alleles - * + * bcf_sync_end(self) */ /*else*/ { - __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2733, __pyx_L1_error) + __pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3159, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyList_SET_ITEM(__pyx_t_3, 0, __pyx_v_value); + __Pyx_INCREF(__pyx_kp_s_NON_REF); + __Pyx_GIVEREF(__pyx_kp_s_NON_REF); + PyList_SET_ITEM(__pyx_t_3, 1, __pyx_kp_s_NON_REF); __pyx_v_alleles = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; } __pyx_L5:; - /* "pysam/libcbcf.pyx":2734 + /* "pysam/libcbcf.pyx":3160 * else: - * alleles = [value] + * alleles = [value, ''] * self.alleles = alleles # <<<<<<<<<<<<<< + * bcf_sync_end(self) + * + */ + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_alleles, __pyx_v_alleles) < 0) __PYX_ERR(0, 3160, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3161 + * alleles = [value, ''] + * self.alleles = alleles + * bcf_sync_end(self) # <<<<<<<<<<<<<< * * @property */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_alleles, __pyx_v_alleles) < 0) __PYX_ERR(0, 2734, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_bcf_sync_end(__pyx_v_self); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3161, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2721 + /* "pysam/libcbcf.pyx":3147 * * @ref.setter * def ref(self, value): # <<<<<<<<<<<<<< @@ -45332,7 +52043,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_3ref_2__set__(struct __pyx_o return __pyx_r; } -/* "pysam/libcbcf.pyx":2737 +/* "pysam/libcbcf.pyx":3164 * * @property * def alleles(self): # <<<<<<<<<<<<<< @@ -45368,9 +52079,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struc uint32_t __pyx_t_5; uint32_t __pyx_t_6; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2737, 0, __PYX_ERR(0, 2737, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3164, 0, __PYX_ERR(0, 3164, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2739 + /* "pysam/libcbcf.pyx":3166 * def alleles(self): * """tuple of reference allele followed by alt alleles""" * cdef bcf1_t *r = self.ptr # <<<<<<<<<<<<<< @@ -45380,7 +52091,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struc __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":2740 + /* "pysam/libcbcf.pyx":3167 * """tuple of reference allele followed by alt alleles""" * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -45390,20 +52101,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struc __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_STR) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2741 + /* "pysam/libcbcf.pyx":3168 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * if not r.d.allele: * return None */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__151, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2741, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__158, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3168, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2741, __pyx_L1_error) + __PYX_ERR(0, 3168, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2740 + /* "pysam/libcbcf.pyx":3167 * """tuple of reference allele followed by alt alleles""" * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -45412,7 +52123,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struc */ } - /* "pysam/libcbcf.pyx":2742 + /* "pysam/libcbcf.pyx":3169 * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') * if not r.d.allele: # <<<<<<<<<<<<<< @@ -45422,7 +52133,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struc __pyx_t_2 = ((!(__pyx_v_r->d.allele != 0)) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":2743 + /* "pysam/libcbcf.pyx":3170 * raise ValueError('Error unpacking VariantRecord') * if not r.d.allele: * return None # <<<<<<<<<<<<<< @@ -45433,7 +52144,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struc __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":2742 + /* "pysam/libcbcf.pyx":3169 * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') * if not r.d.allele: # <<<<<<<<<<<<<< @@ -45442,19 +52153,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struc */ } - /* "pysam/libcbcf.pyx":2744 + /* "pysam/libcbcf.pyx":3171 * if not r.d.allele: * return None * cdef tuple res = PyTuple_New(r.n_allele) # <<<<<<<<<<<<<< * for i in range(r.n_allele): * a = charptr_to_str(r.d.allele[i]) */ - __pyx_t_3 = PyTuple_New(__pyx_v_r->n_allele); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2744, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(__pyx_v_r->n_allele); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_res = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2745 + /* "pysam/libcbcf.pyx":3172 * return None * cdef tuple res = PyTuple_New(r.n_allele) * for i in range(r.n_allele): # <<<<<<<<<<<<<< @@ -45466,19 +52177,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struc for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; - /* "pysam/libcbcf.pyx":2746 + /* "pysam/libcbcf.pyx":3173 * cdef tuple res = PyTuple_New(r.n_allele) * for i in range(r.n_allele): * a = charptr_to_str(r.d.allele[i]) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(res, i, a) * Py_INCREF(a) */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->d.allele[__pyx_v_i]), NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2746, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->d.allele[__pyx_v_i]), NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_v_a, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2747 + /* "pysam/libcbcf.pyx":3174 * for i in range(r.n_allele): * a = charptr_to_str(r.d.allele[i]) * PyTuple_SET_ITEM(res, i, a) # <<<<<<<<<<<<<< @@ -45487,7 +52198,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struc */ PyTuple_SET_ITEM(__pyx_v_res, __pyx_v_i, __pyx_v_a); - /* "pysam/libcbcf.pyx":2748 + /* "pysam/libcbcf.pyx":3175 * a = charptr_to_str(r.d.allele[i]) * PyTuple_SET_ITEM(res, i, a) * Py_INCREF(a) # <<<<<<<<<<<<<< @@ -45497,7 +52208,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struc Py_INCREF(__pyx_v_a); } - /* "pysam/libcbcf.pyx":2749 + /* "pysam/libcbcf.pyx":3176 * PyTuple_SET_ITEM(res, i, a) * Py_INCREF(a) * return res # <<<<<<<<<<<<<< @@ -45509,7 +52220,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struc __pyx_r = __pyx_v_res; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2737 + /* "pysam/libcbcf.pyx":3164 * * @property * def alleles(self): # <<<<<<<<<<<<<< @@ -45531,251 +52242,354 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles___get__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":2752 +/* "pysam/libcbcf.pyx":3179 * * @alleles.setter - * def alleles(self, value): # <<<<<<<<<<<<<< + * def alleles(self, values): # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.ptr - * if bcf_unpack(r, BCF_UN_STR) < 0: + * */ /* Python wrapper */ -static int __pyx_pw_5pysam_7libcbcf_13VariantRecord_7alleles_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_7libcbcf_13VariantRecord_7alleles_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { +static int __pyx_pw_5pysam_7libcbcf_13VariantRecord_7alleles_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values); /*proto*/ +static int __pyx_pw_5pysam_7libcbcf_13VariantRecord_7alleles_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles_2__set__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles_2__set__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_self), ((PyObject *)__pyx_v_values)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles_2__set__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, PyObject *__pyx_v_value) { +static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_7alleles_2__set__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, PyObject *__pyx_v_values) { bcf1_t *__pyx_v_r; + int __pyx_v_rlen; + PyObject *__pyx_v_value = NULL; PyObject *__pyx_v_v = NULL; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations bcf1_t *__pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; + int32_t __pyx_t_2; + int __pyx_t_3; PyObject *__pyx_t_4 = NULL; - Py_ssize_t __pyx_t_5; - PyObject *(*__pyx_t_6)(PyObject *); - PyObject *__pyx_t_7 = NULL; - int __pyx_t_8; - char const *__pyx_t_9; + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + PyObject *(*__pyx_t_7)(PyObject *); + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + char const *__pyx_t_10; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2752, 0, __PYX_ERR(0, 2752, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_value); + __Pyx_TraceCall("__set__", __pyx_f[0], 3179, 0, __PYX_ERR(0, 3179, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_values); - /* "pysam/libcbcf.pyx":2753 + /* "pysam/libcbcf.pyx":3180 * @alleles.setter - * def alleles(self, value): + * def alleles(self, values): * cdef bcf1_t *r = self.ptr # <<<<<<<<<<<<<< - * if bcf_unpack(r, BCF_UN_STR) < 0: - * raise ValueError('Error unpacking VariantRecord') + * + * # Cache rlen of symbolic alleles before call to bcf_update_alleles_str */ __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":2754 - * def alleles(self, value): - * cdef bcf1_t *r = self.ptr + /* "pysam/libcbcf.pyx":3183 + * + * # Cache rlen of symbolic alleles before call to bcf_update_alleles_str + * cdef int rlen = r.rlen # <<<<<<<<<<<<<< + * + * if bcf_unpack(r, BCF_UN_STR) < 0: + */ + __pyx_t_2 = __pyx_v_r->rlen; + __pyx_v_rlen = __pyx_t_2; + + /* "pysam/libcbcf.pyx":3185 + * cdef int rlen = r.rlen + * * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') - * value = [force_bytes(v) for v in value] + * */ - __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_STR) < 0) != 0); - if (unlikely(__pyx_t_2)) { + __pyx_t_3 = ((bcf_unpack(__pyx_v_r, BCF_UN_STR) < 0) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2755 - * cdef bcf1_t *r = self.ptr + /* "pysam/libcbcf.pyx":3186 + * * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< - * value = [force_bytes(v) for v in value] - * if b'' in value: + * + * values = [force_bytes(v) for v in values] */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__152, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2755, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__159, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 3186, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2754 - * def alleles(self, value): - * cdef bcf1_t *r = self.ptr + /* "pysam/libcbcf.pyx":3185 + * cdef int rlen = r.rlen + * * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error unpacking VariantRecord') - * value = [force_bytes(v) for v in value] + * */ } - /* "pysam/libcbcf.pyx":2756 - * if bcf_unpack(r, BCF_UN_STR) < 0: + /* "pysam/libcbcf.pyx":3188 * raise ValueError('Error unpacking VariantRecord') - * value = [force_bytes(v) for v in value] # <<<<<<<<<<<<<< - * if b'' in value: - * raise ValueError('cannot set null allele') + * + * values = [force_bytes(v) for v in values] # <<<<<<<<<<<<<< + * + * if len(values) < 2: */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2756, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (likely(PyList_CheckExact(__pyx_v_value)) || PyTuple_CheckExact(__pyx_v_value)) { - __pyx_t_4 = __pyx_v_value; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0; - __pyx_t_6 = NULL; + __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (likely(PyList_CheckExact(__pyx_v_values)) || PyTuple_CheckExact(__pyx_v_values)) { + __pyx_t_5 = __pyx_v_values; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; + __pyx_t_7 = NULL; } else { - __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2756, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2756, __pyx_L1_error) + __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3188, __pyx_L1_error) } for (;;) { - if (likely(!__pyx_t_6)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; + if (likely(!__pyx_t_7)) { + if (likely(PyList_CheckExact(__pyx_t_5))) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 2756, __pyx_L1_error) + __pyx_t_8 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 3188, __pyx_L1_error) #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2756, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); #endif } else { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 2756, __pyx_L1_error) + __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 3188, __pyx_L1_error) #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2756, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); #endif } } else { - __pyx_t_7 = __pyx_t_6(__pyx_t_4); - if (unlikely(!__pyx_t_7)) { + __pyx_t_8 = __pyx_t_7(__pyx_t_5); + if (unlikely(!__pyx_t_8)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 2756, __pyx_L1_error) + else __PYX_ERR(0, 3188, __pyx_L1_error) } break; } - __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_8); } - __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_7 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_v, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2756, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 2756, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_8 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_v, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_8))) __PYX_ERR(0, 3188, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); - __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF_SET(__pyx_v_values, __pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2757 - * raise ValueError('Error unpacking VariantRecord') - * value = [force_bytes(v) for v in value] - * if b'' in value: # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3190 + * values = [force_bytes(v) for v in values] + * + * if len(values) < 2: # <<<<<<<<<<<<<< + * raise ValueError('must set at least 2 alleles') + * + */ + __pyx_t_6 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3190, __pyx_L1_error) + __pyx_t_3 = ((__pyx_t_6 < 2) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcbcf.pyx":3191 + * + * if len(values) < 2: + * raise ValueError('must set at least 2 alleles') # <<<<<<<<<<<<<< + * + * if b'' in values: + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__160, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 3191, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3190 + * values = [force_bytes(v) for v in values] + * + * if len(values) < 2: # <<<<<<<<<<<<<< + * raise ValueError('must set at least 2 alleles') + * + */ + } + + /* "pysam/libcbcf.pyx":3193 + * raise ValueError('must set at least 2 alleles') + * + * if b'' in values: # <<<<<<<<<<<<<< * raise ValueError('cannot set null allele') - * value = b','.join(value) + * */ - __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_kp_b__5, __pyx_v_value, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2757, __pyx_L1_error) - __pyx_t_8 = (__pyx_t_2 != 0); - if (unlikely(__pyx_t_8)) { + __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_kp_b__15, __pyx_v_values, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 3193, __pyx_L1_error) + __pyx_t_9 = (__pyx_t_3 != 0); + if (unlikely(__pyx_t_9)) { - /* "pysam/libcbcf.pyx":2758 - * value = [force_bytes(v) for v in value] - * if b'' in value: + /* "pysam/libcbcf.pyx":3194 + * + * if b'' in values: * raise ValueError('cannot set null allele') # <<<<<<<<<<<<<< - * value = b','.join(value) - * if bcf_update_alleles_str(self.header.ptr, r, value) < 0: + * + * value = b','.join(values) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__153, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2758, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__161, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 3194, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2757 - * raise ValueError('Error unpacking VariantRecord') - * value = [force_bytes(v) for v in value] - * if b'' in value: # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3193 + * raise ValueError('must set at least 2 alleles') + * + * if b'' in values: # <<<<<<<<<<<<<< * raise ValueError('cannot set null allele') - * value = b','.join(value) + * */ } - /* "pysam/libcbcf.pyx":2759 - * if b'' in value: + /* "pysam/libcbcf.pyx":3196 * raise ValueError('cannot set null allele') - * value = b','.join(value) # <<<<<<<<<<<<<< + * + * value = b','.join(values) # <<<<<<<<<<<<<< + * * if bcf_update_alleles_str(self.header.ptr, r, value) < 0: - * raise ValueError('Error updating alleles') */ - __pyx_t_3 = __Pyx_PyBytes_Join(__pyx_kp_b_, __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2759, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyBytes_Join(__pyx_kp_b__2, __pyx_v_values); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_value = __pyx_t_4; + __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2760 - * raise ValueError('cannot set null allele') - * value = b','.join(value) + /* "pysam/libcbcf.pyx":3198 + * value = b','.join(values) + * * if bcf_update_alleles_str(self.header.ptr, r, value) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error updating alleles') * */ - __pyx_t_9 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 2760, __pyx_L1_error) - __pyx_t_8 = ((bcf_update_alleles_str(__pyx_v_self->header->ptr, __pyx_v_r, __pyx_t_9) < 0) != 0); - if (unlikely(__pyx_t_8)) { + __pyx_t_10 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 3198, __pyx_L1_error) + __pyx_t_9 = ((bcf_update_alleles_str(__pyx_v_self->header->ptr, __pyx_v_r, __pyx_t_10) < 0) != 0); + if (unlikely(__pyx_t_9)) { - /* "pysam/libcbcf.pyx":2761 - * value = b','.join(value) + /* "pysam/libcbcf.pyx":3199 + * * if bcf_update_alleles_str(self.header.ptr, r, value) < 0: * raise ValueError('Error updating alleles') # <<<<<<<<<<<<<< * - * @property + * # Reset rlen if alternate allele isn't symbolic, otherwise used cached */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__154, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2761, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2761, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__162, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3199, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 3199, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2760 - * raise ValueError('cannot set null allele') - * value = b','.join(value) + /* "pysam/libcbcf.pyx":3198 + * value = b','.join(values) + * * if bcf_update_alleles_str(self.header.ptr, r, value) < 0: # <<<<<<<<<<<<<< * raise ValueError('Error updating alleles') * */ } - /* "pysam/libcbcf.pyx":2752 + /* "pysam/libcbcf.pyx":3202 + * + * # Reset rlen if alternate allele isn't symbolic, otherwise used cached + * if has_symbolic_allele(self): # <<<<<<<<<<<<<< + * self.ptr.rlen = rlen + * else: + */ + __pyx_t_9 = (__pyx_f_5pysam_7libcbcf_has_symbolic_allele(__pyx_v_self) != 0); + if (__pyx_t_9) { + + /* "pysam/libcbcf.pyx":3203 + * # Reset rlen if alternate allele isn't symbolic, otherwise used cached + * if has_symbolic_allele(self): + * self.ptr.rlen = rlen # <<<<<<<<<<<<<< + * else: + * self.ptr.rlen = len(values[0]) + */ + __pyx_v_self->ptr->rlen = __pyx_v_rlen; + + /* "pysam/libcbcf.pyx":3202 + * + * # Reset rlen if alternate allele isn't symbolic, otherwise used cached + * if has_symbolic_allele(self): # <<<<<<<<<<<<<< + * self.ptr.rlen = rlen + * else: + */ + goto __pyx_L9; + } + + /* "pysam/libcbcf.pyx":3205 + * self.ptr.rlen = rlen + * else: + * self.ptr.rlen = len(values[0]) # <<<<<<<<<<<<<< + * bcf_sync_end(self) + * + */ + /*else*/ { + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_values, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3205, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_self->ptr->rlen = __pyx_t_6; + } + __pyx_L9:; + + /* "pysam/libcbcf.pyx":3206 + * else: + * self.ptr.rlen = len(values[0]) + * bcf_sync_end(self) # <<<<<<<<<<<<<< + * + * @property + */ + __pyx_t_4 = __pyx_f_5pysam_7libcbcf_bcf_sync_end(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3206, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libcbcf.pyx":3179 * * @alleles.setter - * def alleles(self, value): # <<<<<<<<<<<<<< + * def alleles(self, values): # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.ptr - * if bcf_unpack(r, BCF_UN_STR) < 0: + * */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("pysam.libcbcf.VariantRecord.alleles.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_v); __Pyx_XDECREF(__pyx_v_value); + __Pyx_XDECREF(__pyx_v_v); + __Pyx_XDECREF(__pyx_v_values); __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":2764 +/* "pysam/libcbcf.pyx":3209 * * @property * def alts(self): # <<<<<<<<<<<<<< @@ -45813,9 +52627,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ PyObject *(*__pyx_t_7)(PyObject *); Py_ssize_t __pyx_t_8; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2764, 0, __PYX_ERR(0, 2764, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3209, 0, __PYX_ERR(0, 3209, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2766 + /* "pysam/libcbcf.pyx":3211 * def alts(self): * """tuple of alt alleles""" * cdef bcf1_t *r = self.ptr # <<<<<<<<<<<<<< @@ -45825,7 +52639,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":2767 + /* "pysam/libcbcf.pyx":3212 * """tuple of alt alleles""" * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -45835,20 +52649,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_STR) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2768 + /* "pysam/libcbcf.pyx":3213 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * if r.n_allele < 2 or not r.d.allele: * return None */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__155, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2768, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__163, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3213, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2768, __pyx_L1_error) + __PYX_ERR(0, 3213, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2767 + /* "pysam/libcbcf.pyx":3212 * """tuple of alt alleles""" * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -45857,7 +52671,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ */ } - /* "pysam/libcbcf.pyx":2769 + /* "pysam/libcbcf.pyx":3214 * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') * if r.n_allele < 2 or not r.d.allele: # <<<<<<<<<<<<<< @@ -45875,7 +52689,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ __pyx_L5_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":2770 + /* "pysam/libcbcf.pyx":3215 * raise ValueError('Error unpacking VariantRecord') * if r.n_allele < 2 or not r.d.allele: * return None # <<<<<<<<<<<<<< @@ -45886,7 +52700,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":2769 + /* "pysam/libcbcf.pyx":3214 * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') * if r.n_allele < 2 or not r.d.allele: # <<<<<<<<<<<<<< @@ -45895,28 +52709,28 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ */ } - /* "pysam/libcbcf.pyx":2771 + /* "pysam/libcbcf.pyx":3216 * if r.n_allele < 2 or not r.d.allele: * return None * cdef tuple res = PyTuple_New(r.n_allele - 1) # <<<<<<<<<<<<<< * for i in range(1, r.n_allele): * a = charptr_to_str(r.d.allele[i]) */ - __pyx_t_3 = PyTuple_New((__pyx_v_r->n_allele - 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2771, __pyx_L1_error) + __pyx_t_3 = PyTuple_New((__pyx_v_r->n_allele - 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3216, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_res = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2772 + /* "pysam/libcbcf.pyx":3217 * return None * cdef tuple res = PyTuple_New(r.n_allele - 1) * for i in range(1, r.n_allele): # <<<<<<<<<<<<<< * a = charptr_to_str(r.d.allele[i]) * PyTuple_SET_ITEM(res, i - 1, a) */ - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_r->n_allele); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2772, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_r->n_allele); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3217, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2772, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3217, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_int_1); __Pyx_GIVEREF(__pyx_int_1); @@ -45924,16 +52738,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2772, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3217, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { __pyx_t_5 = __pyx_t_3; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; __pyx_t_7 = NULL; } else { - __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2772, __pyx_L1_error) + __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3217, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2772, __pyx_L1_error) + __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3217, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; for (;;) { @@ -45941,17 +52755,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ if (likely(PyList_CheckExact(__pyx_t_5))) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 2772, __pyx_L1_error) + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 3217, __pyx_L1_error) #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2772, __pyx_L1_error) + __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3217, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); #endif } else { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 2772, __pyx_L1_error) + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 3217, __pyx_L1_error) #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2772, __pyx_L1_error) + __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3217, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); #endif } @@ -45961,7 +52775,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 2772, __pyx_L1_error) + else __PYX_ERR(0, 3217, __pyx_L1_error) } break; } @@ -45970,33 +52784,33 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2773 + /* "pysam/libcbcf.pyx":3218 * cdef tuple res = PyTuple_New(r.n_allele - 1) * for i in range(1, r.n_allele): * a = charptr_to_str(r.d.allele[i]) # <<<<<<<<<<<<<< * PyTuple_SET_ITEM(res, i - 1, a) * Py_INCREF(a) */ - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 2773, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->d.allele[__pyx_t_8]), NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2773, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3218, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_r->d.allele[__pyx_t_8]), NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3218, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_v_a, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2774 + /* "pysam/libcbcf.pyx":3219 * for i in range(1, r.n_allele): * a = charptr_to_str(r.d.allele[i]) * PyTuple_SET_ITEM(res, i - 1, a) # <<<<<<<<<<<<<< * Py_INCREF(a) * return res */ - __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2774, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_v_i, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 2774, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 3219, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyTuple_SET_ITEM(__pyx_v_res, __pyx_t_8, __pyx_v_a); - /* "pysam/libcbcf.pyx":2775 + /* "pysam/libcbcf.pyx":3220 * a = charptr_to_str(r.d.allele[i]) * PyTuple_SET_ITEM(res, i - 1, a) * Py_INCREF(a) # <<<<<<<<<<<<<< @@ -46005,7 +52819,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ */ Py_INCREF(__pyx_v_a); - /* "pysam/libcbcf.pyx":2772 + /* "pysam/libcbcf.pyx":3217 * return None * cdef tuple res = PyTuple_New(r.n_allele - 1) * for i in range(1, r.n_allele): # <<<<<<<<<<<<<< @@ -46015,7 +52829,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcbcf.pyx":2776 + /* "pysam/libcbcf.pyx":3221 * PyTuple_SET_ITEM(res, i - 1, a) * Py_INCREF(a) * return res # <<<<<<<<<<<<<< @@ -46027,7 +52841,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ __pyx_r = __pyx_v_res; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2764 + /* "pysam/libcbcf.pyx":3209 * * @property * def alts(self): # <<<<<<<<<<<<<< @@ -46051,7 +52865,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts___get__(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":2779 +/* "pysam/libcbcf.pyx":3224 * * @alts.setter * def alts(self, value): # <<<<<<<<<<<<<< @@ -46088,10 +52902,10 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts_2__set__(struct __pyx_ PyObject *__pyx_t_7 = NULL; int __pyx_t_8; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2779, 0, __PYX_ERR(0, 2779, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3224, 0, __PYX_ERR(0, 3224, __pyx_L1_error)); __Pyx_INCREF(__pyx_v_value); - /* "pysam/libcbcf.pyx":2781 + /* "pysam/libcbcf.pyx":3226 * def alts(self, value): * #FIXME: Set alleles directly -- this is stupid * cdef bcf1_t *r = self.ptr # <<<<<<<<<<<<<< @@ -46101,7 +52915,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts_2__set__(struct __pyx_ __pyx_t_1 = __pyx_v_self->ptr; __pyx_v_r = __pyx_t_1; - /* "pysam/libcbcf.pyx":2782 + /* "pysam/libcbcf.pyx":3227 * #FIXME: Set alleles directly -- this is stupid * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -46111,20 +52925,20 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts_2__set__(struct __pyx_ __pyx_t_2 = ((bcf_unpack(__pyx_v_r, BCF_UN_STR) < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2783 + /* "pysam/libcbcf.pyx":3228 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * value = [force_bytes(v) for v in value] * if b'' in value: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__156, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2783, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__164, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3228, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2783, __pyx_L1_error) + __PYX_ERR(0, 3228, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2782 + /* "pysam/libcbcf.pyx":3227 * #FIXME: Set alleles directly -- this is stupid * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: # <<<<<<<<<<<<<< @@ -46133,39 +52947,39 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts_2__set__(struct __pyx_ */ } - /* "pysam/libcbcf.pyx":2784 + /* "pysam/libcbcf.pyx":3229 * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') * value = [force_bytes(v) for v in value] # <<<<<<<<<<<<<< * if b'' in value: * raise ValueError('cannot set null alt allele') */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2784, __pyx_L1_error) + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3229, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (likely(PyList_CheckExact(__pyx_v_value)) || PyTuple_CheckExact(__pyx_v_value)) { __pyx_t_4 = __pyx_v_value; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0; __pyx_t_6 = NULL; } else { - __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2784, __pyx_L1_error) + __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3229, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2784, __pyx_L1_error) + __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3229, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_6)) { if (likely(PyList_CheckExact(__pyx_t_4))) { if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 2784, __pyx_L1_error) + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 3229, __pyx_L1_error) #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2784, __pyx_L1_error) + __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3229, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); #endif } else { if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 2784, __pyx_L1_error) + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 3229, __pyx_L1_error) #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2784, __pyx_L1_error) + __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3229, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); #endif } @@ -46175,7 +52989,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts_2__set__(struct __pyx_ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 2784, __pyx_L1_error) + else __PYX_ERR(0, 3229, __pyx_L1_error) } break; } @@ -46183,40 +52997,40 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts_2__set__(struct __pyx_ } __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_v, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2784, __pyx_L1_error) + __pyx_t_7 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_v, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3229, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 2784, __pyx_L1_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 3229, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2785 + /* "pysam/libcbcf.pyx":3230 * raise ValueError('Error unpacking VariantRecord') * value = [force_bytes(v) for v in value] * if b'' in value: # <<<<<<<<<<<<<< * raise ValueError('cannot set null alt allele') * ref = [r.d.allele[0] if r.d.allele and r.n_allele else b'.'] */ - __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_kp_b__5, __pyx_v_value, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2785, __pyx_L1_error) + __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_kp_b__15, __pyx_v_value, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3230, __pyx_L1_error) __pyx_t_8 = (__pyx_t_2 != 0); if (unlikely(__pyx_t_8)) { - /* "pysam/libcbcf.pyx":2786 + /* "pysam/libcbcf.pyx":3231 * value = [force_bytes(v) for v in value] * if b'' in value: * raise ValueError('cannot set null alt allele') # <<<<<<<<<<<<<< * ref = [r.d.allele[0] if r.d.allele and r.n_allele else b'.'] * self.alleles = ref + value */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__157, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2786, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__165, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3231, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2786, __pyx_L1_error) + __PYX_ERR(0, 3231, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2785 + /* "pysam/libcbcf.pyx":3230 * raise ValueError('Error unpacking VariantRecord') * value = [force_bytes(v) for v in value] * if b'' in value: # <<<<<<<<<<<<<< @@ -46225,7 +53039,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts_2__set__(struct __pyx_ */ } - /* "pysam/libcbcf.pyx":2787 + /* "pysam/libcbcf.pyx":3232 * if b'' in value: * raise ValueError('cannot set null alt allele') * ref = [r.d.allele[0] if r.d.allele and r.n_allele else b'.'] # <<<<<<<<<<<<<< @@ -46242,7 +53056,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts_2__set__(struct __pyx_ __pyx_t_8 = __pyx_t_2; __pyx_L7_bool_binop_done:; if (__pyx_t_8) { - __pyx_t_4 = __Pyx_PyBytes_FromString((__pyx_v_r->d.allele[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2787, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyBytes_FromString((__pyx_v_r->d.allele[0])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __pyx_t_4; __pyx_t_4 = 0; @@ -46250,7 +53064,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts_2__set__(struct __pyx_ __Pyx_INCREF(__pyx_kp_b__71); __pyx_t_3 = __pyx_kp_b__71; } - __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2787, __pyx_L1_error) + __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); @@ -46258,19 +53072,19 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts_2__set__(struct __pyx_ __pyx_v_ref = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2788 + /* "pysam/libcbcf.pyx":3233 * raise ValueError('cannot set null alt allele') * ref = [r.d.allele[0] if r.d.allele and r.n_allele else b'.'] * self.alleles = ref + value # <<<<<<<<<<<<<< * * @property */ - __pyx_t_4 = PyNumber_Add(__pyx_v_ref, __pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2788, __pyx_L1_error) + __pyx_t_4 = PyNumber_Add(__pyx_v_ref, __pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3233, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_alleles, __pyx_t_4) < 0) __PYX_ERR(0, 2788, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_alleles, __pyx_t_4) < 0) __PYX_ERR(0, 3233, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":2779 + /* "pysam/libcbcf.pyx":3224 * * @alts.setter * def alts(self, value): # <<<<<<<<<<<<<< @@ -46296,7 +53110,7 @@ static int __pyx_pf_5pysam_7libcbcf_13VariantRecord_4alts_2__set__(struct __pyx_ return __pyx_r; } -/* "pysam/libcbcf.pyx":2791 +/* "pysam/libcbcf.pyx":3236 * * @property * def filter(self): # <<<<<<<<<<<<<< @@ -46324,9 +53138,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6filter___get__(struct int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2791, 0, __PYX_ERR(0, 2791, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3236, 0, __PYX_ERR(0, 3236, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2793 + /* "pysam/libcbcf.pyx":3238 * def filter(self): * """filter information (see :class:`VariantRecordFilter`)""" * if bcf_unpack(self.ptr, BCF_UN_FLT) < 0: # <<<<<<<<<<<<<< @@ -46336,20 +53150,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6filter___get__(struct __pyx_t_1 = ((bcf_unpack(__pyx_v_self->ptr, BCF_UN_FLT) < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":2794 + /* "pysam/libcbcf.pyx":3239 * """filter information (see :class:`VariantRecordFilter`)""" * if bcf_unpack(self.ptr, BCF_UN_FLT) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * return makeVariantRecordFilter(self) * */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__158, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2794, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__166, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3239, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 2794, __pyx_L1_error) + __PYX_ERR(0, 3239, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2793 + /* "pysam/libcbcf.pyx":3238 * def filter(self): * """filter information (see :class:`VariantRecordFilter`)""" * if bcf_unpack(self.ptr, BCF_UN_FLT) < 0: # <<<<<<<<<<<<<< @@ -46358,7 +53172,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6filter___get__(struct */ } - /* "pysam/libcbcf.pyx":2795 + /* "pysam/libcbcf.pyx":3240 * if bcf_unpack(self.ptr, BCF_UN_FLT) < 0: * raise ValueError('Error unpacking VariantRecord') * return makeVariantRecordFilter(self) # <<<<<<<<<<<<<< @@ -46366,13 +53180,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6filter___get__(struct * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordFilter(__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2795, __pyx_L1_error) + __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordFilter(__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3240, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2791 + /* "pysam/libcbcf.pyx":3236 * * @property * def filter(self): # <<<<<<<<<<<<<< @@ -46392,7 +53206,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6filter___get__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":2798 +/* "pysam/libcbcf.pyx":3243 * * @property * def info(self): # <<<<<<<<<<<<<< @@ -46420,9 +53234,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4info___get__(struct _ int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2798, 0, __PYX_ERR(0, 2798, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3243, 0, __PYX_ERR(0, 3243, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2800 + /* "pysam/libcbcf.pyx":3245 * def info(self): * """info data (see :class:`VariantRecordInfo`)""" * if bcf_unpack(self.ptr, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< @@ -46432,20 +53246,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4info___get__(struct _ __pyx_t_1 = ((bcf_unpack(__pyx_v_self->ptr, BCF_UN_INFO) < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":2801 + /* "pysam/libcbcf.pyx":3246 * """info data (see :class:`VariantRecordInfo`)""" * if bcf_unpack(self.ptr, BCF_UN_INFO) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * return makeVariantRecordInfo(self) * */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__159, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2801, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__167, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3246, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 2801, __pyx_L1_error) + __PYX_ERR(0, 3246, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2800 + /* "pysam/libcbcf.pyx":3245 * def info(self): * """info data (see :class:`VariantRecordInfo`)""" * if bcf_unpack(self.ptr, BCF_UN_INFO) < 0: # <<<<<<<<<<<<<< @@ -46454,7 +53268,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4info___get__(struct _ */ } - /* "pysam/libcbcf.pyx":2802 + /* "pysam/libcbcf.pyx":3247 * if bcf_unpack(self.ptr, BCF_UN_INFO) < 0: * raise ValueError('Error unpacking VariantRecord') * return makeVariantRecordInfo(self) # <<<<<<<<<<<<<< @@ -46462,13 +53276,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4info___get__(struct _ * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordInfo(__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2802, __pyx_L1_error) + __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordInfo(__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3247, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2798 + /* "pysam/libcbcf.pyx":3243 * * @property * def info(self): # <<<<<<<<<<<<<< @@ -46488,7 +53302,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_4info___get__(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":2805 +/* "pysam/libcbcf.pyx":3250 * * @property * def format(self): # <<<<<<<<<<<<<< @@ -46516,9 +53330,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6format___get__(struct int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2805, 0, __PYX_ERR(0, 2805, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3250, 0, __PYX_ERR(0, 3250, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2807 + /* "pysam/libcbcf.pyx":3252 * def format(self): * """sample format metadata (see :class:`VariantRecordFormat`)""" * if bcf_unpack(self.ptr, BCF_UN_FMT) < 0: # <<<<<<<<<<<<<< @@ -46528,20 +53342,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6format___get__(struct __pyx_t_1 = ((bcf_unpack(__pyx_v_self->ptr, BCF_UN_FMT) < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":2808 + /* "pysam/libcbcf.pyx":3253 * """sample format metadata (see :class:`VariantRecordFormat`)""" * if bcf_unpack(self.ptr, BCF_UN_FMT) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * return makeVariantRecordFormat(self) * */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__160, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2808, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__168, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3253, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 2808, __pyx_L1_error) + __PYX_ERR(0, 3253, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2807 + /* "pysam/libcbcf.pyx":3252 * def format(self): * """sample format metadata (see :class:`VariantRecordFormat`)""" * if bcf_unpack(self.ptr, BCF_UN_FMT) < 0: # <<<<<<<<<<<<<< @@ -46550,7 +53364,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6format___get__(struct */ } - /* "pysam/libcbcf.pyx":2809 + /* "pysam/libcbcf.pyx":3254 * if bcf_unpack(self.ptr, BCF_UN_FMT) < 0: * raise ValueError('Error unpacking VariantRecord') * return makeVariantRecordFormat(self) # <<<<<<<<<<<<<< @@ -46558,13 +53372,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6format___get__(struct * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordFormat(__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2809, __pyx_L1_error) + __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordFormat(__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3254, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2805 + /* "pysam/libcbcf.pyx":3250 * * @property * def format(self): # <<<<<<<<<<<<<< @@ -46584,7 +53398,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6format___get__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":2812 +/* "pysam/libcbcf.pyx":3257 * * @property * def samples(self): # <<<<<<<<<<<<<< @@ -46612,9 +53426,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7samples___get__(struc int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2812, 0, __PYX_ERR(0, 2812, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3257, 0, __PYX_ERR(0, 3257, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2814 + /* "pysam/libcbcf.pyx":3259 * def samples(self): * """sample data (see :class:`VariantRecordSamples`)""" * if bcf_unpack(self.ptr, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< @@ -46624,20 +53438,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7samples___get__(struc __pyx_t_1 = ((bcf_unpack(__pyx_v_self->ptr, BCF_UN_ALL) < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":2815 + /* "pysam/libcbcf.pyx":3260 * """sample data (see :class:`VariantRecordSamples`)""" * if bcf_unpack(self.ptr, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * return makeVariantRecordSamples(self) * */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__161, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2815, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__169, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 2815, __pyx_L1_error) + __PYX_ERR(0, 3260, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2814 + /* "pysam/libcbcf.pyx":3259 * def samples(self): * """sample data (see :class:`VariantRecordSamples`)""" * if bcf_unpack(self.ptr, BCF_UN_ALL) < 0: # <<<<<<<<<<<<<< @@ -46646,21 +53460,21 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7samples___get__(struc */ } - /* "pysam/libcbcf.pyx":2816 + /* "pysam/libcbcf.pyx":3261 * if bcf_unpack(self.ptr, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') * return makeVariantRecordSamples(self) # <<<<<<<<<<<<<< * - * def __str__(self): + * def __richcmp__(VariantRecord self not None, VariantRecord other not None, int op): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordSamples(__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2816, __pyx_L1_error) + __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecordSamples(__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3261, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2812 + /* "pysam/libcbcf.pyx":3257 * * @property * def samples(self): # <<<<<<<<<<<<<< @@ -46680,28 +53494,432 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_7samples___get__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":2818 +/* "pysam/libcbcf.pyx":3263 * return makeVariantRecordSamples(self) * + * def __richcmp__(VariantRecord self not None, VariantRecord other not None, int op): # <<<<<<<<<<<<<< + * if op != 2 and op != 3: + * return NotImplemented + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_9__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_9__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); + if (unlikely(((PyObject *)__pyx_v_self) == Py_None)) { + PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "self"); __PYX_ERR(0, 3263, __pyx_L1_error) + } + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_7libcbcf_VariantRecord, 0, "other", 0))) __PYX_ERR(0, 3263, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantRecord_8__richcmp__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_self), ((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_other), ((int)__pyx_v_op)); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__richcmp__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_other, int __pyx_v_op) { + bcf1_t *__pyx_v_s; + bcf1_t *__pyx_v_o; + int __pyx_v_cmp; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + bcf1_t *__pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("__richcmp__", 0); + __Pyx_TraceCall("__richcmp__", __pyx_f[0], 3263, 0, __PYX_ERR(0, 3263, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":3264 + * + * def __richcmp__(VariantRecord self not None, VariantRecord other not None, int op): + * if op != 2 and op != 3: # <<<<<<<<<<<<<< + * return NotImplemented + * + */ + switch (__pyx_v_op) { + case 2: + case 3: + __pyx_t_1 = 0; + break; + default: + __pyx_t_1 = 1; + break; + } + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":3265 + * def __richcmp__(VariantRecord self not None, VariantRecord other not None, int op): + * if op != 2 and op != 3: + * return NotImplemented # <<<<<<<<<<<<<< + * + * cdef bcf1_t *s = self.ptr + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_builtin_NotImplemented); + __pyx_r = __pyx_builtin_NotImplemented; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":3264 + * + * def __richcmp__(VariantRecord self not None, VariantRecord other not None, int op): + * if op != 2 and op != 3: # <<<<<<<<<<<<<< + * return NotImplemented + * + */ + } + + /* "pysam/libcbcf.pyx":3267 + * return NotImplemented + * + * cdef bcf1_t *s = self.ptr # <<<<<<<<<<<<<< + * cdef bcf1_t *o = other.ptr + * + */ + __pyx_t_2 = __pyx_v_self->ptr; + __pyx_v_s = __pyx_t_2; + + /* "pysam/libcbcf.pyx":3268 + * + * cdef bcf1_t *s = self.ptr + * cdef bcf1_t *o = other.ptr # <<<<<<<<<<<<<< + * + * cdef bint cmp = self is other or ( + */ + __pyx_t_2 = __pyx_v_other->ptr; + __pyx_v_o = __pyx_t_2; + + /* "pysam/libcbcf.pyx":3270 + * cdef bcf1_t *o = other.ptr + * + * cdef bint cmp = self is other or ( # <<<<<<<<<<<<<< + * s.pos == o.pos + * and s.rlen == o.rlen + */ + __pyx_t_3 = (__pyx_v_self == __pyx_v_other); + __pyx_t_4 = (__pyx_t_3 != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + + /* "pysam/libcbcf.pyx":3271 + * + * cdef bint cmp = self is other or ( + * s.pos == o.pos # <<<<<<<<<<<<<< + * and s.rlen == o.rlen + * and ((bcf_float_is_missing(s.qual) and bcf_float_is_missing(o.qual)) + */ + __pyx_t_4 = ((__pyx_v_s->pos == __pyx_v_o->pos) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + + /* "pysam/libcbcf.pyx":3272 + * cdef bint cmp = self is other or ( + * s.pos == o.pos + * and s.rlen == o.rlen # <<<<<<<<<<<<<< + * and ((bcf_float_is_missing(s.qual) and bcf_float_is_missing(o.qual)) + * or s.qual == o.qual) + */ + __pyx_t_4 = ((__pyx_v_s->rlen == __pyx_v_o->rlen) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + + /* "pysam/libcbcf.pyx":3273 + * s.pos == o.pos + * and s.rlen == o.rlen + * and ((bcf_float_is_missing(s.qual) and bcf_float_is_missing(o.qual)) # <<<<<<<<<<<<<< + * or s.qual == o.qual) + * and s.n_sample == o.n_sample + */ + __pyx_t_4 = (bcf_float_is_missing(__pyx_v_s->qual) != 0); + if (!__pyx_t_4) { + goto __pyx_L9_next_or; + } else { + } + __pyx_t_4 = (bcf_float_is_missing(__pyx_v_o->qual) != 0); + if (!__pyx_t_4) { + } else { + goto __pyx_L8_next_and; + } + __pyx_L9_next_or:; + + /* "pysam/libcbcf.pyx":3274 + * and s.rlen == o.rlen + * and ((bcf_float_is_missing(s.qual) and bcf_float_is_missing(o.qual)) + * or s.qual == o.qual) # <<<<<<<<<<<<<< + * and s.n_sample == o.n_sample + * and s.n_allele == o.n_allele + */ + __pyx_t_4 = ((__pyx_v_s->qual == __pyx_v_o->qual) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_L8_next_and:; + + /* "pysam/libcbcf.pyx":3275 + * and ((bcf_float_is_missing(s.qual) and bcf_float_is_missing(o.qual)) + * or s.qual == o.qual) + * and s.n_sample == o.n_sample # <<<<<<<<<<<<<< + * and s.n_allele == o.n_allele + * and self.contig == other.contig + */ + __pyx_t_4 = ((__pyx_v_s->n_sample == __pyx_v_o->n_sample) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + + /* "pysam/libcbcf.pyx":3276 + * or s.qual == o.qual) + * and s.n_sample == o.n_sample + * and s.n_allele == o.n_allele # <<<<<<<<<<<<<< + * and self.contig == other.contig + * and self.alleles == other.alleles + */ + __pyx_t_4 = ((__pyx_v_s->n_allele == __pyx_v_o->n_allele) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + + /* "pysam/libcbcf.pyx":3277 + * and s.n_sample == o.n_sample + * and s.n_allele == o.n_allele + * and self.contig == other.contig # <<<<<<<<<<<<<< + * and self.alleles == other.alleles + * and self.id == other.id + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contig); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3277, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_contig); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3277, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_5, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3277, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 3277, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + + /* "pysam/libcbcf.pyx":3278 + * and s.n_allele == o.n_allele + * and self.contig == other.contig + * and self.alleles == other.alleles # <<<<<<<<<<<<<< + * and self.id == other.id + * and self.info == other.info + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_alleles); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3278, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_alleles); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3278, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_7, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3278, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 3278, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + + /* "pysam/libcbcf.pyx":3279 + * and self.contig == other.contig + * and self.alleles == other.alleles + * and self.id == other.id # <<<<<<<<<<<<<< + * and self.info == other.info + * and self.filter == other.filter + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3279, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_id); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3279, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_5, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3279, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 3279, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + + /* "pysam/libcbcf.pyx":3280 + * and self.alleles == other.alleles + * and self.id == other.id + * and self.info == other.info # <<<<<<<<<<<<<< + * and self.filter == other.filter + * and self.samples == other.samples) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3280, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_info); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3280, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_7, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3280, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 3280, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + + /* "pysam/libcbcf.pyx":3281 + * and self.id == other.id + * and self.info == other.info + * and self.filter == other.filter # <<<<<<<<<<<<<< + * and self.samples == other.samples) + * + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_filter); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3281, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_filter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3281, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_5, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3281, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 3281, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + + /* "pysam/libcbcf.pyx":3282 + * and self.info == other.info + * and self.filter == other.filter + * and self.samples == other.samples) # <<<<<<<<<<<<<< + * + * if op == 3: + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_samples); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3282, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_samples); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3282, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_7, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3282, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 3282, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_1 = __pyx_t_4; + __pyx_L4_bool_binop_done:; + __pyx_v_cmp = __pyx_t_1; + + /* "pysam/libcbcf.pyx":3284 + * and self.samples == other.samples) + * + * if op == 3: # <<<<<<<<<<<<<< + * cmp = not cmp + * + */ + __pyx_t_1 = ((__pyx_v_op == 3) != 0); + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":3285 + * + * if op == 3: + * cmp = not cmp # <<<<<<<<<<<<<< + * + * return cmp + */ + __pyx_v_cmp = (!(__pyx_v_cmp != 0)); + + /* "pysam/libcbcf.pyx":3284 + * and self.samples == other.samples) + * + * if op == 3: # <<<<<<<<<<<<<< + * cmp = not cmp + * + */ + } + + /* "pysam/libcbcf.pyx":3287 + * cmp = not cmp + * + * return cmp # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_v_cmp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":3263 + * return makeVariantRecordSamples(self) + * + * def __richcmp__(VariantRecord self not None, VariantRecord other not None, int op): # <<<<<<<<<<<<<< + * if op != 2 and op != 3: + * return NotImplemented + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecord.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":3289 + * return cmp + * * def __str__(self): # <<<<<<<<<<<<<< * cdef kstring_t line * cdef char c */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_9__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_9__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_11__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_11__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantRecord_10__str__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_10__str__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self) { kstring_t __pyx_v_line; PyObject *__pyx_v_ret = NULL; PyObject *__pyx_r = NULL; @@ -46710,9 +53928,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__str__", 0); - __Pyx_TraceCall("__str__", __pyx_f[0], 2818, 0, __PYX_ERR(0, 2818, __pyx_L1_error)); + __Pyx_TraceCall("__str__", __pyx_f[0], 3289, 0, __PYX_ERR(0, 3289, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2822 + /* "pysam/libcbcf.pyx":3293 * cdef char c * * line.l = line.m = 0 # <<<<<<<<<<<<<< @@ -46722,7 +53940,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ __pyx_v_line.l = 0; __pyx_v_line.m = 0; - /* "pysam/libcbcf.pyx":2823 + /* "pysam/libcbcf.pyx":3294 * * line.l = line.m = 0 * line.s = NULL # <<<<<<<<<<<<<< @@ -46731,7 +53949,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ */ __pyx_v_line.s = NULL; - /* "pysam/libcbcf.pyx":2825 + /* "pysam/libcbcf.pyx":3296 * line.s = NULL * * if vcf_format(self.header.ptr, self.ptr, &line) < 0: # <<<<<<<<<<<<<< @@ -46741,7 +53959,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ __pyx_t_1 = ((vcf_format(__pyx_v_self->header->ptr, __pyx_v_self->ptr, (&__pyx_v_line)) < 0) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":2826 + /* "pysam/libcbcf.pyx":3297 * * if vcf_format(self.header.ptr, self.ptr, &line) < 0: * if line.m: # <<<<<<<<<<<<<< @@ -46751,7 +53969,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ __pyx_t_1 = (__pyx_v_line.m != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":2827 + /* "pysam/libcbcf.pyx":3298 * if vcf_format(self.header.ptr, self.ptr, &line) < 0: * if line.m: * free(line.s) # <<<<<<<<<<<<<< @@ -46760,7 +53978,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ */ free(__pyx_v_line.s); - /* "pysam/libcbcf.pyx":2826 + /* "pysam/libcbcf.pyx":3297 * * if vcf_format(self.header.ptr, self.ptr, &line) < 0: * if line.m: # <<<<<<<<<<<<<< @@ -46769,20 +53987,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ */ } - /* "pysam/libcbcf.pyx":2828 + /* "pysam/libcbcf.pyx":3299 * if line.m: * free(line.s) * raise ValueError('vcf_format failed') # <<<<<<<<<<<<<< * * # Strip CR/LF? */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__162, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2828, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__170, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3299, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 2828, __pyx_L1_error) + __PYX_ERR(0, 3299, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2825 + /* "pysam/libcbcf.pyx":3296 * line.s = NULL * * if vcf_format(self.header.ptr, self.ptr, &line) < 0: # <<<<<<<<<<<<<< @@ -46791,19 +54009,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ */ } - /* "pysam/libcbcf.pyx":2837 + /* "pysam/libcbcf.pyx":3308 * # line.l -= 1 * * ret = charptr_to_str_w_len(line.s, line.l) # <<<<<<<<<<<<<< * * if line.m: */ - __pyx_t_2 = __pyx_f_5pysam_9libcutils_charptr_to_str_w_len(__pyx_v_line.s, __pyx_v_line.l, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2837, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_charptr_to_str_w_len(__pyx_v_line.s, __pyx_v_line.l, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3308, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_ret = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":2839 + /* "pysam/libcbcf.pyx":3310 * ret = charptr_to_str_w_len(line.s, line.l) * * if line.m: # <<<<<<<<<<<<<< @@ -46813,7 +54031,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ __pyx_t_1 = (__pyx_v_line.m != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":2840 + /* "pysam/libcbcf.pyx":3311 * * if line.m: * free(line.s) # <<<<<<<<<<<<<< @@ -46822,7 +54040,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ */ free(__pyx_v_line.s); - /* "pysam/libcbcf.pyx":2839 + /* "pysam/libcbcf.pyx":3310 * ret = charptr_to_str_w_len(line.s, line.l) * * if line.m: # <<<<<<<<<<<<<< @@ -46831,7 +54049,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ */ } - /* "pysam/libcbcf.pyx":2842 + /* "pysam/libcbcf.pyx":3313 * free(line.s) * * return ret # <<<<<<<<<<<<<< @@ -46843,8 +54061,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2818 - * return makeVariantRecordSamples(self) + /* "pysam/libcbcf.pyx":3289 + * return cmp * * def __str__(self): # <<<<<<<<<<<<<< * cdef kstring_t line @@ -46864,6 +54082,49 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ return __pyx_r; } +/* "pysam/libcbcf.pxd":78 + * + * cdef class VariantRecord(object): + * cdef readonly VariantHeader header # <<<<<<<<<<<<<< + * cdef bcf1_t *ptr + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_6header_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantRecord_6header___get__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_6header___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 78, 0, __PYX_ERR(1, 78, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); + __pyx_r = ((PyObject *)__pyx_v_self->header); + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecord.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * raise TypeError("self.ptr cannot be converted to a Python object for pickling") @@ -46871,26 +54132,26 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_8__str__(struct __pyx_ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_11__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_13VariantRecord_10__reduce_cython__[] = "VariantRecord.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_11__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_13__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_13VariantRecord_12__reduce_cython__[] = "VariantRecord.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_13__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantRecord_10__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantRecord_12__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_10__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_12__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -46898,11 +54159,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_10__reduce_cython__(CY * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__163, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__171, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + __PYX_ERR(2, 2, __pyx_L1_error) /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< @@ -46929,37 +54190,37 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_10__reduce_cython__(CY */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_13__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_13VariantRecord_12__setstate_cython__[] = "VariantRecord.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_13__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_15__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_13VariantRecord_14__setstate_cython__[] = "VariantRecord.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_13VariantRecord_15__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantRecord_12__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_13VariantRecord_14__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_14__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 3, 0, __PYX_ERR(2, 3, __pyx_L1_error)); /* "(tree fragment)":4 * raise TypeError("self.ptr cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__164, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__172, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -46979,7 +54240,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13VariantRecord_12__setstate_cython__( return __pyx_r; } -/* "pysam/libcbcf.pyx":2845 +/* "pysam/libcbcf.pyx":3316 * * * cdef VariantRecord makeVariantRecord(VariantHeader header, bcf1_t *r): # <<<<<<<<<<<<<< @@ -47001,33 +54262,33 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("makeVariantRecord", 0); - __Pyx_TraceCall("makeVariantRecord", __pyx_f[0], 2845, 0, __PYX_ERR(0, 2845, __pyx_L1_error)); + __Pyx_TraceCall("makeVariantRecord", __pyx_f[0], 3316, 0, __PYX_ERR(0, 3316, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2846 + /* "pysam/libcbcf.pyx":3317 * * cdef VariantRecord makeVariantRecord(VariantHeader header, bcf1_t *r): * if not header: # <<<<<<<<<<<<<< * raise ValueError('invalid VariantHeader') * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2846, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 3317, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2847 + /* "pysam/libcbcf.pyx":3318 * cdef VariantRecord makeVariantRecord(VariantHeader header, bcf1_t *r): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * if not r: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__165, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2847, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__173, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2847, __pyx_L1_error) + __PYX_ERR(0, 3318, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2846 + /* "pysam/libcbcf.pyx":3317 * * cdef VariantRecord makeVariantRecord(VariantHeader header, bcf1_t *r): * if not header: # <<<<<<<<<<<<<< @@ -47036,7 +54297,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m */ } - /* "pysam/libcbcf.pyx":2849 + /* "pysam/libcbcf.pyx":3320 * raise ValueError('invalid VariantHeader') * * if not r: # <<<<<<<<<<<<<< @@ -47046,20 +54307,20 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m __pyx_t_2 = ((!(__pyx_v_r != 0)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2850 + /* "pysam/libcbcf.pyx":3321 * * if not r: * raise ValueError('cannot create VariantRecord') # <<<<<<<<<<<<<< * * if r.errcode: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__166, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2850, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__174, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3321, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 2850, __pyx_L1_error) + __PYX_ERR(0, 3321, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2849 + /* "pysam/libcbcf.pyx":3320 * raise ValueError('invalid VariantHeader') * * if not r: # <<<<<<<<<<<<<< @@ -47068,7 +54329,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m */ } - /* "pysam/libcbcf.pyx":2852 + /* "pysam/libcbcf.pyx":3323 * raise ValueError('cannot create VariantRecord') * * if r.errcode: # <<<<<<<<<<<<<< @@ -47078,19 +54339,19 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m __pyx_t_2 = (__pyx_v_r->errcode != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":2853 + /* "pysam/libcbcf.pyx":3324 * * if r.errcode: * msg = [] # <<<<<<<<<<<<<< * #if r.errcode & BCF_ERR_CTG_UNDEF: * # msg.append('undefined contig') */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2853, __pyx_L1_error) + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3324, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_msg = __pyx_t_3; __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2858 + /* "pysam/libcbcf.pyx":3329 * #if r.errcode & BCF_ERR_TAG_UNDEF: * # msg.append('undefined tag') * if r.errcode & BCF_ERR_NCOLS: # <<<<<<<<<<<<<< @@ -47100,16 +54361,16 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m __pyx_t_2 = ((__pyx_v_r->errcode & BCF_ERR_NCOLS) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":2859 + /* "pysam/libcbcf.pyx":3330 * # msg.append('undefined tag') * if r.errcode & BCF_ERR_NCOLS: * msg.append('invalid number of columns') # <<<<<<<<<<<<<< * if r.errcode & BCF_ERR_LIMITS: * msg.append('limits violated') */ - __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_msg, __pyx_kp_s_invalid_number_of_columns); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 2859, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_msg, __pyx_kp_s_invalid_number_of_columns); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 3330, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2858 + /* "pysam/libcbcf.pyx":3329 * #if r.errcode & BCF_ERR_TAG_UNDEF: * # msg.append('undefined tag') * if r.errcode & BCF_ERR_NCOLS: # <<<<<<<<<<<<<< @@ -47118,7 +54379,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m */ } - /* "pysam/libcbcf.pyx":2860 + /* "pysam/libcbcf.pyx":3331 * if r.errcode & BCF_ERR_NCOLS: * msg.append('invalid number of columns') * if r.errcode & BCF_ERR_LIMITS: # <<<<<<<<<<<<<< @@ -47128,16 +54389,16 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m __pyx_t_2 = ((__pyx_v_r->errcode & BCF_ERR_LIMITS) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":2861 + /* "pysam/libcbcf.pyx":3332 * msg.append('invalid number of columns') * if r.errcode & BCF_ERR_LIMITS: * msg.append('limits violated') # <<<<<<<<<<<<<< * if r.errcode & BCF_ERR_CHAR: * msg.append('invalid character found') */ - __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_msg, __pyx_kp_s_limits_violated); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 2861, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_msg, __pyx_kp_s_limits_violated); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 3332, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2860 + /* "pysam/libcbcf.pyx":3331 * if r.errcode & BCF_ERR_NCOLS: * msg.append('invalid number of columns') * if r.errcode & BCF_ERR_LIMITS: # <<<<<<<<<<<<<< @@ -47146,7 +54407,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m */ } - /* "pysam/libcbcf.pyx":2862 + /* "pysam/libcbcf.pyx":3333 * if r.errcode & BCF_ERR_LIMITS: * msg.append('limits violated') * if r.errcode & BCF_ERR_CHAR: # <<<<<<<<<<<<<< @@ -47156,16 +54417,16 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m __pyx_t_2 = ((__pyx_v_r->errcode & BCF_ERR_CHAR) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":2863 + /* "pysam/libcbcf.pyx":3334 * msg.append('limits violated') * if r.errcode & BCF_ERR_CHAR: * msg.append('invalid character found') # <<<<<<<<<<<<<< * if r.errcode & BCF_ERR_CTG_INVALID: * msg.append('invalid contig') */ - __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_msg, __pyx_kp_s_invalid_character_found); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 2863, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_msg, __pyx_kp_s_invalid_character_found); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 3334, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2862 + /* "pysam/libcbcf.pyx":3333 * if r.errcode & BCF_ERR_LIMITS: * msg.append('limits violated') * if r.errcode & BCF_ERR_CHAR: # <<<<<<<<<<<<<< @@ -47174,7 +54435,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m */ } - /* "pysam/libcbcf.pyx":2864 + /* "pysam/libcbcf.pyx":3335 * if r.errcode & BCF_ERR_CHAR: * msg.append('invalid character found') * if r.errcode & BCF_ERR_CTG_INVALID: # <<<<<<<<<<<<<< @@ -47184,16 +54445,16 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m __pyx_t_2 = ((__pyx_v_r->errcode & BCF_ERR_CTG_INVALID) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":2865 + /* "pysam/libcbcf.pyx":3336 * msg.append('invalid character found') * if r.errcode & BCF_ERR_CTG_INVALID: * msg.append('invalid contig') # <<<<<<<<<<<<<< * if r.errcode & BCF_ERR_TAG_INVALID: * msg.append('invalid tag') */ - __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_msg, __pyx_kp_s_invalid_contig); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 2865, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_msg, __pyx_kp_s_invalid_contig_2); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 3336, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2864 + /* "pysam/libcbcf.pyx":3335 * if r.errcode & BCF_ERR_CHAR: * msg.append('invalid character found') * if r.errcode & BCF_ERR_CTG_INVALID: # <<<<<<<<<<<<<< @@ -47202,7 +54463,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m */ } - /* "pysam/libcbcf.pyx":2866 + /* "pysam/libcbcf.pyx":3337 * if r.errcode & BCF_ERR_CTG_INVALID: * msg.append('invalid contig') * if r.errcode & BCF_ERR_TAG_INVALID: # <<<<<<<<<<<<<< @@ -47212,16 +54473,16 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m __pyx_t_2 = ((__pyx_v_r->errcode & BCF_ERR_TAG_INVALID) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":2867 + /* "pysam/libcbcf.pyx":3338 * msg.append('invalid contig') * if r.errcode & BCF_ERR_TAG_INVALID: * msg.append('invalid tag') # <<<<<<<<<<<<<< * * if msg: */ - __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_msg, __pyx_kp_s_invalid_tag); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 2867, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_msg, __pyx_kp_s_invalid_tag); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 3338, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2866 + /* "pysam/libcbcf.pyx":3337 * if r.errcode & BCF_ERR_CTG_INVALID: * msg.append('invalid contig') * if r.errcode & BCF_ERR_TAG_INVALID: # <<<<<<<<<<<<<< @@ -47230,36 +54491,36 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m */ } - /* "pysam/libcbcf.pyx":2869 + /* "pysam/libcbcf.pyx":3340 * msg.append('invalid tag') * * if msg: # <<<<<<<<<<<<<< * msg = ', '.join(msg) * raise ValueError('Error(s) reading record: {}'.format(msg)) */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_msg); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2869, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_msg); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3340, __pyx_L1_error) if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":2870 + /* "pysam/libcbcf.pyx":3341 * * if msg: * msg = ', '.join(msg) # <<<<<<<<<<<<<< * raise ValueError('Error(s) reading record: {}'.format(msg)) * */ - __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__167, __pyx_v_msg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2870, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__175, __pyx_v_msg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3341, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_msg, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":2871 + /* "pysam/libcbcf.pyx":3342 * if msg: * msg = ', '.join(msg) * raise ValueError('Error(s) reading record: {}'.format(msg)) # <<<<<<<<<<<<<< * * cdef VariantRecord record = VariantRecord.__new__(VariantRecord) */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Error_s_reading_record, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2871, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Error_s_reading_record, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { @@ -47272,13 +54533,13 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_msg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2871, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_msg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_msg}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2871, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3342, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -47286,32 +54547,32 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_msg}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2871, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3342, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2871, __pyx_L1_error) + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v_msg); __Pyx_GIVEREF(__pyx_v_msg); PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_msg); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2871, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2871, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 2871, __pyx_L1_error) + __PYX_ERR(0, 3342, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2869 + /* "pysam/libcbcf.pyx":3340 * msg.append('invalid tag') * * if msg: # <<<<<<<<<<<<<< @@ -47320,7 +54581,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m */ } - /* "pysam/libcbcf.pyx":2852 + /* "pysam/libcbcf.pyx":3323 * raise ValueError('cannot create VariantRecord') * * if r.errcode: # <<<<<<<<<<<<<< @@ -47329,19 +54590,19 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m */ } - /* "pysam/libcbcf.pyx":2873 + /* "pysam/libcbcf.pyx":3344 * raise ValueError('Error(s) reading record: {}'.format(msg)) * * cdef VariantRecord record = VariantRecord.__new__(VariantRecord) # <<<<<<<<<<<<<< * record.header = header * record.ptr = r */ - __pyx_t_5 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantRecord(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecord), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2873, __pyx_L1_error) + __pyx_t_5 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantRecord(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecord), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3344, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __pyx_v_record = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcbcf.pyx":2874 + /* "pysam/libcbcf.pyx":3345 * * cdef VariantRecord record = VariantRecord.__new__(VariantRecord) * record.header = header # <<<<<<<<<<<<<< @@ -47354,7 +54615,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m __Pyx_DECREF(((PyObject *)__pyx_v_record->header)); __pyx_v_record->header = __pyx_v_header; - /* "pysam/libcbcf.pyx":2875 + /* "pysam/libcbcf.pyx":3346 * cdef VariantRecord record = VariantRecord.__new__(VariantRecord) * record.header = header * record.ptr = r # <<<<<<<<<<<<<< @@ -47363,7 +54624,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m */ __pyx_v_record->ptr = __pyx_v_r; - /* "pysam/libcbcf.pyx":2877 + /* "pysam/libcbcf.pyx":3348 * record.ptr = r * * return record # <<<<<<<<<<<<<< @@ -47375,7 +54636,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m __pyx_r = __pyx_v_record; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2845 + /* "pysam/libcbcf.pyx":3316 * * * cdef VariantRecord makeVariantRecord(VariantHeader header, bcf1_t *r): # <<<<<<<<<<<<<< @@ -47400,7 +54661,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_m return __pyx_r; } -/* "pysam/libcbcf.pyx":2891 +/* "pysam/libcbcf.pyx":3362 * from format name to values. * """ * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -47434,22 +54695,22 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample___init__(CYTHON_UNUSED __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 2891, 0, __PYX_ERR(0, 2891, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 3362, 0, __PYX_ERR(0, 3362, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2892 + /* "pysam/libcbcf.pyx":3363 * """ * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * @property */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__168, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2892, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__176, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 2892, __pyx_L1_error) + __PYX_ERR(0, 3363, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2891 + /* "pysam/libcbcf.pyx":3362 * from format name to values. * """ * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -47467,7 +54728,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample___init__(CYTHON_UNUSED return __pyx_r; } -/* "pysam/libcbcf.pyx":2895 +/* "pysam/libcbcf.pyx":3366 * * @property * def name(self): # <<<<<<<<<<<<<< @@ -47490,81 +54751,83 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_4name_1__get__(P static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4name___get__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self) { bcf_hdr_t *__pyx_v_hdr; - CYTHON_UNUSED bcf1_t *__pyx_v_r; + bcf1_t *__pyx_v_r; int32_t __pyx_v_n; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations bcf_hdr_t *__pyx_t_1; bcf1_t *__pyx_t_2; - int __pyx_t_3; + uint32_t __pyx_t_3; int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2895, 0, __PYX_ERR(0, 2895, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3366, 0, __PYX_ERR(0, 3366, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2897 + /* "pysam/libcbcf.pyx":3368 * def name(self): * """sample name""" * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr - * cdef int32_t n = bcf_hdr_nsamples(hdr) + * cdef int32_t n = r.n_sample */ __pyx_t_1 = __pyx_v_self->record->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2898 + /* "pysam/libcbcf.pyx":3369 * """sample name""" * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * cdef int32_t n = bcf_hdr_nsamples(hdr) + * cdef int32_t n = r.n_sample * */ __pyx_t_2 = __pyx_v_self->record->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2899 + /* "pysam/libcbcf.pyx":3370 * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr - * cdef int32_t n = bcf_hdr_nsamples(hdr) # <<<<<<<<<<<<<< + * cdef int32_t n = r.n_sample # <<<<<<<<<<<<<< * * if self.index < 0 or self.index >= n: */ - __pyx_v_n = bcf_hdr_nsamples(__pyx_v_hdr); + __pyx_t_3 = __pyx_v_r->n_sample; + __pyx_v_n = __pyx_t_3; - /* "pysam/libcbcf.pyx":2901 - * cdef int32_t n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":3372 + * cdef int32_t n = r.n_sample * * if self.index < 0 or self.index >= n: # <<<<<<<<<<<<<< * raise ValueError('invalid sample index') * */ - __pyx_t_4 = ((__pyx_v_self->index < 0) != 0); - if (!__pyx_t_4) { + __pyx_t_5 = ((__pyx_v_self->index < 0) != 0); + if (!__pyx_t_5) { } else { - __pyx_t_3 = __pyx_t_4; + __pyx_t_4 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } - __pyx_t_4 = ((__pyx_v_self->index >= __pyx_v_n) != 0); - __pyx_t_3 = __pyx_t_4; + __pyx_t_5 = ((__pyx_v_self->index >= __pyx_v_n) != 0); + __pyx_t_4 = __pyx_t_5; __pyx_L4_bool_binop_done:; - if (unlikely(__pyx_t_3)) { + if (unlikely(__pyx_t_4)) { - /* "pysam/libcbcf.pyx":2902 + /* "pysam/libcbcf.pyx":3373 * * if self.index < 0 or self.index >= n: * raise ValueError('invalid sample index') # <<<<<<<<<<<<<< * * return charptr_to_str(hdr.samples[self.index]) */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__169, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2902, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 2902, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__177, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3373, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 3373, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2901 - * cdef int32_t n = bcf_hdr_nsamples(hdr) + /* "pysam/libcbcf.pyx":3372 + * cdef int32_t n = r.n_sample * * if self.index < 0 or self.index >= n: # <<<<<<<<<<<<<< * raise ValueError('invalid sample index') @@ -47572,7 +54835,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4name___get__(st */ } - /* "pysam/libcbcf.pyx":2904 + /* "pysam/libcbcf.pyx":3375 * raise ValueError('invalid sample index') * * return charptr_to_str(hdr.samples[self.index]) # <<<<<<<<<<<<<< @@ -47580,13 +54843,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4name___get__(st * @property */ __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_hdr->samples[__pyx_v_self->index]), NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2904, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; + __pyx_t_6 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_hdr->samples[__pyx_v_self->index]), NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3375, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2895 + /* "pysam/libcbcf.pyx":3366 * * @property * def name(self): # <<<<<<<<<<<<<< @@ -47596,7 +54859,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4name___get__(st /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -47606,7 +54869,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4name___get__(st return __pyx_r; } -/* "pysam/libcbcf.pyx":2907 +/* "pysam/libcbcf.pyx":3378 * * @property * def allele_indices(self): # <<<<<<<<<<<<<< @@ -47633,9 +54896,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_14allele_indices __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2907, 0, __PYX_ERR(0, 2907, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3378, 0, __PYX_ERR(0, 3378, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2909 + /* "pysam/libcbcf.pyx":3380 * def allele_indices(self): * """allele indices for called genotype, if present. Otherwise None""" * return bcf_format_get_allele_indices(self) # <<<<<<<<<<<<<< @@ -47643,13 +54906,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_14allele_indices * @allele_indices.setter */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2909, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf_bcf_format_get_allele_indices(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3380, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2907 + /* "pysam/libcbcf.pyx":3378 * * @property * def allele_indices(self): # <<<<<<<<<<<<<< @@ -47669,7 +54932,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_14allele_indices return __pyx_r; } -/* "pysam/libcbcf.pyx":2912 +/* "pysam/libcbcf.pyx":3383 * * @allele_indices.setter * def allele_indices(self, value): # <<<<<<<<<<<<<< @@ -47695,18 +54958,18 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_14allele_indices_2__se __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2912, 0, __PYX_ERR(0, 2912, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3383, 0, __PYX_ERR(0, 3383, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2913 + /* "pysam/libcbcf.pyx":3384 * @allele_indices.setter * def allele_indices(self, value): * self['GT'] = value # <<<<<<<<<<<<<< * * @allele_indices.deleter */ - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_n_s_GT, __pyx_v_value) < 0)) __PYX_ERR(0, 2913, __pyx_L1_error) + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_n_s_GT, __pyx_v_value) < 0)) __PYX_ERR(0, 3384, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2912 + /* "pysam/libcbcf.pyx":3383 * * @allele_indices.setter * def allele_indices(self, value): # <<<<<<<<<<<<<< @@ -47726,7 +54989,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_14allele_indices_2__se return __pyx_r; } -/* "pysam/libcbcf.pyx":2916 +/* "pysam/libcbcf.pyx":3387 * * @allele_indices.deleter * def allele_indices(self): # <<<<<<<<<<<<<< @@ -47752,18 +55015,18 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_14allele_indices_4__de __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_TraceCall("__del__", __pyx_f[0], 2916, 0, __PYX_ERR(0, 2916, __pyx_L1_error)); + __Pyx_TraceCall("__del__", __pyx_f[0], 3387, 0, __PYX_ERR(0, 3387, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2917 + /* "pysam/libcbcf.pyx":3388 * @allele_indices.deleter * def allele_indices(self): * self['GT'] = () # <<<<<<<<<<<<<< * * @property */ - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_n_s_GT, __pyx_empty_tuple) < 0)) __PYX_ERR(0, 2917, __pyx_L1_error) + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_n_s_GT, __pyx_empty_tuple) < 0)) __PYX_ERR(0, 3388, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2916 + /* "pysam/libcbcf.pyx":3387 * * @allele_indices.deleter * def allele_indices(self): # <<<<<<<<<<<<<< @@ -47783,7 +55046,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_14allele_indices_4__de return __pyx_r; } -/* "pysam/libcbcf.pyx":2920 +/* "pysam/libcbcf.pyx":3391 * * @property * def alleles(self): # <<<<<<<<<<<<<< @@ -47810,9 +55073,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_7alleles___get__ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2920, 0, __PYX_ERR(0, 2920, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3391, 0, __PYX_ERR(0, 3391, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2922 + /* "pysam/libcbcf.pyx":3393 * def alleles(self): * """alleles for called genotype, if present. Otherwise None""" * return bcf_format_get_alleles(self) # <<<<<<<<<<<<<< @@ -47820,13 +55083,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_7alleles___get__ * @alleles.setter */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2922, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf_bcf_format_get_alleles(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3393, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2920 + /* "pysam/libcbcf.pyx":3391 * * @property * def alleles(self): # <<<<<<<<<<<<<< @@ -47846,7 +55109,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_7alleles___get__ return __pyx_r; } -/* "pysam/libcbcf.pyx":2925 +/* "pysam/libcbcf.pyx":3396 * * @alleles.setter * def alleles(self, value): # <<<<<<<<<<<<<< @@ -47872,18 +55135,18 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_7alleles_2__set__(stru __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2925, 0, __PYX_ERR(0, 2925, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3396, 0, __PYX_ERR(0, 3396, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2926 + /* "pysam/libcbcf.pyx":3397 * @alleles.setter * def alleles(self, value): * self['GT'] = value # <<<<<<<<<<<<<< * * @alleles.deleter */ - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_n_s_GT, __pyx_v_value) < 0)) __PYX_ERR(0, 2926, __pyx_L1_error) + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_n_s_GT, __pyx_v_value) < 0)) __PYX_ERR(0, 3397, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2925 + /* "pysam/libcbcf.pyx":3396 * * @alleles.setter * def alleles(self, value): # <<<<<<<<<<<<<< @@ -47903,7 +55166,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_7alleles_2__set__(stru return __pyx_r; } -/* "pysam/libcbcf.pyx":2929 +/* "pysam/libcbcf.pyx":3400 * * @alleles.deleter * def alleles(self): # <<<<<<<<<<<<<< @@ -47929,18 +55192,18 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_7alleles_4__del__(stru __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_TraceCall("__del__", __pyx_f[0], 2929, 0, __PYX_ERR(0, 2929, __pyx_L1_error)); + __Pyx_TraceCall("__del__", __pyx_f[0], 3400, 0, __PYX_ERR(0, 3400, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2930 + /* "pysam/libcbcf.pyx":3401 * @alleles.deleter * def alleles(self): * self['GT'] = () # <<<<<<<<<<<<<< * * @property */ - if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_n_s_GT, __pyx_empty_tuple) < 0)) __PYX_ERR(0, 2930, __pyx_L1_error) + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_n_s_GT, __pyx_empty_tuple) < 0)) __PYX_ERR(0, 3401, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2929 + /* "pysam/libcbcf.pyx":3400 * * @alleles.deleter * def alleles(self): # <<<<<<<<<<<<<< @@ -47960,7 +55223,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_7alleles_4__del__(stru return __pyx_r; } -/* "pysam/libcbcf.pyx":2933 +/* "pysam/libcbcf.pyx":3404 * * @property * def phased(self): # <<<<<<<<<<<<<< @@ -47987,9 +55250,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_6phased___get__( __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 2933, 0, __PYX_ERR(0, 2933, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 3404, 0, __PYX_ERR(0, 3404, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2935 + /* "pysam/libcbcf.pyx":3406 * def phased(self): * """False if genotype is missing or any allele is unphased. Otherwise True.""" * return bcf_sample_get_phased(self) # <<<<<<<<<<<<<< @@ -47997,13 +55260,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_6phased___get__( * @phased.setter */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2935, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_f_5pysam_7libcbcf_bcf_sample_get_phased(__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2933 + /* "pysam/libcbcf.pyx":3404 * * @property * def phased(self): # <<<<<<<<<<<<<< @@ -48023,7 +55286,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_6phased___get__( return __pyx_r; } -/* "pysam/libcbcf.pyx":2938 +/* "pysam/libcbcf.pyx":3409 * * @phased.setter * def phased(self, value): # <<<<<<<<<<<<<< @@ -48051,21 +55314,21 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_6phased_2__set__(struc int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[0], 2938, 0, __PYX_ERR(0, 2938, __pyx_L1_error)); + __Pyx_TraceCall("__set__", __pyx_f[0], 3409, 0, __PYX_ERR(0, 3409, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2939 + /* "pysam/libcbcf.pyx":3410 * @phased.setter * def phased(self, value): * bcf_sample_set_phased(self, value) # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2939, __pyx_L1_error) - __pyx_t_2 = __pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(__pyx_v_self, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2939, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3410, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_7libcbcf_bcf_sample_set_phased(__pyx_v_self, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3410, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":2938 + /* "pysam/libcbcf.pyx":3409 * * @phased.setter * def phased(self, value): # <<<<<<<<<<<<<< @@ -48086,7 +55349,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_6phased_2__set__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":2941 +/* "pysam/libcbcf.pyx":3412 * bcf_sample_set_phased(self, value) * * def __len__(self): # <<<<<<<<<<<<<< @@ -48123,9 +55386,9 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_2__len__(struct uint32_t __pyx_t_6; int __pyx_t_7; __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[0], 2941, 0, __PYX_ERR(0, 2941, __pyx_L1_error)); + __Pyx_TraceCall("__len__", __pyx_f[0], 3412, 0, __PYX_ERR(0, 3412, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2942 + /* "pysam/libcbcf.pyx":3413 * * def __len__(self): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< @@ -48135,7 +55398,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_2__len__(struct __pyx_t_1 = __pyx_v_self->record->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2943 + /* "pysam/libcbcf.pyx":3414 * def __len__(self): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< @@ -48145,7 +55408,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_2__len__(struct __pyx_t_2 = __pyx_v_self->record->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2944 + /* "pysam/libcbcf.pyx":3415 * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr * cdef int i, n = 0 # <<<<<<<<<<<<<< @@ -48154,7 +55417,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_2__len__(struct */ __pyx_v_n = 0; - /* "pysam/libcbcf.pyx":2946 + /* "pysam/libcbcf.pyx":3417 * cdef int i, n = 0 * * if bcf_unpack(r, BCF_UN_FMT) < 0: # <<<<<<<<<<<<<< @@ -48164,20 +55427,20 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_2__len__(struct __pyx_t_3 = ((bcf_unpack(__pyx_v_r, BCF_UN_FMT) < 0) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2947 + /* "pysam/libcbcf.pyx":3418 * * if bcf_unpack(r, BCF_UN_FMT) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * for i in range(r.n_fmt): */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__170, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2947, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__178, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3418, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 2947, __pyx_L1_error) + __PYX_ERR(0, 3418, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2946 + /* "pysam/libcbcf.pyx":3417 * cdef int i, n = 0 * * if bcf_unpack(r, BCF_UN_FMT) < 0: # <<<<<<<<<<<<<< @@ -48186,7 +55449,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_2__len__(struct */ } - /* "pysam/libcbcf.pyx":2949 + /* "pysam/libcbcf.pyx":3420 * raise ValueError('Error unpacking VariantRecord') * * for i in range(r.n_fmt): # <<<<<<<<<<<<<< @@ -48198,7 +55461,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_2__len__(struct for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { __pyx_v_i = __pyx_t_7; - /* "pysam/libcbcf.pyx":2950 + /* "pysam/libcbcf.pyx":3421 * * for i in range(r.n_fmt): * if r.d.fmt[i].p: # <<<<<<<<<<<<<< @@ -48208,7 +55471,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_2__len__(struct __pyx_t_3 = ((__pyx_v_r->d.fmt[__pyx_v_i]).p != 0); if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2951 + /* "pysam/libcbcf.pyx":3422 * for i in range(r.n_fmt): * if r.d.fmt[i].p: * n += 1 # <<<<<<<<<<<<<< @@ -48217,7 +55480,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_2__len__(struct */ __pyx_v_n = (__pyx_v_n + 1); - /* "pysam/libcbcf.pyx":2950 + /* "pysam/libcbcf.pyx":3421 * * for i in range(r.n_fmt): * if r.d.fmt[i].p: # <<<<<<<<<<<<<< @@ -48227,7 +55490,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_2__len__(struct } } - /* "pysam/libcbcf.pyx":2952 + /* "pysam/libcbcf.pyx":3423 * if r.d.fmt[i].p: * n += 1 * return n # <<<<<<<<<<<<<< @@ -48237,7 +55500,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_2__len__(struct __pyx_r = __pyx_v_n; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2941 + /* "pysam/libcbcf.pyx":3412 * bcf_sample_set_phased(self, value) * * def __len__(self): # <<<<<<<<<<<<<< @@ -48256,7 +55519,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_2__len__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":2954 +/* "pysam/libcbcf.pyx":3425 * return n * * def __bool__(self): # <<<<<<<<<<<<<< @@ -48292,9 +55555,9 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4__bool__(struct __pyx uint32_t __pyx_t_6; int __pyx_t_7; __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 2954, 0, __PYX_ERR(0, 2954, __pyx_L1_error)); + __Pyx_TraceCall("__bool__", __pyx_f[0], 3425, 0, __PYX_ERR(0, 3425, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2955 + /* "pysam/libcbcf.pyx":3426 * * def __bool__(self): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< @@ -48304,7 +55567,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4__bool__(struct __pyx __pyx_t_1 = __pyx_v_self->record->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2956 + /* "pysam/libcbcf.pyx":3427 * def __bool__(self): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< @@ -48314,7 +55577,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4__bool__(struct __pyx __pyx_t_2 = __pyx_v_self->record->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2959 + /* "pysam/libcbcf.pyx":3430 * cdef int i * * if bcf_unpack(r, BCF_UN_FMT) < 0: # <<<<<<<<<<<<<< @@ -48324,20 +55587,20 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4__bool__(struct __pyx __pyx_t_3 = ((bcf_unpack(__pyx_v_r, BCF_UN_FMT) < 0) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":2960 + /* "pysam/libcbcf.pyx":3431 * * if bcf_unpack(r, BCF_UN_FMT) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * for i in range(r.n_fmt): */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__171, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2960, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__179, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3431, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 2960, __pyx_L1_error) + __PYX_ERR(0, 3431, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2959 + /* "pysam/libcbcf.pyx":3430 * cdef int i * * if bcf_unpack(r, BCF_UN_FMT) < 0: # <<<<<<<<<<<<<< @@ -48346,7 +55609,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4__bool__(struct __pyx */ } - /* "pysam/libcbcf.pyx":2962 + /* "pysam/libcbcf.pyx":3433 * raise ValueError('Error unpacking VariantRecord') * * for i in range(r.n_fmt): # <<<<<<<<<<<<<< @@ -48358,7 +55621,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4__bool__(struct __pyx for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { __pyx_v_i = __pyx_t_7; - /* "pysam/libcbcf.pyx":2963 + /* "pysam/libcbcf.pyx":3434 * * for i in range(r.n_fmt): * if r.d.fmt[i].p: # <<<<<<<<<<<<<< @@ -48368,7 +55631,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4__bool__(struct __pyx __pyx_t_3 = ((__pyx_v_r->d.fmt[__pyx_v_i]).p != 0); if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":2964 + /* "pysam/libcbcf.pyx":3435 * for i in range(r.n_fmt): * if r.d.fmt[i].p: * return True # <<<<<<<<<<<<<< @@ -48378,7 +55641,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4__bool__(struct __pyx __pyx_r = 1; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2963 + /* "pysam/libcbcf.pyx":3434 * * for i in range(r.n_fmt): * if r.d.fmt[i].p: # <<<<<<<<<<<<<< @@ -48388,7 +55651,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4__bool__(struct __pyx } } - /* "pysam/libcbcf.pyx":2965 + /* "pysam/libcbcf.pyx":3436 * if r.d.fmt[i].p: * return True * return False # <<<<<<<<<<<<<< @@ -48398,7 +55661,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4__bool__(struct __pyx __pyx_r = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2954 + /* "pysam/libcbcf.pyx":3425 * return n * * def __bool__(self): # <<<<<<<<<<<<<< @@ -48417,7 +55680,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_4__bool__(struct __pyx return __pyx_r; } -/* "pysam/libcbcf.pyx":2967 +/* "pysam/libcbcf.pyx":3438 * return False * * def __getitem__(self, key): # <<<<<<<<<<<<<< @@ -48444,9 +55707,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_6__getitem__(str __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[0], 2967, 0, __PYX_ERR(0, 2967, __pyx_L1_error)); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 3438, 0, __PYX_ERR(0, 3438, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2968 + /* "pysam/libcbcf.pyx":3439 * * def __getitem__(self, key): * return bcf_format_get_value(self, key) # <<<<<<<<<<<<<< @@ -48454,13 +55717,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_6__getitem__(str * def __setitem__(self, key, value): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_7libcbcf_bcf_format_get_value(__pyx_v_self, __pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2968, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf_bcf_format_get_value(__pyx_v_self, __pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3439, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":2967 + /* "pysam/libcbcf.pyx":3438 * return False * * def __getitem__(self, key): # <<<<<<<<<<<<<< @@ -48480,7 +55743,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_6__getitem__(str return __pyx_r; } -/* "pysam/libcbcf.pyx":2970 +/* "pysam/libcbcf.pyx":3441 * return bcf_format_get_value(self, key) * * def __setitem__(self, key, value): # <<<<<<<<<<<<<< @@ -48507,20 +55770,20 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_8__setitem__(struct __ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setitem__", 0); - __Pyx_TraceCall("__setitem__", __pyx_f[0], 2970, 0, __PYX_ERR(0, 2970, __pyx_L1_error)); + __Pyx_TraceCall("__setitem__", __pyx_f[0], 3441, 0, __PYX_ERR(0, 3441, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2971 + /* "pysam/libcbcf.pyx":3442 * * def __setitem__(self, key, value): * bcf_format_set_value(self, key, value) # <<<<<<<<<<<<<< * * def __delitem__(self, key): */ - __pyx_t_1 = __pyx_f_5pysam_7libcbcf_bcf_format_set_value(__pyx_v_self, __pyx_v_key, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2971, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf_bcf_format_set_value(__pyx_v_self, __pyx_v_key, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3442, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":2970 + /* "pysam/libcbcf.pyx":3441 * return bcf_format_get_value(self, key) * * def __setitem__(self, key, value): # <<<<<<<<<<<<<< @@ -48541,7 +55804,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_8__setitem__(struct __ return __pyx_r; } -/* "pysam/libcbcf.pyx":2973 +/* "pysam/libcbcf.pyx":3444 * bcf_format_set_value(self, key, value) * * def __delitem__(self, key): # <<<<<<<<<<<<<< @@ -48568,20 +55831,20 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_10__delitem__(struct _ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__delitem__", 0); - __Pyx_TraceCall("__delitem__", __pyx_f[0], 2973, 0, __PYX_ERR(0, 2973, __pyx_L1_error)); + __Pyx_TraceCall("__delitem__", __pyx_f[0], 3444, 0, __PYX_ERR(0, 3444, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2974 + /* "pysam/libcbcf.pyx":3445 * * def __delitem__(self, key): * bcf_format_del_value(self, key) # <<<<<<<<<<<<<< * * def clear(self): */ - __pyx_t_1 = __pyx_f_5pysam_7libcbcf_bcf_format_del_value(__pyx_v_self, __pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2974, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf_bcf_format_del_value(__pyx_v_self, __pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3445, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":2973 + /* "pysam/libcbcf.pyx":3444 * bcf_format_set_value(self, key, value) * * def __delitem__(self, key): # <<<<<<<<<<<<<< @@ -48602,7 +55865,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_10__delitem__(struct _ return __pyx_r; } -/* "pysam/libcbcf.pyx":2976 +/* "pysam/libcbcf.pyx":3447 * bcf_format_del_value(self, key) * * def clear(self): # <<<<<<<<<<<<<< @@ -48641,9 +55904,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_12clear(struct _ PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; __Pyx_RefNannySetupContext("clear", 0); - __Pyx_TraceCall("clear", __pyx_f[0], 2976, 0, __PYX_ERR(0, 2976, __pyx_L1_error)); + __Pyx_TraceCall("clear", __pyx_f[0], 3447, 0, __PYX_ERR(0, 3447, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":2978 + /* "pysam/libcbcf.pyx":3449 * def clear(self): * """Clear all format data (including genotype) for this sample""" * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< @@ -48653,7 +55916,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_12clear(struct _ __pyx_t_1 = __pyx_v_self->record->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2979 + /* "pysam/libcbcf.pyx":3450 * """Clear all format data (including genotype) for this sample""" * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< @@ -48663,7 +55926,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_12clear(struct _ __pyx_t_2 = __pyx_v_self->record->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2983 + /* "pysam/libcbcf.pyx":3454 * cdef int i * * for i in range(r.n_fmt): # <<<<<<<<<<<<<< @@ -48675,7 +55938,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_12clear(struct _ for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_v_i = __pyx_t_5; - /* "pysam/libcbcf.pyx":2984 + /* "pysam/libcbcf.pyx":3455 * * for i in range(r.n_fmt): * fmt = &r.d.fmt[i] # <<<<<<<<<<<<<< @@ -48684,7 +55947,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_12clear(struct _ */ __pyx_v_fmt = (&(__pyx_v_r->d.fmt[__pyx_v_i])); - /* "pysam/libcbcf.pyx":2985 + /* "pysam/libcbcf.pyx":3456 * for i in range(r.n_fmt): * fmt = &r.d.fmt[i] * if fmt.p: # <<<<<<<<<<<<<< @@ -48694,21 +55957,21 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_12clear(struct _ __pyx_t_6 = (__pyx_v_fmt->p != 0); if (__pyx_t_6) { - /* "pysam/libcbcf.pyx":2986 + /* "pysam/libcbcf.pyx":3457 * fmt = &r.d.fmt[i] * if fmt.p: * bcf_format_del_value(self, bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) # <<<<<<<<<<<<<< * * def __iter__(self): */ - __pyx_t_7 = __Pyx_PyBytes_FromString(bcf_hdr_int2id(__pyx_v_hdr, BCF_DT_ID, __pyx_v_fmt->id)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2986, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyBytes_FromString(bcf_hdr_int2id(__pyx_v_hdr, BCF_DT_ID, __pyx_v_fmt->id)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __pyx_f_5pysam_7libcbcf_bcf_format_del_value(__pyx_v_self, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2986, __pyx_L1_error) + __pyx_t_8 = __pyx_f_5pysam_7libcbcf_bcf_format_del_value(__pyx_v_self, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - /* "pysam/libcbcf.pyx":2985 + /* "pysam/libcbcf.pyx":3456 * for i in range(r.n_fmt): * fmt = &r.d.fmt[i] * if fmt.p: # <<<<<<<<<<<<<< @@ -48718,7 +55981,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_12clear(struct _ } } - /* "pysam/libcbcf.pyx":2976 + /* "pysam/libcbcf.pyx":3447 * bcf_format_del_value(self, key) * * def clear(self): # <<<<<<<<<<<<<< @@ -48742,7 +56005,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_12clear(struct _ } static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":2988 +/* "pysam/libcbcf.pyx":3459 * bcf_format_del_value(self, bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -48772,7 +56035,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_14__iter__(struc if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_33___iter__ *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 2988, __pyx_L1_error) + __PYX_ERR(0, 3459, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -48780,7 +56043,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_14__iter__(struc __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantRecordSample___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 2988, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_VariantRecordSample___iter, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 3459, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -48810,7 +56073,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23(__ PyObject *__pyx_t_7 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 2988, 0, __PYX_ERR(0, 2988, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 3459, 0, __PYX_ERR(0, 3459, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L7_resume_from_yield; @@ -48820,9 +56083,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23(__ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2988, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3459, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2989 + /* "pysam/libcbcf.pyx":3460 * * def __iter__(self): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< @@ -48832,7 +56095,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23(__ __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->record->header->ptr; __pyx_cur_scope->__pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":2990 + /* "pysam/libcbcf.pyx":3461 * def __iter__(self): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< @@ -48842,7 +56105,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23(__ __pyx_t_2 = __pyx_cur_scope->__pyx_v_self->record->ptr; __pyx_cur_scope->__pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":2994 + /* "pysam/libcbcf.pyx":3465 * cdef int i * * for i in range(r.n_fmt): # <<<<<<<<<<<<<< @@ -48854,7 +56117,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23(__ for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_5; - /* "pysam/libcbcf.pyx":2995 + /* "pysam/libcbcf.pyx":3466 * * for i in range(r.n_fmt): * fmt = &r.d.fmt[i] # <<<<<<<<<<<<<< @@ -48863,7 +56126,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23(__ */ __pyx_cur_scope->__pyx_v_fmt = (&(__pyx_cur_scope->__pyx_v_r->d.fmt[__pyx_cur_scope->__pyx_v_i])); - /* "pysam/libcbcf.pyx":2996 + /* "pysam/libcbcf.pyx":3467 * for i in range(r.n_fmt): * fmt = &r.d.fmt[i] * if r.d.fmt[i].p: # <<<<<<<<<<<<<< @@ -48873,14 +56136,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23(__ __pyx_t_6 = ((__pyx_cur_scope->__pyx_v_r->d.fmt[__pyx_cur_scope->__pyx_v_i]).p != 0); if (__pyx_t_6) { - /* "pysam/libcbcf.pyx":2997 + /* "pysam/libcbcf.pyx":3468 * fmt = &r.d.fmt[i] * if r.d.fmt[i].p: * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) # <<<<<<<<<<<<<< * * def get(self, key, default=None): */ - __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_int2id(__pyx_cur_scope->__pyx_v_hdr, BCF_DT_ID, __pyx_cur_scope->__pyx_v_fmt->id)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2997, __pyx_L1_error) + __pyx_t_7 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_int2id(__pyx_cur_scope->__pyx_v_hdr, BCF_DT_ID, __pyx_cur_scope->__pyx_v_fmt->id)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3468, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_r = __pyx_t_7; __pyx_t_7 = 0; @@ -48898,9 +56161,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23(__ __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2997, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3468, __pyx_L1_error) - /* "pysam/libcbcf.pyx":2996 + /* "pysam/libcbcf.pyx":3467 * for i in range(r.n_fmt): * fmt = &r.d.fmt[i] * if r.d.fmt[i].p: # <<<<<<<<<<<<<< @@ -48911,7 +56174,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23(__ } CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":2988 + /* "pysam/libcbcf.pyx":3459 * bcf_format_del_value(self, bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -48935,7 +56198,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_16generator23(__ return __pyx_r; } -/* "pysam/libcbcf.pyx":2999 +/* "pysam/libcbcf.pyx":3470 * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) * * def get(self, key, default=None): # <<<<<<<<<<<<<< @@ -48980,7 +56243,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_18get(PyObject * } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 2999, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 3470, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -48996,7 +56259,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_18get(PyObject * } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2999, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3470, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.get", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -49021,9 +56284,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_17get(struct __p PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("get", 0); - __Pyx_TraceCall("get", __pyx_f[0], 2999, 0, __PYX_ERR(0, 2999, __pyx_L1_error)); + __Pyx_TraceCall("get", __pyx_f[0], 3470, 0, __PYX_ERR(0, 3470, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3001 + /* "pysam/libcbcf.pyx":3472 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -49039,7 +56302,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_17get(struct __p __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "pysam/libcbcf.pyx":3002 + /* "pysam/libcbcf.pyx":3473 * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: * return self[key] # <<<<<<<<<<<<<< @@ -49047,13 +56310,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_17get(struct __p * return default */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3002, __pyx_L3_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3473, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L7_try_return; - /* "pysam/libcbcf.pyx":3001 + /* "pysam/libcbcf.pyx":3472 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -49064,7 +56327,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_17get(struct __p __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":3003 + /* "pysam/libcbcf.pyx":3474 * try: * return self[key] * except KeyError: # <<<<<<<<<<<<<< @@ -49074,12 +56337,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_17get(struct __p __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); if (__pyx_t_5) { __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 3003, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 3474, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcbcf.pyx":3004 + /* "pysam/libcbcf.pyx":3475 * return self[key] * except KeyError: * return default # <<<<<<<<<<<<<< @@ -49097,7 +56360,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_17get(struct __p goto __pyx_L5_except_error; __pyx_L5_except_error:; - /* "pysam/libcbcf.pyx":3001 + /* "pysam/libcbcf.pyx":3472 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -49123,7 +56386,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_17get(struct __p goto __pyx_L0; } - /* "pysam/libcbcf.pyx":2999 + /* "pysam/libcbcf.pyx":3470 * yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id)) * * def get(self, key, default=None): # <<<<<<<<<<<<<< @@ -49145,7 +56408,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_17get(struct __p return __pyx_r; } -/* "pysam/libcbcf.pyx":3006 +/* "pysam/libcbcf.pyx":3477 * return default * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -49169,7 +56432,7 @@ static int __pyx_pw_5pysam_7libcbcf_19VariantRecordSample_20__contains__(PyObjec static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_19__contains__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self, PyObject *__pyx_v_key) { bcf_hdr_t *__pyx_v_hdr; bcf1_t *__pyx_v_r; - PyObject *__pyx_v_bkey = NULL; + PyObject *__pyx_v_bkey = 0; bcf_fmt_t *__pyx_v_fmt; int __pyx_r; __Pyx_TraceDeclarations @@ -49181,56 +56444,56 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_19__contains__(struct int __pyx_t_5; int __pyx_t_6; __Pyx_RefNannySetupContext("__contains__", 0); - __Pyx_TraceCall("__contains__", __pyx_f[0], 3006, 0, __PYX_ERR(0, 3006, __pyx_L1_error)); + __Pyx_TraceCall("__contains__", __pyx_f[0], 3477, 0, __PYX_ERR(0, 3477, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3007 + /* "pysam/libcbcf.pyx":3478 * * def __contains__(self, key): * cdef bcf_hdr_t *hdr = self.record.header.ptr # <<<<<<<<<<<<<< * cdef bcf1_t *r = self.record.ptr - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ __pyx_t_1 = __pyx_v_self->record->header->ptr; __pyx_v_hdr = __pyx_t_1; - /* "pysam/libcbcf.pyx":3008 + /* "pysam/libcbcf.pyx":3479 * def __contains__(self, key): * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr # <<<<<<<<<<<<<< - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) */ __pyx_t_2 = __pyx_v_self->record->ptr; __pyx_v_r = __pyx_t_2; - /* "pysam/libcbcf.pyx":3009 + /* "pysam/libcbcf.pyx":3480 * cdef bcf_hdr_t *hdr = self.record.header.ptr * cdef bcf1_t *r = self.record.ptr - * bkey = force_bytes(key) # <<<<<<<<<<<<<< + * cdef bytes bkey = force_bytes(key) # <<<<<<<<<<<<<< * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * return fmt != NULL and fmt.p != NULL */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3009, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_key, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3480, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_bkey = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":3010 + /* "pysam/libcbcf.pyx":3481 * cdef bcf1_t *r = self.record.ptr - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) # <<<<<<<<<<<<<< * return fmt != NULL and fmt.p != NULL * */ if (unlikely(__pyx_v_bkey == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 3010, __pyx_L1_error) + __PYX_ERR(0, 3481, __pyx_L1_error) } - __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 3010, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_bkey); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 3481, __pyx_L1_error) __pyx_v_fmt = bcf_get_fmt(__pyx_v_hdr, __pyx_v_r, __pyx_t_4); - /* "pysam/libcbcf.pyx":3011 - * bkey = force_bytes(key) + /* "pysam/libcbcf.pyx":3482 + * cdef bytes bkey = force_bytes(key) * cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) * return fmt != NULL and fmt.p != NULL # <<<<<<<<<<<<<< * @@ -49248,7 +56511,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_19__contains__(struct __pyx_r = __pyx_t_5; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3006 + /* "pysam/libcbcf.pyx":3477 * return default * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -49268,7 +56531,7 @@ static int __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_19__contains__(struct return __pyx_r; } -/* "pysam/libcbcf.pyx":3013 +/* "pysam/libcbcf.pyx":3484 * return fmt != NULL and fmt.p != NULL * * def iterkeys(self): # <<<<<<<<<<<<<< @@ -49296,9 +56559,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_21iterkeys(struc __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("iterkeys", 0); - __Pyx_TraceCall("iterkeys", __pyx_f[0], 3013, 0, __PYX_ERR(0, 3013, __pyx_L1_error)); + __Pyx_TraceCall("iterkeys", __pyx_f[0], 3484, 0, __PYX_ERR(0, 3484, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3015 + /* "pysam/libcbcf.pyx":3486 * def iterkeys(self): * """D.iterkeys() -> an iterator over the keys of D""" * return iter(self) # <<<<<<<<<<<<<< @@ -49306,13 +56569,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_21iterkeys(struc * def itervalues(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3015, __pyx_L1_error) + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3486, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3013 + /* "pysam/libcbcf.pyx":3484 * return fmt != NULL and fmt.p != NULL * * def iterkeys(self): # <<<<<<<<<<<<<< @@ -49333,7 +56596,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_21iterkeys(struc } static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_25generator24(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":3017 +/* "pysam/libcbcf.pyx":3488 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -49364,7 +56627,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_23itervalues(str if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_34_itervalues *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 3017, __pyx_L1_error) + __PYX_ERR(0, 3488, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -49372,7 +56635,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_23itervalues(str __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordSample_25generator24, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantRecordSample_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 3017, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordSample_25generator24, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_VariantRecordSample_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 3488, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -49399,7 +56662,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_25generator24(__ PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("itervalues", 0); - __Pyx_TraceCall("itervalues", __pyx_f[0], 3017, 0, __PYX_ERR(0, 3017, __pyx_L1_error)); + __Pyx_TraceCall("itervalues", __pyx_f[0], 3488, 0, __PYX_ERR(0, 3488, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -49409,9 +56672,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_25generator24(__ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3017, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3488, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3019 + /* "pysam/libcbcf.pyx":3490 * def itervalues(self): * """D.itervalues() -> an iterator over the values of D""" * for key in self: # <<<<<<<<<<<<<< @@ -49422,26 +56685,26 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_25generator24(__ __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3019, __pyx_L1_error) + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3490, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3019, __pyx_L1_error) + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3490, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_3)) { if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3019, __pyx_L1_error) + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3490, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3019, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3490, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } else { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3019, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3490, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3019, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3490, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } @@ -49451,7 +56714,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_25generator24(__ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 3019, __pyx_L1_error) + else __PYX_ERR(0, 3490, __pyx_L1_error) } break; } @@ -49462,14 +56725,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_25generator24(__ __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":3020 + /* "pysam/libcbcf.pyx":3491 * """D.itervalues() -> an iterator over the values of D""" * for key in self: * yield self[key] # <<<<<<<<<<<<<< * * def iteritems(self): */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3020, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3491, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; @@ -49490,9 +56753,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_25generator24(__ __Pyx_XGOTREF(__pyx_t_1); __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3020, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3491, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3019 + /* "pysam/libcbcf.pyx":3490 * def itervalues(self): * """D.itervalues() -> an iterator over the values of D""" * for key in self: # <<<<<<<<<<<<<< @@ -49503,7 +56766,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_25generator24(__ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":3017 + /* "pysam/libcbcf.pyx":3488 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -49529,7 +56792,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_25generator24(__ } static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_28generator25(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":3022 +/* "pysam/libcbcf.pyx":3493 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -49560,7 +56823,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_26iteritems(stru if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_35_iteritems *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 3022, __pyx_L1_error) + __PYX_ERR(0, 3493, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -49568,7 +56831,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_26iteritems(stru __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordSample_28generator25, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantRecordSample_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 3022, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_19VariantRecordSample_28generator25, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_VariantRecordSample_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 3493, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -49596,7 +56859,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_28generator25(__ PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("iteritems", 0); - __Pyx_TraceCall("iteritems", __pyx_f[0], 3022, 0, __PYX_ERR(0, 3022, __pyx_L1_error)); + __Pyx_TraceCall("iteritems", __pyx_f[0], 3493, 0, __PYX_ERR(0, 3493, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -49606,368 +56869,1188 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_19VariantRecordSample_28generator25(__ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3022, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3493, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3024 + /* "pysam/libcbcf.pyx":3495 * def iteritems(self): * """D.iteritems() -> an iterator over the (key, value) items of D""" * for key in self: # <<<<<<<<<<<<<< * yield (key, self[key]) * */ - if (likely(PyList_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) { - __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3024, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3024, __pyx_L1_error) + if (likely(PyList_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) || PyTuple_CheckExact(((PyObject *)__pyx_cur_scope->__pyx_v_self))) { + __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3495, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3495, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_3)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3495, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3495, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3495, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3495, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 3495, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + + /* "pysam/libcbcf.pyx":3496 + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: + * yield (key, self[key]) # <<<<<<<<<<<<<< + * + * def keys(self): + */ + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3496, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3495 + * def iteritems(self): + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: # <<<<<<<<<<<<<< + * yield (key, self[key]) + * + */ + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); + + /* "pysam/libcbcf.pyx":3493 + * yield self[key] + * + * def iteritems(self): # <<<<<<<<<<<<<< + * """D.iteritems() -> an iterator over the (key, value) items of D""" + * for key in self: + */ + + /* function exit code */ + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":3498 + * yield (key, self[key]) + * + * def keys(self): # <<<<<<<<<<<<<< + * """D.keys() -> list of D's keys""" + * return list(self) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_30keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_29keys[] = "VariantRecordSample.keys(self)\nD.keys() -> list of D's keys"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_30keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("keys (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_29keys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_29keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("keys", 0); + __Pyx_TraceCall("keys", __pyx_f[0], 3498, 0, __PYX_ERR(0, 3498, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":3500 + * def keys(self): + * """D.keys() -> list of D's keys""" + * return list(self) # <<<<<<<<<<<<<< + * + * def items(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3500, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":3498 + * yield (key, self[key]) + * + * def keys(self): # <<<<<<<<<<<<<< + * """D.keys() -> list of D's keys""" + * return list(self) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":3502 + * return list(self) + * + * def items(self): # <<<<<<<<<<<<<< + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_32items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_31items[] = "VariantRecordSample.items(self)\nD.items() -> list of D's (key, value) pairs, as 2-tuples"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_32items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("items (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_31items(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_31items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("items", 0); + __Pyx_TraceCall("items", __pyx_f[0], 3502, 0, __PYX_ERR(0, 3502, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":3504 + * def items(self): + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) # <<<<<<<<<<<<<< + * + * def values(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3504, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3504, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3504, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3504, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":3502 + * return list(self) + * + * def items(self): # <<<<<<<<<<<<<< + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.items", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":3506 + * return list(self.iteritems()) + * + * def values(self): # <<<<<<<<<<<<<< + * """D.values() -> list of D's values""" + * return list(self.itervalues()) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_34values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_33values[] = "VariantRecordSample.values(self)\nD.values() -> list of D's values"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_34values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("values (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_33values(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_33values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("values", 0); + __Pyx_TraceCall("values", __pyx_f[0], 3506, 0, __PYX_ERR(0, 3506, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":3508 + * def values(self): + * """D.values() -> list of D's values""" + * return list(self.itervalues()) # <<<<<<<<<<<<<< + * + * def update(self, items=None, **kwargs): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3508, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3508, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3508, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3508, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":3506 + * return list(self.iteritems()) + * + * def values(self): # <<<<<<<<<<<<<< + * """D.values() -> list of D's values""" + * return list(self.itervalues()) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":3510 + * return list(self.itervalues()) + * + * def update(self, items=None, **kwargs): # <<<<<<<<<<<<<< + * """D.update([E, ]**F) -> None. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_36update(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_35update[] = "VariantRecordSample.update(self, items=None, **kwargs)\nD.update([E, ]**F) -> None.\n\n Update D from dict/iterable E and F.\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_36update(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_items = 0; + PyObject *__pyx_v_kwargs = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("update (wrapper)", 0); + __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,0}; + PyObject* values[1] = {0}; + values[0] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "update") < 0)) __PYX_ERR(0, 3510, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_items = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("update", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3510, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.update", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35update(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self), __pyx_v_items, __pyx_v_kwargs); + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35update(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self, PyObject *__pyx_v_items, PyObject *__pyx_v_kwargs) { + PyObject *__pyx_v_k = NULL; + PyObject *__pyx_v_v = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + __Pyx_RefNannySetupContext("update", 0); + __Pyx_TraceCall("update", __pyx_f[0], 3510, 0, __PYX_ERR(0, 3510, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":3515 + * Update D from dict/iterable E and F. + * """ + * for k, v in items.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_items, __pyx_n_s_items); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3515, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3515, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3515, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3515, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3515, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 3515, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3515, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 3515, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3515, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_5(__pyx_t_2); + if (unlikely(!__pyx_t_1)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 3515, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 3515, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3515, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3515, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3515, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 3515, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 3515, __pyx_L1_error) + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libcbcf.pyx":3516 + * """ + * for k, v in items.items(): + * self[k] = v # <<<<<<<<<<<<<< + * + * if kwargs: + */ + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_k, __pyx_v_v) < 0)) __PYX_ERR(0, 3516, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3515 + * Update D from dict/iterable E and F. + * """ + * for k, v in items.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ } - for (;;) { - if (likely(!__pyx_t_3)) { - if (likely(PyList_CheckExact(__pyx_t_1))) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3024, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3024, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libcbcf.pyx":3518 + * self[k] = v + * + * if kwargs: # <<<<<<<<<<<<<< + * for k, v in kwargs.items(): + * self[k] = v + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_kwargs); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 3518, __pyx_L1_error) + if (__pyx_t_9) { + + /* "pysam/libcbcf.pyx":3519 + * + * if kwargs: + * for k, v in kwargs.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3519, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 3519, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 3519, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } } else { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 3519, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 3519, __pyx_L1_error) + } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3024, __pyx_L1_error) + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_3); #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3024, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L10_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L10_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 3519, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L11_unpacking_done; + __pyx_L10_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 3519, __pyx_L1_error) + __pyx_L11_unpacking_done:; } - } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 3024, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":3025 - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: - * yield (key, self[key]) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3520 + * if kwargs: + * for k, v in kwargs.items(): + * self[k] = v # <<<<<<<<<<<<<< * - * def keys(self): + * def pop(self, key, default=_nothing): */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3025, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_cur_scope->__pyx_v_key); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3025, __pyx_L1_error) + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_k, __pyx_v_v) < 0)) __PYX_ERR(0, 3520, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3024 - * def iteritems(self): - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: # <<<<<<<<<<<<<< - * yield (key, self[key]) + /* "pysam/libcbcf.pyx":3519 + * + * if kwargs: + * for k, v in kwargs.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":3518 + * self[k] = v * + * if kwargs: # <<<<<<<<<<<<<< + * for k, v in kwargs.items(): + * self[k] = v */ } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":3022 - * yield self[key] + /* "pysam/libcbcf.pyx":3510 + * return list(self.itervalues()) + * + * def update(self, items=None, **kwargs): # <<<<<<<<<<<<<< + * """D.update([E, ]**F) -> None. * - * def iteritems(self): # <<<<<<<<<<<<<< - * """D.iteritems() -> an iterator over the (key, value) items of D""" - * for key in self: */ /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.update", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_XDECREF(__pyx_v_k); + __Pyx_XDECREF(__pyx_v_v); + __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":3027 - * yield (key, self[key]) +/* "pysam/libcbcf.pyx":3522 + * self[k] = v * - * def keys(self): # <<<<<<<<<<<<<< - * """D.keys() -> list of D's keys""" - * return list(self) + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * try: + * value = self[key] */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_30keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_29keys[] = "VariantRecordSample.keys(self)\nD.keys() -> list of D's keys"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_30keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_38pop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_37pop[] = "VariantRecordSample.pop(self, key, default=_nothing)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_38pop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_key = 0; + PyObject *__pyx_v_default = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("keys (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_29keys(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self)); + __Pyx_RefNannySetupContext("pop (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_default,0}; + PyObject* values[2] = {0,0}; + values[1] = __pyx_k__180; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_default); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "pop") < 0)) __PYX_ERR(0, 3522, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_key = values[0]; + __pyx_v_default = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("pop", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3522, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_37pop(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self), __pyx_v_key, __pyx_v_default); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_29keys(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_37pop(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default) { + PyObject *__pyx_v_value = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("keys", 0); - __Pyx_TraceCall("keys", __pyx_f[0], 3027, 0, __PYX_ERR(0, 3027, __pyx_L1_error)); + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + int __pyx_t_9; + __Pyx_RefNannySetupContext("pop", 0); + __Pyx_TraceCall("pop", __pyx_f[0], 3522, 0, __PYX_ERR(0, 3522, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3029 - * def keys(self): - * """D.keys() -> list of D's keys""" - * return list(self) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3523 * - * def items(self): + * def pop(self, key, default=_nothing): + * try: # <<<<<<<<<<<<<< + * value = self[key] + * del self[key] */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3029, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { - /* "pysam/libcbcf.pyx":3027 - * yield (key, self[key]) - * - * def keys(self): # <<<<<<<<<<<<<< - * """D.keys() -> list of D's keys""" - * return list(self) + /* "pysam/libcbcf.pyx":3524 + * def pop(self, key, default=_nothing): + * try: + * value = self[key] # <<<<<<<<<<<<<< + * del self[key] + * return value */ + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3524, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_value = __pyx_t_4; + __pyx_t_4 = 0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":3525 + * try: + * value = self[key] + * del self[key] # <<<<<<<<<<<<<< + * return value + * except KeyError: + */ + if (unlikely(PyObject_DelItem(((PyObject *)__pyx_v_self), __pyx_v_key) < 0)) __PYX_ERR(0, 3525, __pyx_L3_error) -/* "pysam/libcbcf.pyx":3031 - * return list(self) + /* "pysam/libcbcf.pyx":3526 + * value = self[key] + * del self[key] + * return value # <<<<<<<<<<<<<< + * except KeyError: + * if default is not _nothing: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_value); + __pyx_r = __pyx_v_value; + goto __pyx_L7_try_return; + + /* "pysam/libcbcf.pyx":3523 * - * def items(self): # <<<<<<<<<<<<<< - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) + * def pop(self, key, default=_nothing): + * try: # <<<<<<<<<<<<<< + * value = self[key] + * del self[key] */ + } + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_32items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_31items[] = "VariantRecordSample.items(self)\nD.items() -> list of D's (key, value) pairs, as 2-tuples"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_32items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("items (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_31items(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self)); + /* "pysam/libcbcf.pyx":3527 + * del self[key] + * return value + * except KeyError: # <<<<<<<<<<<<<< + * if default is not _nothing: + * return default + */ + __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); + if (__pyx_t_5) { + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 3527, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":3528 + * return value + * except KeyError: + * if default is not _nothing: # <<<<<<<<<<<<<< + * return default + * raise + */ + __pyx_t_8 = (__pyx_v_default != __pyx_v_5pysam_7libcbcf__nothing); + __pyx_t_9 = (__pyx_t_8 != 0); + if (__pyx_t_9) { -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_31items(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("items", 0); - __Pyx_TraceCall("items", __pyx_f[0], 3031, 0, __PYX_ERR(0, 3031, __pyx_L1_error)); + /* "pysam/libcbcf.pyx":3529 + * except KeyError: + * if default is not _nothing: + * return default # <<<<<<<<<<<<<< + * raise + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_default); + __pyx_r = __pyx_v_default; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_except_return; - /* "pysam/libcbcf.pyx":3033 - * def items(self): - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3528 + * return value + * except KeyError: + * if default is not _nothing: # <<<<<<<<<<<<<< + * return default + * raise + */ + } + + /* "pysam/libcbcf.pyx":3530 + * if default is not _nothing: + * return default + * raise # <<<<<<<<<<<<<< * - * def values(self): + * def __richcmp__(VariantRecordSample self not None, VariantRecordSample other not None, int op): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3033, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_6, __pyx_t_7); + __pyx_t_4 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0; + __PYX_ERR(0, 3530, __pyx_L5_except_error) } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "pysam/libcbcf.pyx":3523 + * + * def pop(self, key, default=_nothing): + * try: # <<<<<<<<<<<<<< + * value = self[key] + * del self[key] + */ + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L7_try_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + __pyx_L6_except_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3033, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3033, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3033, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - /* "pysam/libcbcf.pyx":3031 - * return list(self) + /* "pysam/libcbcf.pyx":3522 + * self[k] = v * - * def items(self): # <<<<<<<<<<<<<< - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * try: + * value = self[key] */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.items", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_value); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":3035 - * return list(self.iteritems()) +/* "pysam/libcbcf.pyx":3532 + * raise * - * def values(self): # <<<<<<<<<<<<<< - * """D.values() -> list of D's values""" - * return list(self.itervalues()) + * def __richcmp__(VariantRecordSample self not None, VariantRecordSample other not None, int op): # <<<<<<<<<<<<<< + * if op != 2 and op != 3: + * return NotImplemented */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_34values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_33values[] = "VariantRecordSample.values(self)\nD.values() -> list of D's values"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_34values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_40__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_40__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("values (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_33values(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); + if (unlikely(((PyObject *)__pyx_v_self) == Py_None)) { + PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "self"); __PYX_ERR(0, 3532, __pyx_L1_error) + } + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_7libcbcf_VariantRecordSample, 0, "other", 0))) __PYX_ERR(0, 3532, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_39__richcmp__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self), ((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_other), ((int)__pyx_v_op)); /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_33values(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_39__richcmp__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_other, int __pyx_v_op) { + int __pyx_v_cmp; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("values", 0); - __Pyx_TraceCall("values", __pyx_f[0], 3035, 0, __PYX_ERR(0, 3035, __pyx_L1_error)); + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("__richcmp__", 0); + __Pyx_TraceCall("__richcmp__", __pyx_f[0], 3532, 0, __PYX_ERR(0, 3532, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3037 - * def values(self): - * """D.values() -> list of D's values""" - * return list(self.itervalues()) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3533 + * + * def __richcmp__(VariantRecordSample self not None, VariantRecordSample other not None, int op): + * if op != 2 and op != 3: # <<<<<<<<<<<<<< + * return NotImplemented * - * # Mappings are not hashable by default, but subclasses can change this */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3037, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } + switch (__pyx_v_op) { + case 2: + case 3: + __pyx_t_1 = 0; + break; + default: + __pyx_t_1 = 1; + break; } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3037, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3037, __pyx_L1_error) + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":3534 + * def __richcmp__(VariantRecordSample self not None, VariantRecordSample other not None, int op): + * if op != 2 and op != 3: + * return NotImplemented # <<<<<<<<<<<<<< + * + * cdef bint cmp = dict(self) == dict(other) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_builtin_NotImplemented); + __pyx_r = __pyx_builtin_NotImplemented; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":3533 + * + * def __richcmp__(VariantRecordSample self not None, VariantRecordSample other not None, int op): + * if op != 2 and op != 3: # <<<<<<<<<<<<<< + * return NotImplemented + * + */ } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3037, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3536 + * return NotImplemented + * + * cdef bint cmp = dict(self) == dict(other) # <<<<<<<<<<<<<< + * + * if op == 3: + */ + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3536, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3536, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3536, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3536, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_cmp = __pyx_t_1; + + /* "pysam/libcbcf.pyx":3538 + * cdef bint cmp = dict(self) == dict(other) + * + * if op == 3: # <<<<<<<<<<<<<< + * cmp = not cmp + * + */ + __pyx_t_1 = ((__pyx_v_op == 3) != 0); + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":3539 + * + * if op == 3: + * cmp = not cmp # <<<<<<<<<<<<<< + * + * return cmp + */ + __pyx_v_cmp = (!(__pyx_v_cmp != 0)); + + /* "pysam/libcbcf.pyx":3538 + * cdef bint cmp = dict(self) == dict(other) + * + * if op == 3: # <<<<<<<<<<<<<< + * cmp = not cmp + * + */ + } + + /* "pysam/libcbcf.pyx":3541 + * cmp = not cmp + * + * return cmp # <<<<<<<<<<<<<< + * + * # Mappings are not hashable by default, but subclasses can change this + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_cmp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3541, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3035 - * return list(self.iteritems()) + /* "pysam/libcbcf.pyx":3532 + * raise * - * def values(self): # <<<<<<<<<<<<<< - * """D.values() -> list of D's values""" - * return list(self.itervalues()) + * def __richcmp__(VariantRecordSample self not None, VariantRecordSample other not None, int op): # <<<<<<<<<<<<<< + * if op != 2 and op != 3: + * return NotImplemented */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcbcf.VariantRecordSample.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -49976,7 +58059,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_33values(struct return __pyx_r; } -/* "pysam/libcbcf.pxd":101 +/* "pysam/libcbcf.pxd":100 * cdef class VariantRecordSample(object): * cdef VariantRecord record * cdef readonly int32_t index # <<<<<<<<<<<<<< @@ -50003,9 +58086,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_5index___get__(s __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 101, 0, __PYX_ERR(2, 101, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[1], 100, 0, __PYX_ERR(1, 100, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 101, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 100, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -50030,20 +58113,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_5index___get__(s */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_36__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cython__[] = "VariantRecordSample.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_36__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_42__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_41__reduce_cython__[] = "VariantRecordSample.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_42__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_41__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_41__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self) { int __pyx_v_use_setstate; PyObject *__pyx_v_state = NULL; PyObject *__pyx_v__dict = NULL; @@ -50056,7 +58139,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cytho int __pyx_t_4; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -50065,9 +58148,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cytho * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ - __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->index); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); @@ -50085,7 +58168,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cytho * if _dict is not None: * state += (_dict,) */ - __pyx_t_2 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v__dict = __pyx_t_2; __pyx_t_2 = 0; @@ -50108,12 +58191,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cytho * use_setstate = True * else: */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v__dict); - __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_1)); @@ -50169,9 +58252,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cytho * return __pyx_unpickle_VariantRecordSample, (type(self), 0x5d6ff7b, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordSamp_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordSamp_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -50182,7 +58265,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cytho __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_2, 2, Py_None); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); @@ -50215,9 +58298,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cytho */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordSamp_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_VariantRecordSamp_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -50228,7 +58311,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cytho __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_state); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); @@ -50271,34 +58354,34 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cytho */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_38__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_37__setstate_cython__[] = "VariantRecordSample.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_38__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_44__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_43__setstate_cython__[] = "VariantRecordSample.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_44__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_37__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_19VariantRecordSample_43__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_37__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_43__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 14, 0, __PYX_ERR(2, 14, __pyx_L1_error)); /* "(tree fragment)":15 * return __pyx_unpickle_VariantRecordSample, (type(self), 0x5d6ff7b, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_VariantRecordSample__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSample__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSample__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -50323,7 +58406,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_19VariantRecordSample_37__setstate_cyt return __pyx_r; } -/* "pysam/libcbcf.pyx":3045 +/* "pysam/libcbcf.pyx":3547 * * * cdef VariantRecordSample makeVariantRecordSample(VariantRecord record, int32_t sample_index): # <<<<<<<<<<<<<< @@ -50341,16 +58424,16 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_f_5pysam_7lib int __pyx_t_3; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("makeVariantRecordSample", 0); - __Pyx_TraceCall("makeVariantRecordSample", __pyx_f[0], 3045, 0, __PYX_ERR(0, 3045, __pyx_L1_error)); + __Pyx_TraceCall("makeVariantRecordSample", __pyx_f[0], 3547, 0, __PYX_ERR(0, 3547, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3046 + /* "pysam/libcbcf.pyx":3548 * * cdef VariantRecordSample makeVariantRecordSample(VariantRecord record, int32_t sample_index): * if not record or sample_index < 0: # <<<<<<<<<<<<<< * raise ValueError('cannot create VariantRecordSample') * */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_record)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3046, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_record)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3548, __pyx_L1_error) __pyx_t_3 = ((!__pyx_t_2) != 0); if (!__pyx_t_3) { } else { @@ -50362,20 +58445,20 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_f_5pysam_7lib __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3047 + /* "pysam/libcbcf.pyx":3549 * cdef VariantRecordSample makeVariantRecordSample(VariantRecord record, int32_t sample_index): * if not record or sample_index < 0: * raise ValueError('cannot create VariantRecordSample') # <<<<<<<<<<<<<< * * cdef VariantRecordSample sample = VariantRecordSample.__new__(VariantRecordSample) */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__172, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3047, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__181, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3549, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 3047, __pyx_L1_error) + __PYX_ERR(0, 3549, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3046 + /* "pysam/libcbcf.pyx":3548 * * cdef VariantRecordSample makeVariantRecordSample(VariantRecord record, int32_t sample_index): * if not record or sample_index < 0: # <<<<<<<<<<<<<< @@ -50384,19 +58467,19 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_f_5pysam_7lib */ } - /* "pysam/libcbcf.pyx":3049 + /* "pysam/libcbcf.pyx":3551 * raise ValueError('cannot create VariantRecordSample') * * cdef VariantRecordSample sample = VariantRecordSample.__new__(VariantRecordSample) # <<<<<<<<<<<<<< * sample.record = record * sample.index = sample_index */ - __pyx_t_4 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantRecordSample(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordSample), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3049, __pyx_L1_error) + __pyx_t_4 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantRecordSample(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordSample), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3551, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __pyx_v_sample = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":3050 + /* "pysam/libcbcf.pyx":3552 * * cdef VariantRecordSample sample = VariantRecordSample.__new__(VariantRecordSample) * sample.record = record # <<<<<<<<<<<<<< @@ -50409,7 +58492,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_f_5pysam_7lib __Pyx_DECREF(((PyObject *)__pyx_v_sample->record)); __pyx_v_sample->record = __pyx_v_record; - /* "pysam/libcbcf.pyx":3051 + /* "pysam/libcbcf.pyx":3553 * cdef VariantRecordSample sample = VariantRecordSample.__new__(VariantRecordSample) * sample.record = record * sample.index = sample_index # <<<<<<<<<<<<<< @@ -50418,7 +58501,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_f_5pysam_7lib */ __pyx_v_sample->index = __pyx_v_sample_index; - /* "pysam/libcbcf.pyx":3053 + /* "pysam/libcbcf.pyx":3555 * sample.index = sample_index * * return sample # <<<<<<<<<<<<<< @@ -50430,7 +58513,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_f_5pysam_7lib __pyx_r = __pyx_v_sample; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3045 + /* "pysam/libcbcf.pyx":3547 * * * cdef VariantRecordSample makeVariantRecordSample(VariantRecord record, int32_t sample_index): # <<<<<<<<<<<<<< @@ -50451,7 +58534,7 @@ static struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *__pyx_f_5pysam_7lib return __pyx_r; } -/* "pysam/libcbcf.pyx":3063 +/* "pysam/libcbcf.pyx":3565 * * cdef class BaseIndex(object): * def __init__(self): # <<<<<<<<<<<<<< @@ -50481,9 +58564,9 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex___init__(struct __pyx_obj_5pysam_ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 3063, 0, __PYX_ERR(0, 3063, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 3565, 0, __PYX_ERR(0, 3565, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3064 + /* "pysam/libcbcf.pyx":3566 * cdef class BaseIndex(object): * def __init__(self): * self.refs = () # <<<<<<<<<<<<<< @@ -50496,19 +58579,19 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex___init__(struct __pyx_obj_5pysam_ __Pyx_DECREF(__pyx_v_self->refs); __pyx_v_self->refs = __pyx_empty_tuple; - /* "pysam/libcbcf.pyx":3065 + /* "pysam/libcbcf.pyx":3567 * def __init__(self): * self.refs = () * self.remap = {} # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3065, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3567, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_remap, __pyx_t_1) < 0) __PYX_ERR(0, 3065, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_remap, __pyx_t_1) < 0) __PYX_ERR(0, 3567, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3063 + /* "pysam/libcbcf.pyx":3565 * * cdef class BaseIndex(object): * def __init__(self): # <<<<<<<<<<<<<< @@ -50529,7 +58612,7 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex___init__(struct __pyx_obj_5pysam_ return __pyx_r; } -/* "pysam/libcbcf.pyx":3067 +/* "pysam/libcbcf.pyx":3569 * self.remap = {} * * def __len__(self): # <<<<<<<<<<<<<< @@ -50557,9 +58640,9 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_9BaseIndex_2__len__(struct __pyx_obj_ PyObject *__pyx_t_1 = NULL; Py_ssize_t __pyx_t_2; __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[0], 3067, 0, __PYX_ERR(0, 3067, __pyx_L1_error)); + __Pyx_TraceCall("__len__", __pyx_f[0], 3569, 0, __PYX_ERR(0, 3569, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3068 + /* "pysam/libcbcf.pyx":3570 * * def __len__(self): * return len(self.refs) # <<<<<<<<<<<<<< @@ -50570,14 +58653,14 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_9BaseIndex_2__len__(struct __pyx_obj_ __Pyx_INCREF(__pyx_t_1); if (unlikely(__pyx_t_1 == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 3068, __pyx_L1_error) + __PYX_ERR(0, 3570, __pyx_L1_error) } - __pyx_t_2 = PyTuple_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3068, __pyx_L1_error) + __pyx_t_2 = PyTuple_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3570, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3067 + /* "pysam/libcbcf.pyx":3569 * self.remap = {} * * def __len__(self): # <<<<<<<<<<<<<< @@ -50596,7 +58679,7 @@ static Py_ssize_t __pyx_pf_5pysam_7libcbcf_9BaseIndex_2__len__(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libcbcf.pyx":3070 +/* "pysam/libcbcf.pyx":3572 * return len(self.refs) * * def __bool__(self): # <<<<<<<<<<<<<< @@ -50624,9 +58707,9 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex_4__bool__(struct __pyx_obj_5pysam PyObject *__pyx_t_1 = NULL; Py_ssize_t __pyx_t_2; __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 3070, 0, __PYX_ERR(0, 3070, __pyx_L1_error)); + __Pyx_TraceCall("__bool__", __pyx_f[0], 3572, 0, __PYX_ERR(0, 3572, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3071 + /* "pysam/libcbcf.pyx":3573 * * def __bool__(self): * return len(self.refs) != 0 # <<<<<<<<<<<<<< @@ -50637,14 +58720,14 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex_4__bool__(struct __pyx_obj_5pysam __Pyx_INCREF(__pyx_t_1); if (unlikely(__pyx_t_1 == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 3071, __pyx_L1_error) + __PYX_ERR(0, 3573, __pyx_L1_error) } - __pyx_t_2 = PyTuple_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3071, __pyx_L1_error) + __pyx_t_2 = PyTuple_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3573, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = (__pyx_t_2 != 0); goto __pyx_L0; - /* "pysam/libcbcf.pyx":3070 + /* "pysam/libcbcf.pyx":3572 * return len(self.refs) * * def __bool__(self): # <<<<<<<<<<<<<< @@ -50663,7 +58746,7 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex_4__bool__(struct __pyx_obj_5pysam return __pyx_r; } -/* "pysam/libcbcf.pyx":3073 +/* "pysam/libcbcf.pyx":3575 * return len(self.refs) != 0 * * def __getitem__(self, key): # <<<<<<<<<<<<<< @@ -50692,9 +58775,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_6__getitem__(struct __pyx_o int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[0], 3073, 0, __PYX_ERR(0, 3073, __pyx_L1_error)); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 3575, 0, __PYX_ERR(0, 3575, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3074 + /* "pysam/libcbcf.pyx":3576 * * def __getitem__(self, key): * if isinstance(key, int): # <<<<<<<<<<<<<< @@ -50705,7 +58788,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_6__getitem__(struct __pyx_o __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":3075 + /* "pysam/libcbcf.pyx":3577 * def __getitem__(self, key): * if isinstance(key, int): * return self.refs[key] # <<<<<<<<<<<<<< @@ -50715,15 +58798,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_6__getitem__(struct __pyx_o __Pyx_XDECREF(__pyx_r); if (unlikely(__pyx_v_self->refs == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 3075, __pyx_L1_error) + __PYX_ERR(0, 3577, __pyx_L1_error) } - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_self->refs, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3075, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_self->refs, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3074 + /* "pysam/libcbcf.pyx":3576 * * def __getitem__(self, key): * if isinstance(key, int): # <<<<<<<<<<<<<< @@ -50732,7 +58815,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_6__getitem__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":3077 + /* "pysam/libcbcf.pyx":3579 * return self.refs[key] * else: * return self.refmap[key] # <<<<<<<<<<<<<< @@ -50743,16 +58826,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_6__getitem__(struct __pyx_o __Pyx_XDECREF(__pyx_r); if (unlikely(__pyx_v_self->refmap == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 3077, __pyx_L1_error) + __PYX_ERR(0, 3579, __pyx_L1_error) } - __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_self->refmap, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3077, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_self->refmap, __pyx_v_key); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3579, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; } - /* "pysam/libcbcf.pyx":3073 + /* "pysam/libcbcf.pyx":3575 * return len(self.refs) != 0 * * def __getitem__(self, key): # <<<<<<<<<<<<<< @@ -50772,7 +58855,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_6__getitem__(struct __pyx_o return __pyx_r; } -/* "pysam/libcbcf.pyx":3079 +/* "pysam/libcbcf.pyx":3581 * return self.refmap[key] * * def __iter__(self): # <<<<<<<<<<<<<< @@ -50800,9 +58883,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_8__iter__(struct __pyx_obj_ PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 3079, 0, __PYX_ERR(0, 3079, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 3581, 0, __PYX_ERR(0, 3581, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3080 + /* "pysam/libcbcf.pyx":3582 * * def __iter__(self): * return iter(self.refs) # <<<<<<<<<<<<<< @@ -50812,14 +58895,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_8__iter__(struct __pyx_obj_ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_self->refs; __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3080, __pyx_L1_error) + __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3079 + /* "pysam/libcbcf.pyx":3581 * return self.refmap[key] * * def __iter__(self): # <<<<<<<<<<<<<< @@ -50840,7 +58923,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_8__iter__(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libcbcf.pyx":3082 +/* "pysam/libcbcf.pyx":3584 * return iter(self.refs) * * def get(self, key, default=None): # <<<<<<<<<<<<<< @@ -50885,7 +58968,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_11get(PyObject *__pyx_v_sel } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 3082, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 3584, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -50901,7 +58984,7 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_11get(PyObject *__pyx_v_sel } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3082, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3584, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.get", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -50926,9 +59009,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_10get(struct __pyx_obj_5pys PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("get", 0); - __Pyx_TraceCall("get", __pyx_f[0], 3082, 0, __PYX_ERR(0, 3082, __pyx_L1_error)); + __Pyx_TraceCall("get", __pyx_f[0], 3584, 0, __PYX_ERR(0, 3584, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3084 + /* "pysam/libcbcf.pyx":3586 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -50944,7 +59027,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_10get(struct __pyx_obj_5pys __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "pysam/libcbcf.pyx":3085 + /* "pysam/libcbcf.pyx":3587 * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: * return self[key] # <<<<<<<<<<<<<< @@ -50952,13 +59035,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_10get(struct __pyx_obj_5pys * return default */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3085, __pyx_L3_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3587, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L7_try_return; - /* "pysam/libcbcf.pyx":3084 + /* "pysam/libcbcf.pyx":3586 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -50969,7 +59052,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_10get(struct __pyx_obj_5pys __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":3086 + /* "pysam/libcbcf.pyx":3588 * try: * return self[key] * except KeyError: # <<<<<<<<<<<<<< @@ -50979,12 +59062,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_10get(struct __pyx_obj_5pys __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); if (__pyx_t_5) { __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 3086, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 3588, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcbcf.pyx":3087 + /* "pysam/libcbcf.pyx":3589 * return self[key] * except KeyError: * return default # <<<<<<<<<<<<<< @@ -51002,7 +59085,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_10get(struct __pyx_obj_5pys goto __pyx_L5_except_error; __pyx_L5_except_error:; - /* "pysam/libcbcf.pyx":3084 + /* "pysam/libcbcf.pyx":3586 * def get(self, key, default=None): * """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" * try: # <<<<<<<<<<<<<< @@ -51028,7 +59111,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_10get(struct __pyx_obj_5pys goto __pyx_L0; } - /* "pysam/libcbcf.pyx":3082 + /* "pysam/libcbcf.pyx":3584 * return iter(self.refs) * * def get(self, key, default=None): # <<<<<<<<<<<<<< @@ -51050,7 +59133,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_10get(struct __pyx_obj_5pys return __pyx_r; } -/* "pysam/libcbcf.pyx":3089 +/* "pysam/libcbcf.pyx":3591 * return default * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -51083,9 +59166,9 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex_12__contains__(struct __pyx_obj_5 PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("__contains__", 0); - __Pyx_TraceCall("__contains__", __pyx_f[0], 3089, 0, __PYX_ERR(0, 3089, __pyx_L1_error)); + __Pyx_TraceCall("__contains__", __pyx_f[0], 3591, 0, __PYX_ERR(0, 3591, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3090 + /* "pysam/libcbcf.pyx":3592 * * def __contains__(self, key): * try: # <<<<<<<<<<<<<< @@ -51101,18 +59184,18 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex_12__contains__(struct __pyx_obj_5 __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "pysam/libcbcf.pyx":3091 + /* "pysam/libcbcf.pyx":3593 * def __contains__(self, key): * try: * self[key] # <<<<<<<<<<<<<< * except KeyError: * return False */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3091, __pyx_L3_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3593, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":3090 + /* "pysam/libcbcf.pyx":3592 * * def __contains__(self, key): * try: # <<<<<<<<<<<<<< @@ -51121,7 +59204,7 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex_12__contains__(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":3095 + /* "pysam/libcbcf.pyx":3597 * return False * else: * return True # <<<<<<<<<<<<<< @@ -51135,7 +59218,7 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex_12__contains__(struct __pyx_obj_5 __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":3092 + /* "pysam/libcbcf.pyx":3594 * try: * self[key] * except KeyError: # <<<<<<<<<<<<<< @@ -51145,12 +59228,12 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex_12__contains__(struct __pyx_obj_5 __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); if (__pyx_t_5) { __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 3092, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 3594, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcbcf.pyx":3093 + /* "pysam/libcbcf.pyx":3595 * self[key] * except KeyError: * return False # <<<<<<<<<<<<<< @@ -51166,7 +59249,7 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex_12__contains__(struct __pyx_obj_5 goto __pyx_L5_except_error; __pyx_L5_except_error:; - /* "pysam/libcbcf.pyx":3090 + /* "pysam/libcbcf.pyx":3592 * * def __contains__(self, key): * try: # <<<<<<<<<<<<<< @@ -51186,7 +59269,7 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex_12__contains__(struct __pyx_obj_5 goto __pyx_L0; } - /* "pysam/libcbcf.pyx":3089 + /* "pysam/libcbcf.pyx":3591 * return default * * def __contains__(self, key): # <<<<<<<<<<<<<< @@ -51207,7 +59290,7 @@ static int __pyx_pf_5pysam_7libcbcf_9BaseIndex_12__contains__(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libcbcf.pyx":3097 +/* "pysam/libcbcf.pyx":3599 * return True * * def iterkeys(self): # <<<<<<<<<<<<<< @@ -51235,9 +59318,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_14iterkeys(struct __pyx_obj __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("iterkeys", 0); - __Pyx_TraceCall("iterkeys", __pyx_f[0], 3097, 0, __PYX_ERR(0, 3097, __pyx_L1_error)); + __Pyx_TraceCall("iterkeys", __pyx_f[0], 3599, 0, __PYX_ERR(0, 3599, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3099 + /* "pysam/libcbcf.pyx":3601 * def iterkeys(self): * """D.iterkeys() -> an iterator over the keys of D""" * return iter(self) # <<<<<<<<<<<<<< @@ -51245,13 +59328,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_14iterkeys(struct __pyx_obj * def itervalues(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3099, __pyx_L1_error) + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3097 + /* "pysam/libcbcf.pyx":3599 * return True * * def iterkeys(self): # <<<<<<<<<<<<<< @@ -51272,7 +59355,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_14iterkeys(struct __pyx_obj } static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_18generator26(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":3101 +/* "pysam/libcbcf.pyx":3603 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -51303,7 +59386,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_16itervalues(struct __pyx_o if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_36_itervalues *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 3101, __pyx_L1_error) + __PYX_ERR(0, 3603, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -51311,7 +59394,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_16itervalues(struct __pyx_o __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_9BaseIndex_18generator26, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_BaseIndex_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 3101, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_9BaseIndex_18generator26, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_itervalues, __pyx_n_s_BaseIndex_itervalues, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 3603, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -51338,7 +59421,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_18generator26(__pyx_Corouti PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("itervalues", 0); - __Pyx_TraceCall("itervalues", __pyx_f[0], 3101, 0, __PYX_ERR(0, 3101, __pyx_L1_error)); + __Pyx_TraceCall("itervalues", __pyx_f[0], 3603, 0, __PYX_ERR(0, 3603, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -51348,9 +59431,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_18generator26(__pyx_Corouti return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3101, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3603, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3103 + /* "pysam/libcbcf.pyx":3605 * def itervalues(self): * """D.itervalues() -> an iterator over the values of D""" * for key in self: # <<<<<<<<<<<<<< @@ -51361,26 +59444,26 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_18generator26(__pyx_Corouti __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3103, __pyx_L1_error) + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3605, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3103, __pyx_L1_error) + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3605, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_3)) { if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3103, __pyx_L1_error) + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3605, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3103, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3605, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } else { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3103, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3605, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3103, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3605, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } @@ -51390,7 +59473,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_18generator26(__pyx_Corouti PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 3103, __pyx_L1_error) + else __PYX_ERR(0, 3605, __pyx_L1_error) } break; } @@ -51401,14 +59484,14 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_18generator26(__pyx_Corouti __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":3104 + /* "pysam/libcbcf.pyx":3606 * """D.itervalues() -> an iterator over the values of D""" * for key in self: * yield self[key] # <<<<<<<<<<<<<< * * def iteritems(self): */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3104, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3606, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; @@ -51429,9 +59512,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_18generator26(__pyx_Corouti __Pyx_XGOTREF(__pyx_t_1); __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3104, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3606, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3103 + /* "pysam/libcbcf.pyx":3605 * def itervalues(self): * """D.itervalues() -> an iterator over the values of D""" * for key in self: # <<<<<<<<<<<<<< @@ -51442,7 +59525,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_18generator26(__pyx_Corouti __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":3101 + /* "pysam/libcbcf.pyx":3603 * return iter(self) * * def itervalues(self): # <<<<<<<<<<<<<< @@ -51468,7 +59551,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_18generator26(__pyx_Corouti } static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_21generator27(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libcbcf.pyx":3106 +/* "pysam/libcbcf.pyx":3608 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -51499,7 +59582,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_19iteritems(struct __pyx_ob if (unlikely(!__pyx_cur_scope)) { __pyx_cur_scope = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_37_iteritems *)Py_None); __Pyx_INCREF(Py_None); - __PYX_ERR(0, 3106, __pyx_L1_error) + __PYX_ERR(0, 3608, __pyx_L1_error) } else { __Pyx_GOTREF(__pyx_cur_scope); } @@ -51507,7 +59590,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_19iteritems(struct __pyx_ob __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_9BaseIndex_21generator27, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_BaseIndex_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 3106, __pyx_L1_error) + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_7libcbcf_9BaseIndex_21generator27, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_iteritems, __pyx_n_s_BaseIndex_iteritems, __pyx_n_s_pysam_libcbcf); if (unlikely(!gen)) __PYX_ERR(0, 3608, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -51535,7 +59618,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_21generator27(__pyx_Corouti PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("iteritems", 0); - __Pyx_TraceCall("iteritems", __pyx_f[0], 3106, 0, __PYX_ERR(0, 3106, __pyx_L1_error)); + __Pyx_TraceCall("iteritems", __pyx_f[0], 3608, 0, __PYX_ERR(0, 3608, __pyx_L1_error)); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; case 1: goto __pyx_L6_resume_from_yield; @@ -51545,9 +59628,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_21generator27(__pyx_Corouti return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3106, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3608, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3108 + /* "pysam/libcbcf.pyx":3610 * def iteritems(self): * """D.iteritems() -> an iterator over the (key, value) items of D""" * for key in self: # <<<<<<<<<<<<<< @@ -51558,26 +59641,26 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_21generator27(__pyx_Corouti __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3108, __pyx_L1_error) + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3610, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3108, __pyx_L1_error) + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3610, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_3)) { if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3108, __pyx_L1_error) + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3610, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3108, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3610, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } else { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3108, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 3610, __pyx_L1_error) #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3108, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3610, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif } @@ -51587,7 +59670,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_21generator27(__pyx_Corouti PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 3108, __pyx_L1_error) + else __PYX_ERR(0, 3610, __pyx_L1_error) } break; } @@ -51598,16 +59681,16 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_21generator27(__pyx_Corouti __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcbcf.pyx":3109 + /* "pysam/libcbcf.pyx":3611 * """D.iteritems() -> an iterator over the (key, value) items of D""" * for key in self: * yield (key, self[key]) # <<<<<<<<<<<<<< * * def keys(self): */ - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3109, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3611, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3109, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3611, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); @@ -51634,9 +59717,9 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_21generator27(__pyx_Corouti __Pyx_XGOTREF(__pyx_t_1); __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3109, __pyx_L1_error) + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 3611, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3108 + /* "pysam/libcbcf.pyx":3610 * def iteritems(self): * """D.iteritems() -> an iterator over the (key, value) items of D""" * for key in self: # <<<<<<<<<<<<<< @@ -51647,7 +59730,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_21generator27(__pyx_Corouti __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libcbcf.pyx":3106 + /* "pysam/libcbcf.pyx":3608 * yield self[key] * * def iteritems(self): # <<<<<<<<<<<<<< @@ -51673,7 +59756,7 @@ static PyObject *__pyx_gb_5pysam_7libcbcf_9BaseIndex_21generator27(__pyx_Corouti return __pyx_r; } -/* "pysam/libcbcf.pyx":3111 +/* "pysam/libcbcf.pyx":3613 * yield (key, self[key]) * * def keys(self): # <<<<<<<<<<<<<< @@ -51701,214 +59784,872 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_22keys(struct __pyx_obj_5py __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("keys", 0); - __Pyx_TraceCall("keys", __pyx_f[0], 3111, 0, __PYX_ERR(0, 3111, __pyx_L1_error)); + __Pyx_TraceCall("keys", __pyx_f[0], 3613, 0, __PYX_ERR(0, 3613, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":3615 + * def keys(self): + * """D.keys() -> list of D's keys""" + * return list(self) # <<<<<<<<<<<<<< + * + * def items(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3615, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":3613 + * yield (key, self[key]) + * + * def keys(self): # <<<<<<<<<<<<<< + * """D.keys() -> list of D's keys""" + * return list(self) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":3617 + * return list(self) + * + * def items(self): # <<<<<<<<<<<<<< + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_25items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_9BaseIndex_24items[] = "BaseIndex.items(self)\nD.items() -> list of D's (key, value) pairs, as 2-tuples"; +static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_25items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("items (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_9BaseIndex_24items(((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_24items(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("items", 0); + __Pyx_TraceCall("items", __pyx_f[0], 3617, 0, __PYX_ERR(0, 3617, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":3619 + * def items(self): + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) # <<<<<<<<<<<<<< + * + * def values(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3619, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3619, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3619, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3619, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":3617 + * return list(self) + * + * def items(self): # <<<<<<<<<<<<<< + * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + * return list(self.iteritems()) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.items", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":3621 + * return list(self.iteritems()) + * + * def values(self): # <<<<<<<<<<<<<< + * """D.values() -> list of D's values""" + * return list(self.itervalues()) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_27values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_9BaseIndex_26values[] = "BaseIndex.values(self)\nD.values() -> list of D's values"; +static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_27values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("values (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_9BaseIndex_26values(((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_26values(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("values", 0); + __Pyx_TraceCall("values", __pyx_f[0], 3621, 0, __PYX_ERR(0, 3621, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":3623 + * def values(self): + * """D.values() -> list of D's values""" + * return list(self.itervalues()) # <<<<<<<<<<<<<< + * + * def update(self, items=None, **kwargs): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3623, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3623, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3623, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3623, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":3621 + * return list(self.iteritems()) + * + * def values(self): # <<<<<<<<<<<<<< + * """D.values() -> list of D's values""" + * return list(self.itervalues()) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":3625 + * return list(self.itervalues()) + * + * def update(self, items=None, **kwargs): # <<<<<<<<<<<<<< + * """D.update([E, ]**F) -> None. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_29update(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_9BaseIndex_28update[] = "BaseIndex.update(self, items=None, **kwargs)\nD.update([E, ]**F) -> None.\n\n Update D from dict/iterable E and F.\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_29update(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_items = 0; + PyObject *__pyx_v_kwargs = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("update (wrapper)", 0); + __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_items,0}; + PyObject* values[1] = {0}; + values[0] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "update") < 0)) __PYX_ERR(0, 3625, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_items = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("update", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3625, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.update", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_9BaseIndex_28update(((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_v_self), __pyx_v_items, __pyx_v_kwargs); + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28update(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self, PyObject *__pyx_v_items, PyObject *__pyx_v_kwargs) { + PyObject *__pyx_v_k = NULL; + PyObject *__pyx_v_v = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + __Pyx_RefNannySetupContext("update", 0); + __Pyx_TraceCall("update", __pyx_f[0], 3625, 0, __PYX_ERR(0, 3625, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":3630 + * Update D from dict/iterable E and F. + * """ + * for k, v in items.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_items, __pyx_n_s_items); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3630, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3630, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3630, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3630, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3630, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 3630, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3630, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 3630, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3630, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_5(__pyx_t_2); + if (unlikely(!__pyx_t_1)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 3630, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 3630, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3630, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3630, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3630, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 3630, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 3630, __pyx_L1_error) + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libcbcf.pyx":3631 + * """ + * for k, v in items.items(): + * self[k] = v # <<<<<<<<<<<<<< + * + * if kwargs: + */ + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_k, __pyx_v_v) < 0)) __PYX_ERR(0, 3631, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3630 + * Update D from dict/iterable E and F. + * """ + * for k, v in items.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libcbcf.pyx":3633 + * self[k] = v + * + * if kwargs: # <<<<<<<<<<<<<< + * for k, v in kwargs.items(): + * self[k] = v + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_kwargs); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 3633, __pyx_L1_error) + if (__pyx_t_9) { + + /* "pysam/libcbcf.pyx":3634 + * + * if kwargs: + * for k, v in kwargs.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3634, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3634, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3634, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 3634, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3634, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 3634, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3634, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 3634, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 3634, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_3); + #else + __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3634, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3634, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3634, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L10_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L10_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 3634, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L11_unpacking_done; + __pyx_L10_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 3634, __pyx_L1_error) + __pyx_L11_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":3635 + * if kwargs: + * for k, v in kwargs.items(): + * self[k] = v # <<<<<<<<<<<<<< + * + * def pop(self, key, default=_nothing): + */ + if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_k, __pyx_v_v) < 0)) __PYX_ERR(0, 3635, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3634 + * + * if kwargs: + * for k, v in kwargs.items(): # <<<<<<<<<<<<<< + * self[k] = v + * + */ + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3113 - * def keys(self): - * """D.keys() -> list of D's keys""" - * return list(self) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3633 + * self[k] = v * - * def items(self): + * if kwargs: # <<<<<<<<<<<<<< + * for k, v in kwargs.items(): + * self[k] = v */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3113, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + } - /* "pysam/libcbcf.pyx":3111 - * yield (key, self[key]) + /* "pysam/libcbcf.pyx":3625 + * return list(self.itervalues()) + * + * def update(self, items=None, **kwargs): # <<<<<<<<<<<<<< + * """D.update([E, ]**F) -> None. * - * def keys(self): # <<<<<<<<<<<<<< - * """D.keys() -> list of D's keys""" - * return list(self) */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.update", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_k); + __Pyx_XDECREF(__pyx_v_v); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":3115 - * return list(self) +/* "pysam/libcbcf.pyx":3637 + * self[k] = v * - * def items(self): # <<<<<<<<<<<<<< - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * try: + * value = self[key] */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_25items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_9BaseIndex_24items[] = "BaseIndex.items(self)\nD.items() -> list of D's (key, value) pairs, as 2-tuples"; -static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_25items(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_31pop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_9BaseIndex_30pop[] = "BaseIndex.pop(self, key, default=_nothing)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_31pop(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_key = 0; + PyObject *__pyx_v_default = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("items (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_9BaseIndex_24items(((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_v_self)); + __Pyx_RefNannySetupContext("pop (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_default,0}; + PyObject* values[2] = {0,0}; + values[1] = __pyx_k__182; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_default); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "pop") < 0)) __PYX_ERR(0, 3637, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_key = values[0]; + __pyx_v_default = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("pop", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3637, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_7libcbcf_9BaseIndex_30pop(((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_v_self), __pyx_v_key, __pyx_v_default); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_24items(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_30pop(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default) { + PyObject *__pyx_v_value = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("items", 0); - __Pyx_TraceCall("items", __pyx_f[0], 3115, 0, __PYX_ERR(0, 3115, __pyx_L1_error)); + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + int __pyx_t_9; + __Pyx_RefNannySetupContext("pop", 0); + __Pyx_TraceCall("pop", __pyx_f[0], 3637, 0, __PYX_ERR(0, 3637, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3117 - * def items(self): - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3638 * - * def values(self): + * def pop(self, key, default=_nothing): + * try: # <<<<<<<<<<<<<< + * value = self[key] + * del self[key] */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_iteritems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3117, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3117, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { - /* "pysam/libcbcf.pyx":3115 - * return list(self) - * - * def items(self): # <<<<<<<<<<<<<< - * """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - * return list(self.iteritems()) + /* "pysam/libcbcf.pyx":3639 + * def pop(self, key, default=_nothing): + * try: + * value = self[key] # <<<<<<<<<<<<<< + * del self[key] + * return value */ + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3639, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_value = __pyx_t_4; + __pyx_t_4 = 0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.items", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":3640 + * try: + * value = self[key] + * del self[key] # <<<<<<<<<<<<<< + * return value + * except KeyError: + */ + if (unlikely(PyObject_DelItem(((PyObject *)__pyx_v_self), __pyx_v_key) < 0)) __PYX_ERR(0, 3640, __pyx_L3_error) -/* "pysam/libcbcf.pyx":3119 - * return list(self.iteritems()) + /* "pysam/libcbcf.pyx":3641 + * value = self[key] + * del self[key] + * return value # <<<<<<<<<<<<<< + * except KeyError: + * if default is not _nothing: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_value); + __pyx_r = __pyx_v_value; + goto __pyx_L7_try_return; + + /* "pysam/libcbcf.pyx":3638 * - * def values(self): # <<<<<<<<<<<<<< - * """D.values() -> list of D's values""" - * return list(self.itervalues()) + * def pop(self, key, default=_nothing): + * try: # <<<<<<<<<<<<<< + * value = self[key] + * del self[key] */ + } + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_27values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_9BaseIndex_26values[] = "BaseIndex.values(self)\nD.values() -> list of D's values"; -static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_27values(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("values (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_9BaseIndex_26values(((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_v_self)); + /* "pysam/libcbcf.pyx":3642 + * del self[key] + * return value + * except KeyError: # <<<<<<<<<<<<<< + * if default is not _nothing: + * return default + */ + __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); + if (__pyx_t_5) { + __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 3642, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libcbcf.pyx":3643 + * return value + * except KeyError: + * if default is not _nothing: # <<<<<<<<<<<<<< + * return default + * raise + */ + __pyx_t_8 = (__pyx_v_default != __pyx_v_5pysam_7libcbcf__nothing); + __pyx_t_9 = (__pyx_t_8 != 0); + if (__pyx_t_9) { -static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_26values(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("values", 0); - __Pyx_TraceCall("values", __pyx_f[0], 3119, 0, __PYX_ERR(0, 3119, __pyx_L1_error)); + /* "pysam/libcbcf.pyx":3644 + * except KeyError: + * if default is not _nothing: + * return default # <<<<<<<<<<<<<< + * raise + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_default); + __pyx_r = __pyx_v_default; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_except_return; - /* "pysam/libcbcf.pyx":3121 - * def values(self): - * """D.values() -> list of D's values""" - * return list(self.itervalues()) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3643 + * return value + * except KeyError: + * if default is not _nothing: # <<<<<<<<<<<<<< + * return default + * raise + */ + } + + /* "pysam/libcbcf.pyx":3645 + * if default is not _nothing: + * return default + * raise # <<<<<<<<<<<<<< * * # Mappings are not hashable by default, but subclasses can change this */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itervalues); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_6, __pyx_t_7); + __pyx_t_4 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0; + __PYX_ERR(0, 3645, __pyx_L5_except_error) } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "pysam/libcbcf.pyx":3638 + * + * def pop(self, key, default=_nothing): + * try: # <<<<<<<<<<<<<< + * value = self[key] + * del self[key] + */ + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L7_try_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + __pyx_L6_except_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3121, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3121, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - /* "pysam/libcbcf.pyx":3119 - * return list(self.iteritems()) + /* "pysam/libcbcf.pyx":3637 + * self[k] = v * - * def values(self): # <<<<<<<<<<<<<< - * """D.values() -> list of D's values""" - * return list(self.itervalues()) + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * try: + * value = self[key] */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libcbcf.BaseIndex.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_value); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); @@ -51922,20 +60663,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_26values(struct __pyx_obj_5 */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_29__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__[] = "BaseIndex.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_29__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_33__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_9BaseIndex_32__reduce_cython__[] = "BaseIndex.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_33__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_9BaseIndex_32__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_32__reduce_cython__(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self) { int __pyx_v_use_setstate; PyObject *__pyx_v_state = NULL; PyObject *__pyx_v__dict = NULL; @@ -51949,7 +60690,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__(struct int __pyx_t_5; PyObject *__pyx_t_6 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -51958,7 +60699,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__(struct * _dict = getattr(self, '__dict__', None) * if _dict is not None: */ - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_self->refmap); __Pyx_GIVEREF(__pyx_v_self->refmap); @@ -51976,7 +60717,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__(struct * if _dict is not None: * state += (_dict,) */ - __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v__dict = __pyx_t_1; __pyx_t_1 = 0; @@ -51999,12 +60740,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__(struct * use_setstate = True * else: */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v__dict); __Pyx_GIVEREF(__pyx_v__dict); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); @@ -52070,9 +60811,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__(struct * return __pyx_unpickle_BaseIndex, (type(self), 0xd936de3, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_BaseIndex); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_BaseIndex); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -52083,7 +60824,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__(struct __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); - __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); @@ -52116,9 +60857,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__(struct */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_BaseIndex); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_BaseIndex); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); @@ -52129,7 +60870,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__(struct __Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); @@ -52172,34 +60913,34 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__(struct */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_31__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_9BaseIndex_30__setstate_cython__[] = "BaseIndex.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_31__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_35__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_9BaseIndex_34__setstate_cython__[] = "BaseIndex.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_9BaseIndex_35__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_9BaseIndex_30__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_9BaseIndex_34__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_30__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_34__setstate_cython__(struct __pyx_obj_5pysam_7libcbcf_BaseIndex *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 14, 0, __PYX_ERR(2, 14, __pyx_L1_error)); /* "(tree fragment)":15 * return __pyx_unpickle_BaseIndex, (type(self), 0xd936de3, state) * def __setstate_cython__(self, __pyx_state): * __pyx_unpickle_BaseIndex__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_BaseIndex__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_BaseIndex__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -52224,7 +60965,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_9BaseIndex_30__setstate_cython__(struc return __pyx_r; } -/* "pysam/libcbcf.pyx":3131 +/* "pysam/libcbcf.pyx":3655 * cdef class BCFIndex(object): * """CSI index data structure for BCF files""" * def __init__(self): # <<<<<<<<<<<<<< @@ -52264,9 +61005,9 @@ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7 Py_ssize_t __pyx_t_6; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 3131, 0, __PYX_ERR(0, 3131, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 3655, 0, __PYX_ERR(0, 3655, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3132 + /* "pysam/libcbcf.pyx":3656 * """CSI index data structure for BCF files""" * def __init__(self): * self.refs = () # <<<<<<<<<<<<<< @@ -52279,14 +61020,14 @@ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7 __Pyx_DECREF(__pyx_v_self->__pyx_base.refs); __pyx_v_self->__pyx_base.refs = __pyx_empty_tuple; - /* "pysam/libcbcf.pyx":3133 + /* "pysam/libcbcf.pyx":3657 * def __init__(self): * self.refs = () * self.refmap = {} # <<<<<<<<<<<<<< * * if not self.ptr: */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3133, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3657, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->__pyx_base.refmap); @@ -52294,7 +61035,7 @@ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7 __pyx_v_self->__pyx_base.refmap = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3135 + /* "pysam/libcbcf.pyx":3659 * self.refmap = {} * * if not self.ptr: # <<<<<<<<<<<<<< @@ -52304,20 +61045,20 @@ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7 __pyx_t_2 = ((!(__pyx_v_self->ptr != 0)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":3136 + /* "pysam/libcbcf.pyx":3660 * * if not self.ptr: * raise ValueError('Invalid index object') # <<<<<<<<<<<<<< * * cdef int n */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__173, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3136, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__183, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3660, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3136, __pyx_L1_error) + __PYX_ERR(0, 3660, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3135 + /* "pysam/libcbcf.pyx":3659 * self.refmap = {} * * if not self.ptr: # <<<<<<<<<<<<<< @@ -52326,7 +61067,7 @@ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7 */ } - /* "pysam/libcbcf.pyx":3139 + /* "pysam/libcbcf.pyx":3663 * * cdef int n * cdef const char **refs = bcf_index_seqnames(self.ptr, self.header.ptr, &n) # <<<<<<<<<<<<<< @@ -52335,7 +61076,7 @@ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7 */ __pyx_v_refs = bcf_index_seqnames(__pyx_v_self->ptr, __pyx_v_self->header->ptr, (&__pyx_v_n)); - /* "pysam/libcbcf.pyx":3141 + /* "pysam/libcbcf.pyx":3665 * cdef const char **refs = bcf_index_seqnames(self.ptr, self.header.ptr, &n) * * self.refs = char_array_to_tuple(refs, n, free_after=1) if refs else () # <<<<<<<<<<<<<< @@ -52345,7 +61086,7 @@ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7 if ((__pyx_v_refs != 0)) { __pyx_t_4.__pyx_n = 1; __pyx_t_4.free_after = 1; - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_char_array_to_tuple(__pyx_v_refs, __pyx_v_n, &__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3141, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_char_array_to_tuple(__pyx_v_refs, __pyx_v_n, &__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3665, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = __pyx_t_3; __pyx_t_3 = 0; @@ -52359,7 +61100,7 @@ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7 __pyx_v_self->__pyx_base.refs = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3142 + /* "pysam/libcbcf.pyx":3666 * * self.refs = char_array_to_tuple(refs, n, free_after=1) if refs else () * self.refmap = { r:i for i,r in enumerate(self.refs) } # <<<<<<<<<<<<<< @@ -52367,7 +61108,7 @@ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7 * def __dealloc__(self): */ { /* enter inner scope */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3142, __pyx_L6_error) + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3666, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_int_0); __pyx_t_3 = __pyx_int_0; @@ -52375,21 +61116,21 @@ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7 for (;;) { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 3142, __pyx_L6_error) + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 3666, __pyx_L6_error) #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3142, __pyx_L6_error) + __pyx_t_7 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3666, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_7); #endif __Pyx_XDECREF_SET(__pyx_8genexpr6__pyx_v_r, __pyx_t_7); __pyx_t_7 = 0; __Pyx_INCREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_8genexpr6__pyx_v_i, __pyx_t_3); - __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3142, __pyx_L6_error) + __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3666, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = __pyx_t_7; __pyx_t_7 = 0; - if (unlikely(PyDict_SetItem(__pyx_t_1, (PyObject*)__pyx_8genexpr6__pyx_v_r, (PyObject*)__pyx_8genexpr6__pyx_v_i))) __PYX_ERR(0, 3142, __pyx_L6_error) + if (unlikely(PyDict_SetItem(__pyx_t_1, (PyObject*)__pyx_8genexpr6__pyx_v_r, (PyObject*)__pyx_8genexpr6__pyx_v_i))) __PYX_ERR(0, 3666, __pyx_L6_error) } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -52408,7 +61149,7 @@ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7 __pyx_v_self->__pyx_base.refmap = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3131 + /* "pysam/libcbcf.pyx":3655 * cdef class BCFIndex(object): * """CSI index data structure for BCF files""" * def __init__(self): # <<<<<<<<<<<<<< @@ -52434,7 +61175,7 @@ static int __pyx_pf_5pysam_7libcbcf_8BCFIndex___init__(struct __pyx_obj_5pysam_7 return __pyx_r; } -/* "pysam/libcbcf.pyx":3144 +/* "pysam/libcbcf.pyx":3668 * self.refmap = { r:i for i,r in enumerate(self.refs) } * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -52458,9 +61199,9 @@ static void __pyx_pf_5pysam_7libcbcf_8BCFIndex_2__dealloc__(struct __pyx_obj_5py __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 3144, 0, __PYX_ERR(0, 3144, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 3668, 0, __PYX_ERR(0, 3668, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3145 + /* "pysam/libcbcf.pyx":3669 * * def __dealloc__(self): * if self.ptr: # <<<<<<<<<<<<<< @@ -52470,7 +61211,7 @@ static void __pyx_pf_5pysam_7libcbcf_8BCFIndex_2__dealloc__(struct __pyx_obj_5py __pyx_t_1 = (__pyx_v_self->ptr != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3146 + /* "pysam/libcbcf.pyx":3670 * def __dealloc__(self): * if self.ptr: * hts_idx_destroy(self.ptr) # <<<<<<<<<<<<<< @@ -52479,16 +61220,16 @@ static void __pyx_pf_5pysam_7libcbcf_8BCFIndex_2__dealloc__(struct __pyx_obj_5py */ hts_idx_destroy(__pyx_v_self->ptr); - /* "pysam/libcbcf.pyx":3147 + /* "pysam/libcbcf.pyx":3671 * if self.ptr: * hts_idx_destroy(self.ptr) * self.ptr = NULL # <<<<<<<<<<<<<< * - * def fetch(self, bcf, contig, start, stop, region, reopen): + * def fetch(self, bcf, contig, start, stop, reopen): */ __pyx_v_self->ptr = NULL; - /* "pysam/libcbcf.pyx":3145 + /* "pysam/libcbcf.pyx":3669 * * def __dealloc__(self): * if self.ptr: # <<<<<<<<<<<<<< @@ -52497,7 +61238,7 @@ static void __pyx_pf_5pysam_7libcbcf_8BCFIndex_2__dealloc__(struct __pyx_obj_5py */ } - /* "pysam/libcbcf.pyx":3144 + /* "pysam/libcbcf.pyx":3668 * self.refmap = { r:i for i,r in enumerate(self.refs) } * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -52514,36 +61255,33 @@ static void __pyx_pf_5pysam_7libcbcf_8BCFIndex_2__dealloc__(struct __pyx_obj_5py __Pyx_RefNannyFinishContext(); } -/* "pysam/libcbcf.pyx":3149 +/* "pysam/libcbcf.pyx":3673 * self.ptr = NULL * - * def fetch(self, bcf, contig, start, stop, region, reopen): # <<<<<<<<<<<<<< - * return BCFIterator(bcf, contig, start, stop, region, reopen) + * def fetch(self, bcf, contig, start, stop, reopen): # <<<<<<<<<<<<<< + * return BCFIterator(bcf, contig, start, stop, reopen) * */ /* Python wrapper */ static PyObject *__pyx_pw_5pysam_7libcbcf_8BCFIndex_5fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_8BCFIndex_4fetch[] = "BCFIndex.fetch(self, bcf, contig, start, stop, region, reopen)"; +static char __pyx_doc_5pysam_7libcbcf_8BCFIndex_4fetch[] = "BCFIndex.fetch(self, bcf, contig, start, stop, reopen)"; static PyObject *__pyx_pw_5pysam_7libcbcf_8BCFIndex_5fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_bcf = 0; PyObject *__pyx_v_contig = 0; PyObject *__pyx_v_start = 0; PyObject *__pyx_v_stop = 0; - PyObject *__pyx_v_region = 0; PyObject *__pyx_v_reopen = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("fetch (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_bcf,&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_reopen,0}; - PyObject* values[6] = {0,0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_bcf,&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_reopen,0}; + PyObject* values[5] = {0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -52566,37 +61304,31 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_8BCFIndex_5fetch(PyObject *__pyx_v_sel case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_contig)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("fetch", 1, 6, 6, 1); __PYX_ERR(0, 3149, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 1, 5, 5, 1); __PYX_ERR(0, 3673, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("fetch", 1, 6, 6, 2); __PYX_ERR(0, 3149, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 1, 5, 5, 2); __PYX_ERR(0, 3673, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("fetch", 1, 6, 6, 3); __PYX_ERR(0, 3149, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 1, 5, 5, 3); __PYX_ERR(0, 3673, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: - if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fetch", 1, 6, 6, 4); __PYX_ERR(0, 3149, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 5: - if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reopen)) != 0)) kw_args--; + if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reopen)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("fetch", 1, 6, 6, 5); __PYX_ERR(0, 3149, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 1, 5, 5, 4); __PYX_ERR(0, 3673, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 3149, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 3673, __pyx_L3_error) } - } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { + } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -52604,48 +61336,46 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_8BCFIndex_5fetch(PyObject *__pyx_v_sel values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - values[5] = PyTuple_GET_ITEM(__pyx_args, 5); } __pyx_v_bcf = values[0]; __pyx_v_contig = values[1]; __pyx_v_start = values[2]; __pyx_v_stop = values[3]; - __pyx_v_region = values[4]; - __pyx_v_reopen = values[5]; + __pyx_v_reopen = values[4]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fetch", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3149, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3673, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.BCFIndex.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_7libcbcf_8BCFIndex_4fetch(((struct __pyx_obj_5pysam_7libcbcf_BCFIndex *)__pyx_v_self), __pyx_v_bcf, __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_reopen); + __pyx_r = __pyx_pf_5pysam_7libcbcf_8BCFIndex_4fetch(((struct __pyx_obj_5pysam_7libcbcf_BCFIndex *)__pyx_v_self), __pyx_v_bcf, __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_reopen); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_4fetch(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_v_self, PyObject *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reopen) { +static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_4fetch(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_v_self, PyObject *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_reopen) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("fetch", 0); - __Pyx_TraceCall("fetch", __pyx_f[0], 3149, 0, __PYX_ERR(0, 3149, __pyx_L1_error)); + __Pyx_TraceCall("fetch", __pyx_f[0], 3673, 0, __PYX_ERR(0, 3673, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3150 + /* "pysam/libcbcf.pyx":3674 * - * def fetch(self, bcf, contig, start, stop, region, reopen): - * return BCFIterator(bcf, contig, start, stop, region, reopen) # <<<<<<<<<<<<<< + * def fetch(self, bcf, contig, start, stop, reopen): + * return BCFIterator(bcf, contig, start, stop, reopen) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3150, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3674, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_bcf); __Pyx_GIVEREF(__pyx_v_bcf); @@ -52659,24 +61389,21 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_4fetch(CYTHON_UNUSED struct __Pyx_INCREF(__pyx_v_stop); __Pyx_GIVEREF(__pyx_v_stop); PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_stop); - __Pyx_INCREF(__pyx_v_region); - __Pyx_GIVEREF(__pyx_v_region); - PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_region); __Pyx_INCREF(__pyx_v_reopen); __Pyx_GIVEREF(__pyx_v_reopen); - PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_v_reopen); - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_7libcbcf_BCFIterator), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3150, __pyx_L1_error) + PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_reopen); + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_7libcbcf_BCFIterator), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3674, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3149 + /* "pysam/libcbcf.pyx":3673 * self.ptr = NULL * - * def fetch(self, bcf, contig, start, stop, region, reopen): # <<<<<<<<<<<<<< - * return BCFIterator(bcf, contig, start, stop, region, reopen) + * def fetch(self, bcf, contig, start, stop, reopen): # <<<<<<<<<<<<<< + * return BCFIterator(bcf, contig, start, stop, reopen) * */ @@ -52693,6 +61420,49 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_4fetch(CYTHON_UNUSED struct return __pyx_r; } +/* "pysam/libcbcf.pxd":109 + * + * cdef class BCFIndex(BaseIndex): + * cdef readonly VariantHeader header # <<<<<<<<<<<<<< + * cdef hts_idx_t *ptr + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_8BCFIndex_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_8BCFIndex_6header_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_8BCFIndex_6header___get__(((struct __pyx_obj_5pysam_7libcbcf_BCFIndex *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_6header___get__(struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[1], 109, 0, __PYX_ERR(1, 109, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); + __pyx_r = ((PyObject *)__pyx_v_self->header); + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcbcf.BCFIndex.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * raise TypeError("self.ptr cannot be converted to a Python object for pickling") @@ -52719,7 +61489,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_6__reduce_cython__(CYTHON_UN __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -52727,11 +61497,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_6__reduce_cython__(CYTHON_UN * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__174, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__184, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + __PYX_ERR(2, 2, __pyx_L1_error) /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< @@ -52777,18 +61547,18 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_8__setstate_cython__(CYTHON_ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 3, 0, __PYX_ERR(2, 3, __pyx_L1_error)); /* "(tree fragment)":4 * raise TypeError("self.ptr cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__175, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__185, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -52808,7 +61578,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8BCFIndex_8__setstate_cython__(CYTHON_ return __pyx_r; } -/* "pysam/libcbcf.pyx":3153 +/* "pysam/libcbcf.pyx":3677 * * * cdef BCFIndex makeBCFIndex(VariantHeader header, hts_idx_t *idx): # <<<<<<<<<<<<<< @@ -52827,9 +61597,9 @@ static struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_f_5pysam_7libcbcf_makeBC PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("makeBCFIndex", 0); - __Pyx_TraceCall("makeBCFIndex", __pyx_f[0], 3153, 0, __PYX_ERR(0, 3153, __pyx_L1_error)); + __Pyx_TraceCall("makeBCFIndex", __pyx_f[0], 3677, 0, __PYX_ERR(0, 3677, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3154 + /* "pysam/libcbcf.pyx":3678 * * cdef BCFIndex makeBCFIndex(VariantHeader header, hts_idx_t *idx): * if not idx: # <<<<<<<<<<<<<< @@ -52839,7 +61609,7 @@ static struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_f_5pysam_7libcbcf_makeBC __pyx_t_1 = ((!(__pyx_v_idx != 0)) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3155 + /* "pysam/libcbcf.pyx":3679 * cdef BCFIndex makeBCFIndex(VariantHeader header, hts_idx_t *idx): * if not idx: * return None # <<<<<<<<<<<<<< @@ -52850,7 +61620,7 @@ static struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_f_5pysam_7libcbcf_makeBC __pyx_r = ((struct __pyx_obj_5pysam_7libcbcf_BCFIndex *)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":3154 + /* "pysam/libcbcf.pyx":3678 * * cdef BCFIndex makeBCFIndex(VariantHeader header, hts_idx_t *idx): * if not idx: # <<<<<<<<<<<<<< @@ -52859,31 +61629,31 @@ static struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_f_5pysam_7libcbcf_makeBC */ } - /* "pysam/libcbcf.pyx":3157 + /* "pysam/libcbcf.pyx":3681 * return None * * if not header: # <<<<<<<<<<<<<< * raise ValueError('invalid VariantHeader') * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 3157, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 3681, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":3158 + /* "pysam/libcbcf.pyx":3682 * * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * cdef BCFIndex index = BCFIndex.__new__(BCFIndex) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__176, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3158, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__186, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3682, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 3158, __pyx_L1_error) + __PYX_ERR(0, 3682, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3157 + /* "pysam/libcbcf.pyx":3681 * return None * * if not header: # <<<<<<<<<<<<<< @@ -52892,19 +61662,19 @@ static struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_f_5pysam_7libcbcf_makeBC */ } - /* "pysam/libcbcf.pyx":3160 + /* "pysam/libcbcf.pyx":3684 * raise ValueError('invalid VariantHeader') * * cdef BCFIndex index = BCFIndex.__new__(BCFIndex) # <<<<<<<<<<<<<< * index.header = header * index.ptr = idx */ - __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_BCFIndex(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_BCFIndex), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3160, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_BCFIndex(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_BCFIndex), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3684, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_v_index = ((struct __pyx_obj_5pysam_7libcbcf_BCFIndex *)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":3161 + /* "pysam/libcbcf.pyx":3685 * * cdef BCFIndex index = BCFIndex.__new__(BCFIndex) * index.header = header # <<<<<<<<<<<<<< @@ -52917,7 +61687,7 @@ static struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_f_5pysam_7libcbcf_makeBC __Pyx_DECREF(((PyObject *)__pyx_v_index->header)); __pyx_v_index->header = __pyx_v_header; - /* "pysam/libcbcf.pyx":3162 + /* "pysam/libcbcf.pyx":3686 * cdef BCFIndex index = BCFIndex.__new__(BCFIndex) * index.header = header * index.ptr = idx # <<<<<<<<<<<<<< @@ -52926,14 +61696,14 @@ static struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_f_5pysam_7libcbcf_makeBC */ __pyx_v_index->ptr = __pyx_v_idx; - /* "pysam/libcbcf.pyx":3163 + /* "pysam/libcbcf.pyx":3687 * index.header = header * index.ptr = idx * index.__init__() # <<<<<<<<<<<<<< * * return index */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_index), __pyx_n_s_init); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3163, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_index), __pyx_n_s_init); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3687, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { @@ -52946,16 +61716,16 @@ static struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_f_5pysam_7libcbcf_makeBC } } if (__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3163, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3687, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { - __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3163, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3687, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":3165 + /* "pysam/libcbcf.pyx":3689 * index.__init__() * * return index # <<<<<<<<<<<<<< @@ -52967,7 +61737,7 @@ static struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_f_5pysam_7libcbcf_makeBC __pyx_r = __pyx_v_index; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3153 + /* "pysam/libcbcf.pyx":3677 * * * cdef BCFIndex makeBCFIndex(VariantHeader header, hts_idx_t *idx): # <<<<<<<<<<<<<< @@ -52990,7 +61760,7 @@ static struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_f_5pysam_7libcbcf_makeBC return __pyx_r; } -/* "pysam/libcbcf.pyx":3170 +/* "pysam/libcbcf.pyx":3694 * cdef class TabixIndex(BaseIndex): * """Tabix index data structure for VCF files""" * def __init__(self): # <<<<<<<<<<<<<< @@ -53030,9 +61800,9 @@ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysa Py_ssize_t __pyx_t_6; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 3170, 0, __PYX_ERR(0, 3170, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 3694, 0, __PYX_ERR(0, 3694, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3171 + /* "pysam/libcbcf.pyx":3695 * """Tabix index data structure for VCF files""" * def __init__(self): * self.refs = () # <<<<<<<<<<<<<< @@ -53045,14 +61815,14 @@ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysa __Pyx_DECREF(__pyx_v_self->__pyx_base.refs); __pyx_v_self->__pyx_base.refs = __pyx_empty_tuple; - /* "pysam/libcbcf.pyx":3172 + /* "pysam/libcbcf.pyx":3696 * def __init__(self): * self.refs = () * self.refmap = {} # <<<<<<<<<<<<<< * * if not self.ptr: */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3172, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3696, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->__pyx_base.refmap); @@ -53060,7 +61830,7 @@ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysa __pyx_v_self->__pyx_base.refmap = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3174 + /* "pysam/libcbcf.pyx":3698 * self.refmap = {} * * if not self.ptr: # <<<<<<<<<<<<<< @@ -53070,20 +61840,20 @@ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysa __pyx_t_2 = ((!(__pyx_v_self->ptr != 0)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":3175 + /* "pysam/libcbcf.pyx":3699 * * if not self.ptr: * raise ValueError('Invalid index object') # <<<<<<<<<<<<<< * * cdef int n */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__177, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3175, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__187, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3699, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3175, __pyx_L1_error) + __PYX_ERR(0, 3699, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3174 + /* "pysam/libcbcf.pyx":3698 * self.refmap = {} * * if not self.ptr: # <<<<<<<<<<<<<< @@ -53092,7 +61862,7 @@ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysa */ } - /* "pysam/libcbcf.pyx":3178 + /* "pysam/libcbcf.pyx":3702 * * cdef int n * cdef const char **refs = tbx_seqnames(self.ptr, &n) # <<<<<<<<<<<<<< @@ -53101,7 +61871,7 @@ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysa */ __pyx_v_refs = tbx_seqnames(__pyx_v_self->ptr, (&__pyx_v_n)); - /* "pysam/libcbcf.pyx":3180 + /* "pysam/libcbcf.pyx":3704 * cdef const char **refs = tbx_seqnames(self.ptr, &n) * * self.refs = char_array_to_tuple(refs, n, free_after=1) if refs else () # <<<<<<<<<<<<<< @@ -53111,7 +61881,7 @@ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysa if ((__pyx_v_refs != 0)) { __pyx_t_4.__pyx_n = 1; __pyx_t_4.free_after = 1; - __pyx_t_3 = __pyx_f_5pysam_7libcbcf_char_array_to_tuple(__pyx_v_refs, __pyx_v_n, &__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3180, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf_char_array_to_tuple(__pyx_v_refs, __pyx_v_n, &__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3704, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = __pyx_t_3; __pyx_t_3 = 0; @@ -53125,7 +61895,7 @@ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysa __pyx_v_self->__pyx_base.refs = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3181 + /* "pysam/libcbcf.pyx":3705 * * self.refs = char_array_to_tuple(refs, n, free_after=1) if refs else () * self.refmap = { r:i for i,r in enumerate(self.refs) } # <<<<<<<<<<<<<< @@ -53133,7 +61903,7 @@ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysa * def __dealloc__(self): */ { /* enter inner scope */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3181, __pyx_L6_error) + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3705, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_int_0); __pyx_t_3 = __pyx_int_0; @@ -53141,21 +61911,21 @@ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysa for (;;) { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 3181, __pyx_L6_error) + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 3705, __pyx_L6_error) #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3181, __pyx_L6_error) + __pyx_t_7 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3705, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_7); #endif __Pyx_XDECREF_SET(__pyx_8genexpr7__pyx_v_r, __pyx_t_7); __pyx_t_7 = 0; __Pyx_INCREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_8genexpr7__pyx_v_i, __pyx_t_3); - __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3181, __pyx_L6_error) + __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3705, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = __pyx_t_7; __pyx_t_7 = 0; - if (unlikely(PyDict_SetItem(__pyx_t_1, (PyObject*)__pyx_8genexpr7__pyx_v_r, (PyObject*)__pyx_8genexpr7__pyx_v_i))) __PYX_ERR(0, 3181, __pyx_L6_error) + if (unlikely(PyDict_SetItem(__pyx_t_1, (PyObject*)__pyx_8genexpr7__pyx_v_r, (PyObject*)__pyx_8genexpr7__pyx_v_i))) __PYX_ERR(0, 3705, __pyx_L6_error) } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -53174,7 +61944,7 @@ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysa __pyx_v_self->__pyx_base.refmap = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3170 + /* "pysam/libcbcf.pyx":3694 * cdef class TabixIndex(BaseIndex): * """Tabix index data structure for VCF files""" * def __init__(self): # <<<<<<<<<<<<<< @@ -53200,7 +61970,7 @@ static int __pyx_pf_5pysam_7libcbcf_10TabixIndex___init__(struct __pyx_obj_5pysa return __pyx_r; } -/* "pysam/libcbcf.pyx":3183 +/* "pysam/libcbcf.pyx":3707 * self.refmap = { r:i for i,r in enumerate(self.refs) } * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -53224,9 +61994,9 @@ static void __pyx_pf_5pysam_7libcbcf_10TabixIndex_2__dealloc__(struct __pyx_obj_ __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 3183, 0, __PYX_ERR(0, 3183, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 3707, 0, __PYX_ERR(0, 3707, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3184 + /* "pysam/libcbcf.pyx":3708 * * def __dealloc__(self): * if self.ptr: # <<<<<<<<<<<<<< @@ -53236,7 +62006,7 @@ static void __pyx_pf_5pysam_7libcbcf_10TabixIndex_2__dealloc__(struct __pyx_obj_ __pyx_t_1 = (__pyx_v_self->ptr != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3185 + /* "pysam/libcbcf.pyx":3709 * def __dealloc__(self): * if self.ptr: * tbx_destroy(self.ptr) # <<<<<<<<<<<<<< @@ -53245,16 +62015,16 @@ static void __pyx_pf_5pysam_7libcbcf_10TabixIndex_2__dealloc__(struct __pyx_obj_ */ tbx_destroy(__pyx_v_self->ptr); - /* "pysam/libcbcf.pyx":3186 + /* "pysam/libcbcf.pyx":3710 * if self.ptr: * tbx_destroy(self.ptr) * self.ptr = NULL # <<<<<<<<<<<<<< * - * def fetch(self, bcf, contig, start, stop, region, reopen): + * def fetch(self, bcf, contig, start, stop, reopen): */ __pyx_v_self->ptr = NULL; - /* "pysam/libcbcf.pyx":3184 + /* "pysam/libcbcf.pyx":3708 * * def __dealloc__(self): * if self.ptr: # <<<<<<<<<<<<<< @@ -53263,7 +62033,7 @@ static void __pyx_pf_5pysam_7libcbcf_10TabixIndex_2__dealloc__(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3183 + /* "pysam/libcbcf.pyx":3707 * self.refmap = { r:i for i,r in enumerate(self.refs) } * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -53280,36 +62050,33 @@ static void __pyx_pf_5pysam_7libcbcf_10TabixIndex_2__dealloc__(struct __pyx_obj_ __Pyx_RefNannyFinishContext(); } -/* "pysam/libcbcf.pyx":3188 +/* "pysam/libcbcf.pyx":3712 * self.ptr = NULL * - * def fetch(self, bcf, contig, start, stop, region, reopen): # <<<<<<<<<<<<<< - * return TabixIterator(bcf, contig, start, stop, region, reopen) + * def fetch(self, bcf, contig, start, stop, reopen): # <<<<<<<<<<<<<< + * return TabixIterator(bcf, contig, start, stop, reopen) * */ /* Python wrapper */ static PyObject *__pyx_pw_5pysam_7libcbcf_10TabixIndex_5fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_10TabixIndex_4fetch[] = "TabixIndex.fetch(self, bcf, contig, start, stop, region, reopen)"; +static char __pyx_doc_5pysam_7libcbcf_10TabixIndex_4fetch[] = "TabixIndex.fetch(self, bcf, contig, start, stop, reopen)"; static PyObject *__pyx_pw_5pysam_7libcbcf_10TabixIndex_5fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_bcf = 0; PyObject *__pyx_v_contig = 0; PyObject *__pyx_v_start = 0; PyObject *__pyx_v_stop = 0; - PyObject *__pyx_v_region = 0; PyObject *__pyx_v_reopen = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("fetch (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_bcf,&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_reopen,0}; - PyObject* values[6] = {0,0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_bcf,&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_reopen,0}; + PyObject* values[5] = {0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -53332,37 +62099,31 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_10TabixIndex_5fetch(PyObject *__pyx_v_ case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_contig)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("fetch", 1, 6, 6, 1); __PYX_ERR(0, 3188, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 1, 5, 5, 1); __PYX_ERR(0, 3712, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("fetch", 1, 6, 6, 2); __PYX_ERR(0, 3188, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 1, 5, 5, 2); __PYX_ERR(0, 3712, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("fetch", 1, 6, 6, 3); __PYX_ERR(0, 3188, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 1, 5, 5, 3); __PYX_ERR(0, 3712, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: - if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("fetch", 1, 6, 6, 4); __PYX_ERR(0, 3188, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 5: - if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reopen)) != 0)) kw_args--; + if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reopen)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("fetch", 1, 6, 6, 5); __PYX_ERR(0, 3188, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 1, 5, 5, 4); __PYX_ERR(0, 3712, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 3188, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 3712, __pyx_L3_error) } - } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { + } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -53370,48 +62131,46 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_10TabixIndex_5fetch(PyObject *__pyx_v_ values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - values[5] = PyTuple_GET_ITEM(__pyx_args, 5); } __pyx_v_bcf = values[0]; __pyx_v_contig = values[1]; __pyx_v_start = values[2]; __pyx_v_stop = values[3]; - __pyx_v_region = values[4]; - __pyx_v_reopen = values[5]; + __pyx_v_reopen = values[4]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fetch", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3188, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3712, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.TabixIndex.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_7libcbcf_10TabixIndex_4fetch(((struct __pyx_obj_5pysam_7libcbcf_TabixIndex *)__pyx_v_self), __pyx_v_bcf, __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_reopen); + __pyx_r = __pyx_pf_5pysam_7libcbcf_10TabixIndex_4fetch(((struct __pyx_obj_5pysam_7libcbcf_TabixIndex *)__pyx_v_self), __pyx_v_bcf, __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_reopen); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_10TabixIndex_4fetch(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_v_self, PyObject *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reopen) { +static PyObject *__pyx_pf_5pysam_7libcbcf_10TabixIndex_4fetch(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_v_self, PyObject *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_reopen) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("fetch", 0); - __Pyx_TraceCall("fetch", __pyx_f[0], 3188, 0, __PYX_ERR(0, 3188, __pyx_L1_error)); + __Pyx_TraceCall("fetch", __pyx_f[0], 3712, 0, __PYX_ERR(0, 3712, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3189 + /* "pysam/libcbcf.pyx":3713 * - * def fetch(self, bcf, contig, start, stop, region, reopen): - * return TabixIterator(bcf, contig, start, stop, region, reopen) # <<<<<<<<<<<<<< + * def fetch(self, bcf, contig, start, stop, reopen): + * return TabixIterator(bcf, contig, start, stop, reopen) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3189, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3713, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_bcf); __Pyx_GIVEREF(__pyx_v_bcf); @@ -53425,24 +62184,21 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10TabixIndex_4fetch(CYTHON_UNUSED stru __Pyx_INCREF(__pyx_v_stop); __Pyx_GIVEREF(__pyx_v_stop); PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_stop); - __Pyx_INCREF(__pyx_v_region); - __Pyx_GIVEREF(__pyx_v_region); - PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_region); __Pyx_INCREF(__pyx_v_reopen); __Pyx_GIVEREF(__pyx_v_reopen); - PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_v_reopen); - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_7libcbcf_TabixIterator), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3189, __pyx_L1_error) + PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_reopen); + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_7libcbcf_TabixIterator), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3713, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3188 + /* "pysam/libcbcf.pyx":3712 * self.ptr = NULL * - * def fetch(self, bcf, contig, start, stop, region, reopen): # <<<<<<<<<<<<<< - * return TabixIterator(bcf, contig, start, stop, region, reopen) + * def fetch(self, bcf, contig, start, stop, reopen): # <<<<<<<<<<<<<< + * return TabixIterator(bcf, contig, start, stop, reopen) * */ @@ -53485,7 +62241,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10TabixIndex_6__reduce_cython__(CYTHON __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -53493,11 +62249,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10TabixIndex_6__reduce_cython__(CYTHON * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__178, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__188, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + __PYX_ERR(2, 2, __pyx_L1_error) /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< @@ -53543,18 +62299,18 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10TabixIndex_8__setstate_cython__(CYTH __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 3, 0, __PYX_ERR(2, 3, __pyx_L1_error)); /* "(tree fragment)":4 * raise TypeError("self.ptr cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__179, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__189, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -53574,7 +62330,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10TabixIndex_8__setstate_cython__(CYTH return __pyx_r; } -/* "pysam/libcbcf.pyx":3192 +/* "pysam/libcbcf.pyx":3716 * * * cdef TabixIndex makeTabixIndex(tbx_t *idx): # <<<<<<<<<<<<<< @@ -53592,9 +62348,9 @@ static struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_f_5pysam_7libcbcf_make PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("makeTabixIndex", 0); - __Pyx_TraceCall("makeTabixIndex", __pyx_f[0], 3192, 0, __PYX_ERR(0, 3192, __pyx_L1_error)); + __Pyx_TraceCall("makeTabixIndex", __pyx_f[0], 3716, 0, __PYX_ERR(0, 3716, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3193 + /* "pysam/libcbcf.pyx":3717 * * cdef TabixIndex makeTabixIndex(tbx_t *idx): * if not idx: # <<<<<<<<<<<<<< @@ -53604,7 +62360,7 @@ static struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_f_5pysam_7libcbcf_make __pyx_t_1 = ((!(__pyx_v_idx != 0)) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3194 + /* "pysam/libcbcf.pyx":3718 * cdef TabixIndex makeTabixIndex(tbx_t *idx): * if not idx: * return None # <<<<<<<<<<<<<< @@ -53615,7 +62371,7 @@ static struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_f_5pysam_7libcbcf_make __pyx_r = ((struct __pyx_obj_5pysam_7libcbcf_TabixIndex *)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbcf.pyx":3193 + /* "pysam/libcbcf.pyx":3717 * * cdef TabixIndex makeTabixIndex(tbx_t *idx): * if not idx: # <<<<<<<<<<<<<< @@ -53624,19 +62380,19 @@ static struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_f_5pysam_7libcbcf_make */ } - /* "pysam/libcbcf.pyx":3196 + /* "pysam/libcbcf.pyx":3720 * return None * * cdef TabixIndex index = TabixIndex.__new__(TabixIndex) # <<<<<<<<<<<<<< * index.ptr = idx * index.__init__() */ - __pyx_t_2 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_TabixIndex(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_TabixIndex), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3196, __pyx_L1_error) + __pyx_t_2 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_TabixIndex(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_TabixIndex), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3720, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __pyx_v_index = ((struct __pyx_obj_5pysam_7libcbcf_TabixIndex *)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":3197 + /* "pysam/libcbcf.pyx":3721 * * cdef TabixIndex index = TabixIndex.__new__(TabixIndex) * index.ptr = idx # <<<<<<<<<<<<<< @@ -53645,14 +62401,14 @@ static struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_f_5pysam_7libcbcf_make */ __pyx_v_index->ptr = __pyx_v_idx; - /* "pysam/libcbcf.pyx":3198 + /* "pysam/libcbcf.pyx":3722 * cdef TabixIndex index = TabixIndex.__new__(TabixIndex) * index.ptr = idx * index.__init__() # <<<<<<<<<<<<<< * * return index */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_index), __pyx_n_s_init); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3198, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_index), __pyx_n_s_init); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3722, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { @@ -53665,16 +62421,16 @@ static struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_f_5pysam_7libcbcf_make } } if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3198, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3722, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3198, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3722, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":3200 + /* "pysam/libcbcf.pyx":3724 * index.__init__() * * return index # <<<<<<<<<<<<<< @@ -53686,7 +62442,7 @@ static struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_f_5pysam_7libcbcf_make __pyx_r = __pyx_v_index; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3192 + /* "pysam/libcbcf.pyx":3716 * * * cdef TabixIndex makeTabixIndex(tbx_t *idx): # <<<<<<<<<<<<<< @@ -53735,7 +62491,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12BaseIterator___reduce_cython__(CYTHO __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -53743,11 +62499,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12BaseIterator___reduce_cython__(CYTHO * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iter cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__180, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__190, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + __PYX_ERR(2, 2, __pyx_L1_error) /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< @@ -53793,18 +62549,18 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12BaseIterator_2__setstate_cython__(CY __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 3, 0, __PYX_ERR(2, 3, __pyx_L1_error)); /* "(tree fragment)":4 * raise TypeError("self.iter cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__181, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__191, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -53824,7 +62580,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12BaseIterator_2__setstate_cython__(CY return __pyx_r; } -/* "pysam/libcbcf.pyx":3215 +/* "pysam/libcbcf.pyx":3739 * # Interal function to clean up after iteration stop or failure. * # This would be a nested function if it weren't a cdef function. * cdef void _stop_BCFIterator(BCFIterator self, bcf1_t *record): # <<<<<<<<<<<<<< @@ -53836,9 +62592,9 @@ static void __pyx_f_5pysam_7libcbcf__stop_BCFIterator(struct __pyx_obj_5pysam_7l __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("_stop_BCFIterator", 0); - __Pyx_TraceCall("_stop_BCFIterator", __pyx_f[0], 3215, 0, __PYX_ERR(0, 3215, __pyx_L1_error)); + __Pyx_TraceCall("_stop_BCFIterator", __pyx_f[0], 3739, 0, __PYX_ERR(0, 3739, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3216 + /* "pysam/libcbcf.pyx":3740 * # This would be a nested function if it weren't a cdef function. * cdef void _stop_BCFIterator(BCFIterator self, bcf1_t *record): * bcf_destroy1(record) # <<<<<<<<<<<<<< @@ -53847,7 +62603,7 @@ static void __pyx_f_5pysam_7libcbcf__stop_BCFIterator(struct __pyx_obj_5pysam_7l */ bcf_destroy1(__pyx_v_record); - /* "pysam/libcbcf.pyx":3219 + /* "pysam/libcbcf.pyx":3743 * * # destroy iter so future calls to __next__ raise StopIteration * bcf_itr_destroy(self.iter) # <<<<<<<<<<<<<< @@ -53856,7 +62612,7 @@ static void __pyx_f_5pysam_7libcbcf__stop_BCFIterator(struct __pyx_obj_5pysam_7l */ bcf_itr_destroy(__pyx_v_self->__pyx_base.iter); - /* "pysam/libcbcf.pyx":3220 + /* "pysam/libcbcf.pyx":3744 * # destroy iter so future calls to __next__ raise StopIteration * bcf_itr_destroy(self.iter) * self.iter = NULL # <<<<<<<<<<<<<< @@ -53865,7 +62621,7 @@ static void __pyx_f_5pysam_7libcbcf__stop_BCFIterator(struct __pyx_obj_5pysam_7l */ __pyx_v_self->__pyx_base.iter = NULL; - /* "pysam/libcbcf.pyx":3215 + /* "pysam/libcbcf.pyx":3739 * # Interal function to clean up after iteration stop or failure. * # This would be a nested function if it weren't a cdef function. * cdef void _stop_BCFIterator(BCFIterator self, bcf1_t *record): # <<<<<<<<<<<<<< @@ -53882,10 +62638,10 @@ static void __pyx_f_5pysam_7libcbcf__stop_BCFIterator(struct __pyx_obj_5pysam_7l __Pyx_RefNannyFinishContext(); } -/* "pysam/libcbcf.pyx":3224 +/* "pysam/libcbcf.pyx":3748 * * cdef class BCFIterator(BaseIterator): - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): # <<<<<<<<<<<<<< + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): # <<<<<<<<<<<<<< * if bcf is None: * raise ValueError('bcf must not be None') */ @@ -53897,25 +62653,21 @@ static int __pyx_pw_5pysam_7libcbcf_11BCFIterator_1__init__(PyObject *__pyx_v_se PyObject *__pyx_v_contig = 0; PyObject *__pyx_v_start = 0; PyObject *__pyx_v_stop = 0; - PyObject *__pyx_v_region = 0; PyObject *__pyx_v_reopen = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_bcf,&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_reopen,0}; - PyObject* values[6] = {0,0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_bcf,&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_reopen,0}; + PyObject* values[5] = {0,0,0,0,0}; values[1] = ((PyObject *)Py_None); values[2] = ((PyObject *)Py_None); values[3] = ((PyObject *)Py_None); - values[4] = ((PyObject *)Py_None); - values[5] = ((PyObject *)Py_True); + values[4] = ((PyObject *)Py_True); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -53954,24 +62706,16 @@ static int __pyx_pw_5pysam_7libcbcf_11BCFIterator_1__init__(PyObject *__pyx_v_se } CYTHON_FALLTHROUGH; case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region); - if (value) { values[4] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 5: if (kw_args > 0) { PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reopen); - if (value) { values[5] = value; kw_args--; } + if (value) { values[4] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 3224, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 3748, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -53989,19 +62733,18 @@ static int __pyx_pw_5pysam_7libcbcf_11BCFIterator_1__init__(PyObject *__pyx_v_se __pyx_v_contig = values[1]; __pyx_v_start = values[2]; __pyx_v_stop = values[3]; - __pyx_v_region = values[4]; - __pyx_v_reopen = values[5]; + __pyx_v_reopen = values[4]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3224, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3748, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.BCFIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_bcf), __pyx_ptype_5pysam_7libcbcf_VariantFile, 1, "bcf", 0))) __PYX_ERR(0, 3224, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_7libcbcf_11BCFIterator___init__(((struct __pyx_obj_5pysam_7libcbcf_BCFIterator *)__pyx_v_self), __pyx_v_bcf, __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_reopen); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_bcf), __pyx_ptype_5pysam_7libcbcf_VariantFile, 1, "bcf", 0))) __PYX_ERR(0, 3748, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_7libcbcf_11BCFIterator___init__(((struct __pyx_obj_5pysam_7libcbcf_BCFIterator *)__pyx_v_self), __pyx_v_bcf, __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_reopen); /* function exit code */ goto __pyx_L0; @@ -54012,13 +62755,11 @@ static int __pyx_pw_5pysam_7libcbcf_11BCFIterator_1__init__(PyObject *__pyx_v_se return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_11BCFIterator___init__(struct __pyx_obj_5pysam_7libcbcf_BCFIterator *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reopen) { +static int __pyx_pf_5pysam_7libcbcf_11BCFIterator___init__(struct __pyx_obj_5pysam_7libcbcf_BCFIterator *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_reopen) { struct __pyx_obj_5pysam_7libcbcf_BCFIndex *__pyx_v_index = 0; int __pyx_v_rid; int __pyx_v_cstart; int __pyx_v_cstop; - char *__pyx_v_cregion; - PyObject *__pyx_v_bregion = NULL; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -54027,23 +62768,19 @@ static int __pyx_pf_5pysam_7libcbcf_11BCFIterator___init__(struct __pyx_obj_5pys PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - char *__pyx_t_7; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - int __pyx_t_11; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; PyObject *__pyx_t_12 = NULL; - int __pyx_t_13; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 3224, 0, __PYX_ERR(0, 3224, __pyx_L1_error)); - __Pyx_INCREF((PyObject *)__pyx_v_bcf); - __Pyx_INCREF(__pyx_v_start); - __Pyx_INCREF(__pyx_v_stop); + __Pyx_TraceCall("__init__", __pyx_f[0], 3748, 0, __PYX_ERR(0, 3748, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3225 + /* "pysam/libcbcf.pyx":3749 * cdef class BCFIterator(BaseIterator): - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): * if bcf is None: # <<<<<<<<<<<<<< * raise ValueError('bcf must not be None') * @@ -54052,574 +62789,512 @@ static int __pyx_pf_5pysam_7libcbcf_11BCFIterator___init__(struct __pyx_obj_5pys __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":3226 - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): + /* "pysam/libcbcf.pyx":3750 + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): * if bcf is None: * raise ValueError('bcf must not be None') # <<<<<<<<<<<<<< * - * if not isinstance(bcf.index, BCFIndex): - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__182, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 3226, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":3225 - * cdef class BCFIterator(BaseIterator): - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): - * if bcf is None: # <<<<<<<<<<<<<< - * raise ValueError('bcf must not be None') - * - */ - } - - /* "pysam/libcbcf.pyx":3228 - * raise ValueError('bcf must not be None') - * - * if not isinstance(bcf.index, BCFIndex): # <<<<<<<<<<<<<< - * raise ValueError('bcf index required') - * - */ - __pyx_t_3 = ((PyObject *)__pyx_v_bcf->index); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_t_3, __pyx_ptype_5pysam_7libcbcf_BCFIndex); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = ((!(__pyx_t_2 != 0)) != 0); - if (unlikely(__pyx_t_1)) { - - /* "pysam/libcbcf.pyx":3229 - * - * if not isinstance(bcf.index, BCFIndex): - * raise ValueError('bcf index required') # <<<<<<<<<<<<<< - * - * cdef BCFIndex index = bcf.index - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__183, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3229, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 3229, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":3228 - * raise ValueError('bcf must not be None') - * - * if not isinstance(bcf.index, BCFIndex): # <<<<<<<<<<<<<< - * raise ValueError('bcf index required') - * - */ - } - - /* "pysam/libcbcf.pyx":3231 - * raise ValueError('bcf index required') - * - * cdef BCFIndex index = bcf.index # <<<<<<<<<<<<<< - * cdef int rid, cstart, cstop - * cdef char *cregion - */ - if (!(likely(((((PyObject *)__pyx_v_bcf->index)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_bcf->index), __pyx_ptype_5pysam_7libcbcf_BCFIndex))))) __PYX_ERR(0, 3231, __pyx_L1_error) - __pyx_t_3 = ((PyObject *)__pyx_v_bcf->index); - __Pyx_INCREF(__pyx_t_3); - __pyx_v_index = ((struct __pyx_obj_5pysam_7libcbcf_BCFIndex *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pysam/libcbcf.pyx":3235 - * cdef char *cregion - * - * if not index: # <<<<<<<<<<<<<< - * raise ValueError('bcf index required') - * - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_index)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 3235, __pyx_L1_error) - __pyx_t_2 = ((!__pyx_t_1) != 0); - if (unlikely(__pyx_t_2)) { - - /* "pysam/libcbcf.pyx":3236 - * - * if not index: - * raise ValueError('bcf index required') # <<<<<<<<<<<<<< - * - * if reopen: + * if contig is None: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__184, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3236, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__192, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3750, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 3236, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":3235 - * cdef char *cregion - * - * if not index: # <<<<<<<<<<<<<< - * raise ValueError('bcf index required') - * - */ - } - - /* "pysam/libcbcf.pyx":3238 - * raise ValueError('bcf index required') - * - * if reopen: # <<<<<<<<<<<<<< - * bcf = bcf.copy() - * - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reopen); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3238, __pyx_L1_error) - if (__pyx_t_2) { - - /* "pysam/libcbcf.pyx":3239 - * - * if reopen: - * bcf = bcf.copy() # <<<<<<<<<<<<<< - * - * if region is not None: - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_bcf), __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3239, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else { - __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3239, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5pysam_7libcbcf_VariantFile))))) __PYX_ERR(0, 3239, __pyx_L1_error) - __Pyx_DECREF_SET(__pyx_v_bcf, ((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_t_3)); - __pyx_t_3 = 0; + __PYX_ERR(0, 3750, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3238 - * raise ValueError('bcf index required') - * - * if reopen: # <<<<<<<<<<<<<< - * bcf = bcf.copy() + /* "pysam/libcbcf.pyx":3749 + * cdef class BCFIterator(BaseIterator): + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): + * if bcf is None: # <<<<<<<<<<<<<< + * raise ValueError('bcf must not be None') * */ } - /* "pysam/libcbcf.pyx":3241 - * bcf = bcf.copy() + /* "pysam/libcbcf.pyx":3752 + * raise ValueError('bcf must not be None') + * + * if contig is None: # <<<<<<<<<<<<<< + * raise ValueError('contig must be specified') * - * if region is not None: # <<<<<<<<<<<<<< - * if contig is not None or start is not None or stop is not None: - * raise ValueError # FIXME */ - __pyx_t_2 = (__pyx_v_region != Py_None); + __pyx_t_2 = (__pyx_v_contig == Py_None); __pyx_t_1 = (__pyx_t_2 != 0); - if (__pyx_t_1) { + if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3242 + /* "pysam/libcbcf.pyx":3753 * - * if region is not None: - * if contig is not None or start is not None or stop is not None: # <<<<<<<<<<<<<< - * raise ValueError # FIXME + * if contig is None: + * raise ValueError('contig must be specified') # <<<<<<<<<<<<<< * + * if not isinstance(bcf.index, BCFIndex): */ - __pyx_t_2 = (__pyx_v_contig != Py_None); - __pyx_t_6 = (__pyx_t_2 != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_1 = __pyx_t_6; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_6 = (__pyx_v_start != Py_None); - __pyx_t_2 = (__pyx_t_6 != 0); - if (!__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L9_bool_binop_done; - } - __pyx_t_2 = (__pyx_v_stop != Py_None); - __pyx_t_6 = (__pyx_t_2 != 0); - __pyx_t_1 = __pyx_t_6; - __pyx_L9_bool_binop_done:; - if (unlikely(__pyx_t_1)) { + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__193, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3753, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 3753, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3243 - * if region is not None: - * if contig is not None or start is not None or stop is not None: - * raise ValueError # FIXME # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3752 + * raise ValueError('bcf must not be None') + * + * if contig is None: # <<<<<<<<<<<<<< + * raise ValueError('contig must be specified') * - * bregion = force_bytes(region) */ - __Pyx_Raise(__pyx_builtin_ValueError, 0, 0, 0); - __PYX_ERR(0, 3243, __pyx_L1_error) + } - /* "pysam/libcbcf.pyx":3242 + /* "pysam/libcbcf.pyx":3755 + * raise ValueError('contig must be specified') * - * if region is not None: - * if contig is not None or start is not None or stop is not None: # <<<<<<<<<<<<<< - * raise ValueError # FIXME + * if not isinstance(bcf.index, BCFIndex): # <<<<<<<<<<<<<< + * raise ValueError('bcf index required') * */ - } + __pyx_t_3 = ((PyObject *)__pyx_v_bcf->index); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_1 = __Pyx_TypeCheck(__pyx_t_3, __pyx_ptype_5pysam_7libcbcf_BCFIndex); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":3245 - * raise ValueError # FIXME + /* "pysam/libcbcf.pyx":3756 * - * bregion = force_bytes(region) # <<<<<<<<<<<<<< - * cregion = bregion - * with nogil: + * if not isinstance(bcf.index, BCFIndex): + * raise ValueError('bcf index required') # <<<<<<<<<<<<<< + * + * cdef BCFIndex index = bcf.index */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_region, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3245, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__194, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3756, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_v_bregion = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 3756, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3246 + /* "pysam/libcbcf.pyx":3755 + * raise ValueError('contig must be specified') * - * bregion = force_bytes(region) - * cregion = bregion # <<<<<<<<<<<<<< - * with nogil: - * self.iter = bcf_itr_querys(index.ptr, bcf.header.ptr, cregion) - */ - if (unlikely(__pyx_v_bregion == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 3246, __pyx_L1_error) - } - __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_bregion); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 3246, __pyx_L1_error) - __pyx_v_cregion = __pyx_t_7; - - /* "pysam/libcbcf.pyx":3247 - * bregion = force_bytes(region) - * cregion = bregion - * with nogil: # <<<<<<<<<<<<<< - * self.iter = bcf_itr_querys(index.ptr, bcf.header.ptr, cregion) - * else: - */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { - - /* "pysam/libcbcf.pyx":3248 - * cregion = bregion - * with nogil: - * self.iter = bcf_itr_querys(index.ptr, bcf.header.ptr, cregion) # <<<<<<<<<<<<<< - * else: - * if contig is None: - */ - __pyx_v_self->__pyx_base.iter = bcf_itr_querys(__pyx_v_index->ptr, __pyx_v_bcf->header->ptr, __pyx_v_cregion); - } - - /* "pysam/libcbcf.pyx":3247 - * bregion = force_bytes(region) - * cregion = bregion - * with nogil: # <<<<<<<<<<<<<< - * self.iter = bcf_itr_querys(index.ptr, bcf.header.ptr, cregion) - * else: - */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L14; - } - __pyx_L14:; - } - } - - /* "pysam/libcbcf.pyx":3241 - * bcf = bcf.copy() + * if not isinstance(bcf.index, BCFIndex): # <<<<<<<<<<<<<< + * raise ValueError('bcf index required') * - * if region is not None: # <<<<<<<<<<<<<< - * if contig is not None or start is not None or stop is not None: - * raise ValueError # FIXME */ - goto __pyx_L7; } - /* "pysam/libcbcf.pyx":3250 - * self.iter = bcf_itr_querys(index.ptr, bcf.header.ptr, cregion) - * else: - * if contig is None: # <<<<<<<<<<<<<< - * raise ValueError # FIXME + /* "pysam/libcbcf.pyx":3758 + * raise ValueError('bcf index required') * - */ - /*else*/ { - __pyx_t_1 = (__pyx_v_contig == Py_None); - __pyx_t_6 = (__pyx_t_1 != 0); - if (unlikely(__pyx_t_6)) { - - /* "pysam/libcbcf.pyx":3251 - * else: - * if contig is None: - * raise ValueError # FIXME # <<<<<<<<<<<<<< + * cdef BCFIndex index = bcf.index # <<<<<<<<<<<<<< * - * try: + * self.bcf = bcf */ - __Pyx_Raise(__pyx_builtin_ValueError, 0, 0, 0); - __PYX_ERR(0, 3251, __pyx_L1_error) + if (!(likely(((((PyObject *)__pyx_v_bcf->index)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_bcf->index), __pyx_ptype_5pysam_7libcbcf_BCFIndex))))) __PYX_ERR(0, 3758, __pyx_L1_error) + __pyx_t_3 = ((PyObject *)__pyx_v_bcf->index); + __Pyx_INCREF(__pyx_t_3); + __pyx_v_index = ((struct __pyx_obj_5pysam_7libcbcf_BCFIndex *)__pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":3250 - * self.iter = bcf_itr_querys(index.ptr, bcf.header.ptr, cregion) - * else: - * if contig is None: # <<<<<<<<<<<<<< - * raise ValueError # FIXME + /* "pysam/libcbcf.pyx":3760 + * cdef BCFIndex index = bcf.index + * + * self.bcf = bcf # <<<<<<<<<<<<<< + * self.index = index * */ - } + __Pyx_INCREF(((PyObject *)__pyx_v_bcf)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_bcf)); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.bcf); + __Pyx_DECREF(((PyObject *)__pyx_v_self->__pyx_base.bcf)); + __pyx_v_self->__pyx_base.bcf = __pyx_v_bcf; - /* "pysam/libcbcf.pyx":3253 - * raise ValueError # FIXME + /* "pysam/libcbcf.pyx":3761 * - * try: # <<<<<<<<<<<<<< - * rid = index.refmap[contig] - * except KeyError: + * self.bcf = bcf + * self.index = index # <<<<<<<<<<<<<< + * + * cdef int rid, cstart, cstop */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10); - __Pyx_XGOTREF(__pyx_t_8); - __Pyx_XGOTREF(__pyx_t_9); - __Pyx_XGOTREF(__pyx_t_10); - /*try:*/ { + __Pyx_INCREF(((PyObject *)__pyx_v_index)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_index)); + __Pyx_GOTREF(__pyx_v_self->index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->index)); + __pyx_v_self->index = __pyx_v_index; - /* "pysam/libcbcf.pyx":3254 + /* "pysam/libcbcf.pyx":3765 + * cdef int rid, cstart, cstop * - * try: - * rid = index.refmap[contig] # <<<<<<<<<<<<<< - * except KeyError: - * raise ValueError('Unknown contig specified') + * try: # <<<<<<<<<<<<<< + * rid = index.refmap[contig] + * except KeyError: */ - if (unlikely(__pyx_v_index->__pyx_base.refmap == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 3254, __pyx_L16_error) - } - __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_index->__pyx_base.refmap, __pyx_v_contig); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3254, __pyx_L16_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3254, __pyx_L16_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_rid = __pyx_t_11; + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + /*try:*/ { - /* "pysam/libcbcf.pyx":3253 - * raise ValueError # FIXME + /* "pysam/libcbcf.pyx":3766 * - * try: # <<<<<<<<<<<<<< - * rid = index.refmap[contig] - * except KeyError: + * try: + * rid = index.refmap[contig] # <<<<<<<<<<<<<< + * except KeyError: + * # A query for a non-existant contig yields an empty iterator, does not raise an error */ + if (unlikely(__pyx_v_index->__pyx_base.refmap == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 3766, __pyx_L6_error) } - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - goto __pyx_L21_try_end; - __pyx_L16_error:; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_index->__pyx_base.refmap, __pyx_v_contig); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3766, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3766, __pyx_L6_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_rid = __pyx_t_7; - /* "pysam/libcbcf.pyx":3255 - * try: - * rid = index.refmap[contig] - * except KeyError: # <<<<<<<<<<<<<< - * raise ValueError('Unknown contig specified') + /* "pysam/libcbcf.pyx":3765 + * cdef int rid, cstart, cstop * + * try: # <<<<<<<<<<<<<< + * rid = index.refmap[contig] + * except KeyError: */ - __pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); - if (__pyx_t_11) { - __Pyx_AddTraceback("pysam.libcbcf.BCFIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 3255, __pyx_L18_except_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L11_try_end; + __pyx_L6_error:; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":3767 + * try: + * rid = index.refmap[contig] + * except KeyError: # <<<<<<<<<<<<<< + * # A query for a non-existant contig yields an empty iterator, does not raise an error + * self.iter = NULL + */ + __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); + if (__pyx_t_7) { + __Pyx_AddTraceback("pysam.libcbcf.BCFIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_8, &__pyx_t_9) < 0) __PYX_ERR(0, 3767, __pyx_L8_except_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_9); - /* "pysam/libcbcf.pyx":3256 - * rid = index.refmap[contig] - * except KeyError: - * raise ValueError('Unknown contig specified') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3769 + * except KeyError: + * # A query for a non-existant contig yields an empty iterator, does not raise an error + * self.iter = NULL # <<<<<<<<<<<<<< + * return * - * if start is None: */ - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__185, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 3256, __pyx_L18_except_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_Raise(__pyx_t_12, 0, 0, 0); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __PYX_ERR(0, 3256, __pyx_L18_except_error) - } - goto __pyx_L18_except_error; - __pyx_L18_except_error:; + __pyx_v_self->__pyx_base.iter = NULL; - /* "pysam/libcbcf.pyx":3253 - * raise ValueError # FIXME + /* "pysam/libcbcf.pyx":3770 + * # A query for a non-existant contig yields an empty iterator, does not raise an error + * self.iter = NULL + * return # <<<<<<<<<<<<<< * - * try: # <<<<<<<<<<<<<< - * rid = index.refmap[contig] - * except KeyError: + * if reopen: */ - __Pyx_XGIVEREF(__pyx_t_8); - __Pyx_XGIVEREF(__pyx_t_9); - __Pyx_XGIVEREF(__pyx_t_10); - __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); - goto __pyx_L1_error; - __pyx_L21_try_end:; + __pyx_r = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L9_except_return; } + goto __pyx_L8_except_error; + __pyx_L8_except_error:; - /* "pysam/libcbcf.pyx":3258 - * raise ValueError('Unknown contig specified') + /* "pysam/libcbcf.pyx":3765 + * cdef int rid, cstart, cstop * - * if start is None: # <<<<<<<<<<<<<< - * start = 0 - * if stop is None: + * try: # <<<<<<<<<<<<<< + * rid = index.refmap[contig] + * except KeyError: */ - __pyx_t_6 = (__pyx_v_start == Py_None); - __pyx_t_1 = (__pyx_t_6 != 0); - if (__pyx_t_1) { + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); + goto __pyx_L1_error; + __pyx_L9_except_return:; + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); + goto __pyx_L0; + __pyx_L11_try_end:; + } - /* "pysam/libcbcf.pyx":3259 + /* "pysam/libcbcf.pyx":3772 + * return + * + * if reopen: # <<<<<<<<<<<<<< + * self.bcf = self.bcf.copy() * - * if start is None: - * start = 0 # <<<<<<<<<<<<<< - * if stop is None: - * stop = MAX_POS */ - __Pyx_INCREF(__pyx_int_0); - __Pyx_DECREF_SET(__pyx_v_start, __pyx_int_0); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reopen); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3772, __pyx_L1_error) + if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":3258 - * raise ValueError('Unknown contig specified') + /* "pysam/libcbcf.pyx":3773 * - * if start is None: # <<<<<<<<<<<<<< - * start = 0 - * if stop is None: + * if reopen: + * self.bcf = self.bcf.copy() # <<<<<<<<<<<<<< + * + * cstart = start if start is not None else 0 */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.bcf), __pyx_n_s_copy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3773, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + if (__pyx_t_3) { + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3773, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_9 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3773, __pyx_L1_error) } + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (!(likely(((__pyx_t_9) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_9, __pyx_ptype_5pysam_7libcbcf_VariantFile))))) __PYX_ERR(0, 3773, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_9); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.bcf); + __Pyx_DECREF(((PyObject *)__pyx_v_self->__pyx_base.bcf)); + __pyx_v_self->__pyx_base.bcf = ((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_t_9); + __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":3260 - * if start is None: - * start = 0 - * if stop is None: # <<<<<<<<<<<<<< - * stop = MAX_POS + /* "pysam/libcbcf.pyx":3772 + * return * - */ - __pyx_t_1 = (__pyx_v_stop == Py_None); - __pyx_t_6 = (__pyx_t_1 != 0); - if (__pyx_t_6) { - - /* "pysam/libcbcf.pyx":3261 - * start = 0 - * if stop is None: - * stop = MAX_POS # <<<<<<<<<<<<<< + * if reopen: # <<<<<<<<<<<<<< + * self.bcf = self.bcf.copy() * - * cstart, cstop = start, stop */ - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_5pysam_7libcbcf_MAX_POS); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3261, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF_SET(__pyx_v_stop, __pyx_t_5); - __pyx_t_5 = 0; + } - /* "pysam/libcbcf.pyx":3260 - * if start is None: - * start = 0 - * if stop is None: # <<<<<<<<<<<<<< - * stop = MAX_POS + /* "pysam/libcbcf.pyx":3775 + * self.bcf = self.bcf.copy() + * + * cstart = start if start is not None else 0 # <<<<<<<<<<<<<< + * cstop = stop if stop is not None else MAX_POS * */ - } + __pyx_t_2 = (__pyx_v_start != Py_None); + if ((__pyx_t_2 != 0)) { + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_start); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3775, __pyx_L1_error) + __pyx_t_7 = __pyx_t_10; + } else { + __pyx_t_7 = 0; + } + __pyx_v_cstart = __pyx_t_7; - /* "pysam/libcbcf.pyx":3263 - * stop = MAX_POS + /* "pysam/libcbcf.pyx":3776 * - * cstart, cstop = start, stop # <<<<<<<<<<<<<< + * cstart = start if start is not None else 0 + * cstop = stop if stop is not None else MAX_POS # <<<<<<<<<<<<<< * - * with nogil: + * with nogil: */ - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_v_start); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3263, __pyx_L1_error) - __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_v_stop); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3263, __pyx_L1_error) - __pyx_v_cstart = __pyx_t_11; - __pyx_v_cstop = __pyx_t_13; + __pyx_t_2 = (__pyx_v_stop != Py_None); + if ((__pyx_t_2 != 0)) { + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_stop); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3776, __pyx_L1_error) + __pyx_t_7 = __pyx_t_10; + } else { + __pyx_t_7 = __pyx_v_5pysam_7libcbcf_MAX_POS; + } + __pyx_v_cstop = __pyx_t_7; - /* "pysam/libcbcf.pyx":3265 - * cstart, cstop = start, stop + /* "pysam/libcbcf.pyx":3778 + * cstop = stop if stop is not None else MAX_POS * - * with nogil: # <<<<<<<<<<<<<< - * self.iter = bcf_itr_queryi(index.ptr, rid, cstart, cstop) + * with nogil: # <<<<<<<<<<<<<< + * self.iter = bcf_itr_queryi(index.ptr, rid, cstart, cstop) * */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libcbcf.pyx":3266 + /* "pysam/libcbcf.pyx":3779 * - * with nogil: - * self.iter = bcf_itr_queryi(index.ptr, rid, cstart, cstop) # <<<<<<<<<<<<<< + * with nogil: + * self.iter = bcf_itr_queryi(index.ptr, rid, cstart, cstop) # <<<<<<<<<<<<<< * - * # Do not fail on self.iter == NULL, since it signifies a null query. + * if not self.iter: */ - __pyx_v_self->__pyx_base.iter = bcf_itr_queryi(__pyx_v_index->ptr, __pyx_v_rid, __pyx_v_cstart, __pyx_v_cstop); - } + __pyx_v_self->__pyx_base.iter = bcf_itr_queryi(__pyx_v_index->ptr, __pyx_v_rid, __pyx_v_cstart, __pyx_v_cstop); + } - /* "pysam/libcbcf.pyx":3265 - * cstart, cstop = start, stop + /* "pysam/libcbcf.pyx":3778 + * cstop = stop if stop is not None else MAX_POS * - * with nogil: # <<<<<<<<<<<<<< - * self.iter = bcf_itr_queryi(index.ptr, rid, cstart, cstop) + * with nogil: # <<<<<<<<<<<<<< + * self.iter = bcf_itr_queryi(index.ptr, rid, cstart, cstop) * */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L28; - } - __pyx_L28:; + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L17; } - } + __pyx_L17:; + } } - __pyx_L7:; - /* "pysam/libcbcf.pyx":3270 - * # Do not fail on self.iter == NULL, since it signifies a null query. + /* "pysam/libcbcf.pyx":3781 + * self.iter = bcf_itr_queryi(index.ptr, rid, cstart, cstop) * - * self.bcf = bcf # <<<<<<<<<<<<<< - * self.index = index + * if not self.iter: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, strerror(errno)) + */ + __pyx_t_2 = ((!(__pyx_v_self->__pyx_base.iter != 0)) != 0); + if (__pyx_t_2) { + + /* "pysam/libcbcf.pyx":3782 * + * if not self.iter: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) + * else: */ - __Pyx_INCREF(((PyObject *)__pyx_v_bcf)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_bcf)); - __Pyx_GOTREF(__pyx_v_self->__pyx_base.bcf); - __Pyx_DECREF(((PyObject *)__pyx_v_self->__pyx_base.bcf)); - __pyx_v_self->__pyx_base.bcf = __pyx_v_bcf; + __pyx_t_2 = (errno != 0); + if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":3271 + /* "pysam/libcbcf.pyx":3783 + * if not self.iter: + * if errno: + * raise IOError(errno, strerror(errno)) # <<<<<<<<<<<<<< + * else: + * raise IOError('unable to fetch {}:{}-{}'.format(contig, start+1, stop)) + */ + __pyx_t_9 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3783, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3783, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3783, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8); + __pyx_t_9 = 0; + __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3783, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_8, 0, 0, 0); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __PYX_ERR(0, 3783, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3782 * - * self.bcf = bcf - * self.index = index # <<<<<<<<<<<<<< + * if not self.iter: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) + * else: + */ + } + + /* "pysam/libcbcf.pyx":3785 + * raise IOError(errno, strerror(errno)) + * else: + * raise IOError('unable to fetch {}:{}-{}'.format(contig, start+1, stop)) # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __Pyx_INCREF(((PyObject *)__pyx_v_index)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_index)); - __Pyx_GOTREF(__pyx_v_self->index); - __Pyx_DECREF(((PyObject *)__pyx_v_self->index)); - __pyx_v_self->index = __pyx_v_index; + /*else*/ { + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unable_to_fetch, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3785, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_v_start, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3785, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_11, __pyx_v_contig, __pyx_t_9, __pyx_v_stop}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3785, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_11, __pyx_v_contig, __pyx_t_9, __pyx_v_stop}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3785, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 3785, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; + } + __Pyx_INCREF(__pyx_v_contig); + __Pyx_GIVEREF(__pyx_v_contig); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_7, __pyx_v_contig); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_7, __pyx_t_9); + __Pyx_INCREF(__pyx_v_stop); + __Pyx_GIVEREF(__pyx_v_stop); + PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_7, __pyx_v_stop); + __pyx_t_9 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3785, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3785, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 3785, __pyx_L1_error) + } - /* "pysam/libcbcf.pyx":3224 + /* "pysam/libcbcf.pyx":3781 + * self.iter = bcf_itr_queryi(index.ptr, rid, cstart, cstop) + * + * if not self.iter: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, strerror(errno)) + */ + } + + /* "pysam/libcbcf.pyx":3748 * * cdef class BCFIterator(BaseIterator): - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): # <<<<<<<<<<<<<< + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): # <<<<<<<<<<<<<< * if bcf is None: * raise ValueError('bcf must not be None') */ @@ -54629,24 +63304,21 @@ static int __pyx_pf_5pysam_7libcbcf_11BCFIterator___init__(struct __pyx_obj_5pys goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_11); __Pyx_XDECREF(__pyx_t_12); __Pyx_AddTraceback("pysam.libcbcf.BCFIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_index); - __Pyx_XDECREF(__pyx_v_bregion); - __Pyx_XDECREF((PyObject *)__pyx_v_bcf); - __Pyx_XDECREF(__pyx_v_start); - __Pyx_XDECREF(__pyx_v_stop); __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":3273 - * self.index = index +/* "pysam/libcbcf.pyx":3787 + * raise IOError('unable to fetch {}:{}-{}'.format(contig, start+1, stop)) * * def __dealloc__(self): # <<<<<<<<<<<<<< * if self.iter: @@ -54669,9 +63341,9 @@ static void __pyx_pf_5pysam_7libcbcf_11BCFIterator_2__dealloc__(struct __pyx_obj __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 3273, 0, __PYX_ERR(0, 3273, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 3787, 0, __PYX_ERR(0, 3787, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3274 + /* "pysam/libcbcf.pyx":3788 * * def __dealloc__(self): * if self.iter: # <<<<<<<<<<<<<< @@ -54681,7 +63353,7 @@ static void __pyx_pf_5pysam_7libcbcf_11BCFIterator_2__dealloc__(struct __pyx_obj __pyx_t_1 = (__pyx_v_self->__pyx_base.iter != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3275 + /* "pysam/libcbcf.pyx":3789 * def __dealloc__(self): * if self.iter: * bcf_itr_destroy(self.iter) # <<<<<<<<<<<<<< @@ -54690,7 +63362,7 @@ static void __pyx_pf_5pysam_7libcbcf_11BCFIterator_2__dealloc__(struct __pyx_obj */ bcf_itr_destroy(__pyx_v_self->__pyx_base.iter); - /* "pysam/libcbcf.pyx":3276 + /* "pysam/libcbcf.pyx":3790 * if self.iter: * bcf_itr_destroy(self.iter) * self.iter = NULL # <<<<<<<<<<<<<< @@ -54699,7 +63371,7 @@ static void __pyx_pf_5pysam_7libcbcf_11BCFIterator_2__dealloc__(struct __pyx_obj */ __pyx_v_self->__pyx_base.iter = NULL; - /* "pysam/libcbcf.pyx":3274 + /* "pysam/libcbcf.pyx":3788 * * def __dealloc__(self): * if self.iter: # <<<<<<<<<<<<<< @@ -54708,8 +63380,8 @@ static void __pyx_pf_5pysam_7libcbcf_11BCFIterator_2__dealloc__(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":3273 - * self.index = index + /* "pysam/libcbcf.pyx":3787 + * raise IOError('unable to fetch {}:{}-{}'.format(contig, start+1, stop)) * * def __dealloc__(self): # <<<<<<<<<<<<<< * if self.iter: @@ -54725,7 +63397,7 @@ static void __pyx_pf_5pysam_7libcbcf_11BCFIterator_2__dealloc__(struct __pyx_obj __Pyx_RefNannyFinishContext(); } -/* "pysam/libcbcf.pyx":3278 +/* "pysam/libcbcf.pyx":3792 * self.iter = NULL * * def __iter__(self): # <<<<<<<<<<<<<< @@ -54751,9 +63423,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_4__iter__(struct __pyx_o __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 3278, 0, __PYX_ERR(0, 3278, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 3792, 0, __PYX_ERR(0, 3792, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3279 + /* "pysam/libcbcf.pyx":3793 * * def __iter__(self): * return self # <<<<<<<<<<<<<< @@ -54765,7 +63437,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_4__iter__(struct __pyx_o __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcbcf.pyx":3278 + /* "pysam/libcbcf.pyx":3792 * self.iter = NULL * * def __iter__(self): # <<<<<<<<<<<<<< @@ -54784,7 +63456,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_4__iter__(struct __pyx_o return __pyx_r; } -/* "pysam/libcbcf.pyx":3281 +/* "pysam/libcbcf.pyx":3795 * return self * * def __next__(self): # <<<<<<<<<<<<<< @@ -54814,10 +63486,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 3281, 0, __PYX_ERR(0, 3281, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 3795, 0, __PYX_ERR(0, 3795, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3282 + /* "pysam/libcbcf.pyx":3796 * * def __next__(self): * if not self.iter: # <<<<<<<<<<<<<< @@ -54827,7 +63500,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o __pyx_t_1 = ((!(__pyx_v_self->__pyx_base.iter != 0)) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3283 + /* "pysam/libcbcf.pyx":3797 * def __next__(self): * if not self.iter: * raise StopIteration # <<<<<<<<<<<<<< @@ -54835,9 +63508,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o * cdef bcf1_t *record = bcf_init1() */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 3283, __pyx_L1_error) + __PYX_ERR(0, 3797, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3282 + /* "pysam/libcbcf.pyx":3796 * * def __next__(self): * if not self.iter: # <<<<<<<<<<<<<< @@ -54846,25 +63519,57 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":3285 + /* "pysam/libcbcf.pyx":3799 * raise StopIteration * * cdef bcf1_t *record = bcf_init1() # <<<<<<<<<<<<<< * - * record.pos = -1 + * if not record: */ __pyx_v_record = bcf_init1(); - /* "pysam/libcbcf.pyx":3287 + /* "pysam/libcbcf.pyx":3801 + * cdef bcf1_t *record = bcf_init1() + * + * if not record: # <<<<<<<<<<<<<< + * raise MemoryError('unable to allocate BCF record') + * + */ + __pyx_t_1 = ((!(__pyx_v_record != 0)) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbcf.pyx":3802 + * + * if not record: + * raise MemoryError('unable to allocate BCF record') # <<<<<<<<<<<<<< + * + * record.pos = -1 + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__195, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3802, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 3802, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3801 * cdef bcf1_t *record = bcf_init1() * + * if not record: # <<<<<<<<<<<<<< + * raise MemoryError('unable to allocate BCF record') + * + */ + } + + /* "pysam/libcbcf.pyx":3804 + * raise MemoryError('unable to allocate BCF record') + * * record.pos = -1 # <<<<<<<<<<<<<< * if self.bcf.drop_samples: * record.max_unpack = BCF_UN_SHR */ __pyx_v_record->pos = -1; - /* "pysam/libcbcf.pyx":3288 + /* "pysam/libcbcf.pyx":3805 * * record.pos = -1 * if self.bcf.drop_samples: # <<<<<<<<<<<<<< @@ -54874,7 +63579,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o __pyx_t_1 = (__pyx_v_self->__pyx_base.bcf->drop_samples != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3289 + /* "pysam/libcbcf.pyx":3806 * record.pos = -1 * if self.bcf.drop_samples: * record.max_unpack = BCF_UN_SHR # <<<<<<<<<<<<<< @@ -54883,7 +63588,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o */ __pyx_v_record->max_unpack = BCF_UN_SHR; - /* "pysam/libcbcf.pyx":3288 + /* "pysam/libcbcf.pyx":3805 * * record.pos = -1 * if self.bcf.drop_samples: # <<<<<<<<<<<<<< @@ -54892,7 +63597,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":3293 + /* "pysam/libcbcf.pyx":3810 * cdef int ret * * with nogil: # <<<<<<<<<<<<<< @@ -54907,7 +63612,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o #endif /*try:*/ { - /* "pysam/libcbcf.pyx":3294 + /* "pysam/libcbcf.pyx":3811 * * with nogil: * ret = bcf_itr_next(self.bcf.htsfile, self.iter, record) # <<<<<<<<<<<<<< @@ -54917,7 +63622,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o __pyx_v_ret = bcf_itr_next(__pyx_v_self->__pyx_base.bcf->__pyx_base.htsfile, __pyx_v_self->__pyx_base.iter, __pyx_v_record); } - /* "pysam/libcbcf.pyx":3293 + /* "pysam/libcbcf.pyx":3810 * cdef int ret * * with nogil: # <<<<<<<<<<<<<< @@ -54930,13 +63635,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif - goto __pyx_L7; + goto __pyx_L8; } - __pyx_L7:; + __pyx_L8:; } } - /* "pysam/libcbcf.pyx":3296 + /* "pysam/libcbcf.pyx":3813 * ret = bcf_itr_next(self.bcf.htsfile, self.iter, record) * * if ret < 0: # <<<<<<<<<<<<<< @@ -54946,7 +63651,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o __pyx_t_1 = ((__pyx_v_ret < 0) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3297 + /* "pysam/libcbcf.pyx":3814 * * if ret < 0: * _stop_BCFIterator(self, record) # <<<<<<<<<<<<<< @@ -54955,51 +63660,128 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o */ __pyx_f_5pysam_7libcbcf__stop_BCFIterator(__pyx_v_self, __pyx_v_record); - /* "pysam/libcbcf.pyx":3298 + /* "pysam/libcbcf.pyx":3815 * if ret < 0: * _stop_BCFIterator(self, record) * if ret == -1: # <<<<<<<<<<<<<< * raise StopIteration - * else: + * elif ret == -2: */ __pyx_t_1 = ((__pyx_v_ret == -1L) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3299 + /* "pysam/libcbcf.pyx":3816 * _stop_BCFIterator(self, record) * if ret == -1: * raise StopIteration # <<<<<<<<<<<<<< - * else: - * raise ValueError('error reading BCF file') + * elif ret == -2: + * raise IOError('truncated file') */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 3299, __pyx_L1_error) + __PYX_ERR(0, 3816, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3298 + /* "pysam/libcbcf.pyx":3815 * if ret < 0: * _stop_BCFIterator(self, record) * if ret == -1: # <<<<<<<<<<<<<< * raise StopIteration - * else: + * elif ret == -2: */ } - /* "pysam/libcbcf.pyx":3301 + /* "pysam/libcbcf.pyx":3817 + * if ret == -1: + * raise StopIteration + * elif ret == -2: # <<<<<<<<<<<<<< + * raise IOError('truncated file') + * elif errno: + */ + __pyx_t_1 = ((__pyx_v_ret == -2L) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbcf.pyx":3818 + * raise StopIteration + * elif ret == -2: + * raise IOError('truncated file') # <<<<<<<<<<<<<< + * elif errno: + * raise IOError(errno, strerror(errno)) + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__196, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3818, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 3818, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3817 + * if ret == -1: * raise StopIteration + * elif ret == -2: # <<<<<<<<<<<<<< + * raise IOError('truncated file') + * elif errno: + */ + } + + /* "pysam/libcbcf.pyx":3819 + * elif ret == -2: + * raise IOError('truncated file') + * elif errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) + * else: + */ + __pyx_t_1 = (errno != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbcf.pyx":3820 + * raise IOError('truncated file') + * elif errno: + * raise IOError(errno, strerror(errno)) # <<<<<<<<<<<<<< + * else: + * raise IOError('unable to fetch next record') + */ + __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3820, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3820, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3820, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3820, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 3820, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3819 + * elif ret == -2: + * raise IOError('truncated file') + * elif errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) + * else: + */ + } + + /* "pysam/libcbcf.pyx":3822 + * raise IOError(errno, strerror(errno)) * else: - * raise ValueError('error reading BCF file') # <<<<<<<<<<<<<< + * raise IOError('unable to fetch next record') # <<<<<<<<<<<<<< * * ret = bcf_subset_format(self.bcf.header.ptr, record) */ /*else*/ { - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__186, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3301, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 3301, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__197, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3822, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 3822, __pyx_L1_error) } - /* "pysam/libcbcf.pyx":3296 + /* "pysam/libcbcf.pyx":3813 * ret = bcf_itr_next(self.bcf.htsfile, self.iter, record) * * if ret < 0: # <<<<<<<<<<<<<< @@ -55008,8 +63790,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":3303 - * raise ValueError('error reading BCF file') + /* "pysam/libcbcf.pyx":3824 + * raise IOError('unable to fetch next record') * * ret = bcf_subset_format(self.bcf.header.ptr, record) # <<<<<<<<<<<<<< * @@ -55017,7 +63799,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o */ __pyx_v_ret = bcf_subset_format(__pyx_v_self->__pyx_base.bcf->header->ptr, __pyx_v_record); - /* "pysam/libcbcf.pyx":3305 + /* "pysam/libcbcf.pyx":3826 * ret = bcf_subset_format(self.bcf.header.ptr, record) * * if ret < 0: # <<<<<<<<<<<<<< @@ -55027,7 +63809,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o __pyx_t_1 = ((__pyx_v_ret < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3306 + /* "pysam/libcbcf.pyx":3827 * * if ret < 0: * _stop_BCFIterator(self, record) # <<<<<<<<<<<<<< @@ -55036,20 +63818,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o */ __pyx_f_5pysam_7libcbcf__stop_BCFIterator(__pyx_v_self, __pyx_v_record); - /* "pysam/libcbcf.pyx":3307 + /* "pysam/libcbcf.pyx":3828 * if ret < 0: * _stop_BCFIterator(self, record) * raise ValueError('error in bcf_subset_format') # <<<<<<<<<<<<<< * * return makeVariantRecord(self.bcf.header, record) */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__187, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3307, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 3307, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__198, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3828, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 3828, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3305 + /* "pysam/libcbcf.pyx":3826 * ret = bcf_subset_format(self.bcf.header.ptr, record) * * if ret < 0: # <<<<<<<<<<<<<< @@ -55058,7 +63840,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":3309 + /* "pysam/libcbcf.pyx":3830 * raise ValueError('error in bcf_subset_format') * * return makeVariantRecord(self.bcf.header, record) # <<<<<<<<<<<<<< @@ -55066,16 +63848,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.bcf->header); - __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_2), __pyx_v_record)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3309, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_3 = ((PyObject *)__pyx_v_self->__pyx_base.bcf->header); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_3), __pyx_v_record)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3830, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3281 + /* "pysam/libcbcf.pyx":3795 * return self * * def __next__(self): # <<<<<<<<<<<<<< @@ -55087,6 +63869,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_6__next__(struct __pyx_o __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("pysam.libcbcf.BCFIterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -55122,7 +63905,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_8__reduce_cython__(CYTHO __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -55130,11 +63913,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_8__reduce_cython__(CYTHO * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iter cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__188, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__199, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + __PYX_ERR(2, 2, __pyx_L1_error) /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< @@ -55180,18 +63963,18 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_10__setstate_cython__(CY __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 3, 0, __PYX_ERR(2, 3, __pyx_L1_error)); /* "(tree fragment)":4 * raise TypeError("self.iter cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__189, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__200, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -55211,7 +63994,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11BCFIterator_10__setstate_cython__(CY return __pyx_r; } -/* "pysam/libcbcf.pyx":3313 +/* "pysam/libcbcf.pyx":3834 * * cdef class TabixIterator(BaseIterator): * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -55244,9 +64027,9 @@ static int __pyx_pf_5pysam_7libcbcf_13TabixIterator___cinit__(struct __pyx_obj_5 __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[0], 3313, 0, __PYX_ERR(0, 3313, __pyx_L1_error)); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 3834, 0, __PYX_ERR(0, 3834, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3314 + /* "pysam/libcbcf.pyx":3835 * cdef class TabixIterator(BaseIterator): * def __cinit__(self, *args, **kwargs): * self.line_buffer.l = 0 # <<<<<<<<<<<<<< @@ -55255,7 +64038,7 @@ static int __pyx_pf_5pysam_7libcbcf_13TabixIterator___cinit__(struct __pyx_obj_5 */ __pyx_v_self->line_buffer.l = 0; - /* "pysam/libcbcf.pyx":3315 + /* "pysam/libcbcf.pyx":3836 * def __cinit__(self, *args, **kwargs): * self.line_buffer.l = 0 * self.line_buffer.m = 0 # <<<<<<<<<<<<<< @@ -55264,16 +64047,16 @@ static int __pyx_pf_5pysam_7libcbcf_13TabixIterator___cinit__(struct __pyx_obj_5 */ __pyx_v_self->line_buffer.m = 0; - /* "pysam/libcbcf.pyx":3316 + /* "pysam/libcbcf.pyx":3837 * self.line_buffer.l = 0 * self.line_buffer.m = 0 * self.line_buffer.s = NULL # <<<<<<<<<<<<<< * - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): */ __pyx_v_self->line_buffer.s = NULL; - /* "pysam/libcbcf.pyx":3313 + /* "pysam/libcbcf.pyx":3834 * * cdef class TabixIterator(BaseIterator): * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -55293,10 +64076,10 @@ static int __pyx_pf_5pysam_7libcbcf_13TabixIterator___cinit__(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libcbcf.pyx":3318 +/* "pysam/libcbcf.pyx":3839 * self.line_buffer.s = NULL * - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): # <<<<<<<<<<<<<< + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): # <<<<<<<<<<<<<< * if bcf is None: * raise ValueError('bcf must not be None') */ @@ -55308,25 +64091,21 @@ static int __pyx_pw_5pysam_7libcbcf_13TabixIterator_3__init__(PyObject *__pyx_v_ PyObject *__pyx_v_contig = 0; PyObject *__pyx_v_start = 0; PyObject *__pyx_v_stop = 0; - PyObject *__pyx_v_region = 0; PyObject *__pyx_v_reopen = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_bcf,&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_reopen,0}; - PyObject* values[6] = {0,0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_bcf,&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_reopen,0}; + PyObject* values[5] = {0,0,0,0,0}; values[1] = ((PyObject *)Py_None); values[2] = ((PyObject *)Py_None); values[3] = ((PyObject *)Py_None); - values[4] = ((PyObject *)Py_None); - values[5] = ((PyObject *)Py_True); + values[4] = ((PyObject *)Py_True); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -55365,24 +64144,16 @@ static int __pyx_pw_5pysam_7libcbcf_13TabixIterator_3__init__(PyObject *__pyx_v_ } CYTHON_FALLTHROUGH; case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region); - if (value) { values[4] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 5: if (kw_args > 0) { PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reopen); - if (value) { values[5] = value; kw_args--; } + if (value) { values[4] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 3318, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 3839, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -55400,19 +64171,18 @@ static int __pyx_pw_5pysam_7libcbcf_13TabixIterator_3__init__(PyObject *__pyx_v_ __pyx_v_contig = values[1]; __pyx_v_start = values[2]; __pyx_v_stop = values[3]; - __pyx_v_region = values[4]; - __pyx_v_reopen = values[5]; + __pyx_v_reopen = values[4]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3318, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3839, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.TabixIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_bcf), __pyx_ptype_5pysam_7libcbcf_VariantFile, 1, "bcf", 0))) __PYX_ERR(0, 3318, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_7libcbcf_13TabixIterator_2__init__(((struct __pyx_obj_5pysam_7libcbcf_TabixIterator *)__pyx_v_self), __pyx_v_bcf, __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_reopen); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_bcf), __pyx_ptype_5pysam_7libcbcf_VariantFile, 1, "bcf", 0))) __PYX_ERR(0, 3839, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_7libcbcf_13TabixIterator_2__init__(((struct __pyx_obj_5pysam_7libcbcf_TabixIterator *)__pyx_v_self), __pyx_v_bcf, __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_reopen); /* function exit code */ goto __pyx_L0; @@ -55423,9 +64193,11 @@ static int __pyx_pw_5pysam_7libcbcf_13TabixIterator_3__init__(PyObject *__pyx_v_ return __pyx_r; } -static int __pyx_pf_5pysam_7libcbcf_13TabixIterator_2__init__(struct __pyx_obj_5pysam_7libcbcf_TabixIterator *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reopen) { +static int __pyx_pf_5pysam_7libcbcf_13TabixIterator_2__init__(struct __pyx_obj_5pysam_7libcbcf_TabixIterator *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_bcf, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_reopen) { struct __pyx_obj_5pysam_7libcbcf_TabixIndex *__pyx_v_index = 0; - PyObject *__pyx_v_rid = NULL; + int __pyx_v_rid; + CYTHON_UNUSED int __pyx_v_cstart; + CYTHON_UNUSED int __pyx_v_cstop; int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -55434,20 +64206,19 @@ static int __pyx_pf_5pysam_7libcbcf_13TabixIterator_2__init__(struct __pyx_obj_5 PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - char *__pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 3318, 0, __PYX_ERR(0, 3318, __pyx_L1_error)); - __Pyx_INCREF((PyObject *)__pyx_v_bcf); - __Pyx_INCREF(__pyx_v_start); - __Pyx_INCREF(__pyx_v_stop); + __Pyx_TraceCall("__init__", __pyx_f[0], 3839, 0, __PYX_ERR(0, 3839, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3319 + /* "pysam/libcbcf.pyx":3840 * - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): * if bcf is None: # <<<<<<<<<<<<<< * raise ValueError('bcf must not be None') * @@ -55456,29 +64227,29 @@ static int __pyx_pf_5pysam_7libcbcf_13TabixIterator_2__init__(struct __pyx_obj_5 __pyx_t_2 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":3320 - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): + /* "pysam/libcbcf.pyx":3841 + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): * if bcf is None: * raise ValueError('bcf must not be None') # <<<<<<<<<<<<<< * * if not isinstance(bcf.index, TabixIndex): */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__190, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3320, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__201, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3841, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 3320, __pyx_L1_error) + __PYX_ERR(0, 3841, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3319 + /* "pysam/libcbcf.pyx":3840 * - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): * if bcf is None: # <<<<<<<<<<<<<< * raise ValueError('bcf must not be None') * */ } - /* "pysam/libcbcf.pyx":3322 + /* "pysam/libcbcf.pyx":3843 * raise ValueError('bcf must not be None') * * if not isinstance(bcf.index, TabixIndex): # <<<<<<<<<<<<<< @@ -55492,20 +64263,20 @@ static int __pyx_pf_5pysam_7libcbcf_13TabixIterator_2__init__(struct __pyx_obj_5 __pyx_t_1 = ((!(__pyx_t_2 != 0)) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3323 + /* "pysam/libcbcf.pyx":3844 * * if not isinstance(bcf.index, TabixIndex): * raise ValueError('tabix index required') # <<<<<<<<<<<<<< * * cdef TabixIndex index = bcf.index */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__191, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3323, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__202, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3844, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 3323, __pyx_L1_error) + __PYX_ERR(0, 3844, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3322 + /* "pysam/libcbcf.pyx":3843 * raise ValueError('bcf must not be None') * * if not isinstance(bcf.index, TabixIndex): # <<<<<<<<<<<<<< @@ -55514,332 +64285,388 @@ static int __pyx_pf_5pysam_7libcbcf_13TabixIterator_2__init__(struct __pyx_obj_5 */ } - /* "pysam/libcbcf.pyx":3325 + /* "pysam/libcbcf.pyx":3846 * raise ValueError('tabix index required') * * cdef TabixIndex index = bcf.index # <<<<<<<<<<<<<< * - * if not index: + * self.bcf = bcf */ - if (!(likely(((((PyObject *)__pyx_v_bcf->index)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_bcf->index), __pyx_ptype_5pysam_7libcbcf_TabixIndex))))) __PYX_ERR(0, 3325, __pyx_L1_error) + if (!(likely(((((PyObject *)__pyx_v_bcf->index)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_bcf->index), __pyx_ptype_5pysam_7libcbcf_TabixIndex))))) __PYX_ERR(0, 3846, __pyx_L1_error) __pyx_t_3 = ((PyObject *)__pyx_v_bcf->index); __Pyx_INCREF(__pyx_t_3); __pyx_v_index = ((struct __pyx_obj_5pysam_7libcbcf_TabixIndex *)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbcf.pyx":3327 + /* "pysam/libcbcf.pyx":3848 * cdef TabixIndex index = bcf.index * - * if not index: # <<<<<<<<<<<<<< - * raise ValueError('bcf index required') + * self.bcf = bcf # <<<<<<<<<<<<<< + * self.index = index * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_index)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 3327, __pyx_L1_error) - __pyx_t_2 = ((!__pyx_t_1) != 0); - if (unlikely(__pyx_t_2)) { + __Pyx_INCREF(((PyObject *)__pyx_v_bcf)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_bcf)); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.bcf); + __Pyx_DECREF(((PyObject *)__pyx_v_self->__pyx_base.bcf)); + __pyx_v_self->__pyx_base.bcf = __pyx_v_bcf; - /* "pysam/libcbcf.pyx":3328 + /* "pysam/libcbcf.pyx":3849 * - * if not index: - * raise ValueError('bcf index required') # <<<<<<<<<<<<<< + * self.bcf = bcf + * self.index = index # <<<<<<<<<<<<<< * - * if reopen: + * cdef int rid, cstart, cstop */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__192, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3328, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 3328, __pyx_L1_error) + __Pyx_INCREF(((PyObject *)__pyx_v_index)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_index)); + __Pyx_GOTREF(__pyx_v_self->index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->index)); + __pyx_v_self->index = __pyx_v_index; - /* "pysam/libcbcf.pyx":3327 - * cdef TabixIndex index = bcf.index + /* "pysam/libcbcf.pyx":3853 + * cdef int rid, cstart, cstop * - * if not index: # <<<<<<<<<<<<<< - * raise ValueError('bcf index required') + * try: # <<<<<<<<<<<<<< + * rid = index.refmap[contig] + * except KeyError: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + /*try:*/ { + + /* "pysam/libcbcf.pyx":3854 * + * try: + * rid = index.refmap[contig] # <<<<<<<<<<<<<< + * except KeyError: + * # A query for a non-existant contig yields an empty iterator, does not raise an error */ - } + if (unlikely(__pyx_v_index->__pyx_base.refmap == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 3854, __pyx_L5_error) + } + __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_index->__pyx_base.refmap, __pyx_v_contig); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3854, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3854, __pyx_L5_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_rid = __pyx_t_7; - /* "pysam/libcbcf.pyx":3330 - * raise ValueError('bcf index required') + /* "pysam/libcbcf.pyx":3853 + * cdef int rid, cstart, cstop * - * if reopen: # <<<<<<<<<<<<<< - * bcf = bcf.copy() + * try: # <<<<<<<<<<<<<< + * rid = index.refmap[contig] + * except KeyError: + */ + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L10_try_end; + __pyx_L5_error:; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libcbcf.pyx":3855 + * try: + * rid = index.refmap[contig] + * except KeyError: # <<<<<<<<<<<<<< + * # A query for a non-existant contig yields an empty iterator, does not raise an error + * self.iter = NULL + */ + __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); + if (__pyx_t_7) { + __Pyx_AddTraceback("pysam.libcbcf.TabixIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_8, &__pyx_t_9) < 0) __PYX_ERR(0, 3855, __pyx_L7_except_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_9); + + /* "pysam/libcbcf.pyx":3857 + * except KeyError: + * # A query for a non-existant contig yields an empty iterator, does not raise an error + * self.iter = NULL # <<<<<<<<<<<<<< + * return * */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reopen); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3330, __pyx_L1_error) - if (__pyx_t_2) { + __pyx_v_self->__pyx_base.iter = NULL; - /* "pysam/libcbcf.pyx":3331 + /* "pysam/libcbcf.pyx":3858 + * # A query for a non-existant contig yields an empty iterator, does not raise an error + * self.iter = NULL + * return # <<<<<<<<<<<<<< * * if reopen: - * bcf = bcf.copy() # <<<<<<<<<<<<<< - * - * if region is not None: */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_bcf), __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3331, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3331, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else { - __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3331, __pyx_L1_error) + __pyx_r = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L8_except_return; } - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5pysam_7libcbcf_VariantFile))))) __PYX_ERR(0, 3331, __pyx_L1_error) - __Pyx_DECREF_SET(__pyx_v_bcf, ((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_t_3)); - __pyx_t_3 = 0; + goto __pyx_L7_except_error; + __pyx_L7_except_error:; - /* "pysam/libcbcf.pyx":3330 - * raise ValueError('bcf index required') - * - * if reopen: # <<<<<<<<<<<<<< - * bcf = bcf.copy() + /* "pysam/libcbcf.pyx":3853 + * cdef int rid, cstart, cstop * + * try: # <<<<<<<<<<<<<< + * rid = index.refmap[contig] + * except KeyError: */ + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); + goto __pyx_L1_error; + __pyx_L8_except_return:; + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); + goto __pyx_L0; + __pyx_L10_try_end:; } - /* "pysam/libcbcf.pyx":3333 - * bcf = bcf.copy() + /* "pysam/libcbcf.pyx":3860 + * return + * + * if reopen: # <<<<<<<<<<<<<< + * self.bcf = self.bcf.copy() * - * if region is not None: # <<<<<<<<<<<<<< - * if contig is not None or start is not None or stop is not None: - * raise ValueError # FIXME */ - __pyx_t_2 = (__pyx_v_region != Py_None); - __pyx_t_1 = (__pyx_t_2 != 0); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reopen); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 3860, __pyx_L1_error) if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3334 + /* "pysam/libcbcf.pyx":3861 * - * if region is not None: - * if contig is not None or start is not None or stop is not None: # <<<<<<<<<<<<<< - * raise ValueError # FIXME + * if reopen: + * self.bcf = self.bcf.copy() # <<<<<<<<<<<<<< * + * cstart = start if start is not None else 0 */ - __pyx_t_2 = (__pyx_v_contig != Py_None); - __pyx_t_6 = (__pyx_t_2 != 0); - if (!__pyx_t_6) { - } else { - __pyx_t_1 = __pyx_t_6; - goto __pyx_L9_bool_binop_done; + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.bcf), __pyx_n_s_copy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3861, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } } - __pyx_t_6 = (__pyx_v_start != Py_None); - __pyx_t_2 = (__pyx_t_6 != 0); - if (!__pyx_t_2) { + if (__pyx_t_3) { + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3861, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L9_bool_binop_done; + __pyx_t_9 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3861, __pyx_L1_error) } - __pyx_t_2 = (__pyx_v_stop != Py_None); - __pyx_t_6 = (__pyx_t_2 != 0); - __pyx_t_1 = __pyx_t_6; - __pyx_L9_bool_binop_done:; - if (unlikely(__pyx_t_1)) { - - /* "pysam/libcbcf.pyx":3335 - * if region is not None: - * if contig is not None or start is not None or stop is not None: - * raise ValueError # FIXME # <<<<<<<<<<<<<< - * - * self.iter = tbx_itr_querys(index.ptr, region) - */ - __Pyx_Raise(__pyx_builtin_ValueError, 0, 0, 0); - __PYX_ERR(0, 3335, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (!(likely(((__pyx_t_9) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_9, __pyx_ptype_5pysam_7libcbcf_VariantFile))))) __PYX_ERR(0, 3861, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_9); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.bcf); + __Pyx_DECREF(((PyObject *)__pyx_v_self->__pyx_base.bcf)); + __pyx_v_self->__pyx_base.bcf = ((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_t_9); + __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":3334 + /* "pysam/libcbcf.pyx":3860 + * return * - * if region is not None: - * if contig is not None or start is not None or stop is not None: # <<<<<<<<<<<<<< - * raise ValueError # FIXME + * if reopen: # <<<<<<<<<<<<<< + * self.bcf = self.bcf.copy() * */ - } + } - /* "pysam/libcbcf.pyx":3337 - * raise ValueError # FIXME + /* "pysam/libcbcf.pyx":3863 + * self.bcf = self.bcf.copy() * - * self.iter = tbx_itr_querys(index.ptr, region) # <<<<<<<<<<<<<< - * else: - * if contig is None: - */ - __pyx_t_7 = __Pyx_PyObject_AsWritableString(__pyx_v_region); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 3337, __pyx_L1_error) - __pyx_v_self->__pyx_base.iter = tbx_itr_querys(__pyx_v_index->ptr, __pyx_t_7); - - /* "pysam/libcbcf.pyx":3333 - * bcf = bcf.copy() + * cstart = start if start is not None else 0 # <<<<<<<<<<<<<< + * cstop = stop if stop is not None else MAX_POS * - * if region is not None: # <<<<<<<<<<<<<< - * if contig is not None or start is not None or stop is not None: - * raise ValueError # FIXME */ - goto __pyx_L7; + __pyx_t_1 = (__pyx_v_start != Py_None); + if ((__pyx_t_1 != 0)) { + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_start); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3863, __pyx_L1_error) + __pyx_t_7 = __pyx_t_10; + } else { + __pyx_t_7 = 0; } + __pyx_v_cstart = __pyx_t_7; - /* "pysam/libcbcf.pyx":3339 - * self.iter = tbx_itr_querys(index.ptr, region) - * else: - * if contig is None: # <<<<<<<<<<<<<< - * raise ValueError # FIXME - * - */ - /*else*/ { - __pyx_t_1 = (__pyx_v_contig == Py_None); - __pyx_t_6 = (__pyx_t_1 != 0); - if (unlikely(__pyx_t_6)) { - - /* "pysam/libcbcf.pyx":3340 - * else: - * if contig is None: - * raise ValueError # FIXME # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3864 * - * rid = index.refmap.get(contig, -1) - */ - __Pyx_Raise(__pyx_builtin_ValueError, 0, 0, 0); - __PYX_ERR(0, 3340, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":3339 - * self.iter = tbx_itr_querys(index.ptr, region) - * else: - * if contig is None: # <<<<<<<<<<<<<< - * raise ValueError # FIXME + * cstart = start if start is not None else 0 + * cstop = stop if stop is not None else MAX_POS # <<<<<<<<<<<<<< * + * self.iter = tbx_itr_queryi(index.ptr, rid, start, stop) */ - } + __pyx_t_1 = (__pyx_v_stop != Py_None); + if ((__pyx_t_1 != 0)) { + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_stop); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3864, __pyx_L1_error) + __pyx_t_7 = __pyx_t_10; + } else { + __pyx_t_7 = __pyx_v_5pysam_7libcbcf_MAX_POS; + } + __pyx_v_cstop = __pyx_t_7; - /* "pysam/libcbcf.pyx":3342 - * raise ValueError # FIXME + /* "pysam/libcbcf.pyx":3866 + * cstop = stop if stop is not None else MAX_POS * - * rid = index.refmap.get(contig, -1) # <<<<<<<<<<<<<< + * self.iter = tbx_itr_queryi(index.ptr, rid, start, stop) # <<<<<<<<<<<<<< * - * if start is None: + * if not self.iter: */ - if (unlikely(__pyx_v_index->__pyx_base.refmap == Py_None)) { - PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get"); - __PYX_ERR(0, 3342, __pyx_L1_error) - } - __pyx_t_3 = __Pyx_PyDict_GetItemDefault(__pyx_v_index->__pyx_base.refmap, __pyx_v_contig, __pyx_int_neg_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3342, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_rid = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_v_start); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3866, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_stop); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3866, __pyx_L1_error) + __pyx_v_self->__pyx_base.iter = tbx_itr_queryi(__pyx_v_index->ptr, __pyx_v_rid, __pyx_t_7, __pyx_t_10); - /* "pysam/libcbcf.pyx":3344 - * rid = index.refmap.get(contig, -1) + /* "pysam/libcbcf.pyx":3868 + * self.iter = tbx_itr_queryi(index.ptr, rid, start, stop) * - * if start is None: # <<<<<<<<<<<<<< - * start = 0 - * if stop is None: + * if not self.iter: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, strerror(errno)) */ - __pyx_t_6 = (__pyx_v_start == Py_None); - __pyx_t_1 = (__pyx_t_6 != 0); - if (__pyx_t_1) { + __pyx_t_1 = ((!(__pyx_v_self->__pyx_base.iter != 0)) != 0); + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3345 + /* "pysam/libcbcf.pyx":3869 * - * if start is None: - * start = 0 # <<<<<<<<<<<<<< - * if stop is None: - * stop = MAX_POS + * if not self.iter: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) + * else: */ - __Pyx_INCREF(__pyx_int_0); - __Pyx_DECREF_SET(__pyx_v_start, __pyx_int_0); + __pyx_t_1 = (errno != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3344 - * rid = index.refmap.get(contig, -1) - * - * if start is None: # <<<<<<<<<<<<<< - * start = 0 - * if stop is None: + /* "pysam/libcbcf.pyx":3870 + * if not self.iter: + * if errno: + * raise IOError(errno, strerror(errno)) # <<<<<<<<<<<<<< + * else: + * raise IOError('unable to fetch {}:{}-{}'.format(contig, start+1, stop)) */ - } + __pyx_t_9 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3870, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3870, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3870, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8); + __pyx_t_9 = 0; + __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3870, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_8, 0, 0, 0); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __PYX_ERR(0, 3870, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3346 - * if start is None: - * start = 0 - * if stop is None: # <<<<<<<<<<<<<< - * stop = MAX_POS + /* "pysam/libcbcf.pyx":3869 * + * if not self.iter: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) + * else: */ - __pyx_t_1 = (__pyx_v_stop == Py_None); - __pyx_t_6 = (__pyx_t_1 != 0); - if (__pyx_t_6) { + } - /* "pysam/libcbcf.pyx":3347 - * start = 0 - * if stop is None: - * stop = MAX_POS # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3872 + * raise IOError(errno, strerror(errno)) + * else: + * raise IOError('unable to fetch {}:{}-{}'.format(contig, start+1, stop)) # <<<<<<<<<<<<<< * - * self.iter = tbx_itr_queryi(index.ptr, rid, start, stop) + * def __dealloc__(self): */ - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_5pysam_7libcbcf_MAX_POS); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3347, __pyx_L1_error) + /*else*/ { + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unable_to_fetch, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3872, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF_SET(__pyx_v_stop, __pyx_t_3); - __pyx_t_3 = 0; - - /* "pysam/libcbcf.pyx":3346 - * if start is None: - * start = 0 - * if stop is None: # <<<<<<<<<<<<<< - * stop = MAX_POS - * - */ + __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_v_start, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3872, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_11, __pyx_v_contig, __pyx_t_9, __pyx_v_stop}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3872, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_11, __pyx_v_contig, __pyx_t_9, __pyx_v_stop}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3872, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 3872, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; + } + __Pyx_INCREF(__pyx_v_contig); + __Pyx_GIVEREF(__pyx_v_contig); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_10, __pyx_v_contig); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_10, __pyx_t_9); + __Pyx_INCREF(__pyx_v_stop); + __Pyx_GIVEREF(__pyx_v_stop); + PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_10, __pyx_v_stop); + __pyx_t_9 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3872, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3872, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 3872, __pyx_L1_error) } - /* "pysam/libcbcf.pyx":3349 - * stop = MAX_POS - * - * self.iter = tbx_itr_queryi(index.ptr, rid, start, stop) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":3868 + * self.iter = tbx_itr_queryi(index.ptr, rid, start, stop) * - * # Do not fail on self.iter == NULL, since it signifies a null query. + * if not self.iter: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, strerror(errno)) */ - __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_rid); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3349, __pyx_L1_error) - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_v_start); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3349, __pyx_L1_error) - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_stop); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3349, __pyx_L1_error) - __pyx_v_self->__pyx_base.iter = tbx_itr_queryi(__pyx_v_index->ptr, __pyx_t_8, __pyx_t_9, __pyx_t_10); } - __pyx_L7:; - - /* "pysam/libcbcf.pyx":3353 - * # Do not fail on self.iter == NULL, since it signifies a null query. - * - * self.bcf = bcf # <<<<<<<<<<<<<< - * self.index = index - * - */ - __Pyx_INCREF(((PyObject *)__pyx_v_bcf)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_bcf)); - __Pyx_GOTREF(__pyx_v_self->__pyx_base.bcf); - __Pyx_DECREF(((PyObject *)__pyx_v_self->__pyx_base.bcf)); - __pyx_v_self->__pyx_base.bcf = __pyx_v_bcf; - - /* "pysam/libcbcf.pyx":3354 - * - * self.bcf = bcf - * self.index = index # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __Pyx_INCREF(((PyObject *)__pyx_v_index)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_index)); - __Pyx_GOTREF(__pyx_v_self->index); - __Pyx_DECREF(((PyObject *)__pyx_v_self->index)); - __pyx_v_self->index = __pyx_v_index; - /* "pysam/libcbcf.pyx":3318 + /* "pysam/libcbcf.pyx":3839 * self.line_buffer.s = NULL * - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): # <<<<<<<<<<<<<< + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): # <<<<<<<<<<<<<< * if bcf is None: * raise ValueError('bcf must not be None') */ @@ -55849,23 +64676,21 @@ static int __pyx_pf_5pysam_7libcbcf_13TabixIterator_2__init__(struct __pyx_obj_5 goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); __Pyx_AddTraceback("pysam.libcbcf.TabixIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_index); - __Pyx_XDECREF(__pyx_v_rid); - __Pyx_XDECREF((PyObject *)__pyx_v_bcf); - __Pyx_XDECREF(__pyx_v_start); - __Pyx_XDECREF(__pyx_v_stop); __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":3356 - * self.index = index +/* "pysam/libcbcf.pyx":3874 + * raise IOError('unable to fetch {}:{}-{}'.format(contig, start+1, stop)) * * def __dealloc__(self): # <<<<<<<<<<<<<< * if self.iter: @@ -55888,9 +64713,9 @@ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_o __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 3356, 0, __PYX_ERR(0, 3356, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 3874, 0, __PYX_ERR(0, 3874, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3357 + /* "pysam/libcbcf.pyx":3875 * * def __dealloc__(self): * if self.iter: # <<<<<<<<<<<<<< @@ -55900,7 +64725,7 @@ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_o __pyx_t_1 = (__pyx_v_self->__pyx_base.iter != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3358 + /* "pysam/libcbcf.pyx":3876 * def __dealloc__(self): * if self.iter: * tbx_itr_destroy(self.iter) # <<<<<<<<<<<<<< @@ -55909,7 +64734,7 @@ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_o */ tbx_itr_destroy(__pyx_v_self->__pyx_base.iter); - /* "pysam/libcbcf.pyx":3359 + /* "pysam/libcbcf.pyx":3877 * if self.iter: * tbx_itr_destroy(self.iter) * self.iter = NULL # <<<<<<<<<<<<<< @@ -55918,7 +64743,7 @@ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_o */ __pyx_v_self->__pyx_base.iter = NULL; - /* "pysam/libcbcf.pyx":3357 + /* "pysam/libcbcf.pyx":3875 * * def __dealloc__(self): * if self.iter: # <<<<<<<<<<<<<< @@ -55927,7 +64752,7 @@ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":3361 + /* "pysam/libcbcf.pyx":3879 * self.iter = NULL * * if self.line_buffer.m: # <<<<<<<<<<<<<< @@ -55937,7 +64762,7 @@ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_o __pyx_t_1 = (__pyx_v_self->line_buffer.m != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3362 + /* "pysam/libcbcf.pyx":3880 * * if self.line_buffer.m: * free(self.line_buffer.s) # <<<<<<<<<<<<<< @@ -55946,7 +64771,7 @@ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_o */ free(__pyx_v_self->line_buffer.s); - /* "pysam/libcbcf.pyx":3361 + /* "pysam/libcbcf.pyx":3879 * self.iter = NULL * * if self.line_buffer.m: # <<<<<<<<<<<<<< @@ -55955,7 +64780,7 @@ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":3364 + /* "pysam/libcbcf.pyx":3882 * free(self.line_buffer.s) * * self.line_buffer.l = 0 # <<<<<<<<<<<<<< @@ -55964,7 +64789,7 @@ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_o */ __pyx_v_self->line_buffer.l = 0; - /* "pysam/libcbcf.pyx":3365 + /* "pysam/libcbcf.pyx":3883 * * self.line_buffer.l = 0 * self.line_buffer.m = 0 # <<<<<<<<<<<<<< @@ -55973,7 +64798,7 @@ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_o */ __pyx_v_self->line_buffer.m = 0; - /* "pysam/libcbcf.pyx":3366 + /* "pysam/libcbcf.pyx":3884 * self.line_buffer.l = 0 * self.line_buffer.m = 0 * self.line_buffer.s = NULL # <<<<<<<<<<<<<< @@ -55982,8 +64807,8 @@ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_o */ __pyx_v_self->line_buffer.s = NULL; - /* "pysam/libcbcf.pyx":3356 - * self.index = index + /* "pysam/libcbcf.pyx":3874 + * raise IOError('unable to fetch {}:{}-{}'.format(contig, start+1, stop)) * * def __dealloc__(self): # <<<<<<<<<<<<<< * if self.iter: @@ -55999,7 +64824,7 @@ static void __pyx_pf_5pysam_7libcbcf_13TabixIterator_4__dealloc__(struct __pyx_o __Pyx_RefNannyFinishContext(); } -/* "pysam/libcbcf.pyx":3368 +/* "pysam/libcbcf.pyx":3886 * self.line_buffer.s = NULL * * def __iter__(self): # <<<<<<<<<<<<<< @@ -56025,9 +64850,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_6__iter__(struct __pyx __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 3368, 0, __PYX_ERR(0, 3368, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 3886, 0, __PYX_ERR(0, 3886, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3369 + /* "pysam/libcbcf.pyx":3887 * * def __iter__(self): * return self # <<<<<<<<<<<<<< @@ -56039,7 +64864,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_6__iter__(struct __pyx __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcbcf.pyx":3368 + /* "pysam/libcbcf.pyx":3886 * self.line_buffer.s = NULL * * def __iter__(self): # <<<<<<<<<<<<<< @@ -56058,7 +64883,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_6__iter__(struct __pyx return __pyx_r; } -/* "pysam/libcbcf.pyx":3371 +/* "pysam/libcbcf.pyx":3889 * return self * * def __next__(self): # <<<<<<<<<<<<<< @@ -56088,10 +64913,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 3371, 0, __PYX_ERR(0, 3371, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 3889, 0, __PYX_ERR(0, 3889, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3372 + /* "pysam/libcbcf.pyx":3890 * * def __next__(self): * if not self.iter: # <<<<<<<<<<<<<< @@ -56101,7 +64927,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx __pyx_t_1 = ((!(__pyx_v_self->__pyx_base.iter != 0)) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3373 + /* "pysam/libcbcf.pyx":3891 * def __next__(self): * if not self.iter: * raise StopIteration # <<<<<<<<<<<<<< @@ -56109,9 +64935,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx * cdef int ret */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 3373, __pyx_L1_error) + __PYX_ERR(0, 3891, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3372 + /* "pysam/libcbcf.pyx":3890 * * def __next__(self): * if not self.iter: # <<<<<<<<<<<<<< @@ -56120,7 +64946,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx */ } - /* "pysam/libcbcf.pyx":3377 + /* "pysam/libcbcf.pyx":3895 * cdef int ret * * with nogil: # <<<<<<<<<<<<<< @@ -56135,7 +64961,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx #endif /*try:*/ { - /* "pysam/libcbcf.pyx":3378 + /* "pysam/libcbcf.pyx":3896 * * with nogil: * ret = tbx_itr_next(self.bcf.htsfile, self.index.ptr, self.iter, &self.line_buffer) # <<<<<<<<<<<<<< @@ -56145,7 +64971,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx __pyx_v_ret = tbx_itr_next(__pyx_v_self->__pyx_base.bcf->__pyx_base.htsfile, __pyx_v_self->index->ptr, __pyx_v_self->__pyx_base.iter, (&__pyx_v_self->line_buffer)); } - /* "pysam/libcbcf.pyx":3377 + /* "pysam/libcbcf.pyx":3895 * cdef int ret * * with nogil: # <<<<<<<<<<<<<< @@ -56164,7 +64990,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx } } - /* "pysam/libcbcf.pyx":3380 + /* "pysam/libcbcf.pyx":3898 * ret = tbx_itr_next(self.bcf.htsfile, self.index.ptr, self.iter, &self.line_buffer) * * if ret < 0: # <<<<<<<<<<<<<< @@ -56174,7 +65000,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx __pyx_t_1 = ((__pyx_v_ret < 0) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3381 + /* "pysam/libcbcf.pyx":3899 * * if ret < 0: * tbx_itr_destroy(self.iter) # <<<<<<<<<<<<<< @@ -56183,7 +65009,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx */ tbx_itr_destroy(__pyx_v_self->__pyx_base.iter); - /* "pysam/libcbcf.pyx":3382 + /* "pysam/libcbcf.pyx":3900 * if ret < 0: * tbx_itr_destroy(self.iter) * self.iter = NULL # <<<<<<<<<<<<<< @@ -56192,51 +65018,128 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx */ __pyx_v_self->__pyx_base.iter = NULL; - /* "pysam/libcbcf.pyx":3383 + /* "pysam/libcbcf.pyx":3901 * tbx_itr_destroy(self.iter) * self.iter = NULL * if ret == -1: # <<<<<<<<<<<<<< * raise StopIteration - * else: + * elif ret == -2: */ __pyx_t_1 = ((__pyx_v_ret == -1L) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3384 + /* "pysam/libcbcf.pyx":3902 * self.iter = NULL * if ret == -1: * raise StopIteration # <<<<<<<<<<<<<< - * else: - * raise ValueError('error reading indexed VCF file') + * elif ret == -2: + * raise IOError('truncated file') */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 3384, __pyx_L1_error) + __PYX_ERR(0, 3902, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3383 + /* "pysam/libcbcf.pyx":3901 * tbx_itr_destroy(self.iter) * self.iter = NULL * if ret == -1: # <<<<<<<<<<<<<< * raise StopIteration - * else: + * elif ret == -2: */ } - /* "pysam/libcbcf.pyx":3386 + /* "pysam/libcbcf.pyx":3903 + * if ret == -1: + * raise StopIteration + * elif ret == -2: # <<<<<<<<<<<<<< + * raise IOError('truncated file') + * elif errno: + */ + __pyx_t_1 = ((__pyx_v_ret == -2L) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbcf.pyx":3904 * raise StopIteration + * elif ret == -2: + * raise IOError('truncated file') # <<<<<<<<<<<<<< + * elif errno: + * raise IOError(errno, strerror(errno)) + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__203, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3904, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 3904, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3903 + * if ret == -1: + * raise StopIteration + * elif ret == -2: # <<<<<<<<<<<<<< + * raise IOError('truncated file') + * elif errno: + */ + } + + /* "pysam/libcbcf.pyx":3905 + * elif ret == -2: + * raise IOError('truncated file') + * elif errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) + * else: + */ + __pyx_t_1 = (errno != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbcf.pyx":3906 + * raise IOError('truncated file') + * elif errno: + * raise IOError(errno, strerror(errno)) # <<<<<<<<<<<<<< * else: - * raise ValueError('error reading indexed VCF file') # <<<<<<<<<<<<<< + * raise IOError('unable to fetch next record') + */ + __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3906, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3906, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3906, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3906, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 3906, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3905 + * elif ret == -2: + * raise IOError('truncated file') + * elif errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) + * else: + */ + } + + /* "pysam/libcbcf.pyx":3908 + * raise IOError(errno, strerror(errno)) + * else: + * raise IOError('unable to fetch next record') # <<<<<<<<<<<<<< * * cdef bcf1_t *record = bcf_init1() */ /*else*/ { - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__193, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 3386, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__204, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 3908, __pyx_L1_error) } - /* "pysam/libcbcf.pyx":3380 + /* "pysam/libcbcf.pyx":3898 * ret = tbx_itr_next(self.bcf.htsfile, self.index.ptr, self.iter, &self.line_buffer) * * if ret < 0: # <<<<<<<<<<<<<< @@ -56245,25 +65148,57 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx */ } - /* "pysam/libcbcf.pyx":3388 - * raise ValueError('error reading indexed VCF file') + /* "pysam/libcbcf.pyx":3910 + * raise IOError('unable to fetch next record') * * cdef bcf1_t *record = bcf_init1() # <<<<<<<<<<<<<< * - * record.pos = -1 + * if not record: */ __pyx_v_record = bcf_init1(); - /* "pysam/libcbcf.pyx":3390 + /* "pysam/libcbcf.pyx":3912 * cdef bcf1_t *record = bcf_init1() * + * if not record: # <<<<<<<<<<<<<< + * raise MemoryError('unable to allocate BCF record') + * + */ + __pyx_t_1 = ((!(__pyx_v_record != 0)) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbcf.pyx":3913 + * + * if not record: + * raise MemoryError('unable to allocate BCF record') # <<<<<<<<<<<<<< + * + * record.pos = -1 + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__205, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3913, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 3913, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":3912 + * cdef bcf1_t *record = bcf_init1() + * + * if not record: # <<<<<<<<<<<<<< + * raise MemoryError('unable to allocate BCF record') + * + */ + } + + /* "pysam/libcbcf.pyx":3915 + * raise MemoryError('unable to allocate BCF record') + * * record.pos = -1 # <<<<<<<<<<<<<< * if self.bcf.drop_samples: * record.max_unpack = BCF_UN_SHR */ __pyx_v_record->pos = -1; - /* "pysam/libcbcf.pyx":3391 + /* "pysam/libcbcf.pyx":3916 * * record.pos = -1 * if self.bcf.drop_samples: # <<<<<<<<<<<<<< @@ -56273,7 +65208,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx __pyx_t_1 = (__pyx_v_self->__pyx_base.bcf->drop_samples != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3392 + /* "pysam/libcbcf.pyx":3917 * record.pos = -1 * if self.bcf.drop_samples: * record.max_unpack = BCF_UN_SHR # <<<<<<<<<<<<<< @@ -56282,7 +65217,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx */ __pyx_v_record->max_unpack = BCF_UN_SHR; - /* "pysam/libcbcf.pyx":3391 + /* "pysam/libcbcf.pyx":3916 * * record.pos = -1 * if self.bcf.drop_samples: # <<<<<<<<<<<<<< @@ -56291,7 +65226,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx */ } - /* "pysam/libcbcf.pyx":3394 + /* "pysam/libcbcf.pyx":3919 * record.max_unpack = BCF_UN_SHR * * ret = vcf_parse1(&self.line_buffer, self.bcf.header.ptr, record) # <<<<<<<<<<<<<< @@ -56300,7 +65235,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx */ __pyx_v_ret = vcf_parse1((&__pyx_v_self->line_buffer), __pyx_v_self->__pyx_base.bcf->header->ptr, __pyx_v_record); - /* "pysam/libcbcf.pyx":3397 + /* "pysam/libcbcf.pyx":3922 * * # FIXME: stop iteration on parse failure? * if ret < 0: # <<<<<<<<<<<<<< @@ -56310,7 +65245,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx __pyx_t_1 = ((__pyx_v_ret < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3398 + /* "pysam/libcbcf.pyx":3923 * # FIXME: stop iteration on parse failure? * if ret < 0: * bcf_destroy1(record) # <<<<<<<<<<<<<< @@ -56319,20 +65254,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx */ bcf_destroy1(__pyx_v_record); - /* "pysam/libcbcf.pyx":3399 + /* "pysam/libcbcf.pyx":3924 * if ret < 0: * bcf_destroy1(record) * raise ValueError('error in vcf_parse') # <<<<<<<<<<<<<< * * return makeVariantRecord(self.bcf.header, record) */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__194, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 3399, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__206, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3924, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 3924, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3397 + /* "pysam/libcbcf.pyx":3922 * * # FIXME: stop iteration on parse failure? * if ret < 0: # <<<<<<<<<<<<<< @@ -56341,7 +65276,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx */ } - /* "pysam/libcbcf.pyx":3401 + /* "pysam/libcbcf.pyx":3926 * raise ValueError('error in vcf_parse') * * return makeVariantRecord(self.bcf.header, record) # <<<<<<<<<<<<<< @@ -56349,16 +65284,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.bcf->header); - __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_2), __pyx_v_record)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3401, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_3 = ((PyObject *)__pyx_v_self->__pyx_base.bcf->header); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_3), __pyx_v_record)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3926, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3371 + /* "pysam/libcbcf.pyx":3889 * return self * * def __next__(self): # <<<<<<<<<<<<<< @@ -56370,6 +65305,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_8__next__(struct __pyx __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("pysam.libcbcf.TabixIterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -56405,7 +65341,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_10__reduce_cython__(CY __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -56413,11 +65349,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_10__reduce_cython__(CY * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__195, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__207, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + __PYX_ERR(2, 2, __pyx_L1_error) /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< @@ -56463,18 +65399,18 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_12__setstate_cython__( __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 3, 0, __PYX_ERR(2, 3, __pyx_L1_error)); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__196, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__208, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -56494,7 +65430,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_13TabixIterator_12__setstate_cython__( return __pyx_r; } -/* "pysam/libcbcf.pyx":3463 +/* "pysam/libcbcf.pyx":3998 * * """ * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -56527,9 +65463,9 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile___cinit__(struct __pyx_obj_5py __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[0], 3463, 0, __PYX_ERR(0, 3463, __pyx_L1_error)); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 3998, 0, __PYX_ERR(0, 3998, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3464 + /* "pysam/libcbcf.pyx":3999 * """ * def __cinit__(self, *args, **kwargs): * self.htsfile = NULL # <<<<<<<<<<<<<< @@ -56538,7 +65474,7 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile___cinit__(struct __pyx_obj_5py */ __pyx_v_self->__pyx_base.htsfile = NULL; - /* "pysam/libcbcf.pyx":3463 + /* "pysam/libcbcf.pyx":3998 * * """ * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -56558,7 +65494,7 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile___cinit__(struct __pyx_obj_5py return __pyx_r; } -/* "pysam/libcbcf.pyx":3466 +/* "pysam/libcbcf.pyx":4001 * self.htsfile = NULL * * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -56599,9 +65535,9 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 3466, 0, __PYX_ERR(0, 3466, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 4001, 0, __PYX_ERR(0, 4001, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3467 + /* "pysam/libcbcf.pyx":4002 * * def __init__(self, *args, **kwargs): * self.header = None # <<<<<<<<<<<<<< @@ -56614,7 +65550,7 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); __pyx_v_self->header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)Py_None); - /* "pysam/libcbcf.pyx":3468 + /* "pysam/libcbcf.pyx":4003 * def __init__(self, *args, **kwargs): * self.header = None * self.index = None # <<<<<<<<<<<<<< @@ -56627,12 +65563,12 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py __Pyx_DECREF(((PyObject *)__pyx_v_self->index)); __pyx_v_self->index = ((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)Py_None); - /* "pysam/libcbcf.pyx":3469 + /* "pysam/libcbcf.pyx":4004 * self.header = None * self.index = None * self.filename = None # <<<<<<<<<<<<<< * self.mode = None - * self.index_filename = None + * self.threads = 1 */ __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); @@ -56640,12 +65576,12 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py __Pyx_DECREF(__pyx_v_self->__pyx_base.filename); __pyx_v_self->__pyx_base.filename = Py_None; - /* "pysam/libcbcf.pyx":3470 + /* "pysam/libcbcf.pyx":4005 * self.index = None * self.filename = None * self.mode = None # <<<<<<<<<<<<<< + * self.threads = 1 * self.index_filename = None - * self.is_stream = False */ __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); @@ -56653,9 +65589,22 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py __Pyx_DECREF(__pyx_v_self->__pyx_base.mode); __pyx_v_self->__pyx_base.mode = Py_None; - /* "pysam/libcbcf.pyx":3471 + /* "pysam/libcbcf.pyx":4006 * self.filename = None * self.mode = None + * self.threads = 1 # <<<<<<<<<<<<<< + * self.index_filename = None + * self.is_stream = False + */ + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.threads); + __Pyx_DECREF(__pyx_v_self->__pyx_base.threads); + __pyx_v_self->__pyx_base.threads = __pyx_int_1; + + /* "pysam/libcbcf.pyx":4007 + * self.mode = None + * self.threads = 1 * self.index_filename = None # <<<<<<<<<<<<<< * self.is_stream = False * self.is_remote = False @@ -56666,8 +65615,8 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py __Pyx_DECREF(__pyx_v_self->__pyx_base.index_filename); __pyx_v_self->__pyx_base.index_filename = Py_None; - /* "pysam/libcbcf.pyx":3472 - * self.mode = None + /* "pysam/libcbcf.pyx":4008 + * self.threads = 1 * self.index_filename = None * self.is_stream = False # <<<<<<<<<<<<<< * self.is_remote = False @@ -56675,7 +65624,7 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py */ __pyx_v_self->__pyx_base.is_stream = 0; - /* "pysam/libcbcf.pyx":3473 + /* "pysam/libcbcf.pyx":4009 * self.index_filename = None * self.is_stream = False * self.is_remote = False # <<<<<<<<<<<<<< @@ -56684,7 +65633,7 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py */ __pyx_v_self->__pyx_base.is_remote = 0; - /* "pysam/libcbcf.pyx":3474 + /* "pysam/libcbcf.pyx":4010 * self.is_stream = False * self.is_remote = False * self.is_reading = False # <<<<<<<<<<<<<< @@ -56693,7 +65642,7 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py */ __pyx_v_self->is_reading = 0; - /* "pysam/libcbcf.pyx":3475 + /* "pysam/libcbcf.pyx":4011 * self.is_remote = False * self.is_reading = False * self.drop_samples = False # <<<<<<<<<<<<<< @@ -56702,7 +65651,7 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py */ __pyx_v_self->drop_samples = 0; - /* "pysam/libcbcf.pyx":3476 + /* "pysam/libcbcf.pyx":4012 * self.is_reading = False * self.drop_samples = False * self.header_written = False # <<<<<<<<<<<<<< @@ -56711,7 +65660,7 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py */ __pyx_v_self->header_written = 0; - /* "pysam/libcbcf.pyx":3477 + /* "pysam/libcbcf.pyx":4013 * self.drop_samples = False * self.header_written = False * self.start_offset = -1 # <<<<<<<<<<<<<< @@ -56720,21 +65669,21 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py */ __pyx_v_self->__pyx_base.start_offset = -1L; - /* "pysam/libcbcf.pyx":3479 + /* "pysam/libcbcf.pyx":4015 * self.start_offset = -1 * * self.open(*args, **kwargs) # <<<<<<<<<<<<<< * - * def close(self): + * def __dealloc__(self): */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3479, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4015, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_v_args, __pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3479, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_v_args, __pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4015, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":3466 + /* "pysam/libcbcf.pyx":4001 * self.htsfile = NULL * * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -56756,29 +65705,305 @@ static int __pyx_pf_5pysam_7libcbcf_11VariantFile_2__init__(struct __pyx_obj_5py return __pyx_r; } -/* "pysam/libcbcf.pyx":3481 +/* "pysam/libcbcf.pyx":4017 + * self.open(*args, **kwargs) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * if not self.htsfile or not self.header: + * return + */ + +/* Python wrapper */ +static void __pyx_pw_5pysam_7libcbcf_11VariantFile_5__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5pysam_7libcbcf_11VariantFile_5__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5pysam_7libcbcf_11VariantFile_4__dealloc__(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +static void __pyx_pf_5pysam_7libcbcf_11VariantFile_4__dealloc__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { + int __pyx_v_ret; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannySetupContext("__dealloc__", 0); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 4017, 0, __PYX_ERR(0, 4017, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":4018 + * + * def __dealloc__(self): + * if not self.htsfile or not self.header: # <<<<<<<<<<<<<< + * return + * + */ + __pyx_t_2 = ((!(__pyx_v_self->__pyx_base.htsfile != 0)) != 0); + if (!__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 4018, __pyx_L1_error) + __pyx_t_3 = ((!__pyx_t_2) != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":4019 + * def __dealloc__(self): + * if not self.htsfile or not self.header: + * return # <<<<<<<<<<<<<< + * + * # Write header if no records were written + */ + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":4018 + * + * def __dealloc__(self): + * if not self.htsfile or not self.header: # <<<<<<<<<<<<<< + * return + * + */ + } + + /* "pysam/libcbcf.pyx":4022 + * + * # Write header if no records were written + * if self.htsfile.is_write and not self.header_written: # <<<<<<<<<<<<<< + * with nogil: + * bcf_hdr_write(self.htsfile, self.header.ptr) + */ + __pyx_t_3 = (__pyx_v_self->__pyx_base.htsfile->is_write != 0); + if (__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_3 = ((!(__pyx_v_self->header_written != 0)) != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L7_bool_binop_done:; + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":4023 + * # Write header if no records were written + * if self.htsfile.is_write and not self.header_written: + * with nogil: # <<<<<<<<<<<<<< + * bcf_hdr_write(self.htsfile, self.header.ptr) + * + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libcbcf.pyx":4024 + * if self.htsfile.is_write and not self.header_written: + * with nogil: + * bcf_hdr_write(self.htsfile, self.header.ptr) # <<<<<<<<<<<<<< + * + * cdef int ret = hts_close(self.htsfile) + */ + (void)(bcf_hdr_write(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->header->ptr)); + } + + /* "pysam/libcbcf.pyx":4023 + * # Write header if no records were written + * if self.htsfile.is_write and not self.header_written: + * with nogil: # <<<<<<<<<<<<<< + * bcf_hdr_write(self.htsfile, self.header.ptr) + * + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L11; + } + __pyx_L11:; + } + } + + /* "pysam/libcbcf.pyx":4022 + * + * # Write header if no records were written + * if self.htsfile.is_write and not self.header_written: # <<<<<<<<<<<<<< + * with nogil: + * bcf_hdr_write(self.htsfile, self.header.ptr) + */ + } + + /* "pysam/libcbcf.pyx":4026 + * bcf_hdr_write(self.htsfile, self.header.ptr) + * + * cdef int ret = hts_close(self.htsfile) # <<<<<<<<<<<<<< + * self.htsfile = NULL + * self.header = self.index = None + */ + __pyx_v_ret = hts_close(__pyx_v_self->__pyx_base.htsfile); + + /* "pysam/libcbcf.pyx":4027 + * + * cdef int ret = hts_close(self.htsfile) + * self.htsfile = NULL # <<<<<<<<<<<<<< + * self.header = self.index = None + * + */ + __pyx_v_self->__pyx_base.htsfile = NULL; + + /* "pysam/libcbcf.pyx":4028 + * cdef int ret = hts_close(self.htsfile) + * self.htsfile = NULL + * self.header = self.index = None # <<<<<<<<<<<<<< + * + * if ret < 0: + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)Py_None); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->index)); + __pyx_v_self->index = ((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)Py_None); + + /* "pysam/libcbcf.pyx":4030 + * self.header = self.index = None + * + * if ret < 0: # <<<<<<<<<<<<<< + * global errno + * if errno == EPIPE: + */ + __pyx_t_1 = ((__pyx_v_ret < 0) != 0); + if (__pyx_t_1) { + + /* "pysam/libcbcf.pyx":4032 + * if ret < 0: + * global errno + * if errno == EPIPE: # <<<<<<<<<<<<<< + * errno = 0 + * else: + */ + __pyx_t_1 = ((errno == EPIPE) != 0); + if (likely(__pyx_t_1)) { + + /* "pysam/libcbcf.pyx":4033 + * global errno + * if errno == EPIPE: + * errno = 0 # <<<<<<<<<<<<<< + * else: + * raise IOError(errno, force_str(strerror(errno))) + */ + errno = 0; + + /* "pysam/libcbcf.pyx":4032 + * if ret < 0: + * global errno + * if errno == EPIPE: # <<<<<<<<<<<<<< + * errno = 0 + * else: + */ + goto __pyx_L13; + } + + /* "pysam/libcbcf.pyx":4035 + * errno = 0 + * else: + * raise IOError(errno, force_str(strerror(errno))) # <<<<<<<<<<<<<< + * + * def close(self): + */ + /*else*/ { + __pyx_t_4 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6); + __pyx_t_4 = 0; + __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 4035, __pyx_L1_error) + } + __pyx_L13:; + + /* "pysam/libcbcf.pyx":4030 + * self.header = self.index = None + * + * if ret < 0: # <<<<<<<<<<<<<< + * global errno + * if errno == EPIPE: + */ + } + + /* "pysam/libcbcf.pyx":4017 * self.open(*args, **kwargs) * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * if not self.htsfile or not self.header: + * return + */ + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_WriteUnraisable("pysam.libcbcf.VariantFile.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); +} + +/* "pysam/libcbcf.pyx":4037 + * raise IOError(errno, force_str(strerror(errno))) + * * def close(self): # <<<<<<<<<<<<<< * """closes the :class:`pysam.VariantFile`.""" - * cdef int ret = 0 + * if not self.htsfile: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_5close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_11VariantFile_4close[] = "VariantFile.close(self)\ncloses the :class:`pysam.VariantFile`."; -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_5close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_7close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_6close[] = "VariantFile.close(self)\ncloses the :class:`pysam.VariantFile`."; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_7close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("close (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_4close(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_6close(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_4close(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6close(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { int __pyx_v_ret; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations @@ -56789,154 +66014,147 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_4close(struct __pyx_obj_ PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("close", 0); - __Pyx_TraceCall("close", __pyx_f[0], 3481, 0, __PYX_ERR(0, 3481, __pyx_L1_error)); + __Pyx_TraceCall("close", __pyx_f[0], 4037, 0, __PYX_ERR(0, 4037, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3483 + /* "pysam/libcbcf.pyx":4039 * def close(self): * """closes the :class:`pysam.VariantFile`.""" - * cdef int ret = 0 # <<<<<<<<<<<<<< - * self.header = self.index = None - * if self.htsfile: + * if not self.htsfile: # <<<<<<<<<<<<<< + * return + * */ - __pyx_v_ret = 0; + __pyx_t_1 = ((!(__pyx_v_self->__pyx_base.htsfile != 0)) != 0); + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3484 + /* "pysam/libcbcf.pyx":4040 * """closes the :class:`pysam.VariantFile`.""" - * cdef int ret = 0 - * self.header = self.index = None # <<<<<<<<<<<<<< - * if self.htsfile: - * # Write header if no records were written + * if not self.htsfile: + * return # <<<<<<<<<<<<<< + * + * # Write header if no records were written */ - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->header); - __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); - __pyx_v_self->header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)Py_None); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->index); - __Pyx_DECREF(((PyObject *)__pyx_v_self->index)); - __pyx_v_self->index = ((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)Py_None); + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; - /* "pysam/libcbcf.pyx":3485 - * cdef int ret = 0 - * self.header = self.index = None - * if self.htsfile: # <<<<<<<<<<<<<< - * # Write header if no records were written - * if self.htsfile.is_write and not self.header_written: + /* "pysam/libcbcf.pyx":4039 + * def close(self): + * """closes the :class:`pysam.VariantFile`.""" + * if not self.htsfile: # <<<<<<<<<<<<<< + * return + * */ - __pyx_t_1 = (__pyx_v_self->__pyx_base.htsfile != 0); - if (__pyx_t_1) { + } - /* "pysam/libcbcf.pyx":3487 - * if self.htsfile: - * # Write header if no records were written - * if self.htsfile.is_write and not self.header_written: # <<<<<<<<<<<<<< - * self.header_written = True - * with nogil: + /* "pysam/libcbcf.pyx":4043 + * + * # Write header if no records were written + * if self.htsfile.is_write and not self.header_written: # <<<<<<<<<<<<<< + * with nogil: + * bcf_hdr_write(self.htsfile, self.header.ptr) */ - __pyx_t_2 = (__pyx_v_self->__pyx_base.htsfile->is_write != 0); - if (__pyx_t_2) { - } else { - __pyx_t_1 = __pyx_t_2; - goto __pyx_L5_bool_binop_done; - } - __pyx_t_2 = ((!(__pyx_v_self->header_written != 0)) != 0); + __pyx_t_2 = (__pyx_v_self->__pyx_base.htsfile->is_write != 0); + if (__pyx_t_2) { + } else { __pyx_t_1 = __pyx_t_2; - __pyx_L5_bool_binop_done:; - if (__pyx_t_1) { + goto __pyx_L5_bool_binop_done; + } + __pyx_t_2 = ((!(__pyx_v_self->header_written != 0)) != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L5_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3488 - * # Write header if no records were written - * if self.htsfile.is_write and not self.header_written: - * self.header_written = True # <<<<<<<<<<<<<< - * with nogil: - * bcf_hdr_write(self.htsfile, self.header.ptr) + /* "pysam/libcbcf.pyx":4044 + * # Write header if no records were written + * if self.htsfile.is_write and not self.header_written: + * with nogil: # <<<<<<<<<<<<<< + * bcf_hdr_write(self.htsfile, self.header.ptr) + * */ - __pyx_v_self->header_written = 1; + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libcbcf.pyx":3489 - * if self.htsfile.is_write and not self.header_written: - * self.header_written = True - * with nogil: # <<<<<<<<<<<<<< - * bcf_hdr_write(self.htsfile, self.header.ptr) + /* "pysam/libcbcf.pyx":4045 + * if self.htsfile.is_write and not self.header_written: + * with nogil: + * bcf_hdr_write(self.htsfile, self.header.ptr) # <<<<<<<<<<<<<< * + * cdef int ret = hts_close(self.htsfile) */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + (void)(bcf_hdr_write(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->header->ptr)); + } - /* "pysam/libcbcf.pyx":3490 - * self.header_written = True - * with nogil: - * bcf_hdr_write(self.htsfile, self.header.ptr) # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":4044 + * # Write header if no records were written + * if self.htsfile.is_write and not self.header_written: + * with nogil: # <<<<<<<<<<<<<< + * bcf_hdr_write(self.htsfile, self.header.ptr) * - * ret = hts_close(self.htsfile) */ - (void)(bcf_hdr_write(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->header->ptr)); + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L9; } + __pyx_L9:; + } + } - /* "pysam/libcbcf.pyx":3489 - * if self.htsfile.is_write and not self.header_written: - * self.header_written = True - * with nogil: # <<<<<<<<<<<<<< - * bcf_hdr_write(self.htsfile, self.header.ptr) + /* "pysam/libcbcf.pyx":4043 * + * # Write header if no records were written + * if self.htsfile.is_write and not self.header_written: # <<<<<<<<<<<<<< + * with nogil: + * bcf_hdr_write(self.htsfile, self.header.ptr) */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L9; - } - __pyx_L9:; - } - } + } - /* "pysam/libcbcf.pyx":3487 - * if self.htsfile: - * # Write header if no records were written - * if self.htsfile.is_write and not self.header_written: # <<<<<<<<<<<<<< - * self.header_written = True - * with nogil: + /* "pysam/libcbcf.pyx":4047 + * bcf_hdr_write(self.htsfile, self.header.ptr) + * + * cdef int ret = hts_close(self.htsfile) # <<<<<<<<<<<<<< + * self.htsfile = NULL + * self.header = self.index = None */ - } + __pyx_v_ret = hts_close(__pyx_v_self->__pyx_base.htsfile); - /* "pysam/libcbcf.pyx":3492 - * bcf_hdr_write(self.htsfile, self.header.ptr) + /* "pysam/libcbcf.pyx":4048 * - * ret = hts_close(self.htsfile) # <<<<<<<<<<<<<< - * self.htsfile = NULL + * cdef int ret = hts_close(self.htsfile) + * self.htsfile = NULL # <<<<<<<<<<<<<< + * self.header = self.index = None * */ - __pyx_v_ret = hts_close(__pyx_v_self->__pyx_base.htsfile); + __pyx_v_self->__pyx_base.htsfile = NULL; - /* "pysam/libcbcf.pyx":3493 - * - * ret = hts_close(self.htsfile) - * self.htsfile = NULL # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":4049 + * cdef int ret = hts_close(self.htsfile) + * self.htsfile = NULL + * self.header = self.index = None # <<<<<<<<<<<<<< * * if ret < 0: */ - __pyx_v_self->__pyx_base.htsfile = NULL; + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->header); + __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); + __pyx_v_self->header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)Py_None); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->index)); + __pyx_v_self->index = ((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)Py_None); - /* "pysam/libcbcf.pyx":3485 - * cdef int ret = 0 + /* "pysam/libcbcf.pyx":4051 * self.header = self.index = None - * if self.htsfile: # <<<<<<<<<<<<<< - * # Write header if no records were written - * if self.htsfile.is_write and not self.header_written: - */ - } - - /* "pysam/libcbcf.pyx":3495 - * self.htsfile = NULL * * if ret < 0: # <<<<<<<<<<<<<< * global errno @@ -56945,7 +66163,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_4close(struct __pyx_obj_ __pyx_t_1 = ((__pyx_v_ret < 0) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3497 + /* "pysam/libcbcf.pyx":4053 * if ret < 0: * global errno * if errno == EPIPE: # <<<<<<<<<<<<<< @@ -56955,16 +66173,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_4close(struct __pyx_obj_ __pyx_t_1 = ((errno == EPIPE) != 0); if (likely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3498 + /* "pysam/libcbcf.pyx":4054 * global errno * if errno == EPIPE: * errno = 0 # <<<<<<<<<<<<<< * else: - * raise OSError(errno, force_str(strerror(errno))) + * raise IOError(errno, force_str(strerror(errno))) */ errno = 0; - /* "pysam/libcbcf.pyx":3497 + /* "pysam/libcbcf.pyx":4053 * if ret < 0: * global errno * if errno == EPIPE: # <<<<<<<<<<<<<< @@ -56974,22 +66192,22 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_4close(struct __pyx_obj_ goto __pyx_L11; } - /* "pysam/libcbcf.pyx":3500 + /* "pysam/libcbcf.pyx":4056 * errno = 0 * else: - * raise OSError(errno, force_str(strerror(errno))) # <<<<<<<<<<<<<< + * raise IOError(errno, force_str(strerror(errno))) # <<<<<<<<<<<<<< * * def __iter__(self): */ /*else*/ { - __pyx_t_3 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3500, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4056, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3500, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4056, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3500, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4056, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3500, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4056, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); @@ -56997,17 +66215,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_4close(struct __pyx_obj_ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5); __pyx_t_3 = 0; __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3500, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4056, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 3500, __pyx_L1_error) + __PYX_ERR(0, 4056, __pyx_L1_error) } __pyx_L11:; - /* "pysam/libcbcf.pyx":3495 - * self.htsfile = NULL + /* "pysam/libcbcf.pyx":4051 + * self.header = self.index = None * * if ret < 0: # <<<<<<<<<<<<<< * global errno @@ -57015,12 +66233,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_4close(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3481 - * self.open(*args, **kwargs) + /* "pysam/libcbcf.pyx":4037 + * raise IOError(errno, force_str(strerror(errno))) * * def close(self): # <<<<<<<<<<<<<< * """closes the :class:`pysam.VariantFile`.""" - * cdef int ret = 0 + * if not self.htsfile: */ /* function exit code */ @@ -57039,8 +66257,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_4close(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libcbcf.pyx":3502 - * raise OSError(errno, force_str(strerror(errno))) +/* "pysam/libcbcf.pyx":4058 + * raise IOError(errno, force_str(strerror(errno))) * * def __iter__(self): # <<<<<<<<<<<<<< * if not self.is_open: @@ -57048,19 +66266,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_4close(struct __pyx_obj_ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_7__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_7__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_9__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_9__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_6__iter__(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_8__iter__(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6__iter__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__iter__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -57068,36 +66286,36 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6__iter__(struct __pyx_o int __pyx_t_2; int __pyx_t_3; __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 3502, 0, __PYX_ERR(0, 3502, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 4058, 0, __PYX_ERR(0, 4058, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3503 + /* "pysam/libcbcf.pyx":4059 * * def __iter__(self): * if not self.is_open: # <<<<<<<<<<<<<< * raise ValueError('I/O operation on closed file') * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3503, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4059, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3503, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 4059, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = ((!__pyx_t_2) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":3504 + /* "pysam/libcbcf.pyx":4060 * def __iter__(self): * if not self.is_open: * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< * * if self.htsfile.is_write: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__197, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3504, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__209, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4060, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3504, __pyx_L1_error) + __PYX_ERR(0, 4060, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3503 + /* "pysam/libcbcf.pyx":4059 * * def __iter__(self): * if not self.is_open: # <<<<<<<<<<<<<< @@ -57106,7 +66324,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6__iter__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":3506 + /* "pysam/libcbcf.pyx":4062 * raise ValueError('I/O operation on closed file') * * if self.htsfile.is_write: # <<<<<<<<<<<<<< @@ -57116,20 +66334,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6__iter__(struct __pyx_o __pyx_t_3 = (__pyx_v_self->__pyx_base.htsfile->is_write != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":3507 + /* "pysam/libcbcf.pyx":4063 * * if self.htsfile.is_write: * raise ValueError('cannot iterate over Variantfile opened for writing') # <<<<<<<<<<<<<< * * self.is_reading = 1 */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__198, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3507, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__210, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4063, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3507, __pyx_L1_error) + __PYX_ERR(0, 4063, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3506 + /* "pysam/libcbcf.pyx":4062 * raise ValueError('I/O operation on closed file') * * if self.htsfile.is_write: # <<<<<<<<<<<<<< @@ -57138,7 +66356,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6__iter__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":3509 + /* "pysam/libcbcf.pyx":4065 * raise ValueError('cannot iterate over Variantfile opened for writing') * * self.is_reading = 1 # <<<<<<<<<<<<<< @@ -57147,7 +66365,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6__iter__(struct __pyx_o */ __pyx_v_self->is_reading = 1; - /* "pysam/libcbcf.pyx":3510 + /* "pysam/libcbcf.pyx":4066 * * self.is_reading = 1 * return self # <<<<<<<<<<<<<< @@ -57159,8 +66377,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6__iter__(struct __pyx_o __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcbcf.pyx":3502 - * raise OSError(errno, force_str(strerror(errno))) + /* "pysam/libcbcf.pyx":4058 + * raise IOError(errno, force_str(strerror(errno))) * * def __iter__(self): # <<<<<<<<<<<<<< * if not self.is_open: @@ -57179,7 +66397,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6__iter__(struct __pyx_o return __pyx_r; } -/* "pysam/libcbcf.pyx":3512 +/* "pysam/libcbcf.pyx":4068 * return self * * def __next__(self): # <<<<<<<<<<<<<< @@ -57188,19 +66406,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6__iter__(struct __pyx_o */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_9__next__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_9__next__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_11__next__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_11__next__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__next__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_10__next__(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10__next__(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { int __pyx_v_ret; bcf1_t *__pyx_v_record; PyObject *__pyx_r = NULL; @@ -57209,28 +66427,61 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 3512, 0, __PYX_ERR(0, 3512, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 4068, 0, __PYX_ERR(0, 4068, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3514 + /* "pysam/libcbcf.pyx":4070 * def __next__(self): * cdef int ret * cdef bcf1_t *record = bcf_init1() # <<<<<<<<<<<<<< * - * record.pos = -1 + * if not record: */ __pyx_v_record = bcf_init1(); - /* "pysam/libcbcf.pyx":3516 + /* "pysam/libcbcf.pyx":4072 + * cdef bcf1_t *record = bcf_init1() + * + * if not record: # <<<<<<<<<<<<<< + * raise MemoryError('unable to allocate BCF record') + * + */ + __pyx_t_1 = ((!(__pyx_v_record != 0)) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbcf.pyx":4073 + * + * if not record: + * raise MemoryError('unable to allocate BCF record') # <<<<<<<<<<<<<< + * + * record.pos = -1 + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__211, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4073, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 4073, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":4072 * cdef bcf1_t *record = bcf_init1() * + * if not record: # <<<<<<<<<<<<<< + * raise MemoryError('unable to allocate BCF record') + * + */ + } + + /* "pysam/libcbcf.pyx":4075 + * raise MemoryError('unable to allocate BCF record') + * * record.pos = -1 # <<<<<<<<<<<<<< * if self.drop_samples: * record.max_unpack = BCF_UN_SHR */ __pyx_v_record->pos = -1; - /* "pysam/libcbcf.pyx":3517 + /* "pysam/libcbcf.pyx":4076 * * record.pos = -1 * if self.drop_samples: # <<<<<<<<<<<<<< @@ -57240,7 +66491,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o __pyx_t_1 = (__pyx_v_self->drop_samples != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3518 + /* "pysam/libcbcf.pyx":4077 * record.pos = -1 * if self.drop_samples: * record.max_unpack = BCF_UN_SHR # <<<<<<<<<<<<<< @@ -57249,7 +66500,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o */ __pyx_v_record->max_unpack = BCF_UN_SHR; - /* "pysam/libcbcf.pyx":3517 + /* "pysam/libcbcf.pyx":4076 * * record.pos = -1 * if self.drop_samples: # <<<<<<<<<<<<<< @@ -57258,7 +66509,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":3520 + /* "pysam/libcbcf.pyx":4079 * record.max_unpack = BCF_UN_SHR * * with nogil: # <<<<<<<<<<<<<< @@ -57273,7 +66524,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o #endif /*try:*/ { - /* "pysam/libcbcf.pyx":3521 + /* "pysam/libcbcf.pyx":4080 * * with nogil: * ret = bcf_read1(self.htsfile, self.header.ptr, record) # <<<<<<<<<<<<<< @@ -57283,7 +66534,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o __pyx_v_ret = bcf_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->header->ptr, __pyx_v_record); } - /* "pysam/libcbcf.pyx":3520 + /* "pysam/libcbcf.pyx":4079 * record.max_unpack = BCF_UN_SHR * * with nogil: # <<<<<<<<<<<<<< @@ -57296,13 +66547,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif - goto __pyx_L6; + goto __pyx_L7; } - __pyx_L6:; + __pyx_L7:; } } - /* "pysam/libcbcf.pyx":3523 + /* "pysam/libcbcf.pyx":4082 * ret = bcf_read1(self.htsfile, self.header.ptr, record) * * if ret < 0: # <<<<<<<<<<<<<< @@ -57312,7 +66563,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o __pyx_t_1 = ((__pyx_v_ret < 0) != 0); if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3524 + /* "pysam/libcbcf.pyx":4083 * * if ret < 0: * bcf_destroy1(record) # <<<<<<<<<<<<<< @@ -57321,17 +66572,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o */ bcf_destroy1(__pyx_v_record); - /* "pysam/libcbcf.pyx":3525 + /* "pysam/libcbcf.pyx":4084 * if ret < 0: * bcf_destroy1(record) * if ret == -1: # <<<<<<<<<<<<<< * raise StopIteration * elif ret == -2: */ - switch (__pyx_v_ret) { - case -1L: + __pyx_t_1 = ((__pyx_v_ret == -1L) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3526 + /* "pysam/libcbcf.pyx":4085 * bcf_destroy1(record) * if ret == -1: * raise StopIteration # <<<<<<<<<<<<<< @@ -57339,65 +66590,110 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o * raise IOError('truncated file') */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 3526, __pyx_L1_error) + __PYX_ERR(0, 4085, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3525 + /* "pysam/libcbcf.pyx":4084 * if ret < 0: * bcf_destroy1(record) * if ret == -1: # <<<<<<<<<<<<<< * raise StopIteration * elif ret == -2: */ - break; + } - /* "pysam/libcbcf.pyx":3527 + /* "pysam/libcbcf.pyx":4086 * if ret == -1: * raise StopIteration * elif ret == -2: # <<<<<<<<<<<<<< * raise IOError('truncated file') - * else: + * elif errno: */ - case -2L: + __pyx_t_1 = ((__pyx_v_ret == -2L) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3528 + /* "pysam/libcbcf.pyx":4087 * raise StopIteration * elif ret == -2: * raise IOError('truncated file') # <<<<<<<<<<<<<< - * else: - * raise ValueError('Variant read failed') + * elif errno: + * raise IOError(errno, strerror(errno)) */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__199, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3528, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__212, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4087, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 3528, __pyx_L1_error) + __PYX_ERR(0, 4087, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3527 + /* "pysam/libcbcf.pyx":4086 * if ret == -1: * raise StopIteration * elif ret == -2: # <<<<<<<<<<<<<< * raise IOError('truncated file') + * elif errno: + */ + } + + /* "pysam/libcbcf.pyx":4088 + * elif ret == -2: + * raise IOError('truncated file') + * elif errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) * else: */ - break; - default: + __pyx_t_1 = (errno != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3530 + /* "pysam/libcbcf.pyx":4089 + * raise IOError('truncated file') + * elif errno: + * raise IOError(errno, strerror(errno)) # <<<<<<<<<<<<<< + * else: + * raise IOError('unable to fetch next record') + */ + __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4089, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4089, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4089, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4089, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 4089, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":4088 + * elif ret == -2: * raise IOError('truncated file') + * elif errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) * else: - * raise ValueError('Variant read failed') # <<<<<<<<<<<<<< + */ + } + + /* "pysam/libcbcf.pyx":4091 + * raise IOError(errno, strerror(errno)) + * else: + * raise IOError('unable to fetch next record') # <<<<<<<<<<<<<< * * return makeVariantRecord(self.header, record) */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__200, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3530, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 3530, __pyx_L1_error) - break; + /*else*/ { + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__213, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 4091, __pyx_L1_error) } - /* "pysam/libcbcf.pyx":3523 + /* "pysam/libcbcf.pyx":4082 * ret = bcf_read1(self.htsfile, self.header.ptr, record) * * if ret < 0: # <<<<<<<<<<<<<< @@ -57406,24 +66702,24 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o */ } - /* "pysam/libcbcf.pyx":3532 - * raise ValueError('Variant read failed') + /* "pysam/libcbcf.pyx":4093 + * raise IOError('unable to fetch next record') * * return makeVariantRecord(self.header, record) # <<<<<<<<<<<<<< * * def copy(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = ((PyObject *)__pyx_v_self->header); - __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_2), __pyx_v_record)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3532, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_3 = ((PyObject *)__pyx_v_self->header); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantRecord(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_3), __pyx_v_record)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4093, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3512 + /* "pysam/libcbcf.pyx":4068 * return self * * def __next__(self): # <<<<<<<<<<<<<< @@ -57435,6 +66731,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("pysam.libcbcf.VariantFile.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -57444,7 +66741,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o return __pyx_r; } -/* "pysam/libcbcf.pyx":3534 +/* "pysam/libcbcf.pyx":4095 * return makeVariantRecord(self.header, record) * * def copy(self): # <<<<<<<<<<<<<< @@ -57453,20 +66750,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_8__next__(struct __pyx_o */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_11copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_11VariantFile_10copy[] = "VariantFile.copy(self)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_11copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_13copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_12copy[] = "VariantFile.copy(self)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_13copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("copy (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_12copy(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12copy(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_vars = 0; bcf_hdr_t *__pyx_v_hdr; PyObject *__pyx_r = NULL; @@ -57482,23 +66779,23 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("copy", 0); - __Pyx_TraceCall("copy", __pyx_f[0], 3534, 0, __PYX_ERR(0, 3534, __pyx_L1_error)); + __Pyx_TraceCall("copy", __pyx_f[0], 4095, 0, __PYX_ERR(0, 4095, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3535 + /* "pysam/libcbcf.pyx":4096 * * def copy(self): * if not self.is_open: # <<<<<<<<<<<<<< * raise ValueError * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3535, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4096, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3535, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 4096, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = ((!__pyx_t_2) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":3536 + /* "pysam/libcbcf.pyx":4097 * def copy(self): * if not self.is_open: * raise ValueError # <<<<<<<<<<<<<< @@ -57506,9 +66803,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ * cdef VariantFile vars = VariantFile.__new__(VariantFile) */ __Pyx_Raise(__pyx_builtin_ValueError, 0, 0, 0); - __PYX_ERR(0, 3536, __pyx_L1_error) + __PYX_ERR(0, 4097, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3535 + /* "pysam/libcbcf.pyx":4096 * * def copy(self): * if not self.is_open: # <<<<<<<<<<<<<< @@ -57517,29 +66814,29 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3538 + /* "pysam/libcbcf.pyx":4099 * raise ValueError * * cdef VariantFile vars = VariantFile.__new__(VariantFile) # <<<<<<<<<<<<<< * cdef bcf_hdr_t *hdr * */ - __pyx_t_1 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantFile(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantFile), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3538, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_tp_new_5pysam_7libcbcf_VariantFile(((PyTypeObject *)__pyx_ptype_5pysam_7libcbcf_VariantFile), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4099, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_v_vars = ((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3542 + /* "pysam/libcbcf.pyx":4103 * * # FIXME: re-open using fd or else header and index could be invalid * vars.htsfile = self._open_htsfile() # <<<<<<<<<<<<<< * * if not vars.htsfile: */ - __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_7libcbcf_VariantFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_4 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 3542, __pyx_L1_error) + __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_7libcbcf_VariantFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_4 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 4103, __pyx_L1_error) __pyx_v_vars->__pyx_base.htsfile = __pyx_t_4; - /* "pysam/libcbcf.pyx":3544 + /* "pysam/libcbcf.pyx":4105 * vars.htsfile = self._open_htsfile() * * if not vars.htsfile: # <<<<<<<<<<<<<< @@ -57549,20 +66846,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_t_3 = ((!(__pyx_v_vars->__pyx_base.htsfile != 0)) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":3545 + /* "pysam/libcbcf.pyx":4106 * * if not vars.htsfile: * raise ValueError('Cannot re-open htsfile') # <<<<<<<<<<<<<< * * # minimize overhead by re-using header and index. This approach is */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__201, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3545, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__214, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3545, __pyx_L1_error) + __PYX_ERR(0, 4106, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3544 + /* "pysam/libcbcf.pyx":4105 * vars.htsfile = self._open_htsfile() * * if not vars.htsfile: # <<<<<<<<<<<<<< @@ -57571,7 +66868,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3549 + /* "pysam/libcbcf.pyx":4110 * # minimize overhead by re-using header and index. This approach is * # currently risky, but see above for how this can be mitigated. * vars.header = self.header # <<<<<<<<<<<<<< @@ -57586,7 +66883,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_v_vars->header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3550 + /* "pysam/libcbcf.pyx":4111 * # currently risky, but see above for how this can be mitigated. * vars.header = self.header * vars.index = self.index # <<<<<<<<<<<<<< @@ -57601,12 +66898,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_v_vars->index = ((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3552 + /* "pysam/libcbcf.pyx":4113 * vars.index = self.index * * vars.filename = self.filename # <<<<<<<<<<<<<< * vars.mode = self.mode - * vars.index_filename = self.index_filename + * vars.threads = self.threads */ __pyx_t_1 = __pyx_v_self->__pyx_base.filename; __Pyx_INCREF(__pyx_t_1); @@ -57616,12 +66913,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_v_vars->__pyx_base.filename = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3553 + /* "pysam/libcbcf.pyx":4114 * * vars.filename = self.filename * vars.mode = self.mode # <<<<<<<<<<<<<< + * vars.threads = self.threads * vars.index_filename = self.index_filename - * vars.drop_samples = self.drop_samples */ __pyx_t_1 = __pyx_v_self->__pyx_base.mode; __Pyx_INCREF(__pyx_t_1); @@ -57631,9 +66928,24 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_v_vars->__pyx_base.mode = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3554 + /* "pysam/libcbcf.pyx":4115 * vars.filename = self.filename * vars.mode = self.mode + * vars.threads = self.threads # <<<<<<<<<<<<<< + * vars.index_filename = self.index_filename + * vars.drop_samples = self.drop_samples + */ + __pyx_t_1 = __pyx_v_self->__pyx_base.threads; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_vars->__pyx_base.threads); + __Pyx_DECREF(__pyx_v_vars->__pyx_base.threads); + __pyx_v_vars->__pyx_base.threads = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":4116 + * vars.mode = self.mode + * vars.threads = self.threads * vars.index_filename = self.index_filename # <<<<<<<<<<<<<< * vars.drop_samples = self.drop_samples * vars.is_stream = self.is_stream @@ -57646,8 +66958,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_v_vars->__pyx_base.index_filename = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3555 - * vars.mode = self.mode + /* "pysam/libcbcf.pyx":4117 + * vars.threads = self.threads * vars.index_filename = self.index_filename * vars.drop_samples = self.drop_samples # <<<<<<<<<<<<<< * vars.is_stream = self.is_stream @@ -57656,7 +66968,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_t_3 = __pyx_v_self->drop_samples; __pyx_v_vars->drop_samples = __pyx_t_3; - /* "pysam/libcbcf.pyx":3556 + /* "pysam/libcbcf.pyx":4118 * vars.index_filename = self.index_filename * vars.drop_samples = self.drop_samples * vars.is_stream = self.is_stream # <<<<<<<<<<<<<< @@ -57666,7 +66978,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_t_3 = __pyx_v_self->__pyx_base.is_stream; __pyx_v_vars->__pyx_base.is_stream = __pyx_t_3; - /* "pysam/libcbcf.pyx":3557 + /* "pysam/libcbcf.pyx":4119 * vars.drop_samples = self.drop_samples * vars.is_stream = self.is_stream * vars.is_remote = self.is_remote # <<<<<<<<<<<<<< @@ -57676,7 +66988,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_t_3 = __pyx_v_self->__pyx_base.is_remote; __pyx_v_vars->__pyx_base.is_remote = __pyx_t_3; - /* "pysam/libcbcf.pyx":3558 + /* "pysam/libcbcf.pyx":4120 * vars.is_stream = self.is_stream * vars.is_remote = self.is_remote * vars.is_reading = self.is_reading # <<<<<<<<<<<<<< @@ -57686,7 +66998,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_t_3 = __pyx_v_self->is_reading; __pyx_v_vars->is_reading = __pyx_t_3; - /* "pysam/libcbcf.pyx":3559 + /* "pysam/libcbcf.pyx":4121 * vars.is_remote = self.is_remote * vars.is_reading = self.is_reading * vars.start_offset = self.start_offset # <<<<<<<<<<<<<< @@ -57696,7 +67008,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_t_5 = __pyx_v_self->__pyx_base.start_offset; __pyx_v_vars->__pyx_base.start_offset = __pyx_t_5; - /* "pysam/libcbcf.pyx":3560 + /* "pysam/libcbcf.pyx":4122 * vars.is_reading = self.is_reading * vars.start_offset = self.start_offset * vars.header_written = self.header_written # <<<<<<<<<<<<<< @@ -57706,7 +67018,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_t_3 = __pyx_v_self->header_written; __pyx_v_vars->header_written = __pyx_t_3; - /* "pysam/libcbcf.pyx":3562 + /* "pysam/libcbcf.pyx":4124 * vars.header_written = self.header_written * * if self.htsfile.is_bin: # <<<<<<<<<<<<<< @@ -57716,16 +67028,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_t_3 = (__pyx_v_self->__pyx_base.htsfile->is_bin != 0); if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":3563 + /* "pysam/libcbcf.pyx":4125 * * if self.htsfile.is_bin: * vars.seek(self.tell()) # <<<<<<<<<<<<<< * else: * with nogil: */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_vars), __pyx_n_s_seek); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3563, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_vars), __pyx_n_s_seek); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tell); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3563, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tell); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { @@ -57738,10 +67050,10 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ } } if (__pyx_t_9) { - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3563, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4125, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } else { - __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 3563, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4125, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; @@ -57756,14 +67068,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ } } if (!__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3563, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4125, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_6)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3563, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4125, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; @@ -57772,20 +67084,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3563, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4125, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3563, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_7); __pyx_t_7 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3563, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } @@ -57793,7 +67105,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3562 + /* "pysam/libcbcf.pyx":4124 * vars.header_written = self.header_written * * if self.htsfile.is_bin: # <<<<<<<<<<<<<< @@ -57803,7 +67115,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ goto __pyx_L5; } - /* "pysam/libcbcf.pyx":3565 + /* "pysam/libcbcf.pyx":4127 * vars.seek(self.tell()) * else: * with nogil: # <<<<<<<<<<<<<< @@ -57819,7 +67131,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ #endif /*try:*/ { - /* "pysam/libcbcf.pyx":3566 + /* "pysam/libcbcf.pyx":4128 * else: * with nogil: * hdr = bcf_hdr_read(vars.htsfile) # <<<<<<<<<<<<<< @@ -57829,7 +67141,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_v_hdr = bcf_hdr_read(__pyx_v_vars->__pyx_base.htsfile); } - /* "pysam/libcbcf.pyx":3565 + /* "pysam/libcbcf.pyx":4127 * vars.seek(self.tell()) * else: * with nogil: # <<<<<<<<<<<<<< @@ -57848,20 +67160,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ } } - /* "pysam/libcbcf.pyx":3567 + /* "pysam/libcbcf.pyx":4129 * with nogil: * hdr = bcf_hdr_read(vars.htsfile) * makeVariantHeader(hdr) # <<<<<<<<<<<<<< * * return vars */ - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3567, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4129, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L5:; - /* "pysam/libcbcf.pyx":3569 + /* "pysam/libcbcf.pyx":4131 * makeVariantHeader(hdr) * * return vars # <<<<<<<<<<<<<< @@ -57873,7 +67185,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ __pyx_r = ((PyObject *)__pyx_v_vars); goto __pyx_L0; - /* "pysam/libcbcf.pyx":3534 + /* "pysam/libcbcf.pyx":4095 * return makeVariantRecord(self.header, record) * * def copy(self): # <<<<<<<<<<<<<< @@ -57898,7 +67210,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libcbcf.pyx":3571 +/* "pysam/libcbcf.pyx":4133 * return vars * * def open(self, filename, mode='r', # <<<<<<<<<<<<<< @@ -57907,24 +67219,26 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10copy(struct __pyx_obj_ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_13open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_11VariantFile_12open[] = "VariantFile.open(self, filename, mode='r', index_filename=None, VariantHeader header=None, drop_samples=False, duplicate_filehandle=True)\nopen a vcf/bcf file.\n\n If open is called on an existing VariantFile, the current file will be\n closed and a new file will be opened.\n "; -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_13open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_15open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_14open[] = "VariantFile.open(self, filename, mode='r', index_filename=None, VariantHeader header=None, drop_samples=False, duplicate_filehandle=True, ignore_truncation=False, threads=1)\nopen a vcf/bcf file.\n\n If open is called on an existing VariantFile, the current file will be\n closed and a new file will be opened.\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_15open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_filename = 0; PyObject *__pyx_v_mode = 0; PyObject *__pyx_v_index_filename = 0; struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_header = 0; PyObject *__pyx_v_drop_samples = 0; PyObject *__pyx_v_duplicate_filehandle = 0; + PyObject *__pyx_v_ignore_truncation = 0; + PyObject *__pyx_v_threads = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("open (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,&__pyx_n_s_mode,&__pyx_n_s_index_filename,&__pyx_n_s_header,&__pyx_n_s_drop_samples,&__pyx_n_s_duplicate_filehandle,0}; - PyObject* values[6] = {0,0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,&__pyx_n_s_mode,&__pyx_n_s_index_filename,&__pyx_n_s_header,&__pyx_n_s_drop_samples,&__pyx_n_s_duplicate_filehandle,&__pyx_n_s_ignore_truncation,&__pyx_n_s_threads,0}; + PyObject* values[8] = {0,0,0,0,0,0,0,0}; values[1] = ((PyObject *)__pyx_n_s_r); - /* "pysam/libcbcf.pyx":3572 + /* "pysam/libcbcf.pyx":4134 * * def open(self, filename, mode='r', * index_filename=None, # <<<<<<<<<<<<<< @@ -57933,36 +67247,50 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_13open(PyObject *__pyx_v */ values[2] = ((PyObject *)Py_None); - /* "pysam/libcbcf.pyx":3573 + /* "pysam/libcbcf.pyx":4135 * def open(self, filename, mode='r', * index_filename=None, * VariantHeader header=None, # <<<<<<<<<<<<<< * drop_samples=False, - * duplicate_filehandle=True): + * duplicate_filehandle=True, */ values[3] = (PyObject *)((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)Py_None); - /* "pysam/libcbcf.pyx":3574 + /* "pysam/libcbcf.pyx":4136 * index_filename=None, * VariantHeader header=None, * drop_samples=False, # <<<<<<<<<<<<<< - * duplicate_filehandle=True): - * """open a vcf/bcf file. + * duplicate_filehandle=True, + * ignore_truncation=False, */ values[4] = ((PyObject *)Py_False); - /* "pysam/libcbcf.pyx":3575 + /* "pysam/libcbcf.pyx":4137 * VariantHeader header=None, * drop_samples=False, - * duplicate_filehandle=True): # <<<<<<<<<<<<<< - * """open a vcf/bcf file. - * + * duplicate_filehandle=True, # <<<<<<<<<<<<<< + * ignore_truncation=False, + * threads=1): */ values[5] = ((PyObject *)Py_True); + + /* "pysam/libcbcf.pyx":4138 + * drop_samples=False, + * duplicate_filehandle=True, + * ignore_truncation=False, # <<<<<<<<<<<<<< + * threads=1): + * """open a vcf/bcf file. + */ + values[6] = ((PyObject *)Py_False); + values[7] = ((PyObject *)__pyx_int_1); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); @@ -58013,12 +67341,28 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_13open(PyObject *__pyx_v PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_duplicate_filehandle); if (value) { values[5] = value; kw_args--; } } + CYTHON_FALLTHROUGH; + case 6: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ignore_truncation); + if (value) { values[6] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 7: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_threads); + if (value) { values[7] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "open") < 0)) __PYX_ERR(0, 3571, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "open") < 0)) __PYX_ERR(0, 4133, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + CYTHON_FALLTHROUGH; + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); @@ -58040,19 +67384,21 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_13open(PyObject *__pyx_v __pyx_v_header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)values[3]); __pyx_v_drop_samples = values[4]; __pyx_v_duplicate_filehandle = values[5]; + __pyx_v_ignore_truncation = values[6]; + __pyx_v_threads = values[7]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("open", 0, 1, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3571, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("open", 0, 1, 8, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 4133, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.VariantFile.open", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_header), __pyx_ptype_5pysam_7libcbcf_VariantHeader, 1, "header", 0))) __PYX_ERR(0, 3573, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_12open(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), __pyx_v_filename, __pyx_v_mode, __pyx_v_index_filename, __pyx_v_header, __pyx_v_drop_samples, __pyx_v_duplicate_filehandle); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_header), __pyx_ptype_5pysam_7libcbcf_VariantHeader, 1, "header", 0))) __PYX_ERR(0, 4135, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_14open(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), __pyx_v_filename, __pyx_v_mode, __pyx_v_index_filename, __pyx_v_header, __pyx_v_drop_samples, __pyx_v_duplicate_filehandle, __pyx_v_ignore_truncation, __pyx_v_threads); - /* "pysam/libcbcf.pyx":3571 + /* "pysam/libcbcf.pyx":4133 * return vars * * def open(self, filename, mode='r', # <<<<<<<<<<<<<< @@ -58069,9 +67415,8 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_13open(PyObject *__pyx_v return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_index_filename, struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_header, PyObject *__pyx_v_drop_samples, PyObject *__pyx_v_duplicate_filehandle) { +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_14open(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_index_filename, struct __pyx_obj_5pysam_7libcbcf_VariantHeader *__pyx_v_header, PyObject *__pyx_v_drop_samples, PyObject *__pyx_v_duplicate_filehandle, PyObject *__pyx_v_ignore_truncation, PyObject *__pyx_v_threads) { bcf_hdr_t *__pyx_v_hdr; - BGZF *__pyx_v_bgzfp; hts_idx_t *__pyx_v_idx; tbx_t *__pyx_v_tidx; char *__pyx_v_cfilename; @@ -58082,11 +67427,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; + PyObject *__pyx_t_5 = NULL; int __pyx_t_6; Py_ssize_t __pyx_t_7; PyObject *(*__pyx_t_8)(PyObject *); @@ -58103,12 +67448,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ char *__pyx_t_19; int64_t __pyx_t_20; __Pyx_RefNannySetupContext("open", 0); - __Pyx_TraceCall("open", __pyx_f[0], 3571, 0, __PYX_ERR(0, 3571, __pyx_L1_error)); + __Pyx_TraceCall("open", __pyx_f[0], 4133, 0, __PYX_ERR(0, 4133, __pyx_L1_error)); __Pyx_INCREF(__pyx_v_filename); __Pyx_INCREF(__pyx_v_mode); __Pyx_INCREF(__pyx_v_index_filename); - /* "pysam/libcbcf.pyx":3586 + /* "pysam/libcbcf.pyx":4150 * cdef tbx_t *tidx * cdef char *cfilename * cdef char *cindex_filename = NULL # <<<<<<<<<<<<<< @@ -58117,49 +67462,104 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ __pyx_v_cindex_filename = NULL; - /* "pysam/libcbcf.pyx":3590 + /* "pysam/libcbcf.pyx":4153 + * cdef char *cmode + * + * if threads > 1 and ignore_truncation: # <<<<<<<<<<<<<< + * # This won't raise errors if reaching a truncated alignment, + * # because bgzf_mt_reader in htslib does not deal with + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_threads, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4153, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 4153, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_ignore_truncation); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 4153, __pyx_L1_error) + __pyx_t_1 = __pyx_t_3; + __pyx_L4_bool_binop_done:; + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbcf.pyx":4159 + * # to bgzf_read (https://github.com/samtools/htslib/blob/1.7/bgzf.c#L888) + * # Better to avoid this (for now) than to produce seemingly correct results. + * raise ValueError('Cannot add extra threads when "ignore_truncation" is True') # <<<<<<<<<<<<<< + * self.threads = threads + * + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__215, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 4159, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":4153 + * cdef char *cmode + * + * if threads > 1 and ignore_truncation: # <<<<<<<<<<<<<< + * # This won't raise errors if reaching a truncated alignment, + * # because bgzf_mt_reader in htslib does not deal with + */ + } + + /* "pysam/libcbcf.pyx":4160 + * # Better to avoid this (for now) than to produce seemingly correct results. + * raise ValueError('Cannot add extra threads when "ignore_truncation" is True') + * self.threads = threads # <<<<<<<<<<<<<< + * + * # close a previously opened file + */ + __Pyx_INCREF(__pyx_v_threads); + __Pyx_GIVEREF(__pyx_v_threads); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.threads); + __Pyx_DECREF(__pyx_v_self->__pyx_base.threads); + __pyx_v_self->__pyx_base.threads = __pyx_v_threads; + + /* "pysam/libcbcf.pyx":4163 * * # close a previously opened file * if self.is_open: # <<<<<<<<<<<<<< * self.close() * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3590, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3590, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4163, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 4163, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3591 + /* "pysam/libcbcf.pyx":4164 * # close a previously opened file * if self.is_open: * self.close() # <<<<<<<<<<<<<< * * if not mode or mode[0] not in 'rwa': */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3591, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4164, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); + __Pyx_DECREF_SET(__pyx_t_4, function); } } - if (__pyx_t_4) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3591, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4164, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3591, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4164, __pyx_L1_error) } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":3590 + /* "pysam/libcbcf.pyx":4163 * * # close a previously opened file * if self.is_open: # <<<<<<<<<<<<<< @@ -58168,43 +67568,43 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3593 + /* "pysam/libcbcf.pyx":4166 * self.close() * * if not mode or mode[0] not in 'rwa': # <<<<<<<<<<<<<< * raise ValueError('mode must begin with r, w or a') * */ - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_mode); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3593, __pyx_L1_error) - __pyx_t_6 = ((!__pyx_t_5) != 0); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_mode); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 4166, __pyx_L1_error) + __pyx_t_6 = ((!__pyx_t_3) != 0); if (!__pyx_t_6) { } else { - __pyx_t_2 = __pyx_t_6; - goto __pyx_L5_bool_binop_done; + __pyx_t_1 = __pyx_t_6; + goto __pyx_L8_bool_binop_done; } - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3593, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_n_s_rwa, Py_NE)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 3593, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = (__pyx_t_6 != 0); - __pyx_t_2 = __pyx_t_5; - __pyx_L5_bool_binop_done:; - if (unlikely(__pyx_t_2)) { + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4166, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_t_2, __pyx_n_s_rwa, Py_NE)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 4166, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = (__pyx_t_6 != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L8_bool_binop_done:; + if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3594 + /* "pysam/libcbcf.pyx":4167 * * if not mode or mode[0] not in 'rwa': * raise ValueError('mode must begin with r, w or a') # <<<<<<<<<<<<<< * * self.duplicate_filehandle = duplicate_filehandle */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__202, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3594, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3594, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__216, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4167, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 4167, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3593 + /* "pysam/libcbcf.pyx":4166 * self.close() * * if not mode or mode[0] not in 'rwa': # <<<<<<<<<<<<<< @@ -58213,155 +67613,155 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3596 + /* "pysam/libcbcf.pyx":4169 * raise ValueError('mode must begin with r, w or a') * * self.duplicate_filehandle = duplicate_filehandle # <<<<<<<<<<<<<< * * format_modes = [m for m in mode[1:] if m in 'bcguz'] */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_duplicate_filehandle); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3596, __pyx_L1_error) - __pyx_v_self->__pyx_base.duplicate_filehandle = __pyx_t_2; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_duplicate_filehandle); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4169, __pyx_L1_error) + __pyx_v_self->__pyx_base.duplicate_filehandle = __pyx_t_1; - /* "pysam/libcbcf.pyx":3598 + /* "pysam/libcbcf.pyx":4171 * self.duplicate_filehandle = duplicate_filehandle * * format_modes = [m for m in mode[1:] if m in 'bcguz'] # <<<<<<<<<<<<<< * if len(format_modes) > 1: * raise ValueError('mode contains conflicting format specifiers: {}'.format(''.join(format_modes))) */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_v_mode, 1, 0, NULL, NULL, &__pyx_slice__203, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __pyx_t_7 = 0; + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_v_mode, 1, 0, NULL, NULL, &__pyx_slice__217, 1, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_5 = __pyx_t_4; __Pyx_INCREF(__pyx_t_5); __pyx_t_7 = 0; __pyx_t_8 = NULL; } else { - __pyx_t_7 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3598, __pyx_L1_error) + __pyx_t_7 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4171, __pyx_L1_error) } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; for (;;) { if (likely(!__pyx_t_8)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_4)) break; + if (likely(PyList_CheckExact(__pyx_t_5))) { + if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_7); __Pyx_INCREF(__pyx_t_3); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 3598, __pyx_L1_error) + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 4171, __pyx_L1_error) #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); #endif } else { - if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_7); __Pyx_INCREF(__pyx_t_3); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 3598, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 4171, __pyx_L1_error) #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); #endif } } else { - __pyx_t_3 = __pyx_t_8(__pyx_t_4); - if (unlikely(!__pyx_t_3)) { + __pyx_t_4 = __pyx_t_8(__pyx_t_5); + if (unlikely(!__pyx_t_4)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 3598, __pyx_L1_error) + else __PYX_ERR(0, 4171, __pyx_L1_error) } break; } - __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_t_4); } - __Pyx_XDECREF_SET(__pyx_v_m, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_m, __pyx_n_s_bcguz, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3598, __pyx_L1_error) - __pyx_t_5 = (__pyx_t_2 != 0); - if (__pyx_t_5) { - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_v_m))) __PYX_ERR(0, 3598, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_m, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_m, __pyx_n_s_bcguz, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 4171, __pyx_L1_error) + __pyx_t_3 = (__pyx_t_1 != 0); + if (__pyx_t_3) { + if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_v_m))) __PYX_ERR(0, 4171, __pyx_L1_error) } } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_format_modes = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_format_modes = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":3599 + /* "pysam/libcbcf.pyx":4172 * * format_modes = [m for m in mode[1:] if m in 'bcguz'] * if len(format_modes) > 1: # <<<<<<<<<<<<<< * raise ValueError('mode contains conflicting format specifiers: {}'.format(''.join(format_modes))) * */ - __pyx_t_7 = PyList_GET_SIZE(__pyx_v_format_modes); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 3599, __pyx_L1_error) - __pyx_t_5 = ((__pyx_t_7 > 1) != 0); - if (unlikely(__pyx_t_5)) { + __pyx_t_7 = PyList_GET_SIZE(__pyx_v_format_modes); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 4172, __pyx_L1_error) + __pyx_t_3 = ((__pyx_t_7 > 1) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":3600 + /* "pysam/libcbcf.pyx":4173 * format_modes = [m for m in mode[1:] if m in 'bcguz'] * if len(format_modes) > 1: * raise ValueError('mode contains conflicting format specifiers: {}'.format(''.join(format_modes))) # <<<<<<<<<<<<<< * * invalid_modes = [m for m in mode[1:] if m not in 'bcguz0123456789ex'] */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_mode_contains_conflicting_format, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3600, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_mode_contains_conflicting_format, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4173, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyString_Join(__pyx_kp_s__15, __pyx_v_format_modes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__5, __pyx_v_format_modes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3600, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_4); + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_5); if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); + __Pyx_DECREF_SET(__pyx_t_5, function); } } if (!__pyx_t_9) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3600, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4173, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3600, __pyx_L1_error) + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4173, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3600, __pyx_L1_error) + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_4}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4173, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3600, __pyx_L1_error) + __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3600, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4173, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3600, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 3600, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4173, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 4173, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3599 + /* "pysam/libcbcf.pyx":4172 * * format_modes = [m for m in mode[1:] if m in 'bcguz'] * if len(format_modes) > 1: # <<<<<<<<<<<<<< @@ -58370,144 +67770,144 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3602 + /* "pysam/libcbcf.pyx":4175 * raise ValueError('mode contains conflicting format specifiers: {}'.format(''.join(format_modes))) * * invalid_modes = [m for m in mode[1:] if m not in 'bcguz0123456789ex'] # <<<<<<<<<<<<<< * if invalid_modes: * raise ValueError('invalid mode options: {}'.format(''.join(invalid_modes))) */ - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3602, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_mode, 1, 0, NULL, NULL, &__pyx_slice__204, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3602, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_10 = __pyx_t_1; __Pyx_INCREF(__pyx_t_10); __pyx_t_7 = 0; + __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4175, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_mode, 1, 0, NULL, NULL, &__pyx_slice__218, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4175, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_10 = __pyx_t_2; __Pyx_INCREF(__pyx_t_10); __pyx_t_7 = 0; __pyx_t_8 = NULL; } else { - __pyx_t_7 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3602, __pyx_L1_error) + __pyx_t_7 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4175, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); - __pyx_t_8 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3602, __pyx_L1_error) + __pyx_t_8 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4175, __pyx_L1_error) } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { if (likely(!__pyx_t_8)) { if (likely(PyList_CheckExact(__pyx_t_10))) { if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_10)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 3602, __pyx_L1_error) + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 4175, __pyx_L1_error) #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_10, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3602, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PySequence_ITEM(__pyx_t_10, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4175, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_10)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 3602, __pyx_L1_error) + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 4175, __pyx_L1_error) #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_10, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3602, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PySequence_ITEM(__pyx_t_10, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4175, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); #endif } } else { - __pyx_t_1 = __pyx_t_8(__pyx_t_10); - if (unlikely(!__pyx_t_1)) { + __pyx_t_2 = __pyx_t_8(__pyx_t_10); + if (unlikely(!__pyx_t_2)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 3602, __pyx_L1_error) + else __PYX_ERR(0, 4175, __pyx_L1_error) } break; } - __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_2); } - __Pyx_XDECREF_SET(__pyx_v_m, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_v_m, __pyx_n_s_bcguz0123456789ex, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3602, __pyx_L1_error) - __pyx_t_2 = (__pyx_t_5 != 0); - if (__pyx_t_2) { - if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_v_m))) __PYX_ERR(0, 3602, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_m, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_v_m, __pyx_n_s_bcguz0123456789ex, Py_NE)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 4175, __pyx_L1_error) + __pyx_t_1 = (__pyx_t_3 != 0); + if (__pyx_t_1) { + if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_v_m))) __PYX_ERR(0, 4175, __pyx_L1_error) } } __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_v_invalid_modes = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; + __pyx_v_invalid_modes = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; - /* "pysam/libcbcf.pyx":3603 + /* "pysam/libcbcf.pyx":4176 * * invalid_modes = [m for m in mode[1:] if m not in 'bcguz0123456789ex'] * if invalid_modes: # <<<<<<<<<<<<<< * raise ValueError('invalid mode options: {}'.format(''.join(invalid_modes))) * */ - __pyx_t_2 = (PyList_GET_SIZE(__pyx_v_invalid_modes) != 0); - if (unlikely(__pyx_t_2)) { + __pyx_t_1 = (PyList_GET_SIZE(__pyx_v_invalid_modes) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3604 + /* "pysam/libcbcf.pyx":4177 * invalid_modes = [m for m in mode[1:] if m not in 'bcguz0123456789ex'] * if invalid_modes: * raise ValueError('invalid mode options: {}'.format(''.join(invalid_modes))) # <<<<<<<<<<<<<< * * # Autodetect mode from filename */ - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_mode_options, __pyx_n_s_format); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3604, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_mode_options, __pyx_n_s_format); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); - __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__5, __pyx_v_invalid_modes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3604, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = NULL; + __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__15, __pyx_v_invalid_modes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4177, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_10); - if (likely(__pyx_t_3)) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); - __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_10, function); } } - if (!__pyx_t_3) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3604, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_4); + if (!__pyx_t_4) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4177, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_5); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_1}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3604, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4177, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_1}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3604, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4177, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3604, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3604, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4177, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } } __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3604, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_Raise(__pyx_t_10, 0, 0, 0); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __PYX_ERR(0, 3604, __pyx_L1_error) + __PYX_ERR(0, 4177, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3603 + /* "pysam/libcbcf.pyx":4176 * * invalid_modes = [m for m in mode[1:] if m not in 'bcguz0123456789ex'] * if invalid_modes: # <<<<<<<<<<<<<< @@ -58516,42 +67916,42 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3607 + /* "pysam/libcbcf.pyx":4180 * * # Autodetect mode from filename * if mode == 'w' and isinstance(filename, str): # <<<<<<<<<<<<<< * if filename.endswith('.gz'): * mode = 'wz' */ - __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 3607, __pyx_L1_error) - if (__pyx_t_5) { + __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 4180, __pyx_L1_error) + if (__pyx_t_3) { } else { - __pyx_t_2 = __pyx_t_5; - goto __pyx_L16_bool_binop_done; + __pyx_t_1 = __pyx_t_3; + goto __pyx_L19_bool_binop_done; } - __pyx_t_5 = PyString_Check(__pyx_v_filename); - __pyx_t_6 = (__pyx_t_5 != 0); - __pyx_t_2 = __pyx_t_6; - __pyx_L16_bool_binop_done:; - if (__pyx_t_2) { + __pyx_t_3 = PyString_Check(__pyx_v_filename); + __pyx_t_6 = (__pyx_t_3 != 0); + __pyx_t_1 = __pyx_t_6; + __pyx_L19_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3608 + /* "pysam/libcbcf.pyx":4181 * # Autodetect mode from filename * if mode == 'w' and isinstance(filename, str): * if filename.endswith('.gz'): # <<<<<<<<<<<<<< * mode = 'wz' * elif filename.endswith('.bcf'): */ - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_endswith); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3608, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_endswith); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4181, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__205, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3608, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__219, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4181, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3608, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 4181, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3609 + /* "pysam/libcbcf.pyx":4182 * if mode == 'w' and isinstance(filename, str): * if filename.endswith('.gz'): * mode = 'wz' # <<<<<<<<<<<<<< @@ -58561,33 +67961,33 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_INCREF(__pyx_n_s_wz); __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_wz); - /* "pysam/libcbcf.pyx":3608 + /* "pysam/libcbcf.pyx":4181 * # Autodetect mode from filename * if mode == 'w' and isinstance(filename, str): * if filename.endswith('.gz'): # <<<<<<<<<<<<<< * mode = 'wz' * elif filename.endswith('.bcf'): */ - goto __pyx_L18; + goto __pyx_L21; } - /* "pysam/libcbcf.pyx":3610 + /* "pysam/libcbcf.pyx":4183 * if filename.endswith('.gz'): * mode = 'wz' * elif filename.endswith('.bcf'): # <<<<<<<<<<<<<< * mode = 'wb' * */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_endswith); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__206, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3610, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_endswith); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__220, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4183, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3610, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 4183, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (__pyx_t_2) { + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3611 + /* "pysam/libcbcf.pyx":4184 * mode = 'wz' * elif filename.endswith('.bcf'): * mode = 'wb' # <<<<<<<<<<<<<< @@ -58597,7 +67997,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_INCREF(__pyx_n_s_wb); __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_wb); - /* "pysam/libcbcf.pyx":3610 + /* "pysam/libcbcf.pyx":4183 * if filename.endswith('.gz'): * mode = 'wz' * elif filename.endswith('.bcf'): # <<<<<<<<<<<<<< @@ -58605,9 +68005,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ * */ } - __pyx_L18:; + __pyx_L21:; - /* "pysam/libcbcf.pyx":3607 + /* "pysam/libcbcf.pyx":4180 * * # Autodetect mode from filename * if mode == 'w' and isinstance(filename, str): # <<<<<<<<<<<<<< @@ -58616,17 +68016,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3614 + /* "pysam/libcbcf.pyx":4187 * * # for htslib, wbu seems to not work * if mode == 'wbu': # <<<<<<<<<<<<<< * mode = 'wb0' * */ - __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_wbu, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3614, __pyx_L1_error) - if (__pyx_t_2) { + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_wbu, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 4187, __pyx_L1_error) + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3615 + /* "pysam/libcbcf.pyx":4188 * # for htslib, wbu seems to not work * if mode == 'wbu': * mode = 'wb0' # <<<<<<<<<<<<<< @@ -58636,7 +68036,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_INCREF(__pyx_n_s_wb0); __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_wb0); - /* "pysam/libcbcf.pyx":3614 + /* "pysam/libcbcf.pyx":4187 * * # for htslib, wbu seems to not work * if mode == 'wbu': # <<<<<<<<<<<<<< @@ -58645,14 +68045,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3617 + /* "pysam/libcbcf.pyx":4190 * mode = 'wb0' * * self.mode = mode = force_bytes(mode) # <<<<<<<<<<<<<< * try: * filename = encode_filename(filename) */ - __pyx_t_10 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_mode, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3617, __pyx_L1_error) + __pyx_t_10 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_mode, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4190, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_INCREF(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); @@ -58663,7 +68063,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_DECREF_SET(__pyx_v_mode, __pyx_t_10); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - /* "pysam/libcbcf.pyx":3618 + /* "pysam/libcbcf.pyx":4191 * * self.mode = mode = force_bytes(mode) * try: # <<<<<<<<<<<<<< @@ -58679,41 +68079,41 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_XGOTREF(__pyx_t_13); /*try:*/ { - /* "pysam/libcbcf.pyx":3619 + /* "pysam/libcbcf.pyx":4192 * self.mode = mode = force_bytes(mode) * try: * filename = encode_filename(filename) # <<<<<<<<<<<<<< * self.is_remote = hisremote(filename) * self.is_stream = filename == b'-' */ - __pyx_t_10 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3619, __pyx_L20_error) + __pyx_t_10 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4192, __pyx_L23_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF_SET(__pyx_v_filename, __pyx_t_10); __pyx_t_10 = 0; - /* "pysam/libcbcf.pyx":3620 + /* "pysam/libcbcf.pyx":4193 * try: * filename = encode_filename(filename) * self.is_remote = hisremote(filename) # <<<<<<<<<<<<<< * self.is_stream = filename == b'-' * except TypeError: */ - __pyx_t_14 = __Pyx_PyObject_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) __PYX_ERR(0, 3620, __pyx_L20_error) + __pyx_t_14 = __Pyx_PyObject_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) __PYX_ERR(0, 4193, __pyx_L23_error) __pyx_v_self->__pyx_base.is_remote = hisremote(__pyx_t_14); - /* "pysam/libcbcf.pyx":3621 + /* "pysam/libcbcf.pyx":4194 * filename = encode_filename(filename) * self.is_remote = hisremote(filename) * self.is_stream = filename == b'-' # <<<<<<<<<<<<<< * except TypeError: * filename = filename */ - __pyx_t_10 = PyObject_RichCompare(__pyx_v_filename, __pyx_kp_b__207, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3621, __pyx_L20_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3621, __pyx_L20_error) + __pyx_t_10 = PyObject_RichCompare(__pyx_v_filename, __pyx_kp_b__221, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4194, __pyx_L23_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4194, __pyx_L23_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_v_self->__pyx_base.is_stream = __pyx_t_2; + __pyx_v_self->__pyx_base.is_stream = __pyx_t_1; - /* "pysam/libcbcf.pyx":3618 + /* "pysam/libcbcf.pyx":4191 * * self.mode = mode = force_bytes(mode) * try: # <<<<<<<<<<<<<< @@ -58724,15 +68124,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - goto __pyx_L25_try_end; - __pyx_L20_error:; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L28_try_end; + __pyx_L23_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - /* "pysam/libcbcf.pyx":3622 + /* "pysam/libcbcf.pyx":4195 * self.is_remote = hisremote(filename) * self.is_stream = filename == b'-' * except TypeError: # <<<<<<<<<<<<<< @@ -58742,12 +68142,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError); if (__pyx_t_15) { __Pyx_AddTraceback("pysam.libcbcf.VariantFile.open", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_10, &__pyx_t_4, &__pyx_t_9) < 0) __PYX_ERR(0, 3622, __pyx_L22_except_error) + if (__Pyx_GetException(&__pyx_t_10, &__pyx_t_5, &__pyx_t_9) < 0) __PYX_ERR(0, 4195, __pyx_L25_except_error) __Pyx_GOTREF(__pyx_t_10); - __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_5); __Pyx_GOTREF(__pyx_t_9); - /* "pysam/libcbcf.pyx":3623 + /* "pysam/libcbcf.pyx":4196 * self.is_stream = filename == b'-' * except TypeError: * filename = filename # <<<<<<<<<<<<<< @@ -58757,7 +68157,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_INCREF(__pyx_v_filename); __Pyx_DECREF_SET(__pyx_v_filename, __pyx_v_filename); - /* "pysam/libcbcf.pyx":3624 + /* "pysam/libcbcf.pyx":4197 * except TypeError: * filename = filename * self.is_remote = False # <<<<<<<<<<<<<< @@ -58766,7 +68166,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ __pyx_v_self->__pyx_base.is_remote = 0; - /* "pysam/libcbcf.pyx":3625 + /* "pysam/libcbcf.pyx":4198 * filename = filename * self.is_remote = False * self.is_stream = True # <<<<<<<<<<<<<< @@ -58775,14 +68175,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ __pyx_v_self->__pyx_base.is_stream = 1; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L21_exception_handled; + goto __pyx_L24_exception_handled; } - goto __pyx_L22_except_error; - __pyx_L22_except_error:; + goto __pyx_L25_except_error; + __pyx_L25_except_error:; - /* "pysam/libcbcf.pyx":3618 + /* "pysam/libcbcf.pyx":4191 * * self.mode = mode = force_bytes(mode) * try: # <<<<<<<<<<<<<< @@ -58794,15 +68194,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_XGIVEREF(__pyx_t_13); __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); goto __pyx_L1_error; - __pyx_L21_exception_handled:; + __pyx_L24_exception_handled:; __Pyx_XGIVEREF(__pyx_t_11); __Pyx_XGIVEREF(__pyx_t_12); __Pyx_XGIVEREF(__pyx_t_13); __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); - __pyx_L25_try_end:; + __pyx_L28_try_end:; } - /* "pysam/libcbcf.pyx":3627 + /* "pysam/libcbcf.pyx":4200 * self.is_stream = True * * self.filename = filename # <<<<<<<<<<<<<< @@ -58815,25 +68215,25 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_DECREF(__pyx_v_self->__pyx_base.filename); __pyx_v_self->__pyx_base.filename = __pyx_v_filename; - /* "pysam/libcbcf.pyx":3629 + /* "pysam/libcbcf.pyx":4202 * self.filename = filename * * if index_filename is not None: # <<<<<<<<<<<<<< * self.index_filename = index_filename = encode_filename(index_filename) * else: */ - __pyx_t_2 = (__pyx_v_index_filename != Py_None); - __pyx_t_6 = (__pyx_t_2 != 0); + __pyx_t_1 = (__pyx_v_index_filename != Py_None); + __pyx_t_6 = (__pyx_t_1 != 0); if (__pyx_t_6) { - /* "pysam/libcbcf.pyx":3630 + /* "pysam/libcbcf.pyx":4203 * * if index_filename is not None: * self.index_filename = index_filename = encode_filename(index_filename) # <<<<<<<<<<<<<< * else: * self.index_filename = None */ - __pyx_t_9 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_index_filename); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3630, __pyx_L1_error) + __pyx_t_9 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_index_filename); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4203, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_INCREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); @@ -58844,17 +68244,17 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_DECREF_SET(__pyx_v_index_filename, __pyx_t_9); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":3629 + /* "pysam/libcbcf.pyx":4202 * self.filename = filename * * if index_filename is not None: # <<<<<<<<<<<<<< * self.index_filename = index_filename = encode_filename(index_filename) * else: */ - goto __pyx_L28; + goto __pyx_L31; } - /* "pysam/libcbcf.pyx":3632 + /* "pysam/libcbcf.pyx":4205 * self.index_filename = index_filename = encode_filename(index_filename) * else: * self.index_filename = None # <<<<<<<<<<<<<< @@ -58868,19 +68268,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_DECREF(__pyx_v_self->__pyx_base.index_filename); __pyx_v_self->__pyx_base.index_filename = Py_None; } - __pyx_L28:; + __pyx_L31:; - /* "pysam/libcbcf.pyx":3634 + /* "pysam/libcbcf.pyx":4207 * self.index_filename = None * * self.drop_samples = bool(drop_samples) # <<<<<<<<<<<<<< * self.header = None * */ - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_drop_samples); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 3634, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_drop_samples); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 4207, __pyx_L1_error) __pyx_v_self->drop_samples = (!(!__pyx_t_6)); - /* "pysam/libcbcf.pyx":3635 + /* "pysam/libcbcf.pyx":4208 * * self.drop_samples = bool(drop_samples) * self.header = None # <<<<<<<<<<<<<< @@ -58893,7 +68293,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); __pyx_v_self->header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)Py_None); - /* "pysam/libcbcf.pyx":3637 + /* "pysam/libcbcf.pyx":4210 * self.header = None * * self.header_written = False # <<<<<<<<<<<<<< @@ -58902,23 +68302,23 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ __pyx_v_self->header_written = 0; - /* "pysam/libcbcf.pyx":3639 + /* "pysam/libcbcf.pyx":4212 * self.header_written = False * * if mode.startswith(b'w'): # <<<<<<<<<<<<<< * # open file for writing * if index_filename is not None: */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_mode, __pyx_n_s_startswith); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3639, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_mode, __pyx_n_s_startswith); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4212, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__208, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3639, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__222, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4212, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 3639, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 4212, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_6) { - /* "pysam/libcbcf.pyx":3641 + /* "pysam/libcbcf.pyx":4214 * if mode.startswith(b'w'): * # open file for writing * if index_filename is not None: # <<<<<<<<<<<<<< @@ -58926,23 +68326,23 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ * */ __pyx_t_6 = (__pyx_v_index_filename != Py_None); - __pyx_t_2 = (__pyx_t_6 != 0); - if (unlikely(__pyx_t_2)) { + __pyx_t_1 = (__pyx_t_6 != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3642 + /* "pysam/libcbcf.pyx":4215 * # open file for writing * if index_filename is not None: * raise ValueError('Cannot specify an index filename when writing a VCF/BCF file') # <<<<<<<<<<<<<< * * # header structure (used for writing) */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__209, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3642, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 3642, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__223, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4215, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __PYX_ERR(0, 4215, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3641 + /* "pysam/libcbcf.pyx":4214 * if mode.startswith(b'w'): * # open file for writing * if index_filename is not None: # <<<<<<<<<<<<<< @@ -58951,24 +68351,24 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3645 + /* "pysam/libcbcf.pyx":4218 * * # header structure (used for writing) * if header: # <<<<<<<<<<<<<< * self.header = header.copy() * else: */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3645, __pyx_L1_error) - if (__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_header)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 4218, __pyx_L1_error) + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3646 + /* "pysam/libcbcf.pyx":4219 * # header structure (used for writing) * if header: * self.header = header.copy() # <<<<<<<<<<<<<< * else: * self.header = VariantHeader() */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_header), __pyx_n_s_copy); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3646, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_header), __pyx_n_s_copy); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { @@ -58981,31 +68381,31 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ } } if (__pyx_t_10) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3646, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4219, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else { - __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3646, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4219, __pyx_L1_error) } - __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(0, 3646, __pyx_L1_error) - __Pyx_GIVEREF(__pyx_t_4); + if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(0, 4219, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_5); __Pyx_GOTREF(__pyx_v_self->header); __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); - __pyx_v_self->header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_4); - __pyx_t_4 = 0; + __pyx_v_self->header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_5); + __pyx_t_5 = 0; - /* "pysam/libcbcf.pyx":3645 + /* "pysam/libcbcf.pyx":4218 * * # header structure (used for writing) * if header: # <<<<<<<<<<<<<< * self.header = header.copy() * else: */ - goto __pyx_L31; + goto __pyx_L34; } - /* "pysam/libcbcf.pyx":3648 + /* "pysam/libcbcf.pyx":4221 * self.header = header.copy() * else: * self.header = VariantHeader() # <<<<<<<<<<<<<< @@ -59013,44 +68413,44 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ * */ /*else*/ { - __pyx_t_4 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeader)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3648, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeader)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4221, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); __Pyx_GOTREF(__pyx_v_self->header); __Pyx_DECREF(((PyObject *)__pyx_v_self->header)); - __pyx_v_self->header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_4); - __pyx_t_4 = 0; + __pyx_v_self->header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_5); + __pyx_t_5 = 0; } - __pyx_L31:; + __pyx_L34:; - /* "pysam/libcbcf.pyx":3652 + /* "pysam/libcbcf.pyx":4225 * * # Header is not written until the first write or on close * self.htsfile = self._open_htsfile() # <<<<<<<<<<<<<< * * if not self.htsfile: */ - __pyx_t_16 = ((struct __pyx_vtabstruct_5pysam_7libcbcf_VariantFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_16 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 3652, __pyx_L1_error) + __pyx_t_16 = ((struct __pyx_vtabstruct_5pysam_7libcbcf_VariantFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_16 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 4225, __pyx_L1_error) __pyx_v_self->__pyx_base.htsfile = __pyx_t_16; - /* "pysam/libcbcf.pyx":3654 + /* "pysam/libcbcf.pyx":4227 * self.htsfile = self._open_htsfile() * * if not self.htsfile: # <<<<<<<<<<<<<< * raise ValueError("could not open file `{}` (mode='{}')".format(filename, mode)) * */ - __pyx_t_2 = ((!(__pyx_v_self->__pyx_base.htsfile != 0)) != 0); - if (unlikely(__pyx_t_2)) { + __pyx_t_1 = ((!(__pyx_v_self->__pyx_base.htsfile != 0)) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3655 + /* "pysam/libcbcf.pyx":4228 * * if not self.htsfile: * raise ValueError("could not open file `{}` (mode='{}')".format(filename, mode)) # <<<<<<<<<<<<<< * * elif mode.startswith(b'r'): */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_file_mode, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3655, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_file_mode, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4228, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = NULL; __pyx_t_15 = 0; @@ -59067,44 +68467,44 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_9)) { PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_filename, __pyx_v_mode}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3655, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4228, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_5); } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_filename, __pyx_v_mode}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3655, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4228, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_5); } else #endif { - __pyx_t_1 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3655, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); if (__pyx_t_10) { - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_10); __pyx_t_10 = NULL; } __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_15, __pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_15, __pyx_v_filename); __Pyx_INCREF(__pyx_v_mode); __Pyx_GIVEREF(__pyx_v_mode); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_15, __pyx_v_mode); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3655, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_15, __pyx_v_mode); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3655, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4228, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_Raise(__pyx_t_9, 0, 0, 0); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __PYX_ERR(0, 3655, __pyx_L1_error) + __PYX_ERR(0, 4228, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3654 + /* "pysam/libcbcf.pyx":4227 * self.htsfile = self._open_htsfile() * * if not self.htsfile: # <<<<<<<<<<<<<< @@ -59113,470 +68513,364 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3639 + /* "pysam/libcbcf.pyx":4212 * self.header_written = False * * if mode.startswith(b'w'): # <<<<<<<<<<<<<< * # open file for writing * if index_filename is not None: */ - goto __pyx_L29; + goto __pyx_L32; } - /* "pysam/libcbcf.pyx":3657 + /* "pysam/libcbcf.pyx":4230 * raise ValueError("could not open file `{}` (mode='{}')".format(filename, mode)) * * elif mode.startswith(b'r'): # <<<<<<<<<<<<<< * # open file for reading - * + * self.htsfile = self._open_htsfile() */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_mode, __pyx_n_s_startswith); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3657, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_mode, __pyx_n_s_startswith); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4230, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__210, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3657, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__224, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4230, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3657, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (likely(__pyx_t_2)) { + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 4230, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (likely(__pyx_t_1)) { - /* "pysam/libcbcf.pyx":3660 + /* "pysam/libcbcf.pyx":4232 + * elif mode.startswith(b'r'): * # open file for reading + * self.htsfile = self._open_htsfile() # <<<<<<<<<<<<<< * - * if not self._exists(): # <<<<<<<<<<<<<< - * raise IOError('file `{}` not found'.format(filename)) + * if not self.htsfile: + */ + __pyx_t_16 = ((struct __pyx_vtabstruct_5pysam_7libcbcf_VariantFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_16 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 4232, __pyx_L1_error) + __pyx_v_self->__pyx_base.htsfile = __pyx_t_16; + + /* "pysam/libcbcf.pyx":4234 + * self.htsfile = self._open_htsfile() * + * if not self.htsfile: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, 'could not open variant file `{}`: {}'.format(filename, force_str(strerror(errno)))) */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_exists); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - } - } + __pyx_t_1 = ((!(__pyx_v_self->__pyx_base.htsfile != 0)) != 0); if (__pyx_t_1) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3660, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3660, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3660, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_6 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_6)) { - /* "pysam/libcbcf.pyx":3661 + /* "pysam/libcbcf.pyx":4235 * - * if not self._exists(): - * raise IOError('file `{}` not found'.format(filename)) # <<<<<<<<<<<<<< - * - * self.htsfile = self._open_htsfile() + * if not self.htsfile: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, 'could not open variant file `{}`: {}'.format(filename, force_str(strerror(errno)))) + * else: */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_file_not_found, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3661, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - } - } - if (!__pyx_t_1) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_filename); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3661, __pyx_L1_error) + __pyx_t_1 = (errno != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbcf.pyx":4236 + * if not self.htsfile: + * if errno: + * raise IOError(errno, 'could not open variant file `{}`: {}'.format(filename, force_str(strerror(errno)))) # <<<<<<<<<<<<<< + * else: + * raise ValueError('could not open variant file `{}`'.format(filename)) + */ + __pyx_t_5 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4236, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_variant_file, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4236, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 4236, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4236, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - } else { + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = NULL; + __pyx_t_15 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_15 = 1; + } + } #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_filename}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3661, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_4); + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_filename, __pyx_t_4}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4236, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_filename}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3661, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_4); + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_filename, __pyx_t_4}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4236, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3661, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); __pyx_t_1 = NULL; + __pyx_t_17 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 4236, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_17); + if (__pyx_t_10) { + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_10); __pyx_t_10 = NULL; + } __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); - PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_filename); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3661, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_15, __pyx_v_filename); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_15, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_17, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4236, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; } - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3661, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_9, 0, 0, 0); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __PYX_ERR(0, 3661, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":3660 - * # open file for reading - * - * if not self._exists(): # <<<<<<<<<<<<<< - * raise IOError('file `{}` not found'.format(filename)) - * - */ - } - - /* "pysam/libcbcf.pyx":3663 - * raise IOError('file `{}` not found'.format(filename)) - * - * self.htsfile = self._open_htsfile() # <<<<<<<<<<<<<< - * - * if not self.htsfile: - */ - __pyx_t_16 = ((struct __pyx_vtabstruct_5pysam_7libcbcf_VariantFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_16 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 3663, __pyx_L1_error) - __pyx_v_self->__pyx_base.htsfile = __pyx_t_16; - - /* "pysam/libcbcf.pyx":3665 - * self.htsfile = self._open_htsfile() - * - * if not self.htsfile: # <<<<<<<<<<<<<< - * raise ValueError("could not open file `{}` (mode='{}') - is it VCF/BCF format?".format(filename, mode)) - * - */ - __pyx_t_6 = ((!(__pyx_v_self->__pyx_base.htsfile != 0)) != 0); - if (unlikely(__pyx_t_6)) { + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4236, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_9); + __pyx_t_5 = 0; + __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4236, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 4236, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3666 + /* "pysam/libcbcf.pyx":4235 * * if not self.htsfile: - * raise ValueError("could not open file `{}` (mode='{}') - is it VCF/BCF format?".format(filename, mode)) # <<<<<<<<<<<<<< - * - * if self.htsfile.format.format not in (bcf, vcf): + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, 'could not open variant file `{}`: {}'.format(filename, force_str(strerror(errno)))) + * else: */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_file_mode_is_it_V, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3666, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_10 = NULL; - __pyx_t_15 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - __pyx_t_15 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_filename, __pyx_v_mode}; - __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3666, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_9); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_filename, __pyx_v_mode}; - __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3666, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_9); - } else - #endif - { - __pyx_t_1 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3666, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (__pyx_t_10) { - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_10); __pyx_t_10 = NULL; - } - __Pyx_INCREF(__pyx_v_filename); - __Pyx_GIVEREF(__pyx_v_filename); - PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_15, __pyx_v_filename); - __Pyx_INCREF(__pyx_v_mode); - __Pyx_GIVEREF(__pyx_v_mode); - PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_15, __pyx_v_mode); - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3666, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3666, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 3666, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":3665 - * self.htsfile = self._open_htsfile() - * - * if not self.htsfile: # <<<<<<<<<<<<<< - * raise ValueError("could not open file `{}` (mode='{}') - is it VCF/BCF format?".format(filename, mode)) - * - */ - } - /* "pysam/libcbcf.pyx":3668 - * raise ValueError("could not open file `{}` (mode='{}') - is it VCF/BCF format?".format(filename, mode)) - * - * if self.htsfile.format.format not in (bcf, vcf): # <<<<<<<<<<<<<< - * raise ValueError("invalid file `{}` (mode='{}') - is it VCF/BCF format?".format(filename, mode)) - * - */ - switch (__pyx_v_self->__pyx_base.htsfile->format.format) { - case bcf: - case vcf: - __pyx_t_6 = 0; - break; - default: - __pyx_t_6 = 1; - break; - } - __pyx_t_2 = (__pyx_t_6 != 0); - if (unlikely(__pyx_t_2)) { - - /* "pysam/libcbcf.pyx":3669 + /* "pysam/libcbcf.pyx":4238 + * raise IOError(errno, 'could not open variant file `{}`: {}'.format(filename, force_str(strerror(errno)))) + * else: + * raise ValueError('could not open variant file `{}`'.format(filename)) # <<<<<<<<<<<<<< * * if self.htsfile.format.format not in (bcf, vcf): - * raise ValueError("invalid file `{}` (mode='{}') - is it VCF/BCF format?".format(filename, mode)) # <<<<<<<<<<<<<< - * - * if self.htsfile.format.compression == bgzf: - */ - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_file_mode_is_it_VCF_BCF, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = NULL; - __pyx_t_15 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - __pyx_t_15 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_filename, __pyx_v_mode}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3669, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_filename, __pyx_v_mode}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3669, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else - #endif - { - __pyx_t_10 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - if (__pyx_t_1) { - __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); __pyx_t_1 = NULL; - } - __Pyx_INCREF(__pyx_v_filename); - __Pyx_GIVEREF(__pyx_v_filename); - PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_15, __pyx_v_filename); - __Pyx_INCREF(__pyx_v_mode); - __Pyx_GIVEREF(__pyx_v_mode); - PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_15, __pyx_v_mode); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_9, 0, 0, 0); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __PYX_ERR(0, 3669, __pyx_L1_error) - - /* "pysam/libcbcf.pyx":3668 - * raise ValueError("could not open file `{}` (mode='{}') - is it VCF/BCF format?".format(filename, mode)) - * - * if self.htsfile.format.format not in (bcf, vcf): # <<<<<<<<<<<<<< - * raise ValueError("invalid file `{}` (mode='{}') - is it VCF/BCF format?".format(filename, mode)) - * - */ - } - - /* "pysam/libcbcf.pyx":3671 - * raise ValueError("invalid file `{}` (mode='{}') - is it VCF/BCF format?".format(filename, mode)) - * - * if self.htsfile.format.compression == bgzf: # <<<<<<<<<<<<<< - * bgzfp = hts_get_bgzfp(self.htsfile) - * if bgzfp and bgzf_check_EOF(bgzfp) == 0: - */ - __pyx_t_2 = ((__pyx_v_self->__pyx_base.htsfile->format.compression == bgzf) != 0); - if (__pyx_t_2) { - - /* "pysam/libcbcf.pyx":3672 - * - * if self.htsfile.format.compression == bgzf: - * bgzfp = hts_get_bgzfp(self.htsfile) # <<<<<<<<<<<<<< - * if bgzfp and bgzf_check_EOF(bgzfp) == 0: - * warn('[%s] Warning: no BGZF EOF marker; file may be truncated'.format(filename)) - */ - __pyx_v_bgzfp = hts_get_bgzfp(__pyx_v_self->__pyx_base.htsfile); - - /* "pysam/libcbcf.pyx":3673 - * if self.htsfile.format.compression == bgzf: - * bgzfp = hts_get_bgzfp(self.htsfile) - * if bgzfp and bgzf_check_EOF(bgzfp) == 0: # <<<<<<<<<<<<<< - * warn('[%s] Warning: no BGZF EOF marker; file may be truncated'.format(filename)) - * - */ - __pyx_t_6 = (__pyx_v_bgzfp != 0); - if (__pyx_t_6) { - } else { - __pyx_t_2 = __pyx_t_6; - goto __pyx_L38_bool_binop_done; - } - __pyx_t_6 = ((bgzf_check_EOF(__pyx_v_bgzfp) == 0) != 0); - __pyx_t_2 = __pyx_t_6; - __pyx_L38_bool_binop_done:; - if (__pyx_t_2) { - - /* "pysam/libcbcf.pyx":3674 - * bgzfp = hts_get_bgzfp(self.htsfile) - * if bgzfp and bgzf_check_EOF(bgzfp) == 0: - * warn('[%s] Warning: no BGZF EOF marker; file may be truncated'.format(filename)) # <<<<<<<<<<<<<< - * - * with nogil: */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_warn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_s_Warning_no_BGZF_EOF_marker_fi, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - if (!__pyx_t_3) { - __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_filename); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_filename}; - __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3674, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_10); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_filename}; - __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3674, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_10); - } else - #endif - { - __pyx_t_17 = PyTuple_New(1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 3674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_17); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_INCREF(__pyx_v_filename); - __Pyx_GIVEREF(__pyx_v_filename); - PyTuple_SET_ITEM(__pyx_t_17, 0+1, __pyx_v_filename); - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_17, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - } - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_1)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_1); + /*else*/ { + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_variant_file_2, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); + __Pyx_DECREF_SET(__pyx_t_2, function); } } - if (!__pyx_t_1) { - __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3674, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (!__pyx_t_5) { + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filename); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4238, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_10}; - __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3674, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_filename}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_10}; - __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3674, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_filename}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else #endif { - __pyx_t_17 = PyTuple_New(1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 3674, __pyx_L1_error) + __pyx_t_17 = PyTuple_New(1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 4238, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_17); - __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_1); __pyx_t_1 = NULL; - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_17, 0+1, __pyx_t_10); - __pyx_t_10 = 0; - __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_17, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3674, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_17, 0+1, __pyx_v_filename); + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_17, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4238, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; } } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4238, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 4238, __pyx_L1_error) + } + + /* "pysam/libcbcf.pyx":4234 + * self.htsfile = self._open_htsfile() + * + * if not self.htsfile: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, 'could not open variant file `{}`: {}'.format(filename, force_str(strerror(errno)))) + */ + } + + /* "pysam/libcbcf.pyx":4240 + * raise ValueError('could not open variant file `{}`'.format(filename)) + * + * if self.htsfile.format.format not in (bcf, vcf): # <<<<<<<<<<<<<< + * raise ValueError('invalid file `{}` (mode=`{}`) - is it VCF/BCF format?'.format(filename, mode)) + * + */ + switch (__pyx_v_self->__pyx_base.htsfile->format.format) { + case bcf: + case vcf: + __pyx_t_1 = 0; + break; + default: + __pyx_t_1 = 1; + break; + } + __pyx_t_6 = (__pyx_t_1 != 0); + if (unlikely(__pyx_t_6)) { - /* "pysam/libcbcf.pyx":3673 - * if self.htsfile.format.compression == bgzf: - * bgzfp = hts_get_bgzfp(self.htsfile) - * if bgzfp and bgzf_check_EOF(bgzfp) == 0: # <<<<<<<<<<<<<< - * warn('[%s] Warning: no BGZF EOF marker; file may be truncated'.format(filename)) + /* "pysam/libcbcf.pyx":4241 + * + * if self.htsfile.format.format not in (bcf, vcf): + * raise ValueError('invalid file `{}` (mode=`{}`) - is it VCF/BCF format?'.format(filename, mode)) # <<<<<<<<<<<<<< * + * self.check_truncation(ignore_truncation) */ + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_invalid_file_mode_is_it_VCF_BCF, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4241, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_17 = NULL; + __pyx_t_15 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_17)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_17); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_15 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_17, __pyx_v_filename, __pyx_v_mode}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4241, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_17, __pyx_v_filename, __pyx_v_mode}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4241, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_5 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4241, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_17) { + __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_17); __pyx_t_17 = NULL; + } + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_15, __pyx_v_filename); + __Pyx_INCREF(__pyx_v_mode); + __Pyx_GIVEREF(__pyx_v_mode); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_15, __pyx_v_mode); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4241, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4241, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __PYX_ERR(0, 4241, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":4240 + * raise ValueError('could not open variant file `{}`'.format(filename)) + * + * if self.htsfile.format.format not in (bcf, vcf): # <<<<<<<<<<<<<< + * raise ValueError('invalid file `{}` (mode=`{}`) - is it VCF/BCF format?'.format(filename, mode)) + * + */ + } - /* "pysam/libcbcf.pyx":3671 - * raise ValueError("invalid file `{}` (mode='{}') - is it VCF/BCF format?".format(filename, mode)) + /* "pysam/libcbcf.pyx":4243 + * raise ValueError('invalid file `{}` (mode=`{}`) - is it VCF/BCF format?'.format(filename, mode)) * - * if self.htsfile.format.compression == bgzf: # <<<<<<<<<<<<<< - * bgzfp = hts_get_bgzfp(self.htsfile) - * if bgzfp and bgzf_check_EOF(bgzfp) == 0: + * self.check_truncation(ignore_truncation) # <<<<<<<<<<<<<< + * + * with nogil: */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_truncation); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4243, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_5) { + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_ignore_truncation); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4243, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_ignore_truncation}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4243, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_ignore_truncation}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4243, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + { + __pyx_t_17 = PyTuple_New(1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 4243, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_ignore_truncation); + __Pyx_GIVEREF(__pyx_v_ignore_truncation); + PyTuple_SET_ITEM(__pyx_t_17, 0+1, __pyx_v_ignore_truncation); + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_17, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4243, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + } } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":3676 - * warn('[%s] Warning: no BGZF EOF marker; file may be truncated'.format(filename)) + /* "pysam/libcbcf.pyx":4245 + * self.check_truncation(ignore_truncation) * * with nogil: # <<<<<<<<<<<<<< * hdr = bcf_hdr_read(self.htsfile) @@ -59590,7 +68884,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ #endif /*try:*/ { - /* "pysam/libcbcf.pyx":3677 + /* "pysam/libcbcf.pyx":4246 * * with nogil: * hdr = bcf_hdr_read(self.htsfile) # <<<<<<<<<<<<<< @@ -59600,8 +68894,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __pyx_v_hdr = bcf_hdr_read(__pyx_v_self->__pyx_base.htsfile); } - /* "pysam/libcbcf.pyx":3676 - * warn('[%s] Warning: no BGZF EOF marker; file may be truncated'.format(filename)) + /* "pysam/libcbcf.pyx":4245 + * self.check_truncation(ignore_truncation) * * with nogil: # <<<<<<<<<<<<<< * hdr = bcf_hdr_read(self.htsfile) @@ -59613,13 +68907,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif - goto __pyx_L42; + goto __pyx_L41; } - __pyx_L42:; + __pyx_L41:; } } - /* "pysam/libcbcf.pyx":3679 + /* "pysam/libcbcf.pyx":4248 * hdr = bcf_hdr_read(self.htsfile) * * try: # <<<<<<<<<<<<<< @@ -59635,14 +68929,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_XGOTREF(__pyx_t_11); /*try:*/ { - /* "pysam/libcbcf.pyx":3680 + /* "pysam/libcbcf.pyx":4249 * * try: * self.header = makeVariantHeader(hdr) # <<<<<<<<<<<<<< * except ValueError: - * raise ValueError("file `{}` does not have valid header (mode='{}') - is it VCF/BCF format?".format(filename, mode)) + * raise ValueError('file `{}` does not have valid header (mode=`{}`) - is it VCF/BCF format?'.format(filename, mode)) */ - __pyx_t_9 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3680, __pyx_L43_error) + __pyx_t_9 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeVariantHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4249, __pyx_L42_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __Pyx_GOTREF(__pyx_v_self->header); @@ -59650,7 +68944,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __pyx_v_self->header = ((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_9); __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":3679 + /* "pysam/libcbcf.pyx":4248 * hdr = bcf_hdr_read(self.htsfile) * * try: # <<<<<<<<<<<<<< @@ -59661,72 +68955,72 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L48_try_end; - __pyx_L43_error:; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L47_try_end; + __pyx_L42_error:; __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - /* "pysam/libcbcf.pyx":3681 + /* "pysam/libcbcf.pyx":4250 * try: * self.header = makeVariantHeader(hdr) * except ValueError: # <<<<<<<<<<<<<< - * raise ValueError("file `{}` does not have valid header (mode='{}') - is it VCF/BCF format?".format(filename, mode)) + * raise ValueError('file `{}` does not have valid header (mode=`{}`) - is it VCF/BCF format?'.format(filename, mode)) * */ __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError); if (__pyx_t_15) { __Pyx_AddTraceback("pysam.libcbcf.VariantFile.open", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_4, &__pyx_t_17) < 0) __PYX_ERR(0, 3681, __pyx_L45_except_error) + if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_2, &__pyx_t_17) < 0) __PYX_ERR(0, 4250, __pyx_L44_except_error) __Pyx_GOTREF(__pyx_t_9); - __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_2); __Pyx_GOTREF(__pyx_t_17); - /* "pysam/libcbcf.pyx":3682 + /* "pysam/libcbcf.pyx":4251 * self.header = makeVariantHeader(hdr) * except ValueError: - * raise ValueError("file `{}` does not have valid header (mode='{}') - is it VCF/BCF format?".format(filename, mode)) # <<<<<<<<<<<<<< + * raise ValueError('file `{}` does not have valid header (mode=`{}`) - is it VCF/BCF format?'.format(filename, mode)) # <<<<<<<<<<<<<< * * if isinstance(self.filename, bytes): */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_file_does_not_have_valid_header, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3682, __pyx_L45_except_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = NULL; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_file_does_not_have_valid_header, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4251, __pyx_L44_except_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_10 = NULL; __pyx_t_15 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_3); + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); + __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_15 = 1; } } #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_filename, __pyx_v_mode}; - __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3682, __pyx_L45_except_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_10); + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_filename, __pyx_v_mode}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4251, __pyx_L44_except_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_5); } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_filename, __pyx_v_mode}; - __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3682, __pyx_L45_except_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_filename, __pyx_v_mode}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4251, __pyx_L44_except_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_5); } else #endif { - __pyx_t_18 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 3682, __pyx_L45_except_error) + __pyx_t_18 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 4251, __pyx_L44_except_error) __Pyx_GOTREF(__pyx_t_18); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_3); __pyx_t_3 = NULL; + if (__pyx_t_10) { + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_10); __pyx_t_10 = NULL; } __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); @@ -59734,22 +69028,22 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_INCREF(__pyx_v_mode); __Pyx_GIVEREF(__pyx_v_mode); PyTuple_SET_ITEM(__pyx_t_18, 1+__pyx_t_15, __pyx_v_mode); - __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_18, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 3682, __pyx_L45_except_error) - __Pyx_GOTREF(__pyx_t_10); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_18, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4251, __pyx_L44_except_error) + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3682, __pyx_L45_except_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3682, __pyx_L45_except_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4251, __pyx_L44_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 4251, __pyx_L44_except_error) } - goto __pyx_L45_except_error; - __pyx_L45_except_error:; + goto __pyx_L44_except_error; + __pyx_L44_except_error:; - /* "pysam/libcbcf.pyx":3679 + /* "pysam/libcbcf.pyx":4248 * hdr = bcf_hdr_read(self.htsfile) * * try: # <<<<<<<<<<<<<< @@ -59761,11 +69055,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_XGIVEREF(__pyx_t_11); __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_12, __pyx_t_11); goto __pyx_L1_error; - __pyx_L48_try_end:; + __pyx_L47_try_end:; } - /* "pysam/libcbcf.pyx":3684 - * raise ValueError("file `{}` does not have valid header (mode='{}') - is it VCF/BCF format?".format(filename, mode)) + /* "pysam/libcbcf.pyx":4253 + * raise ValueError('file `{}` does not have valid header (mode=`{}`) - is it VCF/BCF format?'.format(filename, mode)) * * if isinstance(self.filename, bytes): # <<<<<<<<<<<<<< * cfilename = self.filename @@ -59773,32 +69067,32 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ __pyx_t_17 = __pyx_v_self->__pyx_base.filename; __Pyx_INCREF(__pyx_t_17); - __pyx_t_2 = PyBytes_Check(__pyx_t_17); + __pyx_t_6 = PyBytes_Check(__pyx_t_17); __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - __pyx_t_6 = (__pyx_t_2 != 0); - if (__pyx_t_6) { + __pyx_t_1 = (__pyx_t_6 != 0); + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3685 + /* "pysam/libcbcf.pyx":4254 * * if isinstance(self.filename, bytes): * cfilename = self.filename # <<<<<<<<<<<<<< * else: * cfilename = NULL */ - __pyx_t_19 = __Pyx_PyObject_AsWritableString(__pyx_v_self->__pyx_base.filename); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 3685, __pyx_L1_error) + __pyx_t_19 = __Pyx_PyObject_AsWritableString(__pyx_v_self->__pyx_base.filename); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 4254, __pyx_L1_error) __pyx_v_cfilename = __pyx_t_19; - /* "pysam/libcbcf.pyx":3684 - * raise ValueError("file `{}` does not have valid header (mode='{}') - is it VCF/BCF format?".format(filename, mode)) + /* "pysam/libcbcf.pyx":4253 + * raise ValueError('file `{}` does not have valid header (mode=`{}`) - is it VCF/BCF format?'.format(filename, mode)) * * if isinstance(self.filename, bytes): # <<<<<<<<<<<<<< * cfilename = self.filename * else: */ - goto __pyx_L51; + goto __pyx_L50; } - /* "pysam/libcbcf.pyx":3687 + /* "pysam/libcbcf.pyx":4256 * cfilename = self.filename * else: * cfilename = NULL # <<<<<<<<<<<<<< @@ -59808,48 +69102,48 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ /*else*/ { __pyx_v_cfilename = NULL; } - __pyx_L51:; + __pyx_L50:; - /* "pysam/libcbcf.pyx":3690 + /* "pysam/libcbcf.pyx":4259 * * # check for index and open if present * if self.htsfile.format.format == bcf and cfilename: # <<<<<<<<<<<<<< * if index_filename is not None: * cindex_filename = index_filename */ - __pyx_t_2 = ((__pyx_v_self->__pyx_base.htsfile->format.format == bcf) != 0); - if (__pyx_t_2) { + __pyx_t_6 = ((__pyx_v_self->__pyx_base.htsfile->format.format == bcf) != 0); + if (__pyx_t_6) { } else { - __pyx_t_6 = __pyx_t_2; - goto __pyx_L53_bool_binop_done; + __pyx_t_1 = __pyx_t_6; + goto __pyx_L52_bool_binop_done; } - __pyx_t_2 = (__pyx_v_cfilename != 0); - __pyx_t_6 = __pyx_t_2; - __pyx_L53_bool_binop_done:; - if (__pyx_t_6) { + __pyx_t_6 = (__pyx_v_cfilename != 0); + __pyx_t_1 = __pyx_t_6; + __pyx_L52_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3691 + /* "pysam/libcbcf.pyx":4260 * # check for index and open if present * if self.htsfile.format.format == bcf and cfilename: * if index_filename is not None: # <<<<<<<<<<<<<< * cindex_filename = index_filename * with nogil: */ - __pyx_t_6 = (__pyx_v_index_filename != Py_None); - __pyx_t_2 = (__pyx_t_6 != 0); - if (__pyx_t_2) { + __pyx_t_1 = (__pyx_v_index_filename != Py_None); + __pyx_t_6 = (__pyx_t_1 != 0); + if (__pyx_t_6) { - /* "pysam/libcbcf.pyx":3692 + /* "pysam/libcbcf.pyx":4261 * if self.htsfile.format.format == bcf and cfilename: * if index_filename is not None: * cindex_filename = index_filename # <<<<<<<<<<<<<< * with nogil: * idx = bcf_index_load2(cfilename, cindex_filename) */ - __pyx_t_19 = __Pyx_PyObject_AsWritableString(__pyx_v_index_filename); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 3692, __pyx_L1_error) + __pyx_t_19 = __Pyx_PyObject_AsWritableString(__pyx_v_index_filename); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 4261, __pyx_L1_error) __pyx_v_cindex_filename = __pyx_t_19; - /* "pysam/libcbcf.pyx":3691 + /* "pysam/libcbcf.pyx":4260 * # check for index and open if present * if self.htsfile.format.format == bcf and cfilename: * if index_filename is not None: # <<<<<<<<<<<<<< @@ -59858,7 +69152,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3693 + /* "pysam/libcbcf.pyx":4262 * if index_filename is not None: * cindex_filename = index_filename * with nogil: # <<<<<<<<<<<<<< @@ -59873,7 +69167,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ #endif /*try:*/ { - /* "pysam/libcbcf.pyx":3694 + /* "pysam/libcbcf.pyx":4263 * cindex_filename = index_filename * with nogil: * idx = bcf_index_load2(cfilename, cindex_filename) # <<<<<<<<<<<<<< @@ -59883,7 +69177,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __pyx_v_idx = bcf_index_load2(__pyx_v_cfilename, __pyx_v_cindex_filename); } - /* "pysam/libcbcf.pyx":3693 + /* "pysam/libcbcf.pyx":4262 * if index_filename is not None: * cindex_filename = index_filename * with nogil: # <<<<<<<<<<<<<< @@ -59896,13 +69190,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif - goto __pyx_L58; + goto __pyx_L57; } - __pyx_L58:; + __pyx_L57:; } } - /* "pysam/libcbcf.pyx":3695 + /* "pysam/libcbcf.pyx":4264 * with nogil: * idx = bcf_index_load2(cfilename, cindex_filename) * self.index = makeBCFIndex(self.header, idx) # <<<<<<<<<<<<<< @@ -59911,65 +69205,65 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ __pyx_t_17 = ((PyObject *)__pyx_v_self->header); __Pyx_INCREF(__pyx_t_17); - __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeBCFIndex(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_17), __pyx_v_idx)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3695, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeBCFIndex(((struct __pyx_obj_5pysam_7libcbcf_VariantHeader *)__pyx_t_17), __pyx_v_idx)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4264, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_self->index); __Pyx_DECREF(((PyObject *)__pyx_v_self->index)); - __pyx_v_self->index = ((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_t_4); - __pyx_t_4 = 0; + __pyx_v_self->index = ((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":3690 + /* "pysam/libcbcf.pyx":4259 * * # check for index and open if present * if self.htsfile.format.format == bcf and cfilename: # <<<<<<<<<<<<<< * if index_filename is not None: * cindex_filename = index_filename */ - goto __pyx_L52; + goto __pyx_L51; } - /* "pysam/libcbcf.pyx":3697 + /* "pysam/libcbcf.pyx":4266 * self.index = makeBCFIndex(self.header, idx) * * elif self.htsfile.format.compression == bgzf and cfilename: # <<<<<<<<<<<<<< * if index_filename is not None: * cindex_filename = index_filename */ - __pyx_t_6 = ((__pyx_v_self->__pyx_base.htsfile->format.compression == bgzf) != 0); - if (__pyx_t_6) { + __pyx_t_1 = ((__pyx_v_self->__pyx_base.htsfile->format.compression == bgzf) != 0); + if (__pyx_t_1) { } else { - __pyx_t_2 = __pyx_t_6; - goto __pyx_L59_bool_binop_done; + __pyx_t_6 = __pyx_t_1; + goto __pyx_L58_bool_binop_done; } - __pyx_t_6 = (__pyx_v_cfilename != 0); - __pyx_t_2 = __pyx_t_6; - __pyx_L59_bool_binop_done:; - if (__pyx_t_2) { + __pyx_t_1 = (__pyx_v_cfilename != 0); + __pyx_t_6 = __pyx_t_1; + __pyx_L58_bool_binop_done:; + if (__pyx_t_6) { - /* "pysam/libcbcf.pyx":3698 + /* "pysam/libcbcf.pyx":4267 * * elif self.htsfile.format.compression == bgzf and cfilename: * if index_filename is not None: # <<<<<<<<<<<<<< * cindex_filename = index_filename * with nogil: */ - __pyx_t_2 = (__pyx_v_index_filename != Py_None); - __pyx_t_6 = (__pyx_t_2 != 0); - if (__pyx_t_6) { + __pyx_t_6 = (__pyx_v_index_filename != Py_None); + __pyx_t_1 = (__pyx_t_6 != 0); + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3699 + /* "pysam/libcbcf.pyx":4268 * elif self.htsfile.format.compression == bgzf and cfilename: * if index_filename is not None: * cindex_filename = index_filename # <<<<<<<<<<<<<< * with nogil: * tidx = tbx_index_load2(cfilename, cindex_filename) */ - __pyx_t_19 = __Pyx_PyObject_AsWritableString(__pyx_v_index_filename); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 3699, __pyx_L1_error) + __pyx_t_19 = __Pyx_PyObject_AsWritableString(__pyx_v_index_filename); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) __PYX_ERR(0, 4268, __pyx_L1_error) __pyx_v_cindex_filename = __pyx_t_19; - /* "pysam/libcbcf.pyx":3698 + /* "pysam/libcbcf.pyx":4267 * * elif self.htsfile.format.compression == bgzf and cfilename: * if index_filename is not None: # <<<<<<<<<<<<<< @@ -59978,7 +69272,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3700 + /* "pysam/libcbcf.pyx":4269 * if index_filename is not None: * cindex_filename = index_filename * with nogil: # <<<<<<<<<<<<<< @@ -59993,7 +69287,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ #endif /*try:*/ { - /* "pysam/libcbcf.pyx":3701 + /* "pysam/libcbcf.pyx":4270 * cindex_filename = index_filename * with nogil: * tidx = tbx_index_load2(cfilename, cindex_filename) # <<<<<<<<<<<<<< @@ -60003,7 +69297,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __pyx_v_tidx = tbx_index_load2(__pyx_v_cfilename, __pyx_v_cindex_filename); } - /* "pysam/libcbcf.pyx":3700 + /* "pysam/libcbcf.pyx":4269 * if index_filename is not None: * cindex_filename = index_filename * with nogil: # <<<<<<<<<<<<<< @@ -60016,28 +69310,28 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif - goto __pyx_L64; + goto __pyx_L63; } - __pyx_L64:; + __pyx_L63:; } } - /* "pysam/libcbcf.pyx":3702 + /* "pysam/libcbcf.pyx":4271 * with nogil: * tidx = tbx_index_load2(cfilename, cindex_filename) * self.index = makeTabixIndex(tidx) # <<<<<<<<<<<<<< * * if not self.is_stream: */ - __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeTabixIndex(__pyx_v_tidx)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3702, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_7libcbcf_makeTabixIndex(__pyx_v_tidx)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4271, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_self->index); __Pyx_DECREF(((PyObject *)__pyx_v_self->index)); - __pyx_v_self->index = ((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_t_4); - __pyx_t_4 = 0; + __pyx_v_self->index = ((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libcbcf.pyx":3697 + /* "pysam/libcbcf.pyx":4266 * self.index = makeBCFIndex(self.header, idx) * * elif self.htsfile.format.compression == bgzf and cfilename: # <<<<<<<<<<<<<< @@ -60045,26 +69339,26 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ * cindex_filename = index_filename */ } - __pyx_L52:; + __pyx_L51:; - /* "pysam/libcbcf.pyx":3704 + /* "pysam/libcbcf.pyx":4273 * self.index = makeTabixIndex(tidx) * * if not self.is_stream: # <<<<<<<<<<<<<< * self.start_offset = self.tell() * else: */ - __pyx_t_6 = ((!(__pyx_v_self->__pyx_base.is_stream != 0)) != 0); - if (__pyx_t_6) { + __pyx_t_1 = ((!(__pyx_v_self->__pyx_base.is_stream != 0)) != 0); + if (__pyx_t_1) { - /* "pysam/libcbcf.pyx":3705 + /* "pysam/libcbcf.pyx":4274 * * if not self.is_stream: * self.start_offset = self.tell() # <<<<<<<<<<<<<< * else: - * raise ValueError("unknown mode {}".format(mode)) + * raise ValueError('unknown mode {}'.format(mode)) */ - __pyx_t_17 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tell); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 3705, __pyx_L1_error) + __pyx_t_17 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tell); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 4274, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_17); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_17))) { @@ -60077,18 +69371,18 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ } } if (__pyx_t_9) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_17, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3705, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_17, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4274, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } else { - __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_17); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3705, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_17); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4274, __pyx_L1_error) } - __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - __pyx_t_20 = __Pyx_PyInt_As_int64_t(__pyx_t_4); if (unlikely((__pyx_t_20 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 3705, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_20 = __Pyx_PyInt_As_int64_t(__pyx_t_2); if (unlikely((__pyx_t_20 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 4274, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_self->__pyx_base.start_offset = __pyx_t_20; - /* "pysam/libcbcf.pyx":3704 + /* "pysam/libcbcf.pyx":4273 * self.index = makeTabixIndex(tidx) * * if not self.is_stream: # <<<<<<<<<<<<<< @@ -60097,25 +69391,25 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ } - /* "pysam/libcbcf.pyx":3657 + /* "pysam/libcbcf.pyx":4230 * raise ValueError("could not open file `{}` (mode='{}')".format(filename, mode)) * * elif mode.startswith(b'r'): # <<<<<<<<<<<<<< * # open file for reading - * + * self.htsfile = self._open_htsfile() */ - goto __pyx_L29; + goto __pyx_L32; } - /* "pysam/libcbcf.pyx":3707 + /* "pysam/libcbcf.pyx":4276 * self.start_offset = self.tell() * else: - * raise ValueError("unknown mode {}".format(mode)) # <<<<<<<<<<<<<< + * raise ValueError('unknown mode {}'.format(mode)) # <<<<<<<<<<<<<< * * def reset(self): */ /*else*/ { - __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unknown_mode, __pyx_n_s_format); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 3707, __pyx_L1_error) + __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_unknown_mode, __pyx_n_s_format); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 4276, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_17); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_17))) { @@ -60128,48 +69422,48 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ } } if (!__pyx_t_9) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_17, __pyx_v_mode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3707, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_17, __pyx_v_mode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4276, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_17)) { PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_mode}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3707, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4276, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_2); } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_17)) { PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_mode}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3707, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4276, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3707, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); __pyx_t_9 = NULL; + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 4276, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9); __pyx_t_9 = NULL; __Pyx_INCREF(__pyx_v_mode); __Pyx_GIVEREF(__pyx_v_mode); - PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_v_mode); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_17, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 3707, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_mode); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_17, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4276, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } } __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - __pyx_t_17 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 3707, __pyx_L1_error) + __pyx_t_17 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 4276, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_17); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_17, 0, 0, 0); __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; - __PYX_ERR(0, 3707, __pyx_L1_error) + __PYX_ERR(0, 4276, __pyx_L1_error) } - __pyx_L29:; + __pyx_L32:; - /* "pysam/libcbcf.pyx":3571 + /* "pysam/libcbcf.pyx":4133 * return vars * * def open(self, filename, mode='r', # <<<<<<<<<<<<<< @@ -60181,9 +69475,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); __Pyx_XDECREF(__pyx_t_17); @@ -60203,8 +69497,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libcbcf.pyx":3709 - * raise ValueError("unknown mode {}".format(mode)) +/* "pysam/libcbcf.pyx":4278 + * raise ValueError('unknown mode {}'.format(mode)) * * def reset(self): # <<<<<<<<<<<<<< * """reset file position to beginning of file just after the header.""" @@ -60212,20 +69506,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12open(struct __pyx_obj_ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_15reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_11VariantFile_14reset[] = "VariantFile.reset(self)\nreset file position to beginning of file just after the header."; -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_15reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_17reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_16reset[] = "VariantFile.reset(self)\nreset file position to beginning of file just after the header."; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_17reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("reset (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_14reset(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_16reset(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_14reset(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16reset(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -60235,19 +69529,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_14reset(struct __pyx_obj PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("reset", 0); - __Pyx_TraceCall("reset", __pyx_f[0], 3709, 0, __PYX_ERR(0, 3709, __pyx_L1_error)); + __Pyx_TraceCall("reset", __pyx_f[0], 4278, 0, __PYX_ERR(0, 4278, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3711 + /* "pysam/libcbcf.pyx":4280 * def reset(self): * """reset file position to beginning of file just after the header.""" * return self.seek(self.start_offset) # <<<<<<<<<<<<<< * - * + * def is_valid_tid(self, tid): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_seek); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3711, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_seek); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4280, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_int64_t(__pyx_v_self->__pyx_base.start_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3711, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int64_t(__pyx_v_self->__pyx_base.start_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4280, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -60260,14 +69554,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_14reset(struct __pyx_obj } } if (!__pyx_t_4) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3711, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4280, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3711, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4280, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -60276,20 +69570,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_14reset(struct __pyx_obj #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3711, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4280, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else #endif { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3711, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4280, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3711, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4280, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } @@ -60299,8 +69593,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_14reset(struct __pyx_obj __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3709 - * raise ValueError("unknown mode {}".format(mode)) + /* "pysam/libcbcf.pyx":4278 + * raise ValueError('unknown mode {}'.format(mode)) * * def reset(self): # <<<<<<<<<<<<<< * """reset file position to beginning of file just after the header.""" @@ -60323,38 +69617,489 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_14reset(struct __pyx_obj return __pyx_r; } -/* "pysam/libcbcf.pyx":3714 +/* "pysam/libcbcf.pyx":4282 + * return self.seek(self.start_offset) + * + * def is_valid_tid(self, tid): # <<<<<<<<<<<<<< + * """ + * return True if the numerical :term:`tid` is valid; False otherwise. + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_19is_valid_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_18is_valid_tid[] = "VariantFile.is_valid_tid(self, tid)\n\n return True if the numerical :term:`tid` is valid; False otherwise.\n\n returns -1 if reference is not known.\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_19is_valid_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_valid_tid (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_18is_valid_tid(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), ((PyObject *)__pyx_v_tid)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_18is_valid_tid(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_tid) { + bcf_hdr_t *__pyx_v_hdr; + int __pyx_v_rid; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + bcf_hdr_t *__pyx_t_4; + int __pyx_t_5; + __Pyx_RefNannySetupContext("is_valid_tid", 0); + __Pyx_TraceCall("is_valid_tid", __pyx_f[0], 4282, 0, __PYX_ERR(0, 4282, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":4288 + * returns -1 if reference is not known. + * """ + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError('I/O operation on closed file') + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4288, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 4288, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = ((!__pyx_t_2) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcbcf.pyx":4289 + * """ + * if not self.is_open: + * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< + * + * cdef bcf_hdr_t *hdr = self.header.ptr + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__225, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4289, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 4289, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":4288 + * returns -1 if reference is not known. + * """ + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError('I/O operation on closed file') + * + */ + } + + /* "pysam/libcbcf.pyx":4291 + * raise ValueError('I/O operation on closed file') + * + * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< + * cdef int rid = tid + * return 0 <= rid < hdr.n[BCF_DT_CTG] + */ + __pyx_t_4 = __pyx_v_self->header->ptr; + __pyx_v_hdr = __pyx_t_4; + + /* "pysam/libcbcf.pyx":4292 + * + * cdef bcf_hdr_t *hdr = self.header.ptr + * cdef int rid = tid # <<<<<<<<<<<<<< + * return 0 <= rid < hdr.n[BCF_DT_CTG] + * + */ + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_v_tid); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4292, __pyx_L1_error) + __pyx_v_rid = __pyx_t_5; + + /* "pysam/libcbcf.pyx":4293 + * cdef bcf_hdr_t *hdr = self.header.ptr + * cdef int rid = tid + * return 0 <= rid < hdr.n[BCF_DT_CTG] # <<<<<<<<<<<<<< + * + * def get_tid(self, reference): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = (0 <= __pyx_v_rid); + if (__pyx_t_3) { + __pyx_t_3 = (__pyx_v_rid < (__pyx_v_hdr->n[BCF_DT_CTG])); + } + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":4282 + * return self.seek(self.start_offset) + * + * def is_valid_tid(self, tid): # <<<<<<<<<<<<<< + * """ + * return True if the numerical :term:`tid` is valid; False otherwise. + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantFile.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":4295 + * return 0 <= rid < hdr.n[BCF_DT_CTG] + * + * def get_tid(self, reference): # <<<<<<<<<<<<<< + * """ + * return the numerical :term:`tid` corresponding to + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_21get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_20get_tid[] = "VariantFile.get_tid(self, reference)\n\n return the numerical :term:`tid` corresponding to\n :term:`reference`\n\n returns -1 if reference is not known.\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_21get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_tid (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_20get_tid(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), ((PyObject *)__pyx_v_reference)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_20get_tid(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_reference) { + vdict_t *__pyx_v_d; + khint_t __pyx_v_k; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + char const *__pyx_t_4; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("get_tid", 0); + __Pyx_TraceCall("get_tid", __pyx_f[0], 4295, 0, __PYX_ERR(0, 4295, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_reference); + + /* "pysam/libcbcf.pyx":4302 + * returns -1 if reference is not known. + * """ + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError('I/O operation on closed file') + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4302, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 4302, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = ((!__pyx_t_2) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcbcf.pyx":4303 + * """ + * if not self.is_open: + * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< + * + * cdef vdict_t *d = self.header.ptr.dict[BCF_DT_CTG] + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__226, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4303, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 4303, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":4302 + * returns -1 if reference is not known. + * """ + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError('I/O operation on closed file') + * + */ + } + + /* "pysam/libcbcf.pyx":4305 + * raise ValueError('I/O operation on closed file') + * + * cdef vdict_t *d = self.header.ptr.dict[BCF_DT_CTG] # <<<<<<<<<<<<<< + * reference = force_bytes(reference) + * cdef khint_t k = kh_get_vdict(d, reference) + */ + __pyx_v_d = ((vdict_t *)(__pyx_v_self->header->ptr->dict[BCF_DT_CTG])); + + /* "pysam/libcbcf.pyx":4306 + * + * cdef vdict_t *d = self.header.ptr.dict[BCF_DT_CTG] + * reference = force_bytes(reference) # <<<<<<<<<<<<<< + * cdef khint_t k = kh_get_vdict(d, reference) + * return kh_val_vdict(d, k).id if k != kh_end(d) else -1 + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_reference, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4306, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF_SET(__pyx_v_reference, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":4307 + * cdef vdict_t *d = self.header.ptr.dict[BCF_DT_CTG] + * reference = force_bytes(reference) + * cdef khint_t k = kh_get_vdict(d, reference) # <<<<<<<<<<<<<< + * return kh_val_vdict(d, k).id if k != kh_end(d) else -1 + * + */ + __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_v_reference); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 4307, __pyx_L1_error) + __pyx_v_k = kh_get_vdict(__pyx_v_d, __pyx_t_4); + + /* "pysam/libcbcf.pyx":4308 + * reference = force_bytes(reference) + * cdef khint_t k = kh_get_vdict(d, reference) + * return kh_val_vdict(d, k).id if k != kh_end(d) else -1 # <<<<<<<<<<<<<< + * + * def get_reference_name(self, tid): + */ + __Pyx_XDECREF(__pyx_r); + if (((__pyx_v_k != kh_end(__pyx_v_d)) != 0)) { + __pyx_t_5 = __Pyx_PyInt_From_int(kh_val(__pyx_v_d, __pyx_v_k).id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4308, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + } else { + __Pyx_INCREF(__pyx_int_neg_1); + __pyx_t_1 = __pyx_int_neg_1; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":4295 + * return 0 <= rid < hdr.n[BCF_DT_CTG] + * + * def get_tid(self, reference): # <<<<<<<<<<<<<< + * """ + * return the numerical :term:`tid` corresponding to + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libcbcf.VariantFile.get_tid", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_reference); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":4310 + * return kh_val_vdict(d, k).id if k != kh_end(d) else -1 + * + * def get_reference_name(self, tid): # <<<<<<<<<<<<<< + * """ + * return :term:`reference` name corresponding to numerical :term:`tid` + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_23get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_22get_reference_name[] = "VariantFile.get_reference_name(self, tid)\n\n return :term:`reference` name corresponding to numerical :term:`tid`\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_23get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_reference_name (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_22get_reference_name(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), ((PyObject *)__pyx_v_tid)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_22get_reference_name(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_tid) { + bcf_hdr_t *__pyx_v_hdr; + int __pyx_v_rid; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + bcf_hdr_t *__pyx_t_4; + int __pyx_t_5; + __Pyx_RefNannySetupContext("get_reference_name", 0); + __Pyx_TraceCall("get_reference_name", __pyx_f[0], 4310, 0, __PYX_ERR(0, 4310, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":4314 + * return :term:`reference` name corresponding to numerical :term:`tid` + * """ + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError('I/O operation on closed file') + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 4314, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = ((!__pyx_t_2) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcbcf.pyx":4315 + * """ + * if not self.is_open: + * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< + * + * cdef bcf_hdr_t *hdr = self.header.ptr + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__227, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4315, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 4315, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":4314 + * return :term:`reference` name corresponding to numerical :term:`tid` + * """ + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError('I/O operation on closed file') + * + */ + } + + /* "pysam/libcbcf.pyx":4317 + * raise ValueError('I/O operation on closed file') + * + * cdef bcf_hdr_t *hdr = self.header.ptr # <<<<<<<<<<<<<< + * cdef int rid = tid + * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: + */ + __pyx_t_4 = __pyx_v_self->header->ptr; + __pyx_v_hdr = __pyx_t_4; + + /* "pysam/libcbcf.pyx":4318 + * + * cdef bcf_hdr_t *hdr = self.header.ptr + * cdef int rid = tid # <<<<<<<<<<<<<< + * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: + * raise ValueError('Invalid tid') + */ + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_v_tid); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4318, __pyx_L1_error) + __pyx_v_rid = __pyx_t_5; + + /* "pysam/libcbcf.pyx":4319 + * cdef bcf_hdr_t *hdr = self.header.ptr + * cdef int rid = tid + * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: # <<<<<<<<<<<<<< + * raise ValueError('Invalid tid') + * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) + */ + __pyx_t_2 = ((__pyx_v_rid < 0) != 0); + if (!__pyx_t_2) { + } else { + __pyx_t_3 = __pyx_t_2; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_rid >= (__pyx_v_hdr->n[BCF_DT_CTG])) != 0); + __pyx_t_3 = __pyx_t_2; + __pyx_L5_bool_binop_done:; + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcbcf.pyx":4320 + * cdef int rid = tid + * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: + * raise ValueError('Invalid tid') # <<<<<<<<<<<<<< + * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) + * + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__228, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4320, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 4320, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":4319 + * cdef bcf_hdr_t *hdr = self.header.ptr + * cdef int rid = tid + * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: # <<<<<<<<<<<<<< + * raise ValueError('Invalid tid') + * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) + */ + } + + /* "pysam/libcbcf.pyx":4321 + * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: + * raise ValueError('Invalid tid') + * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) # <<<<<<<<<<<<<< + * + * def fetch(self, contig=None, start=None, stop=None, region=None, reopen=False, end=None, reference=None): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __pyx_f_5pysam_7libcbcf_bcf_str_cache_get_charptr(bcf_hdr_id2name(__pyx_v_hdr, __pyx_v_rid)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4321, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcbcf.pyx":4310 + * return kh_val_vdict(d, k).id if k != kh_end(d) else -1 * + * def get_reference_name(self, tid): # <<<<<<<<<<<<<< + * """ + * return :term:`reference` name corresponding to numerical :term:`tid` + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcbcf.VariantFile.get_reference_name", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbcf.pyx":4323 + * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) * - * def fetch(self, contig=None, start=None, stop=None, region=None, reopen=False): # <<<<<<<<<<<<<< + * def fetch(self, contig=None, start=None, stop=None, region=None, reopen=False, end=None, reference=None): # <<<<<<<<<<<<<< * """fetch records in a :term:`region` using 0-based indexing. The * region is specified by :term:`contig`, *start* and *end*. */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_17fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_11VariantFile_16fetch[] = "VariantFile.fetch(self, contig=None, start=None, stop=None, region=None, reopen=False)\nfetch records in a :term:`region` using 0-based indexing. The\n region is specified by :term:`contig`, *start* and *end*.\n Alternatively, a samtools :term:`region` string can be supplied.\n\n Without *contig* or *region* all mapped records will be fetched. The\n records will be returned ordered by contig, which will not necessarily\n be the order within the file.\n\n Set *reopen* to true if you will be using multiple iterators on the\n same file at the same time. The iterator returned will receive its\n own copy of a filehandle to the file effectively re-opening the\n file. Re-opening a file incurrs some overhead, so use with care.\n\n If only *contig* is set, all records on *contig* will be fetched.\n If both *region* and *contig* are given, an exception is raised.\n\n Note that a bgzipped :term:`VCF`.gz file without a tabix/CSI index\n (.tbi/.csi) or a :term:`BCF` file without a CSI index can only be\n read sequentially.\n "; -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_17fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_25fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_24fetch[] = "VariantFile.fetch(self, contig=None, start=None, stop=None, region=None, reopen=False, end=None, reference=None)\nfetch records in a :term:`region` using 0-based indexing. The\n region is specified by :term:`contig`, *start* and *end*.\n Alternatively, a samtools :term:`region` string can be supplied.\n\n Without *contig* or *region* all mapped records will be fetched. The\n records will be returned ordered by contig, which will not necessarily\n be the order within the file.\n\n Set *reopen* to true if you will be using multiple iterators on the\n same file at the same time. The iterator returned will receive its\n own copy of a filehandle to the file effectively re-opening the\n file. Re-opening a file incurrs some overhead, so use with care.\n\n If only *contig* is set, all records on *contig* will be fetched.\n If both *region* and *contig* are given, an exception is raised.\n\n Note that a bgzipped :term:`VCF`.gz file without a tabix/CSI index\n (.tbi/.csi) or a :term:`BCF` file without a CSI index can only be\n read sequentially.\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_25fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_contig = 0; PyObject *__pyx_v_start = 0; PyObject *__pyx_v_stop = 0; PyObject *__pyx_v_region = 0; PyObject *__pyx_v_reopen = 0; + PyObject *__pyx_v_end = 0; + PyObject *__pyx_v_reference = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("fetch (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_reopen,0}; - PyObject* values[5] = {0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_reopen,&__pyx_n_s_end,&__pyx_n_s_reference,0}; + PyObject* values[7] = {0,0,0,0,0,0,0}; values[0] = ((PyObject *)Py_None); values[1] = ((PyObject *)Py_None); values[2] = ((PyObject *)Py_None); values[3] = ((PyObject *)Py_None); values[4] = ((PyObject *)Py_False); + values[5] = ((PyObject *)Py_None); + values[6] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -60399,12 +70144,28 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_17fetch(PyObject *__pyx_ PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reopen); if (value) { values[4] = value; kw_args--; } } + CYTHON_FALLTHROUGH; + case 5: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); + if (value) { values[5] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 6: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); + if (value) { values[6] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 3714, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 4323, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -60424,24 +70185,28 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_17fetch(PyObject *__pyx_ __pyx_v_stop = values[2]; __pyx_v_region = values[3]; __pyx_v_reopen = values[4]; + __pyx_v_end = values[5]; + __pyx_v_reference = values[6]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 3714, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 4323, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.VariantFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_reopen); + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_24fetch(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_reopen, __pyx_v_end, __pyx_v_reference); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reopen) { +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_24fetch(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reopen, PyObject *__pyx_v_end, PyObject *__pyx_v_reference) { PyObject *__pyx_v_bcf = NULL; + CYTHON_UNUSED PyObject *__pyx_v__ = NULL; + PyObject *__pyx_v_tid = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -60453,38 +70218,43 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; + PyObject *__pyx_t_9 = NULL; + PyObject *(*__pyx_t_10)(PyObject *); + int __pyx_t_11; __Pyx_RefNannySetupContext("fetch", 0); - __Pyx_TraceCall("fetch", __pyx_f[0], 3714, 0, __PYX_ERR(0, 3714, __pyx_L1_error)); + __Pyx_TraceCall("fetch", __pyx_f[0], 4323, 0, __PYX_ERR(0, 4323, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_contig); + __Pyx_INCREF(__pyx_v_start); + __Pyx_INCREF(__pyx_v_stop); - /* "pysam/libcbcf.pyx":3735 + /* "pysam/libcbcf.pyx":4344 * read sequentially. * """ * if not self.is_open: # <<<<<<<<<<<<<< * raise ValueError('I/O operation on closed file') * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3735, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4344, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3735, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 4344, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = ((!__pyx_t_2) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":3736 + /* "pysam/libcbcf.pyx":4345 * """ * if not self.is_open: * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< * * if self.htsfile.is_write: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__211, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3736, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__229, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4345, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3736, __pyx_L1_error) + __PYX_ERR(0, 4345, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3735 + /* "pysam/libcbcf.pyx":4344 * read sequentially. * """ * if not self.is_open: # <<<<<<<<<<<<<< @@ -60493,7 +70263,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":3738 + /* "pysam/libcbcf.pyx":4347 * raise ValueError('I/O operation on closed file') * * if self.htsfile.is_write: # <<<<<<<<<<<<<< @@ -60503,20 +70273,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj __pyx_t_3 = (__pyx_v_self->__pyx_base.htsfile->is_write != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":3739 + /* "pysam/libcbcf.pyx":4348 * * if self.htsfile.is_write: * raise ValueError('cannot fetch from Variantfile opened for writing') # <<<<<<<<<<<<<< * * if contig is None and region is None: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__212, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3739, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__230, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4348, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3739, __pyx_L1_error) + __PYX_ERR(0, 4348, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3738 + /* "pysam/libcbcf.pyx":4347 * raise ValueError('I/O operation on closed file') * * if self.htsfile.is_write: # <<<<<<<<<<<<<< @@ -60525,7 +70295,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":3741 + /* "pysam/libcbcf.pyx":4350 * raise ValueError('cannot fetch from Variantfile opened for writing') * * if contig is None and region is None: # <<<<<<<<<<<<<< @@ -60545,7 +70315,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj __pyx_L6_bool_binop_done:; if (__pyx_t_3) { - /* "pysam/libcbcf.pyx":3742 + /* "pysam/libcbcf.pyx":4351 * * if contig is None and region is None: * self.is_reading = 1 # <<<<<<<<<<<<<< @@ -60554,16 +70324,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj */ __pyx_v_self->is_reading = 1; - /* "pysam/libcbcf.pyx":3743 + /* "pysam/libcbcf.pyx":4352 * if contig is None and region is None: * self.is_reading = 1 * bcf = self.copy() if reopen else self # <<<<<<<<<<<<<< * bcf.seek(self.start_offset) * return iter(bcf) */ - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_reopen); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 3743, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_reopen); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 4352, __pyx_L1_error) if (__pyx_t_3) { - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_copy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3743, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_copy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4352, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { @@ -60576,10 +70346,10 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj } } if (__pyx_t_7) { - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3743, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4352, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else { - __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3743, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4352, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -60592,16 +70362,16 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj __pyx_v_bcf = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3744 + /* "pysam/libcbcf.pyx":4353 * self.is_reading = 1 * bcf = self.copy() if reopen else self * bcf.seek(self.start_offset) # <<<<<<<<<<<<<< * return iter(bcf) * */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_bcf, __pyx_n_s_seek); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3744, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_bcf, __pyx_n_s_seek); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4353, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyInt_From_int64_t(__pyx_v_self->__pyx_base.start_offset); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3744, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_From_int64_t(__pyx_v_self->__pyx_base.start_offset); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4353, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { @@ -60614,14 +70384,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj } } if (!__pyx_t_7) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3744, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4353, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3744, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4353, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -60630,20 +70400,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3744, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4353, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif { - __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 3744, __pyx_L1_error) + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4353, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL; __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_6); __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3744, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4353, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } @@ -60651,7 +70421,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3745 + /* "pysam/libcbcf.pyx":4354 * bcf = self.copy() if reopen else self * bcf.seek(self.start_offset) * return iter(bcf) # <<<<<<<<<<<<<< @@ -60659,13 +70429,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj * if not self.index: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetIter(__pyx_v_bcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3745, __pyx_L1_error) + __pyx_t_1 = PyObject_GetIter(__pyx_v_bcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4354, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3741 + /* "pysam/libcbcf.pyx":4350 * raise ValueError('cannot fetch from Variantfile opened for writing') * * if contig is None and region is None: # <<<<<<<<<<<<<< @@ -60674,31 +70444,31 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":3747 + /* "pysam/libcbcf.pyx":4356 * return iter(bcf) * * if not self.index: # <<<<<<<<<<<<<< * raise ValueError('fetch requires an index') * */ - __pyx_t_3 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->index)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 3747, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->index)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 4356, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_3) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcbcf.pyx":3748 + /* "pysam/libcbcf.pyx":4357 * * if not self.index: * raise ValueError('fetch requires an index') # <<<<<<<<<<<<<< * - * self.is_reading = 1 + * _, tid, start, stop = self.parse_region(contig, start, stop, region, */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__213, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3748, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__231, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4357, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3748, __pyx_L1_error) + __PYX_ERR(0, 4357, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3747 + /* "pysam/libcbcf.pyx":4356 * return iter(bcf) * * if not self.index: # <<<<<<<<<<<<<< @@ -60707,90 +70477,281 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj */ } - /* "pysam/libcbcf.pyx":3750 + /* "pysam/libcbcf.pyx":4359 * raise ValueError('fetch requires an index') * + * _, tid, start, stop = self.parse_region(contig, start, stop, region, # <<<<<<<<<<<<<< + * None, end=end, reference=reference) + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_parse_region); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pysam/libcbcf.pyx":4360 + * + * _, tid, start, stop = self.parse_region(contig, start, stop, region, + * None, end=end, reference=reference) # <<<<<<<<<<<<<< + * + * if contig is None: + */ + __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_contig); + __Pyx_GIVEREF(__pyx_v_contig); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_contig); + __Pyx_INCREF(__pyx_v_start); + __Pyx_GIVEREF(__pyx_v_start); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_start); + __Pyx_INCREF(__pyx_v_stop); + __Pyx_GIVEREF(__pyx_v_stop); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_stop); + __Pyx_INCREF(__pyx_v_region); + __Pyx_GIVEREF(__pyx_v_region); + PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_region); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_5, 4, Py_None); + __pyx_t_8 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 4360, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 4360, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 4360, __pyx_L1_error) + + /* "pysam/libcbcf.pyx":4359 + * raise ValueError('fetch requires an index') + * + * _, tid, start, stop = self.parse_region(contig, start, stop, region, # <<<<<<<<<<<<<< + * None, end=end, reference=reference) + * + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { + PyObject* sequence = __pyx_t_6; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 4)) { + if (size > 4) __Pyx_RaiseTooManyValuesError(4); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 4359, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_8 = PyList_GET_ITEM(sequence, 0); + __pyx_t_5 = PyList_GET_ITEM(sequence, 1); + __pyx_t_1 = PyList_GET_ITEM(sequence, 2); + __pyx_t_7 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_7); + #else + { + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_8,&__pyx_t_5,&__pyx_t_1,&__pyx_t_7}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 4359, __pyx_L1_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; + } + } + #endif + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else { + Py_ssize_t index = -1; + PyObject** temps[4] = {&__pyx_t_8,&__pyx_t_5,&__pyx_t_1,&__pyx_t_7}; + __pyx_t_9 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; + for (index=0; index < 4; index++) { + PyObject* item = __pyx_t_10(__pyx_t_9); if (unlikely(!item)) goto __pyx_L9_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 4) < 0) __PYX_ERR(0, 4359, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L10_unpacking_done; + __pyx_L9_unpacking_failed:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 4359, __pyx_L1_error) + __pyx_L10_unpacking_done:; + } + __pyx_v__ = __pyx_t_8; + __pyx_t_8 = 0; + __pyx_v_tid = __pyx_t_5; + __pyx_t_5 = 0; + __Pyx_DECREF_SET(__pyx_v_start, __pyx_t_1); + __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_stop, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pysam/libcbcf.pyx":4362 + * None, end=end, reference=reference) + * + * if contig is None: # <<<<<<<<<<<<<< + * contig = self.get_reference_name(tid) + * + */ + __pyx_t_2 = (__pyx_v_contig == Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "pysam/libcbcf.pyx":4363 + * + * if contig is None: + * contig = self.get_reference_name(tid) # <<<<<<<<<<<<<< + * + * self.is_reading = 1 + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4363, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_1) { + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_tid); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4363, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_tid}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4363, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_tid}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4363, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else + #endif + { + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4363, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); __pyx_t_1 = NULL; + __Pyx_INCREF(__pyx_v_tid); + __Pyx_GIVEREF(__pyx_v_tid); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_tid); + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4363, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF_SET(__pyx_v_contig, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libcbcf.pyx":4362 + * None, end=end, reference=reference) + * + * if contig is None: # <<<<<<<<<<<<<< + * contig = self.get_reference_name(tid) + * + */ + } + + /* "pysam/libcbcf.pyx":4365 + * contig = self.get_reference_name(tid) + * * self.is_reading = 1 # <<<<<<<<<<<<<< - * return self.index.fetch(self, contig, start, stop, region, reopen) + * return self.index.fetch(self, contig, start, stop, reopen) * */ __pyx_v_self->is_reading = 1; - /* "pysam/libcbcf.pyx":3751 + /* "pysam/libcbcf.pyx":4366 * * self.is_reading = 1 - * return self.index.fetch(self, contig, start, stop, region, reopen) # <<<<<<<<<<<<<< + * return self.index.fetch(self, contig, start, stop, reopen) # <<<<<<<<<<<<<< * - * cpdef VariantRecord new_record(self): + * def new_record(self, *args, **kwargs): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->index), __pyx_n_s_fetch); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3751, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = NULL; - __pyx_t_9 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_8); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->index), __pyx_n_s_fetch); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 4366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - __pyx_t_9 = 1; + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_11 = 1; } } #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[7] = {__pyx_t_8, ((PyObject *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_reopen}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 6+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3751, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_1); + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[6] = {__pyx_t_5, ((PyObject *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_reopen}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 5+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4366, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_6); } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[7] = {__pyx_t_8, ((PyObject *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_reopen}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 6+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3751, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[6] = {__pyx_t_5, ((PyObject *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_reopen}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 5+__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4366, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_6); } else #endif { - __pyx_t_6 = PyTuple_New(6+__pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 3751, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8); __pyx_t_8 = NULL; + __pyx_t_1 = PyTuple_New(5+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); __pyx_t_5 = NULL; } __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_9, ((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, ((PyObject *)__pyx_v_self)); __Pyx_INCREF(__pyx_v_contig); __Pyx_GIVEREF(__pyx_v_contig); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_9, __pyx_v_contig); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, __pyx_v_contig); __Pyx_INCREF(__pyx_v_start); __Pyx_GIVEREF(__pyx_v_start); - PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_9, __pyx_v_start); + PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_11, __pyx_v_start); __Pyx_INCREF(__pyx_v_stop); __Pyx_GIVEREF(__pyx_v_stop); - PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_9, __pyx_v_stop); - __Pyx_INCREF(__pyx_v_region); - __Pyx_GIVEREF(__pyx_v_region); - PyTuple_SET_ITEM(__pyx_t_6, 4+__pyx_t_9, __pyx_v_region); + PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_11, __pyx_v_stop); __Pyx_INCREF(__pyx_v_reopen); __Pyx_GIVEREF(__pyx_v_reopen); - PyTuple_SET_ITEM(__pyx_t_6, 5+__pyx_t_9, __pyx_v_reopen); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3751, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + PyTuple_SET_ITEM(__pyx_t_1, 4+__pyx_t_11, __pyx_v_reopen); + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 4366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3714 - * + /* "pysam/libcbcf.pyx":4323 + * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) * - * def fetch(self, contig=None, start=None, stop=None, region=None, reopen=False): # <<<<<<<<<<<<<< + * def fetch(self, contig=None, start=None, stop=None, region=None, reopen=False, end=None, reference=None): # <<<<<<<<<<<<<< * """fetch records in a :term:`region` using 0-based indexing. The * region is specified by :term:`contig`, *start* and *end*. */ @@ -60802,139 +70763,95 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_16fetch(struct __pyx_obj __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); __Pyx_AddTraceback("pysam.libcbcf.VariantFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_bcf); + __Pyx_XDECREF(__pyx_v__); + __Pyx_XDECREF(__pyx_v_tid); + __Pyx_XDECREF(__pyx_v_contig); + __Pyx_XDECREF(__pyx_v_start); + __Pyx_XDECREF(__pyx_v_stop); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcbcf.pyx":3753 - * return self.index.fetch(self, contig, start, stop, region, reopen) +/* "pysam/libcbcf.pyx":4368 + * return self.index.fetch(self, contig, start, stop, reopen) * - * cpdef VariantRecord new_record(self): # <<<<<<<<<<<<<< - * """Create a new empty VariantRecord""" - * return self.header.new_record() - */ - -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_19new_record(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_f_5pysam_7libcbcf_11VariantFile_new_record(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, int __pyx_skip_dispatch) { - struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannySetupContext("new_record", 0); - __Pyx_TraceCall("new_record", __pyx_f[0], 3753, 0, __PYX_ERR(0, 3753, __pyx_L1_error)); - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_new_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3753, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_19new_record)) { - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3753, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3753, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5pysam_7libcbcf_VariantRecord))))) __PYX_ERR(0, 3753, __pyx_L1_error) - __pyx_r = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_2); - __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "pysam/libcbcf.pyx":3755 - * cpdef VariantRecord new_record(self): - * """Create a new empty VariantRecord""" - * return self.header.new_record() # <<<<<<<<<<<<<< - * - * cpdef int write(self, VariantRecord record) except -1: - */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_5pysam_7libcbcf_VariantHeader *)__pyx_v_self->header->__pyx_vtab)->new_record(__pyx_v_self->header, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = ((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_t_1); - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "pysam/libcbcf.pyx":3753 - * return self.index.fetch(self, contig, start, stop, region, reopen) + * def new_record(self, *args, **kwargs): # <<<<<<<<<<<<<< + * """Create a new empty :class:`VariantRecord`. * - * cpdef VariantRecord new_record(self): # <<<<<<<<<<<<<< - * """Create a new empty VariantRecord""" - * return self.header.new_record() */ - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcbcf.VariantFile.new_record", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF((PyObject *)__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_19new_record(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_11VariantFile_18new_record[] = "VariantFile.new_record(self) -> VariantRecord\nCreate a new empty VariantRecord"; -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_19new_record(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_27new_record(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_26new_record[] = "VariantFile.new_record(self, *args, **kwargs)\nCreate a new empty :class:`VariantRecord`.\n\n See :meth:`VariantHeader.new_record`\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_27new_record(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_args = 0; + PyObject *__pyx_v_kwargs = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("new_record (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_18new_record(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); + if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "new_record", 1))) return NULL; + if (unlikely(__pyx_kwds)) { + __pyx_v_kwargs = PyDict_Copy(__pyx_kwds); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + } else { + __pyx_v_kwargs = NULL; + } + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_26new_record(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_18new_record(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_26new_record(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("new_record", 0); - __Pyx_TraceCall("new_record (wrapper)", __pyx_f[0], 3753, 0, __PYX_ERR(0, 3753, __pyx_L1_error)); + __Pyx_TraceCall("new_record", __pyx_f[0], 4368, 0, __PYX_ERR(0, 4368, __pyx_L1_error)); + + /* "pysam/libcbcf.pyx":4373 + * See :meth:`VariantHeader.new_record` + * """ + * return self.header.new_record(*args, **kwargs) # <<<<<<<<<<<<<< + * + * cpdef int write(self, VariantRecord record) except -1: + */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_7libcbcf_11VariantFile_new_record(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3753, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_new_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4373, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_v_args, __pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4373, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; + /* "pysam/libcbcf.pyx":4368 + * return self.index.fetch(self, contig, start, stop, reopen) + * + * def new_record(self, *args, **kwargs): # <<<<<<<<<<<<<< + * """Create a new empty :class:`VariantRecord`. + * + */ + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("pysam.libcbcf.VariantFile.new_record", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -60944,15 +70861,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_18new_record(struct __py return __pyx_r; } -/* "pysam/libcbcf.pyx":3757 - * return self.header.new_record() +/* "pysam/libcbcf.pyx":4375 + * return self.header.new_record(*args, **kwargs) * * cpdef int write(self, VariantRecord record) except -1: # <<<<<<<<<<<<<< * """ * write a single :class:`pysam.VariantRecord` to disk. */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_21write(PyObject *__pyx_v_self, PyObject *__pyx_v_record); /*proto*/ +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_29write(PyObject *__pyx_v_self, PyObject *__pyx_v_record); /*proto*/ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record, int __pyx_skip_dispatch) { PyObject *__pyx_v_msg = NULL; int __pyx_v_ret; @@ -60969,14 +70886,14 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 int __pyx_t_8; PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("write", 0); - __Pyx_TraceCall("write", __pyx_f[0], 3757, 0, __PYX_ERR(0, 3757, __pyx_L1_error)); + __Pyx_TraceCall("write", __pyx_f[0], 4375, 0, __PYX_ERR(0, 4375, __pyx_L1_error)); /* Check if called by wrapper */ if (unlikely(__pyx_skip_dispatch)) ; /* Check if overridden in Python */ else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3757, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4375, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_21write)) { + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_29write)) { __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { @@ -60989,13 +70906,13 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 } } if (!__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_record)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3757, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_record)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4375, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_record)}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3757, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4375, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_2); } else @@ -61003,25 +70920,25 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_record)}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3757, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4375, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3757, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4375, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_INCREF(((PyObject *)__pyx_v_record)); __Pyx_GIVEREF(((PyObject *)__pyx_v_record)); PyTuple_SET_ITEM(__pyx_t_5, 0+1, ((PyObject *)__pyx_v_record)); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3757, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4375, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3757, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4375, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_6; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -61030,7 +70947,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - /* "pysam/libcbcf.pyx":3763 + /* "pysam/libcbcf.pyx":4381 * returns the number of bytes written. * """ * if record is None: # <<<<<<<<<<<<<< @@ -61041,20 +70958,20 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 __pyx_t_8 = (__pyx_t_7 != 0); if (unlikely(__pyx_t_8)) { - /* "pysam/libcbcf.pyx":3764 + /* "pysam/libcbcf.pyx":4382 * """ * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * if not self.is_open: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__214, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3764, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__232, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4382, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3764, __pyx_L1_error) + __PYX_ERR(0, 4382, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3763 + /* "pysam/libcbcf.pyx":4381 * returns the number of bytes written. * """ * if record is None: # <<<<<<<<<<<<<< @@ -61063,35 +70980,35 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 */ } - /* "pysam/libcbcf.pyx":3766 + /* "pysam/libcbcf.pyx":4384 * raise ValueError('record must not be None') * * if not self.is_open: # <<<<<<<<<<<<<< * return ValueError('I/O operation on closed file') * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3766, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4384, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 3766, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 4384, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_7 = ((!__pyx_t_8) != 0); if (__pyx_t_7) { - /* "pysam/libcbcf.pyx":3767 + /* "pysam/libcbcf.pyx":4385 * * if not self.is_open: * return ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< * * if not self.htsfile.is_write: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__215, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3767, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__233, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 3767, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 4385, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_6; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3766 + /* "pysam/libcbcf.pyx":4384 * raise ValueError('record must not be None') * * if not self.is_open: # <<<<<<<<<<<<<< @@ -61100,7 +71017,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 */ } - /* "pysam/libcbcf.pyx":3769 + /* "pysam/libcbcf.pyx":4387 * return ValueError('I/O operation on closed file') * * if not self.htsfile.is_write: # <<<<<<<<<<<<<< @@ -61110,20 +71027,20 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 __pyx_t_7 = ((!(__pyx_v_self->__pyx_base.htsfile->is_write != 0)) != 0); if (unlikely(__pyx_t_7)) { - /* "pysam/libcbcf.pyx":3770 + /* "pysam/libcbcf.pyx":4388 * * if not self.htsfile.is_write: * raise ValueError('cannot write to a Variantfile opened for reading') # <<<<<<<<<<<<<< * * if not self.header_written: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__216, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3770, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__234, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4388, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3770, __pyx_L1_error) + __PYX_ERR(0, 4388, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3769 + /* "pysam/libcbcf.pyx":4387 * return ValueError('I/O operation on closed file') * * if not self.htsfile.is_write: # <<<<<<<<<<<<<< @@ -61132,7 +71049,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 */ } - /* "pysam/libcbcf.pyx":3772 + /* "pysam/libcbcf.pyx":4390 * raise ValueError('cannot write to a Variantfile opened for reading') * * if not self.header_written: # <<<<<<<<<<<<<< @@ -61142,7 +71059,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 __pyx_t_7 = ((!(__pyx_v_self->header_written != 0)) != 0); if (__pyx_t_7) { - /* "pysam/libcbcf.pyx":3773 + /* "pysam/libcbcf.pyx":4391 * * if not self.header_written: * self.header_written = True # <<<<<<<<<<<<<< @@ -61151,7 +71068,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 */ __pyx_v_self->header_written = 1; - /* "pysam/libcbcf.pyx":3774 + /* "pysam/libcbcf.pyx":4392 * if not self.header_written: * self.header_written = True * with nogil: # <<<<<<<<<<<<<< @@ -61166,7 +71083,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 #endif /*try:*/ { - /* "pysam/libcbcf.pyx":3775 + /* "pysam/libcbcf.pyx":4393 * self.header_written = True * with nogil: * bcf_hdr_write(self.htsfile, self.header.ptr) # <<<<<<<<<<<<<< @@ -61176,7 +71093,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 (void)(bcf_hdr_write(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->header->ptr)); } - /* "pysam/libcbcf.pyx":3774 + /* "pysam/libcbcf.pyx":4392 * if not self.header_written: * self.header_written = True * with nogil: # <<<<<<<<<<<<<< @@ -61195,7 +71112,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 } } - /* "pysam/libcbcf.pyx":3772 + /* "pysam/libcbcf.pyx":4390 * raise ValueError('cannot write to a Variantfile opened for reading') * * if not self.header_written: # <<<<<<<<<<<<<< @@ -61204,7 +71121,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 */ } - /* "pysam/libcbcf.pyx":3781 + /* "pysam/libcbcf.pyx":4399 * # raise ValueError('Writing records from a different VariantFile is not yet supported') * * if record.ptr.n_sample != bcf_hdr_nsamples(self.header.ptr): # <<<<<<<<<<<<<< @@ -61214,7 +71131,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 __pyx_t_7 = ((__pyx_v_record->ptr->n_sample != bcf_hdr_nsamples(__pyx_v_self->header->ptr)) != 0); if (unlikely(__pyx_t_7)) { - /* "pysam/libcbcf.pyx":3782 + /* "pysam/libcbcf.pyx":4400 * * if record.ptr.n_sample != bcf_hdr_nsamples(self.header.ptr): * msg = 'Invalid VariantRecord. Number of samples does not match header ({} vs {})' # <<<<<<<<<<<<<< @@ -61224,18 +71141,18 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 __Pyx_INCREF(__pyx_kp_s_Invalid_VariantRecord_Number_of); __pyx_v_msg = __pyx_kp_s_Invalid_VariantRecord_Number_of; - /* "pysam/libcbcf.pyx":3783 + /* "pysam/libcbcf.pyx":4401 * if record.ptr.n_sample != bcf_hdr_nsamples(self.header.ptr): * msg = 'Invalid VariantRecord. Number of samples does not match header ({} vs {})' * raise ValueError(msg.format(record.ptr.n_sample, bcf_hdr_nsamples(self.header.ptr))) # <<<<<<<<<<<<<< * - * cdef int ret + * # Sync END annotation before writing */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_msg, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3783, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_msg, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4401, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_record->ptr->n_sample); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3783, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_record->ptr->n_sample); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4401, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyInt_From_int32_t(bcf_hdr_nsamples(__pyx_v_self->header->ptr)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 3783, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_From_int32_t(bcf_hdr_nsamples(__pyx_v_self->header->ptr)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 4401, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = NULL; __pyx_t_6 = 0; @@ -61252,7 +71169,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_3, __pyx_t_5}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3783, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4401, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -61262,7 +71179,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_3, __pyx_t_5}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3783, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4401, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -61270,7 +71187,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 } else #endif { - __pyx_t_9 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3783, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4401, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (__pyx_t_4) { __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4); __pyx_t_4 = NULL; @@ -61281,19 +71198,19 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_5); __pyx_t_3 = 0; __pyx_t_5 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3783, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4401, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3783, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4401, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 3783, __pyx_L1_error) + __PYX_ERR(0, 4401, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3781 + /* "pysam/libcbcf.pyx":4399 * # raise ValueError('Writing records from a different VariantFile is not yet supported') * * if record.ptr.n_sample != bcf_hdr_nsamples(self.header.ptr): # <<<<<<<<<<<<<< @@ -61302,7 +71219,18 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 */ } - /* "pysam/libcbcf.pyx":3787 + /* "pysam/libcbcf.pyx":4404 + * + * # Sync END annotation before writing + * bcf_sync_end(record) # <<<<<<<<<<<<<< + * + * cdef int ret + */ + __pyx_t_2 = __pyx_f_5pysam_7libcbcf_bcf_sync_end(__pyx_v_record); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4404, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libcbcf.pyx":4408 * cdef int ret * * with nogil: # <<<<<<<<<<<<<< @@ -61317,7 +71245,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 #endif /*try:*/ { - /* "pysam/libcbcf.pyx":3788 + /* "pysam/libcbcf.pyx":4409 * * with nogil: * ret = bcf_write1(self.htsfile, self.header.ptr, record.ptr) # <<<<<<<<<<<<<< @@ -61327,7 +71255,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 __pyx_v_ret = bcf_write1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->header->ptr, __pyx_v_record->ptr); } - /* "pysam/libcbcf.pyx":3787 + /* "pysam/libcbcf.pyx":4408 * cdef int ret * * with nogil: # <<<<<<<<<<<<<< @@ -61346,7 +71274,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 } } - /* "pysam/libcbcf.pyx":3790 + /* "pysam/libcbcf.pyx":4411 * ret = bcf_write1(self.htsfile, self.header.ptr, record.ptr) * * if ret < 0: # <<<<<<<<<<<<<< @@ -61356,18 +71284,18 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 __pyx_t_7 = ((__pyx_v_ret < 0) != 0); if (unlikely(__pyx_t_7)) { - /* "pysam/libcbcf.pyx":3791 + /* "pysam/libcbcf.pyx":4412 * * if ret < 0: * raise IOError(errno, strerror(errno)) # <<<<<<<<<<<<<< * * return ret */ - __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3791, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3791, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 3791, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 4412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2); @@ -61375,14 +71303,14 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_1); __pyx_t_2 = 0; __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3791, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3791, __pyx_L1_error) + __PYX_ERR(0, 4412, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3790 + /* "pysam/libcbcf.pyx":4411 * ret = bcf_write1(self.htsfile, self.header.ptr, record.ptr) * * if ret < 0: # <<<<<<<<<<<<<< @@ -61391,7 +71319,7 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 */ } - /* "pysam/libcbcf.pyx":3793 + /* "pysam/libcbcf.pyx":4414 * raise IOError(errno, strerror(errno)) * * return ret # <<<<<<<<<<<<<< @@ -61401,8 +71329,8 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 __pyx_r = __pyx_v_ret; goto __pyx_L0; - /* "pysam/libcbcf.pyx":3757 - * return self.header.new_record() + /* "pysam/libcbcf.pyx":4375 + * return self.header.new_record(*args, **kwargs) * * cpdef int write(self, VariantRecord record) except -1: # <<<<<<<<<<<<<< * """ @@ -61427,14 +71355,14 @@ static int __pyx_f_5pysam_7libcbcf_11VariantFile_write(struct __pyx_obj_5pysam_7 } /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_21write(PyObject *__pyx_v_self, PyObject *__pyx_v_record); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_11VariantFile_20write[] = "VariantFile.write(self, VariantRecord record) -> int\n\n write a single :class:`pysam.VariantRecord` to disk.\n\n returns the number of bytes written.\n "; -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_21write(PyObject *__pyx_v_self, PyObject *__pyx_v_record) { +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_29write(PyObject *__pyx_v_self, PyObject *__pyx_v_record); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_28write[] = "VariantFile.write(self, VariantRecord record) -> int\n\n write a single :class:`pysam.VariantRecord` to disk.\n\n returns the number of bytes written.\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_29write(PyObject *__pyx_v_self, PyObject *__pyx_v_record) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_record), __pyx_ptype_5pysam_7libcbcf_VariantRecord, 1, "record", 0))) __PYX_ERR(0, 3757, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_20write(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), ((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_record)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_record), __pyx_ptype_5pysam_7libcbcf_VariantRecord, 1, "record", 0))) __PYX_ERR(0, 4375, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_28write(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), ((struct __pyx_obj_5pysam_7libcbcf_VariantRecord *)__pyx_v_record)); /* function exit code */ goto __pyx_L0; @@ -61445,17 +71373,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_21write(PyObject *__pyx_ return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_20write(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record) { +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_28write(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, struct __pyx_obj_5pysam_7libcbcf_VariantRecord *__pyx_v_record) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("write", 0); - __Pyx_TraceCall("write (wrapper)", __pyx_f[0], 3757, 0, __PYX_ERR(0, 3757, __pyx_L1_error)); + __Pyx_TraceCall("write (wrapper)", __pyx_f[0], 4375, 0, __PYX_ERR(0, 4375, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_7libcbcf_11VariantFile_write(__pyx_v_self, __pyx_v_record, 1); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 3757, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3757, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_7libcbcf_11VariantFile_write(__pyx_v_self, __pyx_v_record, 1); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 4375, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4375, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; @@ -61473,7 +71401,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_20write(struct __pyx_obj return __pyx_r; } -/* "pysam/libcbcf.pyx":3795 +/* "pysam/libcbcf.pyx":4416 * return ret * * def subset_samples(self, include_samples): # <<<<<<<<<<<<<< @@ -61482,20 +71410,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_20write(struct __pyx_obj */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_23subset_samples(PyObject *__pyx_v_self, PyObject *__pyx_v_include_samples); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_11VariantFile_22subset_samples[] = "VariantFile.subset_samples(self, include_samples)\n\n Read only a subset of samples to reduce processing time and memory.\n Must be called prior to retrieving records.\n "; -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_23subset_samples(PyObject *__pyx_v_self, PyObject *__pyx_v_include_samples) { +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_31subset_samples(PyObject *__pyx_v_self, PyObject *__pyx_v_include_samples); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_30subset_samples[] = "VariantFile.subset_samples(self, include_samples)\n\n Read only a subset of samples to reduce processing time and memory.\n Must be called prior to retrieving records.\n "; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_31subset_samples(PyObject *__pyx_v_self, PyObject *__pyx_v_include_samples) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("subset_samples (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_22subset_samples(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), ((PyObject *)__pyx_v_include_samples)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_30subset_samples(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), ((PyObject *)__pyx_v_include_samples)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_22subset_samples(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_include_samples) { +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_30subset_samples(struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, PyObject *__pyx_v_include_samples) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -61503,36 +71431,36 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_22subset_samples(struct int __pyx_t_2; int __pyx_t_3; __Pyx_RefNannySetupContext("subset_samples", 0); - __Pyx_TraceCall("subset_samples", __pyx_f[0], 3795, 0, __PYX_ERR(0, 3795, __pyx_L1_error)); + __Pyx_TraceCall("subset_samples", __pyx_f[0], 4416, 0, __PYX_ERR(0, 4416, __pyx_L1_error)); - /* "pysam/libcbcf.pyx":3800 + /* "pysam/libcbcf.pyx":4421 * Must be called prior to retrieving records. * """ * if not self.is_open: # <<<<<<<<<<<<<< * raise ValueError('I/O operation on closed file') * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3800, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4421, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 3800, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 4421, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = ((!__pyx_t_2) != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":3801 + /* "pysam/libcbcf.pyx":4422 * """ * if not self.is_open: * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< * * if self.htsfile.is_write: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__217, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3801, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__235, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4422, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3801, __pyx_L1_error) + __PYX_ERR(0, 4422, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3800 + /* "pysam/libcbcf.pyx":4421 * Must be called prior to retrieving records. * """ * if not self.is_open: # <<<<<<<<<<<<<< @@ -61541,7 +71469,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_22subset_samples(struct */ } - /* "pysam/libcbcf.pyx":3803 + /* "pysam/libcbcf.pyx":4424 * raise ValueError('I/O operation on closed file') * * if self.htsfile.is_write: # <<<<<<<<<<<<<< @@ -61551,20 +71479,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_22subset_samples(struct __pyx_t_3 = (__pyx_v_self->__pyx_base.htsfile->is_write != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":3804 + /* "pysam/libcbcf.pyx":4425 * * if self.htsfile.is_write: * raise ValueError('cannot subset samples from Variantfile opened for writing') # <<<<<<<<<<<<<< * * if self.is_reading: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__218, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3804, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__236, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4425, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3804, __pyx_L1_error) + __PYX_ERR(0, 4425, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3803 + /* "pysam/libcbcf.pyx":4424 * raise ValueError('I/O operation on closed file') * * if self.htsfile.is_write: # <<<<<<<<<<<<<< @@ -61573,7 +71501,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_22subset_samples(struct */ } - /* "pysam/libcbcf.pyx":3806 + /* "pysam/libcbcf.pyx":4427 * raise ValueError('cannot subset samples from Variantfile opened for writing') * * if self.is_reading: # <<<<<<<<<<<<<< @@ -61583,20 +71511,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_22subset_samples(struct __pyx_t_3 = (__pyx_v_self->is_reading != 0); if (unlikely(__pyx_t_3)) { - /* "pysam/libcbcf.pyx":3807 + /* "pysam/libcbcf.pyx":4428 * * if self.is_reading: * raise ValueError('cannot subset samples after fetching records') # <<<<<<<<<<<<<< * * self.header._subset_samples(include_samples) */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__219, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3807, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__237, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4428, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 3807, __pyx_L1_error) + __PYX_ERR(0, 4428, __pyx_L1_error) - /* "pysam/libcbcf.pyx":3806 + /* "pysam/libcbcf.pyx":4427 * raise ValueError('cannot subset samples from Variantfile opened for writing') * * if self.is_reading: # <<<<<<<<<<<<<< @@ -61605,35 +71533,35 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_22subset_samples(struct */ } - /* "pysam/libcbcf.pyx":3809 + /* "pysam/libcbcf.pyx":4430 * raise ValueError('cannot subset samples after fetching records') * * self.header._subset_samples(include_samples) # <<<<<<<<<<<<<< * * # potentially unnecessary optimization that also sets max_unpack */ - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_7libcbcf_VariantHeader *)__pyx_v_self->header->__pyx_vtab)->_subset_samples(__pyx_v_self->header, __pyx_v_include_samples); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3809, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_7libcbcf_VariantHeader *)__pyx_v_self->header->__pyx_vtab)->_subset_samples(__pyx_v_self->header, __pyx_v_include_samples); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4430, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":3812 + /* "pysam/libcbcf.pyx":4433 * * # potentially unnecessary optimization that also sets max_unpack * if not include_samples: # <<<<<<<<<<<<<< * self.drop_samples = True */ - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_include_samples); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 3812, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_include_samples); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 4433, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_3) != 0); if (__pyx_t_2) { - /* "pysam/libcbcf.pyx":3813 + /* "pysam/libcbcf.pyx":4434 * # potentially unnecessary optimization that also sets max_unpack * if not include_samples: * self.drop_samples = True # <<<<<<<<<<<<<< */ __pyx_v_self->drop_samples = 1; - /* "pysam/libcbcf.pyx":3812 + /* "pysam/libcbcf.pyx":4433 * * # potentially unnecessary optimization that also sets max_unpack * if not include_samples: # <<<<<<<<<<<<<< @@ -61641,7 +71569,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_22subset_samples(struct */ } - /* "pysam/libcbcf.pyx":3795 + /* "pysam/libcbcf.pyx":4416 * return ret * * def subset_samples(self, include_samples): # <<<<<<<<<<<<<< @@ -61663,7 +71591,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_22subset_samples(struct return __pyx_r; } -/* "pysam/libcbcf.pxd":133 +/* "pysam/libcbcf.pxd":132 * * cdef class VariantFile(HTSFile): * cdef readonly VariantHeader header # <<<<<<<<<<<<<< @@ -61689,7 +71617,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6header___get__(struct _ __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 133, 0, __PYX_ERR(2, 133, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[1], 132, 0, __PYX_ERR(1, 132, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_self->header)); __pyx_r = ((PyObject *)__pyx_v_self->header); @@ -61706,7 +71634,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_6header___get__(struct _ return __pyx_r; } -/* "pysam/libcbcf.pxd":134 +/* "pysam/libcbcf.pxd":133 * cdef class VariantFile(HTSFile): * cdef readonly VariantHeader header * cdef readonly BaseIndex index # <<<<<<<<<<<<<< @@ -61732,7 +71660,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_5index___get__(struct __ __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 134, 0, __PYX_ERR(2, 134, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[1], 133, 0, __PYX_ERR(1, 133, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_self->index)); __pyx_r = ((PyObject *)__pyx_v_self->index); @@ -61749,7 +71677,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_5index___get__(struct __ return __pyx_r; } -/* "pysam/libcbcf.pxd":136 +/* "pysam/libcbcf.pxd":135 * cdef readonly BaseIndex index * * cdef readonly bint drop_samples # true if sample information is to be ignored # <<<<<<<<<<<<<< @@ -61776,9 +71704,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12drop_samples___get__(s __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 136, 0, __PYX_ERR(2, 136, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[1], 135, 0, __PYX_ERR(1, 135, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->drop_samples); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 136, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->drop_samples); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -61796,7 +71724,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_12drop_samples___get__(s return __pyx_r; } -/* "pysam/libcbcf.pxd":139 +/* "pysam/libcbcf.pxd":138 * * # FIXME: Temporary, use htsFormat when it is available * cdef readonly bint is_reading # true if file has begun reading records # <<<<<<<<<<<<<< @@ -61823,9 +71751,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10is_reading___get__(str __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 139, 0, __PYX_ERR(2, 139, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[1], 138, 0, __PYX_ERR(1, 138, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_reading); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 139, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_reading); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 138, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -61843,12 +71771,12 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_10is_reading___get__(str return __pyx_r; } -/* "pysam/libcbcf.pxd":140 +/* "pysam/libcbcf.pxd":139 * # FIXME: Temporary, use htsFormat when it is available * cdef readonly bint is_reading # true if file has begun reading records * cdef readonly bint header_written # true if header has already been written # <<<<<<<<<<<<<< * - * cpdef VariantRecord new_record(self) + * cpdef int write(self, VariantRecord record) except -1 */ /* Python wrapper */ @@ -61870,9 +71798,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_14header_written___get__ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 140, 0, __PYX_ERR(2, 140, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[1], 139, 0, __PYX_ERR(1, 139, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->header_written); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 140, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->header_written); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -61897,26 +71825,26 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_14header_written___get__ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_25__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_11VariantFile_24__reduce_cython__[] = "VariantFile.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_25__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_33__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_32__reduce_cython__[] = "VariantFile.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_33__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_24__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_32__reduce_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_24__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_32__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -61924,11 +71852,11 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_24__reduce_cython__(CYTH * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__220, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__238, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + __PYX_ERR(2, 2, __pyx_L1_error) /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< @@ -61955,37 +71883,37 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_24__reduce_cython__(CYTH */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_27__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_7libcbcf_11VariantFile_26__setstate_cython__[] = "VariantFile.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_27__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_35__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_7libcbcf_11VariantFile_34__setstate_cython__[] = "VariantFile.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_7libcbcf_11VariantFile_35__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_26__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_7libcbcf_11VariantFile_34__setstate_cython__(((struct __pyx_obj_5pysam_7libcbcf_VariantFile *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_26__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_7libcbcf_11VariantFile_34__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_7libcbcf_VariantFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[2], 3, 0, __PYX_ERR(2, 3, __pyx_L1_error)); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__221, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__239, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":3 * def __reduce_cython__(self): @@ -62047,17 +71975,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_1__pyx_unpickle_VariantHeaderRecords(P case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderRecords", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderRecords", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderRecords", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderRecords", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantHeaderRecords") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantHeaderRecords") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -62067,12 +71995,12 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_1__pyx_unpickle_VariantHeaderRecords(P values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderRecords", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderRecords", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.__pyx_unpickle_VariantHeaderRecords", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -62098,9 +72026,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords(CY PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__222) + __Pyx_TraceFrameInit(__pyx_codeobj__240) __Pyx_RefNannySetupContext("__pyx_unpickle_VariantHeaderRecords", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantHeaderRecords", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantHeaderRecords", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __pyx_unpickle_VariantHeaderRecords(__pyx_type, long __pyx_checksum, __pyx_state): @@ -62118,15 +72046,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords(CY * raise __pyx_PickleError("Incompatible checksums (%s vs 0x099fb99 = (header))" % __pyx_checksum) * __pyx_result = VariantHeaderRecords.__new__(__pyx_type) */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; @@ -62140,9 +72068,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords(CY * __pyx_result = VariantHeaderRecords.__new__(__pyx_type) * if __pyx_state is not None: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x09, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x09, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); @@ -62157,14 +72085,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords(CY } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -62173,20 +72101,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords(CY #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -62194,7 +72122,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords(CY __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":2 * def __pyx_unpickle_VariantHeaderRecords(__pyx_type, long __pyx_checksum, __pyx_state): @@ -62211,7 +72139,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords(CY * if __pyx_state is not None: * __pyx_unpickle_VariantHeaderRecords__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderRecords), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderRecords), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -62224,13 +72152,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords(CY } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -62238,19 +72166,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords(CY #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v___pyx_type); __Pyx_GIVEREF(__pyx_v___pyx_type); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -62277,8 +72205,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords(CY * return __pyx_result * cdef __pyx_unpickle_VariantHeaderRecords__set_state(VariantHeaderRecords __pyx_result, tuple __pyx_state): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderRecords *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -62349,7 +72277,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords__se PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("__pyx_unpickle_VariantHeaderRecords__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantHeaderRecords__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantHeaderRecords__set_state", __pyx_f[2], 9, 0, __PYX_ERR(2, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result @@ -62360,11 +72288,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords__se */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->header); __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->header)); @@ -62379,16 +72307,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords__se */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) + __PYX_ERR(2, 11, __pyx_L1_error) } - __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_4 = ((__pyx_t_3 > 1) != 0); if (__pyx_t_4) { } else { __pyx_t_2 = __pyx_t_4; goto __pyx_L4_bool_binop_done; } - __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_5 = (__pyx_t_4 != 0); __pyx_t_2 = __pyx_t_5; __pyx_L4_bool_binop_done:; @@ -62399,16 +72327,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords__se * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) + __PYX_ERR(2, 12, __pyx_L1_error) } - __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { @@ -62421,14 +72349,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords__se } } if (!__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -62437,20 +72365,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderRecords__se #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6); __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } @@ -62534,17 +72462,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_3__pyx_unpickle_VariantMetadata(PyObje case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantMetadata", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantMetadata", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantMetadata", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantMetadata", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantMetadata") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantMetadata") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -62554,12 +72482,12 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_3__pyx_unpickle_VariantMetadata(PyObje values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantMetadata", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantMetadata", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.__pyx_unpickle_VariantMetadata", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -62585,9 +72513,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_2__pyx_unpickle_VariantMetadata(CYTHON PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__223) + __Pyx_TraceFrameInit(__pyx_codeobj__241) __Pyx_RefNannySetupContext("__pyx_unpickle_VariantMetadata", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantMetadata", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantMetadata", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __pyx_unpickle_VariantMetadata(__pyx_type, long __pyx_checksum, __pyx_state): @@ -62605,15 +72533,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_2__pyx_unpickle_VariantMetadata(CYTHON * raise __pyx_PickleError("Incompatible checksums (%s vs 0x9d0a56c = (header, id, type))" % __pyx_checksum) * __pyx_result = VariantMetadata.__new__(__pyx_type) */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; @@ -62627,9 +72555,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_2__pyx_unpickle_VariantMetadata(CYTHON * __pyx_result = VariantMetadata.__new__(__pyx_type) * if __pyx_state is not None: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x9d, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x9d, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); @@ -62644,14 +72572,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_2__pyx_unpickle_VariantMetadata(CYTHON } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -62660,20 +72588,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_2__pyx_unpickle_VariantMetadata(CYTHON #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -62681,7 +72609,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_2__pyx_unpickle_VariantMetadata(CYTHON __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":2 * def __pyx_unpickle_VariantMetadata(__pyx_type, long __pyx_checksum, __pyx_state): @@ -62698,7 +72626,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_2__pyx_unpickle_VariantMetadata(CYTHON * if __pyx_state is not None: * __pyx_unpickle_VariantMetadata__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantMetadata), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantMetadata), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -62711,13 +72639,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_2__pyx_unpickle_VariantMetadata(CYTHON } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -62725,19 +72653,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_2__pyx_unpickle_VariantMetadata(CYTHON #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v___pyx_type); __Pyx_GIVEREF(__pyx_v___pyx_type); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -62764,8 +72692,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_2__pyx_unpickle_VariantMetadata(CYTHON * return __pyx_result * cdef __pyx_unpickle_VariantMetadata__set_state(VariantMetadata __pyx_result, tuple __pyx_state): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantMetadata__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantMetadata__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantMetadata *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -62837,7 +72765,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantMetadata__set_sta PyObject *__pyx_t_9 = NULL; PyObject *__pyx_t_10 = NULL; __Pyx_RefNannySetupContext("__pyx_unpickle_VariantMetadata__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantMetadata__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantMetadata__set_state", __pyx_f[2], 9, 0, __PYX_ERR(2, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result @@ -62848,11 +72776,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantMetadata__set_sta */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->header); __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->header)); @@ -62860,20 +72788,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantMetadata__set_sta __pyx_t_1 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->id = __pyx_t_2; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->type = __pyx_t_2; @@ -62885,16 +72813,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantMetadata__set_sta */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) + __PYX_ERR(2, 11, __pyx_L1_error) } - __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_5 = ((__pyx_t_4 > 3) != 0); if (__pyx_t_5) { } else { __pyx_t_3 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } - __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_6 = (__pyx_t_5 != 0); __pyx_t_3 = __pyx_t_6; __pyx_L4_bool_binop_done:; @@ -62905,16 +72833,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantMetadata__set_sta * if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[3]) # <<<<<<<<<<<<<< */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) + __PYX_ERR(2, 12, __pyx_L1_error) } - __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { @@ -62927,14 +72855,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantMetadata__set_sta } } if (!__pyx_t_9) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_8)) { PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; @@ -62943,20 +72871,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantMetadata__set_sta #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else #endif { - __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_7); __pyx_t_7 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } @@ -63040,17 +72968,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_5__pyx_unpickle_VariantHeaderMetadata( case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderMetadata", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderMetadata", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderMetadata", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderMetadata", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantHeaderMetadata") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantHeaderMetadata") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -63060,12 +72988,12 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_5__pyx_unpickle_VariantHeaderMetadata( values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderMetadata", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderMetadata", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.__pyx_unpickle_VariantHeaderMetadata", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -63091,9 +73019,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_4__pyx_unpickle_VariantHeaderMetadata( PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__224) + __Pyx_TraceFrameInit(__pyx_codeobj__242) __Pyx_RefNannySetupContext("__pyx_unpickle_VariantHeaderMetadata", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantHeaderMetadata", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantHeaderMetadata", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __pyx_unpickle_VariantHeaderMetadata(__pyx_type, long __pyx_checksum, __pyx_state): @@ -63111,15 +73039,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_4__pyx_unpickle_VariantHeaderMetadata( * raise __pyx_PickleError("Incompatible checksums (%s vs 0xed5e66b = (header, type))" % __pyx_checksum) * __pyx_result = VariantHeaderMetadata.__new__(__pyx_type) */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; @@ -63133,9 +73061,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_4__pyx_unpickle_VariantHeaderMetadata( * __pyx_result = VariantHeaderMetadata.__new__(__pyx_type) * if __pyx_state is not None: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xed, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xed, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); @@ -63150,14 +73078,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_4__pyx_unpickle_VariantHeaderMetadata( } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -63166,20 +73094,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_4__pyx_unpickle_VariantHeaderMetadata( #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -63187,7 +73115,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_4__pyx_unpickle_VariantHeaderMetadata( __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":2 * def __pyx_unpickle_VariantHeaderMetadata(__pyx_type, long __pyx_checksum, __pyx_state): @@ -63204,7 +73132,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_4__pyx_unpickle_VariantHeaderMetadata( * if __pyx_state is not None: * __pyx_unpickle_VariantHeaderMetadata__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderMetadata), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderMetadata), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -63217,13 +73145,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_4__pyx_unpickle_VariantHeaderMetadata( } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -63231,19 +73159,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_4__pyx_unpickle_VariantHeaderMetadata( #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v___pyx_type); __Pyx_GIVEREF(__pyx_v___pyx_type); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -63270,8 +73198,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_4__pyx_unpickle_VariantHeaderMetadata( * return __pyx_result * cdef __pyx_unpickle_VariantHeaderMetadata__set_state(VariantHeaderMetadata __pyx_result, tuple __pyx_state): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderMetadata__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderMetadata__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderMetadata *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -63343,7 +73271,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderMetadata__s PyObject *__pyx_t_9 = NULL; PyObject *__pyx_t_10 = NULL; __Pyx_RefNannySetupContext("__pyx_unpickle_VariantHeaderMetadata__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantHeaderMetadata__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantHeaderMetadata__set_state", __pyx_f[2], 9, 0, __PYX_ERR(2, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result @@ -63354,11 +73282,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderMetadata__s */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->header); __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->header)); @@ -63366,11 +73294,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderMetadata__s __pyx_t_1 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_2 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_2 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->type = __pyx_t_2; @@ -63382,16 +73310,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderMetadata__s */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) + __PYX_ERR(2, 11, __pyx_L1_error) } - __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_5 = ((__pyx_t_4 > 2) != 0); if (__pyx_t_5) { } else { __pyx_t_3 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } - __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_6 = (__pyx_t_5 != 0); __pyx_t_3 = __pyx_t_6; __pyx_L4_bool_binop_done:; @@ -63402,16 +73330,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderMetadata__s * if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[2]) # <<<<<<<<<<<<<< */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) + __PYX_ERR(2, 12, __pyx_L1_error) } - __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { @@ -63424,14 +73352,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderMetadata__s } } if (!__pyx_t_9) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_8)) { PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; @@ -63440,20 +73368,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderMetadata__s #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else #endif { - __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_7); __pyx_t_7 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } @@ -63537,17 +73465,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_7__pyx_unpickle_VariantContig(PyObject case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantContig", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantContig", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantContig", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantContig", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantContig") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantContig") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -63557,12 +73485,12 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_7__pyx_unpickle_VariantContig(PyObject values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantContig", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantContig", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.__pyx_unpickle_VariantContig", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -63588,9 +73516,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_6__pyx_unpickle_VariantContig(CYTHON_U PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__225) + __Pyx_TraceFrameInit(__pyx_codeobj__243) __Pyx_RefNannySetupContext("__pyx_unpickle_VariantContig", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantContig", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantContig", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __pyx_unpickle_VariantContig(__pyx_type, long __pyx_checksum, __pyx_state): @@ -63608,15 +73536,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_6__pyx_unpickle_VariantContig(CYTHON_U * raise __pyx_PickleError("Incompatible checksums (%s vs 0xbe66ecb = (header, id))" % __pyx_checksum) * __pyx_result = VariantContig.__new__(__pyx_type) */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; @@ -63630,9 +73558,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_6__pyx_unpickle_VariantContig(CYTHON_U * __pyx_result = VariantContig.__new__(__pyx_type) * if __pyx_state is not None: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xbe, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xbe, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); @@ -63647,14 +73575,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_6__pyx_unpickle_VariantContig(CYTHON_U } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -63663,20 +73591,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_6__pyx_unpickle_VariantContig(CYTHON_U #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -63684,7 +73612,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_6__pyx_unpickle_VariantContig(CYTHON_U __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":2 * def __pyx_unpickle_VariantContig(__pyx_type, long __pyx_checksum, __pyx_state): @@ -63701,7 +73629,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_6__pyx_unpickle_VariantContig(CYTHON_U * if __pyx_state is not None: * __pyx_unpickle_VariantContig__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantContig), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantContig), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -63714,13 +73642,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_6__pyx_unpickle_VariantContig(CYTHON_U } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -63728,19 +73656,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_6__pyx_unpickle_VariantContig(CYTHON_U #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v___pyx_type); __Pyx_GIVEREF(__pyx_v___pyx_type); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -63767,8 +73695,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_6__pyx_unpickle_VariantContig(CYTHON_U * return __pyx_result * cdef __pyx_unpickle_VariantContig__set_state(VariantContig __pyx_result, tuple __pyx_state): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantContig__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantContig *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantContig__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantContig *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -63840,7 +73768,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantContig__set_state PyObject *__pyx_t_9 = NULL; PyObject *__pyx_t_10 = NULL; __Pyx_RefNannySetupContext("__pyx_unpickle_VariantContig__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantContig__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantContig__set_state", __pyx_f[2], 9, 0, __PYX_ERR(2, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result @@ -63851,11 +73779,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantContig__set_state */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->header); __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->header)); @@ -63863,11 +73791,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantContig__set_state __pyx_t_1 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->id = __pyx_t_2; @@ -63879,16 +73807,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantContig__set_state */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) + __PYX_ERR(2, 11, __pyx_L1_error) } - __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_5 = ((__pyx_t_4 > 2) != 0); if (__pyx_t_5) { } else { __pyx_t_3 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } - __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_6 = (__pyx_t_5 != 0); __pyx_t_3 = __pyx_t_6; __pyx_L4_bool_binop_done:; @@ -63899,16 +73827,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantContig__set_state * if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[2]) # <<<<<<<<<<<<<< */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) + __PYX_ERR(2, 12, __pyx_L1_error) } - __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { @@ -63921,14 +73849,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantContig__set_state } } if (!__pyx_t_9) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_8)) { PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; @@ -63937,20 +73865,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantContig__set_state #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else #endif { - __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_7); __pyx_t_7 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } @@ -64034,17 +73962,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_9__pyx_unpickle_VariantHeaderContigs(P case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderContigs", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderContigs", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderContigs", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderContigs", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantHeaderContigs") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantHeaderContigs") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -64054,12 +73982,12 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_9__pyx_unpickle_VariantHeaderContigs(P values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderContigs", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderContigs", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.__pyx_unpickle_VariantHeaderContigs", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -64085,9 +74013,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8__pyx_unpickle_VariantHeaderContigs(C PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__226) + __Pyx_TraceFrameInit(__pyx_codeobj__244) __Pyx_RefNannySetupContext("__pyx_unpickle_VariantHeaderContigs", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantHeaderContigs", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantHeaderContigs", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __pyx_unpickle_VariantHeaderContigs(__pyx_type, long __pyx_checksum, __pyx_state): @@ -64105,15 +74033,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8__pyx_unpickle_VariantHeaderContigs(C * raise __pyx_PickleError("Incompatible checksums (%s vs 0x099fb99 = (header))" % __pyx_checksum) * __pyx_result = VariantHeaderContigs.__new__(__pyx_type) */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; @@ -64127,9 +74055,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8__pyx_unpickle_VariantHeaderContigs(C * __pyx_result = VariantHeaderContigs.__new__(__pyx_type) * if __pyx_state is not None: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x09, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x09, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); @@ -64144,14 +74072,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8__pyx_unpickle_VariantHeaderContigs(C } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -64160,20 +74088,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8__pyx_unpickle_VariantHeaderContigs(C #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -64181,7 +74109,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8__pyx_unpickle_VariantHeaderContigs(C __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":2 * def __pyx_unpickle_VariantHeaderContigs(__pyx_type, long __pyx_checksum, __pyx_state): @@ -64198,7 +74126,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8__pyx_unpickle_VariantHeaderContigs(C * if __pyx_state is not None: * __pyx_unpickle_VariantHeaderContigs__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderContigs), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderContigs), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -64211,13 +74139,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8__pyx_unpickle_VariantHeaderContigs(C } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -64225,19 +74153,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8__pyx_unpickle_VariantHeaderContigs(C #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v___pyx_type); __Pyx_GIVEREF(__pyx_v___pyx_type); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -64264,8 +74192,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_8__pyx_unpickle_VariantHeaderContigs(C * return __pyx_result * cdef __pyx_unpickle_VariantHeaderContigs__set_state(VariantHeaderContigs __pyx_result, tuple __pyx_state): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderContigs__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderContigs__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderContigs *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -64336,7 +74264,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderContigs__se PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("__pyx_unpickle_VariantHeaderContigs__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantHeaderContigs__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantHeaderContigs__set_state", __pyx_f[2], 9, 0, __PYX_ERR(2, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result @@ -64347,11 +74275,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderContigs__se */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->header); __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->header)); @@ -64366,16 +74294,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderContigs__se */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) + __PYX_ERR(2, 11, __pyx_L1_error) } - __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_4 = ((__pyx_t_3 > 1) != 0); if (__pyx_t_4) { } else { __pyx_t_2 = __pyx_t_4; goto __pyx_L4_bool_binop_done; } - __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_5 = (__pyx_t_4 != 0); __pyx_t_2 = __pyx_t_5; __pyx_L4_bool_binop_done:; @@ -64386,16 +74314,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderContigs__se * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) + __PYX_ERR(2, 12, __pyx_L1_error) } - __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { @@ -64408,14 +74336,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderContigs__se } } if (!__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -64424,20 +74352,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderContigs__se #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6); __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } @@ -64521,17 +74449,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_11__pyx_unpickle_VariantHeaderSamples( case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderSamples", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderSamples", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderSamples", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderSamples", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantHeaderSamples") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantHeaderSamples") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -64541,12 +74469,12 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_11__pyx_unpickle_VariantHeaderSamples( values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderSamples", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantHeaderSamples", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.__pyx_unpickle_VariantHeaderSamples", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -64572,9 +74500,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10__pyx_unpickle_VariantHeaderSamples( PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__227) + __Pyx_TraceFrameInit(__pyx_codeobj__245) __Pyx_RefNannySetupContext("__pyx_unpickle_VariantHeaderSamples", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantHeaderSamples", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantHeaderSamples", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __pyx_unpickle_VariantHeaderSamples(__pyx_type, long __pyx_checksum, __pyx_state): @@ -64592,15 +74520,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10__pyx_unpickle_VariantHeaderSamples( * raise __pyx_PickleError("Incompatible checksums (%s vs 0x099fb99 = (header))" % __pyx_checksum) * __pyx_result = VariantHeaderSamples.__new__(__pyx_type) */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; @@ -64614,9 +74542,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10__pyx_unpickle_VariantHeaderSamples( * __pyx_result = VariantHeaderSamples.__new__(__pyx_type) * if __pyx_state is not None: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x09, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x09, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); @@ -64631,14 +74559,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10__pyx_unpickle_VariantHeaderSamples( } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -64647,20 +74575,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10__pyx_unpickle_VariantHeaderSamples( #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -64668,7 +74596,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10__pyx_unpickle_VariantHeaderSamples( __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":2 * def __pyx_unpickle_VariantHeaderSamples(__pyx_type, long __pyx_checksum, __pyx_state): @@ -64685,7 +74613,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10__pyx_unpickle_VariantHeaderSamples( * if __pyx_state is not None: * __pyx_unpickle_VariantHeaderSamples__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderSamples), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderSamples), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -64698,13 +74626,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10__pyx_unpickle_VariantHeaderSamples( } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -64712,19 +74640,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10__pyx_unpickle_VariantHeaderSamples( #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v___pyx_type); __Pyx_GIVEREF(__pyx_v___pyx_type); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -64751,8 +74679,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_10__pyx_unpickle_VariantHeaderSamples( * return __pyx_result * cdef __pyx_unpickle_VariantHeaderSamples__set_state(VariantHeaderSamples __pyx_result, tuple __pyx_state): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderSamples__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderSamples__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantHeaderSamples *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -64823,7 +74751,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderSamples__se PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("__pyx_unpickle_VariantHeaderSamples__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantHeaderSamples__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantHeaderSamples__set_state", __pyx_f[2], 9, 0, __PYX_ERR(2, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result @@ -64834,11 +74762,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderSamples__se */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantHeader))))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->header); __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->header)); @@ -64853,16 +74781,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderSamples__se */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) + __PYX_ERR(2, 11, __pyx_L1_error) } - __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_4 = ((__pyx_t_3 > 1) != 0); if (__pyx_t_4) { } else { __pyx_t_2 = __pyx_t_4; goto __pyx_L4_bool_binop_done; } - __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_5 = (__pyx_t_4 != 0); __pyx_t_2 = __pyx_t_5; __pyx_L4_bool_binop_done:; @@ -64873,16 +74801,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderSamples__se * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) + __PYX_ERR(2, 12, __pyx_L1_error) } - __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { @@ -64895,14 +74823,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderSamples__se } } if (!__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -64911,20 +74839,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantHeaderSamples__se #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6); __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } @@ -65008,17 +74936,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_13__pyx_unpickle_VariantRecordFilter(P case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordFilter", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordFilter", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordFilter", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordFilter", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantRecordFilter") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantRecordFilter") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -65028,12 +74956,12 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_13__pyx_unpickle_VariantRecordFilter(P values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordFilter", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordFilter", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.__pyx_unpickle_VariantRecordFilter", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -65059,9 +74987,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12__pyx_unpickle_VariantRecordFilter(C PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__228) + __Pyx_TraceFrameInit(__pyx_codeobj__246) __Pyx_RefNannySetupContext("__pyx_unpickle_VariantRecordFilter", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantRecordFilter", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantRecordFilter", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __pyx_unpickle_VariantRecordFilter(__pyx_type, long __pyx_checksum, __pyx_state): @@ -65079,15 +75007,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12__pyx_unpickle_VariantRecordFilter(C * raise __pyx_PickleError("Incompatible checksums (%s vs 0xde17f0f = (record))" % __pyx_checksum) * __pyx_result = VariantRecordFilter.__new__(__pyx_type) */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; @@ -65101,9 +75029,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12__pyx_unpickle_VariantRecordFilter(C * __pyx_result = VariantRecordFilter.__new__(__pyx_type) * if __pyx_state is not None: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xde, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xde, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); @@ -65118,14 +75046,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12__pyx_unpickle_VariantRecordFilter(C } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -65134,20 +75062,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12__pyx_unpickle_VariantRecordFilter(C #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -65155,7 +75083,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12__pyx_unpickle_VariantRecordFilter(C __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":2 * def __pyx_unpickle_VariantRecordFilter(__pyx_type, long __pyx_checksum, __pyx_state): @@ -65172,7 +75100,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12__pyx_unpickle_VariantRecordFilter(C * if __pyx_state is not None: * __pyx_unpickle_VariantRecordFilter__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordFilter), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordFilter), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -65185,13 +75113,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12__pyx_unpickle_VariantRecordFilter(C } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -65199,19 +75127,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12__pyx_unpickle_VariantRecordFilter(C #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v___pyx_type); __Pyx_GIVEREF(__pyx_v___pyx_type); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -65238,8 +75166,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_12__pyx_unpickle_VariantRecordFilter(C * return __pyx_result * cdef __pyx_unpickle_VariantRecordFilter__set_state(VariantRecordFilter __pyx_result, tuple __pyx_state): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFilter__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFilter__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFilter *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -65310,7 +75238,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFilter__set PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("__pyx_unpickle_VariantRecordFilter__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantRecordFilter__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantRecordFilter__set_state", __pyx_f[2], 9, 0, __PYX_ERR(2, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result @@ -65321,11 +75249,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFilter__set */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantRecord))))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantRecord))))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->record); __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->record)); @@ -65340,16 +75268,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFilter__set */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) + __PYX_ERR(2, 11, __pyx_L1_error) } - __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_4 = ((__pyx_t_3 > 1) != 0); if (__pyx_t_4) { } else { __pyx_t_2 = __pyx_t_4; goto __pyx_L4_bool_binop_done; } - __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_5 = (__pyx_t_4 != 0); __pyx_t_2 = __pyx_t_5; __pyx_L4_bool_binop_done:; @@ -65360,16 +75288,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFilter__set * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) + __PYX_ERR(2, 12, __pyx_L1_error) } - __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { @@ -65382,14 +75310,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFilter__set } } if (!__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -65398,20 +75326,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFilter__set #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6); __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } @@ -65495,17 +75423,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_15__pyx_unpickle_VariantRecordFormat(P case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordFormat", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordFormat", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordFormat", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordFormat", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantRecordFormat") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantRecordFormat") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -65515,12 +75443,12 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_15__pyx_unpickle_VariantRecordFormat(P values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordFormat", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordFormat", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.__pyx_unpickle_VariantRecordFormat", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -65546,9 +75474,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_14__pyx_unpickle_VariantRecordFormat(C PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__229) + __Pyx_TraceFrameInit(__pyx_codeobj__247) __Pyx_RefNannySetupContext("__pyx_unpickle_VariantRecordFormat", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantRecordFormat", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantRecordFormat", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __pyx_unpickle_VariantRecordFormat(__pyx_type, long __pyx_checksum, __pyx_state): @@ -65566,15 +75494,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_14__pyx_unpickle_VariantRecordFormat(C * raise __pyx_PickleError("Incompatible checksums (%s vs 0xde17f0f = (record))" % __pyx_checksum) * __pyx_result = VariantRecordFormat.__new__(__pyx_type) */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; @@ -65588,9 +75516,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_14__pyx_unpickle_VariantRecordFormat(C * __pyx_result = VariantRecordFormat.__new__(__pyx_type) * if __pyx_state is not None: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xde, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xde, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); @@ -65605,14 +75533,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_14__pyx_unpickle_VariantRecordFormat(C } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -65621,20 +75549,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_14__pyx_unpickle_VariantRecordFormat(C #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -65642,7 +75570,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_14__pyx_unpickle_VariantRecordFormat(C __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":2 * def __pyx_unpickle_VariantRecordFormat(__pyx_type, long __pyx_checksum, __pyx_state): @@ -65659,7 +75587,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_14__pyx_unpickle_VariantRecordFormat(C * if __pyx_state is not None: * __pyx_unpickle_VariantRecordFormat__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordFormat), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordFormat), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -65672,13 +75600,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_14__pyx_unpickle_VariantRecordFormat(C } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -65686,19 +75614,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_14__pyx_unpickle_VariantRecordFormat(C #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v___pyx_type); __Pyx_GIVEREF(__pyx_v___pyx_type); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -65725,8 +75653,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_14__pyx_unpickle_VariantRecordFormat(C * return __pyx_result * cdef __pyx_unpickle_VariantRecordFormat__set_state(VariantRecordFormat __pyx_result, tuple __pyx_state): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFormat__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFormat__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordFormat *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -65797,7 +75725,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFormat__set PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("__pyx_unpickle_VariantRecordFormat__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantRecordFormat__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantRecordFormat__set_state", __pyx_f[2], 9, 0, __PYX_ERR(2, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result @@ -65808,11 +75736,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFormat__set */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantRecord))))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantRecord))))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->record); __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->record)); @@ -65827,16 +75755,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFormat__set */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) + __PYX_ERR(2, 11, __pyx_L1_error) } - __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_4 = ((__pyx_t_3 > 1) != 0); if (__pyx_t_4) { } else { __pyx_t_2 = __pyx_t_4; goto __pyx_L4_bool_binop_done; } - __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_5 = (__pyx_t_4 != 0); __pyx_t_2 = __pyx_t_5; __pyx_L4_bool_binop_done:; @@ -65847,16 +75775,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFormat__set * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) + __PYX_ERR(2, 12, __pyx_L1_error) } - __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { @@ -65869,14 +75797,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFormat__set } } if (!__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -65885,20 +75813,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordFormat__set #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6); __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } @@ -65982,17 +75910,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_17__pyx_unpickle_VariantRecordInfo(PyO case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordInfo", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordInfo", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordInfo", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordInfo", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantRecordInfo") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantRecordInfo") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -66002,12 +75930,12 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_17__pyx_unpickle_VariantRecordInfo(PyO values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordInfo", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordInfo", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.__pyx_unpickle_VariantRecordInfo", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -66033,9 +75961,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_16__pyx_unpickle_VariantRecordInfo(CYT PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__230) + __Pyx_TraceFrameInit(__pyx_codeobj__248) __Pyx_RefNannySetupContext("__pyx_unpickle_VariantRecordInfo", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantRecordInfo", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantRecordInfo", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __pyx_unpickle_VariantRecordInfo(__pyx_type, long __pyx_checksum, __pyx_state): @@ -66053,15 +75981,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_16__pyx_unpickle_VariantRecordInfo(CYT * raise __pyx_PickleError("Incompatible checksums (%s vs 0xde17f0f = (record))" % __pyx_checksum) * __pyx_result = VariantRecordInfo.__new__(__pyx_type) */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; @@ -66075,9 +76003,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_16__pyx_unpickle_VariantRecordInfo(CYT * __pyx_result = VariantRecordInfo.__new__(__pyx_type) * if __pyx_state is not None: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xde, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xde, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); @@ -66092,14 +76020,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_16__pyx_unpickle_VariantRecordInfo(CYT } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -66108,20 +76036,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_16__pyx_unpickle_VariantRecordInfo(CYT #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -66129,7 +76057,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_16__pyx_unpickle_VariantRecordInfo(CYT __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":2 * def __pyx_unpickle_VariantRecordInfo(__pyx_type, long __pyx_checksum, __pyx_state): @@ -66146,7 +76074,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_16__pyx_unpickle_VariantRecordInfo(CYT * if __pyx_state is not None: * __pyx_unpickle_VariantRecordInfo__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordInfo), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordInfo), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -66159,13 +76087,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_16__pyx_unpickle_VariantRecordInfo(CYT } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -66173,19 +76101,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_16__pyx_unpickle_VariantRecordInfo(CYT #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v___pyx_type); __Pyx_GIVEREF(__pyx_v___pyx_type); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -66212,8 +76140,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_16__pyx_unpickle_VariantRecordInfo(CYT * return __pyx_result * cdef __pyx_unpickle_VariantRecordInfo__set_state(VariantRecordInfo __pyx_result, tuple __pyx_state): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordInfo__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordInfo__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordInfo *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -66284,7 +76212,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordInfo__set_s PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("__pyx_unpickle_VariantRecordInfo__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantRecordInfo__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantRecordInfo__set_state", __pyx_f[2], 9, 0, __PYX_ERR(2, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result @@ -66295,11 +76223,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordInfo__set_s */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantRecord))))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantRecord))))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->record); __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->record)); @@ -66314,16 +76242,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordInfo__set_s */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) + __PYX_ERR(2, 11, __pyx_L1_error) } - __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_4 = ((__pyx_t_3 > 1) != 0); if (__pyx_t_4) { } else { __pyx_t_2 = __pyx_t_4; goto __pyx_L4_bool_binop_done; } - __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_5 = (__pyx_t_4 != 0); __pyx_t_2 = __pyx_t_5; __pyx_L4_bool_binop_done:; @@ -66334,16 +76262,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordInfo__set_s * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) + __PYX_ERR(2, 12, __pyx_L1_error) } - __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { @@ -66356,14 +76284,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordInfo__set_s } } if (!__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -66372,20 +76300,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordInfo__set_s #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6); __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } @@ -66469,17 +76397,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_19__pyx_unpickle_VariantRecordSamples( case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordSamples", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordSamples", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordSamples", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordSamples", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantRecordSamples") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantRecordSamples") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -66489,12 +76417,12 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_19__pyx_unpickle_VariantRecordSamples( values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordSamples", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordSamples", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.__pyx_unpickle_VariantRecordSamples", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -66520,9 +76448,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_18__pyx_unpickle_VariantRecordSamples( PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__231) + __Pyx_TraceFrameInit(__pyx_codeobj__249) __Pyx_RefNannySetupContext("__pyx_unpickle_VariantRecordSamples", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantRecordSamples", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantRecordSamples", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __pyx_unpickle_VariantRecordSamples(__pyx_type, long __pyx_checksum, __pyx_state): @@ -66540,15 +76468,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_18__pyx_unpickle_VariantRecordSamples( * raise __pyx_PickleError("Incompatible checksums (%s vs 0xde17f0f = (record))" % __pyx_checksum) * __pyx_result = VariantRecordSamples.__new__(__pyx_type) */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; @@ -66562,9 +76490,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_18__pyx_unpickle_VariantRecordSamples( * __pyx_result = VariantRecordSamples.__new__(__pyx_type) * if __pyx_state is not None: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xde, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xde, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); @@ -66579,14 +76507,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_18__pyx_unpickle_VariantRecordSamples( } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -66595,20 +76523,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_18__pyx_unpickle_VariantRecordSamples( #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -66616,7 +76544,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_18__pyx_unpickle_VariantRecordSamples( __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":2 * def __pyx_unpickle_VariantRecordSamples(__pyx_type, long __pyx_checksum, __pyx_state): @@ -66633,7 +76561,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_18__pyx_unpickle_VariantRecordSamples( * if __pyx_state is not None: * __pyx_unpickle_VariantRecordSamples__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordSamples), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordSamples), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -66646,13 +76574,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_18__pyx_unpickle_VariantRecordSamples( } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -66660,19 +76588,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_18__pyx_unpickle_VariantRecordSamples( #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v___pyx_type); __Pyx_GIVEREF(__pyx_v___pyx_type); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -66699,8 +76627,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_18__pyx_unpickle_VariantRecordSamples( * return __pyx_result * cdef __pyx_unpickle_VariantRecordSamples__set_state(VariantRecordSamples __pyx_result, tuple __pyx_state): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSamples__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSamples__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSamples *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -66771,7 +76699,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSamples__se PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("__pyx_unpickle_VariantRecordSamples__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantRecordSamples__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantRecordSamples__set_state", __pyx_f[2], 9, 0, __PYX_ERR(2, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result @@ -66782,11 +76710,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSamples__se */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantRecord))))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantRecord))))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->record); __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->record)); @@ -66801,16 +76729,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSamples__se */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) + __PYX_ERR(2, 11, __pyx_L1_error) } - __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_4 = ((__pyx_t_3 > 1) != 0); if (__pyx_t_4) { } else { __pyx_t_2 = __pyx_t_4; goto __pyx_L4_bool_binop_done; } - __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_5 = (__pyx_t_4 != 0); __pyx_t_2 = __pyx_t_5; __pyx_L4_bool_binop_done:; @@ -66821,16 +76749,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSamples__se * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) + __PYX_ERR(2, 12, __pyx_L1_error) } - __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { @@ -66843,14 +76771,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSamples__se } } if (!__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -66859,20 +76787,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSamples__se #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6); __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } @@ -66956,17 +76884,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_21__pyx_unpickle_VariantRecordSample(P case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordSample", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordSample", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordSample", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordSample", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantRecordSample") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_VariantRecordSample") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -66976,12 +76904,12 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_21__pyx_unpickle_VariantRecordSample(P values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordSample", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_VariantRecordSample", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.__pyx_unpickle_VariantRecordSample", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -67007,9 +76935,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20__pyx_unpickle_VariantRecordSample(C PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__232) + __Pyx_TraceFrameInit(__pyx_codeobj__250) __Pyx_RefNannySetupContext("__pyx_unpickle_VariantRecordSample", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantRecordSample", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantRecordSample", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __pyx_unpickle_VariantRecordSample(__pyx_type, long __pyx_checksum, __pyx_state): @@ -67027,15 +76955,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20__pyx_unpickle_VariantRecordSample(C * raise __pyx_PickleError("Incompatible checksums (%s vs 0x5d6ff7b = (index, record))" % __pyx_checksum) * __pyx_result = VariantRecordSample.__new__(__pyx_type) */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; @@ -67049,9 +76977,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20__pyx_unpickle_VariantRecordSample(C * __pyx_result = VariantRecordSample.__new__(__pyx_type) * if __pyx_state is not None: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x5d, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x5d, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); @@ -67066,14 +76994,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20__pyx_unpickle_VariantRecordSample(C } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -67082,20 +77010,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20__pyx_unpickle_VariantRecordSample(C #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -67103,7 +77031,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20__pyx_unpickle_VariantRecordSample(C __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":2 * def __pyx_unpickle_VariantRecordSample(__pyx_type, long __pyx_checksum, __pyx_state): @@ -67120,7 +77048,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20__pyx_unpickle_VariantRecordSample(C * if __pyx_state is not None: * __pyx_unpickle_VariantRecordSample__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordSample), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordSample), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -67133,13 +77061,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20__pyx_unpickle_VariantRecordSample(C } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -67147,19 +77075,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20__pyx_unpickle_VariantRecordSample(C #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v___pyx_type); __Pyx_GIVEREF(__pyx_v___pyx_type); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -67186,8 +77114,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_20__pyx_unpickle_VariantRecordSample(C * return __pyx_result * cdef __pyx_unpickle_VariantRecordSample__set_state(VariantRecordSample __pyx_result, tuple __pyx_state): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSample__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSample__set_state(((struct __pyx_obj_5pysam_7libcbcf_VariantRecordSample *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -67259,7 +77187,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSample__set PyObject *__pyx_t_9 = NULL; PyObject *__pyx_t_10 = NULL; __Pyx_RefNannySetupContext("__pyx_unpickle_VariantRecordSample__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_VariantRecordSample__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_VariantRecordSample__set_state", __pyx_f[2], 9, 0, __PYX_ERR(2, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result @@ -67270,20 +77198,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSample__set */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_2 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_2 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v___pyx_result->index = __pyx_t_2; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantRecord))))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_7libcbcf_VariantRecord))))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->record); __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->record)); @@ -67298,16 +77226,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSample__set */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) + __PYX_ERR(2, 11, __pyx_L1_error) } - __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_5 = ((__pyx_t_4 > 2) != 0); if (__pyx_t_5) { } else { __pyx_t_3 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } - __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_6 = (__pyx_t_5 != 0); __pyx_t_3 = __pyx_t_6; __pyx_L4_bool_binop_done:; @@ -67318,16 +77246,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSample__set * if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[2]) # <<<<<<<<<<<<<< */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) + __PYX_ERR(2, 12, __pyx_L1_error) } - __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { @@ -67340,14 +77268,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSample__set } } if (!__pyx_t_9) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_8)) { PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; @@ -67356,20 +77284,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_VariantRecordSample__set #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else #endif { - __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_7); __pyx_t_7 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } @@ -67453,17 +77381,17 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_23__pyx_unpickle_BaseIndex(PyObject *_ case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BaseIndex", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BaseIndex", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BaseIndex", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BaseIndex", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_BaseIndex") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_BaseIndex") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -67473,12 +77401,12 @@ static PyObject *__pyx_pw_5pysam_7libcbcf_23__pyx_unpickle_BaseIndex(PyObject *_ values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v___pyx_type = values[0]; - __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) __pyx_v___pyx_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BaseIndex", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_BaseIndex", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbcf.__pyx_unpickle_BaseIndex", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -67504,9 +77432,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_22__pyx_unpickle_BaseIndex(CYTHON_UNUS PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__233) + __Pyx_TraceFrameInit(__pyx_codeobj__251) __Pyx_RefNannySetupContext("__pyx_unpickle_BaseIndex", 0); - __Pyx_TraceCall("__pyx_unpickle_BaseIndex", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_BaseIndex", __pyx_f[2], 1, 0, __PYX_ERR(2, 1, __pyx_L1_error)); /* "(tree fragment)":2 * def __pyx_unpickle_BaseIndex(__pyx_type, long __pyx_checksum, __pyx_state): @@ -67524,15 +77452,15 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_22__pyx_unpickle_BaseIndex(CYTHON_UNUS * raise __pyx_PickleError("Incompatible checksums (%s vs 0xd936de3 = (refmap, refs))" % __pyx_checksum) * __pyx_result = BaseIndex.__new__(__pyx_type) */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_PickleError); __Pyx_GIVEREF(__pyx_n_s_PickleError); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); - __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_v___pyx_PickleError = __pyx_t_2; @@ -67546,9 +77474,9 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_22__pyx_unpickle_BaseIndex(CYTHON_UNUS * __pyx_result = BaseIndex.__new__(__pyx_type) * if __pyx_state is not None: */ - __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xd9, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xd9, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_v___pyx_PickleError); @@ -67563,14 +77491,14 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_22__pyx_unpickle_BaseIndex(CYTHON_UNUS } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -67579,20 +77507,20 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_22__pyx_unpickle_BaseIndex(CYTHON_UNUS #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -67600,7 +77528,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_22__pyx_unpickle_BaseIndex(CYTHON_UNUS __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __PYX_ERR(2, 4, __pyx_L1_error) /* "(tree fragment)":2 * def __pyx_unpickle_BaseIndex(__pyx_type, long __pyx_checksum, __pyx_state): @@ -67617,7 +77545,7 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_22__pyx_unpickle_BaseIndex(CYTHON_UNUS * if __pyx_state is not None: * __pyx_unpickle_BaseIndex__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_BaseIndex), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_7libcbcf_BaseIndex), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -67630,13 +77558,13 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_22__pyx_unpickle_BaseIndex(CYTHON_UNUS } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -67644,19 +77572,19 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_22__pyx_unpickle_BaseIndex(CYTHON_UNUS #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v___pyx_type); __Pyx_GIVEREF(__pyx_v___pyx_type); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -67683,8 +77611,8 @@ static PyObject *__pyx_pf_5pysam_7libcbcf_22__pyx_unpickle_BaseIndex(CYTHON_UNUS * return __pyx_result * cdef __pyx_unpickle_BaseIndex__set_state(BaseIndex __pyx_result, tuple __pyx_state): */ - if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_BaseIndex__set_state(((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_7libcbcf___pyx_unpickle_BaseIndex__set_state(((struct __pyx_obj_5pysam_7libcbcf_BaseIndex *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -67755,7 +77683,7 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_BaseIndex__set_state(str PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; __Pyx_RefNannySetupContext("__pyx_unpickle_BaseIndex__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_BaseIndex__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_TraceCall("__pyx_unpickle_BaseIndex__set_state", __pyx_f[2], 9, 0, __PYX_ERR(2, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result @@ -67766,11 +77694,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_BaseIndex__set_state(str */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->refmap); __Pyx_DECREF(__pyx_v___pyx_result->refmap); @@ -67778,11 +77706,11 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_BaseIndex__set_state(str __pyx_t_1 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 10, __pyx_L1_error) + __PYX_ERR(2, 10, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (!(likely(PyTuple_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(1, 10, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 10, __pyx_L1_error) __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v___pyx_result->refs); __Pyx_DECREF(__pyx_v___pyx_result->refs); @@ -67797,16 +77725,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_BaseIndex__set_state(str */ if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(1, 11, __pyx_L1_error) + __PYX_ERR(2, 11, __pyx_L1_error) } - __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_4 = ((__pyx_t_3 > 2) != 0); if (__pyx_t_4) { } else { __pyx_t_2 = __pyx_t_4; goto __pyx_L4_bool_binop_done; } - __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 11, __pyx_L1_error) __pyx_t_5 = (__pyx_t_4 != 0); __pyx_t_2 = __pyx_t_5; __pyx_L4_bool_binop_done:; @@ -67817,16 +77745,16 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_BaseIndex__set_state(str * if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[2]) # <<<<<<<<<<<<<< */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(__pyx_v___pyx_state == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(1, 12, __pyx_L1_error) + __PYX_ERR(2, 12, __pyx_L1_error) } - __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { @@ -67839,14 +77767,14 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_BaseIndex__set_state(str } } if (!__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -67855,20 +77783,20 @@ static PyObject *__pyx_f_5pysam_7libcbcf___pyx_unpickle_BaseIndex__set_state(str #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6); __pyx_t_6 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } @@ -68646,7 +78574,7 @@ static PyObject *__pyx_getprop_5pysam_7libcbcf_13VariantHeader_alts(PyObject *o, static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantHeader[] = { {"copy", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantHeader_9copy, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_13VariantHeader_8copy}, {"merge", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantHeader_11merge, METH_O, __pyx_doc_5pysam_7libcbcf_13VariantHeader_10merge}, - {"new_record", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantHeader_15new_record, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_13VariantHeader_14new_record}, + {"new_record", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantHeader_15new_record, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_13VariantHeader_14new_record}, {"add_record", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantHeader_17add_record, METH_O, __pyx_doc_5pysam_7libcbcf_13VariantHeader_16add_record}, {"add_line", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantHeader_19add_line, METH_O, __pyx_doc_5pysam_7libcbcf_13VariantHeader_18add_line}, {"add_meta", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantHeader_21add_meta, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_13VariantHeader_20add_meta}, @@ -68855,6 +78783,10 @@ static PyObject *__pyx_getprop_5pysam_7libcbcf_19VariantHeaderRecord_attrs(PyObj return __pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_5attrs_1__get__(o); } +static PyObject *__pyx_getprop_5pysam_7libcbcf_19VariantHeaderRecord_header(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_6header_1__get__(o); +} + static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantHeaderRecord[] = { {"get", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_12get, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_11get}, {"iterkeys", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_16iterkeys, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_15iterkeys}, @@ -68863,9 +78795,11 @@ static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantHeaderRecord[] = { {"keys", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_24keys, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_23keys}, {"items", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_26items, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_25items}, {"values", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_28values, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_27values}, - {"remove", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_32remove, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_31remove}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_34__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_33__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_36__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_35__setstate_cython__}, + {"update", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_30update, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_29update}, + {"pop", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_32pop, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_31pop}, + {"remove", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_36remove, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_35remove}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_38__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_37__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_40__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_39__setstate_cython__}, {0, 0, 0, 0} }; @@ -68874,6 +78808,7 @@ static struct PyGetSetDef __pyx_getsets_5pysam_7libcbcf_VariantHeaderRecord[] = {(char *)"key", __pyx_getprop_5pysam_7libcbcf_19VariantHeaderRecord_key, 0, (char *)"header key (the part before '=', in FILTER/INFO/FORMAT/contig/fileformat etc.)", 0}, {(char *)"value", __pyx_getprop_5pysam_7libcbcf_19VariantHeaderRecord_value, 0, (char *)"header value. Set only for generic lines, None for FILTER/INFO, etc.", 0}, {(char *)"attrs", __pyx_getprop_5pysam_7libcbcf_19VariantHeaderRecord_attrs, 0, (char *)"sequence of additional header attributes", 0}, + {(char *)"header", __pyx_getprop_5pysam_7libcbcf_19VariantHeaderRecord_header, 0, (char *)0, 0}, {0, 0, 0, 0, 0} }; @@ -68979,7 +78914,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_VariantHeaderRecord = { &__pyx_tp_as_mapping_VariantHeaderRecord, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_30__str__, /*tp_str*/ + __pyx_pw_5pysam_7libcbcf_19VariantHeaderRecord_34__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ @@ -69067,12 +79002,21 @@ static PyObject *__pyx_sq_item_5pysam_7libcbcf_VariantHeaderRecords(PyObject *o, return r; } +static PyObject *__pyx_getprop_5pysam_7libcbcf_20VariantHeaderRecords_header(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_7libcbcf_20VariantHeaderRecords_6header_1__get__(o); +} + static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantHeaderRecords[] = { {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantHeaderRecords_12__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_20VariantHeaderRecords_11__reduce_cython__}, {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantHeaderRecords_14__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_20VariantHeaderRecords_13__setstate_cython__}, {0, 0, 0, 0} }; +static struct PyGetSetDef __pyx_getsets_5pysam_7libcbcf_VariantHeaderRecords[] = { + {(char *)"header", __pyx_getprop_5pysam_7libcbcf_20VariantHeaderRecords_header, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + static PyNumberMethods __pyx_tp_as_number_VariantHeaderRecords = { 0, /*nb_add*/ 0, /*nb_subtract*/ @@ -69189,7 +79133,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_VariantHeaderRecords = { 0, /*tp_iternext*/ __pyx_methods_5pysam_7libcbcf_VariantHeaderRecords, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5pysam_7libcbcf_VariantHeaderRecords, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -69263,6 +79207,10 @@ static PyObject *__pyx_sq_item_5pysam_7libcbcf_VariantHeaderContigs(PyObject *o, return r; } +static PyObject *__pyx_getprop_5pysam_7libcbcf_20VariantHeaderContigs_header(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_7libcbcf_20VariantHeaderContigs_6header_1__get__(o); +} + static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantHeaderContigs[] = { {"remove_header", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantHeaderContigs_9remove_header, METH_O, __pyx_doc_5pysam_7libcbcf_20VariantHeaderContigs_8remove_header}, {"clear_header", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantHeaderContigs_11clear_header, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_20VariantHeaderContigs_10clear_header}, @@ -69279,6 +79227,11 @@ static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantHeaderContigs[] = { {0, 0, 0, 0} }; +static struct PyGetSetDef __pyx_getsets_5pysam_7libcbcf_VariantHeaderContigs[] = { + {(char *)"header", __pyx_getprop_5pysam_7libcbcf_20VariantHeaderContigs_header, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + static PyNumberMethods __pyx_tp_as_number_VariantHeaderContigs = { 0, /*nb_add*/ 0, /*nb_subtract*/ @@ -69395,7 +79348,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_VariantHeaderContigs = { 0, /*tp_iternext*/ __pyx_methods_5pysam_7libcbcf_VariantHeaderContigs, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5pysam_7libcbcf_VariantHeaderContigs, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -69469,6 +79422,10 @@ static PyObject *__pyx_sq_item_5pysam_7libcbcf_VariantHeaderSamples(PyObject *o, return r; } +static PyObject *__pyx_getprop_5pysam_7libcbcf_20VariantHeaderSamples_header(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_7libcbcf_20VariantHeaderSamples_6header_1__get__(o); +} + static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantHeaderSamples[] = { {"add", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantHeaderSamples_14add, METH_O, __pyx_doc_5pysam_7libcbcf_20VariantHeaderSamples_13add}, {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantHeaderSamples_16__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_20VariantHeaderSamples_15__reduce_cython__}, @@ -69476,6 +79433,11 @@ static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantHeaderSamples[] = { {0, 0, 0, 0} }; +static struct PyGetSetDef __pyx_getsets_5pysam_7libcbcf_VariantHeaderSamples[] = { + {(char *)"header", __pyx_getprop_5pysam_7libcbcf_20VariantHeaderSamples_header, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + static PyNumberMethods __pyx_tp_as_number_VariantHeaderSamples = { 0, /*nb_add*/ 0, /*nb_subtract*/ @@ -69592,7 +79554,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_VariantHeaderSamples = { 0, /*tp_iternext*/ __pyx_methods_5pysam_7libcbcf_VariantHeaderSamples, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5pysam_7libcbcf_VariantHeaderSamples, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -69671,6 +79633,10 @@ static PyObject *__pyx_getprop_5pysam_7libcbcf_13VariantContig_length(PyObject * return __pyx_pw_5pysam_7libcbcf_13VariantContig_6length_1__get__(o); } +static PyObject *__pyx_getprop_5pysam_7libcbcf_13VariantContig_header_record(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_7libcbcf_13VariantContig_13header_record_1__get__(o); +} + static PyObject *__pyx_getprop_5pysam_7libcbcf_13VariantContig_header(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5pysam_7libcbcf_13VariantContig_6header_1__get__(o); } @@ -69686,7 +79652,8 @@ static struct PyGetSetDef __pyx_getsets_5pysam_7libcbcf_VariantContig[] = { {(char *)"name", __pyx_getprop_5pysam_7libcbcf_13VariantContig_name, 0, (char *)"contig name", 0}, {(char *)"id", __pyx_getprop_5pysam_7libcbcf_13VariantContig_id, 0, (char *)"contig internal id number", 0}, {(char *)"length", __pyx_getprop_5pysam_7libcbcf_13VariantContig_length, 0, (char *)"contig length or None if not available", 0}, - {(char *)"header", __pyx_getprop_5pysam_7libcbcf_13VariantContig_header, 0, (char *)":class:`VariantHeaderRecord` associated with this :class:`VariantContig` object", 0}, + {(char *)"header_record", __pyx_getprop_5pysam_7libcbcf_13VariantContig_header_record, 0, (char *)":class:`VariantHeaderRecord` associated with this :class:`VariantContig` object", 0}, + {(char *)"header", __pyx_getprop_5pysam_7libcbcf_13VariantContig_header, 0, (char *)0, 0}, {0, 0, 0, 0, 0} }; @@ -69816,6 +79783,10 @@ static PyObject *__pyx_getprop_5pysam_7libcbcf_15VariantMetadata_record(PyObject return __pyx_pw_5pysam_7libcbcf_15VariantMetadata_6record_1__get__(o); } +static PyObject *__pyx_getprop_5pysam_7libcbcf_15VariantMetadata_header(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_7libcbcf_15VariantMetadata_6header_1__get__(o); +} + static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantMetadata[] = { {"remove_header", (PyCFunction)__pyx_pw_5pysam_7libcbcf_15VariantMetadata_3remove_header, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_15VariantMetadata_2remove_header}, {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_15VariantMetadata_5__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_15VariantMetadata_4__reduce_cython__}, @@ -69830,6 +79801,7 @@ static struct PyGetSetDef __pyx_getsets_5pysam_7libcbcf_VariantMetadata[] = { {(char *)"type", __pyx_getprop_5pysam_7libcbcf_15VariantMetadata_type, 0, (char *)"metadata value type", 0}, {(char *)"description", __pyx_getprop_5pysam_7libcbcf_15VariantMetadata_description, 0, (char *)"metadata description (or None if not set)", 0}, {(char *)"record", __pyx_getprop_5pysam_7libcbcf_15VariantMetadata_record, 0, (char *)":class:`VariantHeaderRecord` associated with this :class:`VariantMetadata` object", 0}, + {(char *)"header", __pyx_getprop_5pysam_7libcbcf_15VariantMetadata_header, 0, (char *)0, 0}, {0, 0, 0, 0, 0} }; @@ -69942,6 +79914,10 @@ static PyObject *__pyx_sq_item_5pysam_7libcbcf_VariantHeaderMetadata(PyObject *o return r; } +static PyObject *__pyx_getprop_5pysam_7libcbcf_21VariantHeaderMetadata_header(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_7libcbcf_21VariantHeaderMetadata_6header_1__get__(o); +} + static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantHeaderMetadata[] = { {"add", (PyCFunction)__pyx_pw_5pysam_7libcbcf_21VariantHeaderMetadata_3add, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_21VariantHeaderMetadata_2add}, {"remove_header", (PyCFunction)__pyx_pw_5pysam_7libcbcf_21VariantHeaderMetadata_11remove_header, METH_O, __pyx_doc_5pysam_7libcbcf_21VariantHeaderMetadata_10remove_header}, @@ -69958,6 +79934,11 @@ static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantHeaderMetadata[] = { {0, 0, 0, 0} }; +static struct PyGetSetDef __pyx_getsets_5pysam_7libcbcf_VariantHeaderMetadata[] = { + {(char *)"header", __pyx_getprop_5pysam_7libcbcf_21VariantHeaderMetadata_header, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + static PyNumberMethods __pyx_tp_as_number_VariantHeaderMetadata = { 0, /*nb_add*/ 0, /*nb_subtract*/ @@ -70074,7 +80055,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_VariantHeaderMetadata = { 0, /*tp_iternext*/ __pyx_methods_5pysam_7libcbcf_VariantHeaderMetadata, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5pysam_7libcbcf_VariantHeaderMetadata, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -70333,11 +80314,15 @@ static PyObject *__pyx_getprop_5pysam_7libcbcf_13VariantRecord_samples(PyObject return __pyx_pw_5pysam_7libcbcf_13VariantRecord_7samples_1__get__(o); } +static PyObject *__pyx_getprop_5pysam_7libcbcf_13VariantRecord_header(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_7libcbcf_13VariantRecord_6header_1__get__(o); +} + static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantRecord[] = { {"copy", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantRecord_5copy, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_13VariantRecord_4copy}, {"translate", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantRecord_7translate, METH_O, __pyx_doc_5pysam_7libcbcf_13VariantRecord_6translate}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantRecord_11__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_13VariantRecord_10__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantRecord_13__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_13VariantRecord_12__setstate_cython__}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantRecord_13__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_13VariantRecord_12__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_13VariantRecord_15__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_13VariantRecord_14__setstate_cython__}, {0, 0, 0, 0} }; @@ -70348,7 +80333,7 @@ static struct PyGetSetDef __pyx_getsets_5pysam_7libcbcf_VariantRecord[] = { {(char *)"pos", __pyx_getprop_5pysam_7libcbcf_13VariantRecord_pos, __pyx_setprop_5pysam_7libcbcf_13VariantRecord_pos, (char *)"record start position on chrom/contig (1-based inclusive)", 0}, {(char *)"start", __pyx_getprop_5pysam_7libcbcf_13VariantRecord_start, __pyx_setprop_5pysam_7libcbcf_13VariantRecord_start, (char *)"record start position on chrom/contig (0-based inclusive)", 0}, {(char *)"stop", __pyx_getprop_5pysam_7libcbcf_13VariantRecord_stop, __pyx_setprop_5pysam_7libcbcf_13VariantRecord_stop, (char *)"record stop position on chrom/contig (0-based exclusive)", 0}, - {(char *)"rlen", __pyx_getprop_5pysam_7libcbcf_13VariantRecord_rlen, __pyx_setprop_5pysam_7libcbcf_13VariantRecord_rlen, (char *)"record length on chrom/contig (typically rec.stop - rec.start unless END info is supplied)", 0}, + {(char *)"rlen", __pyx_getprop_5pysam_7libcbcf_13VariantRecord_rlen, __pyx_setprop_5pysam_7libcbcf_13VariantRecord_rlen, (char *)"record length on chrom/contig (aka rec.stop - rec.start)", 0}, {(char *)"qual", __pyx_getprop_5pysam_7libcbcf_13VariantRecord_qual, __pyx_setprop_5pysam_7libcbcf_13VariantRecord_qual, (char *)"phred scaled quality score or None if not available", 0}, {(char *)"id", __pyx_getprop_5pysam_7libcbcf_13VariantRecord_id, __pyx_setprop_5pysam_7libcbcf_13VariantRecord_id, (char *)"record identifier or None if not available", 0}, {(char *)"ref", __pyx_getprop_5pysam_7libcbcf_13VariantRecord_ref, __pyx_setprop_5pysam_7libcbcf_13VariantRecord_ref, (char *)"reference allele", 0}, @@ -70358,6 +80343,7 @@ static struct PyGetSetDef __pyx_getsets_5pysam_7libcbcf_VariantRecord[] = { {(char *)"info", __pyx_getprop_5pysam_7libcbcf_13VariantRecord_info, 0, (char *)"info data (see :class:`VariantRecordInfo`)", 0}, {(char *)"format", __pyx_getprop_5pysam_7libcbcf_13VariantRecord_format, 0, (char *)"sample format metadata (see :class:`VariantRecordFormat`)", 0}, {(char *)"samples", __pyx_getprop_5pysam_7libcbcf_13VariantRecord_samples, 0, (char *)"sample data (see :class:`VariantRecordSamples`)", 0}, + {(char *)"header", __pyx_getprop_5pysam_7libcbcf_13VariantRecord_header, 0, (char *)0, 0}, {0, 0, 0, 0, 0} }; @@ -70382,7 +80368,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_VariantRecord = { 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5pysam_7libcbcf_13VariantRecord_9__str__, /*tp_str*/ + __pyx_pw_5pysam_7libcbcf_13VariantRecord_11__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ @@ -70390,7 +80376,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_VariantRecord = { "VariantRecord(*args, **kwargs)\nVariant record", /*tp_doc*/ __pyx_tp_traverse_5pysam_7libcbcf_VariantRecord, /*tp_traverse*/ __pyx_tp_clear_5pysam_7libcbcf_VariantRecord, /*tp_clear*/ - 0, /*tp_richcompare*/ + __pyx_pw_5pysam_7libcbcf_13VariantRecord_9__richcmp__, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ @@ -70491,8 +80477,8 @@ static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantRecordFilter[] = { {"keys", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_30keys, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_29keys}, {"items", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_32items, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_31items}, {"values", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_34values, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_33values}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_36__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_35__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_38__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_37__setstate_cython__}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_38__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_37__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_40__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_19VariantRecordFilter_39__setstate_cython__}, {0, 0, 0, 0} }; @@ -70606,7 +80592,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_VariantRecordFilter = { "VariantRecordFilter(*args, **kwargs)\nFilters set on a :class:`VariantRecord` object, presented as a mapping from\n filter index or name to :class:`VariantMetadata` object", /*tp_doc*/ __pyx_tp_traverse_5pysam_7libcbcf_VariantRecordFilter, /*tp_traverse*/ __pyx_tp_clear_5pysam_7libcbcf_VariantRecordFilter, /*tp_clear*/ - 0, /*tp_richcompare*/ + __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_36__richcmp__, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ __pyx_pw_5pysam_7libcbcf_19VariantRecordFilter_15__iter__, /*tp_iter*/ 0, /*tp_iternext*/ @@ -70919,8 +80905,10 @@ static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantRecordInfo[] = { {"keys", (PyCFunction)__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_30keys, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_29keys}, {"items", (PyCFunction)__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_32items, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_31items}, {"values", (PyCFunction)__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_34values, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_33values}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_36__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_35__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_38__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_37__setstate_cython__}, + {"update", (PyCFunction)__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_36update, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_35update}, + {"pop", (PyCFunction)__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_38pop, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_37pop}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_42__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_41__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_44__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_17VariantRecordInfo_43__setstate_cython__}, {0, 0, 0, 0} }; @@ -71034,7 +81022,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_VariantRecordInfo = { "VariantRecordInfo(*args, **kwargs)\nInfo data stored in a :class:`VariantRecord` object, presented as a\n mapping from info metadata name to value.", /*tp_doc*/ __pyx_tp_traverse_5pysam_7libcbcf_VariantRecordInfo, /*tp_traverse*/ __pyx_tp_clear_5pysam_7libcbcf_VariantRecordInfo, /*tp_clear*/ - 0, /*tp_richcompare*/ + __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_40__richcmp__, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ __pyx_pw_5pysam_7libcbcf_17VariantRecordInfo_15__iter__, /*tp_iter*/ 0, /*tp_iternext*/ @@ -71122,8 +81110,10 @@ static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantRecordSamples[] = { {"keys", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_24keys, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_23keys}, {"items", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_26items, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_25items}, {"values", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_28values, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_27values}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_30__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_29__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_32__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_31__setstate_cython__}, + {"update", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_30update, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_29update}, + {"pop", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_32pop, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_31pop}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_36__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_35__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_38__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_20VariantRecordSamples_37__setstate_cython__}, {0, 0, 0, 0} }; @@ -71237,7 +81227,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_VariantRecordSamples = { "VariantRecordSamples(*args, **kwargs)\nmapping from sample index or name to :class:`VariantRecordSample` object.", /*tp_doc*/ __pyx_tp_traverse_5pysam_7libcbcf_VariantRecordSamples, /*tp_traverse*/ __pyx_tp_clear_5pysam_7libcbcf_VariantRecordSamples, /*tp_clear*/ - 0, /*tp_richcompare*/ + __pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_34__richcmp__, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ __pyx_pw_5pysam_7libcbcf_20VariantRecordSamples_9__iter__, /*tp_iter*/ 0, /*tp_iternext*/ @@ -71383,8 +81373,10 @@ static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantRecordSample[] = { {"keys", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_30keys, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_29keys}, {"items", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_32items, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_31items}, {"values", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_34values, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_33values}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_36__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_35__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_38__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_37__setstate_cython__}, + {"update", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_36update, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_35update}, + {"pop", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_38pop, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_37pop}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_42__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_41__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_19VariantRecordSample_44__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_19VariantRecordSample_43__setstate_cython__}, {0, 0, 0, 0} }; @@ -71507,7 +81499,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_VariantRecordSample = { "VariantRecordSample(*args, **kwargs)\nData for a single sample from a :class:`VariantRecord` object.\n Provides data accessors for genotypes and a mapping interface\n from format name to values.\n ", /*tp_doc*/ __pyx_tp_traverse_5pysam_7libcbcf_VariantRecordSample, /*tp_traverse*/ __pyx_tp_clear_5pysam_7libcbcf_VariantRecordSample, /*tp_clear*/ - 0, /*tp_richcompare*/ + __pyx_pw_5pysam_7libcbcf_19VariantRecordSample_40__richcmp__, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ __pyx_pw_5pysam_7libcbcf_19VariantRecordSample_15__iter__, /*tp_iter*/ 0, /*tp_iternext*/ @@ -71603,8 +81595,10 @@ static PyMethodDef __pyx_methods_5pysam_7libcbcf_BaseIndex[] = { {"keys", (PyCFunction)__pyx_pw_5pysam_7libcbcf_9BaseIndex_23keys, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_9BaseIndex_22keys}, {"items", (PyCFunction)__pyx_pw_5pysam_7libcbcf_9BaseIndex_25items, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_9BaseIndex_24items}, {"values", (PyCFunction)__pyx_pw_5pysam_7libcbcf_9BaseIndex_27values, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_9BaseIndex_26values}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_9BaseIndex_29__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_9BaseIndex_28__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_9BaseIndex_31__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_9BaseIndex_30__setstate_cython__}, + {"update", (PyCFunction)__pyx_pw_5pysam_7libcbcf_9BaseIndex_29update, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_9BaseIndex_28update}, + {"pop", (PyCFunction)__pyx_pw_5pysam_7libcbcf_9BaseIndex_31pop, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_9BaseIndex_30pop}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_9BaseIndex_33__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_9BaseIndex_32__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_9BaseIndex_35__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_9BaseIndex_34__setstate_cython__}, {0, 0, 0, 0} }; @@ -71797,6 +81791,10 @@ static int __pyx_tp_clear_5pysam_7libcbcf_BCFIndex(PyObject *o) { return 0; } +static PyObject *__pyx_getprop_5pysam_7libcbcf_8BCFIndex_header(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_7libcbcf_8BCFIndex_6header_1__get__(o); +} + static PyMethodDef __pyx_methods_5pysam_7libcbcf_BCFIndex[] = { {"fetch", (PyCFunction)__pyx_pw_5pysam_7libcbcf_8BCFIndex_5fetch, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_8BCFIndex_4fetch}, {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_8BCFIndex_7__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_8BCFIndex_6__reduce_cython__}, @@ -71804,6 +81802,11 @@ static PyMethodDef __pyx_methods_5pysam_7libcbcf_BCFIndex[] = { {0, 0, 0, 0} }; +static struct PyGetSetDef __pyx_getsets_5pysam_7libcbcf_BCFIndex[] = { + {(char *)"header", __pyx_getprop_5pysam_7libcbcf_8BCFIndex_header, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + static PyTypeObject __pyx_type_5pysam_7libcbcf_BCFIndex = { PyVarObject_HEAD_INIT(0, 0) "pysam.libcbcf.BCFIndex", /*tp_name*/ @@ -71843,7 +81846,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_BCFIndex = { 0, /*tp_iternext*/ __pyx_methods_5pysam_7libcbcf_BCFIndex, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5pysam_7libcbcf_BCFIndex, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -72151,7 +82154,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_BCFIterator = { 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "BCFIterator(VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True)", /*tp_doc*/ + "BCFIterator(VariantFile bcf, contig=None, start=None, stop=None, reopen=True)", /*tp_doc*/ __pyx_tp_traverse_5pysam_7libcbcf_BCFIterator, /*tp_traverse*/ __pyx_tp_clear_5pysam_7libcbcf_BCFIterator, /*tp_clear*/ 0, /*tp_richcompare*/ @@ -72270,7 +82273,7 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_TabixIterator = { 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "TabixIterator(VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True)", /*tp_doc*/ + "TabixIterator(VariantFile bcf, contig=None, start=None, stop=None, reopen=True)", /*tp_doc*/ __pyx_tp_traverse_5pysam_7libcbcf_TabixIterator, /*tp_traverse*/ __pyx_tp_clear_5pysam_7libcbcf_TabixIterator, /*tp_clear*/ 0, /*tp_richcompare*/ @@ -72326,6 +82329,14 @@ static void __pyx_tp_dealloc_5pysam_7libcbcf_VariantFile(PyObject *o) { } #endif PyObject_GC_UnTrack(o); + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5pysam_7libcbcf_11VariantFile_5__dealloc__(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } Py_CLEAR(p->header); Py_CLEAR(p->index); PyObject_GC_Track(o); @@ -72379,17 +82390,20 @@ static PyObject *__pyx_getprop_5pysam_7libcbcf_11VariantFile_header_written(PyOb } static PyMethodDef __pyx_methods_5pysam_7libcbcf_VariantFile[] = { - {"close", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_5close, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_11VariantFile_4close}, - {"__next__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_9__next__, METH_NOARGS|METH_COEXIST, 0}, - {"copy", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_11copy, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_11VariantFile_10copy}, - {"open", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_13open, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_11VariantFile_12open}, - {"reset", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_15reset, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_11VariantFile_14reset}, - {"fetch", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_17fetch, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_11VariantFile_16fetch}, - {"new_record", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_19new_record, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_11VariantFile_18new_record}, - {"write", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_21write, METH_O, __pyx_doc_5pysam_7libcbcf_11VariantFile_20write}, - {"subset_samples", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_23subset_samples, METH_O, __pyx_doc_5pysam_7libcbcf_11VariantFile_22subset_samples}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_25__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_11VariantFile_24__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_27__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_11VariantFile_26__setstate_cython__}, + {"close", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_7close, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_11VariantFile_6close}, + {"__next__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_11__next__, METH_NOARGS|METH_COEXIST, 0}, + {"copy", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_13copy, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_11VariantFile_12copy}, + {"open", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_15open, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_11VariantFile_14open}, + {"reset", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_17reset, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_11VariantFile_16reset}, + {"is_valid_tid", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_19is_valid_tid, METH_O, __pyx_doc_5pysam_7libcbcf_11VariantFile_18is_valid_tid}, + {"get_tid", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_21get_tid, METH_O, __pyx_doc_5pysam_7libcbcf_11VariantFile_20get_tid}, + {"get_reference_name", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_23get_reference_name, METH_O, __pyx_doc_5pysam_7libcbcf_11VariantFile_22get_reference_name}, + {"fetch", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_25fetch, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_11VariantFile_24fetch}, + {"new_record", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_27new_record, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_7libcbcf_11VariantFile_26new_record}, + {"write", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_29write, METH_O, __pyx_doc_5pysam_7libcbcf_11VariantFile_28write}, + {"subset_samples", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_31subset_samples, METH_O, __pyx_doc_5pysam_7libcbcf_11VariantFile_30subset_samples}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_33__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_7libcbcf_11VariantFile_32__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_7libcbcf_11VariantFile_35__setstate_cython__, METH_O, __pyx_doc_5pysam_7libcbcf_11VariantFile_34__setstate_cython__}, {0, 0, 0, 0} }; @@ -72428,13 +82442,13 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf_VariantFile = { 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "VariantFile(*args, **kwargs)\n*(filename, mode=None, index_filename=None, header=None, drop_samples=False,\n duplicate_filehandle=True)*\n\n A :term:`VCF`/:term:`BCF` formatted file. The file is automatically\n opened.\n\n If an index for a variant file exists (.csi or .tbi), it will be\n opened automatically. Without an index random access to records\n via :meth:`fetch` is disabled.\n\n For writing, a :class:`VariantHeader` object must be provided,\n typically obtained from another :term:`VCF` file/:term:`BCF`\n file.\n\n Parameters\n ----------\n mode : string\n *mode* should be ``r`` for reading or ``w`` for writing. The default is\n text mode (:term:`VCF`). For binary (:term:`BCF`) I/O you should append\n ``b`` for compressed or ``u`` for uncompressed :term:`BCF` output.\n\n If ``b`` is present, it must immediately follow ``r`` or ``w``. Valid\n modes are ``r``, ``w``, ``wh``, ``rb``, ``wb``, ``wbu`` and ``wb0``.\n For instance, to open a :term:`BCF` formatted file for reading, type::\n\n f = pysam.VariantFile('ex1.bcf','r')\n\n If mode is not specified, we will try to auto-detect the file type. All\n of the following should work::\n\n f1 = pysam.VariantFile('ex1.bcf')\n f2 = pysam.VariantFile('ex1.vcf')\n f3 = pysam.VariantFile('ex1.vcf.gz')\n\n index_filename : string\n Explicit path to an index file.\n\n header : VariantHeader\n :class:`VariantHeader` object required for writing.\n\n drop_samples: bool\n Ignore sample information when reading.\n\n duplicate_filehandle: bool \n By default, file handles passed either directly or through\n File-like objects will be duplicated before passing them to\n htslib. The duplication prevents issues where the same stream\n will be closed by htslib and through destruction of the\n high-level python object. Set to False"" to turn off\n duplication.\n\n ", /*tp_doc*/ + "VariantFile(*args, **kwargs)\n*(filename, mode=None, index_filename=None, header=None, drop_samples=False,\n duplicate_filehandle=True, ignore_truncation=False, threads=1)*\n\n A :term:`VCF`/:term:`BCF` formatted file. The file is automatically\n opened.\n\n If an index for a variant file exists (.csi or .tbi), it will be\n opened automatically. Without an index random access to records\n via :meth:`fetch` is disabled.\n\n For writing, a :class:`VariantHeader` object must be provided,\n typically obtained from another :term:`VCF` file/:term:`BCF`\n file.\n\n Parameters\n ----------\n mode : string\n *mode* should be ``r`` for reading or ``w`` for writing. The default is\n text mode (:term:`VCF`). For binary (:term:`BCF`) I/O you should append\n ``b`` for compressed or ``u`` for uncompressed :term:`BCF` output.\n\n If ``b`` is present, it must immediately follow ``r`` or ``w``. Valid\n modes are ``r``, ``w``, ``wh``, ``rb``, ``wb``, ``wbu`` and ``wb0``.\n For instance, to open a :term:`BCF` formatted file for reading, type::\n\n f = pysam.VariantFile('ex1.bcf','r')\n\n If mode is not specified, we will try to auto-detect the file type. All\n of the following should work::\n\n f1 = pysam.VariantFile('ex1.bcf')\n f2 = pysam.VariantFile('ex1.vcf')\n f3 = pysam.VariantFile('ex1.vcf.gz')\n\n index_filename : string\n Explicit path to an index file.\n\n header : VariantHeader\n :class:`VariantHeader` object required for writing.\n\n drop_samples: bool\n Ignore sample information when reading.\n\n duplicate_filehandle: bool\n By default, file handles passed either directly or through\n File-like objects will be duplicated before passing them to\n htslib. The duplication prevents issues where the same stream\n will be closed by htslib and through destruction of the\n hig""h-level python object. Set to False to turn off\n duplication.\n\n ignore_truncation: bool\n Issue a warning, instead of raising an error if the current file\n appears to be truncated due to a missing EOF marker. Only applies\n to bgzipped formats. (Default=False)\n\n threads: integer\n Number of threads to use for compressing/decompressing VCF/BCF files.\n Setting threads to > 1 cannot be combined with `ignore_truncation`.\n (Default=1)\n\n ", /*tp_doc*/ __pyx_tp_traverse_5pysam_7libcbcf_VariantFile, /*tp_traverse*/ __pyx_tp_clear_5pysam_7libcbcf_VariantFile, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5pysam_7libcbcf_11VariantFile_7__iter__, /*tp_iter*/ - __pyx_pw_5pysam_7libcbcf_11VariantFile_9__next__, /*tp_iternext*/ + __pyx_pw_5pysam_7libcbcf_11VariantFile_9__iter__, /*tp_iter*/ + __pyx_pw_5pysam_7libcbcf_11VariantFile_11__next__, /*tp_iternext*/ __pyx_methods_5pysam_7libcbcf_VariantFile, /*tp_methods*/ 0, /*tp_members*/ __pyx_getsets_5pysam_7libcbcf_VariantFile, /*tp_getset*/ @@ -72527,205 +82541,185 @@ static PyTypeObject __pyx_type_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysa 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysam_7libcbcf_char_array_to_tuple, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ - #endif -}; - -static struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *__pyx_freelist_5pysam_7libcbcf___pyx_scope_struct_1_genexpr[8]; -static int __pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_1_genexpr = 0; - -static PyObject *__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - PyObject *o; - if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_1_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr)))) { - o = (PyObject*)__pyx_freelist_5pysam_7libcbcf___pyx_scope_struct_1_genexpr[--__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_1_genexpr]; - memset(o, 0, sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr)); - (void) PyObject_INIT(o, t); - PyObject_GC_Track(o); - } else { - o = (*t->tp_alloc)(t, 0); - if (unlikely(!o)) return 0; - } - return o; -} - -static void __pyx_tp_dealloc_5pysam_7libcbcf___pyx_scope_struct_1_genexpr(PyObject *o) { - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *)o; - PyObject_GC_UnTrack(o); - Py_CLEAR(p->__pyx_outer_scope); - if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_1_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr)))) { - __pyx_freelist_5pysam_7libcbcf___pyx_scope_struct_1_genexpr[__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_1_genexpr++] = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *)o); - } else { - (*Py_TYPE(o)->tp_free)(o); - } -} - -static int __pyx_tp_traverse_5pysam_7libcbcf___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *)o; - if (p->__pyx_outer_scope) { - e = (*v)(((PyObject *)p->__pyx_outer_scope), a); if (e) return e; - } - return 0; -} - -static PyTypeObject __pyx_type_5pysam_7libcbcf___pyx_scope_struct_1_genexpr = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcbcf.__pyx_scope_struct_1_genexpr", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_7libcbcf___pyx_scope_struct_1_genexpr, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ - #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_5pysam_7libcbcf___pyx_scope_struct_1_genexpr, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - 0, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_1_genexpr, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ - #endif -}; - -static struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *__pyx_freelist_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object[8]; -static int __pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object = 0; - -static PyObject *__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - PyObject *o; - if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object)))) { - o = (PyObject*)__pyx_freelist_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object[--__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object]; - memset(o, 0, sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object)); - (void) PyObject_INIT(o, t); - PyObject_GC_Track(o); - } else { - o = (*t->tp_alloc)(t, 0); - if (unlikely(!o)) return 0; - } - return o; -} - -static void __pyx_tp_dealloc_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object(PyObject *o) { - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *p = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *)o; - PyObject_GC_UnTrack(o); - Py_CLEAR(p->__pyx_v_value); - if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object)))) { - __pyx_freelist_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object[__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object++] = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *)o); - } else { - (*Py_TYPE(o)->tp_free)(o); - } -} - -static int __pyx_tp_traverse_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *p = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *)o; - if (p->__pyx_v_value) { - e = (*v)(p->__pyx_v_value, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object(PyObject *o) { - PyObject* tmp; - struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *p = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *)o; - tmp = ((PyObject*)p->__pyx_v_value); - p->__pyx_v_value = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyTypeObject __pyx_type_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcbcf.__pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ - #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object, /*tp_traverse*/ - __pyx_tp_clear_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - 0, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysam_7libcbcf_char_array_to_tuple, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *__pyx_freelist_5pysam_7libcbcf___pyx_scope_struct_1_genexpr[8]; +static int __pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_1_genexpr = 0; + +static PyObject *__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_1_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr)))) { + o = (PyObject*)__pyx_freelist_5pysam_7libcbcf___pyx_scope_struct_1_genexpr[--__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_1_genexpr]; + memset(o, 0, sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr)); + (void) PyObject_INIT(o, t); + PyObject_GC_Track(o); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } + return o; +} + +static void __pyx_tp_dealloc_5pysam_7libcbcf___pyx_scope_struct_1_genexpr(PyObject *o) { + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *)o; + PyObject_GC_UnTrack(o); + Py_CLEAR(p->__pyx_outer_scope); + if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_1_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr)))) { + __pyx_freelist_5pysam_7libcbcf___pyx_scope_struct_1_genexpr[__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_1_genexpr++] = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); + } +} + +static int __pyx_tp_traverse_5pysam_7libcbcf___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr *)o; + if (p->__pyx_outer_scope) { + e = (*v)(((PyObject *)p->__pyx_outer_scope), a); if (e) return e; + } + return 0; +} + +static PyTypeObject __pyx_type_5pysam_7libcbcf___pyx_scope_struct_1_genexpr = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcbcf.__pyx_scope_struct_1_genexpr", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_1_genexpr), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_7libcbcf___pyx_scope_struct_1_genexpr, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5pysam_7libcbcf___pyx_scope_struct_1_genexpr, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + 0, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_1_genexpr, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *__pyx_freelist_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object[8]; +static int __pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object = 0; + +static PyObject *__pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object)))) { + o = (PyObject*)__pyx_freelist_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object[--__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object]; + memset(o, 0, sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object)); + (void) PyObject_INIT(o, t); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } + return o; +} + +static void __pyx_tp_dealloc_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object(PyObject *o) { + struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *p = (struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *)o; + Py_CLEAR(p->__pyx_v_b); + if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object)))) { + __pyx_freelist_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object[__pyx_freecount_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object++] = ((struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); + } +} + +static PyTypeObject __pyx_type_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libcbcf.__pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + 0, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ __pyx_tp_new_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ @@ -76232,13 +86226,12 @@ static struct PyModuleDef __pyx_moduledef = { #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_b_, __pyx_k_, sizeof(__pyx_k_), 0, 0, 0, 0}, - {&__pyx_kp_s_, __pyx_k_, sizeof(__pyx_k_), 0, 0, 1, 0}, {&__pyx_n_s_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 1, 1}, {&__pyx_n_s_ALT, __pyx_k_ALT, sizeof(__pyx_k_ALT), 0, 0, 1, 1}, {&__pyx_n_s_BaseIndex_iteritems, __pyx_k_BaseIndex_iteritems, sizeof(__pyx_k_BaseIndex_iteritems), 0, 0, 1, 1}, {&__pyx_n_s_BaseIndex_itervalues, __pyx_k_BaseIndex_itervalues, sizeof(__pyx_k_BaseIndex_itervalues), 0, 0, 1, 1}, {&__pyx_n_s_CONTIG, __pyx_k_CONTIG, sizeof(__pyx_k_CONTIG), 0, 0, 1, 1}, + {&__pyx_kp_s_Cannot_add_extra_threads_when_ig, __pyx_k_Cannot_add_extra_threads_when_ig, sizeof(__pyx_k_Cannot_add_extra_threads_when_ig), 0, 0, 1, 0}, {&__pyx_kp_s_Cannot_copy_arrays_with_src_valu, __pyx_k_Cannot_copy_arrays_with_src_valu, sizeof(__pyx_k_Cannot_copy_arrays_with_src_valu), 0, 0, 1, 0}, {&__pyx_kp_s_Cannot_create_empty_array, __pyx_k_Cannot_create_empty_array, sizeof(__pyx_k_Cannot_create_empty_array), 0, 0, 1, 0}, {&__pyx_kp_s_Cannot_re_open_htsfile, __pyx_k_Cannot_re_open_htsfile, sizeof(__pyx_k_Cannot_re_open_htsfile), 0, 0, 1, 0}, @@ -76247,7 +86240,9 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_Cannot_translate_record_Number_o, __pyx_k_Cannot_translate_record_Number_o, sizeof(__pyx_k_Cannot_translate_record_Number_o), 0, 0, 1, 0}, {&__pyx_n_s_Description, __pyx_k_Description, sizeof(__pyx_k_Description), 0, 0, 1, 1}, {&__pyx_kp_s_Duplicated_sample_name, __pyx_k_Duplicated_sample_name, sizeof(__pyx_k_Duplicated_sample_name), 0, 0, 1, 0}, + {&__pyx_n_b_END, __pyx_k_END, sizeof(__pyx_k_END), 0, 0, 0, 1}, {&__pyx_n_s_END, __pyx_k_END, sizeof(__pyx_k_END), 0, 0, 1, 1}, + {&__pyx_kp_s_END_is_a_reserved_attribute_acce, __pyx_k_END_is_a_reserved_attribute_acce, sizeof(__pyx_k_END_is_a_reserved_attribute_acce), 0, 0, 1, 0}, {&__pyx_kp_s_Error_s_reading_record, __pyx_k_Error_s_reading_record, sizeof(__pyx_k_Error_s_reading_record), 0, 0, 1, 0}, {&__pyx_kp_s_Error_unpacking_VariantRecord, __pyx_k_Error_unpacking_VariantRecord, sizeof(__pyx_k_Error_unpacking_VariantRecord), 0, 0, 1, 0}, {&__pyx_kp_s_Error_updating_alleles, __pyx_k_Error_updating_alleles, sizeof(__pyx_k_Error_updating_alleles), 0, 0, 1, 0}, @@ -76287,32 +86282,33 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_Invalid_header_id, __pyx_k_Invalid_header_id, sizeof(__pyx_k_Invalid_header_id), 0, 0, 1, 0}, {&__pyx_kp_s_Invalid_header_record_index, __pyx_k_Invalid_header_record_index, sizeof(__pyx_k_Invalid_header_record_index), 0, 0, 1, 0}, {&__pyx_kp_s_Invalid_index_object, __pyx_k_Invalid_index_object, sizeof(__pyx_k_Invalid_index_object), 0, 0, 1, 0}, + {&__pyx_kp_s_Invalid_tid, __pyx_k_Invalid_tid, sizeof(__pyx_k_Invalid_tid), 0, 0, 1, 0}, {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1}, {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, + {&__pyx_kp_s_NON_REF, __pyx_k_NON_REF, sizeof(__pyx_k_NON_REF), 0, 0, 1, 0}, + {&__pyx_n_s_NotImplemented, __pyx_k_NotImplemented, sizeof(__pyx_k_NotImplemented), 0, 0, 1, 1}, {&__pyx_n_s_Number, __pyx_k_Number, sizeof(__pyx_k_Number), 0, 0, 1, 1}, {&__pyx_kp_s_Number_must_be_None_when_adding, __pyx_k_Number_must_be_None_when_adding, sizeof(__pyx_k_Number_must_be_None_when_adding), 0, 0, 1, 0}, - {&__pyx_n_s_OSError, __pyx_k_OSError, sizeof(__pyx_k_OSError), 0, 0, 1, 1}, {&__pyx_n_s_PASS, __pyx_k_PASS, sizeof(__pyx_k_PASS), 0, 0, 1, 1}, {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, {&__pyx_kp_s_Position_must_be_positive, __pyx_k_Position_must_be_positive, sizeof(__pyx_k_Position_must_be_positive), 0, 0, 1, 0}, {&__pyx_n_s_R, __pyx_k_R, sizeof(__pyx_k_R), 0, 0, 1, 1}, - {&__pyx_kp_s_Reference_length_must_be_non_neg, __pyx_k_Reference_length_must_be_non_neg, sizeof(__pyx_k_Reference_length_must_be_non_neg), 0, 0, 1, 0}, - {&__pyx_kp_s_Removing_header_type_key_value_h, __pyx_k_Removing_header_type_key_value_h, sizeof(__pyx_k_Removing_header_type_key_value_h), 0, 0, 1, 0}, {&__pyx_n_s_STRUCTURED, __pyx_k_STRUCTURED, sizeof(__pyx_k_STRUCTURED), 0, 0, 1, 1}, {&__pyx_kp_s_Start_coordinate_must_be_non_neg, __pyx_k_Start_coordinate_must_be_non_neg, sizeof(__pyx_k_Start_coordinate_must_be_non_neg), 0, 0, 1, 0}, {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1}, - {&__pyx_kp_s_Stop_coordinate_must_be_greater, __pyx_k_Stop_coordinate_must_be_greater, sizeof(__pyx_k_Stop_coordinate_must_be_greater), 0, 0, 1, 0}, + {&__pyx_kp_s_Stop_coordinate_must_be_non_nega, __pyx_k_Stop_coordinate_must_be_non_nega, sizeof(__pyx_k_Stop_coordinate_must_be_non_nega), 0, 0, 1, 0}, + {&__pyx_kp_s_Stop_position_of_the_interval, __pyx_k_Stop_position_of_the_interval, sizeof(__pyx_k_Stop_position_of_the_interval), 0, 0, 1, 0}, {&__pyx_n_s_String, __pyx_k_String, sizeof(__pyx_k_String), 0, 0, 1, 1}, {&__pyx_n_s_Type, __pyx_k_Type, sizeof(__pyx_k_Type), 0, 0, 1, 1}, {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, {&__pyx_kp_s_Type_must_be_None_when_adding_a, __pyx_k_Type_must_be_None_when_adding_a, sizeof(__pyx_k_Type_must_be_None_when_adding_a), 0, 0, 1, 0}, + {&__pyx_kp_s_Unable_to_delete_END, __pyx_k_Unable_to_delete_END, sizeof(__pyx_k_Unable_to_delete_END), 0, 0, 1, 0}, {&__pyx_kp_s_Unable_to_delete_FORMAT, __pyx_k_Unable_to_delete_FORMAT, sizeof(__pyx_k_Unable_to_delete_FORMAT), 0, 0, 1, 0}, {&__pyx_kp_s_Unable_to_delete_INFO, __pyx_k_Unable_to_delete_INFO, sizeof(__pyx_k_Unable_to_delete_INFO), 0, 0, 1, 0}, {&__pyx_kp_s_Unable_to_update_INFO_values, __pyx_k_Unable_to_update_INFO_values, sizeof(__pyx_k_Unable_to_update_INFO_values), 0, 0, 1, 0}, {&__pyx_kp_s_Unable_to_update_format_values, __pyx_k_Unable_to_update_format_values, sizeof(__pyx_k_Unable_to_update_format_values), 0, 0, 1, 0}, {&__pyx_kp_s_Unknown_INFO_field, __pyx_k_Unknown_INFO_field, sizeof(__pyx_k_Unknown_INFO_field), 0, 0, 1, 0}, {&__pyx_kp_s_Unknown_allele, __pyx_k_Unknown_allele, sizeof(__pyx_k_Unknown_allele), 0, 0, 1, 0}, - {&__pyx_kp_s_Unknown_contig_specified, __pyx_k_Unknown_contig_specified, sizeof(__pyx_k_Unknown_contig_specified), 0, 0, 1, 0}, {&__pyx_kp_s_Unknown_format_length, __pyx_k_Unknown_format_length, sizeof(__pyx_k_Unknown_format_length), 0, 0, 1, 0}, {&__pyx_kp_s_Unsupported_FORMAT_type, __pyx_k_Unsupported_FORMAT_type, sizeof(__pyx_k_Unsupported_FORMAT_type), 0, 0, 1, 0}, {&__pyx_kp_s_Unsupported_INFO_type, __pyx_k_Unsupported_INFO_type, sizeof(__pyx_k_Unsupported_INFO_type), 0, 0, 1, 0}, @@ -76349,20 +86345,23 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_VariantRecordSamples___iter, __pyx_k_VariantRecordSamples___iter, sizeof(__pyx_k_VariantRecordSamples___iter), 0, 0, 1, 1}, {&__pyx_n_s_VariantRecordSamples_iteritems, __pyx_k_VariantRecordSamples_iteritems, sizeof(__pyx_k_VariantRecordSamples_iteritems), 0, 0, 1, 1}, {&__pyx_n_s_VariantRecordSamples_itervalues, __pyx_k_VariantRecordSamples_itervalues, sizeof(__pyx_k_VariantRecordSamples_itervalues), 0, 0, 1, 1}, - {&__pyx_kp_s_Variant_read_failed, __pyx_k_Variant_read_failed, sizeof(__pyx_k_Variant_read_failed), 0, 0, 1, 0}, - {&__pyx_kp_s__167, __pyx_k__167, sizeof(__pyx_k__167), 0, 0, 1, 0}, - {&__pyx_kp_b__207, __pyx_k__207, sizeof(__pyx_k__207), 0, 0, 0, 0}, - {&__pyx_kp_b__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 0, 0, 0}, - {&__pyx_kp_s__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 0, 1, 0}, + {&__pyx_kp_b__15, __pyx_k__15, sizeof(__pyx_k__15), 0, 0, 0, 0}, + {&__pyx_kp_s__15, __pyx_k__15, sizeof(__pyx_k__15), 0, 0, 1, 0}, + {&__pyx_kp_s__175, __pyx_k__175, sizeof(__pyx_k__175), 0, 0, 1, 0}, + {&__pyx_kp_b__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 0, 0}, + {&__pyx_kp_s__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 1, 0}, + {&__pyx_kp_b__221, __pyx_k__221, sizeof(__pyx_k__221), 0, 0, 0, 0}, {&__pyx_kp_b__71, __pyx_k__71, sizeof(__pyx_k__71), 0, 0, 0, 0}, {&__pyx_kp_s__71, __pyx_k__71, sizeof(__pyx_k__71), 0, 0, 1, 0}, {&__pyx_kp_s__74, __pyx_k__74, sizeof(__pyx_k__74), 0, 0, 1, 0}, + {&__pyx_n_s_add, __pyx_k_add, sizeof(__pyx_k_add), 0, 0, 1, 1}, {&__pyx_n_s_add_meta, __pyx_k_add_meta, sizeof(__pyx_k_add_meta), 0, 0, 1, 1}, {&__pyx_n_s_add_sample, __pyx_k_add_sample, sizeof(__pyx_k_add_sample), 0, 0, 1, 1}, {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1}, {&__pyx_n_s_alleles, __pyx_k_alleles, sizeof(__pyx_k_alleles), 0, 0, 1, 1}, {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1}, {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1}, + {&__pyx_n_s_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1}, {&__pyx_n_s_bcf, __pyx_k_bcf, sizeof(__pyx_k_bcf), 0, 0, 1, 1}, {&__pyx_kp_s_bcf_2, __pyx_k_bcf_2, sizeof(__pyx_k_bcf_2), 0, 0, 1, 0}, {&__pyx_n_s_bcf_array_to_object_locals_genex, __pyx_k_bcf_array_to_object_locals_genex, sizeof(__pyx_k_bcf_array_to_object_locals_genex), 0, 0, 1, 1}, @@ -76386,13 +86385,17 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_cannot_subset_samples_from_Varia, __pyx_k_cannot_subset_samples_from_Varia, sizeof(__pyx_k_cannot_subset_samples_from_Varia), 0, 0, 1, 0}, {&__pyx_kp_s_cannot_write_to_a_Variantfile_op, __pyx_k_cannot_write_to_a_Variantfile_op, sizeof(__pyx_k_cannot_write_to_a_Variantfile_op), 0, 0, 1, 0}, {&__pyx_n_s_char_array_to_tuple_locals_genex, __pyx_k_char_array_to_tuple_locals_genex, sizeof(__pyx_k_char_array_to_tuple_locals_genex), 0, 0, 1, 1}, + {&__pyx_n_s_check_truncation, __pyx_k_check_truncation, sizeof(__pyx_k_check_truncation), 0, 0, 1, 1}, {&__pyx_n_s_chr, __pyx_k_chr, sizeof(__pyx_k_chr), 0, 0, 1, 1}, {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1}, {&__pyx_n_s_contig, __pyx_k_contig, sizeof(__pyx_k_contig), 0, 0, 1, 1}, + {&__pyx_kp_s_contig_must_be_specified, __pyx_k_contig_must_be_specified, sizeof(__pyx_k_contig_must_be_specified), 0, 0, 1, 0}, {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1}, {&__pyx_kp_s_could_not_open_file_mode, __pyx_k_could_not_open_file_mode, sizeof(__pyx_k_could_not_open_file_mode), 0, 0, 1, 0}, - {&__pyx_kp_s_could_not_open_file_mode_is_it_V, __pyx_k_could_not_open_file_mode_is_it_V, sizeof(__pyx_k_could_not_open_file_mode_is_it_V), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_open_variant_file, __pyx_k_could_not_open_variant_file, sizeof(__pyx_k_could_not_open_variant_file), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_open_variant_file_2, __pyx_k_could_not_open_variant_file_2, sizeof(__pyx_k_could_not_open_variant_file_2), 0, 0, 1, 0}, + {&__pyx_n_s_decode, __pyx_k_decode, sizeof(__pyx_k_decode), 0, 0, 1, 1}, {&__pyx_n_s_default, __pyx_k_default, sizeof(__pyx_k_default), 0, 0, 1, 1}, {&__pyx_n_s_description, __pyx_k_description, sizeof(__pyx_k_description), 0, 0, 1, 1}, {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, @@ -76400,27 +86403,28 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_dst_header_must_not_be_None, __pyx_k_dst_header_must_not_be_None, sizeof(__pyx_k_dst_header_must_not_be_None), 0, 0, 1, 0}, {&__pyx_n_s_duplicate_filehandle, __pyx_k_duplicate_filehandle, sizeof(__pyx_k_duplicate_filehandle), 0, 0, 1, 1}, {&__pyx_kp_s_either_value_or_items_must_be_sp, __pyx_k_either_value_or_items_must_be_sp, sizeof(__pyx_k_either_value_or_items_must_be_sp), 0, 0, 1, 0}, + {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1}, {&__pyx_n_s_endswith, __pyx_k_endswith, sizeof(__pyx_k_endswith), 0, 0, 1, 1}, {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1}, {&__pyx_kp_s_error_in_bcf_subset_format, __pyx_k_error_in_bcf_subset_format, sizeof(__pyx_k_error_in_bcf_subset_format), 0, 0, 1, 0}, {&__pyx_kp_s_error_in_vcf_parse, __pyx_k_error_in_vcf_parse, sizeof(__pyx_k_error_in_vcf_parse), 0, 0, 1, 0}, - {&__pyx_kp_s_error_reading_BCF_file, __pyx_k_error_reading_BCF_file, sizeof(__pyx_k_error_reading_BCF_file), 0, 0, 1, 0}, - {&__pyx_kp_s_error_reading_indexed_VCF_file, __pyx_k_error_reading_indexed_VCF_file, sizeof(__pyx_k_error_reading_indexed_VCF_file), 0, 0, 1, 0}, - {&__pyx_n_s_exists, __pyx_k_exists, sizeof(__pyx_k_exists), 0, 0, 1, 1}, {&__pyx_n_s_fetch, __pyx_k_fetch, sizeof(__pyx_k_fetch), 0, 0, 1, 1}, {&__pyx_kp_s_fetch_requires_an_index, __pyx_k_fetch_requires_an_index, sizeof(__pyx_k_fetch_requires_an_index), 0, 0, 1, 0}, {&__pyx_kp_s_file_does_not_have_valid_header, __pyx_k_file_does_not_have_valid_header, sizeof(__pyx_k_file_does_not_have_valid_header), 0, 0, 1, 0}, - {&__pyx_kp_s_file_not_found, __pyx_k_file_not_found, sizeof(__pyx_k_file_not_found), 0, 0, 1, 0}, {&__pyx_n_s_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 0, 1, 1}, + {&__pyx_n_s_filter, __pyx_k_filter, sizeof(__pyx_k_filter), 0, 0, 1, 1}, {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1}, {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1}, + {&__pyx_kp_s_genotype_is_only_valid_as_a_form, __pyx_k_genotype_is_only_valid_as_a_form, sizeof(__pyx_k_genotype_is_only_valid_as_a_form), 0, 0, 1, 0}, {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1}, + {&__pyx_n_s_get_reference_name, __pyx_k_get_reference_name, sizeof(__pyx_k_get_reference_name), 0, 0, 1, 1}, {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, {&__pyx_kp_s_gz, __pyx_k_gz, sizeof(__pyx_k_gz), 0, 0, 1, 0}, {&__pyx_n_s_hash, __pyx_k_hash, sizeof(__pyx_k_hash), 0, 0, 1, 1}, {&__pyx_n_s_header, __pyx_k_header, sizeof(__pyx_k_header), 0, 0, 1, 1}, {&__pyx_kp_s_header_must_not_be_None, __pyx_k_header_must_not_be_None, sizeof(__pyx_k_header_must_not_be_None), 0, 0, 1, 0}, {&__pyx_n_s_id, __pyx_k_id, sizeof(__pyx_k_id), 0, 0, 1, 1}, + {&__pyx_n_s_ignore_truncation, __pyx_k_ignore_truncation, sizeof(__pyx_k_ignore_truncation), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_n_s_index_filename, __pyx_k_index_filename, sizeof(__pyx_k_index_filename), 0, 0, 1, 1}, {&__pyx_n_s_info, __pyx_k_info, sizeof(__pyx_k_info), 0, 0, 1, 1}, @@ -76430,6 +86434,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_invalid_VariantRecord, __pyx_k_invalid_VariantRecord, sizeof(__pyx_k_invalid_VariantRecord), 0, 0, 1, 0}, {&__pyx_kp_s_invalid_character_found, __pyx_k_invalid_character_found, sizeof(__pyx_k_invalid_character_found), 0, 0, 1, 0}, {&__pyx_kp_s_invalid_contig, __pyx_k_invalid_contig, sizeof(__pyx_k_invalid_contig), 0, 0, 1, 0}, + {&__pyx_kp_s_invalid_contig_2, __pyx_k_invalid_contig_2, sizeof(__pyx_k_invalid_contig_2), 0, 0, 1, 0}, {&__pyx_kp_s_invalid_contig_id, __pyx_k_invalid_contig_id, sizeof(__pyx_k_invalid_contig_id), 0, 0, 1, 0}, {&__pyx_kp_s_invalid_contig_index, __pyx_k_invalid_contig_index, sizeof(__pyx_k_invalid_contig_index), 0, 0, 1, 0}, {&__pyx_kp_s_invalid_file_mode_is_it_VCF_BCF, __pyx_k_invalid_file_mode_is_it_VCF_BCF, sizeof(__pyx_k_invalid_file_mode_is_it_VCF_BCF), 0, 0, 1, 0}, @@ -76460,15 +86465,19 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1}, {&__pyx_kp_s_mode_contains_conflicting_format, __pyx_k_mode_contains_conflicting_format, sizeof(__pyx_k_mode_contains_conflicting_format), 0, 0, 1, 0}, {&__pyx_kp_s_mode_must_begin_with_r_w_or_a, __pyx_k_mode_must_begin_with_r_w_or_a, sizeof(__pyx_k_mode_must_begin_with_r_w_or_a), 0, 0, 1, 0}, + {&__pyx_kp_s_must_set_at_least_2_alleles, __pyx_k_must_set_at_least_2_alleles, sizeof(__pyx_k_must_set_at_least_2_alleles), 0, 0, 1, 0}, {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1}, {&__pyx_n_s_new_record, __pyx_k_new_record, sizeof(__pyx_k_new_record), 0, 0, 1, 1}, {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0}, {&__pyx_n_s_number, __pyx_k_number, sizeof(__pyx_k_number), 0, 0, 1, 1}, + {&__pyx_n_s_object, __pyx_k_object, sizeof(__pyx_k_object), 0, 0, 1, 1}, {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1}, {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1}, + {&__pyx_n_s_parse_region, __pyx_k_parse_region, sizeof(__pyx_k_parse_region), 0, 0, 1, 1}, + {&__pyx_n_s_phased, __pyx_k_phased, sizeof(__pyx_k_phased), 0, 0, 1, 1}, {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, - {&__pyx_n_s_print, __pyx_k_print, sizeof(__pyx_k_print), 0, 0, 1, 1}, + {&__pyx_n_s_pop, __pyx_k_pop, sizeof(__pyx_k_pop), 0, 0, 1, 1}, {&__pyx_n_s_pysam_libcbcf, __pyx_k_pysam_libcbcf, sizeof(__pyx_k_pysam_libcbcf), 0, 0, 1, 1}, {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1}, {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1}, @@ -76488,6 +86497,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_pyx_unpickle_VariantRecordSamp, __pyx_k_pyx_unpickle_VariantRecordSamp, sizeof(__pyx_k_pyx_unpickle_VariantRecordSamp), 0, 0, 1, 1}, {&__pyx_n_s_pyx_unpickle_VariantRecordSamp_2, __pyx_k_pyx_unpickle_VariantRecordSamp_2, sizeof(__pyx_k_pyx_unpickle_VariantRecordSamp_2), 0, 0, 1, 1}, {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1}, + {&__pyx_n_s_qual, __pyx_k_qual, sizeof(__pyx_k_qual), 0, 0, 1, 1}, {&__pyx_n_b_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 0, 1}, {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1}, {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, @@ -76499,12 +86509,12 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, {&__pyx_n_s_ref, __pyx_k_ref, sizeof(__pyx_k_ref), 0, 0, 1, 1}, {&__pyx_kp_s_ref_allele_must_not_be_null, __pyx_k_ref_allele_must_not_be_null, sizeof(__pyx_k_ref_allele_must_not_be_null), 0, 0, 1, 0}, + {&__pyx_n_s_reference, __pyx_k_reference, sizeof(__pyx_k_reference), 0, 0, 1, 1}, {&__pyx_n_s_region, __pyx_k_region, sizeof(__pyx_k_region), 0, 0, 1, 1}, {&__pyx_n_s_remap, __pyx_k_remap, sizeof(__pyx_k_remap), 0, 0, 1, 1}, {&__pyx_n_s_reopen, __pyx_k_reopen, sizeof(__pyx_k_reopen), 0, 0, 1, 1}, {&__pyx_n_s_reversed, __pyx_k_reversed, sizeof(__pyx_k_reversed), 0, 0, 1, 1}, {&__pyx_n_s_rwa, __pyx_k_rwa, sizeof(__pyx_k_rwa), 0, 0, 1, 1}, - {&__pyx_kp_s_s_Warning_no_BGZF_EOF_marker_fi, __pyx_k_s_Warning_no_BGZF_EOF_marker_fi, sizeof(__pyx_k_s_Warning_no_BGZF_EOF_marker_fi), 0, 0, 1, 0}, {&__pyx_kp_s_sample_must_not_be_None, __pyx_k_sample_must_not_be_None, sizeof(__pyx_k_sample_must_not_be_None), 0, 0, 1, 0}, {&__pyx_n_s_samples, __pyx_k_samples, sizeof(__pyx_k_samples), 0, 0, 1, 1}, {&__pyx_n_s_seek, __pyx_k_seek, sizeof(__pyx_k_seek), 0, 0, 1, 1}, @@ -76524,9 +86534,13 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_tell, __pyx_k_tell, sizeof(__pyx_k_tell), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_kp_s_this_class_cannot_be_instantiate, __pyx_k_this_class_cannot_be_instantiate, sizeof(__pyx_k_this_class_cannot_be_instantiate), 0, 0, 1, 0}, + {&__pyx_n_s_threads, __pyx_k_threads, sizeof(__pyx_k_threads), 0, 0, 1, 1}, {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1}, {&__pyx_kp_s_truncated_file, __pyx_k_truncated_file, sizeof(__pyx_k_truncated_file), 0, 0, 1, 0}, {&__pyx_n_s_type, __pyx_k_type, sizeof(__pyx_k_type), 0, 0, 1, 1}, + {&__pyx_kp_s_unable_to_allocate_BCF_record, __pyx_k_unable_to_allocate_BCF_record, sizeof(__pyx_k_unable_to_allocate_BCF_record), 0, 0, 1, 0}, + {&__pyx_kp_s_unable_to_fetch, __pyx_k_unable_to_fetch, sizeof(__pyx_k_unable_to_fetch), 0, 0, 1, 0}, + {&__pyx_kp_s_unable_to_fetch_next_record, __pyx_k_unable_to_fetch_next_record, sizeof(__pyx_k_unable_to_fetch_next_record), 0, 0, 1, 0}, {&__pyx_kp_s_unknown_INFO, __pyx_k_unknown_INFO, sizeof(__pyx_k_unknown_INFO), 0, 0, 1, 0}, {&__pyx_kp_s_unknown_format, __pyx_k_unknown_format, sizeof(__pyx_k_unknown_format), 0, 0, 1, 0}, {&__pyx_kp_s_unknown_mode, __pyx_k_unknown_mode, sizeof(__pyx_k_unknown_mode), 0, 0, 1, 0}, @@ -76538,13 +86552,12 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, {&__pyx_n_s_upper, __pyx_k_upper, sizeof(__pyx_k_upper), 0, 0, 1, 1}, {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1}, - {&__pyx_kp_s_value_expected_to_be_scalar, __pyx_k_value_expected_to_be_scalar, sizeof(__pyx_k_value_expected_to_be_scalar), 0, 0, 1, 0}, - {&__pyx_kp_s_values_expected_to_be_d_tuple, __pyx_k_values_expected_to_be_d_tuple, sizeof(__pyx_k_values_expected_to_be_d_tuple), 0, 0, 1, 0}, + {&__pyx_kp_s_value_expected_to_be_scalar_give, __pyx_k_value_expected_to_be_scalar_give, sizeof(__pyx_k_value_expected_to_be_scalar_give), 0, 0, 1, 0}, + {&__pyx_n_s_values, __pyx_k_values, sizeof(__pyx_k_values), 0, 0, 1, 1}, + {&__pyx_kp_s_values_expected_to_be_tuple_give, __pyx_k_values_expected_to_be_tuple_give, sizeof(__pyx_k_values_expected_to_be_tuple_give), 0, 0, 1, 0}, {&__pyx_kp_s_vcf_format_failed, __pyx_k_vcf_format_failed, sizeof(__pyx_k_vcf_format_failed), 0, 0, 1, 0}, {&__pyx_n_b_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 0, 0, 1}, {&__pyx_n_s_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 0, 1, 1}, - {&__pyx_n_s_warn, __pyx_k_warn, sizeof(__pyx_k_warn), 0, 0, 1, 1}, - {&__pyx_n_s_warnings, __pyx_k_warnings, sizeof(__pyx_k_warnings), 0, 0, 1, 1}, {&__pyx_n_s_wb, __pyx_k_wb, sizeof(__pyx_k_wb), 0, 0, 1, 1}, {&__pyx_n_s_wb0, __pyx_k_wb0, sizeof(__pyx_k_wb0), 0, 0, 1, 1}, {&__pyx_n_s_wbu, __pyx_k_wbu, sizeof(__pyx_k_wbu), 0, 0, 1, 1}, @@ -76553,19 +86566,19 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 175, __pyx_L1_error) - __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 228, __pyx_L1_error) - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 307, __pyx_L1_error) - __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) __PYX_ERR(0, 457, __pyx_L1_error) - __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 593, __pyx_L1_error) - __pyx_builtin_print = __Pyx_GetBuiltinName(__pyx_n_s_print); if (!__pyx_builtin_print) __PYX_ERR(0, 1240, __pyx_L1_error) - __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(0, 1273, __pyx_L1_error) - __pyx_builtin_reversed = __Pyx_GetBuiltinName(__pyx_n_s_reversed); if (!__pyx_builtin_reversed) __PYX_ERR(0, 2179, __pyx_L1_error) - __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 3142, __pyx_L1_error) - __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 3283, __pyx_L1_error) - __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 3500, __pyx_L1_error) - __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 3528, __pyx_L1_error) - __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(3, 109, __pyx_L1_error) + __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) __PYX_ERR(0, 134, __pyx_L1_error) + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 188, __pyx_L1_error) + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 227, __pyx_L1_error) + __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 313, __pyx_L1_error) + __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) __PYX_ERR(0, 542, __pyx_L1_error) + __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 677, __pyx_L1_error) + __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(0, 1430, __pyx_L1_error) + __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 2058, __pyx_L1_error) + __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 2088, __pyx_L1_error) + __pyx_builtin_NotImplemented = __Pyx_GetBuiltinName(__pyx_n_s_NotImplemented); if (!__pyx_builtin_NotImplemented) __PYX_ERR(0, 2322, __pyx_L1_error) + __pyx_builtin_reversed = __Pyx_GetBuiltinName(__pyx_n_s_reversed); if (!__pyx_builtin_reversed) __PYX_ERR(0, 2410, __pyx_L1_error) + __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 3783, __pyx_L1_error) + __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 3797, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; @@ -76575,675 +86588,664 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "pysam/libcbcf.pyx":199 - * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. + /* "pysam/libcbcf.pyx":227 * - * value = tuple(v or None for v in value.split(',')) if value else () # <<<<<<<<<<<<<< - * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. + * if sample < 0: + * raise ValueError('genotype is only valid as a format field') # <<<<<<<<<<<<<< + * + * cdef int32_t *gt_arr = NULL + */ + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_genotype_is_only_valid_as_a_form); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 227, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple_); + __Pyx_GIVEREF(__pyx_tuple_); + + /* "pysam/libcbcf.pyx":285 + * # Otherwise, copy the entire block + * b = datac[:n] + * value = tuple(v.decode('ascii') if v and v != bcf_str_missing else None for v in b.split(b',')) # <<<<<<<<<<<<<< * else: + * value = [] */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 199, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__2); - __Pyx_GIVEREF(__pyx_tuple__2); + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); - /* "pysam/libcbcf.pyx":228 + /* "pysam/libcbcf.pyx":313 * value.append(dataf[i] if not bcf_float_is_missing(dataf[i]) else None) * else: * raise TypeError('unsupported info type code') # <<<<<<<<<<<<<< * * # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. */ - __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_unsupported_info_type_code); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 228, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__3); - __Pyx_GIVEREF(__pyx_tuple__3); + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_unsupported_info_type_code); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 313, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); - /* "pysam/libcbcf.pyx":237 + /* "pysam/libcbcf.pyx":322 * value = () * else: * value = (None,)*count # <<<<<<<<<<<<<< * elif scalar and len(value) == 1: * value = value[0] */ - __pyx_tuple__4 = PyTuple_New(1); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__4); + __pyx_tuple__5 = PyTuple_New(1); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 322, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__5); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_tuple__4, 0, Py_None); - __Pyx_GIVEREF(__pyx_tuple__4); + PyTuple_SET_ITEM(__pyx_tuple__5, 0, Py_None); + __Pyx_GIVEREF(__pyx_tuple__5); - /* "pysam/libcbcf.pyx":297 + /* "pysam/libcbcf.pyx":382 * bcf_float_set(dataf + i, bcf_float_vector_end) * else: * raise TypeError('unsupported type') # <<<<<<<<<<<<<< * * */ - __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_unsupported_type); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 297, __pyx_L1_error) + __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_unsupported_type); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 382, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__6); __Pyx_GIVEREF(__pyx_tuple__6); - /* "pysam/libcbcf.pyx":307 + /* "pysam/libcbcf.pyx":392 * * if n <= 0: * raise ValueError('Cannot create empty array') # <<<<<<<<<<<<<< * * if type == BCF_HT_STR: */ - __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_Cannot_create_empty_array); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 307, __pyx_L1_error) + __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_Cannot_create_empty_array); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 392, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__7); __Pyx_GIVEREF(__pyx_tuple__7); - /* "pysam/libcbcf.pyx":325 + /* "pysam/libcbcf.pyx":410 * bcf_float_set(dataf + i, bcf_float_missing if not vlen else bcf_float_vector_end) * else: * raise TypeError('unsupported header type code') # <<<<<<<<<<<<<< * * return value */ - __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_unsupported_header_type_code); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 325, __pyx_L1_error) + __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_unsupported_header_type_code); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 410, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__8); __Pyx_GIVEREF(__pyx_tuple__8); - /* "pysam/libcbcf.pyx":392 + /* "pysam/libcbcf.pyx":477 * bcf_float_set(dst_dataf + i, bcf_float_missing if not vlen else bcf_float_vector_end) * else: * raise TypeError('unsupported types') # <<<<<<<<<<<<<< * * */ - __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_unsupported_types); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 392, __pyx_L1_error) + __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_unsupported_types); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 477, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__9); __Pyx_GIVEREF(__pyx_tuple__9); - /* "pysam/libcbcf.pyx":397 - * cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar): + /* "pysam/libcbcf.pyx":482 + * cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar, int sample): * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = record.header.ptr */ - __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 397, __pyx_L1_error) + __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 482, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__10); __Pyx_GIVEREF(__pyx_tuple__10); - /* "pysam/libcbcf.pyx":403 + /* "pysam/libcbcf.pyx":488 * * if not check_header_id(hdr, hl_type, id): * raise ValueError('Invalid header') # <<<<<<<<<<<<<< * * cdef int length = bcf_hdr_id2length(hdr, hl_type, id) */ - __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 403, __pyx_L1_error) + __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__11); __Pyx_GIVEREF(__pyx_tuple__11); - /* "pysam/libcbcf.pyx":425 + /* "pysam/libcbcf.pyx":510 * count[0] = -1 * else: * raise ValueError('Unknown format length') # <<<<<<<<<<<<<< * * */ - __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_Unknown_format_length); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 425, __pyx_L1_error) + __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_Unknown_format_length); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 510, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__12); __Pyx_GIVEREF(__pyx_tuple__12); - /* "pysam/libcbcf.pyx":430 + /* "pysam/libcbcf.pyx":515 * cdef object bcf_info_get_value(VariantRecord record, const bcf_info_t *z): * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = record.header.ptr */ - __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 430, __pyx_L1_error) + __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 515, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__13); __Pyx_GIVEREF(__pyx_tuple__13); - /* "pysam/libcbcf.pyx":459 + /* "pysam/libcbcf.pyx":544 * value = force_str(chr(z.v1.i)) * else: * raise TypeError('unsupported info type code') # <<<<<<<<<<<<<< * * if not scalar and value != (): */ - __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_unsupported_info_type_code); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 459, __pyx_L1_error) + __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_unsupported_info_type_code); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 544, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__14); __Pyx_GIVEREF(__pyx_tuple__14); - /* "pysam/libcbcf.pyx":474 + /* "pysam/libcbcf.pyx":560 * * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * - * bcf_get_value_count(record, hl_type, id, value_count, scalar) + * bcf_get_value_count(record, hl_type, id, value_count, scalar, sample) */ - __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 474, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__15); - __Pyx_GIVEREF(__pyx_tuple__15); + __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 560, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__16); + __Pyx_GIVEREF(__pyx_tuple__16); - /* "pysam/libcbcf.pyx":497 + /* "pysam/libcbcf.pyx":584 * for v in values: * if not(v is None or isinstance(v, (float, int))): * raise TypeError('invalid value for Float format') # <<<<<<<<<<<<<< * elif ht_type == BCF_HT_INT: * for v in values: */ - __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_s_invalid_value_for_Float_format); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 497, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__16); - __Pyx_GIVEREF(__pyx_tuple__16); + __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s_invalid_value_for_Float_format); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__17); + __Pyx_GIVEREF(__pyx_tuple__17); - /* "pysam/libcbcf.pyx":501 + /* "pysam/libcbcf.pyx":588 * for v in values: * if not(v is None or (isinstance(v, (float, int)) and int(v) == v)): * raise TypeError('invalid value for Integer format') # <<<<<<<<<<<<<< * for v in values: * if not(v is None or bcf_int32_missing < v <= INT32_MAX): */ - __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s_invalid_value_for_Integer_format); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 501, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__17); - __Pyx_GIVEREF(__pyx_tuple__17); + __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_invalid_value_for_Integer_format); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__18); + __Pyx_GIVEREF(__pyx_tuple__18); - /* "pysam/libcbcf.pyx":504 + /* "pysam/libcbcf.pyx":591 * for v in values: * if not(v is None or bcf_int32_missing < v <= INT32_MAX): * raise ValueError('Integer value too small/large to store in VCF/BCF') # <<<<<<<<<<<<<< * elif ht_type == BCF_HT_STR: * values = b','.join(force_bytes(v) if v is not None else b'' for v in values) */ - __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_Integer_value_too_small_large_to); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 504, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__18); - __Pyx_GIVEREF(__pyx_tuple__18); + __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_Integer_value_too_small_large_to); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 591, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__19); + __Pyx_GIVEREF(__pyx_tuple__19); - /* "pysam/libcbcf.pyx":509 + /* "pysam/libcbcf.pyx":596 * elif ht_type == BCF_HT_FLAG: * if values[0] not in (True, False, None, 1, 0): * raise ValueError('Flag values must be: True, False, None, 1, 0') # <<<<<<<<<<<<<< * else: * raise TypeError('unsupported type') */ - __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_Flag_values_must_be_True_False_N); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 509, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__19); - __Pyx_GIVEREF(__pyx_tuple__19); + __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_Flag_values_must_be_True_False_N); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 596, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__20); + __Pyx_GIVEREF(__pyx_tuple__20); - /* "pysam/libcbcf.pyx":511 + /* "pysam/libcbcf.pyx":598 * raise ValueError('Flag values must be: True, False, None, 1, 0') * else: * raise TypeError('unsupported type') # <<<<<<<<<<<<<< * * realloc[0] = 0 */ - __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_unsupported_type); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 511, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__20); - __Pyx_GIVEREF(__pyx_tuple__20); + __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_unsupported_type); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 598, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__21); + __Pyx_GIVEREF(__pyx_tuple__21); - /* "pysam/libcbcf.pyx":534 + /* "pysam/libcbcf.pyx":621 * cdef bcf_encode_alleles(VariantRecord record, values): * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * cdef bcf1_t *r = record.ptr */ - __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 534, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__21); - __Pyx_GIVEREF(__pyx_tuple__21); + __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 621, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__22); + __Pyx_GIVEREF(__pyx_tuple__22); - /* "pysam/libcbcf.pyx":559 + /* "pysam/libcbcf.pyx":646 * break * else: * raise ValueError('Unknown allele') # <<<<<<<<<<<<<< * else: * i = value */ - __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_Unknown_allele); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 559, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__22); - __Pyx_GIVEREF(__pyx_tuple__22); + __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_Unknown_allele); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 646, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__23); + __Pyx_GIVEREF(__pyx_tuple__23); - /* "pysam/libcbcf.pyx":563 + /* "pysam/libcbcf.pyx":650 * i = value * if not (0 <= i < nalleles): * raise ValueError('Invalid allele index') # <<<<<<<<<<<<<< * gt_values.append(bcf_gt_unphased(i)) * */ - __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_Invalid_allele_index); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 563, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__23); - __Pyx_GIVEREF(__pyx_tuple__23); + __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_Invalid_allele_index); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 650, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__24); + __Pyx_GIVEREF(__pyx_tuple__24); - /* "pysam/libcbcf.pyx":571 + /* "pysam/libcbcf.pyx":658 * cdef bcf_info_set_value(VariantRecord record, key, value): * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = record.header.ptr */ - __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__24); - __Pyx_GIVEREF(__pyx_tuple__24); - - /* "pysam/libcbcf.pyx":581 - * - * if bcf_unpack(r, BCF_UN_INFO) < 0: - * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< - * - * bkey = force_bytes(key) - */ - __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 581, __pyx_L1_error) + __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 658, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__25); __Pyx_GIVEREF(__pyx_tuple__25); - /* "pysam/libcbcf.pyx":593 + /* "pysam/libcbcf.pyx":666 * - * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: - * raise KeyError('unknown INFO') # <<<<<<<<<<<<<< + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * info_id = kh_val_vdict(d, k).id + * cdef bytes bkey = force_bytes(key) */ - __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_unknown_INFO); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 593, __pyx_L1_error) + __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 666, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__26); __Pyx_GIVEREF(__pyx_tuple__26); - /* "pysam/libcbcf.pyx":598 + /* "pysam/libcbcf.pyx":680 * * if not check_header_id(hdr, BCF_HL_INFO, info_id): * raise ValueError('Invalid header') # <<<<<<<<<<<<<< * * info_type = bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) */ - __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 598, __pyx_L1_error) + __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 680, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__27); __Pyx_GIVEREF(__pyx_tuple__27); - /* "pysam/libcbcf.pyx":608 + /* "pysam/libcbcf.pyx":691 * if info_type == BCF_HT_FLAG: * if bcf_update_info(hdr, r, bkey, NULL, bool(values[0]), info_type) < 0: * raise ValueError('Unable to update INFO values') # <<<<<<<<<<<<<< * return * */ - __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_update_INFO_values); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 608, __pyx_L1_error) + __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_update_INFO_values); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 691, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__28); __Pyx_GIVEREF(__pyx_tuple__28); - /* "pysam/libcbcf.pyx":628 - * bcf_object_to_array(values, &info.v1.f, BCF_BT_FLOAT, 1, vlen) - * else: - * raise TypeError('unsupported info type code') # <<<<<<<<<<<<<< - * info.len = 1 - * else: - */ - __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_unsupported_info_type_code); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 628, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__29); - __Pyx_GIVEREF(__pyx_tuple__29); - - /* "pysam/libcbcf.pyx":648 + /* "pysam/libcbcf.pyx":738 * dst_type = BCF_BT_CHAR * else: * raise ValueError('Unsupported INFO type') # <<<<<<<<<<<<<< * * bcf_object_to_array(values, valp, dst_type, alloc_len, vlen) */ - __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_s_Unsupported_INFO_type); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 648, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__30); - __Pyx_GIVEREF(__pyx_tuple__30); + __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_Unsupported_INFO_type); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 738, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__29); + __Pyx_GIVEREF(__pyx_tuple__29); - /* "pysam/libcbcf.pyx":653 + /* "pysam/libcbcf.pyx":743 * * if bcf_update_info(hdr, r, bkey, valp, alloc_len, info_type) < 0: * raise ValueError('Unable to update INFO values') # <<<<<<<<<<<<<< * * */ - __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_update_INFO_values); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 653, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__31); - __Pyx_GIVEREF(__pyx_tuple__31); + __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_update_INFO_values); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 743, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__30); + __Pyx_GIVEREF(__pyx_tuple__30); - /* "pysam/libcbcf.pyx":658 + /* "pysam/libcbcf.pyx":748 * cdef bcf_info_del_value(VariantRecord record, key): * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = record.header.ptr */ - __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 658, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__32); - __Pyx_GIVEREF(__pyx_tuple__32); + __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 748, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__31); + __Pyx_GIVEREF(__pyx_tuple__31); - /* "pysam/libcbcf.pyx":666 + /* "pysam/libcbcf.pyx":756 * * if bcf_unpack(r, BCF_UN_INFO) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ - __pyx_tuple__33 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 666, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__33); - __Pyx_GIVEREF(__pyx_tuple__33); + __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 756, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__32); + __Pyx_GIVEREF(__pyx_tuple__32); - /* "pysam/libcbcf.pyx":681 + /* "pysam/libcbcf.pyx":771 * null_value = None * else: * null_value = (None,)*value_count # <<<<<<<<<<<<<< * * bcf_info_set_value(record, bkey, null_value) */ - __pyx_tuple__34 = PyTuple_New(1); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 681, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__34); + __pyx_tuple__33 = PyTuple_New(1); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 771, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__33); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_tuple__34, 0, Py_None); - __Pyx_GIVEREF(__pyx_tuple__34); + PyTuple_SET_ITEM(__pyx_tuple__33, 0, Py_None); + __Pyx_GIVEREF(__pyx_tuple__33); - /* "pysam/libcbcf.pyx":688 + /* "pysam/libcbcf.pyx":778 * cdef bcf_format_get_value(VariantRecordSample sample, key): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = sample.record.header.ptr */ - __pyx_tuple__35 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 688, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__35); - __Pyx_GIVEREF(__pyx_tuple__35); + __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 778, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__34); + __Pyx_GIVEREF(__pyx_tuple__34); - /* "pysam/libcbcf.pyx":696 + /* "pysam/libcbcf.pyx":786 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) - */ - __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 696, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__36); - __Pyx_GIVEREF(__pyx_tuple__36); - - /* "pysam/libcbcf.pyx":702 - * - * if not fmt or not fmt.p: - * raise KeyError('invalid FORMAT') # <<<<<<<<<<<<<< - * - * if is_gt_fmt(hdr, fmt.id): + * cdef bytes bkey = force_bytes(key) */ - __pyx_tuple__37 = PyTuple_Pack(1, __pyx_kp_s_invalid_FORMAT); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 702, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__37); - __Pyx_GIVEREF(__pyx_tuple__37); + __pyx_tuple__35 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 786, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__35); + __Pyx_GIVEREF(__pyx_tuple__35); - /* "pysam/libcbcf.pyx":716 + /* "pysam/libcbcf.pyx":806 * return () * else: * return (None,)*count # <<<<<<<<<<<<<< * * */ - __pyx_tuple__38 = PyTuple_New(1); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 716, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__38); + __pyx_tuple__36 = PyTuple_New(1); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 806, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__36); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_tuple__38, 0, Py_None); - __Pyx_GIVEREF(__pyx_tuple__38); + PyTuple_SET_ITEM(__pyx_tuple__36, 0, Py_None); + __Pyx_GIVEREF(__pyx_tuple__36); - /* "pysam/libcbcf.pyx":721 + /* "pysam/libcbcf.pyx":811 * cdef bcf_format_set_value(VariantRecordSample sample, key, value): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * - * cdef bcf_hdr_t *hdr = sample.record.header.ptr + * if key == 'phased': */ - __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 721, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__39); - __Pyx_GIVEREF(__pyx_tuple__39); + __pyx_tuple__37 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 811, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__37); + __Pyx_GIVEREF(__pyx_tuple__37); - /* "pysam/libcbcf.pyx":732 + /* "pysam/libcbcf.pyx":826 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ - __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(0, 732, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__40); - __Pyx_GIVEREF(__pyx_tuple__40); - - /* "pysam/libcbcf.pyx":744 - * - * if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_FMT] & 0xF == 0xF: - * raise KeyError('unknown format') # <<<<<<<<<<<<<< - * - * fmt_id = kh_val_vdict(d, k).id - */ - __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_unknown_format); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 744, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__41); - __Pyx_GIVEREF(__pyx_tuple__41); + __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 826, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__38); + __Pyx_GIVEREF(__pyx_tuple__38); - /* "pysam/libcbcf.pyx":749 + /* "pysam/libcbcf.pyx":843 * * if not check_header_id(hdr, BCF_HL_FMT, fmt_id): * raise ValueError('Invalid header') # <<<<<<<<<<<<<< * * fmt_type = bcf_hdr_id2type(hdr, BCF_HL_FMT, fmt_id) */ - __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 749, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__42); - __Pyx_GIVEREF(__pyx_tuple__42); + __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 843, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__39); + __Pyx_GIVEREF(__pyx_tuple__39); - /* "pysam/libcbcf.pyx":754 + /* "pysam/libcbcf.pyx":848 * * if fmt_type == BCF_HT_FLAG: * raise ValueError('Flag types are not allowed on FORMATs') # <<<<<<<<<<<<<< * * if is_gt_fmt(hdr, fmt_id): */ - __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_Flag_types_are_not_allowed_on_FO); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 754, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__43); - __Pyx_GIVEREF(__pyx_tuple__43); + __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_Flag_types_are_not_allowed_on_FO); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(0, 848, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__40); + __Pyx_GIVEREF(__pyx_tuple__40); - /* "pysam/libcbcf.pyx":793 + /* "pysam/libcbcf.pyx":888 * dst_size = sizeof(char) * alloc_len * else: * raise ValueError('Unsupported FORMAT type') # <<<<<<<<<<<<<< * * if fmt and n > 1: */ - __pyx_tuple__44 = PyTuple_Pack(1, __pyx_kp_s_Unsupported_FORMAT_type); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 793, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__44); - __Pyx_GIVEREF(__pyx_tuple__44); + __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_Unsupported_FORMAT_type); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 888, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__41); + __Pyx_GIVEREF(__pyx_tuple__41); - /* "pysam/libcbcf.pyx":804 + /* "pysam/libcbcf.pyx":899 * * if bcf_update_format(hdr, r, bkey, valp, (n*alloc_len), fmt_type) < 0: * raise ValueError('Unable to update format values') # <<<<<<<<<<<<<< * * */ - __pyx_tuple__45 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_update_format_values); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 804, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__45); - __Pyx_GIVEREF(__pyx_tuple__45); + __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_update_format_values); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 899, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__42); + __Pyx_GIVEREF(__pyx_tuple__42); - /* "pysam/libcbcf.pyx":809 + /* "pysam/libcbcf.pyx":904 * cdef bcf_format_del_value(VariantRecordSample sample, key): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = sample.record.header.ptr */ - __pyx_tuple__46 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 809, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__46); - __Pyx_GIVEREF(__pyx_tuple__46); + __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 904, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__43); + __Pyx_GIVEREF(__pyx_tuple__43); - /* "pysam/libcbcf.pyx":817 + /* "pysam/libcbcf.pyx":912 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * cdef bytes bkey = force_bytes(key) */ - __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 817, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__47); - __Pyx_GIVEREF(__pyx_tuple__47); + __pyx_tuple__44 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 912, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__44); + __Pyx_GIVEREF(__pyx_tuple__44); - /* "pysam/libcbcf.pyx":832 + /* "pysam/libcbcf.pyx":927 * null_value = None * else: * null_value = (None,)*value_count # <<<<<<<<<<<<<< * * bcf_format_set_value(sample, bkey, null_value) */ - __pyx_tuple__48 = PyTuple_New(1); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 832, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__48); + __pyx_tuple__45 = PyTuple_New(1); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__45); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); - PyTuple_SET_ITEM(__pyx_tuple__48, 0, Py_None); - __Pyx_GIVEREF(__pyx_tuple__48); + PyTuple_SET_ITEM(__pyx_tuple__45, 0, Py_None); + __Pyx_GIVEREF(__pyx_tuple__45); - /* "pysam/libcbcf.pyx":839 + /* "pysam/libcbcf.pyx":934 * cdef bcf_format_get_allele_indices(VariantRecordSample sample): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = sample.record.header.ptr */ - __pyx_tuple__49 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 839, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__49); - __Pyx_GIVEREF(__pyx_tuple__49); + __pyx_tuple__46 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 934, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__46); + __Pyx_GIVEREF(__pyx_tuple__46); - /* "pysam/libcbcf.pyx":846 + /* "pysam/libcbcf.pyx":941 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * if sample.index < 0 or sample.index >= n or not r.n_fmt: */ - __pyx_tuple__50 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 846, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__50); - __Pyx_GIVEREF(__pyx_tuple__50); + __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 941, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__47); + __Pyx_GIVEREF(__pyx_tuple__47); - /* "pysam/libcbcf.pyx":899 + /* "pysam/libcbcf.pyx":994 * cdef bcf_format_get_alleles(VariantRecordSample sample): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = sample.record.header.ptr */ - __pyx_tuple__51 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 899, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__51); - __Pyx_GIVEREF(__pyx_tuple__51); + __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 994, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__48); + __Pyx_GIVEREF(__pyx_tuple__48); - /* "pysam/libcbcf.pyx":906 + /* "pysam/libcbcf.pyx":1001 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * cdef int32_t nalleles = r.n_allele */ - __pyx_tuple__52 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(0, 906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__52); - __Pyx_GIVEREF(__pyx_tuple__52); + __pyx_tuple__49 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 1001, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__49); + __Pyx_GIVEREF(__pyx_tuple__49); - /* "pysam/libcbcf.pyx":950 + /* "pysam/libcbcf.pyx":1045 * cdef bint bcf_sample_get_phased(VariantRecordSample sample): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = sample.record.header.ptr */ - __pyx_tuple__53 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 950, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__53); - __Pyx_GIVEREF(__pyx_tuple__53); + __pyx_tuple__50 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 1045, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__50); + __Pyx_GIVEREF(__pyx_tuple__50); - /* "pysam/libcbcf.pyx":957 + /* "pysam/libcbcf.pyx":1052 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * if sample.index < 0 or sample.index >= n or not r.n_fmt: */ - __pyx_tuple__54 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(0, 957, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__54); - __Pyx_GIVEREF(__pyx_tuple__54); + __pyx_tuple__51 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 1052, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__51); + __Pyx_GIVEREF(__pyx_tuple__51); - /* "pysam/libcbcf.pyx":1013 + /* "pysam/libcbcf.pyx":1108 * cdef bcf_sample_set_phased(VariantRecordSample sample, bint phased): * if sample is None: * raise ValueError('sample must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = sample.record.header.ptr */ - __pyx_tuple__55 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 1013, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__55); - __Pyx_GIVEREF(__pyx_tuple__55); + __pyx_tuple__52 = PyTuple_Pack(1, __pyx_kp_s_sample_must_not_be_None); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(0, 1108, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__52); + __Pyx_GIVEREF(__pyx_tuple__52); - /* "pysam/libcbcf.pyx":1020 + /* "pysam/libcbcf.pyx":1115 * * if bcf_unpack(r, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * if sample.index < 0 or sample.index >= n or not r.n_fmt: */ - __pyx_tuple__56 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(0, 1020, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__56); - __Pyx_GIVEREF(__pyx_tuple__56); + __pyx_tuple__53 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 1115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__53); + __Pyx_GIVEREF(__pyx_tuple__53); - /* "pysam/libcbcf.pyx":1029 + /* "pysam/libcbcf.pyx":1124 * * if not gt0 or not fmt0.n: * raise ValueError('Cannot set phased before genotype is set') # <<<<<<<<<<<<<< * * cdef int8_t *data8 */ - __pyx_tuple__57 = PyTuple_Pack(1, __pyx_kp_s_Cannot_set_phased_before_genotyp); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(0, 1029, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__57); - __Pyx_GIVEREF(__pyx_tuple__57); + __pyx_tuple__54 = PyTuple_Pack(1, __pyx_kp_s_Cannot_set_phased_before_genotyp); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(0, 1124, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__54); + __Pyx_GIVEREF(__pyx_tuple__54); + + /* "pysam/libcbcf.pyx":1179 + * if info and info.vptr: + * if bcf_update_info(hdr, record.ptr, b'END', NULL, 0, info.type) < 0: + * raise ValueError('Unable to delete END') # <<<<<<<<<<<<<< + * else: + * # Create END header, if not present + */ + __pyx_tuple__55 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_delete_END); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 1179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__55); + __Pyx_GIVEREF(__pyx_tuple__55); + + /* "pysam/libcbcf.pyx":1183 + * # Create END header, if not present + * if end_id < 0: + * record.header.info.add('END', number=1, type='Integer', description='Stop position of the interval') # <<<<<<<<<<<<<< + * + * # Update to reflect stop position + */ + __pyx_tuple__56 = PyTuple_Pack(1, __pyx_n_s_END); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(0, 1183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__56); + __Pyx_GIVEREF(__pyx_tuple__56); - /* "pysam/libcbcf.pyx":1072 + /* "pysam/libcbcf.pyx":1208 * cdef bcf_header_remove_hrec(VariantHeader header, int i): * if header is None: * raise ValueError('header must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *hdr = header.ptr */ - __pyx_tuple__58 = PyTuple_Pack(1, __pyx_kp_s_header_must_not_be_None); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(0, 1072, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__58); - __Pyx_GIVEREF(__pyx_tuple__58); + __pyx_tuple__57 = PyTuple_Pack(1, __pyx_kp_s_header_must_not_be_None); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(0, 1208, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__57); + __Pyx_GIVEREF(__pyx_tuple__57); - /* "pysam/libcbcf.pyx":1077 + /* "pysam/libcbcf.pyx":1213 * * if i < 0 or i >= hdr.nhrec: * raise ValueError('Invalid header record index') # <<<<<<<<<<<<<< * * cdef bcf_hrec_t *hrec = hdr.hrec[i] */ - __pyx_tuple__59 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header_record_index); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(0, 1077, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__59); - __Pyx_GIVEREF(__pyx_tuple__59); + __pyx_tuple__58 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header_record_index); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(0, 1213, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__58); + __Pyx_GIVEREF(__pyx_tuple__58); - /* "pysam/libcbcf.pyx":1096 + /* "pysam/libcbcf.pyx":1232 * """header record from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * @property */ - __pyx_tuple__60 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(0, 1096, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__60); - __Pyx_GIVEREF(__pyx_tuple__60); + __pyx_tuple__59 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(0, 1232, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__59); + __Pyx_GIVEREF(__pyx_tuple__59); - /* "pysam/libcbcf.pyx":1146 + /* "pysam/libcbcf.pyx":1282 * if r.keys[i] and r.keys[i] == bkey: * return charptr_to_str(r.vals[i]) if r.vals[i] else None * raise KeyError('cannot find metadata key') # <<<<<<<<<<<<<< * * def __iter__(self): */ - __pyx_tuple__61 = PyTuple_Pack(1, __pyx_kp_s_cannot_find_metadata_key); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(0, 1146, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__61); - __Pyx_GIVEREF(__pyx_tuple__61); + __pyx_tuple__60 = PyTuple_Pack(1, __pyx_kp_s_cannot_find_metadata_key); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(0, 1282, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__60); + __Pyx_GIVEREF(__pyx_tuple__60); - /* "pysam/libcbcf.pyx":1217 + /* "pysam/libcbcf.pyx":1375 * * if not r: * raise ValueError('cannot convert deleted record to str') # <<<<<<<<<<<<<< * * cdef kstring_t hrec_str */ - __pyx_tuple__62 = PyTuple_Pack(1, __pyx_kp_s_cannot_convert_deleted_record_to); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(0, 1217, __pyx_L1_error) + __pyx_tuple__62 = PyTuple_Pack(1, __pyx_kp_s_cannot_convert_deleted_record_to); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(0, 1375, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__62); __Pyx_GIVEREF(__pyx_tuple__62); @@ -77253,7 +87255,7 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") */ - __pyx_tuple__63 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_tuple__63 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(2, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__63); __Pyx_GIVEREF(__pyx_tuple__63); @@ -77262,416 +87264,394 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__64 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_tuple__64 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(2, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__64); __Pyx_GIVEREF(__pyx_tuple__64); - /* "pysam/libcbcf.pyx":1247 + /* "pysam/libcbcf.pyx":1404 * cdef VariantHeaderRecord makeVariantHeaderRecord(VariantHeader header, bcf_hrec_t *hdr): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * if not hdr: */ - __pyx_tuple__65 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(0, 1247, __pyx_L1_error) + __pyx_tuple__65 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(0, 1404, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__65); __Pyx_GIVEREF(__pyx_tuple__65); - /* "pysam/libcbcf.pyx":1262 + /* "pysam/libcbcf.pyx":1419 * """sequence of :class:`VariantHeaderRecord` object from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_tuple__66 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__66)) __PYX_ERR(0, 1262, __pyx_L1_error) + __pyx_tuple__66 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__66)) __PYX_ERR(0, 1419, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__66); __Pyx_GIVEREF(__pyx_tuple__66); - /* "pysam/libcbcf.pyx":1273 + /* "pysam/libcbcf.pyx":1430 * cdef int32_t i = index * if i < 0 or i >= self.header.ptr.nhrec: * raise IndexError('invalid header record index') # <<<<<<<<<<<<<< * return makeVariantHeaderRecord(self.header, self.header.ptr.hrec[i]) * */ - __pyx_tuple__67 = PyTuple_Pack(1, __pyx_kp_s_invalid_header_record_index); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(0, 1273, __pyx_L1_error) + __pyx_tuple__67 = PyTuple_Pack(1, __pyx_kp_s_invalid_header_record_index); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(0, 1430, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__67); __Pyx_GIVEREF(__pyx_tuple__67); - /* "pysam/libcbcf.pyx":1286 + /* "pysam/libcbcf.pyx":1443 * cdef VariantHeaderRecords makeVariantHeaderRecords(VariantHeader header): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * cdef VariantHeaderRecords records = VariantHeaderRecords.__new__(VariantHeaderRecords) */ - __pyx_tuple__68 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__68)) __PYX_ERR(0, 1286, __pyx_L1_error) + __pyx_tuple__68 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__68)) __PYX_ERR(0, 1443, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__68); __Pyx_GIVEREF(__pyx_tuple__68); - /* "pysam/libcbcf.pyx":1296 + /* "pysam/libcbcf.pyx":1453 * """filter, info or format metadata record from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * @property */ - __pyx_tuple__69 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__69)) __PYX_ERR(0, 1296, __pyx_L1_error) + __pyx_tuple__69 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__69)) __PYX_ERR(0, 1453, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__69); __Pyx_GIVEREF(__pyx_tuple__69); - /* "pysam/libcbcf.pyx":1316 + /* "pysam/libcbcf.pyx":1473 * * if not check_header_id(hdr, self.type, self.id): * raise ValueError('Invalid header id') # <<<<<<<<<<<<<< * * if self.type == BCF_HL_FLT: */ - __pyx_tuple__70 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header_id); if (unlikely(!__pyx_tuple__70)) __PYX_ERR(0, 1316, __pyx_L1_error) + __pyx_tuple__70 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header_id); if (unlikely(!__pyx_tuple__70)) __PYX_ERR(0, 1473, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__70); __Pyx_GIVEREF(__pyx_tuple__70); - /* "pysam/libcbcf.pyx":1334 + /* "pysam/libcbcf.pyx":1491 * cdef bcf_hdr_t *hdr = self.header.ptr * if not check_header_id(hdr, self.type, self.id): * raise ValueError('Invalid header id') # <<<<<<<<<<<<<< * * if self.type == BCF_HL_FLT: */ - __pyx_tuple__72 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header_id); if (unlikely(!__pyx_tuple__72)) __PYX_ERR(0, 1334, __pyx_L1_error) + __pyx_tuple__72 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header_id); if (unlikely(!__pyx_tuple__72)) __PYX_ERR(0, 1491, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__72); __Pyx_GIVEREF(__pyx_tuple__72); - /* "pysam/libcbcf.pyx":1343 + /* "pysam/libcbcf.pyx":1500 * def description(self): * """metadata description (or None if not set)""" * descr = self.record.get('Description') # <<<<<<<<<<<<<< * if descr: * descr = descr.strip('"') */ - __pyx_tuple__73 = PyTuple_Pack(1, __pyx_n_s_Description); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(0, 1343, __pyx_L1_error) + __pyx_tuple__73 = PyTuple_Pack(1, __pyx_n_s_Description); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(0, 1500, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__73); __Pyx_GIVEREF(__pyx_tuple__73); - /* "pysam/libcbcf.pyx":1345 + /* "pysam/libcbcf.pyx":1502 * descr = self.record.get('Description') * if descr: * descr = descr.strip('"') # <<<<<<<<<<<<<< * return force_str(descr) * */ - __pyx_tuple__75 = PyTuple_Pack(1, __pyx_kp_s__74); if (unlikely(!__pyx_tuple__75)) __PYX_ERR(0, 1345, __pyx_L1_error) + __pyx_tuple__75 = PyTuple_Pack(1, __pyx_kp_s__74); if (unlikely(!__pyx_tuple__75)) __PYX_ERR(0, 1502, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__75); __Pyx_GIVEREF(__pyx_tuple__75); - /* "pysam/libcbcf.pyx":1353 + /* "pysam/libcbcf.pyx":1510 * cdef bcf_hdr_t *hdr = self.header.ptr * if not check_header_id(hdr, self.type, self.id): * raise ValueError('Invalid header id') # <<<<<<<<<<<<<< * cdef bcf_hrec_t *hrec = hdr.id[BCF_DT_ID][self.id].val.hrec[self.type] * if not hrec: */ - __pyx_tuple__76 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header_id); if (unlikely(!__pyx_tuple__76)) __PYX_ERR(0, 1353, __pyx_L1_error) + __pyx_tuple__76 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header_id); if (unlikely(!__pyx_tuple__76)) __PYX_ERR(0, 1510, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__76); __Pyx_GIVEREF(__pyx_tuple__76); - /* "pysam/libcbcf.pyx":1367 + /* "pysam/libcbcf.pyx":1524 * cdef VariantMetadata makeVariantMetadata(VariantHeader header, int type, int id): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * if type != BCF_HL_FLT and type != BCF_HL_INFO and type != BCF_HL_FMT: */ - __pyx_tuple__77 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__77)) __PYX_ERR(0, 1367, __pyx_L1_error) + __pyx_tuple__77 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__77)) __PYX_ERR(0, 1524, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__77); __Pyx_GIVEREF(__pyx_tuple__77); - /* "pysam/libcbcf.pyx":1370 + /* "pysam/libcbcf.pyx":1527 * * if type != BCF_HL_FLT and type != BCF_HL_INFO and type != BCF_HL_FMT: * raise ValueError('invalid metadata type') # <<<<<<<<<<<<<< * * if id < 0 or id >= header.ptr.n[BCF_DT_ID]: */ - __pyx_tuple__78 = PyTuple_Pack(1, __pyx_kp_s_invalid_metadata_type); if (unlikely(!__pyx_tuple__78)) __PYX_ERR(0, 1370, __pyx_L1_error) + __pyx_tuple__78 = PyTuple_Pack(1, __pyx_kp_s_invalid_metadata_type); if (unlikely(!__pyx_tuple__78)) __PYX_ERR(0, 1527, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__78); __Pyx_GIVEREF(__pyx_tuple__78); - /* "pysam/libcbcf.pyx":1373 + /* "pysam/libcbcf.pyx":1530 * * if id < 0 or id >= header.ptr.n[BCF_DT_ID]: * raise ValueError('invalid metadata id') # <<<<<<<<<<<<<< * * cdef VariantMetadata meta = VariantMetadata.__new__(VariantMetadata) */ - __pyx_tuple__79 = PyTuple_Pack(1, __pyx_kp_s_invalid_metadata_id); if (unlikely(!__pyx_tuple__79)) __PYX_ERR(0, 1373, __pyx_L1_error) + __pyx_tuple__79 = PyTuple_Pack(1, __pyx_kp_s_invalid_metadata_id); if (unlikely(!__pyx_tuple__79)) __PYX_ERR(0, 1530, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__79); __Pyx_GIVEREF(__pyx_tuple__79); - /* "pysam/libcbcf.pyx":1386 + /* "pysam/libcbcf.pyx":1543 * """mapping from filter, info or format name to :class:`VariantMetadata` object""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def add(self, id, number, type, description, **kwargs): */ - __pyx_tuple__80 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__80)) __PYX_ERR(0, 1386, __pyx_L1_error) + __pyx_tuple__80 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__80)) __PYX_ERR(0, 1543, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__80); __Pyx_GIVEREF(__pyx_tuple__80); - /* "pysam/libcbcf.pyx":1395 + /* "pysam/libcbcf.pyx":1552 * if self.type == BCF_HL_FLT: * if number is not None: * raise ValueError('Number must be None when adding a filter') # <<<<<<<<<<<<<< * if type is not None: * raise ValueError('Type must be None when adding a filter') */ - __pyx_tuple__81 = PyTuple_Pack(1, __pyx_kp_s_Number_must_be_None_when_adding); if (unlikely(!__pyx_tuple__81)) __PYX_ERR(0, 1395, __pyx_L1_error) + __pyx_tuple__81 = PyTuple_Pack(1, __pyx_kp_s_Number_must_be_None_when_adding); if (unlikely(!__pyx_tuple__81)) __PYX_ERR(0, 1552, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__81); __Pyx_GIVEREF(__pyx_tuple__81); - /* "pysam/libcbcf.pyx":1397 + /* "pysam/libcbcf.pyx":1554 * raise ValueError('Number must be None when adding a filter') * if type is not None: * raise ValueError('Type must be None when adding a filter') # <<<<<<<<<<<<<< * * items = [('ID', id), ('Description', description)] */ - __pyx_tuple__82 = PyTuple_Pack(1, __pyx_kp_s_Type_must_be_None_when_adding_a); if (unlikely(!__pyx_tuple__82)) __PYX_ERR(0, 1397, __pyx_L1_error) + __pyx_tuple__82 = PyTuple_Pack(1, __pyx_kp_s_Type_must_be_None_when_adding_a); if (unlikely(!__pyx_tuple__82)) __PYX_ERR(0, 1554, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__82); __Pyx_GIVEREF(__pyx_tuple__82); - /* "pysam/libcbcf.pyx":1444 - * - * if k == kh_end(d) or kh_val_vdict(d, k).info[self.type] & 0xF == 0xF: - * raise KeyError('invalid key') # <<<<<<<<<<<<<< - * - * return makeVariantMetadata(self.header, self.type, kh_val_vdict(d, k).id) - */ - __pyx_tuple__83 = PyTuple_Pack(1, __pyx_kp_s_invalid_key); if (unlikely(!__pyx_tuple__83)) __PYX_ERR(0, 1444, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__83); - __Pyx_GIVEREF(__pyx_tuple__83); - - /* "pysam/libcbcf.pyx":1456 - * - * if k == kh_end(d) or kh_val_vdict(d, k).info[self.type] & 0xF == 0xF: - * raise KeyError('invalid key') # <<<<<<<<<<<<<< - * - * bcf_hdr_remove(hdr, self.type, bkey) - */ - __pyx_tuple__84 = PyTuple_Pack(1, __pyx_kp_s_invalid_key); if (unlikely(!__pyx_tuple__84)) __PYX_ERR(0, 1456, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__84); - __Pyx_GIVEREF(__pyx_tuple__84); - - /* "pysam/libcbcf.pyx":1525 + /* "pysam/libcbcf.pyx":1682 * cdef VariantHeaderMetadata makeVariantHeaderMetadata(VariantHeader header, int32_t type): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * cdef VariantHeaderMetadata meta = VariantHeaderMetadata.__new__(VariantHeaderMetadata) */ - __pyx_tuple__85 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__85)) __PYX_ERR(0, 1525, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__85); - __Pyx_GIVEREF(__pyx_tuple__85); + __pyx_tuple__83 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__83)) __PYX_ERR(0, 1682, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__83); + __Pyx_GIVEREF(__pyx_tuple__83); - /* "pysam/libcbcf.pyx":1537 + /* "pysam/libcbcf.pyx":1694 * """contig metadata from a :class:`VariantHeader`""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * @property */ - __pyx_tuple__86 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__86)) __PYX_ERR(0, 1537, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__86); - __Pyx_GIVEREF(__pyx_tuple__86); + __pyx_tuple__84 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__84)) __PYX_ERR(0, 1694, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__84); + __Pyx_GIVEREF(__pyx_tuple__84); - /* "pysam/libcbcf.pyx":1572 + /* "pysam/libcbcf.pyx":1729 * cdef VariantContig makeVariantContig(VariantHeader header, int id): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * if id < 0 or id >= header.ptr.n[BCF_DT_CTG]: */ - __pyx_tuple__87 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__87)) __PYX_ERR(0, 1572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__87); - __Pyx_GIVEREF(__pyx_tuple__87); + __pyx_tuple__85 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__85)) __PYX_ERR(0, 1729, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__85); + __Pyx_GIVEREF(__pyx_tuple__85); - /* "pysam/libcbcf.pyx":1575 + /* "pysam/libcbcf.pyx":1732 * * if id < 0 or id >= header.ptr.n[BCF_DT_CTG]: * raise ValueError('invalid contig id') # <<<<<<<<<<<<<< * * cdef VariantContig contig = VariantContig.__new__(VariantContig) */ - __pyx_tuple__88 = PyTuple_Pack(1, __pyx_kp_s_invalid_contig_id); if (unlikely(!__pyx_tuple__88)) __PYX_ERR(0, 1575, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__88); - __Pyx_GIVEREF(__pyx_tuple__88); + __pyx_tuple__86 = PyTuple_Pack(1, __pyx_kp_s_invalid_contig_id); if (unlikely(!__pyx_tuple__86)) __PYX_ERR(0, 1732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__86); + __Pyx_GIVEREF(__pyx_tuple__86); - /* "pysam/libcbcf.pyx":1587 + /* "pysam/libcbcf.pyx":1744 * """mapping from contig name or index to :class:`VariantContig` object.""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_tuple__89 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__89)) __PYX_ERR(0, 1587, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__89); - __Pyx_GIVEREF(__pyx_tuple__89); + __pyx_tuple__87 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__87)) __PYX_ERR(0, 1744, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__87); + __Pyx_GIVEREF(__pyx_tuple__87); - /* "pysam/libcbcf.pyx":1606 + /* "pysam/libcbcf.pyx":1763 * index = key * if index < 0 or index >= hdr.n[BCF_DT_CTG]: * raise IndexError('invalid contig index') # <<<<<<<<<<<<<< * return makeVariantContig(self.header, index) * */ - __pyx_tuple__90 = PyTuple_Pack(1, __pyx_kp_s_invalid_contig_index); if (unlikely(!__pyx_tuple__90)) __PYX_ERR(0, 1606, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__90); - __Pyx_GIVEREF(__pyx_tuple__90); - - /* "pysam/libcbcf.pyx":1614 - * - * if k == kh_end(d): - * raise KeyError('invalid contig') # <<<<<<<<<<<<<< - * - * cdef int id = kh_val_vdict(d, k).id - */ - __pyx_tuple__91 = PyTuple_Pack(1, __pyx_kp_s_invalid_contig); if (unlikely(!__pyx_tuple__91)) __PYX_ERR(0, 1614, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__91); - __Pyx_GIVEREF(__pyx_tuple__91); + __pyx_tuple__88 = PyTuple_Pack(1, __pyx_kp_s_invalid_contig_index); if (unlikely(!__pyx_tuple__88)) __PYX_ERR(0, 1763, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__88); + __Pyx_GIVEREF(__pyx_tuple__88); - /* "pysam/libcbcf.pyx":1630 + /* "pysam/libcbcf.pyx":1787 * index = key * if index < 0 or index >= hdr.n[BCF_DT_CTG]: * raise IndexError('invalid contig index') # <<<<<<<<<<<<<< - * bkey = hdr.id[BCF_DT_CTG][self.id].key + * ckey = hdr.id[BCF_DT_CTG][self.id].key * else: */ - __pyx_tuple__92 = PyTuple_Pack(1, __pyx_kp_s_invalid_contig_index); if (unlikely(!__pyx_tuple__92)) __PYX_ERR(0, 1630, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__92); - __Pyx_GIVEREF(__pyx_tuple__92); - - /* "pysam/libcbcf.pyx":1636 - * key = force_bytes(key) - * if kh_get_vdict(d, key) == kh_end(d): - * raise KeyError('invalid contig') # <<<<<<<<<<<<<< - * bkey = key - * - */ - __pyx_tuple__93 = PyTuple_Pack(1, __pyx_kp_s_invalid_contig); if (unlikely(!__pyx_tuple__93)) __PYX_ERR(0, 1636, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__93); - __Pyx_GIVEREF(__pyx_tuple__93); + __pyx_tuple__89 = PyTuple_Pack(1, __pyx_kp_s_invalid_contig_index); if (unlikely(!__pyx_tuple__89)) __PYX_ERR(0, 1787, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__89); + __Pyx_GIVEREF(__pyx_tuple__89); - /* "pysam/libcbcf.pyx":1708 - * - * items = [('ID', id)] + kwargs.items() + /* "pysam/libcbcf.pyx":1866 + * items = [('ID', id)] + * items += kwargs.items() * self.header.add_meta('contig', items=items) # <<<<<<<<<<<<<< * * */ - __pyx_tuple__94 = PyTuple_Pack(1, __pyx_n_s_contig); if (unlikely(!__pyx_tuple__94)) __PYX_ERR(0, 1708, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__94); - __Pyx_GIVEREF(__pyx_tuple__94); + __pyx_tuple__90 = PyTuple_Pack(1, __pyx_n_s_contig); if (unlikely(!__pyx_tuple__90)) __PYX_ERR(0, 1866, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__90); + __Pyx_GIVEREF(__pyx_tuple__90); - /* "pysam/libcbcf.pyx":1713 + /* "pysam/libcbcf.pyx":1871 * cdef VariantHeaderContigs makeVariantHeaderContigs(VariantHeader header): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * cdef VariantHeaderContigs contigs = VariantHeaderContigs.__new__(VariantHeaderContigs) */ - __pyx_tuple__95 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__95)) __PYX_ERR(0, 1713, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__95); - __Pyx_GIVEREF(__pyx_tuple__95); + __pyx_tuple__91 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__91)) __PYX_ERR(0, 1871, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__91); + __Pyx_GIVEREF(__pyx_tuple__91); - /* "pysam/libcbcf.pyx":1724 + /* "pysam/libcbcf.pyx":1882 * """sequence of sample names from a :class:`VariantHeader` object""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_tuple__96 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__96)) __PYX_ERR(0, 1724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__96); - __Pyx_GIVEREF(__pyx_tuple__96); + __pyx_tuple__92 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__92)) __PYX_ERR(0, 1882, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__92); + __Pyx_GIVEREF(__pyx_tuple__92); - /* "pysam/libcbcf.pyx":1738 + /* "pysam/libcbcf.pyx":1896 * * if i < 0 or i >= n: * raise IndexError('invalid sample index') # <<<<<<<<<<<<<< * * return charptr_to_str(hdr.samples[i]) */ - __pyx_tuple__97 = PyTuple_Pack(1, __pyx_kp_s_invalid_sample_index); if (unlikely(!__pyx_tuple__97)) __PYX_ERR(0, 1738, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__97); - __Pyx_GIVEREF(__pyx_tuple__97); + __pyx_tuple__93 = PyTuple_Pack(1, __pyx_kp_s_invalid_sample_index); if (unlikely(!__pyx_tuple__93)) __PYX_ERR(0, 1896, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__93); + __Pyx_GIVEREF(__pyx_tuple__93); - /* "pysam/libcbcf.pyx":1769 + /* "pysam/libcbcf.pyx":1927 * cdef VariantHeaderSamples makeVariantHeaderSamples(VariantHeader header): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * cdef VariantHeaderSamples samples = VariantHeaderSamples.__new__(VariantHeaderSamples) */ - __pyx_tuple__98 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__98)) __PYX_ERR(0, 1769, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__98); - __Pyx_GIVEREF(__pyx_tuple__98); + __pyx_tuple__94 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__94)) __PYX_ERR(0, 1927, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__94); + __Pyx_GIVEREF(__pyx_tuple__94); - /* "pysam/libcbcf.pyx":1791 + /* "pysam/libcbcf.pyx":1949 * self.ptr = bcf_hdr_init(b'w') * if not self.ptr: * raise ValueError('cannot create VariantHeader') # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __pyx_tuple__99 = PyTuple_Pack(1, __pyx_kp_s_cannot_create_VariantHeader); if (unlikely(!__pyx_tuple__99)) __PYX_ERR(0, 1791, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__99); - __Pyx_GIVEREF(__pyx_tuple__99); + __pyx_tuple__95 = PyTuple_Pack(1, __pyx_kp_s_cannot_create_VariantHeader); if (unlikely(!__pyx_tuple__95)) __PYX_ERR(0, 1949, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__95); + __Pyx_GIVEREF(__pyx_tuple__95); - /* "pysam/libcbcf.pyx":1807 + /* "pysam/libcbcf.pyx":1964 * def merge(self, VariantHeader header): * if header is None: * raise ValueError('header must not be None') # <<<<<<<<<<<<<< * bcf_hdr_merge(self.ptr, header.ptr) * */ - __pyx_tuple__100 = PyTuple_Pack(1, __pyx_kp_s_header_must_not_be_None); if (unlikely(!__pyx_tuple__100)) __PYX_ERR(0, 1807, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__100); - __Pyx_GIVEREF(__pyx_tuple__100); + __pyx_tuple__96 = PyTuple_Pack(1, __pyx_kp_s_header_must_not_be_None); if (unlikely(!__pyx_tuple__96)) __PYX_ERR(0, 1964, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__96); + __Pyx_GIVEREF(__pyx_tuple__96); - /* "pysam/libcbcf.pyx":1898 + /* "pysam/libcbcf.pyx":2058 + * + * if not rec: + * raise MemoryError('unable to allocate BCF record') # <<<<<<<<<<<<<< + * + * rec.ptr.n_sample = bcf_hdr_nsamples(self.ptr) + */ + __pyx_tuple__97 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_BCF_record); if (unlikely(!__pyx_tuple__97)) __PYX_ERR(0, 2058, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__97); + __Pyx_GIVEREF(__pyx_tuple__97); + + /* "pysam/libcbcf.pyx":2090 + * for i, sample in enumerate(samples): + * if 'GT' in sample: + * rec.samples[i]['GT'] = sample.pop('GT') # <<<<<<<<<<<<<< + * rec.samples[i].update(sample) + * + */ + __pyx_tuple__98 = PyTuple_Pack(1, __pyx_n_s_GT); if (unlikely(!__pyx_tuple__98)) __PYX_ERR(0, 2090, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__98); + __Pyx_GIVEREF(__pyx_tuple__98); + + /* "pysam/libcbcf.pyx":2098 * """Add an existing :class:`VariantHeaderRecord` to this header""" * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hrec_t *hrec = bcf_hrec_dup(record.ptr) */ - __pyx_tuple__101 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__101)) __PYX_ERR(0, 1898, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__101); - __Pyx_GIVEREF(__pyx_tuple__101); + __pyx_tuple__99 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__99)) __PYX_ERR(0, 2098, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__99); + __Pyx_GIVEREF(__pyx_tuple__99); - /* "pysam/libcbcf.pyx":1911 + /* "pysam/libcbcf.pyx":2111 * bline = force_bytes(line) * if bcf_hdr_append(self.ptr, bline) < 0: * raise ValueError('invalid header line') # <<<<<<<<<<<<<< * * if self.ptr.dirty: */ - __pyx_tuple__102 = PyTuple_Pack(1, __pyx_kp_s_invalid_header_line); if (unlikely(!__pyx_tuple__102)) __PYX_ERR(0, 1911, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__102); - __Pyx_GIVEREF(__pyx_tuple__102); + __pyx_tuple__100 = PyTuple_Pack(1, __pyx_kp_s_invalid_header_line); if (unlikely(!__pyx_tuple__100)) __PYX_ERR(0, 2111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__100); + __Pyx_GIVEREF(__pyx_tuple__100); - /* "pysam/libcbcf.pyx":1919 + /* "pysam/libcbcf.pyx":2119 * """Add metadata to this header""" * if not ((value is not None) ^ (items is not None)): * raise ValueError('either value or items must be specified') # <<<<<<<<<<<<<< * * cdef bcf_hrec_t *hrec = calloc(1, sizeof(bcf_hrec_t)) */ - __pyx_tuple__103 = PyTuple_Pack(1, __pyx_kp_s_either_value_or_items_must_be_sp); if (unlikely(!__pyx_tuple__103)) __PYX_ERR(0, 1919, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__103); - __Pyx_GIVEREF(__pyx_tuple__103); + __pyx_tuple__101 = PyTuple_Pack(1, __pyx_kp_s_either_value_or_items_must_be_sp); if (unlikely(!__pyx_tuple__101)) __PYX_ERR(0, 2119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__101); + __Pyx_GIVEREF(__pyx_tuple__101); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -77679,645 +87659,733 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__104 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__104)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__104); - __Pyx_GIVEREF(__pyx_tuple__104); + __pyx_tuple__102 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__102)) __PYX_ERR(2, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__102); + __Pyx_GIVEREF(__pyx_tuple__102); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__105 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__105)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__105); - __Pyx_GIVEREF(__pyx_tuple__105); + __pyx_tuple__103 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__103)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__103); + __Pyx_GIVEREF(__pyx_tuple__103); - /* "pysam/libcbcf.pyx":1958 + /* "pysam/libcbcf.pyx":2158 * cdef VariantHeader makeVariantHeader(bcf_hdr_t *hdr): * if not hdr: * raise ValueError('cannot create VariantHeader') # <<<<<<<<<<<<<< * * cdef VariantHeader header = VariantHeader.__new__(VariantHeader) */ - __pyx_tuple__106 = PyTuple_Pack(1, __pyx_kp_s_cannot_create_VariantHeader); if (unlikely(!__pyx_tuple__106)) __PYX_ERR(0, 1958, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__106); - __Pyx_GIVEREF(__pyx_tuple__106); + __pyx_tuple__104 = PyTuple_Pack(1, __pyx_kp_s_cannot_create_VariantHeader); if (unlikely(!__pyx_tuple__104)) __PYX_ERR(0, 2158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__104); + __Pyx_GIVEREF(__pyx_tuple__104); - /* "pysam/libcbcf.pyx":1975 + /* "pysam/libcbcf.pyx":2192 * filter index or name to :class:`VariantMetadata` object""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_tuple__107 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__107)) __PYX_ERR(0, 1975, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__107); - __Pyx_GIVEREF(__pyx_tuple__107); + __pyx_tuple__105 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__105)) __PYX_ERR(0, 2192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__105); + __Pyx_GIVEREF(__pyx_tuple__105); - /* "pysam/libcbcf.pyx":1993 + /* "pysam/libcbcf.pyx":2210 + * + * if index < 0 or index >= n: + * raise IndexError('invalid filter index') # <<<<<<<<<<<<<< + * + * id = r.d.flt[index] + */ + __pyx_tuple__106 = PyTuple_Pack(1, __pyx_kp_s_invalid_filter_index); if (unlikely(!__pyx_tuple__106)) __PYX_ERR(0, 2210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__106); + __Pyx_GIVEREF(__pyx_tuple__106); + + /* "pysam/libcbcf.pyx":2252 * * if index < 0 or index >= n: * raise IndexError('invalid filter index') # <<<<<<<<<<<<<< * * id = r.d.flt[index] */ - __pyx_tuple__108 = PyTuple_Pack(1, __pyx_kp_s_invalid_filter_index); if (unlikely(!__pyx_tuple__108)) __PYX_ERR(0, 1993, __pyx_L1_error) + __pyx_tuple__107 = PyTuple_Pack(1, __pyx_kp_s_invalid_filter_index); if (unlikely(!__pyx_tuple__107)) __PYX_ERR(0, 2252, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__107); + __Pyx_GIVEREF(__pyx_tuple__107); + + /* "pysam/libcbcf.pyx":2342 + * cdef VariantRecordFilter makeVariantRecordFilter(VariantRecord record): + * if not record: + * raise ValueError('invalid VariantRecord') # <<<<<<<<<<<<<< + * + * cdef VariantRecordFilter filter = VariantRecordFilter.__new__(VariantRecordFilter) + */ + __pyx_tuple__108 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantRecord); if (unlikely(!__pyx_tuple__108)) __PYX_ERR(0, 2342, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__108); __Pyx_GIVEREF(__pyx_tuple__108); - /* "pysam/libcbcf.pyx":2004 - * - * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): - * raise KeyError('Invalid filter') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2354 + * presented as mapping from format name to :class:`VariantMetadata` object.""" + * def __init__(self, *args, **kwargs): + * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * - * return makeVariantMetadata(self.record.header, BCF_HL_FLT, id) + * def __len__(self): */ - __pyx_tuple__109 = PyTuple_Pack(1, __pyx_kp_s_Invalid_filter); if (unlikely(!__pyx_tuple__109)) __PYX_ERR(0, 2004, __pyx_L1_error) + __pyx_tuple__109 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__109)) __PYX_ERR(0, 2354, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__109); __Pyx_GIVEREF(__pyx_tuple__109); - /* "pysam/libcbcf.pyx":2021 + /* "pysam/libcbcf.pyx":2399 * - * if not check_header_id(hdr, BCF_HL_FLT, id): - * raise KeyError('Invalid filter') # <<<<<<<<<<<<<< + * if bcf_update_format(hdr, r, bkey, fmt.p, 0, fmt.type) < 0: + * raise ValueError('Unable to delete FORMAT') # <<<<<<<<<<<<<< * - * bcf_add_filter(hdr, r, id) + * def clear(self): */ - __pyx_tuple__110 = PyTuple_Pack(1, __pyx_kp_s_Invalid_filter); if (unlikely(!__pyx_tuple__110)) __PYX_ERR(0, 2021, __pyx_L1_error) + __pyx_tuple__110 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_delete_FORMAT); if (unlikely(!__pyx_tuple__110)) __PYX_ERR(0, 2399, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__110); __Pyx_GIVEREF(__pyx_tuple__110); - /* "pysam/libcbcf.pyx":2035 - * - * if index < 0 or index >= n: - * raise IndexError('invalid filter index') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2415 + * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) + * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: + * raise ValueError('Unable to delete FORMAT') # <<<<<<<<<<<<<< * - * id = r.d.flt[index] + * def __iter__(self): */ - __pyx_tuple__111 = PyTuple_Pack(1, __pyx_kp_s_invalid_filter_index); if (unlikely(!__pyx_tuple__111)) __PYX_ERR(0, 2035, __pyx_L1_error) + __pyx_tuple__111 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_delete_FORMAT); if (unlikely(!__pyx_tuple__111)) __PYX_ERR(0, 2415, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__111); __Pyx_GIVEREF(__pyx_tuple__111); - /* "pysam/libcbcf.pyx":2046 - * - * if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): - * raise KeyError('Invalid filter') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2476 + * cdef VariantRecordFormat makeVariantRecordFormat(VariantRecord record): + * if not record: + * raise ValueError('invalid VariantRecord') # <<<<<<<<<<<<<< * - * bcf_remove_filter(hdr, r, id, 0) + * cdef VariantRecordFormat format = VariantRecordFormat.__new__(VariantRecordFormat) */ - __pyx_tuple__112 = PyTuple_Pack(1, __pyx_kp_s_Invalid_filter); if (unlikely(!__pyx_tuple__112)) __PYX_ERR(0, 2046, __pyx_L1_error) + __pyx_tuple__112 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantRecord); if (unlikely(!__pyx_tuple__112)) __PYX_ERR(0, 2476, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__112); __Pyx_GIVEREF(__pyx_tuple__112); - /* "pysam/libcbcf.pyx":2111 - * cdef VariantRecordFilter makeVariantRecordFilter(VariantRecord record): - * if not record: - * raise ValueError('invalid VariantRecord') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2490 * - * cdef VariantRecordFilter filter = VariantRecordFilter.__new__(VariantRecordFilter) + * def __init__(self, *args, **kwargs): + * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< + * + * def __len__(self): */ - __pyx_tuple__113 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantRecord); if (unlikely(!__pyx_tuple__113)) __PYX_ERR(0, 2111, __pyx_L1_error) + __pyx_tuple__113 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__113)) __PYX_ERR(0, 2490, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__113); __Pyx_GIVEREF(__pyx_tuple__113); - /* "pysam/libcbcf.pyx":2123 - * presented as mapping from format name to :class:`VariantMetadata` object.""" - * def __init__(self, *args, **kwargs): - * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2500 * - * def __len__(self): + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * + * for i in range(r.n_info): */ - __pyx_tuple__114 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__114)) __PYX_ERR(0, 2123, __pyx_L1_error) + __pyx_tuple__114 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__114)) __PYX_ERR(0, 2500, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__114); __Pyx_GIVEREF(__pyx_tuple__114); - /* "pysam/libcbcf.pyx":2153 + /* "pysam/libcbcf.pyx":2518 * - * if not fmt or not fmt.p: - * raise KeyError('unknown format') # <<<<<<<<<<<<<< + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * return makeVariantMetadata(self.record.header, BCF_HL_FMT, fmt.id) + * for i in range(r.n_info): */ - __pyx_tuple__115 = PyTuple_Pack(1, __pyx_kp_s_unknown_format); if (unlikely(!__pyx_tuple__115)) __PYX_ERR(0, 2153, __pyx_L1_error) + __pyx_tuple__115 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__115)) __PYX_ERR(0, 2518, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__115); __Pyx_GIVEREF(__pyx_tuple__115); - /* "pysam/libcbcf.pyx":2165 + /* "pysam/libcbcf.pyx":2533 * - * if not fmt or not fmt.p: - * raise KeyError('unknown format') # <<<<<<<<<<<<<< + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * if bcf_update_format(hdr, r, bkey, fmt.p, 0, fmt.type) < 0: + * cdef bytes bkey = force_bytes(key) */ - __pyx_tuple__116 = PyTuple_Pack(1, __pyx_kp_s_unknown_format); if (unlikely(!__pyx_tuple__116)) __PYX_ERR(0, 2165, __pyx_L1_error) + __pyx_tuple__116 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__116)) __PYX_ERR(0, 2533, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__116); __Pyx_GIVEREF(__pyx_tuple__116); - /* "pysam/libcbcf.pyx":2168 + /* "pysam/libcbcf.pyx":2538 * - * if bcf_update_format(hdr, r, bkey, fmt.p, 0, fmt.type) < 0: - * raise ValueError('Unable to delete FORMAT') # <<<<<<<<<<<<<< + * if strcmp(bkey, b'END') == 0: + * raise KeyError('END is a reserved attribute; access is via record.stop') # <<<<<<<<<<<<<< * - * def clear(self): + * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) */ - __pyx_tuple__117 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_delete_FORMAT); if (unlikely(!__pyx_tuple__117)) __PYX_ERR(0, 2168, __pyx_L1_error) + __pyx_tuple__117 = PyTuple_Pack(1, __pyx_kp_s_END_is_a_reserved_attribute_acce); if (unlikely(!__pyx_tuple__117)) __PYX_ERR(0, 2538, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__117); __Pyx_GIVEREF(__pyx_tuple__117); - /* "pysam/libcbcf.pyx":2184 - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, fmt.id) - * if bcf_update_format(hdr, r, key, fmt.p, 0, fmt.type) < 0: - * raise ValueError('Unable to delete FORMAT') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2549 * - * def __iter__(self): + * if not check_header_id(hdr, BCF_HL_INFO, info_id): + * raise ValueError('Invalid header') # <<<<<<<<<<<<<< + * + * # Handle type=Flag values */ - __pyx_tuple__118 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_delete_FORMAT); if (unlikely(!__pyx_tuple__118)) __PYX_ERR(0, 2184, __pyx_L1_error) + __pyx_tuple__118 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__118)) __PYX_ERR(0, 2549, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__118); __Pyx_GIVEREF(__pyx_tuple__118); - /* "pysam/libcbcf.pyx":2245 - * cdef VariantRecordFormat makeVariantRecordFormat(VariantRecord record): - * if not record: - * raise ValueError('invalid VariantRecord') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2564 * - * cdef VariantRecordFormat format = VariantRecordFormat.__new__(VariantRecordFormat) + * if strcmp(bkey, b'END') == 0: + * raise KeyError('END is a reserved attribute; access is via record.stop') # <<<<<<<<<<<<<< + * + * if bcf_unpack(self.record.ptr, BCF_UN_INFO) < 0: */ - __pyx_tuple__119 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantRecord); if (unlikely(!__pyx_tuple__119)) __PYX_ERR(0, 2245, __pyx_L1_error) + __pyx_tuple__119 = PyTuple_Pack(1, __pyx_kp_s_END_is_a_reserved_attribute_acce); if (unlikely(!__pyx_tuple__119)) __PYX_ERR(0, 2564, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__119); __Pyx_GIVEREF(__pyx_tuple__119); - /* "pysam/libcbcf.pyx":2259 + /* "pysam/libcbcf.pyx":2567 * - * def __init__(self, *args, **kwargs): - * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< + * if bcf_unpack(self.record.ptr, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * def __len__(self): + * bcf_info_set_value(self.record, key, value) */ - __pyx_tuple__120 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__120)) __PYX_ERR(0, 2259, __pyx_L1_error) + __pyx_tuple__120 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__120)) __PYX_ERR(0, 2567, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__120); __Pyx_GIVEREF(__pyx_tuple__120); - /* "pysam/libcbcf.pyx":2275 + /* "pysam/libcbcf.pyx":2577 + * cdef bytes bkey = force_bytes(key) + * if strcmp(bkey, b'END') == 0: + * raise KeyError('END is a reserved attribute; access is via record.stop') # <<<<<<<<<<<<<< * * if bcf_unpack(r, BCF_UN_INFO) < 0: - * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< - * - * bkey = force_bytes(key) */ - __pyx_tuple__121 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__121)) __PYX_ERR(0, 2275, __pyx_L1_error) + __pyx_tuple__121 = PyTuple_Pack(1, __pyx_kp_s_END_is_a_reserved_attribute_acce); if (unlikely(!__pyx_tuple__121)) __PYX_ERR(0, 2577, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__121); __Pyx_GIVEREF(__pyx_tuple__121); - /* "pysam/libcbcf.pyx":2292 + /* "pysam/libcbcf.pyx":2580 * - * if not check_header_id(hdr, BCF_HL_INFO, info_id): - * raise ValueError('Invalid header') # <<<<<<<<<<<<<< + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG: + * cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) */ - __pyx_tuple__122 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__122)) __PYX_ERR(0, 2292, __pyx_L1_error) + __pyx_tuple__122 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__122)) __PYX_ERR(0, 2580, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__122); __Pyx_GIVEREF(__pyx_tuple__122); - /* "pysam/libcbcf.pyx":2310 + /* "pysam/libcbcf.pyx":2591 * - * if bcf_unpack(r, BCF_UN_INFO) < 0: - * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * if not check_header_id(hdr, BCF_HL_INFO, info_id): + * raise ValueError('Invalid header') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * # Handle flags */ - __pyx_tuple__123 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__123)) __PYX_ERR(0, 2310, __pyx_L1_error) + __pyx_tuple__123 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__123)) __PYX_ERR(0, 2591, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__123); __Pyx_GIVEREF(__pyx_tuple__123); - /* "pysam/libcbcf.pyx":2319 + /* "pysam/libcbcf.pyx":2601 * * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: * raise ValueError('Unable to delete INFO') # <<<<<<<<<<<<<< * * def clear(self): */ - __pyx_tuple__124 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_delete_INFO); if (unlikely(!__pyx_tuple__124)) __PYX_ERR(0, 2319, __pyx_L1_error) + __pyx_tuple__124 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_delete_INFO); if (unlikely(!__pyx_tuple__124)) __PYX_ERR(0, 2601, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__124); __Pyx_GIVEREF(__pyx_tuple__124); - /* "pysam/libcbcf.pyx":2330 + /* "pysam/libcbcf.pyx":2612 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * + * for i in range(r.n_info): + */ + __pyx_tuple__125 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__125)) __PYX_ERR(0, 2612, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__125); + __Pyx_GIVEREF(__pyx_tuple__125); + + /* "pysam/libcbcf.pyx":2621 + * continue + * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: + * raise ValueError('Unable to delete INFO') # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __pyx_tuple__126 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_delete_INFO); if (unlikely(!__pyx_tuple__126)) __PYX_ERR(0, 2621, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__126); + __Pyx_GIVEREF(__pyx_tuple__126); + + /* "pysam/libcbcf.pyx":2631 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * + * for i in range(r.n_info): + */ + __pyx_tuple__127 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__127)) __PYX_ERR(0, 2631, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__127); + __Pyx_GIVEREF(__pyx_tuple__127); + + /* "pysam/libcbcf.pyx":2646 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * + * cdef bytes bkey = force_bytes(key) + */ + __pyx_tuple__128 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__128)) __PYX_ERR(0, 2646, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__128); + __Pyx_GIVEREF(__pyx_tuple__128); + + /* "pysam/libcbcf.pyx":2659 + * + * if not check_header_id(hdr, BCF_HL_INFO, info_id): + * raise ValueError('Invalid header') # <<<<<<<<<<<<<< + * + * # Handle flags + */ + __pyx_tuple__129 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__129)) __PYX_ERR(0, 2659, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__129); + __Pyx_GIVEREF(__pyx_tuple__129); + + /* "pysam/libcbcf.pyx":2675 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * + * cdef bytes bkey = force_bytes(key) + */ + __pyx_tuple__130 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__130)) __PYX_ERR(0, 2675, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__130); + __Pyx_GIVEREF(__pyx_tuple__130); + + /* "pysam/libcbcf.pyx":2699 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * + * for i in range(r.n_info): + */ + __pyx_tuple__131 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__131)) __PYX_ERR(0, 2699, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__131); + __Pyx_GIVEREF(__pyx_tuple__131); + + /* "pysam/libcbcf.pyx":2717 + * + * if bcf_unpack(r, BCF_UN_INFO) < 0: + * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * + * for i in range(r.n_info): + */ + __pyx_tuple__132 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__132)) __PYX_ERR(0, 2717, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__132); + __Pyx_GIVEREF(__pyx_tuple__132); + + /* "pysam/libcbcf.pyx":2758 * * if bcf_unpack(r, BCF_UN_INFO) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * - * for i in range(r.n_info): + * cdef bytes bkey = force_bytes(key) */ - __pyx_tuple__125 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__125)) __PYX_ERR(0, 2330, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__125); - __Pyx_GIVEREF(__pyx_tuple__125); + __pyx_tuple__134 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__134)) __PYX_ERR(0, 2758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__134); + __Pyx_GIVEREF(__pyx_tuple__134); - /* "pysam/libcbcf.pyx":2337 - * key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) - * if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: - * raise ValueError('Unable to delete INFO') # <<<<<<<<<<<<<< + /* "pysam/libcbcf.pyx":2772 * - * def __iter__(self): + * if not check_header_id(hdr, BCF_HL_INFO, info_id): + * raise ValueError('Invalid header') # <<<<<<<<<<<<<< + * + * # Handle flags */ - __pyx_tuple__126 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_delete_INFO); if (unlikely(!__pyx_tuple__126)) __PYX_ERR(0, 2337, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__126); - __Pyx_GIVEREF(__pyx_tuple__126); + __pyx_tuple__135 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__135)) __PYX_ERR(0, 2772, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__135); + __Pyx_GIVEREF(__pyx_tuple__135); - /* "pysam/libcbcf.pyx":2362 + /* "pysam/libcbcf.pyx":2786 * - * if bcf_unpack(r, BCF_UN_INFO) < 0: - * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< + * if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: + * raise ValueError('Unable to delete INFO') # <<<<<<<<<<<<<< * - * bkey = force_bytes(key) + * return value */ - __pyx_tuple__127 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__127)) __PYX_ERR(0, 2362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__127); - __Pyx_GIVEREF(__pyx_tuple__127); + __pyx_tuple__136 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_delete_INFO); if (unlikely(!__pyx_tuple__136)) __PYX_ERR(0, 2786, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__136); + __Pyx_GIVEREF(__pyx_tuple__136); - /* "pysam/libcbcf.pyx":2418 + /* "pysam/libcbcf.pyx":2811 * cdef VariantRecordInfo makeVariantRecordInfo(VariantRecord record): * if not record: * raise ValueError('invalid VariantRecord') # <<<<<<<<<<<<<< * * cdef VariantRecordInfo info = VariantRecordInfo.__new__(VariantRecordInfo) */ - __pyx_tuple__128 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantRecord); if (unlikely(!__pyx_tuple__128)) __PYX_ERR(0, 2418, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__128); - __Pyx_GIVEREF(__pyx_tuple__128); + __pyx_tuple__137 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantRecord); if (unlikely(!__pyx_tuple__137)) __PYX_ERR(0, 2811, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__137); + __Pyx_GIVEREF(__pyx_tuple__137); - /* "pysam/libcbcf.pyx":2429 + /* "pysam/libcbcf.pyx":2822 * """mapping from sample index or name to :class:`VariantRecordSample` object.""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_tuple__129 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__129)) __PYX_ERR(0, 2429, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__129); - __Pyx_GIVEREF(__pyx_tuple__129); - - /* "pysam/libcbcf.pyx":2451 - * sample_index = bcf_hdr_id2int(hdr, BCF_DT_SAMPLE, bkey) - * if sample_index < 0: - * raise KeyError('invalid sample name') # <<<<<<<<<<<<<< - * - * if sample_index < 0 or sample_index >= n: - */ - __pyx_tuple__130 = PyTuple_Pack(1, __pyx_kp_s_invalid_sample_name); if (unlikely(!__pyx_tuple__130)) __PYX_ERR(0, 2451, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__130); - __Pyx_GIVEREF(__pyx_tuple__130); + __pyx_tuple__138 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__138)) __PYX_ERR(0, 2822, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__138); + __Pyx_GIVEREF(__pyx_tuple__138); - /* "pysam/libcbcf.pyx":2454 + /* "pysam/libcbcf.pyx":2847 * * if sample_index < 0 or sample_index >= n: * raise IndexError('invalid sample index') # <<<<<<<<<<<<<< * * return makeVariantRecordSample(self.record, sample_index) */ - __pyx_tuple__131 = PyTuple_Pack(1, __pyx_kp_s_invalid_sample_index); if (unlikely(!__pyx_tuple__131)) __PYX_ERR(0, 2454, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__131); - __Pyx_GIVEREF(__pyx_tuple__131); - - /* "pysam/libcbcf.pyx":2487 - * sample_index = bcf_hdr_id2int(hdr, BCF_DT_SAMPLE, bkey) - * if sample_index < 0: - * raise KeyError('invalid sample name') # <<<<<<<<<<<<<< - * - * return 0 <= sample_index < n - */ - __pyx_tuple__132 = PyTuple_Pack(1, __pyx_kp_s_invalid_sample_name); if (unlikely(!__pyx_tuple__132)) __PYX_ERR(0, 2487, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__132); - __Pyx_GIVEREF(__pyx_tuple__132); + __pyx_tuple__139 = PyTuple_Pack(1, __pyx_kp_s_invalid_sample_index); if (unlikely(!__pyx_tuple__139)) __PYX_ERR(0, 2847, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__139); + __Pyx_GIVEREF(__pyx_tuple__139); - /* "pysam/libcbcf.pyx":2533 + /* "pysam/libcbcf.pyx":2960 * cdef VariantRecordSamples makeVariantRecordSamples(VariantRecord record): * if not record: * raise ValueError('invalid VariantRecord') # <<<<<<<<<<<<<< * * cdef VariantRecordSamples samples = VariantRecordSamples.__new__( */ - __pyx_tuple__133 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantRecord); if (unlikely(!__pyx_tuple__133)) __PYX_ERR(0, 2533, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__133); - __Pyx_GIVEREF(__pyx_tuple__133); + __pyx_tuple__141 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantRecord); if (unlikely(!__pyx_tuple__141)) __PYX_ERR(0, 2960, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__141); + __Pyx_GIVEREF(__pyx_tuple__141); - /* "pysam/libcbcf.pyx":2545 + /* "pysam/libcbcf.pyx":2972 * """Variant record""" * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __pyx_tuple__134 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__134)) __PYX_ERR(0, 2545, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__134); - __Pyx_GIVEREF(__pyx_tuple__134); + __pyx_tuple__142 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__142)) __PYX_ERR(0, 2972, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__142); + __Pyx_GIVEREF(__pyx_tuple__142); - /* "pysam/libcbcf.pyx":2558 + /* "pysam/libcbcf.pyx":2985 * def translate(self, VariantHeader dst_header): * if dst_header is None: * raise ValueError('dst_header must not be None') # <<<<<<<<<<<<<< * * cdef bcf_hdr_t *src_hdr = self.header.ptr */ - __pyx_tuple__135 = PyTuple_Pack(1, __pyx_kp_s_dst_header_must_not_be_None); if (unlikely(!__pyx_tuple__135)) __PYX_ERR(0, 2558, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__135); - __Pyx_GIVEREF(__pyx_tuple__135); + __pyx_tuple__143 = PyTuple_Pack(1, __pyx_kp_s_dst_header_must_not_be_None); if (unlikely(!__pyx_tuple__143)) __PYX_ERR(0, 2985, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__143); + __Pyx_GIVEREF(__pyx_tuple__143); - /* "pysam/libcbcf.pyx":2580 + /* "pysam/libcbcf.pyx":3008 * cdef int r = value * if r < 0 or r >= hdr.n[BCF_DT_CTG] or not hdr.id[BCF_DT_CTG][r].val: * raise ValueError('invalid reference id') # <<<<<<<<<<<<<< * self.ptr.rid = r * */ - __pyx_tuple__136 = PyTuple_Pack(1, __pyx_kp_s_invalid_reference_id); if (unlikely(!__pyx_tuple__136)) __PYX_ERR(0, 2580, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__136); - __Pyx_GIVEREF(__pyx_tuple__136); + __pyx_tuple__144 = PyTuple_Pack(1, __pyx_kp_s_invalid_reference_id); if (unlikely(!__pyx_tuple__144)) __PYX_ERR(0, 3008, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__144); + __Pyx_GIVEREF(__pyx_tuple__144); - /* "pysam/libcbcf.pyx":2589 + /* "pysam/libcbcf.pyx":3017 * cdef int rid = self.ptr.rid * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: * raise ValueError('Invalid header') # <<<<<<<<<<<<<< * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) * */ - __pyx_tuple__137 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__137)) __PYX_ERR(0, 2589, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__137); - __Pyx_GIVEREF(__pyx_tuple__137); + __pyx_tuple__145 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__145)) __PYX_ERR(0, 3017, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__145); + __Pyx_GIVEREF(__pyx_tuple__145); - /* "pysam/libcbcf.pyx":2598 + /* "pysam/libcbcf.pyx":3026 * cdef khint_t k = kh_get_vdict(d, bchrom) * if k == kh_end(d): * raise ValueError('Invalid chromosome/contig') # <<<<<<<<<<<<<< * self.ptr.rid = kh_val_vdict(d, k).id * */ - __pyx_tuple__138 = PyTuple_Pack(1, __pyx_kp_s_Invalid_chromosome_contig); if (unlikely(!__pyx_tuple__138)) __PYX_ERR(0, 2598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__138); - __Pyx_GIVEREF(__pyx_tuple__138); + __pyx_tuple__146 = PyTuple_Pack(1, __pyx_kp_s_Invalid_chromosome_contig); if (unlikely(!__pyx_tuple__146)) __PYX_ERR(0, 3026, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__146); + __Pyx_GIVEREF(__pyx_tuple__146); - /* "pysam/libcbcf.pyx":2607 + /* "pysam/libcbcf.pyx":3035 * cdef int rid = self.ptr.rid * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: * raise ValueError('Invalid header') # <<<<<<<<<<<<<< * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) * */ - __pyx_tuple__139 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__139)) __PYX_ERR(0, 2607, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__139); - __Pyx_GIVEREF(__pyx_tuple__139); + __pyx_tuple__147 = PyTuple_Pack(1, __pyx_kp_s_Invalid_header); if (unlikely(!__pyx_tuple__147)) __PYX_ERR(0, 3035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__147); + __Pyx_GIVEREF(__pyx_tuple__147); - /* "pysam/libcbcf.pyx":2616 + /* "pysam/libcbcf.pyx":3044 * cdef khint_t k = kh_get_vdict(d, bchrom) * if k == kh_end(d): * raise ValueError('Invalid chromosome/contig') # <<<<<<<<<<<<<< * self.ptr.rid = kh_val_vdict(d, k).id * */ - __pyx_tuple__140 = PyTuple_Pack(1, __pyx_kp_s_Invalid_chromosome_contig); if (unlikely(!__pyx_tuple__140)) __PYX_ERR(0, 2616, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__140); - __Pyx_GIVEREF(__pyx_tuple__140); + __pyx_tuple__148 = PyTuple_Pack(1, __pyx_kp_s_Invalid_chromosome_contig); if (unlikely(!__pyx_tuple__148)) __PYX_ERR(0, 3044, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__148); + __Pyx_GIVEREF(__pyx_tuple__148); - /* "pysam/libcbcf.pyx":2628 + /* "pysam/libcbcf.pyx":3056 * cdef int p = value * if p < 1: * raise ValueError('Position must be positive') # <<<<<<<<<<<<<< * self.ptr.pos = p - 1 - * + * bcf_sync_end(self) */ - __pyx_tuple__141 = PyTuple_Pack(1, __pyx_kp_s_Position_must_be_positive); if (unlikely(!__pyx_tuple__141)) __PYX_ERR(0, 2628, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__141); - __Pyx_GIVEREF(__pyx_tuple__141); + __pyx_tuple__149 = PyTuple_Pack(1, __pyx_kp_s_Position_must_be_positive); if (unlikely(!__pyx_tuple__149)) __PYX_ERR(0, 3056, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__149); + __Pyx_GIVEREF(__pyx_tuple__149); - /* "pysam/libcbcf.pyx":2640 + /* "pysam/libcbcf.pyx":3069 * cdef int s = value * if s < 0: * raise ValueError('Start coordinate must be non-negative') # <<<<<<<<<<<<<< * self.ptr.pos = s - * + * bcf_sync_end(self) */ - __pyx_tuple__142 = PyTuple_Pack(1, __pyx_kp_s_Start_coordinate_must_be_non_neg); if (unlikely(!__pyx_tuple__142)) __PYX_ERR(0, 2640, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__142); - __Pyx_GIVEREF(__pyx_tuple__142); + __pyx_tuple__150 = PyTuple_Pack(1, __pyx_kp_s_Start_coordinate_must_be_non_neg); if (unlikely(!__pyx_tuple__150)) __PYX_ERR(0, 3069, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__150); + __Pyx_GIVEREF(__pyx_tuple__150); - /* "pysam/libcbcf.pyx":2652 + /* "pysam/libcbcf.pyx":3082 * cdef int s = value - * if s < self.ptr.pos: - * raise ValueError('Stop coordinate must be greater than or equal to start') # <<<<<<<<<<<<<< + * if s < 0: + * raise ValueError('Stop coordinate must be non-negative') # <<<<<<<<<<<<<< * self.ptr.rlen = s - self.ptr.pos - * if self.ptr.rlen != len(self.ref) or 'END' in self.info: - */ - __pyx_tuple__143 = PyTuple_Pack(1, __pyx_kp_s_Stop_coordinate_must_be_greater); if (unlikely(!__pyx_tuple__143)) __PYX_ERR(0, 2652, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__143); - __Pyx_GIVEREF(__pyx_tuple__143); - - /* "pysam/libcbcf.pyx":2666 - * cdef int r = value - * if r < 0: - * raise ValueError('Reference length must be non-negative') # <<<<<<<<<<<<<< - * self.ptr.rlen = r - * if r != len(self.ref) or 'END' in self.info: + * bcf_sync_end(self) */ - __pyx_tuple__144 = PyTuple_Pack(1, __pyx_kp_s_Reference_length_must_be_non_neg); if (unlikely(!__pyx_tuple__144)) __PYX_ERR(0, 2666, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__144); - __Pyx_GIVEREF(__pyx_tuple__144); + __pyx_tuple__151 = PyTuple_Pack(1, __pyx_kp_s_Stop_coordinate_must_be_non_nega); if (unlikely(!__pyx_tuple__151)) __PYX_ERR(0, 3082, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__151); + __Pyx_GIVEREF(__pyx_tuple__151); - /* "pysam/libcbcf.pyx":2697 + /* "pysam/libcbcf.pyx":3123 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * return bcf_str_cache_get_charptr(r.d.id) if r.d.id != b'.' else None * */ - __pyx_tuple__145 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__145)) __PYX_ERR(0, 2697, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__145); - __Pyx_GIVEREF(__pyx_tuple__145); + __pyx_tuple__152 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__152)) __PYX_ERR(0, 3123, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__152); + __Pyx_GIVEREF(__pyx_tuple__152); - /* "pysam/libcbcf.pyx":2704 + /* "pysam/libcbcf.pyx":3130 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * cdef char *idstr = NULL * if value is not None: */ - __pyx_tuple__146 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__146)) __PYX_ERR(0, 2704, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__146); - __Pyx_GIVEREF(__pyx_tuple__146); + __pyx_tuple__153 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__153)) __PYX_ERR(0, 3130, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__153); + __Pyx_GIVEREF(__pyx_tuple__153); - /* "pysam/libcbcf.pyx":2710 + /* "pysam/libcbcf.pyx":3136 * idstr = bid * if bcf_update_id(self.header.ptr, self.ptr, idstr) < 0: * raise ValueError('Error updating id') # <<<<<<<<<<<<<< * * @property */ - __pyx_tuple__147 = PyTuple_Pack(1, __pyx_kp_s_Error_updating_id); if (unlikely(!__pyx_tuple__147)) __PYX_ERR(0, 2710, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__147); - __Pyx_GIVEREF(__pyx_tuple__147); + __pyx_tuple__154 = PyTuple_Pack(1, __pyx_kp_s_Error_updating_id); if (unlikely(!__pyx_tuple__154)) __PYX_ERR(0, 3136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__154); + __Pyx_GIVEREF(__pyx_tuple__154); - /* "pysam/libcbcf.pyx":2717 + /* "pysam/libcbcf.pyx":3143 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * return charptr_to_str(r.d.allele[0]) if r.d.allele else None * */ - __pyx_tuple__148 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__148)) __PYX_ERR(0, 2717, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__148); - __Pyx_GIVEREF(__pyx_tuple__148); + __pyx_tuple__155 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__155)) __PYX_ERR(0, 3143, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__155); + __Pyx_GIVEREF(__pyx_tuple__155); - /* "pysam/libcbcf.pyx":2724 + /* "pysam/libcbcf.pyx":3150 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * #FIXME: Set alleles directly -- this is stupid * if not value: */ - __pyx_tuple__149 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__149)) __PYX_ERR(0, 2724, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__149); - __Pyx_GIVEREF(__pyx_tuple__149); + __pyx_tuple__156 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__156)) __PYX_ERR(0, 3150, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__156); + __Pyx_GIVEREF(__pyx_tuple__156); - /* "pysam/libcbcf.pyx":2727 + /* "pysam/libcbcf.pyx":3153 * #FIXME: Set alleles directly -- this is stupid * if not value: * raise ValueError('ref allele must not be null') # <<<<<<<<<<<<<< * value = force_bytes(value) * if r.d.allele and r.n_allele: */ - __pyx_tuple__150 = PyTuple_Pack(1, __pyx_kp_s_ref_allele_must_not_be_null); if (unlikely(!__pyx_tuple__150)) __PYX_ERR(0, 2727, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__150); - __Pyx_GIVEREF(__pyx_tuple__150); + __pyx_tuple__157 = PyTuple_Pack(1, __pyx_kp_s_ref_allele_must_not_be_null); if (unlikely(!__pyx_tuple__157)) __PYX_ERR(0, 3153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__157); + __Pyx_GIVEREF(__pyx_tuple__157); - /* "pysam/libcbcf.pyx":2741 + /* "pysam/libcbcf.pyx":3168 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * if not r.d.allele: * return None */ - __pyx_tuple__151 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__151)) __PYX_ERR(0, 2741, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__151); - __Pyx_GIVEREF(__pyx_tuple__151); + __pyx_tuple__158 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__158)) __PYX_ERR(0, 3168, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__158); + __Pyx_GIVEREF(__pyx_tuple__158); - /* "pysam/libcbcf.pyx":2755 - * cdef bcf1_t *r = self.ptr + /* "pysam/libcbcf.pyx":3186 + * * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< - * value = [force_bytes(v) for v in value] - * if b'' in value: + * + * values = [force_bytes(v) for v in values] */ - __pyx_tuple__152 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__152)) __PYX_ERR(0, 2755, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__152); - __Pyx_GIVEREF(__pyx_tuple__152); + __pyx_tuple__159 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__159)) __PYX_ERR(0, 3186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__159); + __Pyx_GIVEREF(__pyx_tuple__159); - /* "pysam/libcbcf.pyx":2758 - * value = [force_bytes(v) for v in value] - * if b'' in value: + /* "pysam/libcbcf.pyx":3191 + * + * if len(values) < 2: + * raise ValueError('must set at least 2 alleles') # <<<<<<<<<<<<<< + * + * if b'' in values: + */ + __pyx_tuple__160 = PyTuple_Pack(1, __pyx_kp_s_must_set_at_least_2_alleles); if (unlikely(!__pyx_tuple__160)) __PYX_ERR(0, 3191, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__160); + __Pyx_GIVEREF(__pyx_tuple__160); + + /* "pysam/libcbcf.pyx":3194 + * + * if b'' in values: * raise ValueError('cannot set null allele') # <<<<<<<<<<<<<< - * value = b','.join(value) - * if bcf_update_alleles_str(self.header.ptr, r, value) < 0: + * + * value = b','.join(values) */ - __pyx_tuple__153 = PyTuple_Pack(1, __pyx_kp_s_cannot_set_null_allele); if (unlikely(!__pyx_tuple__153)) __PYX_ERR(0, 2758, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__153); - __Pyx_GIVEREF(__pyx_tuple__153); + __pyx_tuple__161 = PyTuple_Pack(1, __pyx_kp_s_cannot_set_null_allele); if (unlikely(!__pyx_tuple__161)) __PYX_ERR(0, 3194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__161); + __Pyx_GIVEREF(__pyx_tuple__161); - /* "pysam/libcbcf.pyx":2761 - * value = b','.join(value) + /* "pysam/libcbcf.pyx":3199 + * * if bcf_update_alleles_str(self.header.ptr, r, value) < 0: * raise ValueError('Error updating alleles') # <<<<<<<<<<<<<< * - * @property + * # Reset rlen if alternate allele isn't symbolic, otherwise used cached */ - __pyx_tuple__154 = PyTuple_Pack(1, __pyx_kp_s_Error_updating_alleles); if (unlikely(!__pyx_tuple__154)) __PYX_ERR(0, 2761, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__154); - __Pyx_GIVEREF(__pyx_tuple__154); + __pyx_tuple__162 = PyTuple_Pack(1, __pyx_kp_s_Error_updating_alleles); if (unlikely(!__pyx_tuple__162)) __PYX_ERR(0, 3199, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__162); + __Pyx_GIVEREF(__pyx_tuple__162); - /* "pysam/libcbcf.pyx":2768 + /* "pysam/libcbcf.pyx":3213 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * if r.n_allele < 2 or not r.d.allele: * return None */ - __pyx_tuple__155 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__155)) __PYX_ERR(0, 2768, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__155); - __Pyx_GIVEREF(__pyx_tuple__155); + __pyx_tuple__163 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__163)) __PYX_ERR(0, 3213, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__163); + __Pyx_GIVEREF(__pyx_tuple__163); - /* "pysam/libcbcf.pyx":2783 + /* "pysam/libcbcf.pyx":3228 * cdef bcf1_t *r = self.ptr * if bcf_unpack(r, BCF_UN_STR) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * value = [force_bytes(v) for v in value] * if b'' in value: */ - __pyx_tuple__156 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__156)) __PYX_ERR(0, 2783, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__156); - __Pyx_GIVEREF(__pyx_tuple__156); + __pyx_tuple__164 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__164)) __PYX_ERR(0, 3228, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__164); + __Pyx_GIVEREF(__pyx_tuple__164); - /* "pysam/libcbcf.pyx":2786 + /* "pysam/libcbcf.pyx":3231 * value = [force_bytes(v) for v in value] * if b'' in value: * raise ValueError('cannot set null alt allele') # <<<<<<<<<<<<<< * ref = [r.d.allele[0] if r.d.allele and r.n_allele else b'.'] * self.alleles = ref + value */ - __pyx_tuple__157 = PyTuple_Pack(1, __pyx_kp_s_cannot_set_null_alt_allele); if (unlikely(!__pyx_tuple__157)) __PYX_ERR(0, 2786, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__157); - __Pyx_GIVEREF(__pyx_tuple__157); + __pyx_tuple__165 = PyTuple_Pack(1, __pyx_kp_s_cannot_set_null_alt_allele); if (unlikely(!__pyx_tuple__165)) __PYX_ERR(0, 3231, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__165); + __Pyx_GIVEREF(__pyx_tuple__165); - /* "pysam/libcbcf.pyx":2794 + /* "pysam/libcbcf.pyx":3239 * """filter information (see :class:`VariantRecordFilter`)""" * if bcf_unpack(self.ptr, BCF_UN_FLT) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * return makeVariantRecordFilter(self) * */ - __pyx_tuple__158 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__158)) __PYX_ERR(0, 2794, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__158); - __Pyx_GIVEREF(__pyx_tuple__158); + __pyx_tuple__166 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__166)) __PYX_ERR(0, 3239, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__166); + __Pyx_GIVEREF(__pyx_tuple__166); - /* "pysam/libcbcf.pyx":2801 + /* "pysam/libcbcf.pyx":3246 * """info data (see :class:`VariantRecordInfo`)""" * if bcf_unpack(self.ptr, BCF_UN_INFO) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * return makeVariantRecordInfo(self) * */ - __pyx_tuple__159 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__159)) __PYX_ERR(0, 2801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__159); - __Pyx_GIVEREF(__pyx_tuple__159); + __pyx_tuple__167 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__167)) __PYX_ERR(0, 3246, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__167); + __Pyx_GIVEREF(__pyx_tuple__167); - /* "pysam/libcbcf.pyx":2808 + /* "pysam/libcbcf.pyx":3253 * """sample format metadata (see :class:`VariantRecordFormat`)""" * if bcf_unpack(self.ptr, BCF_UN_FMT) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * return makeVariantRecordFormat(self) * */ - __pyx_tuple__160 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__160)) __PYX_ERR(0, 2808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__160); - __Pyx_GIVEREF(__pyx_tuple__160); + __pyx_tuple__168 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__168)) __PYX_ERR(0, 3253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__168); + __Pyx_GIVEREF(__pyx_tuple__168); - /* "pysam/libcbcf.pyx":2815 + /* "pysam/libcbcf.pyx":3260 * """sample data (see :class:`VariantRecordSamples`)""" * if bcf_unpack(self.ptr, BCF_UN_ALL) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * return makeVariantRecordSamples(self) * */ - __pyx_tuple__161 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__161)) __PYX_ERR(0, 2815, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__161); - __Pyx_GIVEREF(__pyx_tuple__161); + __pyx_tuple__169 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__169)) __PYX_ERR(0, 3260, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__169); + __Pyx_GIVEREF(__pyx_tuple__169); - /* "pysam/libcbcf.pyx":2828 + /* "pysam/libcbcf.pyx":3299 * if line.m: * free(line.s) * raise ValueError('vcf_format failed') # <<<<<<<<<<<<<< * * # Strip CR/LF? */ - __pyx_tuple__162 = PyTuple_Pack(1, __pyx_kp_s_vcf_format_failed); if (unlikely(!__pyx_tuple__162)) __PYX_ERR(0, 2828, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__162); - __Pyx_GIVEREF(__pyx_tuple__162); + __pyx_tuple__170 = PyTuple_Pack(1, __pyx_kp_s_vcf_format_failed); if (unlikely(!__pyx_tuple__170)) __PYX_ERR(0, 3299, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__170); + __Pyx_GIVEREF(__pyx_tuple__170); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -78325,106 +88393,106 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") */ - __pyx_tuple__163 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__163)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__163); - __Pyx_GIVEREF(__pyx_tuple__163); + __pyx_tuple__171 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__171)) __PYX_ERR(2, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__171); + __Pyx_GIVEREF(__pyx_tuple__171); /* "(tree fragment)":4 * raise TypeError("self.ptr cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__164 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__164)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__164); - __Pyx_GIVEREF(__pyx_tuple__164); + __pyx_tuple__172 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__172)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__172); + __Pyx_GIVEREF(__pyx_tuple__172); - /* "pysam/libcbcf.pyx":2847 + /* "pysam/libcbcf.pyx":3318 * cdef VariantRecord makeVariantRecord(VariantHeader header, bcf1_t *r): * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * if not r: */ - __pyx_tuple__165 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__165)) __PYX_ERR(0, 2847, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__165); - __Pyx_GIVEREF(__pyx_tuple__165); + __pyx_tuple__173 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__173)) __PYX_ERR(0, 3318, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__173); + __Pyx_GIVEREF(__pyx_tuple__173); - /* "pysam/libcbcf.pyx":2850 + /* "pysam/libcbcf.pyx":3321 * * if not r: * raise ValueError('cannot create VariantRecord') # <<<<<<<<<<<<<< * * if r.errcode: */ - __pyx_tuple__166 = PyTuple_Pack(1, __pyx_kp_s_cannot_create_VariantRecord); if (unlikely(!__pyx_tuple__166)) __PYX_ERR(0, 2850, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__166); - __Pyx_GIVEREF(__pyx_tuple__166); + __pyx_tuple__174 = PyTuple_Pack(1, __pyx_kp_s_cannot_create_VariantRecord); if (unlikely(!__pyx_tuple__174)) __PYX_ERR(0, 3321, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__174); + __Pyx_GIVEREF(__pyx_tuple__174); - /* "pysam/libcbcf.pyx":2892 + /* "pysam/libcbcf.pyx":3363 * """ * def __init__(self, *args, **kwargs): * raise TypeError('this class cannot be instantiated from Python') # <<<<<<<<<<<<<< * * @property */ - __pyx_tuple__168 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__168)) __PYX_ERR(0, 2892, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__168); - __Pyx_GIVEREF(__pyx_tuple__168); + __pyx_tuple__176 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__176)) __PYX_ERR(0, 3363, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__176); + __Pyx_GIVEREF(__pyx_tuple__176); - /* "pysam/libcbcf.pyx":2902 + /* "pysam/libcbcf.pyx":3373 * * if self.index < 0 or self.index >= n: * raise ValueError('invalid sample index') # <<<<<<<<<<<<<< * * return charptr_to_str(hdr.samples[self.index]) */ - __pyx_tuple__169 = PyTuple_Pack(1, __pyx_kp_s_invalid_sample_index); if (unlikely(!__pyx_tuple__169)) __PYX_ERR(0, 2902, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__169); - __Pyx_GIVEREF(__pyx_tuple__169); + __pyx_tuple__177 = PyTuple_Pack(1, __pyx_kp_s_invalid_sample_index); if (unlikely(!__pyx_tuple__177)) __PYX_ERR(0, 3373, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__177); + __Pyx_GIVEREF(__pyx_tuple__177); - /* "pysam/libcbcf.pyx":2947 + /* "pysam/libcbcf.pyx":3418 * * if bcf_unpack(r, BCF_UN_FMT) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * for i in range(r.n_fmt): */ - __pyx_tuple__170 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__170)) __PYX_ERR(0, 2947, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__170); - __Pyx_GIVEREF(__pyx_tuple__170); + __pyx_tuple__178 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__178)) __PYX_ERR(0, 3418, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__178); + __Pyx_GIVEREF(__pyx_tuple__178); - /* "pysam/libcbcf.pyx":2960 + /* "pysam/libcbcf.pyx":3431 * * if bcf_unpack(r, BCF_UN_FMT) < 0: * raise ValueError('Error unpacking VariantRecord') # <<<<<<<<<<<<<< * * for i in range(r.n_fmt): */ - __pyx_tuple__171 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__171)) __PYX_ERR(0, 2960, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__171); - __Pyx_GIVEREF(__pyx_tuple__171); + __pyx_tuple__179 = PyTuple_Pack(1, __pyx_kp_s_Error_unpacking_VariantRecord); if (unlikely(!__pyx_tuple__179)) __PYX_ERR(0, 3431, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__179); + __Pyx_GIVEREF(__pyx_tuple__179); - /* "pysam/libcbcf.pyx":3047 + /* "pysam/libcbcf.pyx":3549 * cdef VariantRecordSample makeVariantRecordSample(VariantRecord record, int32_t sample_index): * if not record or sample_index < 0: * raise ValueError('cannot create VariantRecordSample') # <<<<<<<<<<<<<< * * cdef VariantRecordSample sample = VariantRecordSample.__new__(VariantRecordSample) */ - __pyx_tuple__172 = PyTuple_Pack(1, __pyx_kp_s_cannot_create_VariantRecordSampl); if (unlikely(!__pyx_tuple__172)) __PYX_ERR(0, 3047, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__172); - __Pyx_GIVEREF(__pyx_tuple__172); + __pyx_tuple__181 = PyTuple_Pack(1, __pyx_kp_s_cannot_create_VariantRecordSampl); if (unlikely(!__pyx_tuple__181)) __PYX_ERR(0, 3549, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__181); + __Pyx_GIVEREF(__pyx_tuple__181); - /* "pysam/libcbcf.pyx":3136 + /* "pysam/libcbcf.pyx":3660 * * if not self.ptr: * raise ValueError('Invalid index object') # <<<<<<<<<<<<<< * * cdef int n */ - __pyx_tuple__173 = PyTuple_Pack(1, __pyx_kp_s_Invalid_index_object); if (unlikely(!__pyx_tuple__173)) __PYX_ERR(0, 3136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__173); - __Pyx_GIVEREF(__pyx_tuple__173); + __pyx_tuple__183 = PyTuple_Pack(1, __pyx_kp_s_Invalid_index_object); if (unlikely(!__pyx_tuple__183)) __PYX_ERR(0, 3660, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__183); + __Pyx_GIVEREF(__pyx_tuple__183); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -78432,40 +88500,40 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") */ - __pyx_tuple__174 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__174)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__174); - __Pyx_GIVEREF(__pyx_tuple__174); + __pyx_tuple__184 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__184)) __PYX_ERR(2, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__184); + __Pyx_GIVEREF(__pyx_tuple__184); /* "(tree fragment)":4 * raise TypeError("self.ptr cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__175 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__175)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__175); - __Pyx_GIVEREF(__pyx_tuple__175); + __pyx_tuple__185 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__185)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__185); + __Pyx_GIVEREF(__pyx_tuple__185); - /* "pysam/libcbcf.pyx":3158 + /* "pysam/libcbcf.pyx":3682 * * if not header: * raise ValueError('invalid VariantHeader') # <<<<<<<<<<<<<< * * cdef BCFIndex index = BCFIndex.__new__(BCFIndex) */ - __pyx_tuple__176 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__176)) __PYX_ERR(0, 3158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__176); - __Pyx_GIVEREF(__pyx_tuple__176); + __pyx_tuple__186 = PyTuple_Pack(1, __pyx_kp_s_invalid_VariantHeader); if (unlikely(!__pyx_tuple__186)) __PYX_ERR(0, 3682, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__186); + __Pyx_GIVEREF(__pyx_tuple__186); - /* "pysam/libcbcf.pyx":3175 + /* "pysam/libcbcf.pyx":3699 * * if not self.ptr: * raise ValueError('Invalid index object') # <<<<<<<<<<<<<< * * cdef int n */ - __pyx_tuple__177 = PyTuple_Pack(1, __pyx_kp_s_Invalid_index_object); if (unlikely(!__pyx_tuple__177)) __PYX_ERR(0, 3175, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__177); - __Pyx_GIVEREF(__pyx_tuple__177); + __pyx_tuple__187 = PyTuple_Pack(1, __pyx_kp_s_Invalid_index_object); if (unlikely(!__pyx_tuple__187)) __PYX_ERR(0, 3699, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__187); + __Pyx_GIVEREF(__pyx_tuple__187); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -78473,18 +88541,18 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") */ - __pyx_tuple__178 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__178)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__178); - __Pyx_GIVEREF(__pyx_tuple__178); + __pyx_tuple__188 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__188)) __PYX_ERR(2, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__188); + __Pyx_GIVEREF(__pyx_tuple__188); /* "(tree fragment)":4 * raise TypeError("self.ptr cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.ptr cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__179 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__179)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__179); - __Pyx_GIVEREF(__pyx_tuple__179); + __pyx_tuple__189 = PyTuple_Pack(1, __pyx_kp_s_self_ptr_cannot_be_converted_to); if (unlikely(!__pyx_tuple__189)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__189); + __Pyx_GIVEREF(__pyx_tuple__189); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -78492,84 +88560,95 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iter cannot be converted to a Python object for pickling") */ - __pyx_tuple__180 = PyTuple_Pack(1, __pyx_kp_s_self_iter_cannot_be_converted_to); if (unlikely(!__pyx_tuple__180)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__180); - __Pyx_GIVEREF(__pyx_tuple__180); + __pyx_tuple__190 = PyTuple_Pack(1, __pyx_kp_s_self_iter_cannot_be_converted_to); if (unlikely(!__pyx_tuple__190)) __PYX_ERR(2, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__190); + __Pyx_GIVEREF(__pyx_tuple__190); /* "(tree fragment)":4 * raise TypeError("self.iter cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__181 = PyTuple_Pack(1, __pyx_kp_s_self_iter_cannot_be_converted_to); if (unlikely(!__pyx_tuple__181)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__181); - __Pyx_GIVEREF(__pyx_tuple__181); + __pyx_tuple__191 = PyTuple_Pack(1, __pyx_kp_s_self_iter_cannot_be_converted_to); if (unlikely(!__pyx_tuple__191)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__191); + __Pyx_GIVEREF(__pyx_tuple__191); - /* "pysam/libcbcf.pyx":3226 - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): + /* "pysam/libcbcf.pyx":3750 + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): * if bcf is None: * raise ValueError('bcf must not be None') # <<<<<<<<<<<<<< * + * if contig is None: + */ + __pyx_tuple__192 = PyTuple_Pack(1, __pyx_kp_s_bcf_must_not_be_None); if (unlikely(!__pyx_tuple__192)) __PYX_ERR(0, 3750, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__192); + __Pyx_GIVEREF(__pyx_tuple__192); + + /* "pysam/libcbcf.pyx":3753 + * + * if contig is None: + * raise ValueError('contig must be specified') # <<<<<<<<<<<<<< + * * if not isinstance(bcf.index, BCFIndex): */ - __pyx_tuple__182 = PyTuple_Pack(1, __pyx_kp_s_bcf_must_not_be_None); if (unlikely(!__pyx_tuple__182)) __PYX_ERR(0, 3226, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__182); - __Pyx_GIVEREF(__pyx_tuple__182); + __pyx_tuple__193 = PyTuple_Pack(1, __pyx_kp_s_contig_must_be_specified); if (unlikely(!__pyx_tuple__193)) __PYX_ERR(0, 3753, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__193); + __Pyx_GIVEREF(__pyx_tuple__193); - /* "pysam/libcbcf.pyx":3229 + /* "pysam/libcbcf.pyx":3756 * * if not isinstance(bcf.index, BCFIndex): * raise ValueError('bcf index required') # <<<<<<<<<<<<<< * * cdef BCFIndex index = bcf.index */ - __pyx_tuple__183 = PyTuple_Pack(1, __pyx_kp_s_bcf_index_required); if (unlikely(!__pyx_tuple__183)) __PYX_ERR(0, 3229, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__183); - __Pyx_GIVEREF(__pyx_tuple__183); + __pyx_tuple__194 = PyTuple_Pack(1, __pyx_kp_s_bcf_index_required); if (unlikely(!__pyx_tuple__194)) __PYX_ERR(0, 3756, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__194); + __Pyx_GIVEREF(__pyx_tuple__194); - /* "pysam/libcbcf.pyx":3236 + /* "pysam/libcbcf.pyx":3802 * - * if not index: - * raise ValueError('bcf index required') # <<<<<<<<<<<<<< + * if not record: + * raise MemoryError('unable to allocate BCF record') # <<<<<<<<<<<<<< * - * if reopen: + * record.pos = -1 */ - __pyx_tuple__184 = PyTuple_Pack(1, __pyx_kp_s_bcf_index_required); if (unlikely(!__pyx_tuple__184)) __PYX_ERR(0, 3236, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__184); - __Pyx_GIVEREF(__pyx_tuple__184); + __pyx_tuple__195 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_BCF_record); if (unlikely(!__pyx_tuple__195)) __PYX_ERR(0, 3802, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__195); + __Pyx_GIVEREF(__pyx_tuple__195); - /* "pysam/libcbcf.pyx":3256 - * rid = index.refmap[contig] - * except KeyError: - * raise ValueError('Unknown contig specified') # <<<<<<<<<<<<<< - * - * if start is None: + /* "pysam/libcbcf.pyx":3818 + * raise StopIteration + * elif ret == -2: + * raise IOError('truncated file') # <<<<<<<<<<<<<< + * elif errno: + * raise IOError(errno, strerror(errno)) */ - __pyx_tuple__185 = PyTuple_Pack(1, __pyx_kp_s_Unknown_contig_specified); if (unlikely(!__pyx_tuple__185)) __PYX_ERR(0, 3256, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__185); - __Pyx_GIVEREF(__pyx_tuple__185); + __pyx_tuple__196 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__196)) __PYX_ERR(0, 3818, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__196); + __Pyx_GIVEREF(__pyx_tuple__196); - /* "pysam/libcbcf.pyx":3301 - * raise StopIteration + /* "pysam/libcbcf.pyx":3822 + * raise IOError(errno, strerror(errno)) * else: - * raise ValueError('error reading BCF file') # <<<<<<<<<<<<<< + * raise IOError('unable to fetch next record') # <<<<<<<<<<<<<< * * ret = bcf_subset_format(self.bcf.header.ptr, record) */ - __pyx_tuple__186 = PyTuple_Pack(1, __pyx_kp_s_error_reading_BCF_file); if (unlikely(!__pyx_tuple__186)) __PYX_ERR(0, 3301, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__186); - __Pyx_GIVEREF(__pyx_tuple__186); + __pyx_tuple__197 = PyTuple_Pack(1, __pyx_kp_s_unable_to_fetch_next_record); if (unlikely(!__pyx_tuple__197)) __PYX_ERR(0, 3822, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__197); + __Pyx_GIVEREF(__pyx_tuple__197); - /* "pysam/libcbcf.pyx":3307 + /* "pysam/libcbcf.pyx":3828 * if ret < 0: * _stop_BCFIterator(self, record) * raise ValueError('error in bcf_subset_format') # <<<<<<<<<<<<<< * * return makeVariantRecord(self.bcf.header, record) */ - __pyx_tuple__187 = PyTuple_Pack(1, __pyx_kp_s_error_in_bcf_subset_format); if (unlikely(!__pyx_tuple__187)) __PYX_ERR(0, 3307, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__187); - __Pyx_GIVEREF(__pyx_tuple__187); + __pyx_tuple__198 = PyTuple_Pack(1, __pyx_kp_s_error_in_bcf_subset_format); if (unlikely(!__pyx_tuple__198)) __PYX_ERR(0, 3828, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__198); + __Pyx_GIVEREF(__pyx_tuple__198); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -78577,73 +88656,84 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iter cannot be converted to a Python object for pickling") */ - __pyx_tuple__188 = PyTuple_Pack(1, __pyx_kp_s_self_iter_cannot_be_converted_to); if (unlikely(!__pyx_tuple__188)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__188); - __Pyx_GIVEREF(__pyx_tuple__188); + __pyx_tuple__199 = PyTuple_Pack(1, __pyx_kp_s_self_iter_cannot_be_converted_to); if (unlikely(!__pyx_tuple__199)) __PYX_ERR(2, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__199); + __Pyx_GIVEREF(__pyx_tuple__199); /* "(tree fragment)":4 * raise TypeError("self.iter cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iter cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__189 = PyTuple_Pack(1, __pyx_kp_s_self_iter_cannot_be_converted_to); if (unlikely(!__pyx_tuple__189)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__189); - __Pyx_GIVEREF(__pyx_tuple__189); + __pyx_tuple__200 = PyTuple_Pack(1, __pyx_kp_s_self_iter_cannot_be_converted_to); if (unlikely(!__pyx_tuple__200)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__200); + __Pyx_GIVEREF(__pyx_tuple__200); - /* "pysam/libcbcf.pyx":3320 - * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): + /* "pysam/libcbcf.pyx":3841 + * def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): * if bcf is None: * raise ValueError('bcf must not be None') # <<<<<<<<<<<<<< * * if not isinstance(bcf.index, TabixIndex): */ - __pyx_tuple__190 = PyTuple_Pack(1, __pyx_kp_s_bcf_must_not_be_None); if (unlikely(!__pyx_tuple__190)) __PYX_ERR(0, 3320, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__190); - __Pyx_GIVEREF(__pyx_tuple__190); + __pyx_tuple__201 = PyTuple_Pack(1, __pyx_kp_s_bcf_must_not_be_None); if (unlikely(!__pyx_tuple__201)) __PYX_ERR(0, 3841, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__201); + __Pyx_GIVEREF(__pyx_tuple__201); - /* "pysam/libcbcf.pyx":3323 + /* "pysam/libcbcf.pyx":3844 * * if not isinstance(bcf.index, TabixIndex): * raise ValueError('tabix index required') # <<<<<<<<<<<<<< * * cdef TabixIndex index = bcf.index */ - __pyx_tuple__191 = PyTuple_Pack(1, __pyx_kp_s_tabix_index_required); if (unlikely(!__pyx_tuple__191)) __PYX_ERR(0, 3323, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__191); - __Pyx_GIVEREF(__pyx_tuple__191); + __pyx_tuple__202 = PyTuple_Pack(1, __pyx_kp_s_tabix_index_required); if (unlikely(!__pyx_tuple__202)) __PYX_ERR(0, 3844, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__202); + __Pyx_GIVEREF(__pyx_tuple__202); - /* "pysam/libcbcf.pyx":3328 - * - * if not index: - * raise ValueError('bcf index required') # <<<<<<<<<<<<<< - * - * if reopen: + /* "pysam/libcbcf.pyx":3904 + * raise StopIteration + * elif ret == -2: + * raise IOError('truncated file') # <<<<<<<<<<<<<< + * elif errno: + * raise IOError(errno, strerror(errno)) */ - __pyx_tuple__192 = PyTuple_Pack(1, __pyx_kp_s_bcf_index_required); if (unlikely(!__pyx_tuple__192)) __PYX_ERR(0, 3328, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__192); - __Pyx_GIVEREF(__pyx_tuple__192); + __pyx_tuple__203 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__203)) __PYX_ERR(0, 3904, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__203); + __Pyx_GIVEREF(__pyx_tuple__203); - /* "pysam/libcbcf.pyx":3386 - * raise StopIteration + /* "pysam/libcbcf.pyx":3908 + * raise IOError(errno, strerror(errno)) * else: - * raise ValueError('error reading indexed VCF file') # <<<<<<<<<<<<<< + * raise IOError('unable to fetch next record') # <<<<<<<<<<<<<< * * cdef bcf1_t *record = bcf_init1() */ - __pyx_tuple__193 = PyTuple_Pack(1, __pyx_kp_s_error_reading_indexed_VCF_file); if (unlikely(!__pyx_tuple__193)) __PYX_ERR(0, 3386, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__193); - __Pyx_GIVEREF(__pyx_tuple__193); + __pyx_tuple__204 = PyTuple_Pack(1, __pyx_kp_s_unable_to_fetch_next_record); if (unlikely(!__pyx_tuple__204)) __PYX_ERR(0, 3908, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__204); + __Pyx_GIVEREF(__pyx_tuple__204); + + /* "pysam/libcbcf.pyx":3913 + * + * if not record: + * raise MemoryError('unable to allocate BCF record') # <<<<<<<<<<<<<< + * + * record.pos = -1 + */ + __pyx_tuple__205 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_BCF_record); if (unlikely(!__pyx_tuple__205)) __PYX_ERR(0, 3913, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__205); + __Pyx_GIVEREF(__pyx_tuple__205); - /* "pysam/libcbcf.pyx":3399 + /* "pysam/libcbcf.pyx":3924 * if ret < 0: * bcf_destroy1(record) * raise ValueError('error in vcf_parse') # <<<<<<<<<<<<<< * * return makeVariantRecord(self.bcf.header, record) */ - __pyx_tuple__194 = PyTuple_Pack(1, __pyx_kp_s_error_in_vcf_parse); if (unlikely(!__pyx_tuple__194)) __PYX_ERR(0, 3399, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__194); - __Pyx_GIVEREF(__pyx_tuple__194); + __pyx_tuple__206 = PyTuple_Pack(1, __pyx_kp_s_error_in_vcf_parse); if (unlikely(!__pyx_tuple__206)) __PYX_ERR(0, 3924, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__206); + __Pyx_GIVEREF(__pyx_tuple__206); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -78651,260 +88741,326 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__195 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__195)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__195); - __Pyx_GIVEREF(__pyx_tuple__195); + __pyx_tuple__207 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__207)) __PYX_ERR(2, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__207); + __Pyx_GIVEREF(__pyx_tuple__207); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__196 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__196)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__196); - __Pyx_GIVEREF(__pyx_tuple__196); + __pyx_tuple__208 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__208)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__208); + __Pyx_GIVEREF(__pyx_tuple__208); - /* "pysam/libcbcf.pyx":3504 + /* "pysam/libcbcf.pyx":4060 * def __iter__(self): * if not self.is_open: * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< * * if self.htsfile.is_write: */ - __pyx_tuple__197 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__197)) __PYX_ERR(0, 3504, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__197); - __Pyx_GIVEREF(__pyx_tuple__197); + __pyx_tuple__209 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__209)) __PYX_ERR(0, 4060, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__209); + __Pyx_GIVEREF(__pyx_tuple__209); - /* "pysam/libcbcf.pyx":3507 + /* "pysam/libcbcf.pyx":4063 * * if self.htsfile.is_write: * raise ValueError('cannot iterate over Variantfile opened for writing') # <<<<<<<<<<<<<< * * self.is_reading = 1 */ - __pyx_tuple__198 = PyTuple_Pack(1, __pyx_kp_s_cannot_iterate_over_Variantfile); if (unlikely(!__pyx_tuple__198)) __PYX_ERR(0, 3507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__198); - __Pyx_GIVEREF(__pyx_tuple__198); + __pyx_tuple__210 = PyTuple_Pack(1, __pyx_kp_s_cannot_iterate_over_Variantfile); if (unlikely(!__pyx_tuple__210)) __PYX_ERR(0, 4063, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__210); + __Pyx_GIVEREF(__pyx_tuple__210); - /* "pysam/libcbcf.pyx":3528 + /* "pysam/libcbcf.pyx":4073 + * + * if not record: + * raise MemoryError('unable to allocate BCF record') # <<<<<<<<<<<<<< + * + * record.pos = -1 + */ + __pyx_tuple__211 = PyTuple_Pack(1, __pyx_kp_s_unable_to_allocate_BCF_record); if (unlikely(!__pyx_tuple__211)) __PYX_ERR(0, 4073, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__211); + __Pyx_GIVEREF(__pyx_tuple__211); + + /* "pysam/libcbcf.pyx":4087 * raise StopIteration * elif ret == -2: * raise IOError('truncated file') # <<<<<<<<<<<<<< - * else: - * raise ValueError('Variant read failed') + * elif errno: + * raise IOError(errno, strerror(errno)) */ - __pyx_tuple__199 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__199)) __PYX_ERR(0, 3528, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__199); - __Pyx_GIVEREF(__pyx_tuple__199); + __pyx_tuple__212 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__212)) __PYX_ERR(0, 4087, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__212); + __Pyx_GIVEREF(__pyx_tuple__212); - /* "pysam/libcbcf.pyx":3530 - * raise IOError('truncated file') + /* "pysam/libcbcf.pyx":4091 + * raise IOError(errno, strerror(errno)) * else: - * raise ValueError('Variant read failed') # <<<<<<<<<<<<<< + * raise IOError('unable to fetch next record') # <<<<<<<<<<<<<< * * return makeVariantRecord(self.header, record) */ - __pyx_tuple__200 = PyTuple_Pack(1, __pyx_kp_s_Variant_read_failed); if (unlikely(!__pyx_tuple__200)) __PYX_ERR(0, 3530, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__200); - __Pyx_GIVEREF(__pyx_tuple__200); + __pyx_tuple__213 = PyTuple_Pack(1, __pyx_kp_s_unable_to_fetch_next_record); if (unlikely(!__pyx_tuple__213)) __PYX_ERR(0, 4091, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__213); + __Pyx_GIVEREF(__pyx_tuple__213); - /* "pysam/libcbcf.pyx":3545 + /* "pysam/libcbcf.pyx":4106 * * if not vars.htsfile: * raise ValueError('Cannot re-open htsfile') # <<<<<<<<<<<<<< * * # minimize overhead by re-using header and index. This approach is */ - __pyx_tuple__201 = PyTuple_Pack(1, __pyx_kp_s_Cannot_re_open_htsfile); if (unlikely(!__pyx_tuple__201)) __PYX_ERR(0, 3545, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__201); - __Pyx_GIVEREF(__pyx_tuple__201); + __pyx_tuple__214 = PyTuple_Pack(1, __pyx_kp_s_Cannot_re_open_htsfile); if (unlikely(!__pyx_tuple__214)) __PYX_ERR(0, 4106, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__214); + __Pyx_GIVEREF(__pyx_tuple__214); + + /* "pysam/libcbcf.pyx":4159 + * # to bgzf_read (https://github.com/samtools/htslib/blob/1.7/bgzf.c#L888) + * # Better to avoid this (for now) than to produce seemingly correct results. + * raise ValueError('Cannot add extra threads when "ignore_truncation" is True') # <<<<<<<<<<<<<< + * self.threads = threads + * + */ + __pyx_tuple__215 = PyTuple_Pack(1, __pyx_kp_s_Cannot_add_extra_threads_when_ig); if (unlikely(!__pyx_tuple__215)) __PYX_ERR(0, 4159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__215); + __Pyx_GIVEREF(__pyx_tuple__215); - /* "pysam/libcbcf.pyx":3594 + /* "pysam/libcbcf.pyx":4167 * * if not mode or mode[0] not in 'rwa': * raise ValueError('mode must begin with r, w or a') # <<<<<<<<<<<<<< * * self.duplicate_filehandle = duplicate_filehandle */ - __pyx_tuple__202 = PyTuple_Pack(1, __pyx_kp_s_mode_must_begin_with_r_w_or_a); if (unlikely(!__pyx_tuple__202)) __PYX_ERR(0, 3594, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__202); - __Pyx_GIVEREF(__pyx_tuple__202); + __pyx_tuple__216 = PyTuple_Pack(1, __pyx_kp_s_mode_must_begin_with_r_w_or_a); if (unlikely(!__pyx_tuple__216)) __PYX_ERR(0, 4167, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__216); + __Pyx_GIVEREF(__pyx_tuple__216); - /* "pysam/libcbcf.pyx":3598 + /* "pysam/libcbcf.pyx":4171 * self.duplicate_filehandle = duplicate_filehandle * * format_modes = [m for m in mode[1:] if m in 'bcguz'] # <<<<<<<<<<<<<< * if len(format_modes) > 1: * raise ValueError('mode contains conflicting format specifiers: {}'.format(''.join(format_modes))) */ - __pyx_slice__203 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__203)) __PYX_ERR(0, 3598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__203); - __Pyx_GIVEREF(__pyx_slice__203); + __pyx_slice__217 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__217)) __PYX_ERR(0, 4171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__217); + __Pyx_GIVEREF(__pyx_slice__217); - /* "pysam/libcbcf.pyx":3602 + /* "pysam/libcbcf.pyx":4175 * raise ValueError('mode contains conflicting format specifiers: {}'.format(''.join(format_modes))) * * invalid_modes = [m for m in mode[1:] if m not in 'bcguz0123456789ex'] # <<<<<<<<<<<<<< * if invalid_modes: * raise ValueError('invalid mode options: {}'.format(''.join(invalid_modes))) */ - __pyx_slice__204 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__204)) __PYX_ERR(0, 3602, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__204); - __Pyx_GIVEREF(__pyx_slice__204); + __pyx_slice__218 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__218)) __PYX_ERR(0, 4175, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__218); + __Pyx_GIVEREF(__pyx_slice__218); - /* "pysam/libcbcf.pyx":3608 + /* "pysam/libcbcf.pyx":4181 * # Autodetect mode from filename * if mode == 'w' and isinstance(filename, str): * if filename.endswith('.gz'): # <<<<<<<<<<<<<< * mode = 'wz' * elif filename.endswith('.bcf'): */ - __pyx_tuple__205 = PyTuple_Pack(1, __pyx_kp_s_gz); if (unlikely(!__pyx_tuple__205)) __PYX_ERR(0, 3608, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__205); - __Pyx_GIVEREF(__pyx_tuple__205); + __pyx_tuple__219 = PyTuple_Pack(1, __pyx_kp_s_gz); if (unlikely(!__pyx_tuple__219)) __PYX_ERR(0, 4181, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__219); + __Pyx_GIVEREF(__pyx_tuple__219); - /* "pysam/libcbcf.pyx":3610 + /* "pysam/libcbcf.pyx":4183 * if filename.endswith('.gz'): * mode = 'wz' * elif filename.endswith('.bcf'): # <<<<<<<<<<<<<< * mode = 'wb' * */ - __pyx_tuple__206 = PyTuple_Pack(1, __pyx_kp_s_bcf_2); if (unlikely(!__pyx_tuple__206)) __PYX_ERR(0, 3610, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__206); - __Pyx_GIVEREF(__pyx_tuple__206); + __pyx_tuple__220 = PyTuple_Pack(1, __pyx_kp_s_bcf_2); if (unlikely(!__pyx_tuple__220)) __PYX_ERR(0, 4183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__220); + __Pyx_GIVEREF(__pyx_tuple__220); - /* "pysam/libcbcf.pyx":3639 + /* "pysam/libcbcf.pyx":4212 * self.header_written = False * * if mode.startswith(b'w'): # <<<<<<<<<<<<<< * # open file for writing * if index_filename is not None: */ - __pyx_tuple__208 = PyTuple_Pack(1, __pyx_n_b_w); if (unlikely(!__pyx_tuple__208)) __PYX_ERR(0, 3639, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__208); - __Pyx_GIVEREF(__pyx_tuple__208); + __pyx_tuple__222 = PyTuple_Pack(1, __pyx_n_b_w); if (unlikely(!__pyx_tuple__222)) __PYX_ERR(0, 4212, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__222); + __Pyx_GIVEREF(__pyx_tuple__222); - /* "pysam/libcbcf.pyx":3642 + /* "pysam/libcbcf.pyx":4215 * # open file for writing * if index_filename is not None: * raise ValueError('Cannot specify an index filename when writing a VCF/BCF file') # <<<<<<<<<<<<<< * * # header structure (used for writing) */ - __pyx_tuple__209 = PyTuple_Pack(1, __pyx_kp_s_Cannot_specify_an_index_filename); if (unlikely(!__pyx_tuple__209)) __PYX_ERR(0, 3642, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__209); - __Pyx_GIVEREF(__pyx_tuple__209); + __pyx_tuple__223 = PyTuple_Pack(1, __pyx_kp_s_Cannot_specify_an_index_filename); if (unlikely(!__pyx_tuple__223)) __PYX_ERR(0, 4215, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__223); + __Pyx_GIVEREF(__pyx_tuple__223); - /* "pysam/libcbcf.pyx":3657 + /* "pysam/libcbcf.pyx":4230 * raise ValueError("could not open file `{}` (mode='{}')".format(filename, mode)) * * elif mode.startswith(b'r'): # <<<<<<<<<<<<<< * # open file for reading + * self.htsfile = self._open_htsfile() + */ + __pyx_tuple__224 = PyTuple_Pack(1, __pyx_n_b_r); if (unlikely(!__pyx_tuple__224)) __PYX_ERR(0, 4230, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__224); + __Pyx_GIVEREF(__pyx_tuple__224); + + /* "pysam/libcbcf.pyx":4289 + * """ + * if not self.is_open: + * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< * + * cdef bcf_hdr_t *hdr = self.header.ptr */ - __pyx_tuple__210 = PyTuple_Pack(1, __pyx_n_b_r); if (unlikely(!__pyx_tuple__210)) __PYX_ERR(0, 3657, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__210); - __Pyx_GIVEREF(__pyx_tuple__210); + __pyx_tuple__225 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__225)) __PYX_ERR(0, 4289, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__225); + __Pyx_GIVEREF(__pyx_tuple__225); + + /* "pysam/libcbcf.pyx":4303 + * """ + * if not self.is_open: + * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< + * + * cdef vdict_t *d = self.header.ptr.dict[BCF_DT_CTG] + */ + __pyx_tuple__226 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__226)) __PYX_ERR(0, 4303, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__226); + __Pyx_GIVEREF(__pyx_tuple__226); + + /* "pysam/libcbcf.pyx":4315 + * """ + * if not self.is_open: + * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< + * + * cdef bcf_hdr_t *hdr = self.header.ptr + */ + __pyx_tuple__227 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__227)) __PYX_ERR(0, 4315, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__227); + __Pyx_GIVEREF(__pyx_tuple__227); + + /* "pysam/libcbcf.pyx":4320 + * cdef int rid = tid + * if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: + * raise ValueError('Invalid tid') # <<<<<<<<<<<<<< + * return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) + * + */ + __pyx_tuple__228 = PyTuple_Pack(1, __pyx_kp_s_Invalid_tid); if (unlikely(!__pyx_tuple__228)) __PYX_ERR(0, 4320, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__228); + __Pyx_GIVEREF(__pyx_tuple__228); - /* "pysam/libcbcf.pyx":3736 + /* "pysam/libcbcf.pyx":4345 * """ * if not self.is_open: * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< * * if self.htsfile.is_write: */ - __pyx_tuple__211 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__211)) __PYX_ERR(0, 3736, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__211); - __Pyx_GIVEREF(__pyx_tuple__211); + __pyx_tuple__229 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__229)) __PYX_ERR(0, 4345, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__229); + __Pyx_GIVEREF(__pyx_tuple__229); - /* "pysam/libcbcf.pyx":3739 + /* "pysam/libcbcf.pyx":4348 * * if self.htsfile.is_write: * raise ValueError('cannot fetch from Variantfile opened for writing') # <<<<<<<<<<<<<< * * if contig is None and region is None: */ - __pyx_tuple__212 = PyTuple_Pack(1, __pyx_kp_s_cannot_fetch_from_Variantfile_op); if (unlikely(!__pyx_tuple__212)) __PYX_ERR(0, 3739, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__212); - __Pyx_GIVEREF(__pyx_tuple__212); + __pyx_tuple__230 = PyTuple_Pack(1, __pyx_kp_s_cannot_fetch_from_Variantfile_op); if (unlikely(!__pyx_tuple__230)) __PYX_ERR(0, 4348, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__230); + __Pyx_GIVEREF(__pyx_tuple__230); - /* "pysam/libcbcf.pyx":3748 + /* "pysam/libcbcf.pyx":4357 * * if not self.index: * raise ValueError('fetch requires an index') # <<<<<<<<<<<<<< * - * self.is_reading = 1 + * _, tid, start, stop = self.parse_region(contig, start, stop, region, */ - __pyx_tuple__213 = PyTuple_Pack(1, __pyx_kp_s_fetch_requires_an_index); if (unlikely(!__pyx_tuple__213)) __PYX_ERR(0, 3748, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__213); - __Pyx_GIVEREF(__pyx_tuple__213); + __pyx_tuple__231 = PyTuple_Pack(1, __pyx_kp_s_fetch_requires_an_index); if (unlikely(!__pyx_tuple__231)) __PYX_ERR(0, 4357, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__231); + __Pyx_GIVEREF(__pyx_tuple__231); - /* "pysam/libcbcf.pyx":3764 + /* "pysam/libcbcf.pyx":4382 * """ * if record is None: * raise ValueError('record must not be None') # <<<<<<<<<<<<<< * * if not self.is_open: */ - __pyx_tuple__214 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__214)) __PYX_ERR(0, 3764, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__214); - __Pyx_GIVEREF(__pyx_tuple__214); + __pyx_tuple__232 = PyTuple_Pack(1, __pyx_kp_s_record_must_not_be_None); if (unlikely(!__pyx_tuple__232)) __PYX_ERR(0, 4382, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__232); + __Pyx_GIVEREF(__pyx_tuple__232); - /* "pysam/libcbcf.pyx":3767 + /* "pysam/libcbcf.pyx":4385 * * if not self.is_open: * return ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< * * if not self.htsfile.is_write: */ - __pyx_tuple__215 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__215)) __PYX_ERR(0, 3767, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__215); - __Pyx_GIVEREF(__pyx_tuple__215); + __pyx_tuple__233 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__233)) __PYX_ERR(0, 4385, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__233); + __Pyx_GIVEREF(__pyx_tuple__233); - /* "pysam/libcbcf.pyx":3770 + /* "pysam/libcbcf.pyx":4388 * * if not self.htsfile.is_write: * raise ValueError('cannot write to a Variantfile opened for reading') # <<<<<<<<<<<<<< * * if not self.header_written: */ - __pyx_tuple__216 = PyTuple_Pack(1, __pyx_kp_s_cannot_write_to_a_Variantfile_op); if (unlikely(!__pyx_tuple__216)) __PYX_ERR(0, 3770, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__216); - __Pyx_GIVEREF(__pyx_tuple__216); + __pyx_tuple__234 = PyTuple_Pack(1, __pyx_kp_s_cannot_write_to_a_Variantfile_op); if (unlikely(!__pyx_tuple__234)) __PYX_ERR(0, 4388, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__234); + __Pyx_GIVEREF(__pyx_tuple__234); - /* "pysam/libcbcf.pyx":3801 + /* "pysam/libcbcf.pyx":4422 * """ * if not self.is_open: * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< * * if self.htsfile.is_write: */ - __pyx_tuple__217 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__217)) __PYX_ERR(0, 3801, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__217); - __Pyx_GIVEREF(__pyx_tuple__217); + __pyx_tuple__235 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__235)) __PYX_ERR(0, 4422, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__235); + __Pyx_GIVEREF(__pyx_tuple__235); - /* "pysam/libcbcf.pyx":3804 + /* "pysam/libcbcf.pyx":4425 * * if self.htsfile.is_write: * raise ValueError('cannot subset samples from Variantfile opened for writing') # <<<<<<<<<<<<<< * * if self.is_reading: */ - __pyx_tuple__218 = PyTuple_Pack(1, __pyx_kp_s_cannot_subset_samples_from_Varia); if (unlikely(!__pyx_tuple__218)) __PYX_ERR(0, 3804, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__218); - __Pyx_GIVEREF(__pyx_tuple__218); + __pyx_tuple__236 = PyTuple_Pack(1, __pyx_kp_s_cannot_subset_samples_from_Varia); if (unlikely(!__pyx_tuple__236)) __PYX_ERR(0, 4425, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__236); + __Pyx_GIVEREF(__pyx_tuple__236); - /* "pysam/libcbcf.pyx":3807 + /* "pysam/libcbcf.pyx":4428 * * if self.is_reading: * raise ValueError('cannot subset samples after fetching records') # <<<<<<<<<<<<<< * * self.header._subset_samples(include_samples) */ - __pyx_tuple__219 = PyTuple_Pack(1, __pyx_kp_s_cannot_subset_samples_after_fetc); if (unlikely(!__pyx_tuple__219)) __PYX_ERR(0, 3807, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__219); - __Pyx_GIVEREF(__pyx_tuple__219); + __pyx_tuple__237 = PyTuple_Pack(1, __pyx_kp_s_cannot_subset_samples_after_fetc); if (unlikely(!__pyx_tuple__237)) __PYX_ERR(0, 4428, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__237); + __Pyx_GIVEREF(__pyx_tuple__237); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -78912,105 +89068,105 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__220 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__220)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__220); - __Pyx_GIVEREF(__pyx_tuple__220); + __pyx_tuple__238 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__238)) __PYX_ERR(2, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__238); + __Pyx_GIVEREF(__pyx_tuple__238); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__221 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__221)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__221); - __Pyx_GIVEREF(__pyx_tuple__221); + __pyx_tuple__239 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__239)) __PYX_ERR(2, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__239); + __Pyx_GIVEREF(__pyx_tuple__239); - /* "pysam/libcbcf.pyx":118 + /* "pysam/libcbcf.pyx":115 * * cdef int MAX_POS = 2 << 29 * cdef tuple VALUE_TYPES = ('Flag', 'Integer', 'Float', 'String') # <<<<<<<<<<<<<< * cdef tuple METADATA_TYPES = ('FILTER', 'INFO', 'FORMAT', 'CONTIG', 'STRUCTURED', 'GENERIC') * cdef tuple METADATA_LENGTHS = ('FIXED', 'VARIABLE', 'A', 'G', 'R') */ - __pyx_tuple__234 = PyTuple_Pack(4, __pyx_n_s_Flag, __pyx_n_s_Integer, __pyx_n_s_Float, __pyx_n_s_String); if (unlikely(!__pyx_tuple__234)) __PYX_ERR(0, 118, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__234); - __Pyx_GIVEREF(__pyx_tuple__234); + __pyx_tuple__252 = PyTuple_Pack(4, __pyx_n_s_Flag, __pyx_n_s_Integer, __pyx_n_s_Float, __pyx_n_s_String); if (unlikely(!__pyx_tuple__252)) __PYX_ERR(0, 115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__252); + __Pyx_GIVEREF(__pyx_tuple__252); - /* "pysam/libcbcf.pyx":119 + /* "pysam/libcbcf.pyx":116 * cdef int MAX_POS = 2 << 29 * cdef tuple VALUE_TYPES = ('Flag', 'Integer', 'Float', 'String') * cdef tuple METADATA_TYPES = ('FILTER', 'INFO', 'FORMAT', 'CONTIG', 'STRUCTURED', 'GENERIC') # <<<<<<<<<<<<<< * cdef tuple METADATA_LENGTHS = ('FIXED', 'VARIABLE', 'A', 'G', 'R') * */ - __pyx_tuple__235 = PyTuple_Pack(6, __pyx_n_s_FILTER, __pyx_n_s_INFO, __pyx_n_s_FORMAT, __pyx_n_s_CONTIG, __pyx_n_s_STRUCTURED, __pyx_n_s_GENERIC); if (unlikely(!__pyx_tuple__235)) __PYX_ERR(0, 119, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__235); - __Pyx_GIVEREF(__pyx_tuple__235); + __pyx_tuple__253 = PyTuple_Pack(6, __pyx_n_s_FILTER, __pyx_n_s_INFO, __pyx_n_s_FORMAT, __pyx_n_s_CONTIG, __pyx_n_s_STRUCTURED, __pyx_n_s_GENERIC); if (unlikely(!__pyx_tuple__253)) __PYX_ERR(0, 116, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__253); + __Pyx_GIVEREF(__pyx_tuple__253); - /* "pysam/libcbcf.pyx":120 + /* "pysam/libcbcf.pyx":117 * cdef tuple VALUE_TYPES = ('Flag', 'Integer', 'Float', 'String') * cdef tuple METADATA_TYPES = ('FILTER', 'INFO', 'FORMAT', 'CONTIG', 'STRUCTURED', 'GENERIC') * cdef tuple METADATA_LENGTHS = ('FIXED', 'VARIABLE', 'A', 'G', 'R') # <<<<<<<<<<<<<< * * */ - __pyx_tuple__236 = PyTuple_Pack(5, __pyx_n_s_FIXED, __pyx_n_s_VARIABLE, __pyx_n_s_A, __pyx_n_s_G, __pyx_n_s_R); if (unlikely(!__pyx_tuple__236)) __PYX_ERR(0, 120, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__236); - __Pyx_GIVEREF(__pyx_tuple__236); + __pyx_tuple__254 = PyTuple_Pack(5, __pyx_n_s_FIXED, __pyx_n_s_VARIABLE, __pyx_n_s_A, __pyx_n_s_G, __pyx_n_s_R); if (unlikely(!__pyx_tuple__254)) __PYX_ERR(0, 117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__254); + __Pyx_GIVEREF(__pyx_tuple__254); /* "(tree fragment)":1 * def __pyx_unpickle_VariantHeaderRecords(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x099fb99: * from pickle import PickleError as __pyx_PickleError */ - __pyx_tuple__237 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__237)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__237); - __Pyx_GIVEREF(__pyx_tuple__237); - __pyx_codeobj__222 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__237, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantHeaderReco, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__222)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__238 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__238)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__238); - __Pyx_GIVEREF(__pyx_tuple__238); - __pyx_codeobj__223 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__238, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantMetadata, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__223)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__239 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__239)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__239); - __Pyx_GIVEREF(__pyx_tuple__239); - __pyx_codeobj__224 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__239, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantHeaderMeta, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__224)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__240 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__240)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__240); - __Pyx_GIVEREF(__pyx_tuple__240); - __pyx_codeobj__225 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__240, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantContig, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__225)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__241 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__241)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__241); - __Pyx_GIVEREF(__pyx_tuple__241); - __pyx_codeobj__226 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__241, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantHeaderCont, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__226)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__242 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__242)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__242); - __Pyx_GIVEREF(__pyx_tuple__242); - __pyx_codeobj__227 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__242, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantHeaderSamp, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__227)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__243 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__243)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__243); - __Pyx_GIVEREF(__pyx_tuple__243); - __pyx_codeobj__228 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__243, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantRecordFilt, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__228)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__244 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__244)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__244); - __Pyx_GIVEREF(__pyx_tuple__244); - __pyx_codeobj__229 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__244, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantRecordForm, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__229)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__245 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__245)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__245); - __Pyx_GIVEREF(__pyx_tuple__245); - __pyx_codeobj__230 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__245, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantRecordInfo, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__230)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__246 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__246)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__246); - __Pyx_GIVEREF(__pyx_tuple__246); - __pyx_codeobj__231 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__246, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantRecordSamp, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__231)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__247 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__247)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__247); - __Pyx_GIVEREF(__pyx_tuple__247); - __pyx_codeobj__232 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__247, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantRecordSamp_2, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__232)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__248 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__248)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__248); - __Pyx_GIVEREF(__pyx_tuple__248); - __pyx_codeobj__233 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__248, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_BaseIndex, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__233)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_tuple__255 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__255)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__255); + __Pyx_GIVEREF(__pyx_tuple__255); + __pyx_codeobj__240 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__255, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantHeaderReco, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__240)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__256 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__256)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__256); + __Pyx_GIVEREF(__pyx_tuple__256); + __pyx_codeobj__241 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__256, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantMetadata, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__241)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__257 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__257)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__257); + __Pyx_GIVEREF(__pyx_tuple__257); + __pyx_codeobj__242 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__257, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantHeaderMeta, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__242)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__258 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__258)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__258); + __Pyx_GIVEREF(__pyx_tuple__258); + __pyx_codeobj__243 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__258, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantContig, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__243)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__259 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__259)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__259); + __Pyx_GIVEREF(__pyx_tuple__259); + __pyx_codeobj__244 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__259, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantHeaderCont, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__244)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__260 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__260)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__260); + __Pyx_GIVEREF(__pyx_tuple__260); + __pyx_codeobj__245 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__260, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantHeaderSamp, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__245)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__261 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__261)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__261); + __Pyx_GIVEREF(__pyx_tuple__261); + __pyx_codeobj__246 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__261, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantRecordFilt, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__246)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__262 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__262)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__262); + __Pyx_GIVEREF(__pyx_tuple__262); + __pyx_codeobj__247 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__262, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantRecordForm, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__247)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__263 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__263)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__263); + __Pyx_GIVEREF(__pyx_tuple__263); + __pyx_codeobj__248 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__263, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantRecordInfo, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__248)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__264 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__264)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__264); + __Pyx_GIVEREF(__pyx_tuple__264); + __pyx_codeobj__249 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__264, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantRecordSamp, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__249)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__265 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__265)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__265); + __Pyx_GIVEREF(__pyx_tuple__265); + __pyx_codeobj__250 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__265, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_VariantRecordSamp_2, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__250)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__266 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__266)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__266); + __Pyx_GIVEREF(__pyx_tuple__266); + __pyx_codeobj__251 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__266, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_BaseIndex, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__251)) __PYX_ERR(2, 1, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -79019,11 +89175,13 @@ static int __Pyx_InitCachedConstants(void) { } static int __Pyx_InitGlobals(void) { - __pyx_umethod_PyDict_Type_get.type = (PyObject*)&PyDict_Type; + __pyx_umethod_PyBytes_Type_split.type = (PyObject*)&PyBytes_Type; __pyx_umethod_PyDict_Type_items.type = (PyObject*)&PyDict_Type; + __pyx_umethod_PyDict_Type_pop.type = (PyObject*)&PyDict_Type; if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_10091417 = PyInt_FromLong(10091417L); if (unlikely(!__pyx_int_10091417)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_97976187 = PyInt_FromLong(97976187L); if (unlikely(!__pyx_int_97976187)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_164668780 = PyInt_FromLong(164668780L); if (unlikely(!__pyx_int_164668780)) __PYX_ERR(0, 1, __pyx_L1_error) @@ -79053,6 +89211,7 @@ static int __Pyx_modinit_global_init_code(void) { __pyx_v_5pysam_7libcbcf_VALUE_TYPES = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_5pysam_7libcbcf_METADATA_TYPES = ((PyObject*)Py_None); Py_INCREF(Py_None); __pyx_v_5pysam_7libcbcf_METADATA_LENGTHS = ((PyObject*)Py_None); Py_INCREF(Py_None); + __pyx_v_5pysam_7libcbcf__nothing = Py_None; Py_INCREF(Py_None); __pyx_v_5pysam_7libcbcf_bcf_str_cache = ((PyObject*)Py_None); Py_INCREF(Py_None); __Pyx_RefNannyFinishContext(); return 0; @@ -79079,25 +89238,24 @@ static int __Pyx_modinit_type_init_code(void) { __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); /*--- Type init code ---*/ __pyx_vtabptr_5pysam_7libcbcf_VariantHeader = &__pyx_vtable_5pysam_7libcbcf_VariantHeader; - __pyx_vtable_5pysam_7libcbcf_VariantHeader.new_record = (struct __pyx_obj_5pysam_7libcbcf_VariantRecord *(*)(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *, int __pyx_skip_dispatch))__pyx_f_5pysam_7libcbcf_13VariantHeader_new_record; __pyx_vtable_5pysam_7libcbcf_VariantHeader._subset_samples = (PyObject *(*)(struct __pyx_obj_5pysam_7libcbcf_VariantHeader *, PyObject *))__pyx_f_5pysam_7libcbcf_13VariantHeader__subset_samples; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantHeader) < 0) __PYX_ERR(0, 1777, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantHeader) < 0) __PYX_ERR(0, 1935, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantHeader.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantHeader.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantHeader.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantHeader.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_7libcbcf_VariantHeader.tp_dict, __pyx_vtabptr_5pysam_7libcbcf_VariantHeader) < 0) __PYX_ERR(0, 1777, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "VariantHeader", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeader) < 0) __PYX_ERR(0, 1777, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantHeader) < 0) __PYX_ERR(0, 1777, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_7libcbcf_VariantHeader.tp_dict, __pyx_vtabptr_5pysam_7libcbcf_VariantHeader) < 0) __PYX_ERR(0, 1935, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantHeader", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeader) < 0) __PYX_ERR(0, 1935, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantHeader) < 0) __PYX_ERR(0, 1935, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantHeader = &__pyx_type_5pysam_7libcbcf_VariantHeader; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantHeaderRecord) < 0) __PYX_ERR(0, 1093, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantHeaderRecord) < 0) __PYX_ERR(0, 1229, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantHeaderRecord.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantHeaderRecord.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantHeaderRecord.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantHeaderRecord.tp_getattro = __Pyx_PyObject_GenericGetAttr; } #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeaderRecord, "__getitem__"); if (unlikely(!wrapper)) __PYX_ERR(0, 1093, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeaderRecord, "__getitem__"); if (unlikely(!wrapper)) __PYX_ERR(0, 1229, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__.doc = __pyx_doc_5pysam_7libcbcf_19VariantHeaderRecord_6__getitem__; @@ -79105,396 +89263,395 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (PyObject_SetAttrString(__pyx_m, "VariantHeaderRecord", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeaderRecord) < 0) __PYX_ERR(0, 1093, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantHeaderRecord) < 0) __PYX_ERR(0, 1093, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantHeaderRecord", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeaderRecord) < 0) __PYX_ERR(0, 1229, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantHeaderRecord) < 0) __PYX_ERR(0, 1229, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantHeaderRecord = &__pyx_type_5pysam_7libcbcf_VariantHeaderRecord; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantHeaderRecords) < 0) __PYX_ERR(0, 1259, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantHeaderRecords) < 0) __PYX_ERR(0, 1416, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantHeaderRecords.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantHeaderRecords.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantHeaderRecords.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantHeaderRecords.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "VariantHeaderRecords", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeaderRecords) < 0) __PYX_ERR(0, 1259, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantHeaderRecords) < 0) __PYX_ERR(0, 1259, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantHeaderRecords", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeaderRecords) < 0) __PYX_ERR(0, 1416, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantHeaderRecords) < 0) __PYX_ERR(0, 1416, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantHeaderRecords = &__pyx_type_5pysam_7libcbcf_VariantHeaderRecords; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantHeaderContigs) < 0) __PYX_ERR(0, 1584, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantHeaderContigs) < 0) __PYX_ERR(0, 1741, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantHeaderContigs.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantHeaderContigs.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantHeaderContigs.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantHeaderContigs.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "VariantHeaderContigs", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeaderContigs) < 0) __PYX_ERR(0, 1584, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantHeaderContigs) < 0) __PYX_ERR(0, 1584, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantHeaderContigs", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeaderContigs) < 0) __PYX_ERR(0, 1741, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantHeaderContigs) < 0) __PYX_ERR(0, 1741, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantHeaderContigs = &__pyx_type_5pysam_7libcbcf_VariantHeaderContigs; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantHeaderSamples) < 0) __PYX_ERR(0, 1721, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantHeaderSamples) < 0) __PYX_ERR(0, 1879, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantHeaderSamples.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantHeaderSamples.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantHeaderSamples.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantHeaderSamples.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "VariantHeaderSamples", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeaderSamples) < 0) __PYX_ERR(0, 1721, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantHeaderSamples) < 0) __PYX_ERR(0, 1721, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantHeaderSamples", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeaderSamples) < 0) __PYX_ERR(0, 1879, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantHeaderSamples) < 0) __PYX_ERR(0, 1879, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantHeaderSamples = &__pyx_type_5pysam_7libcbcf_VariantHeaderSamples; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantContig) < 0) __PYX_ERR(0, 1534, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantContig) < 0) __PYX_ERR(0, 1691, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantContig.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantContig.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantContig.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantContig.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "VariantContig", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantContig) < 0) __PYX_ERR(0, 1534, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantContig) < 0) __PYX_ERR(0, 1534, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantContig", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantContig) < 0) __PYX_ERR(0, 1691, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantContig) < 0) __PYX_ERR(0, 1691, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantContig = &__pyx_type_5pysam_7libcbcf_VariantContig; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantMetadata) < 0) __PYX_ERR(0, 1293, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantMetadata) < 0) __PYX_ERR(0, 1450, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantMetadata.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantMetadata.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantMetadata.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantMetadata.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "VariantMetadata", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantMetadata) < 0) __PYX_ERR(0, 1293, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantMetadata) < 0) __PYX_ERR(0, 1293, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantMetadata", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantMetadata) < 0) __PYX_ERR(0, 1450, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantMetadata) < 0) __PYX_ERR(0, 1450, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantMetadata = &__pyx_type_5pysam_7libcbcf_VariantMetadata; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantHeaderMetadata) < 0) __PYX_ERR(0, 1383, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantHeaderMetadata) < 0) __PYX_ERR(0, 1540, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantHeaderMetadata.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantHeaderMetadata.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantHeaderMetadata.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantHeaderMetadata.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "VariantHeaderMetadata", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeaderMetadata) < 0) __PYX_ERR(0, 1383, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantHeaderMetadata) < 0) __PYX_ERR(0, 1383, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantHeaderMetadata", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantHeaderMetadata) < 0) __PYX_ERR(0, 1540, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantHeaderMetadata) < 0) __PYX_ERR(0, 1540, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantHeaderMetadata = &__pyx_type_5pysam_7libcbcf_VariantHeaderMetadata; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantRecord) < 0) __PYX_ERR(0, 2542, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantRecord) < 0) __PYX_ERR(0, 2969, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantRecord.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantRecord.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantRecord.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantRecord.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "VariantRecord", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantRecord) < 0) __PYX_ERR(0, 2542, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantRecord) < 0) __PYX_ERR(0, 2542, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantRecord", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantRecord) < 0) __PYX_ERR(0, 2969, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantRecord) < 0) __PYX_ERR(0, 2969, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantRecord = &__pyx_type_5pysam_7libcbcf_VariantRecord; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantRecordFilter) < 0) __PYX_ERR(0, 1971, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantRecordFilter) < 0) __PYX_ERR(0, 2188, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantRecordFilter.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantRecordFilter.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantRecordFilter.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantRecordFilter.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "VariantRecordFilter", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantRecordFilter) < 0) __PYX_ERR(0, 1971, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantRecordFilter) < 0) __PYX_ERR(0, 1971, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantRecordFilter", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantRecordFilter) < 0) __PYX_ERR(0, 2188, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantRecordFilter) < 0) __PYX_ERR(0, 2188, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantRecordFilter = &__pyx_type_5pysam_7libcbcf_VariantRecordFilter; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantRecordFormat) < 0) __PYX_ERR(0, 2119, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantRecordFormat) < 0) __PYX_ERR(0, 2350, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantRecordFormat.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantRecordFormat.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantRecordFormat.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantRecordFormat.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "VariantRecordFormat", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantRecordFormat) < 0) __PYX_ERR(0, 2119, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantRecordFormat) < 0) __PYX_ERR(0, 2119, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantRecordFormat", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantRecordFormat) < 0) __PYX_ERR(0, 2350, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantRecordFormat) < 0) __PYX_ERR(0, 2350, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantRecordFormat = &__pyx_type_5pysam_7libcbcf_VariantRecordFormat; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantRecordInfo) < 0) __PYX_ERR(0, 2254, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantRecordInfo) < 0) __PYX_ERR(0, 2485, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantRecordInfo.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantRecordInfo.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantRecordInfo.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantRecordInfo.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "VariantRecordInfo", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantRecordInfo) < 0) __PYX_ERR(0, 2254, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantRecordInfo) < 0) __PYX_ERR(0, 2254, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantRecordInfo", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantRecordInfo) < 0) __PYX_ERR(0, 2485, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantRecordInfo) < 0) __PYX_ERR(0, 2485, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantRecordInfo = &__pyx_type_5pysam_7libcbcf_VariantRecordInfo; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantRecordSamples) < 0) __PYX_ERR(0, 2426, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantRecordSamples) < 0) __PYX_ERR(0, 2819, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantRecordSamples.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantRecordSamples.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantRecordSamples.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantRecordSamples.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "VariantRecordSamples", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantRecordSamples) < 0) __PYX_ERR(0, 2426, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantRecordSamples) < 0) __PYX_ERR(0, 2426, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantRecordSamples", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantRecordSamples) < 0) __PYX_ERR(0, 2819, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantRecordSamples) < 0) __PYX_ERR(0, 2819, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantRecordSamples = &__pyx_type_5pysam_7libcbcf_VariantRecordSamples; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantRecordSample) < 0) __PYX_ERR(0, 2886, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantRecordSample) < 0) __PYX_ERR(0, 3357, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantRecordSample.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantRecordSample.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantRecordSample.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantRecordSample.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "VariantRecordSample", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantRecordSample) < 0) __PYX_ERR(0, 2886, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantRecordSample) < 0) __PYX_ERR(0, 2886, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantRecordSample", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantRecordSample) < 0) __PYX_ERR(0, 3357, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantRecordSample) < 0) __PYX_ERR(0, 3357, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantRecordSample = &__pyx_type_5pysam_7libcbcf_VariantRecordSample; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_BaseIndex) < 0) __PYX_ERR(0, 3062, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_BaseIndex) < 0) __PYX_ERR(0, 3564, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_BaseIndex.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_BaseIndex.tp_dictoffset && __pyx_type_5pysam_7libcbcf_BaseIndex.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_BaseIndex.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "BaseIndex", (PyObject *)&__pyx_type_5pysam_7libcbcf_BaseIndex) < 0) __PYX_ERR(0, 3062, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_BaseIndex) < 0) __PYX_ERR(0, 3062, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "BaseIndex", (PyObject *)&__pyx_type_5pysam_7libcbcf_BaseIndex) < 0) __PYX_ERR(0, 3564, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_BaseIndex) < 0) __PYX_ERR(0, 3564, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_BaseIndex = &__pyx_type_5pysam_7libcbcf_BaseIndex; __pyx_type_5pysam_7libcbcf_BCFIndex.tp_base = __pyx_ptype_5pysam_7libcbcf_BaseIndex; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_BCFIndex) < 0) __PYX_ERR(0, 3129, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_BCFIndex) < 0) __PYX_ERR(0, 3653, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_BCFIndex.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_BCFIndex.tp_dictoffset && __pyx_type_5pysam_7libcbcf_BCFIndex.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_BCFIndex.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "BCFIndex", (PyObject *)&__pyx_type_5pysam_7libcbcf_BCFIndex) < 0) __PYX_ERR(0, 3129, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_BCFIndex) < 0) __PYX_ERR(0, 3129, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "BCFIndex", (PyObject *)&__pyx_type_5pysam_7libcbcf_BCFIndex) < 0) __PYX_ERR(0, 3653, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_BCFIndex) < 0) __PYX_ERR(0, 3653, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_BCFIndex = &__pyx_type_5pysam_7libcbcf_BCFIndex; __pyx_type_5pysam_7libcbcf_TabixIndex.tp_base = __pyx_ptype_5pysam_7libcbcf_BaseIndex; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_TabixIndex) < 0) __PYX_ERR(0, 3168, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_TabixIndex) < 0) __PYX_ERR(0, 3692, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_TabixIndex.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_TabixIndex.tp_dictoffset && __pyx_type_5pysam_7libcbcf_TabixIndex.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_TabixIndex.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "TabixIndex", (PyObject *)&__pyx_type_5pysam_7libcbcf_TabixIndex) < 0) __PYX_ERR(0, 3168, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_TabixIndex) < 0) __PYX_ERR(0, 3168, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "TabixIndex", (PyObject *)&__pyx_type_5pysam_7libcbcf_TabixIndex) < 0) __PYX_ERR(0, 3692, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_TabixIndex) < 0) __PYX_ERR(0, 3692, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_TabixIndex = &__pyx_type_5pysam_7libcbcf_TabixIndex; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_BaseIterator) < 0) __PYX_ERR(0, 3209, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_BaseIterator) < 0) __PYX_ERR(0, 3733, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_BaseIterator.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_BaseIterator.tp_dictoffset && __pyx_type_5pysam_7libcbcf_BaseIterator.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_BaseIterator.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "BaseIterator", (PyObject *)&__pyx_type_5pysam_7libcbcf_BaseIterator) < 0) __PYX_ERR(0, 3209, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_BaseIterator) < 0) __PYX_ERR(0, 3209, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "BaseIterator", (PyObject *)&__pyx_type_5pysam_7libcbcf_BaseIterator) < 0) __PYX_ERR(0, 3733, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_BaseIterator) < 0) __PYX_ERR(0, 3733, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_BaseIterator = &__pyx_type_5pysam_7libcbcf_BaseIterator; __pyx_type_5pysam_7libcbcf_BCFIterator.tp_base = __pyx_ptype_5pysam_7libcbcf_BaseIterator; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_BCFIterator) < 0) __PYX_ERR(0, 3223, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_BCFIterator) < 0) __PYX_ERR(0, 3747, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_BCFIterator.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_BCFIterator.tp_dictoffset && __pyx_type_5pysam_7libcbcf_BCFIterator.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_BCFIterator.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "BCFIterator", (PyObject *)&__pyx_type_5pysam_7libcbcf_BCFIterator) < 0) __PYX_ERR(0, 3223, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_BCFIterator) < 0) __PYX_ERR(0, 3223, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "BCFIterator", (PyObject *)&__pyx_type_5pysam_7libcbcf_BCFIterator) < 0) __PYX_ERR(0, 3747, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_BCFIterator) < 0) __PYX_ERR(0, 3747, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_BCFIterator = &__pyx_type_5pysam_7libcbcf_BCFIterator; __pyx_type_5pysam_7libcbcf_TabixIterator.tp_base = __pyx_ptype_5pysam_7libcbcf_BaseIterator; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_TabixIterator) < 0) __PYX_ERR(0, 3312, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_TabixIterator) < 0) __PYX_ERR(0, 3833, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_TabixIterator.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_TabixIterator.tp_dictoffset && __pyx_type_5pysam_7libcbcf_TabixIterator.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_TabixIterator.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttrString(__pyx_m, "TabixIterator", (PyObject *)&__pyx_type_5pysam_7libcbcf_TabixIterator) < 0) __PYX_ERR(0, 3312, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_TabixIterator) < 0) __PYX_ERR(0, 3312, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "TabixIterator", (PyObject *)&__pyx_type_5pysam_7libcbcf_TabixIterator) < 0) __PYX_ERR(0, 3833, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_TabixIterator) < 0) __PYX_ERR(0, 3833, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_TabixIterator = &__pyx_type_5pysam_7libcbcf_TabixIterator; __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_vtabptr_5pysam_7libcbcf_VariantFile = &__pyx_vtable_5pysam_7libcbcf_VariantFile; __pyx_vtable_5pysam_7libcbcf_VariantFile.__pyx_base = *__pyx_vtabptr_5pysam_10libchtslib_HTSFile; - __pyx_vtable_5pysam_7libcbcf_VariantFile.new_record = (struct __pyx_obj_5pysam_7libcbcf_VariantRecord *(*)(struct __pyx_obj_5pysam_7libcbcf_VariantFile *, int __pyx_skip_dispatch))__pyx_f_5pysam_7libcbcf_11VariantFile_new_record; __pyx_vtable_5pysam_7libcbcf_VariantFile.write = (int (*)(struct __pyx_obj_5pysam_7libcbcf_VariantFile *, struct __pyx_obj_5pysam_7libcbcf_VariantRecord *, int __pyx_skip_dispatch))__pyx_f_5pysam_7libcbcf_11VariantFile_write; __pyx_type_5pysam_7libcbcf_VariantFile.tp_base = __pyx_ptype_5pysam_10libchtslib_HTSFile; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantFile) < 0) __PYX_ERR(0, 3410, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf_VariantFile) < 0) __PYX_ERR(0, 3935, __pyx_L1_error) __pyx_type_5pysam_7libcbcf_VariantFile.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf_VariantFile.tp_dictoffset && __pyx_type_5pysam_7libcbcf_VariantFile.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf_VariantFile.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_7libcbcf_VariantFile.tp_dict, __pyx_vtabptr_5pysam_7libcbcf_VariantFile) < 0) __PYX_ERR(0, 3410, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "VariantFile", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantFile) < 0) __PYX_ERR(0, 3410, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantFile) < 0) __PYX_ERR(0, 3410, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_7libcbcf_VariantFile.tp_dict, __pyx_vtabptr_5pysam_7libcbcf_VariantFile) < 0) __PYX_ERR(0, 3935, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VariantFile", (PyObject *)&__pyx_type_5pysam_7libcbcf_VariantFile) < 0) __PYX_ERR(0, 3935, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_7libcbcf_VariantFile) < 0) __PYX_ERR(0, 3935, __pyx_L1_error) __pyx_ptype_5pysam_7libcbcf_VariantFile = &__pyx_type_5pysam_7libcbcf_VariantFile; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysam_7libcbcf_char_array_to_tuple) < 0) __PYX_ERR(0, 171, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysam_7libcbcf_char_array_to_tuple) < 0) __PYX_ERR(0, 250, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysam_7libcbcf_char_array_to_tuple.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysam_7libcbcf_char_array_to_tuple.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysam_7libcbcf_char_array_to_tuple.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysam_7libcbcf_char_array_to_tuple.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysam_7libcbcf_char_array_to_tuple = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct____pyx_f_5pysam_7libcbcf_char_array_to_tuple; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_1_genexpr) < 0) __PYX_ERR(0, 175, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_1_genexpr) < 0) __PYX_ERR(0, 254, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_1_genexpr.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_1_genexpr.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_1_genexpr.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_1_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_1_genexpr = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_1_genexpr; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object) < 0) __PYX_ERR(0, 181, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object) < 0) __PYX_ERR(0, 260, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_2___pyx_f_5pysam_7libcbcf_bcf_array_to_object; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_3_genexpr) < 0) __PYX_ERR(0, 199, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_3_genexpr) < 0) __PYX_ERR(0, 285, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_3_genexpr.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_3_genexpr.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_3_genexpr.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_3_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_3_genexpr = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_3_genexpr; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_4___pyx_f_5pysam_7libcbcf_bcf_object_to_array) < 0) __PYX_ERR(0, 246, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_4___pyx_f_5pysam_7libcbcf_bcf_object_to_array) < 0) __PYX_ERR(0, 331, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_4___pyx_f_5pysam_7libcbcf_bcf_object_to_array.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_4___pyx_f_5pysam_7libcbcf_bcf_object_to_array.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_4___pyx_f_5pysam_7libcbcf_bcf_object_to_array.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_4___pyx_f_5pysam_7libcbcf_bcf_object_to_array.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_4___pyx_f_5pysam_7libcbcf_bcf_object_to_array = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_4___pyx_f_5pysam_7libcbcf_bcf_object_to_array; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_5_genexpr) < 0) __PYX_ERR(0, 258, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_5_genexpr) < 0) __PYX_ERR(0, 343, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_5_genexpr.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_5_genexpr.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_5_genexpr.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_5_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_5_genexpr = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_5_genexpr; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values) < 0) __PYX_ERR(0, 469, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values) < 0) __PYX_ERR(0, 554, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_6___pyx_f_5pysam_7libcbcf_bcf_check_values; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_7_genexpr) < 0) __PYX_ERR(0, 506, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_7_genexpr) < 0) __PYX_ERR(0, 593, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_7_genexpr.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_7_genexpr.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_7_genexpr.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_7_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_7_genexpr = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_7_genexpr; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_8___get__) < 0) __PYX_ERR(0, 1119, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_8___get__) < 0) __PYX_ERR(0, 1255, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_8___get__.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_8___get__.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_8___get__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_8___get__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_8___get__ = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_8___get__; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_9_genexpr) < 0) __PYX_ERR(0, 1125, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_9_genexpr) < 0) __PYX_ERR(0, 1261, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_9_genexpr.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_9_genexpr.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_9_genexpr.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_9_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_9_genexpr = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_9_genexpr; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_10___iter__) < 0) __PYX_ERR(0, 1148, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_10___iter__) < 0) __PYX_ERR(0, 1284, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_10___iter__.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_10___iter__.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_10___iter__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_10___iter__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_10___iter__ = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_10___iter__; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_11_itervalues) < 0) __PYX_ERR(0, 1176, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_11_itervalues) < 0) __PYX_ERR(0, 1312, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_11_itervalues.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_11_itervalues.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_11_itervalues.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_11_itervalues.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_11_itervalues = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_11_itervalues; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_12_iteritems) < 0) __PYX_ERR(0, 1186, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_12_iteritems) < 0) __PYX_ERR(0, 1322, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_12_iteritems.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_12_iteritems.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_12_iteritems.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_12_iteritems.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_12_iteritems = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_12_iteritems; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_13___iter__) < 0) __PYX_ERR(0, 1276, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_13___iter__) < 0) __PYX_ERR(0, 1433, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_13___iter__.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_13___iter__.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_13___iter__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_13___iter__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_13___iter__ = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_13___iter__; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_14___iter__) < 0) __PYX_ERR(0, 1466, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_14___iter__) < 0) __PYX_ERR(0, 1623, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_14___iter__.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_14___iter__.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_14___iter__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_14___iter__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_14___iter__ = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_14___iter__; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_15_itervalues) < 0) __PYX_ERR(0, 1495, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_15_itervalues) < 0) __PYX_ERR(0, 1652, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_15_itervalues.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_15_itervalues.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_15_itervalues.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_15_itervalues.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_15_itervalues = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_15_itervalues; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_16_iteritems) < 0) __PYX_ERR(0, 1500, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_16_iteritems) < 0) __PYX_ERR(0, 1657, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_16_iteritems.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_16_iteritems.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_16_iteritems.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_16_iteritems.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_16_iteritems = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_16_iteritems; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_17___iter__) < 0) __PYX_ERR(0, 1646, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_17___iter__) < 0) __PYX_ERR(0, 1803, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_17___iter__.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_17___iter__.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_17___iter__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_17___iter__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_17___iter__ = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_17___iter__; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_18_itervalues) < 0) __PYX_ERR(0, 1675, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_18_itervalues) < 0) __PYX_ERR(0, 1832, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_18_itervalues.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_18_itervalues.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_18_itervalues.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_18_itervalues.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_18_itervalues = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_18_itervalues; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_19_iteritems) < 0) __PYX_ERR(0, 1680, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_19_iteritems) < 0) __PYX_ERR(0, 1837, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_19_iteritems.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_19_iteritems.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_19_iteritems.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_19_iteritems.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_19_iteritems = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_19_iteritems; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_20___iter__) < 0) __PYX_ERR(0, 1742, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_20___iter__) < 0) __PYX_ERR(0, 1900, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_20___iter__.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_20___iter__.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_20___iter__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_20___iter__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_20___iter__ = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_20___iter__; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_21___iter__) < 0) __PYX_ERR(0, 2056, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_21___iter__) < 0) __PYX_ERR(0, 2273, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_21___iter__.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_21___iter__.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_21___iter__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_21___iter__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_21___iter__ = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_21___iter__; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_22_itervalues) < 0) __PYX_ERR(0, 2081, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_22_itervalues) < 0) __PYX_ERR(0, 2298, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_22_itervalues.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_22_itervalues.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_22_itervalues.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_22_itervalues.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_22_itervalues = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_22_itervalues; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_23_iteritems) < 0) __PYX_ERR(0, 2086, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_23_iteritems) < 0) __PYX_ERR(0, 2303, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_23_iteritems.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_23_iteritems.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_23_iteritems.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_23_iteritems.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_23_iteritems = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_23_iteritems; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_24___iter__) < 0) __PYX_ERR(0, 2186, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_24___iter__) < 0) __PYX_ERR(0, 2417, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_24___iter__.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_24___iter__.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_24___iter__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_24___iter__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_24___iter__ = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_24___iter__; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_25_itervalues) < 0) __PYX_ERR(0, 2215, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_25_itervalues) < 0) __PYX_ERR(0, 2446, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_25_itervalues.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_25_itervalues.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_25_itervalues.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_25_itervalues.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_25_itervalues = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_25_itervalues; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_26_iteritems) < 0) __PYX_ERR(0, 2220, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_26_iteritems) < 0) __PYX_ERR(0, 2451, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_26_iteritems.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_26_iteritems.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_26_iteritems.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_26_iteritems.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_26_iteritems = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_26_iteritems; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_27___iter__) < 0) __PYX_ERR(0, 2339, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_27___iter__) < 0) __PYX_ERR(0, 2623, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_27___iter__.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_27___iter__.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_27___iter__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_27___iter__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_27___iter__ = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_27___iter__; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_28_itervalues) < 0) __PYX_ERR(0, 2373, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_28_itervalues) < 0) __PYX_ERR(0, 2690, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_28_itervalues.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_28_itervalues.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_28_itervalues.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_28_itervalues.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_28_itervalues = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_28_itervalues; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_29_iteritems) < 0) __PYX_ERR(0, 2384, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_29_iteritems) < 0) __PYX_ERR(0, 2708, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_29_iteritems.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_29_iteritems.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_29_iteritems.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_29_iteritems.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_29_iteritems = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_29_iteritems; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_30___iter__) < 0) __PYX_ERR(0, 2458, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_30___iter__) < 0) __PYX_ERR(0, 2851, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_30___iter__.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_30___iter__.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_30___iter__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_30___iter__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_30___iter__ = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_30___iter__; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_31_itervalues) < 0) __PYX_ERR(0, 2495, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_31_itervalues) < 0) __PYX_ERR(0, 2888, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_31_itervalues.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_31_itervalues.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_31_itervalues.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_31_itervalues.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_31_itervalues = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_31_itervalues; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_32_iteritems) < 0) __PYX_ERR(0, 2504, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_32_iteritems) < 0) __PYX_ERR(0, 2897, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_32_iteritems.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_32_iteritems.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_32_iteritems.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_32_iteritems.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_32_iteritems = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_32_iteritems; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_33___iter__) < 0) __PYX_ERR(0, 2988, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_33___iter__) < 0) __PYX_ERR(0, 3459, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_33___iter__.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_33___iter__.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_33___iter__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_33___iter__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_33___iter__ = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_33___iter__; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_34_itervalues) < 0) __PYX_ERR(0, 3017, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_34_itervalues) < 0) __PYX_ERR(0, 3488, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_34_itervalues.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_34_itervalues.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_34_itervalues.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_34_itervalues.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_34_itervalues = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_34_itervalues; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_35_iteritems) < 0) __PYX_ERR(0, 3022, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_35_iteritems) < 0) __PYX_ERR(0, 3493, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_35_iteritems.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_35_iteritems.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_35_iteritems.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_35_iteritems.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_35_iteritems = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_35_iteritems; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_36_itervalues) < 0) __PYX_ERR(0, 3101, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_36_itervalues) < 0) __PYX_ERR(0, 3603, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_36_itervalues.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_36_itervalues.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_36_itervalues.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_36_itervalues.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_5pysam_7libcbcf___pyx_scope_struct_36_itervalues = &__pyx_type_5pysam_7libcbcf___pyx_scope_struct_36_itervalues; - if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_37_iteritems) < 0) __PYX_ERR(0, 3106, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_7libcbcf___pyx_scope_struct_37_iteritems) < 0) __PYX_ERR(0, 3608, __pyx_L1_error) __pyx_type_5pysam_7libcbcf___pyx_scope_struct_37_iteritems.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_7libcbcf___pyx_scope_struct_37_iteritems.tp_dictoffset && __pyx_type_5pysam_7libcbcf___pyx_scope_struct_37_iteritems.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_7libcbcf___pyx_scope_struct_37_iteritems.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; @@ -79633,7 +89790,6 @@ static int __pyx_pymod_exec_libcbcf(PyObject *__pyx_pyinit_module) { __Pyx_TraceDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; __Pyx_RefNannyDeclarations #if CYTHON_PEP489_MULTI_PHASE_INIT if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0; @@ -79760,49 +89916,28 @@ if (!__Pyx_RefNanny) { /* "pysam/libcbcf.pyx":104 * * - * from warnings import warn # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_warn); - __Pyx_GIVEREF(__pyx_n_s_warn); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_warn); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_warnings, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 104, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_warn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_warn, __pyx_t_1) < 0) __PYX_ERR(0, 104, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pysam/libcbcf.pyx":107 - * - * * __all__ = ['VariantFile', # <<<<<<<<<<<<<< * 'VariantHeader', * 'VariantHeaderRecord', */ - __pyx_t_2 = PyList_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 107, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyList_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_VariantFile); __Pyx_GIVEREF(__pyx_n_s_VariantFile); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_VariantFile); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_VariantFile); __Pyx_INCREF(__pyx_n_s_VariantHeader); __Pyx_GIVEREF(__pyx_n_s_VariantHeader); - PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_VariantHeader); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_VariantHeader); __Pyx_INCREF(__pyx_n_s_VariantHeaderRecord); __Pyx_GIVEREF(__pyx_n_s_VariantHeaderRecord); - PyList_SET_ITEM(__pyx_t_2, 2, __pyx_n_s_VariantHeaderRecord); + PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_VariantHeaderRecord); __Pyx_INCREF(__pyx_n_s_VariantRecord); __Pyx_GIVEREF(__pyx_n_s_VariantRecord); - PyList_SET_ITEM(__pyx_t_2, 3, __pyx_n_s_VariantRecord); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_2) < 0) __PYX_ERR(0, 107, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_VariantRecord); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 104, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":117 + /* "pysam/libcbcf.pyx":114 * ######################################################################## * * cdef int MAX_POS = 2 << 29 # <<<<<<<<<<<<<< @@ -79811,164 +89946,233 @@ if (!__Pyx_RefNanny) { */ __pyx_v_5pysam_7libcbcf_MAX_POS = 0x40000000; - /* "pysam/libcbcf.pyx":118 + /* "pysam/libcbcf.pyx":115 * * cdef int MAX_POS = 2 << 29 * cdef tuple VALUE_TYPES = ('Flag', 'Integer', 'Float', 'String') # <<<<<<<<<<<<<< * cdef tuple METADATA_TYPES = ('FILTER', 'INFO', 'FORMAT', 'CONTIG', 'STRUCTURED', 'GENERIC') * cdef tuple METADATA_LENGTHS = ('FIXED', 'VARIABLE', 'A', 'G', 'R') */ - __Pyx_INCREF(__pyx_tuple__234); + __Pyx_INCREF(__pyx_tuple__252); __Pyx_XGOTREF(__pyx_v_5pysam_7libcbcf_VALUE_TYPES); - __Pyx_DECREF_SET(__pyx_v_5pysam_7libcbcf_VALUE_TYPES, __pyx_tuple__234); - __Pyx_GIVEREF(__pyx_tuple__234); + __Pyx_DECREF_SET(__pyx_v_5pysam_7libcbcf_VALUE_TYPES, __pyx_tuple__252); + __Pyx_GIVEREF(__pyx_tuple__252); - /* "pysam/libcbcf.pyx":119 + /* "pysam/libcbcf.pyx":116 * cdef int MAX_POS = 2 << 29 * cdef tuple VALUE_TYPES = ('Flag', 'Integer', 'Float', 'String') * cdef tuple METADATA_TYPES = ('FILTER', 'INFO', 'FORMAT', 'CONTIG', 'STRUCTURED', 'GENERIC') # <<<<<<<<<<<<<< * cdef tuple METADATA_LENGTHS = ('FIXED', 'VARIABLE', 'A', 'G', 'R') * */ - __Pyx_INCREF(__pyx_tuple__235); + __Pyx_INCREF(__pyx_tuple__253); __Pyx_XGOTREF(__pyx_v_5pysam_7libcbcf_METADATA_TYPES); - __Pyx_DECREF_SET(__pyx_v_5pysam_7libcbcf_METADATA_TYPES, __pyx_tuple__235); - __Pyx_GIVEREF(__pyx_tuple__235); + __Pyx_DECREF_SET(__pyx_v_5pysam_7libcbcf_METADATA_TYPES, __pyx_tuple__253); + __Pyx_GIVEREF(__pyx_tuple__253); - /* "pysam/libcbcf.pyx":120 + /* "pysam/libcbcf.pyx":117 * cdef tuple VALUE_TYPES = ('Flag', 'Integer', 'Float', 'String') * cdef tuple METADATA_TYPES = ('FILTER', 'INFO', 'FORMAT', 'CONTIG', 'STRUCTURED', 'GENERIC') * cdef tuple METADATA_LENGTHS = ('FIXED', 'VARIABLE', 'A', 'G', 'R') # <<<<<<<<<<<<<< * * */ - __Pyx_INCREF(__pyx_tuple__236); + __Pyx_INCREF(__pyx_tuple__254); __Pyx_XGOTREF(__pyx_v_5pysam_7libcbcf_METADATA_LENGTHS); - __Pyx_DECREF_SET(__pyx_v_5pysam_7libcbcf_METADATA_LENGTHS, __pyx_tuple__236); - __Pyx_GIVEREF(__pyx_tuple__236); + __Pyx_DECREF_SET(__pyx_v_5pysam_7libcbcf_METADATA_LENGTHS, __pyx_tuple__254); + __Pyx_GIVEREF(__pyx_tuple__254); - /* "pysam/libcbcf.pyx":137 + /* "pysam/libcbcf.pyx":134 + * ######################################################################## + * + * cdef object _nothing = object() # <<<<<<<<<<<<<< + * + * ######################################################################## + */ + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_object); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_v_5pysam_7libcbcf__nothing); + __Pyx_DECREF_SET(__pyx_v_5pysam_7libcbcf__nothing, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libcbcf.pyx":141 * ######################################################################## * * cdef dict bcf_str_cache = {} # <<<<<<<<<<<<<< * * cdef inline bcf_str_cache_get_charptr(const char* s): */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 137, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(__pyx_v_5pysam_7libcbcf_bcf_str_cache); - __Pyx_DECREF_SET(__pyx_v_5pysam_7libcbcf_bcf_str_cache, ((PyObject*)__pyx_t_2)); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; + __Pyx_DECREF_SET(__pyx_v_5pysam_7libcbcf_bcf_str_cache, ((PyObject*)__pyx_t_1)); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libcbcf.pyx":1209 + /* "pysam/libcbcf.pyx":1356 + * self[k] = v + * + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * try: + * value = self[key] + */ + __Pyx_INCREF(__pyx_v_5pysam_7libcbcf__nothing); + __pyx_k__61 = __pyx_v_5pysam_7libcbcf__nothing; + __Pyx_GIVEREF(__pyx_v_5pysam_7libcbcf__nothing); + + /* "pysam/libcbcf.pyx":1367 * * # Mappings are not hashable by default, but subclasses can change this * __hash__ = None # <<<<<<<<<<<<<< * * #TODO: implement __richcmp__ */ - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderRecord->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 1209, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderRecord->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 1367, __pyx_L1_error) PyType_Modified(__pyx_ptype_5pysam_7libcbcf_VariantHeaderRecord); - /* "pysam/libcbcf.pyx":1281 + /* "pysam/libcbcf.pyx":1438 * yield makeVariantHeaderRecord(self.header, self.header.ptr.hrec[i]) * * __hash__ = None # <<<<<<<<<<<<<< * * */ - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderRecords->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 1281, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderRecords->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 1438, __pyx_L1_error) PyType_Modified(__pyx_ptype_5pysam_7libcbcf_VariantHeaderRecords); - /* "pysam/libcbcf.pyx":1518 + /* "pysam/libcbcf.pyx":1675 * * # Mappings are not hashable by default, but subclasses can change this * __hash__ = None # <<<<<<<<<<<<<< * * #TODO: implement __richcmp__ */ - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderMetadata->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 1518, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderMetadata->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 1675, __pyx_L1_error) PyType_Modified(__pyx_ptype_5pysam_7libcbcf_VariantHeaderMetadata); - /* "pysam/libcbcf.pyx":1698 + /* "pysam/libcbcf.pyx":1855 * * # Mappings are not hashable by default, but subclasses can change this * __hash__ = None # <<<<<<<<<<<<<< * * #TODO: implement __richcmp__ */ - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderContigs->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 1698, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderContigs->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 1855, __pyx_L1_error) PyType_Modified(__pyx_ptype_5pysam_7libcbcf_VariantHeaderContigs); - /* "pysam/libcbcf.pyx":1758 + /* "pysam/libcbcf.pyx":1916 * * # Mappings are not hashable by default, but subclasses can change this * __hash__ = None # <<<<<<<<<<<<<< * * #TODO: implement __richcmp__ */ - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderSamples->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 1758, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantHeaderSamples->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 1916, __pyx_L1_error) PyType_Modified(__pyx_ptype_5pysam_7libcbcf_VariantHeaderSamples); - /* "pysam/libcbcf.pyx":2104 + /* "pysam/libcbcf.pyx":2335 * * # Mappings are not hashable by default, but subclasses can change this * __hash__ = None # <<<<<<<<<<<<<< * * #TODO: implement __richcmp__ */ - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordFilter->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 2104, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordFilter->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 2335, __pyx_L1_error) PyType_Modified(__pyx_ptype_5pysam_7libcbcf_VariantRecordFilter); - /* "pysam/libcbcf.pyx":2238 + /* "pysam/libcbcf.pyx":2469 * * # Mappings are not hashable by default, but subclasses can change this * __hash__ = None # <<<<<<<<<<<<<< * * #TODO: implement __richcmp__ */ - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordFormat->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 2238, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordFormat->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 2469, __pyx_L1_error) PyType_Modified(__pyx_ptype_5pysam_7libcbcf_VariantRecordFormat); - /* "pysam/libcbcf.pyx":2411 + /* "pysam/libcbcf.pyx":2753 + * self[k] = v + * + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * cdef bcf_hdr_t *hdr = self.record.header.ptr + * cdef bcf1_t *r = self.record.ptr + */ + __Pyx_INCREF(__pyx_v_5pysam_7libcbcf__nothing); + __pyx_k__133 = __pyx_v_5pysam_7libcbcf__nothing; + __Pyx_GIVEREF(__pyx_v_5pysam_7libcbcf__nothing); + + /* "pysam/libcbcf.pyx":2806 * * # Mappings are not hashable by default, but subclasses can change this * __hash__ = None # <<<<<<<<<<<<<< * - * #TODO: implement __richcmp__ + * */ - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordInfo->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 2411, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordInfo->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 2806, __pyx_L1_error) PyType_Modified(__pyx_ptype_5pysam_7libcbcf_VariantRecordInfo); - /* "pysam/libcbcf.pyx":2526 + /* "pysam/libcbcf.pyx":2930 + * self[k] = v + * + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * try: + * value = self[key] + */ + __Pyx_INCREF(__pyx_v_5pysam_7libcbcf__nothing); + __pyx_k__140 = __pyx_v_5pysam_7libcbcf__nothing; + __Pyx_GIVEREF(__pyx_v_5pysam_7libcbcf__nothing); + + /* "pysam/libcbcf.pyx":2955 * * # Mappings are not hashable by default, but subclasses can change this * __hash__ = None # <<<<<<<<<<<<<< * - * #TODO: implement __richcmp__ + * */ - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordSamples->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 2526, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordSamples->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 2955, __pyx_L1_error) PyType_Modified(__pyx_ptype_5pysam_7libcbcf_VariantRecordSamples); - /* "pysam/libcbcf.pyx":3040 + /* "pysam/libcbcf.pyx":3522 + * self[k] = v + * + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * try: + * value = self[key] + */ + __Pyx_INCREF(__pyx_v_5pysam_7libcbcf__nothing); + __pyx_k__180 = __pyx_v_5pysam_7libcbcf__nothing; + __Pyx_GIVEREF(__pyx_v_5pysam_7libcbcf__nothing); + + /* "pysam/libcbcf.pyx":3544 * * # Mappings are not hashable by default, but subclasses can change this * __hash__ = None # <<<<<<<<<<<<<< * - * #TODO: implement __richcmp__ + * */ - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordSample->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 3040, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_VariantRecordSample->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 3544, __pyx_L1_error) PyType_Modified(__pyx_ptype_5pysam_7libcbcf_VariantRecordSample); - /* "pysam/libcbcf.pyx":3124 + /* "pysam/libcbcf.pyx":3637 + * self[k] = v + * + * def pop(self, key, default=_nothing): # <<<<<<<<<<<<<< + * try: + * value = self[key] + */ + __Pyx_INCREF(__pyx_v_5pysam_7libcbcf__nothing); + __pyx_k__182 = __pyx_v_5pysam_7libcbcf__nothing; + __Pyx_GIVEREF(__pyx_v_5pysam_7libcbcf__nothing); + + /* "pysam/libcbcf.pyx":3648 * * # Mappings are not hashable by default, but subclasses can change this * __hash__ = None # <<<<<<<<<<<<<< * * #TODO: implement __richcmp__ */ - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_BaseIndex->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 3124, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_7libcbcf_BaseIndex->tp_dict, __pyx_n_s_hash, Py_None) < 0) __PYX_ERR(0, 3648, __pyx_L1_error) PyType_Modified(__pyx_ptype_5pysam_7libcbcf_BaseIndex); /* "(tree fragment)":1 @@ -79976,10 +90180,10 @@ if (!__Pyx_RefNanny) { * if __pyx_checksum != 0x099fb99: * from pickle import PickleError as __pyx_PickleError */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_1__pyx_unpickle_VariantHeaderRecords, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantHeaderReco, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_1__pyx_unpickle_VariantHeaderRecords, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantHeaderReco, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":9 * __pyx_unpickle_VariantHeaderRecords__set_state( __pyx_result, __pyx_state) @@ -79988,20 +90192,20 @@ if (!__Pyx_RefNanny) { * __pyx_result.header = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_3__pyx_unpickle_VariantMetadata, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantMetadata, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_3__pyx_unpickle_VariantMetadata, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantMetadata, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":1 * def __pyx_unpickle_VariantHeaderMetadata(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0xed5e66b: * from pickle import PickleError as __pyx_PickleError */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_5__pyx_unpickle_VariantHeaderMetadata, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantHeaderMeta, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_5__pyx_unpickle_VariantHeaderMetadata, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantHeaderMeta, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":9 * __pyx_unpickle_VariantHeaderMetadata__set_state( __pyx_result, __pyx_state) @@ -80010,20 +90214,20 @@ if (!__Pyx_RefNanny) { * __pyx_result.header = __pyx_state[0]; __pyx_result.type = __pyx_state[1] * if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'): */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_7__pyx_unpickle_VariantContig, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantContig, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_7__pyx_unpickle_VariantContig, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantContig, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":1 * def __pyx_unpickle_VariantHeaderContigs(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x099fb99: * from pickle import PickleError as __pyx_PickleError */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_9__pyx_unpickle_VariantHeaderContigs, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantHeaderCont, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_9__pyx_unpickle_VariantHeaderContigs, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantHeaderCont, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":9 * __pyx_unpickle_VariantHeaderContigs__set_state( __pyx_result, __pyx_state) @@ -80032,20 +90236,20 @@ if (!__Pyx_RefNanny) { * __pyx_result.header = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_11__pyx_unpickle_VariantHeaderSamples, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantHeaderSamp, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_11__pyx_unpickle_VariantHeaderSamples, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantHeaderSamp, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":1 * def __pyx_unpickle_VariantRecordFilter(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0xde17f0f: * from pickle import PickleError as __pyx_PickleError */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_13__pyx_unpickle_VariantRecordFilter, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantRecordFilt, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_13__pyx_unpickle_VariantRecordFilter, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantRecordFilt, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":9 * __pyx_unpickle_VariantRecordFilter__set_state( __pyx_result, __pyx_state) @@ -80054,20 +90258,20 @@ if (!__Pyx_RefNanny) { * __pyx_result.record = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_15__pyx_unpickle_VariantRecordFormat, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantRecordForm, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_15__pyx_unpickle_VariantRecordFormat, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantRecordForm, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":1 * def __pyx_unpickle_VariantRecordInfo(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0xde17f0f: * from pickle import PickleError as __pyx_PickleError */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_17__pyx_unpickle_VariantRecordInfo, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantRecordInfo, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_17__pyx_unpickle_VariantRecordInfo, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantRecordInfo, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":9 * __pyx_unpickle_VariantRecordInfo__set_state( __pyx_result, __pyx_state) @@ -80076,20 +90280,20 @@ if (!__Pyx_RefNanny) { * __pyx_result.record = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_19__pyx_unpickle_VariantRecordSamples, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantRecordSamp, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_19__pyx_unpickle_VariantRecordSamples, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantRecordSamp, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":1 * def __pyx_unpickle_VariantRecordSample(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x5d6ff7b: * from pickle import PickleError as __pyx_PickleError */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_21__pyx_unpickle_VariantRecordSample, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantRecordSamp_2, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_21__pyx_unpickle_VariantRecordSample, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_VariantRecordSamp_2, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":9 * __pyx_unpickle_VariantRecordSample__set_state( __pyx_result, __pyx_state) @@ -80098,20 +90302,20 @@ if (!__Pyx_RefNanny) { * __pyx_result.index = __pyx_state[0]; __pyx_result.record = __pyx_state[1] * if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'): */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_23__pyx_unpickle_BaseIndex, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_BaseIndex, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_7libcbcf_23__pyx_unpickle_BaseIndex, NULL, __pyx_n_s_pysam_libcbcf); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_BaseIndex, __pyx_t_1) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pysam/libcbcf.pyx":1 * # cython: embedsignature=True # <<<<<<<<<<<<<< * # cython: profile=True * ############################################################################### */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "array.pxd":161 * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) @@ -80127,7 +90331,6 @@ if (!__Pyx_RefNanny) { goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); if (__pyx_m) { if (__pyx_d) { __Pyx_AddTraceback("init pysam.libcbcf", 0, __pyx_lineno, __pyx_filename); @@ -80310,6 +90513,156 @@ static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const cha } #endif +/* None */ +static CYTHON_INLINE long __Pyx_div_long(long a, long b) { + long q = a / b; + long r = a - q*b; + q -= ((r != 0) & ((r ^ b) < 0)); + return q; +} + +/* PyObjectCall */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *result; + ternaryfunc call = func->ob_type->tp_call; + if (unlikely(!call)) + return PyObject_Call(func, arg, kw); + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + result = (*call)(func, arg, kw); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyIntBinop */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { + #if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(op1))) { + const long b = intval; + long x; + long a = PyInt_AS_LONG(op1); + x = (long)((unsigned long)a + b); + if (likely((x^a) >= 0 || (x^b) >= 0)) + return PyInt_FromLong(x); + return PyLong_Type.tp_as_number->nb_add(op1, op2); + } + #endif + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(PyLong_CheckExact(op1))) { + const long b = intval; + long a, x; +#ifdef HAVE_LONG_LONG + const PY_LONG_LONG llb = intval; + PY_LONG_LONG lla, llx; +#endif + const digit* digits = ((PyLongObject*)op1)->ob_digit; + const Py_ssize_t size = Py_SIZE(op1); + if (likely(__Pyx_sst_abs(size) <= 1)) { + a = likely(size) ? digits[0] : 0; + if (size == -1) a = -a; + } else { + switch (size) { + case -2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case -3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case -4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + default: return PyLong_Type.tp_as_number->nb_add(op1, op2); + } + } + x = a + b; + return PyLong_FromLong(x); +#ifdef HAVE_LONG_LONG + long_long: + llx = lla + llb; + return PyLong_FromLongLong(llx); +#endif + + + } + #endif + if (PyFloat_CheckExact(op1)) { + const long b = intval; + double a = PyFloat_AS_DOUBLE(op1); + double result; + PyFPE_START_PROTECT("add", return NULL) + result = ((double)a) + (double)b; + PyFPE_END_PROTECT(result) + return PyFloat_FromDouble(result); + } + return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2); +} +#endif + /* WriteUnraisableException */ static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename, @@ -80352,6 +90705,165 @@ static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, #endif } +/* RaiseException */ +#if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, + CYTHON_UNUSED PyObject *cause) { + __Pyx_PyThreadState_declare + Py_XINCREF(type); + if (!value || value == Py_None) + value = NULL; + else + Py_INCREF(value); + if (!tb || tb == Py_None) + tb = NULL; + else { + Py_INCREF(tb); + if (!PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + } + if (PyType_Check(type)) { +#if CYTHON_COMPILING_IN_PYPY + if (!value) { + Py_INCREF(Py_None); + value = Py_None; + } +#endif + PyErr_NormalizeException(&type, &value, &tb); + } else { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + value = type; + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + } + __Pyx_PyThreadState_assign + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} +#else +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + PyObject* owned_instance = NULL; + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (PyExceptionClass_Check(type)) { + PyObject *instance_class = NULL; + if (value && PyExceptionInstance_Check(value)) { + instance_class = (PyObject*) Py_TYPE(value); + if (instance_class != type) { + int is_subclass = PyObject_IsSubclass(instance_class, type); + if (!is_subclass) { + instance_class = NULL; + } else if (unlikely(is_subclass == -1)) { + goto bad; + } else { + type = instance_class; + } + } + } + if (!instance_class) { + PyObject *args; + if (!value) + args = PyTuple_New(0); + else if (PyTuple_Check(value)) { + Py_INCREF(value); + args = value; + } else + args = PyTuple_Pack(1, value); + if (!args) + goto bad; + owned_instance = PyObject_Call(type, args, NULL); + Py_DECREF(args); + if (!owned_instance) + goto bad; + value = owned_instance; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto bad; + } + } + } else { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } + if (cause) { + PyObject *fixed_cause; + if (cause == Py_None) { + fixed_cause = NULL; + } else if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + PyException_SetCause(value, fixed_cause); + } + PyErr_SetObject(type, value); + if (tb) { +#if CYTHON_COMPILING_IN_PYPY + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#else + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } +#endif + } +bad: + Py_XDECREF(owned_instance); + return; +} +#endif + /* GetException */ #if CYTHON_FAST_THREAD_STATE static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { @@ -80500,25 +91012,77 @@ static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname); } -/* PyObjectCall */ +/* UnpackUnboundCMethod */ + static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) { + PyObject *method; + method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name); + if (unlikely(!method)) + return -1; + target->method = method; +#if CYTHON_COMPILING_IN_CPYTHON + #if PY_MAJOR_VERSION >= 3 + if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type))) + #endif + { + PyMethodDescrObject *descr = (PyMethodDescrObject*) method; + target->func = descr->d_method->ml_meth; + target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST); + } +#endif + return 0; +} + +/* CallUnboundCMethod1 */ #if CYTHON_COMPILING_IN_CPYTHON -static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { - PyObject *result; - ternaryfunc call = func->ob_type->tp_call; - if (unlikely(!call)) - return PyObject_Call(func, arg, kw); - if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) - return NULL; - result = (*call)(func, arg, kw); - Py_LeaveRecursiveCall(); - if (unlikely(!result) && unlikely(!PyErr_Occurred())) { - PyErr_SetString( - PyExc_SystemError, - "NULL result without error in PyObject_Call"); +static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) { + if (likely(cfunc->func)) { + int flag = cfunc->flag; + if (flag == METH_O) { + return (*(cfunc->func))(self, arg); + } else if (PY_VERSION_HEX >= 0x030600B1 && flag == METH_FASTCALL) { + if (PY_VERSION_HEX >= 0x030700A0) { + return (*(__Pyx_PyCFunctionFast)cfunc->func)(self, &arg, 1); + } else { + return (*(__Pyx_PyCFunctionFastWithKeywords)cfunc->func)(self, &arg, 1, NULL); + } + } else if (PY_VERSION_HEX >= 0x030700A0 && flag == (METH_FASTCALL | METH_KEYWORDS)) { + return (*(__Pyx_PyCFunctionFastWithKeywords)cfunc->func)(self, &arg, 1, NULL); + } } - return result; + return __Pyx__CallUnboundCMethod1(cfunc, self, arg); } #endif +static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){ + PyObject *args, *result = NULL; + if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL; +#if CYTHON_COMPILING_IN_CPYTHON + if (cfunc->func && (cfunc->flag & METH_VARARGS)) { + args = PyTuple_New(1); + if (unlikely(!args)) goto bad; + Py_INCREF(arg); + PyTuple_SET_ITEM(args, 0, arg); + if (cfunc->flag & METH_KEYWORDS) + result = (*(PyCFunctionWithKeywords)cfunc->func)(self, args, NULL); + else + result = (*cfunc->func)(self, args); + } else { + args = PyTuple_New(2); + if (unlikely(!args)) goto bad; + Py_INCREF(self); + PyTuple_SET_ITEM(args, 0, self); + Py_INCREF(arg); + PyTuple_SET_ITEM(args, 1, arg); + result = __Pyx_PyObject_Call(cfunc->method, args, NULL); + } +#else + args = PyTuple_Pack(2, self, arg); + if (unlikely(!args)) goto bad; + result = __Pyx_PyObject_Call(cfunc->method, args, NULL); +#endif +bad: + Py_XDECREF(args); + return result; +} /* PyCFunctionFastCall */ #if CYTHON_FAST_PYCCALL @@ -80787,165 +91351,6 @@ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name return 0; } -/* RaiseException */ - #if PY_MAJOR_VERSION < 3 -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, - CYTHON_UNUSED PyObject *cause) { - __Pyx_PyThreadState_declare - Py_XINCREF(type); - if (!value || value == Py_None) - value = NULL; - else - Py_INCREF(value); - if (!tb || tb == Py_None) - tb = NULL; - else { - Py_INCREF(tb); - if (!PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto raise_error; - } - } - if (PyType_Check(type)) { -#if CYTHON_COMPILING_IN_PYPY - if (!value) { - Py_INCREF(Py_None); - value = Py_None; - } -#endif - PyErr_NormalizeException(&type, &value, &tb); - } else { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto raise_error; - } - value = type; - type = (PyObject*) Py_TYPE(type); - Py_INCREF(type); - if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto raise_error; - } - } - __Pyx_PyThreadState_assign - __Pyx_ErrRestore(type, value, tb); - return; -raise_error: - Py_XDECREF(value); - Py_XDECREF(type); - Py_XDECREF(tb); - return; -} -#else -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { - PyObject* owned_instance = NULL; - if (tb == Py_None) { - tb = 0; - } else if (tb && !PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto bad; - } - if (value == Py_None) - value = 0; - if (PyExceptionInstance_Check(type)) { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto bad; - } - value = type; - type = (PyObject*) Py_TYPE(value); - } else if (PyExceptionClass_Check(type)) { - PyObject *instance_class = NULL; - if (value && PyExceptionInstance_Check(value)) { - instance_class = (PyObject*) Py_TYPE(value); - if (instance_class != type) { - int is_subclass = PyObject_IsSubclass(instance_class, type); - if (!is_subclass) { - instance_class = NULL; - } else if (unlikely(is_subclass == -1)) { - goto bad; - } else { - type = instance_class; - } - } - } - if (!instance_class) { - PyObject *args; - if (!value) - args = PyTuple_New(0); - else if (PyTuple_Check(value)) { - Py_INCREF(value); - args = value; - } else - args = PyTuple_Pack(1, value); - if (!args) - goto bad; - owned_instance = PyObject_Call(type, args, NULL); - Py_DECREF(args); - if (!owned_instance) - goto bad; - value = owned_instance; - if (!PyExceptionInstance_Check(value)) { - PyErr_Format(PyExc_TypeError, - "calling %R should have returned an instance of " - "BaseException, not %R", - type, Py_TYPE(value)); - goto bad; - } - } - } else { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto bad; - } - if (cause) { - PyObject *fixed_cause; - if (cause == Py_None) { - fixed_cause = NULL; - } else if (PyExceptionClass_Check(cause)) { - fixed_cause = PyObject_CallObject(cause, NULL); - if (fixed_cause == NULL) - goto bad; - } else if (PyExceptionInstance_Check(cause)) { - fixed_cause = cause; - Py_INCREF(fixed_cause); - } else { - PyErr_SetString(PyExc_TypeError, - "exception causes must derive from " - "BaseException"); - goto bad; - } - PyException_SetCause(value, fixed_cause); - } - PyErr_SetObject(type, value); - if (tb) { -#if CYTHON_COMPILING_IN_PYPY - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); - Py_INCREF(tb); - PyErr_Restore(tmp_type, tmp_value, tb); - Py_XDECREF(tmp_tb); -#else - PyThreadState *tstate = __Pyx_PyThreadState_Current; - PyObject* tmp_tb = tstate->curexc_traceback; - if (tb != tmp_tb) { - Py_INCREF(tb); - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_tb); - } -#endif - } -bad: - Py_XDECREF(owned_instance); - return; -} -#endif - /* GetItemInt */ static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; @@ -81002,51 +91407,203 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, return r; } } - else if (PyTuple_CheckExact(o)) { - Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); - if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, n); - Py_INCREF(r); - return r; + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } else { + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_item)) { + if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { + Py_ssize_t l = m->sq_length(o); + if (likely(l >= 0)) { + i += l; + } else { + if (!PyErr_ExceptionMatches(PyExc_OverflowError)) + return NULL; + PyErr_Clear(); + } + } + return m->sq_item(o, i); + } + } +#else + if (is_list || PySequence_Check(o)) { + return PySequence_GetItem(o, i); + } +#endif + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + +/* StringJoin */ + #if !CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) { + return PyObject_CallMethodObjArgs(sep, __pyx_n_s_join, values, NULL); +} +#endif + +/* BytesEquals */ + static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ + static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; } - } else { - PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; - if (likely(m && m->sq_item)) { - if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { - Py_ssize_t l = m->sq_length(o); - if (likely(l >= 0)) { - i += l; - } else { - if (!PyErr_ExceptionMatches(PyExc_OverflowError)) - return NULL; - PyErr_Clear(); - } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; } - return m->sq_item(o, i); } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; } -#else - if (is_list || PySequence_Check(o)) { - return PySequence_GetItem(o, i); - } +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); #endif - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } -/* StringJoin */ - #if !CYTHON_COMPILING_IN_CPYTHON -static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) { - return PyObject_CallMethodObjArgs(sep, __pyx_n_s_join, values, NULL); -} +/* PyObjectSetAttrStr */ + #if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_setattro)) + return tp->tp_setattro(obj, attr_name, value); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_setattr)) + return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value); #endif - -/* None */ - static CYTHON_INLINE long __Pyx_div_long(long a, long b) { - long q = a / b; - long r = a - q*b; - q -= ((r != 0) & ((r ^ b) < 0)); - return q; + return PyObject_SetAttr(obj, attr_name, value); } +#endif /* KeywordStringCheck */ static int __Pyx_CheckKeywordStrings( @@ -81088,53 +91645,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* value return 0; } -/* BytesEquals */ - static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { -#if CYTHON_COMPILING_IN_PYPY - return PyObject_RichCompareBool(s1, s2, equals); -#else - if (s1 == s2) { - return (equals == Py_EQ); - } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { - const char *ps1, *ps2; - Py_ssize_t length = PyBytes_GET_SIZE(s1); - if (length != PyBytes_GET_SIZE(s2)) - return (equals == Py_NE); - ps1 = PyBytes_AS_STRING(s1); - ps2 = PyBytes_AS_STRING(s2); - if (ps1[0] != ps2[0]) { - return (equals == Py_NE); - } else if (length == 1) { - return (equals == Py_EQ); - } else { - int result; -#if CYTHON_USE_UNICODE_INTERNALS - Py_hash_t hash1, hash2; - hash1 = ((PyBytesObject*)s1)->ob_shash; - hash2 = ((PyBytesObject*)s2)->ob_shash; - if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { - return (equals == Py_NE); - } -#endif - result = memcmp(ps1, ps2, (size_t)length); - return (equals == Py_EQ) ? (result == 0) : (result != 0); - } - } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { - return (equals == Py_NE); - } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { - return (equals == Py_NE); - } else { - int result; - PyObject* py_result = PyObject_RichCompare(s1, s2, equals); - if (!py_result) - return -1; - result = __Pyx_PyObject_IsTrue(py_result); - Py_DECREF(py_result); - return result; - } -#endif -} - /* RaiseDoubleKeywords */ static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, @@ -81352,6 +91862,93 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { } #endif +/* RaiseTooManyValuesToUnpack */ + static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { + PyErr_Format(PyExc_ValueError, + "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected); +} + +/* RaiseNeedMoreValuesToUnpack */ + static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { + PyErr_Format(PyExc_ValueError, + "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack", + index, (index == 1) ? "" : "s"); +} + +/* IterFinish */ + static CYTHON_INLINE int __Pyx_IterFinish(void) { +#if CYTHON_FAST_THREAD_STATE + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject* exc_type = tstate->curexc_type; + if (unlikely(exc_type)) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) { + PyObject *exc_value, *exc_tb; + exc_value = tstate->curexc_value; + exc_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; + Py_DECREF(exc_type); + Py_XDECREF(exc_value); + Py_XDECREF(exc_tb); + return 0; + } else { + return -1; + } + } + return 0; +#else + if (unlikely(PyErr_Occurred())) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { + PyErr_Clear(); + return 0; + } else { + return -1; + } + } + return 0; +#endif +} + +/* UnpackItemEndCheck */ + static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { + if (unlikely(retval)) { + Py_DECREF(retval); + __Pyx_RaiseTooManyValuesError(expected); + return -1; + } else { + return __Pyx_IterFinish(); + } + return 0; +} + +/* CallUnboundCMethod0 */ + static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) { + PyObject *args, *result = NULL; + if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL; +#if CYTHON_ASSUME_SAFE_MACROS + args = PyTuple_New(1); + if (unlikely(!args)) goto bad; + Py_INCREF(self); + PyTuple_SET_ITEM(args, 0, self); +#else + args = PyTuple_Pack(1, self); + if (unlikely(!args)) goto bad; +#endif + result = __Pyx_PyObject_Call(cfunc->method, args, NULL); + Py_DECREF(args); +bad: + return result; +} + +/* py_dict_items */ + static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) { + if (PY_MAJOR_VERSION >= 3) + return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_items, d); + else + return PyDict_Items(d); +} + /* GetAttr */ static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { #if CYTHON_USE_TYPE_SLOTS @@ -81407,53 +92004,6 @@ static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject return result; } -/* UnpackUnboundCMethod */ - static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) { - PyObject *method; - method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name); - if (unlikely(!method)) - return -1; - target->method = method; -#if CYTHON_COMPILING_IN_CPYTHON - #if PY_MAJOR_VERSION >= 3 - if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type))) - #endif - { - PyMethodDescrObject *descr = (PyMethodDescrObject*) method; - target->func = descr->d_method->ml_meth; - target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST); - } -#endif - return 0; -} - -/* CallUnboundCMethod0 */ - static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) { - PyObject *args, *result = NULL; - if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL; -#if CYTHON_ASSUME_SAFE_MACROS - args = PyTuple_New(1); - if (unlikely(!args)) goto bad; - Py_INCREF(self); - PyTuple_SET_ITEM(args, 0, self); -#else - args = PyTuple_Pack(1, self); - if (unlikely(!args)) goto bad; -#endif - result = __Pyx_PyObject_Call(cfunc->method, args, NULL); - Py_DECREF(args); -bad: - return result; -} - -/* py_dict_items */ - static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) { - if (PY_MAJOR_VERSION >= 3) - return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_items, d); - else - return PyDict_Items(d); -} - /* ArgTypeTest */ static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) { @@ -81475,105 +92025,6 @@ static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject return 0; } -/* UnicodeEquals */ - static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { -#if CYTHON_COMPILING_IN_PYPY - return PyObject_RichCompareBool(s1, s2, equals); -#else -#if PY_MAJOR_VERSION < 3 - PyObject* owned_ref = NULL; -#endif - int s1_is_unicode, s2_is_unicode; - if (s1 == s2) { - goto return_eq; - } - s1_is_unicode = PyUnicode_CheckExact(s1); - s2_is_unicode = PyUnicode_CheckExact(s2); -#if PY_MAJOR_VERSION < 3 - if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { - owned_ref = PyUnicode_FromObject(s2); - if (unlikely(!owned_ref)) - return -1; - s2 = owned_ref; - s2_is_unicode = 1; - } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { - owned_ref = PyUnicode_FromObject(s1); - if (unlikely(!owned_ref)) - return -1; - s1 = owned_ref; - s1_is_unicode = 1; - } else if (((!s2_is_unicode) & (!s1_is_unicode))) { - return __Pyx_PyBytes_Equals(s1, s2, equals); - } -#endif - if (s1_is_unicode & s2_is_unicode) { - Py_ssize_t length; - int kind; - void *data1, *data2; - if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) - return -1; - length = __Pyx_PyUnicode_GET_LENGTH(s1); - if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { - goto return_ne; - } -#if CYTHON_USE_UNICODE_INTERNALS - { - Py_hash_t hash1, hash2; - #if CYTHON_PEP393_ENABLED - hash1 = ((PyASCIIObject*)s1)->hash; - hash2 = ((PyASCIIObject*)s2)->hash; - #else - hash1 = ((PyUnicodeObject*)s1)->hash; - hash2 = ((PyUnicodeObject*)s2)->hash; - #endif - if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { - goto return_ne; - } - } -#endif - kind = __Pyx_PyUnicode_KIND(s1); - if (kind != __Pyx_PyUnicode_KIND(s2)) { - goto return_ne; - } - data1 = __Pyx_PyUnicode_DATA(s1); - data2 = __Pyx_PyUnicode_DATA(s2); - if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { - goto return_ne; - } else if (length == 1) { - goto return_eq; - } else { - int result = memcmp(data1, data2, (size_t)(length * kind)); - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_EQ) ? (result == 0) : (result != 0); - } - } else if ((s1 == Py_None) & s2_is_unicode) { - goto return_ne; - } else if ((s2 == Py_None) & s1_is_unicode) { - goto return_ne; - } else { - int result; - PyObject* py_result = PyObject_RichCompare(s1, s2, equals); - if (!py_result) - return -1; - result = __Pyx_PyObject_IsTrue(py_result); - Py_DECREF(py_result); - return result; - } -return_eq: - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_EQ); -return_ne: - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); - #endif - return (equals == Py_NE); -#endif -} - /* DictGetItem */ #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { @@ -81593,77 +92044,74 @@ static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { } #endif -/* ExtTypeTest */ - static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { - if (unlikely(!type)) { - PyErr_SetString(PyExc_SystemError, "Missing type object"); - return 0; +/* CallUnboundCMethod2 */ + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1 +static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2) { + if (likely(cfunc->func)) { + PyObject *args[2] = {arg1, arg2}; + if (cfunc->flag == METH_FASTCALL) { + #if PY_VERSION_HEX >= 0x030700A0 + return (*(__Pyx_PyCFunctionFast)cfunc->func)(self, args, 2); + #else + return (*(__Pyx_PyCFunctionFastWithKeywords)cfunc->func)(self, args, 2, NULL); + #endif + } + #if PY_VERSION_HEX >= 0x030700A0 + if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS)) + return (*(__Pyx_PyCFunctionFastWithKeywords)cfunc->func)(self, args, 2, NULL); + #endif } - if (likely(__Pyx_TypeCheck(obj, type))) - return 1; - PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", - Py_TYPE(obj)->tp_name, type->tp_name); - return 0; -} - -/* RaiseTooManyValuesToUnpack */ - static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { - PyErr_Format(PyExc_ValueError, - "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected); -} - -/* RaiseNeedMoreValuesToUnpack */ - static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { - PyErr_Format(PyExc_ValueError, - "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack", - index, (index == 1) ? "" : "s"); + return __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2); } - -/* IterFinish */ - static CYTHON_INLINE int __Pyx_IterFinish(void) { -#if CYTHON_FAST_THREAD_STATE - PyThreadState *tstate = __Pyx_PyThreadState_Current; - PyObject* exc_type = tstate->curexc_type; - if (unlikely(exc_type)) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) { - PyObject *exc_value, *exc_tb; - exc_value = tstate->curexc_value; - exc_tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; - Py_DECREF(exc_type); - Py_XDECREF(exc_value); - Py_XDECREF(exc_tb); - return 0; - } else { - return -1; - } +#endif +static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2){ + PyObject *args, *result = NULL; + if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL; +#if CYTHON_COMPILING_IN_CPYTHON + if (cfunc->func && (cfunc->flag & METH_VARARGS)) { + args = PyTuple_New(2); + if (unlikely(!args)) goto bad; + Py_INCREF(arg1); + PyTuple_SET_ITEM(args, 0, arg1); + Py_INCREF(arg2); + PyTuple_SET_ITEM(args, 1, arg2); + if (cfunc->flag & METH_KEYWORDS) + result = (*(PyCFunctionWithKeywords)cfunc->func)(self, args, NULL); + else + result = (*cfunc->func)(self, args); + } else { + args = PyTuple_New(3); + if (unlikely(!args)) goto bad; + Py_INCREF(self); + PyTuple_SET_ITEM(args, 0, self); + Py_INCREF(arg1); + PyTuple_SET_ITEM(args, 1, arg1); + Py_INCREF(arg2); + PyTuple_SET_ITEM(args, 2, arg2); + result = __Pyx_PyObject_Call(cfunc->method, args, NULL); } - return 0; #else - if (unlikely(PyErr_Occurred())) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { - PyErr_Clear(); - return 0; - } else { - return -1; - } - } - return 0; + args = PyTuple_Pack(3, self, arg1, arg2); + if (unlikely(!args)) goto bad; + result = __Pyx_PyObject_Call(cfunc->method, args, NULL); #endif +bad: + Py_XDECREF(args); + return result; } -/* UnpackItemEndCheck */ - static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { - if (unlikely(retval)) { - Py_DECREF(retval); - __Pyx_RaiseTooManyValuesError(expected); - return -1; +/* py_dict_pop */ + static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX > 0x030600B3 + if ((1)) { + return _PyDict_Pop(d, key, default_value); + } else +#endif + if (default_value) { + return __Pyx_CallUnboundCMethod2(&__pyx_umethod_PyDict_Type_pop, d, key, default_value); } else { - return __Pyx_IterFinish(); + return __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_pop, d, key); } - return 0; } /* SetItemInt */ @@ -81714,20 +92162,6 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v); } -/* PyObjectSetAttrStr */ - #if CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { - PyTypeObject* tp = Py_TYPE(obj); - if (likely(tp->tp_setattro)) - return tp->tp_setattro(obj, attr_name, value); -#if PY_MAJOR_VERSION < 3 - if (likely(tp->tp_setattr)) - return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value); -#endif - return PyObject_SetAttr(obj, attr_name, value); -} -#endif - /* PyIntBinop */ #if !CYTHON_COMPILING_IN_PYPY static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { @@ -81850,264 +92284,17 @@ static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_U } #endif -/* PyIntBinop */ - #if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { - #if PY_MAJOR_VERSION < 3 - if (likely(PyInt_CheckExact(op1))) { - const long b = intval; - long x; - long a = PyInt_AS_LONG(op1); - x = (long)((unsigned long)a + b); - if (likely((x^a) >= 0 || (x^b) >= 0)) - return PyInt_FromLong(x); - return PyLong_Type.tp_as_number->nb_add(op1, op2); - } - #endif - #if CYTHON_USE_PYLONG_INTERNALS - if (likely(PyLong_CheckExact(op1))) { - const long b = intval; - long a, x; -#ifdef HAVE_LONG_LONG - const PY_LONG_LONG llb = intval; - PY_LONG_LONG lla, llx; -#endif - const digit* digits = ((PyLongObject*)op1)->ob_digit; - const Py_ssize_t size = Py_SIZE(op1); - if (likely(__Pyx_sst_abs(size) <= 1)) { - a = likely(size) ? digits[0] : 0; - if (size == -1) a = -a; - } else { - switch (size) { - case -2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { - a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { - a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case -3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { - a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { - a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case -4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { - a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { - a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - default: return PyLong_Type.tp_as_number->nb_add(op1, op2); - } - } - x = a + b; - return PyLong_FromLong(x); -#ifdef HAVE_LONG_LONG - long_long: - llx = lla + llb; - return PyLong_FromLongLong(llx); -#endif - - - } - #endif - if (PyFloat_CheckExact(op1)) { - const long b = intval; - double a = PyFloat_AS_DOUBLE(op1); - double result; - PyFPE_START_PROTECT("add", return NULL) - result = ((double)a) + (double)b; - PyFPE_END_PROTECT(result) - return PyFloat_FromDouble(result); - } - return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2); -} -#endif - -/* CallUnboundCMethod1 */ - #if CYTHON_COMPILING_IN_CPYTHON -static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) { - if (likely(cfunc->func)) { - int flag = cfunc->flag; - if (flag == METH_O) { - return (*(cfunc->func))(self, arg); - } else if (PY_VERSION_HEX >= 0x030600B1 && flag == METH_FASTCALL) { - if (PY_VERSION_HEX >= 0x030700A0) { - return (*(__Pyx_PyCFunctionFast)cfunc->func)(self, &arg, 1); - } else { - return (*(__Pyx_PyCFunctionFastWithKeywords)cfunc->func)(self, &arg, 1, NULL); - } - } else if (PY_VERSION_HEX >= 0x030700A0 && flag == (METH_FASTCALL | METH_KEYWORDS)) { - return (*(__Pyx_PyCFunctionFastWithKeywords)cfunc->func)(self, &arg, 1, NULL); - } - } - return __Pyx__CallUnboundCMethod1(cfunc, self, arg); -} -#endif -static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){ - PyObject *args, *result = NULL; - if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL; -#if CYTHON_COMPILING_IN_CPYTHON - if (cfunc->func && (cfunc->flag & METH_VARARGS)) { - args = PyTuple_New(1); - if (unlikely(!args)) goto bad; - Py_INCREF(arg); - PyTuple_SET_ITEM(args, 0, arg); - if (cfunc->flag & METH_KEYWORDS) - result = (*(PyCFunctionWithKeywords)cfunc->func)(self, args, NULL); - else - result = (*cfunc->func)(self, args); - } else { - args = PyTuple_New(2); - if (unlikely(!args)) goto bad; - Py_INCREF(self); - PyTuple_SET_ITEM(args, 0, self); - Py_INCREF(arg); - PyTuple_SET_ITEM(args, 1, arg); - result = __Pyx_PyObject_Call(cfunc->method, args, NULL); - } -#else - args = PyTuple_Pack(2, self, arg); - if (unlikely(!args)) goto bad; - result = __Pyx_PyObject_Call(cfunc->method, args, NULL); -#endif -bad: - Py_XDECREF(args); - return result; -} - -/* CallUnboundCMethod2 */ - #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1 -static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2) { - if (likely(cfunc->func)) { - PyObject *args[2] = {arg1, arg2}; - if (cfunc->flag == METH_FASTCALL) { - #if PY_VERSION_HEX >= 0x030700A0 - return (*(__Pyx_PyCFunctionFast)cfunc->func)(self, args, 2); - #else - return (*(__Pyx_PyCFunctionFastWithKeywords)cfunc->func)(self, args, 2, NULL); - #endif - } - #if PY_VERSION_HEX >= 0x030700A0 - if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS)) - return (*(__Pyx_PyCFunctionFastWithKeywords)cfunc->func)(self, args, 2, NULL); - #endif - } - return __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2); -} -#endif -static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2){ - PyObject *args, *result = NULL; - if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL; -#if CYTHON_COMPILING_IN_CPYTHON - if (cfunc->func && (cfunc->flag & METH_VARARGS)) { - args = PyTuple_New(2); - if (unlikely(!args)) goto bad; - Py_INCREF(arg1); - PyTuple_SET_ITEM(args, 0, arg1); - Py_INCREF(arg2); - PyTuple_SET_ITEM(args, 1, arg2); - if (cfunc->flag & METH_KEYWORDS) - result = (*(PyCFunctionWithKeywords)cfunc->func)(self, args, NULL); - else - result = (*cfunc->func)(self, args); - } else { - args = PyTuple_New(3); - if (unlikely(!args)) goto bad; - Py_INCREF(self); - PyTuple_SET_ITEM(args, 0, self); - Py_INCREF(arg1); - PyTuple_SET_ITEM(args, 1, arg1); - Py_INCREF(arg2); - PyTuple_SET_ITEM(args, 2, arg2); - result = __Pyx_PyObject_Call(cfunc->method, args, NULL); - } -#else - args = PyTuple_Pack(3, self, arg1, arg2); - if (unlikely(!args)) goto bad; - result = __Pyx_PyObject_Call(cfunc->method, args, NULL); -#endif -bad: - Py_XDECREF(args); - return result; -} - -/* dict_getitem_default */ - static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) { - PyObject* value; -#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY - value = PyDict_GetItemWithError(d, key); - if (unlikely(!value)) { - if (unlikely(PyErr_Occurred())) - return NULL; - value = default_value; - } - Py_INCREF(value); - if ((1)); -#else - if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) { - value = PyDict_GetItem(d, key); - if (unlikely(!value)) { - value = default_value; - } - Py_INCREF(value); - } -#endif - else { - if (default_value == Py_None) - value = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_get, d, key); - else - value = __Pyx_CallUnboundCMethod2(&__pyx_umethod_PyDict_Type_get, d, key, default_value); +/* ExtTypeTest */ + static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; } - return value; + if (likely(__Pyx_TypeCheck(obj, type))) + return 1; + PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", + Py_TYPE(obj)->tp_name, type->tp_name); + return 0; } /* SliceObject */ @@ -82792,24 +92979,24 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int8_t(int8_t value) { - const int8_t neg_one = (int8_t) -1, const_zero = (int8_t) 0; + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { - if (sizeof(int8_t) < sizeof(long)) { + if (sizeof(long) < sizeof(long)) { return PyInt_FromLong((long) value); - } else if (sizeof(int8_t) <= sizeof(unsigned long)) { + } else if (sizeof(long) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(int8_t) <= sizeof(unsigned PY_LONG_LONG)) { + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { - if (sizeof(int8_t) <= sizeof(long)) { + if (sizeof(long) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(int8_t) <= sizeof(PY_LONG_LONG)) { + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } @@ -82817,30 +93004,30 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(int8_t), + return _PyLong_FromByteArray(bytes, sizeof(long), little, !is_unsigned); } } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int16_t(int16_t value) { - const int16_t neg_one = (int16_t) -1, const_zero = (int16_t) 0; + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int8_t(int8_t value) { + const int8_t neg_one = (int8_t) -1, const_zero = (int8_t) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { - if (sizeof(int16_t) < sizeof(long)) { + if (sizeof(int8_t) < sizeof(long)) { return PyInt_FromLong((long) value); - } else if (sizeof(int16_t) <= sizeof(unsigned long)) { + } else if (sizeof(int8_t) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(int16_t) <= sizeof(unsigned PY_LONG_LONG)) { + } else if (sizeof(int8_t) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { - if (sizeof(int16_t) <= sizeof(long)) { + if (sizeof(int8_t) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(int16_t) <= sizeof(PY_LONG_LONG)) { + } else if (sizeof(int8_t) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } @@ -82848,30 +93035,30 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(int16_t), + return _PyLong_FromByteArray(bytes, sizeof(int8_t), little, !is_unsigned); } } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { - const long neg_one = (long) -1, const_zero = (long) 0; + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int16_t(int16_t value) { + const int16_t neg_one = (int16_t) -1, const_zero = (int16_t) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { - if (sizeof(long) < sizeof(long)) { + if (sizeof(int16_t) < sizeof(long)) { return PyInt_FromLong((long) value); - } else if (sizeof(long) <= sizeof(unsigned long)) { + } else if (sizeof(int16_t) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + } else if (sizeof(int16_t) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { - if (sizeof(long) <= sizeof(long)) { + if (sizeof(int16_t) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + } else if (sizeof(int16_t) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } @@ -82879,7 +93066,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(long), + return _PyLong_FromByteArray(bytes, sizeof(int16_t), little, !is_unsigned); } } diff --git a/pysam/libcbcf.pxd b/pysam/libcbcf.pxd index fc7f56c03..1d4129bce 100644 --- a/pysam/libcbcf.pxd +++ b/pysam/libcbcf.pxd @@ -38,45 +38,44 @@ from pysam.libchtslib cimport * cdef class VariantHeader(object): cdef bcf_hdr_t *ptr - cpdef VariantRecord new_record(self) cdef _subset_samples(self, include_samples) cdef class VariantHeaderRecord(object): - cdef VariantHeader header + cdef readonly VariantHeader header cdef bcf_hrec_t *ptr cdef class VariantHeaderRecords(object): - cdef VariantHeader header + cdef readonly VariantHeader header cdef class VariantHeaderContigs(object): - cdef VariantHeader header + cdef readonly VariantHeader header cdef class VariantHeaderSamples(object): - cdef VariantHeader header + cdef readonly VariantHeader header cdef class VariantContig(object): - cdef VariantHeader header + cdef readonly VariantHeader header cdef int id cdef class VariantMetadata(object): - cdef VariantHeader header + cdef readonly VariantHeader header cdef int type cdef int id cdef class VariantHeaderMetadata(object): - cdef VariantHeader header + cdef readonly VariantHeader header cdef int32_t type cdef class VariantRecord(object): - cdef VariantHeader header + cdef readonly VariantHeader header cdef bcf1_t *ptr @@ -107,7 +106,7 @@ cdef class BaseIndex(object): cdef class BCFIndex(BaseIndex): - cdef VariantHeader header + cdef readonly VariantHeader header cdef hts_idx_t *ptr @@ -139,6 +138,4 @@ cdef class VariantFile(HTSFile): cdef readonly bint is_reading # true if file has begun reading records cdef readonly bint header_written # true if header has already been written - cpdef VariantRecord new_record(self) - cpdef int write(self, VariantRecord record) except -1 diff --git a/pysam/libcbcf.pyx b/pysam/libcbcf.pyx index 8f4045152..b74ada136 100644 --- a/pysam/libcbcf.pyx +++ b/pysam/libcbcf.pyx @@ -101,9 +101,6 @@ from cpython.version cimport PY_MAJOR_VERSION from pysam.libchtslib cimport HTSFile, hisremote -from warnings import warn - - __all__ = ['VariantFile', 'VariantHeader', 'VariantHeaderRecord', @@ -129,6 +126,13 @@ from pysam.libcutils cimport force_bytes, force_str, charptr_to_str, charptr_to_ from pysam.libcutils cimport encode_filename, from_string_and_size +######################################################################## +######################################################################## +## Sentinel object +######################################################################## + +cdef object _nothing = object() + ######################################################################## ######################################################################## ## VCF/BCF string intern system @@ -154,6 +158,55 @@ cdef inline bcf_str_cache_get_charptr(const char* s): return val +######################################################################## +######################################################################## +## Genotype math +######################################################################## + +cdef int comb(int n, int k) except -1: + """Return binomial coeffient: n choose k + + >>> comb(5, 1) + 5 + >>> comb(5, 2) + 10 + >>> comb(2, 2) + 1 + >>> comb(100, 2) + 4950 + """ + if k > n: + return 0 + elif k == n: + return 1 + elif k > n // 2: + k = n - k + + cdef d, result + + d = result = n - k + 1 + for i in range(2, k + 1): + d += 1 + result *= d + result //= i + return result + + +cdef inline int bcf_geno_combinations(int ploidy, int alleles) except -1: + """Return the count of genotypes expected for the given ploidy and number of alleles. + + >>> bcf_geno_combinations(1, 2) + 2 + >>> bcf_geno_combinations(2, 2) + 3 + >>> bcf_geno_combinations(2, 3) + 6 + >>> bcf_geno_combinations(3, 2) + 4 + """ + return comb(alleles + ploidy - 1, ploidy) + + ######################################################################## ######################################################################## ## Low level type conversion helpers @@ -165,7 +218,33 @@ cdef inline bint check_header_id(bcf_hdr_t *hdr, int hl_type, int id): cdef inline int is_gt_fmt(bcf_hdr_t *hdr, int fmt_id): - return strcmp(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt_id), "GT") == 0 + return strcmp(bcf_hdr_int2id(hdr, BCF_DT_ID, fmt_id), 'GT') == 0 + + +cdef inline int bcf_genotype_count(bcf_hdr_t *hdr, bcf1_t *rec, int sample) except -1: + + if sample < 0: + raise ValueError('genotype is only valid as a format field') + + cdef int32_t *gt_arr = NULL + cdef int ngt = 0 + ngt = bcf_get_genotypes(hdr, rec, >_arr, &ngt) + + if ngt <= 0 or not gt_arr: + return 0 + + assert ngt % rec.n_sample == 0 + cdef int max_ploidy = ngt // rec.n_sample + cdef int32_t *gt = gt_arr + sample * max_ploidy + cdef int ploidy = 0 + + while ploidy < max_ploidy and gt[0] != bcf_int32_vector_end: + gt += 1 + ploidy += 1 + + free(gt_arr) + + return bcf_geno_combinations(ploidy, rec.n_allele) cdef tuple char_array_to_tuple(const char **a, ssize_t n, int free_after=0): @@ -185,19 +264,25 @@ cdef bcf_array_to_object(void *data, int type, ssize_t n, ssize_t count, int sca cdef int32_t *data32 cdef float *dataf cdef int i + cdef bytes b if not data or n <= 0: return None if type == BCF_BT_CHAR: datac = data - while n and datac[n-1] == bcf_str_vector_end: - n -= 1 - value = charptr_to_str_w_len(datac, n) if datac[0] != bcf_str_missing else None - # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. - value = tuple(v or None for v in value.split(',')) if value else () - # FIXME: Need to know length? Report errors? Pad with missing values? Not clear what to do. + if not n: + value = () + else: + # Check if at least one null terminator is present + if datac[n-1] == bcf_str_vector_end: + # If so, create a string up to the first null terminator + b = datac + else: + # Otherwise, copy the entire block + b = datac[:n] + value = tuple(v.decode('ascii') if v and v != bcf_str_missing else None for v in b.split(b',')) else: value = [] if type == BCF_BT_INT8: @@ -251,13 +336,13 @@ cdef bcf_object_to_array(values, void *data, int bt_type, ssize_t n, int vlen): cdef float *dataf cdef ssize_t i, value_count = len(values) - assert(value_count <= n) + assert value_count <= n if bt_type == BCF_BT_CHAR: if not isinstance(values, (str, bytes)): - values = b','.join(force_bytes(v) if v is not None else b'' for v in values) + values = b','.join(force_bytes(v) if v else bcf_str_missing for v in values) value_count = len(values) - assert(value_count <= n) + assert value_count <= n datac = data memcpy(datac, values, value_count) for i in range(value_count, n): @@ -392,7 +477,7 @@ cdef bcf_copy_expand_array(void *src_data, int src_type, ssize_t src_values, raise TypeError('unsupported types') -cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar): +cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *count, int *scalar, int sample): if record is None: raise ValueError('record must not be None') @@ -418,7 +503,7 @@ cdef bcf_get_value_count(VariantRecord record, int hl_type, int id, ssize_t *cou elif length == BCF_VL_A: count[0] = r.n_allele - 1 elif length == BCF_VL_G: - count[0] = r.n_allele * (r.n_allele + 1) // 2 + count[0] = bcf_genotype_count(hdr, r, sample) elif length == BCF_VL_VAR: count[0] = -1 else: @@ -435,7 +520,7 @@ cdef object bcf_info_get_value(VariantRecord record, const bcf_info_t *z): cdef ssize_t count cdef int scalar - bcf_get_value_count(record, BCF_HL_INFO, z.key, &count, &scalar) + bcf_get_value_count(record, BCF_HL_INFO, z.key, &count, &scalar, -1) if z.len == 0: if bcf_hdr_id2type(hdr, BCF_HL_INFO, z.key) == BCF_HT_FLAG: @@ -466,14 +551,15 @@ cdef object bcf_info_get_value(VariantRecord record, const bcf_info_t *z): return value -cdef object bcf_check_values(VariantRecord record, value, int hl_type, int ht_type, +cdef object bcf_check_values(VariantRecord record, value, int sample, + int hl_type, int ht_type, int id, int bt_type, ssize_t bt_len, ssize_t *value_count, int *scalar, int *realloc): if record is None: raise ValueError('record must not be None') - bcf_get_value_count(record, hl_type, id, value_count, scalar) + bcf_get_value_count(record, hl_type, id, value_count, scalar, sample) # Validate values now that we know the type and size values = (value,) if not isinstance(value, (list, tuple)) else value @@ -485,11 +571,12 @@ cdef object bcf_check_values(VariantRecord record, value, int hl_type, int ht_ty # KBJ: htslib lies about the cardinality of GT fields-- they're really VLEN (-1) value_count[0] = -1 - if value_count[0] != -1 and value_count[0] != len(values): + cdef int given = len(values) + if value_count[0] != -1 and value_count[0] != given: if scalar[0]: - raise TypeError('value expected to be scalar'.format(value_count[0])) + raise TypeError('value expected to be scalar, given len={}'.format(value_count[0], given)) else: - raise TypeError('values expected to be {:d}-tuple'.format(value_count[0])) + raise TypeError('values expected to be {}-tuple, given len={}'.format(value_count[0], given)) if ht_type == BCF_HT_REAL: for v in values: @@ -572,33 +659,29 @@ cdef bcf_info_set_value(VariantRecord record, key, value): cdef bcf_hdr_t *hdr = record.header.ptr cdef bcf1_t *r = record.ptr - cdef vdict_t *d - cdef khiter_t k cdef int info_id, info_type, scalar, dst_type, realloc, vlen = 0 cdef ssize_t i, value_count, alloc_len, alloc_size, dst_size if bcf_unpack(r, BCF_UN_INFO) < 0: raise ValueError('Error unpacking VariantRecord') - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) if info: info_id = info.key else: - d = hdr.dict[BCF_DT_ID] - k = kh_get_vdict(d, bkey) - - if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: - raise KeyError('unknown INFO') + info_id = bcf_header_get_info_id(hdr, bkey) - info_id = kh_val_vdict(d, k).id + if info_id < 0: + raise KeyError('unknown INFO: {}'.format(key)) if not check_header_id(hdr, BCF_HL_INFO, info_id): raise ValueError('Invalid header') info_type = bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) - values = bcf_check_values(record, value, BCF_HL_INFO, info_type, info_id, + values = bcf_check_values(record, value, -1, + BCF_HL_INFO, info_type, info_id, info.type if info else -1, info.len if info else -1, &value_count, &scalar, &realloc) @@ -611,13 +694,16 @@ cdef bcf_info_set_value(VariantRecord record, key, value): vlen = value_count < 0 value_count = len(values) + # DISABLED DUE TO ISSUES WITH THE CRAZY POINTERS # If we can, write updated values to existing allocated storage - if info and not realloc: + if 0 and info and not realloc: r.d.shared_dirty |= BCF1_DIRTY_INF if value_count == 0: info.len = 0 - # FIXME: Check if need to free vptr if info.len > 0? + if not info.vptr: + info.vptr = &info.v1.i + elif value_count == 1: # FIXME: Check if need to free vptr if info.len > 0? if info.type == BCF_BT_INT8 or info.type == BCF_BT_INT16 or info.type == BCF_BT_INT32: @@ -626,9 +712,13 @@ cdef bcf_info_set_value(VariantRecord record, key, value): bcf_object_to_array(values, &info.v1.f, BCF_BT_FLOAT, 1, vlen) else: raise TypeError('unsupported info type code') + info.len = 1 + if not info.vptr: + info.vptr = &info.v1.i else: bcf_object_to_array(values, info.vptr, info.type, info.len, vlen) + return alloc_len = max(1, value_count) @@ -665,13 +755,13 @@ cdef bcf_info_del_value(VariantRecord record, key): if bcf_unpack(r, BCF_UN_INFO) < 0: raise ValueError('Error unpacking VariantRecord') - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) if not info: raise KeyError(key) - bcf_get_value_count(record, BCF_HL_INFO, info.key, &value_count, &scalar) + bcf_get_value_count(record, BCF_HL_INFO, info.key, &value_count, &scalar, -1) if value_count <= 0: null_value = () @@ -695,16 +785,16 @@ cdef bcf_format_get_value(VariantRecordSample sample, key): if bcf_unpack(r, BCF_UN_ALL) < 0: raise ValueError('Error unpacking VariantRecord') - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) if not fmt or not fmt.p: - raise KeyError('invalid FORMAT') + raise KeyError('invalid FORMAT: {}'.format(key)) if is_gt_fmt(hdr, fmt.id): return bcf_format_get_allele_indices(sample) - bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &count, &scalar) + bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &count, &scalar, sample.index) if fmt.p and fmt.n and fmt.size: return bcf_array_to_object(fmt.p + sample.index * fmt.size, fmt.type, fmt.n, count, scalar) @@ -720,6 +810,10 @@ cdef bcf_format_set_value(VariantRecordSample sample, key, value): if sample is None: raise ValueError('sample must not be None') + if key == 'phased': + sample.phased = bool(value) + return + cdef bcf_hdr_t *hdr = sample.record.header.ptr cdef bcf1_t *r = sample.record.ptr cdef int fmt_id @@ -731,7 +825,7 @@ cdef bcf_format_set_value(VariantRecordSample sample, key, value): if bcf_unpack(r, BCF_UN_ALL) < 0: raise ValueError('Error unpacking VariantRecord') - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) if fmt: @@ -741,7 +835,7 @@ cdef bcf_format_set_value(VariantRecordSample sample, key, value): k = kh_get_vdict(d, bkey) if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_FMT] & 0xF == 0xF: - raise KeyError('unknown format') + raise KeyError('unknown format: {}'.format(key)) fmt_id = kh_val_vdict(d, k).id @@ -758,7 +852,8 @@ cdef bcf_format_set_value(VariantRecordSample sample, key, value): # KBJ: GT field is considered to be a string by the VCF header but BCF represents it as INT. fmt_type = BCF_HT_INT - values = bcf_check_values(sample.record, value, BCF_HL_FMT, fmt_type, fmt_id, + values = bcf_check_values(sample.record, value, sample.index, + BCF_HL_FMT, fmt_type, fmt_id, fmt.type if fmt else -1, fmt.n if fmt else -1, &value_count, &scalar, &realloc) @@ -776,7 +871,7 @@ cdef bcf_format_set_value(VariantRecordSample sample, key, value): if fmt and fmt.n > alloc_len: alloc_len = fmt.n - n = bcf_hdr_nsamples(hdr) + n = r.n_sample new_values = bcf_empty_array(fmt_type, n*alloc_len, vlen) cdef char *valp = new_values @@ -816,13 +911,13 @@ cdef bcf_format_del_value(VariantRecordSample sample, key): if bcf_unpack(r, BCF_UN_ALL) < 0: raise ValueError('Error unpacking VariantRecord') - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) if not fmt or not fmt.p: raise KeyError(key) - bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &value_count, &scalar) + bcf_get_value_count(sample.record, BCF_HL_FMT, fmt.id, &value_count, &scalar, sample.index) if value_count <= 0: null_value = () @@ -840,7 +935,7 @@ cdef bcf_format_get_allele_indices(VariantRecordSample sample): cdef bcf_hdr_t *hdr = sample.record.header.ptr cdef bcf1_t *r = sample.record.ptr - cdef int32_t n = bcf_hdr_nsamples(hdr) + cdef int32_t n = r.n_sample if bcf_unpack(r, BCF_UN_ALL) < 0: raise ValueError('Error unpacking VariantRecord') @@ -900,7 +995,7 @@ cdef bcf_format_get_alleles(VariantRecordSample sample): cdef bcf_hdr_t *hdr = sample.record.header.ptr cdef bcf1_t *r = sample.record.ptr - cdef int32_t nsamples = bcf_hdr_nsamples(hdr) + cdef int32_t nsamples = r.n_sample if bcf_unpack(r, BCF_UN_ALL) < 0: raise ValueError('Error unpacking VariantRecord') @@ -951,7 +1046,7 @@ cdef bint bcf_sample_get_phased(VariantRecordSample sample): cdef bcf_hdr_t *hdr = sample.record.header.ptr cdef bcf1_t *r = sample.record.ptr - cdef int32_t n = bcf_hdr_nsamples(hdr) + cdef int32_t n = r.n_sample if bcf_unpack(r, BCF_UN_ALL) < 0: raise ValueError('Error unpacking VariantRecord') @@ -1014,7 +1109,7 @@ cdef bcf_sample_set_phased(VariantRecordSample sample, bint phased): cdef bcf_hdr_t *hdr = sample.record.header.ptr cdef bcf1_t *r = sample.record.ptr - cdef int32_t n = bcf_hdr_nsamples(hdr) + cdef int32_t n = r.n_sample if bcf_unpack(r, BCF_UN_ALL) < 0: raise ValueError('Error unpacking VariantRecord') @@ -1061,6 +1156,47 @@ cdef bcf_sample_set_phased(VariantRecordSample sample, bint phased): data32[i] = (data32[i] & 0xFFFFFFFE) | phased +cdef inline bcf_sync_end(VariantRecord record): + cdef bcf_hdr_t *hdr = record.header.ptr + cdef bcf_info_t *info + cdef int end_id = bcf_header_get_info_id(record.header.ptr, b'END') + cdef int ref_len + + # allow missing ref when instantiating a new record + if record.ref is not None: + ref_len = len(record.ref) + else: + ref_len = 0 + + # Delete INFO/END if no alleles are present or if rlen is equal to len(ref) + # Always keep END for symbolic alleles + if not has_symbolic_allele(record) and (not record.ptr.n_allele or record.ptr.rlen == ref_len): + # If INFO/END is not defined in the header, it doesn't exist in the record + if end_id >= 0: + info = bcf_get_info(hdr, record.ptr, b'END') + if info and info.vptr: + if bcf_update_info(hdr, record.ptr, b'END', NULL, 0, info.type) < 0: + raise ValueError('Unable to delete END') + else: + # Create END header, if not present + if end_id < 0: + record.header.info.add('END', number=1, type='Integer', description='Stop position of the interval') + + # Update to reflect stop position + bcf_info_set_value(record, b'END', record.ptr.pos + record.ptr.rlen) + + +cdef inline int has_symbolic_allele(VariantRecord record): + """Return index of first symbolic allele. 0 if no symbolic alleles.""" + + for i in range(1, record.ptr.n_allele): + alt = record.ptr.d.allele[i] + if alt[0] == b'<' and alt[len(alt) - 1] == b'>': + return i + + return 0 + + ######################################################################## ######################################################################## ## Variant Header objects @@ -1205,6 +1341,28 @@ cdef class VariantHeaderRecord(object): """D.values() -> list of D's values""" return list(self.itervalues()) + def update(self, items=None, **kwargs): + """D.update([E, ]**F) -> None. + + Update D from dict/iterable E and F. + """ + for k, v in items.items(): + self[k] = v + + if kwargs: + for k, v in kwargs.items(): + self[k] = v + + def pop(self, key, default=_nothing): + try: + value = self[key] + del self[key] + return value + except KeyError: + if default is not _nothing: + return default + raise + # Mappings are not hashable by default, but subclasses can change this __hash__ = None @@ -1235,9 +1393,8 @@ cdef class VariantHeaderRecord(object): cdef bcf_hrec_t *r = self.ptr if not r: return - assert(r.key) + assert r.key cdef char *key = r.key if r.type == BCF_HL_GEN else r.value - print('Removing header type={} key={} value={} hdr={}'.format(METADATA_TYPES[r.type], r.key, r.value, key)) bcf_hdr_remove(hdr, r.type, key) self.ptr = NULL @@ -1358,8 +1515,8 @@ cdef class VariantMetadata(object): def remove_header(self): cdef bcf_hdr_t *hdr = self.header.ptr - cdef const char *bkey = hdr.id[BCF_DT_ID][self.id].key - bcf_hdr_remove(hdr, self.type, bkey) + cdef const char *key = hdr.id[BCF_DT_ID][self.id].key + bcf_hdr_remove(hdr, self.type, key) cdef VariantMetadata makeVariantMetadata(VariantHeader header, int type, int id): @@ -1437,11 +1594,11 @@ cdef class VariantHeaderMetadata(object): cdef bcf_hdr_t *hdr = self.header.ptr cdef vdict_t *d = hdr.dict[BCF_DT_ID] - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef khiter_t k = kh_get_vdict(d, bkey) if k == kh_end(d) or kh_val_vdict(d, k).info[self.type] & 0xF == 0xF: - raise KeyError('invalid key') + raise KeyError('invalid key: {}'.format(key)) return makeVariantMetadata(self.header, self.type, kh_val_vdict(d, k).id) @@ -1449,11 +1606,11 @@ cdef class VariantHeaderMetadata(object): cdef bcf_hdr_t *hdr = self.header.ptr cdef vdict_t *d = hdr.dict[BCF_DT_ID] - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef khiter_t k = kh_get_vdict(d, bkey) if k == kh_end(d) or kh_val_vdict(d, k).info[self.type] & 0xF == 0xF: - raise KeyError('invalid key') + raise KeyError('invalid key: {}'.format(key)) bcf_hdr_remove(hdr, self.type, bkey) #bcf_hdr_sync(hdr) @@ -1555,7 +1712,7 @@ cdef class VariantContig(object): return length if length else None @property - def header(self): + def header_record(self): """:class:`VariantHeaderRecord` associated with this :class:`VariantContig` object""" cdef bcf_hdr_t *hdr = self.header.ptr cdef bcf_hrec_t *hrec = hdr.id[BCF_DT_CTG][self.id].val.hrec[0] @@ -1563,8 +1720,8 @@ cdef class VariantContig(object): def remove_header(self): cdef bcf_hdr_t *hdr = self.header.ptr - cdef const char *bkey = hdr.id[BCF_DT_CTG][self.id].key - bcf_hdr_remove(hdr, BCF_HL_CTG, bkey) + cdef const char *key = hdr.id[BCF_DT_CTG][self.id].key + bcf_hdr_remove(hdr, BCF_HL_CTG, key) cdef VariantContig makeVariantContig(VariantHeader header, int id): @@ -1607,11 +1764,11 @@ cdef class VariantHeaderContigs(object): return makeVariantContig(self.header, index) cdef vdict_t *d = hdr.dict[BCF_DT_CTG] - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef khiter_t k = kh_get_vdict(d, bkey) if k == kh_end(d): - raise KeyError('invalid contig') + raise KeyError('invalid contig: {}'.format(key)) cdef int id = kh_val_vdict(d, k).id @@ -1620,7 +1777,7 @@ cdef class VariantHeaderContigs(object): def remove_header(self, key): cdef bcf_hdr_t *hdr = self.header.ptr cdef int index - cdef const char *bkey + cdef const char *ckey cdef vdict_t *d cdef khiter_t k @@ -1628,15 +1785,15 @@ cdef class VariantHeaderContigs(object): index = key if index < 0 or index >= hdr.n[BCF_DT_CTG]: raise IndexError('invalid contig index') - bkey = hdr.id[BCF_DT_CTG][self.id].key + ckey = hdr.id[BCF_DT_CTG][self.id].key else: d = hdr.dict[BCF_DT_CTG] key = force_bytes(key) if kh_get_vdict(d, key) == kh_end(d): - raise KeyError('invalid contig') - bkey = key + raise KeyError('invalid contig: {}'.format(key)) + ckey = key - bcf_hdr_remove(hdr, BCF_HL_CTG, bkey) + bcf_hdr_remove(hdr, BCF_HL_CTG, ckey) def clear_header(self): cdef bcf_hdr_t *hdr = self.header.ptr @@ -1704,7 +1861,8 @@ cdef class VariantHeaderContigs(object): if id in self: raise ValueError('Header already exists for contig {}'.format(id)) - items = [('ID', id)] + kwargs.items() + items = [('ID', id)] + items += kwargs.items() self.header.add_meta('contig', items=items) @@ -1749,7 +1907,7 @@ cdef class VariantHeaderSamples(object): def __contains__(self, key): cdef bcf_hdr_t *hdr = self.header.ptr cdef vdict_t *d = hdr.dict[BCF_DT_SAMPLE] - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef khiter_t k = kh_get_vdict(d, bkey) return k != kh_end(d) @@ -1796,7 +1954,6 @@ cdef class VariantHeader(object): self.ptr = NULL def __bool__(self): - # self.ptr == NULL should be impossible return self.ptr != NULL def copy(self): @@ -1886,11 +2043,54 @@ cdef class VariantHeader(object): finally: free(hstr) - cpdef VariantRecord new_record(self): - """Create a new empty VariantRecord""" - r = makeVariantRecord(self, bcf_init()) - r.ptr.n_sample = bcf_hdr_nsamples(self.ptr) - return r + def new_record(self, contig=None, start=0, stop=0, alleles=None, + id=None, qual=None, filter=None, info=None, samples=None, + **kwargs): + """Create a new empty VariantRecord. + + Arguments are currently experimental. Use with caution and expect + changes in upcoming releases. + + """ + rec = makeVariantRecord(self, bcf_init()) + + if not rec: + raise MemoryError('unable to allocate BCF record') + + rec.ptr.n_sample = bcf_hdr_nsamples(self.ptr) + + if contig is not None: + rec.contig = contig + if alleles is not None: + rec.alleles = alleles + + rec.start = start + rec.stop = stop + rec.id = id + rec.qual = qual + + if filter is not None: + if isinstance(filter, (list, tuple, VariantRecordFilter)): + for f in filter: + rec.filter.add(f) + else: + rec.filter.add(filter) + + if info: + rec.info.update(info) + + if kwargs: + if 'GT' in kwargs: + rec.samples[0]['GT'] = kwargs.pop('GT') + rec.samples[0].update(kwargs) + + if samples: + for i, sample in enumerate(samples): + if 'GT' in sample: + rec.samples[i]['GT'] = sample.pop('GT') + rec.samples[i].update(sample) + + return rec def add_record(self, VariantHeaderRecord record): """Add an existing :class:`VariantHeaderRecord` to this header""" @@ -1963,6 +2163,23 @@ cdef VariantHeader makeVariantHeader(bcf_hdr_t *hdr): return header +cdef inline int bcf_header_get_info_id(bcf_hdr_t *hdr, key) except? -2: + cdef vdict_t *d + cdef khiter_t k + cdef int info_id + + if isinstance(key, str): + key = force_bytes(key) + + d = hdr.dict[BCF_DT_ID] + k = kh_get_vdict(d, key) + + if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: + return -1 + + return kh_val_vdict(d, k).id + + ######################################################################## ######################################################################## ## Variant Record objects @@ -2001,7 +2218,7 @@ cdef class VariantRecordFilter(object): id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): - raise KeyError('Invalid filter') + raise KeyError('Invalid filter: {}'.format(key)) return makeVariantMetadata(self.record.header, BCF_HL_FLT, id) @@ -2014,11 +2231,11 @@ cdef class VariantRecordFilter(object): if key == '.': key = 'PASS' - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) if not check_header_id(hdr, BCF_HL_FLT, id): - raise KeyError('Invalid filter') + raise KeyError('Invalid filter: {}'.format(key)) bcf_add_filter(hdr, r, id) @@ -2043,7 +2260,7 @@ cdef class VariantRecordFilter(object): id = bcf_hdr_id2int(hdr, BCF_DT_ID, bkey) if not check_header_id(hdr, BCF_HL_FLT, id) or not bcf_has_filter(hdr, r, bkey): - raise KeyError('Invalid filter') + raise KeyError('Invalid filter: {}'.format(key)) bcf_remove_filter(hdr, r, id, 0) @@ -2071,7 +2288,7 @@ cdef class VariantRecordFilter(object): def __contains__(self, key): cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) return bcf_has_filter(hdr, r, bkey) == 1 def iterkeys(self): @@ -2100,6 +2317,20 @@ cdef class VariantRecordFilter(object): """D.values() -> list of D's values""" return list(self.itervalues()) + def __richcmp__(VariantRecordFilter self not None, VariantRecordFilter other not None, int op): + if op != 2 and op != 3: + return NotImplemented + + cdef bcf1_t *s = self.record.ptr + cdef bcf1_t *o = other.record.ptr + + cdef bint cmp = (s.d.n_flt == o.d.n_flt and list(self) == list(other)) + + if op == 3: + cmp = not cmp + + return cmp + # Mappings are not hashable by default, but subclasses can change this __hash__ = None @@ -2146,11 +2377,11 @@ cdef class VariantRecordFormat(object): cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) if not fmt or not fmt.p: - raise KeyError('unknown format') + raise KeyError('unknown format: {}'.format(key)) return makeVariantMetadata(self.record.header, BCF_HL_FMT, fmt.id) @@ -2158,11 +2389,11 @@ cdef class VariantRecordFormat(object): cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) if not fmt or not fmt.p: - raise KeyError('unknown format') + raise KeyError('unknown format: {}'.format(key)) if bcf_update_format(hdr, r, bkey, fmt.p, 0, fmt.type) < 0: raise ValueError('Unable to delete FORMAT') @@ -2204,7 +2435,7 @@ cdef class VariantRecordFormat(object): def __contains__(self, key): cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) return fmt != NULL and fmt.p != NULL @@ -2259,38 +2490,65 @@ cdef class VariantRecordInfo(object): raise TypeError('this class cannot be instantiated from Python') def __len__(self): - return self.record.ptr.n_info + cdef bcf_hdr_t *hdr = self.record.header.ptr + cdef bcf1_t *r = self.record.ptr + cdef bcf_info_t *info + cdef const char *key + cdef int i, count = 0 + + if bcf_unpack(r, BCF_UN_INFO) < 0: + raise ValueError('Error unpacking VariantRecord') + + for i in range(r.n_info): + info = &r.d.info[i] + key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + if info != NULL and info.vptr != NULL and strcmp(key, b'END') != 0: + count += 1 + + return count def __bool__(self): - return self.record.ptr.n_info != 0 + cdef bcf_hdr_t *hdr = self.record.header.ptr + cdef bcf1_t *r = self.record.ptr + cdef bcf_info_t *info + cdef const char *key + cdef int i + + if bcf_unpack(r, BCF_UN_INFO) < 0: + raise ValueError('Error unpacking VariantRecord') + + for i in range(r.n_info): + info = &r.d.info[i] + key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + if info != NULL and info.vptr != NULL and strcmp(key, b'END') != 0: + return True + + return False def __getitem__(self, key): cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr - cdef vdict_t *d - cdef khiter_t k - cdef info_id if bcf_unpack(r, BCF_UN_INFO) < 0: raise ValueError('Error unpacking VariantRecord') - bkey = force_bytes(key) - cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) + cdef bytes bkey = force_bytes(key) - if not info: - d = hdr.dict[BCF_DT_ID] - k = kh_get_vdict(d, bkey) + if strcmp(bkey, b'END') == 0: + raise KeyError('END is a reserved attribute; access is via record.stop') - if k == kh_end(d) or kh_val_vdict(d, k).info[BCF_HL_INFO] & 0xF == 0xF: - raise KeyError('Unknown INFO field: {}'.format(key)) + cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) - info_id = kh_val_vdict(d, k).id - else: - info_id = info.key + # Cannot stop here if info == NULL, since flags must return False + cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key + + if info_id < 0: + raise KeyError('Unknown INFO field: {}'.format(key)) if not check_header_id(hdr, BCF_HL_INFO, info_id): raise ValueError('Invalid header') + # Handle type=Flag values if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG: return info != NULL and info.vptr != NULL @@ -2300,18 +2558,42 @@ cdef class VariantRecordInfo(object): return bcf_info_get_value(self.record, info) def __setitem__(self, key, value): + cdef bytes bkey = force_bytes(key) + + if strcmp(bkey, b'END') == 0: + raise KeyError('END is a reserved attribute; access is via record.stop') + + if bcf_unpack(self.record.ptr, BCF_UN_INFO) < 0: + raise ValueError('Error unpacking VariantRecord') + bcf_info_set_value(self.record, key, value) def __delitem__(self, key): cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr + cdef bytes bkey = force_bytes(key) + if strcmp(bkey, b'END') == 0: + raise KeyError('END is a reserved attribute; access is via record.stop') + if bcf_unpack(r, BCF_UN_INFO) < 0: raise ValueError('Error unpacking VariantRecord') - bkey = force_bytes(key) cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) + # Cannot stop here if info == NULL, since flags must return False + cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key + + if info_id < 0: + raise KeyError('Unknown INFO field: {}'.format(key)) + + if not check_header_id(hdr, BCF_HL_INFO, info_id): + raise ValueError('Invalid header') + + # Handle flags + if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG and (not info or not info.vptr): + return + if not info or not info.vptr: raise KeyError('Unknown INFO field: {}'.format(key)) @@ -2333,6 +2615,8 @@ cdef class VariantRecordInfo(object): info = &r.d.info[i] if info and info.vptr: key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + if strcmp(key, b'END') == 0: + continue if bcf_update_info(hdr, r, key, NULL, 0, info.type) < 0: raise ValueError('Unable to delete INFO') @@ -2340,20 +2624,49 @@ cdef class VariantRecordInfo(object): cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr cdef bcf_info_t *info + cdef const char *key cdef int i + if bcf_unpack(r, BCF_UN_INFO) < 0: + raise ValueError('Error unpacking VariantRecord') + for i in range(r.n_info): info = &r.d.info[i] if info and info.vptr: - yield bcf_str_cache_get_charptr(bcf_hdr_int2id(hdr, BCF_DT_ID, info.key)) + key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + if strcmp(key, b'END') != 0: + yield bcf_str_cache_get_charptr(key) def get(self, key, default=None): """D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.""" - try: - return self[key] - except KeyError: + cdef bcf_hdr_t *hdr = self.record.header.ptr + cdef bcf1_t *r = self.record.ptr + + if bcf_unpack(r, BCF_UN_INFO) < 0: + raise ValueError('Error unpacking VariantRecord') + + cdef bytes bkey = force_bytes(key) + + if strcmp(bkey, b'END') == 0: return default + cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) + + # Cannot stop here if info == NULL, since flags must return False + cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key + + if not check_header_id(hdr, BCF_HL_INFO, info_id): + raise ValueError('Invalid header') + + # Handle flags + if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG: + return info != NULL and info.vptr != NULL + + if not info or not info.vptr: + return default + + return bcf_info_get_value(self.record, info) + def __contains__(self, key): cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr @@ -2361,10 +2674,14 @@ cdef class VariantRecordInfo(object): if bcf_unpack(r, BCF_UN_INFO) < 0: raise ValueError('Error unpacking VariantRecord') - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) + + if strcmp(bkey, b'END') == 0: + return False + cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) - return info != NULL + return info != NULL and info.vptr != NULL def iterkeys(self): """D.iterkeys() -> an iterator over the keys of D""" @@ -2372,28 +2689,40 @@ cdef class VariantRecordInfo(object): def itervalues(self): """D.itervalues() -> an iterator over the values of D""" + cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr cdef bcf_info_t *info + cdef const char *key cdef int i + if bcf_unpack(r, BCF_UN_INFO) < 0: + raise ValueError('Error unpacking VariantRecord') + for i in range(r.n_info): info = &r.d.info[i] if info and info.vptr: - yield bcf_info_get_value(self.record, info) + key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) + if strcmp(key, b'END') != 0: + yield bcf_info_get_value(self.record, info) def iteritems(self): """D.iteritems() -> an iterator over the (key, value) items of D""" cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr cdef bcf_info_t *info + cdef const char *key cdef int i + if bcf_unpack(r, BCF_UN_INFO) < 0: + raise ValueError('Error unpacking VariantRecord') + for i in range(r.n_info): info = &r.d.info[i] if info and info.vptr: key = bcf_hdr_int2id(hdr, BCF_DT_ID, info.key) - value = bcf_info_get_value(self.record, info) - yield bcf_str_cache_get_charptr(key), value + if strcmp(key, b'END') != 0: + value = bcf_info_get_value(self.record, info) + yield bcf_str_cache_get_charptr(key), value def keys(self): """D.keys() -> list of D's keys""" @@ -2407,11 +2736,75 @@ cdef class VariantRecordInfo(object): """D.values() -> list of D's values""" return list(self.itervalues()) + def update(self, items=None, **kwargs): + """D.update([E, ]**F) -> None. + + Update D from dict/iterable E and F. + """ + for k, v in items.items(): + if k != 'END': + self[k] = v + + if kwargs: + kwargs.pop('END', None) + for k, v in kwargs.items(): + self[k] = v + + def pop(self, key, default=_nothing): + cdef bcf_hdr_t *hdr = self.record.header.ptr + cdef bcf1_t *r = self.record.ptr + + if bcf_unpack(r, BCF_UN_INFO) < 0: + raise ValueError('Error unpacking VariantRecord') + + cdef bytes bkey = force_bytes(key) + cdef bcf_info_t *info = bcf_get_info(hdr, r, bkey) + + # Cannot stop here if info == NULL, since flags must return False + cdef int info_id = bcf_header_get_info_id(hdr, bkey) if not info else info.key + + if info_id < 0: + if default is _nothing: + raise KeyError('Unknown INFO field: {}'.format(key)) + return default + + if not check_header_id(hdr, BCF_HL_INFO, info_id): + raise ValueError('Invalid header') + + # Handle flags + if bcf_hdr_id2type(hdr, BCF_HL_INFO, info_id) == BCF_HT_FLAG and (not info or not info.vptr): + return + + if not info or not info.vptr: + if default is _nothing: + raise KeyError('Unknown INFO field: {}'.format(key)) + return default + + value = bcf_info_get_value(self.record, info) + + if bcf_update_info(hdr, r, bkey, NULL, 0, info.type) < 0: + raise ValueError('Unable to delete INFO') + + return value + + def __richcmp__(VariantRecordInfo self not None, VariantRecordInfo other not None, int op): + if op != 2 and op != 3: + return NotImplemented + + cdef bcf1_t *s = self.record.ptr + cdef bcf1_t *o = other.record.ptr + + # Cannot use n_info as shortcut logic, since null values may remain + cdef bint cmp = dict(self) == dict(other) + + if op == 3: + cmp = not cmp + + return cmp + # Mappings are not hashable by default, but subclasses can change this __hash__ = None - #TODO: implement __richcmp__ - cdef VariantRecordInfo makeVariantRecordInfo(VariantRecord record): if not record: @@ -2429,15 +2822,15 @@ cdef class VariantRecordSamples(object): raise TypeError('this class cannot be instantiated from Python') def __len__(self): - return bcf_hdr_nsamples(self.record.header.ptr) + return self.record.ptr.n_sample # bcf_hdr_nsamples(self.record.header.ptr) def __bool__(self): - return bcf_hdr_nsamples(self.record.header.ptr) != 0 + return self.record.ptr.n_sample != 0 # bcf_hdr_nsamples(self.record.header.ptr) != 0 def __getitem__(self, key): cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr - cdef int n = bcf_hdr_nsamples(hdr) + cdef int n = self.record.ptr.n_sample cdef int sample_index cdef vdict_t *d cdef khiter_t k @@ -2448,7 +2841,7 @@ cdef class VariantRecordSamples(object): bkey = force_bytes(key) sample_index = bcf_hdr_id2int(hdr, BCF_DT_SAMPLE, bkey) if sample_index < 0: - raise KeyError('invalid sample name') + raise KeyError('invalid sample name: {}'.format(key)) if sample_index < 0 or sample_index >= n: raise IndexError('invalid sample index') @@ -2458,7 +2851,7 @@ cdef class VariantRecordSamples(object): def __iter__(self): cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr - cdef int32_t i, n = bcf_hdr_nsamples(hdr) + cdef int32_t i, n = self.record.ptr.n_sample for i in range(n): yield charptr_to_str(hdr.samples[i]) @@ -2473,7 +2866,7 @@ cdef class VariantRecordSamples(object): def __contains__(self, key): cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr - cdef int n = bcf_hdr_nsamples(hdr) + cdef int n = self.record.ptr.n_sample cdef int sample_index cdef vdict_t *d cdef khiter_t k @@ -2484,7 +2877,7 @@ cdef class VariantRecordSamples(object): bkey = force_bytes(key) sample_index = bcf_hdr_id2int(hdr, BCF_DT_SAMPLE, bkey) if sample_index < 0: - raise KeyError('invalid sample name') + raise KeyError('invalid sample name: {}'.format(key)) return 0 <= sample_index < n @@ -2496,7 +2889,7 @@ cdef class VariantRecordSamples(object): """D.itervalues() -> an iterator over the values of D""" cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr - cdef int32_t i, n = bcf_hdr_nsamples(hdr) + cdef int32_t i, n = self.record.ptr.n_sample for i in range(n): yield makeVariantRecordSample(self.record, i) @@ -2505,7 +2898,7 @@ cdef class VariantRecordSamples(object): """D.iteritems() -> an iterator over the (key, value) items of D""" cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr - cdef int32_t i, n = bcf_hdr_nsamples(hdr) + cdef int32_t i, n = self.record.ptr.n_sample for i in range(n): yield (charptr_to_str(hdr.samples[i]), makeVariantRecordSample(self.record, i)) @@ -2522,11 +2915,45 @@ cdef class VariantRecordSamples(object): """D.values() -> list of D's values""" return list(self.itervalues()) + def update(self, items=None, **kwargs): + """D.update([E, ]**F) -> None. + + Update D from dict/iterable E and F. + """ + for k, v in items.items(): + self[k] = v + + if kwargs: + for k, v in kwargs.items(): + self[k] = v + + def pop(self, key, default=_nothing): + try: + value = self[key] + del self[key] + return value + except KeyError: + if default is not _nothing: + return default + raise + + def __richcmp__(VariantRecordSamples self not None, VariantRecordSamples other not None, int op): + if op != 2 and op != 3: + return NotImplemented + + cdef bcf1_t *s = self.record.ptr + cdef bcf1_t *o = other.record.ptr + + cdef bint cmp = (s.n_sample == o.n_sample and self.values() == other.values()) + + if op == 3: + cmp = not cmp + + return cmp + # Mappings are not hashable by default, but subclasses can change this __hash__ = None - #TODO: implement __richcmp__ - cdef VariantRecordSamples makeVariantRecordSamples(VariantRecord record): if not record: @@ -2566,6 +2993,7 @@ cdef class VariantRecord(object): raise ValueError(msg.format(self.ptr.n_sample, bcf_hdr_nsamples(dst_hdr))) bcf_translate(dst_hdr, src_hdr, self.ptr) + self.header = dst_header @property def rid(self): @@ -2627,6 +3055,7 @@ cdef class VariantRecord(object): if p < 1: raise ValueError('Position must be positive') self.ptr.pos = p - 1 + bcf_sync_end(self) @property def start(self): @@ -2639,6 +3068,7 @@ cdef class VariantRecord(object): if s < 0: raise ValueError('Start coordinate must be non-negative') self.ptr.pos = s + bcf_sync_end(self) @property def stop(self): @@ -2648,25 +3078,21 @@ cdef class VariantRecord(object): @stop.setter def stop(self, value): cdef int s = value - if s < self.ptr.pos: - raise ValueError('Stop coordinate must be greater than or equal to start') + if s < 0: + raise ValueError('Stop coordinate must be non-negative') self.ptr.rlen = s - self.ptr.pos - if self.ptr.rlen != len(self.ref) or 'END' in self.info: - self.info['END'] = s + bcf_sync_end(self) @property def rlen(self): - """record length on chrom/contig (typically rec.stop - rec.start unless END info is supplied)""" + """record length on chrom/contig (aka rec.stop - rec.start)""" return self.ptr.rlen @rlen.setter def rlen(self, value): cdef int r = value - if r < 0: - raise ValueError('Reference length must be non-negative') self.ptr.rlen = r - if r != len(self.ref) or 'END' in self.info: - self.info['END'] = self.ptr.pos + r + bcf_sync_end(self) @property def qual(self): @@ -2730,8 +3156,9 @@ cdef class VariantRecord(object): alleles = [r.d.allele[i] for i in range(r.n_allele)] alleles[0] = value else: - alleles = [value] + alleles = [value, ''] self.alleles = alleles + bcf_sync_end(self) @property def alleles(self): @@ -2749,17 +3176,35 @@ cdef class VariantRecord(object): return res @alleles.setter - def alleles(self, value): + def alleles(self, values): cdef bcf1_t *r = self.ptr + + # Cache rlen of symbolic alleles before call to bcf_update_alleles_str + cdef int rlen = r.rlen + if bcf_unpack(r, BCF_UN_STR) < 0: raise ValueError('Error unpacking VariantRecord') - value = [force_bytes(v) for v in value] - if b'' in value: + + values = [force_bytes(v) for v in values] + + if len(values) < 2: + raise ValueError('must set at least 2 alleles') + + if b'' in values: raise ValueError('cannot set null allele') - value = b','.join(value) + + value = b','.join(values) + if bcf_update_alleles_str(self.header.ptr, r, value) < 0: raise ValueError('Error updating alleles') + # Reset rlen if alternate allele isn't symbolic, otherwise used cached + if has_symbolic_allele(self): + self.ptr.rlen = rlen + else: + self.ptr.rlen = len(values[0]) + bcf_sync_end(self) + @property def alts(self): """tuple of alt alleles""" @@ -2815,6 +3260,32 @@ cdef class VariantRecord(object): raise ValueError('Error unpacking VariantRecord') return makeVariantRecordSamples(self) + def __richcmp__(VariantRecord self not None, VariantRecord other not None, int op): + if op != 2 and op != 3: + return NotImplemented + + cdef bcf1_t *s = self.ptr + cdef bcf1_t *o = other.ptr + + cdef bint cmp = self is other or ( + s.pos == o.pos + and s.rlen == o.rlen + and ((bcf_float_is_missing(s.qual) and bcf_float_is_missing(o.qual)) + or s.qual == o.qual) + and s.n_sample == o.n_sample + and s.n_allele == o.n_allele + and self.contig == other.contig + and self.alleles == other.alleles + and self.id == other.id + and self.info == other.info + and self.filter == other.filter + and self.samples == other.samples) + + if op == 3: + cmp = not cmp + + return cmp + def __str__(self): cdef kstring_t line cdef char c @@ -2896,7 +3367,7 @@ cdef class VariantRecordSample(object): """sample name""" cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr - cdef int32_t n = bcf_hdr_nsamples(hdr) + cdef int32_t n = r.n_sample if self.index < 0 or self.index >= n: raise ValueError('invalid sample index') @@ -3006,7 +3477,7 @@ cdef class VariantRecordSample(object): def __contains__(self, key): cdef bcf_hdr_t *hdr = self.record.header.ptr cdef bcf1_t *r = self.record.ptr - bkey = force_bytes(key) + cdef bytes bkey = force_bytes(key) cdef bcf_fmt_t *fmt = bcf_get_fmt(hdr, r, bkey) return fmt != NULL and fmt.p != NULL @@ -3036,11 +3507,42 @@ cdef class VariantRecordSample(object): """D.values() -> list of D's values""" return list(self.itervalues()) + def update(self, items=None, **kwargs): + """D.update([E, ]**F) -> None. + + Update D from dict/iterable E and F. + """ + for k, v in items.items(): + self[k] = v + + if kwargs: + for k, v in kwargs.items(): + self[k] = v + + def pop(self, key, default=_nothing): + try: + value = self[key] + del self[key] + return value + except KeyError: + if default is not _nothing: + return default + raise + + def __richcmp__(VariantRecordSample self not None, VariantRecordSample other not None, int op): + if op != 2 and op != 3: + return NotImplemented + + cdef bint cmp = dict(self) == dict(other) + + if op == 3: + cmp = not cmp + + return cmp + # Mappings are not hashable by default, but subclasses can change this __hash__ = None - #TODO: implement __richcmp__ - cdef VariantRecordSample makeVariantRecordSample(VariantRecord record, int32_t sample_index): if not record or sample_index < 0: @@ -3120,6 +3622,28 @@ cdef class BaseIndex(object): """D.values() -> list of D's values""" return list(self.itervalues()) + def update(self, items=None, **kwargs): + """D.update([E, ]**F) -> None. + + Update D from dict/iterable E and F. + """ + for k, v in items.items(): + self[k] = v + + if kwargs: + for k, v in kwargs.items(): + self[k] = v + + def pop(self, key, default=_nothing): + try: + value = self[key] + del self[key] + return value + except KeyError: + if default is not _nothing: + return default + raise + # Mappings are not hashable by default, but subclasses can change this __hash__ = None @@ -3146,8 +3670,8 @@ cdef class BCFIndex(object): hts_idx_destroy(self.ptr) self.ptr = NULL - def fetch(self, bcf, contig, start, stop, region, reopen): - return BCFIterator(bcf, contig, start, stop, region, reopen) + def fetch(self, bcf, contig, start, stop, reopen): + return BCFIterator(bcf, contig, start, stop, reopen) cdef BCFIndex makeBCFIndex(VariantHeader header, hts_idx_t *idx): @@ -3185,8 +3709,8 @@ cdef class TabixIndex(BaseIndex): tbx_destroy(self.ptr) self.ptr = NULL - def fetch(self, bcf, contig, start, stop, region, reopen): - return TabixIterator(bcf, contig, start, stop, region, reopen) + def fetch(self, bcf, contig, start, stop, reopen): + return TabixIterator(bcf, contig, start, stop, reopen) cdef TabixIndex makeTabixIndex(tbx_t *idx): @@ -3221,54 +3745,44 @@ cdef void _stop_BCFIterator(BCFIterator self, bcf1_t *record): cdef class BCFIterator(BaseIterator): - def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): + def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): if bcf is None: raise ValueError('bcf must not be None') + if contig is None: + raise ValueError('contig must be specified') + if not isinstance(bcf.index, BCFIndex): raise ValueError('bcf index required') cdef BCFIndex index = bcf.index - cdef int rid, cstart, cstop - cdef char *cregion - - if not index: - raise ValueError('bcf index required') - - if reopen: - bcf = bcf.copy() - if region is not None: - if contig is not None or start is not None or stop is not None: - raise ValueError # FIXME - - bregion = force_bytes(region) - cregion = bregion - with nogil: - self.iter = bcf_itr_querys(index.ptr, bcf.header.ptr, cregion) - else: - if contig is None: - raise ValueError # FIXME + self.bcf = bcf + self.index = index - try: - rid = index.refmap[contig] - except KeyError: - raise ValueError('Unknown contig specified') + cdef int rid, cstart, cstop - if start is None: - start = 0 - if stop is None: - stop = MAX_POS + try: + rid = index.refmap[contig] + except KeyError: + # A query for a non-existant contig yields an empty iterator, does not raise an error + self.iter = NULL + return - cstart, cstop = start, stop + if reopen: + self.bcf = self.bcf.copy() - with nogil: - self.iter = bcf_itr_queryi(index.ptr, rid, cstart, cstop) + cstart = start if start is not None else 0 + cstop = stop if stop is not None else MAX_POS - # Do not fail on self.iter == NULL, since it signifies a null query. + with nogil: + self.iter = bcf_itr_queryi(index.ptr, rid, cstart, cstop) - self.bcf = bcf - self.index = index + if not self.iter: + if errno: + raise IOError(errno, strerror(errno)) + else: + raise IOError('unable to fetch {}:{}-{}'.format(contig, start+1, stop)) def __dealloc__(self): if self.iter: @@ -3284,6 +3798,9 @@ cdef class BCFIterator(BaseIterator): cdef bcf1_t *record = bcf_init1() + if not record: + raise MemoryError('unable to allocate BCF record') + record.pos = -1 if self.bcf.drop_samples: record.max_unpack = BCF_UN_SHR @@ -3297,8 +3814,12 @@ cdef class BCFIterator(BaseIterator): _stop_BCFIterator(self, record) if ret == -1: raise StopIteration + elif ret == -2: + raise IOError('truncated file') + elif errno: + raise IOError(errno, strerror(errno)) else: - raise ValueError('error reading BCF file') + raise IOError('unable to fetch next record') ret = bcf_subset_format(self.bcf.header.ptr, record) @@ -3315,7 +3836,7 @@ cdef class TabixIterator(BaseIterator): self.line_buffer.m = 0 self.line_buffer.s = NULL - def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, region=None, reopen=True): + def __init__(self, VariantFile bcf, contig=None, start=None, stop=None, reopen=True): if bcf is None: raise ValueError('bcf must not be None') @@ -3324,34 +3845,31 @@ cdef class TabixIterator(BaseIterator): cdef TabixIndex index = bcf.index - if not index: - raise ValueError('bcf index required') - - if reopen: - bcf = bcf.copy() - - if region is not None: - if contig is not None or start is not None or stop is not None: - raise ValueError # FIXME + self.bcf = bcf + self.index = index - self.iter = tbx_itr_querys(index.ptr, region) - else: - if contig is None: - raise ValueError # FIXME + cdef int rid, cstart, cstop - rid = index.refmap.get(contig, -1) + try: + rid = index.refmap[contig] + except KeyError: + # A query for a non-existant contig yields an empty iterator, does not raise an error + self.iter = NULL + return - if start is None: - start = 0 - if stop is None: - stop = MAX_POS + if reopen: + self.bcf = self.bcf.copy() - self.iter = tbx_itr_queryi(index.ptr, rid, start, stop) + cstart = start if start is not None else 0 + cstop = stop if stop is not None else MAX_POS - # Do not fail on self.iter == NULL, since it signifies a null query. + self.iter = tbx_itr_queryi(index.ptr, rid, start, stop) - self.bcf = bcf - self.index = index + if not self.iter: + if errno: + raise IOError(errno, strerror(errno)) + else: + raise IOError('unable to fetch {}:{}-{}'.format(contig, start+1, stop)) def __dealloc__(self): if self.iter: @@ -3382,11 +3900,18 @@ cdef class TabixIterator(BaseIterator): self.iter = NULL if ret == -1: raise StopIteration + elif ret == -2: + raise IOError('truncated file') + elif errno: + raise IOError(errno, strerror(errno)) else: - raise ValueError('error reading indexed VCF file') + raise IOError('unable to fetch next record') cdef bcf1_t *record = bcf_init1() + if not record: + raise MemoryError('unable to allocate BCF record') + record.pos = -1 if self.bcf.drop_samples: record.max_unpack = BCF_UN_SHR @@ -3409,7 +3934,7 @@ cdef class TabixIterator(BaseIterator): cdef class VariantFile(HTSFile): """*(filename, mode=None, index_filename=None, header=None, drop_samples=False, - duplicate_filehandle=True)* + duplicate_filehandle=True, ignore_truncation=False, threads=1)* A :term:`VCF`/:term:`BCF` formatted file. The file is automatically opened. @@ -3451,7 +3976,7 @@ cdef class VariantFile(HTSFile): drop_samples: bool Ignore sample information when reading. - duplicate_filehandle: bool + duplicate_filehandle: bool By default, file handles passed either directly or through File-like objects will be duplicated before passing them to htslib. The duplication prevents issues where the same stream @@ -3459,6 +3984,16 @@ cdef class VariantFile(HTSFile): high-level python object. Set to False to turn off duplication. + ignore_truncation: bool + Issue a warning, instead of raising an error if the current file + appears to be truncated due to a missing EOF marker. Only applies + to bgzipped formats. (Default=False) + + threads: integer + Number of threads to use for compressing/decompressing VCF/BCF files. + Setting threads to > 1 cannot be combined with `ignore_truncation`. + (Default=1) + """ def __cinit__(self, *args, **kwargs): self.htsfile = NULL @@ -3468,6 +4003,7 @@ cdef class VariantFile(HTSFile): self.index = None self.filename = None self.mode = None + self.threads = 1 self.index_filename = None self.is_stream = False self.is_remote = False @@ -3478,26 +4014,46 @@ cdef class VariantFile(HTSFile): self.open(*args, **kwargs) + def __dealloc__(self): + if not self.htsfile or not self.header: + return + + # Write header if no records were written + if self.htsfile.is_write and not self.header_written: + with nogil: + bcf_hdr_write(self.htsfile, self.header.ptr) + + cdef int ret = hts_close(self.htsfile) + self.htsfile = NULL + self.header = self.index = None + + if ret < 0: + global errno + if errno == EPIPE: + errno = 0 + else: + raise IOError(errno, force_str(strerror(errno))) + def close(self): """closes the :class:`pysam.VariantFile`.""" - cdef int ret = 0 - self.header = self.index = None - if self.htsfile: - # Write header if no records were written - if self.htsfile.is_write and not self.header_written: - self.header_written = True - with nogil: - bcf_hdr_write(self.htsfile, self.header.ptr) + if not self.htsfile: + return - ret = hts_close(self.htsfile) - self.htsfile = NULL + # Write header if no records were written + if self.htsfile.is_write and not self.header_written: + with nogil: + bcf_hdr_write(self.htsfile, self.header.ptr) + + cdef int ret = hts_close(self.htsfile) + self.htsfile = NULL + self.header = self.index = None if ret < 0: global errno if errno == EPIPE: errno = 0 else: - raise OSError(errno, force_str(strerror(errno))) + raise IOError(errno, force_str(strerror(errno))) def __iter__(self): if not self.is_open: @@ -3513,6 +4069,9 @@ cdef class VariantFile(HTSFile): cdef int ret cdef bcf1_t *record = bcf_init1() + if not record: + raise MemoryError('unable to allocate BCF record') + record.pos = -1 if self.drop_samples: record.max_unpack = BCF_UN_SHR @@ -3526,8 +4085,10 @@ cdef class VariantFile(HTSFile): raise StopIteration elif ret == -2: raise IOError('truncated file') + elif errno: + raise IOError(errno, strerror(errno)) else: - raise ValueError('Variant read failed') + raise IOError('unable to fetch next record') return makeVariantRecord(self.header, record) @@ -3551,6 +4112,7 @@ cdef class VariantFile(HTSFile): vars.filename = self.filename vars.mode = self.mode + vars.threads = self.threads vars.index_filename = self.index_filename vars.drop_samples = self.drop_samples vars.is_stream = self.is_stream @@ -3572,7 +4134,9 @@ cdef class VariantFile(HTSFile): index_filename=None, VariantHeader header=None, drop_samples=False, - duplicate_filehandle=True): + duplicate_filehandle=True, + ignore_truncation=False, + threads=1): """open a vcf/bcf file. If open is called on an existing VariantFile, the current file will be @@ -3586,6 +4150,15 @@ cdef class VariantFile(HTSFile): cdef char *cindex_filename = NULL cdef char *cmode + if threads > 1 and ignore_truncation: + # This won't raise errors if reaching a truncated alignment, + # because bgzf_mt_reader in htslib does not deal with + # bgzf_mt_read_block returning non-zero values, contrary + # to bgzf_read (https://github.com/samtools/htslib/blob/1.7/bgzf.c#L888) + # Better to avoid this (for now) than to produce seemingly correct results. + raise ValueError('Cannot add extra threads when "ignore_truncation" is True') + self.threads = threads + # close a previously opened file if self.is_open: self.close() @@ -3656,22 +4229,18 @@ cdef class VariantFile(HTSFile): elif mode.startswith(b'r'): # open file for reading - - if not self._exists(): - raise IOError('file `{}` not found'.format(filename)) - self.htsfile = self._open_htsfile() if not self.htsfile: - raise ValueError("could not open file `{}` (mode='{}') - is it VCF/BCF format?".format(filename, mode)) + if errno: + raise IOError(errno, 'could not open variant file `{}`: {}'.format(filename, force_str(strerror(errno)))) + else: + raise ValueError('could not open variant file `{}`'.format(filename)) if self.htsfile.format.format not in (bcf, vcf): - raise ValueError("invalid file `{}` (mode='{}') - is it VCF/BCF format?".format(filename, mode)) + raise ValueError('invalid file `{}` (mode=`{}`) - is it VCF/BCF format?'.format(filename, mode)) - if self.htsfile.format.compression == bgzf: - bgzfp = hts_get_bgzfp(self.htsfile) - if bgzfp and bgzf_check_EOF(bgzfp) == 0: - warn('[%s] Warning: no BGZF EOF marker; file may be truncated'.format(filename)) + self.check_truncation(ignore_truncation) with nogil: hdr = bcf_hdr_read(self.htsfile) @@ -3679,7 +4248,7 @@ cdef class VariantFile(HTSFile): try: self.header = makeVariantHeader(hdr) except ValueError: - raise ValueError("file `{}` does not have valid header (mode='{}') - is it VCF/BCF format?".format(filename, mode)) + raise ValueError('file `{}` does not have valid header (mode=`{}`) - is it VCF/BCF format?'.format(filename, mode)) if isinstance(self.filename, bytes): cfilename = self.filename @@ -3704,14 +4273,54 @@ cdef class VariantFile(HTSFile): if not self.is_stream: self.start_offset = self.tell() else: - raise ValueError("unknown mode {}".format(mode)) + raise ValueError('unknown mode {}'.format(mode)) def reset(self): """reset file position to beginning of file just after the header.""" return self.seek(self.start_offset) + def is_valid_tid(self, tid): + """ + return True if the numerical :term:`tid` is valid; False otherwise. + + returns -1 if reference is not known. + """ + if not self.is_open: + raise ValueError('I/O operation on closed file') + + cdef bcf_hdr_t *hdr = self.header.ptr + cdef int rid = tid + return 0 <= rid < hdr.n[BCF_DT_CTG] + + def get_tid(self, reference): + """ + return the numerical :term:`tid` corresponding to + :term:`reference` + + returns -1 if reference is not known. + """ + if not self.is_open: + raise ValueError('I/O operation on closed file') + + cdef vdict_t *d = self.header.ptr.dict[BCF_DT_CTG] + reference = force_bytes(reference) + cdef khint_t k = kh_get_vdict(d, reference) + return kh_val_vdict(d, k).id if k != kh_end(d) else -1 - def fetch(self, contig=None, start=None, stop=None, region=None, reopen=False): + def get_reference_name(self, tid): + """ + return :term:`reference` name corresponding to numerical :term:`tid` + """ + if not self.is_open: + raise ValueError('I/O operation on closed file') + + cdef bcf_hdr_t *hdr = self.header.ptr + cdef int rid = tid + if rid < 0 or rid >= hdr.n[BCF_DT_CTG]: + raise ValueError('Invalid tid') + return bcf_str_cache_get_charptr(bcf_hdr_id2name(hdr, rid)) + + def fetch(self, contig=None, start=None, stop=None, region=None, reopen=False, end=None, reference=None): """fetch records in a :term:`region` using 0-based indexing. The region is specified by :term:`contig`, *start* and *end*. Alternatively, a samtools :term:`region` string can be supplied. @@ -3747,12 +4356,21 @@ cdef class VariantFile(HTSFile): if not self.index: raise ValueError('fetch requires an index') + _, tid, start, stop = self.parse_region(contig, start, stop, region, + None, end=end, reference=reference) + + if contig is None: + contig = self.get_reference_name(tid) + self.is_reading = 1 - return self.index.fetch(self, contig, start, stop, region, reopen) + return self.index.fetch(self, contig, start, stop, reopen) - cpdef VariantRecord new_record(self): - """Create a new empty VariantRecord""" - return self.header.new_record() + def new_record(self, *args, **kwargs): + """Create a new empty :class:`VariantRecord`. + + See :meth:`VariantHeader.new_record` + """ + return self.header.new_record(*args, **kwargs) cpdef int write(self, VariantRecord record) except -1: """ @@ -3782,6 +4400,9 @@ cdef class VariantFile(HTSFile): msg = 'Invalid VariantRecord. Number of samples does not match header ({} vs {})' raise ValueError(msg.format(record.ptr.n_sample, bcf_hdr_nsamples(self.header.ptr))) + # Sync END annotation before writing + bcf_sync_end(record) + cdef int ret with nogil: diff --git a/pysam/libcbcftools.c b/pysam/libcbcftools.c new file mode 100644 index 000000000..a3c63a4e2 --- /dev/null +++ b/pysam/libcbcftools.c @@ -0,0 +1,2365 @@ +/* Generated by Cython 0.28.3 */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) + #error Cython requires Python 2.6+ or Python 3.3+. +#else +#define CYTHON_ABI "0_28_3" +#define CYTHON_FUTURE_DIVISION 0 +#include +#ifndef offsetof + #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif +#if !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#define __PYX_COMMA , +#ifndef HAVE_LONG_LONG + #if PY_VERSION_HEX >= 0x02070000 + #define HAVE_LONG_LONG + #endif +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif +#ifdef PYPY_VERSION + #define CYTHON_COMPILING_IN_PYPY 1 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 +#elif defined(PYSTON_VERSION) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 1 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 +#else + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #elif !defined(CYTHON_USE_PYTYPE_LOOKUP) + #define CYTHON_USE_PYTYPE_LOOKUP 1 + #endif + #if PY_MAJOR_VERSION < 3 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #elif !defined(CYTHON_USE_PYLONG_INTERNALS) + #define CYTHON_USE_PYLONG_INTERNALS 1 + #endif + #ifndef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 1 + #endif + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #if PY_VERSION_HEX < 0x030300F0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #elif !defined(CYTHON_USE_UNICODE_WRITER) + #define CYTHON_USE_UNICODE_WRITER 1 + #endif + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #ifndef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 1 + #endif + #ifndef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 1 + #endif + #ifndef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT (0 && PY_VERSION_HEX >= 0x03050000) + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) + #endif +#endif +#if !defined(CYTHON_FAST_PYCCALL) +#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) +#endif +#if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #undef SHIFT + #undef BASE + #undef MASK +#endif +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif +#ifndef __has_cpp_attribute + #define __has_cpp_attribute(x) 0 +#endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_MAYBE_UNUSED_VAR +# if defined(__cplusplus) + template void CYTHON_MAYBE_UNUSED_VAR( const T& ) { } +# else +# define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x) +# endif +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) +#ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned char uint8_t; + typedef unsigned int uint32_t; + #else + typedef unsigned __int8 uint8_t; + typedef unsigned __int32 uint32_t; + #endif + #endif +#else + #include +#endif +#ifndef CYTHON_FALLTHROUGH + #if defined(__cplusplus) && __cplusplus >= 201103L + #if __has_cpp_attribute(fallthrough) + #define CYTHON_FALLTHROUGH [[fallthrough]] + #elif __has_cpp_attribute(clang::fallthrough) + #define CYTHON_FALLTHROUGH [[clang::fallthrough]] + #elif __has_cpp_attribute(gnu::fallthrough) + #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_attribute(fallthrough) + #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) + #else + #define CYTHON_FALLTHROUGH + #endif + #endif + #if defined(__clang__ ) && defined(__apple_build_version__) + #if __apple_build_version__ < 7000000 + #undef CYTHON_FALLTHROUGH + #define CYTHON_FALLTHROUGH + #endif + #endif +#endif + +#ifndef CYTHON_INLINE + #if defined(__clang__) + #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) + #elif defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) + #define Py_OptimizeFlag 0 +#endif +#define __PYX_BUILD_PY_SSIZE_T "n" +#define CYTHON_FORMAT_SSIZE_T "z" +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyClass_Type +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyType_Type +#endif +#ifndef Py_TPFLAGS_CHECKTYPES + #define Py_TPFLAGS_CHECKTYPES 0 +#endif +#ifndef Py_TPFLAGS_HAVE_INDEX + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#ifndef Py_TPFLAGS_HAVE_NEWBUFFER + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#ifndef Py_TPFLAGS_HAVE_FINALIZE + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif +#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) + #ifndef METH_FASTCALL + #define METH_FASTCALL 0x80 + #endif + typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); + typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, + Py_ssize_t nargs, PyObject *kwnames); +#else + #define __Pyx_PyCFunctionFast _PyCFunctionFast + #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords +#endif +#if CYTHON_FAST_PYCCALL +#define __Pyx_PyFastCFunction_Check(func)\ + ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS))))) +#else +#define __Pyx_PyFastCFunction_Check(func) 0 +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) + #define PyObject_Malloc(s) PyMem_Malloc(s) + #define PyObject_Free(p) PyMem_Free(p) + #define PyObject_Realloc(p) PyMem_Realloc(p) +#endif +#if CYTHON_COMPILING_IN_PYSTON + #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno) +#else + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) +#endif +#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#elif PY_VERSION_HEX >= 0x03060000 + #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() +#elif PY_VERSION_HEX >= 0x03000000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#else + #define __Pyx_PyThreadState_Current _PyThreadState_Current +#endif +#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) +#include "pythread.h" +#define Py_tss_NEEDS_INIT 0 +typedef int Py_tss_t; +static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { + *key = PyThread_create_key(); + return 0; // PyThread_create_key reports success always +} +static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { + Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); + *key = Py_tss_NEEDS_INIT; + return key; +} +static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { + PyObject_Free(key); +} +static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { + return *key != Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { + PyThread_delete_key(*key); + *key = Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { + return PyThread_set_key_value(*key, value); +} +static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { + return PyThread_get_key_value(*key); +} +#endif // TSS (Thread Specific Storage) API +#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized) +#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) +#else +#define __Pyx_PyDict_NewPresized(n) PyDict_New() +#endif +#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS +#define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) +#else +#define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name) +#endif +#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) + #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) +#else + #define CYTHON_PEP393_ENABLED 0 + #define PyUnicode_1BYTE_KIND 1 + #define PyUnicode_2BYTE_KIND 2 + #define PyUnicode_4BYTE_KIND 4 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111) + #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) + #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) + #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) + #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) +#endif +#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) + #define PyObject_ASCII(o) PyObject_Repr(o) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact + #define PyObject_Unicode PyObject_Str +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) + #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) +#else + #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) +#endif +#if CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) +#else + #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif +#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY + #ifndef PyUnicode_InternFromString + #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) + #endif +#endif +#if PY_VERSION_HEX < 0x030200A4 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t PyInt_AsLong +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func)) +#else + #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) +#endif +#if CYTHON_USE_ASYNC_SLOTS + #if PY_VERSION_HEX >= 0x030500B1 + #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods + #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) + #else + #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) + #endif +#else + #define __Pyx_PyType_AsAsync(obj) NULL +#endif +#ifndef __Pyx_PyAsyncMethodsStruct + typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; + } __Pyx_PyAsyncMethodsStruct; +#endif + +#if defined(WIN32) || defined(MS_WINDOWS) + #define _USE_MATH_DEFINES +#endif +#include +#ifdef NAN +#define __PYX_NAN() ((float) NAN) +#else +static CYTHON_INLINE float __PYX_NAN() { + float value; + memset(&value, 0xFF, sizeof(value)); + return value; +} +#endif +#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) +#define __Pyx_truncl trunc +#else +#define __Pyx_truncl truncl +#endif + + +#define __PYX_ERR(f_index, lineno, Ln_error) \ +{ \ + __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \ +} + +#ifndef __PYX_EXTERN_C + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#define __PYX_HAVE__pysam__libcbcftools +#define __PYX_HAVE_API__pysam__libcbcftools +/* Early includes */ + +#include "bcftools.pysam.h" +#ifdef _OPENMP +#include +#endif /* _OPENMP */ + +#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) +#define CYTHON_WITHOUT_ASSERTIONS +#endif + +typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; + const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; + +#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0 +#define __PYX_DEFAULT_STRING_ENCODING "" +#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString +#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_uchar_cast(c) ((unsigned char)c) +#define __Pyx_long_cast(x) ((long)x) +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ + (sizeof(type) < sizeof(Py_ssize_t)) ||\ + (sizeof(type) > sizeof(Py_ssize_t) &&\ + likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX) &&\ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ + v == (type)PY_SSIZE_T_MIN))) ||\ + (sizeof(type) == sizeof(Py_ssize_t) &&\ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX))) ) +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #define __Pyx_sst_abs(value) std::abs(value) +#elif SIZEOF_INT >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) abs(value) +#elif SIZEOF_LONG >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) labs(value) +#elif defined (_MSC_VER) + #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define __Pyx_sst_abs(value) llabs(value) +#elif defined (__GNUC__) + #define __Pyx_sst_abs(value) __builtin_llabs(value) +#else + #define __Pyx_sst_abs(value) ((value<0) ? -value : value) +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#else + #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize +#endif +#define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) +static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { + const Py_UNICODE *u_end = u; + while (*u_end++) ; + return (size_t)(u_end - u - 1); +} +#define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) +#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode +#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode +#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) +#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); +#define __Pyx_PySequence_Tuple(obj)\ + (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +#if CYTHON_ASSUME_SAFE_MACROS +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) +#else +#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) +#endif +#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII +static int __Pyx_sys_getdefaultencoding_not_ascii; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + PyObject* ascii_chars_u = NULL; + PyObject* ascii_chars_b = NULL; + const char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + if (strcmp(default_encoding_c, "ascii") == 0) { + __Pyx_sys_getdefaultencoding_not_ascii = 0; + } else { + char ascii_chars[128]; + int c; + for (c = 0; c < 128; c++) { + ascii_chars[c] = c; + } + __Pyx_sys_getdefaultencoding_not_ascii = 1; + ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); + if (!ascii_chars_u) goto bad; + ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); + if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { + PyErr_Format( + PyExc_ValueError, + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", + default_encoding_c); + goto bad; + } + Py_DECREF(ascii_chars_u); + Py_DECREF(ascii_chars_b); + } + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + Py_XDECREF(ascii_chars_u); + Py_XDECREF(ascii_chars_b); + return -1; +} +#endif +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) +#else +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +static char* __PYX_DEFAULT_STRING_ENCODING; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c)); + if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; + strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + return -1; +} +#endif +#endif + + +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ +static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } + +static PyObject *__pyx_m = NULL; +static PyObject *__pyx_d; +static PyObject *__pyx_b; +static PyObject *__pyx_cython_runtime = NULL; +static PyObject *__pyx_empty_tuple; +static PyObject *__pyx_empty_bytes; +static PyObject *__pyx_empty_unicode; +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm= __FILE__; +static const char *__pyx_filename; + + +static const char *__pyx_f[] = { + "pysam/libcbcftools.pyx", +}; + +/*--- Type declarations ---*/ + +/* --- Runtime support code (head) --- */ +/* Refnanny.proto */ +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif +#if CYTHON_REFNANNY + typedef struct { + void (*INCREF)(void*, PyObject*, int); + void (*DECREF)(void*, PyObject*, int); + void (*GOTREF)(void*, PyObject*, int); + void (*GIVEREF)(void*, PyObject*, int); + void* (*SetupContext)(const char*, int, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); + #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; +#ifdef WITH_THREAD + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + if (acquire_gil) {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + PyGILState_Release(__pyx_gilstate_save);\ + } else {\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) +#endif + #define __Pyx_RefNannyFinishContext()\ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif +#define __Pyx_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_XDECREF(tmp);\ + } while (0) +#define __Pyx_DECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_DECREF(tmp);\ + } while (0) +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +/* PyObjectGetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) +#endif + +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; +#define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#define __Pyx_PyErr_Occurred() PyErr_Occurred() +#endif + +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) +#else +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#endif +#else +#define __Pyx_PyErr_Clear() PyErr_Clear() +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* CLineInTraceback.proto */ +#ifdef CYTHON_CLINE_IN_TRACEBACK +#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) +#else +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); +#endif + +/* CodeObjectCache.proto */ +typedef struct { + PyCodeObject* code_object; + int code_line; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); + +/* AddTraceback.proto */ +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* FastTypeChecks.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); +#else +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) +#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) +#endif +#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) + +/* CheckBinaryVersion.proto */ +static int __Pyx_check_binary_version(void); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + + +/* Module declarations from 'pysam.libcbcftools' */ +#define __Pyx_MODULE_NAME "pysam.libcbcftools" +extern int __pyx_module_is_main_pysam__libcbcftools; +int __pyx_module_is_main_pysam__libcbcftools = 0; + +/* Implementation of 'pysam.libcbcftools' */ +static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_py_bcftools[] = "py_bcftools"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_pysam_libcbcftools[] = "pysam.libcbcftools"; +static const char __pyx_k_pysam_libcbcftools_pyx[] = "pysam/libcbcftools.pyx"; +static PyObject *__pyx_n_s_cline_in_traceback; +static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_py_bcftools; +static PyObject *__pyx_n_s_pysam_libcbcftools; +static PyObject *__pyx_kp_s_pysam_libcbcftools_pyx; +static PyObject *__pyx_n_s_test; +static PyObject *__pyx_pf_5pysam_12libcbcftools_py_bcftools(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_codeobj_; +/* Late includes */ + +/* "pysam/libcbcftools.pyx":1 + * def py_bcftools(): # <<<<<<<<<<<<<< + * pass + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_12libcbcftools_1py_bcftools(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyMethodDef __pyx_mdef_5pysam_12libcbcftools_1py_bcftools = {"py_bcftools", (PyCFunction)__pyx_pw_5pysam_12libcbcftools_1py_bcftools, METH_NOARGS, 0}; +static PyObject *__pyx_pw_5pysam_12libcbcftools_1py_bcftools(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("py_bcftools (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_12libcbcftools_py_bcftools(__pyx_self); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_12libcbcftools_py_bcftools(CYTHON_UNUSED PyObject *__pyx_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("py_bcftools", 0); + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; + +#if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec_libcbcftools(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_libcbcftools}, + {0, NULL} +}; +#endif + +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + "libcbcftools", + 0, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #else + -1, /* m_size */ + #endif + __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else + NULL, /* m_reload */ + #endif + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ +}; +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_py_bcftools, __pyx_k_py_bcftools, sizeof(__pyx_k_py_bcftools), 0, 0, 1, 1}, + {&__pyx_n_s_pysam_libcbcftools, __pyx_k_pysam_libcbcftools, sizeof(__pyx_k_pysam_libcbcftools), 0, 0, 1, 1}, + {&__pyx_kp_s_pysam_libcbcftools_pyx, __pyx_k_pysam_libcbcftools_pyx, sizeof(__pyx_k_pysam_libcbcftools_pyx), 0, 0, 1, 0}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static int __Pyx_InitCachedBuiltins(void) { + return 0; +} + +static int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "pysam/libcbcftools.pyx":1 + * def py_bcftools(): # <<<<<<<<<<<<<< + * pass + */ + __pyx_codeobj_ = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcbcftools_pyx, __pyx_n_s_py_bcftools, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + return 0; + __pyx_L1_error:; + return -1; +} + +static int __Pyx_modinit_global_init_code(void); /*proto*/ +static int __Pyx_modinit_variable_export_code(void); /*proto*/ +static int __Pyx_modinit_function_export_code(void); /*proto*/ +static int __Pyx_modinit_type_init_code(void); /*proto*/ +static int __Pyx_modinit_type_import_code(void); /*proto*/ +static int __Pyx_modinit_variable_import_code(void); /*proto*/ +static int __Pyx_modinit_function_import_code(void); /*proto*/ + +static int __Pyx_modinit_global_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); + /*--- Global init code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); + /*--- Variable export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); + /*--- Function export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); + /*--- Variable import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); + /*--- Function import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + + +#if PY_MAJOR_VERSION < 3 +#ifdef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC void +#else +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#endif +#else +#ifdef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#endif +#endif +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4))) + #define CYTHON_SMALL_CODE __attribute__((optimize("Os"))) +#else + #define CYTHON_SMALL_CODE +#endif +#endif + + +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC initlibcbcftools(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC initlibcbcftools(void) +#else +__Pyx_PyMODINIT_FUNC PyInit_libcbcftools(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_libcbcftools(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) { + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + result = PyDict_SetItemString(moddict, to_name, value); + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + if (__pyx_m) + return __Pyx_NewRef(__pyx_m); + modname = PyObject_GetAttrString(spec, "name"); + if (unlikely(!modname)) goto bad; + module = PyModule_NewObject(modname); + Py_DECREF(modname); + if (unlikely(!module)) goto bad; + moddict = PyModule_GetDict(module); + if (unlikely(!moddict)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static int __pyx_pymod_exec_libcbcftools(PyObject *__pyx_pyinit_module) +#endif +#endif +{ + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0; + #elif PY_MAJOR_VERSION >= 3 + if (__pyx_m) return __Pyx_NewRef(__pyx_m); + #endif + #if CYTHON_REFNANNY +__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); +if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); +} +#endif + __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_libcbcftools(void)", 0); + if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + #ifdef WITH_THREAD /* Python build with threading support? */ + PyEval_InitThreads(); + #endif + #endif + /*--- Module creation code ---*/ + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_m = __pyx_pyinit_module; + Py_INCREF(__pyx_m); + #else + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("libcbcftools", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + #endif + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + #if CYTHON_COMPILING_IN_PYPY + Py_INCREF(__pyx_b); + #endif + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main_pysam__libcbcftools) { + if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "pysam.libcbcftools")) { + if (unlikely(PyDict_SetItemString(modules, "pysam.libcbcftools", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) + } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global type/function init code ---*/ + (void)__Pyx_modinit_global_init_code(); + (void)__Pyx_modinit_variable_export_code(); + (void)__Pyx_modinit_function_export_code(); + (void)__Pyx_modinit_type_init_code(); + (void)__Pyx_modinit_type_import_code(); + (void)__Pyx_modinit_variable_import_code(); + (void)__Pyx_modinit_function_import_code(); + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + + /* "pysam/libcbcftools.pyx":1 + * def py_bcftools(): # <<<<<<<<<<<<<< + * pass + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_12libcbcftools_1py_bcftools, NULL, __pyx_n_s_pysam_libcbcftools); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_py_bcftools, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /*--- Wrapped vars code ---*/ + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + if (__pyx_m) { + if (__pyx_d) { + __Pyx_AddTraceback("init pysam.libcbcftools", 0, __pyx_lineno, __pyx_filename); + } + Py_DECREF(__pyx_m); __pyx_m = 0; + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init pysam.libcbcftools"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if CYTHON_PEP489_MULTI_PHASE_INIT + return (__pyx_m != NULL) ? 0 : -1; + #elif PY_MAJOR_VERSION >= 3 + return __pyx_m; + #else + return; + #endif +} + +/* --- Runtime support code --- */ +/* Refnanny */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule((char *)modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; +} +#endif + +/* PyObjectGetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); +#endif + return PyObject_GetAttr(obj, attr_name); +} +#endif + +/* PyErrFetchRestore */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +} +#endif + +/* CLineInTraceback */ +#ifndef CYTHON_CLINE_IN_TRACEBACK +static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) { + PyObject *use_cline; + PyObject *ptype, *pvalue, *ptraceback; +#if CYTHON_COMPILING_IN_CPYTHON + PyObject **cython_runtime_dict; +#endif + if (unlikely(!__pyx_cython_runtime)) { + return c_line; + } + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); +#if CYTHON_COMPILING_IN_CPYTHON + cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); + if (likely(cython_runtime_dict)) { + use_cline = __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback); + } else +#endif + { + PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); + if (use_cline_obj) { + use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; + Py_DECREF(use_cline_obj); + } else { + PyErr_Clear(); + use_cline = NULL; + } + } + if (!use_cline) { + c_line = 0; + PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); + } + else if (PyObject_Not(use_cline) != 0) { + c_line = 0; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + return c_line; +} +#endif + +/* CodeObjectCache */ +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = start + (end - start) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} + +/* AddTraceback */ +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + #if PY_MAJOR_VERSION < 3 + py_srcfile = PyString_FromString(filename); + #else + py_srcfile = PyUnicode_FromString(filename); + #endif + if (!py_srcfile) goto bad; + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + #else + py_funcname = PyUnicode_FromString(funcname); + #endif + } + if (!py_funcname) goto bad; + py_code = __Pyx_PyCode_New( + 0, + 0, + 0, + 0, + 0, + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + Py_DECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + if (c_line) { + c_line = __Pyx_CLineForTraceback(tstate, c_line); + } + py_code = __pyx_find_code_object(c_line ? -c_line : py_line); + if (!py_code) { + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) goto bad; + __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); + } + py_frame = PyFrame_New( + tstate, /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + __Pyx_PyFrame_SetLineNumber(py_frame, py_line); + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} + +/* CIntToPy */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) -1, const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); + } +} + +/* CIntFromPyVerify */ +#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) +#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) +#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ + {\ + func_type value = func_value;\ + if (sizeof(target_type) < sizeof(func_type)) {\ + if (unlikely(value != (func_type) (target_type) value)) {\ + func_type zero = 0;\ + if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ + return (target_type) -1;\ + if (is_unsigned && unlikely(value < zero))\ + goto raise_neg_overflow;\ + else\ + goto raise_overflow;\ + }\ + }\ + return (target_type) value;\ + } + +/* CIntFromPy */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { + const long neg_one = (long) -1, const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(long) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (long) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { + return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { + return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { + return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (long) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(long) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) + case -2: + if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + } +#endif + if (sizeof(long) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + long val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (long) -1; + } + } else { + long val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to long"); + return (long) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; +} + +/* CIntFromPy */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { + const int neg_one = (int) -1, const_zero = (int) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(int) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { + return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { + return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { + return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(int) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) + case -2: + if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + } +#endif + if (sizeof(int) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + int val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (int) -1; + } + } else { + int val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; +} + +/* FastTypeChecks */ +#if CYTHON_COMPILING_IN_CPYTHON +static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { + while (a) { + a = a->tp_base; + if (a == b) + return 1; + } + return b == &PyBaseObject_Type; +} +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (a == b) return 1; + mro = a->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(a, b); +} +#if PY_MAJOR_VERSION == 2 +static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { + PyObject *exception, *value, *tb; + int res; + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&exception, &value, &tb); + res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + if (!res) { + res = PyObject_IsSubclass(err, exc_type2); + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + } + __Pyx_ErrRestore(exception, value, tb); + return res; +} +#else +static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { + int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; + if (!res) { + res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + } + return res; +} +#endif +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) { + if (likely(err == exc_type)) return 1; + if (likely(PyExceptionClass_Check(err))) { + return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type); + } + return PyErr_GivenExceptionMatches(err, exc_type); +} +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) { + if (likely(err == exc_type1 || err == exc_type2)) return 1; + if (likely(PyExceptionClass_Check(err))) { + return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2); + } + return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2)); +} +#endif + +/* CheckBinaryVersion */ +static int __Pyx_check_binary_version(void) { + char ctversion[4], rtversion[4]; + PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); + PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); + if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compiletime version %s of module '%.100s' " + "does not match runtime version %s", + ctversion, __Pyx_MODULE_NAME, rtversion); + return PyErr_WarnEx(NULL, message, 1); + } + return 0; +} + +/* InitStrings */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION < 3 + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + #else + if (t->is_unicode | t->is_str) { + if (t->intern) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->encoding) { + *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); + } else { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); + } + } else { + *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); + } + #endif + if (!*t->p) + return -1; + if (PyObject_Hash(*t->p) == -1) + return -1; + ++t; + } + return 0; +} + +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { + return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); +} +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { + Py_ssize_t ignore; + return __Pyx_PyObject_AsStringAndSize(o, &ignore); +} +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#if !CYTHON_PEP393_ENABLED +static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + char* defenc_c; + PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); + if (!defenc) return NULL; + defenc_c = PyBytes_AS_STRING(defenc); +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + { + char* end = defenc_c + PyBytes_GET_SIZE(defenc); + char* c; + for (c = defenc_c; c < end; c++) { + if ((unsigned char) (*c) >= 128) { + PyUnicode_AsASCIIString(o); + return NULL; + } + } + } +#endif + *length = PyBytes_GET_SIZE(defenc); + return defenc_c; +} +#else +static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + if (likely(PyUnicode_IS_ASCII(o))) { + *length = PyUnicode_GET_LENGTH(o); + return PyUnicode_AsUTF8(o); + } else { + PyUnicode_AsASCIIString(o); + return NULL; + } +#else + return PyUnicode_AsUTF8AndSize(o, length); +#endif +} +#endif +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT + if ( +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + __Pyx_sys_getdefaultencoding_not_ascii && +#endif + PyUnicode_Check(o)) { + return __Pyx_PyUnicode_AsStringAndSize(o, length); + } else +#endif +#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif + { + char* result; + int r = PyBytes_AsStringAndSize(o, &result, length); + if (unlikely(r < 0)) { + return NULL; + } else { + return result; + } + } +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} +static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(result)) { + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "__int__ returned non-int (type %.200s). " + "The ability to return an instance of a strict subclass of int " + "is deprecated, and may be removed in a future version of Python.", + Py_TYPE(result)->tp_name)) { + Py_DECREF(result); + return NULL; + } + return result; + } +#endif + PyErr_Format(PyExc_TypeError, + "__%.4s__ returned non-%.4s (type %.200s)", + type_name, type_name, Py_TYPE(result)->tp_name); + Py_DECREF(result); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { +#if CYTHON_USE_TYPE_SLOTS + PyNumberMethods *m; +#endif + const char *name = NULL; + PyObject *res = NULL; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x) || PyLong_Check(x))) +#else + if (likely(PyLong_Check(x))) +#endif + return __Pyx_NewRef(x); +#if CYTHON_USE_TYPE_SLOTS + m = Py_TYPE(x)->tp_as_number; + #if PY_MAJOR_VERSION < 3 + if (m && m->nb_int) { + name = "int"; + res = m->nb_int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = m->nb_long(x); + } + #else + if (likely(m && m->nb_int)) { + name = "int"; + res = m->nb_int(x); + } + #endif +#else + if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { + res = PyNumber_Int(x); + } +#endif + if (likely(res)) { +#if PY_MAJOR_VERSION < 3 + if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { +#else + if (unlikely(!PyLong_CheckExact(res))) { +#endif + return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) { + if (sizeof(Py_ssize_t) >= sizeof(long)) + return PyInt_AS_LONG(b); + else + return PyInt_AsSsize_t(x); + } +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)b)->ob_digit; + const Py_ssize_t size = Py_SIZE(b); + if (likely(__Pyx_sst_abs(size) <= 1)) { + ival = likely(size) ? digits[0] : 0; + if (size == -1) ival = -ival; + return ival; + } else { + switch (size) { + case 2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + } + } + #endif + return PyLong_AsSsize_t(b); + } + x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { + return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); +} +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { + return PyInt_FromSize_t(ival); +} + + +#endif /* Py_PYTHON_H */ diff --git a/pysam/libcbcftools.pxd b/pysam/libcbcftools.pxd new file mode 100644 index 000000000..f1c8d764d --- /dev/null +++ b/pysam/libcbcftools.pxd @@ -0,0 +1,9 @@ +cdef extern from "bcftools.pysam.h": + + int bcftools_main(int argc, char *argv[]) + void bcftools_set_stderr(int fd) + void bcftools_unset_stderr() + void bcftools_set_stdout(int fd) + void bcftools_set_stdout_fn(const char *) + void bcftools_unset_stdout() + void bcftools_set_optind(int) diff --git a/pysam/libcbcftools.pyx b/pysam/libcbcftools.pyx new file mode 100644 index 000000000..8e9038841 --- /dev/null +++ b/pysam/libcbcftools.pyx @@ -0,0 +1,2 @@ +def py_bcftools(): + pass diff --git a/pysam/libcbgzf.c b/pysam/libcbgzf.c index 5af77c4d6..0397915cb 100644 --- a/pysam/libcbgzf.c +++ b/pysam/libcbgzf.c @@ -567,8 +567,8 @@ static CYTHON_INLINE float __PYX_NAN() { #include #include #include "pythread.h" -#include "pysam_util.h" #include +#include "stdarg.h" #include "htslib/kstring.h" #include "htslib_util.h" #include "htslib/hfile.h" @@ -579,6 +579,7 @@ static CYTHON_INLINE float __PYX_NAN() { #include "htslib/tbx.h" #include "htslib/vcf.h" #include "htslib/vcfutils.h" +#include "htslib/cram.h" #ifdef _OPENMP #include #endif /* _OPENMP */ @@ -919,7 +920,7 @@ struct __pyx_opt_args_5pysam_9libcutils_force_bytes { PyObject *encoding; }; -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -933,6 +934,7 @@ struct __pyx_obj_5pysam_10libchtslib_HTSFile { int64_t start_offset; PyObject *filename; PyObject *mode; + PyObject *threads; PyObject *index_filename; int is_stream; int is_remote; @@ -940,7 +942,7 @@ struct __pyx_obj_5pysam_10libchtslib_HTSFile { }; -/* "pysam/libcbgzf.pyx":27 +/* "pysam/libcbgzf.pyx":28 * * * cdef class BGZFile(object): # <<<<<<<<<<<<<< @@ -956,7 +958,7 @@ struct __pyx_obj_5pysam_8libcbgzf_BGZFile { -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -1505,10 +1507,8 @@ static PyTypeObject *__pyx_ptype_7cpython_5array_array = 0; static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *, char *, Py_ssize_t); /*proto*/ /* Module declarations from 'pysam.libcutils' */ -static PyObject *(*__pyx_f_5pysam_9libcutils_charptr_to_str)(char const *, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str *__pyx_optional_args); /*proto*/ -static PyObject *(*__pyx_f_5pysam_9libcutils_charptr_to_str_w_len)(char const *, size_t, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str_w_len *__pyx_optional_args); /*proto*/ -static PyObject *(*__pyx_f_5pysam_9libcutils_force_str)(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_str *__pyx_optional_args); /*proto*/ static PyObject *(*__pyx_f_5pysam_9libcutils_force_bytes)(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_bytes *__pyx_optional_args); /*proto*/ +static PyObject *(*__pyx_f_5pysam_9libcutils_encode_filename)(PyObject *); /*proto*/ /* Module declarations from 'posix.types' */ @@ -1524,8 +1524,8 @@ int __pyx_module_is_main_pysam__libcbgzf = 0; /* Implementation of 'pysam.libcbgzf' */ static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_IOError; -static PyObject *__pyx_builtin_OSError; static PyObject *__pyx_builtin_AttributeError; +static PyObject *__pyx_builtin_StopIteration; static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_MemoryError; static const char __pyx_k_U[] = "U"; @@ -1557,10 +1557,10 @@ static const char __pyx_k_reduce[] = "__reduce__"; static const char __pyx_k_whence[] = "whence"; static const char __pyx_k_BGZFile[] = "BGZFile"; static const char __pyx_k_IOError[] = "IOError"; -static const char __pyx_k_OSError[] = "OSError"; static const char __pyx_k_SEEK_SET[] = "SEEK_SET"; static const char __pyx_k_filename[] = "filename"; static const char __pyx_k_getstate[] = "__getstate__"; +static const char __pyx_k_readline[] = "readline"; static const char __pyx_k_setstate[] = "__setstate__"; static const char __pyx_k_TypeError[] = "TypeError"; static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; @@ -1569,6 +1569,7 @@ static const char __pyx_k_memoryview[] = "memoryview"; static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; static const char __pyx_k_BUFFER_SIZE[] = "BUFFER_SIZE"; static const char __pyx_k_MemoryError[] = "MemoryError"; +static const char __pyx_k_StopIteration[] = "StopIteration"; static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; static const char __pyx_k_AttributeError[] = "AttributeError"; static const char __pyx_k_Invalid_mode_r[] = "Invalid mode: {!r}"; @@ -1588,6 +1589,7 @@ static const char __pyx_k_read_on_closed_BGZFile_object[] = "read() on closed BG static const char __pyx_k_seek_on_closed_BGZFile_object[] = "seek() on closed BGZFile object"; static const char __pyx_k_write_on_closed_BGZFile_object[] = "write() on closed BGZFile object"; static const char __pyx_k_rewind_on_closed_BGZFile_object[] = "rewind() on closed BGZFile object"; +static const char __pyx_k_Error_in_tell_on_BGZFFile_object[] = "Error in tell on BGZFFile object"; static const char __pyx_k_Error_reading_line_in_BGZFFile_o[] = "Error reading line in BGZFFile object"; static const char __pyx_k_Functions_that_read_and_write_bl[] = "Functions that read and write block gzipped files.\n\nThe user of the file doesn't have to worry about the compression\nand random access is allowed if an index file is present."; static const char __pyx_k_read_on_write_only_BGZFile_objec[] = "read() on write-only BGZFile object"; @@ -1606,15 +1608,16 @@ static PyObject *__pyx_n_s_EBADF; static PyObject *__pyx_kp_s_Error_building_bgzf_index; static PyObject *__pyx_kp_s_Error_closing_BGZFile_object; static PyObject *__pyx_kp_s_Error_flushing_BGZFile_object; +static PyObject *__pyx_kp_s_Error_in_tell_on_BGZFFile_object; static PyObject *__pyx_kp_s_Error_reading_from_BGZFile; static PyObject *__pyx_kp_s_Error_reading_line_in_BGZFFile_o; static PyObject *__pyx_kp_s_Error_seeking_BGZFFile_object; static PyObject *__pyx_n_s_IOError; static PyObject *__pyx_kp_s_Invalid_mode_r; static PyObject *__pyx_n_s_MemoryError; -static PyObject *__pyx_n_s_OSError; static PyObject *__pyx_n_s_SEEK_SET; static PyObject *__pyx_kp_s_Seek_from_end_not_supported; +static PyObject *__pyx_n_s_StopIteration; static PyObject *__pyx_n_s_TypeError; static PyObject *__pyx_n_s_U; static PyObject *__pyx_n_s_ValueError; @@ -1643,6 +1646,7 @@ static PyObject *__pyx_n_s_rb; static PyObject *__pyx_kp_s_read_on_closed_BGZFile_object; static PyObject *__pyx_kp_s_read_on_write_only_BGZFile_objec; static PyObject *__pyx_kp_s_readable_on_closed_BGZFile_objec; +static PyObject *__pyx_n_s_readline; static PyObject *__pyx_kp_s_readline_on_closed_BGZFile_objec; static PyObject *__pyx_n_s_reduce; static PyObject *__pyx_n_s_reduce_cython; @@ -1675,16 +1679,21 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_18rewind(struct __pyx_obj_5p static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_20readable(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_22writable(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_24seekable(CYTHON_UNUSED struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self, PyObject *__pyx_v_offset, PyObject *__pyx_v_whence); /* proto */ -static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_28readline(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_size); /* proto */ -static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_30__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_32__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26tell(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_28seek(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self, PyObject *__pyx_v_offset, PyObject *__pyx_v_whence); /* proto */ +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_30readline(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_size); /* proto */ +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_32__iter__(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_34__next__(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_4name___get__(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_5index___get__(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_36__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_38__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags); /* proto */ static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ static PyObject *__pyx_tp_new_5pysam_8libcbgzf_BGZFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_int_0; static PyObject *__pyx_int_neg_1; -static PyObject *__pyx_k__17; +static PyObject *__pyx_k__19; static PyObject *__pyx_tuple_; static PyObject *__pyx_tuple__2; static PyObject *__pyx_tuple__3; @@ -1700,17 +1709,19 @@ static PyObject *__pyx_tuple__13; static PyObject *__pyx_tuple__14; static PyObject *__pyx_tuple__15; static PyObject *__pyx_tuple__16; +static PyObject *__pyx_tuple__17; static PyObject *__pyx_tuple__18; -static PyObject *__pyx_tuple__19; static PyObject *__pyx_tuple__20; static PyObject *__pyx_tuple__21; static PyObject *__pyx_tuple__22; static PyObject *__pyx_tuple__23; static PyObject *__pyx_tuple__24; +static PyObject *__pyx_tuple__25; +static PyObject *__pyx_tuple__26; /* Late includes */ -/* "pysam/libcbgzf.pyx":37 - * cdef bytes name, index +/* "pysam/libcbgzf.pyx":38 + * cdef readonly object name, index * * def __init__(self, filename, mode=None, index=None): # <<<<<<<<<<<<<< * """Constructor for the BGZFile class. @@ -1767,7 +1778,7 @@ static int __pyx_pw_5pysam_8libcbgzf_7BGZFile_1__init__(PyObject *__pyx_v_self, } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 37, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 38, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -1786,7 +1797,7 @@ static int __pyx_pw_5pysam_8libcbgzf_7BGZFile_1__init__(PyObject *__pyx_v_self, } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 37, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 38, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbgzf.BGZFile.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1814,40 +1825,40 @@ static int __pyx_pf_5pysam_8libcbgzf_7BGZFile___init__(struct __pyx_obj_5pysam_8 __Pyx_RefNannySetupContext("__init__", 0); __Pyx_INCREF(__pyx_v_mode); - /* "pysam/libcbgzf.pyx":46 + /* "pysam/libcbgzf.pyx":47 * 'wb', 'a' and 'ab', and 'x' and 'xb'. * """ * if mode and ('t' in mode or 'U' in mode): # <<<<<<<<<<<<<< * raise ValueError("Invalid mode: {!r}".format(mode)) * if not mode: */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_mode); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 46, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_mode); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 47, __pyx_L1_error) if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L4_bool_binop_done; } - __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_t, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 46, __pyx_L1_error) + __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_t, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 47, __pyx_L1_error) __pyx_t_3 = (__pyx_t_2 != 0); if (!__pyx_t_3) { } else { __pyx_t_1 = __pyx_t_3; goto __pyx_L4_bool_binop_done; } - __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_U, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 46, __pyx_L1_error) + __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_U, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 47, __pyx_L1_error) __pyx_t_2 = (__pyx_t_3 != 0); __pyx_t_1 = __pyx_t_2; __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":47 + /* "pysam/libcbgzf.pyx":48 * """ * if mode and ('t' in mode or 'U' in mode): * raise ValueError("Invalid mode: {!r}".format(mode)) # <<<<<<<<<<<<<< * if not mode: * mode = 'rb' */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_mode_r, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 47, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_mode_r, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { @@ -1860,13 +1871,13 @@ static int __pyx_pf_5pysam_8libcbgzf_7BGZFile___init__(struct __pyx_obj_5pysam_8 } } if (!__pyx_t_6) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_mode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 47, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_mode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_mode}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 47, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_4); } else @@ -1874,32 +1885,32 @@ static int __pyx_pf_5pysam_8libcbgzf_7BGZFile___init__(struct __pyx_obj_5pysam_8 #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_mode}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 47, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_4); } else #endif { - __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 47, __pyx_L1_error) + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v_mode); __Pyx_GIVEREF(__pyx_v_mode); PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_mode); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 47, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 47, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 47, __pyx_L1_error) + __PYX_ERR(0, 48, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":46 + /* "pysam/libcbgzf.pyx":47 * 'wb', 'a' and 'ab', and 'x' and 'xb'. * """ * if mode and ('t' in mode or 'U' in mode): # <<<<<<<<<<<<<< @@ -1908,101 +1919,115 @@ static int __pyx_pf_5pysam_8libcbgzf_7BGZFile___init__(struct __pyx_obj_5pysam_8 */ } - /* "pysam/libcbgzf.pyx":48 + /* "pysam/libcbgzf.pyx":49 * if mode and ('t' in mode or 'U' in mode): * raise ValueError("Invalid mode: {!r}".format(mode)) * if not mode: # <<<<<<<<<<<<<< * mode = 'rb' - * if mode and 'b' not in mode: + * elif mode and 'b' not in mode: */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_mode); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 48, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_mode); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 49, __pyx_L1_error) __pyx_t_2 = ((!__pyx_t_1) != 0); if (__pyx_t_2) { - /* "pysam/libcbgzf.pyx":49 + /* "pysam/libcbgzf.pyx":50 * raise ValueError("Invalid mode: {!r}".format(mode)) * if not mode: * mode = 'rb' # <<<<<<<<<<<<<< - * if mode and 'b' not in mode: + * elif mode and 'b' not in mode: * mode += 'b' */ __Pyx_INCREF(__pyx_n_s_rb); __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_rb); - /* "pysam/libcbgzf.pyx":48 + /* "pysam/libcbgzf.pyx":49 * if mode and ('t' in mode or 'U' in mode): * raise ValueError("Invalid mode: {!r}".format(mode)) * if not mode: # <<<<<<<<<<<<<< * mode = 'rb' - * if mode and 'b' not in mode: + * elif mode and 'b' not in mode: */ + goto __pyx_L7; } - /* "pysam/libcbgzf.pyx":50 + /* "pysam/libcbgzf.pyx":51 * if not mode: * mode = 'rb' - * if mode and 'b' not in mode: # <<<<<<<<<<<<<< + * elif mode and 'b' not in mode: # <<<<<<<<<<<<<< * mode += 'b' - * self.name = force_bytes(filename) + * */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_mode); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 50, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_mode); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 51, __pyx_L1_error) if (__pyx_t_1) { } else { __pyx_t_2 = __pyx_t_1; - goto __pyx_L9_bool_binop_done; + goto __pyx_L8_bool_binop_done; } - __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_b, __pyx_v_mode, Py_NE)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 50, __pyx_L1_error) + __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_b, __pyx_v_mode, Py_NE)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 51, __pyx_L1_error) __pyx_t_3 = (__pyx_t_1 != 0); __pyx_t_2 = __pyx_t_3; - __pyx_L9_bool_binop_done:; + __pyx_L8_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcbgzf.pyx":51 + /* "pysam/libcbgzf.pyx":52 * mode = 'rb' - * if mode and 'b' not in mode: + * elif mode and 'b' not in mode: * mode += 'b' # <<<<<<<<<<<<<< - * self.name = force_bytes(filename) - * self.index = force_bytes(index) if index is not None else None + * + * mode = force_bytes(mode) */ - __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_mode, __pyx_n_s_b); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 51, __pyx_L1_error) + __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_mode, __pyx_n_s_b); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_mode, __pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libcbgzf.pyx":50 + /* "pysam/libcbgzf.pyx":51 * if not mode: * mode = 'rb' - * if mode and 'b' not in mode: # <<<<<<<<<<<<<< + * elif mode and 'b' not in mode: # <<<<<<<<<<<<<< * mode += 'b' - * self.name = force_bytes(filename) + * */ } + __pyx_L7:; - /* "pysam/libcbgzf.pyx":52 - * if mode and 'b' not in mode: + /* "pysam/libcbgzf.pyx":54 * mode += 'b' - * self.name = force_bytes(filename) # <<<<<<<<<<<<<< - * self.index = force_bytes(index) if index is not None else None - * self.bgzf = bgzf_open(self.name, mode) + * + * mode = force_bytes(mode) # <<<<<<<<<<<<<< + * + * self.name = encode_filename(filename) + */ + __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_mode, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 54, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF_SET(__pyx_v_mode, __pyx_t_5); + __pyx_t_5 = 0; + + /* "pysam/libcbgzf.pyx":56 + * mode = force_bytes(mode) + * + * self.name = encode_filename(filename) # <<<<<<<<<<<<<< + * self.index = encode_filename(index) if index is not None else None + * */ - __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 52, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 56, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __Pyx_GOTREF(__pyx_v_self->name); __Pyx_DECREF(__pyx_v_self->name); - __pyx_v_self->name = ((PyObject*)__pyx_t_5); + __pyx_v_self->name = __pyx_t_5; __pyx_t_5 = 0; - /* "pysam/libcbgzf.pyx":53 - * mode += 'b' - * self.name = force_bytes(filename) - * self.index = force_bytes(index) if index is not None else None # <<<<<<<<<<<<<< - * self.bgzf = bgzf_open(self.name, mode) + /* "pysam/libcbgzf.pyx":57 + * + * self.name = encode_filename(filename) + * self.index = encode_filename(index) if index is not None else None # <<<<<<<<<<<<<< * + * self.bgzf = bgzf_open(self.name, mode) */ __pyx_t_2 = (__pyx_v_index != Py_None); if ((__pyx_t_2 != 0)) { - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_index, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 53, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_index); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 57, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __pyx_t_4; __pyx_t_4 = 0; @@ -2013,25 +2038,21 @@ static int __pyx_pf_5pysam_8libcbgzf_7BGZFile___init__(struct __pyx_obj_5pysam_8 __Pyx_GIVEREF(__pyx_t_5); __Pyx_GOTREF(__pyx_v_self->index); __Pyx_DECREF(__pyx_v_self->index); - __pyx_v_self->index = ((PyObject*)__pyx_t_5); + __pyx_v_self->index = __pyx_t_5; __pyx_t_5 = 0; - /* "pysam/libcbgzf.pyx":54 - * self.name = force_bytes(filename) - * self.index = force_bytes(index) if index is not None else None + /* "pysam/libcbgzf.pyx":59 + * self.index = encode_filename(index) if index is not None else None + * * self.bgzf = bgzf_open(self.name, mode) # <<<<<<<<<<<<<< * * if self.bgzf.is_write and index is not None and bgzf_index_build_init(self.bgzf) < 0: */ - if (unlikely(__pyx_v_self->name == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 54, __pyx_L1_error) - } - __pyx_t_8 = __Pyx_PyBytes_AsString(__pyx_v_self->name); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 54, __pyx_L1_error) - __pyx_t_9 = __Pyx_PyObject_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 54, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_AsString(__pyx_v_self->name); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 59, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 59, __pyx_L1_error) __pyx_v_self->bgzf = bgzf_open(__pyx_t_8, __pyx_t_9); - /* "pysam/libcbgzf.pyx":56 + /* "pysam/libcbgzf.pyx":61 * self.bgzf = bgzf_open(self.name, mode) * * if self.bgzf.is_write and index is not None and bgzf_index_build_init(self.bgzf) < 0: # <<<<<<<<<<<<<< @@ -2042,34 +2063,34 @@ static int __pyx_pf_5pysam_8libcbgzf_7BGZFile___init__(struct __pyx_obj_5pysam_8 if (__pyx_t_3) { } else { __pyx_t_2 = __pyx_t_3; - goto __pyx_L12_bool_binop_done; + goto __pyx_L11_bool_binop_done; } __pyx_t_3 = (__pyx_v_index != Py_None); __pyx_t_1 = (__pyx_t_3 != 0); if (__pyx_t_1) { } else { __pyx_t_2 = __pyx_t_1; - goto __pyx_L12_bool_binop_done; + goto __pyx_L11_bool_binop_done; } __pyx_t_1 = ((bgzf_index_build_init(__pyx_v_self->bgzf) < 0) != 0); __pyx_t_2 = __pyx_t_1; - __pyx_L12_bool_binop_done:; + __pyx_L11_bool_binop_done:; if (unlikely(__pyx_t_2)) { - /* "pysam/libcbgzf.pyx":57 + /* "pysam/libcbgzf.pyx":62 * * if self.bgzf.is_write and index is not None and bgzf_index_build_init(self.bgzf) < 0: * raise IOError('Error building bgzf index') # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 57, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 62, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 57, __pyx_L1_error) + __PYX_ERR(0, 62, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":56 + /* "pysam/libcbgzf.pyx":61 * self.bgzf = bgzf_open(self.name, mode) * * if self.bgzf.is_write and index is not None and bgzf_index_build_init(self.bgzf) < 0: # <<<<<<<<<<<<<< @@ -2078,8 +2099,8 @@ static int __pyx_pf_5pysam_8libcbgzf_7BGZFile___init__(struct __pyx_obj_5pysam_8 */ } - /* "pysam/libcbgzf.pyx":37 - * cdef bytes name, index + /* "pysam/libcbgzf.pyx":38 + * cdef readonly object name, index * * def __init__(self, filename, mode=None, index=None): # <<<<<<<<<<<<<< * """Constructor for the BGZFile class. @@ -2102,7 +2123,7 @@ static int __pyx_pf_5pysam_8libcbgzf_7BGZFile___init__(struct __pyx_obj_5pysam_8 return __pyx_r; } -/* "pysam/libcbgzf.pyx":59 +/* "pysam/libcbgzf.pyx":64 * raise IOError('Error building bgzf index') * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -2128,14 +2149,14 @@ static void __pyx_pf_5pysam_8libcbgzf_7BGZFile_2__dealloc__(struct __pyx_obj_5py PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "pysam/libcbgzf.pyx":60 + /* "pysam/libcbgzf.pyx":65 * * def __dealloc__(self): * self.close() # <<<<<<<<<<<<<< * - * def write(self,data): + * def write(self, data): */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 65, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -2148,16 +2169,16 @@ static void __pyx_pf_5pysam_8libcbgzf_7BGZFile_2__dealloc__(struct __pyx_obj_5py } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbgzf.pyx":59 + /* "pysam/libcbgzf.pyx":64 * raise IOError('Error building bgzf index') * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -2176,10 +2197,10 @@ static void __pyx_pf_5pysam_8libcbgzf_7BGZFile_2__dealloc__(struct __pyx_obj_5py __Pyx_RefNannyFinishContext(); } -/* "pysam/libcbgzf.pyx":62 +/* "pysam/libcbgzf.pyx":67 * self.close() * - * def write(self,data): # <<<<<<<<<<<<<< + * def write(self, data): # <<<<<<<<<<<<<< * if not self.bgzf: * raise ValueError("write() on closed BGZFile object") */ @@ -2212,9 +2233,9 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_4write(struct __pyx_obj_5pys __Pyx_RefNannySetupContext("write", 0); __Pyx_INCREF(__pyx_v_data); - /* "pysam/libcbgzf.pyx":63 + /* "pysam/libcbgzf.pyx":68 * - * def write(self,data): + * def write(self, data): * if not self.bgzf: # <<<<<<<<<<<<<< * raise ValueError("write() on closed BGZFile object") * @@ -2222,60 +2243,60 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_4write(struct __pyx_obj_5pys __pyx_t_1 = ((!(__pyx_v_self->bgzf != 0)) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":64 - * def write(self,data): + /* "pysam/libcbgzf.pyx":69 + * def write(self, data): * if not self.bgzf: * raise ValueError("write() on closed BGZFile object") # <<<<<<<<<<<<<< * * if not self.bgzf.is_write: */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 64, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 64, __pyx_L1_error) + __PYX_ERR(0, 69, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":63 + /* "pysam/libcbgzf.pyx":68 * - * def write(self,data): + * def write(self, data): * if not self.bgzf: # <<<<<<<<<<<<<< * raise ValueError("write() on closed BGZFile object") * */ } - /* "pysam/libcbgzf.pyx":66 + /* "pysam/libcbgzf.pyx":71 * raise ValueError("write() on closed BGZFile object") * * if not self.bgzf.is_write: # <<<<<<<<<<<<<< * import errno - * raise OSError(errno.EBADF, "write() on read-only BGZFile object") + * raise IOError(errno.EBADF, "write() on read-only BGZFile object") */ __pyx_t_1 = ((!(__pyx_v_self->bgzf->is_write != 0)) != 0); if (__pyx_t_1) { - /* "pysam/libcbgzf.pyx":67 + /* "pysam/libcbgzf.pyx":72 * * if not self.bgzf.is_write: * import errno # <<<<<<<<<<<<<< - * raise OSError(errno.EBADF, "write() on read-only BGZFile object") + * raise IOError(errno.EBADF, "write() on read-only BGZFile object") * */ - __pyx_t_2 = __Pyx_Import(__pyx_n_s_errno, 0, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L1_error) + __pyx_t_2 = __Pyx_Import(__pyx_n_s_errno, 0, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_errno = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libcbgzf.pyx":68 + /* "pysam/libcbgzf.pyx":73 * if not self.bgzf.is_write: * import errno - * raise OSError(errno.EBADF, "write() on read-only BGZFile object") # <<<<<<<<<<<<<< + * raise IOError(errno.EBADF, "write() on read-only BGZFile object") # <<<<<<<<<<<<<< * * if isinstance(data, bytes): */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_errno, __pyx_n_s_EBADF); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_errno, __pyx_n_s_EBADF); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 73, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 73, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); @@ -2283,24 +2304,24 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_4write(struct __pyx_obj_5pys __Pyx_GIVEREF(__pyx_kp_s_write_on_read_only_BGZFile_objec); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_s_write_on_read_only_BGZFile_objec); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 73, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 68, __pyx_L1_error) + __PYX_ERR(0, 73, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":66 + /* "pysam/libcbgzf.pyx":71 * raise ValueError("write() on closed BGZFile object") * * if not self.bgzf.is_write: # <<<<<<<<<<<<<< * import errno - * raise OSError(errno.EBADF, "write() on read-only BGZFile object") + * raise IOError(errno.EBADF, "write() on read-only BGZFile object") */ } - /* "pysam/libcbgzf.pyx":70 - * raise OSError(errno.EBADF, "write() on read-only BGZFile object") + /* "pysam/libcbgzf.pyx":75 + * raise IOError(errno.EBADF, "write() on read-only BGZFile object") * * if isinstance(data, bytes): # <<<<<<<<<<<<<< * length = len(data) @@ -2310,21 +2331,21 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_4write(struct __pyx_obj_5pys __pyx_t_4 = (__pyx_t_1 != 0); if (__pyx_t_4) { - /* "pysam/libcbgzf.pyx":71 + /* "pysam/libcbgzf.pyx":76 * * if isinstance(data, bytes): * length = len(data) # <<<<<<<<<<<<<< * else: * # accept any data that supports the buffer protocol */ - __pyx_t_5 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 71, __pyx_L1_error) - __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_5 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 76, __pyx_L1_error) + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_length = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libcbgzf.pyx":70 - * raise OSError(errno.EBADF, "write() on read-only BGZFile object") + /* "pysam/libcbgzf.pyx":75 + * raise IOError(errno.EBADF, "write() on read-only BGZFile object") * * if isinstance(data, bytes): # <<<<<<<<<<<<<< * length = len(data) @@ -2333,7 +2354,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_4write(struct __pyx_obj_5pys goto __pyx_L5; } - /* "pysam/libcbgzf.pyx":74 + /* "pysam/libcbgzf.pyx":79 * else: * # accept any data that supports the buffer protocol * data = memoryview(data) # <<<<<<<<<<<<<< @@ -2341,64 +2362,64 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_4write(struct __pyx_obj_5pys * */ /*else*/ { - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_memoryview); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 74, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_memoryview); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 74, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_data, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcbgzf.pyx":75 + /* "pysam/libcbgzf.pyx":80 * # accept any data that supports the buffer protocol * data = memoryview(data) * length = data.nbytes # <<<<<<<<<<<<<< * * if length > 0 and bgzf_write(self.bgzf, data, length) < 0: */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_data, __pyx_n_s_nbytes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 75, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_data, __pyx_n_s_nbytes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 80, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_length = __pyx_t_3; __pyx_t_3 = 0; } __pyx_L5:; - /* "pysam/libcbgzf.pyx":77 + /* "pysam/libcbgzf.pyx":82 * length = data.nbytes * * if length > 0 and bgzf_write(self.bgzf, data, length) < 0: # <<<<<<<<<<<<<< * raise IOError('BGZFile write failed') * */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_length, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 77, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 77, __pyx_L1_error) + __pyx_t_3 = PyObject_RichCompare(__pyx_v_length, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 82, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { } else { __pyx_t_4 = __pyx_t_1; goto __pyx_L7_bool_binop_done; } - __pyx_t_6 = __Pyx_PyObject_AsWritableString(__pyx_v_data); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 77, __pyx_L1_error) - __pyx_t_7 = __Pyx_PyInt_As_size_t(__pyx_v_length); if (unlikely((__pyx_t_7 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 77, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_AsWritableString(__pyx_v_data); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 82, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyInt_As_size_t(__pyx_v_length); if (unlikely((__pyx_t_7 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 82, __pyx_L1_error) __pyx_t_1 = ((bgzf_write(__pyx_v_self->bgzf, ((char *)__pyx_t_6), __pyx_t_7) < 0) != 0); __pyx_t_4 = __pyx_t_1; __pyx_L7_bool_binop_done:; if (unlikely(__pyx_t_4)) { - /* "pysam/libcbgzf.pyx":78 + /* "pysam/libcbgzf.pyx":83 * * if length > 0 and bgzf_write(self.bgzf, data, length) < 0: * raise IOError('BGZFile write failed') # <<<<<<<<<<<<<< * * return length */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 78, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 83, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 78, __pyx_L1_error) + __PYX_ERR(0, 83, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":77 + /* "pysam/libcbgzf.pyx":82 * length = data.nbytes * * if length > 0 and bgzf_write(self.bgzf, data, length) < 0: # <<<<<<<<<<<<<< @@ -2407,7 +2428,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_4write(struct __pyx_obj_5pys */ } - /* "pysam/libcbgzf.pyx":80 + /* "pysam/libcbgzf.pyx":85 * raise IOError('BGZFile write failed') * * return length # <<<<<<<<<<<<<< @@ -2419,10 +2440,10 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_4write(struct __pyx_obj_5pys __pyx_r = __pyx_v_length; goto __pyx_L0; - /* "pysam/libcbgzf.pyx":62 + /* "pysam/libcbgzf.pyx":67 * self.close() * - * def write(self,data): # <<<<<<<<<<<<<< + * def write(self, data): # <<<<<<<<<<<<<< * if not self.bgzf: * raise ValueError("write() on closed BGZFile object") */ @@ -2442,7 +2463,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_4write(struct __pyx_obj_5pys return __pyx_r; } -/* "pysam/libcbgzf.pyx":82 +/* "pysam/libcbgzf.pyx":87 * return length * * def read(self, size=-1): # <<<<<<<<<<<<<< @@ -2479,7 +2500,7 @@ static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_7read(PyObject *__pyx_v_self } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "read") < 0)) __PYX_ERR(0, 82, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "read") < 0)) __PYX_ERR(0, 87, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2493,7 +2514,7 @@ static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_7read(PyObject *__pyx_v_self } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("read", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 82, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("read", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 87, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbgzf.BGZFile.read", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2524,7 +2545,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa int __pyx_t_8; __Pyx_RefNannySetupContext("read", 0); - /* "pysam/libcbgzf.pyx":85 + /* "pysam/libcbgzf.pyx":90 * cdef ssize_t read_size * * if not self.bgzf: # <<<<<<<<<<<<<< @@ -2534,20 +2555,20 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa __pyx_t_1 = ((!(__pyx_v_self->bgzf != 0)) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":86 + /* "pysam/libcbgzf.pyx":91 * * if not self.bgzf: * raise ValueError("read() on closed BGZFile object") # <<<<<<<<<<<<<< * * if self.bgzf.is_write: */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 91, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 86, __pyx_L1_error) + __PYX_ERR(0, 91, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":85 + /* "pysam/libcbgzf.pyx":90 * cdef ssize_t read_size * * if not self.bgzf: # <<<<<<<<<<<<<< @@ -2556,38 +2577,38 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ } - /* "pysam/libcbgzf.pyx":88 + /* "pysam/libcbgzf.pyx":93 * raise ValueError("read() on closed BGZFile object") * * if self.bgzf.is_write: # <<<<<<<<<<<<<< * import errno - * raise OSError(errno.EBADF, "read() on write-only BGZFile object") + * raise IOError(errno.EBADF, "read() on write-only BGZFile object") */ __pyx_t_1 = (__pyx_v_self->bgzf->is_write != 0); if (__pyx_t_1) { - /* "pysam/libcbgzf.pyx":89 + /* "pysam/libcbgzf.pyx":94 * * if self.bgzf.is_write: * import errno # <<<<<<<<<<<<<< - * raise OSError(errno.EBADF, "read() on write-only BGZFile object") + * raise IOError(errno.EBADF, "read() on write-only BGZFile object") * */ - __pyx_t_2 = __Pyx_Import(__pyx_n_s_errno, 0, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 89, __pyx_L1_error) + __pyx_t_2 = __Pyx_Import(__pyx_n_s_errno, 0, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 94, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_errno = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libcbgzf.pyx":90 + /* "pysam/libcbgzf.pyx":95 * if self.bgzf.is_write: * import errno - * raise OSError(errno.EBADF, "read() on write-only BGZFile object") # <<<<<<<<<<<<<< + * raise IOError(errno.EBADF, "read() on write-only BGZFile object") # <<<<<<<<<<<<<< * * if size < 0: */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_errno, __pyx_n_s_EBADF); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_errno, __pyx_n_s_EBADF); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); @@ -2595,47 +2616,47 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa __Pyx_GIVEREF(__pyx_kp_s_read_on_write_only_BGZFile_objec); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_s_read_on_write_only_BGZFile_objec); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 90, __pyx_L1_error) + __PYX_ERR(0, 95, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":88 + /* "pysam/libcbgzf.pyx":93 * raise ValueError("read() on closed BGZFile object") * * if self.bgzf.is_write: # <<<<<<<<<<<<<< * import errno - * raise OSError(errno.EBADF, "read() on write-only BGZFile object") + * raise IOError(errno.EBADF, "read() on write-only BGZFile object") */ } - /* "pysam/libcbgzf.pyx":92 - * raise OSError(errno.EBADF, "read() on write-only BGZFile object") + /* "pysam/libcbgzf.pyx":97 + * raise IOError(errno.EBADF, "read() on write-only BGZFile object") * * if size < 0: # <<<<<<<<<<<<<< * chunks = [] * while 1: */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_size, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 92, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 92, __pyx_L1_error) + __pyx_t_2 = PyObject_RichCompare(__pyx_v_size, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 97, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 97, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { - /* "pysam/libcbgzf.pyx":93 + /* "pysam/libcbgzf.pyx":98 * * if size < 0: * chunks = [] # <<<<<<<<<<<<<< * while 1: * chunk = PyBytes_FromStringAndSize(NULL, BUFFER_SIZE) */ - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 98, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_chunks = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbgzf.pyx":94 + /* "pysam/libcbgzf.pyx":99 * if size < 0: * chunks = [] * while 1: # <<<<<<<<<<<<<< @@ -2644,23 +2665,23 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ while (1) { - /* "pysam/libcbgzf.pyx":95 + /* "pysam/libcbgzf.pyx":100 * chunks = [] * while 1: * chunk = PyBytes_FromStringAndSize(NULL, BUFFER_SIZE) # <<<<<<<<<<<<<< * cdata = chunk * read_size = bgzf_read(self.bgzf, chunk, BUFFER_SIZE) */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_BUFFER_SIZE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 95, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_BUFFER_SIZE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 100, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 95, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 100, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyBytes_FromStringAndSize(NULL, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 95, __pyx_L1_error) + __pyx_t_2 = PyBytes_FromStringAndSize(NULL, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 100, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XDECREF_SET(__pyx_v_chunk, ((PyObject*)__pyx_t_2)); __pyx_t_2 = 0; - /* "pysam/libcbgzf.pyx":96 + /* "pysam/libcbgzf.pyx":101 * while 1: * chunk = PyBytes_FromStringAndSize(NULL, BUFFER_SIZE) * cdata = chunk # <<<<<<<<<<<<<< @@ -2672,7 +2693,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa __Pyx_XDECREF_SET(__pyx_v_cdata, ((PyObject*)__pyx_t_2)); __pyx_t_2 = 0; - /* "pysam/libcbgzf.pyx":97 + /* "pysam/libcbgzf.pyx":102 * chunk = PyBytes_FromStringAndSize(NULL, BUFFER_SIZE) * cdata = chunk * read_size = bgzf_read(self.bgzf, chunk, BUFFER_SIZE) # <<<<<<<<<<<<<< @@ -2681,16 +2702,16 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ if (unlikely(__pyx_v_chunk == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 97, __pyx_L1_error) + __PYX_ERR(0, 102, __pyx_L1_error) } - __pyx_t_5 = __Pyx_PyBytes_AsWritableString(__pyx_v_chunk); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 97, __pyx_L1_error) - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_BUFFER_SIZE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 97, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyBytes_AsWritableString(__pyx_v_chunk); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 102, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_BUFFER_SIZE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = __Pyx_PyInt_As_size_t(__pyx_t_2); if (unlikely((__pyx_t_6 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 97, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_size_t(__pyx_t_2); if (unlikely((__pyx_t_6 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 102, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_read_size = bgzf_read(__pyx_v_self->bgzf, ((char *)__pyx_t_5), __pyx_t_6); - /* "pysam/libcbgzf.pyx":98 + /* "pysam/libcbgzf.pyx":103 * cdata = chunk * read_size = bgzf_read(self.bgzf, chunk, BUFFER_SIZE) * if read_size < 0: # <<<<<<<<<<<<<< @@ -2700,20 +2721,20 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa __pyx_t_1 = ((__pyx_v_read_size < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":99 + /* "pysam/libcbgzf.pyx":104 * read_size = bgzf_read(self.bgzf, chunk, BUFFER_SIZE) * if read_size < 0: * raise IOError('Error reading from BGZFile') # <<<<<<<<<<<<<< * elif not read_size: * break */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 99, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 99, __pyx_L1_error) + __PYX_ERR(0, 104, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":98 + /* "pysam/libcbgzf.pyx":103 * cdata = chunk * read_size = bgzf_read(self.bgzf, chunk, BUFFER_SIZE) * if read_size < 0: # <<<<<<<<<<<<<< @@ -2722,7 +2743,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ } - /* "pysam/libcbgzf.pyx":100 + /* "pysam/libcbgzf.pyx":105 * if read_size < 0: * raise IOError('Error reading from BGZFile') * elif not read_size: # <<<<<<<<<<<<<< @@ -2732,7 +2753,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa __pyx_t_1 = ((!(__pyx_v_read_size != 0)) != 0); if (__pyx_t_1) { - /* "pysam/libcbgzf.pyx":101 + /* "pysam/libcbgzf.pyx":106 * raise IOError('Error reading from BGZFile') * elif not read_size: * break # <<<<<<<<<<<<<< @@ -2741,7 +2762,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ goto __pyx_L7_break; - /* "pysam/libcbgzf.pyx":100 + /* "pysam/libcbgzf.pyx":105 * if read_size < 0: * raise IOError('Error reading from BGZFile') * elif not read_size: # <<<<<<<<<<<<<< @@ -2750,25 +2771,25 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ } - /* "pysam/libcbgzf.pyx":102 + /* "pysam/libcbgzf.pyx":107 * elif not read_size: * break * elif read_size < BUFFER_SIZE: # <<<<<<<<<<<<<< * chunk = chunk[:read_size] * chunks.append(chunk) */ - __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_read_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error) + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_read_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_BUFFER_SIZE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 102, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_BUFFER_SIZE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 102, __pyx_L1_error) + __pyx_t_7 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 102, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (__pyx_t_1) { - /* "pysam/libcbgzf.pyx":103 + /* "pysam/libcbgzf.pyx":108 * break * elif read_size < BUFFER_SIZE: * chunk = chunk[:read_size] # <<<<<<<<<<<<<< @@ -2777,14 +2798,14 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ if (unlikely(__pyx_v_chunk == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 103, __pyx_L1_error) + __PYX_ERR(0, 108, __pyx_L1_error) } - __pyx_t_7 = PySequence_GetSlice(__pyx_v_chunk, 0, __pyx_v_read_size); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 103, __pyx_L1_error) + __pyx_t_7 = PySequence_GetSlice(__pyx_v_chunk, 0, __pyx_v_read_size); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_chunk, ((PyObject*)__pyx_t_7)); __pyx_t_7 = 0; - /* "pysam/libcbgzf.pyx":102 + /* "pysam/libcbgzf.pyx":107 * elif not read_size: * break * elif read_size < BUFFER_SIZE: # <<<<<<<<<<<<<< @@ -2793,18 +2814,18 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ } - /* "pysam/libcbgzf.pyx":104 + /* "pysam/libcbgzf.pyx":109 * elif read_size < BUFFER_SIZE: * chunk = chunk[:read_size] * chunks.append(chunk) # <<<<<<<<<<<<<< * return b''.join(chunks) * */ - __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_chunks, __pyx_v_chunk); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 104, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_chunks, __pyx_v_chunk); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 109, __pyx_L1_error) } __pyx_L7_break:; - /* "pysam/libcbgzf.pyx":105 + /* "pysam/libcbgzf.pyx":110 * chunk = chunk[:read_size] * chunks.append(chunk) * return b''.join(chunks) # <<<<<<<<<<<<<< @@ -2812,14 +2833,14 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa * elif size > 0: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_7 = __Pyx_PyBytes_Join(__pyx_kp_b__6, __pyx_v_chunks); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 105, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyBytes_Join(__pyx_kp_b__6, __pyx_v_chunks); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_r = __pyx_t_7; __pyx_t_7 = 0; goto __pyx_L0; - /* "pysam/libcbgzf.pyx":92 - * raise OSError(errno.EBADF, "read() on write-only BGZFile object") + /* "pysam/libcbgzf.pyx":97 + * raise IOError(errno.EBADF, "read() on write-only BGZFile object") * * if size < 0: # <<<<<<<<<<<<<< * chunks = [] @@ -2827,32 +2848,32 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ } - /* "pysam/libcbgzf.pyx":107 + /* "pysam/libcbgzf.pyx":112 * return b''.join(chunks) * * elif size > 0: # <<<<<<<<<<<<<< * chunk = PyBytes_FromStringAndSize(NULL, size) * read_size = bgzf_read(self.bgzf, chunk, size) */ - __pyx_t_7 = PyObject_RichCompare(__pyx_v_size, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 107, __pyx_L1_error) + __pyx_t_7 = PyObject_RichCompare(__pyx_v_size, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 112, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 112, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (__pyx_t_1) { - /* "pysam/libcbgzf.pyx":108 + /* "pysam/libcbgzf.pyx":113 * * elif size > 0: * chunk = PyBytes_FromStringAndSize(NULL, size) # <<<<<<<<<<<<<< * read_size = bgzf_read(self.bgzf, chunk, size) * if read_size < 0: */ - __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_v_size); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 108, __pyx_L1_error) - __pyx_t_7 = PyBytes_FromStringAndSize(NULL, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 108, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_v_size); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 113, __pyx_L1_error) + __pyx_t_7 = PyBytes_FromStringAndSize(NULL, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 113, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_v_chunk = ((PyObject*)__pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcbgzf.pyx":109 + /* "pysam/libcbgzf.pyx":114 * elif size > 0: * chunk = PyBytes_FromStringAndSize(NULL, size) * read_size = bgzf_read(self.bgzf, chunk, size) # <<<<<<<<<<<<<< @@ -2861,13 +2882,13 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ if (unlikely(__pyx_v_chunk == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 109, __pyx_L1_error) + __PYX_ERR(0, 114, __pyx_L1_error) } - __pyx_t_5 = __Pyx_PyBytes_AsWritableString(__pyx_v_chunk); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 109, __pyx_L1_error) - __pyx_t_6 = __Pyx_PyInt_As_size_t(__pyx_v_size); if (unlikely((__pyx_t_6 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 109, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyBytes_AsWritableString(__pyx_v_chunk); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 114, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_size_t(__pyx_v_size); if (unlikely((__pyx_t_6 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 114, __pyx_L1_error) __pyx_v_read_size = bgzf_read(__pyx_v_self->bgzf, ((char *)__pyx_t_5), __pyx_t_6); - /* "pysam/libcbgzf.pyx":110 + /* "pysam/libcbgzf.pyx":115 * chunk = PyBytes_FromStringAndSize(NULL, size) * read_size = bgzf_read(self.bgzf, chunk, size) * if read_size < 0: # <<<<<<<<<<<<<< @@ -2877,20 +2898,20 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa __pyx_t_1 = ((__pyx_v_read_size < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":111 + /* "pysam/libcbgzf.pyx":116 * read_size = bgzf_read(self.bgzf, chunk, size) * if read_size < 0: * raise IOError('Error reading from BGZFile') # <<<<<<<<<<<<<< * elif read_size < size: * chunk = chunk[:size] */ - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 116, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_Raise(__pyx_t_7, 0, 0, 0); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __PYX_ERR(0, 111, __pyx_L1_error) + __PYX_ERR(0, 116, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":110 + /* "pysam/libcbgzf.pyx":115 * chunk = PyBytes_FromStringAndSize(NULL, size) * read_size = bgzf_read(self.bgzf, chunk, size) * if read_size < 0: # <<<<<<<<<<<<<< @@ -2899,22 +2920,22 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ } - /* "pysam/libcbgzf.pyx":112 + /* "pysam/libcbgzf.pyx":117 * if read_size < 0: * raise IOError('Error reading from BGZFile') * elif read_size < size: # <<<<<<<<<<<<<< * chunk = chunk[:size] * return chunk */ - __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_read_size); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 112, __pyx_L1_error) + __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_read_size); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 117, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_7, __pyx_v_size, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 112, __pyx_L1_error) + __pyx_t_3 = PyObject_RichCompare(__pyx_t_7, __pyx_v_size, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 112, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 117, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { - /* "pysam/libcbgzf.pyx":113 + /* "pysam/libcbgzf.pyx":118 * raise IOError('Error reading from BGZFile') * elif read_size < size: * chunk = chunk[:size] # <<<<<<<<<<<<<< @@ -2923,15 +2944,15 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ if (unlikely(__pyx_v_chunk == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 113, __pyx_L1_error) + __PYX_ERR(0, 118, __pyx_L1_error) } - __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_v_size); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 113, __pyx_L1_error) - __pyx_t_3 = PySequence_GetSlice(__pyx_v_chunk, 0, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 113, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_v_size); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 118, __pyx_L1_error) + __pyx_t_3 = PySequence_GetSlice(__pyx_v_chunk, 0, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 118, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_chunk, ((PyObject*)__pyx_t_3)); __pyx_t_3 = 0; - /* "pysam/libcbgzf.pyx":112 + /* "pysam/libcbgzf.pyx":117 * if read_size < 0: * raise IOError('Error reading from BGZFile') * elif read_size < size: # <<<<<<<<<<<<<< @@ -2940,7 +2961,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ } - /* "pysam/libcbgzf.pyx":114 + /* "pysam/libcbgzf.pyx":119 * elif read_size < size: * chunk = chunk[:size] * return chunk # <<<<<<<<<<<<<< @@ -2952,7 +2973,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa __pyx_r = __pyx_v_chunk; goto __pyx_L0; - /* "pysam/libcbgzf.pyx":107 + /* "pysam/libcbgzf.pyx":112 * return b''.join(chunks) * * elif size > 0: # <<<<<<<<<<<<<< @@ -2961,7 +2982,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa */ } - /* "pysam/libcbgzf.pyx":116 + /* "pysam/libcbgzf.pyx":121 * return chunk * else: * return b'' # <<<<<<<<<<<<<< @@ -2975,7 +2996,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa goto __pyx_L0; } - /* "pysam/libcbgzf.pyx":82 + /* "pysam/libcbgzf.pyx":87 * return length * * def read(self, size=-1): # <<<<<<<<<<<<<< @@ -3000,7 +3021,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6read(struct __pyx_obj_5pysa return __pyx_r; } -/* "pysam/libcbgzf.pyx":119 +/* "pysam/libcbgzf.pyx":124 * * @property * def closed(self): # <<<<<<<<<<<<<< @@ -3027,7 +3048,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6closed___get__(struct __pyx PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - /* "pysam/libcbgzf.pyx":120 + /* "pysam/libcbgzf.pyx":125 * @property * def closed(self): * return self.bgzf == NULL # <<<<<<<<<<<<<< @@ -3035,13 +3056,13 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6closed___get__(struct __pyx * def close(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->bgzf == NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 120, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->bgzf == NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbgzf.pyx":119 + /* "pysam/libcbgzf.pyx":124 * * @property * def closed(self): # <<<<<<<<<<<<<< @@ -3060,7 +3081,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_6closed___get__(struct __pyx return __pyx_r; } -/* "pysam/libcbgzf.pyx":122 +/* "pysam/libcbgzf.pyx":127 * return self.bgzf == NULL * * def close(self): # <<<<<<<<<<<<<< @@ -3091,7 +3112,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_8close(struct __pyx_obj_5pys char const *__pyx_t_4; __Pyx_RefNannySetupContext("close", 0); - /* "pysam/libcbgzf.pyx":123 + /* "pysam/libcbgzf.pyx":128 * * def close(self): * if not self.bgzf: # <<<<<<<<<<<<<< @@ -3101,7 +3122,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_8close(struct __pyx_obj_5pys __pyx_t_1 = ((!(__pyx_v_self->bgzf != 0)) != 0); if (__pyx_t_1) { - /* "pysam/libcbgzf.pyx":124 + /* "pysam/libcbgzf.pyx":129 * def close(self): * if not self.bgzf: * return # <<<<<<<<<<<<<< @@ -3112,7 +3133,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_8close(struct __pyx_obj_5pys __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbgzf.pyx":123 + /* "pysam/libcbgzf.pyx":128 * * def close(self): * if not self.bgzf: # <<<<<<<<<<<<<< @@ -3121,7 +3142,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_8close(struct __pyx_obj_5pys */ } - /* "pysam/libcbgzf.pyx":126 + /* "pysam/libcbgzf.pyx":131 * return * * if self.bgzf.is_write and bgzf_flush(self.bgzf) < 0: # <<<<<<<<<<<<<< @@ -3139,20 +3160,20 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_8close(struct __pyx_obj_5pys __pyx_L5_bool_binop_done:; if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":127 + /* "pysam/libcbgzf.pyx":132 * * if self.bgzf.is_write and bgzf_flush(self.bgzf) < 0: * raise IOError('Error flushing BGZFile object') # <<<<<<<<<<<<<< * * if self.index and bgzf_index_dump(self.bgzf, self.index, NULL) < 0: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 127, __pyx_L1_error) + __PYX_ERR(0, 132, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":126 + /* "pysam/libcbgzf.pyx":131 * return * * if self.bgzf.is_write and bgzf_flush(self.bgzf) < 0: # <<<<<<<<<<<<<< @@ -3161,43 +3182,39 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_8close(struct __pyx_obj_5pys */ } - /* "pysam/libcbgzf.pyx":129 + /* "pysam/libcbgzf.pyx":134 * raise IOError('Error flushing BGZFile object') * * if self.index and bgzf_index_dump(self.bgzf, self.index, NULL) < 0: # <<<<<<<<<<<<<< * raise IOError('Cannot write index') * */ - __pyx_t_2 = (__pyx_v_self->index != Py_None)&&(PyBytes_GET_SIZE(__pyx_v_self->index) != 0); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_self->index); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 134, __pyx_L1_error) if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L8_bool_binop_done; } - if (unlikely(__pyx_v_self->index == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 129, __pyx_L1_error) - } - __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_self->index); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 129, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_v_self->index); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 134, __pyx_L1_error) __pyx_t_2 = ((bgzf_index_dump(__pyx_v_self->bgzf, __pyx_t_4, NULL) < 0) != 0); __pyx_t_1 = __pyx_t_2; __pyx_L8_bool_binop_done:; if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":130 + /* "pysam/libcbgzf.pyx":135 * * if self.index and bgzf_index_dump(self.bgzf, self.index, NULL) < 0: * raise IOError('Cannot write index') # <<<<<<<<<<<<<< * * cdef ret = bgzf_close(self.bgzf) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 130, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 130, __pyx_L1_error) + __PYX_ERR(0, 135, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":129 + /* "pysam/libcbgzf.pyx":134 * raise IOError('Error flushing BGZFile object') * * if self.index and bgzf_index_dump(self.bgzf, self.index, NULL) < 0: # <<<<<<<<<<<<<< @@ -3206,19 +3223,19 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_8close(struct __pyx_obj_5pys */ } - /* "pysam/libcbgzf.pyx":132 + /* "pysam/libcbgzf.pyx":137 * raise IOError('Cannot write index') * * cdef ret = bgzf_close(self.bgzf) # <<<<<<<<<<<<<< * self.bgzf = NULL * */ - __pyx_t_3 = __Pyx_PyInt_From_int(bgzf_close(__pyx_v_self->bgzf)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 132, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(bgzf_close(__pyx_v_self->bgzf)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_ret = __pyx_t_3; __pyx_t_3 = 0; - /* "pysam/libcbgzf.pyx":133 + /* "pysam/libcbgzf.pyx":138 * * cdef ret = bgzf_close(self.bgzf) * self.bgzf = NULL # <<<<<<<<<<<<<< @@ -3227,32 +3244,32 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_8close(struct __pyx_obj_5pys */ __pyx_v_self->bgzf = NULL; - /* "pysam/libcbgzf.pyx":135 + /* "pysam/libcbgzf.pyx":140 * self.bgzf = NULL * * if ret < 0: # <<<<<<<<<<<<<< * raise IOError('Error closing BGZFile object') * */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_ret, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 135, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 135, __pyx_L1_error) + __pyx_t_3 = PyObject_RichCompare(__pyx_v_ret, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 140, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 140, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":136 + /* "pysam/libcbgzf.pyx":141 * * if ret < 0: * raise IOError('Error closing BGZFile object') # <<<<<<<<<<<<<< * * def __enter__(self): */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 136, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 141, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 136, __pyx_L1_error) + __PYX_ERR(0, 141, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":135 + /* "pysam/libcbgzf.pyx":140 * self.bgzf = NULL * * if ret < 0: # <<<<<<<<<<<<<< @@ -3261,7 +3278,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_8close(struct __pyx_obj_5pys */ } - /* "pysam/libcbgzf.pyx":122 + /* "pysam/libcbgzf.pyx":127 * return self.bgzf == NULL * * def close(self): # <<<<<<<<<<<<<< @@ -3283,7 +3300,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_8close(struct __pyx_obj_5pys return __pyx_r; } -/* "pysam/libcbgzf.pyx":138 +/* "pysam/libcbgzf.pyx":143 * raise IOError('Error closing BGZFile object') * * def __enter__(self): # <<<<<<<<<<<<<< @@ -3309,7 +3326,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_10__enter__(struct __pyx_obj __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__enter__", 0); - /* "pysam/libcbgzf.pyx":139 + /* "pysam/libcbgzf.pyx":144 * * def __enter__(self): * return self # <<<<<<<<<<<<<< @@ -3321,7 +3338,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_10__enter__(struct __pyx_obj __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcbgzf.pyx":138 + /* "pysam/libcbgzf.pyx":143 * raise IOError('Error closing BGZFile object') * * def __enter__(self): # <<<<<<<<<<<<<< @@ -3336,7 +3353,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_10__enter__(struct __pyx_obj return __pyx_r; } -/* "pysam/libcbgzf.pyx":141 +/* "pysam/libcbgzf.pyx":146 * return self * * def __exit__(self, type, value, tb): # <<<<<<<<<<<<<< @@ -3378,17 +3395,17 @@ static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_13__exit__(PyObject *__pyx_v case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 141, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 146, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tb)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 141, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 146, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 141, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 146, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -3403,7 +3420,7 @@ static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_13__exit__(PyObject *__pyx_v } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 141, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 146, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbgzf.BGZFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -3424,14 +3441,14 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_12__exit__(struct __pyx_obj_ PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__exit__", 0); - /* "pysam/libcbgzf.pyx":142 + /* "pysam/libcbgzf.pyx":147 * * def __exit__(self, type, value, tb): * self.close() # <<<<<<<<<<<<<< * * def flush(self): */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -3444,16 +3461,16 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_12__exit__(struct __pyx_obj_ } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 147, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbgzf.pyx":141 + /* "pysam/libcbgzf.pyx":146 * return self * * def __exit__(self, type, value, tb): # <<<<<<<<<<<<<< @@ -3476,7 +3493,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_12__exit__(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libcbgzf.pyx":144 +/* "pysam/libcbgzf.pyx":149 * self.close() * * def flush(self): # <<<<<<<<<<<<<< @@ -3505,7 +3522,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_14flush(struct __pyx_obj_5py PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("flush", 0); - /* "pysam/libcbgzf.pyx":145 + /* "pysam/libcbgzf.pyx":150 * * def flush(self): * if not self.bgzf: # <<<<<<<<<<<<<< @@ -3515,7 +3532,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_14flush(struct __pyx_obj_5py __pyx_t_1 = ((!(__pyx_v_self->bgzf != 0)) != 0); if (__pyx_t_1) { - /* "pysam/libcbgzf.pyx":146 + /* "pysam/libcbgzf.pyx":151 * def flush(self): * if not self.bgzf: * return # <<<<<<<<<<<<<< @@ -3526,7 +3543,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_14flush(struct __pyx_obj_5py __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcbgzf.pyx":145 + /* "pysam/libcbgzf.pyx":150 * * def flush(self): * if not self.bgzf: # <<<<<<<<<<<<<< @@ -3535,7 +3552,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_14flush(struct __pyx_obj_5py */ } - /* "pysam/libcbgzf.pyx":148 + /* "pysam/libcbgzf.pyx":153 * return * * if self.bgzf.is_write and bgzf_flush(self.bgzf) < 0: # <<<<<<<<<<<<<< @@ -3553,20 +3570,20 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_14flush(struct __pyx_obj_5py __pyx_L5_bool_binop_done:; if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":149 + /* "pysam/libcbgzf.pyx":154 * * if self.bgzf.is_write and bgzf_flush(self.bgzf) < 0: * raise IOError('Error flushing BGZFile object') # <<<<<<<<<<<<<< * * def fileno(self): */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 149, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 149, __pyx_L1_error) + __PYX_ERR(0, 154, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":148 + /* "pysam/libcbgzf.pyx":153 * return * * if self.bgzf.is_write and bgzf_flush(self.bgzf) < 0: # <<<<<<<<<<<<<< @@ -3575,7 +3592,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_14flush(struct __pyx_obj_5py */ } - /* "pysam/libcbgzf.pyx":144 + /* "pysam/libcbgzf.pyx":149 * self.close() * * def flush(self): # <<<<<<<<<<<<<< @@ -3596,7 +3613,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_14flush(struct __pyx_obj_5py return __pyx_r; } -/* "pysam/libcbgzf.pyx":151 +/* "pysam/libcbgzf.pyx":156 * raise IOError('Error flushing BGZFile object') * * def fileno(self): # <<<<<<<<<<<<<< @@ -3624,20 +3641,20 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_16fileno(CYTHON_UNUSED struc PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("fileno", 0); - /* "pysam/libcbgzf.pyx":157 + /* "pysam/libcbgzf.pyx":162 * doesn't support fileno(). * """ * raise AttributeError('fileno') # <<<<<<<<<<<<<< * * def rewind(self): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_AttributeError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_AttributeError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 162, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 157, __pyx_L1_error) + __PYX_ERR(0, 162, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":151 + /* "pysam/libcbgzf.pyx":156 * raise IOError('Error flushing BGZFile object') * * def fileno(self): # <<<<<<<<<<<<<< @@ -3655,7 +3672,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_16fileno(CYTHON_UNUSED struc return __pyx_r; } -/* "pysam/libcbgzf.pyx":159 +/* "pysam/libcbgzf.pyx":164 * raise AttributeError('fileno') * * def rewind(self): # <<<<<<<<<<<<<< @@ -3684,7 +3701,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_18rewind(struct __pyx_obj_5p PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("rewind", 0); - /* "pysam/libcbgzf.pyx":162 + /* "pysam/libcbgzf.pyx":167 * '''Return the uncompressed stream file position indicator to the * beginning of the file''' * if not self.bgzf: # <<<<<<<<<<<<<< @@ -3694,20 +3711,20 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_18rewind(struct __pyx_obj_5p __pyx_t_1 = ((!(__pyx_v_self->bgzf != 0)) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":163 + /* "pysam/libcbgzf.pyx":168 * beginning of the file''' * if not self.bgzf: * raise ValueError("rewind() on closed BGZFile object") # <<<<<<<<<<<<<< * if not self.bgzf.is_write: - * raise OSError("Can't rewind in write mode") + * raise IOError("Can't rewind in write mode") */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 168, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 163, __pyx_L1_error) + __PYX_ERR(0, 168, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":162 + /* "pysam/libcbgzf.pyx":167 * '''Return the uncompressed stream file position indicator to the * beginning of the file''' * if not self.bgzf: # <<<<<<<<<<<<<< @@ -3716,41 +3733,41 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_18rewind(struct __pyx_obj_5p */ } - /* "pysam/libcbgzf.pyx":164 + /* "pysam/libcbgzf.pyx":169 * if not self.bgzf: * raise ValueError("rewind() on closed BGZFile object") * if not self.bgzf.is_write: # <<<<<<<<<<<<<< - * raise OSError("Can't rewind in write mode") + * raise IOError("Can't rewind in write mode") * if bgzf_seek(self.bgzf, 0, SEEK_SET) < 0: */ __pyx_t_1 = ((!(__pyx_v_self->bgzf->is_write != 0)) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":165 + /* "pysam/libcbgzf.pyx":170 * raise ValueError("rewind() on closed BGZFile object") * if not self.bgzf.is_write: - * raise OSError("Can't rewind in write mode") # <<<<<<<<<<<<<< + * raise IOError("Can't rewind in write mode") # <<<<<<<<<<<<<< * if bgzf_seek(self.bgzf, 0, SEEK_SET) < 0: * raise IOError('Error seeking BGZFFile object') */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 165, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 165, __pyx_L1_error) + __PYX_ERR(0, 170, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":164 + /* "pysam/libcbgzf.pyx":169 * if not self.bgzf: * raise ValueError("rewind() on closed BGZFile object") * if not self.bgzf.is_write: # <<<<<<<<<<<<<< - * raise OSError("Can't rewind in write mode") + * raise IOError("Can't rewind in write mode") * if bgzf_seek(self.bgzf, 0, SEEK_SET) < 0: */ } - /* "pysam/libcbgzf.pyx":166 + /* "pysam/libcbgzf.pyx":171 * if not self.bgzf.is_write: - * raise OSError("Can't rewind in write mode") + * raise IOError("Can't rewind in write mode") * if bgzf_seek(self.bgzf, 0, SEEK_SET) < 0: # <<<<<<<<<<<<<< * raise IOError('Error seeking BGZFFile object') * @@ -3758,29 +3775,29 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_18rewind(struct __pyx_obj_5p __pyx_t_1 = ((bgzf_seek(__pyx_v_self->bgzf, 0, SEEK_SET) < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":167 - * raise OSError("Can't rewind in write mode") + /* "pysam/libcbgzf.pyx":172 + * raise IOError("Can't rewind in write mode") * if bgzf_seek(self.bgzf, 0, SEEK_SET) < 0: * raise IOError('Error seeking BGZFFile object') # <<<<<<<<<<<<<< * * def readable(self): */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 167, __pyx_L1_error) + __PYX_ERR(0, 172, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":166 + /* "pysam/libcbgzf.pyx":171 * if not self.bgzf.is_write: - * raise OSError("Can't rewind in write mode") + * raise IOError("Can't rewind in write mode") * if bgzf_seek(self.bgzf, 0, SEEK_SET) < 0: # <<<<<<<<<<<<<< * raise IOError('Error seeking BGZFFile object') * */ } - /* "pysam/libcbgzf.pyx":159 + /* "pysam/libcbgzf.pyx":164 * raise AttributeError('fileno') * * def rewind(self): # <<<<<<<<<<<<<< @@ -3801,7 +3818,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_18rewind(struct __pyx_obj_5p return __pyx_r; } -/* "pysam/libcbgzf.pyx":169 +/* "pysam/libcbgzf.pyx":174 * raise IOError('Error seeking BGZFFile object') * * def readable(self): # <<<<<<<<<<<<<< @@ -3830,7 +3847,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_20readable(struct __pyx_obj_ PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("readable", 0); - /* "pysam/libcbgzf.pyx":170 + /* "pysam/libcbgzf.pyx":175 * * def readable(self): * if not self.bgzf: # <<<<<<<<<<<<<< @@ -3840,20 +3857,20 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_20readable(struct __pyx_obj_ __pyx_t_1 = ((!(__pyx_v_self->bgzf != 0)) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":171 + /* "pysam/libcbgzf.pyx":176 * def readable(self): * if not self.bgzf: * raise ValueError("readable() on closed BGZFile object") # <<<<<<<<<<<<<< * return self.bgzf != NULL and not self.bgzf.is_write * */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 171, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 176, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 171, __pyx_L1_error) + __PYX_ERR(0, 176, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":170 + /* "pysam/libcbgzf.pyx":175 * * def readable(self): * if not self.bgzf: # <<<<<<<<<<<<<< @@ -3862,7 +3879,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_20readable(struct __pyx_obj_ */ } - /* "pysam/libcbgzf.pyx":172 + /* "pysam/libcbgzf.pyx":177 * if not self.bgzf: * raise ValueError("readable() on closed BGZFile object") * return self.bgzf != NULL and not self.bgzf.is_write # <<<<<<<<<<<<<< @@ -3873,14 +3890,14 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_20readable(struct __pyx_obj_ __pyx_t_1 = (__pyx_v_self->bgzf != NULL); if (__pyx_t_1) { } else { - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 172, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L4_bool_binop_done; } __pyx_t_1 = (!(__pyx_v_self->bgzf->is_write != 0)); - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 172, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __pyx_t_3; __pyx_t_3 = 0; @@ -3889,7 +3906,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_20readable(struct __pyx_obj_ __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcbgzf.pyx":169 + /* "pysam/libcbgzf.pyx":174 * raise IOError('Error seeking BGZFFile object') * * def readable(self): # <<<<<<<<<<<<<< @@ -3909,7 +3926,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_20readable(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libcbgzf.pyx":174 +/* "pysam/libcbgzf.pyx":179 * return self.bgzf != NULL and not self.bgzf.is_write * * def writable(self): # <<<<<<<<<<<<<< @@ -3938,7 +3955,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_22writable(struct __pyx_obj_ PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("writable", 0); - /* "pysam/libcbgzf.pyx":175 + /* "pysam/libcbgzf.pyx":180 * * def writable(self): * return self.bgzf != NULL and self.bgzf.is_write # <<<<<<<<<<<<<< @@ -3949,13 +3966,13 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_22writable(struct __pyx_obj_ __pyx_t_2 = (__pyx_v_self->bgzf != NULL); if (__pyx_t_2) { } else { - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 175, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 180, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L3_bool_binop_done; } - __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(__pyx_v_self->bgzf->is_write); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 175, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_unsigned_int(__pyx_v_self->bgzf->is_write); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 180, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = __pyx_t_3; __pyx_t_3 = 0; @@ -3964,7 +3981,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_22writable(struct __pyx_obj_ __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcbgzf.pyx":174 + /* "pysam/libcbgzf.pyx":179 * return self.bgzf != NULL and not self.bgzf.is_write * * def writable(self): # <<<<<<<<<<<<<< @@ -3984,7 +4001,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_22writable(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libcbgzf.pyx":177 +/* "pysam/libcbgzf.pyx":182 * return self.bgzf != NULL and self.bgzf.is_write * * def seekable(self): # <<<<<<<<<<<<<< @@ -4010,19 +4027,19 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_24seekable(CYTHON_UNUSED str __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("seekable", 0); - /* "pysam/libcbgzf.pyx":178 + /* "pysam/libcbgzf.pyx":183 * * def seekable(self): * return True # <<<<<<<<<<<<<< * - * def seek(self, offset, whence=io.SEEK_SET): + * def tell(self): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_True); __pyx_r = Py_True; goto __pyx_L0; - /* "pysam/libcbgzf.pyx":177 + /* "pysam/libcbgzf.pyx":182 * return self.bgzf != NULL and self.bgzf.is_write * * def seekable(self): # <<<<<<<<<<<<<< @@ -4037,17 +4054,152 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_24seekable(CYTHON_UNUSED str return __pyx_r; } -/* "pysam/libcbgzf.pyx":180 +/* "pysam/libcbgzf.pyx":185 + * return True + * + * def tell(self): # <<<<<<<<<<<<<< + * if not self.bgzf: + * raise ValueError("seek() on closed BGZFile object") + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_27tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_27tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("tell (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_26tell(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26tell(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self) { + int64_t __pyx_v_off; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("tell", 0); + + /* "pysam/libcbgzf.pyx":186 + * + * def tell(self): + * if not self.bgzf: # <<<<<<<<<<<<<< + * raise ValueError("seek() on closed BGZFile object") + * cdef int64_t off = bgzf_tell(self.bgzf) + */ + __pyx_t_1 = ((!(__pyx_v_self->bgzf != 0)) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbgzf.pyx":187 + * def tell(self): + * if not self.bgzf: + * raise ValueError("seek() on closed BGZFile object") # <<<<<<<<<<<<<< + * cdef int64_t off = bgzf_tell(self.bgzf) + * if off < 0: + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 187, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 187, __pyx_L1_error) + + /* "pysam/libcbgzf.pyx":186 + * + * def tell(self): + * if not self.bgzf: # <<<<<<<<<<<<<< + * raise ValueError("seek() on closed BGZFile object") + * cdef int64_t off = bgzf_tell(self.bgzf) + */ + } + + /* "pysam/libcbgzf.pyx":188 + * if not self.bgzf: + * raise ValueError("seek() on closed BGZFile object") + * cdef int64_t off = bgzf_tell(self.bgzf) # <<<<<<<<<<<<<< + * if off < 0: + * raise IOError('Error in tell on BGZFFile object') + */ + __pyx_v_off = bgzf_tell(__pyx_v_self->bgzf); + + /* "pysam/libcbgzf.pyx":189 + * raise ValueError("seek() on closed BGZFile object") + * cdef int64_t off = bgzf_tell(self.bgzf) + * if off < 0: # <<<<<<<<<<<<<< + * raise IOError('Error in tell on BGZFFile object') + * + */ + __pyx_t_1 = ((__pyx_v_off < 0) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcbgzf.pyx":190 + * cdef int64_t off = bgzf_tell(self.bgzf) + * if off < 0: + * raise IOError('Error in tell on BGZFFile object') # <<<<<<<<<<<<<< + * + * return off + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 190, __pyx_L1_error) + + /* "pysam/libcbgzf.pyx":189 + * raise ValueError("seek() on closed BGZFile object") + * cdef int64_t off = bgzf_tell(self.bgzf) + * if off < 0: # <<<<<<<<<<<<<< + * raise IOError('Error in tell on BGZFFile object') + * + */ + } + + /* "pysam/libcbgzf.pyx":192 + * raise IOError('Error in tell on BGZFFile object') + * + * return off # <<<<<<<<<<<<<< + * + * def seek(self, offset, whence=io.SEEK_SET): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyInt_From_int64_t(__pyx_v_off); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcbgzf.pyx":185 * return True * + * def tell(self): # <<<<<<<<<<<<<< + * if not self.bgzf: + * raise ValueError("seek() on closed BGZFile object") + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcbgzf.BGZFile.tell", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbgzf.pyx":194 + * return off + * * def seek(self, offset, whence=io.SEEK_SET): # <<<<<<<<<<<<<< * if not self.bgzf: * raise ValueError("seek() on closed BGZFile object") */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_27seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_27seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_29seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_29seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_offset = 0; PyObject *__pyx_v_whence = 0; PyObject *__pyx_r = 0; @@ -4056,7 +4208,7 @@ static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_27seek(PyObject *__pyx_v_sel { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_offset,&__pyx_n_s_whence,0}; PyObject* values[2] = {0,0}; - values[1] = __pyx_k__17; + values[1] = __pyx_k__19; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); @@ -4081,7 +4233,7 @@ static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_27seek(PyObject *__pyx_v_sel } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "seek") < 0)) __PYX_ERR(0, 180, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "seek") < 0)) __PYX_ERR(0, 194, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -4097,20 +4249,20 @@ static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_27seek(PyObject *__pyx_v_sel } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("seek", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 180, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("seek", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 194, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbgzf.BGZFile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self), __pyx_v_offset, __pyx_v_whence); + __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_28seek(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self), __pyx_v_offset, __pyx_v_whence); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self, PyObject *__pyx_v_offset, PyObject *__pyx_v_whence) { +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_28seek(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self, PyObject *__pyx_v_offset, PyObject *__pyx_v_whence) { int64_t __pyx_v_off; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -4121,7 +4273,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(struct __pyx_obj_5pys int64_t __pyx_t_5; __Pyx_RefNannySetupContext("seek", 0); - /* "pysam/libcbgzf.pyx":181 + /* "pysam/libcbgzf.pyx":195 * * def seek(self, offset, whence=io.SEEK_SET): * if not self.bgzf: # <<<<<<<<<<<<<< @@ -4131,20 +4283,20 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(struct __pyx_obj_5pys __pyx_t_1 = ((!(__pyx_v_self->bgzf != 0)) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":182 + /* "pysam/libcbgzf.pyx":196 * def seek(self, offset, whence=io.SEEK_SET): * if not self.bgzf: * raise ValueError("seek() on closed BGZFile object") # <<<<<<<<<<<<<< * if whence is not io.SEEK_SET: * raise ValueError('Seek from end not supported') */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 182, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 196, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 182, __pyx_L1_error) + __PYX_ERR(0, 196, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":181 + /* "pysam/libcbgzf.pyx":195 * * def seek(self, offset, whence=io.SEEK_SET): * if not self.bgzf: # <<<<<<<<<<<<<< @@ -4153,16 +4305,16 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(struct __pyx_obj_5pys */ } - /* "pysam/libcbgzf.pyx":183 + /* "pysam/libcbgzf.pyx":197 * if not self.bgzf: * raise ValueError("seek() on closed BGZFile object") * if whence is not io.SEEK_SET: # <<<<<<<<<<<<<< * raise ValueError('Seek from end not supported') * */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_io); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 183, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_io); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 197, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_SEEK_SET); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 183, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_SEEK_SET); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 197, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_1 = (__pyx_v_whence != __pyx_t_3); @@ -4170,20 +4322,20 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(struct __pyx_obj_5pys __pyx_t_4 = (__pyx_t_1 != 0); if (unlikely(__pyx_t_4)) { - /* "pysam/libcbgzf.pyx":184 + /* "pysam/libcbgzf.pyx":198 * raise ValueError("seek() on closed BGZFile object") * if whence is not io.SEEK_SET: * raise ValueError('Seek from end not supported') # <<<<<<<<<<<<<< * * cdef int64_t off = bgzf_seek(self.bgzf, offset, SEEK_SET) */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 184, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 184, __pyx_L1_error) + __PYX_ERR(0, 198, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":183 + /* "pysam/libcbgzf.pyx":197 * if not self.bgzf: * raise ValueError("seek() on closed BGZFile object") * if whence is not io.SEEK_SET: # <<<<<<<<<<<<<< @@ -4192,17 +4344,17 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(struct __pyx_obj_5pys */ } - /* "pysam/libcbgzf.pyx":186 + /* "pysam/libcbgzf.pyx":200 * raise ValueError('Seek from end not supported') * * cdef int64_t off = bgzf_seek(self.bgzf, offset, SEEK_SET) # <<<<<<<<<<<<<< * if off < 0: * raise IOError('Error seeking BGZFFile object') */ - __pyx_t_5 = __Pyx_PyInt_As_int64_t(__pyx_v_offset); if (unlikely((__pyx_t_5 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 186, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_As_int64_t(__pyx_v_offset); if (unlikely((__pyx_t_5 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 200, __pyx_L1_error) __pyx_v_off = bgzf_seek(__pyx_v_self->bgzf, __pyx_t_5, SEEK_SET); - /* "pysam/libcbgzf.pyx":187 + /* "pysam/libcbgzf.pyx":201 * * cdef int64_t off = bgzf_seek(self.bgzf, offset, SEEK_SET) * if off < 0: # <<<<<<<<<<<<<< @@ -4212,20 +4364,20 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(struct __pyx_obj_5pys __pyx_t_4 = ((__pyx_v_off < 0) != 0); if (unlikely(__pyx_t_4)) { - /* "pysam/libcbgzf.pyx":188 + /* "pysam/libcbgzf.pyx":202 * cdef int64_t off = bgzf_seek(self.bgzf, offset, SEEK_SET) * if off < 0: * raise IOError('Error seeking BGZFFile object') # <<<<<<<<<<<<<< * * return off */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 188, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 202, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 188, __pyx_L1_error) + __PYX_ERR(0, 202, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":187 + /* "pysam/libcbgzf.pyx":201 * * cdef int64_t off = bgzf_seek(self.bgzf, offset, SEEK_SET) * if off < 0: # <<<<<<<<<<<<<< @@ -4234,7 +4386,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(struct __pyx_obj_5pys */ } - /* "pysam/libcbgzf.pyx":190 + /* "pysam/libcbgzf.pyx":204 * raise IOError('Error seeking BGZFFile object') * * return off # <<<<<<<<<<<<<< @@ -4242,14 +4394,14 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(struct __pyx_obj_5pys * def readline(self, size=-1): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyInt_From_int64_t(__pyx_v_off); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 190, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int64_t(__pyx_v_off); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 204, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcbgzf.pyx":180 - * return True + /* "pysam/libcbgzf.pyx":194 + * return off * * def seek(self, offset, whence=io.SEEK_SET): # <<<<<<<<<<<<<< * if not self.bgzf: @@ -4268,7 +4420,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(struct __pyx_obj_5pys return __pyx_r; } -/* "pysam/libcbgzf.pyx":192 +/* "pysam/libcbgzf.pyx":206 * return off * * def readline(self, size=-1): # <<<<<<<<<<<<<< @@ -4277,8 +4429,8 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_26seek(struct __pyx_obj_5pys */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_29readline(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_29readline(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_31readline(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_31readline(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { CYTHON_UNUSED PyObject *__pyx_v_size = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations @@ -4305,7 +4457,7 @@ static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_29readline(PyObject *__pyx_v } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "readline") < 0)) __PYX_ERR(0, 192, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "readline") < 0)) __PYX_ERR(0, 206, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -4319,29 +4471,30 @@ static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_29readline(PyObject *__pyx_v } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("readline", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 192, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("readline", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 206, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcbgzf.BGZFile.readline", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_28readline(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self), __pyx_v_size); + __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_30readline(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self), __pyx_v_size); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_28readline(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_size) { +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_30readline(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_size) { kstring_t __pyx_v_line; - PyObject *__pyx_v_ret = NULL; + int __pyx_v_ret; + PyObject *__pyx_v_s = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("readline", 0); - /* "pysam/libcbgzf.pyx":193 + /* "pysam/libcbgzf.pyx":207 * * def readline(self, size=-1): * if not self.bgzf: # <<<<<<<<<<<<<< @@ -4351,20 +4504,20 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_28readline(struct __pyx_obj_ __pyx_t_1 = ((!(__pyx_v_self->bgzf != 0)) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcbgzf.pyx":194 + /* "pysam/libcbgzf.pyx":208 * def readline(self, size=-1): * if not self.bgzf: * raise ValueError("readline() on closed BGZFile object") # <<<<<<<<<<<<<< * * cdef kstring_t line */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 194, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 208, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 194, __pyx_L1_error) + __PYX_ERR(0, 208, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":193 + /* "pysam/libcbgzf.pyx":207 * * def readline(self, size=-1): * if not self.bgzf: # <<<<<<<<<<<<<< @@ -4373,71 +4526,139 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_28readline(struct __pyx_obj_ */ } - /* "pysam/libcbgzf.pyx":199 + /* "pysam/libcbgzf.pyx":213 * cdef char c * * line.l = line.m = 0 # <<<<<<<<<<<<<< * line.s = NULL - * if bgzf_getline(self.bgzf, '\n', &line) < 0: + * */ __pyx_v_line.l = 0; __pyx_v_line.m = 0; - /* "pysam/libcbgzf.pyx":200 + /* "pysam/libcbgzf.pyx":214 * * line.l = line.m = 0 * line.s = NULL # <<<<<<<<<<<<<< - * if bgzf_getline(self.bgzf, '\n', &line) < 0: - * raise IOError('Error reading line in BGZFFile object') + * + * cdef int ret = bgzf_getline(self.bgzf, '\n', &line) */ __pyx_v_line.s = NULL; - /* "pysam/libcbgzf.pyx":201 - * line.l = line.m = 0 + /* "pysam/libcbgzf.pyx":216 * line.s = NULL - * if bgzf_getline(self.bgzf, '\n', &line) < 0: # <<<<<<<<<<<<<< - * raise IOError('Error reading line in BGZFFile object') * + * cdef int ret = bgzf_getline(self.bgzf, '\n', &line) # <<<<<<<<<<<<<< + * if ret == -1: + * s = b'' */ - __pyx_t_1 = ((bgzf_getline(__pyx_v_self->bgzf, '\n', (&__pyx_v_line)) < 0) != 0); - if (unlikely(__pyx_t_1)) { + __pyx_v_ret = bgzf_getline(__pyx_v_self->bgzf, '\n', (&__pyx_v_line)); - /* "pysam/libcbgzf.pyx":202 - * line.s = NULL - * if bgzf_getline(self.bgzf, '\n', &line) < 0: - * raise IOError('Error reading line in BGZFFile object') # <<<<<<<<<<<<<< + /* "pysam/libcbgzf.pyx":217 * - * ret = charptr_to_str_w_len(line.s, line.l) + * cdef int ret = bgzf_getline(self.bgzf, '\n', &line) + * if ret == -1: # <<<<<<<<<<<<<< + * s = b'' + * elif ret == -2: + */ + switch (__pyx_v_ret) { + case -1L: + + /* "pysam/libcbgzf.pyx":218 + * cdef int ret = bgzf_getline(self.bgzf, '\n', &line) + * if ret == -1: + * s = b'' # <<<<<<<<<<<<<< + * elif ret == -2: + * if line.m: + */ + __Pyx_INCREF(__pyx_kp_b__6); + __pyx_v_s = __pyx_kp_b__6; + + /* "pysam/libcbgzf.pyx":217 + * + * cdef int ret = bgzf_getline(self.bgzf, '\n', &line) + * if ret == -1: # <<<<<<<<<<<<<< + * s = b'' + * elif ret == -2: + */ + break; + + /* "pysam/libcbgzf.pyx":219 + * if ret == -1: + * s = b'' + * elif ret == -2: # <<<<<<<<<<<<<< + * if line.m: + * free(line.s) + */ + case -2L: + + /* "pysam/libcbgzf.pyx":220 + * s = b'' + * elif ret == -2: + * if line.m: # <<<<<<<<<<<<<< + * free(line.s) + * raise IOError('Error reading line in BGZFFile object') + */ + __pyx_t_1 = (__pyx_v_line.m != 0); + if (__pyx_t_1) { + + /* "pysam/libcbgzf.pyx":221 + * elif ret == -2: + * if line.m: + * free(line.s) # <<<<<<<<<<<<<< + * raise IOError('Error reading line in BGZFFile object') + * else: + */ + free(__pyx_v_line.s); + + /* "pysam/libcbgzf.pyx":220 + * s = b'' + * elif ret == -2: + * if line.m: # <<<<<<<<<<<<<< + * free(line.s) + * raise IOError('Error reading line in BGZFFile object') */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 202, __pyx_L1_error) + } + + /* "pysam/libcbgzf.pyx":222 + * if line.m: + * free(line.s) + * raise IOError('Error reading line in BGZFFile object') # <<<<<<<<<<<<<< + * else: + * s = line.s[:line.l] + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 222, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 202, __pyx_L1_error) + __PYX_ERR(0, 222, __pyx_L1_error) - /* "pysam/libcbgzf.pyx":201 - * line.l = line.m = 0 - * line.s = NULL - * if bgzf_getline(self.bgzf, '\n', &line) < 0: # <<<<<<<<<<<<<< - * raise IOError('Error reading line in BGZFFile object') - * + /* "pysam/libcbgzf.pyx":219 + * if ret == -1: + * s = b'' + * elif ret == -2: # <<<<<<<<<<<<<< + * if line.m: + * free(line.s) */ - } + break; + default: - /* "pysam/libcbgzf.pyx":204 + /* "pysam/libcbgzf.pyx":224 * raise IOError('Error reading line in BGZFFile object') - * - * ret = charptr_to_str_w_len(line.s, line.l) # <<<<<<<<<<<<<< + * else: + * s = line.s[:line.l] # <<<<<<<<<<<<<< * * if line.m: */ - __pyx_t_2 = __pyx_f_5pysam_9libcutils_charptr_to_str_w_len(__pyx_v_line.s, __pyx_v_line.l, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 204, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_ret = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_line.s + 0, __pyx_v_line.l - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 224, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_s = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; + break; + } - /* "pysam/libcbgzf.pyx":206 - * ret = charptr_to_str_w_len(line.s, line.l) + /* "pysam/libcbgzf.pyx":226 + * s = line.s[:line.l] * * if line.m: # <<<<<<<<<<<<<< * free(line.s) @@ -4446,17 +4667,17 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_28readline(struct __pyx_obj_ __pyx_t_1 = (__pyx_v_line.m != 0); if (__pyx_t_1) { - /* "pysam/libcbgzf.pyx":207 + /* "pysam/libcbgzf.pyx":227 * * if line.m: * free(line.s) # <<<<<<<<<<<<<< * - * return ret + * return s */ free(__pyx_v_line.s); - /* "pysam/libcbgzf.pyx":206 - * ret = charptr_to_str_w_len(line.s, line.l) + /* "pysam/libcbgzf.pyx":226 + * s = line.s[:line.l] * * if line.m: # <<<<<<<<<<<<<< * free(line.s) @@ -4464,17 +4685,19 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_28readline(struct __pyx_obj_ */ } - /* "pysam/libcbgzf.pyx":209 + /* "pysam/libcbgzf.pyx":229 * free(line.s) * - * return ret # <<<<<<<<<<<<<< + * return s # <<<<<<<<<<<<<< + * + * def __iter__(self): */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_ret); - __pyx_r = __pyx_v_ret; + __Pyx_INCREF(__pyx_v_s); + __pyx_r = __pyx_v_s; goto __pyx_L0; - /* "pysam/libcbgzf.pyx":192 + /* "pysam/libcbgzf.pyx":206 * return off * * def readline(self, size=-1): # <<<<<<<<<<<<<< @@ -4488,7 +4711,252 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_28readline(struct __pyx_obj_ __Pyx_AddTraceback("pysam.libcbgzf.BGZFile.readline", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_ret); + __Pyx_XDECREF(__pyx_v_s); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbgzf.pyx":231 + * return s + * + * def __iter__(self): # <<<<<<<<<<<<<< + * return self + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_33__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_33__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_32__iter__(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_32__iter__(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__", 0); + + /* "pysam/libcbgzf.pyx":232 + * + * def __iter__(self): + * return self # <<<<<<<<<<<<<< + * + * def __next__(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + goto __pyx_L0; + + /* "pysam/libcbgzf.pyx":231 + * return s + * + * def __iter__(self): # <<<<<<<<<<<<<< + * return self + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbgzf.pyx":234 + * return self + * + * def __next__(self): # <<<<<<<<<<<<<< + * line = self.readline() + * if not line: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_35__next__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_35__next__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__next__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_34__next__(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_34__next__(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self) { + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + __Pyx_RefNannySetupContext("__next__", 0); + + /* "pysam/libcbgzf.pyx":235 + * + * def __next__(self): + * line = self.readline() # <<<<<<<<<<<<<< + * if not line: + * raise StopIteration() + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_readline); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 235, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 235, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 235, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_line = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pysam/libcbgzf.pyx":236 + * def __next__(self): + * line = self.readline() + * if not line: # <<<<<<<<<<<<<< + * raise StopIteration() + * return line + */ + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_line); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 236, __pyx_L1_error) + __pyx_t_5 = ((!__pyx_t_4) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pysam/libcbgzf.pyx":237 + * line = self.readline() + * if not line: + * raise StopIteration() # <<<<<<<<<<<<<< + * return line + */ + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_StopIteration); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 237, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 237, __pyx_L1_error) + + /* "pysam/libcbgzf.pyx":236 + * def __next__(self): + * line = self.readline() + * if not line: # <<<<<<<<<<<<<< + * raise StopIteration() + * return line + */ + } + + /* "pysam/libcbgzf.pyx":238 + * if not line: + * raise StopIteration() + * return line # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_line); + __pyx_r = __pyx_v_line; + goto __pyx_L0; + + /* "pysam/libcbgzf.pyx":234 + * return self + * + * def __next__(self): # <<<<<<<<<<<<<< + * line = self.readline() + * if not line: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcbgzf.BGZFile.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcbgzf.pyx":36 + * """ + * cdef BGZF* bgzf + * cdef readonly object name, index # <<<<<<<<<<<<<< + * + * def __init__(self, filename, mode=None, index=None): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_4name_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_4name_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_4name___get__(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_4name___get__(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->name); + __pyx_r = __pyx_v_self->name; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_5index_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_5index_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_5index___get__(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_5index___get__(struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->index); + __pyx_r = __pyx_v_self->index; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; @@ -4501,19 +4969,19 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_28readline(struct __pyx_obj_ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_31__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_31__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_37__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_37__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_30__reduce_cython__(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_36__reduce_cython__(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_30__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_36__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -4525,7 +4993,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_30__reduce_cython__(CYTHON_U * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.bgzf cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -4555,19 +5023,19 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_30__reduce_cython__(CYTHON_U */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_33__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_33__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_39__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_5pysam_8libcbgzf_7BGZFile_39__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_32__setstate_cython__(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_8libcbgzf_7BGZFile_38__setstate_cython__(((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_32__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_38__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_8libcbgzf_BGZFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -4578,7 +5046,7 @@ static PyObject *__pyx_pf_5pysam_8libcbgzf_7BGZFile_32__setstate_cython__(CYTHON * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.bgzf cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -5247,18 +5715,19 @@ static PyObject *__pyx_tp_new_5pysam_8libcbgzf_BGZFile(PyTypeObject *t, CYTHON_U } if (unlikely(!o)) return 0; p = ((struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)o); - p->name = ((PyObject*)Py_None); Py_INCREF(Py_None); - p->index = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->name = Py_None; Py_INCREF(Py_None); + p->index = Py_None; Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_5pysam_8libcbgzf_BGZFile(PyObject *o) { struct __pyx_obj_5pysam_8libcbgzf_BGZFile *p = (struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)o; #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif + PyObject_GC_UnTrack(o); { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); @@ -5272,10 +5741,42 @@ static void __pyx_tp_dealloc_5pysam_8libcbgzf_BGZFile(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } +static int __pyx_tp_traverse_5pysam_8libcbgzf_BGZFile(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_8libcbgzf_BGZFile *p = (struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)o; + if (p->name) { + e = (*v)(p->name, a); if (e) return e; + } + if (p->index) { + e = (*v)(p->index, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5pysam_8libcbgzf_BGZFile(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_5pysam_8libcbgzf_BGZFile *p = (struct __pyx_obj_5pysam_8libcbgzf_BGZFile *)o; + tmp = ((PyObject*)p->name); + p->name = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->index); + p->index = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + static PyObject *__pyx_getprop_5pysam_8libcbgzf_7BGZFile_closed(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5pysam_8libcbgzf_7BGZFile_6closed_1__get__(o); } +static PyObject *__pyx_getprop_5pysam_8libcbgzf_7BGZFile_name(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_8libcbgzf_7BGZFile_4name_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_8libcbgzf_7BGZFile_index(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_8libcbgzf_7BGZFile_5index_1__get__(o); +} + static PyMethodDef __pyx_methods_5pysam_8libcbgzf_BGZFile[] = { {"write", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_5write, METH_O, 0}, {"read", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_7read, METH_VARARGS|METH_KEYWORDS, 0}, @@ -5288,15 +5789,19 @@ static PyMethodDef __pyx_methods_5pysam_8libcbgzf_BGZFile[] = { {"readable", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_21readable, METH_NOARGS, 0}, {"writable", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_23writable, METH_NOARGS, 0}, {"seekable", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_25seekable, METH_NOARGS, 0}, - {"seek", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_27seek, METH_VARARGS|METH_KEYWORDS, 0}, - {"readline", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_29readline, METH_VARARGS|METH_KEYWORDS, 0}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_31__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_33__setstate_cython__, METH_O, 0}, + {"tell", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_27tell, METH_NOARGS, 0}, + {"seek", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_29seek, METH_VARARGS|METH_KEYWORDS, 0}, + {"readline", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_31readline, METH_VARARGS|METH_KEYWORDS, 0}, + {"__next__", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_35__next__, METH_NOARGS|METH_COEXIST, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_37__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_8libcbgzf_7BGZFile_39__setstate_cython__, METH_O, 0}, {0, 0, 0, 0} }; static struct PyGetSetDef __pyx_getsets_5pysam_8libcbgzf_BGZFile[] = { {(char *)"closed", __pyx_getprop_5pysam_8libcbgzf_7BGZFile_closed, 0, (char *)0, 0}, + {(char *)"name", __pyx_getprop_5pysam_8libcbgzf_7BGZFile_name, 0, (char *)0, 0}, + {(char *)"index", __pyx_getprop_5pysam_8libcbgzf_7BGZFile_index, 0, (char *)0, 0}, {0, 0, 0, 0, 0} }; @@ -5325,14 +5830,14 @@ static PyTypeObject __pyx_type_5pysam_8libcbgzf_BGZFile = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ "The BGZFile class simulates most of the methods of a file object with\n the exception of the truncate() method.\n\n This class only supports opening files in binary mode. If you need to open a\n compressed file in text mode, use the gzip.open() function.\n ", /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5pysam_8libcbgzf_BGZFile, /*tp_traverse*/ + __pyx_tp_clear_5pysam_8libcbgzf_BGZFile, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ + __pyx_pw_5pysam_8libcbgzf_7BGZFile_33__iter__, /*tp_iter*/ + __pyx_pw_5pysam_8libcbgzf_7BGZFile_35__next__, /*tp_iternext*/ __pyx_methods_5pysam_8libcbgzf_BGZFile, /*tp_methods*/ 0, /*tp_members*/ __pyx_getsets_5pysam_8libcbgzf_BGZFile, /*tp_getset*/ @@ -5406,15 +5911,16 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_Error_building_bgzf_index, __pyx_k_Error_building_bgzf_index, sizeof(__pyx_k_Error_building_bgzf_index), 0, 0, 1, 0}, {&__pyx_kp_s_Error_closing_BGZFile_object, __pyx_k_Error_closing_BGZFile_object, sizeof(__pyx_k_Error_closing_BGZFile_object), 0, 0, 1, 0}, {&__pyx_kp_s_Error_flushing_BGZFile_object, __pyx_k_Error_flushing_BGZFile_object, sizeof(__pyx_k_Error_flushing_BGZFile_object), 0, 0, 1, 0}, + {&__pyx_kp_s_Error_in_tell_on_BGZFFile_object, __pyx_k_Error_in_tell_on_BGZFFile_object, sizeof(__pyx_k_Error_in_tell_on_BGZFFile_object), 0, 0, 1, 0}, {&__pyx_kp_s_Error_reading_from_BGZFile, __pyx_k_Error_reading_from_BGZFile, sizeof(__pyx_k_Error_reading_from_BGZFile), 0, 0, 1, 0}, {&__pyx_kp_s_Error_reading_line_in_BGZFFile_o, __pyx_k_Error_reading_line_in_BGZFFile_o, sizeof(__pyx_k_Error_reading_line_in_BGZFFile_o), 0, 0, 1, 0}, {&__pyx_kp_s_Error_seeking_BGZFFile_object, __pyx_k_Error_seeking_BGZFFile_object, sizeof(__pyx_k_Error_seeking_BGZFFile_object), 0, 0, 1, 0}, {&__pyx_n_s_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 0, 0, 1, 1}, {&__pyx_kp_s_Invalid_mode_r, __pyx_k_Invalid_mode_r, sizeof(__pyx_k_Invalid_mode_r), 0, 0, 1, 0}, {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, - {&__pyx_n_s_OSError, __pyx_k_OSError, sizeof(__pyx_k_OSError), 0, 0, 1, 1}, {&__pyx_n_s_SEEK_SET, __pyx_k_SEEK_SET, sizeof(__pyx_k_SEEK_SET), 0, 0, 1, 1}, {&__pyx_kp_s_Seek_from_end_not_supported, __pyx_k_Seek_from_end_not_supported, sizeof(__pyx_k_Seek_from_end_not_supported), 0, 0, 1, 0}, + {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1}, {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, {&__pyx_n_s_U, __pyx_k_U, sizeof(__pyx_k_U), 0, 0, 1, 1}, {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, @@ -5443,6 +5949,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_read_on_closed_BGZFile_object, __pyx_k_read_on_closed_BGZFile_object, sizeof(__pyx_k_read_on_closed_BGZFile_object), 0, 0, 1, 0}, {&__pyx_kp_s_read_on_write_only_BGZFile_objec, __pyx_k_read_on_write_only_BGZFile_objec, sizeof(__pyx_k_read_on_write_only_BGZFile_objec), 0, 0, 1, 0}, {&__pyx_kp_s_readable_on_closed_BGZFile_objec, __pyx_k_readable_on_closed_BGZFile_objec, sizeof(__pyx_k_readable_on_closed_BGZFile_objec), 0, 0, 1, 0}, + {&__pyx_n_s_readline, __pyx_k_readline, sizeof(__pyx_k_readline), 0, 0, 1, 1}, {&__pyx_kp_s_readline_on_closed_BGZFile_objec, __pyx_k_readline_on_closed_BGZFile_objec, sizeof(__pyx_k_readline_on_closed_BGZFile_objec), 0, 0, 1, 0}, {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, @@ -5464,10 +5971,10 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 47, __pyx_L1_error) - __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 57, __pyx_L1_error) - __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 68, __pyx_L1_error) - __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 157, __pyx_L1_error) + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 48, __pyx_L1_error) + __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 62, __pyx_L1_error) + __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 162, __pyx_L1_error) + __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 237, __pyx_L1_error) __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(2, 109, __pyx_L1_error) return 0; @@ -5479,225 +5986,247 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "pysam/libcbgzf.pyx":57 + /* "pysam/libcbgzf.pyx":62 * * if self.bgzf.is_write and index is not None and bgzf_index_build_init(self.bgzf) < 0: * raise IOError('Error building bgzf index') # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_Error_building_bgzf_index); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 57, __pyx_L1_error) + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_Error_building_bgzf_index); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 62, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); - /* "pysam/libcbgzf.pyx":64 - * def write(self,data): + /* "pysam/libcbgzf.pyx":69 + * def write(self, data): * if not self.bgzf: * raise ValueError("write() on closed BGZFile object") # <<<<<<<<<<<<<< * * if not self.bgzf.is_write: */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_write_on_closed_BGZFile_object); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 64, __pyx_L1_error) + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_write_on_closed_BGZFile_object); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 69, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2); - /* "pysam/libcbgzf.pyx":78 + /* "pysam/libcbgzf.pyx":83 * * if length > 0 and bgzf_write(self.bgzf, data, length) < 0: * raise IOError('BGZFile write failed') # <<<<<<<<<<<<<< * * return length */ - __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_BGZFile_write_failed); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 78, __pyx_L1_error) + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_BGZFile_write_failed); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 83, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__3); - /* "pysam/libcbgzf.pyx":86 + /* "pysam/libcbgzf.pyx":91 * * if not self.bgzf: * raise ValueError("read() on closed BGZFile object") # <<<<<<<<<<<<<< * * if self.bgzf.is_write: */ - __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_read_on_closed_BGZFile_object); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_read_on_closed_BGZFile_object); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 91, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__4); __Pyx_GIVEREF(__pyx_tuple__4); - /* "pysam/libcbgzf.pyx":99 + /* "pysam/libcbgzf.pyx":104 * read_size = bgzf_read(self.bgzf, chunk, BUFFER_SIZE) * if read_size < 0: * raise IOError('Error reading from BGZFile') # <<<<<<<<<<<<<< * elif not read_size: * break */ - __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_Error_reading_from_BGZFile); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 99, __pyx_L1_error) + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_Error_reading_from_BGZFile); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__5); __Pyx_GIVEREF(__pyx_tuple__5); - /* "pysam/libcbgzf.pyx":111 + /* "pysam/libcbgzf.pyx":116 * read_size = bgzf_read(self.bgzf, chunk, size) * if read_size < 0: * raise IOError('Error reading from BGZFile') # <<<<<<<<<<<<<< * elif read_size < size: * chunk = chunk[:size] */ - __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_Error_reading_from_BGZFile); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_Error_reading_from_BGZFile); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 116, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__7); __Pyx_GIVEREF(__pyx_tuple__7); - /* "pysam/libcbgzf.pyx":127 + /* "pysam/libcbgzf.pyx":132 * * if self.bgzf.is_write and bgzf_flush(self.bgzf) < 0: * raise IOError('Error flushing BGZFile object') # <<<<<<<<<<<<<< * * if self.index and bgzf_index_dump(self.bgzf, self.index, NULL) < 0: */ - __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_Error_flushing_BGZFile_object); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_Error_flushing_BGZFile_object); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__8); __Pyx_GIVEREF(__pyx_tuple__8); - /* "pysam/libcbgzf.pyx":130 + /* "pysam/libcbgzf.pyx":135 * * if self.index and bgzf_index_dump(self.bgzf, self.index, NULL) < 0: * raise IOError('Cannot write index') # <<<<<<<<<<<<<< * * cdef ret = bgzf_close(self.bgzf) */ - __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_Cannot_write_index); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 130, __pyx_L1_error) + __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_Cannot_write_index); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__9); __Pyx_GIVEREF(__pyx_tuple__9); - /* "pysam/libcbgzf.pyx":136 + /* "pysam/libcbgzf.pyx":141 * * if ret < 0: * raise IOError('Error closing BGZFile object') # <<<<<<<<<<<<<< * * def __enter__(self): */ - __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_Error_closing_BGZFile_object); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 136, __pyx_L1_error) + __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_Error_closing_BGZFile_object); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 141, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__10); __Pyx_GIVEREF(__pyx_tuple__10); - /* "pysam/libcbgzf.pyx":149 + /* "pysam/libcbgzf.pyx":154 * * if self.bgzf.is_write and bgzf_flush(self.bgzf) < 0: * raise IOError('Error flushing BGZFile object') # <<<<<<<<<<<<<< * * def fileno(self): */ - __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_Error_flushing_BGZFile_object); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 149, __pyx_L1_error) + __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_Error_flushing_BGZFile_object); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__11); __Pyx_GIVEREF(__pyx_tuple__11); - /* "pysam/libcbgzf.pyx":157 + /* "pysam/libcbgzf.pyx":162 * doesn't support fileno(). * """ * raise AttributeError('fileno') # <<<<<<<<<<<<<< * * def rewind(self): */ - __pyx_tuple__12 = PyTuple_Pack(1, __pyx_n_s_fileno); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 157, __pyx_L1_error) + __pyx_tuple__12 = PyTuple_Pack(1, __pyx_n_s_fileno); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 162, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__12); __Pyx_GIVEREF(__pyx_tuple__12); - /* "pysam/libcbgzf.pyx":163 + /* "pysam/libcbgzf.pyx":168 * beginning of the file''' * if not self.bgzf: * raise ValueError("rewind() on closed BGZFile object") # <<<<<<<<<<<<<< * if not self.bgzf.is_write: - * raise OSError("Can't rewind in write mode") + * raise IOError("Can't rewind in write mode") */ - __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_rewind_on_closed_BGZFile_object); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 163, __pyx_L1_error) + __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_rewind_on_closed_BGZFile_object); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 168, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__13); __Pyx_GIVEREF(__pyx_tuple__13); - /* "pysam/libcbgzf.pyx":165 + /* "pysam/libcbgzf.pyx":170 * raise ValueError("rewind() on closed BGZFile object") * if not self.bgzf.is_write: - * raise OSError("Can't rewind in write mode") # <<<<<<<<<<<<<< + * raise IOError("Can't rewind in write mode") # <<<<<<<<<<<<<< * if bgzf_seek(self.bgzf, 0, SEEK_SET) < 0: * raise IOError('Error seeking BGZFFile object') */ - __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_Can_t_rewind_in_write_mode); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 165, __pyx_L1_error) + __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_Can_t_rewind_in_write_mode); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 170, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__14); __Pyx_GIVEREF(__pyx_tuple__14); - /* "pysam/libcbgzf.pyx":167 - * raise OSError("Can't rewind in write mode") + /* "pysam/libcbgzf.pyx":172 + * raise IOError("Can't rewind in write mode") * if bgzf_seek(self.bgzf, 0, SEEK_SET) < 0: * raise IOError('Error seeking BGZFFile object') # <<<<<<<<<<<<<< * * def readable(self): */ - __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_Error_seeking_BGZFFile_object); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_Error_seeking_BGZFFile_object); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__15); __Pyx_GIVEREF(__pyx_tuple__15); - /* "pysam/libcbgzf.pyx":171 + /* "pysam/libcbgzf.pyx":176 * def readable(self): * if not self.bgzf: * raise ValueError("readable() on closed BGZFile object") # <<<<<<<<<<<<<< * return self.bgzf != NULL and not self.bgzf.is_write * */ - __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_s_readable_on_closed_BGZFile_objec); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 171, __pyx_L1_error) + __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_s_readable_on_closed_BGZFile_objec); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 176, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__16); __Pyx_GIVEREF(__pyx_tuple__16); - /* "pysam/libcbgzf.pyx":182 + /* "pysam/libcbgzf.pyx":187 + * def tell(self): + * if not self.bgzf: + * raise ValueError("seek() on closed BGZFile object") # <<<<<<<<<<<<<< + * cdef int64_t off = bgzf_tell(self.bgzf) + * if off < 0: + */ + __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s_seek_on_closed_BGZFile_object); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 187, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__17); + __Pyx_GIVEREF(__pyx_tuple__17); + + /* "pysam/libcbgzf.pyx":190 + * cdef int64_t off = bgzf_tell(self.bgzf) + * if off < 0: + * raise IOError('Error in tell on BGZFFile object') # <<<<<<<<<<<<<< + * + * return off + */ + __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_Error_in_tell_on_BGZFFile_object); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__18); + __Pyx_GIVEREF(__pyx_tuple__18); + + /* "pysam/libcbgzf.pyx":196 * def seek(self, offset, whence=io.SEEK_SET): * if not self.bgzf: * raise ValueError("seek() on closed BGZFile object") # <<<<<<<<<<<<<< * if whence is not io.SEEK_SET: * raise ValueError('Seek from end not supported') */ - __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_seek_on_closed_BGZFile_object); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__18); - __Pyx_GIVEREF(__pyx_tuple__18); + __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_seek_on_closed_BGZFile_object); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 196, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__20); + __Pyx_GIVEREF(__pyx_tuple__20); - /* "pysam/libcbgzf.pyx":184 + /* "pysam/libcbgzf.pyx":198 * raise ValueError("seek() on closed BGZFile object") * if whence is not io.SEEK_SET: * raise ValueError('Seek from end not supported') # <<<<<<<<<<<<<< * * cdef int64_t off = bgzf_seek(self.bgzf, offset, SEEK_SET) */ - __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_Seek_from_end_not_supported); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 184, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__19); - __Pyx_GIVEREF(__pyx_tuple__19); + __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_Seek_from_end_not_supported); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 198, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__21); + __Pyx_GIVEREF(__pyx_tuple__21); - /* "pysam/libcbgzf.pyx":188 + /* "pysam/libcbgzf.pyx":202 * cdef int64_t off = bgzf_seek(self.bgzf, offset, SEEK_SET) * if off < 0: * raise IOError('Error seeking BGZFFile object') # <<<<<<<<<<<<<< * * return off */ - __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_Error_seeking_BGZFFile_object); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 188, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__20); - __Pyx_GIVEREF(__pyx_tuple__20); + __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_Error_seeking_BGZFFile_object); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__22); + __Pyx_GIVEREF(__pyx_tuple__22); - /* "pysam/libcbgzf.pyx":194 + /* "pysam/libcbgzf.pyx":208 * def readline(self, size=-1): * if not self.bgzf: * raise ValueError("readline() on closed BGZFile object") # <<<<<<<<<<<<<< * * cdef kstring_t line */ - __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_readline_on_closed_BGZFile_objec); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 194, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__21); - __Pyx_GIVEREF(__pyx_tuple__21); + __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_readline_on_closed_BGZFile_objec); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 208, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__23); + __Pyx_GIVEREF(__pyx_tuple__23); - /* "pysam/libcbgzf.pyx":202 - * line.s = NULL - * if bgzf_getline(self.bgzf, '\n', &line) < 0: + /* "pysam/libcbgzf.pyx":222 + * if line.m: + * free(line.s) * raise IOError('Error reading line in BGZFFile object') # <<<<<<<<<<<<<< - * - * ret = charptr_to_str_w_len(line.s, line.l) + * else: + * s = line.s[:line.l] */ - __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_Error_reading_line_in_BGZFFile_o); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 202, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__22); - __Pyx_GIVEREF(__pyx_tuple__22); + __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_Error_reading_line_in_BGZFFile_o); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 222, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__24); + __Pyx_GIVEREF(__pyx_tuple__24); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -5705,18 +6234,18 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.bgzf cannot be converted to a Python object for pickling") */ - __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_self_bgzf_cannot_be_converted_to); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__23); - __Pyx_GIVEREF(__pyx_tuple__23); + __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_s_self_bgzf_cannot_be_converted_to); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__25); + __Pyx_GIVEREF(__pyx_tuple__25); /* "(tree fragment)":4 * raise TypeError("self.bgzf cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.bgzf cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_self_bgzf_cannot_be_converted_to); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__24); - __Pyx_GIVEREF(__pyx_tuple__24); + __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_self_bgzf_cannot_be_converted_to); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__26); + __Pyx_GIVEREF(__pyx_tuple__26); __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -5769,14 +6298,14 @@ static int __Pyx_modinit_type_init_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); /*--- Type init code ---*/ - if (PyType_Ready(&__pyx_type_5pysam_8libcbgzf_BGZFile) < 0) __PYX_ERR(0, 27, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_8libcbgzf_BGZFile) < 0) __PYX_ERR(0, 28, __pyx_L1_error) __pyx_type_5pysam_8libcbgzf_BGZFile.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_8libcbgzf_BGZFile.tp_dictoffset && __pyx_type_5pysam_8libcbgzf_BGZFile.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_8libcbgzf_BGZFile.tp_getattro = __Pyx_PyObject_GenericGetAttr; } #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_8libcbgzf_BGZFile, "__init__"); if (unlikely(!wrapper)) __PYX_ERR(0, 27, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_8libcbgzf_BGZFile, "__init__"); if (unlikely(!wrapper)) __PYX_ERR(0, 28, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_8libcbgzf_7BGZFile___init__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_8libcbgzf_7BGZFile___init__.doc = __pyx_doc_5pysam_8libcbgzf_7BGZFile___init__; @@ -5784,8 +6313,8 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (PyObject_SetAttrString(__pyx_m, "BGZFile", (PyObject *)&__pyx_type_5pysam_8libcbgzf_BGZFile) < 0) __PYX_ERR(0, 27, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_8libcbgzf_BGZFile) < 0) __PYX_ERR(0, 27, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "BGZFile", (PyObject *)&__pyx_type_5pysam_8libcbgzf_BGZFile) < 0) __PYX_ERR(0, 28, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_8libcbgzf_BGZFile) < 0) __PYX_ERR(0, 28, __pyx_L1_error) __pyx_ptype_5pysam_8libcbgzf_BGZFile = &__pyx_type_5pysam_8libcbgzf_BGZFile; __Pyx_RefNannyFinishContext(); return 0; @@ -5808,8 +6337,8 @@ static int __Pyx_modinit_type_import_code(void) { __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) __PYX_ERR(4, 8, __pyx_L1_error) __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) __PYX_ERR(5, 15, __pyx_L1_error) __pyx_ptype_7cpython_5array_array = __Pyx_ImportType("array", "array", sizeof(arrayobject), 0); if (unlikely(!__pyx_ptype_7cpython_5array_array)) __PYX_ERR(2, 58, __pyx_L1_error) - __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(6, 1904, __pyx_L1_error) - __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(6, 1904, __pyx_L1_error) + __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(6, 2590, __pyx_L1_error) + __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(6, 2590, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -5831,10 +6360,8 @@ static int __Pyx_modinit_function_import_code(void) { __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); /*--- Function import code ---*/ __pyx_t_1 = __Pyx_ImportModule("pysam.libcutils"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_1, "charptr_to_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_charptr_to_str, "PyObject *(char const *, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_1, "charptr_to_str_w_len", (void (**)(void))&__pyx_f_5pysam_9libcutils_charptr_to_str_w_len, "PyObject *(char const *, size_t, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str_w_len *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) - if (__Pyx_ImportFunction(__pyx_t_1, "force_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_str, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (__Pyx_ImportFunction(__pyx_t_1, "force_bytes", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_bytes, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_bytes *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_ImportFunction(__pyx_t_1, "encode_filename", (void (**)(void))&__pyx_f_5pysam_9libcutils_encode_filename, "PyObject *(PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error) Py_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_RefNannyFinishContext(); return 0; @@ -6030,49 +6557,49 @@ if (!__Pyx_RefNanny) { if (PyDict_SetItem(__pyx_d, __pyx_n_s_io, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbgzf.pyx":21 - * + /* "pysam/libcbgzf.pyx":22 + * bgzf_tell, bgzf_getline, kstring_t, SEEK_SET, BGZF * * __all__ = ["BGZFile"] # <<<<<<<<<<<<<< * * */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error) + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_BGZFile); __Pyx_GIVEREF(__pyx_n_s_BGZFile); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_BGZFile); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 21, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcbgzf.pyx":24 + /* "pysam/libcbgzf.pyx":25 * * * BUFFER_SIZE = io.DEFAULT_BUFFER_SIZE # <<<<<<<<<<<<<< * * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_io); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 24, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_io); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_DEFAULT_BUFFER_SIZE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_DEFAULT_BUFFER_SIZE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_BUFFER_SIZE, __pyx_t_2) < 0) __PYX_ERR(0, 24, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_BUFFER_SIZE, __pyx_t_2) < 0) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcbgzf.pyx":180 - * return True + /* "pysam/libcbgzf.pyx":194 + * return off * * def seek(self, offset, whence=io.SEEK_SET): # <<<<<<<<<<<<<< * if not self.bgzf: * raise ValueError("seek() on closed BGZFile object") */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_io); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_io); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 194, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_SEEK_SET); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_SEEK_SET); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 194, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_k__17 = __pyx_t_1; + __pyx_k__19 = __pyx_t_1; __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; diff --git a/pysam/libcbgzf.pyx b/pysam/libcbgzf.pyx index 558ceff39..02ff2a27e 100644 --- a/pysam/libcbgzf.pyx +++ b/pysam/libcbgzf.pyx @@ -14,9 +14,10 @@ from libc.stdlib cimport malloc, calloc, realloc, free from cpython.object cimport PyObject from cpython.bytes cimport PyBytes_FromStringAndSize, _PyBytes_Resize -from pysam.libcutils cimport force_bytes, force_str, charptr_to_str, charptr_to_str_w_len -from pysam.libchtslib cimport * - +from pysam.libcutils cimport force_bytes, encode_filename +from pysam.libchtslib cimport bgzf_open, bgzf_index_build_init, bgzf_write, bgzf_read, \ + bgzf_flush, bgzf_index_dump, bgzf_close, bgzf_seek, \ + bgzf_tell, bgzf_getline, kstring_t, SEEK_SET, BGZF __all__ = ["BGZFile"] @@ -32,7 +33,7 @@ cdef class BGZFile(object): compressed file in text mode, use the gzip.open() function. """ cdef BGZF* bgzf - cdef bytes name, index + cdef readonly object name, index def __init__(self, filename, mode=None, index=None): """Constructor for the BGZFile class. @@ -47,10 +48,14 @@ cdef class BGZFile(object): raise ValueError("Invalid mode: {!r}".format(mode)) if not mode: mode = 'rb' - if mode and 'b' not in mode: + elif mode and 'b' not in mode: mode += 'b' - self.name = force_bytes(filename) - self.index = force_bytes(index) if index is not None else None + + mode = force_bytes(mode) + + self.name = encode_filename(filename) + self.index = encode_filename(index) if index is not None else None + self.bgzf = bgzf_open(self.name, mode) if self.bgzf.is_write and index is not None and bgzf_index_build_init(self.bgzf) < 0: @@ -59,13 +64,13 @@ cdef class BGZFile(object): def __dealloc__(self): self.close() - def write(self,data): + def write(self, data): if not self.bgzf: raise ValueError("write() on closed BGZFile object") if not self.bgzf.is_write: import errno - raise OSError(errno.EBADF, "write() on read-only BGZFile object") + raise IOError(errno.EBADF, "write() on read-only BGZFile object") if isinstance(data, bytes): length = len(data) @@ -87,7 +92,7 @@ cdef class BGZFile(object): if self.bgzf.is_write: import errno - raise OSError(errno.EBADF, "read() on write-only BGZFile object") + raise IOError(errno.EBADF, "read() on write-only BGZFile object") if size < 0: chunks = [] @@ -162,7 +167,7 @@ cdef class BGZFile(object): if not self.bgzf: raise ValueError("rewind() on closed BGZFile object") if not self.bgzf.is_write: - raise OSError("Can't rewind in write mode") + raise IOError("Can't rewind in write mode") if bgzf_seek(self.bgzf, 0, SEEK_SET) < 0: raise IOError('Error seeking BGZFFile object') @@ -177,6 +182,15 @@ cdef class BGZFile(object): def seekable(self): return True + def tell(self): + if not self.bgzf: + raise ValueError("seek() on closed BGZFile object") + cdef int64_t off = bgzf_tell(self.bgzf) + if off < 0: + raise IOError('Error in tell on BGZFFile object') + + return off + def seek(self, offset, whence=io.SEEK_SET): if not self.bgzf: raise ValueError("seek() on closed BGZFile object") @@ -198,12 +212,27 @@ cdef class BGZFile(object): line.l = line.m = 0 line.s = NULL - if bgzf_getline(self.bgzf, '\n', &line) < 0: - raise IOError('Error reading line in BGZFFile object') - ret = charptr_to_str_w_len(line.s, line.l) + cdef int ret = bgzf_getline(self.bgzf, '\n', &line) + if ret == -1: + s = b'' + elif ret == -2: + if line.m: + free(line.s) + raise IOError('Error reading line in BGZFFile object') + else: + s = line.s[:line.l] if line.m: free(line.s) - return ret + return s + + def __iter__(self): + return self + + def __next__(self): + line = self.readline() + if not line: + raise StopIteration() + return line diff --git a/pysam/libcfaidx.c b/pysam/libcfaidx.c index b71e1a8a0..9f9b9be45 100644 --- a/pysam/libcfaidx.c +++ b/pysam/libcfaidx.c @@ -568,6 +568,7 @@ static CYTHON_INLINE float __PYX_NAN() { #include #include "pythread.h" #include +#include "stdarg.h" #include "htslib/kstring.h" #include "htslib_util.h" #include "htslib/hfile.h" @@ -578,8 +579,9 @@ static CYTHON_INLINE float __PYX_NAN() { #include "htslib/tbx.h" #include "htslib/vcf.h" #include "htslib/vcfutils.h" +#include "htslib/cram.h" #include "pysam_stream.h" -#include "pysam_util.h" +#include #ifdef _OPENMP #include #endif /* _OPENMP */ @@ -813,13 +815,10 @@ typedef struct arrayobject arrayobject; struct __pyx_obj_5pysam_10libchtslib_HTSFile; struct __pyx_obj_5pysam_9libcfaidx_FastaFile; struct __pyx_obj_5pysam_9libcfaidx_FastqProxy; -struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy; +struct __pyx_obj_5pysam_9libcfaidx_FastxRecord; struct __pyx_obj_5pysam_9libcfaidx_FastxFile; struct __pyx_obj_5pysam_9libcfaidx_FastqFile; struct __pyx_obj_5pysam_9libcfaidx_Fastafile; -struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open; -struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr; -struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr; struct __pyx_opt_args_5pysam_9libcutils_parse_region; struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array; struct __pyx_opt_args_5pysam_9libcutils_array_to_qualitystring; @@ -941,10 +940,10 @@ struct __pyx_opt_args_5pysam_9libcutils_force_bytes { PyObject *encoding; }; struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array; -struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array; +struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array; -/* "pysam/libcfaidx.pxd":48 - * cdef kseq_t * _delegate +/* "pysam/libcfaidx.pxd":49 + * cdef cython.str to_string(self) * cdef cython.str tostring(self) * cpdef array.array get_quality_array(self, int offset=*) # <<<<<<<<<<<<<< * @@ -955,19 +954,19 @@ struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array { int offset; }; -/* "pysam/libcfaidx.pxd":57 - * cdef public str comment, quality, sequence, name +/* "pysam/libcfaidx.pxd":59 + * cdef cython.str to_string(self) * cdef cython.str tostring(self) * cpdef array.array get_quality_array(self, int offset=*) # <<<<<<<<<<<<<< * - * + * cdef class FastxFile: */ -struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array { +struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array { int __pyx_n; int offset; }; -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -981,6 +980,7 @@ struct __pyx_obj_5pysam_10libchtslib_HTSFile { int64_t start_offset; PyObject *filename; PyObject *mode; + PyObject *threads; PyObject *index_filename; int is_stream; int is_remote; @@ -1012,7 +1012,7 @@ struct __pyx_obj_5pysam_9libcfaidx_FastaFile { * * cdef class FastqProxy: # <<<<<<<<<<<<<< * cdef kseq_t * _delegate - * cdef cython.str tostring(self) + * cdef cython.str to_string(self) */ struct __pyx_obj_5pysam_9libcfaidx_FastqProxy { PyObject_HEAD @@ -1021,16 +1021,16 @@ struct __pyx_obj_5pysam_9libcfaidx_FastqProxy { }; -/* "pysam/libcfaidx.pxd":51 +/* "pysam/libcfaidx.pxd":52 * * - * cdef class PersistentFastqProxy: # <<<<<<<<<<<<<< + * cdef class FastxRecord: # <<<<<<<<<<<<<< * """ * Python container for pysam.libcfaidx.FastqProxy with persistence. */ -struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy { +struct __pyx_obj_5pysam_9libcfaidx_FastxRecord { PyObject_HEAD - struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_vtab; + struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *__pyx_vtab; PyObject *comment; PyObject *quality; PyObject *sequence; @@ -1038,8 +1038,8 @@ struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy { }; -/* "pysam/libcfaidx.pxd":60 - * +/* "pysam/libcfaidx.pxd":61 + * cpdef array.array get_quality_array(self, int offset=*) * * cdef class FastxFile: # <<<<<<<<<<<<<< * cdef object _filename @@ -1056,7 +1056,7 @@ struct __pyx_obj_5pysam_9libcfaidx_FastxFile { }; -/* "pysam/libcfaidx.pxd":72 +/* "pysam/libcfaidx.pxd":73 * * # Compatibility Layer for pysam 0.8.1 * cdef class FastqFile(FastxFile): # <<<<<<<<<<<<<< @@ -1068,7 +1068,7 @@ struct __pyx_obj_5pysam_9libcfaidx_FastqFile { }; -/* "pysam/libcfaidx.pxd":77 +/* "pysam/libcfaidx.pxd":78 * * # Compatibility Layer for pysam < 0.8 * cdef class Fastafile(FastaFile): # <<<<<<<<<<<<<< @@ -1080,53 +1080,8 @@ struct __pyx_obj_5pysam_9libcfaidx_Fastafile { }; -/* "pysam/libcfaidx.pyx":126 - * return faidx_nseq(self.fastafile) - * - * def _open(self, filename, filepath_index=None): # <<<<<<<<<<<<<< - * '''open an indexed fasta file. - * - */ -struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open { - PyObject_HEAD - PyObject *__pyx_v_data; -}; - - -/* "pysam/libcfaidx.pyx":169 - * with open(filepath_index) as inf: - * data = [x.split("\t") for x in inf] - * self._references = tuple(x[0] for x in data) # <<<<<<<<<<<<<< - * self._lengths = tuple(int(x[1]) for x in data) - * self.reference2length = dict(zip(self._references, self._lengths)) - */ -struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr { - PyObject_HEAD - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *__pyx_outer_scope; - PyObject *__pyx_v_x; - PyObject *__pyx_t_0; - Py_ssize_t __pyx_t_1; -}; - - -/* "pysam/libcfaidx.pyx":170 - * data = [x.split("\t") for x in inf] - * self._references = tuple(x[0] for x in data) - * self._lengths = tuple(int(x[1]) for x in data) # <<<<<<<<<<<<<< - * self.reference2length = dict(zip(self._references, self._lengths)) - * - */ -struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr { - PyObject_HEAD - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *__pyx_outer_scope; - PyObject *__pyx_v_x; - PyObject *__pyx_t_0; - Py_ssize_t __pyx_t_1; -}; - - -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -1140,7 +1095,7 @@ struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile { static struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile *__pyx_vtabptr_5pysam_10libchtslib_HTSFile; -/* "pysam/libcfaidx.pyx":80 +/* "pysam/libcfaidx.pyx":85 * ## add automatic indexing. * ## add function to get sequence names. * cdef class FastaFile: # <<<<<<<<<<<<<< @@ -1154,7 +1109,7 @@ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile { static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile *__pyx_vtabptr_5pysam_9libcfaidx_FastaFile; -/* "pysam/libcfaidx.pyx":321 +/* "pysam/libcfaidx.pyx":356 * * * cdef class FastqProxy: # <<<<<<<<<<<<<< @@ -1163,28 +1118,30 @@ static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile *__pyx_vtabptr_5pysam */ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy { + PyObject *(*to_string)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *); PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *); arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array *__pyx_optional_args); }; static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy *__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy; -/* "pysam/libcfaidx.pyx":372 +/* "pysam/libcfaidx.pyx":411 * offset=offset) * - * cdef class PersistentFastqProxy: # <<<<<<<<<<<<<< - * """ - * Python container for pysam.libcfaidx.FastqProxy with persistence. + * cdef class FastxRecord: # <<<<<<<<<<<<<< + * """A fasta/fastq record. + * */ -struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy { - PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *); - arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array *__pyx_optional_args); +struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord { + PyObject *(*to_string)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *); + PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *); + arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array *__pyx_optional_args); }; -static struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy; +static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *__pyx_vtabptr_5pysam_9libcfaidx_FastxRecord; -/* "pysam/libcfaidx.pyx":406 +/* "pysam/libcfaidx.pyx":496 * * * cdef class FastxFile: # <<<<<<<<<<<<<< @@ -1199,7 +1156,7 @@ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile { static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile *__pyx_vtabptr_5pysam_9libcfaidx_FastxFile; -/* "pysam/libcfaidx.pyx":559 +/* "pysam/libcfaidx.pyx":652 * * # Compatibility Layer for pysam 0.8.1 * cdef class FastqFile(FastxFile): # <<<<<<<<<<<<<< @@ -1213,7 +1170,7 @@ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile { static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile *__pyx_vtabptr_5pysam_9libcfaidx_FastqFile; -/* "pysam/libcfaidx.pyx":564 +/* "pysam/libcfaidx.pyx":657 * * # Compatibility Layer for pysam < 0.8 * cdef class Fastafile(FastaFile): # <<<<<<<<<<<<<< @@ -1563,31 +1520,6 @@ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); -/* None.proto */ -static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname); - -/* GetItemInt.proto */ -#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ - (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ - __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ - (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ - __Pyx_GetItemInt_Generic(o, to_py_func(i)))) -#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ - (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ - __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ - (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, - int wraparound, int boundscheck); -#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ - (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ - __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ - (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, - int wraparound, int boundscheck); -static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, - int is_list, int wraparound, int boundscheck); - /* PyCFunctionFastCall.proto */ #if CYTHON_FAST_PYCCALL static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs); @@ -1630,38 +1562,12 @@ static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int eq /* GetModuleGlobalName.proto */ static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); -/* PyObjectLookupSpecial.proto */ -#if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name) { - PyObject *res; - PyTypeObject *tp = Py_TYPE(obj); -#if PY_MAJOR_VERSION < 3 - if (unlikely(PyInstance_Check(obj))) - return __Pyx_PyObject_GetAttrStr(obj, attr_name); -#endif - res = _PyType_Lookup(tp, attr_name); - if (likely(res)) { - descrgetfunc f = Py_TYPE(res)->tp_descr_get; - if (!f) { - Py_INCREF(res); - } else { - res = f(res, obj, (PyObject *)tp); - } - } else { - PyErr_SetObject(PyExc_AttributeError, attr_name); - } - return res; -} -#else -#define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n) -#endif - -/* ListCompAppend.proto */ +/* ListAppend.proto */ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS -static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) { +static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { PyListObject* L = (PyListObject*) list; Py_ssize_t len = Py_SIZE(list); - if (likely(L->allocated > len)) { + if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) { Py_INCREF(x); PyList_SET_ITEM(list, len, x); Py_SIZE(list) = len+1; @@ -1670,27 +1576,15 @@ static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) { return PyList_Append(list, x); } #else -#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x) +#define __Pyx_PyList_Append(L,x) PyList_Append(L,x) #endif -/* SaveResetException.proto */ -#if CYTHON_FAST_THREAD_STATE -#define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb) -static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); -#define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb) -static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); -#else -#define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb) -#define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb) -#endif +/* PyObjectCallMethod1.proto */ +static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); +static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg); -/* GetException.proto */ -#if CYTHON_FAST_THREAD_STATE -#define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb) -static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); -#else -static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); -#endif +/* append.proto */ +static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); /* WriteUnraisableException.proto */ static void __Pyx_WriteUnraisable(const char *name, int clineno, @@ -1709,6 +1603,14 @@ static CYTHON_INLINE int __Pyx_IterFinish(void); /* UnpackItemEndCheck.proto */ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); +/* GetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb) +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); +#endif + /* SwapException.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb) @@ -1717,6 +1619,39 @@ static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject * static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); #endif +/* SaveResetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +#else +#define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb) +#define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb) +#endif + +/* GetItemInt.proto */ +#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ + (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ + __Pyx_GetItemInt_Generic(o, to_py_func(i)))) +#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, + int is_list, int wraparound, int boundscheck); + /* ObjectGetItem.proto */ #if CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key); @@ -1927,10 +1862,10 @@ static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) { #endif /* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); /* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); /* CIntFromPy.proto */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); @@ -1951,75 +1886,6 @@ static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObj #endif #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) -/* FetchCommonType.proto */ -static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type); - -/* PyObjectCallMethod1.proto */ -static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); -static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg); - -/* CoroutineBase.proto */ -typedef PyObject *(*__pyx_coroutine_body_t)(PyObject *, PyThreadState *, PyObject *); -typedef struct { - PyObject_HEAD - __pyx_coroutine_body_t body; - PyObject *closure; - PyObject *exc_type; - PyObject *exc_value; - PyObject *exc_traceback; - PyObject *gi_weakreflist; - PyObject *classobj; - PyObject *yieldfrom; - PyObject *gi_name; - PyObject *gi_qualname; - PyObject *gi_modulename; - PyObject *gi_code; - int resume_label; - char is_running; -} __pyx_CoroutineObject; -static __pyx_CoroutineObject *__Pyx__Coroutine_New( - PyTypeObject *type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, - PyObject *name, PyObject *qualname, PyObject *module_name); -static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit( - __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, - PyObject *name, PyObject *qualname, PyObject *module_name); -static int __Pyx_Coroutine_clear(PyObject *self); -static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value); -static PyObject *__Pyx_Coroutine_Close(PyObject *self); -static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args); -#define __Pyx_Coroutine_SwapException(self) {\ - __Pyx_ExceptionSwap(&(self)->exc_type, &(self)->exc_value, &(self)->exc_traceback);\ - __Pyx_Coroutine_ResetFrameBackpointer(self);\ - } -#define __Pyx_Coroutine_ResetAndClearException(self) {\ - __Pyx_ExceptionReset((self)->exc_type, (self)->exc_value, (self)->exc_traceback);\ - (self)->exc_type = (self)->exc_value = (self)->exc_traceback = NULL;\ - } -#if CYTHON_FAST_THREAD_STATE -#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\ - __Pyx_PyGen__FetchStopIterationValue(__pyx_tstate, pvalue) -#else -#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\ - __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, pvalue) -#endif -static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *tstate, PyObject **pvalue); -static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__pyx_CoroutineObject *self); - -/* PatchModuleWithCoroutine.proto */ -static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code); - -/* PatchGeneratorABC.proto */ -static int __Pyx_patch_abc(void); - -/* Generator.proto */ -#define __Pyx_Generator_USED -static PyTypeObject *__pyx_GeneratorType = 0; -#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType) -#define __Pyx_Generator_New(body, code, closure, name, qualname, module_name)\ - __Pyx__Coroutine_New(__pyx_GeneratorType, body, code, closure, name, qualname, module_name) -static PyObject *__Pyx_Generator_Next(PyObject *self); -static int __pyx_Generator_init(void); - /* CheckBinaryVersion.proto */ static int __Pyx_check_binary_version(void); @@ -2045,10 +1911,12 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); static char *__pyx_f_5pysam_9libcfaidx_9FastaFile__fetch(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_self, char *__pyx_v_reference, int __pyx_v_start, int __pyx_v_end, int *__pyx_v_length); /* proto*/ +static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_to_string(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_self); /* proto*/ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_self); /* proto*/ static arrayobject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_get_quality_array(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array *__pyx_optional_args); /* proto*/ -static PyObject *__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_tostring(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self); /* proto*/ -static arrayobject *__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array *__pyx_optional_args); /* proto*/ +static PyObject *__pyx_f_5pysam_9libcfaidx_11FastxRecord_to_string(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto*/ +static PyObject *__pyx_f_5pysam_9libcfaidx_11FastxRecord_tostring(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto*/ +static arrayobject *__pyx_f_5pysam_9libcfaidx_11FastxRecord_get_quality_array(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array *__pyx_optional_args); /* proto*/ static kseq_t *__pyx_f_5pysam_9libcfaidx_9FastxFile_getCurrent(struct __pyx_obj_5pysam_9libcfaidx_FastxFile *__pyx_v_self); /* proto*/ static int __pyx_f_5pysam_9libcfaidx_9FastxFile_cnext(struct __pyx_obj_5pysam_9libcfaidx_FastxFile *__pyx_v_self); /* proto*/ @@ -2152,6 +2020,8 @@ static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *, ch /* Module declarations from 'pysam.libchtslib' */ static PyTypeObject *__pyx_ptype_5pysam_10libchtslib_HTSFile = 0; +/* Module declarations from 'libc.errno' */ + /* Module declarations from 'pysam.libcutils' */ static PyObject *(*__pyx_f_5pysam_9libcutils_parse_region)(int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcutils_parse_region *__pyx_optional_args); /*proto*/ static arrayobject *(*__pyx_f_5pysam_9libcutils_qualitystring_to_array)(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array *__pyx_optional_args); /*proto*/ @@ -2164,78 +2034,62 @@ static PyObject *(*__pyx_f_5pysam_9libcutils_from_string_and_size)(char const *, /* Module declarations from 'pysam.libcfaidx' */ static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastaFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastqProxy = 0; -static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy = 0; +static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastxRecord = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastxFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastqFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_Fastafile = 0; -static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx___pyx_scope_struct___open = 0; -static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr = 0; -static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr = 0; static PyObject *__pyx_f_5pysam_9libcfaidx_makeFastqProxy(kseq_t *); /*proto*/ -static PyObject *__pyx_f_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy__set_state(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *, PyObject *); /*proto*/ +static PyObject *__pyx_f_5pysam_9libcfaidx___pyx_unpickle_FastxRecord__set_state(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *, PyObject *); /*proto*/ #define __Pyx_MODULE_NAME "pysam.libcfaidx" extern int __pyx_module_is_main_pysam__libcfaidx; int __pyx_module_is_main_pysam__libcfaidx = 0; /* Implementation of 'pysam.libcfaidx' */ static PyObject *__pyx_builtin_ValueError; -static PyObject *__pyx_builtin_NotImplementedError; static PyObject *__pyx_builtin_IOError; -static PyObject *__pyx_builtin_open; static PyObject *__pyx_builtin_zip; static PyObject *__pyx_builtin_KeyError; static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_StopIteration; static PyObject *__pyx_builtin_MemoryError; static const char __pyx_k_s[] = " %s"; -static const char __pyx_k__3[] = "-"; -static const char __pyx_k__4[] = "[^:]+:[/]*"; +static const char __pyx_k__2[] = "-"; static const char __pyx_k__5[] = ""; -static const char __pyx_k__6[] = "\t"; static const char __pyx_k_os[] = "os"; static const char __pyx_k_re[] = "re"; static const char __pyx_k_all[] = "__all__"; static const char __pyx_k_end[] = "end"; -static const char __pyx_k_fai[] = ".fai"; static const char __pyx_k_new[] = "__new__"; -static const char __pyx_k_sub[] = "sub"; static const char __pyx_k_sys[] = "sys"; static const char __pyx_k_zip[] = "zip"; -static const char __pyx_k_args[] = "args"; static const char __pyx_k_dict[] = "__dict__"; -static const char __pyx_k_exit[] = "__exit__"; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_name[] = "name"; -static const char __pyx_k_open[] = "open"; +static const char __pyx_k_open[] = "_open"; static const char __pyx_k_path[] = "path"; -static const char __pyx_k_send[] = "send"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_close[] = "close"; -static const char __pyx_k_enter[] = "__enter__"; static const char __pyx_k_fetch[] = "fetch"; +static const char __pyx_k_proxy[] = "proxy"; static const char __pyx_k_s_s_s[] = ">%s%s\n%s"; -static const char __pyx_k_split[] = "split"; static const char __pyx_k_start[] = "start"; -static const char __pyx_k_throw[] = "throw"; +static const char __pyx_k_append[] = "append"; static const char __pyx_k_exists[] = "exists"; static const char __pyx_k_format[] = "format"; static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_name_2[] = "__name__"; static const char __pyx_k_offset[] = "offset"; -static const char __pyx_k_open_2[] = "_open"; static const char __pyx_k_pickle[] = "pickle"; static const char __pyx_k_reduce[] = "__reduce__"; static const char __pyx_k_region[] = "region"; static const char __pyx_k_update[] = "update"; static const char __pyx_k_IOError[] = "IOError"; static const char __pyx_k_comment[] = "comment"; -static const char __pyx_k_genexpr[] = "genexpr"; static const char __pyx_k_is_open[] = "is_open"; static const char __pyx_k_persist[] = "persist"; static const char __pyx_k_quality[] = "quality"; static const char __pyx_k_s_s_s_s[] = "@%s%s\n%s\n+\n%s"; static const char __pyx_k_KeyError[] = "KeyError"; -static const char __pyx_k_basename[] = "basename"; static const char __pyx_k_exc_type[] = "exc_type"; static const char __pyx_k_filename[] = "filename"; static const char __pyx_k_getstate[] = "__getstate__"; @@ -2245,7 +2099,6 @@ static const char __pyx_k_setstate[] = "__setstate__"; static const char __pyx_k_FastaFile[] = "FastaFile"; static const char __pyx_k_Fastafile[] = "Fastafile"; static const char __pyx_k_FastqFile[] = "FastqFile"; -static const char __pyx_k_FastqRead[] = "FastqRead"; static const char __pyx_k_FastxFile[] = "FastxFile"; static const char __pyx_k_TypeError[] = "TypeError"; static const char __pyx_k_exc_value[] = "exc_value"; @@ -2258,6 +2111,7 @@ static const char __pyx_k_ValueError[] = "ValueError"; static const char __pyx_k_pyx_result[] = "__pyx_result"; static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; static const char __pyx_k_references[] = "references"; +static const char __pyx_k_FastxRecord[] = "FastxRecord"; static const char __pyx_k_MemoryError[] = "MemoryError"; static const char __pyx_k_PickleError[] = "PickleError"; static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; @@ -2271,64 +2125,62 @@ static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; static const char __pyx_k_file_s_not_found[] = "file `%s` not found"; static const char __pyx_k_get_quality_array[] = "get_quality_array"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; -static const char __pyx_k_NotImplementedError[] = "NotImplementedError"; -static const char __pyx_k_open_locals_genexpr[] = "_open..genexpr"; -static const char __pyx_k_could_not_open_file_s[] = "could not open file `%s`"; static const char __pyx_k_sequence_s_not_present[] = "sequence '%s' not present"; +static const char __pyx_k_filename_does_not_exist[] = "filename {} does not exist"; +static const char __pyx_k_pyx_unpickle_FastxRecord[] = "__pyx_unpickle_FastxRecord"; +static const char __pyx_k_error_when_opening_file_s[] = "error when opening file `%s`"; +static const char __pyx_k_filepath_index_compressed[] = "filepath_index_compressed"; static const char __pyx_k_calling_len_on_closed_file[] = "calling len() on closed file"; -static const char __pyx_k_could_not_locate_index_file[] = "could not locate index file {}"; static const char __pyx_k_no_sequence_region_supplied[] = "no sequence/region supplied."; static const char __pyx_k_I_O_operation_on_closed_file[] = "I/O operation on closed file"; -static const char __pyx_k_pyx_unpickle_PersistentFastqPr[] = "__pyx_unpickle_PersistentFastqProxy"; +static const char __pyx_k_FastxRecord_must_have_a_name_and[] = "FastxRecord must have a name and not None"; static const char __pyx_k_Incompatible_checksums_s_vs_0x43[] = "Incompatible checksums (%s vs 0x43fd151 = (comment, name, quality, sequence))"; +static const char __pyx_k_can_not_write_record_without_a_s[] = "can not write record without a sequence"; +static const char __pyx_k_can_not_write_record_without_nam[] = "can not write record without name"; static const char __pyx_k_failure_when_retrieving_sequence[] = "failure when retrieving sequence on '%s'"; static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__"; static const char __pyx_k_self__delegate_cannot_be_convert[] = "self._delegate cannot be converted to a Python object for pickling"; -static const char __pyx_k_setting_an_explicit_path_for_the[] = "setting an explicit path for the index is not implemented"; +static const char __pyx_k_sequence_and_quality_length_do_n[] = "sequence and quality length do not match: {} vs {}"; static PyObject *__pyx_n_s_FastaFile; static PyObject *__pyx_n_s_Fastafile; static PyObject *__pyx_n_s_FastqFile; static PyObject *__pyx_n_s_FastqProxy; -static PyObject *__pyx_n_s_FastqRead; static PyObject *__pyx_n_s_FastxFile; +static PyObject *__pyx_n_s_FastxRecord; +static PyObject *__pyx_kp_s_FastxRecord_must_have_a_name_and; static PyObject *__pyx_n_s_IOError; static PyObject *__pyx_kp_s_I_O_operation_on_closed_file; static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x43; static PyObject *__pyx_n_s_KeyError; static PyObject *__pyx_n_s_MemoryError; -static PyObject *__pyx_n_s_NotImplementedError; static PyObject *__pyx_n_s_PickleError; static PyObject *__pyx_n_s_StopIteration; static PyObject *__pyx_n_s_TypeError; static PyObject *__pyx_n_s_ValueError; -static PyObject *__pyx_kp_b__3; -static PyObject *__pyx_kp_s__4; +static PyObject *__pyx_kp_b__2; static PyObject *__pyx_kp_s__5; -static PyObject *__pyx_kp_s__6; static PyObject *__pyx_n_s_all; -static PyObject *__pyx_n_s_args; -static PyObject *__pyx_n_s_basename; +static PyObject *__pyx_n_s_append; static PyObject *__pyx_kp_s_calling_len_on_closed_file; +static PyObject *__pyx_kp_s_can_not_write_record_without_a_s; +static PyObject *__pyx_kp_s_can_not_write_record_without_nam; static PyObject *__pyx_n_s_cline_in_traceback; static PyObject *__pyx_n_s_close; static PyObject *__pyx_n_s_comment; -static PyObject *__pyx_kp_s_could_not_locate_index_file; -static PyObject *__pyx_kp_s_could_not_open_file_s; static PyObject *__pyx_n_s_dict; static PyObject *__pyx_n_s_end; -static PyObject *__pyx_n_s_enter; +static PyObject *__pyx_kp_s_error_when_opening_file_s; static PyObject *__pyx_n_s_exc_type; static PyObject *__pyx_n_s_exc_value; static PyObject *__pyx_n_s_exists; -static PyObject *__pyx_n_s_exit; -static PyObject *__pyx_kp_s_fai; static PyObject *__pyx_kp_s_failure_when_retrieving_sequence; static PyObject *__pyx_n_s_fetch; static PyObject *__pyx_kp_s_file_s_not_found; static PyObject *__pyx_n_s_filename; +static PyObject *__pyx_kp_s_filename_does_not_exist; static PyObject *__pyx_n_s_filepath_index; +static PyObject *__pyx_n_s_filepath_index_compressed; static PyObject *__pyx_n_s_format; -static PyObject *__pyx_n_s_genexpr; static PyObject *__pyx_n_s_get_quality_array; static PyObject *__pyx_n_s_getstate; static PyObject *__pyx_n_s_import; @@ -2341,19 +2193,18 @@ static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; static PyObject *__pyx_kp_s_no_sequence_region_supplied; static PyObject *__pyx_n_s_offset; static PyObject *__pyx_n_s_open; -static PyObject *__pyx_n_s_open_2; -static PyObject *__pyx_n_s_open_locals_genexpr; static PyObject *__pyx_n_s_os; static PyObject *__pyx_n_s_path; static PyObject *__pyx_n_s_persist; static PyObject *__pyx_n_s_pickle; +static PyObject *__pyx_n_s_proxy; static PyObject *__pyx_n_s_pysam_libcfaidx; static PyObject *__pyx_n_s_pyx_PickleError; static PyObject *__pyx_n_s_pyx_checksum; static PyObject *__pyx_n_s_pyx_result; static PyObject *__pyx_n_s_pyx_state; static PyObject *__pyx_n_s_pyx_type; -static PyObject *__pyx_n_s_pyx_unpickle_PersistentFastqPr; +static PyObject *__pyx_n_s_pyx_unpickle_FastxRecord; static PyObject *__pyx_n_s_pyx_vtable; static PyObject *__pyx_n_s_quality; static PyObject *__pyx_n_s_re; @@ -2367,28 +2218,22 @@ static PyObject *__pyx_kp_s_s; static PyObject *__pyx_kp_s_s_s_s; static PyObject *__pyx_kp_s_s_s_s_s; static PyObject *__pyx_kp_s_self__delegate_cannot_be_convert; -static PyObject *__pyx_n_s_send; static PyObject *__pyx_n_s_sequence; +static PyObject *__pyx_kp_s_sequence_and_quality_length_do_n; static PyObject *__pyx_kp_s_sequence_s_not_present; static PyObject *__pyx_n_s_setstate; static PyObject *__pyx_n_s_setstate_cython; -static PyObject *__pyx_kp_s_setting_an_explicit_path_for_the; -static PyObject *__pyx_n_s_split; static PyObject *__pyx_n_s_start; static PyObject *__pyx_kp_s_stringsource; -static PyObject *__pyx_n_s_sub; static PyObject *__pyx_n_s_sys; static PyObject *__pyx_n_s_test; -static PyObject *__pyx_n_s_throw; static PyObject *__pyx_n_s_traceback; static PyObject *__pyx_n_s_update; static PyObject *__pyx_n_s_zip; static int __pyx_pf_5pysam_9libcfaidx_9FastaFile___cinit__(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_2is_open(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_self); /* proto */ static Py_ssize_t __pyx_pf_5pysam_9libcfaidx_9FastaFile_4__len__(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_5_open_genexpr(PyObject *__pyx_self); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_5_open_3genexpr(PyObject *__pyx_self); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6_open(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_filepath_index); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6_open(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_filepath_index, PyObject *__pyx_v_filepath_index_compressed); /* proto */ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_8close(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_self); /* proto */ static void __pyx_pf_5pysam_9libcfaidx_9FastaFile_10__dealloc__(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_12__enter__(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_self); /* proto */ @@ -2413,23 +2258,28 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_2__str__(struct __pyx_o static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_4get_quality_array(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_self, int __pyx_v_offset); /* proto */ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy___init__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_FastqRead); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_2__str__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4get_quality_array(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, int __pyx_v_offset); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7comment___get__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_2__set__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_4__del__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality___get__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_2__set__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_4__del__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence___get__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_2__set__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_4__del__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name___get__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name_2__set__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name_4__del__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_6__reduce_cython__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8__setstate_cython__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord___init__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_comment, PyObject *__pyx_v_sequence, PyObject *__pyx_v_quality, struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_proxy); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_2__copy__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_4__deepcopy__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_6set_name(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_name); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_8set_comment(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_comment); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_10set_sequence(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_sequence, PyObject *__pyx_v_quality); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_12__str__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_14get_quality_array(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, int __pyx_v_offset); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_7comment___get__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto */ +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7comment_2__set__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7comment_4__del__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_7quality___get__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto */ +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7quality_2__set__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7quality_4__del__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_8sequence___get__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto */ +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_8sequence_2__set__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_8sequence_4__del__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_4name___get__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto */ +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_4name_2__set__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_4name_4__del__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_16__reduce_cython__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_18__setstate_cython__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_9libcfaidx_9FastxFile___cinit__(struct __pyx_obj_5pysam_9libcfaidx_FastxFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_2is_open(struct __pyx_obj_5pysam_9libcfaidx_FastxFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5pysam_9libcfaidx_FastxFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_persist); /* proto */ @@ -2447,21 +2297,20 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastqFile___reduce_cython__(CYTHON_ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastqFile_2__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libcfaidx_FastqFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_9libcfaidx_9Fastafile___reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libcfaidx_Fastafile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libcfaidx_9Fastafile_2__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libcfaidx_Fastafile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_FastxRecord(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags); /* proto */ static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ static PyObject *__pyx_tp_new_5pysam_9libcfaidx_FastaFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_9libcfaidx_FastqProxy(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_tp_new_5pysam_9libcfaidx_PersistentFastqProxy(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_5pysam_9libcfaidx_FastxRecord(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_9libcfaidx_FastxFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_9libcfaidx_FastqFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_9libcfaidx_Fastafile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_tp_new_5pysam_9libcfaidx___pyx_scope_struct___open(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_tp_new_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_tp_new_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_int_71291217; static PyObject *__pyx_tuple_; -static PyObject *__pyx_tuple__2; +static PyObject *__pyx_tuple__3; +static PyObject *__pyx_tuple__4; +static PyObject *__pyx_tuple__6; static PyObject *__pyx_tuple__7; static PyObject *__pyx_tuple__8; static PyObject *__pyx_tuple__9; @@ -2475,13 +2324,11 @@ static PyObject *__pyx_tuple__16; static PyObject *__pyx_tuple__17; static PyObject *__pyx_tuple__18; static PyObject *__pyx_tuple__19; -static PyObject *__pyx_tuple__20; static PyObject *__pyx_tuple__21; -static PyObject *__pyx_tuple__23; -static PyObject *__pyx_codeobj__22; +static PyObject *__pyx_codeobj__20; /* Late includes */ -/* "pysam/libcfaidx.pyx":71 +/* "pysam/libcfaidx.pyx":76 * * cdef class FastqProxy * cdef makeFastqProxy(kseq_t * src): # <<<<<<<<<<<<<< @@ -2496,21 +2343,21 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_makeFastqProxy(kseq_t *__pyx_v_src) { __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("makeFastqProxy", 0); - __Pyx_TraceCall("makeFastqProxy", __pyx_f[0], 71, 0, __PYX_ERR(0, 71, __pyx_L1_error)); + __Pyx_TraceCall("makeFastqProxy", __pyx_f[0], 76, 0, __PYX_ERR(0, 76, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":73 + /* "pysam/libcfaidx.pyx":78 * cdef makeFastqProxy(kseq_t * src): * '''enter src into AlignedRead.''' * cdef FastqProxy dest = FastqProxy.__new__(FastqProxy) # <<<<<<<<<<<<<< * dest._delegate = src * return dest */ - __pyx_t_1 = ((PyObject *)__pyx_tp_new_5pysam_9libcfaidx_FastqProxy(((PyTypeObject *)__pyx_ptype_5pysam_9libcfaidx_FastqProxy), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 73, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_tp_new_5pysam_9libcfaidx_FastqProxy(((PyTypeObject *)__pyx_ptype_5pysam_9libcfaidx_FastqProxy), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_v_dest = ((struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcfaidx.pyx":74 + /* "pysam/libcfaidx.pyx":79 * '''enter src into AlignedRead.''' * cdef FastqProxy dest = FastqProxy.__new__(FastqProxy) * dest._delegate = src # <<<<<<<<<<<<<< @@ -2519,7 +2366,7 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_makeFastqProxy(kseq_t *__pyx_v_src) { */ __pyx_v_dest->_delegate = __pyx_v_src; - /* "pysam/libcfaidx.pyx":75 + /* "pysam/libcfaidx.pyx":80 * cdef FastqProxy dest = FastqProxy.__new__(FastqProxy) * dest._delegate = src * return dest # <<<<<<<<<<<<<< @@ -2531,7 +2378,7 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_makeFastqProxy(kseq_t *__pyx_v_src) { __pyx_r = ((PyObject *)__pyx_v_dest); goto __pyx_L0; - /* "pysam/libcfaidx.pyx":71 + /* "pysam/libcfaidx.pyx":76 * * cdef class FastqProxy * cdef makeFastqProxy(kseq_t * src): # <<<<<<<<<<<<<< @@ -2552,7 +2399,7 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_makeFastqProxy(kseq_t *__pyx_v_src) { return __pyx_r; } -/* "pysam/libcfaidx.pyx":108 +/* "pysam/libcfaidx.pyx":117 * """ * * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -2593,9 +2440,9 @@ static int __pyx_pf_5pysam_9libcfaidx_9FastaFile___cinit__(struct __pyx_obj_5pys PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[0], 108, 0, __PYX_ERR(0, 108, __pyx_L1_error)); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 117, 0, __PYX_ERR(0, 117, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":109 + /* "pysam/libcfaidx.pyx":118 * * def __cinit__(self, *args, **kwargs): * self.fastafile = NULL # <<<<<<<<<<<<<< @@ -2604,7 +2451,7 @@ static int __pyx_pf_5pysam_9libcfaidx_9FastaFile___cinit__(struct __pyx_obj_5pys */ __pyx_v_self->fastafile = NULL; - /* "pysam/libcfaidx.pyx":110 + /* "pysam/libcfaidx.pyx":119 * def __cinit__(self, *args, **kwargs): * self.fastafile = NULL * self._filename = None # <<<<<<<<<<<<<< @@ -2617,7 +2464,7 @@ static int __pyx_pf_5pysam_9libcfaidx_9FastaFile___cinit__(struct __pyx_obj_5pys __Pyx_DECREF(__pyx_v_self->_filename); __pyx_v_self->_filename = Py_None; - /* "pysam/libcfaidx.pyx":111 + /* "pysam/libcfaidx.pyx":120 * self.fastafile = NULL * self._filename = None * self._references = None # <<<<<<<<<<<<<< @@ -2630,7 +2477,7 @@ static int __pyx_pf_5pysam_9libcfaidx_9FastaFile___cinit__(struct __pyx_obj_5pys __Pyx_DECREF(__pyx_v_self->_references); __pyx_v_self->_references = Py_None; - /* "pysam/libcfaidx.pyx":112 + /* "pysam/libcfaidx.pyx":121 * self._filename = None * self._references = None * self._lengths = None # <<<<<<<<<<<<<< @@ -2643,7 +2490,7 @@ static int __pyx_pf_5pysam_9libcfaidx_9FastaFile___cinit__(struct __pyx_obj_5pys __Pyx_DECREF(__pyx_v_self->_lengths); __pyx_v_self->_lengths = Py_None; - /* "pysam/libcfaidx.pyx":113 + /* "pysam/libcfaidx.pyx":122 * self._references = None * self._lengths = None * self.reference2length = None # <<<<<<<<<<<<<< @@ -2656,21 +2503,21 @@ static int __pyx_pf_5pysam_9libcfaidx_9FastaFile___cinit__(struct __pyx_obj_5pys __Pyx_DECREF(__pyx_v_self->reference2length); __pyx_v_self->reference2length = Py_None; - /* "pysam/libcfaidx.pyx":114 + /* "pysam/libcfaidx.pyx":123 * self._lengths = None * self.reference2length = None * self._open(*args, **kwargs) # <<<<<<<<<<<<<< * * def is_open(self): */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_v_args, __pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 114, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_v_args, __pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcfaidx.pyx":108 + /* "pysam/libcfaidx.pyx":117 * """ * * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -2692,7 +2539,7 @@ static int __pyx_pf_5pysam_9libcfaidx_9FastaFile___cinit__(struct __pyx_obj_5pys return __pyx_r; } -/* "pysam/libcfaidx.pyx":116 +/* "pysam/libcfaidx.pyx":125 * self._open(*args, **kwargs) * * def is_open(self): # <<<<<<<<<<<<<< @@ -2720,9 +2567,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_2is_open(struct __pyx_obj __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("is_open", 0); - __Pyx_TraceCall("is_open", __pyx_f[0], 116, 0, __PYX_ERR(0, 116, __pyx_L1_error)); + __Pyx_TraceCall("is_open", __pyx_f[0], 125, 0, __PYX_ERR(0, 125, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":118 + /* "pysam/libcfaidx.pyx":127 * def is_open(self): * '''return true if samfile has been opened.''' * return self.fastafile != NULL # <<<<<<<<<<<<<< @@ -2730,13 +2577,13 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_2is_open(struct __pyx_obj * def __len__(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->fastafile != NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 118, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->fastafile != NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":116 + /* "pysam/libcfaidx.pyx":125 * self._open(*args, **kwargs) * * def is_open(self): # <<<<<<<<<<<<<< @@ -2756,7 +2603,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_2is_open(struct __pyx_obj return __pyx_r; } -/* "pysam/libcfaidx.pyx":120 +/* "pysam/libcfaidx.pyx":129 * return self.fastafile != NULL * * def __len__(self): # <<<<<<<<<<<<<< @@ -2784,9 +2631,9 @@ static Py_ssize_t __pyx_pf_5pysam_9libcfaidx_9FastaFile_4__len__(struct __pyx_ob int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__len__", 0); - __Pyx_TraceCall("__len__", __pyx_f[0], 120, 0, __PYX_ERR(0, 120, __pyx_L1_error)); + __Pyx_TraceCall("__len__", __pyx_f[0], 129, 0, __PYX_ERR(0, 129, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":121 + /* "pysam/libcfaidx.pyx":130 * * def __len__(self): * if self.fastafile == NULL: # <<<<<<<<<<<<<< @@ -2796,20 +2643,20 @@ static Py_ssize_t __pyx_pf_5pysam_9libcfaidx_9FastaFile_4__len__(struct __pyx_ob __pyx_t_1 = ((__pyx_v_self->fastafile == NULL) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libcfaidx.pyx":122 + /* "pysam/libcfaidx.pyx":131 * def __len__(self): * if self.fastafile == NULL: * raise ValueError("calling len() on closed file") # <<<<<<<<<<<<<< * * return faidx_nseq(self.fastafile) */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 122, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 131, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 122, __pyx_L1_error) + __PYX_ERR(0, 131, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":121 + /* "pysam/libcfaidx.pyx":130 * * def __len__(self): * if self.fastafile == NULL: # <<<<<<<<<<<<<< @@ -2818,17 +2665,17 @@ static Py_ssize_t __pyx_pf_5pysam_9libcfaidx_9FastaFile_4__len__(struct __pyx_ob */ } - /* "pysam/libcfaidx.pyx":124 + /* "pysam/libcfaidx.pyx":133 * raise ValueError("calling len() on closed file") * * return faidx_nseq(self.fastafile) # <<<<<<<<<<<<<< * - * def _open(self, filename, filepath_index=None): + * def _open(self, filename, filepath_index=None, filepath_index_compressed=None): */ __pyx_r = faidx_nseq(__pyx_v_self->fastafile); goto __pyx_L0; - /* "pysam/libcfaidx.pyx":120 + /* "pysam/libcfaidx.pyx":129 * return self.fastafile != NULL * * def __len__(self): # <<<<<<<<<<<<<< @@ -2847,31 +2694,35 @@ static Py_ssize_t __pyx_pf_5pysam_9libcfaidx_9FastaFile_4__len__(struct __pyx_ob return __pyx_r; } -/* "pysam/libcfaidx.pyx":126 +/* "pysam/libcfaidx.pyx":135 * return faidx_nseq(self.fastafile) * - * def _open(self, filename, filepath_index=None): # <<<<<<<<<<<<<< + * def _open(self, filename, filepath_index=None, filepath_index_compressed=None): # <<<<<<<<<<<<<< * '''open an indexed fasta file. * */ /* Python wrapper */ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libcfaidx_9FastaFile_6_open[] = "FastaFile._open(self, filename, filepath_index=None)\nopen an indexed fasta file.\n\n This method expects an indexed fasta file.\n "; +static char __pyx_doc_5pysam_9libcfaidx_9FastaFile_6_open[] = "FastaFile._open(self, filename, filepath_index=None, filepath_index_compressed=None)\nopen an indexed fasta file.\n\n This method expects an indexed fasta file.\n "; static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_filename = 0; PyObject *__pyx_v_filepath_index = 0; + PyObject *__pyx_v_filepath_index_compressed = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("_open (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,&__pyx_n_s_filepath_index,0}; - PyObject* values[2] = {0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,&__pyx_n_s_filepath_index,&__pyx_n_s_filepath_index_compressed,0}; + PyObject* values[3] = {0,0,0}; values[1] = ((PyObject *)Py_None); + values[2] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -2890,12 +2741,20 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_7_open(PyObject *__pyx_v_ PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filepath_index); if (value) { values[1] = value; kw_args--; } } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filepath_index_compressed); + if (value) { values[2] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) __PYX_ERR(0, 126, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) __PYX_ERR(0, 135, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -2905,357 +2764,89 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_7_open(PyObject *__pyx_v_ } __pyx_v_filename = values[0]; __pyx_v_filepath_index = values[1]; + __pyx_v_filepath_index_compressed = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 126, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 135, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcfaidx.FastaFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libcfaidx_9FastaFile_6_open(((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)__pyx_v_self), __pyx_v_filename, __pyx_v_filepath_index); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_gb_5pysam_9libcfaidx_9FastaFile_5_open_2generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ - -/* "pysam/libcfaidx.pyx":169 - * with open(filepath_index) as inf: - * data = [x.split("\t") for x in inf] - * self._references = tuple(x[0] for x in data) # <<<<<<<<<<<<<< - * self._lengths = tuple(int(x[1]) for x in data) - * self.reference2length = dict(zip(self._references, self._lengths)) - */ - -static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_5_open_genexpr(PyObject *__pyx_self) { - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("genexpr", 0); - __pyx_cur_scope = (struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr *)__pyx_tp_new_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr(__pyx_ptype_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 169, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *) __pyx_self; - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); - { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_9libcfaidx_9FastaFile_5_open_2generator, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_open_locals_genexpr, __pyx_n_s_pysam_libcfaidx); if (unlikely(!gen)) __PYX_ERR(0, 169, __pyx_L1_error) - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __pyx_r = __pyx_pf_5pysam_9libcfaidx_9FastaFile_6_open(((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)__pyx_v_self), __pyx_v_filename, __pyx_v_filepath_index, __pyx_v_filepath_index_compressed); /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcfaidx.FastaFile._open.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5pysam_9libcfaidx_9FastaFile_5_open_2generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr *)__pyx_generator->closure); +static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6_open(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_filepath_index, PyObject *__pyx_v_filepath_index_compressed) { + char *__pyx_v_cfilename; + char *__pyx_v_cindexname; + char *__pyx_v_cindexname_compressed; + CYTHON_UNUSED PyObject *__pyx_v_bindex_filename = NULL; + CYTHON_UNUSED PyObject *__pyx_v_bindex_filename_compressed = NULL; + int __pyx_v_nreferences; + int __pyx_v_x; + char const *__pyx_v_s; + PyObject *__pyx_v_ss = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("genexpr", 0); - __Pyx_TraceCall("genexpr", __pyx_f[0], 169, 0, __PYX_ERR(0, 169, __pyx_L1_error)); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return NULL; - } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 169, __pyx_L1_error) - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data)) { __Pyx_RaiseClosureNameError("data"); __PYX_ERR(0, 169, __pyx_L1_error) } - if (unlikely(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); - __PYX_ERR(0, 169, __pyx_L1_error) - } - __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_data; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - for (;;) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 169, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 169, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_x, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 169, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 169, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + char *__pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + int __pyx_t_9; + int __pyx_t_10; + __Pyx_RefNannySetupContext("_open", 0); + __Pyx_TraceCall("_open", __pyx_f[0], 135, 0, __PYX_ERR(0, 135, __pyx_L1_error)); - /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_gb_5pysam_9libcfaidx_9FastaFile_5_open_5generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ + /* "pysam/libcfaidx.pyx":142 + * + * # close a previously opened file + * if self.fastafile != NULL: # <<<<<<<<<<<<<< + * self.close() + * + */ + __pyx_t_1 = ((__pyx_v_self->fastafile != NULL) != 0); + if (__pyx_t_1) { -/* "pysam/libcfaidx.pyx":170 - * data = [x.split("\t") for x in inf] - * self._references = tuple(x[0] for x in data) - * self._lengths = tuple(int(x[1]) for x in data) # <<<<<<<<<<<<<< - * self.reference2length = dict(zip(self._references, self._lengths)) + /* "pysam/libcfaidx.pyx":143 + * # close a previously opened file + * if self.fastafile != NULL: + * self.close() # <<<<<<<<<<<<<< * + * self._filename = encode_filename(filename) */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 143, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; -static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_5_open_3genexpr(PyObject *__pyx_self) { - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("genexpr", 0); - __pyx_cur_scope = (struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr *)__pyx_tp_new_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr(__pyx_ptype_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 170, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *) __pyx_self; - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); - { - __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_9libcfaidx_9FastaFile_5_open_5generator1, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_open_locals_genexpr, __pyx_n_s_pysam_libcfaidx); if (unlikely(!gen)) __PYX_ERR(0, 170, __pyx_L1_error) - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } - - /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcfaidx.FastaFile._open.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_gb_5pysam_9libcfaidx_9FastaFile_5_open_5generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("genexpr", 0); - __Pyx_TraceCall("genexpr", __pyx_f[0], 170, 0, __PYX_ERR(0, 170, __pyx_L1_error)); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return NULL; - } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 170, __pyx_L1_error) - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data)) { __Pyx_RaiseClosureNameError("data"); __PYX_ERR(0, 170, __pyx_L1_error) } - if (unlikely(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_data == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); - __PYX_ERR(0, 170, __pyx_L1_error) - } - __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_data; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - for (;;) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 170, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 170, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_x, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 170, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 170, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; - if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 170, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - - /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); __pyx_r = 0; - __Pyx_Coroutine_ResetAndClearException(__pyx_generator); - __pyx_generator->resume_label = -1; - __Pyx_Coroutine_clear((PyObject*)__pyx_generator); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libcfaidx.pyx":126 - * return faidx_nseq(self.fastafile) - * - * def _open(self, filename, filepath_index=None): # <<<<<<<<<<<<<< - * '''open an indexed fasta file. - * - */ - -static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6_open(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_filepath_index) { - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *__pyx_cur_scope; - char *__pyx_v_cfilename; - PyObject *__pyx_v_inf = NULL; - PyObject *__pyx_v_x = NULL; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - char *__pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - int __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - int __pyx_t_10; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - PyObject *__pyx_t_15 = NULL; - Py_ssize_t __pyx_t_16; - PyObject *(*__pyx_t_17)(PyObject *); - PyObject *__pyx_t_18 = NULL; - __Pyx_RefNannySetupContext("_open", 0); - __pyx_cur_scope = (struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *)__pyx_tp_new_5pysam_9libcfaidx___pyx_scope_struct___open(__pyx_ptype_5pysam_9libcfaidx___pyx_scope_struct___open, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __pyx_cur_scope = ((struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *)Py_None); - __Pyx_INCREF(Py_None); - __PYX_ERR(0, 126, __pyx_L1_error) - } else { - __Pyx_GOTREF(__pyx_cur_scope); - } - __Pyx_TraceCall("_open", __pyx_f[0], 126, 0, __PYX_ERR(0, 126, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_filepath_index); - - /* "pysam/libcfaidx.pyx":133 - * - * # close a previously opened file - * if self.fastafile != NULL: # <<<<<<<<<<<<<< - * self.close() - * - */ - __pyx_t_1 = ((__pyx_v_self->fastafile != NULL) != 0); - if (__pyx_t_1) { - - /* "pysam/libcfaidx.pyx":134 - * # close a previously opened file - * if self.fastafile != NULL: - * self.close() # <<<<<<<<<<<<<< - * - * self._filename = encode_filename(filename) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 134, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pysam/libcfaidx.pyx":133 + /* "pysam/libcfaidx.pyx":142 * * # close a previously opened file * if self.fastafile != NULL: # <<<<<<<<<<<<<< @@ -3264,14 +2855,14 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6_open(struct __pyx_obj_5 */ } - /* "pysam/libcfaidx.pyx":136 + /* "pysam/libcfaidx.pyx":145 * self.close() * * self._filename = encode_filename(filename) # <<<<<<<<<<<<<< * cdef char *cfilename = self._filename - * self.is_remote = hisremote(cfilename) + * cdef char *cindexname = NULL */ - __pyx_t_2 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 145, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_self->_filename); @@ -3279,99 +2870,84 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6_open(struct __pyx_obj_5 __pyx_v_self->_filename = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libcfaidx.pyx":137 + /* "pysam/libcfaidx.pyx":146 * * self._filename = encode_filename(filename) * cdef char *cfilename = self._filename # <<<<<<<<<<<<<< - * self.is_remote = hisremote(cfilename) - * + * cdef char *cindexname = NULL + * cdef char *cindexname_compressed = NULL */ - __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_self->_filename); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 137, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_self->_filename); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 146, __pyx_L1_error) __pyx_v_cfilename = __pyx_t_5; - /* "pysam/libcfaidx.pyx":138 + /* "pysam/libcfaidx.pyx":147 * self._filename = encode_filename(filename) * cdef char *cfilename = self._filename - * self.is_remote = hisremote(cfilename) # <<<<<<<<<<<<<< - * - * if filepath_index is not None: - */ - __pyx_v_self->is_remote = hisremote(__pyx_v_cfilename); - - /* "pysam/libcfaidx.pyx":140 + * cdef char *cindexname = NULL # <<<<<<<<<<<<<< + * cdef char *cindexname_compressed = NULL * self.is_remote = hisremote(cfilename) - * - * if filepath_index is not None: # <<<<<<<<<<<<<< - * raise NotImplementedError( - * "setting an explicit path for the index " */ - __pyx_t_1 = (__pyx_v_filepath_index != Py_None); - __pyx_t_6 = (__pyx_t_1 != 0); - if (unlikely(__pyx_t_6)) { + __pyx_v_cindexname = NULL; - /* "pysam/libcfaidx.pyx":141 + /* "pysam/libcfaidx.pyx":148 + * cdef char *cfilename = self._filename + * cdef char *cindexname = NULL + * cdef char *cindexname_compressed = NULL # <<<<<<<<<<<<<< + * self.is_remote = hisremote(cfilename) * - * if filepath_index is not None: - * raise NotImplementedError( # <<<<<<<<<<<<<< - * "setting an explicit path for the index " - * "is not implemented") */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 141, __pyx_L1_error) + __pyx_v_cindexname_compressed = NULL; - /* "pysam/libcfaidx.pyx":140 - * self.is_remote = hisremote(cfilename) + /* "pysam/libcfaidx.pyx":149 + * cdef char *cindexname = NULL + * cdef char *cindexname_compressed = NULL + * self.is_remote = hisremote(cfilename) # <<<<<<<<<<<<<< * - * if filepath_index is not None: # <<<<<<<<<<<<<< - * raise NotImplementedError( - * "setting an explicit path for the index " + * # open file for reading */ - } + __pyx_v_self->is_remote = hisremote(__pyx_v_cfilename); - /* "pysam/libcfaidx.pyx":146 + /* "pysam/libcfaidx.pyx":152 * * # open file for reading * if (self._filename != b"-" # <<<<<<<<<<<<<< * and not self.is_remote * and not os.path.exists(filename)): */ - __pyx_t_1 = (__Pyx_PyBytes_Equals(__pyx_v_self->_filename, __pyx_kp_b__3, Py_NE)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 146, __pyx_L1_error) - if (__pyx_t_1) { + __pyx_t_6 = (__Pyx_PyBytes_Equals(__pyx_v_self->_filename, __pyx_kp_b__2, Py_NE)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 152, __pyx_L1_error) + if (__pyx_t_6) { } else { - __pyx_t_6 = __pyx_t_1; - goto __pyx_L6_bool_binop_done; + __pyx_t_1 = __pyx_t_6; + goto __pyx_L5_bool_binop_done; } - /* "pysam/libcfaidx.pyx":147 + /* "pysam/libcfaidx.pyx":153 * # open file for reading * if (self._filename != b"-" * and not self.is_remote # <<<<<<<<<<<<<< * and not os.path.exists(filename)): * raise IOError("file `%s` not found" % filename) */ - __pyx_t_1 = ((!(__pyx_v_self->is_remote != 0)) != 0); - if (__pyx_t_1) { + __pyx_t_6 = ((!(__pyx_v_self->is_remote != 0)) != 0); + if (__pyx_t_6) { } else { - __pyx_t_6 = __pyx_t_1; - goto __pyx_L6_bool_binop_done; + __pyx_t_1 = __pyx_t_6; + goto __pyx_L5_bool_binop_done; } - /* "pysam/libcfaidx.pyx":148 + /* "pysam/libcfaidx.pyx":154 * if (self._filename != b"-" * and not self.is_remote * and not os.path.exists(filename)): # <<<<<<<<<<<<<< * raise IOError("file `%s` not found" % filename) * */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exists); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exists); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = NULL; @@ -3385,13 +2961,13 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6_open(struct __pyx_obj_5 } } if (!__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filename}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_2); } else @@ -3399,56 +2975,56 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6_open(struct __pyx_obj_5 #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filename}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_filename); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = ((!__pyx_t_1) != 0); - __pyx_t_6 = __pyx_t_8; - __pyx_L6_bool_binop_done:; + __pyx_t_8 = ((!__pyx_t_6) != 0); + __pyx_t_1 = __pyx_t_8; + __pyx_L5_bool_binop_done:; - /* "pysam/libcfaidx.pyx":146 + /* "pysam/libcfaidx.pyx":152 * * # open file for reading * if (self._filename != b"-" # <<<<<<<<<<<<<< * and not self.is_remote * and not os.path.exists(filename)): */ - if (unlikely(__pyx_t_6)) { + if (unlikely(__pyx_t_1)) { - /* "pysam/libcfaidx.pyx":149 + /* "pysam/libcfaidx.pyx":155 * and not self.is_remote * and not os.path.exists(filename)): * raise IOError("file `%s` not found" % filename) # <<<<<<<<<<<<<< * - * with nogil: + * # 3 modes to open: */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_file_s_not_found, __pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 149, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_file_s_not_found, __pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 149, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 149, __pyx_L1_error) + __PYX_ERR(0, 155, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":146 + /* "pysam/libcfaidx.pyx":152 * * # open file for reading * if (self._filename != b"-" # <<<<<<<<<<<<<< @@ -3457,673 +3033,645 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6_open(struct __pyx_obj_5 */ } - /* "pysam/libcfaidx.pyx":151 - * raise IOError("file `%s` not found" % filename) - * - * with nogil: # <<<<<<<<<<<<<< - * self.fastafile = fai_load(cfilename) - * + /* "pysam/libcfaidx.pyx":161 + * # uncompressed fa: fai_load3 with filename and index_fai + * # uncompressed fa: fai_load with default index name + * if filepath_index: # <<<<<<<<<<<<<< + * # when opening, set flags to 0 - do not automatically + * # build index if it does not exist. */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_filepath_index); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 161, __pyx_L1_error) + if (__pyx_t_1) { - /* "pysam/libcfaidx.pyx":152 - * - * with nogil: - * self.fastafile = fai_load(cfilename) # <<<<<<<<<<<<<< + /* "pysam/libcfaidx.pyx":165 + * # build index if it does not exist. * - * if self.fastafile == NULL: + * if not os.path.exists(filepath_index): # <<<<<<<<<<<<<< + * raise IOError("filename {} does not exist".format(filepath_index)) + * cindexname = bindex_filename = encode_filename(filepath_index) */ - __pyx_v_self->fastafile = fai_load(__pyx_v_cfilename); + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_exists); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_7) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filepath_index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_filepath_index}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_filepath_index}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7); __pyx_t_7 = NULL; + __Pyx_INCREF(__pyx_v_filepath_index); + __Pyx_GIVEREF(__pyx_v_filepath_index); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_filepath_index); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = ((!__pyx_t_1) != 0); + if (unlikely(__pyx_t_8)) { - /* "pysam/libcfaidx.pyx":151 - * raise IOError("file `%s` not found" % filename) + /* "pysam/libcfaidx.pyx":166 * - * with nogil: # <<<<<<<<<<<<<< - * self.fastafile = fai_load(cfilename) + * if not os.path.exists(filepath_index): + * raise IOError("filename {} does not exist".format(filepath_index)) # <<<<<<<<<<<<<< + * cindexname = bindex_filename = encode_filename(filepath_index) * */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L11; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_filename_does_not_exist, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 166, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); } - __pyx_L11:; } - } + if (!__pyx_t_4) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filepath_index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 166, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filepath_index}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 166, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filepath_index}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 166, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 166, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_INCREF(__pyx_v_filepath_index); + __Pyx_GIVEREF(__pyx_v_filepath_index); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_filepath_index); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 166, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 166, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 166, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":154 - * self.fastafile = fai_load(cfilename) - * - * if self.fastafile == NULL: # <<<<<<<<<<<<<< - * raise IOError("could not open file `%s`" % filename) + /* "pysam/libcfaidx.pyx":165 + * # build index if it does not exist. * + * if not os.path.exists(filepath_index): # <<<<<<<<<<<<<< + * raise IOError("filename {} does not exist".format(filepath_index)) + * cindexname = bindex_filename = encode_filename(filepath_index) */ - __pyx_t_6 = ((__pyx_v_self->fastafile == NULL) != 0); - if (unlikely(__pyx_t_6)) { + } - /* "pysam/libcfaidx.pyx":155 - * - * if self.fastafile == NULL: - * raise IOError("could not open file `%s`" % filename) # <<<<<<<<<<<<<< + /* "pysam/libcfaidx.pyx":167 + * if not os.path.exists(filepath_index): + * raise IOError("filename {} does not exist".format(filepath_index)) + * cindexname = bindex_filename = encode_filename(filepath_index) # <<<<<<<<<<<<<< * - * if self.is_remote: + * if filepath_index_compressed: */ - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_file_s, __pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filepath_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 167, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); + if (unlikely(__pyx_t_2 == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 167, __pyx_L1_error) + } + __pyx_t_5 = __Pyx_PyBytes_AsWritableString(__pyx_t_2); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_v_cindexname = __pyx_t_5; + __Pyx_INCREF(__pyx_t_2); + __pyx_v_bindex_filename = ((PyObject*)__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 155, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":154 - * self.fastafile = fai_load(cfilename) - * - * if self.fastafile == NULL: # <<<<<<<<<<<<<< - * raise IOError("could not open file `%s`" % filename) + /* "pysam/libcfaidx.pyx":169 + * cindexname = bindex_filename = encode_filename(filepath_index) * + * if filepath_index_compressed: # <<<<<<<<<<<<<< + * if not os.path.exists(filepath_index_compressed): + * raise IOError("filename {} does not exist".format(filepath_index_compressed)) */ - } + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_filepath_index_compressed); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 169, __pyx_L1_error) + if (__pyx_t_8) { - /* "pysam/libcfaidx.pyx":157 - * raise IOError("could not open file `%s`" % filename) + /* "pysam/libcfaidx.pyx":170 * - * if self.is_remote: # <<<<<<<<<<<<<< - * filepath_index = os.path.basename( - * re.sub("[^:]+:[/]*", "", filename)) + ".fai" + * if filepath_index_compressed: + * if not os.path.exists(filepath_index_compressed): # <<<<<<<<<<<<<< + * raise IOError("filename {} does not exist".format(filepath_index_compressed)) + * cindexname_compressed = bindex_filename_compressed = encode_filename(filepath_index_compressed) */ - __pyx_t_6 = (__pyx_v_self->is_remote != 0); - if (__pyx_t_6) { + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_exists); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_7) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_filepath_index_compressed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_filepath_index_compressed}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_filepath_index_compressed}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7); __pyx_t_7 = NULL; + __Pyx_INCREF(__pyx_v_filepath_index_compressed); + __Pyx_GIVEREF(__pyx_v_filepath_index_compressed); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_filepath_index_compressed); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = ((!__pyx_t_8) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcfaidx.pyx":158 - * - * if self.is_remote: - * filepath_index = os.path.basename( # <<<<<<<<<<<<<< - * re.sub("[^:]+:[/]*", "", filename)) + ".fai" - * elif filepath_index is None: + /* "pysam/libcfaidx.pyx":171 + * if filepath_index_compressed: + * if not os.path.exists(filepath_index_compressed): + * raise IOError("filename {} does not exist".format(filepath_index_compressed)) # <<<<<<<<<<<<<< + * cindexname_compressed = bindex_filename_compressed = encode_filename(filepath_index_compressed) + * with nogil: */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_basename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_filename_does_not_exist, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_filepath_index_compressed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filepath_index_compressed}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 171, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filepath_index_compressed}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 171, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_INCREF(__pyx_v_filepath_index_compressed); + __Pyx_GIVEREF(__pyx_v_filepath_index_compressed); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_filepath_index_compressed); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 171, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":159 - * if self.is_remote: - * filepath_index = os.path.basename( - * re.sub("[^:]+:[/]*", "", filename)) + ".fai" # <<<<<<<<<<<<<< - * elif filepath_index is None: - * filepath_index = filename + ".fai" + /* "pysam/libcfaidx.pyx":170 + * + * if filepath_index_compressed: + * if not os.path.exists(filepath_index_compressed): # <<<<<<<<<<<<<< + * raise IOError("filename {} does not exist".format(filepath_index_compressed)) + * cindexname_compressed = bindex_filename_compressed = encode_filename(filepath_index_compressed) */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_sub); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - __pyx_t_10 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_9, function); - __pyx_t_10 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_kp_s__4, __pyx_kp_s__5, __pyx_v_filename}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { - PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_kp_s__4, __pyx_kp_s__5, __pyx_v_filename}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - { - __pyx_t_11 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); __pyx_t_4 = NULL; } - __Pyx_INCREF(__pyx_kp_s__4); - __Pyx_GIVEREF(__pyx_kp_s__4); - PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_kp_s__4); - __Pyx_INCREF(__pyx_kp_s__5); - __Pyx_GIVEREF(__pyx_kp_s__5); - PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_kp_s__5); - __Pyx_INCREF(__pyx_v_filename); - __Pyx_GIVEREF(__pyx_v_filename); - PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_10, __pyx_v_filename); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); + + /* "pysam/libcfaidx.pyx":172 + * if not os.path.exists(filepath_index_compressed): + * raise IOError("filename {} does not exist".format(filepath_index_compressed)) + * cindexname_compressed = bindex_filename_compressed = encode_filename(filepath_index_compressed) # <<<<<<<<<<<<<< + * with nogil: + * self.fastafile = fai_load3(cfilename, cindexname, cindexname_compressed, 0) + */ + __pyx_t_3 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filepath_index_compressed); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(__pyx_t_3 == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 172, __pyx_L1_error) } - } - if (!__pyx_t_9) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else - #endif + __pyx_t_5 = __Pyx_PyBytes_AsWritableString(__pyx_t_3); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 172, __pyx_L1_error) + __pyx_v_cindexname_compressed = __pyx_t_5; + __Pyx_INCREF(__pyx_t_3); + __pyx_v_bindex_filename_compressed = ((PyObject*)__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libcfaidx.pyx":173 + * raise IOError("filename {} does not exist".format(filepath_index_compressed)) + * cindexname_compressed = bindex_filename_compressed = encode_filename(filepath_index_compressed) + * with nogil: # <<<<<<<<<<<<<< + * self.fastafile = fai_load3(cfilename, cindexname, cindexname_compressed, 0) + * else: + */ { - __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL; - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 158, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libcfaidx.pyx":174 + * cindexname_compressed = bindex_filename_compressed = encode_filename(filepath_index_compressed) + * with nogil: + * self.fastafile = fai_load3(cfilename, cindexname, cindexname_compressed, 0) # <<<<<<<<<<<<<< + * else: + * with nogil: + */ + __pyx_v_self->fastafile = fai_load3(__pyx_v_cfilename, __pyx_v_cindexname, __pyx_v_cindexname_compressed, 0); + } + + /* "pysam/libcfaidx.pyx":173 + * raise IOError("filename {} does not exist".format(filepath_index_compressed)) + * cindexname_compressed = bindex_filename_compressed = encode_filename(filepath_index_compressed) + * with nogil: # <<<<<<<<<<<<<< + * self.fastafile = fai_load3(cfilename, cindexname, cindexname_compressed, 0) + * else: + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L14; + } + __pyx_L14:; + } } - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Add(__pyx_t_2, __pyx_kp_s_fai); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 159, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_filepath_index, __pyx_t_3); - __pyx_t_3 = 0; - /* "pysam/libcfaidx.pyx":157 - * raise IOError("could not open file `%s`" % filename) + /* "pysam/libcfaidx.pyx":169 + * cindexname = bindex_filename = encode_filename(filepath_index) * - * if self.is_remote: # <<<<<<<<<<<<<< - * filepath_index = os.path.basename( - * re.sub("[^:]+:[/]*", "", filename)) + ".fai" + * if filepath_index_compressed: # <<<<<<<<<<<<<< + * if not os.path.exists(filepath_index_compressed): + * raise IOError("filename {} does not exist".format(filepath_index_compressed)) */ - goto __pyx_L13; - } + goto __pyx_L10; + } - /* "pysam/libcfaidx.pyx":160 - * filepath_index = os.path.basename( - * re.sub("[^:]+:[/]*", "", filename)) + ".fai" - * elif filepath_index is None: # <<<<<<<<<<<<<< - * filepath_index = filename + ".fai" - * + /* "pysam/libcfaidx.pyx":176 + * self.fastafile = fai_load3(cfilename, cindexname, cindexname_compressed, 0) + * else: + * with nogil: # <<<<<<<<<<<<<< + * self.fastafile = fai_load3(cfilename, cindexname, NULL, 0) + * else: */ - __pyx_t_6 = (__pyx_v_filepath_index == Py_None); - __pyx_t_8 = (__pyx_t_6 != 0); - if (__pyx_t_8) { + /*else*/ { + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libcfaidx.pyx":161 - * re.sub("[^:]+:[/]*", "", filename)) + ".fai" - * elif filepath_index is None: - * filepath_index = filename + ".fai" # <<<<<<<<<<<<<< - * - * if not os.path.exists(filepath_index): + /* "pysam/libcfaidx.pyx":177 + * else: + * with nogil: + * self.fastafile = fai_load3(cfilename, cindexname, NULL, 0) # <<<<<<<<<<<<<< + * else: + * with nogil: */ - __pyx_t_3 = PyNumber_Add(__pyx_v_filename, __pyx_kp_s_fai); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF_SET(__pyx_v_filepath_index, __pyx_t_3); - __pyx_t_3 = 0; + __pyx_v_self->fastafile = fai_load3(__pyx_v_cfilename, __pyx_v_cindexname, NULL, 0); + } - /* "pysam/libcfaidx.pyx":160 - * filepath_index = os.path.basename( - * re.sub("[^:]+:[/]*", "", filename)) + ".fai" - * elif filepath_index is None: # <<<<<<<<<<<<<< - * filepath_index = filename + ".fai" - * + /* "pysam/libcfaidx.pyx":176 + * self.fastafile = fai_load3(cfilename, cindexname, cindexname_compressed, 0) + * else: + * with nogil: # <<<<<<<<<<<<<< + * self.fastafile = fai_load3(cfilename, cindexname, NULL, 0) + * else: + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L17; + } + __pyx_L17:; + } + } + } + __pyx_L10:; + + /* "pysam/libcfaidx.pyx":161 + * # uncompressed fa: fai_load3 with filename and index_fai + * # uncompressed fa: fai_load with default index name + * if filepath_index: # <<<<<<<<<<<<<< + * # when opening, set flags to 0 - do not automatically + * # build index if it does not exist. */ + goto __pyx_L8; } - __pyx_L13:; - /* "pysam/libcfaidx.pyx":163 - * filepath_index = filename + ".fai" + /* "pysam/libcfaidx.pyx":179 + * self.fastafile = fai_load3(cfilename, cindexname, NULL, 0) + * else: + * with nogil: # <<<<<<<<<<<<<< + * self.fastafile = fai_load(cfilename) * - * if not os.path.exists(filepath_index): # <<<<<<<<<<<<<< - * raise ValueError("could not locate index file {}".format( - * filepath_index)) */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 163, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_exists); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (!__pyx_t_11) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filepath_index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 163, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_filepath_index}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 163, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_filepath_index}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 163, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif + /*else*/ { { - __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 163, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_11); __pyx_t_11 = NULL; - __Pyx_INCREF(__pyx_v_filepath_index); - __Pyx_GIVEREF(__pyx_v_filepath_index); - PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_filepath_index); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 163, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 163, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = ((!__pyx_t_8) != 0); - if (unlikely(__pyx_t_6)) { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libcfaidx.pyx":164 - * - * if not os.path.exists(filepath_index): - * raise ValueError("could not locate index file {}".format( # <<<<<<<<<<<<<< - * filepath_index)) + /* "pysam/libcfaidx.pyx":180 + * else: + * with nogil: + * self.fastafile = fai_load(cfilename) # <<<<<<<<<<<<<< * + * if self.fastafile == NULL: */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_locate_index_file, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 164, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_v_self->fastafile = fai_load(__pyx_v_cfilename); + } - /* "pysam/libcfaidx.pyx":165 - * if not os.path.exists(filepath_index): - * raise ValueError("could not locate index file {}".format( - * filepath_index)) # <<<<<<<<<<<<<< + /* "pysam/libcfaidx.pyx":179 + * self.fastafile = fai_load3(cfilename, cindexname, NULL, 0) + * else: + * with nogil: # <<<<<<<<<<<<<< + * self.fastafile = fai_load(cfilename) * - * with open(filepath_index) as inf: */ - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (!__pyx_t_7) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filepath_index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 164, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_filepath_index}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 164, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_filepath_index}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 164, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 164, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_7); __pyx_t_7 = NULL; - __Pyx_INCREF(__pyx_v_filepath_index); - __Pyx_GIVEREF(__pyx_v_filepath_index); - PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_filepath_index); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 164, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L20; + } + __pyx_L20:; + } } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_L8:; + + /* "pysam/libcfaidx.pyx":182 + * self.fastafile = fai_load(cfilename) + * + * if self.fastafile == NULL: # <<<<<<<<<<<<<< + * raise IOError("error when opening file `%s`" % filename) + * + */ + __pyx_t_1 = ((__pyx_v_self->fastafile == NULL) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libcfaidx.pyx":164 + /* "pysam/libcfaidx.pyx":183 * - * if not os.path.exists(filepath_index): - * raise ValueError("could not locate index file {}".format( # <<<<<<<<<<<<<< - * filepath_index)) + * if self.fastafile == NULL: + * raise IOError("error when opening file `%s`" % filename) # <<<<<<<<<<<<<< * + * cdef int nreferences = faidx_nseq(self.fastafile) */ - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 164, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_error_when_opening_file_s, __pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 183, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 164, __pyx_L1_error) + __PYX_ERR(0, 183, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":163 - * filepath_index = filename + ".fai" + /* "pysam/libcfaidx.pyx":182 + * self.fastafile = fai_load(cfilename) + * + * if self.fastafile == NULL: # <<<<<<<<<<<<<< + * raise IOError("error when opening file `%s`" % filename) * - * if not os.path.exists(filepath_index): # <<<<<<<<<<<<<< - * raise ValueError("could not locate index file {}".format( - * filepath_index)) */ } - /* "pysam/libcfaidx.pyx":167 - * filepath_index)) + /* "pysam/libcfaidx.pyx":185 + * raise IOError("error when opening file `%s`" % filename) * - * with open(filepath_index) as inf: # <<<<<<<<<<<<<< - * data = [x.split("\t") for x in inf] - * self._references = tuple(x[0] for x in data) + * cdef int nreferences = faidx_nseq(self.fastafile) # <<<<<<<<<<<<<< + * cdef int x + * cdef const char * s */ - /*with:*/ { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_open, __pyx_v_filepath_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 167, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_12 = __Pyx_PyObject_LookupSpecial(__pyx_t_2, __pyx_n_s_exit); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 167, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_11 = __Pyx_PyObject_LookupSpecial(__pyx_t_2, __pyx_n_s_enter); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 167, __pyx_L15_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - if (__pyx_t_7) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 167, __pyx_L15_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else { - __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 167, __pyx_L15_error) - } - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __pyx_t_3; - __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /*try:*/ { - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15); - __Pyx_XGOTREF(__pyx_t_13); - __Pyx_XGOTREF(__pyx_t_14); - __Pyx_XGOTREF(__pyx_t_15); - /*try:*/ { - __pyx_v_inf = __pyx_t_11; - __pyx_t_11 = 0; - - /* "pysam/libcfaidx.pyx":168 - * - * with open(filepath_index) as inf: - * data = [x.split("\t") for x in inf] # <<<<<<<<<<<<<< - * self._references = tuple(x[0] for x in data) - * self._lengths = tuple(int(x[1]) for x in data) - */ - __pyx_t_11 = PyList_New(0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 168, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_11); - if (likely(PyList_CheckExact(__pyx_v_inf)) || PyTuple_CheckExact(__pyx_v_inf)) { - __pyx_t_2 = __pyx_v_inf; __Pyx_INCREF(__pyx_t_2); __pyx_t_16 = 0; - __pyx_t_17 = NULL; - } else { - __pyx_t_16 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_inf); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 168, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_17 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 168, __pyx_L19_error) - } - for (;;) { - if (likely(!__pyx_t_17)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_16 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_16); __Pyx_INCREF(__pyx_t_3); __pyx_t_16++; if (unlikely(0 < 0)) __PYX_ERR(0, 168, __pyx_L19_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_16); __pyx_t_16++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 168, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } else { - if (__pyx_t_16 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_16); __Pyx_INCREF(__pyx_t_3); __pyx_t_16++; if (unlikely(0 < 0)) __PYX_ERR(0, 168, __pyx_L19_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_16); __pyx_t_16++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 168, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } - } else { - __pyx_t_3 = __pyx_t_17(__pyx_t_2); - if (unlikely(!__pyx_t_3)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 168, __pyx_L19_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 168, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 168, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_11, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 168, __pyx_L19_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GIVEREF(__pyx_t_11); - __pyx_cur_scope->__pyx_v_data = ((PyObject*)__pyx_t_11); - __pyx_t_11 = 0; - - /* "pysam/libcfaidx.pyx":169 - * with open(filepath_index) as inf: - * data = [x.split("\t") for x in inf] - * self._references = tuple(x[0] for x in data) # <<<<<<<<<<<<<< - * self._lengths = tuple(int(x[1]) for x in data) - * self.reference2length = dict(zip(self._references, self._lengths)) - */ - __pyx_t_11 = __pyx_pf_5pysam_9libcfaidx_9FastaFile_5_open_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 169, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_2 = __Pyx_PySequence_Tuple(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 169, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_v_self->_references); - __Pyx_DECREF(__pyx_v_self->_references); - __pyx_v_self->_references = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_v_nreferences = faidx_nseq(__pyx_v_self->fastafile); + + /* "pysam/libcfaidx.pyx":188 + * cdef int x + * cdef const char * s + * self._references = [] # <<<<<<<<<<<<<< + * self._lengths = [] + * for x from 0 <= x < nreferences: + */ + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_v_self->_references); + __Pyx_DECREF(__pyx_v_self->_references); + __pyx_v_self->_references = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pysam/libcfaidx.pyx":189 + * cdef const char * s + * self._references = [] + * self._lengths = [] # <<<<<<<<<<<<<< + * for x from 0 <= x < nreferences: + * s = faidx_iseq(self.fastafile, x) + */ + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_v_self->_lengths); + __Pyx_DECREF(__pyx_v_self->_lengths); + __pyx_v_self->_lengths = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pysam/libcfaidx.pyx":190 + * self._references = [] + * self._lengths = [] + * for x from 0 <= x < nreferences: # <<<<<<<<<<<<<< + * s = faidx_iseq(self.fastafile, x) + * ss = force_str(s) + */ + __pyx_t_9 = __pyx_v_nreferences; + for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_9; __pyx_v_x++) { + + /* "pysam/libcfaidx.pyx":191 + * self._lengths = [] + * for x from 0 <= x < nreferences: + * s = faidx_iseq(self.fastafile, x) # <<<<<<<<<<<<<< + * ss = force_str(s) + * self._references.append(ss) + */ + __pyx_v_s = faidx_iseq(__pyx_v_self->fastafile, __pyx_v_x); + + /* "pysam/libcfaidx.pyx":192 + * for x from 0 <= x < nreferences: + * s = faidx_iseq(self.fastafile, x) + * ss = force_str(s) # <<<<<<<<<<<<<< + * self._references.append(ss) + * self._lengths.append(faidx_seq_len(self.fastafile, s)) + */ + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 192, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_ss, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcfaidx.pyx":193 + * s = faidx_iseq(self.fastafile, x) + * ss = force_str(s) + * self._references.append(ss) # <<<<<<<<<<<<<< + * self._lengths.append(faidx_seq_len(self.fastafile, s)) + * self.reference2length = dict(zip(self._references, self._lengths)) + */ + __pyx_t_10 = __Pyx_PyObject_Append(__pyx_v_self->_references, __pyx_v_ss); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 193, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":170 - * data = [x.split("\t") for x in inf] - * self._references = tuple(x[0] for x in data) - * self._lengths = tuple(int(x[1]) for x in data) # <<<<<<<<<<<<<< - * self.reference2length = dict(zip(self._references, self._lengths)) + /* "pysam/libcfaidx.pyx":194 + * ss = force_str(s) + * self._references.append(ss) + * self._lengths.append(faidx_seq_len(self.fastafile, s)) # <<<<<<<<<<<<<< + * self.reference2length = dict(zip(self._references, self._lengths)) * */ - __pyx_t_2 = __pyx_pf_5pysam_9libcfaidx_9FastaFile_5_open_3genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = __Pyx_PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 170, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GIVEREF(__pyx_t_11); - __Pyx_GOTREF(__pyx_v_self->_lengths); - __Pyx_DECREF(__pyx_v_self->_lengths); - __pyx_v_self->_lengths = __pyx_t_11; - __pyx_t_11 = 0; - - /* "pysam/libcfaidx.pyx":171 - * self._references = tuple(x[0] for x in data) - * self._lengths = tuple(int(x[1]) for x in data) - * self.reference2length = dict(zip(self._references, self._lengths)) # <<<<<<<<<<<<<< + __pyx_t_3 = __Pyx_PyInt_From_int(faidx_seq_len(__pyx_v_self->fastafile, __pyx_v_s)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = __Pyx_PyObject_Append(__pyx_v_self->_lengths, __pyx_t_3); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 194, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + + /* "pysam/libcfaidx.pyx":195 + * self._references.append(ss) + * self._lengths.append(faidx_seq_len(self.fastafile, s)) + * self.reference2length = dict(zip(self._references, self._lengths)) # <<<<<<<<<<<<<< * * def close(self): */ - __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 171, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_INCREF(__pyx_v_self->_references); - __Pyx_GIVEREF(__pyx_v_self->_references); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_self->_references); - __Pyx_INCREF(__pyx_v_self->_lengths); - __Pyx_GIVEREF(__pyx_v_self->_lengths); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_v_self->_lengths); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 171, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 171, __pyx_L19_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GIVEREF(__pyx_t_11); - __Pyx_GOTREF(__pyx_v_self->reference2length); - __Pyx_DECREF(__pyx_v_self->reference2length); - __pyx_v_self->reference2length = __pyx_t_11; - __pyx_t_11 = 0; - - /* "pysam/libcfaidx.pyx":167 - * filepath_index)) - * - * with open(filepath_index) as inf: # <<<<<<<<<<<<<< - * data = [x.split("\t") for x in inf] - * self._references = tuple(x[0] for x in data) - */ - } - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; - goto __pyx_L24_try_end; - __pyx_L19_error:; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - /*except:*/ { - __Pyx_AddTraceback("pysam.libcfaidx.FastaFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_11, &__pyx_t_2, &__pyx_t_7) < 0) __PYX_ERR(0, 167, __pyx_L21_except_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = PyTuple_Pack(3, __pyx_t_11, __pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 167, __pyx_L21_except_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_3, NULL); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 167, __pyx_L21_except_error) - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_18); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - if (__pyx_t_6 < 0) __PYX_ERR(0, 167, __pyx_L21_except_error) - __pyx_t_8 = ((!(__pyx_t_6 != 0)) != 0); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_11); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ErrRestoreWithState(__pyx_t_11, __pyx_t_2, __pyx_t_7); - __pyx_t_11 = 0; __pyx_t_2 = 0; __pyx_t_7 = 0; - __PYX_ERR(0, 167, __pyx_L21_except_error) - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L20_exception_handled; - } - __pyx_L21_except_error:; - __Pyx_XGIVEREF(__pyx_t_13); - __Pyx_XGIVEREF(__pyx_t_14); - __Pyx_XGIVEREF(__pyx_t_15); - __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15); - goto __pyx_L1_error; - __pyx_L20_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_13); - __Pyx_XGIVEREF(__pyx_t_14); - __Pyx_XGIVEREF(__pyx_t_15); - __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15); - __pyx_L24_try_end:; - } - } - /*finally:*/ { - /*normal exit:*/{ - if (__pyx_t_12) { - __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_tuple__8, NULL); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 167, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } - goto __pyx_L18; - } - __pyx_L18:; - } - goto __pyx_L30; - __pyx_L15_error:; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - goto __pyx_L1_error; - __pyx_L30:; - } + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_self->_references); + __Pyx_GIVEREF(__pyx_v_self->_references); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_self->_references); + __Pyx_INCREF(__pyx_v_self->_lengths); + __Pyx_GIVEREF(__pyx_v_self->_lengths); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_self->_lengths); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->reference2length); + __Pyx_DECREF(__pyx_v_self->reference2length); + __pyx_v_self->reference2length = __pyx_t_3; + __pyx_t_3 = 0; - /* "pysam/libcfaidx.pyx":126 + /* "pysam/libcfaidx.pyx":135 * return faidx_nseq(self.fastafile) * - * def _open(self, filename, filepath_index=None): # <<<<<<<<<<<<<< + * def _open(self, filename, filepath_index=None, filepath_index_compressed=None): # <<<<<<<<<<<<<< * '''open an indexed fasta file. * */ @@ -4136,23 +3684,20 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6_open(struct __pyx_obj_5 __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_11); __Pyx_AddTraceback("pysam.libcfaidx.FastaFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_inf); - __Pyx_XDECREF(__pyx_v_x); - __Pyx_XDECREF(__pyx_v_filepath_index); - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XDECREF(__pyx_v_bindex_filename); + __Pyx_XDECREF(__pyx_v_bindex_filename_compressed); + __Pyx_XDECREF(__pyx_v_ss); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcfaidx.pyx":173 - * self.reference2length = dict(zip(self._references, self._lengths)) +/* "pysam/libcfaidx.pyx":197 + * self.reference2length = dict(zip(self._references, self._lengths)) * * def close(self): # <<<<<<<<<<<<<< * """close the file.""" @@ -4179,9 +3724,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_8close(struct __pyx_obj_5 __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("close", 0); - __Pyx_TraceCall("close", __pyx_f[0], 173, 0, __PYX_ERR(0, 173, __pyx_L1_error)); + __Pyx_TraceCall("close", __pyx_f[0], 197, 0, __PYX_ERR(0, 197, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":175 + /* "pysam/libcfaidx.pyx":199 * def close(self): * """close the file.""" * if self.fastafile != NULL: # <<<<<<<<<<<<<< @@ -4191,7 +3736,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_8close(struct __pyx_obj_5 __pyx_t_1 = ((__pyx_v_self->fastafile != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcfaidx.pyx":176 + /* "pysam/libcfaidx.pyx":200 * """close the file.""" * if self.fastafile != NULL: * fai_destroy(self.fastafile) # <<<<<<<<<<<<<< @@ -4200,7 +3745,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_8close(struct __pyx_obj_5 */ fai_destroy(__pyx_v_self->fastafile); - /* "pysam/libcfaidx.pyx":177 + /* "pysam/libcfaidx.pyx":201 * if self.fastafile != NULL: * fai_destroy(self.fastafile) * self.fastafile = NULL # <<<<<<<<<<<<<< @@ -4209,7 +3754,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_8close(struct __pyx_obj_5 */ __pyx_v_self->fastafile = NULL; - /* "pysam/libcfaidx.pyx":175 + /* "pysam/libcfaidx.pyx":199 * def close(self): * """close the file.""" * if self.fastafile != NULL: # <<<<<<<<<<<<<< @@ -4218,8 +3763,8 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_8close(struct __pyx_obj_5 */ } - /* "pysam/libcfaidx.pyx":173 - * self.reference2length = dict(zip(self._references, self._lengths)) + /* "pysam/libcfaidx.pyx":197 + * self.reference2length = dict(zip(self._references, self._lengths)) * * def close(self): # <<<<<<<<<<<<<< * """close the file.""" @@ -4239,7 +3784,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_8close(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libcfaidx.pyx":179 +/* "pysam/libcfaidx.pyx":203 * self.fastafile = NULL * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -4263,9 +3808,9 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastaFile_10__dealloc__(struct __pyx_obj __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 179, 0, __PYX_ERR(0, 179, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 203, 0, __PYX_ERR(0, 203, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":180 + /* "pysam/libcfaidx.pyx":204 * * def __dealloc__(self): * if self.fastafile != NULL: # <<<<<<<<<<<<<< @@ -4275,7 +3820,7 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastaFile_10__dealloc__(struct __pyx_obj __pyx_t_1 = ((__pyx_v_self->fastafile != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcfaidx.pyx":181 + /* "pysam/libcfaidx.pyx":205 * def __dealloc__(self): * if self.fastafile != NULL: * fai_destroy(self.fastafile) # <<<<<<<<<<<<<< @@ -4284,7 +3829,7 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastaFile_10__dealloc__(struct __pyx_obj */ fai_destroy(__pyx_v_self->fastafile); - /* "pysam/libcfaidx.pyx":182 + /* "pysam/libcfaidx.pyx":206 * if self.fastafile != NULL: * fai_destroy(self.fastafile) * self.fastafile = NULL # <<<<<<<<<<<<<< @@ -4293,7 +3838,7 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastaFile_10__dealloc__(struct __pyx_obj */ __pyx_v_self->fastafile = NULL; - /* "pysam/libcfaidx.pyx":180 + /* "pysam/libcfaidx.pyx":204 * * def __dealloc__(self): * if self.fastafile != NULL: # <<<<<<<<<<<<<< @@ -4302,7 +3847,7 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastaFile_10__dealloc__(struct __pyx_obj */ } - /* "pysam/libcfaidx.pyx":179 + /* "pysam/libcfaidx.pyx":203 * self.fastafile = NULL * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -4319,7 +3864,7 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastaFile_10__dealloc__(struct __pyx_obj __Pyx_RefNannyFinishContext(); } -/* "pysam/libcfaidx.pyx":185 +/* "pysam/libcfaidx.pyx":209 * * # context manager interface * def __enter__(self): # <<<<<<<<<<<<<< @@ -4346,9 +3891,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_12__enter__(struct __pyx_ __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__enter__", 0); - __Pyx_TraceCall("__enter__", __pyx_f[0], 185, 0, __PYX_ERR(0, 185, __pyx_L1_error)); + __Pyx_TraceCall("__enter__", __pyx_f[0], 209, 0, __PYX_ERR(0, 209, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":186 + /* "pysam/libcfaidx.pyx":210 * # context manager interface * def __enter__(self): * return self # <<<<<<<<<<<<<< @@ -4360,7 +3905,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_12__enter__(struct __pyx_ __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcfaidx.pyx":185 + /* "pysam/libcfaidx.pyx":209 * * # context manager interface * def __enter__(self): # <<<<<<<<<<<<<< @@ -4379,7 +3924,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_12__enter__(struct __pyx_ return __pyx_r; } -/* "pysam/libcfaidx.pyx":188 +/* "pysam/libcfaidx.pyx":212 * return self * * def __exit__(self, exc_type, exc_value, traceback): # <<<<<<<<<<<<<< @@ -4422,17 +3967,17 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_15__exit__(PyObject *__py case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_exc_value)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 188, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 212, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_traceback)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 188, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 212, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 188, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 212, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -4447,7 +3992,7 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_15__exit__(PyObject *__py } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 188, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 212, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcfaidx.FastaFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -4468,16 +4013,16 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_14__exit__(struct __pyx_o PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__exit__", 0); - __Pyx_TraceCall("__exit__", __pyx_f[0], 188, 0, __PYX_ERR(0, 188, __pyx_L1_error)); + __Pyx_TraceCall("__exit__", __pyx_f[0], 212, 0, __PYX_ERR(0, 212, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":189 + /* "pysam/libcfaidx.pyx":213 * * def __exit__(self, exc_type, exc_value, traceback): * self.close() # <<<<<<<<<<<<<< * return False * */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 189, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 213, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -4490,16 +4035,16 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_14__exit__(struct __pyx_o } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 189, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 213, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 189, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 213, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcfaidx.pyx":190 + /* "pysam/libcfaidx.pyx":214 * def __exit__(self, exc_type, exc_value, traceback): * self.close() * return False # <<<<<<<<<<<<<< @@ -4511,7 +4056,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_14__exit__(struct __pyx_o __pyx_r = Py_False; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":188 + /* "pysam/libcfaidx.pyx":212 * return self * * def __exit__(self, exc_type, exc_value, traceback): # <<<<<<<<<<<<<< @@ -4533,7 +4078,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_14__exit__(struct __pyx_o return __pyx_r; } -/* "pysam/libcfaidx.pyx":196 +/* "pysam/libcfaidx.pyx":220 * This is a read-only attribute; the close() method changes the value. * """ * def __get__(self): # <<<<<<<<<<<<<< @@ -4563,9 +4108,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6closed___get__(struct __ PyObject *__pyx_t_3 = NULL; int __pyx_t_4; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 196, 0, __PYX_ERR(0, 196, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 220, 0, __PYX_ERR(0, 220, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":197 + /* "pysam/libcfaidx.pyx":221 * """ * def __get__(self): * return not self.is_open() # <<<<<<<<<<<<<< @@ -4573,7 +4118,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6closed___get__(struct __ * property filename: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 197, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 221, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -4586,22 +4131,22 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6closed___get__(struct __ } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 197, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 221, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 197, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 221, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 197, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 221, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_4)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 197, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_4)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 221, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":196 + /* "pysam/libcfaidx.pyx":220 * This is a read-only attribute; the close() method changes the value. * """ * def __get__(self): # <<<<<<<<<<<<<< @@ -4623,7 +4168,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_6closed___get__(struct __ return __pyx_r; } -/* "pysam/libcfaidx.pyx":201 +/* "pysam/libcfaidx.pyx":225 * property filename: * """filename associated with this object. This is a read-only attribute.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -4649,9 +4194,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_8filename___get__(struct __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 201, 0, __PYX_ERR(0, 201, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 225, 0, __PYX_ERR(0, 225, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":202 + /* "pysam/libcfaidx.pyx":226 * """filename associated with this object. This is a read-only attribute.""" * def __get__(self): * return self._filename # <<<<<<<<<<<<<< @@ -4663,7 +4208,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_8filename___get__(struct __pyx_r = __pyx_v_self->_filename; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":201 + /* "pysam/libcfaidx.pyx":225 * property filename: * """filename associated with this object. This is a read-only attribute.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -4682,7 +4227,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_8filename___get__(struct return __pyx_r; } -/* "pysam/libcfaidx.pyx":206 +/* "pysam/libcfaidx.pyx":230 * property references: * '''tuple with the names of :term:`reference` sequences.''' * def __get__(self): # <<<<<<<<<<<<<< @@ -4708,9 +4253,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_10references___get__(stru __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 206, 0, __PYX_ERR(0, 206, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 230, 0, __PYX_ERR(0, 230, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":207 + /* "pysam/libcfaidx.pyx":231 * '''tuple with the names of :term:`reference` sequences.''' * def __get__(self): * return self._references # <<<<<<<<<<<<<< @@ -4722,7 +4267,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_10references___get__(stru __pyx_r = __pyx_v_self->_references; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":206 + /* "pysam/libcfaidx.pyx":230 * property references: * '''tuple with the names of :term:`reference` sequences.''' * def __get__(self): # <<<<<<<<<<<<<< @@ -4741,7 +4286,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_10references___get__(stru return __pyx_r; } -/* "pysam/libcfaidx.pyx":212 +/* "pysam/libcfaidx.pyx":236 * """"int with the number of :term:`reference` sequences in the file. * This is a read-only attribute.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -4771,9 +4316,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_11nreferences___get__(str int __pyx_t_3; Py_ssize_t __pyx_t_4; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 212, 0, __PYX_ERR(0, 212, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 236, 0, __PYX_ERR(0, 236, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":213 + /* "pysam/libcfaidx.pyx":237 * This is a read-only attribute.""" * def __get__(self): * return len(self._references) if self.references else None # <<<<<<<<<<<<<< @@ -4781,16 +4326,16 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_11nreferences___get__(str * property lengths: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_references); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 213, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_references); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 237, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 213, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 237, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { __pyx_t_2 = __pyx_v_self->_references; __Pyx_INCREF(__pyx_t_2); - __pyx_t_4 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 213, __pyx_L1_error) + __pyx_t_4 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 237, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 213, __pyx_L1_error) + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 237, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; __pyx_t_2 = 0; @@ -4802,7 +4347,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_11nreferences___get__(str __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":212 + /* "pysam/libcfaidx.pyx":236 * """"int with the number of :term:`reference` sequences in the file. * This is a read-only attribute.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -4823,7 +4368,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_11nreferences___get__(str return __pyx_r; } -/* "pysam/libcfaidx.pyx":217 +/* "pysam/libcfaidx.pyx":241 * property lengths: * """tuple with the lengths of :term:`reference` sequences.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -4849,9 +4394,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_7lengths___get__(struct _ __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 217, 0, __PYX_ERR(0, 217, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 241, 0, __PYX_ERR(0, 241, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":218 + /* "pysam/libcfaidx.pyx":242 * """tuple with the lengths of :term:`reference` sequences.""" * def __get__(self): * return self._lengths # <<<<<<<<<<<<<< @@ -4863,7 +4408,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_7lengths___get__(struct _ __pyx_r = __pyx_v_self->_lengths; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":217 + /* "pysam/libcfaidx.pyx":241 * property lengths: * """tuple with the lengths of :term:`reference` sequences.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -4882,7 +4427,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_7lengths___get__(struct _ return __pyx_r; } -/* "pysam/libcfaidx.pyx":220 +/* "pysam/libcfaidx.pyx":244 * return self._lengths * * def fetch(self, # <<<<<<<<<<<<<< @@ -4905,7 +4450,7 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_17fetch(PyObject *__pyx_v static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,0}; PyObject* values[4] = {0,0,0,0}; - /* "pysam/libcfaidx.pyx":221 + /* "pysam/libcfaidx.pyx":245 * * def fetch(self, * reference=None, # <<<<<<<<<<<<<< @@ -4914,7 +4459,7 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_17fetch(PyObject *__pyx_v */ values[0] = ((PyObject *)Py_None); - /* "pysam/libcfaidx.pyx":222 + /* "pysam/libcfaidx.pyx":246 * def fetch(self, * reference=None, * start=None, # <<<<<<<<<<<<<< @@ -4923,7 +4468,7 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_17fetch(PyObject *__pyx_v */ values[1] = ((PyObject *)Py_None); - /* "pysam/libcfaidx.pyx":223 + /* "pysam/libcfaidx.pyx":247 * reference=None, * start=None, * end=None, # <<<<<<<<<<<<<< @@ -4932,7 +4477,7 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_17fetch(PyObject *__pyx_v */ values[2] = ((PyObject *)Py_None); - /* "pysam/libcfaidx.pyx":224 + /* "pysam/libcfaidx.pyx":248 * start=None, * end=None, * region=None): # <<<<<<<<<<<<<< @@ -4982,7 +4527,7 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_17fetch(PyObject *__pyx_v } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 220, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 244, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -5005,7 +4550,7 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_17fetch(PyObject *__pyx_v } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 220, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 244, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcfaidx.FastaFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -5013,7 +4558,7 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastaFile_17fetch(PyObject *__pyx_v __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region); - /* "pysam/libcfaidx.pyx":220 + /* "pysam/libcfaidx.pyx":244 * return self._lengths * * def fetch(self, # <<<<<<<<<<<<<< @@ -5055,17 +4600,17 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ PyObject *__pyx_t_18 = NULL; PyObject *__pyx_t_19 = NULL; __Pyx_RefNannySetupContext("fetch", 0); - __Pyx_TraceCall("fetch", __pyx_f[0], 220, 0, __PYX_ERR(0, 220, __pyx_L1_error)); + __Pyx_TraceCall("fetch", __pyx_f[0], 244, 0, __PYX_ERR(0, 244, __pyx_L1_error)); __Pyx_INCREF(__pyx_v_reference); - /* "pysam/libcfaidx.pyx":258 + /* "pysam/libcfaidx.pyx":282 * """ * * if not self.is_open(): # <<<<<<<<<<<<<< * raise ValueError("I/O operation on closed file" ) * */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -5078,32 +4623,32 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_5 = ((!__pyx_t_4) != 0); if (unlikely(__pyx_t_5)) { - /* "pysam/libcfaidx.pyx":259 + /* "pysam/libcfaidx.pyx":283 * * if not self.is_open(): * raise ValueError("I/O operation on closed file" ) # <<<<<<<<<<<<<< * * cdef int length */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 259, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 283, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 259, __pyx_L1_error) + __PYX_ERR(0, 283, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":258 + /* "pysam/libcfaidx.pyx":282 * """ * * if not self.is_open(): # <<<<<<<<<<<<<< @@ -5112,7 +4657,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ */ } - /* "pysam/libcfaidx.pyx":266 + /* "pysam/libcfaidx.pyx":290 * cdef int rstart, rend * * reference, rstart, rend = parse_region(reference, start, end, region) # <<<<<<<<<<<<<< @@ -5124,7 +4669,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __pyx_t_6.start = __pyx_v_start; __pyx_t_6.end = __pyx_v_end; __pyx_t_6.region = __pyx_v_region; - __pyx_t_1 = __pyx_f_5pysam_9libcutils_parse_region(0, &__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 266, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_parse_region(0, &__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 290, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { PyObject* sequence = __pyx_t_1; @@ -5132,7 +4677,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ if (unlikely(size != 3)) { if (size > 3) __Pyx_RaiseTooManyValuesError(3); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 266, __pyx_L1_error) + __PYX_ERR(0, 290, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { @@ -5148,17 +4693,17 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_7); #else - __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 266, __pyx_L1_error) + __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 290, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 266, __pyx_L1_error) + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 290, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 266, __pyx_L1_error) + __pyx_t_7 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 290, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { Py_ssize_t index = -1; - __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 266, __pyx_L1_error) + __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 290, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; @@ -5168,7 +4713,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __Pyx_GOTREF(__pyx_t_3); index = 2; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 3) < 0) __PYX_ERR(0, 266, __pyx_L1_error) + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 3) < 0) __PYX_ERR(0, 290, __pyx_L1_error) __pyx_t_9 = NULL; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; goto __pyx_L5_unpacking_done; @@ -5176,19 +4721,19 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_9 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 266, __pyx_L1_error) + __PYX_ERR(0, 290, __pyx_L1_error) __pyx_L5_unpacking_done:; } - __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 266, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 290, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 266, __pyx_L1_error) + __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 290, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF_SET(__pyx_v_reference, __pyx_t_2); __pyx_t_2 = 0; __pyx_v_rstart = __pyx_t_10; __pyx_v_rend = __pyx_t_11; - /* "pysam/libcfaidx.pyx":268 + /* "pysam/libcfaidx.pyx":292 * reference, rstart, rend = parse_region(reference, start, end, region) * * if reference is None: # <<<<<<<<<<<<<< @@ -5199,20 +4744,20 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __pyx_t_4 = (__pyx_t_5 != 0); if (unlikely(__pyx_t_4)) { - /* "pysam/libcfaidx.pyx":269 + /* "pysam/libcfaidx.pyx":293 * * if reference is None: * raise ValueError("no sequence/region supplied.") # <<<<<<<<<<<<<< * * if rstart == rend: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 293, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 269, __pyx_L1_error) + __PYX_ERR(0, 293, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":268 + /* "pysam/libcfaidx.pyx":292 * reference, rstart, rend = parse_region(reference, start, end, region) * * if reference is None: # <<<<<<<<<<<<<< @@ -5221,7 +4766,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ */ } - /* "pysam/libcfaidx.pyx":271 + /* "pysam/libcfaidx.pyx":295 * raise ValueError("no sequence/region supplied.") * * if rstart == rend: # <<<<<<<<<<<<<< @@ -5231,7 +4776,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __pyx_t_4 = ((__pyx_v_rstart == __pyx_v_rend) != 0); if (__pyx_t_4) { - /* "pysam/libcfaidx.pyx":272 + /* "pysam/libcfaidx.pyx":296 * * if rstart == rend: * return "" # <<<<<<<<<<<<<< @@ -5243,7 +4788,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __pyx_r = __pyx_kp_s__5; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":271 + /* "pysam/libcfaidx.pyx":295 * raise ValueError("no sequence/region supplied.") * * if rstart == rend: # <<<<<<<<<<<<<< @@ -5252,17 +4797,17 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ */ } - /* "pysam/libcfaidx.pyx":274 + /* "pysam/libcfaidx.pyx":298 * return "" * * ref = reference # <<<<<<<<<<<<<< * with nogil: * length = faidx_seq_len(self.fastafile, ref) */ - __pyx_t_12 = __Pyx_PyObject_AsWritableString(__pyx_v_reference); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 274, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyObject_AsWritableString(__pyx_v_reference); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 298, __pyx_L1_error) __pyx_v_ref = __pyx_t_12; - /* "pysam/libcfaidx.pyx":275 + /* "pysam/libcfaidx.pyx":299 * * ref = reference * with nogil: # <<<<<<<<<<<<<< @@ -5277,7 +4822,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ #endif /*try:*/ { - /* "pysam/libcfaidx.pyx":276 + /* "pysam/libcfaidx.pyx":300 * ref = reference * with nogil: * length = faidx_seq_len(self.fastafile, ref) # <<<<<<<<<<<<<< @@ -5287,7 +4832,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __pyx_v_length = faidx_seq_len(__pyx_v_self->fastafile, __pyx_v_ref); } - /* "pysam/libcfaidx.pyx":275 + /* "pysam/libcfaidx.pyx":299 * * ref = reference * with nogil: # <<<<<<<<<<<<<< @@ -5306,7 +4851,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ } } - /* "pysam/libcfaidx.pyx":277 + /* "pysam/libcfaidx.pyx":301 * with nogil: * length = faidx_seq_len(self.fastafile, ref) * if length == -1: # <<<<<<<<<<<<<< @@ -5316,23 +4861,23 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __pyx_t_4 = ((__pyx_v_length == -1L) != 0); if (unlikely(__pyx_t_4)) { - /* "pysam/libcfaidx.pyx":278 + /* "pysam/libcfaidx.pyx":302 * length = faidx_seq_len(self.fastafile, ref) * if length == -1: * raise KeyError("sequence '%s' not present" % reference) # <<<<<<<<<<<<<< * if rstart >= length: * return "" */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_sequence_s_not_present, __pyx_v_reference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 278, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_sequence_s_not_present, __pyx_v_reference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 302, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 278, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 302, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_7, 0, 0, 0); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __PYX_ERR(0, 278, __pyx_L1_error) + __PYX_ERR(0, 302, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":277 + /* "pysam/libcfaidx.pyx":301 * with nogil: * length = faidx_seq_len(self.fastafile, ref) * if length == -1: # <<<<<<<<<<<<<< @@ -5341,7 +4886,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ */ } - /* "pysam/libcfaidx.pyx":279 + /* "pysam/libcfaidx.pyx":303 * if length == -1: * raise KeyError("sequence '%s' not present" % reference) * if rstart >= length: # <<<<<<<<<<<<<< @@ -5351,7 +4896,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __pyx_t_4 = ((__pyx_v_rstart >= __pyx_v_length) != 0); if (__pyx_t_4) { - /* "pysam/libcfaidx.pyx":280 + /* "pysam/libcfaidx.pyx":304 * raise KeyError("sequence '%s' not present" % reference) * if rstart >= length: * return "" # <<<<<<<<<<<<<< @@ -5363,7 +4908,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __pyx_r = __pyx_kp_s__5; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":279 + /* "pysam/libcfaidx.pyx":303 * if length == -1: * raise KeyError("sequence '%s' not present" % reference) * if rstart >= length: # <<<<<<<<<<<<<< @@ -5372,7 +4917,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ */ } - /* "pysam/libcfaidx.pyx":283 + /* "pysam/libcfaidx.pyx":307 * * # fai_fetch adds a '\0' at the end * with nogil: # <<<<<<<<<<<<<< @@ -5387,7 +4932,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ #endif /*try:*/ { - /* "pysam/libcfaidx.pyx":284 + /* "pysam/libcfaidx.pyx":308 * # fai_fetch adds a '\0' at the end * with nogil: * seq = faidx_fetch_seq(self.fastafile, # <<<<<<<<<<<<<< @@ -5397,7 +4942,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __pyx_v_seq = faidx_fetch_seq(__pyx_v_self->fastafile, __pyx_v_ref, __pyx_v_rstart, (__pyx_v_rend - 1), (&__pyx_v_length)); } - /* "pysam/libcfaidx.pyx":283 + /* "pysam/libcfaidx.pyx":307 * * # fai_fetch adds a '\0' at the end * with nogil: # <<<<<<<<<<<<<< @@ -5416,51 +4961,90 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ } } - /* "pysam/libcfaidx.pyx":290 + /* "pysam/libcfaidx.pyx":314 * &length) * - * if seq == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "failure when retrieving sequence on '%s'" % reference) + * if not seq: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, strerror(errno)) */ - __pyx_t_4 = ((__pyx_v_seq == NULL) != 0); - if (unlikely(__pyx_t_4)) { + __pyx_t_4 = ((!(__pyx_v_seq != 0)) != 0); + if (__pyx_t_4) { - /* "pysam/libcfaidx.pyx":292 - * if seq == NULL: - * raise ValueError( - * "failure when retrieving sequence on '%s'" % reference) # <<<<<<<<<<<<<< + /* "pysam/libcfaidx.pyx":315 * - * try: + * if not seq: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) + * else: */ - __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_failure_when_retrieving_sequence, __pyx_v_reference); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 292, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = (errno != 0); + if (unlikely(__pyx_t_4)) { + + /* "pysam/libcfaidx.pyx":316 + * if not seq: + * if errno: + * raise IOError(errno, strerror(errno)) # <<<<<<<<<<<<<< + * else: + * raise ValueError("failure when retrieving sequence on '%s'" % reference) + */ + __pyx_t_7 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); + __pyx_t_7 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 316, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":291 + /* "pysam/libcfaidx.pyx":315 * - * if seq == NULL: - * raise ValueError( # <<<<<<<<<<<<<< - * "failure when retrieving sequence on '%s'" % reference) + * if not seq: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) + * else: + */ + } + + /* "pysam/libcfaidx.pyx":318 + * raise IOError(errno, strerror(errno)) + * else: + * raise ValueError("failure when retrieving sequence on '%s'" % reference) # <<<<<<<<<<<<<< * + * try: */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 291, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 291, __pyx_L1_error) + /*else*/ { + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_failure_when_retrieving_sequence, __pyx_v_reference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 318, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 318, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 318, __pyx_L1_error) + } - /* "pysam/libcfaidx.pyx":290 + /* "pysam/libcfaidx.pyx":314 * &length) * - * if seq == NULL: # <<<<<<<<<<<<<< - * raise ValueError( - * "failure when retrieving sequence on '%s'" % reference) + * if not seq: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, strerror(errno)) */ } - /* "pysam/libcfaidx.pyx":294 - * "failure when retrieving sequence on '%s'" % reference) + /* "pysam/libcfaidx.pyx":320 + * raise ValueError("failure when retrieving sequence on '%s'" % reference) * * try: # <<<<<<<<<<<<<< * return charptr_to_str(seq) @@ -5468,7 +5052,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ */ /*try:*/ { - /* "pysam/libcfaidx.pyx":295 + /* "pysam/libcfaidx.pyx":321 * * try: * return charptr_to_str(seq) # <<<<<<<<<<<<<< @@ -5476,31 +5060,31 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ * free(seq) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_seq, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 295, __pyx_L18_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L17_return; + __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_seq, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 321, __pyx_L19_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L18_return; } - /* "pysam/libcfaidx.pyx":297 + /* "pysam/libcfaidx.pyx":323 * return charptr_to_str(seq) * finally: * free(seq) # <<<<<<<<<<<<<< * - * cdef char * _fetch(self, char * reference, int start, int end, int * length): + * cdef char *_fetch(self, char *reference, int start, int end, int *length) except? NULL: */ /*finally:*/ { - __pyx_L18_error:; + __pyx_L19_error:; /*exception exit:*/{ __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19); if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16) < 0)) __Pyx_ErrFetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); __Pyx_XGOTREF(__pyx_t_14); @@ -5527,7 +5111,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ __pyx_lineno = __pyx_t_11; __pyx_clineno = __pyx_t_10; __pyx_filename = __pyx_t_13; goto __pyx_L1_error; } - __pyx_L17_return: { + __pyx_L18_return: { __pyx_t_19 = __pyx_r; __pyx_r = 0; free(__pyx_v_seq); @@ -5537,7 +5121,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ } } - /* "pysam/libcfaidx.pyx":220 + /* "pysam/libcfaidx.pyx":244 * return self._lengths * * def fetch(self, # <<<<<<<<<<<<<< @@ -5562,27 +5146,32 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_16fetch(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libcfaidx.pyx":299 +/* "pysam/libcfaidx.pyx":325 * free(seq) * - * cdef char * _fetch(self, char * reference, int start, int end, int * length): # <<<<<<<<<<<<<< + * cdef char *_fetch(self, char *reference, int start, int end, int *length) except? NULL: # <<<<<<<<<<<<<< * '''fetch sequence for reference, start and end''' * */ static char *__pyx_f_5pysam_9libcfaidx_9FastaFile__fetch(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_self, char *__pyx_v_reference, int __pyx_v_start, int __pyx_v_end, int *__pyx_v_length) { + char *__pyx_v_seq; char *__pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("_fetch", 0); - __Pyx_TraceCall("_fetch", __pyx_f[0], 299, 0, __PYX_ERR(0, 299, __pyx_L1_error)); + __Pyx_TraceCall("_fetch", __pyx_f[0], 325, 0, __PYX_ERR(0, 325, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":302 - * '''fetch sequence for reference, start and end''' + /* "pysam/libcfaidx.pyx":329 * + * cdef char *seq * with nogil: # <<<<<<<<<<<<<< - * return faidx_fetch_seq(self.fastafile, - * reference, + * seq = faidx_fetch_seq(self.fastafile, + * reference, */ { #ifdef WITH_THREAD @@ -5592,55 +5181,153 @@ static char *__pyx_f_5pysam_9libcfaidx_9FastaFile__fetch(struct __pyx_obj_5pysam #endif /*try:*/ { - /* "pysam/libcfaidx.pyx":303 - * + /* "pysam/libcfaidx.pyx":330 + * cdef char *seq * with nogil: - * return faidx_fetch_seq(self.fastafile, # <<<<<<<<<<<<<< - * reference, - * start, + * seq = faidx_fetch_seq(self.fastafile, # <<<<<<<<<<<<<< + * reference, + * start, */ - __pyx_r = faidx_fetch_seq(__pyx_v_self->fastafile, __pyx_v_reference, __pyx_v_start, (__pyx_v_end - 1), __pyx_v_length); - goto __pyx_L3_return; + __pyx_v_seq = faidx_fetch_seq(__pyx_v_self->fastafile, __pyx_v_reference, __pyx_v_start, (__pyx_v_end - 1), __pyx_v_length); } - /* "pysam/libcfaidx.pyx":302 - * '''fetch sequence for reference, start and end''' + /* "pysam/libcfaidx.pyx":329 * + * cdef char *seq * with nogil: # <<<<<<<<<<<<<< - * return faidx_fetch_seq(self.fastafile, - * reference, + * seq = faidx_fetch_seq(self.fastafile, + * reference, */ /*finally:*/ { - __pyx_L3_return: { + /*normal exit:*/{ #ifdef WITH_THREAD __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif - goto __pyx_L0; + goto __pyx_L5; } + __pyx_L5:; } } - /* "pysam/libcfaidx.pyx":299 + /* "pysam/libcfaidx.pyx":336 + * length) + * + * if not seq: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, strerror(errno)) + */ + __pyx_t_1 = ((!(__pyx_v_seq != 0)) != 0); + if (__pyx_t_1) { + + /* "pysam/libcfaidx.pyx":337 + * + * if not seq: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) + * else: + */ + __pyx_t_1 = (errno != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcfaidx.pyx":338 + * if not seq: + * if errno: + * raise IOError(errno, strerror(errno)) # <<<<<<<<<<<<<< + * else: + * raise ValueError("failure when retrieving sequence on '%s'" % reference) + */ + __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 338, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 338, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 338, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 338, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 338, __pyx_L1_error) + + /* "pysam/libcfaidx.pyx":337 + * + * if not seq: + * if errno: # <<<<<<<<<<<<<< + * raise IOError(errno, strerror(errno)) + * else: + */ + } + + /* "pysam/libcfaidx.pyx":340 + * raise IOError(errno, strerror(errno)) + * else: + * raise ValueError("failure when retrieving sequence on '%s'" % reference) # <<<<<<<<<<<<<< + * + * return seq + */ + /*else*/ { + __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_reference); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 340, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_failure_when_retrieving_sequence, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 340, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 340, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 340, __pyx_L1_error) + } + + /* "pysam/libcfaidx.pyx":336 + * length) + * + * if not seq: # <<<<<<<<<<<<<< + * if errno: + * raise IOError(errno, strerror(errno)) + */ + } + + /* "pysam/libcfaidx.pyx":342 + * raise ValueError("failure when retrieving sequence on '%s'" % reference) + * + * return seq # <<<<<<<<<<<<<< + * + * def get_reference_length(self, reference): + */ + __pyx_r = __pyx_v_seq; + goto __pyx_L0; + + /* "pysam/libcfaidx.pyx":325 * free(seq) * - * cdef char * _fetch(self, char * reference, int start, int end, int * length): # <<<<<<<<<<<<<< + * cdef char *_fetch(self, char *reference, int start, int end, int *length) except? NULL: # <<<<<<<<<<<<<< * '''fetch sequence for reference, start and end''' * */ /* function exit code */ __pyx_L1_error:; - __Pyx_WriteUnraisable("pysam.libcfaidx.FastaFile._fetch", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libcfaidx.FastaFile._fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libcfaidx.pyx":309 - * length) +/* "pysam/libcfaidx.pyx":344 + * return seq * * def get_reference_length(self, reference): # <<<<<<<<<<<<<< * '''return the length of reference.''' @@ -5667,9 +5354,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_18get_reference_length(st __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("get_reference_length", 0); - __Pyx_TraceCall("get_reference_length", __pyx_f[0], 309, 0, __PYX_ERR(0, 309, __pyx_L1_error)); + __Pyx_TraceCall("get_reference_length", __pyx_f[0], 344, 0, __PYX_ERR(0, 344, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":311 + /* "pysam/libcfaidx.pyx":346 * def get_reference_length(self, reference): * '''return the length of reference.''' * return self.reference2length[reference] # <<<<<<<<<<<<<< @@ -5677,14 +5364,14 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_18get_reference_length(st * def __getitem__(self, reference): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_self->reference2length, __pyx_v_reference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 311, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_self->reference2length, __pyx_v_reference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 346, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":309 - * length) + /* "pysam/libcfaidx.pyx":344 + * return seq * * def get_reference_length(self, reference): # <<<<<<<<<<<<<< * '''return the length of reference.''' @@ -5703,7 +5390,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_18get_reference_length(st return __pyx_r; } -/* "pysam/libcfaidx.pyx":313 +/* "pysam/libcfaidx.pyx":348 * return self.reference2length[reference] * * def __getitem__(self, reference): # <<<<<<<<<<<<<< @@ -5733,9 +5420,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_20__getitem__(struct __py PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__getitem__", 0); - __Pyx_TraceCall("__getitem__", __pyx_f[0], 313, 0, __PYX_ERR(0, 313, __pyx_L1_error)); + __Pyx_TraceCall("__getitem__", __pyx_f[0], 348, 0, __PYX_ERR(0, 348, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":314 + /* "pysam/libcfaidx.pyx":349 * * def __getitem__(self, reference): * return self.fetch(reference) # <<<<<<<<<<<<<< @@ -5743,7 +5430,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_20__getitem__(struct __py * def __contains__(self, reference): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 314, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 349, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -5756,13 +5443,13 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_20__getitem__(struct __py } } if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_reference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 314, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_reference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 349, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_reference}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 314, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 349, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -5770,19 +5457,19 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_20__getitem__(struct __py #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_reference}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 314, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 349, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 314, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 349, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_reference); __Pyx_GIVEREF(__pyx_v_reference); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_reference); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 314, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 349, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -5792,7 +5479,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_20__getitem__(struct __py __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":313 + /* "pysam/libcfaidx.pyx":348 * return self.reference2length[reference] * * def __getitem__(self, reference): # <<<<<<<<<<<<<< @@ -5815,7 +5502,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_20__getitem__(struct __py return __pyx_r; } -/* "pysam/libcfaidx.pyx":316 +/* "pysam/libcfaidx.pyx":351 * return self.fetch(reference) * * def __contains__(self, reference): # <<<<<<<<<<<<<< @@ -5846,20 +5533,20 @@ static int __pyx_pf_5pysam_9libcfaidx_9FastaFile_22__contains__(struct __pyx_obj __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__contains__", 0); - __Pyx_TraceCall("__contains__", __pyx_f[0], 316, 0, __PYX_ERR(0, 316, __pyx_L1_error)); + __Pyx_TraceCall("__contains__", __pyx_f[0], 351, 0, __PYX_ERR(0, 351, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":318 + /* "pysam/libcfaidx.pyx":353 * def __contains__(self, reference): * '''return true if reference in fasta file.''' * return reference in self.reference2length # <<<<<<<<<<<<<< * * */ - __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_reference, __pyx_v_self->reference2length, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 318, __pyx_L1_error) + __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_reference, __pyx_v_self->reference2length, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 353, __pyx_L1_error) __pyx_r = __pyx_t_1; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":316 + /* "pysam/libcfaidx.pyx":351 * return self.fetch(reference) * * def __contains__(self, reference): # <<<<<<<<<<<<<< @@ -5911,7 +5598,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_24__reduce_cython__(CYTHO * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -5968,7 +5655,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_26__setstate_cython__(CYT * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -5992,7 +5679,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastaFile_26__setstate_cython__(CYT return __pyx_r; } -/* "pysam/libcfaidx.pyx":323 +/* "pysam/libcfaidx.pyx":358 * cdef class FastqProxy: * """A single entry in a fastq file.""" * def __init__(self): pass # <<<<<<<<<<<<<< @@ -6021,7 +5708,7 @@ static int __pyx_pf_5pysam_9libcfaidx_10FastqProxy___init__(CYTHON_UNUSED struct __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 323, 0, __PYX_ERR(0, 323, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 358, 0, __PYX_ERR(0, 358, __pyx_L1_error)); /* function exit code */ __pyx_r = 0; @@ -6035,7 +5722,7 @@ static int __pyx_pf_5pysam_9libcfaidx_10FastqProxy___init__(CYTHON_UNUSED struct return __pyx_r; } -/* "pysam/libcfaidx.pyx":327 +/* "pysam/libcfaidx.pyx":362 * property name: * """The name of each entry in the fastq file.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -6062,9 +5749,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_4name___get__(struct __ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 327, 0, __PYX_ERR(0, 327, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 362, 0, __PYX_ERR(0, 362, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":328 + /* "pysam/libcfaidx.pyx":363 * """The name of each entry in the fastq file.""" * def __get__(self): * return charptr_to_str(self._delegate.name.s) # <<<<<<<<<<<<<< @@ -6072,13 +5759,13 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_4name___get__(struct __ * property sequence: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_self->_delegate->name.s, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 328, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_self->_delegate->name.s, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":327 + /* "pysam/libcfaidx.pyx":362 * property name: * """The name of each entry in the fastq file.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -6098,7 +5785,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_4name___get__(struct __ return __pyx_r; } -/* "pysam/libcfaidx.pyx":332 +/* "pysam/libcfaidx.pyx":367 * property sequence: * """The sequence of each entry in the fastq file.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -6125,9 +5812,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_8sequence___get__(struc __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 332, 0, __PYX_ERR(0, 332, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 367, 0, __PYX_ERR(0, 367, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":333 + /* "pysam/libcfaidx.pyx":368 * """The sequence of each entry in the fastq file.""" * def __get__(self): * return charptr_to_str(self._delegate.seq.s) # <<<<<<<<<<<<<< @@ -6135,13 +5822,13 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_8sequence___get__(struc * property comment: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_self->_delegate->seq.s, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 333, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_self->_delegate->seq.s, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 368, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":332 + /* "pysam/libcfaidx.pyx":367 * property sequence: * """The sequence of each entry in the fastq file.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -6161,7 +5848,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_8sequence___get__(struc return __pyx_r; } -/* "pysam/libcfaidx.pyx":336 +/* "pysam/libcfaidx.pyx":371 * * property comment: * def __get__(self): # <<<<<<<<<<<<<< @@ -6189,9 +5876,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_7comment___get__(struct int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 336, 0, __PYX_ERR(0, 336, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 371, 0, __PYX_ERR(0, 371, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":337 + /* "pysam/libcfaidx.pyx":372 * property comment: * def __get__(self): * if self._delegate.comment.l: # <<<<<<<<<<<<<< @@ -6201,7 +5888,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_7comment___get__(struct __pyx_t_1 = (__pyx_v_self->_delegate->comment.l != 0); if (__pyx_t_1) { - /* "pysam/libcfaidx.pyx":338 + /* "pysam/libcfaidx.pyx":373 * def __get__(self): * if self._delegate.comment.l: * return charptr_to_str(self._delegate.comment.s) # <<<<<<<<<<<<<< @@ -6209,13 +5896,13 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_7comment___get__(struct * return None */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_self->_delegate->comment.s, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 338, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_self->_delegate->comment.s, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 373, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":337 + /* "pysam/libcfaidx.pyx":372 * property comment: * def __get__(self): * if self._delegate.comment.l: # <<<<<<<<<<<<<< @@ -6224,7 +5911,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_7comment___get__(struct */ } - /* "pysam/libcfaidx.pyx":340 + /* "pysam/libcfaidx.pyx":375 * return charptr_to_str(self._delegate.comment.s) * else: * return None # <<<<<<<<<<<<<< @@ -6237,7 +5924,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_7comment___get__(struct goto __pyx_L0; } - /* "pysam/libcfaidx.pyx":336 + /* "pysam/libcfaidx.pyx":371 * * property comment: * def __get__(self): # <<<<<<<<<<<<<< @@ -6257,7 +5944,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_7comment___get__(struct return __pyx_r; } -/* "pysam/libcfaidx.pyx":344 +/* "pysam/libcfaidx.pyx":379 * property quality: * """The quality score of each entry in the fastq file, represented as a string.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -6285,9 +5972,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_7quality___get__(struct int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 344, 0, __PYX_ERR(0, 344, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 379, 0, __PYX_ERR(0, 379, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":345 + /* "pysam/libcfaidx.pyx":380 * """The quality score of each entry in the fastq file, represented as a string.""" * def __get__(self): * if self._delegate.qual.l: # <<<<<<<<<<<<<< @@ -6297,7 +5984,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_7quality___get__(struct __pyx_t_1 = (__pyx_v_self->_delegate->qual.l != 0); if (__pyx_t_1) { - /* "pysam/libcfaidx.pyx":346 + /* "pysam/libcfaidx.pyx":381 * def __get__(self): * if self._delegate.qual.l: * return charptr_to_str(self._delegate.qual.s) # <<<<<<<<<<<<<< @@ -6305,13 +5992,13 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_7quality___get__(struct * return None */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_self->_delegate->qual.s, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 346, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_self->_delegate->qual.s, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":345 + /* "pysam/libcfaidx.pyx":380 * """The quality score of each entry in the fastq file, represented as a string.""" * def __get__(self): * if self._delegate.qual.l: # <<<<<<<<<<<<<< @@ -6320,12 +6007,12 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_7quality___get__(struct */ } - /* "pysam/libcfaidx.pyx":348 + /* "pysam/libcfaidx.pyx":383 * return charptr_to_str(self._delegate.qual.s) * else: * return None # <<<<<<<<<<<<<< * - * cdef cython.str tostring(self): + * cdef cython.str to_string(self): */ /*else*/ { __Pyx_XDECREF(__pyx_r); @@ -6333,7 +6020,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_7quality___get__(struct goto __pyx_L0; } - /* "pysam/libcfaidx.pyx":344 + /* "pysam/libcfaidx.pyx":379 * property quality: * """The quality score of each entry in the fastq file, represented as a string.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -6353,15 +6040,15 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_7quality___get__(struct return __pyx_r; } -/* "pysam/libcfaidx.pyx":350 +/* "pysam/libcfaidx.pyx":385 * return None * - * cdef cython.str tostring(self): # <<<<<<<<<<<<<< + * cdef cython.str to_string(self): # <<<<<<<<<<<<<< * if self.comment is None: * comment = "" */ -static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_self) { +static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_to_string(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_self) { PyObject *__pyx_v_comment = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations @@ -6372,25 +6059,25 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_ob PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; - __Pyx_RefNannySetupContext("tostring", 0); - __Pyx_TraceCall("tostring", __pyx_f[0], 350, 0, __PYX_ERR(0, 350, __pyx_L1_error)); + __Pyx_RefNannySetupContext("to_string", 0); + __Pyx_TraceCall("to_string", __pyx_f[0], 385, 0, __PYX_ERR(0, 385, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":351 + /* "pysam/libcfaidx.pyx":386 * - * cdef cython.str tostring(self): + * cdef cython.str to_string(self): * if self.comment is None: # <<<<<<<<<<<<<< * comment = "" * else: */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_comment); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 351, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_comment); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 386, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = (__pyx_t_1 == Py_None); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = (__pyx_t_2 != 0); if (__pyx_t_3) { - /* "pysam/libcfaidx.pyx":352 - * cdef cython.str tostring(self): + /* "pysam/libcfaidx.pyx":387 + * cdef cython.str to_string(self): * if self.comment is None: * comment = "" # <<<<<<<<<<<<<< * else: @@ -6399,9 +6086,9 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_ob __Pyx_INCREF(__pyx_kp_s__5); __pyx_v_comment = __pyx_kp_s__5; - /* "pysam/libcfaidx.pyx":351 + /* "pysam/libcfaidx.pyx":386 * - * cdef cython.str tostring(self): + * cdef cython.str to_string(self): * if self.comment is None: # <<<<<<<<<<<<<< * comment = "" * else: @@ -6409,7 +6096,7 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_ob goto __pyx_L3; } - /* "pysam/libcfaidx.pyx":354 + /* "pysam/libcfaidx.pyx":389 * comment = "" * else: * comment = " %s" % self.comment # <<<<<<<<<<<<<< @@ -6417,9 +6104,9 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_ob * if self.quality is None: */ /*else*/ { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_comment); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 354, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_comment); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 389, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 354, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 389, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_comment = __pyx_t_4; @@ -6427,21 +6114,21 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_ob } __pyx_L3:; - /* "pysam/libcfaidx.pyx":356 + /* "pysam/libcfaidx.pyx":391 * comment = " %s" % self.comment * * if self.quality is None: # <<<<<<<<<<<<<< * return ">%s%s\n%s" % (self.name, comment, self.sequence) * else: */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_quality); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 356, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_quality); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 391, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = (__pyx_t_4 == Py_None); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_2 = (__pyx_t_3 != 0); if (__pyx_t_2) { - /* "pysam/libcfaidx.pyx":357 + /* "pysam/libcfaidx.pyx":392 * * if self.quality is None: * return ">%s%s\n%s" % (self.name, comment, self.sequence) # <<<<<<<<<<<<<< @@ -6449,11 +6136,11 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_ob * return "@%s%s\n%s\n+\n%s" % (self.name, comment, */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 357, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 392, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 357, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 392, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 357, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 392, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); @@ -6464,15 +6151,15 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_ob PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_1); __pyx_t_4 = 0; __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s_s_s, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 357, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s_s_s, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 392, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (!(likely(PyString_CheckExact(__pyx_t_1))||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 357, __pyx_L1_error) + if (!(likely(PyString_CheckExact(__pyx_t_1))||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 392, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":356 + /* "pysam/libcfaidx.pyx":391 * comment = " %s" % self.comment * * if self.quality is None: # <<<<<<<<<<<<<< @@ -6481,7 +6168,7 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_ob */ } - /* "pysam/libcfaidx.pyx":359 + /* "pysam/libcfaidx.pyx":394 * return ">%s%s\n%s" % (self.name, comment, self.sequence) * else: * return "@%s%s\n%s\n+\n%s" % (self.name, comment, # <<<<<<<<<<<<<< @@ -6490,29 +6177,29 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_ob */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 359, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 394, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libcfaidx.pyx":360 + /* "pysam/libcfaidx.pyx":395 * else: * return "@%s%s\n%s\n+\n%s" % (self.name, comment, * self.sequence, self.quality) # <<<<<<<<<<<<<< * - * def __str__(self): + * cdef cython.str tostring(self): */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sequence); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 360, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sequence); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 395, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_quality); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 360, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_quality); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 395, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libcfaidx.pyx":359 + /* "pysam/libcfaidx.pyx":394 * return ">%s%s\n%s" % (self.name, comment, self.sequence) * else: * return "@%s%s\n%s\n+\n%s" % (self.name, comment, # <<<<<<<<<<<<<< * self.sequence, self.quality) * */ - __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 359, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 394, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); @@ -6526,19 +6213,19 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_ob __pyx_t_1 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s_s_s_s, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 359, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s_s_s_s, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 394, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (!(likely(PyString_CheckExact(__pyx_t_4))||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 359, __pyx_L1_error) + if (!(likely(PyString_CheckExact(__pyx_t_4))||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 394, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L0; } - /* "pysam/libcfaidx.pyx":350 + /* "pysam/libcfaidx.pyx":385 * return None * - * cdef cython.str tostring(self): # <<<<<<<<<<<<<< + * cdef cython.str to_string(self): # <<<<<<<<<<<<<< * if self.comment is None: * comment = "" */ @@ -6549,7 +6236,7 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_ob __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libcfaidx.FastqProxy.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastqProxy.to_string", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_comment); @@ -6559,54 +6246,104 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_ob return __pyx_r; } -/* "pysam/libcfaidx.pyx":362 +/* "pysam/libcfaidx.pyx":397 * self.sequence, self.quality) * - * def __str__(self): # <<<<<<<<<<<<<< - * return self.tostring() - * + * cdef cython.str tostring(self): # <<<<<<<<<<<<<< + * """deprecated : use :meth:`to_string`""" + * return self.to_string() */ -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libcfaidx_10FastqProxy_3__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_9libcfaidx_10FastqProxy_3__str__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_10FastqProxy_2__str__(((struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_2__str__(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_self) { +static PyObject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__str__", 0); - __Pyx_TraceCall("__str__", __pyx_f[0], 362, 0, __PYX_ERR(0, 362, __pyx_L1_error)); + __Pyx_RefNannySetupContext("tostring", 0); + __Pyx_TraceCall("tostring", __pyx_f[0], 397, 0, __PYX_ERR(0, 397, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":363 + /* "pysam/libcfaidx.pyx":399 + * cdef cython.str tostring(self): + * """deprecated : use :meth:`to_string`""" + * return self.to_string() # <<<<<<<<<<<<<< * * def __str__(self): - * return self.tostring() # <<<<<<<<<<<<<< - * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy *)__pyx_v_self->__pyx_vtab)->to_string(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcfaidx.pyx":397 + * self.sequence, self.quality) + * + * cdef cython.str tostring(self): # <<<<<<<<<<<<<< + * """deprecated : use :meth:`to_string`""" + * return self.to_string() + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcfaidx.FastqProxy.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcfaidx.pyx":401 + * return self.to_string() + * + * def __str__(self): # <<<<<<<<<<<<<< + * return self.to_string() + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libcfaidx_10FastqProxy_3__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_9libcfaidx_10FastqProxy_3__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_10FastqProxy_2__str__(((struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_2__str__(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__str__", 0); + __Pyx_TraceCall("__str__", __pyx_f[0], 401, 0, __PYX_ERR(0, 401, __pyx_L1_error)); + + /* "pysam/libcfaidx.pyx":402 + * + * def __str__(self): + * return self.to_string() # <<<<<<<<<<<<<< + * * cpdef array.array get_quality_array(self, int offset=33): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy *)__pyx_v_self->__pyx_vtab)->tostring(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 363, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy *)__pyx_v_self->__pyx_vtab)->to_string(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 402, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":362 - * self.sequence, self.quality) + /* "pysam/libcfaidx.pyx":401 + * return self.to_string() * * def __str__(self): # <<<<<<<<<<<<<< - * return self.tostring() + * return self.to_string() * */ @@ -6622,8 +6359,8 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_2__str__(struct __pyx_o return __pyx_r; } -/* "pysam/libcfaidx.pyx":365 - * return self.tostring() +/* "pysam/libcfaidx.pyx":404 + * return self.to_string() * * cpdef array.array get_quality_array(self, int offset=33): # <<<<<<<<<<<<<< * '''return quality values as integer array after subtracting offset.''' @@ -6646,7 +6383,7 @@ static arrayobject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_get_quality_array(str int __pyx_t_8; struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array __pyx_t_9; __Pyx_RefNannySetupContext("get_quality_array", 0); - __Pyx_TraceCall("get_quality_array", __pyx_f[0], 365, 0, __PYX_ERR(0, 365, __pyx_L1_error)); + __Pyx_TraceCall("get_quality_array", __pyx_f[0], 404, 0, __PYX_ERR(0, 404, __pyx_L1_error)); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_offset = __pyx_optional_args->offset; @@ -6656,11 +6393,11 @@ static arrayobject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_get_quality_array(str if (unlikely(__pyx_skip_dispatch)) ; /* Check if overridden in Python */ else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_quality_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 365, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_quality_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_9libcfaidx_10FastqProxy_5get_quality_array)) { __Pyx_XDECREF(((PyObject *)__pyx_r)); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 365, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL; @@ -6674,14 +6411,14 @@ static arrayobject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_get_quality_array(str } } if (!__pyx_t_5) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 365, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 365, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -6690,26 +6427,26 @@ static arrayobject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_get_quality_array(str #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 365, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 365, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_3); __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 365, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 365, __pyx_L1_error) + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 404, __pyx_L1_error) __pyx_r = ((arrayobject *)__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -6718,21 +6455,21 @@ static arrayobject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_get_quality_array(str __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - /* "pysam/libcfaidx.pyx":367 + /* "pysam/libcfaidx.pyx":406 * cpdef array.array get_quality_array(self, int offset=33): * '''return quality values as integer array after subtracting offset.''' * if self.quality is None: # <<<<<<<<<<<<<< * return None * return qualitystring_to_array(force_bytes(self.quality), */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 367, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = (__pyx_t_1 == Py_None); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_8 = (__pyx_t_7 != 0); if (__pyx_t_8) { - /* "pysam/libcfaidx.pyx":368 + /* "pysam/libcfaidx.pyx":407 * '''return quality values as integer array after subtracting offset.''' * if self.quality is None: * return None # <<<<<<<<<<<<<< @@ -6743,7 +6480,7 @@ static arrayobject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_get_quality_array(str __pyx_r = ((arrayobject *)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcfaidx.pyx":367 + /* "pysam/libcfaidx.pyx":406 * cpdef array.array get_quality_array(self, int offset=33): * '''return quality values as integer array after subtracting offset.''' * if self.quality is None: # <<<<<<<<<<<<<< @@ -6752,7 +6489,7 @@ static arrayobject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_get_quality_array(str */ } - /* "pysam/libcfaidx.pyx":369 + /* "pysam/libcfaidx.pyx":408 * if self.quality is None: * return None * return qualitystring_to_array(force_bytes(self.quality), # <<<<<<<<<<<<<< @@ -6760,30 +6497,30 @@ static arrayobject *__pyx_f_5pysam_9libcfaidx_10FastqProxy_get_quality_array(str * */ __Pyx_XDECREF(((PyObject *)__pyx_r)); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 369, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 408, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 369, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 408, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcfaidx.pyx":370 + /* "pysam/libcfaidx.pyx":409 * return None * return qualitystring_to_array(force_bytes(self.quality), * offset=offset) # <<<<<<<<<<<<<< * - * cdef class PersistentFastqProxy: + * cdef class FastxRecord: */ __pyx_t_9.__pyx_n = 1; __pyx_t_9.offset = __pyx_v_offset; - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9libcutils_qualitystring_to_array(__pyx_t_2, 0, &__pyx_t_9)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 369, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9libcutils_qualitystring_to_array(__pyx_t_2, 0, &__pyx_t_9)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 408, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = ((arrayobject *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":365 - * return self.tostring() + /* "pysam/libcfaidx.pyx":404 + * return self.to_string() * * cpdef array.array get_quality_array(self, int offset=33): # <<<<<<<<<<<<<< * '''return quality values as integer array after subtracting offset.''' @@ -6836,7 +6573,7 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_10FastqProxy_5get_quality_array(PyOb } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_quality_array") < 0)) __PYX_ERR(0, 365, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_quality_array") < 0)) __PYX_ERR(0, 404, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -6847,14 +6584,14 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_10FastqProxy_5get_quality_array(PyOb } } if (values[0]) { - __pyx_v_offset = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 365, __pyx_L3_error) + __pyx_v_offset = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 404, __pyx_L3_error) } else { __pyx_v_offset = ((int)33); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_quality_array", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 365, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get_quality_array", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 404, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcfaidx.FastqProxy.get_quality_array", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -6874,11 +6611,11 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_4get_quality_array(stru PyObject *__pyx_t_1 = NULL; struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array __pyx_t_2; __Pyx_RefNannySetupContext("get_quality_array", 0); - __Pyx_TraceCall("get_quality_array (wrapper)", __pyx_f[0], 365, 0, __PYX_ERR(0, 365, __pyx_L1_error)); + __Pyx_TraceCall("get_quality_array (wrapper)", __pyx_f[0], 404, 0, __PYX_ERR(0, 404, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.offset = __pyx_v_offset; - __pyx_t_1 = ((PyObject *)__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy->get_quality_array(__pyx_v_self, 1, &__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 365, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy->get_quality_array(__pyx_v_self, 1, &__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -6930,7 +6667,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_6__reduce_cython__(CYTH * def __setstate_cython__(self, __pyx_state): * raise TypeError("self._delegate cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -6987,7 +6724,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_8__setstate_cython__(CY * def __setstate_cython__(self, __pyx_state): * raise TypeError("self._delegate cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -7011,28 +6748,85 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_10FastqProxy_8__setstate_cython__(CY return __pyx_r; } -/* "pysam/libcfaidx.pyx":377 - * Needed to compare multiple fastq records from the same file. +/* "pysam/libcfaidx.pyx":418 + * * """ - * def __init__(self, FastqProxy FastqRead): # <<<<<<<<<<<<<< - * self.comment = FastqRead.comment - * self.quality = FastqRead.quality + * def __init__(self, # <<<<<<<<<<<<<< + * name=None, + * comment=None, */ /* Python wrapper */ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_FastqRead = 0; +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_name = 0; + PyObject *__pyx_v_comment = 0; + PyObject *__pyx_v_sequence = 0; + PyObject *__pyx_v_quality = 0; + struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_proxy = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_FastqRead,0}; - PyObject* values[1] = {0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,&__pyx_n_s_comment,&__pyx_n_s_sequence,&__pyx_n_s_quality,&__pyx_n_s_proxy,0}; + PyObject* values[5] = {0,0,0,0,0}; + + /* "pysam/libcfaidx.pyx":419 + * """ + * def __init__(self, + * name=None, # <<<<<<<<<<<<<< + * comment=None, + * sequence=None, + */ + values[0] = ((PyObject *)Py_None); + + /* "pysam/libcfaidx.pyx":420 + * def __init__(self, + * name=None, + * comment=None, # <<<<<<<<<<<<<< + * sequence=None, + * quality=None, + */ + values[1] = ((PyObject *)Py_None); + + /* "pysam/libcfaidx.pyx":421 + * name=None, + * comment=None, + * sequence=None, # <<<<<<<<<<<<<< + * quality=None, + * FastqProxy proxy=None): + */ + values[2] = ((PyObject *)Py_None); + + /* "pysam/libcfaidx.pyx":422 + * comment=None, + * sequence=None, + * quality=None, # <<<<<<<<<<<<<< + * FastqProxy proxy=None): + * if proxy is not None: + */ + values[3] = ((PyObject *)Py_None); + + /* "pysam/libcfaidx.pyx":423 + * sequence=None, + * quality=None, + * FastqProxy proxy=None): # <<<<<<<<<<<<<< + * if proxy is not None: + * self.comment = proxy.comment + */ + values[4] = (PyObject *)((struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; @@ -7041,29 +6835,78 @@ static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_1__init__(PyObject kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_FastqRead)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name); + if (value) { values[0] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_comment); + if (value) { values[1] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sequence); + if (value) { values[2] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quality); + if (value) { values[3] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 4: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_proxy); + if (value) { values[4] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 377, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 418, __pyx_L3_error) } - } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { - goto __pyx_L5_argtuple_error; } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } } - __pyx_v_FastqRead = ((struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *)values[0]); + __pyx_v_name = values[0]; + __pyx_v_comment = values[1]; + __pyx_v_sequence = values[2]; + __pyx_v_quality = values[3]; + __pyx_v_proxy = ((struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *)values[4]); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 377, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 418, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_FastqRead), __pyx_ptype_5pysam_9libcfaidx_FastqProxy, 1, "FastqRead", 0))) __PYX_ERR(0, 377, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy___init__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self), __pyx_v_FastqRead); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_proxy), __pyx_ptype_5pysam_9libcfaidx_FastqProxy, 1, "proxy", 0))) __PYX_ERR(0, 423, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord___init__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self), __pyx_v_name, __pyx_v_comment, __pyx_v_sequence, __pyx_v_quality, __pyx_v_proxy); + + /* "pysam/libcfaidx.pyx":418 + * + * """ + * def __init__(self, # <<<<<<<<<<<<<< + * name=None, + * comment=None, + */ /* function exit code */ goto __pyx_L0; @@ -7074,92 +6917,182 @@ static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_1__init__(PyObject return __pyx_r; } -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy___init__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_FastqRead) { +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord___init__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_comment, PyObject *__pyx_v_sequence, PyObject *__pyx_v_quality, struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *__pyx_v_proxy) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 377, 0, __PYX_ERR(0, 377, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 418, 0, __PYX_ERR(0, 418, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":378 - * """ - * def __init__(self, FastqProxy FastqRead): - * self.comment = FastqRead.comment # <<<<<<<<<<<<<< - * self.quality = FastqRead.quality - * self.sequence = FastqRead.sequence + /* "pysam/libcfaidx.pyx":424 + * quality=None, + * FastqProxy proxy=None): + * if proxy is not None: # <<<<<<<<<<<<<< + * self.comment = proxy.comment + * self.quality = proxy.quality */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_FastqRead), __pyx_n_s_comment); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 378, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 378, __pyx_L1_error) - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->comment); - __Pyx_DECREF(__pyx_v_self->comment); - __pyx_v_self->comment = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_1 = (((PyObject *)__pyx_v_proxy) != Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { - /* "pysam/libcfaidx.pyx":379 - * def __init__(self, FastqProxy FastqRead): - * self.comment = FastqRead.comment - * self.quality = FastqRead.quality # <<<<<<<<<<<<<< - * self.sequence = FastqRead.sequence - * self.name = FastqRead.name + /* "pysam/libcfaidx.pyx":425 + * FastqProxy proxy=None): + * if proxy is not None: + * self.comment = proxy.comment # <<<<<<<<<<<<<< + * self.quality = proxy.quality + * self.sequence = proxy.sequence */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_FastqRead), __pyx_n_s_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 379, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 379, __pyx_L1_error) - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->quality); - __Pyx_DECREF(__pyx_v_self->quality); - __pyx_v_self->quality = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_proxy), __pyx_n_s_comment); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 425, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(PyString_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 425, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->comment); + __Pyx_DECREF(__pyx_v_self->comment); + __pyx_v_self->comment = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcfaidx.pyx":380 - * self.comment = FastqRead.comment - * self.quality = FastqRead.quality - * self.sequence = FastqRead.sequence # <<<<<<<<<<<<<< - * self.name = FastqRead.name + /* "pysam/libcfaidx.pyx":426 + * if proxy is not None: + * self.comment = proxy.comment + * self.quality = proxy.quality # <<<<<<<<<<<<<< + * self.sequence = proxy.sequence + * self.name = proxy.name + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_proxy), __pyx_n_s_quality); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 426, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(PyString_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 426, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->quality); + __Pyx_DECREF(__pyx_v_self->quality); + __pyx_v_self->quality = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcfaidx.pyx":427 + * self.comment = proxy.comment + * self.quality = proxy.quality + * self.sequence = proxy.sequence # <<<<<<<<<<<<<< + * self.name = proxy.name + * else: + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_proxy), __pyx_n_s_sequence); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(PyString_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 427, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->sequence); + __Pyx_DECREF(__pyx_v_self->sequence); + __pyx_v_self->sequence = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcfaidx.pyx":428 + * self.quality = proxy.quality + * self.sequence = proxy.sequence + * self.name = proxy.name # <<<<<<<<<<<<<< + * else: + * self.comment = comment + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_proxy), __pyx_n_s_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 428, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(PyString_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 428, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->name); + __Pyx_DECREF(__pyx_v_self->name); + __pyx_v_self->name = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcfaidx.pyx":424 + * quality=None, + * FastqProxy proxy=None): + * if proxy is not None: # <<<<<<<<<<<<<< + * self.comment = proxy.comment + * self.quality = proxy.quality + */ + goto __pyx_L3; + } + + /* "pysam/libcfaidx.pyx":430 + * self.name = proxy.name + * else: + * self.comment = comment # <<<<<<<<<<<<<< + * self.quality = quality + * self.sequence = sequence + */ + /*else*/ { + if (!(likely(PyString_CheckExact(__pyx_v_comment))||((__pyx_v_comment) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_comment)->tp_name), 0))) __PYX_ERR(0, 430, __pyx_L1_error) + __pyx_t_3 = __pyx_v_comment; + __Pyx_INCREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->comment); + __Pyx_DECREF(__pyx_v_self->comment); + __pyx_v_self->comment = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcfaidx.pyx":431 + * else: + * self.comment = comment + * self.quality = quality # <<<<<<<<<<<<<< + * self.sequence = sequence + * self.name = name + */ + if (!(likely(PyString_CheckExact(__pyx_v_quality))||((__pyx_v_quality) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_quality)->tp_name), 0))) __PYX_ERR(0, 431, __pyx_L1_error) + __pyx_t_3 = __pyx_v_quality; + __Pyx_INCREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->quality); + __Pyx_DECREF(__pyx_v_self->quality); + __pyx_v_self->quality = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcfaidx.pyx":432 + * self.comment = comment + * self.quality = quality + * self.sequence = sequence # <<<<<<<<<<<<<< + * self.name = name * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_FastqRead), __pyx_n_s_sequence); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->sequence); - __Pyx_DECREF(__pyx_v_self->sequence); - __pyx_v_self->sequence = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + if (!(likely(PyString_CheckExact(__pyx_v_sequence))||((__pyx_v_sequence) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_sequence)->tp_name), 0))) __PYX_ERR(0, 432, __pyx_L1_error) + __pyx_t_3 = __pyx_v_sequence; + __Pyx_INCREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->sequence); + __Pyx_DECREF(__pyx_v_self->sequence); + __pyx_v_self->sequence = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcfaidx.pyx":381 - * self.quality = FastqRead.quality - * self.sequence = FastqRead.sequence - * self.name = FastqRead.name # <<<<<<<<<<<<<< + /* "pysam/libcfaidx.pyx":433 + * self.quality = quality + * self.sequence = sequence + * self.name = name # <<<<<<<<<<<<<< * - * cdef cython.str tostring(self): + * def __copy__(self): */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_FastqRead), __pyx_n_s_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 381, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 381, __pyx_L1_error) - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->name); - __Pyx_DECREF(__pyx_v_self->name); - __pyx_v_self->name = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + if (!(likely(PyString_CheckExact(__pyx_v_name))||((__pyx_v_name) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_name)->tp_name), 0))) __PYX_ERR(0, 433, __pyx_L1_error) + __pyx_t_3 = __pyx_v_name; + __Pyx_INCREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->name); + __Pyx_DECREF(__pyx_v_self->name); + __pyx_v_self->name = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + } + __pyx_L3:; - /* "pysam/libcfaidx.pyx":377 - * Needed to compare multiple fastq records from the same file. + /* "pysam/libcfaidx.pyx":418 + * * """ - * def __init__(self, FastqProxy FastqRead): # <<<<<<<<<<<<<< - * self.comment = FastqRead.comment - * self.quality = FastqRead.quality + * def __init__(self, # <<<<<<<<<<<<<< + * name=None, + * comment=None, */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -7167,58 +7100,286 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy___init__(struct __p return __pyx_r; } -/* "pysam/libcfaidx.pyx":383 - * self.name = FastqRead.name +/* "pysam/libcfaidx.pyx":435 + * self.name = name + * + * def __copy__(self): # <<<<<<<<<<<<<< + * return FastxRecord(self.name, self.comment, self.sequence, self.quality) * - * cdef cython.str tostring(self): # <<<<<<<<<<<<<< - * if self.comment is None: - * comment = "" */ -static PyObject *__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_tostring(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self) { - PyObject *__pyx_v_comment = NULL; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_3__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_9libcfaidx_11FastxRecord_2__copy__[] = "FastxRecord.__copy__(self)"; +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_3__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__copy__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_2__copy__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_2__copy__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannySetupContext("tostring", 0); - __Pyx_TraceCall("tostring", __pyx_f[0], 383, 0, __PYX_ERR(0, 383, __pyx_L1_error)); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__copy__", 0); + __Pyx_TraceCall("__copy__", __pyx_f[0], 435, 0, __PYX_ERR(0, 435, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":384 + /* "pysam/libcfaidx.pyx":436 * - * cdef cython.str tostring(self): - * if self.comment is None: # <<<<<<<<<<<<<< - * comment = "" - * else: + * def __copy__(self): + * return FastxRecord(self.name, self.comment, self.sequence, self.quality) # <<<<<<<<<<<<<< + * + * def __deepcopy__(self, memo): */ - __pyx_t_1 = (__pyx_v_self->comment == ((PyObject*)Py_None)); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 436, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->name); + __Pyx_INCREF(__pyx_v_self->comment); + __Pyx_GIVEREF(__pyx_v_self->comment); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_self->comment); + __Pyx_INCREF(__pyx_v_self->sequence); + __Pyx_GIVEREF(__pyx_v_self->sequence); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_self->sequence); + __Pyx_INCREF(__pyx_v_self->quality); + __Pyx_GIVEREF(__pyx_v_self->quality); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_self->quality); + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_9libcfaidx_FastxRecord), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 436, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libcfaidx.pyx":385 - * cdef cython.str tostring(self): - * if self.comment is None: - * comment = "" # <<<<<<<<<<<<<< - * else: - * comment = " %s" % self.comment + /* "pysam/libcfaidx.pyx":435 + * self.name = name + * + * def __copy__(self): # <<<<<<<<<<<<<< + * return FastxRecord(self.name, self.comment, self.sequence, self.quality) + * */ - __Pyx_INCREF(__pyx_kp_s__5); - __pyx_v_comment = __pyx_kp_s__5; - /* "pysam/libcfaidx.pyx":384 - * - * cdef cython.str tostring(self): + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.__copy__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcfaidx.pyx":438 + * return FastxRecord(self.name, self.comment, self.sequence, self.quality) + * + * def __deepcopy__(self, memo): # <<<<<<<<<<<<<< + * return FastxRecord(self.name, self.comment, self.sequence, self.quality) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_5__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo); /*proto*/ +static char __pyx_doc_5pysam_9libcfaidx_11FastxRecord_4__deepcopy__[] = "FastxRecord.__deepcopy__(self, memo)"; +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_5__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__deepcopy__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_4__deepcopy__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self), ((PyObject *)__pyx_v_memo)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_4__deepcopy__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__deepcopy__", 0); + __Pyx_TraceCall("__deepcopy__", __pyx_f[0], 438, 0, __PYX_ERR(0, 438, __pyx_L1_error)); + + /* "pysam/libcfaidx.pyx":439 + * + * def __deepcopy__(self, memo): + * return FastxRecord(self.name, self.comment, self.sequence, self.quality) # <<<<<<<<<<<<<< + * + * cdef cython.str to_string(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->name); + __Pyx_INCREF(__pyx_v_self->comment); + __Pyx_GIVEREF(__pyx_v_self->comment); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_self->comment); + __Pyx_INCREF(__pyx_v_self->sequence); + __Pyx_GIVEREF(__pyx_v_self->sequence); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_self->sequence); + __Pyx_INCREF(__pyx_v_self->quality); + __Pyx_GIVEREF(__pyx_v_self->quality); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_self->quality); + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_9libcfaidx_FastxRecord), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libcfaidx.pyx":438 + * return FastxRecord(self.name, self.comment, self.sequence, self.quality) + * + * def __deepcopy__(self, memo): # <<<<<<<<<<<<<< + * return FastxRecord(self.name, self.comment, self.sequence, self.quality) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.__deepcopy__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcfaidx.pyx":441 + * return FastxRecord(self.name, self.comment, self.sequence, self.quality) + * + * cdef cython.str to_string(self): # <<<<<<<<<<<<<< + * if self.name is None: + * raise ValueError("can not write record without name") + */ + +static PyObject *__pyx_f_5pysam_9libcfaidx_11FastxRecord_to_string(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { + PyObject *__pyx_v_comment = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("to_string", 0); + __Pyx_TraceCall("to_string", __pyx_f[0], 441, 0, __PYX_ERR(0, 441, __pyx_L1_error)); + + /* "pysam/libcfaidx.pyx":442 + * + * cdef cython.str to_string(self): + * if self.name is None: # <<<<<<<<<<<<<< + * raise ValueError("can not write record without name") + * + */ + __pyx_t_1 = (__pyx_v_self->name == ((PyObject*)Py_None)); + __pyx_t_2 = (__pyx_t_1 != 0); + if (unlikely(__pyx_t_2)) { + + /* "pysam/libcfaidx.pyx":443 + * cdef cython.str to_string(self): + * if self.name is None: + * raise ValueError("can not write record without name") # <<<<<<<<<<<<<< + * + * if self.sequence is None: + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 443, __pyx_L1_error) + + /* "pysam/libcfaidx.pyx":442 + * + * cdef cython.str to_string(self): + * if self.name is None: # <<<<<<<<<<<<<< + * raise ValueError("can not write record without name") + * + */ + } + + /* "pysam/libcfaidx.pyx":445 + * raise ValueError("can not write record without name") + * + * if self.sequence is None: # <<<<<<<<<<<<<< + * raise ValueError("can not write record without a sequence") + * + */ + __pyx_t_2 = (__pyx_v_self->sequence == ((PyObject*)Py_None)); + __pyx_t_1 = (__pyx_t_2 != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libcfaidx.pyx":446 + * + * if self.sequence is None: + * raise ValueError("can not write record without a sequence") # <<<<<<<<<<<<<< + * + * if self.comment is None: + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 446, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 446, __pyx_L1_error) + + /* "pysam/libcfaidx.pyx":445 + * raise ValueError("can not write record without name") + * + * if self.sequence is None: # <<<<<<<<<<<<<< + * raise ValueError("can not write record without a sequence") + * + */ + } + + /* "pysam/libcfaidx.pyx":448 + * raise ValueError("can not write record without a sequence") + * * if self.comment is None: # <<<<<<<<<<<<<< * comment = "" * else: */ - goto __pyx_L3; + __pyx_t_1 = (__pyx_v_self->comment == ((PyObject*)Py_None)); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "pysam/libcfaidx.pyx":449 + * + * if self.comment is None: + * comment = "" # <<<<<<<<<<<<<< + * else: + * comment = " %s" % self.comment + */ + __Pyx_INCREF(__pyx_kp_s__5); + __pyx_v_comment = __pyx_kp_s__5; + + /* "pysam/libcfaidx.pyx":448 + * raise ValueError("can not write record without a sequence") + * + * if self.comment is None: # <<<<<<<<<<<<<< + * comment = "" + * else: + */ + goto __pyx_L5; } - /* "pysam/libcfaidx.pyx":387 + /* "pysam/libcfaidx.pyx":451 * comment = "" * else: * comment = " %s" % self.comment # <<<<<<<<<<<<<< @@ -7226,14 +7387,14 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_tostring(struc * if self.quality is None: */ /*else*/ { - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_v_self->comment); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 387, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_v_self->comment); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 451, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_comment = __pyx_t_3; __pyx_t_3 = 0; } - __pyx_L3:; + __pyx_L5:; - /* "pysam/libcfaidx.pyx":389 + /* "pysam/libcfaidx.pyx":453 * comment = " %s" % self.comment * * if self.quality is None: # <<<<<<<<<<<<<< @@ -7244,7 +7405,7 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_tostring(struc __pyx_t_1 = (__pyx_t_2 != 0); if (__pyx_t_1) { - /* "pysam/libcfaidx.pyx":390 + /* "pysam/libcfaidx.pyx":454 * * if self.quality is None: * return ">%s%s\n%s" % (self.name, comment, self.sequence) # <<<<<<<<<<<<<< @@ -7252,7 +7413,7 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_tostring(struc * return "@%s%s\n%s\n+\n%s" % (self.name, comment, */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 390, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 454, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_self->name); __Pyx_GIVEREF(__pyx_v_self->name); @@ -7263,15 +7424,15 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_tostring(struc __Pyx_INCREF(__pyx_v_self->sequence); __Pyx_GIVEREF(__pyx_v_self->sequence); PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_self->sequence); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s_s_s, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 390, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s_s_s, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 454, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(PyString_CheckExact(__pyx_t_4))||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 390, __pyx_L1_error) + if (!(likely(PyString_CheckExact(__pyx_t_4))||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 454, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":389 + /* "pysam/libcfaidx.pyx":453 * comment = " %s" % self.comment * * if self.quality is None: # <<<<<<<<<<<<<< @@ -7280,7 +7441,7 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_tostring(struc */ } - /* "pysam/libcfaidx.pyx":392 + /* "pysam/libcfaidx.pyx":456 * return ">%s%s\n%s" % (self.name, comment, self.sequence) * else: * return "@%s%s\n%s\n+\n%s" % (self.name, comment, # <<<<<<<<<<<<<< @@ -7290,14 +7451,14 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_tostring(struc /*else*/ { __Pyx_XDECREF(__pyx_r); - /* "pysam/libcfaidx.pyx":393 + /* "pysam/libcfaidx.pyx":457 * else: * return "@%s%s\n%s\n+\n%s" % (self.name, comment, * self.sequence, self.quality) # <<<<<<<<<<<<<< * - * def __str__(self): + * cdef cython.str tostring(self): */ - __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 392, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 456, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_self->name); __Pyx_GIVEREF(__pyx_v_self->name); @@ -7312,35 +7473,35 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_tostring(struc __Pyx_GIVEREF(__pyx_v_self->quality); PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_self->quality); - /* "pysam/libcfaidx.pyx":392 + /* "pysam/libcfaidx.pyx":456 * return ">%s%s\n%s" % (self.name, comment, self.sequence) * else: * return "@%s%s\n%s\n+\n%s" % (self.name, comment, # <<<<<<<<<<<<<< * self.sequence, self.quality) * */ - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_s_s_s_s, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 392, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_s_s_s_s, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 456, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!(likely(PyString_CheckExact(__pyx_t_3))||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 392, __pyx_L1_error) + if (!(likely(PyString_CheckExact(__pyx_t_3))||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 456, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; } - /* "pysam/libcfaidx.pyx":383 - * self.name = FastqRead.name + /* "pysam/libcfaidx.pyx":441 + * return FastxRecord(self.name, self.comment, self.sequence, self.quality) * - * cdef cython.str tostring(self): # <<<<<<<<<<<<<< - * if self.comment is None: - * comment = "" + * cdef cython.str to_string(self): # <<<<<<<<<<<<<< + * if self.name is None: + * raise ValueError("can not write record without name") */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.to_string", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_comment); @@ -7350,61 +7511,151 @@ static PyObject *__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_tostring(struc return __pyx_r; } -/* "pysam/libcfaidx.pyx":395 +/* "pysam/libcfaidx.pyx":459 * self.sequence, self.quality) * - * def __str__(self): # <<<<<<<<<<<<<< - * return self.tostring() + * cdef cython.str tostring(self): # <<<<<<<<<<<<<< + * """deprecated : use :meth:`to_string`""" + * return self.to_string() + */ + +static PyObject *__pyx_f_5pysam_9libcfaidx_11FastxRecord_tostring(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("tostring", 0); + __Pyx_TraceCall("tostring", __pyx_f[0], 459, 0, __PYX_ERR(0, 459, __pyx_L1_error)); + + /* "pysam/libcfaidx.pyx":461 + * cdef cython.str tostring(self): + * """deprecated : use :meth:`to_string`""" + * return self.to_string() # <<<<<<<<<<<<<< + * + * def set_name(self, name): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self->__pyx_vtab)->to_string(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcfaidx.pyx":459 + * self.sequence, self.quality) + * + * cdef cython.str tostring(self): # <<<<<<<<<<<<<< + * """deprecated : use :meth:`to_string`""" + * return self.to_string() + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcfaidx.pyx":463 + * return self.to_string() * + * def set_name(self, name): # <<<<<<<<<<<<<< + * if name is None: + * raise ValueError("FastxRecord must have a name and not None") */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_3__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_3__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_7set_name(PyObject *__pyx_v_self, PyObject *__pyx_v_name); /*proto*/ +static char __pyx_doc_5pysam_9libcfaidx_11FastxRecord_6set_name[] = "FastxRecord.set_name(self, name)"; +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_7set_name(PyObject *__pyx_v_self, PyObject *__pyx_v_name) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_2__str__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("set_name (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_6set_name(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self), ((PyObject *)__pyx_v_name)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_2__str__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_6set_name(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_name) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__str__", 0); - __Pyx_TraceCall("__str__", __pyx_f[0], 395, 0, __PYX_ERR(0, 395, __pyx_L1_error)); + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("set_name", 0); + __Pyx_TraceCall("set_name", __pyx_f[0], 463, 0, __PYX_ERR(0, 463, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":396 + /* "pysam/libcfaidx.pyx":464 * - * def __str__(self): - * return self.tostring() # <<<<<<<<<<<<<< + * def set_name(self, name): + * if name is None: # <<<<<<<<<<<<<< + * raise ValueError("FastxRecord must have a name and not None") + * self.name = name + */ + __pyx_t_1 = (__pyx_v_name == Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (unlikely(__pyx_t_2)) { + + /* "pysam/libcfaidx.pyx":465 + * def set_name(self, name): + * if name is None: + * raise ValueError("FastxRecord must have a name and not None") # <<<<<<<<<<<<<< + * self.name = name * - * cpdef array.array get_quality_array(self, int offset=33): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self->__pyx_vtab)->tostring(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 396, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 465, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 465, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":395 - * self.sequence, self.quality) + /* "pysam/libcfaidx.pyx":464 * - * def __str__(self): # <<<<<<<<<<<<<< - * return self.tostring() + * def set_name(self, name): + * if name is None: # <<<<<<<<<<<<<< + * raise ValueError("FastxRecord must have a name and not None") + * self.name = name + */ + } + + /* "pysam/libcfaidx.pyx":466 + * if name is None: + * raise ValueError("FastxRecord must have a name and not None") + * self.name = name # <<<<<<<<<<<<<< + * + * def set_comment(self, comment): + */ + if (!(likely(PyString_CheckExact(__pyx_v_name))||((__pyx_v_name) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_name)->tp_name), 0))) __PYX_ERR(0, 466, __pyx_L1_error) + __pyx_t_3 = __pyx_v_name; + __Pyx_INCREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->name); + __Pyx_DECREF(__pyx_v_self->name); + __pyx_v_self->name = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libcfaidx.pyx":463 + * return self.to_string() * + * def set_name(self, name): # <<<<<<<<<<<<<< + * if name is None: + * raise ValueError("FastxRecord must have a name and not None") */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.set_name", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -7413,203 +7664,101 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_2__str__(stru return __pyx_r; } -/* "pysam/libcfaidx.pyx":398 - * return self.tostring() +/* "pysam/libcfaidx.pyx":468 + * self.name = name + * + * def set_comment(self, comment): # <<<<<<<<<<<<<< + * self.comment = comment * - * cpdef array.array get_quality_array(self, int offset=33): # <<<<<<<<<<<<<< - * '''return quality values as array after subtracting offset.''' - * if self.quality is None: */ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_5get_quality_array(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static arrayobject *__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array *__pyx_optional_args) { - int __pyx_v_offset = ((int)33); - arrayobject *__pyx_r = NULL; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_9set_comment(PyObject *__pyx_v_self, PyObject *__pyx_v_comment); /*proto*/ +static char __pyx_doc_5pysam_9libcfaidx_11FastxRecord_8set_comment[] = "FastxRecord.set_comment(self, comment)"; +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_9set_comment(PyObject *__pyx_v_self, PyObject *__pyx_v_comment) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("set_comment (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_8set_comment(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self), ((PyObject *)__pyx_v_comment)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_8set_comment(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_comment) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - int __pyx_t_8; - struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array __pyx_t_9; - __Pyx_RefNannySetupContext("get_quality_array", 0); - __Pyx_TraceCall("get_quality_array", __pyx_f[0], 398, 0, __PYX_ERR(0, 398, __pyx_L1_error)); - if (__pyx_optional_args) { - if (__pyx_optional_args->__pyx_n > 0) { - __pyx_v_offset = __pyx_optional_args->offset; - } - } - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_quality_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_5get_quality_array)) { - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (!__pyx_t_5) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 398, __pyx_L1_error) - __pyx_r = ((arrayobject *)__pyx_t_2); - __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "pysam/libcfaidx.pyx":400 - * cpdef array.array get_quality_array(self, int offset=33): - * '''return quality values as array after subtracting offset.''' - * if self.quality is None: # <<<<<<<<<<<<<< - * return None - * return qualitystring_to_array(force_bytes(self.quality), - */ - __pyx_t_7 = (__pyx_v_self->quality == ((PyObject*)Py_None)); - __pyx_t_8 = (__pyx_t_7 != 0); - if (__pyx_t_8) { - - /* "pysam/libcfaidx.pyx":401 - * '''return quality values as array after subtracting offset.''' - * if self.quality is None: - * return None # <<<<<<<<<<<<<< - * return qualitystring_to_array(force_bytes(self.quality), - * offset=offset) - */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __pyx_r = ((arrayobject *)Py_None); __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "pysam/libcfaidx.pyx":400 - * cpdef array.array get_quality_array(self, int offset=33): - * '''return quality values as array after subtracting offset.''' - * if self.quality is None: # <<<<<<<<<<<<<< - * return None - * return qualitystring_to_array(force_bytes(self.quality), - */ - } - - /* "pysam/libcfaidx.pyx":402 - * if self.quality is None: - * return None - * return qualitystring_to_array(force_bytes(self.quality), # <<<<<<<<<<<<<< - * offset=offset) - * - */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __pyx_t_1 = __pyx_v_self->quality; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_RefNannySetupContext("set_comment", 0); + __Pyx_TraceCall("set_comment", __pyx_f[0], 468, 0, __PYX_ERR(0, 468, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":403 - * return None - * return qualitystring_to_array(force_bytes(self.quality), - * offset=offset) # <<<<<<<<<<<<<< + /* "pysam/libcfaidx.pyx":469 * + * def set_comment(self, comment): + * self.comment = comment # <<<<<<<<<<<<<< * + * def set_sequence(self, sequence, quality=None): */ - __pyx_t_9.__pyx_n = 1; - __pyx_t_9.offset = __pyx_v_offset; - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9libcutils_qualitystring_to_array(__pyx_t_2, 0, &__pyx_t_9)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = ((arrayobject *)__pyx_t_1); + if (!(likely(PyString_CheckExact(__pyx_v_comment))||((__pyx_v_comment) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_comment)->tp_name), 0))) __PYX_ERR(0, 469, __pyx_L1_error) + __pyx_t_1 = __pyx_v_comment; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->comment); + __Pyx_DECREF(__pyx_v_self->comment); + __pyx_v_self->comment = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - /* "pysam/libcfaidx.pyx":398 - * return self.tostring() + /* "pysam/libcfaidx.pyx":468 + * self.name = name + * + * def set_comment(self, comment): # <<<<<<<<<<<<<< + * self.comment = comment * - * cpdef array.array get_quality_array(self, int offset=33): # <<<<<<<<<<<<<< - * '''return quality values as array after subtracting offset.''' - * if self.quality is None: */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.get_quality_array", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.set_comment", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } +/* "pysam/libcfaidx.pyx":471 + * self.comment = comment + * + * def set_sequence(self, sequence, quality=None): # <<<<<<<<<<<<<< + * """set sequence of this record. + * + */ + /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_5get_quality_array(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libcfaidx_20PersistentFastqProxy_4get_quality_array[] = "PersistentFastqProxy.get_quality_array(self, int offset=33) -> array\nreturn quality values as array after subtracting offset."; -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_5get_quality_array(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_offset; +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_11set_sequence(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_9libcfaidx_11FastxRecord_10set_sequence[] = "FastxRecord.set_sequence(self, sequence, quality=None)\nset sequence of this record.\n\n "; +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_11set_sequence(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_sequence = 0; + PyObject *__pyx_v_quality = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_quality_array (wrapper)", 0); + __Pyx_RefNannySetupContext("set_sequence (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_offset,0}; - PyObject* values[1] = {0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sequence,&__pyx_n_s_quality,0}; + PyObject* values[2] = {0,0}; + values[1] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; @@ -7618,64 +7767,259 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_5get_quality_ kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sequence)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_offset); - if (value) { values[0] = value; kw_args--; } + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_quality); + if (value) { values[1] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_quality_array") < 0)) __PYX_ERR(0, 398, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "set_sequence") < 0)) __PYX_ERR(0, 471, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; - case 0: break; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; default: goto __pyx_L5_argtuple_error; } } - if (values[0]) { - __pyx_v_offset = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 398, __pyx_L3_error) - } else { - __pyx_v_offset = ((int)33); - } + __pyx_v_sequence = values[0]; + __pyx_v_quality = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_quality_array", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 398, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("set_sequence", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 471, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.get_quality_array", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.set_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4get_quality_array(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self), __pyx_v_offset); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_10set_sequence(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self), __pyx_v_sequence, __pyx_v_quality); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4get_quality_array(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, int __pyx_v_offset) { +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_10set_sequence(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_sequence, PyObject *__pyx_v_quality) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array __pyx_t_2; - __Pyx_RefNannySetupContext("get_quality_array", 0); - __Pyx_TraceCall("get_quality_array (wrapper)", __pyx_f[0], 398, 0, __PYX_ERR(0, 398, __pyx_L1_error)); - __Pyx_XDECREF(__pyx_r); - __pyx_t_2.__pyx_n = 1; - __pyx_t_2.offset = __pyx_v_offset; - __pyx_t_1 = ((PyObject *)__pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy->get_quality_array(__pyx_v_self, 1, &__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + Py_ssize_t __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + __Pyx_RefNannySetupContext("set_sequence", 0); + __Pyx_TraceCall("set_sequence", __pyx_f[0], 471, 0, __PYX_ERR(0, 471, __pyx_L1_error)); + + /* "pysam/libcfaidx.pyx":475 + * + * """ + * self.sequence = sequence # <<<<<<<<<<<<<< + * if quality is not None: + * if len(sequence) != len(quality): + */ + if (!(likely(PyString_CheckExact(__pyx_v_sequence))||((__pyx_v_sequence) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_sequence)->tp_name), 0))) __PYX_ERR(0, 475, __pyx_L1_error) + __pyx_t_1 = __pyx_v_sequence; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->sequence); + __Pyx_DECREF(__pyx_v_self->sequence); + __pyx_v_self->sequence = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; + + /* "pysam/libcfaidx.pyx":476 + * """ + * self.sequence = sequence + * if quality is not None: # <<<<<<<<<<<<<< + * if len(sequence) != len(quality): + * raise ValueError("sequence and quality length do not match: {} vs {}".format( + */ + __pyx_t_2 = (__pyx_v_quality != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "pysam/libcfaidx.pyx":477 + * self.sequence = sequence + * if quality is not None: + * if len(sequence) != len(quality): # <<<<<<<<<<<<<< + * raise ValueError("sequence and quality length do not match: {} vs {}".format( + * len(sequence), len(quality))) + */ + __pyx_t_4 = PyObject_Length(__pyx_v_sequence); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 477, __pyx_L1_error) + __pyx_t_5 = PyObject_Length(__pyx_v_quality); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 477, __pyx_L1_error) + __pyx_t_3 = ((__pyx_t_4 != __pyx_t_5) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libcfaidx.pyx":478 + * if quality is not None: + * if len(sequence) != len(quality): + * raise ValueError("sequence and quality length do not match: {} vs {}".format( # <<<<<<<<<<<<<< + * len(sequence), len(quality))) + * + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_sequence_and_quality_length_do_n, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + + /* "pysam/libcfaidx.pyx":479 + * if len(sequence) != len(quality): + * raise ValueError("sequence and quality length do not match: {} vs {}".format( + * len(sequence), len(quality))) # <<<<<<<<<<<<<< + * + * self.quality = quality + */ + __pyx_t_5 = PyObject_Length(__pyx_v_sequence); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 479, __pyx_L1_error) + __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 479, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = PyObject_Length(__pyx_v_quality); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 479, __pyx_L1_error) + __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 479, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 478, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 478, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_8); + __pyx_t_7 = 0; + __pyx_t_8 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pysam/libcfaidx.pyx":478 + * if quality is not None: + * if len(sequence) != len(quality): + * raise ValueError("sequence and quality length do not match: {} vs {}".format( # <<<<<<<<<<<<<< + * len(sequence), len(quality))) + * + */ + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 478, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 478, __pyx_L1_error) + + /* "pysam/libcfaidx.pyx":477 + * self.sequence = sequence + * if quality is not None: + * if len(sequence) != len(quality): # <<<<<<<<<<<<<< + * raise ValueError("sequence and quality length do not match: {} vs {}".format( + * len(sequence), len(quality))) + */ + } + + /* "pysam/libcfaidx.pyx":481 + * len(sequence), len(quality))) + * + * self.quality = quality # <<<<<<<<<<<<<< + * else: + * self.quality = None + */ + if (!(likely(PyString_CheckExact(__pyx_v_quality))||((__pyx_v_quality) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_quality)->tp_name), 0))) __PYX_ERR(0, 481, __pyx_L1_error) + __pyx_t_6 = __pyx_v_quality; + __Pyx_INCREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_v_self->quality); + __Pyx_DECREF(__pyx_v_self->quality); + __pyx_v_self->quality = ((PyObject*)__pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libcfaidx.pyx":476 + * """ + * self.sequence = sequence + * if quality is not None: # <<<<<<<<<<<<<< + * if len(sequence) != len(quality): + * raise ValueError("sequence and quality length do not match: {} vs {}".format( + */ + goto __pyx_L3; + } + + /* "pysam/libcfaidx.pyx":483 + * self.quality = quality + * else: + * self.quality = None # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + /*else*/ { + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->quality); + __Pyx_DECREF(__pyx_v_self->quality); + __pyx_v_self->quality = ((PyObject*)Py_None); + } + __pyx_L3:; + + /* "pysam/libcfaidx.pyx":471 + * self.comment = comment + * + * def set_sequence(self, sequence, quality=None): # <<<<<<<<<<<<<< + * """set sequence of this record. + * + */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.get_quality_array", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.set_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -7684,41 +8028,61 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4get_quality_ return __pyx_r; } -/* "pysam/libcfaidx.pxd":55 - * Python container for pysam.libcfaidx.FastqProxy with persistence. - * """ - * cdef public str comment, quality, sequence, name # <<<<<<<<<<<<<< - * cdef cython.str tostring(self) - * cpdef array.array get_quality_array(self, int offset=*) +/* "pysam/libcfaidx.pyx":485 + * self.quality = None + * + * def __str__(self): # <<<<<<<<<<<<<< + * return self.to_string() + * */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_13__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_13__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7comment___get__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_12__str__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7comment___get__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_12__str__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 55, 0, __PYX_ERR(2, 55, __pyx_L1_error)); + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__str__", 0); + __Pyx_TraceCall("__str__", __pyx_f[0], 485, 0, __PYX_ERR(0, 485, __pyx_L1_error)); + + /* "pysam/libcfaidx.pyx":486 + * + * def __str__(self): + * return self.to_string() # <<<<<<<<<<<<<< + * + * cpdef array.array get_quality_array(self, int offset=33): + */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->comment); - __pyx_r = __pyx_v_self->comment; + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self->__pyx_vtab)->to_string(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; + /* "pysam/libcfaidx.pyx":485 + * self.quality = None + * + * def __str__(self): # <<<<<<<<<<<<<< + * return self.to_string() + * + */ + /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.comment.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -7727,104 +8091,418 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7comment___ge return __pyx_r; } -/* Python wrapper */ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_2__set__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} +/* "pysam/libcfaidx.pyx":488 + * return self.to_string() + * + * cpdef array.array get_quality_array(self, int offset=33): # <<<<<<<<<<<<<< + * '''return quality values as array after subtracting offset.''' + * if self.quality is None: + */ -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_2__set__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_15get_quality_array(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static arrayobject *__pyx_f_5pysam_9libcfaidx_11FastxRecord_get_quality_array(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array *__pyx_optional_args) { + int __pyx_v_offset = ((int)33); + arrayobject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[2], 55, 0, __PYX_ERR(2, 55, __pyx_L1_error)); - if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(2, 55, __pyx_L1_error) - __pyx_t_1 = __pyx_v_value; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + int __pyx_t_8; + struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array __pyx_t_9; + __Pyx_RefNannySetupContext("get_quality_array", 0); + __Pyx_TraceCall("get_quality_array", __pyx_f[0], 488, 0, __PYX_ERR(0, 488, __pyx_L1_error)); + if (__pyx_optional_args) { + if (__pyx_optional_args->__pyx_n > 0) { + __pyx_v_offset = __pyx_optional_args->offset; + } + } + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_quality_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_9libcfaidx_11FastxRecord_15get_quality_array)) { + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 488, __pyx_L1_error) + __pyx_r = ((arrayobject *)__pyx_t_2); + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "pysam/libcfaidx.pyx":490 + * cpdef array.array get_quality_array(self, int offset=33): + * '''return quality values as array after subtracting offset.''' + * if self.quality is None: # <<<<<<<<<<<<<< + * return None + * return qualitystring_to_array(force_bytes(self.quality), + */ + __pyx_t_7 = (__pyx_v_self->quality == ((PyObject*)Py_None)); + __pyx_t_8 = (__pyx_t_7 != 0); + if (__pyx_t_8) { + + /* "pysam/libcfaidx.pyx":491 + * '''return quality values as array after subtracting offset.''' + * if self.quality is None: + * return None # <<<<<<<<<<<<<< + * return qualitystring_to_array(force_bytes(self.quality), + * offset=offset) + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __pyx_r = ((arrayobject *)Py_None); __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libcfaidx.pyx":490 + * cpdef array.array get_quality_array(self, int offset=33): + * '''return quality values as array after subtracting offset.''' + * if self.quality is None: # <<<<<<<<<<<<<< + * return None + * return qualitystring_to_array(force_bytes(self.quality), + */ + } + + /* "pysam/libcfaidx.pyx":492 + * if self.quality is None: + * return None + * return qualitystring_to_array(force_bytes(self.quality), # <<<<<<<<<<<<<< + * offset=offset) + * + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __pyx_t_1 = __pyx_v_self->quality; __Pyx_INCREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->comment); - __Pyx_DECREF(__pyx_v_self->comment); - __pyx_v_self->comment = ((PyObject*)__pyx_t_1); + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 492, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libcfaidx.pyx":493 + * return None + * return qualitystring_to_array(force_bytes(self.quality), + * offset=offset) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_9.__pyx_n = 1; + __pyx_t_9.offset = __pyx_v_offset; + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9libcutils_qualitystring_to_array(__pyx_t_2, 0, &__pyx_t_9)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 492, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = ((arrayobject *)__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libcfaidx.pyx":488 + * return self.to_string() + * + * cpdef array.array get_quality_array(self, int offset=33): # <<<<<<<<<<<<<< + * '''return quality values as array after subtracting offset.''' + * if self.quality is None: + */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.comment.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.get_quality_array", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_5__del__(PyObject *__pyx_v_self) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_15get_quality_array(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_9libcfaidx_11FastxRecord_14get_quality_array[] = "FastxRecord.get_quality_array(self, int offset=33) -> array\nreturn quality values as array after subtracting offset."; +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_15get_quality_array(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_offset; + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_4__del__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("get_quality_array (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_offset,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_offset); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_quality_array") < 0)) __PYX_ERR(0, 488, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + if (values[0]) { + __pyx_v_offset = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 488, __pyx_L3_error) + } else { + __pyx_v_offset = ((int)33); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_quality_array", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 488, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.get_quality_array", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_14get_quality_array(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self), __pyx_v_offset); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_4__del__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_14get_quality_array(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, int __pyx_v_offset) { + PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_TraceCall("__del__", __pyx_f[2], 55, 0, __PYX_ERR(2, 55, __pyx_L1_error)); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->comment); - __Pyx_DECREF(__pyx_v_self->comment); - __pyx_v_self->comment = ((PyObject*)Py_None); + PyObject *__pyx_t_1 = NULL; + struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array __pyx_t_2; + __Pyx_RefNannySetupContext("get_quality_array", 0); + __Pyx_TraceCall("get_quality_array (wrapper)", __pyx_f[0], 488, 0, __PYX_ERR(0, 488, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __pyx_t_2.__pyx_n = 1; + __pyx_t_2.offset = __pyx_v_offset; + __pyx_t_1 = ((PyObject *)__pyx_vtabptr_5pysam_9libcfaidx_FastxRecord->get_quality_array(__pyx_v_self, 1, &__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.comment.__del__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.get_quality_array", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libcfaidx.pxd":56 + * Python container for pysam.libcfaidx.FastqProxy with persistence. + * """ + * cdef public str comment, quality, sequence, name # <<<<<<<<<<<<<< + * cdef cython.str to_string(self) + * cdef cython.str tostring(self) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_7comment_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_7comment_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7comment___get__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_7comment___get__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[2], 56, 0, __PYX_ERR(2, 56, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->comment); + __pyx_r = __pyx_v_self->comment; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.comment.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7comment_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7comment_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7comment_2__set__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7comment_2__set__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_TraceCall("__set__", __pyx_f[2], 56, 0, __PYX_ERR(2, 56, __pyx_L1_error)); + if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(2, 56, __pyx_L1_error) + __pyx_t_1 = __pyx_v_value; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->comment); + __Pyx_DECREF(__pyx_v_self->comment); + __pyx_v_self->comment = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.comment.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7comment_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7comment_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7comment_4__del__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7comment_4__del__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_TraceCall("__del__", __pyx_f[2], 56, 0, __PYX_ERR(2, 56, __pyx_L1_error)); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->comment); + __Pyx_DECREF(__pyx_v_self->comment); + __pyx_v_self->comment = ((PyObject*)Py_None); + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.comment.__del__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_7quality_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_7quality_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality___get__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7quality___get__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality___get__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_7quality___get__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 55, 0, __PYX_ERR(2, 55, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[2], 56, 0, __PYX_ERR(2, 56, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->quality); __pyx_r = __pyx_v_self->quality; @@ -7832,7 +8510,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality___ge /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -7842,26 +8520,26 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality___ge } /* Python wrapper */ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7quality_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7quality_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_2__set__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7quality_2__set__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_2__set__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, PyObject *__pyx_v_value) { +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7quality_2__set__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[2], 55, 0, __PYX_ERR(2, 55, __pyx_L1_error)); - if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(2, 55, __pyx_L1_error) + __Pyx_TraceCall("__set__", __pyx_f[2], 56, 0, __PYX_ERR(2, 56, __pyx_L1_error)); + if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(2, 56, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -7875,7 +8553,7 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_2__set__(s goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.quality.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.quality.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -7884,24 +8562,24 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_2__set__(s } /* Python wrapper */ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_5__del__(PyObject *__pyx_v_self) { +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7quality_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7quality_5__del__(PyObject *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_4__del__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7quality_4__del__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_4__del__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self) { +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_7quality_4__del__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_TraceCall("__del__", __pyx_f[2], 55, 0, __PYX_ERR(2, 55, __pyx_L1_error)); + __Pyx_TraceCall("__del__", __pyx_f[2], 56, 0, __PYX_ERR(2, 56, __pyx_L1_error)); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->quality); @@ -7912,7 +8590,7 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_4__del__(s __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.quality.__del__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.quality.__del__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -7921,24 +8599,24 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_4__del__(s } /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_8sequence_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_8sequence_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence___get__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_8sequence___get__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence___get__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_8sequence___get__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 55, 0, __PYX_ERR(2, 55, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[2], 56, 0, __PYX_ERR(2, 56, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->sequence); __pyx_r = __pyx_v_self->sequence; @@ -7946,7 +8624,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence___g /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.sequence.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.sequence.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -7956,26 +8634,26 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence___g } /* Python wrapper */ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_8sequence_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_8sequence_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_2__set__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_8sequence_2__set__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_2__set__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, PyObject *__pyx_v_value) { +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_8sequence_2__set__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[2], 55, 0, __PYX_ERR(2, 55, __pyx_L1_error)); - if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(2, 55, __pyx_L1_error) + __Pyx_TraceCall("__set__", __pyx_f[2], 56, 0, __PYX_ERR(2, 56, __pyx_L1_error)); + if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(2, 56, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -7989,7 +8667,7 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_2__set__( goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.sequence.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.sequence.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -7998,24 +8676,24 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_2__set__( } /* Python wrapper */ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_5__del__(PyObject *__pyx_v_self) { +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_8sequence_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_8sequence_5__del__(PyObject *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_4__del__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_8sequence_4__del__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_4__del__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self) { +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_8sequence_4__del__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_TraceCall("__del__", __pyx_f[2], 55, 0, __PYX_ERR(2, 55, __pyx_L1_error)); + __Pyx_TraceCall("__del__", __pyx_f[2], 56, 0, __PYX_ERR(2, 56, __pyx_L1_error)); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->sequence); @@ -8026,7 +8704,7 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_4__del__( __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.sequence.__del__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.sequence.__del__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -8035,24 +8713,24 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_4__del__( } /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_4name_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_4name_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_4name_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_4name_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name___get__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_4name___get__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name___get__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_4name___get__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 55, 0, __PYX_ERR(2, 55, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[2], 56, 0, __PYX_ERR(2, 56, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->name); __pyx_r = __pyx_v_self->name; @@ -8060,7 +8738,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name___get__ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -8070,26 +8748,26 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name___get__ } /* Python wrapper */ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_4name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_4name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_4name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_4name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name_2__set__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_4name_2__set__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name_2__set__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, PyObject *__pyx_v_value) { +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_4name_2__set__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_TraceCall("__set__", __pyx_f[2], 55, 0, __PYX_ERR(2, 55, __pyx_L1_error)); - if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(2, 55, __pyx_L1_error) + __Pyx_TraceCall("__set__", __pyx_f[2], 56, 0, __PYX_ERR(2, 56, __pyx_L1_error)); + if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(2, 56, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -8103,7 +8781,7 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name_2__set__(stru goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.name.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.name.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -8112,24 +8790,24 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name_2__set__(stru } /* Python wrapper */ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_4name_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_4name_5__del__(PyObject *__pyx_v_self) { +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_4name_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5pysam_9libcfaidx_11FastxRecord_4name_5__del__(PyObject *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name_4__del__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_4name_4__del__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name_4__del__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self) { +static int __pyx_pf_5pysam_9libcfaidx_11FastxRecord_4name_4__del__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_TraceCall("__del__", __pyx_f[2], 55, 0, __PYX_ERR(2, 55, __pyx_L1_error)); + __Pyx_TraceCall("__del__", __pyx_f[2], 56, 0, __PYX_ERR(2, 56, __pyx_L1_error)); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->name); @@ -8140,7 +8818,7 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name_4__del__(stru __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.name.__del__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.name.__del__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_TraceReturn(Py_None, 0); @@ -8155,20 +8833,20 @@ static int __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_4name_4__del__(stru */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_9libcfaidx_20PersistentFastqProxy_6__reduce_cython__[] = "PersistentFastqProxy.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_17__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_9libcfaidx_11FastxRecord_16__reduce_cython__[] = "FastxRecord.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_17__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_6__reduce_cython__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_16__reduce_cython__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_6__reduce_cython__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_16__reduce_cython__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self) { int __pyx_v_use_setstate; PyObject *__pyx_v_state = NULL; PyObject *__pyx_v__dict = NULL; @@ -8273,7 +8951,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_6__reduce_cyt * else: * use_setstate = self.comment is not None or self.name is not None or self.quality is not None or self.sequence is not None # <<<<<<<<<<<<<< * if use_setstate: - * return __pyx_unpickle_PersistentFastqProxy, (type(self), 0x43fd151, None), state + * return __pyx_unpickle_FastxRecord, (type(self), 0x43fd151, None), state */ /*else*/ { __pyx_t_2 = (__pyx_v_self->comment != ((PyObject*)Py_None)); @@ -8309,7 +8987,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_6__reduce_cyt * else: * use_setstate = self.comment is not None or self.name is not None or self.quality is not None or self.sequence is not None * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_PersistentFastqProxy, (type(self), 0x43fd151, None), state + * return __pyx_unpickle_FastxRecord, (type(self), 0x43fd151, None), state * else: */ __pyx_t_3 = (__pyx_v_use_setstate != 0); @@ -8318,12 +8996,12 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_6__reduce_cyt /* "(tree fragment)":11 * use_setstate = self.comment is not None or self.name is not None or self.quality is not None or self.sequence is not None * if use_setstate: - * return __pyx_unpickle_PersistentFastqProxy, (type(self), 0x43fd151, None), state # <<<<<<<<<<<<<< + * return __pyx_unpickle_FastxRecord, (type(self), 0x43fd151, None), state # <<<<<<<<<<<<<< * else: - * return __pyx_unpickle_PersistentFastqProxy, (type(self), 0x43fd151, state) + * return __pyx_unpickle_FastxRecord, (type(self), 0x43fd151, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_PersistentFastqPr); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_FastxRecord); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); @@ -8355,21 +9033,21 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_6__reduce_cyt * else: * use_setstate = self.comment is not None or self.name is not None or self.quality is not None or self.sequence is not None * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_PersistentFastqProxy, (type(self), 0x43fd151, None), state + * return __pyx_unpickle_FastxRecord, (type(self), 0x43fd151, None), state * else: */ } /* "(tree fragment)":13 - * return __pyx_unpickle_PersistentFastqProxy, (type(self), 0x43fd151, None), state + * return __pyx_unpickle_FastxRecord, (type(self), 0x43fd151, None), state * else: - * return __pyx_unpickle_PersistentFastqProxy, (type(self), 0x43fd151, state) # <<<<<<<<<<<<<< + * return __pyx_unpickle_FastxRecord, (type(self), 0x43fd151, state) # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_PersistentFastqProxy__set_state(self, __pyx_state) + * __pyx_unpickle_FastxRecord__set_state(self, __pyx_state) */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_PersistentFastqPr); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_FastxRecord); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); @@ -8406,7 +9084,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_6__reduce_cyt __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_state); @@ -8419,26 +9097,26 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_6__reduce_cyt /* "(tree fragment)":14 * else: - * return __pyx_unpickle_PersistentFastqProxy, (type(self), 0x43fd151, state) + * return __pyx_unpickle_FastxRecord, (type(self), 0x43fd151, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_PersistentFastqProxy__set_state(self, __pyx_state) + * __pyx_unpickle_FastxRecord__set_state(self, __pyx_state) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_9libcfaidx_20PersistentFastqProxy_8__setstate_cython__[] = "PersistentFastqProxy.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_19__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_9libcfaidx_11FastxRecord_18__setstate_cython__[] = "FastxRecord.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_9libcfaidx_11FastxRecord_19__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8__setstate_cython__(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_9libcfaidx_11FastxRecord_18__setstate_cython__(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8__setstate_cython__(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_9libcfaidx_11FastxRecord_18__setstate_cython__(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -8447,20 +9125,20 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8__setstate_c __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); /* "(tree fragment)":15 - * return __pyx_unpickle_PersistentFastqProxy, (type(self), 0x43fd151, state) + * return __pyx_unpickle_FastxRecord, (type(self), 0x43fd151, state) * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_PersistentFastqProxy__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + * __pyx_unpickle_FastxRecord__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcfaidx___pyx_unpickle_FastxRecord__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":14 * else: - * return __pyx_unpickle_PersistentFastqProxy, (type(self), 0x43fd151, state) + * return __pyx_unpickle_FastxRecord, (type(self), 0x43fd151, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_PersistentFastqProxy__set_state(self, __pyx_state) + * __pyx_unpickle_FastxRecord__set_state(self, __pyx_state) */ /* function exit code */ @@ -8468,7 +9146,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8__setstate_c goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libcfaidx.PersistentFastqProxy.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.FastxRecord.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -8477,7 +9155,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_20PersistentFastqProxy_8__setstate_c return __pyx_r; } -/* "pysam/libcfaidx.pyx":452 +/* "pysam/libcfaidx.pyx":545 * * """ * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -8518,9 +9196,9 @@ static int __pyx_pf_5pysam_9libcfaidx_9FastxFile___cinit__(struct __pyx_obj_5pys PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[0], 452, 0, __PYX_ERR(0, 452, __pyx_L1_error)); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 545, 0, __PYX_ERR(0, 545, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":454 + /* "pysam/libcfaidx.pyx":547 * def __cinit__(self, *args, **kwargs): * # self.fastqfile = NULL * self._filename = None # <<<<<<<<<<<<<< @@ -8533,7 +9211,7 @@ static int __pyx_pf_5pysam_9libcfaidx_9FastxFile___cinit__(struct __pyx_obj_5pys __Pyx_DECREF(__pyx_v_self->_filename); __pyx_v_self->_filename = Py_None; - /* "pysam/libcfaidx.pyx":455 + /* "pysam/libcfaidx.pyx":548 * # self.fastqfile = NULL * self._filename = None * self.entry = NULL # <<<<<<<<<<<<<< @@ -8542,21 +9220,21 @@ static int __pyx_pf_5pysam_9libcfaidx_9FastxFile___cinit__(struct __pyx_obj_5pys */ __pyx_v_self->entry = NULL; - /* "pysam/libcfaidx.pyx":456 + /* "pysam/libcfaidx.pyx":549 * self._filename = None * self.entry = NULL * self._open(*args, **kwargs) # <<<<<<<<<<<<<< * * def is_open(self): */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 456, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 549, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_v_args, __pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 456, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_v_args, __pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 549, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcfaidx.pyx":452 + /* "pysam/libcfaidx.pyx":545 * * """ * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< @@ -8578,7 +9256,7 @@ static int __pyx_pf_5pysam_9libcfaidx_9FastxFile___cinit__(struct __pyx_obj_5pys return __pyx_r; } -/* "pysam/libcfaidx.pyx":458 +/* "pysam/libcfaidx.pyx":551 * self._open(*args, **kwargs) * * def is_open(self): # <<<<<<<<<<<<<< @@ -8606,9 +9284,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_2is_open(struct __pyx_obj __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("is_open", 0); - __Pyx_TraceCall("is_open", __pyx_f[0], 458, 0, __PYX_ERR(0, 458, __pyx_L1_error)); + __Pyx_TraceCall("is_open", __pyx_f[0], 551, 0, __PYX_ERR(0, 551, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":460 + /* "pysam/libcfaidx.pyx":553 * def is_open(self): * '''return true if samfile has been opened.''' * return self.entry != NULL # <<<<<<<<<<<<<< @@ -8616,13 +9294,13 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_2is_open(struct __pyx_obj * def _open(self, filename, persist=True): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->entry != NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 460, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->entry != NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 553, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":458 + /* "pysam/libcfaidx.pyx":551 * self._open(*args, **kwargs) * * def is_open(self): # <<<<<<<<<<<<<< @@ -8642,7 +9320,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_2is_open(struct __pyx_obj return __pyx_r; } -/* "pysam/libcfaidx.pyx":462 +/* "pysam/libcfaidx.pyx":555 * return self.entry != NULL * * def _open(self, filename, persist=True): # <<<<<<<<<<<<<< @@ -8687,7 +9365,7 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastxFile_5_open(PyObject *__pyx_v_ } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) __PYX_ERR(0, 462, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) __PYX_ERR(0, 555, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -8703,7 +9381,7 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastxFile_5_open(PyObject *__pyx_v_ } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 462, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 555, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcfaidx.FastxFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -8730,9 +9408,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 PyObject *__pyx_t_7 = NULL; int __pyx_t_8; __Pyx_RefNannySetupContext("_open", 0); - __Pyx_TraceCall("_open", __pyx_f[0], 462, 0, __PYX_ERR(0, 462, __pyx_L1_error)); + __Pyx_TraceCall("_open", __pyx_f[0], 555, 0, __PYX_ERR(0, 555, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":475 + /* "pysam/libcfaidx.pyx":568 * * ''' * if self.fastqfile != NULL: # <<<<<<<<<<<<<< @@ -8742,14 +9420,14 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 __pyx_t_1 = ((__pyx_v_self->fastqfile != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcfaidx.pyx":476 + /* "pysam/libcfaidx.pyx":569 * ''' * if self.fastqfile != NULL: * self.close() # <<<<<<<<<<<<<< * * self._filename = encode_filename(filename) */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 476, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 569, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { @@ -8762,16 +9440,16 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 } } if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 476, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 569, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 476, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 569, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcfaidx.pyx":475 + /* "pysam/libcfaidx.pyx":568 * * ''' * if self.fastqfile != NULL: # <<<<<<<<<<<<<< @@ -8780,14 +9458,14 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 */ } - /* "pysam/libcfaidx.pyx":478 + /* "pysam/libcfaidx.pyx":571 * self.close() * * self._filename = encode_filename(filename) # <<<<<<<<<<<<<< * cdef char *cfilename = self._filename * self.is_remote = hisremote(cfilename) */ - __pyx_t_2 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 478, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 571, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_self->_filename); @@ -8795,17 +9473,17 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 __pyx_v_self->_filename = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libcfaidx.pyx":479 + /* "pysam/libcfaidx.pyx":572 * * self._filename = encode_filename(filename) * cdef char *cfilename = self._filename # <<<<<<<<<<<<<< * self.is_remote = hisremote(cfilename) * */ - __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_self->_filename); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 479, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_self->_filename); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 572, __pyx_L1_error) __pyx_v_cfilename = __pyx_t_5; - /* "pysam/libcfaidx.pyx":480 + /* "pysam/libcfaidx.pyx":573 * self._filename = encode_filename(filename) * cdef char *cfilename = self._filename * self.is_remote = hisremote(cfilename) # <<<<<<<<<<<<<< @@ -8814,21 +9492,21 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 */ __pyx_v_self->is_remote = hisremote(__pyx_v_cfilename); - /* "pysam/libcfaidx.pyx":483 + /* "pysam/libcfaidx.pyx":576 * * # open file for reading * if (self._filename != b"-" # <<<<<<<<<<<<<< * and not self.is_remote * and not os.path.exists(filename)): */ - __pyx_t_6 = (__Pyx_PyBytes_Equals(__pyx_v_self->_filename, __pyx_kp_b__3, Py_NE)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 483, __pyx_L1_error) + __pyx_t_6 = (__Pyx_PyBytes_Equals(__pyx_v_self->_filename, __pyx_kp_b__2, Py_NE)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 576, __pyx_L1_error) if (__pyx_t_6) { } else { __pyx_t_1 = __pyx_t_6; goto __pyx_L5_bool_binop_done; } - /* "pysam/libcfaidx.pyx":484 + /* "pysam/libcfaidx.pyx":577 * # open file for reading * if (self._filename != b"-" * and not self.is_remote # <<<<<<<<<<<<<< @@ -8842,19 +9520,19 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 goto __pyx_L5_bool_binop_done; } - /* "pysam/libcfaidx.pyx":485 + /* "pysam/libcfaidx.pyx":578 * if (self._filename != b"-" * and not self.is_remote * and not os.path.exists(filename)): # <<<<<<<<<<<<<< * raise IOError("file `%s` not found" % filename) * */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 485, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exists); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exists); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = NULL; @@ -8868,13 +9546,13 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 } } if (!__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 485, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filename}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 485, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_2); } else @@ -8882,31 +9560,31 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filename}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 485, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 485, __pyx_L1_error) + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_filename); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 485, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 485, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_8 = ((!__pyx_t_6) != 0); __pyx_t_1 = __pyx_t_8; __pyx_L5_bool_binop_done:; - /* "pysam/libcfaidx.pyx":483 + /* "pysam/libcfaidx.pyx":576 * * # open file for reading * if (self._filename != b"-" # <<<<<<<<<<<<<< @@ -8915,23 +9593,23 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 */ if (unlikely(__pyx_t_1)) { - /* "pysam/libcfaidx.pyx":486 + /* "pysam/libcfaidx.pyx":579 * and not self.is_remote * and not os.path.exists(filename)): * raise IOError("file `%s` not found" % filename) # <<<<<<<<<<<<<< * * self.persist = persist */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_file_s_not_found, __pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 486, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_file_s_not_found, __pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 579, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 486, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 579, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 486, __pyx_L1_error) + __PYX_ERR(0, 579, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":483 + /* "pysam/libcfaidx.pyx":576 * * # open file for reading * if (self._filename != b"-" # <<<<<<<<<<<<<< @@ -8940,17 +9618,17 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 */ } - /* "pysam/libcfaidx.pyx":488 + /* "pysam/libcfaidx.pyx":581 * raise IOError("file `%s` not found" % filename) * * self.persist = persist # <<<<<<<<<<<<<< * * with nogil: */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_persist); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 488, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_persist); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 581, __pyx_L1_error) __pyx_v_self->persist = __pyx_t_1; - /* "pysam/libcfaidx.pyx":490 + /* "pysam/libcfaidx.pyx":583 * self.persist = persist * * with nogil: # <<<<<<<<<<<<<< @@ -8965,7 +9643,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 #endif /*try:*/ { - /* "pysam/libcfaidx.pyx":491 + /* "pysam/libcfaidx.pyx":584 * * with nogil: * self.fastqfile = bgzf_open(cfilename, "r") # <<<<<<<<<<<<<< @@ -8974,7 +9652,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 */ __pyx_v_self->fastqfile = bgzf_open(__pyx_v_cfilename, ((char const *)"r")); - /* "pysam/libcfaidx.pyx":492 + /* "pysam/libcfaidx.pyx":585 * with nogil: * self.fastqfile = bgzf_open(cfilename, "r") * self.entry = kseq_init(self.fastqfile) # <<<<<<<<<<<<<< @@ -8984,7 +9662,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 __pyx_v_self->entry = kseq_init(__pyx_v_self->fastqfile); } - /* "pysam/libcfaidx.pyx":490 + /* "pysam/libcfaidx.pyx":583 * self.persist = persist * * with nogil: # <<<<<<<<<<<<<< @@ -9003,7 +9681,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 } } - /* "pysam/libcfaidx.pyx":493 + /* "pysam/libcfaidx.pyx":586 * self.fastqfile = bgzf_open(cfilename, "r") * self.entry = kseq_init(self.fastqfile) * self._filename = filename # <<<<<<<<<<<<<< @@ -9016,7 +9694,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 __Pyx_DECREF(__pyx_v_self->_filename); __pyx_v_self->_filename = __pyx_v_filename; - /* "pysam/libcfaidx.pyx":462 + /* "pysam/libcfaidx.pyx":555 * return self.entry != NULL * * def _open(self, filename, persist=True): # <<<<<<<<<<<<<< @@ -9041,7 +9719,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_4_open(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libcfaidx.pyx":495 +/* "pysam/libcfaidx.pyx":588 * self._filename = filename * * def close(self): # <<<<<<<<<<<<<< @@ -9069,9 +9747,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6close(struct __pyx_obj_5 __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("close", 0); - __Pyx_TraceCall("close", __pyx_f[0], 495, 0, __PYX_ERR(0, 495, __pyx_L1_error)); + __Pyx_TraceCall("close", __pyx_f[0], 588, 0, __PYX_ERR(0, 588, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":497 + /* "pysam/libcfaidx.pyx":590 * def close(self): * '''close the file.''' * if self.fastqfile != NULL: # <<<<<<<<<<<<<< @@ -9081,7 +9759,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6close(struct __pyx_obj_5 __pyx_t_1 = ((__pyx_v_self->fastqfile != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcfaidx.pyx":498 + /* "pysam/libcfaidx.pyx":591 * '''close the file.''' * if self.fastqfile != NULL: * bgzf_close(self.fastqfile) # <<<<<<<<<<<<<< @@ -9090,7 +9768,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6close(struct __pyx_obj_5 */ (void)(bgzf_close(__pyx_v_self->fastqfile)); - /* "pysam/libcfaidx.pyx":499 + /* "pysam/libcfaidx.pyx":592 * if self.fastqfile != NULL: * bgzf_close(self.fastqfile) * self.fastqfile = NULL # <<<<<<<<<<<<<< @@ -9099,7 +9777,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6close(struct __pyx_obj_5 */ __pyx_v_self->fastqfile = NULL; - /* "pysam/libcfaidx.pyx":497 + /* "pysam/libcfaidx.pyx":590 * def close(self): * '''close the file.''' * if self.fastqfile != NULL: # <<<<<<<<<<<<<< @@ -9108,7 +9786,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6close(struct __pyx_obj_5 */ } - /* "pysam/libcfaidx.pyx":500 + /* "pysam/libcfaidx.pyx":593 * bgzf_close(self.fastqfile) * self.fastqfile = NULL * if self.entry != NULL: # <<<<<<<<<<<<<< @@ -9118,7 +9796,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6close(struct __pyx_obj_5 __pyx_t_1 = ((__pyx_v_self->entry != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcfaidx.pyx":501 + /* "pysam/libcfaidx.pyx":594 * self.fastqfile = NULL * if self.entry != NULL: * kseq_destroy(self.entry) # <<<<<<<<<<<<<< @@ -9127,7 +9805,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6close(struct __pyx_obj_5 */ kseq_destroy(__pyx_v_self->entry); - /* "pysam/libcfaidx.pyx":502 + /* "pysam/libcfaidx.pyx":595 * if self.entry != NULL: * kseq_destroy(self.entry) * self.entry = NULL # <<<<<<<<<<<<<< @@ -9136,7 +9814,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6close(struct __pyx_obj_5 */ __pyx_v_self->entry = NULL; - /* "pysam/libcfaidx.pyx":500 + /* "pysam/libcfaidx.pyx":593 * bgzf_close(self.fastqfile) * self.fastqfile = NULL * if self.entry != NULL: # <<<<<<<<<<<<<< @@ -9145,7 +9823,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6close(struct __pyx_obj_5 */ } - /* "pysam/libcfaidx.pyx":495 + /* "pysam/libcfaidx.pyx":588 * self._filename = filename * * def close(self): # <<<<<<<<<<<<<< @@ -9166,7 +9844,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6close(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libcfaidx.pyx":504 +/* "pysam/libcfaidx.pyx":597 * self.entry = NULL * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -9190,9 +9868,9 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastxFile_8__dealloc__(struct __pyx_obj_ __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 504, 0, __PYX_ERR(0, 504, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 597, 0, __PYX_ERR(0, 597, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":505 + /* "pysam/libcfaidx.pyx":598 * * def __dealloc__(self): * if self.fastqfile != NULL: # <<<<<<<<<<<<<< @@ -9202,7 +9880,7 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastxFile_8__dealloc__(struct __pyx_obj_ __pyx_t_1 = ((__pyx_v_self->fastqfile != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcfaidx.pyx":506 + /* "pysam/libcfaidx.pyx":599 * def __dealloc__(self): * if self.fastqfile != NULL: * bgzf_close(self.fastqfile) # <<<<<<<<<<<<<< @@ -9211,7 +9889,7 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastxFile_8__dealloc__(struct __pyx_obj_ */ (void)(bgzf_close(__pyx_v_self->fastqfile)); - /* "pysam/libcfaidx.pyx":505 + /* "pysam/libcfaidx.pyx":598 * * def __dealloc__(self): * if self.fastqfile != NULL: # <<<<<<<<<<<<<< @@ -9220,7 +9898,7 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastxFile_8__dealloc__(struct __pyx_obj_ */ } - /* "pysam/libcfaidx.pyx":507 + /* "pysam/libcfaidx.pyx":600 * if self.fastqfile != NULL: * bgzf_close(self.fastqfile) * if self.entry: # <<<<<<<<<<<<<< @@ -9230,7 +9908,7 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastxFile_8__dealloc__(struct __pyx_obj_ __pyx_t_1 = (__pyx_v_self->entry != 0); if (__pyx_t_1) { - /* "pysam/libcfaidx.pyx":508 + /* "pysam/libcfaidx.pyx":601 * bgzf_close(self.fastqfile) * if self.entry: * kseq_destroy(self.entry) # <<<<<<<<<<<<<< @@ -9239,7 +9917,7 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastxFile_8__dealloc__(struct __pyx_obj_ */ kseq_destroy(__pyx_v_self->entry); - /* "pysam/libcfaidx.pyx":507 + /* "pysam/libcfaidx.pyx":600 * if self.fastqfile != NULL: * bgzf_close(self.fastqfile) * if self.entry: # <<<<<<<<<<<<<< @@ -9248,7 +9926,7 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastxFile_8__dealloc__(struct __pyx_obj_ */ } - /* "pysam/libcfaidx.pyx":504 + /* "pysam/libcfaidx.pyx":597 * self.entry = NULL * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -9265,7 +9943,7 @@ static void __pyx_pf_5pysam_9libcfaidx_9FastxFile_8__dealloc__(struct __pyx_obj_ __Pyx_RefNannyFinishContext(); } -/* "pysam/libcfaidx.pyx":511 +/* "pysam/libcfaidx.pyx":604 * * # context manager interface * def __enter__(self): # <<<<<<<<<<<<<< @@ -9292,9 +9970,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_10__enter__(struct __pyx_ __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__enter__", 0); - __Pyx_TraceCall("__enter__", __pyx_f[0], 511, 0, __PYX_ERR(0, 511, __pyx_L1_error)); + __Pyx_TraceCall("__enter__", __pyx_f[0], 604, 0, __PYX_ERR(0, 604, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":512 + /* "pysam/libcfaidx.pyx":605 * # context manager interface * def __enter__(self): * return self # <<<<<<<<<<<<<< @@ -9306,7 +9984,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_10__enter__(struct __pyx_ __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcfaidx.pyx":511 + /* "pysam/libcfaidx.pyx":604 * * # context manager interface * def __enter__(self): # <<<<<<<<<<<<<< @@ -9325,7 +10003,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_10__enter__(struct __pyx_ return __pyx_r; } -/* "pysam/libcfaidx.pyx":514 +/* "pysam/libcfaidx.pyx":607 * return self * * def __exit__(self, exc_type, exc_value, traceback): # <<<<<<<<<<<<<< @@ -9368,17 +10046,17 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastxFile_13__exit__(PyObject *__py case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_exc_value)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 514, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 607, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_traceback)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 514, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 607, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 514, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 607, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -9393,7 +10071,7 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_9FastxFile_13__exit__(PyObject *__py } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 514, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 607, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcfaidx.FastxFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -9414,16 +10092,16 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_12__exit__(struct __pyx_o PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__exit__", 0); - __Pyx_TraceCall("__exit__", __pyx_f[0], 514, 0, __PYX_ERR(0, 514, __pyx_L1_error)); + __Pyx_TraceCall("__exit__", __pyx_f[0], 607, 0, __PYX_ERR(0, 607, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":515 + /* "pysam/libcfaidx.pyx":608 * * def __exit__(self, exc_type, exc_value, traceback): * self.close() # <<<<<<<<<<<<<< * return False * */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 515, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 608, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -9436,16 +10114,16 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_12__exit__(struct __pyx_o } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 515, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 608, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 515, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 608, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcfaidx.pyx":516 + /* "pysam/libcfaidx.pyx":609 * def __exit__(self, exc_type, exc_value, traceback): * self.close() * return False # <<<<<<<<<<<<<< @@ -9457,7 +10135,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_12__exit__(struct __pyx_o __pyx_r = Py_False; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":514 + /* "pysam/libcfaidx.pyx":607 * return self * * def __exit__(self, exc_type, exc_value, traceback): # <<<<<<<<<<<<<< @@ -9479,7 +10157,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_12__exit__(struct __pyx_o return __pyx_r; } -/* "pysam/libcfaidx.pyx":522 +/* "pysam/libcfaidx.pyx":615 * This is a read-only attribute; the close() method changes the value. * """ * def __get__(self): # <<<<<<<<<<<<<< @@ -9509,9 +10187,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6closed___get__(struct __ PyObject *__pyx_t_3 = NULL; int __pyx_t_4; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 522, 0, __PYX_ERR(0, 522, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 615, 0, __PYX_ERR(0, 615, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":523 + /* "pysam/libcfaidx.pyx":616 * """ * def __get__(self): * return not self.is_open() # <<<<<<<<<<<<<< @@ -9519,7 +10197,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6closed___get__(struct __ * property filename: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 523, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 616, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -9532,22 +10210,22 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6closed___get__(struct __ } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 523, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 616, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 523, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 616, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 523, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 616, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_4)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 523, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_4)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 616, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":522 + /* "pysam/libcfaidx.pyx":615 * This is a read-only attribute; the close() method changes the value. * """ * def __get__(self): # <<<<<<<<<<<<<< @@ -9569,7 +10247,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_6closed___get__(struct __ return __pyx_r; } -/* "pysam/libcfaidx.pyx":527 +/* "pysam/libcfaidx.pyx":620 * property filename: * """string with the filename associated with this object.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -9595,9 +10273,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_8filename___get__(struct __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 527, 0, __PYX_ERR(0, 527, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 620, 0, __PYX_ERR(0, 620, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":528 + /* "pysam/libcfaidx.pyx":621 * """string with the filename associated with this object.""" * def __get__(self): * return self._filename # <<<<<<<<<<<<<< @@ -9609,7 +10287,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_8filename___get__(struct __pyx_r = __pyx_v_self->_filename; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":527 + /* "pysam/libcfaidx.pyx":620 * property filename: * """string with the filename associated with this object.""" * def __get__(self): # <<<<<<<<<<<<<< @@ -9628,7 +10306,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_8filename___get__(struct return __pyx_r; } -/* "pysam/libcfaidx.pyx":530 +/* "pysam/libcfaidx.pyx":623 * return self._filename * * def __iter__(self): # <<<<<<<<<<<<<< @@ -9659,16 +10337,16 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_14__iter__(struct __pyx_o int __pyx_t_4; int __pyx_t_5; __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 530, 0, __PYX_ERR(0, 530, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 623, 0, __PYX_ERR(0, 623, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":531 + /* "pysam/libcfaidx.pyx":624 * * def __iter__(self): * if not self.is_open(): # <<<<<<<<<<<<<< * raise ValueError("I/O operation on closed file") * return self */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 531, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 624, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -9681,32 +10359,32 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_14__iter__(struct __pyx_o } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 531, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 624, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 531, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 624, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 531, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 624, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_5 = ((!__pyx_t_4) != 0); if (unlikely(__pyx_t_5)) { - /* "pysam/libcfaidx.pyx":532 + /* "pysam/libcfaidx.pyx":625 * def __iter__(self): * if not self.is_open(): * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< * return self * */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 532, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 625, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 532, __pyx_L1_error) + __PYX_ERR(0, 625, __pyx_L1_error) - /* "pysam/libcfaidx.pyx":531 + /* "pysam/libcfaidx.pyx":624 * * def __iter__(self): * if not self.is_open(): # <<<<<<<<<<<<<< @@ -9715,7 +10393,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_14__iter__(struct __pyx_o */ } - /* "pysam/libcfaidx.pyx":533 + /* "pysam/libcfaidx.pyx":626 * if not self.is_open(): * raise ValueError("I/O operation on closed file") * return self # <<<<<<<<<<<<<< @@ -9727,7 +10405,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_14__iter__(struct __pyx_o __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libcfaidx.pyx":530 + /* "pysam/libcfaidx.pyx":623 * return self._filename * * def __iter__(self): # <<<<<<<<<<<<<< @@ -9749,7 +10427,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_14__iter__(struct __pyx_o return __pyx_r; } -/* "pysam/libcfaidx.pyx":535 +/* "pysam/libcfaidx.pyx":628 * return self * * cdef kseq_t * getCurrent(self): # <<<<<<<<<<<<<< @@ -9762,9 +10440,9 @@ static kseq_t *__pyx_f_5pysam_9libcfaidx_9FastxFile_getCurrent(struct __pyx_obj_ __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCurrent", 0); - __Pyx_TraceCall("getCurrent", __pyx_f[0], 535, 0, __PYX_ERR(0, 535, __pyx_L1_error)); + __Pyx_TraceCall("getCurrent", __pyx_f[0], 628, 0, __PYX_ERR(0, 628, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":536 + /* "pysam/libcfaidx.pyx":629 * * cdef kseq_t * getCurrent(self): * return self.entry # <<<<<<<<<<<<<< @@ -9774,7 +10452,7 @@ static kseq_t *__pyx_f_5pysam_9libcfaidx_9FastxFile_getCurrent(struct __pyx_obj_ __pyx_r = __pyx_v_self->entry; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":535 + /* "pysam/libcfaidx.pyx":628 * return self * * cdef kseq_t * getCurrent(self): # <<<<<<<<<<<<<< @@ -9792,7 +10470,7 @@ static kseq_t *__pyx_f_5pysam_9libcfaidx_9FastxFile_getCurrent(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libcfaidx.pyx":538 +/* "pysam/libcfaidx.pyx":631 * return self.entry * * cdef int cnext(self): # <<<<<<<<<<<<<< @@ -9805,9 +10483,9 @@ static int __pyx_f_5pysam_9libcfaidx_9FastxFile_cnext(struct __pyx_obj_5pysam_9l __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("cnext", 0); - __Pyx_TraceCall("cnext", __pyx_f[0], 538, 0, __PYX_ERR(0, 538, __pyx_L1_error)); + __Pyx_TraceCall("cnext", __pyx_f[0], 631, 0, __PYX_ERR(0, 631, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":541 + /* "pysam/libcfaidx.pyx":634 * '''C version of iterator * ''' * with nogil: # <<<<<<<<<<<<<< @@ -9822,7 +10500,7 @@ static int __pyx_f_5pysam_9libcfaidx_9FastxFile_cnext(struct __pyx_obj_5pysam_9l #endif /*try:*/ { - /* "pysam/libcfaidx.pyx":542 + /* "pysam/libcfaidx.pyx":635 * ''' * with nogil: * return kseq_read(self.entry) # <<<<<<<<<<<<<< @@ -9833,7 +10511,7 @@ static int __pyx_f_5pysam_9libcfaidx_9FastxFile_cnext(struct __pyx_obj_5pysam_9l goto __pyx_L3_return; } - /* "pysam/libcfaidx.pyx":541 + /* "pysam/libcfaidx.pyx":634 * '''C version of iterator * ''' * with nogil: # <<<<<<<<<<<<<< @@ -9851,7 +10529,7 @@ static int __pyx_f_5pysam_9libcfaidx_9FastxFile_cnext(struct __pyx_obj_5pysam_9l } } - /* "pysam/libcfaidx.pyx":538 + /* "pysam/libcfaidx.pyx":631 * return self.entry * * cdef int cnext(self): # <<<<<<<<<<<<<< @@ -9869,7 +10547,7 @@ static int __pyx_f_5pysam_9libcfaidx_9FastxFile_cnext(struct __pyx_obj_5pysam_9l return __pyx_r; } -/* "pysam/libcfaidx.pyx":544 +/* "pysam/libcfaidx.pyx":637 * return kseq_read(self.entry) * * def __next__(self): # <<<<<<<<<<<<<< @@ -9903,9 +10581,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_16__next__(struct __pyx_o PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 544, 0, __PYX_ERR(0, 544, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 637, 0, __PYX_ERR(0, 637, __pyx_L1_error)); - /* "pysam/libcfaidx.pyx":549 + /* "pysam/libcfaidx.pyx":642 * """ * cdef int l * with nogil: # <<<<<<<<<<<<<< @@ -9920,7 +10598,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_16__next__(struct __pyx_o #endif /*try:*/ { - /* "pysam/libcfaidx.pyx":550 + /* "pysam/libcfaidx.pyx":643 * cdef int l * with nogil: * l = kseq_read(self.entry) # <<<<<<<<<<<<<< @@ -9930,7 +10608,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_16__next__(struct __pyx_o __pyx_v_l = kseq_read(__pyx_v_self->entry); } - /* "pysam/libcfaidx.pyx":549 + /* "pysam/libcfaidx.pyx":642 * """ * cdef int l * with nogil: # <<<<<<<<<<<<<< @@ -9949,76 +10627,80 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_16__next__(struct __pyx_o } } - /* "pysam/libcfaidx.pyx":551 + /* "pysam/libcfaidx.pyx":644 * with nogil: * l = kseq_read(self.entry) * if (l >= 0): # <<<<<<<<<<<<<< * if self.persist: - * return PersistentFastqProxy(makeFastqProxy(self.entry)) + * return FastxRecord(proxy=makeFastqProxy(self.entry)) */ __pyx_t_1 = ((__pyx_v_l >= 0) != 0); if (likely(__pyx_t_1)) { - /* "pysam/libcfaidx.pyx":552 + /* "pysam/libcfaidx.pyx":645 * l = kseq_read(self.entry) * if (l >= 0): * if self.persist: # <<<<<<<<<<<<<< - * return PersistentFastqProxy(makeFastqProxy(self.entry)) + * return FastxRecord(proxy=makeFastqProxy(self.entry)) * return makeFastqProxy(self.entry) */ __pyx_t_1 = (__pyx_v_self->persist != 0); if (__pyx_t_1) { - /* "pysam/libcfaidx.pyx":553 + /* "pysam/libcfaidx.pyx":646 * if (l >= 0): * if self.persist: - * return PersistentFastqProxy(makeFastqProxy(self.entry)) # <<<<<<<<<<<<<< + * return FastxRecord(proxy=makeFastqProxy(self.entry)) # <<<<<<<<<<<<<< * return makeFastqProxy(self.entry) * else: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_f_5pysam_9libcfaidx_makeFastqProxy(__pyx_v_self->entry); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 553, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 646, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy), __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 553, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcfaidx_makeFastqProxy(__pyx_v_self->entry); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 646, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_proxy, __pyx_t_3) < 0) __PYX_ERR(0, 646, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_9libcfaidx_FastxRecord), __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 646, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":552 + /* "pysam/libcfaidx.pyx":645 * l = kseq_read(self.entry) * if (l >= 0): * if self.persist: # <<<<<<<<<<<<<< - * return PersistentFastqProxy(makeFastqProxy(self.entry)) + * return FastxRecord(proxy=makeFastqProxy(self.entry)) * return makeFastqProxy(self.entry) */ } - /* "pysam/libcfaidx.pyx":554 + /* "pysam/libcfaidx.pyx":647 * if self.persist: - * return PersistentFastqProxy(makeFastqProxy(self.entry)) + * return FastxRecord(proxy=makeFastqProxy(self.entry)) * return makeFastqProxy(self.entry) # <<<<<<<<<<<<<< * else: * raise StopIteration */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __pyx_f_5pysam_9libcfaidx_makeFastqProxy(__pyx_v_self->entry); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 554, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcfaidx_makeFastqProxy(__pyx_v_self->entry); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 647, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcfaidx.pyx":551 + /* "pysam/libcfaidx.pyx":644 * with nogil: * l = kseq_read(self.entry) * if (l >= 0): # <<<<<<<<<<<<<< * if self.persist: - * return PersistentFastqProxy(makeFastqProxy(self.entry)) + * return FastxRecord(proxy=makeFastqProxy(self.entry)) */ } - /* "pysam/libcfaidx.pyx":556 + /* "pysam/libcfaidx.pyx":649 * return makeFastqProxy(self.entry) * else: * raise StopIteration # <<<<<<<<<<<<<< @@ -10027,10 +10709,10 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_16__next__(struct __pyx_o */ /*else*/ { __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 556, __pyx_L1_error) + __PYX_ERR(0, 649, __pyx_L1_error) } - /* "pysam/libcfaidx.pyx":544 + /* "pysam/libcfaidx.pyx":637 * return kseq_read(self.entry) * * def __next__(self): # <<<<<<<<<<<<<< @@ -10085,7 +10767,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_18__reduce_cython__(CYTHO * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10142,7 +10824,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastxFile_20__setstate_cython__(CYT * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10200,7 +10882,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastqFile___reduce_cython__(CYTHON_ * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10257,7 +10939,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9FastqFile_2__setstate_cython__(CYTH * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10315,7 +10997,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9Fastafile___reduce_cython__(CYTHON_ * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10372,7 +11054,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9Fastafile_2__setstate_cython__(CYTH * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10397,22 +11079,22 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx_9Fastafile_2__setstate_cython__(CYTH } /* "(tree fragment)":1 - * def __pyx_unpickle_PersistentFastqProxy(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * def __pyx_unpickle_FastxRecord(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x43fd151: * from pickle import PickleError as __pyx_PickleError */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libcfaidx_1__pyx_unpickle_PersistentFastqProxy(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy[] = "__pyx_unpickle_PersistentFastqProxy(__pyx_type, long __pyx_checksum, __pyx_state)"; -static PyMethodDef __pyx_mdef_5pysam_9libcfaidx_1__pyx_unpickle_PersistentFastqProxy = {"__pyx_unpickle_PersistentFastqProxy", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_1__pyx_unpickle_PersistentFastqProxy, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy}; -static PyObject *__pyx_pw_5pysam_9libcfaidx_1__pyx_unpickle_PersistentFastqProxy(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_9libcfaidx_1__pyx_unpickle_FastxRecord(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_9libcfaidx___pyx_unpickle_FastxRecord[] = "__pyx_unpickle_FastxRecord(__pyx_type, long __pyx_checksum, __pyx_state)"; +static PyMethodDef __pyx_mdef_5pysam_9libcfaidx_1__pyx_unpickle_FastxRecord = {"__pyx_unpickle_FastxRecord", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_1__pyx_unpickle_FastxRecord, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libcfaidx___pyx_unpickle_FastxRecord}; +static PyObject *__pyx_pw_5pysam_9libcfaidx_1__pyx_unpickle_FastxRecord(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v___pyx_type = 0; long __pyx_v___pyx_checksum; PyObject *__pyx_v___pyx_state = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__pyx_unpickle_PersistentFastqProxy (wrapper)", 0); + __Pyx_RefNannySetupContext("__pyx_unpickle_FastxRecord (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; PyObject* values[3] = {0,0,0}; @@ -10438,17 +11120,17 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_1__pyx_unpickle_PersistentFastqProxy case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PersistentFastqProxy", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_FastxRecord", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PersistentFastqProxy", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_FastxRecord", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_PersistentFastqProxy") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_FastxRecord") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -10463,20 +11145,20 @@ static PyObject *__pyx_pw_5pysam_9libcfaidx_1__pyx_unpickle_PersistentFastqProxy } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PersistentFastqProxy", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_FastxRecord", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libcfaidx.__pyx_unpickle_PersistentFastqProxy", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.__pyx_unpickle_FastxRecord", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + __pyx_r = __pyx_pf_5pysam_9libcfaidx___pyx_unpickle_FastxRecord(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_FastxRecord(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_v___pyx_PickleError = NULL; PyObject *__pyx_v___pyx_result = NULL; PyObject *__pyx_r = NULL; @@ -10489,12 +11171,12 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy( PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__22) - __Pyx_RefNannySetupContext("__pyx_unpickle_PersistentFastqProxy", 0); - __Pyx_TraceCall("__pyx_unpickle_PersistentFastqProxy", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceFrameInit(__pyx_codeobj__20) + __Pyx_RefNannySetupContext("__pyx_unpickle_FastxRecord", 0); + __Pyx_TraceCall("__pyx_unpickle_FastxRecord", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); /* "(tree fragment)":2 - * def __pyx_unpickle_PersistentFastqProxy(__pyx_type, long __pyx_checksum, __pyx_state): + * def __pyx_unpickle_FastxRecord(__pyx_type, long __pyx_checksum, __pyx_state): * if __pyx_checksum != 0x43fd151: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x43fd151 = (comment, name, quality, sequence))" % __pyx_checksum) @@ -10503,11 +11185,11 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy( if (__pyx_t_1) { /* "(tree fragment)":3 - * def __pyx_unpickle_PersistentFastqProxy(__pyx_type, long __pyx_checksum, __pyx_state): + * def __pyx_unpickle_FastxRecord(__pyx_type, long __pyx_checksum, __pyx_state): * if __pyx_checksum != 0x43fd151: * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< * raise __pyx_PickleError("Incompatible checksums (%s vs 0x43fd151 = (comment, name, quality, sequence))" % __pyx_checksum) - * __pyx_result = PersistentFastqProxy.__new__(__pyx_type) + * __pyx_result = FastxRecord.__new__(__pyx_type) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); @@ -10528,7 +11210,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy( * if __pyx_checksum != 0x43fd151: * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x43fd151 = (comment, name, quality, sequence))" % __pyx_checksum) # <<<<<<<<<<<<<< - * __pyx_result = PersistentFastqProxy.__new__(__pyx_type) + * __pyx_result = FastxRecord.__new__(__pyx_type) * if __pyx_state is not None: */ __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) @@ -10588,7 +11270,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy( __PYX_ERR(1, 4, __pyx_L1_error) /* "(tree fragment)":2 - * def __pyx_unpickle_PersistentFastqProxy(__pyx_type, long __pyx_checksum, __pyx_state): + * def __pyx_unpickle_FastxRecord(__pyx_type, long __pyx_checksum, __pyx_state): * if __pyx_checksum != 0x43fd151: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x43fd151 = (comment, name, quality, sequence))" % __pyx_checksum) @@ -10598,11 +11280,11 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy( /* "(tree fragment)":5 * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x43fd151 = (comment, name, quality, sequence))" % __pyx_checksum) - * __pyx_result = PersistentFastqProxy.__new__(__pyx_type) # <<<<<<<<<<<<<< + * __pyx_result = FastxRecord.__new__(__pyx_type) # <<<<<<<<<<<<<< * if __pyx_state is not None: - * __pyx_unpickle_PersistentFastqProxy__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_FastxRecord__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_9libcfaidx_FastxRecord), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -10652,9 +11334,9 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy( /* "(tree fragment)":6 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x43fd151 = (comment, name, quality, sequence))" % __pyx_checksum) - * __pyx_result = PersistentFastqProxy.__new__(__pyx_type) + * __pyx_result = FastxRecord.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< - * __pyx_unpickle_PersistentFastqProxy__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_FastxRecord__set_state( __pyx_result, __pyx_state) * return __pyx_result */ __pyx_t_1 = (__pyx_v___pyx_state != Py_None); @@ -10662,31 +11344,31 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy( if (__pyx_t_7) { /* "(tree fragment)":7 - * __pyx_result = PersistentFastqProxy.__new__(__pyx_type) + * __pyx_result = FastxRecord.__new__(__pyx_type) * if __pyx_state is not None: - * __pyx_unpickle_PersistentFastqProxy__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * __pyx_unpickle_FastxRecord__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< * return __pyx_result - * cdef __pyx_unpickle_PersistentFastqProxy__set_state(PersistentFastqProxy __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_FastxRecord__set_state(FastxRecord __pyx_result, tuple __pyx_state): */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy__set_state(((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcfaidx___pyx_unpickle_FastxRecord__set_state(((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":6 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x43fd151 = (comment, name, quality, sequence))" % __pyx_checksum) - * __pyx_result = PersistentFastqProxy.__new__(__pyx_type) + * __pyx_result = FastxRecord.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< - * __pyx_unpickle_PersistentFastqProxy__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_FastxRecord__set_state( __pyx_result, __pyx_state) * return __pyx_result */ } /* "(tree fragment)":8 * if __pyx_state is not None: - * __pyx_unpickle_PersistentFastqProxy__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_FastxRecord__set_state( __pyx_result, __pyx_state) * return __pyx_result # <<<<<<<<<<<<<< - * cdef __pyx_unpickle_PersistentFastqProxy__set_state(PersistentFastqProxy __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_FastxRecord__set_state(FastxRecord __pyx_result, tuple __pyx_state): * __pyx_result.comment = __pyx_state[0]; __pyx_result.name = __pyx_state[1]; __pyx_result.quality = __pyx_state[2]; __pyx_result.sequence = __pyx_state[3] */ __Pyx_XDECREF(__pyx_r); @@ -10695,7 +11377,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy( goto __pyx_L0; /* "(tree fragment)":1 - * def __pyx_unpickle_PersistentFastqProxy(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * def __pyx_unpickle_FastxRecord(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x43fd151: * from pickle import PickleError as __pyx_PickleError */ @@ -10707,7 +11389,7 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy( __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libcfaidx.__pyx_unpickle_PersistentFastqProxy", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.__pyx_unpickle_FastxRecord", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v___pyx_PickleError); @@ -10719,14 +11401,14 @@ static PyObject *__pyx_pf_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy( } /* "(tree fragment)":9 - * __pyx_unpickle_PersistentFastqProxy__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_FastxRecord__set_state( __pyx_result, __pyx_state) * return __pyx_result - * cdef __pyx_unpickle_PersistentFastqProxy__set_state(PersistentFastqProxy __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_FastxRecord__set_state(FastxRecord __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.comment = __pyx_state[0]; __pyx_result.name = __pyx_state[1]; __pyx_result.quality = __pyx_state[2]; __pyx_result.sequence = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): */ -static PyObject *__pyx_f_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy__set_state(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_f_5pysam_9libcfaidx___pyx_unpickle_FastxRecord__set_state(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -10739,12 +11421,12 @@ static PyObject *__pyx_f_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy__ PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; - __Pyx_RefNannySetupContext("__pyx_unpickle_PersistentFastqProxy__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_PersistentFastqProxy__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__pyx_unpickle_FastxRecord__set_state", 0); + __Pyx_TraceCall("__pyx_unpickle_FastxRecord__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result - * cdef __pyx_unpickle_PersistentFastqProxy__set_state(PersistentFastqProxy __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_FastxRecord__set_state(FastxRecord __pyx_result, tuple __pyx_state): * __pyx_result.comment = __pyx_state[0]; __pyx_result.name = __pyx_state[1]; __pyx_result.quality = __pyx_state[2]; __pyx_result.sequence = __pyx_state[3] # <<<<<<<<<<<<<< * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[4]) @@ -10799,7 +11481,7 @@ static PyObject *__pyx_f_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy__ __pyx_t_1 = 0; /* "(tree fragment)":11 - * cdef __pyx_unpickle_PersistentFastqProxy__set_state(PersistentFastqProxy __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_FastxRecord__set_state(FastxRecord __pyx_result, tuple __pyx_state): * __pyx_result.comment = __pyx_state[0]; __pyx_result.name = __pyx_state[1]; __pyx_result.quality = __pyx_state[2]; __pyx_result.sequence = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[4]) @@ -10886,7 +11568,7 @@ static PyObject *__pyx_f_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy__ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":11 - * cdef __pyx_unpickle_PersistentFastqProxy__set_state(PersistentFastqProxy __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_FastxRecord__set_state(FastxRecord __pyx_result, tuple __pyx_state): * __pyx_result.comment = __pyx_state[0]; __pyx_result.name = __pyx_state[1]; __pyx_result.quality = __pyx_state[2]; __pyx_result.sequence = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[4]) @@ -10894,9 +11576,9 @@ static PyObject *__pyx_f_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy__ } /* "(tree fragment)":9 - * __pyx_unpickle_PersistentFastqProxy__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_FastxRecord__set_state( __pyx_result, __pyx_state) * return __pyx_result - * cdef __pyx_unpickle_PersistentFastqProxy__set_state(PersistentFastqProxy __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_FastxRecord__set_state(FastxRecord __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.comment = __pyx_state[0]; __pyx_result.name = __pyx_state[1]; __pyx_result.quality = __pyx_state[2]; __pyx_result.sequence = __pyx_state[3] * if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'): */ @@ -10910,7 +11592,7 @@ static PyObject *__pyx_f_5pysam_9libcfaidx___pyx_unpickle_PersistentFastqProxy__ __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libcfaidx.__pyx_unpickle_PersistentFastqProxy__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libcfaidx.__pyx_unpickle_FastxRecord__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -11760,7 +12442,7 @@ static PyTypeObject __pyx_type_5pysam_9libcfaidx_FastaFile = { 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "Random access to fasta formatted files that\n have been indexed by :term:`faidx`.\n\n The file is automatically opened. The index file of file\n ```` is expected to be called ``.fai``.\n\n Parameters\n ----------\n\n filename : string\n Filename of fasta file to be opened.\n\n filepath_index : string\n Optional, filename of the index. By default this is\n the filename + \".fai\".\n\n Raises\n ------\n\n ValueError\n if index file is missing\n\n IOError\n if file could not be opened\n\n ", /*tp_doc*/ + "Random access to fasta formatted files that\n have been indexed by :term:`faidx`.\n\n The file is automatically opened. The index file of file\n ```` is expected to be called ``.fai``.\n\n Parameters\n ----------\n\n filename : string\n Filename of fasta file to be opened.\n\n filepath_index : string\n Optional, filename of the index. By default this is\n the filename + \".fai\".\n\n filepath_index_compressed : string\n Optional, filename of the index if fasta file is. By default this is\n the filename + \".gzi\".\n\n Raises\n ------\n\n ValueError\n if index file is missing\n\n IOError\n if file could not be opened\n\n ", /*tp_doc*/ __pyx_tp_traverse_5pysam_9libcfaidx_FastaFile, /*tp_traverse*/ __pyx_tp_clear_5pysam_9libcfaidx_FastaFile, /*tp_clear*/ 0, /*tp_richcompare*/ @@ -11904,10 +12586,10 @@ static PyTypeObject __pyx_type_5pysam_9libcfaidx_FastqProxy = { 0, /*tp_finalize*/ #endif }; -static struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy __pyx_vtable_5pysam_9libcfaidx_PersistentFastqProxy; +static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord __pyx_vtable_5pysam_9libcfaidx_FastxRecord; -static PyObject *__pyx_tp_new_5pysam_9libcfaidx_PersistentFastqProxy(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *p; +static PyObject *__pyx_tp_new_5pysam_9libcfaidx_FastxRecord(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *p; PyObject *o; if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { o = (*t->tp_alloc)(t, 0); @@ -11915,8 +12597,8 @@ static PyObject *__pyx_tp_new_5pysam_9libcfaidx_PersistentFastqProxy(PyTypeObjec o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); } if (unlikely(!o)) return 0; - p = ((struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)o); - p->__pyx_vtab = __pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy; + p = ((struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)o); + p->__pyx_vtab = __pyx_vtabptr_5pysam_9libcfaidx_FastxRecord; p->comment = ((PyObject*)Py_None); Py_INCREF(Py_None); p->quality = ((PyObject*)Py_None); Py_INCREF(Py_None); p->sequence = ((PyObject*)Py_None); Py_INCREF(Py_None); @@ -11924,8 +12606,8 @@ static PyObject *__pyx_tp_new_5pysam_9libcfaidx_PersistentFastqProxy(PyTypeObjec return o; } -static void __pyx_tp_dealloc_5pysam_9libcfaidx_PersistentFastqProxy(PyObject *o) { - struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *p = (struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *)o; +static void __pyx_tp_dealloc_5pysam_9libcfaidx_FastxRecord(PyObject *o) { + struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *p = (struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *)o; #if CYTHON_USE_TP_FINALIZE if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { if (PyObject_CallFinalizerFromDealloc(o)) return; @@ -11938,79 +12620,84 @@ static void __pyx_tp_dealloc_5pysam_9libcfaidx_PersistentFastqProxy(PyObject *o) (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5pysam_9libcfaidx_20PersistentFastqProxy_comment(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_1__get__(o); +static PyObject *__pyx_getprop_5pysam_9libcfaidx_11FastxRecord_comment(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7comment_1__get__(o); } -static int __pyx_setprop_5pysam_9libcfaidx_20PersistentFastqProxy_comment(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { +static int __pyx_setprop_5pysam_9libcfaidx_11FastxRecord_comment(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { - return __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_3__set__(o, v); + return __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7comment_3__set__(o, v); } else { - return __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7comment_5__del__(o); + return __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7comment_5__del__(o); } } -static PyObject *__pyx_getprop_5pysam_9libcfaidx_20PersistentFastqProxy_quality(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_1__get__(o); +static PyObject *__pyx_getprop_5pysam_9libcfaidx_11FastxRecord_quality(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7quality_1__get__(o); } -static int __pyx_setprop_5pysam_9libcfaidx_20PersistentFastqProxy_quality(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { +static int __pyx_setprop_5pysam_9libcfaidx_11FastxRecord_quality(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { - return __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_3__set__(o, v); + return __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7quality_3__set__(o, v); } else { - return __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7quality_5__del__(o); + return __pyx_pw_5pysam_9libcfaidx_11FastxRecord_7quality_5__del__(o); } } -static PyObject *__pyx_getprop_5pysam_9libcfaidx_20PersistentFastqProxy_sequence(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_1__get__(o); +static PyObject *__pyx_getprop_5pysam_9libcfaidx_11FastxRecord_sequence(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_9libcfaidx_11FastxRecord_8sequence_1__get__(o); } -static int __pyx_setprop_5pysam_9libcfaidx_20PersistentFastqProxy_sequence(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { +static int __pyx_setprop_5pysam_9libcfaidx_11FastxRecord_sequence(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { - return __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_3__set__(o, v); + return __pyx_pw_5pysam_9libcfaidx_11FastxRecord_8sequence_3__set__(o, v); } else { - return __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_8sequence_5__del__(o); + return __pyx_pw_5pysam_9libcfaidx_11FastxRecord_8sequence_5__del__(o); } } -static PyObject *__pyx_getprop_5pysam_9libcfaidx_20PersistentFastqProxy_name(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_4name_1__get__(o); +static PyObject *__pyx_getprop_5pysam_9libcfaidx_11FastxRecord_name(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_9libcfaidx_11FastxRecord_4name_1__get__(o); } -static int __pyx_setprop_5pysam_9libcfaidx_20PersistentFastqProxy_name(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { +static int __pyx_setprop_5pysam_9libcfaidx_11FastxRecord_name(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { - return __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_4name_3__set__(o, v); + return __pyx_pw_5pysam_9libcfaidx_11FastxRecord_4name_3__set__(o, v); } else { - return __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_4name_5__del__(o); + return __pyx_pw_5pysam_9libcfaidx_11FastxRecord_4name_5__del__(o); } } -static PyMethodDef __pyx_methods_5pysam_9libcfaidx_PersistentFastqProxy[] = { - {"get_quality_array", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_5get_quality_array, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libcfaidx_20PersistentFastqProxy_4get_quality_array}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_7__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_9libcfaidx_20PersistentFastqProxy_6__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_9__setstate_cython__, METH_O, __pyx_doc_5pysam_9libcfaidx_20PersistentFastqProxy_8__setstate_cython__}, +static PyMethodDef __pyx_methods_5pysam_9libcfaidx_FastxRecord[] = { + {"__copy__", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_11FastxRecord_3__copy__, METH_NOARGS, __pyx_doc_5pysam_9libcfaidx_11FastxRecord_2__copy__}, + {"__deepcopy__", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_11FastxRecord_5__deepcopy__, METH_O, __pyx_doc_5pysam_9libcfaidx_11FastxRecord_4__deepcopy__}, + {"set_name", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_11FastxRecord_7set_name, METH_O, __pyx_doc_5pysam_9libcfaidx_11FastxRecord_6set_name}, + {"set_comment", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_11FastxRecord_9set_comment, METH_O, __pyx_doc_5pysam_9libcfaidx_11FastxRecord_8set_comment}, + {"set_sequence", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_11FastxRecord_11set_sequence, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libcfaidx_11FastxRecord_10set_sequence}, + {"get_quality_array", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_11FastxRecord_15get_quality_array, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libcfaidx_11FastxRecord_14get_quality_array}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_11FastxRecord_17__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_9libcfaidx_11FastxRecord_16__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_9libcfaidx_11FastxRecord_19__setstate_cython__, METH_O, __pyx_doc_5pysam_9libcfaidx_11FastxRecord_18__setstate_cython__}, {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5pysam_9libcfaidx_PersistentFastqProxy[] = { - {(char *)"comment", __pyx_getprop_5pysam_9libcfaidx_20PersistentFastqProxy_comment, __pyx_setprop_5pysam_9libcfaidx_20PersistentFastqProxy_comment, (char *)"comment: str", 0}, - {(char *)"quality", __pyx_getprop_5pysam_9libcfaidx_20PersistentFastqProxy_quality, __pyx_setprop_5pysam_9libcfaidx_20PersistentFastqProxy_quality, (char *)"quality: str", 0}, - {(char *)"sequence", __pyx_getprop_5pysam_9libcfaidx_20PersistentFastqProxy_sequence, __pyx_setprop_5pysam_9libcfaidx_20PersistentFastqProxy_sequence, (char *)"sequence: str", 0}, - {(char *)"name", __pyx_getprop_5pysam_9libcfaidx_20PersistentFastqProxy_name, __pyx_setprop_5pysam_9libcfaidx_20PersistentFastqProxy_name, (char *)"name: str", 0}, +static struct PyGetSetDef __pyx_getsets_5pysam_9libcfaidx_FastxRecord[] = { + {(char *)"comment", __pyx_getprop_5pysam_9libcfaidx_11FastxRecord_comment, __pyx_setprop_5pysam_9libcfaidx_11FastxRecord_comment, (char *)"comment: str", 0}, + {(char *)"quality", __pyx_getprop_5pysam_9libcfaidx_11FastxRecord_quality, __pyx_setprop_5pysam_9libcfaidx_11FastxRecord_quality, (char *)"quality: str", 0}, + {(char *)"sequence", __pyx_getprop_5pysam_9libcfaidx_11FastxRecord_sequence, __pyx_setprop_5pysam_9libcfaidx_11FastxRecord_sequence, (char *)"sequence: str", 0}, + {(char *)"name", __pyx_getprop_5pysam_9libcfaidx_11FastxRecord_name, __pyx_setprop_5pysam_9libcfaidx_11FastxRecord_name, (char *)"name: str", 0}, {0, 0, 0, 0, 0} }; -static PyTypeObject __pyx_type_5pysam_9libcfaidx_PersistentFastqProxy = { +static PyTypeObject __pyx_type_5pysam_9libcfaidx_FastxRecord = { PyVarObject_HEAD_INIT(0, 0) - "pysam.libcfaidx.PersistentFastqProxy", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy), /*tp_basicsize*/ + "pysam.libcfaidx.FastxRecord", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_9libcfaidx_PersistentFastqProxy, /*tp_dealloc*/ + __pyx_tp_dealloc_5pysam_9libcfaidx_FastxRecord, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -12026,29 +12713,29 @@ static PyTypeObject __pyx_type_5pysam_9libcfaidx_PersistentFastqProxy = { 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_3__str__, /*tp_str*/ + __pyx_pw_5pysam_9libcfaidx_11FastxRecord_13__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ - "PersistentFastqProxy(FastqProxy FastqRead)\n\n Python container for pysam.libcfaidx.FastqProxy with persistence.\n Needed to compare multiple fastq records from the same file.\n ", /*tp_doc*/ + "FastxRecord(name=None, comment=None, sequence=None, quality=None, FastqProxy proxy=None)\nA fasta/fastq record.\n\n A record must contain a name and a sequence. If either of them are\n None, a ValueError is raised on writing.\n\n ", /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5pysam_9libcfaidx_PersistentFastqProxy, /*tp_methods*/ + __pyx_methods_5pysam_9libcfaidx_FastxRecord, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5pysam_9libcfaidx_PersistentFastqProxy, /*tp_getset*/ + __pyx_getsets_5pysam_9libcfaidx_FastxRecord, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ - __pyx_pw_5pysam_9libcfaidx_20PersistentFastqProxy_1__init__, /*tp_init*/ + __pyx_pw_5pysam_9libcfaidx_11FastxRecord_1__init__, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_9libcfaidx_PersistentFastqProxy, /*tp_new*/ + __pyx_tp_new_5pysam_9libcfaidx_FastxRecord, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -12173,7 +12860,7 @@ static PyTypeObject __pyx_type_5pysam_9libcfaidx_FastxFile = { 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "Stream access to :term:`fasta` or :term:`fastq` formatted files.\n\n The file is automatically opened.\n\n Entries in the file can be both fastq or fasta formatted or even a\n mixture of the two.\n\n This file object permits iterating over all entries in the\n file. Random access is not implemented. The iteration returns\n objects of type :class:`FastqProxy`\n\n Parameters\n ----------\n\n filename : string\n Filename of fasta/fastq file to be opened.\n\n persist : bool\n\n If True (default) make a copy of the entry in the file during\n iteration. If set to False, no copy will be made. This will\n permit faster iteration, but an entry will not persist when\n the iteration continues.\n\n Notes\n -----\n Prior to version 0.8.2, this was called FastqFile.\n\n Raises\n ------\n\n IOError\n if file could not be opened\n\n\n Examples\n --------\n >>> with pysam.FastxFile(filename) as fh:\n ... for entry in fh:\n ... print(entry.name)\n ... print(entry.sequence)\n ... print(entry.comment)\n ... print(entry.quality)\n\n ", /*tp_doc*/ + "Stream access to :term:`fasta` or :term:`fastq` formatted files.\n\n The file is automatically opened.\n\n Entries in the file can be both fastq or fasta formatted or even a\n mixture of the two.\n\n This file object permits iterating over all entries in the\n file. Random access is not implemented. The iteration returns\n objects of type :class:`FastqProxy`\n\n Parameters\n ----------\n\n filename : string\n Filename of fasta/fastq file to be opened.\n\n persist : bool\n\n If True (default) make a copy of the entry in the file during\n iteration. If set to False, no copy will be made. This will\n permit much faster iteration, but an entry will not persist\n when the iteration continues and an entry is read-only.\n\n Notes\n -----\n Prior to version 0.8.2, this class was called FastqFile.\n\n Raises\n ------\n\n IOError\n if file could not be opened\n\n\n Examples\n --------\n >>> with pysam.FastxFile(filename) as fh:\n ... for entry in fh:\n ... print(entry.name)\n ... print(entry.sequence)\n ... print(entry.comment)\n ... print(entry.quality)\n >>> with pysam.FastxFile(filename) as fin, open(out_filename, mode='w') as fout:\n ... for entry in fin:\n ... fout.write(str(entry))\n\n ", /*tp_doc*/ __pyx_tp_traverse_5pysam_9libcfaidx_FastxFile, /*tp_traverse*/ __pyx_tp_clear_5pysam_9libcfaidx_FastxFile, /*tp_clear*/ 0, /*tp_richcompare*/ @@ -12361,397 +13048,83 @@ static PyTypeObject __pyx_type_5pysam_9libcfaidx_Fastafile = { #endif }; -static struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *__pyx_freelist_5pysam_9libcfaidx___pyx_scope_struct___open[8]; -static int __pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct___open = 0; - -static PyObject *__pyx_tp_new_5pysam_9libcfaidx___pyx_scope_struct___open(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - PyObject *o; - if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct___open > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open)))) { - o = (PyObject*)__pyx_freelist_5pysam_9libcfaidx___pyx_scope_struct___open[--__pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct___open]; - memset(o, 0, sizeof(struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open)); - (void) PyObject_INIT(o, t); - PyObject_GC_Track(o); - } else { - o = (*t->tp_alloc)(t, 0); - if (unlikely(!o)) return 0; - } - return o; -} - -static void __pyx_tp_dealloc_5pysam_9libcfaidx___pyx_scope_struct___open(PyObject *o) { - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *p = (struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *)o; - PyObject_GC_UnTrack(o); - Py_CLEAR(p->__pyx_v_data); - if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct___open < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open)))) { - __pyx_freelist_5pysam_9libcfaidx___pyx_scope_struct___open[__pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct___open++] = ((struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *)o); - } else { - (*Py_TYPE(o)->tp_free)(o); - } -} - -static int __pyx_tp_traverse_5pysam_9libcfaidx___pyx_scope_struct___open(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *p = (struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *)o; - if (p->__pyx_v_data) { - e = (*v)(p->__pyx_v_data, a); if (e) return e; - } - return 0; -} +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; -static int __pyx_tp_clear_5pysam_9libcfaidx___pyx_scope_struct___open(PyObject *o) { - PyObject* tmp; - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *p = (struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open *)o; - tmp = ((PyObject*)p->__pyx_v_data); - p->__pyx_v_data = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} +#if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec_libcfaidx(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_libcfaidx}, + {0, NULL} +}; +#endif -static PyTypeObject __pyx_type_5pysam_9libcfaidx___pyx_scope_struct___open = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcfaidx.__pyx_scope_struct___open", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct___open), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_9libcfaidx___pyx_scope_struct___open, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + "libcfaidx", + 0, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #else + -1, /* m_size */ #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_5pysam_9libcfaidx___pyx_scope_struct___open, /*tp_traverse*/ - __pyx_tp_clear_5pysam_9libcfaidx___pyx_scope_struct___open, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - 0, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_9libcfaidx___pyx_scope_struct___open, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ + __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else + NULL, /* m_reload */ #endif + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ }; - -static struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr *__pyx_freelist_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr[8]; -static int __pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr = 0; - -static PyObject *__pyx_tp_new_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - PyObject *o; - if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr)))) { - o = (PyObject*)__pyx_freelist_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr[--__pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr]; - memset(o, 0, sizeof(struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr)); - (void) PyObject_INIT(o, t); - PyObject_GC_Track(o); - } else { - o = (*t->tp_alloc)(t, 0); - if (unlikely(!o)) return 0; - } - return o; -} - -static void __pyx_tp_dealloc_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr(PyObject *o) { - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr *)o; - PyObject_GC_UnTrack(o); - Py_CLEAR(p->__pyx_outer_scope); - Py_CLEAR(p->__pyx_v_x); - Py_CLEAR(p->__pyx_t_0); - if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr)))) { - __pyx_freelist_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr[__pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr++] = ((struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr *)o); - } else { - (*Py_TYPE(o)->tp_free)(o); - } -} - -static int __pyx_tp_traverse_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr *)o; - if (p->__pyx_outer_scope) { - e = (*v)(((PyObject *)p->__pyx_outer_scope), a); if (e) return e; - } - if (p->__pyx_v_x) { - e = (*v)(p->__pyx_v_x, a); if (e) return e; - } - if (p->__pyx_t_0) { - e = (*v)(p->__pyx_t_0, a); if (e) return e; - } - return 0; -} - -static PyTypeObject __pyx_type_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcfaidx.__pyx_scope_struct_1_genexpr", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ - #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - 0, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ - #endif -}; - -static struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr *__pyx_freelist_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr[8]; -static int __pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr = 0; - -static PyObject *__pyx_tp_new_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - PyObject *o; - if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr)))) { - o = (PyObject*)__pyx_freelist_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr[--__pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr]; - memset(o, 0, sizeof(struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr)); - (void) PyObject_INIT(o, t); - PyObject_GC_Track(o); - } else { - o = (*t->tp_alloc)(t, 0); - if (unlikely(!o)) return 0; - } - return o; -} - -static void __pyx_tp_dealloc_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr(PyObject *o) { - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr *)o; - PyObject_GC_UnTrack(o); - Py_CLEAR(p->__pyx_outer_scope); - Py_CLEAR(p->__pyx_v_x); - Py_CLEAR(p->__pyx_t_0); - if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr)))) { - __pyx_freelist_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr[__pyx_freecount_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr++] = ((struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr *)o); - } else { - (*Py_TYPE(o)->tp_free)(o); - } -} - -static int __pyx_tp_traverse_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr *)o; - if (p->__pyx_outer_scope) { - e = (*v)(((PyObject *)p->__pyx_outer_scope), a); if (e) return e; - } - if (p->__pyx_v_x) { - e = (*v)(p->__pyx_v_x, a); if (e) return e; - } - if (p->__pyx_t_0) { - e = (*v)(p->__pyx_t_0, a); if (e) return e; - } - return 0; -} - -static PyTypeObject __pyx_type_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libcfaidx.__pyx_scope_struct_2_genexpr", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ - #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - 0, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ - #endif -}; - -static PyMethodDef __pyx_methods[] = { - {0, 0, 0, 0} -}; - -#if PY_MAJOR_VERSION >= 3 -#if CYTHON_PEP489_MULTI_PHASE_INIT -static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ -static int __pyx_pymod_exec_libcfaidx(PyObject* module); /*proto*/ -static PyModuleDef_Slot __pyx_moduledef_slots[] = { - {Py_mod_create, (void*)__pyx_pymod_create}, - {Py_mod_exec, (void*)__pyx_pymod_exec_libcfaidx}, - {0, NULL} -}; -#endif - -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - "libcfaidx", - 0, /* m_doc */ - #if CYTHON_PEP489_MULTI_PHASE_INIT - 0, /* m_size */ - #else - -1, /* m_size */ - #endif - __pyx_methods /* m_methods */, - #if CYTHON_PEP489_MULTI_PHASE_INIT - __pyx_moduledef_slots, /* m_slots */ - #else - NULL, /* m_reload */ - #endif - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ -}; -#endif +#endif static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_FastaFile, __pyx_k_FastaFile, sizeof(__pyx_k_FastaFile), 0, 0, 1, 1}, {&__pyx_n_s_Fastafile, __pyx_k_Fastafile, sizeof(__pyx_k_Fastafile), 0, 0, 1, 1}, {&__pyx_n_s_FastqFile, __pyx_k_FastqFile, sizeof(__pyx_k_FastqFile), 0, 0, 1, 1}, {&__pyx_n_s_FastqProxy, __pyx_k_FastqProxy, sizeof(__pyx_k_FastqProxy), 0, 0, 1, 1}, - {&__pyx_n_s_FastqRead, __pyx_k_FastqRead, sizeof(__pyx_k_FastqRead), 0, 0, 1, 1}, {&__pyx_n_s_FastxFile, __pyx_k_FastxFile, sizeof(__pyx_k_FastxFile), 0, 0, 1, 1}, + {&__pyx_n_s_FastxRecord, __pyx_k_FastxRecord, sizeof(__pyx_k_FastxRecord), 0, 0, 1, 1}, + {&__pyx_kp_s_FastxRecord_must_have_a_name_and, __pyx_k_FastxRecord_must_have_a_name_and, sizeof(__pyx_k_FastxRecord_must_have_a_name_and), 0, 0, 1, 0}, {&__pyx_n_s_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 0, 0, 1, 1}, {&__pyx_kp_s_I_O_operation_on_closed_file, __pyx_k_I_O_operation_on_closed_file, sizeof(__pyx_k_I_O_operation_on_closed_file), 0, 0, 1, 0}, {&__pyx_kp_s_Incompatible_checksums_s_vs_0x43, __pyx_k_Incompatible_checksums_s_vs_0x43, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x43), 0, 0, 1, 0}, {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1}, {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, - {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1}, {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1}, {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, - {&__pyx_kp_b__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 0, 0}, - {&__pyx_kp_s__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 0, 1, 0}, + {&__pyx_kp_b__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 0, 0}, {&__pyx_kp_s__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 0, 1, 0}, - {&__pyx_kp_s__6, __pyx_k__6, sizeof(__pyx_k__6), 0, 0, 1, 0}, {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1}, - {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1}, - {&__pyx_n_s_basename, __pyx_k_basename, sizeof(__pyx_k_basename), 0, 0, 1, 1}, + {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1}, {&__pyx_kp_s_calling_len_on_closed_file, __pyx_k_calling_len_on_closed_file, sizeof(__pyx_k_calling_len_on_closed_file), 0, 0, 1, 0}, + {&__pyx_kp_s_can_not_write_record_without_a_s, __pyx_k_can_not_write_record_without_a_s, sizeof(__pyx_k_can_not_write_record_without_a_s), 0, 0, 1, 0}, + {&__pyx_kp_s_can_not_write_record_without_nam, __pyx_k_can_not_write_record_without_nam, sizeof(__pyx_k_can_not_write_record_without_nam), 0, 0, 1, 0}, {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1}, {&__pyx_n_s_comment, __pyx_k_comment, sizeof(__pyx_k_comment), 0, 0, 1, 1}, - {&__pyx_kp_s_could_not_locate_index_file, __pyx_k_could_not_locate_index_file, sizeof(__pyx_k_could_not_locate_index_file), 0, 0, 1, 0}, - {&__pyx_kp_s_could_not_open_file_s, __pyx_k_could_not_open_file_s, sizeof(__pyx_k_could_not_open_file_s), 0, 0, 1, 0}, {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1}, - {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1}, + {&__pyx_kp_s_error_when_opening_file_s, __pyx_k_error_when_opening_file_s, sizeof(__pyx_k_error_when_opening_file_s), 0, 0, 1, 0}, {&__pyx_n_s_exc_type, __pyx_k_exc_type, sizeof(__pyx_k_exc_type), 0, 0, 1, 1}, {&__pyx_n_s_exc_value, __pyx_k_exc_value, sizeof(__pyx_k_exc_value), 0, 0, 1, 1}, {&__pyx_n_s_exists, __pyx_k_exists, sizeof(__pyx_k_exists), 0, 0, 1, 1}, - {&__pyx_n_s_exit, __pyx_k_exit, sizeof(__pyx_k_exit), 0, 0, 1, 1}, - {&__pyx_kp_s_fai, __pyx_k_fai, sizeof(__pyx_k_fai), 0, 0, 1, 0}, {&__pyx_kp_s_failure_when_retrieving_sequence, __pyx_k_failure_when_retrieving_sequence, sizeof(__pyx_k_failure_when_retrieving_sequence), 0, 0, 1, 0}, {&__pyx_n_s_fetch, __pyx_k_fetch, sizeof(__pyx_k_fetch), 0, 0, 1, 1}, {&__pyx_kp_s_file_s_not_found, __pyx_k_file_s_not_found, sizeof(__pyx_k_file_s_not_found), 0, 0, 1, 0}, {&__pyx_n_s_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 0, 1, 1}, + {&__pyx_kp_s_filename_does_not_exist, __pyx_k_filename_does_not_exist, sizeof(__pyx_k_filename_does_not_exist), 0, 0, 1, 0}, {&__pyx_n_s_filepath_index, __pyx_k_filepath_index, sizeof(__pyx_k_filepath_index), 0, 0, 1, 1}, + {&__pyx_n_s_filepath_index_compressed, __pyx_k_filepath_index_compressed, sizeof(__pyx_k_filepath_index_compressed), 0, 0, 1, 1}, {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1}, - {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1}, {&__pyx_n_s_get_quality_array, __pyx_k_get_quality_array, sizeof(__pyx_k_get_quality_array), 0, 0, 1, 1}, {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, @@ -12764,19 +13137,18 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_no_sequence_region_supplied, __pyx_k_no_sequence_region_supplied, sizeof(__pyx_k_no_sequence_region_supplied), 0, 0, 1, 0}, {&__pyx_n_s_offset, __pyx_k_offset, sizeof(__pyx_k_offset), 0, 0, 1, 1}, {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1}, - {&__pyx_n_s_open_2, __pyx_k_open_2, sizeof(__pyx_k_open_2), 0, 0, 1, 1}, - {&__pyx_n_s_open_locals_genexpr, __pyx_k_open_locals_genexpr, sizeof(__pyx_k_open_locals_genexpr), 0, 0, 1, 1}, {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1}, {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1}, {&__pyx_n_s_persist, __pyx_k_persist, sizeof(__pyx_k_persist), 0, 0, 1, 1}, {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, + {&__pyx_n_s_proxy, __pyx_k_proxy, sizeof(__pyx_k_proxy), 0, 0, 1, 1}, {&__pyx_n_s_pysam_libcfaidx, __pyx_k_pysam_libcfaidx, sizeof(__pyx_k_pysam_libcfaidx), 0, 0, 1, 1}, {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1}, {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1}, {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1}, {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1}, {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1}, - {&__pyx_n_s_pyx_unpickle_PersistentFastqPr, __pyx_k_pyx_unpickle_PersistentFastqPr, sizeof(__pyx_k_pyx_unpickle_PersistentFastqPr), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_FastxRecord, __pyx_k_pyx_unpickle_FastxRecord, sizeof(__pyx_k_pyx_unpickle_FastxRecord), 0, 0, 1, 1}, {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1}, {&__pyx_n_s_quality, __pyx_k_quality, sizeof(__pyx_k_quality), 0, 0, 1, 1}, {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1}, @@ -12790,33 +13162,27 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_s_s_s, __pyx_k_s_s_s, sizeof(__pyx_k_s_s_s), 0, 0, 1, 0}, {&__pyx_kp_s_s_s_s_s, __pyx_k_s_s_s_s, sizeof(__pyx_k_s_s_s_s), 0, 0, 1, 0}, {&__pyx_kp_s_self__delegate_cannot_be_convert, __pyx_k_self__delegate_cannot_be_convert, sizeof(__pyx_k_self__delegate_cannot_be_convert), 0, 0, 1, 0}, - {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1}, {&__pyx_n_s_sequence, __pyx_k_sequence, sizeof(__pyx_k_sequence), 0, 0, 1, 1}, + {&__pyx_kp_s_sequence_and_quality_length_do_n, __pyx_k_sequence_and_quality_length_do_n, sizeof(__pyx_k_sequence_and_quality_length_do_n), 0, 0, 1, 0}, {&__pyx_kp_s_sequence_s_not_present, __pyx_k_sequence_s_not_present, sizeof(__pyx_k_sequence_s_not_present), 0, 0, 1, 0}, {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, - {&__pyx_kp_s_setting_an_explicit_path_for_the, __pyx_k_setting_an_explicit_path_for_the, sizeof(__pyx_k_setting_an_explicit_path_for_the), 0, 0, 1, 0}, - {&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1}, {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1}, {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, - {&__pyx_n_s_sub, __pyx_k_sub, sizeof(__pyx_k_sub), 0, 0, 1, 1}, {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, - {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1}, {&__pyx_n_s_traceback, __pyx_k_traceback, sizeof(__pyx_k_traceback), 0, 0, 1, 1}, {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, {&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 122, __pyx_L1_error) - __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 141, __pyx_L1_error) - __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 149, __pyx_L1_error) - __pyx_builtin_open = __Pyx_GetBuiltinName(__pyx_n_s_open); if (!__pyx_builtin_open) __PYX_ERR(0, 167, __pyx_L1_error) - __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 171, __pyx_L1_error) - __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 278, __pyx_L1_error) + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 195, __pyx_L1_error) + __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 302, __pyx_L1_error) __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) - __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 556, __pyx_L1_error) + __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 649, __pyx_L1_error) __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(3, 109, __pyx_L1_error) return 0; __pyx_L1_error:; @@ -12827,71 +13193,38 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "pysam/libcfaidx.pyx":122 + /* "pysam/libcfaidx.pyx":131 * def __len__(self): * if self.fastafile == NULL: * raise ValueError("calling len() on closed file") # <<<<<<<<<<<<<< * * return faidx_nseq(self.fastafile) */ - __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_calling_len_on_closed_file); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 122, __pyx_L1_error) + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_calling_len_on_closed_file); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 131, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); - /* "pysam/libcfaidx.pyx":141 - * - * if filepath_index is not None: - * raise NotImplementedError( # <<<<<<<<<<<<<< - * "setting an explicit path for the index " - * "is not implemented") - */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_setting_an_explicit_path_for_the); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__2); - __Pyx_GIVEREF(__pyx_tuple__2); - - /* "pysam/libcfaidx.pyx":168 - * - * with open(filepath_index) as inf: - * data = [x.split("\t") for x in inf] # <<<<<<<<<<<<<< - * self._references = tuple(x[0] for x in data) - * self._lengths = tuple(int(x[1]) for x in data) - */ - __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s__6); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 168, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__7); - __Pyx_GIVEREF(__pyx_tuple__7); - - /* "pysam/libcfaidx.pyx":167 - * filepath_index)) - * - * with open(filepath_index) as inf: # <<<<<<<<<<<<<< - * data = [x.split("\t") for x in inf] - * self._references = tuple(x[0] for x in data) - */ - __pyx_tuple__8 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 167, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__8); - __Pyx_GIVEREF(__pyx_tuple__8); - - /* "pysam/libcfaidx.pyx":259 + /* "pysam/libcfaidx.pyx":283 * * if not self.is_open(): * raise ValueError("I/O operation on closed file" ) # <<<<<<<<<<<<<< * * cdef int length */ - __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 259, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__9); - __Pyx_GIVEREF(__pyx_tuple__9); + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); - /* "pysam/libcfaidx.pyx":269 + /* "pysam/libcfaidx.pyx":293 * * if reference is None: * raise ValueError("no sequence/region supplied.") # <<<<<<<<<<<<<< * * if rstart == rend: */ - __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_no_sequence_region_supplied); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 269, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__10); - __Pyx_GIVEREF(__pyx_tuple__10); + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_no_sequence_region_supplied); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -12899,18 +13232,18 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__11); - __Pyx_GIVEREF(__pyx_tuple__11); + __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__12); - __Pyx_GIVEREF(__pyx_tuple__12); + __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__7); + __Pyx_GIVEREF(__pyx_tuple__7); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -12918,27 +13251,79 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self._delegate cannot be converted to a Python object for pickling") */ - __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_self__delegate_cannot_be_convert); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__13); - __Pyx_GIVEREF(__pyx_tuple__13); + __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_self__delegate_cannot_be_convert); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__8); + __Pyx_GIVEREF(__pyx_tuple__8); /* "(tree fragment)":4 * raise TypeError("self._delegate cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self._delegate cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_self__delegate_cannot_be_convert); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__14); - __Pyx_GIVEREF(__pyx_tuple__14); + __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_self__delegate_cannot_be_convert); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__9); + __Pyx_GIVEREF(__pyx_tuple__9); + + /* "pysam/libcfaidx.pyx":443 + * cdef cython.str to_string(self): + * if self.name is None: + * raise ValueError("can not write record without name") # <<<<<<<<<<<<<< + * + * if self.sequence is None: + */ + __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_can_not_write_record_without_nam); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__10); + __Pyx_GIVEREF(__pyx_tuple__10); + + /* "pysam/libcfaidx.pyx":446 + * + * if self.sequence is None: + * raise ValueError("can not write record without a sequence") # <<<<<<<<<<<<<< + * + * if self.comment is None: + */ + __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_can_not_write_record_without_a_s); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 446, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__11); + __Pyx_GIVEREF(__pyx_tuple__11); - /* "pysam/libcfaidx.pyx":532 + /* "pysam/libcfaidx.pyx":465 + * def set_name(self, name): + * if name is None: + * raise ValueError("FastxRecord must have a name and not None") # <<<<<<<<<<<<<< + * self.name = name + * + */ + __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_FastxRecord_must_have_a_name_and); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 465, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__12); + __Pyx_GIVEREF(__pyx_tuple__12); + + /* "pysam/libcfaidx.pyx":625 * def __iter__(self): * if not self.is_open(): * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< * return self * */ - __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 532, __pyx_L1_error) + __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 625, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__13); + __Pyx_GIVEREF(__pyx_tuple__13); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__14); + __Pyx_GIVEREF(__pyx_tuple__14); + + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + */ + __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__15); __Pyx_GIVEREF(__pyx_tuple__15); @@ -12980,34 +13365,15 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GOTREF(__pyx_tuple__19); __Pyx_GIVEREF(__pyx_tuple__19); - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - */ - __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__20); - __Pyx_GIVEREF(__pyx_tuple__20); - - /* "(tree fragment)":4 - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - */ - __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__21); - __Pyx_GIVEREF(__pyx_tuple__21); - /* "(tree fragment)":1 - * def __pyx_unpickle_PersistentFastqProxy(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * def __pyx_unpickle_FastxRecord(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x43fd151: * from pickle import PickleError as __pyx_PickleError */ - __pyx_tuple__23 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__23); - __Pyx_GIVEREF(__pyx_tuple__23); - __pyx_codeobj__22 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__23, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_PersistentFastqPr, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__22)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_tuple__21 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__21); + __Pyx_GIVEREF(__pyx_tuple__21); + __pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__21, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_FastxRecord, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -13061,14 +13427,14 @@ static int __Pyx_modinit_type_init_code(void) { /*--- Type init code ---*/ __pyx_vtabptr_5pysam_9libcfaidx_FastaFile = &__pyx_vtable_5pysam_9libcfaidx_FastaFile; __pyx_vtable_5pysam_9libcfaidx_FastaFile._fetch = (char *(*)(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *, char *, int, int, int *))__pyx_f_5pysam_9libcfaidx_9FastaFile__fetch; - if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx_FastaFile) < 0) __PYX_ERR(0, 80, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx_FastaFile) < 0) __PYX_ERR(0, 85, __pyx_L1_error) __pyx_type_5pysam_9libcfaidx_FastaFile.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libcfaidx_FastaFile.tp_dictoffset && __pyx_type_5pysam_9libcfaidx_FastaFile.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libcfaidx_FastaFile.tp_getattro = __Pyx_PyObject_GenericGetAttr; } #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libcfaidx_FastaFile, "__contains__"); if (unlikely(!wrapper)) __PYX_ERR(0, 80, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libcfaidx_FastaFile, "__contains__"); if (unlikely(!wrapper)) __PYX_ERR(0, 85, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_9libcfaidx_9FastaFile_22__contains__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_9libcfaidx_9FastaFile_22__contains__.doc = __pyx_doc_5pysam_9libcfaidx_9FastaFile_22__contains__; @@ -13076,45 +13442,47 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_9libcfaidx_FastaFile.tp_dict, __pyx_vtabptr_5pysam_9libcfaidx_FastaFile) < 0) __PYX_ERR(0, 80, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "FastaFile", (PyObject *)&__pyx_type_5pysam_9libcfaidx_FastaFile) < 0) __PYX_ERR(0, 80, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libcfaidx_FastaFile) < 0) __PYX_ERR(0, 80, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libcfaidx_FastaFile.tp_dict, __pyx_vtabptr_5pysam_9libcfaidx_FastaFile) < 0) __PYX_ERR(0, 85, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "FastaFile", (PyObject *)&__pyx_type_5pysam_9libcfaidx_FastaFile) < 0) __PYX_ERR(0, 85, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libcfaidx_FastaFile) < 0) __PYX_ERR(0, 85, __pyx_L1_error) __pyx_ptype_5pysam_9libcfaidx_FastaFile = &__pyx_type_5pysam_9libcfaidx_FastaFile; __pyx_vtabptr_5pysam_9libcfaidx_FastqProxy = &__pyx_vtable_5pysam_9libcfaidx_FastqProxy; + __pyx_vtable_5pysam_9libcfaidx_FastqProxy.to_string = (PyObject *(*)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *))__pyx_f_5pysam_9libcfaidx_10FastqProxy_to_string; __pyx_vtable_5pysam_9libcfaidx_FastqProxy.tostring = (PyObject *(*)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *))__pyx_f_5pysam_9libcfaidx_10FastqProxy_tostring; __pyx_vtable_5pysam_9libcfaidx_FastqProxy.get_quality_array = (arrayobject *(*)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array *__pyx_optional_args))__pyx_f_5pysam_9libcfaidx_10FastqProxy_get_quality_array; - if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx_FastqProxy) < 0) __PYX_ERR(0, 321, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx_FastqProxy) < 0) __PYX_ERR(0, 356, __pyx_L1_error) __pyx_type_5pysam_9libcfaidx_FastqProxy.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libcfaidx_FastqProxy.tp_dictoffset && __pyx_type_5pysam_9libcfaidx_FastqProxy.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libcfaidx_FastqProxy.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_9libcfaidx_FastqProxy.tp_dict, __pyx_vtabptr_5pysam_9libcfaidx_FastqProxy) < 0) __PYX_ERR(0, 321, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "FastqProxy", (PyObject *)&__pyx_type_5pysam_9libcfaidx_FastqProxy) < 0) __PYX_ERR(0, 321, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libcfaidx_FastqProxy) < 0) __PYX_ERR(0, 321, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libcfaidx_FastqProxy.tp_dict, __pyx_vtabptr_5pysam_9libcfaidx_FastqProxy) < 0) __PYX_ERR(0, 356, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "FastqProxy", (PyObject *)&__pyx_type_5pysam_9libcfaidx_FastqProxy) < 0) __PYX_ERR(0, 356, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libcfaidx_FastqProxy) < 0) __PYX_ERR(0, 356, __pyx_L1_error) __pyx_ptype_5pysam_9libcfaidx_FastqProxy = &__pyx_type_5pysam_9libcfaidx_FastqProxy; - __pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy = &__pyx_vtable_5pysam_9libcfaidx_PersistentFastqProxy; - __pyx_vtable_5pysam_9libcfaidx_PersistentFastqProxy.tostring = (PyObject *(*)(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *))__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_tostring; - __pyx_vtable_5pysam_9libcfaidx_PersistentFastqProxy.get_quality_array = (arrayobject *(*)(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array *__pyx_optional_args))__pyx_f_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array; - if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx_PersistentFastqProxy) < 0) __PYX_ERR(0, 372, __pyx_L1_error) - __pyx_type_5pysam_9libcfaidx_PersistentFastqProxy.tp_print = 0; - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libcfaidx_PersistentFastqProxy.tp_dictoffset && __pyx_type_5pysam_9libcfaidx_PersistentFastqProxy.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type_5pysam_9libcfaidx_PersistentFastqProxy.tp_getattro = __Pyx_PyObject_GenericGetAttr; + __pyx_vtabptr_5pysam_9libcfaidx_FastxRecord = &__pyx_vtable_5pysam_9libcfaidx_FastxRecord; + __pyx_vtable_5pysam_9libcfaidx_FastxRecord.to_string = (PyObject *(*)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *))__pyx_f_5pysam_9libcfaidx_11FastxRecord_to_string; + __pyx_vtable_5pysam_9libcfaidx_FastxRecord.tostring = (PyObject *(*)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *))__pyx_f_5pysam_9libcfaidx_11FastxRecord_tostring; + __pyx_vtable_5pysam_9libcfaidx_FastxRecord.get_quality_array = (arrayobject *(*)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array *__pyx_optional_args))__pyx_f_5pysam_9libcfaidx_11FastxRecord_get_quality_array; + if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx_FastxRecord) < 0) __PYX_ERR(0, 411, __pyx_L1_error) + __pyx_type_5pysam_9libcfaidx_FastxRecord.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libcfaidx_FastxRecord.tp_dictoffset && __pyx_type_5pysam_9libcfaidx_FastxRecord.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_9libcfaidx_FastxRecord.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_9libcfaidx_PersistentFastqProxy.tp_dict, __pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy) < 0) __PYX_ERR(0, 372, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "PersistentFastqProxy", (PyObject *)&__pyx_type_5pysam_9libcfaidx_PersistentFastqProxy) < 0) __PYX_ERR(0, 372, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libcfaidx_PersistentFastqProxy) < 0) __PYX_ERR(0, 372, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy = &__pyx_type_5pysam_9libcfaidx_PersistentFastqProxy; + if (__Pyx_SetVtable(__pyx_type_5pysam_9libcfaidx_FastxRecord.tp_dict, __pyx_vtabptr_5pysam_9libcfaidx_FastxRecord) < 0) __PYX_ERR(0, 411, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "FastxRecord", (PyObject *)&__pyx_type_5pysam_9libcfaidx_FastxRecord) < 0) __PYX_ERR(0, 411, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libcfaidx_FastxRecord) < 0) __PYX_ERR(0, 411, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_FastxRecord = &__pyx_type_5pysam_9libcfaidx_FastxRecord; __pyx_vtabptr_5pysam_9libcfaidx_FastxFile = &__pyx_vtable_5pysam_9libcfaidx_FastxFile; __pyx_vtable_5pysam_9libcfaidx_FastxFile.getCurrent = (kseq_t *(*)(struct __pyx_obj_5pysam_9libcfaidx_FastxFile *))__pyx_f_5pysam_9libcfaidx_9FastxFile_getCurrent; __pyx_vtable_5pysam_9libcfaidx_FastxFile.cnext = (int (*)(struct __pyx_obj_5pysam_9libcfaidx_FastxFile *))__pyx_f_5pysam_9libcfaidx_9FastxFile_cnext; - if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx_FastxFile) < 0) __PYX_ERR(0, 406, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx_FastxFile) < 0) __PYX_ERR(0, 496, __pyx_L1_error) __pyx_type_5pysam_9libcfaidx_FastxFile.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libcfaidx_FastxFile.tp_dictoffset && __pyx_type_5pysam_9libcfaidx_FastxFile.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libcfaidx_FastxFile.tp_getattro = __Pyx_PyObject_GenericGetAttr; } #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libcfaidx_FastxFile, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 406, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libcfaidx_FastxFile, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 496, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_9libcfaidx_9FastxFile_16__next__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_9libcfaidx_9FastxFile_16__next__.doc = __pyx_doc_5pysam_9libcfaidx_9FastxFile_16__next__; @@ -13122,52 +13490,34 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_9libcfaidx_FastxFile.tp_dict, __pyx_vtabptr_5pysam_9libcfaidx_FastxFile) < 0) __PYX_ERR(0, 406, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "FastxFile", (PyObject *)&__pyx_type_5pysam_9libcfaidx_FastxFile) < 0) __PYX_ERR(0, 406, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libcfaidx_FastxFile) < 0) __PYX_ERR(0, 406, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libcfaidx_FastxFile.tp_dict, __pyx_vtabptr_5pysam_9libcfaidx_FastxFile) < 0) __PYX_ERR(0, 496, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "FastxFile", (PyObject *)&__pyx_type_5pysam_9libcfaidx_FastxFile) < 0) __PYX_ERR(0, 496, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libcfaidx_FastxFile) < 0) __PYX_ERR(0, 496, __pyx_L1_error) __pyx_ptype_5pysam_9libcfaidx_FastxFile = &__pyx_type_5pysam_9libcfaidx_FastxFile; __pyx_vtabptr_5pysam_9libcfaidx_FastqFile = &__pyx_vtable_5pysam_9libcfaidx_FastqFile; __pyx_vtable_5pysam_9libcfaidx_FastqFile.__pyx_base = *__pyx_vtabptr_5pysam_9libcfaidx_FastxFile; __pyx_type_5pysam_9libcfaidx_FastqFile.tp_base = __pyx_ptype_5pysam_9libcfaidx_FastxFile; - if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx_FastqFile) < 0) __PYX_ERR(0, 559, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx_FastqFile) < 0) __PYX_ERR(0, 652, __pyx_L1_error) __pyx_type_5pysam_9libcfaidx_FastqFile.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libcfaidx_FastqFile.tp_dictoffset && __pyx_type_5pysam_9libcfaidx_FastqFile.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libcfaidx_FastqFile.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_9libcfaidx_FastqFile.tp_dict, __pyx_vtabptr_5pysam_9libcfaidx_FastqFile) < 0) __PYX_ERR(0, 559, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "FastqFile", (PyObject *)&__pyx_type_5pysam_9libcfaidx_FastqFile) < 0) __PYX_ERR(0, 559, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libcfaidx_FastqFile) < 0) __PYX_ERR(0, 559, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libcfaidx_FastqFile.tp_dict, __pyx_vtabptr_5pysam_9libcfaidx_FastqFile) < 0) __PYX_ERR(0, 652, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "FastqFile", (PyObject *)&__pyx_type_5pysam_9libcfaidx_FastqFile) < 0) __PYX_ERR(0, 652, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libcfaidx_FastqFile) < 0) __PYX_ERR(0, 652, __pyx_L1_error) __pyx_ptype_5pysam_9libcfaidx_FastqFile = &__pyx_type_5pysam_9libcfaidx_FastqFile; __pyx_vtabptr_5pysam_9libcfaidx_Fastafile = &__pyx_vtable_5pysam_9libcfaidx_Fastafile; __pyx_vtable_5pysam_9libcfaidx_Fastafile.__pyx_base = *__pyx_vtabptr_5pysam_9libcfaidx_FastaFile; __pyx_type_5pysam_9libcfaidx_Fastafile.tp_base = __pyx_ptype_5pysam_9libcfaidx_FastaFile; - if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx_Fastafile) < 0) __PYX_ERR(0, 564, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx_Fastafile) < 0) __PYX_ERR(0, 657, __pyx_L1_error) __pyx_type_5pysam_9libcfaidx_Fastafile.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libcfaidx_Fastafile.tp_dictoffset && __pyx_type_5pysam_9libcfaidx_Fastafile.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libcfaidx_Fastafile.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_9libcfaidx_Fastafile.tp_dict, __pyx_vtabptr_5pysam_9libcfaidx_Fastafile) < 0) __PYX_ERR(0, 564, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "Fastafile", (PyObject *)&__pyx_type_5pysam_9libcfaidx_Fastafile) < 0) __PYX_ERR(0, 564, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libcfaidx_Fastafile) < 0) __PYX_ERR(0, 564, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libcfaidx_Fastafile.tp_dict, __pyx_vtabptr_5pysam_9libcfaidx_Fastafile) < 0) __PYX_ERR(0, 657, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "Fastafile", (PyObject *)&__pyx_type_5pysam_9libcfaidx_Fastafile) < 0) __PYX_ERR(0, 657, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libcfaidx_Fastafile) < 0) __PYX_ERR(0, 657, __pyx_L1_error) __pyx_ptype_5pysam_9libcfaidx_Fastafile = &__pyx_type_5pysam_9libcfaidx_Fastafile; - if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx___pyx_scope_struct___open) < 0) __PYX_ERR(0, 126, __pyx_L1_error) - __pyx_type_5pysam_9libcfaidx___pyx_scope_struct___open.tp_print = 0; - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libcfaidx___pyx_scope_struct___open.tp_dictoffset && __pyx_type_5pysam_9libcfaidx___pyx_scope_struct___open.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type_5pysam_9libcfaidx___pyx_scope_struct___open.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; - } - __pyx_ptype_5pysam_9libcfaidx___pyx_scope_struct___open = &__pyx_type_5pysam_9libcfaidx___pyx_scope_struct___open; - if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr) < 0) __PYX_ERR(0, 169, __pyx_L1_error) - __pyx_type_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr.tp_print = 0; - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr.tp_dictoffset && __pyx_type_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; - } - __pyx_ptype_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr = &__pyx_type_5pysam_9libcfaidx___pyx_scope_struct_1_genexpr; - if (PyType_Ready(&__pyx_type_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr) < 0) __PYX_ERR(0, 170, __pyx_L1_error) - __pyx_type_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr.tp_print = 0; - if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr.tp_dictoffset && __pyx_type_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr.tp_getattro == PyObject_GenericGetAttr)) { - __pyx_type_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; - } - __pyx_ptype_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr = &__pyx_type_5pysam_9libcfaidx___pyx_scope_struct_2_genexpr; __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -13189,8 +13539,8 @@ static int __Pyx_modinit_type_import_code(void) { __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) __PYX_ERR(5, 8, __pyx_L1_error) __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) __PYX_ERR(6, 15, __pyx_L1_error) __pyx_ptype_7cpython_5array_array = __Pyx_ImportType("array", "array", sizeof(arrayobject), 0); if (unlikely(!__pyx_ptype_7cpython_5array_array)) __PYX_ERR(3, 58, __pyx_L1_error) - __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(7, 1904, __pyx_L1_error) - __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(7, 1904, __pyx_L1_error) + __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(7, 2590, __pyx_L1_error) + __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(7, 2590, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -13420,7 +13770,7 @@ if (!__Pyx_RefNanny) { * import sys * import os # <<<<<<<<<<<<<< * import re - * from cpython cimport array + * */ __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); @@ -13431,7 +13781,7 @@ if (!__Pyx_RefNanny) { * import sys * import os * import re # <<<<<<<<<<<<<< - * from cpython cimport array + * * */ __pyx_t_1 = __Pyx_Import(__pyx_n_s_re, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 50, __pyx_L1_error) @@ -13439,14 +13789,14 @@ if (!__Pyx_RefNanny) { if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_1) < 0) __PYX_ERR(0, 50, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcfaidx.pyx":568 + /* "pysam/libcfaidx.pyx":661 * pass * * __all__ = ["FastaFile", # <<<<<<<<<<<<<< * "FastqFile", * "FastxFile", */ - __pyx_t_1 = PyList_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 568, __pyx_L1_error) + __pyx_t_1 = PyList_New(6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 661, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_FastaFile); __Pyx_GIVEREF(__pyx_n_s_FastaFile); @@ -13460,20 +13810,23 @@ if (!__Pyx_RefNanny) { __Pyx_INCREF(__pyx_n_s_Fastafile); __Pyx_GIVEREF(__pyx_n_s_Fastafile); PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_Fastafile); + __Pyx_INCREF(__pyx_n_s_FastxRecord); + __Pyx_GIVEREF(__pyx_n_s_FastxRecord); + PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_s_FastxRecord); __Pyx_INCREF(__pyx_n_s_FastqProxy); __Pyx_GIVEREF(__pyx_n_s_FastqProxy); - PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_s_FastqProxy); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 568, __pyx_L1_error) + PyList_SET_ITEM(__pyx_t_1, 5, __pyx_n_s_FastqProxy); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 661, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":1 - * def __pyx_unpickle_PersistentFastqProxy(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * def __pyx_unpickle_FastxRecord(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x43fd151: * from pickle import PickleError as __pyx_PickleError */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libcfaidx_1__pyx_unpickle_PersistentFastqProxy, NULL, __pyx_n_s_pysam_libcfaidx); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libcfaidx_1__pyx_unpickle_FastxRecord, NULL, __pyx_n_s_pysam_libcfaidx); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_PersistentFastqPr, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_FastxRecord, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pysam/libcfaidx.pyx":1 @@ -14043,120 +14396,28 @@ static void __Pyx_RaiseArgtupleInvalid( (num_expected == 1) ? "" : "s", num_found); } -/* None */ -static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) { - PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname); +/* PyCFunctionFastCall */ +#if CYTHON_FAST_PYCCALL +static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) { + PyCFunctionObject *func = (PyCFunctionObject*)func_obj; + PyCFunction meth = PyCFunction_GET_FUNCTION(func); + PyObject *self = PyCFunction_GET_SELF(func); + int flags = PyCFunction_GET_FLAGS(func); + assert(PyCFunction_Check(func)); + assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS))); + assert(nargs >= 0); + assert(nargs == 0 || args != NULL); + /* _PyCFunction_FastCallDict() must not be called with an exception set, + because it may clear it (directly or indirectly) and so the + caller loses its exception */ + assert(!PyErr_Occurred()); + if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) { + return (*((__Pyx_PyCFunctionFastWithKeywords)meth)) (self, args, nargs, NULL); + } else { + return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs); + } } - -/* GetItemInt */ -static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { - PyObject *r; - if (!j) return NULL; - r = PyObject_GetItem(o, j); - Py_DECREF(j); - return r; -} -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, - CYTHON_NCP_UNUSED int wraparound, - CYTHON_NCP_UNUSED int boundscheck) { -#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - Py_ssize_t wrapped_i = i; - if (wraparound & unlikely(i < 0)) { - wrapped_i += PyList_GET_SIZE(o); - } - if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, wrapped_i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, - CYTHON_NCP_UNUSED int wraparound, - CYTHON_NCP_UNUSED int boundscheck) { -#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - Py_ssize_t wrapped_i = i; - if (wraparound & unlikely(i < 0)) { - wrapped_i += PyTuple_GET_SIZE(o); - } - if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, - CYTHON_NCP_UNUSED int wraparound, - CYTHON_NCP_UNUSED int boundscheck) { -#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS - if (is_list || PyList_CheckExact(o)) { - Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); - if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) { - PyObject *r = PyList_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } - else if (PyTuple_CheckExact(o)) { - Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); - if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } else { - PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; - if (likely(m && m->sq_item)) { - if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { - Py_ssize_t l = m->sq_length(o); - if (likely(l >= 0)) { - i += l; - } else { - if (!PyErr_ExceptionMatches(PyExc_OverflowError)) - return NULL; - PyErr_Clear(); - } - } - return m->sq_item(o, i); - } - } -#else - if (is_list || PySequence_Check(o)) { - return PySequence_GetItem(o, i); - } -#endif - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} - -/* PyCFunctionFastCall */ -#if CYTHON_FAST_PYCCALL -static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) { - PyCFunctionObject *func = (PyCFunctionObject*)func_obj; - PyCFunction meth = PyCFunction_GET_FUNCTION(func); - PyObject *self = PyCFunction_GET_SELF(func); - int flags = PyCFunction_GET_FLAGS(func); - assert(PyCFunction_Check(func)); - assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS))); - assert(nargs >= 0); - assert(nargs == 0 || args != NULL); - /* _PyCFunction_FastCallDict() must not be called with an exception set, - because it may clear it (directly or indirectly) and so the - caller loses its exception */ - assert(!PyErr_Occurred()); - if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) { - return (*((__Pyx_PyCFunctionFastWithKeywords)meth)) (self, args, nargs, NULL); - } else { - return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs); - } -} -#endif +#endif /* PyFunctionFastCall */ #if CYTHON_FAST_PYCALL @@ -14433,117 +14694,72 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { return result; } -/* SaveResetException */ - #if CYTHON_FAST_THREAD_STATE -static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { - #if PY_VERSION_HEX >= 0x030700A2 - *type = tstate->exc_state.exc_type; - *value = tstate->exc_state.exc_value; - *tb = tstate->exc_state.exc_traceback; - #else - *type = tstate->exc_type; - *value = tstate->exc_value; - *tb = tstate->exc_traceback; - #endif - Py_XINCREF(*type); - Py_XINCREF(*value); - Py_XINCREF(*tb); +/* PyObjectCallMethod1 */ + static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { + PyObject *result = NULL; +#if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(method))) { + PyObject *self = PyMethod_GET_SELF(method); + if (likely(self)) { + PyObject *args; + PyObject *function = PyMethod_GET_FUNCTION(method); + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(function)) { + PyObject *args[2] = {self, arg}; + result = __Pyx_PyFunction_FastCall(function, args, 2); + goto done; + } + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(function)) { + PyObject *args[2] = {self, arg}; + result = __Pyx_PyCFunction_FastCall(function, args, 2); + goto done; + } + #endif + args = PyTuple_New(2); + if (unlikely(!args)) goto done; + Py_INCREF(self); + PyTuple_SET_ITEM(args, 0, self); + Py_INCREF(arg); + PyTuple_SET_ITEM(args, 1, arg); + Py_INCREF(function); + result = __Pyx_PyObject_Call(function, args, NULL); + Py_DECREF(args); + Py_DECREF(function); + return result; + } + } +#endif + result = __Pyx_PyObject_CallOneArg(method, arg); + goto done; +done: + return result; } -static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { - PyObject *tmp_type, *tmp_value, *tmp_tb; - #if PY_VERSION_HEX >= 0x030700A2 - tmp_type = tstate->exc_state.exc_type; - tmp_value = tstate->exc_state.exc_value; - tmp_tb = tstate->exc_state.exc_traceback; - tstate->exc_state.exc_type = type; - tstate->exc_state.exc_value = value; - tstate->exc_state.exc_traceback = tb; - #else - tmp_type = tstate->exc_type; - tmp_value = tstate->exc_value; - tmp_tb = tstate->exc_traceback; - tstate->exc_type = type; - tstate->exc_value = value; - tstate->exc_traceback = tb; - #endif - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); +static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { + PyObject *method, *result; + method = __Pyx_PyObject_GetAttrStr(obj, method_name); + if (unlikely(!method)) return NULL; + result = __Pyx__PyObject_CallMethod1(method, arg); + Py_DECREF(method); + return result; } -#endif -/* GetException */ - #if CYTHON_FAST_THREAD_STATE -static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { -#else -static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { -#endif - PyObject *local_type, *local_value, *local_tb; -#if CYTHON_FAST_THREAD_STATE - PyObject *tmp_type, *tmp_value, *tmp_tb; - local_type = tstate->curexc_type; - local_value = tstate->curexc_value; - local_tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; -#else - PyErr_Fetch(&local_type, &local_value, &local_tb); -#endif - PyErr_NormalizeException(&local_type, &local_value, &local_tb); -#if CYTHON_FAST_THREAD_STATE - if (unlikely(tstate->curexc_type)) -#else - if (unlikely(PyErr_Occurred())) -#endif - goto bad; - #if PY_MAJOR_VERSION >= 3 - if (local_tb) { - if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) - goto bad; +/* append */ + static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) { + if (likely(PyList_CheckExact(L))) { + if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1; + } else { + PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x); + if (unlikely(!retval)) + return -1; + Py_DECREF(retval); } - #endif - Py_XINCREF(local_tb); - Py_XINCREF(local_type); - Py_XINCREF(local_value); - *type = local_type; - *value = local_value; - *tb = local_tb; -#if CYTHON_FAST_THREAD_STATE - #if PY_VERSION_HEX >= 0x030700A2 - tmp_type = tstate->exc_state.exc_type; - tmp_value = tstate->exc_state.exc_value; - tmp_tb = tstate->exc_state.exc_traceback; - tstate->exc_state.exc_type = local_type; - tstate->exc_state.exc_value = local_value; - tstate->exc_state.exc_traceback = local_tb; - #else - tmp_type = tstate->exc_type; - tmp_value = tstate->exc_value; - tmp_tb = tstate->exc_traceback; - tstate->exc_type = local_type; - tstate->exc_value = local_value; - tstate->exc_traceback = local_tb; - #endif - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -#else - PyErr_SetExcInfo(local_type, local_value, local_tb); -#endif return 0; -bad: - *type = 0; - *value = 0; - *tb = 0; - Py_XDECREF(local_type); - Py_XDECREF(local_value); - Py_XDECREF(local_tb); - return -1; } /* WriteUnraisableException */ - static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, + static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename, int full_traceback, CYTHON_UNUSED int nogil) { PyObject *old_exc, *old_val, *old_tb; @@ -14585,20 +14801,20 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) } /* RaiseTooManyValuesToUnpack */ - static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { + static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { PyErr_Format(PyExc_ValueError, "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected); } /* RaiseNeedMoreValuesToUnpack */ - static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { + static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack", index, (index == 1) ? "" : "s"); } /* IterFinish */ - static CYTHON_INLINE int __Pyx_IterFinish(void) { + static CYTHON_INLINE int __Pyx_IterFinish(void) { #if CYTHON_FAST_THREAD_STATE PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject* exc_type = tstate->curexc_type; @@ -14633,7 +14849,7 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) } /* UnpackItemEndCheck */ - static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { + static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { if (unlikely(retval)) { Py_DECREF(retval); __Pyx_RaiseTooManyValuesError(expected); @@ -14644,7 +14860,77 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) return 0; } -/* SwapException */ +/* GetException */ + #if CYTHON_FAST_THREAD_STATE +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { +#endif + PyObject *local_type, *local_value, *local_tb; +#if CYTHON_FAST_THREAD_STATE + PyObject *tmp_type, *tmp_value, *tmp_tb; + local_type = tstate->curexc_type; + local_value = tstate->curexc_value; + local_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#else + PyErr_Fetch(&local_type, &local_value, &local_tb); +#endif + PyErr_NormalizeException(&local_type, &local_value, &local_tb); +#if CYTHON_FAST_THREAD_STATE + if (unlikely(tstate->curexc_type)) +#else + if (unlikely(PyErr_Occurred())) +#endif + goto bad; + #if PY_MAJOR_VERSION >= 3 + if (local_tb) { + if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) + goto bad; + } + #endif + Py_XINCREF(local_tb); + Py_XINCREF(local_type); + Py_XINCREF(local_value); + *type = local_type; + *value = local_value; + *tb = local_tb; +#if CYTHON_FAST_THREAD_STATE + #if PY_VERSION_HEX >= 0x030700A2 + tmp_type = tstate->exc_state.exc_type; + tmp_value = tstate->exc_state.exc_value; + tmp_tb = tstate->exc_state.exc_traceback; + tstate->exc_state.exc_type = local_type; + tstate->exc_state.exc_value = local_value; + tstate->exc_state.exc_traceback = local_tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = local_type; + tstate->exc_value = local_value; + tstate->exc_traceback = local_tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(local_type, local_value, local_tb); +#endif + return 0; +bad: + *type = 0; + *value = 0; + *tb = 0; + Py_XDECREF(local_type); + Py_XDECREF(local_value); + Py_XDECREF(local_tb); + return -1; +} + +/* SwapException */ #if CYTHON_FAST_THREAD_STATE static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; @@ -14678,6 +14964,132 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, } #endif +/* SaveResetException */ + #if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + #if PY_VERSION_HEX >= 0x030700A2 + *type = tstate->exc_state.exc_type; + *value = tstate->exc_state.exc_value; + *tb = tstate->exc_state.exc_traceback; + #else + *type = tstate->exc_type; + *value = tstate->exc_value; + *tb = tstate->exc_traceback; + #endif + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); +} +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if PY_VERSION_HEX >= 0x030700A2 + tmp_type = tstate->exc_state.exc_type; + tmp_value = tstate->exc_state.exc_value; + tmp_tb = tstate->exc_state.exc_traceback; + tstate->exc_state.exc_type = type; + tstate->exc_state.exc_value = value; + tstate->exc_state.exc_traceback = tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = type; + tstate->exc_value = value; + tstate->exc_traceback = tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} +#endif + +/* GetItemInt */ + static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (!j) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyList_GET_SIZE(o); + } + if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyTuple_GET_SIZE(o); + } + if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS + if (is_list || PyList_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } else { + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_item)) { + if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { + Py_ssize_t l = m->sq_length(o); + if (likely(l >= 0)) { + i += l; + } else { + if (!PyErr_ExceptionMatches(PyExc_OverflowError)) + return NULL; + PyErr_Clear(); + } + } + return m->sq_item(o, i); + } + } +#else + if (is_list || PySequence_Check(o)) { + return PySequence_GetItem(o, i); + } +#endif + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + /* ObjectGetItem */ #if CYTHON_USE_TYPE_SLOTS static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) { @@ -15283,24 +15695,24 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { - const long neg_one = (long) -1, const_zero = (long) 0; + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { + const int neg_one = (int) -1, const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { - if (sizeof(long) < sizeof(long)) { + if (sizeof(int) < sizeof(long)) { return PyInt_FromLong((long) value); - } else if (sizeof(long) <= sizeof(unsigned long)) { + } else if (sizeof(int) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { - if (sizeof(long) <= sizeof(long)) { + if (sizeof(int) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } @@ -15308,30 +15720,30 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(long), + return _PyLong_FromByteArray(bytes, sizeof(int), little, !is_unsigned); } } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { - const int neg_one = (int) -1, const_zero = (int) 0; + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { - if (sizeof(int) < sizeof(long)) { + if (sizeof(long) < sizeof(long)) { return PyInt_FromLong((long) value); - } else if (sizeof(int) <= sizeof(unsigned long)) { + } else if (sizeof(long) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); #endif } } else { - if (sizeof(int) <= sizeof(long)) { + if (sizeof(long) <= sizeof(long)) { return PyInt_FromLong((long) value); #ifdef HAVE_LONG_LONG - } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); #endif } @@ -15339,7 +15751,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(int), + return _PyLong_FromByteArray(bytes, sizeof(long), little, !is_unsigned); } } @@ -15794,999 +16206,8 @@ static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObj } #endif -/* FetchCommonType */ - static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { - PyObject* fake_module; - PyTypeObject* cached_type = NULL; - fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI); - if (!fake_module) return NULL; - Py_INCREF(fake_module); - cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name); - if (cached_type) { - if (!PyType_Check((PyObject*)cached_type)) { - PyErr_Format(PyExc_TypeError, - "Shared Cython type %.200s is not a type object", - type->tp_name); - goto bad; - } - if (cached_type->tp_basicsize != type->tp_basicsize) { - PyErr_Format(PyExc_TypeError, - "Shared Cython type %.200s has the wrong size, try recompiling", - type->tp_name); - goto bad; - } - } else { - if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; - PyErr_Clear(); - if (PyType_Ready(type) < 0) goto bad; - if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0) - goto bad; - Py_INCREF(type); - cached_type = type; - } -done: - Py_DECREF(fake_module); - return cached_type; -bad: - Py_XDECREF(cached_type); - cached_type = NULL; - goto done; -} - -/* PyObjectCallMethod1 */ - static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { - PyObject *result = NULL; -#if CYTHON_UNPACK_METHODS - if (likely(PyMethod_Check(method))) { - PyObject *self = PyMethod_GET_SELF(method); - if (likely(self)) { - PyObject *args; - PyObject *function = PyMethod_GET_FUNCTION(method); - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(function)) { - PyObject *args[2] = {self, arg}; - result = __Pyx_PyFunction_FastCall(function, args, 2); - goto done; - } - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(function)) { - PyObject *args[2] = {self, arg}; - result = __Pyx_PyCFunction_FastCall(function, args, 2); - goto done; - } - #endif - args = PyTuple_New(2); - if (unlikely(!args)) goto done; - Py_INCREF(self); - PyTuple_SET_ITEM(args, 0, self); - Py_INCREF(arg); - PyTuple_SET_ITEM(args, 1, arg); - Py_INCREF(function); - result = __Pyx_PyObject_Call(function, args, NULL); - Py_DECREF(args); - Py_DECREF(function); - return result; - } - } -#endif - result = __Pyx_PyObject_CallOneArg(method, arg); - goto done; -done: - return result; -} -static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { - PyObject *method, *result; - method = __Pyx_PyObject_GetAttrStr(obj, method_name); - if (unlikely(!method)) return NULL; - result = __Pyx__PyObject_CallMethod1(method, arg); - Py_DECREF(method); - return result; -} - -/* CoroutineBase */ - #include -#include -#define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom) -static int __Pyx_PyGen__FetchStopIterationValue(CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject **pvalue) { - PyObject *et, *ev, *tb; - PyObject *value = NULL; - __Pyx_ErrFetch(&et, &ev, &tb); - if (!et) { - Py_XDECREF(tb); - Py_XDECREF(ev); - Py_INCREF(Py_None); - *pvalue = Py_None; - return 0; - } - if (likely(et == PyExc_StopIteration)) { - if (!ev) { - Py_INCREF(Py_None); - value = Py_None; - } -#if PY_VERSION_HEX >= 0x030300A0 - else if (Py_TYPE(ev) == (PyTypeObject*)PyExc_StopIteration) { - value = ((PyStopIterationObject *)ev)->value; - Py_INCREF(value); - Py_DECREF(ev); - } -#endif - else if (unlikely(PyTuple_Check(ev))) { - if (PyTuple_GET_SIZE(ev) >= 1) { -#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - value = PyTuple_GET_ITEM(ev, 0); - Py_INCREF(value); -#else - value = PySequence_ITEM(ev, 0); -#endif - } else { - Py_INCREF(Py_None); - value = Py_None; - } - Py_DECREF(ev); - } - else if (!__Pyx_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) { - value = ev; - } - if (likely(value)) { - Py_XDECREF(tb); - Py_DECREF(et); - *pvalue = value; - return 0; - } - } else if (!__Pyx_PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) { - __Pyx_ErrRestore(et, ev, tb); - return -1; - } - PyErr_NormalizeException(&et, &ev, &tb); - if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) { - __Pyx_ErrRestore(et, ev, tb); - return -1; - } - Py_XDECREF(tb); - Py_DECREF(et); -#if PY_VERSION_HEX >= 0x030300A0 - value = ((PyStopIterationObject *)ev)->value; - Py_INCREF(value); - Py_DECREF(ev); -#else - { - PyObject* args = __Pyx_PyObject_GetAttrStr(ev, __pyx_n_s_args); - Py_DECREF(ev); - if (likely(args)) { - value = PySequence_GetItem(args, 0); - Py_DECREF(args); - } - if (unlikely(!value)) { - __Pyx_ErrRestore(NULL, NULL, NULL); - Py_INCREF(Py_None); - value = Py_None; - } - } -#endif - *pvalue = value; - return 0; -} -static CYTHON_INLINE -void __Pyx_Coroutine_ExceptionClear(__pyx_CoroutineObject *self) { - PyObject *exc_type = self->exc_type; - PyObject *exc_value = self->exc_value; - PyObject *exc_traceback = self->exc_traceback; - self->exc_type = NULL; - self->exc_value = NULL; - self->exc_traceback = NULL; - Py_XDECREF(exc_type); - Py_XDECREF(exc_value); - Py_XDECREF(exc_traceback); -} -#define __Pyx_Coroutine_AlreadyRunningError(gen) (__Pyx__Coroutine_AlreadyRunningError(gen), (PyObject*)NULL) -static void __Pyx__Coroutine_AlreadyRunningError(CYTHON_UNUSED __pyx_CoroutineObject *gen) { - const char *msg; - if (0) { - #ifdef __Pyx_Coroutine_USED - } else if (__Pyx_Coroutine_Check((PyObject*)gen)) { - msg = "coroutine already executing"; - #endif - #ifdef __Pyx_AsyncGen_USED - } else if (__Pyx_AsyncGen_CheckExact((PyObject*)gen)) { - msg = "async generator already executing"; - #endif - } else { - msg = "generator already executing"; - } - PyErr_SetString(PyExc_ValueError, msg); -} -#define __Pyx_Coroutine_NotStartedError(gen) (__Pyx__Coroutine_NotStartedError(gen), (PyObject*)NULL) -static void __Pyx__Coroutine_NotStartedError(CYTHON_UNUSED PyObject *gen) { - const char *msg; - if (0) { - #ifdef __Pyx_Coroutine_USED - } else if (__Pyx_Coroutine_Check(gen)) { - msg = "can't send non-None value to a just-started coroutine"; - #endif - #ifdef __Pyx_AsyncGen_USED - } else if (__Pyx_AsyncGen_CheckExact(gen)) { - msg = "can't send non-None value to a just-started async generator"; - #endif - } else { - msg = "can't send non-None value to a just-started generator"; - } - PyErr_SetString(PyExc_TypeError, msg); -} -#define __Pyx_Coroutine_AlreadyTerminatedError(gen, value, closing) (__Pyx__Coroutine_AlreadyTerminatedError(gen, value, closing), (PyObject*)NULL) -static void __Pyx__Coroutine_AlreadyTerminatedError(CYTHON_UNUSED PyObject *gen, PyObject *value, CYTHON_UNUSED int closing) { - #ifdef __Pyx_Coroutine_USED - if (!closing && __Pyx_Coroutine_Check(gen)) { - PyErr_SetString(PyExc_RuntimeError, "cannot reuse already awaited coroutine"); - } else - #endif - if (value) { - #ifdef __Pyx_AsyncGen_USED - if (__Pyx_AsyncGen_CheckExact(gen)) - PyErr_SetNone(__Pyx_PyExc_StopAsyncIteration); - else - #endif - PyErr_SetNone(PyExc_StopIteration); - } -} -static -PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value, int closing) { - __Pyx_PyThreadState_declare - PyThreadState *tstate; - PyObject *retval; - assert(!self->is_running); - if (unlikely(self->resume_label == 0)) { - if (unlikely(value && value != Py_None)) { - return __Pyx_Coroutine_NotStartedError((PyObject*)self); - } - } - if (unlikely(self->resume_label == -1)) { - return __Pyx_Coroutine_AlreadyTerminatedError((PyObject*)self, value, closing); - } -#if CYTHON_FAST_THREAD_STATE - __Pyx_PyThreadState_assign - tstate = __pyx_tstate; -#else - tstate = __Pyx_PyThreadState_Current; -#endif - if (self->exc_type) { -#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON -#else - if (self->exc_traceback) { - PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback; - PyFrameObject *f = tb->tb_frame; - Py_XINCREF(tstate->frame); - assert(f->f_back == NULL); - f->f_back = tstate->frame; - } -#endif - __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, - &self->exc_traceback); - } else { - __Pyx_Coroutine_ExceptionClear(self); - __Pyx_ExceptionSave(&self->exc_type, &self->exc_value, &self->exc_traceback); - } - self->is_running = 1; - retval = self->body((PyObject *) self, tstate, value); - self->is_running = 0; - return retval; -} -static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__pyx_CoroutineObject *self) { - if (likely(self->exc_traceback)) { -#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON -#else - PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback; - PyFrameObject *f = tb->tb_frame; - Py_CLEAR(f->f_back); -#endif - } -} -static CYTHON_INLINE -PyObject *__Pyx_Coroutine_MethodReturn(CYTHON_UNUSED PyObject* gen, PyObject *retval) { - if (unlikely(!retval)) { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - if (!__Pyx_PyErr_Occurred()) { - PyObject *exc = PyExc_StopIteration; - #ifdef __Pyx_AsyncGen_USED - if (__Pyx_AsyncGen_CheckExact(gen)) - exc = __Pyx_PyExc_StopAsyncIteration; - #endif - __Pyx_PyErr_SetNone(exc); - } - } - return retval; -} -static CYTHON_INLINE -PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) { - PyObject *ret; - PyObject *val = NULL; - __Pyx_Coroutine_Undelegate(gen); - __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, &val); - ret = __Pyx_Coroutine_SendEx(gen, val, 0); - Py_XDECREF(val); - return ret; -} -static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) { - PyObject *retval; - __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; - PyObject *yf = gen->yieldfrom; - if (unlikely(gen->is_running)) - return __Pyx_Coroutine_AlreadyRunningError(gen); - if (yf) { - PyObject *ret; - gen->is_running = 1; - #ifdef __Pyx_Generator_USED - if (__Pyx_Generator_CheckExact(yf)) { - ret = __Pyx_Coroutine_Send(yf, value); - } else - #endif - #ifdef __Pyx_Coroutine_USED - if (__Pyx_Coroutine_Check(yf)) { - ret = __Pyx_Coroutine_Send(yf, value); - } else - #endif - #ifdef __Pyx_AsyncGen_USED - if (__pyx_PyAsyncGenASend_CheckExact(yf)) { - ret = __Pyx_async_gen_asend_send(yf, value); - } else - #endif - #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) - if (PyGen_CheckExact(yf)) { - ret = _PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value); - } else - #endif - #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03050000 && defined(PyCoro_CheckExact) && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) - if (PyCoro_CheckExact(yf)) { - ret = _PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value); - } else - #endif - { - if (value == Py_None) - ret = Py_TYPE(yf)->tp_iternext(yf); - else - ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value); - } - gen->is_running = 0; - if (likely(ret)) { - return ret; - } - retval = __Pyx_Coroutine_FinishDelegation(gen); - } else { - retval = __Pyx_Coroutine_SendEx(gen, value, 0); - } - return __Pyx_Coroutine_MethodReturn(self, retval); -} -static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) { - PyObject *retval = NULL; - int err = 0; - #ifdef __Pyx_Generator_USED - if (__Pyx_Generator_CheckExact(yf)) { - retval = __Pyx_Coroutine_Close(yf); - if (!retval) - return -1; - } else - #endif - #ifdef __Pyx_Coroutine_USED - if (__Pyx_Coroutine_Check(yf)) { - retval = __Pyx_Coroutine_Close(yf); - if (!retval) - return -1; - } else - if (__Pyx_CoroutineAwait_CheckExact(yf)) { - retval = __Pyx_CoroutineAwait_Close((__pyx_CoroutineAwaitObject*)yf); - if (!retval) - return -1; - } else - #endif - #ifdef __Pyx_AsyncGen_USED - if (__pyx_PyAsyncGenASend_CheckExact(yf)) { - retval = __Pyx_async_gen_asend_close(yf, NULL); - } else - if (__pyx_PyAsyncGenAThrow_CheckExact(yf)) { - retval = __Pyx_async_gen_athrow_close(yf, NULL); - } else - #endif - { - PyObject *meth; - gen->is_running = 1; - meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_close); - if (unlikely(!meth)) { - if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_WriteUnraisable(yf); - } - PyErr_Clear(); - } else { - retval = PyObject_CallFunction(meth, NULL); - Py_DECREF(meth); - if (!retval) - err = -1; - } - gen->is_running = 0; - } - Py_XDECREF(retval); - return err; -} -static PyObject *__Pyx_Generator_Next(PyObject *self) { - __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; - PyObject *yf = gen->yieldfrom; - if (unlikely(gen->is_running)) - return __Pyx_Coroutine_AlreadyRunningError(gen); - if (yf) { - PyObject *ret; - gen->is_running = 1; - #ifdef __Pyx_Generator_USED - if (__Pyx_Generator_CheckExact(yf)) { - ret = __Pyx_Generator_Next(yf); - } else - #endif - #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) - if (PyGen_CheckExact(yf)) { - ret = _PyGen_Send((PyGenObject*)yf, NULL); - } else - #endif - #ifdef __Pyx_Coroutine_USED - if (__Pyx_Coroutine_Check(yf)) { - ret = __Pyx_Coroutine_Send(yf, Py_None); - } else - #endif - ret = Py_TYPE(yf)->tp_iternext(yf); - gen->is_running = 0; - if (likely(ret)) { - return ret; - } - return __Pyx_Coroutine_FinishDelegation(gen); - } - return __Pyx_Coroutine_SendEx(gen, Py_None, 0); -} -static PyObject *__Pyx_Coroutine_Close(PyObject *self) { - __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; - PyObject *retval, *raised_exception; - PyObject *yf = gen->yieldfrom; - int err = 0; - if (unlikely(gen->is_running)) - return __Pyx_Coroutine_AlreadyRunningError(gen); - if (yf) { - Py_INCREF(yf); - err = __Pyx_Coroutine_CloseIter(gen, yf); - __Pyx_Coroutine_Undelegate(gen); - Py_DECREF(yf); - } - if (err == 0) - PyErr_SetNone(PyExc_GeneratorExit); - retval = __Pyx_Coroutine_SendEx(gen, NULL, 1); - if (unlikely(retval)) { - const char *msg; - Py_DECREF(retval); - if ((0)) { - #ifdef __Pyx_Coroutine_USED - } else if (__Pyx_Coroutine_Check(self)) { - msg = "coroutine ignored GeneratorExit"; - #endif - #ifdef __Pyx_AsyncGen_USED - } else if (__Pyx_AsyncGen_CheckExact(self)) { -#if PY_VERSION_HEX < 0x03060000 - msg = "async generator ignored GeneratorExit - might require Python 3.6+ finalisation (PEP 525)"; -#else - msg = "async generator ignored GeneratorExit"; -#endif - #endif - } else { - msg = "generator ignored GeneratorExit"; - } - PyErr_SetString(PyExc_RuntimeError, msg); - return NULL; - } - raised_exception = PyErr_Occurred(); - if (likely(!raised_exception || __Pyx_PyErr_GivenExceptionMatches2(raised_exception, PyExc_GeneratorExit, PyExc_StopIteration))) { - if (raised_exception) PyErr_Clear(); - Py_INCREF(Py_None); - return Py_None; - } - return NULL; -} -static PyObject *__Pyx__Coroutine_Throw(PyObject *self, PyObject *typ, PyObject *val, PyObject *tb, - PyObject *args, int close_on_genexit) { - __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; - PyObject *yf = gen->yieldfrom; - if (unlikely(gen->is_running)) - return __Pyx_Coroutine_AlreadyRunningError(gen); - if (yf) { - PyObject *ret; - Py_INCREF(yf); - if (__Pyx_PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && close_on_genexit) { - int err = __Pyx_Coroutine_CloseIter(gen, yf); - Py_DECREF(yf); - __Pyx_Coroutine_Undelegate(gen); - if (err < 0) - return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0)); - goto throw_here; - } - gen->is_running = 1; - if (0 - #ifdef __Pyx_Generator_USED - || __Pyx_Generator_CheckExact(yf) - #endif - #ifdef __Pyx_Coroutine_USED - || __Pyx_Coroutine_Check(yf) - #endif - ) { - ret = __Pyx__Coroutine_Throw(yf, typ, val, tb, args, close_on_genexit); - #ifdef __Pyx_Coroutine_USED - } else if (__Pyx_CoroutineAwait_CheckExact(yf)) { - ret = __Pyx__Coroutine_Throw(((__pyx_CoroutineAwaitObject*)yf)->coroutine, typ, val, tb, args, close_on_genexit); - #endif - } else { - PyObject *meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_throw); - if (unlikely(!meth)) { - Py_DECREF(yf); - if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { - gen->is_running = 0; - return NULL; - } - PyErr_Clear(); - __Pyx_Coroutine_Undelegate(gen); - gen->is_running = 0; - goto throw_here; - } - if (likely(args)) { - ret = PyObject_CallObject(meth, args); - } else { - ret = PyObject_CallFunctionObjArgs(meth, typ, val, tb, NULL); - } - Py_DECREF(meth); - } - gen->is_running = 0; - Py_DECREF(yf); - if (!ret) { - ret = __Pyx_Coroutine_FinishDelegation(gen); - } - return __Pyx_Coroutine_MethodReturn(self, ret); - } -throw_here: - __Pyx_Raise(typ, val, tb, NULL); - return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0)); -} -static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) { - PyObject *typ; - PyObject *val = NULL; - PyObject *tb = NULL; - if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb)) - return NULL; - return __Pyx__Coroutine_Throw(self, typ, val, tb, args, 1); -} -static int __Pyx_Coroutine_traverse(__pyx_CoroutineObject *gen, visitproc visit, void *arg) { - Py_VISIT(gen->closure); - Py_VISIT(gen->classobj); - Py_VISIT(gen->yieldfrom); - Py_VISIT(gen->exc_type); - Py_VISIT(gen->exc_value); - Py_VISIT(gen->exc_traceback); - return 0; -} -static int __Pyx_Coroutine_clear(PyObject *self) { - __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; - Py_CLEAR(gen->closure); - Py_CLEAR(gen->classobj); - Py_CLEAR(gen->yieldfrom); - Py_CLEAR(gen->exc_type); - Py_CLEAR(gen->exc_value); - Py_CLEAR(gen->exc_traceback); -#ifdef __Pyx_AsyncGen_USED - if (__Pyx_AsyncGen_CheckExact(self)) { - Py_CLEAR(((__pyx_PyAsyncGenObject*)gen)->ag_finalizer); - } -#endif - Py_CLEAR(gen->gi_code); - Py_CLEAR(gen->gi_name); - Py_CLEAR(gen->gi_qualname); - Py_CLEAR(gen->gi_modulename); - return 0; -} -static void __Pyx_Coroutine_dealloc(PyObject *self) { - __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; - PyObject_GC_UnTrack(gen); - if (gen->gi_weakreflist != NULL) - PyObject_ClearWeakRefs(self); - if (gen->resume_label >= 0) { - PyObject_GC_Track(self); -#if PY_VERSION_HEX >= 0x030400a1 && CYTHON_USE_TP_FINALIZE - if (PyObject_CallFinalizerFromDealloc(self)) -#else - Py_TYPE(gen)->tp_del(self); - if (self->ob_refcnt > 0) -#endif - { - return; - } - PyObject_GC_UnTrack(self); - } -#ifdef __Pyx_AsyncGen_USED - if (__Pyx_AsyncGen_CheckExact(self)) { - /* We have to handle this case for asynchronous generators - right here, because this code has to be between UNTRACK - and GC_Del. */ - Py_CLEAR(((__pyx_PyAsyncGenObject*)self)->ag_finalizer); - } -#endif - __Pyx_Coroutine_clear(self); - PyObject_GC_Del(gen); -} -static void __Pyx_Coroutine_del(PyObject *self) { - PyObject *error_type, *error_value, *error_traceback; - __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; - __Pyx_PyThreadState_declare - if (gen->resume_label < 0) { - return; - } -#if !CYTHON_USE_TP_FINALIZE - assert(self->ob_refcnt == 0); - self->ob_refcnt = 1; -#endif - __Pyx_PyThreadState_assign - __Pyx_ErrFetch(&error_type, &error_value, &error_traceback); -#ifdef __Pyx_AsyncGen_USED - if (__Pyx_AsyncGen_CheckExact(self)) { - __pyx_PyAsyncGenObject *agen = (__pyx_PyAsyncGenObject*)self; - PyObject *finalizer = agen->ag_finalizer; - if (finalizer && !agen->ag_closed) { - PyObject *res = __Pyx_PyObject_CallOneArg(finalizer, self); - if (unlikely(!res)) { - PyErr_WriteUnraisable(self); - } else { - Py_DECREF(res); - } - __Pyx_ErrRestore(error_type, error_value, error_traceback); - return; - } - } -#endif - if (unlikely(gen->resume_label == 0 && !error_value)) { -#ifdef __Pyx_Coroutine_USED -#ifdef __Pyx_Generator_USED - if (!__Pyx_Generator_CheckExact(self)) -#endif - { - PyObject_GC_UnTrack(self); -#if PY_MAJOR_VERSION >= 3 || defined(PyErr_WarnFormat) - if (unlikely(PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "coroutine '%.50S' was never awaited", gen->gi_qualname) < 0)) - PyErr_WriteUnraisable(self); -#else - {PyObject *msg; - char *cmsg; - #if CYTHON_COMPILING_IN_PYPY - msg = NULL; - cmsg = (char*) "coroutine was never awaited"; - #else - char *cname; - PyObject *qualname; - qualname = gen->gi_qualname; - cname = PyString_AS_STRING(qualname); - msg = PyString_FromFormat("coroutine '%.50s' was never awaited", cname); - if (unlikely(!msg)) { - PyErr_Clear(); - cmsg = (char*) "coroutine was never awaited"; - } else { - cmsg = PyString_AS_STRING(msg); - } - #endif - if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, cmsg, 1) < 0)) - PyErr_WriteUnraisable(self); - Py_XDECREF(msg);} -#endif - PyObject_GC_Track(self); - } -#endif - } else { - PyObject *res = __Pyx_Coroutine_Close(self); - if (unlikely(!res)) { - if (PyErr_Occurred()) - PyErr_WriteUnraisable(self); - } else { - Py_DECREF(res); - } - } - __Pyx_ErrRestore(error_type, error_value, error_traceback); -#if !CYTHON_USE_TP_FINALIZE - assert(self->ob_refcnt > 0); - if (--self->ob_refcnt == 0) { - return; - } - { - Py_ssize_t refcnt = self->ob_refcnt; - _Py_NewReference(self); - self->ob_refcnt = refcnt; - } -#if CYTHON_COMPILING_IN_CPYTHON - assert(PyType_IS_GC(self->ob_type) && - _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED); - _Py_DEC_REFTOTAL; -#endif -#ifdef COUNT_ALLOCS - --Py_TYPE(self)->tp_frees; - --Py_TYPE(self)->tp_allocs; -#endif -#endif -} -static PyObject * -__Pyx_Coroutine_get_name(__pyx_CoroutineObject *self) -{ - PyObject *name = self->gi_name; - if (unlikely(!name)) name = Py_None; - Py_INCREF(name); - return name; -} -static int -__Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value) -{ - PyObject *tmp; -#if PY_MAJOR_VERSION >= 3 - if (unlikely(value == NULL || !PyUnicode_Check(value))) { -#else - if (unlikely(value == NULL || !PyString_Check(value))) { -#endif - PyErr_SetString(PyExc_TypeError, - "__name__ must be set to a string object"); - return -1; - } - tmp = self->gi_name; - Py_INCREF(value); - self->gi_name = value; - Py_XDECREF(tmp); - return 0; -} -static PyObject * -__Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self) -{ - PyObject *name = self->gi_qualname; - if (unlikely(!name)) name = Py_None; - Py_INCREF(name); - return name; -} -static int -__Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value) -{ - PyObject *tmp; -#if PY_MAJOR_VERSION >= 3 - if (unlikely(value == NULL || !PyUnicode_Check(value))) { -#else - if (unlikely(value == NULL || !PyString_Check(value))) { -#endif - PyErr_SetString(PyExc_TypeError, - "__qualname__ must be set to a string object"); - return -1; - } - tmp = self->gi_qualname; - Py_INCREF(value); - self->gi_qualname = value; - Py_XDECREF(tmp); - return 0; -} -static __pyx_CoroutineObject *__Pyx__Coroutine_New( - PyTypeObject* type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, - PyObject *name, PyObject *qualname, PyObject *module_name) { - __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type); - if (unlikely(!gen)) - return NULL; - return __Pyx__Coroutine_NewInit(gen, body, code, closure, name, qualname, module_name); -} -static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit( - __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, - PyObject *name, PyObject *qualname, PyObject *module_name) { - gen->body = body; - gen->closure = closure; - Py_XINCREF(closure); - gen->is_running = 0; - gen->resume_label = 0; - gen->classobj = NULL; - gen->yieldfrom = NULL; - gen->exc_type = NULL; - gen->exc_value = NULL; - gen->exc_traceback = NULL; - gen->gi_weakreflist = NULL; - Py_XINCREF(qualname); - gen->gi_qualname = qualname; - Py_XINCREF(name); - gen->gi_name = name; - Py_XINCREF(module_name); - gen->gi_modulename = module_name; - Py_XINCREF(code); - gen->gi_code = code; - PyObject_GC_Track(gen); - return gen; -} - -/* PatchModuleWithCoroutine */ - static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) { -#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) - int result; - PyObject *globals, *result_obj; - globals = PyDict_New(); if (unlikely(!globals)) goto ignore; - result = PyDict_SetItemString(globals, "_cython_coroutine_type", - #ifdef __Pyx_Coroutine_USED - (PyObject*)__pyx_CoroutineType); - #else - Py_None); - #endif - if (unlikely(result < 0)) goto ignore; - result = PyDict_SetItemString(globals, "_cython_generator_type", - #ifdef __Pyx_Generator_USED - (PyObject*)__pyx_GeneratorType); - #else - Py_None); - #endif - if (unlikely(result < 0)) goto ignore; - if (unlikely(PyDict_SetItemString(globals, "_module", module) < 0)) goto ignore; - if (unlikely(PyDict_SetItemString(globals, "__builtins__", __pyx_b) < 0)) goto ignore; - result_obj = PyRun_String(py_code, Py_file_input, globals, globals); - if (unlikely(!result_obj)) goto ignore; - Py_DECREF(result_obj); - Py_DECREF(globals); - return module; -ignore: - Py_XDECREF(globals); - PyErr_WriteUnraisable(module); - if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch module with custom type", 1) < 0)) { - Py_DECREF(module); - module = NULL; - } -#else - py_code++; -#endif - return module; -} - -/* PatchGeneratorABC */ - #ifndef CYTHON_REGISTER_ABCS -#define CYTHON_REGISTER_ABCS 1 -#endif -#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) -static PyObject* __Pyx_patch_abc_module(PyObject *module); -static PyObject* __Pyx_patch_abc_module(PyObject *module) { - module = __Pyx_Coroutine_patch_module( - module, "" -"if _cython_generator_type is not None:\n" -" try: Generator = _module.Generator\n" -" except AttributeError: pass\n" -" else: Generator.register(_cython_generator_type)\n" -"if _cython_coroutine_type is not None:\n" -" try: Coroutine = _module.Coroutine\n" -" except AttributeError: pass\n" -" else: Coroutine.register(_cython_coroutine_type)\n" - ); - return module; -} -#endif -static int __Pyx_patch_abc(void) { -#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) - static int abc_patched = 0; - if (CYTHON_REGISTER_ABCS && !abc_patched) { - PyObject *module; - module = PyImport_ImportModule((PY_MAJOR_VERSION >= 3) ? "collections.abc" : "collections"); - if (!module) { - PyErr_WriteUnraisable(NULL); - if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, - ((PY_MAJOR_VERSION >= 3) ? - "Cython module failed to register with collections.abc module" : - "Cython module failed to register with collections module"), 1) < 0)) { - return -1; - } - } else { - module = __Pyx_patch_abc_module(module); - abc_patched = 1; - if (unlikely(!module)) - return -1; - Py_DECREF(module); - } - module = PyImport_ImportModule("backports_abc"); - if (module) { - module = __Pyx_patch_abc_module(module); - Py_XDECREF(module); - } - if (!module) { - PyErr_Clear(); - } - } -#else - if ((0)) __Pyx_Coroutine_patch_module(NULL, NULL); -#endif - return 0; -} - -/* Generator */ - static PyMethodDef __pyx_Generator_methods[] = { - {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O, - (char*) PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")}, - {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS, - (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in generator,\nreturn next yielded value or raise StopIteration.")}, - {"close", (PyCFunction) __Pyx_Coroutine_Close, METH_NOARGS, - (char*) PyDoc_STR("close() -> raise GeneratorExit inside generator.")}, - {0, 0, 0, 0} -}; -static PyMemberDef __pyx_Generator_memberlist[] = { - {(char *) "gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL}, - {(char*) "gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY, - (char*) PyDoc_STR("object being iterated by 'yield from', or None")}, - {(char*) "gi_code", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_code), READONLY, NULL}, - {0, 0, 0, 0, 0} -}; -static PyGetSetDef __pyx_Generator_getsets[] = { - {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name, - (char*) PyDoc_STR("name of the generator"), 0}, - {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname, - (char*) PyDoc_STR("qualified name of the generator"), 0}, - {0, 0, 0, 0, 0} -}; -static PyTypeObject __pyx_GeneratorType_type = { - PyVarObject_HEAD_INIT(0, 0) - "generator", - sizeof(__pyx_CoroutineObject), - 0, - (destructor) __Pyx_Coroutine_dealloc, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, - 0, - (traverseproc) __Pyx_Coroutine_traverse, - 0, - 0, - offsetof(__pyx_CoroutineObject, gi_weakreflist), - 0, - (iternextfunc) __Pyx_Generator_Next, - __pyx_Generator_methods, - __pyx_Generator_memberlist, - __pyx_Generator_getsets, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, -#if CYTHON_USE_TP_FINALIZE - 0, -#else - __Pyx_Coroutine_del, -#endif - 0, -#if CYTHON_USE_TP_FINALIZE - __Pyx_Coroutine_del, -#elif PY_VERSION_HEX >= 0x030400a1 - 0, -#endif -}; -static int __pyx_Generator_init(void) { - __pyx_GeneratorType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; - __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter; - __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type); - if (unlikely(!__pyx_GeneratorType)) { - return -1; - } - return 0; -} - /* CheckBinaryVersion */ - static int __Pyx_check_binary_version(void) { + static int __Pyx_check_binary_version(void) { char ctversion[4], rtversion[4]; PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); @@ -16802,7 +16223,7 @@ static int __pyx_Generator_init(void) { } /* ModuleImport */ - #ifndef __PYX_HAVE_RT_ImportModule + #ifndef __PYX_HAVE_RT_ImportModule #define __PYX_HAVE_RT_ImportModule static PyObject *__Pyx_ImportModule(const char *name) { PyObject *py_name = 0; @@ -16820,7 +16241,7 @@ static PyObject *__Pyx_ImportModule(const char *name) { #endif /* TypeImport */ - #ifndef __PYX_HAVE_RT_ImportType + #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict) @@ -16885,7 +16306,7 @@ static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class #endif /* FunctionImport */ - #ifndef __PYX_HAVE_RT_ImportFunction + #ifndef __PYX_HAVE_RT_ImportFunction #define __PYX_HAVE_RT_ImportFunction static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) { PyObject *d = 0; @@ -16939,7 +16360,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** #endif /* InitStrings */ - static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { diff --git a/pysam/libcfaidx.pxd b/pysam/libcfaidx.pxd index 2f5f44bec..53ad767df 100644 --- a/pysam/libcfaidx.pxd +++ b/pysam/libcfaidx.pxd @@ -39,24 +39,25 @@ cdef class FastaFile: cdef object _filename, _references, _lengths, reference2length cdef faidx_t* fastafile cdef char* _fetch(self, char* reference, - int start, int end, int* length) + int start, int end, int* length) except? NULL cdef class FastqProxy: cdef kseq_t * _delegate + cdef cython.str to_string(self) cdef cython.str tostring(self) cpdef array.array get_quality_array(self, int offset=*) -cdef class PersistentFastqProxy: +cdef class FastxRecord: """ Python container for pysam.libcfaidx.FastqProxy with persistence. """ cdef public str comment, quality, sequence, name + cdef cython.str to_string(self) cdef cython.str tostring(self) cpdef array.array get_quality_array(self, int offset=*) - cdef class FastxFile: cdef object _filename cdef BGZF * fastqfile diff --git a/pysam/libcfaidx.pyx b/pysam/libcfaidx.pyx index 774152d54..ca2f518ef 100644 --- a/pysam/libcfaidx.pyx +++ b/pysam/libcfaidx.pyx @@ -13,7 +13,7 @@ # of the internal API. These are: # # class FastqProxy -# class PersistentFastqProxy +# class FastxRecord # # For backwards compatibility, the following classes are also defined: # @@ -48,6 +48,11 @@ import sys import os import re + + +from libc.errno cimport errno +from libc.string cimport strerror + from cpython cimport array from cpython cimport PyErr_SetString, \ @@ -58,8 +63,8 @@ from cpython cimport PyErr_SetString, \ from cpython.version cimport PY_MAJOR_VERSION from pysam.libchtslib cimport \ - faidx_nseq, fai_load, fai_destroy, fai_fetch, \ - faidx_seq_len, \ + faidx_nseq, fai_load, fai_load3, fai_destroy, fai_fetch, \ + faidx_seq_len, faidx_iseq, faidx_seq_len, \ faidx_fetch_seq, hisremote, \ bgzf_open, bgzf_close @@ -94,6 +99,10 @@ cdef class FastaFile: Optional, filename of the index. By default this is the filename + ".fai". + filepath_index_compressed : string + Optional, filename of the index if fasta file is. By default this is + the filename + ".gzi". + Raises ------ @@ -123,7 +132,7 @@ cdef class FastaFile: return faidx_nseq(self.fastafile) - def _open(self, filename, filepath_index=None): + def _open(self, filename, filepath_index=None, filepath_index_compressed=None): '''open an indexed fasta file. This method expects an indexed fasta file. @@ -135,40 +144,55 @@ cdef class FastaFile: self._filename = encode_filename(filename) cdef char *cfilename = self._filename + cdef char *cindexname = NULL + cdef char *cindexname_compressed = NULL self.is_remote = hisremote(cfilename) - - if filepath_index is not None: - raise NotImplementedError( - "setting an explicit path for the index " - "is not implemented") - + # open file for reading if (self._filename != b"-" and not self.is_remote and not os.path.exists(filename)): raise IOError("file `%s` not found" % filename) - with nogil: - self.fastafile = fai_load(cfilename) + # 3 modes to open: + # compressed fa: fai_load3 with filename, index_fai and index_gzi + # uncompressed fa: fai_load3 with filename and index_fai + # uncompressed fa: fai_load with default index name + if filepath_index: + # when opening, set flags to 0 - do not automatically + # build index if it does not exist. + + if not os.path.exists(filepath_index): + raise IOError("filename {} does not exist".format(filepath_index)) + cindexname = bindex_filename = encode_filename(filepath_index) + + if filepath_index_compressed: + if not os.path.exists(filepath_index_compressed): + raise IOError("filename {} does not exist".format(filepath_index_compressed)) + cindexname_compressed = bindex_filename_compressed = encode_filename(filepath_index_compressed) + with nogil: + self.fastafile = fai_load3(cfilename, cindexname, cindexname_compressed, 0) + else: + with nogil: + self.fastafile = fai_load3(cfilename, cindexname, NULL, 0) + else: + with nogil: + self.fastafile = fai_load(cfilename) if self.fastafile == NULL: - raise IOError("could not open file `%s`" % filename) - - if self.is_remote: - filepath_index = os.path.basename( - re.sub("[^:]+:[/]*", "", filename)) + ".fai" - elif filepath_index is None: - filepath_index = filename + ".fai" - - if not os.path.exists(filepath_index): - raise ValueError("could not locate index file {}".format( - filepath_index)) - - with open(filepath_index) as inf: - data = [x.split("\t") for x in inf] - self._references = tuple(x[0] for x in data) - self._lengths = tuple(int(x[1]) for x in data) - self.reference2length = dict(zip(self._references, self._lengths)) + raise IOError("error when opening file `%s`" % filename) + + cdef int nreferences = faidx_nseq(self.fastafile) + cdef int x + cdef const char * s + self._references = [] + self._lengths = [] + for x from 0 <= x < nreferences: + s = faidx_iseq(self.fastafile, x) + ss = force_str(s) + self._references.append(ss) + self._lengths.append(faidx_seq_len(self.fastafile, s)) + self.reference2length = dict(zip(self._references, self._lengths)) def close(self): """close the file.""" @@ -287,24 +311,35 @@ cdef class FastaFile: rend-1, &length) - if seq == NULL: - raise ValueError( - "failure when retrieving sequence on '%s'" % reference) + if not seq: + if errno: + raise IOError(errno, strerror(errno)) + else: + raise ValueError("failure when retrieving sequence on '%s'" % reference) try: return charptr_to_str(seq) finally: free(seq) - cdef char * _fetch(self, char * reference, int start, int end, int * length): + cdef char *_fetch(self, char *reference, int start, int end, int *length) except? NULL: '''fetch sequence for reference, start and end''' + cdef char *seq with nogil: - return faidx_fetch_seq(self.fastafile, - reference, - start, - end-1, - length) + seq = faidx_fetch_seq(self.fastafile, + reference, + start, + end-1, + length) + + if not seq: + if errno: + raise IOError(errno, strerror(errno)) + else: + raise ValueError("failure when retrieving sequence on '%s'" % reference) + + return seq def get_reference_length(self, reference): '''return the length of reference.''' @@ -347,7 +382,7 @@ cdef class FastqProxy: else: return None - cdef cython.str tostring(self): + cdef cython.str to_string(self): if self.comment is None: comment = "" else: @@ -358,9 +393,13 @@ cdef class FastqProxy: else: return "@%s%s\n%s\n+\n%s" % (self.name, comment, self.sequence, self.quality) - + + cdef cython.str tostring(self): + """deprecated : use :meth:`to_string`""" + return self.to_string() + def __str__(self): - return self.tostring() + return self.to_string() cpdef array.array get_quality_array(self, int offset=33): '''return quality values as integer array after subtracting offset.''' @@ -369,18 +408,43 @@ cdef class FastqProxy: return qualitystring_to_array(force_bytes(self.quality), offset=offset) -cdef class PersistentFastqProxy: - """ - Python container for pysam.libcfaidx.FastqProxy with persistence. - Needed to compare multiple fastq records from the same file. +cdef class FastxRecord: + """A fasta/fastq record. + + A record must contain a name and a sequence. If either of them are + None, a ValueError is raised on writing. + """ - def __init__(self, FastqProxy FastqRead): - self.comment = FastqRead.comment - self.quality = FastqRead.quality - self.sequence = FastqRead.sequence - self.name = FastqRead.name + def __init__(self, + name=None, + comment=None, + sequence=None, + quality=None, + FastqProxy proxy=None): + if proxy is not None: + self.comment = proxy.comment + self.quality = proxy.quality + self.sequence = proxy.sequence + self.name = proxy.name + else: + self.comment = comment + self.quality = quality + self.sequence = sequence + self.name = name - cdef cython.str tostring(self): + def __copy__(self): + return FastxRecord(self.name, self.comment, self.sequence, self.quality) + + def __deepcopy__(self, memo): + return FastxRecord(self.name, self.comment, self.sequence, self.quality) + + cdef cython.str to_string(self): + if self.name is None: + raise ValueError("can not write record without name") + + if self.sequence is None: + raise ValueError("can not write record without a sequence") + if self.comment is None: comment = "" else: @@ -391,9 +455,35 @@ cdef class PersistentFastqProxy: else: return "@%s%s\n%s\n+\n%s" % (self.name, comment, self.sequence, self.quality) + + cdef cython.str tostring(self): + """deprecated : use :meth:`to_string`""" + return self.to_string() + + def set_name(self, name): + if name is None: + raise ValueError("FastxRecord must have a name and not None") + self.name = name + + def set_comment(self, comment): + self.comment = comment + + def set_sequence(self, sequence, quality=None): + """set sequence of this record. + + """ + self.sequence = sequence + if quality is not None: + if len(sequence) != len(quality): + raise ValueError("sequence and quality length do not match: {} vs {}".format( + len(sequence), len(quality))) + + self.quality = quality + else: + self.quality = None def __str__(self): - return self.tostring() + return self.to_string() cpdef array.array get_quality_array(self, int offset=33): '''return quality values as array after subtracting offset.''' @@ -425,12 +515,12 @@ cdef class FastxFile: If True (default) make a copy of the entry in the file during iteration. If set to False, no copy will be made. This will - permit faster iteration, but an entry will not persist when - the iteration continues. + permit much faster iteration, but an entry will not persist + when the iteration continues and an entry is read-only. Notes ----- - Prior to version 0.8.2, this was called FastqFile. + Prior to version 0.8.2, this class was called FastqFile. Raises ------ @@ -447,6 +537,9 @@ cdef class FastxFile: ... print(entry.sequence) ... print(entry.comment) ... print(entry.quality) + >>> with pysam.FastxFile(filename) as fin, open(out_filename, mode='w') as fout: + ... for entry in fin: + ... fout.write(str(entry)) """ def __cinit__(self, *args, **kwargs): @@ -550,7 +643,7 @@ cdef class FastxFile: l = kseq_read(self.entry) if (l >= 0): if self.persist: - return PersistentFastqProxy(makeFastqProxy(self.entry)) + return FastxRecord(proxy=makeFastqProxy(self.entry)) return makeFastqProxy(self.entry) else: raise StopIteration @@ -569,4 +662,5 @@ __all__ = ["FastaFile", "FastqFile", "FastxFile", "Fastafile", + "FastxRecord", "FastqProxy"] diff --git a/pysam/libchtslib.c b/pysam/libchtslib.c index 9e1b11518..4d3d626b3 100644 --- a/pysam/libchtslib.c +++ b/pysam/libchtslib.c @@ -567,6 +567,7 @@ static CYTHON_INLINE float __PYX_NAN() { #include #include #include +#include "stdarg.h" #include "htslib/kstring.h" #include "htslib_util.h" #include "htslib/hfile.h" @@ -577,9 +578,10 @@ static CYTHON_INLINE float __PYX_NAN() { #include "htslib/tbx.h" #include "htslib/vcf.h" #include "htslib/vcfutils.h" +#include "htslib/cram.h" #include +#include #include "pythread.h" -#include "pysam_util.h" #ifdef _OPENMP #include #endif /* _OPENMP */ @@ -810,6 +812,7 @@ struct arrayobject; typedef struct arrayobject arrayobject; #endif struct __pyx_obj_5pysam_10libchtslib_HTSFile; +struct __pyx_obj_5pysam_10libchtslib_HFile; struct __pyx_opt_args_5pysam_9libcutils_parse_region; struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array; struct __pyx_opt_args_5pysam_9libcutils_array_to_qualitystring; @@ -930,8 +933,21 @@ struct __pyx_opt_args_5pysam_9libcutils_force_bytes { int __pyx_n; PyObject *encoding; }; +struct __pyx_opt_args_5pysam_10libchtslib_5HFile__open; -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pyx":86 + * return self.fp == NULL + * + * cdef _open(self, name, mode, closefd=True): # <<<<<<<<<<<<<< + * self.name = name + * self.mode = mode + */ +struct __pyx_opt_args_5pysam_10libchtslib_5HFile__open { + int __pyx_n; + PyObject *closefd; +}; + +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -945,6 +961,7 @@ struct __pyx_obj_5pysam_10libchtslib_HTSFile { int64_t start_offset; PyObject *filename; PyObject *mode; + PyObject *threads; PyObject *index_filename; int is_stream; int is_remote; @@ -952,9 +969,25 @@ struct __pyx_obj_5pysam_10libchtslib_HTSFile { }; - -/* "pysam/libchtslib.pyx":57 +/* "pysam/libchtslib.pyx":72 + * ######################################################################## * + * cdef class HFile(object): # <<<<<<<<<<<<<< + * cdef hFILE *fp + * cdef readonly object name, mode + */ +struct __pyx_obj_5pysam_10libchtslib_HFile { + PyObject_HEAD + struct __pyx_vtabstruct_5pysam_10libchtslib_HFile *__pyx_vtab; + hFILE *fp; + PyObject *name; + PyObject *mode; +}; + + + +/* "pysam/libchtslib.pyx":326 + * ######################################################################## * * cdef class HTSFile(object): # <<<<<<<<<<<<<< * """ @@ -966,6 +999,20 @@ struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile { }; static struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile *__pyx_vtabptr_5pysam_10libchtslib_HTSFile; + +/* "pysam/libchtslib.pyx":72 + * ######################################################################## + * + * cdef class HFile(object): # <<<<<<<<<<<<<< + * cdef hFILE *fp + * cdef readonly object name, mode + */ + +struct __pyx_vtabstruct_5pysam_10libchtslib_HFile { + PyObject *(*_open)(struct __pyx_obj_5pysam_10libchtslib_HFile *, PyObject *, PyObject *, struct __pyx_opt_args_5pysam_10libchtslib_5HFile__open *__pyx_optional_args); +}; +static struct __pyx_vtabstruct_5pysam_10libchtslib_HFile *__pyx_vtabptr_5pysam_10libchtslib_HFile; + /* --- Runtime support code (head) --- */ /* Refnanny.proto */ #ifndef CYTHON_REFNANNY @@ -1278,10 +1325,6 @@ static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject #define __Pyx_TraceLine(lineno, nogil, goto_error) if ((1)); else goto_error; #endif -/* RaiseArgTupleInvalid.proto */ -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); - /* RaiseDoubleKeywords.proto */ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); @@ -1290,22 +1333,9 @@ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ const char* function_name); -/* PyObjectSetAttrStr.proto */ -#if CYTHON_USE_TYPE_SLOTS -#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL) -static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value); -#else -#define __Pyx_PyObject_DelAttrStr(o,n) PyObject_DelAttr(o,n) -#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v) -#endif - -/* KeywordStringCheck.proto */ -static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); - -/* WriteUnraisableException.proto */ -static void __Pyx_WriteUnraisable(const char *name, int clineno, - int lineno, const char *filename, - int full_traceback, int nogil); +/* RaiseArgTupleInvalid.proto */ +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /* PyCFunctionFastCall.proto */ #if CYTHON_FAST_PYCCALL @@ -1347,9 +1377,76 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL) #endif +/* WriteUnraisableException.proto */ +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename, + int full_traceback, int nogil); + /* RaiseException.proto */ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); +/* PySequenceContains.proto */ +static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) { + int result = PySequence_Contains(seq, item); + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); +} + +/* ListAppend.proto */ +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { + PyListObject* L = (PyListObject*) list; + Py_ssize_t len = Py_SIZE(list); + if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) { + Py_INCREF(x); + PyList_SET_ITEM(list, len, x); + Py_SIZE(list) = len+1; + return 0; + } + return PyList_Append(list, x); +} +#else +#define __Pyx_PyList_Append(L,x) PyList_Append(L,x) +#endif + +/* StringJoin.proto */ +#if PY_MAJOR_VERSION < 3 +#define __Pyx_PyString_Join __Pyx_PyBytes_Join +#define __Pyx_PyBaseString_Join(s, v) (PyUnicode_CheckExact(s) ? PyUnicode_Join(s, v) : __Pyx_PyBytes_Join(s, v)) +#else +#define __Pyx_PyString_Join PyUnicode_Join +#define __Pyx_PyBaseString_Join PyUnicode_Join +#endif +#if CYTHON_COMPILING_IN_CPYTHON + #if PY_MAJOR_VERSION < 3 + #define __Pyx_PyBytes_Join _PyString_Join + #else + #define __Pyx_PyBytes_Join _PyBytes_Join + #endif +#else +static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values); +#endif + +/* GetModuleGlobalName.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); + +/* ArgTypeTest.proto */ +#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\ + ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\ + __Pyx__ArgTypeTest(obj, type, name, exact)) +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); + +/* PyObjectSetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL) +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value); +#else +#define __Pyx_PyObject_DelAttrStr(o,n) PyObject_DelAttr(o,n) +#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v) +#endif + +/* KeywordStringCheck.proto */ +static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); + /* GetItemInt.proto */ #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ @@ -1406,14 +1503,13 @@ static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject #define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb) #endif -/* GetModuleGlobalName.proto */ -static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); - -/* PySequenceContains.proto */ -static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) { - int result = PySequence_Contains(seq, item); - return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); -} +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace); +#else +#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace)\ + (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2)) +#endif /* PyErrExceptionMatches.proto */ #if CYTHON_FAST_THREAD_STATE @@ -1423,6 +1519,22 @@ static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tsta #define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) #endif +/* IncludeStringH.proto */ +#include + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* StrEquals.proto */ +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals +#else +#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals +#endif + /* PyObject_GenericGetAttrNoDict.proto */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); @@ -1446,6 +1558,9 @@ static int __Pyx_setup_reduce(PyObject* type_obj); /* Import.proto */ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); +/* ImportFrom.proto */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); + /* CalculateMetaclass.proto */ static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases); @@ -1551,6 +1666,9 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_off_t(off_t value); + /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__htsFormatCategory(enum htsFormatCategory value); @@ -1566,6 +1684,12 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__htsCompression(enum htsCom /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value); +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value); + /* ArrayAPI.proto */ #ifndef _ARRAYARRAY_H #define _ARRAYARRAY_H @@ -1687,8 +1811,8 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); /* CIntFromPy.proto */ static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *); -/* CIntToPy.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); +/* CIntFromPy.proto */ +static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *); /* CIntFromPy.proto */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); @@ -1730,6 +1854,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** /* InitStrings.proto */ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); +static PyObject *__pyx_f_5pysam_10libchtslib_5HFile__open(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_mode, struct __pyx_opt_args_5pysam_10libchtslib_5HFile__open *__pyx_optional_args); /* proto*/ static htsFile *__pyx_f_5pysam_10libchtslib_7HTSFile__open_htsfile(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto*/ /* Module declarations from 'libc.stdint' */ @@ -1744,7 +1869,7 @@ static htsFile *__pyx_f_5pysam_10libchtslib_7HTSFile__open_htsfile(struct __pyx_ /* Module declarations from 'posix.unistd' */ -/* Module declarations from 'cython' */ +/* Module declarations from 'libc.errno' */ /* Module declarations from 'cpython.version' */ @@ -1825,6 +1950,8 @@ static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0; /* Module declarations from 'cpython' */ +/* Module declarations from 'cython' */ + /* Module declarations from 'array' */ /* Module declarations from 'cpython.array' */ @@ -1841,6 +1968,7 @@ static PyObject *(*__pyx_f_5pysam_9libcutils_from_string_and_size)(char const *, /* Module declarations from 'pysam.libchtslib' */ static PyTypeObject *__pyx_ptype_5pysam_10libchtslib_HTSFile = 0; +static PyTypeObject *__pyx_ptype_5pysam_10libchtslib_HFile = 0; static int __pyx_v_5pysam_10libchtslib_MAX_POS; static PyObject *__pyx_v_5pysam_10libchtslib_FORMAT_CATEGORIES = 0; static PyObject *__pyx_v_5pysam_10libchtslib_FORMATS = 0; @@ -1853,18 +1981,28 @@ int __pyx_module_is_main_pysam__libchtslib = 0; /* Implementation of 'pysam.libchtslib' */ static PyObject *__pyx_builtin_object; -static PyObject *__pyx_builtin_ValueError; -static PyObject *__pyx_builtin_OSError; static PyObject *__pyx_builtin_IOError; static PyObject *__pyx_builtin_AttributeError; +static PyObject *__pyx_builtin_StopIteration; +static PyObject *__pyx_builtin_NotImplementedError; static PyObject *__pyx_builtin_TypeError; +static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_RuntimeError; +static PyObject *__pyx_builtin_OverflowError; +static PyObject *__pyx_builtin_IndexError; static PyObject *__pyx_builtin_MemoryError; static const char __pyx_k_b[] = "b"; static const char __pyx_k_c[] = "c"; +static const char __pyx_k_r[] = "r"; +static const char __pyx_k_w[] = "w"; +static const char __pyx_k__6[] = ""; static const char __pyx_k_eq[] = "__eq__"; static const char __pyx_k_fd[] = ""; +static const char __pyx_k_io[] = "io"; static const char __pyx_k_ne[] = "__ne__"; static const char __pyx_k_os[] = "os"; +static const char __pyx_k_re[] = "re"; +static const char __pyx_k_tb[] = "tb"; static const char __pyx_k_BAI[] = "BAI"; static const char __pyx_k_BAM[] = "BAM"; static const char __pyx_k_BCF[] = "BCF"; @@ -1874,10 +2012,13 @@ static const char __pyx_k_GZI[] = "GZI"; static const char __pyx_k_SAM[] = "SAM"; static const char __pyx_k_TBI[] = "TBI"; static const char __pyx_k_VCF[] = "VCF"; -static const char __pyx_k__16[] = ""; -static const char __pyx_k__20[] = "-"; +static const char __pyx_k__36[] = "[:-]"; +static const char __pyx_k__38[] = "*"; +static const char __pyx_k__39[] = "."; static const char __pyx_k_all[] = "__all__"; static const char __pyx_k_doc[] = "__doc__"; +static const char __pyx_k_end[] = "end"; +static const char __pyx_k_tid[] = "tid"; static const char __pyx_k_BGZF[] = "BGZF"; static const char __pyx_k_CRAI[] = "CRAI"; static const char __pyx_k_CRAM[] = "CRAM"; @@ -1886,31 +2027,46 @@ static const char __pyx_k_NONE[] = "NONE"; static const char __pyx_k_bool[] = "__bool__"; static const char __pyx_k_call[] = "__call__"; static const char __pyx_k_init[] = "__init__"; +static const char __pyx_k_join[] = "join"; static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_mode[] = "mode"; static const char __pyx_k_name[] = "name"; -static const char __pyx_k_path[] = "path"; +static const char __pyx_k_read[] = "read"; static const char __pyx_k_seek[] = "seek"; static const char __pyx_k_self[] = "self"; +static const char __pyx_k_size[] = "size"; +static const char __pyx_k_stop[] = "stop"; static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_type[] = "type"; +static const char __pyx_k_warn[] = "warn"; static const char __pyx_k_CTrue[] = "CTrue"; +static const char __pyx_k_HFile[] = "HFile"; static const char __pyx_k_INDEX[] = "INDEX"; static const char __pyx_k_close[] = "close"; static const char __pyx_k_other[] = "other"; +static const char __pyx_k_split[] = "split"; +static const char __pyx_k_start[] = "start"; static const char __pyx_k_value[] = "value"; +static const char __pyx_k_write[] = "write"; static const char __pyx_k_CFalse[] = "CFalse"; static const char __pyx_k_CUSTOM[] = "CUSTOM"; -static const char __pyx_k_exists[] = "exists"; +static const char __pyx_k_contig[] = "contig"; static const char __pyx_k_fileno[] = "fileno"; static const char __pyx_k_format[] = "format"; static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_module[] = "__module__"; static const char __pyx_k_name_2[] = "__name__"; static const char __pyx_k_object[] = "object"; +static const char __pyx_k_offset[] = "offset"; static const char __pyx_k_reduce[] = "__reduce__"; +static const char __pyx_k_region[] = "region"; +static const char __pyx_k_whence[] = "whence"; +static const char __pyx_k_HTSFile[] = "HTSFile"; static const char __pyx_k_IOError[] = "IOError"; -static const char __pyx_k_OSError[] = "OSError"; static const char __pyx_k_REGIONS[] = "REGIONS"; static const char __pyx_k_UNKNOWN[] = "UNKNOWN"; +static const char __pyx_k_closedf[] = "closedf"; +static const char __pyx_k_get_tid[] = "get_tid"; static const char __pyx_k_is_open[] = "is_open"; static const char __pyx_k_nonzero[] = "__nonzero__"; static const char __pyx_k_prepare[] = "__prepare__"; @@ -1919,40 +2075,75 @@ static const char __pyx_k_VARIANTS[] = "VARIANTS"; static const char __pyx_k_exc_type[] = "exc_type"; static const char __pyx_k_getstate[] = "__getstate__"; static const char __pyx_k_qualname[] = "__qualname__"; +static const char __pyx_k_readline[] = "readline"; static const char __pyx_k_setstate[] = "__setstate__"; +static const char __pyx_k_warnings[] = "warnings"; static const char __pyx_k_TypeError[] = "TypeError"; static const char __pyx_k_exc_value[] = "exc_value"; static const char __pyx_k_metaclass[] = "__metaclass__"; static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_reference[] = "reference"; static const char __pyx_k_traceback[] = "traceback"; static const char __pyx_k_ALIGNMENTS[] = "ALIGNMENTS"; +static const char __pyx_k_IndexError[] = "IndexError"; static const char __pyx_k_ValueError[] = "ValueError"; +static const char __pyx_k_memoryview[] = "memoryview"; static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; static const char __pyx_k_MemoryError[] = "MemoryError"; static const char __pyx_k_TEXT_FORMAT[] = "TEXT_FORMAT"; +static const char __pyx_k_invalid_tid[] = "invalid tid"; +static const char __pyx_k_RuntimeError[] = "RuntimeError"; +static const char __pyx_k_is_valid_tid[] = "is_valid_tid"; static const char __pyx_k_BINARY_FORMAT[] = "BINARY_FORMAT"; static const char __pyx_k_CallableValue[] = "CallableValue"; +static const char __pyx_k_OverflowError[] = "OverflowError"; +static const char __pyx_k_StopIteration[] = "StopIteration"; static const char __pyx_k_get_verbosity[] = "get_verbosity"; static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; static const char __pyx_k_set_verbosity[] = "set_verbosity"; static const char __pyx_k_AttributeError[] = "AttributeError"; +static const char __pyx_k_format_options[] = "format_options"; static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; +static const char __pyx_k_invalid_contig_s[] = "invalid contig `%s`"; static const char __pyx_k_pysam_libchtslib[] = "pysam.libchtslib"; +static const char __pyx_k_ignore_truncation[] = "ignore_truncation"; static const char __pyx_k_CallableValue___eq[] = "CallableValue.__eq__"; static const char __pyx_k_CallableValue___ne[] = "CallableValue.__ne__"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_Cannot_create_hfile[] = "Cannot create hfile"; +static const char __pyx_k_NotImplementedError[] = "NotImplementedError"; +static const char __pyx_k_stop_out_of_range_i[] = "stop out of range (%i)"; static const char __pyx_k_CallableValue___bool[] = "CallableValue.__bool__"; static const char __pyx_k_CallableValue___call[] = "CallableValue.__call__"; static const char __pyx_k_CallableValue___init[] = "CallableValue.__init__"; +static const char __pyx_k_failed_to_open_HFile[] = "failed to open HFile"; +static const char __pyx_k_failed_to_read_HFile[] = "failed to read HFile"; +static const char __pyx_k_fileno_not_available[] = "fileno not available"; static const char __pyx_k_pysam_libchtslib_pyx[] = "pysam/libchtslib.pyx"; +static const char __pyx_k_seek_failed_on_HFile[] = "seek failed on HFile"; +static const char __pyx_k_start_out_of_range_i[] = "start out of range (%i)"; +static const char __pyx_k_tell_failed_on_HFile[] = "tell failed on HFile"; +static const char __pyx_k_failed_to_close_HFile[] = "failed to close HFile"; +static const char __pyx_k_failed_to_flush_HFile[] = "failed to flush HFile"; +static const char __pyx_k_write_failed_on_HFile[] = "write failed on HFile"; static const char __pyx_k_CallableValue___nonzero[] = "CallableValue.__nonzero__"; +static const char __pyx_k_operation_on_closed_HFile[] = "operation on closed HFile"; static const char __pyx_k_I_O_operation_on_closed_file[] = "I/O operation on closed file"; +static const char __pyx_k_error_checking_for_EOF_marker[] = "error checking for EOF marker"; static const char __pyx_k_seek_not_available_in_streams[] = "seek not available in streams"; static const char __pyx_k_tell_not_available_in_streams[] = "tell not available in streams"; +static const char __pyx_k_An_error_occured_while_applying[] = "An error occured while applying the requested format options"; +static const char __pyx_k_Invalid_format_option_specified[] = "Invalid format option ({}) specified"; +static const char __pyx_k_contig_and_reference_should_not[] = "contig and reference should not both be specified"; +static const char __pyx_k_stop_and_end_should_not_both_be[] = "stop and end should not both be specified"; +static const char __pyx_k_invalid_coordinates_start_i_stop[] = "invalid coordinates: start (%i) > stop (%i)"; static const char __pyx_k_metadata_not_available_on_closed[] = "metadata not available on closed file"; +static const char __pyx_k_no_BGZF_EOF_marker_file_may_be_t[] = "no BGZF EOF marker; file may be truncated"; static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__"; +static const char __pyx_k_seek_not_implemented_in_files_co[] = "seek not implemented in files compressed by method {}"; +static const char __pyx_k_self_fp_cannot_be_converted_to_a[] = "self.fp cannot be converted to a Python object for pickling"; static PyObject *__pyx_n_s_ALIGNMENTS; +static PyObject *__pyx_kp_s_An_error_occured_while_applying; static PyObject *__pyx_n_s_AttributeError; static PyObject *__pyx_n_s_BAI; static PyObject *__pyx_n_s_BAM; @@ -1976,14 +2167,21 @@ static PyObject *__pyx_n_s_CallableValue___nonzero; static PyObject *__pyx_kp_s_Cannot_create_hfile; static PyObject *__pyx_n_s_GZI; static PyObject *__pyx_n_s_GZIP; +static PyObject *__pyx_n_s_HFile; +static PyObject *__pyx_n_s_HTSFile; static PyObject *__pyx_n_s_INDEX; static PyObject *__pyx_n_s_IOError; static PyObject *__pyx_kp_s_I_O_operation_on_closed_file; +static PyObject *__pyx_n_s_IndexError; +static PyObject *__pyx_kp_s_Invalid_format_option_specified; static PyObject *__pyx_n_s_MemoryError; static PyObject *__pyx_n_s_NONE; -static PyObject *__pyx_n_s_OSError; +static PyObject *__pyx_n_s_NotImplementedError; +static PyObject *__pyx_n_s_OverflowError; static PyObject *__pyx_n_s_REGIONS; +static PyObject *__pyx_n_s_RuntimeError; static PyObject *__pyx_n_s_SAM; +static PyObject *__pyx_n_s_StopIteration; static PyObject *__pyx_n_s_TBI; static PyObject *__pyx_n_s_TEXT_FORMAT; static PyObject *__pyx_n_s_TypeError; @@ -1991,8 +2189,10 @@ static PyObject *__pyx_n_s_UNKNOWN; static PyObject *__pyx_n_s_VARIANTS; static PyObject *__pyx_n_s_VCF; static PyObject *__pyx_n_s_ValueError; -static PyObject *__pyx_kp_b__16; -static PyObject *__pyx_kp_b__20; +static PyObject *__pyx_kp_s__36; +static PyObject *__pyx_kp_s__38; +static PyObject *__pyx_kp_s__39; +static PyObject *__pyx_kp_b__6; static PyObject *__pyx_n_s_all; static PyObject *__pyx_n_b_b; static PyObject *__pyx_n_s_bool; @@ -2000,53 +2200,129 @@ static PyObject *__pyx_n_b_c; static PyObject *__pyx_n_s_call; static PyObject *__pyx_n_s_cline_in_traceback; static PyObject *__pyx_n_s_close; +static PyObject *__pyx_n_s_closedf; +static PyObject *__pyx_n_s_contig; +static PyObject *__pyx_kp_s_contig_and_reference_should_not; static PyObject *__pyx_n_s_doc; +static PyObject *__pyx_n_s_end; static PyObject *__pyx_n_s_eq; +static PyObject *__pyx_kp_s_error_checking_for_EOF_marker; static PyObject *__pyx_n_s_exc_type; static PyObject *__pyx_n_s_exc_value; -static PyObject *__pyx_n_s_exists; +static PyObject *__pyx_kp_s_failed_to_close_HFile; +static PyObject *__pyx_kp_s_failed_to_flush_HFile; +static PyObject *__pyx_kp_s_failed_to_open_HFile; +static PyObject *__pyx_kp_s_failed_to_read_HFile; static PyObject *__pyx_kp_s_fd; static PyObject *__pyx_n_s_fileno; +static PyObject *__pyx_kp_s_fileno_not_available; static PyObject *__pyx_n_s_format; +static PyObject *__pyx_n_s_format_options; +static PyObject *__pyx_n_s_get_tid; static PyObject *__pyx_n_s_get_verbosity; static PyObject *__pyx_n_s_getstate; +static PyObject *__pyx_n_s_ignore_truncation; static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_init; +static PyObject *__pyx_kp_s_invalid_contig_s; +static PyObject *__pyx_kp_s_invalid_coordinates_start_i_stop; +static PyObject *__pyx_kp_s_invalid_tid; +static PyObject *__pyx_n_s_io; static PyObject *__pyx_n_s_is_open; +static PyObject *__pyx_n_s_is_valid_tid; +static PyObject *__pyx_n_s_join; static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_memoryview; static PyObject *__pyx_n_s_metaclass; static PyObject *__pyx_kp_s_metadata_not_available_on_closed; +static PyObject *__pyx_n_s_mode; static PyObject *__pyx_n_s_module; static PyObject *__pyx_n_s_name; static PyObject *__pyx_n_s_name_2; static PyObject *__pyx_n_s_ne; +static PyObject *__pyx_kp_s_no_BGZF_EOF_marker_file_may_be_t; static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; static PyObject *__pyx_n_s_nonzero; static PyObject *__pyx_n_s_object; +static PyObject *__pyx_n_s_offset; +static PyObject *__pyx_kp_s_operation_on_closed_HFile; static PyObject *__pyx_n_s_os; static PyObject *__pyx_n_s_other; -static PyObject *__pyx_n_s_path; static PyObject *__pyx_n_s_prepare; static PyObject *__pyx_n_s_pysam_libchtslib; static PyObject *__pyx_kp_s_pysam_libchtslib_pyx; static PyObject *__pyx_n_s_pyx_vtable; static PyObject *__pyx_n_s_qualname; +static PyObject *__pyx_n_s_r; +static PyObject *__pyx_n_s_re; +static PyObject *__pyx_n_s_read; +static PyObject *__pyx_n_s_readline; static PyObject *__pyx_n_s_reduce; static PyObject *__pyx_n_s_reduce_cython; static PyObject *__pyx_n_s_reduce_ex; +static PyObject *__pyx_n_s_reference; +static PyObject *__pyx_n_s_region; static PyObject *__pyx_n_s_replace; static PyObject *__pyx_n_s_seek; +static PyObject *__pyx_kp_s_seek_failed_on_HFile; static PyObject *__pyx_kp_s_seek_not_available_in_streams; +static PyObject *__pyx_kp_s_seek_not_implemented_in_files_co; static PyObject *__pyx_n_s_self; +static PyObject *__pyx_kp_s_self_fp_cannot_be_converted_to_a; static PyObject *__pyx_n_s_set_verbosity; static PyObject *__pyx_n_s_setstate; static PyObject *__pyx_n_s_setstate_cython; +static PyObject *__pyx_n_s_size; +static PyObject *__pyx_n_s_split; +static PyObject *__pyx_n_s_start; +static PyObject *__pyx_kp_s_start_out_of_range_i; +static PyObject *__pyx_n_s_stop; +static PyObject *__pyx_kp_s_stop_and_end_should_not_both_be; +static PyObject *__pyx_kp_s_stop_out_of_range_i; +static PyObject *__pyx_n_s_tb; +static PyObject *__pyx_kp_s_tell_failed_on_HFile; static PyObject *__pyx_kp_s_tell_not_available_in_streams; static PyObject *__pyx_n_s_test; +static PyObject *__pyx_n_s_tid; static PyObject *__pyx_n_s_traceback; +static PyObject *__pyx_n_s_type; static PyObject *__pyx_n_s_value; +static PyObject *__pyx_n_s_w; +static PyObject *__pyx_n_s_warn; +static PyObject *__pyx_n_s_warnings; +static PyObject *__pyx_n_s_whence; +static PyObject *__pyx_n_s_write; +static PyObject *__pyx_kp_s_write_failed_on_HFile; static PyObject *__pyx_pf_5pysam_10libchtslib_set_verbosity(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_verbosity); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_2get_verbosity(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ +static int __pyx_pf_5pysam_10libchtslib_5HFile___init__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_mode, CYTHON_UNUSED PyObject *__pyx_v_closedf); /* proto */ +static void __pyx_pf_5pysam_10libchtslib_5HFile_2__dealloc__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_6closed___get__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_4close(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_6fileno(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_8__enter__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_10__exit__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_type, CYTHON_UNUSED PyObject *__pyx_v_value, CYTHON_UNUSED PyObject *__pyx_v_tb); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_12__iter__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_14__next__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_16flush(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_18isatty(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_20readable(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_22read(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, Py_ssize_t __pyx_v_size); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_24readall(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_26readinto(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, PyObject *__pyx_v_buf); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_28readline(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, Py_ssize_t __pyx_v_size); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_30readlines(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_32seek(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, Py_ssize_t __pyx_v_offset, int __pyx_v_whence); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_34tell(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_36seekable(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_38truncate(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_size); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_40writable(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_42write(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, PyObject *__pyx_v_b); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_44writelines(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, PyObject *__pyx_v_lines); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_4name___get__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_4mode___get__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_46__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_48__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_2__call__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_4__bool__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */ @@ -2054,9 +2330,11 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_6__nonzero__(CYTHO static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_8__eq__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_10__ne__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ static int __pyx_pf_5pysam_10libchtslib_7HTSFile___cinit__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ -static void __pyx_pf_5pysam_10libchtslib_7HTSFile_2__dealloc__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_4__enter__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6__exit__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_2close(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ +static void __pyx_pf_5pysam_10libchtslib_7HTSFile_4__dealloc__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6check_truncation(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, PyObject *__pyx_v_ignore_truncation); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8__enter__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_10__exit__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8category___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6format___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7version___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ @@ -2072,22 +2350,36 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_bam___get__(struct __ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7is_cram___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_vcf___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_bcf___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8reset(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_10seek(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, uint64_t __pyx_v_offset); /* proto */ -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_12tell(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_14_exists(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_12reset(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_14seek(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, uint64_t __pyx_v_offset); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_16tell(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_18add_hts_options(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, PyObject *__pyx_v_format_options); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_20parse_region(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_reference, PyObject *__pyx_v_end); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_22is_valid_tid(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_tid); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_24is_valid_reference_name(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, PyObject *__pyx_v_contig); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_26get_tid(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_contig); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_28get_reference_name(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_tid); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8filename___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_4mode___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7threads___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_14index_filename___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_9is_stream___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_9is_remote___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_20duplicate_filehandle___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_16__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_18__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_30__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_32__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags); /* proto */ static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ static PyObject *__pyx_tp_new_5pysam_10libchtslib_HTSFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_codeobj_; +static PyObject *__pyx_tp_new_5pysam_10libchtslib_HFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_int_0; +static PyObject *__pyx_int_1; +static PyObject *__pyx_int_neg_1; +static PyObject *__pyx_tuple_; +static PyObject *__pyx_tuple__2; +static PyObject *__pyx_tuple__3; +static PyObject *__pyx_tuple__4; +static PyObject *__pyx_tuple__5; static PyObject *__pyx_tuple__7; static PyObject *__pyx_tuple__8; static PyObject *__pyx_tuple__9; @@ -2095,11 +2387,7 @@ static PyObject *__pyx_tuple__10; static PyObject *__pyx_tuple__11; static PyObject *__pyx_tuple__12; static PyObject *__pyx_tuple__13; -static PyObject *__pyx_tuple__14; -static PyObject *__pyx_tuple__15; -static PyObject *__pyx_tuple__17; -static PyObject *__pyx_tuple__18; -static PyObject *__pyx_tuple__19; +static PyObject *__pyx_tuple__20; static PyObject *__pyx_tuple__21; static PyObject *__pyx_tuple__22; static PyObject *__pyx_tuple__23; @@ -2114,14 +2402,31 @@ static PyObject *__pyx_tuple__31; static PyObject *__pyx_tuple__32; static PyObject *__pyx_tuple__33; static PyObject *__pyx_tuple__34; -static PyObject *__pyx_codeobj__2; -static PyObject *__pyx_codeobj__3; -static PyObject *__pyx_codeobj__4; -static PyObject *__pyx_codeobj__5; -static PyObject *__pyx_codeobj__6; +static PyObject *__pyx_tuple__35; +static PyObject *__pyx_tuple__37; +static PyObject *__pyx_tuple__40; +static PyObject *__pyx_tuple__41; +static PyObject *__pyx_tuple__42; +static PyObject *__pyx_tuple__43; +static PyObject *__pyx_tuple__44; +static PyObject *__pyx_tuple__45; +static PyObject *__pyx_tuple__46; +static PyObject *__pyx_tuple__47; +static PyObject *__pyx_tuple__48; +static PyObject *__pyx_tuple__49; +static PyObject *__pyx_tuple__50; +static PyObject *__pyx_tuple__51; +static PyObject *__pyx_tuple__52; +static PyObject *__pyx_tuple__53; +static PyObject *__pyx_codeobj__14; +static PyObject *__pyx_codeobj__15; +static PyObject *__pyx_codeobj__16; +static PyObject *__pyx_codeobj__17; +static PyObject *__pyx_codeobj__18; +static PyObject *__pyx_codeobj__19; /* Late includes */ -/* "pysam/libchtslib.pyx":29 +/* "pysam/libchtslib.pyx":58 * * * cpdef set_verbosity(int verbosity): # <<<<<<<<<<<<<< @@ -2136,9 +2441,9 @@ static PyObject *__pyx_f_5pysam_10libchtslib_set_verbosity(int __pyx_v_verbosity __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("set_verbosity", 0); - __Pyx_TraceCall("set_verbosity", __pyx_f[0], 29, 0, __PYX_ERR(0, 29, __pyx_L1_error)); + __Pyx_TraceCall("set_verbosity", __pyx_f[0], 58, 0, __PYX_ERR(0, 58, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":31 + /* "pysam/libchtslib.pyx":60 * cpdef set_verbosity(int verbosity): * """Set htslib's hts_verbose global variable to the specified value.""" * return hts_set_verbosity(verbosity) # <<<<<<<<<<<<<< @@ -2146,13 +2451,13 @@ static PyObject *__pyx_f_5pysam_10libchtslib_set_verbosity(int __pyx_v_verbosity * cpdef get_verbosity(): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(hts_set_verbosity(__pyx_v_verbosity)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(hts_set_verbosity(__pyx_v_verbosity)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libchtslib.pyx":29 + /* "pysam/libchtslib.pyx":58 * * * cpdef set_verbosity(int verbosity): # <<<<<<<<<<<<<< @@ -2181,7 +2486,7 @@ static PyObject *__pyx_pw_5pysam_10libchtslib_1set_verbosity(PyObject *__pyx_sel __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("set_verbosity (wrapper)", 0); assert(__pyx_arg_verbosity); { - __pyx_v_verbosity = __Pyx_PyInt_As_int(__pyx_arg_verbosity); if (unlikely((__pyx_v_verbosity == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 29, __pyx_L3_error) + __pyx_v_verbosity = __Pyx_PyInt_As_int(__pyx_arg_verbosity); if (unlikely((__pyx_v_verbosity == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 58, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2202,9 +2507,9 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_set_verbosity(CYTHON_UNUSED PyObje __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("set_verbosity", 0); - __Pyx_TraceCall("set_verbosity (wrapper)", __pyx_f[0], 29, 0, __PYX_ERR(0, 29, __pyx_L1_error)); + __Pyx_TraceCall("set_verbosity (wrapper)", __pyx_f[0], 58, 0, __PYX_ERR(0, 58, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_10libchtslib_set_verbosity(__pyx_v_verbosity, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 29, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_10libchtslib_set_verbosity(__pyx_v_verbosity, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2222,7 +2527,7 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_set_verbosity(CYTHON_UNUSED PyObje return __pyx_r; } -/* "pysam/libchtslib.pyx":33 +/* "pysam/libchtslib.pyx":62 * return hts_set_verbosity(verbosity) * * cpdef get_verbosity(): # <<<<<<<<<<<<<< @@ -2237,9 +2542,9 @@ static PyObject *__pyx_f_5pysam_10libchtslib_get_verbosity(CYTHON_UNUSED int __p __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("get_verbosity", 0); - __Pyx_TraceCall("get_verbosity", __pyx_f[0], 33, 0, __PYX_ERR(0, 33, __pyx_L1_error)); + __Pyx_TraceCall("get_verbosity", __pyx_f[0], 62, 0, __PYX_ERR(0, 62, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":35 + /* "pysam/libchtslib.pyx":64 * cpdef get_verbosity(): * """Return the value of htslib's hts_verbose global variable.""" * return hts_get_verbosity() # <<<<<<<<<<<<<< @@ -2247,13 +2552,13 @@ static PyObject *__pyx_f_5pysam_10libchtslib_get_verbosity(CYTHON_UNUSED int __p * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(hts_get_verbosity()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 35, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(hts_get_verbosity()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 64, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libchtslib.pyx":33 + /* "pysam/libchtslib.pyx":62 * return hts_set_verbosity(verbosity) * * cpdef get_verbosity(): # <<<<<<<<<<<<<< @@ -2293,9 +2598,9 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_2get_verbosity(CYTHON_UNUSED PyObj __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("get_verbosity", 0); - __Pyx_TraceCall("get_verbosity (wrapper)", __pyx_f[0], 33, 0, __PYX_ERR(0, 33, __pyx_L1_error)); + __Pyx_TraceCall("get_verbosity (wrapper)", __pyx_f[0], 62, 0, __PYX_ERR(0, 62, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_5pysam_10libchtslib_get_verbosity(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_10libchtslib_get_verbosity(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2313,31 +2618,34 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_2get_verbosity(CYTHON_UNUSED PyObj return __pyx_r; } -/* "pysam/libchtslib.pyx":39 +/* "pysam/libchtslib.pyx":76 + * cdef readonly object name, mode + * + * def __init__(self, name, mode='r', closedf=True): # <<<<<<<<<<<<<< + * self._open(name, mode, closefd=True) * - * class CallableValue(object): - * def __init__(self, value): # <<<<<<<<<<<<<< - * self.value = value - * def __call__(self): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_13CallableValue___init__[] = "CallableValue.__init__(self, value)"; -static PyMethodDef __pyx_mdef_5pysam_10libchtslib_13CallableValue_1__init__ = {"__init__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_13CallableValue_1__init__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_13CallableValue___init__}; -static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_value = 0; - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_10libchtslib_5HFile_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_10libchtslib_5HFile_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_name = 0; + PyObject *__pyx_v_mode = 0; + CYTHON_UNUSED PyObject *__pyx_v_closedf = 0; + int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_value,0}; - PyObject* values[2] = {0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,&__pyx_n_s_mode,&__pyx_n_s_closedf,0}; + PyObject* values[3] = {0,0,0}; + values[1] = ((PyObject *)__pyx_n_s_r); + values[2] = ((PyObject *)Py_True); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -2348,204 +2656,229 @@ static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_1__init__(PyObject kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 39, __pyx_L3_error) + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode); + if (value) { values[1] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_closedf); + if (value) { values[2] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 39, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 76, __pyx_L3_error) } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } } - __pyx_v_self = values[0]; - __pyx_v_value = values[1]; + __pyx_v_name = values[0]; + __pyx_v_mode = values[1]; + __pyx_v_closedf = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 39, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 76, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); - return NULL; + return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_10libchtslib_13CallableValue___init__(__pyx_self, __pyx_v_self, __pyx_v_value); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile___init__(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self), __pyx_v_name, __pyx_v_mode, __pyx_v_closedf); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5pysam_10libchtslib_5HFile___init__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_mode, CYTHON_UNUSED PyObject *__pyx_v_closedf) { + int __pyx_r; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_TraceFrameInit(__pyx_codeobj_) + PyObject *__pyx_t_1 = NULL; + struct __pyx_opt_args_5pysam_10libchtslib_5HFile__open __pyx_t_2; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 39, 0, __PYX_ERR(0, 39, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 76, 0, __PYX_ERR(0, 76, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":40 - * class CallableValue(object): - * def __init__(self, value): - * self.value = value # <<<<<<<<<<<<<< - * def __call__(self): - * return self.value + /* "pysam/libchtslib.pyx":77 + * + * def __init__(self, name, mode='r', closedf=True): + * self._open(name, mode, closefd=True) # <<<<<<<<<<<<<< + * + * def __dealloc__(self): */ - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_value, __pyx_v_value) < 0) __PYX_ERR(0, 40, __pyx_L1_error) + __pyx_t_2.__pyx_n = 1; + __pyx_t_2.closefd = Py_True; + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_10libchtslib_HFile *)__pyx_v_self->__pyx_vtab)->_open(__pyx_v_self, __pyx_v_name, __pyx_v_mode, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libchtslib.pyx":39 + /* "pysam/libchtslib.pyx":76 + * cdef readonly object name, mode + * + * def __init__(self, name, mode='r', closedf=True): # <<<<<<<<<<<<<< + * self._open(name, mode, closefd=True) * - * class CallableValue(object): - * def __init__(self, value): # <<<<<<<<<<<<<< - * self.value = value - * def __call__(self): */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libchtslib.HFile.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libchtslib.pyx":41 - * def __init__(self, value): - * self.value = value - * def __call__(self): # <<<<<<<<<<<<<< - * return self.value - * def __bool__(self): +/* "pysam/libchtslib.pyx":79 + * self._open(name, mode, closefd=True) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * self.close() + * */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_3__call__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_13CallableValue_2__call__[] = "CallableValue.__call__(self)"; -static PyMethodDef __pyx_mdef_5pysam_10libchtslib_13CallableValue_3__call__ = {"__call__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_13CallableValue_3__call__, METH_O, __pyx_doc_5pysam_10libchtslib_13CallableValue_2__call__}; -static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_3__call__(PyObject *__pyx_self, PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static void __pyx_pw_5pysam_10libchtslib_5HFile_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5pysam_10libchtslib_5HFile_3__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_13CallableValue_2__call__(__pyx_self, ((PyObject *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5pysam_10libchtslib_5HFile_2__dealloc__(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); - return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_2__call__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static void __pyx_pf_5pysam_10libchtslib_5HFile_2__dealloc__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_TraceFrameInit(__pyx_codeobj__2) - __Pyx_RefNannySetupContext("__call__", 0); - __Pyx_TraceCall("__call__", __pyx_f[0], 41, 0, __PYX_ERR(0, 41, __pyx_L1_error)); + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__dealloc__", 0); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 79, 0, __PYX_ERR(0, 79, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":42 - * self.value = value - * def __call__(self): - * return self.value # <<<<<<<<<<<<<< - * def __bool__(self): - * return self.value + /* "pysam/libchtslib.pyx":80 + * + * def __dealloc__(self): + * self.close() # <<<<<<<<<<<<<< + * + * @property */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 42, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 80, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error) + } __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "pysam/libchtslib.pyx":41 - * def __init__(self, value): - * self.value = value - * def __call__(self): # <<<<<<<<<<<<<< - * return self.value - * def __bool__(self): - */ + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libchtslib.pyx":79 + * self._open(name, mode, closefd=True) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * self.close() + * + */ /* function exit code */ + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_WriteUnraisable("pysam.libchtslib.HFile.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_TraceReturn(Py_None, 0); __Pyx_RefNannyFinishContext(); - return __pyx_r; } -/* "pysam/libchtslib.pyx":43 - * def __call__(self): - * return self.value - * def __bool__(self): # <<<<<<<<<<<<<< - * return self.value - * def __nonzero__(self): +/* "pysam/libchtslib.pyx":83 + * + * @property + * def closed(self): # <<<<<<<<<<<<<< + * return self.fp == NULL + * */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_5__bool__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_13CallableValue_4__bool__[] = "CallableValue.__bool__(self)"; -static PyMethodDef __pyx_mdef_5pysam_10libchtslib_13CallableValue_5__bool__ = {"__bool__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_13CallableValue_5__bool__, METH_O, __pyx_doc_5pysam_10libchtslib_13CallableValue_4__bool__}; -static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_5__bool__(PyObject *__pyx_self, PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_6closed_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_6closed_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__bool__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_13CallableValue_4__bool__(__pyx_self, ((PyObject *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_6closed___get__(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_4__bool__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_6closed___get__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_TraceFrameInit(__pyx_codeobj__3) - __Pyx_RefNannySetupContext("__bool__", 0); - __Pyx_TraceCall("__bool__", __pyx_f[0], 43, 0, __PYX_ERR(0, 43, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 83, 0, __PYX_ERR(0, 83, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":44 - * return self.value - * def __bool__(self): - * return self.value # <<<<<<<<<<<<<< - * def __nonzero__(self): - * return self.value + /* "pysam/libchtslib.pyx":84 + * @property + * def closed(self): + * return self.fp == NULL # <<<<<<<<<<<<<< + * + * cdef _open(self, name, mode, closefd=True): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->fp == NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 84, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libchtslib.pyx":43 - * def __call__(self): - * return self.value - * def __bool__(self): # <<<<<<<<<<<<<< - * return self.value - * def __nonzero__(self): + /* "pysam/libchtslib.pyx":83 + * + * @property + * def closed(self): # <<<<<<<<<<<<<< + * return self.fp == NULL + * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.closed.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -2554,182 +2887,510 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_4__bool__(CYTHON_U return __pyx_r; } -/* "pysam/libchtslib.pyx":45 - * def __bool__(self): - * return self.value - * def __nonzero__(self): # <<<<<<<<<<<<<< - * return self.value - * def __eq__(self, other): +/* "pysam/libchtslib.pyx":86 + * return self.fp == NULL + * + * cdef _open(self, name, mode, closefd=True): # <<<<<<<<<<<<<< + * self.name = name + * self.mode = mode */ -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_7__nonzero__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_13CallableValue_6__nonzero__[] = "CallableValue.__nonzero__(self)"; -static PyMethodDef __pyx_mdef_5pysam_10libchtslib_13CallableValue_7__nonzero__ = {"__nonzero__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_13CallableValue_7__nonzero__, METH_O, __pyx_doc_5pysam_10libchtslib_13CallableValue_6__nonzero__}; -static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_7__nonzero__(PyObject *__pyx_self, PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__nonzero__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_13CallableValue_6__nonzero__(__pyx_self, ((PyObject *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_6__nonzero__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) { +static PyObject *__pyx_f_5pysam_10libchtslib_5HFile__open(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_mode, struct __pyx_opt_args_5pysam_10libchtslib_5HFile__open *__pyx_optional_args) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_TraceFrameInit(__pyx_codeobj__4) - __Pyx_RefNannySetupContext("__nonzero__", 0); - __Pyx_TraceCall("__nonzero__", __pyx_f[0], 45, 0, __PYX_ERR(0, 45, __pyx_L1_error)); + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + char const *__pyx_t_5; + char const *__pyx_t_6; + char const *__pyx_t_7; + PyObject *__pyx_t_8 = NULL; + __Pyx_RefNannySetupContext("_open", 0); + __Pyx_TraceCall("_open", __pyx_f[0], 86, 0, __PYX_ERR(0, 86, __pyx_L1_error)); + if (__pyx_optional_args) { + } + __Pyx_INCREF(__pyx_v_name); + __Pyx_INCREF(__pyx_v_mode); - /* "pysam/libchtslib.pyx":46 - * return self.value - * def __nonzero__(self): - * return self.value # <<<<<<<<<<<<<< - * def __eq__(self, other): - * return self.value == other + /* "pysam/libchtslib.pyx":87 + * + * cdef _open(self, name, mode, closefd=True): + * self.name = name # <<<<<<<<<<<<<< + * self.mode = mode + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 46, __pyx_L1_error) + __Pyx_INCREF(__pyx_v_name); + __Pyx_GIVEREF(__pyx_v_name); + __Pyx_GOTREF(__pyx_v_self->name); + __Pyx_DECREF(__pyx_v_self->name); + __pyx_v_self->name = __pyx_v_name; + + /* "pysam/libchtslib.pyx":88 + * cdef _open(self, name, mode, closefd=True): + * self.name = name + * self.mode = mode # <<<<<<<<<<<<<< + * + * mode = force_bytes(mode) + */ + __Pyx_INCREF(__pyx_v_mode); + __Pyx_GIVEREF(__pyx_v_mode); + __Pyx_GOTREF(__pyx_v_self->mode); + __Pyx_DECREF(__pyx_v_self->mode); + __pyx_v_self->mode = __pyx_v_mode; + + /* "pysam/libchtslib.pyx":90 + * self.mode = mode + * + * mode = force_bytes(mode) # <<<<<<<<<<<<<< + * + * if isinstance(name, int): + */ + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_mode, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; + __Pyx_DECREF_SET(__pyx_v_mode, __pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - /* "pysam/libchtslib.pyx":45 - * def __bool__(self): - * return self.value - * def __nonzero__(self): # <<<<<<<<<<<<<< - * return self.value - * def __eq__(self, other): + /* "pysam/libchtslib.pyx":92 + * mode = force_bytes(mode) + * + * if isinstance(name, int): # <<<<<<<<<<<<<< + * if self.fp != NULL: + * name = dup(name) + */ + __pyx_t_2 = PyInt_Check(__pyx_v_name); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "pysam/libchtslib.pyx":93 + * + * if isinstance(name, int): + * if self.fp != NULL: # <<<<<<<<<<<<<< + * name = dup(name) + * self.fp = hdopen(name, mode) + */ + __pyx_t_3 = ((__pyx_v_self->fp != NULL) != 0); + if (__pyx_t_3) { + + /* "pysam/libchtslib.pyx":94 + * if isinstance(name, int): + * if self.fp != NULL: + * name = dup(name) # <<<<<<<<<<<<<< + * self.fp = hdopen(name, mode) + * else: + */ + __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_v_name); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 94, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(dup(__pyx_t_4)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 94, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF_SET(__pyx_v_name, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libchtslib.pyx":93 + * + * if isinstance(name, int): + * if self.fp != NULL: # <<<<<<<<<<<<<< + * name = dup(name) + * self.fp = hdopen(name, mode) + */ + } + + /* "pysam/libchtslib.pyx":95 + * if self.fp != NULL: + * name = dup(name) + * self.fp = hdopen(name, mode) # <<<<<<<<<<<<<< + * else: + * name = encode_filename(name) + */ + __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_v_name); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 95, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 95, __pyx_L1_error) + __pyx_v_self->fp = hdopen(__pyx_t_4, __pyx_t_5); + + /* "pysam/libchtslib.pyx":92 + * mode = force_bytes(mode) + * + * if isinstance(name, int): # <<<<<<<<<<<<<< + * if self.fp != NULL: + * name = dup(name) + */ + goto __pyx_L3; + } + + /* "pysam/libchtslib.pyx":97 + * self.fp = hdopen(name, mode) + * else: + * name = encode_filename(name) # <<<<<<<<<<<<<< + * self.fp = hopen(name, mode) + * + */ + /*else*/ { + __pyx_t_1 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF_SET(__pyx_v_name, __pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libchtslib.pyx":98 + * else: + * name = encode_filename(name) + * self.fp = hopen(name, mode) # <<<<<<<<<<<<<< + * + * if not self.fp: + */ + __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_name); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 98, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 98, __pyx_L1_error) + __pyx_v_self->fp = hopen(__pyx_t_6, __pyx_t_7); + } + __pyx_L3:; + + /* "pysam/libchtslib.pyx":100 + * self.fp = hopen(name, mode) + * + * if not self.fp: # <<<<<<<<<<<<<< + * raise IOError(errno, 'failed to open HFile', self.name) + * + */ + __pyx_t_3 = ((!(__pyx_v_self->fp != 0)) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libchtslib.pyx":101 + * + * if not self.fp: + * raise IOError(errno, 'failed to open HFile', self.name) # <<<<<<<<<<<<<< + * + * def close(self): + */ + __pyx_t_1 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 101, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 101, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); + __Pyx_INCREF(__pyx_kp_s_failed_to_open_HFile); + __Pyx_GIVEREF(__pyx_kp_s_failed_to_open_HFile); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_kp_s_failed_to_open_HFile); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_self->name); + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 101, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 101, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":100 + * self.fp = hopen(name, mode) + * + * if not self.fp: # <<<<<<<<<<<<<< + * raise IOError(errno, 'failed to open HFile', self.name) + * + */ + } + + /* "pysam/libchtslib.pyx":86 + * return self.fp == NULL + * + * cdef _open(self, name, mode, closefd=True): # <<<<<<<<<<<<<< + * self.name = name + * self.mode = mode */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__nonzero__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pysam.libchtslib.HFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_name); + __Pyx_XDECREF(__pyx_v_mode); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libchtslib.pyx":47 - * def __nonzero__(self): - * return self.value - * def __eq__(self, other): # <<<<<<<<<<<<<< - * return self.value == other - * def __ne__(self, other): +/* "pysam/libchtslib.pyx":103 + * raise IOError(errno, 'failed to open HFile', self.name) + * + * def close(self): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * return */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_9__eq__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_13CallableValue_8__eq__[] = "CallableValue.__eq__(self, other)"; -static PyMethodDef __pyx_mdef_5pysam_10libchtslib_13CallableValue_9__eq__ = {"__eq__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_13CallableValue_9__eq__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_13CallableValue_8__eq__}; -static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_9__eq__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_other = 0; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_5close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_4close[] = "HFile.close(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_5close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__eq__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0}; - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__eq__", 1, 2, 2, 1); __PYX_ERR(0, 47, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__eq__") < 0)) __PYX_ERR(0, 47, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_self = values[0]; - __pyx_v_other = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__eq__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 47, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__eq__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_10libchtslib_13CallableValue_8__eq__(__pyx_self, __pyx_v_self, __pyx_v_other); + __Pyx_RefNannySetupContext("close (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_4close(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_8__eq__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_4close(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { + hFILE *__pyx_v_fp; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_TraceFrameInit(__pyx_codeobj__5) - __Pyx_RefNannySetupContext("__eq__", 0); - __Pyx_TraceCall("__eq__", __pyx_f[0], 47, 0, __PYX_ERR(0, 47, __pyx_L1_error)); + int __pyx_t_1; + hFILE *__pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("close", 0); + __Pyx_TraceCall("close", __pyx_f[0], 103, 0, __PYX_ERR(0, 103, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":48 - * return self.value - * def __eq__(self, other): - * return self.value == other # <<<<<<<<<<<<<< - * def __ne__(self, other): - * return self.value != other + /* "pysam/libchtslib.pyx":104 + * + * def close(self): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * return + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 48, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_v_other, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 48, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0); + if (__pyx_t_1) { - /* "pysam/libchtslib.pyx":47 - * def __nonzero__(self): - * return self.value - * def __eq__(self, other): # <<<<<<<<<<<<<< - * return self.value == other - * def __ne__(self, other): + /* "pysam/libchtslib.pyx":105 + * def close(self): + * if self.fp == NULL: + * return # <<<<<<<<<<<<<< + * + * cdef hFILE *fp = self.fp + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":104 + * + * def close(self): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * return + * + */ + } + + /* "pysam/libchtslib.pyx":107 + * return + * + * cdef hFILE *fp = self.fp # <<<<<<<<<<<<<< + * self.fp = NULL + * + */ + __pyx_t_2 = __pyx_v_self->fp; + __pyx_v_fp = __pyx_t_2; + + /* "pysam/libchtslib.pyx":108 + * + * cdef hFILE *fp = self.fp + * self.fp = NULL # <<<<<<<<<<<<<< + * + * if hclose(fp) != 0: + */ + __pyx_v_self->fp = NULL; + + /* "pysam/libchtslib.pyx":110 + * self.fp = NULL + * + * if hclose(fp) != 0: # <<<<<<<<<<<<<< + * raise IOError(herrno(self.fp), 'failed to close HFile', self.name) + * + */ + __pyx_t_1 = ((hclose(__pyx_v_fp) != 0) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":111 + * + * if hclose(fp) != 0: + * raise IOError(herrno(self.fp), 'failed to close HFile', self.name) # <<<<<<<<<<<<<< + * + * def fileno(self): + */ + __pyx_t_3 = __Pyx_PyInt_From_int(herrno(__pyx_v_self->fp)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_kp_s_failed_to_close_HFile); + __Pyx_GIVEREF(__pyx_kp_s_failed_to_close_HFile); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_kp_s_failed_to_close_HFile); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_self->name); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 111, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 111, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":110 + * self.fp = NULL + * + * if hclose(fp) != 0: # <<<<<<<<<<<<<< + * raise IOError(herrno(self.fp), 'failed to close HFile', self.name) + * + */ + } + + /* "pysam/libchtslib.pyx":103 + * raise IOError(errno, 'failed to open HFile', self.name) + * + * def close(self): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * return + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libchtslib.HFile.close", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":113 + * raise IOError(herrno(self.fp), 'failed to close HFile', self.name) + * + * def fileno(self): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_7fileno(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_6fileno[] = "HFile.fileno(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_7fileno(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("fileno (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_6fileno(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_6fileno(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + __Pyx_RefNannySetupContext("fileno", 0); + __Pyx_TraceCall("fileno", __pyx_f[0], 113, 0, __PYX_ERR(0, 113, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":114 + * + * def fileno(self): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * if isinstance(self.name, int): + */ + __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":115 + * def fileno(self): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * if isinstance(self.name, int): + * return self.name + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 115, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":114 + * + * def fileno(self): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * if isinstance(self.name, int): + */ + } + + /* "pysam/libchtslib.pyx":116 + * if self.fp == NULL: + * raise IOError('operation on closed HFile') + * if isinstance(self.name, int): # <<<<<<<<<<<<<< + * return self.name + * else: + */ + __pyx_t_2 = __pyx_v_self->name; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = PyInt_Check(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = (__pyx_t_1 != 0); + if (likely(__pyx_t_3)) { + + /* "pysam/libchtslib.pyx":117 + * raise IOError('operation on closed HFile') + * if isinstance(self.name, int): + * return self.name # <<<<<<<<<<<<<< + * else: + * raise AttributeError('fileno not available') + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->name); + __pyx_r = __pyx_v_self->name; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":116 + * if self.fp == NULL: + * raise IOError('operation on closed HFile') + * if isinstance(self.name, int): # <<<<<<<<<<<<<< + * return self.name + * else: + */ + } + + /* "pysam/libchtslib.pyx":119 + * return self.name + * else: + * raise AttributeError('fileno not available') # <<<<<<<<<<<<<< + * + * def __enter__(self): + */ + /*else*/ { + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_AttributeError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 119, __pyx_L1_error) + } + + /* "pysam/libchtslib.pyx":113 + * raise IOError(herrno(self.fp), 'failed to close HFile', self.name) + * + * def fileno(self): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__eq__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.fileno", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -2738,31 +3399,93 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_8__eq__(CYTHON_UNU return __pyx_r; } -/* "pysam/libchtslib.pyx":49 - * def __eq__(self, other): - * return self.value == other - * def __ne__(self, other): # <<<<<<<<<<<<<< - * return self.value != other +/* "pysam/libchtslib.pyx":121 + * raise AttributeError('fileno not available') + * + * def __enter__(self): # <<<<<<<<<<<<<< + * return self * */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_11__ne__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_13CallableValue_10__ne__[] = "CallableValue.__ne__(self, other)"; -static PyMethodDef __pyx_mdef_5pysam_10libchtslib_13CallableValue_11__ne__ = {"__ne__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_13CallableValue_11__ne__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_13CallableValue_10__ne__}; -static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_11__ne__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_self = 0; - PyObject *__pyx_v_other = 0; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_9__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_8__enter__[] = "HFile.__enter__(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_9__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__ne__ (wrapper)", 0); + __Pyx_RefNannySetupContext("__enter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_8__enter__(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_8__enter__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__enter__", 0); + __Pyx_TraceCall("__enter__", __pyx_f[0], 121, 0, __PYX_ERR(0, 121, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":122 + * + * def __enter__(self): + * return self # <<<<<<<<<<<<<< + * + * def __exit__(self, type, value, tb): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":121 + * raise AttributeError('fileno not available') + * + * def __enter__(self): # <<<<<<<<<<<<<< + * return self + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libchtslib.HFile.__enter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":124 + * return self + * + * def __exit__(self, type, value, tb): # <<<<<<<<<<<<<< + * self.close() + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_11__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_10__exit__[] = "HFile.__exit__(self, type, value, tb)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_11__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + CYTHON_UNUSED PyObject *__pyx_v_type = 0; + CYTHON_UNUSED PyObject *__pyx_v_value = 0; + CYTHON_UNUSED PyObject *__pyx_v_tb = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__exit__ (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0}; - PyObject* values[2] = {0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_type,&__pyx_n_s_value,&__pyx_n_s_tb,0}; + PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -2773,81 +3496,105 @@ static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_11__ne__(PyObject kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_type)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--; + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 124, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tb)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__ne__", 1, 2, 2, 1); __PYX_ERR(0, 49, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 124, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__ne__") < 0)) __PYX_ERR(0, 49, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 124, __pyx_L3_error) } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } - __pyx_v_self = values[0]; - __pyx_v_other = values[1]; + __pyx_v_type = values[0]; + __pyx_v_value = values[1]; + __pyx_v_tb = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__ne__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 49, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 124, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__ne__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_10libchtslib_13CallableValue_10__ne__(__pyx_self, __pyx_v_self, __pyx_v_other); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_10__exit__(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self), __pyx_v_type, __pyx_v_value, __pyx_v_tb); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_10__ne__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_10__exit__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_type, CYTHON_UNUSED PyObject *__pyx_v_value, CYTHON_UNUSED PyObject *__pyx_v_tb) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - __Pyx_TraceFrameInit(__pyx_codeobj__6) - __Pyx_RefNannySetupContext("__ne__", 0); - __Pyx_TraceCall("__ne__", __pyx_f[0], 49, 0, __PYX_ERR(0, 49, __pyx_L1_error)); + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__exit__", 0); + __Pyx_TraceCall("__exit__", __pyx_f[0], 124, 0, __PYX_ERR(0, 124, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":50 - * return self.value == other - * def __ne__(self, other): - * return self.value != other # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":125 * + * def __exit__(self, type, value, tb): + * self.close() # <<<<<<<<<<<<<< * + * def __iter__(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 50, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error) + } __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_v_other, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - /* "pysam/libchtslib.pyx":49 - * def __eq__(self, other): - * return self.value == other - * def __ne__(self, other): # <<<<<<<<<<<<<< - * return self.value != other + /* "pysam/libchtslib.pyx":124 + * return self + * + * def __exit__(self, type, value, tb): # <<<<<<<<<<<<<< + * self.close() * */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__ne__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -2856,211 +3603,57 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_10__ne__(CYTHON_UN return __pyx_r; } -/* "pysam/libchtslib.pyx":61 - * Base class for HTS file types - * """ - * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< - * self.htsfile = NULL - * self.duplicate_filehandle = True +/* "pysam/libchtslib.pyx":127 + * self.close() + * + * def __iter__(self): # <<<<<<<<<<<<<< + * return self + * */ /* Python wrapper */ -static int __pyx_pw_5pysam_10libchtslib_7HTSFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5pysam_10libchtslib_7HTSFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - CYTHON_UNUSED PyObject *__pyx_v_args = 0; - CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1; - __Pyx_INCREF(__pyx_args); - __pyx_v_args = __pyx_args; - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile___cinit__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); - - /* function exit code */ - __Pyx_XDECREF(__pyx_v_args); - __Pyx_XDECREF(__pyx_v_kwargs); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_10libchtslib_7HTSFile___cinit__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[0], 61, 0, __PYX_ERR(0, 61, __pyx_L1_error)); - - /* "pysam/libchtslib.pyx":62 - * """ - * def __cinit__(self, *args, **kwargs): - * self.htsfile = NULL # <<<<<<<<<<<<<< - * self.duplicate_filehandle = True - * - */ - __pyx_v_self->htsfile = NULL; - - /* "pysam/libchtslib.pyx":63 - * def __cinit__(self, *args, **kwargs): - * self.htsfile = NULL - * self.duplicate_filehandle = True # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_v_self->duplicate_filehandle = 1; - - /* "pysam/libchtslib.pyx":61 - * Base class for HTS file types - * """ - * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< - * self.htsfile = NULL - * self.duplicate_filehandle = True - */ - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libchtslib.pyx":65 - * self.duplicate_filehandle = True - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * if self.htsfile: - * hts_close(self.htsfile) - */ - -/* Python wrapper */ -static void __pyx_pw_5pysam_10libchtslib_7HTSFile_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5pysam_10libchtslib_7HTSFile_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5pysam_10libchtslib_7HTSFile_2__dealloc__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -static void __pyx_pf_5pysam_10libchtslib_7HTSFile_2__dealloc__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 65, 0, __PYX_ERR(0, 65, __pyx_L1_error)); - - /* "pysam/libchtslib.pyx":66 - * - * def __dealloc__(self): - * if self.htsfile: # <<<<<<<<<<<<<< - * hts_close(self.htsfile) - * self.htsfile = NULL - */ - __pyx_t_1 = (__pyx_v_self->htsfile != 0); - if (__pyx_t_1) { - - /* "pysam/libchtslib.pyx":67 - * def __dealloc__(self): - * if self.htsfile: - * hts_close(self.htsfile) # <<<<<<<<<<<<<< - * self.htsfile = NULL - * - */ - (void)(hts_close(__pyx_v_self->htsfile)); - - /* "pysam/libchtslib.pyx":68 - * if self.htsfile: - * hts_close(self.htsfile) - * self.htsfile = NULL # <<<<<<<<<<<<<< - * - * def __enter__(self): - */ - __pyx_v_self->htsfile = NULL; - - /* "pysam/libchtslib.pyx":66 - * - * def __dealloc__(self): - * if self.htsfile: # <<<<<<<<<<<<<< - * hts_close(self.htsfile) - * self.htsfile = NULL - */ - } - - /* "pysam/libchtslib.pyx":65 - * self.duplicate_filehandle = True - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * if self.htsfile: - * hts_close(self.htsfile) - */ - - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("pysam.libchtslib.HTSFile.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_L0:; - __Pyx_TraceReturn(Py_None, 0); - __Pyx_RefNannyFinishContext(); -} - -/* "pysam/libchtslib.pyx":70 - * self.htsfile = NULL - * - * def __enter__(self): # <<<<<<<<<<<<<< - * return self - * - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_5__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_7HTSFile_4__enter__[] = "HTSFile.__enter__(self)"; -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_5__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_13__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_13__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__enter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_4__enter__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_12__iter__(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_4__enter__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_12__iter__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__enter__", 0); - __Pyx_TraceCall("__enter__", __pyx_f[0], 70, 0, __PYX_ERR(0, 70, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__iter__", 0); + __Pyx_TraceCall("__iter__", __pyx_f[0], 127, 0, __PYX_ERR(0, 127, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":71 + /* "pysam/libchtslib.pyx":128 * - * def __enter__(self): + * def __iter__(self): * return self # <<<<<<<<<<<<<< * - * def __exit__(self, exc_type, exc_value, traceback): + * def __next__(self): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_self)); __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libchtslib.pyx":70 - * self.htsfile = NULL + /* "pysam/libchtslib.pyx":127 + * self.close() * - * def __enter__(self): # <<<<<<<<<<<<<< + * def __iter__(self): # <<<<<<<<<<<<<< * return self * */ /* function exit code */ __pyx_L1_error:; - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.__enter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -3069,105 +3662,48 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_4__enter__(struct __pyx_o return __pyx_r; } -/* "pysam/libchtslib.pyx":73 +/* "pysam/libchtslib.pyx":130 * return self * - * def __exit__(self, exc_type, exc_value, traceback): # <<<<<<<<<<<<<< - * self.close() - * return False + * def __next__(self): # <<<<<<<<<<<<<< + * line = self.readline() + * if not line: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_7HTSFile_6__exit__[] = "HTSFile.__exit__(self, exc_type, exc_value, traceback)"; -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - CYTHON_UNUSED PyObject *__pyx_v_exc_type = 0; - CYTHON_UNUSED PyObject *__pyx_v_exc_value = 0; - CYTHON_UNUSED PyObject *__pyx_v_traceback = 0; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_15__next__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_15__next__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__exit__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_exc_type,&__pyx_n_s_exc_value,&__pyx_n_s_traceback,0}; - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_exc_type)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_exc_value)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 73, __pyx_L3_error) - } - CYTHON_FALLTHROUGH; - case 2: - if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_traceback)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 73, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 73, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - } - __pyx_v_exc_type = values[0]; - __pyx_v_exc_value = values[1]; - __pyx_v_traceback = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 73, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6__exit__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), __pyx_v_exc_type, __pyx_v_exc_value, __pyx_v_traceback); + __Pyx_RefNannySetupContext("__next__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_14__next__(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6__exit__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_14__next__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { + PyObject *__pyx_v_line = NULL; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__exit__", 0); - __Pyx_TraceCall("__exit__", __pyx_f[0], 73, 0, __PYX_ERR(0, 73, __pyx_L1_error)); + int __pyx_t_4; + int __pyx_t_5; + __Pyx_RefNannySetupContext("__next__", 0); + __Pyx_TraceCall("__next__", __pyx_f[0], 130, 0, __PYX_ERR(0, 130, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":74 - * - * def __exit__(self, exc_type, exc_value, traceback): - * self.close() # <<<<<<<<<<<<<< - * return False + /* "pysam/libchtslib.pyx":131 * + * def __next__(self): + * line = self.readline() # <<<<<<<<<<<<<< + * if not line: + * raise StopIteration() */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 74, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_readline); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 131, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -3180,33 +3716,67 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6__exit__(struct __pyx_ob } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 131, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 131, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_line = __pyx_t_1; + __pyx_t_1 = 0; - /* "pysam/libchtslib.pyx":75 - * def __exit__(self, exc_type, exc_value, traceback): - * self.close() - * return False # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":132 + * def __next__(self): + * line = self.readline() + * if not line: # <<<<<<<<<<<<<< + * raise StopIteration() + * return line + */ + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_line); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 132, __pyx_L1_error) + __pyx_t_5 = ((!__pyx_t_4) != 0); + if (unlikely(__pyx_t_5)) { + + /* "pysam/libchtslib.pyx":133 + * line = self.readline() + * if not line: + * raise StopIteration() # <<<<<<<<<<<<<< + * return line * - * @property + */ + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_StopIteration); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 133, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":132 + * def __next__(self): + * line = self.readline() + * if not line: # <<<<<<<<<<<<<< + * raise StopIteration() + * return line + */ + } + + /* "pysam/libchtslib.pyx":134 + * if not line: + * raise StopIteration() + * return line # <<<<<<<<<<<<<< + * + * def flush(self): */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(Py_False); - __pyx_r = Py_False; + __Pyx_INCREF(__pyx_v_line); + __pyx_r = __pyx_v_line; goto __pyx_L0; - /* "pysam/libchtslib.pyx":73 + /* "pysam/libchtslib.pyx":130 * return self * - * def __exit__(self, exc_type, exc_value, traceback): # <<<<<<<<<<<<<< - * self.close() - * return False + * def __next__(self): # <<<<<<<<<<<<<< + * line = self.readline() + * if not line: */ /* function exit code */ @@ -3214,112 +3784,141 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6__exit__(struct __pyx_ob __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_line); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libchtslib.pyx":78 +/* "pysam/libchtslib.pyx":136 + * return line * - * @property - * def category(self): # <<<<<<<<<<<<<< - * """General file format category. One of UNKNOWN, ALIGNMENTS, - * VARIANTS, INDEX, REGIONS""" + * def flush(self): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_8category_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_8category_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_17flush(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_16flush[] = "HFile.flush(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_17flush(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_8category___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("flush (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_16flush(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8category___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_16flush(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 78, 0, __PYX_ERR(0, 78, __pyx_L1_error)); + __Pyx_RefNannySetupContext("flush", 0); + __Pyx_TraceCall("flush", __pyx_f[0], 136, 0, __PYX_ERR(0, 136, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":81 - * """General file format category. One of UNKNOWN, ALIGNMENTS, - * VARIANTS, INDEX, REGIONS""" - * if not self.htsfile: # <<<<<<<<<<<<<< - * raise ValueError('metadata not available on closed file') - * return FORMAT_CATEGORIES[self.htsfile.format.category] + /* "pysam/libchtslib.pyx":137 + * + * def flush(self): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * if hflush(self.fp) != 0: */ - __pyx_t_1 = ((!(__pyx_v_self->htsfile != 0)) != 0); + __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libchtslib.pyx":82 - * VARIANTS, INDEX, REGIONS""" - * if not self.htsfile: - * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< - * return FORMAT_CATEGORIES[self.htsfile.format.category] - * + /* "pysam/libchtslib.pyx":138 + * def flush(self): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * if hflush(self.fp) != 0: + * raise IOError(herrno(self.fp), 'failed to flush HFile', self.name) */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 82, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 138, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 82, __pyx_L1_error) + __PYX_ERR(0, 138, __pyx_L1_error) - /* "pysam/libchtslib.pyx":81 - * """General file format category. One of UNKNOWN, ALIGNMENTS, - * VARIANTS, INDEX, REGIONS""" - * if not self.htsfile: # <<<<<<<<<<<<<< - * raise ValueError('metadata not available on closed file') - * return FORMAT_CATEGORIES[self.htsfile.format.category] + /* "pysam/libchtslib.pyx":137 + * + * def flush(self): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * if hflush(self.fp) != 0: */ } - /* "pysam/libchtslib.pyx":83 - * if not self.htsfile: - * raise ValueError('metadata not available on closed file') - * return FORMAT_CATEGORIES[self.htsfile.format.category] # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":139 + * if self.fp == NULL: + * raise IOError('operation on closed HFile') + * if hflush(self.fp) != 0: # <<<<<<<<<<<<<< + * raise IOError(herrno(self.fp), 'failed to flush HFile', self.name) + * + */ + __pyx_t_1 = ((hflush(__pyx_v_self->fp) != 0) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":140 + * raise IOError('operation on closed HFile') + * if hflush(self.fp) != 0: + * raise IOError(herrno(self.fp), 'failed to flush HFile', self.name) # <<<<<<<<<<<<<< + * + * def isatty(self): + */ + __pyx_t_2 = __Pyx_PyInt_From_int(herrno(__pyx_v_self->fp)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 140, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 140, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_INCREF(__pyx_kp_s_failed_to_flush_HFile); + __Pyx_GIVEREF(__pyx_kp_s_failed_to_flush_HFile); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_s_failed_to_flush_HFile); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_self->name); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 140, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 140, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":139 + * if self.fp == NULL: + * raise IOError('operation on closed HFile') + * if hflush(self.fp) != 0: # <<<<<<<<<<<<<< + * raise IOError(herrno(self.fp), 'failed to flush HFile', self.name) * - * @property */ - __Pyx_XDECREF(__pyx_r); - if (unlikely(__pyx_v_5pysam_10libchtslib_FORMAT_CATEGORIES == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 83, __pyx_L1_error) } - __pyx_t_2 = __Pyx_PyInt_From_enum__htsFormatCategory(__pyx_v_self->htsfile->format.category); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 83, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_5pysam_10libchtslib_FORMAT_CATEGORIES, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 83, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - /* "pysam/libchtslib.pyx":78 + /* "pysam/libchtslib.pyx":136 + * return line * - * @property - * def category(self): # <<<<<<<<<<<<<< - * """General file format category. One of UNKNOWN, ALIGNMENTS, - * VARIANTS, INDEX, REGIONS""" + * def flush(self): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.category.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.flush", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -3328,103 +3927,93 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8category___get__(struct return __pyx_r; } -/* "pysam/libchtslib.pyx":86 - * - * @property - * def format(self): # <<<<<<<<<<<<<< - * """File format. +/* "pysam/libchtslib.pyx":142 + * raise IOError(herrno(self.fp), 'failed to flush HFile', self.name) * + * def isatty(self): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6format_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6format_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_19isatty(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_18isatty[] = "HFile.isatty(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_19isatty(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6format___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("isatty (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_18isatty(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6format___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_18isatty(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 86, 0, __PYX_ERR(0, 86, __pyx_L1_error)); + __Pyx_RefNannySetupContext("isatty", 0); + __Pyx_TraceCall("isatty", __pyx_f[0], 142, 0, __PYX_ERR(0, 142, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":92 - * BAI, CRAM, CRAI, VCF, BCF, CSI, GZI, TBI, BED. - * """ - * if not self.htsfile: # <<<<<<<<<<<<<< - * raise ValueError('metadata not available on closed file') - * return FORMATS[self.htsfile.format.format] + /* "pysam/libchtslib.pyx":143 + * + * def isatty(self): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * return False */ - __pyx_t_1 = ((!(__pyx_v_self->htsfile != 0)) != 0); + __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libchtslib.pyx":93 - * """ - * if not self.htsfile: - * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< - * return FORMATS[self.htsfile.format.format] + /* "pysam/libchtslib.pyx":144 + * def isatty(self): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * return False * */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 144, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 93, __pyx_L1_error) + __PYX_ERR(0, 144, __pyx_L1_error) - /* "pysam/libchtslib.pyx":92 - * BAI, CRAM, CRAI, VCF, BCF, CSI, GZI, TBI, BED. - * """ - * if not self.htsfile: # <<<<<<<<<<<<<< - * raise ValueError('metadata not available on closed file') - * return FORMATS[self.htsfile.format.format] + /* "pysam/libchtslib.pyx":143 + * + * def isatty(self): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * return False */ } - /* "pysam/libchtslib.pyx":94 - * if not self.htsfile: - * raise ValueError('metadata not available on closed file') - * return FORMATS[self.htsfile.format.format] # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":145 + * if self.fp == NULL: + * raise IOError('operation on closed HFile') + * return False # <<<<<<<<<<<<<< * - * @property + * def readable(self): */ __Pyx_XDECREF(__pyx_r); - if (unlikely(__pyx_v_5pysam_10libchtslib_FORMATS == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 94, __pyx_L1_error) - } - __pyx_t_2 = __Pyx_PyInt_From_enum__htsExactFormat(__pyx_v_self->htsfile->format.format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 94, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_5pysam_10libchtslib_FORMATS, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 94, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __Pyx_INCREF(Py_False); + __pyx_r = Py_False; goto __pyx_L0; - /* "pysam/libchtslib.pyx":86 - * - * @property - * def format(self): # <<<<<<<<<<<<<< - * """File format. + /* "pysam/libchtslib.pyx":142 + * raise IOError(herrno(self.fp), 'failed to flush HFile', self.name) * + * def isatty(self): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.format.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.isatty", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -3433,108 +4022,78 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6format___get__(struct __ return __pyx_r; } -/* "pysam/libchtslib.pyx":97 +/* "pysam/libchtslib.pyx":147 + * return False + * + * def readable(self): # <<<<<<<<<<<<<< + * return self.fp != NULL and 'r' in self.mode * - * @property - * def version(self): # <<<<<<<<<<<<<< - * """Tuple of file format version numbers (major, minor)""" - * if not self.htsfile: */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7version_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7version_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_21readable(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_20readable[] = "HFile.readable(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_21readable(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_7version___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("readable (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_20readable(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7version___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_20readable(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 97, 0, __PYX_ERR(0, 97, __pyx_L1_error)); - - /* "pysam/libchtslib.pyx":99 - * def version(self): - * """Tuple of file format version numbers (major, minor)""" - * if not self.htsfile: # <<<<<<<<<<<<<< - * raise ValueError('metadata not available on closed file') - * return self.htsfile.format.version.major, self.htsfile.format.version.minor - */ - __pyx_t_1 = ((!(__pyx_v_self->htsfile != 0)) != 0); - if (unlikely(__pyx_t_1)) { + __Pyx_RefNannySetupContext("readable", 0); + __Pyx_TraceCall("readable", __pyx_f[0], 147, 0, __PYX_ERR(0, 147, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":100 - * """Tuple of file format version numbers (major, minor)""" - * if not self.htsfile: - * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< - * return self.htsfile.format.version.major, self.htsfile.format.version.minor + /* "pysam/libchtslib.pyx":148 * - */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 100, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 100, __pyx_L1_error) - - /* "pysam/libchtslib.pyx":99 - * def version(self): - * """Tuple of file format version numbers (major, minor)""" - * if not self.htsfile: # <<<<<<<<<<<<<< - * raise ValueError('metadata not available on closed file') - * return self.htsfile.format.version.major, self.htsfile.format.version.minor - */ - } - - /* "pysam/libchtslib.pyx":101 - * if not self.htsfile: - * raise ValueError('metadata not available on closed file') - * return self.htsfile.format.version.major, self.htsfile.format.version.minor # <<<<<<<<<<<<<< + * def readable(self): + * return self.fp != NULL and 'r' in self.mode # <<<<<<<<<<<<<< * - * @property + * def read(self, Py_ssize_t size=-1): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyInt_From_short(__pyx_v_self->htsfile->format.version.major); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 101, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_short(__pyx_v_self->htsfile->format.version.minor); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 101, __pyx_L1_error) + __pyx_t_2 = (__pyx_v_self->fp != NULL); + if (__pyx_t_2) { + } else { + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3_bool_binop_done; + } + __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_r, __pyx_v_self->mode, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 101, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); - __pyx_t_2 = 0; + __pyx_t_1 = __pyx_t_3; __pyx_t_3 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; + __pyx_L3_bool_binop_done:; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libchtslib.pyx":97 + /* "pysam/libchtslib.pyx":147 + * return False + * + * def readable(self): # <<<<<<<<<<<<<< + * return self.fp != NULL and 'r' in self.mode * - * @property - * def version(self): # <<<<<<<<<<<<<< - * """Tuple of file format version numbers (major, minor)""" - * if not self.htsfile: */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.version.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.readable", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -3543,352 +4102,518 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7version___get__(struct _ return __pyx_r; } -/* "pysam/libchtslib.pyx":104 - * - * @property - * def compression(self): # <<<<<<<<<<<<<< - * """File compression. +/* "pysam/libchtslib.pyx":150 + * return self.fp != NULL and 'r' in self.mode * + * def read(self, Py_ssize_t size=-1): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_11compression_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_11compression_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_23read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_22read[] = "HFile.read(self, Py_ssize_t size=-1)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_23read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + Py_ssize_t __pyx_v_size; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_11compression___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("read (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_size,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_size); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "read") < 0)) __PYX_ERR(0, 150, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + if (values[0]) { + __pyx_v_size = __Pyx_PyIndex_AsSsize_t(values[0]); if (unlikely((__pyx_v_size == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 150, __pyx_L3_error) + } else { + __pyx_v_size = ((Py_ssize_t)-1L); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("read", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 150, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libchtslib.HFile.read", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_22read(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self), __pyx_v_size); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_11compression___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_22read(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, Py_ssize_t __pyx_v_size) { + PyObject *__pyx_v_parts = 0; + PyObject *__pyx_v_part = 0; + Py_ssize_t __pyx_v_chunk_size; + Py_ssize_t __pyx_v_ret; + Py_ssize_t __pyx_v_bytes_read; + char *__pyx_v_cpart; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations int __pyx_t_1; PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 104, 0, __PYX_ERR(0, 104, __pyx_L1_error)); + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + Py_ssize_t __pyx_t_5; + Py_ssize_t __pyx_t_6; + char *__pyx_t_7; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + __Pyx_RefNannySetupContext("read", 0); + __Pyx_TraceCall("read", __pyx_f[0], 150, 0, __PYX_ERR(0, 150, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":108 + /* "pysam/libchtslib.pyx":151 + * + * def read(self, Py_ssize_t size=-1): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') * - * One of NONE, GZIP, BGZF, CUSTOM.""" - * if not self.htsfile: # <<<<<<<<<<<<<< - * raise ValueError('metadata not available on closed file') - * return COMPRESSION[self.htsfile.format.compression] */ - __pyx_t_1 = ((!(__pyx_v_self->htsfile != 0)) != 0); + __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libchtslib.pyx":109 - * One of NONE, GZIP, BGZF, CUSTOM.""" - * if not self.htsfile: - * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< - * return COMPRESSION[self.htsfile.format.compression] + /* "pysam/libchtslib.pyx":152 + * def read(self, Py_ssize_t size=-1): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< * + * if size == 0: */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 109, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 109, __pyx_L1_error) + __PYX_ERR(0, 152, __pyx_L1_error) - /* "pysam/libchtslib.pyx":108 + /* "pysam/libchtslib.pyx":151 + * + * def read(self, Py_ssize_t size=-1): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') * - * One of NONE, GZIP, BGZF, CUSTOM.""" - * if not self.htsfile: # <<<<<<<<<<<<<< - * raise ValueError('metadata not available on closed file') - * return COMPRESSION[self.htsfile.format.compression] */ } - /* "pysam/libchtslib.pyx":110 - * if not self.htsfile: - * raise ValueError('metadata not available on closed file') - * return COMPRESSION[self.htsfile.format.compression] # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":154 + * raise IOError('operation on closed HFile') + * + * if size == 0: # <<<<<<<<<<<<<< + * return b'' * - * @property */ - __Pyx_XDECREF(__pyx_r); - if (unlikely(__pyx_v_5pysam_10libchtslib_COMPRESSION == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 110, __pyx_L1_error) - } - __pyx_t_2 = __Pyx_PyInt_From_enum__htsCompression(__pyx_v_self->htsfile->format.compression); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 110, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_5pysam_10libchtslib_COMPRESSION, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 110, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __pyx_t_1 = ((__pyx_v_size == 0) != 0); + if (__pyx_t_1) { - /* "pysam/libchtslib.pyx":104 + /* "pysam/libchtslib.pyx":155 * - * @property - * def compression(self): # <<<<<<<<<<<<<< - * """File compression. + * if size == 0: + * return b'' # <<<<<<<<<<<<<< * + * cdef list parts = [] */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_kp_b__6); + __pyx_r = __pyx_kp_b__6; + goto __pyx_L0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.compression.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libchtslib.pyx":154 + * raise IOError('operation on closed HFile') + * + * if size == 0: # <<<<<<<<<<<<<< + * return b'' + * + */ + } -/* "pysam/libchtslib.pyx":113 + /* "pysam/libchtslib.pyx":157 + * return b'' * - * @property - * def description(self): # <<<<<<<<<<<<<< - * """Vaguely human readable description of the file format""" - * if not self.htsfile: + * cdef list parts = [] # <<<<<<<<<<<<<< + * cdef bytes part + * cdef Py_ssize_t chunk_size, ret, bytes_read = 0 */ + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_parts = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_11description_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_11description_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_11description___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + /* "pysam/libchtslib.pyx":159 + * cdef list parts = [] + * cdef bytes part + * cdef Py_ssize_t chunk_size, ret, bytes_read = 0 # <<<<<<<<<<<<<< + * cdef char *cpart + * + */ + __pyx_v_bytes_read = 0; - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libchtslib.pyx":162 + * cdef char *cpart + * + * while size == -1 or bytes_read < size: # <<<<<<<<<<<<<< + * chunk_size = 4096 + * if size != -1: + */ + while (1) { + __pyx_t_3 = ((__pyx_v_size == -1L) != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_3 = ((__pyx_v_bytes_read < __pyx_v_size) != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L7_bool_binop_done:; + if (!__pyx_t_1) break; -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_11description___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { - char *__pyx_v_desc; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_t_4; - char const *__pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 113, 0, __PYX_ERR(0, 113, __pyx_L1_error)); + /* "pysam/libchtslib.pyx":163 + * + * while size == -1 or bytes_read < size: + * chunk_size = 4096 # <<<<<<<<<<<<<< + * if size != -1: + * chunk_size = min(chunk_size, size - bytes_read) + */ + __pyx_v_chunk_size = 0x1000; + + /* "pysam/libchtslib.pyx":164 + * while size == -1 or bytes_read < size: + * chunk_size = 4096 + * if size != -1: # <<<<<<<<<<<<<< + * chunk_size = min(chunk_size, size - bytes_read) + * + */ + __pyx_t_1 = ((__pyx_v_size != -1L) != 0); + if (__pyx_t_1) { - /* "pysam/libchtslib.pyx":115 - * def description(self): - * """Vaguely human readable description of the file format""" - * if not self.htsfile: # <<<<<<<<<<<<<< - * raise ValueError('metadata not available on closed file') - * cdef char *desc = hts_format_description(&self.htsfile.format) + /* "pysam/libchtslib.pyx":165 + * chunk_size = 4096 + * if size != -1: + * chunk_size = min(chunk_size, size - bytes_read) # <<<<<<<<<<<<<< + * + * part = PyBytes_FromStringAndSize(NULL, chunk_size) */ - __pyx_t_1 = ((!(__pyx_v_self->htsfile != 0)) != 0); - if (unlikely(__pyx_t_1)) { + __pyx_t_4 = (__pyx_v_size - __pyx_v_bytes_read); + __pyx_t_5 = __pyx_v_chunk_size; + if (((__pyx_t_4 < __pyx_t_5) != 0)) { + __pyx_t_6 = __pyx_t_4; + } else { + __pyx_t_6 = __pyx_t_5; + } + __pyx_v_chunk_size = __pyx_t_6; - /* "pysam/libchtslib.pyx":116 - * """Vaguely human readable description of the file format""" - * if not self.htsfile: - * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< - * cdef char *desc = hts_format_description(&self.htsfile.format) - * try: + /* "pysam/libchtslib.pyx":164 + * while size == -1 or bytes_read < size: + * chunk_size = 4096 + * if size != -1: # <<<<<<<<<<<<<< + * chunk_size = min(chunk_size, size - bytes_read) + * */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __pyx_L1_error) + } + + /* "pysam/libchtslib.pyx":167 + * chunk_size = min(chunk_size, size - bytes_read) + * + * part = PyBytes_FromStringAndSize(NULL, chunk_size) # <<<<<<<<<<<<<< + * cpart = part + * ret = hread(self.fp, cpart, chunk_size) + */ + __pyx_t_2 = PyBytes_FromStringAndSize(NULL, __pyx_v_chunk_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 167, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 116, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_part, ((PyObject*)__pyx_t_2)); + __pyx_t_2 = 0; - /* "pysam/libchtslib.pyx":115 - * def description(self): - * """Vaguely human readable description of the file format""" - * if not self.htsfile: # <<<<<<<<<<<<<< - * raise ValueError('metadata not available on closed file') - * cdef char *desc = hts_format_description(&self.htsfile.format) + /* "pysam/libchtslib.pyx":168 + * + * part = PyBytes_FromStringAndSize(NULL, chunk_size) + * cpart = part # <<<<<<<<<<<<<< + * ret = hread(self.fp, cpart, chunk_size) + * */ - } + if (unlikely(__pyx_v_part == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 168, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_part); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 168, __pyx_L1_error) + __pyx_v_cpart = ((char *)__pyx_t_7); - /* "pysam/libchtslib.pyx":117 - * if not self.htsfile: - * raise ValueError('metadata not available on closed file') - * cdef char *desc = hts_format_description(&self.htsfile.format) # <<<<<<<<<<<<<< - * try: - * return charptr_to_str(desc) + /* "pysam/libchtslib.pyx":169 + * part = PyBytes_FromStringAndSize(NULL, chunk_size) + * cpart = part + * ret = hread(self.fp, cpart, chunk_size) # <<<<<<<<<<<<<< + * + * if ret < 0: */ - __pyx_v_desc = hts_format_description((&__pyx_v_self->htsfile->format)); + __pyx_v_ret = hread(__pyx_v_self->fp, ((void *)__pyx_v_cpart), __pyx_v_chunk_size); - /* "pysam/libchtslib.pyx":118 - * raise ValueError('metadata not available on closed file') - * cdef char *desc = hts_format_description(&self.htsfile.format) - * try: # <<<<<<<<<<<<<< - * return charptr_to_str(desc) - * finally: + /* "pysam/libchtslib.pyx":171 + * ret = hread(self.fp, cpart, chunk_size) + * + * if ret < 0: # <<<<<<<<<<<<<< + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * elif not ret: */ - /*try:*/ { + __pyx_t_1 = ((__pyx_v_ret < 0) != 0); + if (__pyx_t_1) { - /* "pysam/libchtslib.pyx":119 - * cdef char *desc = hts_format_description(&self.htsfile.format) - * try: - * return charptr_to_str(desc) # <<<<<<<<<<<<<< - * finally: - * free(desc) + /* "pysam/libchtslib.pyx":172 + * + * if ret < 0: + * IOError(herrno(self.fp), 'failed to read HFile', self.name) # <<<<<<<<<<<<<< + * elif not ret: + * break */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_desc, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 119, __pyx_L5_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L4_return; - } + __pyx_t_2 = __Pyx_PyInt_From_int(herrno(__pyx_v_self->fp)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); + __Pyx_INCREF(__pyx_kp_s_failed_to_read_HFile); + __Pyx_GIVEREF(__pyx_kp_s_failed_to_read_HFile); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_kp_s_failed_to_read_HFile); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_self->name); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libchtslib.pyx":121 - * return charptr_to_str(desc) - * finally: - * free(desc) # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":171 + * ret = hread(self.fp, cpart, chunk_size) * - * @property + * if ret < 0: # <<<<<<<<<<<<<< + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * elif not ret: */ - /*finally:*/ { - __pyx_L5_error:; - /*exception exit:*/{ - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __pyx_t_6 = 0; __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); - if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_8); - __Pyx_XGOTREF(__pyx_t_9); - __Pyx_XGOTREF(__pyx_t_10); - __Pyx_XGOTREF(__pyx_t_11); - __pyx_t_3 = __pyx_lineno; __pyx_t_4 = __pyx_clineno; __pyx_t_5 = __pyx_filename; - { - free(__pyx_v_desc); - } - if (PY_MAJOR_VERSION >= 3) { - __Pyx_XGIVEREF(__pyx_t_9); - __Pyx_XGIVEREF(__pyx_t_10); - __Pyx_XGIVEREF(__pyx_t_11); - __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); - } - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_XGIVEREF(__pyx_t_8); - __Pyx_ErrRestore(__pyx_t_6, __pyx_t_7, __pyx_t_8); - __pyx_t_6 = 0; __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; - __pyx_lineno = __pyx_t_3; __pyx_clineno = __pyx_t_4; __pyx_filename = __pyx_t_5; - goto __pyx_L1_error; + goto __pyx_L10; } - __pyx_L4_return: { - __pyx_t_11 = __pyx_r; - __pyx_r = 0; - free(__pyx_v_desc); - __pyx_r = __pyx_t_11; - __pyx_t_11 = 0; - goto __pyx_L0; + + /* "pysam/libchtslib.pyx":173 + * if ret < 0: + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * elif not ret: # <<<<<<<<<<<<<< + * break + * + */ + __pyx_t_1 = ((!(__pyx_v_ret != 0)) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":174 + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * elif not ret: + * break # <<<<<<<<<<<<<< + * + * bytes_read += ret + */ + goto __pyx_L6_break; + + /* "pysam/libchtslib.pyx":173 + * if ret < 0: + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * elif not ret: # <<<<<<<<<<<<<< + * break + * + */ + } + __pyx_L10:; + + /* "pysam/libchtslib.pyx":176 + * break + * + * bytes_read += ret # <<<<<<<<<<<<<< + * + * if ret < chunk_size: + */ + __pyx_v_bytes_read = (__pyx_v_bytes_read + __pyx_v_ret); + + /* "pysam/libchtslib.pyx":178 + * bytes_read += ret + * + * if ret < chunk_size: # <<<<<<<<<<<<<< + * part = cpart[:ret] + * + */ + __pyx_t_1 = ((__pyx_v_ret < __pyx_v_chunk_size) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":179 + * + * if ret < chunk_size: + * part = cpart[:ret] # <<<<<<<<<<<<<< + * + * parts.append(part) + */ + __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_cpart + 0, __pyx_v_ret - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF_SET(__pyx_v_part, ((PyObject*)__pyx_t_2)); + __pyx_t_2 = 0; + + /* "pysam/libchtslib.pyx":178 + * bytes_read += ret + * + * if ret < chunk_size: # <<<<<<<<<<<<<< + * part = cpart[:ret] + * + */ } + + /* "pysam/libchtslib.pyx":181 + * part = cpart[:ret] + * + * parts.append(part) # <<<<<<<<<<<<<< + * + * return b''.join(parts) + */ + __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_parts, __pyx_v_part); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 181, __pyx_L1_error) } + __pyx_L6_break:; - /* "pysam/libchtslib.pyx":113 + /* "pysam/libchtslib.pyx":183 + * parts.append(part) * - * @property - * def description(self): # <<<<<<<<<<<<<< - * """Vaguely human readable description of the file format""" - * if not self.htsfile: + * return b''.join(parts) # <<<<<<<<<<<<<< + * + * def readall(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyBytes_Join(__pyx_kp_b__6, __pyx_v_parts); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 183, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":150 + * return self.fp != NULL and 'r' in self.mode + * + * def read(self, Py_ssize_t size=-1): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.description.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pysam.libchtslib.HFile.read", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_parts); + __Pyx_XDECREF(__pyx_v_part); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libchtslib.pyx":124 +/* "pysam/libchtslib.pyx":185 + * return b''.join(parts) + * + * def readall(self): # <<<<<<<<<<<<<< + * return self.read() * - * @property - * def is_open(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is open and in a valid state.""" - * return CTrue if self.htsfile != NULL else CFalse */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7is_open_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7is_open_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_25readall(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_24readall[] = "HFile.readall(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_25readall(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_7is_open___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("readall (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_24readall(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7is_open___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_24readall(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 124, 0, __PYX_ERR(0, 124, __pyx_L1_error)); + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("readall", 0); + __Pyx_TraceCall("readall", __pyx_f[0], 185, 0, __PYX_ERR(0, 185, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":126 - * def is_open(self): - * """return True if HTSFile is open and in a valid state.""" - * return CTrue if self.htsfile != NULL else CFalse # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":186 * - * @property + * def readall(self): + * return self.read() # <<<<<<<<<<<<<< + * + * def readinto(self, buf): */ __Pyx_XDECREF(__pyx_r); - if (((__pyx_v_self->htsfile != NULL) != 0)) { - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_CTrue); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __pyx_t_2; - __pyx_t_2 = 0; - } else { - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_CFalse); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __pyx_t_2; - __pyx_t_2 = 0; - } - __pyx_r = __pyx_t_1; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_read); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 186, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 186, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 186, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libchtslib.pyx":124 + /* "pysam/libchtslib.pyx":185 + * return b''.join(parts) + * + * def readall(self): # <<<<<<<<<<<<<< + * return self.read() * - * @property - * def is_open(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is open and in a valid state.""" - * return CTrue if self.htsfile != NULL else CFalse */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_open.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HFile.readall", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -3897,361 +4622,749 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7is_open___get__(struct _ return __pyx_r; } -/* "pysam/libchtslib.pyx":129 +/* "pysam/libchtslib.pyx":188 + * return self.read() * - * @property - * def is_closed(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is closed.""" - * return self.htsfile == NULL + * def readinto(self, buf): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_9is_closed_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_9is_closed_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_27readinto(PyObject *__pyx_v_self, PyObject *__pyx_v_buf); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_26readinto[] = "HFile.readinto(self, buf)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_27readinto(PyObject *__pyx_v_self, PyObject *__pyx_v_buf) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_9is_closed___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("readinto (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_26readinto(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self), ((PyObject *)__pyx_v_buf)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_9is_closed___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_26readinto(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, PyObject *__pyx_v_buf) { + Py_ssize_t __pyx_v_size; + PyObject *__pyx_v_mv = NULL; + Py_ssize_t __pyx_v_ret; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 129, 0, __PYX_ERR(0, 129, __pyx_L1_error)); + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("readinto", 0); + __Pyx_TraceCall("readinto", __pyx_f[0], 188, 0, __PYX_ERR(0, 188, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":131 - * def is_closed(self): - * """return True if HTSFile is closed.""" - * return self.htsfile == NULL # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":189 + * + * def readinto(self, buf): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') * - * @property */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->htsfile == NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 131, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libchtslib.pyx":129 + /* "pysam/libchtslib.pyx":190 + * def readinto(self, buf): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< * - * @property - * def is_closed(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is closed.""" - * return self.htsfile == NULL + * size = len(buf) */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 190, __pyx_L1_error) - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_closed.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libchtslib.pyx":189 + * + * def readinto(self, buf): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * + */ + } -/* "pysam/libchtslib.pyx":134 + /* "pysam/libchtslib.pyx":192 + * raise IOError('operation on closed HFile') * - * @property - * def closed(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is closed.""" - * return self.htsfile == NULL + * size = len(buf) # <<<<<<<<<<<<<< + * + * if size == 0: */ + __pyx_t_3 = PyObject_Length(__pyx_v_buf); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 192, __pyx_L1_error) + __pyx_v_size = __pyx_t_3; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6closed_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6closed_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6closed___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + /* "pysam/libchtslib.pyx":194 + * size = len(buf) + * + * if size == 0: # <<<<<<<<<<<<<< + * return size + * + */ + __pyx_t_1 = ((__pyx_v_size == 0) != 0); + if (__pyx_t_1) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libchtslib.pyx":195 + * + * if size == 0: + * return size # <<<<<<<<<<<<<< + * + * mv = memoryview(buf) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 195, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6closed___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 134, 0, __PYX_ERR(0, 134, __pyx_L1_error)); + /* "pysam/libchtslib.pyx":194 + * size = len(buf) + * + * if size == 0: # <<<<<<<<<<<<<< + * return size + * + */ + } - /* "pysam/libchtslib.pyx":136 - * def closed(self): - * """return True if HTSFile is closed.""" - * return self.htsfile == NULL # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":197 + * return size * - * @property + * mv = memoryview(buf) # <<<<<<<<<<<<<< + * ret = hread(self.fp, mv, size) + * + */ + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_memoryview); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 197, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_buf); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 197, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_mv = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pysam/libchtslib.pyx":198 + * + * mv = memoryview(buf) + * ret = hread(self.fp, mv, size) # <<<<<<<<<<<<<< + * + * if ret < 0: + */ + __pyx_v_ret = hread(__pyx_v_self->fp, ((void *)__pyx_v_mv), __pyx_v_size); + + /* "pysam/libchtslib.pyx":200 + * ret = hread(self.fp, mv, size) + * + * if ret < 0: # <<<<<<<<<<<<<< + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * + */ + __pyx_t_1 = ((__pyx_v_ret < 0) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":201 + * + * if ret < 0: + * IOError(herrno(self.fp), 'failed to read HFile', self.name) # <<<<<<<<<<<<<< + * + * return ret + */ + __pyx_t_4 = __Pyx_PyInt_From_int(herrno(__pyx_v_self->fp)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); + __Pyx_INCREF(__pyx_kp_s_failed_to_read_HFile); + __Pyx_GIVEREF(__pyx_kp_s_failed_to_read_HFile); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_kp_s_failed_to_read_HFile); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_self->name); + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libchtslib.pyx":200 + * ret = hread(self.fp, mv, size) + * + * if ret < 0: # <<<<<<<<<<<<<< + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * + */ + } + + /* "pysam/libchtslib.pyx":203 + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * + * return ret # <<<<<<<<<<<<<< + * + * def readline(self, Py_ssize_t size=-1): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->htsfile == NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_ret); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 203, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; goto __pyx_L0; - /* "pysam/libchtslib.pyx":134 + /* "pysam/libchtslib.pyx":188 + * return self.read() * - * @property - * def closed(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is closed.""" - * return self.htsfile == NULL + * def readinto(self, buf): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.closed.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libchtslib.HFile.readinto", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_mv); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libchtslib.pyx":139 +/* "pysam/libchtslib.pyx":205 + * return ret * - * @property - * def is_write(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is open for writing""" - * return self.htsfile != NULL and self.htsfile.is_write != 0 + * def readline(self, Py_ssize_t size=-1): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_8is_write_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_8is_write_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_29readline(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_28readline[] = "HFile.readline(self, Py_ssize_t size=-1)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_29readline(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + Py_ssize_t __pyx_v_size; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_8is_write___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("readline (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_size,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_size); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "readline") < 0)) __PYX_ERR(0, 205, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + if (values[0]) { + __pyx_v_size = __Pyx_PyIndex_AsSsize_t(values[0]); if (unlikely((__pyx_v_size == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 205, __pyx_L3_error) + } else { + __pyx_v_size = ((Py_ssize_t)-1L); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("readline", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 205, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libchtslib.HFile.readline", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_28readline(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self), __pyx_v_size); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8is_write___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_28readline(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, Py_ssize_t __pyx_v_size) { + PyObject *__pyx_v_parts = 0; + PyObject *__pyx_v_part = 0; + Py_ssize_t __pyx_v_chunk_size; + Py_ssize_t __pyx_v_ret; + Py_ssize_t __pyx_v_bytes_read; + char *__pyx_v_cpart; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 139, 0, __PYX_ERR(0, 139, __pyx_L1_error)); + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + Py_ssize_t __pyx_t_5; + Py_ssize_t __pyx_t_6; + char *__pyx_t_7; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + __Pyx_RefNannySetupContext("readline", 0); + __Pyx_TraceCall("readline", __pyx_f[0], 205, 0, __PYX_ERR(0, 205, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":141 - * def is_write(self): - * """return True if HTSFile is open for writing""" - * return self.htsfile != NULL and self.htsfile.is_write != 0 # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":206 + * + * def readline(self, Py_ssize_t size=-1): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') * - * @property */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = (__pyx_v_self->htsfile != NULL); - if (__pyx_t_2) { - } else { - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3_bool_binop_done; - } - __pyx_t_2 = (__pyx_v_self->htsfile->is_write != 0); - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_L3_bool_binop_done:; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libchtslib.pyx":139 + /* "pysam/libchtslib.pyx":207 + * def readline(self, Py_ssize_t size=-1): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< * - * @property - * def is_write(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is open for writing""" - * return self.htsfile != NULL and self.htsfile.is_write != 0 + * if size == 0: */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 207, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 207, __pyx_L1_error) - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_write.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libchtslib.pyx":206 + * + * def readline(self, Py_ssize_t size=-1): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * + */ + } -/* "pysam/libchtslib.pyx":144 + /* "pysam/libchtslib.pyx":209 + * raise IOError('operation on closed HFile') + * + * if size == 0: # <<<<<<<<<<<<<< + * return b'' * - * @property - * def is_read(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is open for reading""" - * return self.htsfile != NULL and self.htsfile.is_write == 0 */ + __pyx_t_1 = ((__pyx_v_size == 0) != 0); + if (__pyx_t_1) { -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7is_read_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7is_read_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_7is_read___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + /* "pysam/libchtslib.pyx":210 + * + * if size == 0: + * return b'' # <<<<<<<<<<<<<< + * + * cdef list parts = [] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_kp_b__6); + __pyx_r = __pyx_kp_b__6; + goto __pyx_L0; - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libchtslib.pyx":209 + * raise IOError('operation on closed HFile') + * + * if size == 0: # <<<<<<<<<<<<<< + * return b'' + * + */ + } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7is_read___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 144, 0, __PYX_ERR(0, 144, __pyx_L1_error)); + /* "pysam/libchtslib.pyx":212 + * return b'' + * + * cdef list parts = [] # <<<<<<<<<<<<<< + * cdef bytes part + * cdef Py_ssize_t chunk_size, ret, bytes_read = 0 + */ + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 212, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_parts = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libchtslib.pyx":146 - * def is_read(self): - * """return True if HTSFile is open for reading""" - * return self.htsfile != NULL and self.htsfile.is_write == 0 # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":214 + * cdef list parts = [] + * cdef bytes part + * cdef Py_ssize_t chunk_size, ret, bytes_read = 0 # <<<<<<<<<<<<<< + * cdef char *cpart * - * @property */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = (__pyx_v_self->htsfile != NULL); - if (__pyx_t_2) { - } else { - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 146, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + __pyx_v_bytes_read = 0; + + /* "pysam/libchtslib.pyx":217 + * cdef char *cpart + * + * while size == -1 or bytes_read < size: # <<<<<<<<<<<<<< + * chunk_size = 4096 + * if size != -1: + */ + while (1) { + __pyx_t_3 = ((__pyx_v_size == -1L) != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_3 = ((__pyx_v_bytes_read < __pyx_v_size) != 0); __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3_bool_binop_done; + __pyx_L7_bool_binop_done:; + if (!__pyx_t_1) break; + + /* "pysam/libchtslib.pyx":218 + * + * while size == -1 or bytes_read < size: + * chunk_size = 4096 # <<<<<<<<<<<<<< + * if size != -1: + * chunk_size = min(chunk_size, size - bytes_read) + */ + __pyx_v_chunk_size = 0x1000; + + /* "pysam/libchtslib.pyx":219 + * while size == -1 or bytes_read < size: + * chunk_size = 4096 + * if size != -1: # <<<<<<<<<<<<<< + * chunk_size = min(chunk_size, size - bytes_read) + * + */ + __pyx_t_1 = ((__pyx_v_size != -1L) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":220 + * chunk_size = 4096 + * if size != -1: + * chunk_size = min(chunk_size, size - bytes_read) # <<<<<<<<<<<<<< + * + * part = PyBytes_FromStringAndSize(NULL, chunk_size) + */ + __pyx_t_4 = (__pyx_v_size - __pyx_v_bytes_read); + __pyx_t_5 = __pyx_v_chunk_size; + if (((__pyx_t_4 < __pyx_t_5) != 0)) { + __pyx_t_6 = __pyx_t_4; + } else { + __pyx_t_6 = __pyx_t_5; + } + __pyx_v_chunk_size = __pyx_t_6; + + /* "pysam/libchtslib.pyx":219 + * while size == -1 or bytes_read < size: + * chunk_size = 4096 + * if size != -1: # <<<<<<<<<<<<<< + * chunk_size = min(chunk_size, size - bytes_read) + * + */ + } + + /* "pysam/libchtslib.pyx":222 + * chunk_size = min(chunk_size, size - bytes_read) + * + * part = PyBytes_FromStringAndSize(NULL, chunk_size) # <<<<<<<<<<<<<< + * cpart = part + * + */ + __pyx_t_2 = PyBytes_FromStringAndSize(NULL, __pyx_v_chunk_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 222, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF_SET(__pyx_v_part, ((PyObject*)__pyx_t_2)); + __pyx_t_2 = 0; + + /* "pysam/libchtslib.pyx":223 + * + * part = PyBytes_FromStringAndSize(NULL, chunk_size) + * cpart = part # <<<<<<<<<<<<<< + * + * # Python bytes objects allocate an extra byte for a null terminator + */ + if (unlikely(__pyx_v_part == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 223, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_part); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 223, __pyx_L1_error) + __pyx_v_cpart = ((char *)__pyx_t_7); + + /* "pysam/libchtslib.pyx":226 + * + * # Python bytes objects allocate an extra byte for a null terminator + * ret = hgetln(cpart, chunk_size+1, self.fp) # <<<<<<<<<<<<<< + * + * if ret < 0: + */ + __pyx_v_ret = hgetln(__pyx_v_cpart, (__pyx_v_chunk_size + 1), __pyx_v_self->fp); + + /* "pysam/libchtslib.pyx":228 + * ret = hgetln(cpart, chunk_size+1, self.fp) + * + * if ret < 0: # <<<<<<<<<<<<<< + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * elif not ret: + */ + __pyx_t_1 = ((__pyx_v_ret < 0) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":229 + * + * if ret < 0: + * IOError(herrno(self.fp), 'failed to read HFile', self.name) # <<<<<<<<<<<<<< + * elif not ret: + * break + */ + __pyx_t_2 = __Pyx_PyInt_From_int(herrno(__pyx_v_self->fp)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 229, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 229, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); + __Pyx_INCREF(__pyx_kp_s_failed_to_read_HFile); + __Pyx_GIVEREF(__pyx_kp_s_failed_to_read_HFile); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_kp_s_failed_to_read_HFile); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_self->name); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 229, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libchtslib.pyx":228 + * ret = hgetln(cpart, chunk_size+1, self.fp) + * + * if ret < 0: # <<<<<<<<<<<<<< + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * elif not ret: + */ + goto __pyx_L10; + } + + /* "pysam/libchtslib.pyx":230 + * if ret < 0: + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * elif not ret: # <<<<<<<<<<<<<< + * break + * + */ + __pyx_t_1 = ((!(__pyx_v_ret != 0)) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":231 + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * elif not ret: + * break # <<<<<<<<<<<<<< + * + * bytes_read += ret + */ + goto __pyx_L6_break; + + /* "pysam/libchtslib.pyx":230 + * if ret < 0: + * IOError(herrno(self.fp), 'failed to read HFile', self.name) + * elif not ret: # <<<<<<<<<<<<<< + * break + * + */ + } + __pyx_L10:; + + /* "pysam/libchtslib.pyx":233 + * break + * + * bytes_read += ret # <<<<<<<<<<<<<< + * + * if ret < chunk_size: + */ + __pyx_v_bytes_read = (__pyx_v_bytes_read + __pyx_v_ret); + + /* "pysam/libchtslib.pyx":235 + * bytes_read += ret + * + * if ret < chunk_size: # <<<<<<<<<<<<<< + * part = cpart[:ret] + * cpart = part + */ + __pyx_t_1 = ((__pyx_v_ret < __pyx_v_chunk_size) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":236 + * + * if ret < chunk_size: + * part = cpart[:ret] # <<<<<<<<<<<<<< + * cpart = part + * + */ + __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_cpart + 0, __pyx_v_ret - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 236, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF_SET(__pyx_v_part, ((PyObject*)__pyx_t_2)); + __pyx_t_2 = 0; + + /* "pysam/libchtslib.pyx":237 + * if ret < chunk_size: + * part = cpart[:ret] + * cpart = part # <<<<<<<<<<<<<< + * + * parts.append(part) + */ + __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_part); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 237, __pyx_L1_error) + __pyx_v_cpart = ((char *)__pyx_t_7); + + /* "pysam/libchtslib.pyx":235 + * bytes_read += ret + * + * if ret < chunk_size: # <<<<<<<<<<<<<< + * part = cpart[:ret] + * cpart = part + */ + } + + /* "pysam/libchtslib.pyx":239 + * cpart = part + * + * parts.append(part) # <<<<<<<<<<<<<< + * + * if cpart[ret-1] == b'\n': + */ + __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_parts, __pyx_v_part); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 239, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":241 + * parts.append(part) + * + * if cpart[ret-1] == b'\n': # <<<<<<<<<<<<<< + * break + * + */ + __pyx_t_1 = (((__pyx_v_cpart[(__pyx_v_ret - 1)]) == '\n') != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":242 + * + * if cpart[ret-1] == b'\n': + * break # <<<<<<<<<<<<<< + * + * return b''.join(parts) + */ + goto __pyx_L6_break; + + /* "pysam/libchtslib.pyx":241 + * parts.append(part) + * + * if cpart[ret-1] == b'\n': # <<<<<<<<<<<<<< + * break + * + */ + } } - __pyx_t_2 = (__pyx_v_self->htsfile->is_write == 0); - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 146, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_L3_bool_binop_done:; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_L6_break:; + + /* "pysam/libchtslib.pyx":244 + * break + * + * return b''.join(parts) # <<<<<<<<<<<<<< + * + * def readlines(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyBytes_Join(__pyx_kp_b__6, __pyx_v_parts); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 244, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libchtslib.pyx":144 + /* "pysam/libchtslib.pyx":205 + * return ret * - * @property - * def is_read(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is open for reading""" - * return self.htsfile != NULL and self.htsfile.is_write == 0 + * def readline(self, Py_ssize_t size=-1): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_read.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pysam.libchtslib.HFile.readline", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_parts); + __Pyx_XDECREF(__pyx_v_part); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libchtslib.pyx":149 +/* "pysam/libchtslib.pyx":246 + * return b''.join(parts) + * + * def readlines(self): # <<<<<<<<<<<<<< + * return list(self) * - * @property - * def is_sam(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is reading or writing a SAM alignment file""" - * return self.htsfile != NULL and self.htsfile.format.format == sam */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_sam_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_sam_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_31readlines(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_30readlines[] = "HFile.readlines(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_31readlines(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6is_sam___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("readlines (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_30readlines(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_sam___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_30readlines(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 149, 0, __PYX_ERR(0, 149, __pyx_L1_error)); + __Pyx_RefNannySetupContext("readlines", 0); + __Pyx_TraceCall("readlines", __pyx_f[0], 246, 0, __PYX_ERR(0, 246, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":151 - * def is_sam(self): - * """return True if HTSFile is reading or writing a SAM alignment file""" - * return self.htsfile != NULL and self.htsfile.format.format == sam # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":247 * - * @property + * def readlines(self): + * return list(self) # <<<<<<<<<<<<<< + * + * def seek(self, Py_ssize_t offset, int whence=SEEK_SET): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = (__pyx_v_self->htsfile != NULL); - if (__pyx_t_2) { - } else { - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 151, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3_bool_binop_done; - } - __pyx_t_2 = (__pyx_v_self->htsfile->format.format == sam); - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 151, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_L3_bool_binop_done:; + __pyx_t_1 = PySequence_List(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libchtslib.pyx":149 + /* "pysam/libchtslib.pyx":246 + * return b''.join(parts) + * + * def readlines(self): # <<<<<<<<<<<<<< + * return list(self) * - * @property - * def is_sam(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is reading or writing a SAM alignment file""" - * return self.htsfile != NULL and self.htsfile.format.format == sam */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_sam.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.readlines", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -4260,77 +5373,208 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_sam___get__(struct __ return __pyx_r; } -/* "pysam/libchtslib.pyx":154 +/* "pysam/libchtslib.pyx":249 + * return list(self) * - * @property - * def is_bam(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is reading or writing a BAM alignment file""" - * return self.htsfile != NULL and self.htsfile.format.format == bam + * def seek(self, Py_ssize_t offset, int whence=SEEK_SET): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_bam_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_bam_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_33seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_32seek[] = "HFile.seek(self, Py_ssize_t offset, int whence=0)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_33seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + Py_ssize_t __pyx_v_offset; + int __pyx_v_whence; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6is_bam___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_bam___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 154, 0, __PYX_ERR(0, 154, __pyx_L1_error)); - - /* "pysam/libchtslib.pyx":156 - * def is_bam(self): - * """return True if HTSFile is reading or writing a BAM alignment file""" - * return self.htsfile != NULL and self.htsfile.format.format == bam # <<<<<<<<<<<<<< - * - * @property + __Pyx_RefNannySetupContext("seek (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_offset,&__pyx_n_s_whence,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_offset)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_whence); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "seek") < 0)) __PYX_ERR(0, 249, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_offset = __Pyx_PyIndex_AsSsize_t(values[0]); if (unlikely((__pyx_v_offset == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 249, __pyx_L3_error) + if (values[1]) { + __pyx_v_whence = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_whence == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 249, __pyx_L3_error) + } else { + __pyx_v_whence = ((int)0); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("seek", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 249, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libchtslib.HFile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_32seek(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self), __pyx_v_offset, __pyx_v_whence); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_32seek(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, Py_ssize_t __pyx_v_offset, int __pyx_v_whence) { + Py_ssize_t __pyx_v_off; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("seek", 0); + __Pyx_TraceCall("seek", __pyx_f[0], 249, 0, __PYX_ERR(0, 249, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":250 + * + * def seek(self, Py_ssize_t offset, int whence=SEEK_SET): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = (__pyx_v_self->htsfile != NULL); - if (__pyx_t_2) { - } else { - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 156, __pyx_L1_error) + __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":251 + * def seek(self, Py_ssize_t offset, int whence=SEEK_SET): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * + * cdef Py_ssize_t off = hseek(self.fp, offset, whence) + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 251, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":250 + * + * def seek(self, Py_ssize_t offset, int whence=SEEK_SET): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * + */ + } + + /* "pysam/libchtslib.pyx":253 + * raise IOError('operation on closed HFile') + * + * cdef Py_ssize_t off = hseek(self.fp, offset, whence) # <<<<<<<<<<<<<< + * + * if off < 0: + */ + __pyx_v_off = hseek(__pyx_v_self->fp, __pyx_v_offset, __pyx_v_whence); + + /* "pysam/libchtslib.pyx":255 + * cdef Py_ssize_t off = hseek(self.fp, offset, whence) + * + * if off < 0: # <<<<<<<<<<<<<< + * raise IOError(herrno(self.fp), 'seek failed on HFile', self.name) + * + */ + __pyx_t_1 = ((__pyx_v_off < 0) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":256 + * + * if off < 0: + * raise IOError(herrno(self.fp), 'seek failed on HFile', self.name) # <<<<<<<<<<<<<< + * + * return off + */ + __pyx_t_2 = __Pyx_PyInt_From_int(herrno(__pyx_v_self->fp)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 256, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 256, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3_bool_binop_done; + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_INCREF(__pyx_kp_s_seek_failed_on_HFile); + __Pyx_GIVEREF(__pyx_kp_s_seek_failed_on_HFile); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_s_seek_failed_on_HFile); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_self->name); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 256, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 256, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":255 + * cdef Py_ssize_t off = hseek(self.fp, offset, whence) + * + * if off < 0: # <<<<<<<<<<<<<< + * raise IOError(herrno(self.fp), 'seek failed on HFile', self.name) + * + */ } - __pyx_t_2 = (__pyx_v_self->htsfile->format.format == bam); - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 156, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_L3_bool_binop_done:; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + + /* "pysam/libchtslib.pyx":258 + * raise IOError(herrno(self.fp), 'seek failed on HFile', self.name) + * + * return off # <<<<<<<<<<<<<< + * + * def tell(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_off); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 258, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libchtslib.pyx":154 + /* "pysam/libchtslib.pyx":249 + * return list(self) * - * @property - * def is_bam(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is reading or writing a BAM alignment file""" - * return self.htsfile != NULL and self.htsfile.format.format == bam + * def seek(self, Py_ssize_t offset, int whence=SEEK_SET): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_bam.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -4339,77 +5583,153 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_bam___get__(struct __ return __pyx_r; } -/* "pysam/libchtslib.pyx":159 +/* "pysam/libchtslib.pyx":260 + * return off * - * @property - * def is_cram(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is reading or writing a BAM alignment file""" - * return self.htsfile != NULL and self.htsfile.format.format == cram + * def tell(self): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7is_cram_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7is_cram_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_35tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_34tell[] = "HFile.tell(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_35tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_7is_cram___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("tell (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_34tell(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7is_cram___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_34tell(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { + off_t __pyx_v_ret; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 159, 0, __PYX_ERR(0, 159, __pyx_L1_error)); + __Pyx_RefNannySetupContext("tell", 0); + __Pyx_TraceCall("tell", __pyx_f[0], 260, 0, __PYX_ERR(0, 260, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":161 - * def is_cram(self): - * """return True if HTSFile is reading or writing a BAM alignment file""" - * return self.htsfile != NULL and self.htsfile.format.format == cram # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":261 + * + * def tell(self): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') * - * @property */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = (__pyx_v_self->htsfile != NULL); - if (__pyx_t_2) { - } else { - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error) + __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":262 + * def tell(self): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * + * ret = htell(self.fp) + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 262, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 262, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":261 + * + * def tell(self): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * + */ + } + + /* "pysam/libchtslib.pyx":264 + * raise IOError('operation on closed HFile') + * + * ret = htell(self.fp) # <<<<<<<<<<<<<< + * + * if ret < 0: + */ + __pyx_v_ret = htell(__pyx_v_self->fp); + + /* "pysam/libchtslib.pyx":266 + * ret = htell(self.fp) + * + * if ret < 0: # <<<<<<<<<<<<<< + * raise IOError(herrno(self.fp), 'tell failed on HFile', self.name) + * + */ + __pyx_t_1 = ((__pyx_v_ret < 0) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":267 + * + * if ret < 0: + * raise IOError(herrno(self.fp), 'tell failed on HFile', self.name) # <<<<<<<<<<<<<< + * + * return ret + */ + __pyx_t_2 = __Pyx_PyInt_From_int(herrno(__pyx_v_self->fp)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 267, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 267, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3_bool_binop_done; + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_INCREF(__pyx_kp_s_tell_failed_on_HFile); + __Pyx_GIVEREF(__pyx_kp_s_tell_failed_on_HFile); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_s_tell_failed_on_HFile); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_self->name); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 267, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 267, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":266 + * ret = htell(self.fp) + * + * if ret < 0: # <<<<<<<<<<<<<< + * raise IOError(herrno(self.fp), 'tell failed on HFile', self.name) + * + */ } - __pyx_t_2 = (__pyx_v_self->htsfile->format.format == cram); - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_L3_bool_binop_done:; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + + /* "pysam/libchtslib.pyx":269 + * raise IOError(herrno(self.fp), 'tell failed on HFile', self.name) + * + * return ret # <<<<<<<<<<<<<< + * + * def seekable(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyInt_From_off_t(__pyx_v_ret); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libchtslib.pyx":159 + /* "pysam/libchtslib.pyx":260 + * return off * - * @property - * def is_cram(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is reading or writing a BAM alignment file""" - * return self.htsfile != NULL and self.htsfile.format.format == cram + * def tell(self): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_cram.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.tell", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -4418,77 +5738,62 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7is_cram___get__(struct _ return __pyx_r; } -/* "pysam/libchtslib.pyx":164 +/* "pysam/libchtslib.pyx":271 + * return ret + * + * def seekable(self): # <<<<<<<<<<<<<< + * return self.fp != NULL * - * @property - * def is_vcf(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is reading or writing a VCF variant file""" - * return self.htsfile != NULL and self.htsfile.format.format == vcf */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_vcf_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_vcf_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_37seekable(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_36seekable[] = "HFile.seekable(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_37seekable(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6is_vcf___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("seekable (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_36seekable(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_vcf___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_36seekable(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 164, 0, __PYX_ERR(0, 164, __pyx_L1_error)); + __Pyx_RefNannySetupContext("seekable", 0); + __Pyx_TraceCall("seekable", __pyx_f[0], 271, 0, __PYX_ERR(0, 271, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":166 - * def is_vcf(self): - * """return True if HTSFile is reading or writing a VCF variant file""" - * return self.htsfile != NULL and self.htsfile.format.format == vcf # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":272 * - * @property + * def seekable(self): + * return self.fp != NULL # <<<<<<<<<<<<<< + * + * def truncate(self, size=None): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = (__pyx_v_self->htsfile != NULL); - if (__pyx_t_2) { - } else { - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 166, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3_bool_binop_done; - } - __pyx_t_2 = (__pyx_v_self->htsfile->format.format == vcf); - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 166, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_L3_bool_binop_done:; + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->fp != NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 272, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libchtslib.pyx":164 + /* "pysam/libchtslib.pyx":271 + * return ret + * + * def seekable(self): # <<<<<<<<<<<<<< + * return self.fp != NULL * - * @property - * def is_vcf(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is reading or writing a VCF variant file""" - * return self.htsfile != NULL and self.htsfile.format.format == vcf */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_vcf.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.seekable", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -4497,197 +5802,183 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_vcf___get__(struct __ return __pyx_r; } -/* "pysam/libchtslib.pyx":169 +/* "pysam/libchtslib.pyx":274 + * return self.fp != NULL + * + * def truncate(self, size=None): # <<<<<<<<<<<<<< + * raise NotImplementedError() * - * @property - * def is_bcf(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is reading or writing a BCF variant file""" - * return self.htsfile != NULL and self.htsfile.format.format == bcf */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_bcf_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_bcf_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_39truncate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_38truncate[] = "HFile.truncate(self, size=None)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_39truncate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + CYTHON_UNUSED PyObject *__pyx_v_size = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6is_bcf___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("truncate (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_size,0}; + PyObject* values[1] = {0}; + values[0] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_size); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "truncate") < 0)) __PYX_ERR(0, 274, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_size = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("truncate", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 274, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libchtslib.HFile.truncate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_38truncate(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self), __pyx_v_size); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_bcf___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_38truncate(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_size) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 169, 0, __PYX_ERR(0, 169, __pyx_L1_error)); + __Pyx_RefNannySetupContext("truncate", 0); + __Pyx_TraceCall("truncate", __pyx_f[0], 274, 0, __PYX_ERR(0, 274, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":171 - * def is_bcf(self): - * """return True if HTSFile is reading or writing a BCF variant file""" - * return self.htsfile != NULL and self.htsfile.format.format == bcf # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":275 * - * def reset(self): + * def truncate(self, size=None): + * raise NotImplementedError() # <<<<<<<<<<<<<< + * + * def writable(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = (__pyx_v_self->htsfile != NULL); - if (__pyx_t_2) { - } else { - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 171, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3_bool_binop_done; - } - __pyx_t_2 = (__pyx_v_self->htsfile->format.format == bcf); - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 171, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_L3_bool_binop_done:; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_NotImplementedError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 275, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 275, __pyx_L1_error) - /* "pysam/libchtslib.pyx":169 + /* "pysam/libchtslib.pyx":274 + * return self.fp != NULL + * + * def truncate(self, size=None): # <<<<<<<<<<<<<< + * raise NotImplementedError() * - * @property - * def is_bcf(self): # <<<<<<<<<<<<<< - * """return True if HTSFile is reading or writing a BCF variant file""" - * return self.htsfile != NULL and self.htsfile.format.format == bcf */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_bcf.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.truncate", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; - __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libchtslib.pyx":173 - * return self.htsfile != NULL and self.htsfile.format.format == bcf +/* "pysam/libchtslib.pyx":277 + * raise NotImplementedError() * - * def reset(self): # <<<<<<<<<<<<<< - * """reset file position to beginning of file just after the header. + * def writable(self): # <<<<<<<<<<<<<< + * return self.fp != NULL and 'w' in self.mode * */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_9reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_7HTSFile_8reset[] = "HTSFile.reset(self)\nreset file position to beginning of file just after the header.\n\n Returns\n -------\n\n The file position after moving the file pointer.\n\n "; -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_9reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_41writable(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_40writable[] = "HFile.writable(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_41writable(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("reset (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_8reset(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("writable (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_40writable(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8reset(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_40writable(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + int __pyx_t_2; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("reset", 0); - __Pyx_TraceCall("reset", __pyx_f[0], 173, 0, __PYX_ERR(0, 173, __pyx_L1_error)); + __Pyx_RefNannySetupContext("writable", 0); + __Pyx_TraceCall("writable", __pyx_f[0], 277, 0, __PYX_ERR(0, 277, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":182 + /* "pysam/libchtslib.pyx":278 * - * """ - * return self.seek(self.start_offset) # <<<<<<<<<<<<<< + * def writable(self): + * return self.fp != NULL and 'w' in self.mode # <<<<<<<<<<<<<< * - * def seek(self, uint64_t offset): + * def write(self, bytes b): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_seek); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_int64_t(__pyx_v_self->start_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (!__pyx_t_4) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 182, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = (__pyx_v_self->fp != NULL); + if (__pyx_t_2) { } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 182, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 182, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 182, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 278, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3_bool_binop_done; } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_w, __pyx_v_self->mode, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 278, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 278, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_L3_bool_binop_done:; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libchtslib.pyx":173 - * return self.htsfile != NULL and self.htsfile.format.format == bcf + /* "pysam/libchtslib.pyx":277 + * raise NotImplementedError() * - * def reset(self): # <<<<<<<<<<<<<< - * """reset file position to beginning of file just after the header. + * def writable(self): # <<<<<<<<<<<<<< + * return self.fp != NULL and 'w' in self.mode * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.reset", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.writable", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -4696,254 +5987,384 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8reset(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libchtslib.pyx":184 - * return self.seek(self.start_offset) +/* "pysam/libchtslib.pyx":280 + * return self.fp != NULL and 'w' in self.mode * - * def seek(self, uint64_t offset): # <<<<<<<<<<<<<< - * """move file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`.""" - * if not self.is_open: + * def write(self, bytes b): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_11seek(PyObject *__pyx_v_self, PyObject *__pyx_arg_offset); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_7HTSFile_10seek[] = "HTSFile.seek(self, uint64_t offset)\nmove file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`."; -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_11seek(PyObject *__pyx_v_self, PyObject *__pyx_arg_offset) { - uint64_t __pyx_v_offset; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_43write(PyObject *__pyx_v_self, PyObject *__pyx_v_b); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_42write[] = "HFile.write(self, bytes b)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_43write(PyObject *__pyx_v_self, PyObject *__pyx_v_b) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("seek (wrapper)", 0); - assert(__pyx_arg_offset); { - __pyx_v_offset = __Pyx_PyInt_As_uint64_t(__pyx_arg_offset); if (unlikely((__pyx_v_offset == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 184, __pyx_L3_error) - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_10seek(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), ((uint64_t)__pyx_v_offset)); + __Pyx_RefNannySetupContext("write (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_b), (&PyBytes_Type), 1, "b", 1))) __PYX_ERR(0, 280, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_42write(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self), ((PyObject*)__pyx_v_b)); /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_10seek(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, uint64_t __pyx_v_offset) { - int64_t __pyx_v_ret; +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_42write(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, PyObject *__pyx_v_b) { + Py_ssize_t __pyx_v_got; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("seek", 0); - __Pyx_TraceCall("seek", __pyx_f[0], 184, 0, __PYX_ERR(0, 184, __pyx_L1_error)); + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("write", 0); + __Pyx_TraceCall("write", __pyx_f[0], 280, 0, __PYX_ERR(0, 280, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":186 - * def seek(self, uint64_t offset): - * """move file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`.""" - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError('I/O operation on closed file') - * if self.is_stream: + /* "pysam/libchtslib.pyx":281 + * + * def write(self, bytes b): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 186, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 186, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { + __pyx_t_1 = ((__pyx_v_self->fp == NULL) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libchtslib.pyx":187 - * """move file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`.""" - * if not self.is_open: - * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< - * if self.is_stream: - * raise OSError('seek not available in streams') + /* "pysam/libchtslib.pyx":282 + * def write(self, bytes b): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * + * got = hwrite(self.fp, b, len(b)) */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 187, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 187, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 282, __pyx_L1_error) - /* "pysam/libchtslib.pyx":186 - * def seek(self, uint64_t offset): - * """move file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`.""" - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError('I/O operation on closed file') - * if self.is_stream: + /* "pysam/libchtslib.pyx":281 + * + * def write(self, bytes b): + * if self.fp == NULL: # <<<<<<<<<<<<<< + * raise IOError('operation on closed HFile') + * */ } - /* "pysam/libchtslib.pyx":188 - * if not self.is_open: - * raise ValueError('I/O operation on closed file') - * if self.is_stream: # <<<<<<<<<<<<<< - * raise OSError('seek not available in streams') + /* "pysam/libchtslib.pyx":284 + * raise IOError('operation on closed HFile') * + * got = hwrite(self.fp, b, len(b)) # <<<<<<<<<<<<<< + * + * if got < 0: */ - __pyx_t_3 = (__pyx_v_self->is_stream != 0); - if (unlikely(__pyx_t_3)) { + if (unlikely(__pyx_v_b == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(0, 284, __pyx_L1_error) + } + __pyx_t_3 = PyBytes_GET_SIZE(__pyx_v_b); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 284, __pyx_L1_error) + __pyx_v_got = hwrite(__pyx_v_self->fp, ((void *)__pyx_v_b), __pyx_t_3); - /* "pysam/libchtslib.pyx":189 - * raise ValueError('I/O operation on closed file') - * if self.is_stream: - * raise OSError('seek not available in streams') # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":286 + * got = hwrite(self.fp, b, len(b)) + * + * if got < 0: # <<<<<<<<<<<<<< + * raise IOError(herrno(self.fp), 'write failed on HFile', self.name) * - * cdef int64_t ret */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 189, __pyx_L1_error) + __pyx_t_1 = ((__pyx_v_got < 0) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libchtslib.pyx":188 - * if not self.is_open: - * raise ValueError('I/O operation on closed file') - * if self.is_stream: # <<<<<<<<<<<<<< - * raise OSError('seek not available in streams') + /* "pysam/libchtslib.pyx":287 + * + * if got < 0: + * raise IOError(herrno(self.fp), 'write failed on HFile', self.name) # <<<<<<<<<<<<<< + * + * return got + */ + __pyx_t_2 = __Pyx_PyInt_From_int(herrno(__pyx_v_self->fp)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_INCREF(__pyx_kp_s_write_failed_on_HFile); + __Pyx_GIVEREF(__pyx_kp_s_write_failed_on_HFile); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_kp_s_write_failed_on_HFile); + __Pyx_INCREF(__pyx_v_self->name); + __Pyx_GIVEREF(__pyx_v_self->name); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_self->name); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 287, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 287, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":286 + * got = hwrite(self.fp, b, len(b)) + * + * if got < 0: # <<<<<<<<<<<<<< + * raise IOError(herrno(self.fp), 'write failed on HFile', self.name) * */ } - /* "pysam/libchtslib.pyx":192 + /* "pysam/libchtslib.pyx":289 + * raise IOError(herrno(self.fp), 'write failed on HFile', self.name) * - * cdef int64_t ret - * if self.htsfile.format.compression != no_compression: # <<<<<<<<<<<<<< - * with nogil: - * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) + * return got # <<<<<<<<<<<<<< + * + * def writelines(self, lines): */ - __pyx_t_3 = ((__pyx_v_self->htsfile->format.compression != no_compression) != 0); - if (__pyx_t_3) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_got); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 289, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libchtslib.pyx":193 - * cdef int64_t ret - * if self.htsfile.format.compression != no_compression: - * with nogil: # <<<<<<<<<<<<<< - * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) - * else: + /* "pysam/libchtslib.pyx":280 + * return self.fp != NULL and 'w' in self.mode + * + * def write(self, bytes b): # <<<<<<<<<<<<<< + * if self.fp == NULL: + * raise IOError('operation on closed HFile') */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { - /* "pysam/libchtslib.pyx":194 - * if self.htsfile.format.compression != no_compression: - * with nogil: - * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) # <<<<<<<<<<<<<< - * else: - * with nogil: - */ - __pyx_v_ret = bgzf_seek(hts_get_bgzfp(__pyx_v_self->htsfile), __pyx_v_offset, SEEK_SET); - } + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libchtslib.HFile.write", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libchtslib.pyx":193 - * cdef int64_t ret - * if self.htsfile.format.compression != no_compression: - * with nogil: # <<<<<<<<<<<<<< - * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) - * else: +/* "pysam/libchtslib.pyx":291 + * return got + * + * def writelines(self, lines): # <<<<<<<<<<<<<< + * for line in lines: + * self.write(line) */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L8; - } - __pyx_L8:; - } - } - /* "pysam/libchtslib.pyx":192 +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_45writelines(PyObject *__pyx_v_self, PyObject *__pyx_v_lines); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_44writelines[] = "HFile.writelines(self, lines)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_45writelines(PyObject *__pyx_v_self, PyObject *__pyx_v_lines) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("writelines (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_44writelines(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self), ((PyObject *)__pyx_v_lines)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_44writelines(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, PyObject *__pyx_v_lines) { + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("writelines", 0); + __Pyx_TraceCall("writelines", __pyx_f[0], 291, 0, __PYX_ERR(0, 291, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":292 + * + * def writelines(self, lines): + * for line in lines: # <<<<<<<<<<<<<< + * self.write(line) * - * cdef int64_t ret - * if self.htsfile.format.compression != no_compression: # <<<<<<<<<<<<<< - * with nogil: - * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) */ - goto __pyx_L5; + if (likely(PyList_CheckExact(__pyx_v_lines)) || PyTuple_CheckExact(__pyx_v_lines)) { + __pyx_t_1 = __pyx_v_lines; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_lines); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 292, __pyx_L1_error) } - - /* "pysam/libchtslib.pyx":196 - * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) - * else: - * with nogil: # <<<<<<<<<<<<<< - * ret = hts_useek(self.htsfile, offset, SEEK_SET) - * return ret - */ - /*else*/ { - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); + for (;;) { + if (likely(!__pyx_t_3)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 292, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); #endif - /*try:*/ { + } else { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 292, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 292, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 292, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libchtslib.pyx":197 - * else: - * with nogil: - * ret = hts_useek(self.htsfile, offset, SEEK_SET) # <<<<<<<<<<<<<< - * return ret + /* "pysam/libchtslib.pyx":293 + * def writelines(self, lines): + * for line in lines: + * self.write(line) # <<<<<<<<<<<<<< + * * */ - __pyx_v_ret = hts_useek(__pyx_v_self->htsfile, ((int)__pyx_v_offset), SEEK_SET); - } + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (!__pyx_t_6) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_line); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_line}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 293, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_line}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 293, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_INCREF(__pyx_v_line); + __Pyx_GIVEREF(__pyx_v_line); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_line); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 293, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libchtslib.pyx":196 - * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) - * else: - * with nogil: # <<<<<<<<<<<<<< - * ret = hts_useek(self.htsfile, offset, SEEK_SET) - * return ret + /* "pysam/libchtslib.pyx":292 + * + * def writelines(self, lines): + * for line in lines: # <<<<<<<<<<<<<< + * self.write(line) + * */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L11; - } - __pyx_L11:; - } - } } - __pyx_L5:; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libchtslib.pyx":198 - * with nogil: - * ret = hts_useek(self.htsfile, offset, SEEK_SET) - * return ret # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":291 + * return got * - * def tell(self): + * def writelines(self, lines): # <<<<<<<<<<<<<< + * for line in lines: + * self.write(line) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int64_t(__pyx_v_ret); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 198, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libchtslib.HFile.writelines", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libchtslib.pyx":184 - * return self.seek(self.start_offset) +/* "pysam/libchtslib.pyx":74 + * cdef class HFile(object): + * cdef hFILE *fp + * cdef readonly object name, mode # <<<<<<<<<<<<<< * - * def seek(self, uint64_t offset): # <<<<<<<<<<<<<< - * """move file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`.""" - * if not self.is_open: + * def __init__(self, name, mode='r', closedf=True): */ +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_4name_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_4name_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_4name___get__(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_4name___get__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 74, 0, __PYX_ERR(0, 74, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->name); + __pyx_r = __pyx_v_self->name; + goto __pyx_L0; + /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HFile.name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -4952,1068 +6373,6490 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_10seek(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libchtslib.pyx":200 - * return ret - * - * def tell(self): # <<<<<<<<<<<<<< - * """return current file position, see :meth:`pysam.HTSFile.seek`.""" - * if not self.is_open: +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_4mode_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_4mode_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_4mode___get__(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_4mode___get__(struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 74, 0, __PYX_ERR(0, 74, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->mode); + __pyx_r = __pyx_v_self->mode; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libchtslib.HFile.mode.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("self.fp cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_13tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_7HTSFile_12tell[] = "HTSFile.tell(self)\nreturn current file position, see :meth:`pysam.HTSFile.seek`."; -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_13tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_47__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_46__reduce_cython__[] = "HFile.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_47__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("tell (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_12tell(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_46__reduce_cython__(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_12tell(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { - int64_t __pyx_v_ret; +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_46__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("tell", 0); - __Pyx_TraceCall("tell", __pyx_f[0], 200, 0, __PYX_ERR(0, 200, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":202 - * def tell(self): - * """return current file position, see :meth:`pysam.HTSFile.seek`.""" - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError('I/O operation on closed file') - * if self.is_stream: + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("self.fp cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self.fp cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 202, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 202, __pyx_L1_error) + __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = ((!__pyx_t_2) != 0); - if (unlikely(__pyx_t_3)) { + __PYX_ERR(1, 2, __pyx_L1_error) - /* "pysam/libchtslib.pyx":203 - * """return current file position, see :meth:`pysam.HTSFile.seek`.""" - * if not self.is_open: - * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< - * if self.is_stream: - * raise OSError('tell not available in streams') + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("self.fp cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 203, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 203, __pyx_L1_error) - /* "pysam/libchtslib.pyx":202 - * def tell(self): - * """return current file position, see :meth:`pysam.HTSFile.seek`.""" - * if not self.is_open: # <<<<<<<<<<<<<< - * raise ValueError('I/O operation on closed file') - * if self.is_stream: + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libchtslib.HFile.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("self.fp cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("self.fp cannot be converted to a Python object for pickling") */ - } - /* "pysam/libchtslib.pyx":204 - * if not self.is_open: +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_49__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_5HFile_48__setstate_cython__[] = "HFile.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_5HFile_49__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_5HFile_48__setstate_cython__(((struct __pyx_obj_5pysam_10libchtslib_HFile *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_5HFile_48__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + + /* "(tree fragment)":4 + * raise TypeError("self.fp cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self.fp cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("self.fp cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("self.fp cannot be converted to a Python object for pickling") + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libchtslib.HFile.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":303 + * + * class CallableValue(object): + * def __init__(self, value): # <<<<<<<<<<<<<< + * self.value = value + * def __call__(self): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_13CallableValue___init__[] = "CallableValue.__init__(self, value)"; +static PyMethodDef __pyx_mdef_5pysam_10libchtslib_13CallableValue_1__init__ = {"__init__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_13CallableValue_1__init__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_13CallableValue___init__}; +static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_self = 0; + PyObject *__pyx_v_value = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_value,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 303, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 303, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_self = values[0]; + __pyx_v_value = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 303, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_10libchtslib_13CallableValue___init__(__pyx_self, __pyx_v_self, __pyx_v_value); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_TraceFrameInit(__pyx_codeobj__14) + __Pyx_RefNannySetupContext("__init__", 0); + __Pyx_TraceCall("__init__", __pyx_f[0], 303, 0, __PYX_ERR(0, 303, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":304 + * class CallableValue(object): + * def __init__(self, value): + * self.value = value # <<<<<<<<<<<<<< + * def __call__(self): + * return self.value + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_value, __pyx_v_value) < 0) __PYX_ERR(0, 304, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":303 + * + * class CallableValue(object): + * def __init__(self, value): # <<<<<<<<<<<<<< + * self.value = value + * def __call__(self): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":305 + * def __init__(self, value): + * self.value = value + * def __call__(self): # <<<<<<<<<<<<<< + * return self.value + * def __bool__(self): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_3__call__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_13CallableValue_2__call__[] = "CallableValue.__call__(self)"; +static PyMethodDef __pyx_mdef_5pysam_10libchtslib_13CallableValue_3__call__ = {"__call__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_13CallableValue_3__call__, METH_O, __pyx_doc_5pysam_10libchtslib_13CallableValue_2__call__}; +static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_3__call__(PyObject *__pyx_self, PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_13CallableValue_2__call__(__pyx_self, ((PyObject *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_2__call__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_TraceFrameInit(__pyx_codeobj__15) + __Pyx_RefNannySetupContext("__call__", 0); + __Pyx_TraceCall("__call__", __pyx_f[0], 305, 0, __PYX_ERR(0, 305, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":306 + * self.value = value + * def __call__(self): + * return self.value # <<<<<<<<<<<<<< + * def __bool__(self): + * return self.value + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 306, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":305 + * def __init__(self, value): + * self.value = value + * def __call__(self): # <<<<<<<<<<<<<< + * return self.value + * def __bool__(self): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":307 + * def __call__(self): + * return self.value + * def __bool__(self): # <<<<<<<<<<<<<< + * return self.value + * def __nonzero__(self): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_5__bool__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_13CallableValue_4__bool__[] = "CallableValue.__bool__(self)"; +static PyMethodDef __pyx_mdef_5pysam_10libchtslib_13CallableValue_5__bool__ = {"__bool__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_13CallableValue_5__bool__, METH_O, __pyx_doc_5pysam_10libchtslib_13CallableValue_4__bool__}; +static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_5__bool__(PyObject *__pyx_self, PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__bool__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_13CallableValue_4__bool__(__pyx_self, ((PyObject *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_4__bool__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_TraceFrameInit(__pyx_codeobj__16) + __Pyx_RefNannySetupContext("__bool__", 0); + __Pyx_TraceCall("__bool__", __pyx_f[0], 307, 0, __PYX_ERR(0, 307, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":308 + * return self.value + * def __bool__(self): + * return self.value # <<<<<<<<<<<<<< + * def __nonzero__(self): + * return self.value + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":307 + * def __call__(self): + * return self.value + * def __bool__(self): # <<<<<<<<<<<<<< + * return self.value + * def __nonzero__(self): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":309 + * def __bool__(self): + * return self.value + * def __nonzero__(self): # <<<<<<<<<<<<<< + * return self.value + * def __eq__(self, other): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_7__nonzero__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_13CallableValue_6__nonzero__[] = "CallableValue.__nonzero__(self)"; +static PyMethodDef __pyx_mdef_5pysam_10libchtslib_13CallableValue_7__nonzero__ = {"__nonzero__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_13CallableValue_7__nonzero__, METH_O, __pyx_doc_5pysam_10libchtslib_13CallableValue_6__nonzero__}; +static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_7__nonzero__(PyObject *__pyx_self, PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__nonzero__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_13CallableValue_6__nonzero__(__pyx_self, ((PyObject *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_6__nonzero__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_TraceFrameInit(__pyx_codeobj__17) + __Pyx_RefNannySetupContext("__nonzero__", 0); + __Pyx_TraceCall("__nonzero__", __pyx_f[0], 309, 0, __PYX_ERR(0, 309, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":310 + * return self.value + * def __nonzero__(self): + * return self.value # <<<<<<<<<<<<<< + * def __eq__(self, other): + * return self.value == other + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 310, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":309 + * def __bool__(self): + * return self.value + * def __nonzero__(self): # <<<<<<<<<<<<<< + * return self.value + * def __eq__(self, other): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__nonzero__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":311 + * def __nonzero__(self): + * return self.value + * def __eq__(self, other): # <<<<<<<<<<<<<< + * return self.value == other + * def __ne__(self, other): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_9__eq__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_13CallableValue_8__eq__[] = "CallableValue.__eq__(self, other)"; +static PyMethodDef __pyx_mdef_5pysam_10libchtslib_13CallableValue_9__eq__ = {"__eq__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_13CallableValue_9__eq__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_13CallableValue_8__eq__}; +static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_9__eq__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_self = 0; + PyObject *__pyx_v_other = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__eq__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__eq__", 1, 2, 2, 1); __PYX_ERR(0, 311, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__eq__") < 0)) __PYX_ERR(0, 311, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_self = values[0]; + __pyx_v_other = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__eq__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 311, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__eq__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_10libchtslib_13CallableValue_8__eq__(__pyx_self, __pyx_v_self, __pyx_v_other); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_8__eq__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_TraceFrameInit(__pyx_codeobj__18) + __Pyx_RefNannySetupContext("__eq__", 0); + __Pyx_TraceCall("__eq__", __pyx_f[0], 311, 0, __PYX_ERR(0, 311, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":312 + * return self.value + * def __eq__(self, other): + * return self.value == other # <<<<<<<<<<<<<< + * def __ne__(self, other): + * return self.value != other + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 312, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_v_other, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 312, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":311 + * def __nonzero__(self): + * return self.value + * def __eq__(self, other): # <<<<<<<<<<<<<< + * return self.value == other + * def __ne__(self, other): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__eq__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":313 + * def __eq__(self, other): + * return self.value == other + * def __ne__(self, other): # <<<<<<<<<<<<<< + * return self.value != other + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_11__ne__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_13CallableValue_10__ne__[] = "CallableValue.__ne__(self, other)"; +static PyMethodDef __pyx_mdef_5pysam_10libchtslib_13CallableValue_11__ne__ = {"__ne__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_13CallableValue_11__ne__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_13CallableValue_10__ne__}; +static PyObject *__pyx_pw_5pysam_10libchtslib_13CallableValue_11__ne__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_self = 0; + PyObject *__pyx_v_other = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__ne__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__ne__", 1, 2, 2, 1); __PYX_ERR(0, 313, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__ne__") < 0)) __PYX_ERR(0, 313, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_self = values[0]; + __pyx_v_other = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__ne__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 313, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__ne__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_10libchtslib_13CallableValue_10__ne__(__pyx_self, __pyx_v_self, __pyx_v_other); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_13CallableValue_10__ne__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_TraceFrameInit(__pyx_codeobj__19) + __Pyx_RefNannySetupContext("__ne__", 0); + __Pyx_TraceCall("__ne__", __pyx_f[0], 313, 0, __PYX_ERR(0, 313, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":314 + * return self.value == other + * def __ne__(self, other): + * return self.value != other # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 314, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_v_other, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 314, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":313 + * def __eq__(self, other): + * return self.value == other + * def __ne__(self, other): # <<<<<<<<<<<<<< + * return self.value != other + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libchtslib.CallableValue.__ne__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":330 + * Base class for HTS file types + * """ + * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< + * self.htsfile = NULL + * self.threads = 1 + */ + +/* Python wrapper */ +static int __pyx_pw_5pysam_10libchtslib_7HTSFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_10libchtslib_7HTSFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + CYTHON_UNUSED PyObject *__pyx_v_args = 0; + CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1; + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile___cinit__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_10libchtslib_7HTSFile___cinit__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 330, 0, __PYX_ERR(0, 330, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":331 + * """ + * def __cinit__(self, *args, **kwargs): + * self.htsfile = NULL # <<<<<<<<<<<<<< + * self.threads = 1 + * self.duplicate_filehandle = True + */ + __pyx_v_self->htsfile = NULL; + + /* "pysam/libchtslib.pyx":332 + * def __cinit__(self, *args, **kwargs): + * self.htsfile = NULL + * self.threads = 1 # <<<<<<<<<<<<<< + * self.duplicate_filehandle = True + * + */ + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + __Pyx_GOTREF(__pyx_v_self->threads); + __Pyx_DECREF(__pyx_v_self->threads); + __pyx_v_self->threads = __pyx_int_1; + + /* "pysam/libchtslib.pyx":333 + * self.htsfile = NULL + * self.threads = 1 + * self.duplicate_filehandle = True # <<<<<<<<<<<<<< + * + * def close(self): + */ + __pyx_v_self->duplicate_filehandle = 1; + + /* "pysam/libchtslib.pyx":330 + * Base class for HTS file types + * """ + * def __cinit__(self, *args, **kwargs): # <<<<<<<<<<<<<< + * self.htsfile = NULL + * self.threads = 1 + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":335 + * self.duplicate_filehandle = True + * + * def close(self): # <<<<<<<<<<<<<< + * if self.htsfile: + * hts_close(self.htsfile) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_3close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_2close[] = "HTSFile.close(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_3close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("close (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_2close(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_2close(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("close", 0); + __Pyx_TraceCall("close", __pyx_f[0], 335, 0, __PYX_ERR(0, 335, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":336 + * + * def close(self): + * if self.htsfile: # <<<<<<<<<<<<<< + * hts_close(self.htsfile) + * self.htsfile = NULL + */ + __pyx_t_1 = (__pyx_v_self->htsfile != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":337 + * def close(self): + * if self.htsfile: + * hts_close(self.htsfile) # <<<<<<<<<<<<<< + * self.htsfile = NULL + * + */ + (void)(hts_close(__pyx_v_self->htsfile)); + + /* "pysam/libchtslib.pyx":338 + * if self.htsfile: + * hts_close(self.htsfile) + * self.htsfile = NULL # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->htsfile = NULL; + + /* "pysam/libchtslib.pyx":336 + * + * def close(self): + * if self.htsfile: # <<<<<<<<<<<<<< + * hts_close(self.htsfile) + * self.htsfile = NULL + */ + } + + /* "pysam/libchtslib.pyx":335 + * self.duplicate_filehandle = True + * + * def close(self): # <<<<<<<<<<<<<< + * if self.htsfile: + * hts_close(self.htsfile) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.close", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":340 + * self.htsfile = NULL + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * if self.htsfile: + * hts_close(self.htsfile) + */ + +/* Python wrapper */ +static void __pyx_pw_5pysam_10libchtslib_7HTSFile_5__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5pysam_10libchtslib_7HTSFile_5__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5pysam_10libchtslib_7HTSFile_4__dealloc__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +static void __pyx_pf_5pysam_10libchtslib_7HTSFile_4__dealloc__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__dealloc__", 0); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 340, 0, __PYX_ERR(0, 340, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":341 + * + * def __dealloc__(self): + * if self.htsfile: # <<<<<<<<<<<<<< + * hts_close(self.htsfile) + * self.htsfile = NULL + */ + __pyx_t_1 = (__pyx_v_self->htsfile != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":342 + * def __dealloc__(self): + * if self.htsfile: + * hts_close(self.htsfile) # <<<<<<<<<<<<<< + * self.htsfile = NULL + * + */ + (void)(hts_close(__pyx_v_self->htsfile)); + + /* "pysam/libchtslib.pyx":343 + * if self.htsfile: + * hts_close(self.htsfile) + * self.htsfile = NULL # <<<<<<<<<<<<<< + * + * def check_truncation(self, ignore_truncation=False): + */ + __pyx_v_self->htsfile = NULL; + + /* "pysam/libchtslib.pyx":341 + * + * def __dealloc__(self): + * if self.htsfile: # <<<<<<<<<<<<<< + * hts_close(self.htsfile) + * self.htsfile = NULL + */ + } + + /* "pysam/libchtslib.pyx":340 + * self.htsfile = NULL + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * if self.htsfile: + * hts_close(self.htsfile) + */ + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("pysam.libchtslib.HTSFile.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_L0:; + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); +} + +/* "pysam/libchtslib.pyx":345 + * self.htsfile = NULL + * + * def check_truncation(self, ignore_truncation=False): # <<<<<<<<<<<<<< + * """Check if file is truncated.""" + * if not self.htsfile: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7check_truncation(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_6check_truncation[] = "HTSFile.check_truncation(self, ignore_truncation=False)\nCheck if file is truncated."; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7check_truncation(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_ignore_truncation = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("check_truncation (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_ignore_truncation,0}; + PyObject* values[1] = {0}; + values[0] = ((PyObject *)Py_False); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ignore_truncation); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "check_truncation") < 0)) __PYX_ERR(0, 345, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_ignore_truncation = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("check_truncation", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 345, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.check_truncation", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6check_truncation(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), __pyx_v_ignore_truncation); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6check_truncation(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, PyObject *__pyx_v_ignore_truncation) { + BGZF *__pyx_v_bgzfp; + int __pyx_v_ret; + PyObject *__pyx_v_msg = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("check_truncation", 0); + __Pyx_TraceCall("check_truncation", __pyx_f[0], 345, 0, __PYX_ERR(0, 345, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":347 + * def check_truncation(self, ignore_truncation=False): + * """Check if file is truncated.""" + * if not self.htsfile: # <<<<<<<<<<<<<< + * return + * + */ + __pyx_t_1 = ((!(__pyx_v_self->htsfile != 0)) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":348 + * """Check if file is truncated.""" + * if not self.htsfile: + * return # <<<<<<<<<<<<<< + * + * if self.htsfile.format.compression != bgzf: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":347 + * def check_truncation(self, ignore_truncation=False): + * """Check if file is truncated.""" + * if not self.htsfile: # <<<<<<<<<<<<<< + * return + * + */ + } + + /* "pysam/libchtslib.pyx":350 + * return + * + * if self.htsfile.format.compression != bgzf: # <<<<<<<<<<<<<< + * return + * + */ + __pyx_t_1 = ((__pyx_v_self->htsfile->format.compression != bgzf) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":351 + * + * if self.htsfile.format.compression != bgzf: + * return # <<<<<<<<<<<<<< + * + * cdef BGZF *bgzfp = hts_get_bgzfp(self.htsfile) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":350 + * return + * + * if self.htsfile.format.compression != bgzf: # <<<<<<<<<<<<<< + * return + * + */ + } + + /* "pysam/libchtslib.pyx":353 + * return + * + * cdef BGZF *bgzfp = hts_get_bgzfp(self.htsfile) # <<<<<<<<<<<<<< + * if not bgzfp: + * return + */ + __pyx_v_bgzfp = hts_get_bgzfp(__pyx_v_self->htsfile); + + /* "pysam/libchtslib.pyx":354 + * + * cdef BGZF *bgzfp = hts_get_bgzfp(self.htsfile) + * if not bgzfp: # <<<<<<<<<<<<<< + * return + * + */ + __pyx_t_1 = ((!(__pyx_v_bgzfp != 0)) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":355 + * cdef BGZF *bgzfp = hts_get_bgzfp(self.htsfile) + * if not bgzfp: + * return # <<<<<<<<<<<<<< + * + * cdef int ret = bgzf_check_EOF(bgzfp) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":354 + * + * cdef BGZF *bgzfp = hts_get_bgzfp(self.htsfile) + * if not bgzfp: # <<<<<<<<<<<<<< + * return + * + */ + } + + /* "pysam/libchtslib.pyx":357 + * return + * + * cdef int ret = bgzf_check_EOF(bgzfp) # <<<<<<<<<<<<<< + * if ret < 0: + * raise IOError(errno, 'error checking for EOF marker') + */ + __pyx_v_ret = bgzf_check_EOF(__pyx_v_bgzfp); + + /* "pysam/libchtslib.pyx":358 + * + * cdef int ret = bgzf_check_EOF(bgzfp) + * if ret < 0: # <<<<<<<<<<<<<< + * raise IOError(errno, 'error checking for EOF marker') + * elif ret == 0: + */ + __pyx_t_1 = ((__pyx_v_ret < 0) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":359 + * cdef int ret = bgzf_check_EOF(bgzfp) + * if ret < 0: + * raise IOError(errno, 'error checking for EOF marker') # <<<<<<<<<<<<<< + * elif ret == 0: + * msg = 'no BGZF EOF marker; file may be truncated'.format(self.filename) + */ + __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_INCREF(__pyx_kp_s_error_checking_for_EOF_marker); + __Pyx_GIVEREF(__pyx_kp_s_error_checking_for_EOF_marker); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_s_error_checking_for_EOF_marker); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 359, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 359, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":358 + * + * cdef int ret = bgzf_check_EOF(bgzfp) + * if ret < 0: # <<<<<<<<<<<<<< + * raise IOError(errno, 'error checking for EOF marker') + * elif ret == 0: + */ + } + + /* "pysam/libchtslib.pyx":360 + * if ret < 0: + * raise IOError(errno, 'error checking for EOF marker') + * elif ret == 0: # <<<<<<<<<<<<<< + * msg = 'no BGZF EOF marker; file may be truncated'.format(self.filename) + * if ignore_truncation: + */ + __pyx_t_1 = ((__pyx_v_ret == 0) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":361 + * raise IOError(errno, 'error checking for EOF marker') + * elif ret == 0: + * msg = 'no BGZF EOF marker; file may be truncated'.format(self.filename) # <<<<<<<<<<<<<< + * if ignore_truncation: + * warn(msg) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_no_BGZF_EOF_marker_file_may_be_t, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 361, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_self->filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 361, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_self->filename}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 361, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_self->filename}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 361, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 361, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_INCREF(__pyx_v_self->filename); + __Pyx_GIVEREF(__pyx_v_self->filename); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_self->filename); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 361, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_msg = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pysam/libchtslib.pyx":362 + * elif ret == 0: + * msg = 'no BGZF EOF marker; file may be truncated'.format(self.filename) + * if ignore_truncation: # <<<<<<<<<<<<<< + * warn(msg) + * else: + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_ignore_truncation); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 362, __pyx_L1_error) + if (likely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":363 + * msg = 'no BGZF EOF marker; file may be truncated'.format(self.filename) + * if ignore_truncation: + * warn(msg) # <<<<<<<<<<<<<< + * else: + * raise IOError(msg) + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_warn); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 363, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_msg); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_msg}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_msg}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 363, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_msg); + __Pyx_GIVEREF(__pyx_v_msg); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_msg); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libchtslib.pyx":362 + * elif ret == 0: + * msg = 'no BGZF EOF marker; file may be truncated'.format(self.filename) + * if ignore_truncation: # <<<<<<<<<<<<<< + * warn(msg) + * else: + */ + goto __pyx_L7; + } + + /* "pysam/libchtslib.pyx":365 + * warn(msg) + * else: + * raise IOError(msg) # <<<<<<<<<<<<<< + * + * def __enter__(self): + */ + /*else*/ { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_v_msg); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 365, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 365, __pyx_L1_error) + } + __pyx_L7:; + + /* "pysam/libchtslib.pyx":360 + * if ret < 0: + * raise IOError(errno, 'error checking for EOF marker') + * elif ret == 0: # <<<<<<<<<<<<<< + * msg = 'no BGZF EOF marker; file may be truncated'.format(self.filename) + * if ignore_truncation: + */ + } + + /* "pysam/libchtslib.pyx":345 + * self.htsfile = NULL + * + * def check_truncation(self, ignore_truncation=False): # <<<<<<<<<<<<<< + * """Check if file is truncated.""" + * if not self.htsfile: + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.check_truncation", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_msg); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":367 + * raise IOError(msg) + * + * def __enter__(self): # <<<<<<<<<<<<<< + * return self + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_9__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_8__enter__[] = "HTSFile.__enter__(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_9__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__enter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_8__enter__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8__enter__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__enter__", 0); + __Pyx_TraceCall("__enter__", __pyx_f[0], 367, 0, __PYX_ERR(0, 367, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":368 + * + * def __enter__(self): + * return self # <<<<<<<<<<<<<< + * + * def __exit__(self, exc_type, exc_value, traceback): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":367 + * raise IOError(msg) + * + * def __enter__(self): # <<<<<<<<<<<<<< + * return self + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.__enter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":370 + * return self + * + * def __exit__(self, exc_type, exc_value, traceback): # <<<<<<<<<<<<<< + * self.close() + * return False + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_11__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_10__exit__[] = "HTSFile.__exit__(self, exc_type, exc_value, traceback)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_11__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + CYTHON_UNUSED PyObject *__pyx_v_exc_type = 0; + CYTHON_UNUSED PyObject *__pyx_v_exc_value = 0; + CYTHON_UNUSED PyObject *__pyx_v_traceback = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__exit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_exc_type,&__pyx_n_s_exc_value,&__pyx_n_s_traceback,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_exc_type)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_exc_value)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 370, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_traceback)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 370, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 370, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_exc_type = values[0]; + __pyx_v_exc_value = values[1]; + __pyx_v_traceback = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 370, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_10__exit__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), __pyx_v_exc_type, __pyx_v_exc_value, __pyx_v_traceback); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_10__exit__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__exit__", 0); + __Pyx_TraceCall("__exit__", __pyx_f[0], 370, 0, __PYX_ERR(0, 370, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":371 + * + * def __exit__(self, exc_type, exc_value, traceback): + * self.close() # <<<<<<<<<<<<<< + * return False + * + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 371, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libchtslib.pyx":372 + * def __exit__(self, exc_type, exc_value, traceback): + * self.close() + * return False # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_False); + __pyx_r = Py_False; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":370 + * return self + * + * def __exit__(self, exc_type, exc_value, traceback): # <<<<<<<<<<<<<< + * self.close() + * return False + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":375 + * + * @property + * def category(self): # <<<<<<<<<<<<<< + * """General file format category. One of UNKNOWN, ALIGNMENTS, + * VARIANTS, INDEX, REGIONS""" + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_8category_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_8category_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_8category___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8category___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 375, 0, __PYX_ERR(0, 375, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":378 + * """General file format category. One of UNKNOWN, ALIGNMENTS, + * VARIANTS, INDEX, REGIONS""" + * if not self.htsfile: # <<<<<<<<<<<<<< + * raise ValueError('metadata not available on closed file') + * return FORMAT_CATEGORIES[self.htsfile.format.category] + */ + __pyx_t_1 = ((!(__pyx_v_self->htsfile != 0)) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":379 + * VARIANTS, INDEX, REGIONS""" + * if not self.htsfile: + * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< + * return FORMAT_CATEGORIES[self.htsfile.format.category] + * + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 379, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 379, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":378 + * """General file format category. One of UNKNOWN, ALIGNMENTS, + * VARIANTS, INDEX, REGIONS""" + * if not self.htsfile: # <<<<<<<<<<<<<< + * raise ValueError('metadata not available on closed file') + * return FORMAT_CATEGORIES[self.htsfile.format.category] + */ + } + + /* "pysam/libchtslib.pyx":380 + * if not self.htsfile: + * raise ValueError('metadata not available on closed file') + * return FORMAT_CATEGORIES[self.htsfile.format.category] # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + if (unlikely(__pyx_v_5pysam_10libchtslib_FORMAT_CATEGORIES == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 380, __pyx_L1_error) + } + __pyx_t_2 = __Pyx_PyInt_From_enum__htsFormatCategory(__pyx_v_self->htsfile->format.category); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_5pysam_10libchtslib_FORMAT_CATEGORIES, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 380, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":375 + * + * @property + * def category(self): # <<<<<<<<<<<<<< + * """General file format category. One of UNKNOWN, ALIGNMENTS, + * VARIANTS, INDEX, REGIONS""" + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.category.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":383 + * + * @property + * def format(self): # <<<<<<<<<<<<<< + * """File format. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6format_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6format_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6format___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6format___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 383, 0, __PYX_ERR(0, 383, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":389 + * BAI, CRAM, CRAI, VCF, BCF, CSI, GZI, TBI, BED. + * """ + * if not self.htsfile: # <<<<<<<<<<<<<< + * raise ValueError('metadata not available on closed file') + * return FORMATS[self.htsfile.format.format] + */ + __pyx_t_1 = ((!(__pyx_v_self->htsfile != 0)) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":390 + * """ + * if not self.htsfile: + * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< + * return FORMATS[self.htsfile.format.format] + * + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 390, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 390, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":389 + * BAI, CRAM, CRAI, VCF, BCF, CSI, GZI, TBI, BED. + * """ + * if not self.htsfile: # <<<<<<<<<<<<<< + * raise ValueError('metadata not available on closed file') + * return FORMATS[self.htsfile.format.format] + */ + } + + /* "pysam/libchtslib.pyx":391 + * if not self.htsfile: + * raise ValueError('metadata not available on closed file') + * return FORMATS[self.htsfile.format.format] # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + if (unlikely(__pyx_v_5pysam_10libchtslib_FORMATS == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 391, __pyx_L1_error) + } + __pyx_t_2 = __Pyx_PyInt_From_enum__htsExactFormat(__pyx_v_self->htsfile->format.format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 391, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_5pysam_10libchtslib_FORMATS, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 391, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":383 + * + * @property + * def format(self): # <<<<<<<<<<<<<< + * """File format. + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.format.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":394 + * + * @property + * def version(self): # <<<<<<<<<<<<<< + * """Tuple of file format version numbers (major, minor)""" + * if not self.htsfile: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7version_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7version_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_7version___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7version___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 394, 0, __PYX_ERR(0, 394, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":396 + * def version(self): + * """Tuple of file format version numbers (major, minor)""" + * if not self.htsfile: # <<<<<<<<<<<<<< + * raise ValueError('metadata not available on closed file') + * return self.htsfile.format.version.major, self.htsfile.format.version.minor + */ + __pyx_t_1 = ((!(__pyx_v_self->htsfile != 0)) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":397 + * """Tuple of file format version numbers (major, minor)""" + * if not self.htsfile: + * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< + * return self.htsfile.format.version.major, self.htsfile.format.version.minor + * + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 397, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 397, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":396 + * def version(self): + * """Tuple of file format version numbers (major, minor)""" + * if not self.htsfile: # <<<<<<<<<<<<<< + * raise ValueError('metadata not available on closed file') + * return self.htsfile.format.version.major, self.htsfile.format.version.minor + */ + } + + /* "pysam/libchtslib.pyx":398 + * if not self.htsfile: + * raise ValueError('metadata not available on closed file') + * return self.htsfile.format.version.major, self.htsfile.format.version.minor # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyInt_From_short(__pyx_v_self->htsfile->format.version.major); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 398, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_From_short(__pyx_v_self->htsfile->format.version.minor); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 398, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 398, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":394 + * + * @property + * def version(self): # <<<<<<<<<<<<<< + * """Tuple of file format version numbers (major, minor)""" + * if not self.htsfile: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.version.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":401 + * + * @property + * def compression(self): # <<<<<<<<<<<<<< + * """File compression. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_11compression_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_11compression_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_11compression___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_11compression___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 401, 0, __PYX_ERR(0, 401, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":405 + * + * One of NONE, GZIP, BGZF, CUSTOM.""" + * if not self.htsfile: # <<<<<<<<<<<<<< + * raise ValueError('metadata not available on closed file') + * return COMPRESSION[self.htsfile.format.compression] + */ + __pyx_t_1 = ((!(__pyx_v_self->htsfile != 0)) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":406 + * One of NONE, GZIP, BGZF, CUSTOM.""" + * if not self.htsfile: + * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< + * return COMPRESSION[self.htsfile.format.compression] + * + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 406, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 406, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":405 + * + * One of NONE, GZIP, BGZF, CUSTOM.""" + * if not self.htsfile: # <<<<<<<<<<<<<< + * raise ValueError('metadata not available on closed file') + * return COMPRESSION[self.htsfile.format.compression] + */ + } + + /* "pysam/libchtslib.pyx":407 + * if not self.htsfile: + * raise ValueError('metadata not available on closed file') + * return COMPRESSION[self.htsfile.format.compression] # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + if (unlikely(__pyx_v_5pysam_10libchtslib_COMPRESSION == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 407, __pyx_L1_error) + } + __pyx_t_2 = __Pyx_PyInt_From_enum__htsCompression(__pyx_v_self->htsfile->format.compression); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 407, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_5pysam_10libchtslib_COMPRESSION, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 407, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":401 + * + * @property + * def compression(self): # <<<<<<<<<<<<<< + * """File compression. + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.compression.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":410 + * + * @property + * def description(self): # <<<<<<<<<<<<<< + * """Vaguely human readable description of the file format""" + * if not self.htsfile: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_11description_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_11description_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_11description___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_11description___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + char *__pyx_v_desc; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + char const *__pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 410, 0, __PYX_ERR(0, 410, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":412 + * def description(self): + * """Vaguely human readable description of the file format""" + * if not self.htsfile: # <<<<<<<<<<<<<< + * raise ValueError('metadata not available on closed file') + * cdef char *desc = hts_format_description(&self.htsfile.format) + */ + __pyx_t_1 = ((!(__pyx_v_self->htsfile != 0)) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":413 + * """Vaguely human readable description of the file format""" + * if not self.htsfile: + * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< + * cdef char *desc = hts_format_description(&self.htsfile.format) + * try: + */ + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 413, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 413, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":412 + * def description(self): + * """Vaguely human readable description of the file format""" + * if not self.htsfile: # <<<<<<<<<<<<<< + * raise ValueError('metadata not available on closed file') + * cdef char *desc = hts_format_description(&self.htsfile.format) + */ + } + + /* "pysam/libchtslib.pyx":414 + * if not self.htsfile: + * raise ValueError('metadata not available on closed file') + * cdef char *desc = hts_format_description(&self.htsfile.format) # <<<<<<<<<<<<<< + * try: + * return charptr_to_str(desc) + */ + __pyx_v_desc = hts_format_description((&__pyx_v_self->htsfile->format)); + + /* "pysam/libchtslib.pyx":415 + * raise ValueError('metadata not available on closed file') + * cdef char *desc = hts_format_description(&self.htsfile.format) + * try: # <<<<<<<<<<<<<< + * return charptr_to_str(desc) + * finally: + */ + /*try:*/ { + + /* "pysam/libchtslib.pyx":416 + * cdef char *desc = hts_format_description(&self.htsfile.format) + * try: + * return charptr_to_str(desc) # <<<<<<<<<<<<<< + * finally: + * free(desc) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_desc, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 416, __pyx_L5_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L4_return; + } + + /* "pysam/libchtslib.pyx":418 + * return charptr_to_str(desc) + * finally: + * free(desc) # <<<<<<<<<<<<<< + * + * @property + */ + /*finally:*/ { + __pyx_L5_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_6 = 0; __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __pyx_t_3 = __pyx_lineno; __pyx_t_4 = __pyx_clineno; __pyx_t_5 = __pyx_filename; + { + free(__pyx_v_desc); + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); + } + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ErrRestore(__pyx_t_6, __pyx_t_7, __pyx_t_8); + __pyx_t_6 = 0; __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; + __pyx_lineno = __pyx_t_3; __pyx_clineno = __pyx_t_4; __pyx_filename = __pyx_t_5; + goto __pyx_L1_error; + } + __pyx_L4_return: { + __pyx_t_11 = __pyx_r; + __pyx_r = 0; + free(__pyx_v_desc); + __pyx_r = __pyx_t_11; + __pyx_t_11 = 0; + goto __pyx_L0; + } + } + + /* "pysam/libchtslib.pyx":410 + * + * @property + * def description(self): # <<<<<<<<<<<<<< + * """Vaguely human readable description of the file format""" + * if not self.htsfile: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.description.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":421 + * + * @property + * def is_open(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is open and in a valid state.""" + * return CTrue if self.htsfile != NULL else CFalse + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7is_open_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7is_open_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_7is_open___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7is_open___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 421, 0, __PYX_ERR(0, 421, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":423 + * def is_open(self): + * """return True if HTSFile is open and in a valid state.""" + * return CTrue if self.htsfile != NULL else CFalse # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + if (((__pyx_v_self->htsfile != NULL) != 0)) { + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_CTrue); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 423, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __pyx_t_2; + __pyx_t_2 = 0; + } else { + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_CFalse); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 423, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __pyx_t_2; + __pyx_t_2 = 0; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":421 + * + * @property + * def is_open(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is open and in a valid state.""" + * return CTrue if self.htsfile != NULL else CFalse + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_open.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":426 + * + * @property + * def is_closed(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is closed.""" + * return self.htsfile == NULL + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_9is_closed_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_9is_closed_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_9is_closed___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_9is_closed___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 426, 0, __PYX_ERR(0, 426, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":428 + * def is_closed(self): + * """return True if HTSFile is closed.""" + * return self.htsfile == NULL # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->htsfile == NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 428, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":426 + * + * @property + * def is_closed(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is closed.""" + * return self.htsfile == NULL + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_closed.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":431 + * + * @property + * def closed(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is closed.""" + * return self.htsfile == NULL + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6closed_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6closed_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6closed___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6closed___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 431, 0, __PYX_ERR(0, 431, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":433 + * def closed(self): + * """return True if HTSFile is closed.""" + * return self.htsfile == NULL # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->htsfile == NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 433, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":431 + * + * @property + * def closed(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is closed.""" + * return self.htsfile == NULL + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.closed.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":436 + * + * @property + * def is_write(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is open for writing""" + * return self.htsfile != NULL and self.htsfile.is_write != 0 + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_8is_write_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_8is_write_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_8is_write___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8is_write___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 436, 0, __PYX_ERR(0, 436, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":438 + * def is_write(self): + * """return True if HTSFile is open for writing""" + * return self.htsfile != NULL and self.htsfile.is_write != 0 # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = (__pyx_v_self->htsfile != NULL); + if (__pyx_t_2) { + } else { + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3_bool_binop_done; + } + __pyx_t_2 = (__pyx_v_self->htsfile->is_write != 0); + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_L3_bool_binop_done:; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":436 + * + * @property + * def is_write(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is open for writing""" + * return self.htsfile != NULL and self.htsfile.is_write != 0 + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_write.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":441 + * + * @property + * def is_read(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is open for reading""" + * return self.htsfile != NULL and self.htsfile.is_write == 0 + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7is_read_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7is_read_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_7is_read___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7is_read___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 441, 0, __PYX_ERR(0, 441, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":443 + * def is_read(self): + * """return True if HTSFile is open for reading""" + * return self.htsfile != NULL and self.htsfile.is_write == 0 # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = (__pyx_v_self->htsfile != NULL); + if (__pyx_t_2) { + } else { + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3_bool_binop_done; + } + __pyx_t_2 = (__pyx_v_self->htsfile->is_write == 0); + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_L3_bool_binop_done:; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":441 + * + * @property + * def is_read(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is open for reading""" + * return self.htsfile != NULL and self.htsfile.is_write == 0 + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_read.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":446 + * + * @property + * def is_sam(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is reading or writing a SAM alignment file""" + * return self.htsfile != NULL and self.htsfile.format.format == sam + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_sam_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_sam_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6is_sam___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_sam___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 446, 0, __PYX_ERR(0, 446, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":448 + * def is_sam(self): + * """return True if HTSFile is reading or writing a SAM alignment file""" + * return self.htsfile != NULL and self.htsfile.format.format == sam # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = (__pyx_v_self->htsfile != NULL); + if (__pyx_t_2) { + } else { + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3_bool_binop_done; + } + __pyx_t_2 = (__pyx_v_self->htsfile->format.format == sam); + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 448, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_L3_bool_binop_done:; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":446 + * + * @property + * def is_sam(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is reading or writing a SAM alignment file""" + * return self.htsfile != NULL and self.htsfile.format.format == sam + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_sam.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":451 + * + * @property + * def is_bam(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is reading or writing a BAM alignment file""" + * return self.htsfile != NULL and self.htsfile.format.format == bam + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_bam_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_bam_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6is_bam___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_bam___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 451, 0, __PYX_ERR(0, 451, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":453 + * def is_bam(self): + * """return True if HTSFile is reading or writing a BAM alignment file""" + * return self.htsfile != NULL and self.htsfile.format.format == bam # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = (__pyx_v_self->htsfile != NULL); + if (__pyx_t_2) { + } else { + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3_bool_binop_done; + } + __pyx_t_2 = (__pyx_v_self->htsfile->format.format == bam); + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_L3_bool_binop_done:; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":451 + * + * @property + * def is_bam(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is reading or writing a BAM alignment file""" + * return self.htsfile != NULL and self.htsfile.format.format == bam + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_bam.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":456 + * + * @property + * def is_cram(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is reading or writing a BAM alignment file""" + * return self.htsfile != NULL and self.htsfile.format.format == cram + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7is_cram_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7is_cram_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_7is_cram___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7is_cram___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 456, 0, __PYX_ERR(0, 456, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":458 + * def is_cram(self): + * """return True if HTSFile is reading or writing a BAM alignment file""" + * return self.htsfile != NULL and self.htsfile.format.format == cram # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = (__pyx_v_self->htsfile != NULL); + if (__pyx_t_2) { + } else { + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 458, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3_bool_binop_done; + } + __pyx_t_2 = (__pyx_v_self->htsfile->format.format == cram); + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 458, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_L3_bool_binop_done:; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":456 + * + * @property + * def is_cram(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is reading or writing a BAM alignment file""" + * return self.htsfile != NULL and self.htsfile.format.format == cram + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_cram.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":461 + * + * @property + * def is_vcf(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is reading or writing a VCF variant file""" + * return self.htsfile != NULL and self.htsfile.format.format == vcf + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_vcf_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_vcf_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6is_vcf___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_vcf___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 461, 0, __PYX_ERR(0, 461, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":463 + * def is_vcf(self): + * """return True if HTSFile is reading or writing a VCF variant file""" + * return self.htsfile != NULL and self.htsfile.format.format == vcf # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = (__pyx_v_self->htsfile != NULL); + if (__pyx_t_2) { + } else { + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 463, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3_bool_binop_done; + } + __pyx_t_2 = (__pyx_v_self->htsfile->format.format == vcf); + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 463, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_L3_bool_binop_done:; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":461 + * + * @property + * def is_vcf(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is reading or writing a VCF variant file""" + * return self.htsfile != NULL and self.htsfile.format.format == vcf + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_vcf.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":466 + * + * @property + * def is_bcf(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is reading or writing a BCF variant file""" + * return self.htsfile != NULL and self.htsfile.format.format == bcf + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_bcf_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_6is_bcf_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_6is_bcf___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_6is_bcf___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 466, 0, __PYX_ERR(0, 466, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":468 + * def is_bcf(self): + * """return True if HTSFile is reading or writing a BCF variant file""" + * return self.htsfile != NULL and self.htsfile.format.format == bcf # <<<<<<<<<<<<<< + * + * def reset(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = (__pyx_v_self->htsfile != NULL); + if (__pyx_t_2) { + } else { + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 468, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3_bool_binop_done; + } + __pyx_t_2 = (__pyx_v_self->htsfile->format.format == bcf); + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 468, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_L3_bool_binop_done:; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":466 + * + * @property + * def is_bcf(self): # <<<<<<<<<<<<<< + * """return True if HTSFile is reading or writing a BCF variant file""" + * return self.htsfile != NULL and self.htsfile.format.format == bcf + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_bcf.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":470 + * return self.htsfile != NULL and self.htsfile.format.format == bcf + * + * def reset(self): # <<<<<<<<<<<<<< + * """reset file position to beginning of file just after the header. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_13reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_12reset[] = "HTSFile.reset(self)\nreset file position to beginning of file just after the header.\n\n Returns\n -------\n\n The file position after moving the file pointer.\n\n "; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_13reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("reset (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_12reset(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_12reset(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("reset", 0); + __Pyx_TraceCall("reset", __pyx_f[0], 470, 0, __PYX_ERR(0, 470, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":479 + * + * """ + * return self.seek(self.start_offset) # <<<<<<<<<<<<<< + * + * def seek(self, uint64_t offset): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_seek); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 479, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_From_int64_t(__pyx_v_self->start_offset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 479, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_4) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 479, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 479, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 479, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 479, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 479, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":470 + * return self.htsfile != NULL and self.htsfile.format.format == bcf + * + * def reset(self): # <<<<<<<<<<<<<< + * """reset file position to beginning of file just after the header. + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.reset", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":481 + * return self.seek(self.start_offset) + * + * def seek(self, uint64_t offset): # <<<<<<<<<<<<<< + * """move file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`.""" + * if not self.is_open: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_15seek(PyObject *__pyx_v_self, PyObject *__pyx_arg_offset); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_14seek[] = "HTSFile.seek(self, uint64_t offset)\nmove file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`."; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_15seek(PyObject *__pyx_v_self, PyObject *__pyx_arg_offset) { + uint64_t __pyx_v_offset; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("seek (wrapper)", 0); + assert(__pyx_arg_offset); { + __pyx_v_offset = __Pyx_PyInt_As_uint64_t(__pyx_arg_offset); if (unlikely((__pyx_v_offset == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 481, __pyx_L3_error) + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_14seek(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), ((uint64_t)__pyx_v_offset)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_14seek(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, uint64_t __pyx_v_offset) { + int64_t __pyx_v_ret; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("seek", 0); + __Pyx_TraceCall("seek", __pyx_f[0], 481, 0, __PYX_ERR(0, 481, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":483 + * def seek(self, uint64_t offset): + * """move file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`.""" + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError('I/O operation on closed file') + * if self.is_stream: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 483, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 483, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = ((!__pyx_t_2) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libchtslib.pyx":484 + * """move file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`.""" + * if not self.is_open: + * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< + * if self.is_stream: + * raise IOError('seek not available in streams') + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 484, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 484, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":483 + * def seek(self, uint64_t offset): + * """move file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`.""" + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError('I/O operation on closed file') + * if self.is_stream: + */ + } + + /* "pysam/libchtslib.pyx":485 + * if not self.is_open: + * raise ValueError('I/O operation on closed file') + * if self.is_stream: # <<<<<<<<<<<<<< + * raise IOError('seek not available in streams') + * + */ + __pyx_t_3 = (__pyx_v_self->is_stream != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libchtslib.pyx":486 + * raise ValueError('I/O operation on closed file') + * if self.is_stream: + * raise IOError('seek not available in streams') # <<<<<<<<<<<<<< + * + * cdef int64_t ret + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 486, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":485 + * if not self.is_open: + * raise ValueError('I/O operation on closed file') + * if self.is_stream: # <<<<<<<<<<<<<< + * raise IOError('seek not available in streams') + * + */ + } + + /* "pysam/libchtslib.pyx":489 + * + * cdef int64_t ret + * if self.htsfile.format.compression == bgzf: # <<<<<<<<<<<<<< + * with nogil: + * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) + */ + switch (__pyx_v_self->htsfile->format.compression) { + case bgzf: + + /* "pysam/libchtslib.pyx":490 + * cdef int64_t ret + * if self.htsfile.format.compression == bgzf: + * with nogil: # <<<<<<<<<<<<<< + * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) + * elif self.htsfile.format.compression == no_compression: + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libchtslib.pyx":491 + * if self.htsfile.format.compression == bgzf: + * with nogil: + * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) # <<<<<<<<<<<<<< + * elif self.htsfile.format.compression == no_compression: + * with nogil: + */ + __pyx_v_ret = bgzf_seek(hts_get_bgzfp(__pyx_v_self->htsfile), __pyx_v_offset, 0); + } + + /* "pysam/libchtslib.pyx":490 + * cdef int64_t ret + * if self.htsfile.format.compression == bgzf: + * with nogil: # <<<<<<<<<<<<<< + * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) + * elif self.htsfile.format.compression == no_compression: + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L7; + } + __pyx_L7:; + } + } + + /* "pysam/libchtslib.pyx":489 + * + * cdef int64_t ret + * if self.htsfile.format.compression == bgzf: # <<<<<<<<<<<<<< + * with nogil: + * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) + */ + break; + + /* "pysam/libchtslib.pyx":492 + * with nogil: + * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) + * elif self.htsfile.format.compression == no_compression: # <<<<<<<<<<<<<< + * with nogil: + * ret = hts_useek(self.htsfile, offset, SEEK_SET) + */ + case no_compression: + + /* "pysam/libchtslib.pyx":493 + * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) + * elif self.htsfile.format.compression == no_compression: + * with nogil: # <<<<<<<<<<<<<< + * ret = hts_useek(self.htsfile, offset, SEEK_SET) + * else: + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libchtslib.pyx":494 + * elif self.htsfile.format.compression == no_compression: + * with nogil: + * ret = hts_useek(self.htsfile, offset, SEEK_SET) # <<<<<<<<<<<<<< + * else: + * raise NotImplementedError("seek not implemented in files compressed by method {}".format( + */ + __pyx_v_ret = hts_useek(__pyx_v_self->htsfile, ((int)__pyx_v_offset), 0); + } + + /* "pysam/libchtslib.pyx":493 + * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) + * elif self.htsfile.format.compression == no_compression: + * with nogil: # <<<<<<<<<<<<<< + * ret = hts_useek(self.htsfile, offset, SEEK_SET) + * else: + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L10; + } + __pyx_L10:; + } + } + + /* "pysam/libchtslib.pyx":492 + * with nogil: + * ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) + * elif self.htsfile.format.compression == no_compression: # <<<<<<<<<<<<<< + * with nogil: + * ret = hts_useek(self.htsfile, offset, SEEK_SET) + */ + break; + default: + + /* "pysam/libchtslib.pyx":496 + * ret = hts_useek(self.htsfile, offset, SEEK_SET) + * else: + * raise NotImplementedError("seek not implemented in files compressed by method {}".format( # <<<<<<<<<<<<<< + * self.htsfile.format.compression)) + * return ret + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_seek_not_implemented_in_files_co, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pysam/libchtslib.pyx":497 + * else: + * raise NotImplementedError("seek not implemented in files compressed by method {}".format( + * self.htsfile.format.compression)) # <<<<<<<<<<<<<< + * return ret + * + */ + __pyx_t_5 = __Pyx_PyInt_From_enum__htsCompression(__pyx_v_self->htsfile->format.compression); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 497, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_6) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 496, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 496, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 496, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libchtslib.pyx":496 + * ret = hts_useek(self.htsfile, offset, SEEK_SET) + * else: + * raise NotImplementedError("seek not implemented in files compressed by method {}".format( # <<<<<<<<<<<<<< + * self.htsfile.format.compression)) + * return ret + */ + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_NotImplementedError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 496, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 496, __pyx_L1_error) + break; + } + + /* "pysam/libchtslib.pyx":498 + * raise NotImplementedError("seek not implemented in files compressed by method {}".format( + * self.htsfile.format.compression)) + * return ret # <<<<<<<<<<<<<< + * + * def tell(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyInt_From_int64_t(__pyx_v_ret); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 498, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":481 + * return self.seek(self.start_offset) + * + * def seek(self, uint64_t offset): # <<<<<<<<<<<<<< + * """move file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`.""" + * if not self.is_open: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":500 + * return ret + * + * def tell(self): # <<<<<<<<<<<<<< + * """return current file position, see :meth:`pysam.HTSFile.seek`.""" + * if not self.is_open: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_17tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_16tell[] = "HTSFile.tell(self)\nreturn current file position, see :meth:`pysam.HTSFile.seek`."; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_17tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("tell (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_16tell(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_16tell(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + int64_t __pyx_v_ret; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("tell", 0); + __Pyx_TraceCall("tell", __pyx_f[0], 500, 0, __PYX_ERR(0, 500, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":502 + * def tell(self): + * """return current file position, see :meth:`pysam.HTSFile.seek`.""" + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError('I/O operation on closed file') + * if self.is_stream: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 502, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 502, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = ((!__pyx_t_2) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libchtslib.pyx":503 + * """return current file position, see :meth:`pysam.HTSFile.seek`.""" + * if not self.is_open: + * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< + * if self.is_stream: + * raise IOError('tell not available in streams') + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 503, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":502 + * def tell(self): + * """return current file position, see :meth:`pysam.HTSFile.seek`.""" + * if not self.is_open: # <<<<<<<<<<<<<< + * raise ValueError('I/O operation on closed file') + * if self.is_stream: + */ + } + + /* "pysam/libchtslib.pyx":504 + * if not self.is_open: + * raise ValueError('I/O operation on closed file') + * if self.is_stream: # <<<<<<<<<<<<<< + * raise IOError('tell not available in streams') + * + */ + __pyx_t_3 = (__pyx_v_self->is_stream != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libchtslib.pyx":505 + * raise ValueError('I/O operation on closed file') + * if self.is_stream: + * raise IOError('tell not available in streams') # <<<<<<<<<<<<<< + * + * cdef int64_t ret + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 505, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 505, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":504 + * if not self.is_open: * raise ValueError('I/O operation on closed file') * if self.is_stream: # <<<<<<<<<<<<<< - * raise OSError('tell not available in streams') + * raise IOError('tell not available in streams') + * + */ + } + + /* "pysam/libchtslib.pyx":508 + * + * cdef int64_t ret + * if self.htsfile.format.compression == bgzf: # <<<<<<<<<<<<<< + * with nogil: + * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) + */ + __pyx_t_3 = ((__pyx_v_self->htsfile->format.compression == bgzf) != 0); + if (__pyx_t_3) { + + /* "pysam/libchtslib.pyx":509 + * cdef int64_t ret + * if self.htsfile.format.compression == bgzf: + * with nogil: # <<<<<<<<<<<<<< + * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) + * elif self.htsfile.format.compression == no_compression: + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libchtslib.pyx":510 + * if self.htsfile.format.compression == bgzf: + * with nogil: + * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) # <<<<<<<<<<<<<< + * elif self.htsfile.format.compression == no_compression: + * with nogil: + */ + __pyx_v_ret = bgzf_tell(hts_get_bgzfp(__pyx_v_self->htsfile)); + } + + /* "pysam/libchtslib.pyx":509 + * cdef int64_t ret + * if self.htsfile.format.compression == bgzf: + * with nogil: # <<<<<<<<<<<<<< + * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) + * elif self.htsfile.format.compression == no_compression: + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L8; + } + __pyx_L8:; + } + } + + /* "pysam/libchtslib.pyx":508 + * + * cdef int64_t ret + * if self.htsfile.format.compression == bgzf: # <<<<<<<<<<<<<< + * with nogil: + * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) + */ + goto __pyx_L5; + } + + /* "pysam/libchtslib.pyx":511 + * with nogil: + * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) + * elif self.htsfile.format.compression == no_compression: # <<<<<<<<<<<<<< + * with nogil: + * ret = hts_utell(self.htsfile) + */ + __pyx_t_3 = ((__pyx_v_self->htsfile->format.compression == no_compression) != 0); + if (__pyx_t_3) { + + /* "pysam/libchtslib.pyx":512 + * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) + * elif self.htsfile.format.compression == no_compression: + * with nogil: # <<<<<<<<<<<<<< + * ret = hts_utell(self.htsfile) + * elif self.htsfile.format.format == cram: + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libchtslib.pyx":513 + * elif self.htsfile.format.compression == no_compression: + * with nogil: + * ret = hts_utell(self.htsfile) # <<<<<<<<<<<<<< + * elif self.htsfile.format.format == cram: + * with nogil: + */ + __pyx_v_ret = hts_utell(__pyx_v_self->htsfile); + } + + /* "pysam/libchtslib.pyx":512 + * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) + * elif self.htsfile.format.compression == no_compression: + * with nogil: # <<<<<<<<<<<<<< + * ret = hts_utell(self.htsfile) + * elif self.htsfile.format.format == cram: + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L11; + } + __pyx_L11:; + } + } + + /* "pysam/libchtslib.pyx":511 + * with nogil: + * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) + * elif self.htsfile.format.compression == no_compression: # <<<<<<<<<<<<<< + * with nogil: + * ret = hts_utell(self.htsfile) + */ + goto __pyx_L5; + } + + /* "pysam/libchtslib.pyx":514 + * with nogil: + * ret = hts_utell(self.htsfile) + * elif self.htsfile.format.format == cram: # <<<<<<<<<<<<<< + * with nogil: + * ret = htell(cram_fd_get_fp(self.htsfile.fp.cram)) + */ + __pyx_t_3 = ((__pyx_v_self->htsfile->format.format == cram) != 0); + if (likely(__pyx_t_3)) { + + /* "pysam/libchtslib.pyx":515 + * ret = hts_utell(self.htsfile) + * elif self.htsfile.format.format == cram: + * with nogil: # <<<<<<<<<<<<<< + * ret = htell(cram_fd_get_fp(self.htsfile.fp.cram)) + * else: + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libchtslib.pyx":516 + * elif self.htsfile.format.format == cram: + * with nogil: + * ret = htell(cram_fd_get_fp(self.htsfile.fp.cram)) # <<<<<<<<<<<<<< + * else: + * raise NotImplementedError("seek not implemented in files compressed by method {}".format( + */ + __pyx_v_ret = htell(cram_fd_get_fp(__pyx_v_self->htsfile->fp.cram)); + } + + /* "pysam/libchtslib.pyx":515 + * ret = hts_utell(self.htsfile) + * elif self.htsfile.format.format == cram: + * with nogil: # <<<<<<<<<<<<<< + * ret = htell(cram_fd_get_fp(self.htsfile.fp.cram)) + * else: + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L14; + } + __pyx_L14:; + } + } + + /* "pysam/libchtslib.pyx":514 + * with nogil: + * ret = hts_utell(self.htsfile) + * elif self.htsfile.format.format == cram: # <<<<<<<<<<<<<< + * with nogil: + * ret = htell(cram_fd_get_fp(self.htsfile.fp.cram)) + */ + goto __pyx_L5; + } + + /* "pysam/libchtslib.pyx":518 + * ret = htell(cram_fd_get_fp(self.htsfile.fp.cram)) + * else: + * raise NotImplementedError("seek not implemented in files compressed by method {}".format( # <<<<<<<<<<<<<< + * self.htsfile.format.compression)) + * + */ + /*else*/ { + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_seek_not_implemented_in_files_co, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 518, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pysam/libchtslib.pyx":519 + * else: + * raise NotImplementedError("seek not implemented in files compressed by method {}".format( + * self.htsfile.format.compression)) # <<<<<<<<<<<<<< + * + * return ret + */ + __pyx_t_5 = __Pyx_PyInt_From_enum__htsCompression(__pyx_v_self->htsfile->format.compression); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_6) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 518, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 518, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 518, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 518, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 518, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libchtslib.pyx":518 + * ret = htell(cram_fd_get_fp(self.htsfile.fp.cram)) + * else: + * raise NotImplementedError("seek not implemented in files compressed by method {}".format( # <<<<<<<<<<<<<< + * self.htsfile.format.compression)) + * + */ + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_NotImplementedError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 518, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 518, __pyx_L1_error) + } + __pyx_L5:; + + /* "pysam/libchtslib.pyx":521 + * self.htsfile.format.compression)) + * + * return ret # <<<<<<<<<<<<<< + * + * cdef htsFile *_open_htsfile(self) except? NULL: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyInt_From_int64_t(__pyx_v_ret); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":500 + * return ret + * + * def tell(self): # <<<<<<<<<<<<<< + * """return current file position, see :meth:`pysam.HTSFile.seek`.""" + * if not self.is_open: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.tell", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":523 + * return ret + * + * cdef htsFile *_open_htsfile(self) except? NULL: # <<<<<<<<<<<<<< + * cdef char *cfilename + * cdef char *cmode = self.mode + */ + +static htsFile *__pyx_f_5pysam_10libchtslib_7HTSFile__open_htsfile(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + char *__pyx_v_cfilename; + char *__pyx_v_cmode; + int __pyx_v_fd; + int __pyx_v_dup_fd; + int __pyx_v_threads; + htsFile *__pyx_v_htsfile; + PyObject *__pyx_v_smode = NULL; + hFILE *__pyx_v_hfile; + PyObject *__pyx_v_filename = NULL; + htsFile *__pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + char *__pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + __Pyx_RefNannySetupContext("_open_htsfile", 0); + __Pyx_TraceCall("_open_htsfile", __pyx_f[0], 523, 0, __PYX_ERR(0, 523, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":525 + * cdef htsFile *_open_htsfile(self) except? NULL: + * cdef char *cfilename + * cdef char *cmode = self.mode # <<<<<<<<<<<<<< + * cdef int fd, dup_fd, threads + * + */ + __pyx_t_1 = __Pyx_PyObject_AsWritableString(__pyx_v_self->mode); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 525, __pyx_L1_error) + __pyx_v_cmode = __pyx_t_1; + + /* "pysam/libchtslib.pyx":528 + * cdef int fd, dup_fd, threads + * + * threads = self.threads - 1 # <<<<<<<<<<<<<< + * if isinstance(self.filename, bytes): + * cfilename = self.filename + */ + __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_v_self->threads, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 528, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 528, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_threads = __pyx_t_3; + + /* "pysam/libchtslib.pyx":529 + * + * threads = self.threads - 1 + * if isinstance(self.filename, bytes): # <<<<<<<<<<<<<< + * cfilename = self.filename + * with nogil: + */ + __pyx_t_2 = __pyx_v_self->filename; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_4 = PyBytes_Check(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { + + /* "pysam/libchtslib.pyx":530 + * threads = self.threads - 1 + * if isinstance(self.filename, bytes): + * cfilename = self.filename # <<<<<<<<<<<<<< + * with nogil: + * htsfile = hts_open(cfilename, cmode) + */ + __pyx_t_1 = __Pyx_PyObject_AsWritableString(__pyx_v_self->filename); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 530, __pyx_L1_error) + __pyx_v_cfilename = __pyx_t_1; + + /* "pysam/libchtslib.pyx":531 + * if isinstance(self.filename, bytes): + * cfilename = self.filename + * with nogil: # <<<<<<<<<<<<<< + * htsfile = hts_open(cfilename, cmode) + * if htsfile != NULL: + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libchtslib.pyx":532 + * cfilename = self.filename + * with nogil: + * htsfile = hts_open(cfilename, cmode) # <<<<<<<<<<<<<< + * if htsfile != NULL: + * hts_set_threads(htsfile, threads) + */ + __pyx_v_htsfile = hts_open(__pyx_v_cfilename, __pyx_v_cmode); + + /* "pysam/libchtslib.pyx":533 + * with nogil: + * htsfile = hts_open(cfilename, cmode) + * if htsfile != NULL: # <<<<<<<<<<<<<< + * hts_set_threads(htsfile, threads) + * return htsfile + */ + __pyx_t_5 = ((__pyx_v_htsfile != NULL) != 0); + if (__pyx_t_5) { + + /* "pysam/libchtslib.pyx":534 + * htsfile = hts_open(cfilename, cmode) + * if htsfile != NULL: + * hts_set_threads(htsfile, threads) # <<<<<<<<<<<<<< + * return htsfile + * else: + */ + (void)(hts_set_threads(__pyx_v_htsfile, __pyx_v_threads)); + + /* "pysam/libchtslib.pyx":533 + * with nogil: + * htsfile = hts_open(cfilename, cmode) + * if htsfile != NULL: # <<<<<<<<<<<<<< + * hts_set_threads(htsfile, threads) + * return htsfile + */ + } + + /* "pysam/libchtslib.pyx":535 + * if htsfile != NULL: + * hts_set_threads(htsfile, threads) + * return htsfile # <<<<<<<<<<<<<< + * else: + * if isinstance(self.filename, int): + */ + __pyx_r = __pyx_v_htsfile; + goto __pyx_L4_return; + } + + /* "pysam/libchtslib.pyx":531 + * if isinstance(self.filename, bytes): + * cfilename = self.filename + * with nogil: # <<<<<<<<<<<<<< + * htsfile = hts_open(cfilename, cmode) + * if htsfile != NULL: + */ + /*finally:*/ { + __pyx_L4_return: { + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L0; + } + } + } + + /* "pysam/libchtslib.pyx":529 + * + * threads = self.threads - 1 + * if isinstance(self.filename, bytes): # <<<<<<<<<<<<<< + * cfilename = self.filename + * with nogil: + */ + } + + /* "pysam/libchtslib.pyx":537 + * return htsfile + * else: + * if isinstance(self.filename, int): # <<<<<<<<<<<<<< + * fd = self.filename + * else: + */ + /*else*/ { + __pyx_t_2 = __pyx_v_self->filename; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_5 = PyInt_Check(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = (__pyx_t_5 != 0); + if (__pyx_t_4) { + + /* "pysam/libchtslib.pyx":538 + * else: + * if isinstance(self.filename, int): + * fd = self.filename # <<<<<<<<<<<<<< + * else: + * fd = self.filename.fileno() + */ + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_self->filename); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 538, __pyx_L1_error) + __pyx_v_fd = __pyx_t_3; + + /* "pysam/libchtslib.pyx":537 + * return htsfile + * else: + * if isinstance(self.filename, int): # <<<<<<<<<<<<<< + * fd = self.filename + * else: + */ + goto __pyx_L8; + } + + /* "pysam/libchtslib.pyx":540 + * fd = self.filename + * else: + * fd = self.filename.fileno() # <<<<<<<<<<<<<< + * + * if self.duplicate_filehandle: + */ + /*else*/ { + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->filename, __pyx_n_s_fileno); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + if (__pyx_t_7) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 540, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_fd = __pyx_t_3; + } + __pyx_L8:; + + /* "pysam/libchtslib.pyx":542 + * fd = self.filename.fileno() + * + * if self.duplicate_filehandle: # <<<<<<<<<<<<<< + * dup_fd = dup(fd) + * else: + */ + __pyx_t_4 = (__pyx_v_self->duplicate_filehandle != 0); + if (__pyx_t_4) { + + /* "pysam/libchtslib.pyx":543 + * + * if self.duplicate_filehandle: + * dup_fd = dup(fd) # <<<<<<<<<<<<<< + * else: + * dup_fd = fd + */ + __pyx_v_dup_fd = dup(__pyx_v_fd); + + /* "pysam/libchtslib.pyx":542 + * fd = self.filename.fileno() + * + * if self.duplicate_filehandle: # <<<<<<<<<<<<<< + * dup_fd = dup(fd) + * else: + */ + goto __pyx_L9; + } + + /* "pysam/libchtslib.pyx":545 + * dup_fd = dup(fd) + * else: + * dup_fd = fd # <<<<<<<<<<<<<< + * + * # Replicate mode normalization done in hts_open_format + */ + /*else*/ { + __pyx_v_dup_fd = __pyx_v_fd; + } + __pyx_L9:; + + /* "pysam/libchtslib.pyx":548 + * + * # Replicate mode normalization done in hts_open_format + * smode = self.mode.replace(b'b', b'').replace(b'c', b'') # <<<<<<<<<<<<<< + * if b'b' in self.mode: + * smode += b'b' + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->mode, __pyx_n_s_replace); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 548, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 548, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_replace); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 548, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 548, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_smode = __pyx_t_6; + __pyx_t_6 = 0; + + /* "pysam/libchtslib.pyx":549 + * # Replicate mode normalization done in hts_open_format + * smode = self.mode.replace(b'b', b'').replace(b'c', b'') + * if b'b' in self.mode: # <<<<<<<<<<<<<< + * smode += b'b' + * elif b'c' in self.mode: + */ + __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_n_b_b, __pyx_v_self->mode, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 549, __pyx_L1_error) + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { + + /* "pysam/libchtslib.pyx":550 + * smode = self.mode.replace(b'b', b'').replace(b'c', b'') + * if b'b' in self.mode: + * smode += b'b' # <<<<<<<<<<<<<< + * elif b'c' in self.mode: + * smode += b'c' + */ + __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_v_smode, __pyx_n_b_b); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 550, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF_SET(__pyx_v_smode, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libchtslib.pyx":549 + * # Replicate mode normalization done in hts_open_format + * smode = self.mode.replace(b'b', b'').replace(b'c', b'') + * if b'b' in self.mode: # <<<<<<<<<<<<<< + * smode += b'b' + * elif b'c' in self.mode: + */ + goto __pyx_L10; + } + + /* "pysam/libchtslib.pyx":551 + * if b'b' in self.mode: + * smode += b'b' + * elif b'c' in self.mode: # <<<<<<<<<<<<<< + * smode += b'c' + * cmode = smode + */ + __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_n_b_c, __pyx_v_self->mode, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 551, __pyx_L1_error) + __pyx_t_4 = (__pyx_t_5 != 0); + if (__pyx_t_4) { + + /* "pysam/libchtslib.pyx":552 + * smode += b'b' + * elif b'c' in self.mode: + * smode += b'c' # <<<<<<<<<<<<<< + * cmode = smode + * + */ + __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_v_smode, __pyx_n_b_c); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 552, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF_SET(__pyx_v_smode, __pyx_t_6); + __pyx_t_6 = 0; + + /* "pysam/libchtslib.pyx":551 + * if b'b' in self.mode: + * smode += b'b' + * elif b'c' in self.mode: # <<<<<<<<<<<<<< + * smode += b'c' + * cmode = smode + */ + } + __pyx_L10:; + + /* "pysam/libchtslib.pyx":553 + * elif b'c' in self.mode: + * smode += b'c' + * cmode = smode # <<<<<<<<<<<<<< + * + * hfile = hdopen(dup_fd, cmode) + */ + __pyx_t_1 = __Pyx_PyObject_AsWritableString(__pyx_v_smode); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 553, __pyx_L1_error) + __pyx_v_cmode = __pyx_t_1; + + /* "pysam/libchtslib.pyx":555 + * cmode = smode + * + * hfile = hdopen(dup_fd, cmode) # <<<<<<<<<<<<<< + * if hfile == NULL: + * raise IOError('Cannot create hfile') + */ + __pyx_v_hfile = hdopen(__pyx_v_dup_fd, __pyx_v_cmode); + + /* "pysam/libchtslib.pyx":556 + * + * hfile = hdopen(dup_fd, cmode) + * if hfile == NULL: # <<<<<<<<<<<<<< + * raise IOError('Cannot create hfile') + * + */ + __pyx_t_4 = ((__pyx_v_hfile == NULL) != 0); + if (unlikely(__pyx_t_4)) { + + /* "pysam/libchtslib.pyx":557 + * hfile = hdopen(dup_fd, cmode) + * if hfile == NULL: + * raise IOError('Cannot create hfile') # <<<<<<<<<<<<<< + * + * try: + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __PYX_ERR(0, 557, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":556 + * + * hfile = hdopen(dup_fd, cmode) + * if hfile == NULL: # <<<<<<<<<<<<<< + * raise IOError('Cannot create hfile') + * + */ + } + + /* "pysam/libchtslib.pyx":559 + * raise IOError('Cannot create hfile') + * + * try: # <<<<<<<<<<<<<< + * # filename.name can be an int + * filename = str(self.filename.name) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_10); + /*try:*/ { + + /* "pysam/libchtslib.pyx":561 + * try: + * # filename.name can be an int + * filename = str(self.filename.name) # <<<<<<<<<<<<<< + * except AttributeError: + * filename = ''.format(fd) + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->filename, __pyx_n_s_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 561, __pyx_L12_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 561, __pyx_L12_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_filename = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pysam/libchtslib.pyx":559 + * raise IOError('Cannot create hfile') + * + * try: # <<<<<<<<<<<<<< + * # filename.name can be an int + * filename = str(self.filename.name) + */ + } + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L17_try_end; + __pyx_L12_error:; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libchtslib.pyx":562 + * # filename.name can be an int + * filename = str(self.filename.name) + * except AttributeError: # <<<<<<<<<<<<<< + * filename = ''.format(fd) + * + */ + __pyx_t_3 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError); + if (__pyx_t_3) { + __Pyx_AddTraceback("pysam.libchtslib.HTSFile._open_htsfile", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 562, __pyx_L14_except_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); + + /* "pysam/libchtslib.pyx":563 + * filename = str(self.filename.name) + * except AttributeError: + * filename = ''.format(fd) # <<<<<<<<<<<<<< + * + * filename = encode_filename(filename) + */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_fd, __pyx_n_s_format); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 563, __pyx_L14_except_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_fd); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 563, __pyx_L14_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + if (!__pyx_t_14) { + __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_13); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 563, __pyx_L14_except_error) + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_11); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_12)) { + PyObject *__pyx_temp[2] = {__pyx_t_14, __pyx_t_13}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 563, __pyx_L14_except_error) + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { + PyObject *__pyx_temp[2] = {__pyx_t_14, __pyx_t_13}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 563, __pyx_L14_except_error) + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } else + #endif + { + __pyx_t_15 = PyTuple_New(1+1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 563, __pyx_L14_except_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); __pyx_t_14 = NULL; + __Pyx_GIVEREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_15, 0+1, __pyx_t_13); + __pyx_t_13 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_15, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 563, __pyx_L14_except_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + } + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF_SET(__pyx_v_filename, __pyx_t_11); + __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L13_exception_handled; + } + goto __pyx_L14_except_error; + __pyx_L14_except_error:; + + /* "pysam/libchtslib.pyx":559 + * raise IOError('Cannot create hfile') + * + * try: # <<<<<<<<<<<<<< + * # filename.name can be an int + * filename = str(self.filename.name) + */ + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); + goto __pyx_L1_error; + __pyx_L13_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); + __pyx_L17_try_end:; + } + + /* "pysam/libchtslib.pyx":565 + * filename = ''.format(fd) + * + * filename = encode_filename(filename) # <<<<<<<<<<<<<< + * cfilename = filename + * with nogil: + */ + __pyx_t_7 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 565, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF_SET(__pyx_v_filename, __pyx_t_7); + __pyx_t_7 = 0; + + /* "pysam/libchtslib.pyx":566 + * + * filename = encode_filename(filename) + * cfilename = filename # <<<<<<<<<<<<<< + * with nogil: + * htsfile = hts_hopen(hfile, cfilename, cmode) + */ + __pyx_t_1 = __Pyx_PyObject_AsWritableString(__pyx_v_filename); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 566, __pyx_L1_error) + __pyx_v_cfilename = __pyx_t_1; + + /* "pysam/libchtslib.pyx":567 + * filename = encode_filename(filename) + * cfilename = filename + * with nogil: # <<<<<<<<<<<<<< + * htsfile = hts_hopen(hfile, cfilename, cmode) + * if htsfile != NULL: + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libchtslib.pyx":568 + * cfilename = filename + * with nogil: + * htsfile = hts_hopen(hfile, cfilename, cmode) # <<<<<<<<<<<<<< + * if htsfile != NULL: + * hts_set_threads(htsfile, threads) + */ + __pyx_v_htsfile = hts_hopen(__pyx_v_hfile, __pyx_v_cfilename, __pyx_v_cmode); + + /* "pysam/libchtslib.pyx":569 + * with nogil: + * htsfile = hts_hopen(hfile, cfilename, cmode) + * if htsfile != NULL: # <<<<<<<<<<<<<< + * hts_set_threads(htsfile, threads) + * return htsfile + */ + __pyx_t_4 = ((__pyx_v_htsfile != NULL) != 0); + if (__pyx_t_4) { + + /* "pysam/libchtslib.pyx":570 + * htsfile = hts_hopen(hfile, cfilename, cmode) + * if htsfile != NULL: + * hts_set_threads(htsfile, threads) # <<<<<<<<<<<<<< + * return htsfile + * + */ + (void)(hts_set_threads(__pyx_v_htsfile, __pyx_v_threads)); + + /* "pysam/libchtslib.pyx":569 + * with nogil: + * htsfile = hts_hopen(hfile, cfilename, cmode) + * if htsfile != NULL: # <<<<<<<<<<<<<< + * hts_set_threads(htsfile, threads) + * return htsfile + */ + } + + /* "pysam/libchtslib.pyx":571 + * if htsfile != NULL: + * hts_set_threads(htsfile, threads) + * return htsfile # <<<<<<<<<<<<<< + * + * def add_hts_options(self, format_options=None): + */ + __pyx_r = __pyx_v_htsfile; + goto __pyx_L20_return; + } + + /* "pysam/libchtslib.pyx":567 + * filename = encode_filename(filename) + * cfilename = filename + * with nogil: # <<<<<<<<<<<<<< + * htsfile = hts_hopen(hfile, cfilename, cmode) + * if htsfile != NULL: + */ + /*finally:*/ { + __pyx_L20_return: { + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L0; + } + } + } + } + + /* "pysam/libchtslib.pyx":523 + * return ret + * + * cdef htsFile *_open_htsfile(self) except? NULL: # <<<<<<<<<<<<<< + * cdef char *cfilename + * cdef char *cmode = self.mode + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_15); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile._open_htsfile", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_smode); + __Pyx_XDECREF(__pyx_v_filename); + __Pyx_TraceReturn(Py_None, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":573 + * return htsfile + * + * def add_hts_options(self, format_options=None): # <<<<<<<<<<<<<< + * """Given a list of key=value format option strings, add them to an open htsFile + * """ + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_19add_hts_options(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_18add_hts_options[] = "HTSFile.add_hts_options(self, format_options=None)\nGiven a list of key=value format option strings, add them to an open htsFile\n "; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_19add_hts_options(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_format_options = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_hts_options (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_format_options,0}; + PyObject* values[1] = {0}; + values[0] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format_options); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_hts_options") < 0)) __PYX_ERR(0, 573, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_format_options = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("add_hts_options", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 573, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.add_hts_options", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_18add_hts_options(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), __pyx_v_format_options); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_18add_hts_options(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, PyObject *__pyx_v_format_options) { + int __pyx_v_rval; + hts_opt *__pyx_v_opts; + PyObject *__pyx_v_format_option = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + char const *__pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("add_hts_options", 0); + __Pyx_TraceCall("add_hts_options", __pyx_f[0], 573, 0, __PYX_ERR(0, 573, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":577 + * """ + * cdef int rval + * cdef hts_opt *opts = NULL # <<<<<<<<<<<<<< + * + * if format_options: + */ + __pyx_v_opts = NULL; + + /* "pysam/libchtslib.pyx":579 + * cdef hts_opt *opts = NULL + * + * if format_options: # <<<<<<<<<<<<<< + * for format_option in format_options: + * rval = hts_opt_add(&opts, format_option) + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_format_options); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 579, __pyx_L1_error) + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":580 + * + * if format_options: + * for format_option in format_options: # <<<<<<<<<<<<<< + * rval = hts_opt_add(&opts, format_option) + * if rval != 0: + */ + if (likely(PyList_CheckExact(__pyx_v_format_options)) || PyTuple_CheckExact(__pyx_v_format_options)) { + __pyx_t_2 = __pyx_v_format_options; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_format_options); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 580, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 580, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_4)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 580, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 580, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } else { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 580, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 580, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } + } else { + __pyx_t_5 = __pyx_t_4(__pyx_t_2); + if (unlikely(!__pyx_t_5)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 580, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XDECREF_SET(__pyx_v_format_option, __pyx_t_5); + __pyx_t_5 = 0; + + /* "pysam/libchtslib.pyx":581 + * if format_options: + * for format_option in format_options: + * rval = hts_opt_add(&opts, format_option) # <<<<<<<<<<<<<< + * if rval != 0: + * if opts != NULL: + */ + __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_format_option); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 581, __pyx_L1_error) + __pyx_v_rval = hts_opt_add((&__pyx_v_opts), __pyx_t_6); + + /* "pysam/libchtslib.pyx":582 + * for format_option in format_options: + * rval = hts_opt_add(&opts, format_option) + * if rval != 0: # <<<<<<<<<<<<<< + * if opts != NULL: + * hts_opt_free(opts) + */ + __pyx_t_1 = ((__pyx_v_rval != 0) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":583 + * rval = hts_opt_add(&opts, format_option) + * if rval != 0: + * if opts != NULL: # <<<<<<<<<<<<<< + * hts_opt_free(opts) + * raise RuntimeError('Invalid format option ({}) specified'.format(format_option)) + */ + __pyx_t_1 = ((__pyx_v_opts != NULL) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":584 + * if rval != 0: + * if opts != NULL: + * hts_opt_free(opts) # <<<<<<<<<<<<<< + * raise RuntimeError('Invalid format option ({}) specified'.format(format_option)) + * if opts != NULL: + */ + hts_opt_free(__pyx_v_opts); + + /* "pysam/libchtslib.pyx":583 + * rval = hts_opt_add(&opts, format_option) + * if rval != 0: + * if opts != NULL: # <<<<<<<<<<<<<< + * hts_opt_free(opts) + * raise RuntimeError('Invalid format option ({}) specified'.format(format_option)) + */ + } + + /* "pysam/libchtslib.pyx":585 + * if opts != NULL: + * hts_opt_free(opts) + * raise RuntimeError('Invalid format option ({}) specified'.format(format_option)) # <<<<<<<<<<<<<< + * if opts != NULL: + * rval = hts_opt_apply(self.htsfile, opts) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Invalid_format_option_specified, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_8) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_format_option); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_format_option}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 585, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_format_option}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 585, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_INCREF(__pyx_v_format_option); + __Pyx_GIVEREF(__pyx_v_format_option); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_format_option); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_RuntimeError, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 585, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 585, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":582 + * for format_option in format_options: + * rval = hts_opt_add(&opts, format_option) + * if rval != 0: # <<<<<<<<<<<<<< + * if opts != NULL: + * hts_opt_free(opts) + */ + } + + /* "pysam/libchtslib.pyx":580 * + * if format_options: + * for format_option in format_options: # <<<<<<<<<<<<<< + * rval = hts_opt_add(&opts, format_option) + * if rval != 0: */ - __pyx_t_3 = (__pyx_v_self->is_stream != 0); - if (unlikely(__pyx_t_3)) { + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libchtslib.pyx":205 - * raise ValueError('I/O operation on closed file') - * if self.is_stream: - * raise OSError('tell not available in streams') # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":586 + * hts_opt_free(opts) + * raise RuntimeError('Invalid format option ({}) specified'.format(format_option)) + * if opts != NULL: # <<<<<<<<<<<<<< + * rval = hts_opt_apply(self.htsfile, opts) + * if rval != 0: + */ + __pyx_t_1 = ((__pyx_v_opts != NULL) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":587 + * raise RuntimeError('Invalid format option ({}) specified'.format(format_option)) + * if opts != NULL: + * rval = hts_opt_apply(self.htsfile, opts) # <<<<<<<<<<<<<< + * if rval != 0: + * hts_opt_free(opts) + */ + __pyx_v_rval = hts_opt_apply(__pyx_v_self->htsfile, __pyx_v_opts); + + /* "pysam/libchtslib.pyx":588 + * if opts != NULL: + * rval = hts_opt_apply(self.htsfile, opts) + * if rval != 0: # <<<<<<<<<<<<<< + * hts_opt_free(opts) + * raise RuntimeError('An error occured while applying the requested format options') + */ + __pyx_t_1 = ((__pyx_v_rval != 0) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":589 + * rval = hts_opt_apply(self.htsfile, opts) + * if rval != 0: + * hts_opt_free(opts) # <<<<<<<<<<<<<< + * raise RuntimeError('An error occured while applying the requested format options') + * hts_opt_free(opts) + */ + hts_opt_free(__pyx_v_opts); + + /* "pysam/libchtslib.pyx":590 + * if rval != 0: + * hts_opt_free(opts) + * raise RuntimeError('An error occured while applying the requested format options') # <<<<<<<<<<<<<< + * hts_opt_free(opts) * - * cdef int64_t ret */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 205, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 590, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 590, __pyx_L1_error) - /* "pysam/libchtslib.pyx":204 - * if not self.is_open: - * raise ValueError('I/O operation on closed file') - * if self.is_stream: # <<<<<<<<<<<<<< - * raise OSError('tell not available in streams') + /* "pysam/libchtslib.pyx":588 + * if opts != NULL: + * rval = hts_opt_apply(self.htsfile, opts) + * if rval != 0: # <<<<<<<<<<<<<< + * hts_opt_free(opts) + * raise RuntimeError('An error occured while applying the requested format options') + */ + } + + /* "pysam/libchtslib.pyx":591 + * hts_opt_free(opts) + * raise RuntimeError('An error occured while applying the requested format options') + * hts_opt_free(opts) # <<<<<<<<<<<<<< + * + * def parse_region(self, contig=None, start=None, stop=None, region=None,tid=None, + */ + hts_opt_free(__pyx_v_opts); + + /* "pysam/libchtslib.pyx":586 + * hts_opt_free(opts) + * raise RuntimeError('Invalid format option ({}) specified'.format(format_option)) + * if opts != NULL: # <<<<<<<<<<<<<< + * rval = hts_opt_apply(self.htsfile, opts) + * if rval != 0: + */ + } + + /* "pysam/libchtslib.pyx":579 + * cdef hts_opt *opts = NULL * + * if format_options: # <<<<<<<<<<<<<< + * for format_option in format_options: + * rval = hts_opt_add(&opts, format_option) */ } - /* "pysam/libchtslib.pyx":208 + /* "pysam/libchtslib.pyx":573 + * return htsfile * - * cdef int64_t ret - * if self.htsfile.format.compression != no_compression: # <<<<<<<<<<<<<< - * with nogil: - * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) + * def add_hts_options(self, format_options=None): # <<<<<<<<<<<<<< + * """Given a list of key=value format option strings, add them to an open htsFile + * """ */ - __pyx_t_3 = ((__pyx_v_self->htsfile->format.compression != no_compression) != 0); - if (__pyx_t_3) { - /* "pysam/libchtslib.pyx":209 - * cdef int64_t ret - * if self.htsfile.format.compression != no_compression: - * with nogil: # <<<<<<<<<<<<<< - * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) - * else: + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.add_hts_options", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_format_option); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":593 + * hts_opt_free(opts) + * + * def parse_region(self, contig=None, start=None, stop=None, region=None,tid=None, # <<<<<<<<<<<<<< + * reference=None, end=None): + * """parse alternative ways to specify a genomic region. A region can */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { - /* "pysam/libchtslib.pyx":210 - * if self.htsfile.format.compression != no_compression: - * with nogil: - * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) # <<<<<<<<<<<<<< - * else: - * with nogil: +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_21parse_region(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_20parse_region[] = "HTSFile.parse_region(self, contig=None, start=None, stop=None, region=None, tid=None, reference=None, end=None)\nparse alternative ways to specify a genomic region. A region can\n either be specified by :term:`contig`, `start` and\n `stop`. `start` and `stop` denote 0-based, half-open\n intervals. :term:`reference` and `end` are also accepted for\n backward compatiblity as synonyms for :term:`contig` and\n `stop`, respectively.\n\n Alternatively, a samtools :term:`region` string can be\n supplied.\n\n If any of the coordinates are missing they will be replaced by\n the minimum (`start`) or maximum (`stop`) coordinate.\n\n Note that region strings are 1-based inclusive, while `start`\n and `stop` denote an interval in 0-based, half-open\n coordinates (like BED files and Python slices).\n\n If `contig` or `region` or are ``*``, unmapped reads at the end\n of a BAM file will be returned. Setting either to ``.`` will\n iterate from the beginning of the file.\n\n Returns\n -------\n\n tuple : a tuple of `flag`, :term:`tid`, `start` and\n `stop`. The flag indicates whether no coordinates were\n supplied and the genomic region is the complete genomic space.\n\n Raises\n ------\n\n ValueError\n for invalid or out of bounds regions.\n\n "; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_21parse_region(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_contig = 0; + PyObject *__pyx_v_start = 0; + PyObject *__pyx_v_stop = 0; + PyObject *__pyx_v_region = 0; + PyObject *__pyx_v_tid = 0; + PyObject *__pyx_v_reference = 0; + PyObject *__pyx_v_end = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("parse_region (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_tid,&__pyx_n_s_reference,&__pyx_n_s_end,0}; + PyObject* values[7] = {0,0,0,0,0,0,0}; + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)Py_None); + values[2] = ((PyObject *)Py_None); + values[3] = ((PyObject *)Py_None); + values[4] = ((PyObject *)Py_None); + + /* "pysam/libchtslib.pyx":594 + * + * def parse_region(self, contig=None, start=None, stop=None, region=None,tid=None, + * reference=None, end=None): # <<<<<<<<<<<<<< + * """parse alternative ways to specify a genomic region. A region can + * either be specified by :term:`contig`, `start` and */ - __pyx_v_ret = bgzf_tell(hts_get_bgzfp(__pyx_v_self->htsfile)); + values[5] = ((PyObject *)Py_None); + values[6] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_contig); + if (value) { values[0] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start); + if (value) { values[1] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stop); + if (value) { values[2] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region); + if (value) { values[3] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 4: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tid); + if (value) { values[4] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 5: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); + if (value) { values[5] = value; kw_args--; } } + CYTHON_FALLTHROUGH; + case 6: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); + if (value) { values[6] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "parse_region") < 0)) __PYX_ERR(0, 593, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_contig = values[0]; + __pyx_v_start = values[1]; + __pyx_v_stop = values[2]; + __pyx_v_region = values[3]; + __pyx_v_tid = values[4]; + __pyx_v_reference = values[5]; + __pyx_v_end = values[6]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("parse_region", 0, 0, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 593, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.parse_region", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_20parse_region(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_tid, __pyx_v_reference, __pyx_v_end); - /* "pysam/libchtslib.pyx":209 - * cdef int64_t ret - * if self.htsfile.format.compression != no_compression: - * with nogil: # <<<<<<<<<<<<<< - * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) - * else: + /* "pysam/libchtslib.pyx":593 + * hts_opt_free(opts) + * + * def parse_region(self, contig=None, start=None, stop=None, region=None,tid=None, # <<<<<<<<<<<<<< + * reference=None, end=None): + * """parse alternative ways to specify a genomic region. A region can + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_20parse_region(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_reference, PyObject *__pyx_v_end) { + int __pyx_v_rtid; + PY_LONG_LONG __pyx_v_rstart; + PY_LONG_LONG __pyx_v_rstop; + PyObject *__pyx_v_parts = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PY_LONG_LONG __pyx_t_8; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + Py_ssize_t __pyx_t_14; + __Pyx_RefNannySetupContext("parse_region", 0); + __Pyx_TraceCall("parse_region", __pyx_f[0], 593, 0, __PYX_ERR(0, 593, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_contig); + __Pyx_INCREF(__pyx_v_stop); + __Pyx_INCREF(__pyx_v_region); + + /* "pysam/libchtslib.pyx":634 + * cdef long long rstop + * + * if reference is not None: # <<<<<<<<<<<<<< + * if contig is not None: + * raise ValueError('contig and reference should not both be specified') + */ + __pyx_t_1 = (__pyx_v_reference != Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "pysam/libchtslib.pyx":635 + * + * if reference is not None: + * if contig is not None: # <<<<<<<<<<<<<< + * raise ValueError('contig and reference should not both be specified') + * contig = reference + */ + __pyx_t_2 = (__pyx_v_contig != Py_None); + __pyx_t_1 = (__pyx_t_2 != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":636 + * if reference is not None: + * if contig is not None: + * raise ValueError('contig and reference should not both be specified') # <<<<<<<<<<<<<< + * contig = reference + * + */ + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 636, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 636, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":635 + * + * if reference is not None: + * if contig is not None: # <<<<<<<<<<<<<< + * raise ValueError('contig and reference should not both be specified') + * contig = reference */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L8; - } - __pyx_L8:; - } } - /* "pysam/libchtslib.pyx":208 + /* "pysam/libchtslib.pyx":637 + * if contig is not None: + * raise ValueError('contig and reference should not both be specified') + * contig = reference # <<<<<<<<<<<<<< * - * cdef int64_t ret - * if self.htsfile.format.compression != no_compression: # <<<<<<<<<<<<<< - * with nogil: - * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) + * if end is not None: + */ + __Pyx_INCREF(__pyx_v_reference); + __Pyx_DECREF_SET(__pyx_v_contig, __pyx_v_reference); + + /* "pysam/libchtslib.pyx":634 + * cdef long long rstop + * + * if reference is not None: # <<<<<<<<<<<<<< + * if contig is not None: + * raise ValueError('contig and reference should not both be specified') */ - goto __pyx_L5; } - /* "pysam/libchtslib.pyx":212 - * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) - * else: - * with nogil: # <<<<<<<<<<<<<< - * ret = hts_utell(self.htsfile) - * return ret + /* "pysam/libchtslib.pyx":639 + * contig = reference + * + * if end is not None: # <<<<<<<<<<<<<< + * if stop is not None: + * raise ValueError('stop and end should not both be specified') */ - /*else*/ { - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + __pyx_t_1 = (__pyx_v_end != Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { - /* "pysam/libchtslib.pyx":213 - * else: - * with nogil: - * ret = hts_utell(self.htsfile) # <<<<<<<<<<<<<< - * return ret + /* "pysam/libchtslib.pyx":640 + * + * if end is not None: + * if stop is not None: # <<<<<<<<<<<<<< + * raise ValueError('stop and end should not both be specified') + * stop = end + */ + __pyx_t_2 = (__pyx_v_stop != Py_None); + __pyx_t_1 = (__pyx_t_2 != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":641 + * if end is not None: + * if stop is not None: + * raise ValueError('stop and end should not both be specified') # <<<<<<<<<<<<<< + * stop = end * */ - __pyx_v_ret = hts_utell(__pyx_v_self->htsfile); - } + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 641, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 641, __pyx_L1_error) - /* "pysam/libchtslib.pyx":212 - * ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) - * else: - * with nogil: # <<<<<<<<<<<<<< - * ret = hts_utell(self.htsfile) - * return ret + /* "pysam/libchtslib.pyx":640 + * + * if end is not None: + * if stop is not None: # <<<<<<<<<<<<<< + * raise ValueError('stop and end should not both be specified') + * stop = end */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L11; - } - __pyx_L11:; - } } + + /* "pysam/libchtslib.pyx":642 + * if stop is not None: + * raise ValueError('stop and end should not both be specified') + * stop = end # <<<<<<<<<<<<<< + * + * if contig is None and tid is None and region is None: + */ + __Pyx_INCREF(__pyx_v_end); + __Pyx_DECREF_SET(__pyx_v_stop, __pyx_v_end); + + /* "pysam/libchtslib.pyx":639 + * contig = reference + * + * if end is not None: # <<<<<<<<<<<<<< + * if stop is not None: + * raise ValueError('stop and end should not both be specified') + */ } - __pyx_L5:; - /* "pysam/libchtslib.pyx":214 - * with nogil: - * ret = hts_utell(self.htsfile) - * return ret # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":644 + * stop = end + * + * if contig is None and tid is None and region is None: # <<<<<<<<<<<<<< + * return 0, 0, 0, 0 + * + */ + __pyx_t_2 = (__pyx_v_contig == Py_None); + __pyx_t_4 = (__pyx_t_2 != 0); + if (__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L8_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_tid == Py_None); + __pyx_t_2 = (__pyx_t_4 != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L8_bool_binop_done; + } + __pyx_t_2 = (__pyx_v_region == Py_None); + __pyx_t_4 = (__pyx_t_2 != 0); + __pyx_t_1 = __pyx_t_4; + __pyx_L8_bool_binop_done:; + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":645 * - * cdef htsFile *_open_htsfile(self) except? NULL: + * if contig is None and tid is None and region is None: + * return 0, 0, 0, 0 # <<<<<<<<<<<<<< + * + * rtid = -1 */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int64_t(__pyx_v_ret); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_tuple__35); + __pyx_r = __pyx_tuple__35; + goto __pyx_L0; - /* "pysam/libchtslib.pyx":200 - * return ret + /* "pysam/libchtslib.pyx":644 + * stop = end + * + * if contig is None and tid is None and region is None: # <<<<<<<<<<<<<< + * return 0, 0, 0, 0 * - * def tell(self): # <<<<<<<<<<<<<< - * """return current file position, see :meth:`pysam.HTSFile.seek`.""" - * if not self.is_open: */ + } - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile.tell", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libchtslib.pyx":216 - * return ret + /* "pysam/libchtslib.pyx":647 + * return 0, 0, 0, 0 * - * cdef htsFile *_open_htsfile(self) except? NULL: # <<<<<<<<<<<<<< - * cdef char *cfilename - * cdef char *cmode = self.mode + * rtid = -1 # <<<<<<<<<<<<<< + * rstart = 0 + * rstop = MAX_POS */ + __pyx_v_rtid = -1; -static htsFile *__pyx_f_5pysam_10libchtslib_7HTSFile__open_htsfile(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { - char *__pyx_v_cfilename; - char *__pyx_v_cmode; - int __pyx_v_fd; - int __pyx_v_dup_fd; - PyObject *__pyx_v_smode = NULL; - hFILE *__pyx_v_hfile; - PyObject *__pyx_v_filename = NULL; - htsFile *__pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - char *__pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - PyObject *__pyx_t_15 = NULL; - __Pyx_RefNannySetupContext("_open_htsfile", 0); - __Pyx_TraceCall("_open_htsfile", __pyx_f[0], 216, 0, __PYX_ERR(0, 216, __pyx_L1_error)); - - /* "pysam/libchtslib.pyx":218 - * cdef htsFile *_open_htsfile(self) except? NULL: - * cdef char *cfilename - * cdef char *cmode = self.mode # <<<<<<<<<<<<<< - * cdef int fd, dup_fd + /* "pysam/libchtslib.pyx":648 * + * rtid = -1 + * rstart = 0 # <<<<<<<<<<<<<< + * rstop = MAX_POS + * if start is not None: + */ + __pyx_v_rstart = 0; + + /* "pysam/libchtslib.pyx":649 + * rtid = -1 + * rstart = 0 + * rstop = MAX_POS # <<<<<<<<<<<<<< + * if start is not None: + * try: */ - __pyx_t_1 = __Pyx_PyObject_AsWritableString(__pyx_v_self->mode); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 218, __pyx_L1_error) - __pyx_v_cmode = __pyx_t_1; + __pyx_v_rstop = __pyx_v_5pysam_10libchtslib_MAX_POS; - /* "pysam/libchtslib.pyx":221 - * cdef int fd, dup_fd - * - * if isinstance(self.filename, bytes): # <<<<<<<<<<<<<< - * cfilename = self.filename - * with nogil: + /* "pysam/libchtslib.pyx":650 + * rstart = 0 + * rstop = MAX_POS + * if start is not None: # <<<<<<<<<<<<<< + * try: + * rstart = start */ - __pyx_t_2 = __pyx_v_self->filename; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = PyBytes_Check(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = (__pyx_t_3 != 0); + __pyx_t_1 = (__pyx_v_start != Py_None); + __pyx_t_4 = (__pyx_t_1 != 0); if (__pyx_t_4) { - /* "pysam/libchtslib.pyx":222 - * - * if isinstance(self.filename, bytes): - * cfilename = self.filename # <<<<<<<<<<<<<< - * with nogil: - * return hts_open(cfilename, cmode) + /* "pysam/libchtslib.pyx":651 + * rstop = MAX_POS + * if start is not None: + * try: # <<<<<<<<<<<<<< + * rstart = start + * except OverflowError: */ - __pyx_t_1 = __Pyx_PyObject_AsWritableString(__pyx_v_self->filename); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 222, __pyx_L1_error) - __pyx_v_cfilename = __pyx_t_1; + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { - /* "pysam/libchtslib.pyx":223 - * if isinstance(self.filename, bytes): - * cfilename = self.filename - * with nogil: # <<<<<<<<<<<<<< - * return hts_open(cfilename, cmode) - * else: + /* "pysam/libchtslib.pyx":652 + * if start is not None: + * try: + * rstart = start # <<<<<<<<<<<<<< + * except OverflowError: + * raise ValueError('start out of range (%i)' % start) */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + __pyx_t_8 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_start); if (unlikely((__pyx_t_8 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 652, __pyx_L12_error) + __pyx_v_rstart = __pyx_t_8; - /* "pysam/libchtslib.pyx":224 - * cfilename = self.filename - * with nogil: - * return hts_open(cfilename, cmode) # <<<<<<<<<<<<<< - * else: - * if isinstance(self.filename, int): + /* "pysam/libchtslib.pyx":651 + * rstop = MAX_POS + * if start is not None: + * try: # <<<<<<<<<<<<<< + * rstart = start + * except OverflowError: */ - __pyx_r = hts_open(__pyx_v_cfilename, __pyx_v_cmode); - goto __pyx_L4_return; - } + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L17_try_end; + __pyx_L12_error:; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libchtslib.pyx":223 - * if isinstance(self.filename, bytes): - * cfilename = self.filename - * with nogil: # <<<<<<<<<<<<<< - * return hts_open(cfilename, cmode) - * else: + /* "pysam/libchtslib.pyx":653 + * try: + * rstart = start + * except OverflowError: # <<<<<<<<<<<<<< + * raise ValueError('start out of range (%i)' % start) + * */ - /*finally:*/ { - __pyx_L4_return: { - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L0; - } - } + __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError); + if (__pyx_t_9) { + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.parse_region", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_10, &__pyx_t_11) < 0) __PYX_ERR(0, 653, __pyx_L14_except_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_t_11); + + /* "pysam/libchtslib.pyx":654 + * rstart = start + * except OverflowError: + * raise ValueError('start out of range (%i)' % start) # <<<<<<<<<<<<<< + * + * if stop is not None: + */ + __pyx_t_12 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_v_start); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 654, __pyx_L14_except_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 654, __pyx_L14_except_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_Raise(__pyx_t_13, 0, 0, 0); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __PYX_ERR(0, 654, __pyx_L14_except_error) + } + goto __pyx_L14_except_error; + __pyx_L14_except_error:; + + /* "pysam/libchtslib.pyx":651 + * rstop = MAX_POS + * if start is not None: + * try: # <<<<<<<<<<<<<< + * rstart = start + * except OverflowError: + */ + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L17_try_end:; } - /* "pysam/libchtslib.pyx":221 - * cdef int fd, dup_fd - * - * if isinstance(self.filename, bytes): # <<<<<<<<<<<<<< - * cfilename = self.filename - * with nogil: + /* "pysam/libchtslib.pyx":650 + * rstart = 0 + * rstop = MAX_POS + * if start is not None: # <<<<<<<<<<<<<< + * try: + * rstart = start */ } - /* "pysam/libchtslib.pyx":226 - * return hts_open(cfilename, cmode) - * else: - * if isinstance(self.filename, int): # <<<<<<<<<<<<<< - * fd = self.filename - * else: + /* "pysam/libchtslib.pyx":656 + * raise ValueError('start out of range (%i)' % start) + * + * if stop is not None: # <<<<<<<<<<<<<< + * try: + * rstop = stop */ - /*else*/ { - __pyx_t_2 = __pyx_v_self->filename; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_4 = PyInt_Check(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_3 = (__pyx_t_4 != 0); - if (__pyx_t_3) { + __pyx_t_4 = (__pyx_v_stop != Py_None); + __pyx_t_1 = (__pyx_t_4 != 0); + if (__pyx_t_1) { - /* "pysam/libchtslib.pyx":227 - * else: - * if isinstance(self.filename, int): - * fd = self.filename # <<<<<<<<<<<<<< - * else: - * fd = self.filename.fileno() + /* "pysam/libchtslib.pyx":657 + * + * if stop is not None: + * try: # <<<<<<<<<<<<<< + * rstop = stop + * except OverflowError: */ - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_v_self->filename); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 227, __pyx_L1_error) - __pyx_v_fd = __pyx_t_5; + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_6, &__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_5); + /*try:*/ { - /* "pysam/libchtslib.pyx":226 - * return hts_open(cfilename, cmode) - * else: - * if isinstance(self.filename, int): # <<<<<<<<<<<<<< - * fd = self.filename - * else: + /* "pysam/libchtslib.pyx":658 + * if stop is not None: + * try: + * rstop = stop # <<<<<<<<<<<<<< + * except OverflowError: + * raise ValueError('stop out of range (%i)' % stop) */ - goto __pyx_L7; - } + __pyx_t_8 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_stop); if (unlikely((__pyx_t_8 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 658, __pyx_L21_error) + __pyx_v_rstop = __pyx_t_8; - /* "pysam/libchtslib.pyx":229 - * fd = self.filename - * else: - * fd = self.filename.fileno() # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":657 * - * if self.duplicate_filehandle: + * if stop is not None: + * try: # <<<<<<<<<<<<<< + * rstop = stop + * except OverflowError: */ - /*else*/ { - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->filename, __pyx_n_s_fileno); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 229, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } } - if (__pyx_t_7) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 229, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 229, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L26_try_end; + __pyx_L21_error:; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + + /* "pysam/libchtslib.pyx":659 + * try: + * rstop = stop + * except OverflowError: # <<<<<<<<<<<<<< + * raise ValueError('stop out of range (%i)' % stop) + * + */ + __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError); + if (__pyx_t_9) { + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.parse_region", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_11, &__pyx_t_10, &__pyx_t_3) < 0) __PYX_ERR(0, 659, __pyx_L23_except_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_t_3); + + /* "pysam/libchtslib.pyx":660 + * rstop = stop + * except OverflowError: + * raise ValueError('stop out of range (%i)' % stop) # <<<<<<<<<<<<<< + * + * if region: + */ + __pyx_t_13 = __Pyx_PyString_Format(__pyx_kp_s_stop_out_of_range_i, __pyx_v_stop); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 660, __pyx_L23_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_13); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 660, __pyx_L23_except_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_Raise(__pyx_t_12, 0, 0, 0); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __PYX_ERR(0, 660, __pyx_L23_except_error) } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 229, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_fd = __pyx_t_5; + goto __pyx_L23_except_error; + __pyx_L23_except_error:; + + /* "pysam/libchtslib.pyx":657 + * + * if stop is not None: + * try: # <<<<<<<<<<<<<< + * rstop = stop + * except OverflowError: + */ + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_6, __pyx_t_5); + goto __pyx_L1_error; + __pyx_L26_try_end:; } - __pyx_L7:; - /* "pysam/libchtslib.pyx":231 - * fd = self.filename.fileno() + /* "pysam/libchtslib.pyx":656 + * raise ValueError('start out of range (%i)' % start) * - * if self.duplicate_filehandle: # <<<<<<<<<<<<<< - * dup_fd = dup(fd) - * else: + * if stop is not None: # <<<<<<<<<<<<<< + * try: + * rstop = stop */ - __pyx_t_3 = (__pyx_v_self->duplicate_filehandle != 0); - if (__pyx_t_3) { + } - /* "pysam/libchtslib.pyx":232 + /* "pysam/libchtslib.pyx":662 + * raise ValueError('stop out of range (%i)' % stop) * - * if self.duplicate_filehandle: - * dup_fd = dup(fd) # <<<<<<<<<<<<<< - * else: - * dup_fd = fd + * if region: # <<<<<<<<<<<<<< + * region = force_str(region) + * parts = re.split('[:-]', region) */ - __pyx_v_dup_fd = dup(__pyx_v_fd); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 662, __pyx_L1_error) + if (__pyx_t_1) { - /* "pysam/libchtslib.pyx":231 - * fd = self.filename.fileno() + /* "pysam/libchtslib.pyx":663 * - * if self.duplicate_filehandle: # <<<<<<<<<<<<<< - * dup_fd = dup(fd) - * else: + * if region: + * region = force_str(region) # <<<<<<<<<<<<<< + * parts = re.split('[:-]', region) + * contig = parts[0] + */ + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_region, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 663, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF_SET(__pyx_v_region, __pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libchtslib.pyx":664 + * if region: + * region = force_str(region) + * parts = re.split('[:-]', region) # <<<<<<<<<<<<<< + * contig = parts[0] + * if len(parts) >= 2: + */ + __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 664, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_split); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 664, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = NULL; + __pyx_t_9 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_9 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_kp_s__36, __pyx_v_region}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 664, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_kp_s__36, __pyx_v_region}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 664, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_12 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 664, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_10) { + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL; + } + __Pyx_INCREF(__pyx_kp_s__36); + __Pyx_GIVEREF(__pyx_kp_s__36); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_9, __pyx_kp_s__36); + __Pyx_INCREF(__pyx_v_region); + __Pyx_GIVEREF(__pyx_v_region); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_9, __pyx_v_region); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 664, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_v_parts = __pyx_t_3; + __pyx_t_3 = 0; + + /* "pysam/libchtslib.pyx":665 + * region = force_str(region) + * parts = re.split('[:-]', region) + * contig = parts[0] # <<<<<<<<<<<<<< + * if len(parts) >= 2: + * rstart = int(parts[1]) - 1 */ - goto __pyx_L8; - } + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_parts, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 665, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF_SET(__pyx_v_contig, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libchtslib.pyx":234 - * dup_fd = dup(fd) - * else: - * dup_fd = fd # <<<<<<<<<<<<<< - * - * # Replicate mode normalization done in hts_open_format + /* "pysam/libchtslib.pyx":666 + * parts = re.split('[:-]', region) + * contig = parts[0] + * if len(parts) >= 2: # <<<<<<<<<<<<<< + * rstart = int(parts[1]) - 1 + * if len(parts) >= 3: + */ + __pyx_t_14 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 666, __pyx_L1_error) + __pyx_t_1 = ((__pyx_t_14 >= 2) != 0); + if (__pyx_t_1) { + + /* "pysam/libchtslib.pyx":667 + * contig = parts[0] + * if len(parts) >= 2: + * rstart = int(parts[1]) - 1 # <<<<<<<<<<<<<< + * if len(parts) >= 3: + * rstop = int(parts[2]) + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_parts, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 667, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_11 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 667, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_11, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 667, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_8 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_3); if (unlikely((__pyx_t_8 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 667, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_rstart = __pyx_t_8; + + /* "pysam/libchtslib.pyx":666 + * parts = re.split('[:-]', region) + * contig = parts[0] + * if len(parts) >= 2: # <<<<<<<<<<<<<< + * rstart = int(parts[1]) - 1 + * if len(parts) >= 3: */ - /*else*/ { - __pyx_v_dup_fd = __pyx_v_fd; } - __pyx_L8:; - /* "pysam/libchtslib.pyx":237 + /* "pysam/libchtslib.pyx":668 + * if len(parts) >= 2: + * rstart = int(parts[1]) - 1 + * if len(parts) >= 3: # <<<<<<<<<<<<<< + * rstop = int(parts[2]) * - * # Replicate mode normalization done in hts_open_format - * smode = self.mode.replace(b'b', b'').replace(b'c', b'') # <<<<<<<<<<<<<< - * if b'b' in self.mode: - * smode += b'b' - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->mode, __pyx_n_s_replace); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_replace); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_smode = __pyx_t_6; - __pyx_t_6 = 0; - - /* "pysam/libchtslib.pyx":238 - * # Replicate mode normalization done in hts_open_format - * smode = self.mode.replace(b'b', b'').replace(b'c', b'') - * if b'b' in self.mode: # <<<<<<<<<<<<<< - * smode += b'b' - * elif b'c' in self.mode: */ - __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_n_b_b, __pyx_v_self->mode, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 238, __pyx_L1_error) - __pyx_t_4 = (__pyx_t_3 != 0); - if (__pyx_t_4) { + __pyx_t_14 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 668, __pyx_L1_error) + __pyx_t_1 = ((__pyx_t_14 >= 3) != 0); + if (__pyx_t_1) { - /* "pysam/libchtslib.pyx":239 - * smode = self.mode.replace(b'b', b'').replace(b'c', b'') - * if b'b' in self.mode: - * smode += b'b' # <<<<<<<<<<<<<< - * elif b'c' in self.mode: - * smode += b'c' + /* "pysam/libchtslib.pyx":669 + * rstart = int(parts[1]) - 1 + * if len(parts) >= 3: + * rstop = int(parts[2]) # <<<<<<<<<<<<<< + * + * if tid is not None: */ - __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_v_smode, __pyx_n_b_b); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 239, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF_SET(__pyx_v_smode, __pyx_t_6); - __pyx_t_6 = 0; - - /* "pysam/libchtslib.pyx":238 - * # Replicate mode normalization done in hts_open_format - * smode = self.mode.replace(b'b', b'').replace(b'c', b'') - * if b'b' in self.mode: # <<<<<<<<<<<<<< - * smode += b'b' - * elif b'c' in self.mode: + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_parts, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_11 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_11); if (unlikely((__pyx_t_8 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 669, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_v_rstop = __pyx_t_8; + + /* "pysam/libchtslib.pyx":668 + * if len(parts) >= 2: + * rstart = int(parts[1]) - 1 + * if len(parts) >= 3: # <<<<<<<<<<<<<< + * rstop = int(parts[2]) + * */ - goto __pyx_L9; } - /* "pysam/libchtslib.pyx":240 - * if b'b' in self.mode: - * smode += b'b' - * elif b'c' in self.mode: # <<<<<<<<<<<<<< - * smode += b'c' - * cmode = smode + /* "pysam/libchtslib.pyx":662 + * raise ValueError('stop out of range (%i)' % stop) + * + * if region: # <<<<<<<<<<<<<< + * region = force_str(region) + * parts = re.split('[:-]', region) */ - __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_n_b_c, __pyx_v_self->mode, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 240, __pyx_L1_error) - __pyx_t_3 = (__pyx_t_4 != 0); - if (__pyx_t_3) { + } - /* "pysam/libchtslib.pyx":241 - * smode += b'b' - * elif b'c' in self.mode: - * smode += b'c' # <<<<<<<<<<<<<< - * cmode = smode + /* "pysam/libchtslib.pyx":671 + * rstop = int(parts[2]) * + * if tid is not None: # <<<<<<<<<<<<<< + * if not self.is_valid_tid(tid): + * raise IndexError('invalid tid') */ - __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_v_smode, __pyx_n_b_c); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 241, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF_SET(__pyx_v_smode, __pyx_t_6); - __pyx_t_6 = 0; + __pyx_t_1 = (__pyx_v_tid != Py_None); + __pyx_t_4 = (__pyx_t_1 != 0); + if (__pyx_t_4) { - /* "pysam/libchtslib.pyx":240 - * if b'b' in self.mode: - * smode += b'b' - * elif b'c' in self.mode: # <<<<<<<<<<<<<< - * smode += b'c' - * cmode = smode + /* "pysam/libchtslib.pyx":672 + * + * if tid is not None: + * if not self.is_valid_tid(tid): # <<<<<<<<<<<<<< + * raise IndexError('invalid tid') + * rtid = tid */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_valid_tid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 672, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } } - __pyx_L9:; + if (!__pyx_t_12) { + __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_tid); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 672, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_v_tid}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 672, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_11); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_v_tid}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 672, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_11); + } else + #endif + { + __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 672, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_12); __pyx_t_12 = NULL; + __Pyx_INCREF(__pyx_v_tid); + __Pyx_GIVEREF(__pyx_v_tid); + PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_tid); + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 672, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 672, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_1 = ((!__pyx_t_4) != 0); + if (unlikely(__pyx_t_1)) { + + /* "pysam/libchtslib.pyx":673 + * if tid is not None: + * if not self.is_valid_tid(tid): + * raise IndexError('invalid tid') # <<<<<<<<<<<<<< + * rtid = tid + * else: + */ + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_Raise(__pyx_t_11, 0, 0, 0); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __PYX_ERR(0, 673, __pyx_L1_error) - /* "pysam/libchtslib.pyx":242 - * elif b'c' in self.mode: - * smode += b'c' - * cmode = smode # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":672 * - * hfile = hdopen(dup_fd, cmode) + * if tid is not None: + * if not self.is_valid_tid(tid): # <<<<<<<<<<<<<< + * raise IndexError('invalid tid') + * rtid = tid */ - __pyx_t_1 = __Pyx_PyObject_AsWritableString(__pyx_v_smode); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 242, __pyx_L1_error) - __pyx_v_cmode = __pyx_t_1; + } - /* "pysam/libchtslib.pyx":244 - * cmode = smode - * - * hfile = hdopen(dup_fd, cmode) # <<<<<<<<<<<<<< - * if hfile == NULL: - * raise IOError('Cannot create hfile') + /* "pysam/libchtslib.pyx":674 + * if not self.is_valid_tid(tid): + * raise IndexError('invalid tid') + * rtid = tid # <<<<<<<<<<<<<< + * else: + * if contig == "*": */ - __pyx_v_hfile = hdopen(__pyx_v_dup_fd, __pyx_v_cmode); + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_v_tid); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 674, __pyx_L1_error) + __pyx_v_rtid = __pyx_t_9; - /* "pysam/libchtslib.pyx":245 - * - * hfile = hdopen(dup_fd, cmode) - * if hfile == NULL: # <<<<<<<<<<<<<< - * raise IOError('Cannot create hfile') + /* "pysam/libchtslib.pyx":671 + * rstop = int(parts[2]) * + * if tid is not None: # <<<<<<<<<<<<<< + * if not self.is_valid_tid(tid): + * raise IndexError('invalid tid') */ - __pyx_t_3 = ((__pyx_v_hfile == NULL) != 0); - if (unlikely(__pyx_t_3)) { + goto __pyx_L32; + } - /* "pysam/libchtslib.pyx":246 - * hfile = hdopen(dup_fd, cmode) - * if hfile == NULL: - * raise IOError('Cannot create hfile') # <<<<<<<<<<<<<< - * - * try: + /* "pysam/libchtslib.pyx":676 + * rtid = tid + * else: + * if contig == "*": # <<<<<<<<<<<<<< + * rtid = HTS_IDX_NOCOOR + * elif contig == ".": */ - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_Raise(__pyx_t_6, 0, 0, 0); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __PYX_ERR(0, 246, __pyx_L1_error) + /*else*/ { + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_contig, __pyx_kp_s__38, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 676, __pyx_L1_error) + if (__pyx_t_1) { - /* "pysam/libchtslib.pyx":245 - * - * hfile = hdopen(dup_fd, cmode) - * if hfile == NULL: # <<<<<<<<<<<<<< - * raise IOError('Cannot create hfile') - * + /* "pysam/libchtslib.pyx":677 + * else: + * if contig == "*": + * rtid = HTS_IDX_NOCOOR # <<<<<<<<<<<<<< + * elif contig == ".": + * rtid = HTS_IDX_START */ - } + __pyx_v_rtid = HTS_IDX_NOCOOR; - /* "pysam/libchtslib.pyx":248 - * raise IOError('Cannot create hfile') - * - * try: # <<<<<<<<<<<<<< - * # filename.name can be an int - * filename = str(self.filename.name) + /* "pysam/libchtslib.pyx":676 + * rtid = tid + * else: + * if contig == "*": # <<<<<<<<<<<<<< + * rtid = HTS_IDX_NOCOOR + * elif contig == ".": */ - { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10); - __Pyx_XGOTREF(__pyx_t_8); - __Pyx_XGOTREF(__pyx_t_9); - __Pyx_XGOTREF(__pyx_t_10); - /*try:*/ { + goto __pyx_L34; + } - /* "pysam/libchtslib.pyx":250 - * try: - * # filename.name can be an int - * filename = str(self.filename.name) # <<<<<<<<<<<<<< - * except AttributeError: - * filename = ''.format(fd) + /* "pysam/libchtslib.pyx":678 + * if contig == "*": + * rtid = HTS_IDX_NOCOOR + * elif contig == ".": # <<<<<<<<<<<<<< + * rtid = HTS_IDX_START + * else: */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->filename, __pyx_n_s_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 250, __pyx_L11_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 250, __pyx_L11_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_v_filename = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_contig, __pyx_kp_s__39, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 678, __pyx_L1_error) + if (__pyx_t_1) { - /* "pysam/libchtslib.pyx":248 - * raise IOError('Cannot create hfile') - * - * try: # <<<<<<<<<<<<<< - * # filename.name can be an int - * filename = str(self.filename.name) + /* "pysam/libchtslib.pyx":679 + * rtid = HTS_IDX_NOCOOR + * elif contig == ".": + * rtid = HTS_IDX_START # <<<<<<<<<<<<<< + * else: + * rtid = self.get_tid(contig) */ - } - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - goto __pyx_L16_try_end; - __pyx_L11_error:; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_rtid = HTS_IDX_START; - /* "pysam/libchtslib.pyx":251 - * # filename.name can be an int - * filename = str(self.filename.name) - * except AttributeError: # <<<<<<<<<<<<<< - * filename = ''.format(fd) - * + /* "pysam/libchtslib.pyx":678 + * if contig == "*": + * rtid = HTS_IDX_NOCOOR + * elif contig == ".": # <<<<<<<<<<<<<< + * rtid = HTS_IDX_START + * else: */ - __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError); - if (__pyx_t_5) { - __Pyx_AddTraceback("pysam.libchtslib.HTSFile._open_htsfile", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 251, __pyx_L13_except_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_t_7); + goto __pyx_L34; + } - /* "pysam/libchtslib.pyx":252 - * filename = str(self.filename.name) - * except AttributeError: - * filename = ''.format(fd) # <<<<<<<<<<<<<< - * - * filename = encode_filename(filename) + /* "pysam/libchtslib.pyx":681 + * rtid = HTS_IDX_START + * else: + * rtid = self.get_tid(contig) # <<<<<<<<<<<<<< + * if rtid < 0: + * raise ValueError('invalid contig `%s`' % contig) */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_fd, __pyx_n_s_format); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 252, __pyx_L13_except_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_fd); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 252, __pyx_L13_except_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_14 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_14)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } + /*else*/ { + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); } - if (!__pyx_t_14) { - __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_13); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 252, __pyx_L13_except_error) - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + if (!__pyx_t_10) { + __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_contig); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_contig}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_GOTREF(__pyx_t_11); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[2] = {__pyx_t_14, __pyx_t_13}; - __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 252, __pyx_L13_except_error) - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[2] = {__pyx_t_14, __pyx_t_13}; - __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 252, __pyx_L13_except_error) - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - } else - #endif - { - __pyx_t_15 = PyTuple_New(1+1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 252, __pyx_L13_except_error) - __Pyx_GOTREF(__pyx_t_15); - __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); __pyx_t_14 = NULL; - __Pyx_GIVEREF(__pyx_t_13); - PyTuple_SET_ITEM(__pyx_t_15, 0+1, __pyx_t_13); - __pyx_t_13 = 0; - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_15, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 252, __pyx_L13_except_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_contig}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_11); + } else + #endif + { + __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_INCREF(__pyx_v_contig); + __Pyx_GIVEREF(__pyx_v_contig); + PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_v_contig); + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_12, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; } - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF_SET(__pyx_v_filename, __pyx_t_11); - __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L12_exception_handled; } - goto __pyx_L13_except_error; - __pyx_L13_except_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_v_rtid = __pyx_t_9; - /* "pysam/libchtslib.pyx":248 - * raise IOError('Cannot create hfile') - * - * try: # <<<<<<<<<<<<<< - * # filename.name can be an int - * filename = str(self.filename.name) - */ - __Pyx_XGIVEREF(__pyx_t_8); - __Pyx_XGIVEREF(__pyx_t_9); - __Pyx_XGIVEREF(__pyx_t_10); - __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); - goto __pyx_L1_error; - __pyx_L12_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_8); - __Pyx_XGIVEREF(__pyx_t_9); - __Pyx_XGIVEREF(__pyx_t_10); - __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); - __pyx_L16_try_end:; - } + /* "pysam/libchtslib.pyx":682 + * else: + * rtid = self.get_tid(contig) + * if rtid < 0: # <<<<<<<<<<<<<< + * raise ValueError('invalid contig `%s`' % contig) + * + */ + __pyx_t_1 = ((__pyx_v_rtid < 0) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libchtslib.pyx":254 - * filename = ''.format(fd) + /* "pysam/libchtslib.pyx":683 + * rtid = self.get_tid(contig) + * if rtid < 0: + * raise ValueError('invalid contig `%s`' % contig) # <<<<<<<<<<<<<< + * + * if rstart > rstop: + */ + __pyx_t_11 = __Pyx_PyString_Format(__pyx_kp_s_invalid_contig_s, __pyx_v_contig); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 683, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 683, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 683, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":682 + * else: + * rtid = self.get_tid(contig) + * if rtid < 0: # <<<<<<<<<<<<<< + * raise ValueError('invalid contig `%s`' % contig) * - * filename = encode_filename(filename) # <<<<<<<<<<<<<< - * cfilename = filename - * with nogil: */ - __pyx_t_7 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 254, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF_SET(__pyx_v_filename, __pyx_t_7); - __pyx_t_7 = 0; + } + } + __pyx_L34:; + } + __pyx_L32:; - /* "pysam/libchtslib.pyx":255 + /* "pysam/libchtslib.pyx":685 + * raise ValueError('invalid contig `%s`' % contig) * - * filename = encode_filename(filename) - * cfilename = filename # <<<<<<<<<<<<<< - * with nogil: - * return hts_hopen(hfile, cfilename, cmode) + * if rstart > rstop: # <<<<<<<<<<<<<< + * raise ValueError('invalid coordinates: start (%i) > stop (%i)' % (rstart, rstop)) + * if not 0 <= rstart < MAX_POS: */ - __pyx_t_1 = __Pyx_PyObject_AsWritableString(__pyx_v_filename); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 255, __pyx_L1_error) - __pyx_v_cfilename = __pyx_t_1; + __pyx_t_1 = ((__pyx_v_rstart > __pyx_v_rstop) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libchtslib.pyx":256 - * filename = encode_filename(filename) - * cfilename = filename - * with nogil: # <<<<<<<<<<<<<< - * return hts_hopen(hfile, cfilename, cmode) + /* "pysam/libchtslib.pyx":686 * + * if rstart > rstop: + * raise ValueError('invalid coordinates: start (%i) > stop (%i)' % (rstart, rstop)) # <<<<<<<<<<<<<< + * if not 0 <= rstart < MAX_POS: + * raise ValueError('start out of range (%i)' % rstart) */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + __pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 686, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_11 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstop); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 686, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 686, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_11); + __pyx_t_3 = 0; + __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyString_Format(__pyx_kp_s_invalid_coordinates_start_i_stop, __pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 686, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 686, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_Raise(__pyx_t_12, 0, 0, 0); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __PYX_ERR(0, 686, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":685 + * raise ValueError('invalid contig `%s`' % contig) + * + * if rstart > rstop: # <<<<<<<<<<<<<< + * raise ValueError('invalid coordinates: start (%i) > stop (%i)' % (rstart, rstop)) + * if not 0 <= rstart < MAX_POS: + */ + } - /* "pysam/libchtslib.pyx":257 - * cfilename = filename - * with nogil: - * return hts_hopen(hfile, cfilename, cmode) # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":687 + * if rstart > rstop: + * raise ValueError('invalid coordinates: start (%i) > stop (%i)' % (rstart, rstop)) + * if not 0 <= rstart < MAX_POS: # <<<<<<<<<<<<<< + * raise ValueError('start out of range (%i)' % rstart) + * if not 0 <= rstop <= MAX_POS: + */ + __pyx_t_1 = (0 <= __pyx_v_rstart); + if (__pyx_t_1) { + __pyx_t_1 = (__pyx_v_rstart < __pyx_v_5pysam_10libchtslib_MAX_POS); + } + __pyx_t_4 = ((!(__pyx_t_1 != 0)) != 0); + if (unlikely(__pyx_t_4)) { + + /* "pysam/libchtslib.pyx":688 + * raise ValueError('invalid coordinates: start (%i) > stop (%i)' % (rstart, rstop)) + * if not 0 <= rstart < MAX_POS: + * raise ValueError('start out of range (%i)' % rstart) # <<<<<<<<<<<<<< + * if not 0 <= rstop <= MAX_POS: + * raise ValueError('stop out of range (%i)' % rstop) + */ + __pyx_t_12 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_11 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 688, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_Raise(__pyx_t_12, 0, 0, 0); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __PYX_ERR(0, 688, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":687 + * if rstart > rstop: + * raise ValueError('invalid coordinates: start (%i) > stop (%i)' % (rstart, rstop)) + * if not 0 <= rstart < MAX_POS: # <<<<<<<<<<<<<< + * raise ValueError('start out of range (%i)' % rstart) + * if not 0 <= rstop <= MAX_POS: + */ + } + + /* "pysam/libchtslib.pyx":689 + * if not 0 <= rstart < MAX_POS: + * raise ValueError('start out of range (%i)' % rstart) + * if not 0 <= rstop <= MAX_POS: # <<<<<<<<<<<<<< + * raise ValueError('stop out of range (%i)' % rstop) * - * def _exists(self): */ - __pyx_r = hts_hopen(__pyx_v_hfile, __pyx_v_cfilename, __pyx_v_cmode); - goto __pyx_L19_return; - } + __pyx_t_4 = (0 <= __pyx_v_rstop); + if (__pyx_t_4) { + __pyx_t_4 = (__pyx_v_rstop <= __pyx_v_5pysam_10libchtslib_MAX_POS); + } + __pyx_t_1 = ((!(__pyx_t_4 != 0)) != 0); + if (unlikely(__pyx_t_1)) { - /* "pysam/libchtslib.pyx":256 - * filename = encode_filename(filename) - * cfilename = filename - * with nogil: # <<<<<<<<<<<<<< - * return hts_hopen(hfile, cfilename, cmode) + /* "pysam/libchtslib.pyx":690 + * raise ValueError('start out of range (%i)' % rstart) + * if not 0 <= rstop <= MAX_POS: + * raise ValueError('stop out of range (%i)' % rstop) # <<<<<<<<<<<<<< + * + * return 1, rtid, rstart, rstop + */ + __pyx_t_12 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstop); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_11 = __Pyx_PyString_Format(__pyx_kp_s_stop_out_of_range_i, __pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_Raise(__pyx_t_12, 0, 0, 0); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __PYX_ERR(0, 690, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":689 + * if not 0 <= rstart < MAX_POS: + * raise ValueError('start out of range (%i)' % rstart) + * if not 0 <= rstop <= MAX_POS: # <<<<<<<<<<<<<< + * raise ValueError('stop out of range (%i)' % rstop) * */ - /*finally:*/ { - __pyx_L19_return: { - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L0; - } - } - } } - /* "pysam/libchtslib.pyx":216 - * return ret + /* "pysam/libchtslib.pyx":692 + * raise ValueError('stop out of range (%i)' % rstop) * - * cdef htsFile *_open_htsfile(self) except? NULL: # <<<<<<<<<<<<<< - * cdef char *cfilename - * cdef char *cmode = self.mode + * return 1, rtid, rstart, rstop # <<<<<<<<<<<<<< + * + * def is_valid_tid(self, tid): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_12 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 692, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_11 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 692, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 692, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = PyTuple_New(4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 692, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_int_1); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_3); + __pyx_t_12 = 0; + __pyx_t_11 = 0; + __pyx_t_3 = 0; + __pyx_r = __pyx_t_10; + __pyx_t_10 = 0; + goto __pyx_L0; + + /* "pysam/libchtslib.pyx":593 + * hts_opt_free(opts) + * + * def parse_region(self, contig=None, start=None, stop=None, region=None,tid=None, # <<<<<<<<<<<<<< + * reference=None, end=None): + * """parse alternative ways to specify a genomic region. A region can */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_10); __Pyx_XDECREF(__pyx_t_11); __Pyx_XDECREF(__pyx_t_12); __Pyx_XDECREF(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_14); - __Pyx_XDECREF(__pyx_t_15); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile._open_htsfile", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.parse_region", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_smode); - __Pyx_XDECREF(__pyx_v_filename); - __Pyx_TraceReturn(Py_None, 0); + __Pyx_XDECREF(__pyx_v_parts); + __Pyx_XDECREF(__pyx_v_contig); + __Pyx_XDECREF(__pyx_v_stop); + __Pyx_XDECREF(__pyx_v_region); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libchtslib.pyx":259 - * return hts_hopen(hfile, cfilename, cmode) +/* "pysam/libchtslib.pyx":694 + * return 1, rtid, rstart, rstop * - * def _exists(self): # <<<<<<<<<<<<<< - * """return False iff file is local, a file and exists. + * def is_valid_tid(self, tid): # <<<<<<<<<<<<<< * """ + * return True if the numerical :term:`tid` is valid; False otherwise. */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_15_exists(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_7HTSFile_14_exists[] = "HTSFile._exists(self)\nreturn False iff file is local, a file and exists.\n "; -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_15_exists(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_23is_valid_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_22is_valid_tid[] = "HTSFile.is_valid_tid(self, tid)\n\n return True if the numerical :term:`tid` is valid; False otherwise.\n\n returns -1 if contig is not known.\n "; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_23is_valid_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_exists (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_14_exists(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __Pyx_RefNannySetupContext("is_valid_tid (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_22is_valid_tid(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), ((PyObject *)__pyx_v_tid)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_14_exists(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_22is_valid_tid(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_tid) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; + __Pyx_RefNannySetupContext("is_valid_tid", 0); + __Pyx_TraceCall("is_valid_tid", __pyx_f[0], 694, 0, __PYX_ERR(0, 694, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":700 + * returns -1 if contig is not known. + * """ + * raise NotImplementedError() # <<<<<<<<<<<<<< + * + * def is_valid_reference_name(self, contig): + */ + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_NotImplementedError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 700, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 700, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":694 + * return 1, rtid, rstart, rstop + * + * def is_valid_tid(self, tid): # <<<<<<<<<<<<<< + * """ + * return True if the numerical :term:`tid` is valid; False otherwise. + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":702 + * raise NotImplementedError() + * + * def is_valid_reference_name(self, contig): # <<<<<<<<<<<<<< + * """ + * return True if the contig name :term:`contig` is valid; False otherwise. + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_25is_valid_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_contig); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_24is_valid_reference_name[] = "HTSFile.is_valid_reference_name(self, contig)\n\n return True if the contig name :term:`contig` is valid; False otherwise.\n "; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_25is_valid_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_contig) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_valid_reference_name (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_24is_valid_reference_name(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), ((PyObject *)__pyx_v_contig)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_24is_valid_reference_name(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, PyObject *__pyx_v_contig) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - __Pyx_RefNannySetupContext("_exists", 0); - __Pyx_TraceCall("_exists", __pyx_f[0], 259, 0, __PYX_ERR(0, 259, __pyx_L1_error)); + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("is_valid_reference_name", 0); + __Pyx_TraceCall("is_valid_reference_name", __pyx_f[0], 702, 0, __PYX_ERR(0, 702, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":262 - * """return False iff file is local, a file and exists. + /* "pysam/libchtslib.pyx":706 + * return True if the contig name :term:`contig` is valid; False otherwise. * """ - * return (not isinstance(self.filename, (str, bytes)) or # <<<<<<<<<<<<<< - * self.filename == b'-' or - * self.is_remote or + * return self.get_tid(contig) != -1 # <<<<<<<<<<<<<< + * + * def get_tid(self, contig): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __pyx_v_self->filename; - __Pyx_INCREF(__pyx_t_3); - __pyx_t_4 = PyString_Check(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = (__pyx_t_4 != 0); - if (!__pyx_t_5) { - } else { - __pyx_t_2 = __pyx_t_5; - goto __pyx_L5_bool_binop_done; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } } - __pyx_t_3 = __pyx_v_self->filename; - __Pyx_INCREF(__pyx_t_3); - __pyx_t_5 = PyBytes_Check(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_4 = (__pyx_t_5 != 0); - __pyx_t_2 = __pyx_t_4; - __pyx_L5_bool_binop_done:; - __pyx_t_4 = (!(__pyx_t_2 != 0)); - if (!__pyx_t_4) { + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_contig); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); } else { - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 262, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3_bool_binop_done; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_contig}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_contig}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_contig); + __Pyx_GIVEREF(__pyx_v_contig); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_contig); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_neg_1, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "pysam/libchtslib.pyx":263 + /* "pysam/libchtslib.pyx":702 + * raise NotImplementedError() + * + * def is_valid_reference_name(self, contig): # <<<<<<<<<<<<<< * """ - * return (not isinstance(self.filename, (str, bytes)) or - * self.filename == b'-' or # <<<<<<<<<<<<<< - * self.is_remote or - * os.path.exists(self.filename)) + * return True if the contig name :term:`contig` is valid; False otherwise. */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_self->filename, __pyx_kp_b__20, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 263, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 263, __pyx_L1_error) - if (!__pyx_t_4) { - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __Pyx_INCREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L3_bool_binop_done; - } - /* "pysam/libchtslib.pyx":264 - * return (not isinstance(self.filename, (str, bytes)) or - * self.filename == b'-' or - * self.is_remote or # <<<<<<<<<<<<<< - * os.path.exists(self.filename)) + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.is_valid_reference_name", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":708 + * return self.get_tid(contig) != -1 + * + * def get_tid(self, contig): # <<<<<<<<<<<<<< + * """ + * return the numerical :term:`tid` corresponding to */ - if (!__pyx_v_self->is_remote) { - } else { - __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_self->is_remote); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3_bool_binop_done; - } - /* "pysam/libchtslib.pyx":265 - * self.filename == b'-' or - * self.is_remote or - * os.path.exists(self.filename)) # <<<<<<<<<<<<<< - */ - __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_path); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_exists); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - if (!__pyx_t_7) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_self->filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_self->filename}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { - PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_self->filename}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL; - __Pyx_INCREF(__pyx_v_self->filename); - __Pyx_GIVEREF(__pyx_v_self->filename); - PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_self->filename); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 265, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_INCREF(__pyx_t_3); - __pyx_t_1 = __pyx_t_3; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_L3_bool_binop_done:; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_27get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_contig); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_26get_tid[] = "HTSFile.get_tid(self, contig)\n\n return the numerical :term:`tid` corresponding to\n :term:`contig`\n\n returns -1 if contig is not known.\n "; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_27get_tid(PyObject *__pyx_v_self, PyObject *__pyx_v_contig) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_tid (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_26get_tid(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), ((PyObject *)__pyx_v_contig)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_26get_tid(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_contig) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("get_tid", 0); + __Pyx_TraceCall("get_tid", __pyx_f[0], 708, 0, __PYX_ERR(0, 708, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":715 + * returns -1 if contig is not known. + * """ + * raise NotImplementedError() # <<<<<<<<<<<<<< + * + * def get_reference_name(self, tid): + */ + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_NotImplementedError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 715, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 715, __pyx_L1_error) + + /* "pysam/libchtslib.pyx":708 + * return self.get_tid(contig) != -1 + * + * def get_tid(self, contig): # <<<<<<<<<<<<<< + * """ + * return the numerical :term:`tid` corresponding to + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.get_tid", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pyx":717 + * raise NotImplementedError() + * + * def get_reference_name(self, tid): # <<<<<<<<<<<<<< + * """ + * return :term:`contig` name corresponding to numerical :term:`tid` + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_29get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_28get_reference_name[] = "HTSFile.get_reference_name(self, tid)\n\n return :term:`contig` name corresponding to numerical :term:`tid`\n "; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_29get_reference_name(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_reference_name (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_28get_reference_name(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), ((PyObject *)__pyx_v_tid)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_28get_reference_name(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_tid) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("get_reference_name", 0); + __Pyx_TraceCall("get_reference_name", __pyx_f[0], 717, 0, __PYX_ERR(0, 717, __pyx_L1_error)); + + /* "pysam/libchtslib.pyx":721 + * return :term:`contig` name corresponding to numerical :term:`tid` + * """ + * raise NotImplementedError() # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_NotImplementedError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 721, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 721, __pyx_L1_error) - /* "pysam/libchtslib.pyx":259 - * return hts_hopen(hfile, cfilename, cmode) + /* "pysam/libchtslib.pyx":717 + * raise NotImplementedError() * - * def _exists(self): # <<<<<<<<<<<<<< - * """return False iff file is local, a file and exists. + * def get_reference_name(self, tid): # <<<<<<<<<<<<<< * """ + * return :term:`contig` name corresponding to numerical :term:`tid` */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("pysam.libchtslib.HTSFile._exists", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.get_reference_name", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; - __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libchtslib.pxd":1908 +/* "pysam/libchtslib.pxd":2594 * cdef int64_t start_offset # BGZF offset of first record * * cdef readonly object filename # filename as supplied by user # <<<<<<<<<<<<<< * cdef readonly object mode # file opening mode - * cdef readonly object index_filename # filename of index, if supplied by user + * cdef readonly object threads # number of threads to use */ /* Python wrapper */ @@ -6034,7 +12877,7 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8filename___get__(struct __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 1908, 0, __PYX_ERR(2, 1908, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[2], 2594, 0, __PYX_ERR(2, 2594, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->filename); __pyx_r = __pyx_v_self->filename; @@ -6051,12 +12894,12 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_8filename___get__(struct return __pyx_r; } -/* "pysam/libchtslib.pxd":1909 +/* "pysam/libchtslib.pxd":2595 * * cdef readonly object filename # filename as supplied by user * cdef readonly object mode # file opening mode # <<<<<<<<<<<<<< + * cdef readonly object threads # number of threads to use * cdef readonly object index_filename # filename of index, if supplied by user - * */ /* Python wrapper */ @@ -6077,7 +12920,7 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_4mode___get__(struct __py __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 1909, 0, __PYX_ERR(2, 1909, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[2], 2595, 0, __PYX_ERR(2, 2595, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->mode); __pyx_r = __pyx_v_self->mode; @@ -6094,9 +12937,52 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_4mode___get__(struct __py return __pyx_r; } -/* "pysam/libchtslib.pxd":1910 +/* "pysam/libchtslib.pxd":2596 * cdef readonly object filename # filename as supplied by user * cdef readonly object mode # file opening mode + * cdef readonly object threads # number of threads to use # <<<<<<<<<<<<<< + * cdef readonly object index_filename # filename of index, if supplied by user + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7threads_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_7threads_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_7threads___get__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_7threads___get__(struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[2], 2596, 0, __PYX_ERR(2, 2596, __pyx_L1_error)); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->threads); + __pyx_r = __pyx_v_self->threads; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libchtslib.HTSFile.threads.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libchtslib.pxd":2597 + * cdef readonly object mode # file opening mode + * cdef readonly object threads # number of threads to use * cdef readonly object index_filename # filename of index, if supplied by user # <<<<<<<<<<<<<< * * cdef readonly bint is_stream # Is htsfile a non-seekable stream @@ -6120,7 +13006,7 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_14index_filename___get__( __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 1910, 0, __PYX_ERR(2, 1910, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[2], 2597, 0, __PYX_ERR(2, 2597, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->index_filename); __pyx_r = __pyx_v_self->index_filename; @@ -6137,7 +13023,7 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_14index_filename___get__( return __pyx_r; } -/* "pysam/libchtslib.pxd":1912 +/* "pysam/libchtslib.pxd":2599 * cdef readonly object index_filename # filename of index, if supplied by user * * cdef readonly bint is_stream # Is htsfile a non-seekable stream # <<<<<<<<<<<<<< @@ -6164,9 +13050,9 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_9is_stream___get__(struct __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 1912, 0, __PYX_ERR(2, 1912, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[2], 2599, 0, __PYX_ERR(2, 2599, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_stream); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1912, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_stream); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -6184,7 +13070,7 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_9is_stream___get__(struct return __pyx_r; } -/* "pysam/libchtslib.pxd":1913 +/* "pysam/libchtslib.pxd":2600 * * cdef readonly bint is_stream # Is htsfile a non-seekable stream * cdef readonly bint is_remote # Is htsfile a remote stream # <<<<<<<<<<<<<< @@ -6211,9 +13097,9 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_9is_remote___get__(struct __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 1913, 0, __PYX_ERR(2, 1913, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[2], 2600, 0, __PYX_ERR(2, 2600, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_remote); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1913, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_remote); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -6231,7 +13117,7 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_9is_remote___get__(struct return __pyx_r; } -/* "pysam/libchtslib.pxd":1914 +/* "pysam/libchtslib.pxd":2601 * cdef readonly bint is_stream # Is htsfile a non-seekable stream * cdef readonly bint is_remote # Is htsfile a remote stream * cdef readonly bint duplicate_filehandle # Duplicate filehandle when opening via fh # <<<<<<<<<<<<<< @@ -6258,9 +13144,9 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_20duplicate_filehandle___ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[2], 1914, 0, __PYX_ERR(2, 1914, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[2], 2601, 0, __PYX_ERR(2, 2601, __pyx_L1_error)); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->duplicate_filehandle); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1914, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->duplicate_filehandle); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 2601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -6285,20 +13171,20 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_20duplicate_filehandle___ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_17__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_7HTSFile_16__reduce_cython__[] = "HTSFile.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_17__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_31__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_30__reduce_cython__[] = "HTSFile.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_31__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_16__reduce_cython__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_30__reduce_cython__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_16__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_30__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -6312,7 +13198,7 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_16__reduce_cython__(CYTHO * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -6343,20 +13229,20 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_16__reduce_cython__(CYTHO */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_19__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_10libchtslib_7HTSFile_18__setstate_cython__[] = "HTSFile.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_19__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_33__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_10libchtslib_7HTSFile_32__setstate_cython__[] = "HTSFile.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_10libchtslib_7HTSFile_33__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_18__setstate_cython__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_10libchtslib_7HTSFile_32__setstate_cython__(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_18__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_32__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_10libchtslib_HTSFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -6369,7 +13255,7 @@ static PyObject *__pyx_pf_5pysam_10libchtslib_7HTSFile_18__setstate_cython__(CYT * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -7072,6 +13958,7 @@ static PyObject *__pyx_tp_new_5pysam_10libchtslib_HTSFile(PyTypeObject *t, PyObj p->__pyx_vtab = __pyx_vtabptr_5pysam_10libchtslib_HTSFile; p->filename = Py_None; Py_INCREF(Py_None); p->mode = Py_None; Py_INCREF(Py_None); + p->threads = Py_None; Py_INCREF(Py_None); p->index_filename = Py_None; Py_INCREF(Py_None); if (unlikely(__pyx_pw_5pysam_10libchtslib_7HTSFile_1__cinit__(o, a, k) < 0)) goto bad; return o; @@ -7092,12 +13979,13 @@ static void __pyx_tp_dealloc_5pysam_10libchtslib_HTSFile(PyObject *o) { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5pysam_10libchtslib_7HTSFile_3__dealloc__(o); + __pyx_pw_5pysam_10libchtslib_7HTSFile_5__dealloc__(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } Py_CLEAR(p->filename); Py_CLEAR(p->mode); + Py_CLEAR(p->threads); Py_CLEAR(p->index_filename); (*Py_TYPE(o)->tp_free)(o); } @@ -7111,6 +13999,9 @@ static int __pyx_tp_traverse_5pysam_10libchtslib_HTSFile(PyObject *o, visitproc if (p->mode) { e = (*v)(p->mode, a); if (e) return e; } + if (p->threads) { + e = (*v)(p->threads, a); if (e) return e; + } if (p->index_filename) { e = (*v)(p->index_filename, a); if (e) return e; } @@ -7126,6 +14017,9 @@ static int __pyx_tp_clear_5pysam_10libchtslib_HTSFile(PyObject *o) { tmp = ((PyObject*)p->mode); p->mode = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); + tmp = ((PyObject*)p->threads); + p->threads = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); tmp = ((PyObject*)p->index_filename); p->index_filename = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); @@ -7200,6 +14094,10 @@ static PyObject *__pyx_getprop_5pysam_10libchtslib_7HTSFile_mode(PyObject *o, CY return __pyx_pw_5pysam_10libchtslib_7HTSFile_4mode_1__get__(o); } +static PyObject *__pyx_getprop_5pysam_10libchtslib_7HTSFile_threads(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_10libchtslib_7HTSFile_7threads_1__get__(o); +} + static PyObject *__pyx_getprop_5pysam_10libchtslib_7HTSFile_index_filename(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5pysam_10libchtslib_7HTSFile_14index_filename_1__get__(o); } @@ -7217,14 +14115,21 @@ static PyObject *__pyx_getprop_5pysam_10libchtslib_7HTSFile_duplicate_filehandle } static PyMethodDef __pyx_methods_5pysam_10libchtslib_HTSFile[] = { - {"__enter__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_5__enter__, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_7HTSFile_4__enter__}, - {"__exit__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_7__exit__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_7HTSFile_6__exit__}, - {"reset", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_9reset, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_7HTSFile_8reset}, - {"seek", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_11seek, METH_O, __pyx_doc_5pysam_10libchtslib_7HTSFile_10seek}, - {"tell", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_13tell, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_7HTSFile_12tell}, - {"_exists", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_15_exists, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_7HTSFile_14_exists}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_17__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_7HTSFile_16__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_19__setstate_cython__, METH_O, __pyx_doc_5pysam_10libchtslib_7HTSFile_18__setstate_cython__}, + {"close", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_3close, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_7HTSFile_2close}, + {"check_truncation", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_7check_truncation, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_7HTSFile_6check_truncation}, + {"__enter__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_9__enter__, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_7HTSFile_8__enter__}, + {"__exit__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_11__exit__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_7HTSFile_10__exit__}, + {"reset", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_13reset, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_7HTSFile_12reset}, + {"seek", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_15seek, METH_O, __pyx_doc_5pysam_10libchtslib_7HTSFile_14seek}, + {"tell", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_17tell, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_7HTSFile_16tell}, + {"add_hts_options", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_19add_hts_options, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_7HTSFile_18add_hts_options}, + {"parse_region", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_21parse_region, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_7HTSFile_20parse_region}, + {"is_valid_tid", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_23is_valid_tid, METH_O, __pyx_doc_5pysam_10libchtslib_7HTSFile_22is_valid_tid}, + {"is_valid_reference_name", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_25is_valid_reference_name, METH_O, __pyx_doc_5pysam_10libchtslib_7HTSFile_24is_valid_reference_name}, + {"get_tid", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_27get_tid, METH_O, __pyx_doc_5pysam_10libchtslib_7HTSFile_26get_tid}, + {"get_reference_name", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_29get_reference_name, METH_O, __pyx_doc_5pysam_10libchtslib_7HTSFile_28get_reference_name}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_31__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_7HTSFile_30__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_7HTSFile_33__setstate_cython__, METH_O, __pyx_doc_5pysam_10libchtslib_7HTSFile_32__setstate_cython__}, {0, 0, 0, 0} }; @@ -7246,6 +14151,7 @@ static struct PyGetSetDef __pyx_getsets_5pysam_10libchtslib_HTSFile[] = { {(char *)"is_bcf", __pyx_getprop_5pysam_10libchtslib_7HTSFile_is_bcf, 0, (char *)"return True if HTSFile is reading or writing a BCF variant file", 0}, {(char *)"filename", __pyx_getprop_5pysam_10libchtslib_7HTSFile_filename, 0, (char *)0, 0}, {(char *)"mode", __pyx_getprop_5pysam_10libchtslib_7HTSFile_mode, 0, (char *)0, 0}, + {(char *)"threads", __pyx_getprop_5pysam_10libchtslib_7HTSFile_threads, 0, (char *)0, 0}, {(char *)"index_filename", __pyx_getprop_5pysam_10libchtslib_7HTSFile_index_filename, 0, (char *)0, 0}, {(char *)"is_stream", __pyx_getprop_5pysam_10libchtslib_7HTSFile_is_stream, 0, (char *)0, 0}, {(char *)"is_remote", __pyx_getprop_5pysam_10libchtslib_7HTSFile_is_remote, 0, (char *)0, 0}, @@ -7310,6 +14216,171 @@ static PyTypeObject __pyx_type_5pysam_10libchtslib_HTSFile = { 0, /*tp_finalize*/ #endif }; +static struct __pyx_vtabstruct_5pysam_10libchtslib_HFile __pyx_vtable_5pysam_10libchtslib_HFile; + +static PyObject *__pyx_tp_new_5pysam_10libchtslib_HFile(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_5pysam_10libchtslib_HFile *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_5pysam_10libchtslib_HFile *)o); + p->__pyx_vtab = __pyx_vtabptr_5pysam_10libchtslib_HFile; + p->name = Py_None; Py_INCREF(Py_None); + p->mode = Py_None; Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_5pysam_10libchtslib_HFile(PyObject *o) { + struct __pyx_obj_5pysam_10libchtslib_HFile *p = (struct __pyx_obj_5pysam_10libchtslib_HFile *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5pysam_10libchtslib_5HFile_3__dealloc__(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_CLEAR(p->name); + Py_CLEAR(p->mode); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_5pysam_10libchtslib_HFile(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_10libchtslib_HFile *p = (struct __pyx_obj_5pysam_10libchtslib_HFile *)o; + if (p->name) { + e = (*v)(p->name, a); if (e) return e; + } + if (p->mode) { + e = (*v)(p->mode, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5pysam_10libchtslib_HFile(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_5pysam_10libchtslib_HFile *p = (struct __pyx_obj_5pysam_10libchtslib_HFile *)o; + tmp = ((PyObject*)p->name); + p->name = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->mode); + p->mode = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_5pysam_10libchtslib_5HFile_closed(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_10libchtslib_5HFile_6closed_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_10libchtslib_5HFile_name(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_10libchtslib_5HFile_4name_1__get__(o); +} + +static PyObject *__pyx_getprop_5pysam_10libchtslib_5HFile_mode(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_10libchtslib_5HFile_4mode_1__get__(o); +} + +static PyMethodDef __pyx_methods_5pysam_10libchtslib_HFile[] = { + {"close", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_5close, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_5HFile_4close}, + {"fileno", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_7fileno, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_5HFile_6fileno}, + {"__enter__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_9__enter__, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_5HFile_8__enter__}, + {"__exit__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_11__exit__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_5HFile_10__exit__}, + {"__next__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_15__next__, METH_NOARGS|METH_COEXIST, 0}, + {"flush", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_17flush, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_5HFile_16flush}, + {"isatty", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_19isatty, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_5HFile_18isatty}, + {"readable", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_21readable, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_5HFile_20readable}, + {"read", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_23read, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_5HFile_22read}, + {"readall", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_25readall, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_5HFile_24readall}, + {"readinto", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_27readinto, METH_O, __pyx_doc_5pysam_10libchtslib_5HFile_26readinto}, + {"readline", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_29readline, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_5HFile_28readline}, + {"readlines", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_31readlines, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_5HFile_30readlines}, + {"seek", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_33seek, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_5HFile_32seek}, + {"tell", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_35tell, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_5HFile_34tell}, + {"seekable", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_37seekable, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_5HFile_36seekable}, + {"truncate", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_39truncate, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_10libchtslib_5HFile_38truncate}, + {"writable", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_41writable, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_5HFile_40writable}, + {"write", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_43write, METH_O, __pyx_doc_5pysam_10libchtslib_5HFile_42write}, + {"writelines", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_45writelines, METH_O, __pyx_doc_5pysam_10libchtslib_5HFile_44writelines}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_47__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_10libchtslib_5HFile_46__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_10libchtslib_5HFile_49__setstate_cython__, METH_O, __pyx_doc_5pysam_10libchtslib_5HFile_48__setstate_cython__}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5pysam_10libchtslib_HFile[] = { + {(char *)"closed", __pyx_getprop_5pysam_10libchtslib_5HFile_closed, 0, (char *)0, 0}, + {(char *)"name", __pyx_getprop_5pysam_10libchtslib_5HFile_name, 0, (char *)0, 0}, + {(char *)"mode", __pyx_getprop_5pysam_10libchtslib_5HFile_mode, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_5pysam_10libchtslib_HFile = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libchtslib.HFile", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_10libchtslib_HFile), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_10libchtslib_HFile, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "HFile(name, mode='r', closedf=True)", /*tp_doc*/ + __pyx_tp_traverse_5pysam_10libchtslib_HFile, /*tp_traverse*/ + __pyx_tp_clear_5pysam_10libchtslib_HFile, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_5pysam_10libchtslib_5HFile_13__iter__, /*tp_iter*/ + __pyx_pw_5pysam_10libchtslib_5HFile_15__next__, /*tp_iternext*/ + __pyx_methods_5pysam_10libchtslib_HFile, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5pysam_10libchtslib_HFile, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_5pysam_10libchtslib_5HFile_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_10libchtslib_HFile, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; static PyMethodDef __pyx_methods[] = { {"set_verbosity", (PyCFunction)__pyx_pw_5pysam_10libchtslib_1set_verbosity, METH_O, __pyx_doc_5pysam_10libchtslib_set_verbosity}, @@ -7351,6 +14422,7 @@ static struct PyModuleDef __pyx_moduledef = { static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_ALIGNMENTS, __pyx_k_ALIGNMENTS, sizeof(__pyx_k_ALIGNMENTS), 0, 0, 1, 1}, + {&__pyx_kp_s_An_error_occured_while_applying, __pyx_k_An_error_occured_while_applying, sizeof(__pyx_k_An_error_occured_while_applying), 0, 0, 1, 0}, {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1}, {&__pyx_n_s_BAI, __pyx_k_BAI, sizeof(__pyx_k_BAI), 0, 0, 1, 1}, {&__pyx_n_s_BAM, __pyx_k_BAM, sizeof(__pyx_k_BAM), 0, 0, 1, 1}, @@ -7374,14 +14446,21 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_Cannot_create_hfile, __pyx_k_Cannot_create_hfile, sizeof(__pyx_k_Cannot_create_hfile), 0, 0, 1, 0}, {&__pyx_n_s_GZI, __pyx_k_GZI, sizeof(__pyx_k_GZI), 0, 0, 1, 1}, {&__pyx_n_s_GZIP, __pyx_k_GZIP, sizeof(__pyx_k_GZIP), 0, 0, 1, 1}, + {&__pyx_n_s_HFile, __pyx_k_HFile, sizeof(__pyx_k_HFile), 0, 0, 1, 1}, + {&__pyx_n_s_HTSFile, __pyx_k_HTSFile, sizeof(__pyx_k_HTSFile), 0, 0, 1, 1}, {&__pyx_n_s_INDEX, __pyx_k_INDEX, sizeof(__pyx_k_INDEX), 0, 0, 1, 1}, {&__pyx_n_s_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 0, 0, 1, 1}, {&__pyx_kp_s_I_O_operation_on_closed_file, __pyx_k_I_O_operation_on_closed_file, sizeof(__pyx_k_I_O_operation_on_closed_file), 0, 0, 1, 0}, + {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1}, + {&__pyx_kp_s_Invalid_format_option_specified, __pyx_k_Invalid_format_option_specified, sizeof(__pyx_k_Invalid_format_option_specified), 0, 0, 1, 0}, {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, {&__pyx_n_s_NONE, __pyx_k_NONE, sizeof(__pyx_k_NONE), 0, 0, 1, 1}, - {&__pyx_n_s_OSError, __pyx_k_OSError, sizeof(__pyx_k_OSError), 0, 0, 1, 1}, + {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1}, + {&__pyx_n_s_OverflowError, __pyx_k_OverflowError, sizeof(__pyx_k_OverflowError), 0, 0, 1, 1}, {&__pyx_n_s_REGIONS, __pyx_k_REGIONS, sizeof(__pyx_k_REGIONS), 0, 0, 1, 1}, + {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1}, {&__pyx_n_s_SAM, __pyx_k_SAM, sizeof(__pyx_k_SAM), 0, 0, 1, 1}, + {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1}, {&__pyx_n_s_TBI, __pyx_k_TBI, sizeof(__pyx_k_TBI), 0, 0, 1, 1}, {&__pyx_n_s_TEXT_FORMAT, __pyx_k_TEXT_FORMAT, sizeof(__pyx_k_TEXT_FORMAT), 0, 0, 1, 1}, {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, @@ -7389,8 +14468,10 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_VARIANTS, __pyx_k_VARIANTS, sizeof(__pyx_k_VARIANTS), 0, 0, 1, 1}, {&__pyx_n_s_VCF, __pyx_k_VCF, sizeof(__pyx_k_VCF), 0, 0, 1, 1}, {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, - {&__pyx_kp_b__16, __pyx_k__16, sizeof(__pyx_k__16), 0, 0, 0, 0}, - {&__pyx_kp_b__20, __pyx_k__20, sizeof(__pyx_k__20), 0, 0, 0, 0}, + {&__pyx_kp_s__36, __pyx_k__36, sizeof(__pyx_k__36), 0, 0, 1, 0}, + {&__pyx_kp_s__38, __pyx_k__38, sizeof(__pyx_k__38), 0, 0, 1, 0}, + {&__pyx_kp_s__39, __pyx_k__39, sizeof(__pyx_k__39), 0, 0, 1, 0}, + {&__pyx_kp_b__6, __pyx_k__6, sizeof(__pyx_k__6), 0, 0, 0, 0}, {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1}, {&__pyx_n_b_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 0, 1}, {&__pyx_n_s_bool, __pyx_k_bool, sizeof(__pyx_k_bool), 0, 0, 1, 1}, @@ -7398,60 +14479,112 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_call, __pyx_k_call, sizeof(__pyx_k_call), 0, 0, 1, 1}, {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1}, + {&__pyx_n_s_closedf, __pyx_k_closedf, sizeof(__pyx_k_closedf), 0, 0, 1, 1}, + {&__pyx_n_s_contig, __pyx_k_contig, sizeof(__pyx_k_contig), 0, 0, 1, 1}, + {&__pyx_kp_s_contig_and_reference_should_not, __pyx_k_contig_and_reference_should_not, sizeof(__pyx_k_contig_and_reference_should_not), 0, 0, 1, 0}, {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1}, + {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1}, {&__pyx_n_s_eq, __pyx_k_eq, sizeof(__pyx_k_eq), 0, 0, 1, 1}, + {&__pyx_kp_s_error_checking_for_EOF_marker, __pyx_k_error_checking_for_EOF_marker, sizeof(__pyx_k_error_checking_for_EOF_marker), 0, 0, 1, 0}, {&__pyx_n_s_exc_type, __pyx_k_exc_type, sizeof(__pyx_k_exc_type), 0, 0, 1, 1}, {&__pyx_n_s_exc_value, __pyx_k_exc_value, sizeof(__pyx_k_exc_value), 0, 0, 1, 1}, - {&__pyx_n_s_exists, __pyx_k_exists, sizeof(__pyx_k_exists), 0, 0, 1, 1}, + {&__pyx_kp_s_failed_to_close_HFile, __pyx_k_failed_to_close_HFile, sizeof(__pyx_k_failed_to_close_HFile), 0, 0, 1, 0}, + {&__pyx_kp_s_failed_to_flush_HFile, __pyx_k_failed_to_flush_HFile, sizeof(__pyx_k_failed_to_flush_HFile), 0, 0, 1, 0}, + {&__pyx_kp_s_failed_to_open_HFile, __pyx_k_failed_to_open_HFile, sizeof(__pyx_k_failed_to_open_HFile), 0, 0, 1, 0}, + {&__pyx_kp_s_failed_to_read_HFile, __pyx_k_failed_to_read_HFile, sizeof(__pyx_k_failed_to_read_HFile), 0, 0, 1, 0}, {&__pyx_kp_s_fd, __pyx_k_fd, sizeof(__pyx_k_fd), 0, 0, 1, 0}, {&__pyx_n_s_fileno, __pyx_k_fileno, sizeof(__pyx_k_fileno), 0, 0, 1, 1}, + {&__pyx_kp_s_fileno_not_available, __pyx_k_fileno_not_available, sizeof(__pyx_k_fileno_not_available), 0, 0, 1, 0}, {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1}, + {&__pyx_n_s_format_options, __pyx_k_format_options, sizeof(__pyx_k_format_options), 0, 0, 1, 1}, + {&__pyx_n_s_get_tid, __pyx_k_get_tid, sizeof(__pyx_k_get_tid), 0, 0, 1, 1}, {&__pyx_n_s_get_verbosity, __pyx_k_get_verbosity, sizeof(__pyx_k_get_verbosity), 0, 0, 1, 1}, {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, + {&__pyx_n_s_ignore_truncation, __pyx_k_ignore_truncation, sizeof(__pyx_k_ignore_truncation), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1}, + {&__pyx_kp_s_invalid_contig_s, __pyx_k_invalid_contig_s, sizeof(__pyx_k_invalid_contig_s), 0, 0, 1, 0}, + {&__pyx_kp_s_invalid_coordinates_start_i_stop, __pyx_k_invalid_coordinates_start_i_stop, sizeof(__pyx_k_invalid_coordinates_start_i_stop), 0, 0, 1, 0}, + {&__pyx_kp_s_invalid_tid, __pyx_k_invalid_tid, sizeof(__pyx_k_invalid_tid), 0, 0, 1, 0}, + {&__pyx_n_s_io, __pyx_k_io, sizeof(__pyx_k_io), 0, 0, 1, 1}, {&__pyx_n_s_is_open, __pyx_k_is_open, sizeof(__pyx_k_is_open), 0, 0, 1, 1}, + {&__pyx_n_s_is_valid_tid, __pyx_k_is_valid_tid, sizeof(__pyx_k_is_valid_tid), 0, 0, 1, 1}, + {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_memoryview, __pyx_k_memoryview, sizeof(__pyx_k_memoryview), 0, 0, 1, 1}, {&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1}, {&__pyx_kp_s_metadata_not_available_on_closed, __pyx_k_metadata_not_available_on_closed, sizeof(__pyx_k_metadata_not_available_on_closed), 0, 0, 1, 0}, + {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1}, {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1}, {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1}, {&__pyx_n_s_ne, __pyx_k_ne, sizeof(__pyx_k_ne), 0, 0, 1, 1}, + {&__pyx_kp_s_no_BGZF_EOF_marker_file_may_be_t, __pyx_k_no_BGZF_EOF_marker_file_may_be_t, sizeof(__pyx_k_no_BGZF_EOF_marker_file_may_be_t), 0, 0, 1, 0}, {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0}, {&__pyx_n_s_nonzero, __pyx_k_nonzero, sizeof(__pyx_k_nonzero), 0, 0, 1, 1}, {&__pyx_n_s_object, __pyx_k_object, sizeof(__pyx_k_object), 0, 0, 1, 1}, + {&__pyx_n_s_offset, __pyx_k_offset, sizeof(__pyx_k_offset), 0, 0, 1, 1}, + {&__pyx_kp_s_operation_on_closed_HFile, __pyx_k_operation_on_closed_HFile, sizeof(__pyx_k_operation_on_closed_HFile), 0, 0, 1, 0}, {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1}, {&__pyx_n_s_other, __pyx_k_other, sizeof(__pyx_k_other), 0, 0, 1, 1}, - {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1}, {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1}, {&__pyx_n_s_pysam_libchtslib, __pyx_k_pysam_libchtslib, sizeof(__pyx_k_pysam_libchtslib), 0, 0, 1, 1}, {&__pyx_kp_s_pysam_libchtslib_pyx, __pyx_k_pysam_libchtslib_pyx, sizeof(__pyx_k_pysam_libchtslib_pyx), 0, 0, 1, 0}, {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1}, {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1}, + {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1}, + {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1}, + {&__pyx_n_s_read, __pyx_k_read, sizeof(__pyx_k_read), 0, 0, 1, 1}, + {&__pyx_n_s_readline, __pyx_k_readline, sizeof(__pyx_k_readline), 0, 0, 1, 1}, {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, + {&__pyx_n_s_reference, __pyx_k_reference, sizeof(__pyx_k_reference), 0, 0, 1, 1}, + {&__pyx_n_s_region, __pyx_k_region, sizeof(__pyx_k_region), 0, 0, 1, 1}, {&__pyx_n_s_replace, __pyx_k_replace, sizeof(__pyx_k_replace), 0, 0, 1, 1}, {&__pyx_n_s_seek, __pyx_k_seek, sizeof(__pyx_k_seek), 0, 0, 1, 1}, + {&__pyx_kp_s_seek_failed_on_HFile, __pyx_k_seek_failed_on_HFile, sizeof(__pyx_k_seek_failed_on_HFile), 0, 0, 1, 0}, {&__pyx_kp_s_seek_not_available_in_streams, __pyx_k_seek_not_available_in_streams, sizeof(__pyx_k_seek_not_available_in_streams), 0, 0, 1, 0}, + {&__pyx_kp_s_seek_not_implemented_in_files_co, __pyx_k_seek_not_implemented_in_files_co, sizeof(__pyx_k_seek_not_implemented_in_files_co), 0, 0, 1, 0}, {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1}, + {&__pyx_kp_s_self_fp_cannot_be_converted_to_a, __pyx_k_self_fp_cannot_be_converted_to_a, sizeof(__pyx_k_self_fp_cannot_be_converted_to_a), 0, 0, 1, 0}, {&__pyx_n_s_set_verbosity, __pyx_k_set_verbosity, sizeof(__pyx_k_set_verbosity), 0, 0, 1, 1}, {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, + {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1}, + {&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1}, + {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1}, + {&__pyx_kp_s_start_out_of_range_i, __pyx_k_start_out_of_range_i, sizeof(__pyx_k_start_out_of_range_i), 0, 0, 1, 0}, + {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1}, + {&__pyx_kp_s_stop_and_end_should_not_both_be, __pyx_k_stop_and_end_should_not_both_be, sizeof(__pyx_k_stop_and_end_should_not_both_be), 0, 0, 1, 0}, + {&__pyx_kp_s_stop_out_of_range_i, __pyx_k_stop_out_of_range_i, sizeof(__pyx_k_stop_out_of_range_i), 0, 0, 1, 0}, + {&__pyx_n_s_tb, __pyx_k_tb, sizeof(__pyx_k_tb), 0, 0, 1, 1}, + {&__pyx_kp_s_tell_failed_on_HFile, __pyx_k_tell_failed_on_HFile, sizeof(__pyx_k_tell_failed_on_HFile), 0, 0, 1, 0}, {&__pyx_kp_s_tell_not_available_in_streams, __pyx_k_tell_not_available_in_streams, sizeof(__pyx_k_tell_not_available_in_streams), 0, 0, 1, 0}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_s_tid, __pyx_k_tid, sizeof(__pyx_k_tid), 0, 0, 1, 1}, {&__pyx_n_s_traceback, __pyx_k_traceback, sizeof(__pyx_k_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_type, __pyx_k_type, sizeof(__pyx_k_type), 0, 0, 1, 1}, {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1}, + {&__pyx_n_s_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 0, 1, 1}, + {&__pyx_n_s_warn, __pyx_k_warn, sizeof(__pyx_k_warn), 0, 0, 1, 1}, + {&__pyx_n_s_warnings, __pyx_k_warnings, sizeof(__pyx_k_warnings), 0, 0, 1, 1}, + {&__pyx_n_s_whence, __pyx_k_whence, sizeof(__pyx_k_whence), 0, 0, 1, 1}, + {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1}, + {&__pyx_kp_s_write_failed_on_HFile, __pyx_k_write_failed_on_HFile, sizeof(__pyx_k_write_failed_on_HFile), 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) __PYX_ERR(0, 38, __pyx_L1_error) - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 82, __pyx_L1_error) - __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 189, __pyx_L1_error) - __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 246, __pyx_L1_error) - __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 251, __pyx_L1_error) + __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) __PYX_ERR(0, 302, __pyx_L1_error) + __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 101, __pyx_L1_error) + __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 119, __pyx_L1_error) + __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 133, __pyx_L1_error) + __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 275, __pyx_L1_error) __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 379, __pyx_L1_error) + __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(0, 585, __pyx_L1_error) + __pyx_builtin_OverflowError = __Pyx_GetBuiltinName(__pyx_n_s_OverflowError); if (!__pyx_builtin_OverflowError) __PYX_ERR(0, 653, __pyx_L1_error) + __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(0, 673, __pyx_L1_error) __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(3, 109, __pyx_L1_error) return 0; __pyx_L1_error:; @@ -7462,129 +14595,313 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "pysam/libchtslib.pyx":82 + /* "pysam/libchtslib.pyx":115 + * def fileno(self): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * if isinstance(self.name, int): + * return self.name + */ + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_operation_on_closed_HFile); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 115, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple_); + __Pyx_GIVEREF(__pyx_tuple_); + + /* "pysam/libchtslib.pyx":119 + * return self.name + * else: + * raise AttributeError('fileno not available') # <<<<<<<<<<<<<< + * + * def __enter__(self): + */ + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_fileno_not_available); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__2); + __Pyx_GIVEREF(__pyx_tuple__2); + + /* "pysam/libchtslib.pyx":138 + * def flush(self): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * if hflush(self.fp) != 0: + * raise IOError(herrno(self.fp), 'failed to flush HFile', self.name) + */ + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_operation_on_closed_HFile); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 138, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); + + /* "pysam/libchtslib.pyx":144 + * def isatty(self): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * return False + * + */ + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_operation_on_closed_HFile); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 144, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); + + /* "pysam/libchtslib.pyx":152 + * def read(self, Py_ssize_t size=-1): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * + * if size == 0: + */ + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_operation_on_closed_HFile); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__5); + __Pyx_GIVEREF(__pyx_tuple__5); + + /* "pysam/libchtslib.pyx":190 + * def readinto(self, buf): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * + * size = len(buf) + */ + __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_operation_on_closed_HFile); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 190, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__7); + __Pyx_GIVEREF(__pyx_tuple__7); + + /* "pysam/libchtslib.pyx":207 + * def readline(self, Py_ssize_t size=-1): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * + * if size == 0: + */ + __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_operation_on_closed_HFile); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 207, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__8); + __Pyx_GIVEREF(__pyx_tuple__8); + + /* "pysam/libchtslib.pyx":251 + * def seek(self, Py_ssize_t offset, int whence=SEEK_SET): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * + * cdef Py_ssize_t off = hseek(self.fp, offset, whence) + */ + __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_operation_on_closed_HFile); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 251, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__9); + __Pyx_GIVEREF(__pyx_tuple__9); + + /* "pysam/libchtslib.pyx":262 + * def tell(self): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * + * ret = htell(self.fp) + */ + __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_operation_on_closed_HFile); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 262, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__10); + __Pyx_GIVEREF(__pyx_tuple__10); + + /* "pysam/libchtslib.pyx":282 + * def write(self, bytes b): + * if self.fp == NULL: + * raise IOError('operation on closed HFile') # <<<<<<<<<<<<<< + * + * got = hwrite(self.fp, b, len(b)) + */ + __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_operation_on_closed_HFile); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 282, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__11); + __Pyx_GIVEREF(__pyx_tuple__11); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("self.fp cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self.fp cannot be converted to a Python object for pickling") + */ + __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_self_fp_cannot_be_converted_to_a); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__12); + __Pyx_GIVEREF(__pyx_tuple__12); + + /* "(tree fragment)":4 + * raise TypeError("self.fp cannot be converted to a Python object for pickling") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("self.fp cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + */ + __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_self_fp_cannot_be_converted_to_a); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__13); + __Pyx_GIVEREF(__pyx_tuple__13); + + /* "pysam/libchtslib.pyx":379 * VARIANTS, INDEX, REGIONS""" * if not self.htsfile: * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< * return FORMAT_CATEGORIES[self.htsfile.format.category] * */ - __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_metadata_not_available_on_closed); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 82, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__7); - __Pyx_GIVEREF(__pyx_tuple__7); + __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_metadata_not_available_on_closed); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 379, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__20); + __Pyx_GIVEREF(__pyx_tuple__20); - /* "pysam/libchtslib.pyx":93 + /* "pysam/libchtslib.pyx":390 * """ * if not self.htsfile: * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< * return FORMATS[self.htsfile.format.format] * */ - __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_metadata_not_available_on_closed); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 93, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__8); - __Pyx_GIVEREF(__pyx_tuple__8); + __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_metadata_not_available_on_closed); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 390, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__21); + __Pyx_GIVEREF(__pyx_tuple__21); - /* "pysam/libchtslib.pyx":100 + /* "pysam/libchtslib.pyx":397 * """Tuple of file format version numbers (major, minor)""" * if not self.htsfile: * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< * return self.htsfile.format.version.major, self.htsfile.format.version.minor * */ - __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_metadata_not_available_on_closed); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 100, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__9); - __Pyx_GIVEREF(__pyx_tuple__9); + __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_metadata_not_available_on_closed); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 397, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__22); + __Pyx_GIVEREF(__pyx_tuple__22); - /* "pysam/libchtslib.pyx":109 + /* "pysam/libchtslib.pyx":406 * One of NONE, GZIP, BGZF, CUSTOM.""" * if not self.htsfile: * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< * return COMPRESSION[self.htsfile.format.compression] * */ - __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_metadata_not_available_on_closed); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 109, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__10); - __Pyx_GIVEREF(__pyx_tuple__10); + __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_metadata_not_available_on_closed); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 406, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__23); + __Pyx_GIVEREF(__pyx_tuple__23); - /* "pysam/libchtslib.pyx":116 + /* "pysam/libchtslib.pyx":413 * """Vaguely human readable description of the file format""" * if not self.htsfile: * raise ValueError('metadata not available on closed file') # <<<<<<<<<<<<<< * cdef char *desc = hts_format_description(&self.htsfile.format) * try: */ - __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_metadata_not_available_on_closed); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 116, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__11); - __Pyx_GIVEREF(__pyx_tuple__11); + __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_metadata_not_available_on_closed); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 413, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__24); + __Pyx_GIVEREF(__pyx_tuple__24); - /* "pysam/libchtslib.pyx":187 + /* "pysam/libchtslib.pyx":484 * """move file pointer to position *offset*, see :meth:`pysam.HTSFile.tell`.""" * if not self.is_open: * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< * if self.is_stream: - * raise OSError('seek not available in streams') + * raise IOError('seek not available in streams') */ - __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 187, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__12); - __Pyx_GIVEREF(__pyx_tuple__12); + __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 484, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__25); + __Pyx_GIVEREF(__pyx_tuple__25); - /* "pysam/libchtslib.pyx":189 + /* "pysam/libchtslib.pyx":486 * raise ValueError('I/O operation on closed file') * if self.is_stream: - * raise OSError('seek not available in streams') # <<<<<<<<<<<<<< + * raise IOError('seek not available in streams') # <<<<<<<<<<<<<< * * cdef int64_t ret */ - __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_seek_not_available_in_streams); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 189, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__13); - __Pyx_GIVEREF(__pyx_tuple__13); + __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_seek_not_available_in_streams); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__26); + __Pyx_GIVEREF(__pyx_tuple__26); - /* "pysam/libchtslib.pyx":203 + /* "pysam/libchtslib.pyx":503 * """return current file position, see :meth:`pysam.HTSFile.seek`.""" * if not self.is_open: * raise ValueError('I/O operation on closed file') # <<<<<<<<<<<<<< * if self.is_stream: - * raise OSError('tell not available in streams') + * raise IOError('tell not available in streams') */ - __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 203, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__14); - __Pyx_GIVEREF(__pyx_tuple__14); + __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__27); + __Pyx_GIVEREF(__pyx_tuple__27); - /* "pysam/libchtslib.pyx":205 + /* "pysam/libchtslib.pyx":505 * raise ValueError('I/O operation on closed file') * if self.is_stream: - * raise OSError('tell not available in streams') # <<<<<<<<<<<<<< + * raise IOError('tell not available in streams') # <<<<<<<<<<<<<< * * cdef int64_t ret */ - __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_tell_not_available_in_streams); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 205, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__15); - __Pyx_GIVEREF(__pyx_tuple__15); + __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_s_tell_not_available_in_streams); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 505, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__28); + __Pyx_GIVEREF(__pyx_tuple__28); - /* "pysam/libchtslib.pyx":237 + /* "pysam/libchtslib.pyx":548 * * # Replicate mode normalization done in hts_open_format * smode = self.mode.replace(b'b', b'').replace(b'c', b'') # <<<<<<<<<<<<<< * if b'b' in self.mode: * smode += b'b' */ - __pyx_tuple__17 = PyTuple_Pack(2, __pyx_n_b_b, __pyx_kp_b__16); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__17); - __Pyx_GIVEREF(__pyx_tuple__17); - __pyx_tuple__18 = PyTuple_Pack(2, __pyx_n_b_c, __pyx_kp_b__16); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 237, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__18); - __Pyx_GIVEREF(__pyx_tuple__18); + __pyx_tuple__29 = PyTuple_Pack(2, __pyx_n_b_b, __pyx_kp_b__6); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 548, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__29); + __Pyx_GIVEREF(__pyx_tuple__29); + __pyx_tuple__30 = PyTuple_Pack(2, __pyx_n_b_c, __pyx_kp_b__6); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 548, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__30); + __Pyx_GIVEREF(__pyx_tuple__30); - /* "pysam/libchtslib.pyx":246 + /* "pysam/libchtslib.pyx":557 * hfile = hdopen(dup_fd, cmode) * if hfile == NULL: * raise IOError('Cannot create hfile') # <<<<<<<<<<<<<< * * try: */ - __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_Cannot_create_hfile); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__19); - __Pyx_GIVEREF(__pyx_tuple__19); + __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s_Cannot_create_hfile); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__31); + __Pyx_GIVEREF(__pyx_tuple__31); + + /* "pysam/libchtslib.pyx":590 + * if rval != 0: + * hts_opt_free(opts) + * raise RuntimeError('An error occured while applying the requested format options') # <<<<<<<<<<<<<< + * hts_opt_free(opts) + * + */ + __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_s_An_error_occured_while_applying); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 590, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__32); + __Pyx_GIVEREF(__pyx_tuple__32); + + /* "pysam/libchtslib.pyx":636 + * if reference is not None: + * if contig is not None: + * raise ValueError('contig and reference should not both be specified') # <<<<<<<<<<<<<< + * contig = reference + * + */ + __pyx_tuple__33 = PyTuple_Pack(1, __pyx_kp_s_contig_and_reference_should_not); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 636, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__33); + __Pyx_GIVEREF(__pyx_tuple__33); + + /* "pysam/libchtslib.pyx":641 + * if end is not None: + * if stop is not None: + * raise ValueError('stop and end should not both be specified') # <<<<<<<<<<<<<< + * stop = end + * + */ + __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_s_stop_and_end_should_not_both_be); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 641, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__34); + __Pyx_GIVEREF(__pyx_tuple__34); + + /* "pysam/libchtslib.pyx":645 + * + * if contig is None and tid is None and region is None: + * return 0, 0, 0, 0 # <<<<<<<<<<<<<< + * + * rtid = -1 + */ + __pyx_tuple__35 = PyTuple_Pack(4, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_int_0); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 645, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__35); + __Pyx_GIVEREF(__pyx_tuple__35); + + /* "pysam/libchtslib.pyx":673 + * if tid is not None: + * if not self.is_valid_tid(tid): + * raise IndexError('invalid tid') # <<<<<<<<<<<<<< + * rtid = tid + * else: + */ + __pyx_tuple__37 = PyTuple_Pack(1, __pyx_kp_s_invalid_tid); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 673, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__37); + __Pyx_GIVEREF(__pyx_tuple__37); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -7592,156 +14909,156 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__21); - __Pyx_GIVEREF(__pyx_tuple__21); + __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__40); + __Pyx_GIVEREF(__pyx_tuple__40); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__22); - __Pyx_GIVEREF(__pyx_tuple__22); + __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__41); + __Pyx_GIVEREF(__pyx_tuple__41); - /* "pysam/libchtslib.pyx":23 - * + /* "pysam/libchtslib.pyx":46 * cdef int MAX_POS = 2 << 29 + * * cdef tuple FORMAT_CATEGORIES = ('UNKNOWN', 'ALIGNMENTS', 'VARIANTS', 'INDEX', 'REGIONS') # <<<<<<<<<<<<<< * cdef tuple FORMATS = ('UNKNOWN', 'BINARY_FORMAT', 'TEXT_FORMAT', 'SAM', 'BAM', 'BAI', 'CRAM', 'CRAI', * 'VCF', 'BCF', 'CSI', 'GZI', 'TBI', 'BED') */ - __pyx_tuple__23 = PyTuple_Pack(5, __pyx_n_s_UNKNOWN, __pyx_n_s_ALIGNMENTS, __pyx_n_s_VARIANTS, __pyx_n_s_INDEX, __pyx_n_s_REGIONS); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 23, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__23); - __Pyx_GIVEREF(__pyx_tuple__23); + __pyx_tuple__42 = PyTuple_Pack(5, __pyx_n_s_UNKNOWN, __pyx_n_s_ALIGNMENTS, __pyx_n_s_VARIANTS, __pyx_n_s_INDEX, __pyx_n_s_REGIONS); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 46, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__42); + __Pyx_GIVEREF(__pyx_tuple__42); - /* "pysam/libchtslib.pyx":24 - * cdef int MAX_POS = 2 << 29 + /* "pysam/libchtslib.pyx":47 + * * cdef tuple FORMAT_CATEGORIES = ('UNKNOWN', 'ALIGNMENTS', 'VARIANTS', 'INDEX', 'REGIONS') * cdef tuple FORMATS = ('UNKNOWN', 'BINARY_FORMAT', 'TEXT_FORMAT', 'SAM', 'BAM', 'BAI', 'CRAM', 'CRAI', # <<<<<<<<<<<<<< * 'VCF', 'BCF', 'CSI', 'GZI', 'TBI', 'BED') * cdef tuple COMPRESSION = ('NONE', 'GZIP', 'BGZF', 'CUSTOM') */ - __pyx_tuple__24 = PyTuple_Pack(14, __pyx_n_s_UNKNOWN, __pyx_n_s_BINARY_FORMAT, __pyx_n_s_TEXT_FORMAT, __pyx_n_s_SAM, __pyx_n_s_BAM, __pyx_n_s_BAI, __pyx_n_s_CRAM, __pyx_n_s_CRAI, __pyx_n_s_VCF, __pyx_n_s_BCF, __pyx_n_s_CSI, __pyx_n_s_GZI, __pyx_n_s_TBI, __pyx_n_s_BED); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 24, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__24); - __Pyx_GIVEREF(__pyx_tuple__24); + __pyx_tuple__43 = PyTuple_Pack(14, __pyx_n_s_UNKNOWN, __pyx_n_s_BINARY_FORMAT, __pyx_n_s_TEXT_FORMAT, __pyx_n_s_SAM, __pyx_n_s_BAM, __pyx_n_s_BAI, __pyx_n_s_CRAM, __pyx_n_s_CRAI, __pyx_n_s_VCF, __pyx_n_s_BCF, __pyx_n_s_CSI, __pyx_n_s_GZI, __pyx_n_s_TBI, __pyx_n_s_BED); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 47, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__43); + __Pyx_GIVEREF(__pyx_tuple__43); - /* "pysam/libchtslib.pyx":26 + /* "pysam/libchtslib.pyx":49 * cdef tuple FORMATS = ('UNKNOWN', 'BINARY_FORMAT', 'TEXT_FORMAT', 'SAM', 'BAM', 'BAI', 'CRAM', 'CRAI', * 'VCF', 'BCF', 'CSI', 'GZI', 'TBI', 'BED') * cdef tuple COMPRESSION = ('NONE', 'GZIP', 'BGZF', 'CUSTOM') # <<<<<<<<<<<<<< * * */ - __pyx_tuple__25 = PyTuple_Pack(4, __pyx_n_s_NONE, __pyx_n_s_GZIP, __pyx_n_s_BGZF, __pyx_n_s_CUSTOM); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 26, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__25); - __Pyx_GIVEREF(__pyx_tuple__25); + __pyx_tuple__44 = PyTuple_Pack(4, __pyx_n_s_NONE, __pyx_n_s_GZIP, __pyx_n_s_BGZF, __pyx_n_s_CUSTOM); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 49, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__44); + __Pyx_GIVEREF(__pyx_tuple__44); - /* "pysam/libchtslib.pyx":38 - * + /* "pysam/libchtslib.pyx":302 + * ######################################################################## * * class CallableValue(object): # <<<<<<<<<<<<<< * def __init__(self, value): * self.value = value */ - __pyx_tuple__26 = PyTuple_Pack(1, __pyx_builtin_object); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 38, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__26); - __Pyx_GIVEREF(__pyx_tuple__26); + __pyx_tuple__45 = PyTuple_Pack(1, __pyx_builtin_object); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 302, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__45); + __Pyx_GIVEREF(__pyx_tuple__45); - /* "pysam/libchtslib.pyx":39 + /* "pysam/libchtslib.pyx":303 * * class CallableValue(object): * def __init__(self, value): # <<<<<<<<<<<<<< * self.value = value * def __call__(self): */ - __pyx_tuple__27 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_value); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 39, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__27); - __Pyx_GIVEREF(__pyx_tuple__27); - __pyx_codeobj_ = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__27, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libchtslib_pyx, __pyx_n_s_init, 39, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 39, __pyx_L1_error) + __pyx_tuple__46 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_value); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 303, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__46); + __Pyx_GIVEREF(__pyx_tuple__46); + __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__46, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libchtslib_pyx, __pyx_n_s_init, 303, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 303, __pyx_L1_error) - /* "pysam/libchtslib.pyx":41 + /* "pysam/libchtslib.pyx":305 * def __init__(self, value): * self.value = value * def __call__(self): # <<<<<<<<<<<<<< * return self.value * def __bool__(self): */ - __pyx_tuple__28 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 41, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__28); - __Pyx_GIVEREF(__pyx_tuple__28); - __pyx_codeobj__2 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libchtslib_pyx, __pyx_n_s_call, 41, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__2)) __PYX_ERR(0, 41, __pyx_L1_error) + __pyx_tuple__47 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 305, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__47); + __Pyx_GIVEREF(__pyx_tuple__47); + __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__47, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libchtslib_pyx, __pyx_n_s_call, 305, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(0, 305, __pyx_L1_error) - /* "pysam/libchtslib.pyx":43 + /* "pysam/libchtslib.pyx":307 * def __call__(self): * return self.value * def __bool__(self): # <<<<<<<<<<<<<< * return self.value * def __nonzero__(self): */ - __pyx_tuple__29 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 43, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__29); - __Pyx_GIVEREF(__pyx_tuple__29); - __pyx_codeobj__3 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__29, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libchtslib_pyx, __pyx_n_s_bool, 43, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__3)) __PYX_ERR(0, 43, __pyx_L1_error) + __pyx_tuple__48 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__48); + __Pyx_GIVEREF(__pyx_tuple__48); + __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__48, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libchtslib_pyx, __pyx_n_s_bool, 307, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 307, __pyx_L1_error) - /* "pysam/libchtslib.pyx":45 + /* "pysam/libchtslib.pyx":309 * def __bool__(self): * return self.value * def __nonzero__(self): # <<<<<<<<<<<<<< * return self.value * def __eq__(self, other): */ - __pyx_tuple__30 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 45, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__30); - __Pyx_GIVEREF(__pyx_tuple__30); - __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libchtslib_pyx, __pyx_n_s_nonzero, 45, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_tuple__49 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 309, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__49); + __Pyx_GIVEREF(__pyx_tuple__49); + __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libchtslib_pyx, __pyx_n_s_nonzero, 309, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 309, __pyx_L1_error) - /* "pysam/libchtslib.pyx":47 + /* "pysam/libchtslib.pyx":311 * def __nonzero__(self): * return self.value * def __eq__(self, other): # <<<<<<<<<<<<<< * return self.value == other * def __ne__(self, other): */ - __pyx_tuple__31 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 47, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__31); - __Pyx_GIVEREF(__pyx_tuple__31); - __pyx_codeobj__5 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__31, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libchtslib_pyx, __pyx_n_s_eq, 47, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__5)) __PYX_ERR(0, 47, __pyx_L1_error) + __pyx_tuple__50 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 311, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__50); + __Pyx_GIVEREF(__pyx_tuple__50); + __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__50, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libchtslib_pyx, __pyx_n_s_eq, 311, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) __PYX_ERR(0, 311, __pyx_L1_error) - /* "pysam/libchtslib.pyx":49 + /* "pysam/libchtslib.pyx":313 * def __eq__(self, other): * return self.value == other * def __ne__(self, other): # <<<<<<<<<<<<<< * return self.value != other * */ - __pyx_tuple__32 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 49, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__32); - __Pyx_GIVEREF(__pyx_tuple__32); - __pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libchtslib_pyx, __pyx_n_s_ne, 49, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 49, __pyx_L1_error) + __pyx_tuple__51 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 313, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__51); + __Pyx_GIVEREF(__pyx_tuple__51); + __pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__51, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libchtslib_pyx, __pyx_n_s_ne, 313, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) __PYX_ERR(0, 313, __pyx_L1_error) - /* "pysam/libchtslib.pyx":53 + /* "pysam/libchtslib.pyx":317 * * * CTrue = CallableValue(True) # <<<<<<<<<<<<<< * CFalse = CallableValue(False) * */ - __pyx_tuple__33 = PyTuple_Pack(1, Py_True); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 53, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__33); - __Pyx_GIVEREF(__pyx_tuple__33); + __pyx_tuple__52 = PyTuple_Pack(1, Py_True); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(0, 317, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__52); + __Pyx_GIVEREF(__pyx_tuple__52); - /* "pysam/libchtslib.pyx":54 + /* "pysam/libchtslib.pyx":318 * * CTrue = CallableValue(True) * CFalse = CallableValue(False) # <<<<<<<<<<<<<< * * */ - __pyx_tuple__34 = PyTuple_Pack(1, Py_False); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__34); - __Pyx_GIVEREF(__pyx_tuple__34); + __pyx_tuple__53 = PyTuple_Pack(1, Py_False); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 318, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__53); + __Pyx_GIVEREF(__pyx_tuple__53); __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -7751,6 +15068,9 @@ static int __Pyx_InitCachedConstants(void) { static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; @@ -7797,15 +15117,26 @@ static int __Pyx_modinit_type_init_code(void) { /*--- Type init code ---*/ __pyx_vtabptr_5pysam_10libchtslib_HTSFile = &__pyx_vtable_5pysam_10libchtslib_HTSFile; __pyx_vtable_5pysam_10libchtslib_HTSFile._open_htsfile = (htsFile *(*)(struct __pyx_obj_5pysam_10libchtslib_HTSFile *))__pyx_f_5pysam_10libchtslib_7HTSFile__open_htsfile; - if (PyType_Ready(&__pyx_type_5pysam_10libchtslib_HTSFile) < 0) __PYX_ERR(0, 57, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_10libchtslib_HTSFile) < 0) __PYX_ERR(0, 326, __pyx_L1_error) __pyx_type_5pysam_10libchtslib_HTSFile.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_10libchtslib_HTSFile.tp_dictoffset && __pyx_type_5pysam_10libchtslib_HTSFile.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_10libchtslib_HTSFile.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_10libchtslib_HTSFile.tp_dict, __pyx_vtabptr_5pysam_10libchtslib_HTSFile) < 0) __PYX_ERR(0, 57, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "HTSFile", (PyObject *)&__pyx_type_5pysam_10libchtslib_HTSFile) < 0) __PYX_ERR(0, 57, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_10libchtslib_HTSFile) < 0) __PYX_ERR(0, 57, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_10libchtslib_HTSFile.tp_dict, __pyx_vtabptr_5pysam_10libchtslib_HTSFile) < 0) __PYX_ERR(0, 326, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "HTSFile", (PyObject *)&__pyx_type_5pysam_10libchtslib_HTSFile) < 0) __PYX_ERR(0, 326, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_10libchtslib_HTSFile) < 0) __PYX_ERR(0, 326, __pyx_L1_error) __pyx_ptype_5pysam_10libchtslib_HTSFile = &__pyx_type_5pysam_10libchtslib_HTSFile; + __pyx_vtabptr_5pysam_10libchtslib_HFile = &__pyx_vtable_5pysam_10libchtslib_HFile; + __pyx_vtable_5pysam_10libchtslib_HFile._open = (PyObject *(*)(struct __pyx_obj_5pysam_10libchtslib_HFile *, PyObject *, PyObject *, struct __pyx_opt_args_5pysam_10libchtslib_5HFile__open *__pyx_optional_args))__pyx_f_5pysam_10libchtslib_5HFile__open; + if (PyType_Ready(&__pyx_type_5pysam_10libchtslib_HFile) < 0) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_type_5pysam_10libchtslib_HFile.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_10libchtslib_HFile.tp_dictoffset && __pyx_type_5pysam_10libchtslib_HFile.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_10libchtslib_HFile.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (__Pyx_SetVtable(__pyx_type_5pysam_10libchtslib_HFile.tp_dict, __pyx_vtabptr_5pysam_10libchtslib_HFile) < 0) __PYX_ERR(0, 72, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "HFile", (PyObject *)&__pyx_type_5pysam_10libchtslib_HFile) < 0) __PYX_ERR(0, 72, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_10libchtslib_HFile) < 0) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_ptype_5pysam_10libchtslib_HFile = &__pyx_type_5pysam_10libchtslib_HFile; __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -8040,218 +15371,269 @@ if (!__Pyx_RefNanny) { #endif __Pyx_TraceCall("__Pyx_PyMODINIT_FUNC PyInit_libchtslib(void)", __pyx_f[0], 1, 0, __PYX_ERR(0, 1, __pyx_L1_error)); - /* "pysam/libchtslib.pyx":4 - * # cython: profile=True - * # adds doc-strings for sphinx - * import os # <<<<<<<<<<<<<< + /* "pysam/libchtslib.pyx":25 + * ######################################################################## * - * from posix.unistd cimport dup + * import os # <<<<<<<<<<<<<< + * import io + * import re */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 25, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libchtslib.pyx":14 + /* "pysam/libchtslib.pyx":26 * + * import os + * import io # <<<<<<<<<<<<<< + * import re + * from warnings import warn + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_io, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_io, __pyx_t_1) < 0) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libchtslib.pyx":27 + * import os + * import io + * import re # <<<<<<<<<<<<<< + * from warnings import warn * - * __all__ = ["get_verbosity", "set_verbosity"] # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_re, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_1) < 0) __PYX_ERR(0, 27, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libchtslib.pyx":28 + * import io + * import re + * from warnings import warn # <<<<<<<<<<<<<< * * */ - __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error) + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_warn); + __Pyx_GIVEREF(__pyx_n_s_warn); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_warn); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_warnings, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_warn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_warn, __pyx_t_1) < 0) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libchtslib.pyx":36 + * ######################################################################## + * + * __all__ = ['get_verbosity', 'set_verbosity', 'HFile', 'HTSFile'] # <<<<<<<<<<<<<< + * + * # defines imported from samtools + */ + __pyx_t_2 = PyList_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_get_verbosity); __Pyx_GIVEREF(__pyx_n_s_get_verbosity); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_get_verbosity); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_get_verbosity); __Pyx_INCREF(__pyx_n_s_set_verbosity); __Pyx_GIVEREF(__pyx_n_s_set_verbosity); - PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_set_verbosity); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 14, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_set_verbosity); + __Pyx_INCREF(__pyx_n_s_HFile); + __Pyx_GIVEREF(__pyx_n_s_HFile); + PyList_SET_ITEM(__pyx_t_2, 2, __pyx_n_s_HFile); + __Pyx_INCREF(__pyx_n_s_HTSFile); + __Pyx_GIVEREF(__pyx_n_s_HTSFile); + PyList_SET_ITEM(__pyx_t_2, 3, __pyx_n_s_HTSFile); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_2) < 0) __PYX_ERR(0, 36, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libchtslib.pyx":22 - * ######################################################################## + /* "pysam/libchtslib.pyx":44 * + * # maximum genomic coordinace * cdef int MAX_POS = 2 << 29 # <<<<<<<<<<<<<< + * * cdef tuple FORMAT_CATEGORIES = ('UNKNOWN', 'ALIGNMENTS', 'VARIANTS', 'INDEX', 'REGIONS') - * cdef tuple FORMATS = ('UNKNOWN', 'BINARY_FORMAT', 'TEXT_FORMAT', 'SAM', 'BAM', 'BAI', 'CRAM', 'CRAI', */ __pyx_v_5pysam_10libchtslib_MAX_POS = 0x40000000; - /* "pysam/libchtslib.pyx":23 - * + /* "pysam/libchtslib.pyx":46 * cdef int MAX_POS = 2 << 29 + * * cdef tuple FORMAT_CATEGORIES = ('UNKNOWN', 'ALIGNMENTS', 'VARIANTS', 'INDEX', 'REGIONS') # <<<<<<<<<<<<<< * cdef tuple FORMATS = ('UNKNOWN', 'BINARY_FORMAT', 'TEXT_FORMAT', 'SAM', 'BAM', 'BAI', 'CRAM', 'CRAI', * 'VCF', 'BCF', 'CSI', 'GZI', 'TBI', 'BED') */ - __Pyx_INCREF(__pyx_tuple__23); + __Pyx_INCREF(__pyx_tuple__42); __Pyx_XGOTREF(__pyx_v_5pysam_10libchtslib_FORMAT_CATEGORIES); - __Pyx_DECREF_SET(__pyx_v_5pysam_10libchtslib_FORMAT_CATEGORIES, __pyx_tuple__23); - __Pyx_GIVEREF(__pyx_tuple__23); + __Pyx_DECREF_SET(__pyx_v_5pysam_10libchtslib_FORMAT_CATEGORIES, __pyx_tuple__42); + __Pyx_GIVEREF(__pyx_tuple__42); - /* "pysam/libchtslib.pyx":24 - * cdef int MAX_POS = 2 << 29 + /* "pysam/libchtslib.pyx":47 + * * cdef tuple FORMAT_CATEGORIES = ('UNKNOWN', 'ALIGNMENTS', 'VARIANTS', 'INDEX', 'REGIONS') * cdef tuple FORMATS = ('UNKNOWN', 'BINARY_FORMAT', 'TEXT_FORMAT', 'SAM', 'BAM', 'BAI', 'CRAM', 'CRAI', # <<<<<<<<<<<<<< * 'VCF', 'BCF', 'CSI', 'GZI', 'TBI', 'BED') * cdef tuple COMPRESSION = ('NONE', 'GZIP', 'BGZF', 'CUSTOM') */ - __Pyx_INCREF(__pyx_tuple__24); + __Pyx_INCREF(__pyx_tuple__43); __Pyx_XGOTREF(__pyx_v_5pysam_10libchtslib_FORMATS); - __Pyx_DECREF_SET(__pyx_v_5pysam_10libchtslib_FORMATS, __pyx_tuple__24); - __Pyx_GIVEREF(__pyx_tuple__24); + __Pyx_DECREF_SET(__pyx_v_5pysam_10libchtslib_FORMATS, __pyx_tuple__43); + __Pyx_GIVEREF(__pyx_tuple__43); - /* "pysam/libchtslib.pyx":26 + /* "pysam/libchtslib.pyx":49 * cdef tuple FORMATS = ('UNKNOWN', 'BINARY_FORMAT', 'TEXT_FORMAT', 'SAM', 'BAM', 'BAI', 'CRAM', 'CRAI', * 'VCF', 'BCF', 'CSI', 'GZI', 'TBI', 'BED') * cdef tuple COMPRESSION = ('NONE', 'GZIP', 'BGZF', 'CUSTOM') # <<<<<<<<<<<<<< * * */ - __Pyx_INCREF(__pyx_tuple__25); + __Pyx_INCREF(__pyx_tuple__44); __Pyx_XGOTREF(__pyx_v_5pysam_10libchtslib_COMPRESSION); - __Pyx_DECREF_SET(__pyx_v_5pysam_10libchtslib_COMPRESSION, __pyx_tuple__25); - __Pyx_GIVEREF(__pyx_tuple__25); + __Pyx_DECREF_SET(__pyx_v_5pysam_10libchtslib_COMPRESSION, __pyx_tuple__44); + __Pyx_GIVEREF(__pyx_tuple__44); - /* "pysam/libchtslib.pyx":38 - * + /* "pysam/libchtslib.pyx":302 + * ######################################################################## * * class CallableValue(object): # <<<<<<<<<<<<<< * def __init__(self, value): * self.value = value */ - __pyx_t_1 = __Pyx_CalculateMetaclass(NULL, __pyx_tuple__26); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_Py3MetaclassPrepare(__pyx_t_1, __pyx_tuple__26, __pyx_n_s_CallableValue, __pyx_n_s_CallableValue, (PyObject *) NULL, __pyx_n_s_pysam_libchtslib, (PyObject *) NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 38, __pyx_L1_error) + __pyx_t_2 = __Pyx_CalculateMetaclass(NULL, __pyx_tuple__45); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 302, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_Py3MetaclassPrepare(__pyx_t_2, __pyx_tuple__45, __pyx_n_s_CallableValue, __pyx_n_s_CallableValue, (PyObject *) NULL, __pyx_n_s_pysam_libchtslib, (PyObject *) NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 302, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libchtslib.pyx":39 + /* "pysam/libchtslib.pyx":303 * * class CallableValue(object): * def __init__(self, value): # <<<<<<<<<<<<<< * self.value = value * def __call__(self): */ - __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_10libchtslib_13CallableValue_1__init__, 0, __pyx_n_s_CallableValue___init, NULL, __pyx_n_s_pysam_libchtslib, __pyx_d, ((PyObject *)__pyx_codeobj_)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 39, __pyx_L1_error) + __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_10libchtslib_13CallableValue_1__init__, 0, __pyx_n_s_CallableValue___init, NULL, __pyx_n_s_pysam_libchtslib, __pyx_d, ((PyObject *)__pyx_codeobj__14)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 303, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_n_s_init, __pyx_t_3) < 0) __PYX_ERR(0, 39, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_init, __pyx_t_3) < 0) __PYX_ERR(0, 303, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libchtslib.pyx":41 + /* "pysam/libchtslib.pyx":305 * def __init__(self, value): * self.value = value * def __call__(self): # <<<<<<<<<<<<<< * return self.value * def __bool__(self): */ - __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_10libchtslib_13CallableValue_3__call__, 0, __pyx_n_s_CallableValue___call, NULL, __pyx_n_s_pysam_libchtslib, __pyx_d, ((PyObject *)__pyx_codeobj__2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 41, __pyx_L1_error) + __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_10libchtslib_13CallableValue_3__call__, 0, __pyx_n_s_CallableValue___call, NULL, __pyx_n_s_pysam_libchtslib, __pyx_d, ((PyObject *)__pyx_codeobj__15)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_n_s_call, __pyx_t_3) < 0) __PYX_ERR(0, 41, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_call, __pyx_t_3) < 0) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libchtslib.pyx":43 + /* "pysam/libchtslib.pyx":307 * def __call__(self): * return self.value * def __bool__(self): # <<<<<<<<<<<<<< * return self.value * def __nonzero__(self): */ - __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_10libchtslib_13CallableValue_5__bool__, 0, __pyx_n_s_CallableValue___bool, NULL, __pyx_n_s_pysam_libchtslib, __pyx_d, ((PyObject *)__pyx_codeobj__3)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error) + __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_10libchtslib_13CallableValue_5__bool__, 0, __pyx_n_s_CallableValue___bool, NULL, __pyx_n_s_pysam_libchtslib, __pyx_d, ((PyObject *)__pyx_codeobj__16)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_n_s_bool, __pyx_t_3) < 0) __PYX_ERR(0, 43, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_bool, __pyx_t_3) < 0) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libchtslib.pyx":45 + /* "pysam/libchtslib.pyx":309 * def __bool__(self): * return self.value * def __nonzero__(self): # <<<<<<<<<<<<<< * return self.value * def __eq__(self, other): */ - __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_10libchtslib_13CallableValue_7__nonzero__, 0, __pyx_n_s_CallableValue___nonzero, NULL, __pyx_n_s_pysam_libchtslib, __pyx_d, ((PyObject *)__pyx_codeobj__4)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_10libchtslib_13CallableValue_7__nonzero__, 0, __pyx_n_s_CallableValue___nonzero, NULL, __pyx_n_s_pysam_libchtslib, __pyx_d, ((PyObject *)__pyx_codeobj__17)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 309, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_n_s_nonzero, __pyx_t_3) < 0) __PYX_ERR(0, 45, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_nonzero, __pyx_t_3) < 0) __PYX_ERR(0, 309, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libchtslib.pyx":47 + /* "pysam/libchtslib.pyx":311 * def __nonzero__(self): * return self.value * def __eq__(self, other): # <<<<<<<<<<<<<< * return self.value == other * def __ne__(self, other): */ - __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_10libchtslib_13CallableValue_9__eq__, 0, __pyx_n_s_CallableValue___eq, NULL, __pyx_n_s_pysam_libchtslib, __pyx_d, ((PyObject *)__pyx_codeobj__5)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 47, __pyx_L1_error) + __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_10libchtslib_13CallableValue_9__eq__, 0, __pyx_n_s_CallableValue___eq, NULL, __pyx_n_s_pysam_libchtslib, __pyx_d, ((PyObject *)__pyx_codeobj__18)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 311, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_n_s_eq, __pyx_t_3) < 0) __PYX_ERR(0, 47, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_eq, __pyx_t_3) < 0) __PYX_ERR(0, 311, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libchtslib.pyx":49 + /* "pysam/libchtslib.pyx":313 * def __eq__(self, other): * return self.value == other * def __ne__(self, other): # <<<<<<<<<<<<<< * return self.value != other * */ - __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_10libchtslib_13CallableValue_11__ne__, 0, __pyx_n_s_CallableValue___ne, NULL, __pyx_n_s_pysam_libchtslib, __pyx_d, ((PyObject *)__pyx_codeobj__6)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 49, __pyx_L1_error) + __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_10libchtslib_13CallableValue_11__ne__, 0, __pyx_n_s_CallableValue___ne, NULL, __pyx_n_s_pysam_libchtslib, __pyx_d, ((PyObject *)__pyx_codeobj__19)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 313, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_SetNameInClass(__pyx_t_2, __pyx_n_s_ne, __pyx_t_3) < 0) __PYX_ERR(0, 49, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_ne, __pyx_t_3) < 0) __PYX_ERR(0, 313, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libchtslib.pyx":38 - * + /* "pysam/libchtslib.pyx":302 + * ######################################################################## * * class CallableValue(object): # <<<<<<<<<<<<<< * def __init__(self, value): * self.value = value */ - __pyx_t_3 = __Pyx_Py3ClassCreate(__pyx_t_1, __pyx_n_s_CallableValue, __pyx_tuple__26, __pyx_t_2, NULL, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 38, __pyx_L1_error) + __pyx_t_3 = __Pyx_Py3ClassCreate(__pyx_t_2, __pyx_n_s_CallableValue, __pyx_tuple__45, __pyx_t_1, NULL, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 302, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_CallableValue, __pyx_t_3) < 0) __PYX_ERR(0, 38, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_CallableValue, __pyx_t_3) < 0) __PYX_ERR(0, 302, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libchtslib.pyx":53 + /* "pysam/libchtslib.pyx":317 * * * CTrue = CallableValue(True) # <<<<<<<<<<<<<< * CFalse = CallableValue(False) * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_CallableValue); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 53, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 53, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_CallableValue); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 317, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_CTrue, __pyx_t_2) < 0) __PYX_ERR(0, 53, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_CTrue, __pyx_t_1) < 0) __PYX_ERR(0, 317, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libchtslib.pyx":54 + /* "pysam/libchtslib.pyx":318 * * CTrue = CallableValue(True) * CFalse = CallableValue(False) # <<<<<<<<<<<<<< * * */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_CallableValue); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 54, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_CallableValue); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 318, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_CFalse, __pyx_t_1) < 0) __PYX_ERR(0, 54, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__53, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 318, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_CFalse, __pyx_t_2) < 0) __PYX_ERR(0, 318, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pysam/libchtslib.pyx":1 * # cython: embedsignature=True # <<<<<<<<<<<<<< * # cython: profile=True * # adds doc-strings for sphinx */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "array.pxd":161 * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) @@ -8451,32 +15833,6 @@ static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const cha } #endif -/* RaiseArgTupleInvalid */ -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *more_or_less; - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; - } - if (exact) { - more_or_less = "exactly"; - } - PyErr_Format(PyExc_TypeError, - "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", - func_name, more_or_less, num_expected, - (num_expected == 1) ? "" : "s", num_found); -} - /* RaiseDoubleKeywords */ static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, @@ -8593,100 +15949,30 @@ static int __Pyx_ParseOptionalKeywords( return -1; } -/* PyObjectSetAttrStr */ -#if CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { - PyTypeObject* tp = Py_TYPE(obj); - if (likely(tp->tp_setattro)) - return tp->tp_setattro(obj, attr_name, value); -#if PY_MAJOR_VERSION < 3 - if (likely(tp->tp_setattr)) - return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value); -#endif - return PyObject_SetAttr(obj, attr_name, value); -} -#endif - -/* KeywordStringCheck */ -static int __Pyx_CheckKeywordStrings( - PyObject *kwdict, - const char* function_name, - int kw_allowed) -{ - PyObject* key = 0; - Py_ssize_t pos = 0; -#if CYTHON_COMPILING_IN_PYPY - if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) - goto invalid_keyword; - return 1; -#else - while (PyDict_Next(kwdict, &pos, &key, 0)) { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_Check(key))) - #endif - if (unlikely(!PyUnicode_Check(key))) - goto invalid_keyword_type; - } - if ((!kw_allowed) && unlikely(key)) - goto invalid_keyword; - return 1; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%.200s() keywords must be strings", function_name); - return 0; -#endif -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%.200s() got an unexpected keyword argument '%.200s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif - return 0; -} - -/* WriteUnraisableException */ -static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, - CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename, - int full_traceback, CYTHON_UNUSED int nogil) { - PyObject *old_exc, *old_val, *old_tb; - PyObject *ctx; - __Pyx_PyThreadState_declare -#ifdef WITH_THREAD - PyGILState_STATE state; - if (nogil) - state = PyGILState_Ensure(); -#ifdef _MSC_VER - else state = (PyGILState_STATE)-1; -#endif -#endif - __Pyx_PyThreadState_assign - __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); - if (full_traceback) { - Py_XINCREF(old_exc); - Py_XINCREF(old_val); - Py_XINCREF(old_tb); - __Pyx_ErrRestore(old_exc, old_val, old_tb); - PyErr_PrintEx(1); - } - #if PY_MAJOR_VERSION < 3 - ctx = PyString_FromString(name); - #else - ctx = PyUnicode_FromString(name); - #endif - __Pyx_ErrRestore(old_exc, old_val, old_tb); - if (!ctx) { - PyErr_WriteUnraisable(Py_None); +/* RaiseArgTupleInvalid */ +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; } else { - PyErr_WriteUnraisable(ctx); - Py_DECREF(ctx); + num_expected = num_max; + more_or_less = "at most"; } -#ifdef WITH_THREAD - if (nogil) - PyGILState_Release(state); -#endif + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); } /* PyCFunctionFastCall */ @@ -8933,6 +16219,48 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { } #endif +/* WriteUnraisableException */ + static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, + CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename, + int full_traceback, CYTHON_UNUSED int nogil) { + PyObject *old_exc, *old_val, *old_tb; + PyObject *ctx; + __Pyx_PyThreadState_declare +#ifdef WITH_THREAD + PyGILState_STATE state; + if (nogil) + state = PyGILState_Ensure(); +#ifdef _MSC_VER + else state = (PyGILState_STATE)-1; +#endif +#endif + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); + if (full_traceback) { + Py_XINCREF(old_exc); + Py_XINCREF(old_val); + Py_XINCREF(old_tb); + __Pyx_ErrRestore(old_exc, old_val, old_tb); + PyErr_PrintEx(1); + } + #if PY_MAJOR_VERSION < 3 + ctx = PyString_FromString(name); + #else + ctx = PyUnicode_FromString(name); + #endif + __Pyx_ErrRestore(old_exc, old_val, old_tb); + if (!ctx) { + PyErr_WriteUnraisable(Py_None); + } else { + PyErr_WriteUnraisable(ctx); + Py_DECREF(ctx); + } +#ifdef WITH_THREAD + if (nogil) + PyGILState_Release(state); +#endif +} + /* RaiseException */ #if PY_MAJOR_VERSION < 3 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, @@ -9092,8 +16420,117 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject } #endif +/* StringJoin */ + #if !CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) { + return PyObject_CallMethodObjArgs(sep, __pyx_n_s_join, values, NULL); +} +#endif + +/* GetModuleGlobalName */ + static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 + result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); + if (likely(result)) { + Py_INCREF(result); + } else if (unlikely(PyErr_Occurred())) { + result = NULL; + } else { +#else + result = PyDict_GetItem(__pyx_d, name); + if (likely(result)) { + Py_INCREF(result); + } else { +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + if (!result) { + PyErr_Clear(); +#endif + result = __Pyx_GetBuiltinName(name); + } + return result; +} + +/* ArgTypeTest */ + static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) +{ + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + else if (exact) { + #if PY_MAJOR_VERSION == 2 + if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif + } + else { + if (likely(__Pyx_TypeCheck(obj, type))) return 1; + } + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); + return 0; +} + +/* PyObjectSetAttrStr */ + #if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_setattro)) + return tp->tp_setattro(obj, attr_name, value); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_setattr)) + return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value); +#endif + return PyObject_SetAttr(obj, attr_name, value); +} +#endif + +/* KeywordStringCheck */ + static int __Pyx_CheckKeywordStrings( + PyObject *kwdict, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; +#if CYTHON_COMPILING_IN_PYPY + if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) + goto invalid_keyword; + return 1; +#else + while (PyDict_Next(kwdict, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_Check(key))) + #endif + if (unlikely(!PyUnicode_Check(key))) + goto invalid_keyword_type; + } + if ((!kw_allowed) && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + return 0; +#endif +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif + return 0; +} + /* GetItemInt */ - static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; if (!j) return NULL; r = PyObject_GetItem(o, j); @@ -9180,7 +16617,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, } /* ObjectGetItem */ - #if CYTHON_USE_TYPE_SLOTS + #if CYTHON_USE_TYPE_SLOTS static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) { PyObject *runerr; Py_ssize_t key_value; @@ -9209,7 +16646,7 @@ static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) { #endif /* GetException */ - #if CYTHON_FAST_THREAD_STATE + #if CYTHON_FAST_THREAD_STATE static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { #else static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { @@ -9279,7 +16716,7 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) } /* SwapException */ - #if CYTHON_FAST_THREAD_STATE + #if CYTHON_FAST_THREAD_STATE static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; #if PY_VERSION_HEX >= 0x030700A2 @@ -9313,7 +16750,7 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, #endif /* SaveResetException */ - #if CYTHON_FAST_THREAD_STATE + #if CYTHON_FAST_THREAD_STATE static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { #if PY_VERSION_HEX >= 0x030700A2 *type = tstate->exc_state.exc_type; @@ -9351,32 +16788,127 @@ static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject } #endif -/* GetModuleGlobalName */ - static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { - PyObject *result; -#if !CYTHON_AVOID_BORROWED_REFS -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 - result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); - if (likely(result)) { - Py_INCREF(result); - } else if (unlikely(PyErr_Occurred())) { - result = NULL; - } else { -#else - result = PyDict_GetItem(__pyx_d, name); - if (likely(result)) { - Py_INCREF(result); - } else { +/* PyIntBinop */ + #if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { + #if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(op1))) { + const long b = intval; + long x; + long a = PyInt_AS_LONG(op1); + x = (long)((unsigned long)a - b); + if (likely((x^a) >= 0 || (x^~b) >= 0)) + return PyInt_FromLong(x); + return PyLong_Type.tp_as_number->nb_subtract(op1, op2); + } + #endif + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(PyLong_CheckExact(op1))) { + const long b = intval; + long a, x; +#ifdef HAVE_LONG_LONG + const PY_LONG_LONG llb = intval; + PY_LONG_LONG lla, llx; #endif -#else - result = PyObject_GetItem(__pyx_d, name); - if (!result) { - PyErr_Clear(); + const digit* digits = ((PyLongObject*)op1)->ob_digit; + const Py_ssize_t size = Py_SIZE(op1); + if (likely(__Pyx_sst_abs(size) <= 1)) { + a = likely(size) ? digits[0] : 0; + if (size == -1) a = -a; + } else { + switch (size) { + case -2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; #endif - result = __Pyx_GetBuiltinName(name); + } + CYTHON_FALLTHROUGH; + case 2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case -3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case -4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2); + } + } + x = a - b; + return PyLong_FromLong(x); +#ifdef HAVE_LONG_LONG + long_long: + llx = lla - llb; + return PyLong_FromLongLong(llx); +#endif + + } - return result; + #endif + if (PyFloat_CheckExact(op1)) { + const long b = intval; + double a = PyFloat_AS_DOUBLE(op1); + double result; + PyFPE_START_PROTECT("subtract", return NULL) + result = ((double)a) - (double)b; + PyFPE_END_PROTECT(result) + return PyFloat_FromDouble(result); + } + return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2); } +#endif /* PyErrExceptionMatches */ #if CYTHON_FAST_THREAD_STATE @@ -9388,20 +16920,166 @@ static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1; } #endif - for (i=0; icurexc_type; + if (exc_type == err) return 1; + if (unlikely(!exc_type)) return 0; + if (unlikely(PyTuple_Check(err))) + return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); + return __Pyx_PyErr_GivenExceptionMatches(exc_type, err); +} +#endif + +/* BytesEquals */ + static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ + static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; + } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; + } + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; } - return 0; -} -static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) { - PyObject *exc_type = tstate->curexc_type; - if (exc_type == err) return 1; - if (unlikely(!exc_type)) return 0; - if (unlikely(PyTuple_Check(err))) - return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); - return __Pyx_PyErr_GivenExceptionMatches(exc_type, err); -} +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); #endif +} /* PyObject_GenericGetAttrNoDict */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 @@ -9612,6 +17290,20 @@ static int __Pyx_setup_reduce(PyObject* type_obj) { return module; } +/* ImportFrom */ + static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { + PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); + if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Format(PyExc_ImportError, + #if PY_MAJOR_VERSION < 3 + "cannot import name %.230s", PyString_AS_STRING(name)); + #else + "cannot import name %S", name); + #endif + } + return value; +} + /* CalculateMetaclass */ static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) { Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases); @@ -10609,6 +18301,37 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } } +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_off_t(off_t value) { + const off_t neg_one = (off_t) -1, const_zero = (off_t) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(off_t) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(off_t) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(off_t) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(off_t) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(off_t) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(off_t), + little, !is_unsigned); + } +} + /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__htsFormatCategory(enum htsFormatCategory value) { const enum htsFormatCategory neg_one = (enum htsFormatCategory) -1, const_zero = (enum htsFormatCategory) 0; @@ -10764,6 +18487,68 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } } +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) -1, const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); + } +} + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value) { + const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(PY_LONG_LONG) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(PY_LONG_LONG) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(PY_LONG_LONG), + little, !is_unsigned); + } +} + /* CIntFromPy */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { const int neg_one = (int) -1, const_zero = (int) 0; @@ -11142,35 +18927,193 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, return (uint64_t) -1; } -/* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { - const long neg_one = (long) -1, const_zero = (long) 0; +/* CIntFromPy */ + static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *x) { + const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = (PY_LONG_LONG) 0; const int is_unsigned = neg_one > const_zero; - if (is_unsigned) { - if (sizeof(long) < sizeof(long)) { - return PyInt_FromLong((long) value); - } else if (sizeof(long) <= sizeof(unsigned long)) { - return PyLong_FromUnsignedLong((unsigned long) value); +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(PY_LONG_LONG) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (PY_LONG_LONG) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (PY_LONG_LONG) 0; + case 1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, digit, digits[0]) + case 2: + if (8 * sizeof(PY_LONG_LONG) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) >= 2 * PyLong_SHIFT) { + return (PY_LONG_LONG) (((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(PY_LONG_LONG) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) >= 3 * PyLong_SHIFT) { + return (PY_LONG_LONG) (((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(PY_LONG_LONG) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) >= 4 * PyLong_SHIFT) { + return (PY_LONG_LONG) (((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (PY_LONG_LONG) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x)) #ifdef HAVE_LONG_LONG - } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); + } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) #endif - } - } else { - if (sizeof(long) <= sizeof(long)) { - return PyInt_FromLong((long) value); + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (PY_LONG_LONG) 0; + case -1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, digit, +digits[0]) + case -2: + if (8 * sizeof(PY_LONG_LONG) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(PY_LONG_LONG) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + return (PY_LONG_LONG) ((((((PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(PY_LONG_LONG) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + return (PY_LONG_LONG) ((((((((PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + return (PY_LONG_LONG) (((PY_LONG_LONG)-1)*(((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(PY_LONG_LONG) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + return (PY_LONG_LONG) ((((((((((PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (PY_LONG_LONG)digits[0]))); + } + } + break; + } +#endif + if (sizeof(PY_LONG_LONG) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, long, PyLong_AsLong(x)) #ifdef HAVE_LONG_LONG - } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { - return PyLong_FromLongLong((PY_LONG_LONG) value); + } else if (sizeof(PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(PY_LONG_LONG, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif + } } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + PY_LONG_LONG val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (PY_LONG_LONG) -1; + } + } else { + PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (PY_LONG_LONG) -1; + val = __Pyx_PyInt_As_PY_LONG_LONG(tmp); + Py_DECREF(tmp); + return val; } - { - int one = 1; int little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(long), - little, !is_unsigned); - } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to PY_LONG_LONG"); + return (PY_LONG_LONG) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to PY_LONG_LONG"); + return (PY_LONG_LONG) -1; } /* CIntFromPy */ diff --git a/pysam/libchtslib.pxd b/pysam/libchtslib.pxd index 657a75426..8bcf399f3 100644 --- a/pysam/libchtslib.pxd +++ b/pysam/libchtslib.pxd @@ -9,6 +9,12 @@ cdef extern from "Python.h": FILE* PyFile_AsFile(object) +# cython does not wrap stdarg +cdef extern from "stdarg.h": + ctypedef struct va_list: + pass + + cdef extern from "htslib/kstring.h" nogil: ctypedef struct kstring_t: size_t l, m @@ -54,7 +60,7 @@ cdef extern from "htslib/hfile.h" nogil: # @abstract Open the named file or URL as a stream # @return An hFILE pointer, or NULL (with errno set) if an error occurred. - hFILE *hopen(const char *filename, const char *mode) + hFILE *hopen(const char *filename, const char *mode, ...) # @abstract Associate a stream with an existing open file descriptor # @return An hFILE pointer, or NULL (with errno set) if an error occurred. @@ -97,6 +103,40 @@ cdef extern from "htslib/hfile.h" nogil: # @return The character read, or EOF on end-of-file or error int hgetc(hFILE *fp) + # Read from the stream until the delimiter, up to a maximum length + # @param buffer The buffer into which bytes will be written + # @param size The size of the buffer + # @param delim The delimiter (interpreted as an `unsigned char`) + # @param fp The file stream + # @return The number of bytes read, or negative on error. + # @since 1.4 + # + # Bytes will be read into the buffer up to and including a delimiter, until + # EOF is reached, or _size-1_ bytes have been written, whichever comes first. + # The string will then be terminated with a NUL byte (`\0`). + ssize_t hgetdelim(char *buffer, size_t size, int delim, hFILE *fp) + + # Read a line from the stream, up to a maximum length + # @param buffer The buffer into which bytes will be written + # @param size The size of the buffer + # @param fp The file stream + # @return The number of bytes read, or negative on error. + # @since 1.4 + # + # Specialization of hgetdelim() for a `\n` delimiter. + ssize_t hgetln(char *buffer, size_t size, hFILE *fp) + + # Read a line from the stream, up to a maximum length + # @param buffer The buffer into which bytes will be written + # @param size The size of the buffer (must be > 1 to be useful) + # @param fp The file stream + # @return _buffer_ on success, or `NULL` if an error occurred. + # @since 1.4 + # + # This function can be used as a replacement for `fgets(3)`, or together with + # kstring's `kgetline()` to read arbitrarily-long lines into a _kstring_t_. + char *hgets(char *buffer, int size, hFILE *fp) + # @abstract Peek at characters to be read without removing them from buffers # @param fp The file stream # @param buffer The buffer to which the peeked bytes will be written @@ -384,7 +424,7 @@ cdef extern from "htslib/hts.h" nogil: no_compression, gzip, bgzf, custom compression_maximum - enum hts_fmt_option: + cdef enum hts_fmt_option: CRAM_OPT_DECODE_MD, CRAM_OPT_PREFIX, CRAM_OPT_VERBOSITY, @@ -432,6 +472,27 @@ cdef extern from "htslib/hts.h" nogil: int hts_verbose + cdef union hts_opt_val_union: + int i + char *s + + ctypedef struct hts_opt: + char *arg + hts_fmt_option opt + hts_opt_val_union val + void *next + + # @abstract Parses arg and appends it to the option list. + # @return 0 on success and -1 on failure + int hts_opt_add(hts_opt **opts, const char *c_arg) + + # @abstract Applies an hts_opt option list to a given htsFile. + # @return 0 on success and -1 on failure + int hts_opt_apply(htsFile *fp, hts_opt *opts) + + # @abstract Frees an hts_opt list. + void hts_opt_free(hts_opt *opts) + # @abstract Table for converting a nucleotide character to 4-bit encoding. # The input character may be either an IUPAC ambiguity code, '=' for 0, or # '0'/'1'/'2'/'3' for a result of 1/2/4/8. The result is encoded as 1/2/4/8 @@ -623,7 +684,7 @@ cdef extern from "htslib/hts.h" nogil: # @return The index, or NULL if an error occurred. hts_idx_t *hts_idx_load2(const char *fn, const char *fnidx) - uint8_t *hts_idx_get_meta(hts_idx_t *idx, int *l_meta) + uint8_t *hts_idx_get_meta(hts_idx_t *idx, uint32_t *l_meta) void hts_idx_set_meta(hts_idx_t *idx, int l_meta, uint8_t *meta, int is_copy) int hts_idx_get_stat(const hts_idx_t* idx, int tid, @@ -694,17 +755,90 @@ cdef extern from "htslib/hts.h" nogil: int hts_file_type(const char *fname) - inline int hts_reg2bin(int64_t beg, int64_t end, int min_shift, int n_lvls) - inline int hts_bin_bot(int bin, int n_lvls) + # /*************************** + # * Revised MAQ error model * + # ***************************/ + + ctypedef struct errmod_t + + errmod_t *errmod_init(double depcorr) + void errmod_destroy(errmod_t *em) + + # /* + # n: number of bases + # m: maximum base + # bases[i]: qual:6, strand:1, base:4 + # q[i*m+j]: phred-scaled likelihood of (i,j) + # */ + int errmod_cal(const errmod_t *em, int n, int m, uint16_t *bases, float *Probabilistic) + + # /***************************************** + # * q banded glocal alignment * + # *****************************************/ + + ctypedef struct probaln_par_t: + float d, e + int bw + + int probaln_glocal(const uint8_t *ref, + int l_ref, + const uint8_t *query, + int l_query, const uint8_t *iqual, + const probaln_par_t *c, + int *state, uint8_t *q) + + # /********************** + # * MD5 implementation * + # **********************/ + + ctypedef struct hts_md5_context + + # /*! @abstract Intialises an MD5 context. + # * @discussion + # * The expected use is to allocate an hts_md5_context using + # * hts_md5_init(). This pointer is then passed into one or more calls + # * of hts_md5_update() to compute successive internal portions of the + # * MD5 sum, which can then be externalised as a full 16-byte MD5sum + # * calculation by calling hts_md5_final(). This can then be turned + # * into ASCII via hts_md5_hex(). + # * + # * To dealloate any resources created by hts_md5_init() call the + # * hts_md5_destroy() function. + # * + # * @return hts_md5_context pointer on success, NULL otherwise. + # */ + hts_md5_context *hts_md5_init() + + # /*! @abstract Updates the context with the MD5 of the data. */ + void hts_md5_update(hts_md5_context *ctx, const void *data, unsigned long size) + + # /*! @abstract Computes the final 128-bit MD5 hash from the given context */ + void hts_md5_final(unsigned char *digest, hts_md5_context *ctx) + + # /*! @abstract Resets an md5_context to the initial state, as returned + # * by hts_md5_init(). + # */ + void hts_md5_reset(hts_md5_context *ctx) + + # /*! @abstract Converts a 128-bit MD5 hash into a 33-byte nul-termninated + # * hex string. + # */ + void hts_md5_hex(char *hex, const unsigned char *digest) + + # /*! @abstract Deallocates any memory allocated by hts_md5_init. */ + void hts_md5_destroy(hts_md5_context *ctx) + + int hts_reg2bin(int64_t beg, int64_t end, int min_shift, int n_lvls) + int hts_bin_bot(int bin, int n_lvls) # * Endianness * - inline int ed_is_big() - inline uint16_t ed_swap_2(uint16_t v) - inline void *ed_swap_2p(void *x) - inline uint32_t ed_swap_4(uint32_t v) - inline void *ed_swap_4p(void *x) - inline uint64_t ed_swap_8(uint64_t v) - inline void *ed_swap_8p(void *x) + int ed_is_big() + uint16_t ed_swap_2(uint16_t v) + void *ed_swap_2p(void *x) + uint32_t ed_swap_4(uint32_t v) + void *ed_swap_4p(void *x) + uint64_t ed_swap_8(uint64_t v) + void *ed_swap_8p(void *x) cdef extern from "htslib/sam.h" nogil: @@ -803,7 +937,9 @@ cdef extern from "htslib/sam.h" nogil: uint8_t qual uint8_t l_qname uint16_t flag - uint16_t n_cigar + uint8_t unused1 + uint8_t l_extranul + uint32_t n_cigar int32_t l_qseq int32_t mtid int32_t mpos @@ -824,7 +960,8 @@ cdef extern from "htslib/sam.h" nogil: # 4. seq is nybble-encoded according to seq_nt16_table. ctypedef struct bam1_t: bam1_core_t core - int l_data, m_data + int l_data + uint32_t m_data uint8_t *data uint64_t id @@ -999,7 +1136,7 @@ cdef extern from "htslib/sam.h" nogil: #************************************* uint8_t *bam_aux_get(const bam1_t *b, const char *tag) - int32_t bam_aux2i(const uint8_t *s) + int64_t bam_aux2i(const uint8_t *s) double bam_aux2f(const uint8_t *s) char bam_aux2A(const uint8_t *s) char *bam_aux2Z(const uint8_t *s) @@ -1011,6 +1148,18 @@ cdef extern from "htslib/sam.h" nogil: #*** Pileup and Mpileup *** #************************** + # @abstract Generic pileup 'client data'. + # @discussion The pileup iterator allows setting a constructor and + # destructor function, which will be called every time a sequence is + # fetched and discarded. This permits caching of per-sequence data in + # a tidy manner during the pileup process. This union is the cached + # data to be manipulated by the "client" (the caller of pileup). + # + union bam_pileup_cd: + void *p + int64_t i + double f + # @abstract Structure for one alignment covering the pileup position. # @field b pointer to the alignment # @field qpos position of the read base at the pileup site, 0-based @@ -1041,6 +1190,7 @@ cdef extern from "htslib/sam.h" nogil: uint32_t is_tail uint32_t is_refskip uint32_t aux + bam_pileup_cd cd ctypedef int (*bam_plp_auto_f)(void *data, bam1_t *b) ctypedef int (*bam_test_f)() @@ -1075,38 +1225,125 @@ cdef extern from "htslib/sam.h" nogil: void bam_mplp_destroy(bam_mplp_t iter) void bam_mplp_set_maxcnt(bam_mplp_t iter, int maxcnt) int bam_mplp_auto(bam_mplp_t iter, int *_tid, int *_pos, int *n_plp, const bam_pileup1_t **plp) - + void bam_mplp_reset(bam_mplp_t iter) + void bam_mplp_constructor(bam_mplp_t iter, + int (*func)(void *data, const bam1_t *b, bam_pileup_cd *cd)) + void bam_mplp_destructor(bam_mplp_t iter, + int (*func)(void *data, const bam1_t *b, bam_pileup_cd *cd)) + # Added by AH # ctypedef bam_pileup1_t * const_bam_pileup1_t_ptr "const bam_pileup1_t *" + # *********************************** + # * BAQ calculation and realignment * + # ***********************************/ + int sam_cap_mapq(bam1_t *b, const char *ref, int ref_len, int thres) + int sam_prob_realn(bam1_t *b, const char *ref, int ref_len, int flag) + cdef extern from "htslib/faidx.h" nogil: ctypedef struct faidx_t: pass + # /// Build index for a FASTA or bgzip-compressed FASTA file. + # /** @param fn FASTA file name + # @param fnfai Name of .fai file to build. + # @param fngzi Name of .gzi file to build (if fn is bgzip-compressed). + # @return 0 on success; or -1 on failure + + # If fnfai is NULL, ".fai" will be appended to fn to make the FAI file name. + # If fngzi is NULL, ".gzi" will be appended to fn for the GZI file. The GZI + # file will only be built if fn is bgzip-compressed. + # */ + int fai_build3(const char *fn, + const char *fnfai, + const char *fngzi) + + # /// Build index for a FASTA or bgzip-compressed FASTA file. + # /** @param fn FASTA file name + # @return 0 on success; or -1 on failure + # + # File "fn.fai" will be generated. This function is equivalent to + # fai_build3(fn, NULL, NULL); + # */ int fai_build(char *fn) + # /// Destroy a faidx_t struct void fai_destroy(faidx_t *fai) + # /// Load FASTA indexes. + # /** @param fn File name of the FASTA file (can be compressed with bgzip). + # @param fnfai File name of the FASTA index. + # @param fngzi File name of the bgzip index. + # @param flags Option flags to control index file caching and creation. + # @return Pointer to a faidx_t struct on success, NULL on failure. + + # If fnfai is NULL, ".fai" will be appended to fn to make the FAI file name. + # If fngzi is NULL, ".gzi" will be appended to fn for the bgzip index name. + # The bgzip index is only needed if fn is compressed. + + # If (flags & FAI_CREATE) is true, the index files will be built using + # fai_build3() if they are not already present. + # */ + faidx_t *fai_load3(const char *fn, + const char *fnfai, + const char *fngzi, + int flags) + + # /// Load index from "fn.fai". + # /** @param fn File name of the FASTA file + # @return Pointer to a faidx_t struct on success, NULL on failure. + # This function is equivalent to fai_load3(fn, NULL, NULL, FAI_CREATE|FAI_CACHE); + # */ faidx_t *fai_load(char *fn) + # /// Fetch the sequence in a region + # /** @param fai Pointer to the faidx_t struct + # @param reg Region in the format "chr2:20,000-30,000" + # @param len Length of the region; -2 if seq not present, -1 general error + # @return Pointer to the sequence; `NULL` on failure + # The returned sequence is allocated by `malloc()` family and should be destroyed + # by end users by calling `free()` on it. + # */ char *fai_fetch(faidx_t *fai, char *reg, int *len) - int faidx_nseq(faidx_t *fai) - - int faidx_has_seq(faidx_t *fai, const char *seq) - + # /// Fetch the sequence in a region + # /** @param fai Pointer to the faidx_t struct + # @param c_name Region name + # @param p_beg_i Beginning position number (zero-based) + # @param p_end_i End position number (zero-based) + # @param len Length of the region; -2 if c_name not present, -1 general error + # @return Pointer to the sequence; null on failure + # The returned sequence is allocated by `malloc()` family and should be destroyed + # by end users by calling `free()` on it. + # */ char *faidx_fetch_seq(faidx_t *fai, char *c_name, int p_beg_i, int p_end_i, int *len) - int faidx_seq_len(faidx_t *fai, const char *seq) + # /// Query if sequence is present + # /** @param fai Pointer to the faidx_t struct + # @param seq Sequence name + # @return 1 if present or 0 if absent + # */ + int faidx_has_seq(faidx_t *fai, const char *seq) + + # /// Fetch the number of sequences + # /** @param fai Pointer to the faidx_t struct + # @return The number of sequences + # */ + int faidx_nseq(const faidx_t *fai) + # /// Return name of i-th sequence + const char *faidx_iseq(const faidx_t *fai, int i) + + # /// Return sequence length, -1 if not present + int faidx_seq_len(faidx_t *fai, const char *seq) # tabix support cdef extern from "htslib/tbx.h" nogil: @@ -1695,7 +1932,7 @@ cdef extern from "htslib/vcf.h" nogil: int bcf_get_format_int32(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, int32_t **dst, int *ndst) int bcf_get_format_float(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, float **dst, int *ndst) int bcf_get_format_char(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, char **dst, int *ndst) - int bcf_get_genotypes(const bcf_hdr_t *hdr, bcf1_t *line, int **dst, int *ndst) + int bcf_get_genotypes(const bcf_hdr_t *hdr, bcf1_t *line, int32_t **dst, int *ndst) int bcf_get_format_string(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, char ***dst, int *ndst) int bcf_get_format_values(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **dst, int *ndst, int type) @@ -1901,12 +2138,462 @@ cdef extern from "htslib/vcfutils.h" nogil: uint32_t bcf_ij2G(uint32_t i, uint32_t j) +cdef extern from "htslib/cram.h" nogil: + + enum cram_block_method: + ERROR + RAW + GZIP + BZIP2 + LZMA + RANS + RANS0 + RANS1 + GZIP_RLE + + enum cram_content_type: + CT_ERROR + FILE_HEADER + COMPRESSION_HEADER + MAPPED_SLICE + UNMAPPED_SLICE + EXTERNAL + CORE + + # Opaque data types, see cram_structs for the fully fledged versions. + ctypedef struct SAM_hdr + ctypedef struct cram_file_def + ctypedef struct cram_fd + ctypedef struct cram_container + ctypedef struct cram_block + ctypedef struct cram_slice + ctypedef struct cram_metrics + ctypedef struct cram_block_slice_hdr + ctypedef struct cram_block_compression_hdr + ctypedef struct refs_t + + # Accessor functions + + # + #----------------------------------------------------------------------------- + # cram_fd + # + SAM_hdr *cram_fd_get_header(cram_fd *fd) + void cram_fd_set_header(cram_fd *fd, SAM_hdr *hdr) + + int cram_fd_get_version(cram_fd *fd) + void cram_fd_set_version(cram_fd *fd, int vers) + + int cram_major_vers(cram_fd *fd) + int cram_minor_vers(cram_fd *fd) + + hFILE *cram_fd_get_fp(cram_fd *fd) + void cram_fd_set_fp(cram_fd *fd, hFILE *fp) + + # + #----------------------------------------------------------------------------- + # cram_container + # + int32_t cram_container_get_length(cram_container *c) + void cram_container_set_length(cram_container *c, int32_t length) + int32_t cram_container_get_num_blocks(cram_container *c) + void cram_container_set_num_blocks(cram_container *c, int32_t num_blocks) + int32_t *cram_container_get_landmarks(cram_container *c, int32_t *num_landmarks) + void cram_container_set_landmarks(cram_container *c, int32_t num_landmarks, + int32_t *landmarks) + + # Returns true if the container is empty (EOF marker) */ + int cram_container_is_empty(cram_fd *fd) + + + # + #----------------------------------------------------------------------------- + # cram_block + # + int32_t cram_block_get_content_id(cram_block *b) + int32_t cram_block_get_comp_size(cram_block *b) + int32_t cram_block_get_uncomp_size(cram_block *b) + int32_t cram_block_get_crc32(cram_block *b) + void * cram_block_get_data(cram_block *b) + + cram_content_type cram_block_get_content_type(cram_block *b) + + void cram_block_set_content_id(cram_block *b, int32_t id) + void cram_block_set_comp_size(cram_block *b, int32_t size) + void cram_block_set_uncomp_size(cram_block *b, int32_t size) + void cram_block_set_crc32(cram_block *b, int32_t crc) + void cram_block_set_data(cram_block *b, void *data) + + int cram_block_append(cram_block *b, void *data, int size) + void cram_block_update_size(cram_block *b) + + # Offset is known as "size" internally, but it can be confusing. + size_t cram_block_get_offset(cram_block *b) + void cram_block_set_offset(cram_block *b, size_t offset) + + # + # Computes the size of a cram block, including the block + # header itself. + # + uint32_t cram_block_size(cram_block *b) + + # + # Renumbers RG numbers in a cram compression header. + # + # CRAM stores RG as the Nth number in the header, rather than a + # string holding the ID: tag. This is smaller in space, but means + # "samtools cat" to join files together that contain single but + # different RG lines needs a way of renumbering them. + # + # The file descriptor is expected to be immediately after the + # cram_container structure (ie before the cram compression header). + # Due to the nature of the CRAM format, this needs to read and write + # the blocks itself. Note that there may be multiple slices within + # the container, meaning multiple compression headers to manipulate. + # Changing RG may change the size of the compression header and + # therefore the length field in the container. Hence we rewrite all + # blocks just incase and also emit the adjusted container. + # + # The current implementation can only cope with renumbering a single + # RG (and only then if it is using HUFFMAN or BETA codecs). In + # theory it *may* be possible to renumber multiple RGs if they use + # HUFFMAN to the CORE block or use an external block unshared by any + # other data series. So we have an API that can be upgraded to + # support this, but do not implement it for now. An example + # implementation of RG as an EXTERNAL block would be to find that + # block and rewrite it, returning the number of blocks consumed. + # + # Returns 0 on success; + # -1 if unable to edit; + # -2 on other errors (eg I/O). + # + int cram_transcode_rg(cram_fd *input, cram_fd *output, + cram_container *c, + int nrg, int *in_rg, int *out_rg) + + # + # Copies the blocks representing the next num_slice slices from a + # container from 'in' to 'out'. It is expected that the file pointer + # is just after the read of the cram_container and cram compression + # header. + # + # Returns 0 on success + # -1 on failure + # + int cram_copy_slice(cram_fd *input, cram_fd *output, int32_t num_slice) + + # + #----------------------------------------------------------------------------- + # SAM_hdr + # + + # Tokenises a SAM header into a hash table. + # + # Also extracts a few bits on specific data types, such as @RG lines. + # + # @return + # Returns a SAM_hdr struct on success (free with sam_hdr_free()) + # NULL on failure + # + SAM_hdr *sam_hdr_parse_(const char *hdr, int len) + + + # + #----------------------------------------------------------------------------- + # cram_io basics + # + + # CRAM blocks - the dynamically growable data block. We have code to + # create, update, (un)compress and read/write. + # + # These are derived from the deflate_interlaced.c blocks, but with the + # CRAM extension of content types and IDs. + # + + # Allocates a new cram_block structure with a specified content_type and + # id. + # + # @return + # Returns block pointer on success; + # NULL on failure + # + cram_block *cram_new_block(cram_content_type content_type, + int content_id) + + # Reads a block from a cram file. + # + # @return + # Returns cram_block pointer on success; + # NULL on failure + # + cram_block *cram_read_block(cram_fd *fd) + + # Writes a CRAM block. + # + # @return + # Returns 0 on success; + # -1 on failure + # + int cram_write_block(cram_fd *fd, cram_block *b) + + # Frees a CRAM block, deallocating internal data too. + # + void cram_free_block(cram_block *b) + + # Uncompresses a CRAM block, if compressed. + # + # @return + # Returns 0 on success; + # -1 on failure + # + int cram_uncompress_block(cram_block *b) + + # Compresses a block. + # + # Compresses a block using one of two different zlib strategies. If we only + # want one choice set strat2 to be -1. + # + # The logic here is that sometimes Z_RLE does a better job than Z_FILTERED + # or Z_DEFAULT_STRATEGY on quality data. If so, we'd rather use it as it is + # significantly faster. + # + # @return + # Returns 0 on success; + # -1 on failure + # + int cram_compress_block(cram_fd *fd, cram_block *b, cram_metrics *metrics, + int method, int level) + + # Containers + # + + # Creates a new container, specifying the maximum number of slices + # and records permitted. + # + # @return + # Returns cram_container ptr on success; + # NULL on failure + # + cram_container *cram_new_container(int nrec, int nslice) + void cram_free_container(cram_container *c) + + # Reads a container header. + # + # @return + # Returns cram_container on success; + # NULL on failure or no container left (fd->err == 0). + # + cram_container *cram_read_container(cram_fd *fd) + + # Writes a container structure. + # + # @return + # Returns 0 on success; + # -1 on failure + # + int cram_write_container(cram_fd *fd, cram_container *h) + + # + # Stores the container structure in dat and returns *size as the + # number of bytes written to dat[]. The input size of dat is also + # held in *size and should be initialised to cram_container_size(c). + # + # Returns 0 on success; + # -1 on failure + # + int cram_store_container(cram_fd *fd, cram_container *c, char *dat, int *size) + + int cram_container_size(cram_container *c) + + # The top-level cram opening, closing and option handling + # + + # Opens a CRAM file for read (mode "rb") or write ("wb"). + # + # The filename may be "-" to indicate stdin or stdout. + # + # @return + # Returns file handle on success; + # NULL on failure. + # + cram_fd *cram_open(const char *filename, const char *mode) + + # Opens an existing stream for reading or writing. + # + # @return + # Returns file handle on success; + # NULL on failure. + # + cram_fd *cram_dopen(hFILE *fp, const char *filename, const char *mode) + + # Closes a CRAM file. + # + # @return + # Returns 0 on success; + # -1 on failure + # + int cram_close(cram_fd *fd) + + # + # Seek within a CRAM file. + # + # Returns 0 on success + # -1 on failure + # + int cram_seek(cram_fd *fd, off_t offset, int whence) + + # + # Flushes a CRAM file. + # Useful for when writing to stdout without wishing to close the stream. + # + # Returns 0 on success + # -1 on failure + # + int cram_flush(cram_fd *fd) + + # Checks for end of file on a cram_fd stream. + # + # @return + # Returns 0 if not at end of file + # 1 if we hit an expected EOF (end of range or EOF block) + # 2 for other EOF (end of stream without EOF block) + # + int cram_eof(cram_fd *fd) + + # Sets options on the cram_fd. + # + # See CRAM_OPT_* definitions in hts.h. + # Use this immediately after opening. + # + # @return + # Returns 0 on success; + # -1 on failure + # + int cram_set_option(cram_fd *fd, hts_fmt_option opt, ...) + + # Sets options on the cram_fd. + # + # See CRAM_OPT_* definitions in hts.h. + # Use this immediately after opening. + # + # @return + # Returns 0 on success; + # -1 on failure + # + int cram_set_voption(cram_fd *fd, hts_fmt_option opt, va_list args) + + # + # Attaches a header to a cram_fd. + # + # This should be used when creating a new cram_fd for writing where + # we have an SAM_hdr already constructed (eg from a file we've read + # in). + # + # @return + # Returns 0 on success; + # -1 on failure + # + int cram_set_header(cram_fd *fd, SAM_hdr *hdr) + + # Check if this file has a proper EOF block + # + # @return + # Returns 3 if the file is a version of CRAM that does not contain EOF blocks + # 2 if the file is a stream and thus unseekable + # 1 if the file contains an EOF block + # 0 if the file does not contain an EOF block + # -1 if an error occured whilst reading the file or we could not seek back to where we were + # + # + int cram_check_EOF(cram_fd *fd) + + # As int32_decoded/encode, but from/to blocks instead of cram_fd */ + int int32_put_blk(cram_block *b, int32_t val) + + # Deallocates all storage used by a SAM_hdr struct. + # + # This also decrements the header reference count. If after decrementing + # it is still non-zero then the header is assumed to be in use by another + # caller and the free is not done. + # + # This is a synonym for sam_hdr_dec_ref(). + # + void sam_hdr_free(SAM_hdr *hdr) + + # Returns the current length of the SAM_hdr in text form. + # + # Call sam_hdr_rebuild() first if editing has taken place. + # + int sam_hdr_length(SAM_hdr *hdr) + + # Returns the string form of the SAM_hdr. + # + # Call sam_hdr_rebuild() first if editing has taken place. + # + char *sam_hdr_str(SAM_hdr *hdr) + + # Appends a formatted line to an existing SAM header. + # + # Line is a full SAM header record, eg "@SQ\tSN:foo\tLN:100", with + # optional new-line. If it contains more than 1 line then multiple lines + # will be added in order. + # + # Len is the length of the text data, or 0 if unknown (in which case + # it should be null terminated). + # + # @return + # Returns 0 on success; + # -1 on failure + # + + # Add an @PG line. + # + # If we wish complete control over this use sam_hdr_add() directly. This + # function uses that, but attempts to do a lot of tedious house work for + # you too. + # + # - It will generate a suitable ID if the supplied one clashes. + # - It will generate multiple @PG records if we have multiple PG chains. + # + # Call it as per sam_hdr_add() with a series of key,value pairs ending + # in NULL. + # + # @return + # Returns 0 on success; + # -1 on failure + # + int sam_hdr_add_PG(SAM_hdr *sh, const char *name, ...) + + # + # A function to help with construction of CL tags in @PG records. + # Takes an argc, argv pair and returns a single space-separated string. + # This string should be deallocated by the calling function. + # + # @return + # Returns malloced char * on success; + # NULL on failure + # + char *stringify_argv(int argc, char *argv[]) + + # + # Returns the refs_t structure used by a cram file handle. + # + # This may be used in conjunction with option CRAM_OPT_SHARED_REF to + # share reference memory between multiple file handles. + # + # @return + # Returns NULL if none exists or the file handle is not a CRAM file. + # + refs_t *cram_get_refs(htsFile *fd) + + cdef class HTSFile(object): cdef htsFile *htsfile # pointer to htsFile structure cdef int64_t start_offset # BGZF offset of first record cdef readonly object filename # filename as supplied by user cdef readonly object mode # file opening mode + cdef readonly object threads # number of threads to use cdef readonly object index_filename # filename of index, if supplied by user cdef readonly bint is_stream # Is htsfile a non-seekable stream diff --git a/pysam/libchtslib.pyx b/pysam/libchtslib.pyx index 7eea0598f..d64b198fc 100644 --- a/pysam/libchtslib.pyx +++ b/pysam/libchtslib.pyx @@ -1,9 +1,15 @@ # cython: embedsignature=True # cython: profile=True # adds doc-strings for sphinx -import os + +######################################################################## +######################################################################## +## Cython cimports +######################################################################## from posix.unistd cimport dup +from libc.errno cimport errno +from cpython cimport PyBytes_FromStringAndSize from pysam.libchtslib cimport * @@ -11,7 +17,15 @@ from pysam.libcutils cimport force_bytes, force_str, charptr_to_str, charptr_to_ from pysam.libcutils cimport encode_filename, from_string_and_size -__all__ = ["get_verbosity", "set_verbosity"] +######################################################################## +######################################################################## +## Python imports +######################################################################## + +import os +import io +import re +from warnings import warn ######################################################################## @@ -19,13 +33,28 @@ __all__ = ["get_verbosity", "set_verbosity"] ## Constants ######################################################################## +__all__ = ['get_verbosity', 'set_verbosity', 'HFile', 'HTSFile'] + +# defines imported from samtools +DEF SEEK_SET = 0 +DEF SEEK_CUR = 1 +DEF SEEK_END = 2 + +# maximum genomic coordinace cdef int MAX_POS = 2 << 29 + cdef tuple FORMAT_CATEGORIES = ('UNKNOWN', 'ALIGNMENTS', 'VARIANTS', 'INDEX', 'REGIONS') cdef tuple FORMATS = ('UNKNOWN', 'BINARY_FORMAT', 'TEXT_FORMAT', 'SAM', 'BAM', 'BAI', 'CRAM', 'CRAI', 'VCF', 'BCF', 'CSI', 'GZI', 'TBI', 'BED') cdef tuple COMPRESSION = ('NONE', 'GZIP', 'BGZF', 'CUSTOM') +######################################################################## +######################################################################## +## Verbosity functions +######################################################################## + + cpdef set_verbosity(int verbosity): """Set htslib's hts_verbose global variable to the specified value.""" return hts_set_verbosity(verbosity) @@ -35,6 +64,241 @@ cpdef get_verbosity(): return hts_get_verbosity() +######################################################################## +######################################################################## +## HFile wrapper class +######################################################################## + +cdef class HFile(object): + cdef hFILE *fp + cdef readonly object name, mode + + def __init__(self, name, mode='r', closedf=True): + self._open(name, mode, closefd=True) + + def __dealloc__(self): + self.close() + + @property + def closed(self): + return self.fp == NULL + + cdef _open(self, name, mode, closefd=True): + self.name = name + self.mode = mode + + mode = force_bytes(mode) + + if isinstance(name, int): + if self.fp != NULL: + name = dup(name) + self.fp = hdopen(name, mode) + else: + name = encode_filename(name) + self.fp = hopen(name, mode) + + if not self.fp: + raise IOError(errno, 'failed to open HFile', self.name) + + def close(self): + if self.fp == NULL: + return + + cdef hFILE *fp = self.fp + self.fp = NULL + + if hclose(fp) != 0: + raise IOError(herrno(self.fp), 'failed to close HFile', self.name) + + def fileno(self): + if self.fp == NULL: + raise IOError('operation on closed HFile') + if isinstance(self.name, int): + return self.name + else: + raise AttributeError('fileno not available') + + def __enter__(self): + return self + + def __exit__(self, type, value, tb): + self.close() + + def __iter__(self): + return self + + def __next__(self): + line = self.readline() + if not line: + raise StopIteration() + return line + + def flush(self): + if self.fp == NULL: + raise IOError('operation on closed HFile') + if hflush(self.fp) != 0: + raise IOError(herrno(self.fp), 'failed to flush HFile', self.name) + + def isatty(self): + if self.fp == NULL: + raise IOError('operation on closed HFile') + return False + + def readable(self): + return self.fp != NULL and 'r' in self.mode + + def read(self, Py_ssize_t size=-1): + if self.fp == NULL: + raise IOError('operation on closed HFile') + + if size == 0: + return b'' + + cdef list parts = [] + cdef bytes part + cdef Py_ssize_t chunk_size, ret, bytes_read = 0 + cdef char *cpart + + while size == -1 or bytes_read < size: + chunk_size = 4096 + if size != -1: + chunk_size = min(chunk_size, size - bytes_read) + + part = PyBytes_FromStringAndSize(NULL, chunk_size) + cpart = part + ret = hread(self.fp, cpart, chunk_size) + + if ret < 0: + IOError(herrno(self.fp), 'failed to read HFile', self.name) + elif not ret: + break + + bytes_read += ret + + if ret < chunk_size: + part = cpart[:ret] + + parts.append(part) + + return b''.join(parts) + + def readall(self): + return self.read() + + def readinto(self, buf): + if self.fp == NULL: + raise IOError('operation on closed HFile') + + size = len(buf) + + if size == 0: + return size + + mv = memoryview(buf) + ret = hread(self.fp, mv, size) + + if ret < 0: + IOError(herrno(self.fp), 'failed to read HFile', self.name) + + return ret + + def readline(self, Py_ssize_t size=-1): + if self.fp == NULL: + raise IOError('operation on closed HFile') + + if size == 0: + return b'' + + cdef list parts = [] + cdef bytes part + cdef Py_ssize_t chunk_size, ret, bytes_read = 0 + cdef char *cpart + + while size == -1 or bytes_read < size: + chunk_size = 4096 + if size != -1: + chunk_size = min(chunk_size, size - bytes_read) + + part = PyBytes_FromStringAndSize(NULL, chunk_size) + cpart = part + + # Python bytes objects allocate an extra byte for a null terminator + ret = hgetln(cpart, chunk_size+1, self.fp) + + if ret < 0: + IOError(herrno(self.fp), 'failed to read HFile', self.name) + elif not ret: + break + + bytes_read += ret + + if ret < chunk_size: + part = cpart[:ret] + cpart = part + + parts.append(part) + + if cpart[ret-1] == b'\n': + break + + return b''.join(parts) + + def readlines(self): + return list(self) + + def seek(self, Py_ssize_t offset, int whence=SEEK_SET): + if self.fp == NULL: + raise IOError('operation on closed HFile') + + cdef Py_ssize_t off = hseek(self.fp, offset, whence) + + if off < 0: + raise IOError(herrno(self.fp), 'seek failed on HFile', self.name) + + return off + + def tell(self): + if self.fp == NULL: + raise IOError('operation on closed HFile') + + ret = htell(self.fp) + + if ret < 0: + raise IOError(herrno(self.fp), 'tell failed on HFile', self.name) + + return ret + + def seekable(self): + return self.fp != NULL + + def truncate(self, size=None): + raise NotImplementedError() + + def writable(self): + return self.fp != NULL and 'w' in self.mode + + def write(self, bytes b): + if self.fp == NULL: + raise IOError('operation on closed HFile') + + got = hwrite(self.fp, b, len(b)) + + if got < 0: + raise IOError(herrno(self.fp), 'write failed on HFile', self.name) + + return got + + def writelines(self, lines): + for line in lines: + self.write(line) + + +######################################################################## +######################################################################## +## Helpers for backward compatibility to hide the difference between +## boolean properties and methods +######################################################################## + class CallableValue(object): def __init__(self, value): self.value = value @@ -54,19 +318,52 @@ CTrue = CallableValue(True) CFalse = CallableValue(False) +######################################################################## +######################################################################## +## HTSFile wrapper class (base class for AlignmentFile and VariantFile) +######################################################################## + cdef class HTSFile(object): """ Base class for HTS file types """ def __cinit__(self, *args, **kwargs): self.htsfile = NULL + self.threads = 1 self.duplicate_filehandle = True + def close(self): + if self.htsfile: + hts_close(self.htsfile) + self.htsfile = NULL + def __dealloc__(self): if self.htsfile: hts_close(self.htsfile) self.htsfile = NULL + def check_truncation(self, ignore_truncation=False): + """Check if file is truncated.""" + if not self.htsfile: + return + + if self.htsfile.format.compression != bgzf: + return + + cdef BGZF *bgzfp = hts_get_bgzfp(self.htsfile) + if not bgzfp: + return + + cdef int ret = bgzf_check_EOF(bgzfp) + if ret < 0: + raise IOError(errno, 'error checking for EOF marker') + elif ret == 0: + msg = 'no BGZF EOF marker; file may be truncated'.format(self.filename) + if ignore_truncation: + warn(msg) + else: + raise IOError(msg) + def __enter__(self): return self @@ -186,15 +483,18 @@ cdef class HTSFile(object): if not self.is_open: raise ValueError('I/O operation on closed file') if self.is_stream: - raise OSError('seek not available in streams') + raise IOError('seek not available in streams') cdef int64_t ret - if self.htsfile.format.compression != no_compression: + if self.htsfile.format.compression == bgzf: with nogil: ret = bgzf_seek(hts_get_bgzfp(self.htsfile), offset, SEEK_SET) - else: + elif self.htsfile.format.compression == no_compression: with nogil: ret = hts_useek(self.htsfile, offset, SEEK_SET) + else: + raise NotImplementedError("seek not implemented in files compressed by method {}".format( + self.htsfile.format.compression)) return ret def tell(self): @@ -202,32 +502,43 @@ cdef class HTSFile(object): if not self.is_open: raise ValueError('I/O operation on closed file') if self.is_stream: - raise OSError('tell not available in streams') + raise IOError('tell not available in streams') cdef int64_t ret - if self.htsfile.format.compression != no_compression: + if self.htsfile.format.compression == bgzf: with nogil: ret = bgzf_tell(hts_get_bgzfp(self.htsfile)) - else: + elif self.htsfile.format.compression == no_compression: with nogil: ret = hts_utell(self.htsfile) + elif self.htsfile.format.format == cram: + with nogil: + ret = htell(cram_fd_get_fp(self.htsfile.fp.cram)) + else: + raise NotImplementedError("seek not implemented in files compressed by method {}".format( + self.htsfile.format.compression)) + return ret cdef htsFile *_open_htsfile(self) except? NULL: cdef char *cfilename cdef char *cmode = self.mode - cdef int fd, dup_fd + cdef int fd, dup_fd, threads + threads = self.threads - 1 if isinstance(self.filename, bytes): cfilename = self.filename with nogil: - return hts_open(cfilename, cmode) + htsfile = hts_open(cfilename, cmode) + if htsfile != NULL: + hts_set_threads(htsfile, threads) + return htsfile else: if isinstance(self.filename, int): fd = self.filename else: fd = self.filename.fileno() - + if self.duplicate_filehandle: dup_fd = dup(fd) else: @@ -254,12 +565,157 @@ cdef class HTSFile(object): filename = encode_filename(filename) cfilename = filename with nogil: - return hts_hopen(hfile, cfilename, cmode) + htsfile = hts_hopen(hfile, cfilename, cmode) + if htsfile != NULL: + hts_set_threads(htsfile, threads) + return htsfile + + def add_hts_options(self, format_options=None): + """Given a list of key=value format option strings, add them to an open htsFile + """ + cdef int rval + cdef hts_opt *opts = NULL + + if format_options: + for format_option in format_options: + rval = hts_opt_add(&opts, format_option) + if rval != 0: + if opts != NULL: + hts_opt_free(opts) + raise RuntimeError('Invalid format option ({}) specified'.format(format_option)) + if opts != NULL: + rval = hts_opt_apply(self.htsfile, opts) + if rval != 0: + hts_opt_free(opts) + raise RuntimeError('An error occured while applying the requested format options') + hts_opt_free(opts) + + def parse_region(self, contig=None, start=None, stop=None, region=None,tid=None, + reference=None, end=None): + """parse alternative ways to specify a genomic region. A region can + either be specified by :term:`contig`, `start` and + `stop`. `start` and `stop` denote 0-based, half-open + intervals. :term:`reference` and `end` are also accepted for + backward compatiblity as synonyms for :term:`contig` and + `stop`, respectively. + + Alternatively, a samtools :term:`region` string can be + supplied. + + If any of the coordinates are missing they will be replaced by + the minimum (`start`) or maximum (`stop`) coordinate. + + Note that region strings are 1-based inclusive, while `start` + and `stop` denote an interval in 0-based, half-open + coordinates (like BED files and Python slices). + + If `contig` or `region` or are ``*``, unmapped reads at the end + of a BAM file will be returned. Setting either to ``.`` will + iterate from the beginning of the file. + + Returns + ------- + + tuple : a tuple of `flag`, :term:`tid`, `start` and + `stop`. The flag indicates whether no coordinates were + supplied and the genomic region is the complete genomic space. + + Raises + ------ + + ValueError + for invalid or out of bounds regions. + + """ + cdef int rtid + cdef long long rstart + cdef long long rstop + + if reference is not None: + if contig is not None: + raise ValueError('contig and reference should not both be specified') + contig = reference + + if end is not None: + if stop is not None: + raise ValueError('stop and end should not both be specified') + stop = end + + if contig is None and tid is None and region is None: + return 0, 0, 0, 0 + + rtid = -1 + rstart = 0 + rstop = MAX_POS + if start is not None: + try: + rstart = start + except OverflowError: + raise ValueError('start out of range (%i)' % start) - def _exists(self): - """return False iff file is local, a file and exists. + if stop is not None: + try: + rstop = stop + except OverflowError: + raise ValueError('stop out of range (%i)' % stop) + + if region: + region = force_str(region) + parts = re.split('[:-]', region) + contig = parts[0] + if len(parts) >= 2: + rstart = int(parts[1]) - 1 + if len(parts) >= 3: + rstop = int(parts[2]) + + if tid is not None: + if not self.is_valid_tid(tid): + raise IndexError('invalid tid') + rtid = tid + else: + if contig == "*": + rtid = HTS_IDX_NOCOOR + elif contig == ".": + rtid = HTS_IDX_START + else: + rtid = self.get_tid(contig) + if rtid < 0: + raise ValueError('invalid contig `%s`' % contig) + + if rstart > rstop: + raise ValueError('invalid coordinates: start (%i) > stop (%i)' % (rstart, rstop)) + if not 0 <= rstart < MAX_POS: + raise ValueError('start out of range (%i)' % rstart) + if not 0 <= rstop <= MAX_POS: + raise ValueError('stop out of range (%i)' % rstop) + + return 1, rtid, rstart, rstop + + def is_valid_tid(self, tid): + """ + return True if the numerical :term:`tid` is valid; False otherwise. + + returns -1 if contig is not known. + """ + raise NotImplementedError() + + def is_valid_reference_name(self, contig): + """ + return True if the contig name :term:`contig` is valid; False otherwise. + """ + return self.get_tid(contig) != -1 + + def get_tid(self, contig): + """ + return the numerical :term:`tid` corresponding to + :term:`contig` + + returns -1 if contig is not known. + """ + raise NotImplementedError() + + def get_reference_name(self, tid): + """ + return :term:`contig` name corresponding to numerical :term:`tid` """ - return (not isinstance(self.filename, (str, bytes)) or - self.filename == b'-' or - self.is_remote or - os.path.exists(self.filename)) + raise NotImplementedError() diff --git a/pysam/libcsamfile.c b/pysam/libcsamfile.c index 338195a93..8d8921ea5 100644 --- a/pysam/libcsamfile.c +++ b/pysam/libcsamfile.c @@ -568,6 +568,7 @@ static CYTHON_INLINE float __PYX_NAN() { #include #include "pythread.h" #include +#include "stdarg.h" #include "htslib/kstring.h" #include "htslib_util.h" #include "htslib/hfile.h" @@ -578,8 +579,8 @@ static CYTHON_INLINE float __PYX_NAN() { #include "htslib/tbx.h" #include "htslib/vcf.h" #include "htslib/vcfutils.h" +#include "htslib/cram.h" #include "pysam_stream.h" -#include "samfile_util.h" #ifdef _OPENMP #include #endif /* _OPENMP */ @@ -803,13 +804,14 @@ typedef struct arrayobject arrayobject; struct __pyx_obj_5pysam_10libchtslib_HTSFile; struct __pyx_obj_5pysam_9libcfaidx_FastaFile; struct __pyx_obj_5pysam_9libcfaidx_FastqProxy; -struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy; +struct __pyx_obj_5pysam_9libcfaidx_FastxRecord; struct __pyx_obj_5pysam_9libcfaidx_FastxFile; struct __pyx_obj_5pysam_9libcfaidx_FastqFile; struct __pyx_obj_5pysam_9libcfaidx_Fastafile; struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment; struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn; struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead; +struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader; struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile; struct __pyx_obj_5pysam_17libcalignmentfile_PileupColumn; struct __pyx_obj_5pysam_17libcalignmentfile_PileupRead; @@ -826,10 +828,10 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads; struct __pyx_obj_5pysam_11libcsamfile_AlignedRead; struct __pyx_obj_5pysam_11libcsamfile_Samfile; struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array; -struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array; +struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array; -/* "pysam/libcfaidx.pxd":48 - * cdef kseq_t * _delegate +/* "pysam/libcfaidx.pxd":49 + * cdef cython.str to_string(self) * cdef cython.str tostring(self) * cpdef array.array get_quality_array(self, int offset=*) # <<<<<<<<<<<<<< * @@ -840,30 +842,31 @@ struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array { int offset; }; -/* "pysam/libcfaidx.pxd":57 - * cdef public str comment, quality, sequence, name +/* "pysam/libcfaidx.pxd":59 + * cdef cython.str to_string(self) * cdef cython.str tostring(self) * cpdef array.array get_quality_array(self, int offset=*) # <<<<<<<<<<<<<< * - * + * cdef class FastxFile: */ -struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array { +struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array { int __pyx_n; int offset; }; struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag; struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag; +struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring; -/* "pysam/libcalignedsegment.pxd":36 +/* "pysam/libcalignedsegment.pxd":30 * - * from pysam.libcalignmentfile cimport AlignmentFile + * from pysam.libcalignmentfile cimport AlignmentFile, AlignmentHeader * ctypedef AlignmentFile AlignmentFile_t # <<<<<<<<<<<<<< * * */ typedef struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t; -/* "pysam/libcalignedsegment.pxd":56 +/* "pysam/libcalignedsegment.pxd":50 * # add an alignment tag with value to the AlignedSegment * # an existing tag of the same name will be replaced. * cpdef set_tag(self, tag, value, value_type=?, replace=?) # <<<<<<<<<<<<<< @@ -876,7 +879,7 @@ struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag { PyObject *replace; }; -/* "pysam/libcalignedsegment.pxd":60 +/* "pysam/libcalignedsegment.pxd":54 * # add an alignment tag with value to the AlignedSegment * # an existing tag of the same name will be replaced. * cpdef get_tag(self, tag, with_value_type=?) # <<<<<<<<<<<<<< @@ -887,11 +890,23 @@ struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag { int __pyx_n; PyObject *with_value_type; }; + +/* "pysam/libcalignedsegment.pxd":63 + * + * # returns a valid sam alignment string (deprecated) + * cpdef tostring(self, htsfile=*) # <<<<<<<<<<<<<< + * + * + */ +struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring { + int __pyx_n; + PyObject *htsfile; +}; struct __pyx_t_5pysam_17libcalignmentfile___iterdata; typedef struct __pyx_t_5pysam_17libcalignmentfile___iterdata __pyx_t_5pysam_17libcalignmentfile___iterdata; -struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData; +struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator; -/* "pysam/libcalignmentfile.pxd":29 +/* "pysam/libcalignmentfile.pxd":24 * # Utility types * * ctypedef struct __iterdata: # <<<<<<<<<<<<<< @@ -906,21 +921,28 @@ struct __pyx_t_5pysam_17libcalignmentfile___iterdata { int tid; char *seq; int seq_len; + int min_mapping_quality; + int flag_require; + int flag_filter; + int compute_baq; + int redo_baq; + int ignore_orphans; + int adjust_capq_threshold; }; -/* "pysam/libcalignmentfile.pxd":131 - * cdef char * getSequence(self) - * cdef setMask(self, mask) - * cdef setupIteratorData(self, # <<<<<<<<<<<<<< - * int tid, - * int start, +/* "pysam/libcalignmentfile.pxd":138 + * cdef int cnext(self) + * cdef char * get_sequence(self) + * cdef _setup_iterator(self, # <<<<<<<<<<<<<< + * int tid, + * int start, */ -struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData { +struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator { int __pyx_n; int multiple_iterators; }; -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -934,6 +956,7 @@ struct __pyx_obj_5pysam_10libchtslib_HTSFile { int64_t start_offset; PyObject *filename; PyObject *mode; + PyObject *threads; PyObject *index_filename; int is_stream; int is_remote; @@ -965,7 +988,7 @@ struct __pyx_obj_5pysam_9libcfaidx_FastaFile { * * cdef class FastqProxy: # <<<<<<<<<<<<<< * cdef kseq_t * _delegate - * cdef cython.str tostring(self) + * cdef cython.str to_string(self) */ struct __pyx_obj_5pysam_9libcfaidx_FastqProxy { PyObject_HEAD @@ -974,16 +997,16 @@ struct __pyx_obj_5pysam_9libcfaidx_FastqProxy { }; -/* "pysam/libcfaidx.pxd":51 +/* "pysam/libcfaidx.pxd":52 * * - * cdef class PersistentFastqProxy: # <<<<<<<<<<<<<< + * cdef class FastxRecord: # <<<<<<<<<<<<<< * """ * Python container for pysam.libcfaidx.FastqProxy with persistence. */ -struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy { +struct __pyx_obj_5pysam_9libcfaidx_FastxRecord { PyObject_HEAD - struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_vtab; + struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *__pyx_vtab; PyObject *comment; PyObject *quality; PyObject *sequence; @@ -991,8 +1014,8 @@ struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy { }; -/* "pysam/libcfaidx.pxd":60 - * +/* "pysam/libcfaidx.pxd":61 + * cpdef array.array get_quality_array(self, int offset=*) * * cdef class FastxFile: # <<<<<<<<<<<<<< * cdef object _filename @@ -1009,7 +1032,7 @@ struct __pyx_obj_5pysam_9libcfaidx_FastxFile { }; -/* "pysam/libcfaidx.pxd":72 +/* "pysam/libcfaidx.pxd":73 * * # Compatibility Layer for pysam 0.8.1 * cdef class FastqFile(FastxFile): # <<<<<<<<<<<<<< @@ -1021,7 +1044,7 @@ struct __pyx_obj_5pysam_9libcfaidx_FastqFile { }; -/* "pysam/libcfaidx.pxd":77 +/* "pysam/libcfaidx.pxd":78 * * # Compatibility Layer for pysam < 0.8 * cdef class Fastafile(FastaFile): # <<<<<<<<<<<<<< @@ -1033,7 +1056,7 @@ struct __pyx_obj_5pysam_9libcfaidx_Fastafile { }; -/* "pysam/libcalignedsegment.pxd":40 +/* "pysam/libcalignedsegment.pxd":34 * * # Note: need to declare all C fields and methods here * cdef class AlignedSegment: # <<<<<<<<<<<<<< @@ -1044,7 +1067,7 @@ struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment { PyObject_HEAD struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *__pyx_vtab; bam1_t *_delegate; - struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *_alignment_file; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; PyObject *cache_query_qualities; PyObject *cache_query_alignment_qualities; PyObject *cache_query_sequence; @@ -1052,7 +1075,7 @@ struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment { }; -/* "pysam/libcalignedsegment.pxd":69 +/* "pysam/libcalignedsegment.pxd":66 * * * cdef class PileupColumn: # <<<<<<<<<<<<<< @@ -1065,21 +1088,24 @@ struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn { int tid; int pos; int n_pu; - struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *_alignment_file; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; + uint32_t min_base_quality; + uint8_t *buf; + char *reference_sequence; }; -/* "pysam/libcalignedsegment.pxd":77 - * +/* "pysam/libcalignedsegment.pxd":76 + * cdef char * reference_sequence * * cdef class PileupRead: # <<<<<<<<<<<<<< - * cdef AlignedSegment _alignment * cdef int32_t _qpos + * cdef AlignedSegment _alignment */ struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead { PyObject_HEAD - struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *_alignment; int32_t _qpos; + struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *_alignment; int _indel; int _level; uint32_t _is_del; @@ -1089,23 +1115,36 @@ struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead { }; -/* "pysam/libcalignmentfile.pxd":39 +/* "pysam/libcalignmentfile.pxd":41 + * * + * cdef class AlignmentHeader(object): # <<<<<<<<<<<<<< + * cdef bam_hdr_t *ptr + * + */ +struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader { + PyObject_HEAD + bam_hdr_t *ptr; +}; + + +/* "pysam/libcalignmentfile.pxd":44 + * cdef bam_hdr_t *ptr * * cdef class AlignmentFile(HTSFile): # <<<<<<<<<<<<<< * cdef readonly object reference_filename - * + * cdef readonly AlignmentHeader header */ struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile { struct __pyx_obj_5pysam_10libchtslib_HTSFile __pyx_base; PyObject *reference_filename; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; hts_idx_t *index; - bam_hdr_t *header; bam1_t *b; }; -/* "pysam/libcalignmentfile.pxd":57 +/* "pysam/libcalignmentfile.pxd":61 * * * cdef class PileupColumn: # <<<<<<<<<<<<<< @@ -1121,7 +1160,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_PileupColumn { }; -/* "pysam/libcalignmentfile.pxd":64 +/* "pysam/libcalignmentfile.pxd":68 * * * cdef class PileupRead: # <<<<<<<<<<<<<< @@ -1141,7 +1180,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_PileupRead { }; -/* "pysam/libcalignmentfile.pxd":75 +/* "pysam/libcalignmentfile.pxd":79 * * * cdef class IteratorRow: # <<<<<<<<<<<<<< @@ -1154,12 +1193,13 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow { bam1_t *b; struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *samfile; htsFile *htsfile; - bam_hdr_t *header; + hts_idx_t *index; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; int owns_samfile; }; -/* "pysam/libcalignmentfile.pxd":84 +/* "pysam/libcalignmentfile.pxd":89 * * * cdef class IteratorRowRegion(IteratorRow): # <<<<<<<<<<<<<< @@ -1173,8 +1213,8 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion { }; -/* "pysam/libcalignmentfile.pxd":89 - * cdef int cnext(self) +/* "pysam/libcalignmentfile.pxd":95 + * * * cdef class IteratorRowHead(IteratorRow): # <<<<<<<<<<<<<< * cdef int max_rows @@ -1188,8 +1228,8 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead { }; -/* "pysam/libcalignmentfile.pxd":95 - * cdef int cnext(self) +/* "pysam/libcalignmentfile.pxd":102 + * * * cdef class IteratorRowAll(IteratorRow): # <<<<<<<<<<<<<< * cdef bam1_t * getCurrent(self) @@ -1201,7 +1241,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll { }; -/* "pysam/libcalignmentfile.pxd":100 +/* "pysam/libcalignmentfile.pxd":107 * * * cdef class IteratorRowAllRefs(IteratorRow): # <<<<<<<<<<<<<< @@ -1215,7 +1255,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs { }; -/* "pysam/libcalignmentfile.pxd":105 +/* "pysam/libcalignmentfile.pxd":112 * * * cdef class IteratorRowSelection(IteratorRow): # <<<<<<<<<<<<<< @@ -1230,7 +1270,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection { }; -/* "pysam/libcalignmentfile.pxd":112 +/* "pysam/libcalignmentfile.pxd":119 * * * cdef class IteratorColumn: # <<<<<<<<<<<<<< @@ -1244,33 +1284,34 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn { int tid; int pos; int n_plp; - int mask; + uint32_t min_base_quality; bam_pileup1_t *plp; - bam_plp_t pileup_iter; + bam_mplp_t pileup_iter; __pyx_t_5pysam_17libcalignmentfile___iterdata iterdata; struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *samfile; - struct __pyx_obj_5pysam_9libcfaidx_Fastafile *fastafile; + struct __pyx_obj_5pysam_9libcfaidx_FastaFile *fastafile; PyObject *stepper; int max_depth; + int ignore_overlaps; }; -/* "pysam/libcalignmentfile.pxd":141 +/* "pysam/libcalignmentfile.pxd":150 * * * cdef class IteratorColumnRegion(IteratorColumn): # <<<<<<<<<<<<<< * cdef int start - * cdef int end + * cdef int stop */ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion { struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn __pyx_base; int start; - int end; + int stop; int truncate; }; -/* "pysam/libcalignmentfile.pxd":147 +/* "pysam/libcalignmentfile.pxd":156 * * * cdef class IteratorColumnAllRefs(IteratorColumn): # <<<<<<<<<<<<<< @@ -1282,7 +1323,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs { }; -/* "pysam/libcalignmentfile.pxd":151 +/* "pysam/libcalignmentfile.pxd":160 * * * cdef class IndexedReads: # <<<<<<<<<<<<<< @@ -1295,7 +1336,7 @@ struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads { htsFile *htsfile; PyObject *index; int owns_samfile; - bam_hdr_t *header; + struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header; }; @@ -1324,7 +1365,7 @@ struct __pyx_obj_5pysam_11libcsamfile_Samfile { -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -1357,33 +1398,35 @@ static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile *__pyx_vtabptr_5pysam * * cdef class FastqProxy: # <<<<<<<<<<<<<< * cdef kseq_t * _delegate - * cdef cython.str tostring(self) + * cdef cython.str to_string(self) */ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy { + PyObject *(*to_string)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *); PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *); arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array *__pyx_optional_args); }; static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy *__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy; -/* "pysam/libcfaidx.pxd":51 +/* "pysam/libcfaidx.pxd":52 * * - * cdef class PersistentFastqProxy: # <<<<<<<<<<<<<< + * cdef class FastxRecord: # <<<<<<<<<<<<<< * """ * Python container for pysam.libcfaidx.FastqProxy with persistence. */ -struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy { - PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *); - arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_20PersistentFastqProxy_get_quality_array *__pyx_optional_args); +struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord { + PyObject *(*to_string)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *); + PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *); + arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array *__pyx_optional_args); }; -static struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy *__pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy; +static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *__pyx_vtabptr_5pysam_9libcfaidx_FastxRecord; -/* "pysam/libcfaidx.pxd":60 - * +/* "pysam/libcfaidx.pxd":61 + * cpdef array.array get_quality_array(self, int offset=*) * * cdef class FastxFile: # <<<<<<<<<<<<<< * cdef object _filename @@ -1397,7 +1440,7 @@ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile { static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile *__pyx_vtabptr_5pysam_9libcfaidx_FastxFile; -/* "pysam/libcfaidx.pxd":72 +/* "pysam/libcfaidx.pxd":73 * * # Compatibility Layer for pysam 0.8.1 * cdef class FastqFile(FastxFile): # <<<<<<<<<<<<<< @@ -1411,7 +1454,7 @@ struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile { static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile *__pyx_vtabptr_5pysam_9libcfaidx_FastqFile; -/* "pysam/libcfaidx.pxd":77 +/* "pysam/libcfaidx.pxd":78 * * # Compatibility Layer for pysam < 0.8 * cdef class Fastafile(FastaFile): # <<<<<<<<<<<<<< @@ -1425,7 +1468,7 @@ struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile { static struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile *__pyx_vtabptr_5pysam_9libcfaidx_Fastafile; -/* "pysam/libcalignedsegment.pxd":40 +/* "pysam/libcalignedsegment.pxd":34 * * # Note: need to declare all C fields and methods here * cdef class AlignedSegment: # <<<<<<<<<<<<<< @@ -1437,17 +1480,18 @@ struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment { PyObject *(*set_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag *__pyx_optional_args); PyObject *(*get_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag *__pyx_optional_args); PyObject *(*has_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch); - PyObject *(*tostring)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, __pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t, int __pyx_skip_dispatch); + PyObject *(*to_string)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch); + PyObject *(*tostring)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring *__pyx_optional_args); }; static struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *__pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment; -/* "pysam/libcalignmentfile.pxd":39 - * +/* "pysam/libcalignmentfile.pxd":44 + * cdef bam_hdr_t *ptr * * cdef class AlignmentFile(HTSFile): # <<<<<<<<<<<<<< * cdef readonly object reference_filename - * + * cdef readonly AlignmentHeader header */ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile { @@ -1459,7 +1503,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *__pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile; -/* "pysam/libcalignmentfile.pxd":84 +/* "pysam/libcalignmentfile.pxd":89 * * * cdef class IteratorRowRegion(IteratorRow): # <<<<<<<<<<<<<< @@ -1474,8 +1518,8 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion; -/* "pysam/libcalignmentfile.pxd":89 - * cdef int cnext(self) +/* "pysam/libcalignmentfile.pxd":95 + * * * cdef class IteratorRowHead(IteratorRow): # <<<<<<<<<<<<<< * cdef int max_rows @@ -1489,8 +1533,8 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead; -/* "pysam/libcalignmentfile.pxd":95 - * cdef int cnext(self) +/* "pysam/libcalignmentfile.pxd":102 + * * * cdef class IteratorRowAll(IteratorRow): # <<<<<<<<<<<<<< * cdef bam1_t * getCurrent(self) @@ -1504,7 +1548,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll; -/* "pysam/libcalignmentfile.pxd":105 +/* "pysam/libcalignmentfile.pxd":112 * * * cdef class IteratorRowSelection(IteratorRow): # <<<<<<<<<<<<<< @@ -1519,7 +1563,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection; -/* "pysam/libcalignmentfile.pxd":112 +/* "pysam/libcalignmentfile.pxd":119 * * * cdef class IteratorColumn: # <<<<<<<<<<<<<< @@ -1529,21 +1573,21 @@ static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection * struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn { int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); - char *(*getSequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); - PyObject *(*setMask)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, PyObject *); - PyObject *(*setupIteratorData)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn_setupIteratorData *__pyx_optional_args); + char *(*get_sequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); + PyObject *(*_setup_iterator)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args); PyObject *(*reset)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, PyObject *, PyObject *, PyObject *); PyObject *(*_free_pileup_iter)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); + char *(*getSequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *); }; static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn; -/* "pysam/libcalignmentfile.pxd":141 +/* "pysam/libcalignmentfile.pxd":150 * * * cdef class IteratorColumnRegion(IteratorColumn): # <<<<<<<<<<<<<< * cdef int start - * cdef int end + * cdef int stop */ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion { @@ -1552,7 +1596,7 @@ struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion { static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion; -/* "pysam/libcalignmentfile.pxd":147 +/* "pysam/libcalignmentfile.pxd":156 * * * cdef class IteratorColumnAllRefs(IteratorColumn): # <<<<<<<<<<<<<< @@ -2243,7 +2287,7 @@ static PyTypeObject *__pyx_ptype_5pysam_10libchtslib_HTSFile = 0; /* Module declarations from 'pysam.libcfaidx' */ static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastaFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastqProxy = 0; -static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy = 0; +static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastxRecord = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastxFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastqFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_Fastafile = 0; @@ -2254,6 +2298,7 @@ static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn = 0; static PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_PileupRead = 0; /* Module declarations from 'pysam.libcalignmentfile' */ +static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader = 0; static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile = 0; static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_PileupColumn = 0; static PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_PileupRead = 0; @@ -2306,8 +2351,8 @@ static const char __pyx_k_collections[] = "collections"; static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; -static const char __pyx_k_self_b_self_header_self_htsfile[] = "self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling"; static const char __pyx_k_self__delegate_cannot_be_convert[] = "self._delegate cannot be converted to a Python object for pickling"; +static const char __pyx_k_self_b_self_htsfile_self_index_c[] = "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"; static PyObject *__pyx_n_s_AlignedRead; static PyObject *__pyx_n_s_MemoryError; static PyObject *__pyx_n_s_Samfile; @@ -2329,7 +2374,7 @@ static PyObject *__pyx_n_s_reduce; static PyObject *__pyx_n_s_reduce_cython; static PyObject *__pyx_n_s_reduce_ex; static PyObject *__pyx_kp_s_self__delegate_cannot_be_convert; -static PyObject *__pyx_kp_s_self_b_self_header_self_htsfile; +static PyObject *__pyx_kp_s_self_b_self_htsfile_self_index_c; static PyObject *__pyx_n_s_setstate; static PyObject *__pyx_n_s_setstate_cython; static PyObject *__pyx_n_s_struct; @@ -2354,7 +2399,7 @@ static PyObject *__pyx_tuple__4; /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -2382,9 +2427,9 @@ static PyObject *__pyx_pf_5pysam_11libcsamfile_7Samfile___reduce_cython__(CYTHON /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); @@ -2394,7 +2439,7 @@ static PyObject *__pyx_pf_5pysam_11libcsamfile_7Samfile___reduce_cython__(CYTHON /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): */ @@ -2411,9 +2456,9 @@ static PyObject *__pyx_pf_5pysam_11libcsamfile_7Samfile___reduce_cython__(CYTHON /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ /* Python wrapper */ @@ -2439,9 +2484,9 @@ static PyObject *__pyx_pf_5pysam_11libcsamfile_7Samfile_2__setstate_cython__(CYT __Pyx_TraceCall("__setstate_cython__", __pyx_f[0], 3, 0, __PYX_ERR(0, 3, __pyx_L1_error)); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); @@ -2451,9 +2496,9 @@ static PyObject *__pyx_pf_5pysam_11libcsamfile_7Samfile_2__setstate_cython__(CYT /* "(tree fragment)":3 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ /* function exit code */ @@ -3497,7 +3542,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, {&__pyx_kp_s_self__delegate_cannot_be_convert, __pyx_k_self__delegate_cannot_be_convert, sizeof(__pyx_k_self__delegate_cannot_be_convert), 0, 0, 1, 0}, - {&__pyx_kp_s_self_b_self_header_self_htsfile, __pyx_k_self_b_self_header_self_htsfile, sizeof(__pyx_k_self_b_self_header_self_htsfile), 0, 0, 1, 0}, + {&__pyx_kp_s_self_b_self_htsfile_self_index_c, __pyx_k_self_b_self_htsfile_self_index_c, sizeof(__pyx_k_self_b_self_htsfile_self_index_c), 0, 0, 1, 0}, {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, {&__pyx_n_s_struct, __pyx_k_struct, sizeof(__pyx_k_struct), 0, 0, 1, 1}, @@ -3522,20 +3567,20 @@ static int __Pyx_InitCachedConstants(void) { /* "(tree fragment)":2 * def __reduce_cython__(self): - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") */ - __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); /* "(tree fragment)":4 - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): - * raise TypeError("self.b,self.header,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< + * raise TypeError("self.b,self.htsfile,self.index cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_header_self_htsfile); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 4, __pyx_L1_error) + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_self_b_self_htsfile_self_index_c); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2); @@ -3656,41 +3701,42 @@ static int __Pyx_modinit_type_import_code(void) { __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) __PYX_ERR(4, 8, __pyx_L1_error) __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) __PYX_ERR(5, 15, __pyx_L1_error) __pyx_ptype_7cpython_5array_array = __Pyx_ImportType("array", "array", sizeof(arrayobject), 0); if (unlikely(!__pyx_ptype_7cpython_5array_array)) __PYX_ERR(1, 58, __pyx_L1_error) - __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(6, 1904, __pyx_L1_error) - __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(6, 1904, __pyx_L1_error) + __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(6, 2590, __pyx_L1_error) + __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(6, 2590, __pyx_L1_error) __pyx_ptype_5pysam_9libcfaidx_FastaFile = __Pyx_ImportType("pysam.libcfaidx", "FastaFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastaFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastaFile)) __PYX_ERR(7, 37, __pyx_L1_error) __pyx_vtabptr_5pysam_9libcfaidx_FastaFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastaFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastaFile)) __PYX_ERR(7, 37, __pyx_L1_error) __pyx_ptype_5pysam_9libcfaidx_FastqProxy = __Pyx_ImportType("pysam.libcfaidx", "FastqProxy", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastqProxy)) __PYX_ERR(7, 45, __pyx_L1_error) __pyx_vtabptr_5pysam_9libcfaidx_FastqProxy = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy)) __PYX_ERR(7, 45, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy = __Pyx_ImportType("pysam.libcfaidx", "PersistentFastqProxy", sizeof(struct __pyx_obj_5pysam_9libcfaidx_PersistentFastqProxy), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy)) __PYX_ERR(7, 51, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy = (struct __pyx_vtabstruct_5pysam_9libcfaidx_PersistentFastqProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_PersistentFastqProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_PersistentFastqProxy)) __PYX_ERR(7, 51, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_FastxFile = __Pyx_ImportType("pysam.libcfaidx", "FastxFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(7, 60, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_FastxFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(7, 60, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_FastqFile = __Pyx_ImportType("pysam.libcfaidx", "FastqFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(7, 72, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_FastqFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(7, 72, __pyx_L1_error) - __pyx_ptype_5pysam_9libcfaidx_Fastafile = __Pyx_ImportType("pysam.libcfaidx", "Fastafile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_Fastafile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(7, 77, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libcfaidx_Fastafile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_Fastafile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(7, 77, __pyx_L1_error) - __pyx_ptype_5pysam_18libcalignedsegment_PileupColumn = __Pyx_ImportType("pysam.libcalignedsegment", "PileupColumn", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn), 1); if (unlikely(!__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn)) __PYX_ERR(8, 69, __pyx_L1_error) - __pyx_ptype_5pysam_18libcalignedsegment_PileupRead = __Pyx_ImportType("pysam.libcalignedsegment", "PileupRead", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead), 1); if (unlikely(!__pyx_ptype_5pysam_18libcalignedsegment_PileupRead)) __PYX_ERR(8, 77, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_PileupColumn = __Pyx_ImportType("pysam.libcalignmentfile", "PileupColumn", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_PileupColumn), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_PileupColumn)) __PYX_ERR(9, 57, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_PileupRead = __Pyx_ImportType("pysam.libcalignmentfile", "PileupRead", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_PileupRead), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_PileupRead)) __PYX_ERR(9, 64, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRow", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow)) __PYX_ERR(9, 75, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowRegion", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion)) __PYX_ERR(9, 84, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion)) __PYX_ERR(9, 84, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowHead", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead)) __PYX_ERR(9, 89, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead)) __PYX_ERR(9, 89, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowAll", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll)) __PYX_ERR(9, 95, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll)) __PYX_ERR(9, 95, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowAllRefs", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs)) __PYX_ERR(9, 100, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowSelection", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection)) __PYX_ERR(9, 105, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection)) __PYX_ERR(9, 105, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorColumn", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn)) __PYX_ERR(9, 112, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn)) __PYX_ERR(9, 112, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorColumnRegion", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion)) __PYX_ERR(9, 141, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion)) __PYX_ERR(9, 141, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorColumnAllRefs", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs)) __PYX_ERR(9, 147, __pyx_L1_error) - __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs)) __PYX_ERR(9, 147, __pyx_L1_error) - __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads = __Pyx_ImportType("pysam.libcalignmentfile", "IndexedReads", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads)) __PYX_ERR(9, 151, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_FastxRecord = __Pyx_ImportType("pysam.libcfaidx", "FastxRecord", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastxRecord)) __PYX_ERR(7, 52, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_FastxRecord = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxRecord->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxRecord)) __PYX_ERR(7, 52, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_FastxFile = __Pyx_ImportType("pysam.libcfaidx", "FastxFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(7, 61, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_FastxFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(7, 61, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_FastqFile = __Pyx_ImportType("pysam.libcfaidx", "FastqFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(7, 73, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_FastqFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(7, 73, __pyx_L1_error) + __pyx_ptype_5pysam_9libcfaidx_Fastafile = __Pyx_ImportType("pysam.libcfaidx", "Fastafile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_Fastafile), 1); if (unlikely(!__pyx_ptype_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(7, 78, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libcfaidx_Fastafile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_Fastafile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(7, 78, __pyx_L1_error) + __pyx_ptype_5pysam_18libcalignedsegment_PileupColumn = __Pyx_ImportType("pysam.libcalignedsegment", "PileupColumn", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn), 1); if (unlikely(!__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn)) __PYX_ERR(8, 66, __pyx_L1_error) + __pyx_ptype_5pysam_18libcalignedsegment_PileupRead = __Pyx_ImportType("pysam.libcalignedsegment", "PileupRead", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead), 1); if (unlikely(!__pyx_ptype_5pysam_18libcalignedsegment_PileupRead)) __PYX_ERR(8, 76, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader = __Pyx_ImportType("pysam.libcalignmentfile", "AlignmentHeader", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader)) __PYX_ERR(9, 41, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_PileupColumn = __Pyx_ImportType("pysam.libcalignmentfile", "PileupColumn", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_PileupColumn), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_PileupColumn)) __PYX_ERR(9, 61, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_PileupRead = __Pyx_ImportType("pysam.libcalignmentfile", "PileupRead", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_PileupRead), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_PileupRead)) __PYX_ERR(9, 68, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRow", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow)) __PYX_ERR(9, 79, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowRegion", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion)) __PYX_ERR(9, 89, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion)) __PYX_ERR(9, 89, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowHead", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead)) __PYX_ERR(9, 95, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead)) __PYX_ERR(9, 95, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowAll", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll)) __PYX_ERR(9, 102, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll)) __PYX_ERR(9, 102, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowAllRefs", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs)) __PYX_ERR(9, 107, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorRowSelection", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection)) __PYX_ERR(9, 112, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection)) __PYX_ERR(9, 112, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorColumn", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn)) __PYX_ERR(9, 119, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn)) __PYX_ERR(9, 119, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorColumnRegion", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion)) __PYX_ERR(9, 150, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion)) __PYX_ERR(9, 150, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs = __Pyx_ImportType("pysam.libcalignmentfile", "IteratorColumnAllRefs", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs)) __PYX_ERR(9, 156, __pyx_L1_error) + __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs*)__Pyx_GetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs)) __PYX_ERR(9, 156, __pyx_L1_error) + __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads = __Pyx_ImportType("pysam.libcalignmentfile", "IndexedReads", sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads), 1); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads)) __PYX_ERR(9, 160, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; diff --git a/pysam/libcsamfile.pxd b/pysam/libcsamfile.pxd index de3699844..dff1345f6 100644 --- a/pysam/libcsamfile.pxd +++ b/pysam/libcsamfile.pxd @@ -36,10 +36,10 @@ cdef extern from "htslib_util.h": uint8_t pysam_get_qual(bam1_t * b) uint8_t pysam_get_l_qname(bam1_t * b) uint16_t pysam_get_flag(bam1_t * b) - uint16_t pysam_get_n_cigar(bam1_t * b) + uint32_t pysam_get_n_cigar(bam1_t * b) void pysam_set_bin(bam1_t * b, uint16_t v) void pysam_set_qual(bam1_t * b, uint8_t v) void pysam_set_l_qname(bam1_t * b, uint8_t v) void pysam_set_flag(bam1_t * b, uint16_t v) - void pysam_set_n_cigar(bam1_t * b, uint16_t v) + void pysam_set_n_cigar(bam1_t * b, uint32_t v) void pysam_update_flag(bam1_t * b, uint16_t v, uint16_t flag) diff --git a/pysam/libcsamtools.c b/pysam/libcsamtools.c new file mode 100644 index 000000000..7b1023fc5 --- /dev/null +++ b/pysam/libcsamtools.c @@ -0,0 +1,2364 @@ +/* Generated by Cython 0.28.3 */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) + #error Cython requires Python 2.6+ or Python 3.3+. +#else +#define CYTHON_ABI "0_28_3" +#define CYTHON_FUTURE_DIVISION 0 +#include +#ifndef offsetof + #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif +#if !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#define __PYX_COMMA , +#ifndef HAVE_LONG_LONG + #if PY_VERSION_HEX >= 0x02070000 + #define HAVE_LONG_LONG + #endif +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif +#ifdef PYPY_VERSION + #define CYTHON_COMPILING_IN_PYPY 1 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 +#elif defined(PYSTON_VERSION) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 1 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 +#else + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #elif !defined(CYTHON_USE_PYTYPE_LOOKUP) + #define CYTHON_USE_PYTYPE_LOOKUP 1 + #endif + #if PY_MAJOR_VERSION < 3 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #elif !defined(CYTHON_USE_PYLONG_INTERNALS) + #define CYTHON_USE_PYLONG_INTERNALS 1 + #endif + #ifndef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 1 + #endif + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #if PY_VERSION_HEX < 0x030300F0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #elif !defined(CYTHON_USE_UNICODE_WRITER) + #define CYTHON_USE_UNICODE_WRITER 1 + #endif + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #ifndef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 1 + #endif + #ifndef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 1 + #endif + #ifndef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT (0 && PY_VERSION_HEX >= 0x03050000) + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) + #endif +#endif +#if !defined(CYTHON_FAST_PYCCALL) +#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) +#endif +#if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #undef SHIFT + #undef BASE + #undef MASK +#endif +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif +#ifndef __has_cpp_attribute + #define __has_cpp_attribute(x) 0 +#endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_MAYBE_UNUSED_VAR +# if defined(__cplusplus) + template void CYTHON_MAYBE_UNUSED_VAR( const T& ) { } +# else +# define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x) +# endif +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) +#ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned char uint8_t; + typedef unsigned int uint32_t; + #else + typedef unsigned __int8 uint8_t; + typedef unsigned __int32 uint32_t; + #endif + #endif +#else + #include +#endif +#ifndef CYTHON_FALLTHROUGH + #if defined(__cplusplus) && __cplusplus >= 201103L + #if __has_cpp_attribute(fallthrough) + #define CYTHON_FALLTHROUGH [[fallthrough]] + #elif __has_cpp_attribute(clang::fallthrough) + #define CYTHON_FALLTHROUGH [[clang::fallthrough]] + #elif __has_cpp_attribute(gnu::fallthrough) + #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_attribute(fallthrough) + #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) + #else + #define CYTHON_FALLTHROUGH + #endif + #endif + #if defined(__clang__ ) && defined(__apple_build_version__) + #if __apple_build_version__ < 7000000 + #undef CYTHON_FALLTHROUGH + #define CYTHON_FALLTHROUGH + #endif + #endif +#endif + +#ifndef CYTHON_INLINE + #if defined(__clang__) + #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) + #elif defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) + #define Py_OptimizeFlag 0 +#endif +#define __PYX_BUILD_PY_SSIZE_T "n" +#define CYTHON_FORMAT_SSIZE_T "z" +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyClass_Type +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyType_Type +#endif +#ifndef Py_TPFLAGS_CHECKTYPES + #define Py_TPFLAGS_CHECKTYPES 0 +#endif +#ifndef Py_TPFLAGS_HAVE_INDEX + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#ifndef Py_TPFLAGS_HAVE_NEWBUFFER + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#ifndef Py_TPFLAGS_HAVE_FINALIZE + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif +#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) + #ifndef METH_FASTCALL + #define METH_FASTCALL 0x80 + #endif + typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); + typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, + Py_ssize_t nargs, PyObject *kwnames); +#else + #define __Pyx_PyCFunctionFast _PyCFunctionFast + #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords +#endif +#if CYTHON_FAST_PYCCALL +#define __Pyx_PyFastCFunction_Check(func)\ + ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS))))) +#else +#define __Pyx_PyFastCFunction_Check(func) 0 +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) + #define PyObject_Malloc(s) PyMem_Malloc(s) + #define PyObject_Free(p) PyMem_Free(p) + #define PyObject_Realloc(p) PyMem_Realloc(p) +#endif +#if CYTHON_COMPILING_IN_PYSTON + #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno) +#else + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) +#endif +#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#elif PY_VERSION_HEX >= 0x03060000 + #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() +#elif PY_VERSION_HEX >= 0x03000000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#else + #define __Pyx_PyThreadState_Current _PyThreadState_Current +#endif +#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) +#include "pythread.h" +#define Py_tss_NEEDS_INIT 0 +typedef int Py_tss_t; +static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { + *key = PyThread_create_key(); + return 0; // PyThread_create_key reports success always +} +static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { + Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); + *key = Py_tss_NEEDS_INIT; + return key; +} +static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { + PyObject_Free(key); +} +static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { + return *key != Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { + PyThread_delete_key(*key); + *key = Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { + return PyThread_set_key_value(*key, value); +} +static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { + return PyThread_get_key_value(*key); +} +#endif // TSS (Thread Specific Storage) API +#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized) +#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) +#else +#define __Pyx_PyDict_NewPresized(n) PyDict_New() +#endif +#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS +#define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) +#else +#define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name) +#endif +#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) + #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) +#else + #define CYTHON_PEP393_ENABLED 0 + #define PyUnicode_1BYTE_KIND 1 + #define PyUnicode_2BYTE_KIND 2 + #define PyUnicode_4BYTE_KIND 4 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111) + #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) + #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) + #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) + #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) +#endif +#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) + #define PyObject_ASCII(o) PyObject_Repr(o) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact + #define PyObject_Unicode PyObject_Str +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) + #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) +#else + #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) +#endif +#if CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) +#else + #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif +#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY + #ifndef PyUnicode_InternFromString + #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) + #endif +#endif +#if PY_VERSION_HEX < 0x030200A4 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t PyInt_AsLong +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func)) +#else + #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) +#endif +#if CYTHON_USE_ASYNC_SLOTS + #if PY_VERSION_HEX >= 0x030500B1 + #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods + #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) + #else + #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) + #endif +#else + #define __Pyx_PyType_AsAsync(obj) NULL +#endif +#ifndef __Pyx_PyAsyncMethodsStruct + typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; + } __Pyx_PyAsyncMethodsStruct; +#endif + +#if defined(WIN32) || defined(MS_WINDOWS) + #define _USE_MATH_DEFINES +#endif +#include +#ifdef NAN +#define __PYX_NAN() ((float) NAN) +#else +static CYTHON_INLINE float __PYX_NAN() { + float value; + memset(&value, 0xFF, sizeof(value)); + return value; +} +#endif +#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) +#define __Pyx_truncl trunc +#else +#define __Pyx_truncl truncl +#endif + + +#define __PYX_ERR(f_index, lineno, Ln_error) \ +{ \ + __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \ +} + +#ifndef __PYX_EXTERN_C + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#define __PYX_HAVE__pysam__libcsamtools +#define __PYX_HAVE_API__pysam__libcsamtools +/* Early includes */ +#include "samtools.pysam.h" +#ifdef _OPENMP +#include +#endif /* _OPENMP */ + +#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) +#define CYTHON_WITHOUT_ASSERTIONS +#endif + +typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; + const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; + +#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0 +#define __PYX_DEFAULT_STRING_ENCODING "" +#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString +#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_uchar_cast(c) ((unsigned char)c) +#define __Pyx_long_cast(x) ((long)x) +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ + (sizeof(type) < sizeof(Py_ssize_t)) ||\ + (sizeof(type) > sizeof(Py_ssize_t) &&\ + likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX) &&\ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ + v == (type)PY_SSIZE_T_MIN))) ||\ + (sizeof(type) == sizeof(Py_ssize_t) &&\ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX))) ) +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #define __Pyx_sst_abs(value) std::abs(value) +#elif SIZEOF_INT >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) abs(value) +#elif SIZEOF_LONG >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) labs(value) +#elif defined (_MSC_VER) + #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define __Pyx_sst_abs(value) llabs(value) +#elif defined (__GNUC__) + #define __Pyx_sst_abs(value) __builtin_llabs(value) +#else + #define __Pyx_sst_abs(value) ((value<0) ? -value : value) +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#else + #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize +#endif +#define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) +static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { + const Py_UNICODE *u_end = u; + while (*u_end++) ; + return (size_t)(u_end - u - 1); +} +#define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) +#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode +#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode +#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) +#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); +#define __Pyx_PySequence_Tuple(obj)\ + (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +#if CYTHON_ASSUME_SAFE_MACROS +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) +#else +#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) +#endif +#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII +static int __Pyx_sys_getdefaultencoding_not_ascii; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + PyObject* ascii_chars_u = NULL; + PyObject* ascii_chars_b = NULL; + const char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + if (strcmp(default_encoding_c, "ascii") == 0) { + __Pyx_sys_getdefaultencoding_not_ascii = 0; + } else { + char ascii_chars[128]; + int c; + for (c = 0; c < 128; c++) { + ascii_chars[c] = c; + } + __Pyx_sys_getdefaultencoding_not_ascii = 1; + ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); + if (!ascii_chars_u) goto bad; + ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); + if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { + PyErr_Format( + PyExc_ValueError, + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", + default_encoding_c); + goto bad; + } + Py_DECREF(ascii_chars_u); + Py_DECREF(ascii_chars_b); + } + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + Py_XDECREF(ascii_chars_u); + Py_XDECREF(ascii_chars_b); + return -1; +} +#endif +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) +#else +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +static char* __PYX_DEFAULT_STRING_ENCODING; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c)); + if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; + strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + return -1; +} +#endif +#endif + + +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ +static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } + +static PyObject *__pyx_m = NULL; +static PyObject *__pyx_d; +static PyObject *__pyx_b; +static PyObject *__pyx_cython_runtime = NULL; +static PyObject *__pyx_empty_tuple; +static PyObject *__pyx_empty_bytes; +static PyObject *__pyx_empty_unicode; +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm= __FILE__; +static const char *__pyx_filename; + + +static const char *__pyx_f[] = { + "pysam/libcsamtools.pyx", +}; + +/*--- Type declarations ---*/ + +/* --- Runtime support code (head) --- */ +/* Refnanny.proto */ +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif +#if CYTHON_REFNANNY + typedef struct { + void (*INCREF)(void*, PyObject*, int); + void (*DECREF)(void*, PyObject*, int); + void (*GOTREF)(void*, PyObject*, int); + void (*GIVEREF)(void*, PyObject*, int); + void* (*SetupContext)(const char*, int, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); + #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; +#ifdef WITH_THREAD + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + if (acquire_gil) {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + PyGILState_Release(__pyx_gilstate_save);\ + } else {\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) +#endif + #define __Pyx_RefNannyFinishContext()\ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif +#define __Pyx_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_XDECREF(tmp);\ + } while (0) +#define __Pyx_DECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_DECREF(tmp);\ + } while (0) +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +/* PyObjectGetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) +#endif + +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; +#define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#define __Pyx_PyErr_Occurred() PyErr_Occurred() +#endif + +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) +#else +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#endif +#else +#define __Pyx_PyErr_Clear() PyErr_Clear() +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* CLineInTraceback.proto */ +#ifdef CYTHON_CLINE_IN_TRACEBACK +#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) +#else +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); +#endif + +/* CodeObjectCache.proto */ +typedef struct { + PyCodeObject* code_object; + int code_line; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); + +/* AddTraceback.proto */ +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* FastTypeChecks.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); +#else +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) +#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) +#endif +#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) + +/* CheckBinaryVersion.proto */ +static int __Pyx_check_binary_version(void); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + + +/* Module declarations from 'pysam.libcsamtools' */ +#define __Pyx_MODULE_NAME "pysam.libcsamtools" +extern int __pyx_module_is_main_pysam__libcsamtools; +int __pyx_module_is_main_pysam__libcsamtools = 0; + +/* Implementation of 'pysam.libcsamtools' */ +static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_py_samtools[] = "py_samtools"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_pysam_libcsamtools[] = "pysam.libcsamtools"; +static const char __pyx_k_pysam_libcsamtools_pyx[] = "pysam/libcsamtools.pyx"; +static PyObject *__pyx_n_s_cline_in_traceback; +static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_py_samtools; +static PyObject *__pyx_n_s_pysam_libcsamtools; +static PyObject *__pyx_kp_s_pysam_libcsamtools_pyx; +static PyObject *__pyx_n_s_test; +static PyObject *__pyx_pf_5pysam_12libcsamtools_py_samtools(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_codeobj_; +/* Late includes */ + +/* "pysam/libcsamtools.pyx":1 + * def py_samtools(): # <<<<<<<<<<<<<< + * pass + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_12libcsamtools_1py_samtools(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyMethodDef __pyx_mdef_5pysam_12libcsamtools_1py_samtools = {"py_samtools", (PyCFunction)__pyx_pw_5pysam_12libcsamtools_1py_samtools, METH_NOARGS, 0}; +static PyObject *__pyx_pw_5pysam_12libcsamtools_1py_samtools(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("py_samtools (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_12libcsamtools_py_samtools(__pyx_self); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_12libcsamtools_py_samtools(CYTHON_UNUSED PyObject *__pyx_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("py_samtools", 0); + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; + +#if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec_libcsamtools(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_libcsamtools}, + {0, NULL} +}; +#endif + +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + "libcsamtools", + 0, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #else + -1, /* m_size */ + #endif + __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else + NULL, /* m_reload */ + #endif + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ +}; +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_py_samtools, __pyx_k_py_samtools, sizeof(__pyx_k_py_samtools), 0, 0, 1, 1}, + {&__pyx_n_s_pysam_libcsamtools, __pyx_k_pysam_libcsamtools, sizeof(__pyx_k_pysam_libcsamtools), 0, 0, 1, 1}, + {&__pyx_kp_s_pysam_libcsamtools_pyx, __pyx_k_pysam_libcsamtools_pyx, sizeof(__pyx_k_pysam_libcsamtools_pyx), 0, 0, 1, 0}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static int __Pyx_InitCachedBuiltins(void) { + return 0; +} + +static int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "pysam/libcsamtools.pyx":1 + * def py_samtools(): # <<<<<<<<<<<<<< + * pass + */ + __pyx_codeobj_ = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcsamtools_pyx, __pyx_n_s_py_samtools, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + return 0; + __pyx_L1_error:; + return -1; +} + +static int __Pyx_modinit_global_init_code(void); /*proto*/ +static int __Pyx_modinit_variable_export_code(void); /*proto*/ +static int __Pyx_modinit_function_export_code(void); /*proto*/ +static int __Pyx_modinit_type_init_code(void); /*proto*/ +static int __Pyx_modinit_type_import_code(void); /*proto*/ +static int __Pyx_modinit_variable_import_code(void); /*proto*/ +static int __Pyx_modinit_function_import_code(void); /*proto*/ + +static int __Pyx_modinit_global_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); + /*--- Global init code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); + /*--- Variable export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); + /*--- Function export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); + /*--- Variable import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); + /*--- Function import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + + +#if PY_MAJOR_VERSION < 3 +#ifdef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC void +#else +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#endif +#else +#ifdef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#endif +#endif +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4))) + #define CYTHON_SMALL_CODE __attribute__((optimize("Os"))) +#else + #define CYTHON_SMALL_CODE +#endif +#endif + + +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC initlibcsamtools(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC initlibcsamtools(void) +#else +__Pyx_PyMODINIT_FUNC PyInit_libcsamtools(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_libcsamtools(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) { + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + result = PyDict_SetItemString(moddict, to_name, value); + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + if (__pyx_m) + return __Pyx_NewRef(__pyx_m); + modname = PyObject_GetAttrString(spec, "name"); + if (unlikely(!modname)) goto bad; + module = PyModule_NewObject(modname); + Py_DECREF(modname); + if (unlikely(!module)) goto bad; + moddict = PyModule_GetDict(module); + if (unlikely(!moddict)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static int __pyx_pymod_exec_libcsamtools(PyObject *__pyx_pyinit_module) +#endif +#endif +{ + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0; + #elif PY_MAJOR_VERSION >= 3 + if (__pyx_m) return __Pyx_NewRef(__pyx_m); + #endif + #if CYTHON_REFNANNY +__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); +if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); +} +#endif + __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_libcsamtools(void)", 0); + if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + #ifdef WITH_THREAD /* Python build with threading support? */ + PyEval_InitThreads(); + #endif + #endif + /*--- Module creation code ---*/ + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_m = __pyx_pyinit_module; + Py_INCREF(__pyx_m); + #else + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("libcsamtools", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + #endif + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + #if CYTHON_COMPILING_IN_PYPY + Py_INCREF(__pyx_b); + #endif + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main_pysam__libcsamtools) { + if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "pysam.libcsamtools")) { + if (unlikely(PyDict_SetItemString(modules, "pysam.libcsamtools", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) + } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global type/function init code ---*/ + (void)__Pyx_modinit_global_init_code(); + (void)__Pyx_modinit_variable_export_code(); + (void)__Pyx_modinit_function_export_code(); + (void)__Pyx_modinit_type_init_code(); + (void)__Pyx_modinit_type_import_code(); + (void)__Pyx_modinit_variable_import_code(); + (void)__Pyx_modinit_function_import_code(); + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + + /* "pysam/libcsamtools.pyx":1 + * def py_samtools(): # <<<<<<<<<<<<<< + * pass + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_12libcsamtools_1py_samtools, NULL, __pyx_n_s_pysam_libcsamtools); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_py_samtools, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /*--- Wrapped vars code ---*/ + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + if (__pyx_m) { + if (__pyx_d) { + __Pyx_AddTraceback("init pysam.libcsamtools", 0, __pyx_lineno, __pyx_filename); + } + Py_DECREF(__pyx_m); __pyx_m = 0; + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init pysam.libcsamtools"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if CYTHON_PEP489_MULTI_PHASE_INIT + return (__pyx_m != NULL) ? 0 : -1; + #elif PY_MAJOR_VERSION >= 3 + return __pyx_m; + #else + return; + #endif +} + +/* --- Runtime support code --- */ +/* Refnanny */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule((char *)modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; +} +#endif + +/* PyObjectGetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); +#endif + return PyObject_GetAttr(obj, attr_name); +} +#endif + +/* PyErrFetchRestore */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +} +#endif + +/* CLineInTraceback */ +#ifndef CYTHON_CLINE_IN_TRACEBACK +static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) { + PyObject *use_cline; + PyObject *ptype, *pvalue, *ptraceback; +#if CYTHON_COMPILING_IN_CPYTHON + PyObject **cython_runtime_dict; +#endif + if (unlikely(!__pyx_cython_runtime)) { + return c_line; + } + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); +#if CYTHON_COMPILING_IN_CPYTHON + cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); + if (likely(cython_runtime_dict)) { + use_cline = __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback); + } else +#endif + { + PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); + if (use_cline_obj) { + use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; + Py_DECREF(use_cline_obj); + } else { + PyErr_Clear(); + use_cline = NULL; + } + } + if (!use_cline) { + c_line = 0; + PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); + } + else if (PyObject_Not(use_cline) != 0) { + c_line = 0; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + return c_line; +} +#endif + +/* CodeObjectCache */ +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = start + (end - start) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} + +/* AddTraceback */ +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + #if PY_MAJOR_VERSION < 3 + py_srcfile = PyString_FromString(filename); + #else + py_srcfile = PyUnicode_FromString(filename); + #endif + if (!py_srcfile) goto bad; + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + #else + py_funcname = PyUnicode_FromString(funcname); + #endif + } + if (!py_funcname) goto bad; + py_code = __Pyx_PyCode_New( + 0, + 0, + 0, + 0, + 0, + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + Py_DECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + if (c_line) { + c_line = __Pyx_CLineForTraceback(tstate, c_line); + } + py_code = __pyx_find_code_object(c_line ? -c_line : py_line); + if (!py_code) { + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) goto bad; + __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); + } + py_frame = PyFrame_New( + tstate, /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + __Pyx_PyFrame_SetLineNumber(py_frame, py_line); + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} + +/* CIntToPy */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) -1, const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); + } +} + +/* CIntFromPyVerify */ +#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) +#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) +#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ + {\ + func_type value = func_value;\ + if (sizeof(target_type) < sizeof(func_type)) {\ + if (unlikely(value != (func_type) (target_type) value)) {\ + func_type zero = 0;\ + if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ + return (target_type) -1;\ + if (is_unsigned && unlikely(value < zero))\ + goto raise_neg_overflow;\ + else\ + goto raise_overflow;\ + }\ + }\ + return (target_type) value;\ + } + +/* CIntFromPy */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { + const long neg_one = (long) -1, const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(long) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (long) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { + return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { + return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { + return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (long) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(long) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) + case -2: + if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + } +#endif + if (sizeof(long) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + long val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (long) -1; + } + } else { + long val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to long"); + return (long) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; +} + +/* CIntFromPy */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { + const int neg_one = (int) -1, const_zero = (int) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(int) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { + return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { + return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { + return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(int) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) + case -2: + if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + } +#endif + if (sizeof(int) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + int val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (int) -1; + } + } else { + int val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; +} + +/* FastTypeChecks */ +#if CYTHON_COMPILING_IN_CPYTHON +static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { + while (a) { + a = a->tp_base; + if (a == b) + return 1; + } + return b == &PyBaseObject_Type; +} +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (a == b) return 1; + mro = a->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(a, b); +} +#if PY_MAJOR_VERSION == 2 +static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { + PyObject *exception, *value, *tb; + int res; + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&exception, &value, &tb); + res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + if (!res) { + res = PyObject_IsSubclass(err, exc_type2); + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + } + __Pyx_ErrRestore(exception, value, tb); + return res; +} +#else +static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { + int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; + if (!res) { + res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + } + return res; +} +#endif +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) { + if (likely(err == exc_type)) return 1; + if (likely(PyExceptionClass_Check(err))) { + return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type); + } + return PyErr_GivenExceptionMatches(err, exc_type); +} +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) { + if (likely(err == exc_type1 || err == exc_type2)) return 1; + if (likely(PyExceptionClass_Check(err))) { + return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2); + } + return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2)); +} +#endif + +/* CheckBinaryVersion */ +static int __Pyx_check_binary_version(void) { + char ctversion[4], rtversion[4]; + PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); + PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); + if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compiletime version %s of module '%.100s' " + "does not match runtime version %s", + ctversion, __Pyx_MODULE_NAME, rtversion); + return PyErr_WarnEx(NULL, message, 1); + } + return 0; +} + +/* InitStrings */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION < 3 + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + #else + if (t->is_unicode | t->is_str) { + if (t->intern) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->encoding) { + *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); + } else { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); + } + } else { + *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); + } + #endif + if (!*t->p) + return -1; + if (PyObject_Hash(*t->p) == -1) + return -1; + ++t; + } + return 0; +} + +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { + return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); +} +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { + Py_ssize_t ignore; + return __Pyx_PyObject_AsStringAndSize(o, &ignore); +} +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#if !CYTHON_PEP393_ENABLED +static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + char* defenc_c; + PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); + if (!defenc) return NULL; + defenc_c = PyBytes_AS_STRING(defenc); +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + { + char* end = defenc_c + PyBytes_GET_SIZE(defenc); + char* c; + for (c = defenc_c; c < end; c++) { + if ((unsigned char) (*c) >= 128) { + PyUnicode_AsASCIIString(o); + return NULL; + } + } + } +#endif + *length = PyBytes_GET_SIZE(defenc); + return defenc_c; +} +#else +static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + if (likely(PyUnicode_IS_ASCII(o))) { + *length = PyUnicode_GET_LENGTH(o); + return PyUnicode_AsUTF8(o); + } else { + PyUnicode_AsASCIIString(o); + return NULL; + } +#else + return PyUnicode_AsUTF8AndSize(o, length); +#endif +} +#endif +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT + if ( +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + __Pyx_sys_getdefaultencoding_not_ascii && +#endif + PyUnicode_Check(o)) { + return __Pyx_PyUnicode_AsStringAndSize(o, length); + } else +#endif +#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif + { + char* result; + int r = PyBytes_AsStringAndSize(o, &result, length); + if (unlikely(r < 0)) { + return NULL; + } else { + return result; + } + } +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} +static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(result)) { + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "__int__ returned non-int (type %.200s). " + "The ability to return an instance of a strict subclass of int " + "is deprecated, and may be removed in a future version of Python.", + Py_TYPE(result)->tp_name)) { + Py_DECREF(result); + return NULL; + } + return result; + } +#endif + PyErr_Format(PyExc_TypeError, + "__%.4s__ returned non-%.4s (type %.200s)", + type_name, type_name, Py_TYPE(result)->tp_name); + Py_DECREF(result); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { +#if CYTHON_USE_TYPE_SLOTS + PyNumberMethods *m; +#endif + const char *name = NULL; + PyObject *res = NULL; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x) || PyLong_Check(x))) +#else + if (likely(PyLong_Check(x))) +#endif + return __Pyx_NewRef(x); +#if CYTHON_USE_TYPE_SLOTS + m = Py_TYPE(x)->tp_as_number; + #if PY_MAJOR_VERSION < 3 + if (m && m->nb_int) { + name = "int"; + res = m->nb_int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = m->nb_long(x); + } + #else + if (likely(m && m->nb_int)) { + name = "int"; + res = m->nb_int(x); + } + #endif +#else + if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { + res = PyNumber_Int(x); + } +#endif + if (likely(res)) { +#if PY_MAJOR_VERSION < 3 + if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { +#else + if (unlikely(!PyLong_CheckExact(res))) { +#endif + return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) { + if (sizeof(Py_ssize_t) >= sizeof(long)) + return PyInt_AS_LONG(b); + else + return PyInt_AsSsize_t(x); + } +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)b)->ob_digit; + const Py_ssize_t size = Py_SIZE(b); + if (likely(__Pyx_sst_abs(size) <= 1)) { + ival = likely(size) ? digits[0] : 0; + if (size == -1) ival = -ival; + return ival; + } else { + switch (size) { + case 2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + } + } + #endif + return PyLong_AsSsize_t(b); + } + x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { + return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); +} +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { + return PyInt_FromSize_t(ival); +} + + +#endif /* Py_PYTHON_H */ diff --git a/pysam/libcsamtools.pxd b/pysam/libcsamtools.pxd new file mode 100644 index 000000000..ff797f879 --- /dev/null +++ b/pysam/libcsamtools.pxd @@ -0,0 +1,9 @@ +cdef extern from "samtools.pysam.h": + + int samtools_main(int argc, char *argv[]) + void samtools_set_stderr(int fd) + void samtools_unset_stderr() + void samtools_set_stdout(int fd) + void samtools_set_stdout_fn(const char *) + void samtools_unset_stdout() + void samtools_set_optind(int) diff --git a/pysam/libcsamtools.pyx b/pysam/libcsamtools.pyx new file mode 100644 index 000000000..cc60aceb5 --- /dev/null +++ b/pysam/libcsamtools.pyx @@ -0,0 +1,2 @@ +def py_samtools(): + pass diff --git a/pysam/libctabix.c b/pysam/libctabix.c index 363fedab2..6d3977924 100644 --- a/pysam/libctabix.c +++ b/pysam/libctabix.c @@ -569,6 +569,7 @@ static CYTHON_INLINE float __PYX_NAN() { #include "fcntl.h" #include "unistd.h" #include +#include "stdarg.h" #include "htslib/kstring.h" #include "htslib_util.h" #include "htslib/hfile.h" @@ -579,11 +580,11 @@ static CYTHON_INLINE float __PYX_NAN() { #include "htslib/tbx.h" #include "htslib/vcf.h" #include "htslib/vcfutils.h" +#include "htslib/cram.h" #include "pysam_stream.h" #include #include #include "pythread.h" -#include "pysam_util.h" #ifdef _OPENMP #include #endif /* _OPENMP */ @@ -816,8 +817,9 @@ typedef struct arrayobject arrayobject; #endif struct __pyx_obj_5pysam_10libchtslib_HTSFile; struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy; -struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy; struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy; +struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy; +struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy; struct __pyx_obj_5pysam_16libctabixproxies_BedProxy; struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy; struct __pyx_obj_5pysam_9libctabix_tabix_file_iterator; @@ -825,6 +827,7 @@ struct __pyx_obj_5pysam_9libctabix_TabixFile; struct __pyx_obj_5pysam_9libctabix_Parser; struct __pyx_obj_5pysam_9libctabix_asTuple; struct __pyx_obj_5pysam_9libctabix_asGTF; +struct __pyx_obj_5pysam_9libctabix_asGFF3; struct __pyx_obj_5pysam_9libctabix_asBed; struct __pyx_obj_5pysam_9libctabix_asVCF; struct __pyx_obj_5pysam_9libctabix_TabixIterator; @@ -967,7 +970,7 @@ struct __pyx_opt_args_5pysam_9libcutils_force_bytes { PyObject *encoding; }; -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -981,6 +984,7 @@ struct __pyx_obj_5pysam_10libchtslib_HTSFile { int64_t start_offset; PyObject *filename; PyObject *mode; + PyObject *threads; PyObject *index_filename; int is_stream; int is_remote; @@ -1009,35 +1013,46 @@ struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy { }; -/* "pysam/libctabixproxies.pxd":28 - * cdef update(self, char * buffer, size_t nbytes) +/* "pysam/libctabixproxies.pxd":29 * - * cdef class GTFProxy(TupleProxy) : # <<<<<<<<<<<<<< * - * cdef: + * cdef class NamedTupleProxy(TupleProxy): # <<<<<<<<<<<<<< + * pass + * */ -struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy { +struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy { struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy __pyx_base; - char *_attributes; - int hasOwnAttributes; }; -/* "pysam/libctabixproxies.pxd":38 - * cdef char * getAttributes(self) +/* "pysam/libctabixproxies.pxd":33 * - * cdef class NamedTupleProxy(TupleProxy): # <<<<<<<<<<<<<< - * pass * + * cdef class GTFProxy(NamedTupleProxy): # <<<<<<<<<<<<<< + * cdef object attribute_dict + * cpdef int getMaxFields(self) */ -struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy { - struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy __pyx_base; +struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy { + struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy __pyx_base; + PyObject *attribute_dict; }; -/* "pysam/libctabixproxies.pxd":41 +/* "pysam/libctabixproxies.pxd":39 + * + * + * cdef class GFF3Proxy(GTFProxy): # <<<<<<<<<<<<<< * pass * + */ +struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy { + struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy __pyx_base; +}; + + +/* "pysam/libctabixproxies.pxd":43 + * + * * cdef class BedProxy(NamedTupleProxy): # <<<<<<<<<<<<<< * * cdef: @@ -1051,7 +1066,7 @@ struct __pyx_obj_5pysam_16libctabixproxies_BedProxy { }; -/* "pysam/libctabixproxies.pxd":53 +/* "pysam/libctabixproxies.pxd":55 * cdef update(self, char * buffer, size_t nbytes) * * cdef class VCFProxy(NamedTupleProxy) : # <<<<<<<<<<<<<< @@ -1141,6 +1156,18 @@ struct __pyx_obj_5pysam_9libctabix_asGTF { /* "pysam/libctabix.pxd":84 + * + * + * cdef class asGFF3(Parser): # <<<<<<<<<<<<<< + * pass + * + */ +struct __pyx_obj_5pysam_9libctabix_asGFF3 { + struct __pyx_obj_5pysam_9libctabix_Parser __pyx_base; +}; + + +/* "pysam/libctabix.pxd":88 * * * cdef class asBed(Parser): # <<<<<<<<<<<<<< @@ -1152,7 +1179,7 @@ struct __pyx_obj_5pysam_9libctabix_asBed { }; -/* "pysam/libctabix.pxd":88 +/* "pysam/libctabix.pxd":92 * * * cdef class asVCF(Parser): # <<<<<<<<<<<<<< @@ -1164,7 +1191,7 @@ struct __pyx_obj_5pysam_9libctabix_asVCF { }; -/* "pysam/libctabix.pxd":92 +/* "pysam/libctabix.pxd":96 * * * cdef class TabixIterator: # <<<<<<<<<<<<<< @@ -1181,7 +1208,7 @@ struct __pyx_obj_5pysam_9libctabix_TabixIterator { }; -/* "pysam/libctabix.pxd":100 +/* "pysam/libctabix.pxd":104 * * * cdef class TabixIteratorParsed(TabixIterator): # <<<<<<<<<<<<<< @@ -1194,7 +1221,7 @@ struct __pyx_obj_5pysam_9libctabix_TabixIteratorParsed { }; -/* "pysam/libctabix.pxd":104 +/* "pysam/libctabix.pxd":108 * * * cdef class GZIterator: # <<<<<<<<<<<<<< @@ -1212,7 +1239,7 @@ struct __pyx_obj_5pysam_9libctabix_GZIterator { }; -/* "pysam/libctabix.pxd":113 +/* "pysam/libctabix.pxd":117 * * * cdef class GZIteratorHead(GZIterator): # <<<<<<<<<<<<<< @@ -1224,7 +1251,7 @@ struct __pyx_obj_5pysam_9libctabix_GZIteratorHead { }; -/* "pysam/libctabix.pxd":117 +/* "pysam/libctabix.pxd":121 * * * cdef class GZIteratorParsed(GZIterator): # <<<<<<<<<<<<<< @@ -1237,7 +1264,7 @@ struct __pyx_obj_5pysam_9libctabix_GZIteratorParsed { }; -/* "pysam/libctabix.pxd":122 +/* "pysam/libctabix.pxd":126 * * # Compatibility Layer for pysam < 0.8 * cdef class Tabixfile(TabixFile): # <<<<<<<<<<<<<< @@ -1249,7 +1276,7 @@ struct __pyx_obj_5pysam_9libctabix_Tabixfile { -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -1282,37 +1309,50 @@ struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy { static struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *__pyx_vtabptr_5pysam_16libctabixproxies_TupleProxy; -/* "pysam/libctabixproxies.pxd":28 - * cdef update(self, char * buffer, size_t nbytes) +/* "pysam/libctabixproxies.pxd":29 * - * cdef class GTFProxy(TupleProxy) : # <<<<<<<<<<<<<< * - * cdef: + * cdef class NamedTupleProxy(TupleProxy): # <<<<<<<<<<<<<< + * pass + * */ -struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy { +struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy { struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy __pyx_base; - char *(*getAttributes)(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *); +}; +static struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy; + + +/* "pysam/libctabixproxies.pxd":33 + * + * + * cdef class GTFProxy(NamedTupleProxy): # <<<<<<<<<<<<<< + * cdef object attribute_dict + * cpdef int getMaxFields(self) + */ + +struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy { + struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy __pyx_base; }; static struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy *__pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy; -/* "pysam/libctabixproxies.pxd":38 - * cdef char * getAttributes(self) +/* "pysam/libctabixproxies.pxd":39 * - * cdef class NamedTupleProxy(TupleProxy): # <<<<<<<<<<<<<< + * + * cdef class GFF3Proxy(GTFProxy): # <<<<<<<<<<<<<< * pass * */ -struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy { - struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy __pyx_base; +struct __pyx_vtabstruct_5pysam_16libctabixproxies_GFF3Proxy { + struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy __pyx_base; }; -static struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy; +static struct __pyx_vtabstruct_5pysam_16libctabixproxies_GFF3Proxy *__pyx_vtabptr_5pysam_16libctabixproxies_GFF3Proxy; -/* "pysam/libctabixproxies.pxd":41 - * pass +/* "pysam/libctabixproxies.pxd":43 + * * * cdef class BedProxy(NamedTupleProxy): # <<<<<<<<<<<<<< * @@ -1325,7 +1365,7 @@ struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy { static struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy *__pyx_vtabptr_5pysam_16libctabixproxies_BedProxy; -/* "pysam/libctabixproxies.pxd":53 +/* "pysam/libctabixproxies.pxd":55 * cdef update(self, char * buffer, size_t nbytes) * * cdef class VCFProxy(NamedTupleProxy) : # <<<<<<<<<<<<<< @@ -1339,7 +1379,7 @@ struct __pyx_vtabstruct_5pysam_16libctabixproxies_VCFProxy { static struct __pyx_vtabstruct_5pysam_16libctabixproxies_VCFProxy *__pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy; -/* "pysam/libctabix.pyx":995 +/* "pysam/libctabix.pyx":1115 * * * cdef class tabix_file_iterator: # <<<<<<<<<<<<<< @@ -1353,7 +1393,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_tabix_file_iterator { static struct __pyx_vtabstruct_5pysam_9libctabix_tabix_file_iterator *__pyx_vtabptr_5pysam_9libctabix_tabix_file_iterator; -/* "pysam/libctabix.pyx":249 +/* "pysam/libctabix.pyx":289 * * * cdef class TabixFile: # <<<<<<<<<<<<<< @@ -1367,7 +1407,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_TabixFile { static struct __pyx_vtabstruct_5pysam_9libctabix_TabixFile *__pyx_vtabptr_5pysam_9libctabix_TabixFile; -/* "pysam/libctabix.pyx":80 +/* "pysam/libctabix.pyx":84 * from pysam.libcutils cimport encode_filename, from_string_and_size * * cdef class Parser: # <<<<<<<<<<<<<< @@ -1381,7 +1421,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_Parser { static struct __pyx_vtabstruct_5pysam_9libctabix_Parser *__pyx_vtabptr_5pysam_9libctabix_Parser; -/* "pysam/libctabix.pyx":99 +/* "pysam/libctabix.pyx":103 * * * cdef class asTuple(Parser): # <<<<<<<<<<<<<< @@ -1395,7 +1435,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_asTuple { static struct __pyx_vtabstruct_5pysam_9libctabix_asTuple *__pyx_vtabptr_5pysam_9libctabix_asTuple; -/* "pysam/libctabix.pyx":113 +/* "pysam/libctabix.pyx":153 * * * cdef class asGTF(Parser): # <<<<<<<<<<<<<< @@ -1409,7 +1449,21 @@ struct __pyx_vtabstruct_5pysam_9libctabix_asGTF { static struct __pyx_vtabstruct_5pysam_9libctabix_asGTF *__pyx_vtabptr_5pysam_9libctabix_asGTF; -/* "pysam/libctabix.pyx":160 +/* "pysam/libctabix.pyx":117 + * + * + * cdef class asGFF3(Parser): # <<<<<<<<<<<<<< + * '''converts a :term:`tabix row` into a GFF record with the following + * fields: + */ + +struct __pyx_vtabstruct_5pysam_9libctabix_asGFF3 { + struct __pyx_vtabstruct_5pysam_9libctabix_Parser __pyx_base; +}; +static struct __pyx_vtabstruct_5pysam_9libctabix_asGFF3 *__pyx_vtabptr_5pysam_9libctabix_asGFF3; + + +/* "pysam/libctabix.pyx":200 * * * cdef class asBed(Parser): # <<<<<<<<<<<<<< @@ -1423,7 +1477,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_asBed { static struct __pyx_vtabstruct_5pysam_9libctabix_asBed *__pyx_vtabptr_5pysam_9libctabix_asBed; -/* "pysam/libctabix.pyx":208 +/* "pysam/libctabix.pyx":248 * * * cdef class asVCF(Parser): # <<<<<<<<<<<<<< @@ -1437,7 +1491,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_asVCF { static struct __pyx_vtabstruct_5pysam_9libctabix_asVCF *__pyx_vtabptr_5pysam_9libctabix_asVCF; -/* "pysam/libctabix.pyx":546 +/* "pysam/libctabix.pyx":621 * * * cdef class TabixIterator: # <<<<<<<<<<<<<< @@ -1451,7 +1505,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_TabixIterator { static struct __pyx_vtabstruct_5pysam_9libctabix_TabixIterator *__pyx_vtabptr_5pysam_9libctabix_TabixIterator; -/* "pysam/libctabix.pyx":625 +/* "pysam/libctabix.pyx":700 * * * cdef class TabixIteratorParsed(TabixIterator): # <<<<<<<<<<<<<< @@ -1465,7 +1519,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_TabixIteratorParsed { static struct __pyx_vtabstruct_5pysam_9libctabix_TabixIteratorParsed *__pyx_vtabptr_5pysam_9libctabix_TabixIteratorParsed; -/* "pysam/libctabix.pyx":655 +/* "pysam/libctabix.pyx":730 * * * cdef class GZIterator: # <<<<<<<<<<<<<< @@ -1479,7 +1533,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_GZIterator { static struct __pyx_vtabstruct_5pysam_9libctabix_GZIterator *__pyx_vtabptr_5pysam_9libctabix_GZIterator; -/* "pysam/libctabix.pyx":710 +/* "pysam/libctabix.pyx":785 * * * cdef class GZIteratorHead(GZIterator): # <<<<<<<<<<<<<< @@ -1493,7 +1547,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorHead { static struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorHead *__pyx_vtabptr_5pysam_9libctabix_GZIteratorHead; -/* "pysam/libctabix.pyx":727 +/* "pysam/libctabix.pyx":802 * * * cdef class GZIteratorParsed(GZIterator): # <<<<<<<<<<<<<< @@ -1507,7 +1561,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorParsed { static struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorParsed *__pyx_vtabptr_5pysam_9libctabix_GZIteratorParsed; -/* "pysam/libctabix.pyx":1169 +/* "pysam/libctabix.pyx":1290 * # return tabix_generic_iterator( infile, parser ) * * cdef class Tabixfile(TabixFile): # <<<<<<<<<<<<<< @@ -2039,14 +2093,6 @@ static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObje #define __Pyx_CallUnboundCMethod0(cfunc, self) __Pyx__CallUnboundCMethod0(cfunc, self) #endif -/* PyIntBinop.proto */ -#if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_OrObjC(PyObject *op1, PyObject *op2, long intval, int inplace); -#else -#define __Pyx_PyInt_OrObjC(op1, op2, intval, inplace)\ - (inplace ? PyNumber_InPlaceOr(op1, op2) : PyNumber_Or(op1, op2)) -#endif - /* UnicodeAsUCS4.proto */ static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject*); @@ -2248,6 +2294,9 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int8_t(int8_t value); + /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); @@ -2417,6 +2466,7 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); static PyObject *__pyx_f_5pysam_9libctabix_6Parser_parse(struct __pyx_obj_5pysam_9libctabix_Parser *__pyx_v_self, CYTHON_UNUSED char *__pyx_v_buffer, CYTHON_UNUSED int __pyx_v_length); /* proto*/ static PyObject *__pyx_f_5pysam_9libctabix_7asTuple_parse(struct __pyx_obj_5pysam_9libctabix_asTuple *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len); /* proto*/ +static PyObject *__pyx_f_5pysam_9libctabix_6asGFF3_parse(struct __pyx_obj_5pysam_9libctabix_asGFF3 *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len); /* proto*/ static PyObject *__pyx_f_5pysam_9libctabix_5asGTF_parse(struct __pyx_obj_5pysam_9libctabix_asGTF *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len); /* proto*/ static PyObject *__pyx_f_5pysam_9libctabix_5asBed_parse(struct __pyx_obj_5pysam_9libctabix_asBed *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len); /* proto*/ static PyObject *__pyx_f_5pysam_9libctabix_5asVCF_parse(struct __pyx_obj_5pysam_9libctabix_asVCF *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len); /* proto*/ @@ -2522,8 +2572,9 @@ static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0; /* Module declarations from 'pysam.libctabixproxies' */ static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_TupleProxy = 0; -static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_GTFProxy = 0; static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy = 0; +static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_GTFProxy = 0; +static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_GFF3Proxy = 0; static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_BedProxy = 0; static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_VCFProxy = 0; @@ -2548,6 +2599,7 @@ static PyTypeObject *__pyx_ptype_5pysam_9libctabix_TabixFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_Parser = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_asTuple = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_asGTF = 0; +static PyTypeObject *__pyx_ptype_5pysam_9libctabix_asGFF3 = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_asBed = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_asVCF = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_TabixIterator = 0; @@ -2558,6 +2610,7 @@ static PyTypeObject *__pyx_ptype_5pysam_9libctabix_GZIteratorParsed = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_Tabixfile = 0; static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_Parser__set_state(struct __pyx_obj_5pysam_9libctabix_Parser *, PyObject *); /*proto*/ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asTuple__set_state(struct __pyx_obj_5pysam_9libctabix_asTuple *, PyObject *); /*proto*/ +static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asGFF3__set_state(struct __pyx_obj_5pysam_9libctabix_asGFF3 *, PyObject *); /*proto*/ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asGTF__set_state(struct __pyx_obj_5pysam_9libctabix_asGTF *, PyObject *); /*proto*/ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asBed__set_state(struct __pyx_obj_5pysam_9libctabix_asBed *, PyObject *); /*proto*/ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asVCF__set_state(struct __pyx_obj_5pysam_9libctabix_asVCF *, PyObject *); /*proto*/ @@ -2569,10 +2622,9 @@ int __pyx_module_is_main_pysam__libctabix = 0; static PyObject *__pyx_builtin_NotImplementedError; static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_IOError; -static PyObject *__pyx_builtin_AttributeError; +static PyObject *__pyx_builtin_OSError; static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_StopIteration; -static PyObject *__pyx_builtin_OSError; static PyObject *__pyx_builtin_KeyError; static PyObject *__pyx_builtin_MemoryError; static const char __pyx_k_[] = "-"; @@ -2580,19 +2632,23 @@ static const char __pyx_k_b[] = "b"; static const char __pyx_k_c[] = "c"; static const char __pyx_k_r[] = "r"; static const char __pyx_k_s[] = "%s"; +static const char __pyx_k_fd[] = "fd"; static const char __pyx_k_fn[] = "fn"; static const char __pyx_k_fp[] = "fp"; static const char __pyx_k_gz[] = ".gz"; static const char __pyx_k_os[] = "os"; static const char __pyx_k__24[] = "#"; -static const char __pyx_k__35[] = ","; +static const char __pyx_k__27[] = ","; static const char __pyx_k_all[] = "__all__"; +static const char __pyx_k_bcf[] = "bcf"; static const char __pyx_k_bed[] = "bed"; static const char __pyx_k_cfn[] = "cfn"; static const char __pyx_k_cpy[] = "cpy"; +static const char __pyx_k_csi[] = "csi"; static const char __pyx_k_doc[] = "__doc__"; static const char __pyx_k_dup[] = "_dup"; static const char __pyx_k_end[] = "end"; +static const char __pyx_k_fmt[] = "fmt"; static const char __pyx_k_gff[] = "gff"; static const char __pyx_k_new[] = "__new__"; static const char __pyx_k_s_2[] = "s"; @@ -2601,6 +2657,7 @@ static const char __pyx_k_sam[] = "sam"; static const char __pyx_k_sys[] = "sys"; static const char __pyx_k_tbi[] = ".tbi"; static const char __pyx_k_vcf[] = "vcf"; +static const char __pyx_k_1f8b[] = "1f8b"; static const char __pyx_k_conf[] = "conf"; static const char __pyx_k_dict[] = "__dict__"; static const char __pyx_k_init[] = "__init__"; @@ -2614,6 +2671,7 @@ static const char __pyx_k_name[] = "__name__"; static const char __pyx_k_next[] = "__next__"; static const char __pyx_k_open[] = "_open"; static const char __pyx_k_path[] = "path"; +static const char __pyx_k_read[] = "read"; static const char __pyx_k_self[] = "self"; static const char __pyx_k_tell[] = "tell"; static const char __pyx_k_test[] = "__test__"; @@ -2622,42 +2680,52 @@ static const char __pyx_k_asGTF[] = "asGTF"; static const char __pyx_k_asVCF[] = "asVCF"; static const char __pyx_k_ascii[] = "ascii"; static const char __pyx_k_close[] = "close"; +static const char __pyx_k_csi_2[] = ".csi"; +static const char __pyx_k_fnidx[] = "fnidx"; static const char __pyx_k_force[] = "force"; static const char __pyx_k_index[] = "index"; static const char __pyx_k_s_i_i[] = "%s:%i-%i"; static const char __pyx_k_start[] = "start"; +static const char __pyx_k_asGFF3[] = "asGFF3"; static const char __pyx_k_buffer[] = "buffer"; static const char __pyx_k_closed[] = "closed"; static const char __pyx_k_exists[] = "exists"; static const char __pyx_k_fd_src[] = "fd_src"; +static const char __pyx_k_format[] = "format"; +static const char __pyx_k_header[] = "header"; static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_infile[] = "infile"; static const char __pyx_k_length[] = "length"; static const char __pyx_k_module[] = "__module__"; static const char __pyx_k_nbytes[] = "nbytes"; static const char __pyx_k_next_2[] = "next"; +static const char __pyx_k_open_2[] = "open"; static const char __pyx_k_parser[] = "parser"; static const char __pyx_k_pickle[] = "pickle"; -static const char __pyx_k_pileup[] = "pileup"; static const char __pyx_k_preset[] = "preset"; static const char __pyx_k_psltbl[] = "psltbl"; static const char __pyx_k_reduce[] = "__reduce__"; static const char __pyx_k_region[] = "region"; +static const char __pyx_k_retval[] = "retval"; +static const char __pyx_k_suffix[] = "suffix"; static const char __pyx_k_unlink[] = "unlink"; static const char __pyx_k_update[] = "update"; static const char __pyx_k_IOError[] = "IOError"; static const char __pyx_k_OSError[] = "OSError"; +static const char __pyx_k_a2b_hex[] = "a2b_hex"; static const char __pyx_k_asTuple[] = "asTuple"; static const char __pyx_k_contigs[] = "contigs"; static const char __pyx_k_end_col[] = "end_col"; static const char __pyx_k_is_open[] = "is_open"; static const char __pyx_k_prepare[] = "__prepare__"; static const char __pyx_k_seq_col[] = "seq_col"; +static const char __pyx_k_threads[] = "threads"; static const char __pyx_k_KeyError[] = "KeyError"; static const char __pyx_k_O_RDONLY[] = "O_RDONLY"; +static const char __pyx_k_binascii[] = "binascii"; static const char __pyx_k_encoding[] = "encoding"; -static const char __pyx_k_endswith[] = "endswith"; static const char __pyx_k_filename[] = "filename"; +static const char __pyx_k_fn_index[] = "fn_index"; static const char __pyx_k_getstate[] = "__getstate__"; static const char __pyx_k_is_empty[] = "is_empty"; static const char __pyx_k_pyx_type[] = "__pyx_type"; @@ -2669,6 +2737,7 @@ static const char __pyx_k_Tabixfile[] = "Tabixfile"; static const char __pyx_k_TypeError[] = "TypeError"; static const char __pyx_k_bytes_cpy[] = "bytes_cpy"; static const char __pyx_k_conf_data[] = "conf_data"; +static const char __pyx_k_line_skip[] = "line_skip"; static const char __pyx_k_meta_char[] = "meta_char"; static const char __pyx_k_metaclass[] = "__metaclass__"; static const char __pyx_k_min_shift[] = "min_shift"; @@ -2690,17 +2759,19 @@ static const char __pyx_k_preset2conf[] = "preset2conf"; static const char __pyx_k_tabix_index[] = "tabix_index"; static const char __pyx_k_filename_out[] = "filename_out"; static const char __pyx_k_get_encoding[] = "get_encoding"; +static const char __pyx_k_is_gzip_file[] = "is_gzip_file"; static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; static const char __pyx_k_set_encoding[] = "set_encoding"; static const char __pyx_k_stringsource[] = "stringsource"; static const char __pyx_k_EmptyIterator[] = "EmptyIterator"; static const char __pyx_k_StopIteration[] = "StopIteration"; +static const char __pyx_k_keep_original[] = "keep_original"; static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; static const char __pyx_k_start_i_end_i[] = "start (%i) >= end (%i)"; -static const char __pyx_k_AttributeError[] = "AttributeError"; static const char __pyx_k_GZIteratorHead[] = "GZIteratorHead"; static const char __pyx_k_No_such_file_s[] = "No such file '%s'"; static const char __pyx_k_empty_iterator[] = "empty iterator"; +static const char __pyx_k_gzip_magic_hex[] = "gzip_magic_hex"; static const char __pyx_k_tabix_compress[] = "tabix_compress"; static const char __pyx_k_tabix_iterator[] = "tabix_iterator"; static const char __pyx_k_writing_failed[] = "writing failed"; @@ -2719,6 +2790,7 @@ static const char __pyx_k_pyx_unpickle_asVCF[] = "__pyx_unpickle_asVCF"; static const char __pyx_k_NotImplementedError[] = "NotImplementedError"; static const char __pyx_k_pysam_libctabix_pyx[] = "pysam/libctabix.pyx"; static const char __pyx_k_pyx_unpickle_Parser[] = "__pyx_unpickle_Parser"; +static const char __pyx_k_pyx_unpickle_asGFF3[] = "__pyx_unpickle_asGFF3"; static const char __pyx_k_tabix_file_iterator[] = "tabix_file_iterator"; static const char __pyx_k_EmptyIterator___iter[] = "EmptyIterator.__iter__"; static const char __pyx_k_EmptyIterator___next[] = "EmptyIterator.__next__"; @@ -2734,6 +2806,7 @@ static const char __pyx_k_error_i_when_closing_file_s[] = "error %i when closing static const char __pyx_k_invalid_file_opening_mode_s[] = "invalid file opening mode `%s`"; static const char __pyx_k_tabix_generic_iterator_next[] = "tabix_generic_iterator.next"; static const char __pyx_k_I_O_operation_on_closed_file[] = "I/O operation on closed file"; +static const char __pyx_k_building_of_index_for_failed[] = "building of index for {} failed"; static const char __pyx_k_could_not_open_s_for_reading[] = "could not open '%s' for reading"; static const char __pyx_k_could_not_open_s_for_writing[] = "could not open '%s' for writing"; static const char __pyx_k_tabix_generic_iterator___init[] = "tabix_generic_iterator.__init__"; @@ -2741,13 +2814,14 @@ static const char __pyx_k_tabix_generic_iterator___iter[] = "tabix_generic_itera static const char __pyx_k_tabix_generic_iterator___next[] = "tabix_generic_iterator.__next__"; static const char __pyx_k_I_O_operation_on_closed_file_2[] = "I/O operation on closed file."; static const char __pyx_k_error_i_when_writing_to_file_s[] = "error %i when writing to file %s"; +static const char __pyx_k_could_not_load_tbi_csi_index_of[] = "could not load .tbi/.csi index of {}"; static const char __pyx_k_iterate_over_infile_Permits_the[] = "iterate over ``infile``.\n \n Permits the use of file-like objects for example from the gzip module.\n "; -static const char __pyx_k_the_header_is_not_available_for[] = "the header is not available for remote files"; static const char __pyx_k_Filename_s_already_exists_use_fo[] = "Filename '%s' already exists, use *force* to overwrite"; -static const char __pyx_k_Filename_s_tbi_already_exists_us[] = "Filename '%s.tbi' already exists, use *force* to overwrite"; static const char __pyx_k_Incompatible_checksums_s_vs_0x84[] = "Incompatible checksums (%s vs 0x84bea1f = (encoding))"; static const char __pyx_k_could_not_create_iterator_for_re[] = "could not create iterator for region '%s'"; static const char __pyx_k_could_not_create_iterator_possib[] = "could not create iterator, possible tabix version mismatch"; +static const char __pyx_k_could_not_open_for_reading_heade[] = "could not open {} for reading header"; +static const char __pyx_k_filename_s_already_exists_use_fo[] = "filename '%s' already exists, use *force* to overwrite"; static const char __pyx_k_neither_preset_nor_seq_col_start[] = "neither preset nor seq_col,start_col and end_col given"; static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__"; static const char __pyx_k_parse_method_of_s_not_implemente[] = "parse method of %s not implemented"; @@ -2755,13 +2829,12 @@ static const char __pyx_k_self_gzipfile_self_kstream_canno[] = "self.gzipfile,se static const char __pyx_k_self_iterator_cannot_be_converte[] = "self.iterator cannot be converted to a Python object for pickling"; static const char __pyx_k_unknown_preset_s_valid_presets_a[] = "unknown preset '%s', valid presets are '%s'"; static PyObject *__pyx_kp_b_; -static PyObject *__pyx_n_s_AttributeError; +static PyObject *__pyx_kp_b_1f8b; static PyObject *__pyx_n_s_EmptyIterator; static PyObject *__pyx_n_s_EmptyIterator___iter; static PyObject *__pyx_n_s_EmptyIterator___next; static PyObject *__pyx_n_s_EmptyIterator_next; static PyObject *__pyx_kp_s_Filename_s_already_exists_use_fo; -static PyObject *__pyx_kp_s_Filename_s_tbi_already_exists_us; static PyObject *__pyx_n_s_GZIterator; static PyObject *__pyx_n_s_GZIteratorHead; static PyObject *__pyx_n_s_IOError; @@ -2783,17 +2856,22 @@ static PyObject *__pyx_n_s_TypeError; static PyObject *__pyx_n_s_ValueError; static PyObject *__pyx_n_s_WINDOW_SIZE; static PyObject *__pyx_kp_s__24; -static PyObject *__pyx_kp_s__35; +static PyObject *__pyx_kp_s__27; +static PyObject *__pyx_n_s_a2b_hex; static PyObject *__pyx_n_s_all; static PyObject *__pyx_n_s_asBed; +static PyObject *__pyx_n_s_asGFF3; static PyObject *__pyx_n_s_asGTF; static PyObject *__pyx_n_s_asTuple; static PyObject *__pyx_n_s_asVCF; static PyObject *__pyx_n_s_ascii; static PyObject *__pyx_n_s_b; +static PyObject *__pyx_n_s_bcf; static PyObject *__pyx_n_s_bed; +static PyObject *__pyx_n_s_binascii; static PyObject *__pyx_n_s_buffer; static PyObject *__pyx_n_s_buffer_size; +static PyObject *__pyx_kp_s_building_of_index_for_failed; static PyObject *__pyx_n_s_bytes_cpy; static PyObject *__pyx_n_s_c; static PyObject *__pyx_n_s_cfn; @@ -2805,11 +2883,15 @@ static PyObject *__pyx_n_s_conf_data; static PyObject *__pyx_n_s_contigs; static PyObject *__pyx_kp_s_could_not_create_iterator_for_re; static PyObject *__pyx_kp_s_could_not_create_iterator_possib; +static PyObject *__pyx_kp_s_could_not_load_tbi_csi_index_of; static PyObject *__pyx_kp_s_could_not_open_file_s; +static PyObject *__pyx_kp_s_could_not_open_for_reading_heade; static PyObject *__pyx_kp_s_could_not_open_index_for_s; static PyObject *__pyx_kp_s_could_not_open_s_for_reading; static PyObject *__pyx_kp_s_could_not_open_s_for_writing; static PyObject *__pyx_n_s_cpy; +static PyObject *__pyx_n_s_csi; +static PyObject *__pyx_kp_s_csi_2; static PyObject *__pyx_n_s_dict; static PyObject *__pyx_n_s_doc; static PyObject *__pyx_n_s_dup; @@ -2818,22 +2900,29 @@ static PyObject *__pyx_n_s_encoding; static PyObject *__pyx_n_s_end; static PyObject *__pyx_n_s_end_col; static PyObject *__pyx_kp_s_end_out_of_range_i; -static PyObject *__pyx_n_s_endswith; static PyObject *__pyx_kp_s_error_i_when_closing_file_s; static PyObject *__pyx_kp_s_error_i_when_writing_to_file_s; static PyObject *__pyx_n_s_exists; +static PyObject *__pyx_n_s_fd; static PyObject *__pyx_n_s_fd_src; static PyObject *__pyx_kp_s_file_s_not_found; static PyObject *__pyx_n_s_filename; static PyObject *__pyx_n_s_filename_in; static PyObject *__pyx_n_s_filename_out; +static PyObject *__pyx_kp_s_filename_s_already_exists_use_fo; +static PyObject *__pyx_n_s_fmt; static PyObject *__pyx_n_s_fn; +static PyObject *__pyx_n_s_fn_index; +static PyObject *__pyx_n_s_fnidx; static PyObject *__pyx_n_s_force; +static PyObject *__pyx_n_s_format; static PyObject *__pyx_n_s_fp; static PyObject *__pyx_n_s_get_encoding; static PyObject *__pyx_n_s_getstate; static PyObject *__pyx_n_s_gff; static PyObject *__pyx_kp_s_gz; +static PyObject *__pyx_n_s_gzip_magic_hex; +static PyObject *__pyx_n_s_header; static PyObject *__pyx_n_s_import; static PyObject *__pyx_kp_s_incomplete_line_at_s; static PyObject *__pyx_n_s_index; @@ -2842,14 +2931,17 @@ static PyObject *__pyx_n_s_infile; static PyObject *__pyx_n_s_init; static PyObject *__pyx_kp_s_invalid_file_opening_mode_s; static PyObject *__pyx_n_s_is_empty; +static PyObject *__pyx_n_s_is_gzip_file; static PyObject *__pyx_n_s_is_open; static PyObject *__pyx_n_s_iter; static PyObject *__pyx_kp_s_iterate_over_infile_Permits_the; static PyObject *__pyx_kp_s_iteration_on_closed_file; static PyObject *__pyx_n_s_join; +static PyObject *__pyx_n_s_keep_original; static PyObject *__pyx_n_s_keys; static PyObject *__pyx_n_s_length; static PyObject *__pyx_n_s_line; +static PyObject *__pyx_n_s_line_skip; static PyObject *__pyx_n_s_main; static PyObject *__pyx_n_s_meta_char; static PyObject *__pyx_n_s_metaclass; @@ -2865,12 +2957,12 @@ static PyObject *__pyx_n_s_next; static PyObject *__pyx_n_s_next_2; static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; static PyObject *__pyx_n_s_open; +static PyObject *__pyx_n_s_open_2; static PyObject *__pyx_n_s_os; static PyObject *__pyx_kp_s_parse_method_of_s_not_implemente; static PyObject *__pyx_n_s_parser; static PyObject *__pyx_n_s_path; static PyObject *__pyx_n_s_pickle; -static PyObject *__pyx_n_s_pileup; static PyObject *__pyx_n_s_prepare; static PyObject *__pyx_n_s_preset; static PyObject *__pyx_n_s_preset2conf; @@ -2884,18 +2976,21 @@ static PyObject *__pyx_n_s_pyx_state; static PyObject *__pyx_n_s_pyx_type; static PyObject *__pyx_n_s_pyx_unpickle_Parser; static PyObject *__pyx_n_s_pyx_unpickle_asBed; +static PyObject *__pyx_n_s_pyx_unpickle_asGFF3; static PyObject *__pyx_n_s_pyx_unpickle_asGTF; static PyObject *__pyx_n_s_pyx_unpickle_asTuple; static PyObject *__pyx_n_s_pyx_unpickle_asVCF; static PyObject *__pyx_n_s_pyx_vtable; static PyObject *__pyx_n_s_qualname; static PyObject *__pyx_n_s_r; +static PyObject *__pyx_n_s_read; static PyObject *__pyx_n_s_readline; static PyObject *__pyx_n_s_reduce; static PyObject *__pyx_n_s_reduce_cython; static PyObject *__pyx_n_s_reduce_ex; static PyObject *__pyx_n_s_reference; static PyObject *__pyx_n_s_region; +static PyObject *__pyx_n_s_retval; static PyObject *__pyx_kp_s_s; static PyObject *__pyx_n_s_s_2; static PyObject *__pyx_kp_s_s_i; @@ -2913,6 +3008,7 @@ static PyObject *__pyx_n_s_start_col; static PyObject *__pyx_kp_s_start_i_end_i; static PyObject *__pyx_kp_s_start_out_of_range_i; static PyObject *__pyx_kp_s_stringsource; +static PyObject *__pyx_n_s_suffix; static PyObject *__pyx_n_s_sys; static PyObject *__pyx_n_s_tabix_compress; static PyObject *__pyx_n_s_tabix_file_iterator; @@ -2926,7 +3022,7 @@ static PyObject *__pyx_n_s_tabix_iterator; static PyObject *__pyx_kp_s_tbi; static PyObject *__pyx_n_s_tell; static PyObject *__pyx_n_s_test; -static PyObject *__pyx_kp_s_the_header_is_not_available_for; +static PyObject *__pyx_n_s_threads; static PyObject *__pyx_kp_s_unknown_preset_s_valid_presets_a; static PyObject *__pyx_n_s_unlink; static PyObject *__pyx_n_s_update; @@ -2941,14 +3037,16 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6Parser_8__reduce_cython__(struct __ static PyObject *__pyx_pf_5pysam_9libctabix_6Parser_10__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_Parser *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_7asTuple___reduce_cython__(struct __pyx_obj_5pysam_9libctabix_asTuple *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_7asTuple_2__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_asTuple *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_9libctabix_6asGFF3___reduce_cython__(struct __pyx_obj_5pysam_9libctabix_asGFF3 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_9libctabix_6asGFF3_2__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_asGFF3 *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF___reduce_cython__(struct __pyx_obj_5pysam_9libctabix_asGTF *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF_2__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_asGTF *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_5asBed___reduce_cython__(struct __pyx_obj_5pysam_9libctabix_asBed *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_5asBed_2__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_asBed *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF___reduce_cython__(struct __pyx_obj_5pysam_9libctabix_asVCF *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF_2__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_asVCF *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ -static int __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_parser, PyObject *__pyx_v_index, PyObject *__pyx_v_encoding, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */ -static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_index); /* proto */ +static int __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_parser, PyObject *__pyx_v_index, PyObject *__pyx_v_encoding, PyObject *__pyx_v_threads, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_index, PyObject *__pyx_v_threads); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_4_dup(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_6fetch(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_parser, PyObject *__pyx_v_multiple_iterators); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_6header___get__(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self); /* proto */ @@ -2986,7 +3084,8 @@ static PyObject *__pyx_pf_5pysam_9libctabix_16GZIteratorParsed_2__next__(struct static PyObject *__pyx_pf_5pysam_9libctabix_16GZIteratorParsed_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libctabix_GZIteratorParsed *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_16GZIteratorParsed_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libctabix_GZIteratorParsed *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename_in, PyObject *__pyx_v_filename_out, PyObject *__pyx_v_force); /* proto */ -static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_force, PyObject *__pyx_v_seq_col, PyObject *__pyx_v_start_col, PyObject *__pyx_v_end_col, PyObject *__pyx_v_preset, PyObject *__pyx_v_meta_char, PyObject *__pyx_v_zerobased, int __pyx_v_min_shift); /* proto */ +static PyObject *__pyx_pf_5pysam_9libctabix_2is_gzip_file(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_5pysam_9libctabix_4tabix_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_force, PyObject *__pyx_v_seq_col, PyObject *__pyx_v_start_col, PyObject *__pyx_v_end_col, PyObject *__pyx_v_preset, PyObject *__pyx_v_meta_char, int __pyx_v_line_skip, PyObject *__pyx_v_zerobased, int __pyx_v_min_shift, PyObject *__pyx_v_index, PyObject *__pyx_v_keep_original, PyObject *__pyx_v_csi); /* proto */ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __pyx_obj_5pysam_9libctabix_tabix_file_iterator *__pyx_v_self, PyObject *__pyx_v_infile, struct __pyx_obj_5pysam_9libctabix_Parser *__pyx_v_parser, int __pyx_v_buffer_size); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_19tabix_file_iterator_2__iter__(struct __pyx_obj_5pysam_9libctabix_tabix_file_iterator *__pyx_v_self); /* proto */ static void __pyx_pf_5pysam_9libctabix_19tabix_file_iterator_4__dealloc__(struct __pyx_obj_5pysam_9libctabix_tabix_file_iterator *__pyx_v_self); /* proto */ @@ -2998,14 +3097,15 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator___init__(CY static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_2__iter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_6next(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_9libctabix_4tabix_iterator(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_infile, PyObject *__pyx_v_parser); /* proto */ +static PyObject *__pyx_pf_5pysam_9libctabix_6tabix_iterator(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_infile, PyObject *__pyx_v_parser); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_9Tabixfile___reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libctabix_Tabixfile *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_9libctabix_9Tabixfile_2__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libctabix_Tabixfile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ -static PyObject *__pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ -static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ -static PyObject *__pyx_pf_5pysam_9libctabix_10__pyx_unpickle_asGTF(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ -static PyObject *__pyx_pf_5pysam_9libctabix_12__pyx_unpickle_asBed(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ -static PyObject *__pyx_pf_5pysam_9libctabix_14__pyx_unpickle_asVCF(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_Parser(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_9libctabix_10__pyx_unpickle_asTuple(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_9libctabix_12__pyx_unpickle_asGFF3(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_9libctabix_14__pyx_unpickle_asGTF(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_9libctabix_16__pyx_unpickle_asBed(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_9libctabix_18__pyx_unpickle_asVCF(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags); /* proto */ static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ static PyObject *__pyx_tp_new_5pysam_9libctabix_tabix_file_iterator(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ @@ -3013,6 +3113,7 @@ static PyObject *__pyx_tp_new_5pysam_9libctabix_TabixFile(PyTypeObject *t, PyObj static PyObject *__pyx_tp_new_5pysam_9libctabix_Parser(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_9libctabix_asTuple(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_9libctabix_asGTF(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_5pysam_9libctabix_asGFF3(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_9libctabix_asBed(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_9libctabix_asVCF(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_9libctabix_TabixIterator(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ @@ -3033,7 +3134,6 @@ static PyObject *__pyx_int_17; static PyObject *__pyx_int_18; static PyObject *__pyx_int_35; static PyObject *__pyx_int_64; -static PyObject *__pyx_int_65536; static PyObject *__pyx_int_139192863; static PyObject *__pyx_int_neg_1; static PyObject *__pyx_tuple__2; @@ -3043,7 +3143,7 @@ static PyObject *__pyx_tuple__5; static PyObject *__pyx_tuple__6; static PyObject *__pyx_tuple__7; static PyObject *__pyx_tuple__8; -static PyObject *__pyx_tuple__9; +static PyObject *__pyx_tuple__12; static PyObject *__pyx_tuple__13; static PyObject *__pyx_tuple__14; static PyObject *__pyx_tuple__15; @@ -3052,25 +3152,23 @@ static PyObject *__pyx_tuple__17; static PyObject *__pyx_tuple__18; static PyObject *__pyx_tuple__19; static PyObject *__pyx_tuple__20; -static PyObject *__pyx_tuple__21; -static PyObject *__pyx_tuple__23; +static PyObject *__pyx_tuple__22; static PyObject *__pyx_tuple__26; -static PyObject *__pyx_tuple__27; static PyObject *__pyx_tuple__28; static PyObject *__pyx_tuple__29; static PyObject *__pyx_tuple__30; static PyObject *__pyx_tuple__31; -static PyObject *__pyx_tuple__32; static PyObject *__pyx_tuple__33; -static PyObject *__pyx_tuple__34; static PyObject *__pyx_tuple__36; -static PyObject *__pyx_tuple__37; -static PyObject *__pyx_tuple__38; static PyObject *__pyx_tuple__39; -static PyObject *__pyx_tuple__41; -static PyObject *__pyx_tuple__44; +static PyObject *__pyx_tuple__40; static PyObject *__pyx_tuple__47; static PyObject *__pyx_tuple__48; +static PyObject *__pyx_tuple__49; +static PyObject *__pyx_tuple__50; +static PyObject *__pyx_tuple__51; +static PyObject *__pyx_tuple__52; +static PyObject *__pyx_tuple__53; static PyObject *__pyx_tuple__54; static PyObject *__pyx_tuple__55; static PyObject *__pyx_tuple__56; @@ -3081,29 +3179,26 @@ static PyObject *__pyx_tuple__60; static PyObject *__pyx_tuple__61; static PyObject *__pyx_tuple__62; static PyObject *__pyx_tuple__63; -static PyObject *__pyx_tuple__64; -static PyObject *__pyx_tuple__65; -static PyObject *__pyx_tuple__66; -static PyObject *__pyx_tuple__67; -static PyObject *__pyx_tuple__68; +static PyObject *__pyx_codeobj__9; static PyObject *__pyx_codeobj__10; static PyObject *__pyx_codeobj__11; -static PyObject *__pyx_codeobj__12; -static PyObject *__pyx_codeobj__22; +static PyObject *__pyx_codeobj__21; +static PyObject *__pyx_codeobj__23; static PyObject *__pyx_codeobj__25; -static PyObject *__pyx_codeobj__40; +static PyObject *__pyx_codeobj__32; +static PyObject *__pyx_codeobj__34; +static PyObject *__pyx_codeobj__35; +static PyObject *__pyx_codeobj__37; +static PyObject *__pyx_codeobj__38; +static PyObject *__pyx_codeobj__41; static PyObject *__pyx_codeobj__42; static PyObject *__pyx_codeobj__43; +static PyObject *__pyx_codeobj__44; static PyObject *__pyx_codeobj__45; static PyObject *__pyx_codeobj__46; -static PyObject *__pyx_codeobj__49; -static PyObject *__pyx_codeobj__50; -static PyObject *__pyx_codeobj__51; -static PyObject *__pyx_codeobj__52; -static PyObject *__pyx_codeobj__53; /* Late includes */ -/* "pysam/libctabix.pyx":82 +/* "pysam/libctabix.pyx":86 * cdef class Parser: * * def __init__(self, encoding="ascii"): # <<<<<<<<<<<<<< @@ -3140,7 +3235,7 @@ static int __pyx_pw_5pysam_9libctabix_6Parser_1__init__(PyObject *__pyx_v_self, } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 82, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 86, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -3154,7 +3249,7 @@ static int __pyx_pw_5pysam_9libctabix_6Parser_1__init__(PyObject *__pyx_v_self, } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 82, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 86, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabix.Parser.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -3172,9 +3267,9 @@ static int __pyx_pf_5pysam_9libctabix_6Parser___init__(struct __pyx_obj_5pysam_9 __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 82, 0, __PYX_ERR(0, 82, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 86, 0, __PYX_ERR(0, 86, __pyx_L1_error)); - /* "pysam/libctabix.pyx":83 + /* "pysam/libctabix.pyx":87 * * def __init__(self, encoding="ascii"): * self.encoding = encoding # <<<<<<<<<<<<<< @@ -3187,7 +3282,7 @@ static int __pyx_pf_5pysam_9libctabix_6Parser___init__(struct __pyx_obj_5pysam_9 __Pyx_DECREF(__pyx_v_self->encoding); __pyx_v_self->encoding = __pyx_v_encoding; - /* "pysam/libctabix.pyx":82 + /* "pysam/libctabix.pyx":86 * cdef class Parser: * * def __init__(self, encoding="ascii"): # <<<<<<<<<<<<<< @@ -3207,7 +3302,7 @@ static int __pyx_pf_5pysam_9libctabix_6Parser___init__(struct __pyx_obj_5pysam_9 return __pyx_r; } -/* "pysam/libctabix.pyx":85 +/* "pysam/libctabix.pyx":89 * self.encoding = encoding * * def set_encoding(self, encoding): # <<<<<<<<<<<<<< @@ -3234,9 +3329,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6Parser_2set_encoding(struct __pyx_o __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("set_encoding", 0); - __Pyx_TraceCall("set_encoding", __pyx_f[0], 85, 0, __PYX_ERR(0, 85, __pyx_L1_error)); + __Pyx_TraceCall("set_encoding", __pyx_f[0], 89, 0, __PYX_ERR(0, 89, __pyx_L1_error)); - /* "pysam/libctabix.pyx":86 + /* "pysam/libctabix.pyx":90 * * def set_encoding(self, encoding): * self.encoding = encoding # <<<<<<<<<<<<<< @@ -3249,7 +3344,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6Parser_2set_encoding(struct __pyx_o __Pyx_DECREF(__pyx_v_self->encoding); __pyx_v_self->encoding = __pyx_v_encoding; - /* "pysam/libctabix.pyx":85 + /* "pysam/libctabix.pyx":89 * self.encoding = encoding * * def set_encoding(self, encoding): # <<<<<<<<<<<<<< @@ -3270,7 +3365,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6Parser_2set_encoding(struct __pyx_o return __pyx_r; } -/* "pysam/libctabix.pyx":88 +/* "pysam/libctabix.pyx":92 * self.encoding = encoding * * def get_encoding(self): # <<<<<<<<<<<<<< @@ -3297,9 +3392,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6Parser_4get_encoding(struct __pyx_o __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_encoding", 0); - __Pyx_TraceCall("get_encoding", __pyx_f[0], 88, 0, __PYX_ERR(0, 88, __pyx_L1_error)); + __Pyx_TraceCall("get_encoding", __pyx_f[0], 92, 0, __PYX_ERR(0, 92, __pyx_L1_error)); - /* "pysam/libctabix.pyx":89 + /* "pysam/libctabix.pyx":93 * * def get_encoding(self): * return self.encoding # <<<<<<<<<<<<<< @@ -3311,7 +3406,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6Parser_4get_encoding(struct __pyx_o __pyx_r = __pyx_v_self->encoding; goto __pyx_L0; - /* "pysam/libctabix.pyx":88 + /* "pysam/libctabix.pyx":92 * self.encoding = encoding * * def get_encoding(self): # <<<<<<<<<<<<<< @@ -3330,7 +3425,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6Parser_4get_encoding(struct __pyx_o return __pyx_r; } -/* "pysam/libctabix.pyx":91 +/* "pysam/libctabix.pyx":95 * return self.encoding * * cdef parse(self, char * buffer, int length): # <<<<<<<<<<<<<< @@ -3345,36 +3440,36 @@ static PyObject *__pyx_f_5pysam_9libctabix_6Parser_parse(struct __pyx_obj_5pysam PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("parse", 0); - __Pyx_TraceCall("parse", __pyx_f[0], 91, 0, __PYX_ERR(0, 91, __pyx_L1_error)); + __Pyx_TraceCall("parse", __pyx_f[0], 95, 0, __PYX_ERR(0, 95, __pyx_L1_error)); - /* "pysam/libctabix.pyx":93 + /* "pysam/libctabix.pyx":97 * cdef parse(self, char * buffer, int length): * raise NotImplementedError( * 'parse method of %s not implemented' % str(self)) # <<<<<<<<<<<<<< * * def __call__(self, char * buffer, int length): */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_parse_method_of_s_not_implemente, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_parse_method_of_s_not_implemente, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 97, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":92 + /* "pysam/libctabix.pyx":96 * * cdef parse(self, char * buffer, int length): * raise NotImplementedError( # <<<<<<<<<<<<<< * 'parse method of %s not implemented' % str(self)) * */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_NotImplementedError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_NotImplementedError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 92, __pyx_L1_error) + __PYX_ERR(0, 96, __pyx_L1_error) - /* "pysam/libctabix.pyx":91 + /* "pysam/libctabix.pyx":95 * return self.encoding * * cdef parse(self, char * buffer, int length): # <<<<<<<<<<<<<< @@ -3394,7 +3489,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_6Parser_parse(struct __pyx_obj_5pysam return __pyx_r; } -/* "pysam/libctabix.pyx":95 +/* "pysam/libctabix.pyx":99 * 'parse method of %s not implemented' % str(self)) * * def __call__(self, char * buffer, int length): # <<<<<<<<<<<<<< @@ -3433,11 +3528,11 @@ static PyObject *__pyx_pw_5pysam_9libctabix_6Parser_7__call__(PyObject *__pyx_v_ case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_length)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, 1); __PYX_ERR(0, 95, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, 1); __PYX_ERR(0, 99, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) __PYX_ERR(0, 95, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) __PYX_ERR(0, 99, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -3445,12 +3540,12 @@ static PyObject *__pyx_pw_5pysam_9libctabix_6Parser_7__call__(PyObject *__pyx_v_ values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } - __pyx_v_buffer = __Pyx_PyObject_AsWritableString(values[0]); if (unlikely((!__pyx_v_buffer) && PyErr_Occurred())) __PYX_ERR(0, 95, __pyx_L3_error) - __pyx_v_length = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_length == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 95, __pyx_L3_error) + __pyx_v_buffer = __Pyx_PyObject_AsWritableString(values[0]); if (unlikely((!__pyx_v_buffer) && PyErr_Occurred())) __PYX_ERR(0, 99, __pyx_L3_error) + __pyx_v_length = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_length == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 99, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 95, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__call__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 99, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabix.Parser.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -3469,9 +3564,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6Parser_6__call__(struct __pyx_obj_5 __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__call__", 0); - __Pyx_TraceCall("__call__", __pyx_f[0], 95, 0, __PYX_ERR(0, 95, __pyx_L1_error)); + __Pyx_TraceCall("__call__", __pyx_f[0], 99, 0, __PYX_ERR(0, 99, __pyx_L1_error)); - /* "pysam/libctabix.pyx":96 + /* "pysam/libctabix.pyx":100 * * def __call__(self, char * buffer, int length): * return self.parse(buffer, length) # <<<<<<<<<<<<<< @@ -3479,13 +3574,13 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6Parser_6__call__(struct __pyx_obj_5 * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9libctabix_Parser *)__pyx_v_self->__pyx_vtab)->parse(__pyx_v_self, __pyx_v_buffer, __pyx_v_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9libctabix_Parser *)__pyx_v_self->__pyx_vtab)->parse(__pyx_v_self, __pyx_v_buffer, __pyx_v_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 100, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libctabix.pyx":95 + /* "pysam/libctabix.pyx":99 * 'parse method of %s not implemented' % str(self)) * * def __call__(self, char * buffer, int length): # <<<<<<<<<<<<<< @@ -3800,7 +3895,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6Parser_10__setstate_cython__(struct return __pyx_r; } -/* "pysam/libctabix.pyx":104 +/* "pysam/libctabix.pyx":108 * A field in a row is accessed by numeric index. * ''' * cdef parse(self, char * buffer, int len): # <<<<<<<<<<<<<< @@ -3815,32 +3910,32 @@ static PyObject *__pyx_f_5pysam_9libctabix_7asTuple_parse(struct __pyx_obj_5pysa __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("parse", 0); - __Pyx_TraceCall("parse", __pyx_f[0], 104, 0, __PYX_ERR(0, 104, __pyx_L1_error)); + __Pyx_TraceCall("parse", __pyx_f[0], 108, 0, __PYX_ERR(0, 108, __pyx_L1_error)); - /* "pysam/libctabix.pyx":106 + /* "pysam/libctabix.pyx":110 * cdef parse(self, char * buffer, int len): * cdef ctabixproxies.TupleProxy r * r = ctabixproxies.TupleProxy(self.encoding) # <<<<<<<<<<<<<< * # need to copy - there were some * # persistence issues with "present" */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_v_self->__pyx_base.encoding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_v_self->__pyx_base.encoding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_r = ((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":109 + /* "pysam/libctabix.pyx":113 * # need to copy - there were some * # persistence issues with "present" * r.copy(buffer, len) # <<<<<<<<<<<<<< * return r * */ - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_r->__pyx_vtab)->copy(__pyx_v_r, __pyx_v_buffer, __pyx_v_len, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 109, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_r->__pyx_vtab)->copy(__pyx_v_r, __pyx_v_buffer, __pyx_v_len, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 113, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":110 + /* "pysam/libctabix.pyx":114 * # persistence issues with "present" * r.copy(buffer, len) * return r # <<<<<<<<<<<<<< @@ -3852,7 +3947,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_7asTuple_parse(struct __pyx_obj_5pysa __pyx_r = ((PyObject *)__pyx_v_r); goto __pyx_L0; - /* "pysam/libctabix.pyx":104 + /* "pysam/libctabix.pyx":108 * A field in a row is accessed by numeric index. * ''' * cdef parse(self, char * buffer, int len): # <<<<<<<<<<<<<< @@ -4168,48 +4263,48 @@ static PyObject *__pyx_pf_5pysam_9libctabix_7asTuple_2__setstate_cython__(struct return __pyx_r; } -/* "pysam/libctabix.pyx":153 +/* "pysam/libctabix.pyx":146 * * ''' * cdef parse(self, char * buffer, int len): # <<<<<<<<<<<<<< - * cdef ctabixproxies.GTFProxy r - * r = ctabixproxies.GTFProxy(self.encoding) + * cdef ctabixproxies.GFF3Proxy r + * r = ctabixproxies.GFF3Proxy(self.encoding) */ -static PyObject *__pyx_f_5pysam_9libctabix_5asGTF_parse(struct __pyx_obj_5pysam_9libctabix_asGTF *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) { - struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_r = 0; +static PyObject *__pyx_f_5pysam_9libctabix_6asGFF3_parse(struct __pyx_obj_5pysam_9libctabix_asGFF3 *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) { + struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *__pyx_v_r = 0; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("parse", 0); - __Pyx_TraceCall("parse", __pyx_f[0], 153, 0, __PYX_ERR(0, 153, __pyx_L1_error)); + __Pyx_TraceCall("parse", __pyx_f[0], 146, 0, __PYX_ERR(0, 146, __pyx_L1_error)); - /* "pysam/libctabix.pyx":155 + /* "pysam/libctabix.pyx":148 * cdef parse(self, char * buffer, int len): - * cdef ctabixproxies.GTFProxy r - * r = ctabixproxies.GTFProxy(self.encoding) # <<<<<<<<<<<<<< + * cdef ctabixproxies.GFF3Proxy r + * r = ctabixproxies.GFF3Proxy(self.encoding) # <<<<<<<<<<<<<< * r.copy(buffer, len) * return r */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_GTFProxy), __pyx_v_self->__pyx_base.encoding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_GFF3Proxy), __pyx_v_self->__pyx_base.encoding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_v_r = ((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_t_1); + __pyx_v_r = ((struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":156 - * cdef ctabixproxies.GTFProxy r - * r = ctabixproxies.GTFProxy(self.encoding) + /* "pysam/libctabix.pyx":149 + * cdef ctabixproxies.GFF3Proxy r + * r = ctabixproxies.GFF3Proxy(self.encoding) * r.copy(buffer, len) # <<<<<<<<<<<<<< * return r * */ - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_r->__pyx_base.__pyx_vtab)->__pyx_base.copy(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_GFF3Proxy *)__pyx_v_r->__pyx_base.__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.__pyx_base.__pyx_base.copy(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":157 - * r = ctabixproxies.GTFProxy(self.encoding) + /* "pysam/libctabix.pyx":150 + * r = ctabixproxies.GFF3Proxy(self.encoding) * r.copy(buffer, len) * return r # <<<<<<<<<<<<<< * @@ -4220,18 +4315,18 @@ static PyObject *__pyx_f_5pysam_9libctabix_5asGTF_parse(struct __pyx_obj_5pysam_ __pyx_r = ((PyObject *)__pyx_v_r); goto __pyx_L0; - /* "pysam/libctabix.pyx":153 + /* "pysam/libctabix.pyx":146 * * ''' * cdef parse(self, char * buffer, int len): # <<<<<<<<<<<<<< - * cdef ctabixproxies.GTFProxy r - * r = ctabixproxies.GTFProxy(self.encoding) + * cdef ctabixproxies.GFF3Proxy r + * r = ctabixproxies.GFF3Proxy(self.encoding) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabix.asGTF.parse", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.asGFF3.parse", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_r); @@ -4248,20 +4343,20 @@ static PyObject *__pyx_f_5pysam_9libctabix_5asGTF_parse(struct __pyx_obj_5pysam_ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_5asGTF_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_5asGTF___reduce_cython__[] = "asGTF.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_9libctabix_5asGTF_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_9libctabix_6asGFF3_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_6asGFF3___reduce_cython__[] = "asGFF3.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_9libctabix_6asGFF3_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libctabix_5asGTF___reduce_cython__(((struct __pyx_obj_5pysam_9libctabix_asGTF *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_9libctabix_6asGFF3___reduce_cython__(((struct __pyx_obj_5pysam_9libctabix_asGFF3 *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF___reduce_cython__(struct __pyx_obj_5pysam_9libctabix_asGTF *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_9libctabix_6asGFF3___reduce_cython__(struct __pyx_obj_5pysam_9libctabix_asGFF3 *__pyx_v_self) { int __pyx_v_use_setstate; PyObject *__pyx_v_state = NULL; PyObject *__pyx_v__dict = NULL; @@ -4356,7 +4451,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF___reduce_cython__(struct __py * else: * use_setstate = self.encoding is not None # <<<<<<<<<<<<<< * if use_setstate: - * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, None), state + * return __pyx_unpickle_asGFF3, (type(self), 0x84bea1f, None), state */ /*else*/ { __pyx_t_3 = (__pyx_v_self->__pyx_base.encoding != Py_None); @@ -4368,7 +4463,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF___reduce_cython__(struct __py * else: * use_setstate = self.encoding is not None * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, None), state + * return __pyx_unpickle_asGFF3, (type(self), 0x84bea1f, None), state * else: */ __pyx_t_3 = (__pyx_v_use_setstate != 0); @@ -4377,12 +4472,12 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF___reduce_cython__(struct __py /* "(tree fragment)":11 * use_setstate = self.encoding is not None * if use_setstate: - * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, None), state # <<<<<<<<<<<<<< + * return __pyx_unpickle_asGFF3, (type(self), 0x84bea1f, None), state # <<<<<<<<<<<<<< * else: - * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, state) + * return __pyx_unpickle_asGFF3, (type(self), 0x84bea1f, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asGTF); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asGFF3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); @@ -4414,21 +4509,21 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF___reduce_cython__(struct __py * else: * use_setstate = self.encoding is not None * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, None), state + * return __pyx_unpickle_asGFF3, (type(self), 0x84bea1f, None), state * else: */ } /* "(tree fragment)":13 - * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, None), state + * return __pyx_unpickle_asGFF3, (type(self), 0x84bea1f, None), state * else: - * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, state) # <<<<<<<<<<<<<< + * return __pyx_unpickle_asGFF3, (type(self), 0x84bea1f, state) # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_asGTF__set_state(self, __pyx_state) + * __pyx_unpickle_asGFF3__set_state(self, __pyx_state) */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asGTF); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asGFF3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); @@ -4465,7 +4560,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF___reduce_cython__(struct __py __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libctabix.asGTF.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.asGFF3.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_state); @@ -4478,26 +4573,26 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF___reduce_cython__(struct __py /* "(tree fragment)":14 * else: - * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, state) + * return __pyx_unpickle_asGFF3, (type(self), 0x84bea1f, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_asGTF__set_state(self, __pyx_state) + * __pyx_unpickle_asGFF3__set_state(self, __pyx_state) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_5asGTF_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_5asGTF_2__setstate_cython__[] = "asGTF.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_9libctabix_5asGTF_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_9libctabix_6asGFF3_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_6asGFF3_2__setstate_cython__[] = "asGFF3.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_9libctabix_6asGFF3_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libctabix_5asGTF_2__setstate_cython__(((struct __pyx_obj_5pysam_9libctabix_asGTF *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_9libctabix_6asGFF3_2__setstate_cython__(((struct __pyx_obj_5pysam_9libctabix_asGFF3 *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF_2__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_asGTF *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_9libctabix_6asGFF3_2__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_asGFF3 *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -4506,20 +4601,20 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF_2__setstate_cython__(struct _ __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); /* "(tree fragment)":15 - * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, state) + * return __pyx_unpickle_asGFF3, (type(self), 0x84bea1f, state) * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_asGTF__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + * __pyx_unpickle_asGFF3__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_9libctabix___pyx_unpickle_asGTF__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libctabix___pyx_unpickle_asGFF3__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":14 * else: - * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, state) + * return __pyx_unpickle_asGFF3, (type(self), 0x84bea1f, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_asGTF__set_state(self, __pyx_state) + * __pyx_unpickle_asGFF3__set_state(self, __pyx_state) */ /* function exit code */ @@ -4527,7 +4622,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF_2__setstate_cython__(struct _ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabix.asGTF.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.asGFF3.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -4536,48 +4631,48 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF_2__setstate_cython__(struct _ return __pyx_r; } -/* "pysam/libctabix.pyx":201 +/* "pysam/libctabix.pyx":193 * * ''' * cdef parse(self, char * buffer, int len): # <<<<<<<<<<<<<< - * cdef ctabixproxies.BedProxy r - * r = ctabixproxies.BedProxy(self.encoding) + * cdef ctabixproxies.GTFProxy r + * r = ctabixproxies.GTFProxy(self.encoding) */ -static PyObject *__pyx_f_5pysam_9libctabix_5asBed_parse(struct __pyx_obj_5pysam_9libctabix_asBed *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) { - struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_r = 0; +static PyObject *__pyx_f_5pysam_9libctabix_5asGTF_parse(struct __pyx_obj_5pysam_9libctabix_asGTF *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) { + struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_r = 0; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("parse", 0); - __Pyx_TraceCall("parse", __pyx_f[0], 201, 0, __PYX_ERR(0, 201, __pyx_L1_error)); + __Pyx_TraceCall("parse", __pyx_f[0], 193, 0, __PYX_ERR(0, 193, __pyx_L1_error)); - /* "pysam/libctabix.pyx":203 + /* "pysam/libctabix.pyx":195 * cdef parse(self, char * buffer, int len): - * cdef ctabixproxies.BedProxy r - * r = ctabixproxies.BedProxy(self.encoding) # <<<<<<<<<<<<<< + * cdef ctabixproxies.GTFProxy r + * r = ctabixproxies.GTFProxy(self.encoding) # <<<<<<<<<<<<<< * r.copy(buffer, len) * return r */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_BedProxy), __pyx_v_self->__pyx_base.encoding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 203, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_GTFProxy), __pyx_v_self->__pyx_base.encoding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 195, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_v_r = ((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_t_1); + __pyx_v_r = ((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":204 - * cdef ctabixproxies.BedProxy r - * r = ctabixproxies.BedProxy(self.encoding) + /* "pysam/libctabix.pyx":196 + * cdef ctabixproxies.GTFProxy r + * r = ctabixproxies.GTFProxy(self.encoding) * r.copy(buffer, len) # <<<<<<<<<<<<<< * return r * */ - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy *)__pyx_v_r->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.__pyx_base.copy(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 204, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_r->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.__pyx_base.copy(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 196, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":205 - * r = ctabixproxies.BedProxy(self.encoding) + /* "pysam/libctabix.pyx":197 + * r = ctabixproxies.GTFProxy(self.encoding) * r.copy(buffer, len) * return r # <<<<<<<<<<<<<< * @@ -4588,18 +4683,18 @@ static PyObject *__pyx_f_5pysam_9libctabix_5asBed_parse(struct __pyx_obj_5pysam_ __pyx_r = ((PyObject *)__pyx_v_r); goto __pyx_L0; - /* "pysam/libctabix.pyx":201 + /* "pysam/libctabix.pyx":193 * * ''' * cdef parse(self, char * buffer, int len): # <<<<<<<<<<<<<< - * cdef ctabixproxies.BedProxy r - * r = ctabixproxies.BedProxy(self.encoding) + * cdef ctabixproxies.GTFProxy r + * r = ctabixproxies.GTFProxy(self.encoding) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabix.asBed.parse", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.asGTF.parse", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_r); @@ -4616,20 +4711,20 @@ static PyObject *__pyx_f_5pysam_9libctabix_5asBed_parse(struct __pyx_obj_5pysam_ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_5asBed_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_5asBed___reduce_cython__[] = "asBed.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_9libctabix_5asBed_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_9libctabix_5asGTF_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_5asGTF___reduce_cython__[] = "asGTF.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_9libctabix_5asGTF_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libctabix_5asBed___reduce_cython__(((struct __pyx_obj_5pysam_9libctabix_asBed *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_9libctabix_5asGTF___reduce_cython__(((struct __pyx_obj_5pysam_9libctabix_asGTF *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_5asBed___reduce_cython__(struct __pyx_obj_5pysam_9libctabix_asBed *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF___reduce_cython__(struct __pyx_obj_5pysam_9libctabix_asGTF *__pyx_v_self) { int __pyx_v_use_setstate; PyObject *__pyx_v_state = NULL; PyObject *__pyx_v__dict = NULL; @@ -4724,7 +4819,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asBed___reduce_cython__(struct __py * else: * use_setstate = self.encoding is not None # <<<<<<<<<<<<<< * if use_setstate: - * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, None), state + * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, None), state */ /*else*/ { __pyx_t_3 = (__pyx_v_self->__pyx_base.encoding != Py_None); @@ -4736,7 +4831,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asBed___reduce_cython__(struct __py * else: * use_setstate = self.encoding is not None * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, None), state + * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, None), state * else: */ __pyx_t_3 = (__pyx_v_use_setstate != 0); @@ -4745,12 +4840,12 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asBed___reduce_cython__(struct __py /* "(tree fragment)":11 * use_setstate = self.encoding is not None * if use_setstate: - * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, None), state # <<<<<<<<<<<<<< + * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, None), state # <<<<<<<<<<<<<< * else: - * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, state) + * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asBed); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asGTF); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); @@ -4782,21 +4877,21 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asBed___reduce_cython__(struct __py * else: * use_setstate = self.encoding is not None * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, None), state + * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, None), state * else: */ } /* "(tree fragment)":13 - * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, None), state + * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, None), state * else: - * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, state) # <<<<<<<<<<<<<< + * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, state) # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_asBed__set_state(self, __pyx_state) + * __pyx_unpickle_asGTF__set_state(self, __pyx_state) */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asBed); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asGTF); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); @@ -4833,7 +4928,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asBed___reduce_cython__(struct __py __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libctabix.asBed.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.asGTF.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_state); @@ -4846,26 +4941,26 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asBed___reduce_cython__(struct __py /* "(tree fragment)":14 * else: - * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, state) + * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_asBed__set_state(self, __pyx_state) + * __pyx_unpickle_asGTF__set_state(self, __pyx_state) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_5asBed_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_5asBed_2__setstate_cython__[] = "asBed.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_9libctabix_5asBed_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_9libctabix_5asGTF_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_5asGTF_2__setstate_cython__[] = "asGTF.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_9libctabix_5asGTF_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libctabix_5asBed_2__setstate_cython__(((struct __pyx_obj_5pysam_9libctabix_asBed *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_9libctabix_5asGTF_2__setstate_cython__(((struct __pyx_obj_5pysam_9libctabix_asGTF *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_5asBed_2__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_asBed *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_9libctabix_5asGTF_2__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_asGTF *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -4874,20 +4969,20 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asBed_2__setstate_cython__(struct _ __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); /* "(tree fragment)":15 - * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, state) + * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, state) * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_asBed__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + * __pyx_unpickle_asGTF__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_9libctabix___pyx_unpickle_asBed__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libctabix___pyx_unpickle_asGTF__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":14 * else: - * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, state) + * return __pyx_unpickle_asGTF, (type(self), 0x84bea1f, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_asBed__set_state(self, __pyx_state) + * __pyx_unpickle_asGTF__set_state(self, __pyx_state) */ /* function exit code */ @@ -4895,7 +4990,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asBed_2__setstate_cython__(struct _ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabix.asBed.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.asGTF.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -4904,48 +4999,48 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asBed_2__setstate_cython__(struct _ return __pyx_r; } -/* "pysam/libctabix.pyx":242 +/* "pysam/libctabix.pyx":241 * * ''' * cdef parse(self, char * buffer, int len): # <<<<<<<<<<<<<< - * cdef ctabixproxies.VCFProxy r - * r = ctabixproxies.VCFProxy(self.encoding) + * cdef ctabixproxies.BedProxy r + * r = ctabixproxies.BedProxy(self.encoding) */ -static PyObject *__pyx_f_5pysam_9libctabix_5asVCF_parse(struct __pyx_obj_5pysam_9libctabix_asVCF *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) { - struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_r = 0; +static PyObject *__pyx_f_5pysam_9libctabix_5asBed_parse(struct __pyx_obj_5pysam_9libctabix_asBed *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) { + struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_r = 0; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("parse", 0); - __Pyx_TraceCall("parse", __pyx_f[0], 242, 0, __PYX_ERR(0, 242, __pyx_L1_error)); + __Pyx_TraceCall("parse", __pyx_f[0], 241, 0, __PYX_ERR(0, 241, __pyx_L1_error)); - /* "pysam/libctabix.pyx":244 + /* "pysam/libctabix.pyx":243 * cdef parse(self, char * buffer, int len): - * cdef ctabixproxies.VCFProxy r - * r = ctabixproxies.VCFProxy(self.encoding) # <<<<<<<<<<<<<< + * cdef ctabixproxies.BedProxy r + * r = ctabixproxies.BedProxy(self.encoding) # <<<<<<<<<<<<<< * r.copy(buffer, len) * return r */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_VCFProxy), __pyx_v_self->__pyx_base.encoding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 244, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_BedProxy), __pyx_v_self->__pyx_base.encoding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 243, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_v_r = ((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_t_1); + __pyx_v_r = ((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":245 - * cdef ctabixproxies.VCFProxy r - * r = ctabixproxies.VCFProxy(self.encoding) + /* "pysam/libctabix.pyx":244 + * cdef ctabixproxies.BedProxy r + * r = ctabixproxies.BedProxy(self.encoding) * r.copy(buffer, len) # <<<<<<<<<<<<<< * return r * */ - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_r->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.__pyx_base.copy(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 245, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy *)__pyx_v_r->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.__pyx_base.copy(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 244, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":246 - * r = ctabixproxies.VCFProxy(self.encoding) + /* "pysam/libctabix.pyx":245 + * r = ctabixproxies.BedProxy(self.encoding) * r.copy(buffer, len) * return r # <<<<<<<<<<<<<< * @@ -4956,18 +5051,18 @@ static PyObject *__pyx_f_5pysam_9libctabix_5asVCF_parse(struct __pyx_obj_5pysam_ __pyx_r = ((PyObject *)__pyx_v_r); goto __pyx_L0; - /* "pysam/libctabix.pyx":242 + /* "pysam/libctabix.pyx":241 * * ''' * cdef parse(self, char * buffer, int len): # <<<<<<<<<<<<<< - * cdef ctabixproxies.VCFProxy r - * r = ctabixproxies.VCFProxy(self.encoding) + * cdef ctabixproxies.BedProxy r + * r = ctabixproxies.BedProxy(self.encoding) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabix.asVCF.parse", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.asBed.parse", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_r); @@ -4984,20 +5079,20 @@ static PyObject *__pyx_f_5pysam_9libctabix_5asVCF_parse(struct __pyx_obj_5pysam_ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_5asVCF_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_5asVCF___reduce_cython__[] = "asVCF.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_9libctabix_5asVCF_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_9libctabix_5asBed_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_5asBed___reduce_cython__[] = "asBed.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_9libctabix_5asBed_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libctabix_5asVCF___reduce_cython__(((struct __pyx_obj_5pysam_9libctabix_asVCF *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_9libctabix_5asBed___reduce_cython__(((struct __pyx_obj_5pysam_9libctabix_asBed *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF___reduce_cython__(struct __pyx_obj_5pysam_9libctabix_asVCF *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_9libctabix_5asBed___reduce_cython__(struct __pyx_obj_5pysam_9libctabix_asBed *__pyx_v_self) { int __pyx_v_use_setstate; PyObject *__pyx_v_state = NULL; PyObject *__pyx_v__dict = NULL; @@ -5092,7 +5187,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF___reduce_cython__(struct __py * else: * use_setstate = self.encoding is not None # <<<<<<<<<<<<<< * if use_setstate: - * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, None), state + * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, None), state */ /*else*/ { __pyx_t_3 = (__pyx_v_self->__pyx_base.encoding != Py_None); @@ -5104,7 +5199,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF___reduce_cython__(struct __py * else: * use_setstate = self.encoding is not None * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, None), state + * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, None), state * else: */ __pyx_t_3 = (__pyx_v_use_setstate != 0); @@ -5113,12 +5208,12 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF___reduce_cython__(struct __py /* "(tree fragment)":11 * use_setstate = self.encoding is not None * if use_setstate: - * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, None), state # <<<<<<<<<<<<<< + * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, None), state # <<<<<<<<<<<<<< * else: - * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, state) + * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, state) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asVCF); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asBed); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); @@ -5150,21 +5245,21 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF___reduce_cython__(struct __py * else: * use_setstate = self.encoding is not None * if use_setstate: # <<<<<<<<<<<<<< - * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, None), state + * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, None), state * else: */ } /* "(tree fragment)":13 - * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, None), state + * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, None), state * else: - * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, state) # <<<<<<<<<<<<<< + * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, state) # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_asVCF__set_state(self, __pyx_state) + * __pyx_unpickle_asBed__set_state(self, __pyx_state) */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asVCF); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asBed); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); @@ -5201,7 +5296,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF___reduce_cython__(struct __py __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libctabix.asVCF.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.asBed.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_state); @@ -5214,26 +5309,26 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF___reduce_cython__(struct __py /* "(tree fragment)":14 * else: - * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, state) + * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_asVCF__set_state(self, __pyx_state) + * __pyx_unpickle_asBed__set_state(self, __pyx_state) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_5asVCF_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_5asVCF_2__setstate_cython__[] = "asVCF.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_9libctabix_5asVCF_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_9libctabix_5asBed_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_5asBed_2__setstate_cython__[] = "asBed.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_9libctabix_5asBed_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libctabix_5asVCF_2__setstate_cython__(((struct __pyx_obj_5pysam_9libctabix_asVCF *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_9libctabix_5asBed_2__setstate_cython__(((struct __pyx_obj_5pysam_9libctabix_asBed *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF_2__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_asVCF *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_9libctabix_5asBed_2__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_asBed *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -5242,20 +5337,20 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF_2__setstate_cython__(struct _ __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); /* "(tree fragment)":15 - * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, state) + * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, state) * def __setstate_cython__(self, __pyx_state): - * __pyx_unpickle_asVCF__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + * __pyx_unpickle_asBed__set_state(self, __pyx_state) # <<<<<<<<<<<<<< */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) - __pyx_t_1 = __pyx_f_5pysam_9libctabix___pyx_unpickle_asVCF__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libctabix___pyx_unpickle_asBed__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":14 * else: - * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, state) + * return __pyx_unpickle_asBed, (type(self), 0x84bea1f, state) * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * __pyx_unpickle_asVCF__set_state(self, __pyx_state) + * __pyx_unpickle_asBed__set_state(self, __pyx_state) */ /* function exit code */ @@ -5263,7 +5358,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF_2__setstate_cython__(struct _ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabix.asVCF.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.asBed.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -5272,176 +5367,557 @@ static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF_2__setstate_cython__(struct _ return __pyx_r; } -/* "pysam/libctabix.pyx":291 - * if file could not be opened - * """ - * def __cinit__(self, # <<<<<<<<<<<<<< - * filename, - * mode='r', +/* "pysam/libctabix.pyx":282 + * + * ''' + * cdef parse(self, char * buffer, int len): # <<<<<<<<<<<<<< + * cdef ctabixproxies.VCFProxy r + * r = ctabixproxies.VCFProxy(self.encoding) */ -/* Python wrapper */ -static int __pyx_pw_5pysam_9libctabix_9TabixFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5pysam_9libctabix_9TabixFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_filename = 0; - PyObject *__pyx_v_mode = 0; - PyObject *__pyx_v_parser = 0; - PyObject *__pyx_v_index = 0; - PyObject *__pyx_v_encoding = 0; - PyObject *__pyx_v_args = 0; - PyObject *__pyx_v_kwargs = 0; - int __pyx_r; +static PyObject *__pyx_f_5pysam_9libctabix_5asVCF_parse(struct __pyx_obj_5pysam_9libctabix_asVCF *__pyx_v_self, char *__pyx_v_buffer, int __pyx_v_len) { + struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_r = 0; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1; - __Pyx_GOTREF(__pyx_v_kwargs); - if (PyTuple_GET_SIZE(__pyx_args) > 5) { - __pyx_v_args = PyTuple_GetSlice(__pyx_args, 5, PyTuple_GET_SIZE(__pyx_args)); - if (unlikely(!__pyx_v_args)) { - __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; - __Pyx_RefNannyFinishContext(); - return -1; - } - __Pyx_GOTREF(__pyx_v_args); - } else { - __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple); - } - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,&__pyx_n_s_mode,&__pyx_n_s_parser,&__pyx_n_s_index,&__pyx_n_s_encoding,0}; - PyObject* values[5] = {0,0,0,0,0}; - values[1] = ((PyObject *)__pyx_n_s_r); + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("parse", 0); + __Pyx_TraceCall("parse", __pyx_f[0], 282, 0, __PYX_ERR(0, 282, __pyx_L1_error)); - /* "pysam/libctabix.pyx":294 - * filename, - * mode='r', - * parser=None, # <<<<<<<<<<<<<< - * index=None, - * encoding="ascii", + /* "pysam/libctabix.pyx":284 + * cdef parse(self, char * buffer, int len): + * cdef ctabixproxies.VCFProxy r + * r = ctabixproxies.VCFProxy(self.encoding) # <<<<<<<<<<<<<< + * r.copy(buffer, len) + * return r */ - values[2] = ((PyObject *)Py_None); + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_VCFProxy), __pyx_v_self->__pyx_base.encoding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 284, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_r = ((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":295 - * mode='r', - * parser=None, - * index=None, # <<<<<<<<<<<<<< - * encoding="ascii", - * *args, + /* "pysam/libctabix.pyx":285 + * cdef ctabixproxies.VCFProxy r + * r = ctabixproxies.VCFProxy(self.encoding) + * r.copy(buffer, len) # <<<<<<<<<<<<<< + * return r + * */ - values[3] = ((PyObject *)Py_None); - values[4] = ((PyObject *)__pyx_n_s_ascii); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - default: - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filename)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode); - if (value) { values[1] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_parser); - if (value) { values[2] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_index); - if (value) { values[3] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_encoding); - if (value) { values[4] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - const Py_ssize_t used_pos_args = (pos_args < 5) ? pos_args : 5; - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, used_pos_args, "__cinit__") < 0)) __PYX_ERR(0, 291, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - default: - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - case 0: - goto __pyx_L5_argtuple_error; - } - } - __pyx_v_filename = values[0]; - __pyx_v_mode = values[1]; - __pyx_v_parser = values[2]; - __pyx_v_index = values[3]; - __pyx_v_encoding = values[4]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 291, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_DECREF(__pyx_v_args); __pyx_v_args = 0; - __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; - __Pyx_AddTraceback("pysam.libctabix.TabixFile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(((struct __pyx_obj_5pysam_9libctabix_TabixFile *)__pyx_v_self), __pyx_v_filename, __pyx_v_mode, __pyx_v_parser, __pyx_v_index, __pyx_v_encoding, __pyx_v_args, __pyx_v_kwargs); + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_r->__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base.__pyx_base.copy(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_r), __pyx_v_buffer, __pyx_v_len, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 285, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":291 - * if file could not be opened - * """ - * def __cinit__(self, # <<<<<<<<<<<<<< - * filename, - * mode='r', + /* "pysam/libctabix.pyx":286 + * r = ctabixproxies.VCFProxy(self.encoding) + * r.copy(buffer, len) + * return r # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_r)); + __pyx_r = ((PyObject *)__pyx_v_r); + goto __pyx_L0; + + /* "pysam/libctabix.pyx":282 + * + * ''' + * cdef parse(self, char * buffer, int len): # <<<<<<<<<<<<<< + * cdef ctabixproxies.VCFProxy r + * r = ctabixproxies.VCFProxy(self.encoding) */ /* function exit code */ - __Pyx_XDECREF(__pyx_v_args); - __Pyx_XDECREF(__pyx_v_kwargs); + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libctabix.asVCF.parse", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_r); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_parser, PyObject *__pyx_v_index, PyObject *__pyx_v_encoding, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) { - int __pyx_r; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[0], 291, 0, __PYX_ERR(0, 291, __pyx_L1_error)); +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef bint use_setstate + * state = (self.encoding,) + */ - /* "pysam/libctabix.pyx":300 - * **kwargs ): +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libctabix_5asVCF_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_5asVCF___reduce_cython__[] = "asVCF.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_9libctabix_5asVCF_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libctabix_5asVCF___reduce_cython__(((struct __pyx_obj_5pysam_9libctabix_asVCF *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF___reduce_cython__(struct __pyx_obj_5pysam_9libctabix_asVCF *__pyx_v_self) { + int __pyx_v_use_setstate; + PyObject *__pyx_v_state = NULL; + PyObject *__pyx_v__dict = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * cdef bint use_setstate + * state = (self.encoding,) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_self->__pyx_base.encoding); + __Pyx_GIVEREF(__pyx_v_self->__pyx_base.encoding); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->__pyx_base.encoding); + __pyx_v_state = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":4 + * cdef bint use_setstate + * state = (self.encoding,) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v__dict = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":5 + * state = (self.encoding,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_2 = (__pyx_v__dict != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":6 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "(tree fragment)":7 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self.encoding is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":5 + * state = (self.encoding,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":9 + * use_setstate = True + * else: + * use_setstate = self.encoding is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, None), state + */ + /*else*/ { + __pyx_t_3 = (__pyx_v_self->__pyx_base.encoding != Py_None); + __pyx_v_use_setstate = __pyx_t_3; + } + __pyx_L3:; + + /* "(tree fragment)":10 + * else: + * use_setstate = self.encoding is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, None), state + * else: + */ + __pyx_t_3 = (__pyx_v_use_setstate != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":11 + * use_setstate = self.encoding is not None + * if use_setstate: + * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, state) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asVCF); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_139192863); + __Pyx_GIVEREF(__pyx_int_139192863); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_139192863); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "(tree fragment)":10 + * else: + * use_setstate = self.encoding is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, None), state + * else: + */ + } + + /* "(tree fragment)":13 + * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, None), state + * else: + * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_asVCF__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyx_unpickle_asVCF); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_139192863); + __Pyx_GIVEREF(__pyx_int_139192863); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_139192863); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __pyx_t_5 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef bint use_setstate + * state = (self.encoding,) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libctabix.asVCF.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":14 + * else: + * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_asVCF__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libctabix_5asVCF_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_5asVCF_2__setstate_cython__[] = "asVCF.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_9libctabix_5asVCF_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libctabix_5asVCF_2__setstate_cython__(((struct __pyx_obj_5pysam_9libctabix_asVCF *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_9libctabix_5asVCF_2__setstate_cython__(struct __pyx_obj_5pysam_9libctabix_asVCF *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 14, 0, __PYX_ERR(1, 14, __pyx_L1_error)); + + /* "(tree fragment)":15 + * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_asVCF__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 15, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libctabix___pyx_unpickle_asVCF__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":14 + * else: + * return __pyx_unpickle_asVCF, (type(self), 0x84bea1f, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_asVCF__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libctabix.asVCF.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libctabix.pyx":336 + * if file could not be opened + * """ + * def __cinit__(self, # <<<<<<<<<<<<<< + * filename, + * mode='r', + */ + +/* Python wrapper */ +static int __pyx_pw_5pysam_9libctabix_9TabixFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_9libctabix_9TabixFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_filename = 0; + PyObject *__pyx_v_mode = 0; + PyObject *__pyx_v_parser = 0; + PyObject *__pyx_v_index = 0; + PyObject *__pyx_v_encoding = 0; + PyObject *__pyx_v_threads = 0; + PyObject *__pyx_v_args = 0; + PyObject *__pyx_v_kwargs = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1; + __Pyx_GOTREF(__pyx_v_kwargs); + if (PyTuple_GET_SIZE(__pyx_args) > 6) { + __pyx_v_args = PyTuple_GetSlice(__pyx_args, 6, PyTuple_GET_SIZE(__pyx_args)); + if (unlikely(!__pyx_v_args)) { + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_RefNannyFinishContext(); + return -1; + } + __Pyx_GOTREF(__pyx_v_args); + } else { + __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple); + } + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,&__pyx_n_s_mode,&__pyx_n_s_parser,&__pyx_n_s_index,&__pyx_n_s_encoding,&__pyx_n_s_threads,0}; + PyObject* values[6] = {0,0,0,0,0,0}; + values[1] = ((PyObject *)__pyx_n_s_r); + + /* "pysam/libctabix.pyx":339 + * filename, + * mode='r', + * parser=None, # <<<<<<<<<<<<<< + * index=None, + * encoding="ascii", + */ + values[2] = ((PyObject *)Py_None); + + /* "pysam/libctabix.pyx":340 + * mode='r', + * parser=None, + * index=None, # <<<<<<<<<<<<<< + * encoding="ascii", + * threads=1, + */ + values[3] = ((PyObject *)Py_None); + values[4] = ((PyObject *)__pyx_n_s_ascii); + values[5] = ((PyObject *)__pyx_int_1); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + default: + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filename)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode); + if (value) { values[1] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_parser); + if (value) { values[2] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_index); + if (value) { values[3] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 4: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_encoding); + if (value) { values[4] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 5: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_threads); + if (value) { values[5] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t used_pos_args = (pos_args < 6) ? pos_args : 6; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, used_pos_args, "__cinit__") < 0)) __PYX_ERR(0, 336, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + default: + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + case 0: + goto __pyx_L5_argtuple_error; + } + } + __pyx_v_filename = values[0]; + __pyx_v_mode = values[1]; + __pyx_v_parser = values[2]; + __pyx_v_index = values[3]; + __pyx_v_encoding = values[4]; + __pyx_v_threads = values[5]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 336, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_DECREF(__pyx_v_args); __pyx_v_args = 0; + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_AddTraceback("pysam.libctabix.TabixFile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(((struct __pyx_obj_5pysam_9libctabix_TabixFile *)__pyx_v_self), __pyx_v_filename, __pyx_v_mode, __pyx_v_parser, __pyx_v_index, __pyx_v_encoding, __pyx_v_threads, __pyx_v_args, __pyx_v_kwargs); + + /* "pysam/libctabix.pyx":336 + * if file could not be opened + * """ + * def __cinit__(self, # <<<<<<<<<<<<<< + * filename, + * mode='r', + */ + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_parser, PyObject *__pyx_v_index, PyObject *__pyx_v_encoding, PyObject *__pyx_v_threads, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) { + int __pyx_r; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__cinit__", 0); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 336, 0, __PYX_ERR(0, 336, __pyx_L1_error)); + + /* "pysam/libctabix.pyx":346 + * **kwargs ): * * self.htsfile = NULL # <<<<<<<<<<<<<< * self.is_remote = False @@ -5449,7 +5925,7 @@ static int __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(struct __pyx_obj_5pys */ __pyx_v_self->__pyx_base.htsfile = NULL; - /* "pysam/libctabix.pyx":301 + /* "pysam/libctabix.pyx":347 * * self.htsfile = NULL * self.is_remote = False # <<<<<<<<<<<<<< @@ -5458,23 +5934,23 @@ static int __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(struct __pyx_obj_5pys */ __pyx_v_self->__pyx_base.is_remote = 0; - /* "pysam/libctabix.pyx":302 + /* "pysam/libctabix.pyx":348 * self.htsfile = NULL * self.is_remote = False * self.is_stream = False # <<<<<<<<<<<<<< * self.parser = parser - * self._open(filename, mode, index, *args, **kwargs) + * self.threads = threads */ __pyx_v_self->__pyx_base.is_stream = 0; - /* "pysam/libctabix.pyx":303 + /* "pysam/libctabix.pyx":349 * self.is_remote = False * self.is_stream = False * self.parser = parser # <<<<<<<<<<<<<< + * self.threads = threads * self._open(filename, mode, index, *args, **kwargs) - * self.encoding = encoding */ - if (!(likely(((__pyx_v_parser) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_parser, __pyx_ptype_5pysam_9libctabix_Parser))))) __PYX_ERR(0, 303, __pyx_L1_error) + if (!(likely(((__pyx_v_parser) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_parser, __pyx_ptype_5pysam_9libctabix_Parser))))) __PYX_ERR(0, 349, __pyx_L1_error) __pyx_t_1 = __pyx_v_parser; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -5483,16 +5959,29 @@ static int __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(struct __pyx_obj_5pys __pyx_v_self->parser = ((struct __pyx_obj_5pysam_9libctabix_Parser *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":304 + /* "pysam/libctabix.pyx":350 * self.is_stream = False * self.parser = parser + * self.threads = threads # <<<<<<<<<<<<<< + * self._open(filename, mode, index, *args, **kwargs) + * self.encoding = encoding + */ + __Pyx_INCREF(__pyx_v_threads); + __Pyx_GIVEREF(__pyx_v_threads); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.threads); + __Pyx_DECREF(__pyx_v_self->__pyx_base.threads); + __pyx_v_self->__pyx_base.threads = __pyx_v_threads; + + /* "pysam/libctabix.pyx":351 + * self.parser = parser + * self.threads = threads * self._open(filename, mode, index, *args, **kwargs) # <<<<<<<<<<<<<< * self.encoding = encoding * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 304, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 351, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 304, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 351, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); @@ -5503,17 +5992,17 @@ static int __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(struct __pyx_obj_5pys __Pyx_INCREF(__pyx_v_index); __Pyx_GIVEREF(__pyx_v_index); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_index); - __pyx_t_3 = PyNumber_Add(__pyx_t_2, __pyx_v_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 304, __pyx_L1_error) + __pyx_t_3 = PyNumber_Add(__pyx_t_2, __pyx_v_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 351, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 304, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 351, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":305 - * self.parser = parser + /* "pysam/libctabix.pyx":352 + * self.threads = threads * self._open(filename, mode, index, *args, **kwargs) * self.encoding = encoding # <<<<<<<<<<<<<< * @@ -5525,7 +6014,7 @@ static int __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(struct __pyx_obj_5pys __Pyx_DECREF(__pyx_v_self->encoding); __pyx_v_self->encoding = __pyx_v_encoding; - /* "pysam/libctabix.pyx":291 + /* "pysam/libctabix.pyx":336 * if file could not be opened * """ * def __cinit__(self, # <<<<<<<<<<<<<< @@ -5548,7 +6037,7 @@ static int __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(struct __pyx_obj_5pys return __pyx_r; } -/* "pysam/libctabix.pyx":307 +/* "pysam/libctabix.pyx":354 * self.encoding = encoding * * def _open( self, # <<<<<<<<<<<<<< @@ -5558,31 +6047,35 @@ static int __pyx_pf_5pysam_9libctabix_9TabixFile___cinit__(struct __pyx_obj_5pys /* Python wrapper */ static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_3_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_9TabixFile_2_open[] = "TabixFile._open(self, filename, mode='r', index=None)\nopen a :term:`tabix file` for reading."; +static char __pyx_doc_5pysam_9libctabix_9TabixFile_2_open[] = "TabixFile._open(self, filename, mode='r', index=None, threads=1)\nopen a :term:`tabix file` for reading."; static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_3_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_filename = 0; PyObject *__pyx_v_mode = 0; PyObject *__pyx_v_index = 0; + PyObject *__pyx_v_threads = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("_open (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,&__pyx_n_s_mode,&__pyx_n_s_index,0}; - PyObject* values[3] = {0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,&__pyx_n_s_mode,&__pyx_n_s_index,&__pyx_n_s_threads,0}; + PyObject* values[4] = {0,0,0,0}; values[1] = ((PyObject *)__pyx_n_s_r); - /* "pysam/libctabix.pyx":310 + /* "pysam/libctabix.pyx":357 * filename, * mode='r', * index=None, # <<<<<<<<<<<<<< + * threads=1, * ): - * '''open a :term:`tabix file` for reading.''' */ values[2] = ((PyObject *)Py_None); + values[3] = ((PyObject *)__pyx_int_1); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); @@ -5609,12 +6102,20 @@ static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_3_open(PyObject *__pyx_v_ PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_index); if (value) { values[2] = value; kw_args--; } } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_threads); + if (value) { values[3] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) __PYX_ERR(0, 307, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) __PYX_ERR(0, 354, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); @@ -5627,18 +6128,19 @@ static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_3_open(PyObject *__pyx_v_ __pyx_v_filename = values[0]; __pyx_v_mode = values[1]; __pyx_v_index = values[2]; + __pyx_v_threads = values[3]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 307, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 354, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabix.TabixFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libctabix_9TabixFile_2_open(((struct __pyx_obj_5pysam_9libctabix_TabixFile *)__pyx_v_self), __pyx_v_filename, __pyx_v_mode, __pyx_v_index); + __pyx_r = __pyx_pf_5pysam_9libctabix_9TabixFile_2_open(((struct __pyx_obj_5pysam_9libctabix_TabixFile *)__pyx_v_self), __pyx_v_filename, __pyx_v_mode, __pyx_v_index, __pyx_v_threads); - /* "pysam/libctabix.pyx":307 + /* "pysam/libctabix.pyx":354 * self.encoding = encoding * * def _open( self, # <<<<<<<<<<<<<< @@ -5651,9 +6153,10 @@ static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_3_open(PyObject *__pyx_v_ return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_index) { +static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, PyObject *__pyx_v_index, PyObject *__pyx_v_threads) { PyObject *__pyx_v_filename_index = NULL; char *__pyx_v_cfilename; + char *__pyx_v_cfilename_index; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -5667,35 +6170,35 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 char *__pyx_t_8; int64_t __pyx_t_9; __Pyx_RefNannySetupContext("_open", 0); - __Pyx_TraceCall("_open", __pyx_f[0], 307, 0, __PYX_ERR(0, 307, __pyx_L1_error)); + __Pyx_TraceCall("_open", __pyx_f[0], 354, 0, __PYX_ERR(0, 354, __pyx_L1_error)); - /* "pysam/libctabix.pyx":314 + /* "pysam/libctabix.pyx":362 * '''open a :term:`tabix file` for reading.''' * * if mode != 'r': # <<<<<<<<<<<<<< * raise ValueError("invalid file opening mode `%s`" % mode) * */ - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_r, Py_NE)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 314, __pyx_L1_error) + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_r, Py_NE)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 362, __pyx_L1_error) if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":315 + /* "pysam/libctabix.pyx":363 * * if mode != 'r': * raise ValueError("invalid file opening mode `%s`" % mode) # <<<<<<<<<<<<<< * * if self.htsfile != NULL: */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_invalid_file_opening_mode_s, __pyx_v_mode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 315, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_invalid_file_opening_mode_s, __pyx_v_mode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 315, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 315, __pyx_L1_error) + __PYX_ERR(0, 363, __pyx_L1_error) - /* "pysam/libctabix.pyx":314 + /* "pysam/libctabix.pyx":362 * '''open a :term:`tabix file` for reading.''' * * if mode != 'r': # <<<<<<<<<<<<<< @@ -5704,7 +6207,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 */ } - /* "pysam/libctabix.pyx":317 + /* "pysam/libctabix.pyx":365 * raise ValueError("invalid file opening mode `%s`" % mode) * * if self.htsfile != NULL: # <<<<<<<<<<<<<< @@ -5714,14 +6217,14 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 __pyx_t_1 = ((__pyx_v_self->__pyx_base.htsfile != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":318 + /* "pysam/libctabix.pyx":366 * * if self.htsfile != NULL: * self.close() # <<<<<<<<<<<<<< * self.htsfile = NULL - * + * self.threads=threads */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 318, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 366, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -5734,16 +6237,16 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 } } if (__pyx_t_4) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 318, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { - __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 318, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libctabix.pyx":317 + /* "pysam/libctabix.pyx":365 * raise ValueError("invalid file opening mode `%s`" % mode) * * if self.htsfile != NULL: # <<<<<<<<<<<<<< @@ -5752,30 +6255,43 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 */ } - /* "pysam/libctabix.pyx":319 + /* "pysam/libctabix.pyx":367 * if self.htsfile != NULL: * self.close() * self.htsfile = NULL # <<<<<<<<<<<<<< + * self.threads=threads * - * filename_index = index or (filename + ".tbi") */ __pyx_v_self->__pyx_base.htsfile = NULL; - /* "pysam/libctabix.pyx":321 + /* "pysam/libctabix.pyx":368 + * self.close() * self.htsfile = NULL + * self.threads=threads # <<<<<<<<<<<<<< + * + * filename_index = index or (filename + ".tbi") + */ + __Pyx_INCREF(__pyx_v_threads); + __Pyx_GIVEREF(__pyx_v_threads); + __Pyx_GOTREF(__pyx_v_self->__pyx_base.threads); + __Pyx_DECREF(__pyx_v_self->__pyx_base.threads); + __pyx_v_self->__pyx_base.threads = __pyx_v_threads; + + /* "pysam/libctabix.pyx":370 + * self.threads=threads * * filename_index = index or (filename + ".tbi") # <<<<<<<<<<<<<< * # encode all the strings to pass to tabix * self.filename = encode_filename(filename) */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_index); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 321, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_index); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 370, __pyx_L1_error) if (!__pyx_t_1) { } else { __Pyx_INCREF(__pyx_v_index); __pyx_t_3 = __pyx_v_index; goto __pyx_L5_bool_binop_done; } - __pyx_t_2 = PyNumber_Add(__pyx_v_filename, __pyx_kp_s_tbi); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error) + __pyx_t_2 = PyNumber_Add(__pyx_v_filename, __pyx_kp_s_tbi); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 370, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_t_2; @@ -5784,14 +6300,14 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 __pyx_v_filename_index = __pyx_t_3; __pyx_t_3 = 0; - /* "pysam/libctabix.pyx":323 + /* "pysam/libctabix.pyx":372 * filename_index = index or (filename + ".tbi") * # encode all the strings to pass to tabix * self.filename = encode_filename(filename) # <<<<<<<<<<<<<< * self.filename_index = encode_filename(filename_index) * */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 323, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 372, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename); @@ -5799,14 +6315,14 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 __pyx_v_self->__pyx_base.filename = __pyx_t_3; __pyx_t_3 = 0; - /* "pysam/libctabix.pyx":324 + /* "pysam/libctabix.pyx":373 * # encode all the strings to pass to tabix * self.filename = encode_filename(filename) * self.filename_index = encode_filename(filename_index) # <<<<<<<<<<<<<< * * self.is_stream = self.filename == b'-' */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename_index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 324, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename_index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 373, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_GOTREF(__pyx_v_self->filename_index); @@ -5814,29 +6330,29 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 __pyx_v_self->filename_index = __pyx_t_3; __pyx_t_3 = 0; - /* "pysam/libctabix.pyx":326 + /* "pysam/libctabix.pyx":375 * self.filename_index = encode_filename(filename_index) * * self.is_stream = self.filename == b'-' # <<<<<<<<<<<<<< * self.is_remote = hisremote(self.filename) * */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_self->__pyx_base.filename, __pyx_kp_b_, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 326, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 326, __pyx_L1_error) + __pyx_t_3 = PyObject_RichCompare(__pyx_v_self->__pyx_base.filename, __pyx_kp_b_, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 375, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 375, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_self->__pyx_base.is_stream = __pyx_t_1; - /* "pysam/libctabix.pyx":327 + /* "pysam/libctabix.pyx":376 * * self.is_stream = self.filename == b'-' * self.is_remote = hisremote(self.filename) # <<<<<<<<<<<<<< * * if not self.is_remote: */ - __pyx_t_5 = __Pyx_PyObject_AsString(__pyx_v_self->__pyx_base.filename); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 327, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_AsString(__pyx_v_self->__pyx_base.filename); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 376, __pyx_L1_error) __pyx_v_self->__pyx_base.is_remote = hisremote(__pyx_t_5); - /* "pysam/libctabix.pyx":329 + /* "pysam/libctabix.pyx":378 * self.is_remote = hisremote(self.filename) * * if not self.is_remote: # <<<<<<<<<<<<<< @@ -5846,19 +6362,19 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 __pyx_t_1 = ((!(__pyx_v_self->__pyx_base.is_remote != 0)) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":330 + /* "pysam/libctabix.pyx":379 * * if not self.is_remote: * if not os.path.exists(filename): # <<<<<<<<<<<<<< * raise IOError("file `%s` not found" % filename) * */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 330, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 330, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exists); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 330, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exists); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = NULL; @@ -5872,13 +6388,13 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 } } if (!__pyx_t_4) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 330, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filename}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 330, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 379, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -5886,46 +6402,46 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filename}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 330, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 379, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 330, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_filename); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 330, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 330, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 379, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_7 = ((!__pyx_t_1) != 0); if (unlikely(__pyx_t_7)) { - /* "pysam/libctabix.pyx":331 + /* "pysam/libctabix.pyx":380 * if not self.is_remote: * if not os.path.exists(filename): * raise IOError("file `%s` not found" % filename) # <<<<<<<<<<<<<< * * if not os.path.exists(filename_index): */ - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_file_s_not_found, __pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 331, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_file_s_not_found, __pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 380, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 331, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 331, __pyx_L1_error) + __PYX_ERR(0, 380, __pyx_L1_error) - /* "pysam/libctabix.pyx":330 + /* "pysam/libctabix.pyx":379 * * if not self.is_remote: * if not os.path.exists(filename): # <<<<<<<<<<<<<< @@ -5934,19 +6450,19 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 */ } - /* "pysam/libctabix.pyx":333 + /* "pysam/libctabix.pyx":382 * raise IOError("file `%s` not found" % filename) * * if not os.path.exists(filename_index): # <<<<<<<<<<<<<< * raise IOError("index `%s` not found" % filename_index) * */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 333, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 382, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 333, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 382, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_exists); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 333, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_exists); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 382, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = NULL; @@ -5960,13 +6476,13 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 } } if (!__pyx_t_6) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_filename_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 333, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_filename_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 382, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_filename_index}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 333, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 382, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); } else @@ -5974,46 +6490,46 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_filename_index}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 333, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 382, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 333, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 382, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v_filename_index); __Pyx_GIVEREF(__pyx_v_filename_index); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_filename_index); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 333, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 382, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 333, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 382, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_1 = ((!__pyx_t_7) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":334 + /* "pysam/libctabix.pyx":383 * * if not os.path.exists(filename_index): * raise IOError("index `%s` not found" % filename_index) # <<<<<<<<<<<<<< * * # open file */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_index_s_not_found, __pyx_v_filename_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 334, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_index_s_not_found, __pyx_v_filename_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 383, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 334, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 383, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 334, __pyx_L1_error) + __PYX_ERR(0, 383, __pyx_L1_error) - /* "pysam/libctabix.pyx":333 + /* "pysam/libctabix.pyx":382 * raise IOError("file `%s` not found" % filename) * * if not os.path.exists(filename_index): # <<<<<<<<<<<<<< @@ -6022,7 +6538,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 */ } - /* "pysam/libctabix.pyx":329 + /* "pysam/libctabix.pyx":378 * self.is_remote = hisremote(self.filename) * * if not self.is_remote: # <<<<<<<<<<<<<< @@ -6031,19 +6547,29 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 */ } - /* "pysam/libctabix.pyx":337 + /* "pysam/libctabix.pyx":386 * * # open file * cdef char *cfilename = self.filename # <<<<<<<<<<<<<< + * cdef char *cfilename_index = self.filename_index * with nogil: - * self.htsfile = hts_open(cfilename, 'r') */ - __pyx_t_8 = __Pyx_PyObject_AsWritableString(__pyx_v_self->__pyx_base.filename); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 337, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_AsWritableString(__pyx_v_self->__pyx_base.filename); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 386, __pyx_L1_error) __pyx_v_cfilename = __pyx_t_8; - /* "pysam/libctabix.pyx":338 + /* "pysam/libctabix.pyx":387 * # open file * cdef char *cfilename = self.filename + * cdef char *cfilename_index = self.filename_index # <<<<<<<<<<<<<< + * with nogil: + * self.htsfile = hts_open(cfilename, 'r') + */ + __pyx_t_8 = __Pyx_PyObject_AsWritableString(__pyx_v_self->filename_index); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 387, __pyx_L1_error) + __pyx_v_cfilename_index = __pyx_t_8; + + /* "pysam/libctabix.pyx":388 + * cdef char *cfilename = self.filename + * cdef char *cfilename_index = self.filename_index * with nogil: # <<<<<<<<<<<<<< * self.htsfile = hts_open(cfilename, 'r') * @@ -6056,8 +6582,8 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 #endif /*try:*/ { - /* "pysam/libctabix.pyx":339 - * cdef char *cfilename = self.filename + /* "pysam/libctabix.pyx":389 + * cdef char *cfilename_index = self.filename_index * with nogil: * self.htsfile = hts_open(cfilename, 'r') # <<<<<<<<<<<<<< * @@ -6066,9 +6592,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 __pyx_v_self->__pyx_base.htsfile = hts_open(__pyx_v_cfilename, ((char const *)"r")); } - /* "pysam/libctabix.pyx":338 - * # open file + /* "pysam/libctabix.pyx":388 * cdef char *cfilename = self.filename + * cdef char *cfilename_index = self.filename_index * with nogil: # <<<<<<<<<<<<<< * self.htsfile = hts_open(cfilename, 'r') * @@ -6085,7 +6611,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 } } - /* "pysam/libctabix.pyx":341 + /* "pysam/libctabix.pyx":391 * self.htsfile = hts_open(cfilename, 'r') * * if self.htsfile == NULL: # <<<<<<<<<<<<<< @@ -6095,46 +6621,36 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 __pyx_t_1 = ((__pyx_v_self->__pyx_base.htsfile == NULL) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":342 + /* "pysam/libctabix.pyx":392 * * if self.htsfile == NULL: * raise IOError("could not open file `%s`" % filename) # <<<<<<<<<<<<<< * * #if self.htsfile.format.category != region_list: */ - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_file_s, __pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 342, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_file_s, __pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 392, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 342, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 392, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 342, __pyx_L1_error) + __PYX_ERR(0, 392, __pyx_L1_error) - /* "pysam/libctabix.pyx":341 + /* "pysam/libctabix.pyx":391 * self.htsfile = hts_open(cfilename, 'r') * * if self.htsfile == NULL: # <<<<<<<<<<<<<< * raise IOError("could not open file `%s`" % filename) * */ - } - - /* "pysam/libctabix.pyx":347 - * # raise ValueError("file does not contain region data") - * - * cfilename = self.filename_index # <<<<<<<<<<<<<< - * with nogil: - * self.index = tbx_index_load(cfilename) - */ - __pyx_t_8 = __Pyx_PyObject_AsWritableString(__pyx_v_self->filename_index); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 347, __pyx_L1_error) - __pyx_v_cfilename = __pyx_t_8; + } - /* "pysam/libctabix.pyx":348 + /* "pysam/libctabix.pyx":397 + * # raise ValueError("file does not contain region data") * - * cfilename = self.filename_index * with nogil: # <<<<<<<<<<<<<< - * self.index = tbx_index_load(cfilename) + * self.index = tbx_index_load2(cfilename, cfilename_index) * */ { @@ -6145,21 +6661,21 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 #endif /*try:*/ { - /* "pysam/libctabix.pyx":349 - * cfilename = self.filename_index + /* "pysam/libctabix.pyx":398 + * * with nogil: - * self.index = tbx_index_load(cfilename) # <<<<<<<<<<<<<< + * self.index = tbx_index_load2(cfilename, cfilename_index) # <<<<<<<<<<<<<< * * if self.index == NULL: */ - __pyx_v_self->index = tbx_index_load(__pyx_v_cfilename); + __pyx_v_self->index = tbx_index_load2(__pyx_v_cfilename, __pyx_v_cfilename_index); } - /* "pysam/libctabix.pyx":348 + /* "pysam/libctabix.pyx":397 + * # raise ValueError("file does not contain region data") * - * cfilename = self.filename_index * with nogil: # <<<<<<<<<<<<<< - * self.index = tbx_index_load(cfilename) + * self.index = tbx_index_load2(cfilename, cfilename_index) * */ /*finally:*/ { @@ -6174,8 +6690,8 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 } } - /* "pysam/libctabix.pyx":351 - * self.index = tbx_index_load(cfilename) + /* "pysam/libctabix.pyx":400 + * self.index = tbx_index_load2(cfilename, cfilename_index) * * if self.index == NULL: # <<<<<<<<<<<<<< * raise IOError("could not open index for `%s`" % filename) @@ -6184,24 +6700,24 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 __pyx_t_1 = ((__pyx_v_self->index == NULL) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":352 + /* "pysam/libctabix.pyx":401 * * if self.index == NULL: * raise IOError("could not open index for `%s`" % filename) # <<<<<<<<<<<<<< * * if not self.is_stream: */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_index_for_s, __pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 352, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_index_for_s, __pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 401, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 352, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 401, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 352, __pyx_L1_error) + __PYX_ERR(0, 401, __pyx_L1_error) - /* "pysam/libctabix.pyx":351 - * self.index = tbx_index_load(cfilename) + /* "pysam/libctabix.pyx":400 + * self.index = tbx_index_load2(cfilename, cfilename_index) * * if self.index == NULL: # <<<<<<<<<<<<<< * raise IOError("could not open index for `%s`" % filename) @@ -6209,7 +6725,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 */ } - /* "pysam/libctabix.pyx":354 + /* "pysam/libctabix.pyx":403 * raise IOError("could not open index for `%s`" % filename) * * if not self.is_stream: # <<<<<<<<<<<<<< @@ -6219,14 +6735,14 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 __pyx_t_1 = ((!(__pyx_v_self->__pyx_base.is_stream != 0)) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":355 + /* "pysam/libctabix.pyx":404 * * if not self.is_stream: * self.start_offset = self.tell() # <<<<<<<<<<<<<< * * def _dup(self): */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tell); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 355, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tell); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -6239,18 +6755,18 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 } } if (__pyx_t_4) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { - __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 404, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_9 = __Pyx_PyInt_As_int64_t(__pyx_t_3); if (unlikely((__pyx_t_9 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 355, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_As_int64_t(__pyx_t_3); if (unlikely((__pyx_t_9 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 404, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_self->__pyx_base.start_offset = __pyx_t_9; - /* "pysam/libctabix.pyx":354 + /* "pysam/libctabix.pyx":403 * raise IOError("could not open index for `%s`" % filename) * * if not self.is_stream: # <<<<<<<<<<<<<< @@ -6259,7 +6775,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 */ } - /* "pysam/libctabix.pyx":307 + /* "pysam/libctabix.pyx":354 * self.encoding = encoding * * def _open( self, # <<<<<<<<<<<<<< @@ -6282,594 +6798,1050 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_2_open(struct __pyx_obj_5 __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + return __pyx_r; +} + +/* "pysam/libctabix.pyx":406 + * self.start_offset = self.tell() + * + * def _dup(self): # <<<<<<<<<<<<<< + * '''return a copy of this tabix file. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_5_dup(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_9TabixFile_4_dup[] = "TabixFile._dup(self)\nreturn a copy of this tabix file.\n \n The file is being re-opened.\n "; +static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_5_dup(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_dup (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libctabix_9TabixFile_4_dup(((struct __pyx_obj_5pysam_9libctabix_TabixFile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_4_dup(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("_dup", 0); + __Pyx_TraceCall("_dup", __pyx_f[0], 406, 0, __PYX_ERR(0, 406, __pyx_L1_error)); + + /* "pysam/libctabix.pyx":411 + * The file is being re-opened. + * ''' + * return TabixFile(self.filename, # <<<<<<<<<<<<<< + * mode="r", + * threads=self.threads, + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 411, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_self->__pyx_base.filename); + __Pyx_GIVEREF(__pyx_v_self->__pyx_base.filename); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->__pyx_base.filename); + + /* "pysam/libctabix.pyx":412 + * ''' + * return TabixFile(self.filename, + * mode="r", # <<<<<<<<<<<<<< + * threads=self.threads, + * parser=self.parser, + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 412, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_mode, __pyx_n_s_r) < 0) __PYX_ERR(0, 412, __pyx_L1_error) + + /* "pysam/libctabix.pyx":413 + * return TabixFile(self.filename, + * mode="r", + * threads=self.threads, # <<<<<<<<<<<<<< + * parser=self.parser, + * index=self.filename_index, + */ + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_threads, __pyx_v_self->__pyx_base.threads) < 0) __PYX_ERR(0, 412, __pyx_L1_error) + + /* "pysam/libctabix.pyx":414 + * mode="r", + * threads=self.threads, + * parser=self.parser, # <<<<<<<<<<<<<< + * index=self.filename_index, + * encoding=self.encoding) + */ + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_parser, ((PyObject *)__pyx_v_self->parser)) < 0) __PYX_ERR(0, 412, __pyx_L1_error) + + /* "pysam/libctabix.pyx":415 + * threads=self.threads, + * parser=self.parser, + * index=self.filename_index, # <<<<<<<<<<<<<< + * encoding=self.encoding) + * + */ + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_index, __pyx_v_self->filename_index) < 0) __PYX_ERR(0, 412, __pyx_L1_error) + + /* "pysam/libctabix.pyx":416 + * parser=self.parser, + * index=self.filename_index, + * encoding=self.encoding) # <<<<<<<<<<<<<< + * + * def fetch(self, + */ + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_encoding, __pyx_v_self->encoding) < 0) __PYX_ERR(0, 412, __pyx_L1_error) + + /* "pysam/libctabix.pyx":411 + * The file is being re-opened. + * ''' + * return TabixFile(self.filename, # <<<<<<<<<<<<<< + * mode="r", + * threads=self.threads, + */ + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_9libctabix_TabixFile), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 411, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "pysam/libctabix.pyx":406 + * self.start_offset = self.tell() + * + * def _dup(self): # <<<<<<<<<<<<<< + * '''return a copy of this tabix file. + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libctabix.TabixFile._dup", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libctabix.pyx":418 + * encoding=self.encoding) + * + * def fetch(self, # <<<<<<<<<<<<<< + * reference=None, + * start=None, + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_7fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_9TabixFile_6fetch[] = "TabixFile.fetch(self, reference=None, start=None, end=None, region=None, parser=None, multiple_iterators=False)\nfetch one or more rows in a :term:`region` using 0-based\n indexing. The region is specified by :term:`reference`,\n *start* and *end*. Alternatively, a samtools :term:`region`\n string can be supplied.\n\n Without *reference* or *region* all entries will be fetched. \n \n If only *reference* is set, all reads matching on *reference*\n will be fetched.\n\n If *parser* is None, the default parser will be used for\n parsing.\n \n Set *multiple_iterators* to true if you will be using multiple\n iterators on the same file at the same time. The iterator\n returned will receive its own copy of a filehandle to the file\n effectively re-opening the file. Re-opening a file creates\n some overhead, so beware.\n\n "; +static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_7fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_reference = 0; + PyObject *__pyx_v_start = 0; + PyObject *__pyx_v_end = 0; + PyObject *__pyx_v_region = 0; + PyObject *__pyx_v_parser = 0; + PyObject *__pyx_v_multiple_iterators = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("fetch (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,&__pyx_n_s_parser,&__pyx_n_s_multiple_iterators,0}; + PyObject* values[6] = {0,0,0,0,0,0}; + + /* "pysam/libctabix.pyx":419 + * + * def fetch(self, + * reference=None, # <<<<<<<<<<<<<< + * start=None, + * end=None, + */ + values[0] = ((PyObject *)Py_None); + + /* "pysam/libctabix.pyx":420 + * def fetch(self, + * reference=None, + * start=None, # <<<<<<<<<<<<<< + * end=None, + * region=None, + */ + values[1] = ((PyObject *)Py_None); + + /* "pysam/libctabix.pyx":421 + * reference=None, + * start=None, + * end=None, # <<<<<<<<<<<<<< + * region=None, + * parser=None, + */ + values[2] = ((PyObject *)Py_None); + + /* "pysam/libctabix.pyx":422 + * start=None, + * end=None, + * region=None, # <<<<<<<<<<<<<< + * parser=None, + * multiple_iterators=False): + */ + values[3] = ((PyObject *)Py_None); + + /* "pysam/libctabix.pyx":423 + * end=None, + * region=None, + * parser=None, # <<<<<<<<<<<<<< + * multiple_iterators=False): + * '''fetch one or more rows in a :term:`region` using 0-based + */ + values[4] = ((PyObject *)Py_None); + + /* "pysam/libctabix.pyx":424 + * region=None, + * parser=None, + * multiple_iterators=False): # <<<<<<<<<<<<<< + * '''fetch one or more rows in a :term:`region` using 0-based + * indexing. The region is specified by :term:`reference`, + */ + values[5] = ((PyObject *)Py_False); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); + if (value) { values[0] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start); + if (value) { values[1] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); + if (value) { values[2] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region); + if (value) { values[3] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 4: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_parser); + if (value) { values[4] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 5: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators); + if (value) { values[5] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 418, __pyx_L3_error) + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_reference = values[0]; + __pyx_v_start = values[1]; + __pyx_v_end = values[2]; + __pyx_v_region = values[3]; + __pyx_v_parser = values[4]; + __pyx_v_multiple_iterators = values[5]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 418, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libctabix.TabixFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_9libctabix_9TabixFile_6fetch(((struct __pyx_obj_5pysam_9libctabix_TabixFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_parser, __pyx_v_multiple_iterators); -/* "pysam/libctabix.pyx":357 - * self.start_offset = self.tell() - * - * def _dup(self): # <<<<<<<<<<<<<< - * '''return a copy of this tabix file. + /* "pysam/libctabix.pyx":418 + * encoding=self.encoding) * + * def fetch(self, # <<<<<<<<<<<<<< + * reference=None, + * start=None, */ -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_5_dup(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_9TabixFile_4_dup[] = "TabixFile._dup(self)\nreturn a copy of this tabix file.\n \n The file is being re-opened.\n "; -static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_5_dup(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_dup (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libctabix_9TabixFile_4_dup(((struct __pyx_obj_5pysam_9libctabix_TabixFile *)__pyx_v_self)); - /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_4_dup(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_6fetch(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_parser, PyObject *__pyx_v_multiple_iterators) { + hts_itr_t *__pyx_v_itr; + char *__pyx_v_cstr; + struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_fileobj = 0; + PyObject *__pyx_v_s = NULL; + struct __pyx_obj_5pysam_9libctabix_TabixIterator *__pyx_v_a = 0; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("_dup", 0); - __Pyx_TraceCall("_dup", __pyx_f[0], 357, 0, __PYX_ERR(0, 357, __pyx_L1_error)); + int __pyx_t_4; + int __pyx_t_5; + struct __pyx_opt_args_5pysam_9libcutils_force_bytes __pyx_t_6; + char *__pyx_t_7; + Py_ssize_t __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("fetch", 0); + __Pyx_TraceCall("fetch", __pyx_f[0], 418, 0, __PYX_ERR(0, 418, __pyx_L1_error)); + __Pyx_INCREF(__pyx_v_start); + __Pyx_INCREF(__pyx_v_region); + __Pyx_INCREF(__pyx_v_parser); - /* "pysam/libctabix.pyx":362 - * The file is being re-opened. + /* "pysam/libctabix.pyx":445 + * * ''' - * return TabixFile(self.filename, # <<<<<<<<<<<<<< - * mode="r", - * parser=self.parser, + * if not self.is_open(): # <<<<<<<<<<<<<< + * raise ValueError("I/O operation on closed file") + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 362, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 445, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 445, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 445, __pyx_L1_error) + } __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_self->__pyx_base.filename); - __Pyx_GIVEREF(__pyx_v_self->__pyx_base.filename); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->__pyx_base.filename); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 445, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = ((!__pyx_t_4) != 0); + if (unlikely(__pyx_t_5)) { - /* "pysam/libctabix.pyx":363 + /* "pysam/libctabix.pyx":446 * ''' - * return TabixFile(self.filename, - * mode="r", # <<<<<<<<<<<<<< - * parser=self.parser, - * index=self.filename_index, + * if not self.is_open(): + * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< + * + * # convert coordinates to region string, which is one-based */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_mode, __pyx_n_s_r) < 0) __PYX_ERR(0, 363, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 446, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 446, __pyx_L1_error) - /* "pysam/libctabix.pyx":364 - * return TabixFile(self.filename, - * mode="r", - * parser=self.parser, # <<<<<<<<<<<<<< - * index=self.filename_index, - * encoding=self.encoding) + /* "pysam/libctabix.pyx":445 + * + * ''' + * if not self.is_open(): # <<<<<<<<<<<<<< + * raise ValueError("I/O operation on closed file") + * */ - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_parser, ((PyObject *)__pyx_v_self->parser)) < 0) __PYX_ERR(0, 363, __pyx_L1_error) + } - /* "pysam/libctabix.pyx":365 - * mode="r", - * parser=self.parser, - * index=self.filename_index, # <<<<<<<<<<<<<< - * encoding=self.encoding) + /* "pysam/libctabix.pyx":449 * + * # convert coordinates to region string, which is one-based + * if reference: # <<<<<<<<<<<<<< + * if end is not None: + * if end < 0: */ - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_index, __pyx_v_self->filename_index) < 0) __PYX_ERR(0, 363, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 449, __pyx_L1_error) + if (__pyx_t_5) { - /* "pysam/libctabix.pyx":366 - * parser=self.parser, - * index=self.filename_index, - * encoding=self.encoding) # <<<<<<<<<<<<<< - * - * def fetch(self, + /* "pysam/libctabix.pyx":450 + * # convert coordinates to region string, which is one-based + * if reference: + * if end is not None: # <<<<<<<<<<<<<< + * if end < 0: + * raise ValueError("end out of range (%i)" % end) */ - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_encoding, __pyx_v_self->encoding) < 0) __PYX_ERR(0, 363, __pyx_L1_error) + __pyx_t_5 = (__pyx_v_end != Py_None); + __pyx_t_4 = (__pyx_t_5 != 0); + if (__pyx_t_4) { - /* "pysam/libctabix.pyx":362 - * The file is being re-opened. - * ''' - * return TabixFile(self.filename, # <<<<<<<<<<<<<< - * mode="r", - * parser=self.parser, + /* "pysam/libctabix.pyx":451 + * if reference: + * if end is not None: + * if end < 0: # <<<<<<<<<<<<<< + * raise ValueError("end out of range (%i)" % end) + * if start is None: */ - __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_9libctabix_TabixFile), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 362, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __pyx_t_1 = PyObject_RichCompare(__pyx_v_end, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 451, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 451, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(__pyx_t_4)) { - /* "pysam/libctabix.pyx":357 - * self.start_offset = self.tell() + /* "pysam/libctabix.pyx":452 + * if end is not None: + * if end < 0: + * raise ValueError("end out of range (%i)" % end) # <<<<<<<<<<<<<< + * if start is None: + * start = 0 + */ + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_end_out_of_range_i, __pyx_v_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 452, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 452, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 452, __pyx_L1_error) + + /* "pysam/libctabix.pyx":451 + * if reference: + * if end is not None: + * if end < 0: # <<<<<<<<<<<<<< + * raise ValueError("end out of range (%i)" % end) + * if start is None: + */ + } + + /* "pysam/libctabix.pyx":453 + * if end < 0: + * raise ValueError("end out of range (%i)" % end) + * if start is None: # <<<<<<<<<<<<<< + * start = 0 * - * def _dup(self): # <<<<<<<<<<<<<< - * '''return a copy of this tabix file. + */ + __pyx_t_4 = (__pyx_v_start == Py_None); + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { + + /* "pysam/libctabix.pyx":454 + * raise ValueError("end out of range (%i)" % end) + * if start is None: + * start = 0 # <<<<<<<<<<<<<< * + * if start < 0: */ + __Pyx_INCREF(__pyx_int_0); + __Pyx_DECREF_SET(__pyx_v_start, __pyx_int_0); - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libctabix.TabixFile._dup", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libctabix.pyx":453 + * if end < 0: + * raise ValueError("end out of range (%i)" % end) + * if start is None: # <<<<<<<<<<<<<< + * start = 0 + * + */ + } -/* "pysam/libctabix.pyx":368 - * encoding=self.encoding) + /* "pysam/libctabix.pyx":456 + * start = 0 * - * def fetch(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * if start < 0: # <<<<<<<<<<<<<< + * raise ValueError("start out of range (%i)" % end) + * elif start > end: */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 456, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 456, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(__pyx_t_5)) { -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_7fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_9TabixFile_6fetch[] = "TabixFile.fetch(self, reference=None, start=None, end=None, region=None, parser=None, multiple_iterators=False)\nfetch one or more rows in a :term:`region` using 0-based\n indexing. The region is specified by :term:`reference`,\n *start* and *end*. Alternatively, a samtools :term:`region`\n string can be supplied.\n\n Without *reference* or *region* all entries will be fetched. \n \n If only *reference* is set, all reads matching on *reference*\n will be fetched.\n\n If *parser* is None, the default parser will be used for\n parsing.\n \n Set *multiple_iterators* to true if you will be using multiple\n iterators on the same file at the same time. The iterator\n returned will receive its own copy of a filehandle to the file\n effectively re-opening the file. Re-opening a file creates\n some overhead, so beware.\n\n "; -static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_7fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_reference = 0; - PyObject *__pyx_v_start = 0; - PyObject *__pyx_v_end = 0; - PyObject *__pyx_v_region = 0; - PyObject *__pyx_v_parser = 0; - PyObject *__pyx_v_multiple_iterators = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fetch (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,&__pyx_n_s_parser,&__pyx_n_s_multiple_iterators,0}; - PyObject* values[6] = {0,0,0,0,0,0}; + /* "pysam/libctabix.pyx":457 + * + * if start < 0: + * raise ValueError("start out of range (%i)" % end) # <<<<<<<<<<<<<< + * elif start > end: + * raise ValueError( + */ + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_v_end); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 457, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 457, __pyx_L1_error) - /* "pysam/libctabix.pyx":369 + /* "pysam/libctabix.pyx":456 + * start = 0 * - * def fetch(self, - * reference=None, # <<<<<<<<<<<<<< - * start=None, - * end=None, + * if start < 0: # <<<<<<<<<<<<<< + * raise ValueError("start out of range (%i)" % end) + * elif start > end: */ - values[0] = ((PyObject *)Py_None); + } - /* "pysam/libctabix.pyx":370 - * def fetch(self, - * reference=None, - * start=None, # <<<<<<<<<<<<<< - * end=None, - * region=None, + /* "pysam/libctabix.pyx":458 + * if start < 0: + * raise ValueError("start out of range (%i)" % end) + * elif start > end: # <<<<<<<<<<<<<< + * raise ValueError( + * 'start (%i) >= end (%i)' % (start, end)) */ - values[1] = ((PyObject *)Py_None); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 458, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 458, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(__pyx_t_5)) { - /* "pysam/libctabix.pyx":371 - * reference=None, - * start=None, - * end=None, # <<<<<<<<<<<<<< - * region=None, - * parser=None, + /* "pysam/libctabix.pyx":460 + * elif start > end: + * raise ValueError( + * 'start (%i) >= end (%i)' % (start, end)) # <<<<<<<<<<<<<< + * elif start == end: + * return EmptyIterator() */ - values[2] = ((PyObject *)Py_None); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 460, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_start); + __Pyx_GIVEREF(__pyx_v_start); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_start); + __Pyx_INCREF(__pyx_v_end); + __Pyx_GIVEREF(__pyx_v_end); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_end); + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_start_i_end_i, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 460, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":372 - * start=None, - * end=None, - * region=None, # <<<<<<<<<<<<<< - * parser=None, - * multiple_iterators=False): + /* "pysam/libctabix.pyx":459 + * raise ValueError("start out of range (%i)" % end) + * elif start > end: + * raise ValueError( # <<<<<<<<<<<<<< + * 'start (%i) >= end (%i)' % (start, end)) + * elif start == end: */ - values[3] = ((PyObject *)Py_None); + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 459, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 459, __pyx_L1_error) - /* "pysam/libctabix.pyx":373 - * end=None, - * region=None, - * parser=None, # <<<<<<<<<<<<<< - * multiple_iterators=False): - * '''fetch one or more rows in a :term:`region` using 0-based + /* "pysam/libctabix.pyx":458 + * if start < 0: + * raise ValueError("start out of range (%i)" % end) + * elif start > end: # <<<<<<<<<<<<<< + * raise ValueError( + * 'start (%i) >= end (%i)' % (start, end)) */ - values[4] = ((PyObject *)Py_None); + } - /* "pysam/libctabix.pyx":374 - * region=None, - * parser=None, - * multiple_iterators=False): # <<<<<<<<<<<<<< - * '''fetch one or more rows in a :term:`region` using 0-based - * indexing. The region is specified by :term:`reference`, + /* "pysam/libctabix.pyx":461 + * raise ValueError( + * 'start (%i) >= end (%i)' % (start, end)) + * elif start == end: # <<<<<<<<<<<<<< + * return EmptyIterator() + * else: */ - values[5] = ((PyObject *)Py_False); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_reference); - if (value) { values[0] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 1: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start); - if (value) { values[1] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 2: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_end); - if (value) { values[2] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 3: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_region); - if (value) { values[3] = value; kw_args--; } - } - CYTHON_FALLTHROUGH; - case 4: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_parser); - if (value) { values[4] = value; kw_args--; } + __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 461, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 461, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_5) { + + /* "pysam/libctabix.pyx":462 + * 'start (%i) >= end (%i)' % (start, end)) + * elif start == end: + * return EmptyIterator() # <<<<<<<<<<<<<< + * else: + * region = '%s:%i-%i' % (reference, start + 1, end) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_EmptyIterator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 462, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } } - CYTHON_FALLTHROUGH; - case 5: - if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_multiple_iterators); - if (value) { values[5] = value; kw_args--; } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 462, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 462, __pyx_L1_error) } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libctabix.pyx":461 + * raise ValueError( + * 'start (%i) >= end (%i)' % (start, end)) + * elif start == end: # <<<<<<<<<<<<<< + * return EmptyIterator() + * else: + */ } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) __PYX_ERR(0, 368, __pyx_L3_error) - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - CYTHON_FALLTHROUGH; - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - CYTHON_FALLTHROUGH; - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - CYTHON_FALLTHROUGH; - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - CYTHON_FALLTHROUGH; - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; + + /* "pysam/libctabix.pyx":464 + * return EmptyIterator() + * else: + * region = '%s:%i-%i' % (reference, start + 1, end) # <<<<<<<<<<<<<< + * elif start is not None: + * if start < 0: + */ + /*else*/ { + __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_start, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 464, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 464, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_reference); + __Pyx_GIVEREF(__pyx_v_reference); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_reference); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_v_end); + __Pyx_GIVEREF(__pyx_v_end); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_end); + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s_i_i, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 464, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF_SET(__pyx_v_region, __pyx_t_1); + __pyx_t_1 = 0; } + + /* "pysam/libctabix.pyx":450 + * # convert coordinates to region string, which is one-based + * if reference: + * if end is not None: # <<<<<<<<<<<<<< + * if end < 0: + * raise ValueError("end out of range (%i)" % end) + */ + goto __pyx_L5; } - __pyx_v_reference = values[0]; - __pyx_v_start = values[1]; - __pyx_v_end = values[2]; - __pyx_v_region = values[3]; - __pyx_v_parser = values[4]; - __pyx_v_multiple_iterators = values[5]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 368, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libctabix.TabixFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libctabix_9TabixFile_6fetch(((struct __pyx_obj_5pysam_9libctabix_TabixFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_parser, __pyx_v_multiple_iterators); - /* "pysam/libctabix.pyx":368 - * encoding=self.encoding) - * - * def fetch(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + /* "pysam/libctabix.pyx":465 + * else: + * region = '%s:%i-%i' % (reference, start + 1, end) + * elif start is not None: # <<<<<<<<<<<<<< + * if start < 0: + * raise ValueError("start out of range (%i)" % end) + */ + __pyx_t_5 = (__pyx_v_start != Py_None); + __pyx_t_4 = (__pyx_t_5 != 0); + if (__pyx_t_4) { + + /* "pysam/libctabix.pyx":466 + * region = '%s:%i-%i' % (reference, start + 1, end) + * elif start is not None: + * if start < 0: # <<<<<<<<<<<<<< + * raise ValueError("start out of range (%i)" % end) + * region = '%s:%i' % (reference, start + 1) + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 466, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 466, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(__pyx_t_4)) { + + /* "pysam/libctabix.pyx":467 + * elif start is not None: + * if start < 0: + * raise ValueError("start out of range (%i)" % end) # <<<<<<<<<<<<<< + * region = '%s:%i' % (reference, start + 1) + * else: + */ + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_v_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 467, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 467, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 467, __pyx_L1_error) + + /* "pysam/libctabix.pyx":466 + * region = '%s:%i-%i' % (reference, start + 1, end) + * elif start is not None: + * if start < 0: # <<<<<<<<<<<<<< + * raise ValueError("start out of range (%i)" % end) + * region = '%s:%i' % (reference, start + 1) */ + } - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libctabix.pyx":468 + * if start < 0: + * raise ValueError("start out of range (%i)" % end) + * region = '%s:%i' % (reference, start + 1) # <<<<<<<<<<<<<< + * else: + * region = reference + */ + __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_start, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 468, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 468, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_reference); + __Pyx_GIVEREF(__pyx_v_reference); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_i, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 468, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_region, __pyx_t_2); + __pyx_t_2 = 0; -static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_6fetch(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_parser, PyObject *__pyx_v_multiple_iterators) { - hts_itr_t *__pyx_v_itr; - char *__pyx_v_cstr; - struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_fileobj = 0; - PyObject *__pyx_v_s = NULL; - struct __pyx_obj_5pysam_9libctabix_TabixIterator *__pyx_v_a = 0; - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_t_5; - struct __pyx_opt_args_5pysam_9libcutils_force_bytes __pyx_t_6; - char *__pyx_t_7; - Py_ssize_t __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - __Pyx_RefNannySetupContext("fetch", 0); - __Pyx_TraceCall("fetch", __pyx_f[0], 368, 0, __PYX_ERR(0, 368, __pyx_L1_error)); - __Pyx_INCREF(__pyx_v_start); - __Pyx_INCREF(__pyx_v_region); - __Pyx_INCREF(__pyx_v_parser); + /* "pysam/libctabix.pyx":465 + * else: + * region = '%s:%i-%i' % (reference, start + 1, end) + * elif start is not None: # <<<<<<<<<<<<<< + * if start < 0: + * raise ValueError("start out of range (%i)" % end) + */ + goto __pyx_L5; + } - /* "pysam/libctabix.pyx":395 - * - * ''' - * if not self.is_open(): # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") + /* "pysam/libctabix.pyx":470 + * region = '%s:%i' % (reference, start + 1) + * else: + * region = reference # <<<<<<<<<<<<<< * + * # get iterator */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 395, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); + /*else*/ { + __Pyx_INCREF(__pyx_v_reference); + __Pyx_DECREF_SET(__pyx_v_region, __pyx_v_reference); } - } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 395, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = ((!__pyx_t_4) != 0); - if (unlikely(__pyx_t_5)) { + __pyx_L5:; - /* "pysam/libctabix.pyx":396 - * ''' - * if not self.is_open(): - * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":449 * * # convert coordinates to region string, which is one-based + * if reference: # <<<<<<<<<<<<<< + * if end is not None: + * if end < 0: + */ + } + + /* "pysam/libctabix.pyx":478 + * + * # reopen the same file if necessary + * if multiple_iterators: # <<<<<<<<<<<<<< + * fileobj = self._dup() + * else: + */ + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_multiple_iterators); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 478, __pyx_L1_error) + if (__pyx_t_4) { + + /* "pysam/libctabix.pyx":479 + * # reopen the same file if necessary + * if multiple_iterators: + * fileobj = self._dup() # <<<<<<<<<<<<<< + * else: + * fileobj = self */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 396, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dup); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 479, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + if (__pyx_t_3) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 479, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 479, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 396, __pyx_L1_error) + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5pysam_9libctabix_TabixFile))))) __PYX_ERR(0, 479, __pyx_L1_error) + __pyx_v_fileobj = ((struct __pyx_obj_5pysam_9libctabix_TabixFile *)__pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":395 + /* "pysam/libctabix.pyx":478 * - * ''' - * if not self.is_open(): # <<<<<<<<<<<<<< - * raise ValueError("I/O operation on closed file") + * # reopen the same file if necessary + * if multiple_iterators: # <<<<<<<<<<<<<< + * fileobj = self._dup() + * else: + */ + goto __pyx_L10; + } + + /* "pysam/libctabix.pyx":481 + * fileobj = self._dup() + * else: + * fileobj = self # <<<<<<<<<<<<<< * + * if region is None: */ + /*else*/ { + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_v_fileobj = __pyx_v_self; } + __pyx_L10:; - /* "pysam/libctabix.pyx":399 + /* "pysam/libctabix.pyx":483 + * fileobj = self * - * # convert coordinates to region string, which is one-based - * if reference: # <<<<<<<<<<<<<< - * if end is not None: - * if end < 0: + * if region is None: # <<<<<<<<<<<<<< + * # without region or reference - iterate from start + * with nogil: */ - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 399, __pyx_L1_error) + __pyx_t_4 = (__pyx_v_region == Py_None); + __pyx_t_5 = (__pyx_t_4 != 0); if (__pyx_t_5) { - /* "pysam/libctabix.pyx":400 - * # convert coordinates to region string, which is one-based - * if reference: - * if end is not None: # <<<<<<<<<<<<<< - * if end < 0: - * raise ValueError("end out of range (%i)" % end) + /* "pysam/libctabix.pyx":485 + * if region is None: + * # without region or reference - iterate from start + * with nogil: # <<<<<<<<<<<<<< + * itr = tbx_itr_queryi(fileobj.index, + * HTS_IDX_START, */ - __pyx_t_5 = (__pyx_v_end != Py_None); - __pyx_t_4 = (__pyx_t_5 != 0); - if (__pyx_t_4) { + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libctabix.pyx":401 - * if reference: - * if end is not None: - * if end < 0: # <<<<<<<<<<<<<< - * raise ValueError("end out of range (%i)" % end) - * if start is None: + /* "pysam/libctabix.pyx":486 + * # without region or reference - iterate from start + * with nogil: + * itr = tbx_itr_queryi(fileobj.index, # <<<<<<<<<<<<<< + * HTS_IDX_START, + * 0, */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_end, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 401, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 401, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(__pyx_t_4)) { + __pyx_v_itr = tbx_itr_queryi(__pyx_v_fileobj->index, HTS_IDX_START, 0, 0); + } - /* "pysam/libctabix.pyx":402 - * if end is not None: - * if end < 0: - * raise ValueError("end out of range (%i)" % end) # <<<<<<<<<<<<<< - * if start is None: - * start = 0 + /* "pysam/libctabix.pyx":485 + * if region is None: + * # without region or reference - iterate from start + * with nogil: # <<<<<<<<<<<<<< + * itr = tbx_itr_queryi(fileobj.index, + * HTS_IDX_START, */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_end_out_of_range_i, __pyx_v_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 402, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 402, __pyx_L1_error) + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L14; + } + __pyx_L14:; + } + } - /* "pysam/libctabix.pyx":401 - * if reference: - * if end is not None: - * if end < 0: # <<<<<<<<<<<<<< - * raise ValueError("end out of range (%i)" % end) - * if start is None: + /* "pysam/libctabix.pyx":483 + * fileobj = self + * + * if region is None: # <<<<<<<<<<<<<< + * # without region or reference - iterate from start + * with nogil: */ - } + goto __pyx_L11; + } + + /* "pysam/libctabix.pyx":491 + * 0) + * else: + * s = force_bytes(region, encoding=fileobj.encoding) # <<<<<<<<<<<<<< + * cstr = s + * with nogil: + */ + /*else*/ { + __pyx_t_2 = __pyx_v_fileobj->encoding; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_6.__pyx_n = 1; + __pyx_t_6.encoding = __pyx_t_2; + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_region, &__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_s = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":403 - * if end < 0: - * raise ValueError("end out of range (%i)" % end) - * if start is None: # <<<<<<<<<<<<<< - * start = 0 - * + /* "pysam/libctabix.pyx":492 + * else: + * s = force_bytes(region, encoding=fileobj.encoding) + * cstr = s # <<<<<<<<<<<<<< + * with nogil: + * itr = tbx_itr_querys(fileobj.index, cstr) */ - __pyx_t_4 = (__pyx_v_start == Py_None); - __pyx_t_5 = (__pyx_t_4 != 0); - if (__pyx_t_5) { + if (unlikely(__pyx_v_s == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 492, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_s); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 492, __pyx_L1_error) + __pyx_v_cstr = __pyx_t_7; - /* "pysam/libctabix.pyx":404 - * raise ValueError("end out of range (%i)" % end) - * if start is None: - * start = 0 # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":493 + * s = force_bytes(region, encoding=fileobj.encoding) + * cstr = s + * with nogil: # <<<<<<<<<<<<<< + * itr = tbx_itr_querys(fileobj.index, cstr) * - * if start < 0: */ - __Pyx_INCREF(__pyx_int_0); - __Pyx_DECREF_SET(__pyx_v_start, __pyx_int_0); + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libctabix.pyx":403 - * if end < 0: - * raise ValueError("end out of range (%i)" % end) - * if start is None: # <<<<<<<<<<<<<< - * start = 0 + /* "pysam/libctabix.pyx":494 + * cstr = s + * with nogil: + * itr = tbx_itr_querys(fileobj.index, cstr) # <<<<<<<<<<<<<< * + * if itr == NULL: */ - } + __pyx_v_itr = tbx_itr_querys(__pyx_v_fileobj->index, __pyx_v_cstr); + } - /* "pysam/libctabix.pyx":406 - * start = 0 + /* "pysam/libctabix.pyx":493 + * s = force_bytes(region, encoding=fileobj.encoding) + * cstr = s + * with nogil: # <<<<<<<<<<<<<< + * itr = tbx_itr_querys(fileobj.index, cstr) * - * if start < 0: # <<<<<<<<<<<<<< - * raise ValueError("start out of range (%i)" % end) - * elif start > end: */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 406, __pyx_L1_error) - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 406, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (unlikely(__pyx_t_5)) { + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L17; + } + __pyx_L17:; + } + } + } + __pyx_L11:; - /* "pysam/libctabix.pyx":407 + /* "pysam/libctabix.pyx":496 + * itr = tbx_itr_querys(fileobj.index, cstr) * - * if start < 0: - * raise ValueError("start out of range (%i)" % end) # <<<<<<<<<<<<<< - * elif start > end: - * raise ValueError( + * if itr == NULL: # <<<<<<<<<<<<<< + * if region is None: + * if len(self.contigs) > 0: */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_v_end); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 407, __pyx_L1_error) + __pyx_t_5 = ((__pyx_v_itr == NULL) != 0); + if (__pyx_t_5) { - /* "pysam/libctabix.pyx":406 - * start = 0 + /* "pysam/libctabix.pyx":497 * - * if start < 0: # <<<<<<<<<<<<<< - * raise ValueError("start out of range (%i)" % end) - * elif start > end: + * if itr == NULL: + * if region is None: # <<<<<<<<<<<<<< + * if len(self.contigs) > 0: + * # when accessing a tabix file created prior tabix 1.0 */ - } + __pyx_t_5 = (__pyx_v_region == Py_None); + __pyx_t_4 = (__pyx_t_5 != 0); + if (likely(__pyx_t_4)) { - /* "pysam/libctabix.pyx":408 - * if start < 0: - * raise ValueError("start out of range (%i)" % end) - * elif start > end: # <<<<<<<<<<<<<< - * raise ValueError( - * 'start (%i) >= end (%i)' % (start, end)) + /* "pysam/libctabix.pyx":498 + * if itr == NULL: + * if region is None: + * if len(self.contigs) > 0: # <<<<<<<<<<<<<< + * # when accessing a tabix file created prior tabix 1.0 + * # the full-file iterator is empty. */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 408, __pyx_L1_error) - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 408, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contigs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 498, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 498, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(__pyx_t_5)) { - - /* "pysam/libctabix.pyx":410 - * elif start > end: - * raise ValueError( - * 'start (%i) >= end (%i)' % (start, end)) # <<<<<<<<<<<<<< - * elif start == end: - * return EmptyIterator() - */ - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 410, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_start); - __Pyx_GIVEREF(__pyx_v_start); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_start); - __Pyx_INCREF(__pyx_v_end); - __Pyx_GIVEREF(__pyx_v_end); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_end); - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_start_i_end_i, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 410, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = ((__pyx_t_8 > 0) != 0); + if (unlikely(__pyx_t_4)) { - /* "pysam/libctabix.pyx":409 - * raise ValueError("start out of range (%i)" % end) - * elif start > end: + /* "pysam/libctabix.pyx":501 + * # when accessing a tabix file created prior tabix 1.0 + * # the full-file iterator is empty. * raise ValueError( # <<<<<<<<<<<<<< - * 'start (%i) >= end (%i)' % (start, end)) - * elif start == end: + * "could not create iterator, possible " + * "tabix version mismatch") */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 409, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 501, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 409, __pyx_L1_error) + __PYX_ERR(0, 501, __pyx_L1_error) - /* "pysam/libctabix.pyx":408 - * if start < 0: - * raise ValueError("start out of range (%i)" % end) - * elif start > end: # <<<<<<<<<<<<<< - * raise ValueError( - * 'start (%i) >= end (%i)' % (start, end)) + /* "pysam/libctabix.pyx":498 + * if itr == NULL: + * if region is None: + * if len(self.contigs) > 0: # <<<<<<<<<<<<<< + * # when accessing a tabix file created prior tabix 1.0 + * # the full-file iterator is empty. */ } - /* "pysam/libctabix.pyx":411 - * raise ValueError( - * 'start (%i) >= end (%i)' % (start, end)) - * elif start == end: # <<<<<<<<<<<<<< - * return EmptyIterator() - * else: - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 411, __pyx_L1_error) - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 411, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_5) { - - /* "pysam/libctabix.pyx":412 - * 'start (%i) >= end (%i)' % (start, end)) - * elif start == end: + /* "pysam/libctabix.pyx":507 + * # possible reason is that the file is empty - + * # return an empty iterator * return EmptyIterator() # <<<<<<<<<<<<<< - * else: - * region = '%s:%i-%i' % (reference, start + 1, end) + * else: + * raise ValueError( */ + /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_EmptyIterator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 412, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_EmptyIterator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 507, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { @@ -6882,815 +7854,796 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_6fetch(struct __pyx_obj_5 } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 412, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 507, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 412, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 507, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - - /* "pysam/libctabix.pyx":411 - * raise ValueError( - * 'start (%i) >= end (%i)' % (start, end)) - * elif start == end: # <<<<<<<<<<<<<< - * return EmptyIterator() - * else: - */ - } - - /* "pysam/libctabix.pyx":414 - * return EmptyIterator() - * else: - * region = '%s:%i-%i' % (reference, start + 1, end) # <<<<<<<<<<<<<< - * elif start is not None: - * if start < 0: - */ - /*else*/ { - __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_start, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_reference); - __Pyx_GIVEREF(__pyx_v_reference); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_reference); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); - __Pyx_INCREF(__pyx_v_end); - __Pyx_GIVEREF(__pyx_v_end); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_end); - __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s_i_i, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_region, __pyx_t_1); - __pyx_t_1 = 0; } - /* "pysam/libctabix.pyx":400 - * # convert coordinates to region string, which is one-based - * if reference: - * if end is not None: # <<<<<<<<<<<<<< - * if end < 0: - * raise ValueError("end out of range (%i)" % end) + /* "pysam/libctabix.pyx":497 + * + * if itr == NULL: + * if region is None: # <<<<<<<<<<<<<< + * if len(self.contigs) > 0: + * # when accessing a tabix file created prior tabix 1.0 */ - goto __pyx_L5; } - /* "pysam/libctabix.pyx":415 - * else: - * region = '%s:%i-%i' % (reference, start + 1, end) - * elif start is not None: # <<<<<<<<<<<<<< - * if start < 0: - * raise ValueError("start out of range (%i)" % end) - */ - __pyx_t_5 = (__pyx_v_start != Py_None); - __pyx_t_4 = (__pyx_t_5 != 0); - if (__pyx_t_4) { - - /* "pysam/libctabix.pyx":416 - * region = '%s:%i-%i' % (reference, start + 1, end) - * elif start is not None: - * if start < 0: # <<<<<<<<<<<<<< - * raise ValueError("start out of range (%i)" % end) - * region = '%s:%i' % (reference, start + 1) - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 416, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 416, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(__pyx_t_4)) { - - /* "pysam/libctabix.pyx":417 - * elif start is not None: - * if start < 0: - * raise ValueError("start out of range (%i)" % end) # <<<<<<<<<<<<<< - * region = '%s:%i' % (reference, start + 1) + /* "pysam/libctabix.pyx":509 + * return EmptyIterator() * else: + * raise ValueError( # <<<<<<<<<<<<<< + * "could not create iterator for region '%s'" % + * region) */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_v_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 417, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 417, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 417, __pyx_L1_error) + /*else*/ { - /* "pysam/libctabix.pyx":416 - * region = '%s:%i-%i' % (reference, start + 1, end) - * elif start is not None: - * if start < 0: # <<<<<<<<<<<<<< - * raise ValueError("start out of range (%i)" % end) - * region = '%s:%i' % (reference, start + 1) + /* "pysam/libctabix.pyx":510 + * else: + * raise ValueError( + * "could not create iterator for region '%s'" % # <<<<<<<<<<<<<< + * region) + * */ - } + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_could_not_create_iterator_for_re, __pyx_v_region); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 510, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libctabix.pyx":418 - * if start < 0: - * raise ValueError("start out of range (%i)" % end) - * region = '%s:%i' % (reference, start + 1) # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":509 + * return EmptyIterator() * else: - * region = reference + * raise ValueError( # <<<<<<<<<<<<<< + * "could not create iterator for region '%s'" % + * region) */ - __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_start, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 418, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 418, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_reference); - __Pyx_GIVEREF(__pyx_v_reference); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_i, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 418, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 509, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_region, __pyx_t_2); - __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 509, __pyx_L1_error) + } - /* "pysam/libctabix.pyx":415 - * else: - * region = '%s:%i-%i' % (reference, start + 1, end) - * elif start is not None: # <<<<<<<<<<<<<< - * if start < 0: - * raise ValueError("start out of range (%i)" % end) + /* "pysam/libctabix.pyx":496 + * itr = tbx_itr_querys(fileobj.index, cstr) + * + * if itr == NULL: # <<<<<<<<<<<<<< + * if region is None: + * if len(self.contigs) > 0: */ - goto __pyx_L5; - } + } - /* "pysam/libctabix.pyx":420 - * region = '%s:%i' % (reference, start + 1) - * else: - * region = reference # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":514 + * + * # use default parser if no parser is specified + * if parser is None: # <<<<<<<<<<<<<< + * parser = fileobj.parser * - * # get iterator */ - /*else*/ { - __Pyx_INCREF(__pyx_v_reference); - __Pyx_DECREF_SET(__pyx_v_region, __pyx_v_reference); - } - __pyx_L5:; + __pyx_t_4 = (__pyx_v_parser == Py_None); + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { - /* "pysam/libctabix.pyx":399 + /* "pysam/libctabix.pyx":515 + * # use default parser if no parser is specified + * if parser is None: + * parser = fileobj.parser # <<<<<<<<<<<<<< + * + * cdef TabixIterator a + */ + __pyx_t_2 = ((PyObject *)__pyx_v_fileobj->parser); + __Pyx_INCREF(__pyx_t_2); + __Pyx_DECREF_SET(__pyx_v_parser, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pysam/libctabix.pyx":514 + * + * # use default parser if no parser is specified + * if parser is None: # <<<<<<<<<<<<<< + * parser = fileobj.parser * - * # convert coordinates to region string, which is one-based - * if reference: # <<<<<<<<<<<<<< - * if end is not None: - * if end < 0: */ } - /* "pysam/libctabix.pyx":428 + /* "pysam/libctabix.pyx":518 * - * # reopen the same file if necessary - * if multiple_iterators: # <<<<<<<<<<<<<< - * fileobj = self._dup() + * cdef TabixIterator a + * if parser is None: # <<<<<<<<<<<<<< + * a = TabixIterator(encoding=fileobj.encoding) * else: */ - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_multiple_iterators); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 428, __pyx_L1_error) + __pyx_t_5 = (__pyx_v_parser == Py_None); + __pyx_t_4 = (__pyx_t_5 != 0); if (__pyx_t_4) { - /* "pysam/libctabix.pyx":429 - * # reopen the same file if necessary - * if multiple_iterators: - * fileobj = self._dup() # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":519 + * cdef TabixIterator a + * if parser is None: + * a = TabixIterator(encoding=fileobj.encoding) # <<<<<<<<<<<<<< * else: - * fileobj = self + * parser.set_encoding(fileobj.encoding) */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dup); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 429, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 519, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_encoding, __pyx_v_fileobj->encoding) < 0) __PYX_ERR(0, 519, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_9libctabix_TabixIterator), __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 519, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_a = ((struct __pyx_obj_5pysam_9libctabix_TabixIterator *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libctabix.pyx":518 + * + * cdef TabixIterator a + * if parser is None: # <<<<<<<<<<<<<< + * a = TabixIterator(encoding=fileobj.encoding) + * else: + */ + goto __pyx_L22; + } + + /* "pysam/libctabix.pyx":521 + * a = TabixIterator(encoding=fileobj.encoding) + * else: + * parser.set_encoding(fileobj.encoding) # <<<<<<<<<<<<<< + * a = TabixIteratorParsed(parser) + * + */ + /*else*/ { + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_set_encoding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); + __Pyx_DECREF_SET(__pyx_t_2, function); } } - if (__pyx_t_3) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 429, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_fileobj->encoding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 429, __pyx_L1_error) + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_fileobj->encoding}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_fileobj->encoding}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_fileobj->encoding); + __Pyx_GIVEREF(__pyx_v_fileobj->encoding); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_fileobj->encoding); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } } - __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5pysam_9libctabix_TabixFile))))) __PYX_ERR(0, 429, __pyx_L1_error) - __pyx_v_fileobj = ((struct __pyx_obj_5pysam_9libctabix_TabixFile *)__pyx_t_2); - __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":428 - * - * # reopen the same file if necessary - * if multiple_iterators: # <<<<<<<<<<<<<< - * fileobj = self._dup() + /* "pysam/libctabix.pyx":522 * else: + * parser.set_encoding(fileobj.encoding) + * a = TabixIteratorParsed(parser) # <<<<<<<<<<<<<< + * + * a.tabixfile = fileobj */ - goto __pyx_L10; + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_9libctabix_TabixIteratorParsed), __pyx_v_parser); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 522, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_a = ((struct __pyx_obj_5pysam_9libctabix_TabixIterator *)__pyx_t_1); + __pyx_t_1 = 0; } + __pyx_L22:; - /* "pysam/libctabix.pyx":431 - * fileobj = self._dup() - * else: - * fileobj = self # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":524 + * a = TabixIteratorParsed(parser) + * + * a.tabixfile = fileobj # <<<<<<<<<<<<<< + * a.iterator = itr * - * if region is None: */ - /*else*/ { - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __pyx_v_fileobj = __pyx_v_self; - } - __pyx_L10:; + __Pyx_INCREF(((PyObject *)__pyx_v_fileobj)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fileobj)); + __Pyx_GOTREF(__pyx_v_a->tabixfile); + __Pyx_DECREF(((PyObject *)__pyx_v_a->tabixfile)); + __pyx_v_a->tabixfile = __pyx_v_fileobj; - /* "pysam/libctabix.pyx":433 - * fileobj = self + /* "pysam/libctabix.pyx":525 * - * if region is None: # <<<<<<<<<<<<<< - * # without region or reference - iterate from start - * with nogil: + * a.tabixfile = fileobj + * a.iterator = itr # <<<<<<<<<<<<<< + * + * return a */ - __pyx_t_4 = (__pyx_v_region == Py_None); - __pyx_t_5 = (__pyx_t_4 != 0); - if (__pyx_t_5) { + __pyx_v_a->iterator = __pyx_v_itr; - /* "pysam/libctabix.pyx":435 - * if region is None: - * # without region or reference - iterate from start - * with nogil: # <<<<<<<<<<<<<< - * itr = tbx_itr_queryi(fileobj.index, - * HTS_IDX_START, + /* "pysam/libctabix.pyx":527 + * a.iterator = itr + * + * return a # <<<<<<<<<<<<<< + * + * ############################################################### */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_a)); + __pyx_r = ((PyObject *)__pyx_v_a); + goto __pyx_L0; - /* "pysam/libctabix.pyx":436 - * # without region or reference - iterate from start - * with nogil: - * itr = tbx_itr_queryi(fileobj.index, # <<<<<<<<<<<<<< - * HTS_IDX_START, - * 0, + /* "pysam/libctabix.pyx":418 + * encoding=self.encoding) + * + * def fetch(self, # <<<<<<<<<<<<<< + * reference=None, + * start=None, */ - __pyx_v_itr = tbx_itr_queryi(__pyx_v_fileobj->index, HTS_IDX_START, 0, 0); - } - /* "pysam/libctabix.pyx":435 - * if region is None: - * # without region or reference - iterate from start - * with nogil: # <<<<<<<<<<<<<< - * itr = tbx_itr_queryi(fileobj.index, - * HTS_IDX_START, - */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L14; - } - __pyx_L14:; - } - } + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("pysam.libctabix.TabixFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_fileobj); + __Pyx_XDECREF(__pyx_v_s); + __Pyx_XDECREF((PyObject *)__pyx_v_a); + __Pyx_XDECREF(__pyx_v_start); + __Pyx_XDECREF(__pyx_v_region); + __Pyx_XDECREF(__pyx_v_parser); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libctabix.pyx":433 - * fileobj = self +/* "pysam/libctabix.pyx":545 + * ''' * - * if region is None: # <<<<<<<<<<<<<< - * # without region or reference - iterate from start - * with nogil: + * def __get__(self): # <<<<<<<<<<<<<< + * + * cdef char *cfilename = self.filename */ - goto __pyx_L11; - } - /* "pysam/libctabix.pyx":441 - * 0) - * else: - * s = force_bytes(region, encoding=fileobj.encoding) # <<<<<<<<<<<<<< - * cstr = s - * with nogil: - */ - /*else*/ { - __pyx_t_2 = __pyx_v_fileobj->encoding; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_6.__pyx_n = 1; - __pyx_t_6.encoding = __pyx_t_2; - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_region, &__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 441, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_s = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_6header_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libctabix_9TabixFile_6header___get__(((struct __pyx_obj_5pysam_9libctabix_TabixFile *)__pyx_v_self)); - /* "pysam/libctabix.pyx":442 - * else: - * s = force_bytes(region, encoding=fileobj.encoding) - * cstr = s # <<<<<<<<<<<<<< - * with nogil: - * itr = tbx_itr_querys(fileobj.index, cstr) - */ - if (unlikely(__pyx_v_s == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 442, __pyx_L1_error) - } - __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_s); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 442, __pyx_L1_error) - __pyx_v_cstr = __pyx_t_7; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libctabix.pyx":443 - * s = force_bytes(region, encoding=fileobj.encoding) - * cstr = s - * with nogil: # <<<<<<<<<<<<<< - * itr = tbx_itr_querys(fileobj.index, cstr) +static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_6header___get__(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self) { + char *__pyx_v_cfilename; + char *__pyx_v_cfilename_index; + kstring_t __pyx_v_buffer; + htsFile *__pyx_v_fp; + int __pyx_v_KS_SEP_LINE; + tbx_t *__pyx_v_tbx; + PyObject *__pyx_v_lines = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + char *__pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + struct __pyx_opt_args_5pysam_9libcutils_force_str __pyx_t_8; + int __pyx_t_9; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_TraceCall("__get__", __pyx_f[0], 545, 0, __PYX_ERR(0, 545, __pyx_L1_error)); + + /* "pysam/libctabix.pyx":547 + * def __get__(self): + * + * cdef char *cfilename = self.filename # <<<<<<<<<<<<<< + * cdef char *cfilename_index = self.filename_index * */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + __pyx_t_1 = __Pyx_PyObject_AsWritableString(__pyx_v_self->__pyx_base.filename); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 547, __pyx_L1_error) + __pyx_v_cfilename = __pyx_t_1; - /* "pysam/libctabix.pyx":444 - * cstr = s - * with nogil: - * itr = tbx_itr_querys(fileobj.index, cstr) # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":548 * - * if itr == NULL: + * cdef char *cfilename = self.filename + * cdef char *cfilename_index = self.filename_index # <<<<<<<<<<<<<< + * + * cdef kstring_t buffer */ - __pyx_v_itr = tbx_itr_querys(__pyx_v_fileobj->index, __pyx_v_cstr); - } + __pyx_t_1 = __Pyx_PyObject_AsWritableString(__pyx_v_self->filename_index); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 548, __pyx_L1_error) + __pyx_v_cfilename_index = __pyx_t_1; - /* "pysam/libctabix.pyx":443 - * s = force_bytes(region, encoding=fileobj.encoding) - * cstr = s - * with nogil: # <<<<<<<<<<<<<< - * itr = tbx_itr_querys(fileobj.index, cstr) + /* "pysam/libctabix.pyx":551 + * + * cdef kstring_t buffer + * buffer.l = buffer.m = 0 # <<<<<<<<<<<<<< + * buffer.s = NULL * */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L17; - } - __pyx_L17:; - } - } - } - __pyx_L11:; + __pyx_v_buffer.l = 0; + __pyx_v_buffer.m = 0; - /* "pysam/libctabix.pyx":446 - * itr = tbx_itr_querys(fileobj.index, cstr) + /* "pysam/libctabix.pyx":552 + * cdef kstring_t buffer + * buffer.l = buffer.m = 0 + * buffer.s = NULL # <<<<<<<<<<<<<< * - * if itr == NULL: # <<<<<<<<<<<<<< - * if region is None: - * if len(self.contigs) > 0: + * cdef htsFile * fp = NULL */ - __pyx_t_5 = ((__pyx_v_itr == NULL) != 0); - if (__pyx_t_5) { + __pyx_v_buffer.s = NULL; - /* "pysam/libctabix.pyx":447 + /* "pysam/libctabix.pyx":554 + * buffer.s = NULL * - * if itr == NULL: - * if region is None: # <<<<<<<<<<<<<< - * if len(self.contigs) > 0: - * # when accessing a tabix file created prior tabix 1.0 + * cdef htsFile * fp = NULL # <<<<<<<<<<<<<< + * cdef int KS_SEP_LINE = 2 + * cdef tbx_t * tbx = NULL */ - __pyx_t_5 = (__pyx_v_region == Py_None); - __pyx_t_4 = (__pyx_t_5 != 0); - if (likely(__pyx_t_4)) { + __pyx_v_fp = NULL; - /* "pysam/libctabix.pyx":448 - * if itr == NULL: - * if region is None: - * if len(self.contigs) > 0: # <<<<<<<<<<<<<< - * # when accessing a tabix file created prior tabix 1.0 - * # the full-file iterator is empty. + /* "pysam/libctabix.pyx":555 + * + * cdef htsFile * fp = NULL + * cdef int KS_SEP_LINE = 2 # <<<<<<<<<<<<<< + * cdef tbx_t * tbx = NULL + * lines = [] */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contigs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 448, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = ((__pyx_t_8 > 0) != 0); - if (unlikely(__pyx_t_4)) { + __pyx_v_KS_SEP_LINE = 2; - /* "pysam/libctabix.pyx":451 - * # when accessing a tabix file created prior tabix 1.0 - * # the full-file iterator is empty. - * raise ValueError( # <<<<<<<<<<<<<< - * "could not create iterator, possible " - * "tabix version mismatch") + /* "pysam/libctabix.pyx":556 + * cdef htsFile * fp = NULL + * cdef int KS_SEP_LINE = 2 + * cdef tbx_t * tbx = NULL # <<<<<<<<<<<<<< + * lines = [] + * with nogil: */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 451, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 451, __pyx_L1_error) + __pyx_v_tbx = NULL; - /* "pysam/libctabix.pyx":448 - * if itr == NULL: - * if region is None: - * if len(self.contigs) > 0: # <<<<<<<<<<<<<< - * # when accessing a tabix file created prior tabix 1.0 - * # the full-file iterator is empty. + /* "pysam/libctabix.pyx":557 + * cdef int KS_SEP_LINE = 2 + * cdef tbx_t * tbx = NULL + * lines = [] # <<<<<<<<<<<<<< + * with nogil: + * fp = hts_open(cfilename, 'r') */ - } + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_lines = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":457 - * # possible reason is that the file is empty - - * # return an empty iterator - * return EmptyIterator() # <<<<<<<<<<<<<< - * else: - * raise ValueError( + /* "pysam/libctabix.pyx":558 + * cdef tbx_t * tbx = NULL + * lines = [] + * with nogil: # <<<<<<<<<<<<<< + * fp = hts_open(cfilename, 'r') + * */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_EmptyIterator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 457, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 457, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 457, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - } + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libctabix.pyx":447 + /* "pysam/libctabix.pyx":559 + * lines = [] + * with nogil: + * fp = hts_open(cfilename, 'r') # <<<<<<<<<<<<<< * - * if itr == NULL: - * if region is None: # <<<<<<<<<<<<<< - * if len(self.contigs) > 0: - * # when accessing a tabix file created prior tabix 1.0 + * if fp == NULL: */ - } + __pyx_v_fp = hts_open(__pyx_v_cfilename, ((char const *)"r")); + } - /* "pysam/libctabix.pyx":459 - * return EmptyIterator() - * else: - * raise ValueError( # <<<<<<<<<<<<<< - * "could not create iterator for region '%s'" % - * region) + /* "pysam/libctabix.pyx":558 + * cdef tbx_t * tbx = NULL + * lines = [] + * with nogil: # <<<<<<<<<<<<<< + * fp = hts_open(cfilename, 'r') + * */ - /*else*/ { + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L5; + } + __pyx_L5:; + } + } - /* "pysam/libctabix.pyx":460 - * else: - * raise ValueError( - * "could not create iterator for region '%s'" % # <<<<<<<<<<<<<< - * region) + /* "pysam/libctabix.pyx":561 + * fp = hts_open(cfilename, 'r') + * + * if fp == NULL: # <<<<<<<<<<<<<< + * raise OSError("could not open {} for reading header".format(self.filename)) * */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_could_not_create_iterator_for_re, __pyx_v_region); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 460, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = ((__pyx_v_fp == NULL) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libctabix.pyx":459 - * return EmptyIterator() - * else: - * raise ValueError( # <<<<<<<<<<<<<< - * "could not create iterator for region '%s'" % - * region) + /* "pysam/libctabix.pyx":562 + * + * if fp == NULL: + * raise OSError("could not open {} for reading header".format(self.filename)) # <<<<<<<<<<<<<< + * + * with nogil: */ - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 459, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_open_for_reading_heade, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_self->__pyx_base.filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 562, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 459, __pyx_L1_error) + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_self->__pyx_base.filename}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_self->__pyx_base.filename}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_self->__pyx_base.filename); + __Pyx_GIVEREF(__pyx_v_self->__pyx_base.filename); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_self->__pyx_base.filename); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_OSError, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 562, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 562, __pyx_L1_error) - /* "pysam/libctabix.pyx":446 - * itr = tbx_itr_querys(fileobj.index, cstr) + /* "pysam/libctabix.pyx":561 + * fp = hts_open(cfilename, 'r') + * + * if fp == NULL: # <<<<<<<<<<<<<< + * raise OSError("could not open {} for reading header".format(self.filename)) * - * if itr == NULL: # <<<<<<<<<<<<<< - * if region is None: - * if len(self.contigs) > 0: */ } - /* "pysam/libctabix.pyx":464 + /* "pysam/libctabix.pyx":564 + * raise OSError("could not open {} for reading header".format(self.filename)) * - * # use default parser if no parser is specified - * if parser is None: # <<<<<<<<<<<<<< - * parser = fileobj.parser + * with nogil: # <<<<<<<<<<<<<< + * tbx = tbx_index_load2(cfilename, cfilename_index) * */ - __pyx_t_4 = (__pyx_v_parser == Py_None); - __pyx_t_5 = (__pyx_t_4 != 0); - if (__pyx_t_5) { + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libctabix.pyx":465 - * # use default parser if no parser is specified - * if parser is None: - * parser = fileobj.parser # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":565 * - * cdef TabixIterator a + * with nogil: + * tbx = tbx_index_load2(cfilename, cfilename_index) # <<<<<<<<<<<<<< + * + * if tbx == NULL: */ - __pyx_t_2 = ((PyObject *)__pyx_v_fileobj->parser); - __Pyx_INCREF(__pyx_t_2); - __Pyx_DECREF_SET(__pyx_v_parser, __pyx_t_2); - __pyx_t_2 = 0; + __pyx_v_tbx = tbx_index_load2(__pyx_v_cfilename, __pyx_v_cfilename_index); + } - /* "pysam/libctabix.pyx":464 + /* "pysam/libctabix.pyx":564 + * raise OSError("could not open {} for reading header".format(self.filename)) * - * # use default parser if no parser is specified - * if parser is None: # <<<<<<<<<<<<<< - * parser = fileobj.parser + * with nogil: # <<<<<<<<<<<<<< + * tbx = tbx_index_load2(cfilename, cfilename_index) * */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L9; + } + __pyx_L9:; + } } - /* "pysam/libctabix.pyx":468 + /* "pysam/libctabix.pyx":567 + * tbx = tbx_index_load2(cfilename, cfilename_index) * - * cdef TabixIterator a - * if parser is None: # <<<<<<<<<<<<<< - * a = TabixIterator(encoding=fileobj.encoding) - * else: - */ - __pyx_t_5 = (__pyx_v_parser == Py_None); - __pyx_t_4 = (__pyx_t_5 != 0); - if (__pyx_t_4) { - - /* "pysam/libctabix.pyx":469 - * cdef TabixIterator a - * if parser is None: - * a = TabixIterator(encoding=fileobj.encoding) # <<<<<<<<<<<<<< - * else: - * parser.set_encoding(fileobj.encoding) - */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 469, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_encoding, __pyx_v_fileobj->encoding) < 0) __PYX_ERR(0, 469, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_9libctabix_TabixIterator), __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 469, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_a = ((struct __pyx_obj_5pysam_9libctabix_TabixIterator *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "pysam/libctabix.pyx":468 + * if tbx == NULL: # <<<<<<<<<<<<<< + * raise OSError("could not load .tbi/.csi index of {}".format(self.filename)) * - * cdef TabixIterator a - * if parser is None: # <<<<<<<<<<<<<< - * a = TabixIterator(encoding=fileobj.encoding) - * else: */ - goto __pyx_L22; - } + __pyx_t_3 = ((__pyx_v_tbx == NULL) != 0); + if (unlikely(__pyx_t_3)) { - /* "pysam/libctabix.pyx":471 - * a = TabixIterator(encoding=fileobj.encoding) - * else: - * parser.set_encoding(fileobj.encoding) # <<<<<<<<<<<<<< - * a = TabixIteratorParsed(parser) + /* "pysam/libctabix.pyx":568 * + * if tbx == NULL: + * raise OSError("could not load .tbi/.csi index of {}".format(self.filename)) # <<<<<<<<<<<<<< + * + * while hts_getline(fp, KS_SEP_LINE, &buffer) >= 0: */ - /*else*/ { - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_set_encoding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 471, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_could_not_load_tbi_csi_index_of, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 568, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; + __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } - if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_fileobj->encoding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 471, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + if (!__pyx_t_6) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_self->__pyx_base.filename); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 568, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_fileobj->encoding}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 471, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_self->__pyx_base.filename}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 568, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_fileobj->encoding}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 471, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_self->__pyx_base.filename}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 568, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 471, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_INCREF(__pyx_v_fileobj->encoding); - __Pyx_GIVEREF(__pyx_v_fileobj->encoding); - PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_fileobj->encoding); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 471, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 568, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_INCREF(__pyx_v_self->__pyx_base.filename); + __Pyx_GIVEREF(__pyx_v_self->__pyx_base.filename); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_self->__pyx_base.filename); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 568, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_OSError, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 568, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 568, __pyx_L1_error) - /* "pysam/libctabix.pyx":472 - * else: - * parser.set_encoding(fileobj.encoding) - * a = TabixIteratorParsed(parser) # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":567 + * tbx = tbx_index_load2(cfilename, cfilename_index) + * + * if tbx == NULL: # <<<<<<<<<<<<<< + * raise OSError("could not load .tbi/.csi index of {}".format(self.filename)) * - * a.tabixfile = fileobj */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_9libctabix_TabixIteratorParsed), __pyx_v_parser); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 472, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_a = ((struct __pyx_obj_5pysam_9libctabix_TabixIterator *)__pyx_t_1); - __pyx_t_1 = 0; } - __pyx_L22:; - /* "pysam/libctabix.pyx":474 - * a = TabixIteratorParsed(parser) - * - * a.tabixfile = fileobj # <<<<<<<<<<<<<< - * a.iterator = itr + /* "pysam/libctabix.pyx":570 + * raise OSError("could not load .tbi/.csi index of {}".format(self.filename)) * + * while hts_getline(fp, KS_SEP_LINE, &buffer) >= 0: # <<<<<<<<<<<<<< + * if not buffer.l or buffer.s[0] != tbx.conf.meta_char: + * break */ - __Pyx_INCREF(((PyObject *)__pyx_v_fileobj)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fileobj)); - __Pyx_GOTREF(__pyx_v_a->tabixfile); - __Pyx_DECREF(((PyObject *)__pyx_v_a->tabixfile)); - __pyx_v_a->tabixfile = __pyx_v_fileobj; + while (1) { + __pyx_t_3 = ((hts_getline(__pyx_v_fp, __pyx_v_KS_SEP_LINE, (&__pyx_v_buffer)) >= 0) != 0); + if (!__pyx_t_3) break; - /* "pysam/libctabix.pyx":475 + /* "pysam/libctabix.pyx":571 * - * a.tabixfile = fileobj - * a.iterator = itr # <<<<<<<<<<<<<< - * - * return a + * while hts_getline(fp, KS_SEP_LINE, &buffer) >= 0: + * if not buffer.l or buffer.s[0] != tbx.conf.meta_char: # <<<<<<<<<<<<<< + * break + * lines.append(force_str(buffer.s, self.encoding)) */ - __pyx_v_a->iterator = __pyx_v_itr; + __pyx_t_7 = ((!(__pyx_v_buffer.l != 0)) != 0); + if (!__pyx_t_7) { + } else { + __pyx_t_3 = __pyx_t_7; + goto __pyx_L14_bool_binop_done; + } + __pyx_t_7 = (((__pyx_v_buffer.s[0]) != __pyx_v_tbx->conf.meta_char) != 0); + __pyx_t_3 = __pyx_t_7; + __pyx_L14_bool_binop_done:; + if (__pyx_t_3) { - /* "pysam/libctabix.pyx":477 - * a.iterator = itr - * - * return a # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":572 + * while hts_getline(fp, KS_SEP_LINE, &buffer) >= 0: + * if not buffer.l or buffer.s[0] != tbx.conf.meta_char: + * break # <<<<<<<<<<<<<< + * lines.append(force_str(buffer.s, self.encoding)) * - * ############################################################### */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_a)); - __pyx_r = ((PyObject *)__pyx_v_a); - goto __pyx_L0; + goto __pyx_L12_break; - /* "pysam/libctabix.pyx":368 - * encoding=self.encoding) + /* "pysam/libctabix.pyx":571 * - * def fetch(self, # <<<<<<<<<<<<<< - * reference=None, - * start=None, + * while hts_getline(fp, KS_SEP_LINE, &buffer) >= 0: + * if not buffer.l or buffer.s[0] != tbx.conf.meta_char: # <<<<<<<<<<<<<< + * break + * lines.append(force_str(buffer.s, self.encoding)) */ + } - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libctabix.TabixFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_fileobj); - __Pyx_XDECREF(__pyx_v_s); - __Pyx_XDECREF((PyObject *)__pyx_v_a); - __Pyx_XDECREF(__pyx_v_start); - __Pyx_XDECREF(__pyx_v_region); - __Pyx_XDECREF(__pyx_v_parser); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libctabix.pyx":500 - * ''' + /* "pysam/libctabix.pyx":573 + * if not buffer.l or buffer.s[0] != tbx.conf.meta_char: + * break + * lines.append(force_str(buffer.s, self.encoding)) # <<<<<<<<<<<<<< * - * def __get__(self): # <<<<<<<<<<<<<< - * if self.is_remote: - * raise AttributeError( + * with nogil: */ + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_buffer.s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __pyx_v_self->encoding; + __Pyx_INCREF(__pyx_t_4); + __pyx_t_8.__pyx_n = 1; + __pyx_t_8.encoding = __pyx_t_4; + __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_2, &__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 573, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_5); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 573, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __pyx_L12_break:; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_6header_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_9libctabix_9TabixFile_6header_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libctabix_9TabixFile_6header___get__(((struct __pyx_obj_5pysam_9libctabix_TabixFile *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_6header___get__(struct __pyx_obj_5pysam_9libctabix_TabixFile *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 500, 0, __PYX_ERR(0, 500, __pyx_L1_error)); + /* "pysam/libctabix.pyx":575 + * lines.append(force_str(buffer.s, self.encoding)) + * + * with nogil: # <<<<<<<<<<<<<< + * hts_close(fp) + * free(buffer.s) + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libctabix.pyx":501 + /* "pysam/libctabix.pyx":576 + * + * with nogil: + * hts_close(fp) # <<<<<<<<<<<<<< + * free(buffer.s) * - * def __get__(self): - * if self.is_remote: # <<<<<<<<<<<<<< - * raise AttributeError( - * "the header is not available for remote files") */ - __pyx_t_1 = (__pyx_v_self->__pyx_base.is_remote != 0); - if (unlikely(__pyx_t_1)) { + (void)(hts_close(__pyx_v_fp)); - /* "pysam/libctabix.pyx":502 - * def __get__(self): - * if self.is_remote: - * raise AttributeError( # <<<<<<<<<<<<<< - * "the header is not available for remote files") - * return GZIteratorHead(self.filename) + /* "pysam/libctabix.pyx":577 + * with nogil: + * hts_close(fp) + * free(buffer.s) # <<<<<<<<<<<<<< + * + * return lines */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_AttributeError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 502, __pyx_L1_error) + free(__pyx_v_buffer.s); + } - /* "pysam/libctabix.pyx":501 + /* "pysam/libctabix.pyx":575 + * lines.append(force_str(buffer.s, self.encoding)) * - * def __get__(self): - * if self.is_remote: # <<<<<<<<<<<<<< - * raise AttributeError( - * "the header is not available for remote files") + * with nogil: # <<<<<<<<<<<<<< + * hts_close(fp) + * free(buffer.s) */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L18; + } + __pyx_L18:; + } } - /* "pysam/libctabix.pyx":504 - * raise AttributeError( - * "the header is not available for remote files") - * return GZIteratorHead(self.filename) # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":579 + * free(buffer.s) + * + * return lines # <<<<<<<<<<<<<< * * property contigs: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_5pysam_9libctabix_GZIteratorHead), __pyx_v_self->__pyx_base.filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 504, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v_lines); + __pyx_r = __pyx_v_lines; goto __pyx_L0; - /* "pysam/libctabix.pyx":500 + /* "pysam/libctabix.pyx":545 * ''' * * def __get__(self): # <<<<<<<<<<<<<< - * if self.is_remote: - * raise AttributeError( + * + * cdef char *cfilename = self.filename */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("pysam.libctabix.TabixFile.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_lines); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabix.pyx":508 +/* "pysam/libctabix.pyx":583 * property contigs: * '''list of chromosome names''' * def __get__(self): # <<<<<<<<<<<<<< @@ -7724,9 +8677,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_7contigs___get__(struct _ PyObject *__pyx_t_3 = NULL; int __pyx_t_4; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_TraceCall("__get__", __pyx_f[0], 508, 0, __PYX_ERR(0, 508, __pyx_L1_error)); + __Pyx_TraceCall("__get__", __pyx_f[0], 583, 0, __PYX_ERR(0, 583, __pyx_L1_error)); - /* "pysam/libctabix.pyx":512 + /* "pysam/libctabix.pyx":587 * cdef int nsequences * * with nogil: # <<<<<<<<<<<<<< @@ -7741,7 +8694,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_7contigs___get__(struct _ #endif /*try:*/ { - /* "pysam/libctabix.pyx":513 + /* "pysam/libctabix.pyx":588 * * with nogil: * sequences = tbx_seqnames(self.index, &nsequences) # <<<<<<<<<<<<<< @@ -7751,7 +8704,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_7contigs___get__(struct _ __pyx_v_sequences = tbx_seqnames(__pyx_v_self->index, (&__pyx_v_nsequences)); } - /* "pysam/libctabix.pyx":512 + /* "pysam/libctabix.pyx":587 * cdef int nsequences * * with nogil: # <<<<<<<<<<<<<< @@ -7770,19 +8723,19 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_7contigs___get__(struct _ } } - /* "pysam/libctabix.pyx":515 + /* "pysam/libctabix.pyx":590 * sequences = tbx_seqnames(self.index, &nsequences) * cdef int x * result = [] # <<<<<<<<<<<<<< * for x from 0 <= x < nsequences: * result.append(force_str(sequences[x])) */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 515, __pyx_L1_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":516 + /* "pysam/libctabix.pyx":591 * cdef int x * result = [] * for x from 0 <= x < nsequences: # <<<<<<<<<<<<<< @@ -7792,23 +8745,23 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_7contigs___get__(struct _ __pyx_t_2 = __pyx_v_nsequences; for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) { - /* "pysam/libctabix.pyx":517 + /* "pysam/libctabix.pyx":592 * result = [] * for x from 0 <= x < nsequences: * result.append(force_str(sequences[x])) # <<<<<<<<<<<<<< * * # htslib instructions: */ - __pyx_t_1 = __Pyx_PyBytes_FromString((__pyx_v_sequences[__pyx_v_x])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 517, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBytes_FromString((__pyx_v_sequences[__pyx_v_x])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 592, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 517, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 592, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 517, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 592, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } - /* "pysam/libctabix.pyx":521 + /* "pysam/libctabix.pyx":596 * # htslib instructions: * # only free container, not the sequences themselves * free(sequences) # <<<<<<<<<<<<<< @@ -7817,7 +8770,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_7contigs___get__(struct _ */ free(__pyx_v_sequences); - /* "pysam/libctabix.pyx":523 + /* "pysam/libctabix.pyx":598 * free(sequences) * * return result # <<<<<<<<<<<<<< @@ -7829,7 +8782,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_7contigs___get__(struct _ __pyx_r = __pyx_v_result; goto __pyx_L0; - /* "pysam/libctabix.pyx":508 + /* "pysam/libctabix.pyx":583 * property contigs: * '''list of chromosome names''' * def __get__(self): # <<<<<<<<<<<<<< @@ -7851,7 +8804,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_7contigs___get__(struct _ return __pyx_r; } -/* "pysam/libctabix.pyx":525 +/* "pysam/libctabix.pyx":600 * return result * * def close(self): # <<<<<<<<<<<<<< @@ -7879,9 +8832,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_8close(struct __pyx_obj_5 __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("close", 0); - __Pyx_TraceCall("close", __pyx_f[0], 525, 0, __PYX_ERR(0, 525, __pyx_L1_error)); + __Pyx_TraceCall("close", __pyx_f[0], 600, 0, __PYX_ERR(0, 600, __pyx_L1_error)); - /* "pysam/libctabix.pyx":528 + /* "pysam/libctabix.pyx":603 * ''' * closes the :class:`pysam.TabixFile`.''' * if self.htsfile != NULL: # <<<<<<<<<<<<<< @@ -7891,7 +8844,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_8close(struct __pyx_obj_5 __pyx_t_1 = ((__pyx_v_self->__pyx_base.htsfile != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":529 + /* "pysam/libctabix.pyx":604 * closes the :class:`pysam.TabixFile`.''' * if self.htsfile != NULL: * hts_close(self.htsfile) # <<<<<<<<<<<<<< @@ -7900,7 +8853,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_8close(struct __pyx_obj_5 */ (void)(hts_close(__pyx_v_self->__pyx_base.htsfile)); - /* "pysam/libctabix.pyx":530 + /* "pysam/libctabix.pyx":605 * if self.htsfile != NULL: * hts_close(self.htsfile) * self.htsfile = NULL # <<<<<<<<<<<<<< @@ -7909,7 +8862,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_8close(struct __pyx_obj_5 */ __pyx_v_self->__pyx_base.htsfile = NULL; - /* "pysam/libctabix.pyx":528 + /* "pysam/libctabix.pyx":603 * ''' * closes the :class:`pysam.TabixFile`.''' * if self.htsfile != NULL: # <<<<<<<<<<<<<< @@ -7918,7 +8871,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_8close(struct __pyx_obj_5 */ } - /* "pysam/libctabix.pyx":531 + /* "pysam/libctabix.pyx":606 * hts_close(self.htsfile) * self.htsfile = NULL * if self.index != NULL: # <<<<<<<<<<<<<< @@ -7928,7 +8881,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_8close(struct __pyx_obj_5 __pyx_t_1 = ((__pyx_v_self->index != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":532 + /* "pysam/libctabix.pyx":607 * self.htsfile = NULL * if self.index != NULL: * tbx_destroy(self.index) # <<<<<<<<<<<<<< @@ -7937,7 +8890,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_8close(struct __pyx_obj_5 */ tbx_destroy(__pyx_v_self->index); - /* "pysam/libctabix.pyx":533 + /* "pysam/libctabix.pyx":608 * if self.index != NULL: * tbx_destroy(self.index) * self.index = NULL # <<<<<<<<<<<<<< @@ -7946,7 +8899,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_8close(struct __pyx_obj_5 */ __pyx_v_self->index = NULL; - /* "pysam/libctabix.pyx":531 + /* "pysam/libctabix.pyx":606 * hts_close(self.htsfile) * self.htsfile = NULL * if self.index != NULL: # <<<<<<<<<<<<<< @@ -7955,7 +8908,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_8close(struct __pyx_obj_5 */ } - /* "pysam/libctabix.pyx":525 + /* "pysam/libctabix.pyx":600 * return result * * def close(self): # <<<<<<<<<<<<<< @@ -7976,7 +8929,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_8close(struct __pyx_obj_5 return __pyx_r; } -/* "pysam/libctabix.pyx":535 +/* "pysam/libctabix.pyx":610 * self.index = NULL * * def __dealloc__( self ): # <<<<<<<<<<<<<< @@ -8000,9 +8953,9 @@ static void __pyx_pf_5pysam_9libctabix_9TabixFile_10__dealloc__(struct __pyx_obj __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 535, 0, __PYX_ERR(0, 535, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 610, 0, __PYX_ERR(0, 610, __pyx_L1_error)); - /* "pysam/libctabix.pyx":539 + /* "pysam/libctabix.pyx":614 * # note: no doc string * # note: __del__ is not called. * if self.htsfile != NULL: # <<<<<<<<<<<<<< @@ -8012,7 +8965,7 @@ static void __pyx_pf_5pysam_9libctabix_9TabixFile_10__dealloc__(struct __pyx_obj __pyx_t_1 = ((__pyx_v_self->__pyx_base.htsfile != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":540 + /* "pysam/libctabix.pyx":615 * # note: __del__ is not called. * if self.htsfile != NULL: * hts_close(self.htsfile) # <<<<<<<<<<<<<< @@ -8021,7 +8974,7 @@ static void __pyx_pf_5pysam_9libctabix_9TabixFile_10__dealloc__(struct __pyx_obj */ (void)(hts_close(__pyx_v_self->__pyx_base.htsfile)); - /* "pysam/libctabix.pyx":541 + /* "pysam/libctabix.pyx":616 * if self.htsfile != NULL: * hts_close(self.htsfile) * self.htsfile = NULL # <<<<<<<<<<<<<< @@ -8030,7 +8983,7 @@ static void __pyx_pf_5pysam_9libctabix_9TabixFile_10__dealloc__(struct __pyx_obj */ __pyx_v_self->__pyx_base.htsfile = NULL; - /* "pysam/libctabix.pyx":539 + /* "pysam/libctabix.pyx":614 * # note: no doc string * # note: __del__ is not called. * if self.htsfile != NULL: # <<<<<<<<<<<<<< @@ -8039,7 +8992,7 @@ static void __pyx_pf_5pysam_9libctabix_9TabixFile_10__dealloc__(struct __pyx_obj */ } - /* "pysam/libctabix.pyx":542 + /* "pysam/libctabix.pyx":617 * hts_close(self.htsfile) * self.htsfile = NULL * if self.index != NULL: # <<<<<<<<<<<<<< @@ -8049,7 +9002,7 @@ static void __pyx_pf_5pysam_9libctabix_9TabixFile_10__dealloc__(struct __pyx_obj __pyx_t_1 = ((__pyx_v_self->index != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":543 + /* "pysam/libctabix.pyx":618 * self.htsfile = NULL * if self.index != NULL: * tbx_destroy(self.index) # <<<<<<<<<<<<<< @@ -8058,7 +9011,7 @@ static void __pyx_pf_5pysam_9libctabix_9TabixFile_10__dealloc__(struct __pyx_obj */ tbx_destroy(__pyx_v_self->index); - /* "pysam/libctabix.pyx":542 + /* "pysam/libctabix.pyx":617 * hts_close(self.htsfile) * self.htsfile = NULL * if self.index != NULL: # <<<<<<<<<<<<<< @@ -8067,7 +9020,7 @@ static void __pyx_pf_5pysam_9libctabix_9TabixFile_10__dealloc__(struct __pyx_obj */ } - /* "pysam/libctabix.pyx":535 + /* "pysam/libctabix.pyx":610 * self.index = NULL * * def __dealloc__( self ): # <<<<<<<<<<<<<< @@ -8161,7 +9114,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_12__reduce_cython__(CYTHO * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -8218,7 +9171,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_14__setstate_cython__(CYT * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -8242,7 +9195,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9TabixFile_14__setstate_cython__(CYT return __pyx_r; } -/* "pysam/libctabix.pyx":551 +/* "pysam/libctabix.pyx":626 * """ * * def __init__(self, encoding="ascii"): # <<<<<<<<<<<<<< @@ -8279,7 +9232,7 @@ static int __pyx_pw_5pysam_9libctabix_13TabixIterator_1__init__(PyObject *__pyx_ } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 551, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 626, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -8293,7 +9246,7 @@ static int __pyx_pw_5pysam_9libctabix_13TabixIterator_1__init__(PyObject *__pyx_ } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 551, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 626, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabix.TabixIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -8311,9 +9264,9 @@ static int __pyx_pf_5pysam_9libctabix_13TabixIterator___init__(struct __pyx_obj_ __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 551, 0, __PYX_ERR(0, 551, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 626, 0, __PYX_ERR(0, 626, __pyx_L1_error)); - /* "pysam/libctabix.pyx":552 + /* "pysam/libctabix.pyx":627 * * def __init__(self, encoding="ascii"): * self.encoding = encoding # <<<<<<<<<<<<<< @@ -8326,7 +9279,7 @@ static int __pyx_pf_5pysam_9libctabix_13TabixIterator___init__(struct __pyx_obj_ __Pyx_DECREF(__pyx_v_self->encoding); __pyx_v_self->encoding = __pyx_v_encoding; - /* "pysam/libctabix.pyx":551 + /* "pysam/libctabix.pyx":626 * """ * * def __init__(self, encoding="ascii"): # <<<<<<<<<<<<<< @@ -8346,7 +9299,7 @@ static int __pyx_pf_5pysam_9libctabix_13TabixIterator___init__(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libctabix.pyx":554 +/* "pysam/libctabix.pyx":629 * self.encoding = encoding * * def __iter__(self): # <<<<<<<<<<<<<< @@ -8372,9 +9325,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_2__iter__(struct __p __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 554, 0, __PYX_ERR(0, 554, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 629, 0, __PYX_ERR(0, 629, __pyx_L1_error)); - /* "pysam/libctabix.pyx":555 + /* "pysam/libctabix.pyx":630 * * def __iter__(self): * self.buffer.s = NULL # <<<<<<<<<<<<<< @@ -8383,7 +9336,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_2__iter__(struct __p */ __pyx_v_self->buffer.s = NULL; - /* "pysam/libctabix.pyx":556 + /* "pysam/libctabix.pyx":631 * def __iter__(self): * self.buffer.s = NULL * self.buffer.l = 0 # <<<<<<<<<<<<<< @@ -8392,7 +9345,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_2__iter__(struct __p */ __pyx_v_self->buffer.l = 0; - /* "pysam/libctabix.pyx":557 + /* "pysam/libctabix.pyx":632 * self.buffer.s = NULL * self.buffer.l = 0 * self.buffer.m = 0 # <<<<<<<<<<<<<< @@ -8401,7 +9354,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_2__iter__(struct __p */ __pyx_v_self->buffer.m = 0; - /* "pysam/libctabix.pyx":559 + /* "pysam/libctabix.pyx":634 * self.buffer.m = 0 * * return self # <<<<<<<<<<<<<< @@ -8413,7 +9366,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_2__iter__(struct __p __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libctabix.pyx":554 + /* "pysam/libctabix.pyx":629 * self.encoding = encoding * * def __iter__(self): # <<<<<<<<<<<<<< @@ -8432,7 +9385,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_2__iter__(struct __p return __pyx_r; } -/* "pysam/libctabix.pyx":561 +/* "pysam/libctabix.pyx":636 * return self * * cdef int __cnext__(self): # <<<<<<<<<<<<<< @@ -8447,9 +9400,9 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__cnext__", 0); - __Pyx_TraceCall("__cnext__", __pyx_f[0], 561, 0, __PYX_ERR(0, 561, __pyx_L1_error)); + __Pyx_TraceCall("__cnext__", __pyx_f[0], 636, 0, __PYX_ERR(0, 636, __pyx_L1_error)); - /* "pysam/libctabix.pyx":567 + /* "pysam/libctabix.pyx":642 * was called. * ''' * if self.tabixfile.htsfile == NULL: # <<<<<<<<<<<<<< @@ -8459,7 +9412,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ __pyx_t_1 = ((__pyx_v_self->tabixfile->__pyx_base.htsfile == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":568 + /* "pysam/libctabix.pyx":643 * ''' * if self.tabixfile.htsfile == NULL: * return -5 # <<<<<<<<<<<<<< @@ -8469,7 +9422,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ __pyx_r = -5; goto __pyx_L0; - /* "pysam/libctabix.pyx":567 + /* "pysam/libctabix.pyx":642 * was called. * ''' * if self.tabixfile.htsfile == NULL: # <<<<<<<<<<<<<< @@ -8478,7 +9431,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ */ } - /* "pysam/libctabix.pyx":572 + /* "pysam/libctabix.pyx":647 * cdef int retval * * while 1: # <<<<<<<<<<<<<< @@ -8487,7 +9440,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ */ while (1) { - /* "pysam/libctabix.pyx":573 + /* "pysam/libctabix.pyx":648 * * while 1: * with nogil: # <<<<<<<<<<<<<< @@ -8502,7 +9455,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ #endif /*try:*/ { - /* "pysam/libctabix.pyx":574 + /* "pysam/libctabix.pyx":649 * while 1: * with nogil: * retval = tbx_itr_next( # <<<<<<<<<<<<<< @@ -8512,7 +9465,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ __pyx_v_retval = tbx_itr_next(__pyx_v_self->tabixfile->__pyx_base.htsfile, __pyx_v_self->tabixfile->index, __pyx_v_self->iterator, (&__pyx_v_self->buffer)); } - /* "pysam/libctabix.pyx":573 + /* "pysam/libctabix.pyx":648 * * while 1: * with nogil: # <<<<<<<<<<<<<< @@ -8531,7 +9484,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ } } - /* "pysam/libctabix.pyx":580 + /* "pysam/libctabix.pyx":655 * &self.buffer) * * if retval < 0: # <<<<<<<<<<<<<< @@ -8541,7 +9494,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ __pyx_t_1 = ((__pyx_v_retval < 0) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":581 + /* "pysam/libctabix.pyx":656 * * if retval < 0: * break # <<<<<<<<<<<<<< @@ -8550,7 +9503,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ */ goto __pyx_L5_break; - /* "pysam/libctabix.pyx":580 + /* "pysam/libctabix.pyx":655 * &self.buffer) * * if retval < 0: # <<<<<<<<<<<<<< @@ -8559,7 +9512,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ */ } - /* "pysam/libctabix.pyx":583 + /* "pysam/libctabix.pyx":658 * break * * if self.buffer.s[0] != '#': # <<<<<<<<<<<<<< @@ -8569,7 +9522,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ __pyx_t_1 = (((__pyx_v_self->buffer.s[0]) != '#') != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":584 + /* "pysam/libctabix.pyx":659 * * if self.buffer.s[0] != '#': * break # <<<<<<<<<<<<<< @@ -8578,7 +9531,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ */ goto __pyx_L5_break; - /* "pysam/libctabix.pyx":583 + /* "pysam/libctabix.pyx":658 * break * * if self.buffer.s[0] != '#': # <<<<<<<<<<<<<< @@ -8589,7 +9542,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ } __pyx_L5_break:; - /* "pysam/libctabix.pyx":586 + /* "pysam/libctabix.pyx":661 * break * * return retval # <<<<<<<<<<<<<< @@ -8599,7 +9552,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ __pyx_r = __pyx_v_retval; goto __pyx_L0; - /* "pysam/libctabix.pyx":561 + /* "pysam/libctabix.pyx":636 * return self * * cdef int __cnext__(self): # <<<<<<<<<<<<<< @@ -8617,7 +9570,7 @@ static int __pyx_f_5pysam_9libctabix_13TabixIterator___cnext__(struct __pyx_obj_ return __pyx_r; } -/* "pysam/libctabix.pyx":588 +/* "pysam/libctabix.pyx":663 * return retval * * def __next__(self): # <<<<<<<<<<<<<< @@ -8652,9 +9605,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_4__next__(struct __p PyObject *__pyx_t_3 = NULL; struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str __pyx_t_4; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 588, 0, __PYX_ERR(0, 588, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 663, 0, __PYX_ERR(0, 663, __pyx_L1_error)); - /* "pysam/libctabix.pyx":594 + /* "pysam/libctabix.pyx":669 * """ * * cdef int retval = self.__cnext__() # <<<<<<<<<<<<<< @@ -8663,7 +9616,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_4__next__(struct __p */ __pyx_v_retval = ((struct __pyx_vtabstruct_5pysam_9libctabix_TabixIterator *)__pyx_v_self->__pyx_vtab)->__pyx___cnext__(__pyx_v_self); - /* "pysam/libctabix.pyx":595 + /* "pysam/libctabix.pyx":670 * * cdef int retval = self.__cnext__() * if retval == -5: # <<<<<<<<<<<<<< @@ -8673,20 +9626,20 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_4__next__(struct __p __pyx_t_1 = ((__pyx_v_retval == -5L) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":596 + /* "pysam/libctabix.pyx":671 * cdef int retval = self.__cnext__() * if retval == -5: * raise IOError("iteration on closed file") # <<<<<<<<<<<<<< * elif retval < 0: * raise StopIteration */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 596, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 671, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 596, __pyx_L1_error) + __PYX_ERR(0, 671, __pyx_L1_error) - /* "pysam/libctabix.pyx":595 + /* "pysam/libctabix.pyx":670 * * cdef int retval = self.__cnext__() * if retval == -5: # <<<<<<<<<<<<<< @@ -8695,7 +9648,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_4__next__(struct __p */ } - /* "pysam/libctabix.pyx":597 + /* "pysam/libctabix.pyx":672 * if retval == -5: * raise IOError("iteration on closed file") * elif retval < 0: # <<<<<<<<<<<<<< @@ -8705,7 +9658,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_4__next__(struct __p __pyx_t_1 = ((__pyx_v_retval < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":598 + /* "pysam/libctabix.pyx":673 * raise IOError("iteration on closed file") * elif retval < 0: * raise StopIteration # <<<<<<<<<<<<<< @@ -8713,9 +9666,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_4__next__(struct __p * return charptr_to_str(self.buffer.s, self.encoding) */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 598, __pyx_L1_error) + __PYX_ERR(0, 673, __pyx_L1_error) - /* "pysam/libctabix.pyx":597 + /* "pysam/libctabix.pyx":672 * if retval == -5: * raise IOError("iteration on closed file") * elif retval < 0: # <<<<<<<<<<<<<< @@ -8724,7 +9677,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_4__next__(struct __p */ } - /* "pysam/libctabix.pyx":600 + /* "pysam/libctabix.pyx":675 * raise StopIteration * * return charptr_to_str(self.buffer.s, self.encoding) # <<<<<<<<<<<<<< @@ -8736,14 +9689,14 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_4__next__(struct __p __Pyx_INCREF(__pyx_t_2); __pyx_t_4.__pyx_n = 1; __pyx_t_4.encoding = __pyx_t_2; - __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_self->buffer.s, &__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 600, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str(__pyx_v_self->buffer.s, &__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 675, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libctabix.pyx":588 + /* "pysam/libctabix.pyx":663 * return retval * * def __next__(self): # <<<<<<<<<<<<<< @@ -8764,7 +9717,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_4__next__(struct __p return __pyx_r; } -/* "pysam/libctabix.pyx":602 +/* "pysam/libctabix.pyx":677 * return charptr_to_str(self.buffer.s, self.encoding) * * def next(self): # <<<<<<<<<<<<<< @@ -8794,9 +9747,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_6next(struct __pyx_o PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("next", 0); - __Pyx_TraceCall("next", __pyx_f[0], 602, 0, __PYX_ERR(0, 602, __pyx_L1_error)); + __Pyx_TraceCall("next", __pyx_f[0], 677, 0, __PYX_ERR(0, 677, __pyx_L1_error)); - /* "pysam/libctabix.pyx":603 + /* "pysam/libctabix.pyx":678 * * def next(self): * return self.__next__() # <<<<<<<<<<<<<< @@ -8804,7 +9757,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_6next(struct __pyx_o * def __dealloc__(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 603, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 678, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -8817,10 +9770,10 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_6next(struct __pyx_o } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 603, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 678, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 603, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 678, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -8828,7 +9781,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_6next(struct __pyx_o __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libctabix.pyx":602 + /* "pysam/libctabix.pyx":677 * return charptr_to_str(self.buffer.s, self.encoding) * * def next(self): # <<<<<<<<<<<<<< @@ -8850,7 +9803,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_6next(struct __pyx_o return __pyx_r; } -/* "pysam/libctabix.pyx":605 +/* "pysam/libctabix.pyx":680 * return self.__next__() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -8874,9 +9827,9 @@ static void __pyx_pf_5pysam_9libctabix_13TabixIterator_8__dealloc__(struct __pyx __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 605, 0, __PYX_ERR(0, 605, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 680, 0, __PYX_ERR(0, 680, __pyx_L1_error)); - /* "pysam/libctabix.pyx":606 + /* "pysam/libctabix.pyx":681 * * def __dealloc__(self): * if self.iterator != NULL: # <<<<<<<<<<<<<< @@ -8886,7 +9839,7 @@ static void __pyx_pf_5pysam_9libctabix_13TabixIterator_8__dealloc__(struct __pyx __pyx_t_1 = ((((void *)__pyx_v_self->iterator) != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":607 + /* "pysam/libctabix.pyx":682 * def __dealloc__(self): * if self.iterator != NULL: * tbx_itr_destroy(self.iterator) # <<<<<<<<<<<<<< @@ -8895,7 +9848,7 @@ static void __pyx_pf_5pysam_9libctabix_13TabixIterator_8__dealloc__(struct __pyx */ tbx_itr_destroy(__pyx_v_self->iterator); - /* "pysam/libctabix.pyx":606 + /* "pysam/libctabix.pyx":681 * * def __dealloc__(self): * if self.iterator != NULL: # <<<<<<<<<<<<<< @@ -8904,7 +9857,7 @@ static void __pyx_pf_5pysam_9libctabix_13TabixIterator_8__dealloc__(struct __pyx */ } - /* "pysam/libctabix.pyx":608 + /* "pysam/libctabix.pyx":683 * if self.iterator != NULL: * tbx_itr_destroy(self.iterator) * if self.buffer.s != NULL: # <<<<<<<<<<<<<< @@ -8914,7 +9867,7 @@ static void __pyx_pf_5pysam_9libctabix_13TabixIterator_8__dealloc__(struct __pyx __pyx_t_1 = ((__pyx_v_self->buffer.s != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":609 + /* "pysam/libctabix.pyx":684 * tbx_itr_destroy(self.iterator) * if self.buffer.s != NULL: * free(self.buffer.s) # <<<<<<<<<<<<<< @@ -8923,7 +9876,7 @@ static void __pyx_pf_5pysam_9libctabix_13TabixIterator_8__dealloc__(struct __pyx */ free(__pyx_v_self->buffer.s); - /* "pysam/libctabix.pyx":608 + /* "pysam/libctabix.pyx":683 * if self.iterator != NULL: * tbx_itr_destroy(self.iterator) * if self.buffer.s != NULL: # <<<<<<<<<<<<<< @@ -8932,7 +9885,7 @@ static void __pyx_pf_5pysam_9libctabix_13TabixIterator_8__dealloc__(struct __pyx */ } - /* "pysam/libctabix.pyx":605 + /* "pysam/libctabix.pyx":680 * return self.__next__() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -8983,7 +9936,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_10__reduce_cython__( * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iterator cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -9040,7 +9993,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_12__setstate_cython_ * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iterator cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -9064,7 +10017,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13TabixIterator_12__setstate_cython_ return __pyx_r; } -/* "pysam/libctabix.pyx":615 +/* "pysam/libctabix.pyx":690 * '''empty iterator''' * * def __iter__(self): # <<<<<<<<<<<<<< @@ -9091,11 +10044,11 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13EmptyIterator___iter__(CYTHON_UNUS PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_TraceFrameInit(__pyx_codeobj__10) + __Pyx_TraceFrameInit(__pyx_codeobj__9) __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 615, 0, __PYX_ERR(0, 615, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 690, 0, __PYX_ERR(0, 690, __pyx_L1_error)); - /* "pysam/libctabix.pyx":616 + /* "pysam/libctabix.pyx":691 * * def __iter__(self): * return self # <<<<<<<<<<<<<< @@ -9107,7 +10060,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13EmptyIterator___iter__(CYTHON_UNUS __pyx_r = __pyx_v_self; goto __pyx_L0; - /* "pysam/libctabix.pyx":615 + /* "pysam/libctabix.pyx":690 * '''empty iterator''' * * def __iter__(self): # <<<<<<<<<<<<<< @@ -9126,7 +10079,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13EmptyIterator___iter__(CYTHON_UNUS return __pyx_r; } -/* "pysam/libctabix.pyx":618 +/* "pysam/libctabix.pyx":693 * return self * * def next(self): # <<<<<<<<<<<<<< @@ -9154,24 +10107,24 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13EmptyIterator_2next(CYTHON_UNUSED __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_TraceFrameInit(__pyx_codeobj__11) + __Pyx_TraceFrameInit(__pyx_codeobj__10) __Pyx_RefNannySetupContext("next", 0); - __Pyx_TraceCall("next", __pyx_f[0], 618, 0, __PYX_ERR(0, 618, __pyx_L1_error)); + __Pyx_TraceCall("next", __pyx_f[0], 693, 0, __PYX_ERR(0, 693, __pyx_L1_error)); - /* "pysam/libctabix.pyx":619 + /* "pysam/libctabix.pyx":694 * * def next(self): * raise StopIteration() # <<<<<<<<<<<<<< * * def __next__(self): */ - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_StopIteration); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 619, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_StopIteration); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 694, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 619, __pyx_L1_error) + __PYX_ERR(0, 694, __pyx_L1_error) - /* "pysam/libctabix.pyx":618 + /* "pysam/libctabix.pyx":693 * return self * * def next(self): # <<<<<<<<<<<<<< @@ -9190,7 +10143,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13EmptyIterator_2next(CYTHON_UNUSED return __pyx_r; } -/* "pysam/libctabix.pyx":621 +/* "pysam/libctabix.pyx":696 * raise StopIteration() * * def __next__(self): # <<<<<<<<<<<<<< @@ -9218,24 +10171,24 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13EmptyIterator_4__next__(CYTHON_UNU __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_TraceFrameInit(__pyx_codeobj__12) + __Pyx_TraceFrameInit(__pyx_codeobj__11) __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 621, 0, __PYX_ERR(0, 621, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 696, 0, __PYX_ERR(0, 696, __pyx_L1_error)); - /* "pysam/libctabix.pyx":622 + /* "pysam/libctabix.pyx":697 * * def __next__(self): * raise StopIteration() # <<<<<<<<<<<<<< * * */ - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_StopIteration); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 622, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_StopIteration); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 697, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 622, __pyx_L1_error) + __PYX_ERR(0, 697, __pyx_L1_error) - /* "pysam/libctabix.pyx":621 + /* "pysam/libctabix.pyx":696 * raise StopIteration() * * def __next__(self): # <<<<<<<<<<<<<< @@ -9254,7 +10207,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_13EmptyIterator_4__next__(CYTHON_UNU return __pyx_r; } -/* "pysam/libctabix.pyx":633 +/* "pysam/libctabix.pyx":708 * """ * * def __init__(self, # <<<<<<<<<<<<<< @@ -9288,7 +10241,7 @@ static int __pyx_pw_5pysam_9libctabix_19TabixIteratorParsed_1__init__(PyObject * else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 633, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 708, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -9299,13 +10252,13 @@ static int __pyx_pw_5pysam_9libctabix_19TabixIteratorParsed_1__init__(PyObject * } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 633, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 708, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabix.TabixIteratorParsed.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_parser), __pyx_ptype_5pysam_9libctabix_Parser, 1, "parser", 0))) __PYX_ERR(0, 634, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_parser), __pyx_ptype_5pysam_9libctabix_Parser, 1, "parser", 0))) __PYX_ERR(0, 709, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_9libctabix_19TabixIteratorParsed___init__(((struct __pyx_obj_5pysam_9libctabix_TabixIteratorParsed *)__pyx_v_self), __pyx_v_parser); /* function exit code */ @@ -9326,16 +10279,16 @@ static int __pyx_pf_5pysam_9libctabix_19TabixIteratorParsed___init__(struct __py PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 633, 0, __PYX_ERR(0, 633, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 708, 0, __PYX_ERR(0, 708, __pyx_L1_error)); - /* "pysam/libctabix.pyx":636 + /* "pysam/libctabix.pyx":711 * Parser parser): * * TabixIterator.__init__(self) # <<<<<<<<<<<<<< * self.parser = parser * */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_9libctabix_TabixIterator), __pyx_n_s_init); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 636, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_9libctabix_TabixIterator), __pyx_n_s_init); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 711, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -9348,13 +10301,13 @@ static int __pyx_pf_5pysam_9libctabix_19TabixIteratorParsed___init__(struct __py } } if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 636, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 711, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_self)}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 636, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 711, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -9362,19 +10315,19 @@ static int __pyx_pf_5pysam_9libctabix_19TabixIteratorParsed___init__(struct __py #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_self)}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 636, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 711, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 636, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 711, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_self)); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 636, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 711, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } @@ -9382,7 +10335,7 @@ static int __pyx_pf_5pysam_9libctabix_19TabixIteratorParsed___init__(struct __py __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":637 + /* "pysam/libctabix.pyx":712 * * TabixIterator.__init__(self) * self.parser = parser # <<<<<<<<<<<<<< @@ -9395,7 +10348,7 @@ static int __pyx_pf_5pysam_9libctabix_19TabixIteratorParsed___init__(struct __py __Pyx_DECREF(((PyObject *)__pyx_v_self->parser)); __pyx_v_self->parser = __pyx_v_parser; - /* "pysam/libctabix.pyx":633 + /* "pysam/libctabix.pyx":708 * """ * * def __init__(self, # <<<<<<<<<<<<<< @@ -9419,7 +10372,7 @@ static int __pyx_pf_5pysam_9libctabix_19TabixIteratorParsed___init__(struct __py return __pyx_r; } -/* "pysam/libctabix.pyx":639 +/* "pysam/libctabix.pyx":714 * self.parser = parser * * def __next__(self): # <<<<<<<<<<<<<< @@ -9452,9 +10405,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19TabixIteratorParsed_2__next__(stru int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 639, 0, __PYX_ERR(0, 639, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 714, 0, __PYX_ERR(0, 714, __pyx_L1_error)); - /* "pysam/libctabix.pyx":645 + /* "pysam/libctabix.pyx":720 * """ * * cdef int retval = self.__cnext__() # <<<<<<<<<<<<<< @@ -9463,7 +10416,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19TabixIteratorParsed_2__next__(stru */ __pyx_v_retval = ((struct __pyx_vtabstruct_5pysam_9libctabix_TabixIteratorParsed *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.__pyx___cnext__(((struct __pyx_obj_5pysam_9libctabix_TabixIterator *)__pyx_v_self)); - /* "pysam/libctabix.pyx":646 + /* "pysam/libctabix.pyx":721 * * cdef int retval = self.__cnext__() * if retval == -5: # <<<<<<<<<<<<<< @@ -9473,20 +10426,20 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19TabixIteratorParsed_2__next__(stru __pyx_t_1 = ((__pyx_v_retval == -5L) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":647 + /* "pysam/libctabix.pyx":722 * cdef int retval = self.__cnext__() * if retval == -5: * raise IOError("iteration on closed file") # <<<<<<<<<<<<<< * elif retval < 0: * raise StopIteration */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 647, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 722, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 647, __pyx_L1_error) + __PYX_ERR(0, 722, __pyx_L1_error) - /* "pysam/libctabix.pyx":646 + /* "pysam/libctabix.pyx":721 * * cdef int retval = self.__cnext__() * if retval == -5: # <<<<<<<<<<<<<< @@ -9495,7 +10448,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19TabixIteratorParsed_2__next__(stru */ } - /* "pysam/libctabix.pyx":648 + /* "pysam/libctabix.pyx":723 * if retval == -5: * raise IOError("iteration on closed file") * elif retval < 0: # <<<<<<<<<<<<<< @@ -9505,7 +10458,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19TabixIteratorParsed_2__next__(stru __pyx_t_1 = ((__pyx_v_retval < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":649 + /* "pysam/libctabix.pyx":724 * raise IOError("iteration on closed file") * elif retval < 0: * raise StopIteration # <<<<<<<<<<<<<< @@ -9513,9 +10466,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19TabixIteratorParsed_2__next__(stru * return self.parser.parse(self.buffer.s, */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 649, __pyx_L1_error) + __PYX_ERR(0, 724, __pyx_L1_error) - /* "pysam/libctabix.pyx":648 + /* "pysam/libctabix.pyx":723 * if retval == -5: * raise IOError("iteration on closed file") * elif retval < 0: # <<<<<<<<<<<<<< @@ -9524,7 +10477,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19TabixIteratorParsed_2__next__(stru */ } - /* "pysam/libctabix.pyx":651 + /* "pysam/libctabix.pyx":726 * raise StopIteration * * return self.parser.parse(self.buffer.s, # <<<<<<<<<<<<<< @@ -9533,20 +10486,20 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19TabixIteratorParsed_2__next__(stru */ __Pyx_XDECREF(__pyx_r); - /* "pysam/libctabix.pyx":652 + /* "pysam/libctabix.pyx":727 * * return self.parser.parse(self.buffer.s, * self.buffer.l) # <<<<<<<<<<<<<< * * */ - __pyx_t_2 = ((struct __pyx_vtabstruct_5pysam_9libctabix_Parser *)__pyx_v_self->parser->__pyx_vtab)->parse(__pyx_v_self->parser, __pyx_v_self->__pyx_base.buffer.s, __pyx_v_self->__pyx_base.buffer.l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 651, __pyx_L1_error) + __pyx_t_2 = ((struct __pyx_vtabstruct_5pysam_9libctabix_Parser *)__pyx_v_self->parser->__pyx_vtab)->parse(__pyx_v_self->parser, __pyx_v_self->__pyx_base.buffer.s, __pyx_v_self->__pyx_base.buffer.l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 726, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libctabix.pyx":639 + /* "pysam/libctabix.pyx":714 * self.parser = parser * * def __next__(self): # <<<<<<<<<<<<<< @@ -9600,7 +10553,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19TabixIteratorParsed_4__reduce_cyth * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iterator cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -9657,7 +10610,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19TabixIteratorParsed_6__setstate_cy * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iterator cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -9681,7 +10634,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19TabixIteratorParsed_6__setstate_cy return __pyx_r; } -/* "pysam/libctabix.pyx":656 +/* "pysam/libctabix.pyx":731 * * cdef class GZIterator: * def __init__(self, filename, int buffer_size=65536, encoding="ascii"): # <<<<<<<<<<<<<< @@ -9738,7 +10691,7 @@ static int __pyx_pw_5pysam_9libctabix_10GZIterator_1__init__(PyObject *__pyx_v_s } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 656, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 731, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -9753,7 +10706,7 @@ static int __pyx_pw_5pysam_9libctabix_10GZIterator_1__init__(PyObject *__pyx_v_s } __pyx_v_filename = values[0]; if (values[1]) { - __pyx_v_buffer_size = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_buffer_size == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 656, __pyx_L3_error) + __pyx_v_buffer_size = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_buffer_size == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 731, __pyx_L3_error) } else { __pyx_v_buffer_size = ((int)0x10000); } @@ -9761,7 +10714,7 @@ static int __pyx_pw_5pysam_9libctabix_10GZIterator_1__init__(PyObject *__pyx_v_s } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 656, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 731, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabix.GZIterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -9787,22 +10740,22 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py int __pyx_t_6; char *__pyx_t_7; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 656, 0, __PYX_ERR(0, 656, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 731, 0, __PYX_ERR(0, 731, __pyx_L1_error)); __Pyx_INCREF(__pyx_v_filename); - /* "pysam/libctabix.pyx":660 + /* "pysam/libctabix.pyx":735 * compressed file. * ''' * if not os.path.exists(filename): # <<<<<<<<<<<<<< * raise IOError("No such file or directory: %s" % filename) * */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 660, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 735, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 660, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 735, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_exists); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 660, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_exists); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 735, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; @@ -9816,13 +10769,13 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py } } if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 660, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 735, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_filename}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 660, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 735, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -9830,46 +10783,46 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_filename}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 660, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 735, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 660, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 735, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_filename); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 660, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 735, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 660, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 735, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_6 = ((!__pyx_t_5) != 0); if (unlikely(__pyx_t_6)) { - /* "pysam/libctabix.pyx":661 + /* "pysam/libctabix.pyx":736 * ''' * if not os.path.exists(filename): * raise IOError("No such file or directory: %s" % filename) # <<<<<<<<<<<<<< * * filename = encode_filename(filename) */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_No_such_file_or_directory_s, __pyx_v_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 661, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_No_such_file_or_directory_s, __pyx_v_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 736, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 661, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 736, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 661, __pyx_L1_error) + __PYX_ERR(0, 736, __pyx_L1_error) - /* "pysam/libctabix.pyx":660 + /* "pysam/libctabix.pyx":735 * compressed file. * ''' * if not os.path.exists(filename): # <<<<<<<<<<<<<< @@ -9878,29 +10831,29 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py */ } - /* "pysam/libctabix.pyx":663 + /* "pysam/libctabix.pyx":738 * raise IOError("No such file or directory: %s" % filename) * * filename = encode_filename(filename) # <<<<<<<<<<<<<< * cdef char *cfilename = filename * with nogil: */ - __pyx_t_2 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 663, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 738, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_filename, __pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":664 + /* "pysam/libctabix.pyx":739 * * filename = encode_filename(filename) * cdef char *cfilename = filename # <<<<<<<<<<<<<< * with nogil: * self.gzipfile = bgzf_open(cfilename, "r") */ - __pyx_t_7 = __Pyx_PyObject_AsWritableString(__pyx_v_filename); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 664, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_AsWritableString(__pyx_v_filename); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 739, __pyx_L1_error) __pyx_v_cfilename = __pyx_t_7; - /* "pysam/libctabix.pyx":665 + /* "pysam/libctabix.pyx":740 * filename = encode_filename(filename) * cdef char *cfilename = filename * with nogil: # <<<<<<<<<<<<<< @@ -9915,7 +10868,7 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py #endif /*try:*/ { - /* "pysam/libctabix.pyx":666 + /* "pysam/libctabix.pyx":741 * cdef char *cfilename = filename * with nogil: * self.gzipfile = bgzf_open(cfilename, "r") # <<<<<<<<<<<<<< @@ -9925,7 +10878,7 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py __pyx_v_self->gzipfile = bgzf_open(__pyx_v_cfilename, ((char const *)"r")); } - /* "pysam/libctabix.pyx":665 + /* "pysam/libctabix.pyx":740 * filename = encode_filename(filename) * cdef char *cfilename = filename * with nogil: # <<<<<<<<<<<<<< @@ -9944,7 +10897,7 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py } } - /* "pysam/libctabix.pyx":667 + /* "pysam/libctabix.pyx":742 * with nogil: * self.gzipfile = bgzf_open(cfilename, "r") * self._filename = filename # <<<<<<<<<<<<<< @@ -9957,7 +10910,7 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py __Pyx_DECREF(__pyx_v_self->_filename); __pyx_v_self->_filename = __pyx_v_filename; - /* "pysam/libctabix.pyx":668 + /* "pysam/libctabix.pyx":743 * self.gzipfile = bgzf_open(cfilename, "r") * self._filename = filename * self.kstream = ks_init(self.gzipfile) # <<<<<<<<<<<<<< @@ -9966,7 +10919,7 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py */ __pyx_v_self->kstream = ks_init(__pyx_v_self->gzipfile); - /* "pysam/libctabix.pyx":669 + /* "pysam/libctabix.pyx":744 * self._filename = filename * self.kstream = ks_init(self.gzipfile) * self.encoding = encoding # <<<<<<<<<<<<<< @@ -9979,7 +10932,7 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py __Pyx_DECREF(__pyx_v_self->encoding); __pyx_v_self->encoding = __pyx_v_encoding; - /* "pysam/libctabix.pyx":671 + /* "pysam/libctabix.pyx":746 * self.encoding = encoding * * self.buffer.l = 0 # <<<<<<<<<<<<<< @@ -9988,7 +10941,7 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py */ __pyx_v_self->buffer.l = 0; - /* "pysam/libctabix.pyx":672 + /* "pysam/libctabix.pyx":747 * * self.buffer.l = 0 * self.buffer.m = 0 # <<<<<<<<<<<<<< @@ -9997,7 +10950,7 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py */ __pyx_v_self->buffer.m = 0; - /* "pysam/libctabix.pyx":673 + /* "pysam/libctabix.pyx":748 * self.buffer.l = 0 * self.buffer.m = 0 * self.buffer.s = malloc(buffer_size) # <<<<<<<<<<<<<< @@ -10006,7 +10959,7 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py */ __pyx_v_self->buffer.s = ((char *)malloc(__pyx_v_buffer_size)); - /* "pysam/libctabix.pyx":656 + /* "pysam/libctabix.pyx":731 * * cdef class GZIterator: * def __init__(self, filename, int buffer_size=65536, encoding="ascii"): # <<<<<<<<<<<<<< @@ -10031,7 +10984,7 @@ static int __pyx_pf_5pysam_9libctabix_10GZIterator___init__(struct __pyx_obj_5py return __pyx_r; } -/* "pysam/libctabix.pyx":675 +/* "pysam/libctabix.pyx":750 * self.buffer.s = malloc(buffer_size) * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -10055,9 +11008,9 @@ static void __pyx_pf_5pysam_9libctabix_10GZIterator_2__dealloc__(struct __pyx_ob __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 675, 0, __PYX_ERR(0, 675, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 750, 0, __PYX_ERR(0, 750, __pyx_L1_error)); - /* "pysam/libctabix.pyx":677 + /* "pysam/libctabix.pyx":752 * def __dealloc__(self): * '''close file.''' * if self.gzipfile != NULL: # <<<<<<<<<<<<<< @@ -10067,7 +11020,7 @@ static void __pyx_pf_5pysam_9libctabix_10GZIterator_2__dealloc__(struct __pyx_ob __pyx_t_1 = ((__pyx_v_self->gzipfile != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":678 + /* "pysam/libctabix.pyx":753 * '''close file.''' * if self.gzipfile != NULL: * bgzf_close(self.gzipfile) # <<<<<<<<<<<<<< @@ -10076,7 +11029,7 @@ static void __pyx_pf_5pysam_9libctabix_10GZIterator_2__dealloc__(struct __pyx_ob */ (void)(bgzf_close(__pyx_v_self->gzipfile)); - /* "pysam/libctabix.pyx":679 + /* "pysam/libctabix.pyx":754 * if self.gzipfile != NULL: * bgzf_close(self.gzipfile) * self.gzipfile = NULL # <<<<<<<<<<<<<< @@ -10085,7 +11038,7 @@ static void __pyx_pf_5pysam_9libctabix_10GZIterator_2__dealloc__(struct __pyx_ob */ __pyx_v_self->gzipfile = NULL; - /* "pysam/libctabix.pyx":677 + /* "pysam/libctabix.pyx":752 * def __dealloc__(self): * '''close file.''' * if self.gzipfile != NULL: # <<<<<<<<<<<<<< @@ -10094,7 +11047,7 @@ static void __pyx_pf_5pysam_9libctabix_10GZIterator_2__dealloc__(struct __pyx_ob */ } - /* "pysam/libctabix.pyx":680 + /* "pysam/libctabix.pyx":755 * bgzf_close(self.gzipfile) * self.gzipfile = NULL * if self.buffer.s != NULL: # <<<<<<<<<<<<<< @@ -10104,7 +11057,7 @@ static void __pyx_pf_5pysam_9libctabix_10GZIterator_2__dealloc__(struct __pyx_ob __pyx_t_1 = ((__pyx_v_self->buffer.s != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":681 + /* "pysam/libctabix.pyx":756 * self.gzipfile = NULL * if self.buffer.s != NULL: * free(self.buffer.s) # <<<<<<<<<<<<<< @@ -10113,7 +11066,7 @@ static void __pyx_pf_5pysam_9libctabix_10GZIterator_2__dealloc__(struct __pyx_ob */ free(__pyx_v_self->buffer.s); - /* "pysam/libctabix.pyx":680 + /* "pysam/libctabix.pyx":755 * bgzf_close(self.gzipfile) * self.gzipfile = NULL * if self.buffer.s != NULL: # <<<<<<<<<<<<<< @@ -10122,7 +11075,7 @@ static void __pyx_pf_5pysam_9libctabix_10GZIterator_2__dealloc__(struct __pyx_ob */ } - /* "pysam/libctabix.pyx":682 + /* "pysam/libctabix.pyx":757 * if self.buffer.s != NULL: * free(self.buffer.s) * if self.kstream != NULL: # <<<<<<<<<<<<<< @@ -10132,7 +11085,7 @@ static void __pyx_pf_5pysam_9libctabix_10GZIterator_2__dealloc__(struct __pyx_ob __pyx_t_1 = ((__pyx_v_self->kstream != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":683 + /* "pysam/libctabix.pyx":758 * free(self.buffer.s) * if self.kstream != NULL: * ks_destroy(self.kstream) # <<<<<<<<<<<<<< @@ -10141,7 +11094,7 @@ static void __pyx_pf_5pysam_9libctabix_10GZIterator_2__dealloc__(struct __pyx_ob */ ks_destroy(__pyx_v_self->kstream); - /* "pysam/libctabix.pyx":682 + /* "pysam/libctabix.pyx":757 * if self.buffer.s != NULL: * free(self.buffer.s) * if self.kstream != NULL: # <<<<<<<<<<<<<< @@ -10150,7 +11103,7 @@ static void __pyx_pf_5pysam_9libctabix_10GZIterator_2__dealloc__(struct __pyx_ob */ } - /* "pysam/libctabix.pyx":675 + /* "pysam/libctabix.pyx":750 * self.buffer.s = malloc(buffer_size) * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -10167,7 +11120,7 @@ static void __pyx_pf_5pysam_9libctabix_10GZIterator_2__dealloc__(struct __pyx_ob __Pyx_RefNannyFinishContext(); } -/* "pysam/libctabix.pyx":685 +/* "pysam/libctabix.pyx":760 * ks_destroy(self.kstream) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -10193,9 +11146,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_4__iter__(struct __pyx_ __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 685, 0, __PYX_ERR(0, 685, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 760, 0, __PYX_ERR(0, 760, __pyx_L1_error)); - /* "pysam/libctabix.pyx":686 + /* "pysam/libctabix.pyx":761 * * def __iter__(self): * return self # <<<<<<<<<<<<<< @@ -10207,7 +11160,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_4__iter__(struct __pyx_ __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libctabix.pyx":685 + /* "pysam/libctabix.pyx":760 * ks_destroy(self.kstream) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -10226,7 +11179,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_4__iter__(struct __pyx_ return __pyx_r; } -/* "pysam/libctabix.pyx":688 +/* "pysam/libctabix.pyx":763 * return self * * cdef int __cnext__(self): # <<<<<<<<<<<<<< @@ -10242,9 +11195,9 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__cnext__", 0); - __Pyx_TraceCall("__cnext__", __pyx_f[0], 688, 0, __PYX_ERR(0, 688, __pyx_L1_error)); + __Pyx_TraceCall("__cnext__", __pyx_f[0], 763, 0, __PYX_ERR(0, 763, __pyx_L1_error)); - /* "pysam/libctabix.pyx":689 + /* "pysam/libctabix.pyx":764 * * cdef int __cnext__(self): * cdef int dret = 0 # <<<<<<<<<<<<<< @@ -10253,7 +11206,7 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py */ __pyx_v_dret = 0; - /* "pysam/libctabix.pyx":690 + /* "pysam/libctabix.pyx":765 * cdef int __cnext__(self): * cdef int dret = 0 * cdef int retval = 0 # <<<<<<<<<<<<<< @@ -10262,7 +11215,7 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py */ __pyx_v_retval = 0; - /* "pysam/libctabix.pyx":691 + /* "pysam/libctabix.pyx":766 * cdef int dret = 0 * cdef int retval = 0 * while 1: # <<<<<<<<<<<<<< @@ -10271,7 +11224,7 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py */ while (1) { - /* "pysam/libctabix.pyx":692 + /* "pysam/libctabix.pyx":767 * cdef int retval = 0 * while 1: * with nogil: # <<<<<<<<<<<<<< @@ -10286,7 +11239,7 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py #endif /*try:*/ { - /* "pysam/libctabix.pyx":693 + /* "pysam/libctabix.pyx":768 * while 1: * with nogil: * retval = ks_getuntil(self.kstream, '\n', &self.buffer, &dret) # <<<<<<<<<<<<<< @@ -10296,7 +11249,7 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py __pyx_v_retval = ks_getuntil(__pyx_v_self->kstream, '\n', (&__pyx_v_self->buffer), (&__pyx_v_dret)); } - /* "pysam/libctabix.pyx":692 + /* "pysam/libctabix.pyx":767 * cdef int retval = 0 * while 1: * with nogil: # <<<<<<<<<<<<<< @@ -10315,7 +11268,7 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py } } - /* "pysam/libctabix.pyx":695 + /* "pysam/libctabix.pyx":770 * retval = ks_getuntil(self.kstream, '\n', &self.buffer, &dret) * * if retval < 0: # <<<<<<<<<<<<<< @@ -10325,7 +11278,7 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py __pyx_t_1 = ((__pyx_v_retval < 0) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":696 + /* "pysam/libctabix.pyx":771 * * if retval < 0: * break # <<<<<<<<<<<<<< @@ -10334,7 +11287,7 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py */ goto __pyx_L4_break; - /* "pysam/libctabix.pyx":695 + /* "pysam/libctabix.pyx":770 * retval = ks_getuntil(self.kstream, '\n', &self.buffer, &dret) * * if retval < 0: # <<<<<<<<<<<<<< @@ -10343,7 +11296,7 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py */ } - /* "pysam/libctabix.pyx":698 + /* "pysam/libctabix.pyx":773 * break * * return dret # <<<<<<<<<<<<<< @@ -10355,7 +11308,7 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py } __pyx_L4_break:; - /* "pysam/libctabix.pyx":699 + /* "pysam/libctabix.pyx":774 * * return dret * return -1 # <<<<<<<<<<<<<< @@ -10365,7 +11318,7 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py __pyx_r = -1; goto __pyx_L0; - /* "pysam/libctabix.pyx":688 + /* "pysam/libctabix.pyx":763 * return self * * cdef int __cnext__(self): # <<<<<<<<<<<<<< @@ -10383,7 +11336,7 @@ static int __pyx_f_5pysam_9libctabix_10GZIterator___cnext__(struct __pyx_obj_5py return __pyx_r; } -/* "pysam/libctabix.pyx":701 +/* "pysam/libctabix.pyx":776 * return -1 * * def __next__(self): # <<<<<<<<<<<<<< @@ -10419,9 +11372,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_6__next__(struct __pyx_ PyObject *__pyx_t_4 = NULL; struct __pyx_opt_args_5pysam_9libcutils_force_str __pyx_t_5; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 701, 0, __PYX_ERR(0, 701, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 776, 0, __PYX_ERR(0, 776, __pyx_L1_error)); - /* "pysam/libctabix.pyx":704 + /* "pysam/libctabix.pyx":779 * """python version of next(). * """ * cdef int retval = self.__cnext__() # <<<<<<<<<<<<<< @@ -10430,7 +11383,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_6__next__(struct __pyx_ */ __pyx_v_retval = ((struct __pyx_vtabstruct_5pysam_9libctabix_GZIterator *)__pyx_v_self->__pyx_vtab)->__pyx___cnext__(__pyx_v_self); - /* "pysam/libctabix.pyx":705 + /* "pysam/libctabix.pyx":780 * """ * cdef int retval = self.__cnext__() * if retval < 0: # <<<<<<<<<<<<<< @@ -10440,7 +11393,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_6__next__(struct __pyx_ __pyx_t_1 = ((__pyx_v_retval < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":706 + /* "pysam/libctabix.pyx":781 * cdef int retval = self.__cnext__() * if retval < 0: * raise StopIteration # <<<<<<<<<<<<<< @@ -10448,9 +11401,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_6__next__(struct __pyx_ * */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 706, __pyx_L1_error) + __PYX_ERR(0, 781, __pyx_L1_error) - /* "pysam/libctabix.pyx":705 + /* "pysam/libctabix.pyx":780 * """ * cdef int retval = self.__cnext__() * if retval < 0: # <<<<<<<<<<<<<< @@ -10459,7 +11412,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_6__next__(struct __pyx_ */ } - /* "pysam/libctabix.pyx":707 + /* "pysam/libctabix.pyx":782 * if retval < 0: * raise StopIteration * return force_str(self.buffer.s, self.encoding) # <<<<<<<<<<<<<< @@ -10467,13 +11420,13 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_6__next__(struct __pyx_ * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_self->buffer.s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 707, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_self->buffer.s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 782, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_v_self->encoding; __Pyx_INCREF(__pyx_t_3); __pyx_t_5.__pyx_n = 1; __pyx_t_5.encoding = __pyx_t_3; - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_2, &__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 707, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_2, &__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 782, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -10481,7 +11434,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_6__next__(struct __pyx_ __pyx_t_4 = 0; goto __pyx_L0; - /* "pysam/libctabix.pyx":701 + /* "pysam/libctabix.pyx":776 * return -1 * * def __next__(self): # <<<<<<<<<<<<<< @@ -10537,7 +11490,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_8__reduce_cython__(CYTH * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10594,7 +11547,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_10__setstate_cython__(C * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10618,7 +11571,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10GZIterator_10__setstate_cython__(C return __pyx_r; } -/* "pysam/libctabix.pyx":715 +/* "pysam/libctabix.pyx":790 * ''' * * def __next__(self): # <<<<<<<<<<<<<< @@ -10651,9 +11604,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14GZIteratorHead___next__(struct __p int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 715, 0, __PYX_ERR(0, 715, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 790, 0, __PYX_ERR(0, 790, __pyx_L1_error)); - /* "pysam/libctabix.pyx":718 + /* "pysam/libctabix.pyx":793 * """python version of next(). * """ * cdef int retval = self.__cnext__() # <<<<<<<<<<<<<< @@ -10662,7 +11615,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14GZIteratorHead___next__(struct __p */ __pyx_v_retval = ((struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorHead *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.__pyx___cnext__(((struct __pyx_obj_5pysam_9libctabix_GZIterator *)__pyx_v_self)); - /* "pysam/libctabix.pyx":719 + /* "pysam/libctabix.pyx":794 * """ * cdef int retval = self.__cnext__() * if retval < 0: # <<<<<<<<<<<<<< @@ -10672,7 +11625,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14GZIteratorHead___next__(struct __p __pyx_t_1 = ((__pyx_v_retval < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":720 + /* "pysam/libctabix.pyx":795 * cdef int retval = self.__cnext__() * if retval < 0: * raise StopIteration # <<<<<<<<<<<<<< @@ -10680,9 +11633,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14GZIteratorHead___next__(struct __p * return self.buffer.s */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 720, __pyx_L1_error) + __PYX_ERR(0, 795, __pyx_L1_error) - /* "pysam/libctabix.pyx":719 + /* "pysam/libctabix.pyx":794 * """ * cdef int retval = self.__cnext__() * if retval < 0: # <<<<<<<<<<<<<< @@ -10691,7 +11644,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14GZIteratorHead___next__(struct __p */ } - /* "pysam/libctabix.pyx":721 + /* "pysam/libctabix.pyx":796 * if retval < 0: * raise StopIteration * if self.buffer.s[0] == '#': # <<<<<<<<<<<<<< @@ -10701,7 +11654,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14GZIteratorHead___next__(struct __p __pyx_t_1 = (((__pyx_v_self->__pyx_base.buffer.s[0]) == '#') != 0); if (likely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":722 + /* "pysam/libctabix.pyx":797 * raise StopIteration * if self.buffer.s[0] == '#': * return self.buffer.s # <<<<<<<<<<<<<< @@ -10709,13 +11662,13 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14GZIteratorHead___next__(struct __p * raise StopIteration */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_self->__pyx_base.buffer.s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 722, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_self->__pyx_base.buffer.s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 797, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libctabix.pyx":721 + /* "pysam/libctabix.pyx":796 * if retval < 0: * raise StopIteration * if self.buffer.s[0] == '#': # <<<<<<<<<<<<<< @@ -10724,7 +11677,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14GZIteratorHead___next__(struct __p */ } - /* "pysam/libctabix.pyx":724 + /* "pysam/libctabix.pyx":799 * return self.buffer.s * else: * raise StopIteration # <<<<<<<<<<<<<< @@ -10733,10 +11686,10 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14GZIteratorHead___next__(struct __p */ /*else*/ { __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 724, __pyx_L1_error) + __PYX_ERR(0, 799, __pyx_L1_error) } - /* "pysam/libctabix.pyx":715 + /* "pysam/libctabix.pyx":790 * ''' * * def __next__(self): # <<<<<<<<<<<<<< @@ -10790,7 +11743,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14GZIteratorHead_2__reduce_cython__( * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10847,7 +11800,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14GZIteratorHead_4__setstate_cython_ * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10871,7 +11824,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14GZIteratorHead_4__setstate_cython_ return __pyx_r; } -/* "pysam/libctabix.pyx":732 +/* "pysam/libctabix.pyx":807 * ''' * * def __init__(self, parser): # <<<<<<<<<<<<<< @@ -10905,7 +11858,7 @@ static int __pyx_pw_5pysam_9libctabix_16GZIteratorParsed_1__init__(PyObject *__p else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 732, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 807, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -10916,7 +11869,7 @@ static int __pyx_pw_5pysam_9libctabix_16GZIteratorParsed_1__init__(PyObject *__p } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 732, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 807, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabix.GZIteratorParsed.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -10935,16 +11888,16 @@ static int __pyx_pf_5pysam_9libctabix_16GZIteratorParsed___init__(struct __pyx_o __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 732, 0, __PYX_ERR(0, 732, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 807, 0, __PYX_ERR(0, 807, __pyx_L1_error)); - /* "pysam/libctabix.pyx":733 + /* "pysam/libctabix.pyx":808 * * def __init__(self, parser): * self.parser = parser # <<<<<<<<<<<<<< * * def __next__(self): */ - if (!(likely(((__pyx_v_parser) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_parser, __pyx_ptype_5pysam_9libctabix_Parser))))) __PYX_ERR(0, 733, __pyx_L1_error) + if (!(likely(((__pyx_v_parser) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_parser, __pyx_ptype_5pysam_9libctabix_Parser))))) __PYX_ERR(0, 808, __pyx_L1_error) __pyx_t_1 = __pyx_v_parser; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -10953,7 +11906,7 @@ static int __pyx_pf_5pysam_9libctabix_16GZIteratorParsed___init__(struct __pyx_o __pyx_v_self->parser = ((struct __pyx_obj_5pysam_9libctabix_Parser *)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":732 + /* "pysam/libctabix.pyx":807 * ''' * * def __init__(self, parser): # <<<<<<<<<<<<<< @@ -10974,7 +11927,7 @@ static int __pyx_pf_5pysam_9libctabix_16GZIteratorParsed___init__(struct __pyx_o return __pyx_r; } -/* "pysam/libctabix.pyx":735 +/* "pysam/libctabix.pyx":810 * self.parser = parser * * def __next__(self): # <<<<<<<<<<<<<< @@ -11007,9 +11960,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_16GZIteratorParsed_2__next__(struct int __pyx_t_1; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 735, 0, __PYX_ERR(0, 735, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 810, 0, __PYX_ERR(0, 810, __pyx_L1_error)); - /* "pysam/libctabix.pyx":738 + /* "pysam/libctabix.pyx":813 * """python version of next(). * """ * cdef int retval = self.__cnext__() # <<<<<<<<<<<<<< @@ -11018,7 +11971,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_16GZIteratorParsed_2__next__(struct */ __pyx_v_retval = ((struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorParsed *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.__pyx___cnext__(((struct __pyx_obj_5pysam_9libctabix_GZIterator *)__pyx_v_self)); - /* "pysam/libctabix.pyx":739 + /* "pysam/libctabix.pyx":814 * """ * cdef int retval = self.__cnext__() * if retval < 0: # <<<<<<<<<<<<<< @@ -11028,7 +11981,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_16GZIteratorParsed_2__next__(struct __pyx_t_1 = ((__pyx_v_retval < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":740 + /* "pysam/libctabix.pyx":815 * cdef int retval = self.__cnext__() * if retval < 0: * raise StopIteration # <<<<<<<<<<<<<< @@ -11036,9 +11989,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_16GZIteratorParsed_2__next__(struct * return self.parser.parse(self.buffer.s, */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 740, __pyx_L1_error) + __PYX_ERR(0, 815, __pyx_L1_error) - /* "pysam/libctabix.pyx":739 + /* "pysam/libctabix.pyx":814 * """ * cdef int retval = self.__cnext__() * if retval < 0: # <<<<<<<<<<<<<< @@ -11047,7 +12000,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_16GZIteratorParsed_2__next__(struct */ } - /* "pysam/libctabix.pyx":742 + /* "pysam/libctabix.pyx":817 * raise StopIteration * * return self.parser.parse(self.buffer.s, # <<<<<<<<<<<<<< @@ -11056,20 +12009,20 @@ static PyObject *__pyx_pf_5pysam_9libctabix_16GZIteratorParsed_2__next__(struct */ __Pyx_XDECREF(__pyx_r); - /* "pysam/libctabix.pyx":743 + /* "pysam/libctabix.pyx":818 * * return self.parser.parse(self.buffer.s, * self.buffer.l) # <<<<<<<<<<<<<< * * */ - __pyx_t_2 = ((struct __pyx_vtabstruct_5pysam_9libctabix_Parser *)__pyx_v_self->parser->__pyx_vtab)->parse(__pyx_v_self->parser, __pyx_v_self->__pyx_base.buffer.s, __pyx_v_self->__pyx_base.buffer.l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 742, __pyx_L1_error) + __pyx_t_2 = ((struct __pyx_vtabstruct_5pysam_9libctabix_Parser *)__pyx_v_self->parser->__pyx_vtab)->parse(__pyx_v_self->parser, __pyx_v_self->__pyx_base.buffer.s, __pyx_v_self->__pyx_base.buffer.l); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 817, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libctabix.pyx":735 + /* "pysam/libctabix.pyx":810 * self.parser = parser * * def __next__(self): # <<<<<<<<<<<<<< @@ -11123,7 +12076,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_16GZIteratorParsed_4__reduce_cython_ * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -11180,7 +12133,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_16GZIteratorParsed_6__setstate_cytho * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -11204,7 +12157,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_16GZIteratorParsed_6__setstate_cytho return __pyx_r; } -/* "pysam/libctabix.pyx":746 +/* "pysam/libctabix.pyx":821 * * * def tabix_compress(filename_in, # <<<<<<<<<<<<<< @@ -11227,7 +12180,7 @@ static PyObject *__pyx_pw_5pysam_9libctabix_1tabix_compress(PyObject *__pyx_self static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename_in,&__pyx_n_s_filename_out,&__pyx_n_s_force,0}; PyObject* values[3] = {0,0,0}; - /* "pysam/libctabix.pyx":748 + /* "pysam/libctabix.pyx":823 * def tabix_compress(filename_in, * filename_out, * force=False): # <<<<<<<<<<<<<< @@ -11257,7 +12210,7 @@ static PyObject *__pyx_pw_5pysam_9libctabix_1tabix_compress(PyObject *__pyx_self case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filename_out)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("tabix_compress", 0, 2, 3, 1); __PYX_ERR(0, 746, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("tabix_compress", 0, 2, 3, 1); __PYX_ERR(0, 821, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: @@ -11267,7 +12220,7 @@ static PyObject *__pyx_pw_5pysam_9libctabix_1tabix_compress(PyObject *__pyx_self } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tabix_compress") < 0)) __PYX_ERR(0, 746, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tabix_compress") < 0)) __PYX_ERR(0, 821, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -11285,7 +12238,7 @@ static PyObject *__pyx_pw_5pysam_9libctabix_1tabix_compress(PyObject *__pyx_self } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("tabix_compress", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 746, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("tabix_compress", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 821, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabix.tabix_compress", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -11293,7 +12246,7 @@ static PyObject *__pyx_pw_5pysam_9libctabix_1tabix_compress(PyObject *__pyx_self __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_5pysam_9libctabix_tabix_compress(__pyx_self, __pyx_v_filename_in, __pyx_v_filename_out, __pyx_v_force); - /* "pysam/libctabix.pyx":746 + /* "pysam/libctabix.pyx":821 * * * def tabix_compress(filename_in, # <<<<<<<<<<<<<< @@ -11329,30 +12282,30 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec PyObject *__pyx_t_7 = NULL; int __pyx_t_8; char *__pyx_t_9; - __Pyx_TraceFrameInit(__pyx_codeobj__22) + __Pyx_TraceFrameInit(__pyx_codeobj__21) __Pyx_RefNannySetupContext("tabix_compress", 0); - __Pyx_TraceCall("tabix_compress", __pyx_f[0], 746, 0, __PYX_ERR(0, 746, __pyx_L1_error)); + __Pyx_TraceCall("tabix_compress", __pyx_f[0], 821, 0, __PYX_ERR(0, 821, __pyx_L1_error)); - /* "pysam/libctabix.pyx":755 + /* "pysam/libctabix.pyx":830 * ''' * * if not force and os.path.exists(filename_out): # <<<<<<<<<<<<<< * raise IOError( * "Filename '%s' already exists, use *force* to " */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_force); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 755, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_force); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 830, __pyx_L1_error) __pyx_t_3 = ((!__pyx_t_2) != 0); if (__pyx_t_3) { } else { __pyx_t_1 = __pyx_t_3; goto __pyx_L4_bool_binop_done; } - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 755, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 830, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_path); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 755, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_path); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 830, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_exists); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 755, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_exists); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 830, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = NULL; @@ -11366,13 +12319,13 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec } } if (!__pyx_t_6) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_filename_out); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 755, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_filename_out); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 830, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_filename_out}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 755, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 830, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_4); } else @@ -11380,55 +12333,55 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_filename_out}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 755, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 830, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_4); } else #endif { - __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 755, __pyx_L1_error) + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 830, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v_filename_out); __Pyx_GIVEREF(__pyx_v_filename_out); PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_filename_out); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 755, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 830, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 755, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 830, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_1 = __pyx_t_3; __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":758 + /* "pysam/libctabix.pyx":833 * raise IOError( * "Filename '%s' already exists, use *force* to " * "overwrite" % filename_out) # <<<<<<<<<<<<<< * * cdef int WINDOW_SIZE */ - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Filename_s_already_exists_use_fo, __pyx_v_filename_out); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 758, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Filename_s_already_exists_use_fo, __pyx_v_filename_out); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 833, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libctabix.pyx":756 + /* "pysam/libctabix.pyx":831 * * if not force and os.path.exists(filename_out): * raise IOError( # <<<<<<<<<<<<<< * "Filename '%s' already exists, use *force* to " * "overwrite" % filename_out) */ - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 756, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 831, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 756, __pyx_L1_error) + __PYX_ERR(0, 831, __pyx_L1_error) - /* "pysam/libctabix.pyx":755 + /* "pysam/libctabix.pyx":830 * ''' * * if not force and os.path.exists(filename_out): # <<<<<<<<<<<<<< @@ -11437,7 +12390,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ } - /* "pysam/libctabix.pyx":765 + /* "pysam/libctabix.pyx":840 * cdef BGZF * fp * cdef int fd_src * cdef bint is_empty = True # <<<<<<<<<<<<<< @@ -11446,23 +12399,23 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ __pyx_v_is_empty = 1; - /* "pysam/libctabix.pyx":767 + /* "pysam/libctabix.pyx":842 * cdef bint is_empty = True * cdef int O_RDONLY * O_RDONLY = os.O_RDONLY # <<<<<<<<<<<<<< * * WINDOW_SIZE = 64 * 1024 */ - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 767, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 842, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_O_RDONLY); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 767, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_O_RDONLY); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 842, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 767, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 842, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_O_RDONLY = __pyx_t_8; - /* "pysam/libctabix.pyx":769 + /* "pysam/libctabix.pyx":844 * O_RDONLY = os.O_RDONLY * * WINDOW_SIZE = 64 * 1024 # <<<<<<<<<<<<<< @@ -11471,19 +12424,19 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ __pyx_v_WINDOW_SIZE = 0x10000; - /* "pysam/libctabix.pyx":771 + /* "pysam/libctabix.pyx":846 * WINDOW_SIZE = 64 * 1024 * * fn = encode_filename(filename_out) # <<<<<<<<<<<<<< * cdef char *cfn = fn * with nogil: */ - __pyx_t_4 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename_out); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 771, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename_out); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 846, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_fn = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabix.pyx":772 + /* "pysam/libctabix.pyx":847 * * fn = encode_filename(filename_out) * cdef char *cfn = fn # <<<<<<<<<<<<<< @@ -11492,12 +12445,12 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ if (unlikely(__pyx_v_fn == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 772, __pyx_L1_error) + __PYX_ERR(0, 847, __pyx_L1_error) } - __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_v_fn); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 772, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_v_fn); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 847, __pyx_L1_error) __pyx_v_cfn = __pyx_t_9; - /* "pysam/libctabix.pyx":773 + /* "pysam/libctabix.pyx":848 * fn = encode_filename(filename_out) * cdef char *cfn = fn * with nogil: # <<<<<<<<<<<<<< @@ -11512,7 +12465,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec #endif /*try:*/ { - /* "pysam/libctabix.pyx":774 + /* "pysam/libctabix.pyx":849 * cdef char *cfn = fn * with nogil: * fp = bgzf_open(cfn, "w") # <<<<<<<<<<<<<< @@ -11522,7 +12475,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec __pyx_v_fp = bgzf_open(__pyx_v_cfn, ((char const *)"w")); } - /* "pysam/libctabix.pyx":773 + /* "pysam/libctabix.pyx":848 * fn = encode_filename(filename_out) * cdef char *cfn = fn * with nogil: # <<<<<<<<<<<<<< @@ -11541,7 +12494,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec } } - /* "pysam/libctabix.pyx":775 + /* "pysam/libctabix.pyx":850 * with nogil: * fp = bgzf_open(cfn, "w") * if fp == NULL: # <<<<<<<<<<<<<< @@ -11551,23 +12504,23 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec __pyx_t_1 = ((__pyx_v_fp == NULL) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":776 + /* "pysam/libctabix.pyx":851 * fp = bgzf_open(cfn, "w") * if fp == NULL: * raise IOError("could not open '%s' for writing" % filename_out) # <<<<<<<<<<<<<< * * fn = encode_filename(filename_in) */ - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_s_for_writing, __pyx_v_filename_out); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 776, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_s_for_writing, __pyx_v_filename_out); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 851, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 776, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 851, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 776, __pyx_L1_error) + __PYX_ERR(0, 851, __pyx_L1_error) - /* "pysam/libctabix.pyx":775 + /* "pysam/libctabix.pyx":850 * with nogil: * fp = bgzf_open(cfn, "w") * if fp == NULL: # <<<<<<<<<<<<<< @@ -11576,19 +12529,19 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ } - /* "pysam/libctabix.pyx":778 + /* "pysam/libctabix.pyx":853 * raise IOError("could not open '%s' for writing" % filename_out) * * fn = encode_filename(filename_in) # <<<<<<<<<<<<<< * fd_src = open(fn, O_RDONLY) * if fd_src == 0: */ - __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename_in); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 778, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename_in); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 853, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_fn, ((PyObject*)__pyx_t_5)); __pyx_t_5 = 0; - /* "pysam/libctabix.pyx":779 + /* "pysam/libctabix.pyx":854 * * fn = encode_filename(filename_in) * fd_src = open(fn, O_RDONLY) # <<<<<<<<<<<<<< @@ -11597,12 +12550,12 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ if (unlikely(__pyx_v_fn == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 779, __pyx_L1_error) + __PYX_ERR(0, 854, __pyx_L1_error) } - __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_v_fn); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 779, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyBytes_AsWritableString(__pyx_v_fn); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) __PYX_ERR(0, 854, __pyx_L1_error) __pyx_v_fd_src = open(__pyx_t_9, __pyx_v_O_RDONLY); - /* "pysam/libctabix.pyx":780 + /* "pysam/libctabix.pyx":855 * fn = encode_filename(filename_in) * fd_src = open(fn, O_RDONLY) * if fd_src == 0: # <<<<<<<<<<<<<< @@ -11612,23 +12565,23 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec __pyx_t_1 = ((__pyx_v_fd_src == 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":781 + /* "pysam/libctabix.pyx":856 * fd_src = open(fn, O_RDONLY) * if fd_src == 0: * raise IOError("could not open '%s' for reading" % filename_in) # <<<<<<<<<<<<<< * * buffer = malloc(WINDOW_SIZE) */ - __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_s_for_reading, __pyx_v_filename_in); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 781, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_s_for_reading, __pyx_v_filename_in); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 856, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 781, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 856, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 781, __pyx_L1_error) + __PYX_ERR(0, 856, __pyx_L1_error) - /* "pysam/libctabix.pyx":780 + /* "pysam/libctabix.pyx":855 * fn = encode_filename(filename_in) * fd_src = open(fn, O_RDONLY) * if fd_src == 0: # <<<<<<<<<<<<<< @@ -11637,7 +12590,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ } - /* "pysam/libctabix.pyx":783 + /* "pysam/libctabix.pyx":858 * raise IOError("could not open '%s' for reading" % filename_in) * * buffer = malloc(WINDOW_SIZE) # <<<<<<<<<<<<<< @@ -11646,7 +12599,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ __pyx_v_buffer = malloc(__pyx_v_WINDOW_SIZE); - /* "pysam/libctabix.pyx":784 + /* "pysam/libctabix.pyx":859 * * buffer = malloc(WINDOW_SIZE) * c = 1 # <<<<<<<<<<<<<< @@ -11655,7 +12608,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ __pyx_v_c = 1; - /* "pysam/libctabix.pyx":786 + /* "pysam/libctabix.pyx":861 * c = 1 * * while c > 0: # <<<<<<<<<<<<<< @@ -11666,7 +12619,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec __pyx_t_1 = ((__pyx_v_c > 0) != 0); if (!__pyx_t_1) break; - /* "pysam/libctabix.pyx":787 + /* "pysam/libctabix.pyx":862 * * while c > 0: * with nogil: # <<<<<<<<<<<<<< @@ -11681,7 +12634,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec #endif /*try:*/ { - /* "pysam/libctabix.pyx":788 + /* "pysam/libctabix.pyx":863 * while c > 0: * with nogil: * c = read(fd_src, buffer, WINDOW_SIZE) # <<<<<<<<<<<<<< @@ -11690,7 +12643,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ __pyx_v_c = read(__pyx_v_fd_src, __pyx_v_buffer, __pyx_v_WINDOW_SIZE); - /* "pysam/libctabix.pyx":789 + /* "pysam/libctabix.pyx":864 * with nogil: * c = read(fd_src, buffer, WINDOW_SIZE) * if c > 0: # <<<<<<<<<<<<<< @@ -11700,7 +12653,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec __pyx_t_1 = ((__pyx_v_c > 0) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":790 + /* "pysam/libctabix.pyx":865 * c = read(fd_src, buffer, WINDOW_SIZE) * if c > 0: * is_empty = False # <<<<<<<<<<<<<< @@ -11709,7 +12662,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ __pyx_v_is_empty = 0; - /* "pysam/libctabix.pyx":789 + /* "pysam/libctabix.pyx":864 * with nogil: * c = read(fd_src, buffer, WINDOW_SIZE) * if c > 0: # <<<<<<<<<<<<<< @@ -11718,7 +12671,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ } - /* "pysam/libctabix.pyx":791 + /* "pysam/libctabix.pyx":866 * if c > 0: * is_empty = False * r = bgzf_write(fp, buffer, c) # <<<<<<<<<<<<<< @@ -11728,7 +12681,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec __pyx_v_r = bgzf_write(__pyx_v_fp, __pyx_v_buffer, __pyx_v_c); } - /* "pysam/libctabix.pyx":787 + /* "pysam/libctabix.pyx":862 * * while c > 0: * with nogil: # <<<<<<<<<<<<<< @@ -11747,50 +12700,50 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec } } - /* "pysam/libctabix.pyx":792 + /* "pysam/libctabix.pyx":867 * is_empty = False * r = bgzf_write(fp, buffer, c) * if r < 0: # <<<<<<<<<<<<<< * free(buffer) - * raise OSError("writing failed") + * raise IOError("writing failed") */ __pyx_t_1 = ((__pyx_v_r < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":793 + /* "pysam/libctabix.pyx":868 * r = bgzf_write(fp, buffer, c) * if r < 0: * free(buffer) # <<<<<<<<<<<<<< - * raise OSError("writing failed") + * raise IOError("writing failed") * */ free(__pyx_v_buffer); - /* "pysam/libctabix.pyx":794 + /* "pysam/libctabix.pyx":869 * if r < 0: * free(buffer) - * raise OSError("writing failed") # <<<<<<<<<<<<<< + * raise IOError("writing failed") # <<<<<<<<<<<<<< * * free(buffer) */ - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 794, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 869, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 794, __pyx_L1_error) + __PYX_ERR(0, 869, __pyx_L1_error) - /* "pysam/libctabix.pyx":792 + /* "pysam/libctabix.pyx":867 * is_empty = False * r = bgzf_write(fp, buffer, c) * if r < 0: # <<<<<<<<<<<<<< * free(buffer) - * raise OSError("writing failed") + * raise IOError("writing failed") */ } } - /* "pysam/libctabix.pyx":796 - * raise OSError("writing failed") + /* "pysam/libctabix.pyx":871 + * raise IOError("writing failed") * * free(buffer) # <<<<<<<<<<<<<< * r = bgzf_close(fp) @@ -11798,35 +12751,35 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ free(__pyx_v_buffer); - /* "pysam/libctabix.pyx":797 + /* "pysam/libctabix.pyx":872 * * free(buffer) * r = bgzf_close(fp) # <<<<<<<<<<<<<< * if r < 0: - * raise OSError("error %i when writing to file %s" % (r, filename_out)) + * raise IOError("error %i when writing to file %s" % (r, filename_out)) */ __pyx_v_r = bgzf_close(__pyx_v_fp); - /* "pysam/libctabix.pyx":798 + /* "pysam/libctabix.pyx":873 * free(buffer) * r = bgzf_close(fp) * if r < 0: # <<<<<<<<<<<<<< - * raise OSError("error %i when writing to file %s" % (r, filename_out)) + * raise IOError("error %i when writing to file %s" % (r, filename_out)) * */ __pyx_t_1 = ((__pyx_v_r < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabix.pyx":799 + /* "pysam/libctabix.pyx":874 * r = bgzf_close(fp) * if r < 0: - * raise OSError("error %i when writing to file %s" % (r, filename_out)) # <<<<<<<<<<<<<< + * raise IOError("error %i when writing to file %s" % (r, filename_out)) # <<<<<<<<<<<<<< * * r = close(fd_src) */ - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_r); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 799, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_r); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 874, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 799, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 874, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); @@ -11834,27 +12787,27 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec __Pyx_GIVEREF(__pyx_v_filename_out); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_filename_out); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_error_i_when_writing_to_file_s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 799, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_error_i_when_writing_to_file_s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 874, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_OSError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 799, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 874, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __PYX_ERR(0, 799, __pyx_L1_error) + __PYX_ERR(0, 874, __pyx_L1_error) - /* "pysam/libctabix.pyx":798 + /* "pysam/libctabix.pyx":873 * free(buffer) * r = bgzf_close(fp) * if r < 0: # <<<<<<<<<<<<<< - * raise OSError("error %i when writing to file %s" % (r, filename_out)) + * raise IOError("error %i when writing to file %s" % (r, filename_out)) * */ } - /* "pysam/libctabix.pyx":801 - * raise OSError("error %i when writing to file %s" % (r, filename_out)) + /* "pysam/libctabix.pyx":876 + * raise IOError("error %i when writing to file %s" % (r, filename_out)) * * r = close(fd_src) # <<<<<<<<<<<<<< * # an empty file will return with -1, thus ignore this. @@ -11862,119 +12815,385 @@ static PyObject *__pyx_pf_5pysam_9libctabix_tabix_compress(CYTHON_UNUSED PyObjec */ __pyx_v_r = close(__pyx_v_fd_src); - /* "pysam/libctabix.pyx":803 + /* "pysam/libctabix.pyx":878 * r = close(fd_src) * # an empty file will return with -1, thus ignore this. * if r < 0: # <<<<<<<<<<<<<< * if not (r == -1 and is_empty): - * raise OSError("error %i when closing file %s" % (r, filename_in)) + * raise IOError("error %i when closing file %s" % (r, filename_in)) */ __pyx_t_1 = ((__pyx_v_r < 0) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":804 + /* "pysam/libctabix.pyx":879 * # an empty file will return with -1, thus ignore this. * if r < 0: * if not (r == -1 and is_empty): # <<<<<<<<<<<<<< - * raise OSError("error %i when closing file %s" % (r, filename_in)) + * raise IOError("error %i when closing file %s" % (r, filename_in)) * */ __pyx_t_3 = ((__pyx_v_r == -1L) != 0); if (__pyx_t_3) { - } else { - __pyx_t_1 = __pyx_t_3; - goto __pyx_L23_bool_binop_done; + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L23_bool_binop_done; + } + __pyx_t_3 = (__pyx_v_is_empty != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L23_bool_binop_done:; + __pyx_t_3 = ((!__pyx_t_1) != 0); + if (unlikely(__pyx_t_3)) { + + /* "pysam/libctabix.pyx":880 + * if r < 0: + * if not (r == -1 and is_empty): + * raise IOError("error %i when closing file %s" % (r, filename_in)) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_r); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_INCREF(__pyx_v_filename_in); + __Pyx_GIVEREF(__pyx_v_filename_in); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_filename_in); + __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_error_i_when_closing_file_s, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 880, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 880, __pyx_L1_error) + + /* "pysam/libctabix.pyx":879 + * # an empty file will return with -1, thus ignore this. + * if r < 0: + * if not (r == -1 and is_empty): # <<<<<<<<<<<<<< + * raise IOError("error %i when closing file %s" % (r, filename_in)) + * + */ + } + + /* "pysam/libctabix.pyx":878 + * r = close(fd_src) + * # an empty file will return with -1, thus ignore this. + * if r < 0: # <<<<<<<<<<<<<< + * if not (r == -1 and is_empty): + * raise IOError("error %i when closing file %s" % (r, filename_in)) + */ + } + + /* "pysam/libctabix.pyx":821 + * + * + * def tabix_compress(filename_in, # <<<<<<<<<<<<<< + * filename_out, + * force=False): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libctabix.tabix_compress", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fn); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libctabix.pyx":883 + * + * + * def is_gzip_file(filename): # <<<<<<<<<<<<<< + * gzip_magic_hex = b'1f8b' + * fd = os.open(filename, os.O_RDONLY) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libctabix_3is_gzip_file(PyObject *__pyx_self, PyObject *__pyx_v_filename); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_2is_gzip_file[] = "is_gzip_file(filename)"; +static PyMethodDef __pyx_mdef_5pysam_9libctabix_3is_gzip_file = {"is_gzip_file", (PyCFunction)__pyx_pw_5pysam_9libctabix_3is_gzip_file, METH_O, __pyx_doc_5pysam_9libctabix_2is_gzip_file}; +static PyObject *__pyx_pw_5pysam_9libctabix_3is_gzip_file(PyObject *__pyx_self, PyObject *__pyx_v_filename) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("is_gzip_file (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libctabix_2is_gzip_file(__pyx_self, ((PyObject *)__pyx_v_filename)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_9libctabix_2is_gzip_file(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename) { + PyObject *__pyx_v_gzip_magic_hex = NULL; + PyObject *__pyx_v_fd = NULL; + PyObject *__pyx_v_header = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + __Pyx_TraceFrameInit(__pyx_codeobj__23) + __Pyx_RefNannySetupContext("is_gzip_file", 0); + __Pyx_TraceCall("is_gzip_file", __pyx_f[0], 883, 0, __PYX_ERR(0, 883, __pyx_L1_error)); + + /* "pysam/libctabix.pyx":884 + * + * def is_gzip_file(filename): + * gzip_magic_hex = b'1f8b' # <<<<<<<<<<<<<< + * fd = os.open(filename, os.O_RDONLY) + * header = os.read(fd, 2) + */ + __Pyx_INCREF(__pyx_kp_b_1f8b); + __pyx_v_gzip_magic_hex = __pyx_kp_b_1f8b; + + /* "pysam/libctabix.pyx":885 + * def is_gzip_file(filename): + * gzip_magic_hex = b'1f8b' + * fd = os.open(filename, os.O_RDONLY) # <<<<<<<<<<<<<< + * header = os.read(fd, 2) + * return header == binascii.a2b_hex(gzip_magic_hex) + */ + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 885, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_open_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 885, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 885, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_O_RDONLY); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 885, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_filename, __pyx_t_4}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 885, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_filename, __pyx_t_4}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 885, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 885, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_filename); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 885, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_fd = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pysam/libctabix.pyx":886 + * gzip_magic_hex = b'1f8b' + * fd = os.open(filename, os.O_RDONLY) + * header = os.read(fd, 2) # <<<<<<<<<<<<<< + * return header == binascii.a2b_hex(gzip_magic_hex) + * + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 886, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_read); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 886, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_fd, __pyx_int_2}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 886, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_fd, __pyx_int_2}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 886, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 886, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; } - __pyx_t_3 = (__pyx_v_is_empty != 0); - __pyx_t_1 = __pyx_t_3; - __pyx_L23_bool_binop_done:; - __pyx_t_3 = ((!__pyx_t_1) != 0); - if (unlikely(__pyx_t_3)) { + __Pyx_INCREF(__pyx_v_fd); + __Pyx_GIVEREF(__pyx_v_fd); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_5, __pyx_v_fd); + __Pyx_INCREF(__pyx_int_2); + __Pyx_GIVEREF(__pyx_int_2); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_5, __pyx_int_2); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 886, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_header = __pyx_t_1; + __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":805 - * if r < 0: - * if not (r == -1 and is_empty): - * raise OSError("error %i when closing file %s" % (r, filename_in)) # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":887 + * fd = os.open(filename, os.O_RDONLY) + * header = os.read(fd, 2) + * return header == binascii.a2b_hex(gzip_magic_hex) # <<<<<<<<<<<<<< * * */ - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_r); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 805, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 805, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); - __Pyx_INCREF(__pyx_v_filename_in); - __Pyx_GIVEREF(__pyx_v_filename_in); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_filename_in); - __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_error_i_when_closing_file_s, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 805, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_OSError, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 805, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 805, __pyx_L1_error) - - /* "pysam/libctabix.pyx":804 - * # an empty file will return with -1, thus ignore this. - * if r < 0: - * if not (r == -1 and is_empty): # <<<<<<<<<<<<<< - * raise OSError("error %i when closing file %s" % (r, filename_in)) - * - */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_binascii); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_a2b_hex); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_6) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_gzip_magic_hex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_gzip_magic_hex}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_gzip_magic_hex}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_INCREF(__pyx_v_gzip_magic_hex); + __Pyx_GIVEREF(__pyx_v_gzip_magic_hex); + PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_gzip_magic_hex); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } - - /* "pysam/libctabix.pyx":803 - * r = close(fd_src) - * # an empty file will return with -1, thus ignore this. - * if r < 0: # <<<<<<<<<<<<<< - * if not (r == -1 and is_empty): - * raise OSError("error %i when closing file %s" % (r, filename_in)) - */ } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyObject_RichCompare(__pyx_v_header, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 887, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; - /* "pysam/libctabix.pyx":746 + /* "pysam/libctabix.pyx":883 * * - * def tabix_compress(filename_in, # <<<<<<<<<<<<<< - * filename_out, - * force=False): + * def is_gzip_file(filename): # <<<<<<<<<<<<<< + * gzip_magic_hex = b'1f8b' + * fd = os.open(filename, os.O_RDONLY) */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libctabix.tabix_compress", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.is_gzip_file", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_fn); + __Pyx_XDECREF(__pyx_v_gzip_magic_hex); + __Pyx_XDECREF(__pyx_v_fd); + __Pyx_XDECREF(__pyx_v_header); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabix.pyx":808 +/* "pysam/libctabix.pyx":890 * * - * def tabix_index( filename, # <<<<<<<<<<<<<< - * force = False, - * seq_col = None, + * def tabix_index(filename, # <<<<<<<<<<<<<< + * force=False, + * seq_col=None, */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_3tabix_index(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_2tabix_index[] = "tabix_index(filename, force=False, seq_col=None, start_col=None, end_col=None, preset=None, meta_char='#', zerobased=False, int min_shift=-1)\nindex tab-separated *filename* using tabix.\n\n An existing index will not be overwritten unless\n *force* is set.\n\n The index will be built from coordinates\n in columns *seq_col*, *start_col* and *end_col*.\n\n The contents of *filename* have to be sorted by \n contig and position - the method does not check\n if the file is sorted.\n\n Column indices are 0-based. Coordinates in the file\n are assumed to be 1-based.\n\n If *preset* is provided, the column coordinates\n are taken from a preset. Valid values for preset\n are \"gff\", \"bed\", \"sam\", \"vcf\", psltbl\", \"pileup\".\n \n Lines beginning with *meta_char* and the first\n *line_skip* lines will be skipped.\n \n If *filename* does not end in \".gz\", it will be automatically\n compressed. The original file will be removed and only the \n compressed file will be retained. \n\n If *filename* ends in *gz*, the file is assumed to be already\n compressed with bgzf.\n\n *min-shift* sets the minimal interval size to 1< 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_zerobased); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_line_skip); if (value) { values[7] = value; kw_args--; } } CYTHON_FALLTHROUGH; case 8: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_shift); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_zerobased); if (value) { values[8] = value; kw_args--; } } + CYTHON_FALLTHROUGH; + case 9: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_shift); + if (value) { values[9] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 10: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_index); + if (value) { values[10] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 11: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_keep_original); + if (value) { values[11] = value; kw_args--; } + } + CYTHON_FALLTHROUGH; + case 12: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_csi); + if (value) { values[12] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tabix_index") < 0)) __PYX_ERR(0, 808, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tabix_index") < 0)) __PYX_ERR(0, 890, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); + CYTHON_FALLTHROUGH; + case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); + CYTHON_FALLTHROUGH; + case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); + CYTHON_FALLTHROUGH; + case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); + CYTHON_FALLTHROUGH; case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); CYTHON_FALLTHROUGH; case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); @@ -12157,29 +13447,37 @@ static PyObject *__pyx_pw_5pysam_9libctabix_3tabix_index(PyObject *__pyx_self, P __pyx_v_end_col = values[4]; __pyx_v_preset = values[5]; __pyx_v_meta_char = values[6]; - __pyx_v_zerobased = values[7]; - if (values[8]) { - __pyx_v_min_shift = __Pyx_PyInt_As_int(values[8]); if (unlikely((__pyx_v_min_shift == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 816, __pyx_L3_error) + if (values[7]) { + __pyx_v_line_skip = __Pyx_PyInt_As_int(values[7]); if (unlikely((__pyx_v_line_skip == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 897, __pyx_L3_error) + } else { + __pyx_v_line_skip = ((int)0); + } + __pyx_v_zerobased = values[8]; + if (values[9]) { + __pyx_v_min_shift = __Pyx_PyInt_As_int(values[9]); if (unlikely((__pyx_v_min_shift == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 899, __pyx_L3_error) } else { __pyx_v_min_shift = ((int)-1); } + __pyx_v_index = values[10]; + __pyx_v_keep_original = values[11]; + __pyx_v_csi = values[12]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("tabix_index", 0, 1, 9, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 808, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("tabix_index", 0, 1, 13, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 890, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabix.tabix_index", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libctabix_2tabix_index(__pyx_self, __pyx_v_filename, __pyx_v_force, __pyx_v_seq_col, __pyx_v_start_col, __pyx_v_end_col, __pyx_v_preset, __pyx_v_meta_char, __pyx_v_zerobased, __pyx_v_min_shift); + __pyx_r = __pyx_pf_5pysam_9libctabix_4tabix_index(__pyx_self, __pyx_v_filename, __pyx_v_force, __pyx_v_seq_col, __pyx_v_start_col, __pyx_v_end_col, __pyx_v_preset, __pyx_v_meta_char, __pyx_v_line_skip, __pyx_v_zerobased, __pyx_v_min_shift, __pyx_v_index, __pyx_v_keep_original, __pyx_v_csi); - /* "pysam/libctabix.pyx":808 + /* "pysam/libctabix.pyx":890 * * - * def tabix_index( filename, # <<<<<<<<<<<<<< - * force = False, - * seq_col = None, + * def tabix_index(filename, # <<<<<<<<<<<<<< + * force=False, + * seq_col=None, */ /* function exit code */ @@ -12187,12 +13485,18 @@ static PyObject *__pyx_pw_5pysam_9libctabix_3tabix_index(PyObject *__pyx_self, P return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_force, PyObject *__pyx_v_seq_col, PyObject *__pyx_v_start_col, PyObject *__pyx_v_end_col, PyObject *__pyx_v_preset, PyObject *__pyx_v_meta_char, PyObject *__pyx_v_zerobased, int __pyx_v_min_shift) { +static PyObject *__pyx_pf_5pysam_9libctabix_4tabix_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_force, PyObject *__pyx_v_seq_col, PyObject *__pyx_v_start_col, PyObject *__pyx_v_end_col, PyObject *__pyx_v_preset, PyObject *__pyx_v_meta_char, int __pyx_v_line_skip, PyObject *__pyx_v_zerobased, int __pyx_v_min_shift, PyObject *__pyx_v_index, PyObject *__pyx_v_keep_original, PyObject *__pyx_v_csi) { + PyObject *__pyx_v_fn = NULL; + char *__pyx_v_cfn; + htsFile *__pyx_v_fp; + enum htsExactFormat __pyx_v_fmt; PyObject *__pyx_v_preset2conf = NULL; PyObject *__pyx_v_conf_data = NULL; tbx_conf_t __pyx_v_conf; - PyObject *__pyx_v_fn = NULL; - char *__pyx_v_cfn; + PyObject *__pyx_v_suffix = NULL; + PyObject *__pyx_v_fn_index = NULL; + char *__pyx_v_fnidx; + int __pyx_v_retval; PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -12203,42 +13507,45 @@ static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject int __pyx_t_5; int __pyx_t_6; int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; + char *__pyx_t_8; + enum htsExactFormat __pyx_t_9; PyObject *__pyx_t_10 = NULL; PyObject *__pyx_t_11 = NULL; - int __pyx_t_12; - long __pyx_t_13; + PyObject *__pyx_t_12 = NULL; + int __pyx_t_13; PyObject *__pyx_t_14 = NULL; - PyObject *__pyx_t_15 = NULL; - PyObject *(*__pyx_t_16)(PyObject *); - int32_t __pyx_t_17; - int32_t __pyx_t_18; + long __pyx_t_15; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + PyObject *(*__pyx_t_18)(PyObject *); int32_t __pyx_t_19; int32_t __pyx_t_20; int32_t __pyx_t_21; int32_t __pyx_t_22; - char *__pyx_t_23; + int32_t __pyx_t_23; + int32_t __pyx_t_24; __Pyx_TraceFrameInit(__pyx_codeobj__25) __Pyx_RefNannySetupContext("tabix_index", 0); - __Pyx_TraceCall("tabix_index", __pyx_f[0], 808, 0, __PYX_ERR(0, 808, __pyx_L1_error)); + __Pyx_TraceCall("tabix_index", __pyx_f[0], 890, 0, __PYX_ERR(0, 890, __pyx_L1_error)); __Pyx_INCREF(__pyx_v_filename); __Pyx_INCREF(__pyx_v_end_col); __Pyx_INCREF(__pyx_v_preset); + __Pyx_INCREF(__pyx_v_index); + __Pyx_INCREF(__pyx_v_csi); - /* "pysam/libctabix.pyx":855 + /* "pysam/libctabix.pyx":948 * ''' * * if not os.path.exists(filename): # <<<<<<<<<<<<<< * raise IOError("No such file '%s'" % filename) * */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 855, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 948, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 855, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 948, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_exists); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 855, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_exists); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 948, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; @@ -12252,13 +13559,13 @@ static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject } } if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 948, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_filename}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 948, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -12266,46 +13573,46 @@ static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_filename}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 948, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 855, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 948, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_filename); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 948, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 855, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 948, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_6 = ((!__pyx_t_5) != 0); if (unlikely(__pyx_t_6)) { - /* "pysam/libctabix.pyx":856 + /* "pysam/libctabix.pyx":949 * * if not os.path.exists(filename): * raise IOError("No such file '%s'" % filename) # <<<<<<<<<<<<<< * * if preset is None and \ */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_No_such_file_s, __pyx_v_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 856, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_No_such_file_s, __pyx_v_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 949, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 856, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 949, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 856, __pyx_L1_error) + __PYX_ERR(0, 949, __pyx_L1_error) - /* "pysam/libctabix.pyx":855 + /* "pysam/libctabix.pyx":948 * ''' * * if not os.path.exists(filename): # <<<<<<<<<<<<<< @@ -12314,7 +13621,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject */ } - /* "pysam/libctabix.pyx":858 + /* "pysam/libctabix.pyx":951 * raise IOError("No such file '%s'" % filename) * * if preset is None and \ # <<<<<<<<<<<<<< @@ -12329,7 +13636,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject goto __pyx_L5_bool_binop_done; } - /* "pysam/libctabix.pyx":859 + /* "pysam/libctabix.pyx":952 * * if preset is None and \ * (seq_col is None or start_col is None or end_col is None): # <<<<<<<<<<<<<< @@ -12355,7 +13662,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject __pyx_t_6 = __pyx_t_5; __pyx_L5_bool_binop_done:; - /* "pysam/libctabix.pyx":858 + /* "pysam/libctabix.pyx":951 * raise IOError("No such file '%s'" % filename) * * if preset is None and \ # <<<<<<<<<<<<<< @@ -12364,20 +13671,20 @@ static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject */ if (unlikely(__pyx_t_6)) { - /* "pysam/libctabix.pyx":860 + /* "pysam/libctabix.pyx":953 * if preset is None and \ * (seq_col is None or start_col is None or end_col is None): * raise ValueError( # <<<<<<<<<<<<<< * "neither preset nor seq_col,start_col and end_col given") * */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 860, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 953, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 860, __pyx_L1_error) + __PYX_ERR(0, 953, __pyx_L1_error) - /* "pysam/libctabix.pyx":858 + /* "pysam/libctabix.pyx":951 * raise IOError("No such file '%s'" % filename) * * if preset is None and \ # <<<<<<<<<<<<<< @@ -12386,299 +13693,497 @@ static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject */ } - /* "pysam/libctabix.pyx":863 + /* "pysam/libctabix.pyx":956 * "neither preset nor seq_col,start_col and end_col given") * - * if not filename.endswith(".gz"): # <<<<<<<<<<<<<< + * if not is_gzip_file(filename): # <<<<<<<<<<<<<< * tabix_compress(filename, filename + ".gz", force=force) - * os.unlink( filename ) + * if not keep_original: */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_endswith); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 863, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 863, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_is_gzip_file); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 956, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 863, __pyx_L1_error) + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + if (!__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 956, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filename}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 956, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filename}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 956, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 956, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_filename); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 956, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 956, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_5 = ((!__pyx_t_6) != 0); if (__pyx_t_5) { - /* "pysam/libctabix.pyx":864 + /* "pysam/libctabix.pyx":957 * - * if not filename.endswith(".gz"): + * if not is_gzip_file(filename): * tabix_compress(filename, filename + ".gz", force=force) # <<<<<<<<<<<<<< - * os.unlink( filename ) - * filename += ".gz" + * if not keep_original: + * os.unlink(filename) */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_tabix_compress); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 864, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Add(__pyx_v_filename, __pyx_kp_s_gz); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 864, __pyx_L1_error) + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_tabix_compress); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 957, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 864, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyNumber_Add(__pyx_v_filename, __pyx_kp_s_gz); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 957, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 957, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_filename); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 864, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_force, __pyx_v_force) < 0) __PYX_ERR(0, 864, __pyx_L1_error) - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 864, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_filename); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 957, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_force, __pyx_v_force) < 0) __PYX_ERR(0, 957, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 957, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libctabix.pyx":958 + * if not is_gzip_file(filename): + * tabix_compress(filename, filename + ".gz", force=force) + * if not keep_original: # <<<<<<<<<<<<<< + * os.unlink(filename) + * filename += ".gz" + */ + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_keep_original); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 958, __pyx_L1_error) + __pyx_t_6 = ((!__pyx_t_5) != 0); + if (__pyx_t_6) { - /* "pysam/libctabix.pyx":865 - * if not filename.endswith(".gz"): + /* "pysam/libctabix.pyx":959 * tabix_compress(filename, filename + ".gz", force=force) - * os.unlink( filename ) # <<<<<<<<<<<<<< + * if not keep_original: + * os.unlink(filename) # <<<<<<<<<<<<<< * filename += ".gz" * */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 865, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_unlink); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 865, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (!__pyx_t_2) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 865, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_unlink); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 959, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_filename}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 865, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_filename}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 865, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 865, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __pyx_t_2 = NULL; - __Pyx_INCREF(__pyx_v_filename); - __Pyx_GIVEREF(__pyx_v_filename); - PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_v_filename); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 865, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } } - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (!__pyx_t_1) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_filename); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_filename}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_filename}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL; + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_filename); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 959, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabix.pyx":866 + /* "pysam/libctabix.pyx":958 + * if not is_gzip_file(filename): * tabix_compress(filename, filename + ".gz", force=force) - * os.unlink( filename ) + * if not keep_original: # <<<<<<<<<<<<<< + * os.unlink(filename) + * filename += ".gz" + */ + } + + /* "pysam/libctabix.pyx":960 + * if not keep_original: + * os.unlink(filename) * filename += ".gz" # <<<<<<<<<<<<<< * - * if not force and os.path.exists(filename + ".tbi"): + * fn = encode_filename(filename) */ - __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_filename, __pyx_kp_s_gz); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 866, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF_SET(__pyx_v_filename, __pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_filename, __pyx_kp_s_gz); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 960, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_filename, __pyx_t_4); + __pyx_t_4 = 0; + + /* "pysam/libctabix.pyx":956 + * "neither preset nor seq_col,start_col and end_col given") + * + * if not is_gzip_file(filename): # <<<<<<<<<<<<<< + * tabix_compress(filename, filename + ".gz", force=force) + * if not keep_original: + */ + } + + /* "pysam/libctabix.pyx":962 + * filename += ".gz" + * + * fn = encode_filename(filename) # <<<<<<<<<<<<<< + * cdef char *cfn = fn + * + */ + __pyx_t_4 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 962, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_fn = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libctabix.pyx":863 - * "neither preset nor seq_col,start_col and end_col given") + /* "pysam/libctabix.pyx":963 * - * if not filename.endswith(".gz"): # <<<<<<<<<<<<<< - * tabix_compress(filename, filename + ".gz", force=force) - * os.unlink( filename ) + * fn = encode_filename(filename) + * cdef char *cfn = fn # <<<<<<<<<<<<<< + * + * cdef htsFile *fp = hts_open(cfn, "r") */ + if (unlikely(__pyx_v_fn == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 963, __pyx_L1_error) } + __pyx_t_8 = __Pyx_PyBytes_AsWritableString(__pyx_v_fn); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 963, __pyx_L1_error) + __pyx_v_cfn = __pyx_t_8; - /* "pysam/libctabix.pyx":868 - * filename += ".gz" + /* "pysam/libctabix.pyx":965 + * cdef char *cfn = fn * - * if not force and os.path.exists(filename + ".tbi"): # <<<<<<<<<<<<<< - * raise IOError( - * "Filename '%s.tbi' already exists, use *force* to overwrite") + * cdef htsFile *fp = hts_open(cfn, "r") # <<<<<<<<<<<<<< + * cdef htsExactFormat fmt = fp.format.format + * hts_close(fp) */ - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_force); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 868, __pyx_L1_error) - __pyx_t_7 = ((!__pyx_t_6) != 0); - if (__pyx_t_7) { - } else { - __pyx_t_5 = __pyx_t_7; - goto __pyx_L11_bool_binop_done; - } - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 868, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 868, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_exists); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 868, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Add(__pyx_v_filename, __pyx_kp_s_tbi); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 868, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (!__pyx_t_2) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 868, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_1}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 868, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_1}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 868, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else - #endif - { - __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 868, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); __pyx_t_2 = NULL; - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 868, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 868, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __pyx_t_7; - __pyx_L11_bool_binop_done:; - if (unlikely(__pyx_t_5)) { + __pyx_v_fp = hts_open(__pyx_v_cfn, ((char const *)"r")); - /* "pysam/libctabix.pyx":869 + /* "pysam/libctabix.pyx":966 * - * if not force and os.path.exists(filename + ".tbi"): - * raise IOError( # <<<<<<<<<<<<<< - * "Filename '%s.tbi' already exists, use *force* to overwrite") + * cdef htsFile *fp = hts_open(cfn, "r") + * cdef htsExactFormat fmt = fp.format.format # <<<<<<<<<<<<<< + * hts_close(fp) * */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 869, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 869, __pyx_L1_error) + __pyx_t_9 = __pyx_v_fp->format.format; + __pyx_v_fmt = __pyx_t_9; - /* "pysam/libctabix.pyx":868 - * filename += ".gz" + /* "pysam/libctabix.pyx":967 + * cdef htsFile *fp = hts_open(cfn, "r") + * cdef htsExactFormat fmt = fp.format.format + * hts_close(fp) # <<<<<<<<<<<<<< * - * if not force and os.path.exists(filename + ".tbi"): # <<<<<<<<<<<<<< - * raise IOError( - * "Filename '%s.tbi' already exists, use *force* to overwrite") + * # columns (1-based): */ - } + (void)(hts_close(__pyx_v_fp)); - /* "pysam/libctabix.pyx":877 + /* "pysam/libctabix.pyx":974 * # 0 is a missing column * preset2conf = { - * 'gff' : (0, 1, 4, 5, ord('#'), 0), # <<<<<<<<<<<<<< - * 'bed' : (0x10000, 1, 2, 3, ord('#'), 0), - * 'psltbl' : (0x10000, 15, 17, 18, ord('#'), 0), + * 'gff' : (TBX_GENERIC, 1, 4, 5, ord('#'), 0), # <<<<<<<<<<<<<< + * 'bed' : (TBX_UCSC, 1, 2, 3, ord('#'), 0), + * 'psltbl' : (TBX_UCSC, 15, 17, 18, ord('#'), 0), */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 877, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 974, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyInt_From_int8_t(TBX_GENERIC); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 974, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_gff, __pyx_tuple__29) < 0) __PYX_ERR(0, 877, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 974, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_1); + __Pyx_INCREF(__pyx_int_4); + __Pyx_GIVEREF(__pyx_int_4); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_4); + __Pyx_INCREF(__pyx_int_5); + __Pyx_GIVEREF(__pyx_int_5); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_int_5); + __Pyx_INCREF(__pyx_int_35); + __Pyx_GIVEREF(__pyx_int_35); + PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_int_35); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 5, __pyx_int_0); + __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_gff, __pyx_t_2) < 0) __PYX_ERR(0, 974, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":878 + /* "pysam/libctabix.pyx":975 * preset2conf = { - * 'gff' : (0, 1, 4, 5, ord('#'), 0), - * 'bed' : (0x10000, 1, 2, 3, ord('#'), 0), # <<<<<<<<<<<<<< - * 'psltbl' : (0x10000, 15, 17, 18, ord('#'), 0), - * 'sam' : (1, 3, 4, 0, ord('@'), 0), - */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_bed, __pyx_tuple__30) < 0) __PYX_ERR(0, 877, __pyx_L1_error) - - /* "pysam/libctabix.pyx":879 - * 'gff' : (0, 1, 4, 5, ord('#'), 0), - * 'bed' : (0x10000, 1, 2, 3, ord('#'), 0), - * 'psltbl' : (0x10000, 15, 17, 18, ord('#'), 0), # <<<<<<<<<<<<<< - * 'sam' : (1, 3, 4, 0, ord('@'), 0), - * 'vcf' : (2, 1, 2, 0, ord('#'), 0), - */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_psltbl, __pyx_tuple__31) < 0) __PYX_ERR(0, 877, __pyx_L1_error) - - /* "pysam/libctabix.pyx":880 - * 'bed' : (0x10000, 1, 2, 3, ord('#'), 0), - * 'psltbl' : (0x10000, 15, 17, 18, ord('#'), 0), - * 'sam' : (1, 3, 4, 0, ord('@'), 0), # <<<<<<<<<<<<<< - * 'vcf' : (2, 1, 2, 0, ord('#'), 0), - * 'pileup': (3, 1, 2, 0, ord('#'), 0), - */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_sam, __pyx_tuple__32) < 0) __PYX_ERR(0, 877, __pyx_L1_error) - - /* "pysam/libctabix.pyx":881 - * 'psltbl' : (0x10000, 15, 17, 18, ord('#'), 0), - * 'sam' : (1, 3, 4, 0, ord('@'), 0), - * 'vcf' : (2, 1, 2, 0, ord('#'), 0), # <<<<<<<<<<<<<< - * 'pileup': (3, 1, 2, 0, ord('#'), 0), + * 'gff' : (TBX_GENERIC, 1, 4, 5, ord('#'), 0), + * 'bed' : (TBX_UCSC, 1, 2, 3, ord('#'), 0), # <<<<<<<<<<<<<< + * 'psltbl' : (TBX_UCSC, 15, 17, 18, ord('#'), 0), + * 'sam' : (TBX_SAM, 3, 4, 0, ord('@'), 0), + */ + __pyx_t_2 = __Pyx_PyInt_From_int8_t(TBX_UCSC); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 975, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 975, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_1); + __Pyx_INCREF(__pyx_int_2); + __Pyx_GIVEREF(__pyx_int_2); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_2); + __Pyx_INCREF(__pyx_int_3); + __Pyx_GIVEREF(__pyx_int_3); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_int_3); + __Pyx_INCREF(__pyx_int_35); + __Pyx_GIVEREF(__pyx_int_35); + PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_int_35); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_int_0); + __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_bed, __pyx_t_3) < 0) __PYX_ERR(0, 974, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libctabix.pyx":976 + * 'gff' : (TBX_GENERIC, 1, 4, 5, ord('#'), 0), + * 'bed' : (TBX_UCSC, 1, 2, 3, ord('#'), 0), + * 'psltbl' : (TBX_UCSC, 15, 17, 18, ord('#'), 0), # <<<<<<<<<<<<<< + * 'sam' : (TBX_SAM, 3, 4, 0, ord('@'), 0), + * 'vcf' : (TBX_VCF, 1, 2, 0, ord('#'), 0), + */ + __pyx_t_3 = __Pyx_PyInt_From_int8_t(TBX_UCSC); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 976, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 976, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_int_15); + __Pyx_GIVEREF(__pyx_int_15); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_15); + __Pyx_INCREF(__pyx_int_17); + __Pyx_GIVEREF(__pyx_int_17); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_17); + __Pyx_INCREF(__pyx_int_18); + __Pyx_GIVEREF(__pyx_int_18); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_int_18); + __Pyx_INCREF(__pyx_int_35); + __Pyx_GIVEREF(__pyx_int_35); + PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_int_35); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 5, __pyx_int_0); + __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_psltbl, __pyx_t_2) < 0) __PYX_ERR(0, 974, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libctabix.pyx":977 + * 'bed' : (TBX_UCSC, 1, 2, 3, ord('#'), 0), + * 'psltbl' : (TBX_UCSC, 15, 17, 18, ord('#'), 0), + * 'sam' : (TBX_SAM, 3, 4, 0, ord('@'), 0), # <<<<<<<<<<<<<< + * 'vcf' : (TBX_VCF, 1, 2, 0, ord('#'), 0), * } */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_vcf, __pyx_tuple__33) < 0) __PYX_ERR(0, 877, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int8_t(TBX_SAM); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 977, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 977, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_INCREF(__pyx_int_3); + __Pyx_GIVEREF(__pyx_int_3); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_3); + __Pyx_INCREF(__pyx_int_4); + __Pyx_GIVEREF(__pyx_int_4); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_4); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_int_0); + __Pyx_INCREF(__pyx_int_64); + __Pyx_GIVEREF(__pyx_int_64); + PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_int_64); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_int_0); + __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_sam, __pyx_t_3) < 0) __PYX_ERR(0, 974, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libctabix.pyx":882 - * 'sam' : (1, 3, 4, 0, ord('@'), 0), - * 'vcf' : (2, 1, 2, 0, ord('#'), 0), - * 'pileup': (3, 1, 2, 0, ord('#'), 0), # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":978 + * 'psltbl' : (TBX_UCSC, 15, 17, 18, ord('#'), 0), + * 'sam' : (TBX_SAM, 3, 4, 0, ord('@'), 0), + * 'vcf' : (TBX_VCF, 1, 2, 0, ord('#'), 0), # <<<<<<<<<<<<<< * } * */ - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_pileup, __pyx_tuple__34) < 0) __PYX_ERR(0, 877, __pyx_L1_error) - __pyx_v_preset2conf = ((PyObject*)__pyx_t_3); + __pyx_t_3 = __Pyx_PyInt_From_int8_t(TBX_VCF); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 978, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 978, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_1); + __Pyx_INCREF(__pyx_int_2); + __Pyx_GIVEREF(__pyx_int_2); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_2); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_int_0); + __Pyx_INCREF(__pyx_int_35); + __Pyx_GIVEREF(__pyx_int_35); + PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_int_35); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_2, 5, __pyx_int_0); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_vcf, __pyx_t_2) < 0) __PYX_ERR(0, 974, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_preset2conf = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libctabix.pyx":885 + /* "pysam/libctabix.pyx":981 * } * - * if preset: # <<<<<<<<<<<<<< + * conf_data = None # <<<<<<<<<<<<<< + * if preset == "bcf" or fmt == bcf: + * csi = True + */ + __Pyx_INCREF(Py_None); + __pyx_v_conf_data = Py_None; + + /* "pysam/libctabix.pyx":982 + * + * conf_data = None + * if preset == "bcf" or fmt == bcf: # <<<<<<<<<<<<<< + * csi = True + * if min_shift == -1: + */ + __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_v_preset, __pyx_n_s_bcf, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 982, __pyx_L1_error) + if (!__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L12_bool_binop_done; + } + __pyx_t_5 = ((__pyx_v_fmt == bcf) != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L12_bool_binop_done:; + if (__pyx_t_6) { + + /* "pysam/libctabix.pyx":983 + * conf_data = None + * if preset == "bcf" or fmt == bcf: + * csi = True # <<<<<<<<<<<<<< + * if min_shift == -1: + * min_shift = 14 + */ + __Pyx_INCREF(Py_True); + __Pyx_DECREF_SET(__pyx_v_csi, Py_True); + + /* "pysam/libctabix.pyx":984 + * if preset == "bcf" or fmt == bcf: + * csi = True + * if min_shift == -1: # <<<<<<<<<<<<<< + * min_shift = 14 + * elif preset: + */ + __pyx_t_6 = ((__pyx_v_min_shift == -1L) != 0); + if (__pyx_t_6) { + + /* "pysam/libctabix.pyx":985 + * csi = True + * if min_shift == -1: + * min_shift = 14 # <<<<<<<<<<<<<< + * elif preset: * try: - * conf_data = preset2conf[preset] */ - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_preset); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 885, __pyx_L1_error) - if (__pyx_t_5) { + __pyx_v_min_shift = 14; + + /* "pysam/libctabix.pyx":984 + * if preset == "bcf" or fmt == bcf: + * csi = True + * if min_shift == -1: # <<<<<<<<<<<<<< + * min_shift = 14 + * elif preset: + */ + } - /* "pysam/libctabix.pyx":886 + /* "pysam/libctabix.pyx":982 * - * if preset: + * conf_data = None + * if preset == "bcf" or fmt == bcf: # <<<<<<<<<<<<<< + * csi = True + * if min_shift == -1: + */ + goto __pyx_L11; + } + + /* "pysam/libctabix.pyx":986 + * if min_shift == -1: + * min_shift = 14 + * elif preset: # <<<<<<<<<<<<<< + * try: + * conf_data = preset2conf[preset] + */ + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_preset); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 986, __pyx_L1_error) + if (__pyx_t_6) { + + /* "pysam/libctabix.pyx":987 + * min_shift = 14 + * elif preset: * try: # <<<<<<<<<<<<<< * conf_data = preset2conf[preset] * except KeyError: @@ -12686,407 +14191,761 @@ static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject { __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); - __Pyx_XGOTREF(__pyx_t_9); + __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); __Pyx_XGOTREF(__pyx_t_10); __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); /*try:*/ { - /* "pysam/libctabix.pyx":887 - * if preset: + /* "pysam/libctabix.pyx":988 + * elif preset: * try: * conf_data = preset2conf[preset] # <<<<<<<<<<<<<< * except KeyError: * raise KeyError( */ - __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_preset2conf, __pyx_v_preset); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 887, __pyx_L14_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_conf_data = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_preset2conf, __pyx_v_preset); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 988, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_conf_data, __pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libctabix.pyx":886 - * - * if preset: + /* "pysam/libctabix.pyx":987 + * min_shift = 14 + * elif preset: * try: # <<<<<<<<<<<<<< * conf_data = preset2conf[preset] * except KeyError: */ } - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L19_try_end; - __pyx_L14_error:; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L20_try_end; + __pyx_L15_error:; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabix.pyx":888 + /* "pysam/libctabix.pyx":989 * try: * conf_data = preset2conf[preset] * except KeyError: # <<<<<<<<<<<<<< * raise KeyError( * "unknown preset '%s', valid presets are '%s'" % */ - __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); - if (__pyx_t_12) { + __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); + if (__pyx_t_13) { __Pyx_AddTraceback("pysam.libctabix.tabix_index", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_8) < 0) __PYX_ERR(0, 888, __pyx_L16_except_error) - __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_2, &__pyx_t_3) < 0) __PYX_ERR(0, 989, __pyx_L17_except_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_3); - /* "pysam/libctabix.pyx":891 + /* "pysam/libctabix.pyx":992 * raise KeyError( * "unknown preset '%s', valid presets are '%s'" % * (preset, ",".join(preset2conf.keys()))) # <<<<<<<<<<<<<< * else: - * if end_col == None: + * if end_col is None: */ - __pyx_t_1 = __Pyx_PyDict_Keys(__pyx_v_preset2conf); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 891, __pyx_L16_except_error) + __pyx_t_1 = __Pyx_PyDict_Keys(__pyx_v_preset2conf); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 992, __pyx_L17_except_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__35, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 891, __pyx_L16_except_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyString_Join(__pyx_kp_s__27, __pyx_t_1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 992, __pyx_L17_except_error) + __Pyx_GOTREF(__pyx_t_14); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 891, __pyx_L16_except_error) + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 992, __pyx_L17_except_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_preset); __Pyx_GIVEREF(__pyx_v_preset); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_preset); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); - __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_14); + __pyx_t_14 = 0; - /* "pysam/libctabix.pyx":890 + /* "pysam/libctabix.pyx":991 * except KeyError: * raise KeyError( * "unknown preset '%s', valid presets are '%s'" % # <<<<<<<<<<<<<< * (preset, ",".join(preset2conf.keys()))) * else: */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_unknown_preset_s_valid_presets_a, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 890, __pyx_L16_except_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = __Pyx_PyString_Format(__pyx_kp_s_unknown_preset_s_valid_presets_a, __pyx_t_1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 991, __pyx_L17_except_error) + __Pyx_GOTREF(__pyx_t_14); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":889 + /* "pysam/libctabix.pyx":990 * conf_data = preset2conf[preset] * except KeyError: * raise KeyError( # <<<<<<<<<<<<<< * "unknown preset '%s', valid presets are '%s'" % * (preset, ",".join(preset2conf.keys()))) */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 889, __pyx_L16_except_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 889, __pyx_L16_except_error) - } - goto __pyx_L16_except_error; - __pyx_L16_except_error:; + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 990, __pyx_L17_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 990, __pyx_L17_except_error) + } + goto __pyx_L17_except_error; + __pyx_L17_except_error:; + + /* "pysam/libctabix.pyx":987 + * min_shift = 14 + * elif preset: + * try: # <<<<<<<<<<<<<< + * conf_data = preset2conf[preset] + * except KeyError: + */ + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L1_error; + __pyx_L20_try_end:; + } + + /* "pysam/libctabix.pyx":986 + * if min_shift == -1: + * min_shift = 14 + * elif preset: # <<<<<<<<<<<<<< + * try: + * conf_data = preset2conf[preset] + */ + goto __pyx_L11; + } + + /* "pysam/libctabix.pyx":994 + * (preset, ",".join(preset2conf.keys()))) + * else: + * if end_col is None: # <<<<<<<<<<<<<< + * end_col = -1 + * + */ + /*else*/ { + __pyx_t_6 = (__pyx_v_end_col == Py_None); + __pyx_t_5 = (__pyx_t_6 != 0); + if (__pyx_t_5) { + + /* "pysam/libctabix.pyx":995 + * else: + * if end_col is None: + * end_col = -1 # <<<<<<<<<<<<<< + * + * preset = 0 + */ + __Pyx_INCREF(__pyx_int_neg_1); + __Pyx_DECREF_SET(__pyx_v_end_col, __pyx_int_neg_1); + + /* "pysam/libctabix.pyx":994 + * (preset, ",".join(preset2conf.keys()))) + * else: + * if end_col is None: # <<<<<<<<<<<<<< + * end_col = -1 + * + */ + } + + /* "pysam/libctabix.pyx":997 + * end_col = -1 + * + * preset = 0 # <<<<<<<<<<<<<< + * # tabix internally works with 0-based coordinates and + * # open/closed intervals. When using a preset, conversion is + */ + __Pyx_INCREF(__pyx_int_0); + __Pyx_DECREF_SET(__pyx_v_preset, __pyx_int_0); + + /* "pysam/libctabix.pyx":1004 + * # from the start coordinate. To avoid doing this, set the + * # TI_FLAG_UCSC=0x10000 flag: + * if zerobased: # <<<<<<<<<<<<<< + * preset = preset | TBX_UCSC + * + */ + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_zerobased); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1004, __pyx_L1_error) + if (__pyx_t_5) { + + /* "pysam/libctabix.pyx":1005 + * # TI_FLAG_UCSC=0x10000 flag: + * if zerobased: + * preset = preset | TBX_UCSC # <<<<<<<<<<<<<< + * + * conf_data = (preset, seq_col + 1, start_col + 1, end_col + 1, ord(meta_char), line_skip) + */ + __pyx_t_3 = __Pyx_PyInt_From_int8_t(TBX_UCSC); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1005, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyNumber_Or(__pyx_v_preset, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1005, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF_SET(__pyx_v_preset, __pyx_t_2); + __pyx_t_2 = 0; + + /* "pysam/libctabix.pyx":1004 + * # from the start coordinate. To avoid doing this, set the + * # TI_FLAG_UCSC=0x10000 flag: + * if zerobased: # <<<<<<<<<<<<<< + * preset = preset | TBX_UCSC + * + */ + } + + /* "pysam/libctabix.pyx":1007 + * preset = preset | TBX_UCSC + * + * conf_data = (preset, seq_col + 1, start_col + 1, end_col + 1, ord(meta_char), line_skip) # <<<<<<<<<<<<<< + * + * cdef tbx_conf_t conf + */ + __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_seq_col, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1007, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_start_col, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1007, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_end_col, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1007, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_15 = __Pyx_PyObject_Ord(__pyx_v_meta_char); if (unlikely(__pyx_t_15 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 1007, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1007, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = __Pyx_PyInt_From_int(__pyx_v_line_skip); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1007, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_16 = PyTuple_New(6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1007, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_INCREF(__pyx_v_preset); + __Pyx_GIVEREF(__pyx_v_preset); + PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_v_preset); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_16, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_16, 3, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_16, 4, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_16, 5, __pyx_t_14); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_t_14 = 0; + __Pyx_DECREF_SET(__pyx_v_conf_data, __pyx_t_16); + __pyx_t_16 = 0; + } + __pyx_L11:; + + /* "pysam/libctabix.pyx":1010 + * + * cdef tbx_conf_t conf + * if conf_data: # <<<<<<<<<<<<<< + * conf.preset, conf.sc, conf.bc, conf.ec, conf.meta_char, conf.line_skip = conf_data + * + */ + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_conf_data); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1010, __pyx_L1_error) + if (__pyx_t_5) { + + /* "pysam/libctabix.pyx":1011 + * cdef tbx_conf_t conf + * if conf_data: + * conf.preset, conf.sc, conf.bc, conf.ec, conf.meta_char, conf.line_skip = conf_data # <<<<<<<<<<<<<< + * + * if csi: + */ + if ((likely(PyTuple_CheckExact(__pyx_v_conf_data))) || (PyList_CheckExact(__pyx_v_conf_data))) { + PyObject* sequence = __pyx_v_conf_data; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 6)) { + if (size > 6) __Pyx_RaiseTooManyValuesError(6); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1011, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_16 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_14 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 3); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 4); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 5); + } else { + __pyx_t_16 = PyList_GET_ITEM(sequence, 0); + __pyx_t_14 = PyList_GET_ITEM(sequence, 1); + __pyx_t_1 = PyList_GET_ITEM(sequence, 2); + __pyx_t_4 = PyList_GET_ITEM(sequence, 3); + __pyx_t_3 = PyList_GET_ITEM(sequence, 4); + __pyx_t_2 = PyList_GET_ITEM(sequence, 5); + } + __Pyx_INCREF(__pyx_t_16); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + #else + { + Py_ssize_t i; + PyObject** temps[6] = {&__pyx_t_16,&__pyx_t_14,&__pyx_t_1,&__pyx_t_4,&__pyx_t_3,&__pyx_t_2}; + for (i=0; i < 6; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1011, __pyx_L1_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; + } + } + #endif + } else { + Py_ssize_t index = -1; + PyObject** temps[6] = {&__pyx_t_16,&__pyx_t_14,&__pyx_t_1,&__pyx_t_4,&__pyx_t_3,&__pyx_t_2}; + __pyx_t_17 = PyObject_GetIter(__pyx_v_conf_data); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1011, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_18 = Py_TYPE(__pyx_t_17)->tp_iternext; + for (index=0; index < 6; index++) { + PyObject* item = __pyx_t_18(__pyx_t_17); if (unlikely(!item)) goto __pyx_L26_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_18(__pyx_t_17), 6) < 0) __PYX_ERR(0, 1011, __pyx_L1_error) + __pyx_t_18 = NULL; + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + goto __pyx_L27_unpacking_done; + __pyx_L26_unpacking_failed:; + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_18 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1011, __pyx_L1_error) + __pyx_L27_unpacking_done:; + } + __pyx_t_19 = __Pyx_PyInt_As_int32_t(__pyx_t_16); if (unlikely((__pyx_t_19 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1011, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_20 = __Pyx_PyInt_As_int32_t(__pyx_t_14); if (unlikely((__pyx_t_20 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1011, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_21 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_21 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1011, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_22 = __Pyx_PyInt_As_int32_t(__pyx_t_4); if (unlikely((__pyx_t_22 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1011, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_23 = __Pyx_PyInt_As_int32_t(__pyx_t_3); if (unlikely((__pyx_t_23 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1011, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_24 = __Pyx_PyInt_As_int32_t(__pyx_t_2); if (unlikely((__pyx_t_24 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1011, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_conf.preset = __pyx_t_19; + __pyx_v_conf.sc = __pyx_t_20; + __pyx_v_conf.bc = __pyx_t_21; + __pyx_v_conf.ec = __pyx_t_22; + __pyx_v_conf.meta_char = __pyx_t_23; + __pyx_v_conf.line_skip = __pyx_t_24; + + /* "pysam/libctabix.pyx":1010 + * + * cdef tbx_conf_t conf + * if conf_data: # <<<<<<<<<<<<<< + * conf.preset, conf.sc, conf.bc, conf.ec, conf.meta_char, conf.line_skip = conf_data + * + */ + } + + /* "pysam/libctabix.pyx":1013 + * conf.preset, conf.sc, conf.bc, conf.ec, conf.meta_char, conf.line_skip = conf_data + * + * if csi: # <<<<<<<<<<<<<< + * suffix = ".csi" + * else: + */ + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_csi); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1013, __pyx_L1_error) + if (__pyx_t_5) { - /* "pysam/libctabix.pyx":886 + /* "pysam/libctabix.pyx":1014 * - * if preset: - * try: # <<<<<<<<<<<<<< - * conf_data = preset2conf[preset] - * except KeyError: + * if csi: + * suffix = ".csi" # <<<<<<<<<<<<<< + * else: + * suffix = ".tbi" */ - __Pyx_XGIVEREF(__pyx_t_9); - __Pyx_XGIVEREF(__pyx_t_10); - __Pyx_XGIVEREF(__pyx_t_11); - __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); - goto __pyx_L1_error; - __pyx_L19_try_end:; - } + __Pyx_INCREF(__pyx_kp_s_csi_2); + __pyx_v_suffix = __pyx_kp_s_csi_2; - /* "pysam/libctabix.pyx":885 - * } + /* "pysam/libctabix.pyx":1013 + * conf.preset, conf.sc, conf.bc, conf.ec, conf.meta_char, conf.line_skip = conf_data * - * if preset: # <<<<<<<<<<<<<< - * try: - * conf_data = preset2conf[preset] + * if csi: # <<<<<<<<<<<<<< + * suffix = ".csi" + * else: */ - goto __pyx_L13; + goto __pyx_L28; } - /* "pysam/libctabix.pyx":893 - * (preset, ",".join(preset2conf.keys()))) + /* "pysam/libctabix.pyx":1016 + * suffix = ".csi" * else: - * if end_col == None: # <<<<<<<<<<<<<< - * end_col = -1 - * preset = 0 + * suffix = ".tbi" # <<<<<<<<<<<<<< + * index = index or filename + suffix + * fn_index = encode_filename(index) */ /*else*/ { - __pyx_t_8 = PyObject_RichCompare(__pyx_v_end_col, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 893, __pyx_L1_error) - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 893, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__pyx_t_5) { + __Pyx_INCREF(__pyx_kp_s_tbi); + __pyx_v_suffix = __pyx_kp_s_tbi; + } + __pyx_L28:; - /* "pysam/libctabix.pyx":894 + /* "pysam/libctabix.pyx":1017 * else: - * if end_col == None: - * end_col = -1 # <<<<<<<<<<<<<< - * preset = 0 + * suffix = ".tbi" + * index = index or filename + suffix # <<<<<<<<<<<<<< + * fn_index = encode_filename(index) * */ - __Pyx_INCREF(__pyx_int_neg_1); - __Pyx_DECREF_SET(__pyx_v_end_col, __pyx_int_neg_1); + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_index); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1017, __pyx_L1_error) + if (!__pyx_t_5) { + } else { + __Pyx_INCREF(__pyx_v_index); + __pyx_t_2 = __pyx_v_index; + goto __pyx_L29_bool_binop_done; + } + __pyx_t_3 = PyNumber_Add(__pyx_v_filename, __pyx_v_suffix); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1017, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = __pyx_t_3; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_L29_bool_binop_done:; + __Pyx_DECREF_SET(__pyx_v_index, __pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":893 - * (preset, ",".join(preset2conf.keys()))) - * else: - * if end_col == None: # <<<<<<<<<<<<<< - * end_col = -1 - * preset = 0 + /* "pysam/libctabix.pyx":1018 + * suffix = ".tbi" + * index = index or filename + suffix + * fn_index = encode_filename(index) # <<<<<<<<<<<<<< + * + * if not force and os.path.exists(index): */ - } + __pyx_t_2 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1018, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_fn_index = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":895 - * if end_col == None: - * end_col = -1 - * preset = 0 # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":1020 + * fn_index = encode_filename(index) * - * # note that tabix internally works with 0-based coordinates + * if not force and os.path.exists(index): # <<<<<<<<<<<<<< + * raise IOError( + * "filename '%s' already exists, use *force* to overwrite" % index) */ - __Pyx_INCREF(__pyx_int_0); - __Pyx_DECREF_SET(__pyx_v_preset, __pyx_int_0); + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_force); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1020, __pyx_L1_error) + __pyx_t_7 = ((!__pyx_t_6) != 0); + if (__pyx_t_7) { + } else { + __pyx_t_5 = __pyx_t_7; + goto __pyx_L32_bool_binop_done; + } + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1020, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1020, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exists); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1020, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1020, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_index}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1020, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_index}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1020, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1020, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_INCREF(__pyx_v_index); + __Pyx_GIVEREF(__pyx_v_index); + PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_v_index); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1020, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1020, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_5 = __pyx_t_7; + __pyx_L32_bool_binop_done:; + if (unlikely(__pyx_t_5)) { - /* "pysam/libctabix.pyx":903 - * # subtracted from the start coordinate. To avoid doing this, - * # set the TI_FLAG_UCSC=0x10000 flag: - * if zerobased: # <<<<<<<<<<<<<< - * preset = preset | 0x10000 + /* "pysam/libctabix.pyx":1022 + * if not force and os.path.exists(index): + * raise IOError( + * "filename '%s' already exists, use *force* to overwrite" % index) # <<<<<<<<<<<<<< * + * cdef char *fnidx = fn_index */ - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_zerobased); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 903, __pyx_L1_error) - if (__pyx_t_5) { + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_filename_s_already_exists_use_fo, __pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1022, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); - /* "pysam/libctabix.pyx":904 - * # set the TI_FLAG_UCSC=0x10000 flag: - * if zerobased: - * preset = preset | 0x10000 # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":1021 + * + * if not force and os.path.exists(index): + * raise IOError( # <<<<<<<<<<<<<< + * "filename '%s' already exists, use *force* to overwrite" % index) * - * conf_data = (preset, seq_col+1, start_col+1, end_col+1, ord(meta_char), 0) */ - __pyx_t_8 = __Pyx_PyInt_OrObjC(__pyx_v_preset, __pyx_int_65536, 0x10000, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 904, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF_SET(__pyx_v_preset, __pyx_t_8); - __pyx_t_8 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1021, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 1021, __pyx_L1_error) - /* "pysam/libctabix.pyx":903 - * # subtracted from the start coordinate. To avoid doing this, - * # set the TI_FLAG_UCSC=0x10000 flag: - * if zerobased: # <<<<<<<<<<<<<< - * preset = preset | 0x10000 + /* "pysam/libctabix.pyx":1020 + * fn_index = encode_filename(index) * + * if not force and os.path.exists(index): # <<<<<<<<<<<<<< + * raise IOError( + * "filename '%s' already exists, use *force* to overwrite" % index) */ - } + } - /* "pysam/libctabix.pyx":906 - * preset = preset | 0x10000 + /* "pysam/libctabix.pyx":1024 + * "filename '%s' already exists, use *force* to overwrite" % index) * - * conf_data = (preset, seq_col+1, start_col+1, end_col+1, ord(meta_char), 0) # <<<<<<<<<<<<<< + * cdef char *fnidx = fn_index # <<<<<<<<<<<<<< + * cdef int retval = 0 * - * cdef tbx_conf_t conf */ - __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_v_seq_col, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_start_col, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_end_col, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_13 = __Pyx_PyObject_Ord(__pyx_v_meta_char); if (unlikely(__pyx_t_13 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 906, __pyx_L1_error) - __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 906, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_preset); - __Pyx_GIVEREF(__pyx_v_preset); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_preset); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_t_1); - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_2, 5, __pyx_int_0); - __pyx_t_8 = 0; - __pyx_t_4 = 0; - __pyx_t_3 = 0; - __pyx_t_1 = 0; - __pyx_v_conf_data = __pyx_t_2; - __pyx_t_2 = 0; + if (unlikely(__pyx_v_fn_index == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 1024, __pyx_L1_error) } - __pyx_L13:; + __pyx_t_8 = __Pyx_PyBytes_AsWritableString(__pyx_v_fn_index); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 1024, __pyx_L1_error) + __pyx_v_fnidx = __pyx_t_8; - /* "pysam/libctabix.pyx":909 + /* "pysam/libctabix.pyx":1025 * - * cdef tbx_conf_t conf - * conf.preset, conf.sc, conf.bc, conf.ec, conf.meta_char, conf.line_skip = conf_data # <<<<<<<<<<<<<< + * cdef char *fnidx = fn_index + * cdef int retval = 0 # <<<<<<<<<<<<<< + * + * if csi and fmt == bcf: + */ + __pyx_v_retval = 0; + + /* "pysam/libctabix.pyx":1027 + * cdef int retval = 0 * + * if csi and fmt == bcf: # <<<<<<<<<<<<<< + * with nogil: + * retval = bcf_index_build2(cfn, fnidx, min_shift) + */ + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_csi); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1027, __pyx_L1_error) + if (__pyx_t_7) { + } else { + __pyx_t_5 = __pyx_t_7; + goto __pyx_L35_bool_binop_done; + } + __pyx_t_7 = ((__pyx_v_fmt == bcf) != 0); + __pyx_t_5 = __pyx_t_7; + __pyx_L35_bool_binop_done:; + if (__pyx_t_5) { + + /* "pysam/libctabix.pyx":1028 * + * if csi and fmt == bcf: + * with nogil: # <<<<<<<<<<<<<< + * retval = bcf_index_build2(cfn, fnidx, min_shift) + * else: */ - if ((likely(PyTuple_CheckExact(__pyx_v_conf_data))) || (PyList_CheckExact(__pyx_v_conf_data))) { - PyObject* sequence = __pyx_v_conf_data; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 6)) { - if (size > 6) __Pyx_RaiseTooManyValuesError(6); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 909, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 3); - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 4); - __pyx_t_14 = PyTuple_GET_ITEM(sequence, 5); - } else { - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); - __pyx_t_3 = PyList_GET_ITEM(sequence, 2); - __pyx_t_4 = PyList_GET_ITEM(sequence, 3); - __pyx_t_8 = PyList_GET_ITEM(sequence, 4); - __pyx_t_14 = PyList_GET_ITEM(sequence, 5); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_14); - #else { - Py_ssize_t i; - PyObject** temps[6] = {&__pyx_t_2,&__pyx_t_1,&__pyx_t_3,&__pyx_t_4,&__pyx_t_8,&__pyx_t_14}; - for (i=0; i < 6; i++) { - PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 909, __pyx_L1_error) - __Pyx_GOTREF(item); - *(temps[i]) = item; - } + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "pysam/libctabix.pyx":1029 + * if csi and fmt == bcf: + * with nogil: + * retval = bcf_index_build2(cfn, fnidx, min_shift) # <<<<<<<<<<<<<< + * else: + * with nogil: + */ + __pyx_v_retval = bcf_index_build2(__pyx_v_cfn, __pyx_v_fnidx, __pyx_v_min_shift); + } + + /* "pysam/libctabix.pyx":1028 + * + * if csi and fmt == bcf: + * with nogil: # <<<<<<<<<<<<<< + * retval = bcf_index_build2(cfn, fnidx, min_shift) + * else: + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L39; + } + __pyx_L39:; + } } - #endif - } else { - Py_ssize_t index = -1; - PyObject** temps[6] = {&__pyx_t_2,&__pyx_t_1,&__pyx_t_3,&__pyx_t_4,&__pyx_t_8,&__pyx_t_14}; - __pyx_t_15 = PyObject_GetIter(__pyx_v_conf_data); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 909, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_16 = Py_TYPE(__pyx_t_15)->tp_iternext; - for (index=0; index < 6; index++) { - PyObject* item = __pyx_t_16(__pyx_t_15); if (unlikely(!item)) goto __pyx_L24_unpacking_failed; - __Pyx_GOTREF(item); - *(temps[index]) = item; - } - if (__Pyx_IternextUnpackEndCheck(__pyx_t_16(__pyx_t_15), 6) < 0) __PYX_ERR(0, 909, __pyx_L1_error) - __pyx_t_16 = NULL; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - goto __pyx_L25_unpacking_done; - __pyx_L24_unpacking_failed:; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_16 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 909, __pyx_L1_error) - __pyx_L25_unpacking_done:; - } - __pyx_t_17 = __Pyx_PyInt_As_int32_t(__pyx_t_2); if (unlikely((__pyx_t_17 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 909, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_18 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_18 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 909, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_19 = __Pyx_PyInt_As_int32_t(__pyx_t_3); if (unlikely((__pyx_t_19 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 909, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_20 = __Pyx_PyInt_As_int32_t(__pyx_t_4); if (unlikely((__pyx_t_20 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 909, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_21 = __Pyx_PyInt_As_int32_t(__pyx_t_8); if (unlikely((__pyx_t_21 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 909, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_22 = __Pyx_PyInt_As_int32_t(__pyx_t_14); if (unlikely((__pyx_t_22 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 909, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_v_conf.preset = __pyx_t_17; - __pyx_v_conf.sc = __pyx_t_18; - __pyx_v_conf.bc = __pyx_t_19; - __pyx_v_conf.ec = __pyx_t_20; - __pyx_v_conf.meta_char = __pyx_t_21; - __pyx_v_conf.line_skip = __pyx_t_22; - /* "pysam/libctabix.pyx":912 + /* "pysam/libctabix.pyx":1027 + * cdef int retval = 0 * + * if csi and fmt == bcf: # <<<<<<<<<<<<<< + * with nogil: + * retval = bcf_index_build2(cfn, fnidx, min_shift) + */ + goto __pyx_L34; + } + + /* "pysam/libctabix.pyx":1031 + * retval = bcf_index_build2(cfn, fnidx, min_shift) + * else: + * with nogil: # <<<<<<<<<<<<<< + * retval = tbx_index_build2(cfn, fnidx, min_shift, &conf) * - * fn = encode_filename(filename) # <<<<<<<<<<<<<< - * cdef char *cfn = fn - * with nogil: */ - __pyx_t_14 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filename); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 912, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_14); - __pyx_v_fn = ((PyObject*)__pyx_t_14); - __pyx_t_14 = 0; + /*else*/ { + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { - /* "pysam/libctabix.pyx":913 + /* "pysam/libctabix.pyx":1032 + * else: + * with nogil: + * retval = tbx_index_build2(cfn, fnidx, min_shift, &conf) # <<<<<<<<<<<<<< * - * fn = encode_filename(filename) - * cdef char *cfn = fn # <<<<<<<<<<<<<< - * with nogil: - * tbx_index_build(cfn, min_shift, &conf) + * if retval != 0: */ - if (unlikely(__pyx_v_fn == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 913, __pyx_L1_error) + __pyx_v_retval = tbx_index_build2(__pyx_v_cfn, __pyx_v_fnidx, __pyx_v_min_shift, (&__pyx_v_conf)); + } + + /* "pysam/libctabix.pyx":1031 + * retval = bcf_index_build2(cfn, fnidx, min_shift) + * else: + * with nogil: # <<<<<<<<<<<<<< + * retval = tbx_index_build2(cfn, fnidx, min_shift, &conf) + * + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L42; + } + __pyx_L42:; + } + } } - __pyx_t_23 = __Pyx_PyBytes_AsWritableString(__pyx_v_fn); if (unlikely((!__pyx_t_23) && PyErr_Occurred())) __PYX_ERR(0, 913, __pyx_L1_error) - __pyx_v_cfn = __pyx_t_23; + __pyx_L34:; - /* "pysam/libctabix.pyx":914 - * fn = encode_filename(filename) - * cdef char *cfn = fn - * with nogil: # <<<<<<<<<<<<<< - * tbx_index_build(cfn, min_shift, &conf) + /* "pysam/libctabix.pyx":1034 + * retval = tbx_index_build2(cfn, fnidx, min_shift, &conf) + * + * if retval != 0: # <<<<<<<<<<<<<< + * raise OSError("building of index for {} failed".format(filename)) * */ - { - #ifdef WITH_THREAD - PyThreadState *_save; - Py_UNBLOCK_THREADS - __Pyx_FastGIL_Remember(); - #endif - /*try:*/ { + __pyx_t_5 = ((__pyx_v_retval != 0) != 0); + if (unlikely(__pyx_t_5)) { - /* "pysam/libctabix.pyx":915 - * cdef char *cfn = fn - * with nogil: - * tbx_index_build(cfn, min_shift, &conf) # <<<<<<<<<<<<<< + /* "pysam/libctabix.pyx":1035 + * + * if retval != 0: + * raise OSError("building of index for {} failed".format(filename)) # <<<<<<<<<<<<<< * * return filename */ - (void)(tbx_index_build(__pyx_v_cfn, __pyx_v_min_shift, (&__pyx_v_conf))); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_building_of_index_for_failed, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_1) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_filename}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1035, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_filename}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1035, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL; + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_filename); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_OSError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __PYX_ERR(0, 1035, __pyx_L1_error) - /* "pysam/libctabix.pyx":914 - * fn = encode_filename(filename) - * cdef char *cfn = fn - * with nogil: # <<<<<<<<<<<<<< - * tbx_index_build(cfn, min_shift, &conf) + /* "pysam/libctabix.pyx":1034 + * retval = tbx_index_build2(cfn, fnidx, min_shift, &conf) + * + * if retval != 0: # <<<<<<<<<<<<<< + * raise OSError("building of index for {} failed".format(filename)) * */ - /*finally:*/ { - /*normal exit:*/{ - #ifdef WITH_THREAD - __Pyx_FastGIL_Forget(); - Py_BLOCK_THREADS - #endif - goto __pyx_L28; - } - __pyx_L28:; - } } - /* "pysam/libctabix.pyx":917 - * tbx_index_build(cfn, min_shift, &conf) + /* "pysam/libctabix.pyx":1037 + * raise OSError("building of index for {} failed".format(filename)) * * return filename # <<<<<<<<<<<<<< * @@ -13097,12 +14956,12 @@ static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject __pyx_r = __pyx_v_filename; goto __pyx_L0; - /* "pysam/libctabix.pyx":808 + /* "pysam/libctabix.pyx":890 * * - * def tabix_index( filename, # <<<<<<<<<<<<<< - * force = False, - * seq_col = None, + * def tabix_index(filename, # <<<<<<<<<<<<<< + * force=False, + * seq_col=None, */ /* function exit code */ @@ -13111,25 +14970,29 @@ static PyObject *__pyx_pf_5pysam_9libctabix_2tabix_index(CYTHON_UNUSED PyObject __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_14); - __Pyx_XDECREF(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_16); + __Pyx_XDECREF(__pyx_t_17); __Pyx_AddTraceback("pysam.libctabix.tabix_index", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fn); __Pyx_XDECREF(__pyx_v_preset2conf); __Pyx_XDECREF(__pyx_v_conf_data); - __Pyx_XDECREF(__pyx_v_fn); + __Pyx_XDECREF(__pyx_v_suffix); + __Pyx_XDECREF(__pyx_v_fn_index); __Pyx_XDECREF(__pyx_v_filename); __Pyx_XDECREF(__pyx_v_end_col); __Pyx_XDECREF(__pyx_v_preset); + __Pyx_XDECREF(__pyx_v_index); + __Pyx_XDECREF(__pyx_v_csi); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabix.pyx":999 +/* "pysam/libctabix.pyx":1119 * ''' * * def __cinit__(self, # <<<<<<<<<<<<<< @@ -13171,7 +15034,7 @@ static int __pyx_pw_5pysam_9libctabix_19tabix_file_iterator_1__cinit__(PyObject case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_parser)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); __PYX_ERR(0, 999, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); __PYX_ERR(0, 1119, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: @@ -13181,7 +15044,7 @@ static int __pyx_pw_5pysam_9libctabix_19tabix_file_iterator_1__cinit__(PyObject } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 999, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 1119, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -13196,20 +15059,20 @@ static int __pyx_pw_5pysam_9libctabix_19tabix_file_iterator_1__cinit__(PyObject __pyx_v_infile = values[0]; __pyx_v_parser = ((struct __pyx_obj_5pysam_9libctabix_Parser *)values[1]); if (values[2]) { - __pyx_v_buffer_size = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_buffer_size == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1002, __pyx_L3_error) + __pyx_v_buffer_size = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_buffer_size == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1122, __pyx_L3_error) } else { __pyx_v_buffer_size = ((int)0x10000); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 999, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1119, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabix.tabix_file_iterator.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_parser), __pyx_ptype_5pysam_9libctabix_Parser, 1, "parser", 0))) __PYX_ERR(0, 1001, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_parser), __pyx_ptype_5pysam_9libctabix_Parser, 1, "parser", 0))) __PYX_ERR(0, 1121, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(((struct __pyx_obj_5pysam_9libctabix_tabix_file_iterator *)__pyx_v_self), __pyx_v_infile, __pyx_v_parser, __pyx_v_buffer_size); /* function exit code */ @@ -13231,35 +15094,35 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p int __pyx_t_3; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__cinit__", 0); - __Pyx_TraceCall("__cinit__", __pyx_f[0], 999, 0, __PYX_ERR(0, 999, __pyx_L1_error)); + __Pyx_TraceCall("__cinit__", __pyx_f[0], 1119, 0, __PYX_ERR(0, 1119, __pyx_L1_error)); - /* "pysam/libctabix.pyx":1004 + /* "pysam/libctabix.pyx":1124 * int buffer_size=65536): * * if infile.closed: # <<<<<<<<<<<<<< * raise ValueError("I/O operation on closed file.") * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_infile, __pyx_n_s_closed); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1004, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_infile, __pyx_n_s_closed); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1004, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1124, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_2)) { - /* "pysam/libctabix.pyx":1005 + /* "pysam/libctabix.pyx":1125 * * if infile.closed: * raise ValueError("I/O operation on closed file.") # <<<<<<<<<<<<<< * * self.infile = infile */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1005, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1005, __pyx_L1_error) + __PYX_ERR(0, 1125, __pyx_L1_error) - /* "pysam/libctabix.pyx":1004 + /* "pysam/libctabix.pyx":1124 * int buffer_size=65536): * * if infile.closed: # <<<<<<<<<<<<<< @@ -13268,7 +15131,7 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p */ } - /* "pysam/libctabix.pyx":1007 + /* "pysam/libctabix.pyx":1127 * raise ValueError("I/O operation on closed file.") * * self.infile = infile # <<<<<<<<<<<<<< @@ -13281,17 +15144,17 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p __Pyx_DECREF(__pyx_v_self->infile); __pyx_v_self->infile = __pyx_v_infile; - /* "pysam/libctabix.pyx":1009 + /* "pysam/libctabix.pyx":1129 * self.infile = infile * * cdef int fd = PyObject_AsFileDescriptor(infile) # <<<<<<<<<<<<<< * if fd == -1: * raise ValueError("I/O operation on closed file.") */ - __pyx_t_3 = PyObject_AsFileDescriptor(__pyx_v_infile); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 1009, __pyx_L1_error) + __pyx_t_3 = PyObject_AsFileDescriptor(__pyx_v_infile); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 1129, __pyx_L1_error) __pyx_v_fd = __pyx_t_3; - /* "pysam/libctabix.pyx":1010 + /* "pysam/libctabix.pyx":1130 * * cdef int fd = PyObject_AsFileDescriptor(infile) * if fd == -1: # <<<<<<<<<<<<<< @@ -13301,20 +15164,20 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p __pyx_t_2 = ((__pyx_v_fd == -1L) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libctabix.pyx":1011 + /* "pysam/libctabix.pyx":1131 * cdef int fd = PyObject_AsFileDescriptor(infile) * if fd == -1: * raise ValueError("I/O operation on closed file.") # <<<<<<<<<<<<<< * * self.duplicated_fd = dup(fd) */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1011, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1131, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1011, __pyx_L1_error) + __PYX_ERR(0, 1131, __pyx_L1_error) - /* "pysam/libctabix.pyx":1010 + /* "pysam/libctabix.pyx":1130 * * cdef int fd = PyObject_AsFileDescriptor(infile) * if fd == -1: # <<<<<<<<<<<<<< @@ -13323,7 +15186,7 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p */ } - /* "pysam/libctabix.pyx":1013 + /* "pysam/libctabix.pyx":1133 * raise ValueError("I/O operation on closed file.") * * self.duplicated_fd = dup(fd) # <<<<<<<<<<<<<< @@ -13332,7 +15195,7 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p */ __pyx_v_self->duplicated_fd = dup(__pyx_v_fd); - /* "pysam/libctabix.pyx":1020 + /* "pysam/libctabix.pyx":1140 * # When reading, this will be detected automatically by looking * # for the magic two-byte gzip header. * self.fh = bgzf_dopen(self.duplicated_fd, 'r') # <<<<<<<<<<<<<< @@ -13341,7 +15204,7 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p */ __pyx_v_self->fh = bgzf_dopen(__pyx_v_self->duplicated_fd, ((char const *)"r")); - /* "pysam/libctabix.pyx":1022 + /* "pysam/libctabix.pyx":1142 * self.fh = bgzf_dopen(self.duplicated_fd, 'r') * * if self.fh == NULL: # <<<<<<<<<<<<<< @@ -13351,26 +15214,26 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p __pyx_t_2 = ((__pyx_v_self->fh == NULL) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libctabix.pyx":1023 + /* "pysam/libctabix.pyx":1143 * * if self.fh == NULL: * raise IOError('%s' % strerror(errno)) # <<<<<<<<<<<<<< * * self.kstream = ks_init(self.fh) */ - __pyx_t_1 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1023, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1023, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1023, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 1023, __pyx_L1_error) + __PYX_ERR(0, 1143, __pyx_L1_error) - /* "pysam/libctabix.pyx":1022 + /* "pysam/libctabix.pyx":1142 * self.fh = bgzf_dopen(self.duplicated_fd, 'r') * * if self.fh == NULL: # <<<<<<<<<<<<<< @@ -13379,7 +15242,7 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p */ } - /* "pysam/libctabix.pyx":1025 + /* "pysam/libctabix.pyx":1145 * raise IOError('%s' % strerror(errno)) * * self.kstream = ks_init(self.fh) # <<<<<<<<<<<<<< @@ -13388,7 +15251,7 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p */ __pyx_v_self->kstream = ks_init(__pyx_v_self->fh); - /* "pysam/libctabix.pyx":1027 + /* "pysam/libctabix.pyx":1147 * self.kstream = ks_init(self.fh) * * self.buffer.s = malloc(buffer_size) # <<<<<<<<<<<<<< @@ -13397,7 +15260,7 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p */ __pyx_v_self->buffer.s = ((char *)malloc(__pyx_v_buffer_size)); - /* "pysam/libctabix.pyx":1031 + /* "pysam/libctabix.pyx":1151 * # raise MemoryError( "tabix_file_iterator: could not allocate %i bytes" % buffer_size) * #self.size = buffer_size * self.parser = parser # <<<<<<<<<<<<<< @@ -13410,7 +15273,7 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p __Pyx_DECREF(((PyObject *)__pyx_v_self->parser)); __pyx_v_self->parser = __pyx_v_parser; - /* "pysam/libctabix.pyx":999 + /* "pysam/libctabix.pyx":1119 * ''' * * def __cinit__(self, # <<<<<<<<<<<<<< @@ -13432,7 +15295,7 @@ static int __pyx_pf_5pysam_9libctabix_19tabix_file_iterator___cinit__(struct __p return __pyx_r; } -/* "pysam/libctabix.pyx":1033 +/* "pysam/libctabix.pyx":1153 * self.parser = parser * * def __iter__(self): # <<<<<<<<<<<<<< @@ -13458,9 +15321,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19tabix_file_iterator_2__iter__(stru __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1033, 0, __PYX_ERR(0, 1033, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 1153, 0, __PYX_ERR(0, 1153, __pyx_L1_error)); - /* "pysam/libctabix.pyx":1034 + /* "pysam/libctabix.pyx":1154 * * def __iter__(self): * return self # <<<<<<<<<<<<<< @@ -13472,7 +15335,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19tabix_file_iterator_2__iter__(stru __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libctabix.pyx":1033 + /* "pysam/libctabix.pyx":1153 * self.parser = parser * * def __iter__(self): # <<<<<<<<<<<<<< @@ -13491,7 +15354,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19tabix_file_iterator_2__iter__(stru return __pyx_r; } -/* "pysam/libctabix.pyx":1036 +/* "pysam/libctabix.pyx":1156 * return self * * cdef __cnext__(self): # <<<<<<<<<<<<<< @@ -13511,9 +15374,9 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc int __pyx_t_3; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__cnext__", 0); - __Pyx_TraceCall("__cnext__", __pyx_f[0], 1036, 0, __PYX_ERR(0, 1036, __pyx_L1_error)); + __Pyx_TraceCall("__cnext__", __pyx_f[0], 1156, 0, __PYX_ERR(0, 1156, __pyx_L1_error)); - /* "pysam/libctabix.pyx":1039 + /* "pysam/libctabix.pyx":1159 * * cdef char * b * cdef int dret = 0 # <<<<<<<<<<<<<< @@ -13522,7 +15385,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc */ __pyx_v_dret = 0; - /* "pysam/libctabix.pyx":1040 + /* "pysam/libctabix.pyx":1160 * cdef char * b * cdef int dret = 0 * cdef int retval = 0 # <<<<<<<<<<<<<< @@ -13531,7 +15394,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc */ __pyx_v_retval = 0; - /* "pysam/libctabix.pyx":1041 + /* "pysam/libctabix.pyx":1161 * cdef int dret = 0 * cdef int retval = 0 * while 1: # <<<<<<<<<<<<<< @@ -13540,7 +15403,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc */ while (1) { - /* "pysam/libctabix.pyx":1042 + /* "pysam/libctabix.pyx":1162 * cdef int retval = 0 * while 1: * with nogil: # <<<<<<<<<<<<<< @@ -13555,7 +15418,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc #endif /*try:*/ { - /* "pysam/libctabix.pyx":1043 + /* "pysam/libctabix.pyx":1163 * while 1: * with nogil: * retval = ks_getuntil(self.kstream, '\n', &self.buffer, &dret) # <<<<<<<<<<<<<< @@ -13565,7 +15428,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc __pyx_v_retval = ks_getuntil(__pyx_v_self->kstream, '\n', (&__pyx_v_self->buffer), (&__pyx_v_dret)); } - /* "pysam/libctabix.pyx":1042 + /* "pysam/libctabix.pyx":1162 * cdef int retval = 0 * while 1: * with nogil: # <<<<<<<<<<<<<< @@ -13584,7 +15447,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc } } - /* "pysam/libctabix.pyx":1045 + /* "pysam/libctabix.pyx":1165 * retval = ks_getuntil(self.kstream, '\n', &self.buffer, &dret) * * if retval < 0: # <<<<<<<<<<<<<< @@ -13594,7 +15457,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc __pyx_t_1 = ((__pyx_v_retval < 0) != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":1046 + /* "pysam/libctabix.pyx":1166 * * if retval < 0: * break # <<<<<<<<<<<<<< @@ -13603,7 +15466,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc */ goto __pyx_L4_break; - /* "pysam/libctabix.pyx":1045 + /* "pysam/libctabix.pyx":1165 * retval = ks_getuntil(self.kstream, '\n', &self.buffer, &dret) * * if retval < 0: # <<<<<<<<<<<<<< @@ -13612,7 +15475,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc */ } - /* "pysam/libctabix.pyx":1049 + /* "pysam/libctabix.pyx":1169 * #raise IOError('gzip error: %s' % buildGzipError( self.fh )) * * b = self.buffer.s # <<<<<<<<<<<<<< @@ -13622,7 +15485,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc __pyx_t_2 = __pyx_v_self->buffer.s; __pyx_v_b = __pyx_t_2; - /* "pysam/libctabix.pyx":1052 + /* "pysam/libctabix.pyx":1172 * * # skip comments * if (b[0] == '#'): # <<<<<<<<<<<<<< @@ -13632,7 +15495,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc __pyx_t_1 = (((__pyx_v_b[0]) == '#') != 0); if (__pyx_t_1) { - /* "pysam/libctabix.pyx":1053 + /* "pysam/libctabix.pyx":1173 * # skip comments * if (b[0] == '#'): * continue # <<<<<<<<<<<<<< @@ -13641,7 +15504,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc */ goto __pyx_L3_continue; - /* "pysam/libctabix.pyx":1052 + /* "pysam/libctabix.pyx":1172 * * # skip comments * if (b[0] == '#'): # <<<<<<<<<<<<<< @@ -13650,7 +15513,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc */ } - /* "pysam/libctabix.pyx":1056 + /* "pysam/libctabix.pyx":1176 * * # skip empty lines * if b[0] == '\0' or b[0] == '\n' or b[0] == '\r': # <<<<<<<<<<<<<< @@ -13674,7 +15537,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc __pyx_L13_bool_binop_done:; if (__pyx_t_1) { - /* "pysam/libctabix.pyx":1057 + /* "pysam/libctabix.pyx":1177 * # skip empty lines * if b[0] == '\0' or b[0] == '\n' or b[0] == '\r': * continue # <<<<<<<<<<<<<< @@ -13683,7 +15546,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc */ goto __pyx_L3_continue; - /* "pysam/libctabix.pyx":1056 + /* "pysam/libctabix.pyx":1176 * * # skip empty lines * if b[0] == '\0' or b[0] == '\n' or b[0] == '\r': # <<<<<<<<<<<<<< @@ -13692,7 +15555,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc */ } - /* "pysam/libctabix.pyx":1062 + /* "pysam/libctabix.pyx":1182 * * # parser creates a copy * return self.parser.parse(b, self.buffer.l) # <<<<<<<<<<<<<< @@ -13700,7 +15563,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc * raise StopIteration */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_9libctabix_Parser *)__pyx_v_self->parser->__pyx_vtab)->parse(__pyx_v_self->parser, __pyx_v_b, __pyx_v_self->buffer.l); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1062, __pyx_L1_error) + __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_9libctabix_Parser *)__pyx_v_self->parser->__pyx_vtab)->parse(__pyx_v_self->parser, __pyx_v_b, __pyx_v_self->buffer.l); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1182, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; @@ -13709,7 +15572,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc } __pyx_L4_break:; - /* "pysam/libctabix.pyx":1064 + /* "pysam/libctabix.pyx":1184 * return self.parser.parse(b, self.buffer.l) * * raise StopIteration # <<<<<<<<<<<<<< @@ -13717,9 +15580,9 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc * def __dealloc__(self): */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 1064, __pyx_L1_error) + __PYX_ERR(0, 1184, __pyx_L1_error) - /* "pysam/libctabix.pyx":1036 + /* "pysam/libctabix.pyx":1156 * return self * * cdef __cnext__(self): # <<<<<<<<<<<<<< @@ -13739,7 +15602,7 @@ static PyObject *__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__(struc return __pyx_r; } -/* "pysam/libctabix.pyx":1066 +/* "pysam/libctabix.pyx":1186 * raise StopIteration * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -13762,9 +15625,9 @@ static void __pyx_pf_5pysam_9libctabix_19tabix_file_iterator_4__dealloc__(struct __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1066, 0, __PYX_ERR(0, 1066, __pyx_L1_error)); + __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1186, 0, __PYX_ERR(0, 1186, __pyx_L1_error)); - /* "pysam/libctabix.pyx":1067 + /* "pysam/libctabix.pyx":1187 * * def __dealloc__(self): * free(self.buffer.s) # <<<<<<<<<<<<<< @@ -13773,7 +15636,7 @@ static void __pyx_pf_5pysam_9libctabix_19tabix_file_iterator_4__dealloc__(struct */ free(__pyx_v_self->buffer.s); - /* "pysam/libctabix.pyx":1068 + /* "pysam/libctabix.pyx":1188 * def __dealloc__(self): * free(self.buffer.s) * ks_destroy(self.kstream) # <<<<<<<<<<<<<< @@ -13782,7 +15645,7 @@ static void __pyx_pf_5pysam_9libctabix_19tabix_file_iterator_4__dealloc__(struct */ ks_destroy(__pyx_v_self->kstream); - /* "pysam/libctabix.pyx":1069 + /* "pysam/libctabix.pyx":1189 * free(self.buffer.s) * ks_destroy(self.kstream) * bgzf_close(self.fh) # <<<<<<<<<<<<<< @@ -13791,7 +15654,7 @@ static void __pyx_pf_5pysam_9libctabix_19tabix_file_iterator_4__dealloc__(struct */ (void)(bgzf_close(__pyx_v_self->fh)); - /* "pysam/libctabix.pyx":1066 + /* "pysam/libctabix.pyx":1186 * raise StopIteration * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -13808,7 +15671,7 @@ static void __pyx_pf_5pysam_9libctabix_19tabix_file_iterator_4__dealloc__(struct __Pyx_RefNannyFinishContext(); } -/* "pysam/libctabix.pyx":1071 +/* "pysam/libctabix.pyx":1191 * bgzf_close(self.fh) * * def __next__(self): # <<<<<<<<<<<<<< @@ -13835,9 +15698,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19tabix_file_iterator_6__next__(stru __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 1071, 0, __PYX_ERR(0, 1071, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 1191, 0, __PYX_ERR(0, 1191, __pyx_L1_error)); - /* "pysam/libctabix.pyx":1072 + /* "pysam/libctabix.pyx":1192 * * def __next__(self): * return self.__cnext__() # <<<<<<<<<<<<<< @@ -13845,13 +15708,13 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19tabix_file_iterator_6__next__(stru * def next(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9libctabix_tabix_file_iterator *)__pyx_v_self->__pyx_vtab)->__pyx___cnext__(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1072, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9libctabix_tabix_file_iterator *)__pyx_v_self->__pyx_vtab)->__pyx___cnext__(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1192, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libctabix.pyx":1071 + /* "pysam/libctabix.pyx":1191 * bgzf_close(self.fh) * * def __next__(self): # <<<<<<<<<<<<<< @@ -13871,7 +15734,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19tabix_file_iterator_6__next__(stru return __pyx_r; } -/* "pysam/libctabix.pyx":1074 +/* "pysam/libctabix.pyx":1194 * return self.__cnext__() * * def next(self): # <<<<<<<<<<<<<< @@ -13899,9 +15762,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19tabix_file_iterator_8next(struct _ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("next", 0); - __Pyx_TraceCall("next", __pyx_f[0], 1074, 0, __PYX_ERR(0, 1074, __pyx_L1_error)); + __Pyx_TraceCall("next", __pyx_f[0], 1194, 0, __PYX_ERR(0, 1194, __pyx_L1_error)); - /* "pysam/libctabix.pyx":1075 + /* "pysam/libctabix.pyx":1195 * * def next(self): * return self.__cnext__() # <<<<<<<<<<<<<< @@ -13909,13 +15772,13 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19tabix_file_iterator_8next(struct _ * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9libctabix_tabix_file_iterator *)__pyx_v_self->__pyx_vtab)->__pyx___cnext__(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1075, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_9libctabix_tabix_file_iterator *)__pyx_v_self->__pyx_vtab)->__pyx___cnext__(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1195, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libctabix.pyx":1074 + /* "pysam/libctabix.pyx":1194 * return self.__cnext__() * * def next(self): # <<<<<<<<<<<<<< @@ -13969,7 +15832,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19tabix_file_iterator_10__reduce_cyt * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -14026,7 +15889,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19tabix_file_iterator_12__setstate_c * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -14050,7 +15913,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_19tabix_file_iterator_12__setstate_c return __pyx_r; } -/* "pysam/libctabix.pyx":1083 +/* "pysam/libctabix.pyx":1203 * Permits the use of file-like objects for example from the gzip module. * ''' * def __init__(self, infile, parser): # <<<<<<<<<<<<<< @@ -14094,17 +15957,17 @@ static PyObject *__pyx_pw_5pysam_9libctabix_22tabix_generic_iterator_1__init__(P case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_infile)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 1); __PYX_ERR(0, 1083, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 1); __PYX_ERR(0, 1203, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_parser)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 2); __PYX_ERR(0, 1083, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 2); __PYX_ERR(0, 1203, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1083, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1203, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -14119,7 +15982,7 @@ static PyObject *__pyx_pw_5pysam_9libctabix_22tabix_generic_iterator_1__init__(P } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1083, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1203, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabix.tabix_generic_iterator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -14139,49 +16002,49 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator___init__(CY PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; - __Pyx_TraceFrameInit(__pyx_codeobj__40) + __Pyx_TraceFrameInit(__pyx_codeobj__32) __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_TraceCall("__init__", __pyx_f[0], 1083, 0, __PYX_ERR(0, 1083, __pyx_L1_error)); + __Pyx_TraceCall("__init__", __pyx_f[0], 1203, 0, __PYX_ERR(0, 1203, __pyx_L1_error)); - /* "pysam/libctabix.pyx":1085 + /* "pysam/libctabix.pyx":1205 * def __init__(self, infile, parser): * * self.infile = infile # <<<<<<<<<<<<<< * if self.infile.closed: * raise ValueError("I/O operation on closed file.") */ - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_infile, __pyx_v_infile) < 0) __PYX_ERR(0, 1085, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_infile, __pyx_v_infile) < 0) __PYX_ERR(0, 1205, __pyx_L1_error) - /* "pysam/libctabix.pyx":1086 + /* "pysam/libctabix.pyx":1206 * * self.infile = infile * if self.infile.closed: # <<<<<<<<<<<<<< * raise ValueError("I/O operation on closed file.") * self.parser = parser */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_infile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1086, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_infile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1206, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_closed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1086, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_closed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1206, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1086, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1206, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(__pyx_t_3)) { - /* "pysam/libctabix.pyx":1087 + /* "pysam/libctabix.pyx":1207 * self.infile = infile * if self.infile.closed: * raise ValueError("I/O operation on closed file.") # <<<<<<<<<<<<<< * self.parser = parser * */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1087, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1207, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 1087, __pyx_L1_error) + __PYX_ERR(0, 1207, __pyx_L1_error) - /* "pysam/libctabix.pyx":1086 + /* "pysam/libctabix.pyx":1206 * * self.infile = infile * if self.infile.closed: # <<<<<<<<<<<<<< @@ -14190,16 +16053,16 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator___init__(CY */ } - /* "pysam/libctabix.pyx":1088 + /* "pysam/libctabix.pyx":1208 * if self.infile.closed: * raise ValueError("I/O operation on closed file.") * self.parser = parser # <<<<<<<<<<<<<< * * def __iter__(self): */ - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_parser, __pyx_v_parser) < 0) __PYX_ERR(0, 1088, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_parser, __pyx_v_parser) < 0) __PYX_ERR(0, 1208, __pyx_L1_error) - /* "pysam/libctabix.pyx":1083 + /* "pysam/libctabix.pyx":1203 * Permits the use of file-like objects for example from the gzip module. * ''' * def __init__(self, infile, parser): # <<<<<<<<<<<<<< @@ -14222,7 +16085,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator___init__(CY return __pyx_r; } -/* "pysam/libctabix.pyx":1090 +/* "pysam/libctabix.pyx":1210 * self.parser = parser * * def __iter__(self): # <<<<<<<<<<<<<< @@ -14249,11 +16112,11 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_2__iter__(C PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations - __Pyx_TraceFrameInit(__pyx_codeobj__42) + __Pyx_TraceFrameInit(__pyx_codeobj__34) __Pyx_RefNannySetupContext("__iter__", 0); - __Pyx_TraceCall("__iter__", __pyx_f[0], 1090, 0, __PYX_ERR(0, 1090, __pyx_L1_error)); + __Pyx_TraceCall("__iter__", __pyx_f[0], 1210, 0, __PYX_ERR(0, 1210, __pyx_L1_error)); - /* "pysam/libctabix.pyx":1091 + /* "pysam/libctabix.pyx":1211 * * def __iter__(self): * return self # <<<<<<<<<<<<<< @@ -14265,7 +16128,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_2__iter__(C __pyx_r = __pyx_v_self; goto __pyx_L0; - /* "pysam/libctabix.pyx":1090 + /* "pysam/libctabix.pyx":1210 * self.parser = parser * * def __iter__(self): # <<<<<<<<<<<<<< @@ -14284,7 +16147,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_2__iter__(C return __pyx_r; } -/* "pysam/libctabix.pyx":1094 +/* "pysam/libctabix.pyx":1214 * * # cython version - required for python 3 * def __next__(self): # <<<<<<<<<<<<<< @@ -14330,20 +16193,20 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C PyObject *__pyx_t_10 = NULL; int __pyx_t_11; PyObject *__pyx_t_12 = NULL; - __Pyx_TraceFrameInit(__pyx_codeobj__43) + __Pyx_TraceFrameInit(__pyx_codeobj__35) __Pyx_RefNannySetupContext("__next__", 0); - __Pyx_TraceCall("__next__", __pyx_f[0], 1094, 0, __PYX_ERR(0, 1094, __pyx_L1_error)); + __Pyx_TraceCall("__next__", __pyx_f[0], 1214, 0, __PYX_ERR(0, 1214, __pyx_L1_error)); - /* "pysam/libctabix.pyx":1100 + /* "pysam/libctabix.pyx":1220 * cdef size_t nbytes * * encoding = self.parser.get_encoding() # <<<<<<<<<<<<<< * * # note that GzipFile.close() does not close the file */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_parser); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1100, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_parser); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1220, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get_encoding); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1100, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get_encoding); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1220, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = NULL; @@ -14357,46 +16220,46 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C } } if (__pyx_t_2) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1100, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1220, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1100, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1220, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_encoding = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":1104 + /* "pysam/libctabix.pyx":1224 * # note that GzipFile.close() does not close the file * # reading is still possible. * if self.infile.closed: # <<<<<<<<<<<<<< * raise ValueError("I/O operation on closed file.") * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_infile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1104, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_infile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1224, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_closed); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1104, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_closed); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1224, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1104, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1224, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(__pyx_t_4)) { - /* "pysam/libctabix.pyx":1105 + /* "pysam/libctabix.pyx":1225 * # reading is still possible. * if self.infile.closed: * raise ValueError("I/O operation on closed file.") # <<<<<<<<<<<<<< * * while 1: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1105, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1225, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 1105, __pyx_L1_error) + __PYX_ERR(0, 1225, __pyx_L1_error) - /* "pysam/libctabix.pyx":1104 + /* "pysam/libctabix.pyx":1224 * # note that GzipFile.close() does not close the file * # reading is still possible. * if self.infile.closed: # <<<<<<<<<<<<<< @@ -14405,7 +16268,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C */ } - /* "pysam/libctabix.pyx":1107 + /* "pysam/libctabix.pyx":1227 * raise ValueError("I/O operation on closed file.") * * while 1: # <<<<<<<<<<<<<< @@ -14414,16 +16277,16 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C */ while (1) { - /* "pysam/libctabix.pyx":1109 + /* "pysam/libctabix.pyx":1229 * while 1: * * line = self.infile.readline() # <<<<<<<<<<<<<< * if not line: * break */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_infile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1109, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_infile); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1229, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_readline); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1109, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_readline); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1229, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = NULL; @@ -14437,28 +16300,28 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C } } if (__pyx_t_1) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1109, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1229, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { - __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1109, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1229, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libctabix.pyx":1110 + /* "pysam/libctabix.pyx":1230 * * line = self.infile.readline() * if not line: # <<<<<<<<<<<<<< * break * */ - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_line); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1110, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_line); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1230, __pyx_L1_error) __pyx_t_5 = ((!__pyx_t_4) != 0); if (__pyx_t_5) { - /* "pysam/libctabix.pyx":1111 + /* "pysam/libctabix.pyx":1231 * line = self.infile.readline() * if not line: * break # <<<<<<<<<<<<<< @@ -14467,7 +16330,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C */ goto __pyx_L5_break; - /* "pysam/libctabix.pyx":1110 + /* "pysam/libctabix.pyx":1230 * * line = self.infile.readline() * if not line: # <<<<<<<<<<<<<< @@ -14476,7 +16339,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C */ } - /* "pysam/libctabix.pyx":1113 + /* "pysam/libctabix.pyx":1233 * break * * s = force_bytes(line, encoding) # <<<<<<<<<<<<<< @@ -14485,12 +16348,12 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C */ __pyx_t_6.__pyx_n = 1; __pyx_t_6.encoding = __pyx_v_encoding; - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_line, &__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1113, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_line, &__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1233, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_v_s, ((PyObject*)__pyx_t_3)); __pyx_t_3 = 0; - /* "pysam/libctabix.pyx":1114 + /* "pysam/libctabix.pyx":1234 * * s = force_bytes(line, encoding) * b = s # <<<<<<<<<<<<<< @@ -14499,22 +16362,22 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C */ if (unlikely(__pyx_v_s == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 1114, __pyx_L1_error) + __PYX_ERR(0, 1234, __pyx_L1_error) } - __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_s); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 1114, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_s); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 1234, __pyx_L1_error) __pyx_v_b = __pyx_t_7; - /* "pysam/libctabix.pyx":1115 + /* "pysam/libctabix.pyx":1235 * s = force_bytes(line, encoding) * b = s * nbytes = len(line) # <<<<<<<<<<<<<< * assert b[nbytes] == '\0' * */ - __pyx_t_8 = PyObject_Length(__pyx_v_line); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1115, __pyx_L1_error) + __pyx_t_8 = PyObject_Length(__pyx_v_line); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1235, __pyx_L1_error) __pyx_v_nbytes = __pyx_t_8; - /* "pysam/libctabix.pyx":1116 + /* "pysam/libctabix.pyx":1236 * b = s * nbytes = len(line) * assert b[nbytes] == '\0' # <<<<<<<<<<<<<< @@ -14525,12 +16388,12 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!(((__pyx_v_b[__pyx_v_nbytes]) == '\x00') != 0))) { PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 1116, __pyx_L1_error) + __PYX_ERR(0, 1236, __pyx_L1_error) } } #endif - /* "pysam/libctabix.pyx":1119 + /* "pysam/libctabix.pyx":1239 * * # skip comments * if b[0] == '#': # <<<<<<<<<<<<<< @@ -14540,7 +16403,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C __pyx_t_5 = (((__pyx_v_b[0]) == '#') != 0); if (__pyx_t_5) { - /* "pysam/libctabix.pyx":1120 + /* "pysam/libctabix.pyx":1240 * # skip comments * if b[0] == '#': * continue # <<<<<<<<<<<<<< @@ -14549,7 +16412,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C */ goto __pyx_L4_continue; - /* "pysam/libctabix.pyx":1119 + /* "pysam/libctabix.pyx":1239 * * # skip comments * if b[0] == '#': # <<<<<<<<<<<<<< @@ -14558,7 +16421,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C */ } - /* "pysam/libctabix.pyx":1123 + /* "pysam/libctabix.pyx":1243 * * # skip empty lines * if b[0] == '\0' or b[0] == '\n' or b[0] == '\r': # <<<<<<<<<<<<<< @@ -14582,7 +16445,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C __pyx_L9_bool_binop_done:; if (__pyx_t_5) { - /* "pysam/libctabix.pyx":1124 + /* "pysam/libctabix.pyx":1244 * # skip empty lines * if b[0] == '\0' or b[0] == '\n' or b[0] == '\r': * continue # <<<<<<<<<<<<<< @@ -14591,7 +16454,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C */ goto __pyx_L4_continue; - /* "pysam/libctabix.pyx":1123 + /* "pysam/libctabix.pyx":1243 * * # skip empty lines * if b[0] == '\0' or b[0] == '\n' or b[0] == '\r': # <<<<<<<<<<<<<< @@ -14600,7 +16463,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C */ } - /* "pysam/libctabix.pyx":1127 + /* "pysam/libctabix.pyx":1247 * * # make sure that entry is complete * if b[nbytes-1] != '\n' and b[nbytes-1] != '\r': # <<<<<<<<<<<<<< @@ -14618,282 +16481,609 @@ static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_4__next__(C __pyx_L13_bool_binop_done:; if (unlikely(__pyx_t_5)) { - /* "pysam/libctabix.pyx":1128 + /* "pysam/libctabix.pyx":1248 * # make sure that entry is complete * if b[nbytes-1] != '\n' and b[nbytes-1] != '\r': * raise ValueError("incomplete line at %s" % line) # <<<<<<<<<<<<<< * * bytes_cpy = b */ - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_incomplete_line_at_s, __pyx_v_line); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1128, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_incomplete_line_at_s, __pyx_v_line); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1248, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1128, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1248, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 1128, __pyx_L1_error) + __PYX_ERR(0, 1248, __pyx_L1_error) + + /* "pysam/libctabix.pyx":1247 + * + * # make sure that entry is complete + * if b[nbytes-1] != '\n' and b[nbytes-1] != '\r': # <<<<<<<<<<<<<< + * raise ValueError("incomplete line at %s" % line) + * + */ + } + + /* "pysam/libctabix.pyx":1250 + * raise ValueError("incomplete line at %s" % line) + * + * bytes_cpy = b # <<<<<<<<<<<<<< + * cpy = bytes_cpy + * + */ + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_b); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1250, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_t_2; + __Pyx_INCREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_bytes_cpy = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "pysam/libctabix.pyx":1251 + * + * bytes_cpy = b + * cpy = bytes_cpy # <<<<<<<<<<<<<< + * + * return self.parser(cpy, nbytes) + */ + if (unlikely(__pyx_v_bytes_cpy == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 1251, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_bytes_cpy); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 1251, __pyx_L1_error) + __pyx_v_cpy = ((char *)__pyx_t_7); + + /* "pysam/libctabix.pyx":1253 + * cpy = bytes_cpy + * + * return self.parser(cpy, nbytes) # <<<<<<<<<<<<<< + * + * raise StopIteration + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_parser); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_cpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = __Pyx_PyInt_FromSize_t(__pyx_v_nbytes); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_1, __pyx_t_9}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1253, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_1, __pyx_t_9}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1253, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_10) { + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL; + } + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_t_9); + __pyx_t_1 = 0; + __pyx_t_9 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1253, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + __pyx_L4_continue:; + } + __pyx_L5_break:; + + /* "pysam/libctabix.pyx":1255 + * return self.parser(cpy, nbytes) + * + * raise StopIteration # <<<<<<<<<<<<<< + * + * # python version - required for python 2.7 + */ + __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); + __PYX_ERR(0, 1255, __pyx_L1_error) + + /* "pysam/libctabix.pyx":1214 + * + * # cython version - required for python 3 + * def __next__(self): # <<<<<<<<<<<<<< + * + * cdef char * b + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("pysam.libctabix.tabix_generic_iterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_encoding); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_s); + __Pyx_XDECREF(__pyx_v_bytes_cpy); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libctabix.pyx":1258 + * + * # python version - required for python 2.7 + * def next(self): # <<<<<<<<<<<<<< + * return self.__next__() + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libctabix_22tabix_generic_iterator_7next(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_22tabix_generic_iterator_6next[] = "tabix_generic_iterator.next(self)"; +static PyMethodDef __pyx_mdef_5pysam_9libctabix_22tabix_generic_iterator_7next = {"next", (PyCFunction)__pyx_pw_5pysam_9libctabix_22tabix_generic_iterator_7next, METH_O, __pyx_doc_5pysam_9libctabix_22tabix_generic_iterator_6next}; +static PyObject *__pyx_pw_5pysam_9libctabix_22tabix_generic_iterator_7next(PyObject *__pyx_self, PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("next (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_6next(__pyx_self, ((PyObject *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_6next(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_TraceFrameInit(__pyx_codeobj__37) + __Pyx_RefNannySetupContext("next", 0); + __Pyx_TraceCall("next", __pyx_f[0], 1258, 0, __PYX_ERR(0, 1258, __pyx_L1_error)); + + /* "pysam/libctabix.pyx":1259 + * # python version - required for python 2.7 + * def next(self): + * return self.__next__() # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_next); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1259, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1259, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1259, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libctabix.pyx":1258 + * + * # python version - required for python 2.7 + * def next(self): # <<<<<<<<<<<<<< + * return self.__next__() + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libctabix.tabix_generic_iterator.next", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libctabix.pyx":1127 +/* "pysam/libctabix.pyx":1262 * - * # make sure that entry is complete - * if b[nbytes-1] != '\n' and b[nbytes-1] != '\r': # <<<<<<<<<<<<<< - * raise ValueError("incomplete line at %s" % line) + * + * def tabix_iterator(infile, parser): # <<<<<<<<<<<<<< + * """return an iterator over all entries in a file. * */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libctabix_7tabix_iterator(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_6tabix_iterator[] = "tabix_iterator(infile, parser)\nreturn an iterator over all entries in a file.\n \n Results are returned parsed as specified by the *parser*. If\n *parser* is None, the results are returned as an unparsed string.\n Otherwise, *parser* is assumed to be a functor that will return\n parsed data (see for example :class:`~pysam.asTuple` and\n :class:`~pysam.asGTF`).\n\n "; +static PyMethodDef __pyx_mdef_5pysam_9libctabix_7tabix_iterator = {"tabix_iterator", (PyCFunction)__pyx_pw_5pysam_9libctabix_7tabix_iterator, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_6tabix_iterator}; +static PyObject *__pyx_pw_5pysam_9libctabix_7tabix_iterator(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_infile = 0; + PyObject *__pyx_v_parser = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("tabix_iterator (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_infile,&__pyx_n_s_parser,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_infile)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_parser)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("tabix_iterator", 1, 2, 2, 1); __PYX_ERR(0, 1262, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tabix_iterator") < 0)) __PYX_ERR(0, 1262, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } + __pyx_v_infile = values[0]; + __pyx_v_parser = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("tabix_iterator", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1262, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libctabix.tabix_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_9libctabix_6tabix_iterator(__pyx_self, __pyx_v_infile, __pyx_v_parser); - /* "pysam/libctabix.pyx":1130 - * raise ValueError("incomplete line at %s" % line) - * - * bytes_cpy = b # <<<<<<<<<<<<<< - * cpy = bytes_cpy - * - */ - __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_b); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1130, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __pyx_t_2; - __Pyx_INCREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_bytes_cpy = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libctabix.pyx":1131 - * - * bytes_cpy = b - * cpy = bytes_cpy # <<<<<<<<<<<<<< +static PyObject *__pyx_pf_5pysam_9libctabix_6tabix_iterator(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_infile, PyObject *__pyx_v_parser) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + __Pyx_TraceFrameInit(__pyx_codeobj__38) + __Pyx_RefNannySetupContext("tabix_iterator", 0); + __Pyx_TraceCall("tabix_iterator", __pyx_f[0], 1262, 0, __PYX_ERR(0, 1262, __pyx_L1_error)); + + /* "pysam/libctabix.pyx":1272 * - * return self.parser(cpy, nbytes) + * """ + * if PY_MAJOR_VERSION >= 3: # <<<<<<<<<<<<<< + * return tabix_generic_iterator(infile, parser) + * else: */ - if (unlikely(__pyx_v_bytes_cpy == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 1131, __pyx_L1_error) - } - __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_bytes_cpy); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(0, 1131, __pyx_L1_error) - __pyx_v_cpy = ((char *)__pyx_t_7); + __pyx_t_1 = ((PY_MAJOR_VERSION >= 3) != 0); + if (__pyx_t_1) { - /* "pysam/libctabix.pyx":1133 - * cpy = bytes_cpy - * - * return self.parser(cpy, nbytes) # <<<<<<<<<<<<<< - * - * raise StopIteration + /* "pysam/libctabix.pyx":1273 + * """ + * if PY_MAJOR_VERSION >= 3: + * return tabix_generic_iterator(infile, parser) # <<<<<<<<<<<<<< + * else: + * return tabix_file_iterator(infile, parser) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_parser); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1133, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_cpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1133, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyInt_FromSize_t(__pyx_v_nbytes); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1133, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = NULL; - __pyx_t_11 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_10); + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_tabix_generic_iterator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1273, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_11 = 1; + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_5 = 1; } } #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_1, __pyx_t_9}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1133, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_infile, __pyx_v_parser}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1273, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_1, __pyx_t_9}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1133, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_infile, __pyx_v_parser}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1273, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_12 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1133, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_10) { - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL; + __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1273, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; } - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_t_9); - __pyx_t_1 = 0; - __pyx_t_9 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1133, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_INCREF(__pyx_v_infile); + __Pyx_GIVEREF(__pyx_v_infile); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_infile); + __Pyx_INCREF(__pyx_v_parser); + __Pyx_GIVEREF(__pyx_v_parser); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_parser); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1273, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "pysam/libctabix.pyx":1272 + * + * """ + * if PY_MAJOR_VERSION >= 3: # <<<<<<<<<<<<<< + * return tabix_generic_iterator(infile, parser) + * else: + */ + } + + /* "pysam/libctabix.pyx":1275 + * return tabix_generic_iterator(infile, parser) + * else: + * return tabix_file_iterator(infile, parser) # <<<<<<<<<<<<<< + * + * # file objects can use C stdio + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1275, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_infile); + __Pyx_GIVEREF(__pyx_v_infile); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_infile); + __Pyx_INCREF(__pyx_v_parser); + __Pyx_GIVEREF(__pyx_v_parser); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_parser); + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_9libctabix_tabix_file_iterator), __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1275, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - __pyx_L4_continue:; } - __pyx_L5_break:; - /* "pysam/libctabix.pyx":1135 - * return self.parser(cpy, nbytes) + /* "pysam/libctabix.pyx":1262 * - * raise StopIteration # <<<<<<<<<<<<<< * - * # python version - required for python 2.7 + * def tabix_iterator(infile, parser): # <<<<<<<<<<<<<< + * """return an iterator over all entries in a file. + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libctabix.tabix_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_TraceReturn(__pyx_r, 0); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_9libctabix_9Tabixfile_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_9Tabixfile___reduce_cython__[] = "Tabixfile.__reduce_cython__(self)"; +static PyObject *__pyx_pw_5pysam_9libctabix_9Tabixfile_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libctabix_9Tabixfile___reduce_cython__(((struct __pyx_obj_5pysam_9libctabix_Tabixfile *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_9libctabix_9Tabixfile___reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libctabix_Tabixfile *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 1135, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 2, __pyx_L1_error) - /* "pysam/libctabix.pyx":1094 - * - * # cython version - required for python 3 - * def __next__(self): # <<<<<<<<<<<<<< - * - * cdef char * b + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("pysam.libctabix.tabix_generic_iterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.Tabixfile.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_encoding); - __Pyx_XDECREF(__pyx_v_line); - __Pyx_XDECREF(__pyx_v_s); - __Pyx_XDECREF(__pyx_v_bytes_cpy); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabix.pyx":1138 - * - * # python version - required for python 2.7 - * def next(self): # <<<<<<<<<<<<<< - * return self.__next__() - * +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_22tabix_generic_iterator_7next(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_22tabix_generic_iterator_6next[] = "tabix_generic_iterator.next(self)"; -static PyMethodDef __pyx_mdef_5pysam_9libctabix_22tabix_generic_iterator_7next = {"next", (PyCFunction)__pyx_pw_5pysam_9libctabix_22tabix_generic_iterator_7next, METH_O, __pyx_doc_5pysam_9libctabix_22tabix_generic_iterator_6next}; -static PyObject *__pyx_pw_5pysam_9libctabix_22tabix_generic_iterator_7next(PyObject *__pyx_self, PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_9libctabix_9Tabixfile_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_9Tabixfile_2__setstate_cython__[] = "Tabixfile.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_5pysam_9libctabix_9Tabixfile_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("next (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_6next(__pyx_self, ((PyObject *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_9libctabix_9Tabixfile_2__setstate_cython__(((struct __pyx_obj_5pysam_9libctabix_Tabixfile *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_22tabix_generic_iterator_6next(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_9libctabix_9Tabixfile_2__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libctabix_Tabixfile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_TraceFrameInit(__pyx_codeobj__45) - __Pyx_RefNannySetupContext("next", 0); - __Pyx_TraceCall("next", __pyx_f[0], 1138, 0, __PYX_ERR(0, 1138, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); - /* "pysam/libctabix.pyx":1139 - * # python version - required for python 2.7 - * def next(self): - * return self.__next__() # <<<<<<<<<<<<<< - * - * def tabix_iterator(infile, parser): + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_next); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1139, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1139, __pyx_L1_error) - } + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) - /* "pysam/libctabix.pyx":1138 - * - * # python version - required for python 2.7 - * def next(self): # <<<<<<<<<<<<<< - * return self.__next__() - * + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libctabix.tabix_generic_iterator.next", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.Tabixfile.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; - __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabix.pyx":1141 - * return self.__next__() - * - * def tabix_iterator(infile, parser): # <<<<<<<<<<<<<< - * """return an iterator over all entries in a file. - * +/* "(tree fragment)":1 + * def __pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0x84bea1f: + * from pickle import PickleError as __pyx_PickleError */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_5tabix_iterator(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_4tabix_iterator[] = "tabix_iterator(infile, parser)\nreturn an iterator over all entries in a file.\n \n Results are returned parsed as specified by the *parser*. If\n *parser* is None, the results are returned as an unparsed string.\n Otherwise, *parser* is assumed to be a functor that will return\n parsed data (see for example :class:`~pysam.asTuple` and\n :class:`~pysam.asGTF`).\n\n "; -static PyMethodDef __pyx_mdef_5pysam_9libctabix_5tabix_iterator = {"tabix_iterator", (PyCFunction)__pyx_pw_5pysam_9libctabix_5tabix_iterator, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_4tabix_iterator}; -static PyObject *__pyx_pw_5pysam_9libctabix_5tabix_iterator(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_infile = 0; - PyObject *__pyx_v_parser = 0; +static PyObject *__pyx_pw_5pysam_9libctabix_9__pyx_unpickle_Parser(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_8__pyx_unpickle_Parser[] = "__pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state)"; +static PyMethodDef __pyx_mdef_5pysam_9libctabix_9__pyx_unpickle_Parser = {"__pyx_unpickle_Parser", (PyCFunction)__pyx_pw_5pysam_9libctabix_9__pyx_unpickle_Parser, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_8__pyx_unpickle_Parser}; +static PyObject *__pyx_pw_5pysam_9libctabix_9__pyx_unpickle_Parser(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("tabix_iterator (wrapper)", 0); + __Pyx_RefNannySetupContext("__pyx_unpickle_Parser (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_infile,&__pyx_n_s_parser,0}; - PyObject* values[2] = {0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -14904,291 +17094,450 @@ static PyObject *__pyx_pw_5pysam_9libctabix_5tabix_iterator(PyObject *__pyx_self kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_infile)) != 0)) kw_args--; + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_parser)) != 0)) kw_args--; + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Parser", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("tabix_iterator", 1, 2, 2, 1); __PYX_ERR(0, 1141, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Parser", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tabix_iterator") < 0)) __PYX_ERR(0, 1141, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_Parser") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Parser", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_Parser", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_9libctabix_8__pyx_unpickle_Parser(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_Parser(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = NULL; + PyObject *__pyx_v___pyx_result = NULL; + PyObject *__pyx_r = NULL; + __Pyx_TraceDeclarations + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + __Pyx_TraceFrameInit(__pyx_codeobj__41) + __Pyx_RefNannySetupContext("__pyx_unpickle_Parser", 0); + __Pyx_TraceCall("__pyx_unpickle_Parser", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + + /* "(tree fragment)":2 + * def __pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state): + * if __pyx_checksum != 0x84bea1f: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) + */ + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x84bea1f) != 0); + if (__pyx_t_1) { + + /* "(tree fragment)":3 + * def __pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state): + * if __pyx_checksum != 0x84bea1f: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) + * __pyx_result = Parser.__new__(__pyx_type) + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":4 + * if __pyx_checksum != 0x84bea1f: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = Parser.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x84, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_5) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } - __pyx_v_infile = values[0]; - __pyx_v_parser = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("tabix_iterator", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1141, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libctabix.tabix_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libctabix_4tabix_iterator(__pyx_self, __pyx_v_infile, __pyx_v_parser); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_9libctabix_4tabix_iterator(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_infile, PyObject *__pyx_v_parser) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - __Pyx_TraceFrameInit(__pyx_codeobj__46) - __Pyx_RefNannySetupContext("tabix_iterator", 0); - __Pyx_TraceCall("tabix_iterator", __pyx_f[0], 1141, 0, __PYX_ERR(0, 1141, __pyx_L1_error)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) - /* "pysam/libctabix.pyx":1151 - * - * """ - * if PY_MAJOR_VERSION >= 3: # <<<<<<<<<<<<<< - * return tabix_generic_iterator(infile, parser) - * else: + /* "(tree fragment)":2 + * def __pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state): + * if __pyx_checksum != 0x84bea1f: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) */ - __pyx_t_1 = ((PY_MAJOR_VERSION >= 3) != 0); - if (__pyx_t_1) { + } - /* "pysam/libctabix.pyx":1152 - * """ - * if PY_MAJOR_VERSION >= 3: - * return tabix_generic_iterator(infile, parser) # <<<<<<<<<<<<<< - * else: - * return tabix_file_iterator(infile, parser) + /* "(tree fragment)":5 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) + * __pyx_result = Parser.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_tabix_generic_iterator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_5 = 1; - } + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_9libctabix_Parser), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); } + } + if (!__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_infile, __pyx_v_parser}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1152, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_infile, __pyx_v_parser}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1152, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v___pyx_type}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; - } - __Pyx_INCREF(__pyx_v_infile); - __Pyx_GIVEREF(__pyx_v_infile); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_infile); - __Pyx_INCREF(__pyx_v_parser); - __Pyx_GIVEREF(__pyx_v_parser); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_parser); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_INCREF(__pyx_v___pyx_type); + __Pyx_GIVEREF(__pyx_v___pyx_type); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v___pyx_type); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - /* "pysam/libctabix.pyx":1151 - * - * """ - * if PY_MAJOR_VERSION >= 3: # <<<<<<<<<<<<<< - * return tabix_generic_iterator(infile, parser) - * else: - */ } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; - /* "pysam/libctabix.pyx":1154 - * return tabix_generic_iterator(infile, parser) - * else: - * return tabix_file_iterator(infile, parser) # <<<<<<<<<<<<<< - * - * # file objects can use C stdio + /* "(tree fragment)":6 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) + * __pyx_result = Parser.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) + * return __pyx_result */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_infile); - __Pyx_GIVEREF(__pyx_v_infile); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_infile); - __Pyx_INCREF(__pyx_v_parser); - __Pyx_GIVEREF(__pyx_v_parser); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_parser); - __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_9libctabix_tabix_file_iterator), __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - } + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_7 = (__pyx_t_1 != 0); + if (__pyx_t_7) { - /* "pysam/libctabix.pyx":1141 - * return self.__next__() - * - * def tabix_iterator(infile, parser): # <<<<<<<<<<<<<< - * """return an iterator over all entries in a file. - * + /* "(tree fragment)":7 + * __pyx_result = Parser.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libctabix___pyx_unpickle_Parser__set_state(((struct __pyx_obj_5pysam_9libctabix_Parser *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libctabix.tabix_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_TraceReturn(__pyx_r, 0); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): + /* "(tree fragment)":6 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) + * __pyx_result = Parser.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) + * return __pyx_result */ + } -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_9Tabixfile_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_9Tabixfile___reduce_cython__[] = "Tabixfile.__reduce_cython__(self)"; -static PyObject *__pyx_pw_5pysam_9libctabix_9Tabixfile_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libctabix_9Tabixfile___reduce_cython__(((struct __pyx_obj_5pysam_9libctabix_Tabixfile *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_9libctabix_9Tabixfile___reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libctabix_Tabixfile *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_TraceDeclarations - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__reduce_cython__", 0); - __Pyx_TraceCall("__reduce_cython__", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); - - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + /* "(tree fragment)":8 + * if __pyx_state is not None: + * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): + * __pyx_result.encoding = __pyx_state[0] */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; /* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): + * def __pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * if __pyx_checksum != 0x84bea1f: + * from pickle import PickleError as __pyx_PickleError */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabix.Tabixfile.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_Parser", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") +/* "(tree fragment)":9 + * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.encoding = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): */ -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_9Tabixfile_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_9Tabixfile_2__setstate_cython__[] = "Tabixfile.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_5pysam_9libctabix_9Tabixfile_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_9libctabix_9Tabixfile_2__setstate_cython__(((struct __pyx_obj_5pysam_9libctabix_Tabixfile *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_9libctabix_9Tabixfile_2__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_9libctabix_Tabixfile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_Parser__set_state(struct __pyx_obj_5pysam_9libctabix_Parser *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__setstate_cython__", 0); - __Pyx_TraceCall("__setstate_cython__", __pyx_f[1], 3, 0, __PYX_ERR(1, 3, __pyx_L1_error)); + int __pyx_t_2; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("__pyx_unpickle_Parser__set_state", 0); + __Pyx_TraceCall("__pyx_unpickle_Parser__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); - /* "(tree fragment)":4 - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + /* "(tree fragment)":10 + * return __pyx_result + * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): + * __pyx_result.encoding = __pyx_state[0] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[1]) */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 10, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->encoding); + __Pyx_DECREF(__pyx_v___pyx_result->encoding); + __pyx_v___pyx_result->encoding = __pyx_t_1; + __pyx_t_1 = 0; - /* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + /* "(tree fragment)":11 + * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): + * __pyx_result.encoding = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(1, 11, __pyx_L1_error) + } + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_4 = ((__pyx_t_3 > 1) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_t_5 = (__pyx_t_4 != 0); + __pyx_t_2 = __pyx_t_5; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "(tree fragment)":12 + * __pyx_result.encoding = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_8) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":11 + * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): + * __pyx_result.encoding = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + } + + /* "(tree fragment)":9 + * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.encoding = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabix.Tabixfile.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_Parser__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_TraceReturn(__pyx_r, 0); __Pyx_RefNannyFinishContext(); @@ -15196,22 +17545,22 @@ static PyObject *__pyx_pf_5pysam_9libctabix_9Tabixfile_2__setstate_cython__(CYTH } /* "(tree fragment)":1 - * def __pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * def __pyx_unpickle_asTuple(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x84bea1f: * from pickle import PickleError as __pyx_PickleError */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_7__pyx_unpickle_Parser(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_6__pyx_unpickle_Parser[] = "__pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state)"; -static PyMethodDef __pyx_mdef_5pysam_9libctabix_7__pyx_unpickle_Parser = {"__pyx_unpickle_Parser", (PyCFunction)__pyx_pw_5pysam_9libctabix_7__pyx_unpickle_Parser, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_6__pyx_unpickle_Parser}; -static PyObject *__pyx_pw_5pysam_9libctabix_7__pyx_unpickle_Parser(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_9libctabix_11__pyx_unpickle_asTuple(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_10__pyx_unpickle_asTuple[] = "__pyx_unpickle_asTuple(__pyx_type, long __pyx_checksum, __pyx_state)"; +static PyMethodDef __pyx_mdef_5pysam_9libctabix_11__pyx_unpickle_asTuple = {"__pyx_unpickle_asTuple", (PyCFunction)__pyx_pw_5pysam_9libctabix_11__pyx_unpickle_asTuple, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_10__pyx_unpickle_asTuple}; +static PyObject *__pyx_pw_5pysam_9libctabix_11__pyx_unpickle_asTuple(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v___pyx_type = 0; long __pyx_v___pyx_checksum; PyObject *__pyx_v___pyx_state = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__pyx_unpickle_Parser (wrapper)", 0); + __Pyx_RefNannySetupContext("__pyx_unpickle_asTuple (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; PyObject* values[3] = {0,0,0}; @@ -15237,17 +17586,17 @@ static PyObject *__pyx_pw_5pysam_9libctabix_7__pyx_unpickle_Parser(PyObject *__p case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Parser", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_asTuple", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Parser", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_asTuple", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_Parser") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_asTuple") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -15262,20 +17611,20 @@ static PyObject *__pyx_pw_5pysam_9libctabix_7__pyx_unpickle_Parser(PyObject *__p } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Parser", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_asTuple", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_Parser", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_asTuple", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + __pyx_r = __pyx_pf_5pysam_9libctabix_10__pyx_unpickle_asTuple(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_9libctabix_10__pyx_unpickle_asTuple(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_v___pyx_PickleError = NULL; PyObject *__pyx_v___pyx_result = NULL; PyObject *__pyx_r = NULL; @@ -15288,12 +17637,12 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(CYTHON_UNUSED PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__49) - __Pyx_RefNannySetupContext("__pyx_unpickle_Parser", 0); - __Pyx_TraceCall("__pyx_unpickle_Parser", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceFrameInit(__pyx_codeobj__42) + __Pyx_RefNannySetupContext("__pyx_unpickle_asTuple", 0); + __Pyx_TraceCall("__pyx_unpickle_asTuple", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); /* "(tree fragment)":2 - * def __pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state): + * def __pyx_unpickle_asTuple(__pyx_type, long __pyx_checksum, __pyx_state): * if __pyx_checksum != 0x84bea1f: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) @@ -15302,11 +17651,11 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(CYTHON_UNUSED if (__pyx_t_1) { /* "(tree fragment)":3 - * def __pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state): + * def __pyx_unpickle_asTuple(__pyx_type, long __pyx_checksum, __pyx_state): * if __pyx_checksum != 0x84bea1f: * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) - * __pyx_result = Parser.__new__(__pyx_type) + * __pyx_result = asTuple.__new__(__pyx_type) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); @@ -15327,7 +17676,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(CYTHON_UNUSED * if __pyx_checksum != 0x84bea1f: * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) # <<<<<<<<<<<<<< - * __pyx_result = Parser.__new__(__pyx_type) + * __pyx_result = asTuple.__new__(__pyx_type) * if __pyx_state is not None: */ __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) @@ -15387,7 +17736,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(CYTHON_UNUSED __PYX_ERR(1, 4, __pyx_L1_error) /* "(tree fragment)":2 - * def __pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state): + * def __pyx_unpickle_asTuple(__pyx_type, long __pyx_checksum, __pyx_state): * if __pyx_checksum != 0x84bea1f: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) @@ -15397,11 +17746,11 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(CYTHON_UNUSED /* "(tree fragment)":5 * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) - * __pyx_result = Parser.__new__(__pyx_type) # <<<<<<<<<<<<<< + * __pyx_result = asTuple.__new__(__pyx_type) # <<<<<<<<<<<<<< * if __pyx_state is not None: - * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_9libctabix_Parser), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_9libctabix_asTuple), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -15451,9 +17800,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(CYTHON_UNUSED /* "(tree fragment)":6 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) - * __pyx_result = Parser.__new__(__pyx_type) + * __pyx_result = asTuple.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< - * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) * return __pyx_result */ __pyx_t_1 = (__pyx_v___pyx_state != Py_None); @@ -15461,31 +17810,31 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(CYTHON_UNUSED if (__pyx_t_7) { /* "(tree fragment)":7 - * __pyx_result = Parser.__new__(__pyx_type) + * __pyx_result = asTuple.__new__(__pyx_type) * if __pyx_state is not None: - * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< * return __pyx_result - * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_9libctabix___pyx_unpickle_Parser__set_state(((struct __pyx_obj_5pysam_9libctabix_Parser *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libctabix___pyx_unpickle_asTuple__set_state(((struct __pyx_obj_5pysam_9libctabix_asTuple *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":6 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) - * __pyx_result = Parser.__new__(__pyx_type) + * __pyx_result = asTuple.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< - * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) * return __pyx_result */ } /* "(tree fragment)":8 * if __pyx_state is not None: - * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) * return __pyx_result # <<<<<<<<<<<<<< - * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): * __pyx_result.encoding = __pyx_state[0] */ __Pyx_XDECREF(__pyx_r); @@ -15494,7 +17843,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(CYTHON_UNUSED goto __pyx_L0; /* "(tree fragment)":1 - * def __pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * def __pyx_unpickle_asTuple(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x84bea1f: * from pickle import PickleError as __pyx_PickleError */ @@ -15506,7 +17855,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(CYTHON_UNUSED __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_Parser", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_asTuple", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v___pyx_PickleError); @@ -15518,14 +17867,14 @@ static PyObject *__pyx_pf_5pysam_9libctabix_6__pyx_unpickle_Parser(CYTHON_UNUSED } /* "(tree fragment)":9 - * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) * return __pyx_result - * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.encoding = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): */ -static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_Parser__set_state(struct __pyx_obj_5pysam_9libctabix_Parser *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asTuple__set_state(struct __pyx_obj_5pysam_9libctabix_asTuple *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -15538,12 +17887,12 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_Parser__set_state(stru PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; - __Pyx_RefNannySetupContext("__pyx_unpickle_Parser__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_Parser__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__pyx_unpickle_asTuple__set_state", 0); + __Pyx_TraceCall("__pyx_unpickle_asTuple__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result - * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): * __pyx_result.encoding = __pyx_state[0] # <<<<<<<<<<<<<< * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[1]) @@ -15555,13 +17904,13 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_Parser__set_state(stru __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v___pyx_result->encoding); - __Pyx_DECREF(__pyx_v___pyx_result->encoding); - __pyx_v___pyx_result->encoding = __pyx_t_1; + __Pyx_GOTREF(__pyx_v___pyx_result->__pyx_base.encoding); + __Pyx_DECREF(__pyx_v___pyx_result->__pyx_base.encoding); + __pyx_v___pyx_result->__pyx_base.encoding = __pyx_t_1; __pyx_t_1 = 0; /* "(tree fragment)":11 - * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): * __pyx_result.encoding = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[1]) @@ -15648,7 +17997,7 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_Parser__set_state(stru __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":11 - * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): * __pyx_result.encoding = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[1]) @@ -15656,9 +18005,9 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_Parser__set_state(stru } /* "(tree fragment)":9 - * __pyx_unpickle_Parser__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) * return __pyx_result - * cdef __pyx_unpickle_Parser__set_state(Parser __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.encoding = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): */ @@ -15672,7 +18021,7 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_Parser__set_state(stru __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_Parser__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_asTuple__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -15682,22 +18031,22 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_Parser__set_state(stru } /* "(tree fragment)":1 - * def __pyx_unpickle_asTuple(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * def __pyx_unpickle_asGFF3(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x84bea1f: * from pickle import PickleError as __pyx_PickleError */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_9__pyx_unpickle_asTuple(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_8__pyx_unpickle_asTuple[] = "__pyx_unpickle_asTuple(__pyx_type, long __pyx_checksum, __pyx_state)"; -static PyMethodDef __pyx_mdef_5pysam_9libctabix_9__pyx_unpickle_asTuple = {"__pyx_unpickle_asTuple", (PyCFunction)__pyx_pw_5pysam_9libctabix_9__pyx_unpickle_asTuple, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_8__pyx_unpickle_asTuple}; -static PyObject *__pyx_pw_5pysam_9libctabix_9__pyx_unpickle_asTuple(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_9libctabix_13__pyx_unpickle_asGFF3(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_12__pyx_unpickle_asGFF3[] = "__pyx_unpickle_asGFF3(__pyx_type, long __pyx_checksum, __pyx_state)"; +static PyMethodDef __pyx_mdef_5pysam_9libctabix_13__pyx_unpickle_asGFF3 = {"__pyx_unpickle_asGFF3", (PyCFunction)__pyx_pw_5pysam_9libctabix_13__pyx_unpickle_asGFF3, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_12__pyx_unpickle_asGFF3}; +static PyObject *__pyx_pw_5pysam_9libctabix_13__pyx_unpickle_asGFF3(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v___pyx_type = 0; long __pyx_v___pyx_checksum; PyObject *__pyx_v___pyx_state = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__pyx_unpickle_asTuple (wrapper)", 0); + __Pyx_RefNannySetupContext("__pyx_unpickle_asGFF3 (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; PyObject* values[3] = {0,0,0}; @@ -15723,17 +18072,17 @@ static PyObject *__pyx_pw_5pysam_9libctabix_9__pyx_unpickle_asTuple(PyObject *__ case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_asTuple", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_asGFF3", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_asTuple", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_asGFF3", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_asTuple") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_asGFF3") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; @@ -15748,20 +18097,20 @@ static PyObject *__pyx_pw_5pysam_9libctabix_9__pyx_unpickle_asTuple(PyObject *__ } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_asTuple", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_asGFF3", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_asTuple", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_asGFF3", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + __pyx_r = __pyx_pf_5pysam_9libctabix_12__pyx_unpickle_asGFF3(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_9libctabix_12__pyx_unpickle_asGFF3(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_v___pyx_PickleError = NULL; PyObject *__pyx_v___pyx_result = NULL; PyObject *__pyx_r = NULL; @@ -15774,12 +18123,12 @@ static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(CYTHON_UNUSE PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__50) - __Pyx_RefNannySetupContext("__pyx_unpickle_asTuple", 0); - __Pyx_TraceCall("__pyx_unpickle_asTuple", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); + __Pyx_TraceFrameInit(__pyx_codeobj__43) + __Pyx_RefNannySetupContext("__pyx_unpickle_asGFF3", 0); + __Pyx_TraceCall("__pyx_unpickle_asGFF3", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); /* "(tree fragment)":2 - * def __pyx_unpickle_asTuple(__pyx_type, long __pyx_checksum, __pyx_state): + * def __pyx_unpickle_asGFF3(__pyx_type, long __pyx_checksum, __pyx_state): * if __pyx_checksum != 0x84bea1f: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) @@ -15788,11 +18137,11 @@ static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(CYTHON_UNUSE if (__pyx_t_1) { /* "(tree fragment)":3 - * def __pyx_unpickle_asTuple(__pyx_type, long __pyx_checksum, __pyx_state): + * def __pyx_unpickle_asGFF3(__pyx_type, long __pyx_checksum, __pyx_state): * if __pyx_checksum != 0x84bea1f: * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) - * __pyx_result = asTuple.__new__(__pyx_type) + * __pyx_result = asGFF3.__new__(__pyx_type) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); @@ -15813,7 +18162,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(CYTHON_UNUSE * if __pyx_checksum != 0x84bea1f: * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) # <<<<<<<<<<<<<< - * __pyx_result = asTuple.__new__(__pyx_type) + * __pyx_result = asGFF3.__new__(__pyx_type) * if __pyx_state is not None: */ __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 4, __pyx_L1_error) @@ -15873,7 +18222,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(CYTHON_UNUSE __PYX_ERR(1, 4, __pyx_L1_error) /* "(tree fragment)":2 - * def __pyx_unpickle_asTuple(__pyx_type, long __pyx_checksum, __pyx_state): + * def __pyx_unpickle_asGFF3(__pyx_type, long __pyx_checksum, __pyx_state): * if __pyx_checksum != 0x84bea1f: # <<<<<<<<<<<<<< * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) @@ -15883,11 +18232,11 @@ static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(CYTHON_UNUSE /* "(tree fragment)":5 * from pickle import PickleError as __pyx_PickleError * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) - * __pyx_result = asTuple.__new__(__pyx_type) # <<<<<<<<<<<<<< + * __pyx_result = asGFF3.__new__(__pyx_type) # <<<<<<<<<<<<<< * if __pyx_state is not None: - * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asGFF3__set_state( __pyx_result, __pyx_state) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_9libctabix_asTuple), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_9libctabix_asGFF3), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -15937,9 +18286,9 @@ static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(CYTHON_UNUSE /* "(tree fragment)":6 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) - * __pyx_result = asTuple.__new__(__pyx_type) + * __pyx_result = asGFF3.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< - * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asGFF3__set_state( __pyx_result, __pyx_state) * return __pyx_result */ __pyx_t_1 = (__pyx_v___pyx_state != Py_None); @@ -15947,31 +18296,31 @@ static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(CYTHON_UNUSE if (__pyx_t_7) { /* "(tree fragment)":7 - * __pyx_result = asTuple.__new__(__pyx_type) + * __pyx_result = asGFF3.__new__(__pyx_type) * if __pyx_state is not None: - * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * __pyx_unpickle_asGFF3__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< * return __pyx_result - * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_asGFF3__set_state(asGFF3 __pyx_result, tuple __pyx_state): */ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 7, __pyx_L1_error) - __pyx_t_3 = __pyx_f_5pysam_9libctabix___pyx_unpickle_asTuple__set_state(((struct __pyx_obj_5pysam_9libctabix_asTuple *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libctabix___pyx_unpickle_asGFF3__set_state(((struct __pyx_obj_5pysam_9libctabix_asGFF3 *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "(tree fragment)":6 * raise __pyx_PickleError("Incompatible checksums (%s vs 0x84bea1f = (encoding))" % __pyx_checksum) - * __pyx_result = asTuple.__new__(__pyx_type) + * __pyx_result = asGFF3.__new__(__pyx_type) * if __pyx_state is not None: # <<<<<<<<<<<<<< - * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asGFF3__set_state( __pyx_result, __pyx_state) * return __pyx_result */ } /* "(tree fragment)":8 * if __pyx_state is not None: - * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asGFF3__set_state( __pyx_result, __pyx_state) * return __pyx_result # <<<<<<<<<<<<<< - * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_asGFF3__set_state(asGFF3 __pyx_result, tuple __pyx_state): * __pyx_result.encoding = __pyx_state[0] */ __Pyx_XDECREF(__pyx_r); @@ -15980,7 +18329,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(CYTHON_UNUSE goto __pyx_L0; /* "(tree fragment)":1 - * def __pyx_unpickle_asTuple(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * def __pyx_unpickle_asGFF3(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x84bea1f: * from pickle import PickleError as __pyx_PickleError */ @@ -15992,7 +18341,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(CYTHON_UNUSE __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_asTuple", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_asGFF3", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v___pyx_PickleError); @@ -16004,14 +18353,14 @@ static PyObject *__pyx_pf_5pysam_9libctabix_8__pyx_unpickle_asTuple(CYTHON_UNUSE } /* "(tree fragment)":9 - * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asGFF3__set_state( __pyx_result, __pyx_state) * return __pyx_result - * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_asGFF3__set_state(asGFF3 __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.encoding = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): */ -static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asTuple__set_state(struct __pyx_obj_5pysam_9libctabix_asTuple *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asGFF3__set_state(struct __pyx_obj_5pysam_9libctabix_asGFF3 *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_TraceDeclarations __Pyx_RefNannyDeclarations @@ -16024,12 +18373,12 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asTuple__set_state(str PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; - __Pyx_RefNannySetupContext("__pyx_unpickle_asTuple__set_state", 0); - __Pyx_TraceCall("__pyx_unpickle_asTuple__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); + __Pyx_RefNannySetupContext("__pyx_unpickle_asGFF3__set_state", 0); + __Pyx_TraceCall("__pyx_unpickle_asGFF3__set_state", __pyx_f[1], 9, 0, __PYX_ERR(1, 9, __pyx_L1_error)); /* "(tree fragment)":10 * return __pyx_result - * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_asGFF3__set_state(asGFF3 __pyx_result, tuple __pyx_state): * __pyx_result.encoding = __pyx_state[0] # <<<<<<<<<<<<<< * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): * __pyx_result.__dict__.update(__pyx_state[1]) @@ -16047,7 +18396,7 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asTuple__set_state(str __pyx_t_1 = 0; /* "(tree fragment)":11 - * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_asGFF3__set_state(asGFF3 __pyx_result, tuple __pyx_state): * __pyx_result.encoding = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[1]) @@ -16134,7 +18483,7 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asTuple__set_state(str __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":11 - * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): + * cdef __pyx_unpickle_asGFF3__set_state(asGFF3 __pyx_result, tuple __pyx_state): * __pyx_result.encoding = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< * __pyx_result.__dict__.update(__pyx_state[1]) @@ -16142,9 +18491,9 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asTuple__set_state(str } /* "(tree fragment)":9 - * __pyx_unpickle_asTuple__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asGFF3__set_state( __pyx_result, __pyx_state) * return __pyx_result - * cdef __pyx_unpickle_asTuple__set_state(asTuple __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_asGFF3__set_state(asGFF3 __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.encoding = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): */ @@ -16158,7 +18507,7 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asTuple__set_state(str __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_asTuple__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabix.__pyx_unpickle_asGFF3__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -16174,10 +18523,10 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asTuple__set_state(str */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_11__pyx_unpickle_asGTF(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_10__pyx_unpickle_asGTF[] = "__pyx_unpickle_asGTF(__pyx_type, long __pyx_checksum, __pyx_state)"; -static PyMethodDef __pyx_mdef_5pysam_9libctabix_11__pyx_unpickle_asGTF = {"__pyx_unpickle_asGTF", (PyCFunction)__pyx_pw_5pysam_9libctabix_11__pyx_unpickle_asGTF, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_10__pyx_unpickle_asGTF}; -static PyObject *__pyx_pw_5pysam_9libctabix_11__pyx_unpickle_asGTF(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_9libctabix_15__pyx_unpickle_asGTF(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_14__pyx_unpickle_asGTF[] = "__pyx_unpickle_asGTF(__pyx_type, long __pyx_checksum, __pyx_state)"; +static PyMethodDef __pyx_mdef_5pysam_9libctabix_15__pyx_unpickle_asGTF = {"__pyx_unpickle_asGTF", (PyCFunction)__pyx_pw_5pysam_9libctabix_15__pyx_unpickle_asGTF, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_14__pyx_unpickle_asGTF}; +static PyObject *__pyx_pw_5pysam_9libctabix_15__pyx_unpickle_asGTF(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v___pyx_type = 0; long __pyx_v___pyx_checksum; PyObject *__pyx_v___pyx_state = 0; @@ -16240,14 +18589,14 @@ static PyObject *__pyx_pw_5pysam_9libctabix_11__pyx_unpickle_asGTF(PyObject *__p __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libctabix_10__pyx_unpickle_asGTF(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + __pyx_r = __pyx_pf_5pysam_9libctabix_14__pyx_unpickle_asGTF(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_10__pyx_unpickle_asGTF(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_9libctabix_14__pyx_unpickle_asGTF(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_v___pyx_PickleError = NULL; PyObject *__pyx_v___pyx_result = NULL; PyObject *__pyx_r = NULL; @@ -16260,7 +18609,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_10__pyx_unpickle_asGTF(CYTHON_UNUSED PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__51) + __Pyx_TraceFrameInit(__pyx_codeobj__44) __Pyx_RefNannySetupContext("__pyx_unpickle_asGTF", 0); __Pyx_TraceCall("__pyx_unpickle_asGTF", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); @@ -16660,10 +19009,10 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asGTF__set_state(struc */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_13__pyx_unpickle_asBed(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_12__pyx_unpickle_asBed[] = "__pyx_unpickle_asBed(__pyx_type, long __pyx_checksum, __pyx_state)"; -static PyMethodDef __pyx_mdef_5pysam_9libctabix_13__pyx_unpickle_asBed = {"__pyx_unpickle_asBed", (PyCFunction)__pyx_pw_5pysam_9libctabix_13__pyx_unpickle_asBed, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_12__pyx_unpickle_asBed}; -static PyObject *__pyx_pw_5pysam_9libctabix_13__pyx_unpickle_asBed(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_9libctabix_17__pyx_unpickle_asBed(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_16__pyx_unpickle_asBed[] = "__pyx_unpickle_asBed(__pyx_type, long __pyx_checksum, __pyx_state)"; +static PyMethodDef __pyx_mdef_5pysam_9libctabix_17__pyx_unpickle_asBed = {"__pyx_unpickle_asBed", (PyCFunction)__pyx_pw_5pysam_9libctabix_17__pyx_unpickle_asBed, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_16__pyx_unpickle_asBed}; +static PyObject *__pyx_pw_5pysam_9libctabix_17__pyx_unpickle_asBed(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v___pyx_type = 0; long __pyx_v___pyx_checksum; PyObject *__pyx_v___pyx_state = 0; @@ -16726,14 +19075,14 @@ static PyObject *__pyx_pw_5pysam_9libctabix_13__pyx_unpickle_asBed(PyObject *__p __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libctabix_12__pyx_unpickle_asBed(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + __pyx_r = __pyx_pf_5pysam_9libctabix_16__pyx_unpickle_asBed(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_12__pyx_unpickle_asBed(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_9libctabix_16__pyx_unpickle_asBed(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_v___pyx_PickleError = NULL; PyObject *__pyx_v___pyx_result = NULL; PyObject *__pyx_r = NULL; @@ -16746,7 +19095,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_12__pyx_unpickle_asBed(CYTHON_UNUSED PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__52) + __Pyx_TraceFrameInit(__pyx_codeobj__45) __Pyx_RefNannySetupContext("__pyx_unpickle_asBed", 0); __Pyx_TraceCall("__pyx_unpickle_asBed", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); @@ -17146,10 +19495,10 @@ static PyObject *__pyx_f_5pysam_9libctabix___pyx_unpickle_asBed__set_state(struc */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_9libctabix_15__pyx_unpickle_asVCF(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libctabix_14__pyx_unpickle_asVCF[] = "__pyx_unpickle_asVCF(__pyx_type, long __pyx_checksum, __pyx_state)"; -static PyMethodDef __pyx_mdef_5pysam_9libctabix_15__pyx_unpickle_asVCF = {"__pyx_unpickle_asVCF", (PyCFunction)__pyx_pw_5pysam_9libctabix_15__pyx_unpickle_asVCF, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_14__pyx_unpickle_asVCF}; -static PyObject *__pyx_pw_5pysam_9libctabix_15__pyx_unpickle_asVCF(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_9libctabix_19__pyx_unpickle_asVCF(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_9libctabix_18__pyx_unpickle_asVCF[] = "__pyx_unpickle_asVCF(__pyx_type, long __pyx_checksum, __pyx_state)"; +static PyMethodDef __pyx_mdef_5pysam_9libctabix_19__pyx_unpickle_asVCF = {"__pyx_unpickle_asVCF", (PyCFunction)__pyx_pw_5pysam_9libctabix_19__pyx_unpickle_asVCF, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libctabix_18__pyx_unpickle_asVCF}; +static PyObject *__pyx_pw_5pysam_9libctabix_19__pyx_unpickle_asVCF(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v___pyx_type = 0; long __pyx_v___pyx_checksum; PyObject *__pyx_v___pyx_state = 0; @@ -17212,14 +19561,14 @@ static PyObject *__pyx_pw_5pysam_9libctabix_15__pyx_unpickle_asVCF(PyObject *__p __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libctabix_14__pyx_unpickle_asVCF(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + __pyx_r = __pyx_pf_5pysam_9libctabix_18__pyx_unpickle_asVCF(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_9libctabix_14__pyx_unpickle_asVCF(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_9libctabix_18__pyx_unpickle_asVCF(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_v___pyx_PickleError = NULL; PyObject *__pyx_v___pyx_result = NULL; PyObject *__pyx_r = NULL; @@ -17232,7 +19581,7 @@ static PyObject *__pyx_pf_5pysam_9libctabix_14__pyx_unpickle_asVCF(CYTHON_UNUSED PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; int __pyx_t_7; - __Pyx_TraceFrameInit(__pyx_codeobj__53) + __Pyx_TraceFrameInit(__pyx_codeobj__46) __Pyx_RefNannySetupContext("__pyx_unpickle_asVCF", 0); __Pyx_TraceCall("__pyx_unpickle_asVCF", __pyx_f[1], 1, 0, __PYX_ERR(1, 1, __pyx_L1_error)); @@ -18517,7 +20866,7 @@ static PyMethodDef __pyx_methods_5pysam_9libctabix_TabixFile[] = { }; static struct PyGetSetDef __pyx_getsets_5pysam_9libctabix_TabixFile[] = { - {(char *)"header", __pyx_getprop_5pysam_9libctabix_9TabixFile_header, 0, (char *)"the file header.\n\n The file header consists of the lines at the beginning of a\n file that are prefixed by the comment character ``#``.\n \n .. note::\n The header is returned as an iterator presenting lines\n without the newline character.\n \n .. note::\n The header is only available for local files. For remote\n files an Attribute Error is raised.\n\n ", 0}, + {(char *)"header", __pyx_getprop_5pysam_9libctabix_9TabixFile_header, 0, (char *)"the file header.\n\n The file header consists of the lines at the beginning of a\n file that are prefixed by the comment character ``#``.\n \n .. note::\n The header is returned as an iterator presenting lines\n without the newline character.\n ", 0}, {(char *)"contigs", __pyx_getprop_5pysam_9libctabix_9TabixFile_contigs, 0, (char *)"list of chromosome names", 0}, {(char *)"filename_index", __pyx_getprop_5pysam_9libctabix_9TabixFile_filename_index, 0, (char *)0, 0}, {0, 0, 0, 0, 0} @@ -18549,7 +20898,7 @@ static PyTypeObject __pyx_type_5pysam_9libctabix_TabixFile = { 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "Random access to bgzf formatted files that\n have been indexed by :term:`tabix`.\n\n The file is automatically opened. The index file of file\n ```` is expected to be called ``.tbi``\n by default (see parameter `index`).\n \n Parameters\n ----------\n \n filename : string\n Filename of bgzf file to be opened.\n\n index : string\n The filename of the index. If not set, the default is to\n assume that the index is called ``filename.tbi`\n\n mode : char\n The file opening mode. Currently, only ``r`` is permitted.\n \n parser : :class:`pysam.Parser`\n \n sets the default parser for this tabix file. If `parser`\n is None, the results are returned as an unparsed string.\n Otherwise, `parser` is assumed to be a functor that will return\n parsed data (see for example :class:`~pysam.asTuple` and\n :class:`~pysam.asGTF`).\n\n encoding : string\n\n The encoding passed to the parser\n\n Raises\n ------\n \n ValueError\n if index file is missing.\n\n IOError\n if file could not be opened\n ", /*tp_doc*/ + "Random access to bgzf formatted files that\n have been indexed by :term:`tabix`.\n\n The file is automatically opened. The index file of file\n ```` is expected to be called ``.tbi``\n by default (see parameter `index`).\n \n Parameters\n ----------\n \n filename : string\n Filename of bgzf file to be opened.\n\n index : string\n The filename of the index. If not set, the default is to\n assume that the index is called ``filename.tbi`\n\n mode : char\n The file opening mode. Currently, only ``r`` is permitted.\n \n parser : :class:`pysam.Parser`\n \n sets the default parser for this tabix file. If `parser`\n is None, the results are returned as an unparsed string.\n Otherwise, `parser` is assumed to be a functor that will return\n parsed data (see for example :class:`~pysam.asTuple` and\n :class:`~pysam.asGTF`).\n\n encoding : string\n\n The encoding passed to the parser\n\n threads: integer\n Number of threads to use for decompressing Tabix files.\n (Default=1)\n\n\n Raises\n ------\n \n ValueError\n if index file is missing.\n\n IOError\n if file could not be opened\n ", /*tp_doc*/ __pyx_tp_traverse_5pysam_9libctabix_TabixFile, /*tp_traverse*/ __pyx_tp_clear_5pysam_9libctabix_TabixFile, /*tp_clear*/ 0, /*tp_richcompare*/ @@ -18856,6 +21205,88 @@ static PyTypeObject __pyx_type_5pysam_9libctabix_asGTF = { 0, /*tp_finalize*/ #endif }; +static struct __pyx_vtabstruct_5pysam_9libctabix_asGFF3 __pyx_vtable_5pysam_9libctabix_asGFF3; + +static PyObject *__pyx_tp_new_5pysam_9libctabix_asGFF3(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5pysam_9libctabix_asGFF3 *p; + PyObject *o = __pyx_tp_new_5pysam_9libctabix_Parser(t, a, k); + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_5pysam_9libctabix_asGFF3 *)o); + p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_9libctabix_Parser*)__pyx_vtabptr_5pysam_9libctabix_asGFF3; + return o; +} + +static PyMethodDef __pyx_methods_5pysam_9libctabix_asGFF3[] = { + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_9libctabix_6asGFF3_1__reduce_cython__, METH_NOARGS, __pyx_doc_5pysam_9libctabix_6asGFF3___reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_9libctabix_6asGFF3_3__setstate_cython__, METH_O, __pyx_doc_5pysam_9libctabix_6asGFF3_2__setstate_cython__}, + {0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_5pysam_9libctabix_asGFF3 = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libctabix.asGFF3", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_9libctabix_asGFF3), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_9libctabix_Parser, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_9libctabix_6Parser_7__call__, /*tp_call*/ + #else + 0, /*tp_call*/ + #endif + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "converts a :term:`tabix row` into a GFF record with the following\n fields:\n \n +----------+----------+-------------------------------+\n |*Column* |*Name* |*Content* |\n +----------+----------+-------------------------------+\n |1 |contig |the chromosome name |\n +----------+----------+-------------------------------+\n |2 |feature |The feature type |\n +----------+----------+-------------------------------+\n |3 |source |The feature source |\n +----------+----------+-------------------------------+\n |4 |start |genomic start coordinate |\n | | |(0-based) |\n +----------+----------+-------------------------------+\n |5 |end |genomic end coordinate |\n | | |(0-based) |\n +----------+----------+-------------------------------+\n |6 |score |feature score |\n +----------+----------+-------------------------------+\n |7 |strand |strand |\n +----------+----------+-------------------------------+\n |8 |frame |frame |\n +----------+----------+-------------------------------+\n |9 |attributes|the attribute field |\n +----------+----------+-------------------------------+\n\n ", /*tp_doc*/ + __pyx_tp_traverse_5pysam_9libctabix_Parser, /*tp_traverse*/ + __pyx_tp_clear_5pysam_9libctabix_Parser, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5pysam_9libctabix_asGFF3, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_9libctabix_6Parser_1__init__, /*tp_init*/ + #else + 0, /*tp_init*/ + #endif + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_9libctabix_asGFF3, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; static struct __pyx_vtabstruct_5pysam_9libctabix_asBed __pyx_vtable_5pysam_9libctabix_asBed; static PyObject *__pyx_tp_new_5pysam_9libctabix_asBed(PyTypeObject *t, PyObject *a, PyObject *k) { @@ -19697,13 +22128,12 @@ static struct PyModuleDef __pyx_moduledef = { static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_b_, __pyx_k_, sizeof(__pyx_k_), 0, 0, 0, 0}, - {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1}, + {&__pyx_kp_b_1f8b, __pyx_k_1f8b, sizeof(__pyx_k_1f8b), 0, 0, 0, 0}, {&__pyx_n_s_EmptyIterator, __pyx_k_EmptyIterator, sizeof(__pyx_k_EmptyIterator), 0, 0, 1, 1}, {&__pyx_n_s_EmptyIterator___iter, __pyx_k_EmptyIterator___iter, sizeof(__pyx_k_EmptyIterator___iter), 0, 0, 1, 1}, {&__pyx_n_s_EmptyIterator___next, __pyx_k_EmptyIterator___next, sizeof(__pyx_k_EmptyIterator___next), 0, 0, 1, 1}, {&__pyx_n_s_EmptyIterator_next, __pyx_k_EmptyIterator_next, sizeof(__pyx_k_EmptyIterator_next), 0, 0, 1, 1}, {&__pyx_kp_s_Filename_s_already_exists_use_fo, __pyx_k_Filename_s_already_exists_use_fo, sizeof(__pyx_k_Filename_s_already_exists_use_fo), 0, 0, 1, 0}, - {&__pyx_kp_s_Filename_s_tbi_already_exists_us, __pyx_k_Filename_s_tbi_already_exists_us, sizeof(__pyx_k_Filename_s_tbi_already_exists_us), 0, 0, 1, 0}, {&__pyx_n_s_GZIterator, __pyx_k_GZIterator, sizeof(__pyx_k_GZIterator), 0, 0, 1, 1}, {&__pyx_n_s_GZIteratorHead, __pyx_k_GZIteratorHead, sizeof(__pyx_k_GZIteratorHead), 0, 0, 1, 1}, {&__pyx_n_s_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 0, 0, 1, 1}, @@ -19725,17 +22155,22 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, {&__pyx_n_s_WINDOW_SIZE, __pyx_k_WINDOW_SIZE, sizeof(__pyx_k_WINDOW_SIZE), 0, 0, 1, 1}, {&__pyx_kp_s__24, __pyx_k__24, sizeof(__pyx_k__24), 0, 0, 1, 0}, - {&__pyx_kp_s__35, __pyx_k__35, sizeof(__pyx_k__35), 0, 0, 1, 0}, + {&__pyx_kp_s__27, __pyx_k__27, sizeof(__pyx_k__27), 0, 0, 1, 0}, + {&__pyx_n_s_a2b_hex, __pyx_k_a2b_hex, sizeof(__pyx_k_a2b_hex), 0, 0, 1, 1}, {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1}, {&__pyx_n_s_asBed, __pyx_k_asBed, sizeof(__pyx_k_asBed), 0, 0, 1, 1}, + {&__pyx_n_s_asGFF3, __pyx_k_asGFF3, sizeof(__pyx_k_asGFF3), 0, 0, 1, 1}, {&__pyx_n_s_asGTF, __pyx_k_asGTF, sizeof(__pyx_k_asGTF), 0, 0, 1, 1}, {&__pyx_n_s_asTuple, __pyx_k_asTuple, sizeof(__pyx_k_asTuple), 0, 0, 1, 1}, {&__pyx_n_s_asVCF, __pyx_k_asVCF, sizeof(__pyx_k_asVCF), 0, 0, 1, 1}, {&__pyx_n_s_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1}, {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1}, + {&__pyx_n_s_bcf, __pyx_k_bcf, sizeof(__pyx_k_bcf), 0, 0, 1, 1}, {&__pyx_n_s_bed, __pyx_k_bed, sizeof(__pyx_k_bed), 0, 0, 1, 1}, + {&__pyx_n_s_binascii, __pyx_k_binascii, sizeof(__pyx_k_binascii), 0, 0, 1, 1}, {&__pyx_n_s_buffer, __pyx_k_buffer, sizeof(__pyx_k_buffer), 0, 0, 1, 1}, {&__pyx_n_s_buffer_size, __pyx_k_buffer_size, sizeof(__pyx_k_buffer_size), 0, 0, 1, 1}, + {&__pyx_kp_s_building_of_index_for_failed, __pyx_k_building_of_index_for_failed, sizeof(__pyx_k_building_of_index_for_failed), 0, 0, 1, 0}, {&__pyx_n_s_bytes_cpy, __pyx_k_bytes_cpy, sizeof(__pyx_k_bytes_cpy), 0, 0, 1, 1}, {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1}, {&__pyx_n_s_cfn, __pyx_k_cfn, sizeof(__pyx_k_cfn), 0, 0, 1, 1}, @@ -19747,11 +22182,15 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_contigs, __pyx_k_contigs, sizeof(__pyx_k_contigs), 0, 0, 1, 1}, {&__pyx_kp_s_could_not_create_iterator_for_re, __pyx_k_could_not_create_iterator_for_re, sizeof(__pyx_k_could_not_create_iterator_for_re), 0, 0, 1, 0}, {&__pyx_kp_s_could_not_create_iterator_possib, __pyx_k_could_not_create_iterator_possib, sizeof(__pyx_k_could_not_create_iterator_possib), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_load_tbi_csi_index_of, __pyx_k_could_not_load_tbi_csi_index_of, sizeof(__pyx_k_could_not_load_tbi_csi_index_of), 0, 0, 1, 0}, {&__pyx_kp_s_could_not_open_file_s, __pyx_k_could_not_open_file_s, sizeof(__pyx_k_could_not_open_file_s), 0, 0, 1, 0}, + {&__pyx_kp_s_could_not_open_for_reading_heade, __pyx_k_could_not_open_for_reading_heade, sizeof(__pyx_k_could_not_open_for_reading_heade), 0, 0, 1, 0}, {&__pyx_kp_s_could_not_open_index_for_s, __pyx_k_could_not_open_index_for_s, sizeof(__pyx_k_could_not_open_index_for_s), 0, 0, 1, 0}, {&__pyx_kp_s_could_not_open_s_for_reading, __pyx_k_could_not_open_s_for_reading, sizeof(__pyx_k_could_not_open_s_for_reading), 0, 0, 1, 0}, {&__pyx_kp_s_could_not_open_s_for_writing, __pyx_k_could_not_open_s_for_writing, sizeof(__pyx_k_could_not_open_s_for_writing), 0, 0, 1, 0}, {&__pyx_n_s_cpy, __pyx_k_cpy, sizeof(__pyx_k_cpy), 0, 0, 1, 1}, + {&__pyx_n_s_csi, __pyx_k_csi, sizeof(__pyx_k_csi), 0, 0, 1, 1}, + {&__pyx_kp_s_csi_2, __pyx_k_csi_2, sizeof(__pyx_k_csi_2), 0, 0, 1, 0}, {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1}, {&__pyx_n_s_dup, __pyx_k_dup, sizeof(__pyx_k_dup), 0, 0, 1, 1}, @@ -19760,22 +22199,29 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1}, {&__pyx_n_s_end_col, __pyx_k_end_col, sizeof(__pyx_k_end_col), 0, 0, 1, 1}, {&__pyx_kp_s_end_out_of_range_i, __pyx_k_end_out_of_range_i, sizeof(__pyx_k_end_out_of_range_i), 0, 0, 1, 0}, - {&__pyx_n_s_endswith, __pyx_k_endswith, sizeof(__pyx_k_endswith), 0, 0, 1, 1}, {&__pyx_kp_s_error_i_when_closing_file_s, __pyx_k_error_i_when_closing_file_s, sizeof(__pyx_k_error_i_when_closing_file_s), 0, 0, 1, 0}, {&__pyx_kp_s_error_i_when_writing_to_file_s, __pyx_k_error_i_when_writing_to_file_s, sizeof(__pyx_k_error_i_when_writing_to_file_s), 0, 0, 1, 0}, {&__pyx_n_s_exists, __pyx_k_exists, sizeof(__pyx_k_exists), 0, 0, 1, 1}, + {&__pyx_n_s_fd, __pyx_k_fd, sizeof(__pyx_k_fd), 0, 0, 1, 1}, {&__pyx_n_s_fd_src, __pyx_k_fd_src, sizeof(__pyx_k_fd_src), 0, 0, 1, 1}, {&__pyx_kp_s_file_s_not_found, __pyx_k_file_s_not_found, sizeof(__pyx_k_file_s_not_found), 0, 0, 1, 0}, {&__pyx_n_s_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 0, 1, 1}, {&__pyx_n_s_filename_in, __pyx_k_filename_in, sizeof(__pyx_k_filename_in), 0, 0, 1, 1}, {&__pyx_n_s_filename_out, __pyx_k_filename_out, sizeof(__pyx_k_filename_out), 0, 0, 1, 1}, + {&__pyx_kp_s_filename_s_already_exists_use_fo, __pyx_k_filename_s_already_exists_use_fo, sizeof(__pyx_k_filename_s_already_exists_use_fo), 0, 0, 1, 0}, + {&__pyx_n_s_fmt, __pyx_k_fmt, sizeof(__pyx_k_fmt), 0, 0, 1, 1}, {&__pyx_n_s_fn, __pyx_k_fn, sizeof(__pyx_k_fn), 0, 0, 1, 1}, + {&__pyx_n_s_fn_index, __pyx_k_fn_index, sizeof(__pyx_k_fn_index), 0, 0, 1, 1}, + {&__pyx_n_s_fnidx, __pyx_k_fnidx, sizeof(__pyx_k_fnidx), 0, 0, 1, 1}, {&__pyx_n_s_force, __pyx_k_force, sizeof(__pyx_k_force), 0, 0, 1, 1}, + {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1}, {&__pyx_n_s_fp, __pyx_k_fp, sizeof(__pyx_k_fp), 0, 0, 1, 1}, {&__pyx_n_s_get_encoding, __pyx_k_get_encoding, sizeof(__pyx_k_get_encoding), 0, 0, 1, 1}, {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, {&__pyx_n_s_gff, __pyx_k_gff, sizeof(__pyx_k_gff), 0, 0, 1, 1}, {&__pyx_kp_s_gz, __pyx_k_gz, sizeof(__pyx_k_gz), 0, 0, 1, 0}, + {&__pyx_n_s_gzip_magic_hex, __pyx_k_gzip_magic_hex, sizeof(__pyx_k_gzip_magic_hex), 0, 0, 1, 1}, + {&__pyx_n_s_header, __pyx_k_header, sizeof(__pyx_k_header), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_kp_s_incomplete_line_at_s, __pyx_k_incomplete_line_at_s, sizeof(__pyx_k_incomplete_line_at_s), 0, 0, 1, 0}, {&__pyx_n_s_index, __pyx_k_index, sizeof(__pyx_k_index), 0, 0, 1, 1}, @@ -19784,14 +22230,17 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1}, {&__pyx_kp_s_invalid_file_opening_mode_s, __pyx_k_invalid_file_opening_mode_s, sizeof(__pyx_k_invalid_file_opening_mode_s), 0, 0, 1, 0}, {&__pyx_n_s_is_empty, __pyx_k_is_empty, sizeof(__pyx_k_is_empty), 0, 0, 1, 1}, + {&__pyx_n_s_is_gzip_file, __pyx_k_is_gzip_file, sizeof(__pyx_k_is_gzip_file), 0, 0, 1, 1}, {&__pyx_n_s_is_open, __pyx_k_is_open, sizeof(__pyx_k_is_open), 0, 0, 1, 1}, {&__pyx_n_s_iter, __pyx_k_iter, sizeof(__pyx_k_iter), 0, 0, 1, 1}, {&__pyx_kp_s_iterate_over_infile_Permits_the, __pyx_k_iterate_over_infile_Permits_the, sizeof(__pyx_k_iterate_over_infile_Permits_the), 0, 0, 1, 0}, {&__pyx_kp_s_iteration_on_closed_file, __pyx_k_iteration_on_closed_file, sizeof(__pyx_k_iteration_on_closed_file), 0, 0, 1, 0}, {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1}, + {&__pyx_n_s_keep_original, __pyx_k_keep_original, sizeof(__pyx_k_keep_original), 0, 0, 1, 1}, {&__pyx_n_s_keys, __pyx_k_keys, sizeof(__pyx_k_keys), 0, 0, 1, 1}, {&__pyx_n_s_length, __pyx_k_length, sizeof(__pyx_k_length), 0, 0, 1, 1}, {&__pyx_n_s_line, __pyx_k_line, sizeof(__pyx_k_line), 0, 0, 1, 1}, + {&__pyx_n_s_line_skip, __pyx_k_line_skip, sizeof(__pyx_k_line_skip), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, {&__pyx_n_s_meta_char, __pyx_k_meta_char, sizeof(__pyx_k_meta_char), 0, 0, 1, 1}, {&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1}, @@ -19807,12 +22256,12 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_next_2, __pyx_k_next_2, sizeof(__pyx_k_next_2), 0, 0, 1, 1}, {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0}, {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1}, + {&__pyx_n_s_open_2, __pyx_k_open_2, sizeof(__pyx_k_open_2), 0, 0, 1, 1}, {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1}, {&__pyx_kp_s_parse_method_of_s_not_implemente, __pyx_k_parse_method_of_s_not_implemente, sizeof(__pyx_k_parse_method_of_s_not_implemente), 0, 0, 1, 0}, {&__pyx_n_s_parser, __pyx_k_parser, sizeof(__pyx_k_parser), 0, 0, 1, 1}, {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1}, {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, - {&__pyx_n_s_pileup, __pyx_k_pileup, sizeof(__pyx_k_pileup), 0, 0, 1, 1}, {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1}, {&__pyx_n_s_preset, __pyx_k_preset, sizeof(__pyx_k_preset), 0, 0, 1, 1}, {&__pyx_n_s_preset2conf, __pyx_k_preset2conf, sizeof(__pyx_k_preset2conf), 0, 0, 1, 1}, @@ -19826,18 +22275,21 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1}, {&__pyx_n_s_pyx_unpickle_Parser, __pyx_k_pyx_unpickle_Parser, sizeof(__pyx_k_pyx_unpickle_Parser), 0, 0, 1, 1}, {&__pyx_n_s_pyx_unpickle_asBed, __pyx_k_pyx_unpickle_asBed, sizeof(__pyx_k_pyx_unpickle_asBed), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_asGFF3, __pyx_k_pyx_unpickle_asGFF3, sizeof(__pyx_k_pyx_unpickle_asGFF3), 0, 0, 1, 1}, {&__pyx_n_s_pyx_unpickle_asGTF, __pyx_k_pyx_unpickle_asGTF, sizeof(__pyx_k_pyx_unpickle_asGTF), 0, 0, 1, 1}, {&__pyx_n_s_pyx_unpickle_asTuple, __pyx_k_pyx_unpickle_asTuple, sizeof(__pyx_k_pyx_unpickle_asTuple), 0, 0, 1, 1}, {&__pyx_n_s_pyx_unpickle_asVCF, __pyx_k_pyx_unpickle_asVCF, sizeof(__pyx_k_pyx_unpickle_asVCF), 0, 0, 1, 1}, {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1}, {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1}, {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1}, + {&__pyx_n_s_read, __pyx_k_read, sizeof(__pyx_k_read), 0, 0, 1, 1}, {&__pyx_n_s_readline, __pyx_k_readline, sizeof(__pyx_k_readline), 0, 0, 1, 1}, {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, {&__pyx_n_s_reference, __pyx_k_reference, sizeof(__pyx_k_reference), 0, 0, 1, 1}, {&__pyx_n_s_region, __pyx_k_region, sizeof(__pyx_k_region), 0, 0, 1, 1}, + {&__pyx_n_s_retval, __pyx_k_retval, sizeof(__pyx_k_retval), 0, 0, 1, 1}, {&__pyx_kp_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 0}, {&__pyx_n_s_s_2, __pyx_k_s_2, sizeof(__pyx_k_s_2), 0, 0, 1, 1}, {&__pyx_kp_s_s_i, __pyx_k_s_i, sizeof(__pyx_k_s_i), 0, 0, 1, 0}, @@ -19855,6 +22307,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_start_i_end_i, __pyx_k_start_i_end_i, sizeof(__pyx_k_start_i_end_i), 0, 0, 1, 0}, {&__pyx_kp_s_start_out_of_range_i, __pyx_k_start_out_of_range_i, sizeof(__pyx_k_start_out_of_range_i), 0, 0, 1, 0}, {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, + {&__pyx_n_s_suffix, __pyx_k_suffix, sizeof(__pyx_k_suffix), 0, 0, 1, 1}, {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1}, {&__pyx_n_s_tabix_compress, __pyx_k_tabix_compress, sizeof(__pyx_k_tabix_compress), 0, 0, 1, 1}, {&__pyx_n_s_tabix_file_iterator, __pyx_k_tabix_file_iterator, sizeof(__pyx_k_tabix_file_iterator), 0, 0, 1, 1}, @@ -19868,7 +22321,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_tbi, __pyx_k_tbi, sizeof(__pyx_k_tbi), 0, 0, 1, 0}, {&__pyx_n_s_tell, __pyx_k_tell, sizeof(__pyx_k_tell), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, - {&__pyx_kp_s_the_header_is_not_available_for, __pyx_k_the_header_is_not_available_for, sizeof(__pyx_k_the_header_is_not_available_for), 0, 0, 1, 0}, + {&__pyx_n_s_threads, __pyx_k_threads, sizeof(__pyx_k_threads), 0, 0, 1, 1}, {&__pyx_kp_s_unknown_preset_s_valid_presets_a, __pyx_k_unknown_preset_s_valid_presets_a, sizeof(__pyx_k_unknown_preset_s_valid_presets_a), 0, 0, 1, 0}, {&__pyx_n_s_unlink, __pyx_k_unlink, sizeof(__pyx_k_unlink), 0, 0, 1, 1}, {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, @@ -19878,14 +22331,13 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 92, __pyx_L1_error) - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 315, __pyx_L1_error) - __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 331, __pyx_L1_error) - __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 502, __pyx_L1_error) + __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 96, __pyx_L1_error) + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 363, __pyx_L1_error) + __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 380, __pyx_L1_error) + __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 562, __pyx_L1_error) __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) - __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 598, __pyx_L1_error) - __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 794, __pyx_L1_error) - __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 888, __pyx_L1_error) + __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 673, __pyx_L1_error) + __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 989, __pyx_L1_error) __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(3, 109, __pyx_L1_error) return 0; __pyx_L1_error:; @@ -19896,68 +22348,57 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "pysam/libctabix.pyx":396 + /* "pysam/libctabix.pyx":446 * ''' * if not self.is_open(): * raise ValueError("I/O operation on closed file") # <<<<<<<<<<<<<< * * # convert coordinates to region string, which is one-based */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 396, __pyx_L1_error) + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 446, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2); - /* "pysam/libctabix.pyx":451 + /* "pysam/libctabix.pyx":501 * # when accessing a tabix file created prior tabix 1.0 * # the full-file iterator is empty. * raise ValueError( # <<<<<<<<<<<<<< * "could not create iterator, possible " * "tabix version mismatch") */ - __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_could_not_create_iterator_possib); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 451, __pyx_L1_error) + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_could_not_create_iterator_possib); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 501, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__3); - /* "pysam/libctabix.pyx":502 - * def __get__(self): - * if self.is_remote: - * raise AttributeError( # <<<<<<<<<<<<<< - * "the header is not available for remote files") - * return GZIteratorHead(self.filename) - */ - __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_the_header_is_not_available_for); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__4); - __Pyx_GIVEREF(__pyx_tuple__4); - /* "(tree fragment)":2 * def __reduce_cython__(self): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__5); - __Pyx_GIVEREF(__pyx_tuple__5); + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__6); - __Pyx_GIVEREF(__pyx_tuple__6); + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__5); + __Pyx_GIVEREF(__pyx_tuple__5); - /* "pysam/libctabix.pyx":596 + /* "pysam/libctabix.pyx":671 * cdef int retval = self.__cnext__() * if retval == -5: * raise IOError("iteration on closed file") # <<<<<<<<<<<<<< * elif retval < 0: * raise StopIteration */ - __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_iteration_on_closed_file); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 596, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__7); - __Pyx_GIVEREF(__pyx_tuple__7); + __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_iteration_on_closed_file); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 671, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -19965,29 +22406,29 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iterator cannot be converted to a Python object for pickling") */ - __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_self_iterator_cannot_be_converte); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__8); - __Pyx_GIVEREF(__pyx_tuple__8); + __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_self_iterator_cannot_be_converte); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__7); + __Pyx_GIVEREF(__pyx_tuple__7); /* "(tree fragment)":4 * raise TypeError("self.iterator cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iterator cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_self_iterator_cannot_be_converte); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__9); - __Pyx_GIVEREF(__pyx_tuple__9); + __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_self_iterator_cannot_be_converte); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__8); + __Pyx_GIVEREF(__pyx_tuple__8); - /* "pysam/libctabix.pyx":647 + /* "pysam/libctabix.pyx":722 * cdef int retval = self.__cnext__() * if retval == -5: * raise IOError("iteration on closed file") # <<<<<<<<<<<<<< * elif retval < 0: * raise StopIteration */ - __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_iteration_on_closed_file); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 647, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__13); - __Pyx_GIVEREF(__pyx_tuple__13); + __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_iteration_on_closed_file); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 722, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__12); + __Pyx_GIVEREF(__pyx_tuple__12); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -19995,18 +22436,18 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iterator cannot be converted to a Python object for pickling") */ - __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_self_iterator_cannot_be_converte); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__14); - __Pyx_GIVEREF(__pyx_tuple__14); + __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_self_iterator_cannot_be_converte); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__13); + __Pyx_GIVEREF(__pyx_tuple__13); /* "(tree fragment)":4 * raise TypeError("self.iterator cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.iterator cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_self_iterator_cannot_be_converte); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__15); - __Pyx_GIVEREF(__pyx_tuple__15); + __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_self_iterator_cannot_be_converte); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__14); + __Pyx_GIVEREF(__pyx_tuple__14); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -20014,18 +22455,18 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") */ - __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_s_self_gzipfile_self_kstream_canno); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__16); - __Pyx_GIVEREF(__pyx_tuple__16); + __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_self_gzipfile_self_kstream_canno); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__15); + __Pyx_GIVEREF(__pyx_tuple__15); /* "(tree fragment)":4 * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s_self_gzipfile_self_kstream_canno); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__17); - __Pyx_GIVEREF(__pyx_tuple__17); + __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_s_self_gzipfile_self_kstream_canno); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__16); + __Pyx_GIVEREF(__pyx_tuple__16); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -20033,18 +22474,18 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") */ - __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_self_gzipfile_self_kstream_canno); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__18); - __Pyx_GIVEREF(__pyx_tuple__18); + __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s_self_gzipfile_self_kstream_canno); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__17); + __Pyx_GIVEREF(__pyx_tuple__17); /* "(tree fragment)":4 * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_self_gzipfile_self_kstream_canno); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__19); - __Pyx_GIVEREF(__pyx_tuple__19); + __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_self_gzipfile_self_kstream_canno); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__18); + __Pyx_GIVEREF(__pyx_tuple__18); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -20052,150 +22493,62 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") */ - __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_self_gzipfile_self_kstream_canno); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__20); - __Pyx_GIVEREF(__pyx_tuple__20); + __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_self_gzipfile_self_kstream_canno); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__19); + __Pyx_GIVEREF(__pyx_tuple__19); /* "(tree fragment)":4 * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") * def __setstate_cython__(self, __pyx_state): * raise TypeError("self.gzipfile,self.kstream cannot be converted to a Python object for pickling") # <<<<<<<<<<<<<< */ - __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_self_gzipfile_self_kstream_canno); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__21); - __Pyx_GIVEREF(__pyx_tuple__21); - - /* "pysam/libctabix.pyx":794 - * if r < 0: - * free(buffer) - * raise OSError("writing failed") # <<<<<<<<<<<<<< - * - * free(buffer) - */ - __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_writing_failed); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 794, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__23); - __Pyx_GIVEREF(__pyx_tuple__23); - - /* "pysam/libctabix.pyx":860 - * if preset is None and \ - * (seq_col is None or start_col is None or end_col is None): - * raise ValueError( # <<<<<<<<<<<<<< - * "neither preset nor seq_col,start_col and end_col given") - * - */ - __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_neither_preset_nor_seq_col_start); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 860, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__26); - __Pyx_GIVEREF(__pyx_tuple__26); - - /* "pysam/libctabix.pyx":863 - * "neither preset nor seq_col,start_col and end_col given") - * - * if not filename.endswith(".gz"): # <<<<<<<<<<<<<< - * tabix_compress(filename, filename + ".gz", force=force) - * os.unlink( filename ) - */ - __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_s_gz); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 863, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__27); - __Pyx_GIVEREF(__pyx_tuple__27); - - /* "pysam/libctabix.pyx":869 - * - * if not force and os.path.exists(filename + ".tbi"): - * raise IOError( # <<<<<<<<<<<<<< - * "Filename '%s.tbi' already exists, use *force* to overwrite") - * - */ - __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_s_Filename_s_tbi_already_exists_us); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 869, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__28); - __Pyx_GIVEREF(__pyx_tuple__28); - - /* "pysam/libctabix.pyx":877 - * # 0 is a missing column - * preset2conf = { - * 'gff' : (0, 1, 4, 5, ord('#'), 0), # <<<<<<<<<<<<<< - * 'bed' : (0x10000, 1, 2, 3, ord('#'), 0), - * 'psltbl' : (0x10000, 15, 17, 18, ord('#'), 0), - */ - __pyx_tuple__29 = PyTuple_Pack(6, __pyx_int_0, __pyx_int_1, __pyx_int_4, __pyx_int_5, __pyx_int_35, __pyx_int_0); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 877, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__29); - __Pyx_GIVEREF(__pyx_tuple__29); - - /* "pysam/libctabix.pyx":878 - * preset2conf = { - * 'gff' : (0, 1, 4, 5, ord('#'), 0), - * 'bed' : (0x10000, 1, 2, 3, ord('#'), 0), # <<<<<<<<<<<<<< - * 'psltbl' : (0x10000, 15, 17, 18, ord('#'), 0), - * 'sam' : (1, 3, 4, 0, ord('@'), 0), - */ - __pyx_tuple__30 = PyTuple_Pack(6, __pyx_int_65536, __pyx_int_1, __pyx_int_2, __pyx_int_3, __pyx_int_35, __pyx_int_0); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 878, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__30); - __Pyx_GIVEREF(__pyx_tuple__30); - - /* "pysam/libctabix.pyx":879 - * 'gff' : (0, 1, 4, 5, ord('#'), 0), - * 'bed' : (0x10000, 1, 2, 3, ord('#'), 0), - * 'psltbl' : (0x10000, 15, 17, 18, ord('#'), 0), # <<<<<<<<<<<<<< - * 'sam' : (1, 3, 4, 0, ord('@'), 0), - * 'vcf' : (2, 1, 2, 0, ord('#'), 0), - */ - __pyx_tuple__31 = PyTuple_Pack(6, __pyx_int_65536, __pyx_int_15, __pyx_int_17, __pyx_int_18, __pyx_int_35, __pyx_int_0); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 879, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__31); - __Pyx_GIVEREF(__pyx_tuple__31); + __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_self_gzipfile_self_kstream_canno); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__20); + __Pyx_GIVEREF(__pyx_tuple__20); - /* "pysam/libctabix.pyx":880 - * 'bed' : (0x10000, 1, 2, 3, ord('#'), 0), - * 'psltbl' : (0x10000, 15, 17, 18, ord('#'), 0), - * 'sam' : (1, 3, 4, 0, ord('@'), 0), # <<<<<<<<<<<<<< - * 'vcf' : (2, 1, 2, 0, ord('#'), 0), - * 'pileup': (3, 1, 2, 0, ord('#'), 0), - */ - __pyx_tuple__32 = PyTuple_Pack(6, __pyx_int_1, __pyx_int_3, __pyx_int_4, __pyx_int_0, __pyx_int_64, __pyx_int_0); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 880, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__32); - __Pyx_GIVEREF(__pyx_tuple__32); - - /* "pysam/libctabix.pyx":881 - * 'psltbl' : (0x10000, 15, 17, 18, ord('#'), 0), - * 'sam' : (1, 3, 4, 0, ord('@'), 0), - * 'vcf' : (2, 1, 2, 0, ord('#'), 0), # <<<<<<<<<<<<<< - * 'pileup': (3, 1, 2, 0, ord('#'), 0), - * } + /* "pysam/libctabix.pyx":869 + * if r < 0: + * free(buffer) + * raise IOError("writing failed") # <<<<<<<<<<<<<< + * + * free(buffer) */ - __pyx_tuple__33 = PyTuple_Pack(6, __pyx_int_2, __pyx_int_1, __pyx_int_2, __pyx_int_0, __pyx_int_35, __pyx_int_0); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 881, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__33); - __Pyx_GIVEREF(__pyx_tuple__33); + __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_writing_failed); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 869, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__22); + __Pyx_GIVEREF(__pyx_tuple__22); - /* "pysam/libctabix.pyx":882 - * 'sam' : (1, 3, 4, 0, ord('@'), 0), - * 'vcf' : (2, 1, 2, 0, ord('#'), 0), - * 'pileup': (3, 1, 2, 0, ord('#'), 0), # <<<<<<<<<<<<<< - * } + /* "pysam/libctabix.pyx":953 + * if preset is None and \ + * (seq_col is None or start_col is None or end_col is None): + * raise ValueError( # <<<<<<<<<<<<<< + * "neither preset nor seq_col,start_col and end_col given") * */ - __pyx_tuple__34 = PyTuple_Pack(6, __pyx_int_3, __pyx_int_1, __pyx_int_2, __pyx_int_0, __pyx_int_35, __pyx_int_0); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 882, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__34); - __Pyx_GIVEREF(__pyx_tuple__34); + __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_neither_preset_nor_seq_col_start); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 953, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__26); + __Pyx_GIVEREF(__pyx_tuple__26); - /* "pysam/libctabix.pyx":1005 + /* "pysam/libctabix.pyx":1125 * * if infile.closed: * raise ValueError("I/O operation on closed file.") # <<<<<<<<<<<<<< * * self.infile = infile */ - __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file_2); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 1005, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__36); - __Pyx_GIVEREF(__pyx_tuple__36); + __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file_2); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 1125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__28); + __Pyx_GIVEREF(__pyx_tuple__28); - /* "pysam/libctabix.pyx":1011 + /* "pysam/libctabix.pyx":1131 * cdef int fd = PyObject_AsFileDescriptor(infile) * if fd == -1: * raise ValueError("I/O operation on closed file.") # <<<<<<<<<<<<<< * * self.duplicated_fd = dup(fd) */ - __pyx_tuple__37 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file_2); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 1011, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__37); - __Pyx_GIVEREF(__pyx_tuple__37); + __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file_2); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 1131, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__29); + __Pyx_GIVEREF(__pyx_tuple__29); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -20203,40 +22556,40 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__38); - __Pyx_GIVEREF(__pyx_tuple__38); + __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__30); + __Pyx_GIVEREF(__pyx_tuple__30); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__39); - __Pyx_GIVEREF(__pyx_tuple__39); + __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__31); + __Pyx_GIVEREF(__pyx_tuple__31); - /* "pysam/libctabix.pyx":1087 + /* "pysam/libctabix.pyx":1207 * self.infile = infile * if self.infile.closed: * raise ValueError("I/O operation on closed file.") # <<<<<<<<<<<<<< * self.parser = parser * */ - __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file_2); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 1087, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__41); - __Pyx_GIVEREF(__pyx_tuple__41); + __pyx_tuple__33 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file_2); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 1207, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__33); + __Pyx_GIVEREF(__pyx_tuple__33); - /* "pysam/libctabix.pyx":1105 + /* "pysam/libctabix.pyx":1225 * # reading is still possible. * if self.infile.closed: * raise ValueError("I/O operation on closed file.") # <<<<<<<<<<<<<< * * while 1: */ - __pyx_tuple__44 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file_2); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 1105, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__44); - __Pyx_GIVEREF(__pyx_tuple__44); + __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file_2); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 1225, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__36); + __Pyx_GIVEREF(__pyx_tuple__36); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -20244,164 +22597,180 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__47); - __Pyx_GIVEREF(__pyx_tuple__47); + __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__39); + __Pyx_GIVEREF(__pyx_tuple__39); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__48); - __Pyx_GIVEREF(__pyx_tuple__48); + __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__40); + __Pyx_GIVEREF(__pyx_tuple__40); - /* "pysam/libctabix.pyx":615 + /* "pysam/libctabix.pyx":690 * '''empty iterator''' * * def __iter__(self): # <<<<<<<<<<<<<< * return self * */ - __pyx_tuple__54 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(0, 615, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__54); - __Pyx_GIVEREF(__pyx_tuple__54); - __pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__54, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_iter, 615, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) __PYX_ERR(0, 615, __pyx_L1_error) + __pyx_tuple__47 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 690, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__47); + __Pyx_GIVEREF(__pyx_tuple__47); + __pyx_codeobj__9 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__47, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_iter, 690, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__9)) __PYX_ERR(0, 690, __pyx_L1_error) - /* "pysam/libctabix.pyx":618 + /* "pysam/libctabix.pyx":693 * return self * * def next(self): # <<<<<<<<<<<<<< * raise StopIteration() * */ - __pyx_tuple__55 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 618, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__55); - __Pyx_GIVEREF(__pyx_tuple__55); - __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__55, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_next_2, 618, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 618, __pyx_L1_error) + __pyx_tuple__48 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 693, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__48); + __Pyx_GIVEREF(__pyx_tuple__48); + __pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__48, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_next_2, 693, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) __PYX_ERR(0, 693, __pyx_L1_error) - /* "pysam/libctabix.pyx":621 + /* "pysam/libctabix.pyx":696 * raise StopIteration() * * def __next__(self): # <<<<<<<<<<<<<< * raise StopIteration() * */ - __pyx_tuple__56 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(0, 621, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__56); - __Pyx_GIVEREF(__pyx_tuple__56); - __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__56, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_next, 621, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 621, __pyx_L1_error) + __pyx_tuple__49 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 696, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__49); + __Pyx_GIVEREF(__pyx_tuple__49); + __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_next, 696, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 696, __pyx_L1_error) - /* "pysam/libctabix.pyx":746 + /* "pysam/libctabix.pyx":821 * * * def tabix_compress(filename_in, # <<<<<<<<<<<<<< * filename_out, * force=False): */ - __pyx_tuple__57 = PyTuple_Pack(13, __pyx_n_s_filename_in, __pyx_n_s_filename_out, __pyx_n_s_force, __pyx_n_s_WINDOW_SIZE, __pyx_n_s_c, __pyx_n_s_r, __pyx_n_s_buffer, __pyx_n_s_fp, __pyx_n_s_fd_src, __pyx_n_s_is_empty, __pyx_n_s_O_RDONLY, __pyx_n_s_fn, __pyx_n_s_cfn); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(0, 746, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__57); - __Pyx_GIVEREF(__pyx_tuple__57); - __pyx_codeobj__22 = (PyObject*)__Pyx_PyCode_New(3, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__57, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_tabix_compress, 746, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__22)) __PYX_ERR(0, 746, __pyx_L1_error) + __pyx_tuple__50 = PyTuple_Pack(13, __pyx_n_s_filename_in, __pyx_n_s_filename_out, __pyx_n_s_force, __pyx_n_s_WINDOW_SIZE, __pyx_n_s_c, __pyx_n_s_r, __pyx_n_s_buffer, __pyx_n_s_fp, __pyx_n_s_fd_src, __pyx_n_s_is_empty, __pyx_n_s_O_RDONLY, __pyx_n_s_fn, __pyx_n_s_cfn); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 821, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__50); + __Pyx_GIVEREF(__pyx_tuple__50); + __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(3, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__50, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_tabix_compress, 821, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 821, __pyx_L1_error) - /* "pysam/libctabix.pyx":808 + /* "pysam/libctabix.pyx":883 * * - * def tabix_index( filename, # <<<<<<<<<<<<<< - * force = False, - * seq_col = None, + * def is_gzip_file(filename): # <<<<<<<<<<<<<< + * gzip_magic_hex = b'1f8b' + * fd = os.open(filename, os.O_RDONLY) */ - __pyx_tuple__58 = PyTuple_Pack(14, __pyx_n_s_filename, __pyx_n_s_force, __pyx_n_s_seq_col, __pyx_n_s_start_col, __pyx_n_s_end_col, __pyx_n_s_preset, __pyx_n_s_meta_char, __pyx_n_s_zerobased, __pyx_n_s_min_shift, __pyx_n_s_preset2conf, __pyx_n_s_conf_data, __pyx_n_s_conf, __pyx_n_s_fn, __pyx_n_s_cfn); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(0, 808, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__58); - __Pyx_GIVEREF(__pyx_tuple__58); - __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(9, 0, 14, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__58, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_tabix_index, 808, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 808, __pyx_L1_error) + __pyx_tuple__51 = PyTuple_Pack(4, __pyx_n_s_filename, __pyx_n_s_gzip_magic_hex, __pyx_n_s_fd, __pyx_n_s_header); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 883, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__51); + __Pyx_GIVEREF(__pyx_tuple__51); + __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__51, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_is_gzip_file, 883, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 883, __pyx_L1_error) + + /* "pysam/libctabix.pyx":890 + * + * + * def tabix_index(filename, # <<<<<<<<<<<<<< + * force=False, + * seq_col=None, + */ + __pyx_tuple__52 = PyTuple_Pack(24, __pyx_n_s_filename, __pyx_n_s_force, __pyx_n_s_seq_col, __pyx_n_s_start_col, __pyx_n_s_end_col, __pyx_n_s_preset, __pyx_n_s_meta_char, __pyx_n_s_line_skip, __pyx_n_s_zerobased, __pyx_n_s_min_shift, __pyx_n_s_index, __pyx_n_s_keep_original, __pyx_n_s_csi, __pyx_n_s_fn, __pyx_n_s_cfn, __pyx_n_s_fp, __pyx_n_s_fmt, __pyx_n_s_preset2conf, __pyx_n_s_conf_data, __pyx_n_s_conf, __pyx_n_s_suffix, __pyx_n_s_fn_index, __pyx_n_s_fnidx, __pyx_n_s_retval); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(0, 890, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__52); + __Pyx_GIVEREF(__pyx_tuple__52); + __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(13, 0, 24, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__52, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_tabix_index, 890, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 890, __pyx_L1_error) - /* "pysam/libctabix.pyx":1083 + /* "pysam/libctabix.pyx":1203 * Permits the use of file-like objects for example from the gzip module. * ''' * def __init__(self, infile, parser): # <<<<<<<<<<<<<< * * self.infile = infile */ - __pyx_tuple__59 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_infile, __pyx_n_s_parser); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(0, 1083, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__59); - __Pyx_GIVEREF(__pyx_tuple__59); - __pyx_codeobj__40 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__59, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_init, 1083, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__40)) __PYX_ERR(0, 1083, __pyx_L1_error) + __pyx_tuple__53 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_infile, __pyx_n_s_parser); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 1203, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__53); + __Pyx_GIVEREF(__pyx_tuple__53); + __pyx_codeobj__32 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__53, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_init, 1203, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__32)) __PYX_ERR(0, 1203, __pyx_L1_error) - /* "pysam/libctabix.pyx":1090 + /* "pysam/libctabix.pyx":1210 * self.parser = parser * * def __iter__(self): # <<<<<<<<<<<<<< * return self * */ - __pyx_tuple__60 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(0, 1090, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__60); - __Pyx_GIVEREF(__pyx_tuple__60); - __pyx_codeobj__42 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__60, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_iter, 1090, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__42)) __PYX_ERR(0, 1090, __pyx_L1_error) + __pyx_tuple__54 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(0, 1210, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__54); + __Pyx_GIVEREF(__pyx_tuple__54); + __pyx_codeobj__34 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__54, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_iter, 1210, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__34)) __PYX_ERR(0, 1210, __pyx_L1_error) - /* "pysam/libctabix.pyx":1094 + /* "pysam/libctabix.pyx":1214 * * # cython version - required for python 3 * def __next__(self): # <<<<<<<<<<<<<< * * cdef char * b */ - __pyx_tuple__61 = PyTuple_Pack(8, __pyx_n_s_self, __pyx_n_s_b, __pyx_n_s_cpy, __pyx_n_s_nbytes, __pyx_n_s_encoding, __pyx_n_s_line, __pyx_n_s_s_2, __pyx_n_s_bytes_cpy); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(0, 1094, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__61); - __Pyx_GIVEREF(__pyx_tuple__61); - __pyx_codeobj__43 = (PyObject*)__Pyx_PyCode_New(1, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__61, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_next, 1094, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__43)) __PYX_ERR(0, 1094, __pyx_L1_error) + __pyx_tuple__55 = PyTuple_Pack(8, __pyx_n_s_self, __pyx_n_s_b, __pyx_n_s_cpy, __pyx_n_s_nbytes, __pyx_n_s_encoding, __pyx_n_s_line, __pyx_n_s_s_2, __pyx_n_s_bytes_cpy); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 1214, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__55); + __Pyx_GIVEREF(__pyx_tuple__55); + __pyx_codeobj__35 = (PyObject*)__Pyx_PyCode_New(1, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__55, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_next, 1214, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__35)) __PYX_ERR(0, 1214, __pyx_L1_error) - /* "pysam/libctabix.pyx":1138 + /* "pysam/libctabix.pyx":1258 * * # python version - required for python 2.7 * def next(self): # <<<<<<<<<<<<<< * return self.__next__() * */ - __pyx_tuple__62 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(0, 1138, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__62); - __Pyx_GIVEREF(__pyx_tuple__62); - __pyx_codeobj__45 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__62, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_next_2, 1138, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__45)) __PYX_ERR(0, 1138, __pyx_L1_error) + __pyx_tuple__56 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(0, 1258, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__56); + __Pyx_GIVEREF(__pyx_tuple__56); + __pyx_codeobj__37 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__56, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_next_2, 1258, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__37)) __PYX_ERR(0, 1258, __pyx_L1_error) - /* "pysam/libctabix.pyx":1141 - * return self.__next__() + /* "pysam/libctabix.pyx":1262 + * * * def tabix_iterator(infile, parser): # <<<<<<<<<<<<<< * """return an iterator over all entries in a file. * */ - __pyx_tuple__63 = PyTuple_Pack(2, __pyx_n_s_infile, __pyx_n_s_parser); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(0, 1141, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__63); - __Pyx_GIVEREF(__pyx_tuple__63); - __pyx_codeobj__46 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__63, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_tabix_iterator, 1141, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__46)) __PYX_ERR(0, 1141, __pyx_L1_error) + __pyx_tuple__57 = PyTuple_Pack(2, __pyx_n_s_infile, __pyx_n_s_parser); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(0, 1262, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__57); + __Pyx_GIVEREF(__pyx_tuple__57); + __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__57, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabix_pyx, __pyx_n_s_tabix_iterator, 1262, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 1262, __pyx_L1_error) /* "(tree fragment)":1 * def __pyx_unpickle_Parser(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x84bea1f: * from pickle import PickleError as __pyx_PickleError */ - __pyx_tuple__64 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__64); - __Pyx_GIVEREF(__pyx_tuple__64); - __pyx_codeobj__49 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__64, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_Parser, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__49)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__65 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__65); - __Pyx_GIVEREF(__pyx_tuple__65); - __pyx_codeobj__50 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__65, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_asTuple, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__50)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__66 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__66)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__66); - __Pyx_GIVEREF(__pyx_tuple__66); - __pyx_codeobj__51 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__66, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_asGTF, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__51)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__67 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__67); - __Pyx_GIVEREF(__pyx_tuple__67); - __pyx_codeobj__52 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__67, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_asBed, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__52)) __PYX_ERR(1, 1, __pyx_L1_error) - __pyx_tuple__68 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__68)) __PYX_ERR(1, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__68); - __Pyx_GIVEREF(__pyx_tuple__68); - __pyx_codeobj__53 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__68, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_asVCF, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__53)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_tuple__58 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__58); + __Pyx_GIVEREF(__pyx_tuple__58); + __pyx_codeobj__41 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__58, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_Parser, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__41)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_tuple__59 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__59); + __Pyx_GIVEREF(__pyx_tuple__59); + __pyx_codeobj__42 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__59, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_asTuple, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__42)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_tuple__60 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__60); + __Pyx_GIVEREF(__pyx_tuple__60); + __pyx_codeobj__43 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__60, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_asGFF3, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__43)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_tuple__61 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__61); + __Pyx_GIVEREF(__pyx_tuple__61); + __pyx_codeobj__44 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__61, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_asGTF, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__44)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_tuple__62 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__62); + __Pyx_GIVEREF(__pyx_tuple__62); + __pyx_codeobj__45 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__62, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_asBed, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__45)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_tuple__63 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__63); + __Pyx_GIVEREF(__pyx_tuple__63); + __pyx_codeobj__46 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__63, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_asVCF, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__46)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -20423,7 +22792,6 @@ static int __Pyx_InitGlobals(void) { __pyx_int_18 = PyInt_FromLong(18); if (unlikely(!__pyx_int_18)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_35 = PyInt_FromLong(35); if (unlikely(!__pyx_int_35)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_64 = PyInt_FromLong(64); if (unlikely(!__pyx_int_64)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_int_65536 = PyInt_FromLong(65536L); if (unlikely(!__pyx_int_65536)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_139192863 = PyInt_FromLong(139192863L); if (unlikely(!__pyx_int_139192863)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error) return 0; @@ -20469,102 +22837,115 @@ static int __Pyx_modinit_type_init_code(void) { /*--- Type init code ---*/ __pyx_vtabptr_5pysam_9libctabix_tabix_file_iterator = &__pyx_vtable_5pysam_9libctabix_tabix_file_iterator; __pyx_vtable_5pysam_9libctabix_tabix_file_iterator.__pyx___cnext__ = (PyObject *(*)(struct __pyx_obj_5pysam_9libctabix_tabix_file_iterator *))__pyx_f_5pysam_9libctabix_19tabix_file_iterator___cnext__; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_tabix_file_iterator) < 0) __PYX_ERR(0, 995, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_tabix_file_iterator) < 0) __PYX_ERR(0, 1115, __pyx_L1_error) __pyx_type_5pysam_9libctabix_tabix_file_iterator.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_tabix_file_iterator.tp_dictoffset && __pyx_type_5pysam_9libctabix_tabix_file_iterator.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_tabix_file_iterator.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_tabix_file_iterator.tp_dict, __pyx_vtabptr_5pysam_9libctabix_tabix_file_iterator) < 0) __PYX_ERR(0, 995, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "tabix_file_iterator", (PyObject *)&__pyx_type_5pysam_9libctabix_tabix_file_iterator) < 0) __PYX_ERR(0, 995, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_tabix_file_iterator) < 0) __PYX_ERR(0, 995, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_tabix_file_iterator.tp_dict, __pyx_vtabptr_5pysam_9libctabix_tabix_file_iterator) < 0) __PYX_ERR(0, 1115, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "tabix_file_iterator", (PyObject *)&__pyx_type_5pysam_9libctabix_tabix_file_iterator) < 0) __PYX_ERR(0, 1115, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_tabix_file_iterator) < 0) __PYX_ERR(0, 1115, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_tabix_file_iterator = &__pyx_type_5pysam_9libctabix_tabix_file_iterator; __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_vtabptr_5pysam_9libctabix_TabixFile = &__pyx_vtable_5pysam_9libctabix_TabixFile; __pyx_vtable_5pysam_9libctabix_TabixFile.__pyx_base = *__pyx_vtabptr_5pysam_10libchtslib_HTSFile; __pyx_type_5pysam_9libctabix_TabixFile.tp_base = __pyx_ptype_5pysam_10libchtslib_HTSFile; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_TabixFile) < 0) __PYX_ERR(0, 249, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_TabixFile) < 0) __PYX_ERR(0, 289, __pyx_L1_error) __pyx_type_5pysam_9libctabix_TabixFile.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_TabixFile.tp_dictoffset && __pyx_type_5pysam_9libctabix_TabixFile.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_TabixFile.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_TabixFile.tp_dict, __pyx_vtabptr_5pysam_9libctabix_TabixFile) < 0) __PYX_ERR(0, 249, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "TabixFile", (PyObject *)&__pyx_type_5pysam_9libctabix_TabixFile) < 0) __PYX_ERR(0, 249, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_TabixFile) < 0) __PYX_ERR(0, 249, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_TabixFile.tp_dict, __pyx_vtabptr_5pysam_9libctabix_TabixFile) < 0) __PYX_ERR(0, 289, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "TabixFile", (PyObject *)&__pyx_type_5pysam_9libctabix_TabixFile) < 0) __PYX_ERR(0, 289, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_TabixFile) < 0) __PYX_ERR(0, 289, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_TabixFile = &__pyx_type_5pysam_9libctabix_TabixFile; __pyx_vtabptr_5pysam_9libctabix_Parser = &__pyx_vtable_5pysam_9libctabix_Parser; __pyx_vtable_5pysam_9libctabix_Parser.parse = (PyObject *(*)(struct __pyx_obj_5pysam_9libctabix_Parser *, char *, int))__pyx_f_5pysam_9libctabix_6Parser_parse; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_Parser) < 0) __PYX_ERR(0, 80, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_Parser) < 0) __PYX_ERR(0, 84, __pyx_L1_error) __pyx_type_5pysam_9libctabix_Parser.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_Parser.tp_dictoffset && __pyx_type_5pysam_9libctabix_Parser.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_Parser.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_Parser.tp_dict, __pyx_vtabptr_5pysam_9libctabix_Parser) < 0) __PYX_ERR(0, 80, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "Parser", (PyObject *)&__pyx_type_5pysam_9libctabix_Parser) < 0) __PYX_ERR(0, 80, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_Parser) < 0) __PYX_ERR(0, 80, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_Parser.tp_dict, __pyx_vtabptr_5pysam_9libctabix_Parser) < 0) __PYX_ERR(0, 84, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "Parser", (PyObject *)&__pyx_type_5pysam_9libctabix_Parser) < 0) __PYX_ERR(0, 84, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_Parser) < 0) __PYX_ERR(0, 84, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_Parser = &__pyx_type_5pysam_9libctabix_Parser; __pyx_vtabptr_5pysam_9libctabix_asTuple = &__pyx_vtable_5pysam_9libctabix_asTuple; __pyx_vtable_5pysam_9libctabix_asTuple.__pyx_base = *__pyx_vtabptr_5pysam_9libctabix_Parser; __pyx_vtable_5pysam_9libctabix_asTuple.__pyx_base.parse = (PyObject *(*)(struct __pyx_obj_5pysam_9libctabix_Parser *, char *, int))__pyx_f_5pysam_9libctabix_7asTuple_parse; __pyx_type_5pysam_9libctabix_asTuple.tp_base = __pyx_ptype_5pysam_9libctabix_Parser; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_asTuple) < 0) __PYX_ERR(0, 99, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_asTuple) < 0) __PYX_ERR(0, 103, __pyx_L1_error) __pyx_type_5pysam_9libctabix_asTuple.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_asTuple.tp_dictoffset && __pyx_type_5pysam_9libctabix_asTuple.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_asTuple.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_asTuple.tp_dict, __pyx_vtabptr_5pysam_9libctabix_asTuple) < 0) __PYX_ERR(0, 99, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "asTuple", (PyObject *)&__pyx_type_5pysam_9libctabix_asTuple) < 0) __PYX_ERR(0, 99, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_asTuple) < 0) __PYX_ERR(0, 99, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_asTuple.tp_dict, __pyx_vtabptr_5pysam_9libctabix_asTuple) < 0) __PYX_ERR(0, 103, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "asTuple", (PyObject *)&__pyx_type_5pysam_9libctabix_asTuple) < 0) __PYX_ERR(0, 103, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_asTuple) < 0) __PYX_ERR(0, 103, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_asTuple = &__pyx_type_5pysam_9libctabix_asTuple; __pyx_vtabptr_5pysam_9libctabix_asGTF = &__pyx_vtable_5pysam_9libctabix_asGTF; __pyx_vtable_5pysam_9libctabix_asGTF.__pyx_base = *__pyx_vtabptr_5pysam_9libctabix_Parser; __pyx_vtable_5pysam_9libctabix_asGTF.__pyx_base.parse = (PyObject *(*)(struct __pyx_obj_5pysam_9libctabix_Parser *, char *, int))__pyx_f_5pysam_9libctabix_5asGTF_parse; __pyx_type_5pysam_9libctabix_asGTF.tp_base = __pyx_ptype_5pysam_9libctabix_Parser; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_asGTF) < 0) __PYX_ERR(0, 113, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_asGTF) < 0) __PYX_ERR(0, 153, __pyx_L1_error) __pyx_type_5pysam_9libctabix_asGTF.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_asGTF.tp_dictoffset && __pyx_type_5pysam_9libctabix_asGTF.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_asGTF.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_asGTF.tp_dict, __pyx_vtabptr_5pysam_9libctabix_asGTF) < 0) __PYX_ERR(0, 113, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "asGTF", (PyObject *)&__pyx_type_5pysam_9libctabix_asGTF) < 0) __PYX_ERR(0, 113, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_asGTF) < 0) __PYX_ERR(0, 113, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_asGTF.tp_dict, __pyx_vtabptr_5pysam_9libctabix_asGTF) < 0) __PYX_ERR(0, 153, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "asGTF", (PyObject *)&__pyx_type_5pysam_9libctabix_asGTF) < 0) __PYX_ERR(0, 153, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_asGTF) < 0) __PYX_ERR(0, 153, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_asGTF = &__pyx_type_5pysam_9libctabix_asGTF; + __pyx_vtabptr_5pysam_9libctabix_asGFF3 = &__pyx_vtable_5pysam_9libctabix_asGFF3; + __pyx_vtable_5pysam_9libctabix_asGFF3.__pyx_base = *__pyx_vtabptr_5pysam_9libctabix_Parser; + __pyx_vtable_5pysam_9libctabix_asGFF3.__pyx_base.parse = (PyObject *(*)(struct __pyx_obj_5pysam_9libctabix_Parser *, char *, int))__pyx_f_5pysam_9libctabix_6asGFF3_parse; + __pyx_type_5pysam_9libctabix_asGFF3.tp_base = __pyx_ptype_5pysam_9libctabix_Parser; + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_asGFF3) < 0) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_type_5pysam_9libctabix_asGFF3.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_asGFF3.tp_dictoffset && __pyx_type_5pysam_9libctabix_asGFF3.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_9libctabix_asGFF3.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_asGFF3.tp_dict, __pyx_vtabptr_5pysam_9libctabix_asGFF3) < 0) __PYX_ERR(0, 117, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "asGFF3", (PyObject *)&__pyx_type_5pysam_9libctabix_asGFF3) < 0) __PYX_ERR(0, 117, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_asGFF3) < 0) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_ptype_5pysam_9libctabix_asGFF3 = &__pyx_type_5pysam_9libctabix_asGFF3; __pyx_vtabptr_5pysam_9libctabix_asBed = &__pyx_vtable_5pysam_9libctabix_asBed; __pyx_vtable_5pysam_9libctabix_asBed.__pyx_base = *__pyx_vtabptr_5pysam_9libctabix_Parser; __pyx_vtable_5pysam_9libctabix_asBed.__pyx_base.parse = (PyObject *(*)(struct __pyx_obj_5pysam_9libctabix_Parser *, char *, int))__pyx_f_5pysam_9libctabix_5asBed_parse; __pyx_type_5pysam_9libctabix_asBed.tp_base = __pyx_ptype_5pysam_9libctabix_Parser; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_asBed) < 0) __PYX_ERR(0, 160, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_asBed) < 0) __PYX_ERR(0, 200, __pyx_L1_error) __pyx_type_5pysam_9libctabix_asBed.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_asBed.tp_dictoffset && __pyx_type_5pysam_9libctabix_asBed.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_asBed.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_asBed.tp_dict, __pyx_vtabptr_5pysam_9libctabix_asBed) < 0) __PYX_ERR(0, 160, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "asBed", (PyObject *)&__pyx_type_5pysam_9libctabix_asBed) < 0) __PYX_ERR(0, 160, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_asBed) < 0) __PYX_ERR(0, 160, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_asBed.tp_dict, __pyx_vtabptr_5pysam_9libctabix_asBed) < 0) __PYX_ERR(0, 200, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "asBed", (PyObject *)&__pyx_type_5pysam_9libctabix_asBed) < 0) __PYX_ERR(0, 200, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_asBed) < 0) __PYX_ERR(0, 200, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_asBed = &__pyx_type_5pysam_9libctabix_asBed; __pyx_vtabptr_5pysam_9libctabix_asVCF = &__pyx_vtable_5pysam_9libctabix_asVCF; __pyx_vtable_5pysam_9libctabix_asVCF.__pyx_base = *__pyx_vtabptr_5pysam_9libctabix_Parser; __pyx_vtable_5pysam_9libctabix_asVCF.__pyx_base.parse = (PyObject *(*)(struct __pyx_obj_5pysam_9libctabix_Parser *, char *, int))__pyx_f_5pysam_9libctabix_5asVCF_parse; __pyx_type_5pysam_9libctabix_asVCF.tp_base = __pyx_ptype_5pysam_9libctabix_Parser; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_asVCF) < 0) __PYX_ERR(0, 208, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_asVCF) < 0) __PYX_ERR(0, 248, __pyx_L1_error) __pyx_type_5pysam_9libctabix_asVCF.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_asVCF.tp_dictoffset && __pyx_type_5pysam_9libctabix_asVCF.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_asVCF.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_asVCF.tp_dict, __pyx_vtabptr_5pysam_9libctabix_asVCF) < 0) __PYX_ERR(0, 208, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "asVCF", (PyObject *)&__pyx_type_5pysam_9libctabix_asVCF) < 0) __PYX_ERR(0, 208, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_asVCF) < 0) __PYX_ERR(0, 208, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_asVCF.tp_dict, __pyx_vtabptr_5pysam_9libctabix_asVCF) < 0) __PYX_ERR(0, 248, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "asVCF", (PyObject *)&__pyx_type_5pysam_9libctabix_asVCF) < 0) __PYX_ERR(0, 248, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_asVCF) < 0) __PYX_ERR(0, 248, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_asVCF = &__pyx_type_5pysam_9libctabix_asVCF; __pyx_vtabptr_5pysam_9libctabix_TabixIterator = &__pyx_vtable_5pysam_9libctabix_TabixIterator; __pyx_vtable_5pysam_9libctabix_TabixIterator.__pyx___cnext__ = (int (*)(struct __pyx_obj_5pysam_9libctabix_TabixIterator *))__pyx_f_5pysam_9libctabix_13TabixIterator___cnext__; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_TabixIterator) < 0) __PYX_ERR(0, 546, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_TabixIterator) < 0) __PYX_ERR(0, 621, __pyx_L1_error) __pyx_type_5pysam_9libctabix_TabixIterator.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_TabixIterator.tp_dictoffset && __pyx_type_5pysam_9libctabix_TabixIterator.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_TabixIterator.tp_getattro = __Pyx_PyObject_GenericGetAttr; } #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libctabix_TabixIterator, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 546, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libctabix_TabixIterator, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 621, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_9libctabix_13TabixIterator_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_9libctabix_13TabixIterator_4__next__.doc = __pyx_doc_5pysam_9libctabix_13TabixIterator_4__next__; @@ -20572,21 +22953,21 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_TabixIterator.tp_dict, __pyx_vtabptr_5pysam_9libctabix_TabixIterator) < 0) __PYX_ERR(0, 546, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "TabixIterator", (PyObject *)&__pyx_type_5pysam_9libctabix_TabixIterator) < 0) __PYX_ERR(0, 546, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_TabixIterator) < 0) __PYX_ERR(0, 546, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_TabixIterator.tp_dict, __pyx_vtabptr_5pysam_9libctabix_TabixIterator) < 0) __PYX_ERR(0, 621, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "TabixIterator", (PyObject *)&__pyx_type_5pysam_9libctabix_TabixIterator) < 0) __PYX_ERR(0, 621, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_TabixIterator) < 0) __PYX_ERR(0, 621, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_TabixIterator = &__pyx_type_5pysam_9libctabix_TabixIterator; __pyx_vtabptr_5pysam_9libctabix_TabixIteratorParsed = &__pyx_vtable_5pysam_9libctabix_TabixIteratorParsed; __pyx_vtable_5pysam_9libctabix_TabixIteratorParsed.__pyx_base = *__pyx_vtabptr_5pysam_9libctabix_TabixIterator; __pyx_type_5pysam_9libctabix_TabixIteratorParsed.tp_base = __pyx_ptype_5pysam_9libctabix_TabixIterator; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_TabixIteratorParsed) < 0) __PYX_ERR(0, 625, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_TabixIteratorParsed) < 0) __PYX_ERR(0, 700, __pyx_L1_error) __pyx_type_5pysam_9libctabix_TabixIteratorParsed.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_TabixIteratorParsed.tp_dictoffset && __pyx_type_5pysam_9libctabix_TabixIteratorParsed.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_TabixIteratorParsed.tp_getattro = __Pyx_PyObject_GenericGetAttr; } #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libctabix_TabixIteratorParsed, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 625, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libctabix_TabixIteratorParsed, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 700, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_9libctabix_19TabixIteratorParsed_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_9libctabix_19TabixIteratorParsed_2__next__.doc = __pyx_doc_5pysam_9libctabix_19TabixIteratorParsed_2__next__; @@ -20594,20 +22975,20 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_TabixIteratorParsed.tp_dict, __pyx_vtabptr_5pysam_9libctabix_TabixIteratorParsed) < 0) __PYX_ERR(0, 625, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "TabixIteratorParsed", (PyObject *)&__pyx_type_5pysam_9libctabix_TabixIteratorParsed) < 0) __PYX_ERR(0, 625, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_TabixIteratorParsed) < 0) __PYX_ERR(0, 625, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_TabixIteratorParsed.tp_dict, __pyx_vtabptr_5pysam_9libctabix_TabixIteratorParsed) < 0) __PYX_ERR(0, 700, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "TabixIteratorParsed", (PyObject *)&__pyx_type_5pysam_9libctabix_TabixIteratorParsed) < 0) __PYX_ERR(0, 700, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_TabixIteratorParsed) < 0) __PYX_ERR(0, 700, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_TabixIteratorParsed = &__pyx_type_5pysam_9libctabix_TabixIteratorParsed; __pyx_vtabptr_5pysam_9libctabix_GZIterator = &__pyx_vtable_5pysam_9libctabix_GZIterator; __pyx_vtable_5pysam_9libctabix_GZIterator.__pyx___cnext__ = (int (*)(struct __pyx_obj_5pysam_9libctabix_GZIterator *))__pyx_f_5pysam_9libctabix_10GZIterator___cnext__; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_GZIterator) < 0) __PYX_ERR(0, 655, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_GZIterator) < 0) __PYX_ERR(0, 730, __pyx_L1_error) __pyx_type_5pysam_9libctabix_GZIterator.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_GZIterator.tp_dictoffset && __pyx_type_5pysam_9libctabix_GZIterator.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_GZIterator.tp_getattro = __Pyx_PyObject_GenericGetAttr; } #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libctabix_GZIterator, "__init__"); if (unlikely(!wrapper)) __PYX_ERR(0, 655, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libctabix_GZIterator, "__init__"); if (unlikely(!wrapper)) __PYX_ERR(0, 730, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_9libctabix_10GZIterator___init__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_9libctabix_10GZIterator___init__.doc = __pyx_doc_5pysam_9libctabix_10GZIterator___init__; @@ -20617,7 +22998,7 @@ static int __Pyx_modinit_type_init_code(void) { #endif #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libctabix_GZIterator, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 655, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libctabix_GZIterator, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 730, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_9libctabix_10GZIterator_6__next__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_9libctabix_10GZIterator_6__next__.doc = __pyx_doc_5pysam_9libctabix_10GZIterator_6__next__; @@ -20625,21 +23006,21 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_GZIterator.tp_dict, __pyx_vtabptr_5pysam_9libctabix_GZIterator) < 0) __PYX_ERR(0, 655, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "GZIterator", (PyObject *)&__pyx_type_5pysam_9libctabix_GZIterator) < 0) __PYX_ERR(0, 655, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_GZIterator) < 0) __PYX_ERR(0, 655, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_GZIterator.tp_dict, __pyx_vtabptr_5pysam_9libctabix_GZIterator) < 0) __PYX_ERR(0, 730, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "GZIterator", (PyObject *)&__pyx_type_5pysam_9libctabix_GZIterator) < 0) __PYX_ERR(0, 730, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_GZIterator) < 0) __PYX_ERR(0, 730, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_GZIterator = &__pyx_type_5pysam_9libctabix_GZIterator; __pyx_vtabptr_5pysam_9libctabix_GZIteratorHead = &__pyx_vtable_5pysam_9libctabix_GZIteratorHead; __pyx_vtable_5pysam_9libctabix_GZIteratorHead.__pyx_base = *__pyx_vtabptr_5pysam_9libctabix_GZIterator; __pyx_type_5pysam_9libctabix_GZIteratorHead.tp_base = __pyx_ptype_5pysam_9libctabix_GZIterator; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_GZIteratorHead) < 0) __PYX_ERR(0, 710, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_GZIteratorHead) < 0) __PYX_ERR(0, 785, __pyx_L1_error) __pyx_type_5pysam_9libctabix_GZIteratorHead.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_GZIteratorHead.tp_dictoffset && __pyx_type_5pysam_9libctabix_GZIteratorHead.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_GZIteratorHead.tp_getattro = __Pyx_PyObject_GenericGetAttr; } #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libctabix_GZIteratorHead, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 710, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libctabix_GZIteratorHead, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 785, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_9libctabix_14GZIteratorHead___next__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_9libctabix_14GZIteratorHead___next__.doc = __pyx_doc_5pysam_9libctabix_14GZIteratorHead___next__; @@ -20647,21 +23028,21 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_GZIteratorHead.tp_dict, __pyx_vtabptr_5pysam_9libctabix_GZIteratorHead) < 0) __PYX_ERR(0, 710, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "GZIteratorHead", (PyObject *)&__pyx_type_5pysam_9libctabix_GZIteratorHead) < 0) __PYX_ERR(0, 710, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_GZIteratorHead) < 0) __PYX_ERR(0, 710, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_GZIteratorHead.tp_dict, __pyx_vtabptr_5pysam_9libctabix_GZIteratorHead) < 0) __PYX_ERR(0, 785, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "GZIteratorHead", (PyObject *)&__pyx_type_5pysam_9libctabix_GZIteratorHead) < 0) __PYX_ERR(0, 785, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_GZIteratorHead) < 0) __PYX_ERR(0, 785, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_GZIteratorHead = &__pyx_type_5pysam_9libctabix_GZIteratorHead; __pyx_vtabptr_5pysam_9libctabix_GZIteratorParsed = &__pyx_vtable_5pysam_9libctabix_GZIteratorParsed; __pyx_vtable_5pysam_9libctabix_GZIteratorParsed.__pyx_base = *__pyx_vtabptr_5pysam_9libctabix_GZIterator; __pyx_type_5pysam_9libctabix_GZIteratorParsed.tp_base = __pyx_ptype_5pysam_9libctabix_GZIterator; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_GZIteratorParsed) < 0) __PYX_ERR(0, 727, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_GZIteratorParsed) < 0) __PYX_ERR(0, 802, __pyx_L1_error) __pyx_type_5pysam_9libctabix_GZIteratorParsed.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_GZIteratorParsed.tp_dictoffset && __pyx_type_5pysam_9libctabix_GZIteratorParsed.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_GZIteratorParsed.tp_getattro = __Pyx_PyObject_GenericGetAttr; } #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libctabix_GZIteratorParsed, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 727, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_9libctabix_GZIteratorParsed, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 802, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_9libctabix_16GZIteratorParsed_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_9libctabix_16GZIteratorParsed_2__next__.doc = __pyx_doc_5pysam_9libctabix_16GZIteratorParsed_2__next__; @@ -20669,21 +23050,21 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_GZIteratorParsed.tp_dict, __pyx_vtabptr_5pysam_9libctabix_GZIteratorParsed) < 0) __PYX_ERR(0, 727, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "GZIteratorParsed", (PyObject *)&__pyx_type_5pysam_9libctabix_GZIteratorParsed) < 0) __PYX_ERR(0, 727, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_GZIteratorParsed) < 0) __PYX_ERR(0, 727, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_GZIteratorParsed.tp_dict, __pyx_vtabptr_5pysam_9libctabix_GZIteratorParsed) < 0) __PYX_ERR(0, 802, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "GZIteratorParsed", (PyObject *)&__pyx_type_5pysam_9libctabix_GZIteratorParsed) < 0) __PYX_ERR(0, 802, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_GZIteratorParsed) < 0) __PYX_ERR(0, 802, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_GZIteratorParsed = &__pyx_type_5pysam_9libctabix_GZIteratorParsed; __pyx_vtabptr_5pysam_9libctabix_Tabixfile = &__pyx_vtable_5pysam_9libctabix_Tabixfile; __pyx_vtable_5pysam_9libctabix_Tabixfile.__pyx_base = *__pyx_vtabptr_5pysam_9libctabix_TabixFile; __pyx_type_5pysam_9libctabix_Tabixfile.tp_base = __pyx_ptype_5pysam_9libctabix_TabixFile; - if (PyType_Ready(&__pyx_type_5pysam_9libctabix_Tabixfile) < 0) __PYX_ERR(0, 1169, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_9libctabix_Tabixfile) < 0) __PYX_ERR(0, 1290, __pyx_L1_error) __pyx_type_5pysam_9libctabix_Tabixfile.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_9libctabix_Tabixfile.tp_dictoffset && __pyx_type_5pysam_9libctabix_Tabixfile.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_9libctabix_Tabixfile.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_Tabixfile.tp_dict, __pyx_vtabptr_5pysam_9libctabix_Tabixfile) < 0) __PYX_ERR(0, 1169, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "Tabixfile", (PyObject *)&__pyx_type_5pysam_9libctabix_Tabixfile) < 0) __PYX_ERR(0, 1169, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_Tabixfile) < 0) __PYX_ERR(0, 1169, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_9libctabix_Tabixfile.tp_dict, __pyx_vtabptr_5pysam_9libctabix_Tabixfile) < 0) __PYX_ERR(0, 1290, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "Tabixfile", (PyObject *)&__pyx_type_5pysam_9libctabix_Tabixfile) < 0) __PYX_ERR(0, 1290, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_9libctabix_Tabixfile) < 0) __PYX_ERR(0, 1290, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_Tabixfile = &__pyx_type_5pysam_9libctabix_Tabixfile; __Pyx_RefNannyFinishContext(); return 0; @@ -20707,14 +23088,16 @@ static int __Pyx_modinit_type_import_code(void) { __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) __PYX_ERR(6, 15, __pyx_L1_error) __pyx_ptype_5pysam_16libctabixproxies_TupleProxy = __Pyx_ImportType("pysam.libctabixproxies", "TupleProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_TupleProxy)) __PYX_ERR(7, 6, __pyx_L1_error) __pyx_vtabptr_5pysam_16libctabixproxies_TupleProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_TupleProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_TupleProxy)) __PYX_ERR(7, 6, __pyx_L1_error) - __pyx_ptype_5pysam_16libctabixproxies_GTFProxy = __Pyx_ImportType("pysam.libctabixproxies", "GTFProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_GTFProxy)) __PYX_ERR(7, 28, __pyx_L1_error) - __pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_GTFProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy)) __PYX_ERR(7, 28, __pyx_L1_error) - __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy = __Pyx_ImportType("pysam.libctabixproxies", "NamedTupleProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy)) __PYX_ERR(7, 38, __pyx_L1_error) - __pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy)) __PYX_ERR(7, 38, __pyx_L1_error) - __pyx_ptype_5pysam_16libctabixproxies_BedProxy = __Pyx_ImportType("pysam.libctabixproxies", "BedProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_BedProxy)) __PYX_ERR(7, 41, __pyx_L1_error) - __pyx_vtabptr_5pysam_16libctabixproxies_BedProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_BedProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_BedProxy)) __PYX_ERR(7, 41, __pyx_L1_error) - __pyx_ptype_5pysam_16libctabixproxies_VCFProxy = __Pyx_ImportType("pysam.libctabixproxies", "VCFProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_VCFProxy)) __PYX_ERR(7, 53, __pyx_L1_error) - __pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_VCFProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_VCFProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy)) __PYX_ERR(7, 53, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy = __Pyx_ImportType("pysam.libctabixproxies", "NamedTupleProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy)) __PYX_ERR(7, 29, __pyx_L1_error) + __pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy)) __PYX_ERR(7, 29, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_GTFProxy = __Pyx_ImportType("pysam.libctabixproxies", "GTFProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_GTFProxy)) __PYX_ERR(7, 33, __pyx_L1_error) + __pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_GTFProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy)) __PYX_ERR(7, 33, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_GFF3Proxy = __Pyx_ImportType("pysam.libctabixproxies", "GFF3Proxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_GFF3Proxy)) __PYX_ERR(7, 39, __pyx_L1_error) + __pyx_vtabptr_5pysam_16libctabixproxies_GFF3Proxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_GFF3Proxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_GFF3Proxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_GFF3Proxy)) __PYX_ERR(7, 39, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_BedProxy = __Pyx_ImportType("pysam.libctabixproxies", "BedProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_BedProxy)) __PYX_ERR(7, 43, __pyx_L1_error) + __pyx_vtabptr_5pysam_16libctabixproxies_BedProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_BedProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_BedProxy)) __PYX_ERR(7, 43, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_VCFProxy = __Pyx_ImportType("pysam.libctabixproxies", "VCFProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_VCFProxy)) __PYX_ERR(7, 55, __pyx_L1_error) + __pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_VCFProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_VCFProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy)) __PYX_ERR(7, 55, __pyx_L1_error) __pyx_ptype_7cpython_5array_array = __Pyx_ImportType("array", "array", sizeof(arrayobject), 0); if (unlikely(!__pyx_ptype_7cpython_5array_array)) __PYX_ERR(3, 58, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; @@ -20927,204 +23310,228 @@ if (!__Pyx_RefNanny) { #endif __Pyx_TraceCall("__Pyx_PyMODINIT_FUNC PyInit_libctabix(void)", __pyx_f[0], 1, 0, __PYX_ERR(0, 1, __pyx_L1_error)); - /* "pysam/libctabix.pyx":55 + /* "pysam/libctabix.pyx":56 * # * ############################################################################### + * import binascii # <<<<<<<<<<<<<< + * import os + * import sys + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_binascii, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_binascii, __pyx_t_1) < 0) __PYX_ERR(0, 56, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libctabix.pyx":57 + * ############################################################################### + * import binascii * import os # <<<<<<<<<<<<<< * import sys * */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error) + __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 55, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 57, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":56 - * ############################################################################### + /* "pysam/libctabix.pyx":58 + * import binascii * import os * import sys # <<<<<<<<<<<<<< * * from libc.stdio cimport printf, fprintf, stderr */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error) + __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 56, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 58, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":612 + /* "pysam/libctabix.pyx":687 * * * class EmptyIterator: # <<<<<<<<<<<<<< * '''empty iterator''' * */ - __pyx_t_1 = __Pyx_Py3MetaclassPrepare((PyObject *) NULL, __pyx_empty_tuple, __pyx_n_s_EmptyIterator, __pyx_n_s_EmptyIterator, (PyObject *) NULL, __pyx_n_s_pysam_libctabix, __pyx_kp_s_empty_iterator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 612, __pyx_L1_error) + __pyx_t_1 = __Pyx_Py3MetaclassPrepare((PyObject *) NULL, __pyx_empty_tuple, __pyx_n_s_EmptyIterator, __pyx_n_s_EmptyIterator, (PyObject *) NULL, __pyx_n_s_pysam_libctabix, __pyx_kp_s_empty_iterator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 687, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libctabix.pyx":615 + /* "pysam/libctabix.pyx":690 * '''empty iterator''' * * def __iter__(self): # <<<<<<<<<<<<<< * return self * */ - __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_13EmptyIterator_1__iter__, 0, __pyx_n_s_EmptyIterator___iter, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__10)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 615, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_13EmptyIterator_1__iter__, 0, __pyx_n_s_EmptyIterator___iter, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__9)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 690, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_iter, __pyx_t_2) < 0) __PYX_ERR(0, 615, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_iter, __pyx_t_2) < 0) __PYX_ERR(0, 690, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":618 + /* "pysam/libctabix.pyx":693 * return self * * def next(self): # <<<<<<<<<<<<<< * raise StopIteration() * */ - __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_13EmptyIterator_3next, 0, __pyx_n_s_EmptyIterator_next, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 618, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_13EmptyIterator_3next, 0, __pyx_n_s_EmptyIterator_next, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__10)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 693, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_next_2, __pyx_t_2) < 0) __PYX_ERR(0, 618, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_next_2, __pyx_t_2) < 0) __PYX_ERR(0, 693, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":621 + /* "pysam/libctabix.pyx":696 * raise StopIteration() * * def __next__(self): # <<<<<<<<<<<<<< * raise StopIteration() * */ - __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_13EmptyIterator_5__next__, 0, __pyx_n_s_EmptyIterator___next, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__12)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 621, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_13EmptyIterator_5__next__, 0, __pyx_n_s_EmptyIterator___next, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 696, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_next, __pyx_t_2) < 0) __PYX_ERR(0, 621, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_next, __pyx_t_2) < 0) __PYX_ERR(0, 696, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":612 + /* "pysam/libctabix.pyx":687 * * * class EmptyIterator: # <<<<<<<<<<<<<< * '''empty iterator''' * */ - __pyx_t_2 = __Pyx_Py3ClassCreate(((PyObject*)&__Pyx_DefaultClassType), __pyx_n_s_EmptyIterator, __pyx_empty_tuple, __pyx_t_1, NULL, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 612, __pyx_L1_error) + __pyx_t_2 = __Pyx_Py3ClassCreate(((PyObject*)&__Pyx_DefaultClassType), __pyx_n_s_EmptyIterator, __pyx_empty_tuple, __pyx_t_1, NULL, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 687, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_EmptyIterator, __pyx_t_2) < 0) __PYX_ERR(0, 612, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_EmptyIterator, __pyx_t_2) < 0) __PYX_ERR(0, 687, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":746 + /* "pysam/libctabix.pyx":821 * * * def tabix_compress(filename_in, # <<<<<<<<<<<<<< * filename_out, * force=False): */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_1tabix_compress, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 746, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_1tabix_compress, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 821, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_tabix_compress, __pyx_t_1) < 0) __PYX_ERR(0, 746, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_tabix_compress, __pyx_t_1) < 0) __PYX_ERR(0, 821, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":808 + /* "pysam/libctabix.pyx":883 * * - * def tabix_index( filename, # <<<<<<<<<<<<<< - * force = False, - * seq_col = None, + * def is_gzip_file(filename): # <<<<<<<<<<<<<< + * gzip_magic_hex = b'1f8b' + * fd = os.open(filename, os.O_RDONLY) */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_3tabix_index, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 808, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_3is_gzip_file, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 883, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_tabix_index, __pyx_t_1) < 0) __PYX_ERR(0, 808, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_is_gzip_file, __pyx_t_1) < 0) __PYX_ERR(0, 883, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":1078 + /* "pysam/libctabix.pyx":890 + * + * + * def tabix_index(filename, # <<<<<<<<<<<<<< + * force=False, + * seq_col=None, + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_5tabix_index, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 890, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_tabix_index, __pyx_t_1) < 0) __PYX_ERR(0, 890, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libctabix.pyx":1198 * * * class tabix_generic_iterator: # <<<<<<<<<<<<<< * '''iterate over ``infile``. * */ - __pyx_t_1 = __Pyx_Py3MetaclassPrepare((PyObject *) NULL, __pyx_empty_tuple, __pyx_n_s_tabix_generic_iterator, __pyx_n_s_tabix_generic_iterator, (PyObject *) NULL, __pyx_n_s_pysam_libctabix, __pyx_kp_s_iterate_over_infile_Permits_the); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1078, __pyx_L1_error) + __pyx_t_1 = __Pyx_Py3MetaclassPrepare((PyObject *) NULL, __pyx_empty_tuple, __pyx_n_s_tabix_generic_iterator, __pyx_n_s_tabix_generic_iterator, (PyObject *) NULL, __pyx_n_s_pysam_libctabix, __pyx_kp_s_iterate_over_infile_Permits_the); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libctabix.pyx":1083 + /* "pysam/libctabix.pyx":1203 * Permits the use of file-like objects for example from the gzip module. * ''' * def __init__(self, infile, parser): # <<<<<<<<<<<<<< * * self.infile = infile */ - __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_22tabix_generic_iterator_1__init__, 0, __pyx_n_s_tabix_generic_iterator___init, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__40)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1083, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_22tabix_generic_iterator_1__init__, 0, __pyx_n_s_tabix_generic_iterator___init, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__32)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1203, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_init, __pyx_t_2) < 0) __PYX_ERR(0, 1083, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_init, __pyx_t_2) < 0) __PYX_ERR(0, 1203, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":1090 + /* "pysam/libctabix.pyx":1210 * self.parser = parser * * def __iter__(self): # <<<<<<<<<<<<<< * return self * */ - __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_22tabix_generic_iterator_3__iter__, 0, __pyx_n_s_tabix_generic_iterator___iter, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__42)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1090, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_22tabix_generic_iterator_3__iter__, 0, __pyx_n_s_tabix_generic_iterator___iter, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__34)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1210, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_iter, __pyx_t_2) < 0) __PYX_ERR(0, 1090, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_iter, __pyx_t_2) < 0) __PYX_ERR(0, 1210, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":1094 + /* "pysam/libctabix.pyx":1214 * * # cython version - required for python 3 * def __next__(self): # <<<<<<<<<<<<<< * * cdef char * b */ - __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_22tabix_generic_iterator_5__next__, 0, __pyx_n_s_tabix_generic_iterator___next, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__43)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1094, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_22tabix_generic_iterator_5__next__, 0, __pyx_n_s_tabix_generic_iterator___next, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__35)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_next, __pyx_t_2) < 0) __PYX_ERR(0, 1094, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_next, __pyx_t_2) < 0) __PYX_ERR(0, 1214, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":1138 + /* "pysam/libctabix.pyx":1258 * * # python version - required for python 2.7 * def next(self): # <<<<<<<<<<<<<< * return self.__next__() * */ - __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_22tabix_generic_iterator_7next, 0, __pyx_n_s_tabix_generic_iterator_next, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__45)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1138, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_22tabix_generic_iterator_7next, 0, __pyx_n_s_tabix_generic_iterator_next, NULL, __pyx_n_s_pysam_libctabix, __pyx_d, ((PyObject *)__pyx_codeobj__37)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1258, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_next_2, __pyx_t_2) < 0) __PYX_ERR(0, 1138, __pyx_L1_error) + if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_next_2, __pyx_t_2) < 0) __PYX_ERR(0, 1258, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabix.pyx":1078 + /* "pysam/libctabix.pyx":1198 * * * class tabix_generic_iterator: # <<<<<<<<<<<<<< * '''iterate over ``infile``. * */ - __pyx_t_2 = __Pyx_Py3ClassCreate(((PyObject*)&__Pyx_DefaultClassType), __pyx_n_s_tabix_generic_iterator, __pyx_empty_tuple, __pyx_t_1, NULL, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1078, __pyx_L1_error) + __pyx_t_2 = __Pyx_Py3ClassCreate(((PyObject*)&__Pyx_DefaultClassType), __pyx_n_s_tabix_generic_iterator, __pyx_empty_tuple, __pyx_t_1, NULL, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_tabix_generic_iterator, __pyx_t_2) < 0) __PYX_ERR(0, 1078, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_tabix_generic_iterator, __pyx_t_2) < 0) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":1141 - * return self.__next__() + /* "pysam/libctabix.pyx":1262 + * * * def tabix_iterator(infile, parser): # <<<<<<<<<<<<<< * """return an iterator over all entries in a file. * */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_5tabix_iterator, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1141, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_7tabix_iterator, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1262, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_tabix_iterator, __pyx_t_1) < 0) __PYX_ERR(0, 1141, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_tabix_iterator, __pyx_t_1) < 0) __PYX_ERR(0, 1262, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabix.pyx":1174 + /* "pysam/libctabix.pyx":1295 * * * __all__ = [ # <<<<<<<<<<<<<< * "tabix_index", * "tabix_compress", */ - __pyx_t_1 = PyList_New(13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1174, __pyx_L1_error) + __pyx_t_1 = PyList_New(14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1295, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_tabix_index); __Pyx_GIVEREF(__pyx_n_s_tabix_index); @@ -21144,28 +23551,31 @@ if (!__Pyx_RefNanny) { __Pyx_INCREF(__pyx_n_s_asGTF); __Pyx_GIVEREF(__pyx_n_s_asGTF); PyList_SET_ITEM(__pyx_t_1, 5, __pyx_n_s_asGTF); + __Pyx_INCREF(__pyx_n_s_asGFF3); + __Pyx_GIVEREF(__pyx_n_s_asGFF3); + PyList_SET_ITEM(__pyx_t_1, 6, __pyx_n_s_asGFF3); __Pyx_INCREF(__pyx_n_s_asVCF); __Pyx_GIVEREF(__pyx_n_s_asVCF); - PyList_SET_ITEM(__pyx_t_1, 6, __pyx_n_s_asVCF); + PyList_SET_ITEM(__pyx_t_1, 7, __pyx_n_s_asVCF); __Pyx_INCREF(__pyx_n_s_asBed); __Pyx_GIVEREF(__pyx_n_s_asBed); - PyList_SET_ITEM(__pyx_t_1, 7, __pyx_n_s_asBed); + PyList_SET_ITEM(__pyx_t_1, 8, __pyx_n_s_asBed); __Pyx_INCREF(__pyx_n_s_GZIterator); __Pyx_GIVEREF(__pyx_n_s_GZIterator); - PyList_SET_ITEM(__pyx_t_1, 8, __pyx_n_s_GZIterator); + PyList_SET_ITEM(__pyx_t_1, 9, __pyx_n_s_GZIterator); __Pyx_INCREF(__pyx_n_s_GZIteratorHead); __Pyx_GIVEREF(__pyx_n_s_GZIteratorHead); - PyList_SET_ITEM(__pyx_t_1, 9, __pyx_n_s_GZIteratorHead); + PyList_SET_ITEM(__pyx_t_1, 10, __pyx_n_s_GZIteratorHead); __Pyx_INCREF(__pyx_n_s_tabix_iterator); __Pyx_GIVEREF(__pyx_n_s_tabix_iterator); - PyList_SET_ITEM(__pyx_t_1, 10, __pyx_n_s_tabix_iterator); + PyList_SET_ITEM(__pyx_t_1, 11, __pyx_n_s_tabix_iterator); __Pyx_INCREF(__pyx_n_s_tabix_generic_iterator); __Pyx_GIVEREF(__pyx_n_s_tabix_generic_iterator); - PyList_SET_ITEM(__pyx_t_1, 11, __pyx_n_s_tabix_generic_iterator); + PyList_SET_ITEM(__pyx_t_1, 12, __pyx_n_s_tabix_generic_iterator); __Pyx_INCREF(__pyx_n_s_tabix_file_iterator); __Pyx_GIVEREF(__pyx_n_s_tabix_file_iterator); - PyList_SET_ITEM(__pyx_t_1, 12, __pyx_n_s_tabix_file_iterator); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 1174, __pyx_L1_error) + PyList_SET_ITEM(__pyx_t_1, 13, __pyx_n_s_tabix_file_iterator); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 1295, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":1 @@ -21173,7 +23583,7 @@ if (!__Pyx_RefNanny) { * if __pyx_checksum != 0x84bea1f: * from pickle import PickleError as __pyx_PickleError */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_7__pyx_unpickle_Parser, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_9__pyx_unpickle_Parser, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_Parser, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -21185,39 +23595,51 @@ if (!__Pyx_RefNanny) { * __pyx_result.encoding = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_9__pyx_unpickle_asTuple, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_11__pyx_unpickle_asTuple, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_asTuple, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":1 - * def __pyx_unpickle_asGTF(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * def __pyx_unpickle_asGFF3(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x84bea1f: * from pickle import PickleError as __pyx_PickleError */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_11__pyx_unpickle_asGTF, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_13__pyx_unpickle_asGFF3, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_asGTF, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_asGFF3, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":9 - * __pyx_unpickle_asGTF__set_state( __pyx_result, __pyx_state) + * __pyx_unpickle_asGFF3__set_state( __pyx_result, __pyx_state) * return __pyx_result - * cdef __pyx_unpickle_asGTF__set_state(asGTF __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_asGFF3__set_state(asGFF3 __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< * __pyx_result.encoding = __pyx_state[0] * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_13__pyx_unpickle_asBed, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_15__pyx_unpickle_asGTF, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_asBed, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_asGTF, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "(tree fragment)":1 - * def __pyx_unpickle_asVCF(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * def __pyx_unpickle_asBed(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< * if __pyx_checksum != 0x84bea1f: * from pickle import PickleError as __pyx_PickleError */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_15__pyx_unpickle_asVCF, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_17__pyx_unpickle_asBed, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_asBed, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":9 + * __pyx_unpickle_asBed__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_asBed__set_state(asBed __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.encoding = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libctabix_19__pyx_unpickle_asVCF, NULL, __pyx_n_s_pysam_libctabix); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_asVCF, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -22580,115 +25002,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* value return PyDict_Keys(d); } -/* PyIntBinop */ - #if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_OrObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { - #if PY_MAJOR_VERSION < 3 - if (likely(PyInt_CheckExact(op1))) { - const long b = intval; - long a = PyInt_AS_LONG(op1); - return PyInt_FromLong(a | b); - } - #endif - #if CYTHON_USE_PYLONG_INTERNALS - if (likely(PyLong_CheckExact(op1))) { - const long b = intval; - long a, x; -#ifdef HAVE_LONG_LONG - const PY_LONG_LONG llb = intval; - PY_LONG_LONG lla, llx; -#endif - const digit* digits = ((PyLongObject*)op1)->ob_digit; - const Py_ssize_t size = Py_SIZE(op1); - if (likely(__Pyx_sst_abs(size) <= 1)) { - a = likely(size) ? digits[0] : 0; - if (size == -1) a = -a; - } else { - switch (size) { - case -2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { - a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { - a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case -3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { - a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { - a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case -4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { - a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { - a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - default: return PyLong_Type.tp_as_number->nb_or(op1, op2); - } - } - x = a | b; - return PyLong_FromLong(x); -#ifdef HAVE_LONG_LONG - long_long: - llx = lla | llb; - return PyLong_FromLongLong(llx); -#endif - - - } - #endif - return (inplace ? PyNumber_InPlaceOr : PyNumber_Or)(op1, op2); -} -#endif - /* UnicodeAsUCS4 */ static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) { Py_ssize_t length; @@ -24202,6 +26515,37 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } } +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int8_t(int8_t value) { + const int8_t neg_one = (int8_t) -1, const_zero = (int8_t) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(int8_t) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int8_t) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int8_t) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(int8_t) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int8_t) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(int8_t), + little, !is_unsigned); + } +} + /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { const long neg_one = (long) -1, const_zero = (long) 0; diff --git a/pysam/libctabix.pxd b/pysam/libctabix.pxd index 12cd9ddd4..c986f0399 100644 --- a/pysam/libctabix.pxd +++ b/pysam/libctabix.pxd @@ -81,6 +81,10 @@ cdef class asGTF(Parser): pass +cdef class asGFF3(Parser): + pass + + cdef class asBed(Parser): pass diff --git a/pysam/libctabix.pyx b/pysam/libctabix.pyx index 10dc23bd3..e581b617e 100644 --- a/pysam/libctabix.pyx +++ b/pysam/libctabix.pyx @@ -9,7 +9,8 @@ # class TabixFile class wrapping tabix indexed files in bgzf format # # class asTuple Parser class for tuples -# class asGT Parser class for GTF formatted rows +# class asGTF Parser class for GTF formatted rows +# class asGFF3 Parser class for GFF3 formatted rows # class asBed Parser class for Bed formatted rows # class asVCF Parser class for VCF formatted rows # @@ -52,6 +53,7 @@ # DEALINGS IN THE SOFTWARE. # ############################################################################### +import binascii import os import sys @@ -70,9 +72,11 @@ cimport pysam.libctabixproxies as ctabixproxies from pysam.libchtslib cimport htsFile, hts_open, hts_close, HTS_IDX_START,\ BGZF, bgzf_open, bgzf_dopen, bgzf_close, bgzf_write, \ - tbx_index_build, tbx_index_load, tbx_itr_queryi, tbx_itr_querys, \ + tbx_index_build2, tbx_index_load2, tbx_itr_queryi, tbx_itr_querys, \ tbx_conf_t, tbx_seqnames, tbx_itr_next, tbx_itr_destroy, \ - tbx_destroy, hisremote, region_list + tbx_destroy, hisremote, region_list, hts_getline, \ + TBX_GENERIC, TBX_SAM, TBX_VCF, TBX_UCSC, htsExactFormat, bcf, \ + bcf_index_build2 from pysam.libcutils cimport force_bytes, force_str, charptr_to_str from pysam.libcutils cimport encode_filename, from_string_and_size @@ -110,6 +114,42 @@ cdef class asTuple(Parser): return r +cdef class asGFF3(Parser): + '''converts a :term:`tabix row` into a GFF record with the following + fields: + + +----------+----------+-------------------------------+ + |*Column* |*Name* |*Content* | + +----------+----------+-------------------------------+ + |1 |contig |the chromosome name | + +----------+----------+-------------------------------+ + |2 |feature |The feature type | + +----------+----------+-------------------------------+ + |3 |source |The feature source | + +----------+----------+-------------------------------+ + |4 |start |genomic start coordinate | + | | |(0-based) | + +----------+----------+-------------------------------+ + |5 |end |genomic end coordinate | + | | |(0-based) | + +----------+----------+-------------------------------+ + |6 |score |feature score | + +----------+----------+-------------------------------+ + |7 |strand |strand | + +----------+----------+-------------------------------+ + |8 |frame |frame | + +----------+----------+-------------------------------+ + |9 |attributes|the attribute field | + +----------+----------+-------------------------------+ + + ''' + cdef parse(self, char * buffer, int len): + cdef ctabixproxies.GFF3Proxy r + r = ctabixproxies.GFF3Proxy(self.encoding) + r.copy(buffer, len) + return r + + cdef class asGTF(Parser): '''converts a :term:`tabix row` into a GTF record with the following fields: @@ -155,7 +195,7 @@ cdef class asGTF(Parser): r = ctabixproxies.GTFProxy(self.encoding) r.copy(buffer, len) return r - + cdef class asBed(Parser): '''converts a :term:`tabix row` into a bed record @@ -279,6 +319,11 @@ cdef class TabixFile: The encoding passed to the parser + threads: integer + Number of threads to use for decompressing Tabix files. + (Default=1) + + Raises ------ @@ -294,6 +339,7 @@ cdef class TabixFile: parser=None, index=None, encoding="ascii", + threads=1, *args, **kwargs ): @@ -301,13 +347,15 @@ cdef class TabixFile: self.is_remote = False self.is_stream = False self.parser = parser + self.threads = threads self._open(filename, mode, index, *args, **kwargs) self.encoding = encoding - def _open( self, + def _open( self, filename, mode='r', index=None, + threads=1, ): '''open a :term:`tabix file` for reading.''' @@ -317,6 +365,7 @@ cdef class TabixFile: if self.htsfile != NULL: self.close() self.htsfile = NULL + self.threads=threads filename_index = index or (filename + ".tbi") # encode all the strings to pass to tabix @@ -335,6 +384,7 @@ cdef class TabixFile: # open file cdef char *cfilename = self.filename + cdef char *cfilename_index = self.filename_index with nogil: self.htsfile = hts_open(cfilename, 'r') @@ -344,9 +394,8 @@ cdef class TabixFile: #if self.htsfile.format.category != region_list: # raise ValueError("file does not contain region data") - cfilename = self.filename_index with nogil: - self.index = tbx_index_load(cfilename) + self.index = tbx_index_load2(cfilename, cfilename_index) if self.index == NULL: raise IOError("could not open index for `%s`" % filename) @@ -360,7 +409,8 @@ cdef class TabixFile: The file is being re-opened. ''' return TabixFile(self.filename, - mode="r", + mode="r", + threads=self.threads, parser=self.parser, index=self.filename_index, encoding=self.encoding) @@ -434,9 +484,9 @@ cdef class TabixFile: # without region or reference - iterate from start with nogil: itr = tbx_itr_queryi(fileobj.index, - HTS_IDX_START, - 0, - 0) + HTS_IDX_START, + 0, + 0) else: s = force_bytes(region, encoding=fileobj.encoding) cstr = s @@ -490,18 +540,43 @@ cdef class TabixFile: .. note:: The header is returned as an iterator presenting lines without the newline character. - - .. note:: - The header is only available for local files. For remote - files an Attribute Error is raised. - ''' def __get__(self): - if self.is_remote: - raise AttributeError( - "the header is not available for remote files") - return GZIteratorHead(self.filename) + + cdef char *cfilename = self.filename + cdef char *cfilename_index = self.filename_index + + cdef kstring_t buffer + buffer.l = buffer.m = 0 + buffer.s = NULL + + cdef htsFile * fp = NULL + cdef int KS_SEP_LINE = 2 + cdef tbx_t * tbx = NULL + lines = [] + with nogil: + fp = hts_open(cfilename, 'r') + + if fp == NULL: + raise OSError("could not open {} for reading header".format(self.filename)) + + with nogil: + tbx = tbx_index_load2(cfilename, cfilename_index) + + if tbx == NULL: + raise OSError("could not load .tbi/.csi index of {}".format(self.filename)) + + while hts_getline(fp, KS_SEP_LINE, &buffer) >= 0: + if not buffer.l or buffer.s[0] != tbx.conf.meta_char: + break + lines.append(force_str(buffer.s, self.encoding)) + + with nogil: + hts_close(fp) + free(buffer.s) + + return lines property contigs: '''list of chromosome names''' @@ -791,63 +866,81 @@ def tabix_compress(filename_in, r = bgzf_write(fp, buffer, c) if r < 0: free(buffer) - raise OSError("writing failed") + raise IOError("writing failed") free(buffer) r = bgzf_close(fp) if r < 0: - raise OSError("error %i when writing to file %s" % (r, filename_out)) + raise IOError("error %i when writing to file %s" % (r, filename_out)) r = close(fd_src) # an empty file will return with -1, thus ignore this. if r < 0: if not (r == -1 and is_empty): - raise OSError("error %i when closing file %s" % (r, filename_in)) - - -def tabix_index( filename, - force = False, - seq_col = None, - start_col = None, - end_col = None, - preset = None, - meta_char = "#", - zerobased = False, - int min_shift = -1, + raise IOError("error %i when closing file %s" % (r, filename_in)) + + +def is_gzip_file(filename): + gzip_magic_hex = b'1f8b' + fd = os.open(filename, os.O_RDONLY) + header = os.read(fd, 2) + return header == binascii.a2b_hex(gzip_magic_hex) + + +def tabix_index(filename, + force=False, + seq_col=None, + start_col=None, + end_col=None, + preset=None, + meta_char="#", + int line_skip=0, + zerobased=False, + int min_shift=-1, + index=None, + keep_original=False, + csi=False, ): '''index tab-separated *filename* using tabix. - An existing index will not be overwritten unless - *force* is set. - - The index will be built from coordinates - in columns *seq_col*, *start_col* and *end_col*. + An existing index will not be overwritten unless *force* is set. - The contents of *filename* have to be sorted by - contig and position - the method does not check - if the file is sorted. + The index will be built from coordinates in columns *seq_col*, + *start_col* and *end_col*. - Column indices are 0-based. Coordinates in the file - are assumed to be 1-based. + The contents of *filename* have to be sorted by contig and + position - the method does not check if the file is sorted. - If *preset* is provided, the column coordinates - are taken from a preset. Valid values for preset - are "gff", "bed", "sam", "vcf", psltbl", "pileup". + Column indices are 0-based. Note that this is different from the + tabix command line utility where column indices start at 1. - Lines beginning with *meta_char* and the first - *line_skip* lines will be skipped. + Coordinates in the file are assumed to be 1-based unless + *zerobased* is set. + + If *preset* is provided, the column coordinates are taken from a + preset. Valid values for preset are "gff", "bed", "sam", "vcf", + psltbl", "pileup". - If *filename* does not end in ".gz", it will be automatically - compressed. The original file will be removed and only the - compressed file will be retained. + Lines beginning with *meta_char* and the first *line_skip* lines + will be skipped. - If *filename* ends in *gz*, the file is assumed to be already - compressed with bgzf. + If *filename* is not detected as a gzip file it will be automatically + compressed. The original file will be removed and only the compressed + file will be retained. *min-shift* sets the minimal interval size to 1< #include "pythread.h" #include -#include "pysam_util.h" #ifdef _OPENMP #include #endif /* _OPENMP */ @@ -785,10 +784,17 @@ struct arrayobject; typedef struct arrayobject arrayobject; #endif struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy; -struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy; struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy; +struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy; +struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy; struct __pyx_obj_5pysam_16libctabixproxies_BedProxy; struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy; +struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator; +struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator; +struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr; +struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py; +struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py; +struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py; struct __pyx_opt_args_5pysam_9libcutils_parse_region; struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array; struct __pyx_opt_args_5pysam_9libcutils_array_to_qualitystring; @@ -944,35 +950,46 @@ struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy { }; -/* "pysam/libctabixproxies.pxd":28 - * cdef update(self, char * buffer, size_t nbytes) +/* "pysam/libctabixproxies.pxd":29 * - * cdef class GTFProxy(TupleProxy) : # <<<<<<<<<<<<<< * - * cdef: + * cdef class NamedTupleProxy(TupleProxy): # <<<<<<<<<<<<<< + * pass + * */ -struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy { +struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy { struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy __pyx_base; - char *_attributes; - int hasOwnAttributes; }; -/* "pysam/libctabixproxies.pxd":38 - * cdef char * getAttributes(self) +/* "pysam/libctabixproxies.pxd":33 * - * cdef class NamedTupleProxy(TupleProxy): # <<<<<<<<<<<<<< - * pass * + * cdef class GTFProxy(NamedTupleProxy): # <<<<<<<<<<<<<< + * cdef object attribute_dict + * cpdef int getMaxFields(self) */ -struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy { - struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy __pyx_base; +struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy { + struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy __pyx_base; + PyObject *attribute_dict; }; -/* "pysam/libctabixproxies.pxd":41 +/* "pysam/libctabixproxies.pxd":39 + * + * + * cdef class GFF3Proxy(GTFProxy): # <<<<<<<<<<<<<< * pass * + */ +struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy { + struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy __pyx_base; +}; + + +/* "pysam/libctabixproxies.pxd":43 + * + * * cdef class BedProxy(NamedTupleProxy): # <<<<<<<<<<<<<< * * cdef: @@ -986,7 +1003,7 @@ struct __pyx_obj_5pysam_16libctabixproxies_BedProxy { }; -/* "pysam/libctabixproxies.pxd":53 +/* "pysam/libctabixproxies.pxd":55 * cdef update(self, char * buffer, size_t nbytes) * * cdef class VCFProxy(NamedTupleProxy) : # <<<<<<<<<<<<<< @@ -1000,8 +1017,92 @@ struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy { }; +/* "pysam/libctabixproxies.pyx":563 + * return self.separator.join(aa) + ";" + * + * def attribute_string2iterator(self, s): # <<<<<<<<<<<<<< + * """convert attribute string in GTF format to records + * and iterate over key, value pairs. + */ +struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator { + PyObject_HEAD + PyObject *__pyx_v_attributes; + PyObject *__pyx_v_d; + PyObject *__pyx_v_f; + PyObject *__pyx_v_fields; + PyObject *__pyx_v_n; + PyObject *__pyx_v_s; + struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self; + PyObject *__pyx_v_v; + PyObject *__pyx_v_x; + PyObject *__pyx_t_0; + Py_ssize_t __pyx_t_1; +}; + + +/* "pysam/libctabixproxies.pyx":676 + * return ";".join(["{}={}".format(k, v) for k, v in d.items()]) + * + * def attribute_string2iterator(self, s): # <<<<<<<<<<<<<< + * """convert attribute string in GFF3 format to records + * and iterate over key, value pairs. + */ +struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator { + PyObject_HEAD + PyObject *__pyx_v_f; + PyObject *__pyx_v_genexpr; + PyObject *__pyx_v_key; + PyObject *__pyx_v_s; + struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *__pyx_v_self; + PyObject *__pyx_v_value; + PyObject *__pyx_t_0; + Py_ssize_t __pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); +}; + + +/* "pysam/libctabixproxies.pyx":681 + * """ + * + * for f in (x.strip() for x in s.split(";")): # <<<<<<<<<<<<<< + * if not f: + * continue + */ +struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr { + PyObject_HEAD + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *__pyx_outer_scope; + PyObject *__pyx_v_x; + PyObject *__pyx_t_0; + Py_ssize_t __pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); +}; + + +/* "cfunc.to_py":64 + * + * @cname("__Pyx_CFunc_object____object___to_py") + * cdef object __Pyx_CFunc_object____object___to_py(object (*f)(object) ): # <<<<<<<<<<<<<< + * def wrap(object v): + * """wrap(v)""" + */ +struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py { + PyObject_HEAD + PyObject *(*__pyx_v_f)(PyObject *); +}; + +struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py { + PyObject_HEAD + int (*__pyx_v_f)(PyObject *); +}; + +struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py { + PyObject_HEAD + PyObject *(*__pyx_v_f)(int); +}; + + -/* "pysam/libctabixproxies.pyx":27 +/* "pysam/libctabixproxies.pyx":31 * * * cdef class TupleProxy: # <<<<<<<<<<<<<< @@ -1020,36 +1121,49 @@ struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy { static struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *__pyx_vtabptr_5pysam_16libctabixproxies_TupleProxy; -/* "pysam/libctabixproxies.pyx":353 +/* "pysam/libctabixproxies.pyx":357 + * + * + * cdef class NamedTupleProxy(TupleProxy): # <<<<<<<<<<<<<< + * + * map_key2field = {} + */ + +struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy { + struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy __pyx_base; +}; +static struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy; + + +/* "pysam/libctabixproxies.pyx":412 * * - * cdef class GTFProxy(TupleProxy): # <<<<<<<<<<<<<< + * cdef class GTFProxy(NamedTupleProxy): # <<<<<<<<<<<<<< * '''Proxy class for access to GTF fields. * */ struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy { - struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy __pyx_base; - char *(*getAttributes)(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *); + struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy __pyx_base; }; static struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy *__pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy; -/* "pysam/libctabixproxies.pyx":680 +/* "pysam/libctabixproxies.pyx":670 * * - * cdef class NamedTupleProxy(TupleProxy): # <<<<<<<<<<<<<< + * cdef class GFF3Proxy(GTFProxy): # <<<<<<<<<<<<<< * - * map_key2field = {} + * def dict2attribute_string(self, d): */ -struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy { - struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy __pyx_base; +struct __pyx_vtabstruct_5pysam_16libctabixproxies_GFF3Proxy { + struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy __pyx_base; }; -static struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy; +static struct __pyx_vtabstruct_5pysam_16libctabixproxies_GFF3Proxy *__pyx_vtabptr_5pysam_16libctabixproxies_GFF3Proxy; -/* "pysam/libctabixproxies.pyx":703 +/* "pysam/libctabixproxies.pyx":700 * * * cdef class BedProxy(NamedTupleProxy): # <<<<<<<<<<<<<< @@ -1063,8 +1177,8 @@ struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy { static struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy *__pyx_vtabptr_5pysam_16libctabixproxies_BedProxy; -/* "pysam/libctabixproxies.pyx":776 - * TupleProxy._setindex(self, idx, str(value) ) +/* "pysam/libctabixproxies.pyx":774 + * * * cdef class VCFProxy(NamedTupleProxy): # <<<<<<<<<<<<<< * '''Proxy class for access to VCF fields. @@ -1317,41 +1431,6 @@ static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values); #endif -/* KeywordStringCheck.proto */ -static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); - -/* PyIntBinop.proto */ -#if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace); -#else -#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace)\ - (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2)) -#endif - -/* PyIntBinop.proto */ -#if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace); -#else -#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\ - (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) -#endif - -/* IncludeStringH.proto */ -#include - -/* BytesEquals.proto */ -static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); - -/* UnicodeEquals.proto */ -static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); - -/* StrEquals.proto */ -#if PY_MAJOR_VERSION >= 3 -#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals -#else -#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals -#endif - /* GetItemInt.proto */ #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ @@ -1374,39 +1453,27 @@ static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, int wraparound, int boundscheck); -/* ListCompAppend.proto */ -#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS -static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) { - PyListObject* L = (PyListObject*) list; - Py_ssize_t len = Py_SIZE(list); - if (likely(L->allocated > len)) { - Py_INCREF(x); - PyList_SET_ITEM(list, len, x); - Py_SIZE(list) = len+1; - return 0; - } - return PyList_Append(list, x); -} +/* ObjectGetItem.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key); #else -#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x) +#define __Pyx_PyObject_GetItem(obj, key) PyObject_GetItem(obj, key) #endif -/* GetModuleGlobalName.proto */ -static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); +/* IncludeStringH.proto */ +#include -/* SliceObject.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice( - PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, - PyObject** py_start, PyObject** py_stop, PyObject** py_slice, - int has_cstart, int has_cstop, int wraparound); +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); -/* SliceTupleAndList.proto */ -#if CYTHON_COMPILING_IN_CPYTHON -static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop); -static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop); +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* StrEquals.proto */ +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals #else -#define __Pyx_PyList_GetSlice(seq, start, stop) PySequence_GetSlice(seq, start, stop) -#define __Pyx_PyTuple_GetSlice(seq, start, stop) PySequence_GetSlice(seq, start, stop) +#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals #endif /* SaveResetException.proto */ @@ -1428,6 +1495,28 @@ static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tsta #define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) #endif +/* GetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb) +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* KeywordStringCheck.proto */ +static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); + +/* GetModuleGlobalName.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); + +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace); +#else +#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\ + (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) +#endif + /* PyObjectSetAttrStr.proto */ #if CYTHON_USE_TYPE_SLOTS #define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL) @@ -1437,13 +1526,97 @@ static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr #define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v) #endif -/* ObjectGetItem.proto */ -#if CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key); +/* ListCompAppend.proto */ +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) { + PyListObject* L = (PyListObject*) list; + Py_ssize_t len = Py_SIZE(list); + if (likely(L->allocated > len)) { + Py_INCREF(x); + PyList_SET_ITEM(list, len, x); + Py_SIZE(list) = len+1; + return 0; + } + return PyList_Append(list, x); +} #else -#define __Pyx_PyObject_GetItem(obj, key) PyObject_GetItem(obj, key) +#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x) +#endif + +/* SliceObject.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice( + PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, + PyObject** py_start, PyObject** py_stop, PyObject** py_slice, + int has_cstart, int has_cstop, int wraparound); + +/* SliceTupleAndList.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop); +static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop); +#else +#define __Pyx_PyList_GetSlice(seq, start, stop) PySequence_GetSlice(seq, start, stop) +#define __Pyx_PyTuple_GetSlice(seq, start, stop) PySequence_GetSlice(seq, start, stop) #endif +/* None.proto */ +static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname); + +/* FetchCommonType.proto */ +static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type); + +/* CythonFunction.proto */ +#define __Pyx_CyFunction_USED 1 +#define __Pyx_CYFUNCTION_STATICMETHOD 0x01 +#define __Pyx_CYFUNCTION_CLASSMETHOD 0x02 +#define __Pyx_CYFUNCTION_CCLASS 0x04 +#define __Pyx_CyFunction_GetClosure(f)\ + (((__pyx_CyFunctionObject *) (f))->func_closure) +#define __Pyx_CyFunction_GetClassObj(f)\ + (((__pyx_CyFunctionObject *) (f))->func_classobj) +#define __Pyx_CyFunction_Defaults(type, f)\ + ((type *)(((__pyx_CyFunctionObject *) (f))->defaults)) +#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\ + ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g) +typedef struct { + PyCFunctionObject func; +#if PY_VERSION_HEX < 0x030500A0 + PyObject *func_weakreflist; +#endif + PyObject *func_dict; + PyObject *func_name; + PyObject *func_qualname; + PyObject *func_doc; + PyObject *func_globals; + PyObject *func_code; + PyObject *func_closure; + PyObject *func_classobj; + void *defaults; + int defaults_pyobjects; + int flags; + PyObject *defaults_tuple; + PyObject *defaults_kwdict; + PyObject *(*defaults_getter)(PyObject *); + PyObject *func_annotations; +} __pyx_CyFunctionObject; +static PyTypeObject *__pyx_CyFunctionType = 0; +#define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code)\ + __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, qualname, self, module, globals, code) +static PyObject *__Pyx_CyFunction_New(PyTypeObject *, PyMethodDef *ml, + int flags, PyObject* qualname, + PyObject *self, + PyObject *module, PyObject *globals, + PyObject* code); +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m, + size_t size, + int pyobjects); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m, + PyObject *tuple); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m, + PyObject *dict); +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m, + PyObject *dict); +static int __pyx_CyFunction_init(void); + /* PyObject_GenericGetAttrNoDict.proto */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); @@ -1639,6 +1812,76 @@ static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObj #endif #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) +/* SwapException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* CoroutineBase.proto */ +typedef PyObject *(*__pyx_coroutine_body_t)(PyObject *, PyThreadState *, PyObject *); +typedef struct { + PyObject_HEAD + __pyx_coroutine_body_t body; + PyObject *closure; + PyObject *exc_type; + PyObject *exc_value; + PyObject *exc_traceback; + PyObject *gi_weakreflist; + PyObject *classobj; + PyObject *yieldfrom; + PyObject *gi_name; + PyObject *gi_qualname; + PyObject *gi_modulename; + PyObject *gi_code; + int resume_label; + char is_running; +} __pyx_CoroutineObject; +static __pyx_CoroutineObject *__Pyx__Coroutine_New( + PyTypeObject *type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, + PyObject *name, PyObject *qualname, PyObject *module_name); +static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit( + __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, + PyObject *name, PyObject *qualname, PyObject *module_name); +static int __Pyx_Coroutine_clear(PyObject *self); +static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value); +static PyObject *__Pyx_Coroutine_Close(PyObject *self); +static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args); +#define __Pyx_Coroutine_SwapException(self) {\ + __Pyx_ExceptionSwap(&(self)->exc_type, &(self)->exc_value, &(self)->exc_traceback);\ + __Pyx_Coroutine_ResetFrameBackpointer(self);\ + } +#define __Pyx_Coroutine_ResetAndClearException(self) {\ + __Pyx_ExceptionReset((self)->exc_type, (self)->exc_value, (self)->exc_traceback);\ + (self)->exc_type = (self)->exc_value = (self)->exc_traceback = NULL;\ + } +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\ + __Pyx_PyGen__FetchStopIterationValue(__pyx_tstate, pvalue) +#else +#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\ + __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, pvalue) +#endif +static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *tstate, PyObject **pvalue); +static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__pyx_CoroutineObject *self); + +/* PatchModuleWithCoroutine.proto */ +static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code); + +/* PatchGeneratorABC.proto */ +static int __Pyx_patch_abc(void); + +/* Generator.proto */ +#define __Pyx_Generator_USED +static PyTypeObject *__pyx_GeneratorType = 0; +#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType) +#define __Pyx_Generator_New(body, code, closure, name, qualname, module_name)\ + __Pyx__Coroutine_New(__pyx_GeneratorType, body, code, closure, name, qualname, module_name) +static PyObject *__Pyx_Generator_Next(PyObject *self); +static int __pyx_Generator_init(void); + /* CheckBinaryVersion.proto */ static int __Pyx_check_binary_version(void); @@ -1671,7 +1914,6 @@ static int __pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMaxFields(CYTHON_UN static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *__pyx_v_self, char *__pyx_v_buffer, size_t __pyx_v_nbytes); /* proto*/ static int __pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMinFields(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ static int __pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMaxFields(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ -static char *__pyx_f_5pysam_16libctabixproxies_8GTFProxy_getAttributes(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto*/ static int __pyx_f_5pysam_16libctabixproxies_8BedProxy_getMinFields(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ static int __pyx_f_5pysam_16libctabixproxies_8BedProxy_getMaxFields(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ static PyObject *__pyx_f_5pysam_16libctabixproxies_8BedProxy_update(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, char *__pyx_v_buffer, size_t __pyx_v_nbytes); /* proto*/ @@ -1781,12 +2023,27 @@ static PyObject *(*__pyx_f_5pysam_9libcutils_from_string_and_size)(char const *, /* Module declarations from 'pysam.libctabixproxies' */ static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_TupleProxy = 0; -static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_GTFProxy = 0; static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy = 0; +static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_GTFProxy = 0; +static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_GFF3Proxy = 0; static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_BedProxy = 0; static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_VCFProxy = 0; +static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator = 0; +static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator = 0; +static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr = 0; +static PyTypeObject *__pyx_ptype___pyx_scope_struct____Pyx_CFunc_object____object___to_py = 0; +static PyTypeObject *__pyx_ptype___pyx_scope_struct____Pyx_CFunc_int____object___to_py = 0; +static PyTypeObject *__pyx_ptype___pyx_scope_struct____Pyx_CFunc_str____int___to_py = 0; static char *__pyx_f_5pysam_16libctabixproxies_StrOrEmpty(char *); /*proto*/ static int __pyx_f_5pysam_16libctabixproxies_isNew(char *, char *, size_t); /*proto*/ +static PyObject *__pyx_f_5pysam_16libctabixproxies_dot_or_float(PyObject *); /*proto*/ +static PyObject *__pyx_f_5pysam_16libctabixproxies_dot_or_int(PyObject *); /*proto*/ +static PyObject *__pyx_f_5pysam_16libctabixproxies_dot_or_str(PyObject *); /*proto*/ +static int __pyx_f_5pysam_16libctabixproxies_from1based(PyObject *); /*proto*/ +static PyObject *__pyx_f_5pysam_16libctabixproxies_to1based(int); /*proto*/ +static PyObject *__Pyx_CFunc_object____object___to_py(PyObject *(*)(PyObject *)); /*proto*/ +static PyObject *__Pyx_CFunc_int____object___to_py(int (*)(PyObject *)); /*proto*/ +static PyObject *__Pyx_CFunc_str____int___to_py(PyObject *(*)(int)); /*proto*/ #define __Pyx_MODULE_NAME "pysam.libctabixproxies" extern int __pyx_module_is_main_pysam__libctabixproxies; int __pyx_module_is_main_pysam__libctabixproxies = 0; @@ -1800,46 +2057,55 @@ static PyObject *__pyx_builtin_StopIteration; static PyObject *__pyx_builtin_xrange; static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_KeyError; -static PyObject *__pyx_builtin_AttributeError; static PyObject *__pyx_builtin_MemoryError; static const char __pyx_k_s[] = "\"%s\""; static const char __pyx_k_v[] = "v"; static const char __pyx_k__9[] = "\t"; static const char __pyx_k_id[] = "id"; static const char __pyx_k__13[] = "."; -static const char __pyx_k__20[] = ""; -static const char __pyx_k__25[] = "; "; -static const char __pyx_k__27[] = ";"; -static const char __pyx_k__30[] = " "; -static const char __pyx_k__32[] = "\""; -static const char __pyx_k__35[] = "-"; +static const char __pyx_k__16[] = ""; +static const char __pyx_k__17[] = "-"; +static const char __pyx_k__18[] = "{} \"{}\""; +static const char __pyx_k__19[] = "{} {}"; +static const char __pyx_k__20[] = ";"; +static const char __pyx_k__21[] = "; "; +static const char __pyx_k__25[] = " "; +static const char __pyx_k__27[] = "\""; +static const char __pyx_k__33[] = "{}={}"; +static const char __pyx_k__35[] = "="; +static const char __pyx_k_all[] = "__all__"; static const char __pyx_k_alt[] = "alt"; static const char __pyx_k_end[] = "end"; +static const char __pyx_k_get[] = "get"; static const char __pyx_k_pos[] = "pos"; static const char __pyx_k_ref[] = "ref"; -static const char __pyx_k_s_s[] = "%s \"%s\""; static const char __pyx_k_str[] = "__str__"; +static const char __pyx_k_args[] = "args"; +static const char __pyx_k_copy[] = "copy"; static const char __pyx_k_info[] = "info"; static const char __pyx_k_join[] = "join"; +static const char __pyx_k_keys[] = "keys"; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_name[] = "name"; static const char __pyx_k_qual[] = "qual"; +static const char __pyx_k_send[] = "send"; static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_wrap[] = "wrap"; static const char __pyx_k_ascii[] = "ascii"; +static const char __pyx_k_close[] = "close"; static const char __pyx_k_frame[] = "frame"; static const char __pyx_k_index[] = "index"; static const char __pyx_k_items[] = "items"; static const char __pyx_k_quote[] = "quote"; static const char __pyx_k_range[] = "range"; -static const char __pyx_k_s_s_2[] = "%s %s"; static const char __pyx_k_score[] = "score"; static const char __pyx_k_split[] = "split"; static const char __pyx_k_start[] = "start"; static const char __pyx_k_strip[] = "strip"; +static const char __pyx_k_throw[] = "throw"; static const char __pyx_k_toDot[] = "toDot"; static const char __pyx_k_value[] = "value"; static const char __pyx_k_append[] = "append"; -static const char __pyx_k_asDict[] = "asDict"; static const char __pyx_k_contig[] = "contig"; static const char __pyx_k_decode[] = "decode"; static const char __pyx_k_filter[] = "filter"; @@ -1852,22 +2118,30 @@ static const char __pyx_k_strand[] = "strand"; static const char __pyx_k_xrange[] = "xrange"; static const char __pyx_k_compare[] = "compare"; static const char __pyx_k_feature[] = "feature"; +static const char __pyx_k_genexpr[] = "genexpr"; static const char __pyx_k_getattr[] = "__getattr__"; static const char __pyx_k_indices[] = "indices"; static const char __pyx_k_itemRGB[] = "itemRGB"; static const char __pyx_k_setitem[] = "__setitem__"; +static const char __pyx_k_to_dict[] = "to_dict"; +static const char __pyx_k_BedProxy[] = "BedProxy"; +static const char __pyx_k_GTFProxy[] = "GTFProxy"; static const char __pyx_k_KeyError[] = "KeyError"; +static const char __pyx_k_VCFProxy[] = "VCFProxy"; static const char __pyx_k_encoding[] = "encoding"; static const char __pyx_k_endswith[] = "endswith"; -static const char __pyx_k_fromDict[] = "fromDict"; static const char __pyx_k_getindex[] = "_getindex"; static const char __pyx_k_getstate[] = "__getstate__"; static const char __pyx_k_setindex[] = "_setindex"; static const char __pyx_k_setstate[] = "__setstate__"; static const char __pyx_k_thickEnd[] = "thickEnd"; +static const char __pyx_k_GFF3Proxy[] = "GFF3Proxy"; static const char __pyx_k_TypeError[] = "TypeError"; +static const char __pyx_k_from_dict[] = "from_dict"; static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_separator[] = "separator"; static const char __pyx_k_IndexError[] = "IndexError"; +static const char __pyx_k_TupleProxy[] = "TupleProxy"; static const char __pyx_k_ValueError[] = "ValueError"; static const char __pyx_k_attributes[] = "attributes"; static const char __pyx_k_blockCount[] = "blockCount"; @@ -1877,27 +2151,36 @@ static const char __pyx_k_thickStart[] = "thickStart"; static const char __pyx_k_MemoryError[] = "MemoryError"; static const char __pyx_k_OrderedDict[] = "OrderedDict"; static const char __pyx_k_blockStarts[] = "blockStarts"; +static const char __pyx_k_cfunc_to_py[] = "cfunc.to_py"; static const char __pyx_k_collections[] = "collections"; static const char __pyx_k_getMaxFields[] = "getMaxFields"; static const char __pyx_k_getMinFields[] = "getMinFields"; +static const char __pyx_k_stringsource[] = "stringsource"; static const char __pyx_k_StopIteration[] = "StopIteration"; static const char __pyx_k_map_key2field[] = "map_key2field"; static const char __pyx_k_out_of_memory[] = "out of memory"; static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; -static const char __pyx_k_AttributeError[] = "AttributeError"; +static const char __pyx_k_NamedTupleProxy[] = "NamedTupleProxy"; static const char __pyx_k_field_s_not_set[] = "field %s not set"; static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_NotImplementedError[] = "NotImplementedError"; static const char __pyx_k_incomplete_line_at_s[] = "incomplete line at %s"; +static const char __pyx_k_attribute_dict2string[] = "attribute_dict2string"; +static const char __pyx_k_attribute_string2dict[] = "attribute_string2dict"; +static const char __pyx_k_dict2attribute_string[] = "dict2attribute_string"; static const char __pyx_k_pysam_libctabixproxies[] = "pysam.libctabixproxies"; static const char __pyx_k_list_index_out_of_range[] = "list index out of range"; +static const char __pyx_k_attribute_string2iterator[] = "attribute_string2iterator"; static const char __pyx_k_op_0_isn_t_implemented_yet[] = "op {0} isn't implemented yet"; static const char __pyx_k_pysam_libctabixproxies_pyx[] = "pysam/libctabixproxies.pyx"; -static const char __pyx_k_GTFProxy_has_no_attribute_s[] = "'GTFProxy' has no attribute '%s'"; static const char __pyx_k_list_index_out_of_range_i_i[] = "list index out of range %i >= %i"; -static const char __pyx_k_key_s_not_found_no_attributes[] = "key %s not found, no attributes"; -static const char __pyx_k_no_attributes_defined_GTF_entry[] = "no attributes defined GTF entry"; +static const char __pyx_k_Pyx_CFunc_int____object___to_p[] = "__Pyx_CFunc_int____object___to_py..wrap"; +static const char __pyx_k_Pyx_CFunc_object____object___t[] = "__Pyx_CFunc_object____object___to_py..wrap"; +static const char __pyx_k_Pyx_CFunc_str____int___to_py_l[] = "__Pyx_CFunc_str____int___to_py..wrap"; +static const char __pyx_k_GFF3Proxy_attribute_string2itera[] = "GFF3Proxy.attribute_string2iterator"; +static const char __pyx_k_GTFProxy_attribute_string2iterat[] = "GTFProxy.attribute_string2iterator"; +static const char __pyx_k_attribute_string2iterator_locals[] = "attribute_string2iterator..genexpr"; static const char __pyx_k_bed_format_requires_at_least_thr[] = "bed format requires at least three columns"; static const char __pyx_k_comparison_of_modified_TupleProx[] = "comparison of modified TupleProxies is not implemented"; static const char __pyx_k_copying_modified_tuples_is_not_i[] = "copying modified tuples is not implemented"; @@ -1905,42 +2188,65 @@ static const char __pyx_k_length_of_buffer_i_number_of_byt[] = "length of buffer static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__"; static const char __pyx_k_out_of_memory_in_TupleProxy_copy[] = "out of memory in TupleProxy.copy()"; static const char __pyx_k_out_of_memory_in_TupleProxy_upda[] = "out of memory in TupleProxy.update()"; -static const char __pyx_k_parsing_error_fewer_that_i_field[] = "parsing error: fewer that %i fields in line: %s"; +static const char __pyx_k_parsing_error_fewer_than_i_field[] = "parsing error: fewer than %i fields in line: %s"; static const char __pyx_k_parsing_error_more_than_i_fields[] = "parsing error: more than %i fields in line: %s"; -static PyObject *__pyx_n_s_AttributeError; -static PyObject *__pyx_kp_s_GTFProxy_has_no_attribute_s; +static PyObject *__pyx_n_s_BedProxy; +static PyObject *__pyx_n_s_GFF3Proxy; +static PyObject *__pyx_n_s_GFF3Proxy_attribute_string2itera; +static PyObject *__pyx_n_s_GTFProxy; +static PyObject *__pyx_n_s_GTFProxy_attribute_string2iterat; static PyObject *__pyx_n_s_IndexError; static PyObject *__pyx_n_s_KeyError; static PyObject *__pyx_n_s_MemoryError; +static PyObject *__pyx_n_s_NamedTupleProxy; static PyObject *__pyx_n_s_NotImplementedError; static PyObject *__pyx_n_s_OrderedDict; +static PyObject *__pyx_n_s_Pyx_CFunc_int____object___to_p; +static PyObject *__pyx_n_s_Pyx_CFunc_object____object___t; +static PyObject *__pyx_n_s_Pyx_CFunc_str____int___to_py_l; static PyObject *__pyx_n_s_StopIteration; +static PyObject *__pyx_n_s_TupleProxy; static PyObject *__pyx_n_s_TypeError; +static PyObject *__pyx_n_s_VCFProxy; static PyObject *__pyx_n_s_ValueError; +static PyObject *__pyx_kp_b__13; static PyObject *__pyx_kp_s__13; +static PyObject *__pyx_kp_s__16; +static PyObject *__pyx_kp_s__17; +static PyObject *__pyx_kp_s__18; +static PyObject *__pyx_kp_s__19; static PyObject *__pyx_kp_s__20; +static PyObject *__pyx_kp_s__21; static PyObject *__pyx_kp_s__25; static PyObject *__pyx_kp_s__27; -static PyObject *__pyx_kp_s__30; -static PyObject *__pyx_kp_s__32; +static PyObject *__pyx_kp_s__33; static PyObject *__pyx_kp_s__35; static PyObject *__pyx_kp_s__9; +static PyObject *__pyx_n_s_all; static PyObject *__pyx_n_s_alt; static PyObject *__pyx_n_s_append; -static PyObject *__pyx_n_s_asDict; +static PyObject *__pyx_n_s_args; static PyObject *__pyx_n_s_ascii; +static PyObject *__pyx_n_s_attribute_dict2string; +static PyObject *__pyx_n_s_attribute_string2dict; +static PyObject *__pyx_n_s_attribute_string2iterator; +static PyObject *__pyx_n_s_attribute_string2iterator_locals; static PyObject *__pyx_n_s_attributes; static PyObject *__pyx_kp_s_bed_format_requires_at_least_thr; static PyObject *__pyx_n_s_blockCount; static PyObject *__pyx_n_s_blockSizes; static PyObject *__pyx_n_s_blockStarts; +static PyObject *__pyx_n_s_cfunc_to_py; static PyObject *__pyx_n_s_cline_in_traceback; +static PyObject *__pyx_n_s_close; static PyObject *__pyx_n_s_collections; static PyObject *__pyx_n_s_compare; static PyObject *__pyx_kp_s_comparison_of_modified_TupleProx; static PyObject *__pyx_n_s_contig; +static PyObject *__pyx_n_s_copy; static PyObject *__pyx_kp_s_copying_modified_tuples_is_not_i; static PyObject *__pyx_n_s_decode; +static PyObject *__pyx_n_s_dict2attribute_string; static PyObject *__pyx_n_s_encoding; static PyObject *__pyx_n_s_end; static PyObject *__pyx_n_s_endswith; @@ -1949,7 +2255,9 @@ static PyObject *__pyx_kp_s_field_s_not_set; static PyObject *__pyx_n_s_filter; static PyObject *__pyx_n_s_format; static PyObject *__pyx_n_s_frame; -static PyObject *__pyx_n_s_fromDict; +static PyObject *__pyx_n_s_from_dict; +static PyObject *__pyx_n_s_genexpr; +static PyObject *__pyx_n_s_get; static PyObject *__pyx_n_s_getMaxFields; static PyObject *__pyx_n_s_getMinFields; static PyObject *__pyx_n_s_getattr; @@ -1964,7 +2272,7 @@ static PyObject *__pyx_n_s_info; static PyObject *__pyx_n_s_itemRGB; static PyObject *__pyx_n_s_items; static PyObject *__pyx_n_s_join; -static PyObject *__pyx_kp_s_key_s_not_found_no_attributes; +static PyObject *__pyx_n_s_keys; static PyObject *__pyx_kp_s_length_of_buffer_i_number_of_byt; static PyObject *__pyx_kp_s_list_index_out_of_range; static PyObject *__pyx_kp_s_list_index_out_of_range_i_i; @@ -1972,13 +2280,12 @@ static PyObject *__pyx_n_s_main; static PyObject *__pyx_n_s_map_key2field; static PyObject *__pyx_n_s_name; static PyObject *__pyx_n_s_name_2; -static PyObject *__pyx_kp_s_no_attributes_defined_GTF_entry; static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; static PyObject *__pyx_kp_s_op_0_isn_t_implemented_yet; static PyObject *__pyx_kp_s_out_of_memory; static PyObject *__pyx_kp_s_out_of_memory_in_TupleProxy_copy; static PyObject *__pyx_kp_s_out_of_memory_in_TupleProxy_upda; -static PyObject *__pyx_kp_s_parsing_error_fewer_that_i_field; +static PyObject *__pyx_kp_s_parsing_error_fewer_than_i_field; static PyObject *__pyx_kp_s_parsing_error_more_than_i_fields; static PyObject *__pyx_n_s_pos; static PyObject *__pyx_n_s_pysam_libctabixproxies; @@ -1992,9 +2299,9 @@ static PyObject *__pyx_n_s_reduce_cython; static PyObject *__pyx_n_s_reduce_ex; static PyObject *__pyx_n_s_ref; static PyObject *__pyx_kp_s_s; -static PyObject *__pyx_kp_s_s_s; -static PyObject *__pyx_kp_s_s_s_2; static PyObject *__pyx_n_s_score; +static PyObject *__pyx_n_s_send; +static PyObject *__pyx_n_s_separator; static PyObject *__pyx_n_s_setindex; static PyObject *__pyx_n_s_setitem; static PyObject *__pyx_n_s_setstate; @@ -2004,13 +2311,17 @@ static PyObject *__pyx_n_s_split; static PyObject *__pyx_n_s_start; static PyObject *__pyx_n_s_str; static PyObject *__pyx_n_s_strand; +static PyObject *__pyx_kp_s_stringsource; static PyObject *__pyx_n_s_strip; static PyObject *__pyx_n_s_test; static PyObject *__pyx_n_s_thickEnd; static PyObject *__pyx_n_s_thickStart; +static PyObject *__pyx_n_s_throw; static PyObject *__pyx_n_s_toDot; +static PyObject *__pyx_n_s_to_dict; static PyObject *__pyx_n_s_v; static PyObject *__pyx_n_s_value; +static PyObject *__pyx_n_s_wrap; static PyObject *__pyx_n_s_xrange; static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy___cinit__(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *__pyx_v_self, PyObject *__pyx_v_encoding); /* proto */ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *__pyx_v_self); /* proto */ @@ -2031,46 +2342,39 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_30__reduce_cyth static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_32__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_16libctabixproxies_toDot(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_v); /* proto */ static PyObject *__pyx_pf_5pysam_16libctabixproxies_2quote(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_v); /* proto */ +static int __pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_2__getattr__(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy___cinit__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static void __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_2__dealloc__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_4getMinFields(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6getMaxFields(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6contig___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6contig_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6source___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6source_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_7feature___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_7feature_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5start___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5start_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_3end___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_3end_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5score___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5score_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6strand___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6strand_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5frame___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5frame_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_10attributes___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_10attributes_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_8asDict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_10fromDict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_d); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_2getMinFields(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_4getMaxFields(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6to_dict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_8as_dict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_10from_dict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_d); /* proto */ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_12__str__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_14invert(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, int __pyx_v_lcontig); /* proto */ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_16keys(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_18__getitem__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_20__getattr__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_item); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_22setAttribute(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_20setAttribute(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_22attribute_string2dict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_s); /* proto */ #if PY_MAJOR_VERSION < 3 static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_24__cmp__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ #endif static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_26__richcmp__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_other, int __pyx_v_op); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_28__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_30__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ -static int __pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_2__getattr__(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_28dict2attribute_string(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_d); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_30attribute_string2iterator(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_s); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_33__getattr__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ +static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_35__setattr__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_37asDict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_39fromDict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_41__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_43__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_dict2attribute_string(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *__pyx_v_self, PyObject *__pyx_v_d); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_25attribute_string2iterator_genexpr(PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_2attribute_string2iterator(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *__pyx_v_self, PyObject *__pyx_v_s); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_5__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_7__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_getMinFields(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_2getMaxFields(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_4__str__(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self); /* proto */ @@ -2085,11 +2389,21 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_6__reduce_cython__ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags); /* proto */ static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ +static PyObject *__pyx_pf_11cfunc_dot_to_py_36__Pyx_CFunc_object____object___to_py_wrap(PyObject *__pyx_self, PyObject *__pyx_v_v); /* proto */ +static PyObject *__pyx_pf_11cfunc_dot_to_py_33__Pyx_CFunc_int____object___to_py_wrap(PyObject *__pyx_self, PyObject *__pyx_v_v); /* proto */ +static PyObject *__pyx_pf_11cfunc_dot_to_py_30__Pyx_CFunc_str____int___to_py_wrap(PyObject *__pyx_self, int __pyx_v_v); /* proto */ static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_TupleProxy(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_GTFProxy(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_NamedTupleProxy(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_GTFProxy(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_GFF3Proxy(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_BedProxy(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_VCFProxy(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new___pyx_scope_struct____Pyx_CFunc_object____object___to_py(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new___pyx_scope_struct____Pyx_CFunc_int____object___to_py(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new___pyx_scope_struct____Pyx_CFunc_str____int___to_py(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; static PyObject *__pyx_int_2; @@ -2111,24 +2425,20 @@ static PyObject *__pyx_tuple__5; static PyObject *__pyx_tuple__6; static PyObject *__pyx_tuple__7; static PyObject *__pyx_tuple__8; -static PyObject *__pyx_slice__29; -static PyObject *__pyx_slice__33; +static PyObject *__pyx_slice__24; +static PyObject *__pyx_slice__28; static PyObject *__pyx_tuple__10; static PyObject *__pyx_tuple__11; static PyObject *__pyx_tuple__12; static PyObject *__pyx_tuple__14; static PyObject *__pyx_tuple__15; -static PyObject *__pyx_tuple__16; -static PyObject *__pyx_tuple__17; -static PyObject *__pyx_tuple__18; -static PyObject *__pyx_tuple__19; -static PyObject *__pyx_tuple__21; static PyObject *__pyx_tuple__22; static PyObject *__pyx_tuple__23; -static PyObject *__pyx_tuple__24; static PyObject *__pyx_tuple__26; -static PyObject *__pyx_tuple__28; +static PyObject *__pyx_tuple__29; +static PyObject *__pyx_tuple__30; static PyObject *__pyx_tuple__31; +static PyObject *__pyx_tuple__32; static PyObject *__pyx_tuple__34; static PyObject *__pyx_tuple__36; static PyObject *__pyx_tuple__37; @@ -2139,16 +2449,19 @@ static PyObject *__pyx_tuple__41; static PyObject *__pyx_tuple__42; static PyObject *__pyx_tuple__43; static PyObject *__pyx_tuple__44; -static PyObject *__pyx_tuple__45; static PyObject *__pyx_tuple__46; -static PyObject *__pyx_tuple__47; -static PyObject *__pyx_tuple__49; -static PyObject *__pyx_codeobj__48; -static PyObject *__pyx_codeobj__50; +static PyObject *__pyx_tuple__48; +static PyObject *__pyx_tuple__50; +static PyObject *__pyx_tuple__52; +static PyObject *__pyx_codeobj__45; +static PyObject *__pyx_codeobj__47; +static PyObject *__pyx_codeobj__49; +static PyObject *__pyx_codeobj__51; +static PyObject *__pyx_codeobj__53; /* Late includes */ -/* "pysam/libctabixproxies.pyx":13 - * import collections +/* "pysam/libctabixproxies.pyx":15 + * * * cdef char *StrOrEmpty(char * buffer): # <<<<<<<<<<<<<< * if buffer == NULL: @@ -2161,7 +2474,7 @@ static char *__pyx_f_5pysam_16libctabixproxies_StrOrEmpty(char *__pyx_v_buffer) int __pyx_t_1; __Pyx_RefNannySetupContext("StrOrEmpty", 0); - /* "pysam/libctabixproxies.pyx":14 + /* "pysam/libctabixproxies.pyx":16 * * cdef char *StrOrEmpty(char * buffer): * if buffer == NULL: # <<<<<<<<<<<<<< @@ -2171,7 +2484,7 @@ static char *__pyx_f_5pysam_16libctabixproxies_StrOrEmpty(char *__pyx_v_buffer) __pyx_t_1 = ((__pyx_v_buffer == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":15 + /* "pysam/libctabixproxies.pyx":17 * cdef char *StrOrEmpty(char * buffer): * if buffer == NULL: * return "" # <<<<<<<<<<<<<< @@ -2181,7 +2494,7 @@ static char *__pyx_f_5pysam_16libctabixproxies_StrOrEmpty(char *__pyx_v_buffer) __pyx_r = ((char *)""); goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":14 + /* "pysam/libctabixproxies.pyx":16 * * cdef char *StrOrEmpty(char * buffer): * if buffer == NULL: # <<<<<<<<<<<<<< @@ -2190,20 +2503,20 @@ static char *__pyx_f_5pysam_16libctabixproxies_StrOrEmpty(char *__pyx_v_buffer) */ } - /* "pysam/libctabixproxies.pyx":16 + /* "pysam/libctabixproxies.pyx":18 * if buffer == NULL: * return "" * else: return buffer # <<<<<<<<<<<<<< * - * cdef int isNew(char * p, char * buffer, size_t nbytes): + * */ /*else*/ { __pyx_r = __pyx_v_buffer; goto __pyx_L0; } - /* "pysam/libctabixproxies.pyx":13 - * import collections + /* "pysam/libctabixproxies.pyx":15 + * * * cdef char *StrOrEmpty(char * buffer): # <<<<<<<<<<<<<< * if buffer == NULL: @@ -2216,8 +2529,8 @@ static char *__pyx_f_5pysam_16libctabixproxies_StrOrEmpty(char *__pyx_v_buffer) return __pyx_r; } -/* "pysam/libctabixproxies.pyx":18 - * else: return buffer +/* "pysam/libctabixproxies.pyx":21 + * * * cdef int isNew(char * p, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< * """return True if `p` is located within `buffer` of size @@ -2230,51 +2543,51 @@ static int __pyx_f_5pysam_16libctabixproxies_isNew(char *__pyx_v_p, char *__pyx_ int __pyx_t_1; __Pyx_RefNannySetupContext("isNew", 0); - /* "pysam/libctabixproxies.pyx":22 + /* "pysam/libctabixproxies.pyx":25 * `nbytes` * """ * if p == NULL: # <<<<<<<<<<<<<< * return 0 - * return not (buffer <= p < buffer + nbytes) + * */ __pyx_t_1 = ((__pyx_v_p == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":23 + /* "pysam/libctabixproxies.pyx":26 * """ * if p == NULL: * return 0 # <<<<<<<<<<<<<< - * return not (buffer <= p < buffer + nbytes) * + * return not (buffer <= p <= buffer + nbytes) */ __pyx_r = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":22 + /* "pysam/libctabixproxies.pyx":25 * `nbytes` * """ * if p == NULL: # <<<<<<<<<<<<<< * return 0 - * return not (buffer <= p < buffer + nbytes) + * */ } - /* "pysam/libctabixproxies.pyx":24 - * if p == NULL: + /* "pysam/libctabixproxies.pyx":28 * return 0 - * return not (buffer <= p < buffer + nbytes) # <<<<<<<<<<<<<< + * + * return not (buffer <= p <= buffer + nbytes) # <<<<<<<<<<<<<< * * */ __pyx_t_1 = (__pyx_v_buffer <= __pyx_v_p); if (__pyx_t_1) { - __pyx_t_1 = (__pyx_v_p < (__pyx_v_buffer + __pyx_v_nbytes)); + __pyx_t_1 = (__pyx_v_p <= (__pyx_v_buffer + __pyx_v_nbytes)); } __pyx_r = (!(__pyx_t_1 != 0)); goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":18 - * else: return buffer + /* "pysam/libctabixproxies.pyx":21 + * * * cdef int isNew(char * p, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< * """return True if `p` is located within `buffer` of size @@ -2287,7 +2600,7 @@ static int __pyx_f_5pysam_16libctabixproxies_isNew(char *__pyx_v_p, char *__pyx_ return __pyx_r; } -/* "pysam/libctabixproxies.pyx":38 +/* "pysam/libctabixproxies.pyx":42 * ''' * * def __cinit__(self, encoding="ascii"): # <<<<<<<<<<<<<< @@ -2324,7 +2637,7 @@ static int __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_1__cinit__(PyObject * } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 38, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 42, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2338,7 +2651,7 @@ static int __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_1__cinit__(PyObject * } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 38, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 42, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabixproxies.TupleProxy.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2356,7 +2669,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy___cinit__(struct __py __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__", 0); - /* "pysam/libctabixproxies.pyx":39 + /* "pysam/libctabixproxies.pyx":43 * * def __cinit__(self, encoding="ascii"): * self.data = NULL # <<<<<<<<<<<<<< @@ -2365,7 +2678,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy___cinit__(struct __py */ __pyx_v_self->data = NULL; - /* "pysam/libctabixproxies.pyx":40 + /* "pysam/libctabixproxies.pyx":44 * def __cinit__(self, encoding="ascii"): * self.data = NULL * self.fields = NULL # <<<<<<<<<<<<<< @@ -2374,7 +2687,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy___cinit__(struct __py */ __pyx_v_self->fields = NULL; - /* "pysam/libctabixproxies.pyx":41 + /* "pysam/libctabixproxies.pyx":45 * self.data = NULL * self.fields = NULL * self.index = 0 # <<<<<<<<<<<<<< @@ -2383,7 +2696,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy___cinit__(struct __py */ __pyx_v_self->index = 0; - /* "pysam/libctabixproxies.pyx":42 + /* "pysam/libctabixproxies.pyx":46 * self.fields = NULL * self.index = 0 * self.nbytes = 0 # <<<<<<<<<<<<<< @@ -2392,7 +2705,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy___cinit__(struct __py */ __pyx_v_self->nbytes = 0; - /* "pysam/libctabixproxies.pyx":43 + /* "pysam/libctabixproxies.pyx":47 * self.index = 0 * self.nbytes = 0 * self.is_modified = 0 # <<<<<<<<<<<<<< @@ -2401,7 +2714,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy___cinit__(struct __py */ __pyx_v_self->is_modified = 0; - /* "pysam/libctabixproxies.pyx":44 + /* "pysam/libctabixproxies.pyx":48 * self.nbytes = 0 * self.is_modified = 0 * self.nfields = 0 # <<<<<<<<<<<<<< @@ -2410,7 +2723,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy___cinit__(struct __py */ __pyx_v_self->nfields = 0; - /* "pysam/libctabixproxies.pyx":46 + /* "pysam/libctabixproxies.pyx":50 * self.nfields = 0 * # start counting at field offset * self.offset = 0 # <<<<<<<<<<<<<< @@ -2419,7 +2732,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy___cinit__(struct __py */ __pyx_v_self->offset = 0; - /* "pysam/libctabixproxies.pyx":47 + /* "pysam/libctabixproxies.pyx":51 * # start counting at field offset * self.offset = 0 * self.encoding = encoding # <<<<<<<<<<<<<< @@ -2432,7 +2745,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy___cinit__(struct __py __Pyx_DECREF(__pyx_v_self->encoding); __pyx_v_self->encoding = __pyx_v_encoding; - /* "pysam/libctabixproxies.pyx":38 + /* "pysam/libctabixproxies.pyx":42 * ''' * * def __cinit__(self, encoding="ascii"): # <<<<<<<<<<<<<< @@ -2446,7 +2759,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy___cinit__(struct __py return __pyx_r; } -/* "pysam/libctabixproxies.pyx":49 +/* "pysam/libctabixproxies.pyx":53 * self.encoding = encoding * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -2472,7 +2785,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct int __pyx_t_2; __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "pysam/libctabixproxies.pyx":51 + /* "pysam/libctabixproxies.pyx":55 * def __dealloc__(self): * cdef int x * if self.is_modified: # <<<<<<<<<<<<<< @@ -2482,7 +2795,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct __pyx_t_1 = (__pyx_v_self->is_modified != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":52 + /* "pysam/libctabixproxies.pyx":56 * cdef int x * if self.is_modified: * for x from 0 <= x < self.nfields: # <<<<<<<<<<<<<< @@ -2492,7 +2805,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct __pyx_t_2 = __pyx_v_self->nfields; for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) { - /* "pysam/libctabixproxies.pyx":53 + /* "pysam/libctabixproxies.pyx":57 * if self.is_modified: * for x from 0 <= x < self.nfields: * if isNew(self.fields[x], self.data, self.nbytes): # <<<<<<<<<<<<<< @@ -2502,7 +2815,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct __pyx_t_1 = (__pyx_f_5pysam_16libctabixproxies_isNew((__pyx_v_self->fields[__pyx_v_x]), __pyx_v_self->data, __pyx_v_self->nbytes) != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":54 + /* "pysam/libctabixproxies.pyx":58 * for x from 0 <= x < self.nfields: * if isNew(self.fields[x], self.data, self.nbytes): * free(self.fields[x]) # <<<<<<<<<<<<<< @@ -2511,7 +2824,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct */ free((__pyx_v_self->fields[__pyx_v_x])); - /* "pysam/libctabixproxies.pyx":55 + /* "pysam/libctabixproxies.pyx":59 * if isNew(self.fields[x], self.data, self.nbytes): * free(self.fields[x]) * self.fields[x] = NULL # <<<<<<<<<<<<<< @@ -2520,7 +2833,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct */ (__pyx_v_self->fields[__pyx_v_x]) = NULL; - /* "pysam/libctabixproxies.pyx":53 + /* "pysam/libctabixproxies.pyx":57 * if self.is_modified: * for x from 0 <= x < self.nfields: * if isNew(self.fields[x], self.data, self.nbytes): # <<<<<<<<<<<<<< @@ -2530,7 +2843,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct } } - /* "pysam/libctabixproxies.pyx":51 + /* "pysam/libctabixproxies.pyx":55 * def __dealloc__(self): * cdef int x * if self.is_modified: # <<<<<<<<<<<<<< @@ -2539,7 +2852,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct */ } - /* "pysam/libctabixproxies.pyx":57 + /* "pysam/libctabixproxies.pyx":61 * self.fields[x] = NULL * * if self.data != NULL: # <<<<<<<<<<<<<< @@ -2549,7 +2862,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct __pyx_t_1 = ((__pyx_v_self->data != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":58 + /* "pysam/libctabixproxies.pyx":62 * * if self.data != NULL: * free(self.data) # <<<<<<<<<<<<<< @@ -2558,7 +2871,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct */ free(__pyx_v_self->data); - /* "pysam/libctabixproxies.pyx":57 + /* "pysam/libctabixproxies.pyx":61 * self.fields[x] = NULL * * if self.data != NULL: # <<<<<<<<<<<<<< @@ -2567,7 +2880,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct */ } - /* "pysam/libctabixproxies.pyx":59 + /* "pysam/libctabixproxies.pyx":63 * if self.data != NULL: * free(self.data) * if self.fields != NULL: # <<<<<<<<<<<<<< @@ -2577,7 +2890,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct __pyx_t_1 = ((__pyx_v_self->fields != NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":60 + /* "pysam/libctabixproxies.pyx":64 * free(self.data) * if self.fields != NULL: * free(self.fields) # <<<<<<<<<<<<<< @@ -2586,7 +2899,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct */ free(__pyx_v_self->fields); - /* "pysam/libctabixproxies.pyx":59 + /* "pysam/libctabixproxies.pyx":63 * if self.data != NULL: * free(self.data) * if self.fields != NULL: # <<<<<<<<<<<<<< @@ -2595,7 +2908,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct */ } - /* "pysam/libctabixproxies.pyx":49 + /* "pysam/libctabixproxies.pyx":53 * self.encoding = encoding * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -2607,7 +2920,7 @@ static void __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_2__dealloc__(struct __Pyx_RefNannyFinishContext(); } -/* "pysam/libctabixproxies.pyx":62 +/* "pysam/libctabixproxies.pyx":66 * free(self.fields) * * def __copy__(self): # <<<<<<<<<<<<<< @@ -2639,7 +2952,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_4__copy__(struc struct __pyx_opt_args_5pysam_16libctabixproxies_10TupleProxy_copy __pyx_t_5; __Pyx_RefNannySetupContext("__copy__", 0); - /* "pysam/libctabixproxies.pyx":63 + /* "pysam/libctabixproxies.pyx":67 * * def __copy__(self): * if self.is_modified: # <<<<<<<<<<<<<< @@ -2649,20 +2962,20 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_4__copy__(struc __pyx_t_1 = (__pyx_v_self->is_modified != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabixproxies.pyx":64 + /* "pysam/libctabixproxies.pyx":68 * def __copy__(self): * if self.is_modified: * raise NotImplementedError( # <<<<<<<<<<<<<< * "copying modified tuples is not implemented") * cdef TupleProxy n = type(self)() */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 64, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 68, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 64, __pyx_L1_error) + __PYX_ERR(0, 68, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":63 + /* "pysam/libctabixproxies.pyx":67 * * def __copy__(self): * if self.is_modified: # <<<<<<<<<<<<<< @@ -2671,7 +2984,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_4__copy__(struc */ } - /* "pysam/libctabixproxies.pyx":66 + /* "pysam/libctabixproxies.pyx":70 * raise NotImplementedError( * "copying modified tuples is not implemented") * cdef TupleProxy n = type(self)() # <<<<<<<<<<<<<< @@ -2690,18 +3003,18 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_4__copy__(struc } } if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 70, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 70, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5pysam_16libctabixproxies_TupleProxy))))) __PYX_ERR(0, 66, __pyx_L1_error) + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5pysam_16libctabixproxies_TupleProxy))))) __PYX_ERR(0, 70, __pyx_L1_error) __pyx_v_n = ((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":67 + /* "pysam/libctabixproxies.pyx":71 * "copying modified tuples is not implemented") * cdef TupleProxy n = type(self)() * n.copy(self.data, self.nbytes, reset=True) # <<<<<<<<<<<<<< @@ -2710,11 +3023,11 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_4__copy__(struc */ __pyx_t_5.__pyx_n = 1; __pyx_t_5.reset = 1; - __pyx_t_2 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_n->__pyx_vtab)->copy(__pyx_v_n, __pyx_v_self->data, __pyx_v_self->nbytes, &__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L1_error) + __pyx_t_2 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_n->__pyx_vtab)->copy(__pyx_v_n, __pyx_v_self->data, __pyx_v_self->nbytes, &__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":68 + /* "pysam/libctabixproxies.pyx":72 * cdef TupleProxy n = type(self)() * n.copy(self.data, self.nbytes, reset=True) * return n # <<<<<<<<<<<<<< @@ -2726,7 +3039,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_4__copy__(struc __pyx_r = ((PyObject *)__pyx_v_n); goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":62 + /* "pysam/libctabixproxies.pyx":66 * free(self.fields) * * def __copy__(self): # <<<<<<<<<<<<<< @@ -2748,7 +3061,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_4__copy__(struc return __pyx_r; } -/* "pysam/libctabixproxies.pyx":70 +/* "pysam/libctabixproxies.pyx":74 * return n * * def compare(self, TupleProxy other): # <<<<<<<<<<<<<< @@ -2763,7 +3076,7 @@ static PyObject *__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_7compare(PyObje PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("compare (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_16libctabixproxies_TupleProxy, 1, "other", 0))) __PYX_ERR(0, 70, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_16libctabixproxies_TupleProxy, 1, "other", 0))) __PYX_ERR(0, 74, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self), ((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_other)); /* function exit code */ @@ -2783,7 +3096,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("compare", 0); - /* "pysam/libctabixproxies.pyx":75 + /* "pysam/libctabixproxies.pyx":79 * * ''' * if self.is_modified or other.is_modified: # <<<<<<<<<<<<<< @@ -2801,20 +3114,20 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct __pyx_L4_bool_binop_done:; if (unlikely(__pyx_t_1)) { - /* "pysam/libctabixproxies.pyx":76 + /* "pysam/libctabixproxies.pyx":80 * ''' * if self.is_modified or other.is_modified: * raise NotImplementedError( # <<<<<<<<<<<<<< * 'comparison of modified TupleProxies is not implemented') * if self.data == other.data: */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 76, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 80, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 76, __pyx_L1_error) + __PYX_ERR(0, 80, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":75 + /* "pysam/libctabixproxies.pyx":79 * * ''' * if self.is_modified or other.is_modified: # <<<<<<<<<<<<<< @@ -2823,7 +3136,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct */ } - /* "pysam/libctabixproxies.pyx":78 + /* "pysam/libctabixproxies.pyx":82 * raise NotImplementedError( * 'comparison of modified TupleProxies is not implemented') * if self.data == other.data: # <<<<<<<<<<<<<< @@ -2833,7 +3146,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct __pyx_t_1 = ((__pyx_v_self->data == __pyx_v_other->data) != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":79 + /* "pysam/libctabixproxies.pyx":83 * 'comparison of modified TupleProxies is not implemented') * if self.data == other.data: * return 0 # <<<<<<<<<<<<<< @@ -2845,7 +3158,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct __pyx_r = __pyx_int_0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":78 + /* "pysam/libctabixproxies.pyx":82 * raise NotImplementedError( * 'comparison of modified TupleProxies is not implemented') * if self.data == other.data: # <<<<<<<<<<<<<< @@ -2854,7 +3167,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct */ } - /* "pysam/libctabixproxies.pyx":81 + /* "pysam/libctabixproxies.pyx":85 * return 0 * * if self.nbytes < other.nbytes: # <<<<<<<<<<<<<< @@ -2864,7 +3177,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct __pyx_t_1 = ((__pyx_v_self->nbytes < __pyx_v_other->nbytes) != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":82 + /* "pysam/libctabixproxies.pyx":86 * * if self.nbytes < other.nbytes: * return -1 # <<<<<<<<<<<<<< @@ -2876,7 +3189,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct __pyx_r = __pyx_int_neg_1; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":81 + /* "pysam/libctabixproxies.pyx":85 * return 0 * * if self.nbytes < other.nbytes: # <<<<<<<<<<<<<< @@ -2885,7 +3198,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct */ } - /* "pysam/libctabixproxies.pyx":83 + /* "pysam/libctabixproxies.pyx":87 * if self.nbytes < other.nbytes: * return -1 * elif self.nbytes > other.nbytes: # <<<<<<<<<<<<<< @@ -2895,7 +3208,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct __pyx_t_1 = ((__pyx_v_self->nbytes > __pyx_v_other->nbytes) != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":84 + /* "pysam/libctabixproxies.pyx":88 * return -1 * elif self.nbytes > other.nbytes: * return 1 # <<<<<<<<<<<<<< @@ -2907,7 +3220,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct __pyx_r = __pyx_int_1; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":83 + /* "pysam/libctabixproxies.pyx":87 * if self.nbytes < other.nbytes: * return -1 * elif self.nbytes > other.nbytes: # <<<<<<<<<<<<<< @@ -2916,7 +3229,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct */ } - /* "pysam/libctabixproxies.pyx":85 + /* "pysam/libctabixproxies.pyx":89 * elif self.nbytes > other.nbytes: * return 1 * return memcmp(self.data, other.data, self.nbytes) # <<<<<<<<<<<<<< @@ -2924,13 +3237,13 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct * def __richcmp__(self, TupleProxy other, int op): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyInt_From_int(memcmp(__pyx_v_self->data, __pyx_v_other->data, __pyx_v_self->nbytes)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 85, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(memcmp(__pyx_v_self->data, __pyx_v_other->data, __pyx_v_self->nbytes)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 89, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":70 + /* "pysam/libctabixproxies.pyx":74 * return n * * def compare(self, TupleProxy other): # <<<<<<<<<<<<<< @@ -2949,7 +3262,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_6compare(struct return __pyx_r; } -/* "pysam/libctabixproxies.pyx":87 +/* "pysam/libctabixproxies.pyx":91 * return memcmp(self.data, other.data, self.nbytes) * * def __richcmp__(self, TupleProxy other, int op): # <<<<<<<<<<<<<< @@ -2963,7 +3276,7 @@ static PyObject *__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_9__richcmp__(Py PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_16libctabixproxies_TupleProxy, 1, "other", 0))) __PYX_ERR(0, 87, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_16libctabixproxies_TupleProxy, 1, "other", 0))) __PYX_ERR(0, 91, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self), ((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_other), ((int)__pyx_v_op)); /* function exit code */ @@ -2986,7 +3299,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__richcmp__", 0); - /* "pysam/libctabixproxies.pyx":88 + /* "pysam/libctabixproxies.pyx":92 * * def __richcmp__(self, TupleProxy other, int op): * if op == 2: # == operator # <<<<<<<<<<<<<< @@ -2996,7 +3309,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st switch (__pyx_v_op) { case 2: - /* "pysam/libctabixproxies.pyx":89 + /* "pysam/libctabixproxies.pyx":93 * def __richcmp__(self, TupleProxy other, int op): * if op == 2: # == operator * return self.compare(other) == 0 # <<<<<<<<<<<<<< @@ -3004,7 +3317,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st * return self.compare(other) != 0 */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_compare); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 89, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_compare); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -3017,13 +3330,13 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st } } if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_other)}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -3031,32 +3344,32 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_3, ((PyObject *)__pyx_v_other)}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 89, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 93, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; __Pyx_INCREF(((PyObject *)__pyx_v_other)); __Pyx_GIVEREF(((PyObject *)__pyx_v_other)); PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_other)); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 89, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":88 + /* "pysam/libctabixproxies.pyx":92 * * def __richcmp__(self, TupleProxy other, int op): * if op == 2: # == operator # <<<<<<<<<<<<<< @@ -3065,7 +3378,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st */ break; - /* "pysam/libctabixproxies.pyx":90 + /* "pysam/libctabixproxies.pyx":94 * if op == 2: # == operator * return self.compare(other) == 0 * elif op == 3: # != operator # <<<<<<<<<<<<<< @@ -3074,7 +3387,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st */ case 3: - /* "pysam/libctabixproxies.pyx":91 + /* "pysam/libctabixproxies.pyx":95 * return self.compare(other) == 0 * elif op == 3: # != operator * return self.compare(other) != 0 # <<<<<<<<<<<<<< @@ -3082,7 +3395,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st * err_msg = "op {0} isn't implemented yet".format(op) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_compare); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 91, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_compare); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { @@ -3095,13 +3408,13 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st } } if (!__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 91, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_other)}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 91, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_2); } else @@ -3109,31 +3422,31 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_other)}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 91, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 91, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_INCREF(((PyObject *)__pyx_v_other)); __Pyx_GIVEREF(((PyObject *)__pyx_v_other)); PyTuple_SET_ITEM(__pyx_t_3, 0+1, ((PyObject *)__pyx_v_other)); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 91, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 91, __pyx_L1_error) + __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":90 + /* "pysam/libctabixproxies.pyx":94 * if op == 2: # == operator * return self.compare(other) == 0 * elif op == 3: # != operator # <<<<<<<<<<<<<< @@ -3143,16 +3456,16 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st break; default: - /* "pysam/libctabixproxies.pyx":93 + /* "pysam/libctabixproxies.pyx":97 * return self.compare(other) != 0 * else: * err_msg = "op {0} isn't implemented yet".format(op) # <<<<<<<<<<<<<< * raise NotImplementedError(err_msg) * */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_op_0_isn_t_implemented_yet, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_op_0_isn_t_implemented_yet, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 97, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_op); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_op); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 97, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -3165,14 +3478,14 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st } } if (!__pyx_t_4) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -3181,20 +3494,20 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else #endif { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 97, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } @@ -3203,22 +3516,22 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st __pyx_v_err_msg = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":94 + /* "pysam/libctabixproxies.pyx":98 * else: * err_msg = "op {0} isn't implemented yet".format(op) * raise NotImplementedError(err_msg) # <<<<<<<<<<<<<< * * cdef take(self, char * buffer, size_t nbytes): */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_NotImplementedError, __pyx_v_err_msg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 94, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_NotImplementedError, __pyx_v_err_msg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 98, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 94, __pyx_L1_error) + __PYX_ERR(0, 98, __pyx_L1_error) break; } - /* "pysam/libctabixproxies.pyx":87 + /* "pysam/libctabixproxies.pyx":91 * return memcmp(self.data, other.data, self.nbytes) * * def __richcmp__(self, TupleProxy other, int op): # <<<<<<<<<<<<<< @@ -3242,7 +3555,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_8__richcmp__(st return __pyx_r; } -/* "pysam/libctabixproxies.pyx":96 +/* "pysam/libctabixproxies.pyx":100 * raise NotImplementedError(err_msg) * * cdef take(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< @@ -3256,7 +3569,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_take(struct __py PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("take", 0); - /* "pysam/libctabixproxies.pyx":101 + /* "pysam/libctabixproxies.pyx":105 * Take ownership of the pointer. * ''' * self.data = buffer # <<<<<<<<<<<<<< @@ -3265,7 +3578,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_take(struct __py */ __pyx_v_self->data = __pyx_v_buffer; - /* "pysam/libctabixproxies.pyx":102 + /* "pysam/libctabixproxies.pyx":106 * ''' * self.data = buffer * self.nbytes = nbytes # <<<<<<<<<<<<<< @@ -3274,18 +3587,18 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_take(struct __py */ __pyx_v_self->nbytes = __pyx_v_nbytes; - /* "pysam/libctabixproxies.pyx":103 + /* "pysam/libctabixproxies.pyx":107 * self.data = buffer * self.nbytes = nbytes * self.update(buffer, nbytes) # <<<<<<<<<<<<<< * * cdef present(self, char * buffer, size_t nbytes): */ - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self->__pyx_vtab)->update(__pyx_v_self, __pyx_v_buffer, __pyx_v_nbytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self->__pyx_vtab)->update(__pyx_v_self, __pyx_v_buffer, __pyx_v_nbytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":96 + /* "pysam/libctabixproxies.pyx":100 * raise NotImplementedError(err_msg) * * cdef take(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< @@ -3306,7 +3619,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_take(struct __py return __pyx_r; } -/* "pysam/libctabixproxies.pyx":105 +/* "pysam/libctabixproxies.pyx":109 * self.update(buffer, nbytes) * * cdef present(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< @@ -3320,18 +3633,18 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_present(struct _ PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("present", 0); - /* "pysam/libctabixproxies.pyx":110 + /* "pysam/libctabixproxies.pyx":114 * Do not take ownership of the pointer. * ''' * self.update(buffer, nbytes) # <<<<<<<<<<<<<< * * cdef copy(self, char * buffer, size_t nbytes, bint reset=False): */ - __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self->__pyx_vtab)->update(__pyx_v_self, __pyx_v_buffer, __pyx_v_nbytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self->__pyx_vtab)->update(__pyx_v_self, __pyx_v_buffer, __pyx_v_nbytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":105 + /* "pysam/libctabixproxies.pyx":109 * self.update(buffer, nbytes) * * cdef present(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< @@ -3352,7 +3665,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_present(struct _ return __pyx_r; } -/* "pysam/libctabixproxies.pyx":112 +/* "pysam/libctabixproxies.pyx":116 * self.update(buffer, nbytes) * * cdef copy(self, char * buffer, size_t nbytes, bint reset=False): # <<<<<<<<<<<<<< @@ -3376,7 +3689,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py } } - /* "pysam/libctabixproxies.pyx":120 + /* "pysam/libctabixproxies.pyx":124 * ''' * # +1 for '\0' * cdef int s = sizeof(char) * (nbytes + 1) # <<<<<<<<<<<<<< @@ -3385,7 +3698,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py */ __pyx_v_s = ((sizeof(char)) * (__pyx_v_nbytes + 1)); - /* "pysam/libctabixproxies.pyx":121 + /* "pysam/libctabixproxies.pyx":125 * # +1 for '\0' * cdef int s = sizeof(char) * (nbytes + 1) * self.data = malloc(s) # <<<<<<<<<<<<<< @@ -3394,7 +3707,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py */ __pyx_v_self->data = ((char *)malloc(__pyx_v_s)); - /* "pysam/libctabixproxies.pyx":122 + /* "pysam/libctabixproxies.pyx":126 * cdef int s = sizeof(char) * (nbytes + 1) * self.data = malloc(s) * if self.data == NULL: # <<<<<<<<<<<<<< @@ -3404,20 +3717,20 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py __pyx_t_1 = ((__pyx_v_self->data == NULL) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabixproxies.pyx":123 + /* "pysam/libctabixproxies.pyx":127 * self.data = malloc(s) * if self.data == NULL: * raise ValueError("out of memory in TupleProxy.copy()") # <<<<<<<<<<<<<< * memcpy(self.data, buffer, s) * */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 123, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 123, __pyx_L1_error) + __PYX_ERR(0, 127, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":122 + /* "pysam/libctabixproxies.pyx":126 * cdef int s = sizeof(char) * (nbytes + 1) * self.data = malloc(s) * if self.data == NULL: # <<<<<<<<<<<<<< @@ -3426,7 +3739,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py */ } - /* "pysam/libctabixproxies.pyx":124 + /* "pysam/libctabixproxies.pyx":128 * if self.data == NULL: * raise ValueError("out of memory in TupleProxy.copy()") * memcpy(self.data, buffer, s) # <<<<<<<<<<<<<< @@ -3435,7 +3748,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py */ (void)(memcpy(((char *)__pyx_v_self->data), __pyx_v_buffer, __pyx_v_s)); - /* "pysam/libctabixproxies.pyx":126 + /* "pysam/libctabixproxies.pyx":130 * memcpy(self.data, buffer, s) * * if reset: # <<<<<<<<<<<<<< @@ -3445,7 +3758,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py __pyx_t_1 = (__pyx_v_reset != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":127 + /* "pysam/libctabixproxies.pyx":131 * * if reset: * for x from 0 <= x < nbytes: # <<<<<<<<<<<<<< @@ -3455,7 +3768,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py __pyx_t_3 = __pyx_v_nbytes; for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) { - /* "pysam/libctabixproxies.pyx":128 + /* "pysam/libctabixproxies.pyx":132 * if reset: * for x from 0 <= x < nbytes: * if self.data[x] == '\0': # <<<<<<<<<<<<<< @@ -3465,7 +3778,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py __pyx_t_1 = (((__pyx_v_self->data[__pyx_v_x]) == '\x00') != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":129 + /* "pysam/libctabixproxies.pyx":133 * for x from 0 <= x < nbytes: * if self.data[x] == '\0': * self.data[x] = '\t' # <<<<<<<<<<<<<< @@ -3474,7 +3787,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py */ (__pyx_v_self->data[__pyx_v_x]) = '\t'; - /* "pysam/libctabixproxies.pyx":128 + /* "pysam/libctabixproxies.pyx":132 * if reset: * for x from 0 <= x < nbytes: * if self.data[x] == '\0': # <<<<<<<<<<<<<< @@ -3484,7 +3797,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py } } - /* "pysam/libctabixproxies.pyx":126 + /* "pysam/libctabixproxies.pyx":130 * memcpy(self.data, buffer, s) * * if reset: # <<<<<<<<<<<<<< @@ -3493,18 +3806,18 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py */ } - /* "pysam/libctabixproxies.pyx":131 + /* "pysam/libctabixproxies.pyx":135 * self.data[x] = '\t' * * self.update(self.data, nbytes) # <<<<<<<<<<<<<< * * cpdef int getMinFields(self): */ - __pyx_t_2 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self->__pyx_vtab)->update(__pyx_v_self, __pyx_v_self->data, __pyx_v_nbytes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_2 = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self->__pyx_vtab)->update(__pyx_v_self, __pyx_v_self->data, __pyx_v_nbytes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":112 + /* "pysam/libctabixproxies.pyx":116 * self.update(buffer, nbytes) * * cdef copy(self, char * buffer, size_t nbytes, bint reset=False): # <<<<<<<<<<<<<< @@ -3525,7 +3838,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy(struct __py return __pyx_r; } -/* "pysam/libctabixproxies.pyx":133 +/* "pysam/libctabixproxies.pyx":137 * self.update(self.data, nbytes) * * cpdef int getMinFields(self): # <<<<<<<<<<<<<< @@ -3547,7 +3860,7 @@ static int __pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMinFields(CYTHON_UN if (unlikely(__pyx_skip_dispatch)) ; /* Check if overridden in Python */ else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getMinFields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getMinFields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_11getMinFields)) { __Pyx_INCREF(__pyx_t_1); @@ -3562,14 +3875,14 @@ static int __pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMinFields(CYTHON_UN } } if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 133, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 133, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 137, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 133, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_5; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -3578,7 +3891,7 @@ static int __pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMinFields(CYTHON_UN __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - /* "pysam/libctabixproxies.pyx":137 + /* "pysam/libctabixproxies.pyx":141 * # 1 is not a valid tabix entry, but TupleProxy * # could be more generic. * return 1 # <<<<<<<<<<<<<< @@ -3588,7 +3901,7 @@ static int __pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMinFields(CYTHON_UN __pyx_r = 1; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":133 + /* "pysam/libctabixproxies.pyx":137 * self.update(self.data, nbytes) * * cpdef int getMinFields(self): # <<<<<<<<<<<<<< @@ -3629,7 +3942,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_10getMinFields( PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("getMinFields", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMinFields(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMinFields(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3646,7 +3959,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_10getMinFields( return __pyx_r; } -/* "pysam/libctabixproxies.pyx":139 +/* "pysam/libctabixproxies.pyx":143 * return 1 * * cpdef int getMaxFields(self): # <<<<<<<<<<<<<< @@ -3668,7 +3981,7 @@ static int __pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMaxFields(CYTHON_UN if (unlikely(__pyx_skip_dispatch)) ; /* Check if overridden in Python */ else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getMaxFields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getMaxFields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_13getMaxFields)) { __Pyx_INCREF(__pyx_t_1); @@ -3683,14 +3996,14 @@ static int __pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMaxFields(CYTHON_UN } } if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 139, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 139, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 139, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 143, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_5; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -3699,7 +4012,7 @@ static int __pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMaxFields(CYTHON_UN __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - /* "pysam/libctabixproxies.pyx":142 + /* "pysam/libctabixproxies.pyx":146 * '''return maximum number of fields. Return * 0 for unknown length.''' * return 0 # <<<<<<<<<<<<<< @@ -3709,7 +4022,7 @@ static int __pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMaxFields(CYTHON_UN __pyx_r = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":139 + /* "pysam/libctabixproxies.pyx":143 * return 1 * * cpdef int getMaxFields(self): # <<<<<<<<<<<<<< @@ -3750,7 +4063,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_12getMaxFields( PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("getMaxFields", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMaxFields(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_5pysam_16libctabixproxies_10TupleProxy_getMaxFields(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3767,7 +4080,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_12getMaxFields( return __pyx_r; } -/* "pysam/libctabixproxies.pyx":144 +/* "pysam/libctabixproxies.pyx":148 * return 0 * * cdef update(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< @@ -3792,7 +4105,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ size_t __pyx_t_7; __Pyx_RefNannySetupContext("update", 0); - /* "pysam/libctabixproxies.pyx":165 + /* "pysam/libctabixproxies.pyx":169 * cdef int max_fields, min_fields, x * * assert strlen(buffer) == nbytes, \ # <<<<<<<<<<<<<< @@ -3803,18 +4116,18 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((strlen(__pyx_v_buffer) == __pyx_v_nbytes) != 0))) { - /* "pysam/libctabixproxies.pyx":167 + /* "pysam/libctabixproxies.pyx":171 * assert strlen(buffer) == nbytes, \ * "length of buffer (%i) != number of bytes (%i)" % ( * strlen(buffer), nbytes) # <<<<<<<<<<<<<< * * if buffer[nbytes] != 0: */ - __pyx_t_1 = __Pyx_PyInt_FromSize_t(strlen(__pyx_v_buffer)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_FromSize_t(strlen(__pyx_v_buffer)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_nbytes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_nbytes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); @@ -3823,24 +4136,24 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_1 = 0; __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":166 + /* "pysam/libctabixproxies.pyx":170 * * assert strlen(buffer) == nbytes, \ * "length of buffer (%i) != number of bytes (%i)" % ( # <<<<<<<<<<<<<< * strlen(buffer), nbytes) * */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_length_of_buffer_i_number_of_byt, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 166, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_length_of_buffer_i_number_of_byt, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyErr_SetObject(PyExc_AssertionError, __pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 165, __pyx_L1_error) + __PYX_ERR(0, 169, __pyx_L1_error) } } #endif - /* "pysam/libctabixproxies.pyx":169 + /* "pysam/libctabixproxies.pyx":173 * strlen(buffer), nbytes) * * if buffer[nbytes] != 0: # <<<<<<<<<<<<<< @@ -3850,26 +4163,26 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_4 = (((__pyx_v_buffer[__pyx_v_nbytes]) != 0) != 0); if (unlikely(__pyx_t_4)) { - /* "pysam/libctabixproxies.pyx":170 + /* "pysam/libctabixproxies.pyx":174 * * if buffer[nbytes] != 0: * raise ValueError("incomplete line at %s" % buffer) # <<<<<<<<<<<<<< * * ################################# */ - __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_buffer); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_buffer); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 174, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_incomplete_line_at_s, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 170, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_incomplete_line_at_s, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 174, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 174, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 170, __pyx_L1_error) + __PYX_ERR(0, 174, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":169 + /* "pysam/libctabixproxies.pyx":173 * strlen(buffer), nbytes) * * if buffer[nbytes] != 0: # <<<<<<<<<<<<<< @@ -3878,7 +4191,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ } - /* "pysam/libctabixproxies.pyx":174 + /* "pysam/libctabixproxies.pyx":178 * ################################# * # remove line breaks and feeds and update number of bytes * x = nbytes - 1 # <<<<<<<<<<<<<< @@ -3887,7 +4200,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_x = (__pyx_v_nbytes - 1); - /* "pysam/libctabixproxies.pyx":175 + /* "pysam/libctabixproxies.pyx":179 * # remove line breaks and feeds and update number of bytes * x = nbytes - 1 * while x > 0 and (buffer[x] == '\n' or buffer[x] == '\r'): # <<<<<<<<<<<<<< @@ -3912,7 +4225,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_L6_bool_binop_done:; if (!__pyx_t_4) break; - /* "pysam/libctabixproxies.pyx":176 + /* "pysam/libctabixproxies.pyx":180 * x = nbytes - 1 * while x > 0 and (buffer[x] == '\n' or buffer[x] == '\r'): * buffer[x] = '\0' # <<<<<<<<<<<<<< @@ -3921,7 +4234,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ (__pyx_v_buffer[__pyx_v_x]) = '\x00'; - /* "pysam/libctabixproxies.pyx":177 + /* "pysam/libctabixproxies.pyx":181 * while x > 0 and (buffer[x] == '\n' or buffer[x] == '\r'): * buffer[x] = '\0' * x -= 1 # <<<<<<<<<<<<<< @@ -3931,7 +4244,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_v_x = (__pyx_v_x - 1); } - /* "pysam/libctabixproxies.pyx":178 + /* "pysam/libctabixproxies.pyx":182 * buffer[x] = '\0' * x -= 1 * self.nbytes = x + 1 # <<<<<<<<<<<<<< @@ -3940,7 +4253,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_self->nbytes = (__pyx_v_x + 1); - /* "pysam/libctabixproxies.pyx":182 + /* "pysam/libctabixproxies.pyx":186 * ################################# * # clear data * if self.fields != NULL: # <<<<<<<<<<<<<< @@ -3950,7 +4263,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_4 = ((__pyx_v_self->fields != NULL) != 0); if (__pyx_t_4) { - /* "pysam/libctabixproxies.pyx":183 + /* "pysam/libctabixproxies.pyx":187 * # clear data * if self.fields != NULL: * free(self.fields) # <<<<<<<<<<<<<< @@ -3959,7 +4272,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ free(__pyx_v_self->fields); - /* "pysam/libctabixproxies.pyx":182 + /* "pysam/libctabixproxies.pyx":186 * ################################# * # clear data * if self.fields != NULL: # <<<<<<<<<<<<<< @@ -3968,7 +4281,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ } - /* "pysam/libctabixproxies.pyx":185 + /* "pysam/libctabixproxies.pyx":189 * free(self.fields) * * for field from 0 <= field < self.nfields: # <<<<<<<<<<<<<< @@ -3978,7 +4291,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_6 = __pyx_v_self->nfields; for (__pyx_v_field = 0; __pyx_v_field < __pyx_t_6; __pyx_v_field++) { - /* "pysam/libctabixproxies.pyx":186 + /* "pysam/libctabixproxies.pyx":190 * * for field from 0 <= field < self.nfields: * if isNew(self.fields[field], self.data, self.nbytes): # <<<<<<<<<<<<<< @@ -3988,7 +4301,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_4 = (__pyx_f_5pysam_16libctabixproxies_isNew((__pyx_v_self->fields[__pyx_v_field]), __pyx_v_self->data, __pyx_v_self->nbytes) != 0); if (__pyx_t_4) { - /* "pysam/libctabixproxies.pyx":187 + /* "pysam/libctabixproxies.pyx":191 * for field from 0 <= field < self.nfields: * if isNew(self.fields[field], self.data, self.nbytes): * free(self.fields[field]) # <<<<<<<<<<<<<< @@ -3997,7 +4310,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ free((__pyx_v_self->fields[__pyx_v_field])); - /* "pysam/libctabixproxies.pyx":186 + /* "pysam/libctabixproxies.pyx":190 * * for field from 0 <= field < self.nfields: * if isNew(self.fields[field], self.data, self.nbytes): # <<<<<<<<<<<<<< @@ -4007,7 +4320,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ } } - /* "pysam/libctabixproxies.pyx":189 + /* "pysam/libctabixproxies.pyx":193 * free(self.fields[field]) * * self.is_modified = self.nfields = 0 # <<<<<<<<<<<<<< @@ -4017,7 +4330,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_v_self->is_modified = 0; __pyx_v_self->nfields = 0; - /* "pysam/libctabixproxies.pyx":193 + /* "pysam/libctabixproxies.pyx":197 * ################################# * # allocate new * max_fields = self.getMaxFields() # <<<<<<<<<<<<<< @@ -4026,7 +4339,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_max_fields = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self->__pyx_vtab)->getMaxFields(__pyx_v_self, 0); - /* "pysam/libctabixproxies.pyx":196 + /* "pysam/libctabixproxies.pyx":200 * # pre-count fields - better would be * # to guess or dynamically grow * if max_fields == 0: # <<<<<<<<<<<<<< @@ -4036,7 +4349,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_4 = ((__pyx_v_max_fields == 0) != 0); if (__pyx_t_4) { - /* "pysam/libctabixproxies.pyx":197 + /* "pysam/libctabixproxies.pyx":201 * # to guess or dynamically grow * if max_fields == 0: * for x from 0 <= x < nbytes: # <<<<<<<<<<<<<< @@ -4046,7 +4359,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_7 = __pyx_v_nbytes; for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_7; __pyx_v_x++) { - /* "pysam/libctabixproxies.pyx":198 + /* "pysam/libctabixproxies.pyx":202 * if max_fields == 0: * for x from 0 <= x < nbytes: * if buffer[x] == '\t': # <<<<<<<<<<<<<< @@ -4056,7 +4369,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_4 = (((__pyx_v_buffer[__pyx_v_x]) == '\t') != 0); if (__pyx_t_4) { - /* "pysam/libctabixproxies.pyx":199 + /* "pysam/libctabixproxies.pyx":203 * for x from 0 <= x < nbytes: * if buffer[x] == '\t': * max_fields += 1 # <<<<<<<<<<<<<< @@ -4065,7 +4378,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_max_fields = (__pyx_v_max_fields + 1); - /* "pysam/libctabixproxies.pyx":198 + /* "pysam/libctabixproxies.pyx":202 * if max_fields == 0: * for x from 0 <= x < nbytes: * if buffer[x] == '\t': # <<<<<<<<<<<<<< @@ -4075,7 +4388,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ } } - /* "pysam/libctabixproxies.pyx":200 + /* "pysam/libctabixproxies.pyx":204 * if buffer[x] == '\t': * max_fields += 1 * max_fields += 1 # <<<<<<<<<<<<<< @@ -4084,7 +4397,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_max_fields = (__pyx_v_max_fields + 1); - /* "pysam/libctabixproxies.pyx":196 + /* "pysam/libctabixproxies.pyx":200 * # pre-count fields - better would be * # to guess or dynamically grow * if max_fields == 0: # <<<<<<<<<<<<<< @@ -4093,7 +4406,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ } - /* "pysam/libctabixproxies.pyx":202 + /* "pysam/libctabixproxies.pyx":206 * max_fields += 1 * * self.fields = calloc(max_fields, sizeof(char *)) # <<<<<<<<<<<<<< @@ -4102,7 +4415,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_self->fields = ((char **)calloc(__pyx_v_max_fields, (sizeof(char *)))); - /* "pysam/libctabixproxies.pyx":203 + /* "pysam/libctabixproxies.pyx":207 * * self.fields = calloc(max_fields, sizeof(char *)) * if self.fields == NULL: # <<<<<<<<<<<<<< @@ -4112,20 +4425,20 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_4 = ((__pyx_v_self->fields == NULL) != 0); if (unlikely(__pyx_t_4)) { - /* "pysam/libctabixproxies.pyx":204 + /* "pysam/libctabixproxies.pyx":208 * self.fields = calloc(max_fields, sizeof(char *)) * if self.fields == NULL: * raise ValueError("out of memory in TupleProxy.update()") # <<<<<<<<<<<<<< * * ################################# */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 204, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 208, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 204, __pyx_L1_error) + __PYX_ERR(0, 208, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":203 + /* "pysam/libctabixproxies.pyx":207 * * self.fields = calloc(max_fields, sizeof(char *)) * if self.fields == NULL: # <<<<<<<<<<<<<< @@ -4134,7 +4447,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ } - /* "pysam/libctabixproxies.pyx":208 + /* "pysam/libctabixproxies.pyx":212 * ################################# * # start filling * field = 0 # <<<<<<<<<<<<<< @@ -4143,7 +4456,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_field = 0; - /* "pysam/libctabixproxies.pyx":209 + /* "pysam/libctabixproxies.pyx":213 * # start filling * field = 0 * self.fields[field] = pos = buffer # <<<<<<<<<<<<<< @@ -4153,7 +4466,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ (__pyx_v_self->fields[__pyx_v_field]) = __pyx_v_buffer; __pyx_v_pos = __pyx_v_buffer; - /* "pysam/libctabixproxies.pyx":210 + /* "pysam/libctabixproxies.pyx":214 * field = 0 * self.fields[field] = pos = buffer * field += 1 # <<<<<<<<<<<<<< @@ -4162,7 +4475,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_field = (__pyx_v_field + 1); - /* "pysam/libctabixproxies.pyx":211 + /* "pysam/libctabixproxies.pyx":215 * self.fields[field] = pos = buffer * field += 1 * old_pos = pos # <<<<<<<<<<<<<< @@ -4171,7 +4484,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_old_pos = __pyx_v_pos; - /* "pysam/libctabixproxies.pyx":212 + /* "pysam/libctabixproxies.pyx":216 * field += 1 * old_pos = pos * while 1: # <<<<<<<<<<<<<< @@ -4180,7 +4493,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ while (1) { - /* "pysam/libctabixproxies.pyx":214 + /* "pysam/libctabixproxies.pyx":218 * while 1: * * pos = memchr(pos, '\t', nbytes) # <<<<<<<<<<<<<< @@ -4189,7 +4502,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_pos = ((char *)memchr(__pyx_v_pos, '\t', __pyx_v_nbytes)); - /* "pysam/libctabixproxies.pyx":215 + /* "pysam/libctabixproxies.pyx":219 * * pos = memchr(pos, '\t', nbytes) * if pos == NULL: # <<<<<<<<<<<<<< @@ -4199,7 +4512,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_4 = ((__pyx_v_pos == NULL) != 0); if (__pyx_t_4) { - /* "pysam/libctabixproxies.pyx":216 + /* "pysam/libctabixproxies.pyx":220 * pos = memchr(pos, '\t', nbytes) * if pos == NULL: * break # <<<<<<<<<<<<<< @@ -4208,7 +4521,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ goto __pyx_L19_break; - /* "pysam/libctabixproxies.pyx":215 + /* "pysam/libctabixproxies.pyx":219 * * pos = memchr(pos, '\t', nbytes) * if pos == NULL: # <<<<<<<<<<<<<< @@ -4217,7 +4530,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ } - /* "pysam/libctabixproxies.pyx":217 + /* "pysam/libctabixproxies.pyx":221 * if pos == NULL: * break * if field >= max_fields: # <<<<<<<<<<<<<< @@ -4227,18 +4540,18 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_4 = ((__pyx_v_field >= __pyx_v_max_fields) != 0); if (unlikely(__pyx_t_4)) { - /* "pysam/libctabixproxies.pyx":220 + /* "pysam/libctabixproxies.pyx":224 * raise ValueError( * "parsing error: more than %i fields in line: %s" % * (max_fields, buffer)) # <<<<<<<<<<<<<< * * pos[0] = '\0' */ - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_max_fields); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 220, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_max_fields); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 224, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 220, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 224, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 220, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 224, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); @@ -4247,32 +4560,32 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_2 = 0; __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":219 + /* "pysam/libctabixproxies.pyx":223 * if field >= max_fields: * raise ValueError( * "parsing error: more than %i fields in line: %s" % # <<<<<<<<<<<<<< * (max_fields, buffer)) * */ - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_parsing_error_more_than_i_fields, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 219, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_parsing_error_more_than_i_fields, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 223, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":218 + /* "pysam/libctabixproxies.pyx":222 * break * if field >= max_fields: * raise ValueError( # <<<<<<<<<<<<<< * "parsing error: more than %i fields in line: %s" % * (max_fields, buffer)) */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 218, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 222, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 218, __pyx_L1_error) + __PYX_ERR(0, 222, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":217 + /* "pysam/libctabixproxies.pyx":221 * if pos == NULL: * break * if field >= max_fields: # <<<<<<<<<<<<<< @@ -4281,7 +4594,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ } - /* "pysam/libctabixproxies.pyx":222 + /* "pysam/libctabixproxies.pyx":226 * (max_fields, buffer)) * * pos[0] = '\0' # <<<<<<<<<<<<<< @@ -4290,7 +4603,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ (__pyx_v_pos[0]) = '\x00'; - /* "pysam/libctabixproxies.pyx":223 + /* "pysam/libctabixproxies.pyx":227 * * pos[0] = '\0' * pos += 1 # <<<<<<<<<<<<<< @@ -4299,7 +4612,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_pos = (__pyx_v_pos + 1); - /* "pysam/libctabixproxies.pyx":224 + /* "pysam/libctabixproxies.pyx":228 * pos[0] = '\0' * pos += 1 * self.fields[field] = pos # <<<<<<<<<<<<<< @@ -4308,7 +4621,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ (__pyx_v_self->fields[__pyx_v_field]) = __pyx_v_pos; - /* "pysam/libctabixproxies.pyx":225 + /* "pysam/libctabixproxies.pyx":229 * pos += 1 * self.fields[field] = pos * field += 1 # <<<<<<<<<<<<<< @@ -4317,7 +4630,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_field = (__pyx_v_field + 1); - /* "pysam/libctabixproxies.pyx":226 + /* "pysam/libctabixproxies.pyx":230 * self.fields[field] = pos * field += 1 * nbytes -= pos - old_pos # <<<<<<<<<<<<<< @@ -4326,7 +4639,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_nbytes = (__pyx_v_nbytes - (__pyx_v_pos - __pyx_v_old_pos)); - /* "pysam/libctabixproxies.pyx":227 + /* "pysam/libctabixproxies.pyx":231 * field += 1 * nbytes -= pos - old_pos * if nbytes < 0: # <<<<<<<<<<<<<< @@ -4336,7 +4649,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_4 = ((__pyx_v_nbytes < 0) != 0); if (__pyx_t_4) { - /* "pysam/libctabixproxies.pyx":228 + /* "pysam/libctabixproxies.pyx":232 * nbytes -= pos - old_pos * if nbytes < 0: * break # <<<<<<<<<<<<<< @@ -4345,7 +4658,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ goto __pyx_L19_break; - /* "pysam/libctabixproxies.pyx":227 + /* "pysam/libctabixproxies.pyx":231 * field += 1 * nbytes -= pos - old_pos * if nbytes < 0: # <<<<<<<<<<<<<< @@ -4354,7 +4667,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ } - /* "pysam/libctabixproxies.pyx":229 + /* "pysam/libctabixproxies.pyx":233 * if nbytes < 0: * break * old_pos = pos # <<<<<<<<<<<<<< @@ -4365,7 +4678,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ } __pyx_L19_break:; - /* "pysam/libctabixproxies.pyx":230 + /* "pysam/libctabixproxies.pyx":234 * break * old_pos = pos * self.nfields = field # <<<<<<<<<<<<<< @@ -4374,28 +4687,28 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ */ __pyx_v_self->nfields = __pyx_v_field; - /* "pysam/libctabixproxies.pyx":231 + /* "pysam/libctabixproxies.pyx":235 * old_pos = pos * self.nfields = field * if self.nfields < self.getMinFields(): # <<<<<<<<<<<<<< * raise ValueError( - * "parsing error: fewer that %i fields in line: %s" % + * "parsing error: fewer than %i fields in line: %s" % */ __pyx_t_4 = ((__pyx_v_self->nfields < ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self->__pyx_vtab)->getMinFields(__pyx_v_self, 0)) != 0); if (unlikely(__pyx_t_4)) { - /* "pysam/libctabixproxies.pyx":234 + /* "pysam/libctabixproxies.pyx":238 * raise ValueError( - * "parsing error: fewer that %i fields in line: %s" % + * "parsing error: fewer than %i fields in line: %s" % * (self.getMinFields(), buffer)) # <<<<<<<<<<<<<< * * def _getindex(self, int index): */ - __pyx_t_1 = __Pyx_PyInt_From_int(((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self->__pyx_vtab)->getMinFields(__pyx_v_self, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 234, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(((struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self->__pyx_vtab)->getMinFields(__pyx_v_self, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 238, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 234, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_buffer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 238, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 234, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 238, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); @@ -4404,41 +4717,41 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ __pyx_t_1 = 0; __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":233 + /* "pysam/libctabixproxies.pyx":237 * if self.nfields < self.getMinFields(): * raise ValueError( - * "parsing error: fewer that %i fields in line: %s" % # <<<<<<<<<<<<<< + * "parsing error: fewer than %i fields in line: %s" % # <<<<<<<<<<<<<< * (self.getMinFields(), buffer)) * */ - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_parsing_error_fewer_that_i_field, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 233, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_parsing_error_fewer_than_i_field, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 237, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":232 + /* "pysam/libctabixproxies.pyx":236 * self.nfields = field * if self.nfields < self.getMinFields(): * raise ValueError( # <<<<<<<<<<<<<< - * "parsing error: fewer that %i fields in line: %s" % + * "parsing error: fewer than %i fields in line: %s" % * (self.getMinFields(), buffer)) */ - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 232, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 236, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 232, __pyx_L1_error) + __PYX_ERR(0, 236, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":231 + /* "pysam/libctabixproxies.pyx":235 * old_pos = pos * self.nfields = field * if self.nfields < self.getMinFields(): # <<<<<<<<<<<<<< * raise ValueError( - * "parsing error: fewer that %i fields in line: %s" % + * "parsing error: fewer than %i fields in line: %s" % */ } - /* "pysam/libctabixproxies.pyx":144 + /* "pysam/libctabixproxies.pyx":148 * return 0 * * cdef update(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< @@ -4461,7 +4774,7 @@ static PyObject *__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(struct __ return __pyx_r; } -/* "pysam/libctabixproxies.pyx":236 +/* "pysam/libctabixproxies.pyx":240 * (self.getMinFields(), buffer)) * * def _getindex(self, int index): # <<<<<<<<<<<<<< @@ -4478,7 +4791,7 @@ static PyObject *__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_15_getindex(PyO __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("_getindex (wrapper)", 0); assert(__pyx_arg_index); { - __pyx_v_index = __Pyx_PyInt_As_int(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 236, __pyx_L3_error) + __pyx_v_index = __Pyx_PyInt_As_int(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 240, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -4504,7 +4817,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str struct __pyx_opt_args_5pysam_9libcutils_force_str __pyx_t_5; __Pyx_RefNannySetupContext("_getindex", 0); - /* "pysam/libctabixproxies.pyx":238 + /* "pysam/libctabixproxies.pyx":242 * def _getindex(self, int index): * '''return item at idx index''' * cdef int i = index # <<<<<<<<<<<<<< @@ -4513,7 +4826,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str */ __pyx_v_i = __pyx_v_index; - /* "pysam/libctabixproxies.pyx":239 + /* "pysam/libctabixproxies.pyx":243 * '''return item at idx index''' * cdef int i = index * if i < 0: # <<<<<<<<<<<<<< @@ -4523,7 +4836,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str __pyx_t_1 = ((__pyx_v_i < 0) != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":240 + /* "pysam/libctabixproxies.pyx":244 * cdef int i = index * if i < 0: * i += self.nfields # <<<<<<<<<<<<<< @@ -4532,7 +4845,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str */ __pyx_v_i = (__pyx_v_i + __pyx_v_self->nfields); - /* "pysam/libctabixproxies.pyx":239 + /* "pysam/libctabixproxies.pyx":243 * '''return item at idx index''' * cdef int i = index * if i < 0: # <<<<<<<<<<<<<< @@ -4541,7 +4854,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str */ } - /* "pysam/libctabixproxies.pyx":241 + /* "pysam/libctabixproxies.pyx":245 * if i < 0: * i += self.nfields * if i < 0: # <<<<<<<<<<<<<< @@ -4551,20 +4864,20 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str __pyx_t_1 = ((__pyx_v_i < 0) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabixproxies.pyx":242 + /* "pysam/libctabixproxies.pyx":246 * i += self.nfields * if i < 0: * raise IndexError("list index out of range") # <<<<<<<<<<<<<< * # apply offset - separating a fixed number * # of fields from a variable number such as in VCF */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 242, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 246, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 242, __pyx_L1_error) + __PYX_ERR(0, 246, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":241 + /* "pysam/libctabixproxies.pyx":245 * if i < 0: * i += self.nfields * if i < 0: # <<<<<<<<<<<<<< @@ -4573,7 +4886,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str */ } - /* "pysam/libctabixproxies.pyx":245 + /* "pysam/libctabixproxies.pyx":249 * # apply offset - separating a fixed number * # of fields from a variable number such as in VCF * i += self.offset # <<<<<<<<<<<<<< @@ -4582,7 +4895,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str */ __pyx_v_i = (__pyx_v_i + __pyx_v_self->offset); - /* "pysam/libctabixproxies.pyx":246 + /* "pysam/libctabixproxies.pyx":250 * # of fields from a variable number such as in VCF * i += self.offset * if i >= self.nfields: # <<<<<<<<<<<<<< @@ -4592,18 +4905,18 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str __pyx_t_1 = ((__pyx_v_i >= __pyx_v_self->nfields) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabixproxies.pyx":249 + /* "pysam/libctabixproxies.pyx":253 * raise IndexError( * "list index out of range %i >= %i" % * (i, self.nfields)) # <<<<<<<<<<<<<< * return force_str(self.fields[i], self.encoding) * */ - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 249, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 253, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->nfields); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 249, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->nfields); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 253, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 249, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 253, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); @@ -4612,32 +4925,32 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str __pyx_t_2 = 0; __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":248 + /* "pysam/libctabixproxies.pyx":252 * if i >= self.nfields: * raise IndexError( * "list index out of range %i >= %i" % # <<<<<<<<<<<<<< * (i, self.nfields)) * return force_str(self.fields[i], self.encoding) */ - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_list_index_out_of_range_i_i, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 248, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_list_index_out_of_range_i_i, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 252, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":247 + /* "pysam/libctabixproxies.pyx":251 * i += self.offset * if i >= self.nfields: * raise IndexError( # <<<<<<<<<<<<<< * "list index out of range %i >= %i" % * (i, self.nfields)) */ - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 247, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 251, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 247, __pyx_L1_error) + __PYX_ERR(0, 251, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":246 + /* "pysam/libctabixproxies.pyx":250 * # of fields from a variable number such as in VCF * i += self.offset * if i >= self.nfields: # <<<<<<<<<<<<<< @@ -4646,7 +4959,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str */ } - /* "pysam/libctabixproxies.pyx":250 + /* "pysam/libctabixproxies.pyx":254 * "list index out of range %i >= %i" % * (i, self.nfields)) * return force_str(self.fields[i], self.encoding) # <<<<<<<<<<<<<< @@ -4654,13 +4967,13 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str * def __getitem__(self, key): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyBytes_FromString((__pyx_v_self->fields[__pyx_v_i])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 250, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyBytes_FromString((__pyx_v_self->fields[__pyx_v_i])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 254, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __pyx_v_self->encoding; __Pyx_INCREF(__pyx_t_3); __pyx_t_5.__pyx_n = 1; __pyx_t_5.encoding = __pyx_t_3; - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_4, &__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 250, __pyx_L1_error) + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_4, &__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 254, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -4668,7 +4981,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":236 + /* "pysam/libctabixproxies.pyx":240 * (self.getMinFields(), buffer)) * * def _getindex(self, int index): # <<<<<<<<<<<<<< @@ -4689,7 +5002,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_14_getindex(str return __pyx_r; } -/* "pysam/libctabixproxies.pyx":252 +/* "pysam/libctabixproxies.pyx":256 * return force_str(self.fields[i], self.encoding) * * def __getitem__(self, key): # <<<<<<<<<<<<<< @@ -4730,19 +5043,19 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s int __pyx_t_10; __Pyx_RefNannySetupContext("__getitem__", 0); - /* "pysam/libctabixproxies.pyx":253 + /* "pysam/libctabixproxies.pyx":257 * * def __getitem__(self, key): * if type(key) == int: # <<<<<<<<<<<<<< * return self._getindex(key) * # slice object */ - __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_key)), ((PyObject *)(&PyInt_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 253, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 253, __pyx_L1_error) + __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_key)), ((PyObject *)(&PyInt_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 257, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 257, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "pysam/libctabixproxies.pyx":254 + /* "pysam/libctabixproxies.pyx":258 * def __getitem__(self, key): * if type(key) == int: * return self._getindex(key) # <<<<<<<<<<<<<< @@ -4750,7 +5063,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s * start, end, step = key.indices(self.nfields) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 254, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 258, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { @@ -4763,13 +5076,13 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s } } if (!__pyx_t_4) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 254, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_key}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 254, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -4777,19 +5090,19 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_key}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 254, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 254, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 258, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_INCREF(__pyx_v_key); __Pyx_GIVEREF(__pyx_v_key); PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_key); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 254, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } @@ -4799,7 +5112,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":253 + /* "pysam/libctabixproxies.pyx":257 * * def __getitem__(self, key): * if type(key) == int: # <<<<<<<<<<<<<< @@ -4808,16 +5121,16 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s */ } - /* "pysam/libctabixproxies.pyx":256 + /* "pysam/libctabixproxies.pyx":260 * return self._getindex(key) * # slice object * start, end, step = key.indices(self.nfields) # <<<<<<<<<<<<<< * result = [] * for index in range(start, end, step): */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_key, __pyx_n_s_indices); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 256, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_key, __pyx_n_s_indices); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->nfields); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 256, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->nfields); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { @@ -4830,14 +5143,14 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s } } if (!__pyx_t_4) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 256, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 260, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 256, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 260, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; @@ -4846,20 +5159,20 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 256, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 260, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 256, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_5); __pyx_t_5 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 256, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -4871,7 +5184,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s if (unlikely(size != 3)) { if (size > 3) __Pyx_RaiseTooManyValuesError(3); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 256, __pyx_L1_error) + __PYX_ERR(0, 260, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { @@ -4887,17 +5200,17 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(__pyx_t_5); #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 256, __pyx_L1_error) + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 256, __pyx_L1_error) + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 256, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { Py_ssize_t index = -1; - __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 256, __pyx_L1_error) + __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_7 = Py_TYPE(__pyx_t_4)->tp_iternext; @@ -4907,7 +5220,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s __Pyx_GOTREF(__pyx_t_6); index = 2; __pyx_t_5 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_5)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_4), 3) < 0) __PYX_ERR(0, 256, __pyx_L1_error) + if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_4), 3) < 0) __PYX_ERR(0, 260, __pyx_L1_error) __pyx_t_7 = NULL; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L5_unpacking_done; @@ -4915,7 +5228,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_7 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 256, __pyx_L1_error) + __PYX_ERR(0, 260, __pyx_L1_error) __pyx_L5_unpacking_done:; } __pyx_v_start = __pyx_t_3; @@ -4925,26 +5238,26 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s __pyx_v_step = __pyx_t_5; __pyx_t_5 = 0; - /* "pysam/libctabixproxies.pyx":257 + /* "pysam/libctabixproxies.pyx":261 * # slice object * start, end, step = key.indices(self.nfields) * result = [] # <<<<<<<<<<<<<< * for index in range(start, end, step): * result.append(self._getindex(index)) */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 257, __pyx_L1_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 261, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":258 + /* "pysam/libctabixproxies.pyx":262 * start, end, step = key.indices(self.nfields) * result = [] * for index in range(start, end, step): # <<<<<<<<<<<<<< * result.append(self._getindex(index)) * return result */ - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 262, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_start); __Pyx_GIVEREF(__pyx_v_start); @@ -4955,16 +5268,16 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s __Pyx_INCREF(__pyx_v_step); __Pyx_GIVEREF(__pyx_v_step); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_step); - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 262, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) { __pyx_t_1 = __pyx_t_5; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; __pyx_t_9 = NULL; } else { - __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 262, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 262, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; for (;;) { @@ -4972,17 +5285,17 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_5); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_5); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 262, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 262, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif } else { if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_5); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_5); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 262, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 258, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 262, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif } @@ -4992,7 +5305,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 258, __pyx_L1_error) + else __PYX_ERR(0, 262, __pyx_L1_error) } break; } @@ -5001,14 +5314,14 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libctabixproxies.pyx":259 + /* "pysam/libctabixproxies.pyx":263 * result = [] * for index in range(start, end, step): * result.append(self._getindex(index)) # <<<<<<<<<<<<<< * return result * */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 259, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 263, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { @@ -5021,13 +5334,13 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s } } if (!__pyx_t_3) { - __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 259, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 263, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_6)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_index}; - __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 259, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 263, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_5); } else @@ -5035,28 +5348,28 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_index}; - __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 259, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 263, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_5); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 259, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 263, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_index); __Pyx_GIVEREF(__pyx_v_index); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_index); - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 259, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 263, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } } __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_5); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 259, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_5); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 263, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libctabixproxies.pyx":258 + /* "pysam/libctabixproxies.pyx":262 * start, end, step = key.indices(self.nfields) * result = [] * for index in range(start, end, step): # <<<<<<<<<<<<<< @@ -5066,7 +5379,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":260 + /* "pysam/libctabixproxies.pyx":264 * for index in range(start, end, step): * result.append(self._getindex(index)) * return result # <<<<<<<<<<<<<< @@ -5078,7 +5391,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s __pyx_r = __pyx_v_result; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":252 + /* "pysam/libctabixproxies.pyx":256 * return force_str(self.fields[i], self.encoding) * * def __getitem__(self, key): # <<<<<<<<<<<<<< @@ -5106,7 +5419,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_16__getitem__(s return __pyx_r; } -/* "pysam/libctabixproxies.pyx":262 +/* "pysam/libctabixproxies.pyx":266 * return result * * def _setindex(self, index, value): # <<<<<<<<<<<<<< @@ -5146,11 +5459,11 @@ static PyObject *__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_19_setindex(PyO case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_setindex", 1, 2, 2, 1); __PYX_ERR(0, 262, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_setindex", 1, 2, 2, 1); __PYX_ERR(0, 266, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_setindex") < 0)) __PYX_ERR(0, 262, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_setindex") < 0)) __PYX_ERR(0, 266, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -5163,7 +5476,7 @@ static PyObject *__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_19_setindex(PyO } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_setindex", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 262, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_setindex", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 266, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libctabixproxies.TupleProxy._setindex", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -5189,17 +5502,17 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str __Pyx_RefNannySetupContext("_setindex", 0); __Pyx_INCREF(__pyx_v_value); - /* "pysam/libctabixproxies.pyx":264 + /* "pysam/libctabixproxies.pyx":268 * def _setindex(self, index, value): * '''set item at idx index.''' * cdef int idx = index # <<<<<<<<<<<<<< * if idx < 0: * raise IndexError("list index out of range") */ - __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_index); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 264, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_index); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 268, __pyx_L1_error) __pyx_v_idx = __pyx_t_1; - /* "pysam/libctabixproxies.pyx":265 + /* "pysam/libctabixproxies.pyx":269 * '''set item at idx index.''' * cdef int idx = index * if idx < 0: # <<<<<<<<<<<<<< @@ -5209,20 +5522,20 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str __pyx_t_2 = ((__pyx_v_idx < 0) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libctabixproxies.pyx":266 + /* "pysam/libctabixproxies.pyx":270 * cdef int idx = index * if idx < 0: * raise IndexError("list index out of range") # <<<<<<<<<<<<<< * if idx >= self.nfields: * raise IndexError("list index out of range") */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 266, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 266, __pyx_L1_error) + __PYX_ERR(0, 270, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":265 + /* "pysam/libctabixproxies.pyx":269 * '''set item at idx index.''' * cdef int idx = index * if idx < 0: # <<<<<<<<<<<<<< @@ -5231,7 +5544,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str */ } - /* "pysam/libctabixproxies.pyx":267 + /* "pysam/libctabixproxies.pyx":271 * if idx < 0: * raise IndexError("list index out of range") * if idx >= self.nfields: # <<<<<<<<<<<<<< @@ -5241,20 +5554,20 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str __pyx_t_2 = ((__pyx_v_idx >= __pyx_v_self->nfields) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libctabixproxies.pyx":268 + /* "pysam/libctabixproxies.pyx":272 * raise IndexError("list index out of range") * if idx >= self.nfields: * raise IndexError("list index out of range") # <<<<<<<<<<<<<< * * if isNew(self.fields[idx], self.data, self.nbytes): */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 268, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 272, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 268, __pyx_L1_error) + __PYX_ERR(0, 272, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":267 + /* "pysam/libctabixproxies.pyx":271 * if idx < 0: * raise IndexError("list index out of range") * if idx >= self.nfields: # <<<<<<<<<<<<<< @@ -5263,36 +5576,36 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str */ } - /* "pysam/libctabixproxies.pyx":270 + /* "pysam/libctabixproxies.pyx":274 * raise IndexError("list index out of range") * * if isNew(self.fields[idx], self.data, self.nbytes): # <<<<<<<<<<<<<< - * free(self.fields[idx] ) + * free(self.fields[idx]) * */ __pyx_t_2 = (__pyx_f_5pysam_16libctabixproxies_isNew((__pyx_v_self->fields[__pyx_v_idx]), __pyx_v_self->data, __pyx_v_self->nbytes) != 0); if (__pyx_t_2) { - /* "pysam/libctabixproxies.pyx":271 + /* "pysam/libctabixproxies.pyx":275 * * if isNew(self.fields[idx], self.data, self.nbytes): - * free(self.fields[idx] ) # <<<<<<<<<<<<<< + * free(self.fields[idx]) # <<<<<<<<<<<<<< * * self.is_modified = 1 */ free((__pyx_v_self->fields[__pyx_v_idx])); - /* "pysam/libctabixproxies.pyx":270 + /* "pysam/libctabixproxies.pyx":274 * raise IndexError("list index out of range") * * if isNew(self.fields[idx], self.data, self.nbytes): # <<<<<<<<<<<<<< - * free(self.fields[idx] ) + * free(self.fields[idx]) * */ } - /* "pysam/libctabixproxies.pyx":273 - * free(self.fields[idx] ) + /* "pysam/libctabixproxies.pyx":277 + * free(self.fields[idx]) * * self.is_modified = 1 # <<<<<<<<<<<<<< * @@ -5300,7 +5613,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str */ __pyx_v_self->is_modified = 1; - /* "pysam/libctabixproxies.pyx":275 + /* "pysam/libctabixproxies.pyx":279 * self.is_modified = 1 * * if value is None: # <<<<<<<<<<<<<< @@ -5311,7 +5624,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str __pyx_t_4 = (__pyx_t_2 != 0); if (__pyx_t_4) { - /* "pysam/libctabixproxies.pyx":276 + /* "pysam/libctabixproxies.pyx":280 * * if value is None: * self.fields[idx] = NULL # <<<<<<<<<<<<<< @@ -5320,7 +5633,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str */ (__pyx_v_self->fields[__pyx_v_idx]) = NULL; - /* "pysam/libctabixproxies.pyx":277 + /* "pysam/libctabixproxies.pyx":281 * if value is None: * self.fields[idx] = NULL * return # <<<<<<<<<<<<<< @@ -5331,7 +5644,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":275 + /* "pysam/libctabixproxies.pyx":279 * self.is_modified = 1 * * if value is None: # <<<<<<<<<<<<<< @@ -5340,29 +5653,29 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str */ } - /* "pysam/libctabixproxies.pyx":280 + /* "pysam/libctabixproxies.pyx":284 * * # conversion with error checking * value = force_bytes(value) # <<<<<<<<<<<<<< * cdef char * tmp = value * self.fields[idx] = malloc((strlen( tmp ) + 1) * sizeof(char)) */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 280, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":281 + /* "pysam/libctabixproxies.pyx":285 * # conversion with error checking * value = force_bytes(value) * cdef char * tmp = value # <<<<<<<<<<<<<< * self.fields[idx] = malloc((strlen( tmp ) + 1) * sizeof(char)) * if self.fields[idx] == NULL: */ - __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_value); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 281, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_value); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 285, __pyx_L1_error) __pyx_v_tmp = ((char *)__pyx_t_5); - /* "pysam/libctabixproxies.pyx":282 + /* "pysam/libctabixproxies.pyx":286 * value = force_bytes(value) * cdef char * tmp = value * self.fields[idx] = malloc((strlen( tmp ) + 1) * sizeof(char)) # <<<<<<<<<<<<<< @@ -5371,7 +5684,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str */ (__pyx_v_self->fields[__pyx_v_idx]) = ((char *)malloc(((strlen(__pyx_v_tmp) + 1) * (sizeof(char))))); - /* "pysam/libctabixproxies.pyx":283 + /* "pysam/libctabixproxies.pyx":287 * cdef char * tmp = value * self.fields[idx] = malloc((strlen( tmp ) + 1) * sizeof(char)) * if self.fields[idx] == NULL: # <<<<<<<<<<<<<< @@ -5381,20 +5694,20 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str __pyx_t_4 = (((__pyx_v_self->fields[__pyx_v_idx]) == NULL) != 0); if (unlikely(__pyx_t_4)) { - /* "pysam/libctabixproxies.pyx":284 + /* "pysam/libctabixproxies.pyx":288 * self.fields[idx] = malloc((strlen( tmp ) + 1) * sizeof(char)) * if self.fields[idx] == NULL: * raise ValueError("out of memory" ) # <<<<<<<<<<<<<< * strcpy(self.fields[idx], tmp) * */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 288, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 284, __pyx_L1_error) + __PYX_ERR(0, 288, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":283 + /* "pysam/libctabixproxies.pyx":287 * cdef char * tmp = value * self.fields[idx] = malloc((strlen( tmp ) + 1) * sizeof(char)) * if self.fields[idx] == NULL: # <<<<<<<<<<<<<< @@ -5403,7 +5716,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str */ } - /* "pysam/libctabixproxies.pyx":285 + /* "pysam/libctabixproxies.pyx":289 * if self.fields[idx] == NULL: * raise ValueError("out of memory" ) * strcpy(self.fields[idx], tmp) # <<<<<<<<<<<<<< @@ -5412,7 +5725,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str */ (void)(strcpy((__pyx_v_self->fields[__pyx_v_idx]), __pyx_v_tmp)); - /* "pysam/libctabixproxies.pyx":262 + /* "pysam/libctabixproxies.pyx":266 * return result * * def _setindex(self, index, value): # <<<<<<<<<<<<<< @@ -5434,7 +5747,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_18_setindex(str return __pyx_r; } -/* "pysam/libctabixproxies.pyx":287 +/* "pysam/libctabixproxies.pyx":291 * strcpy(self.fields[idx], tmp) * * def __setitem__(self, index, value): # <<<<<<<<<<<<<< @@ -5472,17 +5785,17 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_20__setitem__(struct PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("__setitem__", 0); - /* "pysam/libctabixproxies.pyx":289 + /* "pysam/libctabixproxies.pyx":293 * def __setitem__(self, index, value): * '''set item at *index* to *value*''' * cdef int i = index # <<<<<<<<<<<<<< * if i < 0: * i += self.nfields */ - __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_index); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 289, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_index); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 293, __pyx_L1_error) __pyx_v_i = __pyx_t_1; - /* "pysam/libctabixproxies.pyx":290 + /* "pysam/libctabixproxies.pyx":294 * '''set item at *index* to *value*''' * cdef int i = index * if i < 0: # <<<<<<<<<<<<<< @@ -5492,7 +5805,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_20__setitem__(struct __pyx_t_2 = ((__pyx_v_i < 0) != 0); if (__pyx_t_2) { - /* "pysam/libctabixproxies.pyx":291 + /* "pysam/libctabixproxies.pyx":295 * cdef int i = index * if i < 0: * i += self.nfields # <<<<<<<<<<<<<< @@ -5501,7 +5814,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_20__setitem__(struct */ __pyx_v_i = (__pyx_v_i + __pyx_v_self->nfields); - /* "pysam/libctabixproxies.pyx":290 + /* "pysam/libctabixproxies.pyx":294 * '''set item at *index* to *value*''' * cdef int i = index * if i < 0: # <<<<<<<<<<<<<< @@ -5510,7 +5823,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_20__setitem__(struct */ } - /* "pysam/libctabixproxies.pyx":292 + /* "pysam/libctabixproxies.pyx":296 * if i < 0: * i += self.nfields * i += self.offset # <<<<<<<<<<<<<< @@ -5519,16 +5832,16 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_20__setitem__(struct */ __pyx_v_i = (__pyx_v_i + __pyx_v_self->offset); - /* "pysam/libctabixproxies.pyx":294 + /* "pysam/libctabixproxies.pyx":298 * i += self.offset * * self._setindex(i, value) # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setindex); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 294, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setindex); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 298, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 294, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 298, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = NULL; __pyx_t_1 = 0; @@ -5545,7 +5858,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_20__setitem__(struct #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_v_value}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_1, 2+__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 294, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_1, 2+__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 298, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; @@ -5554,14 +5867,14 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_20__setitem__(struct #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_v_value}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_1, 2+__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 294, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_1, 2+__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 298, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { - __pyx_t_7 = PyTuple_New(2+__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 294, __pyx_L1_error) + __pyx_t_7 = PyTuple_New(2+__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 298, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); if (__pyx_t_6) { __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; @@ -5572,14 +5885,14 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_20__setitem__(struct __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_1, __pyx_v_value); __pyx_t_5 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 294, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 298, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":287 + /* "pysam/libctabixproxies.pyx":291 * strcpy(self.fields[idx], tmp) * * def __setitem__(self, index, value): # <<<<<<<<<<<<<< @@ -5603,7 +5916,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_20__setitem__(struct return __pyx_r; } -/* "pysam/libctabixproxies.pyx":296 +/* "pysam/libctabixproxies.pyx":300 * self._setindex(i, value) * * def __len__(self): # <<<<<<<<<<<<<< @@ -5629,7 +5942,7 @@ static Py_ssize_t __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_22__len__(stru __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__", 0); - /* "pysam/libctabixproxies.pyx":297 + /* "pysam/libctabixproxies.pyx":301 * * def __len__(self): * return self.nfields # <<<<<<<<<<<<<< @@ -5639,7 +5952,7 @@ static Py_ssize_t __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_22__len__(stru __pyx_r = __pyx_v_self->nfields; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":296 + /* "pysam/libctabixproxies.pyx":300 * self._setindex(i, value) * * def __len__(self): # <<<<<<<<<<<<<< @@ -5653,7 +5966,7 @@ static Py_ssize_t __pyx_pf_5pysam_16libctabixproxies_10TupleProxy_22__len__(stru return __pyx_r; } -/* "pysam/libctabixproxies.pyx":299 +/* "pysam/libctabixproxies.pyx":303 * return self.nfields * * def __iter__(self): # <<<<<<<<<<<<<< @@ -5679,7 +5992,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_24__iter__(stru __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__", 0); - /* "pysam/libctabixproxies.pyx":300 + /* "pysam/libctabixproxies.pyx":304 * * def __iter__(self): * self.index = 0 # <<<<<<<<<<<<<< @@ -5688,7 +6001,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_24__iter__(stru */ __pyx_v_self->index = 0; - /* "pysam/libctabixproxies.pyx":301 + /* "pysam/libctabixproxies.pyx":305 * def __iter__(self): * self.index = 0 * return self # <<<<<<<<<<<<<< @@ -5700,7 +6013,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_24__iter__(stru __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":299 + /* "pysam/libctabixproxies.pyx":303 * return self.nfields * * def __iter__(self): # <<<<<<<<<<<<<< @@ -5715,7 +6028,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_24__iter__(stru return __pyx_r; } -/* "pysam/libctabixproxies.pyx":303 +/* "pysam/libctabixproxies.pyx":307 * return self * * def __next__(self): # <<<<<<<<<<<<<< @@ -5751,7 +6064,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_26__next__(stru struct __pyx_opt_args_5pysam_9libcutils_force_str __pyx_t_5; __Pyx_RefNannySetupContext("__next__", 0); - /* "pysam/libctabixproxies.pyx":306 + /* "pysam/libctabixproxies.pyx":310 * """python version of next(). * """ * if self.index >= self.nfields: # <<<<<<<<<<<<<< @@ -5761,7 +6074,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_26__next__(stru __pyx_t_1 = ((__pyx_v_self->index >= __pyx_v_self->nfields) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabixproxies.pyx":307 + /* "pysam/libctabixproxies.pyx":311 * """ * if self.index >= self.nfields: * raise StopIteration # <<<<<<<<<<<<<< @@ -5769,9 +6082,9 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_26__next__(stru * self.index += 1 */ __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0); - __PYX_ERR(0, 307, __pyx_L1_error) + __PYX_ERR(0, 311, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":306 + /* "pysam/libctabixproxies.pyx":310 * """python version of next(). * """ * if self.index >= self.nfields: # <<<<<<<<<<<<<< @@ -5780,7 +6093,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_26__next__(stru */ } - /* "pysam/libctabixproxies.pyx":308 + /* "pysam/libctabixproxies.pyx":312 * if self.index >= self.nfields: * raise StopIteration * cdef char * retval = self.fields[self.index] # <<<<<<<<<<<<<< @@ -5789,7 +6102,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_26__next__(stru */ __pyx_v_retval = (__pyx_v_self->fields[__pyx_v_self->index]); - /* "pysam/libctabixproxies.pyx":309 + /* "pysam/libctabixproxies.pyx":313 * raise StopIteration * cdef char * retval = self.fields[self.index] * self.index += 1 # <<<<<<<<<<<<<< @@ -5798,7 +6111,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_26__next__(stru */ __pyx_v_self->index = (__pyx_v_self->index + 1); - /* "pysam/libctabixproxies.pyx":310 + /* "pysam/libctabixproxies.pyx":314 * cdef char * retval = self.fields[self.index] * self.index += 1 * if retval == NULL: # <<<<<<<<<<<<<< @@ -5808,7 +6121,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_26__next__(stru __pyx_t_1 = ((__pyx_v_retval == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":311 + /* "pysam/libctabixproxies.pyx":315 * self.index += 1 * if retval == NULL: * return None # <<<<<<<<<<<<<< @@ -5819,7 +6132,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_26__next__(stru __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":310 + /* "pysam/libctabixproxies.pyx":314 * cdef char * retval = self.fields[self.index] * self.index += 1 * if retval == NULL: # <<<<<<<<<<<<<< @@ -5828,7 +6141,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_26__next__(stru */ } - /* "pysam/libctabixproxies.pyx":313 + /* "pysam/libctabixproxies.pyx":317 * return None * else: * return force_str(retval, self.encoding) # <<<<<<<<<<<<<< @@ -5837,13 +6150,13 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_26__next__(stru */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_retval); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 313, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_retval); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 317, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_v_self->encoding; __Pyx_INCREF(__pyx_t_3); __pyx_t_5.__pyx_n = 1; __pyx_t_5.encoding = __pyx_t_3; - __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_2, &__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 313, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_2, &__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 317, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -5852,7 +6165,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_26__next__(stru goto __pyx_L0; } - /* "pysam/libctabixproxies.pyx":303 + /* "pysam/libctabixproxies.pyx":307 * return self * * def __next__(self): # <<<<<<<<<<<<<< @@ -5873,7 +6186,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_26__next__(stru return __pyx_r; } -/* "pysam/libctabixproxies.pyx":315 +/* "pysam/libctabixproxies.pyx":319 * return force_str(retval, self.encoding) * * def __str__(self): # <<<<<<<<<<<<<< @@ -5916,7 +6229,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc int __pyx_t_9; __Pyx_RefNannySetupContext("__str__", 0); - /* "pysam/libctabixproxies.pyx":319 + /* "pysam/libctabixproxies.pyx":323 * # copy and replace \0 bytes with \t characters * cdef char * cpy * if self.is_modified: # <<<<<<<<<<<<<< @@ -5926,19 +6239,19 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc __pyx_t_1 = (__pyx_v_self->is_modified != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":321 + /* "pysam/libctabixproxies.pyx":325 * if self.is_modified: * # todo: treat NULL values * result = [] # <<<<<<<<<<<<<< * for x in xrange(0, self.nfields): * result.append(StrOrEmpty(self.fields[x]).decode(self.encoding)) */ - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error) + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 325, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_result = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":322 + /* "pysam/libctabixproxies.pyx":326 * # todo: treat NULL values * result = [] * for x in xrange(0, self.nfields): # <<<<<<<<<<<<<< @@ -5950,16 +6263,16 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_v_x = __pyx_t_5; - /* "pysam/libctabixproxies.pyx":323 + /* "pysam/libctabixproxies.pyx":327 * result = [] * for x in xrange(0, self.nfields): * result.append(StrOrEmpty(self.fields[x]).decode(self.encoding)) # <<<<<<<<<<<<<< * return "\t".join(result) * else: */ - __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_f_5pysam_16libctabixproxies_StrOrEmpty((__pyx_v_self->fields[__pyx_v_x]))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 323, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_f_5pysam_16libctabixproxies_StrOrEmpty((__pyx_v_self->fields[__pyx_v_x]))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 327, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_decode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 323, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_decode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 327, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = NULL; @@ -5973,13 +6286,13 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc } } if (!__pyx_t_6) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_self->encoding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 323, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_self->encoding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 327, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_self->encoding}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 323, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 327, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); } else @@ -5987,29 +6300,29 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_self->encoding}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 323, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 327, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 323, __pyx_L1_error) + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 327, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v_self->encoding); __Pyx_GIVEREF(__pyx_v_self->encoding); PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_self->encoding); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 323, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 327, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } } __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_9 = __Pyx_PyObject_Append(__pyx_v_result, __pyx_t_2); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 323, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_Append(__pyx_v_result, __pyx_t_2); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 327, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } - /* "pysam/libctabixproxies.pyx":324 + /* "pysam/libctabixproxies.pyx":328 * for x in xrange(0, self.nfields): * result.append(StrOrEmpty(self.fields[x]).decode(self.encoding)) * return "\t".join(result) # <<<<<<<<<<<<<< @@ -6017,13 +6330,13 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc * cpy = calloc(sizeof(char), self.nbytes+1) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__9, __pyx_v_result); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 324, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__9, __pyx_v_result); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 328, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":319 + /* "pysam/libctabixproxies.pyx":323 * # copy and replace \0 bytes with \t characters * cdef char * cpy * if self.is_modified: # <<<<<<<<<<<<<< @@ -6032,7 +6345,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc */ } - /* "pysam/libctabixproxies.pyx":326 + /* "pysam/libctabixproxies.pyx":330 * return "\t".join(result) * else: * cpy = calloc(sizeof(char), self.nbytes+1) # <<<<<<<<<<<<<< @@ -6042,7 +6355,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc /*else*/ { __pyx_v_cpy = ((char *)calloc((sizeof(char)), (__pyx_v_self->nbytes + 1))); - /* "pysam/libctabixproxies.pyx":327 + /* "pysam/libctabixproxies.pyx":331 * else: * cpy = calloc(sizeof(char), self.nbytes+1) * if cpy == NULL: # <<<<<<<<<<<<<< @@ -6052,20 +6365,20 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc __pyx_t_1 = ((__pyx_v_cpy == NULL) != 0); if (unlikely(__pyx_t_1)) { - /* "pysam/libctabixproxies.pyx":328 + /* "pysam/libctabixproxies.pyx":332 * cpy = calloc(sizeof(char), self.nbytes+1) * if cpy == NULL: * raise ValueError("out of memory") # <<<<<<<<<<<<<< * memcpy(cpy, self.data, self.nbytes+1) * for x from 0 <= x < self.nbytes: */ - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 328, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 328, __pyx_L1_error) + __PYX_ERR(0, 332, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":327 + /* "pysam/libctabixproxies.pyx":331 * else: * cpy = calloc(sizeof(char), self.nbytes+1) * if cpy == NULL: # <<<<<<<<<<<<<< @@ -6074,7 +6387,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc */ } - /* "pysam/libctabixproxies.pyx":329 + /* "pysam/libctabixproxies.pyx":333 * if cpy == NULL: * raise ValueError("out of memory") * memcpy(cpy, self.data, self.nbytes+1) # <<<<<<<<<<<<<< @@ -6083,7 +6396,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc */ (void)(memcpy(__pyx_v_cpy, __pyx_v_self->data, (__pyx_v_self->nbytes + 1))); - /* "pysam/libctabixproxies.pyx":330 + /* "pysam/libctabixproxies.pyx":334 * raise ValueError("out of memory") * memcpy(cpy, self.data, self.nbytes+1) * for x from 0 <= x < self.nbytes: # <<<<<<<<<<<<<< @@ -6093,7 +6406,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc __pyx_t_3 = __pyx_v_self->nbytes; for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) { - /* "pysam/libctabixproxies.pyx":331 + /* "pysam/libctabixproxies.pyx":335 * memcpy(cpy, self.data, self.nbytes+1) * for x from 0 <= x < self.nbytes: * if cpy[x] == '\0': # <<<<<<<<<<<<<< @@ -6103,7 +6416,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc __pyx_t_1 = (((__pyx_v_cpy[__pyx_v_x]) == '\x00') != 0); if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":332 + /* "pysam/libctabixproxies.pyx":336 * for x from 0 <= x < self.nbytes: * if cpy[x] == '\0': * cpy[x] = '\t' # <<<<<<<<<<<<<< @@ -6112,7 +6425,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc */ (__pyx_v_cpy[__pyx_v_x]) = '\t'; - /* "pysam/libctabixproxies.pyx":331 + /* "pysam/libctabixproxies.pyx":335 * memcpy(cpy, self.data, self.nbytes+1) * for x from 0 <= x < self.nbytes: * if cpy[x] == '\0': # <<<<<<<<<<<<<< @@ -6122,19 +6435,19 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc } } - /* "pysam/libctabixproxies.pyx":333 + /* "pysam/libctabixproxies.pyx":337 * if cpy[x] == '\0': * cpy[x] = '\t' * result = cpy[:self.nbytes] # <<<<<<<<<<<<<< * free(cpy) * r = result.decode(self.encoding) */ - __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_cpy + 0, __pyx_v_self->nbytes - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 333, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_cpy + 0, __pyx_v_self->nbytes - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 337, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_result = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":334 + /* "pysam/libctabixproxies.pyx":338 * cpy[x] = '\t' * result = cpy[:self.nbytes] * free(cpy) # <<<<<<<<<<<<<< @@ -6143,14 +6456,14 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc */ free(__pyx_v_cpy); - /* "pysam/libctabixproxies.pyx":335 + /* "pysam/libctabixproxies.pyx":339 * result = cpy[:self.nbytes] * free(cpy) * r = result.decode(self.encoding) # <<<<<<<<<<<<<< * return r * */ - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_result, __pyx_n_s_decode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 335, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_result, __pyx_n_s_decode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 339, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { @@ -6163,13 +6476,13 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc } } if (!__pyx_t_8) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_self->encoding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 335, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_self->encoding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_self->encoding}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 335, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_2); } else @@ -6177,19 +6490,19 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_v_self->encoding}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 335, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 335, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 339, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8); __pyx_t_8 = NULL; __Pyx_INCREF(__pyx_v_self->encoding); __Pyx_GIVEREF(__pyx_v_self->encoding); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_self->encoding); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 335, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -6198,7 +6511,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc __pyx_v_r = __pyx_t_2; __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":336 + /* "pysam/libctabixproxies.pyx":340 * free(cpy) * r = result.decode(self.encoding) * return r # <<<<<<<<<<<<<< @@ -6211,7 +6524,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_28__str__(struc goto __pyx_L0; } - /* "pysam/libctabixproxies.pyx":315 + /* "pysam/libctabixproxies.pyx":319 * return force_str(retval, self.encoding) * * def __str__(self): # <<<<<<<<<<<<<< @@ -6342,7 +6655,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_10TupleProxy_32__setstate_cy return __pyx_r; } -/* "pysam/libctabixproxies.pyx":338 +/* "pysam/libctabixproxies.pyx":342 * return r * * def toDot(v): # <<<<<<<<<<<<<< @@ -6373,7 +6686,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_toDot(CYTHON_UNUSED PyObject PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("toDot", 0); - /* "pysam/libctabixproxies.pyx":340 + /* "pysam/libctabixproxies.pyx":344 * def toDot(v): * '''convert value to '.' if None''' * if v is None: # <<<<<<<<<<<<<< @@ -6384,7 +6697,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_toDot(CYTHON_UNUSED PyObject __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libctabixproxies.pyx":341 + /* "pysam/libctabixproxies.pyx":345 * '''convert value to '.' if None''' * if v is None: * return "." # <<<<<<<<<<<<<< @@ -6396,7 +6709,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_toDot(CYTHON_UNUSED PyObject __pyx_r = __pyx_kp_s__13; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":340 + /* "pysam/libctabixproxies.pyx":344 * def toDot(v): * '''convert value to '.' if None''' * if v is None: # <<<<<<<<<<<<<< @@ -6405,7 +6718,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_toDot(CYTHON_UNUSED PyObject */ } - /* "pysam/libctabixproxies.pyx":343 + /* "pysam/libctabixproxies.pyx":347 * return "." * else: * return str(v) # <<<<<<<<<<<<<< @@ -6414,14 +6727,14 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_toDot(CYTHON_UNUSED PyObject */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_v); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 343, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_v); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 347, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; } - /* "pysam/libctabixproxies.pyx":338 + /* "pysam/libctabixproxies.pyx":342 * return r * * def toDot(v): # <<<<<<<<<<<<<< @@ -6440,7 +6753,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_toDot(CYTHON_UNUSED PyObject return __pyx_r; } -/* "pysam/libctabixproxies.pyx":345 +/* "pysam/libctabixproxies.pyx":349 * return str(v) * * def quote(v): # <<<<<<<<<<<<<< @@ -6471,7 +6784,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_2quote(CYTHON_UNUSED PyObjec PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("quote", 0); - /* "pysam/libctabixproxies.pyx":347 + /* "pysam/libctabixproxies.pyx":351 * def quote(v): * '''return a quoted attribute.''' * if isinstance(v, str): # <<<<<<<<<<<<<< @@ -6482,7 +6795,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_2quote(CYTHON_UNUSED PyObjec __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libctabixproxies.pyx":348 + /* "pysam/libctabixproxies.pyx":352 * '''return a quoted attribute.''' * if isinstance(v, str): * return '"%s"' % v # <<<<<<<<<<<<<< @@ -6490,13 +6803,13 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_2quote(CYTHON_UNUSED PyObjec * return str(v) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_v_v); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 348, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_v_v); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 352, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":347 + /* "pysam/libctabixproxies.pyx":351 * def quote(v): * '''return a quoted attribute.''' * if isinstance(v, str): # <<<<<<<<<<<<<< @@ -6505,7 +6818,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_2quote(CYTHON_UNUSED PyObjec */ } - /* "pysam/libctabixproxies.pyx":350 + /* "pysam/libctabixproxies.pyx":354 * return '"%s"' % v * else: * return str(v) # <<<<<<<<<<<<<< @@ -6514,14 +6827,14 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_2quote(CYTHON_UNUSED PyObjec */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_v); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 350, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_v); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 354, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; } - /* "pysam/libctabixproxies.pyx":345 + /* "pysam/libctabixproxies.pyx":349 * return str(v) * * def quote(v): # <<<<<<<<<<<<<< @@ -6540,816 +6853,985 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_2quote(CYTHON_UNUSED PyObjec return __pyx_r; } -/* "pysam/libctabixproxies.pyx":366 - * ''' +/* "pysam/libctabixproxies.pyx":361 + * map_key2field = {} * - * def __cinit__(self): # <<<<<<<<<<<<<< - * # automatically calls TupleProxy.__cinit__ - * self.hasOwnAttributes = False + * def __setattr__(self, key, value): # <<<<<<<<<<<<<< + * '''set attribute.''' + * cdef int idx */ /* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} - if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy___cinit__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy___cinit__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { +static int __pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_1__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__[] = "set attribute."; +#if CYTHON_COMPILING_IN_CPYTHON +struct wrapperbase __pyx_wrapperbase_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__; +#endif +static int __pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_1__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "pysam/libctabixproxies.pyx":368 - * def __cinit__(self): - * # automatically calls TupleProxy.__cinit__ - * self.hasOwnAttributes = False # <<<<<<<<<<<<<< - * self._attributes = NULL - * - */ - __pyx_v_self->hasOwnAttributes = 0; - - /* "pysam/libctabixproxies.pyx":369 - * # automatically calls TupleProxy.__cinit__ - * self.hasOwnAttributes = False - * self._attributes = NULL # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_v_self->_attributes = NULL; - - /* "pysam/libctabixproxies.pyx":366 - * ''' - * - * def __cinit__(self): # <<<<<<<<<<<<<< - * # automatically calls TupleProxy.__cinit__ - * self.hasOwnAttributes = False - */ + __Pyx_RefNannySetupContext("__setattr__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__(((struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *)__pyx_v_self), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_value)); /* function exit code */ - __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":371 - * self._attributes = NULL - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * # automatically calls TupleProxy.__dealloc__ - * if self.hasOwnAttributes: - */ - -/* Python wrapper */ -static void __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_2__dealloc__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -static void __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_2__dealloc__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "pysam/libctabixproxies.pyx":373 - * def __dealloc__(self): - * # automatically calls TupleProxy.__dealloc__ - * if self.hasOwnAttributes: # <<<<<<<<<<<<<< - * free(self._attributes) - * - */ - __pyx_t_1 = (__pyx_v_self->hasOwnAttributes != 0); - if (__pyx_t_1) { - - /* "pysam/libctabixproxies.pyx":374 - * # automatically calls TupleProxy.__dealloc__ - * if self.hasOwnAttributes: - * free(self._attributes) # <<<<<<<<<<<<<< - * - * cpdef int getMinFields(self): - */ - free(__pyx_v_self->_attributes); - - /* "pysam/libctabixproxies.pyx":373 - * def __dealloc__(self): - * # automatically calls TupleProxy.__dealloc__ - * if self.hasOwnAttributes: # <<<<<<<<<<<<<< - * free(self._attributes) - * - */ - } - - /* "pysam/libctabixproxies.pyx":371 - * self._attributes = NULL - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * # automatically calls TupleProxy.__dealloc__ - * if self.hasOwnAttributes: - */ - - /* function exit code */ - __Pyx_RefNannyFinishContext(); -} - -/* "pysam/libctabixproxies.pyx":376 - * free(self._attributes) - * - * cpdef int getMinFields(self): # <<<<<<<<<<<<<< - * '''return minimum number of fields.''' - * return 9 - */ - -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5getMinFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static int __pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMinFields(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, int __pyx_skip_dispatch) { +static int __pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { + int __pyx_v_idx; + CYTHON_UNUSED PyObject *__pyx_v_f = NULL; int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - __Pyx_RefNannySetupContext("getMinFields", 0); - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getMinFields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 376, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5getMinFields)) { - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 376, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 376, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 376, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_5; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; + PyObject *(*__pyx_t_5)(PyObject *); + int __pyx_t_6; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("__setattr__", 0); + + /* "pysam/libctabixproxies.pyx":364 + * '''set attribute.''' + * cdef int idx + * idx, f = self.map_key2field[key] # <<<<<<<<<<<<<< + * if self.nfields < idx: + * raise KeyError("field %s not set" % key) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_map_key2field); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 364, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 364, __pyx_L1_error) } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 364, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 364, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_3 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) __PYX_ERR(0, 364, __pyx_L1_error) + __pyx_t_5 = NULL; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L4_unpacking_done; + __pyx_L3_unpacking_failed:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 364, __pyx_L1_error) + __pyx_L4_unpacking_done:; } + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 364, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_idx = __pyx_t_6; + __pyx_v_f = __pyx_t_3; + __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":378 - * cpdef int getMinFields(self): - * '''return minimum number of fields.''' - * return 9 # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":365 + * cdef int idx + * idx, f = self.map_key2field[key] + * if self.nfields < idx: # <<<<<<<<<<<<<< + * raise KeyError("field %s not set" % key) + * TupleProxy.__setitem__(self, idx, str(value)) + */ + __pyx_t_7 = ((__pyx_v_self->__pyx_base.nfields < __pyx_v_idx) != 0); + if (unlikely(__pyx_t_7)) { + + /* "pysam/libctabixproxies.pyx":366 + * idx, f = self.map_key2field[key] + * if self.nfields < idx: + * raise KeyError("field %s not set" % key) # <<<<<<<<<<<<<< + * TupleProxy.__setitem__(self, idx, str(value)) * - * cpdef int getMaxFields(self): */ - __pyx_r = 9; - goto __pyx_L0; + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_field_s_not_set, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 366, __pyx_L1_error) + + /* "pysam/libctabixproxies.pyx":365 + * cdef int idx + * idx, f = self.map_key2field[key] + * if self.nfields < idx: # <<<<<<<<<<<<<< + * raise KeyError("field %s not set" % key) + * TupleProxy.__setitem__(self, idx, str(value)) + */ + } - /* "pysam/libctabixproxies.pyx":376 - * free(self._attributes) + /* "pysam/libctabixproxies.pyx":367 + * if self.nfields < idx: + * raise KeyError("field %s not set" % key) + * TupleProxy.__setitem__(self, idx, str(value)) # <<<<<<<<<<<<<< * - * cpdef int getMinFields(self): # <<<<<<<<<<<<<< - * '''return minimum number of fields.''' - * return 9 + * def __getattr__(self, key): + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_n_s_setitem); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[4] = {__pyx_t_8, ((PyObject *)__pyx_v_self), __pyx_t_1, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[4] = {__pyx_t_8, ((PyObject *)__pyx_v_self), __pyx_t_1, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_6, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_6, __pyx_t_4); + __pyx_t_1 = 0; + __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libctabixproxies.pyx":361 + * map_key2field = {} + * + * def __setattr__(self, key, value): # <<<<<<<<<<<<<< + * '''set attribute.''' + * cdef int idx */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_WriteUnraisable("pysam.libctabixproxies.GTFProxy.getMinFields", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("pysam.libctabixproxies.NamedTupleProxy.__setattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); __Pyx_RefNannyFinishContext(); return __pyx_r; } +/* "pysam/libctabixproxies.pyx":369 + * TupleProxy.__setitem__(self, idx, str(value)) + * + * def __getattr__(self, key): # <<<<<<<<<<<<<< + * cdef int idx + * idx, f = self.map_key2field[key] + */ + /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5getMinFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_4getMinFields[] = "return minimum number of fields."; -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5getMinFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_3__getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_3__getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getMinFields (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_4getMinFields(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_2__getattr__(((struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *)__pyx_v_self), ((PyObject *)__pyx_v_key)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_4getMinFields(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_2__getattr__(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self, PyObject *__pyx_v_key) { + int __pyx_v_idx; + PyObject *__pyx_v_f = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("getMinFields", 0); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMinFields(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 376, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.getMinFields", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libctabixproxies.pyx":380 - * return 9 - * - * cpdef int getMaxFields(self): # <<<<<<<<<<<<<< - * '''return max number of fields.''' - * return 9 - */ - -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7getMaxFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static int __pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMaxFields(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, int __pyx_skip_dispatch) { - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - __Pyx_RefNannySetupContext("getMaxFields", 0); - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getMaxFields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7getMaxFields)) { - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 380, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_5; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; + PyObject *(*__pyx_t_5)(PyObject *); + int __pyx_t_6; + int __pyx_t_7; + struct __pyx_opt_args_5pysam_9libcutils_force_str __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("__getattr__", 0); + + /* "pysam/libctabixproxies.pyx":371 + * def __getattr__(self, key): + * cdef int idx + * idx, f = self.map_key2field[key] # <<<<<<<<<<<<<< + * if self.nfields < idx: + * raise KeyError("field %s not set" % key) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_map_key2field); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 371, __pyx_L1_error) } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_3 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) __PYX_ERR(0, 371, __pyx_L1_error) + __pyx_t_5 = NULL; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L4_unpacking_done; + __pyx_L3_unpacking_failed:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 371, __pyx_L1_error) + __pyx_L4_unpacking_done:; } + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_idx = __pyx_t_6; + __pyx_v_f = __pyx_t_3; + __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":382 - * cpdef int getMaxFields(self): - * '''return max number of fields.''' - * return 9 # <<<<<<<<<<<<<< - * - * property contig: + /* "pysam/libctabixproxies.pyx":372 + * cdef int idx + * idx, f = self.map_key2field[key] + * if self.nfields < idx: # <<<<<<<<<<<<<< + * raise KeyError("field %s not set" % key) + * if f == str: */ - __pyx_r = 9; - goto __pyx_L0; + __pyx_t_7 = ((__pyx_v_self->__pyx_base.nfields < __pyx_v_idx) != 0); + if (unlikely(__pyx_t_7)) { - /* "pysam/libctabixproxies.pyx":380 - * return 9 - * - * cpdef int getMaxFields(self): # <<<<<<<<<<<<<< - * '''return max number of fields.''' - * return 9 + /* "pysam/libctabixproxies.pyx":373 + * idx, f = self.map_key2field[key] + * if self.nfields < idx: + * raise KeyError("field %s not set" % key) # <<<<<<<<<<<<<< + * if f == str: + * return force_str(self.fields[idx], */ + __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_field_s_not_set, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 373, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 373, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 373, __pyx_L1_error) - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_WriteUnraisable("pysam.libctabixproxies.GTFProxy.getMaxFields", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libctabixproxies.pyx":372 + * cdef int idx + * idx, f = self.map_key2field[key] + * if self.nfields < idx: # <<<<<<<<<<<<<< + * raise KeyError("field %s not set" % key) + * if f == str: + */ + } -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7getMaxFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_6getMaxFields[] = "return max number of fields."; -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7getMaxFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getMaxFields (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6getMaxFields(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); + /* "pysam/libctabixproxies.pyx":374 + * if self.nfields < idx: + * raise KeyError("field %s not set" % key) + * if f == str: # <<<<<<<<<<<<<< + * return force_str(self.fields[idx], + * self.encoding) + */ + __pyx_t_3 = PyObject_RichCompare(__pyx_v_f, ((PyObject *)(&PyString_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 374, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 374, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_7) { - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libctabixproxies.pyx":375 + * raise KeyError("field %s not set" % key) + * if f == str: + * return force_str(self.fields[idx], # <<<<<<<<<<<<<< + * self.encoding) + * return f(self.fields[idx]) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyBytes_FromString((__pyx_v_self->__pyx_base.fields[__pyx_v_idx])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 375, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6getMaxFields(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("getMaxFields", 0); + /* "pysam/libctabixproxies.pyx":376 + * if f == str: + * return force_str(self.fields[idx], + * self.encoding) # <<<<<<<<<<<<<< + * return f(self.fields[idx]) + * + */ + __pyx_t_2 = __pyx_v_self->__pyx_base.encoding; + __Pyx_INCREF(__pyx_t_2); + + /* "pysam/libctabixproxies.pyx":375 + * raise KeyError("field %s not set" % key) + * if f == str: + * return force_str(self.fields[idx], # <<<<<<<<<<<<<< + * self.encoding) + * return f(self.fields[idx]) + */ + __pyx_t_8.__pyx_n = 1; + __pyx_t_8.encoding = __pyx_t_2; + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, &__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 375, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libctabixproxies.pyx":374 + * if self.nfields < idx: + * raise KeyError("field %s not set" % key) + * if f == str: # <<<<<<<<<<<<<< + * return force_str(self.fields[idx], + * self.encoding) + */ + } + + /* "pysam/libctabixproxies.pyx":377 + * return force_str(self.fields[idx], + * self.encoding) + * return f(self.fields[idx]) # <<<<<<<<<<<<<< + * + * + */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMaxFields(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 380, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyBytes_FromString((__pyx_v_self->__pyx_base.fields[__pyx_v_idx])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 377, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_f); + __pyx_t_3 = __pyx_v_f; __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_4) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 377, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 377, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 377, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 377, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 377, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; + /* "pysam/libctabixproxies.pyx":369 + * TupleProxy.__setitem__(self, idx, str(value)) + * + * def __getattr__(self, key): # <<<<<<<<<<<<<< + * cdef int idx + * idx, f = self.map_key2field[key] + */ + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.getMaxFields", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("pysam.libctabixproxies.NamedTupleProxy.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":386 - * property contig: - * '''contig of feature.''' - * def __get__(self): # <<<<<<<<<<<<<< - * return self._getindex(0) - * def __set__(self, value): +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6contig_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6contig_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6contig___get__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_4__reduce_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6contig___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_RefNannySetupContext("__reduce_cython__", 0); - /* "pysam/libctabixproxies.pyx":387 - * '''contig of feature.''' - * def __get__(self): - * return self._getindex(0) # <<<<<<<<<<<<<< - * def __set__(self, value): - * self._setindex(0, value) + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 387, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 387, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __PYX_ERR(1, 2, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":386 - * property contig: - * '''contig of feature.''' - * def __get__(self): # <<<<<<<<<<<<<< - * return self._getindex(0) - * def __set__(self, value): + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.contig.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabixproxies.NamedTupleProxy.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; - __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":388 - * def __get__(self): - * return self._getindex(0) - * def __set__(self, value): # <<<<<<<<<<<<<< - * self._setindex(0, value) - * +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ /* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6contig_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6contig_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6contig_2__set__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_6__setstate_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6contig_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_RefNannySetupContext("__setstate_cython__", 0); - /* "pysam/libctabixproxies.pyx":389 - * return self._getindex(0) - * def __set__(self, value): - * self._setindex(0, value) # <<<<<<<<<<<<<< - * - * property source: + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setindex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - __pyx_t_4 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_4 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_0, __pyx_v_value}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_0, __pyx_v_value}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_int_0); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_value); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 389, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":388 - * def __get__(self): - * return self._getindex(0) - * def __set__(self, value): # <<<<<<<<<<<<<< - * self._setindex(0, value) - * + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.contig.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; + __Pyx_AddTraceback("pysam.libctabixproxies.NamedTupleProxy.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":393 - * property source: - * '''feature source.''' - * def __get__(self): # <<<<<<<<<<<<<< - * return self._getindex(1) - * def __set__(self, value): +/* "pysam/libctabixproxies.pyx":380 + * + * + * cdef dot_or_float(v): # <<<<<<<<<<<<<< + * if v == "" or v == b".": + * return None */ -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6source_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6source_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static PyObject *__pyx_f_5pysam_16libctabixproxies_dot_or_float(PyObject *__pyx_v_v) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6source___get__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + __Pyx_RefNannySetupContext("dot_or_float", 0); - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libctabixproxies.pyx":381 + * + * cdef dot_or_float(v): + * if v == "" or v == b".": # <<<<<<<<<<<<<< + * return None + * else: + */ + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_v, __pyx_kp_s__16, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 381, __pyx_L1_error) + if (!__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = (__Pyx_PyBytes_Equals(__pyx_v_v, __pyx_kp_b__13, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 381, __pyx_L1_error) + __pyx_t_1 = __pyx_t_2; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6source___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); + /* "pysam/libctabixproxies.pyx":382 + * cdef dot_or_float(v): + * if v == "" or v == b".": + * return None # <<<<<<<<<<<<<< + * else: + * try: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":394 - * '''feature source.''' - * def __get__(self): - * return self._getindex(1) # <<<<<<<<<<<<<< - * def __set__(self, value): - * if value is None: + /* "pysam/libctabixproxies.pyx":381 + * + * cdef dot_or_float(v): + * if v == "" or v == b".": # <<<<<<<<<<<<<< + * return None + * else: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 394, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 394, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + } + + /* "pysam/libctabixproxies.pyx":384 + * return None + * else: + * try: # <<<<<<<<<<<<<< + * return int(v) + * except ValueError: + */ + /*else*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + /*try:*/ { + + /* "pysam/libctabixproxies.pyx":385 + * else: + * try: + * return int(v) # <<<<<<<<<<<<<< + * except ValueError: + * return float(v) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = __Pyx_PyNumber_Int(__pyx_v_v); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 385, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L10_try_return; + + /* "pysam/libctabixproxies.pyx":384 + * return None + * else: + * try: # <<<<<<<<<<<<<< + * return int(v) + * except ValueError: + */ + } + __pyx_L6_error:; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "pysam/libctabixproxies.pyx":386 + * try: + * return int(v) + * except ValueError: # <<<<<<<<<<<<<< + * return float(v) + * + */ + __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError); + if (__pyx_t_7) { + __Pyx_AddTraceback("pysam.libctabixproxies.dot_or_float", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_8, &__pyx_t_9) < 0) __PYX_ERR(0, 386, __pyx_L8_except_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_9); + + /* "pysam/libctabixproxies.pyx":387 + * return int(v) + * except ValueError: + * return float(v) # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_10 = __Pyx_PyNumber_Float(__pyx_v_v); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 387, __pyx_L8_except_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_r = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L9_except_return; + } + goto __pyx_L8_except_error; + __pyx_L8_except_error:; + + /* "pysam/libctabixproxies.pyx":384 + * return None + * else: + * try: # <<<<<<<<<<<<<< + * return int(v) + * except ValueError: + */ + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5); + goto __pyx_L1_error; + __pyx_L10_try_return:; + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5); + goto __pyx_L0; + __pyx_L9_except_return:; + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5); + goto __pyx_L0; + } + } - /* "pysam/libctabixproxies.pyx":393 - * property source: - * '''feature source.''' - * def __get__(self): # <<<<<<<<<<<<<< - * return self._getindex(1) - * def __set__(self, value): + /* "pysam/libctabixproxies.pyx":380 + * + * + * cdef dot_or_float(v): # <<<<<<<<<<<<<< + * if v == "" or v == b".": + * return None */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.source.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("pysam.libctabixproxies.dot_or_float", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":395 - * def __get__(self): - * return self._getindex(1) - * def __set__(self, value): # <<<<<<<<<<<<<< - * if value is None: - * value = "." +/* "pysam/libctabixproxies.pyx":390 + * + * + * cdef dot_or_int(v): # <<<<<<<<<<<<<< + * if v == "" or v == b".": + * return None */ -/* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6source_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6source_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6source_2__set__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6source_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_f_5pysam_16libctabixproxies_dot_or_int(PyObject *__pyx_v_v) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_INCREF(__pyx_v_value); + __Pyx_RefNannySetupContext("dot_or_int", 0); - /* "pysam/libctabixproxies.pyx":396 - * return self._getindex(1) - * def __set__(self, value): - * if value is None: # <<<<<<<<<<<<<< - * value = "." - * self._setindex(1, value) + /* "pysam/libctabixproxies.pyx":391 + * + * cdef dot_or_int(v): + * if v == "" or v == b".": # <<<<<<<<<<<<<< + * return None + * else: */ - __pyx_t_1 = (__pyx_v_value == Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_v, __pyx_kp_s__16, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 391, __pyx_L1_error) + if (!__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = (__Pyx_PyBytes_Equals(__pyx_v_v, __pyx_kp_b__13, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 391, __pyx_L1_error) + __pyx_t_1 = __pyx_t_2; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":397 - * def __set__(self, value): - * if value is None: - * value = "." # <<<<<<<<<<<<<< - * self._setindex(1, value) + /* "pysam/libctabixproxies.pyx":392 + * cdef dot_or_int(v): + * if v == "" or v == b".": + * return None # <<<<<<<<<<<<<< + * else: + * return int(v) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "pysam/libctabixproxies.pyx":391 * + * cdef dot_or_int(v): + * if v == "" or v == b".": # <<<<<<<<<<<<<< + * return None + * else: */ - __Pyx_INCREF(__pyx_kp_s__13); - __Pyx_DECREF_SET(__pyx_v_value, __pyx_kp_s__13); + } - /* "pysam/libctabixproxies.pyx":396 - * return self._getindex(1) - * def __set__(self, value): - * if value is None: # <<<<<<<<<<<<<< - * value = "." - * self._setindex(1, value) + /* "pysam/libctabixproxies.pyx":394 + * return None + * else: + * return int(v) # <<<<<<<<<<<<<< + * + * */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_v_v); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; } - /* "pysam/libctabixproxies.pyx":398 - * if value is None: - * value = "." - * self._setindex(1, value) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":390 + * * - * property feature: - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setindex); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_1, __pyx_v_value}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_1, __pyx_v_value}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_INCREF(__pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_int_1); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_value); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 398, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pysam/libctabixproxies.pyx":395 - * def __get__(self): - * return self._getindex(1) - * def __set__(self, value): # <<<<<<<<<<<<<< - * if value is None: - * value = "." + * cdef dot_or_int(v): # <<<<<<<<<<<<<< + * if v == "" or v == b".": + * return None */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.source.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("pysam.libctabixproxies.dot_or_int", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_value); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":402 - * property feature: - * '''feature name.''' - * def __get__(self): # <<<<<<<<<<<<<< - * return self._getindex(2) - * def __set__(self, value): +/* "pysam/libctabixproxies.pyx":397 + * + * + * cdef dot_or_str(v): # <<<<<<<<<<<<<< + * if v == "" or v == b".": + * return None */ -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7feature_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7feature_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static PyObject *__pyx_f_5pysam_16libctabixproxies_dot_or_str(PyObject *__pyx_v_v) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_7feature___get__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("dot_or_str", 0); - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "pysam/libctabixproxies.pyx":398 + * + * cdef dot_or_str(v): + * if v == "" or v == b".": # <<<<<<<<<<<<<< + * return None + * else: + */ + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_v, __pyx_kp_s__16, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 398, __pyx_L1_error) + if (!__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = (__Pyx_PyBytes_Equals(__pyx_v_v, __pyx_kp_b__13, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 398, __pyx_L1_error) + __pyx_t_1 = __pyx_t_2; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_7feature___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); + /* "pysam/libctabixproxies.pyx":399 + * cdef dot_or_str(v): + * if v == "" or v == b".": + * return None # <<<<<<<<<<<<<< + * else: + * return force_str(v) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":403 - * '''feature name.''' - * def __get__(self): - * return self._getindex(2) # <<<<<<<<<<<<<< - * def __set__(self, value): - * if value is None: + /* "pysam/libctabixproxies.pyx":398 + * + * cdef dot_or_str(v): + * if v == "" or v == b".": # <<<<<<<<<<<<<< + * return None + * else: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 403, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 403, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + } + + /* "pysam/libctabixproxies.pyx":401 + * return None + * else: + * return force_str(v) # <<<<<<<<<<<<<< + * + * + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_v, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 401, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + } - /* "pysam/libctabixproxies.pyx":402 - * property feature: - * '''feature name.''' - * def __get__(self): # <<<<<<<<<<<<<< - * return self._getindex(2) - * def __set__(self, value): + /* "pysam/libctabixproxies.pyx":397 + * + * + * cdef dot_or_str(v): # <<<<<<<<<<<<<< + * if v == "" or v == b".": + * return None */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.feature.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libctabixproxies.dot_or_str", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); @@ -7357,400 +7839,270 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_7feature___get__(s } /* "pysam/libctabixproxies.pyx":404 - * def __get__(self): - * return self._getindex(2) - * def __set__(self, value): # <<<<<<<<<<<<<< - * if value is None: - * value = "." + * + * + * cdef int from1based(v): # <<<<<<<<<<<<<< + * return atoi(v) - 1 + * */ -/* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7feature_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7feature_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_7feature_2__set__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_7feature_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value) { +static int __pyx_f_5pysam_16libctabixproxies_from1based(PyObject *__pyx_v_v) { int __pyx_r; __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_INCREF(__pyx_v_value); + char const *__pyx_t_1; + __Pyx_RefNannySetupContext("from1based", 0); /* "pysam/libctabixproxies.pyx":405 - * return self._getindex(2) - * def __set__(self, value): - * if value is None: # <<<<<<<<<<<<<< - * value = "." - * self._setindex(2, value) - */ - __pyx_t_1 = (__pyx_v_value == Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { - - /* "pysam/libctabixproxies.pyx":406 - * def __set__(self, value): - * if value is None: - * value = "." # <<<<<<<<<<<<<< - * self._setindex(2, value) * - */ - __Pyx_INCREF(__pyx_kp_s__13); - __Pyx_DECREF_SET(__pyx_v_value, __pyx_kp_s__13); - - /* "pysam/libctabixproxies.pyx":405 - * return self._getindex(2) - * def __set__(self, value): - * if value is None: # <<<<<<<<<<<<<< - * value = "." - * self._setindex(2, value) - */ - } - - /* "pysam/libctabixproxies.pyx":407 - * if value is None: - * value = "." - * self._setindex(2, value) # <<<<<<<<<<<<<< + * cdef int from1based(v): + * return atoi(v) - 1 # <<<<<<<<<<<<<< + * * - * property start: */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setindex); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_2, __pyx_v_value}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_2, __pyx_v_value}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_INCREF(__pyx_int_2); - __Pyx_GIVEREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_int_2); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_value); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 407, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_v); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 405, __pyx_L1_error) + __pyx_r = (atoi(__pyx_t_1) - 1); + goto __pyx_L0; /* "pysam/libctabixproxies.pyx":404 - * def __get__(self): - * return self._getindex(2) - * def __set__(self, value): # <<<<<<<<<<<<<< - * if value is None: - * value = "." + * + * + * cdef int from1based(v): # <<<<<<<<<<<<<< + * return atoi(v) - 1 + * */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.feature.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_WriteUnraisable("pysam.libctabixproxies.from1based", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_value); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":411 - * property start: - * '''feature start (in 0-based open/closed coordinates).''' - * def __get__(self ): # <<<<<<<<<<<<<< - * return int( self._getindex(3)) - 1 - * def __set__(self, value ): +/* "pysam/libctabixproxies.pyx":408 + * + * + * cdef str to1based(int v): # <<<<<<<<<<<<<< + * return str(v + 1) + * */ -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5start_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5start_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5start___get__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5start___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { +static PyObject *__pyx_f_5pysam_16libctabixproxies_to1based(int __pyx_v_v) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_RefNannySetupContext("to1based", 0); - /* "pysam/libctabixproxies.pyx":412 - * '''feature start (in 0-based open/closed coordinates).''' - * def __get__(self ): - * return int( self._getindex(3)) - 1 # <<<<<<<<<<<<<< - * def __set__(self, value ): - * self._setindex(3, str(value+1)) + /* "pysam/libctabixproxies.pyx":409 + * + * cdef str to1based(int v): + * return str(v + 1) # <<<<<<<<<<<<<< + * + * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 412, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 412, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 412, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_long((__pyx_v_v + 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 412, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; + if (!(likely(PyString_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 409, __pyx_L1_error) + __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":411 - * property start: - * '''feature start (in 0-based open/closed coordinates).''' - * def __get__(self ): # <<<<<<<<<<<<<< - * return int( self._getindex(3)) - 1 - * def __set__(self, value ): + /* "pysam/libctabixproxies.pyx":408 + * + * + * cdef str to1based(int v): # <<<<<<<<<<<<<< + * return str(v + 1) + * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.start.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libctabixproxies.to1based", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":413 - * def __get__(self ): - * return int( self._getindex(3)) - 1 - * def __set__(self, value ): # <<<<<<<<<<<<<< - * self._setindex(3, str(value+1)) +/* "pysam/libctabixproxies.pyx":442 + * 'attributes': (8, (str, str))} * + * def __cinit__(self): # <<<<<<<<<<<<<< + * # automatically calls TupleProxy.__cinit__ + * self.attribute_dict = None */ /* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { +static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5start_2__set__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy___cinit__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5start_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value) { +static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy___cinit__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_RefNannySetupContext("__cinit__", 0); - /* "pysam/libctabixproxies.pyx":414 - * return int( self._getindex(3)) - 1 - * def __set__(self, value ): - * self._setindex(3, str(value+1)) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":444 + * def __cinit__(self): + * # automatically calls TupleProxy.__cinit__ + * self.attribute_dict = None # <<<<<<<<<<<<<< * - * property end: + * cpdef int getMinFields(self): */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setindex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_value, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_3, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_3, __pyx_t_4}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->attribute_dict); + __Pyx_DECREF(__pyx_v_self->attribute_dict); + __pyx_v_self->attribute_dict = Py_None; + + /* "pysam/libctabixproxies.pyx":442 + * 'attributes': (8, (str, str))} + * + * def __cinit__(self): # <<<<<<<<<<<<<< + * # automatically calls TupleProxy.__cinit__ + * self.attribute_dict = None + */ + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libctabixproxies.pyx":446 + * self.attribute_dict = None + * + * cpdef int getMinFields(self): # <<<<<<<<<<<<<< + * '''return minimum number of fields.''' + * return 9 + */ + +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3getMinFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static int __pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMinFields(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, int __pyx_skip_dispatch) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + __Pyx_RefNannySetupContext("getMinFields", 0); + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getMinFields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 446, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL; + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3getMinFields)) { + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 446, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 446, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 446, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_5; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; } - __Pyx_INCREF(__pyx_int_3); - __Pyx_GIVEREF(__pyx_int_3); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_int_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 414, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":413 - * def __get__(self ): - * return int( self._getindex(3)) - 1 - * def __set__(self, value ): # <<<<<<<<<<<<<< - * self._setindex(3, str(value+1)) + /* "pysam/libctabixproxies.pyx":448 + * cpdef int getMinFields(self): + * '''return minimum number of fields.''' + * return 9 # <<<<<<<<<<<<<< + * + * cpdef int getMaxFields(self): + */ + __pyx_r = 9; + goto __pyx_L0; + + /* "pysam/libctabixproxies.pyx":446 + * self.attribute_dict = None * + * cpdef int getMinFields(self): # <<<<<<<<<<<<<< + * '''return minimum number of fields.''' + * return 9 */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.start.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_WriteUnraisable("pysam.libctabixproxies.GTFProxy.getMinFields", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":418 - * property end: - * '''feature end (in 0-based open/closed coordinates).''' - * def __get__(self): # <<<<<<<<<<<<<< - * return int(self._getindex(4)) - * def __set__(self, value): - */ - /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3end_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3end_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3getMinFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_2getMinFields[] = "return minimum number of fields."; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3getMinFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_3end___get__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("getMinFields (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_2getMinFields(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_3end___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_2getMinFields(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "pysam/libctabixproxies.pyx":419 - * '''feature end (in 0-based open/closed coordinates).''' - * def __get__(self): - * return int(self._getindex(4)) # <<<<<<<<<<<<<< - * def __set__(self, value): - * self._setindex(4, str(value)) - */ + __Pyx_RefNannySetupContext("getMinFields", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 419, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 419, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 419, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMinFields(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 446, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":418 - * property end: - * '''feature end (in 0-based open/closed coordinates).''' - * def __get__(self): # <<<<<<<<<<<<<< - * return int(self._getindex(4)) - * def __set__(self, value): - */ - /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.end.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.getMinFields", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -7758,28 +8110,16 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_3end___get__(struc return __pyx_r; } -/* "pysam/libctabixproxies.pyx":420 - * def __get__(self): - * return int(self._getindex(4)) - * def __set__(self, value): # <<<<<<<<<<<<<< - * self._setindex(4, str(value)) +/* "pysam/libctabixproxies.pyx":450 + * return 9 * + * cpdef int getMaxFields(self): # <<<<<<<<<<<<<< + * '''return max number of fields.''' + * return 9 */ -/* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3end_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3end_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_3end_2__set__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_3end_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5getMaxFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static int __pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMaxFields(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, int __pyx_skip_dispatch) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -7787,240 +8127,134 @@ static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_3end_2__set__(struct __p PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - __Pyx_RefNannySetupContext("__set__", 0); - - /* "pysam/libctabixproxies.pyx":421 - * return int(self._getindex(4)) - * def __set__(self, value): - * self._setindex(4, str(value)) # <<<<<<<<<<<<<< - * - * property score: - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setindex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_5 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_int_4, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_int_4, __pyx_t_3}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_RefNannySetupContext("getMaxFields", 0); + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getMaxFields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 450, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5getMaxFields)) { + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 450, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 450, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 450, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_5; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; } - __Pyx_INCREF(__pyx_int_4); - __Pyx_GIVEREF(__pyx_int_4); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_int_4); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 421, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":420 - * def __get__(self): - * return int(self._getindex(4)) - * def __set__(self, value): # <<<<<<<<<<<<<< - * self._setindex(4, str(value)) + /* "pysam/libctabixproxies.pyx":452 + * cpdef int getMaxFields(self): + * '''return max number of fields.''' + * return 9 # <<<<<<<<<<<<<< + * + * def to_dict(self): + */ + __pyx_r = 9; + goto __pyx_L0; + + /* "pysam/libctabixproxies.pyx":450 + * return 9 * + * cpdef int getMaxFields(self): # <<<<<<<<<<<<<< + * '''return max number of fields.''' + * return 9 */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.end.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_WriteUnraisable("pysam.libctabixproxies.GTFProxy.getMaxFields", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":425 - * property score: - * '''feature score.''' - * def __get__(self): # <<<<<<<<<<<<<< - * v = self._getindex(5) - * if v == "" or v[0] == '.': - */ - /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5score_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5getMaxFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_4getMaxFields[] = "return max number of fields."; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5getMaxFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5score___get__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("getMaxFields (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_4getMaxFields(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5score___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { - PyObject *__pyx_v_v = NULL; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_4getMaxFields(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "pysam/libctabixproxies.pyx":426 - * '''feature score.''' - * def __get__(self): - * v = self._getindex(5) # <<<<<<<<<<<<<< - * if v == "" or v[0] == '.': - * return None - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 426, __pyx_L1_error) + __Pyx_RefNannySetupContext("getMaxFields", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMaxFields(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 450, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_v = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":427 - * def __get__(self): - * v = self._getindex(5) - * if v == "" or v[0] == '.': # <<<<<<<<<<<<<< - * return None - * else: - */ - __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_v, __pyx_kp_s__20, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 427, __pyx_L1_error) - if (!__pyx_t_4) { - } else { - __pyx_t_3 = __pyx_t_4; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_v, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 427, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s__13, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 427, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_3 = __pyx_t_4; - __pyx_L4_bool_binop_done:; - if (__pyx_t_3) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.getMaxFields", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "pysam/libctabixproxies.pyx":428 - * v = self._getindex(5) - * if v == "" or v[0] == '.': - * return None # <<<<<<<<<<<<<< - * else: - * return float(v) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - - /* "pysam/libctabixproxies.pyx":427 - * def __get__(self): - * v = self._getindex(5) - * if v == "" or v[0] == '.': # <<<<<<<<<<<<<< - * return None - * else: - */ - } - - /* "pysam/libctabixproxies.pyx":430 - * return None - * else: - * return float(v) # <<<<<<<<<<<<<< - * - * def __set__(self, value): - */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyNumber_Float(__pyx_v_v); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 430, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - } - - /* "pysam/libctabixproxies.pyx":425 - * property score: - * '''feature score.''' - * def __get__(self): # <<<<<<<<<<<<<< - * v = self._getindex(5) - * if v == "" or v[0] == '.': - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_v); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libctabixproxies.pyx":432 - * return float(v) - * - * def __set__(self, value): # <<<<<<<<<<<<<< - * if value is None: - * value = "." +/* "pysam/libctabixproxies.pyx":454 + * return 9 + * + * def to_dict(self): # <<<<<<<<<<<<<< + * """parse attributes - return as dict + * */ /* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7to_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_6to_dict[] = "parse attributes - return as dict\n\n The dictionary can be modified to update attributes.\n "; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7to_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5score_2__set__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("to_dict (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6to_dict(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5score_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6to_dict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; int __pyx_t_2; @@ -8028,184 +8262,228 @@ static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5score_2__set__(struct _ PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_INCREF(__pyx_v_value); + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("to_dict", 0); - /* "pysam/libctabixproxies.pyx":433 - * - * def __set__(self, value): - * if value is None: # <<<<<<<<<<<<<< - * value = "." - * self._setindex(5, str(value)) + /* "pysam/libctabixproxies.pyx":459 + * The dictionary can be modified to update attributes. + * """ + * if not self.attribute_dict: # <<<<<<<<<<<<<< + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) */ - __pyx_t_1 = (__pyx_v_value == Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->attribute_dict); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 459, __pyx_L1_error) + __pyx_t_2 = ((!__pyx_t_1) != 0); if (__pyx_t_2) { - /* "pysam/libctabixproxies.pyx":434 - * def __set__(self, value): - * if value is None: - * value = "." # <<<<<<<<<<<<<< - * self._setindex(5, str(value)) - * + /* "pysam/libctabixproxies.pyx":460 + * """ + * if not self.attribute_dict: + * self.attribute_dict = self.attribute_string2dict( # <<<<<<<<<<<<<< + * self.attributes) + * self.is_modified = True */ - __Pyx_INCREF(__pyx_kp_s__13); - __Pyx_DECREF_SET(__pyx_v_value, __pyx_kp_s__13); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attribute_string2dict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 460, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "pysam/libctabixproxies.pyx":461 + * if not self.attribute_dict: + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) # <<<<<<<<<<<<<< + * self.is_modified = True + * return self.attribute_dict + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attributes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 461, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 460, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 460, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 460, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 460, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 460, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libctabixproxies.pyx":460 + * """ + * if not self.attribute_dict: + * self.attribute_dict = self.attribute_string2dict( # <<<<<<<<<<<<<< + * self.attributes) + * self.is_modified = True + */ + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->attribute_dict); + __Pyx_DECREF(__pyx_v_self->attribute_dict); + __pyx_v_self->attribute_dict = __pyx_t_3; + __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":433 + /* "pysam/libctabixproxies.pyx":462 + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) + * self.is_modified = True # <<<<<<<<<<<<<< + * return self.attribute_dict * - * def __set__(self, value): - * if value is None: # <<<<<<<<<<<<<< - * value = "." - * self._setindex(5, str(value)) + */ + __pyx_v_self->__pyx_base.__pyx_base.is_modified = 1; + + /* "pysam/libctabixproxies.pyx":459 + * The dictionary can be modified to update attributes. + * """ + * if not self.attribute_dict: # <<<<<<<<<<<<<< + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) */ } - /* "pysam/libctabixproxies.pyx":435 - * if value is None: - * value = "." - * self._setindex(5, str(value)) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":463 + * self.attributes) + * self.is_modified = True + * return self.attribute_dict # <<<<<<<<<<<<<< * - * property strand: + * def as_dict(self): */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setindex); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 435, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_value); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 435, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - __pyx_t_7 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_int_5, __pyx_t_5}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 435, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_int_5, __pyx_t_5}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 435, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 435, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (__pyx_t_6) { - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; - } - __Pyx_INCREF(__pyx_int_5); - __Pyx_GIVEREF(__pyx_int_5); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_int_5); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 435, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->attribute_dict); + __pyx_r = __pyx_v_self->attribute_dict; + goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":432 - * return float(v) + /* "pysam/libctabixproxies.pyx":454 + * return 9 + * + * def to_dict(self): # <<<<<<<<<<<<<< + * """parse attributes - return as dict * - * def __set__(self, value): # <<<<<<<<<<<<<< - * if value is None: - * value = "." */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.score.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.to_dict", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_value); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":439 - * property strand: - * '''feature strand.''' - * def __get__(self): # <<<<<<<<<<<<<< - * return self._getindex(6) - * def __set__(self, value ): +/* "pysam/libctabixproxies.pyx":465 + * return self.attribute_dict + * + * def as_dict(self): # <<<<<<<<<<<<<< + * """deprecated: use :meth:`to_dict` + * """ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6strand_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6strand_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_9as_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_8as_dict[] = "deprecated: use :meth:`to_dict`\n "; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_9as_dict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6strand___get__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("as_dict (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_8as_dict(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6strand___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_8as_dict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("as_dict", 0); - /* "pysam/libctabixproxies.pyx":440 - * '''feature strand.''' - * def __get__(self): - * return self._getindex(6) # <<<<<<<<<<<<<< - * def __set__(self, value ): - * if value is None: + /* "pysam/libctabixproxies.pyx":468 + * """deprecated: use :meth:`to_dict` + * """ + * return self.to_dict() # <<<<<<<<<<<<<< + * + * def from_dict(self, d): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 440, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 468, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 468, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 468, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":439 - * property strand: - * '''feature strand.''' - * def __get__(self): # <<<<<<<<<<<<<< - * return self._getindex(6) - * def __set__(self, value ): + /* "pysam/libctabixproxies.pyx":465 + * return self.attribute_dict + * + * def as_dict(self): # <<<<<<<<<<<<<< + * """deprecated: use :meth:`to_dict` + * """ */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.strand.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.as_dict", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -8213,2280 +8491,1448 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6strand___get__(st return __pyx_r; } -/* "pysam/libctabixproxies.pyx":441 - * def __get__(self): - * return self._getindex(6) - * def __set__(self, value ): # <<<<<<<<<<<<<< - * if value is None: - * value = "." +/* "pysam/libctabixproxies.pyx":470 + * return self.to_dict() + * + * def from_dict(self, d): # <<<<<<<<<<<<<< + * '''set attributes from a dictionary.''' + * self.attribute_dict = None */ /* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6strand_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6strand_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_11from_dict(PyObject *__pyx_v_self, PyObject *__pyx_v_d); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_10from_dict[] = "set attributes from a dictionary."; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_11from_dict(PyObject *__pyx_v_self, PyObject *__pyx_v_d) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6strand_2__set__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("from_dict (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_10from_dict(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_d)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_6strand_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_10from_dict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_d) { + PyObject *__pyx_v_attribute_string = NULL; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; + struct __pyx_opt_args_5pysam_9libcutils_force_bytes __pyx_t_5; int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_INCREF(__pyx_v_value); + __Pyx_RefNannySetupContext("from_dict", 0); - /* "pysam/libctabixproxies.pyx":442 - * return self._getindex(6) - * def __set__(self, value ): - * if value is None: # <<<<<<<<<<<<<< - * value = "." - * self._setindex(6, value) + /* "pysam/libctabixproxies.pyx":472 + * def from_dict(self, d): + * '''set attributes from a dictionary.''' + * self.attribute_dict = None # <<<<<<<<<<<<<< + * attribute_string = force_bytes( + * self.attribute_dict2string(d), */ - __pyx_t_1 = (__pyx_v_value == Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->attribute_dict); + __Pyx_DECREF(__pyx_v_self->attribute_dict); + __pyx_v_self->attribute_dict = Py_None; - /* "pysam/libctabixproxies.pyx":443 - * def __set__(self, value ): - * if value is None: - * value = "." # <<<<<<<<<<<<<< - * self._setindex(6, value) + /* "pysam/libctabixproxies.pyx":474 + * self.attribute_dict = None + * attribute_string = force_bytes( + * self.attribute_dict2string(d), # <<<<<<<<<<<<<< + * self.encoding) + * self._setindex(8, attribute_string) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attribute_dict2string); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 474, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_d); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 474, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_d}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 474, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_d}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 474, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 474, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_d); + __Pyx_GIVEREF(__pyx_v_d); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_d); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 474, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libctabixproxies.pyx":475 + * attribute_string = force_bytes( + * self.attribute_dict2string(d), + * self.encoding) # <<<<<<<<<<<<<< + * self._setindex(8, attribute_string) * */ - __Pyx_INCREF(__pyx_kp_s__13); - __Pyx_DECREF_SET(__pyx_v_value, __pyx_kp_s__13); + __pyx_t_2 = __pyx_v_self->__pyx_base.__pyx_base.encoding; + __Pyx_INCREF(__pyx_t_2); - /* "pysam/libctabixproxies.pyx":442 - * return self._getindex(6) - * def __set__(self, value ): - * if value is None: # <<<<<<<<<<<<<< - * value = "." - * self._setindex(6, value) + /* "pysam/libctabixproxies.pyx":473 + * '''set attributes from a dictionary.''' + * self.attribute_dict = None + * attribute_string = force_bytes( # <<<<<<<<<<<<<< + * self.attribute_dict2string(d), + * self.encoding) */ - } + __pyx_t_5.__pyx_n = 1; + __pyx_t_5.encoding = __pyx_t_2; + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_1, &__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 473, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_attribute_string = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":444 - * if value is None: - * value = "." - * self._setindex(6, value) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":476 + * self.attribute_dict2string(d), + * self.encoding) + * self._setindex(8, attribute_string) # <<<<<<<<<<<<<< * - * property frame: + * def __str__(self): */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setindex); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 444, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = NULL; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setindex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = NULL; __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); + __Pyx_DECREF_SET(__pyx_t_2, function); __pyx_t_6 = 1; } } #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_6, __pyx_v_value}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 444, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_int_8, __pyx_v_attribute_string}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_4); } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_6, __pyx_v_value}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 444, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_int_8, __pyx_v_attribute_string}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_4); } else #endif { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 444, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; - } - __Pyx_INCREF(__pyx_int_6); - __Pyx_GIVEREF(__pyx_int_6); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_int_6); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_value); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 444, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 476, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pysam/libctabixproxies.pyx":441 - * def __get__(self): - * return self._getindex(6) - * def __set__(self, value ): # <<<<<<<<<<<<<< - * if value is None: - * value = "." - */ - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.strand.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_value); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libctabixproxies.pyx":448 - * property frame: - * '''feature frame.''' - * def __get__(self): # <<<<<<<<<<<<<< - * v = self._getindex(7) - * if v == "" or v[0] == '.': - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5frame_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5frame_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5frame___get__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5frame___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { - PyObject *__pyx_v_v = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "pysam/libctabixproxies.pyx":449 - * '''feature frame.''' - * def __get__(self): - * v = self._getindex(7) # <<<<<<<<<<<<<< - * if v == "" or v[0] == '.': - * return v - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_v = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pysam/libctabixproxies.pyx":450 - * def __get__(self): - * v = self._getindex(7) - * if v == "" or v[0] == '.': # <<<<<<<<<<<<<< - * return v - * else: - */ - __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_v, __pyx_kp_s__20, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 450, __pyx_L1_error) - if (!__pyx_t_4) { - } else { - __pyx_t_3 = __pyx_t_4; - goto __pyx_L4_bool_binop_done; + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_int_8); + __Pyx_GIVEREF(__pyx_int_8); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_6, __pyx_int_8); + __Pyx_INCREF(__pyx_v_attribute_string); + __Pyx_GIVEREF(__pyx_v_attribute_string); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_6, __pyx_v_attribute_string); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 476, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_v, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 450, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s__13, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 450, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_3 = __pyx_t_4; - __pyx_L4_bool_binop_done:; - if (__pyx_t_3) { - - /* "pysam/libctabixproxies.pyx":451 - * v = self._getindex(7) - * if v == "" or v[0] == '.': - * return v # <<<<<<<<<<<<<< - * else: - * return int(v) - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_v); - __pyx_r = __pyx_v_v; - goto __pyx_L0; - - /* "pysam/libctabixproxies.pyx":450 - * def __get__(self): - * v = self._getindex(7) - * if v == "" or v[0] == '.': # <<<<<<<<<<<<<< - * return v - * else: - */ - } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":453 - * return v - * else: - * return int(v) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":470 + * return self.to_dict() * - * def __set__(self, value): - */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_v_v); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 453, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - } - - /* "pysam/libctabixproxies.pyx":448 - * property frame: - * '''feature frame.''' - * def __get__(self): # <<<<<<<<<<<<<< - * v = self._getindex(7) - * if v == "" or v[0] == '.': + * def from_dict(self, d): # <<<<<<<<<<<<<< + * '''set attributes from a dictionary.''' + * self.attribute_dict = None */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.frame.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.from_dict", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_v); + __Pyx_XDECREF(__pyx_v_attribute_string); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":455 - * return int(v) +/* "pysam/libctabixproxies.pyx":478 + * self._setindex(8, attribute_string) * - * def __set__(self, value): # <<<<<<<<<<<<<< - * if value is None: - * value = "." + * def __str__(self): # <<<<<<<<<<<<<< + * cdef char * cpy + * cdef int x */ /* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5frame_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5frame_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_13__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_13__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5frame_2__set__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_12__str__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_5frame_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_12__str__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; - int __pyx_t_2; + PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; + PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_INCREF(__pyx_v_value); + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + __Pyx_RefNannySetupContext("__str__", 0); - /* "pysam/libctabixproxies.pyx":456 + /* "pysam/libctabixproxies.pyx":482 + * cdef int x * - * def __set__(self, value): - * if value is None: # <<<<<<<<<<<<<< - * value = "." - * self._setindex(7, str(value)) + * if self.is_modified: # <<<<<<<<<<<<<< + * return "\t".join( + * (self.contig, */ - __pyx_t_1 = (__pyx_v_value == Py_None); - __pyx_t_2 = (__pyx_t_1 != 0); - if (__pyx_t_2) { + __pyx_t_1 = (__pyx_v_self->__pyx_base.__pyx_base.is_modified != 0); + if (__pyx_t_1) { - /* "pysam/libctabixproxies.pyx":457 - * def __set__(self, value): - * if value is None: - * value = "." # <<<<<<<<<<<<<< - * self._setindex(7, str(value)) + /* "pysam/libctabixproxies.pyx":483 * + * if self.is_modified: + * return "\t".join( # <<<<<<<<<<<<<< + * (self.contig, + * toDot(self.source), */ - __Pyx_INCREF(__pyx_kp_s__13); - __Pyx_DECREF_SET(__pyx_v_value, __pyx_kp_s__13); + __Pyx_XDECREF(__pyx_r); - /* "pysam/libctabixproxies.pyx":456 - * - * def __set__(self, value): - * if value is None: # <<<<<<<<<<<<<< - * value = "." - * self._setindex(7, str(value)) + /* "pysam/libctabixproxies.pyx":484 + * if self.is_modified: + * return "\t".join( + * (self.contig, # <<<<<<<<<<<<<< + * toDot(self.source), + * toDot(self.feature), */ - } + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contig); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 484, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); - /* "pysam/libctabixproxies.pyx":458 - * if value is None: - * value = "." - * self._setindex(7, str(value)) # <<<<<<<<<<<<<< - * - * property attributes: + /* "pysam/libctabixproxies.pyx":485 + * return "\t".join( + * (self.contig, + * toDot(self.source), # <<<<<<<<<<<<<< + * toDot(self.feature), + * str(self.start + 1), */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setindex); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 458, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_value); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 458, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = NULL; - __pyx_t_7 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - __pyx_t_7 = 1; + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_toDot); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_source); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_int_7, __pyx_t_5}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 458, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_int_7, __pyx_t_5}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 458, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else - #endif - { - __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 458, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - if (__pyx_t_6) { - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; + if (!__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } } - __Pyx_INCREF(__pyx_int_7); - __Pyx_GIVEREF(__pyx_int_7); - PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_int_7); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 458, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pysam/libctabixproxies.pyx":455 - * return int(v) - * - * def __set__(self, value): # <<<<<<<<<<<<<< - * if value is None: - * value = "." - */ - - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.frame.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_value); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; -/* "pysam/libctabixproxies.pyx":462 - * property attributes: - * '''feature attributes (as a string).''' - * def __get__(self): # <<<<<<<<<<<<<< - * if self.hasOwnAttributes: - * return force_str(self._attributes) + /* "pysam/libctabixproxies.pyx":486 + * (self.contig, + * toDot(self.source), + * toDot(self.feature), # <<<<<<<<<<<<<< + * str(self.start + 1), + * str(self.end), */ + __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_toDot); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_feature); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + if (!__pyx_t_6) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 486, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_10attributes_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_10attributes_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_10attributes___get__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_10attributes___get__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "pysam/libctabixproxies.pyx":463 - * '''feature attributes (as a string).''' - * def __get__(self): - * if self.hasOwnAttributes: # <<<<<<<<<<<<<< - * return force_str(self._attributes) - * else: + /* "pysam/libctabixproxies.pyx":487 + * toDot(self.source), + * toDot(self.feature), + * str(self.start + 1), # <<<<<<<<<<<<<< + * str(self.end), + * toDot(self.score), */ - __pyx_t_1 = (__pyx_v_self->hasOwnAttributes != 0); - if (__pyx_t_1) { + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_7, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 487, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - /* "pysam/libctabixproxies.pyx":464 - * def __get__(self): - * if self.hasOwnAttributes: - * return force_str(self._attributes) # <<<<<<<<<<<<<< - * else: - * return force_str(self._getindex(8)) + /* "pysam/libctabixproxies.pyx":488 + * toDot(self.feature), + * str(self.start + 1), + * str(self.end), # <<<<<<<<<<<<<< + * toDot(self.score), + * toDot(self.strand), */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_self->_attributes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 464, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 464, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_end); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 488, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - /* "pysam/libctabixproxies.pyx":463 - * '''feature attributes (as a string).''' - * def __get__(self): - * if self.hasOwnAttributes: # <<<<<<<<<<<<<< - * return force_str(self._attributes) - * else: + /* "pysam/libctabixproxies.pyx":489 + * str(self.start + 1), + * str(self.end), + * toDot(self.score), # <<<<<<<<<<<<<< + * toDot(self.strand), + * toDot(self.frame), */ - } + __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_toDot); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 489, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_score); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 489, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + if (!__pyx_t_10) { + __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 489, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 489, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 489, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 489, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 489, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "pysam/libctabixproxies.pyx":466 - * return force_str(self._attributes) - * else: - * return force_str(self._getindex(8)) # <<<<<<<<<<<<<< - * def __set__( self, value): - * if self.hasOwnAttributes: + /* "pysam/libctabixproxies.pyx":490 + * str(self.end), + * toDot(self.score), + * toDot(self.strand), # <<<<<<<<<<<<<< + * toDot(self.frame), + * self.attributes)) */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getindex); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 466, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 466, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 466, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - } + __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_toDot); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 490, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 490, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + if (!__pyx_t_10) { + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 490, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 490, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 490, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 490, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 490, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - /* "pysam/libctabixproxies.pyx":462 - * property attributes: - * '''feature attributes (as a string).''' - * def __get__(self): # <<<<<<<<<<<<<< - * if self.hasOwnAttributes: - * return force_str(self._attributes) + /* "pysam/libctabixproxies.pyx":491 + * toDot(self.score), + * toDot(self.strand), + * toDot(self.frame), # <<<<<<<<<<<<<< + * self.attributes)) + * else: */ + __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_toDot); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_frame); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + if (!__pyx_t_10) { + __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 491, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_11); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_12)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9}; + __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 491, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { + PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9}; + __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 491, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_10); __pyx_t_10 = NULL; + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_13, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 491, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + } + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.attributes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libctabixproxies.pyx":467 - * else: - * return force_str(self._getindex(8)) - * def __set__( self, value): # <<<<<<<<<<<<<< - * if self.hasOwnAttributes: - * free(self._attributes) + /* "pysam/libctabixproxies.pyx":492 + * toDot(self.strand), + * toDot(self.frame), + * self.attributes)) # <<<<<<<<<<<<<< + * else: + * return TupleProxy.__str__(self) */ + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attributes); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 492, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); -/* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_10attributes_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_10attributes_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_10attributes_2__set__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_10attributes_2__set__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - __Pyx_RefNannySetupContext("__set__", 0); - - /* "pysam/libctabixproxies.pyx":468 - * return force_str(self._getindex(8)) - * def __set__( self, value): - * if self.hasOwnAttributes: # <<<<<<<<<<<<<< - * free(self._attributes) - * self._attributes = NULL + /* "pysam/libctabixproxies.pyx":484 + * if self.is_modified: + * return "\t".join( + * (self.contig, # <<<<<<<<<<<<<< + * toDot(self.source), + * toDot(self.feature), */ - __pyx_t_1 = (__pyx_v_self->hasOwnAttributes != 0); - if (__pyx_t_1) { - - /* "pysam/libctabixproxies.pyx":469 - * def __set__( self, value): - * if self.hasOwnAttributes: - * free(self._attributes) # <<<<<<<<<<<<<< - * self._attributes = NULL - * self.hasOwnAttributes = False - */ - free(__pyx_v_self->_attributes); - - /* "pysam/libctabixproxies.pyx":470 - * if self.hasOwnAttributes: - * free(self._attributes) - * self._attributes = NULL # <<<<<<<<<<<<<< - * self.hasOwnAttributes = False - * self._setindex(8, value) - */ - __pyx_v_self->_attributes = NULL; + __pyx_t_13 = PyTuple_New(9); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 484, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_13, 5, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_13, 6, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_13, 7, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_13, 8, __pyx_t_12); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_t_7 = 0; + __pyx_t_5 = 0; + __pyx_t_8 = 0; + __pyx_t_6 = 0; + __pyx_t_11 = 0; + __pyx_t_12 = 0; - /* "pysam/libctabixproxies.pyx":471 - * free(self._attributes) - * self._attributes = NULL - * self.hasOwnAttributes = False # <<<<<<<<<<<<<< - * self._setindex(8, value) + /* "pysam/libctabixproxies.pyx":483 * + * if self.is_modified: + * return "\t".join( # <<<<<<<<<<<<<< + * (self.contig, + * toDot(self.source), */ - __pyx_v_self->hasOwnAttributes = 0; + __pyx_t_12 = __Pyx_PyString_Join(__pyx_kp_s__9, __pyx_t_13); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 483, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_r = __pyx_t_12; + __pyx_t_12 = 0; + goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":468 - * return force_str(self._getindex(8)) - * def __set__( self, value): - * if self.hasOwnAttributes: # <<<<<<<<<<<<<< - * free(self._attributes) - * self._attributes = NULL + /* "pysam/libctabixproxies.pyx":482 + * cdef int x + * + * if self.is_modified: # <<<<<<<<<<<<<< + * return "\t".join( + * (self.contig, */ } - /* "pysam/libctabixproxies.pyx":472 - * self._attributes = NULL - * self.hasOwnAttributes = False - * self._setindex(8, value) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":494 + * self.attributes)) + * else: + * return TupleProxy.__str__(self) # <<<<<<<<<<<<<< * - * cdef char * getAttributes(self): + * def invert(self, int lcontig): */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_setindex); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 472, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - __pyx_t_5 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_5 = 1; + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_n_s_str); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 494, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_int_8, __pyx_v_value}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 472, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_int_8, __pyx_v_value}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 472, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 472, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - if (__pyx_t_4) { - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + if (!__pyx_t_11) { + __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_t_13, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 494, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_13)) { + PyObject *__pyx_temp[2] = {__pyx_t_11, ((PyObject *)__pyx_v_self)}; + __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 494, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_12); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) { + PyObject *__pyx_temp[2] = {__pyx_t_11, ((PyObject *)__pyx_v_self)}; + __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 494, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GOTREF(__pyx_t_12); + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 494, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_11); __pyx_t_11 = NULL; + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, ((PyObject *)__pyx_v_self)); + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_6, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 494, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } } - __Pyx_INCREF(__pyx_int_8); - __Pyx_GIVEREF(__pyx_int_8); - PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_int_8); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_value); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 472, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_r = __pyx_t_12; + __pyx_t_12 = 0; + goto __pyx_L0; } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":467 - * else: - * return force_str(self._getindex(8)) - * def __set__( self, value): # <<<<<<<<<<<<<< - * if self.hasOwnAttributes: - * free(self._attributes) + /* "pysam/libctabixproxies.pyx":478 + * self._setindex(8, attribute_string) + * + * def __str__(self): # <<<<<<<<<<<<<< + * cdef char * cpy + * cdef int x */ /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.attributes.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":474 - * self._setindex(8, value) - * - * cdef char * getAttributes(self): # <<<<<<<<<<<<<< - * '''return pointer to attributes.''' - * cdef char * attributes - */ - -static char *__pyx_f_5pysam_16libctabixproxies_8GTFProxy_getAttributes(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { - char *__pyx_v_attributes; - char *__pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - char *__pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannySetupContext("getAttributes", 0); - - /* "pysam/libctabixproxies.pyx":477 - * '''return pointer to attributes.''' - * cdef char * attributes - * if self.hasOwnAttributes: # <<<<<<<<<<<<<< - * attributes = self._attributes - * else: - */ - __pyx_t_1 = (__pyx_v_self->hasOwnAttributes != 0); - if (__pyx_t_1) { - - /* "pysam/libctabixproxies.pyx":478 - * cdef char * attributes - * if self.hasOwnAttributes: - * attributes = self._attributes # <<<<<<<<<<<<<< - * else: - * attributes = self.fields[8] - */ - __pyx_t_2 = __pyx_v_self->_attributes; - __pyx_v_attributes = __pyx_t_2; - - /* "pysam/libctabixproxies.pyx":477 - * '''return pointer to attributes.''' - * cdef char * attributes - * if self.hasOwnAttributes: # <<<<<<<<<<<<<< - * attributes = self._attributes - * else: - */ - goto __pyx_L3; - } - - /* "pysam/libctabixproxies.pyx":480 - * attributes = self._attributes - * else: - * attributes = self.fields[8] # <<<<<<<<<<<<<< - * if attributes == NULL: - * raise KeyError("no attributes defined GTF entry") - */ - /*else*/ { - __pyx_v_attributes = (__pyx_v_self->__pyx_base.fields[8]); - } - __pyx_L3:; - - /* "pysam/libctabixproxies.pyx":481 - * else: - * attributes = self.fields[8] - * if attributes == NULL: # <<<<<<<<<<<<<< - * raise KeyError("no attributes defined GTF entry") - * return attributes - */ - __pyx_t_1 = ((__pyx_v_attributes == NULL) != 0); - if (unlikely(__pyx_t_1)) { - - /* "pysam/libctabixproxies.pyx":482 - * attributes = self.fields[8] - * if attributes == NULL: - * raise KeyError("no attributes defined GTF entry") # <<<<<<<<<<<<<< - * return attributes - * - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 482, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 482, __pyx_L1_error) - - /* "pysam/libctabixproxies.pyx":481 - * else: - * attributes = self.fields[8] - * if attributes == NULL: # <<<<<<<<<<<<<< - * raise KeyError("no attributes defined GTF entry") - * return attributes - */ - } - - /* "pysam/libctabixproxies.pyx":483 - * if attributes == NULL: - * raise KeyError("no attributes defined GTF entry") - * return attributes # <<<<<<<<<<<<<< - * - * def asDict(self): - */ - __pyx_r = __pyx_v_attributes; - goto __pyx_L0; - - /* "pysam/libctabixproxies.pyx":474 - * self._setindex(8, value) +/* "pysam/libctabixproxies.pyx":496 + * return TupleProxy.__str__(self) * - * cdef char * getAttributes(self): # <<<<<<<<<<<<<< - * '''return pointer to attributes.''' - * cdef char * attributes - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_WriteUnraisable("pysam.libctabixproxies.GTFProxy.getAttributes", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libctabixproxies.pyx":485 - * return attributes + * def invert(self, int lcontig): # <<<<<<<<<<<<<< + * '''invert coordinates to negative strand coordinates * - * def asDict(self): # <<<<<<<<<<<<<< - * """parse attributes - return as dict - * """ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_9asDict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_8asDict[] = "parse attributes - return as dict\n "; -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_9asDict(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_15invert(PyObject *__pyx_v_self, PyObject *__pyx_arg_lcontig); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_14invert[] = "invert coordinates to negative strand coordinates\n \n This method will only act if the feature is on the\n negative strand."; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_15invert(PyObject *__pyx_v_self, PyObject *__pyx_arg_lcontig) { + int __pyx_v_lcontig; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("asDict (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_8asDict(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("invert (wrapper)", 0); + assert(__pyx_arg_lcontig); { + __pyx_v_lcontig = __Pyx_PyInt_As_int(__pyx_arg_lcontig); if (unlikely((__pyx_v_lcontig == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 496, __pyx_L3_error) + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.invert", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_14invert(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((int)__pyx_v_lcontig)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_8asDict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { - PyObject *__pyx_v_attributes = NULL; - PyObject *__pyx_v_fields = NULL; - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_f = NULL; - PyObject *__pyx_v_d = NULL; - PyObject *__pyx_v_n = NULL; - PyObject *__pyx_v_v = NULL; - PyObject *__pyx_v_x = NULL; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_14invert(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, int __pyx_v_lcontig) { + PyObject *__pyx_v_start = NULL; + PyObject *__pyx_v_end = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; + int __pyx_t_3; PyObject *__pyx_t_4 = NULL; - Py_ssize_t __pyx_t_5; - PyObject *(*__pyx_t_6)(PyObject *); - PyObject *__pyx_t_7 = NULL; - int __pyx_t_8; - Py_ssize_t __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - int __pyx_t_11; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - int __pyx_t_15; - __Pyx_RefNannySetupContext("asDict", 0); + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("invert", 0); - /* "pysam/libctabixproxies.pyx":490 - * - * # remove comments - * attributes = self.attributes # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":502 + * negative strand.''' * - * # separate into fields + * if self.strand[0] == '-': # <<<<<<<<<<<<<< + * start = min(self.start, self.end) + * end = max(self.start, self.end) */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attributes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 502, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_v_attributes = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 502, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s__17, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 502, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_3) { - /* "pysam/libctabixproxies.pyx":500 - * - * # Remove white space to prevent a last empty field. - * fields = [x.strip() for x in attributes.strip().split("; ")] # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":503 * - * result = collections.OrderedDict() - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_attributes, __pyx_n_s_strip); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 500, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0; - __pyx_t_6 = NULL; - } else { - __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 500, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_6)) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 500, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 500, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } + * if self.strand[0] == '-': + * start = min(self.start, self.end) # <<<<<<<<<<<<<< + * end = max(self.start, self.end) + * self.start, self.end = lcontig - end, lcontig - start + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_end); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 503, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 503, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 503, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_3) { + __Pyx_INCREF(__pyx_t_2); + __pyx_t_4 = __pyx_t_2; } else { - __pyx_t_2 = __pyx_t_6(__pyx_t_3); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 500, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_4 = __pyx_t_1; } - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __pyx_t_4; + __Pyx_INCREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_start = __pyx_t_2; __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_n_s_strip); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 500, __pyx_L1_error) + + /* "pysam/libctabixproxies.pyx":504 + * if self.strand[0] == '-': + * start = min(self.start, self.end) + * end = max(self.start, self.end) # <<<<<<<<<<<<<< + * self.start, self.end = lcontig - end, lcontig - start + * + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_end); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 504, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - if (__pyx_t_7) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_4, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 504, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 504, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_3) { + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = __pyx_t_2; } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 500, __pyx_L1_error) + __Pyx_INCREF(__pyx_t_4); + __pyx_t_1 = __pyx_t_4; } - __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 500, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_fields = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_2 = __pyx_t_1; + __Pyx_INCREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_end = __pyx_t_2; + __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":502 - * fields = [x.strip() for x in attributes.strip().split("; ")] + /* "pysam/libctabixproxies.pyx":505 + * start = min(self.start, self.end) + * end = max(self.start, self.end) + * self.start, self.end = lcontig - end, lcontig - start # <<<<<<<<<<<<<< * - * result = collections.OrderedDict() # <<<<<<<<<<<<<< + * def keys(self): + */ + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lcontig); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 505, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyNumber_Subtract(__pyx_t_2, __pyx_v_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 505, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lcontig); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 505, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyNumber_Subtract(__pyx_t_2, __pyx_v_start); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 505, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start, __pyx_t_1) < 0) __PYX_ERR(0, 505, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_end, __pyx_t_4) < 0) __PYX_ERR(0, 505, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libctabixproxies.pyx":502 + * negative strand.''' * - * for f in fields: + * if self.strand[0] == '-': # <<<<<<<<<<<<<< + * start = min(self.start, self.end) + * end = max(self.start, self.end) */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } } - if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 502, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 502, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_result = __pyx_t_1; - __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":504 - * result = collections.OrderedDict() + /* "pysam/libctabixproxies.pyx":496 + * return TupleProxy.__str__(self) * - * for f in fields: # <<<<<<<<<<<<<< + * def invert(self, int lcontig): # <<<<<<<<<<<<<< + * '''invert coordinates to negative strand coordinates * - * # strip semicolon (GTF files without a space after the last semicolon) */ - __pyx_t_1 = __pyx_v_fields; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; - for (;;) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 504, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 504, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - __Pyx_XDECREF_SET(__pyx_v_f, __pyx_t_2); - __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":507 - * - * # strip semicolon (GTF files without a space after the last semicolon) - * if f.endswith(";"): # <<<<<<<<<<<<<< - * f = f[:-1] + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.invert", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_start); + __Pyx_XDECREF(__pyx_v_end); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libctabixproxies.pyx":507 + * self.start, self.end = lcontig - end, lcontig - start * + * def keys(self): # <<<<<<<<<<<<<< + * '''return a list of attributes defined in this entry.''' + * if not self.attribute_dict: */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_f, __pyx_n_s_endswith); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 507, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_8) { - /* "pysam/libctabixproxies.pyx":508 - * # strip semicolon (GTF files without a space after the last semicolon) - * if f.endswith(";"): - * f = f[:-1] # <<<<<<<<<<<<<< - * - * # split at most once in order to avoid separating +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_17keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_16keys[] = "return a list of attributes defined in this entry."; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_17keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("keys (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_16keys(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_16keys(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("keys", 0); + + /* "pysam/libctabixproxies.pyx":509 + * def keys(self): + * '''return a list of attributes defined in this entry.''' + * if not self.attribute_dict: # <<<<<<<<<<<<<< + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) */ - __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_v_f, 0, -1L, NULL, NULL, &__pyx_slice__29, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 508, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF_SET(__pyx_v_f, __pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->attribute_dict); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 509, __pyx_L1_error) + __pyx_t_2 = ((!__pyx_t_1) != 0); + if (__pyx_t_2) { - /* "pysam/libctabixproxies.pyx":507 - * - * # strip semicolon (GTF files without a space after the last semicolon) - * if f.endswith(";"): # <<<<<<<<<<<<<< - * f = f[:-1] - * + /* "pysam/libctabixproxies.pyx":510 + * '''return a list of attributes defined in this entry.''' + * if not self.attribute_dict: + * self.attribute_dict = self.attribute_string2dict( # <<<<<<<<<<<<<< + * self.attributes) + * return self.attribute_dict.keys() */ - } + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attribute_string2dict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 510, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libctabixproxies.pyx":512 - * # split at most once in order to avoid separating - * # multi-word values - * d = [x.strip() for x in f.split(" ", 1)] # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":511 + * if not self.attribute_dict: + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) # <<<<<<<<<<<<<< + * return self.attribute_dict.keys() * - * n,v = d[0], d[1] */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_f, __pyx_n_s_split); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_2 = __pyx_t_4; __Pyx_INCREF(__pyx_t_2); __pyx_t_9 = 0; - __pyx_t_6 = NULL; - } else { - __pyx_t_9 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 512, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attributes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 511, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (likely(!__pyx_t_6)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 512, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } else { - if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_4); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 512, __pyx_L1_error) - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - #endif - } - } else { - __pyx_t_4 = __pyx_t_6(__pyx_t_2); - if (unlikely(!__pyx_t_4)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 512, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_n_s_strip); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_7); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_7, function); - } - } - if (__pyx_t_10) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else { - __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 512, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF_SET(__pyx_v_d, ((PyObject*)__pyx_t_3)); - __pyx_t_3 = 0; - - /* "pysam/libctabixproxies.pyx":514 - * d = [x.strip() for x in f.split(" ", 1)] - * - * n,v = d[0], d[1] # <<<<<<<<<<<<<< - * if len(d) > 2: - * v = d[1:] - */ - __pyx_t_3 = __Pyx_GetItemInt_List(__pyx_v_d, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 514, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_d, 1, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 514, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_3); - __pyx_t_3 = 0; - __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pysam/libctabixproxies.pyx":515 - * - * n,v = d[0], d[1] - * if len(d) > 2: # <<<<<<<<<<<<<< - * v = d[1:] - * - */ - __pyx_t_9 = PyList_GET_SIZE(__pyx_v_d); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 515, __pyx_L1_error) - __pyx_t_8 = ((__pyx_t_9 > 2) != 0); - if (__pyx_t_8) { - - /* "pysam/libctabixproxies.pyx":516 - * n,v = d[0], d[1] - * if len(d) > 2: - * v = d[1:] # <<<<<<<<<<<<<< - * - * if v[0] == '"' and v[-1] == '"': - */ - __pyx_t_2 = __Pyx_PyList_GetSlice(__pyx_v_d, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 516, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF_SET(__pyx_v_v, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pysam/libctabixproxies.pyx":515 - * - * n,v = d[0], d[1] - * if len(d) > 2: # <<<<<<<<<<<<<< - * v = d[1:] - * - */ - } - - /* "pysam/libctabixproxies.pyx":518 - * v = d[1:] - * - * if v[0] == '"' and v[-1] == '"': # <<<<<<<<<<<<<< - * v = v[1:-1] - * else: - */ - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_v, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 518, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s__32, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 518, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_11) { + if (!__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 510, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); } else { - __pyx_t_8 = __pyx_t_11; - goto __pyx_L12_bool_binop_done; - } - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_v, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 518, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s__32, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 518, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = __pyx_t_11; - __pyx_L12_bool_binop_done:; - if (__pyx_t_8) { - - /* "pysam/libctabixproxies.pyx":519 - * - * if v[0] == '"' and v[-1] == '"': - * v = v[1:-1] # <<<<<<<<<<<<<< - * else: - * ## try to convert to a value - */ - __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_v, 1, -1L, NULL, NULL, &__pyx_slice__33, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 519, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF_SET(__pyx_v_v, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pysam/libctabixproxies.pyx":518 - * v = d[1:] - * - * if v[0] == '"' and v[-1] == '"': # <<<<<<<<<<<<<< - * v = v[1:-1] - * else: - */ - goto __pyx_L11; - } - - /* "pysam/libctabixproxies.pyx":522 - * else: - * ## try to convert to a value - * try: # <<<<<<<<<<<<<< - * v = float(v) - * v = int(v) - */ - /*else*/ { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 510, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 510, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif { - __Pyx_PyThreadState_declare - __Pyx_PyThreadState_assign - __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14); - __Pyx_XGOTREF(__pyx_t_12); - __Pyx_XGOTREF(__pyx_t_13); - __Pyx_XGOTREF(__pyx_t_14); - /*try:*/ { - - /* "pysam/libctabixproxies.pyx":523 - * ## try to convert to a value - * try: - * v = float(v) # <<<<<<<<<<<<<< - * v = int(v) - * except ValueError: - */ - __pyx_t_2 = __Pyx_PyNumber_Float(__pyx_v_v); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 523, __pyx_L14_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF_SET(__pyx_v_v, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pysam/libctabixproxies.pyx":524 - * try: - * v = float(v) - * v = int(v) # <<<<<<<<<<<<<< - * except ValueError: - * pass - */ - __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_v_v); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 524, __pyx_L14_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF_SET(__pyx_v_v, __pyx_t_2); - __pyx_t_2 = 0; - - /* "pysam/libctabixproxies.pyx":522 - * else: - * ## try to convert to a value - * try: # <<<<<<<<<<<<<< - * v = float(v) - * v = int(v) - */ - } - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - goto __pyx_L21_try_end; - __pyx_L14_error:; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "pysam/libctabixproxies.pyx":525 - * v = float(v) - * v = int(v) - * except ValueError: # <<<<<<<<<<<<<< - * pass - * except TypeError: - */ - __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError); - if (__pyx_t_15) { - __Pyx_ErrRestore(0,0,0); - goto __pyx_L15_exception_handled; - } - - /* "pysam/libctabixproxies.pyx":527 - * except ValueError: - * pass - * except TypeError: # <<<<<<<<<<<<<< - * pass - * - */ - __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError); - if (__pyx_t_15) { - __Pyx_ErrRestore(0,0,0); - goto __pyx_L15_exception_handled; - } - goto __pyx_L16_except_error; - __pyx_L16_except_error:; - - /* "pysam/libctabixproxies.pyx":522 - * else: - * ## try to convert to a value - * try: # <<<<<<<<<<<<<< - * v = float(v) - * v = int(v) - */ - __Pyx_XGIVEREF(__pyx_t_12); - __Pyx_XGIVEREF(__pyx_t_13); - __Pyx_XGIVEREF(__pyx_t_14); - __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14); - goto __pyx_L1_error; - __pyx_L15_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_12); - __Pyx_XGIVEREF(__pyx_t_13); - __Pyx_XGIVEREF(__pyx_t_14); - __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14); - __pyx_L21_try_end:; + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 510, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 510, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } - __pyx_L11:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":530 - * pass - * - * result[n] = v # <<<<<<<<<<<<<< - * - * return result + /* "pysam/libctabixproxies.pyx":510 + * '''return a list of attributes defined in this entry.''' + * if not self.attribute_dict: + * self.attribute_dict = self.attribute_string2dict( # <<<<<<<<<<<<<< + * self.attributes) + * return self.attribute_dict.keys() */ - if (unlikely(PyObject_SetItem(__pyx_v_result, __pyx_v_n, __pyx_v_v) < 0)) __PYX_ERR(0, 530, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->attribute_dict); + __Pyx_DECREF(__pyx_v_self->attribute_dict); + __pyx_v_self->attribute_dict = __pyx_t_3; + __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":504 - * result = collections.OrderedDict() - * - * for f in fields: # <<<<<<<<<<<<<< - * - * # strip semicolon (GTF files without a space after the last semicolon) + /* "pysam/libctabixproxies.pyx":509 + * def keys(self): + * '''return a list of attributes defined in this entry.''' + * if not self.attribute_dict: # <<<<<<<<<<<<<< + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) */ } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":532 - * result[n] = v - * - * return result # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":512 + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) + * return self.attribute_dict.keys() # <<<<<<<<<<<<<< * - * def fromDict(self, d): + * def __getitem__(self, key): */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result); - __pyx_r = __pyx_v_result; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->attribute_dict, __pyx_n_s_keys); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 512, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (__pyx_t_7) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 512, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else { + __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 512, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":485 - * return attributes + /* "pysam/libctabixproxies.pyx":507 + * self.start, self.end = lcontig - end, lcontig - start * - * def asDict(self): # <<<<<<<<<<<<<< - * """parse attributes - return as dict - * """ + * def keys(self): # <<<<<<<<<<<<<< + * '''return a list of attributes defined in this entry.''' + * if not self.attribute_dict: */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.asDict", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_attributes); - __Pyx_XDECREF(__pyx_v_fields); - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_f); - __Pyx_XDECREF(__pyx_v_d); - __Pyx_XDECREF(__pyx_v_n); - __Pyx_XDECREF(__pyx_v_v); - __Pyx_XDECREF(__pyx_v_x); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":534 - * return result +/* "pysam/libctabixproxies.pyx":514 + * return self.attribute_dict.keys() + * + * def __getitem__(self, key): # <<<<<<<<<<<<<< + * return self.__getattr__(key) * - * def fromDict(self, d): # <<<<<<<<<<<<<< - * '''set attributes from a dictionary.''' - * cdef char * p */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_11fromDict(PyObject *__pyx_v_self, PyObject *__pyx_v_d); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_10fromDict[] = "set attributes from a dictionary."; -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_11fromDict(PyObject *__pyx_v_self, PyObject *__pyx_v_d) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_19__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_19__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fromDict (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_10fromDict(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_d)); + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_18__getitem__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_key)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_10fromDict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_d) { - char *__pyx_v_p; - int __pyx_v_l; - PyObject *__pyx_v_aa = NULL; - PyObject *__pyx_v_k = NULL; - PyObject *__pyx_v_v = NULL; - PyObject *__pyx_v_a = NULL; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_18__getitem__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_key) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; + PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - Py_ssize_t __pyx_t_5; - PyObject *(*__pyx_t_6)(PyObject *); - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *(*__pyx_t_9)(PyObject *); - int __pyx_t_10; - int __pyx_t_11; - char *__pyx_t_12; - __Pyx_RefNannySetupContext("fromDict", 0); - - /* "pysam/libctabixproxies.pyx":540 - * - * # clean up if this field is set twice - * if self.hasOwnAttributes: # <<<<<<<<<<<<<< - * free(self._attributes) - * - */ - __pyx_t_1 = (__pyx_v_self->hasOwnAttributes != 0); - if (__pyx_t_1) { - - /* "pysam/libctabixproxies.pyx":541 - * # clean up if this field is set twice - * if self.hasOwnAttributes: - * free(self._attributes) # <<<<<<<<<<<<<< - * - * aa = [] - */ - free(__pyx_v_self->_attributes); + __Pyx_RefNannySetupContext("__getitem__", 0); - /* "pysam/libctabixproxies.pyx":540 - * - * # clean up if this field is set twice - * if self.hasOwnAttributes: # <<<<<<<<<<<<<< - * free(self._attributes) + /* "pysam/libctabixproxies.pyx":515 * - */ - } - - /* "pysam/libctabixproxies.pyx":543 - * free(self._attributes) + * def __getitem__(self, key): + * return self.__getattr__(key) # <<<<<<<<<<<<<< * - * aa = [] # <<<<<<<<<<<<<< - * for k,v in d.items(): - * if isinstance(v, str): + * def setAttribute(self, name, value): */ - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 543, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getattr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 515, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_v_aa = ((PyObject*)__pyx_t_2); - __pyx_t_2 = 0; - - /* "pysam/libctabixproxies.pyx":544 - * - * aa = [] - * for k,v in d.items(): # <<<<<<<<<<<<<< - * if isinstance(v, str): - * aa.append( '%s "%s"' % (k,v) ) - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_d, __pyx_n_s_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); + __Pyx_DECREF_SET(__pyx_t_2, function); } } - if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 544, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0; - __pyx_t_6 = NULL; + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 515, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); } else { - __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 544, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (likely(!__pyx_t_6)) { - if (likely(PyList_CheckExact(__pyx_t_3))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 544, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } else { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 544, __pyx_L1_error) - #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - #endif - } - } else { - __pyx_t_2 = __pyx_t_6(__pyx_t_3); - if (unlikely(!__pyx_t_2)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 544, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 544, __pyx_L1_error) - } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); - } else { - __pyx_t_4 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_7); - #else - __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 544, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; - index = 0; __pyx_t_4 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_4)) goto __pyx_L6_unpacking_failed; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_key}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 515, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_key}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 515, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 515, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) __PYX_ERR(0, 544, __pyx_L1_error) - __pyx_t_9 = NULL; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 544, __pyx_L1_error) - __pyx_L7_unpacking_done:; - } - __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_4); - __pyx_t_4 = 0; - __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_7); - __pyx_t_7 = 0; - - /* "pysam/libctabixproxies.pyx":545 - * aa = [] - * for k,v in d.items(): - * if isinstance(v, str): # <<<<<<<<<<<<<< - * aa.append( '%s "%s"' % (k,v) ) - * else: - */ - __pyx_t_1 = PyString_Check(__pyx_v_v); - __pyx_t_10 = (__pyx_t_1 != 0); - if (__pyx_t_10) { - - /* "pysam/libctabixproxies.pyx":546 - * for k,v in d.items(): - * if isinstance(v, str): - * aa.append( '%s "%s"' % (k,v) ) # <<<<<<<<<<<<<< - * else: - * aa.append( '%s %s' % (k,str(v)) ) - */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 546, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_k); - __Pyx_GIVEREF(__pyx_v_k); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_k); - __Pyx_INCREF(__pyx_v_v); - __Pyx_GIVEREF(__pyx_v_v); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_v); - __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 546, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_aa, __pyx_t_7); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 546, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "pysam/libctabixproxies.pyx":545 - * aa = [] - * for k,v in d.items(): - * if isinstance(v, str): # <<<<<<<<<<<<<< - * aa.append( '%s "%s"' % (k,v) ) - * else: - */ - goto __pyx_L8; - } - - /* "pysam/libctabixproxies.pyx":548 - * aa.append( '%s "%s"' % (k,v) ) - * else: - * aa.append( '%s %s' % (k,str(v)) ) # <<<<<<<<<<<<<< - * - * a = force_bytes("; ".join(aa) + ";") - */ - /*else*/ { - __pyx_t_7 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_v); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 548, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 548, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_k); - __Pyx_GIVEREF(__pyx_v_k); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_k); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_s_s_2, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 548, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_aa, __pyx_t_7); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 548, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_key); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 515, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - __pyx_L8:; - - /* "pysam/libctabixproxies.pyx":544 - * - * aa = [] - * for k,v in d.items(): # <<<<<<<<<<<<<< - * if isinstance(v, str): - * aa.append( '%s "%s"' % (k,v) ) - */ - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "pysam/libctabixproxies.pyx":550 - * aa.append( '%s %s' % (k,str(v)) ) - * - * a = force_bytes("; ".join(aa) + ";") # <<<<<<<<<<<<<< - * p = a - * l = len(a) - */ - __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__25, __pyx_v_aa); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 550, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PyNumber_Add(__pyx_t_3, __pyx_kp_s__27); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 550, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 550, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_a = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - - /* "pysam/libctabixproxies.pyx":551 - * - * a = force_bytes("; ".join(aa) + ";") - * p = a # <<<<<<<<<<<<<< - * l = len(a) - * self._attributes = calloc(l + 1, sizeof(char)) - */ - if (unlikely(__pyx_v_a == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 551, __pyx_L1_error) - } - __pyx_t_12 = __Pyx_PyBytes_AsWritableString(__pyx_v_a); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 551, __pyx_L1_error) - __pyx_v_p = __pyx_t_12; - - /* "pysam/libctabixproxies.pyx":552 - * a = force_bytes("; ".join(aa) + ";") - * p = a - * l = len(a) # <<<<<<<<<<<<<< - * self._attributes = calloc(l + 1, sizeof(char)) - * if self._attributes == NULL: - */ - if (unlikely(__pyx_v_a == Py_None)) { - PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 552, __pyx_L1_error) - } - __pyx_t_5 = PyBytes_GET_SIZE(__pyx_v_a); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 552, __pyx_L1_error) - __pyx_v_l = __pyx_t_5; - - /* "pysam/libctabixproxies.pyx":553 - * p = a - * l = len(a) - * self._attributes = calloc(l + 1, sizeof(char)) # <<<<<<<<<<<<<< - * if self._attributes == NULL: - * raise ValueError("out of memory") - */ - __pyx_v_self->_attributes = ((char *)calloc((__pyx_v_l + 1), (sizeof(char)))); - - /* "pysam/libctabixproxies.pyx":554 - * l = len(a) - * self._attributes = calloc(l + 1, sizeof(char)) - * if self._attributes == NULL: # <<<<<<<<<<<<<< - * raise ValueError("out of memory") - * memcpy(self._attributes, p, l) - */ - __pyx_t_10 = ((__pyx_v_self->_attributes == NULL) != 0); - if (unlikely(__pyx_t_10)) { - - /* "pysam/libctabixproxies.pyx":555 - * self._attributes = calloc(l + 1, sizeof(char)) - * if self._attributes == NULL: - * raise ValueError("out of memory") # <<<<<<<<<<<<<< - * memcpy(self._attributes, p, l) - * - */ - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 555, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 555, __pyx_L1_error) - - /* "pysam/libctabixproxies.pyx":554 - * l = len(a) - * self._attributes = calloc(l + 1, sizeof(char)) - * if self._attributes == NULL: # <<<<<<<<<<<<<< - * raise ValueError("out of memory") - * memcpy(self._attributes, p, l) - */ } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":556 - * if self._attributes == NULL: - * raise ValueError("out of memory") - * memcpy(self._attributes, p, l) # <<<<<<<<<<<<<< - * - * self.hasOwnAttributes = True - */ - (void)(memcpy(__pyx_v_self->_attributes, __pyx_v_p, __pyx_v_l)); - - /* "pysam/libctabixproxies.pyx":558 - * memcpy(self._attributes, p, l) - * - * self.hasOwnAttributes = True # <<<<<<<<<<<<<< - * self.is_modified = True - * - */ - __pyx_v_self->hasOwnAttributes = 1; - - /* "pysam/libctabixproxies.pyx":559 - * - * self.hasOwnAttributes = True - * self.is_modified = True # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":514 + * return self.attribute_dict.keys() * - * def __str__(self): - */ - __pyx_v_self->__pyx_base.is_modified = 1; - - /* "pysam/libctabixproxies.pyx":534 - * return result + * def __getitem__(self, key): # <<<<<<<<<<<<<< + * return self.__getattr__(key) * - * def fromDict(self, d): # <<<<<<<<<<<<<< - * '''set attributes from a dictionary.''' - * cdef char * p */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.fromDict", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_aa); - __Pyx_XDECREF(__pyx_v_k); - __Pyx_XDECREF(__pyx_v_v); - __Pyx_XDECREF(__pyx_v_a); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":561 - * self.is_modified = True +/* "pysam/libctabixproxies.pyx":517 + * return self.__getattr__(key) * - * def __str__(self): # <<<<<<<<<<<<<< - * cdef char * cpy - * cdef int x + * def setAttribute(self, name, value): # <<<<<<<<<<<<<< + * '''convenience method to set an attribute. + * ''' */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_13__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_13__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_21setAttribute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_20setAttribute[] = "convenience method to set an attribute.\n "; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_21setAttribute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_name = 0; + PyObject *__pyx_v_value = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_12__str__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("setAttribute (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,&__pyx_n_s_value,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("setAttribute", 1, 2, 2, 1); __PYX_ERR(0, 517, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setAttribute") < 0)) __PYX_ERR(0, 517, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_name = values[0]; + __pyx_v_value = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("setAttribute", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 517, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.setAttribute", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_20setAttribute(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), __pyx_v_name, __pyx_v_value); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_12__str__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_20setAttribute(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_value) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; + int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - __Pyx_RefNannySetupContext("__str__", 0); - - /* "pysam/libctabixproxies.pyx":565 - * cdef int x - * - * if self.is_modified: # <<<<<<<<<<<<<< - * return "\t".join( - * (self.contig, - */ - __pyx_t_1 = (__pyx_v_self->__pyx_base.is_modified != 0); - if (__pyx_t_1) { - - /* "pysam/libctabixproxies.pyx":566 - * - * if self.is_modified: - * return "\t".join( # <<<<<<<<<<<<<< - * (self.contig, - * self.source, - */ - __Pyx_XDECREF(__pyx_r); - - /* "pysam/libctabixproxies.pyx":567 - * if self.is_modified: - * return "\t".join( - * (self.contig, # <<<<<<<<<<<<<< - * self.source, - * self.feature, - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contig); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __Pyx_RefNannySetupContext("setAttribute", 0); - /* "pysam/libctabixproxies.pyx":568 - * return "\t".join( - * (self.contig, - * self.source, # <<<<<<<<<<<<<< - * self.feature, - * str(self.start+1), + /* "pysam/libctabixproxies.pyx":520 + * '''convenience method to set an attribute. + * ''' + * if not self.attribute_dict: # <<<<<<<<<<<<<< + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_source); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 568, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->attribute_dict); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 520, __pyx_L1_error) + __pyx_t_2 = ((!__pyx_t_1) != 0); + if (__pyx_t_2) { - /* "pysam/libctabixproxies.pyx":569 - * (self.contig, - * self.source, - * self.feature, # <<<<<<<<<<<<<< - * str(self.start+1), - * str(self.end), + /* "pysam/libctabixproxies.pyx":521 + * ''' + * if not self.attribute_dict: + * self.attribute_dict = self.attribute_string2dict( # <<<<<<<<<<<<<< + * self.attributes) + * self.attribute_dict[name] = value */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_feature); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 569, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attribute_string2dict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 521, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - /* "pysam/libctabixproxies.pyx":570 - * self.source, - * self.feature, - * str(self.start+1), # <<<<<<<<<<<<<< - * str(self.end), - * toDot(self.score), + /* "pysam/libctabixproxies.pyx":522 + * if not self.attribute_dict: + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) # <<<<<<<<<<<<<< + * self.attribute_dict[name] = value + * self.is_modified = True */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 570, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_t_5, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 570, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 570, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attributes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 522, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pysam/libctabixproxies.pyx":571 - * self.feature, - * str(self.start+1), - * str(self.end), # <<<<<<<<<<<<<< - * toDot(self.score), - * toDot(self.strand), - */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_end); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 571, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "pysam/libctabixproxies.pyx":572 - * str(self.start+1), - * str(self.end), - * toDot(self.score), # <<<<<<<<<<<<<< - * toDot(self.strand), - * toDot(self.frame), - */ - __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_toDot); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_score); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_10); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); + __Pyx_DECREF_SET(__pyx_t_4, function); } } - if (!__pyx_t_10) { - __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 572, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_6); + if (!__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9}; - __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 572, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { - PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9}; - __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 572, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { - __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL; - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 572, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 521, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":573 - * str(self.end), - * toDot(self.score), - * toDot(self.strand), # <<<<<<<<<<<<<< - * toDot(self.frame), - * self.attributes)) + /* "pysam/libctabixproxies.pyx":521 + * ''' + * if not self.attribute_dict: + * self.attribute_dict = self.attribute_string2dict( # <<<<<<<<<<<<<< + * self.attributes) + * self.attribute_dict[name] = value */ - __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_toDot); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 573, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 573, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_11, function); - } - } - if (!__pyx_t_10) { - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 573, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_8); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9}; - __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 573, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { - PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9}; - __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 573, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - { - __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 573, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL; - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 573, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - } - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->attribute_dict); + __Pyx_DECREF(__pyx_v_self->attribute_dict); + __pyx_v_self->attribute_dict = __pyx_t_3; + __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":574 - * toDot(self.score), - * toDot(self.strand), - * toDot(self.frame), # <<<<<<<<<<<<<< - * self.attributes)) - * else: + /* "pysam/libctabixproxies.pyx":520 + * '''convenience method to set an attribute. + * ''' + * if not self.attribute_dict: # <<<<<<<<<<<<<< + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) */ - __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_toDot); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 574, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_frame); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 574, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { - __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_12); - if (likely(__pyx_t_10)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_12, function); - } - } - if (!__pyx_t_10) { - __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 574, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_11); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9}; - __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 574, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) { - PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9}; - __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 574, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } else - #endif - { - __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 574, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_10); __pyx_t_10 = NULL; - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_13, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 574, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - } - } - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } - /* "pysam/libctabixproxies.pyx":575 - * toDot(self.strand), - * toDot(self.frame), - * self.attributes)) # <<<<<<<<<<<<<< - * else: - * return TupleProxy.__str__(self) - */ - __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attributes); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 575, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - - /* "pysam/libctabixproxies.pyx":567 - * if self.is_modified: - * return "\t".join( - * (self.contig, # <<<<<<<<<<<<<< - * self.source, - * self.feature, - */ - __pyx_t_13 = PyTuple_New(9); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 567, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_13, 5, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_13, 6, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_13, 7, __pyx_t_11); - __Pyx_GIVEREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_13, 8, __pyx_t_12); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_t_5 = 0; - __pyx_t_7 = 0; - __pyx_t_6 = 0; - __pyx_t_8 = 0; - __pyx_t_11 = 0; - __pyx_t_12 = 0; - - /* "pysam/libctabixproxies.pyx":566 - * - * if self.is_modified: - * return "\t".join( # <<<<<<<<<<<<<< - * (self.contig, - * self.source, - */ - __pyx_t_12 = __Pyx_PyString_Join(__pyx_kp_s__9, __pyx_t_13); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 566, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_r = __pyx_t_12; - __pyx_t_12 = 0; - goto __pyx_L0; - - /* "pysam/libctabixproxies.pyx":565 - * cdef int x + /* "pysam/libctabixproxies.pyx":523 + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) + * self.attribute_dict[name] = value # <<<<<<<<<<<<<< + * self.is_modified = True * - * if self.is_modified: # <<<<<<<<<<<<<< - * return "\t".join( - * (self.contig, */ - } + if (unlikely(PyObject_SetItem(__pyx_v_self->attribute_dict, __pyx_v_name, __pyx_v_value) < 0)) __PYX_ERR(0, 523, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":577 - * self.attributes)) - * else: - * return TupleProxy.__str__(self) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":524 + * self.attributes) + * self.attribute_dict[name] = value + * self.is_modified = True # <<<<<<<<<<<<<< * - * def invert(self, int lcontig): + * def attribute_string2dict(self, s): */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_n_s_str); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 577, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_11 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - if (!__pyx_t_11) { - __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_t_13, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 577, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_13)) { - PyObject *__pyx_temp[2] = {__pyx_t_11, ((PyObject *)__pyx_v_self)}; - __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 577, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_12); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) { - PyObject *__pyx_temp[2] = {__pyx_t_11, ((PyObject *)__pyx_v_self)}; - __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 577, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_12); - } else - #endif - { - __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 577, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_8); - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_11); __pyx_t_11 = NULL; - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_8, 0+1, ((PyObject *)__pyx_v_self)); - __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_8, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 577, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - } - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_r = __pyx_t_12; - __pyx_t_12 = 0; - goto __pyx_L0; - } + __pyx_v_self->__pyx_base.__pyx_base.is_modified = 1; - /* "pysam/libctabixproxies.pyx":561 - * self.is_modified = True + /* "pysam/libctabixproxies.pyx":517 + * return self.__getattr__(key) * - * def __str__(self): # <<<<<<<<<<<<<< - * cdef char * cpy - * cdef int x + * def setAttribute(self, name, value): # <<<<<<<<<<<<<< + * '''convenience method to set an attribute. + * ''' */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.setAttribute", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -10494,378 +9940,284 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_12__str__(struct _ return __pyx_r; } -/* "pysam/libctabixproxies.pyx":579 - * return TupleProxy.__str__(self) - * - * def invert(self, int lcontig): # <<<<<<<<<<<<<< - * '''invert coordinates to negative strand coordinates +/* "pysam/libctabixproxies.pyx":526 + * self.is_modified = True * + * def attribute_string2dict(self, s): # <<<<<<<<<<<<<< + * return collections.OrderedDict( + * self.attribute_string2iterator(s)) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_15invert(PyObject *__pyx_v_self, PyObject *__pyx_arg_lcontig); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_14invert[] = "invert coordinates to negative strand coordinates\n \n This method will only act if the feature is on the\n negative strand."; -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_15invert(PyObject *__pyx_v_self, PyObject *__pyx_arg_lcontig) { - int __pyx_v_lcontig; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_23attribute_string2dict(PyObject *__pyx_v_self, PyObject *__pyx_v_s); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_23attribute_string2dict(PyObject *__pyx_v_self, PyObject *__pyx_v_s) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("invert (wrapper)", 0); - assert(__pyx_arg_lcontig); { - __pyx_v_lcontig = __Pyx_PyInt_As_int(__pyx_arg_lcontig); if (unlikely((__pyx_v_lcontig == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 579, __pyx_L3_error) - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.invert", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_14invert(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((int)__pyx_v_lcontig)); + __Pyx_RefNannySetupContext("attribute_string2dict (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_22attribute_string2dict(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_s)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_14invert(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, int __pyx_v_lcontig) { - PyObject *__pyx_v_start = NULL; - PyObject *__pyx_v_end = NULL; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_22attribute_string2dict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_s) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; + PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("invert", 0); + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannySetupContext("attribute_string2dict", 0); - /* "pysam/libctabixproxies.pyx":585 - * negative strand.''' + /* "pysam/libctabixproxies.pyx":527 + * + * def attribute_string2dict(self, s): + * return collections.OrderedDict( # <<<<<<<<<<<<<< + * self.attribute_string2iterator(s)) * - * if self.strand[0] == '-': # <<<<<<<<<<<<<< - * start = min(self.start, self.end) - * end = max(self.start, self.end) */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 585, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 585, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 527, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s__35, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 585, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 527, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_3) { - /* "pysam/libctabixproxies.pyx":586 + /* "pysam/libctabixproxies.pyx":528 + * def attribute_string2dict(self, s): + * return collections.OrderedDict( + * self.attribute_string2iterator(s)) # <<<<<<<<<<<<<< * - * if self.strand[0] == '-': - * start = min(self.start, self.end) # <<<<<<<<<<<<<< - * end = max(self.start, self.end) - * self.start, self.end = lcontig - end, lcontig - start + * def __cmp__(self, other): */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_end); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 586, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 586, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 586, __pyx_L1_error) - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 586, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_3) { - __Pyx_INCREF(__pyx_t_2); - __pyx_t_4 = __pyx_t_2; - } else { - __Pyx_INCREF(__pyx_t_1); - __pyx_t_4 = __pyx_t_1; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attribute_string2iterator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 528, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __pyx_t_4; - __Pyx_INCREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_start = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pysam/libctabixproxies.pyx":587 - * if self.strand[0] == '-': - * start = min(self.start, self.end) - * end = max(self.start, self.end) # <<<<<<<<<<<<<< - * self.start, self.end = lcontig - end, lcontig - start - * - */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_end); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 587, __pyx_L1_error) + } + if (!__pyx_t_5) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 528, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 587, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_4, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 587, __pyx_L1_error) - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 587, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_3) { - __Pyx_INCREF(__pyx_t_2); - __pyx_t_1 = __pyx_t_2; - } else { + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_s}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 528, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_s}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 528, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 528, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_s); + __Pyx_GIVEREF(__pyx_v_s); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_s); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 528, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); - __pyx_t_1 = __pyx_t_4; + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + if (!__pyx_t_4) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 527, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __pyx_t_1; - __Pyx_INCREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_end = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pysam/libctabixproxies.pyx":588 - * start = min(self.start, self.end) - * end = max(self.start, self.end) - * self.start, self.end = lcontig - end, lcontig - start # <<<<<<<<<<<<<< - * - * def keys(self): - */ - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lcontig); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 588, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyNumber_Subtract(__pyx_t_2, __pyx_v_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 588, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lcontig); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 588, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyNumber_Subtract(__pyx_t_2, __pyx_v_start); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 588, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start, __pyx_t_1) < 0) __PYX_ERR(0, 588, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_end, __pyx_t_4) < 0) __PYX_ERR(0, 588, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "pysam/libctabixproxies.pyx":585 - * negative strand.''' - * - * if self.strand[0] == '-': # <<<<<<<<<<<<<< - * start = min(self.start, self.end) - * end = max(self.start, self.end) - */ - } - - /* "pysam/libctabixproxies.pyx":579 - * return TupleProxy.__str__(self) - * - * def invert(self, int lcontig): # <<<<<<<<<<<<<< - * '''invert coordinates to negative strand coordinates + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 527, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 527, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 527, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 527, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "pysam/libctabixproxies.pyx":526 + * self.is_modified = True * + * def attribute_string2dict(self, s): # <<<<<<<<<<<<<< + * return collections.OrderedDict( + * self.attribute_string2iterator(s)) */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.invert", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.attribute_string2dict", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_start); - __Pyx_XDECREF(__pyx_v_end); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":590 - * self.start, self.end = lcontig - end, lcontig - start +/* "pysam/libctabixproxies.pyx":530 + * self.attribute_string2iterator(s)) * - * def keys(self): # <<<<<<<<<<<<<< - * '''return a list of attributes defined in this entry.''' - * r = self.attributes + * def __cmp__(self, other): # <<<<<<<<<<<<<< + * return (self.contig, self.strand, self.start) < \ + * (other.contig, other.strand, other.start) */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_17keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_16keys[] = "return a list of attributes defined in this entry."; -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_17keys(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; +#if PY_MAJOR_VERSION < 3 +static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_25__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_25__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("keys (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_16keys(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__cmp__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_24__cmp__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_other)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_16keys(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { - PyObject *__pyx_v_r = NULL; - PyObject *__pyx_v_x = NULL; - PyObject *__pyx_r = NULL; +#if PY_MAJOR_VERSION < 3 +static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_24__cmp__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_other) { + int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; - PyObject *(*__pyx_t_5)(PyObject *); - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - int __pyx_t_8; - __Pyx_RefNannySetupContext("keys", 0); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__cmp__", 0); - /* "pysam/libctabixproxies.pyx":592 - * def keys(self): - * '''return a list of attributes defined in this entry.''' - * r = self.attributes # <<<<<<<<<<<<<< - * return [x.strip().split(" ")[0] - * # separator is ';' followed by space + /* "pysam/libctabixproxies.pyx":531 + * + * def __cmp__(self, other): + * return (self.contig, self.strand, self.start) < \ # <<<<<<<<<<<<<< + * (other.contig, other.strand, other.start) + * */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attributes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 592, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contig); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 531, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_v_r = __pyx_t_1; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 531, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 531, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 531, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":593 - * '''return a list of attributes defined in this entry.''' - * r = self.attributes - * return [x.strip().split(" ")[0] # <<<<<<<<<<<<<< - * # separator is ';' followed by space - * for x in r.split("; ") if x.strip() != ''] - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 593, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - - /* "pysam/libctabixproxies.pyx":595 - * return [x.strip().split(" ")[0] - * # separator is ';' followed by space - * for x in r.split("; ") if x.strip() != ''] # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":532 + * def __cmp__(self, other): + * return (self.contig, self.strand, self.start) < \ + * (other.contig, other.strand, other.start) # <<<<<<<<<<<<<< * - * def __getitem__(self, key): + * # python 3 compatibility */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_r, __pyx_n_s_split); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 595, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_contig); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 532, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; - __pyx_t_5 = NULL; - } else { - __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 595, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 595, __pyx_L1_error) - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (likely(!__pyx_t_5)) { - if (likely(PyList_CheckExact(__pyx_t_2))) { - if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 595, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } else { - if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 595, __pyx_L1_error) - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - #endif - } - } else { - __pyx_t_3 = __pyx_t_5(__pyx_t_2); - if (unlikely(!__pyx_t_3)) { - PyObject* exc_type = PyErr_Occurred(); - if (exc_type) { - if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 595, __pyx_L1_error) - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_n_s_strip); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 595, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - if (__pyx_t_7) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else { - __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_kp_s__20, Py_NE)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 595, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_8) { - - /* "pysam/libctabixproxies.pyx":593 - * '''return a list of attributes defined in this entry.''' - * r = self.attributes - * return [x.strip().split(" ")[0] # <<<<<<<<<<<<<< - * # separator is ';' followed by space - * for x in r.split("; ") if x.strip() != ''] - */ - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_n_s_strip); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 593, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_7)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); - } - } - if (__pyx_t_7) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 593, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } else { - __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 593, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_split); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 593, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 593, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 593, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 593, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_strand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 532, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_1); + __pyx_t_3 = 0; + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 531, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libctabixproxies.pyx":595 - * return [x.strip().split(" ")[0] - * # separator is ';' followed by space - * for x in r.split("; ") if x.strip() != ''] # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":531 + * + * def __cmp__(self, other): + * return (self.contig, self.strand, self.start) < \ # <<<<<<<<<<<<<< + * (other.contig, other.strand, other.start) * - * def __getitem__(self, key): */ - } - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 531, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_6; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":590 - * self.start, self.end = lcontig - end, lcontig - start + /* "pysam/libctabixproxies.pyx":530 + * self.attribute_string2iterator(s)) * - * def keys(self): # <<<<<<<<<<<<<< - * '''return a list of attributes defined in this entry.''' - * r = self.attributes + * def __cmp__(self, other): # <<<<<<<<<<<<<< + * return (self.contig, self.strand, self.start) < \ + * (other.contig, other.strand, other.start) */ /* function exit code */ @@ -10873,576 +10225,522 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_16keys(struct __py __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.keys", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__cmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_r); - __Pyx_XDECREF(__pyx_v_x); - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "pysam/libctabixproxies.pyx":597 - * for x in r.split("; ") if x.strip() != ''] - * - * def __getitem__(self, key): # <<<<<<<<<<<<<< - * return self.__getattr__(key) +/* "pysam/libctabixproxies.pyx":535 * + * # python 3 compatibility + * def __richcmp__(GTFProxy self, GTFProxy other, int op): # <<<<<<<<<<<<<< + * if op == 0: + * return (self.contig, self.strand, self.start) < \ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_19__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_19__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_27__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_27__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_18__getitem__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_16libctabixproxies_GTFProxy, 1, "other", 0))) __PYX_ERR(0, 535, __pyx_L1_error) + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_26__richcmp__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_other), ((int)__pyx_v_op)); /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_18__getitem__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_key) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_26__richcmp__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_other, int __pyx_v_op) { + PyObject *__pyx_v_err_msg = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannySetupContext("__getitem__", 0); + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__richcmp__", 0); - /* "pysam/libctabixproxies.pyx":598 - * - * def __getitem__(self, key): - * return self.__getattr__(key) # <<<<<<<<<<<<<< - * - * def __getattr__(self, item): + /* "pysam/libctabixproxies.pyx":536 + * # python 3 compatibility + * def __richcmp__(GTFProxy self, GTFProxy other, int op): + * if op == 0: # <<<<<<<<<<<<<< + * return (self.contig, self.strand, self.start) < \ + * (other.contig, other.strand, other.start) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getattr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_key}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_key}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_INCREF(__pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_key); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 598, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - /* "pysam/libctabixproxies.pyx":597 - * for x in r.split("; ") if x.strip() != ''] - * - * def __getitem__(self, key): # <<<<<<<<<<<<<< - * return self.__getattr__(key) - * - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libctabixproxies.pyx":600 - * return self.__getattr__(key) - * - * def __getattr__(self, item): # <<<<<<<<<<<<<< - * """Generic lookup of attribute from GFF/GTF attributes - * Only called if there *isn't* an attribute with this name - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_21__getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_item); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_20__getattr__[] = "Generic lookup of attribute from GFF/GTF attributes \n Only called if there *isn't* an attribute with this name\n "; -#if CYTHON_COMPILING_IN_CPYTHON -struct wrapperbase __pyx_wrapperbase_5pysam_16libctabixproxies_8GTFProxy_20__getattr__; -#endif -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_21__getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_item) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_20__getattr__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_item)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_20__getattr__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_item) { - char *__pyx_v_start; - char *__pyx_v_query; - char *__pyx_v_end; - int __pyx_v_l; - char *__pyx_v_attributes; - PyObject *__pyx_v_r = NULL; - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - char *__pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - struct __pyx_opt_args_5pysam_9libcutils_force_str __pyx_t_7; - __Pyx_RefNannySetupContext("__getattr__", 0); - - /* "pysam/libctabixproxies.pyx":623 - * # disappeard after accessing the C data structures - * # directly and so did the bug. - * cdef char * attributes = self.getAttributes() # <<<<<<<<<<<<<< - * if attributes == NULL: - * raise KeyError("key %s not found, no attributes" % item) - */ - __pyx_v_attributes = ((struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self->__pyx_base.__pyx_vtab)->getAttributes(__pyx_v_self); - - /* "pysam/libctabixproxies.pyx":624 - * # directly and so did the bug. - * cdef char * attributes = self.getAttributes() - * if attributes == NULL: # <<<<<<<<<<<<<< - * raise KeyError("key %s not found, no attributes" % item) - * - */ - __pyx_t_1 = ((__pyx_v_attributes == NULL) != 0); - if (unlikely(__pyx_t_1)) { + switch (__pyx_v_op) { + case 0: - /* "pysam/libctabixproxies.pyx":625 - * cdef char * attributes = self.getAttributes() - * if attributes == NULL: - * raise KeyError("key %s not found, no attributes" % item) # <<<<<<<<<<<<<< - * - * # add space in order to make sure + /* "pysam/libctabixproxies.pyx":537 + * def __richcmp__(GTFProxy self, GTFProxy other, int op): + * if op == 0: + * return (self.contig, self.strand, self.start) < \ # <<<<<<<<<<<<<< + * (other.contig, other.strand, other.start) + * elif op == 1: */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_key_s_not_found_no_attributes, __pyx_v_item); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 625, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contig); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 537, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 625, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 537, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 625, __pyx_L1_error) - - /* "pysam/libctabixproxies.pyx":624 - * # directly and so did the bug. - * cdef char * attributes = self.getAttributes() - * if attributes == NULL: # <<<<<<<<<<<<<< - * raise KeyError("key %s not found, no attributes" % item) - * - */ - } + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":629 - * # add space in order to make sure - * # to not pick up a field that is a prefix of another field - * r = force_bytes(item + " ") # <<<<<<<<<<<<<< - * query = r - * start = strstr(attributes, query) + /* "pysam/libctabixproxies.pyx":538 + * if op == 0: + * return (self.contig, self.strand, self.start) < \ + * (other.contig, other.strand, other.start) # <<<<<<<<<<<<<< + * elif op == 1: + * return (self.contig, self.strand, self.start) <= \ */ - __pyx_t_3 = PyNumber_Add(__pyx_v_item, __pyx_kp_s__30); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 629, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 629, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_r = ((PyObject*)__pyx_t_2); - __pyx_t_2 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_contig); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 538, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_strand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 538, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 538, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 538, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_1); + __pyx_t_3 = 0; + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 537, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":630 - * # to not pick up a field that is a prefix of another field - * r = force_bytes(item + " ") - * query = r # <<<<<<<<<<<<<< - * start = strstr(attributes, query) - * + /* "pysam/libctabixproxies.pyx":536 + * # python 3 compatibility + * def __richcmp__(GTFProxy self, GTFProxy other, int op): + * if op == 0: # <<<<<<<<<<<<<< + * return (self.contig, self.strand, self.start) < \ + * (other.contig, other.strand, other.start) */ - if (unlikely(__pyx_v_r == Py_None)) { - PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 630, __pyx_L1_error) - } - __pyx_t_4 = __Pyx_PyBytes_AsWritableString(__pyx_v_r); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 630, __pyx_L1_error) - __pyx_v_query = __pyx_t_4; + break; - /* "pysam/libctabixproxies.pyx":631 - * r = force_bytes(item + " ") - * query = r - * start = strstr(attributes, query) # <<<<<<<<<<<<<< - * - * if start == NULL: + /* "pysam/libctabixproxies.pyx":539 + * return (self.contig, self.strand, self.start) < \ + * (other.contig, other.strand, other.start) + * elif op == 1: # <<<<<<<<<<<<<< + * return (self.contig, self.strand, self.start) <= \ + * (other.contig, other.strand, other.start) */ - __pyx_v_start = strstr(__pyx_v_attributes, __pyx_v_query); + case 1: - /* "pysam/libctabixproxies.pyx":633 - * start = strstr(attributes, query) - * - * if start == NULL: # <<<<<<<<<<<<<< - * raise AttributeError("'GTFProxy' has no attribute '%s'" % item) - * + /* "pysam/libctabixproxies.pyx":540 + * (other.contig, other.strand, other.start) + * elif op == 1: + * return (self.contig, self.strand, self.start) <= \ # <<<<<<<<<<<<<< + * (other.contig, other.strand, other.start) + * elif op == 2: */ - __pyx_t_1 = ((__pyx_v_start == NULL) != 0); - if (unlikely(__pyx_t_1)) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contig); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 540, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_4); + __pyx_t_1 = 0; + __pyx_t_5 = 0; + __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":634 - * - * if start == NULL: - * raise AttributeError("'GTFProxy' has no attribute '%s'" % item) # <<<<<<<<<<<<<< - * - * start += strlen(query) + /* "pysam/libctabixproxies.pyx":541 + * elif op == 1: + * return (self.contig, self.strand, self.start) <= \ + * (other.contig, other.strand, other.start) # <<<<<<<<<<<<<< + * elif op == 2: + * return self.compare(other) == 0 */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_GTFProxy_has_no_attribute_s, __pyx_v_item); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 634, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_AttributeError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 634, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_contig); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 541, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_strand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 541, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 541, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 541, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_1); + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 540, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 634, __pyx_L1_error) - - /* "pysam/libctabixproxies.pyx":633 - * start = strstr(attributes, query) - * - * if start == NULL: # <<<<<<<<<<<<<< - * raise AttributeError("'GTFProxy' has no attribute '%s'" % item) - * - */ - } - - /* "pysam/libctabixproxies.pyx":636 - * raise AttributeError("'GTFProxy' has no attribute '%s'" % item) - * - * start += strlen(query) # <<<<<<<<<<<<<< - * # skip gaps before - * while start[0] == ' ': - */ - __pyx_v_start = (__pyx_v_start + strlen(__pyx_v_query)); - - /* "pysam/libctabixproxies.pyx":638 - * start += strlen(query) - * # skip gaps before - * while start[0] == ' ': # <<<<<<<<<<<<<< - * start += 1 - * - */ - while (1) { - __pyx_t_1 = (((__pyx_v_start[0]) == ' ') != 0); - if (!__pyx_t_1) break; - - /* "pysam/libctabixproxies.pyx":639 - * # skip gaps before - * while start[0] == ' ': - * start += 1 # <<<<<<<<<<<<<< - * - * if start[0] == '"': - */ - __pyx_v_start = (__pyx_v_start + 1); - } - - /* "pysam/libctabixproxies.pyx":641 - * start += 1 - * - * if start[0] == '"': # <<<<<<<<<<<<<< - * start += 1 - * end = start - */ - __pyx_t_1 = (((__pyx_v_start[0]) == '"') != 0); - if (__pyx_t_1) { + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":642 - * - * if start[0] == '"': - * start += 1 # <<<<<<<<<<<<<< - * end = start - * while end[0] != '\0' and end[0] != '"': + /* "pysam/libctabixproxies.pyx":539 + * return (self.contig, self.strand, self.start) < \ + * (other.contig, other.strand, other.start) + * elif op == 1: # <<<<<<<<<<<<<< + * return (self.contig, self.strand, self.start) <= \ + * (other.contig, other.strand, other.start) */ - __pyx_v_start = (__pyx_v_start + 1); + break; - /* "pysam/libctabixproxies.pyx":643 - * if start[0] == '"': - * start += 1 - * end = start # <<<<<<<<<<<<<< - * while end[0] != '\0' and end[0] != '"': - * end += 1 + /* "pysam/libctabixproxies.pyx":542 + * return (self.contig, self.strand, self.start) <= \ + * (other.contig, other.strand, other.start) + * elif op == 2: # <<<<<<<<<<<<<< + * return self.compare(other) == 0 + * elif op == 3: */ - __pyx_v_end = __pyx_v_start; + case 2: - /* "pysam/libctabixproxies.pyx":644 - * start += 1 - * end = start - * while end[0] != '\0' and end[0] != '"': # <<<<<<<<<<<<<< - * end += 1 - * l = end - start + /* "pysam/libctabixproxies.pyx":543 + * (other.contig, other.strand, other.start) + * elif op == 2: + * return self.compare(other) == 0 # <<<<<<<<<<<<<< + * elif op == 3: + * return self.compare(other) != 0 */ - while (1) { - __pyx_t_5 = (((__pyx_v_end[0]) != '\x00') != 0); - if (__pyx_t_5) { - } else { - __pyx_t_1 = __pyx_t_5; - goto __pyx_L10_bool_binop_done; - } - __pyx_t_5 = (((__pyx_v_end[0]) != '"') != 0); - __pyx_t_1 = __pyx_t_5; - __pyx_L10_bool_binop_done:; - if (!__pyx_t_1) break; - - /* "pysam/libctabixproxies.pyx":645 - * end = start - * while end[0] != '\0' and end[0] != '"': - * end += 1 # <<<<<<<<<<<<<< - * l = end - start - * result = force_str(PyBytes_FromStringAndSize(start, l), - */ - __pyx_v_end = (__pyx_v_end + 1); + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_compare); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 543, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } } + if (!__pyx_t_2) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 543, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, ((PyObject *)__pyx_v_other)}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 543, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, ((PyObject *)__pyx_v_other)}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 543, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 543, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL; + __Pyx_INCREF(((PyObject *)__pyx_v_other)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_other)); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, ((PyObject *)__pyx_v_other)); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 543, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 543, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":646 - * while end[0] != '\0' and end[0] != '"': - * end += 1 - * l = end - start # <<<<<<<<<<<<<< - * result = force_str(PyBytes_FromStringAndSize(start, l), - * self.encoding) - */ - __pyx_v_l = (__pyx_v_end - __pyx_v_start); - - /* "pysam/libctabixproxies.pyx":647 - * end += 1 - * l = end - start - * result = force_str(PyBytes_FromStringAndSize(start, l), # <<<<<<<<<<<<<< - * self.encoding) - * return result + /* "pysam/libctabixproxies.pyx":542 + * return (self.contig, self.strand, self.start) <= \ + * (other.contig, other.strand, other.start) + * elif op == 2: # <<<<<<<<<<<<<< + * return self.compare(other) == 0 + * elif op == 3: */ - __pyx_t_3 = PyBytes_FromStringAndSize(__pyx_v_start, __pyx_v_l); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 647, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + break; - /* "pysam/libctabixproxies.pyx":648 - * l = end - start - * result = force_str(PyBytes_FromStringAndSize(start, l), - * self.encoding) # <<<<<<<<<<<<<< - * return result + /* "pysam/libctabixproxies.pyx":544 + * elif op == 2: + * return self.compare(other) == 0 + * elif op == 3: # <<<<<<<<<<<<<< + * return self.compare(other) != 0 * else: */ - __pyx_t_2 = __pyx_v_self->__pyx_base.encoding; - __Pyx_INCREF(__pyx_t_2); + case 3: - /* "pysam/libctabixproxies.pyx":647 - * end += 1 - * l = end - start - * result = force_str(PyBytes_FromStringAndSize(start, l), # <<<<<<<<<<<<<< - * self.encoding) - * return result + /* "pysam/libctabixproxies.pyx":545 + * return self.compare(other) == 0 + * elif op == 3: + * return self.compare(other) != 0 # <<<<<<<<<<<<<< + * else: + * err_msg = "op {0} isn't implemented yet".format(op) */ - __pyx_t_7.__pyx_n = 1; - __pyx_t_7.encoding = __pyx_t_2; - __pyx_t_6 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, &__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 647, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_compare); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 545, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + if (!__pyx_t_5) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 545, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, ((PyObject *)__pyx_v_other)}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 545, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, ((PyObject *)__pyx_v_other)}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 545, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 545, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(((PyObject *)__pyx_v_other)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_other)); + PyTuple_SET_ITEM(__pyx_t_2, 0+1, ((PyObject *)__pyx_v_other)); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 545, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 545, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_result = __pyx_t_6; - __pyx_t_6 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":649 - * result = force_str(PyBytes_FromStringAndSize(start, l), - * self.encoding) - * return result # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":544 + * elif op == 2: + * return self.compare(other) == 0 + * elif op == 3: # <<<<<<<<<<<<<< + * return self.compare(other) != 0 * else: - * return force_str(start, self.encoding) */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result); - __pyx_r = __pyx_v_result; - goto __pyx_L0; + break; + default: - /* "pysam/libctabixproxies.pyx":641 - * start += 1 + /* "pysam/libctabixproxies.pyx":547 + * return self.compare(other) != 0 + * else: + * err_msg = "op {0} isn't implemented yet".format(op) # <<<<<<<<<<<<<< + * raise NotImplementedError(err_msg) * - * if start[0] == '"': # <<<<<<<<<<<<<< - * start += 1 - * end = start */ - } + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_op_0_isn_t_implemented_yet, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 547, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_op); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 547, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_5) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 547, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_2}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 547, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_2}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 547, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 547, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 547, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_err_msg = __pyx_t_1; + __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":651 - * return result + /* "pysam/libctabixproxies.pyx":548 * else: - * return force_str(start, self.encoding) # <<<<<<<<<<<<<< + * err_msg = "op {0} isn't implemented yet".format(op) + * raise NotImplementedError(err_msg) # <<<<<<<<<<<<<< * - * def setAttribute(self, name, value): + * def dict2attribute_string(self, d): */ - /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_start); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 651, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = __pyx_v_self->__pyx_base.encoding; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_7.__pyx_n = 1; - __pyx_t_7.encoding = __pyx_t_2; - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_6, &__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 651, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_NotImplementedError, __pyx_v_err_msg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 548, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 548, __pyx_L1_error) + break; } - /* "pysam/libctabixproxies.pyx":600 - * return self.__getattr__(key) + /* "pysam/libctabixproxies.pyx":535 * - * def __getattr__(self, item): # <<<<<<<<<<<<<< - * """Generic lookup of attribute from GFF/GTF attributes - * Only called if there *isn't* an attribute with this name + * # python 3 compatibility + * def __richcmp__(GTFProxy self, GTFProxy other, int op): # <<<<<<<<<<<<<< + * if op == 0: + * return (self.contig, self.strand, self.start) < \ */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_r); - __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_err_msg); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":653 - * return force_str(start, self.encoding) +/* "pysam/libctabixproxies.pyx":550 + * raise NotImplementedError(err_msg) + * + * def dict2attribute_string(self, d): # <<<<<<<<<<<<<< + * """convert dictionary to attribute string in GTF format. * - * def setAttribute(self, name, value): # <<<<<<<<<<<<<< - * '''convenience method to set an attribute.''' - * r = self.asDict() */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_23setAttribute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_22setAttribute[] = "convenience method to set an attribute."; -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_23setAttribute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_name = 0; - PyObject *__pyx_v_value = 0; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_29dict2attribute_string(PyObject *__pyx_v_self, PyObject *__pyx_v_d); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_28dict2attribute_string[] = "convert dictionary to attribute string in GTF format.\n\n "; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_29dict2attribute_string(PyObject *__pyx_v_self, PyObject *__pyx_v_d) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("setAttribute (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,&__pyx_n_s_value,0}; - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - CYTHON_FALLTHROUGH; - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - CYTHON_FALLTHROUGH; - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - CYTHON_FALLTHROUGH; - case 1: - if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("setAttribute", 1, 2, 2, 1); __PYX_ERR(0, 653, __pyx_L3_error) - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setAttribute") < 0)) __PYX_ERR(0, 653, __pyx_L3_error) - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_name = values[0]; - __pyx_v_value = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("setAttribute", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 653, __pyx_L3_error) - __pyx_L3_error:; - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.setAttribute", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_22setAttribute(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), __pyx_v_name, __pyx_v_value); + __Pyx_RefNannySetupContext("dict2attribute_string (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_28dict2attribute_string(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_d)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_22setAttribute(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_value) { - PyObject *__pyx_v_r = NULL; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_28dict2attribute_string(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_d) { + PyObject *__pyx_v_aa = NULL; + PyObject *__pyx_v_k = NULL; + PyObject *__pyx_v_v = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannySetupContext("setAttribute", 0); + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + int __pyx_t_10; + int __pyx_t_11; + int __pyx_t_12; + PyObject *__pyx_t_13 = NULL; + __Pyx_RefNannySetupContext("dict2attribute_string", 0); - /* "pysam/libctabixproxies.pyx":655 - * def setAttribute(self, name, value): - * '''convenience method to set an attribute.''' - * r = self.asDict() # <<<<<<<<<<<<<< - * r[name] = value - * self.fromDict(r) + /* "pysam/libctabixproxies.pyx":554 + * + * """ + * aa = [] # <<<<<<<<<<<<<< + * for k, v in d.items(): + * if isinstance(v, str): + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 554, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_aa = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "pysam/libctabixproxies.pyx":555 + * """ + * aa = [] + * for k, v in d.items(): # <<<<<<<<<<<<<< + * if isinstance(v, str): + * aa.append('{} "{}"'.format(k, v)) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_asDict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 655, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_d, __pyx_n_s_items); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 555, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -11455,2163 +10753,3303 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_22setAttribute(str } } if (__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 655, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 555, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 655, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 555, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_r = __pyx_t_1; - __pyx_t_1 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 555, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 555, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_5)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 555, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 555, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 555, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 555, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_5(__pyx_t_2); + if (unlikely(!__pyx_t_1)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 555, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 555, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 555, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 555, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 555, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 555, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 555, __pyx_L1_error) + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_3); + __pyx_t_3 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_6); + __pyx_t_6 = 0; - /* "pysam/libctabixproxies.pyx":656 - * '''convenience method to set an attribute.''' - * r = self.asDict() - * r[name] = value # <<<<<<<<<<<<<< - * self.fromDict(r) + /* "pysam/libctabixproxies.pyx":556 + * aa = [] + * for k, v in d.items(): + * if isinstance(v, str): # <<<<<<<<<<<<<< + * aa.append('{} "{}"'.format(k, v)) + * else: + */ + __pyx_t_9 = PyString_Check(__pyx_v_v); + __pyx_t_10 = (__pyx_t_9 != 0); + if (__pyx_t_10) { + + /* "pysam/libctabixproxies.pyx":557 + * for k, v in d.items(): + * if isinstance(v, str): + * aa.append('{} "{}"'.format(k, v)) # <<<<<<<<<<<<<< + * else: + * aa.append("{} {}".format(k, str(v))) + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s__18, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_k, __pyx_v_v}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_k, __pyx_v_v}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_k); + __Pyx_GIVEREF(__pyx_v_k); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_v_k); + __Pyx_INCREF(__pyx_v_v); + __Pyx_GIVEREF(__pyx_v_v); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_v_v); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_aa, __pyx_t_1); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 557, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libctabixproxies.pyx":556 + * aa = [] + * for k, v in d.items(): + * if isinstance(v, str): # <<<<<<<<<<<<<< + * aa.append('{} "{}"'.format(k, v)) + * else: + */ + goto __pyx_L7; + } + + /* "pysam/libctabixproxies.pyx":559 + * aa.append('{} "{}"'.format(k, v)) + * else: + * aa.append("{} {}".format(k, str(v))) # <<<<<<<<<<<<<< * + * return self.separator.join(aa) + ";" + */ + /*else*/ { + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s__19, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_v); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_k, __pyx_t_7}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_k, __pyx_t_7}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else + #endif + { + __pyx_t_13 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_k); + __Pyx_GIVEREF(__pyx_v_k); + PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_11, __pyx_v_k); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_11, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_aa, __pyx_t_1); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 559, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __pyx_L7:; + + /* "pysam/libctabixproxies.pyx":555 + * """ + * aa = [] + * for k, v in d.items(): # <<<<<<<<<<<<<< + * if isinstance(v, str): + * aa.append('{} "{}"'.format(k, v)) */ - if (unlikely(PyObject_SetItem(__pyx_v_r, __pyx_v_name, __pyx_v_value) < 0)) __PYX_ERR(0, 656, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":657 - * r = self.asDict() - * r[name] = value - * self.fromDict(r) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":561 + * aa.append("{} {}".format(k, str(v))) * - * def __cmp__(self, other): + * return self.separator.join(aa) + ";" # <<<<<<<<<<<<<< + * + * def attribute_string2iterator(self, s): */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fromDict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_separator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_join); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); + __Pyx_DECREF_SET(__pyx_t_6, function); } } - if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_r); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + if (!__pyx_t_1) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_aa); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_r}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_aa}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 561, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_2); } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_r}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_aa}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 561, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_INCREF(__pyx_v_r); - __Pyx_GIVEREF(__pyx_v_r); - PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_r); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1); __pyx_t_1 = NULL; + __Pyx_INCREF(__pyx_v_aa); + __Pyx_GIVEREF(__pyx_v_aa); + PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_v_aa); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyNumber_Add(__pyx_t_2, __pyx_kp_s__20); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 561, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":653 - * return force_str(start, self.encoding) + /* "pysam/libctabixproxies.pyx":550 + * raise NotImplementedError(err_msg) + * + * def dict2attribute_string(self, d): # <<<<<<<<<<<<<< + * """convert dictionary to attribute string in GTF format. * - * def setAttribute(self, name, value): # <<<<<<<<<<<<<< - * '''convenience method to set an attribute.''' - * r = self.asDict() */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.setAttribute", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.dict2attribute_string", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_r); + __Pyx_XDECREF(__pyx_v_aa); + __Pyx_XDECREF(__pyx_v_k); + __Pyx_XDECREF(__pyx_v_v); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5pysam_16libctabixproxies_8GTFProxy_32generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libctabixproxies.pyx":659 - * self.fromDict(r) +/* "pysam/libctabixproxies.pyx":563 + * return self.separator.join(aa) + ";" * - * def __cmp__(self, other): # <<<<<<<<<<<<<< - * return (self.contig, self.strand, self.start) < \ - * (other.contig, other.strand, other.start) + * def attribute_string2iterator(self, s): # <<<<<<<<<<<<<< + * """convert attribute string in GTF format to records + * and iterate over key, value pairs. */ /* Python wrapper */ -#if PY_MAJOR_VERSION < 3 -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_25__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_25__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_31attribute_string2iterator(PyObject *__pyx_v_self, PyObject *__pyx_v_s); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_30attribute_string2iterator[] = "convert attribute string in GTF format to records\n and iterate over key, value pairs.\n "; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_31attribute_string2iterator(PyObject *__pyx_v_self, PyObject *__pyx_v_s) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cmp__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_24__cmp__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_other)); + __Pyx_RefNannySetupContext("attribute_string2iterator (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_30attribute_string2iterator(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_s)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -#endif /*!(#if PY_MAJOR_VERSION < 3)*/ -#if PY_MAJOR_VERSION < 3 -static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_24__cmp__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_other) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_30attribute_string2iterator(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_s) { + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator *__pyx_cur_scope; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - __Pyx_RefNannySetupContext("__cmp__", 0); - - /* "pysam/libctabixproxies.pyx":660 - * - * def __cmp__(self, other): - * return (self.contig, self.strand, self.start) < \ # <<<<<<<<<<<<<< - * (other.contig, other.strand, other.start) + __Pyx_RefNannySetupContext("attribute_string2iterator", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator *)__pyx_tp_new_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator(__pyx_ptype_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 563, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_s = __pyx_v_s; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_s); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_s); + { + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_16libctabixproxies_8GTFProxy_32generator, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_attribute_string2iterator, __pyx_n_s_GTFProxy_attribute_string2iterat, __pyx_n_s_pysam_libctabixproxies); if (unlikely(!gen)) __PYX_ERR(0, 563, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.attribute_string2iterator", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5pysam_16libctabixproxies_8GTFProxy_32generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator *__pyx_cur_scope = ((struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + struct __pyx_opt_args_5pysam_9libcutils_force_str __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + PyObject *(*__pyx_t_7)(PyObject *); + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + Py_ssize_t __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + int __pyx_t_12; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + int __pyx_t_16; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("attribute_string2iterator", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L23_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 563, __pyx_L1_error) + + /* "pysam/libctabixproxies.pyx":569 + * + * # remove comments + * attributes = force_str(s, encoding=self.encoding) # <<<<<<<<<<<<<< * + * # separate into fields */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contig); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 660, __pyx_L1_error) + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->__pyx_base.__pyx_base.encoding; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3.__pyx_n = 1; + __pyx_t_3.encoding = __pyx_t_1; + __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_cur_scope->__pyx_v_s, &__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 569, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 660, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); - __pyx_t_1 = 0; + __pyx_cur_scope->__pyx_v_attributes = __pyx_t_2; __pyx_t_2 = 0; - __pyx_t_3 = 0; - /* "pysam/libctabixproxies.pyx":661 - * def __cmp__(self, other): - * return (self.contig, self.strand, self.start) < \ - * (other.contig, other.strand, other.start) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":579 + * + * # Remove white space to prevent a last empty field. + * fields = [x.strip() for x in attributes.strip().split("; ")] # <<<<<<<<<<<<<< + * for f in fields: * - * # python 3 compatibility */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_contig); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 661, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_strand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 661, __pyx_L1_error) + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 579, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 661, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_attributes, __pyx_n_s_strip); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (__pyx_t_5) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error) + } __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 661, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_split); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0; + __pyx_t_7 = NULL; + } else { + __pyx_t_6 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 579, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_7)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 579, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 579, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_7(__pyx_t_4); + if (unlikely(!__pyx_t_1)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 579, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_x, __pyx_n_s_strip); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (__pyx_t_8) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else { + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_1))) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_1); - __pyx_t_3 = 0; + __pyx_cur_scope->__pyx_v_fields = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 660, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "pysam/libctabixproxies.pyx":660 - * - * def __cmp__(self, other): - * return (self.contig, self.strand, self.start) < \ # <<<<<<<<<<<<<< - * (other.contig, other.strand, other.start) + /* "pysam/libctabixproxies.pyx":580 + * # Remove white space to prevent a last empty field. + * fields = [x.strip() for x in attributes.strip().split("; ")] + * for f in fields: # <<<<<<<<<<<<<< * + * # strip semicolon (GTF files without a space after the last semicolon) */ - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 660, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_6; - goto __pyx_L0; + __pyx_t_2 = __pyx_cur_scope->__pyx_v_fields; __Pyx_INCREF(__pyx_t_2); __pyx_t_6 = 0; + for (;;) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 580, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 580, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_f, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":659 - * self.fromDict(r) + /* "pysam/libctabixproxies.pyx":583 + * + * # strip semicolon (GTF files without a space after the last semicolon) + * if f.endswith(";"): # <<<<<<<<<<<<<< + * f = f[:-1] * - * def __cmp__(self, other): # <<<<<<<<<<<<<< - * return (self.contig, self.strand, self.start) < \ - * (other.contig, other.strand, other.start) */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_f, __pyx_n_s_endswith); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 583, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 583, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 583, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_9) { - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__cmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -#endif /*!(#if PY_MAJOR_VERSION < 3)*/ - -/* "pysam/libctabixproxies.pyx":664 + /* "pysam/libctabixproxies.pyx":584 + * # strip semicolon (GTF files without a space after the last semicolon) + * if f.endswith(";"): + * f = f[:-1] # <<<<<<<<<<<<<< * - * # python 3 compatibility - * def __richcmp__(GTFProxy self, GTFProxy other, int op): # <<<<<<<<<<<<<< - * if op == 0: - * return (self.contig, self.strand, self.start) < \ + * # split at most once in order to avoid separating */ + __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_cur_scope->__pyx_v_f, 0, -1L, NULL, NULL, &__pyx_slice__24, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_f, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_27__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_27__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_16libctabixproxies_GTFProxy, 1, "other", 0))) __PYX_ERR(0, 664, __pyx_L1_error) - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_26__richcmp__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_other), ((int)__pyx_v_op)); - - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_26__richcmp__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_other, int __pyx_v_op) { - PyObject *__pyx_v_err_msg = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("__richcmp__", 0); - - /* "pysam/libctabixproxies.pyx":665 - * # python 3 compatibility - * def __richcmp__(GTFProxy self, GTFProxy other, int op): - * if op == 0: # <<<<<<<<<<<<<< - * return (self.contig, self.strand, self.start) < \ - * (other.contig, other.strand, other.start) + /* "pysam/libctabixproxies.pyx":583 + * + * # strip semicolon (GTF files without a space after the last semicolon) + * if f.endswith(";"): # <<<<<<<<<<<<<< + * f = f[:-1] + * */ - switch (__pyx_v_op) { - case 0: + } - /* "pysam/libctabixproxies.pyx":666 - * def __richcmp__(GTFProxy self, GTFProxy other, int op): - * if op == 0: - * return (self.contig, self.strand, self.start) < \ # <<<<<<<<<<<<<< - * (other.contig, other.strand, other.start) - * elif op == 1: + /* "pysam/libctabixproxies.pyx":588 + * # split at most once in order to avoid separating + * # multi-word values + * d = [x.strip() for x in f.split(" ", 1)] # <<<<<<<<<<<<<< + * + * n, v = d[0], d[1] */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contig); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 666, __pyx_L1_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 588, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 666, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 666, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 666, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_f, __pyx_n_s_split); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 588, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_3 = 0; - - /* "pysam/libctabixproxies.pyx":667 - * if op == 0: - * return (self.contig, self.strand, self.start) < \ - * (other.contig, other.strand, other.start) # <<<<<<<<<<<<<< - * elif op == 1: - * return (self.contig, self.strand, self.start) <= \ - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_contig); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 667, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_strand); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 667, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 667, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 667, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 588, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_1); - __pyx_t_3 = 0; - __pyx_t_2 = 0; - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 666, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) { + __pyx_t_4 = __pyx_t_5; __Pyx_INCREF(__pyx_t_4); __pyx_t_10 = 0; + __pyx_t_7 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 588, __pyx_L1_error) + } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_r = __pyx_t_1; + for (;;) { + if (likely(!__pyx_t_7)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_10); __Pyx_INCREF(__pyx_t_5); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 588, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } else { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_10); __Pyx_INCREF(__pyx_t_5); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 588, __pyx_L1_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } + } else { + __pyx_t_5 = __pyx_t_7(__pyx_t_4); + if (unlikely(!__pyx_t_5)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 588, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_x, __pyx_n_s_strip); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + if (__pyx_t_11) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 588, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else { + __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 588, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 588, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_d); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_d, ((PyObject*)__pyx_t_1)); + __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - - /* "pysam/libctabixproxies.pyx":665 - * # python 3 compatibility - * def __richcmp__(GTFProxy self, GTFProxy other, int op): - * if op == 0: # <<<<<<<<<<<<<< - * return (self.contig, self.strand, self.start) < \ - * (other.contig, other.strand, other.start) - */ - break; - - /* "pysam/libctabixproxies.pyx":668 - * return (self.contig, self.strand, self.start) < \ - * (other.contig, other.strand, other.start) - * elif op == 1: # <<<<<<<<<<<<<< - * return (self.contig, self.strand, self.start) <= \ - * (other.contig, other.strand, other.start) - */ - case 1: - /* "pysam/libctabixproxies.pyx":669 - * (other.contig, other.strand, other.start) - * elif op == 1: - * return (self.contig, self.strand, self.start) <= \ # <<<<<<<<<<<<<< - * (other.contig, other.strand, other.start) - * elif op == 2: + /* "pysam/libctabixproxies.pyx":590 + * d = [x.strip() for x in f.split(" ", 1)] + * + * n, v = d[0], d[1] # <<<<<<<<<<<<<< + * if len(d) > 2: + * v = d[1:] */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_contig); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 669, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_cur_scope->__pyx_v_d, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_strand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 669, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_cur_scope->__pyx_v_d, 1, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_n); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_n, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_4); __pyx_t_1 = 0; - __pyx_t_5 = 0; - __pyx_t_4 = 0; - - /* "pysam/libctabixproxies.pyx":670 - * elif op == 1: - * return (self.contig, self.strand, self.start) <= \ - * (other.contig, other.strand, other.start) # <<<<<<<<<<<<<< - * elif op == 2: - * return self.compare(other) == 0 - */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_contig); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 670, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_strand); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 670, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 670, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 670, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_v); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_v, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_1); __pyx_t_4 = 0; - __pyx_t_5 = 0; - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 669, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":668 - * return (self.contig, self.strand, self.start) < \ - * (other.contig, other.strand, other.start) - * elif op == 1: # <<<<<<<<<<<<<< - * return (self.contig, self.strand, self.start) <= \ - * (other.contig, other.strand, other.start) + /* "pysam/libctabixproxies.pyx":591 + * + * n, v = d[0], d[1] + * if len(d) > 2: # <<<<<<<<<<<<<< + * v = d[1:] + * */ - break; + __pyx_t_10 = PyList_GET_SIZE(__pyx_cur_scope->__pyx_v_d); if (unlikely(__pyx_t_10 == ((Py_ssize_t)-1))) __PYX_ERR(0, 591, __pyx_L1_error) + __pyx_t_9 = ((__pyx_t_10 > 2) != 0); + if (__pyx_t_9) { - /* "pysam/libctabixproxies.pyx":671 - * return (self.contig, self.strand, self.start) <= \ - * (other.contig, other.strand, other.start) - * elif op == 2: # <<<<<<<<<<<<<< - * return self.compare(other) == 0 - * elif op == 3: + /* "pysam/libctabixproxies.pyx":592 + * n, v = d[0], d[1] + * if len(d) > 2: + * v = d[1:] # <<<<<<<<<<<<<< + * + * if v[0] == '"' and v[-1] == '"': */ - case 2: + __pyx_t_4 = __Pyx_PyList_GetSlice(__pyx_cur_scope->__pyx_v_d, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 592, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_v); + __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_v, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":672 - * (other.contig, other.strand, other.start) - * elif op == 2: - * return self.compare(other) == 0 # <<<<<<<<<<<<<< - * elif op == 3: - * return self.compare(other) != 0 + /* "pysam/libctabixproxies.pyx":591 + * + * n, v = d[0], d[1] + * if len(d) > 2: # <<<<<<<<<<<<<< + * v = d[1:] + * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_compare); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 672, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } } - if (!__pyx_t_2) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 672, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); + + /* "pysam/libctabixproxies.pyx":594 + * v = d[1:] + * + * if v[0] == '"' and v[-1] == '"': # <<<<<<<<<<<<<< + * v = v[1:-1] + * else: + */ + __pyx_t_4 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_v, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 594, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_kp_s__27, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 594, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_12) { } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, ((PyObject *)__pyx_v_other)}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 672, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, ((PyObject *)__pyx_v_other)}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 672, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else - #endif - { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 672, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL; - __Pyx_INCREF(((PyObject *)__pyx_v_other)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_other)); - PyTuple_SET_ITEM(__pyx_t_5, 0+1, ((PyObject *)__pyx_v_other)); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 672, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } + __pyx_t_9 = __pyx_t_12; + goto __pyx_L13_bool_binop_done; } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 672, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; + __pyx_t_4 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_v, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 594, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_kp_s__27, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 594, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = __pyx_t_12; + __pyx_L13_bool_binop_done:; + if (__pyx_t_9) { - /* "pysam/libctabixproxies.pyx":671 - * return (self.contig, self.strand, self.start) <= \ - * (other.contig, other.strand, other.start) - * elif op == 2: # <<<<<<<<<<<<<< - * return self.compare(other) == 0 - * elif op == 3: + /* "pysam/libctabixproxies.pyx":595 + * + * if v[0] == '"' and v[-1] == '"': + * v = v[1:-1] # <<<<<<<<<<<<<< + * else: + * ## try to convert to a value */ - break; + __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_cur_scope->__pyx_v_v, 1, -1L, NULL, NULL, &__pyx_slice__28, 1, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 595, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_v); + __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_v, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":673 - * elif op == 2: - * return self.compare(other) == 0 - * elif op == 3: # <<<<<<<<<<<<<< - * return self.compare(other) != 0 - * else: + /* "pysam/libctabixproxies.pyx":594 + * v = d[1:] + * + * if v[0] == '"' and v[-1] == '"': # <<<<<<<<<<<<<< + * v = v[1:-1] + * else: */ - case 3: + goto __pyx_L12; + } - /* "pysam/libctabixproxies.pyx":674 - * return self.compare(other) == 0 - * elif op == 3: - * return self.compare(other) != 0 # <<<<<<<<<<<<<< - * else: - * err_msg = "op {0} isn't implemented yet".format(op) + /* "pysam/libctabixproxies.pyx":598 + * else: + * ## try to convert to a value + * try: # <<<<<<<<<<<<<< + * v = float(v) + * v = int(v) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_compare); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_1, function); - } - } - if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, ((PyObject *)__pyx_v_other)}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 674, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, ((PyObject *)__pyx_v_other)}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 674, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_3); - } else - #endif + /*else*/ { { - __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); __pyx_t_5 = NULL; - __Pyx_INCREF(((PyObject *)__pyx_v_other)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_other)); - PyTuple_SET_ITEM(__pyx_t_2, 0+1, ((PyObject *)__pyx_v_other)); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 674, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 674, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __Pyx_ExceptionSave(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_15); + /*try:*/ { - /* "pysam/libctabixproxies.pyx":673 - * elif op == 2: - * return self.compare(other) == 0 - * elif op == 3: # <<<<<<<<<<<<<< - * return self.compare(other) != 0 - * else: + /* "pysam/libctabixproxies.pyx":599 + * ## try to convert to a value + * try: + * v = float(v) # <<<<<<<<<<<<<< + * v = int(v) + * except ValueError: */ - break; - default: + __pyx_t_4 = __Pyx_PyNumber_Float(__pyx_cur_scope->__pyx_v_v); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 599, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_v); + __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_v, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":676 - * return self.compare(other) != 0 - * else: - * err_msg = "op {0} isn't implemented yet".format(op) # <<<<<<<<<<<<<< - * raise NotImplementedError(err_msg) - * + /* "pysam/libctabixproxies.pyx":600 + * try: + * v = float(v) + * v = int(v) # <<<<<<<<<<<<<< + * except ValueError: + * pass */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_op_0_isn_t_implemented_yet, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 676, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_op); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 676, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (!__pyx_t_5) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 676, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_2}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 676, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_2}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 676, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_cur_scope->__pyx_v_v); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 600, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_v); + __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_v, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + + /* "pysam/libctabixproxies.pyx":598 + * else: + * ## try to convert to a value + * try: # <<<<<<<<<<<<<< + * v = float(v) + * v = int(v) + */ + } + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + goto __pyx_L22_try_end; + __pyx_L15_error:; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else - #endif - { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 676, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL; - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 676, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libctabixproxies.pyx":601 + * v = float(v) + * v = int(v) + * except ValueError: # <<<<<<<<<<<<<< + * pass + * except TypeError: + */ + __pyx_t_16 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError); + if (__pyx_t_16) { + __Pyx_ErrRestore(0,0,0); + goto __pyx_L16_exception_handled; + } + + /* "pysam/libctabixproxies.pyx":603 + * except ValueError: + * pass + * except TypeError: # <<<<<<<<<<<<<< + * pass + * + */ + __pyx_t_16 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError); + if (__pyx_t_16) { + __Pyx_ErrRestore(0,0,0); + goto __pyx_L16_exception_handled; + } + goto __pyx_L17_except_error; + __pyx_L17_except_error:; + + /* "pysam/libctabixproxies.pyx":598 + * else: + * ## try to convert to a value + * try: # <<<<<<<<<<<<<< + * v = float(v) + * v = int(v) + */ + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15); + goto __pyx_L1_error; + __pyx_L16_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15); + __pyx_L22_try_end:; } } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_err_msg = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_L12:; - /* "pysam/libctabixproxies.pyx":677 - * else: - * err_msg = "op {0} isn't implemented yet".format(op) - * raise NotImplementedError(err_msg) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":606 + * pass * + * yield n, v # <<<<<<<<<<<<<< * + * def __getattr__(self, key): + */ + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 606, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_n); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_n); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_cur_scope->__pyx_v_n); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_v); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_v); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_cur_scope->__pyx_v_v); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_6; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L23_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_6 = __pyx_cur_scope->__pyx_t_1; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 606, __pyx_L1_error) + + /* "pysam/libctabixproxies.pyx":580 + * # Remove white space to prevent a last empty field. + * fields = [x.strip() for x in attributes.strip().split("; ")] + * for f in fields: # <<<<<<<<<<<<<< + * + * # strip semicolon (GTF files without a space after the last semicolon) */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_NotImplementedError, __pyx_v_err_msg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 677, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 677, __pyx_L1_error) - break; } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libctabixproxies.pyx":664 + /* "pysam/libctabixproxies.pyx":563 + * return self.separator.join(aa) + ";" * - * # python 3 compatibility - * def __richcmp__(GTFProxy self, GTFProxy other, int op): # <<<<<<<<<<<<<< - * if op == 0: - * return (self.contig, self.strand, self.start) < \ + * def attribute_string2iterator(self, s): # <<<<<<<<<<<<<< + * """convert attribute string in GTF format to records + * and iterate over key, value pairs. */ /* function exit code */ + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("attribute_string2iterator", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_err_msg); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_29__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_29__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_28__reduce_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_28__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__reduce_cython__", 0); - - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) - - /* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") +/* "pysam/libctabixproxies.pyx":608 + * yield n, v + * + * def __getattr__(self, key): # <<<<<<<<<<<<<< + * """Generic lookup of attribute from GFF/GTF attributes + * """ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_31__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_31__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_34__getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_33__getattr__[] = "Generic lookup of attribute from GFF/GTF attributes \n "; +#if CYTHON_COMPILING_IN_CPYTHON +struct wrapperbase __pyx_wrapperbase_5pysam_16libctabixproxies_8GTFProxy_33__getattr__; +#endif +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_34__getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_30__setstate_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_33__getattr__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_key)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_30__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_33__getattr__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_key) { + int __pyx_v_idx; + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_s = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__setstate_cython__", 0); - - /* "(tree fragment)":4 - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *(*__pyx_t_6)(PyObject *); + int __pyx_t_7; + int __pyx_t_8; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + struct __pyx_opt_args_5pysam_9libcutils_force_str __pyx_t_11; + __Pyx_RefNannySetupContext("__getattr__", 0); - /* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + /* "pysam/libctabixproxies.pyx":614 + * # Only called if there *isn't* an attribute with this name + * cdef int idx + * idx, f = self.map_key2field.get(key, (-1, None)) # <<<<<<<<<<<<<< + * if idx >= 0: + * # deal with known attributes (fields 0-8) */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libctabixproxies.pyx":684 - * map_key2field = {} - * - * def __setattr__(self, key, value): # <<<<<<<<<<<<<< - * '''set attribute.''' - * cdef int idx - */ - -/* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_1__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__[] = "set attribute."; -#if CYTHON_COMPILING_IN_CPYTHON -struct wrapperbase __pyx_wrapperbase_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__; -#endif -static int __pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_1__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setattr__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__(((struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *)__pyx_v_self), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_value)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { - int __pyx_v_idx; - CYTHON_UNUSED PyObject *__pyx_v_f = NULL; - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *(*__pyx_t_5)(PyObject *); - int __pyx_t_6; - int __pyx_t_7; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - __Pyx_RefNannySetupContext("__setattr__", 0); - - /* "pysam/libctabixproxies.pyx":687 - * '''set attribute.''' - * cdef int idx - * idx, f = self.map_key2field[key] # <<<<<<<<<<<<<< - * if self.nfields < idx: - * raise KeyError("field %s not set" % key) - */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_map_key2field); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 687, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 687, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_map_key2field); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 614, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 614, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_4 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_4 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_key, __pyx_tuple__29}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 614, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_key, __pyx_tuple__29}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 614, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 614, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_key); + __Pyx_INCREF(__pyx_tuple__29); + __Pyx_GIVEREF(__pyx_tuple__29); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_tuple__29); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 614, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 687, __pyx_L1_error) + __PYX_ERR(0, 614, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_5 = PyList_GET_ITEM(sequence, 1); } - __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_5); #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 687, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 687, __pyx_L1_error) + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 614, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 614, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { Py_ssize_t index = -1; - __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 687, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_3 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed; + __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 614, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_2); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) __PYX_ERR(0, 687, __pyx_L1_error) - __pyx_t_5 = NULL; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + index = 1; __pyx_t_5 = __pyx_t_6(__pyx_t_2); if (unlikely(!__pyx_t_5)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_2), 2) < 0) __PYX_ERR(0, 614, __pyx_L1_error) + __pyx_t_6 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L4_unpacking_done; __pyx_L3_unpacking_failed:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 687, __pyx_L1_error) + __PYX_ERR(0, 614, __pyx_L1_error) __pyx_L4_unpacking_done:; } - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 687, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_idx = __pyx_t_6; - __pyx_v_f = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 614, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_idx = __pyx_t_4; + __pyx_v_f = __pyx_t_5; + __pyx_t_5 = 0; - /* "pysam/libctabixproxies.pyx":688 + /* "pysam/libctabixproxies.pyx":615 * cdef int idx - * idx, f = self.map_key2field[key] - * if self.nfields < idx: # <<<<<<<<<<<<<< - * raise KeyError("field %s not set" % key) - * TupleProxy.__setitem__(self, idx, str(value)) + * idx, f = self.map_key2field.get(key, (-1, None)) + * if idx >= 0: # <<<<<<<<<<<<<< + * # deal with known attributes (fields 0-8) + * if idx == 8: */ - __pyx_t_7 = ((__pyx_v_self->__pyx_base.nfields < __pyx_v_idx) != 0); - if (unlikely(__pyx_t_7)) { + __pyx_t_7 = ((__pyx_v_idx >= 0) != 0); + if (__pyx_t_7) { - /* "pysam/libctabixproxies.pyx":689 - * idx, f = self.map_key2field[key] - * if self.nfields < idx: - * raise KeyError("field %s not set" % key) # <<<<<<<<<<<<<< - * TupleProxy.__setitem__(self, idx, str(value)) - * + /* "pysam/libctabixproxies.pyx":617 + * if idx >= 0: + * # deal with known attributes (fields 0-8) + * if idx == 8: # <<<<<<<<<<<<<< + * # flush attributes if requested + * if self.is_modified and self.attribute_dict is not None: */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_field_s_not_set, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 689, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 689, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 689, __pyx_L1_error) + __pyx_t_7 = ((__pyx_v_idx == 8) != 0); + if (__pyx_t_7) { - /* "pysam/libctabixproxies.pyx":688 - * cdef int idx - * idx, f = self.map_key2field[key] - * if self.nfields < idx: # <<<<<<<<<<<<<< - * raise KeyError("field %s not set" % key) - * TupleProxy.__setitem__(self, idx, str(value)) + /* "pysam/libctabixproxies.pyx":619 + * if idx == 8: + * # flush attributes if requested + * if self.is_modified and self.attribute_dict is not None: # <<<<<<<<<<<<<< + * s = self.dict2attribute_string(self.attribute_dict) + * TupleProxy._setindex(self, idx, s) */ - } + __pyx_t_8 = (__pyx_v_self->__pyx_base.__pyx_base.is_modified != 0); + if (__pyx_t_8) { + } else { + __pyx_t_7 = __pyx_t_8; + goto __pyx_L8_bool_binop_done; + } + __pyx_t_8 = (__pyx_v_self->attribute_dict != Py_None); + __pyx_t_9 = (__pyx_t_8 != 0); + __pyx_t_7 = __pyx_t_9; + __pyx_L8_bool_binop_done:; + if (__pyx_t_7) { - /* "pysam/libctabixproxies.pyx":690 - * if self.nfields < idx: - * raise KeyError("field %s not set" % key) - * TupleProxy.__setitem__(self, idx, str(value)) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":620 + * # flush attributes if requested + * if self.is_modified and self.attribute_dict is not None: + * s = self.dict2attribute_string(self.attribute_dict) # <<<<<<<<<<<<<< + * TupleProxy._setindex(self, idx, s) + * self.attribute_dict = None + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_dict2attribute_string); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 620, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_self->attribute_dict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 620, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_self->attribute_dict}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 620, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_self->attribute_dict}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 620, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 620, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_self->attribute_dict); + __Pyx_GIVEREF(__pyx_v_self->attribute_dict); + PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_self->attribute_dict); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 620, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_s = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pysam/libctabixproxies.pyx":621 + * if self.is_modified and self.attribute_dict is not None: + * s = self.dict2attribute_string(self.attribute_dict) + * TupleProxy._setindex(self, idx, s) # <<<<<<<<<<<<<< + * self.attribute_dict = None + * return s + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_n_s_setindex); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 621, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 621, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + __pyx_t_4 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_4 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, ((PyObject *)__pyx_v_self), __pyx_t_2, __pyx_v_s}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 621, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, ((PyObject *)__pyx_v_self), __pyx_t_2, __pyx_v_s}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 621, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + #endif + { + __pyx_t_10 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 621, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_4, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_4, __pyx_t_2); + __Pyx_INCREF(__pyx_v_s); + __Pyx_GIVEREF(__pyx_v_s); + PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_4, __pyx_v_s); + __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 621, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libctabixproxies.pyx":622 + * s = self.dict2attribute_string(self.attribute_dict) + * TupleProxy._setindex(self, idx, s) + * self.attribute_dict = None # <<<<<<<<<<<<<< + * return s * - * def __getattr__(self, key): */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_n_s_setitem); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = NULL; - __pyx_t_6 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_6 = 1; + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->attribute_dict); + __Pyx_DECREF(__pyx_v_self->attribute_dict); + __pyx_v_self->attribute_dict = Py_None; + + /* "pysam/libctabixproxies.pyx":623 + * TupleProxy._setindex(self, idx, s) + * self.attribute_dict = None + * return s # <<<<<<<<<<<<<< + * + * if f[0] == str: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_s); + __pyx_r = __pyx_v_s; + goto __pyx_L0; + + /* "pysam/libctabixproxies.pyx":619 + * if idx == 8: + * # flush attributes if requested + * if self.is_modified and self.attribute_dict is not None: # <<<<<<<<<<<<<< + * s = self.dict2attribute_string(self.attribute_dict) + * TupleProxy._setindex(self, idx, s) + */ + } + + /* "pysam/libctabixproxies.pyx":617 + * if idx >= 0: + * # deal with known attributes (fields 0-8) + * if idx == 8: # <<<<<<<<<<<<<< + * # flush attributes if requested + * if self.is_modified and self.attribute_dict is not None: + */ } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[4] = {__pyx_t_8, ((PyObject *)__pyx_v_self), __pyx_t_1, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 690, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[4] = {__pyx_t_8, ((PyObject *)__pyx_v_self), __pyx_t_1, __pyx_t_4}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 690, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_GOTREF(__pyx_t_3); + + /* "pysam/libctabixproxies.pyx":625 + * return s + * + * if f[0] == str: # <<<<<<<<<<<<<< + * return force_str(self.fields[idx], + * self.encoding) + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_f, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 625, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)(&PyString_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 625, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else - #endif - { - __pyx_t_9 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_6, ((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_6, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_6, __pyx_t_4); - __pyx_t_1 = 0; - __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 690, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 625, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_7) { - /* "pysam/libctabixproxies.pyx":684 - * map_key2field = {} + /* "pysam/libctabixproxies.pyx":626 * - * def __setattr__(self, key, value): # <<<<<<<<<<<<<< - * '''set attribute.''' - * cdef int idx + * if f[0] == str: + * return force_str(self.fields[idx], # <<<<<<<<<<<<<< + * self.encoding) + * else: */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = __Pyx_PyBytes_FromString((__pyx_v_self->__pyx_base.__pyx_base.fields[__pyx_v_idx])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 626, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); - /* function exit code */ - __pyx_r = 0; - goto __pyx_L0; + /* "pysam/libctabixproxies.pyx":627 + * if f[0] == str: + * return force_str(self.fields[idx], + * self.encoding) # <<<<<<<<<<<<<< + * else: + * return f[0](self.fields[idx]) + */ + __pyx_t_1 = __pyx_v_self->__pyx_base.__pyx_base.encoding; + __Pyx_INCREF(__pyx_t_1); + + /* "pysam/libctabixproxies.pyx":626 + * + * if f[0] == str: + * return force_str(self.fields[idx], # <<<<<<<<<<<<<< + * self.encoding) + * else: + */ + __pyx_t_11.__pyx_n = 1; + __pyx_t_11.encoding = __pyx_t_1; + __pyx_t_10 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_5, &__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 626, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_10; + __pyx_t_10 = 0; + goto __pyx_L0; + + /* "pysam/libctabixproxies.pyx":625 + * return s + * + * if f[0] == str: # <<<<<<<<<<<<<< + * return force_str(self.fields[idx], + * self.encoding) + */ + } + + /* "pysam/libctabixproxies.pyx":629 + * self.encoding) + * else: + * return f[0](self.fields[idx]) # <<<<<<<<<<<<<< + * else: + * # deal with generic attributes (gene_id, ...) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_f, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 629, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyBytes_FromString((__pyx_v_self->__pyx_base.__pyx_base.fields[__pyx_v_idx])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 629, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + if (!__pyx_t_2) { + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 629, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_10); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_5}; + __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 629, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_5}; + __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 629, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 629, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __pyx_t_2 = NULL; + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 629, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_10; + __pyx_t_10 = 0; + goto __pyx_L0; + } + + /* "pysam/libctabixproxies.pyx":615 + * cdef int idx + * idx, f = self.map_key2field.get(key, (-1, None)) + * if idx >= 0: # <<<<<<<<<<<<<< + * # deal with known attributes (fields 0-8) + * if idx == 8: + */ + } + + /* "pysam/libctabixproxies.pyx":632 + * else: + * # deal with generic attributes (gene_id, ...) + * if self.attribute_dict is None: # <<<<<<<<<<<<<< + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) + */ + /*else*/ { + __pyx_t_7 = (__pyx_v_self->attribute_dict == Py_None); + __pyx_t_9 = (__pyx_t_7 != 0); + if (__pyx_t_9) { + + /* "pysam/libctabixproxies.pyx":633 + * # deal with generic attributes (gene_id, ...) + * if self.attribute_dict is None: + * self.attribute_dict = self.attribute_string2dict( # <<<<<<<<<<<<<< + * self.attributes) + * return self.attribute_dict[key] + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attribute_string2dict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 633, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "pysam/libctabixproxies.pyx":634 + * if self.attribute_dict is None: + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) # <<<<<<<<<<<<<< + * return self.attribute_dict[key] + * + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attributes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 634, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + if (!__pyx_t_5) { + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 633, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_10); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; + __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 633, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3}; + __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 633, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 633, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 633, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libctabixproxies.pyx":633 + * # deal with generic attributes (gene_id, ...) + * if self.attribute_dict is None: + * self.attribute_dict = self.attribute_string2dict( # <<<<<<<<<<<<<< + * self.attributes) + * return self.attribute_dict[key] + */ + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_v_self->attribute_dict); + __Pyx_DECREF(__pyx_v_self->attribute_dict); + __pyx_v_self->attribute_dict = __pyx_t_10; + __pyx_t_10 = 0; + + /* "pysam/libctabixproxies.pyx":632 + * else: + * # deal with generic attributes (gene_id, ...) + * if self.attribute_dict is None: # <<<<<<<<<<<<<< + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) + */ + } + + /* "pysam/libctabixproxies.pyx":635 + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) + * return self.attribute_dict[key] # <<<<<<<<<<<<<< + * + * def __setattr__(self, key, value): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_v_self->attribute_dict, __pyx_v_key); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 635, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_r = __pyx_t_10; + __pyx_t_10 = 0; + goto __pyx_L0; + } + + /* "pysam/libctabixproxies.pyx":608 + * yield n, v + * + * def __getattr__(self, key): # <<<<<<<<<<<<<< + * """Generic lookup of attribute from GFF/GTF attributes + * """ + */ + + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libctabixproxies.NamedTupleProxy.__setattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_s); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":692 - * TupleProxy.__setitem__(self, idx, str(value)) +/* "pysam/libctabixproxies.pyx":637 + * return self.attribute_dict[key] + * + * def __setattr__(self, key, value): # <<<<<<<<<<<<<< + * '''set attribute.''' * - * def __getattr__(self, key): # <<<<<<<<<<<<<< - * cdef int idx - * idx, f = self.map_key2field[key] */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_3__getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_3__getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_36__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_35__setattr__[] = "set attribute."; +#if CYTHON_COMPILING_IN_CPYTHON +struct wrapperbase __pyx_wrapperbase_5pysam_16libctabixproxies_8GTFProxy_35__setattr__; +#endif +static int __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_36__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_2__getattr__(((struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *)__pyx_v_self), ((PyObject *)__pyx_v_key)); + __Pyx_RefNannySetupContext("__setattr__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_35__setattr__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_2__getattr__(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self, PyObject *__pyx_v_key) { +static int __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_35__setattr__(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { int __pyx_v_idx; PyObject *__pyx_v_f = NULL; - PyObject *__pyx_r = NULL; + PyObject *__pyx_v_s = NULL; + int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *(*__pyx_t_5)(PyObject *); - int __pyx_t_6; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *(*__pyx_t_6)(PyObject *); int __pyx_t_7; - struct __pyx_opt_args_5pysam_9libcutils_force_str __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - __Pyx_RefNannySetupContext("__getattr__", 0); + int __pyx_t_8; + struct __pyx_opt_args_5pysam_9libcutils_force_bytes __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + __Pyx_RefNannySetupContext("__setattr__", 0); - /* "pysam/libctabixproxies.pyx":694 - * def __getattr__(self, key): + /* "pysam/libctabixproxies.pyx":644 + * # called after any properties have been resolved. * cdef int idx - * idx, f = self.map_key2field[key] # <<<<<<<<<<<<<< - * if self.nfields < idx: - * raise KeyError("field %s not set" % key) + * idx, f = self.map_key2field.get(key, (-1, None)) # <<<<<<<<<<<<<< + * + * if idx >= 0: */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_map_key2field); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 694, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_map_key2field); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 644, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 644, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_4 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_4 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_key, __pyx_tuple__30}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 644, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_key, __pyx_tuple__30}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 644, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 644, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_key); + __Pyx_GIVEREF(__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_key); + __Pyx_INCREF(__pyx_tuple__30); + __Pyx_GIVEREF(__pyx_tuple__30); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_tuple__30); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 644, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 694, __pyx_L1_error) + __PYX_ERR(0, 644, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_5 = PyList_GET_ITEM(sequence, 1); } - __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_5); #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 694, __pyx_L1_error) + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 644, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 644, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { Py_ssize_t index = -1; - __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 694, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L3_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_3 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed; + __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 644, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_2); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) __PYX_ERR(0, 694, __pyx_L1_error) - __pyx_t_5 = NULL; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + index = 1; __pyx_t_5 = __pyx_t_6(__pyx_t_2); if (unlikely(!__pyx_t_5)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_2), 2) < 0) __PYX_ERR(0, 644, __pyx_L1_error) + __pyx_t_6 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L4_unpacking_done; __pyx_L3_unpacking_failed:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_5 = NULL; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 694, __pyx_L1_error) + __PYX_ERR(0, 644, __pyx_L1_error) __pyx_L4_unpacking_done:; } - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 694, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_idx = __pyx_t_6; - __pyx_v_f = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 644, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_idx = __pyx_t_4; + __pyx_v_f = __pyx_t_5; + __pyx_t_5 = 0; - /* "pysam/libctabixproxies.pyx":695 - * cdef int idx - * idx, f = self.map_key2field[key] - * if self.nfields < idx: # <<<<<<<<<<<<<< - * raise KeyError("field %s not set" % key) - * if f == str: + /* "pysam/libctabixproxies.pyx":646 + * idx, f = self.map_key2field.get(key, (-1, None)) + * + * if idx >= 0: # <<<<<<<<<<<<<< + * if value is None: + * s = "." */ - __pyx_t_7 = ((__pyx_v_self->__pyx_base.nfields < __pyx_v_idx) != 0); - if (unlikely(__pyx_t_7)) { + __pyx_t_7 = ((__pyx_v_idx >= 0) != 0); + if (__pyx_t_7) { - /* "pysam/libctabixproxies.pyx":696 - * idx, f = self.map_key2field[key] - * if self.nfields < idx: - * raise KeyError("field %s not set" % key) # <<<<<<<<<<<<<< - * if f == str: - * return force_str(self.fields[idx], + /* "pysam/libctabixproxies.pyx":647 + * + * if idx >= 0: + * if value is None: # <<<<<<<<<<<<<< + * s = "." + * elif f[1] == str: */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_field_s_not_set, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 696, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 696, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 696, __pyx_L1_error) + __pyx_t_7 = (__pyx_v_value == Py_None); + __pyx_t_8 = (__pyx_t_7 != 0); + if (__pyx_t_8) { - /* "pysam/libctabixproxies.pyx":695 - * cdef int idx - * idx, f = self.map_key2field[key] - * if self.nfields < idx: # <<<<<<<<<<<<<< - * raise KeyError("field %s not set" % key) - * if f == str: + /* "pysam/libctabixproxies.pyx":648 + * if idx >= 0: + * if value is None: + * s = "." # <<<<<<<<<<<<<< + * elif f[1] == str: + * s = force_bytes(value, */ - } + __Pyx_INCREF(__pyx_kp_s__13); + __pyx_v_s = __pyx_kp_s__13; - /* "pysam/libctabixproxies.pyx":697 - * if self.nfields < idx: - * raise KeyError("field %s not set" % key) - * if f == str: # <<<<<<<<<<<<<< - * return force_str(self.fields[idx], - * self.encoding) + /* "pysam/libctabixproxies.pyx":647 + * + * if idx >= 0: + * if value is None: # <<<<<<<<<<<<<< + * s = "." + * elif f[1] == str: */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_f, ((PyObject *)(&PyString_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 697, __pyx_L1_error) - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 697, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_7) { + goto __pyx_L6; + } - /* "pysam/libctabixproxies.pyx":698 - * raise KeyError("field %s not set" % key) - * if f == str: - * return force_str(self.fields[idx], # <<<<<<<<<<<<<< - * self.encoding) - * return f(self.fields[idx]) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyBytes_FromString((__pyx_v_self->__pyx_base.fields[__pyx_v_idx])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 698, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + /* "pysam/libctabixproxies.pyx":649 + * if value is None: + * s = "." + * elif f[1] == str: # <<<<<<<<<<<<<< + * s = force_bytes(value, + * self.encoding) + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_f, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 649, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)(&PyString_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 649, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 649, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_8) { - /* "pysam/libctabixproxies.pyx":699 - * if f == str: - * return force_str(self.fields[idx], - * self.encoding) # <<<<<<<<<<<<<< - * return f(self.fields[idx]) - * + /* "pysam/libctabixproxies.pyx":651 + * elif f[1] == str: + * s = force_bytes(value, + * self.encoding) # <<<<<<<<<<<<<< + * else: + * s = str(f[1](value)) */ - __pyx_t_2 = __pyx_v_self->__pyx_base.encoding; - __Pyx_INCREF(__pyx_t_2); + __pyx_t_5 = __pyx_v_self->__pyx_base.__pyx_base.encoding; + __Pyx_INCREF(__pyx_t_5); - /* "pysam/libctabixproxies.pyx":698 - * raise KeyError("field %s not set" % key) - * if f == str: - * return force_str(self.fields[idx], # <<<<<<<<<<<<<< - * self.encoding) - * return f(self.fields[idx]) + /* "pysam/libctabixproxies.pyx":650 + * s = "." + * elif f[1] == str: + * s = force_bytes(value, # <<<<<<<<<<<<<< + * self.encoding) + * else: */ - __pyx_t_8.__pyx_n = 1; - __pyx_t_8.encoding = __pyx_t_2; - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, &__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 698, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_9.__pyx_n = 1; + __pyx_t_9.encoding = __pyx_t_5; + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_value, &__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 650, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_s = __pyx_t_1; + __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":697 - * if self.nfields < idx: - * raise KeyError("field %s not set" % key) - * if f == str: # <<<<<<<<<<<<<< - * return force_str(self.fields[idx], - * self.encoding) + /* "pysam/libctabixproxies.pyx":649 + * if value is None: + * s = "." + * elif f[1] == str: # <<<<<<<<<<<<<< + * s = force_bytes(value, + * self.encoding) */ - } + goto __pyx_L6; + } - /* "pysam/libctabixproxies.pyx":700 - * return force_str(self.fields[idx], - * self.encoding) - * return f(self.fields[idx]) # <<<<<<<<<<<<<< - * - * + /* "pysam/libctabixproxies.pyx":653 + * self.encoding) + * else: + * s = str(f[1](value)) # <<<<<<<<<<<<<< + * TupleProxy._setindex(self, idx, s) + * else: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyBytes_FromString((__pyx_v_self->__pyx_base.fields[__pyx_v_idx])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 700, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_f); - __pyx_t_3 = __pyx_v_f; __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); + /*else*/ { + __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_f, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 653, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 653, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_value}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 653, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_value}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 653, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 653, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_value); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 653, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 653, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_s = __pyx_t_5; + __pyx_t_5 = 0; } - } - if (!__pyx_t_4) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 700, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_L6:; + + /* "pysam/libctabixproxies.pyx":654 + * else: + * s = str(f[1](value)) + * TupleProxy._setindex(self, idx, s) # <<<<<<<<<<<<<< + * else: + * if self.attribute_dict is None: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_n_s_setindex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 654, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - } else { + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 654, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + __pyx_t_4 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_4 = 1; + } + } #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 700, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, ((PyObject *)__pyx_v_self), __pyx_t_2, __pyx_v_s}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 654, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 700, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, ((PyObject *)__pyx_v_self), __pyx_t_2, __pyx_v_s}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 654, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else #endif { - __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 700, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_9); - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4); __pyx_t_4 = NULL; + __pyx_t_10 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 654, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_4, ((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_4, __pyx_t_2); + __Pyx_INCREF(__pyx_v_s); + __Pyx_GIVEREF(__pyx_v_s); + PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_4, __pyx_v_s); __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 700, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_10, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 654, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "pysam/libctabixproxies.pyx":646 + * idx, f = self.map_key2field.get(key, (-1, None)) + * + * if idx >= 0: # <<<<<<<<<<<<<< + * if value is None: + * s = "." + */ + goto __pyx_L5; + } + + /* "pysam/libctabixproxies.pyx":656 + * TupleProxy._setindex(self, idx, s) + * else: + * if self.attribute_dict is None: # <<<<<<<<<<<<<< + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) + */ + /*else*/ { + __pyx_t_8 = (__pyx_v_self->attribute_dict == Py_None); + __pyx_t_7 = (__pyx_t_8 != 0); + if (__pyx_t_7) { + + /* "pysam/libctabixproxies.pyx":657 + * else: + * if self.attribute_dict is None: + * self.attribute_dict = self.attribute_string2dict( # <<<<<<<<<<<<<< + * self.attributes) + * self.attribute_dict[key] = value + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attribute_string2dict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "pysam/libctabixproxies.pyx":658 + * if self.attribute_dict is None: + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) # <<<<<<<<<<<<<< + * self.attribute_dict[key] = value + * self.is_modified = True + */ + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_attributes); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 658, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + if (!__pyx_t_2) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_10}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_10}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __pyx_t_2 = NULL; + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 657, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libctabixproxies.pyx":657 + * else: + * if self.attribute_dict is None: + * self.attribute_dict = self.attribute_string2dict( # <<<<<<<<<<<<<< + * self.attributes) + * self.attribute_dict[key] = value + */ + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->attribute_dict); + __Pyx_DECREF(__pyx_v_self->attribute_dict); + __pyx_v_self->attribute_dict = __pyx_t_5; + __pyx_t_5 = 0; + + /* "pysam/libctabixproxies.pyx":656 + * TupleProxy._setindex(self, idx, s) + * else: + * if self.attribute_dict is None: # <<<<<<<<<<<<<< + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) + */ } + + /* "pysam/libctabixproxies.pyx":659 + * self.attribute_dict = self.attribute_string2dict( + * self.attributes) + * self.attribute_dict[key] = value # <<<<<<<<<<<<<< + * self.is_modified = True + * + */ + if (unlikely(PyObject_SetItem(__pyx_v_self->attribute_dict, __pyx_v_key, __pyx_v_value) < 0)) __PYX_ERR(0, 659, __pyx_L1_error) + + /* "pysam/libctabixproxies.pyx":660 + * self.attributes) + * self.attribute_dict[key] = value + * self.is_modified = True # <<<<<<<<<<<<<< + * + * # for backwards compatibility + */ + __pyx_v_self->__pyx_base.__pyx_base.is_modified = 1; } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_L5:; - /* "pysam/libctabixproxies.pyx":692 - * TupleProxy.__setitem__(self, idx, str(value)) + /* "pysam/libctabixproxies.pyx":637 + * return self.attribute_dict[key] + * + * def __setattr__(self, key, value): # <<<<<<<<<<<<<< + * '''set attribute.''' * - * def __getattr__(self, key): # <<<<<<<<<<<<<< - * cdef int idx - * idx, f = self.map_key2field[key] */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("pysam.libctabixproxies.NamedTupleProxy.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__setattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_f); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_v_s); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): +/* "pysam/libctabixproxies.pyx":663 + * + * # for backwards compatibility + * def asDict(self, *args, **kwargs): # <<<<<<<<<<<<<< + * return self.to_dict(*args, **kwargs) + * */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_38asDict(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_38asDict(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_args = 0; + PyObject *__pyx_v_kwargs = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_4__reduce_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("asDict (wrapper)", 0); + if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "asDict", 1))) return NULL; + if (unlikely(__pyx_kwds)) { + __pyx_v_kwargs = PyDict_Copy(__pyx_kwds); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + } else { + __pyx_v_kwargs = NULL; + } + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_37asDict(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_37asDict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__reduce_cython__", 0); + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("asDict", 0); - /* "(tree fragment)":2 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + /* "pysam/libctabixproxies.pyx":664 + * # for backwards compatibility + * def asDict(self, *args, **kwargs): + * return self.to_dict(*args, **kwargs) # <<<<<<<<<<<<<< + * + * def fromDict(self, *args, **kwargs): */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 664, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_v_args, __pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 664, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "(tree fragment)":1 - * def __reduce_cython__(self): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): + /* "pysam/libctabixproxies.pyx":663 + * + * # for backwards compatibility + * def asDict(self, *args, **kwargs): # <<<<<<<<<<<<<< + * return self.to_dict(*args, **kwargs) + * */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.NamedTupleProxy.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.asDict", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; + __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") +/* "pysam/libctabixproxies.pyx":666 + * return self.to_dict(*args, **kwargs) + * + * def fromDict(self, *args, **kwargs): # <<<<<<<<<<<<<< + * return self.from_dict(*args, **kwargs) + * */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_40fromDict(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_40fromDict(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_args = 0; + PyObject *__pyx_v_kwargs = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_6__setstate_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __Pyx_RefNannySetupContext("fromDict (wrapper)", 0); + if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "fromDict", 1))) return NULL; + if (unlikely(__pyx_kwds)) { + __pyx_v_kwargs = PyDict_Copy(__pyx_kwds); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + } else { + __pyx_v_kwargs = NULL; + } + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_39fromDict(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_15NamedTupleProxy_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_39fromDict(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__setstate_cython__", 0); - - /* "(tree fragment)":4 - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< - */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 4, __pyx_L1_error) - - /* "(tree fragment)":3 - * def __reduce_cython__(self): - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< - * raise TypeError("no default __reduce__ due to non-trivial __cinit__") - */ - - /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.NamedTupleProxy.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "pysam/libctabixproxies.pyx":722 - * 'blockStarts': (11, str), } - * - * cpdef int getMinFields(self): # <<<<<<<<<<<<<< - * '''return minimum number of fields.''' - * return 3 - */ - -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_1getMinFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static int __pyx_f_5pysam_16libctabixproxies_8BedProxy_getMinFields(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, int __pyx_skip_dispatch) { - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - __Pyx_RefNannySetupContext("getMinFields", 0); - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getMinFields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 722, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8BedProxy_1getMinFields)) { - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 722, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 722, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 722, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_5; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } + __Pyx_RefNannySetupContext("fromDict", 0); - /* "pysam/libctabixproxies.pyx":724 - * cpdef int getMinFields(self): - * '''return minimum number of fields.''' - * return 3 # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":667 + * + * def fromDict(self, *args, **kwargs): + * return self.from_dict(*args, **kwargs) # <<<<<<<<<<<<<< + * * - * cpdef int getMaxFields(self): */ - __pyx_r = 3; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_from_dict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 667, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_v_args, __pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 667, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":722 - * 'blockStarts': (11, str), } + /* "pysam/libctabixproxies.pyx":666 + * return self.to_dict(*args, **kwargs) + * + * def fromDict(self, *args, **kwargs): # <<<<<<<<<<<<<< + * return self.from_dict(*args, **kwargs) * - * cpdef int getMinFields(self): # <<<<<<<<<<<<<< - * '''return minimum number of fields.''' - * return 3 */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_WriteUnraisable("pysam.libctabixproxies.BedProxy.getMinFields", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_r = 0; + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.fromDict", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + */ + /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_1getMinFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8BedProxy_getMinFields[] = "return minimum number of fields."; -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_1getMinFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_42__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_42__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getMinFields (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8BedProxy_getMinFields(((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_41__reduce_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_getMinFields(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_41__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("getMinFields", 0); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_5pysam_16libctabixproxies_8BedProxy_getMinFields(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 722, __pyx_L1_error) + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 2, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.getMinFields", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; - __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":726 - * return 3 - * - * cpdef int getMaxFields(self): # <<<<<<<<<<<<<< - * '''return max number of fields.''' - * return 12 +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_3getMaxFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static int __pyx_f_5pysam_16libctabixproxies_8BedProxy_getMaxFields(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, int __pyx_skip_dispatch) { - int __pyx_r; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_44__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_44__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8GTFProxy_43__setstate_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8GTFProxy_43__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - __Pyx_RefNannySetupContext("getMaxFields", 0); - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getMaxFields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 726, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8BedProxy_3getMaxFields)) { - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } - } - if (__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 726, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 726, __pyx_L1_error) - } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 726, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_5; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } + __Pyx_RefNannySetupContext("__setstate_cython__", 0); - /* "pysam/libctabixproxies.pyx":728 - * cpdef int getMaxFields(self): - * '''return max number of fields.''' - * return 12 # <<<<<<<<<<<<<< - * - * cdef update(self, char * buffer, size_t nbytes): + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_r = 12; - goto __pyx_L0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":726 - * return 3 - * - * cpdef int getMaxFields(self): # <<<<<<<<<<<<<< - * '''return max number of fields.''' - * return 12 + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_WriteUnraisable("pysam.libctabixproxies.BedProxy.getMaxFields", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); - __pyx_r = 0; - __pyx_L0:; + __Pyx_AddTraceback("pysam.libctabixproxies.GTFProxy.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +/* "pysam/libctabixproxies.pyx":672 + * cdef class GFF3Proxy(GTFProxy): + * + * def dict2attribute_string(self, d): # <<<<<<<<<<<<<< + * """convert dictionary to attribute string.""" + * return ";".join(["{}={}".format(k, v) for k, v in d.items()]) + */ + /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_3getMaxFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8BedProxy_2getMaxFields[] = "return max number of fields."; -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_3getMaxFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_9GFF3Proxy_1dict2attribute_string(PyObject *__pyx_v_self, PyObject *__pyx_v_d); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_9GFF3Proxy_dict2attribute_string[] = "convert dictionary to attribute string."; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_9GFF3Proxy_1dict2attribute_string(PyObject *__pyx_v_self, PyObject *__pyx_v_d) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getMaxFields (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8BedProxy_2getMaxFields(((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("dict2attribute_string (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_dict2attribute_string(((struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *)__pyx_v_self), ((PyObject *)__pyx_v_d)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_2getMaxFields(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_dict2attribute_string(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *__pyx_v_self, PyObject *__pyx_v_d) { + PyObject *__pyx_v_k = NULL; + PyObject *__pyx_v_v = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("getMaxFields", 0); + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + PyObject *(*__pyx_t_6)(PyObject *); + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_t_10; + __Pyx_RefNannySetupContext("dict2attribute_string", 0); + + /* "pysam/libctabixproxies.pyx":674 + * def dict2attribute_string(self, d): + * """convert dictionary to attribute string.""" + * return ";".join(["{}={}".format(k, v) for k, v in d.items()]) # <<<<<<<<<<<<<< + * + * def attribute_string2iterator(self, s): + */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_5pysam_16libctabixproxies_8BedProxy_getMaxFields(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 726, __pyx_L1_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 674, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_d, __pyx_n_s_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 674, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_6)) { + if (likely(PyList_CheckExact(__pyx_t_3))) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 674, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 674, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_6(__pyx_t_3); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 674, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 674, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_4 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_7); + #else + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; + index = 0; __pyx_t_4 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_4)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) __PYX_ERR(0, 674, __pyx_L1_error) + __pyx_t_9 = NULL; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 674, __pyx_L1_error) + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_k, __pyx_t_4); + __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s__33, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_k, __pyx_v_v}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_k, __pyx_v_v}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_k); + __Pyx_GIVEREF(__pyx_v_k); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_10, __pyx_v_k); + __Pyx_INCREF(__pyx_v_v); + __Pyx_GIVEREF(__pyx_v_v); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_10, __pyx_v_v); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__20, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 674, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; goto __pyx_L0; + /* "pysam/libctabixproxies.pyx":672 + * cdef class GFF3Proxy(GTFProxy): + * + * def dict2attribute_string(self, d): # <<<<<<<<<<<<<< + * """convert dictionary to attribute string.""" + * return ";".join(["{}={}".format(k, v) for k, v in d.items()]) + */ + /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.getMaxFields", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pysam.libctabixproxies.GFF3Proxy.dict2attribute_string", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_k); + __Pyx_XDECREF(__pyx_v_v); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5pysam_16libctabixproxies_9GFF3Proxy_4generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ -/* "pysam/libctabixproxies.pyx":730 - * return 12 - * - * cdef update(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< - * '''update internal data. +/* "pysam/libctabixproxies.pyx":676 + * return ";".join(["{}={}".format(k, v) for k, v in d.items()]) * + * def attribute_string2iterator(self, s): # <<<<<<<<<<<<<< + * """convert attribute string in GFF3 format to records + * and iterate over key, value pairs. */ -static PyObject *__pyx_f_5pysam_16libctabixproxies_8BedProxy_update(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, char *__pyx_v_buffer, size_t __pyx_v_nbytes) { - PyObject *__pyx_r = NULL; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_9GFF3Proxy_3attribute_string2iterator(PyObject *__pyx_v_self, PyObject *__pyx_v_s); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_9GFF3Proxy_2attribute_string2iterator[] = "convert attribute string in GFF3 format to records\n and iterate over key, value pairs.\n "; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_9GFF3Proxy_3attribute_string2iterator(PyObject *__pyx_v_self, PyObject *__pyx_v_s) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("update", 0); - - /* "pysam/libctabixproxies.pyx":735 - * nbytes does not include the terminal '\0'. - * ''' - * TupleProxy.update(self, buffer, nbytes) # <<<<<<<<<<<<<< - * - * if self.nfields < 3: - */ - __pyx_t_1 = __pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self), __pyx_v_buffer, __pyx_v_nbytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 735, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_RefNannySetupContext("attribute_string2iterator (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_2attribute_string2iterator(((struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *)__pyx_v_self), ((PyObject *)__pyx_v_s)); - /* "pysam/libctabixproxies.pyx":737 - * TupleProxy.update(self, buffer, nbytes) - * - * if self.nfields < 3: # <<<<<<<<<<<<<< - * raise ValueError( - * "bed format requires at least three columns") - */ - __pyx_t_2 = ((__pyx_v_self->__pyx_base.__pyx_base.nfields < 3) != 0); - if (unlikely(__pyx_t_2)) { + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5pysam_16libctabixproxies_9GFF3Proxy_25attribute_string2iterator_2generator2(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ - /* "pysam/libctabixproxies.pyx":738 - * - * if self.nfields < 3: - * raise ValueError( # <<<<<<<<<<<<<< - * "bed format requires at least three columns") +/* "pysam/libctabixproxies.pyx":681 + * """ * + * for f in (x.strip() for x in s.split(";")): # <<<<<<<<<<<<<< + * if not f: + * continue */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 738, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(0, 738, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":737 - * TupleProxy.update(self, buffer, nbytes) - * - * if self.nfields < 3: # <<<<<<<<<<<<<< - * raise ValueError( - * "bed format requires at least three columns") - */ +static PyObject *__pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_25attribute_string2iterator_genexpr(PyObject *__pyx_self) { + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("genexpr", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr *)__pyx_tp_new_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr(__pyx_ptype_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 681, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *) __pyx_self; + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); + { + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_16libctabixproxies_9GFF3Proxy_25attribute_string2iterator_2generator2, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_attribute_string2iterator_locals, __pyx_n_s_pysam_libctabixproxies); if (unlikely(!gen)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; } - - /* "pysam/libctabixproxies.pyx":742 - * - * # determines bed format - * self.bedfields = self.nfields # <<<<<<<<<<<<<< - * - * # do automatic conversion - */ - __pyx_t_3 = __pyx_v_self->__pyx_base.__pyx_base.nfields; - __pyx_v_self->bedfields = __pyx_t_3; - - /* "pysam/libctabixproxies.pyx":745 - * - * # do automatic conversion - * self.contig = self.fields[0] # <<<<<<<<<<<<<< - * self.start = atoi(self.fields[1]) - * self.end = atoi(self.fields[2]) - */ - __pyx_v_self->contig = (__pyx_v_self->__pyx_base.__pyx_base.fields[0]); - - /* "pysam/libctabixproxies.pyx":746 - * # do automatic conversion - * self.contig = self.fields[0] - * self.start = atoi(self.fields[1]) # <<<<<<<<<<<<<< - * self.end = atoi(self.fields[2]) - * - */ - __pyx_v_self->start = atoi((__pyx_v_self->__pyx_base.__pyx_base.fields[1])); - - /* "pysam/libctabixproxies.pyx":747 - * self.contig = self.fields[0] - * self.start = atoi(self.fields[1]) - * self.end = atoi(self.fields[2]) # <<<<<<<<<<<<<< - * - * # __setattr__ in base class seems to take precedence - */ - __pyx_v_self->end = atoi((__pyx_v_self->__pyx_base.__pyx_base.fields[2])); - - /* "pysam/libctabixproxies.pyx":730 - * return 12 - * - * cdef update(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< - * '''update internal data. - * - */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.update", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; + __Pyx_AddTraceback("pysam.libctabixproxies.GFF3Proxy.attribute_string2iterator.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":756 - * # def __get__( self ): return self.end - * - * def __str__(self): # <<<<<<<<<<<<<< - * - * cdef int save_fields = self.nfields - */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_5__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_5__str__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8BedProxy_4__str__(((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_4__str__(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self) { - int __pyx_v_save_fields; - PyObject *__pyx_v_retval = NULL; +static PyObject *__pyx_gb_5pysam_16libctabixproxies_9GFF3Proxy_25attribute_string2iterator_2generator2(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr *)__pyx_generator->closure); PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; + PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("__str__", 0); - - /* "pysam/libctabixproxies.pyx":758 - * def __str__(self): - * - * cdef int save_fields = self.nfields # <<<<<<<<<<<<<< - * # ensure fields to use correct format - * self.nfields = self.bedfields - */ - __pyx_t_1 = __pyx_v_self->__pyx_base.__pyx_base.nfields; - __pyx_v_save_fields = __pyx_t_1; - - /* "pysam/libctabixproxies.pyx":760 - * cdef int save_fields = self.nfields - * # ensure fields to use correct format - * self.nfields = self.bedfields # <<<<<<<<<<<<<< - * retval = TupleProxy.__str__(self) - * self.nfields = save_fields - */ - __pyx_t_1 = __pyx_v_self->bedfields; - __pyx_v_self->__pyx_base.__pyx_base.nfields = __pyx_t_1; - - /* "pysam/libctabixproxies.pyx":761 - * # ensure fields to use correct format - * self.nfields = self.bedfields - * retval = TupleProxy.__str__(self) # <<<<<<<<<<<<<< - * self.nfields = save_fields - * return retval - */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_n_s_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 761, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - } + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("genexpr", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; } - if (!__pyx_t_4) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 761, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 681, __pyx_L1_error) + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_s)) { __Pyx_RaiseClosureNameError("s"); __PYX_ERR(0, 681, __pyx_L1_error) } + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_s, __pyx_n_s_split); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; + __pyx_t_4 = NULL; } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_self)}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 761, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_self)}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 761, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); - } else - #endif - { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 761, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_5, 0+1, ((PyObject *)__pyx_v_self)); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 761, __pyx_L1_error) + __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 681, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_4)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 681, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 681, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_4(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 681, __pyx_L1_error) + } + break; + } __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_x, __pyx_n_s_strip); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (__pyx_t_6) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 681, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 681, __pyx_L1_error) } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_retval = __pyx_t_2; - __pyx_t_2 = 0; - - /* "pysam/libctabixproxies.pyx":762 - * self.nfields = self.bedfields - * retval = TupleProxy.__str__(self) - * self.nfields = save_fields # <<<<<<<<<<<<<< - * return retval - * - */ - __pyx_v_self->__pyx_base.__pyx_base.nfields = __pyx_v_save_fields; - - /* "pysam/libctabixproxies.pyx":763 - * retval = TupleProxy.__str__(self) - * self.nfields = save_fields - * return retval # <<<<<<<<<<<<<< - * - * def __setattr__(self, key, value ): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_retval); - __pyx_r = __pyx_v_retval; - goto __pyx_L0; - - /* "pysam/libctabixproxies.pyx":756 - * # def __get__( self ): return self.end - * - * def __str__(self): # <<<<<<<<<<<<<< - * - * cdef int save_fields = self.nfields - */ + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); /* function exit code */ + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_retval); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":765 - * return retval +/* "pysam/libctabixproxies.pyx":676 + * return ";".join(["{}={}".format(k, v) for k, v in d.items()]) * - * def __setattr__(self, key, value ): # <<<<<<<<<<<<<< - * '''set attribute.''' - * if key == "start": + * def attribute_string2iterator(self, s): # <<<<<<<<<<<<<< + * """convert attribute string in GFF3 format to records + * and iterate over key, value pairs. */ -/* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8BedProxy_7__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8BedProxy_6__setattr__[] = "set attribute."; -#if CYTHON_COMPILING_IN_CPYTHON -struct wrapperbase __pyx_wrapperbase_5pysam_16libctabixproxies_8BedProxy_6__setattr__; -#endif -static int __pyx_pw_5pysam_16libctabixproxies_8BedProxy_7__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_2attribute_string2iterator(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *__pyx_v_self, PyObject *__pyx_v_s) { + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *__pyx_cur_scope; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setattr__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8BedProxy_6__setattr__(((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_v_self), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("attribute_string2iterator", 0); + __pyx_cur_scope = (struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *)__pyx_tp_new_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator(__pyx_ptype_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 676, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_s = __pyx_v_s; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_s); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_s); + { + __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_16libctabixproxies_9GFF3Proxy_4generator1, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_attribute_string2iterator, __pyx_n_s_GFF3Proxy_attribute_string2itera, __pyx_n_s_pysam_libctabixproxies); if (unlikely(!gen)) __PYX_ERR(0, 676, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("pysam.libctabixproxies.GFF3Proxy.attribute_string2iterator", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_16libctabixproxies_8BedProxy_6__setattr__(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { - int __pyx_v_idx; - CYTHON_UNUSED PyObject *__pyx_v_f = NULL; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - uint32_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *(*__pyx_t_7)(PyObject *); - int __pyx_t_8; +static PyObject *__pyx_gb_5pysam_16libctabixproxies_9GFF3Proxy_4generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *__pyx_cur_scope = ((struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - __Pyx_RefNannySetupContext("__setattr__", 0); + PyObject *(*__pyx_t_10)(PyObject *); + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("attribute_string2iterator", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L17_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 676, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":767 - * def __setattr__(self, key, value ): - * '''set attribute.''' - * if key == "start": # <<<<<<<<<<<<<< - * self.start = value - * elif key == "end": + /* "pysam/libctabixproxies.pyx":681 + * """ + * + * for f in (x.strip() for x in s.split(";")): # <<<<<<<<<<<<<< + * if not f: + * continue */ - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_n_s_start, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 767, __pyx_L1_error) - if (__pyx_t_1) { + __pyx_t_1 = __pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_25attribute_string2iterator_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 681, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (likely(!__pyx_t_4)) { + if (likely(PyList_CheckExact(__pyx_t_2))) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 681, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 681, __pyx_L1_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } + } else { + __pyx_t_1 = __pyx_t_4(__pyx_t_2); + if (unlikely(!__pyx_t_1)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 681, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_f, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":768 - * '''set attribute.''' - * if key == "start": - * self.start = value # <<<<<<<<<<<<<< - * elif key == "end": - * self.end = value + /* "pysam/libctabixproxies.pyx":682 + * + * for f in (x.strip() for x in s.split(";")): + * if not f: # <<<<<<<<<<<<<< + * continue + * */ - __pyx_t_2 = __Pyx_PyInt_As_uint32_t(__pyx_v_value); if (unlikely((__pyx_t_2 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 768, __pyx_L1_error) - __pyx_v_self->start = __pyx_t_2; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_f); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 682, __pyx_L1_error) + __pyx_t_6 = ((!__pyx_t_5) != 0); + if (__pyx_t_6) { - /* "pysam/libctabixproxies.pyx":767 - * def __setattr__(self, key, value ): - * '''set attribute.''' - * if key == "start": # <<<<<<<<<<<<<< - * self.start = value - * elif key == "end": - */ - goto __pyx_L3; - } - - /* "pysam/libctabixproxies.pyx":769 - * if key == "start": - * self.start = value - * elif key == "end": # <<<<<<<<<<<<<< - * self.end = value + /* "pysam/libctabixproxies.pyx":683 + * for f in (x.strip() for x in s.split(";")): + * if not f: + * continue # <<<<<<<<<<<<<< * + * key, value = f.split("=", 1) */ - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_n_s_end, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 769, __pyx_L1_error) - if (__pyx_t_1) { + goto __pyx_L4_continue; - /* "pysam/libctabixproxies.pyx":770 - * self.start = value - * elif key == "end": - * self.end = value # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":682 + * + * for f in (x.strip() for x in s.split(";")): + * if not f: # <<<<<<<<<<<<<< + * continue * - * cdef int idx */ - __pyx_t_2 = __Pyx_PyInt_As_uint32_t(__pyx_v_value); if (unlikely((__pyx_t_2 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 770, __pyx_L1_error) - __pyx_v_self->end = __pyx_t_2; + } - /* "pysam/libctabixproxies.pyx":769 - * if key == "start": - * self.start = value - * elif key == "end": # <<<<<<<<<<<<<< - * self.end = value + /* "pysam/libctabixproxies.pyx":685 + * continue + * + * key, value = f.split("=", 1) # <<<<<<<<<<<<<< + * value = value.strip() * */ - } - __pyx_L3:; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_f, __pyx_n_s_split); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 685, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 685, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { + PyObject* sequence = __pyx_t_7; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 685, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_8 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 685, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 685, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + #endif + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_9 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 685, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_1)) goto __pyx_L7_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L7_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) __PYX_ERR(0, 685, __pyx_L1_error) + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L8_unpacking_done; + __pyx_L7_unpacking_failed:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 685, __pyx_L1_error) + __pyx_L8_unpacking_done:; + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_value); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_value, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_8 = 0; - /* "pysam/libctabixproxies.pyx":773 + /* "pysam/libctabixproxies.pyx":686 * - * cdef int idx - * idx, f = self.map_key2field[key] # <<<<<<<<<<<<<< - * TupleProxy._setindex(self, idx, str(value) ) + * key, value = f.split("=", 1) + * value = value.strip() # <<<<<<<<<<<<<< * + * ## try to convert to a value */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_map_key2field); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_3, __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { - PyObject* sequence = __pyx_t_4; - Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); - if (unlikely(size != 2)) { - if (size > 2) __Pyx_RaiseTooManyValuesError(2); - else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 773, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_value, __pyx_n_s_strip); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 686, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } } - #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); + if (__pyx_t_1) { + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 686, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_5 = PyList_GET_ITEM(sequence, 1); + __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 686, __pyx_L1_error) } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_5); - #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - #endif - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_5 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L4_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) __PYX_ERR(0, 773, __pyx_L1_error) - __pyx_t_7 = NULL; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - goto __pyx_L5_unpacking_done; - __pyx_L4_unpacking_failed:; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 773, __pyx_L1_error) - __pyx_L5_unpacking_done:; - } - __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 773, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_idx = __pyx_t_8; - __pyx_v_f = __pyx_t_5; - __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_value); + __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_value, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_t_7 = 0; - /* "pysam/libctabixproxies.pyx":774 - * cdef int idx - * idx, f = self.map_key2field[key] - * TupleProxy._setindex(self, idx, str(value) ) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":689 * - * cdef class VCFProxy(NamedTupleProxy): + * ## try to convert to a value + * try: # <<<<<<<<<<<<<< + * value = float(value) + * value = int(value) */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_n_s_setindex); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 774, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 774, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_value); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 774, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_9 = NULL; - __pyx_t_8 = 0; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_9)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - __pyx_t_8 = 1; + { + __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_13); + /*try:*/ { + + /* "pysam/libctabixproxies.pyx":690 + * ## try to convert to a value + * try: + * value = float(value) # <<<<<<<<<<<<<< + * value = int(value) + * except ValueError: + */ + __pyx_t_7 = __Pyx_PyNumber_Float(__pyx_cur_scope->__pyx_v_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 690, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_value); + __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_value, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_t_7 = 0; + + /* "pysam/libctabixproxies.pyx":691 + * try: + * value = float(value) + * value = int(value) # <<<<<<<<<<<<<< + * except ValueError: + * pass + */ + __pyx_t_7 = __Pyx_PyNumber_Int(__pyx_cur_scope->__pyx_v_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 691, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_value); + __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_value, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_t_7 = 0; + + /* "pysam/libctabixproxies.pyx":689 + * + * ## try to convert to a value + * try: # <<<<<<<<<<<<<< + * value = float(value) + * value = int(value) + */ + } + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L16_try_end; + __pyx_L9_error:; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "pysam/libctabixproxies.pyx":692 + * value = float(value) + * value = int(value) + * except ValueError: # <<<<<<<<<<<<<< + * pass + * except TypeError: + */ + __pyx_t_14 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError); + if (__pyx_t_14) { + __Pyx_ErrRestore(0,0,0); + goto __pyx_L10_exception_handled; + } + + /* "pysam/libctabixproxies.pyx":694 + * except ValueError: + * pass + * except TypeError: # <<<<<<<<<<<<<< + * pass + * + */ + __pyx_t_14 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError); + if (__pyx_t_14) { + __Pyx_ErrRestore(0,0,0); + goto __pyx_L10_exception_handled; + } + goto __pyx_L11_except_error; + __pyx_L11_except_error:; + + /* "pysam/libctabixproxies.pyx":689 + * + * ## try to convert to a value + * try: # <<<<<<<<<<<<<< + * value = float(value) + * value = int(value) + */ + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); + goto __pyx_L1_error; + __pyx_L10_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); + __pyx_L16_try_end:; } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[4] = {__pyx_t_9, ((PyObject *)__pyx_v_self), __pyx_t_3, __pyx_t_6}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 774, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { - PyObject *__pyx_temp[4] = {__pyx_t_9, ((PyObject *)__pyx_v_self), __pyx_t_3, __pyx_t_6}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 774, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else - #endif - { - __pyx_t_10 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 774, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_10); - if (__pyx_t_9) { - __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; + + /* "pysam/libctabixproxies.pyx":697 + * pass + * + * yield key.strip(), value # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_key, __pyx_n_s_strip); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 697, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } } - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_8, ((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_8, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_8, __pyx_t_6); - __pyx_t_3 = 0; - __pyx_t_6 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 774, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__pyx_t_1) { + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 697, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 697, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 697, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_value); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_cur_scope->__pyx_v_value); + __pyx_t_7 = 0; + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L17_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 697, __pyx_L1_error) + + /* "pysam/libctabixproxies.pyx":681 + * """ + * + * for f in (x.strip() for x in s.split(";")): # <<<<<<<<<<<<<< + * if not f: + * continue + */ + __pyx_L4_continue:; } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); - /* "pysam/libctabixproxies.pyx":765 - * return retval + /* "pysam/libctabixproxies.pyx":676 + * return ";".join(["{}={}".format(k, v) for k, v in d.items()]) * - * def __setattr__(self, key, value ): # <<<<<<<<<<<<<< - * '''set attribute.''' - * if key == "start": + * def attribute_string2iterator(self, s): # <<<<<<<<<<<<<< + * """convert attribute string in GFF3 format to records + * and iterate over key, value pairs. */ /* function exit code */ - __pyx_r = 0; + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.__setattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("attribute_string2iterator", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return __pyx_r; } @@ -13623,19 +14061,19 @@ static int __pyx_pf_5pysam_16libctabixproxies_8BedProxy_6__setattr__(struct __py */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_9GFF3Proxy_6__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_9GFF3Proxy_6__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8BedProxy_8__reduce_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_5__reduce_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_5__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -13647,7 +14085,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_8__reduce_cython__ * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -13662,7 +14100,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_8__reduce_cython__ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabixproxies.GFF3Proxy.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); @@ -13677,19 +14115,19 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_8__reduce_cython__ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_9GFF3Proxy_8__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_9GFF3Proxy_8__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8BedProxy_10__setstate_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_7__setstate_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_9GFF3Proxy_7__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -13700,7 +14138,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_10__setstate_cytho * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -13716,348 +14154,637 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_10__setstate_cytho /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabixproxies.GFF3Proxy.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":793 - * 'format' : (8, str) } +/* "pysam/libctabixproxies.pyx":719 + * 'blockStarts': (11, str), } * - * def __cinit__(self): # <<<<<<<<<<<<<< - * # automatically calls TupleProxy.__cinit__ - * # start indexed access at genotypes + * cpdef int getMinFields(self): # <<<<<<<<<<<<<< + * '''return minimum number of fields.''' + * return 3 */ -/* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_1getMinFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static int __pyx_f_5pysam_16libctabixproxies_8BedProxy_getMinFields(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, int __pyx_skip_dispatch) { int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} - if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8VCFProxy___cinit__(((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy___cinit__(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + __Pyx_RefNannySetupContext("getMinFields", 0); + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getMinFields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 719, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8BedProxy_1getMinFields)) { + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 719, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 719, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 719, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_5; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } - /* "pysam/libctabixproxies.pyx":796 - * # automatically calls TupleProxy.__cinit__ - * # start indexed access at genotypes - * self.offset = 9 # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":721 + * cpdef int getMinFields(self): + * '''return minimum number of fields.''' + * return 3 # <<<<<<<<<<<<<< * - * cdef update(self, char * buffer, size_t nbytes): + * cpdef int getMaxFields(self): */ - __pyx_v_self->__pyx_base.__pyx_base.offset = 9; + __pyx_r = 3; + goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":793 - * 'format' : (8, str) } + /* "pysam/libctabixproxies.pyx":719 + * 'blockStarts': (11, str), } * - * def __cinit__(self): # <<<<<<<<<<<<<< - * # automatically calls TupleProxy.__cinit__ - * # start indexed access at genotypes + * cpdef int getMinFields(self): # <<<<<<<<<<<<<< + * '''return minimum number of fields.''' + * return 3 */ /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_WriteUnraisable("pysam.libctabixproxies.BedProxy.getMinFields", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_r = 0; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":798 - * self.offset = 9 - * - * cdef update(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< - * '''update internal data. - * - */ +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_1getMinFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8BedProxy_getMinFields[] = "return minimum number of fields."; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_1getMinFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getMinFields (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8BedProxy_getMinFields(((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_v_self)); -static PyObject *__pyx_f_5pysam_16libctabixproxies_8VCFProxy_update(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self, char *__pyx_v_buffer, size_t __pyx_v_nbytes) { + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_getMinFields(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("update", 0); - - /* "pysam/libctabixproxies.pyx":803 - * nbytes does not include the terminal '\0'. - * ''' - * TupleProxy.update(self, buffer, nbytes) # <<<<<<<<<<<<<< - * - * self.contig = self.fields[0] - */ - __pyx_t_1 = __pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self), __pyx_v_buffer, __pyx_v_nbytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 803, __pyx_L1_error) + __Pyx_RefNannySetupContext("getMinFields", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_5pysam_16libctabixproxies_8BedProxy_getMinFields(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 719, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "pysam/libctabixproxies.pyx":805 - * TupleProxy.update(self, buffer, nbytes) - * - * self.contig = self.fields[0] # <<<<<<<<<<<<<< - * # vcf counts from 1 - correct here - * self.pos = atoi(self.fields[1]) - 1 - */ - __pyx_v_self->contig = (__pyx_v_self->__pyx_base.__pyx_base.fields[0]); - - /* "pysam/libctabixproxies.pyx":807 - * self.contig = self.fields[0] - * # vcf counts from 1 - correct here - * self.pos = atoi(self.fields[1]) - 1 # <<<<<<<<<<<<<< - * - * def __len__(self): - */ - __pyx_v_self->pos = (atoi((__pyx_v_self->__pyx_base.__pyx_base.fields[1])) - 1); - - /* "pysam/libctabixproxies.pyx":798 - * self.offset = 9 - * - * cdef update(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< - * '''update internal data. - * - */ + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.VCFProxy.update", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.getMinFields", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":809 - * self.pos = atoi(self.fields[1]) - 1 +/* "pysam/libctabixproxies.pyx":723 + * return 3 * - * def __len__(self): # <<<<<<<<<<<<<< - * '''return number of genotype fields.''' - * return max(0, self.nfields - 9) + * cpdef int getMaxFields(self): # <<<<<<<<<<<<<< + * '''return max number of fields.''' + * return 12 */ -/* Python wrapper */ -static Py_ssize_t __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3__len__(PyObject *__pyx_v_self); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8VCFProxy_2__len__[] = "return number of genotype fields."; -#if CYTHON_COMPILING_IN_CPYTHON -struct wrapperbase __pyx_wrapperbase_5pysam_16libctabixproxies_8VCFProxy_2__len__; -#endif -static Py_ssize_t __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_2__len__(((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static Py_ssize_t __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_2__len__(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self) { - Py_ssize_t __pyx_r; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_3getMaxFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static int __pyx_f_5pysam_16libctabixproxies_8BedProxy_getMaxFields(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, int __pyx_skip_dispatch) { + int __pyx_r; __Pyx_RefNannyDeclarations - long __pyx_t_1; - long __pyx_t_2; - long __pyx_t_3; - __Pyx_RefNannySetupContext("__len__", 0); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + __Pyx_RefNannySetupContext("getMaxFields", 0); + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_getMaxFields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 723, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8BedProxy_3getMaxFields)) { + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 723, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 723, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 723, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_5; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } - /* "pysam/libctabixproxies.pyx":811 - * def __len__(self): - * '''return number of genotype fields.''' - * return max(0, self.nfields - 9) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":725 + * cpdef int getMaxFields(self): + * '''return max number of fields.''' + * return 12 # <<<<<<<<<<<<<< * - * property pos: + * cdef update(self, char * buffer, size_t nbytes): */ - __pyx_t_1 = (__pyx_v_self->__pyx_base.__pyx_base.nfields - 9); - __pyx_t_2 = 0; - if (((__pyx_t_1 > __pyx_t_2) != 0)) { - __pyx_t_3 = __pyx_t_1; - } else { - __pyx_t_3 = __pyx_t_2; - } - __pyx_r = __pyx_t_3; + __pyx_r = 12; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":809 - * self.pos = atoi(self.fields[1]) - 1 + /* "pysam/libctabixproxies.pyx":723 + * return 3 * - * def __len__(self): # <<<<<<<<<<<<<< - * '''return number of genotype fields.''' - * return max(0, self.nfields - 9) + * cpdef int getMaxFields(self): # <<<<<<<<<<<<<< + * '''return max number of fields.''' + * return 12 */ /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_WriteUnraisable("pysam.libctabixproxies.BedProxy.getMaxFields", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":815 - * property pos: - * '''feature end (in 0-based open/closed coordinates).''' - * def __get__(self): # <<<<<<<<<<<<<< - * return self.pos - * - */ - /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3pos_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_3getMaxFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8BedProxy_2getMaxFields[] = "return max number of fields."; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_3getMaxFields(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_3pos___get__(((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_self)); + __Pyx_RefNannySetupContext("getMaxFields (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8BedProxy_2getMaxFields(((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_3pos___get__(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_2getMaxFields(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "pysam/libctabixproxies.pyx":816 - * '''feature end (in 0-based open/closed coordinates).''' - * def __get__(self): - * return self.pos # <<<<<<<<<<<<<< - * - * def __setattr__(self, key, value): - */ + __Pyx_RefNannySetupContext("getMaxFields", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 816, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_f_5pysam_16libctabixproxies_8BedProxy_getMaxFields(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "pysam/libctabixproxies.pyx":815 - * property pos: - * '''feature end (in 0-based open/closed coordinates).''' - * def __get__(self): # <<<<<<<<<<<<<< - * return self.pos + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.getMaxFields", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libctabixproxies.pyx":727 + * return 12 + * + * cdef update(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< + * '''update internal data. + * + */ + +static PyObject *__pyx_f_5pysam_16libctabixproxies_8BedProxy_update(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, char *__pyx_v_buffer, size_t __pyx_v_nbytes) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("update", 0); + + /* "pysam/libctabixproxies.pyx":732 + * nbytes does not include the terminal '\0'. + * ''' + * TupleProxy.update(self, buffer, nbytes) # <<<<<<<<<<<<<< + * + * if self.nfields < 3: + */ + __pyx_t_1 = __pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self), __pyx_v_buffer, __pyx_v_nbytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 732, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libctabixproxies.pyx":734 + * TupleProxy.update(self, buffer, nbytes) + * + * if self.nfields < 3: # <<<<<<<<<<<<<< + * raise ValueError( + * "bed format requires at least three columns") + */ + __pyx_t_2 = ((__pyx_v_self->__pyx_base.__pyx_base.nfields < 3) != 0); + if (unlikely(__pyx_t_2)) { + + /* "pysam/libctabixproxies.pyx":735 + * + * if self.nfields < 3: + * raise ValueError( # <<<<<<<<<<<<<< + * "bed format requires at least three columns") + * + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 735, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 735, __pyx_L1_error) + + /* "pysam/libctabixproxies.pyx":734 + * TupleProxy.update(self, buffer, nbytes) + * + * if self.nfields < 3: # <<<<<<<<<<<<<< + * raise ValueError( + * "bed format requires at least three columns") + */ + } + + /* "pysam/libctabixproxies.pyx":739 + * + * # determines bed format + * self.bedfields = self.nfields # <<<<<<<<<<<<<< + * + * # do automatic conversion + */ + __pyx_t_3 = __pyx_v_self->__pyx_base.__pyx_base.nfields; + __pyx_v_self->bedfields = __pyx_t_3; + + /* "pysam/libctabixproxies.pyx":742 + * + * # do automatic conversion + * self.contig = self.fields[0] # <<<<<<<<<<<<<< + * self.start = atoi(self.fields[1]) + * self.end = atoi(self.fields[2]) + */ + __pyx_v_self->contig = (__pyx_v_self->__pyx_base.__pyx_base.fields[0]); + + /* "pysam/libctabixproxies.pyx":743 + * # do automatic conversion + * self.contig = self.fields[0] + * self.start = atoi(self.fields[1]) # <<<<<<<<<<<<<< + * self.end = atoi(self.fields[2]) + * + */ + __pyx_v_self->start = atoi((__pyx_v_self->__pyx_base.__pyx_base.fields[1])); + + /* "pysam/libctabixproxies.pyx":744 + * self.contig = self.fields[0] + * self.start = atoi(self.fields[1]) + * self.end = atoi(self.fields[2]) # <<<<<<<<<<<<<< + * + * # __setattr__ in base class seems to take precedence + */ + __pyx_v_self->end = atoi((__pyx_v_self->__pyx_base.__pyx_base.fields[2])); + + /* "pysam/libctabixproxies.pyx":727 + * return 12 + * + * cdef update(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< + * '''update internal data. * */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.VCFProxy.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.update", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pysam/libctabixproxies.pyx":818 - * return self.pos +/* "pysam/libctabixproxies.pyx":753 + * # def __get__( self ): return self.end * - * def __setattr__(self, key, value): # <<<<<<<<<<<<<< - * '''set attribute.''' - * if key == "pos": + * def __str__(self): # <<<<<<<<<<<<<< + * + * cdef int save_fields = self.nfields */ /* Python wrapper */ -static int __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_5__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/ -static char __pyx_doc_5pysam_16libctabixproxies_8VCFProxy_4__setattr__[] = "set attribute."; -#if CYTHON_COMPILING_IN_CPYTHON -struct wrapperbase __pyx_wrapperbase_5pysam_16libctabixproxies_8VCFProxy_4__setattr__; -#endif -static int __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_5__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_5__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_5__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setattr__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8BedProxy_4__str__(((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { - int __pyx_v_idx; - CYTHON_UNUSED PyObject *__pyx_v_f = NULL; - int __pyx_r; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_4__str__(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self) { + int __pyx_v_save_fields; + PyObject *__pyx_v_retval = NULL; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; - uint32_t __pyx_t_2; + PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *(*__pyx_t_7)(PyObject *); - int __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - __Pyx_RefNannySetupContext("__setattr__", 0); - __Pyx_INCREF(__pyx_v_value); - - /* "pysam/libctabixproxies.pyx":820 - * def __setattr__(self, key, value): - * '''set attribute.''' - * if key == "pos": # <<<<<<<<<<<<<< - * self.pos = value - * value += 1 - */ - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_n_s_pos, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 820, __pyx_L1_error) - if (__pyx_t_1) { + __Pyx_RefNannySetupContext("__str__", 0); - /* "pysam/libctabixproxies.pyx":821 - * '''set attribute.''' - * if key == "pos": - * self.pos = value # <<<<<<<<<<<<<< - * value += 1 + /* "pysam/libctabixproxies.pyx":755 + * def __str__(self): * + * cdef int save_fields = self.nfields # <<<<<<<<<<<<<< + * # ensure fields to use correct format + * self.nfields = self.bedfields */ - __pyx_t_2 = __Pyx_PyInt_As_uint32_t(__pyx_v_value); if (unlikely((__pyx_t_2 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 821, __pyx_L1_error) - __pyx_v_self->pos = __pyx_t_2; + __pyx_t_1 = __pyx_v_self->__pyx_base.__pyx_base.nfields; + __pyx_v_save_fields = __pyx_t_1; - /* "pysam/libctabixproxies.pyx":822 - * if key == "pos": - * self.pos = value - * value += 1 # <<<<<<<<<<<<<< - * - * cdef int idx + /* "pysam/libctabixproxies.pyx":757 + * cdef int save_fields = self.nfields + * # ensure fields to use correct format + * self.nfields = self.bedfields # <<<<<<<<<<<<<< + * retval = TupleProxy.__str__(self) + * self.nfields = save_fields */ - __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_value, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 822, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_1 = __pyx_v_self->bedfields; + __pyx_v_self->__pyx_base.__pyx_base.nfields = __pyx_t_1; - /* "pysam/libctabixproxies.pyx":820 - * def __setattr__(self, key, value): - * '''set attribute.''' - * if key == "pos": # <<<<<<<<<<<<<< - * self.pos = value - * value += 1 + /* "pysam/libctabixproxies.pyx":758 + * # ensure fields to use correct format + * self.nfields = self.bedfields + * retval = TupleProxy.__str__(self) # <<<<<<<<<<<<<< + * self.nfields = save_fields + * return retval */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_n_s_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + if (!__pyx_t_4) { + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + } else { + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_self)}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_self)}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_5, 0+1, ((PyObject *)__pyx_v_self)); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 758, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_retval = __pyx_t_2; + __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":825 - * - * cdef int idx - * idx, f = self.map_key2field[key] # <<<<<<<<<<<<<< - * TupleProxy._setindex(self, idx, str(value)) + /* "pysam/libctabixproxies.pyx":759 + * self.nfields = self.bedfields + * retval = TupleProxy.__str__(self) + * self.nfields = save_fields # <<<<<<<<<<<<<< + * return retval * */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_map_key2field); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_3, __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 825, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_v_self->__pyx_base.__pyx_base.nfields = __pyx_v_save_fields; + + /* "pysam/libctabixproxies.pyx":760 + * retval = TupleProxy.__str__(self) + * self.nfields = save_fields + * return retval # <<<<<<<<<<<<<< + * + * def __setattr__(self, key, value): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_retval); + __pyx_r = __pyx_v_retval; + goto __pyx_L0; + + /* "pysam/libctabixproxies.pyx":753 + * # def __get__( self ): return self.end + * + * def __str__(self): # <<<<<<<<<<<<<< + * + * cdef int save_fields = self.nfields + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_retval); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "pysam/libctabixproxies.pyx":762 + * return retval + * + * def __setattr__(self, key, value): # <<<<<<<<<<<<<< + * '''set attribute.''' + * if key == "start": + */ + +/* Python wrapper */ +static int __pyx_pw_5pysam_16libctabixproxies_8BedProxy_7__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8BedProxy_6__setattr__[] = "set attribute."; +#if CYTHON_COMPILING_IN_CPYTHON +struct wrapperbase __pyx_wrapperbase_5pysam_16libctabixproxies_8BedProxy_6__setattr__; +#endif +static int __pyx_pw_5pysam_16libctabixproxies_8BedProxy_7__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setattr__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8BedProxy_6__setattr__(((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_v_self), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5pysam_16libctabixproxies_8BedProxy_6__setattr__(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { + int __pyx_v_idx; + CYTHON_UNUSED PyObject *__pyx_v_f = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + uint32_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *(*__pyx_t_7)(PyObject *); + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + __Pyx_RefNannySetupContext("__setattr__", 0); + + /* "pysam/libctabixproxies.pyx":764 + * def __setattr__(self, key, value): + * '''set attribute.''' + * if key == "start": # <<<<<<<<<<<<<< + * self.start = value + * elif key == "end": + */ + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_n_s_start, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 764, __pyx_L1_error) + if (__pyx_t_1) { + + /* "pysam/libctabixproxies.pyx":765 + * '''set attribute.''' + * if key == "start": + * self.start = value # <<<<<<<<<<<<<< + * elif key == "end": + * self.end = value + */ + __pyx_t_2 = __Pyx_PyInt_As_uint32_t(__pyx_v_value); if (unlikely((__pyx_t_2 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 765, __pyx_L1_error) + __pyx_v_self->start = __pyx_t_2; + + /* "pysam/libctabixproxies.pyx":764 + * def __setattr__(self, key, value): + * '''set attribute.''' + * if key == "start": # <<<<<<<<<<<<<< + * self.start = value + * elif key == "end": + */ + goto __pyx_L3; + } + + /* "pysam/libctabixproxies.pyx":766 + * if key == "start": + * self.start = value + * elif key == "end": # <<<<<<<<<<<<<< + * self.end = value + * + */ + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_n_s_end, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 766, __pyx_L1_error) + if (__pyx_t_1) { + + /* "pysam/libctabixproxies.pyx":767 + * self.start = value + * elif key == "end": + * self.end = value # <<<<<<<<<<<<<< + * + * cdef int idx + */ + __pyx_t_2 = __Pyx_PyInt_As_uint32_t(__pyx_v_value); if (unlikely((__pyx_t_2 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 767, __pyx_L1_error) + __pyx_v_self->end = __pyx_t_2; + + /* "pysam/libctabixproxies.pyx":766 + * if key == "start": + * self.start = value + * elif key == "end": # <<<<<<<<<<<<<< + * self.end = value + * + */ + } + __pyx_L3:; + + /* "pysam/libctabixproxies.pyx":770 + * + * cdef int idx + * idx, f = self.map_key2field[key] # <<<<<<<<<<<<<< + * TupleProxy._setindex(self, idx, str(value)) + * + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_map_key2field); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 770, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_3, __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 770, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { PyObject* sequence = __pyx_t_4; @@ -14065,7 +14792,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(struct __py if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 825, __pyx_L1_error) + __PYX_ERR(0, 770, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { @@ -14078,15 +14805,15 @@ static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(struct __py __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_5); #else - __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 825, __pyx_L1_error) + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 770, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 825, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 770, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { Py_ssize_t index = -1; - __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 825, __pyx_L1_error) + __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 770, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext; @@ -14094,7 +14821,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(struct __py __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_5 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) __PYX_ERR(0, 825, __pyx_L1_error) + if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) __PYX_ERR(0, 770, __pyx_L1_error) __pyx_t_7 = NULL; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L5_unpacking_done; @@ -14102,26 +14829,27 @@ static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(struct __py __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_7 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 825, __pyx_L1_error) + __PYX_ERR(0, 770, __pyx_L1_error) __pyx_L5_unpacking_done:; } - __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 825, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 770, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_idx = __pyx_t_8; __pyx_v_f = __pyx_t_5; __pyx_t_5 = 0; - /* "pysam/libctabixproxies.pyx":826 + /* "pysam/libctabixproxies.pyx":771 * cdef int idx * idx, f = self.map_key2field[key] * TupleProxy._setindex(self, idx, str(value)) # <<<<<<<<<<<<<< * + * */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_n_s_setindex); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 826, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_n_s_setindex); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 771, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 826, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 771, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_value); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 826, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_value); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 771, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_9 = NULL; __pyx_t_8 = 0; @@ -14138,7 +14866,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(struct __py #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[4] = {__pyx_t_9, ((PyObject *)__pyx_v_self), __pyx_t_3, __pyx_t_6}; - __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 826, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 771, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -14148,7 +14876,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(struct __py #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[4] = {__pyx_t_9, ((PyObject *)__pyx_v_self), __pyx_t_3, __pyx_t_6}; - __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 826, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 771, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -14156,7 +14884,7 @@ static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(struct __py } else #endif { - __pyx_t_10 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 826, __pyx_L1_error) + __pyx_t_10 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 771, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); if (__pyx_t_9) { __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; @@ -14170,19 +14898,19 @@ static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(struct __py PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_8, __pyx_t_6); __pyx_t_3 = 0; __pyx_t_6 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 826, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 771, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":818 - * return self.pos + /* "pysam/libctabixproxies.pyx":762 + * return retval * * def __setattr__(self, key, value): # <<<<<<<<<<<<<< * '''set attribute.''' - * if key == "pos": + * if key == "start": */ /* function exit code */ @@ -14195,11 +14923,10 @@ static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(struct __py __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("pysam.libctabixproxies.VCFProxy.__setattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.__setattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_f); - __Pyx_XDECREF(__pyx_v_value); __Pyx_RefNannyFinishContext(); return __pyx_r; } @@ -14211,19 +14938,19 @@ static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(struct __py */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_9__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_6__reduce_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_self)); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8BedProxy_8__reduce_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -14235,7 +14962,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_6__reduce_cython__ * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__45, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -14250,7 +14977,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_6__reduce_cython__ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.VCFProxy.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); @@ -14265,19 +14992,19 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_6__reduce_cython__ */ /* Python wrapper */ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8BedProxy_11__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_8__setstate_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8BedProxy_10__setstate_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8BedProxy_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -14288,7 +15015,7 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_8__setstate_cython * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__46, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -14304,1026 +15031,2351 @@ static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_8__setstate_cython /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("pysam.libctabixproxies.VCFProxy.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pysam.libctabixproxies.BedProxy.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "array.pxd":93 - * __data_union data +/* "pysam/libctabixproxies.pyx":791 + * 'format' : (8, str) } * - * def __getbuffer__(self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< - * # This implementation of getbuffer is geared towards Cython - * # requirements, and does not yet fulfill the PEP. + * def __cinit__(self): # <<<<<<<<<<<<<< + * # automatically calls TupleProxy.__cinit__ + * # start indexed access at genotypes */ /* Python wrapper */ -static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ -static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { +static int __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0); - __pyx_r = __pyx_pf_7cpython_5array_5array___getbuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8VCFProxy___cinit__(((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags) { - PyObject *__pyx_v_item_count = NULL; +static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy___cinit__(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - char *__pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - Py_ssize_t __pyx_t_5; - int __pyx_t_6; - if (__pyx_v_info == NULL) { - PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete"); - return -1; - } - __Pyx_RefNannySetupContext("__getbuffer__", 0); - __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(__pyx_v_info->obj); + __Pyx_RefNannySetupContext("__cinit__", 0); - /* "array.pxd":98 - * # In particular strided access is always provided regardless - * # of flags - * item_count = Py_SIZE(self) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":794 + * # automatically calls TupleProxy.__cinit__ + * # start indexed access at genotypes + * self.offset = 9 # <<<<<<<<<<<<<< * - * info.suboffsets = NULL + * cdef update(self, char * buffer, size_t nbytes): */ - __pyx_t_1 = PyInt_FromSsize_t(Py_SIZE(((PyObject *)__pyx_v_self))); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 98, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_item_count = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_v_self->__pyx_base.__pyx_base.offset = 9; - /* "array.pxd":100 - * item_count = Py_SIZE(self) + /* "pysam/libctabixproxies.pyx":791 + * 'format' : (8, str) } * - * info.suboffsets = NULL # <<<<<<<<<<<<<< - * info.buf = self.data.as_chars - * info.readonly = 0 + * def __cinit__(self): # <<<<<<<<<<<<<< + * # automatically calls TupleProxy.__cinit__ + * # start indexed access at genotypes */ - __pyx_v_info->suboffsets = NULL; - /* "array.pxd":101 - * - * info.suboffsets = NULL - * info.buf = self.data.as_chars # <<<<<<<<<<<<<< - * info.readonly = 0 - * info.ndim = 1 - */ - __pyx_t_2 = __pyx_v_self->data.as_chars; - __pyx_v_info->buf = __pyx_t_2; + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "array.pxd":102 - * info.suboffsets = NULL - * info.buf = self.data.as_chars - * info.readonly = 0 # <<<<<<<<<<<<<< - * info.ndim = 1 - * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) +/* "pysam/libctabixproxies.pyx":796 + * self.offset = 9 + * + * cdef update(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< + * '''update internal data. + * */ - __pyx_v_info->readonly = 0; - /* "array.pxd":103 - * info.buf = self.data.as_chars - * info.readonly = 0 - * info.ndim = 1 # <<<<<<<<<<<<<< - * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) - * info.len = info.itemsize * item_count - */ - __pyx_v_info->ndim = 1; - - /* "array.pxd":104 - * info.readonly = 0 - * info.ndim = 1 - * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) # <<<<<<<<<<<<<< - * info.len = info.itemsize * item_count - * - */ - __pyx_t_3 = __pyx_v_self->ob_descr->itemsize; - __pyx_v_info->itemsize = __pyx_t_3; +static PyObject *__pyx_f_5pysam_16libctabixproxies_8VCFProxy_update(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self, char *__pyx_v_buffer, size_t __pyx_v_nbytes) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("update", 0); - /* "array.pxd":105 - * info.ndim = 1 - * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) - * info.len = info.itemsize * item_count # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":801 + * nbytes does not include the terminal '\0'. + * ''' + * TupleProxy.update(self, buffer, nbytes) # <<<<<<<<<<<<<< * - * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) + * self.contig = self.fields[0] */ - __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_info->itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 105, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_16libctabixproxies_10TupleProxy_update(((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)__pyx_v_self), __pyx_v_buffer, __pyx_v_nbytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 801, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyNumber_Multiply(__pyx_t_1, __pyx_v_item_count); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 105, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 105, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_info->len = __pyx_t_5; - - /* "array.pxd":107 - * info.len = info.itemsize * item_count - * - * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) # <<<<<<<<<<<<<< - * if not info.shape: - * raise MemoryError() - */ - __pyx_v_info->shape = ((Py_ssize_t *)PyObject_Malloc(((sizeof(Py_ssize_t)) + 2))); - - /* "array.pxd":108 - * - * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) - * if not info.shape: # <<<<<<<<<<<<<< - * raise MemoryError() - * info.shape[0] = item_count # constant regardless of resizing - */ - __pyx_t_6 = ((!(__pyx_v_info->shape != 0)) != 0); - if (unlikely(__pyx_t_6)) { - - /* "array.pxd":109 - * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) - * if not info.shape: - * raise MemoryError() # <<<<<<<<<<<<<< - * info.shape[0] = item_count # constant regardless of resizing - * info.strides = &info.itemsize - */ - PyErr_NoMemory(); __PYX_ERR(2, 109, __pyx_L1_error) - - /* "array.pxd":108 - * - * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) - * if not info.shape: # <<<<<<<<<<<<<< - * raise MemoryError() - * info.shape[0] = item_count # constant regardless of resizing - */ - } - - /* "array.pxd":110 - * if not info.shape: - * raise MemoryError() - * info.shape[0] = item_count # constant regardless of resizing # <<<<<<<<<<<<<< - * info.strides = &info.itemsize - * - */ - __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_item_count); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 110, __pyx_L1_error) - (__pyx_v_info->shape[0]) = __pyx_t_5; - - /* "array.pxd":111 - * raise MemoryError() - * info.shape[0] = item_count # constant regardless of resizing - * info.strides = &info.itemsize # <<<<<<<<<<<<<< - * - * info.format = (info.shape + 1) - */ - __pyx_v_info->strides = (&__pyx_v_info->itemsize); - - /* "array.pxd":113 - * info.strides = &info.itemsize - * - * info.format = (info.shape + 1) # <<<<<<<<<<<<<< - * info.format[0] = self.ob_descr.typecode - * info.format[1] = 0 - */ - __pyx_v_info->format = ((char *)(__pyx_v_info->shape + 1)); - /* "array.pxd":114 + /* "pysam/libctabixproxies.pyx":803 + * TupleProxy.update(self, buffer, nbytes) * - * info.format = (info.shape + 1) - * info.format[0] = self.ob_descr.typecode # <<<<<<<<<<<<<< - * info.format[1] = 0 - * info.obj = self + * self.contig = self.fields[0] # <<<<<<<<<<<<<< + * # vcf counts from 1 - correct here + * self.pos = atoi(self.fields[1]) - 1 */ - __pyx_t_3 = __pyx_v_self->ob_descr->typecode; - (__pyx_v_info->format[0]) = __pyx_t_3; + __pyx_v_self->contig = (__pyx_v_self->__pyx_base.__pyx_base.fields[0]); - /* "array.pxd":115 - * info.format = (info.shape + 1) - * info.format[0] = self.ob_descr.typecode - * info.format[1] = 0 # <<<<<<<<<<<<<< - * info.obj = self + /* "pysam/libctabixproxies.pyx":805 + * self.contig = self.fields[0] + * # vcf counts from 1 - correct here + * self.pos = atoi(self.fields[1]) - 1 # <<<<<<<<<<<<<< * + * def __len__(self): */ - (__pyx_v_info->format[1]) = 0; + __pyx_v_self->pos = (atoi((__pyx_v_self->__pyx_base.__pyx_base.fields[1])) - 1); - /* "array.pxd":116 - * info.format[0] = self.ob_descr.typecode - * info.format[1] = 0 - * info.obj = self # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":796 + * self.offset = 9 * - * def __releasebuffer__(self, Py_buffer* info): - */ - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); - __pyx_v_info->obj = ((PyObject *)__pyx_v_self); - - /* "array.pxd":93 - * __data_union data + * cdef update(self, char * buffer, size_t nbytes): # <<<<<<<<<<<<<< + * '''update internal data. * - * def __getbuffer__(self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< - * # This implementation of getbuffer is geared towards Cython - * # requirements, and does not yet fulfill the PEP. */ /* function exit code */ - __pyx_r = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("cpython.array.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - if (__pyx_v_info->obj != NULL) { - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; - } - goto __pyx_L2; + __Pyx_AddTraceback("pysam.libctabixproxies.VCFProxy.update", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - if (__pyx_v_info->obj == Py_None) { - __Pyx_GOTREF(__pyx_v_info->obj); - __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; - } - __pyx_L2:; - __Pyx_XDECREF(__pyx_v_item_count); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "array.pxd":118 - * info.obj = self - * - * def __releasebuffer__(self, Py_buffer* info): # <<<<<<<<<<<<<< - * PyObject_Free(info.shape) +/* "pysam/libctabixproxies.pyx":807 + * self.pos = atoi(self.fields[1]) - 1 * + * def __len__(self): # <<<<<<<<<<<<<< + * '''return number of genotype fields.''' + * return max(0, self.nfields - 9) */ /* Python wrapper */ -static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/ -static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) { +static Py_ssize_t __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3__len__(PyObject *__pyx_v_self); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8VCFProxy_2__len__[] = "return number of genotype fields."; +#if CYTHON_COMPILING_IN_CPYTHON +struct wrapperbase __pyx_wrapperbase_5pysam_16libctabixproxies_8VCFProxy_2__len__; +#endif +static Py_ssize_t __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0); - __pyx_pf_7cpython_5array_5array_2__releasebuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info)); + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_2__len__(((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info) { +static Py_ssize_t __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_2__len__(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__releasebuffer__", 0); + long __pyx_t_1; + long __pyx_t_2; + long __pyx_t_3; + __Pyx_RefNannySetupContext("__len__", 0); - /* "array.pxd":119 - * - * def __releasebuffer__(self, Py_buffer* info): - * PyObject_Free(info.shape) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":809 + * def __len__(self): + * '''return number of genotype fields.''' + * return max(0, self.nfields - 9) # <<<<<<<<<<<<<< * - * array newarrayobject(PyTypeObject* type, Py_ssize_t size, arraydescr *descr) + * property pos: */ - PyObject_Free(__pyx_v_info->shape); + __pyx_t_1 = (__pyx_v_self->__pyx_base.__pyx_base.nfields - 9); + __pyx_t_2 = 0; + if (((__pyx_t_1 > __pyx_t_2) != 0)) { + __pyx_t_3 = __pyx_t_1; + } else { + __pyx_t_3 = __pyx_t_2; + } + __pyx_r = __pyx_t_3; + goto __pyx_L0; - /* "array.pxd":118 - * info.obj = self - * - * def __releasebuffer__(self, Py_buffer* info): # <<<<<<<<<<<<<< - * PyObject_Free(info.shape) + /* "pysam/libctabixproxies.pyx":807 + * self.pos = atoi(self.fields[1]) - 1 * + * def __len__(self): # <<<<<<<<<<<<<< + * '''return number of genotype fields.''' + * return max(0, self.nfields - 9) */ /* function exit code */ + __pyx_L0:; __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "array.pxd":130 - * +/* "pysam/libctabixproxies.pyx":813 + * property pos: + * '''feature end (in 0-based open/closed coordinates).''' + * def __get__(self): # <<<<<<<<<<<<<< + * return self.pos * - * cdef inline array clone(array template, Py_ssize_t length, bint zero): # <<<<<<<<<<<<<< - * """ fast creation of a new array, given a template array. - * type will be same as template. */ -static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_clone(arrayobject *__pyx_v_template, Py_ssize_t __pyx_v_length, int __pyx_v_zero) { - arrayobject *__pyx_v_op = NULL; - arrayobject *__pyx_r = NULL; +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3pos_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("clone", 0); - - /* "array.pxd":134 - * type will be same as template. - * if zero is true, new array will be initialized with zeroes.""" - * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) # <<<<<<<<<<<<<< - * if zero and op is not None: - * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) - */ - __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_template)), __pyx_v_length, __pyx_v_template->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 134, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_op = ((arrayobject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "array.pxd":135 - * if zero is true, new array will be initialized with zeroes.""" - * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) - * if zero and op is not None: # <<<<<<<<<<<<<< - * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) - * return op - */ - __pyx_t_3 = (__pyx_v_zero != 0); - if (__pyx_t_3) { - } else { - __pyx_t_2 = __pyx_t_3; - goto __pyx_L4_bool_binop_done; - } - __pyx_t_3 = (((PyObject *)__pyx_v_op) != Py_None); - __pyx_t_4 = (__pyx_t_3 != 0); - __pyx_t_2 = __pyx_t_4; - __pyx_L4_bool_binop_done:; - if (__pyx_t_2) { - - /* "array.pxd":136 - * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) - * if zero and op is not None: - * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) # <<<<<<<<<<<<<< - * return op - * - */ - (void)(memset(__pyx_v_op->data.as_chars, 0, (__pyx_v_length * __pyx_v_op->ob_descr->itemsize))); - - /* "array.pxd":135 - * if zero is true, new array will be initialized with zeroes.""" - * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) - * if zero and op is not None: # <<<<<<<<<<<<<< - * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) - * return op - */ - } - - /* "array.pxd":137 - * if zero and op is not None: - * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) - * return op # <<<<<<<<<<<<<< - * - * cdef inline array copy(array self): - */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_op)); - __pyx_r = __pyx_v_op; - goto __pyx_L0; - - /* "array.pxd":130 - * - * - * cdef inline array clone(array template, Py_ssize_t length, bint zero): # <<<<<<<<<<<<<< - * """ fast creation of a new array, given a template array. - * type will be same as template. - */ + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_3pos___get__(((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_self)); /* function exit code */ - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("cpython.array.clone", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_op); - __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "array.pxd":139 - * return op - * - * cdef inline array copy(array self): # <<<<<<<<<<<<<< - * """ make a copy of an array. """ - * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) - */ - -static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_copy(arrayobject *__pyx_v_self) { - arrayobject *__pyx_v_op = NULL; - arrayobject *__pyx_r = NULL; +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_3pos___get__(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - __Pyx_RefNannySetupContext("copy", 0); + __Pyx_RefNannySetupContext("__get__", 0); - /* "array.pxd":141 - * cdef inline array copy(array self): - * """ make a copy of an array. """ - * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) # <<<<<<<<<<<<<< - * memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize) - * return op + /* "pysam/libctabixproxies.pyx":814 + * '''feature end (in 0-based open/closed coordinates).''' + * def __get__(self): + * return self.pos # <<<<<<<<<<<<<< + * + * def __setattr__(self, key, value): */ - __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_self)), Py_SIZE(((PyObject *)__pyx_v_self)), __pyx_v_self->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 141, __pyx_L1_error) + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 814, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_v_op = ((arrayobject *)__pyx_t_1); + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; - - /* "array.pxd":142 - * """ make a copy of an array. """ - * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) - * memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize) # <<<<<<<<<<<<<< - * return op - * - */ - (void)(memcpy(__pyx_v_op->data.as_chars, __pyx_v_self->data.as_chars, (Py_SIZE(((PyObject *)__pyx_v_op)) * __pyx_v_op->ob_descr->itemsize))); - - /* "array.pxd":143 - * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) - * memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize) - * return op # <<<<<<<<<<<<<< - * - * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1: - */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_op)); - __pyx_r = __pyx_v_op; goto __pyx_L0; - /* "array.pxd":139 - * return op + /* "pysam/libctabixproxies.pyx":813 + * property pos: + * '''feature end (in 0-based open/closed coordinates).''' + * def __get__(self): # <<<<<<<<<<<<<< + * return self.pos * - * cdef inline array copy(array self): # <<<<<<<<<<<<<< - * """ make a copy of an array. """ - * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("cpython.array.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_AddTraceback("pysam.libctabixproxies.VCFProxy.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_op); - __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "array.pxd":145 - * return op +/* "pysam/libctabixproxies.pyx":816 + * return self.pos * - * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1: # <<<<<<<<<<<<<< - * """ efficient appending of new stuff of same type - * (e.g. of same array type) + * def __setattr__(self, key, value): # <<<<<<<<<<<<<< + * '''set attribute.''' + * if key == "pos": */ -static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *__pyx_v_self, char *__pyx_v_stuff, Py_ssize_t __pyx_v_n) { - Py_ssize_t __pyx_v_itemsize; - Py_ssize_t __pyx_v_origsize; +/* Python wrapper */ +static int __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_5__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/ +static char __pyx_doc_5pysam_16libctabixproxies_8VCFProxy_4__setattr__[] = "set attribute."; +#if CYTHON_COMPILING_IN_CPYTHON +struct wrapperbase __pyx_wrapperbase_5pysam_16libctabixproxies_8VCFProxy_4__setattr__; +#endif +static int __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_5__setattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("extend_buffer", 0); + __Pyx_RefNannySetupContext("__setattr__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_self), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_value)); - /* "array.pxd":149 - * (e.g. of same array type) - * n: number of elements (not number of bytes!) """ - * cdef Py_ssize_t itemsize = self.ob_descr.itemsize # <<<<<<<<<<<<<< - * cdef Py_ssize_t origsize = Py_SIZE(self) - * resize_smart(self, origsize + n) - */ - __pyx_t_1 = __pyx_v_self->ob_descr->itemsize; - __pyx_v_itemsize = __pyx_t_1; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "array.pxd":150 - * n: number of elements (not number of bytes!) """ - * cdef Py_ssize_t itemsize = self.ob_descr.itemsize - * cdef Py_ssize_t origsize = Py_SIZE(self) # <<<<<<<<<<<<<< - * resize_smart(self, origsize + n) - * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) - */ - __pyx_v_origsize = Py_SIZE(((PyObject *)__pyx_v_self)); +static int __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_4__setattr__(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { + int __pyx_v_idx; + CYTHON_UNUSED PyObject *__pyx_v_f = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + uint32_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *(*__pyx_t_7)(PyObject *); + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + __Pyx_RefNannySetupContext("__setattr__", 0); + __Pyx_INCREF(__pyx_v_value); - /* "array.pxd":151 - * cdef Py_ssize_t itemsize = self.ob_descr.itemsize - * cdef Py_ssize_t origsize = Py_SIZE(self) - * resize_smart(self, origsize + n) # <<<<<<<<<<<<<< - * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) - * return 0 + /* "pysam/libctabixproxies.pyx":818 + * def __setattr__(self, key, value): + * '''set attribute.''' + * if key == "pos": # <<<<<<<<<<<<<< + * self.pos = value + * value += 1 */ - __pyx_t_1 = resize_smart(__pyx_v_self, (__pyx_v_origsize + __pyx_v_n)); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(2, 151, __pyx_L1_error) + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_key, __pyx_n_s_pos, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 818, __pyx_L1_error) + if (__pyx_t_1) { - /* "array.pxd":152 - * cdef Py_ssize_t origsize = Py_SIZE(self) - * resize_smart(self, origsize + n) - * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) # <<<<<<<<<<<<<< - * return 0 + /* "pysam/libctabixproxies.pyx":819 + * '''set attribute.''' + * if key == "pos": + * self.pos = value # <<<<<<<<<<<<<< + * value += 1 * */ - (void)(memcpy((__pyx_v_self->data.as_chars + (__pyx_v_origsize * __pyx_v_itemsize)), __pyx_v_stuff, (__pyx_v_n * __pyx_v_itemsize))); + __pyx_t_2 = __Pyx_PyInt_As_uint32_t(__pyx_v_value); if (unlikely((__pyx_t_2 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 819, __pyx_L1_error) + __pyx_v_self->pos = __pyx_t_2; - /* "array.pxd":153 - * resize_smart(self, origsize + n) - * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) - * return 0 # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":820 + * if key == "pos": + * self.pos = value + * value += 1 # <<<<<<<<<<<<<< * - * cdef inline int extend(array self, array other) except -1: + * cdef int idx */ - __pyx_r = 0; - goto __pyx_L0; + __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_value, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 820, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_3); + __pyx_t_3 = 0; - /* "array.pxd":145 - * return op - * - * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1: # <<<<<<<<<<<<<< - * """ efficient appending of new stuff of same type - * (e.g. of same array type) + /* "pysam/libctabixproxies.pyx":818 + * def __setattr__(self, key, value): + * '''set attribute.''' + * if key == "pos": # <<<<<<<<<<<<<< + * self.pos = value + * value += 1 */ + } - /* function exit code */ - __pyx_L1_error:; - __Pyx_AddTraceback("cpython.array.extend_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "array.pxd":155 - * return 0 + /* "pysam/libctabixproxies.pyx":823 * - * cdef inline int extend(array self, array other) except -1: # <<<<<<<<<<<<<< - * """ extend array with data from another array; types must match. """ - * if self.ob_descr.typecode != other.ob_descr.typecode: - */ - -static CYTHON_INLINE int __pyx_f_7cpython_5array_extend(arrayobject *__pyx_v_self, arrayobject *__pyx_v_other) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - __Pyx_RefNannySetupContext("extend", 0); - - /* "array.pxd":157 - * cdef inline int extend(array self, array other) except -1: - * """ extend array with data from another array; types must match. """ - * if self.ob_descr.typecode != other.ob_descr.typecode: # <<<<<<<<<<<<<< - * PyErr_BadArgument() - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) - */ - __pyx_t_1 = ((__pyx_v_self->ob_descr->typecode != __pyx_v_other->ob_descr->typecode) != 0); - if (__pyx_t_1) { - - /* "array.pxd":158 - * """ extend array with data from another array; types must match. """ - * if self.ob_descr.typecode != other.ob_descr.typecode: - * PyErr_BadArgument() # <<<<<<<<<<<<<< - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) + * cdef int idx + * idx, f = self.map_key2field[key] # <<<<<<<<<<<<<< + * TupleProxy._setindex(self, idx, str(value)) * */ - __pyx_t_2 = PyErr_BadArgument(); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(2, 158, __pyx_L1_error) - - /* "array.pxd":157 - * cdef inline int extend(array self, array other) except -1: - * """ extend array with data from another array; types must match. """ - * if self.ob_descr.typecode != other.ob_descr.typecode: # <<<<<<<<<<<<<< - * PyErr_BadArgument() - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) - */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_map_key2field); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 823, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_3, __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 823, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { + PyObject* sequence = __pyx_t_4; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 823, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_5 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_5); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 823, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 823, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 823, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_5 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) __PYX_ERR(0, 823, __pyx_L1_error) + __pyx_t_7 = NULL; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L5_unpacking_done; + __pyx_L4_unpacking_failed:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_7 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 823, __pyx_L1_error) + __pyx_L5_unpacking_done:; } + __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 823, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_idx = __pyx_t_8; + __pyx_v_f = __pyx_t_5; + __pyx_t_5 = 0; - /* "array.pxd":159 - * if self.ob_descr.typecode != other.ob_descr.typecode: - * PyErr_BadArgument() - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":824 + * cdef int idx + * idx, f = self.map_key2field[key] + * TupleProxy._setindex(self, idx, str(value)) # <<<<<<<<<<<<<< + * * - * cdef inline void zero(array self): */ - __pyx_t_2 = __pyx_f_7cpython_5array_extend_buffer(__pyx_v_self, __pyx_v_other->data.as_chars, Py_SIZE(((PyObject *)__pyx_v_other))); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(2, 159, __pyx_L1_error) - __pyx_r = __pyx_t_2; - goto __pyx_L0; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_TupleProxy), __pyx_n_s_setindex); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 824, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 824, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_value); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 824, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_9 = NULL; + __pyx_t_8 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[4] = {__pyx_t_9, ((PyObject *)__pyx_v_self), __pyx_t_3, __pyx_t_6}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 824, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[4] = {__pyx_t_9, ((PyObject *)__pyx_v_self), __pyx_t_3, __pyx_t_6}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 824, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_10 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 824, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_8, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_8, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_8, __pyx_t_6); + __pyx_t_3 = 0; + __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 824, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "array.pxd":155 - * return 0 + /* "pysam/libctabixproxies.pyx":816 + * return self.pos * - * cdef inline int extend(array self, array other) except -1: # <<<<<<<<<<<<<< - * """ extend array with data from another array; types must match. """ - * if self.ob_descr.typecode != other.ob_descr.typecode: + * def __setattr__(self, key, value): # <<<<<<<<<<<<<< + * '''set attribute.''' + * if key == "pos": */ /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("cpython.array.extend", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("pysam.libctabixproxies.VCFProxy.__setattr__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_value); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "array.pxd":161 - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) - * - * cdef inline void zero(array self): # <<<<<<<<<<<<<< - * """ set all elements of array to zero. """ - * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): */ -static CYTHON_INLINE void __pyx_f_7cpython_5array_zero(arrayobject *__pyx_v_self) { +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("zero", 0); + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_6__reduce_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_self)); - /* "array.pxd":163 - * cdef inline void zero(array self): - * """ set all elements of array to zero. """ - * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) # <<<<<<<<<<<<<< + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - (void)(memset(__pyx_v_self->data.as_chars, 0, (Py_SIZE(((PyObject *)__pyx_v_self)) * __pyx_v_self->ob_descr->itemsize))); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 2, __pyx_L1_error) - /* "array.pxd":161 - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) - * - * cdef inline void zero(array self): # <<<<<<<<<<<<<< - * """ set all elements of array to zero. """ - * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): */ /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libctabixproxies.VCFProxy.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy __pyx_vtable_5pysam_16libctabixproxies_TupleProxy; -static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_TupleProxy(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *p; - PyObject *o; - if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { - o = (*t->tp_alloc)(t, 0); - } else { - o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); - } - if (unlikely(!o)) return 0; - p = ((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)o); - p->__pyx_vtab = __pyx_vtabptr_5pysam_16libctabixproxies_TupleProxy; - p->encoding = Py_None; Py_INCREF(Py_None); - if (unlikely(__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_1__cinit__(o, a, k) < 0)) goto bad; - return o; - bad: - Py_DECREF(o); o = 0; - return NULL; -} +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ -static void __pyx_tp_dealloc_5pysam_16libctabixproxies_TupleProxy(PyObject *o) { - struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *p = (struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)o; - #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { - if (PyObject_CallFinalizerFromDealloc(o)) return; - } - #endif - PyObject_GC_UnTrack(o); - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_3__dealloc__(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - Py_CLEAR(p->encoding); - (*Py_TYPE(o)->tp_free)(o); -} +/* Python wrapper */ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_5pysam_16libctabixproxies_8VCFProxy_8__setstate_cython__(((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); -static int __pyx_tp_traverse_5pysam_16libctabixproxies_TupleProxy(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *p = (struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)o; - if (p->encoding) { - e = (*v)(p->encoding, a); if (e) return e; - } - return 0; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static int __pyx_tp_clear_5pysam_16libctabixproxies_TupleProxy(PyObject *o) { - PyObject* tmp; - struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *p = (struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)o; - tmp = ((PyObject*)p->encoding); - p->encoding = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} -static PyObject *__pyx_sq_item_5pysam_16libctabixproxies_TupleProxy(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} +static PyObject *__pyx_pf_5pysam_16libctabixproxies_8VCFProxy_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); -static int __pyx_mp_ass_subscript_5pysam_16libctabixproxies_TupleProxy(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_21__setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name); - return -1; - } -} + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) -static PyMethodDef __pyx_methods_5pysam_16libctabixproxies_TupleProxy[] = { - {"__copy__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_5__copy__, METH_NOARGS, 0}, - {"compare", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_7compare, METH_O, __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_6compare}, - {"getMinFields", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_11getMinFields, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_10getMinFields}, - {"getMaxFields", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_13getMaxFields, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_12getMaxFields}, - {"_getindex", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_15_getindex, METH_O, __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_14_getindex}, - {"_setindex", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_19_setindex, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_18_setindex}, - {"__next__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, METH_NOARGS|METH_COEXIST, __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_26__next__}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_31__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_33__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ -static PySequenceMethods __pyx_tp_as_sequence_TupleProxy = { - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_23__len__, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - __pyx_sq_item_5pysam_16libctabixproxies_TupleProxy, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("pysam.libctabixproxies.VCFProxy.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} -static PyMappingMethods __pyx_tp_as_mapping_TupleProxy = { - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_23__len__, /*mp_length*/ - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_17__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5pysam_16libctabixproxies_TupleProxy, /*mp_ass_subscript*/ -}; +/* "array.pxd":93 + * __data_union data + * + * def __getbuffer__(self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< + * # This implementation of getbuffer is geared towards Cython + * # requirements, and does not yet fulfill the PEP. + */ -static PyTypeObject __pyx_type_5pysam_16libctabixproxies_TupleProxy = { - PyVarObject_HEAD_INIT(0, 0) - "pysam.libctabixproxies.TupleProxy", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_16libctabixproxies_TupleProxy, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #endif - #if PY_MAJOR_VERSION >= 3 - 0, /*tp_as_async*/ - #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - &__pyx_tp_as_sequence_TupleProxy, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_TupleProxy, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_29__str__, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "Proxy class for access to parsed row as a tuple.\n\n This class represents a table row for fast read-access.\n\n Access to individual fields is via the [] operator.\n \n Only read-only access is implemented.\n\n ", /*tp_doc*/ - __pyx_tp_traverse_5pysam_16libctabixproxies_TupleProxy, /*tp_traverse*/ - __pyx_tp_clear_5pysam_16libctabixproxies_TupleProxy, /*tp_clear*/ - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_9__richcmp__, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_25__iter__, /*tp_iter*/ - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, /*tp_iternext*/ - __pyx_methods_5pysam_16libctabixproxies_TupleProxy, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_16libctabixproxies_TupleProxy, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - 0, /*tp_version_tag*/ - #if PY_VERSION_HEX >= 0x030400a1 - 0, /*tp_finalize*/ - #endif -}; -static struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy __pyx_vtable_5pysam_16libctabixproxies_GTFProxy; +/* Python wrapper */ +static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/ +static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0); + __pyx_r = __pyx_pf_7cpython_5array_5array___getbuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags)); -static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_GTFProxy(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *p; - PyObject *o = __pyx_tp_new_5pysam_16libctabixproxies_TupleProxy(t, a, k); - if (unlikely(!o)) return 0; - p = ((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)o); - p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy*)__pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy; - if (unlikely(__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) goto bad; - return o; - bad: - Py_DECREF(o); o = 0; - return NULL; + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static void __pyx_tp_dealloc_5pysam_16libctabixproxies_GTFProxy(PyObject *o) { - #if CYTHON_USE_TP_FINALIZE - if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { - if (PyObject_CallFinalizerFromDealloc(o)) return; - } - #endif - PyObject_GC_UnTrack(o); - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3__dealloc__(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); +static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags) { + PyObject *__pyx_v_item_count = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + char *__pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + int __pyx_t_6; + if (__pyx_v_info == NULL) { + PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete"); + return -1; } - PyObject_GC_Track(o); - __pyx_tp_dealloc_5pysam_16libctabixproxies_TupleProxy(o); -} -static PyObject *__pyx_sq_item_5pysam_16libctabixproxies_GTFProxy(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} + __Pyx_RefNannySetupContext("__getbuffer__", 0); + __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(__pyx_v_info->obj); -static PyObject *__pyx_tp_getattro_5pysam_16libctabixproxies_GTFProxy(PyObject *o, PyObject *n) { - PyObject *v = __Pyx_PyObject_GenericGetAttr(o, n); - if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - v = __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_21__getattr__(o, n); - } - return v; -} + /* "array.pxd":98 + * # In particular strided access is always provided regardless + * # of flags + * item_count = Py_SIZE(self) # <<<<<<<<<<<<<< + * + * info.suboffsets = NULL + */ + __pyx_t_1 = PyInt_FromSsize_t(Py_SIZE(((PyObject *)__pyx_v_self))); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 98, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_item_count = __pyx_t_1; + __pyx_t_1 = 0; -static PyObject *__pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_contig(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6contig_1__get__(o); -} + /* "array.pxd":100 + * item_count = Py_SIZE(self) + * + * info.suboffsets = NULL # <<<<<<<<<<<<<< + * info.buf = self.data.as_chars + * info.readonly = 0 + */ + __pyx_v_info->suboffsets = NULL; -static int __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_contig(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6contig_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "array.pxd":101 + * + * info.suboffsets = NULL + * info.buf = self.data.as_chars # <<<<<<<<<<<<<< + * info.readonly = 0 + * info.ndim = 1 + */ + __pyx_t_2 = __pyx_v_self->data.as_chars; + __pyx_v_info->buf = __pyx_t_2; -static PyObject *__pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_source(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6source_1__get__(o); -} + /* "array.pxd":102 + * info.suboffsets = NULL + * info.buf = self.data.as_chars + * info.readonly = 0 # <<<<<<<<<<<<<< + * info.ndim = 1 + * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) + */ + __pyx_v_info->readonly = 0; -static int __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_source(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6source_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "array.pxd":103 + * info.buf = self.data.as_chars + * info.readonly = 0 + * info.ndim = 1 # <<<<<<<<<<<<<< + * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) + * info.len = info.itemsize * item_count + */ + __pyx_v_info->ndim = 1; -static PyObject *__pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_feature(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7feature_1__get__(o); -} + /* "array.pxd":104 + * info.readonly = 0 + * info.ndim = 1 + * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) # <<<<<<<<<<<<<< + * info.len = info.itemsize * item_count + * + */ + __pyx_t_3 = __pyx_v_self->ob_descr->itemsize; + __pyx_v_info->itemsize = __pyx_t_3; -static int __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_feature(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7feature_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "array.pxd":105 + * info.ndim = 1 + * info.itemsize = self.ob_descr.itemsize # e.g. sizeof(float) + * info.len = info.itemsize * item_count # <<<<<<<<<<<<<< + * + * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) + */ + __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_info->itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 105, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyNumber_Multiply(__pyx_t_1, __pyx_v_item_count); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 105, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 105, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_info->len = __pyx_t_5; -static PyObject *__pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_start(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5start_1__get__(o); -} + /* "array.pxd":107 + * info.len = info.itemsize * item_count + * + * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) # <<<<<<<<<<<<<< + * if not info.shape: + * raise MemoryError() + */ + __pyx_v_info->shape = ((Py_ssize_t *)PyObject_Malloc(((sizeof(Py_ssize_t)) + 2))); -static int __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_start(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5start_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "array.pxd":108 + * + * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) + * if not info.shape: # <<<<<<<<<<<<<< + * raise MemoryError() + * info.shape[0] = item_count # constant regardless of resizing + */ + __pyx_t_6 = ((!(__pyx_v_info->shape != 0)) != 0); + if (unlikely(__pyx_t_6)) { -static PyObject *__pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_end(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3end_1__get__(o); -} + /* "array.pxd":109 + * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) + * if not info.shape: + * raise MemoryError() # <<<<<<<<<<<<<< + * info.shape[0] = item_count # constant regardless of resizing + * info.strides = &info.itemsize + */ + PyErr_NoMemory(); __PYX_ERR(2, 109, __pyx_L1_error) -static int __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_end(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3end_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + /* "array.pxd":108 + * + * info.shape = PyObject_Malloc(sizeof(Py_ssize_t) + 2) + * if not info.shape: # <<<<<<<<<<<<<< + * raise MemoryError() + * info.shape[0] = item_count # constant regardless of resizing + */ } -} -static PyObject *__pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_score(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5score_1__get__(o); -} + /* "array.pxd":110 + * if not info.shape: + * raise MemoryError() + * info.shape[0] = item_count # constant regardless of resizing # <<<<<<<<<<<<<< + * info.strides = &info.itemsize + * + */ + __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_item_count); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 110, __pyx_L1_error) + (__pyx_v_info->shape[0]) = __pyx_t_5; -static int __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_score(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5score_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "array.pxd":111 + * raise MemoryError() + * info.shape[0] = item_count # constant regardless of resizing + * info.strides = &info.itemsize # <<<<<<<<<<<<<< + * + * info.format = (info.shape + 1) + */ + __pyx_v_info->strides = (&__pyx_v_info->itemsize); -static PyObject *__pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_strand(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6strand_1__get__(o); -} + /* "array.pxd":113 + * info.strides = &info.itemsize + * + * info.format = (info.shape + 1) # <<<<<<<<<<<<<< + * info.format[0] = self.ob_descr.typecode + * info.format[1] = 0 + */ + __pyx_v_info->format = ((char *)(__pyx_v_info->shape + 1)); -static int __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_strand(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_6strand_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "array.pxd":114 + * + * info.format = (info.shape + 1) + * info.format[0] = self.ob_descr.typecode # <<<<<<<<<<<<<< + * info.format[1] = 0 + * info.obj = self + */ + __pyx_t_3 = __pyx_v_self->ob_descr->typecode; + (__pyx_v_info->format[0]) = __pyx_t_3; -static PyObject *__pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_frame(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5frame_1__get__(o); -} + /* "array.pxd":115 + * info.format = (info.shape + 1) + * info.format[0] = self.ob_descr.typecode + * info.format[1] = 0 # <<<<<<<<<<<<<< + * info.obj = self + * + */ + (__pyx_v_info->format[1]) = 0; -static int __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_frame(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5frame_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} + /* "array.pxd":116 + * info.format[0] = self.ob_descr.typecode + * info.format[1] = 0 + * info.obj = self # <<<<<<<<<<<<<< + * + * def __releasebuffer__(self, Py_buffer* info): + */ + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); + __pyx_v_info->obj = ((PyObject *)__pyx_v_self); -static PyObject *__pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_attributes(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_10attributes_1__get__(o); -} + /* "array.pxd":93 + * __data_union data + * + * def __getbuffer__(self, Py_buffer* info, int flags): # <<<<<<<<<<<<<< + * # This implementation of getbuffer is geared towards Cython + * # requirements, and does not yet fulfill the PEP. + */ -static int __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_attributes(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_10attributes_3__set__(o, v); + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("cpython.array.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + if (__pyx_v_info->obj != NULL) { + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + goto __pyx_L2; + __pyx_L0:; + if (__pyx_v_info->obj == Py_None) { + __Pyx_GOTREF(__pyx_v_info->obj); + __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0; } + __pyx_L2:; + __Pyx_XDECREF(__pyx_v_item_count); + __Pyx_RefNannyFinishContext(); + return __pyx_r; } -static PyMethodDef __pyx_methods_5pysam_16libctabixproxies_GTFProxy[] = { - {"getMinFields", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5getMinFields, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_4getMinFields}, - {"getMaxFields", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7getMaxFields, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_6getMaxFields}, - {"asDict", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_9asDict, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_8asDict}, - {"fromDict", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_11fromDict, METH_O, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_10fromDict}, - {"invert", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_15invert, METH_O, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_14invert}, - {"keys", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_17keys, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_16keys}, - {"__getattr__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_21__getattr__, METH_O|METH_COEXIST, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_20__getattr__}, - {"setAttribute", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_23setAttribute, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_22setAttribute}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_29__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_31__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_5pysam_16libctabixproxies_GTFProxy[] = { - {(char *)"contig", __pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_contig, __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_contig, (char *)"contig of feature.", 0}, - {(char *)"source", __pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_source, __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_source, (char *)"feature source.", 0}, - {(char *)"feature", __pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_feature, __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_feature, (char *)"feature name.", 0}, - {(char *)"start", __pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_start, __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_start, (char *)"feature start (in 0-based open/closed coordinates).", 0}, - {(char *)"end", __pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_end, __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_end, (char *)"feature end (in 0-based open/closed coordinates).", 0}, - {(char *)"score", __pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_score, __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_score, (char *)"feature score.", 0}, - {(char *)"strand", __pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_strand, __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_strand, (char *)"feature strand.", 0}, - {(char *)"frame", __pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_frame, __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_frame, (char *)"feature frame.", 0}, - {(char *)"attributes", __pyx_getprop_5pysam_16libctabixproxies_8GTFProxy_attributes, __pyx_setprop_5pysam_16libctabixproxies_8GTFProxy_attributes, (char *)"feature attributes (as a string).", 0}, - {0, 0, 0, 0, 0} -}; +/* "array.pxd":118 + * info.obj = self + * + * def __releasebuffer__(self, Py_buffer* info): # <<<<<<<<<<<<<< + * PyObject_Free(info.shape) + * + */ + +/* Python wrapper */ +static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/ +static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0); + __pyx_pf_7cpython_5array_5array_2__releasebuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__releasebuffer__", 0); + + /* "array.pxd":119 + * + * def __releasebuffer__(self, Py_buffer* info): + * PyObject_Free(info.shape) # <<<<<<<<<<<<<< + * + * array newarrayobject(PyTypeObject* type, Py_ssize_t size, arraydescr *descr) + */ + PyObject_Free(__pyx_v_info->shape); + + /* "array.pxd":118 + * info.obj = self + * + * def __releasebuffer__(self, Py_buffer* info): # <<<<<<<<<<<<<< + * PyObject_Free(info.shape) + * + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +/* "array.pxd":130 + * + * + * cdef inline array clone(array template, Py_ssize_t length, bint zero): # <<<<<<<<<<<<<< + * """ fast creation of a new array, given a template array. + * type will be same as template. + */ + +static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_clone(arrayobject *__pyx_v_template, Py_ssize_t __pyx_v_length, int __pyx_v_zero) { + arrayobject *__pyx_v_op = NULL; + arrayobject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("clone", 0); + + /* "array.pxd":134 + * type will be same as template. + * if zero is true, new array will be initialized with zeroes.""" + * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) # <<<<<<<<<<<<<< + * if zero and op is not None: + * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) + */ + __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_template)), __pyx_v_length, __pyx_v_template->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_op = ((arrayobject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "array.pxd":135 + * if zero is true, new array will be initialized with zeroes.""" + * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) + * if zero and op is not None: # <<<<<<<<<<<<<< + * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) + * return op + */ + __pyx_t_3 = (__pyx_v_zero != 0); + if (__pyx_t_3) { + } else { + __pyx_t_2 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_3 = (((PyObject *)__pyx_v_op) != Py_None); + __pyx_t_4 = (__pyx_t_3 != 0); + __pyx_t_2 = __pyx_t_4; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "array.pxd":136 + * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) + * if zero and op is not None: + * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) # <<<<<<<<<<<<<< + * return op + * + */ + (void)(memset(__pyx_v_op->data.as_chars, 0, (__pyx_v_length * __pyx_v_op->ob_descr->itemsize))); + + /* "array.pxd":135 + * if zero is true, new array will be initialized with zeroes.""" + * op = newarrayobject(Py_TYPE(template), length, template.ob_descr) + * if zero and op is not None: # <<<<<<<<<<<<<< + * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) + * return op + */ + } + + /* "array.pxd":137 + * if zero and op is not None: + * memset(op.data.as_chars, 0, length * op.ob_descr.itemsize) + * return op # <<<<<<<<<<<<<< + * + * cdef inline array copy(array self): + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_op)); + __pyx_r = __pyx_v_op; + goto __pyx_L0; + + /* "array.pxd":130 + * + * + * cdef inline array clone(array template, Py_ssize_t length, bint zero): # <<<<<<<<<<<<<< + * """ fast creation of a new array, given a template array. + * type will be same as template. + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cpython.array.clone", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_op); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "array.pxd":139 + * return op + * + * cdef inline array copy(array self): # <<<<<<<<<<<<<< + * """ make a copy of an array. """ + * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) + */ + +static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_copy(arrayobject *__pyx_v_self) { + arrayobject *__pyx_v_op = NULL; + arrayobject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("copy", 0); + + /* "array.pxd":141 + * cdef inline array copy(array self): + * """ make a copy of an array. """ + * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) # <<<<<<<<<<<<<< + * memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize) + * return op + */ + __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_self)), Py_SIZE(((PyObject *)__pyx_v_self)), __pyx_v_self->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_op = ((arrayobject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "array.pxd":142 + * """ make a copy of an array. """ + * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) + * memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize) # <<<<<<<<<<<<<< + * return op + * + */ + (void)(memcpy(__pyx_v_op->data.as_chars, __pyx_v_self->data.as_chars, (Py_SIZE(((PyObject *)__pyx_v_op)) * __pyx_v_op->ob_descr->itemsize))); + + /* "array.pxd":143 + * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) + * memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize) + * return op # <<<<<<<<<<<<<< + * + * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1: + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_op)); + __pyx_r = __pyx_v_op; + goto __pyx_L0; + + /* "array.pxd":139 + * return op + * + * cdef inline array copy(array self): # <<<<<<<<<<<<<< + * """ make a copy of an array. """ + * op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cpython.array.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_op); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "array.pxd":145 + * return op + * + * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1: # <<<<<<<<<<<<<< + * """ efficient appending of new stuff of same type + * (e.g. of same array type) + */ + +static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *__pyx_v_self, char *__pyx_v_stuff, Py_ssize_t __pyx_v_n) { + Py_ssize_t __pyx_v_itemsize; + Py_ssize_t __pyx_v_origsize; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("extend_buffer", 0); + + /* "array.pxd":149 + * (e.g. of same array type) + * n: number of elements (not number of bytes!) """ + * cdef Py_ssize_t itemsize = self.ob_descr.itemsize # <<<<<<<<<<<<<< + * cdef Py_ssize_t origsize = Py_SIZE(self) + * resize_smart(self, origsize + n) + */ + __pyx_t_1 = __pyx_v_self->ob_descr->itemsize; + __pyx_v_itemsize = __pyx_t_1; + + /* "array.pxd":150 + * n: number of elements (not number of bytes!) """ + * cdef Py_ssize_t itemsize = self.ob_descr.itemsize + * cdef Py_ssize_t origsize = Py_SIZE(self) # <<<<<<<<<<<<<< + * resize_smart(self, origsize + n) + * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) + */ + __pyx_v_origsize = Py_SIZE(((PyObject *)__pyx_v_self)); + + /* "array.pxd":151 + * cdef Py_ssize_t itemsize = self.ob_descr.itemsize + * cdef Py_ssize_t origsize = Py_SIZE(self) + * resize_smart(self, origsize + n) # <<<<<<<<<<<<<< + * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) + * return 0 + */ + __pyx_t_1 = resize_smart(__pyx_v_self, (__pyx_v_origsize + __pyx_v_n)); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(2, 151, __pyx_L1_error) + + /* "array.pxd":152 + * cdef Py_ssize_t origsize = Py_SIZE(self) + * resize_smart(self, origsize + n) + * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) # <<<<<<<<<<<<<< + * return 0 + * + */ + (void)(memcpy((__pyx_v_self->data.as_chars + (__pyx_v_origsize * __pyx_v_itemsize)), __pyx_v_stuff, (__pyx_v_n * __pyx_v_itemsize))); + + /* "array.pxd":153 + * resize_smart(self, origsize + n) + * memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize) + * return 0 # <<<<<<<<<<<<<< + * + * cdef inline int extend(array self, array other) except -1: + */ + __pyx_r = 0; + goto __pyx_L0; + + /* "array.pxd":145 + * return op + * + * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1: # <<<<<<<<<<<<<< + * """ efficient appending of new stuff of same type + * (e.g. of same array type) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("cpython.array.extend_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "array.pxd":155 + * return 0 + * + * cdef inline int extend(array self, array other) except -1: # <<<<<<<<<<<<<< + * """ extend array with data from another array; types must match. """ + * if self.ob_descr.typecode != other.ob_descr.typecode: + */ + +static CYTHON_INLINE int __pyx_f_7cpython_5array_extend(arrayobject *__pyx_v_self, arrayobject *__pyx_v_other) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + __Pyx_RefNannySetupContext("extend", 0); + + /* "array.pxd":157 + * cdef inline int extend(array self, array other) except -1: + * """ extend array with data from another array; types must match. """ + * if self.ob_descr.typecode != other.ob_descr.typecode: # <<<<<<<<<<<<<< + * PyErr_BadArgument() + * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) + */ + __pyx_t_1 = ((__pyx_v_self->ob_descr->typecode != __pyx_v_other->ob_descr->typecode) != 0); + if (__pyx_t_1) { + + /* "array.pxd":158 + * """ extend array with data from another array; types must match. """ + * if self.ob_descr.typecode != other.ob_descr.typecode: + * PyErr_BadArgument() # <<<<<<<<<<<<<< + * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) + * + */ + __pyx_t_2 = PyErr_BadArgument(); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(2, 158, __pyx_L1_error) + + /* "array.pxd":157 + * cdef inline int extend(array self, array other) except -1: + * """ extend array with data from another array; types must match. """ + * if self.ob_descr.typecode != other.ob_descr.typecode: # <<<<<<<<<<<<<< + * PyErr_BadArgument() + * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) + */ + } + + /* "array.pxd":159 + * if self.ob_descr.typecode != other.ob_descr.typecode: + * PyErr_BadArgument() + * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) # <<<<<<<<<<<<<< + * + * cdef inline void zero(array self): + */ + __pyx_t_2 = __pyx_f_7cpython_5array_extend_buffer(__pyx_v_self, __pyx_v_other->data.as_chars, Py_SIZE(((PyObject *)__pyx_v_other))); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(2, 159, __pyx_L1_error) + __pyx_r = __pyx_t_2; + goto __pyx_L0; + + /* "array.pxd":155 + * return 0 + * + * cdef inline int extend(array self, array other) except -1: # <<<<<<<<<<<<<< + * """ extend array with data from another array; types must match. """ + * if self.ob_descr.typecode != other.ob_descr.typecode: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("cpython.array.extend", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "array.pxd":161 + * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) + * + * cdef inline void zero(array self): # <<<<<<<<<<<<<< + * """ set all elements of array to zero. """ + * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) + */ + +static CYTHON_INLINE void __pyx_f_7cpython_5array_zero(arrayobject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("zero", 0); + + /* "array.pxd":163 + * cdef inline void zero(array self): + * """ set all elements of array to zero. """ + * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) # <<<<<<<<<<<<<< + */ + (void)(memset(__pyx_v_self->data.as_chars, 0, (Py_SIZE(((PyObject *)__pyx_v_self)) * __pyx_v_self->ob_descr->itemsize))); + + /* "array.pxd":161 + * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) + * + * cdef inline void zero(array self): # <<<<<<<<<<<<<< + * """ set all elements of array to zero. """ + * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); +} + +/* "cfunc.to_py":65 + * @cname("__Pyx_CFunc_object____object___to_py") + * cdef object __Pyx_CFunc_object____object___to_py(object (*f)(object) ): + * def wrap(object v): # <<<<<<<<<<<<<< + * """wrap(v)""" + * return f(v) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cfunc_dot_to_py_36__Pyx_CFunc_object____object___to_py_1wrap(PyObject *__pyx_self, PyObject *__pyx_v_v); /*proto*/ +static char __pyx_doc_11cfunc_dot_to_py_36__Pyx_CFunc_object____object___to_py_wrap[] = "wrap(v)"; +static PyMethodDef __pyx_mdef_11cfunc_dot_to_py_36__Pyx_CFunc_object____object___to_py_1wrap = {"wrap", (PyCFunction)__pyx_pw_11cfunc_dot_to_py_36__Pyx_CFunc_object____object___to_py_1wrap, METH_O, __pyx_doc_11cfunc_dot_to_py_36__Pyx_CFunc_object____object___to_py_wrap}; +static PyObject *__pyx_pw_11cfunc_dot_to_py_36__Pyx_CFunc_object____object___to_py_1wrap(PyObject *__pyx_self, PyObject *__pyx_v_v) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("wrap (wrapper)", 0); + __pyx_r = __pyx_pf_11cfunc_dot_to_py_36__Pyx_CFunc_object____object___to_py_wrap(__pyx_self, ((PyObject *)__pyx_v_v)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cfunc_dot_to_py_36__Pyx_CFunc_object____object___to_py_wrap(PyObject *__pyx_self, PyObject *__pyx_v_v) { + struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py *__pyx_cur_scope; + struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py *__pyx_outer_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("wrap", 0); + __pyx_outer_scope = (struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py *) __Pyx_CyFunction_GetClosure(__pyx_self); + __pyx_cur_scope = __pyx_outer_scope; + + /* "cfunc.to_py":67 + * def wrap(object v): + * """wrap(v)""" + * return f(v) # <<<<<<<<<<<<<< + * return wrap + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __pyx_cur_scope->__pyx_v_f(__pyx_v_v); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 67, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "cfunc.to_py":65 + * @cname("__Pyx_CFunc_object____object___to_py") + * cdef object __Pyx_CFunc_object____object___to_py(object (*f)(object) ): + * def wrap(object v): # <<<<<<<<<<<<<< + * """wrap(v)""" + * return f(v) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cfunc.to_py.__Pyx_CFunc_object____object___to_py.wrap", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cfunc.to_py":64 + * + * @cname("__Pyx_CFunc_object____object___to_py") + * cdef object __Pyx_CFunc_object____object___to_py(object (*f)(object) ): # <<<<<<<<<<<<<< + * def wrap(object v): + * """wrap(v)""" + */ + +static PyObject *__Pyx_CFunc_object____object___to_py(PyObject *(*__pyx_v_f)(PyObject *)) { + struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py *__pyx_cur_scope; + PyObject *__pyx_v_wrap = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__Pyx_CFunc_object____object___to_py", 0); + __pyx_cur_scope = (struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py *)__pyx_tp_new___pyx_scope_struct____Pyx_CFunc_object____object___to_py(__pyx_ptype___pyx_scope_struct____Pyx_CFunc_object____object___to_py, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(1, 64, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_f = __pyx_v_f; + + /* "cfunc.to_py":65 + * @cname("__Pyx_CFunc_object____object___to_py") + * cdef object __Pyx_CFunc_object____object___to_py(object (*f)(object) ): + * def wrap(object v): # <<<<<<<<<<<<<< + * """wrap(v)""" + * return f(v) + */ + __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_11cfunc_dot_to_py_36__Pyx_CFunc_object____object___to_py_1wrap, 0, __pyx_n_s_Pyx_CFunc_object____object___t, ((PyObject*)__pyx_cur_scope), __pyx_n_s_cfunc_to_py, __pyx_d, ((PyObject *)__pyx_codeobj__45)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 65, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_wrap = __pyx_t_1; + __pyx_t_1 = 0; + + /* "cfunc.to_py":68 + * """wrap(v)""" + * return f(v) + * return wrap # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_wrap); + __pyx_r = __pyx_v_wrap; + goto __pyx_L0; + + /* "cfunc.to_py":64 + * + * @cname("__Pyx_CFunc_object____object___to_py") + * cdef object __Pyx_CFunc_object____object___to_py(object (*f)(object) ): # <<<<<<<<<<<<<< + * def wrap(object v): + * """wrap(v)""" + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cfunc.to_py.__Pyx_CFunc_object____object___to_py", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_wrap); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cfunc.to_py":65 + * @cname("__Pyx_CFunc_int____object___to_py") + * cdef object __Pyx_CFunc_int____object___to_py(int (*f)(object) except *): + * def wrap(object v): # <<<<<<<<<<<<<< + * """wrap(v) -> 'int'""" + * return f(v) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cfunc_dot_to_py_33__Pyx_CFunc_int____object___to_py_1wrap(PyObject *__pyx_self, PyObject *__pyx_v_v); /*proto*/ +static char __pyx_doc_11cfunc_dot_to_py_33__Pyx_CFunc_int____object___to_py_wrap[] = "wrap(v) -> 'int'"; +static PyMethodDef __pyx_mdef_11cfunc_dot_to_py_33__Pyx_CFunc_int____object___to_py_1wrap = {"wrap", (PyCFunction)__pyx_pw_11cfunc_dot_to_py_33__Pyx_CFunc_int____object___to_py_1wrap, METH_O, __pyx_doc_11cfunc_dot_to_py_33__Pyx_CFunc_int____object___to_py_wrap}; +static PyObject *__pyx_pw_11cfunc_dot_to_py_33__Pyx_CFunc_int____object___to_py_1wrap(PyObject *__pyx_self, PyObject *__pyx_v_v) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("wrap (wrapper)", 0); + __pyx_r = __pyx_pf_11cfunc_dot_to_py_33__Pyx_CFunc_int____object___to_py_wrap(__pyx_self, ((PyObject *)__pyx_v_v)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cfunc_dot_to_py_33__Pyx_CFunc_int____object___to_py_wrap(PyObject *__pyx_self, PyObject *__pyx_v_v) { + struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py *__pyx_cur_scope; + struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py *__pyx_outer_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("wrap", 0); + __pyx_outer_scope = (struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py *) __Pyx_CyFunction_GetClosure(__pyx_self); + __pyx_cur_scope = __pyx_outer_scope; + + /* "cfunc.to_py":67 + * def wrap(object v): + * """wrap(v) -> 'int'""" + * return f(v) # <<<<<<<<<<<<<< + * return wrap + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __pyx_cur_scope->__pyx_v_f(__pyx_v_v); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(1, 67, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 67, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "cfunc.to_py":65 + * @cname("__Pyx_CFunc_int____object___to_py") + * cdef object __Pyx_CFunc_int____object___to_py(int (*f)(object) except *): + * def wrap(object v): # <<<<<<<<<<<<<< + * """wrap(v) -> 'int'""" + * return f(v) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("cfunc.to_py.__Pyx_CFunc_int____object___to_py.wrap", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cfunc.to_py":64 + * + * @cname("__Pyx_CFunc_int____object___to_py") + * cdef object __Pyx_CFunc_int____object___to_py(int (*f)(object) except *): # <<<<<<<<<<<<<< + * def wrap(object v): + * """wrap(v) -> 'int'""" + */ + +static PyObject *__Pyx_CFunc_int____object___to_py(int (*__pyx_v_f)(PyObject *)) { + struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py *__pyx_cur_scope; + PyObject *__pyx_v_wrap = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__Pyx_CFunc_int____object___to_py", 0); + __pyx_cur_scope = (struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py *)__pyx_tp_new___pyx_scope_struct____Pyx_CFunc_int____object___to_py(__pyx_ptype___pyx_scope_struct____Pyx_CFunc_int____object___to_py, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(1, 64, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_f = __pyx_v_f; + + /* "cfunc.to_py":65 + * @cname("__Pyx_CFunc_int____object___to_py") + * cdef object __Pyx_CFunc_int____object___to_py(int (*f)(object) except *): + * def wrap(object v): # <<<<<<<<<<<<<< + * """wrap(v) -> 'int'""" + * return f(v) + */ + __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_11cfunc_dot_to_py_33__Pyx_CFunc_int____object___to_py_1wrap, 0, __pyx_n_s_Pyx_CFunc_int____object___to_p, ((PyObject*)__pyx_cur_scope), __pyx_n_s_cfunc_to_py, __pyx_d, ((PyObject *)__pyx_codeobj__47)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 65, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_wrap = __pyx_t_1; + __pyx_t_1 = 0; + + /* "cfunc.to_py":68 + * """wrap(v) -> 'int'""" + * return f(v) + * return wrap # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_wrap); + __pyx_r = __pyx_v_wrap; + goto __pyx_L0; + + /* "cfunc.to_py":64 + * + * @cname("__Pyx_CFunc_int____object___to_py") + * cdef object __Pyx_CFunc_int____object___to_py(int (*f)(object) except *): # <<<<<<<<<<<<<< + * def wrap(object v): + * """wrap(v) -> 'int'""" + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cfunc.to_py.__Pyx_CFunc_int____object___to_py", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_wrap); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cfunc.to_py":65 + * @cname("__Pyx_CFunc_str____int___to_py") + * cdef object __Pyx_CFunc_str____int___to_py(str (*f)(int) ): + * def wrap(int v): # <<<<<<<<<<<<<< + * """wrap(v: 'int') -> str""" + * return f(v) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cfunc_dot_to_py_30__Pyx_CFunc_str____int___to_py_1wrap(PyObject *__pyx_self, PyObject *__pyx_arg_v); /*proto*/ +static char __pyx_doc_11cfunc_dot_to_py_30__Pyx_CFunc_str____int___to_py_wrap[] = "wrap(v: 'int') -> str"; +static PyMethodDef __pyx_mdef_11cfunc_dot_to_py_30__Pyx_CFunc_str____int___to_py_1wrap = {"wrap", (PyCFunction)__pyx_pw_11cfunc_dot_to_py_30__Pyx_CFunc_str____int___to_py_1wrap, METH_O, __pyx_doc_11cfunc_dot_to_py_30__Pyx_CFunc_str____int___to_py_wrap}; +static PyObject *__pyx_pw_11cfunc_dot_to_py_30__Pyx_CFunc_str____int___to_py_1wrap(PyObject *__pyx_self, PyObject *__pyx_arg_v) { + int __pyx_v_v; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("wrap (wrapper)", 0); + assert(__pyx_arg_v); { + __pyx_v_v = __Pyx_PyInt_As_int(__pyx_arg_v); if (unlikely((__pyx_v_v == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 65, __pyx_L3_error) + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("cfunc.to_py.__Pyx_CFunc_str____int___to_py.wrap", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cfunc_dot_to_py_30__Pyx_CFunc_str____int___to_py_wrap(__pyx_self, ((int)__pyx_v_v)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cfunc_dot_to_py_30__Pyx_CFunc_str____int___to_py_wrap(PyObject *__pyx_self, int __pyx_v_v) { + struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py *__pyx_cur_scope; + struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py *__pyx_outer_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("wrap", 0); + __pyx_outer_scope = (struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py *) __Pyx_CyFunction_GetClosure(__pyx_self); + __pyx_cur_scope = __pyx_outer_scope; + + /* "cfunc.to_py":67 + * def wrap(int v): + * """wrap(v: 'int') -> str""" + * return f(v) # <<<<<<<<<<<<<< + * return wrap + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __pyx_cur_scope->__pyx_v_f(__pyx_v_v); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 67, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "cfunc.to_py":65 + * @cname("__Pyx_CFunc_str____int___to_py") + * cdef object __Pyx_CFunc_str____int___to_py(str (*f)(int) ): + * def wrap(int v): # <<<<<<<<<<<<<< + * """wrap(v: 'int') -> str""" + * return f(v) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cfunc.to_py.__Pyx_CFunc_str____int___to_py.wrap", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cfunc.to_py":64 + * + * @cname("__Pyx_CFunc_str____int___to_py") + * cdef object __Pyx_CFunc_str____int___to_py(str (*f)(int) ): # <<<<<<<<<<<<<< + * def wrap(int v): + * """wrap(v: 'int') -> str""" + */ + +static PyObject *__Pyx_CFunc_str____int___to_py(PyObject *(*__pyx_v_f)(int)) { + struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py *__pyx_cur_scope; + PyObject *__pyx_v_wrap = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__Pyx_CFunc_str____int___to_py", 0); + __pyx_cur_scope = (struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py *)__pyx_tp_new___pyx_scope_struct____Pyx_CFunc_str____int___to_py(__pyx_ptype___pyx_scope_struct____Pyx_CFunc_str____int___to_py, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(1, 64, __pyx_L1_error) + } else { + __Pyx_GOTREF(__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_f = __pyx_v_f; + + /* "cfunc.to_py":65 + * @cname("__Pyx_CFunc_str____int___to_py") + * cdef object __Pyx_CFunc_str____int___to_py(str (*f)(int) ): + * def wrap(int v): # <<<<<<<<<<<<<< + * """wrap(v: 'int') -> str""" + * return f(v) + */ + __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_11cfunc_dot_to_py_30__Pyx_CFunc_str____int___to_py_1wrap, 0, __pyx_n_s_Pyx_CFunc_str____int___to_py_l, ((PyObject*)__pyx_cur_scope), __pyx_n_s_cfunc_to_py, __pyx_d, ((PyObject *)__pyx_codeobj__49)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 65, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_wrap = __pyx_t_1; + __pyx_t_1 = 0; + + /* "cfunc.to_py":68 + * """wrap(v: 'int') -> str""" + * return f(v) + * return wrap # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_wrap); + __pyx_r = __pyx_v_wrap; + goto __pyx_L0; + + /* "cfunc.to_py":64 + * + * @cname("__Pyx_CFunc_str____int___to_py") + * cdef object __Pyx_CFunc_str____int___to_py(str (*f)(int) ): # <<<<<<<<<<<<<< + * def wrap(int v): + * """wrap(v: 'int') -> str""" + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cfunc.to_py.__Pyx_CFunc_str____int___to_py", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_wrap); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy __pyx_vtable_5pysam_16libctabixproxies_TupleProxy; + +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_TupleProxy(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)o); + p->__pyx_vtab = __pyx_vtabptr_5pysam_16libctabixproxies_TupleProxy; + p->encoding = Py_None; Py_INCREF(Py_None); + if (unlikely(__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_1__cinit__(o, a, k) < 0)) goto bad; + return o; + bad: + Py_DECREF(o); o = 0; + return NULL; +} + +static void __pyx_tp_dealloc_5pysam_16libctabixproxies_TupleProxy(PyObject *o) { + struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *p = (struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_3__dealloc__(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_CLEAR(p->encoding); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_5pysam_16libctabixproxies_TupleProxy(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *p = (struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)o; + if (p->encoding) { + e = (*v)(p->encoding, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5pysam_16libctabixproxies_TupleProxy(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *p = (struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *)o; + tmp = ((PyObject*)p->encoding); + p->encoding = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} +static PyObject *__pyx_sq_item_5pysam_16libctabixproxies_TupleProxy(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5pysam_16libctabixproxies_TupleProxy(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_21__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5pysam_16libctabixproxies_TupleProxy[] = { + {"__copy__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_5__copy__, METH_NOARGS, 0}, + {"compare", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_7compare, METH_O, __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_6compare}, + {"getMinFields", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_11getMinFields, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_10getMinFields}, + {"getMaxFields", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_13getMaxFields, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_12getMaxFields}, + {"_getindex", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_15_getindex, METH_O, __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_14_getindex}, + {"_setindex", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_19_setindex, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_18_setindex}, + {"__next__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, METH_NOARGS|METH_COEXIST, __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_26__next__}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_31__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_10TupleProxy_33__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static PySequenceMethods __pyx_tp_as_sequence_TupleProxy = { + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_23__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5pysam_16libctabixproxies_TupleProxy, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_TupleProxy = { + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_23__len__, /*mp_length*/ + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_17__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5pysam_16libctabixproxies_TupleProxy, /*mp_ass_subscript*/ +}; + +static PyTypeObject __pyx_type_5pysam_16libctabixproxies_TupleProxy = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libctabixproxies.TupleProxy", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_16libctabixproxies_TupleProxy, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + &__pyx_tp_as_sequence_TupleProxy, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_TupleProxy, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_29__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "Proxy class for access to parsed row as a tuple.\n\n This class represents a table row for fast read-access.\n\n Access to individual fields is via the [] operator.\n \n Only read-only access is implemented.\n\n ", /*tp_doc*/ + __pyx_tp_traverse_5pysam_16libctabixproxies_TupleProxy, /*tp_traverse*/ + __pyx_tp_clear_5pysam_16libctabixproxies_TupleProxy, /*tp_clear*/ + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_9__richcmp__, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_25__iter__, /*tp_iter*/ + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, /*tp_iternext*/ + __pyx_methods_5pysam_16libctabixproxies_TupleProxy, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_16libctabixproxies_TupleProxy, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; +static struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy __pyx_vtable_5pysam_16libctabixproxies_NamedTupleProxy; + +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_NamedTupleProxy(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *p; + PyObject *o = __pyx_tp_new_5pysam_16libctabixproxies_TupleProxy(t, a, k); + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *)o); + p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy*)__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy; + return o; +} + +static PyObject *__pyx_tp_getattro_5pysam_16libctabixproxies_NamedTupleProxy(PyObject *o, PyObject *n) { + PyObject *v = __Pyx_PyObject_GenericGetAttr(o, n); + if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + v = __pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_3__getattr__(o, n); + } + return v; +} + +static int __pyx_tp_setattro_5pysam_16libctabixproxies_NamedTupleProxy(PyObject *o, PyObject *n, PyObject *v) { + if (v) { + return __pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_1__setattr__(o, n, v); + } + else { + if (__pyx_ptype_5pysam_16libctabixproxies_TupleProxy->tp_setattro) + return __pyx_ptype_5pysam_16libctabixproxies_TupleProxy->tp_setattro(o, n, v); + return PyObject_GenericSetAttr(o, n, 0); + } +} + +static PyMethodDef __pyx_methods_5pysam_16libctabixproxies_NamedTupleProxy[] = { + {"__getattr__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_3__getattr__, METH_O|METH_COEXIST, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_5__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_7__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_5pysam_16libctabixproxies_NamedTupleProxy = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libctabixproxies.NamedTupleProxy", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_16libctabixproxies_TupleProxy, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_29__str__, /*tp_str*/ + #else + 0, /*tp_str*/ + #endif + __pyx_tp_getattro_5pysam_16libctabixproxies_NamedTupleProxy, /*tp_getattro*/ + __pyx_tp_setattro_5pysam_16libctabixproxies_NamedTupleProxy, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5pysam_16libctabixproxies_TupleProxy, /*tp_traverse*/ + __pyx_tp_clear_5pysam_16libctabixproxies_TupleProxy, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_25__iter__, /*tp_iter*/ + #else + 0, /*tp_iter*/ + #endif + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, /*tp_iternext*/ + #else + 0, /*tp_iternext*/ + #endif + __pyx_methods_5pysam_16libctabixproxies_NamedTupleProxy, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_16libctabixproxies_NamedTupleProxy, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; +static struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy __pyx_vtable_5pysam_16libctabixproxies_GTFProxy; + +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_GTFProxy(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *p; + PyObject *o = __pyx_tp_new_5pysam_16libctabixproxies_NamedTupleProxy(t, a, k); + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)o); + p->__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy*)__pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy; + p->attribute_dict = Py_None; Py_INCREF(Py_None); + if (unlikely(__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) goto bad; + return o; + bad: + Py_DECREF(o); o = 0; + return NULL; +} + +static void __pyx_tp_dealloc_5pysam_16libctabixproxies_GTFProxy(PyObject *o) { + struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *p = (struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->attribute_dict); + PyObject_GC_Track(o); + __pyx_tp_dealloc_5pysam_16libctabixproxies_TupleProxy(o); +} + +static int __pyx_tp_traverse_5pysam_16libctabixproxies_GTFProxy(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *p = (struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)o; + e = __pyx_tp_traverse_5pysam_16libctabixproxies_TupleProxy(o, v, a); if (e) return e; + if (p->attribute_dict) { + e = (*v)(p->attribute_dict, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5pysam_16libctabixproxies_GTFProxy(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *p = (struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *)o; + __pyx_tp_clear_5pysam_16libctabixproxies_TupleProxy(o); + tmp = ((PyObject*)p->attribute_dict); + p->attribute_dict = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} +static PyObject *__pyx_sq_item_5pysam_16libctabixproxies_GTFProxy(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static PyObject *__pyx_tp_getattro_5pysam_16libctabixproxies_GTFProxy(PyObject *o, PyObject *n) { + PyObject *v = __Pyx_PyObject_GenericGetAttr(o, n); + if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + v = __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_34__getattr__(o, n); + } + return v; +} + +static int __pyx_tp_setattro_5pysam_16libctabixproxies_GTFProxy(PyObject *o, PyObject *n, PyObject *v) { + if (v) { + return __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_36__setattr__(o, n, v); + } + else { + if (__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_setattro) + return __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_setattro(o, n, v); + return PyObject_GenericSetAttr(o, n, 0); + } +} + +static PyMethodDef __pyx_methods_5pysam_16libctabixproxies_GTFProxy[] = { + {"getMinFields", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_3getMinFields, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_2getMinFields}, + {"getMaxFields", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_5getMaxFields, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_4getMaxFields}, + {"to_dict", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_7to_dict, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_6to_dict}, + {"as_dict", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_9as_dict, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_8as_dict}, + {"from_dict", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_11from_dict, METH_O, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_10from_dict}, + {"invert", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_15invert, METH_O, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_14invert}, + {"keys", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_17keys, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_16keys}, + {"setAttribute", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_21setAttribute, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_20setAttribute}, + {"attribute_string2dict", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_23attribute_string2dict, METH_O, 0}, + {"dict2attribute_string", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_29dict2attribute_string, METH_O, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_28dict2attribute_string}, + {"attribute_string2iterator", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_31attribute_string2iterator, METH_O, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_30attribute_string2iterator}, + {"__getattr__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_34__getattr__, METH_O|METH_COEXIST, __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_33__getattr__}, + {"asDict", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_38asDict, METH_VARARGS|METH_KEYWORDS, 0}, + {"fromDict", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_40fromDict, METH_VARARGS|METH_KEYWORDS, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_42__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8GTFProxy_44__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; static PySequenceMethods __pyx_tp_as_sequence_GTFProxy = { #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_23__len__, /*sq_length*/ + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_23__len__, /*sq_length*/ + #else + 0, /*sq_length*/ + #endif + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5pysam_16libctabixproxies_GTFProxy, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_GTFProxy = { + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_23__len__, /*mp_length*/ + #else + 0, /*mp_length*/ + #endif + __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_19__getitem__, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyTypeObject __pyx_type_5pysam_16libctabixproxies_GTFProxy = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libctabixproxies.GTFProxy", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_16libctabixproxies_GTFProxy, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_25__cmp__, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + &__pyx_tp_as_sequence_GTFProxy, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_GTFProxy, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_13__str__, /*tp_str*/ + __pyx_tp_getattro_5pysam_16libctabixproxies_GTFProxy, /*tp_getattro*/ + __pyx_tp_setattro_5pysam_16libctabixproxies_GTFProxy, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "Proxy class for access to GTF fields.\n\n This class represents a GTF entry for fast read-access.\n Write-access has been added as well, though some care must\n be taken. If any of the string fields (contig, source, ...)\n are set, the new value is tied to the lifetime of the\n argument that was supplied.\n\n The only exception is the attributes field when set from\n a dictionary - this field will manage its own memory.\n\n ", /*tp_doc*/ + __pyx_tp_traverse_5pysam_16libctabixproxies_GTFProxy, /*tp_traverse*/ + __pyx_tp_clear_5pysam_16libctabixproxies_GTFProxy, /*tp_clear*/ + __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_27__richcmp__, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_25__iter__, /*tp_iter*/ + #else + 0, /*tp_iter*/ + #endif + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, /*tp_iternext*/ + #else + 0, /*tp_iternext*/ + #endif + __pyx_methods_5pysam_16libctabixproxies_GTFProxy, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_16libctabixproxies_GTFProxy, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; +static struct __pyx_vtabstruct_5pysam_16libctabixproxies_GFF3Proxy __pyx_vtable_5pysam_16libctabixproxies_GFF3Proxy; + +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_GFF3Proxy(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *p; + PyObject *o = __pyx_tp_new_5pysam_16libctabixproxies_GTFProxy(t, a, k); + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy *)o); + p->__pyx_base.__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy*)__pyx_vtabptr_5pysam_16libctabixproxies_GFF3Proxy; + return o; +} + +static PyMethodDef __pyx_methods_5pysam_16libctabixproxies_GFF3Proxy[] = { + {"dict2attribute_string", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_9GFF3Proxy_1dict2attribute_string, METH_O, __pyx_doc_5pysam_16libctabixproxies_9GFF3Proxy_dict2attribute_string}, + {"attribute_string2iterator", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_9GFF3Proxy_3attribute_string2iterator, METH_O, __pyx_doc_5pysam_16libctabixproxies_9GFF3Proxy_2attribute_string2iterator}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_9GFF3Proxy_6__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_9GFF3Proxy_8__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_5pysam_16libctabixproxies_GFF3Proxy = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libctabixproxies.GFF3Proxy", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_16libctabixproxies_GTFProxy, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_25__cmp__, /*tp_compare*/ + #else + 0, /*tp_compare*/ + #endif + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_13__str__, /*tp_str*/ + #else + 0, /*tp_str*/ + #endif + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5pysam_16libctabixproxies_GTFProxy, /*tp_traverse*/ + __pyx_tp_clear_5pysam_16libctabixproxies_GTFProxy, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_25__iter__, /*tp_iter*/ + #else + 0, /*tp_iter*/ + #endif + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, /*tp_iternext*/ + #else + 0, /*tp_iternext*/ + #endif + __pyx_methods_5pysam_16libctabixproxies_GFF3Proxy, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_16libctabixproxies_GFF3Proxy, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; +static struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy __pyx_vtable_5pysam_16libctabixproxies_BedProxy; + +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_BedProxy(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *p; + PyObject *o = __pyx_tp_new_5pysam_16libctabixproxies_NamedTupleProxy(t, a, k); + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)o); + p->__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy*)__pyx_vtabptr_5pysam_16libctabixproxies_BedProxy; + return o; +} + +static int __pyx_tp_setattro_5pysam_16libctabixproxies_BedProxy(PyObject *o, PyObject *n, PyObject *v) { + if (v) { + return __pyx_pw_5pysam_16libctabixproxies_8BedProxy_7__setattr__(o, n, v); + } + else { + if (__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_setattro) + return __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_setattro(o, n, v); + return PyObject_GenericSetAttr(o, n, 0); + } +} + +static PyMethodDef __pyx_methods_5pysam_16libctabixproxies_BedProxy[] = { + {"getMinFields", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8BedProxy_1getMinFields, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8BedProxy_getMinFields}, + {"getMaxFields", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8BedProxy_3getMaxFields, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8BedProxy_2getMaxFields}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8BedProxy_9__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8BedProxy_11__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_5pysam_16libctabixproxies_BedProxy = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libctabixproxies.BedProxy", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_16libctabixproxies_TupleProxy, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_5pysam_16libctabixproxies_8BedProxy_5__str__, /*tp_str*/ + 0, /*tp_getattro*/ + __pyx_tp_setattro_5pysam_16libctabixproxies_BedProxy, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "Proxy class for access to Bed fields.\n\n This class represents a BED entry for fast read-access.\n ", /*tp_doc*/ + __pyx_tp_traverse_5pysam_16libctabixproxies_TupleProxy, /*tp_traverse*/ + __pyx_tp_clear_5pysam_16libctabixproxies_TupleProxy, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_25__iter__, /*tp_iter*/ #else - 0, /*sq_length*/ + 0, /*tp_iter*/ + #endif + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, /*tp_iternext*/ + #else + 0, /*tp_iternext*/ + #endif + __pyx_methods_5pysam_16libctabixproxies_BedProxy, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_16libctabixproxies_BedProxy, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ #endif +}; +static struct __pyx_vtabstruct_5pysam_16libctabixproxies_VCFProxy __pyx_vtable_5pysam_16libctabixproxies_VCFProxy; + +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_VCFProxy(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *p; + PyObject *o = __pyx_tp_new_5pysam_16libctabixproxies_NamedTupleProxy(t, a, k); + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)o); + p->__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy*)__pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy; + if (unlikely(__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) goto bad; + return o; + bad: + Py_DECREF(o); o = 0; + return NULL; +} + +static int __pyx_tp_setattro_5pysam_16libctabixproxies_VCFProxy(PyObject *o, PyObject *n, PyObject *v) { + if (v) { + return __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_5__setattr__(o, n, v); + } + else { + if (__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_setattro) + return __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_setattro(o, n, v); + return PyObject_GenericSetAttr(o, n, 0); + } +} + +static PyObject *__pyx_getprop_5pysam_16libctabixproxies_8VCFProxy_pos(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3pos_1__get__(o); +} + +static PyMethodDef __pyx_methods_5pysam_16libctabixproxies_VCFProxy[] = { + {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_7__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_9__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5pysam_16libctabixproxies_VCFProxy[] = { + {(char *)"pos", __pyx_getprop_5pysam_16libctabixproxies_8VCFProxy_pos, 0, (char *)"feature end (in 0-based open/closed coordinates).", 0}, + {0, 0, 0, 0, 0} +}; + +static PySequenceMethods __pyx_tp_as_sequence_VCFProxy = { + __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5pysam_16libctabixproxies_GTFProxy, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -15332,60 +17384,314 @@ static PySequenceMethods __pyx_tp_as_sequence_GTFProxy = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_GTFProxy = { - #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_23__len__, /*mp_length*/ - #else - 0, /*mp_length*/ +static PyMappingMethods __pyx_tp_as_mapping_VCFProxy = { + __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3__len__, /*mp_length*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_17__getitem__, /*mp_subscript*/ + #else + 0, /*mp_subscript*/ + #endif + 0, /*mp_ass_subscript*/ +}; + +static PyTypeObject __pyx_type_5pysam_16libctabixproxies_VCFProxy = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libctabixproxies.VCFProxy", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_16libctabixproxies_TupleProxy, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + &__pyx_tp_as_sequence_VCFProxy, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_VCFProxy, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_29__str__, /*tp_str*/ + #else + 0, /*tp_str*/ + #endif + 0, /*tp_getattro*/ + __pyx_tp_setattro_5pysam_16libctabixproxies_VCFProxy, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "Proxy class for access to VCF fields.\n\n The genotypes are accessed via a numeric index.\n Sample headers are not available.\n ", /*tp_doc*/ + __pyx_tp_traverse_5pysam_16libctabixproxies_TupleProxy, /*tp_traverse*/ + __pyx_tp_clear_5pysam_16libctabixproxies_TupleProxy, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_25__iter__, /*tp_iter*/ + #else + 0, /*tp_iter*/ + #endif + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, /*tp_iternext*/ + #else + 0, /*tp_iternext*/ + #endif + __pyx_methods_5pysam_16libctabixproxies_VCFProxy, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5pysam_16libctabixproxies_VCFProxy, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_16libctabixproxies_VCFProxy, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator *__pyx_freelist_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator[8]; +static int __pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator = 0; + +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator)))) { + o = (PyObject*)__pyx_freelist_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator[--__pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator]; + memset(o, 0, sizeof(struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator)); + (void) PyObject_INIT(o, t); + PyObject_GC_Track(o); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } + return o; +} + +static void __pyx_tp_dealloc_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator(PyObject *o) { + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator *p = (struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator *)o; + PyObject_GC_UnTrack(o); + Py_CLEAR(p->__pyx_v_attributes); + Py_CLEAR(p->__pyx_v_d); + Py_CLEAR(p->__pyx_v_f); + Py_CLEAR(p->__pyx_v_fields); + Py_CLEAR(p->__pyx_v_n); + Py_CLEAR(p->__pyx_v_s); + Py_CLEAR(p->__pyx_v_self); + Py_CLEAR(p->__pyx_v_v); + Py_CLEAR(p->__pyx_v_x); + Py_CLEAR(p->__pyx_t_0); + if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator)))) { + __pyx_freelist_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator[__pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator++] = ((struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); + } +} + +static int __pyx_tp_traverse_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator *p = (struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator *)o; + if (p->__pyx_v_attributes) { + e = (*v)(p->__pyx_v_attributes, a); if (e) return e; + } + if (p->__pyx_v_d) { + e = (*v)(p->__pyx_v_d, a); if (e) return e; + } + if (p->__pyx_v_f) { + e = (*v)(p->__pyx_v_f, a); if (e) return e; + } + if (p->__pyx_v_fields) { + e = (*v)(p->__pyx_v_fields, a); if (e) return e; + } + if (p->__pyx_v_n) { + e = (*v)(p->__pyx_v_n, a); if (e) return e; + } + if (p->__pyx_v_s) { + e = (*v)(p->__pyx_v_s, a); if (e) return e; + } + if (p->__pyx_v_self) { + e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e; + } + if (p->__pyx_v_v) { + e = (*v)(p->__pyx_v_v, a); if (e) return e; + } + if (p->__pyx_v_x) { + e = (*v)(p->__pyx_v_x, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; + } + return 0; +} + +static PyTypeObject __pyx_type_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libctabixproxies.__pyx_scope_struct__attribute_string2iterator", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + 0, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ #endif - __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_19__getitem__, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ }; -static PyTypeObject __pyx_type_5pysam_16libctabixproxies_GTFProxy = { +static struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *__pyx_freelist_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator[8]; +static int __pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator = 0; + +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator)))) { + o = (PyObject*)__pyx_freelist_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator[--__pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator]; + memset(o, 0, sizeof(struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator)); + (void) PyObject_INIT(o, t); + PyObject_GC_Track(o); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } + return o; +} + +static void __pyx_tp_dealloc_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator(PyObject *o) { + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *p = (struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *)o; + PyObject_GC_UnTrack(o); + Py_CLEAR(p->__pyx_v_f); + Py_CLEAR(p->__pyx_v_genexpr); + Py_CLEAR(p->__pyx_v_key); + Py_CLEAR(p->__pyx_v_s); + Py_CLEAR(p->__pyx_v_self); + Py_CLEAR(p->__pyx_v_value); + Py_CLEAR(p->__pyx_t_0); + if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator)))) { + __pyx_freelist_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator[__pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator++] = ((struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); + } +} + +static int __pyx_tp_traverse_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *p = (struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator *)o; + if (p->__pyx_v_f) { + e = (*v)(p->__pyx_v_f, a); if (e) return e; + } + if (p->__pyx_v_genexpr) { + e = (*v)(p->__pyx_v_genexpr, a); if (e) return e; + } + if (p->__pyx_v_key) { + e = (*v)(p->__pyx_v_key, a); if (e) return e; + } + if (p->__pyx_v_s) { + e = (*v)(p->__pyx_v_s, a); if (e) return e; + } + if (p->__pyx_v_self) { + e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e; + } + if (p->__pyx_v_value) { + e = (*v)(p->__pyx_v_value, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; + } + return 0; +} + +static PyTypeObject __pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator = { PyVarObject_HEAD_INIT(0, 0) - "pysam.libctabixproxies.GTFProxy", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy), /*tp_basicsize*/ + "pysam.libctabixproxies.__pyx_scope_struct_1_attribute_string2iterator", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_16libctabixproxies_GTFProxy, /*tp_dealloc*/ + __pyx_tp_dealloc_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_25__cmp__, /*tp_compare*/ + 0, /*tp_compare*/ #endif #if PY_MAJOR_VERSION >= 3 0, /*tp_as_async*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ - &__pyx_tp_as_sequence_GTFProxy, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_GTFProxy, /*tp_as_mapping*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_13__str__, /*tp_str*/ - __pyx_tp_getattro_5pysam_16libctabixproxies_GTFProxy, /*tp_getattro*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "Proxy class for access to GTF fields.\n\n This class represents a GTF entry for fast read-access.\n Write-access has been added as well, though some care must\n be taken. If any of the string fields (contig, source, ...)\n are set, the new value is tied to the lifetime of the\n argument that was supplied.\n\n The only exception is the attributes field when set from\n a dictionary - this field will manage its own memory.\n ", /*tp_doc*/ - __pyx_tp_traverse_5pysam_16libctabixproxies_TupleProxy, /*tp_traverse*/ - __pyx_tp_clear_5pysam_16libctabixproxies_TupleProxy, /*tp_clear*/ - __pyx_pw_5pysam_16libctabixproxies_8GTFProxy_27__richcmp__, /*tp_richcompare*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_25__iter__, /*tp_iter*/ - #else 0, /*tp_iter*/ - #endif - #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, /*tp_iternext*/ - #else 0, /*tp_iternext*/ - #endif - __pyx_methods_5pysam_16libctabixproxies_GTFProxy, /*tp_methods*/ + 0, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5pysam_16libctabixproxies_GTFProxy, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -15393,7 +17699,7 @@ static PyTypeObject __pyx_type_5pysam_16libctabixproxies_GTFProxy = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_16libctabixproxies_GTFProxy, /*tp_new*/ + __pyx_tp_new_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -15407,50 +17713,58 @@ static PyTypeObject __pyx_type_5pysam_16libctabixproxies_GTFProxy = { 0, /*tp_finalize*/ #endif }; -static struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy __pyx_vtable_5pysam_16libctabixproxies_NamedTupleProxy; -static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_NamedTupleProxy(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *p; - PyObject *o = __pyx_tp_new_5pysam_16libctabixproxies_TupleProxy(t, a, k); - if (unlikely(!o)) return 0; - p = ((struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy *)o); - p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy*)__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy; +static struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr *__pyx_freelist_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr[8]; +static int __pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr = 0; + +static PyObject *__pyx_tp_new_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr)))) { + o = (PyObject*)__pyx_freelist_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr[--__pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr]; + memset(o, 0, sizeof(struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr)); + (void) PyObject_INIT(o, t); + PyObject_GC_Track(o); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } return o; } -static PyObject *__pyx_tp_getattro_5pysam_16libctabixproxies_NamedTupleProxy(PyObject *o, PyObject *n) { - PyObject *v = __Pyx_PyObject_GenericGetAttr(o, n); - if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyErr_Clear(); - v = __pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_3__getattr__(o, n); +static void __pyx_tp_dealloc_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr(PyObject *o) { + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr *)o; + PyObject_GC_UnTrack(o); + Py_CLEAR(p->__pyx_outer_scope); + Py_CLEAR(p->__pyx_v_x); + Py_CLEAR(p->__pyx_t_0); + if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr)))) { + __pyx_freelist_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr[__pyx_freecount_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr++] = ((struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); } - return v; } -static int __pyx_tp_setattro_5pysam_16libctabixproxies_NamedTupleProxy(PyObject *o, PyObject *n, PyObject *v) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_1__setattr__(o, n, v); +static int __pyx_tp_traverse_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr *)o; + if (p->__pyx_outer_scope) { + e = (*v)(((PyObject *)p->__pyx_outer_scope), a); if (e) return e; } - else { - if (__pyx_ptype_5pysam_16libctabixproxies_TupleProxy->tp_setattro) - return __pyx_ptype_5pysam_16libctabixproxies_TupleProxy->tp_setattro(o, n, v); - return PyObject_GenericSetAttr(o, n, 0); + if (p->__pyx_v_x) { + e = (*v)(p->__pyx_v_x, a); if (e) return e; } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; + } + return 0; } -static PyMethodDef __pyx_methods_5pysam_16libctabixproxies_NamedTupleProxy[] = { - {"__getattr__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_3__getattr__, METH_O|METH_COEXIST, 0}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_5__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_15NamedTupleProxy_7__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; - -static PyTypeObject __pyx_type_5pysam_16libctabixproxies_NamedTupleProxy = { +static PyTypeObject __pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr = { PyVarObject_HEAD_INIT(0, 0) - "pysam.libctabixproxies.NamedTupleProxy", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy), /*tp_basicsize*/ + "pysam.libctabixproxies.__pyx_scope_struct_2_genexpr", /*tp_name*/ + sizeof(struct __pyx_obj_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_16libctabixproxies_TupleProxy, /*tp_dealloc*/ + __pyx_tp_dealloc_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -15466,31 +17780,19 @@ static PyTypeObject __pyx_type_5pysam_16libctabixproxies_NamedTupleProxy = { 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_29__str__, /*tp_str*/ - #else 0, /*tp_str*/ - #endif - __pyx_tp_getattro_5pysam_16libctabixproxies_NamedTupleProxy, /*tp_getattro*/ - __pyx_tp_setattro_5pysam_16libctabixproxies_NamedTupleProxy, /*tp_setattro*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - __pyx_tp_traverse_5pysam_16libctabixproxies_TupleProxy, /*tp_traverse*/ - __pyx_tp_clear_5pysam_16libctabixproxies_TupleProxy, /*tp_clear*/ + __pyx_tp_traverse_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr, /*tp_traverse*/ + 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_25__iter__, /*tp_iter*/ - #else 0, /*tp_iter*/ - #endif - #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, /*tp_iternext*/ - #else 0, /*tp_iternext*/ - #endif - __pyx_methods_5pysam_16libctabixproxies_NamedTupleProxy, /*tp_methods*/ + 0, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -15500,7 +17802,7 @@ static PyTypeObject __pyx_type_5pysam_16libctabixproxies_NamedTupleProxy = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_16libctabixproxies_NamedTupleProxy, /*tp_new*/ + __pyx_tp_new_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -15514,42 +17816,119 @@ static PyTypeObject __pyx_type_5pysam_16libctabixproxies_NamedTupleProxy = { 0, /*tp_finalize*/ #endif }; -static struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy __pyx_vtable_5pysam_16libctabixproxies_BedProxy; -static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_BedProxy(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *p; - PyObject *o = __pyx_tp_new_5pysam_16libctabixproxies_NamedTupleProxy(t, a, k); - if (unlikely(!o)) return 0; - p = ((struct __pyx_obj_5pysam_16libctabixproxies_BedProxy *)o); - p->__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy*)__pyx_vtabptr_5pysam_16libctabixproxies_BedProxy; +static struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py *__pyx_freelist___pyx_scope_struct____Pyx_CFunc_object____object___to_py[8]; +static int __pyx_freecount___pyx_scope_struct____Pyx_CFunc_object____object___to_py = 0; + +static PyObject *__pyx_tp_new___pyx_scope_struct____Pyx_CFunc_object____object___to_py(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount___pyx_scope_struct____Pyx_CFunc_object____object___to_py > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py)))) { + o = (PyObject*)__pyx_freelist___pyx_scope_struct____Pyx_CFunc_object____object___to_py[--__pyx_freecount___pyx_scope_struct____Pyx_CFunc_object____object___to_py]; + memset(o, 0, sizeof(struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py)); + (void) PyObject_INIT(o, t); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } return o; } -static int __pyx_tp_setattro_5pysam_16libctabixproxies_BedProxy(PyObject *o, PyObject *n, PyObject *v) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_8BedProxy_7__setattr__(o, n, v); - } - else { - if (__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_setattro) - return __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_setattro(o, n, v); - return PyObject_GenericSetAttr(o, n, 0); +static void __pyx_tp_dealloc___pyx_scope_struct____Pyx_CFunc_object____object___to_py(PyObject *o) { + if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount___pyx_scope_struct____Pyx_CFunc_object____object___to_py < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py)))) { + __pyx_freelist___pyx_scope_struct____Pyx_CFunc_object____object___to_py[__pyx_freecount___pyx_scope_struct____Pyx_CFunc_object____object___to_py++] = ((struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); } } -static PyMethodDef __pyx_methods_5pysam_16libctabixproxies_BedProxy[] = { - {"getMinFields", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8BedProxy_1getMinFields, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8BedProxy_getMinFields}, - {"getMaxFields", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8BedProxy_3getMaxFields, METH_NOARGS, __pyx_doc_5pysam_16libctabixproxies_8BedProxy_2getMaxFields}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8BedProxy_9__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8BedProxy_11__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} +static PyTypeObject __pyx_scope_struct____Pyx_CFunc_object____object___to_py = { + PyVarObject_HEAD_INIT(0, 0) + "pysam.libctabixproxies.__pyx_scope_struct____Pyx_CFunc_object____object___to_py", /*tp_name*/ + sizeof(struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_object____object___to_py), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc___pyx_scope_struct____Pyx_CFunc_object____object___to_py, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + 0, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new___pyx_scope_struct____Pyx_CFunc_object____object___to_py, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif }; -static PyTypeObject __pyx_type_5pysam_16libctabixproxies_BedProxy = { +static struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py *__pyx_freelist___pyx_scope_struct____Pyx_CFunc_int____object___to_py[8]; +static int __pyx_freecount___pyx_scope_struct____Pyx_CFunc_int____object___to_py = 0; + +static PyObject *__pyx_tp_new___pyx_scope_struct____Pyx_CFunc_int____object___to_py(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount___pyx_scope_struct____Pyx_CFunc_int____object___to_py > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py)))) { + o = (PyObject*)__pyx_freelist___pyx_scope_struct____Pyx_CFunc_int____object___to_py[--__pyx_freecount___pyx_scope_struct____Pyx_CFunc_int____object___to_py]; + memset(o, 0, sizeof(struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py)); + (void) PyObject_INIT(o, t); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } + return o; +} + +static void __pyx_tp_dealloc___pyx_scope_struct____Pyx_CFunc_int____object___to_py(PyObject *o) { + if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount___pyx_scope_struct____Pyx_CFunc_int____object___to_py < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py)))) { + __pyx_freelist___pyx_scope_struct____Pyx_CFunc_int____object___to_py[__pyx_freecount___pyx_scope_struct____Pyx_CFunc_int____object___to_py++] = ((struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); + } +} + +static PyTypeObject __pyx_scope_struct____Pyx_CFunc_int____object___to_py = { PyVarObject_HEAD_INIT(0, 0) - "pysam.libctabixproxies.BedProxy", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy), /*tp_basicsize*/ + "pysam.libctabixproxies.__pyx_scope_struct____Pyx_CFunc_int____object___to_py", /*tp_name*/ + sizeof(struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_int____object___to_py), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_16libctabixproxies_TupleProxy, /*tp_dealloc*/ + __pyx_tp_dealloc___pyx_scope_struct____Pyx_CFunc_int____object___to_py, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -15565,27 +17944,19 @@ static PyTypeObject __pyx_type_5pysam_16libctabixproxies_BedProxy = { 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5pysam_16libctabixproxies_8BedProxy_5__str__, /*tp_str*/ + 0, /*tp_str*/ 0, /*tp_getattro*/ - __pyx_tp_setattro_5pysam_16libctabixproxies_BedProxy, /*tp_setattro*/ + 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "Proxy class for access to Bed fields.\n\n This class represents a BED entry for fast read-access.\n ", /*tp_doc*/ - __pyx_tp_traverse_5pysam_16libctabixproxies_TupleProxy, /*tp_traverse*/ - __pyx_tp_clear_5pysam_16libctabixproxies_TupleProxy, /*tp_clear*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_25__iter__, /*tp_iter*/ - #else 0, /*tp_iter*/ - #endif - #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, /*tp_iternext*/ - #else 0, /*tp_iternext*/ - #endif - __pyx_methods_5pysam_16libctabixproxies_BedProxy, /*tp_methods*/ + 0, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -15595,7 +17966,7 @@ static PyTypeObject __pyx_type_5pysam_16libctabixproxies_BedProxy = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_16libctabixproxies_BedProxy, /*tp_new*/ + __pyx_tp_new___pyx_scope_struct____Pyx_CFunc_int____object___to_py, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -15609,76 +17980,37 @@ static PyTypeObject __pyx_type_5pysam_16libctabixproxies_BedProxy = { 0, /*tp_finalize*/ #endif }; -static struct __pyx_vtabstruct_5pysam_16libctabixproxies_VCFProxy __pyx_vtable_5pysam_16libctabixproxies_VCFProxy; -static PyObject *__pyx_tp_new_5pysam_16libctabixproxies_VCFProxy(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *p; - PyObject *o = __pyx_tp_new_5pysam_16libctabixproxies_NamedTupleProxy(t, a, k); - if (unlikely(!o)) return 0; - p = ((struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy *)o); - p->__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy*)__pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy; - if (unlikely(__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) goto bad; - return o; - bad: - Py_DECREF(o); o = 0; - return NULL; -} +static struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py *__pyx_freelist___pyx_scope_struct____Pyx_CFunc_str____int___to_py[8]; +static int __pyx_freecount___pyx_scope_struct____Pyx_CFunc_str____int___to_py = 0; -static int __pyx_tp_setattro_5pysam_16libctabixproxies_VCFProxy(PyObject *o, PyObject *n, PyObject *v) { - if (v) { - return __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_5__setattr__(o, n, v); - } - else { - if (__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_setattro) - return __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_setattro(o, n, v); - return PyObject_GenericSetAttr(o, n, 0); +static PyObject *__pyx_tp_new___pyx_scope_struct____Pyx_CFunc_str____int___to_py(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount___pyx_scope_struct____Pyx_CFunc_str____int___to_py > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py)))) { + o = (PyObject*)__pyx_freelist___pyx_scope_struct____Pyx_CFunc_str____int___to_py[--__pyx_freecount___pyx_scope_struct____Pyx_CFunc_str____int___to_py]; + memset(o, 0, sizeof(struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py)); + (void) PyObject_INIT(o, t); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; } + return o; } -static PyObject *__pyx_getprop_5pysam_16libctabixproxies_8VCFProxy_pos(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3pos_1__get__(o); +static void __pyx_tp_dealloc___pyx_scope_struct____Pyx_CFunc_str____int___to_py(PyObject *o) { + if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount___pyx_scope_struct____Pyx_CFunc_str____int___to_py < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py)))) { + __pyx_freelist___pyx_scope_struct____Pyx_CFunc_str____int___to_py[__pyx_freecount___pyx_scope_struct____Pyx_CFunc_str____int___to_py++] = ((struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); + } } -static PyMethodDef __pyx_methods_5pysam_16libctabixproxies_VCFProxy[] = { - {"__reduce_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_7__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_5pysam_16libctabixproxies_8VCFProxy_9__setstate_cython__, METH_O, 0}, - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_5pysam_16libctabixproxies_VCFProxy[] = { - {(char *)"pos", __pyx_getprop_5pysam_16libctabixproxies_8VCFProxy_pos, 0, (char *)"feature end (in 0-based open/closed coordinates).", 0}, - {0, 0, 0, 0, 0} -}; - -static PySequenceMethods __pyx_tp_as_sequence_VCFProxy = { - __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3__len__, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_VCFProxy = { - __pyx_pw_5pysam_16libctabixproxies_8VCFProxy_3__len__, /*mp_length*/ - #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_17__getitem__, /*mp_subscript*/ - #else - 0, /*mp_subscript*/ - #endif - 0, /*mp_ass_subscript*/ -}; - -static PyTypeObject __pyx_type_5pysam_16libctabixproxies_VCFProxy = { +static PyTypeObject __pyx_scope_struct____Pyx_CFunc_str____int___to_py = { PyVarObject_HEAD_INIT(0, 0) - "pysam.libctabixproxies.VCFProxy", /*tp_name*/ - sizeof(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy), /*tp_basicsize*/ + "pysam.libctabixproxies.__pyx_scope_struct____Pyx_CFunc_str____int___to_py", /*tp_name*/ + sizeof(struct __pyx_obj___pyx_scope_struct____Pyx_CFunc_str____int___to_py), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5pysam_16libctabixproxies_TupleProxy, /*tp_dealloc*/ + __pyx_tp_dealloc___pyx_scope_struct____Pyx_CFunc_str____int___to_py, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -15690,37 +18022,25 @@ static PyTypeObject __pyx_type_5pysam_16libctabixproxies_VCFProxy = { #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ - &__pyx_tp_as_sequence_VCFProxy, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_VCFProxy, /*tp_as_mapping*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_29__str__, /*tp_str*/ - #else 0, /*tp_str*/ - #endif 0, /*tp_getattro*/ - __pyx_tp_setattro_5pysam_16libctabixproxies_VCFProxy, /*tp_setattro*/ + 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - "Proxy class for access to VCF fields.\n\n The genotypes are accessed via a numeric index.\n Sample headers are not available.\n ", /*tp_doc*/ - __pyx_tp_traverse_5pysam_16libctabixproxies_TupleProxy, /*tp_traverse*/ - __pyx_tp_clear_5pysam_16libctabixproxies_TupleProxy, /*tp_clear*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_25__iter__, /*tp_iter*/ - #else 0, /*tp_iter*/ - #endif - #if CYTHON_COMPILING_IN_PYPY - __pyx_pw_5pysam_16libctabixproxies_10TupleProxy_27__next__, /*tp_iternext*/ - #else 0, /*tp_iternext*/ - #endif - __pyx_methods_5pysam_16libctabixproxies_VCFProxy, /*tp_methods*/ + 0, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5pysam_16libctabixproxies_VCFProxy, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -15728,7 +18048,7 @@ static PyTypeObject __pyx_type_5pysam_16libctabixproxies_VCFProxy = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5pysam_16libctabixproxies_VCFProxy, /*tp_new*/ + __pyx_tp_new___pyx_scope_struct____Pyx_CFunc_str____int___to_py, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -15780,40 +18100,63 @@ static struct PyModuleDef __pyx_moduledef = { #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1}, - {&__pyx_kp_s_GTFProxy_has_no_attribute_s, __pyx_k_GTFProxy_has_no_attribute_s, sizeof(__pyx_k_GTFProxy_has_no_attribute_s), 0, 0, 1, 0}, + {&__pyx_n_s_BedProxy, __pyx_k_BedProxy, sizeof(__pyx_k_BedProxy), 0, 0, 1, 1}, + {&__pyx_n_s_GFF3Proxy, __pyx_k_GFF3Proxy, sizeof(__pyx_k_GFF3Proxy), 0, 0, 1, 1}, + {&__pyx_n_s_GFF3Proxy_attribute_string2itera, __pyx_k_GFF3Proxy_attribute_string2itera, sizeof(__pyx_k_GFF3Proxy_attribute_string2itera), 0, 0, 1, 1}, + {&__pyx_n_s_GTFProxy, __pyx_k_GTFProxy, sizeof(__pyx_k_GTFProxy), 0, 0, 1, 1}, + {&__pyx_n_s_GTFProxy_attribute_string2iterat, __pyx_k_GTFProxy_attribute_string2iterat, sizeof(__pyx_k_GTFProxy_attribute_string2iterat), 0, 0, 1, 1}, {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1}, {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1}, {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, + {&__pyx_n_s_NamedTupleProxy, __pyx_k_NamedTupleProxy, sizeof(__pyx_k_NamedTupleProxy), 0, 0, 1, 1}, {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1}, {&__pyx_n_s_OrderedDict, __pyx_k_OrderedDict, sizeof(__pyx_k_OrderedDict), 0, 0, 1, 1}, + {&__pyx_n_s_Pyx_CFunc_int____object___to_p, __pyx_k_Pyx_CFunc_int____object___to_p, sizeof(__pyx_k_Pyx_CFunc_int____object___to_p), 0, 0, 1, 1}, + {&__pyx_n_s_Pyx_CFunc_object____object___t, __pyx_k_Pyx_CFunc_object____object___t, sizeof(__pyx_k_Pyx_CFunc_object____object___t), 0, 0, 1, 1}, + {&__pyx_n_s_Pyx_CFunc_str____int___to_py_l, __pyx_k_Pyx_CFunc_str____int___to_py_l, sizeof(__pyx_k_Pyx_CFunc_str____int___to_py_l), 0, 0, 1, 1}, {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1}, + {&__pyx_n_s_TupleProxy, __pyx_k_TupleProxy, sizeof(__pyx_k_TupleProxy), 0, 0, 1, 1}, {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, + {&__pyx_n_s_VCFProxy, __pyx_k_VCFProxy, sizeof(__pyx_k_VCFProxy), 0, 0, 1, 1}, {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, + {&__pyx_kp_b__13, __pyx_k__13, sizeof(__pyx_k__13), 0, 0, 0, 0}, {&__pyx_kp_s__13, __pyx_k__13, sizeof(__pyx_k__13), 0, 0, 1, 0}, + {&__pyx_kp_s__16, __pyx_k__16, sizeof(__pyx_k__16), 0, 0, 1, 0}, + {&__pyx_kp_s__17, __pyx_k__17, sizeof(__pyx_k__17), 0, 0, 1, 0}, + {&__pyx_kp_s__18, __pyx_k__18, sizeof(__pyx_k__18), 0, 0, 1, 0}, + {&__pyx_kp_s__19, __pyx_k__19, sizeof(__pyx_k__19), 0, 0, 1, 0}, {&__pyx_kp_s__20, __pyx_k__20, sizeof(__pyx_k__20), 0, 0, 1, 0}, + {&__pyx_kp_s__21, __pyx_k__21, sizeof(__pyx_k__21), 0, 0, 1, 0}, {&__pyx_kp_s__25, __pyx_k__25, sizeof(__pyx_k__25), 0, 0, 1, 0}, {&__pyx_kp_s__27, __pyx_k__27, sizeof(__pyx_k__27), 0, 0, 1, 0}, - {&__pyx_kp_s__30, __pyx_k__30, sizeof(__pyx_k__30), 0, 0, 1, 0}, - {&__pyx_kp_s__32, __pyx_k__32, sizeof(__pyx_k__32), 0, 0, 1, 0}, + {&__pyx_kp_s__33, __pyx_k__33, sizeof(__pyx_k__33), 0, 0, 1, 0}, {&__pyx_kp_s__35, __pyx_k__35, sizeof(__pyx_k__35), 0, 0, 1, 0}, {&__pyx_kp_s__9, __pyx_k__9, sizeof(__pyx_k__9), 0, 0, 1, 0}, + {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1}, {&__pyx_n_s_alt, __pyx_k_alt, sizeof(__pyx_k_alt), 0, 0, 1, 1}, {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1}, - {&__pyx_n_s_asDict, __pyx_k_asDict, sizeof(__pyx_k_asDict), 0, 0, 1, 1}, + {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1}, {&__pyx_n_s_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1}, + {&__pyx_n_s_attribute_dict2string, __pyx_k_attribute_dict2string, sizeof(__pyx_k_attribute_dict2string), 0, 0, 1, 1}, + {&__pyx_n_s_attribute_string2dict, __pyx_k_attribute_string2dict, sizeof(__pyx_k_attribute_string2dict), 0, 0, 1, 1}, + {&__pyx_n_s_attribute_string2iterator, __pyx_k_attribute_string2iterator, sizeof(__pyx_k_attribute_string2iterator), 0, 0, 1, 1}, + {&__pyx_n_s_attribute_string2iterator_locals, __pyx_k_attribute_string2iterator_locals, sizeof(__pyx_k_attribute_string2iterator_locals), 0, 0, 1, 1}, {&__pyx_n_s_attributes, __pyx_k_attributes, sizeof(__pyx_k_attributes), 0, 0, 1, 1}, {&__pyx_kp_s_bed_format_requires_at_least_thr, __pyx_k_bed_format_requires_at_least_thr, sizeof(__pyx_k_bed_format_requires_at_least_thr), 0, 0, 1, 0}, {&__pyx_n_s_blockCount, __pyx_k_blockCount, sizeof(__pyx_k_blockCount), 0, 0, 1, 1}, {&__pyx_n_s_blockSizes, __pyx_k_blockSizes, sizeof(__pyx_k_blockSizes), 0, 0, 1, 1}, {&__pyx_n_s_blockStarts, __pyx_k_blockStarts, sizeof(__pyx_k_blockStarts), 0, 0, 1, 1}, + {&__pyx_n_s_cfunc_to_py, __pyx_k_cfunc_to_py, sizeof(__pyx_k_cfunc_to_py), 0, 0, 1, 1}, {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1}, {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1}, {&__pyx_n_s_compare, __pyx_k_compare, sizeof(__pyx_k_compare), 0, 0, 1, 1}, {&__pyx_kp_s_comparison_of_modified_TupleProx, __pyx_k_comparison_of_modified_TupleProx, sizeof(__pyx_k_comparison_of_modified_TupleProx), 0, 0, 1, 0}, {&__pyx_n_s_contig, __pyx_k_contig, sizeof(__pyx_k_contig), 0, 0, 1, 1}, + {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1}, {&__pyx_kp_s_copying_modified_tuples_is_not_i, __pyx_k_copying_modified_tuples_is_not_i, sizeof(__pyx_k_copying_modified_tuples_is_not_i), 0, 0, 1, 0}, {&__pyx_n_s_decode, __pyx_k_decode, sizeof(__pyx_k_decode), 0, 0, 1, 1}, + {&__pyx_n_s_dict2attribute_string, __pyx_k_dict2attribute_string, sizeof(__pyx_k_dict2attribute_string), 0, 0, 1, 1}, {&__pyx_n_s_encoding, __pyx_k_encoding, sizeof(__pyx_k_encoding), 0, 0, 1, 1}, {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1}, {&__pyx_n_s_endswith, __pyx_k_endswith, sizeof(__pyx_k_endswith), 0, 0, 1, 1}, @@ -15822,7 +18165,9 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_filter, __pyx_k_filter, sizeof(__pyx_k_filter), 0, 0, 1, 1}, {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1}, {&__pyx_n_s_frame, __pyx_k_frame, sizeof(__pyx_k_frame), 0, 0, 1, 1}, - {&__pyx_n_s_fromDict, __pyx_k_fromDict, sizeof(__pyx_k_fromDict), 0, 0, 1, 1}, + {&__pyx_n_s_from_dict, __pyx_k_from_dict, sizeof(__pyx_k_from_dict), 0, 0, 1, 1}, + {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1}, + {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1}, {&__pyx_n_s_getMaxFields, __pyx_k_getMaxFields, sizeof(__pyx_k_getMaxFields), 0, 0, 1, 1}, {&__pyx_n_s_getMinFields, __pyx_k_getMinFields, sizeof(__pyx_k_getMinFields), 0, 0, 1, 1}, {&__pyx_n_s_getattr, __pyx_k_getattr, sizeof(__pyx_k_getattr), 0, 0, 1, 1}, @@ -15837,7 +18182,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_itemRGB, __pyx_k_itemRGB, sizeof(__pyx_k_itemRGB), 0, 0, 1, 1}, {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1}, {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1}, - {&__pyx_kp_s_key_s_not_found_no_attributes, __pyx_k_key_s_not_found_no_attributes, sizeof(__pyx_k_key_s_not_found_no_attributes), 0, 0, 1, 0}, + {&__pyx_n_s_keys, __pyx_k_keys, sizeof(__pyx_k_keys), 0, 0, 1, 1}, {&__pyx_kp_s_length_of_buffer_i_number_of_byt, __pyx_k_length_of_buffer_i_number_of_byt, sizeof(__pyx_k_length_of_buffer_i_number_of_byt), 0, 0, 1, 0}, {&__pyx_kp_s_list_index_out_of_range, __pyx_k_list_index_out_of_range, sizeof(__pyx_k_list_index_out_of_range), 0, 0, 1, 0}, {&__pyx_kp_s_list_index_out_of_range_i_i, __pyx_k_list_index_out_of_range_i_i, sizeof(__pyx_k_list_index_out_of_range_i_i), 0, 0, 1, 0}, @@ -15845,13 +18190,12 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_map_key2field, __pyx_k_map_key2field, sizeof(__pyx_k_map_key2field), 0, 0, 1, 1}, {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1}, - {&__pyx_kp_s_no_attributes_defined_GTF_entry, __pyx_k_no_attributes_defined_GTF_entry, sizeof(__pyx_k_no_attributes_defined_GTF_entry), 0, 0, 1, 0}, {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0}, {&__pyx_kp_s_op_0_isn_t_implemented_yet, __pyx_k_op_0_isn_t_implemented_yet, sizeof(__pyx_k_op_0_isn_t_implemented_yet), 0, 0, 1, 0}, {&__pyx_kp_s_out_of_memory, __pyx_k_out_of_memory, sizeof(__pyx_k_out_of_memory), 0, 0, 1, 0}, {&__pyx_kp_s_out_of_memory_in_TupleProxy_copy, __pyx_k_out_of_memory_in_TupleProxy_copy, sizeof(__pyx_k_out_of_memory_in_TupleProxy_copy), 0, 0, 1, 0}, {&__pyx_kp_s_out_of_memory_in_TupleProxy_upda, __pyx_k_out_of_memory_in_TupleProxy_upda, sizeof(__pyx_k_out_of_memory_in_TupleProxy_upda), 0, 0, 1, 0}, - {&__pyx_kp_s_parsing_error_fewer_that_i_field, __pyx_k_parsing_error_fewer_that_i_field, sizeof(__pyx_k_parsing_error_fewer_that_i_field), 0, 0, 1, 0}, + {&__pyx_kp_s_parsing_error_fewer_than_i_field, __pyx_k_parsing_error_fewer_than_i_field, sizeof(__pyx_k_parsing_error_fewer_than_i_field), 0, 0, 1, 0}, {&__pyx_kp_s_parsing_error_more_than_i_fields, __pyx_k_parsing_error_more_than_i_fields, sizeof(__pyx_k_parsing_error_more_than_i_fields), 0, 0, 1, 0}, {&__pyx_n_s_pos, __pyx_k_pos, sizeof(__pyx_k_pos), 0, 0, 1, 1}, {&__pyx_n_s_pysam_libctabixproxies, __pyx_k_pysam_libctabixproxies, sizeof(__pyx_k_pysam_libctabixproxies), 0, 0, 1, 1}, @@ -15865,9 +18209,9 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, {&__pyx_n_s_ref, __pyx_k_ref, sizeof(__pyx_k_ref), 0, 0, 1, 1}, {&__pyx_kp_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 0}, - {&__pyx_kp_s_s_s, __pyx_k_s_s, sizeof(__pyx_k_s_s), 0, 0, 1, 0}, - {&__pyx_kp_s_s_s_2, __pyx_k_s_s_2, sizeof(__pyx_k_s_s_2), 0, 0, 1, 0}, {&__pyx_n_s_score, __pyx_k_score, sizeof(__pyx_k_score), 0, 0, 1, 1}, + {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1}, + {&__pyx_n_s_separator, __pyx_k_separator, sizeof(__pyx_k_separator), 0, 0, 1, 1}, {&__pyx_n_s_setindex, __pyx_k_setindex, sizeof(__pyx_k_setindex), 0, 0, 1, 1}, {&__pyx_n_s_setitem, __pyx_k_setitem, sizeof(__pyx_k_setitem), 0, 0, 1, 1}, {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, @@ -15877,30 +18221,33 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1}, {&__pyx_n_s_str, __pyx_k_str, sizeof(__pyx_k_str), 0, 0, 1, 1}, {&__pyx_n_s_strand, __pyx_k_strand, sizeof(__pyx_k_strand), 0, 0, 1, 1}, + {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, {&__pyx_n_s_strip, __pyx_k_strip, sizeof(__pyx_k_strip), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_n_s_thickEnd, __pyx_k_thickEnd, sizeof(__pyx_k_thickEnd), 0, 0, 1, 1}, {&__pyx_n_s_thickStart, __pyx_k_thickStart, sizeof(__pyx_k_thickStart), 0, 0, 1, 1}, + {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1}, {&__pyx_n_s_toDot, __pyx_k_toDot, sizeof(__pyx_k_toDot), 0, 0, 1, 1}, + {&__pyx_n_s_to_dict, __pyx_k_to_dict, sizeof(__pyx_k_to_dict), 0, 0, 1, 1}, {&__pyx_n_s_v, __pyx_k_v, sizeof(__pyx_k_v), 0, 0, 1, 1}, {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1}, + {&__pyx_n_s_wrap, __pyx_k_wrap, sizeof(__pyx_k_wrap), 0, 0, 1, 1}, {&__pyx_n_s_xrange, __pyx_k_xrange, sizeof(__pyx_k_xrange), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 64, __pyx_L1_error) - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 123, __pyx_L1_error) - __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(0, 242, __pyx_L1_error) - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 258, __pyx_L1_error) - __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 307, __pyx_L1_error) + __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(0, 246, __pyx_L1_error) + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 262, __pyx_L1_error) + __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 311, __pyx_L1_error) #if PY_MAJOR_VERSION >= 3 - __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_xrange) __PYX_ERR(0, 322, __pyx_L1_error) + __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_xrange) __PYX_ERR(0, 326, __pyx_L1_error) #else - __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_xrange); if (!__pyx_builtin_xrange) __PYX_ERR(0, 322, __pyx_L1_error) + __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_xrange); if (!__pyx_builtin_xrange) __PYX_ERR(0, 326, __pyx_L1_error) #endif __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) - __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 482, __pyx_L1_error) - __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 634, __pyx_L1_error) + __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 366, __pyx_L1_error) __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(2, 109, __pyx_L1_error) return 0; __pyx_L1_error:; @@ -15911,102 +18258,102 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "pysam/libctabixproxies.pyx":64 + /* "pysam/libctabixproxies.pyx":68 * def __copy__(self): * if self.is_modified: * raise NotImplementedError( # <<<<<<<<<<<<<< * "copying modified tuples is not implemented") * cdef TupleProxy n = type(self)() */ - __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_copying_modified_tuples_is_not_i); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 64, __pyx_L1_error) + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_copying_modified_tuples_is_not_i); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 68, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); - /* "pysam/libctabixproxies.pyx":76 + /* "pysam/libctabixproxies.pyx":80 * ''' * if self.is_modified or other.is_modified: * raise NotImplementedError( # <<<<<<<<<<<<<< * 'comparison of modified TupleProxies is not implemented') * if self.data == other.data: */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_comparison_of_modified_TupleProx); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 76, __pyx_L1_error) + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_comparison_of_modified_TupleProx); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 80, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2); - /* "pysam/libctabixproxies.pyx":123 + /* "pysam/libctabixproxies.pyx":127 * self.data = malloc(s) * if self.data == NULL: * raise ValueError("out of memory in TupleProxy.copy()") # <<<<<<<<<<<<<< * memcpy(self.data, buffer, s) * */ - __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_out_of_memory_in_TupleProxy_copy); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 123, __pyx_L1_error) + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_out_of_memory_in_TupleProxy_copy); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__3); - /* "pysam/libctabixproxies.pyx":204 + /* "pysam/libctabixproxies.pyx":208 * self.fields = calloc(max_fields, sizeof(char *)) * if self.fields == NULL: * raise ValueError("out of memory in TupleProxy.update()") # <<<<<<<<<<<<<< * * ################################# */ - __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_out_of_memory_in_TupleProxy_upda); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 204, __pyx_L1_error) + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_out_of_memory_in_TupleProxy_upda); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 208, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__4); __Pyx_GIVEREF(__pyx_tuple__4); - /* "pysam/libctabixproxies.pyx":242 + /* "pysam/libctabixproxies.pyx":246 * i += self.nfields * if i < 0: * raise IndexError("list index out of range") # <<<<<<<<<<<<<< * # apply offset - separating a fixed number * # of fields from a variable number such as in VCF */ - __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_list_index_out_of_range); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 242, __pyx_L1_error) + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_list_index_out_of_range); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 246, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__5); __Pyx_GIVEREF(__pyx_tuple__5); - /* "pysam/libctabixproxies.pyx":266 + /* "pysam/libctabixproxies.pyx":270 * cdef int idx = index * if idx < 0: * raise IndexError("list index out of range") # <<<<<<<<<<<<<< * if idx >= self.nfields: * raise IndexError("list index out of range") */ - __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_list_index_out_of_range); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 266, __pyx_L1_error) + __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_list_index_out_of_range); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__6); __Pyx_GIVEREF(__pyx_tuple__6); - /* "pysam/libctabixproxies.pyx":268 + /* "pysam/libctabixproxies.pyx":272 * raise IndexError("list index out of range") * if idx >= self.nfields: * raise IndexError("list index out of range") # <<<<<<<<<<<<<< * * if isNew(self.fields[idx], self.data, self.nbytes): */ - __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_list_index_out_of_range); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 268, __pyx_L1_error) + __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_list_index_out_of_range); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 272, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__7); __Pyx_GIVEREF(__pyx_tuple__7); - /* "pysam/libctabixproxies.pyx":284 + /* "pysam/libctabixproxies.pyx":288 * self.fields[idx] = malloc((strlen( tmp ) + 1) * sizeof(char)) * if self.fields[idx] == NULL: * raise ValueError("out of memory" ) # <<<<<<<<<<<<<< * strcpy(self.fields[idx], tmp) * */ - __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_out_of_memory); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 284, __pyx_L1_error) + __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_out_of_memory); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 288, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__8); __Pyx_GIVEREF(__pyx_tuple__8); - /* "pysam/libctabixproxies.pyx":328 + /* "pysam/libctabixproxies.pyx":332 * cpy = calloc(sizeof(char), self.nbytes+1) * if cpy == NULL: * raise ValueError("out of memory") # <<<<<<<<<<<<<< * memcpy(cpy, self.data, self.nbytes+1) * for x from 0 <= x < self.nbytes: */ - __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_out_of_memory); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 328, __pyx_L1_error) + __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_out_of_memory); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__10); __Pyx_GIVEREF(__pyx_tuple__10); @@ -16029,203 +18376,101 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GOTREF(__pyx_tuple__12); __Pyx_GIVEREF(__pyx_tuple__12); - /* "pysam/libctabixproxies.pyx":387 - * '''contig of feature.''' - * def __get__(self): - * return self._getindex(0) # <<<<<<<<<<<<<< - * def __set__(self, value): - * self._setindex(0, value) + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__14 = PyTuple_Pack(1, __pyx_int_0); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 387, __pyx_L1_error) + __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__14); __Pyx_GIVEREF(__pyx_tuple__14); - /* "pysam/libctabixproxies.pyx":394 - * '''feature source.''' - * def __get__(self): - * return self._getindex(1) # <<<<<<<<<<<<<< - * def __set__(self, value): - * if value is None: + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__15 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 394, __pyx_L1_error) + __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__15); __Pyx_GIVEREF(__pyx_tuple__15); - /* "pysam/libctabixproxies.pyx":403 - * '''feature name.''' - * def __get__(self): - * return self._getindex(2) # <<<<<<<<<<<<<< - * def __set__(self, value): - * if value is None: - */ - __pyx_tuple__16 = PyTuple_Pack(1, __pyx_int_2); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 403, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__16); - __Pyx_GIVEREF(__pyx_tuple__16); - - /* "pysam/libctabixproxies.pyx":412 - * '''feature start (in 0-based open/closed coordinates).''' - * def __get__(self ): - * return int( self._getindex(3)) - 1 # <<<<<<<<<<<<<< - * def __set__(self, value ): - * self._setindex(3, str(value+1)) - */ - __pyx_tuple__17 = PyTuple_Pack(1, __pyx_int_3); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 412, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__17); - __Pyx_GIVEREF(__pyx_tuple__17); - - /* "pysam/libctabixproxies.pyx":419 - * '''feature end (in 0-based open/closed coordinates).''' - * def __get__(self): - * return int(self._getindex(4)) # <<<<<<<<<<<<<< - * def __set__(self, value): - * self._setindex(4, str(value)) - */ - __pyx_tuple__18 = PyTuple_Pack(1, __pyx_int_4); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 419, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__18); - __Pyx_GIVEREF(__pyx_tuple__18); - - /* "pysam/libctabixproxies.pyx":426 - * '''feature score.''' - * def __get__(self): - * v = self._getindex(5) # <<<<<<<<<<<<<< - * if v == "" or v[0] == '.': - * return None - */ - __pyx_tuple__19 = PyTuple_Pack(1, __pyx_int_5); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 426, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__19); - __Pyx_GIVEREF(__pyx_tuple__19); - - /* "pysam/libctabixproxies.pyx":440 - * '''feature strand.''' - * def __get__(self): - * return self._getindex(6) # <<<<<<<<<<<<<< - * def __set__(self, value ): - * if value is None: - */ - __pyx_tuple__21 = PyTuple_Pack(1, __pyx_int_6); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 440, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__21); - __Pyx_GIVEREF(__pyx_tuple__21); - - /* "pysam/libctabixproxies.pyx":449 - * '''feature frame.''' - * def __get__(self): - * v = self._getindex(7) # <<<<<<<<<<<<<< - * if v == "" or v[0] == '.': - * return v - */ - __pyx_tuple__22 = PyTuple_Pack(1, __pyx_int_7); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 449, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__22); - __Pyx_GIVEREF(__pyx_tuple__22); - - /* "pysam/libctabixproxies.pyx":466 - * return force_str(self._attributes) - * else: - * return force_str(self._getindex(8)) # <<<<<<<<<<<<<< - * def __set__( self, value): - * if self.hasOwnAttributes: - */ - __pyx_tuple__23 = PyTuple_Pack(1, __pyx_int_8); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 466, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__23); - __Pyx_GIVEREF(__pyx_tuple__23); - - /* "pysam/libctabixproxies.pyx":482 - * attributes = self.fields[8] - * if attributes == NULL: - * raise KeyError("no attributes defined GTF entry") # <<<<<<<<<<<<<< - * return attributes - * - */ - __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_no_attributes_defined_GTF_entry); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 482, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__24); - __Pyx_GIVEREF(__pyx_tuple__24); - - /* "pysam/libctabixproxies.pyx":500 + /* "pysam/libctabixproxies.pyx":579 * * # Remove white space to prevent a last empty field. * fields = [x.strip() for x in attributes.strip().split("; ")] # <<<<<<<<<<<<<< + * for f in fields: * - * result = collections.OrderedDict() */ - __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s__25); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 500, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__26); - __Pyx_GIVEREF(__pyx_tuple__26); + __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s__21); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 579, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__22); + __Pyx_GIVEREF(__pyx_tuple__22); - /* "pysam/libctabixproxies.pyx":507 + /* "pysam/libctabixproxies.pyx":583 * * # strip semicolon (GTF files without a space after the last semicolon) * if f.endswith(";"): # <<<<<<<<<<<<<< * f = f[:-1] * */ - __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_s__27); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 507, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__28); - __Pyx_GIVEREF(__pyx_tuple__28); + __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s__20); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 583, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__23); + __Pyx_GIVEREF(__pyx_tuple__23); - /* "pysam/libctabixproxies.pyx":508 + /* "pysam/libctabixproxies.pyx":584 * # strip semicolon (GTF files without a space after the last semicolon) * if f.endswith(";"): * f = f[:-1] # <<<<<<<<<<<<<< * * # split at most once in order to avoid separating */ - __pyx_slice__29 = PySlice_New(Py_None, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__29)) __PYX_ERR(0, 508, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__29); - __Pyx_GIVEREF(__pyx_slice__29); + __pyx_slice__24 = PySlice_New(Py_None, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__24)) __PYX_ERR(0, 584, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__24); + __Pyx_GIVEREF(__pyx_slice__24); - /* "pysam/libctabixproxies.pyx":512 + /* "pysam/libctabixproxies.pyx":588 * # split at most once in order to avoid separating * # multi-word values * d = [x.strip() for x in f.split(" ", 1)] # <<<<<<<<<<<<<< * - * n,v = d[0], d[1] + * n, v = d[0], d[1] */ - __pyx_tuple__31 = PyTuple_Pack(2, __pyx_kp_s__30, __pyx_int_1); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 512, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__31); - __Pyx_GIVEREF(__pyx_tuple__31); + __pyx_tuple__26 = PyTuple_Pack(2, __pyx_kp_s__25, __pyx_int_1); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 588, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__26); + __Pyx_GIVEREF(__pyx_tuple__26); - /* "pysam/libctabixproxies.pyx":519 + /* "pysam/libctabixproxies.pyx":595 * * if v[0] == '"' and v[-1] == '"': * v = v[1:-1] # <<<<<<<<<<<<<< * else: * ## try to convert to a value */ - __pyx_slice__33 = PySlice_New(__pyx_int_1, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__33)) __PYX_ERR(0, 519, __pyx_L1_error) - __Pyx_GOTREF(__pyx_slice__33); - __Pyx_GIVEREF(__pyx_slice__33); + __pyx_slice__28 = PySlice_New(__pyx_int_1, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__28)) __PYX_ERR(0, 595, __pyx_L1_error) + __Pyx_GOTREF(__pyx_slice__28); + __Pyx_GIVEREF(__pyx_slice__28); - /* "pysam/libctabixproxies.pyx":555 - * self._attributes = calloc(l + 1, sizeof(char)) - * if self._attributes == NULL: - * raise ValueError("out of memory") # <<<<<<<<<<<<<< - * memcpy(self._attributes, p, l) - * + /* "pysam/libctabixproxies.pyx":614 + * # Only called if there *isn't* an attribute with this name + * cdef int idx + * idx, f = self.map_key2field.get(key, (-1, None)) # <<<<<<<<<<<<<< + * if idx >= 0: + * # deal with known attributes (fields 0-8) */ - __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_s_out_of_memory); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 555, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__34); - __Pyx_GIVEREF(__pyx_tuple__34); + __pyx_tuple__29 = PyTuple_Pack(2, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 614, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__29); + __Pyx_GIVEREF(__pyx_tuple__29); - /* "pysam/libctabixproxies.pyx":595 - * return [x.strip().split(" ")[0] - * # separator is ';' followed by space - * for x in r.split("; ") if x.strip() != ''] # <<<<<<<<<<<<<< + /* "pysam/libctabixproxies.pyx":644 + * # called after any properties have been resolved. + * cdef int idx + * idx, f = self.map_key2field.get(key, (-1, None)) # <<<<<<<<<<<<<< * - * def __getitem__(self, key): - */ - __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_s__25); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 595, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__36); - __Pyx_GIVEREF(__pyx_tuple__36); - - /* "pysam/libctabixproxies.pyx":593 - * '''return a list of attributes defined in this entry.''' - * r = self.attributes - * return [x.strip().split(" ")[0] # <<<<<<<<<<<<<< - * # separator is ';' followed by space - * for x in r.split("; ") if x.strip() != ''] + * if idx >= 0: */ - __pyx_tuple__37 = PyTuple_Pack(1, __pyx_kp_s__30); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 593, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__37); - __Pyx_GIVEREF(__pyx_tuple__37); + __pyx_tuple__30 = PyTuple_Pack(2, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 644, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__30); + __Pyx_GIVEREF(__pyx_tuple__30); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -16233,18 +18478,40 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__38); - __Pyx_GIVEREF(__pyx_tuple__38); + __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__31); + __Pyx_GIVEREF(__pyx_tuple__31); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__39); - __Pyx_GIVEREF(__pyx_tuple__39); + __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__32); + __Pyx_GIVEREF(__pyx_tuple__32); + + /* "pysam/libctabixproxies.pyx":681 + * """ + * + * for f in (x.strip() for x in s.split(";")): # <<<<<<<<<<<<<< + * if not f: + * continue + */ + __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_s__20); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 681, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__34); + __Pyx_GIVEREF(__pyx_tuple__34); + + /* "pysam/libctabixproxies.pyx":685 + * continue + * + * key, value = f.split("=", 1) # <<<<<<<<<<<<<< + * value = value.strip() + * + */ + __pyx_tuple__36 = PyTuple_Pack(2, __pyx_kp_s__35, __pyx_int_1); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 685, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__36); + __Pyx_GIVEREF(__pyx_tuple__36); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -16252,29 +18519,29 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__40); - __Pyx_GIVEREF(__pyx_tuple__40); + __pyx_tuple__37 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__37); + __Pyx_GIVEREF(__pyx_tuple__37); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__41); - __Pyx_GIVEREF(__pyx_tuple__41); + __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__38); + __Pyx_GIVEREF(__pyx_tuple__38); - /* "pysam/libctabixproxies.pyx":738 + /* "pysam/libctabixproxies.pyx":735 * * if self.nfields < 3: * raise ValueError( # <<<<<<<<<<<<<< * "bed format requires at least three columns") * */ - __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s_bed_format_requires_at_least_thr); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 738, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__42); - __Pyx_GIVEREF(__pyx_tuple__42); + __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_bed_format_requires_at_least_thr); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 735, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__39); + __Pyx_GIVEREF(__pyx_tuple__39); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -16282,18 +18549,18 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__43); - __Pyx_GIVEREF(__pyx_tuple__43); + __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__40); + __Pyx_GIVEREF(__pyx_tuple__40); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__44 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__44); - __Pyx_GIVEREF(__pyx_tuple__44); + __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__41); + __Pyx_GIVEREF(__pyx_tuple__41); /* "(tree fragment)":2 * def __reduce_cython__(self): @@ -16301,42 +18568,62 @@ static int __Pyx_InitCachedConstants(void) { * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__45 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__45); - __Pyx_GIVEREF(__pyx_tuple__45); + __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__42); + __Pyx_GIVEREF(__pyx_tuple__42); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__46 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__43); + __Pyx_GIVEREF(__pyx_tuple__43); + + /* "cfunc.to_py":65 + * @cname("__Pyx_CFunc_object____object___to_py") + * cdef object __Pyx_CFunc_object____object___to_py(object (*f)(object) ): + * def wrap(object v): # <<<<<<<<<<<<<< + * """wrap(v)""" + * return f(v) + */ + __pyx_tuple__44 = PyTuple_Pack(1, __pyx_n_s_v); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(1, 65, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__44); + __Pyx_GIVEREF(__pyx_tuple__44); + __pyx_codeobj__45 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__44, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_wrap, 65, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__45)) __PYX_ERR(1, 65, __pyx_L1_error) + __pyx_tuple__46 = PyTuple_Pack(1, __pyx_n_s_v); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(1, 65, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__46); __Pyx_GIVEREF(__pyx_tuple__46); + __pyx_codeobj__47 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__46, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_wrap, 65, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__47)) __PYX_ERR(1, 65, __pyx_L1_error) + __pyx_tuple__48 = PyTuple_Pack(2, __pyx_n_s_v, __pyx_n_s_v); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(1, 65, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__48); + __Pyx_GIVEREF(__pyx_tuple__48); + __pyx_codeobj__49 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__48, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_wrap, 65, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__49)) __PYX_ERR(1, 65, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":338 + /* "pysam/libctabixproxies.pyx":342 * return r * * def toDot(v): # <<<<<<<<<<<<<< * '''convert value to '.' if None''' * if v is None: */ - __pyx_tuple__47 = PyTuple_Pack(1, __pyx_n_s_v); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 338, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__47); - __Pyx_GIVEREF(__pyx_tuple__47); - __pyx_codeobj__48 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__47, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabixproxies_pyx, __pyx_n_s_toDot, 338, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__48)) __PYX_ERR(0, 338, __pyx_L1_error) + __pyx_tuple__50 = PyTuple_Pack(1, __pyx_n_s_v); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 342, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__50); + __Pyx_GIVEREF(__pyx_tuple__50); + __pyx_codeobj__51 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__50, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabixproxies_pyx, __pyx_n_s_toDot, 342, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__51)) __PYX_ERR(0, 342, __pyx_L1_error) - /* "pysam/libctabixproxies.pyx":345 + /* "pysam/libctabixproxies.pyx":349 * return str(v) * * def quote(v): # <<<<<<<<<<<<<< * '''return a quoted attribute.''' * if isinstance(v, str): */ - __pyx_tuple__49 = PyTuple_Pack(1, __pyx_n_s_v); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__49); - __Pyx_GIVEREF(__pyx_tuple__49); - __pyx_codeobj__50 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabixproxies_pyx, __pyx_n_s_quote, 345, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__50)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_tuple__52 = PyTuple_Pack(1, __pyx_n_s_v); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(0, 349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__52); + __Pyx_GIVEREF(__pyx_tuple__52); + __pyx_codeobj__53 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__52, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libctabixproxies_pyx, __pyx_n_s_quote, 349, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__53)) __PYX_ERR(0, 349, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -16407,14 +18694,14 @@ static int __Pyx_modinit_type_init_code(void) { __pyx_vtable_5pysam_16libctabixproxies_TupleProxy.present = (PyObject *(*)(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *, char *, size_t))__pyx_f_5pysam_16libctabixproxies_10TupleProxy_present; __pyx_vtable_5pysam_16libctabixproxies_TupleProxy.copy = (PyObject *(*)(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *, char *, size_t, struct __pyx_opt_args_5pysam_16libctabixproxies_10TupleProxy_copy *__pyx_optional_args))__pyx_f_5pysam_16libctabixproxies_10TupleProxy_copy; __pyx_vtable_5pysam_16libctabixproxies_TupleProxy.update = (PyObject *(*)(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *, char *, size_t))__pyx_f_5pysam_16libctabixproxies_10TupleProxy_update; - if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies_TupleProxy) < 0) __PYX_ERR(0, 27, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies_TupleProxy) < 0) __PYX_ERR(0, 31, __pyx_L1_error) __pyx_type_5pysam_16libctabixproxies_TupleProxy.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_16libctabixproxies_TupleProxy.tp_dictoffset && __pyx_type_5pysam_16libctabixproxies_TupleProxy.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_16libctabixproxies_TupleProxy.tp_getattro = __Pyx_PyObject_GenericGetAttr; } #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_TupleProxy, "__setitem__"); if (unlikely(!wrapper)) __PYX_ERR(0, 27, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_TupleProxy, "__setitem__"); if (unlikely(!wrapper)) __PYX_ERR(0, 31, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_16libctabixproxies_10TupleProxy_20__setitem__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_16libctabixproxies_10TupleProxy_20__setitem__.doc = __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_20__setitem__; @@ -16424,7 +18711,7 @@ static int __Pyx_modinit_type_init_code(void) { #endif #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_TupleProxy, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 27, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_TupleProxy, "__next__"); if (unlikely(!wrapper)) __PYX_ERR(0, 31, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_16libctabixproxies_10TupleProxy_26__next__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_16libctabixproxies_10TupleProxy_26__next__.doc = __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_26__next__; @@ -16434,48 +18721,26 @@ static int __Pyx_modinit_type_init_code(void) { #endif #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_TupleProxy, "__str__"); if (unlikely(!wrapper)) __PYX_ERR(0, 27, __pyx_L1_error) - if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { - __pyx_wrapperbase_5pysam_16libctabixproxies_10TupleProxy_28__str__ = *((PyWrapperDescrObject *)wrapper)->d_base; - __pyx_wrapperbase_5pysam_16libctabixproxies_10TupleProxy_28__str__.doc = __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_28__str__; - ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_16libctabixproxies_10TupleProxy_28__str__; - } - } - #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_16libctabixproxies_TupleProxy.tp_dict, __pyx_vtabptr_5pysam_16libctabixproxies_TupleProxy) < 0) __PYX_ERR(0, 27, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "TupleProxy", (PyObject *)&__pyx_type_5pysam_16libctabixproxies_TupleProxy) < 0) __PYX_ERR(0, 27, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_16libctabixproxies_TupleProxy) < 0) __PYX_ERR(0, 27, __pyx_L1_error) - __pyx_ptype_5pysam_16libctabixproxies_TupleProxy = &__pyx_type_5pysam_16libctabixproxies_TupleProxy; - __pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy = &__pyx_vtable_5pysam_16libctabixproxies_GTFProxy; - __pyx_vtable_5pysam_16libctabixproxies_GTFProxy.__pyx_base = *__pyx_vtabptr_5pysam_16libctabixproxies_TupleProxy; - __pyx_vtable_5pysam_16libctabixproxies_GTFProxy.__pyx_base.getMaxFields = (int (*)(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *, int __pyx_skip_dispatch))__pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMaxFields; - __pyx_vtable_5pysam_16libctabixproxies_GTFProxy.__pyx_base.getMinFields = (int (*)(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *, int __pyx_skip_dispatch))__pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMinFields; - __pyx_vtable_5pysam_16libctabixproxies_GTFProxy.getAttributes = (char *(*)(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *))__pyx_f_5pysam_16libctabixproxies_8GTFProxy_getAttributes; - __pyx_type_5pysam_16libctabixproxies_GTFProxy.tp_base = __pyx_ptype_5pysam_16libctabixproxies_TupleProxy; - if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies_GTFProxy) < 0) __PYX_ERR(0, 353, __pyx_L1_error) - __pyx_type_5pysam_16libctabixproxies_GTFProxy.tp_print = 0; - #if CYTHON_COMPILING_IN_CPYTHON - { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_GTFProxy, "__getattr__"); if (unlikely(!wrapper)) __PYX_ERR(0, 353, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_TupleProxy, "__str__"); if (unlikely(!wrapper)) __PYX_ERR(0, 31, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { - __pyx_wrapperbase_5pysam_16libctabixproxies_8GTFProxy_20__getattr__ = *((PyWrapperDescrObject *)wrapper)->d_base; - __pyx_wrapperbase_5pysam_16libctabixproxies_8GTFProxy_20__getattr__.doc = __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_20__getattr__; - ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_16libctabixproxies_8GTFProxy_20__getattr__; + __pyx_wrapperbase_5pysam_16libctabixproxies_10TupleProxy_28__str__ = *((PyWrapperDescrObject *)wrapper)->d_base; + __pyx_wrapperbase_5pysam_16libctabixproxies_10TupleProxy_28__str__.doc = __pyx_doc_5pysam_16libctabixproxies_10TupleProxy_28__str__; + ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_16libctabixproxies_10TupleProxy_28__str__; } } #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_16libctabixproxies_GTFProxy.tp_dict, __pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy) < 0) __PYX_ERR(0, 353, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "GTFProxy", (PyObject *)&__pyx_type_5pysam_16libctabixproxies_GTFProxy) < 0) __PYX_ERR(0, 353, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_16libctabixproxies_GTFProxy) < 0) __PYX_ERR(0, 353, __pyx_L1_error) - __pyx_ptype_5pysam_16libctabixproxies_GTFProxy = &__pyx_type_5pysam_16libctabixproxies_GTFProxy; + if (__Pyx_SetVtable(__pyx_type_5pysam_16libctabixproxies_TupleProxy.tp_dict, __pyx_vtabptr_5pysam_16libctabixproxies_TupleProxy) < 0) __PYX_ERR(0, 31, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "TupleProxy", (PyObject *)&__pyx_type_5pysam_16libctabixproxies_TupleProxy) < 0) __PYX_ERR(0, 31, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_16libctabixproxies_TupleProxy) < 0) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_TupleProxy = &__pyx_type_5pysam_16libctabixproxies_TupleProxy; __pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy = &__pyx_vtable_5pysam_16libctabixproxies_NamedTupleProxy; __pyx_vtable_5pysam_16libctabixproxies_NamedTupleProxy.__pyx_base = *__pyx_vtabptr_5pysam_16libctabixproxies_TupleProxy; __pyx_type_5pysam_16libctabixproxies_NamedTupleProxy.tp_base = __pyx_ptype_5pysam_16libctabixproxies_TupleProxy; - if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies_NamedTupleProxy) < 0) __PYX_ERR(0, 680, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies_NamedTupleProxy) < 0) __PYX_ERR(0, 357, __pyx_L1_error) __pyx_type_5pysam_16libctabixproxies_NamedTupleProxy.tp_print = 0; #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_NamedTupleProxy, "__setattr__"); if (unlikely(!wrapper)) __PYX_ERR(0, 680, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_NamedTupleProxy, "__setattr__"); if (unlikely(!wrapper)) __PYX_ERR(0, 357, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__.doc = __pyx_doc_5pysam_16libctabixproxies_15NamedTupleProxy___setattr__; @@ -16483,24 +18748,67 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_16libctabixproxies_NamedTupleProxy.tp_dict, __pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy) < 0) __PYX_ERR(0, 680, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "NamedTupleProxy", (PyObject *)&__pyx_type_5pysam_16libctabixproxies_NamedTupleProxy) < 0) __PYX_ERR(0, 680, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_16libctabixproxies_NamedTupleProxy) < 0) __PYX_ERR(0, 680, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_16libctabixproxies_NamedTupleProxy.tp_dict, __pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy) < 0) __PYX_ERR(0, 357, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "NamedTupleProxy", (PyObject *)&__pyx_type_5pysam_16libctabixproxies_NamedTupleProxy) < 0) __PYX_ERR(0, 357, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_16libctabixproxies_NamedTupleProxy) < 0) __PYX_ERR(0, 357, __pyx_L1_error) __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy = &__pyx_type_5pysam_16libctabixproxies_NamedTupleProxy; + __pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy = &__pyx_vtable_5pysam_16libctabixproxies_GTFProxy; + __pyx_vtable_5pysam_16libctabixproxies_GTFProxy.__pyx_base = *__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy; + __pyx_vtable_5pysam_16libctabixproxies_GTFProxy.__pyx_base.__pyx_base.getMaxFields = (int (*)(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *, int __pyx_skip_dispatch))__pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMaxFields; + __pyx_vtable_5pysam_16libctabixproxies_GTFProxy.__pyx_base.__pyx_base.getMinFields = (int (*)(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *, int __pyx_skip_dispatch))__pyx_f_5pysam_16libctabixproxies_8GTFProxy_getMinFields; + __pyx_type_5pysam_16libctabixproxies_GTFProxy.tp_base = __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy; + if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies_GTFProxy) < 0) __PYX_ERR(0, 412, __pyx_L1_error) + __pyx_type_5pysam_16libctabixproxies_GTFProxy.tp_print = 0; + #if CYTHON_COMPILING_IN_CPYTHON + { + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_GTFProxy, "__getattr__"); if (unlikely(!wrapper)) __PYX_ERR(0, 412, __pyx_L1_error) + if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { + __pyx_wrapperbase_5pysam_16libctabixproxies_8GTFProxy_33__getattr__ = *((PyWrapperDescrObject *)wrapper)->d_base; + __pyx_wrapperbase_5pysam_16libctabixproxies_8GTFProxy_33__getattr__.doc = __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_33__getattr__; + ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_16libctabixproxies_8GTFProxy_33__getattr__; + } + } + #endif + #if CYTHON_COMPILING_IN_CPYTHON + { + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_GTFProxy, "__setattr__"); if (unlikely(!wrapper)) __PYX_ERR(0, 412, __pyx_L1_error) + if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { + __pyx_wrapperbase_5pysam_16libctabixproxies_8GTFProxy_35__setattr__ = *((PyWrapperDescrObject *)wrapper)->d_base; + __pyx_wrapperbase_5pysam_16libctabixproxies_8GTFProxy_35__setattr__.doc = __pyx_doc_5pysam_16libctabixproxies_8GTFProxy_35__setattr__; + ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_16libctabixproxies_8GTFProxy_35__setattr__; + } + } + #endif + if (__Pyx_SetVtable(__pyx_type_5pysam_16libctabixproxies_GTFProxy.tp_dict, __pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy) < 0) __PYX_ERR(0, 412, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "GTFProxy", (PyObject *)&__pyx_type_5pysam_16libctabixproxies_GTFProxy) < 0) __PYX_ERR(0, 412, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_16libctabixproxies_GTFProxy) < 0) __PYX_ERR(0, 412, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_GTFProxy = &__pyx_type_5pysam_16libctabixproxies_GTFProxy; + __pyx_vtabptr_5pysam_16libctabixproxies_GFF3Proxy = &__pyx_vtable_5pysam_16libctabixproxies_GFF3Proxy; + __pyx_vtable_5pysam_16libctabixproxies_GFF3Proxy.__pyx_base = *__pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy; + __pyx_type_5pysam_16libctabixproxies_GFF3Proxy.tp_base = __pyx_ptype_5pysam_16libctabixproxies_GTFProxy; + if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies_GFF3Proxy) < 0) __PYX_ERR(0, 670, __pyx_L1_error) + __pyx_type_5pysam_16libctabixproxies_GFF3Proxy.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_16libctabixproxies_GFF3Proxy.tp_dictoffset && __pyx_type_5pysam_16libctabixproxies_GFF3Proxy.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_16libctabixproxies_GFF3Proxy.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (__Pyx_SetVtable(__pyx_type_5pysam_16libctabixproxies_GFF3Proxy.tp_dict, __pyx_vtabptr_5pysam_16libctabixproxies_GFF3Proxy) < 0) __PYX_ERR(0, 670, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "GFF3Proxy", (PyObject *)&__pyx_type_5pysam_16libctabixproxies_GFF3Proxy) < 0) __PYX_ERR(0, 670, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_16libctabixproxies_GFF3Proxy) < 0) __PYX_ERR(0, 670, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_GFF3Proxy = &__pyx_type_5pysam_16libctabixproxies_GFF3Proxy; __pyx_vtabptr_5pysam_16libctabixproxies_BedProxy = &__pyx_vtable_5pysam_16libctabixproxies_BedProxy; __pyx_vtable_5pysam_16libctabixproxies_BedProxy.__pyx_base = *__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy; __pyx_vtable_5pysam_16libctabixproxies_BedProxy.__pyx_base.__pyx_base.getMaxFields = (int (*)(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *, int __pyx_skip_dispatch))__pyx_f_5pysam_16libctabixproxies_8BedProxy_getMaxFields; __pyx_vtable_5pysam_16libctabixproxies_BedProxy.__pyx_base.__pyx_base.getMinFields = (int (*)(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *, int __pyx_skip_dispatch))__pyx_f_5pysam_16libctabixproxies_8BedProxy_getMinFields; __pyx_vtable_5pysam_16libctabixproxies_BedProxy.__pyx_base.__pyx_base.update = (PyObject *(*)(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *, char *, size_t))__pyx_f_5pysam_16libctabixproxies_8BedProxy_update; __pyx_type_5pysam_16libctabixproxies_BedProxy.tp_base = __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy; - if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies_BedProxy) < 0) __PYX_ERR(0, 703, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies_BedProxy) < 0) __PYX_ERR(0, 700, __pyx_L1_error) __pyx_type_5pysam_16libctabixproxies_BedProxy.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_16libctabixproxies_BedProxy.tp_dictoffset && __pyx_type_5pysam_16libctabixproxies_BedProxy.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_16libctabixproxies_BedProxy.tp_getattro = __Pyx_PyObject_GenericGetAttr; } #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_BedProxy, "__setattr__"); if (unlikely(!wrapper)) __PYX_ERR(0, 703, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_BedProxy, "__setattr__"); if (unlikely(!wrapper)) __PYX_ERR(0, 700, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_16libctabixproxies_8BedProxy_6__setattr__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_16libctabixproxies_8BedProxy_6__setattr__.doc = __pyx_doc_5pysam_16libctabixproxies_8BedProxy_6__setattr__; @@ -16508,22 +18816,22 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_16libctabixproxies_BedProxy.tp_dict, __pyx_vtabptr_5pysam_16libctabixproxies_BedProxy) < 0) __PYX_ERR(0, 703, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "BedProxy", (PyObject *)&__pyx_type_5pysam_16libctabixproxies_BedProxy) < 0) __PYX_ERR(0, 703, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_16libctabixproxies_BedProxy) < 0) __PYX_ERR(0, 703, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_16libctabixproxies_BedProxy.tp_dict, __pyx_vtabptr_5pysam_16libctabixproxies_BedProxy) < 0) __PYX_ERR(0, 700, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "BedProxy", (PyObject *)&__pyx_type_5pysam_16libctabixproxies_BedProxy) < 0) __PYX_ERR(0, 700, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_16libctabixproxies_BedProxy) < 0) __PYX_ERR(0, 700, __pyx_L1_error) __pyx_ptype_5pysam_16libctabixproxies_BedProxy = &__pyx_type_5pysam_16libctabixproxies_BedProxy; __pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy = &__pyx_vtable_5pysam_16libctabixproxies_VCFProxy; __pyx_vtable_5pysam_16libctabixproxies_VCFProxy.__pyx_base = *__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy; __pyx_vtable_5pysam_16libctabixproxies_VCFProxy.__pyx_base.__pyx_base.update = (PyObject *(*)(struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy *, char *, size_t))__pyx_f_5pysam_16libctabixproxies_8VCFProxy_update; __pyx_type_5pysam_16libctabixproxies_VCFProxy.tp_base = __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy; - if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies_VCFProxy) < 0) __PYX_ERR(0, 776, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies_VCFProxy) < 0) __PYX_ERR(0, 774, __pyx_L1_error) __pyx_type_5pysam_16libctabixproxies_VCFProxy.tp_print = 0; if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_16libctabixproxies_VCFProxy.tp_dictoffset && __pyx_type_5pysam_16libctabixproxies_VCFProxy.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_5pysam_16libctabixproxies_VCFProxy.tp_getattro = __Pyx_PyObject_GenericGetAttr; } #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_VCFProxy, "__len__"); if (unlikely(!wrapper)) __PYX_ERR(0, 776, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_VCFProxy, "__len__"); if (unlikely(!wrapper)) __PYX_ERR(0, 774, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_16libctabixproxies_8VCFProxy_2__len__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_16libctabixproxies_8VCFProxy_2__len__.doc = __pyx_doc_5pysam_16libctabixproxies_8VCFProxy_2__len__; @@ -16533,7 +18841,7 @@ static int __Pyx_modinit_type_init_code(void) { #endif #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_VCFProxy, "__setattr__"); if (unlikely(!wrapper)) __PYX_ERR(0, 776, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_16libctabixproxies_VCFProxy, "__setattr__"); if (unlikely(!wrapper)) __PYX_ERR(0, 774, __pyx_L1_error) if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_5pysam_16libctabixproxies_8VCFProxy_4__setattr__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_5pysam_16libctabixproxies_8VCFProxy_4__setattr__.doc = __pyx_doc_5pysam_16libctabixproxies_8VCFProxy_4__setattr__; @@ -16541,10 +18849,46 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (__Pyx_SetVtable(__pyx_type_5pysam_16libctabixproxies_VCFProxy.tp_dict, __pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy) < 0) __PYX_ERR(0, 776, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "VCFProxy", (PyObject *)&__pyx_type_5pysam_16libctabixproxies_VCFProxy) < 0) __PYX_ERR(0, 776, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_16libctabixproxies_VCFProxy) < 0) __PYX_ERR(0, 776, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_5pysam_16libctabixproxies_VCFProxy.tp_dict, __pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy) < 0) __PYX_ERR(0, 774, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "VCFProxy", (PyObject *)&__pyx_type_5pysam_16libctabixproxies_VCFProxy) < 0) __PYX_ERR(0, 774, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5pysam_16libctabixproxies_VCFProxy) < 0) __PYX_ERR(0, 774, __pyx_L1_error) __pyx_ptype_5pysam_16libctabixproxies_VCFProxy = &__pyx_type_5pysam_16libctabixproxies_VCFProxy; + if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator) < 0) __PYX_ERR(0, 563, __pyx_L1_error) + __pyx_type_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator.tp_dictoffset && __pyx_type_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + } + __pyx_ptype_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator = &__pyx_type_5pysam_16libctabixproxies___pyx_scope_struct__attribute_string2iterator; + if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator) < 0) __PYX_ERR(0, 676, __pyx_L1_error) + __pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator.tp_dictoffset && __pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + } + __pyx_ptype_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator = &__pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_1_attribute_string2iterator; + if (PyType_Ready(&__pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr) < 0) __PYX_ERR(0, 681, __pyx_L1_error) + __pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr.tp_dictoffset && __pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + } + __pyx_ptype_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr = &__pyx_type_5pysam_16libctabixproxies___pyx_scope_struct_2_genexpr; + if (PyType_Ready(&__pyx_scope_struct____Pyx_CFunc_object____object___to_py) < 0) __PYX_ERR(1, 64, __pyx_L1_error) + __pyx_scope_struct____Pyx_CFunc_object____object___to_py.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_scope_struct____Pyx_CFunc_object____object___to_py.tp_dictoffset && __pyx_scope_struct____Pyx_CFunc_object____object___to_py.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_scope_struct____Pyx_CFunc_object____object___to_py.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + } + __pyx_ptype___pyx_scope_struct____Pyx_CFunc_object____object___to_py = &__pyx_scope_struct____Pyx_CFunc_object____object___to_py; + if (PyType_Ready(&__pyx_scope_struct____Pyx_CFunc_int____object___to_py) < 0) __PYX_ERR(1, 64, __pyx_L1_error) + __pyx_scope_struct____Pyx_CFunc_int____object___to_py.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_scope_struct____Pyx_CFunc_int____object___to_py.tp_dictoffset && __pyx_scope_struct____Pyx_CFunc_int____object___to_py.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_scope_struct____Pyx_CFunc_int____object___to_py.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + } + __pyx_ptype___pyx_scope_struct____Pyx_CFunc_int____object___to_py = &__pyx_scope_struct____Pyx_CFunc_int____object___to_py; + if (PyType_Ready(&__pyx_scope_struct____Pyx_CFunc_str____int___to_py) < 0) __PYX_ERR(1, 64, __pyx_L1_error) + __pyx_scope_struct____Pyx_CFunc_str____int___to_py.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_scope_struct____Pyx_CFunc_str____int___to_py.tp_dictoffset && __pyx_scope_struct____Pyx_CFunc_str____int___to_py.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_scope_struct____Pyx_CFunc_str____int___to_py.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + } + __pyx_ptype___pyx_scope_struct____Pyx_CFunc_str____int___to_py = &__pyx_scope_struct____Pyx_CFunc_str____int___to_py; __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -16677,6 +19021,8 @@ static int __pyx_pymod_exec_libctabixproxies(PyObject *__pyx_pyinit_module) { PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations #if CYTHON_PEP489_MULTI_PHASE_INIT if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0; @@ -16779,439 +19125,748 @@ if (!__Pyx_RefNanny) { * from pysam.libcutils cimport encode_filename, from_string_and_size * * import collections # <<<<<<<<<<<<<< + * import copy * - * cdef char *StrOrEmpty(char * buffer): */ __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_collections, __pyx_t_1) < 0) __PYX_ERR(0, 11, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":338 + /* "pysam/libctabixproxies.pyx":12 + * + * import collections + * import copy # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_copy, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_copy, __pyx_t_1) < 0) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "pysam/libctabixproxies.pyx":342 * return r * * def toDot(v): # <<<<<<<<<<<<<< * '''convert value to '.' if None''' * if v is None: */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_16libctabixproxies_1toDot, NULL, __pyx_n_s_pysam_libctabixproxies); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 338, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_16libctabixproxies_1toDot, NULL, __pyx_n_s_pysam_libctabixproxies); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_toDot, __pyx_t_1) < 0) __PYX_ERR(0, 338, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_toDot, __pyx_t_1) < 0) __PYX_ERR(0, 342, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":345 + /* "pysam/libctabixproxies.pyx":349 * return str(v) * * def quote(v): # <<<<<<<<<<<<<< * '''return a quoted attribute.''' * if isinstance(v, str): */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_16libctabixproxies_3quote, NULL, __pyx_n_s_pysam_libctabixproxies); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_16libctabixproxies_3quote, NULL, __pyx_n_s_pysam_libctabixproxies); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 349, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_quote, __pyx_t_1) < 0) __PYX_ERR(0, 345, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_quote, __pyx_t_1) < 0) __PYX_ERR(0, 349, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libctabixproxies.pyx":682 + /* "pysam/libctabixproxies.pyx":359 * cdef class NamedTupleProxy(TupleProxy): * * map_key2field = {} # <<<<<<<<<<<<<< * * def __setattr__(self, key, value): */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 682, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_dict, __pyx_n_s_map_key2field, __pyx_t_1) < 0) __PYX_ERR(0, 682, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_dict, __pyx_n_s_map_key2field, __pyx_t_1) < 0) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyType_Modified(__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy); - /* "pysam/libctabixproxies.pyx":709 + /* "pysam/libctabixproxies.pyx":425 + * * ''' + * separator = "; " # <<<<<<<<<<<<<< + * + * # first value is field index, the tuple contains conversion + */ + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_GTFProxy->tp_dict, __pyx_n_s_separator, __pyx_kp_s__21) < 0) __PYX_ERR(0, 425, __pyx_L1_error) + PyType_Modified(__pyx_ptype_5pysam_16libctabixproxies_GTFProxy); + + /* "pysam/libctabixproxies.pyx":432 + * # interval string representation) * map_key2field = { - * 'contig' : (0, str), # <<<<<<<<<<<<<< - * 'start' : (1, int), - * 'end' : (2, int), + * 'contig' : (0, (str, str)), # <<<<<<<<<<<<<< + * 'source' : (1, (dot_or_str, str)), + * 'feature': (2, (dot_or_str, str)), */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 709, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 432, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 709, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 432, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)(&PyString_Type))); + __Pyx_INCREF(((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_0); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_contig, __pyx_t_3) < 0) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libctabixproxies.pyx":433 + * map_key2field = { + * 'contig' : (0, (str, str)), + * 'source' : (1, (dot_or_str, str)), # <<<<<<<<<<<<<< + * 'feature': (2, (dot_or_str, str)), + * 'start' : (3, (from1based, to1based)), + */ + __pyx_t_3 = __Pyx_CFunc_object____object___to_py(__pyx_f_5pysam_16libctabixproxies_dot_or_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 433, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 433, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_contig, __pyx_t_2) < 0) __PYX_ERR(0, 709, __pyx_L1_error) + __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 433, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_source, __pyx_t_3) < 0) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libctabixproxies.pyx":434 + * 'contig' : (0, (str, str)), + * 'source' : (1, (dot_or_str, str)), + * 'feature': (2, (dot_or_str, str)), # <<<<<<<<<<<<<< + * 'start' : (3, (from1based, to1based)), + * 'end' : (4, (int, int)), + */ + __pyx_t_3 = __Pyx_CFunc_object____object___to_py(__pyx_f_5pysam_16libctabixproxies_dot_or_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 434, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 434, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_INCREF(((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); + __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 434, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_int_2); + __Pyx_GIVEREF(__pyx_int_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_feature, __pyx_t_3) < 0) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libctabixproxies.pyx":435 + * 'source' : (1, (dot_or_str, str)), + * 'feature': (2, (dot_or_str, str)), + * 'start' : (3, (from1based, to1based)), # <<<<<<<<<<<<<< + * 'end' : (4, (int, int)), + * 'score' : (5, (dot_or_float, toDot)), + */ + __pyx_t_3 = __Pyx_CFunc_int____object___to_py(__pyx_f_5pysam_16libctabixproxies_from1based); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 435, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_CFunc_str____int___to_py(__pyx_f_5pysam_16libctabixproxies_to1based); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 435, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 435, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __pyx_t_3 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 435, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_int_3); + __Pyx_GIVEREF(__pyx_int_3); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); + __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_start, __pyx_t_2) < 0) __PYX_ERR(0, 432, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libctabixproxies.pyx":710 + /* "pysam/libctabixproxies.pyx":436 + * 'feature': (2, (dot_or_str, str)), + * 'start' : (3, (from1based, to1based)), + * 'end' : (4, (int, int)), # <<<<<<<<<<<<<< + * 'score' : (5, (dot_or_float, toDot)), + * 'strand' : (6, (dot_or_str, str)), + */ + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 436, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)(&PyInt_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyInt_Type))); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)(&PyInt_Type))); + __Pyx_INCREF(((PyObject *)(&PyInt_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyInt_Type))); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyInt_Type))); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 436, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_int_4); + __Pyx_GIVEREF(__pyx_int_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_end, __pyx_t_4) < 0) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libctabixproxies.pyx":437 + * 'start' : (3, (from1based, to1based)), + * 'end' : (4, (int, int)), + * 'score' : (5, (dot_or_float, toDot)), # <<<<<<<<<<<<<< + * 'strand' : (6, (dot_or_str, str)), + * 'frame' : (7, (dot_or_int, toDot)), + */ + __pyx_t_4 = __Pyx_CFunc_object____object___to_py(__pyx_f_5pysam_16libctabixproxies_dot_or_float); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_toDot); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __pyx_t_4 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_int_5); + __Pyx_GIVEREF(__pyx_int_5); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_5); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); + __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_score, __pyx_t_2) < 0) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libctabixproxies.pyx":438 + * 'end' : (4, (int, int)), + * 'score' : (5, (dot_or_float, toDot)), + * 'strand' : (6, (dot_or_str, str)), # <<<<<<<<<<<<<< + * 'frame' : (7, (dot_or_int, toDot)), + * 'attributes': (8, (str, str))} + */ + __pyx_t_2 = __Pyx_CFunc_object____object___to_py(__pyx_f_5pysam_16libctabixproxies_dot_or_str); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_INCREF(((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); + PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)(&PyString_Type))); + __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 438, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_int_6); + __Pyx_GIVEREF(__pyx_int_6); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_6); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); + __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_strand, __pyx_t_2) < 0) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "pysam/libctabixproxies.pyx":439 + * 'score' : (5, (dot_or_float, toDot)), + * 'strand' : (6, (dot_or_str, str)), + * 'frame' : (7, (dot_or_int, toDot)), # <<<<<<<<<<<<<< + * 'attributes': (8, (str, str))} + * + */ + __pyx_t_2 = __Pyx_CFunc_object____object___to_py(__pyx_f_5pysam_16libctabixproxies_dot_or_int); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_toDot); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_int_7); + __Pyx_GIVEREF(__pyx_int_7); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_7); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); + __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_frame, __pyx_t_3) < 0) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libctabixproxies.pyx":440 + * 'strand' : (6, (dot_or_str, str)), + * 'frame' : (7, (dot_or_int, toDot)), + * 'attributes': (8, (str, str))} # <<<<<<<<<<<<<< + * + * def __cinit__(self): + */ + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)(&PyString_Type))); + __Pyx_INCREF(((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); + PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)(&PyString_Type))); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_int_8); + __Pyx_GIVEREF(__pyx_int_8); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_8); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_attributes, __pyx_t_4) < 0) __PYX_ERR(0, 432, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_GTFProxy->tp_dict, __pyx_n_s_map_key2field, __pyx_t_1) < 0) __PYX_ERR(0, 431, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyType_Modified(__pyx_ptype_5pysam_16libctabixproxies_GTFProxy); + + /* "pysam/libctabixproxies.pyx":706 + * ''' + * map_key2field = { + * 'contig' : (0, str), # <<<<<<<<<<<<<< + * 'start' : (1, int), + * 'end' : (2, int), + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_0); + __Pyx_INCREF(((PyObject *)(&PyString_Type))); + __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_contig, __pyx_t_4) < 0) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libctabixproxies.pyx":707 * map_key2field = { * 'contig' : (0, str), * 'start' : (1, int), # <<<<<<<<<<<<<< * 'end' : (2, int), * 'name' : (3, str), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 710, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 707, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_1); __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_1); __Pyx_INCREF(((PyObject *)(&PyInt_Type))); __Pyx_GIVEREF(((PyObject *)(&PyInt_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyInt_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_start, __pyx_t_2) < 0) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyInt_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_start, __pyx_t_4) < 0) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":711 + /* "pysam/libctabixproxies.pyx":708 * 'contig' : (0, str), * 'start' : (1, int), * 'end' : (2, int), # <<<<<<<<<<<<<< * 'name' : (3, str), * 'score' : (4, float), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 711, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 708, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_2); __Pyx_GIVEREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_2); __Pyx_INCREF(((PyObject *)(&PyInt_Type))); __Pyx_GIVEREF(((PyObject *)(&PyInt_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyInt_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_end, __pyx_t_2) < 0) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyInt_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_end, __pyx_t_4) < 0) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":712 + /* "pysam/libctabixproxies.pyx":709 * 'start' : (1, int), * 'end' : (2, int), * 'name' : (3, str), # <<<<<<<<<<<<<< * 'score' : (4, float), * 'strand' : (5, str), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 712, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 709, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_3); __Pyx_GIVEREF(__pyx_int_3); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_3); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_3); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_name, __pyx_t_2) < 0) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_name, __pyx_t_4) < 0) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":713 + /* "pysam/libctabixproxies.pyx":710 * 'end' : (2, int), * 'name' : (3, str), * 'score' : (4, float), # <<<<<<<<<<<<<< * 'strand' : (5, str), * 'thickStart' : (6, int), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 713, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 710, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_4); __Pyx_GIVEREF(__pyx_int_4); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_4); __Pyx_INCREF(((PyObject *)(&PyFloat_Type))); __Pyx_GIVEREF(((PyObject *)(&PyFloat_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyFloat_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_score, __pyx_t_2) < 0) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyFloat_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_score, __pyx_t_4) < 0) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":714 + /* "pysam/libctabixproxies.pyx":711 * 'name' : (3, str), * 'score' : (4, float), * 'strand' : (5, str), # <<<<<<<<<<<<<< * 'thickStart' : (6, int), * 'thickEnd' : (7, int), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 714, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 711, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_5); __Pyx_GIVEREF(__pyx_int_5); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_5); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_strand, __pyx_t_2) < 0) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_strand, __pyx_t_4) < 0) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":715 + /* "pysam/libctabixproxies.pyx":712 * 'score' : (4, float), * 'strand' : (5, str), * 'thickStart' : (6, int), # <<<<<<<<<<<<<< * 'thickEnd' : (7, int), * 'itemRGB' : (8, str), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 715, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 712, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_6); __Pyx_GIVEREF(__pyx_int_6); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_6); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_6); __Pyx_INCREF(((PyObject *)(&PyInt_Type))); __Pyx_GIVEREF(((PyObject *)(&PyInt_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyInt_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_thickStart, __pyx_t_2) < 0) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyInt_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_thickStart, __pyx_t_4) < 0) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":716 + /* "pysam/libctabixproxies.pyx":713 * 'strand' : (5, str), * 'thickStart' : (6, int), * 'thickEnd' : (7, int), # <<<<<<<<<<<<<< * 'itemRGB' : (8, str), * 'blockCount': (9, int), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 716, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 713, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_7); __Pyx_GIVEREF(__pyx_int_7); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_7); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_7); __Pyx_INCREF(((PyObject *)(&PyInt_Type))); __Pyx_GIVEREF(((PyObject *)(&PyInt_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyInt_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_thickEnd, __pyx_t_2) < 0) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyInt_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_thickEnd, __pyx_t_4) < 0) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":717 + /* "pysam/libctabixproxies.pyx":714 * 'thickStart' : (6, int), * 'thickEnd' : (7, int), * 'itemRGB' : (8, str), # <<<<<<<<<<<<<< * 'blockCount': (9, int), * 'blockSizes': (10, str), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 717, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 714, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_8); __Pyx_GIVEREF(__pyx_int_8); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_8); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_8); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_itemRGB, __pyx_t_2) < 0) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_itemRGB, __pyx_t_4) < 0) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":718 + /* "pysam/libctabixproxies.pyx":715 * 'thickEnd' : (7, int), * 'itemRGB' : (8, str), * 'blockCount': (9, int), # <<<<<<<<<<<<<< * 'blockSizes': (10, str), * 'blockStarts': (11, str), } */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 718, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 715, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_9); __Pyx_GIVEREF(__pyx_int_9); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_9); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_9); __Pyx_INCREF(((PyObject *)(&PyInt_Type))); __Pyx_GIVEREF(((PyObject *)(&PyInt_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyInt_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_blockCount, __pyx_t_2) < 0) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyInt_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_blockCount, __pyx_t_4) < 0) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":719 + /* "pysam/libctabixproxies.pyx":716 * 'itemRGB' : (8, str), * 'blockCount': (9, int), * 'blockSizes': (10, str), # <<<<<<<<<<<<<< * 'blockStarts': (11, str), } * */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 719, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 716, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_10); __Pyx_GIVEREF(__pyx_int_10); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_10); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_10); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_blockSizes, __pyx_t_2) < 0) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_blockSizes, __pyx_t_4) < 0) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":720 + /* "pysam/libctabixproxies.pyx":717 * 'blockCount': (9, int), * 'blockSizes': (10, str), * 'blockStarts': (11, str), } # <<<<<<<<<<<<<< * * cpdef int getMinFields(self): */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 720, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 717, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_11); __Pyx_GIVEREF(__pyx_int_11); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_11); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_11); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_blockStarts, __pyx_t_2) < 0) __PYX_ERR(0, 709, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_BedProxy->tp_dict, __pyx_n_s_map_key2field, __pyx_t_1) < 0) __PYX_ERR(0, 708, __pyx_L1_error) + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_blockStarts, __pyx_t_4) < 0) __PYX_ERR(0, 706, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_BedProxy->tp_dict, __pyx_n_s_map_key2field, __pyx_t_1) < 0) __PYX_ERR(0, 705, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyType_Modified(__pyx_ptype_5pysam_16libctabixproxies_BedProxy); - /* "pysam/libctabixproxies.pyx":783 + /* "pysam/libctabixproxies.pyx":781 * ''' * map_key2field = { * 'contig' : (0, str), # <<<<<<<<<<<<<< * 'pos' : (1, int), * 'id' : (2, str), */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 783, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 781, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 781, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_0); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_contig, __pyx_t_2) < 0) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_contig, __pyx_t_4) < 0) __PYX_ERR(0, 781, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":784 + /* "pysam/libctabixproxies.pyx":782 * map_key2field = { * 'contig' : (0, str), * 'pos' : (1, int), # <<<<<<<<<<<<<< * 'id' : (2, str), * 'ref' : (3, str), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 784, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 782, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_1); __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_1); __Pyx_INCREF(((PyObject *)(&PyInt_Type))); __Pyx_GIVEREF(((PyObject *)(&PyInt_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyInt_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_t_2) < 0) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyInt_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_pos, __pyx_t_4) < 0) __PYX_ERR(0, 781, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":785 + /* "pysam/libctabixproxies.pyx":783 * 'contig' : (0, str), * 'pos' : (1, int), * 'id' : (2, str), # <<<<<<<<<<<<<< * 'ref' : (3, str), * 'alt' : (4, str), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 785, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 783, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_2); __Pyx_GIVEREF(__pyx_int_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_2); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_id, __pyx_t_2) < 0) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_id, __pyx_t_4) < 0) __PYX_ERR(0, 781, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":786 + /* "pysam/libctabixproxies.pyx":784 * 'pos' : (1, int), * 'id' : (2, str), * 'ref' : (3, str), # <<<<<<<<<<<<<< * 'alt' : (4, str), * 'qual' : (5, str), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 786, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 784, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_3); __Pyx_GIVEREF(__pyx_int_3); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_3); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_3); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_ref, __pyx_t_2) < 0) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_ref, __pyx_t_4) < 0) __PYX_ERR(0, 781, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":787 + /* "pysam/libctabixproxies.pyx":785 * 'id' : (2, str), * 'ref' : (3, str), * 'alt' : (4, str), # <<<<<<<<<<<<<< * 'qual' : (5, str), * 'filter' : (6, str), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 787, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 785, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_4); __Pyx_GIVEREF(__pyx_int_4); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_4); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_alt, __pyx_t_2) < 0) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_alt, __pyx_t_4) < 0) __PYX_ERR(0, 781, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":788 + /* "pysam/libctabixproxies.pyx":786 * 'ref' : (3, str), * 'alt' : (4, str), * 'qual' : (5, str), # <<<<<<<<<<<<<< * 'filter' : (6, str), * 'info' : (7, str), */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 788, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 786, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_5); __Pyx_GIVEREF(__pyx_int_5); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_5); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_qual, __pyx_t_2) < 0) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_qual, __pyx_t_4) < 0) __PYX_ERR(0, 781, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":789 + /* "pysam/libctabixproxies.pyx":787 * 'alt' : (4, str), * 'qual' : (5, str), * 'filter' : (6, str), # <<<<<<<<<<<<<< * 'info' : (7, str), * 'format' : (8, str) } */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 789, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 787, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_6); __Pyx_GIVEREF(__pyx_int_6); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_6); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_6); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_filter, __pyx_t_2) < 0) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_filter, __pyx_t_4) < 0) __PYX_ERR(0, 781, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":790 + /* "pysam/libctabixproxies.pyx":788 * 'qual' : (5, str), * 'filter' : (6, str), * 'info' : (7, str), # <<<<<<<<<<<<<< * 'format' : (8, str) } * */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 790, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 788, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_7); __Pyx_GIVEREF(__pyx_int_7); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_7); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_7); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_info, __pyx_t_2) < 0) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_info, __pyx_t_4) < 0) __PYX_ERR(0, 781, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libctabixproxies.pyx":791 + /* "pysam/libctabixproxies.pyx":789 * 'filter' : (6, str), * 'info' : (7, str), * 'format' : (8, str) } # <<<<<<<<<<<<<< * * def __cinit__(self): */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 791, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 789, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_8); __Pyx_GIVEREF(__pyx_int_8); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_8); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_8); __Pyx_INCREF(((PyObject *)(&PyString_Type))); __Pyx_GIVEREF(((PyObject *)(&PyString_Type))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyString_Type))); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_format, __pyx_t_2) < 0) __PYX_ERR(0, 783, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_VCFProxy->tp_dict, __pyx_n_s_map_key2field, __pyx_t_1) < 0) __PYX_ERR(0, 782, __pyx_L1_error) + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)(&PyString_Type))); + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_format, __pyx_t_4) < 0) __PYX_ERR(0, 781, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem((PyObject *)__pyx_ptype_5pysam_16libctabixproxies_VCFProxy->tp_dict, __pyx_n_s_map_key2field, __pyx_t_1) < 0) __PYX_ERR(0, 780, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyType_Modified(__pyx_ptype_5pysam_16libctabixproxies_VCFProxy); + /* "pysam/libctabixproxies.pyx":827 + * + * + * __all__ = [ # <<<<<<<<<<<<<< + * "TupleProxy", + * "NamedTupleProxy", + */ + __pyx_t_1 = PyList_New(6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 827, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_TupleProxy); + __Pyx_GIVEREF(__pyx_n_s_TupleProxy); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_TupleProxy); + __Pyx_INCREF(__pyx_n_s_NamedTupleProxy); + __Pyx_GIVEREF(__pyx_n_s_NamedTupleProxy); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_NamedTupleProxy); + __Pyx_INCREF(__pyx_n_s_GTFProxy); + __Pyx_GIVEREF(__pyx_n_s_GTFProxy); + PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_GTFProxy); + __Pyx_INCREF(__pyx_n_s_GFF3Proxy); + __Pyx_GIVEREF(__pyx_n_s_GFF3Proxy); + PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_GFF3Proxy); + __Pyx_INCREF(__pyx_n_s_BedProxy); + __Pyx_GIVEREF(__pyx_n_s_BedProxy); + PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_s_BedProxy); + __Pyx_INCREF(__pyx_n_s_VCFProxy); + __Pyx_GIVEREF(__pyx_n_s_VCFProxy); + PyList_SET_ITEM(__pyx_t_1, 5, __pyx_n_s_VCFProxy); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 827, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /* "pysam/libctabixproxies.pyx":1 * from cpython cimport PyBytes_FromStringAndSize # <<<<<<<<<<<<<< * @@ -17222,12 +19877,12 @@ if (!__Pyx_RefNanny) { if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "array.pxd":161 - * return extend_buffer(self, other.data.as_chars, Py_SIZE(other)) + /* "cfunc.to_py":64 * - * cdef inline void zero(array self): # <<<<<<<<<<<<<< - * """ set all elements of array to zero. """ - * memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize) + * @cname("__Pyx_CFunc_str____int___to_py") + * cdef object __Pyx_CFunc_str____int___to_py(str (*f)(int) ): # <<<<<<<<<<<<<< + * def wrap(int v): + * """wrap(v: 'int') -> str""" */ /*--- Wrapped vars code ---*/ @@ -17236,6 +19891,8 @@ if (!__Pyx_RefNanny) { __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); if (__pyx_m) { if (__pyx_d) { __Pyx_AddTraceback("init pysam.libctabixproxies", 0, __pyx_lineno, __pyx_filename); @@ -18168,287 +20825,119 @@ static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* value } #endif -/* KeywordStringCheck */ - static int __Pyx_CheckKeywordStrings( - PyObject *kwdict, - const char* function_name, - int kw_allowed) -{ - PyObject* key = 0; - Py_ssize_t pos = 0; -#if CYTHON_COMPILING_IN_PYPY - if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) - goto invalid_keyword; - return 1; -#else - while (PyDict_Next(kwdict, &pos, &key, 0)) { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_Check(key))) - #endif - if (unlikely(!PyUnicode_Check(key))) - goto invalid_keyword_type; +/* GetItemInt */ + static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (!j) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyList_GET_SIZE(o); } - if ((!kw_allowed) && unlikely(key)) - goto invalid_keyword; - return 1; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%.200s() keywords must be strings", function_name); - return 0; + if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); #endif -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%.200s() got an unexpected keyword argument '%.200s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif - return 0; } - -/* PyIntBinop */ - #if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { - #if PY_MAJOR_VERSION < 3 - if (likely(PyInt_CheckExact(op1))) { - const long b = intval; - long x; - long a = PyInt_AS_LONG(op1); - x = (long)((unsigned long)a - b); - if (likely((x^a) >= 0 || (x^~b) >= 0)) - return PyInt_FromLong(x); - return PyLong_Type.tp_as_number->nb_subtract(op1, op2); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyTuple_GET_SIZE(o); } - #endif - #if CYTHON_USE_PYLONG_INTERNALS - if (likely(PyLong_CheckExact(op1))) { - const long b = intval; - long a, x; -#ifdef HAVE_LONG_LONG - const PY_LONG_LONG llb = intval; - PY_LONG_LONG lla, llx; -#endif - const digit* digits = ((PyLongObject*)op1)->ob_digit; - const Py_ssize_t size = Py_SIZE(op1); - if (likely(__Pyx_sst_abs(size) <= 1)) { - a = likely(size) ? digits[0] : 0; - if (size == -1) a = -a; - } else { - switch (size) { - case -2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { - a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { - a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case -3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { - a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { - a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case -4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { - a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { - a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; + if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); #endif - } - CYTHON_FALLTHROUGH; - default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2); +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS + if (is_list || PyList_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } else { + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_item)) { + if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { + Py_ssize_t l = m->sq_length(o); + if (likely(l >= 0)) { + i += l; + } else { + if (!PyErr_ExceptionMatches(PyExc_OverflowError)) + return NULL; + PyErr_Clear(); + } } + return m->sq_item(o, i); } - x = a - b; - return PyLong_FromLong(x); -#ifdef HAVE_LONG_LONG - long_long: - llx = lla - llb; - return PyLong_FromLongLong(llx); -#endif - - } - #endif - if (PyFloat_CheckExact(op1)) { - const long b = intval; - double a = PyFloat_AS_DOUBLE(op1); - double result; - PyFPE_START_PROTECT("subtract", return NULL) - result = ((double)a) - (double)b; - PyFPE_END_PROTECT(result) - return PyFloat_FromDouble(result); +#else + if (is_list || PySequence_Check(o)) { + return PySequence_GetItem(o, i); } - return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2); -} #endif + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} -/* PyIntBinop */ - #if !CYTHON_COMPILING_IN_PYPY -static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { - #if PY_MAJOR_VERSION < 3 - if (likely(PyInt_CheckExact(op1))) { - const long b = intval; - long x; - long a = PyInt_AS_LONG(op1); - x = (long)((unsigned long)a + b); - if (likely((x^a) >= 0 || (x^b) >= 0)) - return PyInt_FromLong(x); - return PyLong_Type.tp_as_number->nb_add(op1, op2); +/* ObjectGetItem */ + #if CYTHON_USE_TYPE_SLOTS +static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) { + PyObject *runerr; + Py_ssize_t key_value; + PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence; + if (unlikely(!(m && m->sq_item))) { + PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name); + return NULL; } - #endif - #if CYTHON_USE_PYLONG_INTERNALS - if (likely(PyLong_CheckExact(op1))) { - const long b = intval; - long a, x; -#ifdef HAVE_LONG_LONG - const PY_LONG_LONG llb = intval; - PY_LONG_LONG lla, llx; -#endif - const digit* digits = ((PyLongObject*)op1)->ob_digit; - const Py_ssize_t size = Py_SIZE(op1); - if (likely(__Pyx_sst_abs(size) <= 1)) { - a = likely(size) ? digits[0] : 0; - if (size == -1) a = -a; - } else { - switch (size) { - case -2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { - a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 2: - if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { - a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case -3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { - a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 3: - if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { - a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case -4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { - a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - case 4: - if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { - a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); - break; -#ifdef HAVE_LONG_LONG - } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { - lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); - goto long_long; -#endif - } - CYTHON_FALLTHROUGH; - default: return PyLong_Type.tp_as_number->nb_add(op1, op2); - } - } - x = a + b; - return PyLong_FromLong(x); -#ifdef HAVE_LONG_LONG - long_long: - llx = lla + llb; - return PyLong_FromLongLong(llx); -#endif - - + key_value = __Pyx_PyIndex_AsSsize_t(index); + if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) { + return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1); } - #endif - if (PyFloat_CheckExact(op1)) { - const long b = intval; - double a = PyFloat_AS_DOUBLE(op1); - double result; - PyFPE_START_PROTECT("add", return NULL) - result = ((double)a) + (double)b; - PyFPE_END_PROTECT(result) - return PyFloat_FromDouble(result); + if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) { + PyErr_Clear(); + PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name); } - return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2); + return NULL; +} +static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) { + PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping; + if (likely(m && m->mp_subscript)) { + return m->mp_subscript(obj, key); + } + return __Pyx_PyObject_GetIndex(obj, key); } #endif @@ -18585,135 +21074,358 @@ static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED Py_DECREF(py_result); return result; } -return_eq: - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* SaveResetException */ + #if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + #if PY_VERSION_HEX >= 0x030700A2 + *type = tstate->exc_state.exc_type; + *value = tstate->exc_state.exc_value; + *tb = tstate->exc_state.exc_traceback; + #else + *type = tstate->exc_type; + *value = tstate->exc_value; + *tb = tstate->exc_traceback; + #endif + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); +} +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if PY_VERSION_HEX >= 0x030700A2 + tmp_type = tstate->exc_state.exc_type; + tmp_value = tstate->exc_state.exc_value; + tmp_tb = tstate->exc_state.exc_traceback; + tstate->exc_state.exc_type = type; + tstate->exc_state.exc_value = value; + tstate->exc_state.exc_traceback = tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = type; + tstate->exc_value = value; + tstate->exc_traceback = tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} +#endif + +/* PyErrExceptionMatches */ + #if CYTHON_FAST_THREAD_STATE +static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; icurexc_type; + if (exc_type == err) return 1; + if (unlikely(!exc_type)) return 0; + if (unlikely(PyTuple_Check(err))) + return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); + return __Pyx_PyErr_GivenExceptionMatches(exc_type, err); +} +#endif + +/* GetException */ + #if CYTHON_FAST_THREAD_STATE +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { +#endif + PyObject *local_type, *local_value, *local_tb; +#if CYTHON_FAST_THREAD_STATE + PyObject *tmp_type, *tmp_value, *tmp_tb; + local_type = tstate->curexc_type; + local_value = tstate->curexc_value; + local_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#else + PyErr_Fetch(&local_type, &local_value, &local_tb); +#endif + PyErr_NormalizeException(&local_type, &local_value, &local_tb); +#if CYTHON_FAST_THREAD_STATE + if (unlikely(tstate->curexc_type)) +#else + if (unlikely(PyErr_Occurred())) +#endif + goto bad; + #if PY_MAJOR_VERSION >= 3 + if (local_tb) { + if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) + goto bad; + } #endif - return (equals == Py_EQ); -return_ne: - #if PY_MAJOR_VERSION < 3 - Py_XDECREF(owned_ref); + Py_XINCREF(local_tb); + Py_XINCREF(local_type); + Py_XINCREF(local_value); + *type = local_type; + *value = local_value; + *tb = local_tb; +#if CYTHON_FAST_THREAD_STATE + #if PY_VERSION_HEX >= 0x030700A2 + tmp_type = tstate->exc_state.exc_type; + tmp_value = tstate->exc_state.exc_value; + tmp_tb = tstate->exc_state.exc_traceback; + tstate->exc_state.exc_type = local_type; + tstate->exc_state.exc_value = local_value; + tstate->exc_state.exc_traceback = local_tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = local_type; + tstate->exc_value = local_value; + tstate->exc_traceback = local_tb; #endif - return (equals == Py_NE); + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(local_type, local_value, local_tb); #endif + return 0; +bad: + *type = 0; + *value = 0; + *tb = 0; + Py_XDECREF(local_type); + Py_XDECREF(local_value); + Py_XDECREF(local_tb); + return -1; } -/* GetItemInt */ - static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { - PyObject *r; - if (!j) return NULL; - r = PyObject_GetItem(o, j); - Py_DECREF(j); - return r; -} -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, - CYTHON_NCP_UNUSED int wraparound, - CYTHON_NCP_UNUSED int boundscheck) { -#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - Py_ssize_t wrapped_i = i; - if (wraparound & unlikely(i < 0)) { - wrapped_i += PyList_GET_SIZE(o); - } - if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, wrapped_i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +/* KeywordStringCheck */ + static int __Pyx_CheckKeywordStrings( + PyObject *kwdict, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; +#if CYTHON_COMPILING_IN_PYPY + if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) + goto invalid_keyword; + return 1; #else - return PySequence_GetItem(o, i); + while (PyDict_Next(kwdict, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_Check(key))) + #endif + if (unlikely(!PyUnicode_Check(key))) + goto invalid_keyword_type; + } + if ((!kw_allowed) && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + return 0; #endif +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif + return 0; } -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, - CYTHON_NCP_UNUSED int wraparound, - CYTHON_NCP_UNUSED int boundscheck) { -#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - Py_ssize_t wrapped_i = i; - if (wraparound & unlikely(i < 0)) { - wrapped_i += PyTuple_GET_SIZE(o); - } - if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); + +/* GetModuleGlobalName */ + static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 + result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); + if (likely(result)) { + Py_INCREF(result); + } else if (unlikely(PyErr_Occurred())) { + result = NULL; + } else { #else - return PySequence_GetItem(o, i); + result = PyDict_GetItem(__pyx_d, name); + if (likely(result)) { + Py_INCREF(result); + } else { +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + if (!result) { + PyErr_Clear(); #endif + result = __Pyx_GetBuiltinName(name); + } + return result; } -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, - CYTHON_NCP_UNUSED int wraparound, - CYTHON_NCP_UNUSED int boundscheck) { -#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS - if (is_list || PyList_CheckExact(o)) { - Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); - if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) { - PyObject *r = PyList_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } + +/* PyIntBinop */ + #if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { + #if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(op1))) { + const long b = intval; + long x; + long a = PyInt_AS_LONG(op1); + x = (long)((unsigned long)a + b); + if (likely((x^a) >= 0 || (x^b) >= 0)) + return PyInt_FromLong(x); + return PyLong_Type.tp_as_number->nb_add(op1, op2); } - else if (PyTuple_CheckExact(o)) { - Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); - if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } else { - PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; - if (likely(m && m->sq_item)) { - if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { - Py_ssize_t l = m->sq_length(o); - if (likely(l >= 0)) { - i += l; - } else { - if (!PyErr_ExceptionMatches(PyExc_OverflowError)) - return NULL; - PyErr_Clear(); - } + #endif + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(PyLong_CheckExact(op1))) { + const long b = intval; + long a, x; +#ifdef HAVE_LONG_LONG + const PY_LONG_LONG llb = intval; + PY_LONG_LONG lla, llx; +#endif + const digit* digits = ((PyLongObject*)op1)->ob_digit; + const Py_ssize_t size = Py_SIZE(op1); + if (likely(__Pyx_sst_abs(size) <= 1)) { + a = likely(size) ? digits[0] : 0; + if (size == -1) a = -a; + } else { + switch (size) { + case -2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case -3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case -4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + default: return PyLong_Type.tp_as_number->nb_add(op1, op2); } - return m->sq_item(o, i); } + x = a + b; + return PyLong_FromLong(x); +#ifdef HAVE_LONG_LONG + long_long: + llx = lla + llb; + return PyLong_FromLongLong(llx); +#endif + + } -#else - if (is_list || PySequence_Check(o)) { - return PySequence_GetItem(o, i); + #endif + if (PyFloat_CheckExact(op1)) { + const long b = intval; + double a = PyFloat_AS_DOUBLE(op1); + double result; + PyFPE_START_PROTECT("add", return NULL) + result = ((double)a) + (double)b; + PyFPE_END_PROTECT(result) + return PyFloat_FromDouble(result); } -#endif - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); + return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2); } - -/* GetModuleGlobalName */ - static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { - PyObject *result; -#if !CYTHON_AVOID_BORROWED_REFS -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 - result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); - if (likely(result)) { - Py_INCREF(result); - } else if (unlikely(PyErr_Occurred())) { - result = NULL; - } else { -#else - result = PyDict_GetItem(__pyx_d, name); - if (likely(result)) { - Py_INCREF(result); - } else { #endif -#else - result = PyObject_GetItem(__pyx_d, name); - if (!result) { - PyErr_Clear(); + +/* PyObjectSetAttrStr */ + #if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_setattro)) + return tp->tp_setattro(obj, attr_name, value); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_setattr)) + return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value); #endif - result = __Pyx_GetBuiltinName(name); - } - return result; + return PyObject_SetAttr(obj, attr_name, value); } +#endif /* SliceObject */ - static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj, + static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice, int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) { @@ -18810,7 +21522,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, } /* SliceTupleAndList */ - #if CYTHON_COMPILING_IN_CPYTHON + #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop, Py_ssize_t* _length) { Py_ssize_t start = *_start, stop = *_stop, length = *_length; if (start < 0) { @@ -18868,115 +21580,646 @@ static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice( } #endif -/* SaveResetException */ - #if CYTHON_FAST_THREAD_STATE -static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { - #if PY_VERSION_HEX >= 0x030700A2 - *type = tstate->exc_state.exc_type; - *value = tstate->exc_state.exc_value; - *tb = tstate->exc_state.exc_traceback; - #else - *type = tstate->exc_type; - *value = tstate->exc_value; - *tb = tstate->exc_traceback; - #endif - Py_XINCREF(*type); - Py_XINCREF(*value); - Py_XINCREF(*tb); +/* None */ + static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) { + PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname); +} + +/* FetchCommonType */ + static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { + PyObject* fake_module; + PyTypeObject* cached_type = NULL; + fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI); + if (!fake_module) return NULL; + Py_INCREF(fake_module); + cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name); + if (cached_type) { + if (!PyType_Check((PyObject*)cached_type)) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s is not a type object", + type->tp_name); + goto bad; + } + if (cached_type->tp_basicsize != type->tp_basicsize) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s has the wrong size, try recompiling", + type->tp_name); + goto bad; + } + } else { + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + if (PyType_Ready(type) < 0) goto bad; + if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0) + goto bad; + Py_INCREF(type); + cached_type = type; + } +done: + Py_DECREF(fake_module); + return cached_type; +bad: + Py_XDECREF(cached_type); + cached_type = NULL; + goto done; } -static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { - PyObject *tmp_type, *tmp_value, *tmp_tb; - #if PY_VERSION_HEX >= 0x030700A2 - tmp_type = tstate->exc_state.exc_type; - tmp_value = tstate->exc_state.exc_value; - tmp_tb = tstate->exc_state.exc_traceback; - tstate->exc_state.exc_type = type; - tstate->exc_state.exc_value = value; - tstate->exc_state.exc_traceback = tb; - #else - tmp_type = tstate->exc_type; - tmp_value = tstate->exc_value; - tmp_tb = tstate->exc_traceback; - tstate->exc_type = type; - tstate->exc_value = value; - tstate->exc_traceback = tb; - #endif - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); + +/* CythonFunction */ + #include +static PyObject * +__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure) +{ + if (unlikely(op->func_doc == NULL)) { + if (op->func.m_ml->ml_doc) { +#if PY_MAJOR_VERSION >= 3 + op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc); +#else + op->func_doc = PyString_FromString(op->func.m_ml->ml_doc); +#endif + if (unlikely(op->func_doc == NULL)) + return NULL; + } else { + Py_INCREF(Py_None); + return Py_None; + } + } + Py_INCREF(op->func_doc); + return op->func_doc; +} +static int +__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value) +{ + PyObject *tmp = op->func_doc; + if (value == NULL) { + value = Py_None; + } + Py_INCREF(value); + op->func_doc = value; + Py_XDECREF(tmp); + return 0; } +static PyObject * +__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op) +{ + if (unlikely(op->func_name == NULL)) { +#if PY_MAJOR_VERSION >= 3 + op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name); +#else + op->func_name = PyString_InternFromString(op->func.m_ml->ml_name); #endif - -/* PyErrExceptionMatches */ - #if CYTHON_FAST_THREAD_STATE -static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { - Py_ssize_t i, n; - n = PyTuple_GET_SIZE(tuple); + if (unlikely(op->func_name == NULL)) + return NULL; + } + Py_INCREF(op->func_name); + return op->func_name; +} +static int +__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value) +{ + PyObject *tmp; #if PY_MAJOR_VERSION >= 3 - for (i=0; ifunc_name; + Py_INCREF(value); + op->func_name = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op) +{ + Py_INCREF(op->func_qualname); + return op->func_qualname; +} +static int +__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value) +{ + PyObject *tmp; +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) { +#else + if (unlikely(value == NULL || !PyString_Check(value))) { #endif - for (i=0; ifunc_qualname; + Py_INCREF(value); + op->func_qualname = value; + Py_XDECREF(tmp); return 0; } -static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) { - PyObject *exc_type = tstate->curexc_type; - if (exc_type == err) return 1; - if (unlikely(!exc_type)) return 0; - if (unlikely(PyTuple_Check(err))) - return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); - return __Pyx_PyErr_GivenExceptionMatches(exc_type, err); +static PyObject * +__Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure) +{ + PyObject *self; + self = m->func_closure; + if (self == NULL) + self = Py_None; + Py_INCREF(self); + return self; +} +static PyObject * +__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op) +{ + if (unlikely(op->func_dict == NULL)) { + op->func_dict = PyDict_New(); + if (unlikely(op->func_dict == NULL)) + return NULL; + } + Py_INCREF(op->func_dict); + return op->func_dict; +} +static int +__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value) +{ + PyObject *tmp; + if (unlikely(value == NULL)) { + PyErr_SetString(PyExc_TypeError, + "function's dictionary may not be deleted"); + return -1; + } + if (unlikely(!PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "setting function's dictionary to a non-dict"); + return -1; + } + tmp = op->func_dict; + Py_INCREF(value); + op->func_dict = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op) +{ + Py_INCREF(op->func_globals); + return op->func_globals; +} +static PyObject * +__Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op) +{ + Py_INCREF(Py_None); + return Py_None; +} +static PyObject * +__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op) +{ + PyObject* result = (op->func_code) ? op->func_code : Py_None; + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) { + int result = 0; + PyObject *res = op->defaults_getter((PyObject *) op); + if (unlikely(!res)) + return -1; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + op->defaults_tuple = PyTuple_GET_ITEM(res, 0); + Py_INCREF(op->defaults_tuple); + op->defaults_kwdict = PyTuple_GET_ITEM(res, 1); + Py_INCREF(op->defaults_kwdict); + #else + op->defaults_tuple = PySequence_ITEM(res, 0); + if (unlikely(!op->defaults_tuple)) result = -1; + else { + op->defaults_kwdict = PySequence_ITEM(res, 1); + if (unlikely(!op->defaults_kwdict)) result = -1; + } + #endif + Py_DECREF(res); + return result; +} +static int +__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value) { + PyObject* tmp; + if (!value) { + value = Py_None; + } else if (value != Py_None && !PyTuple_Check(value)) { + PyErr_SetString(PyExc_TypeError, + "__defaults__ must be set to a tuple object"); + return -1; + } + Py_INCREF(value); + tmp = op->defaults_tuple; + op->defaults_tuple = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op) { + PyObject* result = op->defaults_tuple; + if (unlikely(!result)) { + if (op->defaults_getter) { + if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL; + result = op->defaults_tuple; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value) { + PyObject* tmp; + if (!value) { + value = Py_None; + } else if (value != Py_None && !PyDict_Check(value)) { + PyErr_SetString(PyExc_TypeError, + "__kwdefaults__ must be set to a dict object"); + return -1; + } + Py_INCREF(value); + tmp = op->defaults_kwdict; + op->defaults_kwdict = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op) { + PyObject* result = op->defaults_kwdict; + if (unlikely(!result)) { + if (op->defaults_getter) { + if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL; + result = op->defaults_kwdict; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value) { + PyObject* tmp; + if (!value || value == Py_None) { + value = NULL; + } else if (!PyDict_Check(value)) { + PyErr_SetString(PyExc_TypeError, + "__annotations__ must be set to a dict object"); + return -1; + } + Py_XINCREF(value); + tmp = op->func_annotations; + op->func_annotations = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op) { + PyObject* result = op->func_annotations; + if (unlikely(!result)) { + result = PyDict_New(); + if (unlikely(!result)) return NULL; + op->func_annotations = result; + } + Py_INCREF(result); + return result; } +static PyGetSetDef __pyx_CyFunction_getsets[] = { + {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0}, + {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0}, + {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0}, + {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0}, + {0, 0, 0, 0, 0} +}; +static PyMemberDef __pyx_CyFunction_members[] = { + {(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), PY_WRITE_RESTRICTED, 0}, + {0, 0, 0, 0, 0} +}; +static PyObject * +__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args) +{ +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromString(m->func.m_ml->ml_name); +#else + return PyString_FromString(m->func.m_ml->ml_name); #endif - -/* PyObjectSetAttrStr */ - #if CYTHON_USE_TYPE_SLOTS -static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { - PyTypeObject* tp = Py_TYPE(obj); - if (likely(tp->tp_setattro)) - return tp->tp_setattro(obj, attr_name, value); -#if PY_MAJOR_VERSION < 3 - if (likely(tp->tp_setattr)) - return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value); +} +static PyMethodDef __pyx_CyFunction_methods[] = { + {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0}, + {0, 0, 0, 0} +}; +#if PY_VERSION_HEX < 0x030500A0 +#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist) +#else +#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func.m_weakreflist) #endif - return PyObject_SetAttr(obj, attr_name, value); +static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, PyObject* qualname, + PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { + __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type); + if (op == NULL) + return NULL; + op->flags = flags; + __Pyx_CyFunction_weakreflist(op) = NULL; + op->func.m_ml = ml; + op->func.m_self = (PyObject *) op; + Py_XINCREF(closure); + op->func_closure = closure; + Py_XINCREF(module); + op->func.m_module = module; + op->func_dict = NULL; + op->func_name = NULL; + Py_INCREF(qualname); + op->func_qualname = qualname; + op->func_doc = NULL; + op->func_classobj = NULL; + op->func_globals = globals; + Py_INCREF(op->func_globals); + Py_XINCREF(code); + op->func_code = code; + op->defaults_pyobjects = 0; + op->defaults = NULL; + op->defaults_tuple = NULL; + op->defaults_kwdict = NULL; + op->defaults_getter = NULL; + op->func_annotations = NULL; + PyObject_GC_Track(op); + return (PyObject *) op; +} +static int +__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m) +{ + Py_CLEAR(m->func_closure); + Py_CLEAR(m->func.m_module); + Py_CLEAR(m->func_dict); + Py_CLEAR(m->func_name); + Py_CLEAR(m->func_qualname); + Py_CLEAR(m->func_doc); + Py_CLEAR(m->func_globals); + Py_CLEAR(m->func_code); + Py_CLEAR(m->func_classobj); + Py_CLEAR(m->defaults_tuple); + Py_CLEAR(m->defaults_kwdict); + Py_CLEAR(m->func_annotations); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_XDECREF(pydefaults[i]); + PyObject_Free(m->defaults); + m->defaults = NULL; + } + return 0; +} +static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + if (__Pyx_CyFunction_weakreflist(m) != NULL) + PyObject_ClearWeakRefs((PyObject *) m); + __Pyx_CyFunction_clear(m); + PyObject_GC_Del(m); +} +static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + PyObject_GC_UnTrack(m); + __Pyx__CyFunction_dealloc(m); +} +static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg) +{ + Py_VISIT(m->func_closure); + Py_VISIT(m->func.m_module); + Py_VISIT(m->func_dict); + Py_VISIT(m->func_name); + Py_VISIT(m->func_qualname); + Py_VISIT(m->func_doc); + Py_VISIT(m->func_globals); + Py_VISIT(m->func_code); + Py_VISIT(m->func_classobj); + Py_VISIT(m->defaults_tuple); + Py_VISIT(m->defaults_kwdict); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_VISIT(pydefaults[i]); + } + return 0; } +static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type) +{ + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) { + Py_INCREF(func); + return func; + } + if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) { + if (type == NULL) + type = (PyObject *)(Py_TYPE(obj)); + return __Pyx_PyMethod_New(func, type, (PyObject *)(Py_TYPE(type))); + } + if (obj == Py_None) + obj = NULL; + return __Pyx_PyMethod_New(func, obj, type); +} +static PyObject* +__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op) +{ +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromFormat("", + op->func_qualname, (void *)op); +#else + return PyString_FromFormat("", + PyString_AsString(op->func_qualname), (void *)op); #endif - -/* ObjectGetItem */ - #if CYTHON_USE_TYPE_SLOTS -static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) { - PyObject *runerr; - Py_ssize_t key_value; - PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence; - if (unlikely(!(m && m->sq_item))) { - PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name); +} +static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) { + PyCFunctionObject* f = (PyCFunctionObject*)func; + PyCFunction meth = f->m_ml->ml_meth; + Py_ssize_t size; + switch (f->m_ml->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) { + case METH_VARARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) + return (*meth)(self, arg); + break; + case METH_VARARGS | METH_KEYWORDS: + return (*(PyCFunctionWithKeywords)meth)(self, arg, kw); + case METH_NOARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { + size = PyTuple_GET_SIZE(arg); + if (likely(size == 0)) + return (*meth)(self, NULL); + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); + return NULL; + } + break; + case METH_O: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { + size = PyTuple_GET_SIZE(arg); + if (likely(size == 1)) { + PyObject *result, *arg0; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + arg0 = PyTuple_GET_ITEM(arg, 0); + #else + arg0 = PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL; + #endif + result = (*meth)(self, arg0); + #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) + Py_DECREF(arg0); + #endif + return result; + } + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); + return NULL; + } + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags in " + "__Pyx_CyFunction_Call. METH_OLDARGS is no " + "longer supported!"); return NULL; } - key_value = __Pyx_PyIndex_AsSsize_t(index); - if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) { - return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1); - } - if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) { - PyErr_Clear(); - PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name); - } + PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", + f->m_ml->ml_name); return NULL; } -static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) { - PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping; - if (likely(m && m->mp_subscript)) { - return m->mp_subscript(obj, key); +static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { + return __Pyx_CyFunction_CallMethod(func, ((PyCFunctionObject*)func)->m_self, arg, kw); +} +static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) { + PyObject *result; + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func; + if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { + Py_ssize_t argc; + PyObject *new_args; + PyObject *self; + argc = PyTuple_GET_SIZE(args); + new_args = PyTuple_GetSlice(args, 1, argc); + if (unlikely(!new_args)) + return NULL; + self = PyTuple_GetItem(args, 0); + if (unlikely(!self)) { + Py_DECREF(new_args); + return NULL; + } + result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); + Py_DECREF(new_args); + } else { + result = __Pyx_CyFunction_Call(func, args, kw); } - return __Pyx_PyObject_GetIndex(obj, key); + return result; } +static PyTypeObject __pyx_CyFunctionType_type = { + PyVarObject_HEAD_INIT(0, 0) + "cython_function_or_method", + sizeof(__pyx_CyFunctionObject), + 0, + (destructor) __Pyx_CyFunction_dealloc, + 0, + 0, + 0, +#if PY_MAJOR_VERSION < 3 + 0, +#else + 0, +#endif + (reprfunc) __Pyx_CyFunction_repr, + 0, + 0, + 0, + 0, + __Pyx_CyFunction_CallAsMethod, + 0, + 0, + 0, + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, + 0, + (traverseproc) __Pyx_CyFunction_traverse, + (inquiry) __Pyx_CyFunction_clear, + 0, +#if PY_VERSION_HEX < 0x030500A0 + offsetof(__pyx_CyFunctionObject, func_weakreflist), +#else + offsetof(PyCFunctionObject, m_weakreflist), +#endif + 0, + 0, + __pyx_CyFunction_methods, + __pyx_CyFunction_members, + __pyx_CyFunction_getsets, + 0, + 0, + __Pyx_CyFunction_descr_get, + 0, + offsetof(__pyx_CyFunctionObject, func_dict), + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if PY_VERSION_HEX >= 0x030400a1 + 0, #endif +}; +static int __pyx_CyFunction_init(void) { + __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type); + if (unlikely(__pyx_CyFunctionType == NULL)) { + return -1; + } + return 0; +} +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults = PyObject_Malloc(size); + if (unlikely(!m->defaults)) + return PyErr_NoMemory(); + memset(m->defaults, 0, size); + m->defaults_pyobjects = pyobjects; + return m->defaults; +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_tuple = tuple; + Py_INCREF(tuple); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_kwdict = dict; + Py_INCREF(dict); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->func_annotations = dict; + Py_INCREF(dict); +} /* PyObject_GenericGetAttrNoDict */ - #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 + #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { PyErr_Format(PyExc_AttributeError, #if PY_MAJOR_VERSION >= 3 @@ -19016,7 +22259,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj #endif /* PyObject_GenericGetAttr */ - #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 + #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) { if (unlikely(Py_TYPE(obj)->tp_dictoffset)) { return PyObject_GenericGetAttr(obj, attr_name); @@ -19026,7 +22269,7 @@ static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_nam #endif /* SetVTable */ - static int __Pyx_SetVtable(PyObject *dict, void *vtable) { + static int __Pyx_SetVtable(PyObject *dict, void *vtable) { #if PY_VERSION_HEX >= 0x02070000 PyObject *ob = PyCapsule_New(vtable, 0, 0); #else @@ -19044,7 +22287,7 @@ static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_nam } /* SetupReduce */ - static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { + static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { int ret; PyObject *name_attr; name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name_2); @@ -19120,7 +22363,7 @@ static int __Pyx_setup_reduce(PyObject* type_obj) { } /* Import */ - static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { + static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { PyObject *empty_list = 0; PyObject *module = 0; PyObject *global_dict = 0; @@ -19185,7 +22428,7 @@ static int __Pyx_setup_reduce(PyObject* type_obj) { } /* CLineInTraceback */ - #ifndef CYTHON_CLINE_IN_TRACEBACK + #ifndef CYTHON_CLINE_IN_TRACEBACK static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; @@ -19225,7 +22468,7 @@ static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_li #endif /* CodeObjectCache */ - static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { int start = 0, mid = 0, end = count - 1; if (end >= 0 && code_line > entries[end].code_line) { return count; @@ -19305,7 +22548,7 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { } /* AddTraceback */ - #include "compile.h" + #include "compile.h" #include "frameobject.h" #include "traceback.h" static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( @@ -19390,7 +22633,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPyVerify */ - #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) @@ -19412,7 +22655,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { const int neg_one = (int) -1, const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -19443,7 +22686,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -19474,7 +22717,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) { + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) { const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { @@ -19505,7 +22748,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPy */ - static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { + static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { const int neg_one = (int) -1, const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -19694,7 +22937,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPy */ - static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { + static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -19883,7 +23126,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPy */ - static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) { + static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) { const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 @@ -20024,127 +23267,1062 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } else if (sizeof(uint32_t) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(uint32_t, PY_LONG_LONG, PyLong_AsLongLong(x)) #endif - } + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + uint32_t val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (uint32_t) -1; + } + } else { + uint32_t val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (uint32_t) -1; + val = __Pyx_PyInt_As_uint32_t(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to uint32_t"); + return (uint32_t) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to uint32_t"); + return (uint32_t) -1; +} + +/* FastTypeChecks */ + #if CYTHON_COMPILING_IN_CPYTHON +static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { + while (a) { + a = a->tp_base; + if (a == b) + return 1; + } + return b == &PyBaseObject_Type; +} +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (a == b) return 1; + mro = a->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(a, b); +} +#if PY_MAJOR_VERSION == 2 +static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { + PyObject *exception, *value, *tb; + int res; + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&exception, &value, &tb); + res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + if (!res) { + res = PyObject_IsSubclass(err, exc_type2); + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + } + __Pyx_ErrRestore(exception, value, tb); + return res; +} +#else +static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { + int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; + if (!res) { + res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + } + return res; +} +#endif +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) { + if (likely(err == exc_type)) return 1; + if (likely(PyExceptionClass_Check(err))) { + return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type); + } + return PyErr_GivenExceptionMatches(err, exc_type); +} +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) { + if (likely(err == exc_type1 || err == exc_type2)) return 1; + if (likely(PyExceptionClass_Check(err))) { + return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2); + } + return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2)); +} +#endif + +/* SwapException */ + #if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if PY_VERSION_HEX >= 0x030700A2 + tmp_type = tstate->exc_state.exc_type; + tmp_value = tstate->exc_state.exc_value; + tmp_tb = tstate->exc_state.exc_traceback; + tstate->exc_state.exc_type = *type; + tstate->exc_state.exc_value = *value; + tstate->exc_state.exc_traceback = *tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = *type; + tstate->exc_value = *value; + tstate->exc_traceback = *tb; + #endif + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); + PyErr_SetExcInfo(*type, *value, *tb); + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#endif + +/* CoroutineBase */ + #include +#include +#define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom) +static int __Pyx_PyGen__FetchStopIterationValue(CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject **pvalue) { + PyObject *et, *ev, *tb; + PyObject *value = NULL; + __Pyx_ErrFetch(&et, &ev, &tb); + if (!et) { + Py_XDECREF(tb); + Py_XDECREF(ev); + Py_INCREF(Py_None); + *pvalue = Py_None; + return 0; + } + if (likely(et == PyExc_StopIteration)) { + if (!ev) { + Py_INCREF(Py_None); + value = Py_None; + } +#if PY_VERSION_HEX >= 0x030300A0 + else if (Py_TYPE(ev) == (PyTypeObject*)PyExc_StopIteration) { + value = ((PyStopIterationObject *)ev)->value; + Py_INCREF(value); + Py_DECREF(ev); + } +#endif + else if (unlikely(PyTuple_Check(ev))) { + if (PyTuple_GET_SIZE(ev) >= 1) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + value = PyTuple_GET_ITEM(ev, 0); + Py_INCREF(value); +#else + value = PySequence_ITEM(ev, 0); +#endif + } else { + Py_INCREF(Py_None); + value = Py_None; + } + Py_DECREF(ev); + } + else if (!__Pyx_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) { + value = ev; + } + if (likely(value)) { + Py_XDECREF(tb); + Py_DECREF(et); + *pvalue = value; + return 0; + } + } else if (!__Pyx_PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) { + __Pyx_ErrRestore(et, ev, tb); + return -1; + } + PyErr_NormalizeException(&et, &ev, &tb); + if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) { + __Pyx_ErrRestore(et, ev, tb); + return -1; + } + Py_XDECREF(tb); + Py_DECREF(et); +#if PY_VERSION_HEX >= 0x030300A0 + value = ((PyStopIterationObject *)ev)->value; + Py_INCREF(value); + Py_DECREF(ev); +#else + { + PyObject* args = __Pyx_PyObject_GetAttrStr(ev, __pyx_n_s_args); + Py_DECREF(ev); + if (likely(args)) { + value = PySequence_GetItem(args, 0); + Py_DECREF(args); + } + if (unlikely(!value)) { + __Pyx_ErrRestore(NULL, NULL, NULL); + Py_INCREF(Py_None); + value = Py_None; + } + } +#endif + *pvalue = value; + return 0; +} +static CYTHON_INLINE +void __Pyx_Coroutine_ExceptionClear(__pyx_CoroutineObject *self) { + PyObject *exc_type = self->exc_type; + PyObject *exc_value = self->exc_value; + PyObject *exc_traceback = self->exc_traceback; + self->exc_type = NULL; + self->exc_value = NULL; + self->exc_traceback = NULL; + Py_XDECREF(exc_type); + Py_XDECREF(exc_value); + Py_XDECREF(exc_traceback); +} +#define __Pyx_Coroutine_AlreadyRunningError(gen) (__Pyx__Coroutine_AlreadyRunningError(gen), (PyObject*)NULL) +static void __Pyx__Coroutine_AlreadyRunningError(CYTHON_UNUSED __pyx_CoroutineObject *gen) { + const char *msg; + if (0) { + #ifdef __Pyx_Coroutine_USED + } else if (__Pyx_Coroutine_Check((PyObject*)gen)) { + msg = "coroutine already executing"; + #endif + #ifdef __Pyx_AsyncGen_USED + } else if (__Pyx_AsyncGen_CheckExact((PyObject*)gen)) { + msg = "async generator already executing"; + #endif + } else { + msg = "generator already executing"; + } + PyErr_SetString(PyExc_ValueError, msg); +} +#define __Pyx_Coroutine_NotStartedError(gen) (__Pyx__Coroutine_NotStartedError(gen), (PyObject*)NULL) +static void __Pyx__Coroutine_NotStartedError(CYTHON_UNUSED PyObject *gen) { + const char *msg; + if (0) { + #ifdef __Pyx_Coroutine_USED + } else if (__Pyx_Coroutine_Check(gen)) { + msg = "can't send non-None value to a just-started coroutine"; + #endif + #ifdef __Pyx_AsyncGen_USED + } else if (__Pyx_AsyncGen_CheckExact(gen)) { + msg = "can't send non-None value to a just-started async generator"; + #endif + } else { + msg = "can't send non-None value to a just-started generator"; + } + PyErr_SetString(PyExc_TypeError, msg); +} +#define __Pyx_Coroutine_AlreadyTerminatedError(gen, value, closing) (__Pyx__Coroutine_AlreadyTerminatedError(gen, value, closing), (PyObject*)NULL) +static void __Pyx__Coroutine_AlreadyTerminatedError(CYTHON_UNUSED PyObject *gen, PyObject *value, CYTHON_UNUSED int closing) { + #ifdef __Pyx_Coroutine_USED + if (!closing && __Pyx_Coroutine_Check(gen)) { + PyErr_SetString(PyExc_RuntimeError, "cannot reuse already awaited coroutine"); + } else + #endif + if (value) { + #ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(gen)) + PyErr_SetNone(__Pyx_PyExc_StopAsyncIteration); + else + #endif + PyErr_SetNone(PyExc_StopIteration); + } +} +static +PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value, int closing) { + __Pyx_PyThreadState_declare + PyThreadState *tstate; + PyObject *retval; + assert(!self->is_running); + if (unlikely(self->resume_label == 0)) { + if (unlikely(value && value != Py_None)) { + return __Pyx_Coroutine_NotStartedError((PyObject*)self); + } + } + if (unlikely(self->resume_label == -1)) { + return __Pyx_Coroutine_AlreadyTerminatedError((PyObject*)self, value, closing); + } +#if CYTHON_FAST_THREAD_STATE + __Pyx_PyThreadState_assign + tstate = __pyx_tstate; +#else + tstate = __Pyx_PyThreadState_Current; +#endif + if (self->exc_type) { +#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON +#else + if (self->exc_traceback) { + PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback; + PyFrameObject *f = tb->tb_frame; + Py_XINCREF(tstate->frame); + assert(f->f_back == NULL); + f->f_back = tstate->frame; + } +#endif + __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, + &self->exc_traceback); + } else { + __Pyx_Coroutine_ExceptionClear(self); + __Pyx_ExceptionSave(&self->exc_type, &self->exc_value, &self->exc_traceback); + } + self->is_running = 1; + retval = self->body((PyObject *) self, tstate, value); + self->is_running = 0; + return retval; +} +static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__pyx_CoroutineObject *self) { + if (likely(self->exc_traceback)) { +#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON +#else + PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback; + PyFrameObject *f = tb->tb_frame; + Py_CLEAR(f->f_back); +#endif + } +} +static CYTHON_INLINE +PyObject *__Pyx_Coroutine_MethodReturn(CYTHON_UNUSED PyObject* gen, PyObject *retval) { + if (unlikely(!retval)) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (!__Pyx_PyErr_Occurred()) { + PyObject *exc = PyExc_StopIteration; + #ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(gen)) + exc = __Pyx_PyExc_StopAsyncIteration; + #endif + __Pyx_PyErr_SetNone(exc); } + } + return retval; +} +static CYTHON_INLINE +PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) { + PyObject *ret; + PyObject *val = NULL; + __Pyx_Coroutine_Undelegate(gen); + __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, &val); + ret = __Pyx_Coroutine_SendEx(gen, val, 0); + Py_XDECREF(val); + return ret; +} +static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) { + PyObject *retval; + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(gen->is_running)) + return __Pyx_Coroutine_AlreadyRunningError(gen); + if (yf) { + PyObject *ret; + gen->is_running = 1; + #ifdef __Pyx_Generator_USED + if (__Pyx_Generator_CheckExact(yf)) { + ret = __Pyx_Coroutine_Send(yf, value); + } else + #endif + #ifdef __Pyx_Coroutine_USED + if (__Pyx_Coroutine_Check(yf)) { + ret = __Pyx_Coroutine_Send(yf, value); + } else + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_PyAsyncGenASend_CheckExact(yf)) { + ret = __Pyx_async_gen_asend_send(yf, value); + } else + #endif + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) + if (PyGen_CheckExact(yf)) { + ret = _PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value); + } else + #endif + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03050000 && defined(PyCoro_CheckExact) && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) + if (PyCoro_CheckExact(yf)) { + ret = _PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value); + } else + #endif { -#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) - PyErr_SetString(PyExc_RuntimeError, - "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); + if (value == Py_None) + ret = Py_TYPE(yf)->tp_iternext(yf); + else + ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value); + } + gen->is_running = 0; + if (likely(ret)) { + return ret; + } + retval = __Pyx_Coroutine_FinishDelegation(gen); + } else { + retval = __Pyx_Coroutine_SendEx(gen, value, 0); + } + return __Pyx_Coroutine_MethodReturn(self, retval); +} +static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) { + PyObject *retval = NULL; + int err = 0; + #ifdef __Pyx_Generator_USED + if (__Pyx_Generator_CheckExact(yf)) { + retval = __Pyx_Coroutine_Close(yf); + if (!retval) + return -1; + } else + #endif + #ifdef __Pyx_Coroutine_USED + if (__Pyx_Coroutine_Check(yf)) { + retval = __Pyx_Coroutine_Close(yf); + if (!retval) + return -1; + } else + if (__Pyx_CoroutineAwait_CheckExact(yf)) { + retval = __Pyx_CoroutineAwait_Close((__pyx_CoroutineAwaitObject*)yf); + if (!retval) + return -1; + } else + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_PyAsyncGenASend_CheckExact(yf)) { + retval = __Pyx_async_gen_asend_close(yf, NULL); + } else + if (__pyx_PyAsyncGenAThrow_CheckExact(yf)) { + retval = __Pyx_async_gen_athrow_close(yf, NULL); + } else + #endif + { + PyObject *meth; + gen->is_running = 1; + meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_close); + if (unlikely(!meth)) { + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_WriteUnraisable(yf); + } + PyErr_Clear(); + } else { + retval = PyObject_CallFunction(meth, NULL); + Py_DECREF(meth); + if (!retval) + err = -1; + } + gen->is_running = 0; + } + Py_XDECREF(retval); + return err; +} +static PyObject *__Pyx_Generator_Next(PyObject *self) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(gen->is_running)) + return __Pyx_Coroutine_AlreadyRunningError(gen); + if (yf) { + PyObject *ret; + gen->is_running = 1; + #ifdef __Pyx_Generator_USED + if (__Pyx_Generator_CheckExact(yf)) { + ret = __Pyx_Generator_Next(yf); + } else + #endif + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) + if (PyGen_CheckExact(yf)) { + ret = _PyGen_Send((PyGenObject*)yf, NULL); + } else + #endif + #ifdef __Pyx_Coroutine_USED + if (__Pyx_Coroutine_Check(yf)) { + ret = __Pyx_Coroutine_Send(yf, Py_None); + } else + #endif + ret = Py_TYPE(yf)->tp_iternext(yf); + gen->is_running = 0; + if (likely(ret)) { + return ret; + } + return __Pyx_Coroutine_FinishDelegation(gen); + } + return __Pyx_Coroutine_SendEx(gen, Py_None, 0); +} +static PyObject *__Pyx_Coroutine_Close(PyObject *self) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + PyObject *retval, *raised_exception; + PyObject *yf = gen->yieldfrom; + int err = 0; + if (unlikely(gen->is_running)) + return __Pyx_Coroutine_AlreadyRunningError(gen); + if (yf) { + Py_INCREF(yf); + err = __Pyx_Coroutine_CloseIter(gen, yf); + __Pyx_Coroutine_Undelegate(gen); + Py_DECREF(yf); + } + if (err == 0) + PyErr_SetNone(PyExc_GeneratorExit); + retval = __Pyx_Coroutine_SendEx(gen, NULL, 1); + if (unlikely(retval)) { + const char *msg; + Py_DECREF(retval); + if ((0)) { + #ifdef __Pyx_Coroutine_USED + } else if (__Pyx_Coroutine_Check(self)) { + msg = "coroutine ignored GeneratorExit"; + #endif + #ifdef __Pyx_AsyncGen_USED + } else if (__Pyx_AsyncGen_CheckExact(self)) { +#if PY_VERSION_HEX < 0x03060000 + msg = "async generator ignored GeneratorExit - might require Python 3.6+ finalisation (PEP 525)"; #else - uint32_t val; - PyObject *v = __Pyx_PyNumber_IntOrLong(x); - #if PY_MAJOR_VERSION < 3 - if (likely(v) && !PyLong_Check(v)) { - PyObject *tmp = v; - v = PyNumber_Long(tmp); - Py_DECREF(tmp); + msg = "async generator ignored GeneratorExit"; +#endif + #endif + } else { + msg = "generator ignored GeneratorExit"; + } + PyErr_SetString(PyExc_RuntimeError, msg); + return NULL; + } + raised_exception = PyErr_Occurred(); + if (likely(!raised_exception || __Pyx_PyErr_GivenExceptionMatches2(raised_exception, PyExc_GeneratorExit, PyExc_StopIteration))) { + if (raised_exception) PyErr_Clear(); + Py_INCREF(Py_None); + return Py_None; + } + return NULL; +} +static PyObject *__Pyx__Coroutine_Throw(PyObject *self, PyObject *typ, PyObject *val, PyObject *tb, + PyObject *args, int close_on_genexit) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(gen->is_running)) + return __Pyx_Coroutine_AlreadyRunningError(gen); + if (yf) { + PyObject *ret; + Py_INCREF(yf); + if (__Pyx_PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && close_on_genexit) { + int err = __Pyx_Coroutine_CloseIter(gen, yf); + Py_DECREF(yf); + __Pyx_Coroutine_Undelegate(gen); + if (err < 0) + return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0)); + goto throw_here; + } + gen->is_running = 1; + if (0 + #ifdef __Pyx_Generator_USED + || __Pyx_Generator_CheckExact(yf) + #endif + #ifdef __Pyx_Coroutine_USED + || __Pyx_Coroutine_Check(yf) + #endif + ) { + ret = __Pyx__Coroutine_Throw(yf, typ, val, tb, args, close_on_genexit); + #ifdef __Pyx_Coroutine_USED + } else if (__Pyx_CoroutineAwait_CheckExact(yf)) { + ret = __Pyx__Coroutine_Throw(((__pyx_CoroutineAwaitObject*)yf)->coroutine, typ, val, tb, args, close_on_genexit); + #endif + } else { + PyObject *meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_throw); + if (unlikely(!meth)) { + Py_DECREF(yf); + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { + gen->is_running = 0; + return NULL; + } + PyErr_Clear(); + __Pyx_Coroutine_Undelegate(gen); + gen->is_running = 0; + goto throw_here; } - #endif - if (likely(v)) { - int one = 1; int is_little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - int ret = _PyLong_AsByteArray((PyLongObject *)v, - bytes, sizeof(val), - is_little, !is_unsigned); - Py_DECREF(v); - if (likely(!ret)) - return val; + if (likely(args)) { + ret = PyObject_CallObject(meth, args); + } else { + ret = PyObject_CallFunctionObjArgs(meth, typ, val, tb, NULL); } -#endif - return (uint32_t) -1; + Py_DECREF(meth); } - } else { - uint32_t val; - PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); - if (!tmp) return (uint32_t) -1; - val = __Pyx_PyInt_As_uint32_t(tmp); - Py_DECREF(tmp); - return val; + gen->is_running = 0; + Py_DECREF(yf); + if (!ret) { + ret = __Pyx_Coroutine_FinishDelegation(gen); + } + return __Pyx_Coroutine_MethodReturn(self, ret); } -raise_overflow: - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to uint32_t"); - return (uint32_t) -1; -raise_neg_overflow: - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to uint32_t"); - return (uint32_t) -1; +throw_here: + __Pyx_Raise(typ, val, tb, NULL); + return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0)); } - -/* FastTypeChecks */ - #if CYTHON_COMPILING_IN_CPYTHON -static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { - while (a) { - a = a->tp_base; - if (a == b) - return 1; +static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) { + PyObject *typ; + PyObject *val = NULL; + PyObject *tb = NULL; + if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb)) + return NULL; + return __Pyx__Coroutine_Throw(self, typ, val, tb, args, 1); +} +static int __Pyx_Coroutine_traverse(__pyx_CoroutineObject *gen, visitproc visit, void *arg) { + Py_VISIT(gen->closure); + Py_VISIT(gen->classobj); + Py_VISIT(gen->yieldfrom); + Py_VISIT(gen->exc_type); + Py_VISIT(gen->exc_value); + Py_VISIT(gen->exc_traceback); + return 0; +} +static int __Pyx_Coroutine_clear(PyObject *self) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + Py_CLEAR(gen->closure); + Py_CLEAR(gen->classobj); + Py_CLEAR(gen->yieldfrom); + Py_CLEAR(gen->exc_type); + Py_CLEAR(gen->exc_value); + Py_CLEAR(gen->exc_traceback); +#ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(self)) { + Py_CLEAR(((__pyx_PyAsyncGenObject*)gen)->ag_finalizer); } - return b == &PyBaseObject_Type; +#endif + Py_CLEAR(gen->gi_code); + Py_CLEAR(gen->gi_name); + Py_CLEAR(gen->gi_qualname); + Py_CLEAR(gen->gi_modulename); + return 0; } -static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { - PyObject *mro; - if (a == b) return 1; - mro = a->tp_mro; - if (likely(mro)) { - Py_ssize_t i, n; - n = PyTuple_GET_SIZE(mro); - for (i = 0; i < n; i++) { - if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) - return 1; +static void __Pyx_Coroutine_dealloc(PyObject *self) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + PyObject_GC_UnTrack(gen); + if (gen->gi_weakreflist != NULL) + PyObject_ClearWeakRefs(self); + if (gen->resume_label >= 0) { + PyObject_GC_Track(self); +#if PY_VERSION_HEX >= 0x030400a1 && CYTHON_USE_TP_FINALIZE + if (PyObject_CallFinalizerFromDealloc(self)) +#else + Py_TYPE(gen)->tp_del(self); + if (self->ob_refcnt > 0) +#endif + { + return; } - return 0; + PyObject_GC_UnTrack(self); } - return __Pyx_InBases(a, b); +#ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(self)) { + /* We have to handle this case for asynchronous generators + right here, because this code has to be between UNTRACK + and GC_Del. */ + Py_CLEAR(((__pyx_PyAsyncGenObject*)self)->ag_finalizer); + } +#endif + __Pyx_Coroutine_clear(self); + PyObject_GC_Del(gen); } -#if PY_MAJOR_VERSION == 2 -static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { - PyObject *exception, *value, *tb; - int res; +static void __Pyx_Coroutine_del(PyObject *self) { + PyObject *error_type, *error_value, *error_traceback; + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; __Pyx_PyThreadState_declare + if (gen->resume_label < 0) { + return; + } +#if !CYTHON_USE_TP_FINALIZE + assert(self->ob_refcnt == 0); + self->ob_refcnt = 1; +#endif __Pyx_PyThreadState_assign - __Pyx_ErrFetch(&exception, &value, &tb); - res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; - if (unlikely(res == -1)) { - PyErr_WriteUnraisable(err); - res = 0; + __Pyx_ErrFetch(&error_type, &error_value, &error_traceback); +#ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(self)) { + __pyx_PyAsyncGenObject *agen = (__pyx_PyAsyncGenObject*)self; + PyObject *finalizer = agen->ag_finalizer; + if (finalizer && !agen->ag_closed) { + PyObject *res = __Pyx_PyObject_CallOneArg(finalizer, self); + if (unlikely(!res)) { + PyErr_WriteUnraisable(self); + } else { + Py_DECREF(res); + } + __Pyx_ErrRestore(error_type, error_value, error_traceback); + return; + } } - if (!res) { - res = PyObject_IsSubclass(err, exc_type2); - if (unlikely(res == -1)) { - PyErr_WriteUnraisable(err); - res = 0; +#endif + if (unlikely(gen->resume_label == 0 && !error_value)) { +#ifdef __Pyx_Coroutine_USED +#ifdef __Pyx_Generator_USED + if (!__Pyx_Generator_CheckExact(self)) +#endif + { + PyObject_GC_UnTrack(self); +#if PY_MAJOR_VERSION >= 3 || defined(PyErr_WarnFormat) + if (unlikely(PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "coroutine '%.50S' was never awaited", gen->gi_qualname) < 0)) + PyErr_WriteUnraisable(self); +#else + {PyObject *msg; + char *cmsg; + #if CYTHON_COMPILING_IN_PYPY + msg = NULL; + cmsg = (char*) "coroutine was never awaited"; + #else + char *cname; + PyObject *qualname; + qualname = gen->gi_qualname; + cname = PyString_AS_STRING(qualname); + msg = PyString_FromFormat("coroutine '%.50s' was never awaited", cname); + if (unlikely(!msg)) { + PyErr_Clear(); + cmsg = (char*) "coroutine was never awaited"; + } else { + cmsg = PyString_AS_STRING(msg); + } + #endif + if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, cmsg, 1) < 0)) + PyErr_WriteUnraisable(self); + Py_XDECREF(msg);} +#endif + PyObject_GC_Track(self); + } +#endif + } else { + PyObject *res = __Pyx_Coroutine_Close(self); + if (unlikely(!res)) { + if (PyErr_Occurred()) + PyErr_WriteUnraisable(self); + } else { + Py_DECREF(res); } } - __Pyx_ErrRestore(exception, value, tb); - return res; + __Pyx_ErrRestore(error_type, error_value, error_traceback); +#if !CYTHON_USE_TP_FINALIZE + assert(self->ob_refcnt > 0); + if (--self->ob_refcnt == 0) { + return; + } + { + Py_ssize_t refcnt = self->ob_refcnt; + _Py_NewReference(self); + self->ob_refcnt = refcnt; + } +#if CYTHON_COMPILING_IN_CPYTHON + assert(PyType_IS_GC(self->ob_type) && + _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED); + _Py_DEC_REFTOTAL; +#endif +#ifdef COUNT_ALLOCS + --Py_TYPE(self)->tp_frees; + --Py_TYPE(self)->tp_allocs; +#endif +#endif +} +static PyObject * +__Pyx_Coroutine_get_name(__pyx_CoroutineObject *self) +{ + PyObject *name = self->gi_name; + if (unlikely(!name)) name = Py_None; + Py_INCREF(name); + return name; } +static int +__Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value) +{ + PyObject *tmp; +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) { #else -static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { - int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; - if (!res) { - res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + if (unlikely(value == NULL || !PyString_Check(value))) { +#endif + PyErr_SetString(PyExc_TypeError, + "__name__ must be set to a string object"); + return -1; } - return res; + tmp = self->gi_name; + Py_INCREF(value); + self->gi_name = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self) +{ + PyObject *name = self->gi_qualname; + if (unlikely(!name)) name = Py_None; + Py_INCREF(name); + return name; } +static int +__Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value) +{ + PyObject *tmp; +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) { +#else + if (unlikely(value == NULL || !PyString_Check(value))) { #endif -static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) { - if (likely(err == exc_type)) return 1; - if (likely(PyExceptionClass_Check(err))) { - return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type); + PyErr_SetString(PyExc_TypeError, + "__qualname__ must be set to a string object"); + return -1; } - return PyErr_GivenExceptionMatches(err, exc_type); + tmp = self->gi_qualname; + Py_INCREF(value); + self->gi_qualname = value; + Py_XDECREF(tmp); + return 0; } -static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) { - if (likely(err == exc_type1 || err == exc_type2)) return 1; - if (likely(PyExceptionClass_Check(err))) { - return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2); +static __pyx_CoroutineObject *__Pyx__Coroutine_New( + PyTypeObject* type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, + PyObject *name, PyObject *qualname, PyObject *module_name) { + __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type); + if (unlikely(!gen)) + return NULL; + return __Pyx__Coroutine_NewInit(gen, body, code, closure, name, qualname, module_name); +} +static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit( + __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, + PyObject *name, PyObject *qualname, PyObject *module_name) { + gen->body = body; + gen->closure = closure; + Py_XINCREF(closure); + gen->is_running = 0; + gen->resume_label = 0; + gen->classobj = NULL; + gen->yieldfrom = NULL; + gen->exc_type = NULL; + gen->exc_value = NULL; + gen->exc_traceback = NULL; + gen->gi_weakreflist = NULL; + Py_XINCREF(qualname); + gen->gi_qualname = qualname; + Py_XINCREF(name); + gen->gi_name = name; + Py_XINCREF(module_name); + gen->gi_modulename = module_name; + Py_XINCREF(code); + gen->gi_code = code; + PyObject_GC_Track(gen); + return gen; +} + +/* PatchModuleWithCoroutine */ + static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) { +#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + int result; + PyObject *globals, *result_obj; + globals = PyDict_New(); if (unlikely(!globals)) goto ignore; + result = PyDict_SetItemString(globals, "_cython_coroutine_type", + #ifdef __Pyx_Coroutine_USED + (PyObject*)__pyx_CoroutineType); + #else + Py_None); + #endif + if (unlikely(result < 0)) goto ignore; + result = PyDict_SetItemString(globals, "_cython_generator_type", + #ifdef __Pyx_Generator_USED + (PyObject*)__pyx_GeneratorType); + #else + Py_None); + #endif + if (unlikely(result < 0)) goto ignore; + if (unlikely(PyDict_SetItemString(globals, "_module", module) < 0)) goto ignore; + if (unlikely(PyDict_SetItemString(globals, "__builtins__", __pyx_b) < 0)) goto ignore; + result_obj = PyRun_String(py_code, Py_file_input, globals, globals); + if (unlikely(!result_obj)) goto ignore; + Py_DECREF(result_obj); + Py_DECREF(globals); + return module; +ignore: + Py_XDECREF(globals); + PyErr_WriteUnraisable(module); + if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch module with custom type", 1) < 0)) { + Py_DECREF(module); + module = NULL; } - return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2)); +#else + py_code++; +#endif + return module; +} + +/* PatchGeneratorABC */ + #ifndef CYTHON_REGISTER_ABCS +#define CYTHON_REGISTER_ABCS 1 +#endif +#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) +static PyObject* __Pyx_patch_abc_module(PyObject *module); +static PyObject* __Pyx_patch_abc_module(PyObject *module) { + module = __Pyx_Coroutine_patch_module( + module, "" +"if _cython_generator_type is not None:\n" +" try: Generator = _module.Generator\n" +" except AttributeError: pass\n" +" else: Generator.register(_cython_generator_type)\n" +"if _cython_coroutine_type is not None:\n" +" try: Coroutine = _module.Coroutine\n" +" except AttributeError: pass\n" +" else: Coroutine.register(_cython_coroutine_type)\n" + ); + return module; +} +#endif +static int __Pyx_patch_abc(void) { +#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + static int abc_patched = 0; + if (CYTHON_REGISTER_ABCS && !abc_patched) { + PyObject *module; + module = PyImport_ImportModule((PY_MAJOR_VERSION >= 3) ? "collections.abc" : "collections"); + if (!module) { + PyErr_WriteUnraisable(NULL); + if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, + ((PY_MAJOR_VERSION >= 3) ? + "Cython module failed to register with collections.abc module" : + "Cython module failed to register with collections module"), 1) < 0)) { + return -1; + } + } else { + module = __Pyx_patch_abc_module(module); + abc_patched = 1; + if (unlikely(!module)) + return -1; + Py_DECREF(module); + } + module = PyImport_ImportModule("backports_abc"); + if (module) { + module = __Pyx_patch_abc_module(module); + Py_XDECREF(module); + } + if (!module) { + PyErr_Clear(); + } + } +#else + if ((0)) __Pyx_Coroutine_patch_module(NULL, NULL); +#endif + return 0; } + +/* Generator */ + static PyMethodDef __pyx_Generator_methods[] = { + {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O, + (char*) PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")}, + {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS, + (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in generator,\nreturn next yielded value or raise StopIteration.")}, + {"close", (PyCFunction) __Pyx_Coroutine_Close, METH_NOARGS, + (char*) PyDoc_STR("close() -> raise GeneratorExit inside generator.")}, + {0, 0, 0, 0} +}; +static PyMemberDef __pyx_Generator_memberlist[] = { + {(char *) "gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL}, + {(char*) "gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY, + (char*) PyDoc_STR("object being iterated by 'yield from', or None")}, + {(char*) "gi_code", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_code), READONLY, NULL}, + {0, 0, 0, 0, 0} +}; +static PyGetSetDef __pyx_Generator_getsets[] = { + {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name, + (char*) PyDoc_STR("name of the generator"), 0}, + {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname, + (char*) PyDoc_STR("qualified name of the generator"), 0}, + {0, 0, 0, 0, 0} +}; +static PyTypeObject __pyx_GeneratorType_type = { + PyVarObject_HEAD_INIT(0, 0) + "generator", + sizeof(__pyx_CoroutineObject), + 0, + (destructor) __Pyx_Coroutine_dealloc, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, + 0, + (traverseproc) __Pyx_Coroutine_traverse, + 0, + 0, + offsetof(__pyx_CoroutineObject, gi_weakreflist), + 0, + (iternextfunc) __Pyx_Generator_Next, + __pyx_Generator_methods, + __pyx_Generator_memberlist, + __pyx_Generator_getsets, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if CYTHON_USE_TP_FINALIZE + 0, +#else + __Pyx_Coroutine_del, #endif + 0, +#if CYTHON_USE_TP_FINALIZE + __Pyx_Coroutine_del, +#elif PY_VERSION_HEX >= 0x030400a1 + 0, +#endif +}; +static int __pyx_Generator_init(void) { + __pyx_GeneratorType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter; + __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type); + if (unlikely(!__pyx_GeneratorType)) { + return -1; + } + return 0; +} /* CheckBinaryVersion */ - static int __Pyx_check_binary_version(void) { + static int __Pyx_check_binary_version(void) { char ctversion[4], rtversion[4]; PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); @@ -20160,7 +24338,7 @@ static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObj } /* ModuleImport */ - #ifndef __PYX_HAVE_RT_ImportModule + #ifndef __PYX_HAVE_RT_ImportModule #define __PYX_HAVE_RT_ImportModule static PyObject *__Pyx_ImportModule(const char *name) { PyObject *py_name = 0; @@ -20178,7 +24356,7 @@ static PyObject *__Pyx_ImportModule(const char *name) { #endif /* TypeImport */ - #ifndef __PYX_HAVE_RT_ImportType + #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict) @@ -20243,7 +24421,7 @@ static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class #endif /* FunctionImport */ - #ifndef __PYX_HAVE_RT_ImportFunction + #ifndef __PYX_HAVE_RT_ImportFunction #define __PYX_HAVE_RT_ImportFunction static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) { PyObject *d = 0; @@ -20297,7 +24475,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (** #endif /* InitStrings */ - static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { diff --git a/pysam/libctabixproxies.pxd b/pysam/libctabixproxies.pxd index 5317b813f..edea70173 100644 --- a/pysam/libctabixproxies.pxd +++ b/pysam/libctabixproxies.pxd @@ -25,19 +25,21 @@ cdef class TupleProxy: cdef copy(self, char * buffer, size_t nbytes, bint reset=*) cdef update(self, char * buffer, size_t nbytes) -cdef class GTFProxy(TupleProxy) : - cdef: - char * _attributes - cdef bint hasOwnAttributes +cdef class NamedTupleProxy(TupleProxy): + pass + +cdef class GTFProxy(NamedTupleProxy): + cdef object attribute_dict cpdef int getMaxFields(self) cpdef int getMinFields(self) - cdef char * getAttributes(self) -cdef class NamedTupleProxy(TupleProxy): + +cdef class GFF3Proxy(GTFProxy): pass + cdef class BedProxy(NamedTupleProxy): cdef: diff --git a/pysam/libctabixproxies.pyx b/pysam/libctabixproxies.pyx index 9a8a6789b..f95425ada 100644 --- a/pysam/libctabixproxies.pyx +++ b/pysam/libctabixproxies.pyx @@ -9,19 +9,23 @@ from pysam.libcutils cimport force_bytes, force_str, charptr_to_str from pysam.libcutils cimport encode_filename, from_string_and_size import collections +import copy + cdef char *StrOrEmpty(char * buffer): if buffer == NULL: return "" else: return buffer + cdef int isNew(char * p, char * buffer, size_t nbytes): """return True if `p` is located within `buffer` of size `nbytes` """ if p == NULL: return 0 - return not (buffer <= p < buffer + nbytes) + + return not (buffer <= p <= buffer + nbytes) cdef class TupleProxy: @@ -230,7 +234,7 @@ cdef class TupleProxy: self.nfields = field if self.nfields < self.getMinFields(): raise ValueError( - "parsing error: fewer that %i fields in line: %s" % + "parsing error: fewer than %i fields in line: %s" % (self.getMinFields(), buffer)) def _getindex(self, int index): @@ -268,7 +272,7 @@ cdef class TupleProxy: raise IndexError("list index out of range") if isNew(self.fields[idx], self.data, self.nbytes): - free(self.fields[idx] ) + free(self.fields[idx]) self.is_modified = 1 @@ -350,7 +354,62 @@ def quote(v): return str(v) -cdef class GTFProxy(TupleProxy): +cdef class NamedTupleProxy(TupleProxy): + + map_key2field = {} + + def __setattr__(self, key, value): + '''set attribute.''' + cdef int idx + idx, f = self.map_key2field[key] + if self.nfields < idx: + raise KeyError("field %s not set" % key) + TupleProxy.__setitem__(self, idx, str(value)) + + def __getattr__(self, key): + cdef int idx + idx, f = self.map_key2field[key] + if self.nfields < idx: + raise KeyError("field %s not set" % key) + if f == str: + return force_str(self.fields[idx], + self.encoding) + return f(self.fields[idx]) + + +cdef dot_or_float(v): + if v == "" or v == b".": + return None + else: + try: + return int(v) + except ValueError: + return float(v) + + +cdef dot_or_int(v): + if v == "" or v == b".": + return None + else: + return int(v) + + +cdef dot_or_str(v): + if v == "" or v == b".": + return None + else: + return force_str(v) + + +cdef int from1based(v): + return atoi(v) - 1 + + +cdef str to1based(int v): + return str(v + 1) + + +cdef class GTFProxy(NamedTupleProxy): '''Proxy class for access to GTF fields. This class represents a GTF entry for fast read-access. @@ -361,18 +420,29 @@ cdef class GTFProxy(TupleProxy): The only exception is the attributes field when set from a dictionary - this field will manage its own memory. + ''' + separator = "; " + # first value is field index, the tuple contains conversion + # functions for getting (converting internal string representation + # to pythonic value) and setting (converting pythonic value to + # interval string representation) + map_key2field = { + 'contig' : (0, (str, str)), + 'source' : (1, (dot_or_str, str)), + 'feature': (2, (dot_or_str, str)), + 'start' : (3, (from1based, to1based)), + 'end' : (4, (int, int)), + 'score' : (5, (dot_or_float, toDot)), + 'strand' : (6, (dot_or_str, str)), + 'frame' : (7, (dot_or_int, toDot)), + 'attributes': (8, (str, str))} + def __cinit__(self): # automatically calls TupleProxy.__cinit__ - self.hasOwnAttributes = False - self._attributes = NULL - - def __dealloc__(self): - # automatically calls TupleProxy.__dealloc__ - if self.hasOwnAttributes: - free(self._attributes) - + self.attribute_dict = None + cpdef int getMinFields(self): '''return minimum number of fields.''' return 9 @@ -381,182 +451,29 @@ cdef class GTFProxy(TupleProxy): '''return max number of fields.''' return 9 - property contig: - '''contig of feature.''' - def __get__(self): - return self._getindex(0) - def __set__(self, value): - self._setindex(0, value) - - property source: - '''feature source.''' - def __get__(self): - return self._getindex(1) - def __set__(self, value): - if value is None: - value = "." - self._setindex(1, value) - - property feature: - '''feature name.''' - def __get__(self): - return self._getindex(2) - def __set__(self, value): - if value is None: - value = "." - self._setindex(2, value) - - property start: - '''feature start (in 0-based open/closed coordinates).''' - def __get__(self ): - return int( self._getindex(3)) - 1 - def __set__(self, value ): - self._setindex(3, str(value+1)) - - property end: - '''feature end (in 0-based open/closed coordinates).''' - def __get__(self): - return int(self._getindex(4)) - def __set__(self, value): - self._setindex(4, str(value)) - - property score: - '''feature score.''' - def __get__(self): - v = self._getindex(5) - if v == "" or v[0] == '.': - return None - else: - return float(v) - - def __set__(self, value): - if value is None: - value = "." - self._setindex(5, str(value)) - - property strand: - '''feature strand.''' - def __get__(self): - return self._getindex(6) - def __set__(self, value ): - if value is None: - value = "." - self._setindex(6, value) - - property frame: - '''feature frame.''' - def __get__(self): - v = self._getindex(7) - if v == "" or v[0] == '.': - return v - else: - return int(v) - - def __set__(self, value): - if value is None: - value = "." - self._setindex(7, str(value)) - - property attributes: - '''feature attributes (as a string).''' - def __get__(self): - if self.hasOwnAttributes: - return force_str(self._attributes) - else: - return force_str(self._getindex(8)) - def __set__( self, value): - if self.hasOwnAttributes: - free(self._attributes) - self._attributes = NULL - self.hasOwnAttributes = False - self._setindex(8, value) - - cdef char * getAttributes(self): - '''return pointer to attributes.''' - cdef char * attributes - if self.hasOwnAttributes: - attributes = self._attributes - else: - attributes = self.fields[8] - if attributes == NULL: - raise KeyError("no attributes defined GTF entry") - return attributes - - def asDict(self): + def to_dict(self): """parse attributes - return as dict - """ - - # remove comments - attributes = self.attributes - - # separate into fields - # Fields might contain a ";", for example in ENSEMBL GTF file - # for mouse, v78: - # ...; transcript_name "TXNRD2;-001"; .... - # The current heuristic is to split on a semicolon followed by a - # space, see also http://mblab.wustl.edu/GTF22.html - - # Remove white space to prevent a last empty field. - fields = [x.strip() for x in attributes.strip().split("; ")] - - result = collections.OrderedDict() - - for f in fields: - - # strip semicolon (GTF files without a space after the last semicolon) - if f.endswith(";"): - f = f[:-1] - - # split at most once in order to avoid separating - # multi-word values - d = [x.strip() for x in f.split(" ", 1)] - n,v = d[0], d[1] - if len(d) > 2: - v = d[1:] - - if v[0] == '"' and v[-1] == '"': - v = v[1:-1] - else: - ## try to convert to a value - try: - v = float(v) - v = int(v) - except ValueError: - pass - except TypeError: - pass + The dictionary can be modified to update attributes. + """ + if not self.attribute_dict: + self.attribute_dict = self.attribute_string2dict( + self.attributes) + self.is_modified = True + return self.attribute_dict + + def as_dict(self): + """deprecated: use :meth:`to_dict` + """ + return self.to_dict() - result[n] = v - - return result - - def fromDict(self, d): + def from_dict(self, d): '''set attributes from a dictionary.''' - cdef char * p - cdef int l - - # clean up if this field is set twice - if self.hasOwnAttributes: - free(self._attributes) - - aa = [] - for k,v in d.items(): - if isinstance(v, str): - aa.append( '%s "%s"' % (k,v) ) - else: - aa.append( '%s %s' % (k,str(v)) ) - - a = force_bytes("; ".join(aa) + ";") - p = a - l = len(a) - self._attributes = calloc(l + 1, sizeof(char)) - if self._attributes == NULL: - raise ValueError("out of memory") - memcpy(self._attributes, p, l) - - self.hasOwnAttributes = True - self.is_modified = True + self.attribute_dict = None + attribute_string = force_bytes( + self.attribute_dict2string(d), + self.encoding) + self._setindex(8, attribute_string) def __str__(self): cdef char * cpy @@ -565,9 +482,9 @@ cdef class GTFProxy(TupleProxy): if self.is_modified: return "\t".join( (self.contig, - self.source, - self.feature, - str(self.start+1), + toDot(self.source), + toDot(self.feature), + str(self.start + 1), str(self.end), toDot(self.score), toDot(self.strand), @@ -589,73 +506,27 @@ cdef class GTFProxy(TupleProxy): def keys(self): '''return a list of attributes defined in this entry.''' - r = self.attributes - return [x.strip().split(" ")[0] - # separator is ';' followed by space - for x in r.split("; ") if x.strip() != ''] + if not self.attribute_dict: + self.attribute_dict = self.attribute_string2dict( + self.attributes) + return self.attribute_dict.keys() def __getitem__(self, key): return self.__getattr__(key) - def __getattr__(self, item): - """Generic lookup of attribute from GFF/GTF attributes - Only called if there *isn't* an attribute with this name - """ - cdef char * start - cdef char * query - cdef char * cpy - cdef char * end - cdef int l - - # - # important to use the getAttributes function. - # Using the self.attributes property to access - # the attributes caused a hard-to-trace bug - # in which fields in the attribute string were - # set to 0. - # Running through valgrind complained that - # memory was accessed in the memory field - # that has been released. It is not clear - # why this happened and might be a cython bug - # (Version 0.16). The valgrind warnings - # disappeard after accessing the C data structures - # directly and so did the bug. - cdef char * attributes = self.getAttributes() - if attributes == NULL: - raise KeyError("key %s not found, no attributes" % item) - - # add space in order to make sure - # to not pick up a field that is a prefix of another field - r = force_bytes(item + " ") - query = r - start = strstr(attributes, query) - - if start == NULL: - raise AttributeError("'GTFProxy' has no attribute '%s'" % item) - - start += strlen(query) - # skip gaps before - while start[0] == ' ': - start += 1 - - if start[0] == '"': - start += 1 - end = start - while end[0] != '\0' and end[0] != '"': - end += 1 - l = end - start - result = force_str(PyBytes_FromStringAndSize(start, l), - self.encoding) - return result - else: - return force_str(start, self.encoding) - def setAttribute(self, name, value): - '''convenience method to set an attribute.''' - r = self.asDict() - r[name] = value - self.fromDict(r) + '''convenience method to set an attribute. + ''' + if not self.attribute_dict: + self.attribute_dict = self.attribute_string2dict( + self.attributes) + self.attribute_dict[name] = value + self.is_modified = True + def attribute_string2dict(self, s): + return collections.OrderedDict( + self.attribute_string2iterator(s)) + def __cmp__(self, other): return (self.contig, self.strand, self.start) < \ (other.contig, other.strand, other.start) @@ -676,29 +547,155 @@ cdef class GTFProxy(TupleProxy): err_msg = "op {0} isn't implemented yet".format(op) raise NotImplementedError(err_msg) + def dict2attribute_string(self, d): + """convert dictionary to attribute string in GTF format. -cdef class NamedTupleProxy(TupleProxy): + """ + aa = [] + for k, v in d.items(): + if isinstance(v, str): + aa.append('{} "{}"'.format(k, v)) + else: + aa.append("{} {}".format(k, str(v))) - map_key2field = {} + return self.separator.join(aa) + ";" + + def attribute_string2iterator(self, s): + """convert attribute string in GTF format to records + and iterate over key, value pairs. + """ + + # remove comments + attributes = force_str(s, encoding=self.encoding) + + # separate into fields + # Fields might contain a ";", for example in ENSEMBL GTF file + # for mouse, v78: + # ...; transcript_name "TXNRD2;-001"; .... + # The current heuristic is to split on a semicolon followed by a + # space, see also http://mblab.wustl.edu/GTF22.html + + # Remove white space to prevent a last empty field. + fields = [x.strip() for x in attributes.strip().split("; ")] + for f in fields: + + # strip semicolon (GTF files without a space after the last semicolon) + if f.endswith(";"): + f = f[:-1] + + # split at most once in order to avoid separating + # multi-word values + d = [x.strip() for x in f.split(" ", 1)] + + n, v = d[0], d[1] + if len(d) > 2: + v = d[1:] + + if v[0] == '"' and v[-1] == '"': + v = v[1:-1] + else: + ## try to convert to a value + try: + v = float(v) + v = int(v) + except ValueError: + pass + except TypeError: + pass + + yield n, v + + def __getattr__(self, key): + """Generic lookup of attribute from GFF/GTF attributes + """ + + # Only called if there *isn't* an attribute with this name + cdef int idx + idx, f = self.map_key2field.get(key, (-1, None)) + if idx >= 0: + # deal with known attributes (fields 0-8) + if idx == 8: + # flush attributes if requested + if self.is_modified and self.attribute_dict is not None: + s = self.dict2attribute_string(self.attribute_dict) + TupleProxy._setindex(self, idx, s) + self.attribute_dict = None + return s + + if f[0] == str: + return force_str(self.fields[idx], + self.encoding) + else: + return f[0](self.fields[idx]) + else: + # deal with generic attributes (gene_id, ...) + if self.attribute_dict is None: + self.attribute_dict = self.attribute_string2dict( + self.attributes) + return self.attribute_dict[key] def __setattr__(self, key, value): '''set attribute.''' - cdef int idx - idx, f = self.map_key2field[key] - if self.nfields < idx: - raise KeyError("field %s not set" % key) - TupleProxy.__setitem__(self, idx, str(value)) - def __getattr__(self, key): + # Note that __setattr__ is called before properties, so __setattr__ and + # properties don't mix well. This is different from __getattr__ which is + # called after any properties have been resolved. cdef int idx - idx, f = self.map_key2field[key] - if self.nfields < idx: - raise KeyError("field %s not set" % key) - if f == str: - return force_str(self.fields[idx], - self.encoding) - return f(self.fields[idx]) + idx, f = self.map_key2field.get(key, (-1, None)) + if idx >= 0: + if value is None: + s = "." + elif f[1] == str: + s = force_bytes(value, + self.encoding) + else: + s = str(f[1](value)) + TupleProxy._setindex(self, idx, s) + else: + if self.attribute_dict is None: + self.attribute_dict = self.attribute_string2dict( + self.attributes) + self.attribute_dict[key] = value + self.is_modified = True + + # for backwards compatibility + def asDict(self, *args, **kwargs): + return self.to_dict(*args, **kwargs) + + def fromDict(self, *args, **kwargs): + return self.from_dict(*args, **kwargs) + + +cdef class GFF3Proxy(GTFProxy): + + def dict2attribute_string(self, d): + """convert dictionary to attribute string.""" + return ";".join(["{}={}".format(k, v) for k, v in d.items()]) + + def attribute_string2iterator(self, s): + """convert attribute string in GFF3 format to records + and iterate over key, value pairs. + """ + + for f in (x.strip() for x in s.split(";")): + if not f: + continue + + key, value = f.split("=", 1) + value = value.strip() + + ## try to convert to a value + try: + value = float(value) + value = int(value) + except ValueError: + pass + except TypeError: + pass + + yield key.strip(), value + cdef class BedProxy(NamedTupleProxy): '''Proxy class for access to Bed fields. @@ -762,7 +759,7 @@ cdef class BedProxy(NamedTupleProxy): self.nfields = save_fields return retval - def __setattr__(self, key, value ): + def __setattr__(self, key, value): '''set attribute.''' if key == "start": self.start = value @@ -771,7 +768,8 @@ cdef class BedProxy(NamedTupleProxy): cdef int idx idx, f = self.map_key2field[key] - TupleProxy._setindex(self, idx, str(value) ) + TupleProxy._setindex(self, idx, str(value)) + cdef class VCFProxy(NamedTupleProxy): '''Proxy class for access to VCF fields. @@ -825,3 +823,11 @@ cdef class VCFProxy(NamedTupleProxy): idx, f = self.map_key2field[key] TupleProxy._setindex(self, idx, str(value)) + +__all__ = [ + "TupleProxy", + "NamedTupleProxy", + "GTFProxy", + "GFF3Proxy", + "BedProxy", + "VCFProxy"] diff --git a/pysam/libcutils.c b/pysam/libcutils.c index 2ad72394a..fb9d4d6e6 100644 --- a/pysam/libcutils.c +++ b/pysam/libcutils.c @@ -565,9 +565,10 @@ static CYTHON_INLINE float __PYX_NAN() { #include #include #include "pythread.h" -#include "pysam_util.h" #include #include +#include "samtools.pysam.h" +#include "bcftools.pysam.h" #ifdef _OPENMP #include #endif /* _OPENMP */ @@ -1658,6 +1659,10 @@ static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *, ch /* Module declarations from 'posix.fcntl' */ +/* Module declarations from 'pysam.libcsamtools' */ + +/* Module declarations from 'pysam.libcbcftools' */ + /* Module declarations from 'pysam.libcutils' */ static int __pyx_v_5pysam_9libcutils_MAX_POS; static int __pyx_v_5pysam_9libcutils_IS_PYTHON3; @@ -1678,7 +1683,6 @@ static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_OverflowError; static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_IOError; -static PyObject *__pyx_builtin_OSError; static PyObject *__pyx_builtin_open; static PyObject *__pyx_builtin_UnicodeDecodeError; static PyObject *__pyx_builtin_MemoryError; @@ -1740,12 +1744,12 @@ static const char __pyx_k_remove[] = "remove"; static const char __pyx_k_retval[] = "retval"; static const char __pyx_k_string[] = "string"; static const char __pyx_k_IOError[] = "IOError"; -static const char __pyx_k_OSError[] = "OSError"; static const char __pyx_k_collect[] = "_collect"; static const char __pyx_k_mkstemp[] = "mkstemp"; static const char __pyx_k_mpileup[] = "mpileup"; static const char __pyx_k_bcftools[] = "bcftools"; static const char __pyx_k_fsencode[] = "fsencode"; +static const char __pyx_k_is_usage[] = "is_usage"; static const char __pyx_k_kprobaln[] = "kprobaln"; static const char __pyx_k_samtools[] = "samtools"; static const char __pyx_k_stderr_f[] = "stderr_f"; @@ -1798,7 +1802,6 @@ static PyObject *__pyx_n_s_IOError; static PyObject *__pyx_n_s_MAP_STDOUT_OPTIONS; static PyObject *__pyx_n_s_MemoryError; static PyObject *__pyx_kp_s_No_such_file_or_directory_s; -static PyObject *__pyx_n_s_OSError; static PyObject *__pyx_n_s_OverflowError; static PyObject *__pyx_n_s_TypeError; static PyObject *__pyx_n_s_UnicodeDecodeError; @@ -1849,6 +1852,7 @@ static PyObject *__pyx_n_s_inf; static PyObject *__pyx_n_s_input_str; static PyObject *__pyx_kp_s_invalid_region_start_i_end_i; static PyObject *__pyx_n_s_io; +static PyObject *__pyx_n_s_is_usage; static PyObject *__pyx_n_s_join; static PyObject *__pyx_n_b_kprobaln; static PyObject *__pyx_n_s_l; @@ -1906,7 +1910,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_2array_to_qualitystring(CYTHON_UNUSE static PyObject *__pyx_pf_5pysam_9libcutils_4qualities_to_qualitystring(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_qualities, int __pyx_v_offset); /* proto */ static PyObject *__pyx_pf_5pysam_9libcutils_6parse_region(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region); /* proto */ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_fn); /* proto */ -static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_collection, PyObject *__pyx_v_method, PyObject *__pyx_v_args, PyObject *__pyx_v_catch_stdout, PyObject *__pyx_v_save_stdout); /* proto */ +static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_collection, PyObject *__pyx_v_method, PyObject *__pyx_v_args, PyObject *__pyx_v_catch_stdout, PyObject *__pyx_v_is_usage, PyObject *__pyx_v_save_stdout); /* proto */ static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags); /* proto */ static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ static PyObject *__pyx_int_0; @@ -1924,7 +1928,7 @@ static PyObject *__pyx_codeobj__11; static PyObject *__pyx_codeobj__13; /* Late includes */ -/* "pysam/libcutils.pyx":25 +/* "pysam/libcutils.pyx":31 * ################################################################# * # Utility functions for quality string conversions * cpdef c_array.array qualitystring_to_array(input_str, int offset=33): # <<<<<<<<<<<<<< @@ -1955,7 +1959,7 @@ static arrayobject *__pyx_f_5pysam_9libcutils_qualitystring_to_array(PyObject *_ } } - /* "pysam/libcutils.pyx":27 + /* "pysam/libcutils.pyx":33 * cpdef c_array.array qualitystring_to_array(input_str, int offset=33): * """convert a qualitystring to an array of quality values.""" * if input_str is None: # <<<<<<<<<<<<<< @@ -1966,7 +1970,7 @@ static arrayobject *__pyx_f_5pysam_9libcutils_qualitystring_to_array(PyObject *_ __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcutils.pyx":28 + /* "pysam/libcutils.pyx":34 * """convert a qualitystring to an array of quality values.""" * if input_str is None: * return None # <<<<<<<<<<<<<< @@ -1977,7 +1981,7 @@ static arrayobject *__pyx_f_5pysam_9libcutils_qualitystring_to_array(PyObject *_ __pyx_r = ((arrayobject *)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcutils.pyx":27 + /* "pysam/libcutils.pyx":33 * cpdef c_array.array qualitystring_to_array(input_str, int offset=33): * """convert a qualitystring to an array of quality values.""" * if input_str is None: # <<<<<<<<<<<<<< @@ -1986,19 +1990,19 @@ static arrayobject *__pyx_f_5pysam_9libcutils_qualitystring_to_array(PyObject *_ */ } - /* "pysam/libcutils.pyx":29 + /* "pysam/libcutils.pyx":35 * if input_str is None: * return None * qs = force_bytes(input_str) # <<<<<<<<<<<<<< * cdef char i * return c_array.array('B', [i - offset for i in qs]) */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_input_str, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 29, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_input_str, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 35, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_qs = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcutils.pyx":31 + /* "pysam/libcutils.pyx":37 * qs = force_bytes(input_str) * cdef char i * return c_array.array('B', [i - offset for i in qs]) # <<<<<<<<<<<<<< @@ -2006,11 +2010,11 @@ static arrayobject *__pyx_f_5pysam_9libcutils_qualitystring_to_array(PyObject *_ * */ __Pyx_XDECREF(((PyObject *)__pyx_r)); - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (unlikely(__pyx_v_qs == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable"); - __PYX_ERR(0, 31, __pyx_L1_error) + __PYX_ERR(0, 37, __pyx_L1_error) } __Pyx_INCREF(__pyx_v_qs); __pyx_t_4 = __pyx_v_qs; @@ -2019,13 +2023,13 @@ static arrayobject *__pyx_f_5pysam_9libcutils_qualitystring_to_array(PyObject *_ for (__pyx_t_8 = __pyx_t_6; __pyx_t_8 < __pyx_t_7; __pyx_t_8++) { __pyx_t_5 = __pyx_t_8; __pyx_v_i = (__pyx_t_5[0]); - __pyx_t_9 = __Pyx_PyInt_From_int((__pyx_v_i - __pyx_v_offset)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_From_int((__pyx_v_i - __pyx_v_offset)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_9))) __PYX_ERR(0, 31, __pyx_L1_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_9))) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_INCREF(__pyx_n_s_B); __Pyx_GIVEREF(__pyx_n_s_B); @@ -2033,14 +2037,14 @@ static arrayobject *__pyx_f_5pysam_9libcutils_qualitystring_to_array(PyObject *_ __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 37, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_r = ((arrayobject *)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcutils.pyx":25 + /* "pysam/libcutils.pyx":31 * ################################################################# * # Utility functions for quality string conversions * cpdef c_array.array qualitystring_to_array(input_str, int offset=33): # <<<<<<<<<<<<<< @@ -2098,7 +2102,7 @@ static PyObject *__pyx_pw_5pysam_9libcutils_1qualitystring_to_array(PyObject *__ } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "qualitystring_to_array") < 0)) __PYX_ERR(0, 25, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "qualitystring_to_array") < 0)) __PYX_ERR(0, 31, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2111,14 +2115,14 @@ static PyObject *__pyx_pw_5pysam_9libcutils_1qualitystring_to_array(PyObject *__ } __pyx_v_input_str = values[0]; if (values[1]) { - __pyx_v_offset = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 25, __pyx_L3_error) + __pyx_v_offset = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L3_error) } else { __pyx_v_offset = ((int)33); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("qualitystring_to_array", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 25, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("qualitystring_to_array", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 31, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcutils.qualitystring_to_array", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2140,7 +2144,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_qualitystring_to_array(CYTHON_UNUSED __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.offset = __pyx_v_offset; - __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9libcutils_qualitystring_to_array(__pyx_v_input_str, 0, &__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error) + __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_9libcutils_qualitystring_to_array(__pyx_v_input_str, 0, &__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 31, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2157,7 +2161,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_qualitystring_to_array(CYTHON_UNUSED return __pyx_r; } -/* "pysam/libcutils.pyx":34 +/* "pysam/libcutils.pyx":40 * * * cpdef array_to_qualitystring(c_array.array qualities, int offset=33): # <<<<<<<<<<<<<< @@ -2185,7 +2189,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_array_to_qualitystring(arrayobject *_ } } - /* "pysam/libcutils.pyx":36 + /* "pysam/libcutils.pyx":42 * cpdef array_to_qualitystring(c_array.array qualities, int offset=33): * """convert an array of quality values to a string.""" * if qualities is None: # <<<<<<<<<<<<<< @@ -2196,7 +2200,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_array_to_qualitystring(arrayobject *_ __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcutils.pyx":37 + /* "pysam/libcutils.pyx":43 * """convert an array of quality values to a string.""" * if qualities is None: * return None # <<<<<<<<<<<<<< @@ -2207,7 +2211,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_array_to_qualitystring(arrayobject *_ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcutils.pyx":36 + /* "pysam/libcutils.pyx":42 * cpdef array_to_qualitystring(c_array.array qualities, int offset=33): * """convert an array of quality values to a string.""" * if qualities is None: # <<<<<<<<<<<<<< @@ -2216,7 +2220,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_array_to_qualitystring(arrayobject *_ */ } - /* "pysam/libcutils.pyx":41 + /* "pysam/libcutils.pyx":47 * * cdef c_array.array result * result = c_array.clone(qualities, len(qualities), zero=False) # <<<<<<<<<<<<<< @@ -2225,15 +2229,15 @@ static PyObject *__pyx_f_5pysam_9libcutils_array_to_qualitystring(arrayobject *_ */ if (unlikely(((PyObject *)__pyx_v_qualities) == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 41, __pyx_L1_error) + __PYX_ERR(0, 47, __pyx_L1_error) } - __pyx_t_3 = Py_SIZE(((PyObject *)__pyx_v_qualities)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 41, __pyx_L1_error) - __pyx_t_4 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_qualities, __pyx_t_3, 0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 41, __pyx_L1_error) + __pyx_t_3 = Py_SIZE(((PyObject *)__pyx_v_qualities)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 47, __pyx_L1_error) + __pyx_t_4 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_qualities, __pyx_t_3, 0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 47, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_result = ((arrayobject *)__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcutils.pyx":43 + /* "pysam/libcutils.pyx":49 * result = c_array.clone(qualities, len(qualities), zero=False) * * for x from 0 <= x < len(qualities): # <<<<<<<<<<<<<< @@ -2242,31 +2246,31 @@ static PyObject *__pyx_f_5pysam_9libcutils_array_to_qualitystring(arrayobject *_ */ if (unlikely(((PyObject *)__pyx_v_qualities) == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 43, __pyx_L1_error) + __PYX_ERR(0, 49, __pyx_L1_error) } - __pyx_t_3 = Py_SIZE(((PyObject *)__pyx_v_qualities)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 43, __pyx_L1_error) + __pyx_t_3 = Py_SIZE(((PyObject *)__pyx_v_qualities)); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 49, __pyx_L1_error) for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) { - /* "pysam/libcutils.pyx":44 + /* "pysam/libcutils.pyx":50 * * for x from 0 <= x < len(qualities): * result[x] = qualities[x] + offset # <<<<<<<<<<<<<< * return force_str(result.tostring()) * */ - __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_qualities), __pyx_v_x, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 44, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_qualities), __pyx_v_x, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 50, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_offset); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 44, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_offset); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 50, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyNumber_Add(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 44, __pyx_L1_error) + __pyx_t_6 = PyNumber_Add(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 50, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_result), __pyx_v_x, __pyx_t_6, int, 1, __Pyx_PyInt_From_int, 0, 1, 1) < 0)) __PYX_ERR(0, 44, __pyx_L1_error) + if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_result), __pyx_v_x, __pyx_t_6, int, 1, __Pyx_PyInt_From_int, 0, 1, 1) < 0)) __PYX_ERR(0, 50, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } - /* "pysam/libcutils.pyx":45 + /* "pysam/libcutils.pyx":51 * for x from 0 <= x < len(qualities): * result[x] = qualities[x] + offset * return force_str(result.tostring()) # <<<<<<<<<<<<<< @@ -2274,7 +2278,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_array_to_qualitystring(arrayobject *_ * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_result), __pyx_n_s_tostring); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_result), __pyx_n_s_tostring); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 51, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { @@ -2287,21 +2291,21 @@ static PyObject *__pyx_f_5pysam_9libcutils_array_to_qualitystring(arrayobject *_ } } if (__pyx_t_4) { - __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 51, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { - __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 51, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 51, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; - /* "pysam/libcutils.pyx":34 + /* "pysam/libcutils.pyx":40 * * * cpdef array_to_qualitystring(c_array.array qualities, int offset=33): # <<<<<<<<<<<<<< @@ -2359,7 +2363,7 @@ static PyObject *__pyx_pw_5pysam_9libcutils_3array_to_qualitystring(PyObject *__ } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "array_to_qualitystring") < 0)) __PYX_ERR(0, 34, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "array_to_qualitystring") < 0)) __PYX_ERR(0, 40, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2372,20 +2376,20 @@ static PyObject *__pyx_pw_5pysam_9libcutils_3array_to_qualitystring(PyObject *__ } __pyx_v_qualities = ((arrayobject *)values[0]); if (values[1]) { - __pyx_v_offset = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 34, __pyx_L3_error) + __pyx_v_offset = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 40, __pyx_L3_error) } else { __pyx_v_offset = ((int)33); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("array_to_qualitystring", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 34, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("array_to_qualitystring", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 40, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcutils.array_to_qualitystring", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_qualities), __pyx_ptype_7cpython_5array_array, 1, "qualities", 0))) __PYX_ERR(0, 34, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_qualities), __pyx_ptype_7cpython_5array_array, 1, "qualities", 0))) __PYX_ERR(0, 40, __pyx_L1_error) __pyx_r = __pyx_pf_5pysam_9libcutils_2array_to_qualitystring(__pyx_self, __pyx_v_qualities, __pyx_v_offset); /* function exit code */ @@ -2406,7 +2410,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_2array_to_qualitystring(CYTHON_UNUSE __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.offset = __pyx_v_offset; - __pyx_t_1 = __pyx_f_5pysam_9libcutils_array_to_qualitystring(__pyx_v_qualities, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 34, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_array_to_qualitystring(__pyx_v_qualities, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 40, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2423,7 +2427,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_2array_to_qualitystring(CYTHON_UNUSE return __pyx_r; } -/* "pysam/libcutils.pyx":48 +/* "pysam/libcutils.pyx":54 * * * cpdef qualities_to_qualitystring(qualities, int offset=33): # <<<<<<<<<<<<<< @@ -2454,7 +2458,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_qualities_to_qualitystring(PyObject * } } - /* "pysam/libcutils.pyx":65 + /* "pysam/libcutils.pyx":71 * """ * cdef char x * if qualities is None: # <<<<<<<<<<<<<< @@ -2465,7 +2469,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_qualities_to_qualitystring(PyObject * __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcutils.pyx":66 + /* "pysam/libcutils.pyx":72 * cdef char x * if qualities is None: * return None # <<<<<<<<<<<<<< @@ -2476,7 +2480,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_qualities_to_qualitystring(PyObject * __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcutils.pyx":65 + /* "pysam/libcutils.pyx":71 * """ * cdef char x * if qualities is None: # <<<<<<<<<<<<<< @@ -2485,7 +2489,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_qualities_to_qualitystring(PyObject * */ } - /* "pysam/libcutils.pyx":67 + /* "pysam/libcutils.pyx":73 * if qualities is None: * return None * elif isinstance(qualities, c_array.array): # <<<<<<<<<<<<<< @@ -2496,7 +2500,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_qualities_to_qualitystring(PyObject * __pyx_t_1 = (__pyx_t_2 != 0); if (__pyx_t_1) { - /* "pysam/libcutils.pyx":68 + /* "pysam/libcutils.pyx":74 * return None * elif isinstance(qualities, c_array.array): * return array_to_qualitystring(qualities, offset=offset) # <<<<<<<<<<<<<< @@ -2504,16 +2508,16 @@ static PyObject *__pyx_f_5pysam_9libcutils_qualities_to_qualitystring(PyObject * * # tuples and lists */ __Pyx_XDECREF(__pyx_r); - if (!(likely(((__pyx_v_qualities) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_qualities, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 68, __pyx_L1_error) + if (!(likely(((__pyx_v_qualities) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_qualities, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 74, __pyx_L1_error) __pyx_t_4.__pyx_n = 1; __pyx_t_4.offset = __pyx_v_offset; - __pyx_t_3 = __pyx_f_5pysam_9libcutils_array_to_qualitystring(((arrayobject *)__pyx_v_qualities), 0, &__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_array_to_qualitystring(((arrayobject *)__pyx_v_qualities), 0, &__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 74, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcutils.pyx":67 + /* "pysam/libcutils.pyx":73 * if qualities is None: * return None * elif isinstance(qualities, c_array.array): # <<<<<<<<<<<<<< @@ -2522,7 +2526,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_qualities_to_qualitystring(PyObject * */ } - /* "pysam/libcutils.pyx":71 + /* "pysam/libcutils.pyx":77 * else: * # tuples and lists * return force_str("".join([chr(x + offset) for x in qualities])) # <<<<<<<<<<<<<< @@ -2531,32 +2535,32 @@ static PyObject *__pyx_f_5pysam_9libcutils_qualities_to_qualitystring(PyObject * */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (likely(PyList_CheckExact(__pyx_v_qualities)) || PyTuple_CheckExact(__pyx_v_qualities)) { __pyx_t_5 = __pyx_v_qualities; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; __pyx_t_7 = NULL; } else { - __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_qualities); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_qualities); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 77, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_7)) { if (likely(PyList_CheckExact(__pyx_t_5))) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_8 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 77, __pyx_L1_error) #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_8 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); #endif } else { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 77, __pyx_L1_error) #else - __pyx_t_8 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_8 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); #endif } @@ -2566,28 +2570,28 @@ static PyObject *__pyx_f_5pysam_9libcutils_qualities_to_qualitystring(PyObject * PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 71, __pyx_L1_error) + else __PYX_ERR(0, 77, __pyx_L1_error) } break; } __Pyx_GOTREF(__pyx_t_8); } - __pyx_t_9 = __Pyx_PyInt_As_char(__pyx_t_8); if (unlikely((__pyx_t_9 == (char)-1) && PyErr_Occurred())) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_As_char(__pyx_t_8); if (unlikely((__pyx_t_9 == (char)-1) && PyErr_Occurred())) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_v_x = __pyx_t_9; - __pyx_t_8 = __Pyx_PyInt_From_int((__pyx_v_x + __pyx_v_offset)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyInt_From_int((__pyx_v_x + __pyx_v_offset)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); - __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_10))) __PYX_ERR(0, 71, __pyx_L1_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_10))) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyString_Join(__pyx_kp_s_, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyString_Join(__pyx_kp_s_, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_r = __pyx_t_3; @@ -2595,7 +2599,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_qualities_to_qualitystring(PyObject * goto __pyx_L0; } - /* "pysam/libcutils.pyx":48 + /* "pysam/libcutils.pyx":54 * * * cpdef qualities_to_qualitystring(qualities, int offset=33): # <<<<<<<<<<<<<< @@ -2653,7 +2657,7 @@ static PyObject *__pyx_pw_5pysam_9libcutils_5qualities_to_qualitystring(PyObject } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "qualities_to_qualitystring") < 0)) __PYX_ERR(0, 48, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "qualities_to_qualitystring") < 0)) __PYX_ERR(0, 54, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2666,14 +2670,14 @@ static PyObject *__pyx_pw_5pysam_9libcutils_5qualities_to_qualitystring(PyObject } __pyx_v_qualities = values[0]; if (values[1]) { - __pyx_v_offset = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 48, __pyx_L3_error) + __pyx_v_offset = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 54, __pyx_L3_error) } else { __pyx_v_offset = ((int)33); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("qualities_to_qualitystring", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 48, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("qualities_to_qualitystring", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 54, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcutils.qualities_to_qualitystring", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2695,7 +2699,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_4qualities_to_qualitystring(CYTHON_U __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.offset = __pyx_v_offset; - __pyx_t_1 = __pyx_f_5pysam_9libcutils_qualities_to_qualitystring(__pyx_v_qualities, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 48, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_qualities_to_qualitystring(__pyx_v_qualities, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2712,7 +2716,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_4qualities_to_qualitystring(CYTHON_U return __pyx_r; } -/* "pysam/libcutils.pyx":82 +/* "pysam/libcutils.pyx":88 * cdef bint IS_PYTHON3 = PY_MAJOR_VERSION >= 3 * * cdef from_string_and_size(const char* s, size_t length): # <<<<<<<<<<<<<< @@ -2727,7 +2731,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_from_string_and_size(char const *__py PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("from_string_and_size", 0); - /* "pysam/libcutils.pyx":83 + /* "pysam/libcutils.pyx":89 * * cdef from_string_and_size(const char* s, size_t length): * if IS_PYTHON3: # <<<<<<<<<<<<<< @@ -2737,7 +2741,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_from_string_and_size(char const *__py __pyx_t_1 = (__pyx_v_5pysam_9libcutils_IS_PYTHON3 != 0); if (__pyx_t_1) { - /* "pysam/libcutils.pyx":84 + /* "pysam/libcutils.pyx":90 * cdef from_string_and_size(const char* s, size_t length): * if IS_PYTHON3: * return s[:length].decode("ascii") # <<<<<<<<<<<<<< @@ -2745,13 +2749,13 @@ static PyObject *__pyx_f_5pysam_9libcutils_from_string_and_size(char const *__py * return s[:length] */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_decode_c_string(__pyx_v_s, 0, __pyx_v_length, NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 84, __pyx_L1_error) + __pyx_t_2 = __Pyx_decode_c_string(__pyx_v_s, 0, __pyx_v_length, NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcutils.pyx":83 + /* "pysam/libcutils.pyx":89 * * cdef from_string_and_size(const char* s, size_t length): * if IS_PYTHON3: # <<<<<<<<<<<<<< @@ -2760,7 +2764,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_from_string_and_size(char const *__py */ } - /* "pysam/libcutils.pyx":86 + /* "pysam/libcutils.pyx":92 * return s[:length].decode("ascii") * else: * return s[:length] # <<<<<<<<<<<<<< @@ -2769,14 +2773,14 @@ static PyObject *__pyx_f_5pysam_9libcutils_from_string_and_size(char const *__py */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_s + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_s + 0, __pyx_v_length - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; } - /* "pysam/libcutils.pyx":82 + /* "pysam/libcutils.pyx":88 * cdef bint IS_PYTHON3 = PY_MAJOR_VERSION >= 3 * * cdef from_string_and_size(const char* s, size_t length): # <<<<<<<<<<<<<< @@ -2795,7 +2799,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_from_string_and_size(char const *__py return __pyx_r; } -/* "pysam/libcutils.pyx":93 +/* "pysam/libcutils.pyx":99 * * * cdef bytes encode_filename(object filename): # <<<<<<<<<<<<<< @@ -2814,7 +2818,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil PyObject *__pyx_t_6 = NULL; __Pyx_RefNannySetupContext("encode_filename", 0); - /* "pysam/libcutils.pyx":95 + /* "pysam/libcutils.pyx":101 * cdef bytes encode_filename(object filename): * """Make sure a filename is 8-bit encoded (or None).""" * if filename is None: # <<<<<<<<<<<<<< @@ -2825,7 +2829,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcutils.pyx":96 + /* "pysam/libcutils.pyx":102 * """Make sure a filename is 8-bit encoded (or None).""" * if filename is None: * return None # <<<<<<<<<<<<<< @@ -2836,7 +2840,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcutils.pyx":95 + /* "pysam/libcutils.pyx":101 * cdef bytes encode_filename(object filename): * """Make sure a filename is 8-bit encoded (or None).""" * if filename is None: # <<<<<<<<<<<<<< @@ -2845,7 +2849,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil */ } - /* "pysam/libcutils.pyx":97 + /* "pysam/libcutils.pyx":103 * if filename is None: * return None * elif PY_MAJOR_VERSION >= 3 and PY_MINOR_VERSION >= 2: # <<<<<<<<<<<<<< @@ -2863,7 +2867,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil __pyx_L4_bool_binop_done:; if (__pyx_t_2) { - /* "pysam/libcutils.pyx":99 + /* "pysam/libcutils.pyx":105 * elif PY_MAJOR_VERSION >= 3 and PY_MINOR_VERSION >= 2: * # Added to support path-like objects * return os.fsencode(filename) # <<<<<<<<<<<<<< @@ -2871,9 +2875,9 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil * return filename */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 99, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_fsencode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 99, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_fsencode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = NULL; @@ -2887,13 +2891,13 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil } } if (!__pyx_t_4) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 99, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_filename); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filename}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 99, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -2901,30 +2905,30 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_filename}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 99, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 99, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_filename); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 99, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 99, __pyx_L1_error) + if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 105, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcutils.pyx":97 + /* "pysam/libcutils.pyx":103 * if filename is None: * return None * elif PY_MAJOR_VERSION >= 3 and PY_MINOR_VERSION >= 2: # <<<<<<<<<<<<<< @@ -2933,7 +2937,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil */ } - /* "pysam/libcutils.pyx":100 + /* "pysam/libcutils.pyx":106 * # Added to support path-like objects * return os.fsencode(filename) * elif PyBytes_Check(filename): # <<<<<<<<<<<<<< @@ -2943,7 +2947,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil __pyx_t_2 = (PyBytes_Check(__pyx_v_filename) != 0); if (__pyx_t_2) { - /* "pysam/libcutils.pyx":101 + /* "pysam/libcutils.pyx":107 * return os.fsencode(filename) * elif PyBytes_Check(filename): * return filename # <<<<<<<<<<<<<< @@ -2951,12 +2955,12 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil * return filename.encode(FILENAME_ENCODING) */ __Pyx_XDECREF(__pyx_r); - if (!(likely(PyBytes_CheckExact(__pyx_v_filename))||((__pyx_v_filename) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_filename)->tp_name), 0))) __PYX_ERR(0, 101, __pyx_L1_error) + if (!(likely(PyBytes_CheckExact(__pyx_v_filename))||((__pyx_v_filename) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_filename)->tp_name), 0))) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_INCREF(__pyx_v_filename); __pyx_r = ((PyObject*)__pyx_v_filename); goto __pyx_L0; - /* "pysam/libcutils.pyx":100 + /* "pysam/libcutils.pyx":106 * # Added to support path-like objects * return os.fsencode(filename) * elif PyBytes_Check(filename): # <<<<<<<<<<<<<< @@ -2965,7 +2969,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil */ } - /* "pysam/libcutils.pyx":102 + /* "pysam/libcutils.pyx":108 * elif PyBytes_Check(filename): * return filename * elif PyUnicode_Check(filename): # <<<<<<<<<<<<<< @@ -2975,7 +2979,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil __pyx_t_2 = (PyUnicode_Check(__pyx_v_filename) != 0); if (likely(__pyx_t_2)) { - /* "pysam/libcutils.pyx":103 + /* "pysam/libcutils.pyx":109 * return filename * elif PyUnicode_Check(filename): * return filename.encode(FILENAME_ENCODING) # <<<<<<<<<<<<<< @@ -2983,7 +2987,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil * raise TypeError("Argument must be string or unicode.") */ __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 103, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { @@ -2996,13 +3000,13 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil } } if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_5pysam_9libcutils_FILENAME_ENCODING); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 103, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_5pysam_9libcutils_FILENAME_ENCODING); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_5pysam_9libcutils_FILENAME_ENCODING}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 103, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -3010,30 +3014,30 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_5pysam_9libcutils_FILENAME_ENCODING}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 103, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 103, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v_5pysam_9libcutils_FILENAME_ENCODING); __Pyx_GIVEREF(__pyx_v_5pysam_9libcutils_FILENAME_ENCODING); PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_5pysam_9libcutils_FILENAME_ENCODING); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 103, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 103, __pyx_L1_error) + if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 109, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcutils.pyx":102 + /* "pysam/libcutils.pyx":108 * elif PyBytes_Check(filename): * return filename * elif PyUnicode_Check(filename): # <<<<<<<<<<<<<< @@ -3042,7 +3046,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil */ } - /* "pysam/libcutils.pyx":105 + /* "pysam/libcutils.pyx":111 * return filename.encode(FILENAME_ENCODING) * else: * raise TypeError("Argument must be string or unicode.") # <<<<<<<<<<<<<< @@ -3050,14 +3054,14 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil * */ /*else*/ { - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 105, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 111, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 105, __pyx_L1_error) + __PYX_ERR(0, 111, __pyx_L1_error) } - /* "pysam/libcutils.pyx":93 + /* "pysam/libcutils.pyx":99 * * * cdef bytes encode_filename(object filename): # <<<<<<<<<<<<<< @@ -3079,7 +3083,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_encode_filename(PyObject *__pyx_v_fil return __pyx_r; } -/* "pysam/libcutils.pyx":108 +/* "pysam/libcutils.pyx":114 * * * cdef bytes force_bytes(object s, encoding="ascii"): # <<<<<<<<<<<<<< @@ -3104,7 +3108,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru } } - /* "pysam/libcutils.pyx":112 + /* "pysam/libcutils.pyx":118 * ascii encoding. * """ * if s is None: # <<<<<<<<<<<<<< @@ -3115,7 +3119,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcutils.pyx":113 + /* "pysam/libcutils.pyx":119 * """ * if s is None: * return None # <<<<<<<<<<<<<< @@ -3126,7 +3130,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcutils.pyx":112 + /* "pysam/libcutils.pyx":118 * ascii encoding. * """ * if s is None: # <<<<<<<<<<<<<< @@ -3135,7 +3139,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru */ } - /* "pysam/libcutils.pyx":114 + /* "pysam/libcutils.pyx":120 * if s is None: * return None * elif PyBytes_Check(s): # <<<<<<<<<<<<<< @@ -3145,7 +3149,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru __pyx_t_2 = (PyBytes_Check(__pyx_v_s) != 0); if (__pyx_t_2) { - /* "pysam/libcutils.pyx":115 + /* "pysam/libcutils.pyx":121 * return None * elif PyBytes_Check(s): * return s # <<<<<<<<<<<<<< @@ -3153,12 +3157,12 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru * return s.encode(encoding) */ __Pyx_XDECREF(__pyx_r); - if (!(likely(PyBytes_CheckExact(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_s)->tp_name), 0))) __PYX_ERR(0, 115, __pyx_L1_error) + if (!(likely(PyBytes_CheckExact(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_s)->tp_name), 0))) __PYX_ERR(0, 121, __pyx_L1_error) __Pyx_INCREF(__pyx_v_s); __pyx_r = ((PyObject*)__pyx_v_s); goto __pyx_L0; - /* "pysam/libcutils.pyx":114 + /* "pysam/libcutils.pyx":120 * if s is None: * return None * elif PyBytes_Check(s): # <<<<<<<<<<<<<< @@ -3167,7 +3171,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru */ } - /* "pysam/libcutils.pyx":116 + /* "pysam/libcutils.pyx":122 * elif PyBytes_Check(s): * return s * elif PyUnicode_Check(s): # <<<<<<<<<<<<<< @@ -3177,7 +3181,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru __pyx_t_2 = (PyUnicode_Check(__pyx_v_s) != 0); if (likely(__pyx_t_2)) { - /* "pysam/libcutils.pyx":117 + /* "pysam/libcutils.pyx":123 * return s * elif PyUnicode_Check(s): * return s.encode(encoding) # <<<<<<<<<<<<<< @@ -3185,7 +3189,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru * raise TypeError("Argument must be string, bytes or unicode.") */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { @@ -3198,13 +3202,13 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_encoding); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_encoding); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_encoding}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -3212,30 +3216,30 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_encoding}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_INCREF(__pyx_v_encoding); __Pyx_GIVEREF(__pyx_v_encoding); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_encoding); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 117, __pyx_L1_error) + if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 123, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcutils.pyx":116 + /* "pysam/libcutils.pyx":122 * elif PyBytes_Check(s): * return s * elif PyUnicode_Check(s): # <<<<<<<<<<<<<< @@ -3244,7 +3248,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru */ } - /* "pysam/libcutils.pyx":119 + /* "pysam/libcutils.pyx":125 * return s.encode(encoding) * else: * raise TypeError("Argument must be string, bytes or unicode.") # <<<<<<<<<<<<<< @@ -3252,14 +3256,14 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru * */ /*else*/ { - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 119, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __PYX_ERR(0, 119, __pyx_L1_error) + __PYX_ERR(0, 125, __pyx_L1_error) } - /* "pysam/libcutils.pyx":108 + /* "pysam/libcutils.pyx":114 * * * cdef bytes force_bytes(object s, encoding="ascii"): # <<<<<<<<<<<<<< @@ -3281,7 +3285,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_bytes(PyObject *__pyx_v_s, stru return __pyx_r; } -/* "pysam/libcutils.pyx":122 +/* "pysam/libcutils.pyx":128 * * * cdef charptr_to_str(const char* s, encoding="ascii"): # <<<<<<<<<<<<<< @@ -3305,7 +3309,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str(char const *__pyx_v_s, } } - /* "pysam/libcutils.pyx":123 + /* "pysam/libcutils.pyx":129 * * cdef charptr_to_str(const char* s, encoding="ascii"): * if s == NULL: # <<<<<<<<<<<<<< @@ -3315,7 +3319,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str(char const *__pyx_v_s, __pyx_t_1 = ((__pyx_v_s == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcutils.pyx":124 + /* "pysam/libcutils.pyx":130 * cdef charptr_to_str(const char* s, encoding="ascii"): * if s == NULL: * return None # <<<<<<<<<<<<<< @@ -3326,7 +3330,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str(char const *__pyx_v_s, __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcutils.pyx":123 + /* "pysam/libcutils.pyx":129 * * cdef charptr_to_str(const char* s, encoding="ascii"): * if s == NULL: # <<<<<<<<<<<<<< @@ -3335,7 +3339,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str(char const *__pyx_v_s, */ } - /* "pysam/libcutils.pyx":125 + /* "pysam/libcutils.pyx":131 * if s == NULL: * return None * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< @@ -3345,7 +3349,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str(char const *__pyx_v_s, __pyx_t_1 = ((PY_MAJOR_VERSION < 3) != 0); if (__pyx_t_1) { - /* "pysam/libcutils.pyx":126 + /* "pysam/libcutils.pyx":132 * return None * if PY_MAJOR_VERSION < 3: * return s # <<<<<<<<<<<<<< @@ -3353,13 +3357,13 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str(char const *__pyx_v_s, * return s.decode(encoding) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcutils.pyx":125 + /* "pysam/libcutils.pyx":131 * if s == NULL: * return None * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< @@ -3368,7 +3372,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str(char const *__pyx_v_s, */ } - /* "pysam/libcutils.pyx":128 + /* "pysam/libcutils.pyx":134 * return s * else: * return s.decode(encoding) # <<<<<<<<<<<<<< @@ -3377,9 +3381,9 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str(char const *__pyx_v_s, */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 128, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_decode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 128, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_decode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; @@ -3393,13 +3397,13 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str(char const *__pyx_v_s, } } if (!__pyx_t_3) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_encoding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 128, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_encoding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_encoding}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 128, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_2); } else @@ -3407,19 +3411,19 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str(char const *__pyx_v_s, #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_encoding}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 128, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 128, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_encoding); __Pyx_GIVEREF(__pyx_v_encoding); PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_encoding); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 128, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } @@ -3430,7 +3434,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str(char const *__pyx_v_s, goto __pyx_L0; } - /* "pysam/libcutils.pyx":122 + /* "pysam/libcutils.pyx":128 * * * cdef charptr_to_str(const char* s, encoding="ascii"): # <<<<<<<<<<<<<< @@ -3452,7 +3456,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str(char const *__pyx_v_s, return __pyx_r; } -/* "pysam/libcutils.pyx":131 +/* "pysam/libcutils.pyx":137 * * * cdef charptr_to_str_w_len(const char* s, size_t n, encoding="ascii"): # <<<<<<<<<<<<<< @@ -3476,7 +3480,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str_w_len(char const *__py } } - /* "pysam/libcutils.pyx":132 + /* "pysam/libcutils.pyx":138 * * cdef charptr_to_str_w_len(const char* s, size_t n, encoding="ascii"): * if s == NULL: # <<<<<<<<<<<<<< @@ -3486,7 +3490,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str_w_len(char const *__py __pyx_t_1 = ((__pyx_v_s == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcutils.pyx":133 + /* "pysam/libcutils.pyx":139 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding="ascii"): * if s == NULL: * return None # <<<<<<<<<<<<<< @@ -3497,7 +3501,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str_w_len(char const *__py __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcutils.pyx":132 + /* "pysam/libcutils.pyx":138 * * cdef charptr_to_str_w_len(const char* s, size_t n, encoding="ascii"): * if s == NULL: # <<<<<<<<<<<<<< @@ -3506,7 +3510,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str_w_len(char const *__py */ } - /* "pysam/libcutils.pyx":134 + /* "pysam/libcutils.pyx":140 * if s == NULL: * return None * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< @@ -3516,7 +3520,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str_w_len(char const *__py __pyx_t_1 = ((PY_MAJOR_VERSION < 3) != 0); if (__pyx_t_1) { - /* "pysam/libcutils.pyx":135 + /* "pysam/libcutils.pyx":141 * return None * if PY_MAJOR_VERSION < 3: * return s[:n] # <<<<<<<<<<<<<< @@ -3524,13 +3528,13 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str_w_len(char const *__py * return s[:n].decode(encoding) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_s + 0, __pyx_v_n - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 135, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_s + 0, __pyx_v_n - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 141, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "pysam/libcutils.pyx":134 + /* "pysam/libcutils.pyx":140 * if s == NULL: * return None * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< @@ -3539,7 +3543,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str_w_len(char const *__py */ } - /* "pysam/libcutils.pyx":137 + /* "pysam/libcutils.pyx":143 * return s[:n] * else: * return s[:n].decode(encoding) # <<<<<<<<<<<<<< @@ -3548,9 +3552,9 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str_w_len(char const *__py */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_s + 0, __pyx_v_n - 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 137, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_s + 0, __pyx_v_n - 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_decode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 137, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_decode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; @@ -3564,13 +3568,13 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str_w_len(char const *__py } } if (!__pyx_t_3) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_encoding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 137, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_encoding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_encoding}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 137, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_2); } else @@ -3578,19 +3582,19 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str_w_len(char const *__py #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_encoding}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 137, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_2); } else #endif { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 137, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_encoding); __Pyx_GIVEREF(__pyx_v_encoding); PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_encoding); - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 137, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } @@ -3601,7 +3605,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str_w_len(char const *__py goto __pyx_L0; } - /* "pysam/libcutils.pyx":131 + /* "pysam/libcutils.pyx":137 * * * cdef charptr_to_str_w_len(const char* s, size_t n, encoding="ascii"): # <<<<<<<<<<<<<< @@ -3623,7 +3627,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_str_w_len(char const *__py return __pyx_r; } -/* "pysam/libcutils.pyx":140 +/* "pysam/libcutils.pyx":146 * * * cdef bytes charptr_to_bytes(const char* s, encoding="ascii"): # <<<<<<<<<<<<<< @@ -3640,7 +3644,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_bytes(char const *__pyx_v_ if (__pyx_optional_args) { } - /* "pysam/libcutils.pyx":141 + /* "pysam/libcutils.pyx":147 * * cdef bytes charptr_to_bytes(const char* s, encoding="ascii"): * if s == NULL: # <<<<<<<<<<<<<< @@ -3650,7 +3654,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_bytes(char const *__pyx_v_ __pyx_t_1 = ((__pyx_v_s == NULL) != 0); if (__pyx_t_1) { - /* "pysam/libcutils.pyx":142 + /* "pysam/libcutils.pyx":148 * cdef bytes charptr_to_bytes(const char* s, encoding="ascii"): * if s == NULL: * return None # <<<<<<<<<<<<<< @@ -3661,7 +3665,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_bytes(char const *__pyx_v_ __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcutils.pyx":141 + /* "pysam/libcutils.pyx":147 * * cdef bytes charptr_to_bytes(const char* s, encoding="ascii"): * if s == NULL: # <<<<<<<<<<<<<< @@ -3670,7 +3674,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_bytes(char const *__pyx_v_ */ } - /* "pysam/libcutils.pyx":144 + /* "pysam/libcutils.pyx":150 * return None * else: * return s # <<<<<<<<<<<<<< @@ -3679,14 +3683,14 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_bytes(char const *__pyx_v_ */ /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 144, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 150, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L0; } - /* "pysam/libcutils.pyx":140 + /* "pysam/libcutils.pyx":146 * * * cdef bytes charptr_to_bytes(const char* s, encoding="ascii"): # <<<<<<<<<<<<<< @@ -3705,7 +3709,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_charptr_to_bytes(char const *__pyx_v_ return __pyx_r; } -/* "pysam/libcutils.pyx":147 +/* "pysam/libcutils.pyx":153 * * * cdef force_str(object s, encoding="ascii"): # <<<<<<<<<<<<<< @@ -3730,7 +3734,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct } } - /* "pysam/libcutils.pyx":150 + /* "pysam/libcutils.pyx":156 * """Return s converted to str type of current Python * (bytes in Py2, unicode in Py3)""" * if s is None: # <<<<<<<<<<<<<< @@ -3741,7 +3745,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "pysam/libcutils.pyx":151 + /* "pysam/libcutils.pyx":157 * (bytes in Py2, unicode in Py3)""" * if s is None: * return None # <<<<<<<<<<<<<< @@ -3752,7 +3756,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "pysam/libcutils.pyx":150 + /* "pysam/libcutils.pyx":156 * """Return s converted to str type of current Python * (bytes in Py2, unicode in Py3)""" * if s is None: # <<<<<<<<<<<<<< @@ -3761,7 +3765,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct */ } - /* "pysam/libcutils.pyx":152 + /* "pysam/libcutils.pyx":158 * if s is None: * return None * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< @@ -3771,7 +3775,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct __pyx_t_2 = ((PY_MAJOR_VERSION < 3) != 0); if (__pyx_t_2) { - /* "pysam/libcutils.pyx":153 + /* "pysam/libcutils.pyx":159 * return None * if PY_MAJOR_VERSION < 3: * return s # <<<<<<<<<<<<<< @@ -3783,7 +3787,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct __pyx_r = __pyx_v_s; goto __pyx_L0; - /* "pysam/libcutils.pyx":152 + /* "pysam/libcutils.pyx":158 * if s is None: * return None * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< @@ -3792,7 +3796,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct */ } - /* "pysam/libcutils.pyx":154 + /* "pysam/libcutils.pyx":160 * if PY_MAJOR_VERSION < 3: * return s * elif PyBytes_Check(s): # <<<<<<<<<<<<<< @@ -3802,7 +3806,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct __pyx_t_2 = (PyBytes_Check(__pyx_v_s) != 0); if (__pyx_t_2) { - /* "pysam/libcutils.pyx":155 + /* "pysam/libcutils.pyx":161 * return s * elif PyBytes_Check(s): * return s.decode(encoding) # <<<<<<<<<<<<<< @@ -3810,7 +3814,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct * # assume unicode */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_decode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_decode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { @@ -3823,13 +3827,13 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct } } if (!__pyx_t_5) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_encoding); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_encoding); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_encoding}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); } else @@ -3837,19 +3841,19 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_encoding}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_INCREF(__pyx_v_encoding); __Pyx_GIVEREF(__pyx_v_encoding); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_encoding); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } @@ -3859,7 +3863,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct __pyx_t_3 = 0; goto __pyx_L0; - /* "pysam/libcutils.pyx":154 + /* "pysam/libcutils.pyx":160 * if PY_MAJOR_VERSION < 3: * return s * elif PyBytes_Check(s): # <<<<<<<<<<<<<< @@ -3868,7 +3872,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct */ } - /* "pysam/libcutils.pyx":158 + /* "pysam/libcutils.pyx":164 * else: * # assume unicode * return s # <<<<<<<<<<<<<< @@ -3882,7 +3886,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct goto __pyx_L0; } - /* "pysam/libcutils.pyx":147 + /* "pysam/libcutils.pyx":153 * * * cdef force_str(object s, encoding="ascii"): # <<<<<<<<<<<<<< @@ -3904,7 +3908,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_force_str(PyObject *__pyx_v_s, struct return __pyx_r; } -/* "pysam/libcutils.pyx":161 +/* "pysam/libcutils.pyx":167 * * * cpdef parse_region(reference=None, # <<<<<<<<<<<<<< @@ -3916,7 +3920,7 @@ static PyObject *__pyx_pw_5pysam_9libcutils_7parse_region(PyObject *__pyx_self, static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcutils_parse_region *__pyx_optional_args) { PyObject *__pyx_v_reference = ((PyObject *)Py_None); - /* "pysam/libcutils.pyx":162 + /* "pysam/libcutils.pyx":168 * * cpdef parse_region(reference=None, * start=None, # <<<<<<<<<<<<<< @@ -3925,7 +3929,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ */ PyObject *__pyx_v_start = ((PyObject *)Py_None); - /* "pysam/libcutils.pyx":163 + /* "pysam/libcutils.pyx":169 * cpdef parse_region(reference=None, * start=None, * end=None, # <<<<<<<<<<<<<< @@ -3934,7 +3938,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ */ PyObject *__pyx_v_end = ((PyObject *)Py_None); - /* "pysam/libcutils.pyx":164 + /* "pysam/libcutils.pyx":170 * start=None, * end=None, * region=None): # <<<<<<<<<<<<<< @@ -3942,7 +3946,6 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ * either be specified by :term:`reference`, `start` and */ PyObject *__pyx_v_region = ((PyObject *)Py_None); - CYTHON_UNUSED int __pyx_v_rtid; PY_LONG_LONG __pyx_v_rstart; PY_LONG_LONG __pyx_v_rend; PyObject *__pyx_v_parts = NULL; @@ -3979,26 +3982,17 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __Pyx_INCREF(__pyx_v_reference); __Pyx_INCREF(__pyx_v_region); - /* "pysam/libcutils.pyx":195 + /* "pysam/libcutils.pyx":198 * cdef long long rend * - * rtid = -1 # <<<<<<<<<<<<<< - * rstart = 0 - * rend = MAX_POS - */ - __pyx_v_rtid = -1; - - /* "pysam/libcutils.pyx":196 - * - * rtid = -1 * rstart = 0 # <<<<<<<<<<<<<< * rend = MAX_POS * if start != None: */ __pyx_v_rstart = 0; - /* "pysam/libcutils.pyx":197 - * rtid = -1 + /* "pysam/libcutils.pyx":199 + * * rstart = 0 * rend = MAX_POS # <<<<<<<<<<<<<< * if start != None: @@ -4006,19 +4000,19 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ */ __pyx_v_rend = __pyx_v_5pysam_9libcutils_MAX_POS; - /* "pysam/libcutils.pyx":198 + /* "pysam/libcutils.pyx":200 * rstart = 0 * rend = MAX_POS * if start != None: # <<<<<<<<<<<<<< * try: * rstart = start */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 198, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 198, __pyx_L1_error) + __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 200, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 200, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "pysam/libcutils.pyx":199 + /* "pysam/libcutils.pyx":201 * rend = MAX_POS * if start != None: * try: # <<<<<<<<<<<<<< @@ -4034,17 +4028,17 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __Pyx_XGOTREF(__pyx_t_5); /*try:*/ { - /* "pysam/libcutils.pyx":200 + /* "pysam/libcutils.pyx":202 * if start != None: * try: * rstart = start # <<<<<<<<<<<<<< * except OverflowError: * raise ValueError('start out of range (%i)' % start) */ - __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_start); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 200, __pyx_L4_error) + __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_start); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 202, __pyx_L4_error) __pyx_v_rstart = __pyx_t_6; - /* "pysam/libcutils.pyx":199 + /* "pysam/libcutils.pyx":201 * rend = MAX_POS * if start != None: * try: # <<<<<<<<<<<<<< @@ -4059,7 +4053,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __pyx_L4_error:; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcutils.pyx":201 + /* "pysam/libcutils.pyx":203 * try: * rstart = start * except OverflowError: # <<<<<<<<<<<<<< @@ -4069,31 +4063,31 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError); if (__pyx_t_7) { __Pyx_AddTraceback("pysam.libcutils.parse_region", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_8, &__pyx_t_9) < 0) __PYX_ERR(0, 201, __pyx_L6_except_error) + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_8, &__pyx_t_9) < 0) __PYX_ERR(0, 203, __pyx_L6_except_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GOTREF(__pyx_t_8); __Pyx_GOTREF(__pyx_t_9); - /* "pysam/libcutils.pyx":202 + /* "pysam/libcutils.pyx":204 * rstart = start * except OverflowError: * raise ValueError('start out of range (%i)' % start) # <<<<<<<<<<<<<< * * if end != None: */ - __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_v_start); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 202, __pyx_L6_except_error) + __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_v_start); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 204, __pyx_L6_except_error) __Pyx_GOTREF(__pyx_t_10); - __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 202, __pyx_L6_except_error) + __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 204, __pyx_L6_except_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_Raise(__pyx_t_11, 0, 0, 0); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __PYX_ERR(0, 202, __pyx_L6_except_error) + __PYX_ERR(0, 204, __pyx_L6_except_error) } goto __pyx_L6_except_error; __pyx_L6_except_error:; - /* "pysam/libcutils.pyx":199 + /* "pysam/libcutils.pyx":201 * rend = MAX_POS * if start != None: * try: # <<<<<<<<<<<<<< @@ -4108,7 +4102,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __pyx_L9_try_end:; } - /* "pysam/libcutils.pyx":198 + /* "pysam/libcutils.pyx":200 * rstart = 0 * rend = MAX_POS * if start != None: # <<<<<<<<<<<<<< @@ -4117,19 +4111,19 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ */ } - /* "pysam/libcutils.pyx":204 + /* "pysam/libcutils.pyx":206 * raise ValueError('start out of range (%i)' % start) * * if end != None: # <<<<<<<<<<<<<< * try: * rend = end */ - __pyx_t_9 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 204, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 204, __pyx_L1_error) + __pyx_t_9 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 206, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 206, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (__pyx_t_2) { - /* "pysam/libcutils.pyx":205 + /* "pysam/libcutils.pyx":207 * * if end != None: * try: # <<<<<<<<<<<<<< @@ -4145,17 +4139,17 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "pysam/libcutils.pyx":206 + /* "pysam/libcutils.pyx":208 * if end != None: * try: * rend = end # <<<<<<<<<<<<<< * except OverflowError: * raise ValueError('end out of range (%i)' % end) */ - __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_end); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 206, __pyx_L13_error) + __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_end); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 208, __pyx_L13_error) __pyx_v_rend = __pyx_t_6; - /* "pysam/libcutils.pyx":205 + /* "pysam/libcutils.pyx":207 * * if end != None: * try: # <<<<<<<<<<<<<< @@ -4174,7 +4168,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; - /* "pysam/libcutils.pyx":207 + /* "pysam/libcutils.pyx":209 * try: * rend = end * except OverflowError: # <<<<<<<<<<<<<< @@ -4184,31 +4178,31 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError); if (__pyx_t_7) { __Pyx_AddTraceback("pysam.libcutils.parse_region", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_8, &__pyx_t_1) < 0) __PYX_ERR(0, 207, __pyx_L15_except_error) + if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_8, &__pyx_t_1) < 0) __PYX_ERR(0, 209, __pyx_L15_except_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GOTREF(__pyx_t_8); __Pyx_GOTREF(__pyx_t_1); - /* "pysam/libcutils.pyx":208 + /* "pysam/libcutils.pyx":210 * rend = end * except OverflowError: * raise ValueError('end out of range (%i)' % end) # <<<<<<<<<<<<<< * * if region: */ - __pyx_t_11 = __Pyx_PyString_Format(__pyx_kp_s_end_out_of_range_i, __pyx_v_end); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 208, __pyx_L15_except_error) + __pyx_t_11 = __Pyx_PyString_Format(__pyx_kp_s_end_out_of_range_i, __pyx_v_end); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 210, __pyx_L15_except_error) __Pyx_GOTREF(__pyx_t_11); - __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 208, __pyx_L15_except_error) + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 210, __pyx_L15_except_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_Raise(__pyx_t_10, 0, 0, 0); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __PYX_ERR(0, 208, __pyx_L15_except_error) + __PYX_ERR(0, 210, __pyx_L15_except_error) } goto __pyx_L15_except_error; __pyx_L15_except_error:; - /* "pysam/libcutils.pyx":205 + /* "pysam/libcutils.pyx":207 * * if end != None: * try: # <<<<<<<<<<<<<< @@ -4223,7 +4217,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __pyx_L18_try_end:; } - /* "pysam/libcutils.pyx":204 + /* "pysam/libcutils.pyx":206 * raise ValueError('start out of range (%i)' % start) * * if end != None: # <<<<<<<<<<<<<< @@ -4232,38 +4226,38 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ */ } - /* "pysam/libcutils.pyx":210 + /* "pysam/libcutils.pyx":212 * raise ValueError('end out of range (%i)' % end) * * if region: # <<<<<<<<<<<<<< * region = force_str(region) * parts = re.split("[:-]", region) */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 210, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 212, __pyx_L1_error) if (__pyx_t_2) { - /* "pysam/libcutils.pyx":211 + /* "pysam/libcutils.pyx":213 * * if region: * region = force_str(region) # <<<<<<<<<<<<<< * parts = re.split("[:-]", region) * reference = parts[0] */ - __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_region, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 211, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_region, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 213, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_region, __pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcutils.pyx":212 + /* "pysam/libcutils.pyx":214 * if region: * region = force_str(region) * parts = re.split("[:-]", region) # <<<<<<<<<<<<<< * reference = parts[0] * if len(parts) >= 2: */ - __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 212, __pyx_L1_error) + __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_split); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 212, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_split); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = NULL; @@ -4281,7 +4275,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_9)) { PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_kp_s__4, __pyx_v_region}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 212, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -4289,13 +4283,13 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_kp_s__4, __pyx_v_region}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 212, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_10 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 212, __pyx_L1_error) + __pyx_t_10 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); if (__pyx_t_8) { __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL; @@ -4306,7 +4300,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __Pyx_INCREF(__pyx_v_region); __Pyx_GIVEREF(__pyx_v_region); PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_7, __pyx_v_region); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 212, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } @@ -4314,49 +4308,49 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __pyx_v_parts = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcutils.pyx":213 + /* "pysam/libcutils.pyx":215 * region = force_str(region) * parts = re.split("[:-]", region) * reference = parts[0] # <<<<<<<<<<<<<< * if len(parts) >= 2: * rstart = int(parts[1]) - 1 */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 213, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_reference, __pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcutils.pyx":214 + /* "pysam/libcutils.pyx":216 * parts = re.split("[:-]", region) * reference = parts[0] * if len(parts) >= 2: # <<<<<<<<<<<<<< * rstart = int(parts[1]) - 1 * if len(parts) >= 3: */ - __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 214, __pyx_L1_error) + __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 216, __pyx_L1_error) __pyx_t_2 = ((__pyx_t_12 >= 2) != 0); if (__pyx_t_2) { - /* "pysam/libcutils.pyx":215 + /* "pysam/libcutils.pyx":217 * reference = parts[0] * if len(parts) >= 2: * rstart = int(parts[1]) - 1 # <<<<<<<<<<<<<< * if len(parts) >= 3: * rend = int(parts[2]) */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 217, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_t_9, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_t_9, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 217, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_rstart = __pyx_t_6; - /* "pysam/libcutils.pyx":214 + /* "pysam/libcutils.pyx":216 * parts = re.split("[:-]", region) * reference = parts[0] * if len(parts) >= 2: # <<<<<<<<<<<<<< @@ -4365,34 +4359,34 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ */ } - /* "pysam/libcutils.pyx":216 + /* "pysam/libcutils.pyx":218 * if len(parts) >= 2: * rstart = int(parts[1]) - 1 * if len(parts) >= 3: # <<<<<<<<<<<<<< * rend = int(parts[2]) * */ - __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 216, __pyx_L1_error) + __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 218, __pyx_L1_error) __pyx_t_2 = ((__pyx_t_12 >= 3) != 0); if (__pyx_t_2) { - /* "pysam/libcutils.pyx":217 + /* "pysam/libcutils.pyx":219 * rstart = int(parts[1]) - 1 * if len(parts) >= 3: * rend = int(parts[2]) # <<<<<<<<<<<<<< * * if not reference: */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 217, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_9); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 217, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_t_9); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 219, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_rend = __pyx_t_6; - /* "pysam/libcutils.pyx":216 + /* "pysam/libcutils.pyx":218 * if len(parts) >= 2: * rstart = int(parts[1]) - 1 * if len(parts) >= 3: # <<<<<<<<<<<<<< @@ -4401,7 +4395,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ */ } - /* "pysam/libcutils.pyx":210 + /* "pysam/libcutils.pyx":212 * raise ValueError('end out of range (%i)' % end) * * if region: # <<<<<<<<<<<<<< @@ -4410,18 +4404,18 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ */ } - /* "pysam/libcutils.pyx":219 + /* "pysam/libcutils.pyx":221 * rend = int(parts[2]) * * if not reference: # <<<<<<<<<<<<<< * return None, 0, 0 * */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 219, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 221, __pyx_L1_error) __pyx_t_13 = ((!__pyx_t_2) != 0); if (__pyx_t_13) { - /* "pysam/libcutils.pyx":220 + /* "pysam/libcutils.pyx":222 * * if not reference: * return None, 0, 0 # <<<<<<<<<<<<<< @@ -4433,7 +4427,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __pyx_r = __pyx_tuple__5; goto __pyx_L0; - /* "pysam/libcutils.pyx":219 + /* "pysam/libcutils.pyx":221 * rend = int(parts[2]) * * if not reference: # <<<<<<<<<<<<<< @@ -4442,7 +4436,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ */ } - /* "pysam/libcutils.pyx":222 + /* "pysam/libcutils.pyx":224 * return None, 0, 0 * * if not 0 <= rstart < MAX_POS: # <<<<<<<<<<<<<< @@ -4456,26 +4450,26 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __pyx_t_2 = ((!(__pyx_t_13 != 0)) != 0); if (unlikely(__pyx_t_2)) { - /* "pysam/libcutils.pyx":223 + /* "pysam/libcutils.pyx":225 * * if not 0 <= rstart < MAX_POS: * raise ValueError('start out of range (%i)' % rstart) # <<<<<<<<<<<<<< * if not 0 <= rend <= MAX_POS: * raise ValueError('end out of range (%i)' % rend) */ - __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 223, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 225, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 223, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 225, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 223, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 225, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_9, 0, 0, 0); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __PYX_ERR(0, 223, __pyx_L1_error) + __PYX_ERR(0, 225, __pyx_L1_error) - /* "pysam/libcutils.pyx":222 + /* "pysam/libcutils.pyx":224 * return None, 0, 0 * * if not 0 <= rstart < MAX_POS: # <<<<<<<<<<<<<< @@ -4484,7 +4478,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ */ } - /* "pysam/libcutils.pyx":224 + /* "pysam/libcutils.pyx":226 * if not 0 <= rstart < MAX_POS: * raise ValueError('start out of range (%i)' % rstart) * if not 0 <= rend <= MAX_POS: # <<<<<<<<<<<<<< @@ -4498,26 +4492,26 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __pyx_t_13 = ((!(__pyx_t_2 != 0)) != 0); if (unlikely(__pyx_t_13)) { - /* "pysam/libcutils.pyx":225 + /* "pysam/libcutils.pyx":227 * raise ValueError('start out of range (%i)' % rstart) * if not 0 <= rend <= MAX_POS: * raise ValueError('end out of range (%i)' % rend) # <<<<<<<<<<<<<< * if rstart > rend: * raise ValueError( */ - __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 225, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 227, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_end_out_of_range_i, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 225, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_end_out_of_range_i, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 227, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 225, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 227, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_9, 0, 0, 0); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __PYX_ERR(0, 225, __pyx_L1_error) + __PYX_ERR(0, 227, __pyx_L1_error) - /* "pysam/libcutils.pyx":224 + /* "pysam/libcutils.pyx":226 * if not 0 <= rstart < MAX_POS: * raise ValueError('start out of range (%i)' % rstart) * if not 0 <= rend <= MAX_POS: # <<<<<<<<<<<<<< @@ -4526,7 +4520,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ */ } - /* "pysam/libcutils.pyx":226 + /* "pysam/libcutils.pyx":228 * if not 0 <= rend <= MAX_POS: * raise ValueError('end out of range (%i)' % rend) * if rstart > rend: # <<<<<<<<<<<<<< @@ -4536,18 +4530,18 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __pyx_t_13 = ((__pyx_v_rstart > __pyx_v_rend) != 0); if (unlikely(__pyx_t_13)) { - /* "pysam/libcutils.pyx":228 + /* "pysam/libcutils.pyx":230 * if rstart > rend: * raise ValueError( * 'invalid region: start (%i) > end (%i)' % (rstart, rend)) # <<<<<<<<<<<<<< * * return force_bytes(reference), rstart, rend */ - __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 228, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 230, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 228, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 230, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 228, __pyx_L1_error) + __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 230, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); @@ -4555,25 +4549,25 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); __pyx_t_9 = 0; __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_invalid_region_start_i_end_i, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 228, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_invalid_region_start_i_end_i, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 230, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - /* "pysam/libcutils.pyx":227 + /* "pysam/libcutils.pyx":229 * raise ValueError('end out of range (%i)' % rend) * if rstart > rend: * raise ValueError( # <<<<<<<<<<<<<< * 'invalid region: start (%i) > end (%i)' % (rstart, rend)) * */ - __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 227, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 229, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_10, 0, 0, 0); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __PYX_ERR(0, 227, __pyx_L1_error) + __PYX_ERR(0, 229, __pyx_L1_error) - /* "pysam/libcutils.pyx":226 + /* "pysam/libcutils.pyx":228 * if not 0 <= rend <= MAX_POS: * raise ValueError('end out of range (%i)' % rend) * if rstart > rend: # <<<<<<<<<<<<<< @@ -4582,7 +4576,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ */ } - /* "pysam/libcutils.pyx":230 + /* "pysam/libcutils.pyx":232 * 'invalid region: start (%i) > end (%i)' % (rstart, rend)) * * return force_bytes(reference), rstart, rend # <<<<<<<<<<<<<< @@ -4590,13 +4584,13 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_10 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_reference, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 230, __pyx_L1_error) + __pyx_t_10 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_reference, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); - __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 230, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 230, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 230, __pyx_L1_error) + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_10); @@ -4611,7 +4605,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ __pyx_t_8 = 0; goto __pyx_L0; - /* "pysam/libcutils.pyx":161 + /* "pysam/libcutils.pyx":167 * * * cpdef parse_region(reference=None, # <<<<<<<<<<<<<< @@ -4639,7 +4633,7 @@ static PyObject *__pyx_f_5pysam_9libcutils_parse_region(CYTHON_UNUSED int __pyx_ /* Python wrapper */ static PyObject *__pyx_pw_5pysam_9libcutils_7parse_region(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libcutils_6parse_region[] = "parse alternative ways to specify a genomic region. A region can\n either be specified by :term:`reference`, `start` and\n `end`. `start` and `end` denote 0-based, half-open\n intervals.\n\n Alternatively, a samtools :term:`region` string can be\n supplied.\n\n If any of the coordinates are missing they will be replaced by the\n minimum (`start`) or maximum (`end`) coordinate.\n\n Note that region strings are 1-based, while `start` and `end` denote\n an interval in python coordinates.\n\n Returns\n -------\n\n tuple : a tuple of `reference`, `start` and `end`.\n\n Raises\n ------\n\n ValueError\n for invalid or out of bounds regions.\n\n "; +static char __pyx_doc_5pysam_9libcutils_6parse_region[] = "parse alternative ways to specify a genomic region. A region can\n either be specified by :term:`reference`, `start` and\n `end`. `start` and `end` denote 0-based, half-open intervals.\n\n Alternatively, a samtools :term:`region` string can be supplied.\n\n If any of the coordinates are missing they will be replaced by the\n minimum (`start`) or maximum (`end`) coordinate.\n\n Note that region strings are 1-based, while `start` and `end`\n denote an interval in python coordinates.\n\n Returns\n -------\n\n tuple : a tuple of `reference`, `start` and `end`.\n\n Raises\n ------\n\n ValueError\n for invalid or out of bounds regions.\n\n "; static PyObject *__pyx_pw_5pysam_9libcutils_7parse_region(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_reference = 0; PyObject *__pyx_v_start = 0; @@ -4653,7 +4647,7 @@ static PyObject *__pyx_pw_5pysam_9libcutils_7parse_region(PyObject *__pyx_self, PyObject* values[4] = {0,0,0,0}; values[0] = ((PyObject *)Py_None); - /* "pysam/libcutils.pyx":162 + /* "pysam/libcutils.pyx":168 * * cpdef parse_region(reference=None, * start=None, # <<<<<<<<<<<<<< @@ -4662,7 +4656,7 @@ static PyObject *__pyx_pw_5pysam_9libcutils_7parse_region(PyObject *__pyx_self, */ values[1] = ((PyObject *)Py_None); - /* "pysam/libcutils.pyx":163 + /* "pysam/libcutils.pyx":169 * cpdef parse_region(reference=None, * start=None, * end=None, # <<<<<<<<<<<<<< @@ -4671,7 +4665,7 @@ static PyObject *__pyx_pw_5pysam_9libcutils_7parse_region(PyObject *__pyx_self, */ values[2] = ((PyObject *)Py_None); - /* "pysam/libcutils.pyx":164 + /* "pysam/libcutils.pyx":170 * start=None, * end=None, * region=None): # <<<<<<<<<<<<<< @@ -4721,7 +4715,7 @@ static PyObject *__pyx_pw_5pysam_9libcutils_7parse_region(PyObject *__pyx_self, } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "parse_region") < 0)) __PYX_ERR(0, 161, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "parse_region") < 0)) __PYX_ERR(0, 167, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -4744,7 +4738,7 @@ static PyObject *__pyx_pw_5pysam_9libcutils_7parse_region(PyObject *__pyx_self, } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("parse_region", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 161, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("parse_region", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 167, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcutils.parse_region", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -4752,7 +4746,7 @@ static PyObject *__pyx_pw_5pysam_9libcutils_7parse_region(PyObject *__pyx_self, __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_5pysam_9libcutils_6parse_region(__pyx_self, __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region); - /* "pysam/libcutils.pyx":161 + /* "pysam/libcutils.pyx":167 * * * cpdef parse_region(reference=None, # <<<<<<<<<<<<<< @@ -4777,7 +4771,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_6parse_region(CYTHON_UNUSED PyObject __pyx_t_2.start = __pyx_v_start; __pyx_t_2.end = __pyx_v_end; __pyx_t_2.region = __pyx_v_region; - __pyx_t_1 = __pyx_f_5pysam_9libcutils_parse_region(0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error) + __pyx_t_1 = __pyx_f_5pysam_9libcutils_parse_region(0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 167, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -4794,7 +4788,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_6parse_region(CYTHON_UNUSED PyObject return __pyx_r; } -/* "pysam/libcutils.pyx":233 +/* "pysam/libcutils.pyx":235 * * * def _pysam_dispatch(collection, # <<<<<<<<<<<<<< @@ -4804,51 +4798,63 @@ static PyObject *__pyx_pf_5pysam_9libcutils_6parse_region(CYTHON_UNUSED PyObject /* Python wrapper */ static PyObject *__pyx_pw_5pysam_9libcutils_9_pysam_dispatch(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_5pysam_9libcutils_8_pysam_dispatch[] = "call ``method`` in samtools/bcftools providing arguments in args.\n \n Catching of stdout can be turned off by setting *catch_stdout* to\n False.\n\n "; +static char __pyx_doc_5pysam_9libcutils_8_pysam_dispatch[] = "call ``method`` in samtools/bcftools providing arguments in args.\n \n By default, stdout is redirected to a temporary file using the patched\n C sources except for a few commands that have an explicit output option\n (typically: -o). In these commands (such as samtools view), this explicit\n option is used. If *is_usage* is True, then these explicit output options\n will not be used.\n\n Catching of stdout can be turned off by setting *catch_stdout* to\n False.\n "; static PyMethodDef __pyx_mdef_5pysam_9libcutils_9_pysam_dispatch = {"_pysam_dispatch", (PyCFunction)__pyx_pw_5pysam_9libcutils_9_pysam_dispatch, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_9libcutils_8_pysam_dispatch}; static PyObject *__pyx_pw_5pysam_9libcutils_9_pysam_dispatch(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_collection = 0; PyObject *__pyx_v_method = 0; PyObject *__pyx_v_args = 0; PyObject *__pyx_v_catch_stdout = 0; + PyObject *__pyx_v_is_usage = 0; PyObject *__pyx_v_save_stdout = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("_pysam_dispatch (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_collection,&__pyx_n_s_method,&__pyx_n_s_args,&__pyx_n_s_catch_stdout,&__pyx_n_s_save_stdout,0}; - PyObject* values[5] = {0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_collection,&__pyx_n_s_method,&__pyx_n_s_args,&__pyx_n_s_catch_stdout,&__pyx_n_s_is_usage,&__pyx_n_s_save_stdout,0}; + PyObject* values[6] = {0,0,0,0,0,0}; - /* "pysam/libcutils.pyx":235 + /* "pysam/libcutils.pyx":237 * def _pysam_dispatch(collection, * method, * args=None, # <<<<<<<<<<<<<< * catch_stdout=True, - * save_stdout=None): + * is_usage=False, */ values[2] = ((PyObject *)Py_None); - /* "pysam/libcutils.pyx":236 + /* "pysam/libcutils.pyx":238 * method, * args=None, * catch_stdout=True, # <<<<<<<<<<<<<< + * is_usage=False, * save_stdout=None): - * '''call ``method`` in samtools/bcftools providing arguments in args. */ values[3] = ((PyObject *)Py_True); - /* "pysam/libcutils.pyx":237 + /* "pysam/libcutils.pyx":239 * args=None, * catch_stdout=True, + * is_usage=False, # <<<<<<<<<<<<<< + * save_stdout=None): + * '''call ``method`` in samtools/bcftools providing arguments in args. + */ + values[4] = ((PyObject *)Py_False); + + /* "pysam/libcutils.pyx":240 + * catch_stdout=True, + * is_usage=False, * save_stdout=None): # <<<<<<<<<<<<<< * '''call ``method`` in samtools/bcftools providing arguments in args. * */ - values[4] = ((PyObject *)Py_None); + values[5] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -4871,7 +4877,7 @@ static PyObject *__pyx_pw_5pysam_9libcutils_9_pysam_dispatch(PyObject *__pyx_sel case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_method)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_pysam_dispatch", 0, 2, 5, 1); __PYX_ERR(0, 233, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_pysam_dispatch", 0, 2, 6, 1); __PYX_ERR(0, 235, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: @@ -4888,15 +4894,23 @@ static PyObject *__pyx_pw_5pysam_9libcutils_9_pysam_dispatch(PyObject *__pyx_sel CYTHON_FALLTHROUGH; case 4: if (kw_args > 0) { - PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_save_stdout); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_is_usage); if (value) { values[4] = value; kw_args--; } } + CYTHON_FALLTHROUGH; + case 5: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_save_stdout); + if (value) { values[5] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_pysam_dispatch") < 0)) __PYX_ERR(0, 233, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_pysam_dispatch") < 0)) __PYX_ERR(0, 235, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); @@ -4913,19 +4927,20 @@ static PyObject *__pyx_pw_5pysam_9libcutils_9_pysam_dispatch(PyObject *__pyx_sel __pyx_v_method = values[1]; __pyx_v_args = values[2]; __pyx_v_catch_stdout = values[3]; - __pyx_v_save_stdout = values[4]; + __pyx_v_is_usage = values[4]; + __pyx_v_save_stdout = values[5]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_pysam_dispatch", 0, 2, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 233, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_pysam_dispatch", 0, 2, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 235, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("pysam.libcutils._pysam_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5pysam_9libcutils_8_pysam_dispatch(__pyx_self, __pyx_v_collection, __pyx_v_method, __pyx_v_args, __pyx_v_catch_stdout, __pyx_v_save_stdout); + __pyx_r = __pyx_pf_5pysam_9libcutils_8_pysam_dispatch(__pyx_self, __pyx_v_collection, __pyx_v_method, __pyx_v_args, __pyx_v_catch_stdout, __pyx_v_is_usage, __pyx_v_save_stdout); - /* "pysam/libcutils.pyx":233 + /* "pysam/libcutils.pyx":235 * * * def _pysam_dispatch(collection, # <<<<<<<<<<<<<< @@ -4938,7 +4953,7 @@ static PyObject *__pyx_pw_5pysam_9libcutils_9_pysam_dispatch(PyObject *__pyx_sel return __pyx_r; } -/* "pysam/libcutils.pyx":345 +/* "pysam/libcutils.pyx":361 * * # get error messages * def _collect(fn): # <<<<<<<<<<<<<< @@ -4987,19 +5002,19 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN char const *__pyx_t_20; __Pyx_RefNannySetupContext("_collect", 0); - /* "pysam/libcutils.pyx":346 + /* "pysam/libcutils.pyx":362 * # get error messages * def _collect(fn): * out = [] # <<<<<<<<<<<<<< * try: * with open(fn, "r") as inf: */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 346, __pyx_L1_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 362, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_out = __pyx_t_1; __pyx_t_1 = 0; - /* "pysam/libcutils.pyx":347 + /* "pysam/libcutils.pyx":363 * def _collect(fn): * out = [] * try: # <<<<<<<<<<<<<< @@ -5016,7 +5031,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __Pyx_XGOTREF(__pyx_t_4); /*try:*/ { - /* "pysam/libcutils.pyx":348 + /* "pysam/libcutils.pyx":364 * out = [] * try: * with open(fn, "r") as inf: # <<<<<<<<<<<<<< @@ -5024,7 +5039,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN * except UnicodeDecodeError: */ /*with:*/ { - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 348, __pyx_L6_error) + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_fn); __Pyx_GIVEREF(__pyx_v_fn); @@ -5032,12 +5047,12 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __Pyx_INCREF(__pyx_n_s_r); __Pyx_GIVEREF(__pyx_n_s_r); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_r); - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 348, __pyx_L6_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 364, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 348, __pyx_L6_error) + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 364, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_enter); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 348, __pyx_L12_error) + __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_enter); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 364, __pyx_L12_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { @@ -5050,10 +5065,10 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN } } if (__pyx_t_8) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 348, __pyx_L12_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L12_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 348, __pyx_L12_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L12_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; @@ -5072,14 +5087,14 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __pyx_v_inf = __pyx_t_7; __pyx_t_7 = 0; - /* "pysam/libcutils.pyx":349 + /* "pysam/libcutils.pyx":365 * try: * with open(fn, "r") as inf: * out = inf.read() # <<<<<<<<<<<<<< * except UnicodeDecodeError: * with open(fn, "rb") as inf: */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_inf, __pyx_n_s_read); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 349, __pyx_L16_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_inf, __pyx_n_s_read); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 365, __pyx_L16_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_1 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { @@ -5092,17 +5107,17 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN } } if (__pyx_t_1) { - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 349, __pyx_L16_error) + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 365, __pyx_L16_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { - __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 349, __pyx_L16_error) + __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 365, __pyx_L16_error) } __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF_SET(__pyx_v_out, __pyx_t_7); __pyx_t_7 = 0; - /* "pysam/libcutils.pyx":348 + /* "pysam/libcutils.pyx":364 * out = [] * try: * with open(fn, "r") as inf: # <<<<<<<<<<<<<< @@ -5121,20 +5136,20 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; /*except:*/ { __Pyx_AddTraceback("pysam.libcutils._pysam_dispatch._collect", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_5, &__pyx_t_1) < 0) __PYX_ERR(0, 348, __pyx_L18_except_error) + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_5, &__pyx_t_1) < 0) __PYX_ERR(0, 364, __pyx_L18_except_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GOTREF(__pyx_t_5); __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = PyTuple_Pack(3, __pyx_t_7, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 348, __pyx_L18_except_error) + __pyx_t_8 = PyTuple_Pack(3, __pyx_t_7, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 364, __pyx_L18_except_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 348, __pyx_L18_except_error) + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 364, __pyx_L18_except_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_12); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (__pyx_t_13 < 0) __PYX_ERR(0, 348, __pyx_L18_except_error) + if (__pyx_t_13 < 0) __PYX_ERR(0, 364, __pyx_L18_except_error) __pyx_t_14 = ((!(__pyx_t_13 != 0)) != 0); if (__pyx_t_14) { __Pyx_GIVEREF(__pyx_t_7); @@ -5142,7 +5157,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __Pyx_XGIVEREF(__pyx_t_1); __Pyx_ErrRestoreWithState(__pyx_t_7, __pyx_t_5, __pyx_t_1); __pyx_t_7 = 0; __pyx_t_5 = 0; __pyx_t_1 = 0; - __PYX_ERR(0, 348, __pyx_L18_except_error) + __PYX_ERR(0, 364, __pyx_L18_except_error) } __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; @@ -5168,7 +5183,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN if (__pyx_t_6) { __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__6, NULL); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 348, __pyx_L6_error) + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 364, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } @@ -5183,7 +5198,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __pyx_L25:; } - /* "pysam/libcutils.pyx":347 + /* "pysam/libcutils.pyx":363 * def _collect(fn): * out = [] * try: # <<<<<<<<<<<<<< @@ -5201,7 +5216,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pysam/libcutils.pyx":350 + /* "pysam/libcutils.pyx":366 * with open(fn, "r") as inf: * out = inf.read() * except UnicodeDecodeError: # <<<<<<<<<<<<<< @@ -5211,12 +5226,12 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_UnicodeDecodeError); if (__pyx_t_15) { __Pyx_AddTraceback("pysam.libcutils._pysam_dispatch._collect", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_5, &__pyx_t_7) < 0) __PYX_ERR(0, 350, __pyx_L8_except_error) + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_5, &__pyx_t_7) < 0) __PYX_ERR(0, 366, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GOTREF(__pyx_t_5); __Pyx_GOTREF(__pyx_t_7); - /* "pysam/libcutils.pyx":351 + /* "pysam/libcutils.pyx":367 * out = inf.read() * except UnicodeDecodeError: * with open(fn, "rb") as inf: # <<<<<<<<<<<<<< @@ -5224,7 +5239,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN * out = inf.read() */ /*with:*/ { - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 351, __pyx_L8_except_error) + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 367, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_INCREF(__pyx_v_fn); __Pyx_GIVEREF(__pyx_v_fn); @@ -5232,12 +5247,12 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __Pyx_INCREF(__pyx_n_s_rb); __Pyx_GIVEREF(__pyx_n_s_rb); PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_n_s_rb); - __pyx_t_16 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_8, NULL); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 351, __pyx_L8_except_error) + __pyx_t_16 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_8, NULL); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 367, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_16); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_16, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 351, __pyx_L8_except_error) + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_16, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 367, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_6); - __pyx_t_17 = __Pyx_PyObject_LookupSpecial(__pyx_t_16, __pyx_n_s_enter); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 351, __pyx_L28_error) + __pyx_t_17 = __Pyx_PyObject_LookupSpecial(__pyx_t_16, __pyx_n_s_enter); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 367, __pyx_L28_error) __Pyx_GOTREF(__pyx_t_17); __pyx_t_18 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_17))) { @@ -5250,10 +5265,10 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN } } if (__pyx_t_18) { - __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_17, __pyx_t_18); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 351, __pyx_L28_error) + __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_17, __pyx_t_18); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 367, __pyx_L28_error) __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; } else { - __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 351, __pyx_L28_error) + __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 367, __pyx_L28_error) } __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; @@ -5272,14 +5287,14 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __Pyx_XDECREF_SET(__pyx_v_inf, __pyx_t_17); __pyx_t_17 = 0; - /* "pysam/libcutils.pyx":353 + /* "pysam/libcutils.pyx":369 * with open(fn, "rb") as inf: * # read binary output * out = inf.read() # <<<<<<<<<<<<<< * finally: * os.remove(fn) */ - __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_inf, __pyx_n_s_read); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 353, __pyx_L34_error) + __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_inf, __pyx_n_s_read); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 369, __pyx_L34_error) __Pyx_GOTREF(__pyx_t_16); __pyx_t_8 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_16))) { @@ -5292,17 +5307,17 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN } } if (__pyx_t_8) { - __pyx_t_17 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_8); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 353, __pyx_L34_error) + __pyx_t_17 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_8); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 369, __pyx_L34_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } else { - __pyx_t_17 = __Pyx_PyObject_CallNoArg(__pyx_t_16); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 353, __pyx_L34_error) + __pyx_t_17 = __Pyx_PyObject_CallNoArg(__pyx_t_16); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 369, __pyx_L34_error) } __Pyx_GOTREF(__pyx_t_17); __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; __Pyx_DECREF_SET(__pyx_v_out, __pyx_t_17); __pyx_t_17 = 0; - /* "pysam/libcutils.pyx":351 + /* "pysam/libcutils.pyx":367 * out = inf.read() * except UnicodeDecodeError: * with open(fn, "rb") as inf: # <<<<<<<<<<<<<< @@ -5321,20 +5336,20 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; /*except:*/ { __Pyx_AddTraceback("pysam.libcutils._pysam_dispatch._collect", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_17, &__pyx_t_16, &__pyx_t_8) < 0) __PYX_ERR(0, 351, __pyx_L36_except_error) + if (__Pyx_GetException(&__pyx_t_17, &__pyx_t_16, &__pyx_t_8) < 0) __PYX_ERR(0, 367, __pyx_L36_except_error) __Pyx_GOTREF(__pyx_t_17); __Pyx_GOTREF(__pyx_t_16); __Pyx_GOTREF(__pyx_t_8); - __pyx_t_18 = PyTuple_Pack(3, __pyx_t_17, __pyx_t_16, __pyx_t_8); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 351, __pyx_L36_except_error) + __pyx_t_18 = PyTuple_Pack(3, __pyx_t_17, __pyx_t_16, __pyx_t_8); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 367, __pyx_L36_except_error) __Pyx_GOTREF(__pyx_t_18); __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_18, NULL); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 351, __pyx_L36_except_error) + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 367, __pyx_L36_except_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_12); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (__pyx_t_14 < 0) __PYX_ERR(0, 351, __pyx_L36_except_error) + if (__pyx_t_14 < 0) __PYX_ERR(0, 367, __pyx_L36_except_error) __pyx_t_13 = ((!(__pyx_t_14 != 0)) != 0); if (__pyx_t_13) { __Pyx_GIVEREF(__pyx_t_17); @@ -5342,7 +5357,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __Pyx_XGIVEREF(__pyx_t_8); __Pyx_ErrRestoreWithState(__pyx_t_17, __pyx_t_16, __pyx_t_8); __pyx_t_17 = 0; __pyx_t_16 = 0; __pyx_t_8 = 0; - __PYX_ERR(0, 351, __pyx_L36_except_error) + __PYX_ERR(0, 367, __pyx_L36_except_error) } __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; @@ -5368,7 +5383,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN if (__pyx_t_6) { __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__7, NULL); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 351, __pyx_L8_except_error) + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 367, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } @@ -5390,7 +5405,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN goto __pyx_L8_except_error; __pyx_L8_except_error:; - /* "pysam/libcutils.pyx":347 + /* "pysam/libcutils.pyx":363 * def _collect(fn): * out = [] * try: # <<<<<<<<<<<<<< @@ -5411,7 +5426,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN } } - /* "pysam/libcutils.pyx":355 + /* "pysam/libcutils.pyx":371 * out = inf.read() * finally: * os.remove(fn) # <<<<<<<<<<<<<< @@ -5420,9 +5435,9 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN */ /*finally:*/ { /*normal exit:*/{ - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 355, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 371, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_remove); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 355, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_remove); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 371, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = NULL; @@ -5436,13 +5451,13 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN } } if (!__pyx_t_5) { - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_fn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_fn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_fn}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_7); } else @@ -5450,19 +5465,19 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_fn}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_7); } else #endif { - __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 355, __pyx_L1_error) + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 371, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_INCREF(__pyx_v_fn); __Pyx_GIVEREF(__pyx_v_fn); PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_fn); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } @@ -5493,9 +5508,9 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __Pyx_XGOTREF(__pyx_t_10); __pyx_t_15 = __pyx_lineno; __pyx_t_19 = __pyx_clineno; __pyx_t_20 = __pyx_filename; { - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 355, __pyx_L47_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 371, __pyx_L47_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_remove); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 355, __pyx_L47_error) + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_remove); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 371, __pyx_L47_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = NULL; @@ -5509,13 +5524,13 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN } } if (!__pyx_t_1) { - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_fn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L47_error) + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_fn); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L47_error) __Pyx_GOTREF(__pyx_t_7); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_8)) { PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_fn}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L47_error) + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L47_error) __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GOTREF(__pyx_t_7); } else @@ -5523,19 +5538,19 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_fn}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L47_error) + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L47_error) __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GOTREF(__pyx_t_7); } else #endif { - __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 355, __pyx_L47_error) + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 371, __pyx_L47_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); __pyx_t_1 = NULL; __Pyx_INCREF(__pyx_v_fn); __Pyx_GIVEREF(__pyx_v_fn); PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_fn); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_5, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L47_error) + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_5, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L47_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } @@ -5572,19 +5587,19 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN __pyx_L5:; } - /* "pysam/libcutils.pyx":356 + /* "pysam/libcutils.pyx":372 * finally: * os.remove(fn) * return out # <<<<<<<<<<<<<< * - * pysam_unset_stderr() + * samtools_unset_stderr() */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_out); __pyx_r = __pyx_v_out; goto __pyx_L0; - /* "pysam/libcutils.pyx":345 + /* "pysam/libcutils.pyx":361 * * # get error messages * def _collect(fn): # <<<<<<<<<<<<<< @@ -5611,7 +5626,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN return __pyx_r; } -/* "pysam/libcutils.pyx":233 +/* "pysam/libcutils.pyx":235 * * * def _pysam_dispatch(collection, # <<<<<<<<<<<<<< @@ -5619,7 +5634,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(CYTHON_UN * args=None, */ -static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_collection, PyObject *__pyx_v_method, PyObject *__pyx_v_args, PyObject *__pyx_v_catch_stdout, PyObject *__pyx_v_save_stdout) { +static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_collection, PyObject *__pyx_v_method, PyObject *__pyx_v_args, PyObject *__pyx_v_catch_stdout, PyObject *__pyx_v_is_usage, PyObject *__pyx_v_save_stdout) { PyObject *__pyx_v_stderr_h = NULL; PyObject *__pyx_v_stderr_f = NULL; PyObject *__pyx_v_stdout_f = NULL; @@ -5639,175 +5654,184 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; + int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - PyObject *(*__pyx_t_8)(PyObject *); - int __pyx_t_9; - char *__pyx_t_10; - char const *__pyx_t_11; - int __pyx_t_12; - PyObject *__pyx_t_13 = NULL; - Py_ssize_t __pyx_t_14; - PyObject *(*__pyx_t_15)(PyObject *); - char const *__pyx_t_16; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_t_10; + char *__pyx_t_11; + char const *__pyx_t_12; + char const *__pyx_t_13; + PyObject *__pyx_t_14 = NULL; + Py_ssize_t __pyx_t_15; + PyObject *(*__pyx_t_16)(PyObject *); + char const *__pyx_t_17; __Pyx_RefNannySetupContext("_pysam_dispatch", 0); __Pyx_INCREF(__pyx_v_collection); __Pyx_INCREF(__pyx_v_method); __Pyx_INCREF(__pyx_v_args); - /* "pysam/libcutils.pyx":245 + /* "pysam/libcutils.pyx":253 * ''' * * if method == "index": # <<<<<<<<<<<<<< - * if not os.path.exists(args[0]): + * if args and not os.path.exists(args[0]): * raise IOError("No such file or directory: '%s'" % args[0]) */ - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_index, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 245, __pyx_L1_error) + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_index, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 253, __pyx_L1_error) if (__pyx_t_1) { - /* "pysam/libcutils.pyx":246 + /* "pysam/libcutils.pyx":254 * * if method == "index": - * if not os.path.exists(args[0]): # <<<<<<<<<<<<<< + * if args and not os.path.exists(args[0]): # <<<<<<<<<<<<<< * raise IOError("No such file or directory: '%s'" % args[0]) * */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_path); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 246, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_args); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 254, __pyx_L1_error) + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 254, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exists); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_path); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_args, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 246, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_exists); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 254, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_args, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); + __Pyx_DECREF_SET(__pyx_t_4, function); } } - if (!__pyx_t_5) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GOTREF(__pyx_t_2); + if (!__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 254, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 254, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 254, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 254, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 254, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 246, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = ((!__pyx_t_1) != 0); - if (unlikely(__pyx_t_7)) { + __pyx_t_8 = ((!__pyx_t_2) != 0); + __pyx_t_1 = __pyx_t_8; + __pyx_L5_bool_binop_done:; + if (unlikely(__pyx_t_1)) { - /* "pysam/libcutils.pyx":247 + /* "pysam/libcutils.pyx":255 * if method == "index": - * if not os.path.exists(args[0]): + * if args and not os.path.exists(args[0]): * raise IOError("No such file or directory: '%s'" % args[0]) # <<<<<<<<<<<<<< * * if args is None: */ - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_args, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_No_such_file_or_directory_s, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 247, __pyx_L1_error) + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_args, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 255, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 247, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_No_such_file_or_directory_s, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 255, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 255, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 247, __pyx_L1_error) + __PYX_ERR(0, 255, __pyx_L1_error) - /* "pysam/libcutils.pyx":246 + /* "pysam/libcutils.pyx":254 * * if method == "index": - * if not os.path.exists(args[0]): # <<<<<<<<<<<<<< + * if args and not os.path.exists(args[0]): # <<<<<<<<<<<<<< * raise IOError("No such file or directory: '%s'" % args[0]) * */ } - /* "pysam/libcutils.pyx":245 + /* "pysam/libcutils.pyx":253 * ''' * * if method == "index": # <<<<<<<<<<<<<< - * if not os.path.exists(args[0]): + * if args and not os.path.exists(args[0]): * raise IOError("No such file or directory: '%s'" % args[0]) */ } - /* "pysam/libcutils.pyx":249 + /* "pysam/libcutils.pyx":257 * raise IOError("No such file or directory: '%s'" % args[0]) * * if args is None: # <<<<<<<<<<<<<< * args = [] * else: */ - __pyx_t_7 = (__pyx_v_args == Py_None); - __pyx_t_1 = (__pyx_t_7 != 0); - if (__pyx_t_1) { + __pyx_t_1 = (__pyx_v_args == Py_None); + __pyx_t_8 = (__pyx_t_1 != 0); + if (__pyx_t_8) { - /* "pysam/libcutils.pyx":250 + /* "pysam/libcutils.pyx":258 * * if args is None: * args = [] # <<<<<<<<<<<<<< * else: * args = list(args) */ - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 250, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_2); - __pyx_t_2 = 0; + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 258, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcutils.pyx":249 + /* "pysam/libcutils.pyx":257 * raise IOError("No such file or directory: '%s'" % args[0]) * * if args is None: # <<<<<<<<<<<<<< * args = [] * else: */ - goto __pyx_L5; + goto __pyx_L7; } - /* "pysam/libcutils.pyx":252 + /* "pysam/libcutils.pyx":260 * args = [] * else: * args = list(args) # <<<<<<<<<<<<<< @@ -5815,115 +5839,125 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj * # redirect stderr to file */ /*else*/ { - __pyx_t_2 = PySequence_List(__pyx_v_args); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 252, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_2); - __pyx_t_2 = 0; + __pyx_t_3 = PySequence_List(__pyx_v_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_3); + __pyx_t_3 = 0; } - __pyx_L5:; + __pyx_L7:; - /* "pysam/libcutils.pyx":255 + /* "pysam/libcutils.pyx":263 * * # redirect stderr to file * stderr_h, stderr_f = tempfile.mkstemp() # <<<<<<<<<<<<<< - * pysam_set_stderr(stderr_h) - * + * samtools_set_stderr(stderr_h) + * bcftools_set_stderr(stderr_h) */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_tempfile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 255, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_mkstemp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 255, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); - __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_tempfile); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_mkstemp); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_6, function); + __Pyx_DECREF_SET(__pyx_t_7, function); } } - if (__pyx_t_3) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 255, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_4) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 263, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 255, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 263, __pyx_L1_error) } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 255, __pyx_L1_error) + __PYX_ERR(0, 263, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); } else { - __pyx_t_6 = PyList_GET_ITEM(sequence, 0); - __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + __pyx_t_7 = PyList_GET_ITEM(sequence, 0); + __pyx_t_4 = PyList_GET_ITEM(sequence, 1); } - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); #else - __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 255, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 255, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { Py_ssize_t index = -1; - __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 255, __pyx_L1_error) + __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = Py_TYPE(__pyx_t_5)->tp_iternext; + index = 0; __pyx_t_7 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_7)) goto __pyx_L8_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 1; __pyx_t_4 = __pyx_t_9(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; - index = 0; __pyx_t_6 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_4), 2) < 0) __PYX_ERR(0, 255, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_8 = NULL; + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_5), 2) < 0) __PYX_ERR(0, 263, __pyx_L1_error) + __pyx_t_9 = NULL; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L9_unpacking_done; + __pyx_L8_unpacking_failed:; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_9 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 255, __pyx_L1_error) - __pyx_L7_unpacking_done:; + __PYX_ERR(0, 263, __pyx_L1_error) + __pyx_L9_unpacking_done:; } - __pyx_v_stderr_h = __pyx_t_6; - __pyx_t_6 = 0; - __pyx_v_stderr_f = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_v_stderr_h = __pyx_t_7; + __pyx_t_7 = 0; + __pyx_v_stderr_f = __pyx_t_4; + __pyx_t_4 = 0; - /* "pysam/libcutils.pyx":256 + /* "pysam/libcutils.pyx":264 * # redirect stderr to file * stderr_h, stderr_f = tempfile.mkstemp() - * pysam_set_stderr(stderr_h) # <<<<<<<<<<<<<< + * samtools_set_stderr(stderr_h) # <<<<<<<<<<<<<< + * bcftools_set_stderr(stderr_h) + * + */ + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_stderr_h); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 264, __pyx_L1_error) + samtools_set_stderr(__pyx_t_10); + + /* "pysam/libcutils.pyx":265 + * stderr_h, stderr_f = tempfile.mkstemp() + * samtools_set_stderr(stderr_h) + * bcftools_set_stderr(stderr_h) # <<<<<<<<<<<<<< * * # redirect stdout to file */ - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_v_stderr_h); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 256, __pyx_L1_error) - pysam_set_stderr(__pyx_t_9); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_stderr_h); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 265, __pyx_L1_error) + bcftools_set_stderr(__pyx_t_10); - /* "pysam/libcutils.pyx":259 + /* "pysam/libcutils.pyx":268 * * # redirect stdout to file * if save_stdout: # <<<<<<<<<<<<<< * stdout_f = save_stdout * stdout_h = c_open(force_bytes(stdout_f), */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_save_stdout); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 259, __pyx_L1_error) - if (__pyx_t_1) { + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_save_stdout); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 268, __pyx_L1_error) + if (__pyx_t_8) { - /* "pysam/libcutils.pyx":260 + /* "pysam/libcutils.pyx":269 * # redirect stdout to file * if save_stdout: * stdout_f = save_stdout # <<<<<<<<<<<<<< @@ -5933,284 +5967,311 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj __Pyx_INCREF(__pyx_v_save_stdout); __pyx_v_stdout_f = __pyx_v_save_stdout; - /* "pysam/libcutils.pyx":261 + /* "pysam/libcutils.pyx":270 * if save_stdout: * stdout_f = save_stdout * stdout_h = c_open(force_bytes(stdout_f), # <<<<<<<<<<<<<< * O_WRONLY) * if stdout_h == -1: */ - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_stdout_f, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 261, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (unlikely(__pyx_t_2 == Py_None)) { + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_stdout_f, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 270, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(__pyx_t_3 == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 261, __pyx_L1_error) + __PYX_ERR(0, 270, __pyx_L1_error) } - __pyx_t_10 = __Pyx_PyBytes_AsWritableString(__pyx_t_2); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 261, __pyx_L1_error) + __pyx_t_11 = __Pyx_PyBytes_AsWritableString(__pyx_t_3); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) __PYX_ERR(0, 270, __pyx_L1_error) - /* "pysam/libcutils.pyx":262 + /* "pysam/libcutils.pyx":271 * stdout_f = save_stdout * stdout_h = c_open(force_bytes(stdout_f), * O_WRONLY) # <<<<<<<<<<<<<< * if stdout_h == -1: - * raise OSError("error while opening {} for writing".format(stdout_f)) + * raise IOError("error while opening {} for writing".format(stdout_f)) */ - __pyx_t_3 = __Pyx_PyInt_From_int(open(__pyx_t_10, O_WRONLY)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 261, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_stdout_h = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyInt_From_int(open(__pyx_t_11, O_WRONLY)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 270, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_stdout_h = __pyx_t_4; + __pyx_t_4 = 0; - /* "pysam/libcutils.pyx":263 + /* "pysam/libcutils.pyx":272 * stdout_h = c_open(force_bytes(stdout_f), * O_WRONLY) * if stdout_h == -1: # <<<<<<<<<<<<<< - * raise OSError("error while opening {} for writing".format(stdout_f)) + * raise IOError("error while opening {} for writing".format(stdout_f)) * */ - __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_v_stdout_h, __pyx_int_neg_1, -1L, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 263, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 263, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(__pyx_t_1)) { + __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_v_stdout_h, __pyx_int_neg_1, -1L, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 272, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 272, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(__pyx_t_8)) { - /* "pysam/libcutils.pyx":264 + /* "pysam/libcutils.pyx":273 * O_WRONLY) * if stdout_h == -1: - * raise OSError("error while opening {} for writing".format(stdout_f)) # <<<<<<<<<<<<<< + * raise IOError("error while opening {} for writing".format(stdout_f)) # <<<<<<<<<<<<<< * - * pysam_set_stdout_fn(force_bytes(stdout_f)) + * samtools_set_stdout_fn(force_bytes(stdout_f)) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_error_while_opening_for_writing, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_6)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_6); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_error_while_opening_for_writing, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 273, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); + __Pyx_DECREF_SET(__pyx_t_3, function); } } - if (!__pyx_t_6) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_stdout_f); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + if (!__pyx_t_7) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_stdout_f); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 273, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_stdout_f}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_stdout_f}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 273, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_4); } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_stdout_f}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_stdout_f}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 273, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_4); } else #endif { - __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL; + __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 273, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); __pyx_t_7 = NULL; __Pyx_INCREF(__pyx_v_stdout_f); __Pyx_GIVEREF(__pyx_v_stdout_f); - PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_stdout_f); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_stdout_f); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 273, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_OSError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 264, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(0, 264, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 273, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(0, 273, __pyx_L1_error) - /* "pysam/libcutils.pyx":263 + /* "pysam/libcutils.pyx":272 * stdout_h = c_open(force_bytes(stdout_f), * O_WRONLY) * if stdout_h == -1: # <<<<<<<<<<<<<< - * raise OSError("error while opening {} for writing".format(stdout_f)) + * raise IOError("error while opening {} for writing".format(stdout_f)) * */ } - /* "pysam/libcutils.pyx":266 - * raise OSError("error while opening {} for writing".format(stdout_f)) + /* "pysam/libcutils.pyx":275 + * raise IOError("error while opening {} for writing".format(stdout_f)) * - * pysam_set_stdout_fn(force_bytes(stdout_f)) # <<<<<<<<<<<<<< - * pysam_set_stdout(stdout_h) - * elif catch_stdout: + * samtools_set_stdout_fn(force_bytes(stdout_f)) # <<<<<<<<<<<<<< + * samtools_set_stdout(stdout_h) + * bcftools_set_stdout_fn(force_bytes(stdout_f)) */ - __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_stdout_f, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 266, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - if (unlikely(__pyx_t_2 == Py_None)) { + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_stdout_f, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 275, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(__pyx_t_3 == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 275, __pyx_L1_error) + } + __pyx_t_12 = __Pyx_PyBytes_AsString(__pyx_t_3); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 275, __pyx_L1_error) + samtools_set_stdout_fn(__pyx_t_12); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "pysam/libcutils.pyx":276 + * + * samtools_set_stdout_fn(force_bytes(stdout_f)) + * samtools_set_stdout(stdout_h) # <<<<<<<<<<<<<< + * bcftools_set_stdout_fn(force_bytes(stdout_f)) + * bcftools_set_stdout(stdout_h) + */ + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_stdout_h); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 276, __pyx_L1_error) + samtools_set_stdout(__pyx_t_10); + + /* "pysam/libcutils.pyx":277 + * samtools_set_stdout_fn(force_bytes(stdout_f)) + * samtools_set_stdout(stdout_h) + * bcftools_set_stdout_fn(force_bytes(stdout_f)) # <<<<<<<<<<<<<< + * bcftools_set_stdout(stdout_h) + * + */ + __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_stdout_f, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 277, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(__pyx_t_3 == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 266, __pyx_L1_error) + __PYX_ERR(0, 277, __pyx_L1_error) } - __pyx_t_11 = __Pyx_PyBytes_AsString(__pyx_t_2); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) __PYX_ERR(0, 266, __pyx_L1_error) - pysam_set_stdout_fn(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_13 = __Pyx_PyBytes_AsString(__pyx_t_3); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) __PYX_ERR(0, 277, __pyx_L1_error) + bcftools_set_stdout_fn(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcutils.pyx":267 + /* "pysam/libcutils.pyx":278 + * samtools_set_stdout(stdout_h) + * bcftools_set_stdout_fn(force_bytes(stdout_f)) + * bcftools_set_stdout(stdout_h) # <<<<<<<<<<<<<< * - * pysam_set_stdout_fn(force_bytes(stdout_f)) - * pysam_set_stdout(stdout_h) # <<<<<<<<<<<<<< * elif catch_stdout: - * stdout_h, stdout_f = tempfile.mkstemp() */ - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_v_stdout_h); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 267, __pyx_L1_error) - pysam_set_stdout(__pyx_t_9); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_stdout_h); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 278, __pyx_L1_error) + bcftools_set_stdout(__pyx_t_10); - /* "pysam/libcutils.pyx":259 + /* "pysam/libcutils.pyx":268 * * # redirect stdout to file * if save_stdout: # <<<<<<<<<<<<<< * stdout_f = save_stdout * stdout_h = c_open(force_bytes(stdout_f), */ - goto __pyx_L8; + goto __pyx_L10; } - /* "pysam/libcutils.pyx":268 - * pysam_set_stdout_fn(force_bytes(stdout_f)) - * pysam_set_stdout(stdout_h) + /* "pysam/libcutils.pyx":280 + * bcftools_set_stdout(stdout_h) + * * elif catch_stdout: # <<<<<<<<<<<<<< * stdout_h, stdout_f = tempfile.mkstemp() - * + * MAP_STDOUT_OPTIONS = { */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 268, __pyx_L1_error) - if (__pyx_t_1) { + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 280, __pyx_L1_error) + if (__pyx_t_8) { - /* "pysam/libcutils.pyx":269 - * pysam_set_stdout(stdout_h) + /* "pysam/libcutils.pyx":281 + * * elif catch_stdout: * stdout_h, stdout_f = tempfile.mkstemp() # <<<<<<<<<<<<<< - * * MAP_STDOUT_OPTIONS = { + * "samtools": { */ - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_tempfile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 269, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_mkstemp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 269, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_tempfile); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 281, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_mkstemp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 281, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); + __Pyx_DECREF_SET(__pyx_t_5, function); } } - if (__pyx_t_3) { - __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_4) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 281, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { - __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 281, __pyx_L1_error) } - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 269, __pyx_L1_error) + __PYX_ERR(0, 281, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); } else { - __pyx_t_4 = PyList_GET_ITEM(sequence, 0); - __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_4 = PyList_GET_ITEM(sequence, 1); } + __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_3); #else - __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 269, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 281, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 281, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 269, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); #endif - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { Py_ssize_t index = -1; - __pyx_t_6 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 269, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_6)->tp_iternext; - index = 0; __pyx_t_4 = __pyx_t_8(__pyx_t_6); if (unlikely(!__pyx_t_4)) goto __pyx_L10_unpacking_failed; + __pyx_t_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 281, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_5 = __pyx_t_9(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L12_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + index = 1; __pyx_t_4 = __pyx_t_9(__pyx_t_7); if (unlikely(!__pyx_t_4)) goto __pyx_L12_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); - index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L10_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_6), 2) < 0) __PYX_ERR(0, 269, __pyx_L1_error) - __pyx_t_8 = NULL; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - goto __pyx_L11_unpacking_done; - __pyx_L10_unpacking_failed:; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_8 = NULL; + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_7), 2) < 0) __PYX_ERR(0, 281, __pyx_L1_error) + __pyx_t_9 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L13_unpacking_done; + __pyx_L12_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_9 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 269, __pyx_L1_error) - __pyx_L11_unpacking_done:; + __PYX_ERR(0, 281, __pyx_L1_error) + __pyx_L13_unpacking_done:; } - __pyx_v_stdout_h = __pyx_t_4; + __pyx_v_stdout_h = __pyx_t_5; + __pyx_t_5 = 0; + __pyx_v_stdout_f = __pyx_t_4; __pyx_t_4 = 0; - __pyx_v_stdout_f = __pyx_t_3; - __pyx_t_3 = 0; - /* "pysam/libcutils.pyx":272 - * + /* "pysam/libcutils.pyx":283 + * stdout_h, stdout_f = tempfile.mkstemp() * MAP_STDOUT_OPTIONS = { - * "samtools": { # <<<<<<<<<<<<<< - * "view": "-o {}", - * "mpileup": "-o {}", + * "samtools": { # <<<<<<<<<<<<<< + * "view": "-o {}", + * "mpileup": "-o {}", */ - __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 272, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); - /* "pysam/libcutils.pyx":273 + /* "pysam/libcutils.pyx":284 * MAP_STDOUT_OPTIONS = { - * "samtools": { - * "view": "-o {}", # <<<<<<<<<<<<<< - * "mpileup": "-o {}", - * "depad": "-o {}", + * "samtools": { + * "view": "-o {}", # <<<<<<<<<<<<<< + * "mpileup": "-o {}", + * "depad": "-o {}", */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 273, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_view, __pyx_kp_s_o) < 0) __PYX_ERR(0, 273, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_mpileup, __pyx_kp_s_o) < 0) __PYX_ERR(0, 273, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_depad, __pyx_kp_s_o) < 0) __PYX_ERR(0, 273, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_calmd, __pyx_kp_s_) < 0) __PYX_ERR(0, 273, __pyx_L1_error) - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_samtools, __pyx_t_3) < 0) __PYX_ERR(0, 272, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 284, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_view, __pyx_kp_s_o) < 0) __PYX_ERR(0, 284, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_mpileup, __pyx_kp_s_o) < 0) __PYX_ERR(0, 284, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_depad, __pyx_kp_s_o) < 0) __PYX_ERR(0, 284, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_calmd, __pyx_kp_s_) < 0) __PYX_ERR(0, 284, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_samtools, __pyx_t_4) < 0) __PYX_ERR(0, 283, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcutils.pyx":278 - * "calmd": "", # uses pysam_stdout_fn - * }, + /* "pysam/libcutils.pyx":289 + * "calmd": "", # uses pysam_stdout_fn + * }, * "bcftools": {} # <<<<<<<<<<<<<< * } * */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 278, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_bcftools, __pyx_t_3) < 0) __PYX_ERR(0, 272, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_MAP_STDOUT_OPTIONS = ((PyObject*)__pyx_t_2); - __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 289, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_bcftools, __pyx_t_4) < 0) __PYX_ERR(0, 283, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_MAP_STDOUT_OPTIONS = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; - /* "pysam/libcutils.pyx":281 + /* "pysam/libcutils.pyx":292 * } * * stdout_option = None # <<<<<<<<<<<<<< @@ -6220,17 +6281,17 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj __Pyx_INCREF(Py_None); __pyx_v_stdout_option = Py_None; - /* "pysam/libcutils.pyx":282 + /* "pysam/libcutils.pyx":293 * * stdout_option = None * if collection == "bcftools": # <<<<<<<<<<<<<< * # in bcftools, most methods accept -o, the exceptions * # are below: */ - __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_collection, __pyx_n_s_bcftools, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 282, __pyx_L1_error) - if (__pyx_t_1) { + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_collection, __pyx_n_s_bcftools, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 293, __pyx_L1_error) + if (__pyx_t_8) { - /* "pysam/libcutils.pyx":285 + /* "pysam/libcutils.pyx":296 * # in bcftools, most methods accept -o, the exceptions * # are below: * if method not in ("index", "roh", "stats"): # <<<<<<<<<<<<<< @@ -6238,27 +6299,27 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj * elif method in MAP_STDOUT_OPTIONS[collection]: */ __Pyx_INCREF(__pyx_v_method); - __pyx_t_2 = __pyx_v_method; - __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_index, Py_NE)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 285, __pyx_L1_error) - if (__pyx_t_7) { + __pyx_t_3 = __pyx_v_method; + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_index, Py_NE)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 296, __pyx_L1_error) + if (__pyx_t_1) { } else { - __pyx_t_1 = __pyx_t_7; - goto __pyx_L14_bool_binop_done; + __pyx_t_8 = __pyx_t_1; + goto __pyx_L16_bool_binop_done; } - __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_roh, Py_NE)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 285, __pyx_L1_error) - if (__pyx_t_7) { + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_roh, Py_NE)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 296, __pyx_L1_error) + if (__pyx_t_1) { } else { - __pyx_t_1 = __pyx_t_7; - goto __pyx_L14_bool_binop_done; + __pyx_t_8 = __pyx_t_1; + goto __pyx_L16_bool_binop_done; } - __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_stats, Py_NE)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 285, __pyx_L1_error) - __pyx_t_1 = __pyx_t_7; - __pyx_L14_bool_binop_done:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = (__pyx_t_1 != 0); - if (__pyx_t_7) { + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_stats, Py_NE)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 296, __pyx_L1_error) + __pyx_t_8 = __pyx_t_1; + __pyx_L16_bool_binop_done:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = (__pyx_t_8 != 0); + if (__pyx_t_1) { - /* "pysam/libcutils.pyx":286 + /* "pysam/libcutils.pyx":297 * # are below: * if method not in ("index", "roh", "stats"): * stdout_option = "-o {}" # <<<<<<<<<<<<<< @@ -6268,7 +6329,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj __Pyx_INCREF(__pyx_kp_s_o); __Pyx_DECREF_SET(__pyx_v_stdout_option, __pyx_kp_s_o); - /* "pysam/libcutils.pyx":285 + /* "pysam/libcutils.pyx":296 * # in bcftools, most methods accept -o, the exceptions * # are below: * if method not in ("index", "roh", "stats"): # <<<<<<<<<<<<<< @@ -6277,66 +6338,66 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj */ } - /* "pysam/libcutils.pyx":282 + /* "pysam/libcutils.pyx":293 * * stdout_option = None * if collection == "bcftools": # <<<<<<<<<<<<<< * # in bcftools, most methods accept -o, the exceptions * # are below: */ - goto __pyx_L12; + goto __pyx_L14; } - /* "pysam/libcutils.pyx":287 + /* "pysam/libcutils.pyx":298 * if method not in ("index", "roh", "stats"): * stdout_option = "-o {}" * elif method in MAP_STDOUT_OPTIONS[collection]: # <<<<<<<<<<<<<< * # special case - samtools view -c outputs on stdout * if not(method == "view" and "-c" in args): */ - __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_MAP_STDOUT_OPTIONS, __pyx_v_collection); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 287, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_v_method, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 287, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_1 = (__pyx_t_7 != 0); - if (__pyx_t_1) { + __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_MAP_STDOUT_OPTIONS, __pyx_v_collection); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 298, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_method, __pyx_t_3, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 298, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = (__pyx_t_1 != 0); + if (__pyx_t_8) { - /* "pysam/libcutils.pyx":289 + /* "pysam/libcutils.pyx":300 * elif method in MAP_STDOUT_OPTIONS[collection]: * # special case - samtools view -c outputs on stdout * if not(method == "view" and "-c" in args): # <<<<<<<<<<<<<< * stdout_option = MAP_STDOUT_OPTIONS[collection][method] * */ - __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_view, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 289, __pyx_L1_error) - if (__pyx_t_7) { + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_view, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 300, __pyx_L1_error) + if (__pyx_t_1) { } else { - __pyx_t_1 = __pyx_t_7; - goto __pyx_L18_bool_binop_done; + __pyx_t_8 = __pyx_t_1; + goto __pyx_L20_bool_binop_done; } - __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_kp_s_c, __pyx_v_args, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 289, __pyx_L1_error) - __pyx_t_12 = (__pyx_t_7 != 0); - __pyx_t_1 = __pyx_t_12; - __pyx_L18_bool_binop_done:; - __pyx_t_12 = ((!__pyx_t_1) != 0); - if (__pyx_t_12) { - - /* "pysam/libcutils.pyx":290 + __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_kp_s_c, __pyx_v_args, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 300, __pyx_L1_error) + __pyx_t_2 = (__pyx_t_1 != 0); + __pyx_t_8 = __pyx_t_2; + __pyx_L20_bool_binop_done:; + __pyx_t_2 = ((!__pyx_t_8) != 0); + if (__pyx_t_2) { + + /* "pysam/libcutils.pyx":301 * # special case - samtools view -c outputs on stdout * if not(method == "view" and "-c" in args): * stdout_option = MAP_STDOUT_OPTIONS[collection][method] # <<<<<<<<<<<<<< * - * if stdout_option is not None: + * if stdout_option is not None and not is_usage: */ - __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_MAP_STDOUT_OPTIONS, __pyx_v_collection); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 290, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_method); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 290, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_MAP_STDOUT_OPTIONS, __pyx_v_collection); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 301, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF_SET(__pyx_v_stdout_option, __pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_3, __pyx_v_method); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 301, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF_SET(__pyx_v_stdout_option, __pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcutils.pyx":289 + /* "pysam/libcutils.pyx":300 * elif method in MAP_STDOUT_OPTIONS[collection]: * # special case - samtools view -c outputs on stdout * if not(method == "view" and "-c" in args): # <<<<<<<<<<<<<< @@ -6345,7 +6406,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj */ } - /* "pysam/libcutils.pyx":287 + /* "pysam/libcutils.pyx":298 * if method not in ("index", "roh", "stats"): * stdout_option = "-o {}" * elif method in MAP_STDOUT_OPTIONS[collection]: # <<<<<<<<<<<<<< @@ -6353,340 +6414,385 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj * if not(method == "view" and "-c" in args): */ } - __pyx_L12:; + __pyx_L14:; - /* "pysam/libcutils.pyx":292 + /* "pysam/libcutils.pyx":303 * stdout_option = MAP_STDOUT_OPTIONS[collection][method] * - * if stdout_option is not None: # <<<<<<<<<<<<<< + * if stdout_option is not None and not is_usage: # <<<<<<<<<<<<<< * os.close(stdout_h) - * pysam_set_stdout_fn(force_bytes(stdout_f)) + * samtools_set_stdout_fn(force_bytes(stdout_f)) */ - __pyx_t_12 = (__pyx_v_stdout_option != Py_None); - __pyx_t_1 = (__pyx_t_12 != 0); + __pyx_t_8 = (__pyx_v_stdout_option != Py_None); + __pyx_t_1 = (__pyx_t_8 != 0); if (__pyx_t_1) { + } else { + __pyx_t_2 = __pyx_t_1; + goto __pyx_L23_bool_binop_done; + } + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_is_usage); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 303, __pyx_L1_error) + __pyx_t_8 = ((!__pyx_t_1) != 0); + __pyx_t_2 = __pyx_t_8; + __pyx_L23_bool_binop_done:; + if (__pyx_t_2) { - /* "pysam/libcutils.pyx":293 + /* "pysam/libcutils.pyx":304 * - * if stdout_option is not None: + * if stdout_option is not None and not is_usage: * os.close(stdout_h) # <<<<<<<<<<<<<< - * pysam_set_stdout_fn(force_bytes(stdout_f)) - * args.extend(stdout_option.format(stdout_f).split(" ")) + * samtools_set_stdout_fn(force_bytes(stdout_f)) + * bcftools_set_stdout_fn(force_bytes(stdout_f)) */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 293, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 293, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_close); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); + __Pyx_DECREF_SET(__pyx_t_5, function); } } - if (!__pyx_t_2) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_stdout_h); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 293, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + if (!__pyx_t_3) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_stdout_h); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_stdout_h}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 293, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_3); + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_stdout_h}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_4); } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_stdout_h}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 293, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_stdout_h}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_4); } else #endif { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 293, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL; + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); __pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_stdout_h); __Pyx_GIVEREF(__pyx_v_stdout_h); - PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_stdout_h); - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 293, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_stdout_h); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcutils.pyx":294 - * if stdout_option is not None: + /* "pysam/libcutils.pyx":305 + * if stdout_option is not None and not is_usage: * os.close(stdout_h) - * pysam_set_stdout_fn(force_bytes(stdout_f)) # <<<<<<<<<<<<<< + * samtools_set_stdout_fn(force_bytes(stdout_f)) # <<<<<<<<<<<<<< + * bcftools_set_stdout_fn(force_bytes(stdout_f)) * args.extend(stdout_option.format(stdout_f).split(" ")) - * else: */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_stdout_f, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 294, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - if (unlikely(__pyx_t_3 == Py_None)) { + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_stdout_f, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 305, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (unlikely(__pyx_t_4 == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 294, __pyx_L1_error) + __PYX_ERR(0, 305, __pyx_L1_error) } - __pyx_t_11 = __Pyx_PyBytes_AsString(__pyx_t_3); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) __PYX_ERR(0, 294, __pyx_L1_error) - pysam_set_stdout_fn(__pyx_t_11); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_12 = __Pyx_PyBytes_AsString(__pyx_t_4); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) __PYX_ERR(0, 305, __pyx_L1_error) + samtools_set_stdout_fn(__pyx_t_12); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "pysam/libcutils.pyx":295 + /* "pysam/libcutils.pyx":306 * os.close(stdout_h) - * pysam_set_stdout_fn(force_bytes(stdout_f)) - * args.extend(stdout_option.format(stdout_f).split(" ")) # <<<<<<<<<<<<<< + * samtools_set_stdout_fn(force_bytes(stdout_f)) + * bcftools_set_stdout_fn(force_bytes(stdout_f)) # <<<<<<<<<<<<<< + * args.extend(stdout_option.format(stdout_f).split(" ")) * else: - * pysam_set_stdout(stdout_h) */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_args, __pyx_n_s_extend); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 295, __pyx_L1_error) + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_stdout_f, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 306, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_stdout_option, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); + if (unlikely(__pyx_t_4 == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(0, 306, __pyx_L1_error) + } + __pyx_t_13 = __Pyx_PyBytes_AsString(__pyx_t_4); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) __PYX_ERR(0, 306, __pyx_L1_error) + bcftools_set_stdout_fn(__pyx_t_13); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "pysam/libcutils.pyx":307 + * samtools_set_stdout_fn(force_bytes(stdout_f)) + * bcftools_set_stdout_fn(force_bytes(stdout_f)) + * args.extend(stdout_option.format(stdout_f).split(" ")) # <<<<<<<<<<<<<< + * else: + * samtools_set_stdout(stdout_h) + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_args, __pyx_n_s_extend); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_stdout_option, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); + __Pyx_DECREF_SET(__pyx_t_3, function); } } - if (!__pyx_t_5) { - __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_stdout_f); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); + if (!__pyx_t_6) { + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_stdout_f); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_stdout_f}; - __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_6); + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_stdout_f}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_7); } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_stdout_f}; - __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_stdout_f}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_7); } else #endif { - __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_5); __pyx_t_5 = NULL; + __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_v_stdout_f); __Pyx_GIVEREF(__pyx_v_stdout_f); - PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_v_stdout_f); - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_13, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_v_stdout_f); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_14, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; } } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_split); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_2)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); + __Pyx_DECREF_SET(__pyx_t_5, function); } } - if (!__pyx_t_2) { - __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_3); + if (!__pyx_t_3) { + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_4); } else { #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_6}; - __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_7}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else #endif #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_6}; - __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_7}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else #endif { - __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_2); __pyx_t_2 = NULL; - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_6); - __pyx_t_6 = 0; - __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_13, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 295, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_14, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; } } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "pysam/libcutils.pyx":292 + /* "pysam/libcutils.pyx":303 * stdout_option = MAP_STDOUT_OPTIONS[collection][method] * - * if stdout_option is not None: # <<<<<<<<<<<<<< + * if stdout_option is not None and not is_usage: # <<<<<<<<<<<<<< * os.close(stdout_h) - * pysam_set_stdout_fn(force_bytes(stdout_f)) + * samtools_set_stdout_fn(force_bytes(stdout_f)) */ - goto __pyx_L20; + goto __pyx_L22; } - /* "pysam/libcutils.pyx":297 + /* "pysam/libcutils.pyx":309 * args.extend(stdout_option.format(stdout_f).split(" ")) * else: - * pysam_set_stdout(stdout_h) # <<<<<<<<<<<<<< + * samtools_set_stdout(stdout_h) # <<<<<<<<<<<<<< + * bcftools_set_stdout(stdout_h) * else: - * pysam_set_stdout_fn("-") */ /*else*/ { - __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_v_stdout_h); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 297, __pyx_L1_error) - pysam_set_stdout(__pyx_t_9); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_stdout_h); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 309, __pyx_L1_error) + samtools_set_stdout(__pyx_t_10); + + /* "pysam/libcutils.pyx":310 + * else: + * samtools_set_stdout(stdout_h) + * bcftools_set_stdout(stdout_h) # <<<<<<<<<<<<<< + * else: + * samtools_set_stdout_fn("-") + */ + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_stdout_h); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 310, __pyx_L1_error) + bcftools_set_stdout(__pyx_t_10); } - __pyx_L20:; + __pyx_L22:; - /* "pysam/libcutils.pyx":268 - * pysam_set_stdout_fn(force_bytes(stdout_f)) - * pysam_set_stdout(stdout_h) + /* "pysam/libcutils.pyx":280 + * bcftools_set_stdout(stdout_h) + * * elif catch_stdout: # <<<<<<<<<<<<<< * stdout_h, stdout_f = tempfile.mkstemp() - * + * MAP_STDOUT_OPTIONS = { */ - goto __pyx_L8; + goto __pyx_L10; } - /* "pysam/libcutils.pyx":299 - * pysam_set_stdout(stdout_h) + /* "pysam/libcutils.pyx":312 + * bcftools_set_stdout(stdout_h) * else: - * pysam_set_stdout_fn("-") # <<<<<<<<<<<<<< + * samtools_set_stdout_fn("-") # <<<<<<<<<<<<<< + * bcftools_set_stdout_fn("-") * - * # setup the function call to samtools/bcftools main */ /*else*/ { - pysam_set_stdout_fn(((char const *)"-")); + samtools_set_stdout_fn(((char const *)"-")); + + /* "pysam/libcutils.pyx":313 + * else: + * samtools_set_stdout_fn("-") + * bcftools_set_stdout_fn("-") # <<<<<<<<<<<<<< + * + * # setup the function call to samtools/bcftools main + */ + bcftools_set_stdout_fn(((char const *)"-")); } - __pyx_L8:; + __pyx_L10:; - /* "pysam/libcutils.pyx":304 + /* "pysam/libcutils.pyx":318 * cdef char ** cargs * cdef int i, n, retval, l * n = len(args) # <<<<<<<<<<<<<< * method = force_bytes(method) * collection = force_bytes(collection) */ - __pyx_t_14 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 304, __pyx_L1_error) - __pyx_v_n = __pyx_t_14; + __pyx_t_15 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 318, __pyx_L1_error) + __pyx_v_n = __pyx_t_15; - /* "pysam/libcutils.pyx":305 + /* "pysam/libcutils.pyx":319 * cdef int i, n, retval, l * n = len(args) * method = force_bytes(method) # <<<<<<<<<<<<<< * collection = force_bytes(collection) * args = [force_bytes(a) for a in args] */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_method, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 305, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF_SET(__pyx_v_method, __pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_method, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 319, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_method, __pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcutils.pyx":306 + /* "pysam/libcutils.pyx":320 * n = len(args) * method = force_bytes(method) * collection = force_bytes(collection) # <<<<<<<<<<<<<< * args = [force_bytes(a) for a in args] * */ - __pyx_t_3 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_collection, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 306, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF_SET(__pyx_v_collection, __pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_collection, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 320, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_collection, __pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcutils.pyx":307 + /* "pysam/libcutils.pyx":321 * method = force_bytes(method) * collection = force_bytes(collection) * args = [force_bytes(a) for a in args] # <<<<<<<<<<<<<< * * # allocate two more for first (dummy) argument (contains command) */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 307, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); if (likely(PyList_CheckExact(__pyx_v_args)) || PyTuple_CheckExact(__pyx_v_args)) { - __pyx_t_4 = __pyx_v_args; __Pyx_INCREF(__pyx_t_4); __pyx_t_14 = 0; - __pyx_t_15 = NULL; + __pyx_t_5 = __pyx_v_args; __Pyx_INCREF(__pyx_t_5); __pyx_t_15 = 0; + __pyx_t_16 = NULL; } else { - __pyx_t_14 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_args); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 307, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_15 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 307, __pyx_L1_error) + __pyx_t_15 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_args); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_16 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 321, __pyx_L1_error) } for (;;) { - if (likely(!__pyx_t_15)) { - if (likely(PyList_CheckExact(__pyx_t_4))) { - if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_4)) break; + if (likely(!__pyx_t_16)) { + if (likely(PyList_CheckExact(__pyx_t_5))) { + if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_13 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_14); __Pyx_INCREF(__pyx_t_13); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 307, __pyx_L1_error) + __pyx_t_14 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_15); __Pyx_INCREF(__pyx_t_14); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 321, __pyx_L1_error) #else - __pyx_t_13 = PySequence_ITEM(__pyx_t_4, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 307, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = PySequence_ITEM(__pyx_t_5, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); #endif } else { - if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_5)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_13 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_14); __Pyx_INCREF(__pyx_t_13); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 307, __pyx_L1_error) + __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_15); __Pyx_INCREF(__pyx_t_14); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 321, __pyx_L1_error) #else - __pyx_t_13 = PySequence_ITEM(__pyx_t_4, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 307, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = PySequence_ITEM(__pyx_t_5, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); #endif } } else { - __pyx_t_13 = __pyx_t_15(__pyx_t_4); - if (unlikely(!__pyx_t_13)) { + __pyx_t_14 = __pyx_t_16(__pyx_t_5); + if (unlikely(!__pyx_t_14)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 307, __pyx_L1_error) + else __PYX_ERR(0, 321, __pyx_L1_error) } break; } - __Pyx_GOTREF(__pyx_t_13); - } - __Pyx_XDECREF_SET(__pyx_v_a, __pyx_t_13); - __pyx_t_13 = 0; - __pyx_t_13 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_a, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 307, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_13); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_13))) __PYX_ERR(0, 307, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_14); + } + __Pyx_XDECREF_SET(__pyx_v_a, __pyx_t_14); + __pyx_t_14 = 0; + __pyx_t_14 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_a, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_14))) __PYX_ERR(0, 321, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_3); - __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_4); + __pyx_t_4 = 0; - /* "pysam/libcutils.pyx":310 + /* "pysam/libcutils.pyx":324 * * # allocate two more for first (dummy) argument (contains command) * cdef int extra_args = 0 # <<<<<<<<<<<<<< @@ -6695,17 +6801,17 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj */ __pyx_v_extra_args = 0; - /* "pysam/libcutils.pyx":311 + /* "pysam/libcutils.pyx":325 * # allocate two more for first (dummy) argument (contains command) * cdef int extra_args = 0 * if method == b"index": # <<<<<<<<<<<<<< * extra_args = 1 * # add extra arguments for commands accepting optional arguments */ - __pyx_t_1 = (__Pyx_PyBytes_Equals(__pyx_v_method, __pyx_n_b_index, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 311, __pyx_L1_error) - if (__pyx_t_1) { + __pyx_t_2 = (__Pyx_PyBytes_Equals(__pyx_v_method, __pyx_n_b_index, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 325, __pyx_L1_error) + if (__pyx_t_2) { - /* "pysam/libcutils.pyx":312 + /* "pysam/libcutils.pyx":326 * cdef int extra_args = 0 * if method == b"index": * extra_args = 1 # <<<<<<<<<<<<<< @@ -6714,7 +6820,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj */ __pyx_v_extra_args = 1; - /* "pysam/libcutils.pyx":311 + /* "pysam/libcutils.pyx":325 * # allocate two more for first (dummy) argument (contains command) * cdef int extra_args = 0 * if method == b"index": # <<<<<<<<<<<<<< @@ -6723,7 +6829,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj */ } - /* "pysam/libcutils.pyx":315 + /* "pysam/libcutils.pyx":329 * # add extra arguments for commands accepting optional arguments * # such as 'samtools index x.bam [out.index]' * cargs = calloc(n + 2 + extra_args, sizeof(char *)) # <<<<<<<<<<<<<< @@ -6732,50 +6838,50 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj */ __pyx_v_cargs = ((char **)calloc(((__pyx_v_n + 2) + __pyx_v_extra_args), (sizeof(char *)))); - /* "pysam/libcutils.pyx":316 + /* "pysam/libcutils.pyx":330 * # such as 'samtools index x.bam [out.index]' * cargs = calloc(n + 2 + extra_args, sizeof(char *)) * cargs[0] = collection # <<<<<<<<<<<<<< * cargs[1] = method * */ - __pyx_t_10 = __Pyx_PyObject_AsWritableString(__pyx_v_collection); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 316, __pyx_L1_error) - (__pyx_v_cargs[0]) = __pyx_t_10; + __pyx_t_11 = __Pyx_PyObject_AsWritableString(__pyx_v_collection); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) __PYX_ERR(0, 330, __pyx_L1_error) + (__pyx_v_cargs[0]) = __pyx_t_11; - /* "pysam/libcutils.pyx":317 + /* "pysam/libcutils.pyx":331 * cargs = calloc(n + 2 + extra_args, sizeof(char *)) * cargs[0] = collection * cargs[1] = method # <<<<<<<<<<<<<< * * # create copies of strings - getopt for long options permutes */ - __pyx_t_10 = __Pyx_PyObject_AsWritableString(__pyx_v_method); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 317, __pyx_L1_error) - (__pyx_v_cargs[1]) = __pyx_t_10; + __pyx_t_11 = __Pyx_PyObject_AsWritableString(__pyx_v_method); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) __PYX_ERR(0, 331, __pyx_L1_error) + (__pyx_v_cargs[1]) = __pyx_t_11; - /* "pysam/libcutils.pyx":321 + /* "pysam/libcutils.pyx":335 * # create copies of strings - getopt for long options permutes * # arguments * for i from 0 <= i < n: # <<<<<<<<<<<<<< * l = len(args[i]) * cargs[i + 2] = calloc(l + 1, sizeof(char)) */ - __pyx_t_9 = __pyx_v_n; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_9; __pyx_v_i++) { + __pyx_t_10 = __pyx_v_n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_10; __pyx_v_i++) { - /* "pysam/libcutils.pyx":322 + /* "pysam/libcutils.pyx":336 * # arguments * for i from 0 <= i < n: * l = len(args[i]) # <<<<<<<<<<<<<< * cargs[i + 2] = calloc(l + 1, sizeof(char)) * strncpy(cargs[i + 2], args[i], l) */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_args, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 322, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_14 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 322, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_l = __pyx_t_14; + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_args, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 336, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_15 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 336, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_l = __pyx_t_15; - /* "pysam/libcutils.pyx":323 + /* "pysam/libcutils.pyx":337 * for i from 0 <= i < n: * l = len(args[i]) * cargs[i + 2] = calloc(l + 1, sizeof(char)) # <<<<<<<<<<<<<< @@ -6784,102 +6890,120 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj */ (__pyx_v_cargs[(__pyx_v_i + 2)]) = ((char *)calloc((__pyx_v_l + 1), (sizeof(char)))); - /* "pysam/libcutils.pyx":324 + /* "pysam/libcutils.pyx":338 * l = len(args[i]) * cargs[i + 2] = calloc(l + 1, sizeof(char)) * strncpy(cargs[i + 2], args[i], l) # <<<<<<<<<<<<<< * * # reset getopt. On OsX there getopt reset is different */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_args, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 324, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_16 = __Pyx_PyObject_AsString(__pyx_t_3); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) __PYX_ERR(0, 324, __pyx_L1_error) - (void)(strncpy((__pyx_v_cargs[(__pyx_v_i + 2)]), __pyx_t_16, __pyx_v_l)); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_args, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 338, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_17 = __Pyx_PyObject_AsString(__pyx_t_4); if (unlikely((!__pyx_t_17) && PyErr_Occurred())) __PYX_ERR(0, 338, __pyx_L1_error) + (void)(strncpy((__pyx_v_cargs[(__pyx_v_i + 2)]), __pyx_t_17, __pyx_v_l)); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - /* "pysam/libcutils.pyx":328 + /* "pysam/libcutils.pyx":342 * # reset getopt. On OsX there getopt reset is different * # between getopt and getopt_long * if method in [b'index', b'cat', b'quickcheck', # <<<<<<<<<<<<<< * b'faidx', b'kprobaln']: - * set_optind(1) + * samtools_set_optind(1) */ __Pyx_INCREF(__pyx_v_method); - __pyx_t_3 = __pyx_v_method; - __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_t_3, __pyx_n_b_index, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 328, __pyx_L1_error) - if (!__pyx_t_12) { + __pyx_t_4 = __pyx_v_method; + __pyx_t_8 = (__Pyx_PyBytes_Equals(__pyx_t_4, __pyx_n_b_index, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 342, __pyx_L1_error) + if (!__pyx_t_8) { } else { - __pyx_t_1 = __pyx_t_12; - goto __pyx_L27_bool_binop_done; + __pyx_t_2 = __pyx_t_8; + goto __pyx_L31_bool_binop_done; } - __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_t_3, __pyx_n_b_cat, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 328, __pyx_L1_error) - if (!__pyx_t_12) { + __pyx_t_8 = (__Pyx_PyBytes_Equals(__pyx_t_4, __pyx_n_b_cat, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 342, __pyx_L1_error) + if (!__pyx_t_8) { } else { - __pyx_t_1 = __pyx_t_12; - goto __pyx_L27_bool_binop_done; + __pyx_t_2 = __pyx_t_8; + goto __pyx_L31_bool_binop_done; } - __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_t_3, __pyx_n_b_quickcheck, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 328, __pyx_L1_error) - if (!__pyx_t_12) { + __pyx_t_8 = (__Pyx_PyBytes_Equals(__pyx_t_4, __pyx_n_b_quickcheck, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 342, __pyx_L1_error) + if (!__pyx_t_8) { } else { - __pyx_t_1 = __pyx_t_12; - goto __pyx_L27_bool_binop_done; + __pyx_t_2 = __pyx_t_8; + goto __pyx_L31_bool_binop_done; } - __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_t_3, __pyx_n_b_faidx, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 328, __pyx_L1_error) - if (!__pyx_t_12) { + __pyx_t_8 = (__Pyx_PyBytes_Equals(__pyx_t_4, __pyx_n_b_faidx, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 342, __pyx_L1_error) + if (!__pyx_t_8) { } else { - __pyx_t_1 = __pyx_t_12; - goto __pyx_L27_bool_binop_done; + __pyx_t_2 = __pyx_t_8; + goto __pyx_L31_bool_binop_done; } - __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_t_3, __pyx_n_b_kprobaln, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 328, __pyx_L1_error) - __pyx_t_1 = __pyx_t_12; - __pyx_L27_bool_binop_done:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_12 = (__pyx_t_1 != 0); - if (__pyx_t_12) { + __pyx_t_8 = (__Pyx_PyBytes_Equals(__pyx_t_4, __pyx_n_b_kprobaln, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 342, __pyx_L1_error) + __pyx_t_2 = __pyx_t_8; + __pyx_L31_bool_binop_done:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = (__pyx_t_2 != 0); + if (__pyx_t_8) { - /* "pysam/libcutils.pyx":330 + /* "pysam/libcutils.pyx":344 * if method in [b'index', b'cat', b'quickcheck', * b'faidx', b'kprobaln']: - * set_optind(1) # <<<<<<<<<<<<<< + * samtools_set_optind(1) # <<<<<<<<<<<<<< + * bcftools_set_optind(1) + * else: + */ + samtools_set_optind(1); + + /* "pysam/libcutils.pyx":345 + * b'faidx', b'kprobaln']: + * samtools_set_optind(1) + * bcftools_set_optind(1) # <<<<<<<<<<<<<< * else: - * set_optind(0) + * samtools_set_optind(0) */ - set_optind(1); + bcftools_set_optind(1); - /* "pysam/libcutils.pyx":328 + /* "pysam/libcutils.pyx":342 * # reset getopt. On OsX there getopt reset is different * # between getopt and getopt_long * if method in [b'index', b'cat', b'quickcheck', # <<<<<<<<<<<<<< * b'faidx', b'kprobaln']: - * set_optind(1) + * samtools_set_optind(1) */ - goto __pyx_L26; + goto __pyx_L30; } - /* "pysam/libcutils.pyx":332 - * set_optind(1) + /* "pysam/libcutils.pyx":347 + * bcftools_set_optind(1) * else: - * set_optind(0) # <<<<<<<<<<<<<< + * samtools_set_optind(0) # <<<<<<<<<<<<<< + * bcftools_set_optind(0) * - * # call samtools/bcftools */ /*else*/ { - set_optind(0); + samtools_set_optind(0); + + /* "pysam/libcutils.pyx":348 + * else: + * samtools_set_optind(0) + * bcftools_set_optind(0) # <<<<<<<<<<<<<< + * + * # call samtools/bcftools + */ + bcftools_set_optind(0); } - __pyx_L26:; + __pyx_L30:; - /* "pysam/libcutils.pyx":335 + /* "pysam/libcutils.pyx":351 * * # call samtools/bcftools * if collection == b"samtools": # <<<<<<<<<<<<<< * retval = samtools_main(n + 2, cargs) * elif collection == b"bcftools": */ - __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_v_collection, __pyx_n_b_samtools, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 335, __pyx_L1_error) - if (__pyx_t_12) { + __pyx_t_8 = (__Pyx_PyBytes_Equals(__pyx_v_collection, __pyx_n_b_samtools, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 351, __pyx_L1_error) + if (__pyx_t_8) { - /* "pysam/libcutils.pyx":336 + /* "pysam/libcutils.pyx":352 * # call samtools/bcftools * if collection == b"samtools": * retval = samtools_main(n + 2, cargs) # <<<<<<<<<<<<<< @@ -6888,27 +7012,27 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj */ __pyx_v_retval = samtools_main((__pyx_v_n + 2), __pyx_v_cargs); - /* "pysam/libcutils.pyx":335 + /* "pysam/libcutils.pyx":351 * * # call samtools/bcftools * if collection == b"samtools": # <<<<<<<<<<<<<< * retval = samtools_main(n + 2, cargs) * elif collection == b"bcftools": */ - goto __pyx_L32; + goto __pyx_L36; } - /* "pysam/libcutils.pyx":337 + /* "pysam/libcutils.pyx":353 * if collection == b"samtools": * retval = samtools_main(n + 2, cargs) * elif collection == b"bcftools": # <<<<<<<<<<<<<< * retval = bcftools_main(n + 2, cargs) * */ - __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_v_collection, __pyx_n_b_bcftools, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 337, __pyx_L1_error) - if (__pyx_t_12) { + __pyx_t_8 = (__Pyx_PyBytes_Equals(__pyx_v_collection, __pyx_n_b_bcftools, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 353, __pyx_L1_error) + if (__pyx_t_8) { - /* "pysam/libcutils.pyx":338 + /* "pysam/libcutils.pyx":354 * retval = samtools_main(n + 2, cargs) * elif collection == b"bcftools": * retval = bcftools_main(n + 2, cargs) # <<<<<<<<<<<<<< @@ -6917,7 +7041,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj */ __pyx_v_retval = bcftools_main((__pyx_v_n + 2), __pyx_v_cargs); - /* "pysam/libcutils.pyx":337 + /* "pysam/libcutils.pyx":353 * if collection == b"samtools": * retval = samtools_main(n + 2, cargs) * elif collection == b"bcftools": # <<<<<<<<<<<<<< @@ -6925,19 +7049,19 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj * */ } - __pyx_L32:; + __pyx_L36:; - /* "pysam/libcutils.pyx":340 + /* "pysam/libcutils.pyx":356 * retval = bcftools_main(n + 2, cargs) * * for i from 0 <= i < n: # <<<<<<<<<<<<<< * free(cargs[i + 2]) * free(cargs) */ - __pyx_t_9 = __pyx_v_n; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_9; __pyx_v_i++) { + __pyx_t_10 = __pyx_v_n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_10; __pyx_v_i++) { - /* "pysam/libcutils.pyx":341 + /* "pysam/libcutils.pyx":357 * * for i from 0 <= i < n: * free(cargs[i + 2]) # <<<<<<<<<<<<<< @@ -6947,7 +7071,7 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj free((__pyx_v_cargs[(__pyx_v_i + 2)])); } - /* "pysam/libcutils.pyx":342 + /* "pysam/libcutils.pyx":358 * for i from 0 <= i < n: * free(cargs[i + 2]) * free(cargs) # <<<<<<<<<<<<<< @@ -6956,121 +7080,157 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj */ free(__pyx_v_cargs); - /* "pysam/libcutils.pyx":345 + /* "pysam/libcutils.pyx":361 * * # get error messages * def _collect(fn): # <<<<<<<<<<<<<< * out = [] * try: */ - __pyx_t_3 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libcutils_15_pysam_dispatch_1_collect, 0, __pyx_n_s_pysam_dispatch_locals__collect, NULL, __pyx_n_s_pysam_libcutils, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 345, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v__collect = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5pysam_9libcutils_15_pysam_dispatch_1_collect, 0, __pyx_n_s_pysam_dispatch_locals__collect, NULL, __pyx_n_s_pysam_libcutils, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 361, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v__collect = __pyx_t_4; + __pyx_t_4 = 0; - /* "pysam/libcutils.pyx":358 + /* "pysam/libcutils.pyx":374 * return out * - * pysam_unset_stderr() # <<<<<<<<<<<<<< - * out_stderr = _collect(stderr_f) + * samtools_unset_stderr() # <<<<<<<<<<<<<< + * bcftools_unset_stderr() * */ - pysam_unset_stderr(); + samtools_unset_stderr(); - /* "pysam/libcutils.pyx":359 + /* "pysam/libcutils.pyx":375 * - * pysam_unset_stderr() - * out_stderr = _collect(stderr_f) # <<<<<<<<<<<<<< + * samtools_unset_stderr() + * bcftools_unset_stderr() # <<<<<<<<<<<<<< * - * if save_stdout: + * if save_stdout or catch_stdout: */ - __pyx_t_3 = __pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(__pyx_v__collect, __pyx_v_stderr_f); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 359, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_out_stderr = __pyx_t_3; - __pyx_t_3 = 0; + bcftools_unset_stderr(); - /* "pysam/libcutils.pyx":361 + /* "pysam/libcutils.pyx":377 + * bcftools_unset_stderr() + * + * if save_stdout or catch_stdout: # <<<<<<<<<<<<<< + * samtools_unset_stdout() + * bcftools_unset_stdout() + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_save_stdout); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 377, __pyx_L1_error) + if (!__pyx_t_2) { + } else { + __pyx_t_8 = __pyx_t_2; + goto __pyx_L40_bool_binop_done; + } + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 377, __pyx_L1_error) + __pyx_t_8 = __pyx_t_2; + __pyx_L40_bool_binop_done:; + if (__pyx_t_8) { + + /* "pysam/libcutils.pyx":378 + * + * if save_stdout or catch_stdout: + * samtools_unset_stdout() # <<<<<<<<<<<<<< + * bcftools_unset_stdout() + * + */ + samtools_unset_stdout(); + + /* "pysam/libcutils.pyx":379 + * if save_stdout or catch_stdout: + * samtools_unset_stdout() + * bcftools_unset_stdout() # <<<<<<<<<<<<<< + * * out_stderr = _collect(stderr_f) + */ + bcftools_unset_stdout(); + + /* "pysam/libcutils.pyx":377 + * bcftools_unset_stderr() * - * if save_stdout: # <<<<<<<<<<<<<< - * pysam_unset_stdout() - * out_stdout = None + * if save_stdout or catch_stdout: # <<<<<<<<<<<<<< + * samtools_unset_stdout() + * bcftools_unset_stdout() */ - __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_save_stdout); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 361, __pyx_L1_error) - if (__pyx_t_12) { + } - /* "pysam/libcutils.pyx":362 + /* "pysam/libcutils.pyx":381 + * bcftools_unset_stdout() * + * out_stderr = _collect(stderr_f) # <<<<<<<<<<<<<< * if save_stdout: - * pysam_unset_stdout() # <<<<<<<<<<<<<< + * out_stdout = None + */ + __pyx_t_4 = __pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(__pyx_v__collect, __pyx_v_stderr_f); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 381, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_out_stderr = __pyx_t_4; + __pyx_t_4 = 0; + + /* "pysam/libcutils.pyx":382 + * + * out_stderr = _collect(stderr_f) + * if save_stdout: # <<<<<<<<<<<<<< * out_stdout = None * elif catch_stdout: */ - pysam_unset_stdout(); + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_save_stdout); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 382, __pyx_L1_error) + if (__pyx_t_8) { - /* "pysam/libcutils.pyx":363 + /* "pysam/libcutils.pyx":383 + * out_stderr = _collect(stderr_f) * if save_stdout: - * pysam_unset_stdout() * out_stdout = None # <<<<<<<<<<<<<< * elif catch_stdout: - * pysam_unset_stdout() + * out_stdout = _collect(stdout_f) */ __Pyx_INCREF(Py_None); __pyx_v_out_stdout = Py_None; - /* "pysam/libcutils.pyx":361 - * out_stderr = _collect(stderr_f) + /* "pysam/libcutils.pyx":382 * + * out_stderr = _collect(stderr_f) * if save_stdout: # <<<<<<<<<<<<<< - * pysam_unset_stdout() * out_stdout = None + * elif catch_stdout: */ - goto __pyx_L35; + goto __pyx_L42; } - /* "pysam/libcutils.pyx":364 - * pysam_unset_stdout() + /* "pysam/libcutils.pyx":384 + * if save_stdout: * out_stdout = None * elif catch_stdout: # <<<<<<<<<<<<<< - * pysam_unset_stdout() - * out_stdout = _collect(stdout_f) - */ - __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 364, __pyx_L1_error) - if (__pyx_t_12) { - - /* "pysam/libcutils.pyx":365 - * out_stdout = None - * elif catch_stdout: - * pysam_unset_stdout() # <<<<<<<<<<<<<< * out_stdout = _collect(stdout_f) * else: */ - pysam_unset_stdout(); + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 384, __pyx_L1_error) + if (__pyx_t_8) { - /* "pysam/libcutils.pyx":366 + /* "pysam/libcutils.pyx":385 + * out_stdout = None * elif catch_stdout: - * pysam_unset_stdout() * out_stdout = _collect(stdout_f) # <<<<<<<<<<<<<< * else: * out_stdout = None */ - if (unlikely(!__pyx_v_stdout_f)) { __Pyx_RaiseUnboundLocalError("stdout_f"); __PYX_ERR(0, 366, __pyx_L1_error) } - __pyx_t_3 = __pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(__pyx_v__collect, __pyx_v_stdout_f); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_out_stdout = __pyx_t_3; - __pyx_t_3 = 0; + if (unlikely(!__pyx_v_stdout_f)) { __Pyx_RaiseUnboundLocalError("stdout_f"); __PYX_ERR(0, 385, __pyx_L1_error) } + __pyx_t_4 = __pyx_pf_5pysam_9libcutils_15_pysam_dispatch__collect(__pyx_v__collect, __pyx_v_stdout_f); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 385, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_out_stdout = __pyx_t_4; + __pyx_t_4 = 0; - /* "pysam/libcutils.pyx":364 - * pysam_unset_stdout() + /* "pysam/libcutils.pyx":384 + * if save_stdout: * out_stdout = None * elif catch_stdout: # <<<<<<<<<<<<<< - * pysam_unset_stdout() * out_stdout = _collect(stdout_f) + * else: */ - goto __pyx_L35; + goto __pyx_L42; } - /* "pysam/libcutils.pyx":368 + /* "pysam/libcutils.pyx":387 * out_stdout = _collect(stdout_f) * else: * out_stdout = None # <<<<<<<<<<<<<< @@ -7081,9 +7241,9 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj __Pyx_INCREF(Py_None); __pyx_v_out_stdout = Py_None; } - __pyx_L35:; + __pyx_L42:; - /* "pysam/libcutils.pyx":370 + /* "pysam/libcutils.pyx":389 * out_stdout = None * * return retval, out_stderr, out_stdout # <<<<<<<<<<<<<< @@ -7091,24 +7251,24 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_retval); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 370, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 370, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_retval); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 389, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 389, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __Pyx_INCREF(__pyx_v_out_stderr); __Pyx_GIVEREF(__pyx_v_out_stderr); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_out_stderr); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_out_stderr); __Pyx_INCREF(__pyx_v_out_stdout); __Pyx_GIVEREF(__pyx_v_out_stdout); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_out_stdout); - __pyx_t_3 = 0; - __pyx_r = __pyx_t_4; + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_out_stdout); __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; goto __pyx_L0; - /* "pysam/libcutils.pyx":233 + /* "pysam/libcutils.pyx":235 * * * def _pysam_dispatch(collection, # <<<<<<<<<<<<<< @@ -7118,12 +7278,12 @@ static PyObject *__pyx_pf_5pysam_9libcutils_8_pysam_dispatch(CYTHON_UNUSED PyObj /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_14); __Pyx_AddTraceback("pysam.libcutils._pysam_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -7830,7 +7990,6 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_MAP_STDOUT_OPTIONS, __pyx_k_MAP_STDOUT_OPTIONS, sizeof(__pyx_k_MAP_STDOUT_OPTIONS), 0, 0, 1, 1}, {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, {&__pyx_kp_s_No_such_file_or_directory_s, __pyx_k_No_such_file_or_directory_s, sizeof(__pyx_k_No_such_file_or_directory_s), 0, 0, 1, 0}, - {&__pyx_n_s_OSError, __pyx_k_OSError, sizeof(__pyx_k_OSError), 0, 0, 1, 1}, {&__pyx_n_s_OverflowError, __pyx_k_OverflowError, sizeof(__pyx_k_OverflowError), 0, 0, 1, 1}, {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, {&__pyx_n_s_UnicodeDecodeError, __pyx_k_UnicodeDecodeError, sizeof(__pyx_k_UnicodeDecodeError), 0, 0, 1, 1}, @@ -7881,6 +8040,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_input_str, __pyx_k_input_str, sizeof(__pyx_k_input_str), 0, 0, 1, 1}, {&__pyx_kp_s_invalid_region_start_i_end_i, __pyx_k_invalid_region_start_i_end_i, sizeof(__pyx_k_invalid_region_start_i_end_i), 0, 0, 1, 0}, {&__pyx_n_s_io, __pyx_k_io, sizeof(__pyx_k_io), 0, 0, 1, 1}, + {&__pyx_n_s_is_usage, __pyx_k_is_usage, sizeof(__pyx_k_is_usage), 0, 0, 1, 1}, {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1}, {&__pyx_n_b_kprobaln, __pyx_k_kprobaln, sizeof(__pyx_k_kprobaln), 0, 0, 0, 1}, {&__pyx_n_s_l, __pyx_k_l, sizeof(__pyx_k_l), 0, 0, 1, 1}, @@ -7936,14 +8096,13 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) __PYX_ERR(0, 71, __pyx_L1_error) - __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 105, __pyx_L1_error) - __pyx_builtin_OverflowError = __Pyx_GetBuiltinName(__pyx_n_s_OverflowError); if (!__pyx_builtin_OverflowError) __PYX_ERR(0, 201, __pyx_L1_error) - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 202, __pyx_L1_error) - __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 247, __pyx_L1_error) - __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 264, __pyx_L1_error) - __pyx_builtin_open = __Pyx_GetBuiltinName(__pyx_n_s_open); if (!__pyx_builtin_open) __PYX_ERR(0, 348, __pyx_L1_error) - __pyx_builtin_UnicodeDecodeError = __Pyx_GetBuiltinName(__pyx_n_s_UnicodeDecodeError); if (!__pyx_builtin_UnicodeDecodeError) __PYX_ERR(0, 350, __pyx_L1_error) + __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) __PYX_ERR(0, 77, __pyx_L1_error) + __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_builtin_OverflowError = __Pyx_GetBuiltinName(__pyx_n_s_OverflowError); if (!__pyx_builtin_OverflowError) __PYX_ERR(0, 203, __pyx_L1_error) + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 204, __pyx_L1_error) + __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 255, __pyx_L1_error) + __pyx_builtin_open = __Pyx_GetBuiltinName(__pyx_n_s_open); if (!__pyx_builtin_open) __PYX_ERR(0, 364, __pyx_L1_error) + __pyx_builtin_UnicodeDecodeError = __Pyx_GetBuiltinName(__pyx_n_s_UnicodeDecodeError); if (!__pyx_builtin_UnicodeDecodeError) __PYX_ERR(0, 366, __pyx_L1_error) __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(1, 109, __pyx_L1_error) return 0; __pyx_L1_error:; @@ -7954,95 +8113,95 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "pysam/libcutils.pyx":105 + /* "pysam/libcutils.pyx":111 * return filename.encode(FILENAME_ENCODING) * else: * raise TypeError("Argument must be string or unicode.") # <<<<<<<<<<<<<< * * */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_Argument_must_be_string_or_unico); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 105, __pyx_L1_error) + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_Argument_must_be_string_or_unico); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 111, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2); - /* "pysam/libcutils.pyx":119 + /* "pysam/libcutils.pyx":125 * return s.encode(encoding) * else: * raise TypeError("Argument must be string, bytes or unicode.") # <<<<<<<<<<<<<< * * */ - __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_Argument_must_be_string_bytes_or); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 119, __pyx_L1_error) + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_Argument_must_be_string_bytes_or); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 125, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__3); - /* "pysam/libcutils.pyx":220 + /* "pysam/libcutils.pyx":222 * * if not reference: * return None, 0, 0 # <<<<<<<<<<<<<< * * if not 0 <= rstart < MAX_POS: */ - __pyx_tuple__5 = PyTuple_Pack(3, Py_None, __pyx_int_0, __pyx_int_0); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 220, __pyx_L1_error) + __pyx_tuple__5 = PyTuple_Pack(3, Py_None, __pyx_int_0, __pyx_int_0); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 222, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__5); __Pyx_GIVEREF(__pyx_tuple__5); - /* "pysam/libcutils.pyx":348 + /* "pysam/libcutils.pyx":364 * out = [] * try: * with open(fn, "r") as inf: # <<<<<<<<<<<<<< * out = inf.read() * except UnicodeDecodeError: */ - __pyx_tuple__6 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 348, __pyx_L1_error) + __pyx_tuple__6 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 364, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__6); __Pyx_GIVEREF(__pyx_tuple__6); - /* "pysam/libcutils.pyx":351 + /* "pysam/libcutils.pyx":367 * out = inf.read() * except UnicodeDecodeError: * with open(fn, "rb") as inf: # <<<<<<<<<<<<<< * # read binary output * out = inf.read() */ - __pyx_tuple__7 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 351, __pyx_L1_error) + __pyx_tuple__7 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 367, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__7); __Pyx_GIVEREF(__pyx_tuple__7); - /* "pysam/libcutils.pyx":295 - * os.close(stdout_h) - * pysam_set_stdout_fn(force_bytes(stdout_f)) + /* "pysam/libcutils.pyx":307 + * samtools_set_stdout_fn(force_bytes(stdout_f)) + * bcftools_set_stdout_fn(force_bytes(stdout_f)) * args.extend(stdout_option.format(stdout_f).split(" ")) # <<<<<<<<<<<<<< * else: - * pysam_set_stdout(stdout_h) + * samtools_set_stdout(stdout_h) */ - __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s__8); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 295, __pyx_L1_error) + __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s__8); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__9); __Pyx_GIVEREF(__pyx_tuple__9); - /* "pysam/libcutils.pyx":345 + /* "pysam/libcutils.pyx":361 * * # get error messages * def _collect(fn): # <<<<<<<<<<<<<< * out = [] * try: */ - __pyx_tuple__10 = PyTuple_Pack(3, __pyx_n_s_fn, __pyx_n_s_out, __pyx_n_s_inf); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_tuple__10 = PyTuple_Pack(3, __pyx_n_s_fn, __pyx_n_s_out, __pyx_n_s_inf); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 361, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__10); __Pyx_GIVEREF(__pyx_tuple__10); - __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcutils_pyx, __pyx_n_s_collect, 345, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 345, __pyx_L1_error) + __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcutils_pyx, __pyx_n_s_collect, 361, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 361, __pyx_L1_error) - /* "pysam/libcutils.pyx":233 + /* "pysam/libcutils.pyx":235 * * * def _pysam_dispatch(collection, # <<<<<<<<<<<<<< * method, * args=None, */ - __pyx_tuple__12 = PyTuple_Pack(22, __pyx_n_s_collection, __pyx_n_s_method, __pyx_n_s_args, __pyx_n_s_catch_stdout, __pyx_n_s_save_stdout, __pyx_n_s_stderr_h, __pyx_n_s_stderr_f, __pyx_n_s_stdout_f, __pyx_n_s_stdout_h, __pyx_n_s_MAP_STDOUT_OPTIONS, __pyx_n_s_stdout_option, __pyx_n_s_cargs, __pyx_n_s_i, __pyx_n_s_n, __pyx_n_s_retval, __pyx_n_s_l, __pyx_n_s_extra_args, __pyx_n_s_collect, __pyx_n_s_collect, __pyx_n_s_out_stderr, __pyx_n_s_out_stdout, __pyx_n_s_a); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 233, __pyx_L1_error) + __pyx_tuple__12 = PyTuple_Pack(23, __pyx_n_s_collection, __pyx_n_s_method, __pyx_n_s_args, __pyx_n_s_catch_stdout, __pyx_n_s_is_usage, __pyx_n_s_save_stdout, __pyx_n_s_stderr_h, __pyx_n_s_stderr_f, __pyx_n_s_stdout_f, __pyx_n_s_stdout_h, __pyx_n_s_MAP_STDOUT_OPTIONS, __pyx_n_s_stdout_option, __pyx_n_s_cargs, __pyx_n_s_i, __pyx_n_s_n, __pyx_n_s_retval, __pyx_n_s_l, __pyx_n_s_extra_args, __pyx_n_s_collect, __pyx_n_s_collect, __pyx_n_s_out_stderr, __pyx_n_s_out_stdout, __pyx_n_s_a); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 235, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__12); __Pyx_GIVEREF(__pyx_tuple__12); - __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(5, 0, 22, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcutils_pyx, __pyx_n_s_pysam_dispatch, 233, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 233, __pyx_L1_error) + __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(6, 0, 23, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcutils_pyx, __pyx_n_s_pysam_dispatch, 235, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 235, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -8430,7 +8589,7 @@ if (!__Pyx_RefNanny) { __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcutils.pyx":21 + /* "pysam/libcutils.pyx":27 * ##################################################################### * # hard-coded constants * cdef int MAX_POS = 2 << 29 # <<<<<<<<<<<<<< @@ -8439,7 +8598,7 @@ if (!__Pyx_RefNanny) { */ __pyx_v_5pysam_9libcutils_MAX_POS = 0x40000000; - /* "pysam/libcutils.pyx":80 + /* "pysam/libcutils.pyx":86 * ######################################################################## * * cdef bint IS_PYTHON3 = PY_MAJOR_VERSION >= 3 # <<<<<<<<<<<<<< @@ -8448,44 +8607,44 @@ if (!__Pyx_RefNanny) { */ __pyx_v_5pysam_9libcutils_IS_PYTHON3 = (PY_MAJOR_VERSION >= 3); - /* "pysam/libcutils.pyx":90 + /* "pysam/libcutils.pyx":96 * * # filename encoding (adapted from lxml.etree.pyx) * cdef str FILENAME_ENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding() or 'ascii' # <<<<<<<<<<<<<< * * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_getfilesystemencoding); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_getfilesystemencoding); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 96, __pyx_L1_error) if (!__pyx_t_4) { __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { - if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 90, __pyx_L1_error) + if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_t_1; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L2_bool_binop_done; } - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_getdefaultencoding); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_getdefaultencoding); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 96, __pyx_L1_error) if (!__pyx_t_4) { __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { - if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 90, __pyx_L1_error) + if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 96, __pyx_L1_error) __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_t_1; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -8499,26 +8658,26 @@ if (!__Pyx_RefNanny) { __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcutils.pyx":233 + /* "pysam/libcutils.pyx":235 * * * def _pysam_dispatch(collection, # <<<<<<<<<<<<<< * method, * args=None, */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libcutils_9_pysam_dispatch, NULL, __pyx_n_s_pysam_libcutils); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 233, __pyx_L1_error) + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_5pysam_9libcutils_9_pysam_dispatch, NULL, __pyx_n_s_pysam_libcutils); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 235, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pysam_dispatch, __pyx_t_2) < 0) __PYX_ERR(0, 233, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pysam_dispatch, __pyx_t_2) < 0) __PYX_ERR(0, 235, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "pysam/libcutils.pyx":373 + /* "pysam/libcutils.pyx":392 * * * __all__ = ["qualitystring_to_array", # <<<<<<<<<<<<<< * "array_to_qualitystring", * "qualities_to_qualitystring"] */ - __pyx_t_2 = PyList_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 373, __pyx_L1_error) + __pyx_t_2 = PyList_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 392, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_qualitystring_to_array); __Pyx_GIVEREF(__pyx_n_s_qualitystring_to_array); @@ -8529,7 +8688,7 @@ if (!__Pyx_RefNanny) { __Pyx_INCREF(__pyx_n_s_qualities_to_qualitystring); __Pyx_GIVEREF(__pyx_n_s_qualities_to_qualitystring); PyList_SET_ITEM(__pyx_t_2, 2, __pyx_n_s_qualities_to_qualitystring); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_2) < 0) __PYX_ERR(0, 373, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_2) < 0) __PYX_ERR(0, 392, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pysam/libcutils.pyx":1 diff --git a/pysam/libcutils.pxd b/pysam/libcutils.pxd index 81e544a30..f2d0aeb89 100644 --- a/pysam/libcutils.pxd +++ b/pysam/libcutils.pxd @@ -26,13 +26,3 @@ cdef bytes force_bytes(object s, encoding=*) cdef bytes encode_filename(object filename) cdef from_string_and_size(const char *s, size_t length) -cdef extern from "pysam_util.h": - - int samtools_main(int argc, char *argv[]) - int bcftools_main(int argc, char *argv[]) - void pysam_set_stderr(int fd) - void pysam_unset_stderr() - void pysam_set_stdout(int fd) - void pysam_set_stdout_fn(const char *) - void pysam_unset_stdout() - void set_optind(int) diff --git a/pysam/libcutils.pyx b/pysam/libcutils.pyx index 80bd9e44c..66f9bf939 100644 --- a/pysam/libcutils.pyx +++ b/pysam/libcutils.pyx @@ -16,6 +16,12 @@ from libc.stdio cimport fprintf, stderr, fflush from libc.stdio cimport stdout as c_stdout from posix.fcntl cimport open as c_open, O_WRONLY +from libcsamtools cimport samtools_main, samtools_set_stdout, samtools_set_stderr, \ + samtools_unset_stderr, samtools_unset_stdout, samtools_set_stdout_fn, samtools_set_optind + +from libcbcftools cimport bcftools_main, bcftools_set_stdout, bcftools_set_stderr, \ + bcftools_unset_stderr, bcftools_unset_stdout, bcftools_set_stdout_fn, bcftools_set_optind + ##################################################################### # hard-coded constants cdef int MAX_POS = 2 << 29 @@ -164,17 +170,15 @@ cpdef parse_region(reference=None, region=None): """parse alternative ways to specify a genomic region. A region can either be specified by :term:`reference`, `start` and - `end`. `start` and `end` denote 0-based, half-open - intervals. + `end`. `start` and `end` denote 0-based, half-open intervals. - Alternatively, a samtools :term:`region` string can be - supplied. + Alternatively, a samtools :term:`region` string can be supplied. If any of the coordinates are missing they will be replaced by the minimum (`start`) or maximum (`end`) coordinate. - Note that region strings are 1-based, while `start` and `end` denote - an interval in python coordinates. + Note that region strings are 1-based, while `start` and `end` + denote an interval in python coordinates. Returns ------- @@ -188,11 +192,9 @@ cpdef parse_region(reference=None, for invalid or out of bounds regions. """ - cdef int rtid cdef long long rstart cdef long long rend - rtid = -1 rstart = 0 rend = MAX_POS if start != None: @@ -234,16 +236,22 @@ def _pysam_dispatch(collection, method, args=None, catch_stdout=True, + is_usage=False, save_stdout=None): '''call ``method`` in samtools/bcftools providing arguments in args. + By default, stdout is redirected to a temporary file using the patched + C sources except for a few commands that have an explicit output option + (typically: -o). In these commands (such as samtools view), this explicit + option is used. If *is_usage* is True, then these explicit output options + will not be used. + Catching of stdout can be turned off by setting *catch_stdout* to False. - ''' if method == "index": - if not os.path.exists(args[0]): + if args and not os.path.exists(args[0]): raise IOError("No such file or directory: '%s'" % args[0]) if args is None: @@ -253,31 +261,34 @@ def _pysam_dispatch(collection, # redirect stderr to file stderr_h, stderr_f = tempfile.mkstemp() - pysam_set_stderr(stderr_h) - + samtools_set_stderr(stderr_h) + bcftools_set_stderr(stderr_h) + # redirect stdout to file if save_stdout: stdout_f = save_stdout stdout_h = c_open(force_bytes(stdout_f), O_WRONLY) if stdout_h == -1: - raise OSError("error while opening {} for writing".format(stdout_f)) + raise IOError("error while opening {} for writing".format(stdout_f)) - pysam_set_stdout_fn(force_bytes(stdout_f)) - pysam_set_stdout(stdout_h) + samtools_set_stdout_fn(force_bytes(stdout_f)) + samtools_set_stdout(stdout_h) + bcftools_set_stdout_fn(force_bytes(stdout_f)) + bcftools_set_stdout(stdout_h) + elif catch_stdout: stdout_h, stdout_f = tempfile.mkstemp() - MAP_STDOUT_OPTIONS = { - "samtools": { - "view": "-o {}", - "mpileup": "-o {}", - "depad": "-o {}", - "calmd": "", # uses pysam_stdout_fn - }, + "samtools": { + "view": "-o {}", + "mpileup": "-o {}", + "depad": "-o {}", + "calmd": "", # uses pysam_stdout_fn + }, "bcftools": {} } - + stdout_option = None if collection == "bcftools": # in bcftools, most methods accept -o, the exceptions @@ -289,14 +300,17 @@ def _pysam_dispatch(collection, if not(method == "view" and "-c" in args): stdout_option = MAP_STDOUT_OPTIONS[collection][method] - if stdout_option is not None: + if stdout_option is not None and not is_usage: os.close(stdout_h) - pysam_set_stdout_fn(force_bytes(stdout_f)) + samtools_set_stdout_fn(force_bytes(stdout_f)) + bcftools_set_stdout_fn(force_bytes(stdout_f)) args.extend(stdout_option.format(stdout_f).split(" ")) else: - pysam_set_stdout(stdout_h) + samtools_set_stdout(stdout_h) + bcftools_set_stdout(stdout_h) else: - pysam_set_stdout_fn("-") + samtools_set_stdout_fn("-") + bcftools_set_stdout_fn("-") # setup the function call to samtools/bcftools main cdef char ** cargs @@ -327,9 +341,11 @@ def _pysam_dispatch(collection, # between getopt and getopt_long if method in [b'index', b'cat', b'quickcheck', b'faidx', b'kprobaln']: - set_optind(1) + samtools_set_optind(1) + bcftools_set_optind(1) else: - set_optind(0) + samtools_set_optind(0) + bcftools_set_optind(0) # call samtools/bcftools if collection == b"samtools": @@ -355,18 +371,21 @@ def _pysam_dispatch(collection, os.remove(fn) return out - pysam_unset_stderr() - out_stderr = _collect(stderr_f) + samtools_unset_stderr() + bcftools_unset_stderr() + if save_stdout or catch_stdout: + samtools_unset_stdout() + bcftools_unset_stdout() + + out_stderr = _collect(stderr_f) if save_stdout: - pysam_unset_stdout() out_stdout = None elif catch_stdout: - pysam_unset_stdout() out_stdout = _collect(stdout_f) else: out_stdout = None - + return retval, out_stderr, out_stdout diff --git a/pysam/libcvcf.c b/pysam/libcvcf.c index 3dc2ee655..8833f6fbf 100644 --- a/pysam/libcvcf.c +++ b/pysam/libcvcf.c @@ -569,6 +569,7 @@ static CYTHON_INLINE float __PYX_NAN() { #include "fcntl.h" #include "unistd.h" #include +#include "stdarg.h" #include "htslib/kstring.h" #include "htslib_util.h" #include "htslib/hfile.h" @@ -579,9 +580,9 @@ static CYTHON_INLINE float __PYX_NAN() { #include "htslib/tbx.h" #include "htslib/vcf.h" #include "htslib/vcfutils.h" +#include "htslib/cram.h" #include "pysam_stream.h" #include "pythread.h" -#include "pysam_util.h" #ifdef _OPENMP #include #endif /* _OPENMP */ @@ -807,6 +808,7 @@ struct __pyx_obj_5pysam_9libctabix_TabixFile; struct __pyx_obj_5pysam_9libctabix_Parser; struct __pyx_obj_5pysam_9libctabix_asTuple; struct __pyx_obj_5pysam_9libctabix_asGTF; +struct __pyx_obj_5pysam_9libctabix_asGFF3; struct __pyx_obj_5pysam_9libctabix_asBed; struct __pyx_obj_5pysam_9libctabix_asVCF; struct __pyx_obj_5pysam_9libctabix_TabixIterator; @@ -816,8 +818,9 @@ struct __pyx_obj_5pysam_9libctabix_GZIteratorHead; struct __pyx_obj_5pysam_9libctabix_GZIteratorParsed; struct __pyx_obj_5pysam_9libctabix_Tabixfile; struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy; -struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy; struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy; +struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy; +struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy; struct __pyx_obj_5pysam_16libctabixproxies_BedProxy; struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy; struct __pyx_obj_5pysam_7libcvcf_VCFRecord; @@ -957,7 +960,7 @@ struct __pyx_opt_args_5pysam_9libcutils_force_bytes { PyObject *encoding; }; -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -971,6 +974,7 @@ struct __pyx_obj_5pysam_10libchtslib_HTSFile { int64_t start_offset; PyObject *filename; PyObject *mode; + PyObject *threads; PyObject *index_filename; int is_stream; int is_remote; @@ -1054,6 +1058,18 @@ struct __pyx_obj_5pysam_9libctabix_asGTF { /* "pysam/libctabix.pxd":84 + * + * + * cdef class asGFF3(Parser): # <<<<<<<<<<<<<< + * pass + * + */ +struct __pyx_obj_5pysam_9libctabix_asGFF3 { + struct __pyx_obj_5pysam_9libctabix_Parser __pyx_base; +}; + + +/* "pysam/libctabix.pxd":88 * * * cdef class asBed(Parser): # <<<<<<<<<<<<<< @@ -1065,7 +1081,7 @@ struct __pyx_obj_5pysam_9libctabix_asBed { }; -/* "pysam/libctabix.pxd":88 +/* "pysam/libctabix.pxd":92 * * * cdef class asVCF(Parser): # <<<<<<<<<<<<<< @@ -1077,7 +1093,7 @@ struct __pyx_obj_5pysam_9libctabix_asVCF { }; -/* "pysam/libctabix.pxd":92 +/* "pysam/libctabix.pxd":96 * * * cdef class TabixIterator: # <<<<<<<<<<<<<< @@ -1094,7 +1110,7 @@ struct __pyx_obj_5pysam_9libctabix_TabixIterator { }; -/* "pysam/libctabix.pxd":100 +/* "pysam/libctabix.pxd":104 * * * cdef class TabixIteratorParsed(TabixIterator): # <<<<<<<<<<<<<< @@ -1107,7 +1123,7 @@ struct __pyx_obj_5pysam_9libctabix_TabixIteratorParsed { }; -/* "pysam/libctabix.pxd":104 +/* "pysam/libctabix.pxd":108 * * * cdef class GZIterator: # <<<<<<<<<<<<<< @@ -1125,7 +1141,7 @@ struct __pyx_obj_5pysam_9libctabix_GZIterator { }; -/* "pysam/libctabix.pxd":113 +/* "pysam/libctabix.pxd":117 * * * cdef class GZIteratorHead(GZIterator): # <<<<<<<<<<<<<< @@ -1137,7 +1153,7 @@ struct __pyx_obj_5pysam_9libctabix_GZIteratorHead { }; -/* "pysam/libctabix.pxd":117 +/* "pysam/libctabix.pxd":121 * * * cdef class GZIteratorParsed(GZIterator): # <<<<<<<<<<<<<< @@ -1150,7 +1166,7 @@ struct __pyx_obj_5pysam_9libctabix_GZIteratorParsed { }; -/* "pysam/libctabix.pxd":122 +/* "pysam/libctabix.pxd":126 * * # Compatibility Layer for pysam < 0.8 * cdef class Tabixfile(TabixFile): # <<<<<<<<<<<<<< @@ -1182,35 +1198,46 @@ struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy { }; -/* "pysam/libctabixproxies.pxd":28 - * cdef update(self, char * buffer, size_t nbytes) +/* "pysam/libctabixproxies.pxd":29 * - * cdef class GTFProxy(TupleProxy) : # <<<<<<<<<<<<<< * - * cdef: + * cdef class NamedTupleProxy(TupleProxy): # <<<<<<<<<<<<<< + * pass + * */ -struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy { +struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy { struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy __pyx_base; - char *_attributes; - int hasOwnAttributes; }; -/* "pysam/libctabixproxies.pxd":38 - * cdef char * getAttributes(self) +/* "pysam/libctabixproxies.pxd":33 * - * cdef class NamedTupleProxy(TupleProxy): # <<<<<<<<<<<<<< - * pass * + * cdef class GTFProxy(NamedTupleProxy): # <<<<<<<<<<<<<< + * cdef object attribute_dict + * cpdef int getMaxFields(self) */ -struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy { - struct __pyx_obj_5pysam_16libctabixproxies_TupleProxy __pyx_base; +struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy { + struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy __pyx_base; + PyObject *attribute_dict; }; -/* "pysam/libctabixproxies.pxd":41 +/* "pysam/libctabixproxies.pxd":39 + * + * + * cdef class GFF3Proxy(GTFProxy): # <<<<<<<<<<<<<< * pass * + */ +struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy { + struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy __pyx_base; +}; + + +/* "pysam/libctabixproxies.pxd":43 + * + * * cdef class BedProxy(NamedTupleProxy): # <<<<<<<<<<<<<< * * cdef: @@ -1224,7 +1251,7 @@ struct __pyx_obj_5pysam_16libctabixproxies_BedProxy { }; -/* "pysam/libctabixproxies.pxd":53 +/* "pysam/libctabixproxies.pxd":55 * cdef update(self, char * buffer, size_t nbytes) * * cdef class VCFProxy(NamedTupleProxy) : # <<<<<<<<<<<<<< @@ -1286,7 +1313,7 @@ struct __pyx_obj_5pysam_7libcvcf___pyx_scope_struct___parse { -/* "pysam/libchtslib.pxd":1904 +/* "pysam/libchtslib.pxd":2590 * * * cdef class HTSFile(object): # <<<<<<<<<<<<<< @@ -1371,6 +1398,20 @@ static struct __pyx_vtabstruct_5pysam_9libctabix_asGTF *__pyx_vtabptr_5pysam_9li /* "pysam/libctabix.pxd":84 + * + * + * cdef class asGFF3(Parser): # <<<<<<<<<<<<<< + * pass + * + */ + +struct __pyx_vtabstruct_5pysam_9libctabix_asGFF3 { + struct __pyx_vtabstruct_5pysam_9libctabix_Parser __pyx_base; +}; +static struct __pyx_vtabstruct_5pysam_9libctabix_asGFF3 *__pyx_vtabptr_5pysam_9libctabix_asGFF3; + + +/* "pysam/libctabix.pxd":88 * * * cdef class asBed(Parser): # <<<<<<<<<<<<<< @@ -1384,7 +1425,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_asBed { static struct __pyx_vtabstruct_5pysam_9libctabix_asBed *__pyx_vtabptr_5pysam_9libctabix_asBed; -/* "pysam/libctabix.pxd":88 +/* "pysam/libctabix.pxd":92 * * * cdef class asVCF(Parser): # <<<<<<<<<<<<<< @@ -1398,7 +1439,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_asVCF { static struct __pyx_vtabstruct_5pysam_9libctabix_asVCF *__pyx_vtabptr_5pysam_9libctabix_asVCF; -/* "pysam/libctabix.pxd":92 +/* "pysam/libctabix.pxd":96 * * * cdef class TabixIterator: # <<<<<<<<<<<<<< @@ -1412,7 +1453,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_TabixIterator { static struct __pyx_vtabstruct_5pysam_9libctabix_TabixIterator *__pyx_vtabptr_5pysam_9libctabix_TabixIterator; -/* "pysam/libctabix.pxd":100 +/* "pysam/libctabix.pxd":104 * * * cdef class TabixIteratorParsed(TabixIterator): # <<<<<<<<<<<<<< @@ -1426,7 +1467,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_TabixIteratorParsed { static struct __pyx_vtabstruct_5pysam_9libctabix_TabixIteratorParsed *__pyx_vtabptr_5pysam_9libctabix_TabixIteratorParsed; -/* "pysam/libctabix.pxd":104 +/* "pysam/libctabix.pxd":108 * * * cdef class GZIterator: # <<<<<<<<<<<<<< @@ -1440,7 +1481,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_GZIterator { static struct __pyx_vtabstruct_5pysam_9libctabix_GZIterator *__pyx_vtabptr_5pysam_9libctabix_GZIterator; -/* "pysam/libctabix.pxd":113 +/* "pysam/libctabix.pxd":117 * * * cdef class GZIteratorHead(GZIterator): # <<<<<<<<<<<<<< @@ -1454,7 +1495,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorHead { static struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorHead *__pyx_vtabptr_5pysam_9libctabix_GZIteratorHead; -/* "pysam/libctabix.pxd":117 +/* "pysam/libctabix.pxd":121 * * * cdef class GZIteratorParsed(GZIterator): # <<<<<<<<<<<<<< @@ -1468,7 +1509,7 @@ struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorParsed { static struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorParsed *__pyx_vtabptr_5pysam_9libctabix_GZIteratorParsed; -/* "pysam/libctabix.pxd":122 +/* "pysam/libctabix.pxd":126 * * # Compatibility Layer for pysam < 0.8 * cdef class Tabixfile(TabixFile): # <<<<<<<<<<<<<< @@ -1500,37 +1541,50 @@ struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy { static struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy *__pyx_vtabptr_5pysam_16libctabixproxies_TupleProxy; -/* "pysam/libctabixproxies.pxd":28 - * cdef update(self, char * buffer, size_t nbytes) +/* "pysam/libctabixproxies.pxd":29 * - * cdef class GTFProxy(TupleProxy) : # <<<<<<<<<<<<<< * - * cdef: + * cdef class NamedTupleProxy(TupleProxy): # <<<<<<<<<<<<<< + * pass + * */ -struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy { +struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy { struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy __pyx_base; - char *(*getAttributes)(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy *); +}; +static struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy; + + +/* "pysam/libctabixproxies.pxd":33 + * + * + * cdef class GTFProxy(NamedTupleProxy): # <<<<<<<<<<<<<< + * cdef object attribute_dict + * cpdef int getMaxFields(self) + */ + +struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy { + struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy __pyx_base; }; static struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy *__pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy; -/* "pysam/libctabixproxies.pxd":38 - * cdef char * getAttributes(self) +/* "pysam/libctabixproxies.pxd":39 * - * cdef class NamedTupleProxy(TupleProxy): # <<<<<<<<<<<<<< + * + * cdef class GFF3Proxy(GTFProxy): # <<<<<<<<<<<<<< * pass * */ -struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy { - struct __pyx_vtabstruct_5pysam_16libctabixproxies_TupleProxy __pyx_base; +struct __pyx_vtabstruct_5pysam_16libctabixproxies_GFF3Proxy { + struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy __pyx_base; }; -static struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy *__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy; +static struct __pyx_vtabstruct_5pysam_16libctabixproxies_GFF3Proxy *__pyx_vtabptr_5pysam_16libctabixproxies_GFF3Proxy; -/* "pysam/libctabixproxies.pxd":41 - * pass +/* "pysam/libctabixproxies.pxd":43 + * * * cdef class BedProxy(NamedTupleProxy): # <<<<<<<<<<<<<< * @@ -1543,7 +1597,7 @@ struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy { static struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy *__pyx_vtabptr_5pysam_16libctabixproxies_BedProxy; -/* "pysam/libctabixproxies.pxd":53 +/* "pysam/libctabixproxies.pxd":55 * cdef update(self, char * buffer, size_t nbytes) * * cdef class VCFProxy(NamedTupleProxy) : # <<<<<<<<<<<<<< @@ -2443,6 +2497,7 @@ static PyTypeObject *__pyx_ptype_5pysam_9libctabix_TabixFile = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_Parser = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_asTuple = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_asGTF = 0; +static PyTypeObject *__pyx_ptype_5pysam_9libctabix_asGFF3 = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_asBed = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_asVCF = 0; static PyTypeObject *__pyx_ptype_5pysam_9libctabix_TabixIterator = 0; @@ -2454,8 +2509,9 @@ static PyTypeObject *__pyx_ptype_5pysam_9libctabix_Tabixfile = 0; /* Module declarations from 'pysam.libctabixproxies' */ static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_TupleProxy = 0; -static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_GTFProxy = 0; static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy = 0; +static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_GTFProxy = 0; +static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_GFF3Proxy = 0; static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_BedProxy = 0; static PyTypeObject *__pyx_ptype_5pysam_16libctabixproxies_VCFProxy = 0; @@ -33884,8 +33940,8 @@ static int __Pyx_modinit_type_import_code(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); /*--- Type import code ---*/ - __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(3, 1904, __pyx_L1_error) - __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(3, 1904, __pyx_L1_error) + __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType("pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), 1); if (unlikely(!__pyx_ptype_5pysam_10libchtslib_HTSFile)) __PYX_ERR(3, 2590, __pyx_L1_error) + __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(3, 2590, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_tabix_file_iterator = __Pyx_ImportType("pysam.libctabix", "tabix_file_iterator", sizeof(struct __pyx_obj_5pysam_9libctabix_tabix_file_iterator), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_tabix_file_iterator)) __PYX_ERR(4, 47, __pyx_L1_error) __pyx_vtabptr_5pysam_9libctabix_tabix_file_iterator = (struct __pyx_vtabstruct_5pysam_9libctabix_tabix_file_iterator*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_tabix_file_iterator->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_tabix_file_iterator)) __PYX_ERR(4, 47, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_TabixFile = __Pyx_ImportType("pysam.libctabix", "TabixFile", sizeof(struct __pyx_obj_5pysam_9libctabix_TabixFile), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_TabixFile)) __PYX_ERR(4, 60, __pyx_L1_error) @@ -33894,30 +33950,34 @@ static int __Pyx_modinit_type_import_code(void) { __pyx_vtabptr_5pysam_9libctabix_asTuple = (struct __pyx_vtabstruct_5pysam_9libctabix_asTuple*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_asTuple->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_asTuple)) __PYX_ERR(4, 76, __pyx_L1_error) __pyx_ptype_5pysam_9libctabix_asGTF = __Pyx_ImportType("pysam.libctabix", "asGTF", sizeof(struct __pyx_obj_5pysam_9libctabix_asGTF), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_asGTF)) __PYX_ERR(4, 80, __pyx_L1_error) __pyx_vtabptr_5pysam_9libctabix_asGTF = (struct __pyx_vtabstruct_5pysam_9libctabix_asGTF*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_asGTF->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_asGTF)) __PYX_ERR(4, 80, __pyx_L1_error) - __pyx_ptype_5pysam_9libctabix_asBed = __Pyx_ImportType("pysam.libctabix", "asBed", sizeof(struct __pyx_obj_5pysam_9libctabix_asBed), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_asBed)) __PYX_ERR(4, 84, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libctabix_asBed = (struct __pyx_vtabstruct_5pysam_9libctabix_asBed*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_asBed->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_asBed)) __PYX_ERR(4, 84, __pyx_L1_error) - __pyx_ptype_5pysam_9libctabix_asVCF = __Pyx_ImportType("pysam.libctabix", "asVCF", sizeof(struct __pyx_obj_5pysam_9libctabix_asVCF), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_asVCF)) __PYX_ERR(4, 88, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libctabix_asVCF = (struct __pyx_vtabstruct_5pysam_9libctabix_asVCF*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_asVCF->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_asVCF)) __PYX_ERR(4, 88, __pyx_L1_error) - __pyx_ptype_5pysam_9libctabix_TabixIterator = __Pyx_ImportType("pysam.libctabix", "TabixIterator", sizeof(struct __pyx_obj_5pysam_9libctabix_TabixIterator), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_TabixIterator)) __PYX_ERR(4, 92, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libctabix_TabixIterator = (struct __pyx_vtabstruct_5pysam_9libctabix_TabixIterator*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_TabixIterator->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_TabixIterator)) __PYX_ERR(4, 92, __pyx_L1_error) - __pyx_ptype_5pysam_9libctabix_TabixIteratorParsed = __Pyx_ImportType("pysam.libctabix", "TabixIteratorParsed", sizeof(struct __pyx_obj_5pysam_9libctabix_TabixIteratorParsed), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_TabixIteratorParsed)) __PYX_ERR(4, 100, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libctabix_TabixIteratorParsed = (struct __pyx_vtabstruct_5pysam_9libctabix_TabixIteratorParsed*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_TabixIteratorParsed->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_TabixIteratorParsed)) __PYX_ERR(4, 100, __pyx_L1_error) - __pyx_ptype_5pysam_9libctabix_GZIterator = __Pyx_ImportType("pysam.libctabix", "GZIterator", sizeof(struct __pyx_obj_5pysam_9libctabix_GZIterator), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_GZIterator)) __PYX_ERR(4, 104, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libctabix_GZIterator = (struct __pyx_vtabstruct_5pysam_9libctabix_GZIterator*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_GZIterator->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_GZIterator)) __PYX_ERR(4, 104, __pyx_L1_error) - __pyx_ptype_5pysam_9libctabix_GZIteratorHead = __Pyx_ImportType("pysam.libctabix", "GZIteratorHead", sizeof(struct __pyx_obj_5pysam_9libctabix_GZIteratorHead), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_GZIteratorHead)) __PYX_ERR(4, 113, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libctabix_GZIteratorHead = (struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorHead*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_GZIteratorHead->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_GZIteratorHead)) __PYX_ERR(4, 113, __pyx_L1_error) - __pyx_ptype_5pysam_9libctabix_GZIteratorParsed = __Pyx_ImportType("pysam.libctabix", "GZIteratorParsed", sizeof(struct __pyx_obj_5pysam_9libctabix_GZIteratorParsed), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_GZIteratorParsed)) __PYX_ERR(4, 117, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libctabix_GZIteratorParsed = (struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorParsed*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_GZIteratorParsed->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_GZIteratorParsed)) __PYX_ERR(4, 117, __pyx_L1_error) - __pyx_ptype_5pysam_9libctabix_Tabixfile = __Pyx_ImportType("pysam.libctabix", "Tabixfile", sizeof(struct __pyx_obj_5pysam_9libctabix_Tabixfile), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_Tabixfile)) __PYX_ERR(4, 122, __pyx_L1_error) - __pyx_vtabptr_5pysam_9libctabix_Tabixfile = (struct __pyx_vtabstruct_5pysam_9libctabix_Tabixfile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_Tabixfile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_Tabixfile)) __PYX_ERR(4, 122, __pyx_L1_error) - __pyx_ptype_5pysam_16libctabixproxies_GTFProxy = __Pyx_ImportType("pysam.libctabixproxies", "GTFProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_GTFProxy)) __PYX_ERR(5, 28, __pyx_L1_error) - __pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_GTFProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy)) __PYX_ERR(5, 28, __pyx_L1_error) - __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy = __Pyx_ImportType("pysam.libctabixproxies", "NamedTupleProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy)) __PYX_ERR(5, 38, __pyx_L1_error) - __pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy)) __PYX_ERR(5, 38, __pyx_L1_error) - __pyx_ptype_5pysam_16libctabixproxies_BedProxy = __Pyx_ImportType("pysam.libctabixproxies", "BedProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_BedProxy)) __PYX_ERR(5, 41, __pyx_L1_error) - __pyx_vtabptr_5pysam_16libctabixproxies_BedProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_BedProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_BedProxy)) __PYX_ERR(5, 41, __pyx_L1_error) - __pyx_ptype_5pysam_16libctabixproxies_VCFProxy = __Pyx_ImportType("pysam.libctabixproxies", "VCFProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_VCFProxy)) __PYX_ERR(5, 53, __pyx_L1_error) - __pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_VCFProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_VCFProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy)) __PYX_ERR(5, 53, __pyx_L1_error) + __pyx_ptype_5pysam_9libctabix_asGFF3 = __Pyx_ImportType("pysam.libctabix", "asGFF3", sizeof(struct __pyx_obj_5pysam_9libctabix_asGFF3), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_asGFF3)) __PYX_ERR(4, 84, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libctabix_asGFF3 = (struct __pyx_vtabstruct_5pysam_9libctabix_asGFF3*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_asGFF3->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_asGFF3)) __PYX_ERR(4, 84, __pyx_L1_error) + __pyx_ptype_5pysam_9libctabix_asBed = __Pyx_ImportType("pysam.libctabix", "asBed", sizeof(struct __pyx_obj_5pysam_9libctabix_asBed), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_asBed)) __PYX_ERR(4, 88, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libctabix_asBed = (struct __pyx_vtabstruct_5pysam_9libctabix_asBed*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_asBed->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_asBed)) __PYX_ERR(4, 88, __pyx_L1_error) + __pyx_ptype_5pysam_9libctabix_asVCF = __Pyx_ImportType("pysam.libctabix", "asVCF", sizeof(struct __pyx_obj_5pysam_9libctabix_asVCF), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_asVCF)) __PYX_ERR(4, 92, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libctabix_asVCF = (struct __pyx_vtabstruct_5pysam_9libctabix_asVCF*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_asVCF->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_asVCF)) __PYX_ERR(4, 92, __pyx_L1_error) + __pyx_ptype_5pysam_9libctabix_TabixIterator = __Pyx_ImportType("pysam.libctabix", "TabixIterator", sizeof(struct __pyx_obj_5pysam_9libctabix_TabixIterator), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_TabixIterator)) __PYX_ERR(4, 96, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libctabix_TabixIterator = (struct __pyx_vtabstruct_5pysam_9libctabix_TabixIterator*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_TabixIterator->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_TabixIterator)) __PYX_ERR(4, 96, __pyx_L1_error) + __pyx_ptype_5pysam_9libctabix_TabixIteratorParsed = __Pyx_ImportType("pysam.libctabix", "TabixIteratorParsed", sizeof(struct __pyx_obj_5pysam_9libctabix_TabixIteratorParsed), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_TabixIteratorParsed)) __PYX_ERR(4, 104, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libctabix_TabixIteratorParsed = (struct __pyx_vtabstruct_5pysam_9libctabix_TabixIteratorParsed*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_TabixIteratorParsed->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_TabixIteratorParsed)) __PYX_ERR(4, 104, __pyx_L1_error) + __pyx_ptype_5pysam_9libctabix_GZIterator = __Pyx_ImportType("pysam.libctabix", "GZIterator", sizeof(struct __pyx_obj_5pysam_9libctabix_GZIterator), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_GZIterator)) __PYX_ERR(4, 108, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libctabix_GZIterator = (struct __pyx_vtabstruct_5pysam_9libctabix_GZIterator*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_GZIterator->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_GZIterator)) __PYX_ERR(4, 108, __pyx_L1_error) + __pyx_ptype_5pysam_9libctabix_GZIteratorHead = __Pyx_ImportType("pysam.libctabix", "GZIteratorHead", sizeof(struct __pyx_obj_5pysam_9libctabix_GZIteratorHead), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_GZIteratorHead)) __PYX_ERR(4, 117, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libctabix_GZIteratorHead = (struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorHead*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_GZIteratorHead->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_GZIteratorHead)) __PYX_ERR(4, 117, __pyx_L1_error) + __pyx_ptype_5pysam_9libctabix_GZIteratorParsed = __Pyx_ImportType("pysam.libctabix", "GZIteratorParsed", sizeof(struct __pyx_obj_5pysam_9libctabix_GZIteratorParsed), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_GZIteratorParsed)) __PYX_ERR(4, 121, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libctabix_GZIteratorParsed = (struct __pyx_vtabstruct_5pysam_9libctabix_GZIteratorParsed*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_GZIteratorParsed->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_GZIteratorParsed)) __PYX_ERR(4, 121, __pyx_L1_error) + __pyx_ptype_5pysam_9libctabix_Tabixfile = __Pyx_ImportType("pysam.libctabix", "Tabixfile", sizeof(struct __pyx_obj_5pysam_9libctabix_Tabixfile), 1); if (unlikely(!__pyx_ptype_5pysam_9libctabix_Tabixfile)) __PYX_ERR(4, 126, __pyx_L1_error) + __pyx_vtabptr_5pysam_9libctabix_Tabixfile = (struct __pyx_vtabstruct_5pysam_9libctabix_Tabixfile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libctabix_Tabixfile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9libctabix_Tabixfile)) __PYX_ERR(4, 126, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy = __Pyx_ImportType("pysam.libctabixproxies", "NamedTupleProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_NamedTupleProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy)) __PYX_ERR(5, 29, __pyx_L1_error) + __pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_NamedTupleProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_NamedTupleProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_NamedTupleProxy)) __PYX_ERR(5, 29, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_GTFProxy = __Pyx_ImportType("pysam.libctabixproxies", "GTFProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_GTFProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_GTFProxy)) __PYX_ERR(5, 33, __pyx_L1_error) + __pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_GTFProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_GTFProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_GTFProxy)) __PYX_ERR(5, 33, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_GFF3Proxy = __Pyx_ImportType("pysam.libctabixproxies", "GFF3Proxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_GFF3Proxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_GFF3Proxy)) __PYX_ERR(5, 39, __pyx_L1_error) + __pyx_vtabptr_5pysam_16libctabixproxies_GFF3Proxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_GFF3Proxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_GFF3Proxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_GFF3Proxy)) __PYX_ERR(5, 39, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_BedProxy = __Pyx_ImportType("pysam.libctabixproxies", "BedProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_BedProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_BedProxy)) __PYX_ERR(5, 43, __pyx_L1_error) + __pyx_vtabptr_5pysam_16libctabixproxies_BedProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_BedProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_BedProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_BedProxy)) __PYX_ERR(5, 43, __pyx_L1_error) + __pyx_ptype_5pysam_16libctabixproxies_VCFProxy = __Pyx_ImportType("pysam.libctabixproxies", "VCFProxy", sizeof(struct __pyx_obj_5pysam_16libctabixproxies_VCFProxy), 1); if (unlikely(!__pyx_ptype_5pysam_16libctabixproxies_VCFProxy)) __PYX_ERR(5, 55, __pyx_L1_error) + __pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy = (struct __pyx_vtabstruct_5pysam_16libctabixproxies_VCFProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_16libctabixproxies_VCFProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_16libctabixproxies_VCFProxy)) __PYX_ERR(5, 55, __pyx_L1_error) __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 sizeof(PyTypeObject), diff --git a/pysam/namedtuple.py b/pysam/namedtuple.py deleted file mode 100644 index a60fb1afd..000000000 --- a/pysam/namedtuple.py +++ /dev/null @@ -1,117 +0,0 @@ -from operator import itemgetter as _itemgetter -from keyword import iskeyword as _iskeyword -import sys as _sys - -def namedtuple(typename, field_names, verbose=False, rename=False): - """Returns a new subclass of tuple with named fields. - - >>> Point = namedtuple('Point', 'x y') - >>> Point.__doc__ # docstring for the new class - 'Point(x, y)' - >>> p = Point(11, y=22) # instantiate with positional args or keywords - >>> p[0] + p[1] # indexable like a plain tuple - 33 - >>> x, y = p # unpack like a regular tuple - >>> x, y - (11, 22) - >>> p.x + p.y # fields also accessable by name - 33 - >>> d = p._asdict() # convert to a dictionary - >>> d['x'] - 11 - >>> Point(**d) # convert from a dictionary - Point(x=11, y=22) - >>> p._replace(x=100) # _replace() is like str.replace() but targets named fields - Point(x=100, y=22) - - """ - - # Parse and validate the field names. Validation serves two purposes, - # generating informative error messages and preventing template injection attacks. - if isinstance(field_names, basestring): - field_names = field_names.replace(',', ' ').split() # names separated by whitespace and/or commas - field_names = tuple(map(str, field_names)) - if rename: - names = list(field_names) - seen = set() - for i, name in enumerate(names): - if (not min(c.isalnum() or c=='_' for c in name) or _iskeyword(name) - or not name or name[0].isdigit() or name.startswith('_') - or name in seen): - names[i] = '_%d' % i - seen.add(name) - field_names = tuple(names) - for name in (typename,) + field_names: - if not min(c.isalnum() or c=='_' for c in name): - raise ValueError('Type names and field names can only contain alphanumeric characters and underscores: %r' % name) - if _iskeyword(name): - raise ValueError('Type names and field names cannot be a keyword: %r' % name) - if name[0].isdigit(): - raise ValueError('Type names and field names cannot start with a number: %r' % name) - seen_names = set() - for name in field_names: - if name.startswith('_') and not rename: - raise ValueError('Field names cannot start with an underscore: %r' % name) - if name in seen_names: - raise ValueError('Encountered duplicate field name: %r' % name) - seen_names.add(name) - - # Create and fill-in the class template - numfields = len(field_names) - argtxt = repr(field_names).replace("'", "")[1:-1] # tuple repr without parens or quotes - reprtxt = ', '.join('%s=%%r' % name for name in field_names) - template = '''class %(typename)s(tuple): - '%(typename)s(%(argtxt)s)' \n - __slots__ = () \n - _fields = %(field_names)r \n - def __new__(_cls, %(argtxt)s): - return _tuple.__new__(_cls, (%(argtxt)s)) \n - @classmethod - def _make(cls, iterable, new=tuple.__new__, len=len): - 'Make a new %(typename)s object from a sequence or iterable' - result = new(cls, iterable) - if len(result) != %(numfields)d: - raise TypeError('Expected %(numfields)d arguments, got %%d' %% len(result)) - return result \n - def __repr__(self): - return '%(typename)s(%(reprtxt)s)' %% self \n - def _asdict(self): - 'Return a new dict which maps field names to their values' - return dict(zip(self._fields, self)) \n - def _replace(_self, **kwds): - 'Return a new %(typename)s object replacing specified fields with new values' - result = _self._make(map(kwds.pop, %(field_names)r, _self)) - if kwds: - raise ValueError('Got unexpected field names: %%r' %% kwds.keys()) - return result \n - def __getnewargs__(self): - return tuple(self) \n\n''' % locals() - for i, name in enumerate(field_names): - template += ' %s = _property(_itemgetter(%d))\n' % (name, i) - if verbose: - print template - - # Execute the template string in a temporary namespace - namespace = dict(_itemgetter=_itemgetter, __name__='namedtuple_%s' % typename, - _property=property, _tuple=tuple) - try: - exec template in namespace - except SyntaxError, e: - raise SyntaxError(e.message + ':\n' + template) - result = namespace[typename] - - # For pickling to work, the __module__ variable needs to be set to the frame - # where the named tuple is created. Bypass this step in enviroments where - # sys._getframe is not defined (Jython for example) or sys._getframe is not - # defined for arguments greater than 0 (IronPython). - try: - result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__') - except (AttributeError, ValueError): - pass - - return result - - - - - diff --git a/pysam/pysam_util.c b/pysam/pysam_util.c index 94717c846..349af44d8 100644 --- a/pysam/pysam_util.c +++ b/pysam/pysam_util.c @@ -2,70 +2,35 @@ #include #include #include -#include "bam.h" -#include "bam_endian.h" +#include +#include + #include "htslib/khash.h" #include "htslib/ksort.h" #include "htslib/knetfile.h" -#include "pysam_util.h" - - -FILE * pysam_stderr = NULL; -FILE * pysam_stdout = NULL; -const char * pysam_stdout_fn = NULL; -int PYSAM_STDOUT_FILENO = STDOUT_FILENO; - - -FILE * pysam_set_stderr(int fd) -{ - if (pysam_stderr != NULL) - fclose(pysam_stderr); - pysam_stderr = fdopen(fd, "w"); - return pysam_stderr; -} - -void pysam_unset_stderr(void) -{ - if (pysam_stderr != NULL) - fclose(pysam_stderr); - pysam_stderr = fopen("/dev/null", "w"); -} -FILE * pysam_set_stdout(int fd) +#if !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700) +/* + * A rudimentary emulation of getline() for systems that dont support it + * natively. Since this is used for PPD file reading, it assumes (possibly + * falsely) that BUFSIZ is big enough. + */ +ssize_t +getline(char **line, size_t *linelen, FILE *fp) { - if (pysam_stdout != NULL) - fclose(pysam_stdout); - pysam_stdout = fdopen(fd, "w"); - if (pysam_stdout == NULL) + if (*linelen == 0) { - fprintf(pysam_stderr, "could not set stdout to fd %i", fd); + *linelen = BUFSIZ; + *line = malloc(*linelen); } - PYSAM_STDOUT_FILENO = fd; - return pysam_stdout; -} -void pysam_set_stdout_fn(const char *fn) -{ - pysam_stdout_fn = fn; -} + memset(*line, 0, *linelen); + fgets(*line, *linelen, fp); -void pysam_unset_stdout(void) -{ - if (pysam_stdout != NULL) - fclose(pysam_stdout); - pysam_stdout = fopen("/dev/null", "w"); - PYSAM_STDOUT_FILENO = STDOUT_FILENO; -} + return (strlen(*line)); -void set_optind(int val) -{ - // setting this in cython via - // "from posix.unistd cimport optind" - // did not work. - // - // setting to 0 forces a complete re-initialization - optind = val; } +#endif diff --git a/pysam/pysam_util.h b/pysam/pysam_util.h index a30808f6c..789e9d0d3 100644 --- a/pysam/pysam_util.h +++ b/pysam/pysam_util.h @@ -1,37 +1,5 @@ #ifndef PYSAM_UTIL_H #define PYSAM_UTIL_H -/*! set pysam standard error to point to file descriptor - - Setting the stderr will close the previous stderr. - */ -FILE * pysam_set_stderr(int fd); - -/*! set pysam standard output to point to file descriptor - - Setting the stderr will close the previous stdout. - */ -FILE * pysam_set_stdout(int fd); - -/*! set pysam standard output to point to filename - - */ -void pysam_set_stdout_fn(const char * fn); - -/*! set pysam standard error to /dev/null. - - Unsetting the stderr will close the previous stderr. - */ -void pysam_unset_stderr(void); - -/*! set pysam standard error to /dev/null. - - Unsetting the stderr will close the previous stderr. - */ -void pysam_unset_stdout(void); - -int pysam_dispatch(int argc, char *argv[]); - -void set_optind(int); #endif diff --git a/pysam/samfile_util.c b/pysam/samfile_util.c deleted file mode 100644 index f5724ae0c..000000000 --- a/pysam/samfile_util.c +++ /dev/null @@ -1,188 +0,0 @@ -#include "samfile_util.h" -#include "htslib/sam.h" - -#include "kprobaln.h" - -// taken from bam_md.c -// replace bam1_{qual,seq,cigar} with bam_get_{qual,seq,cigar} -// bam1_seqi -> bam_seqi -// bam_nt16_table -> seq_nt16_table - -#include -#include -#include - -char bam_nt16_nt4_table[] = { 4, 0, 1, 4, 2, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4 }; - -int bam_cap_mapQ(bam1_t *b, char *ref, int thres) -{ - uint8_t *seq = bam_get_seq(b), *qual = bam_get_qual(b); - uint32_t *cigar = bam_get_cigar(b); - bam1_core_t *c = &b->core; - int i, x, y, mm, q, len, clip_l, clip_q; - double t; - if (thres < 0) thres = 40; // set the default - mm = q = len = clip_l = clip_q = 0; - for (i = y = 0, x = c->pos; i < c->n_cigar; ++i) { - int j, l = cigar[i]>>4, op = cigar[i]&0xf; - if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { - for (j = 0; j < l; ++j) { - int z = y + j; - int c1 = bam_seqi(seq, z), c2 = seq_nt16_table[(int)ref[x+j]]; - if (ref[x+j] == 0) break; // out of boundary - if (c2 != 15 && c1 != 15 && qual[z] >= 13) { // not ambiguous - ++len; - if (c1 && c1 != c2 && qual[z] >= 13) { // mismatch - ++mm; - q += qual[z] > 33? 33 : qual[z]; - } - } - } - if (j < l) break; - x += l; y += l; len += l; - } else if (op == BAM_CDEL) { - for (j = 0; j < l; ++j) - if (ref[x+j] == 0) break; - if (j < l) break; - x += l; - } else if (op == BAM_CSOFT_CLIP) { - for (j = 0; j < l; ++j) clip_q += qual[y+j]; - clip_l += l; - y += l; - } else if (op == BAM_CHARD_CLIP) { - clip_q += 13 * l; - clip_l += l; - } else if (op == BAM_CINS) y += l; - else if (op == BAM_CREF_SKIP) x += l; - } - for (i = 0, t = 1; i < mm; ++i) - t *= (double)len / (i+1); - t = q - 4.343 * log(t) + clip_q / 5.; - if (t > thres) return -1; - if (t < 0) t = 0; - t = sqrt((thres - t) / thres) * thres; -// fprintf(stderr, "%s %lf %d\n", bam1_qname(b), t, q); - return (int)(t + .499); -} - - -int bam_prob_realn_core(bam1_t *b, const char *ref, int flag) -{ - int k, i, bw, x, y, yb, ye, xb, xe, apply_baq = flag&1, extend_baq = flag>>1&1, redo_baq = flag&4; - uint32_t *cigar = bam_get_cigar(b); - bam1_core_t *c = &b->core; - kpa_par_t conf = kpa_par_def; - uint8_t *bq = 0, *zq = 0, *qual = bam_get_qual(b); - if ((c->flag & BAM_FUNMAP) || b->core.l_qseq == 0) return -1; // do nothing - // test if BQ or ZQ is present - if ((bq = bam_aux_get(b, "BQ")) != 0) ++bq; - if ((zq = bam_aux_get(b, "ZQ")) != 0 && *zq == 'Z') ++zq; - if (bq && redo_baq) - { - bam_aux_del(b, bq-1); - bq = 0; - } - if (bq && zq) { // remove the ZQ tag - bam_aux_del(b, zq-1); - zq = 0; - } - if (bq || zq) { - if ((apply_baq && zq) || (!apply_baq && bq)) return -3; // in both cases, do nothing - if (bq && apply_baq) { // then convert BQ to ZQ - for (i = 0; i < c->l_qseq; ++i) - qual[i] = qual[i] + 64 < bq[i]? 0 : qual[i] - ((int)bq[i] - 64); - *(bq - 3) = 'Z'; - } else if (zq && !apply_baq) { // then convert ZQ to BQ - for (i = 0; i < c->l_qseq; ++i) - qual[i] += (int)zq[i] - 64; - *(zq - 3) = 'B'; - } - return 0; - } - // find the start and end of the alignment - x = c->pos, y = 0, yb = ye = xb = xe = -1; - for (k = 0; k < c->n_cigar; ++k) { - int op, l; - op = cigar[k]&0xf; l = cigar[k]>>4; - if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { - if (yb < 0) yb = y; - if (xb < 0) xb = x; - ye = y + l; xe = x + l; - x += l; y += l; - } else if (op == BAM_CSOFT_CLIP || op == BAM_CINS) y += l; - else if (op == BAM_CDEL) x += l; - else if (op == BAM_CREF_SKIP) return -1; // do nothing if there is a reference skip - } - // set bandwidth and the start and the end - bw = 7; - if (abs((xe - xb) - (ye - yb)) > bw) - bw = abs((xe - xb) - (ye - yb)) + 3; - conf.bw = bw; - xb -= yb + bw/2; if (xb < 0) xb = 0; - xe += c->l_qseq - ye + bw/2; - if (xe - xb - c->l_qseq > bw) - xb += (xe - xb - c->l_qseq - bw) / 2, xe -= (xe - xb - c->l_qseq - bw) / 2; - { // glocal - uint8_t *s, *r, *q, *seq = bam_get_seq(b), *bq; - int *state; - bq = calloc(c->l_qseq + 1, 1); - memcpy(bq, qual, c->l_qseq); - s = calloc(c->l_qseq, 1); - for (i = 0; i < c->l_qseq; ++i) s[i] = bam_nt16_nt4_table[bam_seqi(seq, i)]; - r = calloc(xe - xb, 1); - for (i = xb; i < xe; ++i) { - if (ref[i] == 0) { xe = i; break; } - r[i-xb] = bam_nt16_nt4_table[seq_nt16_table[(int)ref[i]]]; - } - state = calloc(c->l_qseq, sizeof(int)); - q = calloc(c->l_qseq, 1); - kpa_glocal(r, xe-xb, s, c->l_qseq, qual, &conf, state, q); - if (!extend_baq) { // in this block, bq[] is capped by base quality qual[] - for (k = 0, x = c->pos, y = 0; k < c->n_cigar; ++k) { - int op = cigar[k]&0xf, l = cigar[k]>>4; - if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { - for (i = y; i < y + l; ++i) { - if ((state[i]&3) != 0 || state[i]>>2 != x - xb + (i - y)) bq[i] = 0; - else bq[i] = bq[i] < q[i]? bq[i] : q[i]; - } - x += l; y += l; - } else if (op == BAM_CSOFT_CLIP || op == BAM_CINS) y += l; - else if (op == BAM_CDEL) x += l; - } - for (i = 0; i < c->l_qseq; ++i) bq[i] = qual[i] - bq[i] + 64; // finalize BQ - } else { // in this block, bq[] is BAQ that can be larger than qual[] (different from the above!) - uint8_t *left, *rght; - left = calloc(c->l_qseq, 1); rght = calloc(c->l_qseq, 1); - for (k = 0, x = c->pos, y = 0; k < c->n_cigar; ++k) { - int op = cigar[k]&0xf, l = cigar[k]>>4; - if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { - for (i = y; i < y + l; ++i) - bq[i] = ((state[i]&3) != 0 || state[i]>>2 != x - xb + (i - y))? 0 : q[i]; - for (left[y] = bq[y], i = y + 1; i < y + l; ++i) - left[i] = bq[i] > left[i-1]? bq[i] : left[i-1]; - for (rght[y+l-1] = bq[y+l-1], i = y + l - 2; i >= y; --i) - rght[i] = bq[i] > rght[i+1]? bq[i] : rght[i+1]; - for (i = y; i < y + l; ++i) - bq[i] = left[i] < rght[i]? left[i] : rght[i]; - x += l; y += l; - } else if (op == BAM_CSOFT_CLIP || op == BAM_CINS) y += l; - else if (op == BAM_CDEL) x += l; - } - for (i = 0; i < c->l_qseq; ++i) bq[i] = 64 + (qual[i] <= bq[i]? 0 : qual[i] - bq[i]); // finalize BQ - free(left); free(rght); - } - if (apply_baq) { - for (i = 0; i < c->l_qseq; ++i) qual[i] -= bq[i] - 64; // modify qual - bam_aux_append(b, "ZQ", 'Z', c->l_qseq + 1, bq); - } else bam_aux_append(b, "BQ", 'Z', c->l_qseq + 1, bq); - free(bq); free(s); free(r); free(q); free(state); - } - return 0; -} - -int bam_prob_realn(bam1_t *b, const char *ref) -{ - return bam_prob_realn_core(b, ref, 1); -} - - diff --git a/pysam/samfile_util.h b/pysam/samfile_util.h deleted file mode 100644 index dd3e27a62..000000000 --- a/pysam/samfile_util.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SAMFILE_UTIL_H -#define SAMFILE_UTIL_H - -#include "htslib/sam.h" - -int bam_cap_mapQ(bam1_t *b, char *ref, int thres); -int bam_prob_realn(bam1_t *b, const char *ref); - -#endif - diff --git a/pysam/tabix_util.c b/pysam/tabix_util.c deleted file mode 100644 index bff140e6b..000000000 --- a/pysam/tabix_util.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -#if !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700) -/* - * A rudimentary emulation of getline() for systems that dont support it - * natively. Since this is used for PPD file reading, it assumes (possibly - * falsely) that BUFSIZ is big enough. - */ -ssize_t -getline(char **line, size_t *linelen, FILE *fp) -{ - if (*linelen == 0) - { - *linelen = BUFSIZ; - *line = malloc(*linelen); - } - - memset(*line, 0, *linelen); - fgets(*line, *linelen, fp); - - return (strlen(*line)); - -} -#endif - diff --git a/pysam/tabix_util.h b/pysam/tabix_util.h deleted file mode 100644 index 65412ca94..000000000 --- a/pysam/tabix_util.h +++ /dev/null @@ -1,12 +0,0 @@ -/* See issue 122 - On some MACOSX systems getline is not defined. - */ -#if !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700) -#include "unistd.h" -ssize_t getline(char **line, size_t *linelen, FILE *fp); -#endif - - - - - diff --git a/pysam/utils.py b/pysam/utils.py index 5c045df1a..528c411c8 100644 --- a/pysam/utils.py +++ b/pysam/utils.py @@ -41,7 +41,7 @@ def __init__(self, collection, dispatch, parsers): self.dispatch = dispatch self.parsers = parsers self.stderr = [] - + def __call__(self, *args, **kwargs): '''execute a samtools command. @@ -70,7 +70,7 @@ def __call__(self, *args, **kwargs): "%s returned with error %i: " "stdout=%s, stderr=%s" % (self.collection, - retval, + retval, stdout, stderr)) @@ -92,7 +92,13 @@ def get_messages(self): def usage(self): '''return the samtools usage information for this command''' - retval, stderr, stdout = csamtools._samtools_dispatch( - self.dispatch) - return stderr - + retval, stderr, stdout = _pysam_dispatch( + self.collection, + self.dispatch, + is_usage=True, + catch_stdout=True) + # some tools write usage to stderr, such as mpileup + if stderr: + return stderr + else: + return stdout diff --git a/pysam/version.py b/pysam/version.py index facb3bbcb..8a68bcc67 100644 --- a/pysam/version.py +++ b/pysam/version.py @@ -1,9 +1,10 @@ # pysam versioning information +__version__ = "0.14.1" -__version__ = "0.10.0" +# TODO: upgrade number +__samtools_version__ = "1.7" -__samtools_version__ = "1.3.1" +# TODO: upgrade code and number +__bcftools_version__ = "1.6" -__bcftools_version__ = "1.3.1" - -__htslib_version__ = "1.3.2" +__htslib_version__ = "1.7" diff --git a/run_tests_travis.sh b/run_tests_travis.sh index a229ff5cd..b2659bce1 100755 --- a/run_tests_travis.sh +++ b/run_tests_travis.sh @@ -1,5 +1,16 @@ #!/usr/bin/env bash +# test script for pysam. +# The script performs the following tasks: +# 1. Setup a conda environment and install dependencies via conda +# 2. Build pysam via the conda recipe +# 3. Build pysam via setup.py from repository +# 4. Run tests on the setup.py version +# 5. Additional build tests +# 5.1 pip install with cython +# 5.2 pip install without cython +# 5.3 pip install without cython and without configure options + pushd . WORKDIR=`pwd` @@ -15,22 +26,24 @@ bash Miniconda3.sh -b # Create a new conda environment with the target python version ~/miniconda3/bin/conda install conda-build -y -~/miniconda3/bin/conda create -q -y --name testenv python=$CONDA_PY cython numpy nose psutil pip +~/miniconda3/bin/conda create -q -y --name testenv python=$CONDA_PY cython numpy pytest psutil pip # activate testenv environment source ~/miniconda3/bin/activate testenv -conda config --add channels conda-forge -conda config --add channels defaults conda config --add channels r +conda config --add channels defaults +conda config --add channels conda-forge conda config --add channels bioconda -conda install -y samtools bcftools htslib +# pin versions, so that tests do not fail when pysam/htslib out of step +# add htslib dependencies +conda install -y "samtools=1.7" "bcftools=1.6" "htslib=1.7" xz curl bzip2 # Need to make C compiler and linker use the anaconda includes and libraries: export PREFIX=~/miniconda3/ export CFLAGS="-I${PREFIX}/include -L${PREFIX}/lib" -export HTSLIB_CONFIGURE_OPTIONS="--disable-libcurl" +export HTSLIB_CONFIGURE_OPTIONS="--disable-libcurl --disable-lzma" samtools --version htslib --version @@ -39,36 +52,29 @@ bcftools --version # Try building conda recipe first ~/miniconda3/bin/conda-build ci/conda-recipe/ --python=$CONDA_PY -# install code from the repository +# install code from the repository via setup.py +echo "installing via setup.py from repository" python setup.py install -# find build/ - -# change into tests directory. Otherwise, -# 'import pysam' will import the repository, -# not the installed version. This causes -# problems in the compilation test. -cd tests - # create auxilliary data echo echo 'building test data' echo -make -C pysam_data -make -C cbcf_data +make -C tests/pysam_data +make -C tests/cbcf_data + +# echo any limits that are in place +ulimit -a -# run nosetests -# -s: do not capture stdout, conflicts with pysam.dispatch -# -v: verbose output -nosetests -s -v +# run tests +pytest if [ $? != 0 ]; then exit 1 fi -# build source tar-ball. Make sure to build so that .pyx files -# are cythonized. -cd .. +# build source tar-ball. Make sure to run 'build' target so that .pyx +# files are cythonized. python setup.py build sdist if [ $? != 0 ]; then @@ -80,6 +86,8 @@ echo "checking for presence of config.h files in tar-ball" tar -tvzf dist/pysam-*.tar.gz | grep "config.h$" if [ $? != 1 ]; then + echo "ERROR: found config.h in tar-ball" + tar -tvzf dist/pysam-*.tar.gz | grep "config.h%" exit 1 fi diff --git a/samtools/LICENSE b/samtools/LICENSE new file mode 100644 index 000000000..aeaae3cfc --- /dev/null +++ b/samtools/LICENSE @@ -0,0 +1,33 @@ +The MIT/Expat License + +Copyright (C) 2008-2014 Genome Research Ltd. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + + +[The use of a range of years within a copyright notice in this distribution +should be interpreted as being equivalent to a list of years including the +first and last year specified and all consecutive years between them. + +For example, a copyright notice that reads "Copyright (C) 2005, 2007-2009, +2011-2012" should be interpreted as being identical to a notice that reads +"Copyright (C) 2005, 2007, 2008, 2009, 2011, 2012" and a copyright notice +that reads "Copyright (C) 2005-2012" should be interpreted as being identical +to a notice that reads "Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, +2011, 2012".] diff --git a/samtools/README b/samtools/README new file mode 100644 index 000000000..7088f7925 --- /dev/null +++ b/samtools/README @@ -0,0 +1,54 @@ +Samtools implements various utilities for post-processing alignments in the +SAM, BAM, and CRAM formats, including indexing, variant calling (in conjunction +with bcftools), and a simple alignment viewer. + + +Building samtools +================= + +The typical simple case of building Samtools using the HTSlib bundled within +this Samtools release tarball is done as follows: + + cd .../samtools-1.7 # Within the unpacked release directory + ./configure + make + +You may wish to copy the resulting samtools executable into somewhere on your +$PATH, or run it where it is. + +Rather than running-in-place like that, the next simplest typical case is to +install samtools etc properly into a directory of your choosing. Building for +installation using the HTSlib bundled within this Samtools release tarball, +and building the various HTSlib utilities such as bgzip is done as follows: + + cd .../samtools-1.7 # Within the unpacked release directory + ./configure --prefix=/path/to/location + make all all-htslib + make install install-htslib + +You will likely wish to add /path/to/location/bin to your $PATH. + +See INSTALL for full building and installation instructions and details. + + +Using an optimised zlib library +=============================== + +Samtools has been minimally tested against both the Intel-optimised and +CloudFlare-optimised zlibs and shown to work. + +They can be downloaded from: + + https://github.com/jtkukunas/zlib # Intel + https://github.com/cloudflare/zlib # CloudFlare + +Neither Samtools nor HTSlib needs recompiling to use these optimised libraries, +but the LD_LIBRARY_PATH environment variable should be set to a directory +containing the libz.so.1 file. + +Benchmarks comparing the various zlibs are available at: + + http://www.htslib.org/benchmarks/zlib.html + +It is recommended that you perform your own rigorous tests for an entire +pipeline if you wish to switch to one of the optimised zlib implementations. diff --git a/samtools/bam.c.pysam.c b/samtools/bam.c.pysam.c index 188fe8c18..982bf4106 100644 --- a/samtools/bam.c.pysam.c +++ b/samtools/bam.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam.c -- BAM format. @@ -51,7 +51,7 @@ int bam_view1(const bam_header_t *header, const bam1_t *b) char *s = bam_format1(header, b); int ret = -1; if (!s) return -1; - if (fputs(s, pysam_stdout) & fputc('\n', pysam_stdout) != EOF) ret = 0; + if (fputs(s, samtools_stdout) & fputc('\n', samtools_stdout) != EOF) ret = 0; free(s); return ret; } diff --git a/samtools/bam.h b/samtools/bam.h index e928ce436..d4df9377a 100644 --- a/samtools/bam.h +++ b/samtools/bam.h @@ -38,7 +38,7 @@ DEALINGS IN THE SOFTWARE. */ @copyright Genome Research Ltd. */ -#define BAM_VERSION "1.3.1" +#define BAM_VERSION "1.7" #include #include diff --git a/samtools/bam2bcf.c b/samtools/bam2bcf.c index 85ce30788..a824d5ac0 100644 --- a/samtools/bam2bcf.c +++ b/samtools/bam2bcf.c @@ -29,11 +29,11 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include #include #include #include #include "bam2bcf.h" -#include "errmod.h" extern void ks_introsort_uint32_t(size_t n, uint32_t a[]); diff --git a/samtools/bam2bcf.c.pysam.c b/samtools/bam2bcf.c.pysam.c index 6938ec081..3bd623d66 100644 --- a/samtools/bam2bcf.c.pysam.c +++ b/samtools/bam2bcf.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam2bcf.c -- variant calling. @@ -31,11 +31,11 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include #include #include #include #include "bam2bcf.h" -#include "errmod.h" extern void ks_introsort_uint32_t(size_t n, uint32_t a[]); @@ -110,7 +110,7 @@ static int get_position(const bam_pileup1_t *p, int *len) if ( cig==BAM_CHARD_CLIP ) continue; if ( cig==BAM_CPAD ) continue; if ( cig==BAM_CREF_SKIP ) continue; - fprintf(pysam_stderr,"todo: cigar %d\n", cig); + fprintf(samtools_stderr,"todo: cigar %d\n", cig); assert(0); } *len = n_tot_bases; @@ -481,7 +481,7 @@ void calc_SegBias(const bcf_callret1_t *bcr, bcf_call_t *call) double sum = 0; const double log2 = log(2.0); - // fprintf(pysam_stderr,"M=%.1f p=%e q=%e f=%f dp=%d\n",M,p,q,f,avg_dp); + // fprintf(samtools_stderr,"M=%.1f p=%e q=%e f=%f dp=%d\n",M,p,q,f,avg_dp); int i; for (i=0; in; i++) { @@ -496,7 +496,7 @@ void calc_SegBias(const bcf_callret1_t *bcr, bcf_call_t *call) else tmp = log(2*f*(1-f)*exp(-q) + f*f*exp(-2*q) + (1-f)*(1-f)) + p; sum += tmp; - // fprintf(pysam_stderr,"oi=%d %e\n", oi,tmp); + // fprintf(samtools_stderr,"oi=%d %e\n", oi,tmp); } call->seg_bias = sum; } @@ -660,7 +660,7 @@ int bcf_call_combine(int n, const bcf_callret1_t *calls, bcf_callaux_t *bca, int } } -// if (ref_base < 0) fprintf(pysam_stderr, "%d,%d,%f,%d\n", call->n_alleles, x, sum_min, call->unseen); +// if (ref_base < 0) fprintf(samtools_stderr, "%d,%d,%f,%d\n", call->n_alleles, x, sum_min, call->unseen); call->shift = (int)(sum_min + .499); } // combine annotations diff --git a/samtools/bam2bcf.h b/samtools/bam2bcf.h index 22c67ccfa..54e5faaaa 100644 --- a/samtools/bam2bcf.h +++ b/samtools/bam2bcf.h @@ -27,8 +27,8 @@ DEALINGS IN THE SOFTWARE. */ #define BAM2BCF_H #include +#include #include -#include "errmod.h" /** * A simplified version of Mann-Whitney U-test is calculated diff --git a/samtools/bam2bcf_indel.c b/samtools/bam2bcf_indel.c index 5b353fc7c..9749d5bb7 100644 --- a/samtools/bam2bcf_indel.c +++ b/samtools/bam2bcf_indel.c @@ -28,9 +28,9 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include "htslib/hts.h" #include "htslib/sam.h" #include "bam2bcf.h" -#include "kprobaln.h" #include "htslib/khash.h" KHASH_SET_INIT_STR(rg) @@ -359,7 +359,7 @@ int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_calla bca->indelreg = 0; for (t = 0; t < n_types; ++t) { int l, ir; - kpa_par_t apf1 = { 1e-4, 1e-2, 10 }, apf2 = { 1e-6, 1e-3, 10 }; + probaln_par_t apf1 = { 1e-4, 1e-2, 10 }, apf2 = { 1e-6, 1e-3, 10 }; apf1.bw = apf2.bw = abs(types[t]) + 3; // compute indelreg if (types[t] == 0) ir = 0; @@ -412,14 +412,14 @@ int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_calla if (qq[l - qbeg] > 30) qq[l - qbeg] = 30; if (qq[l - qbeg] < 7) qq[l - qbeg] = 7; } - sc = kpa_glocal((uint8_t*)ref2 + tbeg - left, tend - tbeg + abs(types[t]), - (uint8_t*)query, qend - qbeg, qq, &apf1, 0, 0); + sc = probaln_glocal((uint8_t*)ref2 + tbeg - left, tend - tbeg + abs(types[t]), + (uint8_t*)query, qend - qbeg, qq, &apf1, 0, 0); l = (int)(100. * sc / (qend - qbeg) + .499); // used for adjusting indelQ below if (l > 255) l = 255; score1[K*n_types + t] = score2[K*n_types + t] = sc<<8 | l; if (sc > 5) { - sc = kpa_glocal((uint8_t*)ref2 + tbeg - left, tend - tbeg + abs(types[t]), - (uint8_t*)query, qend - qbeg, qq, &apf2, 0, 0); + sc = probaln_glocal((uint8_t*)ref2 + tbeg - left, tend - tbeg + abs(types[t]), + (uint8_t*)query, qend - qbeg, qq, &apf2, 0, 0); l = (int)(100. * sc / (qend - qbeg) + .499); if (l > 255) l = 255; score2[K*n_types + t] = sc<<8 | l; @@ -439,10 +439,13 @@ int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_calla } free(ref2); free(query); { // compute indelQ - int *sc, tmp, *sumq; - sc = alloca(n_types * sizeof(int)); - sumq = alloca(n_types * sizeof(int)); - memset(sumq, 0, sizeof(int) * n_types); + int sc_a[16], sumq_a[16]; + int tmp, *sc = sc_a, *sumq = sumq_a; + if (n_types > 16) { + sc = (int *)malloc(n_types * sizeof(int)); + sumq = (int *)malloc(n_types * sizeof(int)); + } + memset(sumq, 0, n_types * sizeof(int)); for (s = K = 0; s < n; ++s) { for (i = 0; i < n_plp[s]; ++i, ++K) { bam_pileup1_t *p = plp[s] + i; @@ -523,6 +526,9 @@ int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_calla //fprintf(stderr, "X pos=%d read=%d:%d name=%s call=%d type=%d seqQ=%d indelQ=%d\n", pos, s, i, bam1_qname(p->b), (p->aux>>16)&0x3f, bca->indel_types[(p->aux>>16)&0x3f], (p->aux>>8)&0xff, p->aux&0xff); } } + + if (sc != sc_a) free(sc); + if (sumq != sumq_a) free(sumq); } free(score1); free(score2); // free diff --git a/samtools/bam2bcf_indel.c.pysam.c b/samtools/bam2bcf_indel.c.pysam.c index 21cbb0392..8241d377e 100644 --- a/samtools/bam2bcf_indel.c.pysam.c +++ b/samtools/bam2bcf_indel.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam2bcf_indel.c -- indel caller. @@ -30,9 +30,9 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include "htslib/hts.h" #include "htslib/sam.h" #include "bam2bcf.h" -#include "kprobaln.h" #include "htslib/khash.h" KHASH_SET_INIT_STR(rg) @@ -227,7 +227,7 @@ int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_calla free(aux); // TODO revisit how/whether to control printing this warning if (hts_verbose >= 2) - fprintf(pysam_stderr, "[%s] excessive INDEL alleles at position %d. Skip the position.\n", __func__, pos + 1); + fprintf(samtools_stderr, "[%s] excessive INDEL alleles at position %d. Skip the position.\n", __func__, pos + 1); return -1; } types = (int*)calloc(n_types, sizeof(int)); @@ -300,7 +300,7 @@ int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_calla if ((double)(max2&0xffff) / ((max2&0xffff) + (max2>>16)) >= 0.7) max2_i = -1; if (max_i >= 0) r[max_i] = 15; if (max2_i >= 0) r[max2_i] = 15; - //for (i = 0; i < right - left; ++i) fputc("=ACMGRSVTWYHKDBN"[(int)r[i]], pysam_stderr); fputc('\n', pysam_stderr); + //for (i = 0; i < right - left; ++i) fputc("=ACMGRSVTWYHKDBN"[(int)r[i]], samtools_stderr); fputc('\n', samtools_stderr); } free(ref0); free(cns); } @@ -361,14 +361,14 @@ int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_calla bca->indelreg = 0; for (t = 0; t < n_types; ++t) { int l, ir; - kpa_par_t apf1 = { 1e-4, 1e-2, 10 }, apf2 = { 1e-6, 1e-3, 10 }; + probaln_par_t apf1 = { 1e-4, 1e-2, 10 }, apf2 = { 1e-6, 1e-3, 10 }; apf1.bw = apf2.bw = abs(types[t]) + 3; // compute indelreg if (types[t] == 0) ir = 0; else if (types[t] > 0) ir = est_indelreg(pos, ref, types[t], &inscns[t*max_ins]); else ir = est_indelreg(pos, ref, -types[t], 0); if (ir > bca->indelreg) bca->indelreg = ir; -// fprintf(pysam_stderr, "%d, %d, %d\n", pos, types[t], ir); +// fprintf(samtools_stderr, "%d, %d, %d\n", pos, types[t], ir); // realignment for (s = K = 0; s < n; ++s) { // write ref2 @@ -414,14 +414,14 @@ int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_calla if (qq[l - qbeg] > 30) qq[l - qbeg] = 30; if (qq[l - qbeg] < 7) qq[l - qbeg] = 7; } - sc = kpa_glocal((uint8_t*)ref2 + tbeg - left, tend - tbeg + abs(types[t]), - (uint8_t*)query, qend - qbeg, qq, &apf1, 0, 0); + sc = probaln_glocal((uint8_t*)ref2 + tbeg - left, tend - tbeg + abs(types[t]), + (uint8_t*)query, qend - qbeg, qq, &apf1, 0, 0); l = (int)(100. * sc / (qend - qbeg) + .499); // used for adjusting indelQ below if (l > 255) l = 255; score1[K*n_types + t] = score2[K*n_types + t] = sc<<8 | l; if (sc > 5) { - sc = kpa_glocal((uint8_t*)ref2 + tbeg - left, tend - tbeg + abs(types[t]), - (uint8_t*)query, qend - qbeg, qq, &apf2, 0, 0); + sc = probaln_glocal((uint8_t*)ref2 + tbeg - left, tend - tbeg + abs(types[t]), + (uint8_t*)query, qend - qbeg, qq, &apf2, 0, 0); l = (int)(100. * sc / (qend - qbeg) + .499); if (l > 255) l = 255; score2[K*n_types + t] = sc<<8 | l; @@ -430,21 +430,24 @@ int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_calla } /* for (l = 0; l < tend - tbeg + abs(types[t]); ++l) - fputc("ACGTN"[(int)ref2[tbeg-left+l]], pysam_stderr); - fputc('\n', pysam_stderr); - for (l = 0; l < qend - qbeg; ++l) fputc("ACGTN"[(int)query[l]], pysam_stderr); - fputc('\n', pysam_stderr); - fprintf(pysam_stderr, "pos=%d type=%d read=%d:%d name=%s qbeg=%d tbeg=%d score=%d\n", pos, types[t], s, i, bam1_qname(p->b), qbeg, tbeg, sc); + fputc("ACGTN"[(int)ref2[tbeg-left+l]], samtools_stderr); + fputc('\n', samtools_stderr); + for (l = 0; l < qend - qbeg; ++l) fputc("ACGTN"[(int)query[l]], samtools_stderr); + fputc('\n', samtools_stderr); + fprintf(samtools_stderr, "pos=%d type=%d read=%d:%d name=%s qbeg=%d tbeg=%d score=%d\n", pos, types[t], s, i, bam1_qname(p->b), qbeg, tbeg, sc); */ } } } free(ref2); free(query); { // compute indelQ - int *sc, tmp, *sumq; - sc = alloca(n_types * sizeof(int)); - sumq = alloca(n_types * sizeof(int)); - memset(sumq, 0, sizeof(int) * n_types); + int sc_a[16], sumq_a[16]; + int tmp, *sc = sc_a, *sumq = sumq_a; + if (n_types > 16) { + sc = (int *)malloc(n_types * sizeof(int)); + sumq = (int *)malloc(n_types * sizeof(int)); + } + memset(sumq, 0, n_types * sizeof(int)); for (s = K = 0; s < n; ++s) { for (i = 0; i < n_plp[s]; ++i, ++K) { bam_pileup1_t *p = plp[s] + i; @@ -490,7 +493,7 @@ int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_calla if (seqQ > 255) seqQ = 255; p->aux = (sc[0]&0x3f)<<16 | seqQ<<8 | indelQ; // use 22 bits in total sumq[sc[0]&0x3f] += indelQ < seqQ? indelQ : seqQ; -// fprintf(pysam_stderr, "pos=%d read=%d:%d name=%s call=%d indelQ=%d seqQ=%d\n", pos, s, i, bam1_qname(p->b), types[sc[0]&0x3f], indelQ, seqQ); +// fprintf(samtools_stderr, "pos=%d read=%d:%d name=%s call=%d indelQ=%d seqQ=%d\n", pos, s, i, bam1_qname(p->b), types[sc[0]&0x3f], indelQ, seqQ); } } // determine bca->indel_types[] and bca->inscns @@ -522,9 +525,12 @@ int bcf_call_gap_prep(int n, int *n_plp, bam_pileup1_t **plp, int pos, bcf_calla if (x == bca->indel_types[j]) break; p->aux = j<<16 | (j == 4? 0 : (p->aux&0xffff)); if ((p->aux>>16&0x3f) > 0) ++n_alt; - //fprintf(pysam_stderr, "X pos=%d read=%d:%d name=%s call=%d type=%d seqQ=%d indelQ=%d\n", pos, s, i, bam1_qname(p->b), (p->aux>>16)&0x3f, bca->indel_types[(p->aux>>16)&0x3f], (p->aux>>8)&0xff, p->aux&0xff); + //fprintf(samtools_stderr, "X pos=%d read=%d:%d name=%s call=%d type=%d seqQ=%d indelQ=%d\n", pos, s, i, bam1_qname(p->b), (p->aux>>16)&0x3f, bca->indel_types[(p->aux>>16)&0x3f], (p->aux>>8)&0xff, p->aux&0xff); } } + + if (sc != sc_a) free(sc); + if (sumq != sumq_a) free(sumq); } free(score1); free(score2); // free diff --git a/samtools/bam2depth.c b/samtools/bam2depth.c index 21220f15e..b732e8e60 100644 --- a/samtools/bam2depth.c +++ b/samtools/bam2depth.c @@ -80,13 +80,13 @@ static int usage() { fprintf(stderr, " -a -a (or -aa) output absolutely all positions, including unused ref. sequences\n"); fprintf(stderr, " -b list of positions or regions\n"); fprintf(stderr, " -f list of input BAM filenames, one per line [null]\n"); - fprintf(stderr, " -l read length threshold (ignore reads shorter than )\n"); + fprintf(stderr, " -l read length threshold (ignore reads shorter than ) [0]\n"); fprintf(stderr, " -d/-m maximum coverage depth [8000]\n"); // the htslib's default - fprintf(stderr, " -q base quality threshold\n"); - fprintf(stderr, " -Q mapping quality threshold\n"); + fprintf(stderr, " -q base quality threshold [0]\n"); + fprintf(stderr, " -Q mapping quality threshold [0]\n"); fprintf(stderr, " -r region\n"); - sam_global_opt_help(stderr, "-.--."); + sam_global_opt_help(stderr, "-.--.-"); fprintf(stderr, "\n"); fprintf(stderr, "The output is a simple tab-separated table with three columns: reference name,\n"); @@ -99,7 +99,7 @@ static int usage() { int main_depth(int argc, char *argv[]) { - int i, n, tid, beg, end, pos, *n_plp, baseQ = 0, mapQ = 0, min_len = 0; + int i, n, tid, reg_tid, beg, end, pos, *n_plp, baseQ = 0, mapQ = 0, min_len = 0; int all = 0, status = EXIT_SUCCESS, nfiles, max_depth = -1; const bam_pileup1_t **plp; char *reg = 0; // specified region @@ -112,7 +112,7 @@ int main_depth(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0, '-'), { NULL, 0, NULL, 0 } }; @@ -149,7 +149,7 @@ int main_depth(int argc, char *argv[]) else n = argc - optind; // the number of BAMs on the command line data = calloc(n, sizeof(aux_t*)); // data[i] for the i-th input - beg = 0; end = INT_MAX; // set the default region + reg_tid = 0; beg = 0; end = INT_MAX; // set the default region for (i = 0; i < n; ++i) { int rf; data[i] = calloc(1, sizeof(aux_t)); @@ -199,6 +199,7 @@ int main_depth(int argc, char *argv[]) if (reg) { beg = data[0]->iter->beg; // and to the parsed region coordinates end = data[0]->iter->end; + reg_tid = data[0]->iter->tid; } // the core multi-pileup loop @@ -210,12 +211,12 @@ int main_depth(int argc, char *argv[]) while ((ret=bam_mplp_auto(mplp, &tid, &pos, n_plp, plp)) > 0) { // come to the next covered position if (pos < beg || pos >= end) continue; // out of range; skip if (tid >= h->n_targets) continue; // diff number of @SQ lines per file? - if (bed && bed_overlap(bed, h->target_name[tid], pos, pos + 1) == 0) continue; // not in BED; skip if (all) { while (tid > last_tid) { - if (last_tid >= 0 && all > 1 && !reg) { - // Deal with remainder or entirety of last tid + if (last_tid >= 0 && !reg) { + // Deal with remainder or entirety of last tid. while (++last_pos < h->target_len[last_tid]) { + // Horribly inefficient, but the bed API is an obfuscated black box. if (bed && bed_overlap(bed, h->target_name[last_tid], last_pos, last_pos + 1) == 0) continue; fputs(h->target_name[last_tid], stdout); printf("\t%d", last_pos+1); @@ -226,6 +227,8 @@ int main_depth(int argc, char *argv[]) } last_tid++; last_pos = -1; + if (all < 2) + break; } // Deal with missing portion of current tid @@ -242,6 +245,7 @@ int main_depth(int argc, char *argv[]) last_tid = tid; last_pos = pos; } + if (bed && bed_overlap(bed, h->target_name[tid], pos, pos + 1) == 0) continue; fputs(h->target_name[tid], stdout); printf("\t%d", pos+1); // a customized printf() would be faster for (i = 0; i < n; ++i) { // base level filters have to go here int j, m = 0; @@ -260,7 +264,11 @@ int main_depth(int argc, char *argv[]) if (all) { // Handle terminating region - while (last_tid < h->n_targets) { + if (last_tid < 0 && reg && all > 1) { + last_tid = reg_tid; + last_pos = beg-1; + } + while (last_tid >= 0 && last_tid < h->n_targets) { while (++last_pos < h->target_len[last_tid]) { if (last_pos >= end) break; if (bed && bed_overlap(bed, h->target_name[last_tid], last_pos, last_pos + 1) == 0) diff --git a/samtools/bam2depth.c.pysam.c b/samtools/bam2depth.c.pysam.c index 9d9dc406c..ebe60d5d5 100644 --- a/samtools/bam2depth.c.pysam.c +++ b/samtools/bam2depth.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam2depth.c -- depth subcommand. @@ -75,33 +75,33 @@ static int read_bam(void *data, bam1_t *b) // read level filters better go here int read_file_list(const char *file_list,int *n,char **argv[]); static int usage() { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Usage: samtools depth [options] in1.bam [in2.bam [...]]\n"); - fprintf(pysam_stderr, "Options:\n"); - fprintf(pysam_stderr, " -a output all positions (including zero depth)\n"); - fprintf(pysam_stderr, " -a -a (or -aa) output absolutely all positions, including unused ref. sequences\n"); - fprintf(pysam_stderr, " -b list of positions or regions\n"); - fprintf(pysam_stderr, " -f list of input BAM filenames, one per line [null]\n"); - fprintf(pysam_stderr, " -l read length threshold (ignore reads shorter than )\n"); - fprintf(pysam_stderr, " -d/-m maximum coverage depth [8000]\n"); // the htslib's default - fprintf(pysam_stderr, " -q base quality threshold\n"); - fprintf(pysam_stderr, " -Q mapping quality threshold\n"); - fprintf(pysam_stderr, " -r region\n"); + fprintf(samtools_stderr, "\n"); + fprintf(samtools_stderr, "Usage: samtools depth [options] in1.bam [in2.bam [...]]\n"); + fprintf(samtools_stderr, "Options:\n"); + fprintf(samtools_stderr, " -a output all positions (including zero depth)\n"); + fprintf(samtools_stderr, " -a -a (or -aa) output absolutely all positions, including unused ref. sequences\n"); + fprintf(samtools_stderr, " -b list of positions or regions\n"); + fprintf(samtools_stderr, " -f list of input BAM filenames, one per line [null]\n"); + fprintf(samtools_stderr, " -l read length threshold (ignore reads shorter than ) [0]\n"); + fprintf(samtools_stderr, " -d/-m maximum coverage depth [8000]\n"); // the htslib's default + fprintf(samtools_stderr, " -q base quality threshold [0]\n"); + fprintf(samtools_stderr, " -Q mapping quality threshold [0]\n"); + fprintf(samtools_stderr, " -r region\n"); - sam_global_opt_help(pysam_stderr, "-.--."); + sam_global_opt_help(samtools_stderr, "-.--.-"); - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "The output is a simple tab-separated table with three columns: reference name,\n"); - fprintf(pysam_stderr, "position, and coverage depth. Note that positions with zero coverage may be\n"); - fprintf(pysam_stderr, "omitted by default; see the -a option.\n"); - fprintf(pysam_stderr, "\n"); + fprintf(samtools_stderr, "\n"); + fprintf(samtools_stderr, "The output is a simple tab-separated table with three columns: reference name,\n"); + fprintf(samtools_stderr, "position, and coverage depth. Note that positions with zero coverage may be\n"); + fprintf(samtools_stderr, "omitted by default; see the -a option.\n"); + fprintf(samtools_stderr, "\n"); return 1; } int main_depth(int argc, char *argv[]) { - int i, n, tid, beg, end, pos, *n_plp, baseQ = 0, mapQ = 0, min_len = 0; + int i, n, tid, reg_tid, beg, end, pos, *n_plp, baseQ = 0, mapQ = 0, min_len = 0; int all = 0, status = EXIT_SUCCESS, nfiles, max_depth = -1; const bam_pileup1_t **plp; char *reg = 0; // specified region @@ -114,7 +114,7 @@ int main_depth(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0, '-'), { NULL, 0, NULL, 0 } }; @@ -151,7 +151,7 @@ int main_depth(int argc, char *argv[]) else n = argc - optind; // the number of BAMs on the command line data = calloc(n, sizeof(aux_t*)); // data[i] for the i-th input - beg = 0; end = INT_MAX; // set the default region + reg_tid = 0; beg = 0; end = INT_MAX; // set the default region for (i = 0; i < n; ++i) { int rf; data[i] = calloc(1, sizeof(aux_t)); @@ -164,18 +164,18 @@ int main_depth(int argc, char *argv[]) rf = SAM_FLAG | SAM_RNAME | SAM_POS | SAM_MAPQ | SAM_CIGAR | SAM_SEQ; if (baseQ) rf |= SAM_QUAL; if (hts_set_opt(data[i]->fp, CRAM_OPT_REQUIRED_FIELDS, rf)) { - fprintf(pysam_stderr, "Failed to set CRAM_OPT_REQUIRED_FIELDS value\n"); + fprintf(samtools_stderr, "Failed to set CRAM_OPT_REQUIRED_FIELDS value\n"); return 1; } if (hts_set_opt(data[i]->fp, CRAM_OPT_DECODE_MD, 0)) { - fprintf(pysam_stderr, "Failed to set CRAM_OPT_DECODE_MD value\n"); + fprintf(samtools_stderr, "Failed to set CRAM_OPT_DECODE_MD value\n"); return 1; } data[i]->min_mapQ = mapQ; // set the mapQ filter data[i]->min_len = min_len; // set the qlen filter data[i]->hdr = sam_hdr_read(data[i]->fp); // read the BAM header if (data[i]->hdr == NULL) { - fprintf(pysam_stderr, "Couldn't read header for \"%s\"\n", + fprintf(samtools_stderr, "Couldn't read header for \"%s\"\n", argv[optind+i]); status = EXIT_FAILURE; goto depth_end; @@ -201,6 +201,7 @@ int main_depth(int argc, char *argv[]) if (reg) { beg = data[0]->iter->beg; // and to the parsed region coordinates end = data[0]->iter->end; + reg_tid = data[0]->iter->tid; } // the core multi-pileup loop @@ -212,22 +213,24 @@ int main_depth(int argc, char *argv[]) while ((ret=bam_mplp_auto(mplp, &tid, &pos, n_plp, plp)) > 0) { // come to the next covered position if (pos < beg || pos >= end) continue; // out of range; skip if (tid >= h->n_targets) continue; // diff number of @SQ lines per file? - if (bed && bed_overlap(bed, h->target_name[tid], pos, pos + 1) == 0) continue; // not in BED; skip if (all) { while (tid > last_tid) { - if (last_tid >= 0 && all > 1 && !reg) { - // Deal with remainder or entirety of last tid + if (last_tid >= 0 && !reg) { + // Deal with remainder or entirety of last tid. while (++last_pos < h->target_len[last_tid]) { + // Horribly inefficient, but the bed API is an obfuscated black box. if (bed && bed_overlap(bed, h->target_name[last_tid], last_pos, last_pos + 1) == 0) continue; - fputs(h->target_name[last_tid], pysam_stdout); fprintf(pysam_stdout, "\t%d", last_pos+1); + fputs(h->target_name[last_tid], samtools_stdout); fprintf(samtools_stdout, "\t%d", last_pos+1); for (i = 0; i < n; i++) - fputc('\t', pysam_stdout), fputc('0', pysam_stdout); - fputc('\n', pysam_stdout); + fputc('\t', samtools_stdout), fputc('0', samtools_stdout); + fputc('\n', samtools_stdout); } } last_tid++; last_pos = -1; + if (all < 2) + break; } // Deal with missing portion of current tid @@ -235,16 +238,17 @@ int main_depth(int argc, char *argv[]) if (last_pos < beg) continue; // out of range; skip if (bed && bed_overlap(bed, h->target_name[tid], last_pos, last_pos + 1) == 0) continue; - fputs(h->target_name[tid], pysam_stdout); fprintf(pysam_stdout, "\t%d", last_pos+1); + fputs(h->target_name[tid], samtools_stdout); fprintf(samtools_stdout, "\t%d", last_pos+1); for (i = 0; i < n; i++) - fputc('\t', pysam_stdout), fputc('0', pysam_stdout); - fputc('\n', pysam_stdout); + fputc('\t', samtools_stdout), fputc('0', samtools_stdout); + fputc('\n', samtools_stdout); } last_tid = tid; last_pos = pos; } - fputs(h->target_name[tid], pysam_stdout); fprintf(pysam_stdout, "\t%d", pos+1); // a customized fprintf(pysam_stdout, ) would be faster + if (bed && bed_overlap(bed, h->target_name[tid], pos, pos + 1) == 0) continue; + fputs(h->target_name[tid], samtools_stdout); fprintf(samtools_stdout, "\t%d", pos+1); // a customized fprintf(samtools_stdout, ) would be faster for (i = 0; i < n; ++i) { // base level filters have to go here int j, m = 0; for (j = 0; j < n_plp[i]; ++j) { @@ -252,9 +256,9 @@ int main_depth(int argc, char *argv[]) if (p->is_del || p->is_refskip) ++m; // having dels or refskips at tid:pos else if (bam_get_qual(p->b)[p->qpos] < baseQ) ++m; // low base quality } - fprintf(pysam_stdout, "\t%d", n_plp[i] - m); // this the depth to output + fprintf(samtools_stdout, "\t%d", n_plp[i] - m); // this the depth to output } - fputc('\n', pysam_stdout); + fputc('\n', samtools_stdout); } if (ret < 0) status = EXIT_FAILURE; free(n_plp); free(plp); @@ -262,15 +266,19 @@ int main_depth(int argc, char *argv[]) if (all) { // Handle terminating region - while (last_tid < h->n_targets) { + if (last_tid < 0 && reg && all > 1) { + last_tid = reg_tid; + last_pos = beg-1; + } + while (last_tid >= 0 && last_tid < h->n_targets) { while (++last_pos < h->target_len[last_tid]) { if (last_pos >= end) break; if (bed && bed_overlap(bed, h->target_name[last_tid], last_pos, last_pos + 1) == 0) continue; - fputs(h->target_name[last_tid], pysam_stdout); fprintf(pysam_stdout, "\t%d", last_pos+1); + fputs(h->target_name[last_tid], samtools_stdout); fprintf(samtools_stdout, "\t%d", last_pos+1); for (i = 0; i < n; i++) - fputc('\t', pysam_stdout), fputc('0', pysam_stdout); - fputc('\n', pysam_stdout); + fputc('\t', samtools_stdout), fputc('0', samtools_stdout); + fputc('\n', samtools_stdout); } last_tid++; last_pos = -1; diff --git a/samtools/bam_addrprg.c b/samtools/bam_addrprg.c index f7bbfab0d..99a198d22 100644 --- a/samtools/bam_addrprg.c +++ b/samtools/bam_addrprg.c @@ -1,6 +1,6 @@ /* bam_addrprg.c -- samtools command to add or replace readgroups. - Copyright (c) 2013, 2015 Genome Research Limited. + Copyright (c) 2013, 2015, 2016 Genome Research Limited. Author: Martin O. Pollard @@ -27,6 +27,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include "samtools.h" +#include "htslib/thread_pool.h" #include "sam_opts.h" #include #include @@ -48,6 +49,7 @@ struct parsed_opts { char* rg_line; rg_mode mode; sam_global_args ga; + htsThreadPool p; }; struct state; @@ -69,6 +71,7 @@ static void cleanup_opts(parsed_opts_t* opts) free(opts->rg_id); free(opts->output_name); free(opts->input_name); + if (opts->p.pool) hts_tpool_destroy(opts->p.pool); sam_global_args_free(&opts->ga); free(opts); } @@ -131,6 +134,19 @@ static char* basic_unescape(const char* in) return tmp; } +// Malloc a string containing [s,slim) or to the end of s if slim is NULL. +// If lenp is non-NULL, stores the length of the resulting string there. +static char *dup_substring(const char *s, const char *slim, size_t *lenp) +{ + size_t len = slim? (slim - s) : strlen(s); + char *ns = malloc(len+1); + if (ns == NULL) return NULL; + memcpy(ns, s, len); + ns[len] = '\0'; + if (lenp) *lenp = len; + return ns; +} + // These are to be replaced by samtools header parser // Extracts the first @RG line from a string. static char* get_rg_line(const char* text, size_t* last) @@ -143,37 +159,17 @@ static char* get_rg_line(const char* text, size_t* last) rg++;//skip initial \n } // duplicate the line for return - char* line; - char* end = strchr(rg, '\n'); - if (end) { - line = strndup(rg,(end-rg)); - *last = end - rg; - } else { - line = strdup(rg); - *last = strlen(rg); - } - return line; + return dup_substring(rg, strchr(rg, '\n'), last); } // Given a @RG line return the id -static char* get_rg_id(const char* input) +static char* get_rg_id(const char *line) { - assert(input!=NULL); - char* line = strdup(input); - char *next = line; - char* token = strsep(&next, "\t"); - token = strsep(&next,"\t"); // skip first token it should always be "@RG" - while (next != NULL) { - char* key = strsep(&token,":"); - if (!strcmp(key,"ID")) { - char* retval = strdup(token); - free(line); - return retval; - } - token = strsep(&next,"\t"); - } - free(line); - return NULL; + const char *id = strstr(line, "\tID:"); + if (! id) return NULL; + + id += 4; + return dup_substring(id, strchr(id, '\t'), NULL); } // Confirms the existance of an RG line with a given ID in a bam header @@ -181,9 +177,8 @@ static bool confirm_rg( const bam_hdr_t *hdr, const char* rgid ) { assert( hdr != NULL && rgid != NULL ); - char *ptr, *start; + const char *ptr = hdr->text; bool found = false; - start = ptr = strndup(hdr->text, hdr->l_text); while (ptr != NULL && *ptr != '\0' && found == false ) { size_t end = 0; char* line = get_rg_line(ptr, &end); @@ -196,16 +191,14 @@ static bool confirm_rg( const bam_hdr_t *hdr, const char* rgid ) free(line); ptr += end; } - free(start); return found; } static char* get_first_rgid( const bam_hdr_t *hdr ) { assert( hdr != NULL ); - char *ptr, *start; + const char *ptr = hdr->text; char* found = NULL; - start = ptr = strndup(hdr->text, hdr->l_text); while (ptr != NULL && *ptr != '\0' && found == NULL ) { size_t end = 0; char* line = get_rg_line(ptr, &end); @@ -215,7 +208,6 @@ static char* get_first_rgid( const bam_hdr_t *hdr ) free(line); ptr += end; } - free(start); return found; } @@ -230,7 +222,7 @@ static void usage(FILE *fp) " -r STRING @RG line text\n" " -R STRING ID of @RG line in existing header to use\n" ); - sam_global_opt_help(fp, "..O.."); + sam_global_opt_help(fp, "..O..@"); } static bool parse_args(int argc, char** argv, parsed_opts_t** opts) @@ -249,12 +241,12 @@ static bool parse_args(int argc, char** argv, parsed_opts_t** opts) retval->mode = overwrite_all; sam_global_args_init(&retval->ga); static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS(0, 0, 'O', 0, 0), + SAM_OPT_GLOBAL_OPTIONS(0, 0, 'O', 0, 0, '@'), { NULL, 0, NULL, 0 } }; kstring_t rg_line = {0,0,NULL}; - while ((n = getopt_long(argc, argv, "r:R:m:o:O:l:h", lopts, NULL)) >= 0) { + while ((n = getopt_long(argc, argv, "r:R:m:o:O:l:h@:", lopts, NULL)) >= 0) { switch (n) { case 'r': // Are we adding to existing rg line? @@ -328,6 +320,13 @@ static bool parse_args(int argc, char** argv, parsed_opts_t** opts) } retval->input_name = strdup(argv[optind+0]); + if (retval->ga.nthreads > 0) { + if (!(retval->p.pool = hts_tpool_init(retval->ga.nthreads))) { + fprintf(stderr, "Error creating thread pool\n"); + return false; + } + } + *opts = retval; return true; } @@ -369,7 +368,7 @@ static bool init(const parsed_opts_t* opts, state_t** state_out) { // Open files retval->input_file = sam_open_format(opts->input_name, "r", &opts->ga.in); if (retval->input_file == NULL) { - fprintf(stderr, "[init] Could not open input file: %s\n", opts->input_name); + print_error_errno("addreplacerg", "could not open \"%s\"", opts->input_name); return false; } retval->input_header = sam_hdr_read(retval->input_file); @@ -378,10 +377,15 @@ static bool init(const parsed_opts_t* opts, state_t** state_out) { retval->output_file = sam_open_format(opts->output_name == NULL?"-":opts->output_name, "w", &opts->ga.out); if (retval->output_file == NULL) { - print_error_errno("addreplacerg", "Could not open output file: %s\n", opts->output_name); + print_error_errno("addreplacerg", "could not create \"%s\"", opts->output_name); return false; } + if (opts->p.pool) { + hts_set_opt(retval->input_file, HTS_OPT_THREAD_POOL, &opts->p); + hts_set_opt(retval->output_file, HTS_OPT_THREAD_POOL, &opts->p); + } + if (opts->rg_line) { // Append new RG line to header. // Check does not already exist @@ -466,13 +470,13 @@ int main_addreplacerg(int argc, char** argv) if (!readgroupise(state)) goto error; - cleanup_opts(opts); cleanup_state(state); + cleanup_opts(opts); return EXIT_SUCCESS; error: - cleanup_opts(opts); cleanup_state(state); + cleanup_opts(opts); return EXIT_FAILURE; } diff --git a/samtools/bam_addrprg.c.pysam.c b/samtools/bam_addrprg.c.pysam.c index 2ddd1b16d..6d65ccb5c 100644 --- a/samtools/bam_addrprg.c.pysam.c +++ b/samtools/bam_addrprg.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_addrprg.c -- samtools command to add or replace readgroups. - Copyright (c) 2013, 2015 Genome Research Limited. + Copyright (c) 2013, 2015, 2016 Genome Research Limited. Author: Martin O. Pollard @@ -29,6 +29,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include "samtools.h" +#include "htslib/thread_pool.h" #include "sam_opts.h" #include #include @@ -50,6 +51,7 @@ struct parsed_opts { char* rg_line; rg_mode mode; sam_global_args ga; + htsThreadPool p; }; struct state; @@ -71,6 +73,7 @@ static void cleanup_opts(parsed_opts_t* opts) free(opts->rg_id); free(opts->output_name); free(opts->input_name); + if (opts->p.pool) hts_tpool_destroy(opts->p.pool); sam_global_args_free(&opts->ga); free(opts); } @@ -97,7 +100,7 @@ static char* basic_unescape(const char* in) if (*in == '\\') { ++in; if (*in == '\0') { - fprintf(pysam_stderr, "[%s] Unterminated escape sequence.\n", __func__); + fprintf(samtools_stderr, "[%s] Unterminated escape sequence.\n", __func__); free(out); return NULL; } @@ -109,11 +112,11 @@ static char* basic_unescape(const char* in) *ptr = '\t'; break; case 'n': - fprintf(pysam_stderr, "[%s] \\n in escape sequence is not supported.\n", __func__); + fprintf(samtools_stderr, "[%s] \\n in escape sequence is not supported.\n", __func__); free(out); return NULL; default: - fprintf(pysam_stderr, "[%s] Unsupported escape sequence.\n", __func__); + fprintf(samtools_stderr, "[%s] Unsupported escape sequence.\n", __func__); free(out); return NULL; } @@ -133,6 +136,19 @@ static char* basic_unescape(const char* in) return tmp; } +// Malloc a string containing [s,slim) or to the end of s if slim is NULL. +// If lenp is non-NULL, stores the length of the resulting string there. +static char *dup_substring(const char *s, const char *slim, size_t *lenp) +{ + size_t len = slim? (slim - s) : strlen(s); + char *ns = malloc(len+1); + if (ns == NULL) return NULL; + memcpy(ns, s, len); + ns[len] = '\0'; + if (lenp) *lenp = len; + return ns; +} + // These are to be replaced by samtools header parser // Extracts the first @RG line from a string. static char* get_rg_line(const char* text, size_t* last) @@ -145,37 +161,17 @@ static char* get_rg_line(const char* text, size_t* last) rg++;//skip initial \n } // duplicate the line for return - char* line; - char* end = strchr(rg, '\n'); - if (end) { - line = strndup(rg,(end-rg)); - *last = end - rg; - } else { - line = strdup(rg); - *last = strlen(rg); - } - return line; + return dup_substring(rg, strchr(rg, '\n'), last); } // Given a @RG line return the id -static char* get_rg_id(const char* input) +static char* get_rg_id(const char *line) { - assert(input!=NULL); - char* line = strdup(input); - char *next = line; - char* token = strsep(&next, "\t"); - token = strsep(&next,"\t"); // skip first token it should always be "@RG" - while (next != NULL) { - char* key = strsep(&token,":"); - if (!strcmp(key,"ID")) { - char* retval = strdup(token); - free(line); - return retval; - } - token = strsep(&next,"\t"); - } - free(line); - return NULL; + const char *id = strstr(line, "\tID:"); + if (! id) return NULL; + + id += 4; + return dup_substring(id, strchr(id, '\t'), NULL); } // Confirms the existance of an RG line with a given ID in a bam header @@ -183,9 +179,8 @@ static bool confirm_rg( const bam_hdr_t *hdr, const char* rgid ) { assert( hdr != NULL && rgid != NULL ); - char *ptr, *start; + const char *ptr = hdr->text; bool found = false; - start = ptr = strndup(hdr->text, hdr->l_text); while (ptr != NULL && *ptr != '\0' && found == false ) { size_t end = 0; char* line = get_rg_line(ptr, &end); @@ -198,16 +193,14 @@ static bool confirm_rg( const bam_hdr_t *hdr, const char* rgid ) free(line); ptr += end; } - free(start); return found; } static char* get_first_rgid( const bam_hdr_t *hdr ) { assert( hdr != NULL ); - char *ptr, *start; + const char *ptr = hdr->text; char* found = NULL; - start = ptr = strndup(hdr->text, hdr->l_text); while (ptr != NULL && *ptr != '\0' && found == NULL ) { size_t end = 0; char* line = get_rg_line(ptr, &end); @@ -217,7 +210,6 @@ static char* get_first_rgid( const bam_hdr_t *hdr ) free(line); ptr += end; } - free(start); return found; } @@ -228,11 +220,11 @@ static void usage(FILE *fp) "\n" "Options:\n" " -m MODE Set the mode of operation from one of overwrite_all, orphan_only [overwrite_all]\n" - " -o FILE Where to write output to [pysam_stdout]\n" + " -o FILE Where to write output to [samtools_stdout]\n" " -r STRING @RG line text\n" " -R STRING ID of @RG line in existing header to use\n" ); - sam_global_opt_help(fp, "..O.."); + sam_global_opt_help(fp, "..O..@"); } static bool parse_args(int argc, char** argv, parsed_opts_t** opts) @@ -240,23 +232,23 @@ static bool parse_args(int argc, char** argv, parsed_opts_t** opts) *opts = NULL; int n; - if (argc == 1) { usage(pysam_stdout); return true; } + if (argc == 1) { usage(samtools_stdout); return true; } parsed_opts_t* retval = calloc(1, sizeof(parsed_opts_t)); if (! retval ) { - fprintf(pysam_stderr, "[%s] Out of memory allocating parsed_opts_t\n", __func__); + fprintf(samtools_stderr, "[%s] Out of memory allocating parsed_opts_t\n", __func__); return false; } // Set defaults retval->mode = overwrite_all; sam_global_args_init(&retval->ga); static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS(0, 0, 'O', 0, 0), + SAM_OPT_GLOBAL_OPTIONS(0, 0, 'O', 0, 0, '@'), { NULL, 0, NULL, 0 } }; kstring_t rg_line = {0,0,NULL}; - while ((n = getopt_long(argc, argv, "r:R:m:o:O:l:h", lopts, NULL)) >= 0) { + while ((n = getopt_long(argc, argv, "r:R:m:o:O:l:h@:", lopts, NULL)) >= 0) { switch (n) { case 'r': // Are we adding to existing rg line? @@ -278,7 +270,7 @@ static bool parse_args(int argc, char** argv, parsed_opts_t** opts) } else if (strcmp(optarg, "orphan_only") == 0) { retval->mode = orphan_only; } else { - usage(pysam_stderr); + usage(samtools_stderr); return false; } break; @@ -287,17 +279,17 @@ static bool parse_args(int argc, char** argv, parsed_opts_t** opts) retval->output_name = strdup(optarg); break; case 'h': - usage(pysam_stdout); + usage(samtools_stdout); free(retval); return true; case '?': - usage(pysam_stderr); + usage(samtools_stderr); free(retval); return false; case 'O': default: if (parse_sam_global_opt(n, optarg, lopts, &retval->ga) == 0) break; - usage(pysam_stderr); + usage(samtools_stderr); free(retval); return false; } @@ -305,13 +297,13 @@ static bool parse_args(int argc, char** argv, parsed_opts_t** opts) retval->rg_line = ks_release(&rg_line); if (argc-optind < 1) { - fprintf(pysam_stderr, "You must specify an input file.\n"); - usage(pysam_stderr); + fprintf(samtools_stderr, "You must specify an input file.\n"); + usage(samtools_stderr); cleanup_opts(retval); return false; } if (retval->rg_id && retval->rg_line) { - fprintf(pysam_stderr, "The options -r and -R are mutually exclusive.\n"); + fprintf(samtools_stderr, "The options -r and -R are mutually exclusive.\n"); cleanup_opts(retval); return false; } @@ -321,7 +313,7 @@ static bool parse_args(int argc, char** argv, parsed_opts_t** opts) char* tmp = basic_unescape(retval->rg_line); if ((retval->rg_id = get_rg_id(tmp)) == NULL) { - fprintf(pysam_stderr, "[%s] The supplied RG line lacks an ID tag.\n", __func__); + fprintf(samtools_stderr, "[%s] The supplied RG line lacks an ID tag.\n", __func__); free(tmp); cleanup_opts(retval); return false; @@ -330,6 +322,13 @@ static bool parse_args(int argc, char** argv, parsed_opts_t** opts) } retval->input_name = strdup(argv[optind+0]); + if (retval->ga.nthreads > 0) { + if (!(retval->p.pool = hts_tpool_init(retval->ga.nthreads))) { + fprintf(samtools_stderr, "Error creating thread pool\n"); + return false; + } + } + *opts = retval; return true; } @@ -363,7 +362,7 @@ static void orphan_only_func(const state_t* state, bam1_t* file_read) static bool init(const parsed_opts_t* opts, state_t** state_out) { state_t* retval = (state_t*) calloc(1, sizeof(state_t)); if (retval == NULL) { - fprintf(pysam_stderr, "[init] Out of memory allocating state struct.\n"); + fprintf(samtools_stderr, "[init] Out of memory allocating state struct.\n"); return false; } *state_out = retval; @@ -371,7 +370,7 @@ static bool init(const parsed_opts_t* opts, state_t** state_out) { // Open files retval->input_file = sam_open_format(opts->input_name, "r", &opts->ga.in); if (retval->input_file == NULL) { - fprintf(pysam_stderr, "[init] Could not open input file: %s\n", opts->input_name); + print_error_errno("addreplacerg", "could not open \"%s\"", opts->input_name); return false; } retval->input_header = sam_hdr_read(retval->input_file); @@ -380,22 +379,27 @@ static bool init(const parsed_opts_t* opts, state_t** state_out) { retval->output_file = sam_open_format(opts->output_name == NULL?"-":opts->output_name, "w", &opts->ga.out); if (retval->output_file == NULL) { - print_error_errno("addreplacerg", "Could not open output file: %s\n", opts->output_name); + print_error_errno("addreplacerg", "could not create \"%s\"", opts->output_name); return false; } + if (opts->p.pool) { + hts_set_opt(retval->input_file, HTS_OPT_THREAD_POOL, &opts->p); + hts_set_opt(retval->output_file, HTS_OPT_THREAD_POOL, &opts->p); + } + if (opts->rg_line) { // Append new RG line to header. // Check does not already exist if ( confirm_rg(retval->output_header, opts->rg_id) ) { - fprintf(pysam_stderr, "[init] ID of new RG line specified conflicts with that of an existing header RG line. Overwrite not yet implemented.\n"); + fprintf(samtools_stderr, "[init] ID of new RG line specified conflicts with that of an existing header RG line. Overwrite not yet implemented.\n"); return false; } retval->rg_id = strdup(opts->rg_id); size_t new_len = strlen( retval->output_header->text ) + strlen( opts->rg_line ) + 2; char* new_header = malloc(new_len); if (!new_header) { - fprintf(pysam_stderr, "[init] Out of memory whilst writing new header.\n"); + fprintf(samtools_stderr, "[init] Out of memory whilst writing new header.\n"); return false; } sprintf(new_header,"%s%s\n", retval->output_header->text, opts->rg_line); @@ -406,13 +410,13 @@ static bool init(const parsed_opts_t* opts, state_t** state_out) { if (opts->rg_id) { // Confirm what has been supplied exists if ( !confirm_rg(retval->output_header, opts->rg_id) ) { - fprintf(pysam_stderr, "RG ID supplied does not exist in header. Supply full @RG line with -r instead?\n"); + fprintf(samtools_stderr, "RG ID supplied does not exist in header. Supply full @RG line with -r instead?\n"); return false; } retval->rg_id = strdup(opts->rg_id); } else { if ((retval->rg_id = get_first_rgid(retval->output_header)) == NULL ) { - fprintf(pysam_stderr, "No RG specified on command line or in existing header.\n"); + fprintf(samtools_stderr, "No RG specified on command line or in existing header.\n"); return false; } } @@ -468,13 +472,13 @@ int main_addreplacerg(int argc, char** argv) if (!readgroupise(state)) goto error; - cleanup_opts(opts); cleanup_state(state); + cleanup_opts(opts); return EXIT_SUCCESS; error: - cleanup_opts(opts); cleanup_state(state); + cleanup_opts(opts); return EXIT_FAILURE; } diff --git a/samtools/bam_aux.c.pysam.c b/samtools/bam_aux.c.pysam.c index c6bd0aab3..637e76647 100644 --- a/samtools/bam_aux.c.pysam.c +++ b/samtools/bam_aux.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_aux.c -- remaining aux field handling. diff --git a/samtools/bam_cat.c b/samtools/bam_cat.c index 5c303d1ed..95498ec36 100644 --- a/samtools/bam_cat.c +++ b/samtools/bam_cat.c @@ -40,6 +40,7 @@ Illumina. #include #include #include +#include #include "htslib/bgzf.h" #include "htslib/sam.h" @@ -468,7 +469,7 @@ int bam_cat(int nfn, char * const *fn, const bam_hdr_t *h, const char* outbam) } if (in->block_offset < in->block_length) { - if (bgzf_write(fp, in->uncompressed_block + in->block_offset, in->block_length - in->block_offset) < 0) goto write_fail; + if (bgzf_write(fp, (char *)in->uncompressed_block + in->block_offset, in->block_length - in->block_offset) < 0) goto write_fail; if (bgzf_flush(fp) != 0) goto write_fail; } @@ -531,10 +532,12 @@ int main_cat(int argc, char *argv[]) { bam_hdr_t *h = 0; char *outfn = 0; + char **infns = NULL; // files to concatenate + int infns_size = 0; int c, ret = 0; samFile *in; - while ((c = getopt(argc, argv, "h:o:")) >= 0) { + while ((c = getopt(argc, argv, "h:o:b:")) >= 0) { switch (c) { case 'h': { samFile *fph = sam_open(optarg, "r"); @@ -553,29 +556,61 @@ int main_cat(int argc, char *argv[]) break; } case 'o': outfn = strdup(optarg); break; + case 'b': { + // add file names in "optarg" to the list + // of files to concatenate + int nfns; + char **fns_read = hts_readlines(optarg, &nfns); + if (fns_read) { + infns = realloc(infns, (infns_size + nfns) * sizeof(char*)); + if (infns == NULL) { ret = 1; goto end; } + memcpy(infns+infns_size, fns_read, nfns * sizeof(char*)); + infns_size += nfns; + free(fns_read); + } else { + print_error("cat", "Invalid file list \"%s\"", optarg); + ret = 1; + } + break; + } } } - if (argc - optind < 1) { - fprintf(stderr, "Usage: samtools cat [-h header.sam] [-o out.bam] [...]\n"); + + // Append files specified in argv to the list. + int nargv_fns = argc - optind; + if (nargv_fns > 0) { + infns = realloc(infns, (infns_size + nargv_fns) * sizeof(char*)); + if (infns == NULL) { ret = 1; goto end; } + memcpy(infns + infns_size, argv + optind, nargv_fns * sizeof(char*)); + } + + // Require at least one input file + if (infns_size + nargv_fns == 0) { + fprintf(stderr, "Usage: samtools cat [options] [... ]\n"); + fprintf(stderr, " samtools cat [options] [... ]\n\n"); + fprintf(stderr, "Concatenate BAM or CRAM files, first those in , then those\non the command line.\n\n"); + fprintf(stderr, "Options: -b FILE list of input BAM/CRAM file names, one per line\n"); + fprintf(stderr, " -h FILE copy the header from FILE [default is 1st input file]\n"); + fprintf(stderr, " -o FILE output BAM/CRAM\n"); return 1; } - in = sam_open(argv[optind], "r"); + in = sam_open(infns[0], "r"); if (!in) { - print_error_errno("cat", "failed to open file '%s'", argv[optind]); + print_error_errno("cat", "failed to open file '%s'", infns[0]); return 1; } switch (hts_get_format(in)->format) { case bam: sam_close(in); - if (bam_cat(argc - optind, argv + optind, h, outfn? outfn : "-") < 0) + if (bam_cat(infns_size+nargv_fns, infns, h, outfn? outfn : "-") < 0) ret = 1; break; case cram: sam_close(in); - if (cram_cat(argc - optind, argv + optind, h, outfn? outfn : "-") < 0) + if (cram_cat(infns_size+nargv_fns, infns, h, outfn? outfn : "-") < 0) ret = 1; break; @@ -584,7 +619,16 @@ int main_cat(int argc, char *argv[]) fprintf(stderr, "[%s] ERROR: input is not BAM or CRAM\n", __func__); return 1; } + + end: + if (infns_size > 0) { + int i; + for (i=0; i #include #include +#include #include "htslib/bgzf.h" #include "htslib/sam.h" @@ -209,7 +210,7 @@ static bam_hdr_t *cram_cat_check_hdr(int nfn, char * const *fn, const bam_hdr_t int vmin = cram_minor_vers(in_c); if ((vers_maj != -1 && vers_maj != vmaj) || (vers_min != -1 && vers_min != vmin)) { - fprintf(pysam_stderr, "[%s] ERROR: input files have differing version numbers.\n", + fprintf(samtools_stderr, "[%s] ERROR: input files have differing version numbers.\n", __func__); return NULL; } @@ -229,7 +230,7 @@ static bam_hdr_t *cram_cat_check_hdr(int nfn, char * const *fn, const bam_hdr_t int added; new_rg = hash_s2i_inc(*rg2id, rg2id_in->id[ki], rg2id_in->line[ki], &added); - //fprintf(pysam_stderr, "RG %s: #%d -> #%d\n", + //fprintf(samtools_stderr, "RG %s: #%d -> #%d\n", // rg2id_in->id[ki], ki, new_rg); if (added) { @@ -245,7 +246,7 @@ static bam_hdr_t *cram_cat_check_hdr(int nfn, char * const *fn, const bam_hdr_t } if (new_rg != ki && rg2id_in->n_id > 1) { - fprintf(pysam_stderr, "[%s] ERROR: Same size @RG lists but differing order / contents\n", + fprintf(samtools_stderr, "[%s] ERROR: Same size @RG lists but differing order / contents\n", __func__); return NULL; } @@ -312,7 +313,7 @@ int cram_cat(int nfn, char * const *fn, const bam_hdr_t *h, const char* outcram) } out_c = out->fp.cram; cram_set_option(out_c, CRAM_OPT_VERSION, vers); - //fprintf(pysam_stderr, "Creating cram vers %s\n", vers); + //fprintf(samtools_stderr, "Creating cram vers %s\n", vers); cram_fd_set_header(out_c, sam_hdr_parse_(new_h->text, new_h->l_text)); // needed? if (sam_hdr_write(out, new_h) < 0) { @@ -373,7 +374,7 @@ int cram_cat(int nfn, char * const *fn, const bam_hdr_t *h, const char* outcram) // we need to edit the compression header. IF WE CAN. if (new_rg) { int zero = 0; - //fprintf(pysam_stderr, "Transcode RG %d to %d\n", 0, new_rg); + //fprintf(samtools_stderr, "Transcode RG %d to %d\n", 0, new_rg); cram_transcode_rg(in_c, out_c, c, 1, &zero, &new_rg); } else { int32_t num_slices; @@ -428,7 +429,7 @@ int bam_cat(int nfn, char * const *fn, const bam_hdr_t *h, const char* outbam) const int es=BGZF_EMPTY_BLOCK_SIZE; int i; - fp = strcmp(outbam, "-")? bgzf_open(outbam, "w") : bgzf_fdopen(fileno(pysam_stdout), "w"); + fp = strcmp(outbam, "-")? bgzf_open(outbam, "w") : bgzf_fdopen(fileno(samtools_stdout), "w"); if (fp == 0) { print_error_errno("cat", "fail to open output file '%s'", outbam); return -1; @@ -442,7 +443,7 @@ int bam_cat(int nfn, char * const *fn, const bam_hdr_t *h, const char* outbam) buf = (uint8_t*) malloc(BUF_SIZE); if (!buf) { - fprintf(pysam_stderr, "[%s] Couldn't allocate buffer\n", __func__); + fprintf(samtools_stderr, "[%s] Couldn't allocate buffer\n", __func__); goto fail; } for(i = 0; i < nfn; ++i){ @@ -458,7 +459,7 @@ int bam_cat(int nfn, char * const *fn, const bam_hdr_t *h, const char* outbam) old = bam_hdr_read(in); if (old == NULL) { - fprintf(pysam_stderr, "[%s] ERROR: couldn't read header for '%s'.\n", + fprintf(samtools_stderr, "[%s] ERROR: couldn't read header for '%s'.\n", __func__, fn[i]); goto fail; } @@ -470,7 +471,7 @@ int bam_cat(int nfn, char * const *fn, const bam_hdr_t *h, const char* outbam) } if (in->block_offset < in->block_length) { - if (bgzf_write(fp, in->uncompressed_block + in->block_offset, in->block_length - in->block_offset) < 0) goto write_fail; + if (bgzf_write(fp, (char *)in->uncompressed_block + in->block_offset, in->block_length - in->block_offset) < 0) goto write_fail; if (bgzf_flush(fp) != 0) goto write_fail; } @@ -479,7 +480,7 @@ int bam_cat(int nfn, char * const *fn, const bam_hdr_t *h, const char* outbam) if(len= 0) { + while ((c = getopt(argc, argv, "h:o:b:")) >= 0) { switch (c) { case 'h': { samFile *fph = sam_open(optarg, "r"); if (fph == 0) { - fprintf(pysam_stderr, "[%s] ERROR: fail to read the header from '%s'.\n", __func__, argv[1]); + fprintf(samtools_stderr, "[%s] ERROR: fail to read the header from '%s'.\n", __func__, argv[1]); return 1; } h = sam_hdr_read(fph); if (h == NULL) { - fprintf(pysam_stderr, + fprintf(samtools_stderr, "[%s] ERROR: failed to read the header for '%s'.\n", __func__, argv[1]); return 1; @@ -555,38 +558,79 @@ int main_cat(int argc, char *argv[]) break; } case 'o': outfn = strdup(optarg); break; + case 'b': { + // add file names in "optarg" to the list + // of files to concatenate + int nfns; + char **fns_read = hts_readlines(optarg, &nfns); + if (fns_read) { + infns = realloc(infns, (infns_size + nfns) * sizeof(char*)); + if (infns == NULL) { ret = 1; goto end; } + memcpy(infns+infns_size, fns_read, nfns * sizeof(char*)); + infns_size += nfns; + free(fns_read); + } else { + print_error("cat", "Invalid file list \"%s\"", optarg); + ret = 1; + } + break; + } } } - if (argc - optind < 1) { - fprintf(pysam_stderr, "Usage: samtools cat [-h header.sam] [-o out.bam] [...]\n"); + + // Append files specified in argv to the list. + int nargv_fns = argc - optind; + if (nargv_fns > 0) { + infns = realloc(infns, (infns_size + nargv_fns) * sizeof(char*)); + if (infns == NULL) { ret = 1; goto end; } + memcpy(infns + infns_size, argv + optind, nargv_fns * sizeof(char*)); + } + + // Require at least one input file + if (infns_size + nargv_fns == 0) { + fprintf(samtools_stderr, "Usage: samtools cat [options] [... ]\n"); + fprintf(samtools_stderr, " samtools cat [options] [... ]\n\n"); + fprintf(samtools_stderr, "Concatenate BAM or CRAM files, first those in , then those\non the command line.\n\n"); + fprintf(samtools_stderr, "Options: -b FILE list of input BAM/CRAM file names, one per line\n"); + fprintf(samtools_stderr, " -h FILE copy the header from FILE [default is 1st input file]\n"); + fprintf(samtools_stderr, " -o FILE output BAM/CRAM\n"); return 1; } - in = sam_open(argv[optind], "r"); + in = sam_open(infns[0], "r"); if (!in) { - print_error_errno("cat", "failed to open file '%s'", argv[optind]); + print_error_errno("cat", "failed to open file '%s'", infns[0]); return 1; } switch (hts_get_format(in)->format) { case bam: sam_close(in); - if (bam_cat(argc - optind, argv + optind, h, outfn? outfn : "-") < 0) + if (bam_cat(infns_size+nargv_fns, infns, h, outfn? outfn : "-") < 0) ret = 1; break; case cram: sam_close(in); - if (cram_cat(argc - optind, argv + optind, h, outfn? outfn : "-") < 0) + if (cram_cat(infns_size+nargv_fns, infns, h, outfn? outfn : "-") < 0) ret = 1; break; default: sam_close(in); - fprintf(pysam_stderr, "[%s] ERROR: input is not BAM or CRAM\n", __func__); + fprintf(samtools_stderr, "[%s] ERROR: input is not BAM or CRAM\n", __func__); return 1; } + + end: + if (infns_size > 0) { + int i; + for (i=0; is); free(str); header = sam_hdr_parse(samstr.l, samstr.s? samstr.s : ""); free(samstr.s); - fprintf(pysam_stderr, "[sam_header_read2] %d sequences loaded.\n", n_targets); + fprintf(samtools_stderr, "[sam_header_read2] %d sequences loaded.\n", n_targets); return header; } diff --git a/samtools/bam_index.c b/samtools/bam_index.c index 3a5acf6f8..40b7e0fd2 100644 --- a/samtools/bam_index.c +++ b/samtools/bam_index.c @@ -46,20 +46,23 @@ static void index_usage(FILE *fp) "Options:\n" " -b Generate BAI-format index for BAM files [default]\n" " -c Generate CSI-format index for BAM files\n" -" -m INT Set minimum interval size for CSI indices to 2^INT [%d]\n", BAM_LIDX_SHIFT); +" -m INT Set minimum interval size for CSI indices to 2^INT [%d]\n" +" -@ INT Sets the number of threads [none]\n", BAM_LIDX_SHIFT); } int bam_index(int argc, char *argv[]) { int csi = 0; int min_shift = BAM_LIDX_SHIFT; + int n_threads = 0; int c, ret; - while ((c = getopt(argc, argv, "bcm:")) >= 0) + while ((c = getopt(argc, argv, "bcm:@:")) >= 0) switch (c) { case 'b': csi = 0; break; case 'c': csi = 1; break; case 'm': csi = 1; min_shift = atoi(optarg); break; + case '@': n_threads = atoi(optarg); break; default: index_usage(stderr); return 1; @@ -70,18 +73,32 @@ int bam_index(int argc, char *argv[]) return 1; } - ret = sam_index_build2(argv[optind], argv[optind+1], csi? min_shift : 0); - if (ret != 0) { - if (ret == -2) - print_error_errno("index", "failed to open \"%s\"", argv[optind]); - else if (ret == -3) - print_error("index", "\"%s\" is in a format that cannot be usefully indexed", argv[optind]); + ret = sam_index_build3(argv[optind], argv[optind+1], csi? min_shift : 0, n_threads); + switch (ret) { + case 0: + return 0; + + case -2: + print_error_errno("index", "failed to open \"%s\"", argv[optind]); + break; + + case -3: + print_error("index", "\"%s\" is in a format that cannot be usefully indexed", argv[optind]); + break; + + case -4: + if (argv[optind+1]) + print_error("index", "failed to create or write index \"%s\"", argv[optind+1]); else - print_error("index", "\"%s\" is corrupted or unsorted", argv[optind]); - return EXIT_FAILURE; + print_error("index", "failed to create or write index"); + break; + + default: + print_error_errno("index", "failed to create index for \"%s\"", argv[optind]); + break; } - return 0; + return EXIT_FAILURE; } int bam_idxstats(int argc, char *argv[]) @@ -95,15 +112,20 @@ int bam_idxstats(int argc, char *argv[]) return 1; } fp = sam_open(argv[1], "r"); - if (fp == NULL) { fprintf(stderr, "[%s] fail to open BAM.\n", __func__); return 1; } + if (fp == NULL) { + print_error_errno("idxstats", "failed to open \"%s\"", argv[1]); + return 1; + } header = sam_hdr_read(fp); if (header == NULL) { - fprintf(stderr, "[%s] failed to read header for '%s'.\n", - __func__, argv[1]); + print_error("idxstats", "failed to read header for \"%s\"", argv[1]); return 1; } idx = sam_index_load(fp, argv[1]); - if (idx == NULL) { fprintf(stderr, "[%s] fail to load the index.\n", __func__); return 1; } + if (idx == NULL) { + print_error("idxstats", "fail to load index for \"%s\"", argv[1]); + return 1; + } int i; for (i = 0; i < header->n_targets; ++i) { diff --git a/samtools/bam_index.c.pysam.c b/samtools/bam_index.c.pysam.c index 6c0efdcf0..e13d453a3 100644 --- a/samtools/bam_index.c.pysam.c +++ b/samtools/bam_index.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_index.c -- index and idxstats subcommands. @@ -48,42 +48,59 @@ static void index_usage(FILE *fp) "Options:\n" " -b Generate BAI-format index for BAM files [default]\n" " -c Generate CSI-format index for BAM files\n" -" -m INT Set minimum interval size for CSI indices to 2^INT [%d]\n", BAM_LIDX_SHIFT); +" -m INT Set minimum interval size for CSI indices to 2^INT [%d]\n" +" -@ INT Sets the number of threads [none]\n", BAM_LIDX_SHIFT); } int bam_index(int argc, char *argv[]) { int csi = 0; int min_shift = BAM_LIDX_SHIFT; + int n_threads = 0; int c, ret; - while ((c = getopt(argc, argv, "bcm:")) >= 0) + while ((c = getopt(argc, argv, "bcm:@:")) >= 0) switch (c) { case 'b': csi = 0; break; case 'c': csi = 1; break; case 'm': csi = 1; min_shift = atoi(optarg); break; + case '@': n_threads = atoi(optarg); break; default: - index_usage(pysam_stderr); + index_usage(samtools_stderr); return 1; } if (optind == argc) { - index_usage(pysam_stdout); + index_usage(samtools_stdout); return 1; } - ret = sam_index_build2(argv[optind], argv[optind+1], csi? min_shift : 0); - if (ret != 0) { - if (ret == -2) - print_error_errno("index", "failed to open \"%s\"", argv[optind]); - else if (ret == -3) - print_error("index", "\"%s\" is in a format that cannot be usefully indexed", argv[optind]); + ret = sam_index_build3(argv[optind], argv[optind+1], csi? min_shift : 0, n_threads); + switch (ret) { + case 0: + return 0; + + case -2: + print_error_errno("index", "failed to open \"%s\"", argv[optind]); + break; + + case -3: + print_error("index", "\"%s\" is in a format that cannot be usefully indexed", argv[optind]); + break; + + case -4: + if (argv[optind+1]) + print_error("index", "failed to create or write index \"%s\"", argv[optind+1]); else - print_error("index", "\"%s\" is corrupted or unsorted", argv[optind]); - return EXIT_FAILURE; + print_error("index", "failed to create or write index"); + break; + + default: + print_error_errno("index", "failed to create index for \"%s\"", argv[optind]); + break; } - return 0; + return EXIT_FAILURE; } int bam_idxstats(int argc, char *argv[]) @@ -93,31 +110,36 @@ int bam_idxstats(int argc, char *argv[]) samFile* fp; if (argc < 2) { - fprintf(pysam_stderr, "Usage: samtools idxstats \n"); + fprintf(samtools_stderr, "Usage: samtools idxstats \n"); return 1; } fp = sam_open(argv[1], "r"); - if (fp == NULL) { fprintf(pysam_stderr, "[%s] fail to open BAM.\n", __func__); return 1; } + if (fp == NULL) { + print_error_errno("idxstats", "failed to open \"%s\"", argv[1]); + return 1; + } header = sam_hdr_read(fp); if (header == NULL) { - fprintf(pysam_stderr, "[%s] failed to read header for '%s'.\n", - __func__, argv[1]); + print_error("idxstats", "failed to read header for \"%s\"", argv[1]); return 1; } idx = sam_index_load(fp, argv[1]); - if (idx == NULL) { fprintf(pysam_stderr, "[%s] fail to load the index.\n", __func__); return 1; } + if (idx == NULL) { + print_error("idxstats", "fail to load index for \"%s\"", argv[1]); + return 1; + } int i; for (i = 0; i < header->n_targets; ++i) { // Print out contig name and length - fprintf(pysam_stdout, "%s\t%d", header->target_name[i], header->target_len[i]); + fprintf(samtools_stdout, "%s\t%d", header->target_name[i], header->target_len[i]); // Now fetch info about it from the meta bin uint64_t u, v; hts_idx_get_stat(idx, i, &u, &v); - fprintf(pysam_stdout, "\t%" PRIu64 "\t%" PRIu64 "\n", u, v); + fprintf(samtools_stdout, "\t%" PRIu64 "\t%" PRIu64 "\n", u, v); } // Dump information about unmapped reads - fprintf(pysam_stdout, "*\t0\t0\t%" PRIu64 "\n", hts_idx_get_n_no_coor(idx)); + fprintf(samtools_stdout, "*\t0\t0\t%" PRIu64 "\n", hts_idx_get_n_no_coor(idx)); bam_hdr_destroy(header); hts_idx_destroy(idx); sam_close(fp); diff --git a/samtools/bam_lpileup.c b/samtools/bam_lpileup.c index e20cc92a5..cc7a75bdf 100644 --- a/samtools/bam_lpileup.c +++ b/samtools/bam_lpileup.c @@ -29,6 +29,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include "bam_plbuf.h" #include "bam_lpileup.h" +#include "samtools.h" #include #define TV_GAP 2 diff --git a/samtools/bam_lpileup.c.pysam.c b/samtools/bam_lpileup.c.pysam.c index 9f7f06355..8a1555cc5 100644 --- a/samtools/bam_lpileup.c.pysam.c +++ b/samtools/bam_lpileup.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_lpileup.c -- lplbuf routines. @@ -31,6 +31,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include "bam_plbuf.h" #include "bam_lpileup.h" +#include "samtools.h" #include #define TV_GAP 2 @@ -181,14 +182,14 @@ static int tview_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl } tv->n_pre = l; /* - fprintf(pysam_stderr, "%d\t", pos+1); + fprintf(samtools_stderr, "%d\t", pos+1); for (i = 0; i < n; ++i) { const bam_pileup1_t *p = pl + i; - if (p->is_head) fprintf(pysam_stderr, "^"); - if (p->is_tail) fprintf(pysam_stderr, "$"); - fprintf(pysam_stderr, "%d,", p->level); + if (p->is_head) fprintf(samtools_stderr, "^"); + if (p->is_tail) fprintf(samtools_stderr, "$"); + fprintf(samtools_stderr, "%d,", p->level); } - fprintf(pysam_stderr, "\n"); + fprintf(samtools_stderr, "\n"); */ return 0; } diff --git a/samtools/bam_markdup.c b/samtools/bam_markdup.c new file mode 100644 index 000000000..21bf90aa9 --- /dev/null +++ b/samtools/bam_markdup.c @@ -0,0 +1,1039 @@ +/* bam_markdup.c -- Mark duplicates from a coord sorted file that has gone + through fixmates with the mate scoring option on. + + Copyright (C) 2017 Genome Research Ltd. + + Author: Andrew Whitwham + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include "htslib/thread_pool.h" +#include "htslib/sam.h" +#include "sam_opts.h" +#include "samtools.h" +#include "htslib/khash.h" +#include "htslib/klist.h" +#include "htslib/kstring.h" +#include "tmp_file.h" + +typedef struct { + int32_t single; + int32_t this_ref; + int32_t this_coord; + int32_t other_ref; + int32_t other_coord; + int32_t leftmost; + int32_t orientation; +} key_data_t; + +typedef struct { + bam1_t *p; +} in_hash_t; + +typedef struct { + bam1_t *b; + int32_t pos; + key_data_t pair_key; + key_data_t single_key; +} read_queue_t; + + + +static khint32_t do_hash(unsigned char *key, khint32_t len); + +static khint_t hash_key(key_data_t key) { + int i = 0; + khint_t hash; + + if (key.single) { + unsigned char sig[12]; + + memcpy(sig + i, &key.this_ref, 4); i += 4; + memcpy(sig + i, &key.this_coord, 4); i += 4; + memcpy(sig + i, &key.orientation, 4); i += 4; + + hash = do_hash(sig, i); + } else { + unsigned char sig[24]; + + memcpy(sig + i, &key.this_ref, 4); i += 4; + memcpy(sig + i, &key.this_coord, 4); i += 4; + memcpy(sig + i, &key.other_ref, 4); i += 4; + memcpy(sig + i, &key.other_coord, 4); i += 4; + memcpy(sig + i, &key.leftmost, 4); i += 4; + memcpy(sig + i, &key.orientation, 4); i += 4; + + hash = do_hash(sig, i); + } + + return hash; +} + + +static int key_equal(key_data_t a, key_data_t b) { + int match = 1; + + if (a.this_coord != b.this_coord) + match = 0; + else if (a.orientation != b.orientation) + match = 0; + else if (a.this_ref != b.this_ref) + match = 0; + else if (a.single != b.single) + match = 0; + + if (!a.single) { + if (a.other_coord != b.other_coord) + match = 0; + else if (a.leftmost != b.leftmost) + match = 0; + else if (a.other_ref != b.other_ref) + match = 0; + } + + return match; +} + + +#define __free_queue_element(p) +#define O_FF 2 +#define O_RR 3 +#define O_FR 5 +#define O_RF 7 + +KHASH_INIT(reads, key_data_t, in_hash_t, 1, hash_key, key_equal) // read map hash +KLIST_INIT(read_queue, read_queue_t, __free_queue_element) // the reads buffer +KHASH_MAP_INIT_STR(duplicates, int) // map of duplicates for supplementary dup id + + +/* Calculate the mate's unclipped start based on position and cigar string from MC tag. */ + +static int32_t unclipped_other_start(int32_t op, char *cigar) { + char *c = cigar; + int32_t clipped = 0; + + while (*c && *c != '*') { + long num = 0; + + if (isdigit((int)*c)) { + num = strtol(c, &c, 10); + } else { + num = 1; + } + + if (*c == 'S' || *c == 'H') { // clips + clipped += num; + } else { + break; + } + + c++; + } + + return op - clipped + 1; +} + + +/* Calculate the current read's start based on the stored cigar string. */ + +static int32_t unclipped_start(bam1_t *b) { + uint32_t *cigar = bam_get_cigar(b); + int32_t clipped = 0; + uint32_t i; + + for (i = 0; i < b->core.n_cigar; i++) { + char c = bam_cigar_opchr(cigar[i]); + + if (c == 'S' || c == 'H') { // clips + clipped += bam_cigar_oplen(cigar[i]); + } else { + break; + } + } + + return b->core.pos - clipped + 1; +} + + +/* Calculate the mate's unclipped end based on start position and cigar string from MC tag.*/ + +static int32_t unclipped_other_end(int32_t op, char *cigar) { + char *c = cigar; + int32_t refpos = 0; + int skip = 1; + + while (*c && *c != '*') { + long num = 0; + + if (isdigit((int)*c)) { + num = strtol(c, &c, 10); + } else { + num = 1; + } + + switch (*c) { + case 'M': + case 'D': + case 'N': + case '=': + case 'X': + refpos += num; + skip = 0; // ignore initial clips + break; + + case 'S': + case 'H': + if (!skip) { + refpos += num; + } + break; + } + + c++; + } + + return op + refpos; +} + + +/* Calculate the current read's end based on the stored cigar string. */ + +static int32_t unclipped_end(bam1_t *b) { + uint32_t *cigar = bam_get_cigar(b); + int32_t end_pos, clipped = 0; + int32_t i; + + end_pos = bam_endpos(b); + + // now get the clipped end bases (if any) + // if we get to the beginning of the cigar string + // without hitting a non-clip then the results are meaningless + for (i = b->core.n_cigar - 1; i >= 0; i--) { + char c = bam_cigar_opchr(cigar[i]); + + if (c == 'S' || c == 'H') { // clips + clipped += bam_cigar_oplen(cigar[i]); + } else { + break; + } + } + + return end_pos + clipped; +} + + +/* The Bob Jenkins one_at_a_time hash to reduce the key to a 32 bit value. */ + +static khint32_t do_hash(unsigned char *key, khint32_t len) { + khint32_t hash, i; + + for (hash = 0, i = 0; i < len; ++i) { + hash += key[i]; + hash += (hash << 10); + hash ^= (hash >> 6); + } + + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + + return hash; +} + + +/* Get mate score from tag. */ + +static int64_t get_mate_score(bam1_t *b) { + uint8_t *data; + int64_t score; + + if ((data = bam_aux_get(b, "ms"))) { + score = bam_aux2i(data); + } else { + fprintf(stderr, "[markdup] error: no ms score tag.\n"); + return -1; + } + + return score; +} + + +/* Calc current score from quality. */ + +static int64_t calc_score(bam1_t *b) +{ + int64_t score = 0; + uint8_t *qual = bam_get_qual(b); + int i; + + for (i = 0; i < b->core.l_qseq; i++) { + if (qual[i] >= 15) score += qual[i]; + } + + return score; +} + + +/* Create a signature hash of the current read and its pair. + Uses the unclipped start (or end depending on orientation), + the reference id, orientation and whether the current + read is leftmost of the pair. */ + +static int make_pair_key(key_data_t *key, bam1_t *bam) { + int32_t this_ref, this_coord, this_end; + int32_t other_ref, other_coord, other_end; + int32_t orientation, leftmost; + uint8_t *data; + char *cig; + + this_ref = bam->core.tid + 1; // avoid a 0 being put into the hash + other_ref = bam->core.mtid + 1; + + this_coord = unclipped_start(bam); + this_end = unclipped_end(bam); + + if ((data = bam_aux_get(bam, "MC"))) { + cig = bam_aux2Z(data); + other_end = unclipped_other_end(bam->core.mpos, cig); + other_coord = unclipped_other_start(bam->core.mpos, cig); + } else { + fprintf(stderr, "[markdup] error: no MC tag.\n"); + return 1; + } + + // work out orientations + if (this_ref != other_ref) { + leftmost = this_ref < other_ref; + } else { + if (bam_is_rev(bam) == bam_is_mrev(bam)) { + if (!bam_is_rev(bam)) { + leftmost = this_coord <= other_coord; + } else { + leftmost = this_end <= other_end; + } + } else { + if (bam_is_rev(bam)) { + leftmost = this_end <= other_coord; + } else { + leftmost = this_coord <= other_end; + } + } + } + + // pair orientation + if (leftmost) { + if (bam_is_rev(bam) == bam_is_mrev(bam)) { + other_coord = other_end; + + if (!bam_is_rev(bam)) { + if (bam->core.flag & BAM_FREAD1) { + orientation = O_FF; + } else { + orientation = O_RR; + } + } else { + if (bam->core.flag & BAM_FREAD1) { + orientation = O_RR; + } else { + orientation = O_FF; + } + } + } else { + if (!bam_is_rev(bam)) { + orientation = O_FR; + other_coord = other_end; + } else { + orientation = O_RF; + this_coord = this_end; + } + } + } else { + if (bam_is_rev(bam) == bam_is_mrev(bam)) { + this_coord = this_end; + + if (!bam_is_rev(bam)) { + if (bam->core.flag & BAM_FREAD1) { + orientation = O_RR; + } else { + orientation = O_FF; + } + } else { + if (bam->core.flag & BAM_FREAD1) { + orientation = O_FF; + } else { + orientation = O_RR; + } + } + } else { + if (!bam_is_rev(bam)) { + orientation = O_RF; + other_coord = other_end; + } else { + orientation = O_FR; + this_coord = this_end; + } + } + } + + if (!leftmost) + leftmost = 13; + else + leftmost = 11; + + key->single = 0; + key->this_ref = this_ref; + key->this_coord = this_coord; + key->other_ref = other_ref; + key->other_coord = other_coord; + key->leftmost = leftmost; + key->orientation = orientation; + + return 0; +} + + +/* Create a signature hash of single read (or read with an unmatched pair). + Uses unclipped start (or end depending on orientation), reference id, + and orientation. */ + +static void make_single_key(key_data_t *key, bam1_t *bam) { + int32_t this_ref, this_coord; + int32_t orientation; + + this_ref = bam->core.tid + 1; // avoid a 0 being put into the hash + + if (bam_is_rev(bam)) { + this_coord = unclipped_end(bam); + orientation = O_RR; + } else { + this_coord = unclipped_start(bam); + orientation = O_FF; + } + + key->single = 1; + key->this_ref = this_ref; + key->this_coord = this_coord; + key->orientation = orientation; +} + +/* Add the duplicate name to a hash if it does not exist. */ + +static int add_duplicate(khash_t(duplicates) *d_hash, bam1_t *dupe) { + khiter_t d; + int ret; + + d = kh_get(duplicates, d_hash, bam_get_qname(dupe)); + + if (d == kh_end(d_hash)) { + d = kh_put(duplicates, d_hash, strdup(bam_get_qname(dupe)), &ret); + + if (ret > 0) { + kh_value(d_hash, d) = 1; + } else if (ret == 0) { + kh_value(d_hash, d)++; + } else { + fprintf(stderr, "[markdup] error: unable to store supplementary duplicates.\n"); + return 1; + } + } + + return 0; +} + + +/* Compare the reads near each other (coordinate sorted) and try to spot the duplicates. + Generally the highest quality scoring is chosen as the original and all others the duplicates. + The score is based on the sum of the quality values (<= 15) of the read and its mate (if any). + While single reads are compared to only one read of a pair, the pair will chosen as the original. + The comparison is done on position and orientation, see above for details. + + Marking the supplementary reads of a duplicate as also duplicates takes an extra file read/write + step. This is because the duplicate can occur before the primary read.*/ + +static int bam_mark_duplicates(samFile *in, samFile *out, char *prefix, int remove_dups, int32_t max_length, int do_stats, int supp, int tag) { + bam_hdr_t *header; + khiter_t k; + khash_t(reads) *pair_hash = kh_init(reads); + khash_t(reads) *single_hash = kh_init(reads); + klist_t(read_queue) *read_buffer = kl_init(read_queue); + kliter_t(read_queue) *rq; + khash_t(duplicates) *dup_hash = kh_init(duplicates); + int32_t prev_tid, prev_coord; + read_queue_t *in_read; + int ret; + int reading, writing, excluded, duplicate, single, pair, single_dup, examined; + tmp_file_t temp; + + if ((header = sam_hdr_read(in)) == NULL) { + fprintf(stderr, "[markdup] error reading header\n"); + return 1; + } + + // accept unknown, unsorted or coordinate sort order, but error on queryname sorted. + // only really works on coordinate sorted files. + if ((header->l_text > 3) && (strncmp(header->text, "@HD", 3) == 0)) { + char *p, *q; + + p = strstr(header->text, "\tSO:queryname"); + q = strchr(header->text, '\n'); + + // looking for SO:queryname within @HD only + // (e.g. must ignore in a @CO comment line later in header) + if ((p != 0) && (p < q)) { + fprintf(stderr, "[markdup] error: queryname sorted, must be sorted by coordinate.\n"); + return 1; + } + } + + if (sam_hdr_write(out, header) < 0) { + fprintf(stderr, "[markdup] error writing header.\n"); + return 1; + } + + // used for coordinate order checks + prev_tid = prev_coord = 0; + + // get the buffer going + in_read = kl_pushp(read_queue, read_buffer); + + // handling supplementary reads needs a temporary file + if (supp) { + if (tmp_file_open_write(&temp, prefix, 1)) { + fprintf(stderr, "[markdup] error: unable to open tmp file %s.\n", prefix); + return 1; + } + } + + if ((in_read->b = bam_init1()) == NULL) { + fprintf(stderr, "[markdup] error: unable to allocate memory for alignment.\n"); + return 1; + } + + reading = writing = excluded = single_dup = duplicate = examined = pair = single = 0; + + while ((ret = sam_read1(in, header, in_read->b)) >= 0) { + + // do some basic coordinate order checks + if (in_read->b->core.tid >= 0) { // -1 for unmapped reads + if (in_read->b->core.tid < prev_tid || + ((in_read->b->core.tid == prev_tid) && (in_read->b->core.pos < prev_coord))) { + fprintf(stderr, "[markdup] error: bad coordinate order.\n"); + return 1; + } + } + + prev_coord = in_read->pos = in_read->b->core.pos; + prev_tid = in_read->b->core.tid; + in_read->pair_key.single = 1; + in_read->single_key.single = 0; + + reading++; + + // read must not be secondary, supplementary, unmapped or failed QC + if (!(in_read->b->core.flag & (BAM_FSECONDARY | BAM_FSUPPLEMENTARY | BAM_FUNMAP | BAM_FQCFAIL))) { + examined++; + + + // look at the pairs first + if ((in_read->b->core.flag & BAM_FPAIRED) && !(in_read->b->core.flag & BAM_FMUNMAP)) { + int ret, mate_tmp; + key_data_t pair_key; + key_data_t single_key; + in_hash_t *bp; + + if (make_pair_key(&pair_key, in_read->b)) { + fprintf(stderr, "[markdup] error: unable to assign pair hash key.\n"); + return 1; + } + + make_single_key(&single_key, in_read->b); + + pair++; + in_read->pos = single_key.this_coord; // cigar/orientation modified pos + + // put in singles hash for checking against non paired reads + k = kh_put(reads, single_hash, single_key, &ret); + + if (ret > 0) { // new + // add to single duplicate hash + bp = &kh_val(single_hash, k); + bp->p = in_read->b; + in_read->single_key = single_key; + } else if (ret == 0) { // exists + // look at singles only for duplication marking + bp = &kh_val(single_hash, k); + + if (!(bp->p->core.flag & BAM_FPAIRED) || (bp->p->core.flag & BAM_FMUNMAP)) { + bam1_t *dup = bp->p; + + // singleton will always be marked duplicate even if + // scores more than one read of the pair + + bp->p = in_read->b; + dup->core.flag |= BAM_FDUP; + single_dup++; + + if (tag) { + if (bam_aux_append(dup, "do", 'Z', strlen(bam_get_qname(bp->p)) + 1, (uint8_t*)bam_get_qname(bp->p))) { + fprintf(stderr, "[markdup] error: unable to append 'do' tag.\n"); + return 1; + } + } + + if (supp) { + if (bam_aux_get(dup, "SA") || (dup->core.flag & BAM_FMUNMAP)) { + if (add_duplicate(dup_hash, dup)) { + return 1; + } + } + } + } + } else { + fprintf(stderr, "[markdup] error: single hashing failure.\n"); + return 1; + } + + // now do the pair + k = kh_put(reads, pair_hash, pair_key, &ret); + + if (ret > 0) { // new + // add to the pair hash + bp = &kh_val(pair_hash, k); + bp->p = in_read->b; + in_read->pair_key = pair_key; + } else if (ret == 0) { + int64_t old_score, new_score, tie_add = 0; + bam1_t *dup; + + bp = &kh_val(pair_hash, k); + + if ((mate_tmp = get_mate_score(bp->p)) == -1) { + fprintf(stderr, "[markdup] error: no ms score tag.\n"); + return 1; + } else { + old_score = calc_score(bp->p) + mate_tmp; + } + + if ((mate_tmp = get_mate_score(in_read->b)) == -1) { + fprintf(stderr, "[markdup] error: no ms score tag.\n"); + return 1; + } else { + new_score = calc_score(in_read->b) + mate_tmp; + } + + // choose the highest score as the original + // and add it to the pair hash, mark the other as duplicate + + if (new_score == old_score) { + if (strcmp(bam_get_qname(in_read->b), bam_get_qname(bp->p)) < 0) { + tie_add = 1; + } else { + tie_add = -1; + } + } + + if (new_score + tie_add > old_score) { // swap reads + dup = bp->p; + bp->p = in_read->b; + } else { + dup = in_read->b; + } + + dup->core.flag |= BAM_FDUP; + + if (tag) { + if (bam_aux_append(dup, "do", 'Z', strlen(bam_get_qname(bp->p)) + 1, (uint8_t*)bam_get_qname(bp->p))) { + fprintf(stderr, "[markdup] error: unable to append 'do' tag.\n"); + return 1; + } + + } + + if (supp) { + if (bam_aux_get(dup, "SA") || (dup->core.flag & BAM_FMUNMAP)) { + if (add_duplicate(dup_hash, dup)) { + return 1; + } + } + } + + duplicate++; + } else { + fprintf(stderr, "[markdup] error: pair hashing failure.\n"); + return 1; + } + } else { // do the single (or effectively single) reads + int ret; + key_data_t single_key; + in_hash_t *bp; + + make_single_key(&single_key, in_read->b); + + single++; + in_read->pos = single_key.this_coord; // cigar/orientation modified pos + + k = kh_put(reads, single_hash, single_key, &ret); + + if (ret > 0) { // new + bp = &kh_val(single_hash, k); + bp->p = in_read->b; + in_read->single_key = single_key; + } else if (ret == 0) { // exists + bp = &kh_val(single_hash, k); + + if ((bp->p->core.flag & BAM_FPAIRED) && !(bp->p->core.flag & BAM_FMUNMAP)) { + // if matched against one of a pair just mark as duplicate + + if (tag) { + if (bam_aux_append(in_read->b, "do", 'Z', strlen(bam_get_qname(bp->p)) + 1, (uint8_t*)bam_get_qname(bp->p))) { + fprintf(stderr, "[markdup] error: unable to append 'do' tag.\n"); + return 1; + } + } + + if (supp) { + if (bam_aux_get(in_read->b, "SA") || (in_read->b->core.flag & BAM_FMUNMAP)) { + if (add_duplicate(dup_hash, in_read->b)) { + return 1; + } + } + } + + in_read->b->core.flag |= BAM_FDUP; + } else { + int64_t old_score, new_score; + bam1_t *dup; + + old_score = calc_score(bp->p); + new_score = calc_score(in_read->b); + + // choose the highest score as the original, add it + // to the single hash and mark the other as duplicate + if (new_score > old_score) { // swap reads + dup = bp->p; + bp->p = in_read->b; + } else { + dup = in_read->b; + } + + dup->core.flag |= BAM_FDUP; + + if (tag) { + if (bam_aux_append(dup, "do", 'Z', strlen(bam_get_qname(bp->p)) + 1, (uint8_t*)bam_get_qname(bp->p))) { + fprintf(stderr, "[markdup] error: unable to append 'do' tag.\n"); + return 1; + } + } + + if (supp) { + if (bam_aux_get(dup, "SA") || (dup->core.flag & BAM_FMUNMAP)) { + if (add_duplicate(dup_hash, dup)) { + return 1; + } + } + } + } + + single_dup++; + } else { + fprintf(stderr, "[markdup] error: single hashing failure.\n"); + return 1; + } + } + } else { + excluded++; + } + + // loop through the stored reads and write out those we + // no longer need + rq = kl_begin(read_buffer); + while (rq != kl_end(read_buffer)) { + in_read = &kl_val(rq); + + /* keep a moving window of reads based on coordinates and max read length. Any unaligned reads + should just be written as they cannot be matched as duplicates. */ + if (in_read->pos + max_length > prev_coord && in_read->b->core.tid == prev_tid && (prev_tid != -1 || prev_coord != -1)) { + break; + } + + if (!remove_dups || !(in_read->b->core.flag & BAM_FDUP)) { + if (supp) { + if (tmp_file_write(&temp, in_read->b)) { + fprintf(stderr, "[markdup] error: writing temp output failed.\n"); + return 1; + } + } else { + if (sam_write1(out, header, in_read->b) < 0) { + fprintf(stderr, "[markdup] error: writing output failed.\n"); + return 1; + } + } + + writing++; + } + + // remove from hash + if (in_read->pair_key.single == 0) { + k = kh_get(reads, pair_hash, in_read->pair_key); + kh_del(reads, pair_hash, k); + } + + if (in_read->single_key.single == 1) { + k = kh_get(reads, single_hash, in_read->single_key); + kh_del(reads, single_hash, k); + } + + kl_shift(read_queue, read_buffer, NULL); + bam_destroy1(in_read->b); + rq = kl_begin(read_buffer); + } + + // set the next one up for reading + in_read = kl_pushp(read_queue, read_buffer); + + if ((in_read->b = bam_init1()) == NULL) { + fprintf(stderr, "[markdup] error: unable to allocate memory for alignment.\n"); + return 1; + } + } + + if (ret < -1) { + fprintf(stderr, "[markdup] error: truncated input file.\n"); + return 1; + } + + // write out the end of the list + rq = kl_begin(read_buffer); + while (rq != kl_end(read_buffer)) { + in_read = &kl_val(rq); + + if (bam_get_qname(in_read->b)) { // last entry will be blank + if (!remove_dups || !(in_read->b->core.flag & BAM_FDUP)) { + if (supp) { + if (tmp_file_write(&temp, in_read->b)) { + fprintf(stderr, "[markdup] error: writing temp output failed.\n"); + return 1; + } + } else { + if (sam_write1(out, header, in_read->b) < 0) { + fprintf(stderr, "[markdup] error: writing output failed.\n"); + return 1; + } + } + + writing++; + } + } + + kl_shift(read_queue, read_buffer, NULL); + bam_destroy1(in_read->b); + rq = kl_begin(read_buffer); + } + + if (supp) { + bam1_t *b; + + if (tmp_file_end_write(&temp)) { + fprintf(stderr, "[markdup] error: unable to end tmp writing.\n"); + return 1; + } + + // read data from temp file and mark duplicate supplementary alignments + + if (tmp_file_begin_read(&temp, NULL)) { + return 1; + } + + b = bam_init1(); + + while ((ret = tmp_file_read(&temp, b)) > 0) { + + if ((b->core.flag & BAM_FSUPPLEMENTARY) || (b->core.flag & BAM_FUNMAP)) { + k = kh_get(duplicates, dup_hash, bam_get_qname(b)); + + if (k != kh_end(dup_hash)) { + b->core.flag |= BAM_FDUP; + } + } + + if (!remove_dups || !(b->core.flag & BAM_FDUP)) { + if (sam_write1(out, header, b) < 0) { + fprintf(stderr, "[markdup] error: writing final output failed.\n"); + return 1; + } + } + } + + if (ret == -1) { + fprintf(stderr, "[markdup] error: failed to read tmp file.\n"); + return 1; + } + + for (k = kh_begin(dup_hash); k != kh_end(dup_hash); ++k) { + if (kh_exist(dup_hash, k)) { + free((char *)kh_key(dup_hash, k)); + } + } + + tmp_file_destroy(&temp, b, 0); + kh_destroy(duplicates, dup_hash); + bam_destroy1(b); + } + + if (do_stats) { + fprintf(stderr, "READ %d WRITTEN %d \n" + "EXCLUDED %d EXAMINED %d\n" + "PAIRED %d SINGLE %d\n" + "DULPICATE PAIR %d DUPLICATE SINGLE %d\n" + "DUPLICATE TOTAL %d\n", reading, writing, excluded, examined, pair, single, + duplicate, single_dup, single_dup + duplicate); + } + + kh_destroy(reads, pair_hash); + kh_destroy(reads, single_hash); + kl_destroy(read_queue, read_buffer); + bam_hdr_destroy(header); + + return 0; +} + + +static int markdup_usage(void) { + fprintf(stderr, "\n"); + fprintf(stderr, "Usage: samtools markdup \n\n"); + fprintf(stderr, "Option: \n"); + fprintf(stderr, " -r Remove duplicate reads\n"); + fprintf(stderr, " -l INT Max read length (default 300 bases)\n"); + fprintf(stderr, " -S Mark supplemenary alignments of duplicates as duplicates (slower).\n"); + fprintf(stderr, " -s Report stats.\n"); + fprintf(stderr, " -T PREFIX Write temporary files to PREFIX.samtools.nnnn.nnnn.tmp.\n"); + fprintf(stderr, " -t Mark primary duplicates with the name of the original in a \'do\' tag." + " Mainly for information and debugging.\n"); + + sam_global_opt_help(stderr, "-.O..@"); + + fprintf(stderr, "\nThe input file must be coordinate sorted and must have gone" + " through fixmates with the mate scoring option on.\n"); + + return 1; +} + + +int bam_markdup(int argc, char **argv) { + int c, ret, remove_dups = 0, report_stats = 0, include_supplementary = 0, tag_dup = 0; + int32_t max_length = 300; + samFile *in = NULL, *out = NULL; + char wmode[3] = {'w', 'b', 0}; + sam_global_args ga = SAM_GLOBAL_ARGS_INIT; + htsThreadPool p = {NULL, 0}; + kstring_t tmpprefix = {0, 0, NULL}; + struct stat st; + unsigned int t; + + static const struct option lopts[] = { + SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0, '@'), + {NULL, 0, NULL, 0} + }; + + while ((c = getopt_long(argc, argv, "rsl:StT:O:@:", lopts, NULL)) >= 0) { + switch (c) { + case 'r': remove_dups = 1; break; + case 'l': max_length = atoi(optarg); break; + case 's': report_stats = 1; break; + case 'T': kputs(optarg, &tmpprefix); break; + case 'S': include_supplementary = 1; break; + case 't': tag_dup = 1; break; + default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; + /* else fall-through */ + case '?': return markdup_usage(); + } + } + + if (optind + 2 > argc) + return markdup_usage(); + + in = sam_open_format(argv[optind], "r", &ga.in); + + if (!in) { + print_error_errno("markdup", "failed to open \"%s\" for input", argv[optind]); + return 1; + } + + sam_open_mode(wmode + 1, argv[optind + 1], NULL); + out = sam_open_format(argv[optind + 1], wmode, &ga.out); + + if (!out) { + print_error_errno("markdup", "failed to open \"%s\" for output", argv[optind + 1]); + return 1; + } + + if (ga.nthreads > 0) { + if (!(p.pool = hts_tpool_init(ga.nthreads))) { + fprintf(stderr, "[markdup] error creating thread pool\n"); + return 1; + } + + hts_set_opt(in, HTS_OPT_THREAD_POOL, &p); + hts_set_opt(out, HTS_OPT_THREAD_POOL, &p); + } + + // actual stuff happens here + + // we need temp files so fix up the name here + if (tmpprefix.l == 0) { + + if (strcmp(argv[optind + 1], "-") != 0) + ksprintf(&tmpprefix, "%s.", argv[optind + 1]); + else + kputc('.', &tmpprefix); + } + + if (stat(tmpprefix.s, &st) == 0 && S_ISDIR(st.st_mode)) { + if (tmpprefix.s[tmpprefix.l-1] != '/') kputc('/', &tmpprefix); + } + + t = ((unsigned) time(NULL)) ^ ((unsigned) clock()); + ksprintf(&tmpprefix, "samtools.%d.%u.tmp", (int) getpid(), t % 10000); + + ret = bam_mark_duplicates(in, out, tmpprefix.s, remove_dups, max_length, report_stats, include_supplementary, tag_dup); + + sam_close(in); + + if (sam_close(out) < 0) { + fprintf(stderr, "[markdup] error closing output file\n"); + ret = 1; + } + + if (p.pool) hts_tpool_destroy(p.pool); + + free(tmpprefix.s); + sam_global_args_free(&ga); + + return ret; +} diff --git a/samtools/bam_markdup.c.pysam.c b/samtools/bam_markdup.c.pysam.c new file mode 100644 index 000000000..ce621d3bf --- /dev/null +++ b/samtools/bam_markdup.c.pysam.c @@ -0,0 +1,1041 @@ +#include "samtools.pysam.h" + +/* bam_markdup.c -- Mark duplicates from a coord sorted file that has gone + through fixmates with the mate scoring option on. + + Copyright (C) 2017 Genome Research Ltd. + + Author: Andrew Whitwham + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include "htslib/thread_pool.h" +#include "htslib/sam.h" +#include "sam_opts.h" +#include "samtools.h" +#include "htslib/khash.h" +#include "htslib/klist.h" +#include "htslib/kstring.h" +#include "tmp_file.h" + +typedef struct { + int32_t single; + int32_t this_ref; + int32_t this_coord; + int32_t other_ref; + int32_t other_coord; + int32_t leftmost; + int32_t orientation; +} key_data_t; + +typedef struct { + bam1_t *p; +} in_hash_t; + +typedef struct { + bam1_t *b; + int32_t pos; + key_data_t pair_key; + key_data_t single_key; +} read_queue_t; + + + +static khint32_t do_hash(unsigned char *key, khint32_t len); + +static khint_t hash_key(key_data_t key) { + int i = 0; + khint_t hash; + + if (key.single) { + unsigned char sig[12]; + + memcpy(sig + i, &key.this_ref, 4); i += 4; + memcpy(sig + i, &key.this_coord, 4); i += 4; + memcpy(sig + i, &key.orientation, 4); i += 4; + + hash = do_hash(sig, i); + } else { + unsigned char sig[24]; + + memcpy(sig + i, &key.this_ref, 4); i += 4; + memcpy(sig + i, &key.this_coord, 4); i += 4; + memcpy(sig + i, &key.other_ref, 4); i += 4; + memcpy(sig + i, &key.other_coord, 4); i += 4; + memcpy(sig + i, &key.leftmost, 4); i += 4; + memcpy(sig + i, &key.orientation, 4); i += 4; + + hash = do_hash(sig, i); + } + + return hash; +} + + +static int key_equal(key_data_t a, key_data_t b) { + int match = 1; + + if (a.this_coord != b.this_coord) + match = 0; + else if (a.orientation != b.orientation) + match = 0; + else if (a.this_ref != b.this_ref) + match = 0; + else if (a.single != b.single) + match = 0; + + if (!a.single) { + if (a.other_coord != b.other_coord) + match = 0; + else if (a.leftmost != b.leftmost) + match = 0; + else if (a.other_ref != b.other_ref) + match = 0; + } + + return match; +} + + +#define __free_queue_element(p) +#define O_FF 2 +#define O_RR 3 +#define O_FR 5 +#define O_RF 7 + +KHASH_INIT(reads, key_data_t, in_hash_t, 1, hash_key, key_equal) // read map hash +KLIST_INIT(read_queue, read_queue_t, __free_queue_element) // the reads buffer +KHASH_MAP_INIT_STR(duplicates, int) // map of duplicates for supplementary dup id + + +/* Calculate the mate's unclipped start based on position and cigar string from MC tag. */ + +static int32_t unclipped_other_start(int32_t op, char *cigar) { + char *c = cigar; + int32_t clipped = 0; + + while (*c && *c != '*') { + long num = 0; + + if (isdigit((int)*c)) { + num = strtol(c, &c, 10); + } else { + num = 1; + } + + if (*c == 'S' || *c == 'H') { // clips + clipped += num; + } else { + break; + } + + c++; + } + + return op - clipped + 1; +} + + +/* Calculate the current read's start based on the stored cigar string. */ + +static int32_t unclipped_start(bam1_t *b) { + uint32_t *cigar = bam_get_cigar(b); + int32_t clipped = 0; + uint32_t i; + + for (i = 0; i < b->core.n_cigar; i++) { + char c = bam_cigar_opchr(cigar[i]); + + if (c == 'S' || c == 'H') { // clips + clipped += bam_cigar_oplen(cigar[i]); + } else { + break; + } + } + + return b->core.pos - clipped + 1; +} + + +/* Calculate the mate's unclipped end based on start position and cigar string from MC tag.*/ + +static int32_t unclipped_other_end(int32_t op, char *cigar) { + char *c = cigar; + int32_t refpos = 0; + int skip = 1; + + while (*c && *c != '*') { + long num = 0; + + if (isdigit((int)*c)) { + num = strtol(c, &c, 10); + } else { + num = 1; + } + + switch (*c) { + case 'M': + case 'D': + case 'N': + case '=': + case 'X': + refpos += num; + skip = 0; // ignore initial clips + break; + + case 'S': + case 'H': + if (!skip) { + refpos += num; + } + break; + } + + c++; + } + + return op + refpos; +} + + +/* Calculate the current read's end based on the stored cigar string. */ + +static int32_t unclipped_end(bam1_t *b) { + uint32_t *cigar = bam_get_cigar(b); + int32_t end_pos, clipped = 0; + int32_t i; + + end_pos = bam_endpos(b); + + // now get the clipped end bases (if any) + // if we get to the beginning of the cigar string + // without hitting a non-clip then the results are meaningless + for (i = b->core.n_cigar - 1; i >= 0; i--) { + char c = bam_cigar_opchr(cigar[i]); + + if (c == 'S' || c == 'H') { // clips + clipped += bam_cigar_oplen(cigar[i]); + } else { + break; + } + } + + return end_pos + clipped; +} + + +/* The Bob Jenkins one_at_a_time hash to reduce the key to a 32 bit value. */ + +static khint32_t do_hash(unsigned char *key, khint32_t len) { + khint32_t hash, i; + + for (hash = 0, i = 0; i < len; ++i) { + hash += key[i]; + hash += (hash << 10); + hash ^= (hash >> 6); + } + + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + + return hash; +} + + +/* Get mate score from tag. */ + +static int64_t get_mate_score(bam1_t *b) { + uint8_t *data; + int64_t score; + + if ((data = bam_aux_get(b, "ms"))) { + score = bam_aux2i(data); + } else { + fprintf(samtools_stderr, "[markdup] error: no ms score tag.\n"); + return -1; + } + + return score; +} + + +/* Calc current score from quality. */ + +static int64_t calc_score(bam1_t *b) +{ + int64_t score = 0; + uint8_t *qual = bam_get_qual(b); + int i; + + for (i = 0; i < b->core.l_qseq; i++) { + if (qual[i] >= 15) score += qual[i]; + } + + return score; +} + + +/* Create a signature hash of the current read and its pair. + Uses the unclipped start (or end depending on orientation), + the reference id, orientation and whether the current + read is leftmost of the pair. */ + +static int make_pair_key(key_data_t *key, bam1_t *bam) { + int32_t this_ref, this_coord, this_end; + int32_t other_ref, other_coord, other_end; + int32_t orientation, leftmost; + uint8_t *data; + char *cig; + + this_ref = bam->core.tid + 1; // avoid a 0 being put into the hash + other_ref = bam->core.mtid + 1; + + this_coord = unclipped_start(bam); + this_end = unclipped_end(bam); + + if ((data = bam_aux_get(bam, "MC"))) { + cig = bam_aux2Z(data); + other_end = unclipped_other_end(bam->core.mpos, cig); + other_coord = unclipped_other_start(bam->core.mpos, cig); + } else { + fprintf(samtools_stderr, "[markdup] error: no MC tag.\n"); + return 1; + } + + // work out orientations + if (this_ref != other_ref) { + leftmost = this_ref < other_ref; + } else { + if (bam_is_rev(bam) == bam_is_mrev(bam)) { + if (!bam_is_rev(bam)) { + leftmost = this_coord <= other_coord; + } else { + leftmost = this_end <= other_end; + } + } else { + if (bam_is_rev(bam)) { + leftmost = this_end <= other_coord; + } else { + leftmost = this_coord <= other_end; + } + } + } + + // pair orientation + if (leftmost) { + if (bam_is_rev(bam) == bam_is_mrev(bam)) { + other_coord = other_end; + + if (!bam_is_rev(bam)) { + if (bam->core.flag & BAM_FREAD1) { + orientation = O_FF; + } else { + orientation = O_RR; + } + } else { + if (bam->core.flag & BAM_FREAD1) { + orientation = O_RR; + } else { + orientation = O_FF; + } + } + } else { + if (!bam_is_rev(bam)) { + orientation = O_FR; + other_coord = other_end; + } else { + orientation = O_RF; + this_coord = this_end; + } + } + } else { + if (bam_is_rev(bam) == bam_is_mrev(bam)) { + this_coord = this_end; + + if (!bam_is_rev(bam)) { + if (bam->core.flag & BAM_FREAD1) { + orientation = O_RR; + } else { + orientation = O_FF; + } + } else { + if (bam->core.flag & BAM_FREAD1) { + orientation = O_FF; + } else { + orientation = O_RR; + } + } + } else { + if (!bam_is_rev(bam)) { + orientation = O_RF; + other_coord = other_end; + } else { + orientation = O_FR; + this_coord = this_end; + } + } + } + + if (!leftmost) + leftmost = 13; + else + leftmost = 11; + + key->single = 0; + key->this_ref = this_ref; + key->this_coord = this_coord; + key->other_ref = other_ref; + key->other_coord = other_coord; + key->leftmost = leftmost; + key->orientation = orientation; + + return 0; +} + + +/* Create a signature hash of single read (or read with an unmatched pair). + Uses unclipped start (or end depending on orientation), reference id, + and orientation. */ + +static void make_single_key(key_data_t *key, bam1_t *bam) { + int32_t this_ref, this_coord; + int32_t orientation; + + this_ref = bam->core.tid + 1; // avoid a 0 being put into the hash + + if (bam_is_rev(bam)) { + this_coord = unclipped_end(bam); + orientation = O_RR; + } else { + this_coord = unclipped_start(bam); + orientation = O_FF; + } + + key->single = 1; + key->this_ref = this_ref; + key->this_coord = this_coord; + key->orientation = orientation; +} + +/* Add the duplicate name to a hash if it does not exist. */ + +static int add_duplicate(khash_t(duplicates) *d_hash, bam1_t *dupe) { + khiter_t d; + int ret; + + d = kh_get(duplicates, d_hash, bam_get_qname(dupe)); + + if (d == kh_end(d_hash)) { + d = kh_put(duplicates, d_hash, strdup(bam_get_qname(dupe)), &ret); + + if (ret > 0) { + kh_value(d_hash, d) = 1; + } else if (ret == 0) { + kh_value(d_hash, d)++; + } else { + fprintf(samtools_stderr, "[markdup] error: unable to store supplementary duplicates.\n"); + return 1; + } + } + + return 0; +} + + +/* Compare the reads near each other (coordinate sorted) and try to spot the duplicates. + Generally the highest quality scoring is chosen as the original and all others the duplicates. + The score is based on the sum of the quality values (<= 15) of the read and its mate (if any). + While single reads are compared to only one read of a pair, the pair will chosen as the original. + The comparison is done on position and orientation, see above for details. + + Marking the supplementary reads of a duplicate as also duplicates takes an extra file read/write + step. This is because the duplicate can occur before the primary read.*/ + +static int bam_mark_duplicates(samFile *in, samFile *out, char *prefix, int remove_dups, int32_t max_length, int do_stats, int supp, int tag) { + bam_hdr_t *header; + khiter_t k; + khash_t(reads) *pair_hash = kh_init(reads); + khash_t(reads) *single_hash = kh_init(reads); + klist_t(read_queue) *read_buffer = kl_init(read_queue); + kliter_t(read_queue) *rq; + khash_t(duplicates) *dup_hash = kh_init(duplicates); + int32_t prev_tid, prev_coord; + read_queue_t *in_read; + int ret; + int reading, writing, excluded, duplicate, single, pair, single_dup, examined; + tmp_file_t temp; + + if ((header = sam_hdr_read(in)) == NULL) { + fprintf(samtools_stderr, "[markdup] error reading header\n"); + return 1; + } + + // accept unknown, unsorted or coordinate sort order, but error on queryname sorted. + // only really works on coordinate sorted files. + if ((header->l_text > 3) && (strncmp(header->text, "@HD", 3) == 0)) { + char *p, *q; + + p = strstr(header->text, "\tSO:queryname"); + q = strchr(header->text, '\n'); + + // looking for SO:queryname within @HD only + // (e.g. must ignore in a @CO comment line later in header) + if ((p != 0) && (p < q)) { + fprintf(samtools_stderr, "[markdup] error: queryname sorted, must be sorted by coordinate.\n"); + return 1; + } + } + + if (sam_hdr_write(out, header) < 0) { + fprintf(samtools_stderr, "[markdup] error writing header.\n"); + return 1; + } + + // used for coordinate order checks + prev_tid = prev_coord = 0; + + // get the buffer going + in_read = kl_pushp(read_queue, read_buffer); + + // handling supplementary reads needs a temporary file + if (supp) { + if (tmp_file_open_write(&temp, prefix, 1)) { + fprintf(samtools_stderr, "[markdup] error: unable to open tmp file %s.\n", prefix); + return 1; + } + } + + if ((in_read->b = bam_init1()) == NULL) { + fprintf(samtools_stderr, "[markdup] error: unable to allocate memory for alignment.\n"); + return 1; + } + + reading = writing = excluded = single_dup = duplicate = examined = pair = single = 0; + + while ((ret = sam_read1(in, header, in_read->b)) >= 0) { + + // do some basic coordinate order checks + if (in_read->b->core.tid >= 0) { // -1 for unmapped reads + if (in_read->b->core.tid < prev_tid || + ((in_read->b->core.tid == prev_tid) && (in_read->b->core.pos < prev_coord))) { + fprintf(samtools_stderr, "[markdup] error: bad coordinate order.\n"); + return 1; + } + } + + prev_coord = in_read->pos = in_read->b->core.pos; + prev_tid = in_read->b->core.tid; + in_read->pair_key.single = 1; + in_read->single_key.single = 0; + + reading++; + + // read must not be secondary, supplementary, unmapped or failed QC + if (!(in_read->b->core.flag & (BAM_FSECONDARY | BAM_FSUPPLEMENTARY | BAM_FUNMAP | BAM_FQCFAIL))) { + examined++; + + + // look at the pairs first + if ((in_read->b->core.flag & BAM_FPAIRED) && !(in_read->b->core.flag & BAM_FMUNMAP)) { + int ret, mate_tmp; + key_data_t pair_key; + key_data_t single_key; + in_hash_t *bp; + + if (make_pair_key(&pair_key, in_read->b)) { + fprintf(samtools_stderr, "[markdup] error: unable to assign pair hash key.\n"); + return 1; + } + + make_single_key(&single_key, in_read->b); + + pair++; + in_read->pos = single_key.this_coord; // cigar/orientation modified pos + + // put in singles hash for checking against non paired reads + k = kh_put(reads, single_hash, single_key, &ret); + + if (ret > 0) { // new + // add to single duplicate hash + bp = &kh_val(single_hash, k); + bp->p = in_read->b; + in_read->single_key = single_key; + } else if (ret == 0) { // exists + // look at singles only for duplication marking + bp = &kh_val(single_hash, k); + + if (!(bp->p->core.flag & BAM_FPAIRED) || (bp->p->core.flag & BAM_FMUNMAP)) { + bam1_t *dup = bp->p; + + // singleton will always be marked duplicate even if + // scores more than one read of the pair + + bp->p = in_read->b; + dup->core.flag |= BAM_FDUP; + single_dup++; + + if (tag) { + if (bam_aux_append(dup, "do", 'Z', strlen(bam_get_qname(bp->p)) + 1, (uint8_t*)bam_get_qname(bp->p))) { + fprintf(samtools_stderr, "[markdup] error: unable to append 'do' tag.\n"); + return 1; + } + } + + if (supp) { + if (bam_aux_get(dup, "SA") || (dup->core.flag & BAM_FMUNMAP)) { + if (add_duplicate(dup_hash, dup)) { + return 1; + } + } + } + } + } else { + fprintf(samtools_stderr, "[markdup] error: single hashing failure.\n"); + return 1; + } + + // now do the pair + k = kh_put(reads, pair_hash, pair_key, &ret); + + if (ret > 0) { // new + // add to the pair hash + bp = &kh_val(pair_hash, k); + bp->p = in_read->b; + in_read->pair_key = pair_key; + } else if (ret == 0) { + int64_t old_score, new_score, tie_add = 0; + bam1_t *dup; + + bp = &kh_val(pair_hash, k); + + if ((mate_tmp = get_mate_score(bp->p)) == -1) { + fprintf(samtools_stderr, "[markdup] error: no ms score tag.\n"); + return 1; + } else { + old_score = calc_score(bp->p) + mate_tmp; + } + + if ((mate_tmp = get_mate_score(in_read->b)) == -1) { + fprintf(samtools_stderr, "[markdup] error: no ms score tag.\n"); + return 1; + } else { + new_score = calc_score(in_read->b) + mate_tmp; + } + + // choose the highest score as the original + // and add it to the pair hash, mark the other as duplicate + + if (new_score == old_score) { + if (strcmp(bam_get_qname(in_read->b), bam_get_qname(bp->p)) < 0) { + tie_add = 1; + } else { + tie_add = -1; + } + } + + if (new_score + tie_add > old_score) { // swap reads + dup = bp->p; + bp->p = in_read->b; + } else { + dup = in_read->b; + } + + dup->core.flag |= BAM_FDUP; + + if (tag) { + if (bam_aux_append(dup, "do", 'Z', strlen(bam_get_qname(bp->p)) + 1, (uint8_t*)bam_get_qname(bp->p))) { + fprintf(samtools_stderr, "[markdup] error: unable to append 'do' tag.\n"); + return 1; + } + + } + + if (supp) { + if (bam_aux_get(dup, "SA") || (dup->core.flag & BAM_FMUNMAP)) { + if (add_duplicate(dup_hash, dup)) { + return 1; + } + } + } + + duplicate++; + } else { + fprintf(samtools_stderr, "[markdup] error: pair hashing failure.\n"); + return 1; + } + } else { // do the single (or effectively single) reads + int ret; + key_data_t single_key; + in_hash_t *bp; + + make_single_key(&single_key, in_read->b); + + single++; + in_read->pos = single_key.this_coord; // cigar/orientation modified pos + + k = kh_put(reads, single_hash, single_key, &ret); + + if (ret > 0) { // new + bp = &kh_val(single_hash, k); + bp->p = in_read->b; + in_read->single_key = single_key; + } else if (ret == 0) { // exists + bp = &kh_val(single_hash, k); + + if ((bp->p->core.flag & BAM_FPAIRED) && !(bp->p->core.flag & BAM_FMUNMAP)) { + // if matched against one of a pair just mark as duplicate + + if (tag) { + if (bam_aux_append(in_read->b, "do", 'Z', strlen(bam_get_qname(bp->p)) + 1, (uint8_t*)bam_get_qname(bp->p))) { + fprintf(samtools_stderr, "[markdup] error: unable to append 'do' tag.\n"); + return 1; + } + } + + if (supp) { + if (bam_aux_get(in_read->b, "SA") || (in_read->b->core.flag & BAM_FMUNMAP)) { + if (add_duplicate(dup_hash, in_read->b)) { + return 1; + } + } + } + + in_read->b->core.flag |= BAM_FDUP; + } else { + int64_t old_score, new_score; + bam1_t *dup; + + old_score = calc_score(bp->p); + new_score = calc_score(in_read->b); + + // choose the highest score as the original, add it + // to the single hash and mark the other as duplicate + if (new_score > old_score) { // swap reads + dup = bp->p; + bp->p = in_read->b; + } else { + dup = in_read->b; + } + + dup->core.flag |= BAM_FDUP; + + if (tag) { + if (bam_aux_append(dup, "do", 'Z', strlen(bam_get_qname(bp->p)) + 1, (uint8_t*)bam_get_qname(bp->p))) { + fprintf(samtools_stderr, "[markdup] error: unable to append 'do' tag.\n"); + return 1; + } + } + + if (supp) { + if (bam_aux_get(dup, "SA") || (dup->core.flag & BAM_FMUNMAP)) { + if (add_duplicate(dup_hash, dup)) { + return 1; + } + } + } + } + + single_dup++; + } else { + fprintf(samtools_stderr, "[markdup] error: single hashing failure.\n"); + return 1; + } + } + } else { + excluded++; + } + + // loop through the stored reads and write out those we + // no longer need + rq = kl_begin(read_buffer); + while (rq != kl_end(read_buffer)) { + in_read = &kl_val(rq); + + /* keep a moving window of reads based on coordinates and max read length. Any unaligned reads + should just be written as they cannot be matched as duplicates. */ + if (in_read->pos + max_length > prev_coord && in_read->b->core.tid == prev_tid && (prev_tid != -1 || prev_coord != -1)) { + break; + } + + if (!remove_dups || !(in_read->b->core.flag & BAM_FDUP)) { + if (supp) { + if (tmp_file_write(&temp, in_read->b)) { + fprintf(samtools_stderr, "[markdup] error: writing temp output failed.\n"); + return 1; + } + } else { + if (sam_write1(out, header, in_read->b) < 0) { + fprintf(samtools_stderr, "[markdup] error: writing output failed.\n"); + return 1; + } + } + + writing++; + } + + // remove from hash + if (in_read->pair_key.single == 0) { + k = kh_get(reads, pair_hash, in_read->pair_key); + kh_del(reads, pair_hash, k); + } + + if (in_read->single_key.single == 1) { + k = kh_get(reads, single_hash, in_read->single_key); + kh_del(reads, single_hash, k); + } + + kl_shift(read_queue, read_buffer, NULL); + bam_destroy1(in_read->b); + rq = kl_begin(read_buffer); + } + + // set the next one up for reading + in_read = kl_pushp(read_queue, read_buffer); + + if ((in_read->b = bam_init1()) == NULL) { + fprintf(samtools_stderr, "[markdup] error: unable to allocate memory for alignment.\n"); + return 1; + } + } + + if (ret < -1) { + fprintf(samtools_stderr, "[markdup] error: truncated input file.\n"); + return 1; + } + + // write out the end of the list + rq = kl_begin(read_buffer); + while (rq != kl_end(read_buffer)) { + in_read = &kl_val(rq); + + if (bam_get_qname(in_read->b)) { // last entry will be blank + if (!remove_dups || !(in_read->b->core.flag & BAM_FDUP)) { + if (supp) { + if (tmp_file_write(&temp, in_read->b)) { + fprintf(samtools_stderr, "[markdup] error: writing temp output failed.\n"); + return 1; + } + } else { + if (sam_write1(out, header, in_read->b) < 0) { + fprintf(samtools_stderr, "[markdup] error: writing output failed.\n"); + return 1; + } + } + + writing++; + } + } + + kl_shift(read_queue, read_buffer, NULL); + bam_destroy1(in_read->b); + rq = kl_begin(read_buffer); + } + + if (supp) { + bam1_t *b; + + if (tmp_file_end_write(&temp)) { + fprintf(samtools_stderr, "[markdup] error: unable to end tmp writing.\n"); + return 1; + } + + // read data from temp file and mark duplicate supplementary alignments + + if (tmp_file_begin_read(&temp, NULL)) { + return 1; + } + + b = bam_init1(); + + while ((ret = tmp_file_read(&temp, b)) > 0) { + + if ((b->core.flag & BAM_FSUPPLEMENTARY) || (b->core.flag & BAM_FUNMAP)) { + k = kh_get(duplicates, dup_hash, bam_get_qname(b)); + + if (k != kh_end(dup_hash)) { + b->core.flag |= BAM_FDUP; + } + } + + if (!remove_dups || !(b->core.flag & BAM_FDUP)) { + if (sam_write1(out, header, b) < 0) { + fprintf(samtools_stderr, "[markdup] error: writing final output failed.\n"); + return 1; + } + } + } + + if (ret == -1) { + fprintf(samtools_stderr, "[markdup] error: failed to read tmp file.\n"); + return 1; + } + + for (k = kh_begin(dup_hash); k != kh_end(dup_hash); ++k) { + if (kh_exist(dup_hash, k)) { + free((char *)kh_key(dup_hash, k)); + } + } + + tmp_file_destroy(&temp, b, 0); + kh_destroy(duplicates, dup_hash); + bam_destroy1(b); + } + + if (do_stats) { + fprintf(samtools_stderr, "READ %d WRITTEN %d \n" + "EXCLUDED %d EXAMINED %d\n" + "PAIRED %d SINGLE %d\n" + "DULPICATE PAIR %d DUPLICATE SINGLE %d\n" + "DUPLICATE TOTAL %d\n", reading, writing, excluded, examined, pair, single, + duplicate, single_dup, single_dup + duplicate); + } + + kh_destroy(reads, pair_hash); + kh_destroy(reads, single_hash); + kl_destroy(read_queue, read_buffer); + bam_hdr_destroy(header); + + return 0; +} + + +static int markdup_usage(void) { + fprintf(samtools_stderr, "\n"); + fprintf(samtools_stderr, "Usage: samtools markdup \n\n"); + fprintf(samtools_stderr, "Option: \n"); + fprintf(samtools_stderr, " -r Remove duplicate reads\n"); + fprintf(samtools_stderr, " -l INT Max read length (default 300 bases)\n"); + fprintf(samtools_stderr, " -S Mark supplemenary alignments of duplicates as duplicates (slower).\n"); + fprintf(samtools_stderr, " -s Report stats.\n"); + fprintf(samtools_stderr, " -T PREFIX Write temporary files to PREFIX.samtools.nnnn.nnnn.tmp.\n"); + fprintf(samtools_stderr, " -t Mark primary duplicates with the name of the original in a \'do\' tag." + " Mainly for information and debugging.\n"); + + sam_global_opt_help(samtools_stderr, "-.O..@"); + + fprintf(samtools_stderr, "\nThe input file must be coordinate sorted and must have gone" + " through fixmates with the mate scoring option on.\n"); + + return 1; +} + + +int bam_markdup(int argc, char **argv) { + int c, ret, remove_dups = 0, report_stats = 0, include_supplementary = 0, tag_dup = 0; + int32_t max_length = 300; + samFile *in = NULL, *out = NULL; + char wmode[3] = {'w', 'b', 0}; + sam_global_args ga = SAM_GLOBAL_ARGS_INIT; + htsThreadPool p = {NULL, 0}; + kstring_t tmpprefix = {0, 0, NULL}; + struct stat st; + unsigned int t; + + static const struct option lopts[] = { + SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0, '@'), + {NULL, 0, NULL, 0} + }; + + while ((c = getopt_long(argc, argv, "rsl:StT:O:@:", lopts, NULL)) >= 0) { + switch (c) { + case 'r': remove_dups = 1; break; + case 'l': max_length = atoi(optarg); break; + case 's': report_stats = 1; break; + case 'T': kputs(optarg, &tmpprefix); break; + case 'S': include_supplementary = 1; break; + case 't': tag_dup = 1; break; + default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; + /* else fall-through */ + case '?': return markdup_usage(); + } + } + + if (optind + 2 > argc) + return markdup_usage(); + + in = sam_open_format(argv[optind], "r", &ga.in); + + if (!in) { + print_error_errno("markdup", "failed to open \"%s\" for input", argv[optind]); + return 1; + } + + sam_open_mode(wmode + 1, argv[optind + 1], NULL); + out = sam_open_format(argv[optind + 1], wmode, &ga.out); + + if (!out) { + print_error_errno("markdup", "failed to open \"%s\" for output", argv[optind + 1]); + return 1; + } + + if (ga.nthreads > 0) { + if (!(p.pool = hts_tpool_init(ga.nthreads))) { + fprintf(samtools_stderr, "[markdup] error creating thread pool\n"); + return 1; + } + + hts_set_opt(in, HTS_OPT_THREAD_POOL, &p); + hts_set_opt(out, HTS_OPT_THREAD_POOL, &p); + } + + // actual stuff happens here + + // we need temp files so fix up the name here + if (tmpprefix.l == 0) { + + if (strcmp(argv[optind + 1], "-") != 0) + ksprintf(&tmpprefix, "%s.", argv[optind + 1]); + else + kputc('.', &tmpprefix); + } + + if (stat(tmpprefix.s, &st) == 0 && S_ISDIR(st.st_mode)) { + if (tmpprefix.s[tmpprefix.l-1] != '/') kputc('/', &tmpprefix); + } + + t = ((unsigned) time(NULL)) ^ ((unsigned) clock()); + ksprintf(&tmpprefix, "samtools.%d.%u.tmp", (int) getpid(), t % 10000); + + ret = bam_mark_duplicates(in, out, tmpprefix.s, remove_dups, max_length, report_stats, include_supplementary, tag_dup); + + sam_close(in); + + if (sam_close(out) < 0) { + fprintf(samtools_stderr, "[markdup] error closing output file\n"); + ret = 1; + } + + if (p.pool) hts_tpool_destroy(p.pool); + + free(tmpprefix.s); + sam_global_args_free(&ga); + + return ret; +} diff --git a/samtools/bam_mate.c b/samtools/bam_mate.c index 5b13b2e34..1d6c55f3c 100644 --- a/samtools/bam_mate.c +++ b/samtools/bam_mate.c @@ -1,6 +1,6 @@ /* bam_mate.c -- fix mate pairing information and clean up flags. - Copyright (C) 2009, 2011-2016 Genome Research Ltd. + Copyright (C) 2009, 2011-2017 Genome Research Ltd. Portions copyright (C) 2011 Broad Institute. Portions copyright (C) 2012 Peter Cock, The James Hutton Institute. @@ -31,6 +31,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include "htslib/thread_pool.h" #include "sam_opts.h" #include "htslib/kstring.h" #include "htslib/sam.h" @@ -155,9 +156,30 @@ static bool plausibly_properly_paired(bam1_t* a, bam1_t* b) return false; } -static void sync_mq(bam1_t* src, bam1_t* dest) +// Returns 0 on success, -1 on failure. +static int bam_format_cigar(const bam1_t* b, kstring_t* str) +{ + // An empty cigar is a special case return "*" rather than "" + if (b->core.n_cigar == 0) { + return (kputc('*', str) == EOF) ? -1 : 0; + } + + const uint32_t *cigar = bam_get_cigar(b); + uint32_t i; + + for (i = 0; i < b->core.n_cigar; ++i) { + if (kputw(bam_cigar_oplen(cigar[i]), str) == EOF) return -1; + if (kputc(bam_cigar_opchr(cigar[i]), str) == EOF) return -1; + } + + return 0; +} + +// Returns 0 on success, -1 on failure. +static int sync_mq_mc(bam1_t* src, bam1_t* dest) { if ( (src->core.flag & BAM_FUNMAP) == 0 ) { // If mapped + // Copy Mate Mapping Quality uint32_t mq = src->core.qual; uint8_t* data; if ((data = bam_aux_get(dest,"MQ")) != NULL) { @@ -166,21 +188,69 @@ static void sync_mq(bam1_t* src, bam1_t* dest) bam_aux_append(dest, "MQ", 'i', sizeof(uint32_t), (uint8_t*)&mq); } + // Copy mate cigar if either read is mapped + if ( (src->core.flag & BAM_FUNMAP) == 0 || (dest->core.flag & BAM_FUNMAP) == 0 ) { + uint8_t* data_mc; + if ((data_mc = bam_aux_get(dest,"MC")) != NULL) { + bam_aux_del(dest, data_mc); + } + + // Convert cigar to string + kstring_t mc = { 0, 0, NULL }; + if (bam_format_cigar(src, &mc) < 0) return -1; + + bam_aux_append(dest, "MC", 'Z', ks_len(&mc)+1, (uint8_t*)ks_str(&mc)); + free(mc.s); + } + return 0; } -// copy flags -static void sync_mate(bam1_t* a, bam1_t* b) +// Copy flags. +// Returns 0 on success, -1 on failure. +static int sync_mate(bam1_t* a, bam1_t* b) { sync_unmapped_pos_inner(a,b); sync_unmapped_pos_inner(b,a); sync_mate_inner(a,b); sync_mate_inner(b,a); - sync_mq(a,b); - sync_mq(b,a); + if (sync_mq_mc(a,b) < 0) return -1; + if (sync_mq_mc(b,a) < 0) return -1; + return 0; +} + + +static uint32_t calc_mate_score(bam1_t *b) +{ + uint32_t score = 0; + uint8_t *qual = bam_get_qual(b); + int i; + + for (i = 0; i < b->core.l_qseq; i++) { + if (qual[i] >= 15) score += qual[i]; + } + + return score; +} + + +static int add_mate_score(bam1_t *src, bam1_t *dest) +{ + uint8_t *data_ms; + uint32_t mate_score = calc_mate_score(src); + + if ((data_ms = bam_aux_get(dest, "ms")) != NULL) { + bam_aux_del(dest, data_ms); + } + + if (bam_aux_append(dest, "ms", 'i', sizeof(uint32_t), (uint8_t*)&mate_score) == -1) { + return -1; + } + + return 0; } // currently, this function ONLY works if each read has one hit -static int bam_mating_core(samFile* in, samFile* out, int remove_reads, int proper_pair_check, int add_ct) +static int bam_mating_core(samFile *in, samFile *out, int remove_reads, int proper_pair_check, int add_ct, int do_mate_scoring) { bam_hdr_t *header; bam1_t *b[2] = { NULL, NULL }; @@ -239,7 +309,7 @@ static int bam_mating_core(samFile* in, samFile* out, int remove_reads, int prop if (strcmp(bam_get_qname(cur), bam_get_qname(pre)) == 0) { // identical pair name pre->core.flag |= BAM_FPAIRED; cur->core.flag |= BAM_FPAIRED; - sync_mate(pre, cur); + if (sync_mate(pre, cur)) goto fail; if (pre->core.tid == cur->core.tid && !(cur->core.flag&(BAM_FUNMAP|BAM_FMUNMAP)) && !(pre->core.flag&(BAM_FUNMAP|BAM_FMUNMAP))) // if safe set TLEN/ISIZE @@ -256,6 +326,13 @@ static int bam_mating_core(samFile* in, samFile* out, int remove_reads, int prop cur->core.flag &= ~BAM_FPROPER_PAIR; } + if (do_mate_scoring) { + if ((add_mate_score(pre, cur) == -1) || (add_mate_score(cur, pre) == -1)) { + fprintf(stderr, "[bam_mating_core] ERROR: unable to add mate score.\n"); + goto fail; + } + } + // Write out result if ( !remove_reads ) { if (sam_write1(out, header, pre) < 0) goto write_fail; @@ -322,9 +399,10 @@ void usage(FILE* where) "Options:\n" " -r Remove unmapped reads and secondary alignments\n" " -p Disable FR proper pair check\n" -" -c Add template cigar ct tag\n"); +" -c Add template cigar ct tag\n" +" -m Add mate score tag\n"); - sam_global_opt_help(where, "-.O.."); + sam_global_opt_help(where, "-.O..@"); fprintf(where, "\n" @@ -335,22 +413,24 @@ void usage(FILE* where) int bam_mating(int argc, char *argv[]) { + htsThreadPool p = {NULL, 0}; samFile *in = NULL, *out = NULL; - int c, remove_reads = 0, proper_pair_check = 1, add_ct = 0, res = 1; + int c, remove_reads = 0, proper_pair_check = 1, add_ct = 0, res = 1, mate_score = 0; sam_global_args ga = SAM_GLOBAL_ARGS_INIT; char wmode[3] = {'w', 'b', 0}; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0, '@'), { NULL, 0, NULL, 0 } }; // parse args if (argc == 1) { usage(stdout); return 0; } - while ((c = getopt_long(argc, argv, "rpcO:", lopts, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "rpcmO:@:", lopts, NULL)) >= 0) { switch (c) { case 'r': remove_reads = 1; break; case 'p': proper_pair_check = 0; break; case 'c': add_ct = 1; break; + case 'm': mate_score = 1; break; default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; /* else fall-through */ case '?': usage(stderr); goto fail; @@ -369,8 +449,17 @@ int bam_mating(int argc, char *argv[]) goto fail; } + if (ga.nthreads > 0) { + if (!(p.pool = hts_tpool_init(ga.nthreads))) { + fprintf(stderr, "Error creating thread pool\n"); + goto fail; + } + hts_set_opt(in, HTS_OPT_THREAD_POOL, &p); + hts_set_opt(out, HTS_OPT_THREAD_POOL, &p); + } + // run - res = bam_mating_core(in, out, remove_reads, proper_pair_check, add_ct); + res = bam_mating_core(in, out, remove_reads, proper_pair_check, add_ct, mate_score); // cleanup sam_close(in); @@ -379,12 +468,14 @@ int bam_mating(int argc, char *argv[]) res = 1; } + if (p.pool) hts_tpool_destroy(p.pool); sam_global_args_free(&ga); return res; fail: if (in) sam_close(in); if (out) sam_close(out); + if (p.pool) hts_tpool_destroy(p.pool); sam_global_args_free(&ga); return 1; } diff --git a/samtools/bam_mate.c.pysam.c b/samtools/bam_mate.c.pysam.c index a416d071a..57159cc7e 100644 --- a/samtools/bam_mate.c.pysam.c +++ b/samtools/bam_mate.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_mate.c -- fix mate pairing information and clean up flags. - Copyright (C) 2009, 2011-2016 Genome Research Ltd. + Copyright (C) 2009, 2011-2017 Genome Research Ltd. Portions copyright (C) 2011 Broad Institute. Portions copyright (C) 2012 Peter Cock, The James Hutton Institute. @@ -33,6 +33,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include "htslib/thread_pool.h" #include "sam_opts.h" #include "htslib/kstring.h" #include "htslib/sam.h" @@ -157,9 +158,30 @@ static bool plausibly_properly_paired(bam1_t* a, bam1_t* b) return false; } -static void sync_mq(bam1_t* src, bam1_t* dest) +// Returns 0 on success, -1 on failure. +static int bam_format_cigar(const bam1_t* b, kstring_t* str) +{ + // An empty cigar is a special case return "*" rather than "" + if (b->core.n_cigar == 0) { + return (kputc('*', str) == EOF) ? -1 : 0; + } + + const uint32_t *cigar = bam_get_cigar(b); + uint32_t i; + + for (i = 0; i < b->core.n_cigar; ++i) { + if (kputw(bam_cigar_oplen(cigar[i]), str) == EOF) return -1; + if (kputc(bam_cigar_opchr(cigar[i]), str) == EOF) return -1; + } + + return 0; +} + +// Returns 0 on success, -1 on failure. +static int sync_mq_mc(bam1_t* src, bam1_t* dest) { if ( (src->core.flag & BAM_FUNMAP) == 0 ) { // If mapped + // Copy Mate Mapping Quality uint32_t mq = src->core.qual; uint8_t* data; if ((data = bam_aux_get(dest,"MQ")) != NULL) { @@ -168,21 +190,69 @@ static void sync_mq(bam1_t* src, bam1_t* dest) bam_aux_append(dest, "MQ", 'i', sizeof(uint32_t), (uint8_t*)&mq); } + // Copy mate cigar if either read is mapped + if ( (src->core.flag & BAM_FUNMAP) == 0 || (dest->core.flag & BAM_FUNMAP) == 0 ) { + uint8_t* data_mc; + if ((data_mc = bam_aux_get(dest,"MC")) != NULL) { + bam_aux_del(dest, data_mc); + } + + // Convert cigar to string + kstring_t mc = { 0, 0, NULL }; + if (bam_format_cigar(src, &mc) < 0) return -1; + + bam_aux_append(dest, "MC", 'Z', ks_len(&mc)+1, (uint8_t*)ks_str(&mc)); + free(mc.s); + } + return 0; } -// copy flags -static void sync_mate(bam1_t* a, bam1_t* b) +// Copy flags. +// Returns 0 on success, -1 on failure. +static int sync_mate(bam1_t* a, bam1_t* b) { sync_unmapped_pos_inner(a,b); sync_unmapped_pos_inner(b,a); sync_mate_inner(a,b); sync_mate_inner(b,a); - sync_mq(a,b); - sync_mq(b,a); + if (sync_mq_mc(a,b) < 0) return -1; + if (sync_mq_mc(b,a) < 0) return -1; + return 0; +} + + +static uint32_t calc_mate_score(bam1_t *b) +{ + uint32_t score = 0; + uint8_t *qual = bam_get_qual(b); + int i; + + for (i = 0; i < b->core.l_qseq; i++) { + if (qual[i] >= 15) score += qual[i]; + } + + return score; +} + + +static int add_mate_score(bam1_t *src, bam1_t *dest) +{ + uint8_t *data_ms; + uint32_t mate_score = calc_mate_score(src); + + if ((data_ms = bam_aux_get(dest, "ms")) != NULL) { + bam_aux_del(dest, data_ms); + } + + if (bam_aux_append(dest, "ms", 'i', sizeof(uint32_t), (uint8_t*)&mate_score) == -1) { + return -1; + } + + return 0; } // currently, this function ONLY works if each read has one hit -static int bam_mating_core(samFile* in, samFile* out, int remove_reads, int proper_pair_check, int add_ct) +static int bam_mating_core(samFile *in, samFile *out, int remove_reads, int proper_pair_check, int add_ct, int do_mate_scoring) { bam_hdr_t *header; bam1_t *b[2] = { NULL, NULL }; @@ -192,7 +262,7 @@ static int bam_mating_core(samFile* in, samFile* out, int remove_reads, int prop str.l = str.m = 0; str.s = 0; header = sam_hdr_read(in); if (header == NULL) { - fprintf(pysam_stderr, "[bam_mating_core] ERROR: Couldn't read header\n"); + fprintf(samtools_stderr, "[bam_mating_core] ERROR: Couldn't read header\n"); return 1; } // Accept unknown, unsorted, or queryname sort order, but error on coordinate sorted. @@ -203,7 +273,7 @@ static int bam_mating_core(samFile* in, samFile* out, int remove_reads, int prop // Looking for SO:coordinate within the @HD line only // (e.g. must ignore in a @CO comment line later in header) if ((p != 0) && (p < q)) { - fprintf(pysam_stderr, "[bam_mating_core] ERROR: Coordinate sorted, require grouped/sorted by queryname.\n"); + fprintf(samtools_stderr, "[bam_mating_core] ERROR: Coordinate sorted, require grouped/sorted by queryname.\n"); goto fail; } } @@ -241,7 +311,7 @@ static int bam_mating_core(samFile* in, samFile* out, int remove_reads, int prop if (strcmp(bam_get_qname(cur), bam_get_qname(pre)) == 0) { // identical pair name pre->core.flag |= BAM_FPAIRED; cur->core.flag |= BAM_FPAIRED; - sync_mate(pre, cur); + if (sync_mate(pre, cur)) goto fail; if (pre->core.tid == cur->core.tid && !(cur->core.flag&(BAM_FUNMAP|BAM_FMUNMAP)) && !(pre->core.flag&(BAM_FUNMAP|BAM_FMUNMAP))) // if safe set TLEN/ISIZE @@ -258,6 +328,13 @@ static int bam_mating_core(samFile* in, samFile* out, int remove_reads, int prop cur->core.flag &= ~BAM_FPROPER_PAIR; } + if (do_mate_scoring) { + if ((add_mate_score(pre, cur) == -1) || (add_mate_score(cur, pre) == -1)) { + fprintf(samtools_stderr, "[bam_mating_core] ERROR: unable to add mate score.\n"); + goto fail; + } + } + // Write out result if ( !remove_reads ) { if (sam_write1(out, header, pre) < 0) goto write_fail; @@ -324,41 +401,44 @@ void usage(FILE* where) "Options:\n" " -r Remove unmapped reads and secondary alignments\n" " -p Disable FR proper pair check\n" -" -c Add template cigar ct tag\n"); +" -c Add template cigar ct tag\n" +" -m Add mate score tag\n"); - sam_global_opt_help(where, "-.O.."); + sam_global_opt_help(where, "-.O..@"); fprintf(where, "\n" -"As elsewhere in samtools, use '-' as the filename for stdin/pysam_stdout. The input\n" +"As elsewhere in samtools, use '-' as the filename for stdin/samtools_stdout. The input\n" "file must be grouped by read name (e.g. sorted by name). Coordinated sorted\n" "input is not accepted.\n"); } int bam_mating(int argc, char *argv[]) { + htsThreadPool p = {NULL, 0}; samFile *in = NULL, *out = NULL; - int c, remove_reads = 0, proper_pair_check = 1, add_ct = 0, res = 1; + int c, remove_reads = 0, proper_pair_check = 1, add_ct = 0, res = 1, mate_score = 0; sam_global_args ga = SAM_GLOBAL_ARGS_INIT; char wmode[3] = {'w', 'b', 0}; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0, '@'), { NULL, 0, NULL, 0 } }; // parse args - if (argc == 1) { usage(pysam_stdout); return 0; } - while ((c = getopt_long(argc, argv, "rpcO:", lopts, NULL)) >= 0) { + if (argc == 1) { usage(samtools_stdout); return 0; } + while ((c = getopt_long(argc, argv, "rpcmO:@:", lopts, NULL)) >= 0) { switch (c) { case 'r': remove_reads = 1; break; case 'p': proper_pair_check = 0; break; case 'c': add_ct = 1; break; + case 'm': mate_score = 1; break; default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; /* else fall-through */ - case '?': usage(pysam_stderr); goto fail; + case '?': usage(samtools_stderr); goto fail; } } - if (optind+1 >= argc) { usage(pysam_stderr); goto fail; } + if (optind+1 >= argc) { usage(samtools_stderr); goto fail; } // init if ((in = sam_open_format(argv[optind], "rb", &ga.in)) == NULL) { @@ -371,22 +451,33 @@ int bam_mating(int argc, char *argv[]) goto fail; } + if (ga.nthreads > 0) { + if (!(p.pool = hts_tpool_init(ga.nthreads))) { + fprintf(samtools_stderr, "Error creating thread pool\n"); + goto fail; + } + hts_set_opt(in, HTS_OPT_THREAD_POOL, &p); + hts_set_opt(out, HTS_OPT_THREAD_POOL, &p); + } + // run - res = bam_mating_core(in, out, remove_reads, proper_pair_check, add_ct); + res = bam_mating_core(in, out, remove_reads, proper_pair_check, add_ct, mate_score); // cleanup sam_close(in); if (sam_close(out) < 0) { - fprintf(pysam_stderr, "[bam_mating] error while closing output file\n"); + fprintf(samtools_stderr, "[bam_mating] error while closing output file\n"); res = 1; } + if (p.pool) hts_tpool_destroy(p.pool); sam_global_args_free(&ga); return res; fail: if (in) sam_close(in); if (out) sam_close(out); + if (p.pool) hts_tpool_destroy(p.pool); sam_global_args_free(&ga); return 1; } diff --git a/samtools/bam_md.c b/samtools/bam_md.c index 71206cda7..f09503030 100644 --- a/samtools/bam_md.c +++ b/samtools/bam_md.c @@ -25,15 +25,15 @@ DEALINGS IN THE SOFTWARE. */ #include -#include +#include +#include #include #include #include -#include #include "htslib/faidx.h" #include "htslib/sam.h" #include "htslib/kstring.h" -#include "kprobaln.h" +#include "htslib/thread_pool.h" #include "sam_opts.h" #include "samtools.h" @@ -161,178 +161,6 @@ void bam_fillmd1(bam1_t *b, char *ref, int flag) bam_fillmd1_core(b, ref, INT_MAX, flag, 0); } -int bam_cap_mapQ(bam1_t *b, char *ref, int ref_len, int thres) -{ - uint8_t *seq = bam_get_seq(b), *qual = bam_get_qual(b); - uint32_t *cigar = bam_get_cigar(b); - bam1_core_t *c = &b->core; - int i, x, y, mm, q, len, clip_l, clip_q; - double t; - if (thres < 0) thres = 40; // set the default - mm = q = len = clip_l = clip_q = 0; - for (i = y = 0, x = c->pos; i < c->n_cigar; ++i) { - int j, l = cigar[i]>>4, op = cigar[i]&0xf; - if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { - for (j = 0; j < l; ++j) { - int c1, c2, z = y + j; - if (x+j >= ref_len || ref[x+j] == '\0') break; // out of bounds - c1 = bam_seqi(seq, z), c2 = seq_nt16_table[(int)ref[x+j]]; - if (c2 != 15 && c1 != 15 && qual[z] >= 13) { // not ambiguous - ++len; - if (c1 && c1 != c2 && qual[z] >= 13) { // mismatch - ++mm; - q += qual[z] > 33? 33 : qual[z]; - } - } - } - if (j < l) break; - x += l; y += l; len += l; - } else if (op == BAM_CDEL) { - for (j = 0; j < l; ++j) - if (x+j >= ref_len || ref[x+j] == '\0') break; - if (j < l) break; - x += l; - } else if (op == BAM_CSOFT_CLIP) { - for (j = 0; j < l; ++j) clip_q += qual[y+j]; - clip_l += l; - y += l; - } else if (op == BAM_CHARD_CLIP) { - clip_q += 13 * l; - clip_l += l; - } else if (op == BAM_CINS) y += l; - else if (op == BAM_CREF_SKIP) x += l; - } - for (i = 0, t = 1; i < mm; ++i) - t *= (double)len / (i+1); - t = q - 4.343 * log(t) + clip_q / 5.; - if (t > thres) return -1; - if (t < 0) t = 0; - t = sqrt((thres - t) / thres) * thres; -// fprintf(stderr, "%s %lf %d\n", bam_get_qname(b), t, q); - return (int)(t + .499); -} - -int bam_prob_realn_core(bam1_t *b, const char *ref, int ref_len, int flag) -{ - int k, i, bw, x, y, yb, ye, xb, xe, apply_baq = flag&1, extend_baq = flag>>1&1, redo_baq = flag&4; - uint32_t *cigar = bam_get_cigar(b); - bam1_core_t *c = &b->core; - kpa_par_t conf = kpa_par_def; - uint8_t *bq = 0, *zq = 0, *qual = bam_get_qual(b); - if ((c->flag & BAM_FUNMAP) || b->core.l_qseq == 0 || qual[0] == (uint8_t)-1) - return -1; // do nothing - - // test if BQ or ZQ is present - if ((bq = bam_aux_get(b, "BQ")) != 0) ++bq; - if ((zq = bam_aux_get(b, "ZQ")) != 0 && *zq == 'Z') ++zq; - if (bq && redo_baq) - { - bam_aux_del(b, bq-1); - bq = 0; - } - if (bq && zq) { // remove the ZQ tag - bam_aux_del(b, zq-1); - zq = 0; - } - if (bq || zq) { - if ((apply_baq && zq) || (!apply_baq && bq)) return -3; // in both cases, do nothing - if (bq && apply_baq) { // then convert BQ to ZQ - for (i = 0; i < c->l_qseq; ++i) - qual[i] = qual[i] + 64 < bq[i]? 0 : qual[i] - ((int)bq[i] - 64); - *(bq - 3) = 'Z'; - } else if (zq && !apply_baq) { // then convert ZQ to BQ - for (i = 0; i < c->l_qseq; ++i) - qual[i] += (int)zq[i] - 64; - *(zq - 3) = 'B'; - } - return 0; - } - // find the start and end of the alignment - x = c->pos, y = 0, yb = ye = xb = xe = -1; - for (k = 0; k < c->n_cigar; ++k) { - int op, l; - op = cigar[k]&0xf; l = cigar[k]>>4; - if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { - if (yb < 0) yb = y; - if (xb < 0) xb = x; - ye = y + l; xe = x + l; - x += l; y += l; - } else if (op == BAM_CSOFT_CLIP || op == BAM_CINS) y += l; - else if (op == BAM_CDEL) x += l; - else if (op == BAM_CREF_SKIP) return -1; // do nothing if there is a reference skip - } - // set bandwidth and the start and the end - bw = 7; - if (abs((xe - xb) - (ye - yb)) > bw) - bw = abs((xe - xb) - (ye - yb)) + 3; - conf.bw = bw; - xb -= yb + bw/2; if (xb < 0) xb = 0; - xe += c->l_qseq - ye + bw/2; - if (xe - xb - c->l_qseq > bw) - xb += (xe - xb - c->l_qseq - bw) / 2, xe -= (xe - xb - c->l_qseq - bw) / 2; - { // glocal - uint8_t *s, *r, *q, *seq = bam_get_seq(b), *bq; - int *state; - bq = calloc(c->l_qseq + 1, 1); - memcpy(bq, qual, c->l_qseq); - s = calloc(c->l_qseq, 1); - for (i = 0; i < c->l_qseq; ++i) s[i] = seq_nt16_int[bam_seqi(seq, i)]; - r = calloc(xe - xb, 1); - for (i = xb; i < xe; ++i) { - if (i >= ref_len || ref[i] == '\0') { xe = i; break; } - r[i-xb] = seq_nt16_int[seq_nt16_table[(int)ref[i]]]; - } - state = calloc(c->l_qseq, sizeof(int)); - q = calloc(c->l_qseq, 1); - kpa_glocal(r, xe-xb, s, c->l_qseq, qual, &conf, state, q); - if (!extend_baq) { // in this block, bq[] is capped by base quality qual[] - for (k = 0, x = c->pos, y = 0; k < c->n_cigar; ++k) { - int op = cigar[k]&0xf, l = cigar[k]>>4; - if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { - for (i = y; i < y + l; ++i) { - if ((state[i]&3) != 0 || state[i]>>2 != x - xb + (i - y)) bq[i] = 0; - else bq[i] = bq[i] < q[i]? bq[i] : q[i]; - } - x += l; y += l; - } else if (op == BAM_CSOFT_CLIP || op == BAM_CINS) y += l; - else if (op == BAM_CDEL) x += l; - } - for (i = 0; i < c->l_qseq; ++i) bq[i] = qual[i] - bq[i] + 64; // finalize BQ - } else { // in this block, bq[] is BAQ that can be larger than qual[] (different from the above!) - uint8_t *left, *rght; - left = calloc(c->l_qseq, 1); rght = calloc(c->l_qseq, 1); - for (k = 0, x = c->pos, y = 0; k < c->n_cigar; ++k) { - int op = cigar[k]&0xf, l = cigar[k]>>4; - if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { - for (i = y; i < y + l; ++i) - bq[i] = ((state[i]&3) != 0 || state[i]>>2 != x - xb + (i - y))? 0 : q[i]; - for (left[y] = bq[y], i = y + 1; i < y + l; ++i) - left[i] = bq[i] > left[i-1]? bq[i] : left[i-1]; - for (rght[y+l-1] = bq[y+l-1], i = y + l - 2; i >= y; --i) - rght[i] = bq[i] > rght[i+1]? bq[i] : rght[i+1]; - for (i = y; i < y + l; ++i) - bq[i] = left[i] < rght[i]? left[i] : rght[i]; - x += l; y += l; - } else if (op == BAM_CSOFT_CLIP || op == BAM_CINS) y += l; - else if (op == BAM_CDEL) x += l; - } - for (i = 0; i < c->l_qseq; ++i) bq[i] = 64 + (qual[i] <= bq[i]? 0 : qual[i] - bq[i]); // finalize BQ - free(left); free(rght); - } - if (apply_baq) { - for (i = 0; i < c->l_qseq; ++i) qual[i] -= bq[i] - 64; // modify qual - bam_aux_append(b, "ZQ", 'Z', c->l_qseq + 1, bq); - } else bam_aux_append(b, "BQ", 'Z', c->l_qseq + 1, bq); - free(bq); free(s); free(r); free(q); free(state); - } - return 0; -} - -int bam_prob_realn(bam1_t *b, const char *ref) -{ - return bam_prob_realn_core(b, ref, INT_MAX, 1); -} - int calmd_usage() { fprintf(stderr, "Usage: samtools calmd [-eubrAES] \n" @@ -345,13 +173,14 @@ int calmd_usage() { " -r compute the BQ tag (without -A) or cap baseQ by BAQ (with -A)\n" " -E extended BAQ for better sensitivity but lower specificity\n"); - sam_global_opt_help(stderr, "-...."); + sam_global_opt_help(stderr, "-....@"); return 1; } int bam_fillmd(int argc, char *argv[]) { int c, flt_flag, tid = -2, ret, len, is_bam_out, is_uncompressed, max_nm, is_realn, capQ, baq_flag; + htsThreadPool p = {NULL, 0}; samFile *fp = NULL, *fpout = NULL; bam_hdr_t *header = NULL; faidx_t *fai = NULL; @@ -360,14 +189,14 @@ int bam_fillmd(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0,'@'), { NULL, 0, NULL, 0 } }; flt_flag = UPDATE_NM | UPDATE_MD; is_bam_out = is_uncompressed = is_realn = max_nm = capQ = baq_flag = 0; strcpy(mode_w, "w"); - while ((c = getopt_long(argc, argv, "EqreuNhbSC:n:Ad", lopts, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "EqreuNhbSC:n:Ad@:", lopts, NULL)) >= 0) { switch (c) { case 'r': is_realn = 1; break; case 'e': flt_flag |= USE_EQUAL; break; @@ -415,6 +244,15 @@ int bam_fillmd(int argc, char *argv[]) goto fail; } + if (ga.nthreads > 0) { + if (!(p.pool = hts_tpool_init(ga.nthreads))) { + fprintf(stderr, "Error creating thread pool\n"); + goto fail; + } + hts_set_opt(fp, HTS_OPT_THREAD_POOL, &p); + hts_set_opt(fpout, HTS_OPT_THREAD_POOL, &p); + } + ref_file = argc > optind + 1 ? argv[optind+1] : ga.reference; fai = fai_load(ref_file); @@ -440,9 +278,9 @@ int bam_fillmd(int argc, char *argv[]) if (is_realn || capQ > 10) goto fail; // Would otherwise crash } } - if (is_realn) bam_prob_realn_core(b, ref, len, baq_flag); + if (is_realn) sam_prob_realn(b, ref, len, baq_flag); if (capQ > 10) { - int q = bam_cap_mapQ(b, ref, len, capQ); + int q = sam_cap_mapq(b, ref, len, capQ); if (b->core.qual > q) b->core.qual = q; } if (ref) bam_fillmd1_core(b, ref, len, flt_flag, max_nm); @@ -466,6 +304,8 @@ int bam_fillmd(int argc, char *argv[]) fprintf(stderr, "[bam_fillmd] error when closing output file\n"); return 1; } + if (p.pool) hts_tpool_destroy(p.pool); + return 0; fail: @@ -475,5 +315,7 @@ int bam_fillmd(int argc, char *argv[]) if (fai) fai_destroy(fai); if (fp) sam_close(fp); if (fpout) sam_close(fpout); + if (p.pool) hts_tpool_destroy(p.pool); + return 1; } diff --git a/samtools/bam_md.c.pysam.c b/samtools/bam_md.c.pysam.c index d00c01d06..f266fe7b6 100644 --- a/samtools/bam_md.c.pysam.c +++ b/samtools/bam_md.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_md.c -- calmd subcommand. @@ -27,15 +27,15 @@ DEALINGS IN THE SOFTWARE. */ #include -#include +#include +#include #include #include #include -#include #include "htslib/faidx.h" #include "htslib/sam.h" #include "htslib/kstring.h" -#include "kprobaln.h" +#include "htslib/thread_pool.h" #include "sam_opts.h" #include "samtools.h" @@ -118,7 +118,7 @@ void bam_fillmd1_core(bam1_t *b, char *ref, int ref_len, int flag, int max_nm) if (old_nm) old_nm_i = bam_aux2i(old_nm); if (!old_nm) bam_aux_append(b, "NM", 'i', 4, (uint8_t*)&nm); else if (nm != old_nm_i) { - fprintf(pysam_stderr, "[bam_fillmd1] different NM for read '%s': %d -> %d\n", bam_get_qname(b), old_nm_i, nm); + fprintf(samtools_stderr, "[bam_fillmd1] different NM for read '%s': %d -> %d\n", bam_get_qname(b), old_nm_i, nm); bam_aux_del(b, old_nm); bam_aux_append(b, "NM", 'i', 4, (uint8_t*)&nm); } @@ -136,7 +136,7 @@ void bam_fillmd1_core(bam1_t *b, char *ref, int ref_len, int flag, int max_nm) if (i < str->l) is_diff = 1; } else is_diff = 1; if (is_diff) { - fprintf(pysam_stderr, "[bam_fillmd1] different MD for read '%s': '%s' -> '%s'\n", bam_get_qname(b), old_md+1, str->s); + fprintf(samtools_stderr, "[bam_fillmd1] different MD for read '%s': '%s' -> '%s'\n", bam_get_qname(b), old_md+1, str->s); bam_aux_del(b, old_md); bam_aux_append(b, "MD", 'Z', str->l + 1, (uint8_t*)str->s); } @@ -163,180 +163,8 @@ void bam_fillmd1(bam1_t *b, char *ref, int flag) bam_fillmd1_core(b, ref, INT_MAX, flag, 0); } -int bam_cap_mapQ(bam1_t *b, char *ref, int ref_len, int thres) -{ - uint8_t *seq = bam_get_seq(b), *qual = bam_get_qual(b); - uint32_t *cigar = bam_get_cigar(b); - bam1_core_t *c = &b->core; - int i, x, y, mm, q, len, clip_l, clip_q; - double t; - if (thres < 0) thres = 40; // set the default - mm = q = len = clip_l = clip_q = 0; - for (i = y = 0, x = c->pos; i < c->n_cigar; ++i) { - int j, l = cigar[i]>>4, op = cigar[i]&0xf; - if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { - for (j = 0; j < l; ++j) { - int c1, c2, z = y + j; - if (x+j >= ref_len || ref[x+j] == '\0') break; // out of bounds - c1 = bam_seqi(seq, z), c2 = seq_nt16_table[(int)ref[x+j]]; - if (c2 != 15 && c1 != 15 && qual[z] >= 13) { // not ambiguous - ++len; - if (c1 && c1 != c2 && qual[z] >= 13) { // mismatch - ++mm; - q += qual[z] > 33? 33 : qual[z]; - } - } - } - if (j < l) break; - x += l; y += l; len += l; - } else if (op == BAM_CDEL) { - for (j = 0; j < l; ++j) - if (x+j >= ref_len || ref[x+j] == '\0') break; - if (j < l) break; - x += l; - } else if (op == BAM_CSOFT_CLIP) { - for (j = 0; j < l; ++j) clip_q += qual[y+j]; - clip_l += l; - y += l; - } else if (op == BAM_CHARD_CLIP) { - clip_q += 13 * l; - clip_l += l; - } else if (op == BAM_CINS) y += l; - else if (op == BAM_CREF_SKIP) x += l; - } - for (i = 0, t = 1; i < mm; ++i) - t *= (double)len / (i+1); - t = q - 4.343 * log(t) + clip_q / 5.; - if (t > thres) return -1; - if (t < 0) t = 0; - t = sqrt((thres - t) / thres) * thres; -// fprintf(pysam_stderr, "%s %lf %d\n", bam_get_qname(b), t, q); - return (int)(t + .499); -} - -int bam_prob_realn_core(bam1_t *b, const char *ref, int ref_len, int flag) -{ - int k, i, bw, x, y, yb, ye, xb, xe, apply_baq = flag&1, extend_baq = flag>>1&1, redo_baq = flag&4; - uint32_t *cigar = bam_get_cigar(b); - bam1_core_t *c = &b->core; - kpa_par_t conf = kpa_par_def; - uint8_t *bq = 0, *zq = 0, *qual = bam_get_qual(b); - if ((c->flag & BAM_FUNMAP) || b->core.l_qseq == 0 || qual[0] == (uint8_t)-1) - return -1; // do nothing - - // test if BQ or ZQ is present - if ((bq = bam_aux_get(b, "BQ")) != 0) ++bq; - if ((zq = bam_aux_get(b, "ZQ")) != 0 && *zq == 'Z') ++zq; - if (bq && redo_baq) - { - bam_aux_del(b, bq-1); - bq = 0; - } - if (bq && zq) { // remove the ZQ tag - bam_aux_del(b, zq-1); - zq = 0; - } - if (bq || zq) { - if ((apply_baq && zq) || (!apply_baq && bq)) return -3; // in both cases, do nothing - if (bq && apply_baq) { // then convert BQ to ZQ - for (i = 0; i < c->l_qseq; ++i) - qual[i] = qual[i] + 64 < bq[i]? 0 : qual[i] - ((int)bq[i] - 64); - *(bq - 3) = 'Z'; - } else if (zq && !apply_baq) { // then convert ZQ to BQ - for (i = 0; i < c->l_qseq; ++i) - qual[i] += (int)zq[i] - 64; - *(zq - 3) = 'B'; - } - return 0; - } - // find the start and end of the alignment - x = c->pos, y = 0, yb = ye = xb = xe = -1; - for (k = 0; k < c->n_cigar; ++k) { - int op, l; - op = cigar[k]&0xf; l = cigar[k]>>4; - if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { - if (yb < 0) yb = y; - if (xb < 0) xb = x; - ye = y + l; xe = x + l; - x += l; y += l; - } else if (op == BAM_CSOFT_CLIP || op == BAM_CINS) y += l; - else if (op == BAM_CDEL) x += l; - else if (op == BAM_CREF_SKIP) return -1; // do nothing if there is a reference skip - } - // set bandwidth and the start and the end - bw = 7; - if (abs((xe - xb) - (ye - yb)) > bw) - bw = abs((xe - xb) - (ye - yb)) + 3; - conf.bw = bw; - xb -= yb + bw/2; if (xb < 0) xb = 0; - xe += c->l_qseq - ye + bw/2; - if (xe - xb - c->l_qseq > bw) - xb += (xe - xb - c->l_qseq - bw) / 2, xe -= (xe - xb - c->l_qseq - bw) / 2; - { // glocal - uint8_t *s, *r, *q, *seq = bam_get_seq(b), *bq; - int *state; - bq = calloc(c->l_qseq + 1, 1); - memcpy(bq, qual, c->l_qseq); - s = calloc(c->l_qseq, 1); - for (i = 0; i < c->l_qseq; ++i) s[i] = seq_nt16_int[bam_seqi(seq, i)]; - r = calloc(xe - xb, 1); - for (i = xb; i < xe; ++i) { - if (i >= ref_len || ref[i] == '\0') { xe = i; break; } - r[i-xb] = seq_nt16_int[seq_nt16_table[(int)ref[i]]]; - } - state = calloc(c->l_qseq, sizeof(int)); - q = calloc(c->l_qseq, 1); - kpa_glocal(r, xe-xb, s, c->l_qseq, qual, &conf, state, q); - if (!extend_baq) { // in this block, bq[] is capped by base quality qual[] - for (k = 0, x = c->pos, y = 0; k < c->n_cigar; ++k) { - int op = cigar[k]&0xf, l = cigar[k]>>4; - if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { - for (i = y; i < y + l; ++i) { - if ((state[i]&3) != 0 || state[i]>>2 != x - xb + (i - y)) bq[i] = 0; - else bq[i] = bq[i] < q[i]? bq[i] : q[i]; - } - x += l; y += l; - } else if (op == BAM_CSOFT_CLIP || op == BAM_CINS) y += l; - else if (op == BAM_CDEL) x += l; - } - for (i = 0; i < c->l_qseq; ++i) bq[i] = qual[i] - bq[i] + 64; // finalize BQ - } else { // in this block, bq[] is BAQ that can be larger than qual[] (different from the above!) - uint8_t *left, *rght; - left = calloc(c->l_qseq, 1); rght = calloc(c->l_qseq, 1); - for (k = 0, x = c->pos, y = 0; k < c->n_cigar; ++k) { - int op = cigar[k]&0xf, l = cigar[k]>>4; - if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) { - for (i = y; i < y + l; ++i) - bq[i] = ((state[i]&3) != 0 || state[i]>>2 != x - xb + (i - y))? 0 : q[i]; - for (left[y] = bq[y], i = y + 1; i < y + l; ++i) - left[i] = bq[i] > left[i-1]? bq[i] : left[i-1]; - for (rght[y+l-1] = bq[y+l-1], i = y + l - 2; i >= y; --i) - rght[i] = bq[i] > rght[i+1]? bq[i] : rght[i+1]; - for (i = y; i < y + l; ++i) - bq[i] = left[i] < rght[i]? left[i] : rght[i]; - x += l; y += l; - } else if (op == BAM_CSOFT_CLIP || op == BAM_CINS) y += l; - else if (op == BAM_CDEL) x += l; - } - for (i = 0; i < c->l_qseq; ++i) bq[i] = 64 + (qual[i] <= bq[i]? 0 : qual[i] - bq[i]); // finalize BQ - free(left); free(rght); - } - if (apply_baq) { - for (i = 0; i < c->l_qseq; ++i) qual[i] -= bq[i] - 64; // modify qual - bam_aux_append(b, "ZQ", 'Z', c->l_qseq + 1, bq); - } else bam_aux_append(b, "BQ", 'Z', c->l_qseq + 1, bq); - free(bq); free(s); free(r); free(q); free(state); - } - return 0; -} - -int bam_prob_realn(bam1_t *b, const char *ref) -{ - return bam_prob_realn_core(b, ref, INT_MAX, 1); -} - int calmd_usage() { - fprintf(pysam_stderr, + fprintf(samtools_stderr, "Usage: samtools calmd [-eubrAES] \n" "Options:\n" " -e change identical bases to '='\n" @@ -347,13 +175,14 @@ int calmd_usage() { " -r compute the BQ tag (without -A) or cap baseQ by BAQ (with -A)\n" " -E extended BAQ for better sensitivity but lower specificity\n"); - sam_global_opt_help(pysam_stderr, "-...."); + sam_global_opt_help(samtools_stderr, "-....@"); return 1; } int bam_fillmd(int argc, char *argv[]) { int c, flt_flag, tid = -2, ret, len, is_bam_out, is_uncompressed, max_nm, is_realn, capQ, baq_flag; + htsThreadPool p = {NULL, 0}; samFile *fp = NULL, *fpout = NULL; bam_hdr_t *header = NULL; faidx_t *fai = NULL; @@ -362,14 +191,14 @@ int bam_fillmd(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0,'@'), { NULL, 0, NULL, 0 } }; flt_flag = UPDATE_NM | UPDATE_MD; is_bam_out = is_uncompressed = is_realn = max_nm = capQ = baq_flag = 0; strcpy(mode_w, "w"); - while ((c = getopt_long(argc, argv, "EqreuNhbSC:n:Ad", lopts, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "EqreuNhbSC:n:Ad@:", lopts, NULL)) >= 0) { switch (c) { case 'r': is_realn = 1; break; case 'e': flt_flag |= USE_EQUAL; break; @@ -385,7 +214,7 @@ int bam_fillmd(int argc, char *argv[]) case 'A': baq_flag |= 1; break; case 'E': baq_flag |= 2; break; default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; - fprintf(pysam_stderr, "[bam_fillmd] unrecognized option '-%c'\n\n", c); + fprintf(samtools_stderr, "[bam_fillmd] unrecognized option '-%c'\n\n", c); /* else fall-through */ case '?': return calmd_usage(); } @@ -403,11 +232,11 @@ int bam_fillmd(int argc, char *argv[]) header = sam_hdr_read(fp); if (header == NULL || header->n_targets == 0) { - fprintf(pysam_stderr, "[bam_fillmd] input SAM does not have header. Abort!\n"); + fprintf(samtools_stderr, "[bam_fillmd] input SAM does not have header. Abort!\n"); goto fail; } - - fpout = sam_open_format(pysam_stdout_fn, mode_w, &ga.out); + + fpout = sam_open_format(samtools_stdout_fn, mode_w, &ga.out); if (fpout == NULL) { print_error_errno("calmd", "Failed to open output"); goto fail; @@ -417,6 +246,15 @@ int bam_fillmd(int argc, char *argv[]) goto fail; } + if (ga.nthreads > 0) { + if (!(p.pool = hts_tpool_init(ga.nthreads))) { + fprintf(samtools_stderr, "Error creating thread pool\n"); + goto fail; + } + hts_set_opt(fp, HTS_OPT_THREAD_POOL, &p); + hts_set_opt(fpout, HTS_OPT_THREAD_POOL, &p); + } + ref_file = argc > optind + 1 ? argv[optind+1] : ga.reference; fai = fai_load(ref_file); @@ -427,7 +265,7 @@ int bam_fillmd(int argc, char *argv[]) b = bam_init1(); if (!b) { - fprintf(pysam_stderr, "[bam_fillmd] Failed to allocate bam struct\n"); + fprintf(samtools_stderr, "[bam_fillmd] Failed to allocate bam struct\n"); goto fail; } while ((ret = sam_read1(fp, header, b)) >= 0) { @@ -437,14 +275,14 @@ int bam_fillmd(int argc, char *argv[]) ref = fai_fetch(fai, header->target_name[b->core.tid], &len); tid = b->core.tid; if (ref == 0) { // FIXME: Should this always be fatal? - fprintf(pysam_stderr, "[bam_fillmd] fail to find sequence '%s' in the reference.\n", + fprintf(samtools_stderr, "[bam_fillmd] fail to find sequence '%s' in the reference.\n", header->target_name[tid]); if (is_realn || capQ > 10) goto fail; // Would otherwise crash } } - if (is_realn) bam_prob_realn_core(b, ref, len, baq_flag); + if (is_realn) sam_prob_realn(b, ref, len, baq_flag); if (capQ > 10) { - int q = bam_cap_mapQ(b, ref, len, capQ); + int q = sam_cap_mapq(b, ref, len, capQ); if (b->core.qual > q) b->core.qual = q; } if (ref) bam_fillmd1_core(b, ref, len, flt_flag, max_nm); @@ -455,7 +293,7 @@ int bam_fillmd(int argc, char *argv[]) } } if (ret < -1) { - fprintf(pysam_stderr, "[bam_fillmd] Error reading input.\n"); + fprintf(samtools_stderr, "[bam_fillmd] Error reading input.\n"); goto fail; } bam_destroy1(b); @@ -465,9 +303,11 @@ int bam_fillmd(int argc, char *argv[]) fai_destroy(fai); sam_close(fp); if (sam_close(fpout) < 0) { - fprintf(pysam_stderr, "[bam_fillmd] error when closing output file\n"); + fprintf(samtools_stderr, "[bam_fillmd] error when closing output file\n"); return 1; } + if (p.pool) hts_tpool_destroy(p.pool); + return 0; fail: @@ -477,5 +317,7 @@ int bam_fillmd(int argc, char *argv[]) if (fai) fai_destroy(fai); if (fp) sam_close(fp); if (fpout) sam_close(fpout); + if (p.pool) hts_tpool_destroy(p.pool); + return 1; } diff --git a/samtools/bam_plbuf.c.pysam.c b/samtools/bam_plbuf.c.pysam.c index 76c1ac181..a2e3d182d 100644 --- a/samtools/bam_plbuf.c.pysam.c +++ b/samtools/bam_plbuf.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_plbuf.c -- plbuf routines (previously in bam_pileup.c). diff --git a/samtools/bam_plcmd.c b/samtools/bam_plcmd.c index dc12bf3a0..d451ffdfa 100644 --- a/samtools/bam_plcmd.c +++ b/samtools/bam_plcmd.c @@ -31,6 +31,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include #include #include #include @@ -112,13 +113,14 @@ static inline void pileup_seq(FILE *fp, const bam_pileup1_t *p, int pos, int ref #define MPLP_PRINT_MAPQ (1<<10) #define MPLP_PER_SAMPLE (1<<11) #define MPLP_SMART_OVERLAPS (1<<12) +#define MPLP_PRINT_QNAME (1<<13) void *bed_read(const char *fn); void bed_destroy(void *_h); int bed_overlap(const void *_h, const char *chr, int beg, int end); typedef struct { - int min_mq, flag, min_baseQ, capQ_thres, max_depth, max_indel_depth, fmt_flag; + int min_mq, flag, min_baseQ, capQ_thres, max_depth, max_indel_depth, fmt_flag, all; int rflag_require, rflag_filter; int openQ, extQ, tandemQ, min_support; // for indels double min_frac; // for indels @@ -209,11 +211,23 @@ static int mplp_get_ref(mplp_aux_t *ma, int tid, char **ref, int *ref_len) { return 1; } +static void +print_empty_pileup(FILE *fp, const mplp_conf_t *conf, const char *tname, + int pos, int n, const char *ref, int ref_len) +{ + int i; + fprintf(fp, "%s\t%d\t%c", tname, pos+1, (ref && pos < ref_len)? ref[pos] : 'N'); + for (i = 0; i < n; ++i) { + fputs("\t0\t*\t*", fp); + if (conf->flag & MPLP_PRINT_MAPQ) fputs("\t*", fp); + if (conf->flag & MPLP_PRINT_POS) fputs("\t*", fp); + if (conf->flag & MPLP_PRINT_QNAME) fputs("\t*", fp); + } + putc('\n', fp); +} + static int mplp_func(void *data, bam1_t *b) { - extern int bam_realn(bam1_t *b, const char *ref); - extern int bam_prob_realn_core(bam1_t *b, const char *ref, int ref_len, int flag); - extern int bam_cap_mapQ(bam1_t *b, char *ref, int ref_len, int thres); char *ref; mplp_aux_t *ma = (mplp_aux_t*)data; int ret, skip = 0, ref_len; @@ -229,7 +243,7 @@ static int mplp_func(void *data, bam1_t *b) } if (ma->conf->rflag_require && !(ma->conf->rflag_require&b->core.flag)) { skip = 1; continue; } if (ma->conf->rflag_filter && ma->conf->rflag_filter&b->core.flag) { skip = 1; continue; } - if (ma->conf->bed) { // test overlap + if (ma->conf->bed && ma->conf->all == 0) { // test overlap skip = !bed_overlap(ma->conf->bed, ma->h->target_name[b->core.tid], b->core.pos, bam_endpos(b)); if (skip) continue; } @@ -258,9 +272,9 @@ static int mplp_func(void *data, bam1_t *b) } skip = 0; - if (has_ref && (ma->conf->flag&MPLP_REALN)) bam_prob_realn_core(b, ref, ref_len, (ma->conf->flag & MPLP_REDO_BAQ)? 7 : 3); + if (has_ref && (ma->conf->flag&MPLP_REALN)) sam_prob_realn(b, ref, ref_len, (ma->conf->flag & MPLP_REDO_BAQ)? 7 : 3); if (has_ref && ma->conf->capQ_thres > 10) { - int q = bam_cap_mapQ(b, ref, ref_len, ma->conf->capQ_thres); + int q = sam_cap_mapq(b, ref, ref_len, ma->conf->capQ_thres); if (q < 0) skip = 1; else if (b->core.qual > q) b->core.qual = q; } @@ -308,7 +322,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) extern void *bcf_call_add_rg(void *rghash, const char *hdtext, const char *list); extern void bcf_call_del_rghash(void *rghash); mplp_aux_t **data; - int i, tid, pos, *n_plp, beg0 = 0, end0 = INT_MAX, ref_len, max_depth, max_indel_depth; + int i, tid, pos, *n_plp, beg0 = 0, end0 = INT_MAX, tid0 = 0, ref_len, max_depth, max_indel_depth; const bam_pileup1_t **plp; mplp_ref_t mp_ref = MPLP_REF_INIT; bam_mplp_t iter; @@ -379,7 +393,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) fprintf(stderr, "[E::%s] fail to parse region '%s' with %s\n", __func__, conf->reg, fn[i]); exit(EXIT_FAILURE); } - if (i == 0) beg0 = data[i]->iter->beg, end0 = data[i]->iter->end; + if (i == 0) beg0 = data[i]->iter->beg, end0 = data[i]->iter->end, tid0 = data[i]->iter->tid; hts_idx_destroy(idx); } else @@ -551,14 +565,16 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) bam_mplp_set_maxcnt(iter, max_depth); bcf1_t *bcf_rec = bcf_init1(); int ret; + int last_tid = -1, last_pos = -1; + // begin pileup while ( (ret=bam_mplp_auto(iter, &tid, &pos, n_plp, plp)) > 0) { if (conf->reg && (pos < beg0 || pos >= end0)) continue; // out of the region requested - if (conf->bed && tid >= 0 && !bed_overlap(conf->bed, h->target_name[tid], pos, pos+1)) continue; mplp_get_ref(data[0], tid, &ref, &ref_len); //printf("tid=%d len=%d ref=%p/%s\n", tid, ref_len, ref, ref); if (conf->flag & MPLP_BCF) { int total_depth, _ref0, ref16; + if (conf->bed && tid >= 0 && !bed_overlap(conf->bed, h->target_name[tid], pos, pos+1)) continue; for (i = total_depth = 0; i < n; ++i) total_depth += n_plp[i]; group_smpl(&gplp, sm, &buf, n, fn, n_plp, plp, conf->flag & MPLP_IGNORE_RG); _ref0 = (ref && pos < ref_len)? ref[pos] : 'N'; @@ -584,6 +600,35 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) } } } else { + if (conf->all) { + // Deal with missing portions of previous tids + while (tid > last_tid) { + if (last_tid >= 0 && !conf->reg) { + while (++last_pos < h->target_len[last_tid]) { + if (conf->bed && bed_overlap(conf->bed, h->target_name[last_tid], last_pos, last_pos + 1) == 0) + continue; + print_empty_pileup(pileup_fp, conf, h->target_name[last_tid], last_pos, n, ref, ref_len); + } + } + last_tid++; + last_pos = -1; + if (conf->all < 2) + break; + } + } + if (conf->all) { + // Deal with missing portion of current tid + while (++last_pos < pos) { + if (conf->reg && last_pos < beg0) continue; // out of range; skip + if (conf->bed && bed_overlap(conf->bed, h->target_name[tid], last_pos, last_pos + 1) == 0) + continue; + print_empty_pileup(pileup_fp, conf, h->target_name[tid], last_pos, n, ref, ref_len); + } + last_tid = tid; + last_pos = pos; + } + if (conf->bed && tid >= 0 && !bed_overlap(conf->bed, h->target_name[tid], pos, pos+1)) continue; + fprintf(pileup_fp, "%s\t%d\t%c", h->target_name[tid], pos + 1, (ref && pos < ref_len)? ref[pos] : 'N'); for (i = 0; i < n; ++i) { int j, cnt; @@ -599,15 +644,20 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) fputs("*\t*", pileup_fp); if (conf->flag & MPLP_PRINT_MAPQ) fputs("\t*", pileup_fp); if (conf->flag & MPLP_PRINT_POS) fputs("\t*", pileup_fp); + if (conf->flag & MPLP_PRINT_QNAME) fputs("\t*", pileup_fp); } else { + int n = 0; for (j = 0; j < n_plp[i]; ++j) { const bam_pileup1_t *p = plp[i] + j; int c = p->qpos < p->b->core.l_qseq ? bam_get_qual(p->b)[p->qpos] : 0; if (c >= conf->min_baseQ) - pileup_seq(pileup_fp, plp[i] + j, pos, ref_len, ref); + n++, pileup_seq(pileup_fp, plp[i] + j, pos, ref_len, ref); } + if (!n) putc('*', pileup_fp); + + n = 0; putc('\t', pileup_fp); for (j = 0; j < n_plp[i]; ++j) { const bam_pileup1_t *p = plp[i] + j; @@ -617,9 +667,13 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) if (c >= conf->min_baseQ) { c = c + 33 < 126? c + 33 : 126; putc(c, pileup_fp); + n++; } } + if (!n) putc('*', pileup_fp); + if (conf->flag & MPLP_PRINT_MAPQ) { + n = 0; putc('\t', pileup_fp); for (j = 0; j < n_plp[i]; ++j) { const bam_pileup1_t *p = plp[i] + j; @@ -628,19 +682,39 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) c = plp[i][j].b->core.qual + 33; if (c > 126) c = 126; putc(c, pileup_fp); + n++; } + if (!n) putc('*', pileup_fp); } + if (conf->flag & MPLP_PRINT_POS) { + n = 0; putc('\t', pileup_fp); - int last = 0; for (j = 0; j < n_plp[i]; ++j) { const bam_pileup1_t *p = plp[i] + j; int c = bam_get_qual(p->b)[p->qpos]; if ( c < conf->min_baseQ ) continue; - if (last++) putc(',', pileup_fp); + if (n > 0) putc(',', pileup_fp); fprintf(pileup_fp, "%d", plp[i][j].qpos + 1); // FIXME: printf() is very slow... + n++; } + if (!n) putc('*', pileup_fp); + } + + if (conf->flag & MPLP_PRINT_QNAME) { + n = 0; + putc('\t', pileup_fp); + for (j = 0; j < n_plp[i]; ++j) { + const bam_pileup1_t *p = &plp[i][j]; + int c = bam_get_qual(p->b)[p->qpos]; + if ( c < conf->min_baseQ ) continue; + + if (n > 0) putc(',', pileup_fp); + fputs(bam_get_qname(p->b), pileup_fp); + n++; + } + if (!n) putc('*', pileup_fp); } } } @@ -648,6 +722,27 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) } } + if (conf->all && !(conf->flag & MPLP_BCF)) { + // Handle terminating region + if (last_tid < 0 && conf->reg && conf->all > 1) { + last_tid = tid0; + last_pos = beg0-1; + mplp_get_ref(data[0], tid0, &ref, &ref_len); + } + while (last_tid >= 0 && last_tid < h->n_targets) { + while (++last_pos < h->target_len[last_tid]) { + if (last_pos >= end0) break; + if (conf->bed && bed_overlap(conf->bed, h->target_name[last_tid], last_pos, last_pos + 1) == 0) + continue; + print_empty_pileup(pileup_fp, conf, h->target_name[last_tid], last_pos, n, ref, ref_len); + } + last_tid++; + last_pos = -1; + if (conf->all < 2 || conf->reg) + break; + } + } + // clean up free(bc.tmp.s); bcf_destroy1(bcf_rec); @@ -681,6 +776,13 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) return ret; } +static int is_url(const char *s) +{ + static const char uri_scheme_chars[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+.-"; + return s[strspn(s, uri_scheme_chars)] == ':'; +} + #define MAX_PATH_LEN 1024 int read_file_list(const char *file_list,int *n,char **argv[]) { @@ -710,7 +812,7 @@ int read_file_list(const char *file_list,int *n,char **argv[]) // check sanity of the file list buf[len] = 0; - if (stat(buf, &sb) != 0) + if (! (is_url(buf) || stat(buf, &sb) == 0)) { // no such file, check if it is safe to print its name int i, safe_to_print = 1; @@ -814,6 +916,9 @@ static void print_usage(FILE *fp, const mplp_conf_t *mplp) "Output options for mpileup format (without -g/-v):\n" " -O, --output-BP output base positions on reads\n" " -s, --output-MQ output mapping quality\n" +" --output-QNAME output read names\n" +" -a output all positions (including zero depth)\n" +" -a -a (or -aa) output absolutely all positions, including unused ref. sequences\n" "\n" "Output options for genotype likelihoods (when -g/-v is used):\n" " -t, --output-tags LIST optional tags to output:\n" @@ -836,7 +941,7 @@ static void print_usage(FILE *fp, const mplp_conf_t *mplp) fprintf(fp, " -p, --per-sample-mF apply -m and -F per-sample for increased sensitivity\n" " -P, --platforms STR comma separated list of platforms for indels [all]\n"); - sam_global_opt_help(fp, "-.--."); + sam_global_opt_help(fp, "-.--.-"); fprintf(fp, "\n" "Notes: Assuming diploid individuals.\n"); @@ -862,17 +967,20 @@ int bam_mpileup(int argc, char *argv[]) mplp.argc = argc; mplp.argv = argv; mplp.rflag_filter = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP; mplp.output_fname = NULL; + mplp.all = 0; sam_global_args_init(&mplp.ga); static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0, '-'), {"rf", required_argument, NULL, 1}, // require flag {"ff", required_argument, NULL, 2}, // filter flag {"incl-flags", required_argument, NULL, 1}, {"excl-flags", required_argument, NULL, 2}, {"output", required_argument, NULL, 3}, {"open-prob", required_argument, NULL, 4}, + {"output-QNAME", no_argument, NULL, 5}, + {"output-qname", no_argument, NULL, 5}, {"illumina1.3+", no_argument, NULL, '6'}, {"count-orphans", no_argument, NULL, 'A'}, {"bam-list", required_argument, NULL, 'b'}, @@ -916,7 +1024,7 @@ int bam_mpileup(int argc, char *argv[]) {"platforms", required_argument, NULL, 'P'}, {NULL, 0, NULL, 0} }; - while ((c = getopt_long(argc, argv, "Agf:r:l:q:Q:uRC:BDSd:L:b:P:po:e:h:Im:F:EG:6OsVvxt:",lopts,NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "Agf:r:l:q:Q:uRC:BDSd:L:b:P:po:e:h:Im:F:EG:6OsVvxt:a",lopts,NULL)) >= 0) { switch (c) { case 'x': mplp.flag &= ~MPLP_SMART_OVERLAPS; break; case 1 : @@ -929,6 +1037,7 @@ int bam_mpileup(int argc, char *argv[]) break; case 3 : mplp.output_fname = optarg; break; case 4 : mplp.openQ = atoi(optarg); break; + case 5 : mplp.flag |= MPLP_PRINT_QNAME; break; case 'f': mplp.fai = fai_load(optarg); if (mplp.fai == NULL) return 1; @@ -988,6 +1097,7 @@ int bam_mpileup(int argc, char *argv[]) } break; case 't': mplp.fmt_flag |= parse_format_flag(optarg); break; + case 'a': mplp.all++; break; default: if (parse_sam_global_opt(c, optarg, lopts, &mplp.ga) == 0) break; /* else fall-through */ diff --git a/samtools/bam_plcmd.c.pysam.c b/samtools/bam_plcmd.c.pysam.c index 650e81896..77999e65f 100644 --- a/samtools/bam_plcmd.c.pysam.c +++ b/samtools/bam_plcmd.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_plcmd.c -- mpileup subcommand. @@ -33,6 +33,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include #include #include #include @@ -114,13 +115,14 @@ static inline void pileup_seq(FILE *fp, const bam_pileup1_t *p, int pos, int ref #define MPLP_PRINT_MAPQ (1<<10) #define MPLP_PER_SAMPLE (1<<11) #define MPLP_SMART_OVERLAPS (1<<12) +#define MPLP_PRINT_QNAME (1<<13) void *bed_read(const char *fn); void bed_destroy(void *_h); int bed_overlap(const void *_h, const char *chr, int beg, int end); typedef struct { - int min_mq, flag, min_baseQ, capQ_thres, max_depth, max_indel_depth, fmt_flag; + int min_mq, flag, min_baseQ, capQ_thres, max_depth, max_indel_depth, fmt_flag, all; int rflag_require, rflag_filter; int openQ, extQ, tandemQ, min_support; // for indels double min_frac; // for indels @@ -211,11 +213,23 @@ static int mplp_get_ref(mplp_aux_t *ma, int tid, char **ref, int *ref_len) { return 1; } +static void +print_empty_pileup(FILE *fp, const mplp_conf_t *conf, const char *tname, + int pos, int n, const char *ref, int ref_len) +{ + int i; + fprintf(fp, "%s\t%d\t%c", tname, pos+1, (ref && pos < ref_len)? ref[pos] : 'N'); + for (i = 0; i < n; ++i) { + fputs("\t0\t*\t*", fp); + if (conf->flag & MPLP_PRINT_MAPQ) fputs("\t*", fp); + if (conf->flag & MPLP_PRINT_POS) fputs("\t*", fp); + if (conf->flag & MPLP_PRINT_QNAME) fputs("\t*", fp); + } + putc('\n', fp); +} + static int mplp_func(void *data, bam1_t *b) { - extern int bam_realn(bam1_t *b, const char *ref); - extern int bam_prob_realn_core(bam1_t *b, const char *ref, int ref_len, int flag); - extern int bam_cap_mapQ(bam1_t *b, char *ref, int ref_len, int thres); char *ref; mplp_aux_t *ma = (mplp_aux_t*)data; int ret, skip = 0, ref_len; @@ -231,7 +245,7 @@ static int mplp_func(void *data, bam1_t *b) } if (ma->conf->rflag_require && !(ma->conf->rflag_require&b->core.flag)) { skip = 1; continue; } if (ma->conf->rflag_filter && ma->conf->rflag_filter&b->core.flag) { skip = 1; continue; } - if (ma->conf->bed) { // test overlap + if (ma->conf->bed && ma->conf->all == 0) { // test overlap skip = !bed_overlap(ma->conf->bed, ma->h->target_name[b->core.tid], b->core.pos, bam_endpos(b)); if (skip) continue; } @@ -250,7 +264,7 @@ static int mplp_func(void *data, bam1_t *b) if (ma->conf->fai && b->core.tid >= 0) { has_ref = mplp_get_ref(ma, b->core.tid, &ref, &ref_len); if (has_ref && ref_len <= b->core.pos) { // exclude reads outside of the reference sequence - fprintf(pysam_stderr,"[%s] Skipping because %d is outside of %d [ref:%d]\n", + fprintf(samtools_stderr,"[%s] Skipping because %d is outside of %d [ref:%d]\n", __func__, b->core.pos, ref_len, b->core.tid); skip = 1; continue; @@ -260,9 +274,9 @@ static int mplp_func(void *data, bam1_t *b) } skip = 0; - if (has_ref && (ma->conf->flag&MPLP_REALN)) bam_prob_realn_core(b, ref, ref_len, (ma->conf->flag & MPLP_REDO_BAQ)? 7 : 3); + if (has_ref && (ma->conf->flag&MPLP_REALN)) sam_prob_realn(b, ref, ref_len, (ma->conf->flag & MPLP_REDO_BAQ)? 7 : 3); if (has_ref && ma->conf->capQ_thres > 10) { - int q = bam_cap_mapQ(b, ref, ref_len, ma->conf->capQ_thres); + int q = sam_cap_mapq(b, ref, ref_len, ma->conf->capQ_thres); if (q < 0) skip = 1; else if (b->core.qual > q) b->core.qual = q; } @@ -287,7 +301,7 @@ static void group_smpl(mplp_pileup_t *m, bam_sample_t *sm, kstring_t *buf, if (id < 0) id = bam_smpl_rg2smid(sm, fn[i], 0, buf); if (id < 0 || id >= m->n) { assert(q); // otherwise a bug - fprintf(pysam_stderr, "[%s] Read group %s used in file %s but absent from the header or an alignment missing read group.\n", __func__, (char*)q+1, fn[i]); + fprintf(samtools_stderr, "[%s] Read group %s used in file %s but absent from the header or an alignment missing read group.\n", __func__, (char*)q+1, fn[i]); exit(EXIT_FAILURE); } if (m->n_plp[id] == m->m_plp[id]) { @@ -310,7 +324,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) extern void *bcf_call_add_rg(void *rghash, const char *hdtext, const char *list); extern void bcf_call_del_rghash(void *rghash); mplp_aux_t **data; - int i, tid, pos, *n_plp, beg0 = 0, end0 = INT_MAX, ref_len, max_depth, max_indel_depth; + int i, tid, pos, *n_plp, beg0 = 0, end0 = INT_MAX, tid0 = 0, ref_len, max_depth, max_indel_depth; const bam_pileup1_t **plp; mplp_ref_t mp_ref = MPLP_REF_INIT; bam_mplp_t iter; @@ -338,7 +352,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) sm = bam_smpl_init(); if (n == 0) { - fprintf(pysam_stderr,"[%s] no input file/data given\n", __func__); + fprintf(samtools_stderr,"[%s] no input file/data given\n", __func__); exit(EXIT_FAILURE); } @@ -349,15 +363,15 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) data[i]->fp = sam_open_format(fn[i], "rb", &conf->ga.in); if ( !data[i]->fp ) { - fprintf(pysam_stderr, "[%s] failed to open %s: %s\n", __func__, fn[i], strerror(errno)); + fprintf(samtools_stderr, "[%s] failed to open %s: %s\n", __func__, fn[i], strerror(errno)); exit(EXIT_FAILURE); } if (hts_set_opt(data[i]->fp, CRAM_OPT_DECODE_MD, 0)) { - fprintf(pysam_stderr, "Failed to set CRAM_OPT_DECODE_MD value\n"); + fprintf(samtools_stderr, "Failed to set CRAM_OPT_DECODE_MD value\n"); exit(EXIT_FAILURE); } if (conf->fai_fname && hts_set_fai_filename(data[i]->fp, conf->fai_fname) != 0) { - fprintf(pysam_stderr, "[%s] failed to process %s: %s\n", + fprintf(samtools_stderr, "[%s] failed to process %s: %s\n", __func__, conf->fai_fname, strerror(errno)); exit(EXIT_FAILURE); } @@ -365,7 +379,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) data[i]->ref = &mp_ref; h_tmp = sam_hdr_read(data[i]->fp); if ( !h_tmp ) { - fprintf(pysam_stderr,"[%s] fail to read the header of %s\n", __func__, fn[i]); + fprintf(samtools_stderr,"[%s] fail to read the header of %s\n", __func__, fn[i]); exit(EXIT_FAILURE); } bam_smpl_add(sm, fn[i], (conf->flag&MPLP_IGNORE_RG)? 0 : h_tmp->text); @@ -374,14 +388,14 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) if (conf->reg) { hts_idx_t *idx = sam_index_load(data[i]->fp, fn[i]); if (idx == NULL) { - fprintf(pysam_stderr, "[%s] fail to load index for %s\n", __func__, fn[i]); + fprintf(samtools_stderr, "[%s] fail to load index for %s\n", __func__, fn[i]); exit(EXIT_FAILURE); } if ( (data[i]->iter=sam_itr_querys(idx, h_tmp, conf->reg)) == 0) { - fprintf(pysam_stderr, "[E::%s] fail to parse region '%s' with %s\n", __func__, conf->reg, fn[i]); + fprintf(samtools_stderr, "[E::%s] fail to parse region '%s' with %s\n", __func__, conf->reg, fn[i]); exit(EXIT_FAILURE); } - if (i == 0) beg0 = data[i]->iter->beg, end0 = data[i]->iter->end; + if (i == 0) beg0 = data[i]->iter->beg, end0 = data[i]->iter->end, tid0 = data[i]->iter->tid; hts_idx_destroy(idx); } else @@ -403,7 +417,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) gplp.m_plp = calloc(sm->n, sizeof(int)); gplp.plp = calloc(sm->n, sizeof(bam_pileup1_t*)); - fprintf(pysam_stderr, "[%s] %d samples in %d input files\n", __func__, sm->n, n); + fprintf(samtools_stderr, "[%s] %d samples in %d input files\n", __func__, sm->n, n); // write the VCF header if (conf->flag & MPLP_BCF) { @@ -415,7 +429,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) bcf_fp = bcf_open(conf->output_fname? conf->output_fname : "-", mode); if (bcf_fp == NULL) { - fprintf(pysam_stderr, "[%s] failed to write to %s: %s\n", __func__, conf->output_fname? conf->output_fname : "standard output", strerror(errno)); + fprintf(samtools_stderr, "[%s] failed to write to %s: %s\n", __func__, conf->output_fname? conf->output_fname : "standard output", strerror(errno)); exit(EXIT_FAILURE); } @@ -531,10 +545,10 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) } } else { - pileup_fp = conf->output_fname? fopen(conf->output_fname, "w") : pysam_stdout; + pileup_fp = conf->output_fname? fopen(conf->output_fname, "w") : samtools_stdout; if (pileup_fp == NULL) { - fprintf(pysam_stderr, "[%s] failed to write to %s: %s\n", __func__, conf->output_fname, strerror(errno)); + fprintf(samtools_stderr, "[%s] failed to write to %s: %s\n", __func__, conf->output_fname, strerror(errno)); exit(EXIT_FAILURE); } } @@ -544,23 +558,25 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) if ( conf->flag & MPLP_SMART_OVERLAPS ) bam_mplp_init_overlaps(iter); max_depth = conf->max_depth; if (max_depth * sm->n > 1<<20) - fprintf(pysam_stderr, "(%s) Max depth is above 1M. Potential memory hog!\n", __func__); + fprintf(samtools_stderr, "(%s) Max depth is above 1M. Potential memory hog!\n", __func__); if (max_depth * sm->n < 8000) { max_depth = 8000 / sm->n; - fprintf(pysam_stderr, "<%s> Set max per-file depth to %d\n", __func__, max_depth); + fprintf(samtools_stderr, "<%s> Set max per-file depth to %d\n", __func__, max_depth); } max_indel_depth = conf->max_indel_depth * sm->n; bam_mplp_set_maxcnt(iter, max_depth); bcf1_t *bcf_rec = bcf_init1(); int ret; + int last_tid = -1, last_pos = -1; + // begin pileup while ( (ret=bam_mplp_auto(iter, &tid, &pos, n_plp, plp)) > 0) { if (conf->reg && (pos < beg0 || pos >= end0)) continue; // out of the region requested - if (conf->bed && tid >= 0 && !bed_overlap(conf->bed, h->target_name[tid], pos, pos+1)) continue; mplp_get_ref(data[0], tid, &ref, &ref_len); //printf("tid=%d len=%d ref=%p/%s\n", tid, ref_len, ref, ref); if (conf->flag & MPLP_BCF) { int total_depth, _ref0, ref16; + if (conf->bed && tid >= 0 && !bed_overlap(conf->bed, h->target_name[tid], pos, pos+1)) continue; for (i = total_depth = 0; i < n; ++i) total_depth += n_plp[i]; group_smpl(&gplp, sm, &buf, n, fn, n_plp, plp, conf->flag & MPLP_IGNORE_RG); _ref0 = (ref && pos < ref_len)? ref[pos] : 'N'; @@ -586,6 +602,35 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) } } } else { + if (conf->all) { + // Deal with missing portions of previous tids + while (tid > last_tid) { + if (last_tid >= 0 && !conf->reg) { + while (++last_pos < h->target_len[last_tid]) { + if (conf->bed && bed_overlap(conf->bed, h->target_name[last_tid], last_pos, last_pos + 1) == 0) + continue; + print_empty_pileup(pileup_fp, conf, h->target_name[last_tid], last_pos, n, ref, ref_len); + } + } + last_tid++; + last_pos = -1; + if (conf->all < 2) + break; + } + } + if (conf->all) { + // Deal with missing portion of current tid + while (++last_pos < pos) { + if (conf->reg && last_pos < beg0) continue; // out of range; skip + if (conf->bed && bed_overlap(conf->bed, h->target_name[tid], last_pos, last_pos + 1) == 0) + continue; + print_empty_pileup(pileup_fp, conf, h->target_name[tid], last_pos, n, ref, ref_len); + } + last_tid = tid; + last_pos = pos; + } + if (conf->bed && tid >= 0 && !bed_overlap(conf->bed, h->target_name[tid], pos, pos+1)) continue; + fprintf(pileup_fp, "%s\t%d\t%c", h->target_name[tid], pos + 1, (ref && pos < ref_len)? ref[pos] : 'N'); for (i = 0; i < n; ++i) { int j, cnt; @@ -601,15 +646,20 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) fputs("*\t*", pileup_fp); if (conf->flag & MPLP_PRINT_MAPQ) fputs("\t*", pileup_fp); if (conf->flag & MPLP_PRINT_POS) fputs("\t*", pileup_fp); + if (conf->flag & MPLP_PRINT_QNAME) fputs("\t*", pileup_fp); } else { + int n = 0; for (j = 0; j < n_plp[i]; ++j) { const bam_pileup1_t *p = plp[i] + j; int c = p->qpos < p->b->core.l_qseq ? bam_get_qual(p->b)[p->qpos] : 0; if (c >= conf->min_baseQ) - pileup_seq(pileup_fp, plp[i] + j, pos, ref_len, ref); + n++, pileup_seq(pileup_fp, plp[i] + j, pos, ref_len, ref); } + if (!n) putc('*', pileup_fp); + + n = 0; putc('\t', pileup_fp); for (j = 0; j < n_plp[i]; ++j) { const bam_pileup1_t *p = plp[i] + j; @@ -619,9 +669,13 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) if (c >= conf->min_baseQ) { c = c + 33 < 126? c + 33 : 126; putc(c, pileup_fp); + n++; } } + if (!n) putc('*', pileup_fp); + if (conf->flag & MPLP_PRINT_MAPQ) { + n = 0; putc('\t', pileup_fp); for (j = 0; j < n_plp[i]; ++j) { const bam_pileup1_t *p = plp[i] + j; @@ -630,19 +684,39 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) c = plp[i][j].b->core.qual + 33; if (c > 126) c = 126; putc(c, pileup_fp); + n++; } + if (!n) putc('*', pileup_fp); } + if (conf->flag & MPLP_PRINT_POS) { + n = 0; putc('\t', pileup_fp); - int last = 0; for (j = 0; j < n_plp[i]; ++j) { const bam_pileup1_t *p = plp[i] + j; int c = bam_get_qual(p->b)[p->qpos]; if ( c < conf->min_baseQ ) continue; - if (last++) putc(',', pileup_fp); - fprintf(pileup_fp, "%d", plp[i][j].qpos + 1); // FIXME: fprintf(pysam_stdout, ) is very slow... + if (n > 0) putc(',', pileup_fp); + fprintf(pileup_fp, "%d", plp[i][j].qpos + 1); // FIXME: fprintf(samtools_stdout, ) is very slow... + n++; } + if (!n) putc('*', pileup_fp); + } + + if (conf->flag & MPLP_PRINT_QNAME) { + n = 0; + putc('\t', pileup_fp); + for (j = 0; j < n_plp[i]; ++j) { + const bam_pileup1_t *p = &plp[i][j]; + int c = bam_get_qual(p->b)[p->qpos]; + if ( c < conf->min_baseQ ) continue; + + if (n > 0) putc(',', pileup_fp); + fputs(bam_get_qname(p->b), pileup_fp); + n++; + } + if (!n) putc('*', pileup_fp); } } } @@ -650,6 +724,27 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) } } + if (conf->all && !(conf->flag & MPLP_BCF)) { + // Handle terminating region + if (last_tid < 0 && conf->reg && conf->all > 1) { + last_tid = tid0; + last_pos = beg0-1; + mplp_get_ref(data[0], tid0, &ref, &ref_len); + } + while (last_tid >= 0 && last_tid < h->n_targets) { + while (++last_pos < h->target_len[last_tid]) { + if (last_pos >= end0) break; + if (conf->bed && bed_overlap(conf->bed, h->target_name[last_tid], last_pos, last_pos + 1) == 0) + continue; + print_empty_pileup(pileup_fp, conf, h->target_name[last_tid], last_pos, n, ref, ref_len); + } + last_tid++; + last_pos = -1; + if (conf->all < 2 || conf->reg) + break; + } + } + // clean up free(bc.tmp.s); bcf_destroy1(bcf_rec); @@ -683,6 +778,13 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) return ret; } +static int is_url(const char *s) +{ + static const char uri_scheme_chars[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+.-"; + return s[strspn(s, uri_scheme_chars)] == ':'; +} + #define MAX_PATH_LEN 1024 int read_file_list(const char *file_list,int *n,char **argv[]) { @@ -697,7 +799,7 @@ int read_file_list(const char *file_list,int *n,char **argv[]) FILE *fh = fopen(file_list,"r"); if ( !fh ) { - fprintf(pysam_stderr,"%s: %s\n", file_list,strerror(errno)); + fprintf(samtools_stderr,"%s: %s\n", file_list,strerror(errno)); return 1; } @@ -712,16 +814,16 @@ int read_file_list(const char *file_list,int *n,char **argv[]) // check sanity of the file list buf[len] = 0; - if (stat(buf, &sb) != 0) + if (! (is_url(buf) || stat(buf, &sb) == 0)) { // no such file, check if it is safe to print its name int i, safe_to_print = 1; for (i=0; i= 0) { + while ((c = getopt_long(argc, argv, "Agf:r:l:q:Q:uRC:BDSd:L:b:P:po:e:h:Im:F:EG:6OsVvxt:a",lopts,NULL)) >= 0) { switch (c) { case 'x': mplp.flag &= ~MPLP_SMART_OVERLAPS; break; case 1 : mplp.rflag_require = bam_str2flag(optarg); - if ( mplp.rflag_require<0 ) { fprintf(pysam_stderr,"Could not parse --rf %s\n", optarg); return 1; } + if ( mplp.rflag_require<0 ) { fprintf(samtools_stderr,"Could not parse --rf %s\n", optarg); return 1; } break; case 2 : mplp.rflag_filter = bam_str2flag(optarg); - if ( mplp.rflag_filter<0 ) { fprintf(pysam_stderr,"Could not parse --ff %s\n", optarg); return 1; } + if ( mplp.rflag_filter<0 ) { fprintf(samtools_stderr,"Could not parse --ff %s\n", optarg); return 1; } break; case 3 : mplp.output_fname = optarg; break; case 4 : mplp.openQ = atoi(optarg); break; + case 5 : mplp.flag |= MPLP_PRINT_QNAME; break; case 'f': mplp.fai = fai_load(optarg); if (mplp.fai == NULL) return 1; @@ -951,9 +1060,9 @@ int bam_mpileup(int argc, char *argv[]) case 'v': mplp.flag |= MPLP_BCF | MPLP_VCF; break; case 'u': mplp.flag |= MPLP_NO_COMP | MPLP_BCF; break; case 'B': mplp.flag &= ~MPLP_REALN; break; - case 'D': mplp.fmt_flag |= B2B_FMT_DP; fprintf(pysam_stderr, "[warning] samtools mpileup option `-D` is functional, but deprecated. Please switch to `-t DP` in future.\n"); break; - case 'S': mplp.fmt_flag |= B2B_FMT_SP; fprintf(pysam_stderr, "[warning] samtools mpileup option `-S` is functional, but deprecated. Please switch to `-t SP` in future.\n"); break; - case 'V': mplp.fmt_flag |= B2B_FMT_DV; fprintf(pysam_stderr, "[warning] samtools mpileup option `-V` is functional, but deprecated. Please switch to `-t DV` in future.\n"); break; + case 'D': mplp.fmt_flag |= B2B_FMT_DP; fprintf(samtools_stderr, "[warning] samtools mpileup option `-D` is functional, but deprecated. Please switch to `-t DP` in future.\n"); break; + case 'S': mplp.fmt_flag |= B2B_FMT_SP; fprintf(samtools_stderr, "[warning] samtools mpileup option `-S` is functional, but deprecated. Please switch to `-t SP` in future.\n"); break; + case 'V': mplp.fmt_flag |= B2B_FMT_DV; fprintf(samtools_stderr, "[warning] samtools mpileup option `-V` is functional, but deprecated. Please switch to `-t DV` in future.\n"); break; case 'I': mplp.flag |= MPLP_NO_INDEL; break; case 'E': mplp.flag |= MPLP_REDO_BAQ; break; case '6': mplp.flag |= MPLP_ILLUMINA13; break; @@ -983,18 +1092,19 @@ int bam_mpileup(int argc, char *argv[]) char buf[1024]; mplp.rghash = khash_str2int_init(); if ((fp_rg = fopen(optarg, "r")) == NULL) - fprintf(pysam_stderr, "(%s) Fail to open file %s. Continue anyway.\n", __func__, optarg); + fprintf(samtools_stderr, "(%s) Fail to open file %s. Continue anyway.\n", __func__, optarg); while (!feof(fp_rg) && fscanf(fp_rg, "%s", buf) > 0) // this is not a good style, but forgive me... khash_str2int_inc(mplp.rghash, strdup(buf)); fclose(fp_rg); } break; case 't': mplp.fmt_flag |= parse_format_flag(optarg); break; + case 'a': mplp.all++; break; default: if (parse_sam_global_opt(c, optarg, lopts, &mplp.ga) == 0) break; /* else fall-through */ case '?': - print_usage(pysam_stderr, &mplp); + print_usage(samtools_stderr, &mplp); return 1; } } @@ -1006,13 +1116,13 @@ int bam_mpileup(int argc, char *argv[]) if ( !(mplp.flag&MPLP_REALN) && mplp.flag&MPLP_REDO_BAQ ) { - fprintf(pysam_stderr,"Error: The -B option cannot be combined with -E\n"); + fprintf(samtools_stderr,"Error: The -B option cannot be combined with -E\n"); return 1; } if (use_orphan) mplp.flag &= ~MPLP_NO_ORPHAN; if (argc == 1) { - print_usage(pysam_stderr, &mplp); + print_usage(samtools_stderr, &mplp); return 1; } int ret; diff --git a/samtools/bam_quickcheck.c b/samtools/bam_quickcheck.c index 6c3c66452..e7c239798 100644 --- a/samtools/bam_quickcheck.c +++ b/samtools/bam_quickcheck.c @@ -26,48 +26,70 @@ DEALINGS IN THE SOFTWARE. */ #include #include -#include #include #include #include +/* File status flags (zero means OK). It's possible for more than one to be + * set on a single file. The final exit status is the bitwise-or of the + * status of all the files. */ +#define QC_FAIL_OPEN 2 +#define QC_NOT_SEQUENCE 4 +#define QC_BAD_HEADER 8 +#define QC_NO_EOF_BLOCK 16 +#define QC_FAIL_CLOSE 32 + static void usage_quickcheck(FILE *write_to) { fprintf(write_to, "Usage: samtools quickcheck [options] [...]\n" "Options:\n" " -v verbose output (repeat for more verbosity)\n" +" -q suppress warning messages\n" "\n" "Notes:\n" "\n" -"1. In order to use this command effectively, you should check its exit status;\n" -" without any -v options it will NOT print any output, even when some files\n" -" fail the check. One way to use quickcheck might be as a check that all\n" -" BAM files in a directory are okay:\n" +"1. By default quickcheck will emit a warning message if and only if a file\n" +" fails the checks, in which case the exit status is non-zero. Under normal\n" +" behaviour with valid data it will be silent and has a zero exit status.\n" +" The warning messages are purely for manual inspection and should not be \n" +" parsed by scripts.\n" +"\n" +"2. In order to use this command programmatically, you should check its exit\n" +" status. One way to use quickcheck might be as a check that all BAM files in\n" +" a directory are okay:\n" "\n" "\tsamtools quickcheck *.bam && echo 'all ok' \\\n" "\t || echo 'fail!'\n" "\n" -" To also determine which files have failed, use the -v option:\n" +" The first level of verbosity lists only files that fail to stdout.\n" +" To obtain a parsable list of files that have failed, use this option:\n" "\n" -"\tsamtools quickcheck -v *.bam > bad_bams.fofn \\\n" +"\tsamtools quickcheck -qv *.bam > bad_bams.fofn \\\n" "\t && echo 'all ok' \\\n" "\t || echo 'some files failed check, see bad_bams.fofn'\n" ); } +#define QC_ERR(state, v, msg, arg1) \ + file_state |= (state); \ + if (!quiet || verbose >= (v)) fprintf(stderr, (msg), (arg1)) + int main_quickcheck(int argc, char** argv) { - int verbose = 0; + int verbose = 0, quiet = 0; hts_verbose = 0; - const char* optstring = "v"; + const char* optstring = "vq"; int opt; while ((opt = getopt(argc, argv, optstring)) != -1) { switch (opt) { case 'v': verbose++; break; + case 'q': + quiet = 1; + break; default: usage_quickcheck(stderr); return 1; @@ -102,45 +124,55 @@ int main_quickcheck(int argc, char** argv) // attempt to open htsFile *hts_fp = hts_open(fn, "r"); if (hts_fp == NULL) { - if (verbose >= 2) fprintf(stderr, "%s could not be opened for reading\n", fn); - file_state |= 2; + QC_ERR(QC_FAIL_OPEN, 2, "%s could not be opened for reading.\n", fn); } else { if (verbose >= 3) fprintf(stderr, "opened %s\n", fn); // make sure we have sequence data const htsFormat *fmt = hts_get_format(hts_fp); if (fmt->category != sequence_data ) { - if (verbose >= 2) fprintf(stderr, "%s was not identified as sequence data\n", fn); - file_state |= 4; + QC_ERR(QC_NOT_SEQUENCE, 2, "%s was not identified as sequence data.\n", fn); } else { if (verbose >= 3) fprintf(stderr, "%s is sequence data\n", fn); // check header bam_hdr_t *header = sam_hdr_read(hts_fp); - if (header->n_targets <= 0) { - if (verbose >= 2) fprintf(stderr, "%s had no targets in header\n", fn); - file_state |= 8; - } - else { - if (verbose >= 3) fprintf(stderr, "%s has %d targets in header\n", fn, header->n_targets); - } - - // only check EOF on BAM for now - // TODO implement and use hts_check_EOF() to include CRAM support - if (fmt->format == bam) { - if (bgzf_check_EOF(hts_fp->fp.bgzf) <= 0) { - if (verbose >= 2) fprintf(stderr, "%s was missing EOF block\n", fn); - file_state |= 16; + if (header == NULL) { + QC_ERR(QC_BAD_HEADER, 2, "%s caused an error whilst reading its header.\n", fn); + } else { + if (header->n_targets <= 0) { + QC_ERR(QC_BAD_HEADER, 2, "%s had no targets in header.\n", fn); } else { - if (verbose >= 3) fprintf(stderr, "%s has good EOF block\n", fn); + if (verbose >= 3) fprintf(stderr, "%s has %d targets in header.\n", fn, header->n_targets); } + bam_hdr_destroy(header); + } + } + // check EOF on formats that support this + int ret; + if ((ret = hts_check_EOF(hts_fp)) < 0) { + QC_ERR(QC_NO_EOF_BLOCK, 2, "%s caused an error whilst checking for EOF block.\n", fn); + } + else { + switch (ret) { + case 0: + QC_ERR(QC_NO_EOF_BLOCK, 2, "%s was missing EOF block when one should be present.\n", fn); + break; + case 1: + if (verbose >= 3) fprintf(stderr, "%s has good EOF block.\n", fn); + break; + case 2: + if (verbose >= 3) fprintf(stderr, "%s cannot be checked for EOF block as it is not seekable.\n", fn); + break; + case 3: + if (verbose >= 3) fprintf(stderr, "%s cannot be checked for EOF block because its filetype does not contain one.\n", fn); + break; } } if (hts_close(hts_fp) < 0) { - file_state |= 32; - if (verbose >= 2) fprintf(stderr, "%s did not close cleanly\n", fn); + QC_ERR(QC_FAIL_CLOSE, 2, "%s did not close cleanly.\n", fn); } } diff --git a/samtools/bam_quickcheck.c.pysam.c b/samtools/bam_quickcheck.c.pysam.c index 26dbeb9ab..fc0af2e2e 100644 --- a/samtools/bam_quickcheck.c.pysam.c +++ b/samtools/bam_quickcheck.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_quickcheck.c -- quickcheck subcommand. @@ -28,50 +28,72 @@ DEALINGS IN THE SOFTWARE. */ #include #include -#include #include #include #include +/* File status flags (zero means OK). It's possible for more than one to be + * set on a single file. The final exit status is the bitwise-or of the + * status of all the files. */ +#define QC_FAIL_OPEN 2 +#define QC_NOT_SEQUENCE 4 +#define QC_BAD_HEADER 8 +#define QC_NO_EOF_BLOCK 16 +#define QC_FAIL_CLOSE 32 + static void usage_quickcheck(FILE *write_to) { fprintf(write_to, "Usage: samtools quickcheck [options] [...]\n" "Options:\n" " -v verbose output (repeat for more verbosity)\n" +" -q suppress warning messages\n" "\n" "Notes:\n" "\n" -"1. In order to use this command effectively, you should check its exit status;\n" -" without any -v options it will NOT print any output, even when some files\n" -" fail the check. One way to use quickcheck might be as a check that all\n" -" BAM files in a directory are okay:\n" +"1. By default quickcheck will emit a warning message if and only if a file\n" +" fails the checks, in which case the exit status is non-zero. Under normal\n" +" behaviour with valid data it will be silent and has a zero exit status.\n" +" The warning messages are purely for manual inspection and should not be \n" +" parsed by scripts.\n" +"\n" +"2. In order to use this command programmatically, you should check its exit\n" +" status. One way to use quickcheck might be as a check that all BAM files in\n" +" a directory are okay:\n" "\n" "\tsamtools quickcheck *.bam && echo 'all ok' \\\n" "\t || echo 'fail!'\n" "\n" -" To also determine which files have failed, use the -v option:\n" +" The first level of verbosity lists only files that fail to samtools_stdout.\n" +" To obtain a parsable list of files that have failed, use this option:\n" "\n" -"\tsamtools quickcheck -v *.bam > bad_bams.fofn \\\n" +"\tsamtools quickcheck -qv *.bam > bad_bams.fofn \\\n" "\t && echo 'all ok' \\\n" "\t || echo 'some files failed check, see bad_bams.fofn'\n" ); } +#define QC_ERR(state, v, msg, arg1) \ + file_state |= (state); \ + if (!quiet || verbose >= (v)) fprintf(samtools_stderr, (msg), (arg1)) + int main_quickcheck(int argc, char** argv) { - int verbose = 0; + int verbose = 0, quiet = 0; hts_verbose = 0; - const char* optstring = "v"; + const char* optstring = "vq"; int opt; while ((opt = getopt(argc, argv, optstring)) != -1) { switch (opt) { case 'v': verbose++; break; + case 'q': + quiet = 1; + break; default: - usage_quickcheck(pysam_stderr); + usage_quickcheck(samtools_stderr); return 1; } } @@ -80,12 +102,12 @@ int main_quickcheck(int argc, char** argv) argv += optind; if (argc < 1) { - usage_quickcheck(pysam_stdout); + usage_quickcheck(samtools_stdout); return 1; } if (verbose >= 2) { - fprintf(pysam_stderr, "verbosity set to %d\n", verbose); + fprintf(samtools_stderr, "verbosity set to %d\n", verbose); } if (verbose >= 4) { @@ -99,55 +121,65 @@ int main_quickcheck(int argc, char** argv) char* fn = argv[i]; int file_state = 0; - if (verbose >= 3) fprintf(pysam_stderr, "checking %s\n", fn); + if (verbose >= 3) fprintf(samtools_stderr, "checking %s\n", fn); // attempt to open htsFile *hts_fp = hts_open(fn, "r"); if (hts_fp == NULL) { - if (verbose >= 2) fprintf(pysam_stderr, "%s could not be opened for reading\n", fn); - file_state |= 2; + QC_ERR(QC_FAIL_OPEN, 2, "%s could not be opened for reading.\n", fn); } else { - if (verbose >= 3) fprintf(pysam_stderr, "opened %s\n", fn); + if (verbose >= 3) fprintf(samtools_stderr, "opened %s\n", fn); // make sure we have sequence data const htsFormat *fmt = hts_get_format(hts_fp); if (fmt->category != sequence_data ) { - if (verbose >= 2) fprintf(pysam_stderr, "%s was not identified as sequence data\n", fn); - file_state |= 4; + QC_ERR(QC_NOT_SEQUENCE, 2, "%s was not identified as sequence data.\n", fn); } else { - if (verbose >= 3) fprintf(pysam_stderr, "%s is sequence data\n", fn); + if (verbose >= 3) fprintf(samtools_stderr, "%s is sequence data\n", fn); // check header bam_hdr_t *header = sam_hdr_read(hts_fp); - if (header->n_targets <= 0) { - if (verbose >= 2) fprintf(pysam_stderr, "%s had no targets in header\n", fn); - file_state |= 8; - } - else { - if (verbose >= 3) fprintf(pysam_stderr, "%s has %d targets in header\n", fn, header->n_targets); - } - - // only check EOF on BAM for now - // TODO implement and use hts_check_EOF() to include CRAM support - if (fmt->format == bam) { - if (bgzf_check_EOF(hts_fp->fp.bgzf) <= 0) { - if (verbose >= 2) fprintf(pysam_stderr, "%s was missing EOF block\n", fn); - file_state |= 16; + if (header == NULL) { + QC_ERR(QC_BAD_HEADER, 2, "%s caused an error whilst reading its header.\n", fn); + } else { + if (header->n_targets <= 0) { + QC_ERR(QC_BAD_HEADER, 2, "%s had no targets in header.\n", fn); } else { - if (verbose >= 3) fprintf(pysam_stderr, "%s has good EOF block\n", fn); + if (verbose >= 3) fprintf(samtools_stderr, "%s has %d targets in header.\n", fn, header->n_targets); } + bam_hdr_destroy(header); + } + } + // check EOF on formats that support this + int ret; + if ((ret = hts_check_EOF(hts_fp)) < 0) { + QC_ERR(QC_NO_EOF_BLOCK, 2, "%s caused an error whilst checking for EOF block.\n", fn); + } + else { + switch (ret) { + case 0: + QC_ERR(QC_NO_EOF_BLOCK, 2, "%s was missing EOF block when one should be present.\n", fn); + break; + case 1: + if (verbose >= 3) fprintf(samtools_stderr, "%s has good EOF block.\n", fn); + break; + case 2: + if (verbose >= 3) fprintf(samtools_stderr, "%s cannot be checked for EOF block as it is not seekable.\n", fn); + break; + case 3: + if (verbose >= 3) fprintf(samtools_stderr, "%s cannot be checked for EOF block because its filetype does not contain one.\n", fn); + break; } } if (hts_close(hts_fp) < 0) { - file_state |= 32; - if (verbose >= 2) fprintf(pysam_stderr, "%s did not close cleanly\n", fn); + QC_ERR(QC_FAIL_CLOSE, 2, "%s did not close cleanly.\n", fn); } } if (file_state > 0 && verbose >= 1) { - fprintf(pysam_stdout, "%s\n", fn); + fprintf(samtools_stdout, "%s\n", fn); } ret |= file_state; } diff --git a/samtools/bam_reheader.c b/samtools/bam_reheader.c index 0469c0671..acaebd409 100644 --- a/samtools/bam_reheader.c +++ b/samtools/bam_reheader.c @@ -91,7 +91,7 @@ int bam_reheader(BGZF *in, bam_hdr_t *h, int fd, goto fail; } if (in->block_offset < in->block_length) { - if (bgzf_write(fp, in->uncompressed_block + in->block_offset, in->block_length - in->block_offset) < 0) goto write_fail; + if (bgzf_write(fp, (char *)in->uncompressed_block + in->block_offset, in->block_length - in->block_offset) < 0) goto write_fail; if (bgzf_flush(fp) < 0) goto write_fail; } while ((len = bgzf_raw_read(in, buf, BUF_SIZE)) > 0) { @@ -246,7 +246,7 @@ int cram_reheader_inplace2(cram_fd *fd, const bam_hdr_t *h, const char *arg_list int32_put_blk(b, header_len); cram_block_append(b, sam_hdr_str(hdr), header_len); // Zero the remaining block - memset(cram_block_get_data(b)+cram_block_get_offset(b), 0, + memset((char *)cram_block_get_data(b)+cram_block_get_offset(b), 0, cram_block_get_uncomp_size(b) - cram_block_get_offset(b)); // Make sure all sizes and byte-offsets are consistent after memset cram_block_set_offset(b, cram_block_get_uncomp_size(b)); diff --git a/samtools/bam_reheader.c.pysam.c b/samtools/bam_reheader.c.pysam.c index 16990e69e..4ba635364 100644 --- a/samtools/bam_reheader.c.pysam.c +++ b/samtools/bam_reheader.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_reheader.c -- reheader subcommand. @@ -54,11 +54,11 @@ int bam_reheader(BGZF *in, bam_hdr_t *h, int fd, if (in->is_write) return -1; buf = malloc(BUF_SIZE); if (!buf) { - fprintf(pysam_stderr, "Out of memory\n"); + fprintf(samtools_stderr, "Out of memory\n"); return -1; } if (bam_hdr_read(in) == NULL) { - fprintf(pysam_stderr, "Couldn't read header\n"); + fprintf(samtools_stderr, "Couldn't read header\n"); goto fail; } fp = bgzf_fdopen(fd, "w"); @@ -93,20 +93,20 @@ int bam_reheader(BGZF *in, bam_hdr_t *h, int fd, goto fail; } if (in->block_offset < in->block_length) { - if (bgzf_write(fp, in->uncompressed_block + in->block_offset, in->block_length - in->block_offset) < 0) goto write_fail; + if (bgzf_write(fp, (char *)in->uncompressed_block + in->block_offset, in->block_length - in->block_offset) < 0) goto write_fail; if (bgzf_flush(fp) < 0) goto write_fail; } while ((len = bgzf_raw_read(in, buf, BUF_SIZE)) > 0) { if (bgzf_raw_write(fp, buf, len) < 0) goto write_fail; } if (len < 0) { - fprintf(pysam_stderr, "[%s] Error reading input file\n", __func__); + fprintf(samtools_stderr, "[%s] Error reading input file\n", __func__); goto fail; } free(buf); fp->block_offset = in->block_offset = 0; if (bgzf_close(fp) < 0) { - fprintf(pysam_stderr, "[%s] Error closing output file\n", __func__); + fprintf(samtools_stderr, "[%s] Error closing output file\n", __func__); return -1; } return 0; @@ -121,7 +121,7 @@ int bam_reheader(BGZF *in, bam_hdr_t *h, int fd, } /* - * Reads a file and outputs a new CRAM file to pysam_stdout with 'h' + * Reads a file and outputs a new CRAM file to samtools_stdout with 'h' * replaced as the header. No checks are made to the validity. * * FIXME: error checking @@ -205,7 +205,7 @@ int cram_reheader_inplace2(cram_fd *fd, const bam_hdr_t *h, const char *arg_list if (cram_major_vers(fd) < 2 || cram_major_vers(fd) > 3) { - fprintf(pysam_stderr, "[%s] unsupported CRAM version %d\n", __func__, + fprintf(samtools_stderr, "[%s] unsupported CRAM version %d\n", __func__, cram_major_vers(fd)); goto err; } @@ -238,7 +238,7 @@ int cram_reheader_inplace2(cram_fd *fd, const bam_hdr_t *h, const char *arg_list goto err; if (cram_block_get_uncomp_size(b) < header_len+4) { - fprintf(pysam_stderr, "New header will not fit. Use non-inplace version (%d > %d)\n", + fprintf(samtools_stderr, "New header will not fit. Use non-inplace version (%d > %d)\n", header_len+4, cram_block_get_uncomp_size(b)); ret = -2; goto err; @@ -248,7 +248,7 @@ int cram_reheader_inplace2(cram_fd *fd, const bam_hdr_t *h, const char *arg_list int32_put_blk(b, header_len); cram_block_append(b, sam_hdr_str(hdr), header_len); // Zero the remaining block - memset(cram_block_get_data(b)+cram_block_get_offset(b), 0, + memset((char *)cram_block_get_data(b)+cram_block_get_offset(b), 0, cram_block_get_uncomp_size(b) - cram_block_get_offset(b)); // Make sure all sizes and byte-offsets are consistent after memset cram_block_set_offset(b, cram_block_get_uncomp_size(b)); @@ -301,7 +301,7 @@ int cram_reheader_inplace3(cram_fd *fd, const bam_hdr_t *h, const char *arg_list if (cram_major_vers(fd) < 2 || cram_major_vers(fd) > 3) { - fprintf(pysam_stderr, "[%s] unsupported CRAM version %d\n", __func__, + fprintf(samtools_stderr, "[%s] unsupported CRAM version %d\n", __func__, cram_major_vers(fd)); goto err; } @@ -373,7 +373,7 @@ int cram_reheader_inplace3(cram_fd *fd, const bam_hdr_t *h, const char *arg_list goto err; if (old_container_sz != container_sz) { - fprintf(pysam_stderr, "Quirk of fate makes this troublesome! " + fprintf(samtools_stderr, "Quirk of fate makes this troublesome! " "Please use non-inplace version.\n"); goto err; } @@ -392,7 +392,7 @@ int cram_reheader_inplace3(cram_fd *fd, const bam_hdr_t *h, const char *arg_list goto err; if (cram_block_size(b) > cram_container_get_length(c)) { - fprintf(pysam_stderr, "New header will not fit. Use non-inplace version" + fprintf(samtools_stderr, "New header will not fit. Use non-inplace version" " (%d > %d)\n", (int)cram_block_size(b), cram_container_get_length(c)); ret = -2; @@ -430,7 +430,7 @@ int cram_reheader_inplace(cram_fd *fd, const bam_hdr_t *h, const char *arg_list, case 2: return cram_reheader_inplace2(fd, h, arg_list, add_PG); case 3: return cram_reheader_inplace3(fd, h, arg_list, add_PG); default: - fprintf(pysam_stderr, "[%s] unsupported CRAM version %d\n", __func__, + fprintf(samtools_stderr, "[%s] unsupported CRAM version %d\n", __func__, cram_major_vers(fd)); return -1; } @@ -444,7 +444,7 @@ static void usage(FILE *fp, int ret) { "Options:\n" " -P, --no-PG Do not generate an @PG header line.\n" " -i, --in-place Modify the bam/cram file directly.\n" - " (Defaults to outputting to pysam_stdout.)\n"); + " (Defaults to outputting to samtools_stdout.)\n"); exit(ret); } @@ -466,15 +466,15 @@ int main_reheader(int argc, char *argv[]) switch (c) { case 'P': add_PG = 0; break; case 'i': inplace = 1; break; - case 'h': usage(pysam_stdout, 0); break; + case 'h': usage(samtools_stdout, 0); break; default: - fprintf(pysam_stderr, "Invalid option '%c'\n", c); - usage(pysam_stderr, 1); + fprintf(samtools_stderr, "Invalid option '%c'\n", c); + usage(samtools_stderr, 1); } } if (argc - optind != 2) - usage(pysam_stderr, 1); + usage(samtools_stderr, 1); { // read the header samFile *fph = sam_open(argv[optind], "r"); @@ -485,7 +485,7 @@ int main_reheader(int argc, char *argv[]) h = sam_hdr_read(fph); sam_close(fph); if (h == NULL) { - fprintf(pysam_stderr, "[%s] failed to read the header for '%s'.\n", + fprintf(samtools_stderr, "[%s] failed to read the header for '%s'.\n", __func__, argv[1]); return 1; } @@ -496,7 +496,7 @@ int main_reheader(int argc, char *argv[]) return 1; } if (hts_get_format(in)->format == bam) { - r = bam_reheader(in->fp.bgzf, h, fileno(pysam_stdout), arg_list, add_PG); + r = bam_reheader(in->fp.bgzf, h, fileno(samtools_stdout), arg_list, add_PG); } else { if (inplace) r = cram_reheader_inplace(in->fp.cram, h, arg_list, add_PG); diff --git a/samtools/bam_rmdup.c b/samtools/bam_rmdup.c index 57612b40a..513848d66 100644 --- a/samtools/bam_rmdup.c +++ b/samtools/bam_rmdup.c @@ -258,7 +258,7 @@ static int rmdup_usage(void) { fprintf(stderr, "Option: -s rmdup for SE reads\n"); fprintf(stderr, " -S treat PE reads as SE in rmdup (force -s)\n"); - sam_global_opt_help(stderr, "-...."); + sam_global_opt_help(stderr, "-....-"); return 1; } @@ -271,7 +271,7 @@ int bam_rmdup(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0, '-'), { NULL, 0, NULL, 0 } }; diff --git a/samtools/bam_rmdup.c.pysam.c b/samtools/bam_rmdup.c.pysam.c index 3c160259e..64326de77 100644 --- a/samtools/bam_rmdup.c.pysam.c +++ b/samtools/bam_rmdup.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_rmdup.c -- duplicate read detection. @@ -156,7 +156,7 @@ int bam_rmdup_core(samFile *in, bam_hdr_t *hdr, samFile *out) if (c->tid != last_tid) { clear_best(aux, 0); if (kh_size(del_set)) { // check - fprintf(pysam_stderr, "[bam_rmdup_core] %llu unmatched pairs\n", (long long)kh_size(del_set)); + fprintf(samtools_stderr, "[bam_rmdup_core] %llu unmatched pairs\n", (long long)kh_size(del_set)); clear_del_set(del_set); } if ((int)c->tid == -1) { // append unmapped reads @@ -167,7 +167,7 @@ int bam_rmdup_core(samFile *in, bam_hdr_t *hdr, samFile *out) break; } last_tid = c->tid; - fprintf(pysam_stderr, "[bam_rmdup_core] processing reference %s...\n", hdr->target_name[c->tid]); + fprintf(samtools_stderr, "[bam_rmdup_core] processing reference %s...\n", hdr->target_name[c->tid]); } } if (!(c->flag&BAM_FPAIRED) || (c->flag&(BAM_FUNMAP|BAM_FMUNMAP)) || (c->mtid >= 0 && c->tid != c->mtid)) { @@ -189,7 +189,7 @@ int bam_rmdup_core(samFile *in, bam_hdr_t *hdr, samFile *out) bam_copy1(p, b); // replaced as b } else kh_put(name, del_set, strdup(bam_get_qname(b)), &ret); // b will be removed if (ret == 0) - fprintf(pysam_stderr, "[bam_rmdup_core] inconsistent BAM file for pair '%s'. Continue anyway.\n", bam_get_qname(b)); + fprintf(samtools_stderr, "[bam_rmdup_core] inconsistent BAM file for pair '%s'. Continue anyway.\n", bam_get_qname(b)); } else { // not found in best_hash kh_val(q->best_hash, k) = bam_dup1(b); stack_insert(&stack, kh_val(q->best_hash, k)); @@ -206,7 +206,7 @@ int bam_rmdup_core(samFile *in, bam_hdr_t *hdr, samFile *out) last_pos = c->pos; } if (r < -1) { - fprintf(pysam_stderr, "[%s] failed to read input file\n", __func__); + fprintf(samtools_stderr, "[%s] failed to read input file\n", __func__); goto fail; } @@ -214,7 +214,7 @@ int bam_rmdup_core(samFile *in, bam_hdr_t *hdr, samFile *out) if (kh_exist(aux, k)) { lib_aux_t *q = &kh_val(aux, k); if (dump_best(&stack, out, hdr) < 0) goto write_fail; - fprintf(pysam_stderr, "[bam_rmdup_core] %lld / %lld = %.4lf in library '%s'\n", (long long)q->n_removed, + fprintf(samtools_stderr, "[bam_rmdup_core] %lld / %lld = %.4lf in library '%s'\n", (long long)q->n_removed, (long long)q->n_checked, (double)q->n_removed/q->n_checked, kh_key(aux, k)); kh_destroy(pos, q->best_hash); free((char*)kh_key(aux, k)); @@ -255,12 +255,12 @@ int bam_rmdup_core(samFile *in, bam_hdr_t *hdr, samFile *out) int bam_rmdupse_core(samFile *in, bam_hdr_t *hdr, samFile *out, int force_se); static int rmdup_usage(void) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Usage: samtools rmdup [-sS] \n\n"); - fprintf(pysam_stderr, "Option: -s rmdup for SE reads\n"); - fprintf(pysam_stderr, " -S treat PE reads as SE in rmdup (force -s)\n"); + fprintf(samtools_stderr, "\n"); + fprintf(samtools_stderr, "Usage: samtools rmdup [-sS] \n\n"); + fprintf(samtools_stderr, "Option: -s rmdup for SE reads\n"); + fprintf(samtools_stderr, " -S treat PE reads as SE in rmdup (force -s)\n"); - sam_global_opt_help(pysam_stderr, "-...."); + sam_global_opt_help(samtools_stderr, "-....-"); return 1; } @@ -273,7 +273,7 @@ int bam_rmdup(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0, '-'), { NULL, 0, NULL, 0 } }; @@ -296,7 +296,7 @@ int bam_rmdup(int argc, char *argv[]) } header = sam_hdr_read(in); if (header == NULL || header->n_targets == 0) { - fprintf(pysam_stderr, "[bam_rmdup] input SAM does not have header. Abort!\n"); + fprintf(samtools_stderr, "[bam_rmdup] input SAM does not have header. Abort!\n"); return 1; } @@ -317,7 +317,7 @@ int bam_rmdup(int argc, char *argv[]) bam_hdr_destroy(header); sam_close(in); if (sam_close(out) < 0) { - fprintf(pysam_stderr, "[bam_rmdup] error closing output file\n"); + fprintf(samtools_stderr, "[bam_rmdup] error closing output file\n"); ret = 1; } return ret; diff --git a/samtools/bam_rmdupse.c.pysam.c b/samtools/bam_rmdupse.c.pysam.c index 3a3d0d03b..2038dbfe1 100644 --- a/samtools/bam_rmdupse.c.pysam.c +++ b/samtools/bam_rmdupse.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_rmdupse.c -- duplicate read detection for unpaired reads. @@ -188,7 +188,7 @@ int bam_rmdupse_core(samFile *in, bam_hdr_t *hdr, samFile *out, int force_se) } } if (r < -1) { - fprintf(pysam_stderr, "[%s] error reading input file\n", __func__); + fprintf(samtools_stderr, "[%s] error reading input file\n", __func__); goto fail; } @@ -197,7 +197,7 @@ int bam_rmdupse_core(samFile *in, bam_hdr_t *hdr, samFile *out, int force_se) for (k = kh_begin(aux); k != kh_end(aux); ++k) { if (kh_exist(aux, k)) { lib_aux_t *q = &kh_val(aux, k); - fprintf(pysam_stderr, "[bam_rmdupse_core] %lld / %lld = %.4lf in library '%s'\n", (long long)q->n_removed, + fprintf(samtools_stderr, "[bam_rmdupse_core] %lld / %lld = %.4lf in library '%s'\n", (long long)q->n_removed, (long long)q->n_checked, (double)q->n_removed/q->n_checked, kh_key(aux, k)); kh_destroy(best, q->left); kh_destroy(best, q->rght); free((char*)kh_key(aux, k)); diff --git a/samtools/bam_sort.c b/samtools/bam_sort.c index 4955dccd0..509c1d96b 100644 --- a/samtools/bam_sort.c +++ b/samtools/bam_sort.c @@ -37,12 +37,34 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include +#include "htslib/bgzf.h" #include "htslib/ksort.h" +#include "htslib/hts_os.h" #include "htslib/khash.h" #include "htslib/klist.h" #include "htslib/kstring.h" #include "htslib/sam.h" #include "sam_opts.h" +#include "samtools.h" + + +// Struct which contains the a record, and the pointer to the sort tag (if any) +// Used to speed up sort-by-tag. +typedef struct bam1_tag { + bam1_t *bam_record; + const uint8_t *tag; +} bam1_tag; + +/* Minimum memory required in megabytes before sort will attempt to run. This + is to prevent accidents where failing to use the -m option correctly results + in the creation of a temporary file for each read in the input file. + Don't forget to update the man page if you change this. */ +const size_t SORT_MIN_MEGS_PER_THREAD = 1; + +/* Default per-thread memory for sort. Must be >= SORT_MIN_MEGS_PER_THREAD. + Don't forget to update the man page if you change this. */ +const size_t SORT_DEFAULT_MEGS_PER_THREAD = 768; #if !defined(__DARWIN_C_LEVEL) || __DARWIN_C_LEVEL < 900000L #define NEED_MEMSET_PATTERN4 @@ -70,6 +92,8 @@ KHASH_MAP_INIT_STR(c2i, int) KLIST_INIT(hdrln, char*, hdrln_free_char) static int g_is_by_qname = 0; +static int g_is_by_tag = 0; +static char g_sort_tag[2] = {0,0}; static int strnum_cmp(const char *_a, const char *_b) { @@ -100,20 +124,36 @@ static int strnum_cmp(const char *_a, const char *_b) typedef struct { int i; uint64_t pos, idx; - bam1_t *b; + bam1_tag entry; } heap1_t; -#define __pos_cmp(a, b) ((a).pos > (b).pos || ((a).pos == (b).pos && ((a).i > (b).i || ((a).i == (b).i && (a).idx > (b).idx)))) +static inline int bam1_cmp_by_tag(const bam1_tag a, const bam1_tag b); // Function to compare reads in the heap and determine which one is < the other static inline int heap_lt(const heap1_t a, const heap1_t b) { - if (g_is_by_qname) { + if (!a.entry.bam_record) + return 1; + if (!b.entry.bam_record) + return 0; + + if (g_is_by_tag) { int t; - if (a.b == NULL || b.b == NULL) return a.b == NULL? 1 : 0; - t = strnum_cmp(bam_get_qname(a.b), bam_get_qname(b.b)); - return (t > 0 || (t == 0 && (a.b->core.flag&0xc0) > (b.b->core.flag&0xc0))); - } else return __pos_cmp(a, b); + t = bam1_cmp_by_tag(a.entry, b.entry); + if (t != 0) return t > 0; + } else if (g_is_by_qname) { + int t, fa, fb; + t = strnum_cmp(bam_get_qname(a.entry.bam_record), bam_get_qname(b.entry.bam_record)); + if (t != 0) return t > 0; + fa = a.entry.bam_record->core.flag & 0xc0; + fb = b.entry.bam_record->core.flag & 0xc0; + if (fa != fb) return fa > fb; + } else { + if (a.pos != b.pos) return a.pos > b.pos; + } + // This compares by position in the input file(s) + if (a.i != b.i) return a.i > b.i; + return a.idx > b.idx; } KSORT_INIT(heap, heap1_t, heap_lt) @@ -1087,7 +1127,8 @@ int* rtrans_build(int n, int n_targets, trans_tbl_t* translation_tbl) /*! @abstract Merge multiple sorted BAM. - @param is_by_qname whether to sort by query name + @param by_qname whether to sort by query name + @param sort_tag if non-null, sort by the given tag @param out output BAM file name @param mode sam_open() mode to be used to create the final output file (overrides level settings from UNCOMP and LEVEL1 flags) @@ -1098,14 +1139,15 @@ int* rtrans_build(int n, int n_targets, trans_tbl_t* translation_tbl) @param flag flags that control how the merge is undertaken @param reg region to merge @param n_threads number of threads to use (passed to htslib) + @param cmd command name (used in print_error() etc) @param in_fmt format options for input files @param out_fmt output file format and options @discussion Padding information may NOT correctly maintained. This function is NOT thread safe. */ -int bam_merge_core2(int by_qname, const char *out, const char *mode, +int bam_merge_core2(int by_qname, char* sort_tag, const char *out, const char *mode, const char *headers, int n, char * const *fn, int flag, - const char *reg, int n_threads, + const char *reg, int n_threads, const char *cmd, const htsFormat *in_fmt, const htsFormat *out_fmt) { samFile *fpout, **fp = NULL; @@ -1126,28 +1168,24 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, if (headers) { samFile* fpheaders = sam_open(headers, "r"); if (fpheaders == NULL) { - const char *message = strerror(errno); - fprintf(stderr, "[bam_merge_core] cannot open '%s': %s\n", headers, message); + print_error_errno(cmd, "cannot open \"%s\"", headers); return -1; } hin = sam_hdr_read(fpheaders); sam_close(fpheaders); if (hin == NULL) { - fprintf(stderr, "[bam_merge_core] couldn't read headers for '%s'\n", - headers); + print_error(cmd, "couldn't read headers from \"%s\"", headers); goto mem_fail; } - } else { - hout = bam_hdr_init(); - if (!hout) { - fprintf(stderr, "[bam_merge_core] couldn't allocate bam header\n"); - goto mem_fail; - } - hout->text = strdup(""); - if (!hout->text) goto mem_fail; } g_is_by_qname = by_qname; + if (sort_tag) { + g_is_by_tag = 1; + g_sort_tag[0] = sort_tag[0]; + g_sort_tag[1] = sort_tag[1]; + } + fp = (samFile**)calloc(n, sizeof(samFile*)); if (!fp) goto mem_fail; heap = (heap1_t*)calloc(n, sizeof(heap1_t)); @@ -1194,13 +1232,12 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, bam_hdr_t *hin; fp[i] = sam_open_format(fn[i], "r", in_fmt); if (fp[i] == NULL) { - fprintf(stderr, "[bam_merge_core] fail to open file %s\n", fn[i]); + print_error_errno(cmd, "fail to open \"%s\"", fn[i]); goto fail; } hin = sam_hdr_read(fp[i]); if (hin == NULL) { - fprintf(stderr, "[bam_merge_core] failed to read header for '%s'\n", - fn[i]); + print_error(cmd, "failed to read header from \"%s\"", fn[i]); goto fail; } @@ -1218,6 +1255,16 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, if ((translation_tbl+i)->lost_coord_sort && !by_qname) { fprintf(stderr, "[bam_merge_core] Order of targets in file %s caused coordinate sort to be lost\n", fn[i]); } + + // Potential future improvement is to share headers between CRAM files for + // samtools sort (where all headers are identical. + // Eg: + // + // if (i > 1) { + // sam_hdr_free(cram_fd_get_header(fp[i]->fp.cram)); + // cram_fd_set_header(fp[i]->fp.cram, cram_fd_get_header(fp[0]->fp.cram)); + // sam_hdr_incr_ref(cram_fd_get_header(fp[0]->fp.cram)); + // } } // Did we get an @HD line? @@ -1313,32 +1360,38 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, heap1_t *h = heap + i; int res; h->i = i; - h->b = bam_init1(); - if (!h->b) goto mem_fail; - res = iter[i] ? sam_itr_next(fp[i], iter[i], h->b) : sam_read1(fp[i], hdr[i], h->b); + h->entry.bam_record = bam_init1(); + h->entry.tag = NULL; + if (!h->entry.bam_record) goto mem_fail; + res = iter[i] ? sam_itr_next(fp[i], iter[i], h->entry.bam_record) : sam_read1(fp[i], hdr[i], h->entry.bam_record); if (res >= 0) { - bam_translate(h->b, translation_tbl + i); - h->pos = ((uint64_t)h->b->core.tid<<32) | (uint32_t)((int32_t)h->b->core.pos+1)<<1 | bam_is_rev(h->b); + bam_translate(h->entry.bam_record, translation_tbl + i); + h->pos = ((uint64_t)h->entry.bam_record->core.tid<<32) | (uint32_t)((int32_t)h->entry.bam_record->core.pos+1)<<1 | bam_is_rev(h->entry.bam_record); h->idx = idx++; + if (g_is_by_tag) { + h->entry.tag = bam_aux_get(h->entry.bam_record, g_sort_tag); + } else { + h->entry.tag = NULL; + } } else if (res == -1 && (!iter[i] || iter[i]->finished)) { h->pos = HEAP_EMPTY; - bam_destroy1(h->b); - h->b = NULL; + bam_destroy1(h->entry.bam_record); + h->entry.bam_record = NULL; + h->entry.tag = NULL; } else { - fprintf(stderr, "[%s] failed to read first record from %s\n", - __func__, fn[i]); + print_error(cmd, "failed to read first record from \"%s\"", fn[i]); goto fail; } } // Open output file and write header if ((fpout = sam_open_format(out, mode, out_fmt)) == 0) { - fprintf(stderr, "[%s] failed to create \"%s\": %s\n", __func__, out, strerror(errno)); + print_error_errno(cmd, "failed to create \"%s\"", out); return -1; } if (sam_hdr_write(fpout, hout) != 0) { - fprintf(stderr, "[%s] failed to write header.\n", __func__); + print_error_errno(cmd, "failed to write header to \"%s\"", out); sam_close(fpout); return -1; } @@ -1347,14 +1400,14 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, // Begin the actual merge ks_heapmake(heap, n, heap); while (heap->pos != HEAP_EMPTY) { - bam1_t *b = heap->b; + bam1_t *b = heap->entry.bam_record; if (flag & MERGE_RG) { uint8_t *rg = bam_aux_get(b, "RG"); if (rg) bam_aux_del(b, rg); bam_aux_append(b, "RG", 'Z', RG_len[heap->i] + 1, (uint8_t*)RG[heap->i]); } if (sam_write1(fpout, hout, b) < 0) { - fprintf(stderr, "[%s] failed to write to output file.\n", __func__); + print_error_errno(cmd, "failed writing to \"%s\"", out); sam_close(fpout); return -1; } @@ -1362,13 +1415,18 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, bam_translate(b, translation_tbl + heap->i); heap->pos = ((uint64_t)b->core.tid<<32) | (uint32_t)((int)b->core.pos+1)<<1 | bam_is_rev(b); heap->idx = idx++; + if (g_is_by_tag) { + heap->entry.tag = bam_aux_get(heap->entry.bam_record, g_sort_tag); + } else { + heap->entry.tag = NULL; + } } else if (j == -1 && (!iter[heap->i] || iter[heap->i]->finished)) { heap->pos = HEAP_EMPTY; - bam_destroy1(heap->b); - heap->b = NULL; + bam_destroy1(heap->entry.bam_record); + heap->entry.bam_record = NULL; + heap->entry.tag = NULL; } else { - fprintf(stderr, "[bam_merge_core] error: '%s' is truncated.\n", - fn[heap->i]); + print_error(cmd, "\"%s\" is truncated", fn[heap->i]); goto fail; } ks_heapadjust(heap, 0, n, heap); @@ -1390,13 +1448,13 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, free_merged_header(merged_hdr); free(RG); free(translation_tbl); free(fp); free(heap); free(iter); free(hdr); if (sam_close(fpout) < 0) { - fprintf(stderr, "[bam_merge_core] error closing output file\n"); + print_error(cmd, "error closing output file"); return -1; } return 0; mem_fail: - fprintf(stderr, "[bam_merge_core] Out of memory\n"); + print_error(cmd, "Out of memory"); fail: if (flag & MERGE_RG) { @@ -1410,7 +1468,7 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, if (iter && iter[i]) hts_itr_destroy(iter[i]); if (hdr && hdr[i]) bam_hdr_destroy(hdr[i]); if (fp && fp[i]) sam_close(fp[i]); - if (heap && heap[i].b) bam_destroy1(heap[i].b); + if (heap && heap[i].entry.bam_record) bam_destroy1(heap[i].entry.bam_record); } if (hout) bam_hdr_destroy(hout); free(RG); @@ -1430,7 +1488,7 @@ int bam_merge_core(int by_qname, const char *out, const char *headers, int n, ch strcpy(mode, "wb"); if (flag & MERGE_UNCOMP) strcat(mode, "0"); else if (flag & MERGE_LEVEL1) strcat(mode, "1"); - return bam_merge_core2(by_qname, out, mode, headers, n, fn, flag, reg, 0, NULL, NULL); + return bam_merge_core2(by_qname, NULL, out, mode, headers, n, fn, flag, reg, 0, "merge", NULL, NULL); } static void merge_usage(FILE *to) @@ -1440,6 +1498,7 @@ static void merge_usage(FILE *to) "\n" "Options:\n" " -n Input files are sorted by read name\n" +" -t TAG Input files are sorted by TAG value\n" " -r Attach RG tag (inferred from file names)\n" " -u Uncompressed BAM output\n" " -f Overwrite the output BAM if exist\n" @@ -1450,23 +1509,22 @@ static void merge_usage(FILE *to) " -c Combine @RG headers with colliding IDs [alter IDs to be distinct]\n" " -p Combine @PG headers with colliding IDs [alter IDs to be distinct]\n" " -s VALUE Override random seed\n" -" -b FILE List of input BAM filenames, one per line [null]\n" -" -@, --threads INT\n" -" Number of BAM/CRAM compression threads [0]\n"); - sam_global_opt_help(to, "-.O.."); +" -b FILE List of input BAM filenames, one per line [null]\n"); + sam_global_opt_help(to, "-.O..@"); } int bam_merge(int argc, char *argv[]) { - int c, is_by_qname = 0, flag = 0, ret = 0, n_threads = 0, level = -1; + int c, is_by_qname = 0, flag = 0, ret = 0, level = -1; char *fn_headers = NULL, *reg = NULL, mode[12]; + char *sort_tag = NULL; long random_seed = (long)time(NULL); char** fn = NULL; int fn_size = 0; sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0, '@'), { "threads", required_argument, NULL, '@' }, { NULL, 0, NULL, 0 } }; @@ -1476,17 +1534,17 @@ int bam_merge(int argc, char *argv[]) return 0; } - while ((c = getopt_long(argc, argv, "h:nru1R:f@:l:cps:b:O:", lopts, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "h:nru1R:f@:l:cps:b:O:t:", lopts, NULL)) >= 0) { switch (c) { case 'r': flag |= MERGE_RG; break; case 'f': flag |= MERGE_FORCE; break; case 'h': fn_headers = strdup(optarg); break; case 'n': is_by_qname = 1; break; + case 't': sort_tag = strdup(optarg); break; case '1': flag |= MERGE_LEVEL1; level = 1; break; case 'u': flag |= MERGE_UNCOMP; level = 0; break; case 'R': reg = strdup(optarg); break; case 'l': level = atoi(optarg); break; - case '@': n_threads = atoi(optarg); break; case 'c': flag |= MERGE_COMBINE_RG; break; case 'p': flag |= MERGE_COMBINE_PG; break; case 's': random_seed = atol(optarg); break; @@ -1500,9 +1558,10 @@ int bam_merge(int argc, char *argv[]) if (fn == NULL) { ret = 1; goto end; } memcpy(fn+fn_size, fn_read, nfiles * sizeof(char*)); fn_size += nfiles; + free(fn_read); } else { - fprintf(stderr, "[%s] Invalid file list \"%s\"\n", __func__, optarg); + print_error("merge", "Invalid file list \"%s\"", optarg); ret = 1; } break; @@ -1514,7 +1573,7 @@ int bam_merge(int argc, char *argv[]) } } if ( argc - optind < 1 ) { - fprintf(stderr, "You must at least specify the output file.\n"); + print_error("merge", "You must at least specify the output file"); merge_usage(stderr); return 1; } @@ -1537,16 +1596,16 @@ int bam_merge(int argc, char *argv[]) memcpy(fn+fn_size, argv + (optind+1), nargcfiles * sizeof(char*)); } if (fn_size+nargcfiles < 1) { - fprintf(stderr, "You must specify at least one (and usually two or more) input files.\n"); + print_error("merge", "You must specify at least one (and usually two or more) input files"); merge_usage(stderr); return 1; } strcpy(mode, "wb"); sam_open_mode(mode+1, argv[optind], NULL); if (level >= 0) sprintf(strchr(mode, '\0'), "%d", level < 9? level : 9); - if (bam_merge_core2(is_by_qname, argv[optind], mode, fn_headers, - fn_size+nargcfiles, fn, flag, reg, n_threads, - &ga.in, &ga.out) < 0) + if (bam_merge_core2(is_by_qname, sort_tag, argv[optind], mode, fn_headers, + fn_size+nargcfiles, fn, flag, reg, ga.nthreads, + "merge", &ga.in, &ga.out) < 0) ret = 1; end: @@ -1565,66 +1624,291 @@ int bam_merge(int argc, char *argv[]) * BAM sorting * ***************/ -#include +typedef struct { + size_t from; + size_t to; +} buf_region; + +/* Simplified version of bam_merge_core2() for merging part-sorted + temporary files. No need for header merging or translation, + it just needs to read data into the heap and push it out again. */ + +static inline int heap_add_read(heap1_t *heap, int nfiles, samFile **fp, + int num_in_mem, buf_region *in_mem, + bam1_tag *buf, uint64_t *idx, bam_hdr_t *hout) { + int i = heap->i, res; + if (i < nfiles) { // read from file + res = sam_read1(fp[i], hout, heap->entry.bam_record); + } else { // read from memory + if (in_mem[i - nfiles].from < in_mem[i - nfiles].to) { + heap->entry.bam_record = buf[in_mem[i - nfiles].from++].bam_record; + res = 0; + } else { + res = -1; + } + } + if (res >= 0) { + heap->pos = (((uint64_t)heap->entry.bam_record->core.tid<<32) + | (uint32_t)((int32_t)heap->entry.bam_record->core.pos+1)<<1 + | bam_is_rev(heap->entry.bam_record)); + heap->idx = (*idx)++; + if (g_is_by_tag) { + heap->entry.tag = bam_aux_get(heap->entry.bam_record, g_sort_tag); + } else { + heap->entry.tag = NULL; + } + } else if (res == -1) { + heap->pos = HEAP_EMPTY; + if (i < nfiles) bam_destroy1(heap->entry.bam_record); + heap->entry.bam_record = NULL; + heap->entry.tag = NULL; + } else { + return -1; + } + return 0; +} -typedef bam1_t *bam1_p; +static int bam_merge_simple(int by_qname, char *sort_tag, const char *out, + const char *mode, bam_hdr_t *hout, + int n, char * const *fn, int num_in_mem, + buf_region *in_mem, bam1_tag *buf, int n_threads, + const char *cmd, const htsFormat *in_fmt, + const htsFormat *out_fmt) { + samFile *fpout = NULL, **fp = NULL; + heap1_t *heap = NULL; + uint64_t idx = 0; + int i, heap_size = n + num_in_mem; -static int change_SO(bam_hdr_t *h, const char *so) -{ - char *p, *q, *beg = NULL, *end = NULL, *newtext; - if (h->l_text > 3) { - if (strncmp(h->text, "@HD", 3) == 0) { - if ((p = strchr(h->text, '\n')) == 0) return -1; - *p = '\0'; - if ((q = strstr(h->text, "\tSO:")) != 0) { - *p = '\n'; // change back - if (strncmp(q + 4, so, p - q - 4) != 0) { - beg = q; - for (q += 4; *q != '\n' && *q != '\t'; ++q); - end = q; - } else return 0; // no need to change - } else beg = end = p, *p = '\n'; + g_is_by_qname = by_qname; + if (sort_tag) { + g_is_by_tag = 1; + g_sort_tag[0] = sort_tag[0]; + g_sort_tag[1] = sort_tag[1]; + } + if (n > 0) { + fp = (samFile**)calloc(n, sizeof(samFile*)); + if (!fp) goto mem_fail; + } + heap = (heap1_t*)calloc(heap_size, sizeof(heap1_t)); + if (!heap) goto mem_fail; + + // Open each file, read the header and put the first read into the heap + for (i = 0; i < heap_size; i++) { + bam_hdr_t *hin; + heap1_t *h = &heap[i]; + + if (i < n) { + fp[i] = sam_open_format(fn[i], "r", in_fmt); + if (fp[i] == NULL) { + print_error_errno(cmd, "fail to open \"%s\"", fn[i]); + goto fail; + } + + // Read header ... + hin = sam_hdr_read(fp[i]); + if (hin == NULL) { + print_error(cmd, "failed to read header from \"%s\"", fn[i]); + goto fail; + } + // ... and throw it away as we don't really need it + bam_hdr_destroy(hin); + } + + // Get a read into the heap + h->i = i; + h->entry.tag = NULL; + if (i < n) { + h->entry.bam_record = bam_init1(); + if (!h->entry.bam_record) goto mem_fail; + } + if (heap_add_read(h, n, fp, num_in_mem, in_mem, buf, &idx, hout) < 0) { + assert(i < n); + print_error(cmd, "failed to read first record from \"%s\"", fn[i]); + goto fail; + } + } + + // Open output file and write header + if ((fpout = sam_open_format(out, mode, out_fmt)) == 0) { + print_error_errno(cmd, "failed to create \"%s\"", out); + return -1; + } + + hts_set_threads(fpout, n_threads); + + if (sam_hdr_write(fpout, hout) != 0) { + print_error_errno(cmd, "failed to write header to \"%s\"", out); + sam_close(fpout); + return -1; + } + + // Now do the merge + ks_heapmake(heap, heap_size, heap); + while (heap->pos != HEAP_EMPTY) { + bam1_t *b = heap->entry.bam_record; + if (sam_write1(fpout, hout, b) < 0) { + print_error_errno(cmd, "failed writing to \"%s\"", out); + sam_close(fpout); + return -1; + } + if (heap_add_read(heap, n, fp, num_in_mem, in_mem, buf, &idx, hout) < 0) { + assert(heap->i < n); + print_error(cmd, "Error reading \"%s\" : %s", + fn[heap->i], strerror(errno)); + goto fail; + } + ks_heapadjust(heap, 0, heap_size, heap); + } + // Clean up and close + for (i = 0; i < n; i++) { + if (sam_close(fp[i]) != 0) { + print_error(cmd, "Error on closing \"%s\" : %s", + fn[i], strerror(errno)); } } - if (beg == NULL) { // no @HD - h->l_text += strlen(so) + 15; - newtext = (char*)malloc(h->l_text + 1); - sprintf(newtext, "@HD\tVN:1.3\tSO:%s\n", so); - strcat(newtext, h->text); - } else { // has @HD but different or no SO - h->l_text = (beg - h->text) + (4 + strlen(so)) + (h->text + h->l_text - end); - newtext = (char*)malloc(h->l_text + 1); - strncpy(newtext, h->text, beg - h->text); - sprintf(newtext + (beg - h->text), "\tSO:%s", so); - strcat(newtext, end); - } - free(h->text); - h->text = newtext; + free(fp); + free(heap); + if (sam_close(fpout) < 0) { + print_error(cmd, "error closing output file"); + return -1; + } return 0; + mem_fail: + print_error(cmd, "Out of memory"); + + fail: + for (i = 0; i < n; i++) { + if (fp && fp[i]) sam_close(fp[i]); + if (heap && heap[i].entry.bam_record) bam_destroy1(heap[i].entry.bam_record); + } + free(fp); + free(heap); + if (fpout) sam_close(fpout); + return -1; } -// Function to compare reads and determine which one is < the other -static inline int bam1_lt(const bam1_p a, const bam1_p b) +// Function to compare reads and determine which one is < or > the other +// Handle sort-by-pos and sort-by-name. Used as the secondary sort in bam1_lt_by_tag, if reads are equivalent by tag. +// Returns a value less than, equal to or greater than zero if a is less than, +// equal to or greater than b, respectively. +static inline int bam1_cmp_core(const bam1_tag a, const bam1_tag b) { + uint64_t pa, pb; + if (!a.bam_record) + return 1; + if (!b.bam_record) + return 0; + if (g_is_by_qname) { - int t = strnum_cmp(bam_get_qname(a), bam_get_qname(b)); - return (t < 0 || (t == 0 && (a->core.flag&0xc0) < (b->core.flag&0xc0))); - } else return (((uint64_t)a->core.tid<<32|(a->core.pos+1)<<1|bam_is_rev(a)) < ((uint64_t)b->core.tid<<32|(b->core.pos+1)<<1|bam_is_rev(b))); + int t = strnum_cmp(bam_get_qname(a.bam_record), bam_get_qname(b.bam_record)); + if (t != 0) return t; + return (int) (a.bam_record->core.flag&0xc0) - (int) (b.bam_record->core.flag&0xc0); + } else { + pa = (uint64_t)a.bam_record->core.tid<<32|(a.bam_record->core.pos+1)<<1|bam_is_rev(a.bam_record); + pb = (uint64_t)b.bam_record->core.tid<<32|(b.bam_record->core.pos+1)<<1|bam_is_rev(b.bam_record); + return pa < pb ? -1 : (pa > pb ? 1 : 0); + } +} + +uint8_t normalize_type(const uint8_t* aux) { + if (*aux == 'c' || *aux == 'C' || *aux == 's' || *aux == 'S' || *aux == 'i' || *aux == 'I') { + return 'c'; + } else if (*aux == 'f' || *aux == 'd') { + return 'f'; + } else if (*aux == 'H' || *aux == 'Z') { + return 'H'; + } else { + return *aux; + } +} + +// Sort record by tag, using pos or read name as a secondary key if tags are identical. Reads not carrying the tag sort first. +// Tags are first sorted by the type character (in case the types differ), or by the appropriate comparator for that type if they agree. +// Returns a value less than, equal to or greater than zero if a is less than, +// equal to or greater than b, respectively. +static inline int bam1_cmp_by_tag(const bam1_tag a, const bam1_tag b) +{ + const uint8_t* aux_a = a.tag; + const uint8_t* aux_b = b.tag; + + if (aux_a == NULL && aux_b != NULL) { + return -1; + } else if (aux_a != NULL && aux_b == NULL) { + return 1; + } else if (aux_a == NULL && aux_b == NULL) { + return bam1_cmp_core(a,b); + } + + // 'Normalize' the letters of the datatypes to a canonical letter, + // so that comparison of different types + // forms a correct total ordering. + uint8_t a_type = normalize_type(aux_a); + uint8_t b_type = normalize_type(aux_b); + + if (a_type != b_type) { + // Fix int to float comparisons by using bam_aux2f() to read the int + if (a_type == 'c' && b_type == 'f') { + a_type = 'f'; + } else if (a_type == 'f' && b_type == 'c') { + b_type = 'f'; + } else { + // Unfixable mismatched types + return a_type < b_type ? -1 : 1; + } + } + + if (a_type == 'c') { + int64_t va = bam_aux2i(aux_a); + int64_t vb = bam_aux2i(aux_b); + if (va != vb) return va < vb ? -1 : 1; + return bam1_cmp_core(a, b); + } else if (a_type == 'f') { + double va = bam_aux2f(aux_a); + double vb = bam_aux2f(aux_b); + if (va != vb) return va < vb ? -1 : 1; + return bam1_cmp_core(a, b); + } else if (a_type == 'A') { + unsigned char va = bam_aux2A(aux_a); + unsigned char vb = bam_aux2A(aux_b); + if (va != vb) return va < vb ? -1 : 1; + return bam1_cmp_core(a, b); + } else if (a_type == 'H') { + int t = strcmp(bam_aux2Z(aux_a), bam_aux2Z(aux_b)); + if (t) return t; + return bam1_cmp_core(a, b); + } else { + return bam1_cmp_core(a,b); + } +} + +// Function to compare reads and determine which one is < the other +// Handle sort-by-pos, sort-by-name, or sort-by-tag +static inline int bam1_lt(const bam1_tag a, const bam1_tag b) +{ + if (g_is_by_tag) { + return bam1_cmp_by_tag(a, b) < 0; + } else { + return bam1_cmp_core(a,b) < 0; + } } -KSORT_INIT(sort, bam1_p, bam1_lt) + + + +KSORT_INIT(sort, bam1_tag, bam1_lt) typedef struct { size_t buf_len; const char *prefix; - bam1_p *buf; + bam1_tag *buf; const bam_hdr_t *h; int index; int error; + int no_save; } worker_t; // Returns 0 for success // -1 for failure -static int write_buffer(const char *fn, const char *mode, size_t l, bam1_p *buf, const bam_hdr_t *h, int n_threads, const htsFormat *fmt) +static int write_buffer(const char *fn, const char *mode, size_t l, bam1_tag *buf, const bam_hdr_t *h, int n_threads, const htsFormat *fmt) { size_t i; samFile* fp; @@ -1633,7 +1917,7 @@ static int write_buffer(const char *fn, const char *mode, size_t l, bam1_p *buf, if (sam_hdr_write(fp, h) != 0) goto fail; if (n_threads > 1) hts_set_threads(fp, n_threads); for (i = 0; i < l; ++i) { - if (sam_write1(fp, h, buf[i]) < 0) goto fail; + if (sam_write1(fp, h, buf[i].bam_record) < 0) goto fail; } if (sam_close(fp) < 0) return -1; return 0; @@ -1648,31 +1932,47 @@ static void *worker(void *data) char *name; w->error = 0; ks_mergesort(sort, w->buf_len, w->buf, 0); + + if (w->no_save) + return 0; + name = (char*)calloc(strlen(w->prefix) + 20, 1); if (!name) { w->error = errno; return 0; } sprintf(name, "%s.%.4d.bam", w->prefix, w->index); - if (write_buffer(name, "wbx1", w->buf_len, w->buf, w->h, 0, NULL) < 0) - w->error = errno; - -// Consider using CRAM temporary files if the final output is CRAM. -// Typically it is comparable speed while being smaller. -// hts_opt opt[2] = { -// {"version=3.0", CRAM_OPT_VERSION, {"3.0"}, NULL}, -// {"no_ref", CRAM_OPT_NO_REF, {1}, NULL} -// }; -// opt[0].next = &opt[1]; -// if (write_buffer(name, "wc1", w->buf_len, w->buf, w->h, 0, opt) < 0) -// w->error = errno; + + uint32_t max_ncigar = 0; + int i; + for (i = 0; i < w->buf_len; i++) { + uint32_t nc = w->buf[i].bam_record->core.n_cigar; + if (max_ncigar < nc) + max_ncigar = nc; + } + + if (max_ncigar > 65535) { + htsFormat fmt; + memset(&fmt, 0, sizeof(fmt)); + if (hts_parse_format(&fmt, "cram,version=3.0,no_ref,seqs_per_slice=1000") < 0) { + w->error = errno; + free(name); + return 0; + } + + if (write_buffer(name, "wcx1", w->buf_len, w->buf, w->h, 0, &fmt) < 0) + w->error = errno; + } else { + if (write_buffer(name, "wbx1", w->buf_len, w->buf, w->h, 0, NULL) < 0) + w->error = errno; + } free(name); return 0; } -static int sort_blocks(int n_files, size_t k, bam1_p *buf, const char *prefix, const bam_hdr_t *h, int n_threads) +static int sort_blocks(int n_files, size_t k, bam1_tag *buf, const char *prefix, + const bam_hdr_t *h, int n_threads, buf_region *in_mem) { int i; - size_t rest; - bam1_p *b; + size_t pos, rest; pthread_t *tid; pthread_attr_t attr; worker_t *w; @@ -1683,26 +1983,38 @@ static int sort_blocks(int n_files, size_t k, bam1_p *buf, const char *prefix, c pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); w = (worker_t*)calloc(n_threads, sizeof(worker_t)); + if (!w) return -1; tid = (pthread_t*)calloc(n_threads, sizeof(pthread_t)); - b = buf; rest = k; + if (!tid) { free(w); return -1; } + pos = 0; rest = k; for (i = 0; i < n_threads; ++i) { w[i].buf_len = rest / (n_threads - i); - w[i].buf = b; + w[i].buf = &buf[pos]; w[i].prefix = prefix; w[i].h = h; w[i].index = n_files + i; - b += w[i].buf_len; rest -= w[i].buf_len; + if (in_mem) { + w[i].no_save = 1; + in_mem[i].from = pos; + in_mem[i].to = pos + w[i].buf_len; + } else { + w[i].no_save = 0; + } + pos += w[i].buf_len; rest -= w[i].buf_len; pthread_create(&tid[i], &attr, worker, &w[i]); } for (i = 0; i < n_threads; ++i) { pthread_join(tid[i], 0); if (w[i].error != 0) { - fprintf(stderr, "[bam_sort_core] failed to create temporary file \"%s.%.4d.bam\": %s\n", prefix, w[i].index, strerror(w[i].error)); + errno = w[i].error; + print_error_errno("sort", "failed to create temporary file \"%s.%.4d.bam\"", prefix, w[i].index); n_failed++; } } free(tid); free(w); - return (n_failed == 0)? n_files + n_threads : -1; + if (n_failed) return -1; + if (in_mem) return n_threads; + return n_files + n_threads; } /*! @@ -1710,6 +2022,7 @@ static int sort_blocks(int n_files, size_t k, bam1_p *buf, const char *prefix, c and the leftmost position of an alignment @param is_by_qname whether to sort by query name + @param sort_by_tag if non-null, sort by the given tag @param fn name of the file to be sorted @param prefix prefix of the temporary files (prefix.NNNN.bam are written) @param fnout name of the final output file to be written @@ -1720,114 +2033,190 @@ static int sort_blocks(int n_files, size_t k, bam1_p *buf, const char *prefix, c @return 0 for successful sorting, negative on errors @discussion It may create multiple temporary subalignment files - and then merge them by calling bam_merge_core2(). This function is + and then merge them by calling bam_merge_simple(). This function is NOT thread safe. */ -int bam_sort_core_ext(int is_by_qname, const char *fn, const char *prefix, +int bam_sort_core_ext(int is_by_qname, char* sort_by_tag, const char *fn, const char *prefix, const char *fnout, const char *modeout, size_t _max_mem, int n_threads, const htsFormat *in_fmt, const htsFormat *out_fmt) { - int ret = -1, i, n_files = 0; - size_t mem, max_k, k, max_mem; + int ret = -1, res, i, n_files = 0; + size_t max_k, k, max_mem, bam_mem_offset; bam_hdr_t *header = NULL; samFile *fp; - bam1_t *b, **buf; + bam1_tag *buf = NULL; + bam1_t *b = bam_init1(); + uint8_t *bam_mem = NULL; + char **fns = NULL; + const char *new_so; + buf_region *in_mem = NULL; + int num_in_mem = 0; + + if (!b) { + print_error("sort", "couldn't allocate memory for bam record"); + return -1; + } if (n_threads < 2) n_threads = 1; g_is_by_qname = is_by_qname; - max_k = k = 0; mem = 0; + if (sort_by_tag) { + g_is_by_tag = 1; + strncpy(g_sort_tag, sort_by_tag, 2); + } + max_mem = _max_mem * n_threads; buf = NULL; fp = sam_open_format(fn, "r", in_fmt); if (fp == NULL) { - const char *message = strerror(errno); - fprintf(stderr, "[bam_sort_core] fail to open '%s': %s\n", fn, message); - return -2; + print_error_errno("sort", "can't open \"%s\"", fn); + goto err; } header = sam_hdr_read(fp); if (header == NULL) { - fprintf(stderr, "[bam_sort_core] failed to read header for '%s'\n", fn); + print_error("sort", "failed to read header from \"%s\"", fn); + goto err; + } + + if (sort_by_tag != NULL) + new_so = "unknown"; + else if (is_by_qname) + new_so = "queryname"; + else + new_so = "coordinate"; + + if (sam_hdr_change_HD(header, "SO", new_so) != 0) { + print_error("sort", + "failed to change sort order header to '%s'\n", new_so); + goto err; + } + if (sam_hdr_change_HD(header, "GO", NULL) != 0) { + print_error("sort", + "failed to delete group order header\n"); goto err; } - if (is_by_qname) change_SO(header, "queryname"); - else change_SO(header, "coordinate"); + + // No gain to using the thread pool here as the flow of this code + // is such that we are *either* reading *or* sorting. Hence a shared + // pool makes no real difference except to reduce the thread count a little. + if (n_threads > 1) + hts_set_threads(fp, n_threads); + + if ((bam_mem = malloc(max_mem)) == NULL) { + print_error("sort", "couldn't allocate memory for bam_mem"); + goto err; + } + // write sub files - for (;;) { + k = max_k = bam_mem_offset = 0; + while ((res = sam_read1(fp, header, b)) >= 0) { + int mem_full = 0; + if (k == max_k) { - size_t kk, old_max = max_k; + bam1_tag *new_buf; max_k = max_k? max_k<<1 : 0x10000; - buf = (bam1_t**)realloc(buf, max_k * sizeof(bam1_t*)); - for (kk = old_max; kk < max_k; ++kk) buf[kk] = NULL; + if ((new_buf = realloc(buf, max_k * sizeof(bam1_tag))) == NULL) { + print_error("sort", "couldn't allocate memory for buf"); + goto err; + } + buf = new_buf; } - if (buf[k] == NULL) buf[k] = bam_init1(); - b = buf[k]; - if ((ret = sam_read1(fp, header, b)) < 0) break; - if (b->l_data < b->m_data>>2) { // shrink - b->m_data = b->l_data; - kroundup32(b->m_data); - b->data = (uint8_t*)realloc(b->data, b->m_data); + + // Check if the BAM record will fit in the memory limit + if (bam_mem_offset + sizeof(*b) + b->l_data < max_mem) { + // Copy record into the memory block + buf[k].bam_record = (bam1_t *)(bam_mem + bam_mem_offset); + *buf[k].bam_record = *b; + buf[k].bam_record->data = (uint8_t *)((char *)buf[k].bam_record + sizeof(bam1_t)); + memcpy(buf[k].bam_record->data, b->data, b->l_data); + // store next BAM record in next 8-byte-aligned address after + // current one + bam_mem_offset = (bam_mem_offset + sizeof(*b) + b->l_data + 8 - 1) & ~((size_t)(8 - 1)); + } else { + // Add a pointer to the remaining record + buf[k].bam_record = b; + mem_full = 1; + } + + // Pull out the pointer to the sort tag if applicable + if (g_is_by_tag) { + buf[k].tag = bam_aux_get(buf[k].bam_record, g_sort_tag); + } else { + buf[k].tag = NULL; } - mem += sizeof(bam1_t) + b->m_data + sizeof(void*) + sizeof(void*); // two sizeof(void*) for the data allocated to pointer arrays ++k; - if (mem >= max_mem) { - n_files = sort_blocks(n_files, k, buf, prefix, header, n_threads); + + if (mem_full) { + n_files = sort_blocks(n_files, k, buf, prefix, header, n_threads, + NULL); if (n_files < 0) { - ret = -1; goto err; } - mem = k = 0; + k = 0; + bam_mem_offset = 0; } } - if (ret != -1) { - fprintf(stderr, "[bam_sort_core] truncated file. Aborting.\n"); - ret = -1; + if (res != -1) { + print_error("sort", "truncated file. Aborting"); goto err; } + // Sort last records + if (k > 0) { + in_mem = calloc(n_threads > 0 ? n_threads : 1, sizeof(in_mem[0])); + if (!in_mem) goto err; + num_in_mem = sort_blocks(n_files, k, buf, prefix, header, n_threads, + in_mem); + if (num_in_mem < 0) goto err; + } else { + num_in_mem = 0; + } + // write the final output - if (n_files == 0) { // a single block + if (n_files == 0 && num_in_mem < 2) { // a single block ks_mergesort(sort, k, buf, 0); if (write_buffer(fnout, modeout, k, buf, header, n_threads, out_fmt) != 0) { - fprintf(stderr, "[bam_sort_core] failed to create \"%s\": %s\n", fnout, strerror(errno)); - ret = -1; + print_error_errno("sort", "failed to create \"%s\"", fnout); goto err; } } else { // then merge - char **fns; - n_files = sort_blocks(n_files, k, buf, prefix, header, n_threads); - if (n_files == -1) { - ret = -1; - goto err; - } - fprintf(stderr, "[bam_sort_core] merging from %d files...\n", n_files); + fprintf(stderr, + "[bam_sort_core] merging from %d files and %d in-memory blocks...\n", + n_files, num_in_mem); fns = (char**)calloc(n_files, sizeof(char*)); + if (!fns) goto err; for (i = 0; i < n_files; ++i) { fns[i] = (char*)calloc(strlen(prefix) + 20, 1); + if (!fns[i]) goto err; sprintf(fns[i], "%s.%.4d.bam", prefix, i); } - if (bam_merge_core2(is_by_qname, fnout, modeout, NULL, n_files, fns, - MERGE_COMBINE_RG|MERGE_COMBINE_PG|MERGE_FIRST_CO, - NULL, n_threads, in_fmt, out_fmt) < 0) { - // Propagate bam_merge_core2() failure; it has already emitted a + if (bam_merge_simple(is_by_qname, sort_by_tag, fnout, modeout, header, + n_files, fns, num_in_mem, in_mem, buf, + n_threads, "sort", in_fmt, out_fmt) < 0) { + // Propagate bam_merge_simple() failure; it has already emitted a // message explaining the failure, so no further message is needed. goto err; } - for (i = 0; i < n_files; ++i) { - unlink(fns[i]); - free(fns[i]); - } - free(fns); } ret = 0; err: // free - for (k = 0; k < max_k; ++k) bam_destroy1(buf[k]); + if (fns) { + for (i = 0; i < n_files; ++i) { + if (fns[i]) { + unlink(fns[i]); + free(fns[i]); + } + } + free(fns); + } + bam_destroy1(b); free(buf); + free(bam_mem); bam_hdr_destroy(header); - sam_close(fp); + if (fp) sam_close(fp); return ret; } @@ -1836,8 +2225,9 @@ int bam_sort_core(int is_by_qname, const char *fn, const char *prefix, size_t ma { int ret; char *fnout = calloc(strlen(prefix) + 4 + 1, 1); + if (!fnout) return -1; sprintf(fnout, "%s.bam", prefix); - ret = bam_sort_core_ext(is_by_qname, fn, prefix, fnout, "wb", max_mem, 0, NULL, NULL); + ret = bam_sort_core_ext(is_by_qname, NULL, fn, prefix, fnout, "wb", max_mem, 0, NULL, NULL); free(fnout); return ret; } @@ -1850,32 +2240,50 @@ static void sort_usage(FILE *fp) " -l INT Set compression level, from 0 (uncompressed) to 9 (best)\n" " -m INT Set maximum memory per thread; suffix K/M/G recognized [768M]\n" " -n Sort by read name\n" +" -t TAG Sort by value of TAG. Uses position as secondary index (or read name if -n is set)\n" " -o FILE Write final output to FILE rather than standard output\n" -" -T PREFIX Write temporary files to PREFIX.nnnn.bam\n" -" -@, --threads INT\n" -" Set number of sorting and compression threads [1]\n"); - sam_global_opt_help(fp, "-.O.."); +" -T PREFIX Write temporary files to PREFIX.nnnn.bam\n"); + sam_global_opt_help(fp, "-.O..@"); +} + +static void complain_about_memory_setting(size_t max_mem) { + char *suffix = ""; + const size_t nine_k = 9<<10; + if (max_mem > nine_k) { max_mem >>= 10; suffix = "K"; } + if (max_mem > nine_k) { max_mem >>= 10; suffix = "M"; } + + fprintf(stderr, +"[bam_sort] -m setting (%zu%s bytes) is less than the minimum required (%zuM).\n\n" +"Trying to run with -m too small can lead to the creation of a very large number\n" +"of temporary files. This may make sort fail due to it exceeding limits on the\n" +"number of files it can have open at the same time.\n\n" +"Please check your -m parameter. It should be an integer followed by one of the\n" +"letters K (for kilobytes), M (megabytes) or G (gigabytes). You should ensure it\n" +"is at least the minimum above, and much higher if you are sorting a large file.\n", + max_mem, suffix, SORT_MIN_MEGS_PER_THREAD); } int bam_sort(int argc, char *argv[]) { - size_t max_mem = 768<<20; // 512MB - int c, nargs, is_by_qname = 0, ret, o_seen = 0, n_threads = 0, level = -1; + size_t max_mem = SORT_DEFAULT_MEGS_PER_THREAD << 20; + int c, nargs, is_by_qname = 0, ret, o_seen = 0, level = -1; + char* sort_tag = NULL; char *fnout = "-", modeout[12]; kstring_t tmpprefix = { 0, 0, NULL }; struct stat st; sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0, '@'), { "threads", required_argument, NULL, '@' }, { NULL, 0, NULL, 0 } }; - while ((c = getopt_long(argc, argv, "l:m:no:O:T:@:", lopts, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "l:m:no:O:T:@:t:", lopts, NULL)) >= 0) { switch (c) { case 'o': fnout = optarg; o_seen = 1; break; case 'n': is_by_qname = 1; break; + case 't': sort_tag = strdup(optarg); break; case 'm': { char *q; max_mem = strtol(optarg, &q, 0); @@ -1885,7 +2293,6 @@ int bam_sort(int argc, char *argv[]) break; } case 'T': kputs(optarg, &tmpprefix); break; - case '@': n_threads = atoi(optarg); break; case 'l': level = atoi(optarg); break; default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; @@ -1910,6 +2317,12 @@ int bam_sort(int argc, char *argv[]) goto sort_end; } + if (max_mem < (SORT_MIN_MEGS_PER_THREAD << 20)) { + complain_about_memory_setting(max_mem); + ret = EXIT_FAILURE; + goto sort_end; + } + strcpy(modeout, "wb"); sam_open_mode(modeout+1, fnout, NULL); if (level >= 0) sprintf(strchr(modeout, '\0'), "%d", level < 9? level : 9); @@ -1924,8 +2337,8 @@ int bam_sort(int argc, char *argv[]) ksprintf(&tmpprefix, "samtools.%d.%u.tmp", (int) getpid(), t % 10000); } - ret = bam_sort_core_ext(is_by_qname, (nargs > 0)? argv[optind] : "-", - tmpprefix.s, fnout, modeout, max_mem, n_threads, + ret = bam_sort_core_ext(is_by_qname, sort_tag, (nargs > 0)? argv[optind] : "-", + tmpprefix.s, fnout, modeout, max_mem, ga.nthreads, &ga.in, &ga.out); if (ret >= 0) ret = EXIT_SUCCESS; diff --git a/samtools/bam_sort.c.pysam.c b/samtools/bam_sort.c.pysam.c index b2b625d35..d38a311cf 100644 --- a/samtools/bam_sort.c.pysam.c +++ b/samtools/bam_sort.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_sort.c -- sorting and merging. @@ -39,12 +39,34 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include +#include "htslib/bgzf.h" #include "htslib/ksort.h" +#include "htslib/hts_os.h" #include "htslib/khash.h" #include "htslib/klist.h" #include "htslib/kstring.h" #include "htslib/sam.h" #include "sam_opts.h" +#include "samtools.h" + + +// Struct which contains the a record, and the pointer to the sort tag (if any) +// Used to speed up sort-by-tag. +typedef struct bam1_tag { + bam1_t *bam_record; + const uint8_t *tag; +} bam1_tag; + +/* Minimum memory required in megabytes before sort will attempt to run. This + is to prevent accidents where failing to use the -m option correctly results + in the creation of a temporary file for each read in the input file. + Don't forget to update the man page if you change this. */ +const size_t SORT_MIN_MEGS_PER_THREAD = 1; + +/* Default per-thread memory for sort. Must be >= SORT_MIN_MEGS_PER_THREAD. + Don't forget to update the man page if you change this. */ +const size_t SORT_DEFAULT_MEGS_PER_THREAD = 768; #if !defined(__DARWIN_C_LEVEL) || __DARWIN_C_LEVEL < 900000L #define NEED_MEMSET_PATTERN4 @@ -72,6 +94,8 @@ KHASH_MAP_INIT_STR(c2i, int) KLIST_INIT(hdrln, char*, hdrln_free_char) static int g_is_by_qname = 0; +static int g_is_by_tag = 0; +static char g_sort_tag[2] = {0,0}; static int strnum_cmp(const char *_a, const char *_b) { @@ -102,20 +126,36 @@ static int strnum_cmp(const char *_a, const char *_b) typedef struct { int i; uint64_t pos, idx; - bam1_t *b; + bam1_tag entry; } heap1_t; -#define __pos_cmp(a, b) ((a).pos > (b).pos || ((a).pos == (b).pos && ((a).i > (b).i || ((a).i == (b).i && (a).idx > (b).idx)))) +static inline int bam1_cmp_by_tag(const bam1_tag a, const bam1_tag b); // Function to compare reads in the heap and determine which one is < the other static inline int heap_lt(const heap1_t a, const heap1_t b) { - if (g_is_by_qname) { + if (!a.entry.bam_record) + return 1; + if (!b.entry.bam_record) + return 0; + + if (g_is_by_tag) { int t; - if (a.b == NULL || b.b == NULL) return a.b == NULL? 1 : 0; - t = strnum_cmp(bam_get_qname(a.b), bam_get_qname(b.b)); - return (t > 0 || (t == 0 && (a.b->core.flag&0xc0) > (b.b->core.flag&0xc0))); - } else return __pos_cmp(a, b); + t = bam1_cmp_by_tag(a.entry, b.entry); + if (t != 0) return t > 0; + } else if (g_is_by_qname) { + int t, fa, fb; + t = strnum_cmp(bam_get_qname(a.entry.bam_record), bam_get_qname(b.entry.bam_record)); + if (t != 0) return t > 0; + fa = a.entry.bam_record->core.flag & 0xc0; + fb = b.entry.bam_record->core.flag & 0xc0; + if (fa != fb) return fa > fb; + } else { + if (a.pos != b.pos) return a.pos > b.pos; + } + // This compares by position in the input file(s) + if (a.i != b.i) return a.i > b.i; + return a.idx > b.idx; } KSORT_INIT(heap, heap1_t, heap_lt) @@ -486,7 +526,7 @@ static int trans_tbl_add_sq(merged_header_t* merged_hdr, bam_hdr_t *translate, if (iter == kh_end(sq_tids)) { // Warn about this, but it's not really fatal. - fprintf(pysam_stderr, "[W::%s] @SQ SN (%.*s) found in text header but not binary header.\n", + fprintf(samtools_stderr, "[W::%s] @SQ SN (%.*s) found in text header but not binary header.\n", __func__, (int) (matches[1].rm_eo - matches[1].rm_so), text + matches[1].rm_so); @@ -723,7 +763,7 @@ static int finish_rg_pg(bool is_rg, klist_t(hdrln) *hdr_lines, idx = kh_get(c2c, pg_map, id); if (idx == kh_end(pg_map)) { // Not found, warn. - fprintf(pysam_stderr, "[W::%s] Tag %s%s not found in @PG records\n", + fprintf(samtools_stderr, "[W::%s] Tag %s%s not found in @PG records\n", __func__, search + 1, id); } else { // Remember new id and splice points on original string @@ -874,7 +914,7 @@ static bam_hdr_t * finish_merged_header(merged_header_t *merged_hdr) { + ks_len(&merged_hdr->out_pg) + ks_len(&merged_hdr->out_co)); if (txt_sz >= INT32_MAX) { - fprintf(pysam_stderr, "[%s] Output header text too long\n", __func__); + fprintf(samtools_stderr, "[%s] Output header text too long\n", __func__); return NULL; } @@ -991,7 +1031,7 @@ static void bam_translate(bam1_t* b, trans_tbl_t* tbl) } } else { char *tmp = strdup(decoded_rg); - fprintf(pysam_stderr, + fprintf(samtools_stderr, "[bam_translate] RG tag \"%s\" on read \"%s\" encountered " "with no corresponding entry in header, tag lost. " "Unknown tags are only reported once per input file for " @@ -1021,7 +1061,7 @@ static void bam_translate(bam1_t* b, trans_tbl_t* tbl) } } else { char *tmp = strdup(decoded_pg); - fprintf(pysam_stderr, + fprintf(samtools_stderr, "[bam_translate] PG tag \"%s\" on read \"%s\" encountered " "with no corresponding entry in header, tag lost. " "Unknown tags are only reported once per input file for " @@ -1089,7 +1129,8 @@ int* rtrans_build(int n, int n_targets, trans_tbl_t* translation_tbl) /*! @abstract Merge multiple sorted BAM. - @param is_by_qname whether to sort by query name + @param by_qname whether to sort by query name + @param sort_tag if non-null, sort by the given tag @param out output BAM file name @param mode sam_open() mode to be used to create the final output file (overrides level settings from UNCOMP and LEVEL1 flags) @@ -1100,14 +1141,15 @@ int* rtrans_build(int n, int n_targets, trans_tbl_t* translation_tbl) @param flag flags that control how the merge is undertaken @param reg region to merge @param n_threads number of threads to use (passed to htslib) + @param cmd command name (used in print_error() etc) @param in_fmt format options for input files @param out_fmt output file format and options @discussion Padding information may NOT correctly maintained. This function is NOT thread safe. */ -int bam_merge_core2(int by_qname, const char *out, const char *mode, +int bam_merge_core2(int by_qname, char* sort_tag, const char *out, const char *mode, const char *headers, int n, char * const *fn, int flag, - const char *reg, int n_threads, + const char *reg, int n_threads, const char *cmd, const htsFormat *in_fmt, const htsFormat *out_fmt) { samFile *fpout, **fp = NULL; @@ -1128,28 +1170,24 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, if (headers) { samFile* fpheaders = sam_open(headers, "r"); if (fpheaders == NULL) { - const char *message = strerror(errno); - fprintf(pysam_stderr, "[bam_merge_core] cannot open '%s': %s\n", headers, message); + print_error_errno(cmd, "cannot open \"%s\"", headers); return -1; } hin = sam_hdr_read(fpheaders); sam_close(fpheaders); if (hin == NULL) { - fprintf(pysam_stderr, "[bam_merge_core] couldn't read headers for '%s'\n", - headers); + print_error(cmd, "couldn't read headers from \"%s\"", headers); goto mem_fail; } - } else { - hout = bam_hdr_init(); - if (!hout) { - fprintf(pysam_stderr, "[bam_merge_core] couldn't allocate bam header\n"); - goto mem_fail; - } - hout->text = strdup(""); - if (!hout->text) goto mem_fail; } g_is_by_qname = by_qname; + if (sort_tag) { + g_is_by_tag = 1; + g_sort_tag[0] = sort_tag[0]; + g_sort_tag[1] = sort_tag[1]; + } + fp = (samFile**)calloc(n, sizeof(samFile*)); if (!fp) goto mem_fail; heap = (heap1_t*)calloc(n, sizeof(heap1_t)); @@ -1196,13 +1234,12 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, bam_hdr_t *hin; fp[i] = sam_open_format(fn[i], "r", in_fmt); if (fp[i] == NULL) { - fprintf(pysam_stderr, "[bam_merge_core] fail to open file %s\n", fn[i]); + print_error_errno(cmd, "fail to open \"%s\"", fn[i]); goto fail; } hin = sam_hdr_read(fp[i]); if (hin == NULL) { - fprintf(pysam_stderr, "[bam_merge_core] failed to read header for '%s'\n", - fn[i]); + print_error(cmd, "failed to read header from \"%s\"", fn[i]); goto fail; } @@ -1218,13 +1255,23 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, else { bam_hdr_destroy(hin); hdr[i] = NULL; } if ((translation_tbl+i)->lost_coord_sort && !by_qname) { - fprintf(pysam_stderr, "[bam_merge_core] Order of targets in file %s caused coordinate sort to be lost\n", fn[i]); + fprintf(samtools_stderr, "[bam_merge_core] Order of targets in file %s caused coordinate sort to be lost\n", fn[i]); } + + // Potential future improvement is to share headers between CRAM files for + // samtools sort (where all headers are identical. + // Eg: + // + // if (i > 1) { + // sam_hdr_free(cram_fd_get_header(fp[i]->fp.cram)); + // cram_fd_set_header(fp[i]->fp.cram, cram_fd_get_header(fp[0]->fp.cram)); + // sam_hdr_incr_ref(cram_fd_get_header(fp[0]->fp.cram)); + // } } // Did we get an @HD line? if (!merged_hdr->have_hd) { - fprintf(pysam_stderr, "[W::%s] No @HD tag found.\n", __func__); + fprintf(samtools_stderr, "[W::%s] No @HD tag found.\n", __func__); /* FIXME: Should we add an @HD line here, and if so what should we put in it? Ideally we want a way of getting htslib to tell us the SAM version number to assume given no @HD line. Is @@ -1261,8 +1308,8 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, end = INT_MAX; } if (tid < 0) { - if (name_lim) fprintf(pysam_stderr, "[%s] Region \"%s\" specifies an unknown reference name\n", __func__, reg); - else fprintf(pysam_stderr, "[%s] Badly formatted region: \"%s\"\n", __func__, reg); + if (name_lim) fprintf(samtools_stderr, "[%s] Region \"%s\" specifies an unknown reference name\n", __func__, reg); + else fprintf(samtools_stderr, "[%s] Badly formatted region: \"%s\"\n", __func__, reg); goto fail; } for (i = 0; i < n; ++i) { @@ -1270,7 +1317,7 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, // (rtrans[i*n+tid]) Look up what hout tid translates to in input tid space int mapped_tid = rtrans[i*hout->n_targets+tid]; if (idx == NULL) { - fprintf(pysam_stderr, "[%s] failed to load index for %s. Random alignment retrieval only works for indexed BAM or CRAM files.\n", + fprintf(samtools_stderr, "[%s] failed to load index for %s. Random alignment retrieval only works for indexed BAM or CRAM files.\n", __func__, fn[i]); goto fail; } @@ -1282,12 +1329,12 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, hts_idx_destroy(idx); if (iter[i] == NULL) { if (mapped_tid != INT32_MIN) { - fprintf(pysam_stderr, + fprintf(samtools_stderr, "[%s] failed to get iterator over " "{%s, %d, %d, %d}\n", __func__, fn[i], mapped_tid, beg, end); } else { - fprintf(pysam_stderr, + fprintf(samtools_stderr, "[%s] failed to get iterator over " "{%s, HTS_IDX_NONE, 0, 0}\n", __func__, fn[i]); @@ -1302,7 +1349,7 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, if (hdr[i] == NULL) { iter[i] = sam_itr_queryi(NULL, HTS_IDX_REST, 0, 0); if (iter[i] == NULL) { - fprintf(pysam_stderr, "[%s] failed to get iterator\n", __func__); + fprintf(samtools_stderr, "[%s] failed to get iterator\n", __func__); goto fail; } } @@ -1315,32 +1362,38 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, heap1_t *h = heap + i; int res; h->i = i; - h->b = bam_init1(); - if (!h->b) goto mem_fail; - res = iter[i] ? sam_itr_next(fp[i], iter[i], h->b) : sam_read1(fp[i], hdr[i], h->b); + h->entry.bam_record = bam_init1(); + h->entry.tag = NULL; + if (!h->entry.bam_record) goto mem_fail; + res = iter[i] ? sam_itr_next(fp[i], iter[i], h->entry.bam_record) : sam_read1(fp[i], hdr[i], h->entry.bam_record); if (res >= 0) { - bam_translate(h->b, translation_tbl + i); - h->pos = ((uint64_t)h->b->core.tid<<32) | (uint32_t)((int32_t)h->b->core.pos+1)<<1 | bam_is_rev(h->b); + bam_translate(h->entry.bam_record, translation_tbl + i); + h->pos = ((uint64_t)h->entry.bam_record->core.tid<<32) | (uint32_t)((int32_t)h->entry.bam_record->core.pos+1)<<1 | bam_is_rev(h->entry.bam_record); h->idx = idx++; + if (g_is_by_tag) { + h->entry.tag = bam_aux_get(h->entry.bam_record, g_sort_tag); + } else { + h->entry.tag = NULL; + } } else if (res == -1 && (!iter[i] || iter[i]->finished)) { h->pos = HEAP_EMPTY; - bam_destroy1(h->b); - h->b = NULL; + bam_destroy1(h->entry.bam_record); + h->entry.bam_record = NULL; + h->entry.tag = NULL; } else { - fprintf(pysam_stderr, "[%s] failed to read first record from %s\n", - __func__, fn[i]); + print_error(cmd, "failed to read first record from \"%s\"", fn[i]); goto fail; } } // Open output file and write header if ((fpout = sam_open_format(out, mode, out_fmt)) == 0) { - fprintf(pysam_stderr, "[%s] failed to create \"%s\": %s\n", __func__, out, strerror(errno)); + print_error_errno(cmd, "failed to create \"%s\"", out); return -1; } if (sam_hdr_write(fpout, hout) != 0) { - fprintf(pysam_stderr, "[%s] failed to write header.\n", __func__); + print_error_errno(cmd, "failed to write header to \"%s\"", out); sam_close(fpout); return -1; } @@ -1349,14 +1402,14 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, // Begin the actual merge ks_heapmake(heap, n, heap); while (heap->pos != HEAP_EMPTY) { - bam1_t *b = heap->b; + bam1_t *b = heap->entry.bam_record; if (flag & MERGE_RG) { uint8_t *rg = bam_aux_get(b, "RG"); if (rg) bam_aux_del(b, rg); bam_aux_append(b, "RG", 'Z', RG_len[heap->i] + 1, (uint8_t*)RG[heap->i]); } if (sam_write1(fpout, hout, b) < 0) { - fprintf(pysam_stderr, "[%s] failed to write to output file.\n", __func__); + print_error_errno(cmd, "failed writing to \"%s\"", out); sam_close(fpout); return -1; } @@ -1364,13 +1417,18 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, bam_translate(b, translation_tbl + heap->i); heap->pos = ((uint64_t)b->core.tid<<32) | (uint32_t)((int)b->core.pos+1)<<1 | bam_is_rev(b); heap->idx = idx++; + if (g_is_by_tag) { + heap->entry.tag = bam_aux_get(heap->entry.bam_record, g_sort_tag); + } else { + heap->entry.tag = NULL; + } } else if (j == -1 && (!iter[heap->i] || iter[heap->i]->finished)) { heap->pos = HEAP_EMPTY; - bam_destroy1(heap->b); - heap->b = NULL; + bam_destroy1(heap->entry.bam_record); + heap->entry.bam_record = NULL; + heap->entry.tag = NULL; } else { - fprintf(pysam_stderr, "[bam_merge_core] error: '%s' is truncated.\n", - fn[heap->i]); + print_error(cmd, "\"%s\" is truncated", fn[heap->i]); goto fail; } ks_heapadjust(heap, 0, n, heap); @@ -1392,13 +1450,13 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, free_merged_header(merged_hdr); free(RG); free(translation_tbl); free(fp); free(heap); free(iter); free(hdr); if (sam_close(fpout) < 0) { - fprintf(pysam_stderr, "[bam_merge_core] error closing output file\n"); + print_error(cmd, "error closing output file"); return -1; } return 0; mem_fail: - fprintf(pysam_stderr, "[bam_merge_core] Out of memory\n"); + print_error(cmd, "Out of memory"); fail: if (flag & MERGE_RG) { @@ -1412,7 +1470,7 @@ int bam_merge_core2(int by_qname, const char *out, const char *mode, if (iter && iter[i]) hts_itr_destroy(iter[i]); if (hdr && hdr[i]) bam_hdr_destroy(hdr[i]); if (fp && fp[i]) sam_close(fp[i]); - if (heap && heap[i].b) bam_destroy1(heap[i].b); + if (heap && heap[i].entry.bam_record) bam_destroy1(heap[i].entry.bam_record); } if (hout) bam_hdr_destroy(hout); free(RG); @@ -1432,7 +1490,7 @@ int bam_merge_core(int by_qname, const char *out, const char *headers, int n, ch strcpy(mode, "wb"); if (flag & MERGE_UNCOMP) strcat(mode, "0"); else if (flag & MERGE_LEVEL1) strcat(mode, "1"); - return bam_merge_core2(by_qname, out, mode, headers, n, fn, flag, reg, 0, NULL, NULL); + return bam_merge_core2(by_qname, NULL, out, mode, headers, n, fn, flag, reg, 0, "merge", NULL, NULL); } static void merge_usage(FILE *to) @@ -1442,6 +1500,7 @@ static void merge_usage(FILE *to) "\n" "Options:\n" " -n Input files are sorted by read name\n" +" -t TAG Input files are sorted by TAG value\n" " -r Attach RG tag (inferred from file names)\n" " -u Uncompressed BAM output\n" " -f Overwrite the output BAM if exist\n" @@ -1452,43 +1511,42 @@ static void merge_usage(FILE *to) " -c Combine @RG headers with colliding IDs [alter IDs to be distinct]\n" " -p Combine @PG headers with colliding IDs [alter IDs to be distinct]\n" " -s VALUE Override random seed\n" -" -b FILE List of input BAM filenames, one per line [null]\n" -" -@, --threads INT\n" -" Number of BAM/CRAM compression threads [0]\n"); - sam_global_opt_help(to, "-.O.."); +" -b FILE List of input BAM filenames, one per line [null]\n"); + sam_global_opt_help(to, "-.O..@"); } int bam_merge(int argc, char *argv[]) { - int c, is_by_qname = 0, flag = 0, ret = 0, n_threads = 0, level = -1; + int c, is_by_qname = 0, flag = 0, ret = 0, level = -1; char *fn_headers = NULL, *reg = NULL, mode[12]; + char *sort_tag = NULL; long random_seed = (long)time(NULL); char** fn = NULL; int fn_size = 0; sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0, '@'), { "threads", required_argument, NULL, '@' }, { NULL, 0, NULL, 0 } }; if (argc == 1) { - merge_usage(pysam_stdout); + merge_usage(samtools_stdout); return 0; } - while ((c = getopt_long(argc, argv, "h:nru1R:f@:l:cps:b:O:", lopts, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "h:nru1R:f@:l:cps:b:O:t:", lopts, NULL)) >= 0) { switch (c) { case 'r': flag |= MERGE_RG; break; case 'f': flag |= MERGE_FORCE; break; case 'h': fn_headers = strdup(optarg); break; case 'n': is_by_qname = 1; break; + case 't': sort_tag = strdup(optarg); break; case '1': flag |= MERGE_LEVEL1; level = 1; break; case 'u': flag |= MERGE_UNCOMP; level = 0; break; case 'R': reg = strdup(optarg); break; case 'l': level = atoi(optarg); break; - case '@': n_threads = atoi(optarg); break; case 'c': flag |= MERGE_COMBINE_RG; break; case 'p': flag |= MERGE_COMBINE_PG; break; case 's': random_seed = atol(optarg); break; @@ -1502,9 +1560,10 @@ int bam_merge(int argc, char *argv[]) if (fn == NULL) { ret = 1; goto end; } memcpy(fn+fn_size, fn_read, nfiles * sizeof(char*)); fn_size += nfiles; + free(fn_read); } else { - fprintf(pysam_stderr, "[%s] Invalid file list \"%s\"\n", __func__, optarg); + print_error("merge", "Invalid file list \"%s\"", optarg); ret = 1; } break; @@ -1512,12 +1571,12 @@ int bam_merge(int argc, char *argv[]) default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; /* else fall-through */ - case '?': merge_usage(pysam_stderr); return 1; + case '?': merge_usage(samtools_stderr); return 1; } } if ( argc - optind < 1 ) { - fprintf(pysam_stderr, "You must at least specify the output file.\n"); - merge_usage(pysam_stderr); + print_error("merge", "You must at least specify the output file"); + merge_usage(samtools_stderr); return 1; } @@ -1526,7 +1585,7 @@ int bam_merge(int argc, char *argv[]) FILE *fp = fopen(argv[optind], "rb"); if (fp != NULL) { fclose(fp); - fprintf(pysam_stderr, "[%s] File '%s' exists. Please apply '-f' to overwrite. Abort.\n", __func__, argv[optind]); + fprintf(samtools_stderr, "[%s] File '%s' exists. Please apply '-f' to overwrite. Abort.\n", __func__, argv[optind]); return 1; } } @@ -1539,16 +1598,16 @@ int bam_merge(int argc, char *argv[]) memcpy(fn+fn_size, argv + (optind+1), nargcfiles * sizeof(char*)); } if (fn_size+nargcfiles < 1) { - fprintf(pysam_stderr, "You must specify at least one (and usually two or more) input files.\n"); - merge_usage(pysam_stderr); + print_error("merge", "You must specify at least one (and usually two or more) input files"); + merge_usage(samtools_stderr); return 1; } strcpy(mode, "wb"); sam_open_mode(mode+1, argv[optind], NULL); if (level >= 0) sprintf(strchr(mode, '\0'), "%d", level < 9? level : 9); - if (bam_merge_core2(is_by_qname, argv[optind], mode, fn_headers, - fn_size+nargcfiles, fn, flag, reg, n_threads, - &ga.in, &ga.out) < 0) + if (bam_merge_core2(is_by_qname, sort_tag, argv[optind], mode, fn_headers, + fn_size+nargcfiles, fn, flag, reg, ga.nthreads, + "merge", &ga.in, &ga.out) < 0) ret = 1; end: @@ -1567,66 +1626,291 @@ int bam_merge(int argc, char *argv[]) * BAM sorting * ***************/ -#include +typedef struct { + size_t from; + size_t to; +} buf_region; + +/* Simplified version of bam_merge_core2() for merging part-sorted + temporary files. No need for header merging or translation, + it just needs to read data into the heap and push it out again. */ + +static inline int heap_add_read(heap1_t *heap, int nfiles, samFile **fp, + int num_in_mem, buf_region *in_mem, + bam1_tag *buf, uint64_t *idx, bam_hdr_t *hout) { + int i = heap->i, res; + if (i < nfiles) { // read from file + res = sam_read1(fp[i], hout, heap->entry.bam_record); + } else { // read from memory + if (in_mem[i - nfiles].from < in_mem[i - nfiles].to) { + heap->entry.bam_record = buf[in_mem[i - nfiles].from++].bam_record; + res = 0; + } else { + res = -1; + } + } + if (res >= 0) { + heap->pos = (((uint64_t)heap->entry.bam_record->core.tid<<32) + | (uint32_t)((int32_t)heap->entry.bam_record->core.pos+1)<<1 + | bam_is_rev(heap->entry.bam_record)); + heap->idx = (*idx)++; + if (g_is_by_tag) { + heap->entry.tag = bam_aux_get(heap->entry.bam_record, g_sort_tag); + } else { + heap->entry.tag = NULL; + } + } else if (res == -1) { + heap->pos = HEAP_EMPTY; + if (i < nfiles) bam_destroy1(heap->entry.bam_record); + heap->entry.bam_record = NULL; + heap->entry.tag = NULL; + } else { + return -1; + } + return 0; +} -typedef bam1_t *bam1_p; +static int bam_merge_simple(int by_qname, char *sort_tag, const char *out, + const char *mode, bam_hdr_t *hout, + int n, char * const *fn, int num_in_mem, + buf_region *in_mem, bam1_tag *buf, int n_threads, + const char *cmd, const htsFormat *in_fmt, + const htsFormat *out_fmt) { + samFile *fpout = NULL, **fp = NULL; + heap1_t *heap = NULL; + uint64_t idx = 0; + int i, heap_size = n + num_in_mem; -static int change_SO(bam_hdr_t *h, const char *so) -{ - char *p, *q, *beg = NULL, *end = NULL, *newtext; - if (h->l_text > 3) { - if (strncmp(h->text, "@HD", 3) == 0) { - if ((p = strchr(h->text, '\n')) == 0) return -1; - *p = '\0'; - if ((q = strstr(h->text, "\tSO:")) != 0) { - *p = '\n'; // change back - if (strncmp(q + 4, so, p - q - 4) != 0) { - beg = q; - for (q += 4; *q != '\n' && *q != '\t'; ++q); - end = q; - } else return 0; // no need to change - } else beg = end = p, *p = '\n'; + g_is_by_qname = by_qname; + if (sort_tag) { + g_is_by_tag = 1; + g_sort_tag[0] = sort_tag[0]; + g_sort_tag[1] = sort_tag[1]; + } + if (n > 0) { + fp = (samFile**)calloc(n, sizeof(samFile*)); + if (!fp) goto mem_fail; + } + heap = (heap1_t*)calloc(heap_size, sizeof(heap1_t)); + if (!heap) goto mem_fail; + + // Open each file, read the header and put the first read into the heap + for (i = 0; i < heap_size; i++) { + bam_hdr_t *hin; + heap1_t *h = &heap[i]; + + if (i < n) { + fp[i] = sam_open_format(fn[i], "r", in_fmt); + if (fp[i] == NULL) { + print_error_errno(cmd, "fail to open \"%s\"", fn[i]); + goto fail; + } + + // Read header ... + hin = sam_hdr_read(fp[i]); + if (hin == NULL) { + print_error(cmd, "failed to read header from \"%s\"", fn[i]); + goto fail; + } + // ... and throw it away as we don't really need it + bam_hdr_destroy(hin); + } + + // Get a read into the heap + h->i = i; + h->entry.tag = NULL; + if (i < n) { + h->entry.bam_record = bam_init1(); + if (!h->entry.bam_record) goto mem_fail; + } + if (heap_add_read(h, n, fp, num_in_mem, in_mem, buf, &idx, hout) < 0) { + assert(i < n); + print_error(cmd, "failed to read first record from \"%s\"", fn[i]); + goto fail; + } + } + + // Open output file and write header + if ((fpout = sam_open_format(out, mode, out_fmt)) == 0) { + print_error_errno(cmd, "failed to create \"%s\"", out); + return -1; + } + + hts_set_threads(fpout, n_threads); + + if (sam_hdr_write(fpout, hout) != 0) { + print_error_errno(cmd, "failed to write header to \"%s\"", out); + sam_close(fpout); + return -1; + } + + // Now do the merge + ks_heapmake(heap, heap_size, heap); + while (heap->pos != HEAP_EMPTY) { + bam1_t *b = heap->entry.bam_record; + if (sam_write1(fpout, hout, b) < 0) { + print_error_errno(cmd, "failed writing to \"%s\"", out); + sam_close(fpout); + return -1; + } + if (heap_add_read(heap, n, fp, num_in_mem, in_mem, buf, &idx, hout) < 0) { + assert(heap->i < n); + print_error(cmd, "Error reading \"%s\" : %s", + fn[heap->i], strerror(errno)); + goto fail; + } + ks_heapadjust(heap, 0, heap_size, heap); + } + // Clean up and close + for (i = 0; i < n; i++) { + if (sam_close(fp[i]) != 0) { + print_error(cmd, "Error on closing \"%s\" : %s", + fn[i], strerror(errno)); } } - if (beg == NULL) { // no @HD - h->l_text += strlen(so) + 15; - newtext = (char*)malloc(h->l_text + 1); - sprintf(newtext, "@HD\tVN:1.3\tSO:%s\n", so); - strcat(newtext, h->text); - } else { // has @HD but different or no SO - h->l_text = (beg - h->text) + (4 + strlen(so)) + (h->text + h->l_text - end); - newtext = (char*)malloc(h->l_text + 1); - strncpy(newtext, h->text, beg - h->text); - sprintf(newtext + (beg - h->text), "\tSO:%s", so); - strcat(newtext, end); - } - free(h->text); - h->text = newtext; + free(fp); + free(heap); + if (sam_close(fpout) < 0) { + print_error(cmd, "error closing output file"); + return -1; + } return 0; + mem_fail: + print_error(cmd, "Out of memory"); + + fail: + for (i = 0; i < n; i++) { + if (fp && fp[i]) sam_close(fp[i]); + if (heap && heap[i].entry.bam_record) bam_destroy1(heap[i].entry.bam_record); + } + free(fp); + free(heap); + if (fpout) sam_close(fpout); + return -1; } -// Function to compare reads and determine which one is < the other -static inline int bam1_lt(const bam1_p a, const bam1_p b) +// Function to compare reads and determine which one is < or > the other +// Handle sort-by-pos and sort-by-name. Used as the secondary sort in bam1_lt_by_tag, if reads are equivalent by tag. +// Returns a value less than, equal to or greater than zero if a is less than, +// equal to or greater than b, respectively. +static inline int bam1_cmp_core(const bam1_tag a, const bam1_tag b) { + uint64_t pa, pb; + if (!a.bam_record) + return 1; + if (!b.bam_record) + return 0; + if (g_is_by_qname) { - int t = strnum_cmp(bam_get_qname(a), bam_get_qname(b)); - return (t < 0 || (t == 0 && (a->core.flag&0xc0) < (b->core.flag&0xc0))); - } else return (((uint64_t)a->core.tid<<32|(a->core.pos+1)<<1|bam_is_rev(a)) < ((uint64_t)b->core.tid<<32|(b->core.pos+1)<<1|bam_is_rev(b))); + int t = strnum_cmp(bam_get_qname(a.bam_record), bam_get_qname(b.bam_record)); + if (t != 0) return t; + return (int) (a.bam_record->core.flag&0xc0) - (int) (b.bam_record->core.flag&0xc0); + } else { + pa = (uint64_t)a.bam_record->core.tid<<32|(a.bam_record->core.pos+1)<<1|bam_is_rev(a.bam_record); + pb = (uint64_t)b.bam_record->core.tid<<32|(b.bam_record->core.pos+1)<<1|bam_is_rev(b.bam_record); + return pa < pb ? -1 : (pa > pb ? 1 : 0); + } +} + +uint8_t normalize_type(const uint8_t* aux) { + if (*aux == 'c' || *aux == 'C' || *aux == 's' || *aux == 'S' || *aux == 'i' || *aux == 'I') { + return 'c'; + } else if (*aux == 'f' || *aux == 'd') { + return 'f'; + } else if (*aux == 'H' || *aux == 'Z') { + return 'H'; + } else { + return *aux; + } +} + +// Sort record by tag, using pos or read name as a secondary key if tags are identical. Reads not carrying the tag sort first. +// Tags are first sorted by the type character (in case the types differ), or by the appropriate comparator for that type if they agree. +// Returns a value less than, equal to or greater than zero if a is less than, +// equal to or greater than b, respectively. +static inline int bam1_cmp_by_tag(const bam1_tag a, const bam1_tag b) +{ + const uint8_t* aux_a = a.tag; + const uint8_t* aux_b = b.tag; + + if (aux_a == NULL && aux_b != NULL) { + return -1; + } else if (aux_a != NULL && aux_b == NULL) { + return 1; + } else if (aux_a == NULL && aux_b == NULL) { + return bam1_cmp_core(a,b); + } + + // 'Normalize' the letters of the datatypes to a canonical letter, + // so that comparison of different types + // forms a correct total ordering. + uint8_t a_type = normalize_type(aux_a); + uint8_t b_type = normalize_type(aux_b); + + if (a_type != b_type) { + // Fix int to float comparisons by using bam_aux2f() to read the int + if (a_type == 'c' && b_type == 'f') { + a_type = 'f'; + } else if (a_type == 'f' && b_type == 'c') { + b_type = 'f'; + } else { + // Unfixable mismatched types + return a_type < b_type ? -1 : 1; + } + } + + if (a_type == 'c') { + int64_t va = bam_aux2i(aux_a); + int64_t vb = bam_aux2i(aux_b); + if (va != vb) return va < vb ? -1 : 1; + return bam1_cmp_core(a, b); + } else if (a_type == 'f') { + double va = bam_aux2f(aux_a); + double vb = bam_aux2f(aux_b); + if (va != vb) return va < vb ? -1 : 1; + return bam1_cmp_core(a, b); + } else if (a_type == 'A') { + unsigned char va = bam_aux2A(aux_a); + unsigned char vb = bam_aux2A(aux_b); + if (va != vb) return va < vb ? -1 : 1; + return bam1_cmp_core(a, b); + } else if (a_type == 'H') { + int t = strcmp(bam_aux2Z(aux_a), bam_aux2Z(aux_b)); + if (t) return t; + return bam1_cmp_core(a, b); + } else { + return bam1_cmp_core(a,b); + } +} + +// Function to compare reads and determine which one is < the other +// Handle sort-by-pos, sort-by-name, or sort-by-tag +static inline int bam1_lt(const bam1_tag a, const bam1_tag b) +{ + if (g_is_by_tag) { + return bam1_cmp_by_tag(a, b) < 0; + } else { + return bam1_cmp_core(a,b) < 0; + } } -KSORT_INIT(sort, bam1_p, bam1_lt) + + + +KSORT_INIT(sort, bam1_tag, bam1_lt) typedef struct { size_t buf_len; const char *prefix; - bam1_p *buf; + bam1_tag *buf; const bam_hdr_t *h; int index; int error; + int no_save; } worker_t; // Returns 0 for success // -1 for failure -static int write_buffer(const char *fn, const char *mode, size_t l, bam1_p *buf, const bam_hdr_t *h, int n_threads, const htsFormat *fmt) +static int write_buffer(const char *fn, const char *mode, size_t l, bam1_tag *buf, const bam_hdr_t *h, int n_threads, const htsFormat *fmt) { size_t i; samFile* fp; @@ -1635,7 +1919,7 @@ static int write_buffer(const char *fn, const char *mode, size_t l, bam1_p *buf, if (sam_hdr_write(fp, h) != 0) goto fail; if (n_threads > 1) hts_set_threads(fp, n_threads); for (i = 0; i < l; ++i) { - if (sam_write1(fp, h, buf[i]) < 0) goto fail; + if (sam_write1(fp, h, buf[i].bam_record) < 0) goto fail; } if (sam_close(fp) < 0) return -1; return 0; @@ -1650,31 +1934,47 @@ static void *worker(void *data) char *name; w->error = 0; ks_mergesort(sort, w->buf_len, w->buf, 0); + + if (w->no_save) + return 0; + name = (char*)calloc(strlen(w->prefix) + 20, 1); if (!name) { w->error = errno; return 0; } sprintf(name, "%s.%.4d.bam", w->prefix, w->index); - if (write_buffer(name, "wbx1", w->buf_len, w->buf, w->h, 0, NULL) < 0) - w->error = errno; - -// Consider using CRAM temporary files if the final output is CRAM. -// Typically it is comparable speed while being smaller. -// hts_opt opt[2] = { -// {"version=3.0", CRAM_OPT_VERSION, {"3.0"}, NULL}, -// {"no_ref", CRAM_OPT_NO_REF, {1}, NULL} -// }; -// opt[0].next = &opt[1]; -// if (write_buffer(name, "wc1", w->buf_len, w->buf, w->h, 0, opt) < 0) -// w->error = errno; + + uint32_t max_ncigar = 0; + int i; + for (i = 0; i < w->buf_len; i++) { + uint32_t nc = w->buf[i].bam_record->core.n_cigar; + if (max_ncigar < nc) + max_ncigar = nc; + } + + if (max_ncigar > 65535) { + htsFormat fmt; + memset(&fmt, 0, sizeof(fmt)); + if (hts_parse_format(&fmt, "cram,version=3.0,no_ref,seqs_per_slice=1000") < 0) { + w->error = errno; + free(name); + return 0; + } + + if (write_buffer(name, "wcx1", w->buf_len, w->buf, w->h, 0, &fmt) < 0) + w->error = errno; + } else { + if (write_buffer(name, "wbx1", w->buf_len, w->buf, w->h, 0, NULL) < 0) + w->error = errno; + } free(name); return 0; } -static int sort_blocks(int n_files, size_t k, bam1_p *buf, const char *prefix, const bam_hdr_t *h, int n_threads) +static int sort_blocks(int n_files, size_t k, bam1_tag *buf, const char *prefix, + const bam_hdr_t *h, int n_threads, buf_region *in_mem) { int i; - size_t rest; - bam1_p *b; + size_t pos, rest; pthread_t *tid; pthread_attr_t attr; worker_t *w; @@ -1685,26 +1985,38 @@ static int sort_blocks(int n_files, size_t k, bam1_p *buf, const char *prefix, c pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); w = (worker_t*)calloc(n_threads, sizeof(worker_t)); + if (!w) return -1; tid = (pthread_t*)calloc(n_threads, sizeof(pthread_t)); - b = buf; rest = k; + if (!tid) { free(w); return -1; } + pos = 0; rest = k; for (i = 0; i < n_threads; ++i) { w[i].buf_len = rest / (n_threads - i); - w[i].buf = b; + w[i].buf = &buf[pos]; w[i].prefix = prefix; w[i].h = h; w[i].index = n_files + i; - b += w[i].buf_len; rest -= w[i].buf_len; + if (in_mem) { + w[i].no_save = 1; + in_mem[i].from = pos; + in_mem[i].to = pos + w[i].buf_len; + } else { + w[i].no_save = 0; + } + pos += w[i].buf_len; rest -= w[i].buf_len; pthread_create(&tid[i], &attr, worker, &w[i]); } for (i = 0; i < n_threads; ++i) { pthread_join(tid[i], 0); if (w[i].error != 0) { - fprintf(pysam_stderr, "[bam_sort_core] failed to create temporary file \"%s.%.4d.bam\": %s\n", prefix, w[i].index, strerror(w[i].error)); + errno = w[i].error; + print_error_errno("sort", "failed to create temporary file \"%s.%.4d.bam\"", prefix, w[i].index); n_failed++; } } free(tid); free(w); - return (n_failed == 0)? n_files + n_threads : -1; + if (n_failed) return -1; + if (in_mem) return n_threads; + return n_files + n_threads; } /*! @@ -1712,6 +2024,7 @@ static int sort_blocks(int n_files, size_t k, bam1_p *buf, const char *prefix, c and the leftmost position of an alignment @param is_by_qname whether to sort by query name + @param sort_by_tag if non-null, sort by the given tag @param fn name of the file to be sorted @param prefix prefix of the temporary files (prefix.NNNN.bam are written) @param fnout name of the final output file to be written @@ -1722,114 +2035,190 @@ static int sort_blocks(int n_files, size_t k, bam1_p *buf, const char *prefix, c @return 0 for successful sorting, negative on errors @discussion It may create multiple temporary subalignment files - and then merge them by calling bam_merge_core2(). This function is + and then merge them by calling bam_merge_simple(). This function is NOT thread safe. */ -int bam_sort_core_ext(int is_by_qname, const char *fn, const char *prefix, +int bam_sort_core_ext(int is_by_qname, char* sort_by_tag, const char *fn, const char *prefix, const char *fnout, const char *modeout, size_t _max_mem, int n_threads, const htsFormat *in_fmt, const htsFormat *out_fmt) { - int ret = -1, i, n_files = 0; - size_t mem, max_k, k, max_mem; + int ret = -1, res, i, n_files = 0; + size_t max_k, k, max_mem, bam_mem_offset; bam_hdr_t *header = NULL; samFile *fp; - bam1_t *b, **buf; + bam1_tag *buf = NULL; + bam1_t *b = bam_init1(); + uint8_t *bam_mem = NULL; + char **fns = NULL; + const char *new_so; + buf_region *in_mem = NULL; + int num_in_mem = 0; + + if (!b) { + print_error("sort", "couldn't allocate memory for bam record"); + return -1; + } if (n_threads < 2) n_threads = 1; g_is_by_qname = is_by_qname; - max_k = k = 0; mem = 0; + if (sort_by_tag) { + g_is_by_tag = 1; + strncpy(g_sort_tag, sort_by_tag, 2); + } + max_mem = _max_mem * n_threads; buf = NULL; fp = sam_open_format(fn, "r", in_fmt); if (fp == NULL) { - const char *message = strerror(errno); - fprintf(pysam_stderr, "[bam_sort_core] fail to open '%s': %s\n", fn, message); - return -2; + print_error_errno("sort", "can't open \"%s\"", fn); + goto err; } header = sam_hdr_read(fp); if (header == NULL) { - fprintf(pysam_stderr, "[bam_sort_core] failed to read header for '%s'\n", fn); + print_error("sort", "failed to read header from \"%s\"", fn); + goto err; + } + + if (sort_by_tag != NULL) + new_so = "unknown"; + else if (is_by_qname) + new_so = "queryname"; + else + new_so = "coordinate"; + + if (sam_hdr_change_HD(header, "SO", new_so) != 0) { + print_error("sort", + "failed to change sort order header to '%s'\n", new_so); + goto err; + } + if (sam_hdr_change_HD(header, "GO", NULL) != 0) { + print_error("sort", + "failed to delete group order header\n"); goto err; } - if (is_by_qname) change_SO(header, "queryname"); - else change_SO(header, "coordinate"); + + // No gain to using the thread pool here as the flow of this code + // is such that we are *either* reading *or* sorting. Hence a shared + // pool makes no real difference except to reduce the thread count a little. + if (n_threads > 1) + hts_set_threads(fp, n_threads); + + if ((bam_mem = malloc(max_mem)) == NULL) { + print_error("sort", "couldn't allocate memory for bam_mem"); + goto err; + } + // write sub files - for (;;) { + k = max_k = bam_mem_offset = 0; + while ((res = sam_read1(fp, header, b)) >= 0) { + int mem_full = 0; + if (k == max_k) { - size_t kk, old_max = max_k; + bam1_tag *new_buf; max_k = max_k? max_k<<1 : 0x10000; - buf = (bam1_t**)realloc(buf, max_k * sizeof(bam1_t*)); - for (kk = old_max; kk < max_k; ++kk) buf[kk] = NULL; + if ((new_buf = realloc(buf, max_k * sizeof(bam1_tag))) == NULL) { + print_error("sort", "couldn't allocate memory for buf"); + goto err; + } + buf = new_buf; } - if (buf[k] == NULL) buf[k] = bam_init1(); - b = buf[k]; - if ((ret = sam_read1(fp, header, b)) < 0) break; - if (b->l_data < b->m_data>>2) { // shrink - b->m_data = b->l_data; - kroundup32(b->m_data); - b->data = (uint8_t*)realloc(b->data, b->m_data); + + // Check if the BAM record will fit in the memory limit + if (bam_mem_offset + sizeof(*b) + b->l_data < max_mem) { + // Copy record into the memory block + buf[k].bam_record = (bam1_t *)(bam_mem + bam_mem_offset); + *buf[k].bam_record = *b; + buf[k].bam_record->data = (uint8_t *)((char *)buf[k].bam_record + sizeof(bam1_t)); + memcpy(buf[k].bam_record->data, b->data, b->l_data); + // store next BAM record in next 8-byte-aligned address after + // current one + bam_mem_offset = (bam_mem_offset + sizeof(*b) + b->l_data + 8 - 1) & ~((size_t)(8 - 1)); + } else { + // Add a pointer to the remaining record + buf[k].bam_record = b; + mem_full = 1; + } + + // Pull out the pointer to the sort tag if applicable + if (g_is_by_tag) { + buf[k].tag = bam_aux_get(buf[k].bam_record, g_sort_tag); + } else { + buf[k].tag = NULL; } - mem += sizeof(bam1_t) + b->m_data + sizeof(void*) + sizeof(void*); // two sizeof(void*) for the data allocated to pointer arrays ++k; - if (mem >= max_mem) { - n_files = sort_blocks(n_files, k, buf, prefix, header, n_threads); + + if (mem_full) { + n_files = sort_blocks(n_files, k, buf, prefix, header, n_threads, + NULL); if (n_files < 0) { - ret = -1; goto err; } - mem = k = 0; + k = 0; + bam_mem_offset = 0; } } - if (ret != -1) { - fprintf(pysam_stderr, "[bam_sort_core] truncated file. Aborting.\n"); - ret = -1; + if (res != -1) { + print_error("sort", "truncated file. Aborting"); goto err; } + // Sort last records + if (k > 0) { + in_mem = calloc(n_threads > 0 ? n_threads : 1, sizeof(in_mem[0])); + if (!in_mem) goto err; + num_in_mem = sort_blocks(n_files, k, buf, prefix, header, n_threads, + in_mem); + if (num_in_mem < 0) goto err; + } else { + num_in_mem = 0; + } + // write the final output - if (n_files == 0) { // a single block + if (n_files == 0 && num_in_mem < 2) { // a single block ks_mergesort(sort, k, buf, 0); if (write_buffer(fnout, modeout, k, buf, header, n_threads, out_fmt) != 0) { - fprintf(pysam_stderr, "[bam_sort_core] failed to create \"%s\": %s\n", fnout, strerror(errno)); - ret = -1; + print_error_errno("sort", "failed to create \"%s\"", fnout); goto err; } } else { // then merge - char **fns; - n_files = sort_blocks(n_files, k, buf, prefix, header, n_threads); - if (n_files == -1) { - ret = -1; - goto err; - } - fprintf(pysam_stderr, "[bam_sort_core] merging from %d files...\n", n_files); + fprintf(samtools_stderr, + "[bam_sort_core] merging from %d files and %d in-memory blocks...\n", + n_files, num_in_mem); fns = (char**)calloc(n_files, sizeof(char*)); + if (!fns) goto err; for (i = 0; i < n_files; ++i) { fns[i] = (char*)calloc(strlen(prefix) + 20, 1); + if (!fns[i]) goto err; sprintf(fns[i], "%s.%.4d.bam", prefix, i); } - if (bam_merge_core2(is_by_qname, fnout, modeout, NULL, n_files, fns, - MERGE_COMBINE_RG|MERGE_COMBINE_PG|MERGE_FIRST_CO, - NULL, n_threads, in_fmt, out_fmt) < 0) { - // Propagate bam_merge_core2() failure; it has already emitted a + if (bam_merge_simple(is_by_qname, sort_by_tag, fnout, modeout, header, + n_files, fns, num_in_mem, in_mem, buf, + n_threads, "sort", in_fmt, out_fmt) < 0) { + // Propagate bam_merge_simple() failure; it has already emitted a // message explaining the failure, so no further message is needed. goto err; } - for (i = 0; i < n_files; ++i) { - unlink(fns[i]); - free(fns[i]); - } - free(fns); } ret = 0; err: // free - for (k = 0; k < max_k; ++k) bam_destroy1(buf[k]); + if (fns) { + for (i = 0; i < n_files; ++i) { + if (fns[i]) { + unlink(fns[i]); + free(fns[i]); + } + } + free(fns); + } + bam_destroy1(b); free(buf); + free(bam_mem); bam_hdr_destroy(header); - sam_close(fp); + if (fp) sam_close(fp); return ret; } @@ -1838,8 +2227,9 @@ int bam_sort_core(int is_by_qname, const char *fn, const char *prefix, size_t ma { int ret; char *fnout = calloc(strlen(prefix) + 4 + 1, 1); + if (!fnout) return -1; sprintf(fnout, "%s.bam", prefix); - ret = bam_sort_core_ext(is_by_qname, fn, prefix, fnout, "wb", max_mem, 0, NULL, NULL); + ret = bam_sort_core_ext(is_by_qname, NULL, fn, prefix, fnout, "wb", max_mem, 0, NULL, NULL); free(fnout); return ret; } @@ -1852,32 +2242,50 @@ static void sort_usage(FILE *fp) " -l INT Set compression level, from 0 (uncompressed) to 9 (best)\n" " -m INT Set maximum memory per thread; suffix K/M/G recognized [768M]\n" " -n Sort by read name\n" +" -t TAG Sort by value of TAG. Uses position as secondary index (or read name if -n is set)\n" " -o FILE Write final output to FILE rather than standard output\n" -" -T PREFIX Write temporary files to PREFIX.nnnn.bam\n" -" -@, --threads INT\n" -" Set number of sorting and compression threads [1]\n"); - sam_global_opt_help(fp, "-.O.."); +" -T PREFIX Write temporary files to PREFIX.nnnn.bam\n"); + sam_global_opt_help(fp, "-.O..@"); +} + +static void complain_about_memory_setting(size_t max_mem) { + char *suffix = ""; + const size_t nine_k = 9<<10; + if (max_mem > nine_k) { max_mem >>= 10; suffix = "K"; } + if (max_mem > nine_k) { max_mem >>= 10; suffix = "M"; } + + fprintf(samtools_stderr, +"[bam_sort] -m setting (%zu%s bytes) is less than the minimum required (%zuM).\n\n" +"Trying to run with -m too small can lead to the creation of a very large number\n" +"of temporary files. This may make sort fail due to it exceeding limits on the\n" +"number of files it can have open at the same time.\n\n" +"Please check your -m parameter. It should be an integer followed by one of the\n" +"letters K (for kilobytes), M (megabytes) or G (gigabytes). You should ensure it\n" +"is at least the minimum above, and much higher if you are sorting a large file.\n", + max_mem, suffix, SORT_MIN_MEGS_PER_THREAD); } int bam_sort(int argc, char *argv[]) { - size_t max_mem = 768<<20; // 512MB - int c, nargs, is_by_qname = 0, ret, o_seen = 0, n_threads = 0, level = -1; + size_t max_mem = SORT_DEFAULT_MEGS_PER_THREAD << 20; + int c, nargs, is_by_qname = 0, ret, o_seen = 0, level = -1; + char* sort_tag = NULL; char *fnout = "-", modeout[12]; kstring_t tmpprefix = { 0, 0, NULL }; struct stat st; sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 0, '@'), { "threads", required_argument, NULL, '@' }, { NULL, 0, NULL, 0 } }; - while ((c = getopt_long(argc, argv, "l:m:no:O:T:@:", lopts, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "l:m:no:O:T:@:t:", lopts, NULL)) >= 0) { switch (c) { case 'o': fnout = optarg; o_seen = 1; break; case 'n': is_by_qname = 1; break; + case 't': sort_tag = strdup(optarg); break; case 'm': { char *q; max_mem = strtol(optarg, &q, 0); @@ -1887,27 +2295,32 @@ int bam_sort(int argc, char *argv[]) break; } case 'T': kputs(optarg, &tmpprefix); break; - case '@': n_threads = atoi(optarg); break; case 'l': level = atoi(optarg); break; default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; /* else fall-through */ - case '?': sort_usage(pysam_stderr); ret = EXIT_FAILURE; goto sort_end; + case '?': sort_usage(samtools_stderr); ret = EXIT_FAILURE; goto sort_end; } } nargs = argc - optind; if (nargs == 0 && isatty(STDIN_FILENO)) { - sort_usage(pysam_stdout); + sort_usage(samtools_stdout); ret = EXIT_SUCCESS; goto sort_end; } else if (nargs >= 2) { // If exactly two, user probably tried to specify legacy if (nargs == 2) - fprintf(pysam_stderr, "[bam_sort] Use -T PREFIX / -o FILE to specify temporary and final output files\n"); + fprintf(samtools_stderr, "[bam_sort] Use -T PREFIX / -o FILE to specify temporary and final output files\n"); + + sort_usage(samtools_stderr); + ret = EXIT_FAILURE; + goto sort_end; + } - sort_usage(pysam_stderr); + if (max_mem < (SORT_MIN_MEGS_PER_THREAD << 20)) { + complain_about_memory_setting(max_mem); ret = EXIT_FAILURE; goto sort_end; } @@ -1926,8 +2339,8 @@ int bam_sort(int argc, char *argv[]) ksprintf(&tmpprefix, "samtools.%d.%u.tmp", (int) getpid(), t % 10000); } - ret = bam_sort_core_ext(is_by_qname, (nargs > 0)? argv[optind] : "-", - tmpprefix.s, fnout, modeout, max_mem, n_threads, + ret = bam_sort_core_ext(is_by_qname, sort_tag, (nargs > 0)? argv[optind] : "-", + tmpprefix.s, fnout, modeout, max_mem, ga.nthreads, &ga.in, &ga.out); if (ret >= 0) ret = EXIT_SUCCESS; @@ -1936,7 +2349,7 @@ int bam_sort(int argc, char *argv[]) // If we failed on opening the input file & it has no .bam/.cram/etc // extension, the user probably tried legacy -o if (ret == -2 && o_seen && nargs > 0 && sam_open_mode(dummy, argv[optind], NULL) < 0) - fprintf(pysam_stderr, "[bam_sort] Note the argument has been replaced by -T/-o options\n"); + fprintf(samtools_stderr, "[bam_sort] Note the argument has been replaced by -T/-o options\n"); ret = EXIT_FAILURE; } diff --git a/samtools/bam_split.c b/samtools/bam_split.c index 9a2998ade..9bb2030d3 100644 --- a/samtools/bam_split.c +++ b/samtools/bam_split.c @@ -1,6 +1,6 @@ /* bam_split.c -- split subcommand. - Copyright (C) 2013-2015 Genome Research Ltd. + Copyright (C) 2013-2016 Genome Research Ltd. Author: Martin Pollard @@ -34,7 +34,10 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include +#include "htslib/thread_pool.h" #include "sam_opts.h" +#include "samtools.h" KHASH_MAP_INIT_STR(c2i, int) @@ -61,6 +64,7 @@ struct state { samFile** rg_output_file; bam_hdr_t** rg_output_header; kh_c2i_t* rg_hash; + htsThreadPool p; }; typedef struct state state_t; @@ -78,7 +82,7 @@ static void usage(FILE *write_to) " -u FILE1 put reads with no RG tag or an unrecognised RG tag in FILE1\n" " -u FILE1:FILE2 ...and override the header with FILE2\n" " -v verbose output\n"); - sam_global_opt_help(write_to, "-...."); + sam_global_opt_help(write_to, "-....@"); fprintf(write_to, "\n" "Format string expansions:\n" @@ -95,11 +99,11 @@ static parsed_opts_t* parse_args(int argc, char** argv) { if (argc == 1) { usage(stdout); return NULL; } - const char* optstring = "vf:u:"; + const char* optstring = "vf:u:@:"; char* delim; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0, '@'), { NULL, 0, NULL, 0 } }; @@ -143,7 +147,7 @@ static parsed_opts_t* parse_args(int argc, char** argv) argv += optind; if (argc != 1) { - fprintf(stderr, "Invalid number of arguments: %d\n", argc); + print_error("split", "Invalid number of arguments: %d", argc); usage(stderr); free(retval); return NULL; @@ -270,7 +274,7 @@ static bool count_RG(bam_hdr_t* hdr, size_t* count, char*** output_name) // Filters a header of @RG lines where ID != id_keep // TODO: strip @PG's descended from other RGs and their descendants -static bool filter_header_rg(bam_hdr_t* hdr, const char* id_keep) +static bool filter_header_rg(bam_hdr_t* hdr, const char* id_keep, const char *arg_list) { kstring_t str = {0, 0, NULL}; @@ -315,28 +319,52 @@ static bool filter_header_rg(bam_hdr_t* hdr, const char* id_keep) free(hdr->text); hdr->text = ks_release(&str); + // Add the PG line + SAM_hdr *sh = sam_hdr_parse_(hdr->text, hdr->l_text); + if (sam_hdr_add_PG(sh, "samtools", + "VN", samtools_version(), + arg_list ? "CL": NULL, + arg_list ? arg_list : NULL, + NULL) != 0) + return -1; + + free(hdr->text); + hdr->text = strdup(sam_hdr_str(sh)); + hdr->l_text = sam_hdr_length(sh); + if (!hdr->text) + return false; + sam_hdr_free(sh); + return true; } // Set the initial state -static state_t* init(parsed_opts_t* opts) +static state_t* init(parsed_opts_t* opts, const char *arg_list) { state_t* retval = calloc(sizeof(state_t), 1); if (!retval) { - fprintf(stderr, "Out of memory"); + print_error_errno("split", "Initialisation failed"); return NULL; } + if (opts->ga.nthreads > 0) { + if (!(retval->p.pool = hts_tpool_init(opts->ga.nthreads))) { + fprintf(stderr, "Error creating thread pool\n"); + return NULL; + } + } + retval->merged_input_file = sam_open_format(opts->merged_input_name, "rb", &opts->ga.in); if (!retval->merged_input_file) { - fprintf(stderr, "Could not open input file (%s)\n", opts->merged_input_name); + print_error_errno("split", "Could not open \"%s\"", opts->merged_input_name); free(retval); return NULL; } + if (retval->p.pool) + hts_set_opt(retval->merged_input_file, HTS_OPT_THREAD_POOL, &retval->p); retval->merged_input_header = sam_hdr_read(retval->merged_input_file); if (retval->merged_input_header == NULL) { - fprintf(stderr, "Could not read header for file '%s'\n", - opts->merged_input_name); + print_error("split", "Could not read header from \"%s\"", opts->merged_input_name); cleanup_state(retval, false); return NULL; } @@ -345,14 +373,13 @@ static state_t* init(parsed_opts_t* opts) if (opts->unaccounted_header_name) { samFile* hdr_load = sam_open_format(opts->unaccounted_header_name, "r", &opts->ga.in); if (!hdr_load) { - fprintf(stderr, "Could not open unaccounted header file (%s)\n", opts->unaccounted_header_name); + print_error_errno("split", "Could not open unaccounted header file \"%s\"", opts->unaccounted_header_name); cleanup_state(retval, false); return NULL; } retval->unaccounted_header = sam_hdr_read(hdr_load); if (retval->unaccounted_header == NULL) { - fprintf(stderr, "Could not read header for file '%s'\n", - opts->unaccounted_header_name); + print_error("split", "Could not read header from \"%s\"", opts->unaccounted_header_name); cleanup_state(retval, false); return NULL; } @@ -363,10 +390,12 @@ static state_t* init(parsed_opts_t* opts) retval->unaccounted_file = sam_open_format(opts->unaccounted_name, "wb", &opts->ga.out); if (retval->unaccounted_file == NULL) { - fprintf(stderr, "Could not open unaccounted output file: %s\n", opts->unaccounted_name); + print_error_errno("split", "Could not open unaccounted output file \"%s\"", opts->unaccounted_name); cleanup_state(retval, false); return NULL; } + if (retval->p.pool) + hts_set_opt(retval->unaccounted_file, HTS_OPT_THREAD_POOL, &retval->p); } // Open output files for RGs @@ -378,7 +407,7 @@ static state_t* init(parsed_opts_t* opts) retval->rg_output_header = (bam_hdr_t**)calloc(retval->output_count, sizeof(bam_hdr_t*)); retval->rg_hash = kh_init_c2i(); if (!retval->rg_output_file_name || !retval->rg_output_file || !retval->rg_output_header || !retval->rg_hash) { - fprintf(stderr, "Could not allocate memory for output file array. Out of memory?"); + print_error_errno("split", "Could not initialise output file array"); cleanup_state(retval, false); return NULL; } @@ -386,7 +415,7 @@ static state_t* init(parsed_opts_t* opts) char* dirsep = strrchr(opts->merged_input_name, '/'); char* input_base_name = strdup(dirsep? dirsep+1 : opts->merged_input_name); if (!input_base_name) { - fprintf(stderr, "Out of memory\n"); + print_error_errno("split", "Filename manipulation failed"); cleanup_state(retval, false); return NULL; } @@ -403,7 +432,7 @@ static state_t* init(parsed_opts_t* opts) &opts->ga.out); if ( output_filename == NULL ) { - fprintf(stderr, "Error expanding output filename format string.\n"); + print_error("split", "Error expanding output filename format string"); cleanup_state(retval, false); free(input_base_name); return NULL; @@ -412,11 +441,13 @@ static state_t* init(parsed_opts_t* opts) retval->rg_output_file_name[i] = output_filename; retval->rg_output_file[i] = sam_open_format(output_filename, "wb", &opts->ga.out); if (retval->rg_output_file[i] == NULL) { - fprintf(stderr, "Could not open output file: %s\n", output_filename); + print_error_errno("split", "Could not open \"%s\"", output_filename); cleanup_state(retval, false); free(input_base_name); return NULL; } + if (retval->p.pool) + hts_set_opt(retval->rg_output_file[i], HTS_OPT_THREAD_POOL, &retval->p); // Record index in hash int ret; @@ -425,8 +456,8 @@ static state_t* init(parsed_opts_t* opts) // Set and edit header retval->rg_output_header[i] = bam_hdr_dup(retval->merged_input_header); - if ( !filter_header_rg(retval->rg_output_header[i], retval->rg_id[i]) ) { - fprintf(stderr, "Could not rewrite header for file: %s\n", output_filename); + if ( !filter_header_rg(retval->rg_output_header[i], retval->rg_id[i], arg_list) ) { + print_error("split", "Could not rewrite header for \"%s\"", output_filename); cleanup_state(retval, false); free(input_base_name); return NULL; @@ -441,14 +472,13 @@ static state_t* init(parsed_opts_t* opts) static bool split(state_t* state) { if (state->unaccounted_file && sam_hdr_write(state->unaccounted_file, state->unaccounted_header) != 0) { - fprintf(stderr, "Could not write output file header\n"); + print_error_errno("split", "Could not write output file header"); return false; } size_t i; for (i = 0; i < state->output_count; i++) { if (sam_hdr_write(state->rg_output_file[i], state->rg_output_header[i]) != 0) { - fprintf(stderr, "Could not write output file header for '%s'\n", - state->rg_output_file_name[i]); + print_error_errno("split", "Could not write file header to \"%s\"", state->rg_output_file_name[i]); return false; } } @@ -461,7 +491,7 @@ static bool split(state_t* state) bam_destroy1(file_read); file_read = NULL; if (r < -1) { - fprintf(stderr, "Could not read first input record\n"); + print_error("split", "Could not read first input record"); return false; } } @@ -482,8 +512,7 @@ static bool split(state_t* state) // if found write to the appropriate untangled bam int i = kh_val(state->rg_hash,iter); if (sam_write1(state->rg_output_file[i], state->rg_output_header[i], file_read) < 0) { - fprintf(stderr, "Could not write to output file '%s'\n", - state->rg_output_file_name[i]); + print_error_errno("split", "Could not write to \"%s\"", state->rg_output_file_name[i]); bam_destroy1(file_read); return false; } @@ -499,7 +528,7 @@ static bool split(state_t* state) return false; } else { if (sam_write1(state->unaccounted_file, state->unaccounted_header, file_read) < 0) { - fprintf(stderr, "Could not write to unaccounted output file\n"); + print_error_errno("split", "Could not write to unaccounted output file"); bam_destroy1(file_read); return false; } @@ -512,7 +541,7 @@ static bool split(state_t* state) bam_destroy1(file_read); file_read = NULL; if (r < -1) { - fprintf(stderr, "Could not read input record\n"); + print_error("split", "Could not read input record"); return false; } } @@ -529,7 +558,7 @@ static int cleanup_state(state_t* status, bool check_close) if (status->unaccounted_header) bam_hdr_destroy(status->unaccounted_header); if (status->unaccounted_file) { if (sam_close(status->unaccounted_file) < 0 && check_close) { - fprintf(stderr, "Error on closing unaccounted file\n"); + print_error("split", "Error on closing unaccounted file"); ret = -1; } } @@ -540,8 +569,7 @@ static int cleanup_state(state_t* status, bool check_close) bam_hdr_destroy(status->rg_output_header[i]); if (status->rg_output_file && status->rg_output_file[i]) { if (sam_close(status->rg_output_file[i]) < 0 && check_close) { - fprintf(stderr, "Error on closing output file '%s'\n", - status->rg_output_file_name[i]); + print_error("split", "Error on closing output file \"%s\"", status->rg_output_file_name[i]); ret = -1; } } @@ -557,6 +585,9 @@ static int cleanup_state(state_t* status, bool check_close) free(status->rg_id); free(status); + if (status->p.pool) + hts_tpool_destroy(status->p.pool); + return ret; } @@ -574,9 +605,10 @@ static void cleanup_opts(parsed_opts_t* opts) int main_split(int argc, char** argv) { int ret = 1; + char *arg_list = stringify_argv(argc+1, argv-1); parsed_opts_t* opts = parse_args(argc, argv); if (!opts) goto cleanup_opts; - state_t* status = init(opts); + state_t* status = init(opts, arg_list); if (!status) goto cleanup_opts; if (!split(status)) { @@ -588,6 +620,7 @@ int main_split(int argc, char** argv) cleanup_opts: cleanup_opts(opts); + free(arg_list); return ret; } diff --git a/samtools/bam_split.c.pysam.c b/samtools/bam_split.c.pysam.c index 2348f4876..9395c81e0 100644 --- a/samtools/bam_split.c.pysam.c +++ b/samtools/bam_split.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_split.c -- split subcommand. - Copyright (C) 2013-2015 Genome Research Ltd. + Copyright (C) 2013-2016 Genome Research Ltd. Author: Martin Pollard @@ -36,7 +36,10 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include +#include "htslib/thread_pool.h" #include "sam_opts.h" +#include "samtools.h" KHASH_MAP_INIT_STR(c2i, int) @@ -63,6 +66,7 @@ struct state { samFile** rg_output_file; bam_hdr_t** rg_output_header; kh_c2i_t* rg_hash; + htsThreadPool p; }; typedef struct state state_t; @@ -80,7 +84,7 @@ static void usage(FILE *write_to) " -u FILE1 put reads with no RG tag or an unrecognised RG tag in FILE1\n" " -u FILE1:FILE2 ...and override the header with FILE2\n" " -v verbose output\n"); - sam_global_opt_help(write_to, "-...."); + sam_global_opt_help(write_to, "-....@"); fprintf(write_to, "\n" "Format string expansions:\n" @@ -95,13 +99,13 @@ static void usage(FILE *write_to) // Takes the command line options and turns them into something we can understand static parsed_opts_t* parse_args(int argc, char** argv) { - if (argc == 1) { usage(pysam_stdout); return NULL; } + if (argc == 1) { usage(samtools_stdout); return NULL; } - const char* optstring = "vf:u:"; + const char* optstring = "vf:u:@:"; char* delim; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0, '@'), { NULL, 0, NULL, 0 } }; @@ -133,7 +137,7 @@ static parsed_opts_t* parse_args(int argc, char** argv) if (parse_sam_global_opt(opt, optarg, lopts, &retval->ga) == 0) break; /* else fall-through */ case '?': - usage(pysam_stdout); + usage(samtools_stdout); free(retval); return NULL; } @@ -145,8 +149,8 @@ static parsed_opts_t* parse_args(int argc, char** argv) argv += optind; if (argc != 1) { - fprintf(pysam_stderr, "Invalid number of arguments: %d\n", argc); - usage(pysam_stderr); + print_error("split", "Invalid number of arguments: %d", argc); + usage(samtools_stderr); free(retval); return NULL; } @@ -187,11 +191,11 @@ static char* expand_format_string(const char* format_string, const char* basenam kputs("bam", &str); break; case '\0': - // Error is: fprintf(pysam_stderr, "bad format string, trailing %%\n"); + // Error is: fprintf(samtools_stderr, "bad format string, trailing %%\n"); free(str.s); return NULL; default: - // Error is: fprintf(pysam_stderr, "bad format string, unknown format specifier\n"); + // Error is: fprintf(samtools_stderr, "bad format string, unknown format specifier\n"); free(str.s); return NULL; } @@ -272,7 +276,7 @@ static bool count_RG(bam_hdr_t* hdr, size_t* count, char*** output_name) // Filters a header of @RG lines where ID != id_keep // TODO: strip @PG's descended from other RGs and their descendants -static bool filter_header_rg(bam_hdr_t* hdr, const char* id_keep) +static bool filter_header_rg(bam_hdr_t* hdr, const char* id_keep, const char *arg_list) { kstring_t str = {0, 0, NULL}; @@ -317,28 +321,52 @@ static bool filter_header_rg(bam_hdr_t* hdr, const char* id_keep) free(hdr->text); hdr->text = ks_release(&str); + // Add the PG line + SAM_hdr *sh = sam_hdr_parse_(hdr->text, hdr->l_text); + if (sam_hdr_add_PG(sh, "samtools", + "VN", samtools_version(), + arg_list ? "CL": NULL, + arg_list ? arg_list : NULL, + NULL) != 0) + return -1; + + free(hdr->text); + hdr->text = strdup(sam_hdr_str(sh)); + hdr->l_text = sam_hdr_length(sh); + if (!hdr->text) + return false; + sam_hdr_free(sh); + return true; } // Set the initial state -static state_t* init(parsed_opts_t* opts) +static state_t* init(parsed_opts_t* opts, const char *arg_list) { state_t* retval = calloc(sizeof(state_t), 1); if (!retval) { - fprintf(pysam_stderr, "Out of memory"); + print_error_errno("split", "Initialisation failed"); return NULL; } + if (opts->ga.nthreads > 0) { + if (!(retval->p.pool = hts_tpool_init(opts->ga.nthreads))) { + fprintf(samtools_stderr, "Error creating thread pool\n"); + return NULL; + } + } + retval->merged_input_file = sam_open_format(opts->merged_input_name, "rb", &opts->ga.in); if (!retval->merged_input_file) { - fprintf(pysam_stderr, "Could not open input file (%s)\n", opts->merged_input_name); + print_error_errno("split", "Could not open \"%s\"", opts->merged_input_name); free(retval); return NULL; } + if (retval->p.pool) + hts_set_opt(retval->merged_input_file, HTS_OPT_THREAD_POOL, &retval->p); retval->merged_input_header = sam_hdr_read(retval->merged_input_file); if (retval->merged_input_header == NULL) { - fprintf(pysam_stderr, "Could not read header for file '%s'\n", - opts->merged_input_name); + print_error("split", "Could not read header from \"%s\"", opts->merged_input_name); cleanup_state(retval, false); return NULL; } @@ -347,14 +375,13 @@ static state_t* init(parsed_opts_t* opts) if (opts->unaccounted_header_name) { samFile* hdr_load = sam_open_format(opts->unaccounted_header_name, "r", &opts->ga.in); if (!hdr_load) { - fprintf(pysam_stderr, "Could not open unaccounted header file (%s)\n", opts->unaccounted_header_name); + print_error_errno("split", "Could not open unaccounted header file \"%s\"", opts->unaccounted_header_name); cleanup_state(retval, false); return NULL; } retval->unaccounted_header = sam_hdr_read(hdr_load); if (retval->unaccounted_header == NULL) { - fprintf(pysam_stderr, "Could not read header for file '%s'\n", - opts->unaccounted_header_name); + print_error("split", "Could not read header from \"%s\"", opts->unaccounted_header_name); cleanup_state(retval, false); return NULL; } @@ -365,22 +392,24 @@ static state_t* init(parsed_opts_t* opts) retval->unaccounted_file = sam_open_format(opts->unaccounted_name, "wb", &opts->ga.out); if (retval->unaccounted_file == NULL) { - fprintf(pysam_stderr, "Could not open unaccounted output file: %s\n", opts->unaccounted_name); + print_error_errno("split", "Could not open unaccounted output file \"%s\"", opts->unaccounted_name); cleanup_state(retval, false); return NULL; } + if (retval->p.pool) + hts_set_opt(retval->unaccounted_file, HTS_OPT_THREAD_POOL, &retval->p); } // Open output files for RGs if (!count_RG(retval->merged_input_header, &retval->output_count, &retval->rg_id)) return NULL; - if (opts->verbose) fprintf(pysam_stderr, "@RG's found %zu\n",retval->output_count); + if (opts->verbose) fprintf(samtools_stderr, "@RG's found %zu\n",retval->output_count); retval->rg_output_file_name = (char **)calloc(retval->output_count, sizeof(char *)); retval->rg_output_file = (samFile**)calloc(retval->output_count, sizeof(samFile*)); retval->rg_output_header = (bam_hdr_t**)calloc(retval->output_count, sizeof(bam_hdr_t*)); retval->rg_hash = kh_init_c2i(); if (!retval->rg_output_file_name || !retval->rg_output_file || !retval->rg_output_header || !retval->rg_hash) { - fprintf(pysam_stderr, "Could not allocate memory for output file array. Out of memory?"); + print_error_errno("split", "Could not initialise output file array"); cleanup_state(retval, false); return NULL; } @@ -388,7 +417,7 @@ static state_t* init(parsed_opts_t* opts) char* dirsep = strrchr(opts->merged_input_name, '/'); char* input_base_name = strdup(dirsep? dirsep+1 : opts->merged_input_name); if (!input_base_name) { - fprintf(pysam_stderr, "Out of memory\n"); + print_error_errno("split", "Filename manipulation failed"); cleanup_state(retval, false); return NULL; } @@ -405,7 +434,7 @@ static state_t* init(parsed_opts_t* opts) &opts->ga.out); if ( output_filename == NULL ) { - fprintf(pysam_stderr, "Error expanding output filename format string.\n"); + print_error("split", "Error expanding output filename format string"); cleanup_state(retval, false); free(input_base_name); return NULL; @@ -414,11 +443,13 @@ static state_t* init(parsed_opts_t* opts) retval->rg_output_file_name[i] = output_filename; retval->rg_output_file[i] = sam_open_format(output_filename, "wb", &opts->ga.out); if (retval->rg_output_file[i] == NULL) { - fprintf(pysam_stderr, "Could not open output file: %s\n", output_filename); + print_error_errno("split", "Could not open \"%s\"", output_filename); cleanup_state(retval, false); free(input_base_name); return NULL; } + if (retval->p.pool) + hts_set_opt(retval->rg_output_file[i], HTS_OPT_THREAD_POOL, &retval->p); // Record index in hash int ret; @@ -427,8 +458,8 @@ static state_t* init(parsed_opts_t* opts) // Set and edit header retval->rg_output_header[i] = bam_hdr_dup(retval->merged_input_header); - if ( !filter_header_rg(retval->rg_output_header[i], retval->rg_id[i]) ) { - fprintf(pysam_stderr, "Could not rewrite header for file: %s\n", output_filename); + if ( !filter_header_rg(retval->rg_output_header[i], retval->rg_id[i], arg_list) ) { + print_error("split", "Could not rewrite header for \"%s\"", output_filename); cleanup_state(retval, false); free(input_base_name); return NULL; @@ -443,14 +474,13 @@ static state_t* init(parsed_opts_t* opts) static bool split(state_t* state) { if (state->unaccounted_file && sam_hdr_write(state->unaccounted_file, state->unaccounted_header) != 0) { - fprintf(pysam_stderr, "Could not write output file header\n"); + print_error_errno("split", "Could not write output file header"); return false; } size_t i; for (i = 0; i < state->output_count; i++) { if (sam_hdr_write(state->rg_output_file[i], state->rg_output_header[i]) != 0) { - fprintf(pysam_stderr, "Could not write output file header for '%s'\n", - state->rg_output_file_name[i]); + print_error_errno("split", "Could not write file header to \"%s\"", state->rg_output_file_name[i]); return false; } } @@ -463,7 +493,7 @@ static bool split(state_t* state) bam_destroy1(file_read); file_read = NULL; if (r < -1) { - fprintf(pysam_stderr, "Could not read first input record\n"); + print_error("split", "Could not read first input record"); return false; } } @@ -484,8 +514,7 @@ static bool split(state_t* state) // if found write to the appropriate untangled bam int i = kh_val(state->rg_hash,iter); if (sam_write1(state->rg_output_file[i], state->rg_output_header[i], file_read) < 0) { - fprintf(pysam_stderr, "Could not write to output file '%s'\n", - state->rg_output_file_name[i]); + print_error_errno("split", "Could not write to \"%s\"", state->rg_output_file_name[i]); bam_destroy1(file_read); return false; } @@ -493,15 +522,15 @@ static bool split(state_t* state) // otherwise write to the unaccounted bam if there is one or fail if (state->unaccounted_file == NULL) { if (tag) { - fprintf(pysam_stderr, "Read \"%s\" with unaccounted for tag \"%s\".\n", bam_get_qname(file_read), bam_aux2Z(tag)); + fprintf(samtools_stderr, "Read \"%s\" with unaccounted for tag \"%s\".\n", bam_get_qname(file_read), bam_aux2Z(tag)); } else { - fprintf(pysam_stderr, "Read \"%s\" has no RG tag.\n", bam_get_qname(file_read)); + fprintf(samtools_stderr, "Read \"%s\" has no RG tag.\n", bam_get_qname(file_read)); } bam_destroy1(file_read); return false; } else { if (sam_write1(state->unaccounted_file, state->unaccounted_header, file_read) < 0) { - fprintf(pysam_stderr, "Could not write to unaccounted output file\n"); + print_error_errno("split", "Could not write to unaccounted output file"); bam_destroy1(file_read); return false; } @@ -514,7 +543,7 @@ static bool split(state_t* state) bam_destroy1(file_read); file_read = NULL; if (r < -1) { - fprintf(pysam_stderr, "Could not read input record\n"); + print_error("split", "Could not read input record"); return false; } } @@ -531,7 +560,7 @@ static int cleanup_state(state_t* status, bool check_close) if (status->unaccounted_header) bam_hdr_destroy(status->unaccounted_header); if (status->unaccounted_file) { if (sam_close(status->unaccounted_file) < 0 && check_close) { - fprintf(pysam_stderr, "Error on closing unaccounted file\n"); + print_error("split", "Error on closing unaccounted file"); ret = -1; } } @@ -542,8 +571,7 @@ static int cleanup_state(state_t* status, bool check_close) bam_hdr_destroy(status->rg_output_header[i]); if (status->rg_output_file && status->rg_output_file[i]) { if (sam_close(status->rg_output_file[i]) < 0 && check_close) { - fprintf(pysam_stderr, "Error on closing output file '%s'\n", - status->rg_output_file_name[i]); + print_error("split", "Error on closing output file \"%s\"", status->rg_output_file_name[i]); ret = -1; } } @@ -559,6 +587,9 @@ static int cleanup_state(state_t* status, bool check_close) free(status->rg_id); free(status); + if (status->p.pool) + hts_tpool_destroy(status->p.pool); + return ret; } @@ -576,9 +607,10 @@ static void cleanup_opts(parsed_opts_t* opts) int main_split(int argc, char** argv) { int ret = 1; + char *arg_list = stringify_argv(argc+1, argv-1); parsed_opts_t* opts = parse_args(argc, argv); if (!opts) goto cleanup_opts; - state_t* status = init(opts); + state_t* status = init(opts, arg_list); if (!status) goto cleanup_opts; if (!split(status)) { @@ -590,6 +622,7 @@ int main_split(int argc, char** argv) cleanup_opts: cleanup_opts(opts); + free(arg_list); return ret; } diff --git a/samtools/bam_stat.c b/samtools/bam_stat.c index f6cf1d5c4..aa5f8d301 100644 --- a/samtools/bam_stat.c +++ b/samtools/bam_stat.c @@ -34,6 +34,7 @@ DEALINGS IN THE SOFTWARE. */ #include "htslib/sam.h" #include "samtools.h" +#include "sam_opts.h" typedef struct { long long n_reads[2], n_mapped[2], n_pair_all[2], n_pair_map[2], n_pair_good[2]; @@ -94,7 +95,8 @@ static const char *percent(char *buffer, long long n, long long total) static void usage_exit(FILE *fp, int exit_status) { - fprintf(fp, "Usage: samtools flagstat [--input-fmt-option OPT=VAL] \n"); + fprintf(fp, "Usage: samtools flagstat [options] \n"); + sam_global_opt_help(fp, "-.---@"); exit(exit_status); } @@ -104,25 +106,23 @@ int bam_flagstat(int argc, char *argv[]) bam_hdr_t *header; bam_flagstat_t *s; char b0[16], b1[16]; - hts_opt *in_opts = NULL; int c; enum { INPUT_FMT_OPTION = CHAR_MAX+1, }; + sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - {"input-fmt-option", required_argument, NULL, INPUT_FMT_OPTION}, + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', '-', '@'), {NULL, 0, NULL, 0} }; - while ((c = getopt_long(argc, argv, "", lopts, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "@:", lopts, NULL)) >= 0) { switch (c) { - case INPUT_FMT_OPTION: - if (hts_opt_add(&in_opts, optarg) < 0) - usage_exit(stderr, EXIT_FAILURE); - break; - default: + default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; + /* else fall-through */ + case '?': usage_exit(stderr, EXIT_FAILURE); } } @@ -131,15 +131,13 @@ int bam_flagstat(int argc, char *argv[]) if (argc == optind) usage_exit(stdout, EXIT_SUCCESS); else usage_exit(stderr, EXIT_FAILURE); } - fp = sam_open(argv[optind], "r"); + fp = sam_open_format(argv[optind], "r", &ga.in); if (fp == NULL) { print_error_errno("flagstat", "Cannot open input file \"%s\"", argv[optind]); return 1; } - if (hts_opt_apply(fp, in_opts)) { - fprintf(stderr, "Failed to apply input-fmt-options\n"); - return 1; - } + if (ga.nthreads > 0) + hts_set_threads(fp, ga.nthreads); if (hts_set_opt(fp, CRAM_OPT_REQUIRED_FIELDS, SAM_FLAG | SAM_MAPQ | SAM_RNEXT)) { @@ -174,6 +172,6 @@ int bam_flagstat(int argc, char *argv[]) free(s); bam_hdr_destroy(header); sam_close(fp); - hts_opt_free(in_opts); + sam_global_args_free(&ga); return 0; } diff --git a/samtools/bam_stat.c.pysam.c b/samtools/bam_stat.c.pysam.c index cdca4dd7d..40c17c45d 100644 --- a/samtools/bam_stat.c.pysam.c +++ b/samtools/bam_stat.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bam_stat.c -- flagstat subcommand. @@ -36,6 +36,7 @@ DEALINGS IN THE SOFTWARE. */ #include "htslib/sam.h" #include "samtools.h" +#include "sam_opts.h" typedef struct { long long n_reads[2], n_mapped[2], n_pair_all[2], n_pair_map[2], n_pair_good[2]; @@ -83,7 +84,7 @@ bam_flagstat_t *bam_flagstat_core(samFile *fp, bam_hdr_t *h) flagstat_loop(s, c); bam_destroy1(b); if (ret != -1) - fprintf(pysam_stderr, "[bam_flagstat_core] Truncated file? Continue anyway.\n"); + fprintf(samtools_stderr, "[bam_flagstat_core] Truncated file? Continue anyway.\n"); return s; } @@ -96,7 +97,8 @@ static const char *percent(char *buffer, long long n, long long total) static void usage_exit(FILE *fp, int exit_status) { - fprintf(fp, "Usage: samtools flagstat [--input-fmt-option OPT=VAL] \n"); + fprintf(fp, "Usage: samtools flagstat [options] \n"); + sam_global_opt_help(fp, "-.---@"); exit(exit_status); } @@ -106,76 +108,72 @@ int bam_flagstat(int argc, char *argv[]) bam_hdr_t *header; bam_flagstat_t *s; char b0[16], b1[16]; - hts_opt *in_opts = NULL; int c; enum { INPUT_FMT_OPTION = CHAR_MAX+1, }; + sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - {"input-fmt-option", required_argument, NULL, INPUT_FMT_OPTION}, + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', '-', '@'), {NULL, 0, NULL, 0} }; - while ((c = getopt_long(argc, argv, "", lopts, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "@:", lopts, NULL)) >= 0) { switch (c) { - case INPUT_FMT_OPTION: - if (hts_opt_add(&in_opts, optarg) < 0) - usage_exit(pysam_stderr, EXIT_FAILURE); - break; - default: - usage_exit(pysam_stderr, EXIT_FAILURE); + default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; + /* else fall-through */ + case '?': + usage_exit(samtools_stderr, EXIT_FAILURE); } } if (argc != optind+1) { - if (argc == optind) usage_exit(pysam_stdout, EXIT_SUCCESS); - else usage_exit(pysam_stderr, EXIT_FAILURE); + if (argc == optind) usage_exit(samtools_stdout, EXIT_SUCCESS); + else usage_exit(samtools_stderr, EXIT_FAILURE); } - fp = sam_open(argv[optind], "r"); + fp = sam_open_format(argv[optind], "r", &ga.in); if (fp == NULL) { print_error_errno("flagstat", "Cannot open input file \"%s\"", argv[optind]); return 1; } - if (hts_opt_apply(fp, in_opts)) { - fprintf(pysam_stderr, "Failed to apply input-fmt-options\n"); - return 1; - } + if (ga.nthreads > 0) + hts_set_threads(fp, ga.nthreads); if (hts_set_opt(fp, CRAM_OPT_REQUIRED_FIELDS, SAM_FLAG | SAM_MAPQ | SAM_RNEXT)) { - fprintf(pysam_stderr, "Failed to set CRAM_OPT_REQUIRED_FIELDS value\n"); + fprintf(samtools_stderr, "Failed to set CRAM_OPT_REQUIRED_FIELDS value\n"); return 1; } if (hts_set_opt(fp, CRAM_OPT_DECODE_MD, 0)) { - fprintf(pysam_stderr, "Failed to set CRAM_OPT_DECODE_MD value\n"); + fprintf(samtools_stderr, "Failed to set CRAM_OPT_DECODE_MD value\n"); return 1; } header = sam_hdr_read(fp); if (header == NULL) { - fprintf(pysam_stderr, "Failed to read header for \"%s\"\n", argv[optind]); + fprintf(samtools_stderr, "Failed to read header for \"%s\"\n", argv[optind]); return 1; } s = bam_flagstat_core(fp, header); - fprintf(pysam_stdout, "%lld + %lld in total (QC-passed reads + QC-failed reads)\n", s->n_reads[0], s->n_reads[1]); - fprintf(pysam_stdout, "%lld + %lld secondary\n", s->n_secondary[0], s->n_secondary[1]); - fprintf(pysam_stdout, "%lld + %lld supplementary\n", s->n_supp[0], s->n_supp[1]); - fprintf(pysam_stdout, "%lld + %lld duplicates\n", s->n_dup[0], s->n_dup[1]); - fprintf(pysam_stdout, "%lld + %lld mapped (%s : %s)\n", s->n_mapped[0], s->n_mapped[1], percent(b0, s->n_mapped[0], s->n_reads[0]), percent(b1, s->n_mapped[1], s->n_reads[1])); - fprintf(pysam_stdout, "%lld + %lld paired in sequencing\n", s->n_pair_all[0], s->n_pair_all[1]); - fprintf(pysam_stdout, "%lld + %lld read1\n", s->n_read1[0], s->n_read1[1]); - fprintf(pysam_stdout, "%lld + %lld read2\n", s->n_read2[0], s->n_read2[1]); - fprintf(pysam_stdout, "%lld + %lld properly paired (%s : %s)\n", s->n_pair_good[0], s->n_pair_good[1], percent(b0, s->n_pair_good[0], s->n_pair_all[0]), percent(b1, s->n_pair_good[1], s->n_pair_all[1])); - fprintf(pysam_stdout, "%lld + %lld with itself and mate mapped\n", s->n_pair_map[0], s->n_pair_map[1]); - fprintf(pysam_stdout, "%lld + %lld singletons (%s : %s)\n", s->n_sgltn[0], s->n_sgltn[1], percent(b0, s->n_sgltn[0], s->n_pair_all[0]), percent(b1, s->n_sgltn[1], s->n_pair_all[1])); - fprintf(pysam_stdout, "%lld + %lld with mate mapped to a different chr\n", s->n_diffchr[0], s->n_diffchr[1]); - fprintf(pysam_stdout, "%lld + %lld with mate mapped to a different chr (mapQ>=5)\n", s->n_diffhigh[0], s->n_diffhigh[1]); + fprintf(samtools_stdout, "%lld + %lld in total (QC-passed reads + QC-failed reads)\n", s->n_reads[0], s->n_reads[1]); + fprintf(samtools_stdout, "%lld + %lld secondary\n", s->n_secondary[0], s->n_secondary[1]); + fprintf(samtools_stdout, "%lld + %lld supplementary\n", s->n_supp[0], s->n_supp[1]); + fprintf(samtools_stdout, "%lld + %lld duplicates\n", s->n_dup[0], s->n_dup[1]); + fprintf(samtools_stdout, "%lld + %lld mapped (%s : %s)\n", s->n_mapped[0], s->n_mapped[1], percent(b0, s->n_mapped[0], s->n_reads[0]), percent(b1, s->n_mapped[1], s->n_reads[1])); + fprintf(samtools_stdout, "%lld + %lld paired in sequencing\n", s->n_pair_all[0], s->n_pair_all[1]); + fprintf(samtools_stdout, "%lld + %lld read1\n", s->n_read1[0], s->n_read1[1]); + fprintf(samtools_stdout, "%lld + %lld read2\n", s->n_read2[0], s->n_read2[1]); + fprintf(samtools_stdout, "%lld + %lld properly paired (%s : %s)\n", s->n_pair_good[0], s->n_pair_good[1], percent(b0, s->n_pair_good[0], s->n_pair_all[0]), percent(b1, s->n_pair_good[1], s->n_pair_all[1])); + fprintf(samtools_stdout, "%lld + %lld with itself and mate mapped\n", s->n_pair_map[0], s->n_pair_map[1]); + fprintf(samtools_stdout, "%lld + %lld singletons (%s : %s)\n", s->n_sgltn[0], s->n_sgltn[1], percent(b0, s->n_sgltn[0], s->n_pair_all[0]), percent(b1, s->n_sgltn[1], s->n_pair_all[1])); + fprintf(samtools_stdout, "%lld + %lld with mate mapped to a different chr\n", s->n_diffchr[0], s->n_diffchr[1]); + fprintf(samtools_stdout, "%lld + %lld with mate mapped to a different chr (mapQ>=5)\n", s->n_diffhigh[0], s->n_diffhigh[1]); free(s); bam_hdr_destroy(header); sam_close(fp); - hts_opt_free(in_opts); + sam_global_args_free(&ga); return 0; } diff --git a/samtools/bam_tview.c b/samtools/bam_tview.c deleted file mode 100644 index f1f0cc77a..000000000 --- a/samtools/bam_tview.c +++ /dev/null @@ -1,441 +0,0 @@ -/* bam_tview.c -- tview subcommand. - - Copyright (C) 2008-2015 Genome Research Ltd. - Portions copyright (C) 2013 Pierre Lindenbaum, Institut du Thorax, INSERM U1087, Université de Nantes. - - Author: Heng Li - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notices and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. */ - -#include - -#include -#include -#include "bam_tview.h" -#include -#include -#include -#include "sam_opts.h" - -khash_t(kh_rg)* get_rg_sample(const char* header, const char* sample) -{ - khash_t(kh_rg)* rg_hash = kh_init(kh_rg); - // given sample id return all the RD ID's - const char rg_regex[] = "^@RG.*\tID:([!-)+-<>-~][ !-~]*)(\t.*$|$)"; - - regex_t rg_id; - regmatch_t* matches = (regmatch_t*)calloc(2, sizeof(regmatch_t)); - if (matches == NULL) { perror("out of memory"); exit(-1); } - regcomp(&rg_id, rg_regex, REG_EXTENDED|REG_NEWLINE); - char* text = strdup(header); - char* end = text + strlen(header); - char* tofree = text; - while (end > text && regexec(&rg_id, text, 2, matches, 0) == 0) { // foreach rg id in header - int ret; - text[matches[1].rm_eo] = '\0'; - kh_put(kh_rg, rg_hash, strdup(text+matches[1].rm_so), &ret); // Add the RG to the list - text += matches[0].rm_eo + 1; // Move search pointer forward - } - free(tofree); - return rg_hash; -} - -int base_tv_init(tview_t* tv, const char *fn, const char *fn_fa, - const char *samples, const htsFormat *fmt) -{ - assert(tv!=NULL); - assert(fn!=NULL); - tv->mrow = 24; tv->mcol = 80; - tv->color_for = TV_COLOR_MAPQ; - tv->is_dot = 1; - - tv->fp = sam_open_format(fn, "r", fmt); - if(tv->fp == NULL) - { - fprintf(stderr,"sam_open %s. %s\n", fn,fn_fa); - exit(EXIT_FAILURE); - } - // TODO bgzf_set_cache_size(tv->fp->fp.bgzf, 8 * 1024 *1024); - assert(tv->fp); - - tv->header = sam_hdr_read(tv->fp); - if(tv->header == NULL) - { - fprintf(stderr,"Cannot read '%s'.\n", fn); - exit(EXIT_FAILURE); - } - tv->idx = sam_index_load(tv->fp, fn); - if (tv->idx == NULL) - { - fprintf(stderr,"Cannot read index for '%s'.\n", fn); - exit(EXIT_FAILURE); - } - tv->lplbuf = bam_lplbuf_init(tv_pl_func, tv); - if (fn_fa) tv->fai = fai_load(fn_fa); - tv->bca = bcf_call_init(0.83, 13); - tv->ins = 1; - - // If the user has asked for specific samples find out create a list of readgroups make up these samples - if ( samples ) - { - tv->rg_hash = get_rg_sample(tv->header->text, samples); // Init the list of rg's - } - - return 0; -} - - -void base_tv_destroy(tview_t* tv) -{ - bam_lplbuf_destroy(tv->lplbuf); - bcf_call_destroy(tv->bca); - hts_idx_destroy(tv->idx); - if (tv->fai) fai_destroy(tv->fai); - free(tv->ref); - bam_hdr_destroy(tv->header); - sam_close(tv->fp); -} - - -int tv_pl_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl, void *data) -{ - tview_t *tv = (tview_t*)data; - int i, j, c, rb, attr, max_ins = 0; - uint32_t call = 0; - if (pos < tv->left_pos || tv->ccol > tv->mcol) return 0; // out of screen - // print reference - rb = (tv->ref && pos - tv->left_pos < tv->l_ref)? tv->ref[pos - tv->left_pos] : 'N'; - for (i = tv->last_pos + 1; i < pos; ++i) { - if (i%10 == 0 && tv->mcol - tv->ccol >= 10) tv->my_mvprintw(tv,0, tv->ccol, "%-d", i+1); - c = tv->ref? tv->ref[i - tv->left_pos] : 'N'; - tv->my_mvaddch(tv,1, tv->ccol++, c); - } - if (pos%10 == 0 && tv->mcol - tv->ccol >= 10) tv->my_mvprintw(tv,0, tv->ccol, "%-d", pos+1); - { // call consensus - bcf_callret1_t bcr; - memset(&bcr, 0, sizeof bcr); - int qsum[4], a1, a2, tmp; - double p[3], prior = 30; - bcf_call_glfgen(n, pl, seq_nt16_table[rb], tv->bca, &bcr); - for (i = 0; i < 4; ++i) qsum[i] = ((int)bcr.qsum[i])<<2 | i; - for (i = 1; i < 4; ++i) // insertion sort - for (j = i; j > 0 && qsum[j] > qsum[j-1]; --j) - tmp = qsum[j], qsum[j] = qsum[j-1], qsum[j-1] = tmp; - a1 = qsum[0]&3; a2 = qsum[1]&3; - p[0] = bcr.p[a1*5+a1]; p[1] = bcr.p[a1*5+a2] + prior; p[2] = bcr.p[a2*5+a2]; - if ("ACGT"[a1] != toupper(rb)) p[0] += prior + 3; - if ("ACGT"[a2] != toupper(rb)) p[2] += prior + 3; - if (p[0] < p[1] && p[0] < p[2]) call = (1<my_underline(tv); - c = ",ACMGRSVTWYHKDBN"[call>>16&0xf]; - i = (call&0xffff)/10+1; - if (i > 4) i = 4; - attr |= tv->my_colorpair(tv,i); - if (c == toupper(rb)) c = '.'; - tv->my_attron(tv,attr); - tv->my_mvaddch(tv,2, tv->ccol, c); - tv->my_attroff(tv,attr); - if(tv->ins) { - // calculate maximum insert - for (i = 0; i < n; ++i) { - const bam_pileup1_t *p = pl + i; - if (p->indel > 0 && max_ins < p->indel) max_ins = p->indel; - } - } - // core loop - for (j = 0; j <= max_ins; ++j) { - for (i = 0; i < n; ++i) { - const bam_pileup1_t *p = pl + i; - int row = TV_MIN_ALNROW + p->level - tv->row_shift; - if (j == 0) { - if (!p->is_del) { - if (tv->base_for == TV_BASE_COLOR_SPACE && - (c = bam_aux_getCSi(p->b, p->qpos))) { - // assume that if we found one color, we will be able to get the color error - if (tv->is_dot && '-' == bam_aux_getCEi(p->b, p->qpos)) c = bam_is_rev(p->b)? ',' : '.'; - } else { - if (tv->show_name) { - char *name = bam_get_qname(p->b); - c = (p->qpos + 1 >= p->b->core.l_qname)? ' ' : name[p->qpos]; - } else { - c = seq_nt16_str[bam_seqi(bam_get_seq(p->b), p->qpos)]; - if (tv->is_dot && toupper(c) == toupper(rb)) c = bam_is_rev(p->b)? ',' : '.'; - } - } - } else c = p->is_refskip? (bam_is_rev(p->b)? '<' : '>') : '*'; - } else { // padding - if (j > p->indel) c = '*'; - else { // insertion - if (tv->base_for == TV_BASE_NUCL) { - if (tv->show_name) { - char *name = bam_get_qname(p->b); - c = (p->qpos + j + 1 >= p->b->core.l_qname)? ' ' : name[p->qpos + j]; - } else { - c = seq_nt16_str[bam_seqi(bam_get_seq(p->b), p->qpos + j)]; - if (j == 0 && tv->is_dot && toupper(c) == toupper(rb)) c = bam_is_rev(p->b)? ',' : '.'; - } - } else { - c = bam_aux_getCSi(p->b, p->qpos + j); - if (tv->is_dot && '-' == bam_aux_getCEi(p->b, p->qpos + j)) c = bam_is_rev(p->b)? ',' : '.'; - } - } - } - if (row > TV_MIN_ALNROW && row < tv->mrow) { - int x; - attr = 0; - if (((p->b->core.flag&BAM_FPAIRED) && !(p->b->core.flag&BAM_FPROPER_PAIR)) - || (p->b->core.flag & BAM_FSECONDARY)) attr |= tv->my_underline(tv); - if (tv->color_for == TV_COLOR_BASEQ) { - x = bam_get_qual(p->b)[p->qpos]/10 + 1; - if (x > 4) x = 4; - attr |= tv->my_colorpair(tv,x); - } else if (tv->color_for == TV_COLOR_MAPQ) { - x = p->b->core.qual/10 + 1; - if (x > 4) x = 4; - attr |= tv->my_colorpair(tv,x); - } else if (tv->color_for == TV_COLOR_NUCL) { - x = seq_nt16_int[bam_seqi(bam_get_seq(p->b), p->qpos)] + 5; - attr |= tv->my_colorpair(tv,x); - } else if(tv->color_for == TV_COLOR_COL) { - x = 0; - switch(bam_aux_getCSi(p->b, p->qpos)) { - case '0': x = 0; break; - case '1': x = 1; break; - case '2': x = 2; break; - case '3': x = 3; break; - case '4': x = 4; break; - default: x = seq_nt16_int[bam_seqi(bam_get_seq(p->b), p->qpos)]; break; - } - x+=5; - attr |= tv->my_colorpair(tv,x); - } else if(tv->color_for == TV_COLOR_COLQ) { - x = bam_aux_getCQi(p->b, p->qpos); - if(0 == x) x = bam_get_qual(p->b)[p->qpos]; - x = x/10 + 1; - if (x > 4) x = 4; - attr |= tv->my_colorpair(tv,x); - } - tv->my_attron(tv,attr); - tv->my_mvaddch(tv,row, tv->ccol, bam_is_rev(p->b)? tolower(c) : toupper(c)); - tv->my_attroff(tv,attr); - } - } - c = j? '*' : rb; - if (c == '*') { - attr = tv->my_colorpair(tv,8); - tv->my_attron(tv,attr); - tv->my_mvaddch(tv,1, tv->ccol++, c); - tv->my_attroff(tv,attr); - } else tv->my_mvaddch(tv,1, tv->ccol++, c); - } - tv->last_pos = pos; - return 0; -} - - - - -static int tv_push_aln(const bam1_t *b, tview_t *tv) -{ - /* If we are restricted to specific readgroups check RG is in the list */ - if ( tv->rg_hash ) - { - const uint8_t *rg = bam_aux_get(b, "RG"); - if ( !rg ) return 0; // If we don't have an RG tag exclude read - khiter_t k = kh_get(kh_rg, tv->rg_hash, (const char*)(rg + 1)); - if ( k == kh_end(tv->rg_hash) ) return 0; // if RG tag is not in list of allowed tags exclude read - } - if (tv->no_skip) { - uint32_t *cigar = bam_get_cigar(b); // this is cheating... - int i; - for (i = 0; i core.n_cigar; ++i) { - if ((cigar[i]&0xf) == BAM_CREF_SKIP) - cigar[i] = cigar[i]>>4<<4 | BAM_CDEL; - } - } - bam_lplbuf_push(b, tv->lplbuf); - return 0; -} - -int base_draw_aln(tview_t *tv, int tid, int pos) -{ - assert(tv!=NULL); - // reset - tv->my_clear(tv); - tv->curr_tid = tid; tv->left_pos = pos; - tv->last_pos = tv->left_pos - 1; - tv->ccol = 0; - // print ref and consensus - if (tv->fai) { - char *str; - if (tv->ref) free(tv->ref); - assert(tv->curr_tid>=0); - - str = (char*)calloc(strlen(tv->header->target_name[tv->curr_tid]) + 30, 1); - assert(str!=NULL); - sprintf(str, "%s:%d-%d", tv->header->target_name[tv->curr_tid], tv->left_pos + 1, tv->left_pos + tv->mcol); - tv->ref = fai_fetch(tv->fai, str, &tv->l_ref); - free(str); - if ( !tv->ref ) - { - fprintf(stderr,"Could not read the reference sequence. Is it seekable (plain text or compressed + .gzi indexed with bgzip)?\n"); - exit(1); - } - } - // draw aln - bam_lplbuf_reset(tv->lplbuf); - hts_itr_t *iter = sam_itr_queryi(tv->idx, tv->curr_tid, tv->left_pos, tv->left_pos + tv->mcol); - bam1_t *b = bam_init1(); - while (sam_itr_next(tv->fp, iter, b) >= 0) tv_push_aln(b, tv); - bam_destroy1(b); - hts_itr_destroy(iter); - bam_lplbuf_push(0, tv->lplbuf); - - while (tv->ccol < tv->mcol) { - int pos = tv->last_pos + 1; - if (pos%10 == 0 && tv->mcol - tv->ccol >= 10) tv->my_mvprintw(tv,0, tv->ccol, "%-d", pos+1); - tv->my_mvaddch(tv,1, tv->ccol++, (tv->ref && pos < tv->l_ref)? tv->ref[pos - tv->left_pos] : 'N'); - ++tv->last_pos; - } - return 0; -} - - - - -static void error(const char *format, ...) -{ - if ( !format ) - { - fprintf(stderr, -"Usage: samtools tview [options] [ref.fasta]\n" -"Options:\n" -" -d display output as (H)tml or (C)urses or (T)ext \n" -" -p chr:pos go directly to this position\n" -" -s STR display only reads from this sample or group\n"); - sam_global_opt_help(stderr, "-.--."); - } - else - { - va_list ap; - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); - } - exit(-1); -} - -enum dipsay_mode {display_ncurses,display_html,display_text}; -extern tview_t* curses_tv_init(const char *fn, const char *fn_fa, - const char *samples, const htsFormat *fmt); -extern tview_t* html_tv_init(const char *fn, const char *fn_fa, - const char *samples, const htsFormat *fmt); -extern tview_t* text_tv_init(const char *fn, const char *fn_fa, - const char *samples, const htsFormat *fmt); - -int bam_tview_main(int argc, char *argv[]) -{ - int view_mode=display_ncurses; - tview_t* tv=NULL; - char *samples=NULL, *position=NULL, *ref; - int c; - - sam_global_args ga = SAM_GLOBAL_ARGS_INIT; - static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0), - { NULL, 0, NULL, 0 } - }; - - while ((c = getopt_long(argc, argv, "s:p:d:", lopts, NULL)) >= 0) { - switch (c) { - case 's': samples=optarg; break; - case 'p': position=optarg; break; - case 'd': - { - switch(optarg[0]) - { - case 'H': case 'h': view_mode=display_html;break; - case 'T': case 't': view_mode=display_text;break; - case 'C': case 'c': view_mode=display_ncurses;break; - default: view_mode=display_ncurses;break; - } - break; - } - default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; - /* else fall-through */ - case '?': error(NULL); - } - } - if (argc==optind) error(NULL); - - ref = (optind+1>=argc)? ga.reference : argv[optind+1]; - - switch(view_mode) - { - case display_ncurses: - tv = curses_tv_init(argv[optind], ref, samples, &ga.in); - break; - - case display_text: - tv = text_tv_init(argv[optind], ref, samples, &ga.in); - break; - - case display_html: - tv = html_tv_init(argv[optind], ref, samples, &ga.in); - break; - } - if (tv==NULL) - { - error("cannot create view"); - return EXIT_FAILURE; - } - - if ( position ) - { - int tid, beg, end; - char *name_lim = (char *) hts_parse_reg(position, &beg, &end); - if (name_lim) *name_lim = '\0'; - else beg = 0; // region parsing failed, but possibly a seq named "foo:a" - tid = bam_name2id(tv->header, position); - if (tid >= 0) { tv->curr_tid = tid; tv->left_pos = beg; } - } - else if ( tv->fai ) - { - // find the first sequence present in both BAM and the reference file - int i; - for (i=0; iheader->n_targets; i++) - { - if ( faidx_has_seq(tv->fai, tv->header->target_name[i]) ) break; - } - if ( i==tv->header->n_targets ) - { - fprintf(stderr,"None of the BAM sequence names present in the fasta file\n"); - exit(EXIT_FAILURE); - } - tv->curr_tid = i; - } - tv->my_drawaln(tv, tv->curr_tid, tv->left_pos); - tv->my_loop(tv); - tv->my_destroy(tv); - - return EXIT_SUCCESS; -} diff --git a/samtools/bam_tview.c.pysam.c b/samtools/bam_tview.c.pysam.c deleted file mode 100644 index a47bced14..000000000 --- a/samtools/bam_tview.c.pysam.c +++ /dev/null @@ -1,443 +0,0 @@ -#include "pysam.h" - -/* bam_tview.c -- tview subcommand. - - Copyright (C) 2008-2015 Genome Research Ltd. - Portions copyright (C) 2013 Pierre Lindenbaum, Institut du Thorax, INSERM U1087, Université de Nantes. - - Author: Heng Li - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notices and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. */ - -#include - -#include -#include -#include "bam_tview.h" -#include -#include -#include -#include "sam_opts.h" - -khash_t(kh_rg)* get_rg_sample(const char* header, const char* sample) -{ - khash_t(kh_rg)* rg_hash = kh_init(kh_rg); - // given sample id return all the RD ID's - const char rg_regex[] = "^@RG.*\tID:([!-)+-<>-~][ !-~]*)(\t.*$|$)"; - - regex_t rg_id; - regmatch_t* matches = (regmatch_t*)calloc(2, sizeof(regmatch_t)); - if (matches == NULL) { perror("out of memory"); exit(-1); } - regcomp(&rg_id, rg_regex, REG_EXTENDED|REG_NEWLINE); - char* text = strdup(header); - char* end = text + strlen(header); - char* tofree = text; - while (end > text && regexec(&rg_id, text, 2, matches, 0) == 0) { // foreach rg id in header - int ret; - text[matches[1].rm_eo] = '\0'; - kh_put(kh_rg, rg_hash, strdup(text+matches[1].rm_so), &ret); // Add the RG to the list - text += matches[0].rm_eo + 1; // Move search pointer forward - } - free(tofree); - return rg_hash; -} - -int base_tv_init(tview_t* tv, const char *fn, const char *fn_fa, - const char *samples, const htsFormat *fmt) -{ - assert(tv!=NULL); - assert(fn!=NULL); - tv->mrow = 24; tv->mcol = 80; - tv->color_for = TV_COLOR_MAPQ; - tv->is_dot = 1; - - tv->fp = sam_open_format(fn, "r", fmt); - if(tv->fp == NULL) - { - fprintf(pysam_stderr,"sam_open %s. %s\n", fn,fn_fa); - exit(EXIT_FAILURE); - } - // TODO bgzf_set_cache_size(tv->fp->fp.bgzf, 8 * 1024 *1024); - assert(tv->fp); - - tv->header = sam_hdr_read(tv->fp); - if(tv->header == NULL) - { - fprintf(pysam_stderr,"Cannot read '%s'.\n", fn); - exit(EXIT_FAILURE); - } - tv->idx = sam_index_load(tv->fp, fn); - if (tv->idx == NULL) - { - fprintf(pysam_stderr,"Cannot read index for '%s'.\n", fn); - exit(EXIT_FAILURE); - } - tv->lplbuf = bam_lplbuf_init(tv_pl_func, tv); - if (fn_fa) tv->fai = fai_load(fn_fa); - tv->bca = bcf_call_init(0.83, 13); - tv->ins = 1; - - // If the user has asked for specific samples find out create a list of readgroups make up these samples - if ( samples ) - { - tv->rg_hash = get_rg_sample(tv->header->text, samples); // Init the list of rg's - } - - return 0; -} - - -void base_tv_destroy(tview_t* tv) -{ - bam_lplbuf_destroy(tv->lplbuf); - bcf_call_destroy(tv->bca); - hts_idx_destroy(tv->idx); - if (tv->fai) fai_destroy(tv->fai); - free(tv->ref); - bam_hdr_destroy(tv->header); - sam_close(tv->fp); -} - - -int tv_pl_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl, void *data) -{ - tview_t *tv = (tview_t*)data; - int i, j, c, rb, attr, max_ins = 0; - uint32_t call = 0; - if (pos < tv->left_pos || tv->ccol > tv->mcol) return 0; // out of screen - // print reference - rb = (tv->ref && pos - tv->left_pos < tv->l_ref)? tv->ref[pos - tv->left_pos] : 'N'; - for (i = tv->last_pos + 1; i < pos; ++i) { - if (i%10 == 0 && tv->mcol - tv->ccol >= 10) tv->my_mvprintw(tv,0, tv->ccol, "%-d", i+1); - c = tv->ref? tv->ref[i - tv->left_pos] : 'N'; - tv->my_mvaddch(tv,1, tv->ccol++, c); - } - if (pos%10 == 0 && tv->mcol - tv->ccol >= 10) tv->my_mvprintw(tv,0, tv->ccol, "%-d", pos+1); - { // call consensus - bcf_callret1_t bcr; - memset(&bcr, 0, sizeof bcr); - int qsum[4], a1, a2, tmp; - double p[3], prior = 30; - bcf_call_glfgen(n, pl, seq_nt16_table[rb], tv->bca, &bcr); - for (i = 0; i < 4; ++i) qsum[i] = ((int)bcr.qsum[i])<<2 | i; - for (i = 1; i < 4; ++i) // insertion sort - for (j = i; j > 0 && qsum[j] > qsum[j-1]; --j) - tmp = qsum[j], qsum[j] = qsum[j-1], qsum[j-1] = tmp; - a1 = qsum[0]&3; a2 = qsum[1]&3; - p[0] = bcr.p[a1*5+a1]; p[1] = bcr.p[a1*5+a2] + prior; p[2] = bcr.p[a2*5+a2]; - if ("ACGT"[a1] != toupper(rb)) p[0] += prior + 3; - if ("ACGT"[a2] != toupper(rb)) p[2] += prior + 3; - if (p[0] < p[1] && p[0] < p[2]) call = (1<my_underline(tv); - c = ",ACMGRSVTWYHKDBN"[call>>16&0xf]; - i = (call&0xffff)/10+1; - if (i > 4) i = 4; - attr |= tv->my_colorpair(tv,i); - if (c == toupper(rb)) c = '.'; - tv->my_attron(tv,attr); - tv->my_mvaddch(tv,2, tv->ccol, c); - tv->my_attroff(tv,attr); - if(tv->ins) { - // calculate maximum insert - for (i = 0; i < n; ++i) { - const bam_pileup1_t *p = pl + i; - if (p->indel > 0 && max_ins < p->indel) max_ins = p->indel; - } - } - // core loop - for (j = 0; j <= max_ins; ++j) { - for (i = 0; i < n; ++i) { - const bam_pileup1_t *p = pl + i; - int row = TV_MIN_ALNROW + p->level - tv->row_shift; - if (j == 0) { - if (!p->is_del) { - if (tv->base_for == TV_BASE_COLOR_SPACE && - (c = bam_aux_getCSi(p->b, p->qpos))) { - // assume that if we found one color, we will be able to get the color error - if (tv->is_dot && '-' == bam_aux_getCEi(p->b, p->qpos)) c = bam_is_rev(p->b)? ',' : '.'; - } else { - if (tv->show_name) { - char *name = bam_get_qname(p->b); - c = (p->qpos + 1 >= p->b->core.l_qname)? ' ' : name[p->qpos]; - } else { - c = seq_nt16_str[bam_seqi(bam_get_seq(p->b), p->qpos)]; - if (tv->is_dot && toupper(c) == toupper(rb)) c = bam_is_rev(p->b)? ',' : '.'; - } - } - } else c = p->is_refskip? (bam_is_rev(p->b)? '<' : '>') : '*'; - } else { // padding - if (j > p->indel) c = '*'; - else { // insertion - if (tv->base_for == TV_BASE_NUCL) { - if (tv->show_name) { - char *name = bam_get_qname(p->b); - c = (p->qpos + j + 1 >= p->b->core.l_qname)? ' ' : name[p->qpos + j]; - } else { - c = seq_nt16_str[bam_seqi(bam_get_seq(p->b), p->qpos + j)]; - if (j == 0 && tv->is_dot && toupper(c) == toupper(rb)) c = bam_is_rev(p->b)? ',' : '.'; - } - } else { - c = bam_aux_getCSi(p->b, p->qpos + j); - if (tv->is_dot && '-' == bam_aux_getCEi(p->b, p->qpos + j)) c = bam_is_rev(p->b)? ',' : '.'; - } - } - } - if (row > TV_MIN_ALNROW && row < tv->mrow) { - int x; - attr = 0; - if (((p->b->core.flag&BAM_FPAIRED) && !(p->b->core.flag&BAM_FPROPER_PAIR)) - || (p->b->core.flag & BAM_FSECONDARY)) attr |= tv->my_underline(tv); - if (tv->color_for == TV_COLOR_BASEQ) { - x = bam_get_qual(p->b)[p->qpos]/10 + 1; - if (x > 4) x = 4; - attr |= tv->my_colorpair(tv,x); - } else if (tv->color_for == TV_COLOR_MAPQ) { - x = p->b->core.qual/10 + 1; - if (x > 4) x = 4; - attr |= tv->my_colorpair(tv,x); - } else if (tv->color_for == TV_COLOR_NUCL) { - x = seq_nt16_int[bam_seqi(bam_get_seq(p->b), p->qpos)] + 5; - attr |= tv->my_colorpair(tv,x); - } else if(tv->color_for == TV_COLOR_COL) { - x = 0; - switch(bam_aux_getCSi(p->b, p->qpos)) { - case '0': x = 0; break; - case '1': x = 1; break; - case '2': x = 2; break; - case '3': x = 3; break; - case '4': x = 4; break; - default: x = seq_nt16_int[bam_seqi(bam_get_seq(p->b), p->qpos)]; break; - } - x+=5; - attr |= tv->my_colorpair(tv,x); - } else if(tv->color_for == TV_COLOR_COLQ) { - x = bam_aux_getCQi(p->b, p->qpos); - if(0 == x) x = bam_get_qual(p->b)[p->qpos]; - x = x/10 + 1; - if (x > 4) x = 4; - attr |= tv->my_colorpair(tv,x); - } - tv->my_attron(tv,attr); - tv->my_mvaddch(tv,row, tv->ccol, bam_is_rev(p->b)? tolower(c) : toupper(c)); - tv->my_attroff(tv,attr); - } - } - c = j? '*' : rb; - if (c == '*') { - attr = tv->my_colorpair(tv,8); - tv->my_attron(tv,attr); - tv->my_mvaddch(tv,1, tv->ccol++, c); - tv->my_attroff(tv,attr); - } else tv->my_mvaddch(tv,1, tv->ccol++, c); - } - tv->last_pos = pos; - return 0; -} - - - - -static int tv_push_aln(const bam1_t *b, tview_t *tv) -{ - /* If we are restricted to specific readgroups check RG is in the list */ - if ( tv->rg_hash ) - { - const uint8_t *rg = bam_aux_get(b, "RG"); - if ( !rg ) return 0; // If we don't have an RG tag exclude read - khiter_t k = kh_get(kh_rg, tv->rg_hash, (const char*)(rg + 1)); - if ( k == kh_end(tv->rg_hash) ) return 0; // if RG tag is not in list of allowed tags exclude read - } - if (tv->no_skip) { - uint32_t *cigar = bam_get_cigar(b); // this is cheating... - int i; - for (i = 0; i core.n_cigar; ++i) { - if ((cigar[i]&0xf) == BAM_CREF_SKIP) - cigar[i] = cigar[i]>>4<<4 | BAM_CDEL; - } - } - bam_lplbuf_push(b, tv->lplbuf); - return 0; -} - -int base_draw_aln(tview_t *tv, int tid, int pos) -{ - assert(tv!=NULL); - // reset - tv->my_clear(tv); - tv->curr_tid = tid; tv->left_pos = pos; - tv->last_pos = tv->left_pos - 1; - tv->ccol = 0; - // print ref and consensus - if (tv->fai) { - char *str; - if (tv->ref) free(tv->ref); - assert(tv->curr_tid>=0); - - str = (char*)calloc(strlen(tv->header->target_name[tv->curr_tid]) + 30, 1); - assert(str!=NULL); - sprintf(str, "%s:%d-%d", tv->header->target_name[tv->curr_tid], tv->left_pos + 1, tv->left_pos + tv->mcol); - tv->ref = fai_fetch(tv->fai, str, &tv->l_ref); - free(str); - if ( !tv->ref ) - { - fprintf(pysam_stderr,"Could not read the reference sequence. Is it seekable (plain text or compressed + .gzi indexed with bgzip)?\n"); - exit(1); - } - } - // draw aln - bam_lplbuf_reset(tv->lplbuf); - hts_itr_t *iter = sam_itr_queryi(tv->idx, tv->curr_tid, tv->left_pos, tv->left_pos + tv->mcol); - bam1_t *b = bam_init1(); - while (sam_itr_next(tv->fp, iter, b) >= 0) tv_push_aln(b, tv); - bam_destroy1(b); - hts_itr_destroy(iter); - bam_lplbuf_push(0, tv->lplbuf); - - while (tv->ccol < tv->mcol) { - int pos = tv->last_pos + 1; - if (pos%10 == 0 && tv->mcol - tv->ccol >= 10) tv->my_mvprintw(tv,0, tv->ccol, "%-d", pos+1); - tv->my_mvaddch(tv,1, tv->ccol++, (tv->ref && pos < tv->l_ref)? tv->ref[pos - tv->left_pos] : 'N'); - ++tv->last_pos; - } - return 0; -} - - - - -static void error(const char *format, ...) -{ - if ( !format ) - { - fprintf(pysam_stderr, -"Usage: samtools tview [options] [ref.fasta]\n" -"Options:\n" -" -d display output as (H)tml or (C)urses or (T)ext \n" -" -p chr:pos go directly to this position\n" -" -s STR display only reads from this sample or group\n"); - sam_global_opt_help(pysam_stderr, "-.--."); - } - else - { - va_list ap; - va_start(ap, format); - vfprintf(pysam_stderr, format, ap); - va_end(ap); - } - exit(-1); -} - -enum dipsay_mode {display_ncurses,display_html,display_text}; -extern tview_t* curses_tv_init(const char *fn, const char *fn_fa, - const char *samples, const htsFormat *fmt); -extern tview_t* html_tv_init(const char *fn, const char *fn_fa, - const char *samples, const htsFormat *fmt); -extern tview_t* text_tv_init(const char *fn, const char *fn_fa, - const char *samples, const htsFormat *fmt); - -int bam_tview_main(int argc, char *argv[]) -{ - int view_mode=display_ncurses; - tview_t* tv=NULL; - char *samples=NULL, *position=NULL, *ref; - int c; - - sam_global_args ga = SAM_GLOBAL_ARGS_INIT; - static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0), - { NULL, 0, NULL, 0 } - }; - - while ((c = getopt_long(argc, argv, "s:p:d:", lopts, NULL)) >= 0) { - switch (c) { - case 's': samples=optarg; break; - case 'p': position=optarg; break; - case 'd': - { - switch(optarg[0]) - { - case 'H': case 'h': view_mode=display_html;break; - case 'T': case 't': view_mode=display_text;break; - case 'C': case 'c': view_mode=display_ncurses;break; - default: view_mode=display_ncurses;break; - } - break; - } - default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; - /* else fall-through */ - case '?': error(NULL); - } - } - if (argc==optind) error(NULL); - - ref = (optind+1>=argc)? ga.reference : argv[optind+1]; - - switch(view_mode) - { - case display_ncurses: - tv = curses_tv_init(argv[optind], ref, samples, &ga.in); - break; - - case display_text: - tv = text_tv_init(argv[optind], ref, samples, &ga.in); - break; - - case display_html: - tv = html_tv_init(argv[optind], ref, samples, &ga.in); - break; - } - if (tv==NULL) - { - error("cannot create view"); - return EXIT_FAILURE; - } - - if ( position ) - { - int tid, beg, end; - char *name_lim = (char *) hts_parse_reg(position, &beg, &end); - if (name_lim) *name_lim = '\0'; - else beg = 0; // region parsing failed, but possibly a seq named "foo:a" - tid = bam_name2id(tv->header, position); - if (tid >= 0) { tv->curr_tid = tid; tv->left_pos = beg; } - } - else if ( tv->fai ) - { - // find the first sequence present in both BAM and the reference file - int i; - for (i=0; iheader->n_targets; i++) - { - if ( faidx_has_seq(tv->fai, tv->header->target_name[i]) ) break; - } - if ( i==tv->header->n_targets ) - { - fprintf(pysam_stderr,"None of the BAM sequence names present in the fasta file\n"); - exit(EXIT_FAILURE); - } - tv->curr_tid = i; - } - tv->my_drawaln(tv, tv->curr_tid, tv->left_pos); - tv->my_loop(tv); - tv->my_destroy(tv); - - return EXIT_SUCCESS; -} diff --git a/samtools/bam_tview.h b/samtools/bam_tview.h deleted file mode 100644 index e11e39d6d..000000000 --- a/samtools/bam_tview.h +++ /dev/null @@ -1,105 +0,0 @@ -/* bam_tview.h -- tview subcommand. - - Copyright (C) 2008, 2013 Genome Research Ltd. - Portions copyright (C) 2013 Pierre Lindenbaum, Institut du Thorax, INSERM U1087, Université de Nantes. - - Author: Heng Li - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notices and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. */ - -#ifndef BAM_TVIEW_H -#define BAM_TVIEW_H - -#include -#include -#include -#include -#include -#include -#include "bam2bcf.h" -#include -#include -#include -#include "bam_lpileup.h" - - -KHASH_MAP_INIT_STR(kh_rg, const char *) - -/* Holds state of Tview */ -typedef struct AbstractTview { - int mrow, mcol; - - hts_idx_t* idx; - bam_lplbuf_t* lplbuf; - bam_hdr_t* header; - samFile* fp; - int curr_tid, left_pos; - faidx_t* fai; - bcf_callaux_t* bca; - - int ccol, last_pos, row_shift, base_for, color_for, is_dot, l_ref, ins; - int no_skip, show_name, inverse; - char *ref; - /* maps @RG ID => SM (sample), in practice only used to determine whether a particular RG is in the list of allowed ones */ - khash_t(kh_rg) *rg_hash; - /* callbacks */ - void (*my_destroy)(struct AbstractTview* ); - void (*my_mvprintw)(struct AbstractTview* ,int,int,const char*,...); - void (*my_mvaddch)(struct AbstractTview*,int,int,int); - void (*my_attron)(struct AbstractTview*,int); - void (*my_attroff)(struct AbstractTview*,int); - void (*my_clear)(struct AbstractTview*); - int (*my_colorpair)(struct AbstractTview*,int); - int (*my_drawaln)(struct AbstractTview*,int,int); - int (*my_loop)(struct AbstractTview*); - int (*my_underline)(struct AbstractTview*); -} tview_t; - - -char bam_aux_getCEi(bam1_t *b, int i); -char bam_aux_getCSi(bam1_t *b, int i); -char bam_aux_getCQi(bam1_t *b, int i); - -#define TV_MIN_ALNROW 2 -#define TV_MAX_GOTO 40 -#define TV_LOW_MAPQ 10 - -#define TV_COLOR_MAPQ 0 -#define TV_COLOR_BASEQ 1 -#define TV_COLOR_NUCL 2 -#define TV_COLOR_COL 3 -#define TV_COLOR_COLQ 4 - -#define TV_BASE_NUCL 0 -#define TV_BASE_COLOR_SPACE 1 - -int tv_pl_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl, void *data); -int base_tv_init(tview_t*,const char *fn, const char *fn_fa, - const char *samples, const htsFormat *fmt); -void base_tv_destroy(tview_t*); -int base_draw_aln(tview_t *tv, int tid, int pos); - -typedef struct Tixel - { - int ch; - int attributes; - }tixel_t; - -#endif - diff --git a/samtools/bam_tview_curses.c b/samtools/bam_tview_curses.c deleted file mode 100644 index d7edfe859..000000000 --- a/samtools/bam_tview_curses.c +++ /dev/null @@ -1,352 +0,0 @@ -/* bam_tview_curses.c -- curses tview implementation. - - Copyright (C) 2008-2013 Genome Research Ltd. - Portions copyright (C) 2013 Pierre Lindenbaum, Institut du Thorax, INSERM U1087, Université de Nantes. - - Author: Heng Li - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notices and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. */ - -#include - -#include "bam_tview.h" - -#ifdef HAVE_CURSES - -#if defined HAVE_NCURSESW_CURSES_H -#include -#elif defined HAVE_NCURSESW_H -#include -#elif defined HAVE_NCURSES_CURSES_H -#include -#elif defined HAVE_NCURSES_H -#include -#elif defined HAVE_CURSES_H -#include -#endif - -typedef struct CursesTview { - tview_t view; - WINDOW *wgoto, *whelp; - } curses_tview_t; - -#define FROM_TV(ptr) ((curses_tview_t*)ptr) - -static void curses_destroy(tview_t* base) - { - curses_tview_t* tv=(curses_tview_t*)base; - - - delwin(tv->wgoto); delwin(tv->whelp); - endwin(); - - base_tv_destroy(base); - - free(tv); - } - -/* - void (*my_mvprintw)(struct AbstractTview* ,int,int,const char*,...); - void (*my_)(struct AbstractTview*,int,int,int); - void (*my_attron)(struct AbstractTview*,int); - void (*my_attroff)(struct AbstractTview*,int); - void (*my_clear)(struct AbstractTview*); - int (*my_colorpair)(struct AbstractTview*,int); -*/ - -static void curses_mvprintw(struct AbstractTview* tv,int y ,int x,const char* fmt,...) - { - unsigned int size=tv->mcol+2; - char* str=malloc(size); - if(str==0) exit(EXIT_FAILURE); - va_list argptr; - va_start(argptr, fmt); - vsnprintf(str,size, fmt, argptr); - va_end(argptr); - mvprintw(y,x,str); - free(str); - } - -static void curses_mvaddch(struct AbstractTview* tv,int y,int x,int ch) - { - mvaddch(y,x,ch); - } - -static void curses_attron(struct AbstractTview* tv,int flag) - { - attron(flag); - } -static void curses_attroff(struct AbstractTview* tv,int flag) - { - attroff(flag); - } -static void curses_clear(struct AbstractTview* tv) - { - clear(); - } - -static int curses_init_colors(int inverse) -{ - if (inverse) { - init_pair(1, COLOR_WHITE, COLOR_BLUE); - init_pair(2, COLOR_BLACK, COLOR_GREEN); - init_pair(3, COLOR_BLACK, COLOR_YELLOW); - init_pair(4, COLOR_BLACK, COLOR_WHITE); - init_pair(5, COLOR_BLACK, COLOR_GREEN); - init_pair(6, COLOR_BLACK, COLOR_CYAN); - init_pair(7, COLOR_WHITE, COLOR_MAGENTA); - init_pair(8, COLOR_WHITE, COLOR_RED); - init_pair(9, COLOR_WHITE, COLOR_BLUE); - } else { - init_pair(1, COLOR_BLUE, COLOR_BLACK); - init_pair(2, COLOR_GREEN, COLOR_BLACK); - init_pair(3, COLOR_YELLOW, COLOR_BLACK); - init_pair(4, COLOR_WHITE, COLOR_BLACK); - init_pair(5, COLOR_GREEN, COLOR_BLACK); - init_pair(6, COLOR_CYAN, COLOR_BLACK); - init_pair(7, COLOR_MAGENTA, COLOR_BLACK); - init_pair(8, COLOR_RED, COLOR_BLACK); - init_pair(9, COLOR_BLUE, COLOR_BLACK); - } - - return 0; -} - -static int curses_colorpair(struct AbstractTview* tv,int flag) - { - return COLOR_PAIR(flag); - } - -static int curses_drawaln(struct AbstractTview* tv, int tid, int pos) - { - return base_draw_aln(tv, tid, pos); - } - - - -static void tv_win_goto(curses_tview_t *tv, int *tid, int *pos) - { - char str[256], *p; - int i, l = 0; - tview_t *base=(tview_t*)tv; - wborder(tv->wgoto, '|', '|', '-', '-', '+', '+', '+', '+'); - mvwprintw(tv->wgoto, 1, 2, "Goto: "); - for (;;) { - int invalid = 0; - int c = wgetch(tv->wgoto); - wrefresh(tv->wgoto); - if (c == KEY_BACKSPACE || c == '\010' || c == '\177') { - if(l > 0) --l; - } else if (c == KEY_ENTER || c == '\012' || c == '\015') { - int _tid = -1, _beg, _end; - if (str[0] == '=') { - _beg = strtol(str+1, &p, 10) - 1; - if (_beg > 0) { - *pos = _beg; - return; - } - } else { - char *name_lim = (char *) hts_parse_reg(str, &_beg, &_end); - if (name_lim) { - char name_terminator = *name_lim; - *name_lim = '\0'; - _tid = bam_name2id(base->header, str); - *name_lim = name_terminator; - } - else { - // Unparsable region, but possibly a sequence named "foo:a" - _tid = bam_name2id(base->header, str); - _beg = 0; - } - - if (_tid >= 0) { - *tid = _tid; *pos = _beg; - return; - } - } - - // If we get here, the region string is invalid - invalid = 1; - } else if (isgraph(c)) { - if (l < TV_MAX_GOTO) str[l++] = c; - } else if (c == '\027') l = 0; - else if (c == '\033') return; - str[l] = '\0'; - for (i = 0; i < TV_MAX_GOTO; ++i) mvwaddch(tv->wgoto, 1, 8 + i, ' '); - if (invalid) mvwprintw(tv->wgoto, 1, TV_MAX_GOTO - 1, "[Invalid]"); - mvwprintw(tv->wgoto, 1, 8, "%s", str); - } -} - - - - -static void tv_win_help(curses_tview_t *tv) { - int r = 1; - tview_t* base=(tview_t*)base; - WINDOW *win = tv->whelp; - wborder(win, '|', '|', '-', '-', '+', '+', '+', '+'); - mvwprintw(win, r++, 2, " -=- Help -=- "); - r++; - mvwprintw(win, r++, 2, "? This window"); - mvwprintw(win, r++, 2, "Arrows Small scroll movement"); - mvwprintw(win, r++, 2, "h,j,k,l Small scroll movement"); - mvwprintw(win, r++, 2, "H,J,K,L Large scroll movement"); - mvwprintw(win, r++, 2, "ctrl-H Scroll 1k left"); - mvwprintw(win, r++, 2, "ctrl-L Scroll 1k right"); - mvwprintw(win, r++, 2, "space Scroll one screen"); - mvwprintw(win, r++, 2, "backspace Scroll back one screen"); - mvwprintw(win, r++, 2, "g Go to specific location"); - mvwprintw(win, r++, 2, "m Color for mapping qual"); - mvwprintw(win, r++, 2, "n Color for nucleotide"); - mvwprintw(win, r++, 2, "b Color for base quality"); - mvwprintw(win, r++, 2, "c Color for cs color"); - mvwprintw(win, r++, 2, "z Color for cs qual"); - mvwprintw(win, r++, 2, ". Toggle on/off dot view"); - mvwprintw(win, r++, 2, "s Toggle on/off ref skip"); - mvwprintw(win, r++, 2, "r Toggle on/off rd name"); - mvwprintw(win, r++, 2, "N Turn on nt view"); - mvwprintw(win, r++, 2, "C Turn on cs view"); - mvwprintw(win, r++, 2, "i Toggle on/off ins"); - mvwprintw(win, r++, 2, "v Inverse video"); - mvwprintw(win, r++, 2, "q Exit"); - r++; - mvwprintw(win, r++, 2, "Underline: Secondary or orphan"); - mvwprintw(win, r++, 2, "Blue: 0-9 Green: 10-19"); - mvwprintw(win, r++, 2, "Yellow: 20-29 White: >=30"); - wrefresh(win); - wgetch(win); -} - -static int curses_underline(tview_t* tv) - { - return A_UNDERLINE; - } - -static int curses_loop(tview_t* tv) - { - int tid, pos; - curses_tview_t *CTV=(curses_tview_t *)tv; - tid = tv->curr_tid; pos = tv->left_pos; - while (1) { - int c = getch(); - switch (c) { - case '?': tv_win_help(CTV); break; - case '\033': - case 'q': goto end_loop; - case '/': - case 'g': tv_win_goto(CTV, &tid, &pos); break; - case 'm': tv->color_for = TV_COLOR_MAPQ; break; - case 'b': tv->color_for = TV_COLOR_BASEQ; break; - case 'n': tv->color_for = TV_COLOR_NUCL; break; - case 'c': tv->color_for = TV_COLOR_COL; break; - case 'z': tv->color_for = TV_COLOR_COLQ; break; - case 'v': curses_init_colors(tv->inverse = !tv->inverse); break; - case 's': tv->no_skip = !tv->no_skip; break; - case 'r': tv->show_name = !tv->show_name; break; - case KEY_LEFT: - case 'h': --pos; break; - case KEY_RIGHT: - case 'l': ++pos; break; - case KEY_SLEFT: - case 'H': pos -= 20; break; - case KEY_SRIGHT: - case 'L': pos += 20; break; - case '.': tv->is_dot = !tv->is_dot; break; - case 'N': tv->base_for = TV_BASE_NUCL; break; - case 'C': tv->base_for = TV_BASE_COLOR_SPACE; break; - case 'i': tv->ins = !tv->ins; break; - case '\010': pos -= 1000; break; - case '\014': pos += 1000; break; - case ' ': pos += tv->mcol; break; - case KEY_UP: - case 'j': --tv->row_shift; break; - case KEY_DOWN: - case 'k': ++tv->row_shift; break; - case KEY_BACKSPACE: - case '\177': pos -= tv->mcol; break; - case KEY_RESIZE: getmaxyx(stdscr, tv->mrow, tv->mcol); break; - default: continue; - } - if (pos < 0) pos = 0; - if (tv->row_shift < 0) tv->row_shift = 0; - tv->my_drawaln(tv, tid, pos); - } -end_loop: - return 0; -} - - - - -tview_t* curses_tv_init(const char *fn, const char *fn_fa, const char *samples, - const htsFormat *fmt) - { - curses_tview_t *tv = (curses_tview_t*)calloc(1, sizeof(curses_tview_t)); - tview_t* base=(tview_t*)tv; - if(tv==0) - { - fprintf(stderr,"Calloc failed\n"); - return 0; - } - - base_tv_init(base,fn,fn_fa,samples,fmt); - /* initialize callbacks */ -#define SET_CALLBACK(fun) base->my_##fun=curses_##fun; - SET_CALLBACK(destroy); - SET_CALLBACK(mvprintw); - SET_CALLBACK(mvaddch); - SET_CALLBACK(attron); - SET_CALLBACK(attroff); - SET_CALLBACK(clear); - SET_CALLBACK(colorpair); - SET_CALLBACK(drawaln); - SET_CALLBACK(loop); - SET_CALLBACK(underline); -#undef SET_CALLBACK - - initscr(); - keypad(stdscr, TRUE); - clear(); - noecho(); - cbreak(); - - getmaxyx(stdscr, base->mrow, base->mcol); - tv->wgoto = newwin(3, TV_MAX_GOTO + 10, 10, 5); - tv->whelp = newwin(30, 40, 5, 5); - - start_color(); - curses_init_colors(0); - return base; - } - -#else // !HAVE_CURSES - -#warning "No curses library is available; tview with curses is disabled." - -extern tview_t* text_tv_init(const char *fn, const char *fn_fa, const char *samples, - const htsFormat *fmt); - -tview_t* curses_tv_init(const char *fn, const char *fn_fa, const char *samples, - const htsFormat *fmt) - { - return text_tv_init(fn,fn_fa,samples,fmt); - } - -#endif diff --git a/samtools/bam_tview_curses.c.pysam.c b/samtools/bam_tview_curses.c.pysam.c deleted file mode 100644 index 90a83353d..000000000 --- a/samtools/bam_tview_curses.c.pysam.c +++ /dev/null @@ -1,354 +0,0 @@ -#include "pysam.h" - -/* bam_tview_curses.c -- curses tview implementation. - - Copyright (C) 2008-2013 Genome Research Ltd. - Portions copyright (C) 2013 Pierre Lindenbaum, Institut du Thorax, INSERM U1087, Université de Nantes. - - Author: Heng Li - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notices and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. */ - -#include - -#include "bam_tview.h" - -#ifdef HAVE_CURSES - -#if defined HAVE_NCURSESW_CURSES_H -#include -#elif defined HAVE_NCURSESW_H -#include -#elif defined HAVE_NCURSES_CURSES_H -#include -#elif defined HAVE_NCURSES_H -#include -#elif defined HAVE_CURSES_H -#include -#endif - -typedef struct CursesTview { - tview_t view; - WINDOW *wgoto, *whelp; - } curses_tview_t; - -#define FROM_TV(ptr) ((curses_tview_t*)ptr) - -static void curses_destroy(tview_t* base) - { - curses_tview_t* tv=(curses_tview_t*)base; - - - delwin(tv->wgoto); delwin(tv->whelp); - endwin(); - - base_tv_destroy(base); - - free(tv); - } - -/* - void (*my_mvprintw)(struct AbstractTview* ,int,int,const char*,...); - void (*my_)(struct AbstractTview*,int,int,int); - void (*my_attron)(struct AbstractTview*,int); - void (*my_attroff)(struct AbstractTview*,int); - void (*my_clear)(struct AbstractTview*); - int (*my_colorpair)(struct AbstractTview*,int); -*/ - -static void curses_mvprintw(struct AbstractTview* tv,int y ,int x,const char* fmt,...) - { - unsigned int size=tv->mcol+2; - char* str=malloc(size); - if(str==0) exit(EXIT_FAILURE); - va_list argptr; - va_start(argptr, fmt); - vsnprintf(str,size, fmt, argptr); - va_end(argptr); - mvprintw(y,x,str); - free(str); - } - -static void curses_mvaddch(struct AbstractTview* tv,int y,int x,int ch) - { - mvaddch(y,x,ch); - } - -static void curses_attron(struct AbstractTview* tv,int flag) - { - attron(flag); - } -static void curses_attroff(struct AbstractTview* tv,int flag) - { - attroff(flag); - } -static void curses_clear(struct AbstractTview* tv) - { - clear(); - } - -static int curses_init_colors(int inverse) -{ - if (inverse) { - init_pair(1, COLOR_WHITE, COLOR_BLUE); - init_pair(2, COLOR_BLACK, COLOR_GREEN); - init_pair(3, COLOR_BLACK, COLOR_YELLOW); - init_pair(4, COLOR_BLACK, COLOR_WHITE); - init_pair(5, COLOR_BLACK, COLOR_GREEN); - init_pair(6, COLOR_BLACK, COLOR_CYAN); - init_pair(7, COLOR_WHITE, COLOR_MAGENTA); - init_pair(8, COLOR_WHITE, COLOR_RED); - init_pair(9, COLOR_WHITE, COLOR_BLUE); - } else { - init_pair(1, COLOR_BLUE, COLOR_BLACK); - init_pair(2, COLOR_GREEN, COLOR_BLACK); - init_pair(3, COLOR_YELLOW, COLOR_BLACK); - init_pair(4, COLOR_WHITE, COLOR_BLACK); - init_pair(5, COLOR_GREEN, COLOR_BLACK); - init_pair(6, COLOR_CYAN, COLOR_BLACK); - init_pair(7, COLOR_MAGENTA, COLOR_BLACK); - init_pair(8, COLOR_RED, COLOR_BLACK); - init_pair(9, COLOR_BLUE, COLOR_BLACK); - } - - return 0; -} - -static int curses_colorpair(struct AbstractTview* tv,int flag) - { - return COLOR_PAIR(flag); - } - -static int curses_drawaln(struct AbstractTview* tv, int tid, int pos) - { - return base_draw_aln(tv, tid, pos); - } - - - -static void tv_win_goto(curses_tview_t *tv, int *tid, int *pos) - { - char str[256], *p; - int i, l = 0; - tview_t *base=(tview_t*)tv; - wborder(tv->wgoto, '|', '|', '-', '-', '+', '+', '+', '+'); - mvwprintw(tv->wgoto, 1, 2, "Goto: "); - for (;;) { - int invalid = 0; - int c = wgetch(tv->wgoto); - wrefresh(tv->wgoto); - if (c == KEY_BACKSPACE || c == '\010' || c == '\177') { - if(l > 0) --l; - } else if (c == KEY_ENTER || c == '\012' || c == '\015') { - int _tid = -1, _beg, _end; - if (str[0] == '=') { - _beg = strtol(str+1, &p, 10) - 1; - if (_beg > 0) { - *pos = _beg; - return; - } - } else { - char *name_lim = (char *) hts_parse_reg(str, &_beg, &_end); - if (name_lim) { - char name_terminator = *name_lim; - *name_lim = '\0'; - _tid = bam_name2id(base->header, str); - *name_lim = name_terminator; - } - else { - // Unparsable region, but possibly a sequence named "foo:a" - _tid = bam_name2id(base->header, str); - _beg = 0; - } - - if (_tid >= 0) { - *tid = _tid; *pos = _beg; - return; - } - } - - // If we get here, the region string is invalid - invalid = 1; - } else if (isgraph(c)) { - if (l < TV_MAX_GOTO) str[l++] = c; - } else if (c == '\027') l = 0; - else if (c == '\033') return; - str[l] = '\0'; - for (i = 0; i < TV_MAX_GOTO; ++i) mvwaddch(tv->wgoto, 1, 8 + i, ' '); - if (invalid) mvwprintw(tv->wgoto, 1, TV_MAX_GOTO - 1, "[Invalid]"); - mvwprintw(tv->wgoto, 1, 8, "%s", str); - } -} - - - - -static void tv_win_help(curses_tview_t *tv) { - int r = 1; - tview_t* base=(tview_t*)base; - WINDOW *win = tv->whelp; - wborder(win, '|', '|', '-', '-', '+', '+', '+', '+'); - mvwprintw(win, r++, 2, " -=- Help -=- "); - r++; - mvwprintw(win, r++, 2, "? This window"); - mvwprintw(win, r++, 2, "Arrows Small scroll movement"); - mvwprintw(win, r++, 2, "h,j,k,l Small scroll movement"); - mvwprintw(win, r++, 2, "H,J,K,L Large scroll movement"); - mvwprintw(win, r++, 2, "ctrl-H Scroll 1k left"); - mvwprintw(win, r++, 2, "ctrl-L Scroll 1k right"); - mvwprintw(win, r++, 2, "space Scroll one screen"); - mvwprintw(win, r++, 2, "backspace Scroll back one screen"); - mvwprintw(win, r++, 2, "g Go to specific location"); - mvwprintw(win, r++, 2, "m Color for mapping qual"); - mvwprintw(win, r++, 2, "n Color for nucleotide"); - mvwprintw(win, r++, 2, "b Color for base quality"); - mvwprintw(win, r++, 2, "c Color for cs color"); - mvwprintw(win, r++, 2, "z Color for cs qual"); - mvwprintw(win, r++, 2, ". Toggle on/off dot view"); - mvwprintw(win, r++, 2, "s Toggle on/off ref skip"); - mvwprintw(win, r++, 2, "r Toggle on/off rd name"); - mvwprintw(win, r++, 2, "N Turn on nt view"); - mvwprintw(win, r++, 2, "C Turn on cs view"); - mvwprintw(win, r++, 2, "i Toggle on/off ins"); - mvwprintw(win, r++, 2, "v Inverse video"); - mvwprintw(win, r++, 2, "q Exit"); - r++; - mvwprintw(win, r++, 2, "Underline: Secondary or orphan"); - mvwprintw(win, r++, 2, "Blue: 0-9 Green: 10-19"); - mvwprintw(win, r++, 2, "Yellow: 20-29 White: >=30"); - wrefresh(win); - wgetch(win); -} - -static int curses_underline(tview_t* tv) - { - return A_UNDERLINE; - } - -static int curses_loop(tview_t* tv) - { - int tid, pos; - curses_tview_t *CTV=(curses_tview_t *)tv; - tid = tv->curr_tid; pos = tv->left_pos; - while (1) { - int c = getch(); - switch (c) { - case '?': tv_win_help(CTV); break; - case '\033': - case 'q': goto end_loop; - case '/': - case 'g': tv_win_goto(CTV, &tid, &pos); break; - case 'm': tv->color_for = TV_COLOR_MAPQ; break; - case 'b': tv->color_for = TV_COLOR_BASEQ; break; - case 'n': tv->color_for = TV_COLOR_NUCL; break; - case 'c': tv->color_for = TV_COLOR_COL; break; - case 'z': tv->color_for = TV_COLOR_COLQ; break; - case 'v': curses_init_colors(tv->inverse = !tv->inverse); break; - case 's': tv->no_skip = !tv->no_skip; break; - case 'r': tv->show_name = !tv->show_name; break; - case KEY_LEFT: - case 'h': --pos; break; - case KEY_RIGHT: - case 'l': ++pos; break; - case KEY_SLEFT: - case 'H': pos -= 20; break; - case KEY_SRIGHT: - case 'L': pos += 20; break; - case '.': tv->is_dot = !tv->is_dot; break; - case 'N': tv->base_for = TV_BASE_NUCL; break; - case 'C': tv->base_for = TV_BASE_COLOR_SPACE; break; - case 'i': tv->ins = !tv->ins; break; - case '\010': pos -= 1000; break; - case '\014': pos += 1000; break; - case ' ': pos += tv->mcol; break; - case KEY_UP: - case 'j': --tv->row_shift; break; - case KEY_DOWN: - case 'k': ++tv->row_shift; break; - case KEY_BACKSPACE: - case '\177': pos -= tv->mcol; break; - case KEY_RESIZE: getmaxyx(stdscr, tv->mrow, tv->mcol); break; - default: continue; - } - if (pos < 0) pos = 0; - if (tv->row_shift < 0) tv->row_shift = 0; - tv->my_drawaln(tv, tid, pos); - } -end_loop: - return 0; -} - - - - -tview_t* curses_tv_init(const char *fn, const char *fn_fa, const char *samples, - const htsFormat *fmt) - { - curses_tview_t *tv = (curses_tview_t*)calloc(1, sizeof(curses_tview_t)); - tview_t* base=(tview_t*)tv; - if(tv==0) - { - fprintf(pysam_stderr,"Calloc failed\n"); - return 0; - } - - base_tv_init(base,fn,fn_fa,samples,fmt); - /* initialize callbacks */ -#define SET_CALLBACK(fun) base->my_##fun=curses_##fun; - SET_CALLBACK(destroy); - SET_CALLBACK(mvprintw); - SET_CALLBACK(mvaddch); - SET_CALLBACK(attron); - SET_CALLBACK(attroff); - SET_CALLBACK(clear); - SET_CALLBACK(colorpair); - SET_CALLBACK(drawaln); - SET_CALLBACK(loop); - SET_CALLBACK(underline); -#undef SET_CALLBACK - - initscr(); - keypad(stdscr, TRUE); - clear(); - noecho(); - cbreak(); - - getmaxyx(stdscr, base->mrow, base->mcol); - tv->wgoto = newwin(3, TV_MAX_GOTO + 10, 10, 5); - tv->whelp = newwin(30, 40, 5, 5); - - start_color(); - curses_init_colors(0); - return base; - } - -#else // !HAVE_CURSES - -#warning "No curses library is available; tview with curses is disabled." - -extern tview_t* text_tv_init(const char *fn, const char *fn_fa, const char *samples, - const htsFormat *fmt); - -tview_t* curses_tv_init(const char *fn, const char *fn_fa, const char *samples, - const htsFormat *fmt) - { - return text_tv_init(fn,fn_fa,samples,fmt); - } - -#endif diff --git a/samtools/bam_tview_html.c b/samtools/bam_tview_html.c deleted file mode 100644 index e3aecda30..000000000 --- a/samtools/bam_tview_html.c +++ /dev/null @@ -1,377 +0,0 @@ -/* bam_tview_html.c -- HTML tview output. - - Copyright (C) 2013 Pierre Lindenbaum, Institut du Thorax, INSERM U1087, Université de Nantes. - - Author: Pierre Lindenbaum - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. */ - -#include - -#include -#include "bam_tview.h" - -#define UNDERLINE_FLAG 10 - -typedef struct HtmlTview { - tview_t view; - int row_count; - tixel_t** screen; - FILE* out; - int attributes;/* color... */ - } html_tview_t; - -#define FROM_TV(ptr) ((html_tview_t*)ptr) - -static void html_destroy(tview_t* base) - { - int i; - html_tview_t* tv=(html_tview_t*)base; - if(tv->screen!=NULL) - { - for(i=0;i< tv->row_count;++i) free(tv->screen[i]); - free(tv->screen); - } - base_tv_destroy(base); - free(tv); - } - -/* - void (*my_mvprintw)(struct AbstractTview* ,int,int,const char*,...); - void (*my_)(struct AbstractTview*,int,int,int); - void (*my_attron)(struct AbstractTview*,int); - void (*my_attroff)(struct AbstractTview*,int); - void (*my_clear)(struct AbstractTview*); - int (*my_colorpair)(struct AbstractTview*,int); -*/ - -static void html_mvprintw(struct AbstractTview* tv,int y ,int x,const char* fmt,...) - { - int i,nchars=0; - unsigned int size=tv->mcol+2; - char* str=malloc(size); - if(str==0) exit(EXIT_FAILURE); - va_list argptr; - va_start(argptr, fmt); - nchars=vsnprintf(str,size, fmt, argptr); - va_end(argptr); - - for(i=0;i< nchars;++i) - { - tv->my_mvaddch(tv,y,x+i,str[i]); - } - free(str); - } - -static void html_mvaddch(struct AbstractTview* tv,int y,int x,int ch) - { - tixel_t* row=NULL; - html_tview_t* ptr=FROM_TV(tv); - if( x >= tv->mcol ) return; //out of screen - while(ptr->row_count<=y) - { - int x; - row=(tixel_t*)calloc(tv->mcol,sizeof(tixel_t)); - if(row==0) exit(EXIT_FAILURE); - for(x=0;xmcol;++x) {row[x].ch=' ';row[x].attributes=0;} - ptr->screen=(tixel_t**)realloc(ptr->screen,sizeof(tixel_t*)*(ptr->row_count+1)); - ptr->screen[ptr->row_count++]=row; - } - row=ptr->screen[y]; - row[x].ch=ch; - row[x].attributes=ptr->attributes; - } - -static void html_attron(struct AbstractTview* tv,int flag) - { - html_tview_t* ptr=FROM_TV(tv); - ptr->attributes |= flag; - - - } - -static void html_attroff(struct AbstractTview* tv,int flag) - { - html_tview_t* ptr=FROM_TV(tv); - ptr->attributes &= ~(flag); - } - -static void html_clear(struct AbstractTview* tv) - { - html_tview_t* ptr=FROM_TV(tv); - if(ptr->screen!=NULL) - { - int i; - for(i=0;i< ptr->row_count;++i) free(ptr->screen[i]); - free(ptr->screen); - ptr->screen=NULL; - } - ptr->row_count=0; - ptr->attributes=0; - } - -static int html_colorpair(struct AbstractTview* tv,int flag) - { - return (1 << (flag)); - } - -static int html_drawaln(struct AbstractTview* tv, int tid, int pos) - { - int y,x; - html_tview_t* ptr=FROM_TV(tv); - html_clear(tv); - base_draw_aln(tv, tid, pos); - fputs("",ptr->out); - fprintf(ptr->out,"%s:%d", - tv->header->target_name[tid], - pos+1 - ); - //style - - fputs("",ptr->out); - - fputs("",ptr->out); - - fprintf(ptr->out,"
%s:%d
", - tv->header->target_name[tid], - pos+1 - ); - - fputs("
",ptr->out);
-    for(y=0;y< ptr->row_count;++y)
-        {
-
-        for(x=0;x< tv->mcol;++x)
-            {
-
-
-        if(x== 0 || ptr->screen[y][x].attributes != ptr->screen[y][x-1].attributes)
-                {
-                int css=0;
-            fprintf(ptr->out,"1) fprintf(stderr,"css=%d pow2=%d vs %d\n",css,(1 << (css)),ptr->screen[y][x].attributes);
-                    if(( (ptr->screen[y][x].attributes) & (1 << (css)))!=0)
-                        {
-
-                        fprintf(ptr->out," class='tviewc%s%d'",
-                            (( (ptr->screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)) )!=0?"u":""),
-                            css);
-                        break;
-                        }
-                    ++css;
-                    }
-
-
-                fputs(">",ptr->out);
-                }
-
-        int ch=ptr->screen[y][x].ch;
-        switch(ch)
-            {
-            case '<': fputs("<",ptr->out);break;
-            case '>': fputs(">",ptr->out);break;
-            case '&': fputs("&",ptr->out);break;
-            default: fputc(ch,ptr->out); break;
-            }
-
-
-            if(x+1 == tv->mcol  || ptr->screen[y][x].attributes!=ptr->screen[y][x+1].attributes)
-                {
-                fputs("",ptr->out);
-                }
-            }
-        if(y+1 < ptr->row_count) fputs("
",ptr->out); - } - fputs("
",ptr->out); - return 0; - } - - -#define ANSI_COLOR_RED "\x1b[31m" -#define ANSI_COLOR_GREEN "\x1b[32m" -#define ANSI_COLOR_YELLOW "\x1b[33m" -#define ANSI_COLOR_BLUE "\x1b[34m" -#define ANSI_COLOR_MAGENTA "\x1b[35m" -#define ANSI_COLOR_CYAN "\x1b[36m" -#define ANSI_COLOR_BLACK "\x1b[0m" -#define ANSI_COLOR_RESET ANSI_COLOR_BLACK - -#define ANSI_UNDERLINE_SET "\033[4m" -#define ANSI_UNDERLINE_UNSET "\033[0m" - -static int text_drawaln(struct AbstractTview* tv, int tid, int pos) - { - int y,x; - html_tview_t* ptr=FROM_TV(tv); - html_clear(tv); - base_draw_aln(tv, tid, pos); - int is_term= isatty(fileno(ptr->out)); - - for(y=0;y< ptr->row_count;++y) - { - for(x=0;x< tv->mcol;++x) - { - if(is_term) - { - int css=0; - while(css<32) - { - if(( (ptr->screen[y][x].attributes) & (1 << (css)))!=0) - { - break; - } - ++css; - } - switch(css) - { - //CSS(0, "black"); - case 1: fputs(ANSI_COLOR_BLUE,ptr->out); break; - case 2: fputs(ANSI_COLOR_GREEN,ptr->out); break; - case 3: fputs(ANSI_COLOR_YELLOW,ptr->out); break; - //CSS(4, "black"); - case 5: fputs(ANSI_COLOR_GREEN,ptr->out); break; - case 6: fputs(ANSI_COLOR_CYAN,ptr->out); break; - case 7: fputs(ANSI_COLOR_YELLOW,ptr->out); break; - case 8: fputs(ANSI_COLOR_RED,ptr->out); break; - case 9: fputs(ANSI_COLOR_BLUE,ptr->out); break; - default:break; - } - if(( (ptr->screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)))!=0) - { - fputs(ANSI_UNDERLINE_SET,ptr->out); - } - - } - - - int ch=ptr->screen[y][x].ch; - - fputc(ch,ptr->out); - if(is_term) - { - fputs(ANSI_COLOR_RESET,ptr->out); - if(( (ptr->screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)))!=0) - { - fputs(ANSI_UNDERLINE_UNSET,ptr->out); - } - } - } - fputc('\n',ptr->out); - } - return 0; - } - - -static int html_loop(tview_t* tv) - { - //tv->my_drawaln(tv, tv->curr_tid, tv->left_pos); - return 0; - } - -static int html_underline(tview_t* tv) - { - return (1 << UNDERLINE_FLAG); - } - -/* -static void init_pair(html_tview_t *tv,int id_ge_1, const char* pen, const char* paper) - { - - } -*/ - -tview_t* html_tv_init(const char *fn, const char *fn_fa, const char *samples, - const htsFormat *fmt) - { - char* colstr=getenv("COLUMNS"); - html_tview_t *tv = (html_tview_t*)calloc(1, sizeof(html_tview_t)); - tview_t* base=(tview_t*)tv; - if(tv==0) - { - fprintf(stderr,"Calloc failed\n"); - return 0; - } - tv->row_count=0; - tv->screen=NULL; - tv->out=stdout; - tv->attributes=0; - base_tv_init(base,fn,fn_fa,samples,fmt); - /* initialize callbacks */ -#define SET_CALLBACK(fun) base->my_##fun=html_##fun; - SET_CALLBACK(destroy); - SET_CALLBACK(mvprintw); - SET_CALLBACK(mvaddch); - SET_CALLBACK(attron); - SET_CALLBACK(attroff); - SET_CALLBACK(clear); - SET_CALLBACK(colorpair); - SET_CALLBACK(drawaln); - SET_CALLBACK(loop); - SET_CALLBACK(underline); -#undef SET_CALLBACK - - - if(colstr!=0) - { - base->mcol=atoi(colstr); - if(base->mcol<10) base->mcol=80; - } - base->mrow=99999; - -/* - init_pair(tv,1, "blue", "white"); - init_pair(tv,2, "green", "white"); - init_pair(tv,3, "yellow", "white"); - init_pair(tv,4, "white", "white"); - init_pair(tv,5, "green", "white"); - init_pair(tv,6, "cyan", "white"); - init_pair(tv,7, "yellow", "white"); - init_pair(tv,8, "red", "white"); - init_pair(tv,9, "blue", "white"); - */ - return base; - } - - -tview_t* text_tv_init(const char *fn, const char *fn_fa, const char *samples, - const htsFormat *fmt) - { - tview_t* tv=html_tv_init(fn,fn_fa,samples,fmt); - tv->my_drawaln=text_drawaln; - return tv; - } - diff --git a/samtools/bam_tview_html.c.pysam.c b/samtools/bam_tview_html.c.pysam.c deleted file mode 100644 index 164e33da8..000000000 --- a/samtools/bam_tview_html.c.pysam.c +++ /dev/null @@ -1,379 +0,0 @@ -#include "pysam.h" - -/* bam_tview_html.c -- HTML tview output. - - Copyright (C) 2013 Pierre Lindenbaum, Institut du Thorax, INSERM U1087, Université de Nantes. - - Author: Pierre Lindenbaum - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. */ - -#include - -#include -#include "bam_tview.h" - -#define UNDERLINE_FLAG 10 - -typedef struct HtmlTview { - tview_t view; - int row_count; - tixel_t** screen; - FILE* out; - int attributes;/* color... */ - } html_tview_t; - -#define FROM_TV(ptr) ((html_tview_t*)ptr) - -static void html_destroy(tview_t* base) - { - int i; - html_tview_t* tv=(html_tview_t*)base; - if(tv->screen!=NULL) - { - for(i=0;i< tv->row_count;++i) free(tv->screen[i]); - free(tv->screen); - } - base_tv_destroy(base); - free(tv); - } - -/* - void (*my_mvprintw)(struct AbstractTview* ,int,int,const char*,...); - void (*my_)(struct AbstractTview*,int,int,int); - void (*my_attron)(struct AbstractTview*,int); - void (*my_attroff)(struct AbstractTview*,int); - void (*my_clear)(struct AbstractTview*); - int (*my_colorpair)(struct AbstractTview*,int); -*/ - -static void html_mvprintw(struct AbstractTview* tv,int y ,int x,const char* fmt,...) - { - int i,nchars=0; - unsigned int size=tv->mcol+2; - char* str=malloc(size); - if(str==0) exit(EXIT_FAILURE); - va_list argptr; - va_start(argptr, fmt); - nchars=vsnprintf(str,size, fmt, argptr); - va_end(argptr); - - for(i=0;i< nchars;++i) - { - tv->my_mvaddch(tv,y,x+i,str[i]); - } - free(str); - } - -static void html_mvaddch(struct AbstractTview* tv,int y,int x,int ch) - { - tixel_t* row=NULL; - html_tview_t* ptr=FROM_TV(tv); - if( x >= tv->mcol ) return; //out of screen - while(ptr->row_count<=y) - { - int x; - row=(tixel_t*)calloc(tv->mcol,sizeof(tixel_t)); - if(row==0) exit(EXIT_FAILURE); - for(x=0;xmcol;++x) {row[x].ch=' ';row[x].attributes=0;} - ptr->screen=(tixel_t**)realloc(ptr->screen,sizeof(tixel_t*)*(ptr->row_count+1)); - ptr->screen[ptr->row_count++]=row; - } - row=ptr->screen[y]; - row[x].ch=ch; - row[x].attributes=ptr->attributes; - } - -static void html_attron(struct AbstractTview* tv,int flag) - { - html_tview_t* ptr=FROM_TV(tv); - ptr->attributes |= flag; - - - } - -static void html_attroff(struct AbstractTview* tv,int flag) - { - html_tview_t* ptr=FROM_TV(tv); - ptr->attributes &= ~(flag); - } - -static void html_clear(struct AbstractTview* tv) - { - html_tview_t* ptr=FROM_TV(tv); - if(ptr->screen!=NULL) - { - int i; - for(i=0;i< ptr->row_count;++i) free(ptr->screen[i]); - free(ptr->screen); - ptr->screen=NULL; - } - ptr->row_count=0; - ptr->attributes=0; - } - -static int html_colorpair(struct AbstractTview* tv,int flag) - { - return (1 << (flag)); - } - -static int html_drawaln(struct AbstractTview* tv, int tid, int pos) - { - int y,x; - html_tview_t* ptr=FROM_TV(tv); - html_clear(tv); - base_draw_aln(tv, tid, pos); - fputs("",ptr->out); - fprintf(ptr->out,"%s:%d", - tv->header->target_name[tid], - pos+1 - ); - //style - - fputs("",ptr->out); - - fputs("",ptr->out); - - fprintf(ptr->out,"
%s:%d
", - tv->header->target_name[tid], - pos+1 - ); - - fputs("
",ptr->out);
-    for(y=0;y< ptr->row_count;++y)
-        {
-
-        for(x=0;x< tv->mcol;++x)
-            {
-
-
-        if(x== 0 || ptr->screen[y][x].attributes != ptr->screen[y][x-1].attributes)
-                {
-                int css=0;
-            fprintf(ptr->out,"1) fprintf(pysam_stderr,"css=%d pow2=%d vs %d\n",css,(1 << (css)),ptr->screen[y][x].attributes);
-                    if(( (ptr->screen[y][x].attributes) & (1 << (css)))!=0)
-                        {
-
-                        fprintf(ptr->out," class='tviewc%s%d'",
-                            (( (ptr->screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)) )!=0?"u":""),
-                            css);
-                        break;
-                        }
-                    ++css;
-                    }
-
-
-                fputs(">",ptr->out);
-                }
-
-        int ch=ptr->screen[y][x].ch;
-        switch(ch)
-            {
-            case '<': fputs("<",ptr->out);break;
-            case '>': fputs(">",ptr->out);break;
-            case '&': fputs("&",ptr->out);break;
-            default: fputc(ch,ptr->out); break;
-            }
-
-
-            if(x+1 == tv->mcol  || ptr->screen[y][x].attributes!=ptr->screen[y][x+1].attributes)
-                {
-                fputs("",ptr->out);
-                }
-            }
-        if(y+1 < ptr->row_count) fputs("
",ptr->out); - } - fputs("
",ptr->out); - return 0; - } - - -#define ANSI_COLOR_RED "\x1b[31m" -#define ANSI_COLOR_GREEN "\x1b[32m" -#define ANSI_COLOR_YELLOW "\x1b[33m" -#define ANSI_COLOR_BLUE "\x1b[34m" -#define ANSI_COLOR_MAGENTA "\x1b[35m" -#define ANSI_COLOR_CYAN "\x1b[36m" -#define ANSI_COLOR_BLACK "\x1b[0m" -#define ANSI_COLOR_RESET ANSI_COLOR_BLACK - -#define ANSI_UNDERLINE_SET "\033[4m" -#define ANSI_UNDERLINE_UNSET "\033[0m" - -static int text_drawaln(struct AbstractTview* tv, int tid, int pos) - { - int y,x; - html_tview_t* ptr=FROM_TV(tv); - html_clear(tv); - base_draw_aln(tv, tid, pos); - int is_term= isatty(fileno(ptr->out)); - - for(y=0;y< ptr->row_count;++y) - { - for(x=0;x< tv->mcol;++x) - { - if(is_term) - { - int css=0; - while(css<32) - { - if(( (ptr->screen[y][x].attributes) & (1 << (css)))!=0) - { - break; - } - ++css; - } - switch(css) - { - //CSS(0, "black"); - case 1: fputs(ANSI_COLOR_BLUE,ptr->out); break; - case 2: fputs(ANSI_COLOR_GREEN,ptr->out); break; - case 3: fputs(ANSI_COLOR_YELLOW,ptr->out); break; - //CSS(4, "black"); - case 5: fputs(ANSI_COLOR_GREEN,ptr->out); break; - case 6: fputs(ANSI_COLOR_CYAN,ptr->out); break; - case 7: fputs(ANSI_COLOR_YELLOW,ptr->out); break; - case 8: fputs(ANSI_COLOR_RED,ptr->out); break; - case 9: fputs(ANSI_COLOR_BLUE,ptr->out); break; - default:break; - } - if(( (ptr->screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)))!=0) - { - fputs(ANSI_UNDERLINE_SET,ptr->out); - } - - } - - - int ch=ptr->screen[y][x].ch; - - fputc(ch,ptr->out); - if(is_term) - { - fputs(ANSI_COLOR_RESET,ptr->out); - if(( (ptr->screen[y][x].attributes) & (1 << (UNDERLINE_FLAG)))!=0) - { - fputs(ANSI_UNDERLINE_UNSET,ptr->out); - } - } - } - fputc('\n',ptr->out); - } - return 0; - } - - -static int html_loop(tview_t* tv) - { - //tv->my_drawaln(tv, tv->curr_tid, tv->left_pos); - return 0; - } - -static int html_underline(tview_t* tv) - { - return (1 << UNDERLINE_FLAG); - } - -/* -static void init_pair(html_tview_t *tv,int id_ge_1, const char* pen, const char* paper) - { - - } -*/ - -tview_t* html_tv_init(const char *fn, const char *fn_fa, const char *samples, - const htsFormat *fmt) - { - char* colstr=getenv("COLUMNS"); - html_tview_t *tv = (html_tview_t*)calloc(1, sizeof(html_tview_t)); - tview_t* base=(tview_t*)tv; - if(tv==0) - { - fprintf(pysam_stderr,"Calloc failed\n"); - return 0; - } - tv->row_count=0; - tv->screen=NULL; - tv->out=pysam_stdout; - tv->attributes=0; - base_tv_init(base,fn,fn_fa,samples,fmt); - /* initialize callbacks */ -#define SET_CALLBACK(fun) base->my_##fun=html_##fun; - SET_CALLBACK(destroy); - SET_CALLBACK(mvprintw); - SET_CALLBACK(mvaddch); - SET_CALLBACK(attron); - SET_CALLBACK(attroff); - SET_CALLBACK(clear); - SET_CALLBACK(colorpair); - SET_CALLBACK(drawaln); - SET_CALLBACK(loop); - SET_CALLBACK(underline); -#undef SET_CALLBACK - - - if(colstr!=0) - { - base->mcol=atoi(colstr); - if(base->mcol<10) base->mcol=80; - } - base->mrow=99999; - -/* - init_pair(tv,1, "blue", "white"); - init_pair(tv,2, "green", "white"); - init_pair(tv,3, "yellow", "white"); - init_pair(tv,4, "white", "white"); - init_pair(tv,5, "green", "white"); - init_pair(tv,6, "cyan", "white"); - init_pair(tv,7, "yellow", "white"); - init_pair(tv,8, "red", "white"); - init_pair(tv,9, "blue", "white"); - */ - return base; - } - - -tview_t* text_tv_init(const char *fn, const char *fn_fa, const char *samples, - const htsFormat *fmt) - { - tview_t* tv=html_tv_init(fn,fn_fa,samples,fmt); - tv->my_drawaln=text_drawaln; - return tv; - } - diff --git a/samtools/bamshuf.c b/samtools/bamshuf.c index 044bc4e96..c1c89fb93 100644 --- a/samtools/bamshuf.c +++ b/samtools/bamshuf.c @@ -34,6 +34,7 @@ DEALINGS IN THE SOFTWARE. */ #include "htslib/hts.h" #include "htslib/ksort.h" #include "samtools.h" +#include "htslib/thread_pool.h" #include "sam_opts.h" #define DEF_CLEVEL 1 @@ -86,6 +87,14 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, bam_hdr_t *h = NULL; int64_t j, max_cnt = 0, *cnt = NULL; elem_t *a = NULL; + htsThreadPool p = {NULL, 0}; + + if (ga->nthreads > 0) { + if (!(p.pool = hts_tpool_init(ga->nthreads))) { + print_error_errno("collate", "Error creating thread pool\n"); + return 1; + } + } // Read input, distribute reads pseudo-randomly into n_files temporary // files. @@ -94,12 +103,25 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, print_error_errno("collate", "Cannot open input file \"%s\"", fn); return 1; } + if (p.pool) hts_set_opt(fp, HTS_OPT_THREAD_POOL, &p); h = sam_hdr_read(fp); if (h == NULL) { fprintf(stderr, "Couldn't read header for '%s'\n", fn); goto fail; } + + if (sam_hdr_change_HD(h, "SO", "unsorted") != 0) { + print_error("collate", + "failed to change sort order header to 'unsorted'\n"); + goto fail; + } + if (sam_hdr_change_HD(h, "GO", "query") != 0) { + print_error("collate", + "failed to change group order header to 'query'\n"); + goto fail; + } + fnt = (char**)calloc(n_files, sizeof(char*)); if (!fnt) goto mem_fail; fpt = (samFile**)calloc(n_files, sizeof(samFile*)); @@ -173,6 +195,7 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, else print_error_errno("collate", "Cannot open output file \"%s.bam\"", pre); goto fail; } + if (p.pool) hts_set_opt(fpw, HTS_OPT_THREAD_POOL, &p); if (sam_hdr_write(fpw, h) < 0) { print_error_errno("collate", "Couldn't write header"); @@ -193,6 +216,7 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, print_error_errno("collate", "Couldn't open \"%s\"", fnt[i]); goto fail; } + if (p.pool) hts_set_opt(fp, HTS_OPT_THREAD_POOL, &p); bam_hdr_destroy(sam_hdr_read(fp)); // Skip over header // Slurp in one of the split files @@ -228,6 +252,7 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, return 1; } + if (p.pool) hts_tpool_destroy(p.pool); return 0; mem_fail: @@ -249,13 +274,14 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, free(fnt); free(fpt); free(cnt); + if (p.pool) hts_tpool_destroy(p.pool); sam_global_args_free(ga); return 1; } static int usage(FILE *fp, int n_files) { fprintf(fp, - "Usage: samtools collate [-Ou] [-n nFiles] [-c cLevel] \n\n" + "Usage: samtools collate [-Ou] [-n nFiles] [-l cLevel] \n\n" "Options:\n" " -O output to stdout\n" " -u uncompressed BAM output\n" @@ -263,7 +289,7 @@ static int usage(FILE *fp, int n_files) { " -n INT number of temporary files [%d]\n", // n_files DEF_CLEVEL, n_files); - sam_global_opt_help(fp, "-...."); + sam_global_opt_help(fp, "-....@"); return 1; } @@ -273,11 +299,11 @@ int main_bamshuf(int argc, char *argv[]) int c, n_files = 64, clevel = DEF_CLEVEL, is_stdout = 0, is_un = 0; sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0, '@'), { NULL, 0, NULL, 0 } }; - while ((c = getopt_long(argc, argv, "n:l:uO", lopts, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "n:l:uO@:", lopts, NULL)) >= 0) { switch (c) { case 'n': n_files = atoi(optarg); break; case 'l': clevel = atoi(optarg); break; diff --git a/samtools/bamshuf.c.pysam.c b/samtools/bamshuf.c.pysam.c index fb1a5ac70..008aa0c33 100644 --- a/samtools/bamshuf.c.pysam.c +++ b/samtools/bamshuf.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bamshuf.c -- collate subcommand. @@ -36,6 +36,7 @@ DEALINGS IN THE SOFTWARE. */ #include "htslib/hts.h" #include "htslib/ksort.h" #include "samtools.h" +#include "htslib/thread_pool.h" #include "sam_opts.h" #define DEF_CLEVEL 1 @@ -79,7 +80,7 @@ static inline int elem_lt(elem_t x, elem_t y) KSORT_INIT(bamshuf, elem_t, elem_lt) static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, - int is_pysam_stdout, sam_global_args *ga) + int is_samtools_stdout, sam_global_args *ga) { samFile *fp, *fpw = NULL, **fpt = NULL; char **fnt = NULL, modew[8]; @@ -88,6 +89,14 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, bam_hdr_t *h = NULL; int64_t j, max_cnt = 0, *cnt = NULL; elem_t *a = NULL; + htsThreadPool p = {NULL, 0}; + + if (ga->nthreads > 0) { + if (!(p.pool = hts_tpool_init(ga->nthreads))) { + print_error_errno("collate", "Error creating thread pool\n"); + return 1; + } + } // Read input, distribute reads pseudo-randomly into n_files temporary // files. @@ -96,12 +105,25 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, print_error_errno("collate", "Cannot open input file \"%s\"", fn); return 1; } + if (p.pool) hts_set_opt(fp, HTS_OPT_THREAD_POOL, &p); h = sam_hdr_read(fp); if (h == NULL) { - fprintf(pysam_stderr, "Couldn't read header for '%s'\n", fn); + fprintf(samtools_stderr, "Couldn't read header for '%s'\n", fn); + goto fail; + } + + if (sam_hdr_change_HD(h, "SO", "unsorted") != 0) { + print_error("collate", + "failed to change sort order header to 'unsorted'\n"); goto fail; } + if (sam_hdr_change_HD(h, "GO", "query") != 0) { + print_error("collate", + "failed to change group order header to 'query'\n"); + goto fail; + } + fnt = (char**)calloc(n_files, sizeof(char*)); if (!fnt) goto mem_fail; fpt = (samFile**)calloc(n_files, sizeof(samFile*)); @@ -139,7 +161,7 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, bam_destroy1(b); b = NULL; if (r < -1) { - fprintf(pysam_stderr, "Error reading input file\n"); + fprintf(samtools_stderr, "Error reading input file\n"); goto fail; } for (i = 0; i < n_files; ++i) { @@ -147,7 +169,7 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, r = sam_close(fpt[i]); fpt[i] = NULL; if (r < 0) { - fprintf(pysam_stderr, "Error on closing '%s'\n", fnt[i]); + fprintf(samtools_stderr, "Error on closing '%s'\n", fnt[i]); return 1; } @@ -160,7 +182,7 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, fp = NULL; // merge sprintf(modew, "wb%d", (clevel >= 0 && clevel <= 9)? clevel : DEF_CLEVEL); - if (!is_pysam_stdout) { // output to a file + if (!is_samtools_stdout) { // output to a file char *fnw = (char*)calloc(l + 5, 1); if (!fnw) goto mem_fail; if (ga->out.format == unknown_format) @@ -169,12 +191,13 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, sprintf(fnw, "%s.%s", pre, hts_format_file_extension(&ga->out)); fpw = sam_open_format(fnw, modew, &ga->out); free(fnw); - } else fpw = sam_open_format("-", modew, &ga->out); // output to pysam_stdout + } else fpw = sam_open_format("-", modew, &ga->out); // output to samtools_stdout if (fpw == NULL) { - if (is_pysam_stdout) print_error_errno("collate", "Cannot open standard output"); + if (is_samtools_stdout) print_error_errno("collate", "Cannot open standard output"); else print_error_errno("collate", "Cannot open output file \"%s.bam\"", pre); goto fail; } + if (p.pool) hts_set_opt(fpw, HTS_OPT_THREAD_POOL, &p); if (sam_hdr_write(fpw, h) < 0) { print_error_errno("collate", "Couldn't write header"); @@ -195,12 +218,13 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, print_error_errno("collate", "Couldn't open \"%s\"", fnt[i]); goto fail; } + if (p.pool) hts_set_opt(fp, HTS_OPT_THREAD_POOL, &p); bam_hdr_destroy(sam_hdr_read(fp)); // Skip over header // Slurp in one of the split files for (j = 0; j < c; ++j) { if (sam_read1(fp, h, a[j].b) < 0) { - fprintf(pysam_stderr, "Error reading '%s'\n", fnt[i]); + fprintf(samtools_stderr, "Error reading '%s'\n", fnt[i]); goto fail; } a[j].key = hash_X31_Wang(bam_get_qname(a[j].b)); @@ -226,14 +250,15 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, free(a); free(fnt); free(cnt); sam_global_args_free(ga); if (sam_close(fpw) < 0) { - fprintf(pysam_stderr, "Error on closing output\n"); + fprintf(samtools_stderr, "Error on closing output\n"); return 1; } + if (p.pool) hts_tpool_destroy(p.pool); return 0; mem_fail: - fprintf(pysam_stderr, "Out of memory\n"); + fprintf(samtools_stderr, "Out of memory\n"); fail: if (fp) sam_close(fp); @@ -251,48 +276,49 @@ static int bamshuf(const char *fn, int n_files, const char *pre, int clevel, free(fnt); free(fpt); free(cnt); + if (p.pool) hts_tpool_destroy(p.pool); sam_global_args_free(ga); return 1; } static int usage(FILE *fp, int n_files) { fprintf(fp, - "Usage: samtools collate [-Ou] [-n nFiles] [-c cLevel] \n\n" + "Usage: samtools collate [-Ou] [-n nFiles] [-l cLevel] \n\n" "Options:\n" - " -O output to pysam_stdout\n" + " -O output to samtools_stdout\n" " -u uncompressed BAM output\n" " -l INT compression level [%d]\n" // DEF_CLEVEL " -n INT number of temporary files [%d]\n", // n_files DEF_CLEVEL, n_files); - sam_global_opt_help(fp, "-...."); + sam_global_opt_help(fp, "-....@"); return 1; } int main_bamshuf(int argc, char *argv[]) { - int c, n_files = 64, clevel = DEF_CLEVEL, is_pysam_stdout = 0, is_un = 0; + int c, n_files = 64, clevel = DEF_CLEVEL, is_samtools_stdout = 0, is_un = 0; sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0, '@'), { NULL, 0, NULL, 0 } }; - while ((c = getopt_long(argc, argv, "n:l:uO", lopts, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "n:l:uO@:", lopts, NULL)) >= 0) { switch (c) { case 'n': n_files = atoi(optarg); break; case 'l': clevel = atoi(optarg); break; case 'u': is_un = 1; break; - case 'O': is_pysam_stdout = 1; break; + case 'O': is_samtools_stdout = 1; break; default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; /* else fall-through */ - case '?': return usage(pysam_stderr, n_files); + case '?': return usage(samtools_stderr, n_files); } } if (is_un) clevel = 0; if (optind + 2 > argc) - return usage(pysam_stderr, n_files); + return usage(samtools_stderr, n_files); - return bamshuf(argv[optind], n_files, argv[optind+1], clevel, is_pysam_stdout, &ga); + return bamshuf(argv[optind], n_files, argv[optind+1], clevel, is_samtools_stdout, &ga); } diff --git a/samtools/bamtk.c b/samtools/bamtk.c index 5c1c60d73..d1e89c685 100644 --- a/samtools/bamtk.c +++ b/samtools/bamtk.c @@ -1,6 +1,6 @@ /* bamtk.c -- main samtools command front-end. - Copyright (C) 2008-2016 Genome Research Ltd. + Copyright (C) 2008-2018 Genome Research Ltd. Author: Heng Li @@ -27,12 +27,10 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include -#include #include -#include + #include "htslib/hts.h" #include "samtools.h" -#include "version.h" int bam_taf2baf(int argc, char *argv[]); int bam_mpileup(int argc, char *argv[]); @@ -45,6 +43,7 @@ int bam_rmdup(int argc, char *argv[]); int bam_flagstat(int argc, char *argv[]); int bam_fillmd(int argc, char *argv[]); int bam_idxstats(int argc, char *argv[]); +int bam_markdup(int argc, char *argv[]); int main_samview(int argc, char *argv[]); int main_import(int argc, char *argv[]); int main_reheader(int argc, char *argv[]); @@ -64,38 +63,6 @@ int main_addreplacerg(int argc, char *argv[]); int faidx_main(int argc, char *argv[]); int dict_main(int argc, char *argv[]); -const char *samtools_version() -{ - return SAMTOOLS_VERSION; -} - -static void vprint_error_core(const char *subcommand, const char *format, va_list args, const char *extra) -{ - fflush(stdout); - if (subcommand && *subcommand) fprintf(stderr, "samtools %s: ", subcommand); - else fprintf(stderr, "samtools: "); - vfprintf(stderr, format, args); - if (extra) fprintf(stderr, ": %s\n", extra); - else fprintf(stderr, "\n"); - fflush(stderr); -} - -void print_error(const char *subcommand, const char *format, ...) -{ - va_list args; - va_start(args, format); - vprint_error_core(subcommand, format, args, NULL); - va_end(args); -} - -void print_error_errno(const char *subcommand, const char *format, ...) -{ - int err = errno; - va_list args; - va_start(args, format); - vprint_error_core(subcommand, format, args, strerror(err)); - va_end(args); -} static void usage(FILE *fp) { @@ -118,9 +85,9 @@ static void usage(FILE *fp) " calmd recalculate MD/NM tags and '=' bases\n" " fixmate fix mate information\n" " reheader replace BAM header\n" -" rmdup remove PCR duplicates\n" " targetcut cut fosmid regions (for fosmid pool only)\n" " addreplacerg adds or replaces RG tags\n" +" markdup mark duplicates\n" "\n" " -- File operations\n" " collate shuffle and group alignments by name\n" @@ -155,6 +122,18 @@ static void usage(FILE *fp) #endif } +// This is a tricky one, but on Windows the filename wildcard expansion is done by +// the application and not by the shell, as traditionally it never had a "shell". +// Even now, DOS and Powershell do not do this expansion (but bash does). +// +// This means that Mingw/Msys implements code before main() that takes e.g. "*" and +// expands it up to a list of matching filenames. This in turn breaks things like +// specifying "*" as a region (all the unmapped reads). We take a hard line here - +// filename expansion is the task of the shell, not our application! +#ifdef _WIN32 +int _CRT_glob = 0; +#endif + int main(int argc, char *argv[]) { #ifdef _WIN32 @@ -185,6 +164,7 @@ int main(int argc, char *argv[]) else if (strcmp(argv[1], "dict") == 0) ret = dict_main(argc-1, argv+1); else if (strcmp(argv[1], "fixmate") == 0) ret = bam_mating(argc-1, argv+1); else if (strcmp(argv[1], "rmdup") == 0) ret = bam_rmdup(argc-1, argv+1); + else if (strcmp(argv[1], "markdup") == 0) ret = bam_markdup(argc-1, argv+1); else if (strcmp(argv[1], "flagstat") == 0) ret = bam_flagstat(argc-1, argv+1); else if (strcmp(argv[1], "calmd") == 0) ret = bam_fillmd(argc-1, argv+1); else if (strcmp(argv[1], "fillmd") == 0) ret = bam_fillmd(argc-1, argv+1); @@ -215,7 +195,7 @@ int main(int argc, char *argv[]) printf( "samtools %s\n" "Using htslib %s\n" -"Copyright (C) 2016 Genome Research Ltd.\n", +"Copyright (C) 2018 Genome Research Ltd.\n", samtools_version(), hts_version()); } else if (strcmp(argv[1], "--version-only") == 0) { diff --git a/samtools/bamtk.c.pysam.c b/samtools/bamtk.c.pysam.c index 1f3d93843..e14f01c7a 100644 --- a/samtools/bamtk.c.pysam.c +++ b/samtools/bamtk.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bamtk.c -- main samtools command front-end. - Copyright (C) 2008-2016 Genome Research Ltd. + Copyright (C) 2008-2018 Genome Research Ltd. Author: Heng Li @@ -29,24 +29,23 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include -#include #include -#include + #include "htslib/hts.h" #include "samtools.h" -#include "version.h" int bam_taf2baf(int argc, char *argv[]); int bam_mpileup(int argc, char *argv[]); int bam_merge(int argc, char *argv[]); int bam_index(int argc, char *argv[]); int bam_sort(int argc, char *argv[]); -int bam_tview_main(int argc, char *argv[]); +// int bam_tview_main(int argc, char *argv[]); int bam_mating(int argc, char *argv[]); int bam_rmdup(int argc, char *argv[]); int bam_flagstat(int argc, char *argv[]); int bam_fillmd(int argc, char *argv[]); int bam_idxstats(int argc, char *argv[]); +int bam_markdup(int argc, char *argv[]); int main_samview(int argc, char *argv[]); int main_import(int argc, char *argv[]); int main_reheader(int argc, char *argv[]); @@ -66,38 +65,6 @@ int main_addreplacerg(int argc, char *argv[]); int faidx_main(int argc, char *argv[]); int dict_main(int argc, char *argv[]); -const char *samtools_version() -{ - return SAMTOOLS_VERSION; -} - -static void vprint_error_core(const char *subcommand, const char *format, va_list args, const char *extra) -{ - fflush(pysam_stdout); - if (subcommand && *subcommand) fprintf(pysam_stderr, "samtools %s: ", subcommand); - else fprintf(pysam_stderr, "samtools: "); - vfprintf(pysam_stderr, format, args); - if (extra) fprintf(pysam_stderr, ": %s\n", extra); - else fprintf(pysam_stderr, "\n"); - fflush(pysam_stderr); -} - -void print_error(const char *subcommand, const char *format, ...) -{ - va_list args; - va_start(args, format); - vprint_error_core(subcommand, format, args, NULL); - va_end(args); -} - -void print_error_errno(const char *subcommand, const char *format, ...) -{ - int err = errno; - va_list args; - va_start(args, format); - vprint_error_core(subcommand, format, args, strerror(err)); - va_end(args); -} static void usage(FILE *fp) { @@ -120,9 +87,9 @@ static void usage(FILE *fp) " calmd recalculate MD/NM tags and '=' bases\n" " fixmate fix mate information\n" " reheader replace BAM header\n" -" rmdup remove PCR duplicates\n" " targetcut cut fosmid regions (for fosmid pool only)\n" " addreplacerg adds or replaces RG tags\n" +" markdup mark duplicates\n" "\n" " -- File operations\n" " collate shuffle and group alignments by name\n" @@ -157,16 +124,28 @@ static void usage(FILE *fp) #endif } +// This is a tricky one, but on Windows the filename wildcard expansion is done by +// the application and not by the shell, as traditionally it never had a "shell". +// Even now, DOS and Powershell do not do this expansion (but bash does). +// +// This means that Mingw/Msys implements code before main() that takes e.g. "*" and +// expands it up to a list of matching filenames. This in turn breaks things like +// specifying "*" as a region (all the unmapped reads). We take a hard line here - +// filename expansion is the task of the shell, not our application! +#ifdef _WIN32 +int _CRT_glob = 0; +#endif + int samtools_main(int argc, char *argv[]) { #ifdef _WIN32 - setmode(fileno(pysam_stdout), O_BINARY); + setmode(fileno(samtools_stdout), O_BINARY); setmode(fileno(stdin), O_BINARY); #endif - if (argc < 2) { usage(pysam_stderr); return 1; } + if (argc < 2) { usage(samtools_stderr); return 1; } if (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "--help") == 0) { - if (argc == 2) { usage(pysam_stdout); return 0; } + if (argc == 2) { usage(samtools_stdout); return 0; } // Otherwise change "samtools help COMMAND [...]" to "samtools COMMAND"; // main_xyz() functions by convention display the subcommand's usage @@ -187,6 +166,7 @@ int samtools_main(int argc, char *argv[]) else if (strcmp(argv[1], "dict") == 0) ret = dict_main(argc-1, argv+1); else if (strcmp(argv[1], "fixmate") == 0) ret = bam_mating(argc-1, argv+1); else if (strcmp(argv[1], "rmdup") == 0) ret = bam_rmdup(argc-1, argv+1); + else if (strcmp(argv[1], "markdup") == 0) ret = bam_markdup(argc-1, argv+1); else if (strcmp(argv[1], "flagstat") == 0) ret = bam_flagstat(argc-1, argv+1); else if (strcmp(argv[1], "calmd") == 0) ret = bam_fillmd(argc-1, argv+1); else if (strcmp(argv[1], "fillmd") == 0) ret = bam_fillmd(argc-1, argv+1); @@ -209,22 +189,22 @@ int samtools_main(int argc, char *argv[]) else if (strcmp(argv[1], "quickcheck") == 0) ret = main_quickcheck(argc-1, argv+1); else if (strcmp(argv[1], "addreplacerg") == 0) ret = main_addreplacerg(argc-1, argv+1); else if (strcmp(argv[1], "pileup") == 0) { - fprintf(pysam_stderr, "[main] The `pileup' command has been removed. Please use `mpileup' instead.\n"); + fprintf(samtools_stderr, "[main] The `pileup' command has been removed. Please use `mpileup' instead.\n"); return 1; } - else if (strcmp(argv[1], "tview") == 0) ret = bam_tview_main(argc-1, argv+1); + // else if (strcmp(argv[1], "tview") == 0) ret = bam_tview_main(argc-1, argv+1); else if (strcmp(argv[1], "--version") == 0) { - fprintf(pysam_stdout, + fprintf(samtools_stdout, "samtools %s\n" "Using htslib %s\n" -"Copyright (C) 2016 Genome Research Ltd.\n", +"Copyright (C) 2018 Genome Research Ltd.\n", samtools_version(), hts_version()); } else if (strcmp(argv[1], "--version-only") == 0) { - fprintf(pysam_stdout, "%s+htslib-%s\n", samtools_version(), hts_version()); + fprintf(samtools_stdout, "%s+htslib-%s\n", samtools_version(), hts_version()); } else { - fprintf(pysam_stderr, "[main] unrecognized command '%s'\n", argv[1]); + fprintf(samtools_stderr, "[main] unrecognized command '%s'\n", argv[1]); return 1; } return ret; diff --git a/samtools/bedcov.c b/samtools/bedcov.c index d4dceeee1..10983097e 100644 --- a/samtools/bedcov.c +++ b/samtools/bedcov.c @@ -33,6 +33,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include "htslib/kstring.h" #include "htslib/sam.h" +#include "htslib/thread_pool.h" #include "sam_opts.h" #include "htslib/kseq.h" @@ -74,7 +75,7 @@ int main_bedcov(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0, '-'), { NULL, 0, NULL, 0 } }; @@ -89,8 +90,9 @@ int main_bedcov(int argc, char *argv[]) } if (usage || optind + 2 > argc) { fprintf(stderr, "Usage: samtools bedcov [options] [...]\n\n"); - fprintf(stderr, " -Q INT Only count bases of at least INT quality [0]\n"); - sam_global_opt_help(stderr, "-.--."); + fprintf(stderr, "Options:\n"); + fprintf(stderr, " -Q mapping quality threshold [0]\n"); + sam_global_opt_help(stderr, "-.--.-"); return 1; } memset(&str, 0, sizeof(kstring_t)); @@ -126,6 +128,12 @@ int main_bedcov(int argc, char *argv[]) int tid, beg, end, pos; bam_mplp_t mplp; + if (str.l == 0 || *str.s == '#') continue; /* empty or comment line */ + /* Track and browser lines. Also look for a trailing *space* in + case someone has badly-chosen a chromosome name (it would + be followed by a tab in that case). */ + if (strncmp(str.s, "track ", 6) == 0) continue; + if (strncmp(str.s, "browser ", 8) == 0) continue; for (p = q = str.s; *p && *p != '\t'; ++p); if (*p != '\t') goto bed_error; *p = 0; tid = bam_name2id(aux[0]->header, q); *p = '\t'; diff --git a/samtools/bedcov.c.pysam.c b/samtools/bedcov.c.pysam.c index 25fdffcd8..fa7c9a263 100644 --- a/samtools/bedcov.c.pysam.c +++ b/samtools/bedcov.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bedcov.c -- bedcov subcommand. @@ -35,6 +35,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include "htslib/kstring.h" #include "htslib/sam.h" +#include "htslib/thread_pool.h" #include "sam_opts.h" #include "htslib/kseq.h" @@ -76,7 +77,7 @@ int main_bedcov(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0, '-'), { NULL, 0, NULL, 0 } }; @@ -90,9 +91,10 @@ int main_bedcov(int argc, char *argv[]) if (usage) break; } if (usage || optind + 2 > argc) { - fprintf(pysam_stderr, "Usage: samtools bedcov [options] [...]\n\n"); - fprintf(pysam_stderr, " -Q INT Only count bases of at least INT quality [0]\n"); - sam_global_opt_help(pysam_stderr, "-.--."); + fprintf(samtools_stderr, "Usage: samtools bedcov [options] [...]\n\n"); + fprintf(samtools_stderr, "Options:\n"); + fprintf(samtools_stderr, " -Q mapping quality threshold [0]\n"); + sam_global_opt_help(samtools_stderr, "-.--.-"); return 1; } memset(&str, 0, sizeof(kstring_t)); @@ -106,13 +108,13 @@ int main_bedcov(int argc, char *argv[]) if (aux[i]->fp) idx[i] = sam_index_load(aux[i]->fp, argv[i+optind+1]); if (aux[i]->fp == 0 || idx[i] == 0) { - fprintf(pysam_stderr, "ERROR: fail to open index BAM file '%s'\n", argv[i+optind+1]); + fprintf(samtools_stderr, "ERROR: fail to open index BAM file '%s'\n", argv[i+optind+1]); return 2; } // TODO bgzf_set_cache_size(aux[i]->fp, 20); aux[i]->header = sam_hdr_read(aux[i]->fp); if (aux[i]->header == NULL) { - fprintf(pysam_stderr, "ERROR: failed to read header for '%s'\n", + fprintf(samtools_stderr, "ERROR: failed to read header for '%s'\n", argv[i+optind+1]); return 2; } @@ -128,6 +130,12 @@ int main_bedcov(int argc, char *argv[]) int tid, beg, end, pos; bam_mplp_t mplp; + if (str.l == 0 || *str.s == '#') continue; /* empty or comment line */ + /* Track and browser lines. Also look for a trailing *space* in + case someone has badly-chosen a chromosome name (it would + be followed by a tab in that case). */ + if (strncmp(str.s, "track ", 6) == 0) continue; + if (strncmp(str.s, "browser ", 8) == 0) continue; for (p = q = str.s; *p && *p != '\t'; ++p); if (*p != '\t') goto bed_error; *p = 0; tid = bam_name2id(aux[0]->header, q); *p = '\t'; @@ -155,12 +163,12 @@ int main_bedcov(int argc, char *argv[]) kputc('\t', &str); kputl(cnt[i], &str); } - fputs(str.s, pysam_stdout) & fputc('\n', pysam_stdout); + fputs(str.s, samtools_stdout) & fputc('\n', samtools_stdout); bam_mplp_destroy(mplp); continue; bed_error: - fprintf(pysam_stderr, "Errors in BED line '%s'\n", str.s); + fprintf(samtools_stderr, "Errors in BED line '%s'\n", str.s); } free(n_plp); free(plp); ks_destroy(ks); diff --git a/samtools/bedidx.c b/samtools/bedidx.c index c1954ad79..3489c2768 100644 --- a/samtools/bedidx.c +++ b/samtools/bedidx.c @@ -31,10 +31,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include - -#ifdef _WIN32 -#define drand48() ((double)rand() / RAND_MAX) -#endif +#include "bedidx.h" #include "htslib/ksort.h" KSORT_INIT_GENERIC(uint64_t) @@ -42,48 +39,91 @@ KSORT_INIT_GENERIC(uint64_t) #include "htslib/kseq.h" KSTREAM_INIT(gzFile, gzread, 8192) +/*! @typedef + * @abstract bed_reglist_t - value type of the BED hash table + * This structure encodes the list of intervals (ranges) for the regions provided via BED file or + * command line arguments. + * @field *a pointer to the array of intervals (kept as 64 bit integers). The upper 32 bits + * encode the beginning of the interval, while the lower 32 bits encode the end, for easy sorting. + * |-- 32 bits --|-- 32 bits --| + * |---- beg ----|---- end ----| + * @field n actual number of elements contained by a + * @field m number of allocated elements to a (n <= m) + * @field *idx index array for computing the minimum offset + */ typedef struct { int n, m; uint64_t *a; int *idx; + int filter; } bed_reglist_t; #include "htslib/khash.h" KHASH_MAP_INIT_STR(reg, bed_reglist_t) -#define LIDX_SHIFT 13 - typedef kh_reg_t reghash_t; -void bed_destroy(void *_h); +#if 0 +// Debug function +static void bed_print(void *reg_hash) { + reghash_t *h = (reghash_t *)reg_hash; + bed_reglist_t *p; + khint_t k; + int i; + const char *reg; + uint32_t beg, end; + if (!h) { + printf("Hash table is empty!\n"); + return; + } + for (k = kh_begin(h); k < kh_end(h); k++) { + if (kh_exist(h,k)) { + reg = kh_key(h,k); + printf("Region: '%s'\n", reg); + if ((p = &kh_val(h,k)) != NULL && p->n > 0) { + printf("Filter: %d\n", p->filter); + for (i=0; in; i++) { + beg = (uint32_t)(p->a[i]>>32); + end = (uint32_t)(p->a[i]); + + printf("\tinterval[%d]: %d-%d\n",i,beg,end); + } + } else { + printf("Region '%s' has no intervals!\n", reg); + } + } + } +} +#endif -int *bed_index_core(int n, uint64_t *a, int *n_idx) +static int *bed_index_core(int n, uint64_t *a) { - int i, j, m, *idx; - m = *n_idx = 0; idx = 0; + int i, j, l, *idx; + l = 0; idx = 0; for (i = 0; i < n; ++i) { int beg, end; beg = a[i]>>32 >> LIDX_SHIFT; end = ((uint32_t)a[i]) >> LIDX_SHIFT; - if (m < end + 1) { - int oldm = m; - m = end + 1; - kroundup32(m); - idx = realloc(idx, m * sizeof(int)); - for (j = oldm; j < m; ++j) idx[j] = -1; + if (l < end + 1) { + int old_l = l; + l = end + 1; + kroundup32(l); + idx = realloc(idx, l * sizeof(int)); + if (!idx) + return NULL; + + for (j = old_l; j < l; ++j) + idx[j] = -1; } - if (beg == end) { - if (idx[beg] < 0) idx[beg] = i; - } else { - for (j = beg; j <= end; ++j) - if (idx[j] < 0) idx[j] = i; - } - *n_idx = end + 1; + + for (j = beg; j < end+1; ++j) + if (idx[j] < 0) + idx[j] = i; } return idx; } -void bed_index(void *_h) +static void bed_index(void *_h) { reghash_t *h = (reghash_t*)_h; khint_t k; @@ -92,23 +132,36 @@ void bed_index(void *_h) bed_reglist_t *p = &kh_val(h, k); if (p->idx) free(p->idx); ks_introsort(uint64_t, p->n, p->a); - p->idx = bed_index_core(p->n, p->a, &p->m); + p->idx = bed_index_core(p->n, p->a); } } } -int bed_overlap_core(const bed_reglist_t *p, int beg, int end) +static int bed_minoff(const bed_reglist_t *p, unsigned int beg, unsigned int end) { + int i, min_off=0; + + if (p && p->idx) { + min_off = (beg>>LIDX_SHIFT >= p->n)? p->idx[p->n-1] : p->idx[beg>>LIDX_SHIFT]; + if (min_off < 0) { // TODO: this block can be improved, but speed should not matter too much here + int n = beg>>LIDX_SHIFT; + if (n > p->n) + n = p->n; + for (i = n - 1; i >= 0; --i) + if (p->idx[i] >= 0) + break; + min_off = i >= 0? p->idx[i] : 0; + } + } + + return min_off; +} + +static int bed_overlap_core(const bed_reglist_t *p, int beg, int end) { int i, min_off; if (p->n == 0) return 0; - min_off = (beg>>LIDX_SHIFT >= p->n)? p->idx[p->n-1] : p->idx[beg>>LIDX_SHIFT]; - if (min_off < 0) { // TODO: this block can be improved, but speed should not matter too much here - int n = beg>>LIDX_SHIFT; - if (n > p->n) n = p->n; - for (i = n - 1; i >= 0; --i) - if (p->idx[i] >= 0) break; - min_off = i >= 0? p->idx[i] : 0; - } + min_off = bed_minoff(p, beg, end); + for (i = min_off; i < p->n; ++i) { if ((int)(p->a[i]>>32) >= end) break; // out of range; no need to proceed if ((int32_t)p->a[i] > beg && (int32_t)(p->a[i]>>32) < end) @@ -127,6 +180,40 @@ int bed_overlap(const void *_h, const char *chr, int beg, int end) return bed_overlap_core(&kh_val(h, k), beg, end); } +/** @brief Trim a sorted interval list, inside a region hash table, + * by removing completely contained intervals and merging adjacent or + * overlapping intervals. + * @param reg_hash the region hash table with interval lists as values + */ + +static void bed_unify(void *reg_hash) { + + int i, j, new_n; + reghash_t *h; + bed_reglist_t *p; + + if (!reg_hash) + return; + + h = (reghash_t *)reg_hash; + + for (i = kh_begin(h); i < kh_end(h); i++) { + if (!kh_exist(h,i) || !(p = &kh_val(h,i)) || !(p->n)) + continue; + + for (new_n = 0, j = 1; j < p->n; j++) { + if ((uint32_t)p->a[new_n] < (uint32_t)(p->a[j]>>32)) { + p->a[++new_n] = p->a[j]; + } else { + if ((uint32_t)p->a[new_n] < (uint32_t)p->a[j]) + p->a[new_n] = (p->a[new_n] & 0xFFFFFFFF00000000) | (uint32_t)(p->a[j]); + } + } + + p->n = ++new_n; + } +} + /* "BED" file reader, which actually reads two different formats. BED files contain between three and nine fields per line, of which @@ -221,8 +308,8 @@ void *bed_read(const char *fn) // Add begin,end to the list if (p->n == p->m) { - p->m = p->m? p->m<<1 : 4; - p->a = realloc(p->a, p->m * 8); + p->m = p->m ? p->m<<1 : 4; + p->a = realloc(p->a, p->m * sizeof(uint64_t)); if (NULL == p->a) goto fail; } p->a[p->n++] = (uint64_t)beg<<32 | end; @@ -234,6 +321,7 @@ void *bed_read(const char *fn) gzclose(fp); free(str.s); bed_index(h); + //bed_unify(h); return h; fail: fprintf(stderr, "[bed_read] Error reading %s : %s\n", fn, strerror(errno)); @@ -247,8 +335,13 @@ void *bed_read(const char *fn) void bed_destroy(void *_h) { - reghash_t *h = (reghash_t*)_h; + reghash_t *h; khint_t k; + + if (!_h) + return; + + h = (reghash_t*)_h; for (k = 0; k < kh_end(h); ++k) { if (kh_exist(h, k)) { free(kh_val(h, k).a); @@ -258,3 +351,250 @@ void bed_destroy(void *_h) } kh_destroy(reg, h); } + +static void *bed_insert(void *reg_hash, char *reg, unsigned int beg, unsigned int end) { + + reghash_t *h; + khint_t k; + bed_reglist_t *p; + + if (!reg_hash) + return NULL; + + h = (reghash_t *)reg_hash; + + // Put reg in the hash table if not already there + k = kh_get(reg, h, reg); //looks strange, but only the second reg is the actual region name. + if (k == kh_end(h)) { // absent from the hash table + int ret; + char *s = strdup(reg); + if (NULL == s) goto fail; + k = kh_put(reg, h, s, &ret); + if (-1 == ret) { + free(s); + goto fail; + } + memset(&kh_val(h, k), 0, sizeof(bed_reglist_t)); + } + p = &kh_val(h, k); + + // Add beg and end to the list + if (p->n == p->m) { + p->m = p->m ? p->m<<1 : 4; + p->a = realloc(p->a, p->m * sizeof(uint64_t)); + if (NULL == p->a) goto fail; + } + p->a[p->n++] = (uint64_t)beg<<32 | end; + +fail: + return h; +} + +/* @brief Filter a region hash table (coming from the BED file) by another + * region hash table (coming from CLI), so that only intervals contained in + * both hash tables are kept. + * @param reg_hash the target region hash table + * @param tmp_hash the filter region hash table + * @return pointer to the filtered hash table + */ + +static void *bed_filter(void *reg_hash, void *tmp_hash) { + + reghash_t *h; + reghash_t *t; + bed_reglist_t *p, *q; + khint_t l, k; + uint64_t *new_a; + int i, j, new_n, min_off; + const char *reg; + uint32_t beg, end; + + h = (reghash_t *)reg_hash; + t = (reghash_t *)tmp_hash; + if (!h) + return NULL; + if (!t) + return h; + + for (l = kh_begin(t); l < kh_end(t); l++) { + if (!kh_exist(t,l) || !(q = &kh_val(t,l)) || !(q->n)) + continue; + + reg = kh_key(t,l); + k = kh_get(reg, h, reg); //looks strange, but only the second reg is a proper argument. + if (k == kh_end(h) || !(p = &kh_val(h, k)) || !(p->n)) + continue; + + new_a = (uint64_t *)calloc(q->n + p->n, sizeof(uint64_t)); + if (!new_a) + return NULL; + new_n = 0; + + for (i = 0; i < q->n; i++) { + beg = (uint32_t)(q->a[i]>>32); + end = (uint32_t)(q->a[i]); + + min_off = bed_minoff(p, beg, end); + for (j = min_off; j < p->n; ++j) { + if ((uint32_t)(p->a[j]>>32) >= end) break; // out of range; no need to proceed + if ((uint32_t)(p->a[j]) > beg && (uint32_t)(p->a[j]>>32) < end) { + new_a[new_n++] = ((uint64_t)MAX((uint32_t)(p->a[j]>>32), beg) << 32) | MIN((uint32_t)p->a[j], end); + } + } + } + + if (new_n > 0) { + free(p->a); + p->a = new_a; + p->n = new_n; + p->m = new_n; + p->filter = FILTERED; + } else { + free(new_a); + p->filter = ALL; + } + } + + return h; +} + +void *bed_hash_regions(void *reg_hash, char **regs, int first, int last, int *op) { + + reghash_t *h = (reghash_t *)reg_hash; + reghash_t *t = NULL; + + int i; + char reg[1024]; + const char *q; + int beg, end; + + if (h) { + t = kh_init(reg); + if (!t) { + fprintf(stderr, "Error when creating the temporary region hash table!\n"); + return NULL; + } + } else { + h = kh_init(reg); + if (!h) { + fprintf(stderr, "Error when creating the region hash table!\n"); + return NULL; + } + *op = 1; + } + + for (i=first; i 1024) { + fprintf(stderr, "Region name '%s' is too long (bigger than %d).\n", regs[i], 1024); + continue; + } + strncpy(reg, regs[i], q - regs[i]); + reg[q - regs[i]] = 0; + } else { + // not parsable as a region, but possibly a sequence named "foo:a" + if (strlen(regs[i]) + 1 > 1024) { + fprintf(stderr, "Region name '%s' is too long (bigger than %d).\n", regs[i], 1024); + continue; + } + strcpy(reg, regs[i]); + beg = 0; end = INT_MAX; + } + + //if op==1 insert reg to the bed hash table + if (*op && !(bed_insert(h, reg, beg, end))) { + fprintf(stderr, "Error when inserting region='%s' in the bed hash table at address=%p!\n", regs[i], h); + } + //if op==0, first insert the regions in the temporary hash table, + //then filter the bed hash table using it + if (!(*op) && !(bed_insert(t, reg, beg, end))) { + fprintf(stderr, "Error when inserting region='%s' in the temporary hash table at address=%p!\n", regs[i], t); + } + } + + if (!(*op)) { + bed_index(t); + bed_unify(t); + h = bed_filter(h, t); + bed_destroy(t); + } + + if (h) { + bed_index(h); + bed_unify(h); + } + + return h; +} + +const char* bed_get(void *reg_hash, int i, int filter) { + + reghash_t *h; + bed_reglist_t *p; + + if (!reg_hash) + return NULL; + + h = (reghash_t *)reg_hash; + if (!kh_exist(h,i) || !(p = &kh_val(h,i)) || (p->filter < filter)) + return NULL; + + return kh_key(h, i); +} + +hts_reglist_t *bed_reglist(void *reg_hash, int filter, int *n_reg) { + + reghash_t *h; + bed_reglist_t *p; + khint_t i; + hts_reglist_t *reglist = NULL; + int count = 0; + int j; + + if (!reg_hash) + return NULL; + + h = (reghash_t *)reg_hash; + + for (i = kh_begin(h); i < kh_end(h); i++) { + if (!kh_exist(h,i) || !(p = &kh_val(h,i)) || (p->filter < filter)) + continue; + count++; + } + if (!count) + return NULL; + + reglist = (hts_reglist_t *)calloc(count, sizeof(hts_reglist_t)); + if (!reglist) + return NULL; + + *n_reg = count; + count = 0; + + for (i = kh_begin(h); i < kh_end(h) && count < *n_reg; i++) { + if (!kh_exist(h,i) || !(p = &kh_val(h,i)) || (p->filter < filter)) + continue; + + reglist[count].reg = kh_key(h,i); + reglist[count].intervals = (hts_pair32_t *)calloc(p->n, sizeof(hts_pair32_t)); + if(!(reglist[count].intervals)) { + hts_reglist_free(reglist, count); + return NULL; + } + reglist[count].count = p->n; + reglist[count].max_end = 0; + + for (j = 0; j < p->n; j++) { + reglist[count].intervals[j].beg = (uint32_t)(p->a[j]>>32); + reglist[count].intervals[j].end = (uint32_t)(p->a[j]); + + if (reglist[count].intervals[j].end > reglist[count].max_end) + reglist[count].max_end = reglist[count].intervals[j].end; + } + count++; + } + + return reglist; +} diff --git a/samtools/bedidx.c.pysam.c b/samtools/bedidx.c.pysam.c index 5b7df0c31..fa92fa0cc 100644 --- a/samtools/bedidx.c.pysam.c +++ b/samtools/bedidx.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* bedidx.c -- BED file indexing. @@ -33,10 +33,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include - -#ifdef _WIN32 -#define drand48() ((double)rand() / RAND_MAX) -#endif +#include "bedidx.h" #include "htslib/ksort.h" KSORT_INIT_GENERIC(uint64_t) @@ -44,48 +41,91 @@ KSORT_INIT_GENERIC(uint64_t) #include "htslib/kseq.h" KSTREAM_INIT(gzFile, gzread, 8192) +/*! @typedef + * @abstract bed_reglist_t - value type of the BED hash table + * This structure encodes the list of intervals (ranges) for the regions provided via BED file or + * command line arguments. + * @field *a pointer to the array of intervals (kept as 64 bit integers). The upper 32 bits + * encode the beginning of the interval, while the lower 32 bits encode the end, for easy sorting. + * |-- 32 bits --|-- 32 bits --| + * |---- beg ----|---- end ----| + * @field n actual number of elements contained by a + * @field m number of allocated elements to a (n <= m) + * @field *idx index array for computing the minimum offset + */ typedef struct { int n, m; uint64_t *a; int *idx; + int filter; } bed_reglist_t; #include "htslib/khash.h" KHASH_MAP_INIT_STR(reg, bed_reglist_t) -#define LIDX_SHIFT 13 - typedef kh_reg_t reghash_t; -void bed_destroy(void *_h); +#if 0 +// Debug function +static void bed_print(void *reg_hash) { + reghash_t *h = (reghash_t *)reg_hash; + bed_reglist_t *p; + khint_t k; + int i; + const char *reg; + uint32_t beg, end; + if (!h) { + fprintf(samtools_stdout, "Hash table is empty!\n"); + return; + } + for (k = kh_begin(h); k < kh_end(h); k++) { + if (kh_exist(h,k)) { + reg = kh_key(h,k); + fprintf(samtools_stdout, "Region: '%s'\n", reg); + if ((p = &kh_val(h,k)) != NULL && p->n > 0) { + fprintf(samtools_stdout, "Filter: %d\n", p->filter); + for (i=0; in; i++) { + beg = (uint32_t)(p->a[i]>>32); + end = (uint32_t)(p->a[i]); + + fprintf(samtools_stdout, "\tinterval[%d]: %d-%d\n",i,beg,end); + } + } else { + fprintf(samtools_stdout, "Region '%s' has no intervals!\n", reg); + } + } + } +} +#endif -int *bed_index_core(int n, uint64_t *a, int *n_idx) +static int *bed_index_core(int n, uint64_t *a) { - int i, j, m, *idx; - m = *n_idx = 0; idx = 0; + int i, j, l, *idx; + l = 0; idx = 0; for (i = 0; i < n; ++i) { int beg, end; beg = a[i]>>32 >> LIDX_SHIFT; end = ((uint32_t)a[i]) >> LIDX_SHIFT; - if (m < end + 1) { - int oldm = m; - m = end + 1; - kroundup32(m); - idx = realloc(idx, m * sizeof(int)); - for (j = oldm; j < m; ++j) idx[j] = -1; + if (l < end + 1) { + int old_l = l; + l = end + 1; + kroundup32(l); + idx = realloc(idx, l * sizeof(int)); + if (!idx) + return NULL; + + for (j = old_l; j < l; ++j) + idx[j] = -1; } - if (beg == end) { - if (idx[beg] < 0) idx[beg] = i; - } else { - for (j = beg; j <= end; ++j) - if (idx[j] < 0) idx[j] = i; - } - *n_idx = end + 1; + + for (j = beg; j < end+1; ++j) + if (idx[j] < 0) + idx[j] = i; } return idx; } -void bed_index(void *_h) +static void bed_index(void *_h) { reghash_t *h = (reghash_t*)_h; khint_t k; @@ -94,23 +134,36 @@ void bed_index(void *_h) bed_reglist_t *p = &kh_val(h, k); if (p->idx) free(p->idx); ks_introsort(uint64_t, p->n, p->a); - p->idx = bed_index_core(p->n, p->a, &p->m); + p->idx = bed_index_core(p->n, p->a); } } } -int bed_overlap_core(const bed_reglist_t *p, int beg, int end) +static int bed_minoff(const bed_reglist_t *p, unsigned int beg, unsigned int end) { + int i, min_off=0; + + if (p && p->idx) { + min_off = (beg>>LIDX_SHIFT >= p->n)? p->idx[p->n-1] : p->idx[beg>>LIDX_SHIFT]; + if (min_off < 0) { // TODO: this block can be improved, but speed should not matter too much here + int n = beg>>LIDX_SHIFT; + if (n > p->n) + n = p->n; + for (i = n - 1; i >= 0; --i) + if (p->idx[i] >= 0) + break; + min_off = i >= 0? p->idx[i] : 0; + } + } + + return min_off; +} + +static int bed_overlap_core(const bed_reglist_t *p, int beg, int end) { int i, min_off; if (p->n == 0) return 0; - min_off = (beg>>LIDX_SHIFT >= p->n)? p->idx[p->n-1] : p->idx[beg>>LIDX_SHIFT]; - if (min_off < 0) { // TODO: this block can be improved, but speed should not matter too much here - int n = beg>>LIDX_SHIFT; - if (n > p->n) n = p->n; - for (i = n - 1; i >= 0; --i) - if (p->idx[i] >= 0) break; - min_off = i >= 0? p->idx[i] : 0; - } + min_off = bed_minoff(p, beg, end); + for (i = min_off; i < p->n; ++i) { if ((int)(p->a[i]>>32) >= end) break; // out of range; no need to proceed if ((int32_t)p->a[i] > beg && (int32_t)(p->a[i]>>32) < end) @@ -129,6 +182,40 @@ int bed_overlap(const void *_h, const char *chr, int beg, int end) return bed_overlap_core(&kh_val(h, k), beg, end); } +/** @brief Trim a sorted interval list, inside a region hash table, + * by removing completely contained intervals and merging adjacent or + * overlapping intervals. + * @param reg_hash the region hash table with interval lists as values + */ + +static void bed_unify(void *reg_hash) { + + int i, j, new_n; + reghash_t *h; + bed_reglist_t *p; + + if (!reg_hash) + return; + + h = (reghash_t *)reg_hash; + + for (i = kh_begin(h); i < kh_end(h); i++) { + if (!kh_exist(h,i) || !(p = &kh_val(h,i)) || !(p->n)) + continue; + + for (new_n = 0, j = 1; j < p->n; j++) { + if ((uint32_t)p->a[new_n] < (uint32_t)(p->a[j]>>32)) { + p->a[++new_n] = p->a[j]; + } else { + if ((uint32_t)p->a[new_n] < (uint32_t)p->a[j]) + p->a[new_n] = (p->a[new_n] & 0xFFFFFFFF00000000) | (uint32_t)(p->a[j]); + } + } + + p->n = ++new_n; + } +} + /* "BED" file reader, which actually reads two different formats. BED files contain between three and nine fields per line, of which @@ -201,7 +288,7 @@ void *bed_read(const char *fn) // has called their reference "browser" or "track". if (0 == strcmp(ref, "browser")) continue; if (0 == strcmp(ref, "track")) continue; - fprintf(pysam_stderr, "[bed_read] Parse error reading %s at line %u\n", + fprintf(samtools_stderr, "[bed_read] Parse error reading %s at line %u\n", fn, line); goto fail_no_msg; } @@ -223,8 +310,8 @@ void *bed_read(const char *fn) // Add begin,end to the list if (p->n == p->m) { - p->m = p->m? p->m<<1 : 4; - p->a = realloc(p->a, p->m * 8); + p->m = p->m ? p->m<<1 : 4; + p->a = realloc(p->a, p->m * sizeof(uint64_t)); if (NULL == p->a) goto fail; } p->a[p->n++] = (uint64_t)beg<<32 | end; @@ -236,9 +323,10 @@ void *bed_read(const char *fn) gzclose(fp); free(str.s); bed_index(h); + //bed_unify(h); return h; fail: - fprintf(pysam_stderr, "[bed_read] Error reading %s : %s\n", fn, strerror(errno)); + fprintf(samtools_stderr, "[bed_read] Error reading %s : %s\n", fn, strerror(errno)); fail_no_msg: if (ks) ks_destroy(ks); if (fp) gzclose(fp); @@ -249,8 +337,13 @@ void *bed_read(const char *fn) void bed_destroy(void *_h) { - reghash_t *h = (reghash_t*)_h; + reghash_t *h; khint_t k; + + if (!_h) + return; + + h = (reghash_t*)_h; for (k = 0; k < kh_end(h); ++k) { if (kh_exist(h, k)) { free(kh_val(h, k).a); @@ -260,3 +353,250 @@ void bed_destroy(void *_h) } kh_destroy(reg, h); } + +static void *bed_insert(void *reg_hash, char *reg, unsigned int beg, unsigned int end) { + + reghash_t *h; + khint_t k; + bed_reglist_t *p; + + if (!reg_hash) + return NULL; + + h = (reghash_t *)reg_hash; + + // Put reg in the hash table if not already there + k = kh_get(reg, h, reg); //looks strange, but only the second reg is the actual region name. + if (k == kh_end(h)) { // absent from the hash table + int ret; + char *s = strdup(reg); + if (NULL == s) goto fail; + k = kh_put(reg, h, s, &ret); + if (-1 == ret) { + free(s); + goto fail; + } + memset(&kh_val(h, k), 0, sizeof(bed_reglist_t)); + } + p = &kh_val(h, k); + + // Add beg and end to the list + if (p->n == p->m) { + p->m = p->m ? p->m<<1 : 4; + p->a = realloc(p->a, p->m * sizeof(uint64_t)); + if (NULL == p->a) goto fail; + } + p->a[p->n++] = (uint64_t)beg<<32 | end; + +fail: + return h; +} + +/* @brief Filter a region hash table (coming from the BED file) by another + * region hash table (coming from CLI), so that only intervals contained in + * both hash tables are kept. + * @param reg_hash the target region hash table + * @param tmp_hash the filter region hash table + * @return pointer to the filtered hash table + */ + +static void *bed_filter(void *reg_hash, void *tmp_hash) { + + reghash_t *h; + reghash_t *t; + bed_reglist_t *p, *q; + khint_t l, k; + uint64_t *new_a; + int i, j, new_n, min_off; + const char *reg; + uint32_t beg, end; + + h = (reghash_t *)reg_hash; + t = (reghash_t *)tmp_hash; + if (!h) + return NULL; + if (!t) + return h; + + for (l = kh_begin(t); l < kh_end(t); l++) { + if (!kh_exist(t,l) || !(q = &kh_val(t,l)) || !(q->n)) + continue; + + reg = kh_key(t,l); + k = kh_get(reg, h, reg); //looks strange, but only the second reg is a proper argument. + if (k == kh_end(h) || !(p = &kh_val(h, k)) || !(p->n)) + continue; + + new_a = (uint64_t *)calloc(q->n + p->n, sizeof(uint64_t)); + if (!new_a) + return NULL; + new_n = 0; + + for (i = 0; i < q->n; i++) { + beg = (uint32_t)(q->a[i]>>32); + end = (uint32_t)(q->a[i]); + + min_off = bed_minoff(p, beg, end); + for (j = min_off; j < p->n; ++j) { + if ((uint32_t)(p->a[j]>>32) >= end) break; // out of range; no need to proceed + if ((uint32_t)(p->a[j]) > beg && (uint32_t)(p->a[j]>>32) < end) { + new_a[new_n++] = ((uint64_t)MAX((uint32_t)(p->a[j]>>32), beg) << 32) | MIN((uint32_t)p->a[j], end); + } + } + } + + if (new_n > 0) { + free(p->a); + p->a = new_a; + p->n = new_n; + p->m = new_n; + p->filter = FILTERED; + } else { + free(new_a); + p->filter = ALL; + } + } + + return h; +} + +void *bed_hash_regions(void *reg_hash, char **regs, int first, int last, int *op) { + + reghash_t *h = (reghash_t *)reg_hash; + reghash_t *t = NULL; + + int i; + char reg[1024]; + const char *q; + int beg, end; + + if (h) { + t = kh_init(reg); + if (!t) { + fprintf(samtools_stderr, "Error when creating the temporary region hash table!\n"); + return NULL; + } + } else { + h = kh_init(reg); + if (!h) { + fprintf(samtools_stderr, "Error when creating the region hash table!\n"); + return NULL; + } + *op = 1; + } + + for (i=first; i 1024) { + fprintf(samtools_stderr, "Region name '%s' is too long (bigger than %d).\n", regs[i], 1024); + continue; + } + strncpy(reg, regs[i], q - regs[i]); + reg[q - regs[i]] = 0; + } else { + // not parsable as a region, but possibly a sequence named "foo:a" + if (strlen(regs[i]) + 1 > 1024) { + fprintf(samtools_stderr, "Region name '%s' is too long (bigger than %d).\n", regs[i], 1024); + continue; + } + strcpy(reg, regs[i]); + beg = 0; end = INT_MAX; + } + + //if op==1 insert reg to the bed hash table + if (*op && !(bed_insert(h, reg, beg, end))) { + fprintf(samtools_stderr, "Error when inserting region='%s' in the bed hash table at address=%p!\n", regs[i], h); + } + //if op==0, first insert the regions in the temporary hash table, + //then filter the bed hash table using it + if (!(*op) && !(bed_insert(t, reg, beg, end))) { + fprintf(samtools_stderr, "Error when inserting region='%s' in the temporary hash table at address=%p!\n", regs[i], t); + } + } + + if (!(*op)) { + bed_index(t); + bed_unify(t); + h = bed_filter(h, t); + bed_destroy(t); + } + + if (h) { + bed_index(h); + bed_unify(h); + } + + return h; +} + +const char* bed_get(void *reg_hash, int i, int filter) { + + reghash_t *h; + bed_reglist_t *p; + + if (!reg_hash) + return NULL; + + h = (reghash_t *)reg_hash; + if (!kh_exist(h,i) || !(p = &kh_val(h,i)) || (p->filter < filter)) + return NULL; + + return kh_key(h, i); +} + +hts_reglist_t *bed_reglist(void *reg_hash, int filter, int *n_reg) { + + reghash_t *h; + bed_reglist_t *p; + khint_t i; + hts_reglist_t *reglist = NULL; + int count = 0; + int j; + + if (!reg_hash) + return NULL; + + h = (reghash_t *)reg_hash; + + for (i = kh_begin(h); i < kh_end(h); i++) { + if (!kh_exist(h,i) || !(p = &kh_val(h,i)) || (p->filter < filter)) + continue; + count++; + } + if (!count) + return NULL; + + reglist = (hts_reglist_t *)calloc(count, sizeof(hts_reglist_t)); + if (!reglist) + return NULL; + + *n_reg = count; + count = 0; + + for (i = kh_begin(h); i < kh_end(h) && count < *n_reg; i++) { + if (!kh_exist(h,i) || !(p = &kh_val(h,i)) || (p->filter < filter)) + continue; + + reglist[count].reg = kh_key(h,i); + reglist[count].intervals = (hts_pair32_t *)calloc(p->n, sizeof(hts_pair32_t)); + if(!(reglist[count].intervals)) { + hts_reglist_free(reglist, count); + return NULL; + } + reglist[count].count = p->n; + reglist[count].max_end = 0; + + for (j = 0; j < p->n; j++) { + reglist[count].intervals[j].beg = (uint32_t)(p->a[j]>>32); + reglist[count].intervals[j].end = (uint32_t)(p->a[j]); + + if (reglist[count].intervals[j].end > reglist[count].max_end) + reglist[count].max_end = reglist[count].intervals[j].end; + } + count++; + } + + return reglist; +} diff --git a/samtools/bedidx.h b/samtools/bedidx.h new file mode 100644 index 000000000..a33a65f2e --- /dev/null +++ b/samtools/bedidx.h @@ -0,0 +1,20 @@ +#ifndef BEDIDX_H +#define BEDIDX_H + +#include "htslib/hts.h" + +#define LIDX_SHIFT 13 +#define ALL 0 +#define FILTERED 1 + +#define MIN(A,B) ( ( (A) < (B) ) ? (A) : (B) ) +#define MAX(A,B) ( ( (A) > (B) ) ? (A) : (B) ) + +void *bed_read(const char *fn); +void bed_destroy(void *_h); +int bed_overlap(const void *_h, const char *chr, int beg, int end); +void *bed_hash_regions(void *reg_hash, char **regs, int first, int last, int *op); +const char* bed_get(void *reg_hash, int index, int filter); +hts_reglist_t *bed_reglist(void *reg_hash, int filter, int *count_regs); + +#endif diff --git a/samtools/cut_target.c b/samtools/cut_target.c index 71a6c8538..6348a0aad 100644 --- a/samtools/cut_target.c +++ b/samtools/cut_target.c @@ -1,7 +1,7 @@ /* cut_target.c -- targetcut subcommand. Copyright (C) 2011 Broad Institute. - Copyright (C) 2012-2013, 2015 Genome Research Ltd. + Copyright (C) 2012-2013, 2015, 2016 Genome Research Ltd. Author: Heng Li @@ -28,9 +28,10 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include "htslib/hts.h" #include "htslib/sam.h" -#include "errmod.h" #include "htslib/faidx.h" +#include "samtools.h" #include "sam_opts.h" #define ERR_DEP 0.83 @@ -122,7 +123,7 @@ static void process_cns(bam_hdr_t *h, int tid, int l, uint16_t *cns) s = b[i]>>s&1; } // print - for (i = 0, s = -1; i <= l; ++i) { + for (i = 0, s = -1; i < INT_MAX && i <= l; ++i) { if (i == l || ((b[i]>>2&3) == 0 && s >= 0)) { if (s >= 0) { int j; @@ -146,7 +147,6 @@ static void process_cns(bam_hdr_t *h, int tid, int l, uint16_t *cns) static int read_aln(void *data, bam1_t *b) { - extern int bam_prob_realn_core(bam1_t *b, const char *ref, int ref_len, int flag); ct_t *g = (ct_t*)data; int ret; while (1) @@ -160,7 +160,7 @@ static int read_aln(void *data, bam1_t *b) g->ref = fai_fetch(g->fai, g->h->target_name[b->core.tid], &g->len); g->tid = b->core.tid; } - bam_prob_realn_core(b, g->ref, g->len, 1<<1|1); + sam_prob_realn(b, g->ref, g->len, 1<<1|1); } break; } @@ -177,7 +177,7 @@ int main_cut_target(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 'f'), + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 'f', '-'), { NULL, 0, NULL, 0 } }; @@ -201,14 +201,19 @@ int main_cut_target(int argc, char *argv[]) } if (usage || argc == optind) { fprintf(stderr, "Usage: samtools targetcut [-Q minQ] [-i inPen] [-0 em0] [-1 em1] [-2 em2] \n"); - sam_global_opt_help(stderr, "-.--f"); + sam_global_opt_help(stderr, "-.--f-"); return 1; } l = max_l = 0; cns = 0; g.fp = sam_open_format(argv[optind], "r", &ga.in); + if (g.fp == NULL) { + print_error_errno("targetcut", "can't open \"%s\"", argv[optind]); + return 1; + } + g.h = sam_hdr_read(g.fp); if (g.h == NULL) { - fprintf(stderr, "Couldn't read header for '%s'\n", argv[optind]); + print_error("targetcut", "couldn't read header for \"%s\"", argv[optind]); sam_close(g.fp); return 1; } diff --git a/samtools/cut_target.c.pysam.c b/samtools/cut_target.c.pysam.c index 82a4c4c04..a15677329 100644 --- a/samtools/cut_target.c.pysam.c +++ b/samtools/cut_target.c.pysam.c @@ -1,9 +1,9 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* cut_target.c -- targetcut subcommand. Copyright (C) 2011 Broad Institute. - Copyright (C) 2012-2013, 2015 Genome Research Ltd. + Copyright (C) 2012-2013, 2015, 2016 Genome Research Ltd. Author: Heng Li @@ -30,9 +30,10 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include "htslib/hts.h" #include "htslib/sam.h" -#include "errmod.h" #include "htslib/faidx.h" +#include "samtools.h" #include "sam_opts.h" #define ERR_DEP 0.83 @@ -124,22 +125,22 @@ static void process_cns(bam_hdr_t *h, int tid, int l, uint16_t *cns) s = b[i]>>s&1; } // print - for (i = 0, s = -1; i <= l; ++i) { + for (i = 0, s = -1; i < INT_MAX && i <= l; ++i) { if (i == l || ((b[i]>>2&3) == 0 && s >= 0)) { if (s >= 0) { int j; - fprintf(pysam_stdout, "%s:%d-%d\t0\t%s\t%d\t60\t%dM\t*\t0\t0\t", h->target_name[tid], s+1, i, h->target_name[tid], s+1, i-s); + fprintf(samtools_stdout, "%s:%d-%d\t0\t%s\t%d\t60\t%dM\t*\t0\t0\t", h->target_name[tid], s+1, i, h->target_name[tid], s+1, i-s); for (j = s; j < i; ++j) { int c = cns[j]>>8; - if (c == 0) fputc('N', pysam_stdout); - else fputc("ACGT"[c&3], pysam_stdout); + if (c == 0) fputc('N', samtools_stdout); + else fputc("ACGT"[c&3], samtools_stdout); } - fputc('\t', pysam_stdout); + fputc('\t', samtools_stdout); for (j = s; j < i; ++j) - fputc(33 + (cns[j]>>8>>2), pysam_stdout); - fputc('\n', pysam_stdout); + fputc(33 + (cns[j]>>8>>2), samtools_stdout); + fputc('\n', samtools_stdout); } - //if (s >= 0) fprintf(pysam_stdout, "%s\t%d\t%d\t%d\n", h->target_name[tid], s, i, i - s); + //if (s >= 0) fprintf(samtools_stdout, "%s\t%d\t%d\t%d\n", h->target_name[tid], s, i, i - s); s = -1; } else if ((b[i]>>2&3) && s < 0) s = i; } @@ -148,7 +149,6 @@ static void process_cns(bam_hdr_t *h, int tid, int l, uint16_t *cns) static int read_aln(void *data, bam1_t *b) { - extern int bam_prob_realn_core(bam1_t *b, const char *ref, int ref_len, int flag); ct_t *g = (ct_t*)data; int ret; while (1) @@ -162,7 +162,7 @@ static int read_aln(void *data, bam1_t *b) g->ref = fai_fetch(g->fai, g->h->target_name[b->core.tid], &g->len); g->tid = b->core.tid; } - bam_prob_realn_core(b, g->ref, g->len, 1<<1|1); + sam_prob_realn(b, g->ref, g->len, 1<<1|1); } break; } @@ -179,7 +179,7 @@ int main_cut_target(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 'f'), + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 'f', '-'), { NULL, 0, NULL, 0 } }; @@ -199,18 +199,23 @@ int main_cut_target(int argc, char *argv[]) } if (ga.reference) { g.fai = fai_load(ga.reference); - if (g.fai == 0) fprintf(pysam_stderr, "[%s] fail to load the fasta index.\n", __func__); + if (g.fai == 0) fprintf(samtools_stderr, "[%s] fail to load the fasta index.\n", __func__); } if (usage || argc == optind) { - fprintf(pysam_stderr, "Usage: samtools targetcut [-Q minQ] [-i inPen] [-0 em0] [-1 em1] [-2 em2] \n"); - sam_global_opt_help(pysam_stderr, "-.--f"); + fprintf(samtools_stderr, "Usage: samtools targetcut [-Q minQ] [-i inPen] [-0 em0] [-1 em1] [-2 em2] \n"); + sam_global_opt_help(samtools_stderr, "-.--f-"); return 1; } l = max_l = 0; cns = 0; g.fp = sam_open_format(argv[optind], "r", &ga.in); + if (g.fp == NULL) { + print_error_errno("targetcut", "can't open \"%s\"", argv[optind]); + return 1; + } + g.h = sam_hdr_read(g.fp); if (g.h == NULL) { - fprintf(pysam_stderr, "Couldn't read header for '%s'\n", argv[optind]); + print_error("targetcut", "couldn't read header for \"%s\"", argv[optind]); sam_close(g.fp); return 1; } diff --git a/samtools/dict.c b/samtools/dict.c index fa64a161c..7321a7741 100644 --- a/samtools/dict.c +++ b/samtools/dict.c @@ -71,8 +71,8 @@ static void write_dict(const char *fn, args_t *args) if (args->header) fprintf(out, "@HD\tVN:1.0\tSO:unsorted\n"); while ((l = kseq_read(seq)) >= 0) { for (i = k = 0; i < seq->seq.l; ++i) { - if (islower(seq->seq.s[i])) seq->seq.s[k++] = toupper(seq->seq.s[i]); - else if (isupper(seq->seq.s[i])) seq->seq.s[k++] = seq->seq.s[i]; + if (seq->seq.s[i] >= '!' && seq->seq.s[i] <= '~') + seq->seq.s[k++] = toupper(seq->seq.s[i]); } hts_md5_reset(md5); hts_md5_update(md5, (unsigned char*)seq->seq.s, k); @@ -82,7 +82,11 @@ static void write_dict(const char *fn, args_t *args) if (args->uri) fprintf(out, "\tUR:%s", args->uri); else if (strcmp(fn, "-") != 0) { +#ifdef _WIN32 + char *real_path = _fullpath(NULL, fn, PATH_MAX); +#else char *real_path = realpath(fn, NULL); +#endif fprintf(out, "\tUR:file://%s", real_path); free(real_path); } diff --git a/samtools/dict.c.pysam.c b/samtools/dict.c.pysam.c index 53688518d..f42e41608 100644 --- a/samtools/dict.c.pysam.c +++ b/samtools/dict.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* dict.c -- create a sequence dictionary file. @@ -54,14 +54,14 @@ static void write_dict(const char *fn, args_t *args) fp = strcmp(fn, "-") ? gzopen(fn, "r") : gzdopen(fileno(stdin), "r"); if (fp == 0) { - fprintf(pysam_stderr, "dict: %s: No such file or directory\n", fn); + fprintf(samtools_stderr, "dict: %s: No such file or directory\n", fn); exit(1); } - FILE *out = pysam_stdout; + FILE *out = samtools_stdout; if (args->output_fname) { out = fopen(args->output_fname, "w"); if (out == NULL) { - fprintf(pysam_stderr, "dict: %s: Cannot open file for writing\n", args->output_fname); + fprintf(samtools_stderr, "dict: %s: Cannot open file for writing\n", args->output_fname); exit(1); } } @@ -73,8 +73,8 @@ static void write_dict(const char *fn, args_t *args) if (args->header) fprintf(out, "@HD\tVN:1.0\tSO:unsorted\n"); while ((l = kseq_read(seq)) >= 0) { for (i = k = 0; i < seq->seq.l; ++i) { - if (islower(seq->seq.s[i])) seq->seq.s[k++] = toupper(seq->seq.s[i]); - else if (isupper(seq->seq.s[i])) seq->seq.s[k++] = seq->seq.s[i]; + if (seq->seq.s[i] >= '!' && seq->seq.s[i] <= '~') + seq->seq.s[k++] = toupper(seq->seq.s[i]); } hts_md5_reset(md5); hts_md5_update(md5, (unsigned char*)seq->seq.s, k); @@ -84,7 +84,11 @@ static void write_dict(const char *fn, args_t *args) if (args->uri) fprintf(out, "\tUR:%s", args->uri); else if (strcmp(fn, "-") != 0) { +#ifdef _WIN32 + char *real_path = _fullpath(NULL, fn, PATH_MAX); +#else char *real_path = realpath(fn, NULL); +#endif fprintf(out, "\tUR:file://%s", real_path); free(real_path); } @@ -100,15 +104,15 @@ static void write_dict(const char *fn, args_t *args) static int dict_usage(void) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "About: Create a sequence dictionary file from a fasta file\n"); - fprintf(pysam_stderr, "Usage: samtools dict [options] \n\n"); - fprintf(pysam_stderr, "Options: -a, --assembly STR assembly\n"); - fprintf(pysam_stderr, " -H, --no-header do not print @HD line\n"); - fprintf(pysam_stderr, " -o, --output STR file to write out dict file [pysam_stdout]\n"); - fprintf(pysam_stderr, " -s, --species STR species\n"); - fprintf(pysam_stderr, " -u, --uri STR URI [file:///abs/path/to/file.fa]\n"); - fprintf(pysam_stderr, "\n"); + fprintf(samtools_stderr, "\n"); + fprintf(samtools_stderr, "About: Create a sequence dictionary file from a fasta file\n"); + fprintf(samtools_stderr, "Usage: samtools dict [options] \n\n"); + fprintf(samtools_stderr, "Options: -a, --assembly STR assembly\n"); + fprintf(samtools_stderr, " -H, --no-header do not print @HD line\n"); + fprintf(samtools_stderr, " -o, --output STR file to write out dict file [samtools_stdout]\n"); + fprintf(samtools_stderr, " -s, --species STR species\n"); + fprintf(samtools_stderr, " -u, --uri STR URI [file:///abs/path/to/file.fa]\n"); + fprintf(samtools_stderr, "\n"); return 1; } diff --git a/samtools/errmod.c.pysam.c b/samtools/errmod.c.pysam.c deleted file mode 100644 index 12176cf78..000000000 --- a/samtools/errmod.c.pysam.c +++ /dev/null @@ -1,196 +0,0 @@ -#include "pysam.h" - -/* errmod.c -- revised MAQ error model. - - Copyright (C) 2010 Broad Institute. - Copyright (C) 2012, 2013 Genome Research Ltd. - - Author: Heng Li - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. */ - -#include - -#include -#include "errmod.h" -#include "htslib/ksort.h" -KSORT_INIT_GENERIC(uint16_t) - -/* table of constants generated for given depcorr and eta */ -typedef struct __errmod_coef_t { - double *fk, *beta, *lhet; -} errmod_coef_t; - -typedef struct { - double fsum[16], bsum[16]; - uint32_t c[16]; -} call_aux_t; - -/* \Gamma(n) = (n-1)! */ -#define lfact(n) lgamma(n+1) - -/* generates a success * trials table of bionomial probability densities (log transformed) */ -static double* logbinomial_table( const int n_size ) -{ - /* prob distribution for binom var is p(k) = {n! \over k! (n-k)! } p^k (1-p)^{n-k} */ - /* this calcs p(k) = {log(n!) - log(k!) - log((n-k)!) */ - int k, n; - double *logbinom = (double*)calloc(n_size * n_size, sizeof(double)); - for (n = 1; n < n_size; ++n) { - double lfn = lfact(n); - for (k = 1; k <= n; ++k) - logbinom[n<<8|k] = lfn - lfact(k) - lfact(n-k); - } - return logbinom; -} - -static errmod_coef_t *cal_coef(double depcorr, double eta) -{ - int k, n, q; - long double sum, sum1; - double *lC; - errmod_coef_t *ec; - - ec = calloc(1, sizeof(errmod_coef_t)); - // initialize ->fk - ec->fk = (double*)calloc(256, sizeof(double)); - ec->fk[0] = 1.0; - for (n = 1; n < 256; ++n) - ec->fk[n] = pow(1. - depcorr, n) * (1.0 - eta) + eta; - // initialize ->coef - ec->beta = (double*)calloc(256 * 256 * 64, sizeof(double)); - - lC = logbinomial_table( 256 ); - - for (q = 1; q < 64; ++q) { - double e = pow(10.0, -q/10.0); - double le = log(e); - double le1 = log(1.0 - e); - for (n = 1; n <= 255; ++n) { - double *beta = ec->beta + (q<<16|n<<8); - sum1 = sum = 0.0; - for (k = n; k >= 0; --k, sum1 = sum) { - sum = sum1 + expl(lC[n<<8|k] + k*le + (n-k)*le1); - beta[k] = -10. / M_LN10 * logl(sum1 / sum); - } - } - } - // initialize ->lhet - ec->lhet = (double*)calloc(256 * 256, sizeof(double)); - for (n = 0; n < 256; ++n) - for (k = 0; k < 256; ++k) - ec->lhet[n<<8|k] = lC[n<<8|k] - M_LN2 * n; - free(lC); - return ec; -} - -/** - * Create errmod_t object with obj.depcorr set to depcorr and initialise - */ -errmod_t *errmod_init(double depcorr) -{ - errmod_t *em; - em = (errmod_t*)calloc(1, sizeof(errmod_t)); - em->depcorr = depcorr; - em->coef = cal_coef(depcorr, 0.03); - return em; -} - -/** - * Deallocate an errmod_t object - */ -void errmod_destroy(errmod_t *em) -{ - if (em == 0) return; - free(em->coef->lhet); free(em->coef->fk); free(em->coef->beta); - free(em->coef); free(em); -} - -// -// em: error model to fit to data -// m: number of alleles across all samples -// n: number of bases observed in sample -// bases[i]: bases observed in pileup [6 bit quality|1 bit strand|4 bit base] -// q[i*m+j]: (Output) phred-scaled likelihood of each genotype (i,j) -int errmod_cal(const errmod_t *em, int n, int m, uint16_t *bases, float *q) -{ - // Aux - // aux.c is total count of each base observed (ignoring strand) - call_aux_t aux; - // Loop variables - int i, j, k; - // The total count of each base observed per strand - int w[32]; - - memset(q, 0, m * m * sizeof(float)); // initialise q to 0 - if (n == 0) return 0; - // This section randomly downsamples to 255 depth so as not to go beyond our precalculated matrix - if (n > 255) { // if we exceed 255 bases observed then shuffle them to sample and only keep the first 255 - ks_shuffle(uint16_t, n, bases); - n = 255; - } - ks_introsort(uint16_t, n, bases); - /* zero out w and aux */ - memset(w, 0, 32 * sizeof(int)); - memset(&aux, 0, sizeof(call_aux_t)); - - for (j = n - 1; j >= 0; --j) { // calculate esum and fsum - uint16_t b = bases[j]; - /* extract quality and cap at 63 */ - int qual = b>>5 < 4? 4 : b>>5; - if (qual > 63) qual = 63; - /* extract base ORed with strand */ - int basestrand = b&0x1f; - /* extract base */ - int base = b&0xf; - aux.fsum[base] += em->coef->fk[w[basestrand]]; - aux.bsum[base] += em->coef->fk[w[basestrand]] * em->coef->beta[qual<<16|n<<8|aux.c[base]]; - ++aux.c[base]; - ++w[basestrand]; - } - - // generate likelihood - for (j = 0; j < m; ++j) { - float tmp1, tmp3; - int tmp2; - // homozygous - for (k = 0, tmp1 = tmp3 = 0.0, tmp2 = 0; k < m; ++k) { - if (k == j) continue; - tmp1 += aux.bsum[k]; tmp2 += aux.c[k]; tmp3 += aux.fsum[k]; - } - if (tmp2) { - q[j*m+j] = tmp1; - } - // heterozygous - for (k = j + 1; k < m; ++k) { - int cjk = aux.c[j] + aux.c[k]; - for (i = 0, tmp2 = 0, tmp1 = tmp3 = 0.0; i < m; ++i) { - if (i == j || i == k) continue; - tmp1 += aux.bsum[i]; tmp2 += aux.c[i]; tmp3 += aux.fsum[i]; - } - if (tmp2) { - q[j*m+k] = q[k*m+j] = -4.343 * em->coef->lhet[cjk<<8|aux.c[k]] + tmp1; - } else q[j*m+k] = q[k*m+j] = -4.343 * em->coef->lhet[cjk<<8|aux.c[k]]; // all the bases are either j or k - } - /* clamp to greater than 0 */ - for (k = 0; k < m; ++k) if (q[j*m+k] < 0.0) q[j*m+k] = 0.0; - } - - return 0; -} diff --git a/samtools/faidx.c b/samtools/faidx.c index 336bde5eb..c5c9ed635 100644 --- a/samtools/faidx.c +++ b/samtools/faidx.c @@ -1,6 +1,6 @@ /* faidx.c -- faidx subcommand. - Copyright (C) 2008, 2009, 2013 Genome Research Ltd. + Copyright (C) 2008, 2009, 2013, 2016 Genome Research Ltd. Portions copyright (C) 2011 Broad Institute. Author: Heng Li @@ -25,34 +25,19 @@ DEALINGS IN THE SOFTWARE. */ #include -#include -#include #include #include -#include #include -#include + #include +#include "samtools.h" -static void error(const char *format, ...) +static int usage(FILE *fp, int exit_status) { - if ( format ) - { - va_list ap; - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); - } - else - { - fprintf(stderr, "\n"); - fprintf(stderr, "Usage: samtools faidx [ [...]]\n"); - fprintf(stderr, "\n"); - } - exit(-1); + fprintf(fp, "Usage: samtools faidx [ [...]]\n"); + return exit_status; } - int faidx_main(int argc, char *argv[]) { int c; @@ -61,39 +46,60 @@ int faidx_main(int argc, char *argv[]) switch(c) { case 'h': + return usage(stdout, EXIT_SUCCESS); + default: - error(NULL); + return usage(stderr, EXIT_FAILURE); } } if ( argc==optind ) - error(NULL); + return usage(stdout, EXIT_SUCCESS); if ( argc==2 ) { if (fai_build(argv[optind]) != 0) { - error("Could not build fai index %s.fai\n", argv[optind]); + fprintf(stderr, "Could not build fai index %s.fai\n", argv[optind]); + return EXIT_FAILURE; } return 0; } faidx_t *fai = fai_load(argv[optind]); - if ( !fai ) error("Could not load fai index of %s\n", argv[optind]); + if ( !fai ) { + fprintf(stderr, "Could not load fai index of %s\n", argv[optind]); + return EXIT_FAILURE; + } + + int exit_status = EXIT_SUCCESS; - while ( ++optind%s\n", argv[optind]); - int i, j, seq_len; + int seq_len; char *seq = fai_fetch(fai, argv[optind], &seq_len); - if ( seq_len < 0 ) error("Failed to fetch sequence in %s\n", argv[optind]); - for (i=0; i @@ -27,34 +27,19 @@ DEALINGS IN THE SOFTWARE. */ #include -#include -#include #include #include -#include #include -#include + #include +#include "samtools.h" -static void error(const char *format, ...) +static int usage(FILE *fp, int exit_status) { - if ( format ) - { - va_list ap; - va_start(ap, format); - vfprintf(pysam_stderr, format, ap); - va_end(ap); - } - else - { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Usage: samtools faidx [ [...]]\n"); - fprintf(pysam_stderr, "\n"); - } - exit(-1); + fprintf(fp, "Usage: samtools faidx [ [...]]\n"); + return exit_status; } - int faidx_main(int argc, char *argv[]) { int c; @@ -63,39 +48,60 @@ int faidx_main(int argc, char *argv[]) switch(c) { case 'h': + return usage(samtools_stdout, EXIT_SUCCESS); + default: - error(NULL); + return usage(samtools_stderr, EXIT_FAILURE); } } if ( argc==optind ) - error(NULL); + return usage(samtools_stdout, EXIT_SUCCESS); if ( argc==2 ) { if (fai_build(argv[optind]) != 0) { - error("Could not build fai index %s.fai\n", argv[optind]); + fprintf(samtools_stderr, "Could not build fai index %s.fai\n", argv[optind]); + return EXIT_FAILURE; } return 0; } faidx_t *fai = fai_load(argv[optind]); - if ( !fai ) error("Could not load fai index of %s\n", argv[optind]); + if ( !fai ) { + fprintf(samtools_stderr, "Could not load fai index of %s\n", argv[optind]); + return EXIT_FAILURE; + } + + int exit_status = EXIT_SUCCESS; - while ( ++optind%s\n", argv[optind]); - int i, j, seq_len; + fprintf(samtools_stdout, ">%s\n", argv[optind]); + int seq_len; char *seq = fai_fetch(fai, argv[optind], &seq_len); - if ( seq_len < 0 ) error("Failed to fetch sequence in %s\n", argv[optind]); - for (i=0; i - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#include - -#include -#include -#include -#include -#include -#include "kprobaln.h" - -/***************************************** - * Probabilistic banded glocal alignment * - *****************************************/ - -#define EI .25 -#define EM .33333333333 - -static float g_qual2prob[256]; - -#define set_u(u, b, i, k) { int x=(i)-(b); x=x>0?x:0; (u)=((k)-x+1)*3; } - -kpa_par_t kpa_par_def = { 0.001, 0.1, 10 }; -kpa_par_t kpa_par_alt = { 0.0001, 0.01, 10 }; - -/* - The topology of the profile HMM: - - /\ /\ /\ /\ - I[1] I[k-1] I[k] I[L] - ^ \ \ ^ \ ^ \ \ ^ - | \ \ | \ | \ \ | - M[0] M[1] -> ... -> M[k-1] -> M[k] -> ... -> M[L] M[L+1] - \ \/ \/ \/ / - \ /\ /\ /\ / - -> D[k-1] -> D[k] -> - - M[0] points to every {M,I}[k] and every {M,I}[k] points M[L+1]. - - On input, _ref is the reference sequence and _query is the query - sequence. Both are sequences of 0/1/2/3/4 where 4 stands for an - ambiguous residue. iqual is the base quality. c sets the gap open - probability, gap extension probability and band width. - - On output, state and q are arrays of length l_query. The higher 30 - bits give the reference position the query base is matched to and the - lower two bits can be 0 (an alignment match) or 1 (an - insertion). q[i] gives the phred scaled posterior probability of - state[i] being wrong. - */ -int kpa_glocal(const uint8_t *_ref, int l_ref, const uint8_t *_query, int l_query, const uint8_t *iqual, - const kpa_par_t *c, int *state, uint8_t *q) -{ - double **f, **b = 0, *s, m[9], sI, sM, bI, bM, pb; - float *qual, *_qual; - const uint8_t *ref, *query; - int bw, bw2, i, k, is_diff = 0, is_backward = 1, Pr; - - if ( l_ref<=0 || l_query<=0 ) return 0; // FIXME: this may not be an ideal fix, just prevents sefgault - - /*** initialization ***/ - is_backward = state && q? 1 : 0; - ref = _ref - 1; query = _query - 1; // change to 1-based coordinate - bw = l_ref > l_query? l_ref : l_query; - if (bw > c->bw) bw = c->bw; - if (bw < abs(l_ref - l_query)) bw = abs(l_ref - l_query); - bw2 = bw * 2 + 1; - // allocate the forward and backward matrices f[][] and b[][] and the scaling array s[] - f = calloc(l_query+1, sizeof(double*)); - if (is_backward) b = calloc(l_query+1, sizeof(double*)); - for (i = 0; i <= l_query; ++i) { // FIXME: this will lead in segfault for l_query==0 - f[i] = calloc(bw2 * 3 + 6, sizeof(double)); // FIXME: this is over-allocated for very short seqs - if (is_backward) b[i] = calloc(bw2 * 3 + 6, sizeof(double)); - } - s = calloc(l_query+2, sizeof(double)); // s[] is the scaling factor to avoid underflow - // initialize qual - _qual = calloc(l_query, sizeof(float)); - if (g_qual2prob[0] == 0) - for (i = 0; i < 256; ++i) - g_qual2prob[i] = pow(10, -i/10.); - for (i = 0; i < l_query; ++i) _qual[i] = g_qual2prob[iqual? iqual[i] : 30]; - qual = _qual - 1; - // initialize transition probability - sM = sI = 1. / (2 * l_query + 2); // the value here seems not to affect results; FIXME: need proof - m[0*3+0] = (1 - c->d - c->d) * (1 - sM); m[0*3+1] = m[0*3+2] = c->d * (1 - sM); - m[1*3+0] = (1 - c->e) * (1 - sI); m[1*3+1] = c->e * (1 - sI); m[1*3+2] = 0.; - m[2*3+0] = 1 - c->e; m[2*3+1] = 0.; m[2*3+2] = c->e; - bM = (1 - c->d) / l_ref; bI = c->d / l_ref; // (bM+bI)*l_ref==1 - /*** forward ***/ - // f[0] - set_u(k, bw, 0, 0); - f[0][k] = s[0] = 1.; - { // f[1] - double *fi = f[1], sum; - int beg = 1, end = l_ref < bw + 1? l_ref : bw + 1, _beg, _end; - for (k = beg, sum = 0.; k <= end; ++k) { - int u; - double e = (ref[k] > 3 || query[1] > 3)? 1. : ref[k] == query[1]? 1. - qual[1] : qual[1] * EM; - set_u(u, bw, 1, k); - fi[u+0] = e * bM; fi[u+1] = EI * bI; - sum += fi[u] + fi[u+1]; - } - // rescale - s[1] = sum; - set_u(_beg, bw, 1, beg); set_u(_end, bw, 1, end); _end += 2; - for (k = _beg; k <= _end; ++k) fi[k] /= sum; - } - // f[2..l_query] - for (i = 2; i <= l_query; ++i) { - double *fi = f[i], *fi1 = f[i-1], sum, qli = qual[i]; - int beg = 1, end = l_ref, x, _beg, _end; - uint8_t qyi = query[i]; - x = i - bw; beg = beg > x? beg : x; // band start - x = i + bw; end = end < x? end : x; // band end - for (k = beg, sum = 0.; k <= end; ++k) { - int u, v11, v01, v10; - double e; - e = (ref[k] > 3 || qyi > 3)? 1. : ref[k] == qyi? 1. - qli : qli * EM; - set_u(u, bw, i, k); set_u(v11, bw, i-1, k-1); set_u(v10, bw, i-1, k); set_u(v01, bw, i, k-1); - fi[u+0] = e * (m[0] * fi1[v11+0] + m[3] * fi1[v11+1] + m[6] * fi1[v11+2]); - fi[u+1] = EI * (m[1] * fi1[v10+0] + m[4] * fi1[v10+1]); - fi[u+2] = m[2] * fi[v01+0] + m[8] * fi[v01+2]; - sum += fi[u] + fi[u+1] + fi[u+2]; -// fprintf(stderr, "F (%d,%d;%d): %lg,%lg,%lg\n", i, k, u, fi[u], fi[u+1], fi[u+2]); // DEBUG - } - // rescale - s[i] = sum; - set_u(_beg, bw, i, beg); set_u(_end, bw, i, end); _end += 2; - for (k = _beg, sum = 1./sum; k <= _end; ++k) fi[k] *= sum; - } - { // f[l_query+1] - double sum; - for (k = 1, sum = 0.; k <= l_ref; ++k) { - int u; - set_u(u, bw, l_query, k); - if (u < 3 || u >= bw2*3+3) continue; - sum += f[l_query][u+0] * sM + f[l_query][u+1] * sI; - } - s[l_query+1] = sum; // the last scaling factor - } - { // compute likelihood - double p = 1., Pr1 = 0.; - for (i = 0; i <= l_query + 1; ++i) { - p *= s[i]; - if (p < 1e-100) Pr1 += -4.343 * log(p), p = 1.; - } - Pr1 += -4.343 * log(p * l_ref * l_query); - Pr = (int)(Pr1 + .499); - if (!is_backward) { // skip backward and MAP - for (i = 0; i <= l_query; ++i) free(f[i]); - free(f); free(s); free(_qual); - return Pr; - } - } - /*** backward ***/ - // b[l_query] (b[l_query+1][0]=1 and thus \tilde{b}[][]=1/s[l_query+1]; this is where s[l_query+1] comes from) - for (k = 1; k <= l_ref; ++k) { - int u; - double *bi = b[l_query]; - set_u(u, bw, l_query, k); - if (u < 3 || u >= bw2*3+3) continue; - bi[u+0] = sM / s[l_query] / s[l_query+1]; bi[u+1] = sI / s[l_query] / s[l_query+1]; - } - // b[l_query-1..1] - for (i = l_query - 1; i >= 1; --i) { - int beg = 1, end = l_ref, x, _beg, _end; - double *bi = b[i], *bi1 = b[i+1], y = (i > 1), qli1 = qual[i+1]; - uint8_t qyi1 = query[i+1]; - x = i - bw; beg = beg > x? beg : x; - x = i + bw; end = end < x? end : x; - for (k = end; k >= beg; --k) { - int u, v11, v01, v10; - double e; - set_u(u, bw, i, k); set_u(v11, bw, i+1, k+1); set_u(v10, bw, i+1, k); set_u(v01, bw, i, k+1); - e = (k >= l_ref? 0 : (ref[k+1] > 3 || qyi1 > 3)? 1. : ref[k+1] == qyi1? 1. - qli1 : qli1 * EM) * bi1[v11]; - bi[u+0] = e * m[0] + EI * m[1] * bi1[v10+1] + m[2] * bi[v01+2]; // bi1[v11] has been foled into e. - bi[u+1] = e * m[3] + EI * m[4] * bi1[v10+1]; - bi[u+2] = (e * m[6] + m[8] * bi[v01+2]) * y; -// fprintf(stderr, "B (%d,%d;%d): %lg,%lg,%lg\n", i, k, u, bi[u], bi[u+1], bi[u+2]); // DEBUG - } - // rescale - set_u(_beg, bw, i, beg); set_u(_end, bw, i, end); _end += 2; - for (k = _beg, y = 1./s[i]; k <= _end; ++k) bi[k] *= y; - } - { // b[0] - int beg = 1, end = l_ref < bw + 1? l_ref : bw + 1; - double sum = 0.; - for (k = end; k >= beg; --k) { - int u; - double e = (ref[k] > 3 || query[1] > 3)? 1. : ref[k] == query[1]? 1. - qual[1] : qual[1] * EM; - set_u(u, bw, 1, k); - if (u < 3 || u >= bw2*3+3) continue; - sum += e * b[1][u+0] * bM + EI * b[1][u+1] * bI; - } - set_u(k, bw, 0, 0); - pb = b[0][k] = sum / s[0]; // if everything works as is expected, pb == 1.0 - } - is_diff = fabs(pb - 1.) > 1e-7? 1 : 0; - /*** MAP ***/ - for (i = 1; i <= l_query; ++i) { - double sum = 0., *fi = f[i], *bi = b[i], max = 0.; - int beg = 1, end = l_ref, x, max_k = -1; - x = i - bw; beg = beg > x? beg : x; - x = i + bw; end = end < x? end : x; - for (k = beg; k <= end; ++k) { - int u; - double z; - set_u(u, bw, i, k); - z = fi[u+0] * bi[u+0]; if (z > max) max = z, max_k = (k-1)<<2 | 0; sum += z; - z = fi[u+1] * bi[u+1]; if (z > max) max = z, max_k = (k-1)<<2 | 1; sum += z; - } - max /= sum; sum *= s[i]; // if everything works as is expected, sum == 1.0 - if (state) state[i-1] = max_k; - if (q) k = (int)(-4.343 * log(1. - max) + .499), q[i-1] = k > 100? 99 : k; -#ifdef _MAIN - fprintf(stderr, "(%.10lg,%.10lg) (%d,%d:%c,%c:%d) %lg\n", pb, sum, i-1, max_k>>2, - "ACGT"[query[i]], "ACGT"[ref[(max_k>>2)+1]], max_k&3, max); // DEBUG -#endif - } - /*** free ***/ - for (i = 0; i <= l_query; ++i) { - free(f[i]); free(b[i]); - } - free(f); free(b); free(s); free(_qual); - return Pr; -} - -#ifdef _MAIN -#include -int main(int argc, char *argv[]) -{ - uint8_t conv[256], *iqual, *ref, *query; - int c, l_ref, l_query, i, q = 30, b = 10, P; - while ((c = getopt(argc, argv, "b:q:")) >= 0) { - switch (c) { - case 'b': b = atoi(optarg); break; - case 'q': q = atoi(optarg); break; - } - } - if (optind + 2 > argc) { - fprintf(stderr, "Usage: %s [-q %d] [-b %d] \n", argv[0], q, b); // example: acttc attc - return 1; - } - memset(conv, 4, 256); - conv['a'] = conv['A'] = 0; conv['c'] = conv['C'] = 1; - conv['g'] = conv['G'] = 2; conv['t'] = conv['T'] = 3; - ref = (uint8_t*)argv[optind]; query = (uint8_t*)argv[optind+1]; - l_ref = strlen((char*)ref); l_query = strlen((char*)query); - for (i = 0; i < l_ref; ++i) ref[i] = conv[ref[i]]; - for (i = 0; i < l_query; ++i) query[i] = conv[query[i]]; - iqual = malloc(l_query); - memset(iqual, q, l_query); - kpa_par_def.bw = b; - P = kpa_glocal(ref, l_ref, query, l_query, iqual, &kpa_par_alt, 0, 0); - fprintf(stderr, "%d\n", P); - free(iqual); - return 0; -} -#endif diff --git a/samtools/kprobaln.c.pysam.c b/samtools/kprobaln.c.pysam.c deleted file mode 100644 index 630b730e1..000000000 --- a/samtools/kprobaln.c.pysam.c +++ /dev/null @@ -1,284 +0,0 @@ -#include "pysam.h" - -/* The MIT License - - Copyright (C) 2003-2006, 2008-2010 by Heng Li - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#include - -#include -#include -#include -#include -#include -#include "kprobaln.h" - -/***************************************** - * Probabilistic banded glocal alignment * - *****************************************/ - -#define EI .25 -#define EM .33333333333 - -static float g_qual2prob[256]; - -#define set_u(u, b, i, k) { int x=(i)-(b); x=x>0?x:0; (u)=((k)-x+1)*3; } - -kpa_par_t kpa_par_def = { 0.001, 0.1, 10 }; -kpa_par_t kpa_par_alt = { 0.0001, 0.01, 10 }; - -/* - The topology of the profile HMM: - - /\ /\ /\ /\ - I[1] I[k-1] I[k] I[L] - ^ \ \ ^ \ ^ \ \ ^ - | \ \ | \ | \ \ | - M[0] M[1] -> ... -> M[k-1] -> M[k] -> ... -> M[L] M[L+1] - \ \/ \/ \/ / - \ /\ /\ /\ / - -> D[k-1] -> D[k] -> - - M[0] points to every {M,I}[k] and every {M,I}[k] points M[L+1]. - - On input, _ref is the reference sequence and _query is the query - sequence. Both are sequences of 0/1/2/3/4 where 4 stands for an - ambiguous residue. iqual is the base quality. c sets the gap open - probability, gap extension probability and band width. - - On output, state and q are arrays of length l_query. The higher 30 - bits give the reference position the query base is matched to and the - lower two bits can be 0 (an alignment match) or 1 (an - insertion). q[i] gives the phred scaled posterior probability of - state[i] being wrong. - */ -int kpa_glocal(const uint8_t *_ref, int l_ref, const uint8_t *_query, int l_query, const uint8_t *iqual, - const kpa_par_t *c, int *state, uint8_t *q) -{ - double **f, **b = 0, *s, m[9], sI, sM, bI, bM, pb; - float *qual, *_qual; - const uint8_t *ref, *query; - int bw, bw2, i, k, is_diff = 0, is_backward = 1, Pr; - - if ( l_ref<=0 || l_query<=0 ) return 0; // FIXME: this may not be an ideal fix, just prevents sefgault - - /*** initialization ***/ - is_backward = state && q? 1 : 0; - ref = _ref - 1; query = _query - 1; // change to 1-based coordinate - bw = l_ref > l_query? l_ref : l_query; - if (bw > c->bw) bw = c->bw; - if (bw < abs(l_ref - l_query)) bw = abs(l_ref - l_query); - bw2 = bw * 2 + 1; - // allocate the forward and backward matrices f[][] and b[][] and the scaling array s[] - f = calloc(l_query+1, sizeof(double*)); - if (is_backward) b = calloc(l_query+1, sizeof(double*)); - for (i = 0; i <= l_query; ++i) { // FIXME: this will lead in segfault for l_query==0 - f[i] = calloc(bw2 * 3 + 6, sizeof(double)); // FIXME: this is over-allocated for very short seqs - if (is_backward) b[i] = calloc(bw2 * 3 + 6, sizeof(double)); - } - s = calloc(l_query+2, sizeof(double)); // s[] is the scaling factor to avoid underflow - // initialize qual - _qual = calloc(l_query, sizeof(float)); - if (g_qual2prob[0] == 0) - for (i = 0; i < 256; ++i) - g_qual2prob[i] = pow(10, -i/10.); - for (i = 0; i < l_query; ++i) _qual[i] = g_qual2prob[iqual? iqual[i] : 30]; - qual = _qual - 1; - // initialize transition probability - sM = sI = 1. / (2 * l_query + 2); // the value here seems not to affect results; FIXME: need proof - m[0*3+0] = (1 - c->d - c->d) * (1 - sM); m[0*3+1] = m[0*3+2] = c->d * (1 - sM); - m[1*3+0] = (1 - c->e) * (1 - sI); m[1*3+1] = c->e * (1 - sI); m[1*3+2] = 0.; - m[2*3+0] = 1 - c->e; m[2*3+1] = 0.; m[2*3+2] = c->e; - bM = (1 - c->d) / l_ref; bI = c->d / l_ref; // (bM+bI)*l_ref==1 - /*** forward ***/ - // f[0] - set_u(k, bw, 0, 0); - f[0][k] = s[0] = 1.; - { // f[1] - double *fi = f[1], sum; - int beg = 1, end = l_ref < bw + 1? l_ref : bw + 1, _beg, _end; - for (k = beg, sum = 0.; k <= end; ++k) { - int u; - double e = (ref[k] > 3 || query[1] > 3)? 1. : ref[k] == query[1]? 1. - qual[1] : qual[1] * EM; - set_u(u, bw, 1, k); - fi[u+0] = e * bM; fi[u+1] = EI * bI; - sum += fi[u] + fi[u+1]; - } - // rescale - s[1] = sum; - set_u(_beg, bw, 1, beg); set_u(_end, bw, 1, end); _end += 2; - for (k = _beg; k <= _end; ++k) fi[k] /= sum; - } - // f[2..l_query] - for (i = 2; i <= l_query; ++i) { - double *fi = f[i], *fi1 = f[i-1], sum, qli = qual[i]; - int beg = 1, end = l_ref, x, _beg, _end; - uint8_t qyi = query[i]; - x = i - bw; beg = beg > x? beg : x; // band start - x = i + bw; end = end < x? end : x; // band end - for (k = beg, sum = 0.; k <= end; ++k) { - int u, v11, v01, v10; - double e; - e = (ref[k] > 3 || qyi > 3)? 1. : ref[k] == qyi? 1. - qli : qli * EM; - set_u(u, bw, i, k); set_u(v11, bw, i-1, k-1); set_u(v10, bw, i-1, k); set_u(v01, bw, i, k-1); - fi[u+0] = e * (m[0] * fi1[v11+0] + m[3] * fi1[v11+1] + m[6] * fi1[v11+2]); - fi[u+1] = EI * (m[1] * fi1[v10+0] + m[4] * fi1[v10+1]); - fi[u+2] = m[2] * fi[v01+0] + m[8] * fi[v01+2]; - sum += fi[u] + fi[u+1] + fi[u+2]; -// fprintf(pysam_stderr, "F (%d,%d;%d): %lg,%lg,%lg\n", i, k, u, fi[u], fi[u+1], fi[u+2]); // DEBUG - } - // rescale - s[i] = sum; - set_u(_beg, bw, i, beg); set_u(_end, bw, i, end); _end += 2; - for (k = _beg, sum = 1./sum; k <= _end; ++k) fi[k] *= sum; - } - { // f[l_query+1] - double sum; - for (k = 1, sum = 0.; k <= l_ref; ++k) { - int u; - set_u(u, bw, l_query, k); - if (u < 3 || u >= bw2*3+3) continue; - sum += f[l_query][u+0] * sM + f[l_query][u+1] * sI; - } - s[l_query+1] = sum; // the last scaling factor - } - { // compute likelihood - double p = 1., Pr1 = 0.; - for (i = 0; i <= l_query + 1; ++i) { - p *= s[i]; - if (p < 1e-100) Pr1 += -4.343 * log(p), p = 1.; - } - Pr1 += -4.343 * log(p * l_ref * l_query); - Pr = (int)(Pr1 + .499); - if (!is_backward) { // skip backward and MAP - for (i = 0; i <= l_query; ++i) free(f[i]); - free(f); free(s); free(_qual); - return Pr; - } - } - /*** backward ***/ - // b[l_query] (b[l_query+1][0]=1 and thus \tilde{b}[][]=1/s[l_query+1]; this is where s[l_query+1] comes from) - for (k = 1; k <= l_ref; ++k) { - int u; - double *bi = b[l_query]; - set_u(u, bw, l_query, k); - if (u < 3 || u >= bw2*3+3) continue; - bi[u+0] = sM / s[l_query] / s[l_query+1]; bi[u+1] = sI / s[l_query] / s[l_query+1]; - } - // b[l_query-1..1] - for (i = l_query - 1; i >= 1; --i) { - int beg = 1, end = l_ref, x, _beg, _end; - double *bi = b[i], *bi1 = b[i+1], y = (i > 1), qli1 = qual[i+1]; - uint8_t qyi1 = query[i+1]; - x = i - bw; beg = beg > x? beg : x; - x = i + bw; end = end < x? end : x; - for (k = end; k >= beg; --k) { - int u, v11, v01, v10; - double e; - set_u(u, bw, i, k); set_u(v11, bw, i+1, k+1); set_u(v10, bw, i+1, k); set_u(v01, bw, i, k+1); - e = (k >= l_ref? 0 : (ref[k+1] > 3 || qyi1 > 3)? 1. : ref[k+1] == qyi1? 1. - qli1 : qli1 * EM) * bi1[v11]; - bi[u+0] = e * m[0] + EI * m[1] * bi1[v10+1] + m[2] * bi[v01+2]; // bi1[v11] has been foled into e. - bi[u+1] = e * m[3] + EI * m[4] * bi1[v10+1]; - bi[u+2] = (e * m[6] + m[8] * bi[v01+2]) * y; -// fprintf(pysam_stderr, "B (%d,%d;%d): %lg,%lg,%lg\n", i, k, u, bi[u], bi[u+1], bi[u+2]); // DEBUG - } - // rescale - set_u(_beg, bw, i, beg); set_u(_end, bw, i, end); _end += 2; - for (k = _beg, y = 1./s[i]; k <= _end; ++k) bi[k] *= y; - } - { // b[0] - int beg = 1, end = l_ref < bw + 1? l_ref : bw + 1; - double sum = 0.; - for (k = end; k >= beg; --k) { - int u; - double e = (ref[k] > 3 || query[1] > 3)? 1. : ref[k] == query[1]? 1. - qual[1] : qual[1] * EM; - set_u(u, bw, 1, k); - if (u < 3 || u >= bw2*3+3) continue; - sum += e * b[1][u+0] * bM + EI * b[1][u+1] * bI; - } - set_u(k, bw, 0, 0); - pb = b[0][k] = sum / s[0]; // if everything works as is expected, pb == 1.0 - } - is_diff = fabs(pb - 1.) > 1e-7? 1 : 0; - /*** MAP ***/ - for (i = 1; i <= l_query; ++i) { - double sum = 0., *fi = f[i], *bi = b[i], max = 0.; - int beg = 1, end = l_ref, x, max_k = -1; - x = i - bw; beg = beg > x? beg : x; - x = i + bw; end = end < x? end : x; - for (k = beg; k <= end; ++k) { - int u; - double z; - set_u(u, bw, i, k); - z = fi[u+0] * bi[u+0]; if (z > max) max = z, max_k = (k-1)<<2 | 0; sum += z; - z = fi[u+1] * bi[u+1]; if (z > max) max = z, max_k = (k-1)<<2 | 1; sum += z; - } - max /= sum; sum *= s[i]; // if everything works as is expected, sum == 1.0 - if (state) state[i-1] = max_k; - if (q) k = (int)(-4.343 * log(1. - max) + .499), q[i-1] = k > 100? 99 : k; -#ifdef _MAIN - fprintf(pysam_stderr, "(%.10lg,%.10lg) (%d,%d:%c,%c:%d) %lg\n", pb, sum, i-1, max_k>>2, - "ACGT"[query[i]], "ACGT"[ref[(max_k>>2)+1]], max_k&3, max); // DEBUG -#endif - } - /*** free ***/ - for (i = 0; i <= l_query; ++i) { - free(f[i]); free(b[i]); - } - free(f); free(b); free(s); free(_qual); - return Pr; -} - -#ifdef _MAIN -#include -int samtools_kprobaln_main(int argc, char *argv[]) -{ - uint8_t conv[256], *iqual, *ref, *query; - int c, l_ref, l_query, i, q = 30, b = 10, P; - while ((c = getopt(argc, argv, "b:q:")) >= 0) { - switch (c) { - case 'b': b = atoi(optarg); break; - case 'q': q = atoi(optarg); break; - } - } - if (optind + 2 > argc) { - fprintf(pysam_stderr, "Usage: %s [-q %d] [-b %d] \n", argv[0], q, b); // example: acttc attc - return 1; - } - memset(conv, 4, 256); - conv['a'] = conv['A'] = 0; conv['c'] = conv['C'] = 1; - conv['g'] = conv['G'] = 2; conv['t'] = conv['T'] = 3; - ref = (uint8_t*)argv[optind]; query = (uint8_t*)argv[optind+1]; - l_ref = strlen((char*)ref); l_query = strlen((char*)query); - for (i = 0; i < l_ref; ++i) ref[i] = conv[ref[i]]; - for (i = 0; i < l_query; ++i) query[i] = conv[query[i]]; - iqual = malloc(l_query); - memset(iqual, q, l_query); - kpa_par_def.bw = b; - P = kpa_glocal(ref, l_ref, query, l_query, iqual, &kpa_par_alt, 0, 0); - fprintf(pysam_stderr, "%d\n", P); - free(iqual); - return 0; -} -#endif diff --git a/samtools/kprobaln.h b/samtools/kprobaln.h deleted file mode 100644 index 50ae77b8c..000000000 --- a/samtools/kprobaln.h +++ /dev/null @@ -1,49 +0,0 @@ -/* The MIT License - - Copyright (C) 2003-2006, 2008-2010 by Heng Li - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#ifndef LH3_KPROBALN_H_ -#define LH3_KPROBALN_H_ - -#include - -typedef struct { - float d, e; - int bw; -} kpa_par_t; - -#ifdef __cplusplus -extern "C" { -#endif - - int kpa_glocal(const uint8_t *_ref, int l_ref, const uint8_t *_query, int l_query, const uint8_t *iqual, - const kpa_par_t *c, int *state, uint8_t *q); - -#ifdef __cplusplus -} -#endif - -extern kpa_par_t kpa_par_def, kpa_par_alt; - -#endif diff --git a/samtools/lz4/LICENSE b/samtools/lz4/LICENSE new file mode 100644 index 000000000..74c2cdd7d --- /dev/null +++ b/samtools/lz4/LICENSE @@ -0,0 +1,24 @@ +LZ4 Library +Copyright (c) 2011-2016, Yann Collet +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/samtools/lz4/lz4.c b/samtools/lz4/lz4.c new file mode 100644 index 000000000..41c0a28ba --- /dev/null +++ b/samtools/lz4/lz4.c @@ -0,0 +1,1478 @@ +/* + LZ4 - Fast LZ compression algorithm + Copyright (C) 2011-2017, Yann Collet. + + BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + You can contact the author at : + - LZ4 homepage : http://www.lz4.org + - LZ4 source repository : https://github.com/lz4/lz4 +*/ + + +/*-************************************ +* Tuning parameters +**************************************/ +/* + * LZ4_HEAPMODE : + * Select how default compression functions will allocate memory for their hash table, + * in memory stack (0:default, fastest), or in memory heap (1:requires malloc()). + */ +#ifndef LZ4_HEAPMODE +# define LZ4_HEAPMODE 0 +#endif + +/* + * ACCELERATION_DEFAULT : + * Select "acceleration" for LZ4_compress_fast() when parameter value <= 0 + */ +#define ACCELERATION_DEFAULT 1 + + +/*-************************************ +* CPU Feature Detection +**************************************/ +/* LZ4_FORCE_MEMORY_ACCESS + * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable. + * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal. + * The below switch allow to select different access method for improved performance. + * Method 0 (default) : use `memcpy()`. Safe and portable. + * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable). + * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`. + * Method 2 : direct access. This method is portable but violate C standard. + * It can generate buggy code on targets which assembly generation depends on alignment. + * But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6) + * See https://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details. + * Prefer these methods in priority order (0 > 1 > 2) + */ +#ifndef LZ4_FORCE_MEMORY_ACCESS /* can be defined externally */ +# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) ) +# define LZ4_FORCE_MEMORY_ACCESS 2 +# elif defined(__INTEL_COMPILER) || defined(__GNUC__) +# define LZ4_FORCE_MEMORY_ACCESS 1 +# endif +#endif + +/* + * LZ4_FORCE_SW_BITCOUNT + * Define this parameter if your target system or compiler does not support hardware bit count + */ +#if defined(_MSC_VER) && defined(_WIN32_WCE) /* Visual Studio for Windows CE does not support Hardware bit count */ +# define LZ4_FORCE_SW_BITCOUNT +#endif + + +/*-************************************ +* Dependency +**************************************/ +#include "lz4.h" +/* see also "memory routines" below */ + + +/*-************************************ +* Compiler Options +**************************************/ +#ifdef _MSC_VER /* Visual Studio */ +# include +# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ +# pragma warning(disable : 4293) /* disable: C4293: too large shift (32-bits) */ +#endif /* _MSC_VER */ + +#ifndef FORCE_INLINE +# ifdef _MSC_VER /* Visual Studio */ +# define FORCE_INLINE static __forceinline +# else +# if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ +# ifdef __GNUC__ +# define FORCE_INLINE static inline __attribute__((always_inline)) +# else +# define FORCE_INLINE static inline +# endif +# else +# define FORCE_INLINE static +# endif /* __STDC_VERSION__ */ +# endif /* _MSC_VER */ +#endif /* FORCE_INLINE */ + +#if (defined(__GNUC__) && (__GNUC__ >= 3)) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) || defined(__clang__) +# define expect(expr,value) (__builtin_expect ((expr),(value)) ) +#else +# define expect(expr,value) (expr) +#endif + +#define likely(expr) expect((expr) != 0, 1) +#define unlikely(expr) expect((expr) != 0, 0) + + +/*-************************************ +* Memory routines +**************************************/ +#include /* malloc, calloc, free */ +#define ALLOCATOR(n,s) calloc(n,s) +#define FREEMEM free +#include /* memset, memcpy */ +#define MEM_INIT memset + + +/*-************************************ +* Basic Types +**************************************/ +#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) +# include + typedef uint8_t BYTE; + typedef uint16_t U16; + typedef uint32_t U32; + typedef int32_t S32; + typedef uint64_t U64; + typedef uintptr_t uptrval; +#else + typedef unsigned char BYTE; + typedef unsigned short U16; + typedef unsigned int U32; + typedef signed int S32; + typedef unsigned long long U64; + typedef size_t uptrval; /* generally true, except OpenVMS-64 */ +#endif + +#if defined(__x86_64__) + typedef U64 reg_t; /* 64-bits in x32 mode */ +#else + typedef size_t reg_t; /* 32-bits in x32 mode */ +#endif + +/*-************************************ +* Reading and writing into memory +**************************************/ +static unsigned LZ4_isLittleEndian(void) +{ + const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */ + return one.c[0]; +} + + +#if defined(LZ4_FORCE_MEMORY_ACCESS) && (LZ4_FORCE_MEMORY_ACCESS==2) +/* lie to the compiler about data alignment; use with caution */ + +static U16 LZ4_read16(const void* memPtr) { return *(const U16*) memPtr; } +static U32 LZ4_read32(const void* memPtr) { return *(const U32*) memPtr; } +static reg_t LZ4_read_ARCH(const void* memPtr) { return *(const reg_t*) memPtr; } + +static void LZ4_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; } +static void LZ4_write32(void* memPtr, U32 value) { *(U32*)memPtr = value; } + +#elif defined(LZ4_FORCE_MEMORY_ACCESS) && (LZ4_FORCE_MEMORY_ACCESS==1) + +/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */ +/* currently only defined for gcc and icc */ +typedef union { U16 u16; U32 u32; reg_t uArch; } __attribute__((packed)) unalign; + +static U16 LZ4_read16(const void* ptr) { return ((const unalign*)ptr)->u16; } +static U32 LZ4_read32(const void* ptr) { return ((const unalign*)ptr)->u32; } +static reg_t LZ4_read_ARCH(const void* ptr) { return ((const unalign*)ptr)->uArch; } + +static void LZ4_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; } +static void LZ4_write32(void* memPtr, U32 value) { ((unalign*)memPtr)->u32 = value; } + +#else /* safe and portable access through memcpy() */ + +static U16 LZ4_read16(const void* memPtr) +{ + U16 val; memcpy(&val, memPtr, sizeof(val)); return val; +} + +static U32 LZ4_read32(const void* memPtr) +{ + U32 val; memcpy(&val, memPtr, sizeof(val)); return val; +} + +static reg_t LZ4_read_ARCH(const void* memPtr) +{ + reg_t val; memcpy(&val, memPtr, sizeof(val)); return val; +} + +static void LZ4_write16(void* memPtr, U16 value) +{ + memcpy(memPtr, &value, sizeof(value)); +} + +static void LZ4_write32(void* memPtr, U32 value) +{ + memcpy(memPtr, &value, sizeof(value)); +} + +#endif /* LZ4_FORCE_MEMORY_ACCESS */ + + +static U16 LZ4_readLE16(const void* memPtr) +{ + if (LZ4_isLittleEndian()) { + return LZ4_read16(memPtr); + } else { + const BYTE* p = (const BYTE*)memPtr; + return (U16)((U16)p[0] + (p[1]<<8)); + } +} + +static void LZ4_writeLE16(void* memPtr, U16 value) +{ + if (LZ4_isLittleEndian()) { + LZ4_write16(memPtr, value); + } else { + BYTE* p = (BYTE*)memPtr; + p[0] = (BYTE) value; + p[1] = (BYTE)(value>>8); + } +} + +static void LZ4_copy8(void* dst, const void* src) +{ + memcpy(dst,src,8); +} + +/* customized variant of memcpy, which can overwrite up to 8 bytes beyond dstEnd */ +static void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd) +{ + BYTE* d = (BYTE*)dstPtr; + const BYTE* s = (const BYTE*)srcPtr; + BYTE* const e = (BYTE*)dstEnd; + + do { LZ4_copy8(d,s); d+=8; s+=8; } while (d=2) +# include +# define DEBUGLOG(l, ...) { \ + if (l<=LZ4_DEBUG) { \ + fprintf(stderr, __FILE__ ": "); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, " \n"); \ + } } +#else +# define DEBUGLOG(l, ...) {} /* disabled */ +#endif + + +/*-************************************ +* Common functions +**************************************/ +static unsigned LZ4_NbCommonBytes (register reg_t val) +{ + if (LZ4_isLittleEndian()) { + if (sizeof(val)==8) { +# if defined(_MSC_VER) && defined(_WIN64) && !defined(LZ4_FORCE_SW_BITCOUNT) + unsigned long r = 0; + _BitScanForward64( &r, (U64)val ); + return (int)(r>>3); +# elif (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>=3))) && !defined(LZ4_FORCE_SW_BITCOUNT) + return (__builtin_ctzll((U64)val) >> 3); +# else + static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 }; + return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58]; +# endif + } else /* 32 bits */ { +# if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT) + unsigned long r; + _BitScanForward( &r, (U32)val ); + return (int)(r>>3); +# elif (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>=3))) && !defined(LZ4_FORCE_SW_BITCOUNT) + return (__builtin_ctz((U32)val) >> 3); +# else + static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 }; + return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27]; +# endif + } + } else /* Big Endian CPU */ { + if (sizeof(val)==8) { +# if defined(_MSC_VER) && defined(_WIN64) && !defined(LZ4_FORCE_SW_BITCOUNT) + unsigned long r = 0; + _BitScanReverse64( &r, val ); + return (unsigned)(r>>3); +# elif (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>=3))) && !defined(LZ4_FORCE_SW_BITCOUNT) + return (__builtin_clzll((U64)val) >> 3); +# else + unsigned r; + if (!(val>>32)) { r=4; } else { r=0; val>>=32; } + if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; } + r += (!val); + return r; +# endif + } else /* 32 bits */ { +# if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT) + unsigned long r = 0; + _BitScanReverse( &r, (unsigned long)val ); + return (unsigned)(r>>3); +# elif (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>=3))) && !defined(LZ4_FORCE_SW_BITCOUNT) + return (__builtin_clz((U32)val) >> 3); +# else + unsigned r; + if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; } + r += (!val); + return r; +# endif + } + } +} + +#define STEPSIZE sizeof(reg_t) +static unsigned LZ4_count(const BYTE* pIn, const BYTE* pMatch, const BYTE* pInLimit) +{ + const BYTE* const pStart = pIn; + + while (likely(pIn compression run slower on incompressible data */ + + +/*-************************************ +* Local Structures and types +**************************************/ +typedef enum { notLimited = 0, limitedOutput = 1 } limitedOutput_directive; +typedef enum { byPtr, byU32, byU16 } tableType_t; + +typedef enum { noDict = 0, withPrefix64k, usingExtDict } dict_directive; +typedef enum { noDictIssue = 0, dictSmall } dictIssue_directive; + +typedef enum { endOnOutputSize = 0, endOnInputSize = 1 } endCondition_directive; +typedef enum { full = 0, partial = 1 } earlyEnd_directive; + + +/*-************************************ +* Local Utils +**************************************/ +int LZ4_versionNumber (void) { return LZ4_VERSION_NUMBER; } +const char* LZ4_versionString(void) { return LZ4_VERSION_STRING; } +int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); } +int LZ4_sizeofState() { return LZ4_STREAMSIZE; } + + +/*-****************************** +* Compression functions +********************************/ +static U32 LZ4_hash4(U32 sequence, tableType_t const tableType) +{ + if (tableType == byU16) + return ((sequence * 2654435761U) >> ((MINMATCH*8)-(LZ4_HASHLOG+1))); + else + return ((sequence * 2654435761U) >> ((MINMATCH*8)-LZ4_HASHLOG)); +} + +static U32 LZ4_hash5(U64 sequence, tableType_t const tableType) +{ + static const U64 prime5bytes = 889523592379ULL; + static const U64 prime8bytes = 11400714785074694791ULL; + const U32 hashLog = (tableType == byU16) ? LZ4_HASHLOG+1 : LZ4_HASHLOG; + if (LZ4_isLittleEndian()) + return (U32)(((sequence << 24) * prime5bytes) >> (64 - hashLog)); + else + return (U32)(((sequence >> 24) * prime8bytes) >> (64 - hashLog)); +} + +FORCE_INLINE U32 LZ4_hashPosition(const void* const p, tableType_t const tableType) +{ + if ((sizeof(reg_t)==8) && (tableType != byU16)) return LZ4_hash5(LZ4_read_ARCH(p), tableType); + return LZ4_hash4(LZ4_read32(p), tableType); +} + +static void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t const tableType, const BYTE* srcBase) +{ + switch (tableType) + { + case byPtr: { const BYTE** hashTable = (const BYTE**)tableBase; hashTable[h] = p; return; } + case byU32: { U32* hashTable = (U32*) tableBase; hashTable[h] = (U32)(p-srcBase); return; } + case byU16: { U16* hashTable = (U16*) tableBase; hashTable[h] = (U16)(p-srcBase); return; } + } +} + +FORCE_INLINE void LZ4_putPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase) +{ + U32 const h = LZ4_hashPosition(p, tableType); + LZ4_putPositionOnHash(p, h, tableBase, tableType, srcBase); +} + +static const BYTE* LZ4_getPositionOnHash(U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase) +{ + if (tableType == byPtr) { const BYTE** hashTable = (const BYTE**) tableBase; return hashTable[h]; } + if (tableType == byU32) { const U32* const hashTable = (U32*) tableBase; return hashTable[h] + srcBase; } + { const U16* const hashTable = (U16*) tableBase; return hashTable[h] + srcBase; } /* default, to ensure a return */ +} + +FORCE_INLINE const BYTE* LZ4_getPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase) +{ + U32 const h = LZ4_hashPosition(p, tableType); + return LZ4_getPositionOnHash(h, tableBase, tableType, srcBase); +} + + +/** LZ4_compress_generic() : + inlined, to ensure branches are decided at compilation time */ +FORCE_INLINE int LZ4_compress_generic( + LZ4_stream_t_internal* const cctx, + const char* const source, + char* const dest, + const int inputSize, + const int maxOutputSize, + const limitedOutput_directive outputLimited, + const tableType_t tableType, + const dict_directive dict, + const dictIssue_directive dictIssue, + const U32 acceleration) +{ + const BYTE* ip = (const BYTE*) source; + const BYTE* base; + const BYTE* lowLimit; + const BYTE* const lowRefLimit = ip - cctx->dictSize; + const BYTE* const dictionary = cctx->dictionary; + const BYTE* const dictEnd = dictionary + cctx->dictSize; + const ptrdiff_t dictDelta = dictEnd - (const BYTE*)source; + const BYTE* anchor = (const BYTE*) source; + const BYTE* const iend = ip + inputSize; + const BYTE* const mflimit = iend - MFLIMIT; + const BYTE* const matchlimit = iend - LASTLITERALS; + + BYTE* op = (BYTE*) dest; + BYTE* const olimit = op + maxOutputSize; + + U32 forwardH; + + /* Init conditions */ + if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported inputSize, too large (or negative) */ + switch(dict) + { + case noDict: + default: + base = (const BYTE*)source; + lowLimit = (const BYTE*)source; + break; + case withPrefix64k: + base = (const BYTE*)source - cctx->currentOffset; + lowLimit = (const BYTE*)source - cctx->dictSize; + break; + case usingExtDict: + base = (const BYTE*)source - cctx->currentOffset; + lowLimit = (const BYTE*)source; + break; + } + if ((tableType == byU16) && (inputSize>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ + if (inputSizehashTable, tableType, base); + ip++; forwardH = LZ4_hashPosition(ip, tableType); + + /* Main Loop */ + for ( ; ; ) { + ptrdiff_t refDelta = 0; + const BYTE* match; + BYTE* token; + + /* Find a match */ + { const BYTE* forwardIp = ip; + unsigned step = 1; + unsigned searchMatchNb = acceleration << LZ4_skipTrigger; + do { + U32 const h = forwardH; + ip = forwardIp; + forwardIp += step; + step = (searchMatchNb++ >> LZ4_skipTrigger); + + if (unlikely(forwardIp > mflimit)) goto _last_literals; + + match = LZ4_getPositionOnHash(h, cctx->hashTable, tableType, base); + if (dict==usingExtDict) { + if (match < (const BYTE*)source) { + refDelta = dictDelta; + lowLimit = dictionary; + } else { + refDelta = 0; + lowLimit = (const BYTE*)source; + } } + forwardH = LZ4_hashPosition(forwardIp, tableType); + LZ4_putPositionOnHash(ip, h, cctx->hashTable, tableType, base); + + } while ( ((dictIssue==dictSmall) ? (match < lowRefLimit) : 0) + || ((tableType==byU16) ? 0 : (match + MAX_DISTANCE < ip)) + || (LZ4_read32(match+refDelta) != LZ4_read32(ip)) ); + } + + /* Catch up */ + while (((ip>anchor) & (match+refDelta > lowLimit)) && (unlikely(ip[-1]==match[refDelta-1]))) { ip--; match--; } + + /* Encode Literals */ + { unsigned const litLength = (unsigned)(ip - anchor); + token = op++; + if ((outputLimited) && /* Check output buffer overflow */ + (unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > olimit))) + return 0; + if (litLength >= RUN_MASK) { + int len = (int)litLength-RUN_MASK; + *token = (RUN_MASK<= 255 ; len-=255) *op++ = 255; + *op++ = (BYTE)len; + } + else *token = (BYTE)(litLength< matchlimit) limit = matchlimit; + matchCode = LZ4_count(ip+MINMATCH, match+MINMATCH, limit); + ip += MINMATCH + matchCode; + if (ip==limit) { + unsigned const more = LZ4_count(ip, (const BYTE*)source, matchlimit); + matchCode += more; + ip += more; + } + } else { + matchCode = LZ4_count(ip+MINMATCH, match+MINMATCH, matchlimit); + ip += MINMATCH + matchCode; + } + + if ( outputLimited && /* Check output buffer overflow */ + (unlikely(op + (1 + LASTLITERALS) + (matchCode>>8) > olimit)) ) + return 0; + if (matchCode >= ML_MASK) { + *token += ML_MASK; + matchCode -= ML_MASK; + LZ4_write32(op, 0xFFFFFFFF); + while (matchCode >= 4*255) op+=4, LZ4_write32(op, 0xFFFFFFFF), matchCode -= 4*255; + op += matchCode / 255; + *op++ = (BYTE)(matchCode % 255); + } else + *token += (BYTE)(matchCode); + } + + anchor = ip; + + /* Test end of chunk */ + if (ip > mflimit) break; + + /* Fill table */ + LZ4_putPosition(ip-2, cctx->hashTable, tableType, base); + + /* Test next position */ + match = LZ4_getPosition(ip, cctx->hashTable, tableType, base); + if (dict==usingExtDict) { + if (match < (const BYTE*)source) { + refDelta = dictDelta; + lowLimit = dictionary; + } else { + refDelta = 0; + lowLimit = (const BYTE*)source; + } } + LZ4_putPosition(ip, cctx->hashTable, tableType, base); + if ( ((dictIssue==dictSmall) ? (match>=lowRefLimit) : 1) + && (match+MAX_DISTANCE>=ip) + && (LZ4_read32(match+refDelta)==LZ4_read32(ip)) ) + { token=op++; *token=0; goto _next_match; } + + /* Prepare next loop */ + forwardH = LZ4_hashPosition(++ip, tableType); + } + +_last_literals: + /* Encode Last Literals */ + { size_t const lastRun = (size_t)(iend - anchor); + if ( (outputLimited) && /* Check output buffer overflow */ + ((op - (BYTE*)dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize) ) + return 0; + if (lastRun >= RUN_MASK) { + size_t accumulator = lastRun - RUN_MASK; + *op++ = RUN_MASK << ML_BITS; + for(; accumulator >= 255 ; accumulator-=255) *op++ = 255; + *op++ = (BYTE) accumulator; + } else { + *op++ = (BYTE)(lastRun<internal_donotuse; + LZ4_resetStream((LZ4_stream_t*)state); + if (acceleration < 1) acceleration = ACCELERATION_DEFAULT; + + if (maxOutputSize >= LZ4_compressBound(inputSize)) { + if (inputSize < LZ4_64Klimit) + return LZ4_compress_generic(ctx, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, acceleration); + else + return LZ4_compress_generic(ctx, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noDict, noDictIssue, acceleration); + } else { + if (inputSize < LZ4_64Klimit) + return LZ4_compress_generic(ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); + else + return LZ4_compress_generic(ctx, source, dest, inputSize, maxOutputSize, limitedOutput, (sizeof(void*)==8) ? byU32 : byPtr, noDict, noDictIssue, acceleration); + } +} + + +int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) +{ +#if (LZ4_HEAPMODE) + void* ctxPtr = ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */ +#else + LZ4_stream_t ctx; + void* const ctxPtr = &ctx; +#endif + + int const result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration); + +#if (LZ4_HEAPMODE) + FREEMEM(ctxPtr); +#endif + return result; +} + + +int LZ4_compress_default(const char* source, char* dest, int inputSize, int maxOutputSize) +{ + return LZ4_compress_fast(source, dest, inputSize, maxOutputSize, 1); +} + + +/* hidden debug function */ +/* strangely enough, gcc generates faster code when this function is uncommented, even if unused */ +int LZ4_compress_fast_force(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) +{ + LZ4_stream_t ctx; + LZ4_resetStream(&ctx); + + if (inputSize < LZ4_64Klimit) + return LZ4_compress_generic(&ctx.internal_donotuse, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); + else + return LZ4_compress_generic(&ctx.internal_donotuse, source, dest, inputSize, maxOutputSize, limitedOutput, sizeof(void*)==8 ? byU32 : byPtr, noDict, noDictIssue, acceleration); +} + + +/*-****************************** +* *_destSize() variant +********************************/ + +static int LZ4_compress_destSize_generic( + LZ4_stream_t_internal* const ctx, + const char* const src, + char* const dst, + int* const srcSizePtr, + const int targetDstSize, + const tableType_t tableType) +{ + const BYTE* ip = (const BYTE*) src; + const BYTE* base = (const BYTE*) src; + const BYTE* lowLimit = (const BYTE*) src; + const BYTE* anchor = ip; + const BYTE* const iend = ip + *srcSizePtr; + const BYTE* const mflimit = iend - MFLIMIT; + const BYTE* const matchlimit = iend - LASTLITERALS; + + BYTE* op = (BYTE*) dst; + BYTE* const oend = op + targetDstSize; + BYTE* const oMaxLit = op + targetDstSize - 2 /* offset */ - 8 /* because 8+MINMATCH==MFLIMIT */ - 1 /* token */; + BYTE* const oMaxMatch = op + targetDstSize - (LASTLITERALS + 1 /* token */); + BYTE* const oMaxSeq = oMaxLit - 1 /* token */; + + U32 forwardH; + + + /* Init conditions */ + if (targetDstSize < 1) return 0; /* Impossible to store anything */ + if ((U32)*srcSizePtr > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */ + if ((tableType == byU16) && (*srcSizePtr>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ + if (*srcSizePtrhashTable, tableType, base); + ip++; forwardH = LZ4_hashPosition(ip, tableType); + + /* Main Loop */ + for ( ; ; ) { + const BYTE* match; + BYTE* token; + + /* Find a match */ + { const BYTE* forwardIp = ip; + unsigned step = 1; + unsigned searchMatchNb = 1 << LZ4_skipTrigger; + + do { + U32 h = forwardH; + ip = forwardIp; + forwardIp += step; + step = (searchMatchNb++ >> LZ4_skipTrigger); + + if (unlikely(forwardIp > mflimit)) goto _last_literals; + + match = LZ4_getPositionOnHash(h, ctx->hashTable, tableType, base); + forwardH = LZ4_hashPosition(forwardIp, tableType); + LZ4_putPositionOnHash(ip, h, ctx->hashTable, tableType, base); + + } while ( ((tableType==byU16) ? 0 : (match + MAX_DISTANCE < ip)) + || (LZ4_read32(match) != LZ4_read32(ip)) ); + } + + /* Catch up */ + while ((ip>anchor) && (match > lowLimit) && (unlikely(ip[-1]==match[-1]))) { ip--; match--; } + + /* Encode Literal length */ + { unsigned litLength = (unsigned)(ip - anchor); + token = op++; + if (op + ((litLength+240)/255) + litLength > oMaxLit) { + /* Not enough space for a last match */ + op--; + goto _last_literals; + } + if (litLength>=RUN_MASK) { + unsigned len = litLength - RUN_MASK; + *token=(RUN_MASK<= 255 ; len-=255) *op++ = 255; + *op++ = (BYTE)len; + } + else *token = (BYTE)(litLength< oMaxMatch) { + /* Match description too long : reduce it */ + matchLength = (15-1) + (oMaxMatch-op) * 255; + } + ip += MINMATCH + matchLength; + + if (matchLength>=ML_MASK) { + *token += ML_MASK; + matchLength -= ML_MASK; + while (matchLength >= 255) { matchLength-=255; *op++ = 255; } + *op++ = (BYTE)matchLength; + } + else *token += (BYTE)(matchLength); + } + + anchor = ip; + + /* Test end of block */ + if (ip > mflimit) break; + if (op > oMaxSeq) break; + + /* Fill table */ + LZ4_putPosition(ip-2, ctx->hashTable, tableType, base); + + /* Test next position */ + match = LZ4_getPosition(ip, ctx->hashTable, tableType, base); + LZ4_putPosition(ip, ctx->hashTable, tableType, base); + if ( (match+MAX_DISTANCE>=ip) + && (LZ4_read32(match)==LZ4_read32(ip)) ) + { token=op++; *token=0; goto _next_match; } + + /* Prepare next loop */ + forwardH = LZ4_hashPosition(++ip, tableType); + } + +_last_literals: + /* Encode Last Literals */ + { size_t lastRunSize = (size_t)(iend - anchor); + if (op + 1 /* token */ + ((lastRunSize+240)/255) /* litLength */ + lastRunSize /* literals */ > oend) { + /* adapt lastRunSize to fill 'dst' */ + lastRunSize = (oend-op) - 1; + lastRunSize -= (lastRunSize+240)/255; + } + ip = anchor + lastRunSize; + + if (lastRunSize >= RUN_MASK) { + size_t accumulator = lastRunSize - RUN_MASK; + *op++ = RUN_MASK << ML_BITS; + for(; accumulator >= 255 ; accumulator-=255) *op++ = 255; + *op++ = (BYTE) accumulator; + } else { + *op++ = (BYTE)(lastRunSize<= LZ4_compressBound(*srcSizePtr)) { /* compression success is guaranteed */ + return LZ4_compress_fast_extState(state, src, dst, *srcSizePtr, targetDstSize, 1); + } else { + if (*srcSizePtr < LZ4_64Klimit) + return LZ4_compress_destSize_generic(&state->internal_donotuse, src, dst, srcSizePtr, targetDstSize, byU16); + else + return LZ4_compress_destSize_generic(&state->internal_donotuse, src, dst, srcSizePtr, targetDstSize, sizeof(void*)==8 ? byU32 : byPtr); + } +} + + +int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targetDstSize) +{ +#if (LZ4_HEAPMODE) + LZ4_stream_t* ctx = (LZ4_stream_t*)ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */ +#else + LZ4_stream_t ctxBody; + LZ4_stream_t* ctx = &ctxBody; +#endif + + int result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize); + +#if (LZ4_HEAPMODE) + FREEMEM(ctx); +#endif + return result; +} + + + +/*-****************************** +* Streaming functions +********************************/ + +LZ4_stream_t* LZ4_createStream(void) +{ + LZ4_stream_t* lz4s = (LZ4_stream_t*)ALLOCATOR(8, LZ4_STREAMSIZE_U64); + LZ4_STATIC_ASSERT(LZ4_STREAMSIZE >= sizeof(LZ4_stream_t_internal)); /* A compilation error here means LZ4_STREAMSIZE is not large enough */ + LZ4_resetStream(lz4s); + return lz4s; +} + +void LZ4_resetStream (LZ4_stream_t* LZ4_stream) +{ + MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t)); +} + +int LZ4_freeStream (LZ4_stream_t* LZ4_stream) +{ + if (!LZ4_stream) return 0; /* support free on NULL */ + FREEMEM(LZ4_stream); + return (0); +} + + +#define HASH_UNIT sizeof(reg_t) +int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) +{ + LZ4_stream_t_internal* dict = &LZ4_dict->internal_donotuse; + const BYTE* p = (const BYTE*)dictionary; + const BYTE* const dictEnd = p + dictSize; + const BYTE* base; + + if ((dict->initCheck) || (dict->currentOffset > 1 GB)) /* Uninitialized structure, or reuse overflow */ + LZ4_resetStream(LZ4_dict); + + if (dictSize < (int)HASH_UNIT) { + dict->dictionary = NULL; + dict->dictSize = 0; + return 0; + } + + if ((dictEnd - p) > 64 KB) p = dictEnd - 64 KB; + dict->currentOffset += 64 KB; + base = p - dict->currentOffset; + dict->dictionary = p; + dict->dictSize = (U32)(dictEnd - p); + dict->currentOffset += dict->dictSize; + + while (p <= dictEnd-HASH_UNIT) { + LZ4_putPosition(p, dict->hashTable, byU32, base); + p+=3; + } + + return dict->dictSize; +} + + +static void LZ4_renormDictT(LZ4_stream_t_internal* LZ4_dict, const BYTE* src) +{ + if ((LZ4_dict->currentOffset > 0x80000000) || + ((uptrval)LZ4_dict->currentOffset > (uptrval)src)) { /* address space overflow */ + /* rescale hash table */ + U32 const delta = LZ4_dict->currentOffset - 64 KB; + const BYTE* dictEnd = LZ4_dict->dictionary + LZ4_dict->dictSize; + int i; + for (i=0; ihashTable[i] < delta) LZ4_dict->hashTable[i]=0; + else LZ4_dict->hashTable[i] -= delta; + } + LZ4_dict->currentOffset = 64 KB; + if (LZ4_dict->dictSize > 64 KB) LZ4_dict->dictSize = 64 KB; + LZ4_dict->dictionary = dictEnd - LZ4_dict->dictSize; + } +} + + +int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) +{ + LZ4_stream_t_internal* streamPtr = &LZ4_stream->internal_donotuse; + const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize; + + const BYTE* smallest = (const BYTE*) source; + if (streamPtr->initCheck) return 0; /* Uninitialized structure detected */ + if ((streamPtr->dictSize>0) && (smallest>dictEnd)) smallest = dictEnd; + LZ4_renormDictT(streamPtr, smallest); + if (acceleration < 1) acceleration = ACCELERATION_DEFAULT; + + /* Check overlapping input/dictionary space */ + { const BYTE* sourceEnd = (const BYTE*) source + inputSize; + if ((sourceEnd > streamPtr->dictionary) && (sourceEnd < dictEnd)) { + streamPtr->dictSize = (U32)(dictEnd - sourceEnd); + if (streamPtr->dictSize > 64 KB) streamPtr->dictSize = 64 KB; + if (streamPtr->dictSize < 4) streamPtr->dictSize = 0; + streamPtr->dictionary = dictEnd - streamPtr->dictSize; + } + } + + /* prefix mode : source data follows dictionary */ + if (dictEnd == (const BYTE*)source) { + int result; + if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) + result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, dictSmall, acceleration); + else + result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, noDictIssue, acceleration); + streamPtr->dictSize += (U32)inputSize; + streamPtr->currentOffset += (U32)inputSize; + return result; + } + + /* external dictionary mode */ + { int result; + if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) + result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, dictSmall, acceleration); + else + result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, noDictIssue, acceleration); + streamPtr->dictionary = (const BYTE*)source; + streamPtr->dictSize = (U32)inputSize; + streamPtr->currentOffset += (U32)inputSize; + return result; + } +} + + +/* Hidden debug function, to force external dictionary mode */ +int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* dest, int inputSize) +{ + LZ4_stream_t_internal* streamPtr = &LZ4_dict->internal_donotuse; + int result; + const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize; + + const BYTE* smallest = dictEnd; + if (smallest > (const BYTE*) source) smallest = (const BYTE*) source; + LZ4_renormDictT(streamPtr, smallest); + + result = LZ4_compress_generic(streamPtr, source, dest, inputSize, 0, notLimited, byU32, usingExtDict, noDictIssue, 1); + + streamPtr->dictionary = (const BYTE*)source; + streamPtr->dictSize = (U32)inputSize; + streamPtr->currentOffset += (U32)inputSize; + + return result; +} + + +/*! LZ4_saveDict() : + * If previously compressed data block is not guaranteed to remain available at its memory location, + * save it into a safer place (char* safeBuffer). + * Note : you don't need to call LZ4_loadDict() afterwards, + * dictionary is immediately usable, you can therefore call LZ4_compress_fast_continue(). + * Return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error. + */ +int LZ4_saveDict (LZ4_stream_t* LZ4_dict, char* safeBuffer, int dictSize) +{ + LZ4_stream_t_internal* const dict = &LZ4_dict->internal_donotuse; + const BYTE* const previousDictEnd = dict->dictionary + dict->dictSize; + + if ((U32)dictSize > 64 KB) dictSize = 64 KB; /* useless to define a dictionary > 64 KB */ + if ((U32)dictSize > dict->dictSize) dictSize = dict->dictSize; + + memmove(safeBuffer, previousDictEnd - dictSize, dictSize); + + dict->dictionary = (const BYTE*)safeBuffer; + dict->dictSize = (U32)dictSize; + + return dictSize; +} + + + +/*-***************************** +* Decompression functions +*******************************/ +/*! LZ4_decompress_generic() : + * This generic decompression function cover all use cases. + * It shall be instantiated several times, using different sets of directives + * Note that it is important this generic function is really inlined, + * in order to remove useless branches during compilation optimization. + */ +FORCE_INLINE int LZ4_decompress_generic( + const char* const source, + char* const dest, + int inputSize, + int outputSize, /* If endOnInput==endOnInputSize, this value is the max size of Output Buffer. */ + + int endOnInput, /* endOnOutputSize, endOnInputSize */ + int partialDecoding, /* full, partial */ + int targetOutputSize, /* only used if partialDecoding==partial */ + int dict, /* noDict, withPrefix64k, usingExtDict */ + const BYTE* const lowPrefix, /* == dest when no prefix */ + const BYTE* const dictStart, /* only if dict==usingExtDict */ + const size_t dictSize /* note : = 0 if noDict */ + ) +{ + /* Local Variables */ + const BYTE* ip = (const BYTE*) source; + const BYTE* const iend = ip + inputSize; + + BYTE* op = (BYTE*) dest; + BYTE* const oend = op + outputSize; + BYTE* cpy; + BYTE* oexit = op + targetOutputSize; + const BYTE* const lowLimit = lowPrefix - dictSize; + + const BYTE* const dictEnd = (const BYTE*)dictStart + dictSize; + const unsigned dec32table[] = {0, 1, 2, 1, 4, 4, 4, 4}; + const int dec64table[] = {0, 0, 0, -1, 0, 1, 2, 3}; + + const int safeDecode = (endOnInput==endOnInputSize); + const int checkOffset = ((safeDecode) && (dictSize < (int)(64 KB))); + + + /* Special cases */ + if ((partialDecoding) && (oexit > oend-MFLIMIT)) oexit = oend-MFLIMIT; /* targetOutputSize too high => decode everything */ + if ((endOnInput) && (unlikely(outputSize==0))) return ((inputSize==1) && (*ip==0)) ? 0 : -1; /* Empty output buffer */ + if ((!endOnInput) && (unlikely(outputSize==0))) return (*ip==0?1:-1); + + /* Main Loop : decode sequences */ + while (1) { + size_t length; + const BYTE* match; + size_t offset; + + /* get literal length */ + unsigned const token = *ip++; + if ((length=(token>>ML_BITS)) == RUN_MASK) { + unsigned s; + do { + s = *ip++; + length += s; + } while ( likely(endOnInput ? ip(partialDecoding?oexit:oend-MFLIMIT)) || (ip+length>iend-(2+1+LASTLITERALS))) ) + || ((!endOnInput) && (cpy>oend-WILDCOPYLENGTH)) ) + { + if (partialDecoding) { + if (cpy > oend) goto _output_error; /* Error : write attempt beyond end of output buffer */ + if ((endOnInput) && (ip+length > iend)) goto _output_error; /* Error : read attempt beyond end of input buffer */ + } else { + if ((!endOnInput) && (cpy != oend)) goto _output_error; /* Error : block decoding must stop exactly there */ + if ((endOnInput) && ((ip+length != iend) || (cpy > oend))) goto _output_error; /* Error : input must be consumed */ + } + memcpy(op, ip, length); + ip += length; + op += length; + break; /* Necessarily EOF, due to parsing restrictions */ + } + LZ4_wildCopy(op, ip, cpy); + ip += length; op = cpy; + + /* get offset */ + offset = LZ4_readLE16(ip); ip+=2; + match = op - offset; + if ((checkOffset) && (unlikely(match < lowLimit))) goto _output_error; /* Error : offset outside buffers */ + LZ4_write32(op, (U32)offset); /* costs ~1%; silence an msan warning when offset==0 */ + + /* get matchlength */ + length = token & ML_MASK; + if (length == ML_MASK) { + unsigned s; + do { + s = *ip++; + if ((endOnInput) && (ip > iend-LASTLITERALS)) goto _output_error; + length += s; + } while (s==255); + if ((safeDecode) && unlikely((uptrval)(op)+length<(uptrval)op)) goto _output_error; /* overflow detection */ + } + length += MINMATCH; + + /* check external dictionary */ + if ((dict==usingExtDict) && (match < lowPrefix)) { + if (unlikely(op+length > oend-LASTLITERALS)) goto _output_error; /* doesn't respect parsing restriction */ + + if (length <= (size_t)(lowPrefix-match)) { + /* match can be copied as a single segment from external dictionary */ + memmove(op, dictEnd - (lowPrefix-match), length); + op += length; + } else { + /* match encompass external dictionary and current block */ + size_t const copySize = (size_t)(lowPrefix-match); + size_t const restSize = length - copySize; + memcpy(op, dictEnd - copySize, copySize); + op += copySize; + if (restSize > (size_t)(op-lowPrefix)) { /* overlap copy */ + BYTE* const endOfMatch = op + restSize; + const BYTE* copyFrom = lowPrefix; + while (op < endOfMatch) *op++ = *copyFrom++; + } else { + memcpy(op, lowPrefix, restSize); + op += restSize; + } } + continue; + } + + /* copy match within block */ + cpy = op + length; + if (unlikely(offset<8)) { + const int dec64 = dec64table[offset]; + op[0] = match[0]; + op[1] = match[1]; + op[2] = match[2]; + op[3] = match[3]; + match += dec32table[offset]; + memcpy(op+4, match, 4); + match -= dec64; + } else { LZ4_copy8(op, match); match+=8; } + op += 8; + + if (unlikely(cpy>oend-12)) { + BYTE* const oCopyLimit = oend-(WILDCOPYLENGTH-1); + if (cpy > oend-LASTLITERALS) goto _output_error; /* Error : last LASTLITERALS bytes must be literals (uncompressed) */ + if (op < oCopyLimit) { + LZ4_wildCopy(op, match, oCopyLimit); + match += oCopyLimit - op; + op = oCopyLimit; + } + while (op16) LZ4_wildCopy(op+8, match+8, cpy); + } + op=cpy; /* correction */ + } + + /* end of decoding */ + if (endOnInput) + return (int) (((char*)op)-dest); /* Nb of output bytes decoded */ + else + return (int) (((const char*)ip)-source); /* Nb of input bytes read */ + + /* Overflow error detected */ +_output_error: + return (int) (-(((const char*)ip)-source))-1; +} + + +int LZ4_decompress_safe(const char* source, char* dest, int compressedSize, int maxDecompressedSize) +{ + return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, endOnInputSize, full, 0, noDict, (BYTE*)dest, NULL, 0); +} + +int LZ4_decompress_safe_partial(const char* source, char* dest, int compressedSize, int targetOutputSize, int maxDecompressedSize) +{ + return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, endOnInputSize, partial, targetOutputSize, noDict, (BYTE*)dest, NULL, 0); +} + +int LZ4_decompress_fast(const char* source, char* dest, int originalSize) +{ + return LZ4_decompress_generic(source, dest, 0, originalSize, endOnOutputSize, full, 0, withPrefix64k, (BYTE*)(dest - 64 KB), NULL, 64 KB); +} + + +/*===== streaming decompression functions =====*/ + +LZ4_streamDecode_t* LZ4_createStreamDecode(void) +{ + LZ4_streamDecode_t* lz4s = (LZ4_streamDecode_t*) ALLOCATOR(1, sizeof(LZ4_streamDecode_t)); + return lz4s; +} + +int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream) +{ + if (!LZ4_stream) return 0; /* support free on NULL */ + FREEMEM(LZ4_stream); + return 0; +} + +/*! + * LZ4_setStreamDecode() : + * Use this function to instruct where to find the dictionary. + * This function is not necessary if previous data is still available where it was decoded. + * Loading a size of 0 is allowed (same effect as no dictionary). + * Return : 1 if OK, 0 if error + */ +int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize) +{ + LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse; + lz4sd->prefixSize = (size_t) dictSize; + lz4sd->prefixEnd = (const BYTE*) dictionary + dictSize; + lz4sd->externalDict = NULL; + lz4sd->extDictSize = 0; + return 1; +} + +/* +*_continue() : + These decoding functions allow decompression of multiple blocks in "streaming" mode. + Previously decoded blocks must still be available at the memory position where they were decoded. + If it's not possible, save the relevant part of decoded data into a safe buffer, + and indicate where it stands using LZ4_setStreamDecode() +*/ +int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxOutputSize) +{ + LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse; + int result; + + if (lz4sd->prefixEnd == (BYTE*)dest) { + result = LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, + endOnInputSize, full, 0, + usingExtDict, lz4sd->prefixEnd - lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize); + if (result <= 0) return result; + lz4sd->prefixSize += result; + lz4sd->prefixEnd += result; + } else { + lz4sd->extDictSize = lz4sd->prefixSize; + lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize; + result = LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, + endOnInputSize, full, 0, + usingExtDict, (BYTE*)dest, lz4sd->externalDict, lz4sd->extDictSize); + if (result <= 0) return result; + lz4sd->prefixSize = result; + lz4sd->prefixEnd = (BYTE*)dest + result; + } + + return result; +} + +int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int originalSize) +{ + LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse; + int result; + + if (lz4sd->prefixEnd == (BYTE*)dest) { + result = LZ4_decompress_generic(source, dest, 0, originalSize, + endOnOutputSize, full, 0, + usingExtDict, lz4sd->prefixEnd - lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize); + if (result <= 0) return result; + lz4sd->prefixSize += originalSize; + lz4sd->prefixEnd += originalSize; + } else { + lz4sd->extDictSize = lz4sd->prefixSize; + lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize; + result = LZ4_decompress_generic(source, dest, 0, originalSize, + endOnOutputSize, full, 0, + usingExtDict, (BYTE*)dest, lz4sd->externalDict, lz4sd->extDictSize); + if (result <= 0) return result; + lz4sd->prefixSize = originalSize; + lz4sd->prefixEnd = (BYTE*)dest + originalSize; + } + + return result; +} + + +/* +Advanced decoding functions : +*_usingDict() : + These decoding functions work the same as "_continue" ones, + the dictionary must be explicitly provided within parameters +*/ + +FORCE_INLINE int LZ4_decompress_usingDict_generic(const char* source, char* dest, int compressedSize, int maxOutputSize, int safe, const char* dictStart, int dictSize) +{ + if (dictSize==0) + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, noDict, (BYTE*)dest, NULL, 0); + if (dictStart+dictSize == dest) { + if (dictSize >= (int)(64 KB - 1)) + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, withPrefix64k, (BYTE*)dest-64 KB, NULL, 0); + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, noDict, (BYTE*)dest-dictSize, NULL, 0); + } + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, usingExtDict, (BYTE*)dest, (const BYTE*)dictStart, dictSize); +} + +int LZ4_decompress_safe_usingDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize) +{ + return LZ4_decompress_usingDict_generic(source, dest, compressedSize, maxOutputSize, 1, dictStart, dictSize); +} + +int LZ4_decompress_fast_usingDict(const char* source, char* dest, int originalSize, const char* dictStart, int dictSize) +{ + return LZ4_decompress_usingDict_generic(source, dest, 0, originalSize, 0, dictStart, dictSize); +} + +/* debug function */ +int LZ4_decompress_safe_forceExtDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize) +{ + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, usingExtDict, (BYTE*)dest, (const BYTE*)dictStart, dictSize); +} + + +/*=************************************************* +* Obsolete Functions +***************************************************/ +/* obsolete compression functions */ +int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) { return LZ4_compress_default(source, dest, inputSize, maxOutputSize); } +int LZ4_compress(const char* source, char* dest, int inputSize) { return LZ4_compress_default(source, dest, inputSize, LZ4_compressBound(inputSize)); } +int LZ4_compress_limitedOutput_withState (void* state, const char* src, char* dst, int srcSize, int dstSize) { return LZ4_compress_fast_extState(state, src, dst, srcSize, dstSize, 1); } +int LZ4_compress_withState (void* state, const char* src, char* dst, int srcSize) { return LZ4_compress_fast_extState(state, src, dst, srcSize, LZ4_compressBound(srcSize), 1); } +int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compress_fast_continue(LZ4_stream, src, dst, srcSize, maxDstSize, 1); } +int LZ4_compress_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize) { return LZ4_compress_fast_continue(LZ4_stream, source, dest, inputSize, LZ4_compressBound(inputSize), 1); } + +/* +These function names are deprecated and should no longer be used. +They are only provided here for compatibility with older user programs. +- LZ4_uncompress is totally equivalent to LZ4_decompress_fast +- LZ4_uncompress_unknownOutputSize is totally equivalent to LZ4_decompress_safe +*/ +int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); } +int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); } + + +/* Obsolete Streaming functions */ + +int LZ4_sizeofStreamState() { return LZ4_STREAMSIZE; } + +static void LZ4_init(LZ4_stream_t* lz4ds, BYTE* base) +{ + MEM_INIT(lz4ds, 0, sizeof(LZ4_stream_t)); + lz4ds->internal_donotuse.bufferStart = base; +} + +int LZ4_resetStreamState(void* state, char* inputBuffer) +{ + if ((((uptrval)state) & 3) != 0) return 1; /* Error : pointer is not aligned on 4-bytes boundary */ + LZ4_init((LZ4_stream_t*)state, (BYTE*)inputBuffer); + return 0; +} + +void* LZ4_create (char* inputBuffer) +{ + LZ4_stream_t* lz4ds = (LZ4_stream_t*)ALLOCATOR(8, sizeof(LZ4_stream_t)); + LZ4_init (lz4ds, (BYTE*)inputBuffer); + return lz4ds; +} + +char* LZ4_slideInputBuffer (void* LZ4_Data) +{ + LZ4_stream_t_internal* ctx = &((LZ4_stream_t*)LZ4_Data)->internal_donotuse; + int dictSize = LZ4_saveDict((LZ4_stream_t*)LZ4_Data, (char*)ctx->bufferStart, 64 KB); + return (char*)(ctx->bufferStart + dictSize); +} + +/* Obsolete streaming decompression functions */ + +int LZ4_decompress_safe_withPrefix64k(const char* source, char* dest, int compressedSize, int maxOutputSize) +{ + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, withPrefix64k, (BYTE*)dest - 64 KB, NULL, 64 KB); +} + +int LZ4_decompress_fast_withPrefix64k(const char* source, char* dest, int originalSize) +{ + return LZ4_decompress_generic(source, dest, 0, originalSize, endOnOutputSize, full, 0, withPrefix64k, (BYTE*)dest - 64 KB, NULL, 64 KB); +} + +#endif /* LZ4_COMMONDEFS_ONLY */ diff --git a/samtools/lz4/lz4.c.pysam.c b/samtools/lz4/lz4.c.pysam.c new file mode 100644 index 000000000..a4a8ab43d --- /dev/null +++ b/samtools/lz4/lz4.c.pysam.c @@ -0,0 +1,1480 @@ +#include "samtools.pysam.h" + +/* + LZ4 - Fast LZ compression algorithm + Copyright (C) 2011-2017, Yann Collet. + + BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + You can contact the author at : + - LZ4 homepage : http://www.lz4.org + - LZ4 source repository : https://github.com/lz4/lz4 +*/ + + +/*-************************************ +* Tuning parameters +**************************************/ +/* + * LZ4_HEAPMODE : + * Select how default compression functions will allocate memory for their hash table, + * in memory stack (0:default, fastest), or in memory heap (1:requires malloc()). + */ +#ifndef LZ4_HEAPMODE +# define LZ4_HEAPMODE 0 +#endif + +/* + * ACCELERATION_DEFAULT : + * Select "acceleration" for LZ4_compress_fast() when parameter value <= 0 + */ +#define ACCELERATION_DEFAULT 1 + + +/*-************************************ +* CPU Feature Detection +**************************************/ +/* LZ4_FORCE_MEMORY_ACCESS + * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable. + * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal. + * The below switch allow to select different access method for improved performance. + * Method 0 (default) : use `memcpy()`. Safe and portable. + * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable). + * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`. + * Method 2 : direct access. This method is portable but violate C standard. + * It can generate buggy code on targets which assembly generation depends on alignment. + * But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6) + * See https://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details. + * Prefer these methods in priority order (0 > 1 > 2) + */ +#ifndef LZ4_FORCE_MEMORY_ACCESS /* can be defined externally */ +# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) ) +# define LZ4_FORCE_MEMORY_ACCESS 2 +# elif defined(__INTEL_COMPILER) || defined(__GNUC__) +# define LZ4_FORCE_MEMORY_ACCESS 1 +# endif +#endif + +/* + * LZ4_FORCE_SW_BITCOUNT + * Define this parameter if your target system or compiler does not support hardware bit count + */ +#if defined(_MSC_VER) && defined(_WIN32_WCE) /* Visual Studio for Windows CE does not support Hardware bit count */ +# define LZ4_FORCE_SW_BITCOUNT +#endif + + +/*-************************************ +* Dependency +**************************************/ +#include "lz4.h" +/* see also "memory routines" below */ + + +/*-************************************ +* Compiler Options +**************************************/ +#ifdef _MSC_VER /* Visual Studio */ +# include +# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ +# pragma warning(disable : 4293) /* disable: C4293: too large shift (32-bits) */ +#endif /* _MSC_VER */ + +#ifndef FORCE_INLINE +# ifdef _MSC_VER /* Visual Studio */ +# define FORCE_INLINE static __forceinline +# else +# if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ +# ifdef __GNUC__ +# define FORCE_INLINE static inline __attribute__((always_inline)) +# else +# define FORCE_INLINE static inline +# endif +# else +# define FORCE_INLINE static +# endif /* __STDC_VERSION__ */ +# endif /* _MSC_VER */ +#endif /* FORCE_INLINE */ + +#if (defined(__GNUC__) && (__GNUC__ >= 3)) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) || defined(__clang__) +# define expect(expr,value) (__builtin_expect ((expr),(value)) ) +#else +# define expect(expr,value) (expr) +#endif + +#define likely(expr) expect((expr) != 0, 1) +#define unlikely(expr) expect((expr) != 0, 0) + + +/*-************************************ +* Memory routines +**************************************/ +#include /* malloc, calloc, free */ +#define ALLOCATOR(n,s) calloc(n,s) +#define FREEMEM free +#include /* memset, memcpy */ +#define MEM_INIT memset + + +/*-************************************ +* Basic Types +**************************************/ +#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) +# include + typedef uint8_t BYTE; + typedef uint16_t U16; + typedef uint32_t U32; + typedef int32_t S32; + typedef uint64_t U64; + typedef uintptr_t uptrval; +#else + typedef unsigned char BYTE; + typedef unsigned short U16; + typedef unsigned int U32; + typedef signed int S32; + typedef unsigned long long U64; + typedef size_t uptrval; /* generally true, except OpenVMS-64 */ +#endif + +#if defined(__x86_64__) + typedef U64 reg_t; /* 64-bits in x32 mode */ +#else + typedef size_t reg_t; /* 32-bits in x32 mode */ +#endif + +/*-************************************ +* Reading and writing into memory +**************************************/ +static unsigned LZ4_isLittleEndian(void) +{ + const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */ + return one.c[0]; +} + + +#if defined(LZ4_FORCE_MEMORY_ACCESS) && (LZ4_FORCE_MEMORY_ACCESS==2) +/* lie to the compiler about data alignment; use with caution */ + +static U16 LZ4_read16(const void* memPtr) { return *(const U16*) memPtr; } +static U32 LZ4_read32(const void* memPtr) { return *(const U32*) memPtr; } +static reg_t LZ4_read_ARCH(const void* memPtr) { return *(const reg_t*) memPtr; } + +static void LZ4_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; } +static void LZ4_write32(void* memPtr, U32 value) { *(U32*)memPtr = value; } + +#elif defined(LZ4_FORCE_MEMORY_ACCESS) && (LZ4_FORCE_MEMORY_ACCESS==1) + +/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */ +/* currently only defined for gcc and icc */ +typedef union { U16 u16; U32 u32; reg_t uArch; } __attribute__((packed)) unalign; + +static U16 LZ4_read16(const void* ptr) { return ((const unalign*)ptr)->u16; } +static U32 LZ4_read32(const void* ptr) { return ((const unalign*)ptr)->u32; } +static reg_t LZ4_read_ARCH(const void* ptr) { return ((const unalign*)ptr)->uArch; } + +static void LZ4_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; } +static void LZ4_write32(void* memPtr, U32 value) { ((unalign*)memPtr)->u32 = value; } + +#else /* safe and portable access through memcpy() */ + +static U16 LZ4_read16(const void* memPtr) +{ + U16 val; memcpy(&val, memPtr, sizeof(val)); return val; +} + +static U32 LZ4_read32(const void* memPtr) +{ + U32 val; memcpy(&val, memPtr, sizeof(val)); return val; +} + +static reg_t LZ4_read_ARCH(const void* memPtr) +{ + reg_t val; memcpy(&val, memPtr, sizeof(val)); return val; +} + +static void LZ4_write16(void* memPtr, U16 value) +{ + memcpy(memPtr, &value, sizeof(value)); +} + +static void LZ4_write32(void* memPtr, U32 value) +{ + memcpy(memPtr, &value, sizeof(value)); +} + +#endif /* LZ4_FORCE_MEMORY_ACCESS */ + + +static U16 LZ4_readLE16(const void* memPtr) +{ + if (LZ4_isLittleEndian()) { + return LZ4_read16(memPtr); + } else { + const BYTE* p = (const BYTE*)memPtr; + return (U16)((U16)p[0] + (p[1]<<8)); + } +} + +static void LZ4_writeLE16(void* memPtr, U16 value) +{ + if (LZ4_isLittleEndian()) { + LZ4_write16(memPtr, value); + } else { + BYTE* p = (BYTE*)memPtr; + p[0] = (BYTE) value; + p[1] = (BYTE)(value>>8); + } +} + +static void LZ4_copy8(void* dst, const void* src) +{ + memcpy(dst,src,8); +} + +/* customized variant of memcpy, which can overwrite up to 8 bytes beyond dstEnd */ +static void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd) +{ + BYTE* d = (BYTE*)dstPtr; + const BYTE* s = (const BYTE*)srcPtr; + BYTE* const e = (BYTE*)dstEnd; + + do { LZ4_copy8(d,s); d+=8; s+=8; } while (d=2) +# include +# define DEBUGLOG(l, ...) { \ + if (l<=LZ4_DEBUG) { \ + fprintf(samtools_stderr, __FILE__ ": "); \ + fprintf(samtools_stderr, __VA_ARGS__); \ + fprintf(samtools_stderr, " \n"); \ + } } +#else +# define DEBUGLOG(l, ...) {} /* disabled */ +#endif + + +/*-************************************ +* Common functions +**************************************/ +static unsigned LZ4_NbCommonBytes (register reg_t val) +{ + if (LZ4_isLittleEndian()) { + if (sizeof(val)==8) { +# if defined(_MSC_VER) && defined(_WIN64) && !defined(LZ4_FORCE_SW_BITCOUNT) + unsigned long r = 0; + _BitScanForward64( &r, (U64)val ); + return (int)(r>>3); +# elif (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>=3))) && !defined(LZ4_FORCE_SW_BITCOUNT) + return (__builtin_ctzll((U64)val) >> 3); +# else + static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 }; + return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58]; +# endif + } else /* 32 bits */ { +# if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT) + unsigned long r; + _BitScanForward( &r, (U32)val ); + return (int)(r>>3); +# elif (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>=3))) && !defined(LZ4_FORCE_SW_BITCOUNT) + return (__builtin_ctz((U32)val) >> 3); +# else + static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 }; + return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27]; +# endif + } + } else /* Big Endian CPU */ { + if (sizeof(val)==8) { +# if defined(_MSC_VER) && defined(_WIN64) && !defined(LZ4_FORCE_SW_BITCOUNT) + unsigned long r = 0; + _BitScanReverse64( &r, val ); + return (unsigned)(r>>3); +# elif (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>=3))) && !defined(LZ4_FORCE_SW_BITCOUNT) + return (__builtin_clzll((U64)val) >> 3); +# else + unsigned r; + if (!(val>>32)) { r=4; } else { r=0; val>>=32; } + if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; } + r += (!val); + return r; +# endif + } else /* 32 bits */ { +# if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT) + unsigned long r = 0; + _BitScanReverse( &r, (unsigned long)val ); + return (unsigned)(r>>3); +# elif (defined(__clang__) || (defined(__GNUC__) && (__GNUC__>=3))) && !defined(LZ4_FORCE_SW_BITCOUNT) + return (__builtin_clz((U32)val) >> 3); +# else + unsigned r; + if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; } + r += (!val); + return r; +# endif + } + } +} + +#define STEPSIZE sizeof(reg_t) +static unsigned LZ4_count(const BYTE* pIn, const BYTE* pMatch, const BYTE* pInLimit) +{ + const BYTE* const pStart = pIn; + + while (likely(pIn compression run slower on incompressible data */ + + +/*-************************************ +* Local Structures and types +**************************************/ +typedef enum { notLimited = 0, limitedOutput = 1 } limitedOutput_directive; +typedef enum { byPtr, byU32, byU16 } tableType_t; + +typedef enum { noDict = 0, withPrefix64k, usingExtDict } dict_directive; +typedef enum { noDictIssue = 0, dictSmall } dictIssue_directive; + +typedef enum { endOnOutputSize = 0, endOnInputSize = 1 } endCondition_directive; +typedef enum { full = 0, partial = 1 } earlyEnd_directive; + + +/*-************************************ +* Local Utils +**************************************/ +int LZ4_versionNumber (void) { return LZ4_VERSION_NUMBER; } +const char* LZ4_versionString(void) { return LZ4_VERSION_STRING; } +int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); } +int LZ4_sizeofState() { return LZ4_STREAMSIZE; } + + +/*-****************************** +* Compression functions +********************************/ +static U32 LZ4_hash4(U32 sequence, tableType_t const tableType) +{ + if (tableType == byU16) + return ((sequence * 2654435761U) >> ((MINMATCH*8)-(LZ4_HASHLOG+1))); + else + return ((sequence * 2654435761U) >> ((MINMATCH*8)-LZ4_HASHLOG)); +} + +static U32 LZ4_hash5(U64 sequence, tableType_t const tableType) +{ + static const U64 prime5bytes = 889523592379ULL; + static const U64 prime8bytes = 11400714785074694791ULL; + const U32 hashLog = (tableType == byU16) ? LZ4_HASHLOG+1 : LZ4_HASHLOG; + if (LZ4_isLittleEndian()) + return (U32)(((sequence << 24) * prime5bytes) >> (64 - hashLog)); + else + return (U32)(((sequence >> 24) * prime8bytes) >> (64 - hashLog)); +} + +FORCE_INLINE U32 LZ4_hashPosition(const void* const p, tableType_t const tableType) +{ + if ((sizeof(reg_t)==8) && (tableType != byU16)) return LZ4_hash5(LZ4_read_ARCH(p), tableType); + return LZ4_hash4(LZ4_read32(p), tableType); +} + +static void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t const tableType, const BYTE* srcBase) +{ + switch (tableType) + { + case byPtr: { const BYTE** hashTable = (const BYTE**)tableBase; hashTable[h] = p; return; } + case byU32: { U32* hashTable = (U32*) tableBase; hashTable[h] = (U32)(p-srcBase); return; } + case byU16: { U16* hashTable = (U16*) tableBase; hashTable[h] = (U16)(p-srcBase); return; } + } +} + +FORCE_INLINE void LZ4_putPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase) +{ + U32 const h = LZ4_hashPosition(p, tableType); + LZ4_putPositionOnHash(p, h, tableBase, tableType, srcBase); +} + +static const BYTE* LZ4_getPositionOnHash(U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase) +{ + if (tableType == byPtr) { const BYTE** hashTable = (const BYTE**) tableBase; return hashTable[h]; } + if (tableType == byU32) { const U32* const hashTable = (U32*) tableBase; return hashTable[h] + srcBase; } + { const U16* const hashTable = (U16*) tableBase; return hashTable[h] + srcBase; } /* default, to ensure a return */ +} + +FORCE_INLINE const BYTE* LZ4_getPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase) +{ + U32 const h = LZ4_hashPosition(p, tableType); + return LZ4_getPositionOnHash(h, tableBase, tableType, srcBase); +} + + +/** LZ4_compress_generic() : + inlined, to ensure branches are decided at compilation time */ +FORCE_INLINE int LZ4_compress_generic( + LZ4_stream_t_internal* const cctx, + const char* const source, + char* const dest, + const int inputSize, + const int maxOutputSize, + const limitedOutput_directive outputLimited, + const tableType_t tableType, + const dict_directive dict, + const dictIssue_directive dictIssue, + const U32 acceleration) +{ + const BYTE* ip = (const BYTE*) source; + const BYTE* base; + const BYTE* lowLimit; + const BYTE* const lowRefLimit = ip - cctx->dictSize; + const BYTE* const dictionary = cctx->dictionary; + const BYTE* const dictEnd = dictionary + cctx->dictSize; + const ptrdiff_t dictDelta = dictEnd - (const BYTE*)source; + const BYTE* anchor = (const BYTE*) source; + const BYTE* const iend = ip + inputSize; + const BYTE* const mflimit = iend - MFLIMIT; + const BYTE* const matchlimit = iend - LASTLITERALS; + + BYTE* op = (BYTE*) dest; + BYTE* const olimit = op + maxOutputSize; + + U32 forwardH; + + /* Init conditions */ + if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported inputSize, too large (or negative) */ + switch(dict) + { + case noDict: + default: + base = (const BYTE*)source; + lowLimit = (const BYTE*)source; + break; + case withPrefix64k: + base = (const BYTE*)source - cctx->currentOffset; + lowLimit = (const BYTE*)source - cctx->dictSize; + break; + case usingExtDict: + base = (const BYTE*)source - cctx->currentOffset; + lowLimit = (const BYTE*)source; + break; + } + if ((tableType == byU16) && (inputSize>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ + if (inputSizehashTable, tableType, base); + ip++; forwardH = LZ4_hashPosition(ip, tableType); + + /* Main Loop */ + for ( ; ; ) { + ptrdiff_t refDelta = 0; + const BYTE* match; + BYTE* token; + + /* Find a match */ + { const BYTE* forwardIp = ip; + unsigned step = 1; + unsigned searchMatchNb = acceleration << LZ4_skipTrigger; + do { + U32 const h = forwardH; + ip = forwardIp; + forwardIp += step; + step = (searchMatchNb++ >> LZ4_skipTrigger); + + if (unlikely(forwardIp > mflimit)) goto _last_literals; + + match = LZ4_getPositionOnHash(h, cctx->hashTable, tableType, base); + if (dict==usingExtDict) { + if (match < (const BYTE*)source) { + refDelta = dictDelta; + lowLimit = dictionary; + } else { + refDelta = 0; + lowLimit = (const BYTE*)source; + } } + forwardH = LZ4_hashPosition(forwardIp, tableType); + LZ4_putPositionOnHash(ip, h, cctx->hashTable, tableType, base); + + } while ( ((dictIssue==dictSmall) ? (match < lowRefLimit) : 0) + || ((tableType==byU16) ? 0 : (match + MAX_DISTANCE < ip)) + || (LZ4_read32(match+refDelta) != LZ4_read32(ip)) ); + } + + /* Catch up */ + while (((ip>anchor) & (match+refDelta > lowLimit)) && (unlikely(ip[-1]==match[refDelta-1]))) { ip--; match--; } + + /* Encode Literals */ + { unsigned const litLength = (unsigned)(ip - anchor); + token = op++; + if ((outputLimited) && /* Check output buffer overflow */ + (unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > olimit))) + return 0; + if (litLength >= RUN_MASK) { + int len = (int)litLength-RUN_MASK; + *token = (RUN_MASK<= 255 ; len-=255) *op++ = 255; + *op++ = (BYTE)len; + } + else *token = (BYTE)(litLength< matchlimit) limit = matchlimit; + matchCode = LZ4_count(ip+MINMATCH, match+MINMATCH, limit); + ip += MINMATCH + matchCode; + if (ip==limit) { + unsigned const more = LZ4_count(ip, (const BYTE*)source, matchlimit); + matchCode += more; + ip += more; + } + } else { + matchCode = LZ4_count(ip+MINMATCH, match+MINMATCH, matchlimit); + ip += MINMATCH + matchCode; + } + + if ( outputLimited && /* Check output buffer overflow */ + (unlikely(op + (1 + LASTLITERALS) + (matchCode>>8) > olimit)) ) + return 0; + if (matchCode >= ML_MASK) { + *token += ML_MASK; + matchCode -= ML_MASK; + LZ4_write32(op, 0xFFFFFFFF); + while (matchCode >= 4*255) op+=4, LZ4_write32(op, 0xFFFFFFFF), matchCode -= 4*255; + op += matchCode / 255; + *op++ = (BYTE)(matchCode % 255); + } else + *token += (BYTE)(matchCode); + } + + anchor = ip; + + /* Test end of chunk */ + if (ip > mflimit) break; + + /* Fill table */ + LZ4_putPosition(ip-2, cctx->hashTable, tableType, base); + + /* Test next position */ + match = LZ4_getPosition(ip, cctx->hashTable, tableType, base); + if (dict==usingExtDict) { + if (match < (const BYTE*)source) { + refDelta = dictDelta; + lowLimit = dictionary; + } else { + refDelta = 0; + lowLimit = (const BYTE*)source; + } } + LZ4_putPosition(ip, cctx->hashTable, tableType, base); + if ( ((dictIssue==dictSmall) ? (match>=lowRefLimit) : 1) + && (match+MAX_DISTANCE>=ip) + && (LZ4_read32(match+refDelta)==LZ4_read32(ip)) ) + { token=op++; *token=0; goto _next_match; } + + /* Prepare next loop */ + forwardH = LZ4_hashPosition(++ip, tableType); + } + +_last_literals: + /* Encode Last Literals */ + { size_t const lastRun = (size_t)(iend - anchor); + if ( (outputLimited) && /* Check output buffer overflow */ + ((op - (BYTE*)dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize) ) + return 0; + if (lastRun >= RUN_MASK) { + size_t accumulator = lastRun - RUN_MASK; + *op++ = RUN_MASK << ML_BITS; + for(; accumulator >= 255 ; accumulator-=255) *op++ = 255; + *op++ = (BYTE) accumulator; + } else { + *op++ = (BYTE)(lastRun<internal_donotuse; + LZ4_resetStream((LZ4_stream_t*)state); + if (acceleration < 1) acceleration = ACCELERATION_DEFAULT; + + if (maxOutputSize >= LZ4_compressBound(inputSize)) { + if (inputSize < LZ4_64Klimit) + return LZ4_compress_generic(ctx, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, acceleration); + else + return LZ4_compress_generic(ctx, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noDict, noDictIssue, acceleration); + } else { + if (inputSize < LZ4_64Klimit) + return LZ4_compress_generic(ctx, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); + else + return LZ4_compress_generic(ctx, source, dest, inputSize, maxOutputSize, limitedOutput, (sizeof(void*)==8) ? byU32 : byPtr, noDict, noDictIssue, acceleration); + } +} + + +int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) +{ +#if (LZ4_HEAPMODE) + void* ctxPtr = ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */ +#else + LZ4_stream_t ctx; + void* const ctxPtr = &ctx; +#endif + + int const result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration); + +#if (LZ4_HEAPMODE) + FREEMEM(ctxPtr); +#endif + return result; +} + + +int LZ4_compress_default(const char* source, char* dest, int inputSize, int maxOutputSize) +{ + return LZ4_compress_fast(source, dest, inputSize, maxOutputSize, 1); +} + + +/* hidden debug function */ +/* strangely enough, gcc generates faster code when this function is uncommented, even if unused */ +int LZ4_compress_fast_force(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) +{ + LZ4_stream_t ctx; + LZ4_resetStream(&ctx); + + if (inputSize < LZ4_64Klimit) + return LZ4_compress_generic(&ctx.internal_donotuse, source, dest, inputSize, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration); + else + return LZ4_compress_generic(&ctx.internal_donotuse, source, dest, inputSize, maxOutputSize, limitedOutput, sizeof(void*)==8 ? byU32 : byPtr, noDict, noDictIssue, acceleration); +} + + +/*-****************************** +* *_destSize() variant +********************************/ + +static int LZ4_compress_destSize_generic( + LZ4_stream_t_internal* const ctx, + const char* const src, + char* const dst, + int* const srcSizePtr, + const int targetDstSize, + const tableType_t tableType) +{ + const BYTE* ip = (const BYTE*) src; + const BYTE* base = (const BYTE*) src; + const BYTE* lowLimit = (const BYTE*) src; + const BYTE* anchor = ip; + const BYTE* const iend = ip + *srcSizePtr; + const BYTE* const mflimit = iend - MFLIMIT; + const BYTE* const matchlimit = iend - LASTLITERALS; + + BYTE* op = (BYTE*) dst; + BYTE* const oend = op + targetDstSize; + BYTE* const oMaxLit = op + targetDstSize - 2 /* offset */ - 8 /* because 8+MINMATCH==MFLIMIT */ - 1 /* token */; + BYTE* const oMaxMatch = op + targetDstSize - (LASTLITERALS + 1 /* token */); + BYTE* const oMaxSeq = oMaxLit - 1 /* token */; + + U32 forwardH; + + + /* Init conditions */ + if (targetDstSize < 1) return 0; /* Impossible to store anything */ + if ((U32)*srcSizePtr > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */ + if ((tableType == byU16) && (*srcSizePtr>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ + if (*srcSizePtrhashTable, tableType, base); + ip++; forwardH = LZ4_hashPosition(ip, tableType); + + /* Main Loop */ + for ( ; ; ) { + const BYTE* match; + BYTE* token; + + /* Find a match */ + { const BYTE* forwardIp = ip; + unsigned step = 1; + unsigned searchMatchNb = 1 << LZ4_skipTrigger; + + do { + U32 h = forwardH; + ip = forwardIp; + forwardIp += step; + step = (searchMatchNb++ >> LZ4_skipTrigger); + + if (unlikely(forwardIp > mflimit)) goto _last_literals; + + match = LZ4_getPositionOnHash(h, ctx->hashTable, tableType, base); + forwardH = LZ4_hashPosition(forwardIp, tableType); + LZ4_putPositionOnHash(ip, h, ctx->hashTable, tableType, base); + + } while ( ((tableType==byU16) ? 0 : (match + MAX_DISTANCE < ip)) + || (LZ4_read32(match) != LZ4_read32(ip)) ); + } + + /* Catch up */ + while ((ip>anchor) && (match > lowLimit) && (unlikely(ip[-1]==match[-1]))) { ip--; match--; } + + /* Encode Literal length */ + { unsigned litLength = (unsigned)(ip - anchor); + token = op++; + if (op + ((litLength+240)/255) + litLength > oMaxLit) { + /* Not enough space for a last match */ + op--; + goto _last_literals; + } + if (litLength>=RUN_MASK) { + unsigned len = litLength - RUN_MASK; + *token=(RUN_MASK<= 255 ; len-=255) *op++ = 255; + *op++ = (BYTE)len; + } + else *token = (BYTE)(litLength< oMaxMatch) { + /* Match description too long : reduce it */ + matchLength = (15-1) + (oMaxMatch-op) * 255; + } + ip += MINMATCH + matchLength; + + if (matchLength>=ML_MASK) { + *token += ML_MASK; + matchLength -= ML_MASK; + while (matchLength >= 255) { matchLength-=255; *op++ = 255; } + *op++ = (BYTE)matchLength; + } + else *token += (BYTE)(matchLength); + } + + anchor = ip; + + /* Test end of block */ + if (ip > mflimit) break; + if (op > oMaxSeq) break; + + /* Fill table */ + LZ4_putPosition(ip-2, ctx->hashTable, tableType, base); + + /* Test next position */ + match = LZ4_getPosition(ip, ctx->hashTable, tableType, base); + LZ4_putPosition(ip, ctx->hashTable, tableType, base); + if ( (match+MAX_DISTANCE>=ip) + && (LZ4_read32(match)==LZ4_read32(ip)) ) + { token=op++; *token=0; goto _next_match; } + + /* Prepare next loop */ + forwardH = LZ4_hashPosition(++ip, tableType); + } + +_last_literals: + /* Encode Last Literals */ + { size_t lastRunSize = (size_t)(iend - anchor); + if (op + 1 /* token */ + ((lastRunSize+240)/255) /* litLength */ + lastRunSize /* literals */ > oend) { + /* adapt lastRunSize to fill 'dst' */ + lastRunSize = (oend-op) - 1; + lastRunSize -= (lastRunSize+240)/255; + } + ip = anchor + lastRunSize; + + if (lastRunSize >= RUN_MASK) { + size_t accumulator = lastRunSize - RUN_MASK; + *op++ = RUN_MASK << ML_BITS; + for(; accumulator >= 255 ; accumulator-=255) *op++ = 255; + *op++ = (BYTE) accumulator; + } else { + *op++ = (BYTE)(lastRunSize<= LZ4_compressBound(*srcSizePtr)) { /* compression success is guaranteed */ + return LZ4_compress_fast_extState(state, src, dst, *srcSizePtr, targetDstSize, 1); + } else { + if (*srcSizePtr < LZ4_64Klimit) + return LZ4_compress_destSize_generic(&state->internal_donotuse, src, dst, srcSizePtr, targetDstSize, byU16); + else + return LZ4_compress_destSize_generic(&state->internal_donotuse, src, dst, srcSizePtr, targetDstSize, sizeof(void*)==8 ? byU32 : byPtr); + } +} + + +int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targetDstSize) +{ +#if (LZ4_HEAPMODE) + LZ4_stream_t* ctx = (LZ4_stream_t*)ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */ +#else + LZ4_stream_t ctxBody; + LZ4_stream_t* ctx = &ctxBody; +#endif + + int result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize); + +#if (LZ4_HEAPMODE) + FREEMEM(ctx); +#endif + return result; +} + + + +/*-****************************** +* Streaming functions +********************************/ + +LZ4_stream_t* LZ4_createStream(void) +{ + LZ4_stream_t* lz4s = (LZ4_stream_t*)ALLOCATOR(8, LZ4_STREAMSIZE_U64); + LZ4_STATIC_ASSERT(LZ4_STREAMSIZE >= sizeof(LZ4_stream_t_internal)); /* A compilation error here means LZ4_STREAMSIZE is not large enough */ + LZ4_resetStream(lz4s); + return lz4s; +} + +void LZ4_resetStream (LZ4_stream_t* LZ4_stream) +{ + MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t)); +} + +int LZ4_freeStream (LZ4_stream_t* LZ4_stream) +{ + if (!LZ4_stream) return 0; /* support free on NULL */ + FREEMEM(LZ4_stream); + return (0); +} + + +#define HASH_UNIT sizeof(reg_t) +int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize) +{ + LZ4_stream_t_internal* dict = &LZ4_dict->internal_donotuse; + const BYTE* p = (const BYTE*)dictionary; + const BYTE* const dictEnd = p + dictSize; + const BYTE* base; + + if ((dict->initCheck) || (dict->currentOffset > 1 GB)) /* Uninitialized structure, or reuse overflow */ + LZ4_resetStream(LZ4_dict); + + if (dictSize < (int)HASH_UNIT) { + dict->dictionary = NULL; + dict->dictSize = 0; + return 0; + } + + if ((dictEnd - p) > 64 KB) p = dictEnd - 64 KB; + dict->currentOffset += 64 KB; + base = p - dict->currentOffset; + dict->dictionary = p; + dict->dictSize = (U32)(dictEnd - p); + dict->currentOffset += dict->dictSize; + + while (p <= dictEnd-HASH_UNIT) { + LZ4_putPosition(p, dict->hashTable, byU32, base); + p+=3; + } + + return dict->dictSize; +} + + +static void LZ4_renormDictT(LZ4_stream_t_internal* LZ4_dict, const BYTE* src) +{ + if ((LZ4_dict->currentOffset > 0x80000000) || + ((uptrval)LZ4_dict->currentOffset > (uptrval)src)) { /* address space overflow */ + /* rescale hash table */ + U32 const delta = LZ4_dict->currentOffset - 64 KB; + const BYTE* dictEnd = LZ4_dict->dictionary + LZ4_dict->dictSize; + int i; + for (i=0; ihashTable[i] < delta) LZ4_dict->hashTable[i]=0; + else LZ4_dict->hashTable[i] -= delta; + } + LZ4_dict->currentOffset = 64 KB; + if (LZ4_dict->dictSize > 64 KB) LZ4_dict->dictSize = 64 KB; + LZ4_dict->dictionary = dictEnd - LZ4_dict->dictSize; + } +} + + +int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration) +{ + LZ4_stream_t_internal* streamPtr = &LZ4_stream->internal_donotuse; + const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize; + + const BYTE* smallest = (const BYTE*) source; + if (streamPtr->initCheck) return 0; /* Uninitialized structure detected */ + if ((streamPtr->dictSize>0) && (smallest>dictEnd)) smallest = dictEnd; + LZ4_renormDictT(streamPtr, smallest); + if (acceleration < 1) acceleration = ACCELERATION_DEFAULT; + + /* Check overlapping input/dictionary space */ + { const BYTE* sourceEnd = (const BYTE*) source + inputSize; + if ((sourceEnd > streamPtr->dictionary) && (sourceEnd < dictEnd)) { + streamPtr->dictSize = (U32)(dictEnd - sourceEnd); + if (streamPtr->dictSize > 64 KB) streamPtr->dictSize = 64 KB; + if (streamPtr->dictSize < 4) streamPtr->dictSize = 0; + streamPtr->dictionary = dictEnd - streamPtr->dictSize; + } + } + + /* prefix mode : source data follows dictionary */ + if (dictEnd == (const BYTE*)source) { + int result; + if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) + result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, dictSmall, acceleration); + else + result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k, noDictIssue, acceleration); + streamPtr->dictSize += (U32)inputSize; + streamPtr->currentOffset += (U32)inputSize; + return result; + } + + /* external dictionary mode */ + { int result; + if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) + result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, dictSmall, acceleration); + else + result = LZ4_compress_generic(streamPtr, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict, noDictIssue, acceleration); + streamPtr->dictionary = (const BYTE*)source; + streamPtr->dictSize = (U32)inputSize; + streamPtr->currentOffset += (U32)inputSize; + return result; + } +} + + +/* Hidden debug function, to force external dictionary mode */ +int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* dest, int inputSize) +{ + LZ4_stream_t_internal* streamPtr = &LZ4_dict->internal_donotuse; + int result; + const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize; + + const BYTE* smallest = dictEnd; + if (smallest > (const BYTE*) source) smallest = (const BYTE*) source; + LZ4_renormDictT(streamPtr, smallest); + + result = LZ4_compress_generic(streamPtr, source, dest, inputSize, 0, notLimited, byU32, usingExtDict, noDictIssue, 1); + + streamPtr->dictionary = (const BYTE*)source; + streamPtr->dictSize = (U32)inputSize; + streamPtr->currentOffset += (U32)inputSize; + + return result; +} + + +/*! LZ4_saveDict() : + * If previously compressed data block is not guaranteed to remain available at its memory location, + * save it into a safer place (char* safeBuffer). + * Note : you don't need to call LZ4_loadDict() afterwards, + * dictionary is immediately usable, you can therefore call LZ4_compress_fast_continue(). + * Return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error. + */ +int LZ4_saveDict (LZ4_stream_t* LZ4_dict, char* safeBuffer, int dictSize) +{ + LZ4_stream_t_internal* const dict = &LZ4_dict->internal_donotuse; + const BYTE* const previousDictEnd = dict->dictionary + dict->dictSize; + + if ((U32)dictSize > 64 KB) dictSize = 64 KB; /* useless to define a dictionary > 64 KB */ + if ((U32)dictSize > dict->dictSize) dictSize = dict->dictSize; + + memmove(safeBuffer, previousDictEnd - dictSize, dictSize); + + dict->dictionary = (const BYTE*)safeBuffer; + dict->dictSize = (U32)dictSize; + + return dictSize; +} + + + +/*-***************************** +* Decompression functions +*******************************/ +/*! LZ4_decompress_generic() : + * This generic decompression function cover all use cases. + * It shall be instantiated several times, using different sets of directives + * Note that it is important this generic function is really inlined, + * in order to remove useless branches during compilation optimization. + */ +FORCE_INLINE int LZ4_decompress_generic( + const char* const source, + char* const dest, + int inputSize, + int outputSize, /* If endOnInput==endOnInputSize, this value is the max size of Output Buffer. */ + + int endOnInput, /* endOnOutputSize, endOnInputSize */ + int partialDecoding, /* full, partial */ + int targetOutputSize, /* only used if partialDecoding==partial */ + int dict, /* noDict, withPrefix64k, usingExtDict */ + const BYTE* const lowPrefix, /* == dest when no prefix */ + const BYTE* const dictStart, /* only if dict==usingExtDict */ + const size_t dictSize /* note : = 0 if noDict */ + ) +{ + /* Local Variables */ + const BYTE* ip = (const BYTE*) source; + const BYTE* const iend = ip + inputSize; + + BYTE* op = (BYTE*) dest; + BYTE* const oend = op + outputSize; + BYTE* cpy; + BYTE* oexit = op + targetOutputSize; + const BYTE* const lowLimit = lowPrefix - dictSize; + + const BYTE* const dictEnd = (const BYTE*)dictStart + dictSize; + const unsigned dec32table[] = {0, 1, 2, 1, 4, 4, 4, 4}; + const int dec64table[] = {0, 0, 0, -1, 0, 1, 2, 3}; + + const int safeDecode = (endOnInput==endOnInputSize); + const int checkOffset = ((safeDecode) && (dictSize < (int)(64 KB))); + + + /* Special cases */ + if ((partialDecoding) && (oexit > oend-MFLIMIT)) oexit = oend-MFLIMIT; /* targetOutputSize too high => decode everything */ + if ((endOnInput) && (unlikely(outputSize==0))) return ((inputSize==1) && (*ip==0)) ? 0 : -1; /* Empty output buffer */ + if ((!endOnInput) && (unlikely(outputSize==0))) return (*ip==0?1:-1); + + /* Main Loop : decode sequences */ + while (1) { + size_t length; + const BYTE* match; + size_t offset; + + /* get literal length */ + unsigned const token = *ip++; + if ((length=(token>>ML_BITS)) == RUN_MASK) { + unsigned s; + do { + s = *ip++; + length += s; + } while ( likely(endOnInput ? ip(partialDecoding?oexit:oend-MFLIMIT)) || (ip+length>iend-(2+1+LASTLITERALS))) ) + || ((!endOnInput) && (cpy>oend-WILDCOPYLENGTH)) ) + { + if (partialDecoding) { + if (cpy > oend) goto _output_error; /* Error : write attempt beyond end of output buffer */ + if ((endOnInput) && (ip+length > iend)) goto _output_error; /* Error : read attempt beyond end of input buffer */ + } else { + if ((!endOnInput) && (cpy != oend)) goto _output_error; /* Error : block decoding must stop exactly there */ + if ((endOnInput) && ((ip+length != iend) || (cpy > oend))) goto _output_error; /* Error : input must be consumed */ + } + memcpy(op, ip, length); + ip += length; + op += length; + break; /* Necessarily EOF, due to parsing restrictions */ + } + LZ4_wildCopy(op, ip, cpy); + ip += length; op = cpy; + + /* get offset */ + offset = LZ4_readLE16(ip); ip+=2; + match = op - offset; + if ((checkOffset) && (unlikely(match < lowLimit))) goto _output_error; /* Error : offset outside buffers */ + LZ4_write32(op, (U32)offset); /* costs ~1%; silence an msan warning when offset==0 */ + + /* get matchlength */ + length = token & ML_MASK; + if (length == ML_MASK) { + unsigned s; + do { + s = *ip++; + if ((endOnInput) && (ip > iend-LASTLITERALS)) goto _output_error; + length += s; + } while (s==255); + if ((safeDecode) && unlikely((uptrval)(op)+length<(uptrval)op)) goto _output_error; /* overflow detection */ + } + length += MINMATCH; + + /* check external dictionary */ + if ((dict==usingExtDict) && (match < lowPrefix)) { + if (unlikely(op+length > oend-LASTLITERALS)) goto _output_error; /* doesn't respect parsing restriction */ + + if (length <= (size_t)(lowPrefix-match)) { + /* match can be copied as a single segment from external dictionary */ + memmove(op, dictEnd - (lowPrefix-match), length); + op += length; + } else { + /* match encompass external dictionary and current block */ + size_t const copySize = (size_t)(lowPrefix-match); + size_t const restSize = length - copySize; + memcpy(op, dictEnd - copySize, copySize); + op += copySize; + if (restSize > (size_t)(op-lowPrefix)) { /* overlap copy */ + BYTE* const endOfMatch = op + restSize; + const BYTE* copyFrom = lowPrefix; + while (op < endOfMatch) *op++ = *copyFrom++; + } else { + memcpy(op, lowPrefix, restSize); + op += restSize; + } } + continue; + } + + /* copy match within block */ + cpy = op + length; + if (unlikely(offset<8)) { + const int dec64 = dec64table[offset]; + op[0] = match[0]; + op[1] = match[1]; + op[2] = match[2]; + op[3] = match[3]; + match += dec32table[offset]; + memcpy(op+4, match, 4); + match -= dec64; + } else { LZ4_copy8(op, match); match+=8; } + op += 8; + + if (unlikely(cpy>oend-12)) { + BYTE* const oCopyLimit = oend-(WILDCOPYLENGTH-1); + if (cpy > oend-LASTLITERALS) goto _output_error; /* Error : last LASTLITERALS bytes must be literals (uncompressed) */ + if (op < oCopyLimit) { + LZ4_wildCopy(op, match, oCopyLimit); + match += oCopyLimit - op; + op = oCopyLimit; + } + while (op16) LZ4_wildCopy(op+8, match+8, cpy); + } + op=cpy; /* correction */ + } + + /* end of decoding */ + if (endOnInput) + return (int) (((char*)op)-dest); /* Nb of output bytes decoded */ + else + return (int) (((const char*)ip)-source); /* Nb of input bytes read */ + + /* Overflow error detected */ +_output_error: + return (int) (-(((const char*)ip)-source))-1; +} + + +int LZ4_decompress_safe(const char* source, char* dest, int compressedSize, int maxDecompressedSize) +{ + return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, endOnInputSize, full, 0, noDict, (BYTE*)dest, NULL, 0); +} + +int LZ4_decompress_safe_partial(const char* source, char* dest, int compressedSize, int targetOutputSize, int maxDecompressedSize) +{ + return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, endOnInputSize, partial, targetOutputSize, noDict, (BYTE*)dest, NULL, 0); +} + +int LZ4_decompress_fast(const char* source, char* dest, int originalSize) +{ + return LZ4_decompress_generic(source, dest, 0, originalSize, endOnOutputSize, full, 0, withPrefix64k, (BYTE*)(dest - 64 KB), NULL, 64 KB); +} + + +/*===== streaming decompression functions =====*/ + +LZ4_streamDecode_t* LZ4_createStreamDecode(void) +{ + LZ4_streamDecode_t* lz4s = (LZ4_streamDecode_t*) ALLOCATOR(1, sizeof(LZ4_streamDecode_t)); + return lz4s; +} + +int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream) +{ + if (!LZ4_stream) return 0; /* support free on NULL */ + FREEMEM(LZ4_stream); + return 0; +} + +/*! + * LZ4_setStreamDecode() : + * Use this function to instruct where to find the dictionary. + * This function is not necessary if previous data is still available where it was decoded. + * Loading a size of 0 is allowed (same effect as no dictionary). + * Return : 1 if OK, 0 if error + */ +int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize) +{ + LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse; + lz4sd->prefixSize = (size_t) dictSize; + lz4sd->prefixEnd = (const BYTE*) dictionary + dictSize; + lz4sd->externalDict = NULL; + lz4sd->extDictSize = 0; + return 1; +} + +/* +*_continue() : + These decoding functions allow decompression of multiple blocks in "streaming" mode. + Previously decoded blocks must still be available at the memory position where they were decoded. + If it's not possible, save the relevant part of decoded data into a safe buffer, + and indicate where it stands using LZ4_setStreamDecode() +*/ +int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxOutputSize) +{ + LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse; + int result; + + if (lz4sd->prefixEnd == (BYTE*)dest) { + result = LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, + endOnInputSize, full, 0, + usingExtDict, lz4sd->prefixEnd - lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize); + if (result <= 0) return result; + lz4sd->prefixSize += result; + lz4sd->prefixEnd += result; + } else { + lz4sd->extDictSize = lz4sd->prefixSize; + lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize; + result = LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, + endOnInputSize, full, 0, + usingExtDict, (BYTE*)dest, lz4sd->externalDict, lz4sd->extDictSize); + if (result <= 0) return result; + lz4sd->prefixSize = result; + lz4sd->prefixEnd = (BYTE*)dest + result; + } + + return result; +} + +int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int originalSize) +{ + LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse; + int result; + + if (lz4sd->prefixEnd == (BYTE*)dest) { + result = LZ4_decompress_generic(source, dest, 0, originalSize, + endOnOutputSize, full, 0, + usingExtDict, lz4sd->prefixEnd - lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize); + if (result <= 0) return result; + lz4sd->prefixSize += originalSize; + lz4sd->prefixEnd += originalSize; + } else { + lz4sd->extDictSize = lz4sd->prefixSize; + lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize; + result = LZ4_decompress_generic(source, dest, 0, originalSize, + endOnOutputSize, full, 0, + usingExtDict, (BYTE*)dest, lz4sd->externalDict, lz4sd->extDictSize); + if (result <= 0) return result; + lz4sd->prefixSize = originalSize; + lz4sd->prefixEnd = (BYTE*)dest + originalSize; + } + + return result; +} + + +/* +Advanced decoding functions : +*_usingDict() : + These decoding functions work the same as "_continue" ones, + the dictionary must be explicitly provided within parameters +*/ + +FORCE_INLINE int LZ4_decompress_usingDict_generic(const char* source, char* dest, int compressedSize, int maxOutputSize, int safe, const char* dictStart, int dictSize) +{ + if (dictSize==0) + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, noDict, (BYTE*)dest, NULL, 0); + if (dictStart+dictSize == dest) { + if (dictSize >= (int)(64 KB - 1)) + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, withPrefix64k, (BYTE*)dest-64 KB, NULL, 0); + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, noDict, (BYTE*)dest-dictSize, NULL, 0); + } + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, safe, full, 0, usingExtDict, (BYTE*)dest, (const BYTE*)dictStart, dictSize); +} + +int LZ4_decompress_safe_usingDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize) +{ + return LZ4_decompress_usingDict_generic(source, dest, compressedSize, maxOutputSize, 1, dictStart, dictSize); +} + +int LZ4_decompress_fast_usingDict(const char* source, char* dest, int originalSize, const char* dictStart, int dictSize) +{ + return LZ4_decompress_usingDict_generic(source, dest, 0, originalSize, 0, dictStart, dictSize); +} + +/* debug function */ +int LZ4_decompress_safe_forceExtDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize) +{ + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, usingExtDict, (BYTE*)dest, (const BYTE*)dictStart, dictSize); +} + + +/*=************************************************* +* Obsolete Functions +***************************************************/ +/* obsolete compression functions */ +int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize) { return LZ4_compress_default(source, dest, inputSize, maxOutputSize); } +int LZ4_compress(const char* source, char* dest, int inputSize) { return LZ4_compress_default(source, dest, inputSize, LZ4_compressBound(inputSize)); } +int LZ4_compress_limitedOutput_withState (void* state, const char* src, char* dst, int srcSize, int dstSize) { return LZ4_compress_fast_extState(state, src, dst, srcSize, dstSize, 1); } +int LZ4_compress_withState (void* state, const char* src, char* dst, int srcSize) { return LZ4_compress_fast_extState(state, src, dst, srcSize, LZ4_compressBound(srcSize), 1); } +int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* src, char* dst, int srcSize, int maxDstSize) { return LZ4_compress_fast_continue(LZ4_stream, src, dst, srcSize, maxDstSize, 1); } +int LZ4_compress_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize) { return LZ4_compress_fast_continue(LZ4_stream, source, dest, inputSize, LZ4_compressBound(inputSize), 1); } + +/* +These function names are deprecated and should no longer be used. +They are only provided here for compatibility with older user programs. +- LZ4_uncompress is totally equivalent to LZ4_decompress_fast +- LZ4_uncompress_unknownOutputSize is totally equivalent to LZ4_decompress_safe +*/ +int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); } +int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); } + + +/* Obsolete Streaming functions */ + +int LZ4_sizeofStreamState() { return LZ4_STREAMSIZE; } + +static void LZ4_init(LZ4_stream_t* lz4ds, BYTE* base) +{ + MEM_INIT(lz4ds, 0, sizeof(LZ4_stream_t)); + lz4ds->internal_donotuse.bufferStart = base; +} + +int LZ4_resetStreamState(void* state, char* inputBuffer) +{ + if ((((uptrval)state) & 3) != 0) return 1; /* Error : pointer is not aligned on 4-bytes boundary */ + LZ4_init((LZ4_stream_t*)state, (BYTE*)inputBuffer); + return 0; +} + +void* LZ4_create (char* inputBuffer) +{ + LZ4_stream_t* lz4ds = (LZ4_stream_t*)ALLOCATOR(8, sizeof(LZ4_stream_t)); + LZ4_init (lz4ds, (BYTE*)inputBuffer); + return lz4ds; +} + +char* LZ4_slideInputBuffer (void* LZ4_Data) +{ + LZ4_stream_t_internal* ctx = &((LZ4_stream_t*)LZ4_Data)->internal_donotuse; + int dictSize = LZ4_saveDict((LZ4_stream_t*)LZ4_Data, (char*)ctx->bufferStart, 64 KB); + return (char*)(ctx->bufferStart + dictSize); +} + +/* Obsolete streaming decompression functions */ + +int LZ4_decompress_safe_withPrefix64k(const char* source, char* dest, int compressedSize, int maxOutputSize) +{ + return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize, endOnInputSize, full, 0, withPrefix64k, (BYTE*)dest - 64 KB, NULL, 64 KB); +} + +int LZ4_decompress_fast_withPrefix64k(const char* source, char* dest, int originalSize) +{ + return LZ4_decompress_generic(source, dest, 0, originalSize, endOnOutputSize, full, 0, withPrefix64k, (BYTE*)dest - 64 KB, NULL, 64 KB); +} + +#endif /* LZ4_COMMONDEFS_ONLY */ diff --git a/samtools/lz4/lz4.h b/samtools/lz4/lz4.h new file mode 100644 index 000000000..86ca0d59c --- /dev/null +++ b/samtools/lz4/lz4.h @@ -0,0 +1,463 @@ +/* + * LZ4 - Fast LZ compression algorithm + * Header File + * Copyright (C) 2011-2017, Yann Collet. + + BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + You can contact the author at : + - LZ4 homepage : http://www.lz4.org + - LZ4 source repository : https://github.com/lz4/lz4 +*/ +#if defined (__cplusplus) +extern "C" { +#endif + +#ifndef LZ4_H_2983827168210 +#define LZ4_H_2983827168210 + +/* --- Dependency --- */ +#include /* size_t */ + + +/** + Introduction + + LZ4 is lossless compression algorithm, providing compression speed at 400 MB/s per core, + scalable with multi-cores CPU. It features an extremely fast decoder, with speed in + multiple GB/s per core, typically reaching RAM speed limits on multi-core systems. + + The LZ4 compression library provides in-memory compression and decompression functions. + Compression can be done in: + - a single step (described as Simple Functions) + - a single step, reusing a context (described in Advanced Functions) + - unbounded multiple steps (described as Streaming compression) + + lz4.h provides block compression functions. It gives full buffer control to user. + Decompressing an lz4-compressed block also requires metadata (such as compressed size). + Each application is free to encode such metadata in whichever way it wants. + + An additional format, called LZ4 frame specification (doc/lz4_Frame_format.md), + take care of encoding standard metadata alongside LZ4-compressed blocks. + If your application requires interoperability, it's recommended to use it. + A library is provided to take care of it, see lz4frame.h. +*/ + +/*^*************************************************************** +* Export parameters +*****************************************************************/ +/* +* LZ4_DLL_EXPORT : +* Enable exporting of functions when building a Windows DLL +* LZ4LIB_API : +* Control library symbols visibility. +*/ +#if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1) +# define LZ4LIB_API __declspec(dllexport) +#elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1) +# define LZ4LIB_API __declspec(dllimport) /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ +#elif defined(__GNUC__) && (__GNUC__ >= 4) +# define LZ4LIB_API __attribute__ ((__visibility__ ("default"))) +#else +# define LZ4LIB_API +#endif + + +/*------ Version ------*/ +#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */ +#define LZ4_VERSION_MINOR 8 /* for new (non-breaking) interface capabilities */ +#define LZ4_VERSION_RELEASE 0 /* for tweaks, bug-fixes, or development */ + +#define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE) + +#define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE +#define LZ4_QUOTE(str) #str +#define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str) +#define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION) + +LZ4LIB_API int LZ4_versionNumber (void); /**< library version number; to be used when checking dll version */ +LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; to be used when checking dll version */ + + +/*-************************************ +* Tuning parameter +**************************************/ +/*! + * LZ4_MEMORY_USAGE : + * Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.) + * Increasing memory usage improves compression ratio + * Reduced memory usage can improve speed, due to cache effect + * Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache + */ +#ifndef LZ4_MEMORY_USAGE +# define LZ4_MEMORY_USAGE 14 +#endif + +/*-************************************ +* Simple Functions +**************************************/ +/*! LZ4_compress_default() : + Compresses 'sourceSize' bytes from buffer 'source' + into already allocated 'dest' buffer of size 'maxDestSize'. + Compression is guaranteed to succeed if 'maxDestSize' >= LZ4_compressBound(sourceSize). + It also runs faster, so it's a recommended setting. + If the function cannot compress 'source' into a more limited 'dest' budget, + compression stops *immediately*, and the function result is zero. + As a consequence, 'dest' content is not valid. + This function never writes outside 'dest' buffer, nor read outside 'source' buffer. + sourceSize : Max supported value is LZ4_MAX_INPUT_VALUE + maxDestSize : full or partial size of buffer 'dest' (which must be already allocated) + return : the number of bytes written into buffer 'dest' (necessarily <= maxOutputSize) + or 0 if compression fails */ +LZ4LIB_API int LZ4_compress_default(const char* source, char* dest, int sourceSize, int maxDestSize); + +/*! LZ4_decompress_safe() : + compressedSize : is the precise full size of the compressed block. + maxDecompressedSize : is the size of destination buffer, which must be already allocated. + return : the number of bytes decompressed into destination buffer (necessarily <= maxDecompressedSize) + If destination buffer is not large enough, decoding will stop and output an error code (<0). + If the source stream is detected malformed, the function will stop decoding and return a negative result. + This function is protected against buffer overflow exploits, including malicious data packets. + It never writes outside output buffer, nor reads outside input buffer. +*/ +LZ4LIB_API int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize); + + +/*-************************************ +* Advanced Functions +**************************************/ +#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */ +#define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16) + +/*! +LZ4_compressBound() : + Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible) + This function is primarily useful for memory allocation purposes (destination buffer size). + Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example). + Note that LZ4_compress_default() compress faster when dest buffer size is >= LZ4_compressBound(srcSize) + inputSize : max supported value is LZ4_MAX_INPUT_SIZE + return : maximum output size in a "worst case" scenario + or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE) +*/ +LZ4LIB_API int LZ4_compressBound(int inputSize); + +/*! +LZ4_compress_fast() : + Same as LZ4_compress_default(), but allows to select an "acceleration" factor. + The larger the acceleration value, the faster the algorithm, but also the lesser the compression. + It's a trade-off. It can be fine tuned, with each successive value providing roughly +~3% to speed. + An acceleration value of "1" is the same as regular LZ4_compress_default() + Values <= 0 will be replaced by ACCELERATION_DEFAULT (see lz4.c), which is 1. +*/ +LZ4LIB_API int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxDestSize, int acceleration); + + +/*! +LZ4_compress_fast_extState() : + Same compression function, just using an externally allocated memory space to store compression state. + Use LZ4_sizeofState() to know how much memory must be allocated, + and allocate it on 8-bytes boundaries (using malloc() typically). + Then, provide it as 'void* state' to compression function. +*/ +LZ4LIB_API int LZ4_sizeofState(void); +LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* source, char* dest, int inputSize, int maxDestSize, int acceleration); + + +/*! +LZ4_compress_destSize() : + Reverse the logic, by compressing as much data as possible from 'source' buffer + into already allocated buffer 'dest' of size 'targetDestSize'. + This function either compresses the entire 'source' content into 'dest' if it's large enough, + or fill 'dest' buffer completely with as much data as possible from 'source'. + *sourceSizePtr : will be modified to indicate how many bytes where read from 'source' to fill 'dest'. + New value is necessarily <= old value. + return : Nb bytes written into 'dest' (necessarily <= targetDestSize) + or 0 if compression fails +*/ +LZ4LIB_API int LZ4_compress_destSize (const char* source, char* dest, int* sourceSizePtr, int targetDestSize); + + +/*! +LZ4_decompress_fast() : + originalSize : is the original and therefore uncompressed size + return : the number of bytes read from the source buffer (in other words, the compressed size) + If the source stream is detected malformed, the function will stop decoding and return a negative result. + Destination buffer must be already allocated. Its size must be a minimum of 'originalSize' bytes. + note : This function fully respect memory boundaries for properly formed compressed data. + It is a bit faster than LZ4_decompress_safe(). + However, it does not provide any protection against intentionally modified data stream (malicious input). + Use this function in trusted environment only (data to decode comes from a trusted source). +*/ +LZ4LIB_API int LZ4_decompress_fast (const char* source, char* dest, int originalSize); + +/*! +LZ4_decompress_safe_partial() : + This function decompress a compressed block of size 'compressedSize' at position 'source' + into destination buffer 'dest' of size 'maxDecompressedSize'. + The function tries to stop decompressing operation as soon as 'targetOutputSize' has been reached, + reducing decompression time. + return : the number of bytes decoded in the destination buffer (necessarily <= maxDecompressedSize) + Note : this number can be < 'targetOutputSize' should the compressed block to decode be smaller. + Always control how many bytes were decoded. + If the source stream is detected malformed, the function will stop decoding and return a negative result. + This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets +*/ +LZ4LIB_API int LZ4_decompress_safe_partial (const char* source, char* dest, int compressedSize, int targetOutputSize, int maxDecompressedSize); + + +/*-********************************************* +* Streaming Compression Functions +***********************************************/ +typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */ + +/*! LZ4_createStream() and LZ4_freeStream() : + * LZ4_createStream() will allocate and initialize an `LZ4_stream_t` structure. + * LZ4_freeStream() releases its memory. + */ +LZ4LIB_API LZ4_stream_t* LZ4_createStream(void); +LZ4LIB_API int LZ4_freeStream (LZ4_stream_t* streamPtr); + +/*! LZ4_resetStream() : + * An LZ4_stream_t structure can be allocated once and re-used multiple times. + * Use this function to init an allocated `LZ4_stream_t` structure and start a new compression. + */ +LZ4LIB_API void LZ4_resetStream (LZ4_stream_t* streamPtr); + +/*! LZ4_loadDict() : + * Use this function to load a static dictionary into LZ4_stream. + * Any previous data will be forgotten, only 'dictionary' will remain in memory. + * Loading a size of 0 is allowed. + * Return : dictionary size, in bytes (necessarily <= 64 KB) + */ +LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize); + +/*! LZ4_compress_fast_continue() : + * Compress buffer content 'src', using data from previously compressed blocks as dictionary to improve compression ratio. + * Important : Previous data blocks are assumed to remain present and unmodified ! + * 'dst' buffer must be already allocated. + * If dstCapacity >= LZ4_compressBound(srcSize), compression is guaranteed to succeed, and runs faster. + * If not, and if compressed data cannot fit into 'dst' buffer size, compression stops, and function @return==0. + * After an error, the stream status is invalid, it can only be reset or freed. + */ +LZ4LIB_API int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration); + +/*! LZ4_saveDict() : + * If previously compressed data block is not guaranteed to remain available at its current memory location, + * save it into a safer place (char* safeBuffer). + * Note : it's not necessary to call LZ4_loadDict() after LZ4_saveDict(), dictionary is immediately usable. + * @return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error. + */ +LZ4LIB_API int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int dictSize); + + +/*-********************************************** +* Streaming Decompression Functions +* Bufferless synchronous API +************************************************/ +typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* incomplete type (defined later) */ + +/*! LZ4_createStreamDecode() and LZ4_freeStreamDecode() : + * creation / destruction of streaming decompression tracking structure */ +LZ4LIB_API LZ4_streamDecode_t* LZ4_createStreamDecode(void); +LZ4LIB_API int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream); + +/*! LZ4_setStreamDecode() : + * Use this function to instruct where to find the dictionary. + * Setting a size of 0 is allowed (same effect as reset). + * @return : 1 if OK, 0 if error + */ +LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize); + +/*! LZ4_decompress_*_continue() : + * These decoding functions allow decompression of multiple blocks in "streaming" mode. + * Previously decoded blocks *must* remain available at the memory position where they were decoded (up to 64 KB) + * In the case of a ring buffers, decoding buffer must be either : + * - Exactly same size as encoding buffer, with same update rule (block boundaries at same positions) + * In which case, the decoding & encoding ring buffer can have any size, including very small ones ( < 64 KB). + * - Larger than encoding buffer, by a minimum of maxBlockSize more bytes. + * maxBlockSize is implementation dependent. It's the maximum size you intend to compress into a single block. + * In which case, encoding and decoding buffers do not need to be synchronized, + * and encoding ring buffer can have any size, including small ones ( < 64 KB). + * - _At least_ 64 KB + 8 bytes + maxBlockSize. + * In which case, encoding and decoding buffers do not need to be synchronized, + * and encoding ring buffer can have any size, including larger than decoding buffer. + * Whenever these conditions are not possible, save the last 64KB of decoded data into a safe buffer, + * and indicate where it is saved using LZ4_setStreamDecode() +*/ +LZ4LIB_API int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxDecompressedSize); +LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int originalSize); + + +/*! LZ4_decompress_*_usingDict() : + * These decoding functions work the same as + * a combination of LZ4_setStreamDecode() followed by LZ4_decompress_*_continue() + * They are stand-alone, and don't need an LZ4_streamDecode_t structure. + */ +LZ4LIB_API int LZ4_decompress_safe_usingDict (const char* source, char* dest, int compressedSize, int maxDecompressedSize, const char* dictStart, int dictSize); +LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalSize, const char* dictStart, int dictSize); + + +/*^********************************************** + * !!!!!! STATIC LINKING ONLY !!!!!! + ***********************************************/ +/*-************************************ + * Private definitions + ************************************** + * Do not use these definitions. + * They are exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`. + * Using these definitions will expose code to API and/or ABI break in future versions of the library. + **************************************/ +#define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2) +#define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE) +#define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */ + +#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) +#include + +typedef struct { + uint32_t hashTable[LZ4_HASH_SIZE_U32]; + uint32_t currentOffset; + uint32_t initCheck; + const uint8_t* dictionary; + uint8_t* bufferStart; /* obsolete, used for slideInputBuffer */ + uint32_t dictSize; +} LZ4_stream_t_internal; + +typedef struct { + const uint8_t* externalDict; + size_t extDictSize; + const uint8_t* prefixEnd; + size_t prefixSize; +} LZ4_streamDecode_t_internal; + +#else + +typedef struct { + unsigned int hashTable[LZ4_HASH_SIZE_U32]; + unsigned int currentOffset; + unsigned int initCheck; + const unsigned char* dictionary; + unsigned char* bufferStart; /* obsolete, used for slideInputBuffer */ + unsigned int dictSize; +} LZ4_stream_t_internal; + +typedef struct { + const unsigned char* externalDict; + size_t extDictSize; + const unsigned char* prefixEnd; + size_t prefixSize; +} LZ4_streamDecode_t_internal; + +#endif + +/*! + * LZ4_stream_t : + * information structure to track an LZ4 stream. + * init this structure before first use. + * note : only use in association with static linking ! + * this definition is not API/ABI safe, + * it may change in a future version ! + */ +#define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4) +#define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(unsigned long long)) +union LZ4_stream_u { + unsigned long long table[LZ4_STREAMSIZE_U64]; + LZ4_stream_t_internal internal_donotuse; +} ; /* previously typedef'd to LZ4_stream_t */ + + +/*! + * LZ4_streamDecode_t : + * information structure to track an LZ4 stream during decompression. + * init this structure using LZ4_setStreamDecode (or memset()) before first use + * note : only use in association with static linking ! + * this definition is not API/ABI safe, + * and may change in a future version ! + */ +#define LZ4_STREAMDECODESIZE_U64 4 +#define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long)) +union LZ4_streamDecode_u { + unsigned long long table[LZ4_STREAMDECODESIZE_U64]; + LZ4_streamDecode_t_internal internal_donotuse; +} ; /* previously typedef'd to LZ4_streamDecode_t */ + + +/*-************************************ +* Obsolete Functions +**************************************/ + +/*! Deprecation warnings + Should deprecation warnings be a problem, + it is generally possible to disable them, + typically with -Wno-deprecated-declarations for gcc + or _CRT_SECURE_NO_WARNINGS in Visual. + Otherwise, it's also possible to define LZ4_DISABLE_DEPRECATE_WARNINGS */ +#ifdef LZ4_DISABLE_DEPRECATE_WARNINGS +# define LZ4_DEPRECATED(message) /* disable deprecation warnings */ +#else +# define LZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) +# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */ +# define LZ4_DEPRECATED(message) [[deprecated(message)]] +# elif (LZ4_GCC_VERSION >= 405) || defined(__clang__) +# define LZ4_DEPRECATED(message) __attribute__((deprecated(message))) +# elif (LZ4_GCC_VERSION >= 301) +# define LZ4_DEPRECATED(message) __attribute__((deprecated)) +# elif defined(_MSC_VER) +# define LZ4_DEPRECATED(message) __declspec(deprecated(message)) +# else +# pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler") +# define LZ4_DEPRECATED(message) +# endif +#endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */ + +/* Obsolete compression functions */ +LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_default() instead") int LZ4_compress (const char* source, char* dest, int sourceSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_default() instead") int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize); + +/* Obsolete decompression functions */ +LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_fast() instead") int LZ4_uncompress (const char* source, char* dest, int outputSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_safe() instead") int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize); + +/* Obsolete streaming functions; use new streaming interface whenever possible */ +LZ4LIB_API LZ4_DEPRECATED("use LZ4_createStream() instead") void* LZ4_create (char* inputBuffer); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_createStream() instead") int LZ4_sizeofStreamState(void); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void* state, char* inputBuffer); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_saveDict() instead") char* LZ4_slideInputBuffer (void* state); + +/* Obsolete streaming decoding functions */ +LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize); +LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize); + +#endif /* LZ4_H_2983827168210 */ + + +#if defined (__cplusplus) +} +#endif diff --git a/samtools/misc/ace2sam.c b/samtools/misc/ace2sam.c index 77b9993cc..19727eb3f 100644 --- a/samtools/misc/ace2sam.c +++ b/samtools/misc/ace2sam.c @@ -161,7 +161,10 @@ int main(int argc, char *argv[]) } if (dret != '\n') ks_getuntil(ks, '\n', &s, &dret); ks_getuntil(ks, '\n', &s, &dret); // skip the empty line - if (write_cns) puts(t[4].s); t[4].l = 0; + if (write_cns) { + if (t[4].l) puts(t[4].s); + t[4].l = 0; + } } else if (strcmp(s.s, "AF") == 0) { // padded read position int reversed, neg, pos; if (t[0].l == 0) fatal("come to 'AF' before reading 'CO'"); diff --git a/samtools/misc/ace2sam.c.pysam.c b/samtools/misc/ace2sam.c.pysam.c index a663399c2..113596740 100644 --- a/samtools/misc/ace2sam.c.pysam.c +++ b/samtools/misc/ace2sam.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* The MIT License @@ -51,7 +51,7 @@ KSTREAM_INIT(gzFile, gzread, 16384) // a fatal error static void fatal(const char *msg) { - fprintf(pysam_stderr, "E %s\n", msg); + fprintf(samtools_stderr, "E %s\n", msg); exit(1); } // remove pads @@ -82,13 +82,13 @@ int samtools_ace2sam_main(int argc, char *argv[]) } } if (argc == optind) { - fprintf(pysam_stderr, "\nUsage: ace2sam [-pc] \n\n"); - fprintf(pysam_stderr, "Options: -p output padded SAM\n"); - fprintf(pysam_stderr, " -c write the contig sequence in SAM\n\n"); - fprintf(pysam_stderr, "Notes: 1. Fields must appear in the following order: (CO->[BQ]->(AF)->(RD->QA))\n"); - fprintf(pysam_stderr, " 2. The order of reads in AF and in RD must be identical\n"); - fprintf(pysam_stderr, " 3. Except in BQ, words and numbers must be separated by a single SPACE or TAB\n"); - fprintf(pysam_stderr, " 4. This program writes the headerless SAM to pysam_stdout and header to pysam_stderr\n\n"); + fprintf(samtools_stderr, "\nUsage: ace2sam [-pc] \n\n"); + fprintf(samtools_stderr, "Options: -p output padded SAM\n"); + fprintf(samtools_stderr, " -c write the contig sequence in SAM\n\n"); + fprintf(samtools_stderr, "Notes: 1. Fields must appear in the following order: (CO->[BQ]->(AF)->(RD->QA))\n"); + fprintf(samtools_stderr, " 2. The order of reads in AF and in RD must be identical\n"); + fprintf(samtools_stderr, " 3. Except in BQ, words and numbers must be separated by a single SPACE or TAB\n"); + fprintf(samtools_stderr, " 4. This program writes the headerless SAM to samtools_stdout and header to samtools_stderr\n\n"); return 1; } @@ -113,14 +113,14 @@ int samtools_ace2sam_main(int argc, char *argv[]) if (t[1].s[i] != '*') ++k; } // write out the SAM header and contig sequences - fprintf(pysam_stderr, "H @SQ\tSN:%s\tLN:%llu\n", t[0].s, (unsigned long long)(t[is_padded?1:2].l)); // The SAM header line + fprintf(samtools_stderr, "H @SQ\tSN:%s\tLN:%llu\n", t[0].s, (unsigned long long)(t[is_padded?1:2].l)); // The SAM header line cns = &t[is_padded?1:2]; - fprintf(pysam_stderr, "S >%s\n", t[0].s); + fprintf(samtools_stderr, "S >%s\n", t[0].s); for (i = 0; i < cns->l; i += LINE_LEN) { - fputs("S ", pysam_stderr); + fputs("S ", samtools_stderr); for (k = 0; k < LINE_LEN && i + k < cns->l; ++k) - fputc(cns->s[i + k], pysam_stderr); - fputc('\n', pysam_stderr); + fputc(cns->s[i + k], samtools_stderr); + fputc('\n', samtools_stderr); } #define __padded2cigar(sp) do { \ @@ -154,7 +154,7 @@ int samtools_ace2sam_main(int argc, char *argv[]) if (write_cns) t[4].s[--t[4].l] = 0; // remove the trailing "*" for (i = 0; i < t[2].l; ++i) { // read the consensus quality int q; - if (ks_getuntil(ks, 0, &s, &dret) < 0) fprintf(pysam_stderr, "E truncated contig quality\n"); + if (ks_getuntil(ks, 0, &s, &dret) < 0) fprintf(samtools_stderr, "E truncated contig quality\n"); if (s.l) { q = atoi(s.s) + 33; if (q > 126) q = 126; @@ -163,12 +163,15 @@ int samtools_ace2sam_main(int argc, char *argv[]) } if (dret != '\n') ks_getuntil(ks, '\n', &s, &dret); ks_getuntil(ks, '\n', &s, &dret); // skip the empty line - if (write_cns) fputs(t[4].s, pysam_stdout) & fputc('\n', pysam_stdout); t[4].l = 0; + if (write_cns) { + if (t[4].l) fputs(t[4].s, samtools_stdout) & fputc('\n', samtools_stdout); + t[4].l = 0; + } } else if (strcmp(s.s, "AF") == 0) { // padded read position int reversed, neg, pos; if (t[0].l == 0) fatal("come to 'AF' before reading 'CO'"); if (write_cns) { - if (t[4].l) fputs(t[4].s, pysam_stdout) & fputc('\n', pysam_stdout); + if (t[4].l) fputs(t[4].s, samtools_stdout) & fputc('\n', samtools_stdout); t[4].l = 0; } ks_getuntil(ks, 0, &s, &dret); // read name @@ -241,7 +244,7 @@ int samtools_ace2sam_main(int argc, char *argv[]) kputs("\t*\t0\t0\t", &t[4]); // empty MRNM, MPOS and TLEN kputsn(t[3].s, t[3].l, &t[4]); // unpadded SEQ kputs("\t*", &t[4]); // QUAL - fputs(t[4].s, pysam_stdout) & fputc('\n', pysam_stdout); // print to pysam_stdout + fputs(t[4].s, samtools_stdout) & fputc('\n', samtools_stdout); // print to samtools_stdout ++af_i; } else if (dret != '\n') ks_getuntil(ks, '\n', &s, &dret); } diff --git a/samtools/padding.c b/samtools/padding.c index cea79cfa6..650aff8a0 100644 --- a/samtools/padding.c +++ b/samtools/padding.c @@ -382,6 +382,7 @@ bam_hdr_t * fix_header(bam_hdr_t *old, faidx_t *fai) { int i = 0, unpadded_len = 0; bam_hdr_t *header = 0 ; + unsigned short ln_found; header = bam_hdr_dup(old); for (i = 0; i < old->n_targets; ++i) { @@ -418,27 +419,45 @@ bam_hdr_t * fix_header(bam_hdr_t *old, faidx_t *fai) name += 4; for (name_end = name; name_end != end && *name_end != '\t'; name_end++); strcat(newtext, "@SQ"); + ln_found = 0; /* Parse the @SQ lines */ while (cp != end) { - if (end-cp >= 2 && strncmp(cp, "LN", 2) == 0) { + if (!ln_found && end-cp >= 2 && strncmp(cp, "LN", 2) == 0) { // Rewrite the length char len_buf[100]; int tid; + unsigned int old_length, new_length; + const char *old_cp = cp; + + ln_found = 1; + + while (cp != end && *cp++ != '\t'); + old_length = (int)(cp - old_cp); + for (tid = 0; tid < header->n_targets; tid++) { // may want to hash this, but new header API incoming. if (strncmp(name, header->target_name[tid], name_end - name) == 0) { - sprintf(len_buf, "LN:%d", header->target_len[tid]); - strcat(newtext, len_buf); + new_length = sprintf(len_buf, "LN:%d", header->target_len[tid]); + if (new_length <= old_length) { + strcat(newtext, len_buf); + } + else { + fprintf(stderr, "LN value of the reference is larger than the original!\n"); + exit(1); + } break; } } - while (cp != end && *cp++ != '\t'); + if (cp != end) strcat(newtext, "\t"); } else if (end-cp >= 2 && - (strncmp(cp, "M5", 2) == 0 || - strncmp(cp, "UR", 2) == 0)) { + ((ln_found && strncmp(cp, "LN", 2) == 0) || + strncmp(cp, "M5", 2) == 0 || + strncmp(cp, "UR", 2) == 0)) + { + // skip secondary LNs // MD5 changed during depadding; ditch it. // URLs are also invalid. while (cp != end && *cp++ != '\t'); @@ -491,7 +510,7 @@ int main_pad2unpad(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 'T'), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 'T', '-'), { NULL, 0, NULL, 0 } }; @@ -603,7 +622,7 @@ static int usage(int is_long_help) fprintf(stderr, " Padded reference sequence file [null]\n"); fprintf(stderr, " -o FILE Output file name [stdout]\n"); fprintf(stderr, " -? Longer help\n"); - sam_global_opt_help(stderr, "-...-"); + sam_global_opt_help(stderr, "-...--"); if (is_long_help) fprintf(stderr, diff --git a/samtools/padding.c.pysam.c b/samtools/padding.c.pysam.c index 9f85c9580..dfaedb722 100644 --- a/samtools/padding.c.pysam.c +++ b/samtools/padding.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* padding.c -- depad subcommand. @@ -99,10 +99,10 @@ static int unpad_seq(bam1_t *b, kstring_t *s) for (i = 0; i < ol; ++i) s->s[s->l++] = 0; if (0 == cigar_n_warning) { cigar_n_warning = -1; - fprintf(pysam_stderr, "[depad] WARNING: CIGAR op N treated as op D in read %s\n", bam_get_qname(b)); + fprintf(samtools_stderr, "[depad] WARNING: CIGAR op N treated as op D in read %s\n", bam_get_qname(b)); } } else { - fprintf(pysam_stderr, "[depad] ERROR: Didn't expect CIGAR op %c in read %s\n", BAM_CIGAR_STR[op], bam_get_qname(b)); + fprintf(samtools_stderr, "[depad] ERROR: Didn't expect CIGAR op %c in read %s\n", BAM_CIGAR_STR[op], bam_get_qname(b)); return -1; } } @@ -117,7 +117,7 @@ int load_unpadded_ref(faidx_t *fai, char *ref_name, int ref_len, kstring_t *seq) fai_ref = fai_fetch(fai, ref_name, &fai_ref_len); if (fai_ref_len != ref_len) { - fprintf(pysam_stderr, "[depad] ERROR: FASTA sequence %s length %i, expected %i\n", ref_name, fai_ref_len, ref_len); + fprintf(samtools_stderr, "[depad] ERROR: FASTA sequence %s length %i, expected %i\n", ref_name, fai_ref_len, ref_len); free(fai_ref); return -1; } @@ -131,7 +131,7 @@ int load_unpadded_ref(faidx_t *fai, char *ref_name, int ref_len, kstring_t *seq) } else { int i = seq_nt16_table[(int)base]; if (i == 0 || i==16) { // Equals maps to 0, anything unexpected to 16 - fprintf(pysam_stderr, "[depad] ERROR: Invalid character %c (ASCII %i) in FASTA sequence %s\n", base, (int)base, ref_name); + fprintf(samtools_stderr, "[depad] ERROR: Invalid character %c (ASCII %i) in FASTA sequence %s\n", base, (int)base, ref_name); free(fai_ref); return -1; } @@ -152,19 +152,19 @@ int get_unpadded_len(faidx_t *fai, char *ref_name, int padded_len) fai_ref = fai_fetch(fai, ref_name, &fai_ref_len); if (fai_ref_len != padded_len) { - fprintf(pysam_stderr, "[depad] ERROR: FASTA sequence '%s' length %i, expected %i\n", ref_name, fai_ref_len, padded_len); + fprintf(samtools_stderr, "[depad] ERROR: FASTA sequence '%s' length %i, expected %i\n", ref_name, fai_ref_len, padded_len); free(fai_ref); return -1; } for (k = 0; k < padded_len; ++k) { - //fprintf(pysam_stderr, "[depad] checking base %i of %i or %i\n", k+1, ref_len, strlen(fai_ref)); + //fprintf(samtools_stderr, "[depad] checking base %i of %i or %i\n", k+1, ref_len, strlen(fai_ref)); base = fai_ref[k]; if (base == '-' || base == '*') { gaps += 1; } else { int i = seq_nt16_table[(int)base]; if (i == 0 || i==16) { // Equals maps to 0, anything unexpected to 16 - fprintf(pysam_stderr, "[depad] ERROR: Invalid character %c (ASCII %i) in FASTA sequence '%s'\n", base, (int)base, ref_name); + fprintf(samtools_stderr, "[depad] ERROR: Invalid character %c (ASCII %i) in FASTA sequence '%s'\n", base, (int)base, ref_name); free(fai_ref); return -1; } @@ -197,7 +197,7 @@ int bam_pad2unpad(samFile *in, samFile *out, bam_hdr_t *h, faidx_t *fai) b = bam_init1(); if (!b) { - fprintf(pysam_stderr, "[depad] Couldn't allocate bam struct\n"); + fprintf(samtools_stderr, "[depad] Couldn't allocate bam struct\n"); return -1; } r.l = r.m = q.l = q.m = 0; r.s = q.s = 0; @@ -210,20 +210,20 @@ int bam_pad2unpad(samFile *in, samFile *out, bam_hdr_t *h, faidx_t *fai) uint32_t *cigar = bam_get_cigar(b); n2 = 0; if (b->core.pos == 0 && b->core.tid >= 0 && strcmp(bam_get_qname(b), h->target_name[b->core.tid]) == 0) { - // fprintf(pysam_stderr, "[depad] Found embedded reference '%s'\n", bam_get_qname(b)); + // fprintf(samtools_stderr, "[depad] Found embedded reference '%s'\n", bam_get_qname(b)); r_tid = b->core.tid; if (0!=unpad_seq(b, &r)) { - fprintf(pysam_stderr, "[depad] ERROR: Problem parsing SEQ and/or CIGAR in reference %s\n", bam_get_qname(b)); + fprintf(samtools_stderr, "[depad] ERROR: Problem parsing SEQ and/or CIGAR in reference %s\n", bam_get_qname(b)); return -1; }; if (h->target_len[r_tid] != r.l) { - fprintf(pysam_stderr, "[depad] ERROR: (Padded) length of '%s' is %u in BAM header, but %llu in embedded reference\n", bam_get_qname(b), h->target_len[r_tid], (unsigned long long)(r.l)); + fprintf(samtools_stderr, "[depad] ERROR: (Padded) length of '%s' is %u in BAM header, but %llu in embedded reference\n", bam_get_qname(b), h->target_len[r_tid], (unsigned long long)(r.l)); return -1; } if (fai) { // Check the embedded reference matches the FASTA file if (load_unpadded_ref(fai, h->target_name[b->core.tid], h->target_len[b->core.tid], &q)) { - fprintf(pysam_stderr, "[depad] ERROR: Failed to load embedded reference '%s' from FASTA\n", h->target_name[b->core.tid]); + fprintf(samtools_stderr, "[depad] ERROR: Failed to load embedded reference '%s' from FASTA\n", h->target_name[b->core.tid]); return -1; } assert(r.l == q.l); @@ -231,7 +231,7 @@ int bam_pad2unpad(samFile *in, samFile *out, bam_hdr_t *h, faidx_t *fai) for (i = 0; i < r.l; ++i) { if (r.s[i] != q.s[i]) { // Show gaps as ASCII 45 - fprintf(pysam_stderr, "[depad] ERROR: Embedded sequence and reference FASTA don't match for %s base %i, '%c' vs '%c'\n", + fprintf(samtools_stderr, "[depad] ERROR: Embedded sequence and reference FASTA don't match for %s base %i, '%c' vs '%c'\n", h->target_name[b->core.tid], i+1, r.s[i] ? seq_nt16_str[(int)r.s[i]] : 45, q.s[i] ? seq_nt16_str[(int)q.s[i]] : 45); @@ -245,25 +245,25 @@ int bam_pad2unpad(samFile *in, samFile *out, bam_hdr_t *h, faidx_t *fai) } else if (b->core.n_cigar > 0) { int i, k, op; if (b->core.tid < 0) { - fprintf(pysam_stderr, "[depad] ERROR: Read '%s' has CIGAR but no RNAME\n", bam_get_qname(b)); + fprintf(samtools_stderr, "[depad] ERROR: Read '%s' has CIGAR but no RNAME\n", bam_get_qname(b)); return -1; } else if (b->core.tid == r_tid) { ; // good case, reference available - //fprintf(pysam_stderr, "[depad] Have ref '%s' for read '%s'\n", h->target_name[b->core.tid], bam_get_qname(b)); + //fprintf(samtools_stderr, "[depad] Have ref '%s' for read '%s'\n", h->target_name[b->core.tid], bam_get_qname(b)); } else if (fai) { if (load_unpadded_ref(fai, h->target_name[b->core.tid], h->target_len[b->core.tid], &r)) { - fprintf(pysam_stderr, "[depad] ERROR: Failed to load '%s' from reference FASTA\n", h->target_name[b->core.tid]); + fprintf(samtools_stderr, "[depad] ERROR: Failed to load '%s' from reference FASTA\n", h->target_name[b->core.tid]); return -1; } posmap = update_posmap(posmap, r); r_tid = b->core.tid; - // fprintf(pysam_stderr, "[depad] Loaded %s from FASTA file\n", h->target_name[b->core.tid]); + // fprintf(samtools_stderr, "[depad] Loaded %s from FASTA file\n", h->target_name[b->core.tid]); } else { - fprintf(pysam_stderr, "[depad] ERROR: Missing %s embedded reference sequence (and no FASTA file)\n", h->target_name[b->core.tid]); + fprintf(samtools_stderr, "[depad] ERROR: Missing %s embedded reference sequence (and no FASTA file)\n", h->target_name[b->core.tid]); return -1; } if (0!=unpad_seq(b, &q)) { - fprintf(pysam_stderr, "[depad] ERROR: Problem parsing SEQ and/or CIGAR in read %s\n", bam_get_qname(b)); + fprintf(samtools_stderr, "[depad] ERROR: Problem parsing SEQ and/or CIGAR in read %s\n", bam_get_qname(b)); return -1; }; if (bam_cigar_op(cigar[0]) == BAM_CSOFT_CLIP) { @@ -332,32 +332,32 @@ int bam_pad2unpad(samFile *in, samFile *out, bam_hdr_t *h, faidx_t *fai) if (b->core.pos != -1) b->core.pos = posmap[b->core.pos]; if (b->core.mtid < 0 || b->core.mpos < 0) { /* Nice case, no mate to worry about*/ - // fprintf(pysam_stderr, "[depad] Read '%s' mate not mapped\n", bam_get_qname(b)); + // fprintf(samtools_stderr, "[depad] Read '%s' mate not mapped\n", bam_get_qname(b)); /* TODO - Warning if FLAG says mate should be mapped? */ /* Clean up funny input where mate position is given but mate reference is missing: */ b->core.mtid = -1; b->core.mpos = -1; } else if (b->core.mtid == b->core.tid) { /* Nice case, same reference */ - // fprintf(pysam_stderr, "[depad] Read '%s' mate mapped to same ref\n", bam_get_qname(b)); + // fprintf(samtools_stderr, "[depad] Read '%s' mate mapped to same ref\n", bam_get_qname(b)); b->core.mpos = posmap[b->core.mpos]; } else { /* Nasty case, Must load alternative posmap */ - // fprintf(pysam_stderr, "[depad] Loading reference '%s' temporarily\n", h->target_name[b->core.mtid]); + // fprintf(samtools_stderr, "[depad] Loading reference '%s' temporarily\n", h->target_name[b->core.mtid]); if (!fai) { - fprintf(pysam_stderr, "[depad] ERROR: Needed reference %s sequence for mate (and no FASTA file)\n", h->target_name[b->core.mtid]); + fprintf(samtools_stderr, "[depad] ERROR: Needed reference %s sequence for mate (and no FASTA file)\n", h->target_name[b->core.mtid]); return -1; } /* Temporarily load the other reference sequence */ if (load_unpadded_ref(fai, h->target_name[b->core.mtid], h->target_len[b->core.mtid], &r)) { - fprintf(pysam_stderr, "[depad] ERROR: Failed to load '%s' from reference FASTA\n", h->target_name[b->core.mtid]); + fprintf(samtools_stderr, "[depad] ERROR: Failed to load '%s' from reference FASTA\n", h->target_name[b->core.mtid]); return -1; } posmap = update_posmap(posmap, r); b->core.mpos = posmap[b->core.mpos]; /* Restore the reference and posmap*/ if (load_unpadded_ref(fai, h->target_name[b->core.tid], h->target_len[b->core.tid], &r)) { - fprintf(pysam_stderr, "[depad] ERROR: Failed to load '%s' from reference FASTA\n", h->target_name[b->core.tid]); + fprintf(samtools_stderr, "[depad] ERROR: Failed to load '%s' from reference FASTA\n", h->target_name[b->core.tid]); return -1; } posmap = update_posmap(posmap, r); @@ -372,7 +372,7 @@ int bam_pad2unpad(samFile *in, samFile *out, bam_hdr_t *h, faidx_t *fai) } } if (read_ret < -1) { - fprintf(pysam_stderr, "[depad] truncated file.\n"); + fprintf(samtools_stderr, "[depad] truncated file.\n"); ret = 1; } free(r.s); free(q.s); free(posmap); @@ -384,15 +384,16 @@ bam_hdr_t * fix_header(bam_hdr_t *old, faidx_t *fai) { int i = 0, unpadded_len = 0; bam_hdr_t *header = 0 ; + unsigned short ln_found; header = bam_hdr_dup(old); for (i = 0; i < old->n_targets; ++i) { unpadded_len = get_unpadded_len(fai, old->target_name[i], old->target_len[i]); if (unpadded_len < 0) { - fprintf(pysam_stderr, "[depad] ERROR getting unpadded length of '%s', padded length %i\n", old->target_name[i], old->target_len[i]); + fprintf(samtools_stderr, "[depad] ERROR getting unpadded length of '%s', padded length %i\n", old->target_name[i], old->target_len[i]); } else { header->target_len[i] = unpadded_len; - //fprintf(pysam_stderr, "[depad] Recalculating '%s' length %i -> %i\n", old->target_name[i], old->target_len[i], header->target_len[i]); + //fprintf(samtools_stderr, "[depad] Recalculating '%s' length %i -> %i\n", old->target_name[i], old->target_len[i], header->target_len[i]); } } /* Duplicating the header allocated new buffer for header string */ @@ -414,33 +415,51 @@ bam_hdr_t * fix_header(bam_hdr_t *old, faidx_t *fai) char *name = strstr(text, "\tSN:"); char *name_end; if (!name) { - fprintf(pysam_stderr, "Unable to find SN: header field\n"); + fprintf(samtools_stderr, "Unable to find SN: header field\n"); return NULL; } name += 4; for (name_end = name; name_end != end && *name_end != '\t'; name_end++); strcat(newtext, "@SQ"); + ln_found = 0; /* Parse the @SQ lines */ while (cp != end) { - if (end-cp >= 2 && strncmp(cp, "LN", 2) == 0) { + if (!ln_found && end-cp >= 2 && strncmp(cp, "LN", 2) == 0) { // Rewrite the length char len_buf[100]; int tid; + unsigned int old_length, new_length; + const char *old_cp = cp; + + ln_found = 1; + + while (cp != end && *cp++ != '\t'); + old_length = (int)(cp - old_cp); + for (tid = 0; tid < header->n_targets; tid++) { // may want to hash this, but new header API incoming. if (strncmp(name, header->target_name[tid], name_end - name) == 0) { - sprintf(len_buf, "LN:%d", header->target_len[tid]); - strcat(newtext, len_buf); + new_length = sprintf(len_buf, "LN:%d", header->target_len[tid]); + if (new_length <= old_length) { + strcat(newtext, len_buf); + } + else { + fprintf(samtools_stderr, "LN value of the reference is larger than the original!\n"); + exit(1); + } break; } } - while (cp != end && *cp++ != '\t'); + if (cp != end) strcat(newtext, "\t"); } else if (end-cp >= 2 && - (strncmp(cp, "M5", 2) == 0 || - strncmp(cp, "UR", 2) == 0)) { + ((ln_found && strncmp(cp, "LN", 2) == 0) || + strncmp(cp, "M5", 2) == 0 || + strncmp(cp, "UR", 2) == 0)) + { + // skip secondary LNs // MD5 changed during depadding; ditch it. // URLs are also invalid. while (cp != end && *cp++ != '\t'); @@ -468,7 +487,7 @@ bam_hdr_t * fix_header(bam_hdr_t *old, faidx_t *fai) /* Check we didn't overflow the buffer */ assert (strlen(header->text) <= strlen(old->text)); if (strlen(header->text) < header->l_text) { - //fprintf(pysam_stderr, "[depad] Reallocating header buffer\n"); + //fprintf(samtools_stderr, "[depad] Reallocating header buffer\n"); assert (newtext == header->text); newtext = malloc(strlen(header->text) + 1); strcpy(newtext, header->text); @@ -476,7 +495,7 @@ bam_hdr_t * fix_header(bam_hdr_t *old, faidx_t *fai) header->text = newtext; header->l_text = strlen(newtext); } - //fprintf(pysam_stderr, "[depad] Here is the new header (pending @SQ lines),\n\n%s\n(end)\n", header->text); + //fprintf(samtools_stderr, "[depad] Here is the new header (pending @SQ lines),\n\n%s\n(end)\n", header->text); return header; } @@ -493,7 +512,7 @@ int main_pad2unpad(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 'T'), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 'T', '-'), { NULL, 0, NULL, 0 } }; @@ -517,7 +536,7 @@ int main_pad2unpad(int argc, char *argv[]) break; case '?': is_long_help = 1; break; default: if (parse_sam_global_opt(c, optarg, lopts, &ga) == 0) break; - fprintf(pysam_stderr, "[bam_fillmd] unrecognized option '-%c'\n\n", c); + fprintf(samtools_stderr, "[bam_fillmd] unrecognized option '-%c'\n\n", c); return usage(is_long_help); } } @@ -542,19 +561,19 @@ int main_pad2unpad(int argc, char *argv[]) goto depad_end; } if (fn_list && hts_set_fai_filename(in, fn_list) != 0) { - fprintf(pysam_stderr, "[depad] failed to load reference file \"%s\".\n", fn_list); + fprintf(samtools_stderr, "[depad] failed to load reference file \"%s\".\n", fn_list); ret = 1; goto depad_end; } if ((h = sam_hdr_read(in)) == 0) { - fprintf(pysam_stderr, "[depad] failed to read the header from \"%s\".\n", argv[optind]); + fprintf(samtools_stderr, "[depad] failed to read the header from \"%s\".\n", argv[optind]); ret = 1; goto depad_end; } if (fai) { h_fix = fix_header(h, fai); } else { - fprintf(pysam_stderr, "[depad] Warning - reference lengths will not be corrected without FASTA reference\n"); + fprintf(samtools_stderr, "[depad] Warning - reference lengths will not be corrected without FASTA reference\n"); h_fix = h; } char wmode[2]; @@ -571,7 +590,7 @@ int main_pad2unpad(int argc, char *argv[]) hts_set_opt(out, CRAM_OPT_NO_REF, 1); if (sam_hdr_write(out, h_fix) != 0) { - fprintf(pysam_stderr, "[depad] failed to write header.\n"); + fprintf(samtools_stderr, "[depad] failed to write header.\n"); ret = 1; goto depad_end; } @@ -585,7 +604,7 @@ int main_pad2unpad(int argc, char *argv[]) if (h) bam_hdr_destroy(h); if (in) sam_close(in); if (out && sam_close(out) < 0) { - fprintf(pysam_stderr, "[depad] error on closing output file.\n"); + fprintf(samtools_stderr, "[depad] error on closing output file.\n"); ret = 1; } free(fn_list); free(fn_out); @@ -594,21 +613,21 @@ int main_pad2unpad(int argc, char *argv[]) static int usage(int is_long_help) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Usage: samtools depad \n\n"); - fprintf(pysam_stderr, "Options:\n"); - fprintf(pysam_stderr, " -s Output is SAM (default is BAM)\n"); - fprintf(pysam_stderr, " -S Input is SAM (default is BAM)\n"); - fprintf(pysam_stderr, " -u Uncompressed BAM output (can't use with -s)\n"); - fprintf(pysam_stderr, " -1 Fast compression BAM output (can't use with -s)\n"); - fprintf(pysam_stderr, " -T, --reference FILE\n"); - fprintf(pysam_stderr, " Padded reference sequence file [null]\n"); - fprintf(pysam_stderr, " -o FILE Output file name [pysam_stdout]\n"); - fprintf(pysam_stderr, " -? Longer help\n"); - sam_global_opt_help(pysam_stderr, "-...-"); + fprintf(samtools_stderr, "\n"); + fprintf(samtools_stderr, "Usage: samtools depad \n\n"); + fprintf(samtools_stderr, "Options:\n"); + fprintf(samtools_stderr, " -s Output is SAM (default is BAM)\n"); + fprintf(samtools_stderr, " -S Input is SAM (default is BAM)\n"); + fprintf(samtools_stderr, " -u Uncompressed BAM output (can't use with -s)\n"); + fprintf(samtools_stderr, " -1 Fast compression BAM output (can't use with -s)\n"); + fprintf(samtools_stderr, " -T, --reference FILE\n"); + fprintf(samtools_stderr, " Padded reference sequence file [null]\n"); + fprintf(samtools_stderr, " -o FILE Output file name [samtools_stdout]\n"); + fprintf(samtools_stderr, " -? Longer help\n"); + sam_global_opt_help(samtools_stderr, "-...--"); if (is_long_help) - fprintf(pysam_stderr, + fprintf(samtools_stderr, "Notes:\n" "\n" "1. Requires embedded reference sequences (before the reads for that reference),\n" diff --git a/samtools/phase.c b/samtools/phase.c index 69099125c..0e00d9b0f 100644 --- a/samtools/phase.c +++ b/samtools/phase.c @@ -31,11 +31,12 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include "htslib/hts.h" #include "htslib/sam.h" #include "htslib/kstring.h" -#include "errmod.h" #include "sam_opts.h" #include "samtools.h" +#include "htslib/hts_os.h" #include "htslib/kseq.h" KSTREAM_INIT(gzFile, gzread, 16384) @@ -580,7 +581,7 @@ int main_phase(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0, '-'), { NULL, 0, NULL, 0 } }; @@ -620,7 +621,7 @@ int main_phase(int argc, char *argv[]) // fprintf(stderr, " -e do not discover SNPs (effective with -l)\n"); fprintf(stderr, "\n"); - sam_global_opt_help(stderr, "-...."); + sam_global_opt_help(stderr, "-....-"); return 1; } diff --git a/samtools/phase.c.pysam.c b/samtools/phase.c.pysam.c index 3babd3704..f74ba489c 100644 --- a/samtools/phase.c.pysam.c +++ b/samtools/phase.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* phase.c -- phase subcommand. @@ -33,11 +33,12 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include "htslib/hts.h" #include "htslib/sam.h" #include "htslib/kstring.h" -#include "errmod.h" #include "sam_opts.h" #include "samtools.h" +#include "htslib/hts_os.h" #include "htslib/kseq.h" KSTREAM_INIT(gzFile, gzread, 16384) @@ -392,8 +393,8 @@ static int phase(phaseg_t *g, const char *chr, int vpos, uint64_t *cns, nseq_t * i = clean_seqs(vpos, hash); // i is true if hash has an element with its vpos >= vpos min_pos = i? cns[vpos]>>32 : 0x7fffffff; if (vpos == 1) { - fprintf(pysam_stdout, "PS\t%s\t%d\t%d\n", chr, (int)(cns[0]>>32) + 1, (int)(cns[0]>>32) + 1); - fprintf(pysam_stdout, "M0\t%s\t%d\t%d\t%c\t%c\t%d\t0\t0\t0\t0\n//\n", chr, (int)(cns[0]>>32) + 1, (int)(cns[0]>>32) + 1, + fprintf(samtools_stdout, "PS\t%s\t%d\t%d\n", chr, (int)(cns[0]>>32) + 1, (int)(cns[0]>>32) + 1); + fprintf(samtools_stdout, "M0\t%s\t%d\t%d\t%c\t%c\t%d\t0\t0\t0\t0\n//\n", chr, (int)(cns[0]>>32) + 1, (int)(cns[0]>>32) + 1, "ACGTX"[cns[0]&3], "ACGTX"[cns[0]>>16&3], g->vpos_shift + 1); for (k = 0; k < kh_end(hash); ++k) { if (kh_exist(hash, k)) { @@ -411,7 +412,7 @@ static int phase(phaseg_t *g, const char *chr, int vpos, uint64_t *cns, nseq_t * { // phase int **cnt; uint64_t *mask; - fprintf(pysam_stdout, "PS\t%s\t%d\t%d\n", chr, (int)(cns[0]>>32) + 1, (int)(cns[vpos-1]>>32) + 1); + fprintf(samtools_stdout, "PS\t%s\t%d\t%d\n", chr, (int)(cns[0]>>32) + 1, (int)(cns[vpos-1]>>32) + 1); sitemask = calloc(vpos, 1); cnt = count_all(g->k, vpos, hash); path = dynaprog(g->k, vpos, cnt); @@ -432,13 +433,13 @@ static int phase(phaseg_t *g, const char *chr, int vpos, uint64_t *cns, nseq_t * } } for (i = 0; i < n_masked; ++i) - fprintf(pysam_stdout, "FL\t%s\t%d\t%d\n", chr, (int)(regmask[i]>>32) + 1, (int)regmask[i] + 1); + fprintf(samtools_stdout, "FL\t%s\t%d\t%d\n", chr, (int)(regmask[i]>>32) + 1, (int)regmask[i] + 1); for (i = 0; i < vpos; ++i) { uint64_t x = pcnt[i]; int8_t c[2]; c[0] = (cns[i]&0xffff)>>2 == 0? 4 : (cns[i]&3); c[1] = (cns[i]>>16&0xffff)>>2 == 0? 4 : (cns[i]>>16&3); - fprintf(pysam_stdout, "M%d\t%s\t%d\t%d\t%c\t%c\t%d\t%d\t%d\t%d\t%d\n", sitemask[i]+1, chr, (int)(cns[0]>>32) + 1, (int)(cns[i]>>32) + 1, "ACGTX"[c[path[i]]], "ACGTX"[c[1-path[i]]], + fprintf(samtools_stdout, "M%d\t%s\t%d\t%d\t%c\t%c\t%d\t%d\t%d\t%d\t%d\n", sitemask[i]+1, chr, (int)(cns[0]>>32) + 1, (int)(cns[i]>>32) + 1, "ACGTX"[c[path[i]]], "ACGTX"[c[1-path[i]]], i + g->vpos_shift + 1, (int)(x&0xffff), (int)(x>>16&0xffff), (int)(x>>32&0xffff), (int)(x>>48&0xffff)); } free(path); free(pcnt); free(regmask); free(sitemask); @@ -450,17 +451,17 @@ static int phase(phaseg_t *g, const char *chr, int vpos, uint64_t *cns, nseq_t * ks_introsort_rseq(n_seqs, seqs); for (i = 0; i < n_seqs; ++i) { frag_t *f = seqs[i]; - fprintf(pysam_stdout, "EV\t0\t%s\t%d\t40\t%dM\t*\t0\t0\t", chr, f->vpos + 1 + g->vpos_shift, f->vlen); + fprintf(samtools_stdout, "EV\t0\t%s\t%d\t40\t%dM\t*\t0\t0\t", chr, f->vpos + 1 + g->vpos_shift, f->vlen); for (j = 0; j < f->vlen; ++j) { uint32_t c = cns[f->vpos + j]; - if (f->seq[j] == 0) fputc('N', pysam_stdout); - else fputc("ACGT"[f->seq[j] == 1? (c&3) : (c>>16&3)], pysam_stdout); + if (f->seq[j] == 0) fputc('N', samtools_stdout); + else fputc("ACGT"[f->seq[j] == 1? (c&3) : (c>>16&3)], samtools_stdout); } - fprintf(pysam_stdout, "\t*\tYP:i:%d\tYF:i:%d\tYI:i:%d\tYO:i:%d\tYS:i:%d\n", f->phase, f->flip, f->in, f->out, f->beg+1); + fprintf(samtools_stdout, "\t*\tYP:i:%d\tYF:i:%d\tYI:i:%d\tYO:i:%d\tYS:i:%d\n", f->phase, f->flip, f->in, f->out, f->beg+1); } free(seqs); - fprintf(pysam_stdout, "//\n"); - fflush(pysam_stdout); + fprintf(samtools_stdout, "//\n"); + fflush(samtools_stdout); g->vpos_shift += vpos; if (dump_aln(g, min_pos, hash) < 0) return -1; return vpos; @@ -582,7 +583,7 @@ int main_phase(int argc, char *argv[]) sam_global_args ga = SAM_GLOBAL_ARGS_INIT; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, 0, 0, 0, '-'), { NULL, 0, NULL, 0 } }; @@ -609,20 +610,20 @@ int main_phase(int argc, char *argv[]) if (usage) break; } if (usage || argc == optind) { - fprintf(pysam_stderr, "\n"); - fprintf(pysam_stderr, "Usage: samtools phase [options] \n\n"); - fprintf(pysam_stderr, "Options: -k INT block length [%d]\n", g.k); - fprintf(pysam_stderr, " -b STR prefix of BAMs to output [null]\n"); - fprintf(pysam_stderr, " -q INT min het phred-LOD [%d]\n", g.min_varLOD); - fprintf(pysam_stderr, " -Q INT min base quality in het calling [%d]\n", g.min_baseQ); - fprintf(pysam_stderr, " -D INT max read depth [%d]\n", g.max_depth); -// fprintf(pysam_stderr, " -l FILE list of sites to phase [null]\n"); - fprintf(pysam_stderr, " -F do not attempt to fix chimeras\n"); - fprintf(pysam_stderr, " -A drop reads with ambiguous phase\n"); -// fprintf(pysam_stderr, " -e do not discover SNPs (effective with -l)\n"); - fprintf(pysam_stderr, "\n"); - - sam_global_opt_help(pysam_stderr, "-...."); + fprintf(samtools_stderr, "\n"); + fprintf(samtools_stderr, "Usage: samtools phase [options] \n\n"); + fprintf(samtools_stderr, "Options: -k INT block length [%d]\n", g.k); + fprintf(samtools_stderr, " -b STR prefix of BAMs to output [null]\n"); + fprintf(samtools_stderr, " -q INT min het phred-LOD [%d]\n", g.min_varLOD); + fprintf(samtools_stderr, " -Q INT min base quality in het calling [%d]\n", g.min_baseQ); + fprintf(samtools_stderr, " -D INT max read depth [%d]\n", g.max_depth); +// fprintf(samtools_stderr, " -l FILE list of sites to phase [null]\n"); + fprintf(samtools_stderr, " -F do not attempt to fix chimeras\n"); + fprintf(samtools_stderr, " -A drop reads with ambiguous phase\n"); +// fprintf(samtools_stderr, " -e do not discover SNPs (effective with -l)\n"); + fprintf(samtools_stderr, "\n"); + + sam_global_opt_help(samtools_stderr, "-....-"); return 1; } @@ -633,7 +634,7 @@ int main_phase(int argc, char *argv[]) } g.fp_hdr = sam_hdr_read(g.fp); if (g.fp_hdr == NULL) { - fprintf(pysam_stderr, "[%s] Failed to read header for '%s'\n", + fprintf(samtools_stderr, "[%s] Failed to read header for '%s'\n", __func__, argv[optind]); return 1; } @@ -656,20 +657,20 @@ int main_phase(int argc, char *argv[]) seqs = kh_init(64); em = errmod_init(1. - 0.83); bases = calloc(g.max_depth, 2); - fprintf(pysam_stdout, "CC\n"); - fprintf(pysam_stdout, "CC\tDescriptions:\nCC\n"); - fprintf(pysam_stdout, "CC\t CC comments\n"); - fprintf(pysam_stdout, "CC\t PS start of a phase set\n"); - fprintf(pysam_stdout, "CC\t FL filtered region\n"); - fprintf(pysam_stdout, "CC\t M[012] markers; 0 for singletons, 1 for phased and 2 for filtered\n"); - fprintf(pysam_stdout, "CC\t EV supporting reads; SAM format\n"); - fprintf(pysam_stdout, "CC\t // end of a phase set\nCC\n"); - fprintf(pysam_stdout, "CC\tFormats of PS, FL and M[012] lines (1-based coordinates):\nCC\n"); - fprintf(pysam_stdout, "CC\t PS chr phaseSetStart phaseSetEnd\n"); - fprintf(pysam_stdout, "CC\t FL chr filterStart filterEnd\n"); - fprintf(pysam_stdout, "CC\t M? chr PS pos allele0 allele1 hetIndex #supports0 #errors0 #supp1 #err1\n"); - fprintf(pysam_stdout, "CC\nCC\n"); - fflush(pysam_stdout); + fprintf(samtools_stdout, "CC\n"); + fprintf(samtools_stdout, "CC\tDescriptions:\nCC\n"); + fprintf(samtools_stdout, "CC\t CC comments\n"); + fprintf(samtools_stdout, "CC\t PS start of a phase set\n"); + fprintf(samtools_stdout, "CC\t FL filtered region\n"); + fprintf(samtools_stdout, "CC\t M[012] markers; 0 for singletons, 1 for phased and 2 for filtered\n"); + fprintf(samtools_stdout, "CC\t EV supporting reads; SAM format\n"); + fprintf(samtools_stdout, "CC\t // end of a phase set\nCC\n"); + fprintf(samtools_stdout, "CC\tFormats of PS, FL and M[012] lines (1-based coordinates):\nCC\n"); + fprintf(samtools_stdout, "CC\t PS chr phaseSetStart phaseSetEnd\n"); + fprintf(samtools_stdout, "CC\t FL chr filterStart filterEnd\n"); + fprintf(samtools_stdout, "CC\t M? chr PS pos allele0 allele1 hetIndex #supports0 #errors0 #supp1 #err1\n"); + fprintf(samtools_stdout, "CC\nCC\n"); + fflush(samtools_stdout); while ((plp = bam_plp_auto(iter, &tid, &pos, &n)) != 0) { int i, k, c, tmp, dophase = 1, in_set = 0; float q[16]; @@ -776,7 +777,7 @@ int main_phase(int argc, char *argv[]) int res = 0; for (c = 0; c <= 2; ++c) { if (sam_close(g.out[c]) < 0) { - fprintf(pysam_stderr, "[%s] error on closing '%s'\n", + fprintf(samtools_stderr, "[%s] error on closing '%s'\n", __func__, g.out_name[c]); res = 1; } diff --git a/samtools/pysam.h b/samtools/pysam.h deleted file mode 100644 index b0fc4fb56..000000000 --- a/samtools/pysam.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef PYSAM_H -#define PYSAM_H -#include "stdio.h" -extern FILE * pysam_stderr; -extern FILE * pysam_stdout; -extern const char * pysam_stdout_fn; -#endif diff --git a/samtools/sam.c.pysam.c b/samtools/sam.c.pysam.c index f7db82090..457769dbd 100644 --- a/samtools/sam.c.pysam.c +++ b/samtools/sam.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* sam.c -- format-neutral SAM/BAM API. @@ -68,7 +68,7 @@ samfile_t *samopen(const char *fn, const char *mode, const void *aux) } fp->is_write = 0; if (fp->header->n_targets == 0 && bam_verbose >= 1) - fprintf(pysam_stderr, "[samopen] no @SQ lines in the header.\n"); + fprintf(samtools_stderr, "[samopen] no @SQ lines in the header.\n"); } else { enum htsExactFormat fmt = hts_get_format(fp->file)->format; @@ -77,7 +77,7 @@ samfile_t *samopen(const char *fn, const char *mode, const void *aux) if (!(fmt == text_format || fmt == sam) || strchr(mode, 'h')) { if (sam_hdr_write(fp->file, fp->header) < 0) { if (bam_verbose >= 1) - fprintf(pysam_stderr, "[samopen] Couldn't write header\n"); + fprintf(samtools_stderr, "[samopen] Couldn't write header\n"); sam_close(hts_fp); free(fp); return NULL; @@ -136,11 +136,11 @@ char *samfaipath(const char *fn_ref) strcat(strcpy(fn_list, fn_ref), ".fai"); if (access(fn_list, R_OK) == -1) { // fn_list is unreadable if (access(fn_ref, R_OK) == -1) { - fprintf(pysam_stderr, "[samfaipath] fail to read file %s.\n", fn_ref); + fprintf(samtools_stderr, "[samfaipath] fail to read file %s.\n", fn_ref); } else { - if (bam_verbose >= 3) fprintf(pysam_stderr, "[samfaipath] build FASTA index...\n"); + if (bam_verbose >= 3) fprintf(samtools_stderr, "[samfaipath] build FASTA index...\n"); if (fai_build(fn_ref) == -1) { - fprintf(pysam_stderr, "[samfaipath] fail to build FASTA index.\n"); + fprintf(samtools_stderr, "[samfaipath] fail to build FASTA index.\n"); free(fn_list); fn_list = 0; } } diff --git a/samtools/sam.h b/samtools/sam.h index 513010512..6545e640b 100644 --- a/samtools/sam.h +++ b/samtools/sam.h @@ -50,7 +50,7 @@ typedef struct { samFile *file; struct { BGZF *bam; } x; // Hack so that fp->x.bam still works bam_hdr_t *header; - short is_write:1; + unsigned short is_write:1; } samfile_t; #ifdef __cplusplus diff --git a/samtools/sam_header.c b/samtools/sam_header.c index 64da68f37..defa5c3a4 100644 --- a/samtools/sam_header.c +++ b/samtools/sam_header.c @@ -713,7 +713,7 @@ void *sam_header2key_val(void *iter, const char type[2], const char key_tag[2], HeaderTag *key, *value; key = header_line_has_tag(hline,key_tag); value = header_line_has_tag(hline,value_tag); - if ( !key && !value ) + if ( !key || !value ) { l = l->next; continue; diff --git a/samtools/sam_header.c.pysam.c b/samtools/sam_header.c.pysam.c index e39807d15..32332bd1a 100644 --- a/samtools/sam_header.c.pysam.c +++ b/samtools/sam_header.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* sam_header.c -- basic SAM/BAM header API. @@ -83,7 +83,7 @@ static void debug(const char *format, ...) { va_list ap; va_start(ap, format); - vfprintf(pysam_stderr, format, ap); + vfprintf(samtools_stderr, format, ap); va_end(ap); } @@ -715,7 +715,7 @@ void *sam_header2key_val(void *iter, const char type[2], const char key_tag[2], HeaderTag *key, *value; key = header_line_has_tag(hline,key_tag); value = header_line_has_tag(hline,value_tag); - if ( !key && !value ) + if ( !key || !value ) { l = l->next; continue; @@ -777,8 +777,8 @@ void *sam_header_merge(int n, const void **_dicts) if ( status==2 ) { - print_header_line(pysam_stderr,tmpl_hlines->data); - print_header_line(pysam_stderr,out_hlines->data); + print_header_line(samtools_stderr,tmpl_hlines->data); + print_header_line(samtools_stderr,out_hlines->data); debug("Conflicting lines, cannot merge the headers.\n"); return 0; } diff --git a/samtools/sam_opts.c b/samtools/sam_opts.c index 936914562..9e7a8dee6 100644 --- a/samtools/sam_opts.c +++ b/samtools/sam_opts.c @@ -72,6 +72,9 @@ int parse_sam_global_opt(int c, const char *optarg, const struct option *lopt, r |= hts_opt_add((hts_opt **)&ga->out.specific, ref); free(ref); break; + } else if (strcmp(lopt->name, "threads") == 0) { + ga->nthreads = atoi(optarg); + break; // } else if (strcmp(lopt->name, "verbose") == 0) { // ga->verbosity++; // break; @@ -100,7 +103,7 @@ void sam_global_opt_help(FILE *fp, const char *shortopts) { int i = 0; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS(0,0,0,0,0), + SAM_OPT_GLOBAL_OPTIONS(0,0,0,0,0,0), { NULL, 0, NULL, 0 } }; @@ -130,6 +133,9 @@ void sam_global_opt_help(FILE *fp, const char *shortopts) { else if (strcmp(lopts[i].name, "reference") == 0) fprintf(fp,"reference FILE\n" " Reference sequence FASTA FILE [null]\n"); + else if (strcmp(lopts[i].name, "threads") == 0) + fprintf(fp,"threads INT\n" + " Number of additional threads to use [0]\n"); // else if (strcmp(lopts[i].name, "verbose") == 0) // fprintf(fp,"verbose\n" // " Increment level of verbosity\n"); diff --git a/samtools/sam_opts.c.pysam.c b/samtools/sam_opts.c.pysam.c index d0b56a32e..d96520821 100644 --- a/samtools/sam_opts.c.pysam.c +++ b/samtools/sam_opts.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* sam_opts.c -- utilities to aid parsing common command line options. @@ -74,6 +74,9 @@ int parse_sam_global_opt(int c, const char *optarg, const struct option *lopt, r |= hts_opt_add((hts_opt **)&ga->out.specific, ref); free(ref); break; + } else if (strcmp(lopt->name, "threads") == 0) { + ga->nthreads = atoi(optarg); + break; // } else if (strcmp(lopt->name, "verbose") == 0) { // ga->verbosity++; // break; @@ -81,7 +84,7 @@ int parse_sam_global_opt(int c, const char *optarg, const struct option *lopt, } if (!lopt->name) { - fprintf(pysam_stderr, "Unexpected global option: %s\n", lopt->name); + fprintf(samtools_stderr, "Unexpected global option: %s\n", lopt->name); return -1; } @@ -102,7 +105,7 @@ void sam_global_opt_help(FILE *fp, const char *shortopts) { int i = 0; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS(0,0,0,0,0), + SAM_OPT_GLOBAL_OPTIONS(0,0,0,0,0,0), { NULL, 0, NULL, 0 } }; @@ -132,6 +135,9 @@ void sam_global_opt_help(FILE *fp, const char *shortopts) { else if (strcmp(lopts[i].name, "reference") == 0) fprintf(fp,"reference FILE\n" " Reference sequence FASTA FILE [null]\n"); + else if (strcmp(lopts[i].name, "threads") == 0) + fprintf(fp,"threads INT\n" + " Number of additional threads to use [0]\n"); // else if (strcmp(lopts[i].name, "verbose") == 0) // fprintf(fp,"verbose\n" // " Increment level of verbosity\n"); diff --git a/samtools/sam_opts.h b/samtools/sam_opts.h index 25e9279e0..6edbf6408 100644 --- a/samtools/sam_opts.h +++ b/samtools/sam_opts.h @@ -34,6 +34,7 @@ typedef struct sam_global_args { htsFormat in; htsFormat out; char *reference; + int nthreads; //int verbosity; } sam_global_args; @@ -45,6 +46,7 @@ enum { SAM_OPT_OUTPUT_FMT, SAM_OPT_OUTPUT_FMT_OPTION, SAM_OPT_REFERENCE, + SAM_OPT_NTHREADS, //SAM_OPT_VERBOSE }; @@ -56,12 +58,13 @@ enum { // 0 No short option has been assigned. Use --long-opt only. // '-' Both long and short options are disabled. // Otherwise the equivalent short option is character . -#define SAM_OPT_GLOBAL_OPTIONS(o1, o2, o3, o4, o5) \ +#define SAM_OPT_GLOBAL_OPTIONS(o1, o2, o3, o4, o5, o6) \ {"input-fmt", required_argument, NULL, SAM_OPT_VAL(o1, SAM_OPT_INPUT_FMT)}, \ {"input-fmt-option", required_argument, NULL, SAM_OPT_VAL(o2, SAM_OPT_INPUT_FMT_OPTION)}, \ {"output-fmt", required_argument, NULL, SAM_OPT_VAL(o3, SAM_OPT_OUTPUT_FMT)}, \ {"output-fmt-option", required_argument, NULL, SAM_OPT_VAL(o4, SAM_OPT_OUTPUT_FMT_OPTION)}, \ - {"reference", required_argument, NULL, SAM_OPT_VAL(o5, SAM_OPT_REFERENCE)} + {"reference", required_argument, NULL, SAM_OPT_VAL(o5, SAM_OPT_REFERENCE)}, \ + {"threads", required_argument, NULL, SAM_OPT_VAL(o6, SAM_OPT_NTHREADS)} //{"verbose", no_argument, NULL, SAM_OPT_VERBOSE} /* diff --git a/samtools/sam_utils.c b/samtools/sam_utils.c new file mode 100644 index 000000000..efa6e2fb1 --- /dev/null +++ b/samtools/sam_utils.c @@ -0,0 +1,88 @@ +/* sam_utils.c -- various utilities internal to samtools. + + Copyright (C) 2014-2016 Genome Research Ltd. + + Author: John Marshall + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include + +#include +#include +#include +#include +#include + +#include "samtools.h" +#include "version.h" + +static void vprint_error_core(const char *subcommand, const char *format, va_list args, const char *extra) +{ + fflush(stdout); + if (subcommand && *subcommand) fprintf(stderr, "samtools %s: ", subcommand); + else fprintf(stderr, "samtools: "); + vfprintf(stderr, format, args); + if (extra) fprintf(stderr, ": %s\n", extra); + else fprintf(stderr, "\n"); + fflush(stderr); +} + +void print_error(const char *subcommand, const char *format, ...) +{ + va_list args; + va_start(args, format); + vprint_error_core(subcommand, format, args, NULL); + va_end(args); +} + +void print_error_errno(const char *subcommand, const char *format, ...) +{ + int err = errno; + va_list args; + va_start(args, format); + vprint_error_core(subcommand, format, args, err? strerror(err) : NULL); + va_end(args); +} + +const char *samtools_version() +{ + return SAMTOOLS_VERSION; +} + +const char *samtools_version_short() +{ + char *sv, *hyph, *v; + int len; + + v = SAMTOOLS_VERSION; + hyph = strchr(v, '-'); + if (!hyph) + return strdup(v); + + len = hyph - v; + sv = (char *)malloc(len+1); + if (!sv) + return NULL; + + strncpy(sv, v, len); + sv[len] = '\0'; + + return (const char*)sv; +} diff --git a/samtools/sam_utils.c.pysam.c b/samtools/sam_utils.c.pysam.c new file mode 100644 index 000000000..53f1763cb --- /dev/null +++ b/samtools/sam_utils.c.pysam.c @@ -0,0 +1,90 @@ +#include "samtools.pysam.h" + +/* sam_utils.c -- various utilities internal to samtools. + + Copyright (C) 2014-2016 Genome Research Ltd. + + Author: John Marshall + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ + +#include + +#include +#include +#include +#include +#include + +#include "samtools.h" +#include "version.h" + +static void vprint_error_core(const char *subcommand, const char *format, va_list args, const char *extra) +{ + fflush(samtools_stdout); + if (subcommand && *subcommand) fprintf(samtools_stderr, "samtools %s: ", subcommand); + else fprintf(samtools_stderr, "samtools: "); + vfprintf(samtools_stderr, format, args); + if (extra) fprintf(samtools_stderr, ": %s\n", extra); + else fprintf(samtools_stderr, "\n"); + fflush(samtools_stderr); +} + +void print_error(const char *subcommand, const char *format, ...) +{ + va_list args; + va_start(args, format); + vprint_error_core(subcommand, format, args, NULL); + va_end(args); +} + +void print_error_errno(const char *subcommand, const char *format, ...) +{ + int err = errno; + va_list args; + va_start(args, format); + vprint_error_core(subcommand, format, args, err? strerror(err) : NULL); + va_end(args); +} + +const char *samtools_version() +{ + return SAMTOOLS_VERSION; +} + +const char *samtools_version_short() +{ + char *sv, *hyph, *v; + int len; + + v = SAMTOOLS_VERSION; + hyph = strchr(v, '-'); + if (!hyph) + return strdup(v); + + len = hyph - v; + sv = (char *)malloc(len+1); + if (!sv) + return NULL; + + strncpy(sv, v, len); + sv[len] = '\0'; + + return (const char*)sv; +} diff --git a/samtools/sam_view.c b/samtools/sam_view.c index 402e1d30f..bce2c0643 100644 --- a/samtools/sam_view.c +++ b/samtools/sam_view.c @@ -1,6 +1,6 @@ /* sam_view.c -- SAM<->BAM<->CRAM conversion. - Copyright (C) 2009-2015 Genome Research Ltd. + Copyright (C) 2009-2017 Genome Research Ltd. Portions copyright (C) 2009, 2011, 2012 Broad Institute. Author: Heng Li @@ -27,6 +27,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include +#include #include #include #include @@ -34,13 +35,24 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include #include "htslib/sam.h" #include "htslib/faidx.h" #include "htslib/kstring.h" #include "htslib/khash.h" +#include "htslib/klist.h" +#include "htslib/thread_pool.h" +#include "htslib/bgzf.h" #include "samtools.h" #include "sam_opts.h" +#include "bedidx.h" + +#define DEFAULT_BARCODE_TAG "BC" +#define DEFAULT_QUALITY_TAG "QT" + KHASH_SET_INIT_STR(rg) +#define taglist_free(p) +KLIST_INIT(ktaglist, char*, taglist_free) typedef khash_t(rg) *rghash_t; @@ -50,6 +62,7 @@ typedef struct samview_settings { int min_mapQ; int flag_on; int flag_off; + int flag_alloff; int min_qlen; int remove_B; uint32_t subsam_seed; @@ -58,6 +71,7 @@ typedef struct samview_settings { void* bed; size_t remove_aux_len; char** remove_aux; + int multi_region; } samview_settings_t; @@ -65,9 +79,6 @@ typedef struct samview_settings { extern const char *bam_get_library(bam_hdr_t *header, const bam1_t *b); extern int bam_remove_B(bam1_t *b); extern char *samfaipath(const char *fn_ref); -void *bed_read(const char *fn); -void bed_destroy(void *_h); -int bed_overlap(const void *_h, const char *chr, int beg, int end); // Returns 0 to indicate read should be output 1 otherwise static int process_aln(const bam_hdr_t *h, bam1_t *b, samview_settings_t* settings) @@ -83,7 +94,9 @@ static int process_aln(const bam_hdr_t *h, bam1_t *b, samview_settings_t* settin } if (b->core.qual < settings->min_mapQ || ((b->core.flag & settings->flag_on) != settings->flag_on) || (b->core.flag & settings->flag_off)) return 1; - if (settings->bed && (b->core.tid < 0 || !bed_overlap(settings->bed, h->target_name[b->core.tid], b->core.pos, bam_endpos(b)))) + if (settings->flag_alloff && ((b->core.flag & settings->flag_alloff) == settings->flag_alloff)) + return 1; + if (!settings->multi_region && settings->bed && (b->core.tid < 0 || !bed_overlap(settings->bed, h->target_name[b->core.tid], b->core.pos, bam_endpos(b)))) return 1; if (settings->subsam_frac > 0.) { uint32_t k = __ac_Wang_hash(__ac_X31_hash_string(bam_get_qname(b)) ^ settings->subsam_seed); @@ -231,30 +244,35 @@ static void check_sam_close(const char *subcmd, samFile *fp, const char *fname, int main_samview(int argc, char *argv[]) { int c, is_header = 0, is_header_only = 0, ret = 0, compress_level = -1, is_count = 0; - int is_long_help = 0, n_threads = 0; + int is_long_help = 0; int64_t count = 0; samFile *in = 0, *out = 0, *un_out=0; + FILE *fp_out = NULL; bam_hdr_t *header = NULL; char out_mode[5], out_un_mode[5], *out_format = ""; char *fn_in = 0, *fn_out = 0, *fn_list = 0, *q, *fn_un_out = 0; sam_global_args ga = SAM_GLOBAL_ARGS_INIT; + htsThreadPool p = {NULL, 0}; + int filter_state = ALL, filter_op = 0; + int result; samview_settings_t settings = { .rghash = NULL, .min_mapQ = 0, .flag_on = 0, .flag_off = 0, + .flag_alloff = 0, .min_qlen = 0, .remove_B = 0, .subsam_seed = 0, .subsam_frac = -1., .library = NULL, .bed = NULL, + .multi_region = 0 }; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 'T'), - { "threads", required_argument, NULL, '@' }, + SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 'T', '@'), { NULL, 0, NULL, 0 } }; @@ -262,11 +280,13 @@ int main_samview(int argc, char *argv[]) strcpy(out_mode, "w"); strcpy(out_un_mode, "w"); while ((c = getopt_long(argc, argv, - "SbBcCt:h1Ho:O:q:f:F:ul:r:?T:R:L:s:@:m:x:U:", + "SbBcCt:h1Ho:O:q:f:F:G:ul:r:?T:R:L:s:@:m:x:U:M", lopts, NULL)) >= 0) { switch (c) { case 's': if ((settings.subsam_seed = strtol(optarg, &q, 10)) != 0) { + // Convert likely user input 0,1,2,... to pseudo-random + // values with more entropy and more bits set srand(settings.subsam_seed); settings.subsam_seed = rand(); } @@ -284,6 +304,7 @@ int main_samview(int argc, char *argv[]) case 'U': fn_un_out = strdup(optarg); break; case 'f': settings.flag_on |= strtol(optarg, 0, 0); break; case 'F': settings.flag_off |= strtol(optarg, 0, 0); break; + case 'G': settings.flag_alloff |= strtol(optarg, 0, 0); break; case 'q': settings.min_mapQ = atoi(optarg); break; case 'u': compress_level = 0; break; case '1': compress_level = 1; break; @@ -313,7 +334,6 @@ int main_samview(int argc, char *argv[]) */ case '?': is_long_help = 1; break; case 'B': settings.remove_B = 1; break; - case '@': n_threads = strtol(optarg, 0, 0); break; case 'x': { if (strlen(optarg) != 2) { @@ -324,7 +344,7 @@ int main_samview(int argc, char *argv[]) settings.remove_aux[settings.remove_aux_len-1] = optarg; } break; - + case 'M': settings.multi_region = 1; break; default: if (parse_sam_global_opt(c, optarg, lopts, &ga) != 0) return usage(stderr, EXIT_FAILURE, is_long_help); @@ -425,49 +445,91 @@ int main_samview(int argc, char *argv[]) } } } + else { + if (fn_out) { + fp_out = fopen(fn_out, "w"); + if (fp_out == NULL) { + print_error_errno("view", "can't create \"%s\"", fn_out); + ret = EXIT_FAILURE; + goto view_end; + } + } + } - if (n_threads > 1) { if (out) hts_set_threads(out, n_threads); } + if (ga.nthreads > 1) { + if (!(p.pool = hts_tpool_init(ga.nthreads))) { + fprintf(stderr, "Error creating thread pool\n"); + ret = 1; + goto view_end; + } + hts_set_opt(in, HTS_OPT_THREAD_POOL, &p); + if (out) hts_set_opt(out, HTS_OPT_THREAD_POOL, &p); + } if (is_header_only) goto view_end; // no need to print alignments - if (optind + 1 >= argc) { // convert/print the entire file + if (settings.multi_region) { + if (optind < argc - 1) { //regions have been specified in the command line + settings.bed = bed_hash_regions(settings.bed, argv, optind+1, argc, &filter_op); //insert(1) or filter out(0) the regions from the command line in the same hash table as the bed file + if (!filter_op) + filter_state = FILTERED; + } + bam1_t *b = bam_init1(); - int r; - while ((r = sam_read1(in, header, b)) >= 0) { // read one alignment from `in' - if (!process_aln(header, b, &settings)) { - if (!is_count) { if (check_sam_write1(out, header, b, fn_out, &ret) < 0) break; } - count++; + if (settings.bed == NULL) { // index is unavailable or no regions have been specified + while ((result = sam_read1(in, header, b)) >= 0) { // read one alignment from `in' + if (!process_aln(header, b, &settings)) { + if (!is_count) { if (check_sam_write1(out, header, b, fn_out, &ret) < 0) break; } + count++; + } else { + if (un_out) { if (check_sam_write1(un_out, header, b, fn_un_out, &ret) < 0) break; } + } + } + if (result < -1) { + fprintf(stderr, "[main_samview] truncated file.\n"); + ret = 1; + } + } else { + hts_idx_t *idx = sam_index_load(in, fn_in); // load index + if (idx != NULL) { + + int regcount = 0; + + hts_reglist_t *reglist = bed_reglist(settings.bed, filter_state, ®count); + if(reglist) { + hts_itr_multi_t *iter = sam_itr_regions(idx, header, reglist, regcount); + if (iter) { + // fetch alignments + while ((result = sam_itr_multi_next(in, iter, b)) >= 0) { + if (!process_aln(header, b, &settings)) { + if (!is_count) { if (check_sam_write1(out, header, b, fn_out, &ret) < 0) break; } + count++; + } else { + if (un_out) { if (check_sam_write1(un_out, header, b, fn_un_out, &ret) < 0) break; } + } + } + if (result < -1) { + fprintf(stderr, "[main_samview] retrieval of region %d failed due to truncated file or corrupt BAM index file\n", iter->curr_tid); + ret = 1; + } + + hts_itr_multi_destroy(iter); + } else { + fprintf(stderr, "[main_samview] iterator could not be created. Aborting.\n"); + } + } else { + fprintf(stderr, "[main_samview] region list is empty or could not be created. Aborting.\n"); + } + hts_idx_destroy(idx); // destroy the BAM index } else { - if (un_out) { if (check_sam_write1(un_out, header, b, fn_un_out, &ret) < 0) break; } + fprintf(stderr, "[main_samview] random alignment retrieval only works for indexed BAM or CRAM files.\n"); } } - if (r < -1) { - fprintf(stderr, "[main_samview] truncated file.\n"); - ret = 1; - } bam_destroy1(b); - } else { // retrieve alignments in specified regions - int i; - bam1_t *b; - hts_idx_t *idx = sam_index_load(in, fn_in); // load index - if (idx == 0) { // index is unavailable - fprintf(stderr, "[main_samview] random alignment retrieval only works for indexed BAM or CRAM files.\n"); - ret = 1; - goto view_end; - } - b = bam_init1(); - for (i = optind + 1; i < argc; ++i) { - int result; - hts_itr_t *iter = sam_itr_querys(idx, header, argv[i]); // parse a region in the format like `chr2:100-200' - if (iter == NULL) { // region invalid or reference name not found - int beg, end; - if (hts_parse_reg(argv[i], &beg, &end)) - fprintf(stderr, "[main_samview] region \"%s\" specifies an unknown reference name. Continue anyway.\n", argv[i]); - else - fprintf(stderr, "[main_samview] region \"%s\" could not be parsed. Continue anyway.\n", argv[i]); - continue; - } - // fetch alignments - while ((result = sam_itr_next(in, iter, b)) >= 0) { + } else { + if (optind + 1 >= argc) { // convert/print the entire file + bam1_t *b = bam_init1(); + int r; + while ((r = sam_read1(in, header, b)) >= 0) { // read one alignment from `in' if (!process_aln(header, b, &settings)) { if (!is_count) { if (check_sam_write1(out, header, b, fn_out, &ret) < 0) break; } count++; @@ -475,25 +537,67 @@ int main_samview(int argc, char *argv[]) if (un_out) { if (check_sam_write1(un_out, header, b, fn_un_out, &ret) < 0) break; } } } - hts_itr_destroy(iter); - if (result < -1) { - fprintf(stderr, "[main_samview] retrieval of region \"%s\" failed due to truncated file or corrupt BAM index file\n", argv[i]); + if (r < -1) { + fprintf(stderr, "[main_samview] truncated file.\n"); ret = 1; - break; } + bam_destroy1(b); + } else { // retrieve alignments in specified regions + int i; + bam1_t *b; + hts_idx_t *idx = sam_index_load(in, fn_in); // load index + if (idx == 0) { // index is unavailable + fprintf(stderr, "[main_samview] random alignment retrieval only works for indexed BAM or CRAM files.\n"); + ret = 1; + goto view_end; + } + b = bam_init1(); + for (i = optind + 1; i < argc; ++i) { + int result; + hts_itr_t *iter = sam_itr_querys(idx, header, argv[i]); // parse a region in the format like `chr2:100-200' + if (iter == NULL) { // region invalid or reference name not found + int beg, end; + if (hts_parse_reg(argv[i], &beg, &end)) + fprintf(stderr, "[main_samview] region \"%s\" specifies an unknown reference name. Continue anyway.\n", argv[i]); + else + fprintf(stderr, "[main_samview] region \"%s\" could not be parsed. Continue anyway.\n", argv[i]); + continue; + } + // fetch alignments + while ((result = sam_itr_next(in, iter, b)) >= 0) { + if (!process_aln(header, b, &settings)) { + if (!is_count) { if (check_sam_write1(out, header, b, fn_out, &ret) < 0) break; } + count++; + } else { + if (un_out) { if (check_sam_write1(un_out, header, b, fn_un_out, &ret) < 0) break; } + } + } + hts_itr_destroy(iter); + if (result < -1) { + fprintf(stderr, "[main_samview] retrieval of region \"%s\" failed due to truncated file or corrupt BAM index file\n", argv[i]); + ret = 1; + break; + } + } + bam_destroy1(b); + hts_idx_destroy(idx); // destroy the BAM index } - bam_destroy1(b); - hts_idx_destroy(idx); // destroy the BAM index } view_end: - if (is_count && ret == 0) - printf("%" PRId64 "\n", count); + if (is_count && ret == 0) { + if (fprintf(fn_out? fp_out : stdout, "%" PRId64 "\n", count) < 0) { + if (fn_out) print_error_errno("view", "writing to \"%s\" failed", fn_out); + else print_error_errno("view", "writing to standard output failed"); + ret = EXIT_FAILURE; + } + } // close files, free and return if (in) check_sam_close("view", in, fn_in, "standard input", &ret); if (out) check_sam_close("view", out, fn_out, "standard output", &ret); if (un_out) check_sam_close("view", un_out, fn_un_out, "file", &ret); + if (fp_out) fclose(fp_out); free(fn_list); free(fn_out); free(settings.library); free(fn_un_out); sam_global_args_free(&ga); @@ -508,6 +612,10 @@ int main_samview(int argc, char *argv[]) if (settings.remove_aux_len) { free(settings.remove_aux); } + + if (p.pool) + hts_tpool_destroy(p.pool); + return ret; } @@ -538,20 +646,21 @@ static int usage(FILE *fp, int exit_status, int is_long_help) " -l STR only include reads in library STR [null]\n" " -m INT only include reads with number of CIGAR operations consuming\n" " query sequence >= INT [0]\n" -" -f INT only include reads with all bits set in INT set in FLAG [0]\n" -" -F INT only include reads with none of the bits set in INT set in FLAG [0]\n" +" -f INT only include reads with all of the FLAGs in INT present [0]\n" // F&x == x +" -F INT only include reads with none of the FLAGS in INT present [0]\n" // F&x == 0 +" -G INT only EXCLUDE reads with all of the FLAGs in INT present [0]\n" // !(F&x == x) +" -s FLOAT subsample reads (given INT.FRAC option value, 0.FRAC is the\n" +" fraction of templates/read pairs to keep; INT part sets seed)\n" +" -M use the multi-region iterator (increases the speed, removes\n" +" duplicates and outputs the reads as they are ordered in the file)\n" // read processing " -x STR read tag to strip (repeatable) [null]\n" " -B collapse the backward CIGAR operation\n" -" -s FLOAT integer part sets seed of random number generator [0];\n" -" rest sets fraction of templates to subsample [no subsampling]\n" // general options -" -@, --threads INT\n" -" number of BAM/CRAM compression threads [0]\n" " -? print long help, including note about region specification\n" " -S ignored (input format is auto-detected)\n"); - sam_global_opt_help(fp, "-.O.T"); + sam_global_opt_help(fp, "-.O.T@"); fprintf(fp, "\n"); if (is_long_help) @@ -620,21 +729,42 @@ static void bam2fq_usage(FILE *to, const char *command) "Usage: samtools %s [options...] \n", command); fprintf(to, "Options:\n" -" -0 FILE write paired reads flagged both or neither READ1 and READ2 to FILE\n" -" -1 FILE write paired reads flagged READ1 to FILE\n" -" -2 FILE write paired reads flagged READ2 to FILE\n" -" -f INT only include reads with all bits set in INT set in FLAG [0]\n" -" -F INT only include reads with none of the bits set in INT set in FLAG [0]\n" -" -n don't append /1 and /2 to the read name\n"); +" -0 FILE write paired reads flagged both or neither READ1 and READ2 to FILE\n" +" -1 FILE write paired reads flagged READ1 to FILE\n" +" -2 FILE write paired reads flagged READ2 to FILE\n" +" -f INT only include reads with all of the FLAGs in INT present [0]\n" // F&x == x +" -F INT only include reads with none of the FLAGS in INT present [0]\n" // F&x == 0 +" -G INT only EXCLUDE reads with all of the FLAGs in INT present [0]\n" // !(F&x == x) +" -n don't append /1 and /2 to the read name\n" +" -N always append /1 and /2 to the read name\n"); if (fq) fprintf(to, -" -O output quality in the OQ tag if present\n"); +" -O output quality in the OQ tag if present\n"); + fprintf(to, +" -s FILE write singleton reads to FILE [assume single-end]\n" +" -t copy RG, BC and QT tags to the %s header line\n", + fq ? "FASTQ" : "FASTA"); fprintf(to, -" -s FILE write singleton reads to FILE [assume single-end]\n" -" -t copy RG, BC and QT tags to the %s header line\n", +" -T TAGLIST copy arbitrary tags to the %s header line\n", fq ? "FASTQ" : "FASTA"); if (fq) fprintf(to, -" -v INT default quality score if not given in file [1]\n"); - sam_global_opt_help(to, "-.--."); +" -v INT default quality score if not given in file [1]\n" +" -i add Illumina Casava 1.8 format entry to header (eg 1:N:0:ATCACG)\n" +" -c compression level [0..9] to use when creating gz or bgzf fastq files\n" +" --i1 FILE write first index reads to FILE\n" +" --i2 FILE write second index reads to FILE\n" +" --barcode-tag TAG Barcode tag [default: " DEFAULT_BARCODE_TAG "]\n" +" --quality-tag TAG Quality tag [default: " DEFAULT_QUALITY_TAG "]\n" +" --index-format STR How to parse barcode and quality tags\n\n"); + sam_global_opt_help(to, "-.--.@"); + fprintf(to, +" \n" +" The index-format string describes how to parse the barcode and quality tags, for example:\n" +" i14i8 the first 14 characters are index 1, the next 8 characters are index 2\n" +" n8i14 ignore the first 8 characters, and use the next 14 characters for index 1\n" +" If the tag contains a separator, then the numeric part can be replaced with '*' to mean\n" +" 'read until the separator or end of tag', for example:\n" +" n*i* ignore the left part of the tag until the separator, then use the second part\n" +" of the tag as index 1\n"); } typedef enum { READ_UNKNOWN = 0, READ_1 = 1, READ_2 = 2 } readpart; @@ -643,24 +773,110 @@ typedef struct bam2fq_opts { char *fnse; char *fnr[3]; char *fn_input; // pointer to input filename in argv do not free - bool has12, use_oq, copy_tags; - int flag_on, flag_off; + bool has12, has12always, use_oq, copy_tags, illumina_tag; + int flag_on, flag_off, flag_alloff; sam_global_args ga; fastfile filetype; int def_qual; + char *barcode_tag; + char *quality_tag; + char *index_file[2]; + char *index_format; + char *extra_tags; + char compression_level; } bam2fq_opts_t; typedef struct bam2fq_state { samFile *fp; - FILE *fpse; - FILE *fpr[3]; + BGZF *fpse; + BGZF *fpr[3]; + BGZF *fpi[2]; + BGZF *hstdout; bam_hdr_t *h; - bool has12, use_oq, copy_tags; - int flag_on, flag_off; + bool has12, use_oq, copy_tags, illumina_tag; + int flag_on, flag_off, flag_alloff; fastfile filetype; int def_qual; + klist_t(ktaglist) *taglist; + char *index_sequence; + char compression_level; } bam2fq_state_t; +/* + * Get and decode the read from a BAM record. + * + * TODO: htslib really needs an interface for this. Consider this or perhaps + * bam_get_seq_str (current vs original orientation) and bam_get_qual_str + * functions as string formatted equivalents to bam_get_{seq,qual}? + */ + +/* + * Reverse a string in place. + * From http://stackoverflow.com/questions/8534274/is-the-strrev-function-not-available-in-linux. + * Author Sumit-naik: http://stackoverflow.com/users/4590926/sumit-naik + */ +static char *reverse(char *str) +{ + int i = strlen(str)-1,j=0; + char ch; + while (i>j) { + ch = str[i]; + str[i]= str[j]; + str[j] = ch; + i--; + j++; + } + return str; +} + +/* return the read, reverse complemented if necessary */ +static char *get_read(const bam1_t *rec) +{ + int len = rec->core.l_qseq + 1; + char *read = calloc(1, len); + char *seq = (char *)bam_get_seq(rec); + int n; + + if (!read) return NULL; + + for (n=0; n < rec->core.l_qseq; n++) { + if (rec->core.flag & BAM_FREVERSE) read[n] = seq_nt16_str[seq_comp_table[bam_seqi(seq,n)]]; + else read[n] = seq_nt16_str[bam_seqi(seq,n)]; + } + if (rec->core.flag & BAM_FREVERSE) reverse(read); + return read; +} + +/* + * get and decode the quality from a BAM record + */ +static int get_quality(const bam1_t *rec, char **qual_out) +{ + char *quality = calloc(1, rec->core.l_qseq + 1); + char *q = (char *)bam_get_qual(rec); + int n; + + if (!quality) return -1; + + if (*q == '\xff') { + free(quality); + *qual_out = NULL; + return 0; + } + + for (n=0; n < rec->core.l_qseq; n++) { + quality[n] = q[n]+33; + } + if (rec->core.flag & BAM_FREVERSE) reverse(quality); + *qual_out = quality; + return 0; +} + +// +// End of htslib complaints +// + + static readpart which_readpart(const bam1_t *b) { if ((b->core.flag & BAM_FREAD1) && !(b->core.flag & BAM_FREAD2)) { @@ -672,91 +888,281 @@ static readpart which_readpart(const bam1_t *b) } } -// Transform a bam1_t record into a string with the FASTQ representation of it -// @returns false for error, true for success -static bool bam1_to_fq(const bam1_t *b, kstring_t *linebuf, const bam2fq_state_t *state) +/* + * parse the length part from the index-format string + */ +static int getLength(char **s) { - int i; - int32_t qlen = b->core.l_qseq; - assert(qlen >= 0); - uint8_t *seq; - uint8_t *qual = bam_get_qual(b); - const uint8_t *oq = NULL; - if (state->use_oq) { - oq = bam_aux_get(b, "OQ"); - if (oq) oq++; // skip tag type + int n = 0; + while (**s) { + if (**s == '*') { n=-1; (*s)++; break; } + if ( !isdigit(**s)) break; + n = n*10 + ((**s)-'0'); + (*s)++; } - bool has_qual = (qual[0] != 0xff || (state->use_oq && oq)); // test if there is quality + return n; +} + +static bool copy_tag(const char *tag, const bam1_t *rec, kstring_t *linebuf) +{ + uint8_t *s = bam_aux_get(rec, tag); + if (s) { + char aux_type = *s; + switch (aux_type) { + case 'C': + case 'S': aux_type = 'I'; break; + case 'c': + case 's': aux_type = 'i'; break; + case 'd': aux_type = 'f'; break; + } + + // Ensure space. Need 6 chars + length of tag. Max length of + // i is 16, A is 21, B currently 26, Z is unknown, so + // have to check that one later. + if (ks_resize(linebuf, ks_len(linebuf) + 64) < 0) return false; + + kputc('\t', linebuf); + kputsn(tag, 2, linebuf); + kputc(':', linebuf); + kputc(aux_type=='I'? 'i': aux_type, linebuf); + kputc(':', linebuf); + switch (aux_type) { + case 'H': + case 'Z': + if (kputs(bam_aux2Z(s), linebuf) < 0) return false; + break; + case 'i': kputw(bam_aux2i(s), linebuf); break; + case 'I': kputuw(bam_aux2i(s), linebuf); break; + case 'A': kputc(bam_aux2A(s), linebuf); break; + case 'f': kputd(bam_aux2f(s), linebuf); break; + case 'B': kputs("*** Unhandled aux type ***", linebuf); return false; + default: kputs("*** Unknown aux type ***", linebuf); return false; + } + } + return true; +} + +static int insert_index_sequence_into_linebuf(char *index_sequence, kstring_t *linebuf, bam1_t *rec) +{ + if (!index_sequence) return 0; + + kstring_t new = {0,0,NULL}; + if (linebuf->s) { + char *s = strchr(linebuf->s, '\n'); + if (s) { + if (ks_resize(&new, linebuf->l + strlen(index_sequence) + 16) < 0) + return -1; + *s = 0; + kputs(linebuf->s, &new); + kputc(' ', &new); + readpart readpart = which_readpart(rec); + if (readpart == READ_1) kputc('1', &new); + else if (readpart == READ_2) kputc('2', &new); + else kputc('0', &new); + + kputc(':', &new); + if (rec->core.flag & BAM_FQCFAIL) kputc('Y', &new); + else kputc('N', &new); + + kputs(":0:", &new); + kputs(index_sequence, &new); + kputc('\n', &new); + kputs(s+1, &new); + free(ks_release(linebuf)); + linebuf->s = new.s; linebuf->l = new.l; linebuf->m = new.m; + } + } + return 0; +} + +static bool make_fq_line(const bam1_t *rec, char *seq, char *qual, kstring_t *linebuf, const bam2fq_state_t *state) +{ + int i; linebuf->l = 0; // Write read name - readpart readpart = which_readpart(b); - kputc(state->filetype == FASTA? '>' : '@', linebuf); - kputs(bam_get_qname(b), linebuf); + if (kputc(state->filetype == FASTA? '>' : '@', linebuf) < 0) return false; + if (kputs(bam_get_qname(rec), linebuf) < 0) return false; // Add the /1 /2 if requested if (state->has12) { - if (readpart == READ_1) kputs("/1", linebuf); - else if (readpart == READ_2) kputs("/2", linebuf); + readpart readpart = which_readpart(rec); + if (readpart == READ_1) { + if (kputs("/1", linebuf) < 0) return false; + } else if (readpart == READ_2) { + if (kputs("/2", linebuf) < 0) return false; + } } if (state->copy_tags) { for (i = 0; copied_tags[i]; ++i) { - uint8_t *s; - if ((s = bam_aux_get(b, copied_tags[i])) != 0) { - kputc('\t', linebuf); - kputsn(copied_tags[i], 2, linebuf); - kputsn(":Z:", 3, linebuf); - kputs(bam_aux2Z(s), linebuf); + if (!copy_tag(copied_tags[i], rec, linebuf)) { + fprintf(stderr, "Problem copying aux tags: [%s]\n", linebuf->s); + return false; } } } - kputc('\n', linebuf); - - seq = bam_get_seq(b); - if (b->core.flag & BAM_FREVERSE) { // read is reverse complemented - for (i = qlen-1; i > -1; --i) { - char c = seq_nt16_str[seq_comp_table[bam_seqi(seq,i)]]; - kputc(c, linebuf); - } - } else { - for (i = 0; i < qlen; ++i) { - char c = seq_nt16_str[bam_seqi(seq,i)]; - kputc(c, linebuf); + if (state->taglist->size) { + kliter_t(ktaglist) *p; + for (p = kl_begin(state->taglist); p != kl_end(state->taglist); p = kl_next(p)) { + if (!copy_tag(kl_val(p), rec, linebuf)) { + fprintf(stderr, "Problem copying aux tags: [%s]\n", linebuf->s); + return false; + } } } - kputc('\n', linebuf); + + if (kputc('\n', linebuf) < 0) return false; + if (kputs(seq, linebuf) < 0) return false; + if (kputc('\n', linebuf) < 0) return false; if (state->filetype == FASTQ) { // Write quality - kputs("+\n", linebuf); - if (has_qual) { - if (state->use_oq && oq) { - if (b->core.flag & BAM_FREVERSE) { // read is reverse complemented - for (i = qlen-1; i > -1; --i) { - kputc(oq[i], linebuf); - } - } else { - kputs((char*)oq, linebuf); - } - } else { - if (b->core.flag & BAM_FREVERSE) { // read is reverse complemented - for (i = qlen-1; i > -1; --i) { - kputc(33 + qual[i], linebuf); - } - } else { - for (i = 0; i < qlen; ++i) { - kputc(33 + qual[i], linebuf); - } - } - } + if (kputs("+\n", linebuf) < 0) return false; + if (qual && *qual) { + if (kputs(qual, linebuf) < 0) return false; } else { - for (i = 0; i < qlen; ++i) { + int len = strlen(seq); + if (ks_resize(linebuf, ks_len(linebuf) + len + 1) < 0) return false; + for (i = 0; i < len; ++i) { kputc(33 + state->def_qual, linebuf); } } - kputc('\n', linebuf); + if (kputc('\n', linebuf) < 0) return false; + } + return true; +} + +/* + * Create FASTQ lines from the barcode tag using the index-format + */ +static bool tags2fq(bam1_t *rec, bam2fq_state_t *state, const bam2fq_opts_t* opts) +{ + uint8_t *p; + char *ifmt = opts->index_format; + char *tag = NULL; + char *qual = NULL; + char *sub_tag = NULL; + char *sub_qual = NULL; + size_t tag_len; + int file_number = 0; + kstring_t linebuf = { 0, 0, NULL }; // Buffer + + + // read barcode tag + p = bam_aux_get(rec,opts->barcode_tag); + if (p) tag = bam_aux2Z(p); + + if (!tag) return true; // there is no tag + + tag_len = strlen(tag); + sub_tag = calloc(1, tag_len + 1); + if (!sub_tag) goto fail; + sub_qual = calloc(1, tag_len + 1); + if (!sub_qual) goto fail; + + // read quality tag + p = bam_aux_get(rec, opts->quality_tag); + if (p) qual = bam_aux2Z(p); + + // Parse the index-format string + while (*ifmt) { + if (file_number > 1) break; // shouldn't happen if we've validated paramaters correctly + char action = *ifmt; // should be 'i' or 'n' + ifmt++; // skip over action + int index_len = getLength(&ifmt); + int n = 0; + + if (index_len < 0) { + // read until separator + while (isalpha(*tag)) { + sub_tag[n] = *tag++; + if (qual) sub_qual[n] = *qual++; + n++; + } + if (*tag) { // skip separator + tag++; + if (qual) qual++; + } + } else { + // read index_len characters + while (index_len-- && *tag) { + sub_tag[n] = *tag++; + if (qual) sub_qual[n] = *qual++; + n++; + } + } + sub_tag[n] = '\0'; + sub_qual[n] = '\0'; + + if (action=='i' && *sub_tag && state->fpi[file_number]) { + //if (file_number==0) state->index_sequence = strdup(sub_tag); // we're going to need this later... + state->index_sequence = strdup(sub_tag); // we're going to need this later... + if (!state->index_sequence) goto fail; + if (!make_fq_line(rec, sub_tag, sub_qual, &linebuf, state)) goto fail; + if (state->illumina_tag) { + if (insert_index_sequence_into_linebuf(state->index_sequence, &linebuf, rec) < 0) { + goto fail; + } + } + if (bgzf_write(state->fpi[file_number++], linebuf.s, linebuf.l) < 0) + goto fail; + } + + } + + free(sub_qual); free(sub_tag); + free(linebuf.s); + return true; + + fail: + perror(__func__); + free(sub_qual); free(sub_tag); + free(linebuf.s); + return true; +} + +// Transform a bam1_t record into a string with the FASTQ representation of it +// @returns false for error, true for success +static bool bam1_to_fq(const bam1_t *b, kstring_t *linebuf, const bam2fq_state_t *state) +{ + int32_t qlen = b->core.l_qseq; + assert(qlen >= 0); + const uint8_t *oq = NULL; + char *qual = NULL; + + char *seq = get_read(b); + if (!seq) return false; + + if (state->use_oq) oq = bam_aux_get(b, "OQ"); + if (oq && *oq=='Z') { + qual = strdup(bam_aux2Z(oq)); + if (!qual) goto fail; + if (b->core.flag & BAM_FREVERSE) { // read is reverse complemented + reverse(qual); + } + } else { + if (get_quality(b, &qual) < 0) goto fail; } + + if (!make_fq_line(b, seq, qual, linebuf, state)) goto fail; + + free(qual); + free(seq); return true; + + fail: + free(seq); + free(qual); + return false; +} + +static void free_opts(bam2fq_opts_t *opts) +{ + free(opts->barcode_tag); + free(opts->quality_tag); + free(opts->index_format); + free(opts->extra_tags); + free(opts); } // return true if valid @@ -765,43 +1171,116 @@ static bool parse_opts(int argc, char *argv[], bam2fq_opts_t** opts_out) // Parse args bam2fq_opts_t* opts = calloc(1, sizeof(bam2fq_opts_t)); opts->has12 = true; + opts->has12always = false; opts->filetype = FASTQ; opts->def_qual = 1; + opts->barcode_tag = NULL; + opts->quality_tag = NULL; + opts->index_format = NULL; + opts->index_file[0] = NULL; + opts->index_file[1] = NULL; + opts->extra_tags = NULL; + opts->compression_level = 1; int c; sam_global_args_init(&opts->ga); static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0, '@'), + {"i1", required_argument, NULL, 1}, + {"I1", required_argument, NULL, 1}, + {"i2", required_argument, NULL, 2}, + {"I2", required_argument, NULL, 2}, + {"if", required_argument, NULL, 3}, + {"IF", required_argument, NULL, 3}, + {"index-format", required_argument, NULL, 3}, + {"barcode-tag", required_argument, NULL, 'b'}, + {"quality-tag", required_argument, NULL, 'q'}, { NULL, 0, NULL, 0 } }; - while ((c = getopt_long(argc, argv, "0:1:2:f:F:nOs:tv:", lopts, NULL)) > 0) { + while ((c = getopt_long(argc, argv, "0:1:2:f:F:G:niNOs:c:tT:v:@:", lopts, NULL)) > 0) { switch (c) { + case 'b': opts->barcode_tag = strdup(optarg); break; + case 'q': opts->quality_tag = strdup(optarg); break; + case 1 : opts->index_file[0] = optarg; break; + case 2 : opts->index_file[1] = optarg; break; + case 3 : opts->index_format = strdup(optarg); break; case '0': opts->fnr[0] = optarg; break; case '1': opts->fnr[1] = optarg; break; case '2': opts->fnr[2] = optarg; break; case 'f': opts->flag_on |= strtol(optarg, 0, 0); break; case 'F': opts->flag_off |= strtol(optarg, 0, 0); break; + case 'G': opts->flag_alloff |= strtol(optarg, 0, 0); break; case 'n': opts->has12 = false; break; + case 'N': opts->has12always = true; break; case 'O': opts->use_oq = true; break; case 's': opts->fnse = optarg; break; case 't': opts->copy_tags = true; break; + case 'i': opts->illumina_tag = true; break; + case 'c': opts->compression_level = atoi(optarg); break; + case 'T': opts->extra_tags = strdup(optarg); break; case 'v': opts->def_qual = atoi(optarg); break; - case '?': bam2fq_usage(stderr, argv[0]); free(opts); return false; + case '?': bam2fq_usage(stderr, argv[0]); free_opts(opts); return false; default: if (parse_sam_global_opt(c, optarg, lopts, &opts->ga) != 0) { - bam2fq_usage(stderr, argv[0]); free(opts); return false; + bam2fq_usage(stderr, argv[0]); free_opts(opts); return false; } break; } } if (opts->fnr[1] || opts->fnr[2]) opts->has12 = false; + if (opts->has12always) opts->has12 = true; + + if (!opts->barcode_tag) opts->barcode_tag = strdup(DEFAULT_BARCODE_TAG); + if (!opts->quality_tag) opts->quality_tag = strdup(DEFAULT_QUALITY_TAG); + + int nIndex = 0; + if (opts->index_format) { + char *s; + for (s = opts->index_format; *s; s++) { + if (*s == 'i') nIndex++; + } + } + if (nIndex>2) { + fprintf(stderr,"Invalid index format: more than 2 indexes\n"); + bam2fq_usage(stderr, argv[0]); + free_opts(opts); + return false; + } + + if (opts->index_file[1] && !opts->index_file[0]) { + fprintf(stderr, "Index one specified, but index two not given\n"); + bam2fq_usage(stderr, argv[0]); + free_opts(opts); + return false; + } + + if (nIndex==2 && !opts->index_file[1]) { + fprintf(stderr, "index_format specifies two indexes, but only one index file given\n"); + bam2fq_usage(stderr, argv[0]); + free_opts(opts); + return false; + } + + if (nIndex==1 && !opts->index_file[0]) { + fprintf(stderr, "index_format specifies an index, but no index file given\n"); + bam2fq_usage(stderr, argv[0]); + free_opts(opts); + return false; + } + + if (nIndex==0 && opts->index_file[0]) { + fprintf(stderr, "index_format not specified, but index file given\n"); + bam2fq_usage(stderr, argv[0]); + free_opts(opts); + return false; + } if (opts->def_qual < 0 || 93 < opts->def_qual) { fprintf(stderr, "Invalid -v default quality %i, allowed range 0 to 93\n", opts->def_qual); bam2fq_usage(stderr, argv[0]); - free(opts); - return true; + free_opts(opts); + return false; } const char* type_str = argv[0]; @@ -812,20 +1291,21 @@ static bool parse_opts(int argc, char *argv[], bam2fq_opts_t** opts_out) } else { print_error("bam2fq", "Unrecognised type call \"%s\", this should be impossible... but you managed it!", type_str); bam2fq_usage(stderr, argv[0]); - free(opts); + free_opts(opts); return false; } if ((argc - (optind)) == 0) { + fprintf(stderr, "No input file specified.\n"); bam2fq_usage(stdout, argv[0]); - free(opts); + free_opts(opts); return false; } if ((argc - (optind)) != 1) { fprintf(stderr, "Too many arguments.\n"); bam2fq_usage(stderr, argv[0]); - free(opts); + free_opts(opts); return false; } opts->fn_input = argv[optind]; @@ -833,16 +1313,55 @@ static bool parse_opts(int argc, char *argv[], bam2fq_opts_t** opts_out) return true; } +static BGZF *open_fqfile(char *filename, int c) +{ + char mode[4] = "w"; + size_t len = strlen(filename); + + mode[2] = 0; mode[3] = 0; + if (len > 3 && strstr(filename + (len - 3),".gz")) { + mode[1] = 'g'; mode[2] = c+'0'; + } else if ((len > 4 && strstr(filename + (len - 4),".bgz")) + || (len > 5 && strstr(filename + (len - 5),".bgzf"))) { + mode[1] = c+'0'; + } else { + mode[1] = 'u'; + } + + return bgzf_open(filename,mode); +} + static bool init_state(const bam2fq_opts_t* opts, bam2fq_state_t** state_out) { bam2fq_state_t* state = calloc(1, sizeof(bam2fq_state_t)); state->flag_on = opts->flag_on; state->flag_off = opts->flag_off; + state->flag_alloff = opts->flag_alloff; state->has12 = opts->has12; state->use_oq = opts->use_oq; + state->illumina_tag = opts->illumina_tag; state->copy_tags = opts->copy_tags; state->filetype = opts->filetype; state->def_qual = opts->def_qual; + state->index_sequence = NULL; + state->hstdout = bgzf_dopen(fileno(stdout), "wu"); + state->compression_level = opts->compression_level; + + state->taglist = kl_init(ktaglist); + if (opts->extra_tags) { + char *save_p; + char *s = strtok_r(opts->extra_tags, ",", &save_p); + while (s) { + if (strlen(s) != 2) { + fprintf(stderr, "Parsing extra tags - '%s' is not two characters\n", s); + free(state); + return false; + } + char **et = kl_pushp(ktaglist, state->taglist); + *et = s; + s = strtok_r(NULL, ",", &save_p); + } + } state->fp = sam_open(opts->fn_input, "r"); if (state->fp == NULL) { @@ -850,8 +1369,10 @@ static bool init_state(const bam2fq_opts_t* opts, bam2fq_state_t** state_out) free(state); return false; } + if (opts->ga.nthreads > 0) + hts_set_threads(state->fp, opts->ga.nthreads); uint32_t rf = SAM_QNAME | SAM_FLAG | SAM_SEQ | SAM_QUAL; - if (opts->use_oq) rf |= SAM_AUX; + if (opts->use_oq || opts->extra_tags || opts->index_file[0]) rf |= SAM_AUX; if (hts_set_opt(state->fp, CRAM_OPT_REQUIRED_FIELDS, rf)) { fprintf(stderr, "Failed to set CRAM_OPT_REQUIRED_FIELDS value\n"); free(state); @@ -863,7 +1384,7 @@ static bool init_state(const bam2fq_opts_t* opts, bam2fq_state_t** state_out) return false; } if (opts->fnse) { - state->fpse = fopen(opts->fnse,"w"); + state->fpse = open_fqfile(opts->fnse, state->compression_level); if (state->fpse == NULL) { print_error_errno("bam2fq", "Cannot write to singleton file \"%s\"", opts->fnse); free(state); @@ -874,14 +1395,25 @@ static bool init_state(const bam2fq_opts_t* opts, bam2fq_state_t** state_out) int i; for (i = 0; i < 3; ++i) { if (opts->fnr[i]) { - state->fpr[i] = fopen(opts->fnr[i], "w"); + state->fpr[i] = open_fqfile(opts->fnr[i], state->compression_level); if (state->fpr[i] == NULL) { print_error_errno("bam2fq", "Cannot write to r%d file \"%s\"", i, opts->fnr[i]); free(state); return false; } } else { - state->fpr[i] = stdout; + state->fpr[i] = state->hstdout; + } + } + for (i = 0; i < 2; i++) { + state->fpi[i] = NULL; + if (opts->index_file[i]) { + state->fpi[i] = open_fqfile(opts->index_file[i], state->compression_level); + if (state->fpi[i] == NULL) { + print_error_errno("bam2fq", "Cannot write to i%d file \"%s\"", i+1, opts->index_file[i]); + free(state); + return false; + } } } @@ -901,11 +1433,23 @@ static bool destroy_state(const bam2fq_opts_t *opts, bam2fq_state_t *state, int* bool valid = true; bam_hdr_destroy(state->h); check_sam_close("bam2fq", state->fp, opts->fn_input, "file", status); - if (state->fpse && fclose(state->fpse)) { print_error_errno("bam2fq", "Error closing singleton file \"%s\"", opts->fnse); valid = false; } + if (state->fpse && bgzf_close(state->fpse)) { print_error_errno("bam2fq", "Error closing singleton file \"%s\"", opts->fnse); valid = false; } int i; for (i = 0; i < 3; ++i) { - if (state->fpr[i] != stdout && fclose(state->fpr[i])) { print_error_errno("bam2fq", "Error closing r%d file \"%s\"", i, opts->fnr[i]); valid = false; } + if (state->fpr[i] == state->hstdout) { + if (i==0 && bgzf_close(state->fpr[i])) { print_error_errno("bam2fq", "Error closing STDOUT"); valid = false; } + } else { + if (bgzf_close(state->fpr[i])) { print_error_errno("bam2fq", "Error closing r%d file \"%s\"", i, opts->fnr[i]); valid = false; } + } + } + for (i = 0; i < 2; i++) { + if (state->fpi[i] && bgzf_close(state->fpi[i])) { + print_error_errno("bam2fq", "Error closing i%d file \"%s\"", i+1, opts->index_file[i]); + valid = false; + } } + kl_destroy(ktaglist,state->taglist); + free(state->index_sequence); free(state); return valid; } @@ -914,12 +1458,15 @@ static inline bool filter_it_out(const bam1_t *b, const bam2fq_state_t *state) { return (b->core.flag&(BAM_FSECONDARY|BAM_FSUPPLEMENTARY) // skip secondary and supplementary alignments || (b->core.flag&(state->flag_on)) != state->flag_on // or reads indicated by filter flags - || (b->core.flag&(state->flag_off)) != 0); + || (b->core.flag&(state->flag_off)) != 0 + || (b->core.flag&(state->flag_alloff) && (b->core.flag&(state->flag_alloff)) == state->flag_alloff)); } -static bool bam2fq_mainloop_singletontrack(bam2fq_state_t *state) +static bool bam2fq_mainloop(bam2fq_state_t *state, bam2fq_opts_t* opts) { + int n; + bam1_t *records[3]; bam1_t* b = bam_init1(); char *current_qname = NULL; int64_t n_reads = 0, n_singletons = 0; // Statistics @@ -927,35 +1474,55 @@ static bool bam2fq_mainloop_singletontrack(bam2fq_state_t *state) int score[3]; int at_eof; if (b == NULL ) { - perror("[bam2fq_mainloop_singletontrack] Malloc error for bam record buffer."); + perror("[bam2fq_mainloop] Malloc error for bam record buffer."); return false; } bool valid = true; while (true) { - at_eof = sam_read1(state->fp, state->h, b) < 0; + int res = sam_read1(state->fp, state->h, b); + if (res < -1) { + fprintf(stderr, "[bam2fq_mainloop] Failed to read bam record.\n"); + return false; + } + at_eof = res < 0; if (!at_eof && filter_it_out(b, state)) continue; if (!at_eof) ++n_reads; if (at_eof || !current_qname || (strcmp(current_qname, bam_get_qname(b)) != 0)) { if (current_qname) { + if (state->illumina_tag) { + for (n=0; valid && n<3; n++) { + if (insert_index_sequence_into_linebuf(state->index_sequence, &linebuf[n], records[n]) < 0) valid = false; + } + if (!valid) break; + } + free(state->index_sequence); state->index_sequence = NULL; if (score[1] > 0 && score[2] > 0) { // print linebuf[1] to fpr[1], linebuf[2] to fpr[2] - if (fputs(linebuf[1].s, state->fpr[1]) == EOF) { valid = false; break; } - if (fputs(linebuf[2].s, state->fpr[2]) == EOF) { valid = false; break; } + if (bgzf_write(state->fpr[1], linebuf[1].s, linebuf[1].l) < 0) { valid = false; break; } + if (bgzf_write(state->fpr[2], linebuf[2].s, linebuf[2].l) < 0) { valid = false; break; } } else if (score[1] > 0 || score[2] > 0) { - // print whichever one exists to fpse - if (score[1] > 0) { - if (fputs(linebuf[1].s, state->fpse) == EOF) { valid = false; break; } + if (state->fpse) { + // print whichever one exists to fpse + if (score[1] > 0) { + if (bgzf_write(state->fpse, linebuf[1].s, linebuf[1].l) < 0) { valid = false; break; } + } else { + if (bgzf_write(state->fpse, linebuf[2].s, linebuf[2].l) < 0) { valid = false; break; } + } + ++n_singletons; } else { - if (fputs(linebuf[2].s, state->fpse) == EOF) { valid = false; break; } + if (score[1] > 0) { + if (bgzf_write(state->fpr[1], linebuf[1].s, linebuf[1].l) < 0) { valid = false; break; } + } else { + if (bgzf_write(state->fpr[2], linebuf[2].s, linebuf[2].l) < 0) { valid = false; break; } + } } - ++n_singletons; } if (score[0]) { // TODO: check this // print linebuf[0] to fpr[0] - if (fputs(linebuf[0].s, state->fpr[0]) == EOF) { valid = false; break; } + if (bgzf_write(state->fpr[0], linebuf[0].s, linebuf[0].l) < 0) { valid = false; break; } } } @@ -963,12 +1530,15 @@ static bool bam2fq_mainloop_singletontrack(bam2fq_state_t *state) free(current_qname); current_qname = strdup(bam_get_qname(b)); + if (!current_qname) { valid = false; break; } score[0] = score[1] = score[2] = 0; } // Prefer a copy of the read that has base qualities int b_score = bam_get_qual(b)[0] != 0xff? 2 : 1; if (b_score > score[which_readpart(b)]) { + if (state->fpi[0]) if (!tags2fq(b, state, opts)) return false; + records[which_readpart(b)] = b; if(!bam1_to_fq(b, &linebuf[which_readpart(b)], state)) { fprintf(stderr, "[%s] Error converting read to FASTA/Q\n", __func__); return false; @@ -978,7 +1548,7 @@ static bool bam2fq_mainloop_singletontrack(bam2fq_state_t *state) } if (!valid) { - perror("[bam2fq_mainloop_singletontrack] Error writing to FASTx files."); + perror("[bam2fq_mainloop] Error writing to FASTx files."); } bam_destroy1(b); free(current_qname); @@ -991,32 +1561,6 @@ static bool bam2fq_mainloop_singletontrack(bam2fq_state_t *state) return valid; } -static bool bam2fq_mainloop(bam2fq_state_t *state) -{ - // process a name collated BAM into fastq - bam1_t* b = bam_init1(); - if (b == NULL) { - perror(NULL); - return false; - } - int64_t n_reads = 0; // Statistics - kstring_t linebuf = { 0, 0, NULL }; // Buffer - while (sam_read1(state->fp, state->h, b) >= 0) { - if (b->core.flag&(BAM_FSECONDARY|BAM_FSUPPLEMENTARY) // skip secondary and supplementary alignments - || (b->core.flag&(state->flag_on)) != state->flag_on // or reads indicated by filter flags - || (b->core.flag&(state->flag_off)) != 0) continue; - ++n_reads; - - if (!bam1_to_fq(b, &linebuf, state)) return false; - fputs(linebuf.s, state->fpr[which_readpart(b)]); - } - free(linebuf.s); - bam_destroy1(b); - - fprintf(stderr, "[M::%s] processed %" PRId64 " reads\n", __func__, n_reads); - return true; -} - int main_bam2fq(int argc, char *argv[]) { int status = EXIT_SUCCESS; @@ -1028,15 +1572,11 @@ int main_bam2fq(int argc, char *argv[]) if (!init_state(opts, &state)) return EXIT_FAILURE; - if (state->fpse) { - if (!bam2fq_mainloop_singletontrack(state)) status = EXIT_FAILURE; - } else { - if (!bam2fq_mainloop(state)) status = EXIT_FAILURE; - } + if (!bam2fq_mainloop(state,opts)) status = EXIT_FAILURE; if (!destroy_state(opts, state, &status)) return EXIT_FAILURE; sam_global_args_free(&opts->ga); - free(opts); + free_opts(opts); return status; } diff --git a/samtools/sam_view.c.pysam.c b/samtools/sam_view.c.pysam.c index 8c883b0b3..4e3f8ab48 100644 --- a/samtools/sam_view.c.pysam.c +++ b/samtools/sam_view.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* sam_view.c -- SAM<->BAM<->CRAM conversion. - Copyright (C) 2009-2015 Genome Research Ltd. + Copyright (C) 2009-2017 Genome Research Ltd. Portions copyright (C) 2009, 2011, 2012 Broad Institute. Author: Heng Li @@ -29,6 +29,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include +#include #include #include #include @@ -36,13 +37,24 @@ DEALINGS IN THE SOFTWARE. */ #include #include #include +#include #include "htslib/sam.h" #include "htslib/faidx.h" #include "htslib/kstring.h" #include "htslib/khash.h" +#include "htslib/klist.h" +#include "htslib/thread_pool.h" +#include "htslib/bgzf.h" #include "samtools.h" #include "sam_opts.h" +#include "bedidx.h" + +#define DEFAULT_BARCODE_TAG "BC" +#define DEFAULT_QUALITY_TAG "QT" + KHASH_SET_INIT_STR(rg) +#define taglist_free(p) +KLIST_INIT(ktaglist, char*, taglist_free) typedef khash_t(rg) *rghash_t; @@ -52,6 +64,7 @@ typedef struct samview_settings { int min_mapQ; int flag_on; int flag_off; + int flag_alloff; int min_qlen; int remove_B; uint32_t subsam_seed; @@ -60,6 +73,7 @@ typedef struct samview_settings { void* bed; size_t remove_aux_len; char** remove_aux; + int multi_region; } samview_settings_t; @@ -67,9 +81,6 @@ typedef struct samview_settings { extern const char *bam_get_library(bam_hdr_t *header, const bam1_t *b); extern int bam_remove_B(bam1_t *b); extern char *samfaipath(const char *fn_ref); -void *bed_read(const char *fn); -void bed_destroy(void *_h); -int bed_overlap(const void *_h, const char *chr, int beg, int end); // Returns 0 to indicate read should be output 1 otherwise static int process_aln(const bam_hdr_t *h, bam1_t *b, samview_settings_t* settings) @@ -85,7 +96,9 @@ static int process_aln(const bam_hdr_t *h, bam1_t *b, samview_settings_t* settin } if (b->core.qual < settings->min_mapQ || ((b->core.flag & settings->flag_on) != settings->flag_on) || (b->core.flag & settings->flag_off)) return 1; - if (settings->bed && (b->core.tid < 0 || !bed_overlap(settings->bed, h->target_name[b->core.tid], b->core.pos, bam_endpos(b)))) + if (settings->flag_alloff && ((b->core.flag & settings->flag_alloff) == settings->flag_alloff)) + return 1; + if (!settings->multi_region && settings->bed && (b->core.tid < 0 || !bed_overlap(settings->bed, h->target_name[b->core.tid], b->core.pos, bam_endpos(b)))) return 1; if (settings->subsam_frac > 0.) { uint32_t k = __ac_Wang_hash(__ac_X31_hash_string(bam_get_qname(b)) ^ settings->subsam_seed); @@ -233,30 +246,35 @@ static void check_sam_close(const char *subcmd, samFile *fp, const char *fname, int main_samview(int argc, char *argv[]) { int c, is_header = 0, is_header_only = 0, ret = 0, compress_level = -1, is_count = 0; - int is_long_help = 0, n_threads = 0; + int is_long_help = 0; int64_t count = 0; samFile *in = 0, *out = 0, *un_out=0; + FILE *fp_out = NULL; bam_hdr_t *header = NULL; char out_mode[5], out_un_mode[5], *out_format = ""; char *fn_in = 0, *fn_out = 0, *fn_list = 0, *q, *fn_un_out = 0; sam_global_args ga = SAM_GLOBAL_ARGS_INIT; + htsThreadPool p = {NULL, 0}; + int filter_state = ALL, filter_op = 0; + int result; samview_settings_t settings = { .rghash = NULL, .min_mapQ = 0, .flag_on = 0, .flag_off = 0, + .flag_alloff = 0, .min_qlen = 0, .remove_B = 0, .subsam_seed = 0, .subsam_frac = -1., .library = NULL, .bed = NULL, + .multi_region = 0 }; static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 'T'), - { "threads", required_argument, NULL, '@' }, + SAM_OPT_GLOBAL_OPTIONS('-', 0, 'O', 0, 'T', '@'), { NULL, 0, NULL, 0 } }; @@ -264,11 +282,13 @@ int main_samview(int argc, char *argv[]) strcpy(out_mode, "w"); strcpy(out_un_mode, "w"); while ((c = getopt_long(argc, argv, - "SbBcCt:h1Ho:O:q:f:F:ul:r:?T:R:L:s:@:m:x:U:", + "SbBcCt:h1Ho:O:q:f:F:G:ul:r:?T:R:L:s:@:m:x:U:M", lopts, NULL)) >= 0) { switch (c) { case 's': if ((settings.subsam_seed = strtol(optarg, &q, 10)) != 0) { + // Convert likely user input 0,1,2,... to pseudo-random + // values with more entropy and more bits set srand(settings.subsam_seed); settings.subsam_seed = rand(); } @@ -286,6 +306,7 @@ int main_samview(int argc, char *argv[]) case 'U': fn_un_out = strdup(optarg); break; case 'f': settings.flag_on |= strtol(optarg, 0, 0); break; case 'F': settings.flag_off |= strtol(optarg, 0, 0); break; + case 'G': settings.flag_alloff |= strtol(optarg, 0, 0); break; case 'q': settings.min_mapQ = atoi(optarg); break; case 'u': compress_level = 0; break; case '1': compress_level = 1; break; @@ -315,21 +336,20 @@ int main_samview(int argc, char *argv[]) */ case '?': is_long_help = 1; break; case 'B': settings.remove_B = 1; break; - case '@': n_threads = strtol(optarg, 0, 0); break; case 'x': { if (strlen(optarg) != 2) { - fprintf(pysam_stderr, "main_samview: Error parsing -x auxiliary tags should be exactly two characters long.\n"); - return usage(pysam_stderr, EXIT_FAILURE, is_long_help); + fprintf(samtools_stderr, "main_samview: Error parsing -x auxiliary tags should be exactly two characters long.\n"); + return usage(samtools_stderr, EXIT_FAILURE, is_long_help); } settings.remove_aux = (char**)realloc(settings.remove_aux, sizeof(char*) * (++settings.remove_aux_len)); settings.remove_aux[settings.remove_aux_len-1] = optarg; } break; - + case 'M': settings.multi_region = 1; break; default: if (parse_sam_global_opt(c, optarg, lopts, &ga) != 0) - return usage(pysam_stderr, EXIT_FAILURE, is_long_help); + return usage(samtools_stderr, EXIT_FAILURE, is_long_help); break; } } @@ -349,7 +369,7 @@ int main_samview(int argc, char *argv[]) strcat(out_mode, tmp); strcat(out_un_mode, tmp); } - if (argc == optind && isatty(STDIN_FILENO)) return usage(pysam_stdout, EXIT_SUCCESS, is_long_help); // potential memory leak... + if (argc == optind && isatty(STDIN_FILENO)) return usage(samtools_stdout, EXIT_SUCCESS, is_long_help); // potential memory leak... fn_in = (optind < argc)? argv[optind] : "-"; // generate the fn_list if necessary @@ -363,13 +383,13 @@ int main_samview(int argc, char *argv[]) if (fn_list) { if (hts_set_fai_filename(in, fn_list) != 0) { - fprintf(pysam_stderr, "[main_samview] failed to use reference \"%s\".\n", fn_list); + fprintf(samtools_stderr, "[main_samview] failed to use reference \"%s\".\n", fn_list); ret = 1; goto view_end; } } if ((header = sam_hdr_read(in)) == 0) { - fprintf(pysam_stderr, "[main_samview] fail to read the header from \"%s\".\n", fn_in); + fprintf(samtools_stderr, "[main_samview] fail to read the header from \"%s\".\n", fn_in); ret = 1; goto view_end; } @@ -389,7 +409,7 @@ int main_samview(int argc, char *argv[]) } if (fn_list) { if (hts_set_fai_filename(out, fn_list) != 0) { - fprintf(pysam_stderr, "[main_samview] failed to use reference \"%s\".\n", fn_list); + fprintf(samtools_stderr, "[main_samview] failed to use reference \"%s\".\n", fn_list); ret = 1; goto view_end; } @@ -398,7 +418,7 @@ int main_samview(int argc, char *argv[]) out_mode[1] == 'b' || out_mode[1] == 'c' || (ga.out.format != sam && ga.out.format != unknown_format)) { if (sam_hdr_write(out, header) != 0) { - fprintf(pysam_stderr, "[main_samview] failed to write the SAM header\n"); + fprintf(samtools_stderr, "[main_samview] failed to write the SAM header\n"); ret = 1; goto view_end; } @@ -411,7 +431,7 @@ int main_samview(int argc, char *argv[]) } if (fn_list) { if (hts_set_fai_filename(un_out, fn_list) != 0) { - fprintf(pysam_stderr, "[main_samview] failed to use reference \"%s\".\n", fn_list); + fprintf(samtools_stderr, "[main_samview] failed to use reference \"%s\".\n", fn_list); ret = 1; goto view_end; } @@ -420,56 +440,98 @@ int main_samview(int argc, char *argv[]) out_un_mode[1] == 'b' || out_un_mode[1] == 'c' || (ga.out.format != sam && ga.out.format != unknown_format)) { if (sam_hdr_write(un_out, header) != 0) { - fprintf(pysam_stderr, "[main_samview] failed to write the SAM header\n"); + fprintf(samtools_stderr, "[main_samview] failed to write the SAM header\n"); ret = 1; goto view_end; } } } } + else { + if (fn_out) { + fp_out = fopen(fn_out, "w"); + if (fp_out == NULL) { + print_error_errno("view", "can't create \"%s\"", fn_out); + ret = EXIT_FAILURE; + goto view_end; + } + } + } - if (n_threads > 1) { if (out) hts_set_threads(out, n_threads); } + if (ga.nthreads > 1) { + if (!(p.pool = hts_tpool_init(ga.nthreads))) { + fprintf(samtools_stderr, "Error creating thread pool\n"); + ret = 1; + goto view_end; + } + hts_set_opt(in, HTS_OPT_THREAD_POOL, &p); + if (out) hts_set_opt(out, HTS_OPT_THREAD_POOL, &p); + } if (is_header_only) goto view_end; // no need to print alignments - if (optind + 1 >= argc) { // convert/print the entire file + if (settings.multi_region) { + if (optind < argc - 1) { //regions have been specified in the command line + settings.bed = bed_hash_regions(settings.bed, argv, optind+1, argc, &filter_op); //insert(1) or filter out(0) the regions from the command line in the same hash table as the bed file + if (!filter_op) + filter_state = FILTERED; + } + bam1_t *b = bam_init1(); - int r; - while ((r = sam_read1(in, header, b)) >= 0) { // read one alignment from `in' - if (!process_aln(header, b, &settings)) { - if (!is_count) { if (check_sam_write1(out, header, b, fn_out, &ret) < 0) break; } - count++; + if (settings.bed == NULL) { // index is unavailable or no regions have been specified + while ((result = sam_read1(in, header, b)) >= 0) { // read one alignment from `in' + if (!process_aln(header, b, &settings)) { + if (!is_count) { if (check_sam_write1(out, header, b, fn_out, &ret) < 0) break; } + count++; + } else { + if (un_out) { if (check_sam_write1(un_out, header, b, fn_un_out, &ret) < 0) break; } + } + } + if (result < -1) { + fprintf(samtools_stderr, "[main_samview] truncated file.\n"); + ret = 1; + } + } else { + hts_idx_t *idx = sam_index_load(in, fn_in); // load index + if (idx != NULL) { + + int regcount = 0; + + hts_reglist_t *reglist = bed_reglist(settings.bed, filter_state, ®count); + if(reglist) { + hts_itr_multi_t *iter = sam_itr_regions(idx, header, reglist, regcount); + if (iter) { + // fetch alignments + while ((result = sam_itr_multi_next(in, iter, b)) >= 0) { + if (!process_aln(header, b, &settings)) { + if (!is_count) { if (check_sam_write1(out, header, b, fn_out, &ret) < 0) break; } + count++; + } else { + if (un_out) { if (check_sam_write1(un_out, header, b, fn_un_out, &ret) < 0) break; } + } + } + if (result < -1) { + fprintf(samtools_stderr, "[main_samview] retrieval of region %d failed due to truncated file or corrupt BAM index file\n", iter->curr_tid); + ret = 1; + } + + hts_itr_multi_destroy(iter); + } else { + fprintf(samtools_stderr, "[main_samview] iterator could not be created. Aborting.\n"); + } + } else { + fprintf(samtools_stderr, "[main_samview] region list is empty or could not be created. Aborting.\n"); + } + hts_idx_destroy(idx); // destroy the BAM index } else { - if (un_out) { if (check_sam_write1(un_out, header, b, fn_un_out, &ret) < 0) break; } + fprintf(samtools_stderr, "[main_samview] random alignment retrieval only works for indexed BAM or CRAM files.\n"); } } - if (r < -1) { - fprintf(pysam_stderr, "[main_samview] truncated file.\n"); - ret = 1; - } bam_destroy1(b); - } else { // retrieve alignments in specified regions - int i; - bam1_t *b; - hts_idx_t *idx = sam_index_load(in, fn_in); // load index - if (idx == 0) { // index is unavailable - fprintf(pysam_stderr, "[main_samview] random alignment retrieval only works for indexed BAM or CRAM files.\n"); - ret = 1; - goto view_end; - } - b = bam_init1(); - for (i = optind + 1; i < argc; ++i) { - int result; - hts_itr_t *iter = sam_itr_querys(idx, header, argv[i]); // parse a region in the format like `chr2:100-200' - if (iter == NULL) { // region invalid or reference name not found - int beg, end; - if (hts_parse_reg(argv[i], &beg, &end)) - fprintf(pysam_stderr, "[main_samview] region \"%s\" specifies an unknown reference name. Continue anyway.\n", argv[i]); - else - fprintf(pysam_stderr, "[main_samview] region \"%s\" could not be parsed. Continue anyway.\n", argv[i]); - continue; - } - // fetch alignments - while ((result = sam_itr_next(in, iter, b)) >= 0) { + } else { + if (optind + 1 >= argc) { // convert/print the entire file + bam1_t *b = bam_init1(); + int r; + while ((r = sam_read1(in, header, b)) >= 0) { // read one alignment from `in' if (!process_aln(header, b, &settings)) { if (!is_count) { if (check_sam_write1(out, header, b, fn_out, &ret) < 0) break; } count++; @@ -477,25 +539,67 @@ int main_samview(int argc, char *argv[]) if (un_out) { if (check_sam_write1(un_out, header, b, fn_un_out, &ret) < 0) break; } } } - hts_itr_destroy(iter); - if (result < -1) { - fprintf(pysam_stderr, "[main_samview] retrieval of region \"%s\" failed due to truncated file or corrupt BAM index file\n", argv[i]); + if (r < -1) { + fprintf(samtools_stderr, "[main_samview] truncated file.\n"); ret = 1; - break; } + bam_destroy1(b); + } else { // retrieve alignments in specified regions + int i; + bam1_t *b; + hts_idx_t *idx = sam_index_load(in, fn_in); // load index + if (idx == 0) { // index is unavailable + fprintf(samtools_stderr, "[main_samview] random alignment retrieval only works for indexed BAM or CRAM files.\n"); + ret = 1; + goto view_end; + } + b = bam_init1(); + for (i = optind + 1; i < argc; ++i) { + int result; + hts_itr_t *iter = sam_itr_querys(idx, header, argv[i]); // parse a region in the format like `chr2:100-200' + if (iter == NULL) { // region invalid or reference name not found + int beg, end; + if (hts_parse_reg(argv[i], &beg, &end)) + fprintf(samtools_stderr, "[main_samview] region \"%s\" specifies an unknown reference name. Continue anyway.\n", argv[i]); + else + fprintf(samtools_stderr, "[main_samview] region \"%s\" could not be parsed. Continue anyway.\n", argv[i]); + continue; + } + // fetch alignments + while ((result = sam_itr_next(in, iter, b)) >= 0) { + if (!process_aln(header, b, &settings)) { + if (!is_count) { if (check_sam_write1(out, header, b, fn_out, &ret) < 0) break; } + count++; + } else { + if (un_out) { if (check_sam_write1(un_out, header, b, fn_un_out, &ret) < 0) break; } + } + } + hts_itr_destroy(iter); + if (result < -1) { + fprintf(samtools_stderr, "[main_samview] retrieval of region \"%s\" failed due to truncated file or corrupt BAM index file\n", argv[i]); + ret = 1; + break; + } + } + bam_destroy1(b); + hts_idx_destroy(idx); // destroy the BAM index } - bam_destroy1(b); - hts_idx_destroy(idx); // destroy the BAM index } view_end: - if (is_count && ret == 0) - fprintf(pysam_stdout, "%" PRId64 "\n", count); - + if (is_count && ret == 0) { + if (fprintf(fn_out? fp_out : samtools_stdout, "%" PRId64 "\n", count) < 0) { + if (fn_out) print_error_errno("view", "writing to \"%s\" failed", fn_out); + else print_error_errno("view", "writing to standard output failed"); + ret = EXIT_FAILURE; + } + } + // close files, free and return if (in) check_sam_close("view", in, fn_in, "standard input", &ret); if (out) check_sam_close("view", out, fn_out, "standard output", &ret); if (un_out) check_sam_close("view", un_out, fn_un_out, "file", &ret); + if (fp_out) fclose(fp_out); free(fn_list); free(fn_out); free(settings.library); free(fn_un_out); sam_global_args_free(&ga); @@ -510,6 +614,10 @@ int main_samview(int argc, char *argv[]) if (settings.remove_aux_len) { free(settings.remove_aux); } + + if (p.pool) + hts_tpool_destroy(p.pool); + return ret; } @@ -528,7 +636,7 @@ static int usage(FILE *fp, int exit_status, int is_long_help) " -h include header in SAM output\n" " -H print SAM header only (no alignments)\n" " -c print only the count of matching records\n" -" -o FILE output file name [pysam_stdout]\n" +" -o FILE output file name [samtools_stdout]\n" " -U FILE output reads not selected by filters to FILE [null]\n" // extra input " -t FILE FILE listing reference names and lengths (see long help) [null]\n" @@ -540,20 +648,21 @@ static int usage(FILE *fp, int exit_status, int is_long_help) " -l STR only include reads in library STR [null]\n" " -m INT only include reads with number of CIGAR operations consuming\n" " query sequence >= INT [0]\n" -" -f INT only include reads with all bits set in INT set in FLAG [0]\n" -" -F INT only include reads with none of the bits set in INT set in FLAG [0]\n" +" -f INT only include reads with all of the FLAGs in INT present [0]\n" // F&x == x +" -F INT only include reads with none of the FLAGS in INT present [0]\n" // F&x == 0 +" -G INT only EXCLUDE reads with all of the FLAGs in INT present [0]\n" // !(F&x == x) +" -s FLOAT subsample reads (given INT.FRAC option value, 0.FRAC is the\n" +" fraction of templates/read pairs to keep; INT part sets seed)\n" +" -M use the multi-region iterator (increases the speed, removes\n" +" duplicates and outputs the reads as they are ordered in the file)\n" // read processing " -x STR read tag to strip (repeatable) [null]\n" " -B collapse the backward CIGAR operation\n" -" -s FLOAT integer part sets seed of random number generator [0];\n" -" rest sets fraction of templates to subsample [no subsampling]\n" // general options -" -@, --threads INT\n" -" number of BAM/CRAM compression threads [0]\n" " -? print long help, including note about region specification\n" " -S ignored (input format is auto-detected)\n"); - sam_global_opt_help(fp, "-.O.T"); + sam_global_opt_help(fp, "-.O.T@"); fprintf(fp, "\n"); if (is_long_help) @@ -601,7 +710,7 @@ int main_import(int argc, char *argv[]) int argc2, ret; char **argv2; if (argc != 4) { - fprintf(pysam_stderr, "Usage: samtools import \n"); + fprintf(samtools_stderr, "Usage: samtools import \n"); return 1; } argc2 = 6; @@ -622,21 +731,42 @@ static void bam2fq_usage(FILE *to, const char *command) "Usage: samtools %s [options...] \n", command); fprintf(to, "Options:\n" -" -0 FILE write paired reads flagged both or neither READ1 and READ2 to FILE\n" -" -1 FILE write paired reads flagged READ1 to FILE\n" -" -2 FILE write paired reads flagged READ2 to FILE\n" -" -f INT only include reads with all bits set in INT set in FLAG [0]\n" -" -F INT only include reads with none of the bits set in INT set in FLAG [0]\n" -" -n don't append /1 and /2 to the read name\n"); +" -0 FILE write paired reads flagged both or neither READ1 and READ2 to FILE\n" +" -1 FILE write paired reads flagged READ1 to FILE\n" +" -2 FILE write paired reads flagged READ2 to FILE\n" +" -f INT only include reads with all of the FLAGs in INT present [0]\n" // F&x == x +" -F INT only include reads with none of the FLAGS in INT present [0]\n" // F&x == 0 +" -G INT only EXCLUDE reads with all of the FLAGs in INT present [0]\n" // !(F&x == x) +" -n don't append /1 and /2 to the read name\n" +" -N always append /1 and /2 to the read name\n"); if (fq) fprintf(to, -" -O output quality in the OQ tag if present\n"); +" -O output quality in the OQ tag if present\n"); fprintf(to, -" -s FILE write singleton reads to FILE [assume single-end]\n" -" -t copy RG, BC and QT tags to the %s header line\n", +" -s FILE write singleton reads to FILE [assume single-end]\n" +" -t copy RG, BC and QT tags to the %s header line\n", + fq ? "FASTQ" : "FASTA"); + fprintf(to, +" -T TAGLIST copy arbitrary tags to the %s header line\n", fq ? "FASTQ" : "FASTA"); if (fq) fprintf(to, -" -v INT default quality score if not given in file [1]\n"); - sam_global_opt_help(to, "-.--."); +" -v INT default quality score if not given in file [1]\n" +" -i add Illumina Casava 1.8 format entry to header (eg 1:N:0:ATCACG)\n" +" -c compression level [0..9] to use when creating gz or bgzf fastq files\n" +" --i1 FILE write first index reads to FILE\n" +" --i2 FILE write second index reads to FILE\n" +" --barcode-tag TAG Barcode tag [default: " DEFAULT_BARCODE_TAG "]\n" +" --quality-tag TAG Quality tag [default: " DEFAULT_QUALITY_TAG "]\n" +" --index-format STR How to parse barcode and quality tags\n\n"); + sam_global_opt_help(to, "-.--.@"); + fprintf(to, +" \n" +" The index-format string describes how to parse the barcode and quality tags, for example:\n" +" i14i8 the first 14 characters are index 1, the next 8 characters are index 2\n" +" n8i14 ignore the first 8 characters, and use the next 14 characters for index 1\n" +" If the tag contains a separator, then the numeric part can be replaced with '*' to mean\n" +" 'read until the separator or end of tag', for example:\n" +" n*i* ignore the left part of the tag until the separator, then use the second part\n" +" of the tag as index 1\n"); } typedef enum { READ_UNKNOWN = 0, READ_1 = 1, READ_2 = 2 } readpart; @@ -645,24 +775,110 @@ typedef struct bam2fq_opts { char *fnse; char *fnr[3]; char *fn_input; // pointer to input filename in argv do not free - bool has12, use_oq, copy_tags; - int flag_on, flag_off; + bool has12, has12always, use_oq, copy_tags, illumina_tag; + int flag_on, flag_off, flag_alloff; sam_global_args ga; fastfile filetype; int def_qual; + char *barcode_tag; + char *quality_tag; + char *index_file[2]; + char *index_format; + char *extra_tags; + char compression_level; } bam2fq_opts_t; typedef struct bam2fq_state { samFile *fp; - FILE *fpse; - FILE *fpr[3]; + BGZF *fpse; + BGZF *fpr[3]; + BGZF *fpi[2]; + BGZF *hsamtools_stdout; bam_hdr_t *h; - bool has12, use_oq, copy_tags; - int flag_on, flag_off; + bool has12, use_oq, copy_tags, illumina_tag; + int flag_on, flag_off, flag_alloff; fastfile filetype; int def_qual; + klist_t(ktaglist) *taglist; + char *index_sequence; + char compression_level; } bam2fq_state_t; +/* + * Get and decode the read from a BAM record. + * + * TODO: htslib really needs an interface for this. Consider this or perhaps + * bam_get_seq_str (current vs original orientation) and bam_get_qual_str + * functions as string formatted equivalents to bam_get_{seq,qual}? + */ + +/* + * Reverse a string in place. + * From http://stackoverflow.com/questions/8534274/is-the-strrev-function-not-available-in-linux. + * Author Sumit-naik: http://stackoverflow.com/users/4590926/sumit-naik + */ +static char *reverse(char *str) +{ + int i = strlen(str)-1,j=0; + char ch; + while (i>j) { + ch = str[i]; + str[i]= str[j]; + str[j] = ch; + i--; + j++; + } + return str; +} + +/* return the read, reverse complemented if necessary */ +static char *get_read(const bam1_t *rec) +{ + int len = rec->core.l_qseq + 1; + char *read = calloc(1, len); + char *seq = (char *)bam_get_seq(rec); + int n; + + if (!read) return NULL; + + for (n=0; n < rec->core.l_qseq; n++) { + if (rec->core.flag & BAM_FREVERSE) read[n] = seq_nt16_str[seq_comp_table[bam_seqi(seq,n)]]; + else read[n] = seq_nt16_str[bam_seqi(seq,n)]; + } + if (rec->core.flag & BAM_FREVERSE) reverse(read); + return read; +} + +/* + * get and decode the quality from a BAM record + */ +static int get_quality(const bam1_t *rec, char **qual_out) +{ + char *quality = calloc(1, rec->core.l_qseq + 1); + char *q = (char *)bam_get_qual(rec); + int n; + + if (!quality) return -1; + + if (*q == '\xff') { + free(quality); + *qual_out = NULL; + return 0; + } + + for (n=0; n < rec->core.l_qseq; n++) { + quality[n] = q[n]+33; + } + if (rec->core.flag & BAM_FREVERSE) reverse(quality); + *qual_out = quality; + return 0; +} + +// +// End of htslib complaints +// + + static readpart which_readpart(const bam1_t *b) { if ((b->core.flag & BAM_FREAD1) && !(b->core.flag & BAM_FREAD2)) { @@ -674,91 +890,281 @@ static readpart which_readpart(const bam1_t *b) } } -// Transform a bam1_t record into a string with the FASTQ representation of it -// @returns false for error, true for success -static bool bam1_to_fq(const bam1_t *b, kstring_t *linebuf, const bam2fq_state_t *state) +/* + * parse the length part from the index-format string + */ +static int getLength(char **s) { - int i; - int32_t qlen = b->core.l_qseq; - assert(qlen >= 0); - uint8_t *seq; - uint8_t *qual = bam_get_qual(b); - const uint8_t *oq = NULL; - if (state->use_oq) { - oq = bam_aux_get(b, "OQ"); - if (oq) oq++; // skip tag type + int n = 0; + while (**s) { + if (**s == '*') { n=-1; (*s)++; break; } + if ( !isdigit(**s)) break; + n = n*10 + ((**s)-'0'); + (*s)++; } - bool has_qual = (qual[0] != 0xff || (state->use_oq && oq)); // test if there is quality + return n; +} + +static bool copy_tag(const char *tag, const bam1_t *rec, kstring_t *linebuf) +{ + uint8_t *s = bam_aux_get(rec, tag); + if (s) { + char aux_type = *s; + switch (aux_type) { + case 'C': + case 'S': aux_type = 'I'; break; + case 'c': + case 's': aux_type = 'i'; break; + case 'd': aux_type = 'f'; break; + } + + // Ensure space. Need 6 chars + length of tag. Max length of + // i is 16, A is 21, B currently 26, Z is unknown, so + // have to check that one later. + if (ks_resize(linebuf, ks_len(linebuf) + 64) < 0) return false; + + kputc('\t', linebuf); + kputsn(tag, 2, linebuf); + kputc(':', linebuf); + kputc(aux_type=='I'? 'i': aux_type, linebuf); + kputc(':', linebuf); + switch (aux_type) { + case 'H': + case 'Z': + if (kputs(bam_aux2Z(s), linebuf) < 0) return false; + break; + case 'i': kputw(bam_aux2i(s), linebuf); break; + case 'I': kputuw(bam_aux2i(s), linebuf); break; + case 'A': kputc(bam_aux2A(s), linebuf); break; + case 'f': kputd(bam_aux2f(s), linebuf); break; + case 'B': kputs("*** Unhandled aux type ***", linebuf); return false; + default: kputs("*** Unknown aux type ***", linebuf); return false; + } + } + return true; +} + +static int insert_index_sequence_into_linebuf(char *index_sequence, kstring_t *linebuf, bam1_t *rec) +{ + if (!index_sequence) return 0; + + kstring_t new = {0,0,NULL}; + if (linebuf->s) { + char *s = strchr(linebuf->s, '\n'); + if (s) { + if (ks_resize(&new, linebuf->l + strlen(index_sequence) + 16) < 0) + return -1; + *s = 0; + kputs(linebuf->s, &new); + kputc(' ', &new); + readpart readpart = which_readpart(rec); + if (readpart == READ_1) kputc('1', &new); + else if (readpart == READ_2) kputc('2', &new); + else kputc('0', &new); + + kputc(':', &new); + if (rec->core.flag & BAM_FQCFAIL) kputc('Y', &new); + else kputc('N', &new); + + kputs(":0:", &new); + kputs(index_sequence, &new); + kputc('\n', &new); + kputs(s+1, &new); + free(ks_release(linebuf)); + linebuf->s = new.s; linebuf->l = new.l; linebuf->m = new.m; + } + } + return 0; +} + +static bool make_fq_line(const bam1_t *rec, char *seq, char *qual, kstring_t *linebuf, const bam2fq_state_t *state) +{ + int i; linebuf->l = 0; // Write read name - readpart readpart = which_readpart(b); - kputc(state->filetype == FASTA? '>' : '@', linebuf); - kputs(bam_get_qname(b), linebuf); + if (kputc(state->filetype == FASTA? '>' : '@', linebuf) < 0) return false; + if (kputs(bam_get_qname(rec), linebuf) < 0) return false; // Add the /1 /2 if requested if (state->has12) { - if (readpart == READ_1) kputs("/1", linebuf); - else if (readpart == READ_2) kputs("/2", linebuf); + readpart readpart = which_readpart(rec); + if (readpart == READ_1) { + if (kputs("/1", linebuf) < 0) return false; + } else if (readpart == READ_2) { + if (kputs("/2", linebuf) < 0) return false; + } } if (state->copy_tags) { for (i = 0; copied_tags[i]; ++i) { - uint8_t *s; - if ((s = bam_aux_get(b, copied_tags[i])) != 0) { - kputc('\t', linebuf); - kputsn(copied_tags[i], 2, linebuf); - kputsn(":Z:", 3, linebuf); - kputs(bam_aux2Z(s), linebuf); + if (!copy_tag(copied_tags[i], rec, linebuf)) { + fprintf(samtools_stderr, "Problem copying aux tags: [%s]\n", linebuf->s); + return false; } } } - kputc('\n', linebuf); - - seq = bam_get_seq(b); - if (b->core.flag & BAM_FREVERSE) { // read is reverse complemented - for (i = qlen-1; i > -1; --i) { - char c = seq_nt16_str[seq_comp_table[bam_seqi(seq,i)]]; - kputc(c, linebuf); - } - } else { - for (i = 0; i < qlen; ++i) { - char c = seq_nt16_str[bam_seqi(seq,i)]; - kputc(c, linebuf); + if (state->taglist->size) { + kliter_t(ktaglist) *p; + for (p = kl_begin(state->taglist); p != kl_end(state->taglist); p = kl_next(p)) { + if (!copy_tag(kl_val(p), rec, linebuf)) { + fprintf(samtools_stderr, "Problem copying aux tags: [%s]\n", linebuf->s); + return false; + } } } - kputc('\n', linebuf); + + if (kputc('\n', linebuf) < 0) return false; + if (kputs(seq, linebuf) < 0) return false; + if (kputc('\n', linebuf) < 0) return false; if (state->filetype == FASTQ) { // Write quality - kputs("+\n", linebuf); - if (has_qual) { - if (state->use_oq && oq) { - if (b->core.flag & BAM_FREVERSE) { // read is reverse complemented - for (i = qlen-1; i > -1; --i) { - kputc(oq[i], linebuf); - } - } else { - kputs((char*)oq, linebuf); - } - } else { - if (b->core.flag & BAM_FREVERSE) { // read is reverse complemented - for (i = qlen-1; i > -1; --i) { - kputc(33 + qual[i], linebuf); - } - } else { - for (i = 0; i < qlen; ++i) { - kputc(33 + qual[i], linebuf); - } - } - } + if (kputs("+\n", linebuf) < 0) return false; + if (qual && *qual) { + if (kputs(qual, linebuf) < 0) return false; } else { - for (i = 0; i < qlen; ++i) { + int len = strlen(seq); + if (ks_resize(linebuf, ks_len(linebuf) + len + 1) < 0) return false; + for (i = 0; i < len; ++i) { kputc(33 + state->def_qual, linebuf); } } - kputc('\n', linebuf); + if (kputc('\n', linebuf) < 0) return false; + } + return true; +} + +/* + * Create FASTQ lines from the barcode tag using the index-format + */ +static bool tags2fq(bam1_t *rec, bam2fq_state_t *state, const bam2fq_opts_t* opts) +{ + uint8_t *p; + char *ifmt = opts->index_format; + char *tag = NULL; + char *qual = NULL; + char *sub_tag = NULL; + char *sub_qual = NULL; + size_t tag_len; + int file_number = 0; + kstring_t linebuf = { 0, 0, NULL }; // Buffer + + + // read barcode tag + p = bam_aux_get(rec,opts->barcode_tag); + if (p) tag = bam_aux2Z(p); + + if (!tag) return true; // there is no tag + + tag_len = strlen(tag); + sub_tag = calloc(1, tag_len + 1); + if (!sub_tag) goto fail; + sub_qual = calloc(1, tag_len + 1); + if (!sub_qual) goto fail; + + // read quality tag + p = bam_aux_get(rec, opts->quality_tag); + if (p) qual = bam_aux2Z(p); + + // Parse the index-format string + while (*ifmt) { + if (file_number > 1) break; // shouldn't happen if we've validated paramaters correctly + char action = *ifmt; // should be 'i' or 'n' + ifmt++; // skip over action + int index_len = getLength(&ifmt); + int n = 0; + + if (index_len < 0) { + // read until separator + while (isalpha(*tag)) { + sub_tag[n] = *tag++; + if (qual) sub_qual[n] = *qual++; + n++; + } + if (*tag) { // skip separator + tag++; + if (qual) qual++; + } + } else { + // read index_len characters + while (index_len-- && *tag) { + sub_tag[n] = *tag++; + if (qual) sub_qual[n] = *qual++; + n++; + } + } + sub_tag[n] = '\0'; + sub_qual[n] = '\0'; + + if (action=='i' && *sub_tag && state->fpi[file_number]) { + //if (file_number==0) state->index_sequence = strdup(sub_tag); // we're going to need this later... + state->index_sequence = strdup(sub_tag); // we're going to need this later... + if (!state->index_sequence) goto fail; + if (!make_fq_line(rec, sub_tag, sub_qual, &linebuf, state)) goto fail; + if (state->illumina_tag) { + if (insert_index_sequence_into_linebuf(state->index_sequence, &linebuf, rec) < 0) { + goto fail; + } + } + if (bgzf_write(state->fpi[file_number++], linebuf.s, linebuf.l) < 0) + goto fail; + } + + } + + free(sub_qual); free(sub_tag); + free(linebuf.s); + return true; + + fail: + perror(__func__); + free(sub_qual); free(sub_tag); + free(linebuf.s); + return true; +} + +// Transform a bam1_t record into a string with the FASTQ representation of it +// @returns false for error, true for success +static bool bam1_to_fq(const bam1_t *b, kstring_t *linebuf, const bam2fq_state_t *state) +{ + int32_t qlen = b->core.l_qseq; + assert(qlen >= 0); + const uint8_t *oq = NULL; + char *qual = NULL; + + char *seq = get_read(b); + if (!seq) return false; + + if (state->use_oq) oq = bam_aux_get(b, "OQ"); + if (oq && *oq=='Z') { + qual = strdup(bam_aux2Z(oq)); + if (!qual) goto fail; + if (b->core.flag & BAM_FREVERSE) { // read is reverse complemented + reverse(qual); + } + } else { + if (get_quality(b, &qual) < 0) goto fail; } + + if (!make_fq_line(b, seq, qual, linebuf, state)) goto fail; + + free(qual); + free(seq); return true; + + fail: + free(seq); + free(qual); + return false; +} + +static void free_opts(bam2fq_opts_t *opts) +{ + free(opts->barcode_tag); + free(opts->quality_tag); + free(opts->index_format); + free(opts->extra_tags); + free(opts); } // return true if valid @@ -767,43 +1173,116 @@ static bool parse_opts(int argc, char *argv[], bam2fq_opts_t** opts_out) // Parse args bam2fq_opts_t* opts = calloc(1, sizeof(bam2fq_opts_t)); opts->has12 = true; + opts->has12always = false; opts->filetype = FASTQ; opts->def_qual = 1; + opts->barcode_tag = NULL; + opts->quality_tag = NULL; + opts->index_format = NULL; + opts->index_file[0] = NULL; + opts->index_file[1] = NULL; + opts->extra_tags = NULL; + opts->compression_level = 1; int c; sam_global_args_init(&opts->ga); static const struct option lopts[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0, '@'), + {"i1", required_argument, NULL, 1}, + {"I1", required_argument, NULL, 1}, + {"i2", required_argument, NULL, 2}, + {"I2", required_argument, NULL, 2}, + {"if", required_argument, NULL, 3}, + {"IF", required_argument, NULL, 3}, + {"index-format", required_argument, NULL, 3}, + {"barcode-tag", required_argument, NULL, 'b'}, + {"quality-tag", required_argument, NULL, 'q'}, { NULL, 0, NULL, 0 } }; - while ((c = getopt_long(argc, argv, "0:1:2:f:F:nOs:tv:", lopts, NULL)) > 0) { + while ((c = getopt_long(argc, argv, "0:1:2:f:F:G:niNOs:c:tT:v:@:", lopts, NULL)) > 0) { switch (c) { + case 'b': opts->barcode_tag = strdup(optarg); break; + case 'q': opts->quality_tag = strdup(optarg); break; + case 1 : opts->index_file[0] = optarg; break; + case 2 : opts->index_file[1] = optarg; break; + case 3 : opts->index_format = strdup(optarg); break; case '0': opts->fnr[0] = optarg; break; case '1': opts->fnr[1] = optarg; break; case '2': opts->fnr[2] = optarg; break; case 'f': opts->flag_on |= strtol(optarg, 0, 0); break; case 'F': opts->flag_off |= strtol(optarg, 0, 0); break; + case 'G': opts->flag_alloff |= strtol(optarg, 0, 0); break; case 'n': opts->has12 = false; break; + case 'N': opts->has12always = true; break; case 'O': opts->use_oq = true; break; case 's': opts->fnse = optarg; break; case 't': opts->copy_tags = true; break; + case 'i': opts->illumina_tag = true; break; + case 'c': opts->compression_level = atoi(optarg); break; + case 'T': opts->extra_tags = strdup(optarg); break; case 'v': opts->def_qual = atoi(optarg); break; - case '?': bam2fq_usage(pysam_stderr, argv[0]); free(opts); return false; + case '?': bam2fq_usage(samtools_stderr, argv[0]); free_opts(opts); return false; default: if (parse_sam_global_opt(c, optarg, lopts, &opts->ga) != 0) { - bam2fq_usage(pysam_stderr, argv[0]); free(opts); return false; + bam2fq_usage(samtools_stderr, argv[0]); free_opts(opts); return false; } break; } } if (opts->fnr[1] || opts->fnr[2]) opts->has12 = false; + if (opts->has12always) opts->has12 = true; + + if (!opts->barcode_tag) opts->barcode_tag = strdup(DEFAULT_BARCODE_TAG); + if (!opts->quality_tag) opts->quality_tag = strdup(DEFAULT_QUALITY_TAG); + + int nIndex = 0; + if (opts->index_format) { + char *s; + for (s = opts->index_format; *s; s++) { + if (*s == 'i') nIndex++; + } + } + if (nIndex>2) { + fprintf(samtools_stderr,"Invalid index format: more than 2 indexes\n"); + bam2fq_usage(samtools_stderr, argv[0]); + free_opts(opts); + return false; + } + + if (opts->index_file[1] && !opts->index_file[0]) { + fprintf(samtools_stderr, "Index one specified, but index two not given\n"); + bam2fq_usage(samtools_stderr, argv[0]); + free_opts(opts); + return false; + } + + if (nIndex==2 && !opts->index_file[1]) { + fprintf(samtools_stderr, "index_format specifies two indexes, but only one index file given\n"); + bam2fq_usage(samtools_stderr, argv[0]); + free_opts(opts); + return false; + } + + if (nIndex==1 && !opts->index_file[0]) { + fprintf(samtools_stderr, "index_format specifies an index, but no index file given\n"); + bam2fq_usage(samtools_stderr, argv[0]); + free_opts(opts); + return false; + } + + if (nIndex==0 && opts->index_file[0]) { + fprintf(samtools_stderr, "index_format not specified, but index file given\n"); + bam2fq_usage(samtools_stderr, argv[0]); + free_opts(opts); + return false; + } if (opts->def_qual < 0 || 93 < opts->def_qual) { - fprintf(pysam_stderr, "Invalid -v default quality %i, allowed range 0 to 93\n", opts->def_qual); - bam2fq_usage(pysam_stderr, argv[0]); - free(opts); - return true; + fprintf(samtools_stderr, "Invalid -v default quality %i, allowed range 0 to 93\n", opts->def_qual); + bam2fq_usage(samtools_stderr, argv[0]); + free_opts(opts); + return false; } const char* type_str = argv[0]; @@ -813,21 +1292,22 @@ static bool parse_opts(int argc, char *argv[], bam2fq_opts_t** opts_out) opts->filetype = FASTA; } else { print_error("bam2fq", "Unrecognised type call \"%s\", this should be impossible... but you managed it!", type_str); - bam2fq_usage(pysam_stderr, argv[0]); - free(opts); + bam2fq_usage(samtools_stderr, argv[0]); + free_opts(opts); return false; } if ((argc - (optind)) == 0) { - bam2fq_usage(pysam_stdout, argv[0]); - free(opts); + fprintf(samtools_stderr, "No input file specified.\n"); + bam2fq_usage(samtools_stdout, argv[0]); + free_opts(opts); return false; } if ((argc - (optind)) != 1) { - fprintf(pysam_stderr, "Too many arguments.\n"); - bam2fq_usage(pysam_stderr, argv[0]); - free(opts); + fprintf(samtools_stderr, "Too many arguments.\n"); + bam2fq_usage(samtools_stderr, argv[0]); + free_opts(opts); return false; } opts->fn_input = argv[optind]; @@ -835,16 +1315,55 @@ static bool parse_opts(int argc, char *argv[], bam2fq_opts_t** opts_out) return true; } +static BGZF *open_fqfile(char *filename, int c) +{ + char mode[4] = "w"; + size_t len = strlen(filename); + + mode[2] = 0; mode[3] = 0; + if (len > 3 && strstr(filename + (len - 3),".gz")) { + mode[1] = 'g'; mode[2] = c+'0'; + } else if ((len > 4 && strstr(filename + (len - 4),".bgz")) + || (len > 5 && strstr(filename + (len - 5),".bgzf"))) { + mode[1] = c+'0'; + } else { + mode[1] = 'u'; + } + + return bgzf_open(filename,mode); +} + static bool init_state(const bam2fq_opts_t* opts, bam2fq_state_t** state_out) { bam2fq_state_t* state = calloc(1, sizeof(bam2fq_state_t)); state->flag_on = opts->flag_on; state->flag_off = opts->flag_off; + state->flag_alloff = opts->flag_alloff; state->has12 = opts->has12; state->use_oq = opts->use_oq; + state->illumina_tag = opts->illumina_tag; state->copy_tags = opts->copy_tags; state->filetype = opts->filetype; state->def_qual = opts->def_qual; + state->index_sequence = NULL; + state->hsamtools_stdout = bgzf_dopen(fileno(samtools_stdout), "wu"); + state->compression_level = opts->compression_level; + + state->taglist = kl_init(ktaglist); + if (opts->extra_tags) { + char *save_p; + char *s = strtok_r(opts->extra_tags, ",", &save_p); + while (s) { + if (strlen(s) != 2) { + fprintf(samtools_stderr, "Parsing extra tags - '%s' is not two characters\n", s); + free(state); + return false; + } + char **et = kl_pushp(ktaglist, state->taglist); + *et = s; + s = strtok_r(NULL, ",", &save_p); + } + } state->fp = sam_open(opts->fn_input, "r"); if (state->fp == NULL) { @@ -852,20 +1371,22 @@ static bool init_state(const bam2fq_opts_t* opts, bam2fq_state_t** state_out) free(state); return false; } + if (opts->ga.nthreads > 0) + hts_set_threads(state->fp, opts->ga.nthreads); uint32_t rf = SAM_QNAME | SAM_FLAG | SAM_SEQ | SAM_QUAL; - if (opts->use_oq) rf |= SAM_AUX; + if (opts->use_oq || opts->extra_tags || opts->index_file[0]) rf |= SAM_AUX; if (hts_set_opt(state->fp, CRAM_OPT_REQUIRED_FIELDS, rf)) { - fprintf(pysam_stderr, "Failed to set CRAM_OPT_REQUIRED_FIELDS value\n"); + fprintf(samtools_stderr, "Failed to set CRAM_OPT_REQUIRED_FIELDS value\n"); free(state); return false; } if (hts_set_opt(state->fp, CRAM_OPT_DECODE_MD, 0)) { - fprintf(pysam_stderr, "Failed to set CRAM_OPT_DECODE_MD value\n"); + fprintf(samtools_stderr, "Failed to set CRAM_OPT_DECODE_MD value\n"); free(state); return false; } if (opts->fnse) { - state->fpse = fopen(opts->fnse,"w"); + state->fpse = open_fqfile(opts->fnse, state->compression_level); if (state->fpse == NULL) { print_error_errno("bam2fq", "Cannot write to singleton file \"%s\"", opts->fnse); free(state); @@ -876,20 +1397,31 @@ static bool init_state(const bam2fq_opts_t* opts, bam2fq_state_t** state_out) int i; for (i = 0; i < 3; ++i) { if (opts->fnr[i]) { - state->fpr[i] = fopen(opts->fnr[i], "w"); + state->fpr[i] = open_fqfile(opts->fnr[i], state->compression_level); if (state->fpr[i] == NULL) { print_error_errno("bam2fq", "Cannot write to r%d file \"%s\"", i, opts->fnr[i]); free(state); return false; } } else { - state->fpr[i] = pysam_stdout; + state->fpr[i] = state->hsamtools_stdout; + } + } + for (i = 0; i < 2; i++) { + state->fpi[i] = NULL; + if (opts->index_file[i]) { + state->fpi[i] = open_fqfile(opts->index_file[i], state->compression_level); + if (state->fpi[i] == NULL) { + print_error_errno("bam2fq", "Cannot write to i%d file \"%s\"", i+1, opts->index_file[i]); + free(state); + return false; + } } } state->h = sam_hdr_read(state->fp); if (state->h == NULL) { - fprintf(pysam_stderr, "Failed to read header for \"%s\"\n", opts->fn_input); + fprintf(samtools_stderr, "Failed to read header for \"%s\"\n", opts->fn_input); free(state); return false; } @@ -903,11 +1435,23 @@ static bool destroy_state(const bam2fq_opts_t *opts, bam2fq_state_t *state, int* bool valid = true; bam_hdr_destroy(state->h); check_sam_close("bam2fq", state->fp, opts->fn_input, "file", status); - if (state->fpse && fclose(state->fpse)) { print_error_errno("bam2fq", "Error closing singleton file \"%s\"", opts->fnse); valid = false; } + if (state->fpse && bgzf_close(state->fpse)) { print_error_errno("bam2fq", "Error closing singleton file \"%s\"", opts->fnse); valid = false; } int i; for (i = 0; i < 3; ++i) { - if (state->fpr[i] != pysam_stdout && fclose(state->fpr[i])) { print_error_errno("bam2fq", "Error closing r%d file \"%s\"", i, opts->fnr[i]); valid = false; } + if (state->fpr[i] == state->hsamtools_stdout) { + if (i==0 && bgzf_close(state->fpr[i])) { print_error_errno("bam2fq", "Error closing STDOUT"); valid = false; } + } else { + if (bgzf_close(state->fpr[i])) { print_error_errno("bam2fq", "Error closing r%d file \"%s\"", i, opts->fnr[i]); valid = false; } + } + } + for (i = 0; i < 2; i++) { + if (state->fpi[i] && bgzf_close(state->fpi[i])) { + print_error_errno("bam2fq", "Error closing i%d file \"%s\"", i+1, opts->index_file[i]); + valid = false; + } } + kl_destroy(ktaglist,state->taglist); + free(state->index_sequence); free(state); return valid; } @@ -916,12 +1460,15 @@ static inline bool filter_it_out(const bam1_t *b, const bam2fq_state_t *state) { return (b->core.flag&(BAM_FSECONDARY|BAM_FSUPPLEMENTARY) // skip secondary and supplementary alignments || (b->core.flag&(state->flag_on)) != state->flag_on // or reads indicated by filter flags - || (b->core.flag&(state->flag_off)) != 0); + || (b->core.flag&(state->flag_off)) != 0 + || (b->core.flag&(state->flag_alloff) && (b->core.flag&(state->flag_alloff)) == state->flag_alloff)); } -static bool bam2fq_mainloop_singletontrack(bam2fq_state_t *state) +static bool bam2fq_mainloop(bam2fq_state_t *state, bam2fq_opts_t* opts) { + int n; + bam1_t *records[3]; bam1_t* b = bam_init1(); char *current_qname = NULL; int64_t n_reads = 0, n_singletons = 0; // Statistics @@ -929,35 +1476,55 @@ static bool bam2fq_mainloop_singletontrack(bam2fq_state_t *state) int score[3]; int at_eof; if (b == NULL ) { - perror("[bam2fq_mainloop_singletontrack] Malloc error for bam record buffer."); + perror("[bam2fq_mainloop] Malloc error for bam record buffer."); return false; } bool valid = true; while (true) { - at_eof = sam_read1(state->fp, state->h, b) < 0; + int res = sam_read1(state->fp, state->h, b); + if (res < -1) { + fprintf(samtools_stderr, "[bam2fq_mainloop] Failed to read bam record.\n"); + return false; + } + at_eof = res < 0; if (!at_eof && filter_it_out(b, state)) continue; if (!at_eof) ++n_reads; if (at_eof || !current_qname || (strcmp(current_qname, bam_get_qname(b)) != 0)) { if (current_qname) { + if (state->illumina_tag) { + for (n=0; valid && n<3; n++) { + if (insert_index_sequence_into_linebuf(state->index_sequence, &linebuf[n], records[n]) < 0) valid = false; + } + if (!valid) break; + } + free(state->index_sequence); state->index_sequence = NULL; if (score[1] > 0 && score[2] > 0) { // print linebuf[1] to fpr[1], linebuf[2] to fpr[2] - if (fputs(linebuf[1].s, state->fpr[1]) == EOF) { valid = false; break; } - if (fputs(linebuf[2].s, state->fpr[2]) == EOF) { valid = false; break; } + if (bgzf_write(state->fpr[1], linebuf[1].s, linebuf[1].l) < 0) { valid = false; break; } + if (bgzf_write(state->fpr[2], linebuf[2].s, linebuf[2].l) < 0) { valid = false; break; } } else if (score[1] > 0 || score[2] > 0) { - // print whichever one exists to fpse - if (score[1] > 0) { - if (fputs(linebuf[1].s, state->fpse) == EOF) { valid = false; break; } + if (state->fpse) { + // print whichever one exists to fpse + if (score[1] > 0) { + if (bgzf_write(state->fpse, linebuf[1].s, linebuf[1].l) < 0) { valid = false; break; } + } else { + if (bgzf_write(state->fpse, linebuf[2].s, linebuf[2].l) < 0) { valid = false; break; } + } + ++n_singletons; } else { - if (fputs(linebuf[2].s, state->fpse) == EOF) { valid = false; break; } + if (score[1] > 0) { + if (bgzf_write(state->fpr[1], linebuf[1].s, linebuf[1].l) < 0) { valid = false; break; } + } else { + if (bgzf_write(state->fpr[2], linebuf[2].s, linebuf[2].l) < 0) { valid = false; break; } + } } - ++n_singletons; } if (score[0]) { // TODO: check this // print linebuf[0] to fpr[0] - if (fputs(linebuf[0].s, state->fpr[0]) == EOF) { valid = false; break; } + if (bgzf_write(state->fpr[0], linebuf[0].s, linebuf[0].l) < 0) { valid = false; break; } } } @@ -965,14 +1532,17 @@ static bool bam2fq_mainloop_singletontrack(bam2fq_state_t *state) free(current_qname); current_qname = strdup(bam_get_qname(b)); + if (!current_qname) { valid = false; break; } score[0] = score[1] = score[2] = 0; } // Prefer a copy of the read that has base qualities int b_score = bam_get_qual(b)[0] != 0xff? 2 : 1; if (b_score > score[which_readpart(b)]) { + if (state->fpi[0]) if (!tags2fq(b, state, opts)) return false; + records[which_readpart(b)] = b; if(!bam1_to_fq(b, &linebuf[which_readpart(b)], state)) { - fprintf(pysam_stderr, "[%s] Error converting read to FASTA/Q\n", __func__); + fprintf(samtools_stderr, "[%s] Error converting read to FASTA/Q\n", __func__); return false; } score[which_readpart(b)] = b_score; @@ -980,45 +1550,19 @@ static bool bam2fq_mainloop_singletontrack(bam2fq_state_t *state) } if (!valid) { - perror("[bam2fq_mainloop_singletontrack] Error writing to FASTx files."); + perror("[bam2fq_mainloop] Error writing to FASTx files."); } bam_destroy1(b); free(current_qname); free(linebuf[0].s); free(linebuf[1].s); free(linebuf[2].s); - fprintf(pysam_stderr, "[M::%s] discarded %" PRId64 " singletons\n", __func__, n_singletons); - fprintf(pysam_stderr, "[M::%s] processed %" PRId64 " reads\n", __func__, n_reads); + fprintf(samtools_stderr, "[M::%s] discarded %" PRId64 " singletons\n", __func__, n_singletons); + fprintf(samtools_stderr, "[M::%s] processed %" PRId64 " reads\n", __func__, n_reads); return valid; } -static bool bam2fq_mainloop(bam2fq_state_t *state) -{ - // process a name collated BAM into fastq - bam1_t* b = bam_init1(); - if (b == NULL) { - perror(NULL); - return false; - } - int64_t n_reads = 0; // Statistics - kstring_t linebuf = { 0, 0, NULL }; // Buffer - while (sam_read1(state->fp, state->h, b) >= 0) { - if (b->core.flag&(BAM_FSECONDARY|BAM_FSUPPLEMENTARY) // skip secondary and supplementary alignments - || (b->core.flag&(state->flag_on)) != state->flag_on // or reads indicated by filter flags - || (b->core.flag&(state->flag_off)) != 0) continue; - ++n_reads; - - if (!bam1_to_fq(b, &linebuf, state)) return false; - fputs(linebuf.s, state->fpr[which_readpart(b)]); - } - free(linebuf.s); - bam_destroy1(b); - - fprintf(pysam_stderr, "[M::%s] processed %" PRId64 " reads\n", __func__, n_reads); - return true; -} - int main_bam2fq(int argc, char *argv[]) { int status = EXIT_SUCCESS; @@ -1030,15 +1574,11 @@ int main_bam2fq(int argc, char *argv[]) if (!init_state(opts, &state)) return EXIT_FAILURE; - if (state->fpse) { - if (!bam2fq_mainloop_singletontrack(state)) status = EXIT_FAILURE; - } else { - if (!bam2fq_mainloop(state)) status = EXIT_FAILURE; - } + if (!bam2fq_mainloop(state,opts)) status = EXIT_FAILURE; if (!destroy_state(opts, state, &status)) return EXIT_FAILURE; sam_global_args_free(&opts->ga); - free(opts); + free_opts(opts); return status; } diff --git a/samtools/sample.c.pysam.c b/samtools/sample.c.pysam.c index dff818825..8b39a90f3 100644 --- a/samtools/sample.c.pysam.c +++ b/samtools/sample.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* sample.c -- group data by sample. diff --git a/samtools/samtools.h b/samtools/samtools.h index 1e726543d..7a406a22a 100644 --- a/samtools/samtools.h +++ b/samtools/samtools.h @@ -26,6 +26,7 @@ DEALINGS IN THE SOFTWARE. */ #define SAMTOOLS_H const char *samtools_version(void); +const char *samtools_version_short(void); #if defined __GNUC__ && __GNUC__ >= 2 #define CHECK_PRINTF(fmt,args) __attribute__ ((format (printf, fmt, args))) diff --git a/samtools/samtools.pysam.c b/samtools/samtools.pysam.c new file mode 100644 index 000000000..c276a8a09 --- /dev/null +++ b/samtools/samtools.pysam.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include +#include + +#include "samtools.pysam.h" + +FILE * samtools_stderr = NULL; +FILE * samtools_stdout = NULL; +const char * samtools_stdout_fn = NULL; +int samtools_stdout_fileno = STDOUT_FILENO; + + +FILE * samtools_set_stderr(int fd) +{ + if (samtools_stderr != NULL) + fclose(samtools_stderr); + samtools_stderr = fdopen(fd, "w"); + return samtools_stderr; +} + +void samtools_unset_stderr(void) +{ + if (samtools_stderr != NULL) + fclose(samtools_stderr); + samtools_stderr = fopen("/dev/null", "w"); +} + +FILE * samtools_set_stdout(int fd) +{ + if (samtools_stdout != NULL) + fclose(samtools_stdout); + samtools_stdout = fdopen(fd, "w"); + if (samtools_stdout == NULL) + { + fprintf(samtools_stderr, "could not set stdout to fd %i", fd); + } + samtools_stdout_fileno = fd; + return samtools_stdout; +} + +void samtools_set_stdout_fn(const char *fn) +{ + samtools_stdout_fn = fn; +} + +void samtools_unset_stdout(void) +{ + if (samtools_stdout != NULL) + fclose(samtools_stdout); + samtools_stdout = fopen("/dev/null", "w"); + samtools_stdout_fileno = STDOUT_FILENO; +} + +void samtools_set_optind(int val) +{ + // setting this in cython via + // "from posix.unistd cimport optind" + // did not work. + // + // setting to 0 forces a complete re-initialization + optind = val; +} + + + diff --git a/samtools/samtools.pysam.h b/samtools/samtools.pysam.h new file mode 100644 index 000000000..e2bfd85e7 --- /dev/null +++ b/samtools/samtools.pysam.h @@ -0,0 +1,47 @@ +#ifndef PYSAM_H +#define PYSAM_H + +#include "stdio.h" + +extern FILE * samtools_stderr; + +extern FILE * samtools_stdout; + +extern const char * samtools_stdout_fn; + +/*! set pysam standard error to point to file descriptor + + Setting the stderr will close the previous stderr. + */ +FILE * samtools_set_stderr(int fd); + +/*! set pysam standard output to point to file descriptor + + Setting the stderr will close the previous stdout. + */ +FILE * samtools_set_stdout(int fd); + +/*! set pysam standard output to point to filename + + */ +void samtools_set_stdout_fn(const char * fn); + +/*! set pysam standard error to /dev/null. + + Unsetting the stderr will close the previous stderr. + */ +void samtools_unset_stderr(void); + +/*! set pysam standard error to /dev/null. + + Unsetting the stderr will close the previous stderr. + */ +void samtools_unset_stdout(void); + +int samtools_dispatch(int argc, char *argv[]); + +void samtools_set_optind(int); + +extern int samtools_main(int argc, char *argv[]); + +#endif diff --git a/samtools/stats.c b/samtools/stats.c index eb6bb525d..35574ed83 100644 --- a/samtools/stats.c +++ b/samtools/stats.c @@ -828,8 +828,8 @@ void collect_stats(bam1_t *bam_line, stats_t *stats) // reads. Mates mapped to different chromosomes have isize==0. int32_t isize = bam_line->core.isize; if ( isize<0 ) isize = -isize; - if ( stats->info->nisize > 0 && isize >= stats->info->nisize ) - isize = stats->info->nisize-1; + if ( stats->info->nisize > 0 && isize > stats->info->nisize ) + isize = stats->info->nisize; if ( isize>0 || bam_line->core.tid==bam_line->core.mtid ) { int pos_fst = bam_line->core.mpos - bam_line->core.pos; @@ -1263,7 +1263,7 @@ void init_regions(stats_t *stats, const char *file) stats->regions[tid].pos = realloc(stats->regions[tid].pos,sizeof(pos_t)*stats->regions[tid].mpos); } - if ( (sscanf(&line.s[i+1],"%d %d",&stats->regions[tid].pos[npos].from,&stats->regions[tid].pos[npos].to))!=2 ) error("Could not parse the region [%s]\n", &line.s[i+1]); + if ( (sscanf(&line.s[i+1],"%u %u",&stats->regions[tid].pos[npos].from,&stats->regions[tid].pos[npos].to))!=2 ) error("Could not parse the region [%s]\n", &line.s[i+1]); if ( prev_tid==-1 || prev_tid!=tid ) { prev_tid = tid; @@ -1375,7 +1375,7 @@ static void error(const char *format, ...) printf(" -S, --split Also write statistics to separate files split by tagged field.\n"); printf(" -t, --target-regions Do stats in these regions only. Tab-delimited file chr,from,to, 1-based, inclusive.\n"); printf(" -x, --sparse Suppress outputting IS rows where there are no insertions.\n"); - sam_global_opt_help(stdout, "-.--."); + sam_global_opt_help(stdout, "-.--.@"); printf("\n"); } else @@ -1481,13 +1481,13 @@ int init_stat_info_fname(stats_info_t* info, const char* bam_fname, const htsFor // .. bam samFile* sam; if ((sam = sam_open_format(bam_fname, "r", in_fmt)) == 0) { - error("Failed to open: %s\n", bam_fname); + print_error_errno("stats", "failed to open \"%s\"", bam_fname); return 1; } info->sam = sam; info->sam_header = sam_hdr_read(sam); if (info->sam_header == NULL) { - error("Failed to read header for '%s'\n", bam_fname); + print_error("stats", "failed to read header for \"%s\"", bam_fname); return 1; } return 0; @@ -1537,7 +1537,7 @@ static void init_stat_structs(stats_t* stats, stats_info_t* info, const char* gr stats->quals_2nd = calloc(stats->nquals*stats->nbases,sizeof(uint64_t)); stats->gc_1st = calloc(stats->ngc,sizeof(uint64_t)); stats->gc_2nd = calloc(stats->ngc,sizeof(uint64_t)); - stats->isize = init_isize_t(info->nisize); + stats->isize = init_isize_t(info->nisize ?info->nisize+1 :0); stats->gcd = calloc(stats->ngcd,sizeof(gc_depth_t)); stats->mpc_buf = info->fai ? calloc(stats->nquals*stats->nbases,sizeof(uint64_t)) : NULL; stats->acgtno_cycles = calloc(stats->nbases,sizeof(acgtno_count_t)); @@ -1596,7 +1596,7 @@ int main_stats(int argc, char *argv[]) static const struct option loptions[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0, '@'), {"help", no_argument, NULL, 'h'}, {"remove-dups", no_argument, NULL, 'd'}, {"sam", no_argument, NULL, 's'}, @@ -1618,7 +1618,7 @@ int main_stats(int argc, char *argv[]) }; int opt; - while ( (opt=getopt_long(argc,argv,"?hdsxr:c:l:i:t:m:q:f:F:I:1:S:P:",loptions,NULL))>0 ) + while ( (opt=getopt_long(argc,argv,"?hdsxr:c:l:i:t:m:q:f:F:I:1:S:P:@:",loptions,NULL))>0 ) { switch (opt) { @@ -1662,6 +1662,8 @@ int main_stats(int argc, char *argv[]) } if (init_stat_info_fname(info, bam_fname, &ga.in)) return 1; + if (ga.nthreads > 0) + hts_set_threads(info->sam, ga.nthreads); stats_t *all_stats = stats_init(); stats_t *curr_stats = NULL; diff --git a/samtools/stats.c.pysam.c b/samtools/stats.c.pysam.c index da187ac4b..1c94a10a7 100644 --- a/samtools/stats.c.pysam.c +++ b/samtools/stats.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* stats.c -- This is the former bamcheck integrated into samtools/htslib. @@ -830,8 +830,8 @@ void collect_stats(bam1_t *bam_line, stats_t *stats) // reads. Mates mapped to different chromosomes have isize==0. int32_t isize = bam_line->core.isize; if ( isize<0 ) isize = -isize; - if ( stats->info->nisize > 0 && isize >= stats->info->nisize ) - isize = stats->info->nisize-1; + if ( stats->info->nisize > 0 && isize > stats->info->nisize ) + isize = stats->info->nisize; if ( isize>0 || bam_line->core.tid==bam_line->core.mtid ) { int pos_fst = bam_line->core.mpos - bam_line->core.pos; @@ -1242,7 +1242,7 @@ void init_regions(stats_t *stats, const char *file) if ( tid < 0 ) { if ( !warned ) - fprintf(pysam_stderr,"Warning: Some sequences not present in the BAM, e.g. \"%s\". This message is printed only once.\n", line.s); + fprintf(samtools_stderr,"Warning: Some sequences not present in the BAM, e.g. \"%s\". This message is printed only once.\n", line.s); warned = 1; continue; } @@ -1265,7 +1265,7 @@ void init_regions(stats_t *stats, const char *file) stats->regions[tid].pos = realloc(stats->regions[tid].pos,sizeof(pos_t)*stats->regions[tid].mpos); } - if ( (sscanf(&line.s[i+1],"%d %d",&stats->regions[tid].pos[npos].from,&stats->regions[tid].pos[npos].to))!=2 ) error("Could not parse the region [%s]\n", &line.s[i+1]); + if ( (sscanf(&line.s[i+1],"%u %u",&stats->regions[tid].pos[npos].from,&stats->regions[tid].pos[npos].to))!=2 ) error("Could not parse the region [%s]\n", &line.s[i+1]); if ( prev_tid==-1 || prev_tid!=tid ) { prev_tid = tid; @@ -1336,7 +1336,7 @@ void init_group_id(stats_t *stats, const char *id) { khiter_t k = kh_get(kh_rg, stats->rg_hash, key); if ( k != kh_end(stats->rg_hash) ) - fprintf(pysam_stderr, "[init_group_id] The group ID not unique: \"%s\"\n", key); + fprintf(samtools_stderr, "[init_group_id] The group ID not unique: \"%s\"\n", key); int ret; k = kh_put(kh_rg, stats->rg_hash, key, &ret); kh_value(stats->rg_hash, k) = val; @@ -1346,7 +1346,7 @@ void init_group_id(stats_t *stats, const char *id) if ( !n ) error("The sample or read group \"%s\" not present.\n", id); #else - fprintf(pysam_stderr, "Samtools-htslib: init_group_id() header parsing not yet implemented\n"); + fprintf(samtools_stderr, "Samtools-htslib: init_group_id() header parsing not yet implemented\n"); abort(); #endif } @@ -1356,35 +1356,35 @@ static void error(const char *format, ...) { if ( !format ) { - fprintf(pysam_stdout, "About: The program collects statistics from BAM files. The output can be visualized using plot-bamstats.\n"); - fprintf(pysam_stdout, "Usage: samtools stats [OPTIONS] file.bam\n"); - fprintf(pysam_stdout, " samtools stats [OPTIONS] file.bam chr:from-to\n"); - fprintf(pysam_stdout, "Options:\n"); - fprintf(pysam_stdout, " -c, --coverage ,, Coverage distribution min,max,step [1,1000,1]\n"); - fprintf(pysam_stdout, " -d, --remove-dups Exclude from statistics reads marked as duplicates\n"); - fprintf(pysam_stdout, " -f, --required-flag Required flag, 0 for unset. See also `samtools flags` [0]\n"); - fprintf(pysam_stdout, " -F, --filtering-flag Filtering flag, 0 for unset. See also `samtools flags` [0]\n"); - fprintf(pysam_stdout, " --GC-depth the size of GC-depth bins (decreasing bin size increases memory requirement) [2e4]\n"); - fprintf(pysam_stdout, " -h, --help This help message\n"); - fprintf(pysam_stdout, " -i, --insert-size Maximum insert size [8000]\n"); - fprintf(pysam_stdout, " -I, --id Include only listed read group or sample name\n"); - fprintf(pysam_stdout, " -l, --read-length Include in the statistics only reads with the given read length []\n"); - fprintf(pysam_stdout, " -m, --most-inserts Report only the main part of inserts [0.99]\n"); - fprintf(pysam_stdout, " -P, --split-prefix Path or string prefix for filepaths output by -S (default is input filename)\n"); - fprintf(pysam_stdout, " -q, --trim-quality The BWA trimming parameter [0]\n"); - fprintf(pysam_stdout, " -r, --ref-seq Reference sequence (required for GC-depth and mismatches-per-cycle calculation).\n"); - fprintf(pysam_stdout, " -s, --sam Ignored (input format is auto-detected).\n"); - fprintf(pysam_stdout, " -S, --split Also write statistics to separate files split by tagged field.\n"); - fprintf(pysam_stdout, " -t, --target-regions Do stats in these regions only. Tab-delimited file chr,from,to, 1-based, inclusive.\n"); - fprintf(pysam_stdout, " -x, --sparse Suppress outputting IS rows where there are no insertions.\n"); - sam_global_opt_help(pysam_stdout, "-.--."); - fprintf(pysam_stdout, "\n"); + fprintf(samtools_stdout, "About: The program collects statistics from BAM files. The output can be visualized using plot-bamstats.\n"); + fprintf(samtools_stdout, "Usage: samtools stats [OPTIONS] file.bam\n"); + fprintf(samtools_stdout, " samtools stats [OPTIONS] file.bam chr:from-to\n"); + fprintf(samtools_stdout, "Options:\n"); + fprintf(samtools_stdout, " -c, --coverage ,, Coverage distribution min,max,step [1,1000,1]\n"); + fprintf(samtools_stdout, " -d, --remove-dups Exclude from statistics reads marked as duplicates\n"); + fprintf(samtools_stdout, " -f, --required-flag Required flag, 0 for unset. See also `samtools flags` [0]\n"); + fprintf(samtools_stdout, " -F, --filtering-flag Filtering flag, 0 for unset. See also `samtools flags` [0]\n"); + fprintf(samtools_stdout, " --GC-depth the size of GC-depth bins (decreasing bin size increases memory requirement) [2e4]\n"); + fprintf(samtools_stdout, " -h, --help This help message\n"); + fprintf(samtools_stdout, " -i, --insert-size Maximum insert size [8000]\n"); + fprintf(samtools_stdout, " -I, --id Include only listed read group or sample name\n"); + fprintf(samtools_stdout, " -l, --read-length Include in the statistics only reads with the given read length []\n"); + fprintf(samtools_stdout, " -m, --most-inserts Report only the main part of inserts [0.99]\n"); + fprintf(samtools_stdout, " -P, --split-prefix Path or string prefix for filepaths output by -S (default is input filename)\n"); + fprintf(samtools_stdout, " -q, --trim-quality The BWA trimming parameter [0]\n"); + fprintf(samtools_stdout, " -r, --ref-seq Reference sequence (required for GC-depth and mismatches-per-cycle calculation).\n"); + fprintf(samtools_stdout, " -s, --sam Ignored (input format is auto-detected).\n"); + fprintf(samtools_stdout, " -S, --split Also write statistics to separate files split by tagged field.\n"); + fprintf(samtools_stdout, " -t, --target-regions Do stats in these regions only. Tab-delimited file chr,from,to, 1-based, inclusive.\n"); + fprintf(samtools_stdout, " -x, --sparse Suppress outputting IS rows where there are no insertions.\n"); + sam_global_opt_help(samtools_stdout, "-.--.@"); + fprintf(samtools_stdout, "\n"); } else { va_list ap; va_start(ap, format); - vfprintf(pysam_stderr, format, ap); + vfprintf(samtools_stderr, format, ap); va_end(ap); } exit(1); @@ -1483,13 +1483,13 @@ int init_stat_info_fname(stats_info_t* info, const char* bam_fname, const htsFor // .. bam samFile* sam; if ((sam = sam_open_format(bam_fname, "r", in_fmt)) == 0) { - error("Failed to open: %s\n", bam_fname); + print_error_errno("stats", "failed to open \"%s\"", bam_fname); return 1; } info->sam = sam; info->sam_header = sam_hdr_read(sam); if (info->sam_header == NULL) { - error("Failed to read header for '%s'\n", bam_fname); + print_error("stats", "failed to read header for \"%s\"", bam_fname); return 1; } return 0; @@ -1539,7 +1539,7 @@ static void init_stat_structs(stats_t* stats, stats_info_t* info, const char* gr stats->quals_2nd = calloc(stats->nquals*stats->nbases,sizeof(uint64_t)); stats->gc_1st = calloc(stats->ngc,sizeof(uint64_t)); stats->gc_2nd = calloc(stats->ngc,sizeof(uint64_t)); - stats->isize = init_isize_t(info->nisize); + stats->isize = init_isize_t(info->nisize ?info->nisize+1 :0); stats->gcd = calloc(stats->ngcd,sizeof(gc_depth_t)); stats->mpc_buf = info->fai ? calloc(stats->nquals*stats->nbases,sizeof(uint64_t)) : NULL; stats->acgtno_cycles = calloc(stats->nbases,sizeof(acgtno_count_t)); @@ -1598,7 +1598,7 @@ int main_stats(int argc, char *argv[]) static const struct option loptions[] = { - SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0), + SAM_OPT_GLOBAL_OPTIONS('-', 0, '-', '-', 0, '@'), {"help", no_argument, NULL, 'h'}, {"remove-dups", no_argument, NULL, 'd'}, {"sam", no_argument, NULL, 's'}, @@ -1620,7 +1620,7 @@ int main_stats(int argc, char *argv[]) }; int opt; - while ( (opt=getopt_long(argc,argv,"?hdsxr:c:l:i:t:m:q:f:F:I:1:S:P:",loptions,NULL))>0 ) + while ( (opt=getopt_long(argc,argv,"?hdsxr:c:l:i:t:m:q:f:F:I:1:S:P:@:",loptions,NULL))>0 ) { switch (opt) { @@ -1664,6 +1664,8 @@ int main_stats(int argc, char *argv[]) } if (init_stat_info_fname(info, bam_fname, &ga.in)) return 1; + if (ga.nthreads > 0) + hts_set_threads(info->sam, ga.nthreads); stats_t *all_stats = stats_init(); stats_t *curr_stats = NULL; @@ -1710,13 +1712,13 @@ int main_stats(int argc, char *argv[]) } if (ret < -1) { - fprintf(pysam_stderr, "Failure while decoding file\n"); + fprintf(samtools_stderr, "Failure while decoding file\n"); return 1; } } round_buffer_flush(all_stats, -1); - output_stats(pysam_stdout, all_stats, sparse); + output_stats(samtools_stdout, all_stats, sparse); if (info->split_tag) output_split_stats(split_hash, bam_fname, sparse); diff --git a/samtools/stats_isize.c.pysam.c b/samtools/stats_isize.c.pysam.c index 6ae908886..492780bd2 100644 --- a/samtools/stats_isize.c.pysam.c +++ b/samtools/stats_isize.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* stats_isize.c -- generalised insert size calculation for samtools stats. @@ -96,7 +96,7 @@ static void sparse_set_f(isize_data_t data, int at, isize_insert_t field, uint64 kh_value(h, it) = rec; a->max = max(at, a->max); } else { - fprintf(pysam_stderr, "%s\n", "Failed to allocate memory for isize_sparse_record_t"); + fprintf(samtools_stderr, "%s\n", "Failed to allocate memory for isize_sparse_record_t"); exit(11); } } else { diff --git a/samtools/test/merge/test_bam_translate.c.pysam.c b/samtools/test/merge/test_bam_translate.c.pysam.c index 193954d5b..21db13c45 100644 --- a/samtools/test/merge/test_bam_translate.c.pysam.c +++ b/samtools/test/merge/test_bam_translate.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* test/merge/test_bam_translate.c -- header merging test harness. @@ -35,40 +35,40 @@ DEALINGS IN THE SOFTWARE. */ #include void dump_read(bam1_t* b) { - fprintf(pysam_stdout, "->core.tid:(%d)\n", b->core.tid); - fprintf(pysam_stdout, "->core.pos:(%d)\n", b->core.pos); - fprintf(pysam_stdout, "->core.bin:(%d)\n", b->core.bin); - fprintf(pysam_stdout, "->core.qual:(%d)\n", b->core.qual); - fprintf(pysam_stdout, "->core.l_qname:(%d)\n", b->core.l_qname); - fprintf(pysam_stdout, "->core.flag:(%d)\n", b->core.flag); - fprintf(pysam_stdout, "->core.n_cigar:(%d)\n", b->core.n_cigar); - fprintf(pysam_stdout, "->core.l_qseq:(%d)\n", b->core.l_qseq); - fprintf(pysam_stdout, "->core.mtid:(%d)\n", b->core.mtid); - fprintf(pysam_stdout, "->core.mpos:(%d)\n", b->core.mpos); - fprintf(pysam_stdout, "->core.isize:(%d)\n", b->core.isize); + fprintf(samtools_stdout, "->core.tid:(%d)\n", b->core.tid); + fprintf(samtools_stdout, "->core.pos:(%d)\n", b->core.pos); + fprintf(samtools_stdout, "->core.bin:(%d)\n", b->core.bin); + fprintf(samtools_stdout, "->core.qual:(%d)\n", b->core.qual); + fprintf(samtools_stdout, "->core.l_qname:(%d)\n", b->core.l_qname); + fprintf(samtools_stdout, "->core.flag:(%d)\n", b->core.flag); + fprintf(samtools_stdout, "->core.n_cigar:(%d)\n", b->core.n_cigar); + fprintf(samtools_stdout, "->core.l_qseq:(%d)\n", b->core.l_qseq); + fprintf(samtools_stdout, "->core.mtid:(%d)\n", b->core.mtid); + fprintf(samtools_stdout, "->core.mpos:(%d)\n", b->core.mpos); + fprintf(samtools_stdout, "->core.isize:(%d)\n", b->core.isize); if (b->data) { - fprintf(pysam_stdout, "->data:"); + fprintf(samtools_stdout, "->data:"); int i; for (i = 0; i < b->l_data; ++i) { - fprintf(pysam_stdout, "%x ", b->data[i]); + fprintf(samtools_stdout, "%x ", b->data[i]); } - fprintf(pysam_stdout, "\n"); + fprintf(samtools_stdout, "\n"); } if (b->core.l_qname) { - fprintf(pysam_stdout, "qname: %s\n",bam_get_qname(b)); + fprintf(samtools_stdout, "qname: %s\n",bam_get_qname(b)); } if (b->core.l_qseq) { - fprintf(pysam_stdout, "qseq:"); + fprintf(samtools_stdout, "qseq:"); int i; for (i = 0; i < b->core.l_qseq; ++i) { - fprintf(pysam_stdout, "%c",seq_nt16_str[seq_nt16_table[bam_seqi(bam_get_seq(b),i)]]); + fprintf(samtools_stdout, "%c",seq_nt16_str[seq_nt16_table[bam_seqi(bam_get_seq(b),i)]]); } - fprintf(pysam_stdout, "\n"); - fprintf(pysam_stdout, "qual:"); + fprintf(samtools_stdout, "\n"); + fprintf(samtools_stdout, "qual:"); for (i = 0; i < b->core.l_qseq; ++i) { - fprintf(pysam_stdout, "%c",bam_get_qual(b)[i]); + fprintf(samtools_stdout, "%c",bam_get_qual(b)[i]); } - fprintf(pysam_stdout, "\n"); + fprintf(samtools_stdout, "\n"); } @@ -77,18 +77,18 @@ void dump_read(bam1_t* b) { uint8_t* aux = bam_get_aux(b); while (i < bam_get_l_aux(b)) { - fprintf(pysam_stdout, "%.2s:%c:",aux+i,*(aux+i+2)); + fprintf(samtools_stdout, "%.2s:%c:",aux+i,*(aux+i+2)); i += 2; switch (*(aux+i)) { case 'Z': - while (*(aux+1+i) != '\0') { putc(*(aux+1+i), pysam_stdout); ++i; } + while (*(aux+1+i) != '\0') { putc(*(aux+1+i), samtools_stdout); ++i; } break; } - putc('\n',pysam_stdout); + putc('\n',samtools_stdout); ++i;++i; } } - fprintf(pysam_stdout, "\n"); + fprintf(samtools_stdout, "\n"); } void trans_tbl_test_init(trans_tbl_t* tbl, int32_t n_targets) @@ -357,30 +357,30 @@ int samtools_test_bam_translate_main(int argc, char**argv) bam1_t* b; - // Setup pysam_stderr redirect + // Setup samtools_stderr redirect kstring_t res = { 0, 0, NULL }; - FILE* orig_pysam_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save pysam_stderr + FILE* orig_samtools_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save samtools_stderr char* tempfname = (optind < argc)? argv[optind] : "test_bam_translate.tmp"; FILE* check = NULL; // setup - if (verbose) fprintf(pysam_stdout, "BEGIN test 1\n"); // TID test + if (verbose) fprintf(samtools_stdout, "BEGIN test 1\n"); // TID test trans_tbl_t tbl1; setup_test_1(&b,&tbl1); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_read(b); } - if (verbose) fprintf(pysam_stdout, "RUN test 1\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 1\n"); // test - xfreopen(tempfname, "w", pysam_stderr); // Redirect pysam_stderr to pipe + xfreopen(tempfname, "w", samtools_stderr); // Redirect samtools_stderr to pipe bam_translate(b, &tbl1); - fclose(pysam_stderr); + fclose(samtools_stderr); - if (verbose) fprintf(pysam_stdout, "END RUN test 1\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 1\n"); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_read(b); } @@ -392,33 +392,33 @@ int samtools_test_bam_translate_main(int argc, char**argv) ++success; } else { ++failure; - if (verbose) fprintf(pysam_stdout, "FAIL test 1\n"); + if (verbose) fprintf(samtools_stdout, "FAIL test 1\n"); } fclose(check); // teardown bam_destroy1(b); trans_tbl_destroy(&tbl1); - if (verbose) fprintf(pysam_stdout, "END test 1\n"); + if (verbose) fprintf(samtools_stdout, "END test 1\n"); // setup - if (verbose) fprintf(pysam_stdout, "BEGIN test 2\n"); // RG exists and translate test + if (verbose) fprintf(samtools_stdout, "BEGIN test 2\n"); // RG exists and translate test trans_tbl_t tbl2; setup_test_2(&b,&tbl2); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_read(b); } - if (verbose) fprintf(pysam_stdout, "RUN test 2\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 2\n"); // test - xfreopen(tempfname, "w", pysam_stderr); // Redirect pysam_stderr to pipe + xfreopen(tempfname, "w", samtools_stderr); // Redirect samtools_stderr to pipe bam_translate(b, &tbl2); - fclose(pysam_stderr); + fclose(samtools_stderr); - if (verbose) fprintf(pysam_stdout, "END RUN test 2\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 2\n"); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_read(b); } @@ -430,33 +430,33 @@ int samtools_test_bam_translate_main(int argc, char**argv) ++success; } else { ++failure; - if (verbose) fprintf(pysam_stdout, "FAIL test 2\n"); + if (verbose) fprintf(samtools_stdout, "FAIL test 2\n"); } fclose(check); // teardown bam_destroy1(b); trans_tbl_destroy(&tbl2); - if (verbose) fprintf(pysam_stdout, "END test 2\n"); + if (verbose) fprintf(samtools_stdout, "END test 2\n"); - if (verbose) fprintf(pysam_stdout, "BEGIN test 3\n"); // PG exists and translate test + if (verbose) fprintf(samtools_stdout, "BEGIN test 3\n"); // PG exists and translate test // setup trans_tbl_t tbl3; setup_test_3(&b,&tbl3); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_read(b); } - if (verbose) fprintf(pysam_stdout, "RUN test 3\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 3\n"); // test - xfreopen(tempfname, "w", pysam_stderr); // Redirect pysam_stderr to pipe + xfreopen(tempfname, "w", samtools_stderr); // Redirect samtools_stderr to pipe bam_translate(b, &tbl3); - fclose(pysam_stderr); + fclose(samtools_stderr); - if (verbose) fprintf(pysam_stdout, "END RUN test 3\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 3\n"); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_read(b); } @@ -468,33 +468,33 @@ int samtools_test_bam_translate_main(int argc, char**argv) ++success; } else { ++failure; - if (verbose) fprintf(pysam_stdout, "FAIL test 3\n"); + if (verbose) fprintf(samtools_stdout, "FAIL test 3\n"); } fclose(check); // teardown bam_destroy1(b); trans_tbl_destroy(&tbl3); - if (verbose) fprintf(pysam_stdout, "END test 3\n"); + if (verbose) fprintf(samtools_stdout, "END test 3\n"); - if (verbose) fprintf(pysam_stdout, "BEGIN test 4\n"); // RG test non-existent + if (verbose) fprintf(samtools_stdout, "BEGIN test 4\n"); // RG test non-existent // setup trans_tbl_t tbl4; setup_test_4(&b,&tbl4); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_read(b); } - if (verbose) fprintf(pysam_stdout, "RUN test 4\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 4\n"); // test - xfreopen(tempfname, "w", pysam_stderr); // Redirect pysam_stderr to pipe + xfreopen(tempfname, "w", samtools_stderr); // Redirect samtools_stderr to pipe bam_translate(b, &tbl4); - fclose(pysam_stderr); + fclose(samtools_stderr); - if (verbose) fprintf(pysam_stdout, "END RUN test 4\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 4\n"); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_read(b); } // check result @@ -505,32 +505,32 @@ int samtools_test_bam_translate_main(int argc, char**argv) ++success; } else { ++failure; - if (verbose) fprintf(pysam_stdout, "FAIL test 4\n"); + if (verbose) fprintf(samtools_stdout, "FAIL test 4\n"); } fclose(check); // teardown bam_destroy1(b); trans_tbl_destroy(&tbl4); - if (verbose) fprintf(pysam_stdout, "END test 4\n"); + if (verbose) fprintf(samtools_stdout, "END test 4\n"); - if (verbose) fprintf(pysam_stdout, "BEGIN test 5\n"); // PG test non-existent + if (verbose) fprintf(samtools_stdout, "BEGIN test 5\n"); // PG test non-existent // setup trans_tbl_t tbl5; setup_test_5(&b,&tbl5); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_read(b); - fprintf(pysam_stdout, "RUN test 5\n"); + fprintf(samtools_stdout, "RUN test 5\n"); } // test - xfreopen(tempfname, "w", pysam_stderr); // Redirect pysam_stderr to pipe + xfreopen(tempfname, "w", samtools_stderr); // Redirect samtools_stderr to pipe bam_translate(b, &tbl5); - fclose(pysam_stderr); + fclose(samtools_stderr); - if (verbose) fprintf(pysam_stdout, "END RUN test 5\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 5\n"); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_read(b); } @@ -542,33 +542,33 @@ int samtools_test_bam_translate_main(int argc, char**argv) ++success; } else { ++failure; - if (verbose) fprintf(pysam_stdout, "FAIL test 5\n"); + if (verbose) fprintf(samtools_stdout, "FAIL test 5\n"); } fclose(check); // teardown bam_destroy1(b); trans_tbl_destroy(&tbl5); - if (verbose) fprintf(pysam_stdout, "END test 5\n"); + if (verbose) fprintf(samtools_stdout, "END test 5\n"); - if (verbose) fprintf(pysam_stdout, "BEGIN test 6\n"); // RG and PG exists and translate test + if (verbose) fprintf(samtools_stdout, "BEGIN test 6\n"); // RG and PG exists and translate test // setup trans_tbl_t tbl6; setup_test_6(&b,&tbl6); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_read(b); } - if (verbose) fprintf(pysam_stdout, "RUN test 6\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 6\n"); // test - xfreopen(tempfname, "w", pysam_stderr); // Redirect pysam_stderr to pipe + xfreopen(tempfname, "w", samtools_stderr); // Redirect samtools_stderr to pipe bam_translate(b, &tbl6); - fclose(pysam_stderr); + fclose(samtools_stderr); - if (verbose) fprintf(pysam_stdout, "END RUN test 6\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 6\n"); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_read(b); } @@ -580,21 +580,21 @@ int samtools_test_bam_translate_main(int argc, char**argv) ++success; } else { ++failure; - if (verbose) fprintf(pysam_stdout, "FAIL test 6\n"); + if (verbose) fprintf(samtools_stdout, "FAIL test 6\n"); } fclose(check); // teardown bam_destroy1(b); trans_tbl_destroy(&tbl6); - if (verbose) fprintf(pysam_stdout, "END test 6\n"); + if (verbose) fprintf(samtools_stdout, "END test 6\n"); // Cleanup free(res.s); remove(tempfname); if (failure > 0) - fprintf(orig_pysam_stderr, "%d failures %d successes\n", failure, success); - fclose(orig_pysam_stderr); + fprintf(orig_samtools_stderr, "%d failures %d successes\n", failure, success); + fclose(orig_samtools_stderr); return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/samtools/test/merge/test_rtrans_build.c.pysam.c b/samtools/test/merge/test_rtrans_build.c.pysam.c index 0ac136762..5ba47e7fc 100644 --- a/samtools/test/merge/test_rtrans_build.c.pysam.c +++ b/samtools/test/merge/test_rtrans_build.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* test/merge/test_rtrans_build.c -- header translation test harness. @@ -29,13 +29,13 @@ DEALINGS IN THE SOFTWARE. */ #include "../../bam_sort.c" void dump_rtrans(int* rtrans, int n, int n_targets) { - fprintf(pysam_stdout, "->n_targets:(%d)\n", n_targets); + fprintf(samtools_stdout, "->n_targets:(%d)\n", n_targets); int i, j; for (i = 0; i < n; ++i) { - fprintf(pysam_stderr, "%d",rtrans[i*n_targets+0]); + fprintf(samtools_stderr, "%d",rtrans[i*n_targets+0]); for (j = 1; j < n_targets; ++j) - fprintf(pysam_stderr, "\t%d",rtrans[i*n_targets+j]); - fprintf(pysam_stderr, "\n"); + fprintf(samtools_stderr, "\t%d",rtrans[i*n_targets+j]); + fprintf(samtools_stderr, "\n"); } } @@ -83,7 +83,7 @@ int samtools_test_rtrans_build_main(int argc, char**argv) const long GIMMICK_SEED = 0x1234330e; srand48(GIMMICK_SEED); - if (verbose) fprintf(pysam_stdout, "BEGIN test 1\n"); + if (verbose) fprintf(samtools_stdout, "BEGIN test 1\n"); // setup trans_tbl_t tbl_1[2]; int n_targets_1 = 3; @@ -94,29 +94,29 @@ int samtools_test_rtrans_build_main(int argc, char**argv) if (verbose > 1) { // dump_trans_tid } - if (verbose) fprintf(pysam_stdout, "RUN test 1\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 1\n"); rtrans_1 = rtrans_build(n_1, n_targets_1, &tbl_1[0]); - if (verbose) fprintf(pysam_stdout, "END RUN test 1\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 1\n"); if (verbose > 1) { - fprintf(pysam_stdout, "rtrans\n"); + fprintf(samtools_stdout, "rtrans\n"); dump_rtrans(rtrans_1, n_1, n_targets_1); } if (check_test_1(&tbl_1[0], rtrans_1)) { ++success; } else { ++failure; - if (verbose) fprintf(pysam_stdout, "FAIL test 1\n"); + if (verbose) fprintf(samtools_stdout, "FAIL test 1\n"); } // teardown trans_tbl_destroy(&tbl_1[0]); trans_tbl_destroy(&tbl_1[1]); free(rtrans_1); - if (verbose) fprintf(pysam_stdout, "END test 1\n"); + if (verbose) fprintf(samtools_stdout, "END test 1\n"); if (success == NUM_TESTS) { return 0; } else { - fprintf(pysam_stderr, "%d failures %d successes\n", failure, success); + fprintf(samtools_stderr, "%d failures %d successes\n", failure, success); return 1; } } diff --git a/samtools/test/merge/test_trans_tbl_init.c.pysam.c b/samtools/test/merge/test_trans_tbl_init.c.pysam.c index af8af4337..f3abf71ce 100644 --- a/samtools/test/merge/test_trans_tbl_init.c.pysam.c +++ b/samtools/test/merge/test_trans_tbl_init.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* test/merge/test_trans_tbl_init.c -- merge test harness. @@ -36,16 +36,16 @@ typedef struct refseq_info { } refseq_info_t; void dump_header(bam_hdr_t* hdr) { - fprintf(pysam_stdout, "->n_targets:(%d)\n", hdr->n_targets); + fprintf(samtools_stdout, "->n_targets:(%d)\n", hdr->n_targets); int i; for (i = 0; i < hdr->n_targets; ++i) { - fprintf(pysam_stdout, "->target_name[%d]:(%s)\n",i,hdr->target_name[i]); - fprintf(pysam_stdout, "->target_len[%d]:(%d)\n",i,hdr->target_len[i]); + fprintf(samtools_stdout, "->target_name[%d]:(%s)\n",i,hdr->target_name[i]); + fprintf(samtools_stdout, "->target_len[%d]:(%d)\n",i,hdr->target_len[i]); } - fprintf(pysam_stdout, "->text:("); - fwrite((void*)hdr->text, (size_t) hdr->l_text, 1, pysam_stdout); - fprintf(pysam_stdout, ")\n"); + fprintf(samtools_stdout, "->text:("); + fwrite((void*)hdr->text, (size_t) hdr->l_text, 1, samtools_stdout); + fprintf(samtools_stdout, ")\n"); } static int populate_merged_header(bam_hdr_t *hdr, merged_header_t *merged_hdr) { @@ -351,7 +351,7 @@ int samtools_test_trans_tbl_init_main(int argc, char**argv) bam_hdr_t* out; bam_hdr_t* translate; - if (verbose) fprintf(pysam_stdout, "BEGIN test 1\n"); + if (verbose) fprintf(samtools_stdout, "BEGIN test 1\n"); // setup trans_tbl_t tbl_1; merged_header_t *merged_hdr = init_merged_header(); @@ -359,36 +359,36 @@ int samtools_test_trans_tbl_init_main(int argc, char**argv) assert(translate); // test if (verbose > 1) { - fprintf(pysam_stdout, "translate\n"); + fprintf(samtools_stdout, "translate\n"); dump_header(translate); } - if (verbose) fprintf(pysam_stdout, "RUN test 1\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 1\n"); trans_tbl_init(merged_hdr, translate, &tbl_1, false, false, true, NULL); out = finish_merged_header(merged_hdr); free_merged_header(merged_hdr); - if (verbose) fprintf(pysam_stdout, "END RUN test 1\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 1\n"); if (verbose > 1) { - fprintf(pysam_stdout, "translate\n"); + fprintf(samtools_stdout, "translate\n"); dump_header(translate); - fprintf(pysam_stdout, "out\n"); + fprintf(samtools_stdout, "out\n"); dump_header(out); } if (check_test_1(translate, out, &tbl_1)) { - if (verbose) fprintf(pysam_stdout, "Test 1 : PASS\n"); + if (verbose) fprintf(samtools_stdout, "Test 1 : PASS\n"); ++success; } else { - if (verbose) fprintf(pysam_stdout, "Test 1 : FAIL\n"); - fprintf(pysam_stderr, "Test 1 : FAIL\n"); + if (verbose) fprintf(samtools_stdout, "Test 1 : FAIL\n"); + fprintf(samtools_stderr, "Test 1 : FAIL\n"); ++failure; } // teardown bam_hdr_destroy(translate); bam_hdr_destroy(out); trans_tbl_destroy(&tbl_1); - if (verbose) fprintf(pysam_stdout, "END test 1\n"); + if (verbose) fprintf(samtools_stdout, "END test 1\n"); // test - if (verbose) fprintf(pysam_stdout, "BEGIN test 2\n"); + if (verbose) fprintf(samtools_stdout, "BEGIN test 2\n"); // reinit trans_tbl_t tbl_2; @@ -396,108 +396,108 @@ int samtools_test_trans_tbl_init_main(int argc, char**argv) translate = setup_test_2(merged_hdr); assert(translate); if (verbose > 1) { - fprintf(pysam_stdout, "translate\n"); + fprintf(samtools_stdout, "translate\n"); dump_header(translate); } - if (verbose) fprintf(pysam_stdout, "RUN test 2\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 2\n"); trans_tbl_init(merged_hdr, translate, &tbl_2, false, false, true, NULL); out = finish_merged_header(merged_hdr); free_merged_header(merged_hdr); - if (verbose) fprintf(pysam_stdout, "END RUN test 2\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 2\n"); if (verbose > 1) { - fprintf(pysam_stdout, "translate\n"); + fprintf(samtools_stdout, "translate\n"); dump_header(translate); - fprintf(pysam_stdout, "out\n"); + fprintf(samtools_stdout, "out\n"); dump_header(out); } if (check_test_2(translate, out, &tbl_2)) { - if (verbose) fprintf(pysam_stdout, "Test 2 : PASS\n"); + if (verbose) fprintf(samtools_stdout, "Test 2 : PASS\n"); ++success; } else { - if (verbose) fprintf(pysam_stdout, "Test 2 : FAIL\n"); - fprintf(pysam_stderr, "Test 2 : FAIL\n"); + if (verbose) fprintf(samtools_stdout, "Test 2 : FAIL\n"); + fprintf(samtools_stderr, "Test 2 : FAIL\n"); ++failure; } // teardown bam_hdr_destroy(translate); bam_hdr_destroy(out); trans_tbl_destroy(&tbl_2); - if (verbose) fprintf(pysam_stdout, "END test 2\n"); + if (verbose) fprintf(samtools_stdout, "END test 2\n"); // test - if (verbose) fprintf(pysam_stdout, "BEGIN test 3\n"); + if (verbose) fprintf(samtools_stdout, "BEGIN test 3\n"); // reinit trans_tbl_t tbl_3; merged_hdr = init_merged_header(); translate = setup_test_3(merged_hdr); assert(translate); if (verbose > 1) { - fprintf(pysam_stdout, "translate\n"); + fprintf(samtools_stdout, "translate\n"); dump_header(translate); } - if (verbose) fprintf(pysam_stdout, "RUN test 3\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 3\n"); trans_tbl_init(merged_hdr, translate, &tbl_3, false, false, true, NULL); out = finish_merged_header(merged_hdr); free_merged_header(merged_hdr); - if (verbose) fprintf(pysam_stdout, "END RUN test 3\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 3\n"); if (verbose > 1) { - fprintf(pysam_stdout, "translate\n"); + fprintf(samtools_stdout, "translate\n"); dump_header(translate); - fprintf(pysam_stdout, "out\n"); + fprintf(samtools_stdout, "out\n"); dump_header(out); } if (check_test_3(translate, out, &tbl_3)) { - if (verbose) fprintf(pysam_stdout, "Test 3 : PASS\n"); + if (verbose) fprintf(samtools_stdout, "Test 3 : PASS\n"); ++success; } else { - if (verbose) fprintf(pysam_stdout, "Test 3 : FAIL\n"); - fprintf(pysam_stderr, "Test 3 : FAIL\n"); + if (verbose) fprintf(samtools_stdout, "Test 3 : FAIL\n"); + fprintf(samtools_stderr, "Test 3 : FAIL\n"); ++failure; } // teardown bam_hdr_destroy(translate); bam_hdr_destroy(out); trans_tbl_destroy(&tbl_3); - if (verbose) fprintf(pysam_stdout, "END test 3\n"); + if (verbose) fprintf(samtools_stdout, "END test 3\n"); // test - if (verbose) fprintf(pysam_stdout, "BEGIN test 4\n"); + if (verbose) fprintf(samtools_stdout, "BEGIN test 4\n"); // reinit trans_tbl_t tbl_4; merged_hdr = init_merged_header(); translate = setup_test_4(merged_hdr); assert(translate); if (verbose > 1) { - fprintf(pysam_stdout, "translate\n"); + fprintf(samtools_stdout, "translate\n"); dump_header(translate); } - if (verbose) fprintf(pysam_stdout, "RUN test 4\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 4\n"); trans_tbl_init(merged_hdr, translate, &tbl_4, false, false, true, NULL); out = finish_merged_header(merged_hdr); free_merged_header(merged_hdr); - if (verbose) fprintf(pysam_stdout, "END RUN test 4\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 4\n"); if (verbose > 1) { - fprintf(pysam_stdout, "translate\n"); + fprintf(samtools_stdout, "translate\n"); dump_header(translate); - fprintf(pysam_stdout, "out\n"); + fprintf(samtools_stdout, "out\n"); dump_header(out); } if (check_test_4(translate, out, &tbl_4)) { - if (verbose) fprintf(pysam_stdout, "Test 4 : PASS\n"); + if (verbose) fprintf(samtools_stdout, "Test 4 : PASS\n"); ++success; } else { - if (verbose) fprintf(pysam_stdout, "Test 4 : FAIL\n"); - fprintf(pysam_stderr, "Test 4 : FAIL\n"); + if (verbose) fprintf(samtools_stdout, "Test 4 : FAIL\n"); + fprintf(samtools_stderr, "Test 4 : FAIL\n"); ++failure; } // teardown bam_hdr_destroy(translate); bam_hdr_destroy(out); trans_tbl_destroy(&tbl_4); - if (verbose) fprintf(pysam_stdout, "END test 4\n"); + if (verbose) fprintf(samtools_stdout, "END test 4\n"); // test - if (verbose) fprintf(pysam_stdout, "BEGIN test 5\n"); + if (verbose) fprintf(samtools_stdout, "BEGIN test 5\n"); // reinit trans_tbl_t tbl_5; merged_hdr = init_merged_header(); @@ -505,74 +505,74 @@ int samtools_test_trans_tbl_init_main(int argc, char**argv) assert(translate); if (verbose > 1) { - fprintf(pysam_stdout, "translate\n"); + fprintf(samtools_stdout, "translate\n"); dump_header(translate); } - if (verbose) fprintf(pysam_stdout, "RUN test 5\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 5\n"); trans_tbl_init(merged_hdr, translate, &tbl_5, false, false, true, NULL); out = finish_merged_header(merged_hdr); free_merged_header(merged_hdr); - if (verbose) fprintf(pysam_stdout, "END RUN test 5\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 5\n"); if (verbose > 1) { - fprintf(pysam_stdout, "translate\n"); + fprintf(samtools_stdout, "translate\n"); dump_header(translate); - fprintf(pysam_stdout, "out\n"); + fprintf(samtools_stdout, "out\n"); dump_header(out); } if (check_test_5(translate, out, &tbl_5)) { - if (verbose) fprintf(pysam_stdout, "Test 5 : PASS\n"); + if (verbose) fprintf(samtools_stdout, "Test 5 : PASS\n"); ++success; } else { - if (verbose) fprintf(pysam_stdout, "Test 5 : FAIL\n"); - fprintf(pysam_stderr, "Test 5 : FAIL\n"); + if (verbose) fprintf(samtools_stdout, "Test 5 : FAIL\n"); + fprintf(samtools_stderr, "Test 5 : FAIL\n"); ++failure; } // teardown bam_hdr_destroy(translate); bam_hdr_destroy(out); trans_tbl_destroy(&tbl_5); - if (verbose) fprintf(pysam_stdout, "END test 5\n"); + if (verbose) fprintf(samtools_stdout, "END test 5\n"); // test - if (verbose) fprintf(pysam_stdout, "BEGIN test 6\n"); + if (verbose) fprintf(samtools_stdout, "BEGIN test 6\n"); // reinit trans_tbl_t tbl_6; merged_hdr = init_merged_header(); translate = setup_test_6(merged_hdr); assert(translate); if (verbose > 1) { - fprintf(pysam_stdout, "translate\n"); + fprintf(samtools_stdout, "translate\n"); dump_header(translate); } - if (verbose) fprintf(pysam_stdout, "RUN test 6\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 6\n"); trans_tbl_init(merged_hdr, translate, &tbl_6, false, false, true, "filename"); out = finish_merged_header(merged_hdr); free_merged_header(merged_hdr); - if (verbose) fprintf(pysam_stdout, "END RUN test 6\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 6\n"); if (verbose > 1) { - fprintf(pysam_stdout, "translate\n"); + fprintf(samtools_stdout, "translate\n"); dump_header(translate); - fprintf(pysam_stdout, "out\n"); + fprintf(samtools_stdout, "out\n"); dump_header(out); } if (check_test_6(translate, out, &tbl_6)) { - if (verbose) fprintf(pysam_stdout, "Test 6 : PASS\n"); + if (verbose) fprintf(samtools_stdout, "Test 6 : PASS\n"); ++success; } else { - if (verbose) fprintf(pysam_stdout, "Test 6 : FAIL\n"); - fprintf(pysam_stderr, "Test 6 : FAIL\n"); + if (verbose) fprintf(samtools_stdout, "Test 6 : FAIL\n"); + fprintf(samtools_stderr, "Test 6 : FAIL\n"); ++failure; } // teardown bam_hdr_destroy(translate); bam_hdr_destroy(out); trans_tbl_destroy(&tbl_6); - if (verbose) fprintf(pysam_stdout, "END test 6\n"); + if (verbose) fprintf(samtools_stdout, "END test 6\n"); if (success == NUM_TESTS) { return 0; } else { - fprintf(pysam_stderr, "%d failures %d successes\n", failure, success); + fprintf(samtools_stderr, "%d failures %d successes\n", failure, success); return 1; } } diff --git a/samtools/test/split/test_count_rg.c.pysam.c b/samtools/test/split/test_count_rg.c.pysam.c index 25131a84f..c6f7fefc1 100644 --- a/samtools/test/split/test_count_rg.c.pysam.c +++ b/samtools/test/split/test_count_rg.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* test/split/test_count_rg.c -- split test cases. @@ -57,7 +57,7 @@ int samtools_test_count_rg_main(int argc, char**argv) ++verbose; break; default: - fprintf(pysam_stdout, + fprintf(samtools_stdout, "usage: test_count_rg [-v]\n\n" " -v verbose output\n" ); @@ -66,32 +66,32 @@ int samtools_test_count_rg_main(int argc, char**argv) } - // Setup pysam_stderr redirect + // Setup samtools_stderr redirect kstring_t res = { 0, 0, NULL }; - FILE* orig_pysam_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save pysam_stderr + FILE* orig_samtools_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save samtools_stderr char* tempfname = (optind < argc)? argv[optind] : "test_count_rg.tmp"; FILE* check = NULL; // setup - if (verbose) fprintf(pysam_stdout, "BEGIN test 1\n"); // TID test + if (verbose) fprintf(samtools_stdout, "BEGIN test 1\n"); // TID test bam_hdr_t* hdr1; size_t count; char** output; setup_test_1(&hdr1); if (verbose > 1) { - fprintf(pysam_stdout, "hdr1\n"); + fprintf(samtools_stdout, "hdr1\n"); dump_hdr(hdr1); } - if (verbose) fprintf(pysam_stdout, "RUN test 1\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 1\n"); // test - xfreopen(tempfname, "w", pysam_stderr); // Redirect pysam_stderr to pipe + xfreopen(tempfname, "w", samtools_stderr); // Redirect samtools_stderr to pipe bool result_1 = count_RG(hdr1, &count, &output); - fclose(pysam_stderr); + fclose(samtools_stderr); - if (verbose) fprintf(pysam_stdout, "END RUN test 1\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 1\n"); if (verbose > 1) { - fprintf(pysam_stdout, "b\n"); + fprintf(samtools_stdout, "b\n"); dump_hdr(hdr1); } @@ -103,7 +103,7 @@ int samtools_test_count_rg_main(int argc, char**argv) ++success; } else { ++failure; - if (verbose) fprintf(pysam_stdout, "FAIL test 1\n"); + if (verbose) fprintf(samtools_stdout, "FAIL test 1\n"); } fclose(check); @@ -114,14 +114,14 @@ int samtools_test_count_rg_main(int argc, char**argv) } free(output); bam_hdr_destroy(hdr1); - if (verbose) fprintf(pysam_stdout, "END test 1\n"); + if (verbose) fprintf(samtools_stdout, "END test 1\n"); // Cleanup free(res.s); remove(tempfname); if (failure > 0) - fprintf(orig_pysam_stderr, "%d failures %d successes\n", failure, success); - fclose(orig_pysam_stderr); + fprintf(orig_samtools_stderr, "%d failures %d successes\n", failure, success); + fclose(orig_samtools_stderr); return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/samtools/test/split/test_expand_format_string.c.pysam.c b/samtools/test/split/test_expand_format_string.c.pysam.c index fe9a426c9..1583818f1 100644 --- a/samtools/test/split/test_expand_format_string.c.pysam.c +++ b/samtools/test/split/test_expand_format_string.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* test/split/test_expand_format_string.c -- split format string test cases. @@ -57,7 +57,7 @@ int samtools_test_expand_format_string_main(int argc, char**argv) ++verbose; break; default: - fprintf(pysam_stdout, + fprintf(samtools_stdout, "usage: test_expand_format_string [-v]\n\n" " -v verbose output\n" ); @@ -66,34 +66,34 @@ int samtools_test_expand_format_string_main(int argc, char**argv) } - // Setup pysam_stderr redirect + // Setup samtools_stderr redirect kstring_t res = { 0, 0, NULL }; - FILE* orig_pysam_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save pysam_stderr + FILE* orig_samtools_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save samtools_stderr char* tempfname = (optind < argc)? argv[optind] : "test_expand_format_string.tmp"; FILE* check = NULL; // setup - if (verbose) fprintf(pysam_stdout, "BEGIN test 1\n"); // default format string test + if (verbose) fprintf(samtools_stdout, "BEGIN test 1\n"); // default format string test const char* format_string_1 = "%*_%#.bam"; const char* basename_1 = "basename"; const char* rg_id_1 = "1#2.3"; const int rg_idx_1 = 4; if (verbose > 1) { - fprintf(pysam_stdout, "format_string:%s\n" + fprintf(samtools_stdout, "format_string:%s\n" "basename:%s\n" "rg_id:%s\n" "rg_idx:%d\n", format_string_1, basename_1, rg_id_1, rg_idx_1); } - if (verbose) fprintf(pysam_stdout, "RUN test 1\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 1\n"); // test - xfreopen(tempfname, "w", pysam_stderr); // Redirect pysam_stderr to pipe + xfreopen(tempfname, "w", samtools_stderr); // Redirect samtools_stderr to pipe char* output_1 = expand_format_string(format_string_1, basename_1, rg_id_1, rg_idx_1, NULL); - fclose(pysam_stderr); + fclose(samtools_stderr); - if (verbose) fprintf(pysam_stdout, "END RUN test 1\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 1\n"); if (verbose > 1) { - fprintf(pysam_stdout, "format_string:%s\n" + fprintf(samtools_stdout, "format_string:%s\n" "basename:%s\n" "rg_id:%s\n" "rg_idx:%d\n", format_string_1, basename_1, rg_id_1, rg_idx_1); @@ -108,20 +108,20 @@ int samtools_test_expand_format_string_main(int argc, char**argv) ++success; } else { ++failure; - if (verbose) fprintf(pysam_stdout, "FAIL test 1\n"); + if (verbose) fprintf(samtools_stdout, "FAIL test 1\n"); } fclose(check); // teardown free(output_1); - if (verbose) fprintf(pysam_stdout, "END test 1\n"); + if (verbose) fprintf(samtools_stdout, "END test 1\n"); // Cleanup test harness free(res.s); remove(tempfname); if (failure > 0) - fprintf(orig_pysam_stderr, "%d failures %d successes\n", failure, success); - fclose(orig_pysam_stderr); + fprintf(orig_samtools_stderr, "%d failures %d successes\n", failure, success); + fclose(orig_samtools_stderr); return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/samtools/test/split/test_filter_header_rg.c b/samtools/test/split/test_filter_header_rg.c index d9505d67e..3792ab546 100644 --- a/samtools/test/split/test_filter_header_rg.c +++ b/samtools/test/split/test_filter_header_rg.c @@ -40,9 +40,11 @@ void setup_test_1(bam_hdr_t** hdr_in) } bool check_test_1(const bam_hdr_t* hdr) { - const char *test1_res = + char test1_res[200]; + snprintf(test1_res, 199, "@HD\tVN:1.4\n" - "@SQ\tSN:blah\n"; + "@SQ\tSN:blah\n" + "@PG\tID:samtools\tPN:samtools\tVN:%s\tCL:test_filter_header_rg foo bar baz\n", samtools_version()); if (strcmp(hdr->text, test1_res)) { return false; @@ -62,10 +64,12 @@ void setup_test_2(bam_hdr_t** hdr_in) } bool check_test_2(const bam_hdr_t* hdr) { - const char *test2_res = + char test2_res[200]; + snprintf(test2_res, 199, "@HD\tVN:1.4\n" "@SQ\tSN:blah\n" - "@RG\tID:fish\n"; + "@RG\tID:fish\n" + "@PG\tID:samtools\tPN:samtools\tVN:%s\tCL:test_filter_header_rg foo bar baz\n", samtools_version()); if (strcmp(hdr->text, test2_res)) { return false; @@ -73,7 +77,7 @@ bool check_test_2(const bam_hdr_t* hdr) { return true; } -int main(int argc, char**argv) +int main(int argc, char *argv[]) { // test state const int NUM_TESTS = 2; @@ -82,6 +86,8 @@ int main(int argc, char**argv) int failure = 0; int getopt_char; + char *test_argv[] = { "test_filter_header_rg", "foo\tbar", "baz" }; + char *arg_list = stringify_argv(3, test_argv); while ((getopt_char = getopt(argc, argv, "v")) != -1) { switch (getopt_char) { case 'v': @@ -108,7 +114,7 @@ int main(int argc, char**argv) bam_hdr_t* hdr1; const char* id_to_keep_1 = "1#2.3"; setup_test_1(&hdr1); - if (verbose > 1) { + if (verbose > 0) { printf("hdr1\n"); dump_hdr(hdr1); } @@ -116,11 +122,11 @@ int main(int argc, char**argv) // test xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe - bool result_1 = filter_header_rg(hdr1, id_to_keep_1); + bool result_1 = filter_header_rg(hdr1, id_to_keep_1, arg_list); fclose(stderr); if (verbose) printf("END RUN test 1\n"); - if (verbose > 1) { + if (verbose > 0) { printf("hdr1\n"); dump_hdr(hdr1); } @@ -147,7 +153,7 @@ int main(int argc, char**argv) bam_hdr_t* hdr2; const char* id_to_keep_2 = "fish"; setup_test_2(&hdr2); - if (verbose > 1) { + if (verbose > 0) { printf("hdr2\n"); dump_hdr(hdr2); } @@ -155,11 +161,11 @@ int main(int argc, char**argv) // test xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe - bool result_2 = filter_header_rg(hdr2, id_to_keep_2); + bool result_2 = filter_header_rg(hdr2, id_to_keep_2, arg_list); fclose(stderr); if (verbose) printf("END RUN test 2\n"); - if (verbose > 1) { + if (verbose > 0) { printf("hdr2\n"); dump_hdr(hdr2); } @@ -185,6 +191,7 @@ int main(int argc, char**argv) // Cleanup free(res.s); + free(arg_list); remove(tempfname); if (failure > 0) fprintf(orig_stderr, "%d failures %d successes\n", failure, success); diff --git a/samtools/test/split/test_filter_header_rg.c.pysam.c b/samtools/test/split/test_filter_header_rg.c.pysam.c index 97b357307..54227fce4 100644 --- a/samtools/test/split/test_filter_header_rg.c.pysam.c +++ b/samtools/test/split/test_filter_header_rg.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* test/split/test_filter_header_rg.c -- split test cases. @@ -42,9 +42,11 @@ void setup_test_1(bam_hdr_t** hdr_in) } bool check_test_1(const bam_hdr_t* hdr) { - const char *test1_res = + char test1_res[200]; + snprintf(test1_res, 199, "@HD\tVN:1.4\n" - "@SQ\tSN:blah\n"; + "@SQ\tSN:blah\n" + "@PG\tID:samtools\tPN:samtools\tVN:%s\tCL:test_filter_header_rg foo bar baz\n", samtools_version()); if (strcmp(hdr->text, test1_res)) { return false; @@ -64,10 +66,12 @@ void setup_test_2(bam_hdr_t** hdr_in) } bool check_test_2(const bam_hdr_t* hdr) { - const char *test2_res = + char test2_res[200]; + snprintf(test2_res, 199, "@HD\tVN:1.4\n" "@SQ\tSN:blah\n" - "@RG\tID:fish\n"; + "@RG\tID:fish\n" + "@PG\tID:samtools\tPN:samtools\tVN:%s\tCL:test_filter_header_rg foo bar baz\n", samtools_version()); if (strcmp(hdr->text, test2_res)) { return false; @@ -75,7 +79,7 @@ bool check_test_2(const bam_hdr_t* hdr) { return true; } -int samtools_test_filter_header_rg_main(int argc, char**argv) +int samtools_test_filter_header_rg_main(int argc, char *argv[]) { // test state const int NUM_TESTS = 2; @@ -84,13 +88,15 @@ int samtools_test_filter_header_rg_main(int argc, char**argv) int failure = 0; int getopt_char; + char *test_argv[] = { "test_filter_header_rg", "foo\tbar", "baz" }; + char *arg_list = stringify_argv(3, test_argv); while ((getopt_char = getopt(argc, argv, "v")) != -1) { switch (getopt_char) { case 'v': ++verbose; break; default: - fprintf(pysam_stdout, + fprintf(samtools_stdout, "usage: test_filter_header_rg [-v]\n\n" " -v verbose output\n" ); @@ -99,31 +105,31 @@ int samtools_test_filter_header_rg_main(int argc, char**argv) } - // Setup pysam_stderr redirect + // Setup samtools_stderr redirect kstring_t res = { 0, 0, NULL }; - FILE* orig_pysam_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save pysam_stderr + FILE* orig_samtools_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save samtools_stderr char* tempfname = (optind < argc)? argv[optind] : "test_count_rg.tmp"; FILE* check = NULL; // setup - if (verbose) fprintf(pysam_stdout, "BEGIN test 1\n"); // test eliminating a tag that isn't there + if (verbose) fprintf(samtools_stdout, "BEGIN test 1\n"); // test eliminating a tag that isn't there bam_hdr_t* hdr1; const char* id_to_keep_1 = "1#2.3"; setup_test_1(&hdr1); - if (verbose > 1) { - fprintf(pysam_stdout, "hdr1\n"); + if (verbose > 0) { + fprintf(samtools_stdout, "hdr1\n"); dump_hdr(hdr1); } - if (verbose) fprintf(pysam_stdout, "RUN test 1\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 1\n"); // test - xfreopen(tempfname, "w", pysam_stderr); // Redirect pysam_stderr to pipe - bool result_1 = filter_header_rg(hdr1, id_to_keep_1); - fclose(pysam_stderr); + xfreopen(tempfname, "w", samtools_stderr); // Redirect samtools_stderr to pipe + bool result_1 = filter_header_rg(hdr1, id_to_keep_1, arg_list); + fclose(samtools_stderr); - if (verbose) fprintf(pysam_stdout, "END RUN test 1\n"); - if (verbose > 1) { - fprintf(pysam_stdout, "hdr1\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 1\n"); + if (verbose > 0) { + fprintf(samtools_stdout, "hdr1\n"); dump_hdr(hdr1); } @@ -137,32 +143,32 @@ int samtools_test_filter_header_rg_main(int argc, char**argv) ++success; } else { ++failure; - if (verbose) fprintf(pysam_stdout, "FAIL test 1\n"); + if (verbose) fprintf(samtools_stdout, "FAIL test 1\n"); } fclose(check); // teardown bam_hdr_destroy(hdr1); - if (verbose) fprintf(pysam_stdout, "END test 1\n"); + if (verbose) fprintf(samtools_stdout, "END test 1\n"); - if (verbose) fprintf(pysam_stdout, "BEGIN test 2\n"); // test eliminating a tag that is there + if (verbose) fprintf(samtools_stdout, "BEGIN test 2\n"); // test eliminating a tag that is there bam_hdr_t* hdr2; const char* id_to_keep_2 = "fish"; setup_test_2(&hdr2); - if (verbose > 1) { - fprintf(pysam_stdout, "hdr2\n"); + if (verbose > 0) { + fprintf(samtools_stdout, "hdr2\n"); dump_hdr(hdr2); } - if (verbose) fprintf(pysam_stdout, "RUN test 2\n"); + if (verbose) fprintf(samtools_stdout, "RUN test 2\n"); // test - xfreopen(tempfname, "w", pysam_stderr); // Redirect pysam_stderr to pipe - bool result_2 = filter_header_rg(hdr2, id_to_keep_2); - fclose(pysam_stderr); + xfreopen(tempfname, "w", samtools_stderr); // Redirect samtools_stderr to pipe + bool result_2 = filter_header_rg(hdr2, id_to_keep_2, arg_list); + fclose(samtools_stderr); - if (verbose) fprintf(pysam_stdout, "END RUN test 2\n"); - if (verbose > 1) { - fprintf(pysam_stdout, "hdr2\n"); + if (verbose) fprintf(samtools_stdout, "END RUN test 2\n"); + if (verbose > 0) { + fprintf(samtools_stdout, "hdr2\n"); dump_hdr(hdr2); } @@ -176,21 +182,22 @@ int samtools_test_filter_header_rg_main(int argc, char**argv) ++success; } else { ++failure; - if (verbose) fprintf(pysam_stdout, "FAIL test 2\n"); + if (verbose) fprintf(samtools_stdout, "FAIL test 2\n"); } fclose(check); // teardown bam_hdr_destroy(hdr2); - if (verbose) fprintf(pysam_stdout, "END test 2\n"); + if (verbose) fprintf(samtools_stdout, "END test 2\n"); // Cleanup free(res.s); + free(arg_list); remove(tempfname); if (failure > 0) - fprintf(orig_pysam_stderr, "%d failures %d successes\n", failure, success); - fclose(orig_pysam_stderr); + fprintf(orig_samtools_stderr, "%d failures %d successes\n", failure, success); + fclose(orig_samtools_stderr); return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/samtools/test/split/test_parse_args.c.pysam.c b/samtools/test/split/test_parse_args.c.pysam.c index 2c3e749e1..01d9bcb1b 100644 --- a/samtools/test/split/test_parse_args.c.pysam.c +++ b/samtools/test/split/test_parse_args.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* test/split/test_parse_args.c -- split test cases. @@ -82,7 +82,7 @@ int samtools_test_parse_args_main(int argc, char**argv) ++verbose; break; default: - fprintf(pysam_stdout, + fprintf(samtools_stdout, "usage: test_parse_args [-v]\n\n" " -v verbose output\n" ); @@ -90,58 +90,58 @@ int samtools_test_parse_args_main(int argc, char**argv) } } - // Setup pysam_stdout and pysam_stderr redirect - kstring_t res_pysam_stdout = { 0, 0, NULL }; - kstring_t res_pysam_stderr = { 0, 0, NULL }; - FILE* orig_pysam_stdout = fdopen(dup(STDOUT_FILENO), "a"); // Save pysam_stderr - FILE* orig_pysam_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save pysam_stderr - char* tempfname_pysam_stdout = (optind < argc)? argv[optind] : "test_parse_args.tmp.o"; - char* tempfname_pysam_stderr = (optind < argc)? argv[optind] : "test_parse_args.tmp.e"; - FILE* check_pysam_stdout = NULL; - FILE* check_pysam_stderr = NULL; + // Setup samtools_stdout and samtools_stderr redirect + kstring_t res_samtools_stdout = { 0, 0, NULL }; + kstring_t res_samtools_stderr = { 0, 0, NULL }; + FILE* orig_samtools_stdout = fdopen(dup(STDOUT_FILENO), "a"); // Save samtools_stderr + FILE* orig_samtools_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save samtools_stderr + char* tempfname_samtools_stdout = (optind < argc)? argv[optind] : "test_parse_args.tmp.o"; + char* tempfname_samtools_stderr = (optind < argc)? argv[optind] : "test_parse_args.tmp.e"; + FILE* check_samtools_stdout = NULL; + FILE* check_samtools_stderr = NULL; // Cleanup getopt optind = 1; // setup - if (verbose) fprintf(orig_pysam_stdout,"BEGIN test 1\n"); // test eliminating a tag that isn't there + if (verbose) fprintf(orig_samtools_stdout,"BEGIN test 1\n"); // test eliminating a tag that isn't there int argc_1; char** argv_1; setup_test_1(&argc_1, &argv_1); if (verbose > 1) { - fprintf(orig_pysam_stdout, "argc: %d\n", argc_1); + fprintf(orig_samtools_stdout, "argc: %d\n", argc_1); } - if (verbose) fprintf(orig_pysam_stdout,"RUN test 1\n"); + if (verbose) fprintf(orig_samtools_stdout,"RUN test 1\n"); // test - xfreopen(tempfname_pysam_stdout, "w", pysam_stdout); // Redirect pysam_stdout to pipe - xfreopen(tempfname_pysam_stderr, "w", pysam_stderr); // Redirect pysam_stderr to pipe + xfreopen(tempfname_samtools_stdout, "w", samtools_stdout); // Redirect samtools_stdout to pipe + xfreopen(tempfname_samtools_stderr, "w", samtools_stderr); // Redirect samtools_stderr to pipe parsed_opts_t* result_1 = parse_args(argc_1, argv_1); - fclose(pysam_stdout); - fclose(pysam_stderr); + fclose(samtools_stdout); + fclose(samtools_stderr); - if (verbose) fprintf(orig_pysam_stdout, "END RUN test 1\n"); + if (verbose) fprintf(orig_samtools_stdout, "END RUN test 1\n"); if (verbose > 1) { - fprintf(orig_pysam_stdout, "argc: %d\n", argc_1); + fprintf(orig_samtools_stdout, "argc: %d\n", argc_1); } // check result - res_pysam_stdout.l = res_pysam_stderr.l = 0; - check_pysam_stdout = fopen(tempfname_pysam_stdout, "r"); - check_pysam_stderr = fopen(tempfname_pysam_stderr, "r"); + res_samtools_stdout.l = res_samtools_stderr.l = 0; + check_samtools_stdout = fopen(tempfname_samtools_stdout, "r"); + check_samtools_stderr = fopen(tempfname_samtools_stderr, "r"); if ( !result_1 - && kgetline(&res_pysam_stdout, (kgets_func *)fgets, check_pysam_stdout) >= 0 - && !feof(check_pysam_stdout) - && res_pysam_stdout.l > 0 - && kgetline(&res_pysam_stderr, (kgets_func *)fgets, check_pysam_stderr) < 0 - && (feof(check_pysam_stderr) || res_pysam_stderr.l == 0)) { + && kgetline(&res_samtools_stdout, (kgets_func *)fgets, check_samtools_stdout) >= 0 + && !feof(check_samtools_stdout) + && res_samtools_stdout.l > 0 + && kgetline(&res_samtools_stderr, (kgets_func *)fgets, check_samtools_stderr) < 0 + && (feof(check_samtools_stderr) || res_samtools_stderr.l == 0)) { ++success; } else { ++failure; - if (verbose) fprintf(orig_pysam_stdout, "FAIL test 1\n"); + if (verbose) fprintf(orig_samtools_stdout, "FAIL test 1\n"); } - fclose(check_pysam_stderr); - fclose(check_pysam_stdout); + fclose(check_samtools_stderr); + fclose(check_samtools_stdout); // teardown cleanup_opts(result_1); @@ -150,49 +150,49 @@ int samtools_test_parse_args_main(int argc, char**argv) free(argv_1[i]); } free(argv_1); - if (verbose) fprintf(orig_pysam_stdout, "END test 1\n"); + if (verbose) fprintf(orig_samtools_stdout, "END test 1\n"); // Cleanup getopt optind = 1; - if (verbose) fprintf(orig_pysam_stdout, "BEGIN test 2\n"); // test eliminating a tag that is there + if (verbose) fprintf(orig_samtools_stdout, "BEGIN test 2\n"); // test eliminating a tag that is there int argc_2; char** argv_2; setup_test_2(&argc_2, &argv_2); if (verbose > 1) { - fprintf(orig_pysam_stdout, "argc: %d\n", argc_2); + fprintf(orig_samtools_stdout, "argc: %d\n", argc_2); } - if (verbose) fprintf(orig_pysam_stdout, "RUN test 2\n"); + if (verbose) fprintf(orig_samtools_stdout, "RUN test 2\n"); // test - xfreopen(tempfname_pysam_stdout, "w", pysam_stdout); // Redirect pysam_stdout to pipe - xfreopen(tempfname_pysam_stderr, "w", pysam_stderr); // Redirect pysam_stderr to pipe + xfreopen(tempfname_samtools_stdout, "w", samtools_stdout); // Redirect samtools_stdout to pipe + xfreopen(tempfname_samtools_stderr, "w", samtools_stderr); // Redirect samtools_stderr to pipe parsed_opts_t* result_2 = parse_args(argc_2, argv_2); - fclose(pysam_stdout); - fclose(pysam_stderr); + fclose(samtools_stdout); + fclose(samtools_stderr); - if (verbose) fprintf(orig_pysam_stdout, "END RUN test 2\n"); + if (verbose) fprintf(orig_samtools_stdout, "END RUN test 2\n"); if (verbose > 1) { - fprintf(orig_pysam_stdout, "argc: %d\n", argc_2); + fprintf(orig_samtools_stdout, "argc: %d\n", argc_2); } // check result - res_pysam_stdout.l = res_pysam_stderr.l = 0; - check_pysam_stdout = fopen(tempfname_pysam_stdout, "r"); - check_pysam_stderr = fopen(tempfname_pysam_stderr, "r"); + res_samtools_stdout.l = res_samtools_stderr.l = 0; + check_samtools_stdout = fopen(tempfname_samtools_stdout, "r"); + check_samtools_stderr = fopen(tempfname_samtools_stderr, "r"); if ( result_2 && check_test_2(result_2) - && kgetline(&res_pysam_stdout, (kgets_func *)fgets, check_pysam_stdout) < 0 - && (feof(check_pysam_stdout) || res_pysam_stdout.l == 0) - && kgetline(&res_pysam_stderr, (kgets_func *)fgets, check_pysam_stderr) < 0 - && (feof(check_pysam_stderr) || res_pysam_stderr.l == 0)) { + && kgetline(&res_samtools_stdout, (kgets_func *)fgets, check_samtools_stdout) < 0 + && (feof(check_samtools_stdout) || res_samtools_stdout.l == 0) + && kgetline(&res_samtools_stderr, (kgets_func *)fgets, check_samtools_stderr) < 0 + && (feof(check_samtools_stderr) || res_samtools_stderr.l == 0)) { ++success; } else { ++failure; - if (verbose) fprintf(orig_pysam_stdout, "FAIL test 2\n"); + if (verbose) fprintf(orig_samtools_stdout, "FAIL test 2\n"); } - fclose(check_pysam_stdout); - fclose(check_pysam_stderr); + fclose(check_samtools_stdout); + fclose(check_samtools_stderr); // teardown cleanup_opts(result_2); @@ -202,18 +202,18 @@ int samtools_test_parse_args_main(int argc, char**argv) } free(argv_2); - if (verbose) fprintf(orig_pysam_stdout, "END test 2\n"); + if (verbose) fprintf(orig_samtools_stdout, "END test 2\n"); // Cleanup - free(res_pysam_stdout.s); - free(res_pysam_stderr.s); - remove(tempfname_pysam_stdout); - remove(tempfname_pysam_stderr); - fclose(orig_pysam_stdout); + free(res_samtools_stdout.s); + free(res_samtools_stderr.s); + remove(tempfname_samtools_stdout); + remove(tempfname_samtools_stderr); + fclose(orig_samtools_stdout); if (failure > 0) - fprintf(orig_pysam_stderr, "%d failures %d successes\n", failure, success); - fclose(orig_pysam_stderr); + fprintf(orig_samtools_stderr, "%d failures %d successes\n", failure, success); + fclose(orig_samtools_stderr); return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/samtools/test/test.c b/samtools/test/test.c index 7ab38afbe..0b4d58511 100644 --- a/samtools/test/test.c +++ b/samtools/test/test.c @@ -1,6 +1,6 @@ /* test/test.c -- test harness utility routines. - Copyright (C) 2014 Genome Research Ltd. + Copyright (C) 2014, 2016 Genome Research Ltd. Author: Martin O. Pollard diff --git a/samtools/test/test.c.pysam.c b/samtools/test/test.c.pysam.c index a8295b561..df87fbbd8 100644 --- a/samtools/test/test.c.pysam.c +++ b/samtools/test/test.c.pysam.c @@ -1,8 +1,8 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* test/test.c -- test harness utility routines. - Copyright (C) 2014 Genome Research Ltd. + Copyright (C) 2014, 2016 Genome Research Ltd. Author: Martin O. Pollard @@ -37,7 +37,7 @@ DEALINGS IN THE SOFTWARE. */ void xfreopen(const char *path, const char *mode, FILE *stream) { if (freopen(path, mode, stream) == NULL) { - fprintf(pysam_stderr, __FILE__": error reopening %s: %s\n", + fprintf(samtools_stderr, __FILE__": error reopening %s: %s\n", path, strerror(errno)); exit(2); } @@ -45,13 +45,13 @@ void xfreopen(const char *path, const char *mode, FILE *stream) void dump_hdr(const bam_hdr_t* hdr) { - fprintf(pysam_stdout, "n_targets: %d\n", hdr->n_targets); - fprintf(pysam_stdout, "ignore_sam_err: %d\n", hdr->ignore_sam_err); - fprintf(pysam_stdout, "l_text: %u\n", hdr->l_text); - fprintf(pysam_stdout, "idx\ttarget_len\ttarget_name:\n"); + fprintf(samtools_stdout, "n_targets: %d\n", hdr->n_targets); + fprintf(samtools_stdout, "ignore_sam_err: %d\n", hdr->ignore_sam_err); + fprintf(samtools_stdout, "l_text: %u\n", hdr->l_text); + fprintf(samtools_stdout, "idx\ttarget_len\ttarget_name:\n"); int32_t target; for (target = 0; target < hdr->n_targets; ++target) { - fprintf(pysam_stdout, "%d\t%u\t\"%s\"\n", target, hdr->target_len[target], hdr->target_name[target]); + fprintf(samtools_stdout, "%d\t%u\t\"%s\"\n", target, hdr->target_len[target], hdr->target_name[target]); } - fprintf(pysam_stdout, "text: \"%s\"\n", hdr->text); + fprintf(samtools_stdout, "text: \"%s\"\n", hdr->text); } diff --git a/samtools/test/tview/test_get_rg_sample.c.pysam.c b/samtools/test/tview/test_get_rg_sample.c.pysam.c index 8c441f943..02568763c 100644 --- a/samtools/test/tview/test_get_rg_sample.c.pysam.c +++ b/samtools/test/tview/test_get_rg_sample.c.pysam.c @@ -1,4 +1,4 @@ -#include "pysam.h" +#include "samtools.pysam.h" /* test/tview/test_get_rg_sample.c -- tview test cases. @@ -79,7 +79,7 @@ int samtools_test_get_rg_sample_main(int argc, char** argv) if (success == NUM_TESTS) { return 0; } else { - fprintf(pysam_stderr, "%d failures %d successes\n", failure, success); + fprintf(samtools_stderr, "%d failures %d successes\n", failure, success); return 1; } } diff --git a/samtools/tmp_file.c b/samtools/tmp_file.c new file mode 100644 index 000000000..85d2822c8 --- /dev/null +++ b/samtools/tmp_file.c @@ -0,0 +1,507 @@ +/* + tmp_file.c - write to and read from a temporary binary file + for fast storage plus added compression. + + Copyright (C) 2017 Genome Research Ltd. + + Author: Andrew Whitwham + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#include +#endif /* _WIN32 */ + +#include "tmp_file.h" +#include "htslib/sam.h" + + +static void tmp_print_error(tmp_file_t *tmp, const char *fmt, ...) { + va_list argp; + + if (tmp->verbose) { + va_start(argp, fmt); + vfprintf(stderr, fmt, argp); + va_end(argp); + } +} + + +static int tmp_file_init(tmp_file_t *tmp, int verbose) { + tmp->stream = LZ4_createStream(); + tmp->data_size = 0; + tmp->group_size = TMP_SAM_GROUP_SIZE; + tmp->input_size = 0; + tmp->read_size = 0; + tmp->output_size = 0; + tmp->entry_number = 0; + tmp->offset = 0; + tmp->max_data_size = TMP_SAM_MAX_DATA + sizeof(bam1_t); // arbitrary but growable + tmp->ring_buffer_size = TMP_SAM_RING_SIZE; // arbitrary (min 64K) but growable + tmp->comp_buffer_size = LZ4_COMPRESSBOUND(tmp->max_data_size * tmp->group_size); + tmp->data = NULL; + tmp->ring_buffer = malloc(sizeof(uint8_t) * tmp->ring_buffer_size); + tmp->ring_index = tmp->ring_buffer; + tmp->comp_buffer = malloc(tmp->comp_buffer_size); + tmp->verbose = verbose; + tmp->dict = NULL; + tmp->groups_written = 0; + + if (!tmp->ring_buffer || !tmp->comp_buffer || !tmp->stream) { + tmp_print_error(tmp, "[tmp_file] Error: unable to allocate compression buffers.\n"); + return TMP_SAM_MEM_ERROR; + } + + return TMP_SAM_OK; +} + + +/* + * Opens the temp file and initialises memory. + * Verbose mode prints out error messages to stderr. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_open_write(tmp_file_t *tmp, char *tmp_name, int verbose) { + int ret; + unsigned int count = 1; + const unsigned int max_count = 100000; // more tries than this then something else is wrong + int fd; + + if ((ret = tmp_file_init(tmp, verbose))) { + return ret; + } + + // make space to write extended file name + if ((tmp->name = malloc(strlen(tmp_name) + 7)) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to allocate memory for %s.\n", tmp_name); + return TMP_SAM_MEM_ERROR; + } + + // make sure temp file has a unique name + while (count < max_count) { + sprintf(tmp->name, "%s.%d", tmp_name, count); + + + #ifdef _WIN32 + if ((fd = _open(tmp->name, O_RDWR|O_CREAT|O_EXCL|O_BINARY|O_TEMPORARY, 0600)) == -1) { + #else + if ((fd = open(tmp->name, O_RDWR|O_CREAT|O_EXCL, 0600)) == -1) { + #endif /* _WIN32 */ + + if (errno != EEXIST) { + tmp_print_error(tmp, "[tmp_file] Error: unable to create tmp file %s.\n", tmp->name); + return TMP_SAM_FILE_ERROR; + } + + count++; + continue; + } + + break; + } + + if (count >= max_count) { + tmp_print_error(tmp, "[tmp_file] Error: unable to create unique temp file.\n"); + return TMP_SAM_FILE_ERROR; + } + + if ((tmp->fp = fdopen(fd, "w+b")) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to open write file %s.\n", tmp->name); + return TMP_SAM_FILE_ERROR; + } + + #ifndef _WIN32 + unlink(tmp->name); // should auto delete when closed on linux + #endif + + return TMP_SAM_OK; +} + + +/* + * The ring buffer stores precompressionn/post decompression data. LZ4 requires that + * previous data (64K worth) be available for efficient compression. This function grows + * the ring buffer when needed. + * Returns 0 on success, a negative number on failure. + */ +static int tmp_file_grow_ring_buffer(tmp_file_t *tmp, size_t new_size) { + // save the dictionary so lz4 can continue to function + int dict_size = 64 * 1024; // 64K max size + + if (tmp->groups_written) { + // if compression has been done then there is a dictionary to save + + if (tmp->dict == NULL) { + + if ((tmp->dict = malloc(sizeof(char) * dict_size)) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to allocate memory for compression dictionary.\n"); + return TMP_SAM_MEM_ERROR; + } + } + + if (LZ4_saveDict(tmp->stream, tmp->dict, dict_size) == 0) { + tmp_print_error(tmp, "[tmp_file] Error: unable to save compression dictionary.\n"); + return TMP_SAM_LZ4_ERROR; + } + } + + if ((tmp->ring_buffer = realloc(tmp->ring_buffer, sizeof(char) * new_size)) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to reallocate ring buffer.\n"); + return TMP_SAM_MEM_ERROR; + } + + tmp->ring_buffer_size = new_size; + + return TMP_SAM_OK; +} + + +/* + * This does the actual compression and writing to disk. On disk format consists of a + * single size_t for the size of the compressed data followed by the data itself. + * Returns 0 on success, a negative number on failure. + */ +static int tmp_file_write_to_file(tmp_file_t *tmp) { + size_t comp_size; + + if (tmp->input_size > tmp->max_data_size) { + tmp->max_data_size += tmp->input_size + sizeof(bam1_t); + tmp->comp_buffer_size = LZ4_COMPRESSBOUND(tmp->max_data_size); + + if ((tmp->comp_buffer = realloc(tmp->comp_buffer, sizeof(char) * tmp->comp_buffer_size)) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to reallocate compression buffer.\n"); + return TMP_SAM_MEM_ERROR; + } + + // make sure the ring buffer is big enough to accommodate the new max_data_size + if (tmp->ring_buffer_size < tmp->max_data_size * 5) { + int ret; + if ((ret = tmp_file_grow_ring_buffer(tmp, tmp->max_data_size * 5))) { + return ret; + } + } + } + + tmp->ring_index = tmp->ring_buffer + tmp->offset; + + comp_size = LZ4_compress_fast_continue(tmp->stream, (const char *)tmp->ring_index, + tmp->comp_buffer, tmp->input_size, tmp->comp_buffer_size, 1); + + if (comp_size == 0) { + tmp_print_error(tmp, "[tmp_file] Error: compression failed.\n"); + return TMP_SAM_LZ4_ERROR; + } + + if (fwrite(&comp_size, sizeof(size_t), 1, tmp->fp) < 1) { + tmp_print_error(tmp, "[tmp_file] Error: tmp file write size failed.\n"); + return TMP_SAM_FILE_ERROR; + } + + if (fwrite(tmp->comp_buffer, sizeof(char), comp_size, tmp->fp) < comp_size) { + tmp_print_error(tmp, "[tmp_file] Error: tmp file write data failed.\n"); + return TMP_SAM_FILE_ERROR; + } + + tmp->offset += tmp->input_size; + + if (tmp->offset >= tmp->ring_buffer_size - tmp->max_data_size) + tmp->offset = 0; + + tmp->input_size = 0; + tmp->entry_number = 0; + tmp->groups_written++; + + return TMP_SAM_OK; +} + + +/* + * Stores an in memory bam structure for writing and if enough are gathered together writes + * it to disk. Mulitiple alignments compress better that single ones though after a certain number + * there is a law of diminishing returns. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_write(tmp_file_t *tmp, bam1_t *inbam) { + + if ((tmp->input_size + sizeof(bam1_t) + inbam->l_data) >= tmp->ring_buffer_size) { + int ret; + + if ((ret = tmp_file_grow_ring_buffer(tmp, (tmp->input_size + sizeof(bam1_t) + inbam->l_data) * 5))) { + tmp_print_error(tmp, "[tmp_file] Error: input line too big. (%ld).\n", + (tmp->input_size + inbam->l_data)); + + return ret; + } + } + + tmp->ring_index = tmp->ring_buffer + tmp->offset + tmp->input_size; + + // copy data into the ring buffer + memcpy(tmp->ring_index, inbam, sizeof(bam1_t)); + memcpy(tmp->ring_index + sizeof(bam1_t) , inbam->data, inbam->l_data); + tmp->input_size += sizeof(bam1_t) + inbam->l_data; + tmp->entry_number++; + + if (tmp->entry_number == tmp->group_size) { + // actually write out the data + int ret; + + if ((ret = tmp_file_write_to_file(tmp))) { + return ret; + } + } + + return TMP_SAM_OK; +} + + +/* + * Closes the file after writing out any remaining alignments. Adds a size_t 0 to + * mark the end of the file. Companion function to tmp_file_open_read below. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_close_write(tmp_file_t *tmp) { + size_t terminator = 0; + + if (tmp->entry_number) { + int ret; + + if ((ret = tmp_file_write_to_file(tmp))) { + return ret; + } + } + + if (fwrite(&terminator, sizeof(size_t), 1, tmp->fp) < 1) { + tmp_print_error(tmp, "[tmp_file] Error: tmp file write terminator failed.\n"); + return TMP_SAM_FILE_ERROR; + } + + if (fclose(tmp->fp)) { + tmp_print_error(tmp, "[tmp_file] Error: closing tmp file %s failed.\n", tmp->name); + return TMP_SAM_FILE_ERROR; + } + + LZ4_freeStream(tmp->stream); + + return TMP_SAM_OK; +} + + +/* + * Opens the file for reading. Optionally, if given a pointer to an existing + * bam1_t structure, it will free the data entry to prevent memory leaks. + * Companion function to tmp_file_close_write above. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_open_read(tmp_file_t *tmp, bam1_t *inbam) { + + if ((tmp->fp = fopen(tmp->name, "rb")) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to open read file %s.\n", tmp->name); + return TMP_SAM_FILE_ERROR; + } + + tmp->dstream = LZ4_createStreamDecode(); + tmp->offset = 0; + + if (inbam) { + free(inbam->data); + } + + if (!tmp->dstream) { + tmp_print_error(tmp, "[tmp_file] Error: unable to allocate compression stream.\n"); + return TMP_SAM_MEM_ERROR; + } + + + return TMP_SAM_OK; +} + + +/* + * An alternative to tmp_file_close_write that does the same job without actually + * closing the file. Companion function to tmp_file_begin_read below. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_end_write(tmp_file_t *tmp) { + size_t terminator = 0; + + if (tmp->entry_number) { + int ret; + + if ((ret = tmp_file_write_to_file(tmp))) { + return ret; + } + } + + if (fwrite(&terminator, sizeof(size_t), 1, tmp->fp) < 1) { + tmp_print_error(tmp, "[tmp_file] Error: tmp file write terminator failed.\n"); + return TMP_SAM_FILE_ERROR; + } + + fflush(tmp->fp); + + LZ4_freeStream(tmp->stream); + + return TMP_SAM_OK; +} + + +/* + * An alternative to tmp_file_open_read but works on an open file. + * Companion function to tmp_file_end_write above. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_begin_read(tmp_file_t *tmp, bam1_t *inbam) { + + rewind(tmp->fp); + + tmp->dstream = LZ4_createStreamDecode(); + tmp->offset = 0; + tmp->entry_number = tmp->group_size; + + if (inbam) { + free(inbam->data); + } + + if (!tmp->dstream) { + tmp_print_error(tmp, "[tmp_file] Error: unable to allocate compression stream.\n"); + return TMP_SAM_MEM_ERROR; + } + + return TMP_SAM_OK; +} + + +/* + * Read the next alignment, either from memory or from disk. + * Returns size of entry on success, 0 on end of file or a negative on error. + */ +int tmp_file_read(tmp_file_t *tmp, bam1_t *inbam) { + int entry_size; + + if (tmp->entry_number == tmp->group_size) { + // read more data + size_t comp_size; + + if (fread(&comp_size, sizeof(size_t), 1, tmp->fp) == 0 || comp_size == 0) { + return TMP_SAM_OK; + } + + if (tmp->offset >= tmp->ring_buffer_size - tmp->max_data_size) + tmp->offset = 0; + + tmp->ring_index = tmp->ring_buffer + tmp->offset; + + if (fread(tmp->comp_buffer, sizeof(char), comp_size, tmp->fp) > comp_size) { + tmp_print_error(tmp, "[tmp_file] Error: error reading compressed data.\n"); + return TMP_SAM_FILE_ERROR; + } + + tmp->output_size = LZ4_decompress_safe_continue(tmp->dstream, tmp->comp_buffer, + (char *)tmp->ring_index, comp_size, tmp->max_data_size); + + if (tmp->output_size == 0) { + tmp_print_error(tmp, "[tmp_file] Error: decompression failed.\n"); + return TMP_SAM_LZ4_ERROR; + } + + tmp->entry_number = 0; + tmp->read_size = 0; + } + + tmp->ring_index = tmp->ring_buffer + tmp->offset; + memcpy(inbam, tmp->ring_index, sizeof(bam1_t)); + + if ((unsigned int)inbam->l_data > tmp->data_size) { + if ((tmp->data = realloc(tmp->data, sizeof(uint8_t) * inbam->l_data)) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to allocate tmp data memory.\n"); + return TMP_SAM_MEM_ERROR; + } + + tmp->data_size = inbam->l_data; + } + + inbam->data = tmp->data; + entry_size = sizeof(bam1_t); + + memcpy(inbam->data, tmp->ring_index + entry_size, inbam->l_data); + entry_size += inbam->l_data; + + tmp->offset += entry_size; + tmp->read_size += entry_size; + tmp->entry_number++; + + if (tmp->read_size > tmp->output_size) { + tmp_print_error(tmp, "[tmp_file] Error: wrong size of data returned RS:%ld OS:%ld EN:%ld GS:%ld.\n", + tmp->read_size, tmp->output_size, tmp->entry_number, tmp->group_size); + return TMP_SAM_LZ4_ERROR; + } + + if (tmp->read_size == tmp->output_size && tmp->entry_number != tmp->group_size) { + // hopefully the last entries in the read file + tmp->entry_number = tmp->group_size; + } + + return entry_size; +} + + +/* + * Frees up memory, closes the file and optionally deletes it. Giving this function + * pointer to the bam1_t structure used for reading will set its data value to null, + * preventing bam_destroy1() from trying to free already freed memory. + * Returns 0 on success, a negative number or EOF on failure. + */ +int tmp_file_destroy(tmp_file_t *tmp, bam1_t *inbam, int delete) { + int ret = 0; + + ret = fclose(tmp->fp); + + if (delete && ret == 0) { + if (unlink(tmp->name)) { + tmp_print_error(tmp, "[tmp_file] Error: unable to delete file %s.\n", tmp->name); + ret = TMP_SAM_FILE_ERROR; + } + } + + LZ4_freeStreamDecode(tmp->dstream); + free(tmp->ring_buffer); + free(tmp->comp_buffer); + free(tmp->name); + free(tmp->data); + free(tmp->dict); + + + if (inbam) { + inbam->data = NULL; + } + + return ret; +} diff --git a/samtools/tmp_file.c.pysam.c b/samtools/tmp_file.c.pysam.c new file mode 100644 index 000000000..3a00b38b6 --- /dev/null +++ b/samtools/tmp_file.c.pysam.c @@ -0,0 +1,509 @@ +#include "samtools.pysam.h" + +/* + tmp_file.c - write to and read from a temporary binary file + for fast storage plus added compression. + + Copyright (C) 2017 Genome Research Ltd. + + Author: Andrew Whitwham + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#include +#endif /* _WIN32 */ + +#include "tmp_file.h" +#include "htslib/sam.h" + + +static void tmp_print_error(tmp_file_t *tmp, const char *fmt, ...) { + va_list argp; + + if (tmp->verbose) { + va_start(argp, fmt); + vfprintf(samtools_stderr, fmt, argp); + va_end(argp); + } +} + + +static int tmp_file_init(tmp_file_t *tmp, int verbose) { + tmp->stream = LZ4_createStream(); + tmp->data_size = 0; + tmp->group_size = TMP_SAM_GROUP_SIZE; + tmp->input_size = 0; + tmp->read_size = 0; + tmp->output_size = 0; + tmp->entry_number = 0; + tmp->offset = 0; + tmp->max_data_size = TMP_SAM_MAX_DATA + sizeof(bam1_t); // arbitrary but growable + tmp->ring_buffer_size = TMP_SAM_RING_SIZE; // arbitrary (min 64K) but growable + tmp->comp_buffer_size = LZ4_COMPRESSBOUND(tmp->max_data_size * tmp->group_size); + tmp->data = NULL; + tmp->ring_buffer = malloc(sizeof(uint8_t) * tmp->ring_buffer_size); + tmp->ring_index = tmp->ring_buffer; + tmp->comp_buffer = malloc(tmp->comp_buffer_size); + tmp->verbose = verbose; + tmp->dict = NULL; + tmp->groups_written = 0; + + if (!tmp->ring_buffer || !tmp->comp_buffer || !tmp->stream) { + tmp_print_error(tmp, "[tmp_file] Error: unable to allocate compression buffers.\n"); + return TMP_SAM_MEM_ERROR; + } + + return TMP_SAM_OK; +} + + +/* + * Opens the temp file and initialises memory. + * Verbose mode prints out error messages to samtools_stderr. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_open_write(tmp_file_t *tmp, char *tmp_name, int verbose) { + int ret; + unsigned int count = 1; + const unsigned int max_count = 100000; // more tries than this then something else is wrong + int fd; + + if ((ret = tmp_file_init(tmp, verbose))) { + return ret; + } + + // make space to write extended file name + if ((tmp->name = malloc(strlen(tmp_name) + 7)) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to allocate memory for %s.\n", tmp_name); + return TMP_SAM_MEM_ERROR; + } + + // make sure temp file has a unique name + while (count < max_count) { + sprintf(tmp->name, "%s.%d", tmp_name, count); + + + #ifdef _WIN32 + if ((fd = _open(tmp->name, O_RDWR|O_CREAT|O_EXCL|O_BINARY|O_TEMPORARY, 0600)) == -1) { + #else + if ((fd = open(tmp->name, O_RDWR|O_CREAT|O_EXCL, 0600)) == -1) { + #endif /* _WIN32 */ + + if (errno != EEXIST) { + tmp_print_error(tmp, "[tmp_file] Error: unable to create tmp file %s.\n", tmp->name); + return TMP_SAM_FILE_ERROR; + } + + count++; + continue; + } + + break; + } + + if (count >= max_count) { + tmp_print_error(tmp, "[tmp_file] Error: unable to create unique temp file.\n"); + return TMP_SAM_FILE_ERROR; + } + + if ((tmp->fp = fdopen(fd, "w+b")) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to open write file %s.\n", tmp->name); + return TMP_SAM_FILE_ERROR; + } + + #ifndef _WIN32 + unlink(tmp->name); // should auto delete when closed on linux + #endif + + return TMP_SAM_OK; +} + + +/* + * The ring buffer stores precompressionn/post decompression data. LZ4 requires that + * previous data (64K worth) be available for efficient compression. This function grows + * the ring buffer when needed. + * Returns 0 on success, a negative number on failure. + */ +static int tmp_file_grow_ring_buffer(tmp_file_t *tmp, size_t new_size) { + // save the dictionary so lz4 can continue to function + int dict_size = 64 * 1024; // 64K max size + + if (tmp->groups_written) { + // if compression has been done then there is a dictionary to save + + if (tmp->dict == NULL) { + + if ((tmp->dict = malloc(sizeof(char) * dict_size)) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to allocate memory for compression dictionary.\n"); + return TMP_SAM_MEM_ERROR; + } + } + + if (LZ4_saveDict(tmp->stream, tmp->dict, dict_size) == 0) { + tmp_print_error(tmp, "[tmp_file] Error: unable to save compression dictionary.\n"); + return TMP_SAM_LZ4_ERROR; + } + } + + if ((tmp->ring_buffer = realloc(tmp->ring_buffer, sizeof(char) * new_size)) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to reallocate ring buffer.\n"); + return TMP_SAM_MEM_ERROR; + } + + tmp->ring_buffer_size = new_size; + + return TMP_SAM_OK; +} + + +/* + * This does the actual compression and writing to disk. On disk format consists of a + * single size_t for the size of the compressed data followed by the data itself. + * Returns 0 on success, a negative number on failure. + */ +static int tmp_file_write_to_file(tmp_file_t *tmp) { + size_t comp_size; + + if (tmp->input_size > tmp->max_data_size) { + tmp->max_data_size += tmp->input_size + sizeof(bam1_t); + tmp->comp_buffer_size = LZ4_COMPRESSBOUND(tmp->max_data_size); + + if ((tmp->comp_buffer = realloc(tmp->comp_buffer, sizeof(char) * tmp->comp_buffer_size)) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to reallocate compression buffer.\n"); + return TMP_SAM_MEM_ERROR; + } + + // make sure the ring buffer is big enough to accommodate the new max_data_size + if (tmp->ring_buffer_size < tmp->max_data_size * 5) { + int ret; + if ((ret = tmp_file_grow_ring_buffer(tmp, tmp->max_data_size * 5))) { + return ret; + } + } + } + + tmp->ring_index = tmp->ring_buffer + tmp->offset; + + comp_size = LZ4_compress_fast_continue(tmp->stream, (const char *)tmp->ring_index, + tmp->comp_buffer, tmp->input_size, tmp->comp_buffer_size, 1); + + if (comp_size == 0) { + tmp_print_error(tmp, "[tmp_file] Error: compression failed.\n"); + return TMP_SAM_LZ4_ERROR; + } + + if (fwrite(&comp_size, sizeof(size_t), 1, tmp->fp) < 1) { + tmp_print_error(tmp, "[tmp_file] Error: tmp file write size failed.\n"); + return TMP_SAM_FILE_ERROR; + } + + if (fwrite(tmp->comp_buffer, sizeof(char), comp_size, tmp->fp) < comp_size) { + tmp_print_error(tmp, "[tmp_file] Error: tmp file write data failed.\n"); + return TMP_SAM_FILE_ERROR; + } + + tmp->offset += tmp->input_size; + + if (tmp->offset >= tmp->ring_buffer_size - tmp->max_data_size) + tmp->offset = 0; + + tmp->input_size = 0; + tmp->entry_number = 0; + tmp->groups_written++; + + return TMP_SAM_OK; +} + + +/* + * Stores an in memory bam structure for writing and if enough are gathered together writes + * it to disk. Mulitiple alignments compress better that single ones though after a certain number + * there is a law of diminishing returns. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_write(tmp_file_t *tmp, bam1_t *inbam) { + + if ((tmp->input_size + sizeof(bam1_t) + inbam->l_data) >= tmp->ring_buffer_size) { + int ret; + + if ((ret = tmp_file_grow_ring_buffer(tmp, (tmp->input_size + sizeof(bam1_t) + inbam->l_data) * 5))) { + tmp_print_error(tmp, "[tmp_file] Error: input line too big. (%ld).\n", + (tmp->input_size + inbam->l_data)); + + return ret; + } + } + + tmp->ring_index = tmp->ring_buffer + tmp->offset + tmp->input_size; + + // copy data into the ring buffer + memcpy(tmp->ring_index, inbam, sizeof(bam1_t)); + memcpy(tmp->ring_index + sizeof(bam1_t) , inbam->data, inbam->l_data); + tmp->input_size += sizeof(bam1_t) + inbam->l_data; + tmp->entry_number++; + + if (tmp->entry_number == tmp->group_size) { + // actually write out the data + int ret; + + if ((ret = tmp_file_write_to_file(tmp))) { + return ret; + } + } + + return TMP_SAM_OK; +} + + +/* + * Closes the file after writing out any remaining alignments. Adds a size_t 0 to + * mark the end of the file. Companion function to tmp_file_open_read below. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_close_write(tmp_file_t *tmp) { + size_t terminator = 0; + + if (tmp->entry_number) { + int ret; + + if ((ret = tmp_file_write_to_file(tmp))) { + return ret; + } + } + + if (fwrite(&terminator, sizeof(size_t), 1, tmp->fp) < 1) { + tmp_print_error(tmp, "[tmp_file] Error: tmp file write terminator failed.\n"); + return TMP_SAM_FILE_ERROR; + } + + if (fclose(tmp->fp)) { + tmp_print_error(tmp, "[tmp_file] Error: closing tmp file %s failed.\n", tmp->name); + return TMP_SAM_FILE_ERROR; + } + + LZ4_freeStream(tmp->stream); + + return TMP_SAM_OK; +} + + +/* + * Opens the file for reading. Optionally, if given a pointer to an existing + * bam1_t structure, it will free the data entry to prevent memory leaks. + * Companion function to tmp_file_close_write above. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_open_read(tmp_file_t *tmp, bam1_t *inbam) { + + if ((tmp->fp = fopen(tmp->name, "rb")) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to open read file %s.\n", tmp->name); + return TMP_SAM_FILE_ERROR; + } + + tmp->dstream = LZ4_createStreamDecode(); + tmp->offset = 0; + + if (inbam) { + free(inbam->data); + } + + if (!tmp->dstream) { + tmp_print_error(tmp, "[tmp_file] Error: unable to allocate compression stream.\n"); + return TMP_SAM_MEM_ERROR; + } + + + return TMP_SAM_OK; +} + + +/* + * An alternative to tmp_file_close_write that does the same job without actually + * closing the file. Companion function to tmp_file_begin_read below. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_end_write(tmp_file_t *tmp) { + size_t terminator = 0; + + if (tmp->entry_number) { + int ret; + + if ((ret = tmp_file_write_to_file(tmp))) { + return ret; + } + } + + if (fwrite(&terminator, sizeof(size_t), 1, tmp->fp) < 1) { + tmp_print_error(tmp, "[tmp_file] Error: tmp file write terminator failed.\n"); + return TMP_SAM_FILE_ERROR; + } + + fflush(tmp->fp); + + LZ4_freeStream(tmp->stream); + + return TMP_SAM_OK; +} + + +/* + * An alternative to tmp_file_open_read but works on an open file. + * Companion function to tmp_file_end_write above. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_begin_read(tmp_file_t *tmp, bam1_t *inbam) { + + rewind(tmp->fp); + + tmp->dstream = LZ4_createStreamDecode(); + tmp->offset = 0; + tmp->entry_number = tmp->group_size; + + if (inbam) { + free(inbam->data); + } + + if (!tmp->dstream) { + tmp_print_error(tmp, "[tmp_file] Error: unable to allocate compression stream.\n"); + return TMP_SAM_MEM_ERROR; + } + + return TMP_SAM_OK; +} + + +/* + * Read the next alignment, either from memory or from disk. + * Returns size of entry on success, 0 on end of file or a negative on error. + */ +int tmp_file_read(tmp_file_t *tmp, bam1_t *inbam) { + int entry_size; + + if (tmp->entry_number == tmp->group_size) { + // read more data + size_t comp_size; + + if (fread(&comp_size, sizeof(size_t), 1, tmp->fp) == 0 || comp_size == 0) { + return TMP_SAM_OK; + } + + if (tmp->offset >= tmp->ring_buffer_size - tmp->max_data_size) + tmp->offset = 0; + + tmp->ring_index = tmp->ring_buffer + tmp->offset; + + if (fread(tmp->comp_buffer, sizeof(char), comp_size, tmp->fp) > comp_size) { + tmp_print_error(tmp, "[tmp_file] Error: error reading compressed data.\n"); + return TMP_SAM_FILE_ERROR; + } + + tmp->output_size = LZ4_decompress_safe_continue(tmp->dstream, tmp->comp_buffer, + (char *)tmp->ring_index, comp_size, tmp->max_data_size); + + if (tmp->output_size == 0) { + tmp_print_error(tmp, "[tmp_file] Error: decompression failed.\n"); + return TMP_SAM_LZ4_ERROR; + } + + tmp->entry_number = 0; + tmp->read_size = 0; + } + + tmp->ring_index = tmp->ring_buffer + tmp->offset; + memcpy(inbam, tmp->ring_index, sizeof(bam1_t)); + + if ((unsigned int)inbam->l_data > tmp->data_size) { + if ((tmp->data = realloc(tmp->data, sizeof(uint8_t) * inbam->l_data)) == NULL) { + tmp_print_error(tmp, "[tmp_file] Error: unable to allocate tmp data memory.\n"); + return TMP_SAM_MEM_ERROR; + } + + tmp->data_size = inbam->l_data; + } + + inbam->data = tmp->data; + entry_size = sizeof(bam1_t); + + memcpy(inbam->data, tmp->ring_index + entry_size, inbam->l_data); + entry_size += inbam->l_data; + + tmp->offset += entry_size; + tmp->read_size += entry_size; + tmp->entry_number++; + + if (tmp->read_size > tmp->output_size) { + tmp_print_error(tmp, "[tmp_file] Error: wrong size of data returned RS:%ld OS:%ld EN:%ld GS:%ld.\n", + tmp->read_size, tmp->output_size, tmp->entry_number, tmp->group_size); + return TMP_SAM_LZ4_ERROR; + } + + if (tmp->read_size == tmp->output_size && tmp->entry_number != tmp->group_size) { + // hopefully the last entries in the read file + tmp->entry_number = tmp->group_size; + } + + return entry_size; +} + + +/* + * Frees up memory, closes the file and optionally deletes it. Giving this function + * pointer to the bam1_t structure used for reading will set its data value to null, + * preventing bam_destroy1() from trying to free already freed memory. + * Returns 0 on success, a negative number or EOF on failure. + */ +int tmp_file_destroy(tmp_file_t *tmp, bam1_t *inbam, int delete) { + int ret = 0; + + ret = fclose(tmp->fp); + + if (delete && ret == 0) { + if (unlink(tmp->name)) { + tmp_print_error(tmp, "[tmp_file] Error: unable to delete file %s.\n", tmp->name); + ret = TMP_SAM_FILE_ERROR; + } + } + + LZ4_freeStreamDecode(tmp->dstream); + free(tmp->ring_buffer); + free(tmp->comp_buffer); + free(tmp->name); + free(tmp->data); + free(tmp->dict); + + + if (inbam) { + inbam->data = NULL; + } + + return ret; +} diff --git a/samtools/tmp_file.h b/samtools/tmp_file.h new file mode 100644 index 000000000..74e4126b2 --- /dev/null +++ b/samtools/tmp_file.h @@ -0,0 +1,144 @@ +/* + tmp_file.h - write to and read from a temporary binary file + for fast storage plus added compression. + + Copyright (C) 2017 Genome Research Ltd. + + Author: Andrew Whitwham + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE +*/ + +#ifndef _TMP_SAM_FILE_H_ +#define _TMP_SAM_FILE_H_ + +#include +#include "htslib/sam.h" + +#ifdef _cplusplus +extern "C" { +#endif + +// Group size that seems to give reasonable compression. +#define TMP_SAM_GROUP_SIZE 100 + +// Arbitrary initial size values but growable. +#define TMP_SAM_MAX_DATA 1024 +#define TMP_SAM_RING_SIZE 1048576 + +// Error numbers. +#define TMP_SAM_OK 0 +#define TMP_SAM_MEM_ERROR -1 +#define TMP_SAM_FILE_ERROR -2 +#define TMP_SAM_LZ4_ERROR -3 +#define TMP_SAM_INPUT_ERROR -4 + +typedef struct { + FILE *fp; + LZ4_stream_t *stream; + LZ4_streamDecode_t *dstream; + size_t data_size; + size_t max_data_size; + size_t ring_buffer_size; + size_t comp_buffer_size; + size_t offset; + uint8_t *data; + uint8_t *ring_buffer; + uint8_t *ring_index; + char *comp_buffer; + char *name; + size_t group_size; + size_t input_size; + size_t read_size; + size_t output_size; + size_t entry_number; + int verbose; + char *dict; + size_t groups_written; +} tmp_file_t; + + +/* + * Opens the temp file and initialises memory. + * Verbose mode prints out error messages to stderr. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_open_write(tmp_file_t *tmp, char *tmp_name, int verbose); + + +/* + * Stores an in memory bam structure for writing and if enough are gathered together writes + * it to disk. Mulitiple alignments compress better that single ones though after a certain number + * there is a law of diminishing returns. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_write(tmp_file_t *tmp, bam1_t *inbam); + + +/* + * Closes the file after writing out any remaining alignments. Adds a size_t 0 to + * mark the end of the file. Companion function to tmp_file_open_read below. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_close_write(tmp_file_t *tmp); + + +/* + * Opens the file for reading. Optionally, if given a pointer to an existing + * bam1_t structure, it will free the data entry to prevent memory leaks. + * Companion function to tmp_file_close_write above. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_open_read(tmp_file_t *tmp, bam1_t *inbam); + + +/* + * An alternative to tmp_file_close_write that does the same job without actually + * closing the file. Companion function to tmp_file_begin_read below. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_end_write(tmp_file_t *tmp); + +/* + * An alternative to tmp_file_open_read but works on an open file. + * Companion function to tmp_file_end_write above. + * Returns 0 on success, a negative number on failure. + */ +int tmp_file_begin_read(tmp_file_t *tmp, bam1_t *inbam); + +/* + * Read the next alignment, either from memory or from disk. + * Returns size of entry on success, 0 on end of file or a negative on error. + */ +int tmp_file_read(tmp_file_t *tmp, bam1_t *inbam); + + +/* + * Frees up memory, closes the file and optionally deletes it. Giving this function + * pointer to the bam1_t structure used for reading will set its data value to null, + * preventing bam_destroy1() from trying to free already freed memory. + * Returns 0 on success, a negative number or EOF on failure. + */ +int tmp_file_destroy(tmp_file_t *tmp, bam1_t *inbam, int delete); + +#ifdef __cplusplus +} +#endif + +#endif /* _TMP_SAM_FILE_H_ */ diff --git a/samtools/version.h b/samtools/version.h index ec46e67f1..9dcb73f18 100644 --- a/samtools/version.h +++ b/samtools/version.h @@ -1 +1 @@ -#define SAMTOOLS_VERSION "1.3.1" +#define SAMTOOLS_VERSION "1.7" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 000000000..1f061e55d --- /dev/null +++ b/setup.cfg @@ -0,0 +1,10 @@ +[bdist_wheel] +universal = 0 + +[tool:pytest] +# -s: do not capture stdout, conflicts with pysam.dispatch +# -v: verbose output +addopts = -s -v +testpaths = pysam tests +pep8maxlinelength = 120 +pep8ignore = E402 diff --git a/setup.py b/setup.py index e99391963..6756b4ed1 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ using cython and a high-level API for convenient access to the data within standard genomic file formats. -The current version wraps htslib-1.3.1, samtools-1.3.1 and bcftools-1.3.1. +The current version wraps htslib-1.7, samtools-1.7 and bcftools-1.6. See: http://www.htslib.org @@ -32,6 +32,12 @@ import sysconfig from contextlib import contextmanager from setuptools import Extension, setup +from cy_build import CyExtension as Extension, cy_build_ext as build_ext +try: + import cython + HAVE_CYTHON = True +except ImportError: + HAVE_CYTHON = False IS_PYTHON3 = sys.version_info.major >= 3 @@ -78,6 +84,11 @@ def configure_library(library_dir, env_options=None, options=[]): configure_script = os.path.join(library_dir, "configure") + on_rtd = os.environ.get("READTHEDOCS") == "True" + # RTD has no bzip2 development libraries installed: + if on_rtd: + env_options = "--disable-bz2" + if not os.path.exists(configure_script): raise ValueError( "configure script {} does not exist".format(configure_script)) @@ -104,17 +115,23 @@ def distutils_dir_name(dname): platform=sysconfig.get_platform(), version=sys.version_info) + +def get_pysam_version(): + sys.path.insert(0, "pysam") + import version + return version.__version__ + + # How to link against HTSLIB -# separate: use included htslib and include in each extension -# module. No dependencies between modules and works -# with setup.py install, but wasteful in terms of -# memory and compilation time. -# shared: share chtslib across extension modules. This would be -# the ideal method, but currently requires -# LD_LIBRARY_PATH to be set correctly when using -# pysam. +# shared: build shared chtslib from builtin htslib code. # external: use shared libhts.so compiled outside of # pysam +# separate: use included htslib and include in each extension +# module. No dependencies between modules and works with +# setup.py install, but wasteful in terms of memory and +# compilation time. Fallback if shared module compilation +# fails. + HTSLIB_MODE = os.environ.get("HTSLIB_MODE", "shared") HTSLIB_LIBRARY_DIR = os.environ.get("HTSLIB_LIBRARY_DIR", None) HTSLIB_INCLUDE_DIR = os.environ.get("HTSLIB_INCLUDE_DIR", None) @@ -129,42 +146,37 @@ def distutils_dir_name(dname): package_dirs = {'pysam': 'pysam', 'pysam.include.samtools': 'samtools', 'pysam.include.bcftools': 'bcftools'} -config_headers = ["samtools/config.h"] -from cy_build import CyExtension as Extension, cy_build_ext as build_ext +# list of config files that will be automatically generated should +# they not already exist or be created by configure scripts in the +# subpackages. +config_headers = ["samtools/config.h", + "bcftools/config.h"] cmdclass = {'build_ext': build_ext} -# Check if cython is available -# # If cython is available, the pysam will be built using cython from # the .pyx files. If no cython is available, the C-files included in the # distribution will be used. -try: - import cython - HAVE_CYTHON = True +if HAVE_CYTHON: print ("# pysam: cython is available - using cythonize if necessary") source_pattern = "pysam/libc%s.pyx" -except ImportError: - HAVE_CYTHON = False +else: print ("# pysam: no cython available - using pre-compiled C") - # no Cython available - use existing C code source_pattern = "pysam/libc%s.c" -# collect pysam version -sys.path.insert(0, "pysam") -import version -version = version.__version__ +# Exit if there are no pre-compiled files and no cython available +fn = source_pattern % "htslib" +if not os.path.exists(fn): + raise ValueError( + "no cython installed, but can not find {}." + "Make sure that cython is installed when building " + "from the repository" + .format(fn)) # exclude sources that contain a main function EXCLUDE = { "samtools": ( - "razip.c", "bgzip.c", "main.c", - "calDepth.c", "bam2bed.c", "wgsim.c", - "md5fa.c", "md5sum-lite.c", "maq2sam.c", - "bamcheck.c", "chk_indel.c", "vcf-miniview.c", - "htslib-1.3", # do not import twice - "hfile_irods.c", # requires irods library ), "bcftools": ( "test", "plugins", "peakfit.c", @@ -173,8 +185,9 @@ def distutils_dir_name(dname): "reheader.c", "polysomy.c"), "htslib": ( - 'htslib/tabix.c', 'htslib/bgzip.c', - 'htslib/htsfile.c', 'htslib/hfile_irods.c'), + 'htslib/tabix.c', + 'htslib/bgzip.c', + 'htslib/htsfile.c'), } print ("# pysam: htslib mode is {}".format(HTSLIB_MODE)) @@ -232,7 +245,6 @@ def distutils_dir_name(dname): htslib_library_dirs = [HTSLIB_LIBRARY_DIR] htslib_include_dirs = [HTSLIB_INCLUDE_DIR] external_htslib_libraries = ['z', 'hts'] - elif HTSLIB_MODE == 'separate': # add to each pysam component a separately compiled # htslib @@ -240,23 +252,19 @@ def distutils_dir_name(dname): shared_htslib_sources = htslib_sources htslib_library_dirs = [] htslib_include_dirs = ['htslib'] - elif HTSLIB_MODE == 'shared': # link each pysam component against the same # htslib built from sources included in the pysam # package. htslib_library_dirs = [ - 'pysam', - ".", + "pysam", # when using setup.py develop? + ".", # when using setup.py develop? os.path.join("build", distutils_dir_name("lib"), "pysam")] htslib_include_dirs = ['htslib'] - else: raise ValueError("unknown HTSLIB value '%s'" % HTSLIB_MODE) -internal_htslib_libraries = [os.path.splitext("chtslib{}".format(sysconfig.get_config_var('SO')))[0]] - # build config.py with open(os.path.join("pysam", "config.py"), "w") as outf: outf.write('HTSLIB = "{}"\n'.format(HTSLIB_SOURCE)) @@ -290,42 +298,6 @@ def distutils_dir_name(dname): outf.write( "/* conservative compilation options */\n") -parts = ["samtools", - "bcftools", - "htslib", - "tabix", - "faidx", - "samfile", - "utils", - "alignmentfile", - "tabixproxies", - "vcf", - "bcf"] - -# Exit if there are no pre-compiled files and no cython available -fn = source_pattern % "htslib" -if not os.path.exists(fn): - raise ValueError( - "no cython installed, but can not find {}." - "Make sure that cython is installed when building " - "from the repository" - .format(fn)) - - -####################################################### -classifiers = """ -Development Status :: 3 - Beta -Operating System :: MacOS :: MacOS X -Operating System :: POSIX -Operating System :: POSIX :: Linux -Operating System :: Unix -Programming Language :: Python -Topic :: Scientific/Engineering -Topic :: Scientific/Engineering :: Bioinformatics -""" - -####################################################### - ####################################################### # Windows compatibility - untested if platform.system() == 'Windows': @@ -347,199 +319,115 @@ def distutils_dir_name(dname): define_macros = [] -chtslib = Extension( - "pysam.libchtslib", - [source_pattern % "htslib", - "pysam/htslib_util.c"] + - shared_htslib_sources + - os_c_files, - library_dirs=htslib_library_dirs, - runtime_library_dirs=htslib_library_dirs, - include_dirs=["pysam", "."] + include_os + htslib_include_dirs, - libraries=external_htslib_libraries, - language="c", - extra_compile_args=extra_compile_args, - define_macros=define_macros -) - -# samfile requires functions defined in bam_md.c -# for __advance_samtools method. -# Selected ones have been copied into samfile_utils.c -# Needs to be devolved somehow. -csamfile = Extension( - "pysam.libcsamfile", - [source_pattern % "samfile", - "pysam/htslib_util.c", - "pysam/samfile_util.c", - "samtools/kprobaln.c"] + - htslib_sources + - os_c_files, - library_dirs=htslib_library_dirs, - include_dirs=["pysam", "samtools", "."] + include_os + htslib_include_dirs, - libraries=external_htslib_libraries + internal_htslib_libraries, - language="c", - extra_compile_args=extra_compile_args, - define_macros=define_macros -) - -# alignmentfile requires functions defined in bam_md.c -# for __advance_samtools method. -# Selected ones have been copied into samfile_utils.c -# Needs to be devolved somehow. -calignmentfile = Extension( - "pysam.libcalignmentfile", - [source_pattern % "alignmentfile", - "pysam/htslib_util.c", - "pysam/samfile_util.c", - "samtools/kprobaln.c"] + - htslib_sources + - os_c_files, - library_dirs=htslib_library_dirs, - include_dirs=["pysam", "samtools"] + include_os + htslib_include_dirs, - libraries=external_htslib_libraries + internal_htslib_libraries, - language="c", - extra_compile_args=extra_compile_args, - define_macros=define_macros -) - -# alignmentfile requires functions defined in bam_md.c -# for __advance_samtools method. -# Selected ones have been copied into samfile_utils.c -# Needs to be devolved somehow. -calignedsegment = Extension( - "pysam.libcalignedsegment", - [source_pattern % "alignedsegment", - "pysam/htslib_util.c", - "pysam/samfile_util.c", - "samtools/kprobaln.c"] + - htslib_sources + - os_c_files, - library_dirs=htslib_library_dirs, - include_dirs=["pysam", "samtools", "."] + include_os + htslib_include_dirs, - libraries=external_htslib_libraries + internal_htslib_libraries, - language="c", - extra_compile_args=extra_compile_args, - define_macros=define_macros -) - -ctabix = Extension( - "pysam.libctabix", - [source_pattern % "tabix", - "pysam/tabix_util.c"] + - htslib_sources + - os_c_files, - library_dirs=["pysam"] + htslib_library_dirs, - include_dirs=["pysam", "."] + include_os + htslib_include_dirs, - libraries=external_htslib_libraries + internal_htslib_libraries, +suffix = sysconfig.get_config_var('EXT_SUFFIX') +if not suffix: + suffix = sysconfig.get_config_var('SO') + +internal_htslib_libraries = [ + os.path.splitext("chtslib{}".format(suffix))[0]] +internal_samtools_libraries = [ + os.path.splitext("csamtools{}".format(suffix))[0], + os.path.splitext("cbcftools{}".format(suffix))[0], + ] +internal_pysamutil_libraries = [ + os.path.splitext("cutils{}".format(suffix))[0]] + +libraries_for_pysam_module = external_htslib_libraries + internal_htslib_libraries + internal_pysamutil_libraries + +# Order of modules matters in order to make sure that dependencies are resolved. +# The structures of dependencies is as follows: +# libchtslib: htslib utility functions and htslib itself if builtin is set. +# libcsamtools: samtools code (builtin) +# libcbcftools: bcftools code (builtin) +# libcutils: General utility functions, depends on all of the above +# libcXXX (pysam module): depends on libchtslib and libcutils + +# The list below uses the union of include_dirs and library_dirs for +# reasons of simplicity. + +modules = [ + dict(name="pysam.libchtslib", + sources=[source_pattern % "htslib", "pysam/htslib_util.c"] + shared_htslib_sources + os_c_files, + libraries=external_htslib_libraries), + dict(name="pysam.libcsamtools", + sources=[source_pattern % "samtools"] + glob.glob(os.path.join("samtools", "*.pysam.c")) + + [os.path.join("samtools", "lz4", "lz4.c")] + htslib_sources + os_c_files, + libraries=external_htslib_libraries + internal_htslib_libraries), + dict(name="pysam.libcbcftools", + sources=[source_pattern % "bcftools"] + glob.glob(os.path.join("bcftools", "*.pysam.c")) + htslib_sources + os_c_files, + libraries=external_htslib_libraries + internal_htslib_libraries), + dict(name="pysam.libcutils", + sources=[source_pattern % "utils", "pysam/pysam_util.c"] + htslib_sources + os_c_files, + libraries=external_htslib_libraries + internal_htslib_libraries + internal_samtools_libraries), + dict(name="pysam.libcalignmentfile", + sources=[source_pattern % "alignmentfile"] + htslib_sources + os_c_files, + libraries=libraries_for_pysam_module), + dict(name="pysam.libcsamfile", + sources=[source_pattern % "samfile"] + htslib_sources + os_c_files, + libraries=libraries_for_pysam_module), + dict(name="pysam.libcalignedsegment", + sources=[source_pattern % "alignedsegment"] + htslib_sources + os_c_files, + libraries=libraries_for_pysam_module), + dict(name="pysam.libctabix", + sources=[source_pattern % "tabix"] + htslib_sources + os_c_files, + libraries=libraries_for_pysam_module), + dict(name="pysam.libcfaidx", + sources=[source_pattern % "faidx"] + htslib_sources + os_c_files, + libraries=libraries_for_pysam_module), + dict(name="pysam.libcbcf", + sources=[source_pattern % "bcf"] + htslib_sources + os_c_files, + libraries=libraries_for_pysam_module), + dict(name="pysam.libcbgzf", + sources=[source_pattern % "bgzf"] + htslib_sources + os_c_files, + libraries=libraries_for_pysam_module), + dict(name="pysam.libctabixproxies", + sources=[source_pattern % "tabixproxies"] + htslib_sources + os_c_files, + libraries=libraries_for_pysam_module), + dict(name="pysam.libcvcf", + sources=[source_pattern % "vcf"] + htslib_sources + os_c_files, + libraries=libraries_for_pysam_module), +] + +common_options = dict( language="c", extra_compile_args=extra_compile_args, - define_macros=define_macros -) - -cutils = Extension( - "pysam.libcutils", - [source_pattern % "utils", "pysam/pysam_util.c"] + - glob.glob(os.path.join("samtools", "*.pysam.c")) + - # glob.glob(os.path.join("samtools", "*", "*.pysam.c")) + - glob.glob(os.path.join("bcftools", "*.pysam.c")) + - # glob.glob(os.path.join("bcftools", "*", "*.pysam.c")) + - htslib_sources + - os_c_files, - library_dirs=["pysam"] + htslib_library_dirs, - include_dirs=["samtools", "bcftools", "pysam", "."] + - include_os + htslib_include_dirs, - libraries=external_htslib_libraries + internal_htslib_libraries, - language="c", - extra_compile_args=extra_compile_args, - define_macros=define_macros -) - -cfaidx = Extension( - "pysam.libcfaidx", - [source_pattern % "faidx"] + - htslib_sources + - os_c_files, - library_dirs=["pysam"] + htslib_library_dirs, - include_dirs=["pysam", "."] + include_os + htslib_include_dirs, - libraries=external_htslib_libraries + internal_htslib_libraries, - language="c", - extra_compile_args=extra_compile_args, - define_macros=define_macros -) - -ctabixproxies = Extension( - "pysam.libctabixproxies", - [source_pattern % "tabixproxies"] + - os_c_files, - library_dirs=htslib_library_dirs, - include_dirs=include_os, - libraries=external_htslib_libraries + internal_htslib_libraries, - language="c", - extra_compile_args=extra_compile_args, - define_macros=define_macros -) - -cvcf = Extension( - "pysam.libcvcf", - [source_pattern % "vcf"] + - os_c_files, - library_dirs=htslib_library_dirs, - include_dirs=["htslib", "."] + include_os + htslib_include_dirs, - libraries=external_htslib_libraries + internal_htslib_libraries, - language="c", - extra_compile_args=extra_compile_args, - define_macros=define_macros -) - -cbcf = Extension( - "pysam.libcbcf", - [source_pattern % "bcf"] + - htslib_sources + - os_c_files, - library_dirs=htslib_library_dirs, - include_dirs=["htslib", "."] + include_os + htslib_include_dirs, - libraries=external_htslib_libraries + internal_htslib_libraries, - language="c", - extra_compile_args=extra_compile_args, - define_macros=define_macros -) - -cbgzf = Extension( - "pysam.libcbgzf", - [source_pattern % "bgzf"] + - htslib_sources + - os_c_files, - library_dirs=htslib_library_dirs, - include_dirs=["htslib", "."] + include_os + htslib_include_dirs, - libraries=external_htslib_libraries + internal_htslib_libraries, - language="c", - extra_compile_args=extra_compile_args, - define_macros=define_macros -) + define_macros=define_macros, + # for out-of-tree compilation, use absolute paths + library_dirs=[os.path.abspath(x) for x in ["pysam"] + htslib_library_dirs], + include_dirs=[os.path.abspath(x) for x in htslib_include_dirs + \ + ["samtools", "samtools/lz4", "bcftools", "pysam", "."] + include_os]) + +# add common options (in python >3.5, could use n = {**a, **b} +for module in modules: + module.update(**common_options) +classifiers = """ +Development Status :: 4 - Beta +Intended Audience :: Science/Research +Intended Audience :: Developers +License :: OSI Approved +Programming Language :: Python +Topic :: Software Development +Topic :: Scientific/Engineering +Operating System :: POSIX +Operating System :: Unix +Operating System :: MacOS +""" + metadata = { 'name': "pysam", - 'version': version, + 'version': get_pysam_version(), 'description': "pysam", 'long_description': __doc__, 'author': "Andreas Heger", 'author_email': "andreas.heger@gmail.com", 'license': "MIT", - 'platforms': "ALL", + 'platforms': ["POSIX", "UNIX", "MacOS"], + 'classifiers': [_f for _f in classifiers.split("\n") if _f], 'url': "https://github.com/pysam-developers/pysam", 'packages': package_list, 'requires': ['cython (>=0.21)'], - 'ext_modules': [chtslib, - csamfile, - calignmentfile, - calignedsegment, - ctabix, - ctabixproxies, - cvcf, - cbcf, - cbgzf, - cfaidx, - cutils], + 'ext_modules': [Extension(**opts) for opts in modules], 'cmdclass': cmdclass, 'package_dir': package_dirs, 'package_data': {'': ['*.pxd', '*.h'], }, diff --git a/tests/AlignedSegment_bench.py b/tests/AlignedSegment_bench.py new file mode 100644 index 000000000..f5bccd677 --- /dev/null +++ b/tests/AlignedSegment_bench.py @@ -0,0 +1,30 @@ +"""Benchmarking module for AlignedSegment functionality""" +import os +import array +import pysam + + +from TestUtils import BAM_DATADIR + + +def set_binary_tag(): + read = pysam.AlignedSegment() + read.set_tag('FZ', array.array('H', range(1000))) + return len(read.get_tag('FZ')) + + +def read_binary_tag(fn): + with pysam.AlignmentFile(fn) as inf: + read = next(inf.fetch()) + return len(read.get_tag('FZ')) + + +def test_set_binary_tag(benchmark): + result = benchmark(set_binary_tag) + assert result == 1000 + + +def test_read_binary_tag(benchmark): + result = benchmark(read_binary_tag, os.path.join( + BAM_DATADIR, "example_btag.bam")) + assert result == 260 diff --git a/tests/AlignedSegment_test.py b/tests/AlignedSegment_test.py index b0a3466d4..332727901 100644 --- a/tests/AlignedSegment_test.py +++ b/tests/AlignedSegment_test.py @@ -1,26 +1,32 @@ import os import pysam import unittest +import json import collections +import string import copy import array -from TestUtils import checkFieldEqual +from TestUtils import checkFieldEqual, BAM_DATADIR, get_temp_filename, get_temp_context, IS_PYTHON3 -SAMTOOLS = "samtools" -WORKDIR = "pysam_test_work" -DATADIR = "pysam_data" - +if IS_PYTHON3: + maketrans = str.maketrans +else: + maketrans = string.maketrans class ReadTest(unittest.TestCase): - def buildRead(self): + def build_read(self): '''build an example read.''' - a = pysam.AlignedSegment() + header = pysam.AlignmentHeader.from_references( + ["chr1", "chr2"], + [10000000, 10000000]) + + a = pysam.AlignedSegment(header) a.query_name = "read_12345" - a.query_sequence = "ACGT" * 10 + a.query_sequence = "ATGC" * 10 a.flag = 0 a.reference_id = 0 a.reference_start = 20 @@ -30,7 +36,6 @@ def buildRead(self): a.next_reference_start = 200 a.template_length = 167 a.query_qualities = pysam.qualitystring_to_array("1234") * 10 - # todo: create tags return a @@ -41,10 +46,12 @@ class TestAlignedSegment(ReadTest): ''' def testEmpty(self): + a = pysam.AlignedSegment() self.assertEqual(a.query_name, None) self.assertEqual(a.query_sequence, None) - self.assertEqual(pysam.qualities_to_qualitystring(a.query_qualities), None) + self.assertEqual(pysam.qualities_to_qualitystring( + a.query_qualities), None) self.assertEqual(a.flag, 0) self.assertEqual(a.reference_id, -1) self.assertEqual(a.mapping_quality, 0) @@ -53,7 +60,7 @@ def testEmpty(self): self.assertEqual(a.next_reference_id, -1) self.assertEqual(a.next_reference_start, -1) self.assertEqual(a.template_length, 0) - + def testStrOfEmptyRead(self): a = pysam.AlignedSegment() s = str(a) @@ -70,8 +77,8 @@ def testSettingTagInEmptyRead(self): def testCompare(self): '''check comparison functions.''' - a = self.buildRead() - b = self.buildRead() + a = self.build_read() + b = self.build_read() self.assertEqual(0, a.compare(b)) self.assertEqual(0, b.compare(a)) @@ -80,24 +87,24 @@ def testCompare(self): self.assertFalse(a != b) self.assertFalse(b != a) - b.tid = 2 + b.tid = 1 self.assertFalse(a == b) self.assertFalse(b == a) self.assertTrue(a != b) self.assertTrue(b != a) def testHashing(self): - a = self.buildRead() - b = self.buildRead() + a = self.build_read() + b = self.build_read() self.assertEqual(hash(a), hash(b)) - b.tid = 2 + b.tid = 1 self.assertNotEqual(hash(a), hash(b)) def testUpdate(self): '''check if updating fields affects other variable length data ''' - a = self.buildRead() - b = self.buildRead() + a = self.build_read() + b = self.build_read() # check qname b.query_name = "read_123" @@ -116,19 +123,19 @@ def testUpdate(self): checkFieldEqual(self, a, b) # check seq - b.query_sequence = "ACGT" + b.query_sequence = "ATGC" checkFieldEqual(self, a, b, ("query_sequence", "query_qualities", "query_length")) - b.query_sequence = "ACGT" * 3 + b.query_sequence = "ATGC" * 3 checkFieldEqual(self, a, b, ("query_sequence", "query_qualities", "query_length")) - b.query_sequence = "ACGT" * 10 + b.query_sequence = "ATGC" * 10 checkFieldEqual(self, a, b, ("query_qualities",)) # reset qual - b = self.buildRead() + b = self.build_read() # check flags: for x in ( @@ -151,25 +158,27 @@ def testUpdate2(self): This does not work as setting the sequence will erase the quality scores. ''' - a = self.buildRead() + a = self.build_read() a.query_sequence = a.query_sequence[5:10] - self.assertEqual(pysam.qualities_to_qualitystring(a.query_qualities), None) + self.assertEqual(pysam.qualities_to_qualitystring( + a.query_qualities), None) - a = self.buildRead() + a = self.build_read() s = pysam.qualities_to_qualitystring(a.query_qualities) a.query_sequence = a.query_sequence[5:10] a.query_qualities = pysam.qualitystring_to_array(s[5:10]) - self.assertEqual(pysam.qualities_to_qualitystring(a.query_qualities), s[5:10]) + self.assertEqual(pysam.qualities_to_qualitystring( + a.query_qualities), s[5:10]) def testLargeRead(self): '''build an example read.''' a = pysam.AlignedSegment() a.query_name = "read_12345" - a.query_sequence = "ACGT" * 200 + a.query_sequence = "ATGC" * 200 a.flag = 0 - a.reference_id = 0 + a.reference_id = -1 a.reference_start = 20 a.mapping_quality = 20 a.cigartuples = ((0, 4 * 200), ) @@ -182,14 +191,14 @@ def testLargeRead(self): def testUpdateTlen(self): '''check if updating tlen works''' - a = self.buildRead() + a = self.build_read() oldlen = a.template_length oldlen *= 2 a.template_length = oldlen self.assertEqual(a.template_length, oldlen) def testPositions(self): - a = self.buildRead() + a = self.build_read() self.assertEqual(a.get_reference_positions(), [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 34, 35, 36, 37, 38, 39, @@ -220,37 +229,67 @@ def testPositions(self): def testFullReferencePositions(self): '''see issue 26''' - a = self.buildRead() + a = self.build_read() a.cigar = [(4, 30), (0, 20), (1, 3), (0, 47)] self.assertEqual(100, len(a.get_reference_positions(full_length=True))) def testBlocks(self): - a = self.buildRead() + a = self.build_read() self.assertEqual(a.get_blocks(), [(20, 30), (31, 40), (40, 60)]) def test_infer_query_length(self): '''Test infer_query_length on M|=|X|I|D|H|S cigar ops''' - a = self.buildRead() - a.cigarstring = '15M' - self.assertEqual(a.infer_query_length(), 15) - a.cigarstring = '15=' - self.assertEqual(a.infer_query_length(), 15) - a.cigarstring = '15X' - self.assertEqual(a.infer_query_length(), 15) - a.cigarstring = '5M5I5M' - self.assertEqual(a.infer_query_length(), 15) - a.cigarstring = '5M5D5M' - self.assertEqual(a.infer_query_length(), 10) - a.cigarstring = '5H10M' - self.assertEqual(a.infer_query_length(), 15) - a.cigarstring = '5S10M' - self.assertEqual(a.infer_query_length(), 15) + a = self.build_read() + a.cigarstring = '40M' + self.assertEqual(a.infer_query_length(), 40) + a.cigarstring = '40=' + self.assertEqual(a.infer_query_length(), 40) + a.cigarstring = '40X' + self.assertEqual(a.infer_query_length(), 40) + a.cigarstring = '20M5I20M' + self.assertEqual(a.infer_query_length(), 45) + a.cigarstring = '20M5D20M' + self.assertEqual(a.infer_query_length(), 40) + a.cigarstring = '5H35M' + self.assertEqual(a.infer_query_length(), 35) + a.cigarstring = '5S35M' + self.assertEqual(a.infer_query_length(), 40) + a.cigarstring = '35M5H' + self.assertEqual(a.infer_query_length(), 35) + a.cigarstring = '35M5S' + self.assertEqual(a.infer_query_length(), 40) + a.cigarstring = None + self.assertEqual(a.infer_query_length(), None) + + def test_infer_read_length(self): + '''Test infer_read_length on M|=|X|I|D|H|S cigar ops''' + a = self.build_read() + a.cigarstring = '40M' + self.assertEqual(a.infer_read_length(), 40) + a.cigarstring = '40=' + self.assertEqual(a.infer_read_length(), 40) + a.cigarstring = '40X' + self.assertEqual(a.infer_read_length(), 40) + a.cigarstring = '20M5I20M' + self.assertEqual(a.infer_read_length(), 45) + a.cigarstring = '20M5D20M' + self.assertEqual(a.infer_read_length(), 40) + a.cigarstring = '5H35M' + self.assertEqual(a.infer_read_length(), 40) + a.cigarstring = '5S35M' + self.assertEqual(a.infer_read_length(), 40) + a.cigarstring = '35M5H' + self.assertEqual(a.infer_read_length(), 40) + a.cigarstring = '35M5S' + self.assertEqual(a.infer_read_length(), 40) + a.cigarstring = None + self.assertEqual(a.infer_read_length(), None) def test_get_aligned_pairs_soft_clipping(self): - a = self.buildRead() + a = self.build_read() a.cigartuples = ((4, 2), (0, 35), (4, 3)) self.assertEqual(a.get_aligned_pairs(), [(0, None), (1, None)] + @@ -266,7 +305,7 @@ def test_get_aligned_pairs_soft_clipping(self): ) def test_get_aligned_pairs_hard_clipping(self): - a = self.buildRead() + a = self.build_read() a.cigartuples = ((5, 2), (0, 35), (5, 3)) self.assertEqual(a.get_aligned_pairs(), # No seq, no seq pos @@ -277,7 +316,7 @@ def test_get_aligned_pairs_hard_clipping(self): range(0, 0 + 35), range(20, 20 + 35))]) def test_get_aligned_pairs_skip(self): - a = self.buildRead() + a = self.build_read() a.cigarstring = "2M100D38M" self.assertEqual(a.get_aligned_pairs(), [(0, 20), (1, 21)] + @@ -293,7 +332,7 @@ def test_get_aligned_pairs_skip(self): range(20 + 2 + 100, 20 + 2 + 100 + 38))]) def test_get_aligned_pairs_match_mismatch(self): - a = self.buildRead() + a = self.build_read() a.cigartuples = ((7, 20), (8, 20)) self.assertEqual(a.get_aligned_pairs(), [(qpos, refpos) for (qpos, refpos) in zip( @@ -303,7 +342,7 @@ def test_get_aligned_pairs_match_mismatch(self): range(0, 0 + 40), range(20, 20 + 40))]) def test_get_aligned_pairs_padding(self): - a = self.buildRead() + a = self.build_read() a.cigartuples = ((7, 20), (6, 1), (8, 19)) def inner(): @@ -312,7 +351,7 @@ def inner(): self.assertRaises(NotImplementedError, inner) def test_get_aligned_pairs(self): - a = self.buildRead() + a = self.build_read() a.query_sequence = "A" * 9 a.cigarstring = "9M" a.set_tag("MD", "9") @@ -337,7 +376,7 @@ def test_get_aligned_pairs(self): (3, 23, 'A'), (4, 24, 'c'), (None, 25, 'T'), (None, 26, 'T'), (5, 27, 'A'), (6, 28, 'A'), (7, 29, 'A'), (8, 30, 'A')] - ) + ) a.cigarstring = "5M2D2I2M" a.set_tag("MD", "4C^TT2") @@ -348,10 +387,23 @@ def test_get_aligned_pairs(self): (None, 25, 'T'), (None, 26, 'T'), (5, None, None), (6, None, None), (7, 27, 'A'), (8, 28, 'A')] - ) + ) + + def test_get_aligned_pairs_with_malformed_MD_tag(self): + + a = self.build_read() + a.query_sequence = "A" * 9 + + # out of range issue, see issue #560 + a.cigarstring = "64M2D85M2S" + a.set_tag("MD", "64^TG86A0") + self.assertRaises( + AssertionError, + a.get_aligned_pairs, + with_seq=True) def test_get_aligned_pairs_skip_reference(self): - a = self.buildRead() + a = self.build_read() a.query_sequence = "A" * 10 a.cigarstring = "5M1N5M" a.set_tag("MD", "10") @@ -382,35 +434,234 @@ def testNoSequence(self): '''issue 176: retrieving length without query sequence with soft-clipping. ''' - a = self.buildRead() + a = self.build_read() a.query_sequence = None a.cigarstring = "20M" self.assertEqual(a.query_alignment_length, 20) a.cigarstring = "20M1S" self.assertEqual(a.query_alignment_length, 20) + a.cigarstring = "20M1H" + self.assertEqual(a.query_alignment_length, 20) a.cigarstring = "1S20M" self.assertEqual(a.query_alignment_length, 20) + a.cigarstring = "1H20M" + self.assertEqual(a.query_alignment_length, 20) a.cigarstring = "1S20M1S" self.assertEqual(a.query_alignment_length, 20) + a.cigarstring = "1H20M1H" + self.assertEqual(a.query_alignment_length, 20) def test_query_length_is_limited(self): - - a = self.buildRead() + a = self.build_read() a.query_name = "A" * 1 - a.query_name = "A" * 254 + a.query_name = "A" * 251 self.assertRaises( ValueError, setattr, a, "query_name", - "A" * 255) + "A" * 252) + + def test_header_accessible(self): + a = self.build_read() + self.assertTrue(isinstance(a.header, pysam.AlignmentHeader)) + + def test_bin_values_for_unmapped_reads_ignore_length(self): + a = self.build_read() + # use a long read + a.cigarstring="2000000M" + self.assertEqual(a.bin, 9) + # changing unmapped flag changes bin because length is 0 + a.is_unmapped = True + self.assertTrue(a.is_unmapped) + self.assertEqual(a.bin, 4681) + + # unmapped read without chromosomal location + a.reference_start = -1 + self.assertEqual(a.reference_start, -1) + self.assertEqual(a.bin, 4680) + + def test_bin_values_for_mapped_reads_are_updated(self): + a = self.build_read() + a.pos = 20000 + self.assertFalse(a.is_unmapped) + self.assertEqual(a.bin, 4682) + + # updating length updates bin + a.cigarstring="2000000M" + self.assertEqual(a.bin, 9) + + # updating length updates bin + a.cigarstring="20M" + self.assertEqual(a.bin, 4682) + + # updating length updates bin + a.reference_start = 2000000 + self.assertEqual(a.bin, 4803) + + +class TestTidMapping(ReadTest): + + def test_reference_name_can_be_set_to_none(self): + a = self.build_read() + a.reference_name = None + self.assertEqual(a.reference_name, None) + self.assertEqual(a.reference_id, -1) + + def test_reference_name_can_be_set_to_asterisk(self): + a = self.build_read() + a.reference_name = "*" + self.assertEqual(a.reference_name, None) + self.assertEqual(a.reference_id, -1) + + def test_reference_name_can_be_set_to_chromosome(self): + a = self.build_read() + a.reference_name = "chr1" + self.assertEqual(a.reference_name, "chr1") + self.assertEqual(a.reference_id, 0) + + def test_reference_name_can_not_be_set_to_unknown_chromosome(self): + a = self.build_read() + self.assertRaises(ValueError, + setattr, + a, + "reference_name", + "chrX") + + def test_tid_can_be_set_to_missing(self): + a = self.build_read() + a.reference_id = -1 + self.assertEqual(a.reference_id, -1) + self.assertEqual(a.reference_name, None) + + def test_tid_can_be_set_to_missing_without_header(self): + a = pysam.AlignedSegment() + a.reference_id = -1 + self.assertEqual(a.reference_id, -1) + self.assertEqual(a.reference_name, None) + + def test_tid_can_be_set_without_header(self): + a = pysam.AlignedSegment() + a.reference_id = 1 + self.assertRaises(ValueError, getattr, a, "reference_name") + + def test_tid_can_be_set_to_chromosome(self): + a = self.build_read() + a.reference_id = 0 + self.assertEqual(a.reference_id, 0) + self.assertEqual(a.reference_name, "chr1") + + def test_tid_can_not_be_set_to_unknown_chromosome(self): + a = self.build_read() + self.assertRaises(ValueError, + setattr, + a, + "reference_id", + 2) + + def test_unmapped_tid_is_asterisk_in_output(self): + a = self.build_read() + a.reference_id = -1 + self.assertEqual(a.to_string().split("\t")[2], "*") + + +class TestNextTidMapping(ReadTest): + + def test_next_reference_name_can_be_set_to_none(self): + a = self.build_read() + a.next_reference_name = None + self.assertEqual(a.next_reference_name, None) + self.assertEqual(a.next_reference_id, -1) + + def test_next_reference_name_can_be_set_to_asterisk(self): + a = self.build_read() + a.next_reference_name = "*" + self.assertEqual(a.next_reference_name, None) + self.assertEqual(a.next_reference_id, -1) + + def test_next_reference_name_can_be_set_to_chromosome(self): + a = self.build_read() + a.next_reference_name = "chr1" + self.assertEqual(a.next_reference_name, "chr1") + self.assertEqual(a.next_reference_id, 0) + + def test_next_reference_name_can_not_be_set_to_unknown_chromosome(self): + a = self.build_read() + self.assertRaises(ValueError, + setattr, + a, + "next_reference_name", + "chrX") + + def test_next_tid_can_be_set_to_missing(self): + a = self.build_read() + a.next_reference_id = -1 + self.assertEqual(a.next_reference_id, -1) + self.assertEqual(a.next_reference_name, None) + + def test_next_tid_can_be_set_to_equal(self): + a = self.build_read() + a.reference_name = "chr1" + a.next_reference_name = "=" + self.assertEqual(a.next_reference_id, a.reference_id) + self.assertEqual(a.next_reference_name, a.reference_name) + self.assertEqual(a.to_string().split("\t")[6], "=") + + def test_next_tid_can_be_set_to_missing_without_header(self): + a = pysam.AlignedSegment() + a.next_reference_id = -1 + self.assertEqual(a.next_reference_id, -1) + self.assertEqual(a.next_reference_name, None) + + def test_next_tid_can_be_set_without_header(self): + a = pysam.AlignedSegment() + a.next_reference_id = 1 + self.assertRaises(ValueError, getattr, a, "next_reference_name") + + def test_next_tid_can_be_set_to_chromosome(self): + a = self.build_read() + a.next_reference_id = 0 + self.assertEqual(a.next_reference_id, 0) + self.assertEqual(a.next_reference_name, "chr1") + + def test_next_tid_can_not_be_set_to_unknown_chromosome(self): + a = self.build_read() + self.assertRaises(ValueError, + setattr, + a, + "next_reference_id", + 2) + + def test_next_unmapped_tid_is_asterisk_in_output(self): + a = self.build_read() + a.next_reference_id = -1 + self.assertEqual(a.to_string().split("\t")[6], "*") + + +class TestCigar(ReadTest): + + def testCigarString(self): + r = self.build_read() + self.assertEqual(r.cigarstring, "10M1D9M1I20M") + r.cigarstring = "20M10D20M" + self.assertEqual(r.cigartuples, [(0, 20), (2, 10), (0, 20)]) + # unsetting cigar string + r.cigarstring = None + self.assertEqual(r.cigarstring, None) + + def testCigar(self): + r = self.build_read() + self.assertEqual( + r.cigartuples, [(0, 10), (2, 1), (0, 9), (1, 1), (0, 20)]) + # unsetting cigar string + r.cigartuples = None + self.assertEqual(r.cigartuples, None) class TestCigarStats(ReadTest): - + def testStats(self): - - a = self.buildRead() + a = self.build_read() a.cigarstring = None self.assertEqual( @@ -454,7 +705,7 @@ def testStats(self): class TestAlignedPairs(unittest.TestCase): - filename = os.path.join(DATADIR, "example_aligned_pairs.bam") + filename = os.path.join(BAM_DATADIR, "example_aligned_pairs.bam") def testReferenceBases(self): """reference bases should always be the same nucleotide @@ -476,15 +727,15 @@ def testReferenceBases(self): class TestTags(ReadTest): def testMissingTag(self): - a = self.buildRead() + a = self.build_read() self.assertRaises(KeyError, a.get_tag, "XP") def testEmptyTag(self): - a = self.buildRead() + a = self.build_read() self.assertRaises(KeyError, a.get_tag, "XT") def testSetTag(self): - a = self.buildRead() + a = self.build_read() self.assertEqual(False, a.has_tag("NM")) a.set_tag("NM", 2) self.assertEqual(True, a.has_tag("NM")) @@ -498,7 +749,7 @@ def testSetTag(self): a.set_tag("NM", None) def testArrayTags(self): - read = self.buildRead() + read = self.build_read() supported_dtypes = "bhBHf" unsupported_dtypes = "lLd" @@ -513,9 +764,9 @@ def testArrayTags(self): read.set_tag, key, array.array(dtype, range(10))) - + def testAddTagsType(self): - a = self.buildRead() + a = self.build_read() a.tags = None self.assertEqual(a.tags, []) @@ -547,10 +798,10 @@ def testAddTagsType(self): ('X5', 5)])) # test setting invalid type code - self.assertRaises(ValueError, a.setTag, 'X6', 5.2, 'g') + self.assertRaises(ValueError, a.set_tag, 'X6', 5.2, 'g') def testTagsUpdatingFloat(self): - a = self.buildRead() + a = self.build_read() a.tags = [('NM', 1), ('RG', 'L1'), ('PG', 'P1'), ('XT', 'U')] @@ -563,7 +814,7 @@ def testTagsUpdatingFloat(self): ('PG', 'P1'), ('XT', 'U'), ('XC', 5.0)]) def testAddTags(self): - a = self.buildRead() + a = self.build_read() a.tags = [('NM', 1), ('RG', 'L1'), ('PG', 'P1'), ('XT', 'U')] @@ -601,7 +852,7 @@ def testTagParsing(self): see http://groups.google.com/group/pysam-user-group/browse_thread/thread/67ca204059ea465a ''' samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex8.bam"), + os.path.join(BAM_DATADIR, "ex8.bam"), "rb") for entry in samfile: @@ -611,7 +862,7 @@ def testTagParsing(self): self.assertEqual(after, before) def testMDTagMatchOnly(self): - a = self.buildRead() + a = self.build_read() # Substitutions only a.cigarstring = "21M" @@ -636,7 +887,7 @@ def testMDTagMatchOnly(self): a.get_reference_sequence()) def testMDTagInsertions(self): - a = self.buildRead() + a = self.build_read() # insertions are silent in the reference sequence a.cigarstring = "5M1I5M" @@ -659,7 +910,7 @@ def testMDTagInsertions(self): "A" * 10) def testMDTagDeletions(self): - a = self.buildRead() + a = self.build_read() a.cigarstring = "5M1D5M" a.query_sequence = "A" * 10 @@ -676,7 +927,7 @@ def testMDTagDeletions(self): a.get_reference_sequence()) def testMDTagRefSkipping(self): - a = self.buildRead() + a = self.build_read() a.cigarstring = "5M1N5M" a.query_sequence = "A" * 10 @@ -693,7 +944,7 @@ def testMDTagRefSkipping(self): a.get_reference_sequence()) def testMDTagSoftClipping(self): - a = self.buildRead() + a = self.build_read() # softclipping a.cigarstring = "5S5M1D5M5S" @@ -712,7 +963,7 @@ def testMDTagSoftClipping(self): a.get_reference_sequence()) def testMDTagComplex(self): - a = self.buildRead() + a = self.build_read() a.cigarstring = "5S5M1I2D5M5S" a.query_sequence = "G" * 5 + "A" * 11 + "G" * 5 @@ -745,11 +996,79 @@ def testMDTagComplex(self): "AAAAcTTAA", a.get_reference_sequence()) + def testArrayTags(self): + + r = self.build_read() + + def c(r, l): + r.tags = [('ZM', l)] + self.assertEqual(list(r.opt("ZM")), list(l)) + + # signed integers + c(r, (-1, 1)) + c(r, (-1, 100)) + c(r, (-1, 200)) + c(r, (-1, 1000)) + c(r, (-1, 30000)) + c(r, (-1, 50000)) + c(r, (1, -1)) + c(r, (1, -100)) + c(r, (1, -200)) + c(r, (1, -1000)) + c(r, (1, -30000)) + c(r, (1, -50000)) + + # unsigned integers + c(r, (1, 100)) + c(r, (1, 1000)) + c(r, (1, 10000)) + c(r, (1, 100000)) + + # floats + c(r, (1.0, 100.0)) + + def testLongTags(self): + '''see issue 115''' + + r = self.build_read() + rg = 'HS2000-899_199.L3' + tags = [('XC', 85), ('XT', 'M'), ('NM', 5), + ('SM', 29), ('AM', 29), ('XM', 1), + ('XO', 1), ('XG', 4), ('MD', '37^ACCC29T18'), + ('XA', '5,+11707,36M1I48M,2;21,-48119779,46M1I38M,2;hs37d5,-10060835,40M1D45M,3;5,+11508,36M1I48M,3;hs37d5,+6743812,36M1I48M,3;19,-59118894,46M1I38M,3;4,-191044002,6M1I78M,3;')] # noqa + + r.tags = tags + r.tags += [("RG", rg)] * 100 + tags += [("RG", rg)] * 100 + + self.assertEqual(tags, r.tags) + + def testNegativeIntegers(self): + x = -2 + aligned_read = self.build_read() + aligned_read.tags = [("XD", int(x))] + self.assertEqual(aligned_read.opt('XD'), x) + # print (aligned_read.tags) + + def testNegativeIntegersWrittenToFile(self): + r = self.build_read() + x = -2 + r.tags = [("XD", x)] + with get_temp_context("negative_integers.bam") as fn: + with pysam.AlignmentFile(fn, + "wb", + referencenames=("chr1",), + referencelengths=(1000,)) as outf: + outf.write(r) + with pysam.AlignmentFile(fn) as inf: + r = next(inf) + self.assertEqual(r.tags, [("XD", x)]) + class TestCopy(ReadTest): def testCopy(self): - a = self.buildRead() + a = self.build_read() b = copy.copy(a) # check if a and be are the same self.assertEqual(a, b) @@ -761,7 +1080,7 @@ def testCopy(self): self.assertEqual(b.query_name, 'ReadB') def testDeepCopy(self): - a = self.buildRead() + a = self.build_read() b = copy.deepcopy(a) # check if a and be are the same self.assertEqual(a, b) @@ -773,17 +1092,257 @@ def testDeepCopy(self): self.assertEqual(b.query_name, 'ReadB') -class TestAsString(unittest.TestCase): +class TestSetTagGetTag(ReadTest): + + def check_tag(self, tag, value, value_type, alt_value_type=None): + a = self.build_read() + a.set_tag(tag, value, value_type=value_type) + v, t = a.get_tag(tag, with_value_type=True) + self.assertEqual(v, value) + + if alt_value_type: + self.assertEqual(t, alt_value_type) + else: + self.assertEqual(t, value_type) + + def test_set_tag_with_A(self): + self.check_tag('TT', "x", value_type="A") + + def test_set_tag_with_a(self): + self.check_tag('TT', "x", value_type="a", alt_value_type="A") + + def test_set_tag_with_C(self): + self.check_tag('TT', 12, value_type="C") + + def test_set_tag_with_c(self): + self.check_tag('TT', 12, value_type="c") + + def test_set_tag_with_S(self): + self.check_tag('TT', 12, value_type="S") + + def test_set_tag_with_s(self): + self.check_tag('TT', 12, value_type="s") + + def test_set_tag_with_I(self): + self.check_tag('TT', 12, value_type="I") + + def test_set_tag_with_i(self): + self.check_tag('TT', 12, value_type="i") + + def test_set_tag_with_f(self): + self.check_tag('TT', 2.5, value_type="f") + + def test_set_tag_with_d(self): + self.check_tag('TT', 2.5, value_type="d") + + def test_set_tag_with_H(self): + self.check_tag('TT', "AE12", value_type="H") + + def test_set_tag_with_automated_type_detection(self): + self.check_tag('TT', -(1 << 7), value_type=None, alt_value_type="c") + self.check_tag('TT', -(1 << 7) - 1, + value_type=None, alt_value_type="s") + self.check_tag('TT', -(1 << 15), value_type=None, alt_value_type="s") + self.check_tag('TT', -(1 << 15) - 1, + value_type=None, alt_value_type="i") + self.check_tag('TT', -(1 << 31), value_type=None, alt_value_type="i") + self.assertRaises( + ValueError, + self.check_tag, + 'TT', + -(1 << 31) - 1, + value_type=None, + alt_value_type="i") + + self.check_tag('TT', (1 << 8) - 1, value_type=None, alt_value_type="C") + self.check_tag('TT', (1 << 8), value_type=None, alt_value_type="S") + self.check_tag('TT', (1 << 16) - 1, + value_type=None, alt_value_type="S") + self.check_tag('TT', (1 << 16), value_type=None, alt_value_type="I") + self.check_tag('TT', (1 << 32) - 1, + value_type=None, alt_value_type="I") + self.assertRaises( + ValueError, + self.check_tag, + 'TT', + (1 << 32), + value_type=None, + alt_value_type="I") + + +class TestSetTagsGetTag(TestSetTagGetTag): + + def check_tag(self, tag, value, value_type, alt_value_type=None): + a = self.build_read() + a.set_tags([(tag, value, value_type)]) + v, t = a.get_tag(tag, with_value_type=True) + if alt_value_type: + self.assertEqual(t, alt_value_type) + else: + self.assertEqual(t, value_type) + self.assertEqual(v, value) + + +class TestEnums(unittest.TestCase): + + def test_cigar_enums_are_defined(self): + self.assertEqual(pysam.CMATCH, 0) + self.assertEqual(pysam.CINS, 1) + self.assertEqual(pysam.CDEL, 2) + self.assertEqual(pysam.CREF_SKIP, 3) + self.assertEqual(pysam.CSOFT_CLIP, 4) + self.assertEqual(pysam.CHARD_CLIP, 5) + self.assertEqual(pysam.CPAD, 6) + self.assertEqual(pysam.CEQUAL, 7) + self.assertEqual(pysam.CDIFF, 8) + self.assertEqual(pysam.CBACK, 9) + + def test_sam_flags_are_defined(self): + self.assertEqual(pysam.FPAIRED, 1) + self.assertEqual(pysam.FPROPER_PAIR, 2) + self.assertEqual(pysam.FUNMAP, 4) + self.assertEqual(pysam.FMUNMAP, 8) + self.assertEqual(pysam.FREVERSE, 16) + self.assertEqual(pysam.FMREVERSE, 32) + self.assertEqual(pysam.FREAD1, 64) + self.assertEqual(pysam.FREAD2, 128) + self.assertEqual(pysam.FSECONDARY, 256) + self.assertEqual(pysam.FQCFAIL, 512) + self.assertEqual(pysam.FDUP, 1024) + self.assertEqual(pysam.FSUPPLEMENTARY, 2048) + + +class TestBuildingReadsWithoutHeader(unittest.TestCase): + + def build_read(self): + '''build an example read, but without header information.''' + + a = pysam.AlignedSegment() + a.query_name = "read_12345" + a.query_sequence = "ATGC" * 10 + a.flag = 0 + a.reference_id = -1 + a.reference_start = 20 + a.mapping_quality = 20 + a.cigartuples = ((0, 10), (2, 1), (0, 9), (1, 1), (0, 20)) + a.next_reference_id = 0 + a.next_reference_start = 200 + a.template_length = 167 + a.query_qualities = pysam.qualitystring_to_array("1234") * 10 + # todo: create tags + return a + + def test_read_can_be_constructed_without_header(self): + read = self.build_read() + self.assertEqual(read.query_name, "read_12345") + + def test_reference_id_can_be_set(self): + read = self.build_read() + read.reference_id = 2 + self.assertEqual(read.reference_id, 2) + + def test_reference_name_is_not_available(self): + read = self.build_read() + self.assertRaises( + ValueError, + setattr, + read, + "reference_name", + "chr2") + + def test_read_can_be_written_to_file(self): + tmpfilename = get_temp_filename(".bam") + with pysam.AlignmentFile(tmpfilename, "wb", + reference_names=["chr1", "chr2", "chr3"], + reference_lengths=[1000, 2000, 3000]) as outf: + read = self.build_read() + read.reference_id = 2 + outf.write(read) + + stdout = pysam.samtools.view(tmpfilename) + chromosome = stdout.split("\t")[2] + self.assertEqual(chromosome, "chr3") + os.unlink(tmpfilename) + + +class TestForwardStrandValues(ReadTest): + + def test_sequence_is_complemented(self): + a = self.build_read() + a.is_reverse = False + fwd_seq = a.query_sequence + + rev_seq = fwd_seq.translate(maketrans("ACGTacgtNnXx", "TGCAtgcaNnXx"))[::-1] + self.assertEqual(fwd_seq, a.get_forward_sequence()) + a.is_reverse = True + self.assertEqual(fwd_seq, a.query_sequence) + self.assertEqual(rev_seq, a.get_forward_sequence()) + + def test_qualities_are_complemented(self): + a = self.build_read() + a.is_reverse = False + fwd_qual = a.query_qualities + rev_qual = fwd_qual[::-1] + self.assertEqual(fwd_qual, a.get_forward_qualities()) + a.is_reverse = True + self.assertEqual(fwd_qual, a.query_qualities) + self.assertEqual(rev_qual, a.get_forward_qualities()) + + +class TestExportImport(ReadTest): + + def test_string_export(self): + a = self.build_read() + self.assertEqual(a.to_string(), + "read_12345\t0\tchr1\t21\t20\t10M1D9M1I20M\t=\t201\t167\t" + "ATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC\t1234123412341234123412341234123412341234") + + def test_string_export_import_without_tags(self): + a = self.build_read() + a.tags = [] + b = pysam.AlignedSegment.fromstring(a.to_string(), a.header) + self.assertEqual(a, b) - def testAsString(self): - with open(os.path.join(DATADIR, "ex2.sam")) as samf: + def test_string_export_import_with_tags(self): + a = self.build_read() + a.tags = [("XD", 12), ("RF", "abc")] + b = pysam.AlignedSegment.fromstring(a.to_string(), a.header) + self.assertEqual(a, b) + + def test_to_string_without_alignment_file(self): + with open(os.path.join(BAM_DATADIR, "ex2.sam")) as samf: reference = [x[:-1] for x in samf if not x.startswith("@")] with pysam.AlignmentFile( - os.path.join(DATADIR, "ex2.bam"), "r") as pysamf: + os.path.join(BAM_DATADIR, "ex2.bam"), "r") as pysamf: for s, p in zip(reference, pysamf): - self.assertEqual(s, p.tostring(pysamf)) - + self.assertEqual(s, p.to_string()) + + def test_dict_export(self): + a = self.build_read() + a.tags = [("XD", 12), ("RF", "abc")] + + self.assertEqual( + a.to_dict(), + json.loads( + '{"name": "read_12345", "flag": "0", "ref_name": "chr1", "ref_pos": "21", ' + '"map_quality": "20", "cigar": "10M1D9M1I20M", "next_ref_name": "=", ' + '"next_ref_pos": "201", "length": "167", ' + '"seq": "ATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC", ' + '"qual": "1234123412341234123412341234123412341234", "tags": ["XD:i:12", "RF:Z:abc"]}')) + + def test_string_export_import_without_tags(self): + a = self.build_read() + a.tags = [] + b = pysam.AlignedSegment.from_dict(a.to_dict(), a.header) + self.assertEqual(a, b) + def test_string_export_import_with_tags(self): + a = self.build_read() + a.tags = [("XD", 12), ("RF", "abc")] + b = pysam.AlignedSegment.from_dict(a.to_dict(), a.header) + self.assertEqual(a, b) + + if __name__ == "__main__": unittest.main() diff --git a/tests/AlignmentFileFetchTestUtils.py b/tests/AlignmentFileFetchTestUtils.py new file mode 100644 index 000000000..100b40520 --- /dev/null +++ b/tests/AlignmentFileFetchTestUtils.py @@ -0,0 +1,86 @@ +import os +import subprocess +import pysam + +from TestUtils import BAM_DATADIR, force_str + +def build_fetch_with_samtoolsshell(fn): + retval = os.popen("samtools view {} 2> /dev/null | wc -l".format(fn)).read() + return int(retval.strip()) + + +def build_fetch_with_samtoolspipe(fn): + FNULL = open(os.devnull, 'w') + with subprocess.Popen(["samtools", "view", fn], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=FNULL) as proc: + return len(proc.stdout.readlines()) + + +def build_fetch_with_pysam(*args, **kwargs): + with pysam.AlignmentFile(*args, **kwargs) as inf: + return len(list(inf.fetch())) + + +def build_query_sequences_with_samtoolsshell(fn): + retval = os.popen("samtools view {} 2> /dev/null | cut -f 11".format(fn)).read() + return force_str(retval).splitlines() + + +def build_query_sequences_with_samtoolspipe(fn): + FNULL = open(os.devnull, 'w') + with subprocess.Popen(["samtools", "view", fn], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=FNULL) as proc: + data = [force_str(x).split()[10] for x in proc.stdout.readlines()] + return data + + +def build_query_sequences_with_pysam(*args, **kwargs): + with pysam.AlignmentFile(*args, **kwargs) as inf: + data = [x.query_sequence for x in inf] + return data + + +def build_query_qualities_with_pysam(*args, **kwargs): + with pysam.AlignmentFile(*args, **kwargs) as inf: + data = [x.query_qualities for x in inf] + return data + + +def build_query_sequences_flagfilter_with_samtoolsshell(fn): + retval = os.popen("samtools view -f 2 {} 2> /dev/null | cut -f 11".format(fn)).read() + return force_str(retval).splitlines() + + +def build_query_sequences_flagfilter_with_samtoolspipe(fn): + FNULL = open(os.devnull, 'w') + with subprocess.Popen(["samtools", "view", "-f", "2", fn], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=FNULL) as proc: + data = [force_str(x).split()[10] for x in proc.stdout.readlines()] + return data + +def build_query_sequences_flagfilter_with_pysam(*args, **kwargs): + with pysam.AlignmentFile(*args, **kwargs) as inf: + data = [x.query_sequence for x in inf if x.is_proper_pair] + return data + + +def build_query_sequences_directflagfilter_with_pysam(*args, **kwargs): + with pysam.AlignmentFile(*args, **kwargs) as inf: + data = [x.query_sequence for x in inf if x.flag & 2] + return data + + +def build_aligned_pairs_with_pysam(*args, **kwargs): + matches_only = kwargs.pop("matches_only", False) + with_seq = kwargs.pop("with_seq", False) + with pysam.AlignmentFile(*args, **kwargs) as inf: + data = [x.get_aligned_pairs(matches_only=matches_only, with_seq=with_seq) + for x in inf if not x.is_unmapped] + return data + diff --git a/tests/AlignmentFileFetch_bench.py b/tests/AlignmentFileFetch_bench.py new file mode 100644 index 000000000..bb8ce43f4 --- /dev/null +++ b/tests/AlignmentFileFetch_bench.py @@ -0,0 +1,98 @@ +"""Benchmarking module for AlignmentFile functionality""" +import os +import pytest + + +from TestUtils import BAM_DATADIR, force_str, flatten_nested_list +from AlignmentFileFetchTestUtils import * + + +def test_build_fetch_from_bam_with_samtoolsshell(benchmark): + result = benchmark(build_fetch_with_samtoolsshell, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert result == 3270 + + +def test_build_fetch_from_bam_with_samtoolspipe(benchmark): + result = benchmark(build_fetch_with_samtoolspipe, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert result == 3270 + + +def test_build_fetch_from_bam_with_pysam(benchmark): + result = benchmark(build_fetch_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert result == 3270 + + +def test_build_query_sequences_from_bam_with_samtoolsshell(benchmark): + result = benchmark(build_query_sequences_with_samtoolsshell, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len(result) == 3270 + + +def test_build_query_sequences_from_bam_with_samtoolspipe(benchmark): + result = benchmark(build_query_sequences_with_samtoolspipe, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len(result) == 3270 + + +def test_build_query_sequences_from_bam_with_pysam(benchmark): + result = benchmark(build_query_sequences_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len(result) == 3270 + + +def test_build_query_qualities_from_bam_with_pysam(benchmark): + result = benchmark(build_query_qualities_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len(result) == 3270 + + +def test_build_query_sequences_from_bam_flagfilter_with_samtoolsshell(benchmark): + result = benchmark(build_query_sequences_flagfilter_with_samtoolsshell, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len(result) == 3124 + + +def test_build_query_sequences_from_bam_flagfilter_with_samtoolspipe(benchmark): + result = benchmark(build_query_sequences_flagfilter_with_samtoolspipe, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len(result) == 3124 + + +def test_build_query_sequences_from_bam_flagfilter_with_pysam(benchmark): + result = benchmark(build_query_sequences_flagfilter_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len(result) == 3124 + + +def test_build_query_sequences_from_bam_directflagfilter_with_pysam(benchmark): + result = benchmark(build_query_sequences_flagfilter_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len(result) == 3124 + + +@pytest.mark.aligned_pairs +def test_build_aligned_pairs_default_with_pysam(benchmark): + result = benchmark(build_aligned_pairs_with_pysam, + os.path.join(BAM_DATADIR, "with_md.bam")) + assert len(result) == 3235 + + +@pytest.mark.aligned_pairs +def test_build_aligned_pairs_matchesonly_with_pysam(benchmark): + result = benchmark(build_aligned_pairs_with_pysam, + os.path.join(BAM_DATADIR, "with_md.bam"), + matches_only=True) + assert len(result) == 3235 + + +@pytest.mark.aligned_pairs +def test_build_aligned_pairs_withseq_with_pysam(benchmark): + result = benchmark(build_aligned_pairs_with_pysam, + os.path.join(BAM_DATADIR, "with_md.bam"), + with_seq=True) + assert len(result) == 3235 + + diff --git a/tests/AlignmentFileHeader_test.py b/tests/AlignmentFileHeader_test.py new file mode 100644 index 000000000..1cf733e0e --- /dev/null +++ b/tests/AlignmentFileHeader_test.py @@ -0,0 +1,316 @@ +#!/usr/bin/env python +'''unit testing code for pysam. + +Execute in the :file:`tests` directory as it requires the Makefile +and data files located there. +''' + +import unittest +import os +import sys +import re +import copy +from collections import OrderedDict as odict +import pysam +import pysam.samtools +from TestUtils import get_temp_filename, BAM_DATADIR + +if sys.version_info.major >= 3: + from io import StringIO +else: + from StringIO import StringIO + + +class TestHeaderConstruction(unittest.TestCase): + """testing header construction.""" + + header_dict = odict( + [('SQ', [odict([('LN', 1575), ('SN', 'chr1'), ('AH', 'chr1:5000000-5010000')]), + odict([('LN', 1584), ('SN', 'chr2'), ('AH', '*')])]), + ('RG', [odict([('LB', 'SC_1'), ('ID', 'L1'), ('SM', 'NA12891'), + ('PU', 'SC_1_10'), ("CN", "name:with:colon")]), + odict([('LB', 'SC_2'), ('ID', 'L2'), ('SM', 'NA12891'), + ('PU', 'SC_2_12'), ("CN", "name:with:colon")])]), + ('PG', [odict([('ID', 'P1'), ('VN', '1.0')]), + odict([('ID', 'P2'), ('VN', '1.1')])]), + ('HD', odict([('VN', '1.0')])), + ('CO', ['this is a comment', 'this is another comment']), + ]) + + header_text = ("@HD\tVN:1.0\n" + "@SQ\tSN:chr1\tLN:1575\tAH:chr1:5000000-5010000\n" + "@SQ\tSN:chr2\tLN:1584\tAH:*\n" + "@RG\tID:L1\tPU:SC_1_10\tLB:SC_1\tSM:NA12891\tCN:name:with:colon\n" + "@RG\tID:L2\tPU:SC_2_12\tLB:SC_2\tSM:NA12891\tCN:name:with:colon\n" + "@PG\tID:P1\tVN:1.0\n" + "@PG\tID:P2\tVN:1.1\n" + "@CO\tthis is a comment\n" + "@CO\tthis is another comment\n") + + + header_from_references = odict( + [('SQ', [odict([('LN', 1575), ('SN', 'chr1')]), + odict([('LN', 1584), ('SN', 'chr2')])]), + ('RG', [odict([('LB', 'SC_1'), ('ID', 'L1'), ('SM', 'NA12891'), + ('PU', 'SC_1_10'), ("CN", "name:with:colon")]), + odict([('LB', 'SC_2'), ('ID', 'L2'), ('SM', 'NA12891'), + ('PU', 'SC_2_12'), ("CN", "name:with:colon")])]), + ('PG', [odict([('ID', 'P1'), ('VN', '1.0')]), + odict([('ID', 'P2'), ('VN', '1.1')])]), + ('HD', odict([('VN', '1.0')])), + ('CO', ['this is a comment', 'this is another comment']), + ]) + + header_without_text = odict( + [('SQ', [odict([('LN', 1575), ('SN', 'chr1')]), + odict([('LN', 1584), ('SN', 'chr2')])]), + ]) + + def compare_headers(self, test_header, ref_header=None): + '''compare two headers a and b.''' + test_header_dict = test_header.as_dict() + if ref_header is None: + ref_header = self.header_dict + + for ak, av in test_header_dict.items(): + self.assertTrue(ak in self.header_dict, "key '%s' not in '%s' " % (ak, ref_header)) + self.assertEqual(av, ref_header[ak]) + for ak, av in ref_header.items(): + self.assertTrue(ak in test_header_dict, "key '%s' not in '%s' " % (ak, test_header_dict)) + self.assertEqual(av, test_header_dict[ak]) + + def check_name_mapping(self, test_header): + for x, y in enumerate(("chr1", "chr2")): + tid = test_header.get_tid(y) + ref = test_header.get_reference_name(x) + self.assertEqual(tid, x) + self.assertEqual(ref, y) + + self.assertEqual(test_header.get_tid("chr?"), -1) + self.assertRaises(ValueError, test_header.get_reference_name, 2) + + def test_header_constructed_from_dict(self): + header = pysam.AlignmentHeader.from_dict(self.header_dict) + self.compare_headers(header) + self.check_name_mapping(header) + + def test_header_constructed_from_text(self): + header = pysam.AlignmentHeader.from_text(self.header_text) + self.compare_headers(header) + self.check_name_mapping(header) + + def test_header_constructed_from_header(self): + header = pysam.AlignmentHeader.from_text(self.header_text) + self.compare_headers(header.copy()) + self.check_name_mapping(header) + + def test_header_constructed_from_references(self): + text = re.sub("@SQ[^\n]+\n", "", self.header_text) + assert "@SQ" not in text + header = pysam.AlignmentHeader.from_references( + reference_names=["chr1", "chr2"], + reference_lengths=[1575, 1584], + text=text) + self.compare_headers(header, self.header_from_references) + self.check_name_mapping(header) + + def test_header_constructed_from_references_without_text(self): + header = pysam.AlignmentHeader.from_references( + reference_names=["chr1", "chr2"], + reference_lengths=[1575, 1584]) + self.compare_headers(header, self.header_without_text) + self.check_name_mapping(header) + + +class TestHeaderSAM(unittest.TestCase): + """testing header manipulation""" + + header = {'SQ': [{'LN': 1575, 'SN': 'chr1', 'AH': 'chr1:5000000-5010000'}, + {'LN': 1584, 'SN': 'chr2', 'AH': '*'}], + 'RG': [{'LB': 'SC_1', 'ID': 'L1', 'SM': 'NA12891', + 'PU': 'SC_1_10', "CN": "name:with:colon"}, + {'LB': 'SC_2', 'ID': 'L2', 'SM': 'NA12891', + 'PU': 'SC_2_12', "CN": "name:with:colon"}], + 'PG': [{'ID': 'P1', 'VN': '1.0'}, {'ID': 'P2', 'VN': '1.1'}], + 'HD': {'VN': '1.0'}, + 'CO': ['this is a comment', 'this is another comment'], + } + + def compare_headers(self, a, b): + '''compare two headers a and b.''' + for ak, av in a.items(): + self.assertTrue(ak in b, "key '%s' not in '%s' " % (ak, b)) + self.assertEqual(av, b[ak]) + + def setUp(self): + self.samfile = pysam.AlignmentFile( + os.path.join(BAM_DATADIR, "ex3.sam"), + "r") + + def test_header_content_is_as_expected(self): + self.compare_headers(self.header, self.samfile.header.to_dict()) + self.compare_headers(self.samfile.header.to_dict(), self.header) + + def test_text_access_works(self): + self.assertEqual(self.samfile.text, self.samfile.header.__str__()) + + def test_name_mapping(self): + for x, y in enumerate(("chr1", "chr2")): + tid = self.samfile.gettid(y) + ref = self.samfile.getrname(x) + self.assertEqual(tid, x) + self.assertEqual(ref, y) + + self.assertEqual(self.samfile.gettid("chr?"), -1) + self.assertRaises(ValueError, self.samfile.getrname, 2) + + def test_dictionary_access_works(self): + for key in self.header.keys(): + self.compare_headers({key: self.header[key]}, + {key: self.samfile.header[key]}) + + def test_dictionary_setting_raises_error(self): + self.assertRaises(TypeError, + self.samfile.header.__setitem__, + "CO", + ["This is a final comment"]) + + def test_dictionary_len_works(self): + self.assertEqual(len(self.header), len(self.samfile.header)) + + def test_dictionary_keys_works(self): + # sort for py2.7 + self.assertEqual(sorted(self.header.keys()), + sorted(self.samfile.header.keys())) + + def test_dictionary_values_works(self): + self.assertEqual(len(self.header.values()), len(self.samfile.header.values())) + + def test_dictionary_get_works(self): + self.assertEqual(self.header.get("HD"), {'VN': '1.0'}) + self.assertEqual(self.header.get("UK", "xyz"), "xyz") + self.assertEqual(self.header.get("UK"), None) + + def test_dictionary_contains_works(self): + self.assertTrue("HD" in self.header) + self.assertFalse("UK" in self.header) + + def tearDown(self): + self.samfile.close() + + +class TestHeaderBAM(TestHeaderSAM): + + def setUp(self): + self.samfile = pysam.AlignmentFile( + os.path.join(BAM_DATADIR, "ex3.bam"), + "rb") + + +class TestHeaderCRAM(TestHeaderSAM): + + def setUp(self): + self.samfile = pysam.AlignmentFile( + os.path.join(BAM_DATADIR, "ex3.cram"), + "rc") + + def compare_headers(self, a, b): + '''compare two headers a and b.''' + def _strip(dd): + for x in dd: + for y in ("M5", "UR"): + if y in x: + del x[y] + for ak, av in a.items(): + _strip(av) + self.assertTrue(ak in b, "key '%s' not in '%s' " % (ak, b)) + _strip(b[ak]) + + self.assertEqual(av, b[ak]) + + +class TestHeaderFromRefs(unittest.TestCase): + '''see issue 144 + + reference names need to be converted to string for python 3 + ''' + + # def testHeader( self ): + # refs = ['chr1', 'chr2'] + # tmpfile = "tmp_%i" % id(self) + # s = pysam.AlignmentFile(tmpfile, 'wb', + # referencenames=refs, + # referencelengths=[100]*len(refs)) + # s.close() + + # self.assertTrue( checkBinaryEqual( 'issue144.bam', tmpfile ), + # 'bam files differ') + # os.unlink( tmpfile ) + + + +class TestHeaderWriteRead(unittest.TestCase): + header = {'SQ': [{'LN': 1575, 'SN': 'chr1'}, + {'LN': 1584, 'SN': 'chr2'}], + 'RG': [{'LB': 'SC_1', 'ID': 'L1', 'SM': 'NA12891', + 'PU': 'SC_1_10', "CN": "name:with:colon"}, + {'LB': 'SC_2', 'ID': 'L2', 'SM': 'NA12891', + 'PU': 'SC_2_12', "CN": "name:with:colon"}], + 'PG': [{'ID': 'P1', 'VN': '1.0', 'CL': 'tool'}, + {'ID': 'P2', 'VN': '1.1', 'CL': 'tool with in option -R a\tb', + 'PP': 'P1'}], + 'HD': {'VN': '1.0'}, + 'CO': ['this is a comment', 'this is another comment'], + } + + def compare_headers(self, a, header_b): + '''compare two headers a and b. + + Ignore M5 and UR field as they are set application specific. + ''' + b = header_b.to_dict() + for ak, av in a.items(): + self.assertTrue(ak in b, "key '%s' not in '%s' " % (ak, b)) + self.assertEqual( + len(av), len(b[ak]), + "unequal number of entries for key {}: {} vs {}" + .format(ak, av, b[ak])) + + for row_a, row_b in zip(av, b[ak]): + if isinstance(row_b, dict): + for x in ["M5", "UR"]: + try: + del row_b[x] + except KeyError: + pass + self.assertEqual(row_a, row_b) + + def check_read_write(self, flag_write, header): + + fn = get_temp_filename() + with pysam.AlignmentFile( + fn, + flag_write, + header=header, + reference_filename=os.path.join(BAM_DATADIR, "ex1.fa")) as outf: + a = pysam.AlignedSegment() + a.query_name = "abc" + outf.write(a) + + with pysam.AlignmentFile(fn) as inf: + read_header = inf.header + + os.unlink(fn) + self.compare_headers(header, read_header) + + def test_SAM(self): + self.check_read_write("wh", self.header) + + def test_BAM(self): + self.check_read_write("wb", self.header) + + def test_CRAM(self): + header = copy.copy(self.header) + # for CRAM, \t needs to be quoted: + header['PG'][1]['CL'] = re.sub(r"\t", r"\\\\t", header['PG'][1]['CL']) + self.check_read_write("wc", header) diff --git a/tests/AlignmentFilePileup_bench.py b/tests/AlignmentFilePileup_bench.py new file mode 100644 index 000000000..24a06cbeb --- /dev/null +++ b/tests/AlignmentFilePileup_bench.py @@ -0,0 +1,147 @@ +"""Benchmarking module for AlignmentFile functionality""" +import os + +from TestUtils import BAM_DATADIR, force_str, flatten_nested_list +from PileupTestUtils import * + + +def test_build_pileup_from_bam_with_samtoolsshell(benchmark): + result = benchmark(build_pileup_with_samtoolsshell, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert result == 2998 + + +def test_build_pileup_from_bam_with_samtoolspipe(benchmark): + result = benchmark(build_pileup_with_samtoolspipe, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert result == 2998 + + +def test_build_pileup_from_bam_with_pysam(benchmark): + result = benchmark(build_pileup_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert result == 2998 + + +def test_build_depth_from_bam_with_samtoolsshell(benchmark): + result = benchmark(build_depth_with_samtoolsshell, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert result == 107241 + + +def test_build_depth_from_bam_with_samtoolspipe(benchmark): + result = benchmark(build_depth_with_samtoolspipe, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert sum(result) == 107241 + + +def test_build_depth_from_bam_with_pysam(benchmark): + result = benchmark(build_depth_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + # different value, as samtools filters with a minimum + # base quality of 13 + assert sum(result) == 110015 + + +def test_build_depth_with_filter_from_bam_with_pysam(benchmark): + result = benchmark(build_depth_with_filter_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert sum(result) == 107241 + + +def test_build_query_bases_from_bam_with_samtoolsshell(benchmark): + result = benchmark(build_query_bases_with_samtoolsshell, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert result == 116308 + + +def test_build_query_bases_from_bam_with_samtoolspysam(benchmark): + result = benchmark(build_query_bases_with_samtoolspysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len("".join(flatten_nested_list(result))) == 116308 + + +def test_build_query_bases_from_bam_with_samtoolspipe(benchmark): + result = benchmark(build_query_bases_with_samtoolspipe, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len("".join(flatten_nested_list(result))) == 116308 + + +def test_build_query_bases_from_bam_with_pysam_pileups(benchmark): + # note that there is no overlap detection here + result = benchmark(build_query_bases_with_pysam_pileups, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len("".join(flatten_nested_list(result))) == 107241 + + +def test_build_query_bases_from_bam_with_pysam(benchmark): + result = benchmark(build_query_bases_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len("".join(flatten_nested_list(result))) == 116308 + + +# note that pileups with/without reference sequence will differ due to +# realignment. +def test_build_query_bases_with_reference_from_bam_with_samtoolspipe(benchmark): + result = benchmark(build_query_bases_with_samtoolspipe, + os.path.join(BAM_DATADIR, "ex2.bam"), + "-f", os.path.join(BAM_DATADIR, "ex1.fa")) + assert len("".join(flatten_nested_list(result))) == 115924 + + +def test_build_query_bases_with_reference_from_bam_with_pysam(benchmark): + with pysam.FastaFile(os.path.join(BAM_DATADIR, "ex1.fa")) as fasta: + result = benchmark(build_query_bases_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam"), + fastafile=fasta) + assert len("".join(flatten_nested_list(result))) == 115924 + + +def test_build_query_bases_with_reference_from_bam_with_samtoolspysam(benchmark): + result = benchmark(build_query_bases_with_samtoolspysam, + os.path.join(BAM_DATADIR, "ex2.bam"), + "-f", os.path.join(BAM_DATADIR, "ex1.fa")) + assert len("".join(flatten_nested_list(result))) == 115924 + + +def test_build_query_qualities_from_bam_with_samtoolspipe(benchmark): + result = benchmark(build_query_qualities_with_samtoolspipe, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len("".join(result)) == 107241 + + +def test_build_query_qualities_from_bam_with_pysam(benchmark): + result = benchmark(build_query_qualities_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert sum([len(x) for x in result]) == 107241 + + +def test_build_query_names_from_bam_with_pysam(benchmark): + result = benchmark(build_query_names_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len("".join([x for column in result for x in column])) == 2307343 + + +def test_build_mapping_qualities_from_bam_with_samtoolspipe(benchmark): + result = benchmark(build_mapping_qualities_with_samtoolspipe, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert len("".join(result)) == 107241 + + +def test_build_mapping_qualities_from_bam_with_pysam(benchmark): + result = benchmark(build_mapping_qualities_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert sum([len(x) for x in result]) == 107241 + + +def test_build_query_positions_from_bam_with_samtoolspipe(benchmark): + result = benchmark(build_query_positions_with_samtoolspipe, + os.path.join(BAM_DATADIR, "ex2.bam")) + # positions output by samtools are 1-based + assert sum([sum(x) - len(x) for x in result]) == 1841699 + + +def test_build_query_positions_from_bam_with_pysam(benchmark): + result = benchmark(build_query_positions_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert sum([sum(x) for x in result]) == 1841699 diff --git a/tests/AlignmentFilePileup_test.py b/tests/AlignmentFilePileup_test.py new file mode 100644 index 000000000..32738fe71 --- /dev/null +++ b/tests/AlignmentFilePileup_test.py @@ -0,0 +1,392 @@ +"""Benchmarking module for AlignmentFile functionality""" +import os +import pysam +import unittest +from TestUtils import BAM_DATADIR, IS_PYTHON3, force_str, flatten_nested_list +import PileupTestUtils + + +class TestPileupReadSelection(unittest.TestCase): + '''test pileup functionality.''' + + samfilename = os.path.join(BAM_DATADIR, "ex1.bam") + fastafilename = os.path.join(BAM_DATADIR, "ex1.fa") + + def setUp(self): + + self.samfile = pysam.AlignmentFile(self.samfilename) + self.fastafile = pysam.FastaFile(self.fastafilename) + + def tearDown(self): + self.samfile.close() + self.fastafile.close() + + def check_equal(self, references, iterator): + + for x, column in enumerate(iterator): + v = references[x][:-1].split("\t") + self.assertEqual( + len(v), 6, + "expected 6 values, got {}".format(v)) + (contig, pos, reference_base, + read_bases, read_qualities, alignment_mapping_qualities) \ + = v + self.assertEqual(int(pos) - 1, column.reference_pos) + + def test_samtools_stepper(self): + refs = force_str( + pysam.samtools.mpileup( + "-f", self.fastafilename, + self.samfilename)).splitlines(True) + iterator = self.samfile.pileup( + stepper="samtools", + fastafile=self.fastafile) + self.check_equal(refs, iterator) + + def test_all_stepper(self): + refs = force_str( + pysam.samtools.mpileup( + "-f", self.fastafilename, + "-A", "-B", + self.samfilename)).splitlines(True) + + iterator = self.samfile.pileup( + stepper="all", + fastafile=self.fastafile) + self.check_equal(refs, iterator) + + def test_ignore_overlaps(self): + refs = force_str( + pysam.samtools.mpileup( + "-f", self.fastafilename, + "-A", "-B", "-x", + self.samfilename)).splitlines(True) + + iterator = self.samfile.pileup( + stepper="all", + fastafile=self.fastafile, + ignore_overlaps=False) + self.check_equal(refs, iterator) + + def test_samtools_stepper_mapping_quality_threshold(self): + refs = force_str( + pysam.samtools.mpileup( + "-f", self.fastafilename, + "--min-MQ", "15", + self.samfilename)).splitlines(True) + iterator = self.samfile.pileup( + stepper="samtools", + fastafile=self.fastafile, + min_mapping_quality=15) + self.check_equal(refs, iterator) + + def test_samtools_stepper_base_quality_threshold(self): + refs = force_str( + pysam.samtools.mpileup( + "-f", self.fastafilename, + "--min-BQ", "20", + self.samfilename)).splitlines(True) + iterator = self.samfile.pileup( + stepper="samtools", + fastafile=self.fastafile, + min_base_quality=20) + self.check_equal(refs, iterator) + + def test_samtools_stepper_ignore_orphans(self): + refs = force_str( + pysam.samtools.mpileup( + "-f", self.fastafilename, + "--count-orphans", + self.samfilename)).splitlines(True) + iterator = self.samfile.pileup( + stepper="samtools", + fastafile=self.fastafile, + ignore_orphans=False) + self.check_equal(refs, iterator) + + def test_samtools_stepper_redo_baq(self): + refs = force_str( + pysam.samtools.mpileup( + "-f", self.fastafilename, + "--redo-BAQ", + self.samfilename)).splitlines(True) + iterator = self.samfile.pileup( + stepper="samtools", + fastafile=self.fastafile, + redo_baq=True) + self.check_equal(refs, iterator) + + +class TestPileupReadSelectionFastafile(TestPileupReadSelection): + '''test pileup functionality - backwards compatibility''' + + samfilename = os.path.join(BAM_DATADIR, "ex1.bam") + fastafilename = os.path.join(BAM_DATADIR, "ex1.fa") + + def setUp(self): + + self.samfile = pysam.AlignmentFile(self.samfilename) + self.fastafile = pysam.Fastafile(self.fastafilename) + + +class TestPileupQueryPosition(unittest.TestCase): + + filename = "test_query_position.bam" + + def testPileup(self): + last = {} + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, self.filename)) as inf: + for col in inf.pileup(): + for r in col.pileups: + # print r.alignment.query_name + # print r.query_position, r.query_position_or_next, r.is_del + if r.is_del: + self.assertEqual(r.query_position, None) + self.assertEqual(r.query_position_or_next, + last[r.alignment.query_name] + 1) + else: + self.assertNotEqual(r.query_position, None) + last[r.alignment.query_name] = r.query_position + + +class TestPileupObjects(unittest.TestCase): + + def setUp(self): + self.samfile = pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex1.bam"), + "rb") + + def testPileupColumn(self): + for pcolumn1 in self.samfile.pileup(region="chr1:105-106"): + if pcolumn1.reference_pos == 104: + self.assertEqual( + pcolumn1.reference_id, 0, + "chromosome/target id mismatch in position 1: %s != %s" % + (pcolumn1.reference_id, 0)) + self.assertEqual( + pcolumn1.reference_name, "chr1", + "chromosome mismatch in position 1: %s != %s" % + (pcolumn1.reference_name, "chr1")) + self.assertEqual( + pcolumn1.reference_pos, 105 - 1, + "position mismatch in position 1: %s != %s" % + (pcolumn1.reference_pos, 105 - 1)) + self.assertEqual( + pcolumn1.nsegments, 1, + "# reads mismatch in position 1: %s != %s" % + (pcolumn1.nsegments, 1)) + self.assertEqual( + len(pcolumn1.pileups), 1, + "# reads aligned to column mismatch in position 1" + ": %s != %s" % + (len(pcolumn1.pileups), 1)) + + for pcolumn2 in self.samfile.pileup(region="chr2:1480-1481"): + if pcolumn2.reference_pos == 1479: + self.assertEqual( + pcolumn2.reference_id, 1, + "chromosome/target id mismatch in position 1: %s != %s" % + (pcolumn2.reference_id, 1)) + self.assertEqual( + pcolumn2.reference_name, "chr2", + "chromosome mismatch in position 1: %s != %s" % + (pcolumn2.reference_name, "chr2")) + self.assertEqual( + pcolumn2.reference_pos, 1480 - 1, + "position mismatch in position 1: %s != %s" % + (pcolumn2.reference_pos, 1480 - 1)) + self.assertEqual( + pcolumn2.nsegments, 12, + "# reads mismatch in position 1: %s != %s" % + (pcolumn2.nsegments, 12)) + + def tearDown(self): + self.samfile.close() + + def testIteratorOutOfScope(self): + '''test if exception is raised if pileup col is accessed after + iterator is exhausted.''' + + for pileupcol in self.samfile.pileup(): + pass + + self.assertRaises(ValueError, getattr, pileupcol, "pileups") + + +class TestIteratorColumnBAM(unittest.TestCase): + + '''test iterator column against contents of ex4.bam.''' + + # note that samfile contains 1-based coordinates + # 1D means deletion with respect to reference sequence + # + mCoverages = {'chr1': [0] * 20 + [1] * 36 + [0] * (100 - 20 - 35), + 'chr2': [0] * 20 + [1] * 35 + [0] * (100 - 20 - 35), + } + + def setUp(self): + self.samfile = pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex4.bam"), + "rb") + + def checkRange(self, contig, start=None, end=None, truncate=False): + '''compare results from iterator with those from samtools.''' + # check if the same reads are returned and in the same order + for column in self.samfile.pileup( + contig, start, end, truncate=truncate, min_base_quality=0): + if truncate: + self.assertGreaterEqual(column.reference_pos, start) + self.assertLess(column.reference_pos, end) + thiscov = len(column.pileups) + refcov = self.mCoverages[ + self.samfile.getrname(column.reference_id)][column.reference_pos] + self.assertEqual(thiscov, refcov, + "wrong coverage at pos %s:%i %i should be %i" % ( + self.samfile.getrname(column.reference_id), + column.reference_pos, thiscov, refcov)) + + def testIterateAll(self): + '''check random access per contig''' + self.checkRange(None) + + def testIteratePerContig(self): + '''check random access per contig''' + for contig in self.samfile.references: + self.checkRange(contig) + + def testIterateRanges(self): + '''check random access per range''' + for contig, length in zip( + self.samfile.references, self.samfile.lengths): + for start in range(1, length, 90): + # this includes empty ranges + self.checkRange(contig, start, start + 90) + + def testInverse(self): + '''test the inverse, is point-wise pileup accurate.''' + for contig, refseq in list(self.mCoverages.items()): + refcolumns = sum(refseq) + for pos, refcov in enumerate(refseq): + columns = list(self.samfile.pileup(contig, pos, pos + 1)) + if refcov == 0: + # if no read, no coverage + self.assertEqual( + len(columns), + refcov, + "wrong number of pileup columns returned for position %s:%i, %i should be %i" % ( + contig, pos, + len(columns), refcov)) + elif refcov == 1: + # one read, all columns of the read are returned + self.assertEqual( + len(columns), + refcolumns, + "pileup incomplete at position %i: got %i, expected %i " % + (pos, len(columns), refcolumns)) + + def testIterateTruncate(self): + '''check random access per range''' + for contig, length in zip(self.samfile.references, + self.samfile.lengths): + for start in range(1, length, 90): + # this includes empty ranges + self.checkRange(contig, start, start + 90, truncate=True) + + def tearDown(self): + self.samfile.close() + + +class TestIteratorColumn2(unittest.TestCase): + + '''test iterator column against contents of ex1.bam.''' + + def setUp(self): + self.samfile = pysam.AlignmentFile( + os.path.join(BAM_DATADIR, "ex1.bam"), + "rb") + + def testStart(self): + # print self.samfile.fetch().next().reference_start + # print self.samfile.pileup().next().reference_start + pass + + def testTruncate(self): + '''see issue 107.''' + # note that ranges in regions start from 1 + p = self.samfile.pileup(region='chr1:170:172', truncate=True) + columns = [x.reference_pos for x in p] + self.assertEqual(len(columns), 3) + self.assertEqual(columns, [169, 170, 171]) + + p = self.samfile.pileup('chr1', 169, 172, truncate=True) + columns = [x.reference_pos for x in p] + + self.assertEqual(len(columns), 3) + self.assertEqual(columns, [169, 170, 171]) + + def testAccessOnClosedIterator(self): + '''see issue 131 + + Accessing pileup data after iterator has closed. + ''' + pcolumn = self.samfile.pileup('chr1', 170, 180).__next__() + self.assertRaises(ValueError, getattr, pcolumn, "pileups") + + def testStr(self): + '''test if PileupRead can be printed.''' + iter = self.samfile.pileup('chr1', 170, 180) + pcolumn = iter.__next__() + s = str(pcolumn) + self.assertEqual(len(s.split("\n")), 2) + + +@unittest.skipIf(not IS_PYTHON3, + "tests requires at least python3 for subprocess context manager") +class PileUpColumnTests(unittest.TestCase): + + fn = os.path.join(BAM_DATADIR, "ex2.bam") + fn_fasta = os.path.join(BAM_DATADIR, "ex1.fa") + + def test_pileup_depths_are_equal(self): + samtools_result = PileupTestUtils.build_depth_with_samtoolspipe(self.fn) + pysam_result = PileupTestUtils.build_depth_with_filter_with_pysam(self.fn) + self.assertEqual(pysam_result, samtools_result) + + def test_pileup_query_bases_without_reference_are_equal(self): + samtools_result = PileupTestUtils.build_query_bases_with_samtoolspipe(self.fn) + pysam_result = PileupTestUtils.build_query_bases_with_pysam(self.fn) + self.assertEqual(["".join(x) for x in pysam_result], samtools_result) + + def test_pileup_query_bases_with_reference_are_equal(self): + samtools_result = PileupTestUtils.build_query_bases_with_samtoolspipe(self.fn, "-f", self.fn_fasta) + with pysam.FastaFile(self.fn_fasta) as fasta: + pysam_result = PileupTestUtils.build_query_bases_with_pysam(self.fn, fastafile=fasta, stepper="samtools") + self.assertEqual(["".join(x) for x in pysam_result], samtools_result) + + def test_pileup_query_qualities_are_equal(self): + samtools_result = PileupTestUtils.build_query_qualities_with_samtoolspipe(self.fn) + pysam_result = PileupTestUtils.build_query_qualities_with_pysam(self.fn) + pysam_result = [ + [chr(min(126, x + 33)) for x in l] for l in pysam_result] + self.assertEqual("".join(flatten_nested_list(pysam_result)), + "".join(flatten_nested_list(samtools_result))) + + def test_pileup_mapping_qualities_are_equal(self): + samtools_result = PileupTestUtils.build_mapping_qualities_with_samtoolspipe(self.fn) + pysam_result = PileupTestUtils.build_mapping_qualities_with_pysam(self.fn) + # convert to chars + pysam_result = [ + [chr(min(126, x + 33)) for x in l] for l in pysam_result] + + self.assertEqual("".join(flatten_nested_list(pysam_result)), + "".join(flatten_nested_list(samtools_result))) + + def test_pileup_query_qualities_from_pileups_are_equal(self): + samtools_result = PileupTestUtils.build_query_qualities_with_samtoolspipe(self.fn) + pysam_result = PileupTestUtils.build_query_qualities_with_pysam_pileups(self.fn) + pysam_result = [ + "".join([chr(min(126, x + 33)) for x in l]) for l in pysam_result] + + self.assertEqual(pysam_result, samtools_result) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/AlignmentFile_bench.py b/tests/AlignmentFile_bench.py new file mode 100644 index 000000000..275a5fbff --- /dev/null +++ b/tests/AlignmentFile_bench.py @@ -0,0 +1,60 @@ +"""Benchmarking module for AlignmentFile functionality""" +import os +import subprocess +import pysam + + +from TestUtils import BAM_DATADIR + + +def count_number_lines_with_samtools(fn): + os.system("samtools view {} | wc -l > /dev/null".format(fn)) + return 3270 + + +def count_number_lines_with_samtoolspipe(fn): + with subprocess.Popen(["samtools", "view", fn], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) as proc: + return len(proc.stdout.readlines()) + + +def count_number_lines_with_pysam(*args, **kwargs): + with pysam.AlignmentFile(*args, **kwargs) as inf: + return len(list(inf.fetch())) + + +def test_count_number_lines_from_sam_with_samtools(benchmark): + result = benchmark(count_number_lines_with_samtools, + os.path.join(BAM_DATADIR, "ex2.sam")) + assert result == 3270 + + +def test_count_number_lines_from_sam_with_samtoolspipe(benchmark): + result = benchmark(count_number_lines_with_samtoolspipe, + os.path.join(BAM_DATADIR, "ex2.sam")) + assert result == 3270 + + +def test_count_number_lines_from_sam_with_pysam(benchmark): + result = benchmark(count_number_lines_with_pysam, + os.path.join(BAM_DATADIR, "ex2.sam"), "r") + assert result == 3270 + + +def test_count_number_lines_from_bam_with_samtools(benchmark): + result = benchmark(count_number_lines_with_samtools, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert result == 3270 + + +def test_count_number_lines_from_bam_with_samtoolspipe(benchmark): + result = benchmark(count_number_lines_with_samtoolspipe, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert result == 3270 + + +def test_count_number_lines_from_bam_with_pysam(benchmark): + result = benchmark(count_number_lines_with_pysam, + os.path.join(BAM_DATADIR, "ex2.bam")) + assert result == 3270 diff --git a/tests/AlignmentFile_test.py b/tests/AlignmentFile_test.py index 18fb05be0..a2d9aa1ce 100644 --- a/tests/AlignmentFile_test.py +++ b/tests/AlignmentFile_test.py @@ -9,8 +9,6 @@ import os import shutil import sys -import re -import copy import collections import subprocess import logging @@ -24,13 +22,9 @@ import pysam import pysam.samtools -from TestUtils import checkBinaryEqual, checkURL, \ +from TestUtils import checkBinaryEqual, check_url, \ check_samtools_view_equal, checkFieldEqual, force_str, \ - get_temp_filename - - -DATADIR = os.path.abspath(os.path.join(os.path.dirname(__file__), - "pysam_data")) + get_temp_filename, BAM_DATADIR ################################################## @@ -49,7 +43,7 @@ class BasicTestBAMFromFetch(unittest.TestCase): def setUp(self): self.samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex3.bam"), + os.path.join(BAM_DATADIR, "ex3.bam"), "rb") self.reads = list(self.samfile.fetch()) @@ -57,99 +51,46 @@ def tearDown(self): self.samfile.close() def testARqname(self): - self.assertEqual( - self.reads[0].query_name, - "read_28833_29006_6945", - "read name mismatch in read 1: %s != %s" % ( - self.reads[0].query_name, "read_28833_29006_6945")) - self.assertEqual( - self.reads[1].query_name, - "read_28701_28881_323b", - "read name mismatch in read 2: %s != %s" % ( - self.reads[1].query_name, "read_28701_28881_323b")) + self.assertEqual(self.reads[0].query_name, + "read_28833_29006_6945") + self.assertEqual(self.reads[1].query_name, + "read_28701_28881_323b") def testARflag(self): - self.assertEqual( - self.reads[0].flag, 99, - "flag mismatch in read 1: %s != %s" % ( - self.reads[0].flag, 99)) - self.assertEqual( - self.reads[1].flag, 147, - "flag mismatch in read 2: %s != %s" % ( - self.reads[1].flag, 147)) + self.assertEqual(self.reads[0].flag, 99) + self.assertEqual(self.reads[1].flag, 147) def testARrname(self): - self.assertEqual( - self.reads[0].reference_id, 0, - "chromosome/target id mismatch in read 1: %s != %s" % - (self.reads[0].reference_id, 0)) - self.assertEqual( - self.reads[1].reference_id, 1, - "chromosome/target id mismatch in read 2: %s != %s" % - (self.reads[1].reference_id, 1)) + self.assertEqual(self.reads[0].reference_id, 0) + self.assertEqual(self.reads[1].reference_id, 1) def testARpos(self): - self.assertEqual( - self.reads[0].reference_start, 33 - 1, - "mapping position mismatch in read 1: %s != %s" % - (self.reads[0].reference_start, 33 - 1)) - self.assertEqual( - self.reads[1].reference_start, 88 - 1, - "mapping position mismatch in read 2: %s != %s" % - (self.reads[1].reference_start, 88 - 1)) + self.assertEqual(self.reads[0].reference_start, 33 - 1) + self.assertEqual(self.reads[1].reference_start, 88 - 1) def testARmapq(self): - self.assertEqual( - self.reads[0].mapping_quality, 20, - "mapping quality mismatch in read 1: %s != %s" % - (self.reads[0].mapping_quality, 20)) - self.assertEqual( - self.reads[1].mapping_quality, 30, - "mapping quality mismatch in read 2: %s != %s" % ( - self.reads[1].mapping_quality, 30)) + self.assertEqual(self.reads[0].mapping_quality, 20) + self.assertEqual(self.reads[1].mapping_quality, 30) def testARcigar(self): - self.assertEqual( - self.reads[0].cigartuples, - [(0, 10), (2, 1), (0, 25)], - "read name length mismatch in read 1: %s != %s" % - (self.reads[0].cigartuples, [(0, 10), (2, 1), (0, 25)])) - self.assertEqual( - self.reads[1].cigartuples, [(0, 35)], - "read name length mismatch in read 2: %s != %s" % - (self.reads[1].cigartuples, [(0, 35)])) + self.assertEqual(self.reads[0].cigartuples, [(0, 10), (2, 1), (0, 25)]) + self.assertEqual(self.reads[1].cigartuples, [(0, 35)]) def testARcigarstring(self): self.assertEqual(self.reads[0].cigarstring, '10M1D25M') self.assertEqual(self.reads[1].cigarstring, '35M') def testARmrnm(self): - self.assertEqual( - self.reads[0].next_reference_id, 0, - "mate reference sequence name mismatch in read 1: %s != %s" % - (self.reads[0].next_reference_id, 0)) - self.assertEqual( - self.reads[1].next_reference_id, 1, - "mate reference sequence name mismatch in read 2: %s != %s" % - (self.reads[1].next_reference_id, 1)) - self.assertEqual( - self.reads[0].next_reference_id, 0, - "mate reference sequence name mismatch in read 1: %s != %s" % - (self.reads[0].next_reference_id, 0)) - self.assertEqual( - self.reads[1].next_reference_id, 1, - "mate reference sequence name mismatch in read 2: %s != %s" % - (self.reads[1].next_reference_id, 1)) + self.assertEqual(self.reads[0].next_reference_id, 0) + self.assertEqual(self.reads[1].next_reference_id, 1) + self.assertEqual(self.reads[0].next_reference_id, 0) + self.assertEqual(self.reads[1].next_reference_id, 1) def testARmpos(self): - self.assertEqual(self.reads[ - 0].next_reference_start, 200 - 1, "mate mapping position mismatch in read 1: %s != %s" % (self.reads[0].next_reference_start, 200 - 1)) - self.assertEqual(self.reads[ - 1].next_reference_start, 500 - 1, "mate mapping position mismatch in read 2: %s != %s" % (self.reads[1].next_reference_start, 500 - 1)) - self.assertEqual(self.reads[ - 0].next_reference_start, 200 - 1, "mate mapping position mismatch in read 1: %s != %s" % (self.reads[0].next_reference_start, 200 - 1)) - self.assertEqual(self.reads[ - 1].next_reference_start, 500 - 1, "mate mapping position mismatch in read 2: %s != %s" % (self.reads[1].next_reference_start, 500 - 1)) + self.assertEqual(self.reads[0].next_reference_start, 200 - 1) + self.assertEqual(self.reads[1].next_reference_start, 500 - 1) + self.assertEqual(self.reads[0].next_reference_start, 200 - 1) + self.assertEqual(self.reads[1].next_reference_start, 500 - 1) def testARQueryLength(self): self.assertEqual( @@ -170,12 +111,15 @@ def testARQueryLength(self): (self.reads[1].query_length, 35)) def testARseq(self): - self.assertEqual(self.reads[0].query_sequence, "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG", "sequence mismatch in read 1: %s != %s" % ( - self.reads[0].query_sequence, "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG")) - self.assertEqual(self.reads[1].query_sequence, "ACCTATATCTTGGCCTTGGCCGATGCGGCCTTGCA", "sequence size mismatch in read 2: %s != %s" % ( - self.reads[1].query_sequence, "ACCTATATCTTGGCCTTGGCCGATGCGGCCTTGCA")) - self.assertEqual(self.reads[3].query_sequence, "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG", "sequence mismatch in read 4: %s != %s" % ( - self.reads[3].query_sequence, "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG")) + self.assertEqual( + self.reads[0].query_sequence, + "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG") + self.assertEqual( + self.reads[1].query_sequence, + "ACCTATATCTTGGCCTTGGCCGATGCGGCCTTGCA") + self.assertEqual( + self.reads[3].query_sequence, + "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG") def testARqual(self): self.assertEqual( @@ -210,19 +154,22 @@ def testARquery(self): def testARqqual(self): self.assertEqual( - pysam.qualities_to_qualitystring(self.reads[0].query_alignment_qualities), + pysam.qualities_to_qualitystring( + self.reads[0].query_alignment_qualities), "<<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<<", "qquality string mismatch in read 1: %s != %s" % (pysam.qualities_to_qualitystring(self.reads[0].query_alignment_qualities), "<<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<<")) self.assertEqual( - pysam.qualities_to_qualitystring(self.reads[1].query_alignment_qualities), + pysam.qualities_to_qualitystring( + self.reads[1].query_alignment_qualities), "<<<<<;<<<<7;:<<<6;<<<<<<<<<<<<7<<<<", "qquality string mismatch in read 2: %s != %s" % (pysam.qualities_to_qualitystring(self.reads[1].query_alignment_qualities), "<<<<<;<<<<7;:<<<6;<<<<<<<<<<<<7<<<<")) self.assertEqual( - pysam.qualities_to_qualitystring(self.reads[3].query_alignment_qualities), + pysam.qualities_to_qualitystring( + self.reads[3].query_alignment_qualities), "<<<<<<<<<<<<<<<<<:<9/,&,22", "qquality string mismatch in read 3: %s != %s" % (pysam.qualities_to_qualitystring(self.reads[3].query_alignment_qualities), @@ -273,7 +220,7 @@ class BasicTestSAMFromFetch(BasicTestBAMFromFetch): def setUp(self): self.samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex3.sam"), + os.path.join(BAM_DATADIR, "ex3.sam"), "r") self.reads = list(self.samfile.fetch()) @@ -282,7 +229,7 @@ class BasicTestCRAMFromFetch(BasicTestBAMFromFetch): def setUp(self): self.samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex3.cram"), + os.path.join(BAM_DATADIR, "ex3.cram"), "rc") self.reads = list(self.samfile.fetch()) @@ -328,7 +275,7 @@ class BasicTestSAMFromFilename(BasicTestBAMFromFetch): def setUp(self): self.samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex3.sam"), + os.path.join(BAM_DATADIR, "ex3.sam"), "r") self.reads = [r for r in self.samfile] @@ -337,7 +284,7 @@ class BasicTestCRAMFromFilename(BasicTestCRAMFromFetch): def setUp(self): self.samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex3.cram"), + os.path.join(BAM_DATADIR, "ex3.cram"), "rc") self.reads = [r for r in self.samfile] @@ -346,7 +293,7 @@ class BasicTestBAMFromFilename(BasicTestBAMFromFetch): def setUp(self): self.samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex3.bam"), + os.path.join(BAM_DATADIR, "ex3.bam"), "rb") self.reads = [r for r in self.samfile] @@ -354,7 +301,7 @@ def setUp(self): class BasicTestBAMFromFile(BasicTestBAMFromFetch): def setUp(self): - with open(os.path.join(DATADIR, "ex3.bam")) as f: + with open(os.path.join(BAM_DATADIR, "ex3.bam")) as f: self.samfile = pysam.AlignmentFile( f, "rb") self.reads = [r for r in self.samfile] @@ -363,7 +310,7 @@ def setUp(self): class BasicTestBAMFromFileNo(BasicTestBAMFromFetch): def setUp(self): - with open(os.path.join(DATADIR, "ex3.bam")) as f: + with open(os.path.join(BAM_DATADIR, "ex3.bam")) as f: self.samfile = pysam.AlignmentFile( f.fileno(), "rb") self.reads = [r for r in self.samfile] @@ -372,7 +319,7 @@ def setUp(self): class BasicTestSAMFromFile(BasicTestBAMFromFetch): def setUp(self): - with open(os.path.join(DATADIR, "ex3.sam")) as f: + with open(os.path.join(BAM_DATADIR, "ex3.sam")) as f: self.samfile = pysam.AlignmentFile( f, "r") self.reads = [r for r in self.samfile] @@ -381,7 +328,7 @@ def setUp(self): class BasicTestSAMFromFileNo(BasicTestBAMFromFetch): def setUp(self): - with open(os.path.join(DATADIR, "ex3.sam")) as f: + with open(os.path.join(BAM_DATADIR, "ex3.sam")) as f: self.samfile = pysam.AlignmentFile( f.fileno(), "r") self.reads = [r for r in self.samfile] @@ -390,7 +337,7 @@ def setUp(self): class BasicTestCRAMFromFile(BasicTestCRAMFromFetch): def setUp(self): - with open(os.path.join(DATADIR, "ex3.cram")) as f: + with open(os.path.join(BAM_DATADIR, "ex3.cram")) as f: self.samfile = pysam.AlignmentFile(f, "rc") self.reads = [r for r in self.samfile] @@ -398,7 +345,7 @@ def setUp(self): class BasicTestCRAMFromFileNo(BasicTestCRAMFromFetch): def setUp(self): - with open(os.path.join(DATADIR, "ex3.cram")) as f: + with open(os.path.join(BAM_DATADIR, "ex3.cram")) as f: self.samfile = pysam.AlignmentFile( f.fileno(), "rc") self.reads = [r for r in self.samfile] @@ -408,7 +355,7 @@ class BasicTestSAMFromStringIO(BasicTestBAMFromFetch): def testRaises(self): statement = "samtools view -h {}".format( - os.path.join(DATADIR, "ex3.bam")) + os.path.join(BAM_DATADIR, "ex3.bam")) stdout = subprocess.check_output(statement.split(" ")) bam = StringIO() if sys.version_info.major >= 3: @@ -439,10 +386,12 @@ def checkEcho(self, input_filename, reference_filename, output_filename, - input_mode, output_mode, + input_mode, + output_mode, sequence_filename=None, use_template=True, - checkf=checkBinaryEqual): + checkf=checkBinaryEqual, + **kwargs): '''iterate through *input_filename* writing to *output_filename* and comparing the output to *reference_filename*. @@ -459,7 +408,7 @@ def checkEcho(self, ''' with pysam.AlignmentFile( - os.path.join(DATADIR, input_filename), + os.path.join(BAM_DATADIR, input_filename), input_mode) as infile: if "b" in input_mode: @@ -477,7 +426,7 @@ def checkEcho(self, output_filename, output_mode, reference_filename=sequence_filename, - template=infile) + template=infile, **kwargs) else: outfile = pysam.AlignmentFile( output_filename, @@ -485,7 +434,8 @@ def checkEcho(self, reference_names=infile.references, reference_lengths=infile.lengths, reference_filename=sequence_filename, - add_sq_text=False) + add_sq_text=False, + **kwargs) iter = infile.fetch() @@ -495,7 +445,7 @@ def checkEcho(self, outfile.close() self.assertTrue(checkf( - os.path.join(DATADIR, reference_filename), + os.path.join(BAM_DATADIR, reference_filename), output_filename), "files %s and %s are not the same" % (reference_filename, @@ -509,6 +459,13 @@ def testSAM2SAM(self): "tmp_ex2.sam", "r", "wh") + def testSAM2SAMWithoutHeader(self): + self.checkEcho("ex2.sam", + "ex1.sam", + "tmp_ex2.sam", + "r", "w", + add_sam_header=False) + def testBAM2BAM(self): self.checkEcho("ex2.bam", "ex2.bam", @@ -516,12 +473,17 @@ def testBAM2BAM(self): "rb", "wb") def testCRAM2CRAM(self): + # in some systems different reference sequence paths might be + # embedded in the CRAM files which will result in different headers + # see #542 self.checkEcho("ex2.cram", "ex2.cram", "tmp_ex2.cram", "rc", "wc", - sequence_filename="pysam_data/ex1.fa", - checkf=check_samtools_view_equal) + sequence_filename=os.path.join(BAM_DATADIR, "ex1.fa"), + checkf=partial( + check_samtools_view_equal, + without_header=True)) def testSAM2BAM(self): self.checkEcho("ex2.sam", @@ -541,7 +503,7 @@ def testBAM2CRAM(self): "ex2.cram", "tmp_ex2.cram", "rb", "wc", - sequence_filename="pysam_data/ex1.fa", + sequence_filename=os.path.join(BAM_DATADIR, "ex1.fa"), checkf=partial( check_samtools_view_equal, without_header=True)) @@ -552,7 +514,7 @@ def testCRAM2BAM(self): "ex2.bam", "tmp_ex2.bam", "rc", "wb", - sequence_filename="pysam_data/ex1.fa", + sequence_filename=os.path.join(BAM_DATADIR, "ex1.fa"), checkf=partial( check_samtools_view_equal, without_header=True)) @@ -562,7 +524,7 @@ def testSAM2CRAM(self): "ex2.cram", "tmp_ex2.cram", "r", "wc", - sequence_filename="pysam_data/ex1.fa", + sequence_filename=os.path.join(BAM_DATADIR, "ex1.fa"), checkf=partial( check_samtools_view_equal, without_header=True)) @@ -572,7 +534,7 @@ def testCRAM2SAM(self): "ex2.sam", "tmp_ex2.sam", "rc", "wh", - sequence_filename="pysam_data/ex1.fa", + sequence_filename=os.path.join(BAM_DATADIR, "ex1.fa"), checkf=partial( check_samtools_view_equal, without_header=True)) @@ -588,18 +550,10 @@ def testCRAM2SAM(self): # self.checkEcho(input_filename, reference_filename, output_filename, # "rb", "wb", use_template=False) - # Release 0.8.0 - # no samfiles without header - def testSAM2SAMWithoutHeader(self): - self.checkEcho("ex2.sam", - "ex1.sam", - "tmp_ex2.sam", - "r", "w") - def testReadSamWithoutTargetNames(self): '''see issue 104.''' input_filename = os.path.join( - DATADIR, + BAM_DATADIR, "example_unmapped_reads_no_sq.sam") # raise exception in default mode @@ -614,19 +568,17 @@ def testReadSamWithoutTargetNames(self): input_filename, "r", check_header=True) - infile = pysam.AlignmentFile( - input_filename, - check_header=False, - check_sq=False) - - # TODO - # result = list(infile.fetch(until_eof=True)) - # self.assertEqual(2, len(result)) + with pysam.AlignmentFile( + input_filename, + check_header=False, + check_sq=False) as infile: + result = list(infile.fetch(until_eof=True)) + self.assertEqual(2, len(result)) def testReadBamWithoutTargetNames(self): '''see issue 104.''' input_filename = os.path.join( - DATADIR, "example_unmapped_reads_no_sq.bam") + BAM_DATADIR, "example_unmapped_reads_no_sq.bam") # raise exception in default mode self.assertRaises(ValueError, @@ -641,56 +593,47 @@ def testReadBamWithoutTargetNames(self): "r", check_header=True) - infile = pysam.AlignmentFile( - input_filename, check_header=False, check_sq=False) - result = list(infile.fetch(until_eof=True)) + with pysam.AlignmentFile( + input_filename, check_sq=False) as infile: + result = list(infile.fetch(until_eof=True)) - # TODO - def testReadSamWithoutHeader(self): - input_filename = os.path.join(DATADIR, "ex1.sam") + def test_fail_read_sam_without_header(self): + input_filename = os.path.join(BAM_DATADIR, "ex1.sam") - # reading from a samfile without header is not - # implemented self.assertRaises(ValueError, pysam.AlignmentFile, input_filename, "r") - # TODO - # without check_header header is no read - # leading to segfault - # self.assertRaises(ValueError, - # pysam.AlignmentFile, - # input_filename, - # "r", - # check_header=False) + def test_pass_read_sam_without_header_with_refs(self): + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex1.sam"), + "r", + reference_names=["chr1", "chr2"], + reference_lengths=[1575, 1584]) as samfile: + self.assertEqual(len(list(samfile.fetch(until_eof=True))), 3270) - # TODO - # def testReadUnformattedFile(self): - # '''test reading from a file that is not bam/sam formatted''' - # input_filename = os.path.join(DATADIR, 'Makefile') - - # # bam - file raise error - # self.assertRaises(ValueError, - # pysam.AlignmentFile, - # input_filename, - # "rb") - - # # sam - file error, but can't fetch - # self.assertRaises(ValueError, - # pysam.AlignmentFile, - # input_filename, - # "r") - - # self.assertRaises(ValueError, - # pysam.AlignmentFile, - # input_filename, - # "r", - # check_header=False) + def test_pass_read_sam_with_header_without_header_check(self): + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex2.sam"), + "r", check_header=False) as samfile: + self.assertEqual(len(list(samfile.fetch(until_eof=True))), 3270) + + def test_fail_when_reading_unformatted_files(self): + '''test reading from a file that is not bam/sam formatted''' + input_filename = os.path.join(BAM_DATADIR, 'Makefile') + + self.assertRaises(ValueError, + pysam.AlignmentFile, + input_filename, + "rb") + + self.assertRaises(ValueError, + pysam.AlignmentFile, + input_filename, + "r") def testBAMWithoutAlignedSegments(self): '''see issue 117''' - input_filename = os.path.join(DATADIR, "test_unaligned.bam") + input_filename = os.path.join(BAM_DATADIR, "test_unaligned.bam") samfile = pysam.AlignmentFile(input_filename, "rb", check_sq=False) @@ -698,7 +641,7 @@ def testBAMWithoutAlignedSegments(self): def testBAMWithShortBAI(self): '''see issue 116''' - input_filename = os.path.join(DATADIR, "example_bai.bam") + input_filename = os.path.join(BAM_DATADIR, "example_bai.bam") samfile = pysam.AlignmentFile(input_filename, "rb", check_sq=False) @@ -707,14 +650,14 @@ def testBAMWithShortBAI(self): def testFetchFromClosedFile(self): samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex1.bam"), + os.path.join(BAM_DATADIR, "ex1.bam"), "rb") samfile.close() self.assertRaises(ValueError, samfile.fetch, 'chr1', 100, 120) def testFetchFromClosedFileObject(self): - f = open(os.path.join(DATADIR, "ex1.bam")) + f = open(os.path.join(BAM_DATADIR, "ex1.bam")) samfile = pysam.AlignmentFile(f, "rb") f.close() self.assertTrue(f.closed) @@ -724,19 +667,20 @@ def testFetchFromClosedFileObject(self): "tmp_ex1.bam", "rb", "wb") - f = open(os.path.join(DATADIR, "ex1.bam")) + f = open(os.path.join(BAM_DATADIR, "ex1.bam")) samfile = pysam.AlignmentFile(f, "rb") self.assertFalse(f.closed) samfile.close() # python file needs to be closed separately self.assertFalse(f.closed) - def testClosedFile(self): + def test_accessing_attributes_in_closed_file_raises_errors(self): '''test that access to a closed samfile raises ValueError.''' - samfile = pysam.AlignmentFile(os.path.join(DATADIR, "ex1.bam"), + samfile = pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex1.bam"), "rb") samfile.close() + self.assertRaises(ValueError, samfile.fetch, 'chr1', 100, 120) self.assertRaises(ValueError, samfile.pileup, 'chr1', 100, 120) self.assertRaises(ValueError, samfile.getrname, 0) @@ -746,18 +690,41 @@ def testClosedFile(self): self.assertRaises(ValueError, getattr, samfile, "nreferences") self.assertRaises(ValueError, getattr, samfile, "references") self.assertRaises(ValueError, getattr, samfile, "lengths") - self.assertRaises(ValueError, getattr, samfile, "text") - self.assertRaises(ValueError, getattr, samfile, "header") + self.assertEqual(samfile.header, None) # write on closed file self.assertEqual(0, samfile.write(None)) + def test_header_available_after_closing_file(self): + def load_bam(): + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex1.bam"), "rb") as inf: + header = inf.header + return header + + header = load_bam() + self.assertTrue(header) + self.assertEqual(header.nreferences, 2) + self.assertEqual(header.references, ("chr1", "chr2")) + + def test_reference_name_available_after_closing_file(self): + """read tids can be mapped to references after AlignmentFile has been closed. + + see issue #517""" + + def load_bam(): + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex1.bam"), "rb") as inf: + read = next(inf) + return read + + read = load_bam() + self.assertEqual(read.reference_name, "chr1") + # TOOD # def testReadingFromSamFileWithoutHeader(self): # '''read from samfile without header. # ''' - # samfile = pysam.AlignmentFile(os.path.join(DATADIR, "ex7.sam"), + # samfile = pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex7.sam"), # check_header=False, # check_sq=False) # self.assertRaises(NotImplementedError, samfile.__iter__) @@ -765,15 +732,16 @@ def testClosedFile(self): def testReadingFromFileWithoutIndex(self): '''read from bam file without index.''' - shutil.copyfile(os.path.join(DATADIR, "ex2.bam"), - 'tmp_ex2.bam') - samfile = pysam.AlignmentFile('tmp_ex2.bam', + dest = get_temp_filename("tmp_ex2.bam") + shutil.copyfile(os.path.join(BAM_DATADIR, "ex2.bam"), + dest) + samfile = pysam.AlignmentFile(dest, "rb") self.assertRaises(ValueError, samfile.fetch) self.assertEqual( len(list(samfile.fetch(until_eof=True))), 3270) - os.unlink('tmp_ex2.bam') + os.unlink(dest) # def testReadingUniversalFileMode(self): # '''read from samfile without header. @@ -790,7 +758,7 @@ def testReadingFromFileWithoutIndex(self): def testHead(self): '''test IteratorRowHead''' - samfile = pysam.AlignmentFile(os.path.join(DATADIR, "ex1.bam"), + samfile = pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex1.bam"), "rb") l10 = list(samfile.head(10)) l100 = list(samfile.head(100)) @@ -817,7 +785,7 @@ def testWriteUncompressedBAMFile(self): "r", "wbu") def testEmptyBAM(self): - samfile = pysam.Samfile(os.path.join(DATADIR, "empty.bam"), + samfile = pysam.Samfile(os.path.join(BAM_DATADIR, "empty.bam"), "rb") self.assertEqual(samfile.mapped, 0) self.assertEqual(samfile.unmapped, 0) @@ -827,11 +795,11 @@ def testEmptyWithHeaderBAM(self): self.assertRaises( ValueError, pysam.Samfile, - os.path.join(DATADIR, "example_empty_with_header.bam"), + os.path.join(BAM_DATADIR, "example_empty_with_header.bam"), "rb") samfile = pysam.Samfile( - os.path.join(DATADIR, "example_empty_with_header.bam"), + os.path.join(BAM_DATADIR, "example_empty_with_header.bam"), "rb", check_sq=False) self.assertEqual(samfile.mapped, 0) @@ -842,19 +810,45 @@ def testEmptyWithHeaderBAM(self): def testOpenFromFilename(self): samfile = pysam.AlignmentFile( - filename=os.path.join(DATADIR, "ex1.bam"), + filename=os.path.join(BAM_DATADIR, "ex1.bam"), mode="rb") self.assertEqual(len(list(samfile.fetch())), 3270) def testBAMWithCSIIndex(self): '''see issue 116''' - input_filename = os.path.join(DATADIR, "ex1_csi.bam") + input_filename = os.path.join(BAM_DATADIR, "ex1_csi.bam") samfile = pysam.AlignmentFile(input_filename, "rb", check_sq=False) samfile.fetch('chr2') - + def test_fetch_by_tid(self): + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex1.bam"), "rb") as samfile: + self.assertEqual(len(list(samfile.fetch('chr1'))), + len(list(samfile.fetch(tid=0)))) + self.assertEqual(len(list(samfile.fetch('chr2'))), + len(list(samfile.fetch(tid=1)))) + self.assertRaises( + IndexError, + samfile.fetch, + tid=2) + self.assertRaises( + IndexError, + samfile.fetch, + tid=-1) + self.assertEqual(len(list(samfile.fetch('chr1', start=1000, end=2000))), + len(list(samfile.fetch(tid=0, start=1000, end=2000)))) + + def test_write_bam_to_unknown_path_fails(self): + '''see issue 116''' + input_filename = os.path.join(BAM_DATADIR, "ex1.bam") + with pysam.AlignmentFile(input_filename) as inf: + self.assertRaises(IOError, + pysam.AlignmentFile, + "missing_directory/new_file.bam", + "wb", + template=inf) + class TestAutoDetect(unittest.TestCase): @@ -862,7 +856,7 @@ def testSAM(self): """test SAM autodetection.""" with pysam.AlignmentFile( - os.path.join(DATADIR, "ex3.sam")) as inf: + os.path.join(BAM_DATADIR, "ex3.sam")) as inf: self.assertFalse(inf.is_bam) self.assertFalse(inf.is_cram) @@ -872,7 +866,7 @@ def testBAM(self): """test BAM autodetection.""" with pysam.AlignmentFile( - os.path.join(DATADIR, "ex3.bam")) as inf: + os.path.join(BAM_DATADIR, "ex3.bam")) as inf: self.assertTrue(inf.is_bam) self.assertFalse(inf.is_cram) self.assertEqual(len(list(inf.fetch('chr1'))), 1) @@ -882,7 +876,7 @@ def testCRAM(self): """test CRAM autodetection.""" with pysam.AlignmentFile( - os.path.join(DATADIR, "ex3.cram")) as inf: + os.path.join(BAM_DATADIR, "ex3.cram")) as inf: self.assertFalse(inf.is_bam) self.assertTrue(inf.is_cram) self.assertEqual(len(list(inf.fetch('chr1'))), 1) @@ -896,7 +890,7 @@ def testCRAM(self): ################################################## class TestIteratorRowBAM(unittest.TestCase): - filename = os.path.join(DATADIR, "ex2.bam") + filename = os.path.join(BAM_DATADIR, "ex2.bam") mode = "rb" reference_filename = None @@ -960,7 +954,7 @@ def testIterateRanges(self): class TestIteratorRowAllBAM(unittest.TestCase): - filename = os.path.join(DATADIR, "ex2.bam") + filename = os.path.join(BAM_DATADIR, "ex2.bam") mode = "rb" def setUp(self): @@ -990,100 +984,15 @@ def tearDown(self): self.samfile.close() -class TestIteratorColumnBAM(unittest.TestCase): - - '''test iterator column against contents of ex4.bam.''' - - # note that samfile contains 1-based coordinates - # 1D means deletion with respect to reference sequence - # - mCoverages = {'chr1': [0] * 20 + [1] * 36 + [0] * (100 - 20 - 35), - 'chr2': [0] * 20 + [1] * 35 + [0] * (100 - 20 - 35), - } - - def setUp(self): - self.samfile = pysam.AlignmentFile(os.path.join(DATADIR, "ex4.bam"), - "rb") - - def checkRange(self, contig, start=None, end=None, truncate=False): - '''compare results from iterator with those from samtools.''' - # check if the same reads are returned and in the same order - for column in self.samfile.pileup( - contig, start, end, truncate=truncate): - if truncate: - self.assertGreaterEqual(column.reference_pos, start) - self.assertLess(column.reference_pos, end) - thiscov = len(column.pileups) - refcov = self.mCoverages[ - self.samfile.getrname(column.reference_id)][column.reference_pos] - self.assertEqual(thiscov, refcov, - "wrong coverage at pos %s:%i %i should be %i" % ( - self.samfile.getrname(column.reference_id), - column.reference_pos, thiscov, refcov)) - - def testIterateAll(self): - '''check random access per contig''' - self.checkRange(None) - - def testIteratePerContig(self): - '''check random access per contig''' - for contig in self.samfile.references: - self.checkRange(contig) - - def testIterateRanges(self): - '''check random access per range''' - for contig, length in zip( - self.samfile.references, self.samfile.lengths): - for start in range(1, length, 90): - # this includes empty ranges - self.checkRange(contig, start, start + 90) - - def testInverse(self): - '''test the inverse, is point-wise pileup accurate.''' - for contig, refseq in list(self.mCoverages.items()): - refcolumns = sum(refseq) - for pos, refcov in enumerate(refseq): - columns = list(self.samfile.pileup(contig, pos, pos + 1)) - if refcov == 0: - # if no read, no coverage - self.assertEqual( - len(columns), - refcov, - "wrong number of pileup columns returned for position %s:%i, %i should be %i" % ( - contig, pos, - len(columns), refcov)) - elif refcov == 1: - # one read, all columns of the read are returned - self.assertEqual( - len(columns), - refcolumns, - "pileup incomplete at position %i: got %i, expected %i " % - (pos, len(columns), refcolumns)) - - def testIterateTruncate(self): - '''check random access per range''' - for contig, length in zip(self.samfile.references, - self.samfile.lengths): - for start in range(1, length, 90): - # this includes empty ranges - self.checkRange(contig, start, start + 90, truncate=True) - - def tearDown(self): - self.samfile.close() - - class TestIteratorRowCRAM(TestIteratorRowBAM): - filename = os.path.join(DATADIR, "ex2.cram") + filename = os.path.join(BAM_DATADIR, "ex2.cram") mode = "rc" class TestIteratorRowCRAMWithReferenceFilename(TestIteratorRowCRAM): - reference_filename = os.path.join(DATADIR, "ex1.fa") + reference_filename = os.path.join(BAM_DATADIR, "ex1.fa") -########################################################## -########################################################## -########################################################## # needs to be implemented # class TestAlignedSegmentFromSamWithoutHeader(TestAlignedSegmentFromBam): # @@ -1092,50 +1001,6 @@ class TestIteratorRowCRAMWithReferenceFilename(TestIteratorRowCRAM): # self.reads=list(self.samfile.fetch()) -class TestIteratorColumn2(unittest.TestCase): - - '''test iterator column against contents of ex1.bam.''' - - def setUp(self): - self.samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex1.bam"), - "rb") - - def testStart(self): - # print self.samfile.fetch().next().reference_start - # print self.samfile.pileup().next().reference_start - pass - - def testTruncate(self): - '''see issue 107.''' - # note that ranges in regions start from 1 - p = self.samfile.pileup(region='chr1:170:172', truncate=True) - columns = [x.reference_pos for x in p] - self.assertEqual(len(columns), 3) - self.assertEqual(columns, [169, 170, 171]) - - p = self.samfile.pileup('chr1', 169, 172, truncate=True) - columns = [x.reference_pos for x in p] - - self.assertEqual(len(columns), 3) - self.assertEqual(columns, [169, 170, 171]) - - def testAccessOnClosedIterator(self): - '''see issue 131 - - Accessing pileup data after iterator has closed. - ''' - pcolumn = self.samfile.pileup('chr1', 170, 180).__next__() - self.assertRaises(ValueError, getattr, pcolumn, "pileups") - - def testStr(self): - '''test if PileupRead can be printed.''' - iter = self.samfile.pileup('chr1', 170, 180) - pcolumn = iter.__next__() - s = str(pcolumn) - self.assertEqual(len(s.split("\n")), 2) - - class TestFloatTagBug(unittest.TestCase): '''see issue 71''' @@ -1145,7 +1010,7 @@ def testFloatTagBug(self): Fixed in 0.1.19 ''' - samfile = pysam.AlignmentFile(os.path.join(DATADIR, "tag_bug.bam")) + samfile = pysam.AlignmentFile(os.path.join(BAM_DATADIR, "tag_bug.bam")) read = next(samfile.fetch(until_eof=True)) self.assertTrue(('XC', 1) in read.tags) self.assertEqual(read.opt('XC'), 1) @@ -1160,123 +1025,20 @@ def testLargeFileBug(self): causes an error: NotImplementedError: tags field too large ''' - samfile = pysam.AlignmentFile(os.path.join(DATADIR, "issue100.bam")) + samfile = pysam.AlignmentFile( + os.path.join(BAM_DATADIR, "issue100.bam")) read = next(samfile.fetch(until_eof=True)) new_read = pysam.AlignedSegment() new_read.tags = read.tags self.assertEqual(new_read.tags, read.tags) -class TestTagParsing(unittest.TestCase): - - '''tests checking the accuracy of tag setting and retrieval.''' - - def makeRead(self): - a = pysam.AlignedSegment() - a.query_name = "read_12345" - a.reference_id = 0 - a.query_sequence = "ACGT" * 3 - a.flag = 0 - a.reference_id = 0 - a.reference_start = 1 - a.mapping_quality = 20 - a.cigartuples = ((0, 10), (2, 1), (0, 25)) - a.next_reference_id = 0 - a.next_reference_start = 200 - a.template_length = 0 - a.query_qualities = pysam.qualitystring_to_array("1234") * 3 - # todo: create tags - return a - - def testNegativeIntegers(self): - x = -2 - aligned_read = self.makeRead() - aligned_read.tags = [("XD", int(x))] - self.assertEqual(aligned_read.opt('XD'), x) - # print (aligned_read.tags) - - def testNegativeIntegers2(self): - x = -2 - r = self.makeRead() - r.tags = [("XD", int(x))] - outfile = pysam.AlignmentFile( - "test.bam", - "wb", - referencenames=("chr1",), - referencelengths = (1000,)) - outfile.write(r) - outfile.close() - - def testCigarString(self): - r = self.makeRead() - self.assertEqual(r.cigarstring, "10M1D25M") - r.cigarstring = "20M10D20M" - self.assertEqual(r.cigartuples, [(0, 20), (2, 10), (0, 20)]) - # unsetting cigar string - r.cigarstring = None - self.assertEqual(r.cigarstring, None) - - def testCigar(self): - r = self.makeRead() - self.assertEqual(r.cigartuples, [(0, 10), (2, 1), (0, 25)]) - # unsetting cigar string - r.cigartuples = None - self.assertEqual(r.cigartuples, None) - - def testLongTags(self): - '''see issue 115''' - - r = self.makeRead() - rg = 'HS2000-899_199.L3' - tags = [('XC', 85), ('XT', 'M'), ('NM', 5), - ('SM', 29), ('AM', 29), ('XM', 1), - ('XO', 1), ('XG', 4), ('MD', '37^ACCC29T18'), - ('XA', '5,+11707,36M1I48M,2;21,-48119779,46M1I38M,2;hs37d5,-10060835,40M1D45M,3;5,+11508,36M1I48M,3;hs37d5,+6743812,36M1I48M,3;19,-59118894,46M1I38M,3;4,-191044002,6M1I78M,3;')] - - r.tags = tags - r.tags += [("RG", rg)] * 100 - tags += [("RG", rg)] * 100 - - self.assertEqual(tags, r.tags) - - def testArrayTags(self): - - r = self.makeRead() - - def c(r, l): - r.tags = [('ZM', l)] - self.assertEqual(list(r.opt("ZM")), list(l)) - - # signed integers - c(r, (-1, 1)) - c(r, (-1, 100)) - c(r, (-1, 200)) - c(r, (-1, 1000)) - c(r, (-1, 30000)) - c(r, (-1, 50000)) - c(r, (1, -1)) - c(r, (1, -100)) - c(r, (1, -200)) - c(r, (1, -1000)) - c(r, (1, -30000)) - c(r, (1, -50000)) - - # unsigned integers - c(r, (1, 100)) - c(r, (1, 1000)) - c(r, (1, 10000)) - c(r, (1, 100000)) - - # floats - c(r, (1.0, 100.0)) - - class TestClipping(unittest.TestCase): def testClipping(self): self.samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "softclip.bam"), + os.path.join(BAM_DATADIR, "softclip.bam"), "rb") for read in self.samfile: @@ -1287,7 +1049,8 @@ def testClipping(self): self.assertEqual(pysam.qualities_to_qualitystring(read.query_qualities), None) self.assertEqual( - pysam.qualities_to_qualitystring(read.query_alignment_qualities), + pysam.qualities_to_qualitystring( + read.query_alignment_qualities), None) elif read.query_name == "r002": @@ -1298,7 +1061,8 @@ def testClipping(self): pysam.qualities_to_qualitystring(read.query_qualities), '01234567890') self.assertEqual( - pysam.qualities_to_qualitystring(read.query_alignment_qualities), + pysam.qualities_to_qualitystring( + read.query_alignment_qualities), '567890') elif read.query_name == "r003": @@ -1309,7 +1073,8 @@ def testClipping(self): pysam.qualities_to_qualitystring(read.query_qualities), '01234567890') self.assertEqual( - pysam.qualities_to_qualitystring(read.query_alignment_qualities), + pysam.qualities_to_qualitystring( + read.query_alignment_qualities), '012345') elif read.query_name == "r004": @@ -1320,277 +1085,80 @@ def testClipping(self): pysam.qualities_to_qualitystring(read.query_qualities), '01234') self.assertEqual( - pysam.qualities_to_qualitystring(read.query_alignment_qualities), + pysam.qualities_to_qualitystring( + read.query_alignment_qualities), '01234') -class TestHeaderSAM(unittest.TestCase): - - """testing header manipulation""" - - header = {'SQ': [{'LN': 1575, 'SN': 'chr1', 'AH': 'chr1:5000000-5010000'}, - {'LN': 1584, 'SN': 'chr2', 'AH': '*'}], - 'RG': [{'LB': 'SC_1', 'ID': 'L1', 'SM': 'NA12891', - 'PU': 'SC_1_10', "CN": "name:with:colon"}, - {'LB': 'SC_2', 'ID': 'L2', 'SM': 'NA12891', - 'PU': 'SC_2_12', "CN": "name:with:colon"}], - 'PG': [{'ID': 'P1', 'VN': '1.0'}, {'ID': 'P2', 'VN': '1.1'}], - 'HD': {'VN': '1.0'}, - 'CO': ['this is a comment', 'this is another comment'], - } - - def compareHeaders(self, a, b): - '''compare two headers a and b.''' - for ak, av in a.items(): - self.assertTrue(ak in b, "key '%s' not in '%s' " % (ak, b)) - self.assertEqual(av, b[ak]) - - def setUp(self): - self.samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex3.sam"), - "r") - - def testHeaders(self): - self.compareHeaders(self.header, self.samfile.header) - self.compareHeaders(self.samfile.header, self.header) - - def testNameMapping(self): - for x, y in enumerate(("chr1", "chr2")): - tid = self.samfile.gettid(y) - ref = self.samfile.getrname(x) - self.assertEqual(tid, x) - self.assertEqual(ref, y) - - self.assertEqual(self.samfile.gettid("chr?"), -1) - self.assertRaises(ValueError, self.samfile.getrname, 2) - - def tearDown(self): - self.samfile.close() - - -class TestHeaderBAM(TestHeaderSAM): - - def setUp(self): - self.samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex3.bam"), - "rb") - - -class TestHeaderCRAM(TestHeaderSAM): - - def setUp(self): - self.samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex3.cram"), - "rc") - - def compareHeaders(self, a, b): - '''compare two headers a and b.''' - def _strip(dd): - for x in dd: - for y in ("M5", "UR"): - if y in x: - del x[y] - - for ak, av in a.items(): - _strip(av) - self.assertTrue(ak in b, "key '%s' not in '%s' " % (ak, b)) - _strip(b[ak]) - - self.assertEqual(av, b[ak]) - - -class TestHeaderFromRefs(unittest.TestCase): - - '''see issue 144 - - reference names need to be converted to string for python 3 - ''' - - # def testHeader( self ): - # refs = ['chr1', 'chr2'] - # tmpfile = "tmp_%i" % id(self) - # s = pysam.AlignmentFile(tmpfile, 'wb', - # referencenames=refs, - # referencelengths=[100]*len(refs)) - # s.close() - - # self.assertTrue( checkBinaryEqual( 'issue144.bam', tmpfile ), - # 'bam files differ') - # os.unlink( tmpfile ) - - -class TestHeader1000Genomes(unittest.TestCase): - - '''see issue 110''' - # bamfile = "http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/phase2b_alignment/data/NA07048/exome_alignment/NA07048.unmapped.ILLUMINA.bwa.CEU.exome.20120522_p2b.bam" - bamfile = "http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/phase3_EX_or_LC_only_alignment/data/HG00104/alignment/HG00104.chrom11.ILLUMINA.bwa.GBR.low_coverage.20130415.bam" - - def testRead(self): - - if not checkURL(self.bamfile): - return - - f = pysam.AlignmentFile(self.bamfile, "rb") - data = f.header.copy() - self.assertTrue(data) - - -class TestHeaderWriteRead(unittest.TestCase): - header = {'SQ': [{'LN': 1575, 'SN': 'chr1'}, - {'LN': 1584, 'SN': 'chr2'}], - 'RG': [{'LB': 'SC_1', 'ID': 'L1', 'SM': 'NA12891', - 'PU': 'SC_1_10', "CN": "name:with:colon"}, - {'LB': 'SC_2', 'ID': 'L2', 'SM': 'NA12891', - 'PU': 'SC_2_12', "CN": "name:with:colon"}], - 'PG': [{'ID': 'P1', 'VN': '1.0', 'CL': 'tool'}, - {'ID': 'P2', 'VN': '1.1', 'CL': 'tool with in option -R a\tb', - 'PP': 'P1'}], - 'HD': {'VN': '1.0'}, - 'CO': ['this is a comment', 'this is another comment'], - } - - def compare_headers(self, a, b): - '''compare two headers a and b. - - Ignore M5 and UR field as they are set application specific. - ''' - for ak, av in a.items(): - self.assertTrue(ak in b, "key '%s' not in '%s' " % (ak, b)) - self.assertEqual( - len(av), len(b[ak]), - "unequal number of entries for key {}: {} vs {}" - .format(ak, av, b[ak])) - - for row_a, row_b in zip(av, b[ak]): - if isinstance(row_b, dict): - for x in ["M5", "UR"]: - try: - del row_b[x] - except KeyError: - pass - self.assertEqual(row_a, row_b) - - def check_read_write(self, flag_write, header): - - fn = get_temp_filename() - with pysam.AlignmentFile( - fn, - flag_write, - header=header, - reference_filename="pysam_data/ex1.fa") as outf: - a = pysam.AlignedSegment() - a.query_name = "abc" - outf.write(a) - - with pysam.AlignmentFile(fn) as inf: - read_header = inf.header - - os.unlink(fn) - self.compare_headers(header, read_header) - - def test_SAM(self): - self.check_read_write("wh", self.header) - - def test_BAM(self): - self.check_read_write("wb", self.header) - - def test_CRAM(self): - header = copy.copy(self.header) - # for CRAM, \t needs to be quoted: - header['PG'][1]['CL'] = re.sub(r"\t", r"\\\\t", header['PG'][1]['CL']) - self.check_read_write("wc", header) - - -class TestUnmappedReads(unittest.TestCase): - - # TODO - # def testSAM(self): - # samfile = pysam.AlignmentFile(os.path.join(DATADIR, "ex5.sam"), - # "r") - # self.assertEqual(len(list(samfile.fetch(until_eof=True))), 2) - # samfile.close() - - def testBAM(self): - samfile = pysam.AlignmentFile(os.path.join(DATADIR, "ex5.bam"), - "rb") - self.assertEqual(len(list(samfile.fetch(until_eof=True))), 2) - samfile.close() - +class TestUnmappedReadsRetrieval(unittest.TestCase): -class TestPileupObjects(unittest.TestCase): - - def setUp(self): - self.samfile = pysam.AlignmentFile(os.path.join(DATADIR, "ex1.bam"), - "rb") - - def testPileupColumn(self): - for pcolumn1 in self.samfile.pileup(region="chr1:105"): - if pcolumn1.reference_pos == 104: - self.assertEqual( - pcolumn1.reference_id, 0, - "chromosome/target id mismatch in position 1: %s != %s" % - (pcolumn1.reference_id, 0)) - self.assertEqual( - pcolumn1.reference_pos, 105 - 1, - "position mismatch in position 1: %s != %s" % - (pcolumn1.reference_pos, 105 - 1)) - self.assertEqual( - pcolumn1.nsegments, 2, - "# reads mismatch in position 1: %s != %s" % - (pcolumn1.nsegments, 2)) - for pcolumn2 in self.samfile.pileup(region="chr2:1480"): - if pcolumn2.reference_pos == 1479: - self.assertEqual( - pcolumn2.reference_id, 1, - "chromosome/target id mismatch in position 1: %s != %s" % - (pcolumn2.reference_id, 1)) - self.assertEqual( - pcolumn2.reference_pos, 1480 - 1, - "position mismatch in position 1: %s != %s" % - (pcolumn2.reference_pos, 1480 - 1)) - self.assertEqual( - pcolumn2.nsegments, 12, - "# reads mismatch in position 1: %s != %s" % - (pcolumn2.nsegments, 12)) - - def testPileupRead(self): - for pcolumn1 in self.samfile.pileup(region="chr1:105"): - if pcolumn1.reference_pos == 104: - self.assertEqual( - len(pcolumn1.pileups), 2, - "# reads aligned to column mismatch in position 1" - ": %s != %s" % - (len(pcolumn1.pileups), 2)) - - # self.assertEqual( pcolumn1.pileups[0] # need to test additional - # properties here - - def tearDown(self): - self.samfile.close() + def test_fetch_from_sam_with_until_eof_reads_unmapped_reads(self): + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex5.sam"), + "rb") as samfile: + self.assertEqual(len(list(samfile.fetch(until_eof=True))), 2) - def testIteratorOutOfScope(self): - '''test if exception is raised if pileup col is accessed after - iterator is exhausted.''' + def test_fetch_from_bam_with_until_eof_reads_unmapped_reads(self): + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex5.bam"), + "rb") as samfile: + self.assertEqual(len(list(samfile.fetch(until_eof=True))), 2) - for pileupcol in self.samfile.pileup(): - pass + def test_fetch_with_asterisk_only_returns_unmapped_reads(self): + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, "test_mapped_unmapped.bam"), + "rb") as samfile: + self.assertEqual(len(list(samfile.fetch(region="*"))), 4) - self.assertRaises(ValueError, getattr, pileupcol, "pileups") + def test_fetch_with_asterisk_only_returns_unmapped_reads_by_contig(self): + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, "test_mapped_unmapped.bam"), + "rb") as samfile: + self.assertEqual(len(list(samfile.fetch(contig="*"))), 4) class TestContextManager(unittest.TestCase): def testManager(self): - with pysam.AlignmentFile(os.path.join(DATADIR, 'ex1.bam'), + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, 'ex1.bam'), 'rb') as samfile: samfile.fetch() self.assertEqual(samfile.closed, True) +class TestMultiThread(unittest.TestCase): + + def testSingleThreadEqualsMultithread(self): + input_bam = os.path.join(BAM_DATADIR, 'ex1.bam') + single_thread_out = get_temp_filename("tmp_single.bam") + multi_thread_out = get_temp_filename("tmp_multi.bam") + with pysam.AlignmentFile(input_bam, + 'rb') as samfile: + reads = [r for r in samfile] + with pysam.AlignmentFile(single_thread_out, + mode='wb', + template=samfile, + threads=1) as single_out: + [single_out.write(r) for r in reads] + with pysam.AlignmentFile(multi_thread_out, + mode='wb', + template=samfile, + threads=2) as multi_out: + [single_out.write(r) for r in reads] + with pysam.AlignmentFile(input_bam) as inp, \ + pysam.AlignmentFile(single_thread_out) as single, \ + pysam.AlignmentFile(multi_thread_out) as multi: + for r1, r2, r3 in zip(inp, single, multi): + assert r1.to_string == r2.to_string == r3.to_string + + def TestNoMultiThreadingWithIgnoreTruncation(self): + self.assertRaises( + ValueError, pysam.AlignmentFile(os.path.join(BAM_DATADIR, 'ex1.bam'), + threads=2, + ignore_truncation=True) + ) + + class TestExceptions(unittest.TestCase): def setUp(self): - self.samfile = pysam.AlignmentFile(os.path.join(DATADIR, "ex1.bam"), + self.samfile = pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex1.bam"), "rb") def testMissingFile(self): @@ -1667,14 +1235,14 @@ class TestWrongFormat(unittest.TestCase): def testOpenSamAsBam(self): self.assertRaises(ValueError, pysam.AlignmentFile, - os.path.join(DATADIR, 'ex1.sam'), + os.path.join(BAM_DATADIR, 'ex1.sam'), 'rb') def testOpenBamAsSam(self): # test fails, needs to be implemented. # sam.fetch() fails on reading, not on opening - #self.assertRaises(ValueError, pysam.AlignmentFile, - # os.path.join(DATADIR, 'ex1.bam'), + # self.assertRaises(ValueError, pysam.AlignmentFile, + # os.path.join(BAM_DATADIR, 'ex1.bam'), # 'r') pass @@ -1687,7 +1255,7 @@ def testOpenFastaAsSam(self): def testOpenFastaAsBam(self): self.assertRaises(ValueError, pysam.AlignmentFile, - os.path.join(DATADIR, 'ex1.fa'), + os.path.join(BAM_DATADIR, 'ex1.fa'), 'rb') @@ -1699,18 +1267,20 @@ class TestDeNovoConstruction(unittest.TestCase): read_28833_29006_6945 99 chr1 33 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 RG:Z:L1 read_28701_28881_323b 147 chr2 88 30 35M = 500 412 ACCTATATCTTGGCCTTGGCCGATGCGGCCTTGCA <<<<<;<<<<7;:<<<6;<<<<<<<<<<<<7<<<< MF:i:18 RG:Z:L2 - ''' + ''' # noqa header = {'HD': {'VN': '1.0'}, 'SQ': [{'LN': 1575, 'SN': 'chr1'}, {'LN': 1584, 'SN': 'chr2'}], } - bamfile = os.path.join(DATADIR, "ex6.bam") - samfile = os.path.join(DATADIR, "ex6.sam") + bamfile = os.path.join(BAM_DATADIR, "ex6.bam") + samfile = os.path.join(BAM_DATADIR, "ex6.sam") def setUp(self): - a = pysam.AlignedSegment() + header = pysam.AlignmentHeader.from_dict(self.header) + + a = pysam.AlignedSegment(header) a.query_name = "read_28833_29006_6945" a.query_sequence = "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG" a.flag = 99 @@ -1726,7 +1296,7 @@ def setUp(self): a.tags = (("NM", 1), ("RG", "L1")) - b = pysam.AlignedSegment() + b = pysam.AlignedSegment(header) b.query_name = "read_28701_28881_323b" b.query_sequence = "ACCTATATCTTGGCCTTGGCCGATGCGGCCTTGCA" b.flag = 147 @@ -1761,14 +1331,14 @@ def setUp(self): # os.unlink(tmpfilename) - def testBAMPerRead(self): + def test_pass_if_reads_binary_equal(self): '''check if individual reads are binary equal.''' infile = pysam.AlignmentFile(self.bamfile, "rb") - others = list(infile) - for denovo, other in zip(others, self.reads): - checkFieldEqual(self, other, denovo) - self.assertEqual(other.compare(denovo), 0) + references = list(infile) + for denovo, reference in zip(references, self.reads): + checkFieldEqual(self, reference, denovo) + self.assertEqual(reference.compare(denovo), 0) # TODO # def testSAMPerRead(self): @@ -1809,29 +1379,33 @@ class TestDeNovoConstructionUserTags(TestDeNovoConstruction): 'x3': {'A': 6, 'B': 5}, 'x2': {'A': 4, 'B': 5}} - bamfile = os.path.join(DATADIR, "example_user_header.bam") - samfile = os.path.join(DATADIR, "example_user_header.sam") + bamfile = os.path.join(BAM_DATADIR, "example_user_header.bam") + samfile = os.path.join(BAM_DATADIR, "example_user_header.sam") class TestEmptyHeader(unittest.TestCase): - '''see issue 84.''' def testEmptyHeader(self): - s = pysam.AlignmentFile(os.path.join(DATADIR, + s = pysam.AlignmentFile(os.path.join(BAM_DATADIR, 'example_empty_header.bam')) - self.assertEqual(s.header, {'SQ': [{'LN': 1000, 'SN': 'chr1'}]}) + self.assertEqual(s.header.to_dict(), {'SQ': [{'LN': 1000, 'SN': 'chr1'}]}) + def test_bam_without_seq_in_header(self): + s = pysam.AlignmentFile(os.path.join(BAM_DATADIR, "example_no_seq_in_header.bam")) + self.assertTrue("SQ" in s.header.to_dict()) + self.assertTrue("@SQ" in str(s.header)) + class TestHeaderWithProgramOptions(unittest.TestCase): '''see issue 39.''' def testHeader(self): - s = pysam.AlignmentFile(os.path.join(DATADIR, + s = pysam.AlignmentFile(os.path.join(BAM_DATADIR, 'rg_with_tab.bam')) self.assertEqual( - s.header, + s.header.to_dict(), {'SQ': [{'LN': 1575, 'SN': 'chr1'}, {'LN': 1584, 'SN': 'chr2'}], 'PG': [{'PN': 'bwa', @@ -1846,25 +1420,19 @@ class TestTruncatedBAM(unittest.TestCase): '''see pull request 50.''' - def testTruncatedBam(self): + def testTruncatedBam2(self): + self.assertRaises(IOError, + pysam.AlignmentFile, + os.path.join(BAM_DATADIR, 'ex2_truncated.bam')) + + def testTruncatedBam2(self): + s = pysam.AlignmentFile(os.path.join(BAM_DATADIR, 'ex2_truncated.bam'), + ignore_truncation=True) - s = pysam.AlignmentFile( - os.path.join(DATADIR, 'ex2_truncated.bam')) - iterall = lambda x: len([a for a in x]) + def iterall(x): + return len([a for a in x]) self.assertRaises(IOError, iterall, s) - def testTruncatedBamFetch(self): - '''See comments for pull request at - https://github.com/pysam-developers/pysam/pull/50#issuecomment-64928625 - ''' - # Currently there is no way to detect truncated - # files through hts_iter_fetch, so this test is - # disabled - return - s = pysam.AlignmentFile( - os.path.join(DATADIR, 'ex2_truncated.bam')) - iterall = lambda x: len([a for a in x]) - self.assertRaises(IOError, iterall, s.fetch()) COMPARE_BTAG = [100, 1, 91, 0, 7, 101, 0, 201, 96, 204, 0, 0, 87, 109, 0, 7, 97, 112, 1, 12, 78, @@ -1890,6 +1458,7 @@ def testTruncatedBamFetch(self): 295, 0, 200, 16, 172, 3, 16, 182, 3, 11, 0, 0, 223, 111, 103, 0, 5, 225, 0, 95] + class TestBTagSam(unittest.TestCase): '''see issue 81.''' @@ -1900,7 +1469,7 @@ class TestBTagSam(unittest.TestCase): [12, 15], [-1.0, 5.0, 2.5]] - filename = os.path.join(DATADIR, 'example_btag.sam') + filename = os.path.join(BAM_DATADIR, 'example_btag.sam') read0 = [('RG', 'QW85I'), ('PG', 'tmap'), @@ -1921,14 +1490,14 @@ def testReadTags(self): tags = read.tags if x == 0: self.assertEqual(tags, self.read0) - + fz = list(dict(tags)["FZ"]) self.assertEqual(fz, self.compare[x]) self.assertEqual(list(read.opt("FZ")), self.compare[x]) self.assertEqual(tags, read.get_tags()) for tag, value in tags: self.assertEqual(value, read.get_tag(tag)) - + def testReadWriteTags(self): s = pysam.AlignmentFile(self.filename) @@ -1936,7 +1505,7 @@ def testReadWriteTags(self): before = read.tags read.tags = before self.assertEqual(read.tags, before) - + read.set_tags(before) self.assertEqual(read.tags, before) @@ -1946,13 +1515,13 @@ def testReadWriteTags(self): class TestBTagBam(TestBTagSam): - filename = os.path.join(DATADIR, 'example_btag.bam') + filename = os.path.join(BAM_DATADIR, 'example_btag.bam') class TestDoubleFetchBAM(unittest.TestCase): '''check if two iterators on the same bamfile are independent.''' - filename = os.path.join(DATADIR, 'ex1.bam') + filename = os.path.join(BAM_DATADIR, 'ex1.bam') mode = "rb" def testDoubleFetch(self): @@ -1962,22 +1531,43 @@ def testDoubleFetch(self): samfile1.fetch(multiple_iterators=True)): self.assertEqual(a.compare(b), 0) - def testDoubleFetchWithRegion(self): + def testDoubleFetchWithRegionTrueTrue(self): with pysam.AlignmentFile(self.filename, self.mode) as samfile1: - contig, start, stop = 'chr1', 200, 3000000 + contig, start, stop = 'chr2', 200, 3000000 # just making sure the test has something to catch self.assertTrue(len(list(samfile1.fetch(contig, start, stop))) > 0) - # see Issue #293 - # The following fails for CRAM files, but works for BAM - # files when the first is multiple_iterators=False: for a, b in zip(samfile1.fetch(contig, start, stop, multiple_iterators=True), samfile1.fetch(contig, start, stop, multiple_iterators=True)): self.assertEqual(a.compare(b), 0) + def testDoubleFetchWithRegionFalseTrue(self): + with pysam.AlignmentFile(self.filename, self.mode) as samfile1: + contig, start, stop = 'chr2', 200, 3000000 + # just making sure the test has something to catch + self.assertTrue(len(list(samfile1.fetch(contig, start, stop))) > 0) + + for a, b in zip(samfile1.fetch(contig, start, stop, + multiple_iterators=False), + samfile1.fetch(contig, start, stop, + multiple_iterators=True)): + self.assertEqual(a.compare(b), 0) + + def testDoubleFetchWithRegionTrueFalse(self): + with pysam.AlignmentFile(self.filename, self.mode) as samfile1: + contig, start, stop = 'chr2', 200, 3000000 + # just making sure the test has something to catch + self.assertTrue(len(list(samfile1.fetch(contig, start, stop))) > 0) + + for a, b in zip(samfile1.fetch(contig, start, stop, + multiple_iterators=True), + samfile1.fetch(contig, start, stop, + multiple_iterators=False)): + self.assertEqual(a.compare(b), 0) + def testDoubleFetchUntilEOF(self): with pysam.AlignmentFile(self.filename, self.mode) as samfile1: @@ -1989,14 +1579,14 @@ def testDoubleFetchUntilEOF(self): class TestDoubleFetchCRAM(TestDoubleFetchBAM): - filename = os.path.join(DATADIR, 'ex2.cram') + filename = os.path.join(BAM_DATADIR, 'ex2.cram') mode = "rc" class TestDoubleFetchCRAMWithReference(TestDoubleFetchBAM): - filename = os.path.join(DATADIR, 'ex2.cram') + filename = os.path.join(BAM_DATADIR, 'ex2.cram') mode = "rc" - reference_filename = os.path.join(DATADIR, 'ex1.fa') + reference_filename = os.path.join(BAM_DATADIR, 'ex1.fa') class TestRemoteFileFTP(unittest.TestCase): @@ -2013,7 +1603,7 @@ class TestRemoteFileFTP(unittest.TestCase): def testFTPView(self): return - if not checkURL(self.url): + if not check_url(self.url): return result = pysam.samtools.view(self.url, self.region) @@ -2021,7 +1611,7 @@ def testFTPView(self): def testFTPFetch(self): return - if not checkURL(self.url): + if not check_url(self.url): return samfile = pysam.AlignmentFile(self.url, "rb") @@ -2033,10 +1623,10 @@ class TestRemoteFileHTTP(unittest.TestCase): url = "http://genserv.anat.ox.ac.uk/downloads/pysam/test/ex1.bam" region = "chr1:1-1000" - local = os.path.join(DATADIR, "ex1.bam") + local = os.path.join(BAM_DATADIR, "ex1.bam") def testView(self): - if not checkURL(self.url): + if not check_url(self.url): return samfile_local = pysam.AlignmentFile(self.local, "rb") @@ -2046,7 +1636,7 @@ def testView(self): self.assertEqual(len(result.splitlines()), len(ref)) def testFetch(self): - if not checkURL(self.url): + if not check_url(self.url): return with pysam.AlignmentFile(self.url, "rb") as samfile: @@ -2060,7 +1650,7 @@ def testFetch(self): self.assertEqual(x.compare(y), 0) def testFetchAll(self): - if not checkURL(self.url): + if not check_url(self.url): return with pysam.AlignmentFile(self.url, "rb") as samfile: @@ -2111,108 +1701,64 @@ def check(self, samfile): def testSAM(self): samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex10.sam"), + os.path.join(BAM_DATADIR, "ex10.sam"), "r") self.check(samfile) def testBAM(self): samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex10.bam"), + os.path.join(BAM_DATADIR, "ex10.bam"), "rb") self.check(samfile) -class TestPileup(unittest.TestCase): - - '''test pileup functionality.''' - - samfilename = "pysam_data/ex1.bam" - fastafilename = "pysam_data/ex1.fa" - - def setUp(self): - - self.samfile = pysam.AlignmentFile(self.samfilename) - self.fastafile = pysam.Fastafile(self.fastafilename) - - def tearDown(self): - self.samfile.close() - self.fastafile.close() - - def checkEqual(self, references, iterator): - - for x, column in enumerate(iterator): - v = references[x][:-1].split("\t") - self.assertEqual( - len(v), 6, - "expected 6 values, got {}".format(v)) - (contig, pos, reference_base, - read_bases, read_qualities, alignment_mapping_qualities) \ - = v - self.assertEqual(int(pos) - 1, column.reference_pos) - - def testSamtoolsStepper(self): - refs = force_str( - pysam.samtools.mpileup( - "-f", self.fastafilename, - self.samfilename)).splitlines(True) - iterator = self.samfile.pileup( - stepper="samtools", - fastafile=self.fastafile) - self.checkEqual(refs, iterator) - - def testAllStepper(self): - refs = force_str( - pysam.samtools.mpileup( - "-f", self.fastafilename, - "-A", "-B", - self.samfilename)).splitlines(True) - - iterator = self.samfile.pileup( - stepper="all", - fastafile=self.fastafile) - self.checkEqual(refs, iterator) - - class TestCountCoverage(unittest.TestCase): - samfilename = "pysam_data/ex1.bam" - fastafilename = "pysam_data/ex1.fa" + samfilename = os.path.join(BAM_DATADIR, "ex1.bam") + fastafilename = os.path.join(BAM_DATADIR, "ex1.fa") def setUp(self): - self.samfile = pysam.AlignmentFile(self.samfilename) self.fastafile = pysam.Fastafile(self.fastafilename) - - samfile = pysam.AlignmentFile( - "test_count_coverage_read_all.bam", 'wb', - template=self.samfile) - for ii, read in enumerate(self.samfile.fetch()): - # if ii % 2 == 0: # setting BFUNMAP makes no sense... - #read.flag = read.flag | 0x4 - if ii % 3 == 0: - read.flag = read.flag | 0x100 - if ii % 5 == 0: - read.flag = read.flag | 0x200 - if ii % 7 == 0: - read.flag = read.flag | 0x400 - samfile.write(read) - samfile.close() - pysam.samtools.index("test_count_coverage_read_all.bam") + self.tmpfilename = get_temp_filename(".bam") + + with pysam.AlignmentFile(self.samfilename) as inf: + with pysam.AlignmentFile( + self.tmpfilename, + 'wb', + template=inf) as outf: + for ii, read in enumerate(inf.fetch()): + # if ii % 2 == 0: # setting BFUNMAP makes no sense... + #read.flag = read.flag | 0x4 + if ii % 3 == 0: + read.flag = read.flag | 0x100 + if ii % 5 == 0: + read.flag = read.flag | 0x200 + if ii % 7 == 0: + read.flag = read.flag | 0x400 + outf.write(read) + pysam.samtools.index(self.tmpfilename) def tearDown(self): - self.samfile.close() self.fastafile.close() + os.unlink(self.tmpfilename) + os.unlink(self.tmpfilename + ".bai") - def count_coverage_python(self, bam, chrom, start, stop, + def count_coverage_python(self, + bam, chrom, start, stop, read_callback, quality_threshold=15): + stop = min(stop, bam.get_reference_length(chrom)) l = stop - start count_a = array.array('L', [0] * l) count_c = array.array('L', [0] * l) count_g = array.array('L', [0] * l) count_t = array.array('L', [0] * l) - for p in bam.pileup(chrom, start, stop, truncate=True, - stepper='nofilter'): + for p in bam.pileup(chrom, start, stop, + truncate=True, + stepper='nofilter', + min_base_quality=quality_threshold, + ignore_overlaps=False): rpos = p.reference_pos - start for read in p.pileups: if not read.is_del and not read.is_refskip and \ @@ -2233,18 +1779,56 @@ def count_coverage_python(self, bam, chrom, start, stop, pass return count_a, count_c, count_g, count_t - def test_count_coverage(self): + def test_count_coverage_with_coordinates_works(self): + + with pysam.AlignmentFile(self.samfilename) as inf: + c = inf.count_coverage("chr1") + self.assertEqual(len(c[0]), inf.get_reference_length("chr1")) + self.assertEqual(len(c[0]), 1575) + + c = inf.count_coverage("chr1", 100) + self.assertEqual(len(c[0]), inf.get_reference_length("chr1") - 100) + + c = inf.count_coverage("chr1", 100, 200) + self.assertEqual(len(c[0]), 200 - 100) + + c = inf.count_coverage("chr1", None, 200) + self.assertEqual(len(c[0]), 200) + + c = inf.count_coverage("chr1", None, inf.get_reference_length("chr1") + 10000) + self.assertEqual(len(c[0]), inf.get_reference_length("chr1")) + + def test_count_coverage_without_coordinates_fails(self): + with pysam.AlignmentFile(self.samfilename) as inf: + self.assertRaises(TypeError, inf.count_coverage) + + def test_count_coverage_wrong_coordinates_fails(self): + with pysam.AlignmentFile(self.samfilename) as inf: + self.assertRaises(ValueError, inf.count_coverage, "chr1", 200, 100) + self.assertRaises(KeyError, inf.count_coverage, "chrUnknown", 100, 200) + + def test_counting_the_same_region_works(self): + + with pysam.AlignmentFile(self.samfilename) as inf: + c1 = inf.count_coverage("chr1") + c2 = inf.count_coverage("chr1") + self.assertEqual(c1, c2) + + def test_count_coverage_counts_as_expected(self): chrom = 'chr1' start = 0 - stop = 2000 - manual_counts = self.count_coverage_python( - self.samfile, chrom, start, stop, - lambda read: True, - quality_threshold=0) - fast_counts = self.samfile.count_coverage( - chrom, start, stop, - read_callback=lambda read: True, - quality_threshold=0) + stop = 1000 + + with pysam.AlignmentFile(self.samfilename) as inf: + manual_counts = self.count_coverage_python( + inf, chrom, start, stop, + lambda read: True, + quality_threshold=0) + + fast_counts = inf.count_coverage( + chrom, start, stop, + read_callback=lambda read: True, + quality_threshold=0) self.assertEqual(list(fast_counts[0]), list(manual_counts[0])) self.assertEqual(list(fast_counts[1]), list(manual_counts[1])) @@ -2254,15 +1838,17 @@ def test_count_coverage(self): def test_count_coverage_quality_filter(self): chrom = 'chr1' start = 0 - stop = 2000 - manual_counts = self.count_coverage_python( - self.samfile, chrom, start, stop, - lambda read: True, - quality_threshold=0) - fast_counts = self.samfile.count_coverage( - chrom, start, stop, - read_callback=lambda read: True, - quality_threshold=15) + stop = 1000 + with pysam.AlignmentFile(self.samfilename) as inf: + manual_counts = self.count_coverage_python( + inf, chrom, start, stop, + lambda read: True, + quality_threshold=0) + fast_counts = inf.count_coverage( + chrom, start, stop, + read_callback=lambda read: True, + quality_threshold=15) + # we filtered harder, should be less for i in range(4): for r in range(start, stop): @@ -2271,22 +1857,25 @@ def test_count_coverage_quality_filter(self): def test_count_coverage_read_callback(self): chrom = 'chr1' start = 0 - stop = 2000 - manual_counts = self.count_coverage_python( - self.samfile, chrom, start, stop, - lambda read: read.flag & 0x10, - quality_threshold=0) - fast_counts = self.samfile.count_coverage( - chrom, start, stop, - read_callback=lambda read: True, - quality_threshold=0) - for i in range(4): - for r in range(start, stop): - self.assertTrue(fast_counts[i][r] >= manual_counts[i][r]) - fast_counts = self.samfile.count_coverage( - chrom, start, stop, - read_callback=lambda read: read.flag & 0x10, - quality_threshold=0) + stop = 1000 + with pysam.AlignmentFile(self.samfilename) as inf: + manual_counts = self.count_coverage_python( + inf, chrom, start, stop, + lambda read: read.flag & 0x10, + quality_threshold=0) + fast_counts = inf.count_coverage( + chrom, start, stop, + read_callback=lambda read: True, + quality_threshold=0) + + for i in range(4): + for r in range(start, stop): + self.assertTrue(fast_counts[i][r] >= manual_counts[i][r]) + + fast_counts = inf.count_coverage( + chrom, start, stop, + read_callback=lambda read: read.flag & 0x10, + quality_threshold=0) self.assertEqual(fast_counts[0], manual_counts[0]) self.assertEqual(fast_counts[1], manual_counts[1]) @@ -2297,17 +1886,16 @@ def test_count_coverage_read_all(self): chrom = 'chr1' start = 0 - stop = 2000 + stop = 1000 def filter(read): return not (read.flag & (0x4 | 0x100 | 0x200 | 0x400)) - with pysam.AlignmentFile("test_count_coverage_read_all.bam") as samfile: - + with pysam.AlignmentFile(self.tmpfilename) as samfile: fast_counts = samfile.count_coverage( chrom, start, stop, read_callback='all', - #read_callback = lambda read: ~(read.flag & (0x4 | 0x100 | 0x200 | 0x400)), + # read_callback = lambda read: ~(read.flag & (0x4 | 0x100 | 0x200 | 0x400)), quality_threshold=0) manual_counts = samfile.count_coverage( chrom, start, stop, @@ -2315,73 +1903,50 @@ def filter(read): read.flag & (0x4 | 0x100 | 0x200 | 0x400)), quality_threshold=0) - os.unlink("test_count_coverage_read_all.bam") - os.unlink("test_count_coverage_read_all.bam.bai") - self.assertEqual(fast_counts[0], manual_counts[0]) self.assertEqual(fast_counts[1], manual_counts[1]) self.assertEqual(fast_counts[2], manual_counts[2]) self.assertEqual(fast_counts[3], manual_counts[3]) def test_count_coverage_nofilter(self): - samfile = pysam.AlignmentFile( - "test_count_coverage_nofilter.bam", 'wb', template=self.samfile) - for ii, read in enumerate(self.samfile.fetch()): - # if ii % 2 == 0: # setting BFUNMAP makes no sense... - #read.flag = read.flag | 0x4 - if ii % 3 == 0: - read.flag = read.flag | 0x100 - if ii % 5 == 0: - read.flag = read.flag | 0x200 - if ii % 7 == 0: - read.flag = read.flag | 0x400 - samfile.write(read) - samfile.close() - pysam.samtools.index("test_count_coverage_nofilter.bam") + + with pysam.AlignmentFile(self.samfilename) as inf: + with pysam.AlignmentFile( + self.tmpfilename, 'wb', template=inf) as outf: + + for ii, read in enumerate(inf.fetch()): + # if ii % 2 == 0: # setting BFUNMAP makes no sense... + # read.flag = read.flag | 0x4 + if ii % 3 == 0: + read.flag = read.flag | 0x100 + if ii % 5 == 0: + read.flag = read.flag | 0x200 + if ii % 7 == 0: + read.flag = read.flag | 0x400 + outf.write(read) + + pysam.samtools.index(self.tmpfilename) chr = 'chr1' start = 0 - stop = 2000 - - with pysam.AlignmentFile("test_count_coverage_nofilter.bam") as samfile: + stop = 1000 - fast_counts = samfile.count_coverage(chr, start, stop, - read_callback='nofilter', - quality_threshold=0) + with pysam.AlignmentFile(self.tmpfilename) as inf: + fast_counts = inf.count_coverage(chr, start, stop, + read_callback='nofilter', + quality_threshold=0) - manual_counts = self.count_coverage_python(samfile, chr, start, stop, + manual_counts = self.count_coverage_python(inf, chr, start, stop, read_callback=lambda x: True, quality_threshold=0) - os.unlink("test_count_coverage_nofilter.bam") - os.unlink("test_count_coverage_nofilter.bam.bai") self.assertEqual(fast_counts[0], manual_counts[0]) self.assertEqual(fast_counts[1], manual_counts[1]) self.assertEqual(fast_counts[2], manual_counts[2]) self.assertEqual(fast_counts[3], manual_counts[3]) - - -class TestPileupQueryPosition(unittest.TestCase): - - filename = "test_query_position.bam" - - def testPileup(self): - last = {} - with pysam.AlignmentFile(os.path.join(DATADIR, self.filename)) as inf: - for col in inf.pileup(): - for r in col.pileups: - # print r.alignment.query_name - # print r.query_position, r.query_position_or_next, r.is_del - if r.is_del: - self.assertEqual(r.query_position, None) - self.assertEqual(r.query_position_or_next, - last[r.alignment.query_name] + 1) - else: - self.assertNotEqual(r.query_position, None) - last[r.alignment.query_name] = r.query_position - + class TestFindIntrons(unittest.TestCase): - samfilename = "pysam_data/ex_spliced.bam" + samfilename = os.path.join(BAM_DATADIR, "ex_spliced.bam") def setUp(self): self.samfile = pysam.AlignmentFile(self.samfilename) @@ -2392,16 +1957,18 @@ def tearDown(self): def test_total(self): all_read_counts = self.samfile.count() splice_sites = self.samfile.find_introns(self.samfile.fetch()) - self.assertEqual(sum(splice_sites.values()), all_read_counts -1) # there is a single unspliced read in there - + # there is a single unspliced read in there + self.assertEqual(sum(splice_sites.values()), all_read_counts - 1) + def test_first(self): reads = list(self.samfile.fetch())[:10] splice_sites = self.samfile.find_introns(reads) - starts = [14792+38 - 1] - stops = [14792+38 + 140 - 1] + starts = [14792 + 38 - 1] + stops = [14792 + 38 + 140 - 1] self.assertEqual(len(splice_sites), 1) self.assertTrue((starts[0], stops[0]) in splice_sites) - self.assertEqual(splice_sites[(starts[0], stops[0])], 9) # first one is the unspliced read + # first one is the unspliced read + self.assertEqual(splice_sites[(starts[0], stops[0])], 9) def test_all(self): reads = list(self.samfile.fetch()) @@ -2416,8 +1983,8 @@ def test_all(self): (17055, 17605): 3, (17055, 17914): 1, (17368, 17605): 7, - }) - self.assertEqual(should, splice_sites) + }) + self.assertEqual(should, splice_sites) class TestLogging(unittest.TestCase): @@ -2443,21 +2010,21 @@ def check(self, bamfile, log): self.assertTrue(True) def testFail1(self): - self.check(os.path.join(DATADIR, "ex9_fail.bam"), + self.check(os.path.join(BAM_DATADIR, "ex9_fail.bam"), False) - self.check(os.path.join(DATADIR, "ex9_fail.bam"), + self.check(os.path.join(BAM_DATADIR, "ex9_fail.bam"), True) def testNoFail1(self): - self.check(os.path.join(DATADIR, "ex9_nofail.bam"), + self.check(os.path.join(BAM_DATADIR, "ex9_nofail.bam"), False) - self.check(os.path.join(DATADIR, "ex9_nofail.bam"), + self.check(os.path.join(BAM_DATADIR, "ex9_nofail.bam"), True) def testNoFail2(self): - self.check(os.path.join(DATADIR, "ex9_nofail.bam"), + self.check(os.path.join(BAM_DATADIR, "ex9_nofail.bam"), True) - self.check(os.path.join(DATADIR, "ex9_nofail.bam"), + self.check(os.path.join(BAM_DATADIR, "ex9_nofail.bam"), True) # TODOS @@ -2471,7 +2038,7 @@ class TestAlignmentFileUtilityFunctions(unittest.TestCase): def testCount(self): with pysam.AlignmentFile( - os.path.join(DATADIR, "ex1.bam"), + os.path.join(BAM_DATADIR, "ex1.bam"), "rb") as samfile: for contig in ("chr1", "chr2"): @@ -2509,7 +2076,7 @@ def testCount(self): def testMate(self): '''test mate access.''' - with open(os.path.join(DATADIR, "ex1.sam"), "rb") as inf: + with open(os.path.join(BAM_DATADIR, "ex1.sam"), "rb") as inf: readnames = [x.split(b"\t")[0] for x in inf.readlines()] if sys.version_info[0] >= 3: readnames = [name.decode('ascii') for name in readnames] @@ -2518,7 +2085,7 @@ def testMate(self): for x in readnames: counts[x] += 1 - with pysam.AlignmentFile(os.path.join(DATADIR, "ex1.bam"), + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex1.bam"), "rb") as samfile: for read in samfile.fetch(): @@ -2542,7 +2109,7 @@ def testMate(self): def testIndexStats(self): '''test if total number of mapped/unmapped reads is correct.''' - with pysam.AlignmentFile(os.path.join(DATADIR, "ex1.bam"), + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, "ex1.bam"), "rb") as samfile: self.assertEqual(samfile.mapped, 3235) self.assertEqual(samfile.unmapped, 35) @@ -2552,9 +2119,9 @@ def testIndexStats(self): class TestMappedUnmapped(unittest.TestCase): filename = "test_mapped_unmapped.bam" - def testMapped(self): + def test_counts_of_mapped_and_unmapped_are_correct(self): - with pysam.AlignmentFile(os.path.join(DATADIR, + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, self.filename)) as inf: unmapped_flag = 0 unmapped_nopos = 0 @@ -2587,6 +2154,32 @@ def testMapped(self): self.assertEqual(inf.count(until_eof=True, read_callback="all"), inf.mapped) + def test_counts_of_mapped_and_unmapped_are_correct_per_chromosome(self): + + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, + self.filename)) as inf: + + counts = inf.get_index_statistics() + + counts_contigs = [x.contig for x in counts] + self.assertEqual(sorted(counts_contigs), + sorted(inf.references)) + + for contig in inf.references: + unmapped_flag = 0 + unmapped_nopos = 0 + mapped_flag = 0 + for x in inf.fetch(contig=contig): + if x.is_unmapped: + unmapped_flag += 1 + else: + mapped_flag += 1 + + cc = [c for c in counts if c.contig == contig][0] + self.assertEqual(cc.mapped, mapped_flag) + self.assertEqual(cc.unmapped, unmapped_flag) + self.assertEqual(cc.total, mapped_flag + unmapped_flag) + class TestSamtoolsProxy(unittest.TestCase): @@ -2611,7 +2204,7 @@ class TestAlignmentFileIndex(unittest.TestCase): def testIndex(self): samfile = pysam.AlignmentFile( - os.path.join(DATADIR, "ex1.bam"), + os.path.join(BAM_DATADIR, "ex1.bam"), "rb") index = pysam.IndexedReads(samfile) index.build() @@ -2631,27 +2224,27 @@ class TestExplicitIndex(unittest.TestCase): def testExplicitIndexBAM(self): with pysam.AlignmentFile( - os.path.join(DATADIR, "explicit_index.bam"), + os.path.join(BAM_DATADIR, "explicit_index.bam"), "rb", - filepath_index=os.path.join(DATADIR, 'ex1.bam.bai')) as samfile: + filepath_index=os.path.join(BAM_DATADIR, 'ex1.bam.bai')) as samfile: samfile.fetch("chr1") def testExplicitIndexCRAM(self): with pysam.AlignmentFile( - os.path.join(DATADIR, "explicit_index.cram"), + os.path.join(BAM_DATADIR, "explicit_index.cram"), "rc", - filepath_index=os.path.join(DATADIR, 'ex1.cram.crai')) as samfile: + filepath_index=os.path.join(BAM_DATADIR, 'ex1.cram.crai')) as samfile: samfile.fetch("chr1") def testRemoteExplicitIndexBAM(self): - if not checkURL( + if not check_url( "http://genserv.anat.ox.ac.uk/downloads/pysam/test/noindex.bam"): return with pysam.AlignmentFile( "http://genserv.anat.ox.ac.uk/downloads/pysam/test/noindex.bam", "rb", - filepath_index=os.path.join(DATADIR, 'ex1.bam.bai')) as samfile: + filepath_index=os.path.join(BAM_DATADIR, 'ex1.bam.bai')) as samfile: samfile.fetch("chr1") @@ -2669,16 +2262,16 @@ def testVerbosity(self): class TestSanityCheckingBAM(unittest.TestCase): - + mode = "wb" def check_write(self, read): - + fn = "tmp_test_sanity_check.bam" names = ["chr1"] lengths = [10000] with pysam.AlignmentFile( - fn, + fn, self.mode, reference_names=names, reference_lengths=lengths) as outf: @@ -2686,20 +2279,109 @@ def check_write(self, read): if os.path.exists(fn): os.unlink(fn) - + def test_empty_read_gives_value_error(self): read = pysam.AlignedSegment() self.check_write(read) + +class TestHeader1000Genomes(unittest.TestCase): + + '''see issue 110''' + bamfile = "http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/phase3_EX_or_LC_only_alignment/data/HG00104/alignment/HG00104.chrom11.ILLUMINA.bwa.GBR.low_coverage.20130415.bam" # noqa + + def testRead(self): + + if not check_url(self.bamfile): + return + + f = pysam.AlignmentFile(self.bamfile, "rb") + data = f.header.copy() + self.assertTrue(data) + + +class TestLargeCigar(unittest.TestCase): + + def setUp(self): + self.read_length = 70000 + self.header = pysam.AlignmentHeader.from_references( + ["chr1", "chr2"], + [self.read_length * 2, self.read_length * 2]) + + def build_read(self): + '''build an example read.''' + + a = pysam.AlignedSegment(self.header) + l = self.read_length + a.query_name = "read_12345" + a.query_sequence = "A" * (l + 1) + a.flag = 0 + a.reference_id = 0 + a.reference_start = 20 + a.mapping_quality = 20 + a.cigarstring = "1M1D" * l + "1M" + self.assertEqual(len(a.cigartuples), 2 * l + 1) + a.next_reference_id = 0 + a.next_reference_start = 0 + a.template_length = l + a.query_qualities = pysam.qualitystring_to_array("1") * (l + 1) + return a + + def check_read(self, read, mode="bam"): + fn = get_temp_filename("tmp_largecigar.{}".format(mode)) + fn_reference = get_temp_filename("tmp_largecigar.fa") + + nrows = int(self.read_length * 2 / 80) + + s = "\n".join(["A" * 80 for x in range(nrows)]) + with open(fn_reference, "w") as outf: + outf.write(">chr1\n{seq}\n>chr2\n{seq}\n".format( + seq=s)) + + if mode == "bam": + write_mode = "wb" + elif mode == "sam": + write_mode = "w" + elif mode == "cram": + write_mode = "wc" + + with pysam.AlignmentFile(fn, write_mode, + header=self.header, + reference_filename=fn_reference) as outf: + outf.write(read) + + with pysam.AlignmentFile(fn) as inf: + ref_read = next(inf) + + if mode == "cram": + # in CRAM, the tag field is kept, while it is emptied by the BAM/SAM reader + self.assertEqual(read.cigarstring, ref_read.cigarstring) + else: + self.assertEqual(read, ref_read) + + os.unlink(fn) + os.unlink(fn_reference) + + def test_reading_writing_sam(self): + read = self.build_read() + self.check_read(read, mode="sam") + + def test_reading_writing_bam(self): + read = self.build_read() + self.check_read(read, mode="bam") + + def test_reading_writing_cram(self): + read = self.build_read() + self.check_read(read, mode="cram") + # SAM writing fails, as query length is 0 # class TestSanityCheckingSAM(TestSanityCheckingSAM): # mode = "w" - if __name__ == "__main__": # build data files - print ("building data files") - subprocess.call("make -C %s" % DATADIR, shell=True) - print ("starting tests") + print("building data files") + subprocess.call("make -C %s" % BAM_DATADIR, shell=True) + print("starting tests") unittest.main() - print ("completed tests") + print("completed tests") diff --git a/tests/PileupTestUtils.py b/tests/PileupTestUtils.py new file mode 100644 index 000000000..652bd5b4a --- /dev/null +++ b/tests/PileupTestUtils.py @@ -0,0 +1,160 @@ +import os +import subprocess +import pysam + +from TestUtils import BAM_DATADIR, force_str + +def build_pileup_with_samtoolsshell(fn): + os.system("samtools mpileup {} 2> /dev/null | wc -l > /dev/null".format(fn)) + return 2998 + + +def build_pileup_with_samtoolspipe(fn): + FNULL = open(os.devnull, 'w') + with subprocess.Popen(["samtools", "mpileup", fn], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=FNULL) as proc: + return len(proc.stdout.readlines()) + + +def build_pileup_with_pysam(*args, **kwargs): + with pysam.AlignmentFile(*args, **kwargs) as inf: + return len(list(inf.pileup(stepper="samtools"))) + + +def build_depth_with_samtoolsshell(fn): + os.system( + "samtools mpileup {} 2> /dev/null | awk '{{a += $4}} END {{print a}}' > /dev/null".format(fn)) + return 107241 + + +def build_depth_with_samtoolspipe(fn): + FNULL = open(os.devnull, 'w') + with subprocess.Popen(["samtools", "mpileup", fn], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=FNULL) as proc: + data = [x.split() for x in proc.stdout.readlines()] + return [int(x[3]) for x in data] + + +def build_depth_with_filter_with_pysam(*args, **kwargs): + with pysam.AlignmentFile(*args, **kwargs) as inf: + return [x.get_num_aligned() for x in inf.pileup(stepper="samtools")] + + +def build_depth_with_pysam(*args, **kwargs): + with pysam.AlignmentFile(*args, **kwargs) as inf: + return [x.nsegments for x in inf.pileup(stepper="samtools")] + + +def build_query_bases_with_samtoolsshell(fn): + os.system("samtools mpileup {} 2> /dev/null | awk '{{a = a $5}} END {{print a}}' | wc -c > /dev/null".format(fn)) + return 116308 + + +def build_query_bases_with_samtoolspipe(fn, *args, **kwargs): + FNULL = open(os.devnull, 'w') + with subprocess.Popen(["samtools", "mpileup", fn] + list(args), + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=FNULL) as proc: + stdout = proc.stdout.read().decode() + return [x.split()[4] for x in stdout.splitlines()] + + +def build_query_bases_with_samtoolspysam(fn, *args): + return [x.split()[4] for x in pysam.samtools.mpileup(fn, *args).splitlines()] + + +def build_query_bases_with_pysam_pileups(*args, **kwargs): + total_pileup = [] + with pysam.AlignmentFile(*args, **kwargs) as inf: + total_pileup = [ + [r.alignment.query_sequence[r.query_position_or_next] + for r in column.pileups if r.query_position_or_next is not None] + for column in inf.pileup(stepper="samtools")] + return total_pileup + + +def build_query_qualities_with_pysam_pileups(*args, **kwargs): + total_pileup = [] + with pysam.AlignmentFile(*args, **kwargs) as inf: + total_pileup = [ + [r.alignment.query_qualities[r.query_position_or_next] + for r in column.pileups if r.query_position_or_next is not None] + for column in inf.pileup(stepper="samtools")] + return total_pileup + + +def build_query_bases_with_pysam(fn, *args, **kwargs): + total_pileup = [] + with pysam.AlignmentFile(fn) as inf: + total_pileup = [column.get_query_sequences( + mark_ends=True, add_indels=True, mark_matches=True) for column in + inf.pileup(*args, **kwargs)] + return total_pileup + + +def build_query_names_with_pysam(*args, **kwargs): + total_pileup = [] + with pysam.AlignmentFile(*args, **kwargs) as inf: + total_pileup = [column.get_query_names() for column in + inf.pileup(stepper="samtools")] + return total_pileup + + +def build_query_qualities_with_samtoolspipe(fn): + FNULL = open(os.devnull, 'w') + with subprocess.Popen(["samtools", "mpileup", fn], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=FNULL) as proc: + data = [force_str(x).split()[5] for x in proc.stdout.readlines()] + return data + + +def build_query_qualities_with_pysam(*args, **kwargs): + total_pileup = [] + with pysam.AlignmentFile(*args, **kwargs) as inf: + total_pileup = [column.get_query_qualities() for column in + inf.pileup(stepper="samtools")] + return total_pileup + + +def build_mapping_qualities_with_samtoolspipe(fn): + FNULL = open(os.devnull, 'w') + with subprocess.Popen(["samtools", "mpileup", "-s", fn], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=FNULL) as proc: + data = [force_str(x).split()[6] for x in proc.stdout.readlines()] + return data + + +def build_mapping_qualities_with_pysam(*args, **kwargs): + total_pileup = [] + with pysam.AlignmentFile(*args, **kwargs) as inf: + total_pileup = [column.get_mapping_qualities() for column in + inf.pileup(stepper="samtools")] + return total_pileup + + +def build_query_positions_with_samtoolspipe(fn): + FNULL = open(os.devnull, 'w') + with subprocess.Popen(["samtools", "mpileup", "-O", fn], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=FNULL) as proc: + data = [list(map(int, force_str(x).split()[6].split(","))) + for x in proc.stdout.readlines()] + return data + + +def build_query_positions_with_pysam(*args, **kwargs): + total_pileup = [] + with pysam.AlignmentFile(*args, **kwargs) as inf: + total_pileup = [column.get_query_positions() for column in + inf.pileup(stepper="samtools")] + return total_pileup diff --git a/tests/SamFile_test.py b/tests/SamFile_test.py deleted file mode 100644 index ff1304570..000000000 --- a/tests/SamFile_test.py +++ /dev/null @@ -1,1990 +0,0 @@ -#!/usr/bin/env python -'''unit testing code for pysam. - -Execute in the :file:`tests` directory as it requires the Makefile -and data files located there. -''' - -import pysam -import pysam.samtools -import unittest -import os -import shutil -import sys -import collections -import subprocess -import logging -import array -from TestUtils import checkBinaryEqual, checkURL, force_str - -DATADIR = "pysam_data" - - -class BasicTestBAMFetch(unittest.TestCase): - - '''basic first test - detailed testing - if information in file is consistent - with information in AlignedRead object.''' - - def setUp(self): - self.samfile = pysam.Samfile( - os.path.join(DATADIR, "ex3.bam"), - "rb") - self.reads = list(self.samfile.fetch()) - - def testARqname(self): - self.assertEqual( - self.reads[0].qname, - "read_28833_29006_6945", - "read name mismatch in read 1: %s != %s" % ( - self.reads[0].qname, "read_28833_29006_6945")) - self.assertEqual( - self.reads[1].qname, - "read_28701_28881_323b", - "read name mismatch in read 2: %s != %s" % ( - self.reads[1].qname, "read_28701_28881_323b")) - - def testARflag(self): - self.assertEqual( - self.reads[0].flag, 99, - "flag mismatch in read 1: %s != %s" % ( - self.reads[0].flag, 99)) - self.assertEqual( - self.reads[1].flag, 147, - "flag mismatch in read 2: %s != %s" % ( - self.reads[1].flag, 147)) - - def testARrname(self): - self.assertEqual( - self.reads[0].rname, 0, - "chromosome/target id mismatch in read 1: %s != %s" % - (self.reads[0].rname, 0)) - self.assertEqual( - self.reads[1].rname, 1, - "chromosome/target id mismatch in read 2: %s != %s" % - (self.reads[1].rname, 1)) - - def testARpos(self): - self.assertEqual( - self.reads[0].pos, 33 - 1, - "mapping position mismatch in read 1: %s != %s" % - (self.reads[0].pos, 33 - 1)) - self.assertEqual( - self.reads[1].pos, 88 - 1, - "mapping position mismatch in read 2: %s != %s" % - (self.reads[1].pos, 88 - 1)) - - def testARmapq(self): - self.assertEqual( - self.reads[0].mapq, 20, - "mapping quality mismatch in read 1: %s != %s" % - (self.reads[0].mapq, 20)) - self.assertEqual( - self.reads[1].mapq, 30, - "mapping quality mismatch in read 2: %s != %s" % ( - self.reads[1].mapq, 30)) - - def testARcigar(self): - self.assertEqual( - self.reads[0].cigar, - [(0, 10), (2, 1), (0, 25)], - "read name length mismatch in read 1: %s != %s" % - (self.reads[0].cigar, [(0, 10), (2, 1), (0, 25)])) - self.assertEqual( - self.reads[1].cigar, [(0, 35)], - "read name length mismatch in read 2: %s != %s" % - (self.reads[1].cigar, [(0, 35)])) - - def testARcigarstring(self): - self.assertEqual(self.reads[0].cigarstring, '10M1D25M') - self.assertEqual(self.reads[1].cigarstring, '35M') - - def testARmrnm(self): - self.assertEqual( - self.reads[0].mrnm, 0, - "mate reference sequence name mismatch in read 1: %s != %s" % - (self.reads[0].mrnm, 0)) - self.assertEqual( - self.reads[1].mrnm, 1, - "mate reference sequence name mismatch in read 2: %s != %s" % - (self.reads[1].mrnm, 1)) - self.assertEqual( - self.reads[0].rnext, 0, - "mate reference sequence name mismatch in read 1: %s != %s" % - (self.reads[0].rnext, 0)) - self.assertEqual( - self.reads[1].rnext, 1, - "mate reference sequence name mismatch in read 2: %s != %s" % - (self.reads[1].rnext, 1)) - - def testARmpos(self): - self.assertEqual(self.reads[ - 0].mpos, 200 - 1, "mate mapping position mismatch in read 1: %s != %s" % (self.reads[0].mpos, 200 - 1)) - self.assertEqual(self.reads[ - 1].mpos, 500 - 1, "mate mapping position mismatch in read 2: %s != %s" % (self.reads[1].mpos, 500 - 1)) - self.assertEqual(self.reads[ - 0].pnext, 200 - 1, "mate mapping position mismatch in read 1: %s != %s" % (self.reads[0].pnext, 200 - 1)) - self.assertEqual(self.reads[ - 1].pnext, 500 - 1, "mate mapping position mismatch in read 2: %s != %s" % (self.reads[1].pnext, 500 - 1)) - - def testARisize(self): - self.assertEqual(self.reads[0].isize, 167, "insert size mismatch in read 1: %s != %s" % ( - self.reads[0].isize, 167)) - self.assertEqual(self.reads[1].isize, 412, "insert size mismatch in read 2: %s != %s" % ( - self.reads[1].isize, 412)) - self.assertEqual(self.reads[0].tlen, 167, "insert size mismatch in read 1: %s != %s" % ( - self.reads[0].tlen, 167)) - self.assertEqual(self.reads[1].tlen, 412, "insert size mismatch in read 2: %s != %s" % ( - self.reads[1].tlen, 412)) - - def testARseq(self): - self.assertEqual(self.reads[0].seq, "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG", "sequence mismatch in read 1: %s != %s" % ( - self.reads[0].seq, "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG")) - self.assertEqual(self.reads[1].seq, "ACCTATATCTTGGCCTTGGCCGATGCGGCCTTGCA", "sequence size mismatch in read 2: %s != %s" % ( - self.reads[1].seq, "ACCTATATCTTGGCCTTGGCCGATGCGGCCTTGCA")) - self.assertEqual(self.reads[3].seq, "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG", "sequence mismatch in read 4: %s != %s" % ( - self.reads[3].seq, "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG")) - - def testARqual(self): - self.assertEqual(self.reads[0].qual, "<<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<<", - "quality string mismatch in read 1: %s != %s" % (self.reads[0].qual, "<<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<<")) - self.assertEqual(self.reads[1].qual, "<<<<<;<<<<7;:<<<6;<<<<<<<<<<<<7<<<<", "quality string mismatch in read 2: %s != %s" % ( - self.reads[1].qual, "<<<<<;<<<<7;:<<<6;<<<<<<<<<<<<7<<<<")) - self.assertEqual(self.reads[3].qual, "<<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<<", - "quality string mismatch in read 3: %s != %s" % (self.reads[3].qual, "<<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<<")) - - def testARquery(self): - self.assertEqual(self.reads[0].query, "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG", "query mismatch in read 1: %s != %s" % ( - self.reads[0].query, "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG")) - self.assertEqual(self.reads[1].query, "ACCTATATCTTGGCCTTGGCCGATGCGGCCTTGCA", "query size mismatch in read 2: %s != %s" % ( - self.reads[1].query, "ACCTATATCTTGGCCTTGGCCGATGCGGCCTTGCA")) - self.assertEqual(self.reads[3].query, "TAGCTAGCTACCTATATCTTGGTCTT", "query mismatch in read 4: %s != %s" % ( - self.reads[3].query, "TAGCTAGCTACCTATATCTTGGTCTT")) - - def testARqqual(self): - self.assertEqual( - self.reads[0].qqual, "<<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<<", - "qquality string mismatch in read 1: %s != %s" % - (self.reads[0].qqual, "<<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<<")) - self.assertEqual( - self.reads[1].qqual, "<<<<<;<<<<7;:<<<6;<<<<<<<<<<<<7<<<<", - "qquality string mismatch in read 2: %s != %s" % - (self.reads[1].qqual, "<<<<<;<<<<7;:<<<6;<<<<<<<<<<<<7<<<<")) - self.assertEqual( - self.reads[3].qqual, "<<<<<<<<<<<<<<<<<:<9/,&,22", - "qquality string mismatch in read 3: %s != %s" % - (self.reads[3].qqual, "<<<<<<<<<<<<<<<<<:<9/,&,22")) - - def testPresentOptionalFields(self): - self.assertEqual( - self.reads[0].opt('NM'), 1, - "optional field mismatch in read 1, NM: %s != %s" % - (self.reads[0].opt('NM'), 1)) - self.assertEqual( - self.reads[0].opt('RG'), 'L1', - "optional field mismatch in read 1, RG: %s != %s" % - (self.reads[0].opt('RG'), 'L1')) - self.assertEqual( - self.reads[1].opt('RG'), 'L2', - "optional field mismatch in read 2, RG: %s != %s" % - (self.reads[1].opt('RG'), 'L2')) - self.assertEqual( - self.reads[1].opt('MF'), 18, - "optional field mismatch in read 2, MF: %s != %s" % - (self.reads[1].opt('MF'), 18)) - - def testPairedBools(self): - self.assertEqual(self.reads[0].is_paired, True, - "is paired mismatch in read 1: %s != %s" % ( - self.reads[0].is_paired, True)) - self.assertEqual(self.reads[1].is_paired, True, - "is paired mismatch in read 2: %s != %s" % ( - self.reads[1].is_paired, True)) - self.assertEqual(self.reads[0].is_proper_pair, True, - "is proper pair mismatch in read 1: %s != %s" % ( - self.reads[0].is_proper_pair, True)) - self.assertEqual(self.reads[1].is_proper_pair, True, - "is proper pair mismatch in read 2: %s != %s" % ( - self.reads[1].is_proper_pair, True)) - - def testTags(self): - self.assertEqual(self.reads[0].tags, - [('NM', 1), ('RG', 'L1'), - ('PG', 'P1'), ('XT', 'U')]) - self.assertEqual(self.reads[1].tags, - [('MF', 18), ('RG', 'L2'), - ('PG', 'P2'), ('XT', 'R')]) - - def testAddTags(self): - self.assertEqual(sorted(self.reads[0].tags), - sorted([('NM', 1), ('RG', 'L1'), - ('PG', 'P1'), ('XT', 'U')])) - - self.reads[0].setTag('X1', 'C') - self.assertEqual(sorted(self.reads[0].tags), - sorted([('X1', 'C'), ('NM', 1), ('RG', 'L1'), - ('PG', 'P1'), ('XT', 'U'), ])) - self.reads[0].setTag('X2', 5) - self.assertEqual(sorted(self.reads[0].tags), - sorted([('X2', 5), ('X1', 'C'), - ('NM', 1), ('RG', 'L1'), - ('PG', 'P1'), ('XT', 'U'), ])) - # add with replacement - self.reads[0].setTag('X2', 10) - self.assertEqual(sorted(self.reads[0].tags), - sorted([('X2', 10), ('X1', 'C'), - ('NM', 1), ('RG', 'L1'), - ('PG', 'P1'), ('XT', 'U'), ])) - - # add without replacement - self.reads[0].setTag('X2', 5, replace=False) - self.assertEqual(sorted(self.reads[0].tags), - sorted([('X2', 10), ('X1', 'C'), - ('X2', 5), - ('NM', 1), ('RG', 'L1'), - ('PG', 'P1'), ('XT', 'U'), ])) - - def testAddTagsType(self): - self.reads[0].tags = None - self.assertEqual(self.reads[0].tags, []) - - self.reads[0].setTag('X1', 5.0) - self.reads[0].setTag('X2', "5.0") - self.reads[0].setTag('X3', 5) - - self.assertEqual(sorted(self.reads[0].tags), - sorted([('X1', 5.0), - ('X2', "5.0"), - ('X3', 5)])) - - # test setting float for int value - self.reads[0].setTag('X4', 5, value_type='d') - self.assertEqual(sorted(self.reads[0].tags), - sorted([('X1', 5.0), - ('X2', "5.0"), - ('X3', 5), - ('X4', 5.0)])) - - # test setting int for float value - the - # value will be rounded. - self.reads[0].setTag('X5', 5.2, value_type='i') - self.assertEqual(sorted(self.reads[0].tags), - sorted([('X1', 5.0), - ('X2', "5.0"), - ('X3', 5), - ('X4', 5.0), - ('X5', 5)])) - - # test setting invalid type code - self.assertRaises(ValueError, self.reads[0].setTag, 'X6', 5.2, 'g') - - def testTagsUpdatingFloat(self): - self.assertEqual(self.reads[0].tags, - [('NM', 1), ('RG', 'L1'), - ('PG', 'P1'), ('XT', 'U')]) - self.reads[0].tags += [('XC', 5.0)] - self.assertEqual(self.reads[0].tags, - [('NM', 1), ('RG', 'L1'), - ('PG', 'P1'), ('XT', 'U'), ('XC', 5.0)]) - - def testOpt(self): - self.assertEqual(self.reads[0].opt("XT"), "U") - self.assertEqual(self.reads[1].opt("XT"), "R") - - def testMissingOpt(self): - self.assertRaises(KeyError, self.reads[0].opt, "XP") - - def testEmptyOpt(self): - self.assertRaises(KeyError, self.reads[2].opt, "XT") - - def tearDown(self): - self.samfile.close() - - -class BasicTestBAMFile(BasicTestBAMFetch): - - def setUp(self): - self.samfile = pysam.Samfile( - os.path.join(DATADIR, "ex3.sam"), - "r") - self.reads = [r for r in self.samfile] - - -class BasicTestSAMFile(BasicTestBAMFetch): - - def setUp(self): - self.samfile = pysam.Samfile( - os.path.join(DATADIR, "ex3.sam"), - "r") - self.reads = [r for r in self.samfile] - - -class BasicTestSAMFetch(BasicTestBAMFetch): - - def setUp(self): - self.samfile = pysam.Samfile( - os.path.join(DATADIR, "ex3.sam"), - "r") - self.reads = list(self.samfile.fetch()) - - -# needs to be implemented -# class TestAlignedReadFromSamWithoutHeader(TestAlignedReadFromBam): -# -# def setUp(self): -# self.samfile=pysam.Samfile( "ex7.sam","r" ) -# self.reads=list(self.samfile.fetch()) - - -class TestIO(unittest.TestCase): - - '''check if reading samfile and writing a samfile are consistent.''' - - def checkEcho(self, - input_filename, - reference_filename, - output_filename, - input_mode, output_mode, - use_template=True): - '''iterate through *input_filename* writing to *output_filename* and - comparing the output to *reference_filename*. - - The files are opened according to the *input_mode* and *output_mode*. - - If *use_template* is set, the header is copied from infile - using the template mechanism, otherwise target names and - lengths are passed explicitly. - - ''' - - infile = pysam.Samfile(os.path.join(DATADIR, input_filename), - input_mode) - if use_template: - outfile = pysam.Samfile(output_filename, - output_mode, - template=infile) - else: - outfile = pysam.Samfile(output_filename, - output_mode, - referencenames=infile.references, - referencelengths=infile.lengths, - add_sq_text=False) - - iter = infile.fetch() - - for x in iter: - outfile.write(x) - infile.close() - outfile.close() - - self.assertTrue( - checkBinaryEqual(os.path.join(DATADIR, reference_filename), - output_filename), - "files %s and %s are not the same" % (reference_filename, - output_filename)) - - def testReadWriteBam(self): - - input_filename = "ex1.bam" - output_filename = "pysam_ex1.bam" - reference_filename = "ex1.bam" - - self.checkEcho(input_filename, reference_filename, output_filename, - "rb", "wb", use_template=True) - - # Disabled - should work, files are not binary equal, but are - # non-binary equal: - # diff <(samtools view pysam_ex1.bam) <(samtools view pysam_data/ex1.bam) - # def testReadWriteBamWithTargetNames(self): - # input_filename = "ex1.bam" - # output_filename = "pysam_ex1.bam" - # reference_filename = "ex1.bam" - - # self.checkEcho(input_filename, reference_filename, output_filename, - # "rb", "wb", use_template=False) - - def testReadWriteSamWithHeader(self): - - input_filename = "ex2.sam" - output_filename = "pysam_ex2.sam" - reference_filename = "ex2.sam" - - self.checkEcho(input_filename, - reference_filename, - output_filename, - "r", "wh") - - # Release 0.8.0 - # no samfiles without header - def testReadWriteSamWithoutHeader(self): - - input_filename = "ex2.sam" - output_filename = "pysam_ex2.sam" - reference_filename = "ex1.sam" - - self.checkEcho(input_filename, - reference_filename, - output_filename, - "r", "w") - - def testReadSamWithoutTargetNames(self): - '''see issue 104.''' - input_filename = os.path.join(DATADIR, - "example_unmapped_reads_no_sq.sam") - - # raise exception in default mode - self.assertRaises(ValueError, pysam.Samfile, input_filename, "r") - - # raise exception if no SQ files - self.assertRaises(ValueError, pysam.Samfile, - input_filename, "r", - check_header=True) - - infile = pysam.Samfile( - input_filename, - check_header=False, - check_sq=False) - - # TODO - # result = list(infile.fetch(until_eof=True)) - # self.assertEqual(2, len(result)) - - def testReadBamWithoutTargetNames(self): - '''see issue 104.''' - input_filename = os.path.join( - DATADIR, "example_unmapped_reads_no_sq.bam") - - # raise exception in default mode - self.assertRaises(ValueError, pysam.Samfile, input_filename, "r") - - # raise exception if no SQ files - self.assertRaises(ValueError, pysam.Samfile, input_filename, "r", - check_header=True) - - infile = pysam.Samfile( - input_filename, check_header=False, check_sq=False) - result = list(infile.fetch(until_eof=True)) - - # TODO - def testReadSamWithoutHeader(self): - input_filename = os.path.join(DATADIR, "ex1.sam") - - # reading from a samfile without header is not - # implemented - self.assertRaises(ValueError, - pysam.Samfile, - input_filename, - "r") - - # TODO - # without check_header header is no read - # leading to segfault - # self.assertRaises(ValueError, - # pysam.Samfile, - # input_filename, - # "r", - # check_header=False) - - # TODO - # def testReadUnformattedFile(self): - # '''test reading from a file that is not bam/sam formatted''' - # input_filename = os.path.join(DATADIR, 'Makefile') - - # # bam - file raise error - # self.assertRaises(ValueError, - # pysam.Samfile, - # input_filename, - # "rb") - - # # sam - file error, but can't fetch - # self.assertRaises(ValueError, - # pysam.Samfile, - # input_filename, - # "r") - - # self.assertRaises(ValueError, - # pysam.Samfile, - # input_filename, - # "r", - # check_header=False) - - def testBAMWithoutAlignedReads(self): - '''see issue 117''' - input_filename = os.path.join(DATADIR, "test_unaligned.bam") - samfile = pysam.Samfile(input_filename, "rb", check_sq=False) - samfile.fetch(until_eof=True) - - def testBAMWithShortBAI(self): - '''see issue 116''' - input_filename = os.path.join(DATADIR, "example_bai.bam") - samfile = pysam.Samfile(input_filename, "rb", check_sq=False) - samfile.fetch('chr2') - - def testFetchFromClosedFile(self): - - samfile = pysam.Samfile(os.path.join(DATADIR, "ex1.bam"), - "rb") - samfile.close() - self.assertRaises(ValueError, samfile.fetch, 'chr1', 100, 120) - - def testClosedFile(self): - '''test that access to a closed samfile raises ValueError.''' - - samfile = pysam.Samfile(os.path.join(DATADIR, "ex1.bam"), - "rb") - samfile.close() - self.assertRaises(ValueError, samfile.fetch, 'chr1', 100, 120) - self.assertRaises(ValueError, samfile.pileup, 'chr1', 100, 120) - self.assertRaises(ValueError, samfile.getrname, 0) - # TODO - self.assertRaises(ValueError, samfile.tell) - self.assertRaises(ValueError, samfile.seek, 0) - self.assertRaises(ValueError, getattr, samfile, "nreferences") - self.assertRaises(ValueError, getattr, samfile, "references") - self.assertRaises(ValueError, getattr, samfile, "lengths") - self.assertRaises(ValueError, getattr, samfile, "text") - self.assertRaises(ValueError, getattr, samfile, "header") - - # write on closed file - self.assertEqual(0, samfile.write(None)) - - def testAutoDetection(self): - '''test if autodetection works.''' - - # TODO - # samfile = pysam.Samfile(os.path.join(DATADIR, "ex3.sam")) - # self.assertRaises(ValueError, samfile.fetch, 'chr1') - # samfile.close() - - samfile = pysam.Samfile(os.path.join(DATADIR, "ex3.bam")) - samfile.fetch('chr1') - samfile.close() - - # TOOD - # def testReadingFromSamFileWithoutHeader(self): - # '''read from samfile without header. - # ''' - # samfile = pysam.Samfile(os.path.join(DATADIR, "ex7.sam"), - # check_header=False, - # check_sq=False) - # self.assertRaises(NotImplementedError, samfile.__iter__) - - def testReadingFromFileWithoutIndex(self): - '''read from bam file without index.''' - - shutil.copyfile(os.path.join(DATADIR, "ex2.bam"), 'tmp_ex2.bam') - samfile = pysam.Samfile('tmp_ex2.bam', - "rb") - self.assertRaises(ValueError, samfile.fetch) - self.assertEqual(len(list(samfile.fetch(until_eof=True))), - 3270) - os.unlink('tmp_ex2.bam') - - # def testReadingUniversalFileMode(self): - # '''read from samfile without header. - # ''' - - # input_filename = "ex2.sam" - # output_filename = "pysam_ex2.sam" - # reference_filename = "ex1.sam" - - # self.checkEcho(input_filename, - # reference_filename, - # output_filename, - # "rU", "w") - - def testHead(self): - '''test IteratorRowHead''' - samfile = pysam.Samfile(os.path.join(DATADIR, "ex1.bam"), - "rb") - l10 = list(samfile.head(10)) - l100 = list(samfile.head(100)) - self.assertEqual(len(l10), 10) - self.assertEqual(len(l100), 100) - self.assertEqual(list(map(str, l10)), - list(map(str, l100[:10]))) - - -class TestFloatTagBug(unittest.TestCase): - - '''see issue 71''' - - def testFloatTagBug(self): - '''a float tag before another exposed a parsing bug in bam_aux_get. - - Fixed in 0.1.19 - ''' - samfile = pysam.Samfile(os.path.join(DATADIR, "tag_bug.bam")) - read = next(samfile.fetch(until_eof=True)) - self.assertTrue(('XC', 1) in read.tags) - self.assertEqual(read.opt('XC'), 1) - - -class TestLargeFieldBug(unittest.TestCase): - - '''see issue 100''' - - def testLargeFileBug(self): - '''when creating a read with a large entry in the tag field - causes an errror: - NotImplementedError: tags field too large - ''' - samfile = pysam.Samfile(os.path.join(DATADIR, "issue100.bam")) - read = next(samfile.fetch(until_eof=True)) - new_read = pysam.AlignedRead() - new_read.tags = read.tags - self.assertEqual(new_read.tags, read.tags) - - -class TestTagParsing(unittest.TestCase): - - '''tests checking the accuracy of tag setting and retrieval.''' - - def makeRead(self): - a = pysam.AlignedRead() - a.qname = "read_12345" - a.tid = 0 - a.seq = "ACGT" * 3 - a.flag = 0 - a.rname = 0 - a.pos = 1 - a.mapq = 20 - a.cigar = ((0, 10), (2, 1), (0, 25)) - a.mrnm = 0 - a.mpos = 200 - a.isize = 0 - a.qual = "1234" * 3 - # todo: create tags - return a - - def testNegativeIntegers(self): - x = -2 - aligned_read = self.makeRead() - aligned_read.tags = [("XD", int(x))] - # print (aligned_read.tags) - - def testNegativeIntegers2(self): - x = -2 - r = self.makeRead() - r.tags = [("XD", int(x))] - outfile = pysam.Samfile("test.bam", - "wb", - referencenames=("chr1",), - referencelengths = (1000,)) - outfile.write(r) - outfile.close() - - def testCigarString(self): - r = self.makeRead() - self.assertEqual(r.cigarstring, "10M1D25M") - r.cigarstring = "20M10D20M" - self.assertEqual(r.cigar, [(0, 20), (2, 10), (0, 20)]) - # unsetting cigar string - r.cigarstring = None - self.assertEqual(r.cigarstring, None) - - def testCigar(self): - r = self.makeRead() - self.assertEqual(r.cigar, [(0, 10), (2, 1), (0, 25)]) - # unsetting cigar string - r.cigar = None - self.assertEqual(r.cigar, []) - - def testLongTags(self): - '''see issue 115''' - - r = self.makeRead() - rg = 'HS2000-899_199.L3' - tags = [('XC', 85), ('XT', 'M'), ('NM', 5), - ('SM', 29), ('AM', 29), ('XM', 1), - ('XO', 1), ('XG', 4), ('MD', '37^ACCC29T18'), - ('XA', '5,+11707,36M1I48M,2;21,-48119779,46M1I38M,2;hs37d5,-10060835,40M1D45M,3;5,+11508,36M1I48M,3;hs37d5,+6743812,36M1I48M,3;19,-59118894,46M1I38M,3;4,-191044002,6M1I78M,3;')] - - r.tags = tags - r.tags += [("RG", rg)] * 100 - tags += [("RG", rg)] * 100 - - self.assertEqual(tags, r.tags) - - -class TestClipping(unittest.TestCase): - - def testClipping(self): - - self.samfile = pysam.Samfile(os.path.join(DATADIR, "softclip.bam"), - "rb") - for read in self.samfile: - - if read.qname == "r001": - self.assertEqual(read.seq, 'AAAAGATAAGGATA') - self.assertEqual(read.query, 'AGATAAGGATA') - self.assertEqual(read.qual, None) - self.assertEqual(read.qqual, None) - - elif read.qname == "r002": - - self.assertEqual(read.seq, 'GCCTAAGCTAA') - self.assertEqual(read.query, 'AGCTAA') - self.assertEqual(read.qual, '01234567890') - self.assertEqual(read.qqual, '567890') - - elif read.qname == "r003": - - self.assertEqual(read.seq, 'GCCTAAGCTAA') - self.assertEqual(read.query, 'GCCTAA') - self.assertEqual(read.qual, '01234567890') - self.assertEqual(read.qqual, '012345') - - elif read.qname == "r004": - - self.assertEqual(read.seq, 'TAGGC') - self.assertEqual(read.query, 'TAGGC') - self.assertEqual(read.qual, '01234') - self.assertEqual(read.qqual, '01234') - - -class TestIteratorRow(unittest.TestCase): - - def setUp(self): - self.samfile = pysam.Samfile(os.path.join(DATADIR, "ex1.bam"), - "rb") - - def checkRange(self, rnge): - '''compare results from iterator with those from samtools.''' - ps = list(self.samfile.fetch(region=rnge)) - sa = force_str( - pysam.samtools.view( - os.path.join(DATADIR, "ex1.bam"), - rnge, - raw=True)).splitlines(True) - self.assertEqual( - len(ps), len(sa), - "unequal number of results for range %s: %i != %i" % - (rnge, len(ps), len(sa))) - # check if the same reads are returned and in the same order - for line, (a, b) in enumerate(list(zip(ps, sa))): - d = b.split("\t") - self.assertEqual( - a.qname, d[0], - "line %i: read id mismatch: %s != %s" % - (line, a.rname, d[0])) - self.assertEqual( - a.pos, int(d[3]) - 1, - "line %i: read position mismatch: %s != %s, " - "\n%s\n%s\n" % - (line, a.pos, int(d[3]) - 1, - str(a), str(d))) - qual = d[10] - self.assertEqual( - a.qual, qual, - "line %i: quality mismatch: %s != %s, \n%s\n%s\n" % - (line, a.qual, qual, - str(a), str(d))) - - def testIteratePerContig(self): - '''check random access per contig''' - for contig in self.samfile.references: - self.checkRange(contig) - - def testIterateRanges(self): - '''check random access per range''' - for contig, length in zip(self.samfile.references, self.samfile.lengths): - for start in range(1, length, 90): - # this includes empty ranges - self.checkRange("%s:%i-%i" % (contig, start, start + 90)) - - def tearDown(self): - self.samfile.close() - - -class TestIteratorRowAll(unittest.TestCase): - - def setUp(self): - self.samfile = pysam.Samfile(os.path.join(DATADIR, "ex1.bam"), - "rb") - - def testIterate(self): - '''compare results from iterator with those from samtools.''' - ps = list(self.samfile.fetch()) - sa = force_str( - pysam.samtools.view( - os.path.join(DATADIR, "ex1.bam"), - raw=True)).splitlines(True) - - self.assertEqual( - len(ps), len(sa), "unequal number of results: %i != %i" % (len(ps), len(sa))) - # check if the same reads are returned - for line, pair in enumerate(list(zip(ps, sa))): - data = pair[1].split("\t") - self.assertEqual(pair[0].qname, data[ - 0], "read id mismatch in line %i: %s != %s" % (line, pair[0].rname, data[0])) - - def tearDown(self): - self.samfile.close() - - -class TestIteratorColumn(unittest.TestCase): - - '''test iterator column against contents of ex4.bam.''' - - # note that samfile contains 1-based coordinates - # 1D means deletion with respect to reference sequence - # - mCoverages = {'chr1': [0] * 20 + [1] * 36 + [0] * (100 - 20 - 35), - 'chr2': [0] * 20 + [1] * 35 + [0] * (100 - 20 - 35), - } - - def setUp(self): - self.samfile = pysam.Samfile(os.path.join(DATADIR, "ex4.bam"), - "rb") - - def checkRange(self, contig, start=None, end=None, truncate=False): - '''compare results from iterator with those from samtools.''' - # check if the same reads are returned and in the same order - for column in self.samfile.pileup(contig, start, end, - truncate=truncate): - if truncate: - self.assertGreaterEqual(column.pos, start) - self.assertLess(column.pos, end) - thiscov = len(column.pileups) - refcov = self.mCoverages[ - self.samfile.getrname(column.tid)][column.pos] - self.assertEqual( - thiscov, refcov, "wrong coverage at pos %s:%i %i should be %i" % ( - self.samfile.getrname(column.tid), column.pos, thiscov, refcov)) - - def testIterateAll(self): - '''check random access per contig''' - self.checkRange(None) - - def testIteratePerContig(self): - '''check random access per contig''' - for contig in self.samfile.references: - self.checkRange(contig) - - def testIterateRanges(self): - '''check random access per range''' - for contig, length in zip( - self.samfile.references, self.samfile.lengths): - for start in range(1, length, 90): - # this includes empty ranges - self.checkRange(contig, start, start + 90) - - def testInverse(self): - '''test the inverse, is point-wise pileup accurate.''' - for contig, refseq in list(self.mCoverages.items()): - refcolumns = sum(refseq) - for pos, refcov in enumerate(refseq): - columns = list(self.samfile.pileup(contig, pos, pos + 1)) - if refcov == 0: - # if no read, no coverage - self.assertEqual( - len(columns), - refcov, - "wrong number of pileup columns returned for position %s:%i, %i should be %i" % ( - contig, pos, - len(columns), refcov)) - elif refcov == 1: - # one read, all columns of the read are returned - self.assertEqual( - len(columns), - refcolumns, - "pileup incomplete at position %i: got %i, expected %i " % - (pos, len(columns), refcolumns)) - - def testIterateTruncate(self): - '''check random access per range''' - for contig, length in zip(self.samfile.references, self.samfile.lengths): - for start in range(1, length, 90): - # this includes empty ranges - self.checkRange(contig, start, start + 90, truncate=True) - - def tearDown(self): - self.samfile.close() - - -class TestIteratorColumn2(unittest.TestCase): - - '''test iterator column against contents of ex1.bam.''' - - def setUp(self): - self.samfile = pysam.Samfile(os.path.join(DATADIR, "ex1.bam"), - "rb") - - def testStart(self): - # print self.samfile.fetch().next().pos - # print self.samfile.pileup().next().pos - pass - - def testTruncate(self): - '''see issue 107.''' - # note that ranges in regions start from 1 - p = self.samfile.pileup(region='chr1:170:172', truncate=True) - columns = [x.pos for x in p] - self.assertEqual(len(columns), 3) - self.assertEqual(columns, [169, 170, 171]) - - p = self.samfile.pileup('chr1', 169, 172, truncate=True) - columns = [x.pos for x in p] - - self.assertEqual(len(columns), 3) - self.assertEqual(columns, [169, 170, 171]) - - def testAccessOnClosedIterator(self): - '''see issue 131 - - Accessing pileup data after iterator has closed. - ''' - pcolumn = self.samfile.pileup('chr1', 170, 180).__next__() - self.assertRaises(ValueError, getattr, pcolumn, "pileups") - - -class TestHeaderSam(unittest.TestCase): - - header = {'SQ': [{'LN': 1575, 'SN': 'chr1', 'AH': 'chr1:5000000-5010000'}, - {'LN': 1584, 'SN': 'chr2', 'AH': '*'}], - 'RG': [{'LB': 'SC_1', 'ID': 'L1', 'SM': 'NA12891', 'PU': 'SC_1_10', "CN": "name:with:colon"}, - {'LB': 'SC_2', 'ID': 'L2', 'SM': 'NA12891', 'PU': 'SC_2_12', "CN": "name:with:colon"}], - 'PG': [{'ID': 'P1', 'VN': '1.0'}, {'ID': 'P2', 'VN': '1.1'}], - 'HD': {'VN': '1.0'}, - 'CO': ['this is a comment', 'this is another comment'], - } - - def compareHeaders(self, a, b): - '''compare two headers a and b.''' - for ak, av in a.items(): - self.assertTrue(ak in b, "key '%s' not in '%s' " % (ak, b)) - self.assertEqual(av, b[ak]) - - def setUp(self): - self.samfile = pysam.Samfile(os.path.join(DATADIR, "ex3.sam"), - "r") - - def testHeaders(self): - self.compareHeaders(self.header, self.samfile.header) - self.compareHeaders(self.samfile.header, self.header) - - def testNameMapping(self): - for x, y in enumerate(("chr1", "chr2")): - tid = self.samfile.gettid(y) - ref = self.samfile.getrname(x) - self.assertEqual(tid, x) - self.assertEqual(ref, y) - - self.assertEqual(self.samfile.gettid("chr?"), -1) - self.assertRaises(ValueError, self.samfile.getrname, 2) - - def tearDown(self): - self.samfile.close() - - -class TestHeaderBam(TestHeaderSam): - - def setUp(self): - self.samfile = pysam.Samfile(os.path.join(DATADIR, "ex3.bam"), - "rb") - - -class TestHeaderFromRefs(unittest.TestCase): - - '''see issue 144 - - reference names need to be converted to string for python 3 - ''' - - # def testHeader( self ): - # refs = ['chr1', 'chr2'] - # tmpfile = "tmp_%i" % id(self) - # s = pysam.Samfile(tmpfile, 'wb', - # referencenames=refs, - # referencelengths=[100]*len(refs)) - # s.close() - - # self.assertTrue( checkBinaryEqual( 'issue144.bam', tmpfile ), - # 'bam files differ') - # os.unlink( tmpfile ) - - -class TestHeader1000Genomes(unittest.TestCase): - - '''see issue 110''' - # bamfile = "http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/phase2b_alignment/data/NA07048/exome_alignment/NA07048.unmapped.ILLUMINA.bwa.CEU.exome.20120522_p2b.bam" - bamfile = "http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/phase3_EX_or_LC_only_alignment/data/HG00104/alignment/HG00104.chrom11.ILLUMINA.bwa.GBR.low_coverage.20130415.bam" - - def testRead(self): - - if not checkURL(self.bamfile): - return - - f = pysam.Samfile(self.bamfile, "rb") - data = f.header.copy() - self.assertTrue(data) - - -class TestUnmappedReads(unittest.TestCase): - - # TODO - # def testSAM(self): - # samfile = pysam.Samfile(os.path.join(DATADIR, "ex5.sam"), - # "r") - # self.assertEqual(len(list(samfile.fetch(until_eof=True))), 2) - # samfile.close() - - def testBAM(self): - samfile = pysam.Samfile(os.path.join(DATADIR, "ex5.bam"), - "rb") - self.assertEqual(len(list(samfile.fetch(until_eof=True))), 2) - samfile.close() - - -class TestPileupObjects(unittest.TestCase): - - def setUp(self): - self.samfile = pysam.Samfile(os.path.join(DATADIR, "ex1.bam"), - "rb") - - def testPileupColumn(self): - for pcolumn1 in self.samfile.pileup(region="chr1:105"): - if pcolumn1.pos == 104: - self.assertEqual( - pcolumn1.tid, 0, "chromosome/target id mismatch in position 1: %s != %s" % (pcolumn1.tid, 0)) - self.assertEqual( - pcolumn1.pos, 105 - 1, "position mismatch in position 1: %s != %s" % (pcolumn1.pos, 105 - 1)) - self.assertEqual( - pcolumn1.n, 2, "# reads mismatch in position 1: %s != %s" % (pcolumn1.n, 2)) - for pcolumn2 in self.samfile.pileup(region="chr2:1480"): - if pcolumn2.pos == 1479: - self.assertEqual( - pcolumn2.tid, 1, "chromosome/target id mismatch in position 1: %s != %s" % (pcolumn2.tid, 1)) - self.assertEqual( - pcolumn2.pos, 1480 - 1, "position mismatch in position 1: %s != %s" % (pcolumn2.pos, 1480 - 1)) - self.assertEqual( - pcolumn2.n, 12, "# reads mismatch in position 1: %s != %s" % (pcolumn2.n, 12)) - - def testPileupRead(self): - for pcolumn1 in self.samfile.pileup(region="chr1:105"): - if pcolumn1.pos == 104: - self.assertEqual( - len(pcolumn1.pileups), 2, - "# reads aligned to column mismatch in position 1" - ": %s != %s" % - (len(pcolumn1.pileups), 2)) - - -# self.assertEqual( pcolumn1.pileups[0] # need to test additional -# properties here - - def tearDown(self): - self.samfile.close() - - def testIteratorOutOfScope(self): - '''test if exception is raised if pileup col is accessed after - iterator is exhausted.''' - - for pileupcol in self.samfile.pileup(): - pass - - self.assertRaises(ValueError, getattr, pileupcol, "pileups") - - -class TestContextManager(unittest.TestCase): - - def testManager(self): - with pysam.Samfile(os.path.join(DATADIR, 'ex1.bam'), - 'rb') as samfile: - samfile.fetch() - self.assertEqual(samfile.closed, True) - - -class TestExceptions(unittest.TestCase): - - def setUp(self): - self.samfile = pysam.Samfile(os.path.join(DATADIR, "ex1.bam"), - "rb") - - def testMissingFile(self): - - self.assertRaises(IOError, pysam.Samfile, "exdoesntexist.bam", "rb") - self.assertRaises(IOError, pysam.Samfile, "exdoesntexist.sam", "r") - self.assertRaises(IOError, pysam.Samfile, "exdoesntexist.bam", "r") - self.assertRaises(IOError, pysam.Samfile, "exdoesntexist.sam", "rb") - - def testBadContig(self): - self.assertRaises(ValueError, self.samfile.fetch, "chr88") - - def testMeaninglessCrap(self): - self.assertRaises(ValueError, self.samfile.fetch, "skljf") - - def testBackwardsOrderNewFormat(self): - self.assertRaises(ValueError, self.samfile.fetch, 'chr1', 100, 10) - - def testBackwardsOrderOldFormat(self): - self.assertRaises(ValueError, self.samfile.fetch, region="chr1:100-10") - - def testOutOfRangeNegativeNewFormat(self): - self.assertRaises(ValueError, self.samfile.fetch, "chr1", 5, -10) - self.assertRaises(ValueError, self.samfile.fetch, "chr1", 5, 0) - self.assertRaises(ValueError, self.samfile.fetch, "chr1", -5, -10) - - self.assertRaises(ValueError, self.samfile.count, "chr1", 5, -10) - self.assertRaises(ValueError, self.samfile.count, "chr1", 5, 0) - self.assertRaises(ValueError, self.samfile.count, "chr1", -5, -10) - - def testOutOfRangeNegativeOldFormat(self): - self.assertRaises(ValueError, self.samfile.fetch, region="chr1:-5-10") - self.assertRaises(ValueError, self.samfile.fetch, region="chr1:-5-0") - self.assertRaises(ValueError, self.samfile.fetch, region="chr1:-5--10") - - self.assertRaises(ValueError, self.samfile.count, region="chr1:-5-10") - self.assertRaises(ValueError, self.samfile.count, region="chr1:-5-0") - self.assertRaises(ValueError, self.samfile.count, region="chr1:-5--10") - - def testOutOfRangNewFormat(self): - self.assertRaises( - ValueError, self.samfile.fetch, "chr1", 9999999999, 99999999999) - self.assertRaises( - ValueError, self.samfile.count, "chr1", 9999999999, 99999999999) - - def testOutOfRangeLargeNewFormat(self): - self.assertRaises(ValueError, self.samfile.fetch, "chr1", - 9999999999999999999999999999999, 9999999999999999999999999999999999999999) - self.assertRaises(ValueError, self.samfile.count, "chr1", - 9999999999999999999999999999999, 9999999999999999999999999999999999999999) - - def testOutOfRangeLargeOldFormat(self): - self.assertRaises( - ValueError, self.samfile.fetch, "chr1:99999999999999999-999999999999999999") - self.assertRaises( - ValueError, self.samfile.count, "chr1:99999999999999999-999999999999999999") - - def testZeroToZero(self): - '''see issue 44''' - self.assertEqual(len(list(self.samfile.fetch('chr1', 0, 0))), 0) - - def tearDown(self): - self.samfile.close() - - -class TestWrongFormat(unittest.TestCase): - - '''test cases for opening files not in bam/sam format.''' - - def testOpenSamAsBam(self): - self.assertRaises(ValueError, - pysam.Samfile, - os.path.join(DATADIR, 'ex1.sam'), - 'rb') - - def testOpenBamAsSam(self): - # test fails, needs to be implemented. - # sam.fetch() fails on reading, not on opening - # self.assertRaises( ValueError, pysam.Samfile, 'ex1.bam', 'r' ) - pass - - def testOpenFastaAsSam(self): - # test fails, needs to be implemented. - # sam.fetch() fails on reading, not on opening - # self.assertRaises( ValueError, pysam.Samfile, 'ex1.fa', 'r' ) - pass - - def testOpenFastaAsBam(self): - self.assertRaises(ValueError, - pysam.Samfile, - os.path.join(DATADIR, 'ex1.fa'), - 'rb') - - -class ReadTest(unittest.TestCase): - - def checkFieldEqual(self, read1, read2, exclude=[]): - '''check if two reads are equal by comparing each field.''' - - # add the . for refactoring purposes. - for x in (".qname", ".seq", ".flag", - ".rname", ".pos", ".mapq", ".cigar", - ".mrnm", ".mpos", ".isize", - ".qual", - ".bin", - ".is_paired", ".is_proper_pair", - ".is_unmapped", ".mate_is_unmapped", - ".is_reverse", ".mate_is_reverse", - ".is_read1", ".is_read2", - ".is_secondary", ".is_qcfail", - ".is_duplicate"): - n = x[1:] - if n in exclude: - continue - self.assertEqual(getattr(read1, n), getattr(read2, n), - "attribute mismatch for %s: %s != %s" % - (n, getattr(read1, n), getattr(read2, n))) - - -class TestAlignedRead(ReadTest): - - '''tests to check if aligned read can be constructed - and manipulated. - ''' - - def testEmpty(self): - a = pysam.AlignedRead() - self.assertEqual(a.qname, None) - self.assertEqual(a.seq, None) - self.assertEqual(a.qual, None) - self.assertEqual(a.flag, 0) - self.assertEqual(a.rname, -1) - self.assertEqual(a.mapq, 0) - self.assertEqual(a.cigar, []) - self.assertEqual(a.tags, []) - self.assertEqual(a.mrnm, -1) - self.assertEqual(a.mpos, -1) - self.assertEqual(a.isize, 0) - - def testStrOfEmptyRead(self): - a = pysam.AlignedRead() - s = str(a) - self.assertEqual( - "None\t0\t-1\t-1\t0\tNone\t-1\t-1\t0\tNone\tNone\t[]", - s) - - def buildRead(self): - '''build an example read.''' - - a = pysam.AlignedRead() - a.qname = "read_12345" - a.seq = "ACGT" * 10 - a.flag = 0 - a.rname = 0 - a.pos = 20 - a.mapq = 20 - a.cigar = ((0, 10), (2, 1), (0, 9), (1, 1), (0, 20)) - a.mrnm = 0 - a.mpos = 200 - a.isize = 167 - a.qual = "1234" * 10 - # todo: create tags - return a - - def testUpdate(self): - '''check if updating fields affects other variable length data - ''' - a = self.buildRead() - b = self.buildRead() - - # check qname - b.qname = "read_123" - self.checkFieldEqual(a, b, "qname") - b.qname = "read_12345678" - self.checkFieldEqual(a, b, "qname") - b.qname = "read_12345" - self.checkFieldEqual(a, b) - - # check cigar - b.cigar = ((0, 10), ) - self.checkFieldEqual(a, b, "cigar") - b.cigar = ((0, 10), (2, 1), (0, 10)) - self.checkFieldEqual(a, b, "cigar") - b.cigar = ((0, 10), (2, 1), (0, 9), (1, 1), (0, 20)) - self.checkFieldEqual(a, b) - - # check seq - b.seq = "ACGT" - self.checkFieldEqual(a, b, ("seq", "qual")) - b.seq = "ACGT" * 3 - self.checkFieldEqual(a, b, ("seq", "qual")) - b.seq = "ACGT" * 10 - self.checkFieldEqual(a, b, ("qual",)) - - # reset qual - b = self.buildRead() - - # check flags: - for x in ( - "is_paired", "is_proper_pair", - "is_unmapped", "mate_is_unmapped", - "is_reverse", "mate_is_reverse", - "is_read1", "is_read2", - "is_secondary", "is_qcfail", - "is_duplicate"): - setattr(b, x, True) - self.assertEqual(getattr(b, x), True) - self.checkFieldEqual(a, b, ("flag", x,)) - setattr(b, x, False) - self.assertEqual(getattr(b, x), False) - self.checkFieldEqual(a, b) - - def testUpdate2(self): - '''issue 135: inplace update of sequence and quality score. - - This does not work as setting the sequence will erase - the quality scores. - ''' - a = self.buildRead() - a.seq = a.seq[5:10] - self.assertEqual(a.qual, None) - - a = self.buildRead() - s = a.qual - a.seq = a.seq[5:10] - a.qual = s[5:10] - - self.assertEqual(a.qual, s[5:10]) - - def testLargeRead(self): - '''build an example read.''' - - a = pysam.AlignedRead() - a.qname = "read_12345" - a.seq = "ACGT" * 200 - a.flag = 0 - a.rname = 0 - a.pos = 20 - a.mapq = 20 - a.cigar = ((0, 4 * 200), ) - a.mrnm = 0 - a.mpos = 200 - a.isize = 167 - a.qual = "1234" * 200 - - return a - - def testTagParsing(self): - '''test for tag parsing - - see http://groups.google.com/group/pysam-user-group/browse_thread/thread/67ca204059ea465a - ''' - samfile = pysam.Samfile(os.path.join(DATADIR, "ex8.bam"), - "rb") - - for entry in samfile: - before = entry.tags - entry.tags = entry.tags - after = entry.tags - self.assertEqual(after, before) - - def testUpdateTlen(self): - '''check if updating tlen works''' - a = self.buildRead() - oldlen = a.tlen - oldlen *= 2 - a.tlen = oldlen - self.assertEqual(a.tlen, oldlen) - - def testPositions(self): - a = self.buildRead() - self.assertEqual(a.positions, - [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 31, 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, - 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]) - - self.assertEqual(a.aligned_pairs, - [(0, 20), (1, 21), (2, 22), (3, 23), (4, 24), - (5, 25), (6, 26), (7, 27), (8, 28), (9, 29), - (None, 30), - (10, 31), (11, 32), (12, 33), (13, 34), (14, 35), - (15, 36), (16, 37), (17, 38), (18, 39), (19, None), - (20, 40), (21, 41), (22, 42), (23, 43), (24, 44), - (25, 45), (26, 46), (27, 47), (28, 48), (29, 49), - (30, 50), (31, 51), (32, 52), (33, 53), (34, 54), - (35, 55), (36, 56), (37, 57), (38, 58), (39, 59)]) - - self.assertEqual( - a.positions, - [x[1] for x in a.aligned_pairs - if x[0] is not None and x[1] is not None]) - # alen is the length of the aligned read in genome - self.assertEqual(a.alen, a.aligned_pairs[-1][0] + 1) - # aend points to one beyond last aligned base in ref - self.assertEqual(a.positions[-1], a.aend - 1) - - def testBlocks(self): - a = self.buildRead() - self.assertEqual(a.blocks, - [(20, 30), (31, 40), (40, 60)]) - - # Disabled as not backwards compatible - # def testFancyStr(self): - # a = self.buildRead() - # output = a.fancy_str() - # self.assertEqual(len(output), 9) - - -class TestDeNovoConstruction(ReadTest): - - '''check BAM/SAM file construction using ex6.sam - - (note these are +1 coordinates): - - read_28833_29006_6945 99 chr1 33 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 RG:Z:L1 - read_28701_28881_323b 147 chr2 88 30 35M = 500 412 ACCTATATCTTGGCCTTGGCCGATGCGGCCTTGCA <<<<<;<<<<7;:<<<6;<<<<<<<<<<<<7<<<< MF:i:18 RG:Z:L2 - ''' - - header = {'HD': {'VN': '1.0'}, - 'SQ': [{'LN': 1575, 'SN': 'chr1'}, - {'LN': 1584, 'SN': 'chr2'}], } - - bamfile = os.path.join(DATADIR, "ex6.bam") - samfile = os.path.join(DATADIR, "ex6.sam") - - def setUp(self): - - a = pysam.AlignedRead() - a.qname = "read_28833_29006_6945" - a.seq = "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG" - a.flag = 99 - a.rname = 0 - a.pos = 32 - a.mapq = 20 - a.cigar = ((0, 10), (2, 1), (0, 25)) - a.mrnm = 0 - a.mpos = 199 - a.isize = 167 - a.qual = "<<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<<" - a.tags = (("NM", 1), - ("RG", "L1")) - - b = pysam.AlignedRead() - b.qname = "read_28701_28881_323b" - b.seq = "ACCTATATCTTGGCCTTGGCCGATGCGGCCTTGCA" - b.flag = 147 - b.rname = 1 - b.pos = 87 - b.mapq = 30 - b.cigar = ((0, 35), ) - b.mrnm = 1 - b.mpos = 499 - b.isize = 412 - b.qual = "<<<<<;<<<<7;:<<<6;<<<<<<<<<<<<7<<<<" - b.tags = (("MF", 18), - ("RG", "L2")) - - self.reads = (a, b) - - # TODO - # def testSAMWholeFile(self): - - # tmpfilename = "tmp_%i.sam" % id(self) - - # outfile = pysam.Samfile(tmpfilename, - # "wh", - # header=self.header) - - # for x in self.reads: - # outfile.write(x) - # outfile.close() - # self.assertTrue(checkBinaryEqual(tmpfilename, self.samfile), - # "mismatch when construction SAM file, see %s %s" % (tmpfilename, self.samfile)) - - # os.unlink(tmpfilename) - - def testBAMPerRead(self): - '''check if individual reads are binary equal.''' - infile = pysam.Samfile(self.bamfile, "rb") - - others = list(infile) - for denovo, other in zip(others, self.reads): - self.checkFieldEqual(other, denovo) - self.assertEqual(other.compare(denovo), 0) - - # TODO - # def testSAMPerRead(self): - # '''check if individual reads are binary equal.''' - # infile = pysam.Samfile(self.samfile, "r") - - # others = list(infile) - # for denovo, other in zip(others, self.reads): - # self.checkFieldEqual(other, denovo) - # self.assertEqual(other.compare(denovo), 0) - - def testBAMWholeFile(self): - - tmpfilename = "tmp_%i.bam" % id(self) - - outfile = pysam.Samfile(tmpfilename, "wb", header=self.header) - - for x in self.reads: - outfile.write(x) - outfile.close() - - self.assertTrue(checkBinaryEqual(tmpfilename, self.bamfile), - "mismatch when construction BAM file, see %s %s" % (tmpfilename, self.bamfile)) - - os.unlink(tmpfilename) - - -class TestDeNovoConstructionUserTags(TestDeNovoConstruction): - - '''test de novo construction with a header that contains lower-case tags.''' - - header = {'HD': {'VN': '1.0'}, - 'SQ': [{'LN': 1575, 'SN': 'chr1'}, - {'LN': 1584, 'SN': 'chr2'}], - 'x1': {'A': 2, 'B': 5}, - 'x3': {'A': 6, 'B': 5}, - 'x2': {'A': 4, 'B': 5}} - - bamfile = os.path.join(DATADIR, "example_user_header.bam") - samfile = os.path.join(DATADIR, "example_user_header.sam") - - -class TestEmptyHeader(unittest.TestCase): - - '''see issue 84.''' - - def testEmptyHeader(self): - - s = pysam.Samfile(os.path.join(DATADIR, 'example_empty_header.bam')) - self.assertEqual(s.header, {'SQ': [{'LN': 1000, 'SN': 'chr1'}]}) - -COMPARE_BTAG = [100, 1, 91, 0, 7, 101, 0, 201, 96, 204, - 0, 0, 87, 109, 0, 7, 97, 112, 1, 12, 78, - 197, 0, 7, 100, 95, 101, 202, 0, 6, 0, 1, - 186, 0, 84, 0, 244, 0, 0, 324, 0, 107, 195, - 101, 113, 0, 102, 0, 104, 3, 0, 101, 1, 0, - 212, 6, 0, 0, 1, 0, 74, 1, 11, 0, 196, 2, - 197, 103, 0, 108, 98, 2, 7, 0, 1, 2, 194, - 0, 180, 0, 108, 0, 203, 104, 16, 5, 205, - 0, 0, 0, 1, 1, 100, 98, 0, 0, 204, 6, 0, - 79, 0, 0, 101, 7, 109, 90, 265, 1, 27, 10, - 109, 102, 9, 0, 292, 0, 110, 0, 0, 102, - 112, 0, 0, 84, 100, 103, 2, 81, 126, 0, 2, - 90, 0, 15, 96, 15, 1, 0, 2, 0, 107, 92, 0, - 0, 101, 3, 98, 15, 102, 13, 116, 116, 90, 93, - 198, 0, 0, 0, 199, 92, 26, 495, 100, 5, 0, - 100, 5, 209, 0, 92, 107, 90, 0, 0, 0, 0, 109, - 194, 7, 94, 200, 0, 40, 197, 0, 11, 0, 0, 112, - 110, 6, 4, 200, 28, 0, 196, 0, 203, 1, 129, - 0, 0, 1, 0, 94, 0, 1, 0, 107, 5, 201, 3, 3, 100, - 0, 121, 0, 7, 0, 1, 105, 306, 3, 86, 8, 183, 0, - 12, 163, 17, 83, 22, 0, 0, 1, 8, 109, 103, 0, 0, - 295, 0, 200, 16, 172, 3, 16, 182, 3, 11, 0, 0, - 223, 111, 103, 0, 5, 225, 0, 95] - - -class TestBTagSam(unittest.TestCase): - - '''see issue 81.''' - - compare = [COMPARE_BTAG, - [-100, 200, -300, -400], - [-100, 12], - [12, 15], - [-1.0, 5.0, 2.5]] - - filename = os.path.join(DATADIR, 'example_btag.sam') - - read0 = [('RG', 'QW85I'), - ('PG', 'tmap'), - ('MD', '140'), - ('NM', 0), - ('AS', 140), - ('FZ', array.array('H', COMPARE_BTAG)), - ('XA', 'map2-1'), - ('XS', 53), - ('XT', 38), - ('XF', 1), - ('XE', 0)] - - def testReadTags(self): - - s = pysam.Samfile(self.filename) - for x, read in enumerate(s): - tags = read.tags - if x == 0: - self.assertEqual(tags, self.read0) - - fz = list(dict(tags)["FZ"]) - self.assertEqual(fz, self.compare[x]) - self.assertEqual(list(read.opt("FZ")), self.compare[x]) - self.assertEqual(tags, read.get_tags()) - for tag, value in tags: - self.assertEqual(value, read.get_tag(tag)) - - def testReadWriteTags(self): - - s = pysam.Samfile(self.filename) - for read in s: - before = read.tags - read.tags = before - self.assertEqual(read.tags, before) - - read.set_tags(before) - self.assertEqual(read.tags, before) - - for tag, value in before: - read.set_tag(tag, value) - self.assertEqual(value, read.get_tag(tag)) - - -class TestBTagBam(TestBTagSam): - filename = os.path.join(DATADIR, 'example_btag.bam') - - -class TestDoubleFetch(unittest.TestCase): - - '''check if two iterators on the same bamfile are independent.''' - - filename = os.path.join(DATADIR, 'ex1.bam') - - def testDoubleFetch(self): - - samfile1 = pysam.Samfile(self.filename, 'rb') - - for a, b in zip(samfile1.fetch(multiple_iterators=True), - samfile1.fetch(multiple_iterators=True)): - self.assertEqual(a.compare(b), 0) - - def testDoubleFetchWithRegion(self): - - samfile1 = pysam.Samfile(self.filename, 'rb') - chr, start, stop = 'chr1', 200, 3000000 - # just making sure the test has something to catch - self.assertTrue(len(list(samfile1.fetch(chr, start, stop))) > 0) - - for a, b in zip(samfile1.fetch(chr, start, stop), - samfile1.fetch(chr, start, stop, - multiple_iterators=True)): - self.assertEqual(a.compare(b), 0) - - def testDoubleFetchUntilEOF(self): - - samfile1 = pysam.Samfile(self.filename, 'rb') - - for a, b in zip(samfile1.fetch(until_eof=True), - samfile1.fetch(until_eof=True, - multiple_iterators=True)): - self.assertEqual(a.compare(b), 0) - - -class TestRemoteFileFTP(unittest.TestCase): - - '''test remote access. - - ''' - - # Need to find an ftp server without password on standard - # port. - - url = "ftp://ftp.sanger.ac.uk/pub/rd/humanSequences/CV.bam" - region = "1:1-1000" - - def testFTPView(self): - return - if not checkURL(self.url): - return - - result = pysam.samtools.view(self.url, self.region) - self.assertEqual(len(result), 36) - - def testFTPFetch(self): - return - if not checkURL(self.url): - return - - samfile = pysam.Samfile(self.url, "rb") - result = list(samfile.fetch(region=self.region)) - self.assertEqual(len(result), 36) - - -class TestRemoteFileHTTP(unittest.TestCase): - - url = "http://genserv.anat.ox.ac.uk/downloads/pysam/test/ex1.bam" - region = "chr1:1-1000" - local = os.path.join(DATADIR, "ex1.bam") - - def testView(self): - if not checkURL(self.url): - return - - samfile_local = pysam.Samfile(self.local, "rb") - ref = list(samfile_local.fetch(region=self.region)) - - result = pysam.samtools.view( - self.url, self.region).splitlines(True) - self.assertEqual(len(result), len(ref)) - - def testFetch(self): - if not checkURL(self.url): - return - - samfile = pysam.Samfile(self.url, "rb") - result = list(samfile.fetch(region=self.region)) - samfile_local = pysam.Samfile(self.local, "rb") - ref = list(samfile_local.fetch(region=self.region)) - - self.assertEqual(len(ref), len(result)) - for x, y in zip(result, ref): - self.assertEqual(x.compare(y), 0) - - def testFetchAll(self): - if not checkURL(self.url): - return - - samfile = pysam.Samfile(self.url, "rb") - result = list(samfile.fetch()) - samfile_local = pysam.Samfile(self.local, "rb") - ref = list(samfile_local.fetch()) - - self.assertEqual(len(ref), len(result)) - for x, y in zip(result, ref): - self.assertEqual(x.compare(y), 0) - - -class TestLargeOptValues(unittest.TestCase): - - ints = (65536, 214748, 2147484, 2147483647) - floats = (65536.0, 214748.0, 2147484.0) - - def check(self, samfile): - - i = samfile.fetch() - for exp in self.ints: - rr = next(i) - obs = rr.opt("ZP") - self.assertEqual(exp, obs, - "expected %s, got %s\n%s" % - (str(exp), str(obs), str(rr))) - - for exp in [-x for x in self.ints]: - rr = next(i) - obs = rr.opt("ZP") - self.assertEqual(exp, obs, - "expected %s, got %s\n%s" % - (str(exp), str(obs), str(rr))) - - for exp in self.floats: - rr = next(i) - obs = rr.opt("ZP") - self.assertEqual(exp, obs, - "expected %s, got %s\n%s" % - (str(exp), str(obs), str(rr))) - - for exp in [-x for x in self.floats]: - rr = next(i) - obs = rr.opt("ZP") - self.assertEqual(exp, obs, "expected %s, got %s\n%s" % - (str(exp), str(obs), str(rr))) - - def testSAM(self): - samfile = pysam.Samfile( - os.path.join(DATADIR, "ex10.sam"), - "r") - self.check(samfile) - - def testBAM(self): - samfile = pysam.Samfile( - os.path.join(DATADIR, "ex10.bam"), - "rb") - self.check(samfile) - - -class TestPileup(unittest.TestCase): - - '''test pileup functionality.''' - - samfilename = "pysam_data/ex1.bam" - fastafilename = "pysam_data/ex1.fa" - - def setUp(self): - - self.samfile = pysam.Samfile(self.samfilename) - self.fastafile = pysam.Fastafile(self.fastafilename) - - def checkEqual(self, references, iterator): - - for x, column in enumerate(iterator): - (contig, pos, reference_base, - read_bases, read_qualities, alignment_mapping_qualities) \ - = references[x][:-1].split("\t") - self.assertEqual(int(pos) - 1, column.pos) - - def testSamtoolsStepper(self): - refs = force_str( - pysam.samtools.mpileup( - "-f", self.fastafilename, - self.samfilename)).splitlines(True) - iterator = self.samfile.pileup( - stepper="samtools", - fastafile=self.fastafile) - self.checkEqual(refs, iterator) - - def testAllStepper(self): - refs = force_str( - pysam.samtools.mpileup( - "-f", self.fastafilename, - "-A", "-B", - self.samfilename)).splitlines(True) - - iterator = self.samfile.pileup( - stepper="all", - fastafile=self.fastafile) - self.checkEqual(refs, iterator) - - -class TestLogging(unittest.TestCase): - - '''test around bug issue 42, - - failed in versions < 0.4 - ''' - - def check(self, bamfile, log): - - if log: - logger = logging.getLogger('franklin') - logger.setLevel(logging.INFO) - formatter = logging.Formatter( - '%(asctime)s %(levelname)s %(message)s') - log_hand = logging.FileHandler('log.txt') - log_hand.setFormatter(formatter) - logger.addHandler(log_hand) - - bam = pysam.Samfile(bamfile, 'rb') - cols = bam.pileup() - self.assertTrue(True) - - def testFail1(self): - self.check(os.path.join(DATADIR, "ex9_fail.bam"), - False) - self.check(os.path.join(DATADIR, "ex9_fail.bam"), - True) - - def testNoFail1(self): - self.check(os.path.join(DATADIR, "ex9_nofail.bam"), - False) - self.check(os.path.join(DATADIR, "ex9_nofail.bam"), - True) - - def testNoFail2(self): - self.check(os.path.join(DATADIR, "ex9_nofail.bam"), - True) - self.check(os.path.join(DATADIR, "ex9_nofail.bam"), - True) - -# TODOS -# 1. finish testing all properties within pileup objects -# 2. check exceptions and bad input problems (missing files, optional fields that aren't present, etc...) -# 3. check: presence of sequence - - -class TestSamfileUtilityFunctions(unittest.TestCase): - - def testCount(self): - - samfile = pysam.Samfile(os.path.join(DATADIR, "ex1.bam"), - "rb") - - for contig in ("chr1", "chr2"): - for start in range(0, 2000, 100): - end = start + 1 - self.assertEqual( - len(list(samfile.fetch(contig, start, end))), - samfile.count(contig, start, end), - 'number mismatch for %s:%i-%i %i != %i' % ( - contig, start, end, - len(list(samfile.fetch(contig, start, end))), - samfile.count(contig, start, end))) - - # test empty intervals - self.assertEqual( - len(list(samfile.fetch(contig, start, start))), - samfile.count(contig, start, start), - 'number mismatch for %s:%i-%i %i != %i' % ( - contig, start, start, - len(list(samfile.fetch(contig, start, start))), - samfile.count(contig, start, start))) - - # test half empty intervals - self.assertEqual(len(list(samfile.fetch(contig, start))), - samfile.count(contig, start)) - - self.assertEqual( - len(list(samfile.fetch(contig, start))), - samfile.count(contig, start), - 'number mismatch for %s:%i %i != %i' % ( - contig, start, - len(list(samfile.fetch(contig, start))), - samfile.count(contig, start))) - - def testMate(self): - '''test mate access.''' - - with open(os.path.join(DATADIR, "ex1.sam"), "rb") as inf: - readnames = [x.split(b"\t")[0] for x in inf.readlines()] - if sys.version_info[0] >= 3: - readnames = [name.decode('ascii') for name in readnames] - - counts = collections.defaultdict(int) - for x in readnames: - counts[x] += 1 - - samfile = pysam.Samfile(os.path.join(DATADIR, "ex1.bam"), - "rb") - - for read in samfile.fetch(): - if not read.is_paired: - self.assertRaises(ValueError, samfile.mate, read) - elif read.mate_is_unmapped: - self.assertRaises(ValueError, samfile.mate, read) - else: - if counts[read.qname] == 1: - self.assertRaises(ValueError, samfile.mate, read) - else: - mate = samfile.mate(read) - self.assertEqual(read.qname, mate.qname) - self.assertEqual(read.is_read1, mate.is_read2) - self.assertEqual(read.is_read2, mate.is_read1) - self.assertEqual(read.pos, mate.mpos) - self.assertEqual(read.mpos, mate.pos) - - def testIndexStats(self): - '''test if total number of mapped/unmapped reads is correct.''' - - samfile = pysam.Samfile(os.path.join(DATADIR, "ex1.bam"), - "rb") - self.assertEqual(samfile.mapped, 3235) - self.assertEqual(samfile.unmapped, 35) - self.assertEqual(samfile.nocoordinate, 0) - - -class TestSamtoolsProxy(unittest.TestCase): - - '''tests for sanity checking access to samtools functions.''' - - def testIndex(self): - self.assertRaises(IOError, pysam.samtools.index, "missing_file") - - def testView(self): - # note that view still echos "open: No such file or directory" - self.assertRaises(pysam.SamtoolsError, pysam.samtools.view, "missing_file") - - def testSort(self): - self.assertRaises(pysam.SamtoolsError, pysam.samtools.sort, "missing_file") - - -class TestSamfileIndex(unittest.TestCase): - - def testIndex(self): - samfile = pysam.Samfile(os.path.join(DATADIR, "ex1.bam"), - "rb") - index = pysam.IndexedReads(samfile) - index.build() - reads = collections.defaultdict(int) - - for read in samfile: - reads[read.qname] += 1 - - for qname, counts in reads.items(): - found = list(index.find(qname)) - self.assertEqual(len(found), counts) - for x in found: - self.assertEqual(x.qname, qname) - - -if __name__ == "__main__": - # build data files - print ("building data files") - subprocess.call("make -C %s" % DATADIR, shell=True) - print ("starting tests") - unittest.main() - print ("completed tests") diff --git a/tests/StreamFiledescriptors_test.py b/tests/StreamFiledescriptors_test.py index ce59da75f..f09ef372a 100644 --- a/tests/StreamFiledescriptors_test.py +++ b/tests/StreamFiledescriptors_test.py @@ -1,19 +1,18 @@ import os +import sys import subprocess import threading import errno import unittest - from pysam import AlignmentFile +from TestUtils import BAM_DATADIR -DATADIR = os.path.abspath(os.path.join( - os.path.dirname(__file__), - "pysam_data")) +IS_PYTHON2 = sys.version_info[0] == 2 def alignmentfile_writer_thread(infile, outfile): def _writer_thread(infile, outfile): - """read from infile and write to outfile""" + """read from infile and write to outfile""" try: i = 0 for record in infile: @@ -41,41 +40,49 @@ def stream_process(self, proc, in_stream, out_stream, writer): read += 1 return 0, read + @unittest.skipIf(IS_PYTHON2, "no context manager in py2") def test_text_processing(self): - proc = subprocess.Popen('head -n200', - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - shell=True) + with subprocess.Popen('head -n200', + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + shell=True) as proc: - in_stream = AlignmentFile('pysam_data/ex1.bam') - out_stream = AlignmentFile(proc.stdin, 'wh', header=in_stream.header) - writer = alignmentfile_writer_thread(in_stream, - out_stream) + in_stream = AlignmentFile(os.path.join(BAM_DATADIR, 'ex1.bam')) + out_stream = AlignmentFile( + proc.stdin, 'wh', header=in_stream.header) + writer = alignmentfile_writer_thread(in_stream, + out_stream) - written, read = self.stream_process(proc, - in_stream, - out_stream, - writer) - self.assertEqual(read, 198) + written, read = self.stream_process(proc, + in_stream, + out_stream, + writer) + self.assertEqual(read, 198) + @unittest.skip("test contains bug") def test_samtools_processing(self): - proc = subprocess.Popen('samtools view -b -f 4', - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - shell=True) - - in_stream = AlignmentFile('pysam_data/ex1.bam') - out_stream = AlignmentFile(proc.stdin, 'wb', header=in_stream.header) - writer = alignmentfile_writer_thread(in_stream, - out_stream) - - written, read = self.stream_process(proc, - in_stream, - out_stream, - writer) - self.assertEqual(read, 35) + # The following test causes the suite to hang + # as the stream_processor raises: + # ValueError: file has no sequences defined (mode='r') - is it SAM/BAM format? + # The whole setup then hangs during exception handling. + with subprocess.Popen('samtools view -b -f 4', + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + shell=True) as proc: + + in_stream = AlignmentFile(os.path.join(BAM_DATADIR, 'ex1.bam')) + out_stream = AlignmentFile( + proc.stdin, 'wb', header=in_stream.header) + writer = alignmentfile_writer_thread(in_stream, + out_stream) + + written, read = self.stream_process(proc, + in_stream, + out_stream, + writer) + self.assertEqual(read, 35) if __name__ == "__main__": diff --git a/tests/TestUtils.py b/tests/TestUtils.py index 71ab22a69..7811b9e18 100644 --- a/tests/TestUtils.py +++ b/tests/TestUtils.py @@ -1,13 +1,35 @@ import sys import os -import pysam +import glob import difflib import gzip +import contextlib import inspect import tempfile +import pysam + +WORKDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), + "pysam_test_work")) + +BAM_DATADIR = os.path.abspath(os.path.join(os.path.dirname(__file__), + "pysam_data")) + +TABIX_DATADIR = os.path.abspath(os.path.join(os.path.dirname(__file__), + "tabix_data")) + +CBCF_DATADIR = os.path.abspath(os.path.join(os.path.dirname(__file__), + "cbcf_data")) + +LINKDIR = os.path.abspath(os.path.join( + os.path.dirname(__file__), "..", "linker_tests")) + + +TESTS_TEMPDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "tmp")) + IS_PYTHON3 = sys.version_info[0] >= 3 + if IS_PYTHON3: from itertools import zip_longest from urllib.request import urlopen @@ -22,6 +44,7 @@ def force_str(s): return s.decode('ascii') except AttributeError: return s + def force_bytes(s): try: return s.encode('ascii') @@ -30,6 +53,7 @@ def force_bytes(s): else: def force_str(s): return s + def force_bytes(s): return s @@ -78,7 +102,6 @@ def check_samtools_view_equal( '''return true if the two files are equal in their content through samtools view. ''' - # strip MD and NM tags, as not preserved in CRAM files args = ["-x", "MD", "-x", "NM"] if not without_header: @@ -99,9 +122,9 @@ def check_samtools_view_equal( l1 = sorted(l1[:-1].split("\t")) l2 = sorted(l2[:-1].split("\t")) if l1 != l2: - print ("mismatch in line %i" % n) - print (l1) - print (l2) + print("mismatch in line %i" % n) + print(l1) + print(l2) return False else: return False @@ -109,7 +132,7 @@ def check_samtools_view_equal( return True -def checkURL(url): +def check_url(url): '''return True if URL is available. A URL might not be available if it is the wrong URL @@ -161,8 +184,10 @@ def check_lines_equal(cls, a, b, sort=False, filter_f=None, msg=None): filter_f: remover lines in both a and b where expression is True """ - aa = openfile(a).readlines() - bb = openfile(b).readlines() + with openfile(a) as inf: + aa = inf.readlines() + with openfile(b) as inf: + bb = inf.readlines() if filter_f is not None: aa = [x for x in aa if not filter_f(x)] @@ -176,10 +201,67 @@ def check_lines_equal(cls, a, b, sort=False, filter_f=None, msg=None): def get_temp_filename(suffix=""): caller_name = inspect.getouterframes(inspect.currentframe(), 2)[1][3] + try: + os.makedirs(TESTS_TEMPDIR) + except OSError: + pass + f = tempfile.NamedTemporaryFile( - prefix="tmp_{}_".format(caller_name), + prefix="pysamtests_tmp_{}_".format(caller_name), suffix=suffix, delete=False, - dir=".") + dir=TESTS_TEMPDIR) + f.close() return f.name + +@contextlib.contextmanager +def get_temp_context(suffix="", keep=False): + caller_name = inspect.getouterframes(inspect.currentframe(), 3)[1][3] + try: + os.makedirs(TESTS_TEMPDIR) + except OSError: + pass + + f = tempfile.NamedTemporaryFile( + prefix="pysamtests_tmp_{}_".format(caller_name), + suffix=suffix, + delete=False, + dir=TESTS_TEMPDIR) + + f.close() + yield f.name + + if not keep: + # clear up any indices as well + for f in glob.glob(f.name + "*"): + os.unlink(f) + + +def load_and_convert(filename, encode=True): + '''load data from filename and convert all fields to string. + + Filename can be either plain or compressed (ending in .gz). + ''' + data = [] + if filename.endswith(".gz"): + with gzip.open(filename) as inf: + for line in inf: + line = line.decode("ascii") + if line.startswith("#"): + continue + d = line.strip().split("\t") + data.append(d) + else: + with open(filename) as f: + for line in f: + if line.startswith("#"): + continue + d = line.strip().split("\t") + data.append(d) + + return data + + +def flatten_nested_list(l): + return [i for ll in l for i in ll] diff --git a/tests/VariantFileFetchTestUtils.py b/tests/VariantFileFetchTestUtils.py new file mode 100644 index 000000000..1aaca37c7 --- /dev/null +++ b/tests/VariantFileFetchTestUtils.py @@ -0,0 +1,69 @@ +import os +import subprocess +import pysam + +try: + import cyvcf2 +except ImportError: + pass + + +from TestUtils import CBCF_DATADIR, force_str + +def build_filter_from_vcf_with_samtoolsshell(fn): + retval = os.popen( + "bcftools filter -e \"N_ALT != 1 || QUAL < 20 || maf[0]>0.05\" {} | grep -cv ^# ".format(fn)).read() + return int(retval.strip()) + + +def build_filter_from_vcf_with_bcftoolspipe(fn): + FNULL = open(os.devnull, 'w') + with subprocess.Popen([ + "bcftools", + "filter", + "-e", + "N_ALT != 1 || QUAL < 20 || maf[0]>0.05", + fn], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=FNULL) as proc: + data = [line for line in proc.stdout.readlines() if not line.startswith(b"#")] + return len(data) + + +def build_filter_from_vcf_with_cyvcf2(fn): + n = 0 + try: + for v in cyvcf2.VCF(fn): + if len(v.ALT) > 1: + continue + if v.QUAL < 20: + continue + if v.aaf > 0.05: + continue + n += 1 + except NameError: + n = 9120 + return n + + +def build_filter_from_vcf_with_pysam(fn): + n = 0 + with pysam.VariantFile(fn) as vcf: + for v in vcf: + # the two commands below take >1s out of 19s total + if len(v.alts) > 1: + continue + if v.qual < 20: + continue + # this takes 12s out of 19s total + gts = [s['GT'] for s in v.samples.values()] + # the lines below take 6s out of 19s total + an = sum(len(gt) for gt in gts) + ac = sum(sum(gt) for gt in gts) + aaf = (float(ac) / float(an)) + if aaf > 0.05: + continue + n += 1 + return n + diff --git a/tests/VariantFile_bench.py b/tests/VariantFile_bench.py new file mode 100644 index 000000000..d48760cbf --- /dev/null +++ b/tests/VariantFile_bench.py @@ -0,0 +1,59 @@ +"""Benchmarking module for AlignmentFile functionality""" +import os +import pytest + + +from TestUtils import BAM_DATADIR, force_str, flatten_nested_list +from VariantFileFetchTestUtils import * + + +GENOMES_URL = "ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/release/20130502/ALL.chr{chrom}.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz" + +CHROM = 22 + + +@pytest.fixture +def genomes_data(): + url = GENOMES_URL.format(chrom=CHROM) + fn = os.path.basename(url) + print(fn) + if not os.path.exists(fn): + os.system("wget {}".format(url)) + if not os.path.exists(fn + ".tbi"): + os.system("wget {}".format(url + ".tbi")) + + fn_small = "small.vcf.gz" + if not os.path.exists(fn_small): + os.system("bcftools view {} | head -n 10000 | bgzip > {}".format(fn, fn_small)) + os.system("tabix -p vcf {}".format(fn_small)) + + return fn_small + + +@pytest.mark.benchmark(min_rounds=1) +def test_build_filter_from_vcf_with_bcftoolsshell(benchmark, genomes_data): + result = benchmark(build_filter_from_vcf_with_samtoolsshell, genomes_data) + assert result == 9120 + + +@pytest.mark.benchmark(min_rounds=1) +def test_build_filter_from_vcf_with_bcftoolpipe(benchmark, genomes_data): + result = benchmark(build_filter_from_vcf_with_bcftoolspipe, genomes_data) + assert result == 9120 + + +@pytest.mark.benchmark(min_rounds=1) +def test_build_filter_from_vcf_with_cyvcf2(benchmark, genomes_data): + result = benchmark(build_filter_from_vcf_with_cyvcf2, genomes_data) + # note: inconsistent with bcftools + assert result == 9114 + + +@pytest.mark.benchmark(min_rounds=1) +def test_build_filter_from_vcf_with_pysam(benchmark, genomes_data): + result = benchmark(build_filter_from_vcf_with_pysam, genomes_data) + # note: inconsistent with bcftools + assert result == 9114 + + + diff --git a/tests/VariantFile_test.py b/tests/VariantFile_test.py index aa82c6656..88bd34ff4 100644 --- a/tests/VariantFile_test.py +++ b/tests/VariantFile_test.py @@ -2,6 +2,7 @@ import sys import unittest import pysam +import shutil import gzip import subprocess @@ -10,10 +11,7 @@ except ImportError: Path = None -from TestUtils import get_temp_filename, check_lines_equal - -DATADIR="cbcf_data" -from tabix_test import loadAndConvert +from TestUtils import get_temp_filename, check_lines_equal, load_and_convert, CBCF_DATADIR, get_temp_context def read_header(filename): @@ -37,22 +35,22 @@ class TestMissingGenotypes(unittest.TestCase): filename = "missing_genotypes.vcf" def setUp(self): - self.compare = loadAndConvert( - os.path.join(DATADIR, self.filename), + self.compare = load_and_convert( + os.path.join(CBCF_DATADIR, self.filename), encode=False) def check(self, filename): """see issue 203 - check for segmentation fault""" - fn = os.path.join(DATADIR, filename) + fn = os.path.join(CBCF_DATADIR, filename) self.assertEqual(True, os.path.exists(fn)) v = pysam.VariantFile(fn) for site in v: - for ss,rec in site.samples.items(): + for ss, rec in site.samples.items(): a, b = ss, rec v = pysam.VariantFile(fn) for x, site in enumerate(v): - for ss,rec in site.samples.items(): + for ss, rec in site.samples.items(): a, b = ss, rec.alleles a, b = ss, rec.allele_indices @@ -63,6 +61,41 @@ def testVCFGZ(self): self.check(self.filename + ".gz") +class TestMissingSamples(unittest.TestCase): + + filename = "gnomad.vcf" + + def setUp(self): + self.compare = load_and_convert( + os.path.join(CBCF_DATADIR, self.filename), + encode=False) + + def check(self, filename): + """see issue #593""" + fn = os.path.join(CBCF_DATADIR, filename) + self.assertEqual(True, os.path.exists(fn)) + expect_fail = not "fixed" in self.filename + with pysam.VariantFile(fn) as inf: + rec = next(inf.fetch()) + if expect_fail: + self.assertRaises(ValueError, rec.info.__getitem__, "GC") + else: + self.assertEqual(rec.info["GC"], (27, 35, 16)) + + def testVCF(self): + self.check(self.filename) + + def testVCFGZ(self): + self.check(self.filename + ".gz") + + +class TestMissingSamplesFixed(TestMissingSamples): + # workaround for NUMBER=G in INFO records: + # perl 's/Number=G/Number=./ if (/INFO/)' + + filename = "gnomad_fixed.vcf" + + class TestOpening(unittest.TestCase): def testMissingFile(self): @@ -74,68 +107,56 @@ def testMissingFileVCFGZ(self): "missing_file.vcf.gz") def testEmptyFileVCF(self): - with open("tmp_testEmptyFile.vcf", "w"): - pass - - self.assertRaises(ValueError, pysam.VariantFile, - "tmp_testEmptyFile.vcf") - - os.unlink("tmp_testEmptyFile.vcf") - - - if Path and sys.version_info >= (3,6): - def testEmptyFileVCFFromPath(self): - with open("tmp_testEmptyFile.vcf", "w"): + with get_temp_context("tmp_testEmptyFile.vcf") as fn: + with open(fn, "w"): pass + self.assertRaises(ValueError, pysam.VariantFile, fn) - self.assertRaises(ValueError, pysam.VariantFile, - Path("tmp_testEmptyFile.vcf")) - - os.unlink("tmp_testEmptyFile.vcf") + if Path and sys.version_info >= (3, 6): + def testEmptyFileVCFFromPath(self): + with get_temp_context("tmp_testEmptyFile.vcf") as fn: + with open(fn, "w"): + pass + self.assertRaises(ValueError, pysam.VariantFile, + Path(fn)) def testEmptyFileVCFGZWithIndex(self): - with open("tmp_testEmptyFile.vcf", "w"): - pass - - pysam.tabix_index("tmp_testEmptyFile.vcf", - preset="vcf", - force=True) - - self.assertRaises(ValueError, pysam.VariantFile, - "tmp_testEmptyFile.vcf.gz") + with get_temp_context("tmp_testEmptyFile.vcf") as fn: + with open(fn, "w"): + pass + # tabix_index will automatically compress + pysam.tabix_index(fn, + preset="vcf", + force=True) - os.unlink("tmp_testEmptyFile.vcf.gz") - os.unlink("tmp_testEmptyFile.vcf.gz.tbi") + self.assertRaises(ValueError, pysam.VariantFile, fn + ".gz") def testEmptyFileVCFGZWithoutIndex(self): - with open("tmp_testEmptyFileWithoutIndex.vcf", "w"): - pass - - pysam.tabix_compress("tmp_testEmptyFileWithoutIndex.vcf", - "tmp_testEmptyFileWithoutIndex.vcf.gz", - force=True) + with get_temp_context("tmp_testEmptyFileWithoutIndex.vcf") as fn: + with open(fn, "w"): + pass - self.assertRaises(ValueError, pysam.VariantFile, - "tmp_testEmptyFileWithoutIndex.vcf.gz") + pysam.tabix_compress(fn, + fn + ".gz", + force=True) - os.unlink("tmp_testEmptyFileWithoutIndex.vcf") - os.unlink("tmp_testEmptyFileWithoutIndex.vcf.gz") + self.assertRaises(ValueError, pysam.VariantFile, fn + ".gz") def testEmptyFileVCFOnlyHeader(self): with pysam.VariantFile(os.path.join( - DATADIR, + CBCF_DATADIR, "example_vcf42_only_header.vcf")) as inf: self.assertEqual(len(list(inf.fetch())), 0) def testEmptyFileVCFGZOnlyHeader(self): with pysam.VariantFile(os.path.join( - DATADIR, + CBCF_DATADIR, "example_vcf42_only_header.vcf")) as inf: self.assertEqual(len(list(inf.fetch())), 0) def testDetectVCF(self): - with pysam.VariantFile(os.path.join(DATADIR, - "example_vcf40.vcf")) as inf: + with pysam.VariantFile(os.path.join(CBCF_DATADIR, + "example_vcf40.vcf")) as inf: self.assertEqual(inf.category, 'VARIANTS') self.assertEqual(inf.format, 'VCF') self.assertEqual(inf.compression, 'NONE') @@ -144,8 +165,8 @@ def testDetectVCF(self): self.assertEqual(len(list(inf.fetch())), 5) def testDetectVCFGZ(self): - with pysam.VariantFile(os.path.join(DATADIR, - "example_vcf40.vcf.gz")) as inf: + with pysam.VariantFile(os.path.join(CBCF_DATADIR, + "example_vcf40.vcf.gz")) as inf: self.assertEqual(inf.category, 'VARIANTS') self.assertEqual(inf.format, 'VCF') self.assertEqual(inf.compression, 'BGZF') @@ -155,7 +176,7 @@ def testDetectVCFGZ(self): def testDetectBCF(self): with pysam.VariantFile(os.path.join( - DATADIR, + CBCF_DATADIR, "example_vcf40.bcf")) as inf: self.assertEqual(inf.category, 'VARIANTS') self.assertEqual(inf.format, 'BCF') @@ -165,13 +186,74 @@ def testDetectBCF(self): self.assertEqual(len(list(inf.fetch())), 5) +class TestIndexFormatsVCF(unittest.TestCase): + + vcf_filename = os.path.join(CBCF_DATADIR, "example_vcf40.vcf") + bcf_filename = os.path.join(CBCF_DATADIR, "example_vcf40.bcf") + + def test_vcf_with_tbi_index(self): + with get_temp_context("tmp_fn.vcf") as fn: + shutil.copyfile(self.vcf_filename, fn) + pysam.tabix_index(fn, preset="vcf", force=True) + self.assertTrue(os.path.exists(fn + ".gz" + ".tbi")) + self.assertFalse(os.path.exists(fn + ".gz" + ".csi")) + + with pysam.VariantFile(fn + ".gz") as inf: + self.assertEqual(len(list(inf.fetch("20"))), 3) + + def test_vcf_with_csi_index(self): + with get_temp_context("tmp_fn.vcf") as fn: + shutil.copyfile(self.vcf_filename, fn) + + pysam.tabix_index(fn, preset="vcf", force=True, csi=True) + self.assertTrue(os.path.exists(fn + ".gz" + ".csi")) + self.assertFalse(os.path.exists(fn + ".gz" + ".tbi")) + + with pysam.VariantFile(fn + ".gz") as inf: + self.assertEqual(len(list(inf.fetch("20"))), 3) + + def test_bcf_with_prebuilt_csi(self): + with get_temp_context("tmp_fn.bcf") as fn: + shutil.copyfile(self.bcf_filename, fn) + shutil.copyfile(self.bcf_filename + ".csi", fn + ".csi") + + self.assertTrue(os.path.exists(fn + ".csi")) + self.assertFalse(os.path.exists(fn + ".tbi")) + + with pysam.VariantFile(fn) as inf: + self.assertEqual(len(list(inf.fetch("20"))), 3) + + def test_bcf_with_tbi_index_will_produce_csi(self): + with get_temp_context("tmp_fn.bcf") as fn: + shutil.copyfile(self.bcf_filename, fn) + + pysam.tabix_index(fn, preset="bcf", force=True, csi=False) + self.assertTrue(os.path.exists(fn + ".csi")) + self.assertFalse(os.path.exists(fn + ".tbi")) + + with pysam.VariantFile(fn) as inf: + self.assertEqual(len(list(inf.fetch("20"))), 3) + + def test_bcf_with_csi_index(self): + with get_temp_context("tmp_fn.bcf") as fn: + shutil.copyfile(self.bcf_filename, fn) + + pysam.tabix_index(fn, preset="vcf", force=True, csi=True) + + self.assertTrue(os.path.exists(fn + ".csi")) + self.assertFalse(os.path.exists(fn + ".tbi")) + + with pysam.VariantFile(fn) as inf: + self.assertEqual(len(list(inf.fetch("20"))), 3) + + class TestHeader(unittest.TestCase): filename = "example_vcf40.vcf" def testStr(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) ref = read_header(fn) @@ -182,7 +264,7 @@ def testStr(self): def testIterator(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) ref = read_header(fn) @@ -208,85 +290,91 @@ class TestParsing(unittest.TestCase): filename = "example_vcf40.vcf.gz" def testChrom(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) chrom = [rec.chrom for rec in v] self.assertEqual(chrom, ['M', '17', '20', '20', '20']) - if Path and sys.version_info >= (3,6): + if Path and sys.version_info >= (3, 6): def testChromFromPath(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(Path(fn)) chrom = [rec.chrom for rec in v] self.assertEqual(chrom, ['M', '17', '20', '20', '20']) def testPos(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) pos = [rec.pos for rec in v] self.assertEqual(pos, [1230237, 14370, 17330, 1110696, 1234567]) def testStart(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) start = [rec.start for rec in v] self.assertEqual(start, [1230236, 14369, 17329, 1110695, 1234566]) def testStop(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) stop = [rec.stop for rec in v] self.assertEqual(stop, [1230237, 14370, 17330, 1110696, 1234570]) def testId(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) ids = [rec.id for rec in v] - self.assertEqual(ids, [None, 'rs6054257', None, 'rs6040355', 'microsat1']) + self.assertEqual( + ids, [None, 'rs6054257', None, 'rs6040355', 'microsat1']) def testRef(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) ref = [rec.ref for rec in v] self.assertEqual(ref, ['T', 'G', 'T', 'A', 'GTCT']) def testAlt(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) alts = [rec.alts for rec in v] - self.assertEqual(alts, [None, ('A',), ('A',), ('G', 'T'), ('G', 'GTACT')]) + self.assertEqual(alts, [None, ('A',), ('A',), + ('G', 'T'), ('G', 'GTACT')]) def testAlleles(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) alleles = [rec.alleles for rec in v] - self.assertEqual(alleles, [('T',), ('G', 'A'), ('T', 'A'), ('A', 'G', 'T'), ('GTCT', 'G', 'GTACT')]) + self.assertEqual(alleles, [ + ('T',), ('G', 'A'), ('T', 'A'), ('A', 'G', 'T'), ('GTCT', 'G', 'GTACT')]) def testQual(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) qual = [rec.qual for rec in v] self.assertEqual(qual, [47.0, 29.0, 3.0, 67.0, 50.0]) def testFilter(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) filter = [rec.filter.keys() for rec in v] - self.assertEqual(filter, [['PASS'], ['PASS'], ['q10'], ['PASS'], ['PASS']]) + self.assertEqual(filter, [['PASS'], ['PASS'], + ['q10'], ['PASS'], ['PASS']]) def testInfo(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) info = [rec.info.items() for rec in v] self.assertEqual(info, [[('NS', 3), ('DP', 13), ('AA', 'T')], - [('NS', 3), ('DP', 14), ('AF', (0.5,)), ('DB', True), ('H2', True)], - [('NS', 3), ('DP', 11), ('AF', (0.017000000923871994,))], + [('NS', 3), ('DP', 14), ('AF', (0.5,)), + ('DB', True), ('H2', True)], + [('NS', 3), ('DP', 11), + ('AF', (0.017000000923871994,))], [('NS', 2), ('DP', 10), ('AF', (0.3330000042915344, 0.6669999957084656)), - ('AA', 'T'), ('DB', True)], + ('AA', 'T'), ('DB', True)], [('NS', 3), ('DP', 9), ('AA', 'G')]]) def testFormat(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) format = [rec.format.keys() for rec in v] self.assertEqual(format, [['GT', 'GQ', 'DP', 'HQ'], @@ -296,7 +384,7 @@ def testFormat(self): ['GT', 'GQ', 'DP']]) def testSampleAlleles(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) alleles = [s.alleles for rec in v for s in rec.samples.values()] self.assertEqual(alleles, [('T', 'T'), ('T', 'T'), ('T', 'T'), @@ -307,27 +395,38 @@ def testSampleAlleles(self): ('G', 'G')]) def testSampleFormats(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) format = [s.items() for rec in v for s in rec.samples.values()] self.assertEqual(format, [[('GT', (0, 0)), ('GQ', 54), ('DP', 7), ('HQ', (56, 60))], - [('GT', (0, 0)), ('GQ', 48), ('DP', 4), ('HQ', (51, 51))], - [('GT', (0, 0)), ('GQ', 61), ('DP', 2), ('HQ', (None,))], - [('GT', (0, 0)), ('GQ', 48), ('DP', 1), ('HQ', (51, 51))], - [('GT', (1, 0)), ('GQ', 48), ('DP', 8), ('HQ', (51, 51))], - [('GT', (1, 1)), ('GQ', 43), ('DP', 5), ('HQ', (None, None))], - [('GT', (0, 0)), ('GQ', 49), ('DP', 3), ('HQ', (58, 50))], - [('GT', (0, 1)), ('GQ', 3), ('DP', 5), ('HQ', (65, 3))], - [('GT', (0, 0)), ('GQ', 41), ('DP', 3), ('HQ', (None,))], - [('GT', (1, 2)), ('GQ', 21), ('DP', 6), ('HQ', (23, 27))], - [('GT', (2, 1)), ('GQ', 2), ('DP', 0), ('HQ', (18, 2))], - [('GT', (2, 2)), ('GQ', 35), ('DP', 4), ('HQ', (None,))], + [('GT', (0, 0)), ('GQ', 48), + ('DP', 4), ('HQ', (51, 51))], + [('GT', (0, 0)), ('GQ', 61), + ('DP', 2), ('HQ', (None,))], + [('GT', (0, 0)), ('GQ', 48), + ('DP', 1), ('HQ', (51, 51))], + [('GT', (1, 0)), ('GQ', 48), + ('DP', 8), ('HQ', (51, 51))], + [('GT', (1, 1)), ('GQ', 43), + ('DP', 5), ('HQ', (None, None))], + [('GT', (0, 0)), ('GQ', 49), + ('DP', 3), ('HQ', (58, 50))], + [('GT', (0, 1)), ('GQ', 3), + ('DP', 5), ('HQ', (65, 3))], + [('GT', (0, 0)), ('GQ', 41), + ('DP', 3), ('HQ', (None,))], + [('GT', (1, 2)), ('GQ', 21), + ('DP', 6), ('HQ', (23, 27))], + [('GT', (2, 1)), ('GQ', 2), + ('DP', 0), ('HQ', (18, 2))], + [('GT', (2, 2)), ('GQ', 35), + ('DP', 4), ('HQ', (None,))], [('GT', (0, 1)), ('GQ', 35), ('DP', 4)], [('GT', (0, 2)), ('GQ', 17), ('DP', 2)], [('GT', (1, 1)), ('GQ', 40), ('DP', 3)]]) def testSampleAlleleIndices(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(CBCF_DATADIR, self.filename) v = pysam.VariantFile(fn) indices = [s.allele_indices for rec in v for s in rec.samples.values()] self.assertEqual(indices, [(0, 0), (0, 0), (0, 0), (0, 0), (1, 0), @@ -339,16 +438,15 @@ class TestIndexFilename(unittest.TestCase): filenames = [('example_vcf40.vcf.gz', 'example_vcf40.vcf.gz.tbi'), ('example_vcf40.vcf.gz', 'example_vcf40.vcf.gz.csi'), - ('example_vcf40.bcf', 'example_vcf40.bcf.csi')] + ('example_vcf40.bcf', 'example_vcf40.bcf.csi')] def testOpen(self): for fn, idx_fn in self.filenames: - fn = os.path.join(DATADIR, fn) - idx_fn = os.path.join(DATADIR, idx_fn) - - v = pysam.VariantFile(fn, index_filename=idx_fn) + fn = os.path.join(CBCF_DATADIR, fn) + idx_fn = os.path.join(CBCF_DATADIR, idx_fn) - self.assertEqual(len(list(v.fetch('20'))), 3) + with pysam.VariantFile(fn, index_filename=idx_fn) as inf: + self.assertEqual(len(list(inf.fetch('20'))), 3) class TestConstructionVCFWithContigs(unittest.TestCase): @@ -359,7 +457,7 @@ class TestConstructionVCFWithContigs(unittest.TestCase): description = 'VCF version 4.2 variant calling text' def testBase(self): - with pysam.VariantFile(os.path.join(DATADIR, self.filename)) as inf: + with pysam.VariantFile(os.path.join(CBCF_DATADIR, self.filename)) as inf: self.assertEqual(inf.category, 'VARIANTS') self.assertEqual(inf.format, 'VCF') self.assertEqual(inf.version, (4, 2)) @@ -378,7 +476,7 @@ def complete_check(self, fn_in, fn_out): def testConstructionWithRecords(self): - fn_in = os.path.join(DATADIR, self.filename) + fn_in = os.path.join(CBCF_DATADIR, self.filename) fn_out = get_temp_filename(suffix=".vcf") vcf_in = pysam.VariantFile(fn_in) @@ -401,7 +499,7 @@ def testConstructionWithRecords(self): def testConstructionFromCopy(self): - fn_in = os.path.join(DATADIR, self.filename) + fn_in = os.path.join(CBCF_DATADIR, self.filename) fn_out = get_temp_filename(suffix=".vcf") vcf_in = pysam.VariantFile(fn_in) @@ -416,7 +514,7 @@ def testConstructionFromCopy(self): def testConstructionWithLines(self): - fn_in = os.path.join(DATADIR, self.filename) + fn_in = os.path.join(CBCF_DATADIR, self.filename) fn_out = get_temp_filename(suffix=".vcf") vcf_in = pysam.VariantFile(fn_in) @@ -438,7 +536,7 @@ def testConstructionWithLines(self): self.complete_check(fn_in, fn_out) -#class TestConstructionVCFWithoutContigs(TestConstructionVCFWithContigs): +# class TestConstructionVCFWithoutContigs(TestConstructionVCFWithContigs): # """construct VariantFile from scratch.""" # filename = "example_vcf40.vcf" @@ -464,18 +562,19 @@ class TestSettingRecordValues(unittest.TestCase): filename = "example_vcf40.vcf" def testBase(self): - with pysam.VariantFile(os.path.join(DATADIR, self.filename)) as inf: + with pysam.VariantFile(os.path.join(CBCF_DATADIR, self.filename)) as inf: self.assertEqual(inf.category, 'VARIANTS') self.assertEqual(inf.format, 'VCF') self.assertEqual(inf.version, (4, 0)) self.assertEqual(inf.compression, 'NONE') - self.assertEqual(inf.description, 'VCF version 4.0 variant calling text') + self.assertEqual( + inf.description, 'VCF version 4.0 variant calling text') self.assertTrue(inf.is_open) self.assertEqual(inf.is_read, True) self.assertEqual(inf.is_write, False) def testSetQual(self): - with pysam.VariantFile(os.path.join(DATADIR, self.filename)) as inf: + with pysam.VariantFile(os.path.join(CBCF_DATADIR, self.filename)) as inf: record = next(inf) self.assertEqual(record.qual, 47) record.qual = record.qual @@ -485,27 +584,59 @@ def testSetQual(self): self.assertEqual(str(record).split("\t")[5], "10") def testGenotype(self): - with pysam.VariantFile(os.path.join(DATADIR, self.filename)) as inf: + with pysam.VariantFile(os.path.join(CBCF_DATADIR, self.filename)) as inf: record = next(inf) sample = record.samples["NA00001"] - print (sample["GT"]) + print(sample["GT"]) self.assertEqual(sample["GT"], (0, 0)) sample["GT"] = sample["GT"] + +class TestMultiThreading(unittest.TestCase): + + filename = os.path.join(CBCF_DATADIR, "example_vcf42.vcf.gz") + + def testSingleThreadEqualsMultithreadResult(self): + with pysam.VariantFile(self.filename) as inf: + header = inf.header + single = [r for r in inf] + with pysam.VariantFile(self.filename, threads=2) as inf: + multi = [r for r in inf] + for r1, r2 in zip(single, multi): + assert str(r1) == str(r2) + + bcf_out = get_temp_filename(suffix=".bcf") + with pysam.VariantFile(bcf_out, mode='wb', + header=header, + threads=2) as out: + for r in single: + out.write(r) + with pysam.VariantFile(bcf_out) as inf: + multi_out = [r for r in inf] + for r1, r2 in zip(single, multi_out): + assert str(r1) == str(r2) + + def testNoMultiThreadingWithIgnoreTruncation(self): + with self.assertRaises(ValueError): + pysam.VariantFile(self.filename, + threads=2, + ignore_truncation=True) + + class TestSubsetting(unittest.TestCase): - + filename = "example_vcf42.vcf.gz" - + def testSubsetting(self): - with pysam.VariantFile(os.path.join(DATADIR, + with pysam.VariantFile(os.path.join(CBCF_DATADIR, self.filename)) as inf: inf.subset_samples(["NA00001"]) if __name__ == "__main__": # build data files - print ("building data files") - subprocess.call("make -C %s" % DATADIR, shell=True) - print ("starting tests") + print("building data files") + subprocess.call("make -C %s" % CBCF_DATADIR, shell=True) + print("starting tests") unittest.main() - print ("completed tests") + print("completed tests") diff --git a/tests/cbcf_data/gnomad.vcf b/tests/cbcf_data/gnomad.vcf new file mode 100644 index 000000000..9875c03d6 --- /dev/null +++ b/tests/cbcf_data/gnomad.vcf @@ -0,0 +1,200 @@ +##fileformat=VCFv4.2 +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FILTER= +##FILTER== 20, DP >= 10, AB => 0.2 for het calls))"> +##FILTER= +##FILTER= +##FILTER= +##FILTER= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##reference=file:///seq/references/Homo_sapiens_assembly19/v1/Homo_sapiens_assembly19.fasta +#CHROM POS ID REF ALT QUAL FILTER INFO +22 16050036 rs374742143 A C 442156.34 RF AC=67;AF=4.29487e-01;AN=156;BaseQRankSum=7.36000e-01;ClippingRankSum=2.96000e-01;DB;DP=50165;FS=7.05600e+00;InbreedingCoeff=3.82000e-01;MQ=2.71500e+01;MQRankSum=-1.02600e+00;QD=2.47500e+01;ReadPosRankSum=-2.11000e-01;SOR=1.26750e+01;VQSLOD=-9.58600e+02;VQSR_culprit=MQ;GQ_HIST_ALT=16|1279|299|254|155|24|16|28|50|135|78|4|6|11|32|43|6|4|3|35;DP_HIST_ALT=1769|653|51|5|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|2|5|24|36|11|89|2|125|31|61|85|24|60|34|8|3|7;GQ_HIST_ALL=2359|2810|730|651|296|51|34|33|53|135|78|4|6|11|32|43|6|4|3|35;DP_HIST_ALL=5518|1756|94|6|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|2|5|24|36|11|89|2|125|31|61|85|24|60|34|8|3|7;AC_AFR=3;AC_AMR=7;AC_ASJ=0;AC_EAS=0;AC_FIN=50;AC_NFE=3;AC_OTH=4;AC_Male=32;AC_Female=35;AN_AFR=14;AN_AMR=10;AN_ASJ=0;AN_EAS=0;AN_FIN=84;AN_NFE=42;AN_OTH=6;AN_Male=80;AN_Female=76;AF_AFR=2.14286e-01;AF_AMR=7.00000e-01;AF_ASJ=.;AF_EAS=.;AF_FIN=5.95238e-01;AF_NFE=7.14286e-02;AF_OTH=6.66667e-01;AF_Male=4.00000e-01;AF_Female=4.60526e-01;GC_AFR=4,3,0;GC_AMR=0,3,2;GC_ASJ=0,0,0;GC_EAS=0,0,0;GC_FIN=4,26,12;GC_NFE=18,3,0;GC_OTH=1,0,2;GC_Male=16,16,8;GC_Female=11,19,8;AC_raw=4349;AN_raw=14748;AF_raw=2.94887e-01;GC_raw=4896,607,1871;GC=27,35,16;Hom_AFR=0;Hom_AMR=2;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=12;Hom_NFE=0;Hom_OTH=2;Hom_Male=8;Hom_Female=8;Hom_raw=1871;Hom=16;POPMAX=AMR;AC_POPMAX=7;AN_POPMAX=10;AF_POPMAX=7.00000e-01;DP_MEDIAN=3;DREF_MEDIAN=5.60406e-10;GQ_MEDIAN=12;AB_MEDIAN=5.55556e-01;AS_RF=4.71609e-02;AS_FilterStatus=RF;CSQ=C|intergenic_variant|MODIFIER|||||||||||||||rs374742143|1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050068 . A G 82.46 RF;AC0 AC=0;AF=0.00000e+00;AN=2708;DP=111486;FS=0.00000e+00;InbreedingCoeff=-3.63000e-02;MQ=3.20200e+01;QD=1.64900e+01;SOR=3.61100e+00;VQSLOD=-9.28900e+01;VQSR_culprit=MQ;GQ_HIST_ALT=0|0|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;DP_HIST_ALT=0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;GQ_HIST_ALL=1227|4189|2184|3537|2071|618|693|346|97|92|61|9|18|0|7|4|4|0|0|0;DP_HIST_ALL=7502|6289|1163|169|26|8|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AC_AFR=0;AC_AMR=0;AC_ASJ=0;AC_EAS=0;AC_FIN=0;AC_NFE=0;AC_OTH=0;AC_Male=0;AC_Female=0;AN_AFR=280;AN_AMR=162;AN_ASJ=34;AN_EAS=74;AN_FIN=748;AN_NFE=1300;AN_OTH=110;AN_Male=1584;AN_Female=1124;AF_AFR=0.00000e+00;AF_AMR=0.00000e+00;AF_ASJ=0.00000e+00;AF_EAS=0.00000e+00;AF_FIN=0.00000e+00;AF_NFE=0.00000e+00;AF_OTH=0.00000e+00;AF_Male=0.00000e+00;AF_Female=0.00000e+00;GC_AFR=140,0,0;GC_AMR=81,0,0;GC_ASJ=17,0,0;GC_EAS=37,0,0;GC_FIN=374,0,0;GC_NFE=650,0,0;GC_OTH=55,0,0;GC_Male=792,0,0;GC_Female=562,0,0;AC_raw=2;AN_raw=30314;AF_raw=6.59761e-05;GC_raw=15156,0,1;GC=1354,0,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=1;Hom=0;POPMAX=.;AC_POPMAX=.;AN_POPMAX=.;AF_POPMAX=.;DP_MEDIAN=5;DREF_MEDIAN=1.22034e-16;GQ_MEDIAN=15;AB_MEDIAN=5.00000e-01;AS_RF=5.87186e-02;AS_FilterStatus=RF|AC0;CSQ=G|intergenic_variant|MODIFIER||||||||||||||||1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050069 . C T 43.44 RF;AC0 AC=0;AF=0.00000e+00;AN=2802;BaseQRankSum=7.20000e-01;ClippingRankSum=-1.38000e+00;DP=112972;FS=0.00000e+00;InbreedingCoeff=-3.70000e-02;MQ=3.67700e+01;MQRankSum=7.20000e-01;QD=7.24000e+00;ReadPosRankSum=1.38000e+00;SOR=1.32900e+00;VQSLOD=-3.27400e+01;VQSR_culprit=MQ;GQ_HIST_ALT=0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0|0|0|0;DP_HIST_ALT=0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0;GQ_HIST_ALL=1200|4098|2219|3540|2117|622|710|352|104|101|64|10|20|1|8|3|4|0|0|0;DP_HIST_ALL=7405|6348|1203|181|28|8|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0;AC_AFR=0;AC_AMR=0;AC_ASJ=0;AC_EAS=0;AC_FIN=0;AC_NFE=0;AC_OTH=0;AC_Male=0;AC_Female=0;AN_AFR=296;AN_AMR=164;AN_ASJ=36;AN_EAS=70;AN_FIN=766;AN_NFE=1354;AN_OTH=116;AN_Male=1638;AN_Female=1164;AF_AFR=0.00000e+00;AF_AMR=0.00000e+00;AF_ASJ=0.00000e+00;AF_EAS=0.00000e+00;AF_FIN=0.00000e+00;AF_NFE=0.00000e+00;AF_OTH=0.00000e+00;AF_Male=0.00000e+00;AF_Female=0.00000e+00;GC_AFR=148,0,0;GC_AMR=82,0,0;GC_ASJ=18,0,0;GC_EAS=35,0,0;GC_FIN=383,0,0;GC_NFE=677,0,0;GC_OTH=58,0,0;GC_Male=819,0,0;GC_Female=582,0,0;AC_raw=1;AN_raw=30346;AF_raw=3.29533e-05;GC_raw=15172,1,0;GC=1401,0,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=0;Hom=0;POPMAX=.;AC_POPMAX=.;AN_POPMAX=.;AF_POPMAX=.;DP_MEDIAN=6;DREF_MEDIAN=3.16178e-11;GQ_MEDIAN=38;AB_MEDIAN=6.66667e-01;AS_RF=9.22976e-02;AS_FilterStatus=RF|AC0;CSQ=T|intergenic_variant|MODIFIER||||||||||||||||1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050098 . G A 242.82 RF AC=2;AF=2.40964e-04;AN=8300;BaseQRankSum=2.45000e+00;ClippingRankSum=1.03000e-01;DP=167171;FS=0.00000e+00;InbreedingCoeff=-1.46000e-02;MQ=3.06100e+01;MQRankSum=-9.35000e-01;QD=1.05600e+01;ReadPosRankSum=6.60000e-01;SOR=3.84000e-01;VQSLOD=-4.11500e+01;VQSR_culprit=MQ;GQ_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|2;DP_HIST_ALT=0|0|2|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|0|0|0|0|0|0|1|1|0|0|0|0|0|0|0|0|0;GQ_HIST_ALL=350|1697|1483|3462|3106|1262|1746|994|348|436|237|88|141|14|39|5|22|4|8|7;DP_HIST_ALL=3368|7876|3165|776|212|33|16|3|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|0|0|0|0|0|0|1|1|0|0|0|0|0|0|0|0|0;AC_AFR=0;AC_AMR=0;AC_ASJ=0;AC_EAS=0;AC_FIN=0;AC_NFE=2;AC_OTH=0;AC_Male=2;AC_Female=0;AN_AFR=1298;AN_AMR=334;AN_ASJ=84;AN_EAS=380;AN_FIN=1460;AN_NFE=4412;AN_OTH=332;AN_Male=4748;AN_Female=3552;AF_AFR=0.00000e+00;AF_AMR=0.00000e+00;AF_ASJ=0.00000e+00;AF_EAS=0.00000e+00;AF_FIN=0.00000e+00;AF_NFE=4.53309e-04;AF_OTH=0.00000e+00;AF_Male=4.21230e-04;AF_Female=0.00000e+00;GC_AFR=649,0,0;GC_AMR=167,0,0;GC_ASJ=42,0,0;GC_EAS=190,0,0;GC_FIN=730,0,0;GC_NFE=2204,2,0;GC_OTH=166,0,0;GC_Male=2372,2,0;GC_Female=1776,0,0;AC_raw=2;AN_raw=30898;AF_raw=6.47291e-05;GC_raw=15447,2,0;GC=4148,2,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=0;Hom=0;POPMAX=NFE;AC_POPMAX=2;AN_POPMAX=4412;AF_POPMAX=4.53309e-04;DP_MEDIAN=11;DREF_MEDIAN=6.29479e-16;GQ_MEDIAN=99;AB_MEDIAN=4.80769e-01;AS_RF=3.30908e-01;AS_FilterStatus=RF;CSQ=A|intergenic_variant|MODIFIER||||||||||||||||1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050115 rs587755077 G A 10684.53 RF AC=31;AF=2.54057e-03;AN=12202;BaseQRankSum=1.59000e+00;ClippingRankSum=6.70000e-02;DP=196906;FS=0.00000e+00;InbreedingCoeff=1.40000e-02;MQ=3.37700e+01;MQRankSum=4.06000e-01;QD=8.23000e+00;ReadPosRankSum=3.22000e-01;SOR=4.23100e+00;VQSLOD=-1.16300e+02;VQSR_culprit=MQ;GQ_HIST_ALT=3|6|10|5|3|3|6|13|17|16|2|3|9|12|8|11|5|3|3|14;DP_HIST_ALT=22|95|32|3|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|4|6|16|20|8|21|1|28|5|7|7|7|7|8|0|0|0;GQ_HIST_ALL=237|959|984|2740|3098|1328|2215|1483|527|685|442|163|289|52|79|25|61|6|27|39;DP_HIST_ALL=1972|7287|4327|1314|407|79|44|9|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|4|6|16|20|8|21|1|28|5|7|7|7|7|8|0|0|0;AC_AFR=30;AC_AMR=1;AC_ASJ=0;AC_EAS=0;AC_FIN=0;AC_NFE=0;AC_OTH=0;AC_Male=16;AC_Female=15;AN_AFR=2236;AN_AMR=436;AN_ASJ=144;AN_EAS=640;AN_FIN=1862;AN_NFE=6410;AN_OTH=474;AN_Male=6874;AN_Female=5328;AF_AFR=1.34168e-02;AF_AMR=2.29358e-03;AF_ASJ=0.00000e+00;AF_EAS=0.00000e+00;AF_FIN=0.00000e+00;AF_NFE=0.00000e+00;AF_OTH=0.00000e+00;AF_Male=2.32761e-03;AF_Female=2.81532e-03;GC_AFR=1088,30,0;GC_AMR=217,1,0;GC_ASJ=72,0,0;GC_EAS=320,0,0;GC_FIN=931,0,0;GC_NFE=3205,0,0;GC_OTH=237,0,0;GC_Male=3421,16,0;GC_Female=2649,15,0;AC_raw=159;AN_raw=30878;AF_raw=5.14930e-03;GC_raw=15287,145,7;GC=6070,31,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=7;Hom=0;POPMAX=AFR;AC_POPMAX=30;AN_POPMAX=2236;AF_POPMAX=1.34168e-02;DP_MEDIAN=7;DREF_MEDIAN=1.74246e-08;GQ_MEDIAN=48;AB_MEDIAN=4.44444e-01;AS_RF=5.02621e-02;AS_FilterStatus=RF;CSQ=A|intergenic_variant|MODIFIER|||||||||||||||rs587755077|1||||SNV|1||||||||||||||||A:0.0064|||||||||||||||||||||||||||| +22 16050116 . G C 28395.88 RF AC=246;AF=2.51431e-02;AN=9784;BaseQRankSum=2.48000e-01;ClippingRankSum=0.00000e+00;DP=201089;FS=0.00000e+00;InbreedingCoeff=-7.09000e-02;MQ=3.23400e+01;MQRankSum=-1.23100e+00;QD=3.27000e+00;ReadPosRankSum=2.48000e-01;SOR=7.16400e+00;VQSLOD=-3.11400e+02;VQSR_culprit=MQ;GQ_HIST_ALT=0|3|6|9|32|41|110|119|73|75|49|48|27|32|38|16|4|9|19|27;DP_HIST_ALT=21|356|285|60|12|3|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|11|105|184|174|98|40|64|2|30|5|11|8|2|2|0|0|0|0;GQ_HIST_ALL=2616|992|935|2244|2407|1109|1723|1219|458|593|382|175|259|62|105|27|46|11|38|55;DP_HIST_ALL=1838|7215|4403|1404|443|92|50|11|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|11|105|184|174|98|40|64|2|30|5|11|8|2|2|0|0|0|0;AC_AFR=18;AC_AMR=5;AC_ASJ=4;AC_EAS=3;AC_FIN=5;AC_NFE=202;AC_OTH=9;AC_Male=141;AC_Female=105;AN_AFR=2166;AN_AMR=402;AN_ASJ=88;AN_EAS=650;AN_FIN=1722;AN_NFE=4390;AN_OTH=366;AN_Male=5450;AN_Female=4334;AF_AFR=8.31025e-03;AF_AMR=1.24378e-02;AF_ASJ=4.54545e-02;AF_EAS=4.61538e-03;AF_FIN=2.90360e-03;AF_NFE=4.60137e-02;AF_OTH=2.45902e-02;AF_Male=2.58716e-02;AF_Female=2.42270e-02;GC_AFR=1065,18,0;GC_AMR=196,5,0;GC_ASJ=40,4,0;GC_EAS=322,3,0;GC_FIN=856,5,0;GC_NFE=1993,202,0;GC_OTH=174,9,0;GC_Male=2584,141,0;GC_Female=2062,105,0;AC_raw=738;AN_raw=30912;AF_raw=2.38742e-02;GC_raw=14719,736,1;GC=4646,246,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=1;Hom=0;POPMAX=NFE;AC_POPMAX=202;AN_POPMAX=4390;AF_POPMAX=4.60137e-02;DP_MEDIAN=9;DREF_MEDIAN=6.30918e-05;GQ_MEDIAN=42;AB_MEDIAN=2.50000e-01;AS_RF=8.65786e-03;AS_FilterStatus=RF;CSQ=C|intergenic_variant|MODIFIER||||||||||||||||1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050129 . G GACA,C 1164.92 PASS AC=3,0;AF=1.81378e-04,0.00000e+00;AN=16540;BaseQRankSum=-2.24000e-01;ClippingRankSum=-2.63000e-01;DP=230703;FS=8.86700e+00;InbreedingCoeff=5.80000e-03;MQ=3.46800e+01;MQRankSum=1.43000e-01;QD=1.01300e+01;ReadPosRankSum=-2.13000e-01;SOR=3.30000e-02;VQSLOD=-1.37800e+00;VQSR_culprit=SOR;VQSR_NEGATIVE_TRAIN_SITE;GQ_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|1|0|0|4,0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0;DP_HIST_ALT=0|3|2|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0,0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|0|0|0|2|0|1|1|1|0|0|0|0|1|0|0|0|0,0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0;GQ_HIST_ALL=104|464|608|1985|2741|1441|2526|1859|721|1069|690|260|538|62|159|47|92|8|46|68;DP_HIST_ALL=1018|6123|5177|2097|791|161|97|24|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|0|0|0|2|0|1|1|1|0|1|0|0|1|0|0|0|0;AC_AFR=0,0;AC_AMR=0,0;AC_ASJ=0,0;AC_EAS=0,0;AC_FIN=0,0;AC_NFE=3,0;AC_OTH=0,0;AC_Male=3,0;AC_Female=0,0;AN_AFR=3614;AN_AMR=528;AN_ASJ=180;AN_EAS=892;AN_FIN=2256;AN_NFE=8466;AN_OTH=604;AN_Male=9308;AN_Female=7232;AF_AFR=0.00000e+00,0.00000e+00;AF_AMR=0.00000e+00,0.00000e+00;AF_ASJ=0.00000e+00,0.00000e+00;AF_EAS=0.00000e+00,0.00000e+00;AF_FIN=0.00000e+00,0.00000e+00;AF_NFE=3.54359e-04,0.00000e+00;AF_OTH=0.00000e+00,0.00000e+00;AF_Male=3.22303e-04,0.00000e+00;AF_Female=0.00000e+00,0.00000e+00;GC_AFR=1807,0,0,0,0,0;GC_AMR=264,0,0,0,0,0;GC_ASJ=90,0,0,0,0,0;GC_EAS=446,0,0,0,0,0;GC_FIN=1128,0,0,0,0,0;GC_NFE=4230,3,0,0,0,0;GC_OTH=302,0,0,0,0,0;GC_Male=4651,3,0,0,0,0;GC_Female=3616,0,0,0,0,0;AC_raw=6,1;AN_raw=30976;AF_raw=1.93698e-04,3.22831e-05;GC_raw=15481,6,0,1,0,0;GC=8267,3,0,0,0,0;Hom_AFR=0,0;Hom_AMR=0,0;Hom_ASJ=0,0;Hom_EAS=0,0;Hom_FIN=0,0;Hom_NFE=0,0;Hom_OTH=0,0;Hom_Male=0,0;Hom_Female=0,0;Hom_raw=0,0;Hom=0,0;POPMAX=NFE,.;AC_POPMAX=3,.;AN_POPMAX=8466,.;AF_POPMAX=3.54359e-04,.;DP_MEDIAN=10,8;DREF_MEDIAN=3.15558e-20,2.51189e-13;GQ_MEDIAN=99,72;AB_MEDIAN=4.41558e-01,6.25000e-01;AS_RF=5.16800e-01,3.29197e-01;AS_FilterStatus=PASS,RF|AC0;CSQ=C|intergenic_variant|MODIFIER||||||||||||||||2||||insertion|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050141 . C A 108.57 PASS AC=1;AF=5.09632e-05;AN=19622;BaseQRankSum=-7.51000e-01;ClippingRankSum=-1.43000e-01;DP=255559;FS=0.00000e+00;InbreedingCoeff=-4.70000e-03;MQ=3.40100e+01;MQRankSum=-3.32000e-01;QD=9.87000e+00;ReadPosRankSum=6.60000e-02;SOR=9.90000e-02;VQSLOD=-3.45100e+01;VQSR_culprit=MQ;GQ_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1;DP_HIST_ALT=0|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0;GQ_HIST_ALL=90|295|443|1443|2398|1347|2546|2110|845|1318|842|356|727|79|237|59|159|7|90|99;DP_HIST_ALL=626|4935|5582|2741|1103|289|169|45|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0;AC_AFR=0;AC_AMR=0;AC_ASJ=0;AC_EAS=0;AC_FIN=0;AC_NFE=1;AC_OTH=0;AC_Male=1;AC_Female=0;AN_AFR=4696;AN_AMR=588;AN_ASJ=206;AN_EAS=1092;AN_FIN=2392;AN_NFE=9986;AN_OTH=662;AN_Male=10956;AN_Female=8666;AF_AFR=0.00000e+00;AF_AMR=0.00000e+00;AF_ASJ=0.00000e+00;AF_EAS=0.00000e+00;AF_FIN=0.00000e+00;AF_NFE=1.00140e-04;AF_OTH=0.00000e+00;AF_Male=9.12742e-05;AF_Female=0.00000e+00;GC_AFR=2348,0,0;GC_AMR=294,0,0;GC_ASJ=103,0,0;GC_EAS=546,0,0;GC_FIN=1196,0,0;GC_NFE=4992,1,0;GC_OTH=331,0,0;GC_Male=5477,1,0;GC_Female=4333,0,0;AC_raw=1;AN_raw=30980;AF_raw=3.22789e-05;GC_raw=15489,1,0;GC=9810,1,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=0;Hom=0;POPMAX=NFE;AC_POPMAX=1;AN_POPMAX=9986;AF_POPMAX=1.00140e-04;DP_MEDIAN=11;DREF_MEDIAN=7.94328e-18;GQ_MEDIAN=99;AB_MEDIAN=5.45455e-01;AS_RF=4.14273e-01;AS_FilterStatus=PASS;CSQ=A|intergenic_variant|MODIFIER||||||||||||||||1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050146 . A T 48.32 RF;AC0 AC=0;AF=0.00000e+00;AN=20636;BaseQRankSum=-3.54000e-01;ClippingRankSum=5.50000e-01;DP=264413;FS=2.76200e+00;InbreedingCoeff=-4.10000e-03;MQ=3.73000e+01;MQRankSum=2.00000e+00;QD=6.90000e+00;ReadPosRankSum=2.00000e+00;SOR=1.53600e+00;VQSLOD=-3.42700e+01;VQSR_culprit=MQ;GQ_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0;DP_HIST_ALT=0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0;GQ_HIST_ALL=84|258|359|1323|2262|1285|2499|2192|869|1402|937|374|819|84|270|69|176|10|92|126;DP_HIST_ALL=524|4533|5628|2926|1267|363|187|58|4|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0;AC_AFR=0;AC_AMR=0;AC_ASJ=0;AC_EAS=0;AC_FIN=0;AC_NFE=0;AC_OTH=0;AC_Male=0;AC_Female=0;AN_AFR=5074;AN_AMR=602;AN_ASJ=216;AN_EAS=1154;AN_FIN=2448;AN_NFE=10458;AN_OTH=684;AN_Male=11480;AN_Female=9156;AF_AFR=0.00000e+00;AF_AMR=0.00000e+00;AF_ASJ=0.00000e+00;AF_EAS=0.00000e+00;AF_FIN=0.00000e+00;AF_NFE=0.00000e+00;AF_OTH=0.00000e+00;AF_Male=0.00000e+00;AF_Female=0.00000e+00;GC_AFR=2537,0,0;GC_AMR=301,0,0;GC_ASJ=108,0,0;GC_EAS=577,0,0;GC_FIN=1224,0,0;GC_NFE=5229,0,0;GC_OTH=342,0,0;GC_Male=5740,0,0;GC_Female=4578,0,0;AC_raw=1;AN_raw=30980;AF_raw=3.22789e-05;GC_raw=15489,1,0;GC=10318,0,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=0;Hom=0;POPMAX=.;AC_POPMAX=.;AN_POPMAX=.;AF_POPMAX=.;DP_MEDIAN=7;DREF_MEDIAN=1.00000e-11;GQ_MEDIAN=78;AB_MEDIAN=5.71429e-01;AS_RF=2.11047e-01;AS_FilterStatus=RF|AC0;CSQ=T|intergenic_variant|MODIFIER||||||||||||||||1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| diff --git a/tests/cbcf_data/gnomad_fixed.vcf b/tests/cbcf_data/gnomad_fixed.vcf new file mode 100644 index 000000000..552a41ac8 --- /dev/null +++ b/tests/cbcf_data/gnomad_fixed.vcf @@ -0,0 +1,200 @@ +##fileformat=VCFv4.2 +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FILTER= +##FILTER== 20, DP >= 10, AB => 0.2 for het calls))"> +##FILTER= +##FILTER= +##FILTER= +##FILTER= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##contig= +##reference=file:///seq/references/Homo_sapiens_assembly19/v1/Homo_sapiens_assembly19.fasta +#CHROM POS ID REF ALT QUAL FILTER INFO +22 16050036 rs374742143 A C 442156.34 RF AC=67;AF=4.29487e-01;AN=156;BaseQRankSum=7.36000e-01;ClippingRankSum=2.96000e-01;DB;DP=50165;FS=7.05600e+00;InbreedingCoeff=3.82000e-01;MQ=2.71500e+01;MQRankSum=-1.02600e+00;QD=2.47500e+01;ReadPosRankSum=-2.11000e-01;SOR=1.26750e+01;VQSLOD=-9.58600e+02;VQSR_culprit=MQ;GQ_HIST_ALT=16|1279|299|254|155|24|16|28|50|135|78|4|6|11|32|43|6|4|3|35;DP_HIST_ALT=1769|653|51|5|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|2|5|24|36|11|89|2|125|31|61|85|24|60|34|8|3|7;GQ_HIST_ALL=2359|2810|730|651|296|51|34|33|53|135|78|4|6|11|32|43|6|4|3|35;DP_HIST_ALL=5518|1756|94|6|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|2|5|24|36|11|89|2|125|31|61|85|24|60|34|8|3|7;AC_AFR=3;AC_AMR=7;AC_ASJ=0;AC_EAS=0;AC_FIN=50;AC_NFE=3;AC_OTH=4;AC_Male=32;AC_Female=35;AN_AFR=14;AN_AMR=10;AN_ASJ=0;AN_EAS=0;AN_FIN=84;AN_NFE=42;AN_OTH=6;AN_Male=80;AN_Female=76;AF_AFR=2.14286e-01;AF_AMR=7.00000e-01;AF_ASJ=.;AF_EAS=.;AF_FIN=5.95238e-01;AF_NFE=7.14286e-02;AF_OTH=6.66667e-01;AF_Male=4.00000e-01;AF_Female=4.60526e-01;GC_AFR=4,3,0;GC_AMR=0,3,2;GC_ASJ=0,0,0;GC_EAS=0,0,0;GC_FIN=4,26,12;GC_NFE=18,3,0;GC_OTH=1,0,2;GC_Male=16,16,8;GC_Female=11,19,8;AC_raw=4349;AN_raw=14748;AF_raw=2.94887e-01;GC_raw=4896,607,1871;GC=27,35,16;Hom_AFR=0;Hom_AMR=2;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=12;Hom_NFE=0;Hom_OTH=2;Hom_Male=8;Hom_Female=8;Hom_raw=1871;Hom=16;POPMAX=AMR;AC_POPMAX=7;AN_POPMAX=10;AF_POPMAX=7.00000e-01;DP_MEDIAN=3;DREF_MEDIAN=5.60406e-10;GQ_MEDIAN=12;AB_MEDIAN=5.55556e-01;AS_RF=4.71609e-02;AS_FilterStatus=RF;CSQ=C|intergenic_variant|MODIFIER|||||||||||||||rs374742143|1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050068 . A G 82.46 RF;AC0 AC=0;AF=0.00000e+00;AN=2708;DP=111486;FS=0.00000e+00;InbreedingCoeff=-3.63000e-02;MQ=3.20200e+01;QD=1.64900e+01;SOR=3.61100e+00;VQSLOD=-9.28900e+01;VQSR_culprit=MQ;GQ_HIST_ALT=0|0|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;DP_HIST_ALT=0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;GQ_HIST_ALL=1227|4189|2184|3537|2071|618|693|346|97|92|61|9|18|0|7|4|4|0|0|0;DP_HIST_ALL=7502|6289|1163|169|26|8|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AC_AFR=0;AC_AMR=0;AC_ASJ=0;AC_EAS=0;AC_FIN=0;AC_NFE=0;AC_OTH=0;AC_Male=0;AC_Female=0;AN_AFR=280;AN_AMR=162;AN_ASJ=34;AN_EAS=74;AN_FIN=748;AN_NFE=1300;AN_OTH=110;AN_Male=1584;AN_Female=1124;AF_AFR=0.00000e+00;AF_AMR=0.00000e+00;AF_ASJ=0.00000e+00;AF_EAS=0.00000e+00;AF_FIN=0.00000e+00;AF_NFE=0.00000e+00;AF_OTH=0.00000e+00;AF_Male=0.00000e+00;AF_Female=0.00000e+00;GC_AFR=140,0,0;GC_AMR=81,0,0;GC_ASJ=17,0,0;GC_EAS=37,0,0;GC_FIN=374,0,0;GC_NFE=650,0,0;GC_OTH=55,0,0;GC_Male=792,0,0;GC_Female=562,0,0;AC_raw=2;AN_raw=30314;AF_raw=6.59761e-05;GC_raw=15156,0,1;GC=1354,0,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=1;Hom=0;POPMAX=.;AC_POPMAX=.;AN_POPMAX=.;AF_POPMAX=.;DP_MEDIAN=5;DREF_MEDIAN=1.22034e-16;GQ_MEDIAN=15;AB_MEDIAN=5.00000e-01;AS_RF=5.87186e-02;AS_FilterStatus=RF|AC0;CSQ=G|intergenic_variant|MODIFIER||||||||||||||||1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050069 . C T 43.44 RF;AC0 AC=0;AF=0.00000e+00;AN=2802;BaseQRankSum=7.20000e-01;ClippingRankSum=-1.38000e+00;DP=112972;FS=0.00000e+00;InbreedingCoeff=-3.70000e-02;MQ=3.67700e+01;MQRankSum=7.20000e-01;QD=7.24000e+00;ReadPosRankSum=1.38000e+00;SOR=1.32900e+00;VQSLOD=-3.27400e+01;VQSR_culprit=MQ;GQ_HIST_ALT=0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0|0|0|0;DP_HIST_ALT=0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0;GQ_HIST_ALL=1200|4098|2219|3540|2117|622|710|352|104|101|64|10|20|1|8|3|4|0|0|0;DP_HIST_ALL=7405|6348|1203|181|28|8|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0;AC_AFR=0;AC_AMR=0;AC_ASJ=0;AC_EAS=0;AC_FIN=0;AC_NFE=0;AC_OTH=0;AC_Male=0;AC_Female=0;AN_AFR=296;AN_AMR=164;AN_ASJ=36;AN_EAS=70;AN_FIN=766;AN_NFE=1354;AN_OTH=116;AN_Male=1638;AN_Female=1164;AF_AFR=0.00000e+00;AF_AMR=0.00000e+00;AF_ASJ=0.00000e+00;AF_EAS=0.00000e+00;AF_FIN=0.00000e+00;AF_NFE=0.00000e+00;AF_OTH=0.00000e+00;AF_Male=0.00000e+00;AF_Female=0.00000e+00;GC_AFR=148,0,0;GC_AMR=82,0,0;GC_ASJ=18,0,0;GC_EAS=35,0,0;GC_FIN=383,0,0;GC_NFE=677,0,0;GC_OTH=58,0,0;GC_Male=819,0,0;GC_Female=582,0,0;AC_raw=1;AN_raw=30346;AF_raw=3.29533e-05;GC_raw=15172,1,0;GC=1401,0,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=0;Hom=0;POPMAX=.;AC_POPMAX=.;AN_POPMAX=.;AF_POPMAX=.;DP_MEDIAN=6;DREF_MEDIAN=3.16178e-11;GQ_MEDIAN=38;AB_MEDIAN=6.66667e-01;AS_RF=9.22976e-02;AS_FilterStatus=RF|AC0;CSQ=T|intergenic_variant|MODIFIER||||||||||||||||1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050098 . G A 242.82 RF AC=2;AF=2.40964e-04;AN=8300;BaseQRankSum=2.45000e+00;ClippingRankSum=1.03000e-01;DP=167171;FS=0.00000e+00;InbreedingCoeff=-1.46000e-02;MQ=3.06100e+01;MQRankSum=-9.35000e-01;QD=1.05600e+01;ReadPosRankSum=6.60000e-01;SOR=3.84000e-01;VQSLOD=-4.11500e+01;VQSR_culprit=MQ;GQ_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|2;DP_HIST_ALT=0|0|2|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|0|0|0|0|0|0|1|1|0|0|0|0|0|0|0|0|0;GQ_HIST_ALL=350|1697|1483|3462|3106|1262|1746|994|348|436|237|88|141|14|39|5|22|4|8|7;DP_HIST_ALL=3368|7876|3165|776|212|33|16|3|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|0|0|0|0|0|0|1|1|0|0|0|0|0|0|0|0|0;AC_AFR=0;AC_AMR=0;AC_ASJ=0;AC_EAS=0;AC_FIN=0;AC_NFE=2;AC_OTH=0;AC_Male=2;AC_Female=0;AN_AFR=1298;AN_AMR=334;AN_ASJ=84;AN_EAS=380;AN_FIN=1460;AN_NFE=4412;AN_OTH=332;AN_Male=4748;AN_Female=3552;AF_AFR=0.00000e+00;AF_AMR=0.00000e+00;AF_ASJ=0.00000e+00;AF_EAS=0.00000e+00;AF_FIN=0.00000e+00;AF_NFE=4.53309e-04;AF_OTH=0.00000e+00;AF_Male=4.21230e-04;AF_Female=0.00000e+00;GC_AFR=649,0,0;GC_AMR=167,0,0;GC_ASJ=42,0,0;GC_EAS=190,0,0;GC_FIN=730,0,0;GC_NFE=2204,2,0;GC_OTH=166,0,0;GC_Male=2372,2,0;GC_Female=1776,0,0;AC_raw=2;AN_raw=30898;AF_raw=6.47291e-05;GC_raw=15447,2,0;GC=4148,2,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=0;Hom=0;POPMAX=NFE;AC_POPMAX=2;AN_POPMAX=4412;AF_POPMAX=4.53309e-04;DP_MEDIAN=11;DREF_MEDIAN=6.29479e-16;GQ_MEDIAN=99;AB_MEDIAN=4.80769e-01;AS_RF=3.30908e-01;AS_FilterStatus=RF;CSQ=A|intergenic_variant|MODIFIER||||||||||||||||1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050115 rs587755077 G A 10684.53 RF AC=31;AF=2.54057e-03;AN=12202;BaseQRankSum=1.59000e+00;ClippingRankSum=6.70000e-02;DP=196906;FS=0.00000e+00;InbreedingCoeff=1.40000e-02;MQ=3.37700e+01;MQRankSum=4.06000e-01;QD=8.23000e+00;ReadPosRankSum=3.22000e-01;SOR=4.23100e+00;VQSLOD=-1.16300e+02;VQSR_culprit=MQ;GQ_HIST_ALT=3|6|10|5|3|3|6|13|17|16|2|3|9|12|8|11|5|3|3|14;DP_HIST_ALT=22|95|32|3|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|4|6|16|20|8|21|1|28|5|7|7|7|7|8|0|0|0;GQ_HIST_ALL=237|959|984|2740|3098|1328|2215|1483|527|685|442|163|289|52|79|25|61|6|27|39;DP_HIST_ALL=1972|7287|4327|1314|407|79|44|9|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|4|6|16|20|8|21|1|28|5|7|7|7|7|8|0|0|0;AC_AFR=30;AC_AMR=1;AC_ASJ=0;AC_EAS=0;AC_FIN=0;AC_NFE=0;AC_OTH=0;AC_Male=16;AC_Female=15;AN_AFR=2236;AN_AMR=436;AN_ASJ=144;AN_EAS=640;AN_FIN=1862;AN_NFE=6410;AN_OTH=474;AN_Male=6874;AN_Female=5328;AF_AFR=1.34168e-02;AF_AMR=2.29358e-03;AF_ASJ=0.00000e+00;AF_EAS=0.00000e+00;AF_FIN=0.00000e+00;AF_NFE=0.00000e+00;AF_OTH=0.00000e+00;AF_Male=2.32761e-03;AF_Female=2.81532e-03;GC_AFR=1088,30,0;GC_AMR=217,1,0;GC_ASJ=72,0,0;GC_EAS=320,0,0;GC_FIN=931,0,0;GC_NFE=3205,0,0;GC_OTH=237,0,0;GC_Male=3421,16,0;GC_Female=2649,15,0;AC_raw=159;AN_raw=30878;AF_raw=5.14930e-03;GC_raw=15287,145,7;GC=6070,31,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=7;Hom=0;POPMAX=AFR;AC_POPMAX=30;AN_POPMAX=2236;AF_POPMAX=1.34168e-02;DP_MEDIAN=7;DREF_MEDIAN=1.74246e-08;GQ_MEDIAN=48;AB_MEDIAN=4.44444e-01;AS_RF=5.02621e-02;AS_FilterStatus=RF;CSQ=A|intergenic_variant|MODIFIER|||||||||||||||rs587755077|1||||SNV|1||||||||||||||||A:0.0064|||||||||||||||||||||||||||| +22 16050116 . G C 28395.88 RF AC=246;AF=2.51431e-02;AN=9784;BaseQRankSum=2.48000e-01;ClippingRankSum=0.00000e+00;DP=201089;FS=0.00000e+00;InbreedingCoeff=-7.09000e-02;MQ=3.23400e+01;MQRankSum=-1.23100e+00;QD=3.27000e+00;ReadPosRankSum=2.48000e-01;SOR=7.16400e+00;VQSLOD=-3.11400e+02;VQSR_culprit=MQ;GQ_HIST_ALT=0|3|6|9|32|41|110|119|73|75|49|48|27|32|38|16|4|9|19|27;DP_HIST_ALT=21|356|285|60|12|3|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|11|105|184|174|98|40|64|2|30|5|11|8|2|2|0|0|0|0;GQ_HIST_ALL=2616|992|935|2244|2407|1109|1723|1219|458|593|382|175|259|62|105|27|46|11|38|55;DP_HIST_ALL=1838|7215|4403|1404|443|92|50|11|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|11|105|184|174|98|40|64|2|30|5|11|8|2|2|0|0|0|0;AC_AFR=18;AC_AMR=5;AC_ASJ=4;AC_EAS=3;AC_FIN=5;AC_NFE=202;AC_OTH=9;AC_Male=141;AC_Female=105;AN_AFR=2166;AN_AMR=402;AN_ASJ=88;AN_EAS=650;AN_FIN=1722;AN_NFE=4390;AN_OTH=366;AN_Male=5450;AN_Female=4334;AF_AFR=8.31025e-03;AF_AMR=1.24378e-02;AF_ASJ=4.54545e-02;AF_EAS=4.61538e-03;AF_FIN=2.90360e-03;AF_NFE=4.60137e-02;AF_OTH=2.45902e-02;AF_Male=2.58716e-02;AF_Female=2.42270e-02;GC_AFR=1065,18,0;GC_AMR=196,5,0;GC_ASJ=40,4,0;GC_EAS=322,3,0;GC_FIN=856,5,0;GC_NFE=1993,202,0;GC_OTH=174,9,0;GC_Male=2584,141,0;GC_Female=2062,105,0;AC_raw=738;AN_raw=30912;AF_raw=2.38742e-02;GC_raw=14719,736,1;GC=4646,246,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=1;Hom=0;POPMAX=NFE;AC_POPMAX=202;AN_POPMAX=4390;AF_POPMAX=4.60137e-02;DP_MEDIAN=9;DREF_MEDIAN=6.30918e-05;GQ_MEDIAN=42;AB_MEDIAN=2.50000e-01;AS_RF=8.65786e-03;AS_FilterStatus=RF;CSQ=C|intergenic_variant|MODIFIER||||||||||||||||1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050129 . G GACA,C 1164.92 PASS AC=3,0;AF=1.81378e-04,0.00000e+00;AN=16540;BaseQRankSum=-2.24000e-01;ClippingRankSum=-2.63000e-01;DP=230703;FS=8.86700e+00;InbreedingCoeff=5.80000e-03;MQ=3.46800e+01;MQRankSum=1.43000e-01;QD=1.01300e+01;ReadPosRankSum=-2.13000e-01;SOR=3.30000e-02;VQSLOD=-1.37800e+00;VQSR_culprit=SOR;VQSR_NEGATIVE_TRAIN_SITE;GQ_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|1|0|0|4,0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0;DP_HIST_ALT=0|3|2|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0,0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|0|0|0|2|0|1|1|1|0|0|0|0|1|0|0|0|0,0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0;GQ_HIST_ALL=104|464|608|1985|2741|1441|2526|1859|721|1069|690|260|538|62|159|47|92|8|46|68;DP_HIST_ALL=1018|6123|5177|2097|791|161|97|24|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|0|0|0|2|0|1|1|1|0|1|0|0|1|0|0|0|0;AC_AFR=0,0;AC_AMR=0,0;AC_ASJ=0,0;AC_EAS=0,0;AC_FIN=0,0;AC_NFE=3,0;AC_OTH=0,0;AC_Male=3,0;AC_Female=0,0;AN_AFR=3614;AN_AMR=528;AN_ASJ=180;AN_EAS=892;AN_FIN=2256;AN_NFE=8466;AN_OTH=604;AN_Male=9308;AN_Female=7232;AF_AFR=0.00000e+00,0.00000e+00;AF_AMR=0.00000e+00,0.00000e+00;AF_ASJ=0.00000e+00,0.00000e+00;AF_EAS=0.00000e+00,0.00000e+00;AF_FIN=0.00000e+00,0.00000e+00;AF_NFE=3.54359e-04,0.00000e+00;AF_OTH=0.00000e+00,0.00000e+00;AF_Male=3.22303e-04,0.00000e+00;AF_Female=0.00000e+00,0.00000e+00;GC_AFR=1807,0,0,0,0,0;GC_AMR=264,0,0,0,0,0;GC_ASJ=90,0,0,0,0,0;GC_EAS=446,0,0,0,0,0;GC_FIN=1128,0,0,0,0,0;GC_NFE=4230,3,0,0,0,0;GC_OTH=302,0,0,0,0,0;GC_Male=4651,3,0,0,0,0;GC_Female=3616,0,0,0,0,0;AC_raw=6,1;AN_raw=30976;AF_raw=1.93698e-04,3.22831e-05;GC_raw=15481,6,0,1,0,0;GC=8267,3,0,0,0,0;Hom_AFR=0,0;Hom_AMR=0,0;Hom_ASJ=0,0;Hom_EAS=0,0;Hom_FIN=0,0;Hom_NFE=0,0;Hom_OTH=0,0;Hom_Male=0,0;Hom_Female=0,0;Hom_raw=0,0;Hom=0,0;POPMAX=NFE,.;AC_POPMAX=3,.;AN_POPMAX=8466,.;AF_POPMAX=3.54359e-04,.;DP_MEDIAN=10,8;DREF_MEDIAN=3.15558e-20,2.51189e-13;GQ_MEDIAN=99,72;AB_MEDIAN=4.41558e-01,6.25000e-01;AS_RF=5.16800e-01,3.29197e-01;AS_FilterStatus=PASS,RF|AC0;CSQ=C|intergenic_variant|MODIFIER||||||||||||||||2||||insertion|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050141 . C A 108.57 PASS AC=1;AF=5.09632e-05;AN=19622;BaseQRankSum=-7.51000e-01;ClippingRankSum=-1.43000e-01;DP=255559;FS=0.00000e+00;InbreedingCoeff=-4.70000e-03;MQ=3.40100e+01;MQRankSum=-3.32000e-01;QD=9.87000e+00;ReadPosRankSum=6.60000e-02;SOR=9.90000e-02;VQSLOD=-3.45100e+01;VQSR_culprit=MQ;GQ_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1;DP_HIST_ALT=0|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0;GQ_HIST_ALL=90|295|443|1443|2398|1347|2546|2110|845|1318|842|356|727|79|237|59|159|7|90|99;DP_HIST_ALL=626|4935|5582|2741|1103|289|169|45|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0;AC_AFR=0;AC_AMR=0;AC_ASJ=0;AC_EAS=0;AC_FIN=0;AC_NFE=1;AC_OTH=0;AC_Male=1;AC_Female=0;AN_AFR=4696;AN_AMR=588;AN_ASJ=206;AN_EAS=1092;AN_FIN=2392;AN_NFE=9986;AN_OTH=662;AN_Male=10956;AN_Female=8666;AF_AFR=0.00000e+00;AF_AMR=0.00000e+00;AF_ASJ=0.00000e+00;AF_EAS=0.00000e+00;AF_FIN=0.00000e+00;AF_NFE=1.00140e-04;AF_OTH=0.00000e+00;AF_Male=9.12742e-05;AF_Female=0.00000e+00;GC_AFR=2348,0,0;GC_AMR=294,0,0;GC_ASJ=103,0,0;GC_EAS=546,0,0;GC_FIN=1196,0,0;GC_NFE=4992,1,0;GC_OTH=331,0,0;GC_Male=5477,1,0;GC_Female=4333,0,0;AC_raw=1;AN_raw=30980;AF_raw=3.22789e-05;GC_raw=15489,1,0;GC=9810,1,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=0;Hom=0;POPMAX=NFE;AC_POPMAX=1;AN_POPMAX=9986;AF_POPMAX=1.00140e-04;DP_MEDIAN=11;DREF_MEDIAN=7.94328e-18;GQ_MEDIAN=99;AB_MEDIAN=5.45455e-01;AS_RF=4.14273e-01;AS_FilterStatus=PASS;CSQ=A|intergenic_variant|MODIFIER||||||||||||||||1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| +22 16050146 . A T 48.32 RF;AC0 AC=0;AF=0.00000e+00;AN=20636;BaseQRankSum=-3.54000e-01;ClippingRankSum=5.50000e-01;DP=264413;FS=2.76200e+00;InbreedingCoeff=-4.10000e-03;MQ=3.73000e+01;MQRankSum=2.00000e+00;QD=6.90000e+00;ReadPosRankSum=2.00000e+00;SOR=1.53600e+00;VQSLOD=-3.42700e+01;VQSR_culprit=MQ;GQ_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0;DP_HIST_ALT=0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALT=0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0;GQ_HIST_ALL=84|258|359|1323|2262|1285|2499|2192|869|1402|937|374|819|84|270|69|176|10|92|126;DP_HIST_ALL=524|4533|5628|2926|1267|363|187|58|4|0|0|0|0|0|0|0|0|0|0|0;AB_HIST_ALL=0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0;AC_AFR=0;AC_AMR=0;AC_ASJ=0;AC_EAS=0;AC_FIN=0;AC_NFE=0;AC_OTH=0;AC_Male=0;AC_Female=0;AN_AFR=5074;AN_AMR=602;AN_ASJ=216;AN_EAS=1154;AN_FIN=2448;AN_NFE=10458;AN_OTH=684;AN_Male=11480;AN_Female=9156;AF_AFR=0.00000e+00;AF_AMR=0.00000e+00;AF_ASJ=0.00000e+00;AF_EAS=0.00000e+00;AF_FIN=0.00000e+00;AF_NFE=0.00000e+00;AF_OTH=0.00000e+00;AF_Male=0.00000e+00;AF_Female=0.00000e+00;GC_AFR=2537,0,0;GC_AMR=301,0,0;GC_ASJ=108,0,0;GC_EAS=577,0,0;GC_FIN=1224,0,0;GC_NFE=5229,0,0;GC_OTH=342,0,0;GC_Male=5740,0,0;GC_Female=4578,0,0;AC_raw=1;AN_raw=30980;AF_raw=3.22789e-05;GC_raw=15489,1,0;GC=10318,0,0;Hom_AFR=0;Hom_AMR=0;Hom_ASJ=0;Hom_EAS=0;Hom_FIN=0;Hom_NFE=0;Hom_OTH=0;Hom_Male=0;Hom_Female=0;Hom_raw=0;Hom=0;POPMAX=.;AC_POPMAX=.;AN_POPMAX=.;AF_POPMAX=.;DP_MEDIAN=7;DREF_MEDIAN=1.00000e-11;GQ_MEDIAN=78;AB_MEDIAN=5.71429e-01;AS_RF=2.11047e-01;AS_FilterStatus=RF|AC0;CSQ=T|intergenic_variant|MODIFIER||||||||||||||||1||||SNV|1|||||||||||||||||||||||||||||||||||||||||||| diff --git a/tests/compile_test.py b/tests/compile_test.py index 5744dbe02..f56adb77f 100644 --- a/tests/compile_test.py +++ b/tests/compile_test.py @@ -1,30 +1,31 @@ ''' -compile_test.py - check pyximport -================================= +compile_test.py - check pyximport functionality with pysam +========================================================== test script for checking if compilation against pysam and tabix works. ''' + # clean up previous compilation import os +import unittest +import pysam +from TestUtils import BAM_DATADIR, TABIX_DATADIR + try: - os.unlink('_compile_test.c') - os.unlink('_compile_test.pyxbldc') + os.unlink('tests/_compile_test.c') + os.unlink('tests/_compile_test.pyxbldc') except OSError: pass - import pyximport pyximport.install(build_in_temp=False) import _compile_test -import unittest -import pysam - class BAMTest(unittest.TestCase): - input_filename = "pysam_data/ex1.bam" + input_filename = os.path.join(BAM_DATADIR, "ex1.bam") def testCount(self): @@ -35,12 +36,13 @@ def testCount(self): class GTFTest(unittest.TestCase): - input_filename = "tabix_data/example.gtf.gz" + input_filename = os.path.join(TABIX_DATADIR, "example.gtf.gz") def testCount(self): nread = _compile_test.testCountGTF( pysam.Tabixfile(self.input_filename)) self.assertEqual(nread, 237) + if __name__ == "__main__": unittest.main() diff --git a/tests/faidx_bench.py b/tests/faidx_bench.py new file mode 100644 index 000000000..c1673360e --- /dev/null +++ b/tests/faidx_bench.py @@ -0,0 +1,71 @@ +"""Benchmarking the cfaidx module. Usage:: + +pytest benchmark/faidx_bench.py +""" +import os +import pysam + + +from TestUtils import BAM_DATADIR + + +def iterate_over_fastx(fn, persist=True): + return len(list(pysam.FastxFile(fn, persist=persist))) + + +def iterate_over_fastx_as_file(fn): + with open(fn) as inf: + return len(inf.read()) + + +def test_fasta_iteration_short_sequences(benchmark): + result = benchmark(iterate_over_fastx, os.path.join( + BAM_DATADIR, "faidx_ex1.fa")) + assert result == 3270 + + +def test_fasta_iteration_long_sequences(benchmark): + result = benchmark(iterate_over_fastx, os.path.join(BAM_DATADIR, "ex1.fa")) + assert result == 2 + + +def test_fasta_iteration_short_sequences_without_persistence(benchmark): + result = benchmark(iterate_over_fastx, os.path.join( + BAM_DATADIR, "faidx_ex1.fa"), persist=False) + assert result == 3270 + + +def test_fasta_iteration_long_sequences_without_persistence(benchmark): + result = benchmark(iterate_over_fastx, os.path.join( + BAM_DATADIR, "ex1.fa"), persist=False) + assert result == 2 + + +def test_fasta_iteration_short_sequences_as_file(benchmark): + result = benchmark(iterate_over_fastx_as_file, + os.path.join(BAM_DATADIR, "faidx_ex1.fa")) + assert result == 195399 + + +def test_fasta_iteration_long_sequences_as_file(benchmark): + result = benchmark(iterate_over_fastx_as_file, + os.path.join(BAM_DATADIR, "ex1.fa")) + assert result == 3225 + + +def test_fastq_iteration_short_sequences(benchmark): + result = benchmark(iterate_over_fastx, os.path.join( + BAM_DATADIR, "faidx_ex1.fq")) + assert result == 3270 + + +def test_fastq_iteration_short_sequences_without_persistence(benchmark): + result = benchmark(iterate_over_fastx, os.path.join( + BAM_DATADIR, "faidx_ex1.fq"), persist=False) + assert result == 3270 + + +def test_fastq_iteration_short_sequences_as_file(benchmark): + result = benchmark(iterate_over_fastx_as_file, + os.path.join(BAM_DATADIR, "faidx_ex1.fq")) + assert result == 320458 diff --git a/tests/faidx_test.py b/tests/faidx_test.py index a12355046..3126e2388 100644 --- a/tests/faidx_test.py +++ b/tests/faidx_test.py @@ -2,24 +2,23 @@ import unittest import os import gzip +import copy import shutil -from TestUtils import checkURL - -DATADIR = "pysam_data" +from TestUtils import check_url, BAM_DATADIR, get_temp_filename class TestFastaFile(unittest.TestCase): sequences = { 'chr1': - "CACTAGTGGCTCATTGTAAATGTGTGGTTTAACTCGTCCATGGCCCAGCATTAGGGAGCTGTGGACCCTGCAGCCTGGCTGTGGGGGCCGCAGTGGCTGAGGGGTGCAGAGCCGAGTCACGGGGTTGCCAGCACAGGGGCTTAACCTCTGGTGACTGCCAGAGCTGCTGGCAAGCTAGAGTCCCATTTGGAGCCCCTCTAAGCCGTTCTATTTGTAATGAAAACTATATTTATGCTATTCAGTTCTAAATATAGAAATTGAAACAGCTGTGTTTAGTGCCTTTGTTCAACCCCCTTGCAACAACCTTGAGAACCCCAGGGAATTTGTCAATGTCAGGGAAGGAGCATTTTGTCAGTTACCAAATGTGTTTATTACCAGAGGGATGGAGGGAAGAGGGACGCTGAAGAACTTTGATGCCCTCTTCTTCCAAAGATGAAACGCGTAACTGCGCTCTCATTCACTCCAGCTCCCTGTCACCCAATGGACCTGTGATATCTGGATTCTGGGAAATTCTTCATCCTGGACCCTGAGAGATTCTGCAGCCCAGCTCCAGATTGCTTGTGGTCTGACAGGCTGCAACTGTGAGCCATCACAATGAACAACAGGAAGAAAAGGTCTTTCAAAAGGTGATGTGTGTTCTCATCAACCTCATACACACACATGGTTTAGGGGTATAATACCTCTACATGGCTGATTATGAAAACAATGTTCCCCAGATACCATCCCTGTCTTACTTCCAGCTCCCCAGAGGGAAAGCTTTCAACGCTTCTAGCCATTTCTTTTGGCATTTGCCTTCAGACCCTACACGAATGCGTCTCTACCACAGGGGGCTGCGCGGTTTCCCATCATGAAGCACTGAACTTCCACGTCTCATCTAGGGGAACAGGGAGGTGCACTAATGCGCTCCACGCCCAAGCCCTTCTCACAGTTTCTGCCCCCAGCATGGTTGTACTGGGCAATACATGAGATTATTAGGAAATGCTTTACTGTCATAACTATGAAGAGACTATTGCCAGATGAACCACACATTAATACTATGTTTCTTATCTGCACATTACTACCCTGCAATTAATATAATTGTGTCCATGTACACACGCTGTCCTATGTACTTATCATGACTCTATCCCAAATTCCCAATTACGTCCTATCTTCTTCTTAGGGAAGAACAGCTTAGGTATCAATTTGGTGTTCTGTGTAAAGTCTCAGGGAGCCGTCCGTGTCCTCCCATCTGGCCTCGTCCACACTGGTTCTCTTGAAAGCTTGGGCTGTAATGATGCCCCTTGGCCATCACCCAGTCCCTGCCCCATCTCTTGTAATCTCTCTCCTTTTTGCTGCATCCCTGTCTTCCTCTGTCTTGATTTACTTGTTGTTGGTTTTCTGTTTCTTTGTTTGATTTGGTGGAAGACATAATCCCACGCTTCCTATGGAAAGGTTGTTGGGAGATTTTTAATGATTCCTCAATGTTAAAATGTCTATTTTTGTCTTGACACCCAACTAATATTTGTCTGAGCAAAACAGTCTAGATGAGAGAGAACTTCCCTGGAGGTCTGATGGCGTTTCTCCCTCGTCTTCTTA", + "CACTAGTGGCTCATTGTAAATGTGTGGTTTAACTCGTCCATGGCCCAGCATTAGGGAGCTGTGGACCCTGCAGCCTGGCTGTGGGGGCCGCAGTGGCTGAGGGGTGCAGAGCCGAGTCACGGGGTTGCCAGCACAGGGGCTTAACCTCTGGTGACTGCCAGAGCTGCTGGCAAGCTAGAGTCCCATTTGGAGCCCCTCTAAGCCGTTCTATTTGTAATGAAAACTATATTTATGCTATTCAGTTCTAAATATAGAAATTGAAACAGCTGTGTTTAGTGCCTTTGTTCAACCCCCTTGCAACAACCTTGAGAACCCCAGGGAATTTGTCAATGTCAGGGAAGGAGCATTTTGTCAGTTACCAAATGTGTTTATTACCAGAGGGATGGAGGGAAGAGGGACGCTGAAGAACTTTGATGCCCTCTTCTTCCAAAGATGAAACGCGTAACTGCGCTCTCATTCACTCCAGCTCCCTGTCACCCAATGGACCTGTGATATCTGGATTCTGGGAAATTCTTCATCCTGGACCCTGAGAGATTCTGCAGCCCAGCTCCAGATTGCTTGTGGTCTGACAGGCTGCAACTGTGAGCCATCACAATGAACAACAGGAAGAAAAGGTCTTTCAAAAGGTGATGTGTGTTCTCATCAACCTCATACACACACATGGTTTAGGGGTATAATACCTCTACATGGCTGATTATGAAAACAATGTTCCCCAGATACCATCCCTGTCTTACTTCCAGCTCCCCAGAGGGAAAGCTTTCAACGCTTCTAGCCATTTCTTTTGGCATTTGCCTTCAGACCCTACACGAATGCGTCTCTACCACAGGGGGCTGCGCGGTTTCCCATCATGAAGCACTGAACTTCCACGTCTCATCTAGGGGAACAGGGAGGTGCACTAATGCGCTCCACGCCCAAGCCCTTCTCACAGTTTCTGCCCCCAGCATGGTTGTACTGGGCAATACATGAGATTATTAGGAAATGCTTTACTGTCATAACTATGAAGAGACTATTGCCAGATGAACCACACATTAATACTATGTTTCTTATCTGCACATTACTACCCTGCAATTAATATAATTGTGTCCATGTACACACGCTGTCCTATGTACTTATCATGACTCTATCCCAAATTCCCAATTACGTCCTATCTTCTTCTTAGGGAAGAACAGCTTAGGTATCAATTTGGTGTTCTGTGTAAAGTCTCAGGGAGCCGTCCGTGTCCTCCCATCTGGCCTCGTCCACACTGGTTCTCTTGAAAGCTTGGGCTGTAATGATGCCCCTTGGCCATCACCCAGTCCCTGCCCCATCTCTTGTAATCTCTCTCCTTTTTGCTGCATCCCTGTCTTCCTCTGTCTTGATTTACTTGTTGTTGGTTTTCTGTTTCTTTGTTTGATTTGGTGGAAGACATAATCCCACGCTTCCTATGGAAAGGTTGTTGGGAGATTTTTAATGATTCCTCAATGTTAAAATGTCTATTTTTGTCTTGACACCCAACTAATATTTGTCTGAGCAAAACAGTCTAGATGAGAGAGAACTTCCCTGGAGGTCTGATGGCGTTTCTCCCTCGTCTTCTTA", # noqa 'chr2': - "TTCAAATGAACTTCTGTAATTGAAAAATTCATTTAAGAAATTACAAAATATAGTTGAAAGCTCTAACAATAGACTAAACCAAGCAGAAGAAAGAGGTTCAGAACTTGAAGACAAGTCTCTTATGAATTAACCCAGTCAGACAAAAATAAAGAAAAAAATTTTAAAAATGAACAGAGCTTTCAAGAAGTATGAGATTATGTAAAGTAACTGAACCTATGAGTCACAGGTATTCCTGAGGAAAAAGAAAAAGTGAGAAGTTTGGAAAAACTATTTGAGGAAGTAATTGGGGAAAACCTCTTTAGTCTTGCTAGAGATTTAGACATCTAAATGAAAGAGGCTCAAAGAATGCCAGGAAGATACATTGCAAGACAGACTTCATCAAGATATGTAGTCATCAGACTATCTAAAGTCAACATGAAGGAAAAAAATTCTAAAATCAGCAAGAGAAAAGCATACAGTCATCTATAAAGGAAATCCCATCAGAATAACAATGGGCTTCTCAGCAGAAACCTTACAAGCCAGAAGAGATTGGATCTAATTTTTGGACTTCTTAAAGAAAAAAAAACCTGTCAAACACGAATGTTATGCCCTGCTAAACTAAGCATCATAAATGAAGGGGAAATAAAGTCAAGTCTTTCCTGACAAGCAAATGCTAAGATAATTCATCATCACTAAACCAGTCCTATAAGAAATGCTCAAAAGAATTGTAAAAGTCAAAATTAAAGTTCAATACTCACCATCATAAATACACACAAAAGTACAAAACTCACAGGTTTTATAAAACAATTGAGACTACAGAGCAACTAGGTAAAAAATTAACATTACAACAGGAACAAAACCTCATATATCAATATTAACTTTGAATAAAAAGGGATTAAATTCCCCCACTTAAGAGATATAGATTGGCAGAACAGATTTAAAAACATGAACTAACTATATGCTGTTTACAAGAAACTCATTAATAAAGACATGAGTTCAGGTAAAGGGGTGGAAAAAGATGTTCTACGCAAACAGAAACCAAATGAGAGAAGGAGTAGCTATACTTATATCAGATAAAGCACACTTTAAATCAACAACAGTAAAATAAAACAAAGGAGGTCATCATACAATGATAAAAAGATCAATTCAGCAAGAAGATATAACCATCCTACTAAATACATATGCACCTAACACAAGACTACCCAGATTCATAAAACAAATACTACTAGACCTAAGAGGGATGAGAAATTACCTAATTGGTACAATGTACAATATTCTGATGATGGTTACACTAAAAGCCCATACTTTACTGCTACTCAATATATCCATGTAACAAATCTGCGCTTGTACTTCTAAATCTATAAAAAAATTAAAATTTAACAAAAGTAAATAAAACACATAGCTAAAACTAAAAAAGCAAAAACAAAAACTATGCTAAGTATTGGTAAAGATGTGGGGAAAAAAGTAAACTCTCAAATATTGCTAGTGGGAGTATAAATTGTTTTCCACTTTGGAAAACAATTTGGTAATTTCGTTTTTTTTTTTTTCTTTTCTCTTTTTTTTTTTTTTTTTTTTGCATGCCAGAAAAAAATATTTACAGTAACT", + "TTCAAATGAACTTCTGTAATTGAAAAATTCATTTAAGAAATTACAAAATATAGTTGAAAGCTCTAACAATAGACTAAACCAAGCAGAAGAAAGAGGTTCAGAACTTGAAGACAAGTCTCTTATGAATTAACCCAGTCAGACAAAAATAAAGAAAAAAATTTTAAAAATGAACAGAGCTTTCAAGAAGTATGAGATTATGTAAAGTAACTGAACCTATGAGTCACAGGTATTCCTGAGGAAAAAGAAAAAGTGAGAAGTTTGGAAAAACTATTTGAGGAAGTAATTGGGGAAAACCTCTTTAGTCTTGCTAGAGATTTAGACATCTAAATGAAAGAGGCTCAAAGAATGCCAGGAAGATACATTGCAAGACAGACTTCATCAAGATATGTAGTCATCAGACTATCTAAAGTCAACATGAAGGAAAAAAATTCTAAAATCAGCAAGAGAAAAGCATACAGTCATCTATAAAGGAAATCCCATCAGAATAACAATGGGCTTCTCAGCAGAAACCTTACAAGCCAGAAGAGATTGGATCTAATTTTTGGACTTCTTAAAGAAAAAAAAACCTGTCAAACACGAATGTTATGCCCTGCTAAACTAAGCATCATAAATGAAGGGGAAATAAAGTCAAGTCTTTCCTGACAAGCAAATGCTAAGATAATTCATCATCACTAAACCAGTCCTATAAGAAATGCTCAAAAGAATTGTAAAAGTCAAAATTAAAGTTCAATACTCACCATCATAAATACACACAAAAGTACAAAACTCACAGGTTTTATAAAACAATTGAGACTACAGAGCAACTAGGTAAAAAATTAACATTACAACAGGAACAAAACCTCATATATCAATATTAACTTTGAATAAAAAGGGATTAAATTCCCCCACTTAAGAGATATAGATTGGCAGAACAGATTTAAAAACATGAACTAACTATATGCTGTTTACAAGAAACTCATTAATAAAGACATGAGTTCAGGTAAAGGGGTGGAAAAAGATGTTCTACGCAAACAGAAACCAAATGAGAGAAGGAGTAGCTATACTTATATCAGATAAAGCACACTTTAAATCAACAACAGTAAAATAAAACAAAGGAGGTCATCATACAATGATAAAAAGATCAATTCAGCAAGAAGATATAACCATCCTACTAAATACATATGCACCTAACACAAGACTACCCAGATTCATAAAACAAATACTACTAGACCTAAGAGGGATGAGAAATTACCTAATTGGTACAATGTACAATATTCTGATGATGGTTACACTAAAAGCCCATACTTTACTGCTACTCAATATATCCATGTAACAAATCTGCGCTTGTACTTCTAAATCTATAAAAAAATTAAAATTTAACAAAAGTAAATAAAACACATAGCTAAAACTAAAAAAGCAAAAACAAAAACTATGCTAAGTATTGGTAAAGATGTGGGGAAAAAAGTAAACTCTCAAATATTGCTAGTGGGAGTATAAATTGTTTTCCACTTTGGAAAACAATTTGGTAATTTCGTTTTTTTTTTTTTCTTTTCTCTTTTTTTTTTTTTTTTTTTTGCATGCCAGAAAAAAATATTTACAGTAACT", # noqa } def setUp(self): - self.file = pysam.FastaFile(os.path.join(DATADIR, "ex1.fa")) + self.file = pysam.FastaFile(os.path.join(BAM_DATADIR, "ex1.fa")) def testFetch(self): for id, seq in list(self.sequences.items()): @@ -59,50 +58,47 @@ def tearDown(self): class TestFastaFilePathIndex(unittest.TestCase): - filename = os.path.join(DATADIR, "ex1.fa") - - def testGarbageIndex(self): - self.assertRaises(NotImplementedError, + filename = os.path.join(BAM_DATADIR, "ex1.fa") + data_suffix = ".fa" + + def test_raise_exception_if_index_is_missing(self): + self.assertRaises(IOError, pysam.FastaFile, self.filename, - filepath_index="garbage.fa.fai") - return + filepath_index="garbage" + self.data_suffix + ".fai") - self.assertRaises(ValueError, - pysam.FastaFile, - self.filename, - filepath_index="garbage.fa.fai") + def test_open_file_without_index_succeeds(self): + with pysam.FastaFile(self.filename) as inf: + self.assertEqual(len(inf), 2) - def testOpenWithoutIndex(self): - faidx = pysam.FastaFile(self.filename) - faidx.close() + def test_open_file_with_explicit_index_succeeds(self): + with pysam.FastaFile(self.filename, + filepath_index=self.filename + ".fai") as inf: + self.assertEqual(len(inf), 2) - def testOpenWithStandardIndex(self): - self.assertRaises(NotImplementedError, - pysam.FastaFile, - self.filename, - filepath_index=self.filename + ".fai") - return + def test_open_file_with_explicit_abritrarily_named_index_succeeds(self): + tmpfilename = get_temp_filename(self.data_suffix) + shutil.copyfile(self.filename, tmpfilename) - faidx = pysam.FastaFile(self.filename, - filepath_index=self.filename + ".fai") - faidx.close() + filepath_index = self.filename + ".fai" + filepath_index_compressed = self.filename + ".gzi" + if not os.path.exists(filepath_index_compressed): + filepath_index_compressed = None + with pysam.FastaFile(tmpfilename, + filepath_index=filepath_index, + filepath_index_compressed=filepath_index_compressed) as inf: + self.assertEqual(len(inf), 2) - def testOpenWithOtherIndex(self): - return - tmpfilename = "tmp_" + os.path.basename(self.filename) - shutil.copyfile(self.filename, tmpfilename) - faidx = pysam.FastaFile(tmpfilename, - filepath_index=self.filename + ".fai") - faidx.close() # index should not be auto-generated self.assertFalse(os.path.exists(tmpfilename + ".fai")) os.unlink(tmpfilename) + class TestFastaFilePathIndexCompressed(TestFastaFilePathIndex): - - filename = os.path.join(DATADIR, "ex1.fa.gz") + filename = os.path.join(BAM_DATADIR, "ex1.fa.gz") + data_suffix = ".fa.gz" + class TestFastxFileFastq(unittest.TestCase): @@ -111,7 +107,7 @@ class TestFastxFileFastq(unittest.TestCase): persist = True def setUp(self): - self.file = self.filetype(os.path.join(DATADIR, self.filename), + self.file = self.filetype(os.path.join(BAM_DATADIR, self.filename), persist=self.persist) self.has_quality = self.filename.endswith('.fq') @@ -170,7 +166,7 @@ def testSequence(self): self.checkLast(first) def testManager(self): - with self.filetype(os.path.join(DATADIR, self.filename), + with self.filetype(os.path.join(BAM_DATADIR, self.filename), persist=self.persist) as inf: first = inf.__next__() self.checkFirst(first) @@ -206,7 +202,7 @@ class TestFastxFileWithEmptySequence(unittest.TestCase): filename = "faidx_empty_seq.fq.gz" def testIteration(self): - fn = os.path.join(DATADIR, self.filename) + fn = os.path.join(BAM_DATADIR, self.filename) with gzip.open(fn) as inf: ref_num = len(list(inf)) / 4 @@ -220,17 +216,105 @@ class TestRemoteFileFTP(unittest.TestCase): '''test remote access. ''' - url = "ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/GRCh38_reference_genome/GRCh38_full_analysis_set_plus_decoy_hla.fa" - + url = ("ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/" + "GRCh38_reference_genome/GRCh38_full_analysis_set_plus_decoy_hla.fa") def testFTPView(self): - if not checkURL(self.url): + if not check_url(self.url): return + with pysam.Fastafile(self.url) as f: self.assertEqual( len(f.fetch("chr1", 0, 1000)), 1000) + def test_sequence_lengths_are_available(self): + if not check_url(self.url): + return + + with pysam.Fastafile(self.url) as f: + self.assertEqual(len(f.references), 3366) + self.assertTrue("chr1" in f.references) + self.assertEqual(f.lengths[0], + 248956422) + self.assertEqual(f.get_reference_length("chr1"), + 248956422) + + +class TestFastqRecord(unittest.TestCase): + + filetype = pysam.FastxFile + filename = "faidx_ex1.fq" + + def setUp(self): + + with self.filetype(os.path.join(BAM_DATADIR, self.filename), persist=True) as inf: + self.record = next(inf) + + def test_fastx_record_sequence_can_be_modified(self): + old_sequence = self.record.sequence + new_record = copy.copy(self.record) + new_sequence = "AAAC" + new_record.set_sequence(new_sequence) + self.assertEqual(str(new_record), ">{}\n{}".format( + self.record.name, new_sequence)) + self.assertEqual(self.record.sequence, old_sequence) + self.assertEqual(new_record.sequence, new_sequence) + + def test_fastx_record_name_can_be_modified(self): + old_name = self.record.name + new_name = "new_name" + new_record = copy.copy(self.record) + new_record.set_name(new_name) + self.assertEqual(new_record.name, new_name) + self.assertEqual(self.record.name, old_name) + + def test_fastx_record_fail_if_name_is_None(self): + self.assertRaises(ValueError, + self.record.set_name, + None) + + def test_fastx_record_comment_can_be_modified(self): + old_comment = self.record.comment + new_comment = "this is a new comment" + new_record = copy.copy(self.record) + new_record.set_comment(new_comment) + self.assertEqual(new_record.comment, new_comment) + self.assertEqual(self.record.comment, old_comment) + + def test_fastx_record_comment_can_be_None(self): + old_comment = self.record.comment + new_comment = None + new_record = copy.copy(self.record) + new_record.set_comment(new_comment) + self.assertEqual(new_record.comment, new_comment) + self.assertEqual(self.record.comment, old_comment) + + def test_fastx_record_quality_can_be_modified(self): + old_quality = self.record.quality + new_quality = "A" * len(old_quality) + new_record = copy.copy(self.record) + new_record.set_sequence(self.record.sequence, new_quality) + self.assertEqual(new_record.quality, new_quality) + self.assertEqual(self.record.quality, old_quality) + + def test_fastx_record_fail_if_quality_is_wrong_length(self): + self.assertRaises(ValueError, + self.record.set_sequence, + self.record.sequence, self.record.quality * 2) + + def test_fastx_record_can_be_created_from_scratch(self): + fastx_record = pysam.FastxRecord() + self.assertRaises(ValueError, + str, + fastx_record) + fastx_record.set_name("name") + self.assertRaises(ValueError, + str, + fastx_record) + fastx_record.set_sequence("sequence") + self.assertEqual(str(fastx_record), ">name\nsequence") + if __name__ == "__main__": unittest.main() diff --git a/tests/linking_test.py b/tests/linking_test.py new file mode 100644 index 000000000..15fd91a82 --- /dev/null +++ b/tests/linking_test.py @@ -0,0 +1,92 @@ +"""test linking against pysam. +""" + +import unittest +import os +import subprocess +import pysam + +from TestUtils import LINKDIR + + +def check_import(statement): + try: + output = subprocess.check_output( + statement, stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as exc: + if b"ImportError" in exc.output: + raise ImportError( + "module could not be imported: {}".format(str(exc.output))) + else: + raise + + +def check_pass(statement): + try: + output = subprocess.check_output( + statement, stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as exc: + raise ValueError("{}: {}".format(exc, exc.output)) + if b"FAILED" in output: + raise ValueError("module tests failed") + return True + + +@unittest.skipUnless( + os.environ.get("PYSAM_LINKING_TESTS", None), + "enable linking tests by setting PYSAM_LINKING_TESTS environment variable") +class TestLinking(unittest.TestCase): + + package_name = "link_with_rpath" + + def setUp(self): + self.workdir = os.path.join(LINKDIR, self.package_name) + + def test_package_can_be_installed(self): + subprocess.check_output( + "cd {} && rm -rf build && python setup.py install".format( + self.workdir), + shell=True) + + +@unittest.skipUnless( + os.environ.get("PYSAM_LINKING_TESTS", None), + "enable linking tests by setting PYSAM_LINKING_TESTS environment variable") +class TestLinkWithRpath(TestLinking): + + package_name = "link_with_rpath" + + def test_package_tests_pass(self): + self.assertTrue(check_pass( + "cd {} && python test_module.py".format(os.path.join(self.workdir, "tests")))) + + +@unittest.skipUnless( + os.environ.get("PYSAM_LINKING_TESTS", None), + "enable linking tests by setting PYSAM_LINKING_TESTS environment variable") +class TestLinkWithoutRpath(TestLinking): + + package_name = "link_without_rpath" + + def test_package_tests_fail_on_import(self): + + self.assertRaises( + ImportError, + check_import, + "cd {} && python test_module.py".format(os.path.join(self.workdir, "tests"))) + + def test_package_tests_pass_if_ld_library_path_set(self): + + pysam_libraries = pysam.get_libraries() + pysam_libdirs, pysam_libs = zip( + *[os.path.split(x) for x in pysam_libraries]) + pysam_libdir = pysam_libdirs[0] + + self.assertTrue(check_pass( + "export LD_LIBRARY_PATH={}:$PATH && cd {} && python test_module.py".format( + pysam_libdir, + os.path.join(self.workdir, "tests")))) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pysam_data/Makefile b/tests/pysam_data/Makefile index 2ccedd28a..b48a27c02 100644 --- a/tests/pysam_data/Makefile +++ b/tests/pysam_data/Makefile @@ -9,6 +9,7 @@ CRAI=$(CRAM:%.cram=%.cram.crai) all: ex1.pileup.gz \ ex1.sam ex1.bam \ ex2.sam.gz ex2.sam ex2.bam ex2.bam.bai \ + with_md.sam.gz with_md.bam with_md.bam.bai \ uncompressed.bam \ $(BAM) $(BAI) \ $(CRAM) $(CRAI) \ @@ -18,13 +19,17 @@ all: ex1.pileup.gz \ empty.bam empty.bam.bai \ explicit_index.bam explicit_index.cram \ faidx_empty_seq.fq.gz \ - ex1.fa.gz ex1.fa.gz.fai \ - ex1_csi.bam + ex1.fa.gz ex1.fa.gz.csi \ + ex1_csi.bam \ + example_reverse_complement.bam # ex2.sam - as ex1.sam, but with header ex2.sam.gz: ex1.bam ex1.bam.bai samtools view -h ex1.bam | gzip > ex2.sam.gz +with_md.sam.gz: ex2.bam ex1.fa + samtools calmd --output-fmt BAM $^ > $@ + #%.bam: %.sam ex1.fa.fai # samtools import ex1.fa.fai $< $@ @@ -93,5 +98,5 @@ clean: %.fa.gz: %.fa bgzip < $< > $@ -%.fa.gz.fai: %.fa.gz +%.fa.gz.csi: %.fa.gz samtools faidx $< diff --git a/tests/pysam_data/example_no_seq_in_header.bam b/tests/pysam_data/example_no_seq_in_header.bam new file mode 100644 index 000000000..72de63619 Binary files /dev/null and b/tests/pysam_data/example_no_seq_in_header.bam differ diff --git a/tests/pysam_data/example_reverse_complement.sam b/tests/pysam_data/example_reverse_complement.sam new file mode 100644 index 000000000..795d19c43 --- /dev/null +++ b/tests/pysam_data/example_reverse_complement.sam @@ -0,0 +1,28 @@ +@SQ SN:chr1 LN:249250621 +@SQ SN:chr10 LN:135534747 +@SQ SN:chr11 LN:135006516 +@SQ SN:chr12 LN:133851895 +@SQ SN:chr13 LN:115169878 +@SQ SN:chr14 LN:107349540 +@SQ SN:chr15 LN:102531392 +@SQ SN:chr16 LN:90354753 +@SQ SN:chr17 LN:81195210 +@SQ SN:chr18 LN:78077248 +@SQ SN:chr19 LN:59128983 +@SQ SN:chr2 LN:243199373 +@SQ SN:chr20 LN:63025520 +@SQ SN:chr21 LN:48129895 +@SQ SN:chr22 LN:51304566 +@SQ SN:chr3 LN:198022430 +@SQ SN:chr4 LN:191154276 +@SQ SN:chr5 LN:180915260 +@SQ SN:chr6 LN:171115067 +@SQ SN:chr7 LN:159138663 +@SQ SN:chr8 LN:146364022 +@SQ SN:chr9 LN:141213431 +@SQ SN:chrM LN:16571 +@SQ SN:chrX LN:155270560 +@SQ SN:chrY LN:59373566 +@PG ID:bwa PN:bwa VN:0.7.12-r1039 CL:bwa mem /ifs/mirror/genomes/bwa-0.7.5a/hg19 both.fq +chr22:25000000-25000500 0 chr22 25000000 60 501M * 0 0 GCTCTGTGCCGCAAGGGTGGAAACTGTGAGAGACAGATTCCAACTCCACGTCTGGGTAGTAAGCATCCAGTCCAGGGCTGTAGGCAGTCCTGGGGAAGACGCCAGAGATCTGTGCATTCTCATATCGAGGGATAGCGACTCCAGGCTGGGGGCTGGCAGGGTAAGGGGTGGGTGGGTCCTGGGCTTACCCGCAGGTCTGCAGACTTCCTGGGGCCAGCTGACCTCGTAAAATCCCTTTTGTCTAAGCTTCAGTTTCCTGCCTGTGAATGGGGTTGGGGCTGTGCTCTGGTTTCACCCTTGTGGCTCTGGGGTTGTGGTGACAAAGCCATCAAGCTGGGTTGAAGGATTAACCAGGAAACTTCAGACTGGCTGCCGTGTCTACCTCTTCCTCATACTCCTCTCTCTGCTGCATCCTGGGAAGCTGCTCTGCTCAGCCTAAATGAGGCTCAGTTGTGTGTGTGCGCACGTGCTTGCACGTGTGTTGGAAGTGGGTGATACTGA GCTCTGTGCCGCAAGGGTGGAAACTGTGAGAGACAGATTCCAACTCCACGTCTGGGTAGTAAGCATCCAGTCCAGGGCTGTAGGCAGTCCTGGGGAAGACGCCAGAGATCTGTGCATTCTCATATCGAGGGATAGCGACTCCAGGCTGGGGGCTGGCAGGGTAAGGGGTGGGTGGGTCCTGGGCTTACCCGCAGGTCTGCAGACTTCCTGGGGCCAGCTGACCTCGTAAAATCCCTTTTGTCTAAGCTTCAGTTTCCTGCCTGTGAATGGGGTTGGGGCTGTGCTCTGGTTTCACCCTTGTGGCTCTGGGGTTGTGGTGACAAAGCCATCAAGCTGGGTTGAAGGATTAACCAGGAAACTTCAGACTGGCTGCCGTGTCTACCTCTTCCTCATACTCCTCTCTCTGCTGCATCCTGGGAAGCTGCTCTGCTCAGCCTAAATGAGGCTCAGTTGTGTGTGTGCGCACGTGCTTGCACGTGTGTTGGAAGTGGGTGATACTGA NM:i:0 MD:Z:501 AS:i:501 XS:i:343 +chr22:25000000-25000500 16 chr22 25000000 60 501M * 0 0 GCTCTGTGCCGCAAGGGTGGAAACTGTGAGAGACAGATTCCAACTCCACGTCTGGGTAGTAAGCATCCAGTCCAGGGCTGTAGGCAGTCCTGGGGAAGACGCCAGAGATCTGTGCATTCTCATATCGAGGGATAGCGACTCCAGGCTGGGGGCTGGCAGGGTAAGGGGTGGGTGGGTCCTGGGCTTACCCGCAGGTCTGCAGACTTCCTGGGGCCAGCTGACCTCGTAAAATCCCTTTTGTCTAAGCTTCAGTTTCCTGCCTGTGAATGGGGTTGGGGCTGTGCTCTGGTTTCACCCTTGTGGCTCTGGGGTTGTGGTGACAAAGCCATCAAGCTGGGTTGAAGGATTAACCAGGAAACTTCAGACTGGCTGCCGTGTCTACCTCTTCCTCATACTCCTCTCTCTGCTGCATCCTGGGAAGCTGCTCTGCTCAGCCTAAATGAGGCTCAGTTGTGTGTGTGCGCACGTGCTTGCACGTGTGTTGGAAGTGGGTGATACTGA CGAGACACGGCGTTCCCACCTTTGACACTCTCTGTCTAAGGTTGAGGTGCAGACCCATCATTCGTAGGTCAGGTCCCGACATCCGTCAGGACCCCTTCTGCGGTCTCTAGACACGTAAGAGTATAGCTCCCTATCGCTGAGGTCCGACCCCCGACCGTCCCATTCCCCACCCACCCAGGACCCGAATGGGCGTCCAGACGTCTGAAGGACCCCGGTCGACTGGAGCATTTTAGGGAAAACAGATTCGAAGTCAAAGGACGGACACTTACCCCAACCCCGACACGAGACCAAAGTGGGAACACCGAGACCCCAACACCACTGTTTCGGTAGTTCGACCCAACTTCCTAATTGGTCCTTTGAAGTCTGACCGACGGCACAGATGGAGAAGGAGTATGAGGAGAGAGACGACGTAGGACCCTTCGACGAGACGAGTCGGATTTACTCCGAGTCAACACACACACGCGTGCACGAACGTGCACACAACCTTCACCCACTATGACT NM:i:0 MD:Z:501 AS:i:501 XS:i:343 diff --git a/tests/pysam_data/test_mapped_unmapped.sam b/tests/pysam_data/test_mapped_unmapped.sam index c0b623043..f5ca805e3 100644 --- a/tests/pysam_data/test_mapped_unmapped.sam +++ b/tests/pysam_data/test_mapped_unmapped.sam @@ -1,5 +1,6 @@ @HD VN:1.0 @SQ SN:chr1 LN:100 +@SQ SN:chr2 LN:100 @CO Test counting of mapped/unmapped reads read1_mapped 0 chr1 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 read2_unmapped 4 chr1 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 @@ -11,6 +12,16 @@ pair2b_mapped 139 chr1 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGG pair3a_unmapped 77 chr1 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 pair3b_unmapped 141 chr1 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 noseq2b_mapped 139 chr1 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 +bread1_mapped 0 chr2 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 +bread2_unmapped 4 chr2 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 +bread3_unmapped 20 chr2 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 +bpair1a_mapped 67 chr2 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 +bpair1b_mapped 131 chr2 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 +bpair2a_unmapped 71 chr2 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 +bpair2b_mapped 139 chr2 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 +bpair3a_unmapped 77 chr2 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 +bpair3b_unmapped 141 chr2 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 +bnoseq2b_mapped 139 chr2 21 20 10M1D25M = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 noseq1_unmapped 4 * 0 20 * = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 noseq2a_unmapped 71 * 0 20 * = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 pair3a_unmapped 77 * 0 20 * = 200 167 AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG <<<<<<<<<<<<<<<<<<<<<:<9/,&,22;;<<< NM:i:1 diff --git a/tests/samtools_test.py b/tests/samtools_test.py index aa4c5540a..e84c7e55c 100644 --- a/tests/samtools_test.py +++ b/tests/samtools_test.py @@ -5,9 +5,7 @@ and data files located there. ''' -import pysam -import pysam.samtools -import pysam.bcftools +import warnings import unittest import os import re @@ -15,13 +13,15 @@ import sys import subprocess import shutil +import pysam +import pysam.samtools +import pysam.bcftools from TestUtils import checkBinaryEqual, check_lines_equal, \ - check_samtools_view_equal, get_temp_filename, force_bytes + check_samtools_view_equal, get_temp_filename, force_bytes, WORKDIR, \ + BAM_DATADIR -IS_PYTHON3 = sys.version_info[0] >= 3 -WORKDIR = "pysam_test_work" -DATADIR = "pysam_data" +IS_PYTHON3 = sys.version_info[0] >= 3 def run_command(cmd): @@ -63,7 +63,10 @@ class SamtoolsTest(unittest.TestCase): "ex1.fa", "ex1.fa.fai", "ex1.sam.gz", "ex1.bam", "ex1.bam.bai", - "ex1.sam", "ex2.bam", + "ex1.sam", + "ex1.sam", + "ex2.bam", + "ex2.sam", "ex1.bed"] # a list of statements to test @@ -92,7 +95,7 @@ class SamtoolsTest(unittest.TestCase): # unknow option # "rmdup -s ex1.bam %(out)s_ex1.rmdup.bam", # "merge -f %(out)s_ex1.merge.bam ex1.bam ex1.bam", - "reheader ex1.sam ex1.bam > %(out)s_ex1.reheader", + "reheader ex2.sam ex1.bam > %(out)s_ex1.reheader.bam", "cat -o %(out)s_ex1.cat.bam ex1.bam ex1.bam", "targetcut ex1.bam > %(out)s_ex1.targetcut", "phase ex1.bam > %(out)s_ex1.phase", @@ -120,6 +123,7 @@ class SamtoolsTest(unittest.TestCase): def check_version(self): samtools_version = get_version(self.executable) + def _r(s): # patch - remove any of the alpha/beta suffixes, i.e., 0.1.12a -> # 0.1.12 @@ -128,7 +132,7 @@ def _r(s): return re.sub("[^0-9.]", "", s) if _r(samtools_version) != _r(pysam.__samtools_version__): - raise ValueError( + warnings.warn( "versions of pysam.%s and %s differ: %s != %s" % (self.executable, self.executable, @@ -143,29 +147,39 @@ def setUp(self): files. ''' - self.check_version() - if not os.path.exists(WORKDIR): - os.makedirs(WORKDIR) + self.workdir = os.path.join(WORKDIR, "samtools_test") + + if not os.path.exists(self.workdir): + os.makedirs(self.workdir) for f in self.requisites: - shutil.copy(os.path.join(DATADIR, f), - os.path.join(WORKDIR, f)) + shutil.copy(os.path.join(BAM_DATADIR, f), + os.path.join(self.workdir, f)) self.savedir = os.getcwd() - os.chdir(WORKDIR) + os.chdir(self.workdir) return + def get_command(self, statement, map_to_internal=True): + """return samtools command from statement""" + parts = statement.split(" ") + command = parts[0] + if map_to_internal: + return self.map_command.get(command, command) + else: + return command + def check_statement(self, statement): parts = statement.split(" ") r_samtools = {"out": self.executable} r_pysam = {"out": "pysam"} - command = parts[0] - command = self.map_command.get(command, command) + command = self.get_command(statement) + # self.assertTrue(command in pysam.SAMTOOLS_DISPATCH) targets = [x for x in parts if "%(out)s" in x] @@ -173,6 +187,7 @@ def check_statement(self, statement): pysam_targets = [x % r_pysam for x in targets] pysam_method = getattr(self.module, command) + # run samtools full_statement = re.sub("%\(out\)s", self.executable, statement) run_command(" ".join((self.executable, full_statement))) @@ -193,7 +208,6 @@ def check_statement(self, statement): with open(pysam_targets[-1], "wb") as outfile: if output is not None: outfile.write(force_bytes(output)) - for samtools_target, pysam_target in zip(samtools_targets, pysam_targets): if os.path.isdir(samtools_target): @@ -209,32 +223,60 @@ def check_statement(self, statement): for s, p in zip(samtools_files, pysam_files): binary_equal = checkBinaryEqual(s, p) - error_msg = "%s failed: files %s and %s are not the same" % (command, s, p) + error_msg = "%s failed: files %s and %s are not the same" % ( + command, s, p) if binary_equal: continue - if s.endswith(".bam"): + elif s.endswith(".bam"): self.assertTrue( check_samtools_view_equal( s, p, without_header=True), error_msg) - check_lines_equal( - self, s, p, - filter_f=lambda x: x.startswith("#"), - msg=error_msg) + else: + check_lines_equal( + self, s, p, + filter_f=lambda x: x.startswith("#"), + msg=error_msg) def testStatements(self): for statement in self.statements: - if (statement.startswith("calmd") and - list(sys.version_info[:2]) == [3, 3]): + command = self.get_command(statement, map_to_internal=False) + # bam2fq differs between version 1.5 and 1.6 - reenable if + # bioconda samtools will be available. + if command in ("bedcov", "stats", "dict", "bam2fq"): + continue + + if (command == "calmd" and + list(sys.version_info[:2]) == [3, 3]): # skip calmd test, fails only on python 3.3.5 # in linux (empty output). Works in OsX and passes # for 3.4 and 3.5, see issue #293 continue self.check_statement(statement) + @unittest.skipIf(sys.platform == "darwin", "not supported, pattern does not match") + @unittest.skipIf(not sys.stdin.isatty(), "skipping usage tests, stdin is not a tty") + def testUsage(self): + if self.executable == "bcftools": + # bcftools usage messages end with exit(1) + return + + for statement in self.statements: + command = self.get_command(statement, map_to_internal=False) + # ignore commands that exit or cause other failures + # TODO: check - if reheader or phase is run in testStatements, sort fails + # here + if command in ("view", "sort", "bam2fq", "flagstat", "reheader", "stats"): + continue + mapped_command = self.get_command(statement, map_to_internal=True) + pysam_method = getattr(self.module, mapped_command) + usage_msg = pysam_method.usage() + expected = "Usage:\s+{} {}".format(self.executable, command) + self.assertTrue(re.search(expected, usage_msg) is not None) + def tearDown(self): - if os.path.exists(WORKDIR): - shutil.rmtree(WORKDIR) + if os.path.exists(self.workdir): + shutil.rmtree(self.workdir) os.chdir(self.savedir) @@ -244,120 +286,124 @@ def testEmptyIndex(self): self.assertRaises(IOError, pysam.samtools.index, "exdoesntexist.bam") -class TestReturnType(unittest.TestCase): - - def testReturnValueString(self): - retval = pysam.idxstats(os.path.join(DATADIR, "ex1.bam")) - if IS_PYTHON3: - self.assertFalse(isinstance(retval, bytes)) - self.assertTrue(isinstance(retval, str)) - else: - self.assertTrue(isinstance(retval, bytes)) - self.assertTrue(isinstance(retval, basestring)) - - def testReturnValueData(self): - args = "-O BAM {}".format(os.path.join(DATADIR, "ex1.bam")).split(" ") - retval = pysam.view(*args) - - if IS_PYTHON3: - self.assertTrue(isinstance(retval, bytes)) - self.assertFalse(isinstance(retval, str)) - else: - self.assertTrue(isinstance(retval, bytes)) - self.assertTrue(isinstance(retval, basestring)) - - -class StdoutTest(unittest.TestCase): - '''test if stdout can be redirected.''' - - def testWithRedirectedStdout(self): - r = pysam.samtools.flagstat( - os.path.join(DATADIR, "ex1.bam")) - self.assertTrue(len(r) > 0) - - def testWithoutRedirectedStdout(self): - r = pysam.samtools.flagstat( - os.path.join(DATADIR, "ex1.bam"), - catch_stdout=False) - self.assertEqual(r, None) - - def testDoubleCalling(self): - # The following would fail if there is an - # issue with stdout being improperly caught. - retvals = pysam.idxstats( - os.path.join(DATADIR, "ex1.bam")) - retvals = pysam.idxstats( - os.path.join(DATADIR, "ex1.bam")) - - def testSaveStdout(self): - outfile = get_temp_filename(suffix=".tsv") - r = pysam.samtools.flagstat( - os.path.join(DATADIR, "ex1.bam"), - save_stdout=outfile) - self.assertEqual(r, None) - with open(outfile) as inf: - r = inf.read() - self.assertTrue(len(r) > 0) - - -class PysamTest(SamtoolsTest): - """check access to samtools command in the pysam - main package. - - This is for backwards capability. - """ - - module = pysam +if sys.platform != "darwin": + # fails with segfault with htslib 1.5 on Osx, an issue with flockfile + # issue seems to be with repeated calls to interface -class BcftoolsTest(SamtoolsTest): + class TestReturnType(unittest.TestCase): - requisites = [ - "ex1.fa", - "ex1.vcf.gz", - "ex1.vcf.gz.tbi", - ] - # a list of statements to test - # should contain at least one %(out)s component indicating - # an output file. - statements = [ - # "index -n ex1.vcf.gz > %(out)s_ex1.index", - - "annotate -x ID ex1.vcf.gz > %(out)s_ex1.annotate", - "concat -a ex1.vcf.gz ex1.vcf.gz > %(out)s_ex1.concat", - "isec -p %(out)s_ex1.isec ex1.vcf.gz ex1.vcf.gz", - "merge --force-samples ex1.vcf.gz ex1.vcf.gz > %(out)s_ex1.norm", - "norm -m +both ex1.vcf.gz > %(out)s_ex1.norm", - - # "plugin", - # "query -f '%CHROM\n' ex1.vcf.gz > %(out)s_ex1.query", - # "reheader -s A > %(out)s_ex1.reheader", - # "view ex1.vcf.gz > %(out)s_ex1.view", - # "call -m ex1.vcf.gz > %(out)s_ex1.call", - # bad file descriptor - # "consensus -f ex1.fa ex1.vcf.gz > %(out)s_ex1.consensus" - # need appropriate VCF file - # "cnv", - # segfault - # "filter -s A ex1.vcf.gz > %(out)s_ex1.filter", - # exit - # "gtcheck -s A ex1.vcf.gz > %(out)s_ex1.gtcheck", - "roh -s A ex1.vcf.gz > %(out)s_ex1.roh", - "stats ex1.vcf.gz > %(out)s_ex1.stats", - ] - - map_command = { - "import": "samimport"} + def testReturnValueString(self): + retval = pysam.idxstats(os.path.join(BAM_DATADIR, "ex1.bam")) + if IS_PYTHON3: + self.assertFalse(isinstance(retval, bytes)) + self.assertTrue(isinstance(retval, str)) + else: + self.assertTrue(isinstance(retval, bytes)) + self.assertTrue(isinstance(retval, basestring)) - executable = "bcftools" + def testReturnValueData(self): + args = "-O BAM {}".format(os.path.join(BAM_DATADIR, + "ex1.bam")).split(" ") + retval = pysam.view(*args) - module = pysam.bcftools + if IS_PYTHON3: + self.assertTrue(isinstance(retval, bytes)) + self.assertFalse(isinstance(retval, str)) + else: + self.assertTrue(isinstance(retval, bytes)) + self.assertTrue(isinstance(retval, basestring)) + + class StdoutTest(unittest.TestCase): + '''test if stdout can be redirected.''' + + def testWithRedirectedStdout(self): + r = pysam.samtools.flagstat( + os.path.join(BAM_DATADIR, "ex1.bam")) + self.assertTrue(len(r) > 0) + + def testWithoutRedirectedStdout(self): + r = pysam.samtools.flagstat( + os.path.join(BAM_DATADIR, "ex1.bam"), + catch_stdout=False) + self.assertEqual(r, None) + + def testDoubleCalling(self): + # The following would fail if there is an + # issue with stdout being improperly caught. + retvals = pysam.idxstats( + os.path.join(BAM_DATADIR, "ex1.bam")) + retvals = pysam.idxstats( + os.path.join(BAM_DATADIR, "ex1.bam")) + + def testSaveStdout(self): + outfile = get_temp_filename(suffix=".tsv") + r = pysam.samtools.flagstat( + os.path.join(BAM_DATADIR, "ex1.bam"), + save_stdout=outfile) + self.assertEqual(r, None) + with open(outfile) as inf: + r = inf.read() + self.assertTrue(len(r) > 0) + + class PysamTest(SamtoolsTest): + """check access to samtools command in the pysam + main package. + + This is for backwards capability. + """ + + module = pysam + +# class BcftoolsTest(SamtoolsTest): + +# requisites = [ +# "ex1.fa", +# "ex1.vcf.gz", +# "ex1.vcf.gz.tbi", +# ] +# # a list of statements to test +# # should contain at least one %(out)s component indicating +# # an output file. +# statements = [ +# # "index -n ex1.vcf.gz > %(out)s_ex1.index", + +# "annotate -x ID ex1.vcf.gz > %(out)s_ex1.annotate", +# "concat -a ex1.vcf.gz ex1.vcf.gz > %(out)s_ex1.concat", +# "isec -p %(out)s_ex1.isec ex1.vcf.gz ex1.vcf.gz", +# "merge --force-samples ex1.vcf.gz ex1.vcf.gz > %(out)s_ex1.norm", +# "norm -m +both ex1.vcf.gz > %(out)s_ex1.norm", + +# # "plugin", +# # "query -f '%CHROM\n' ex1.vcf.gz > %(out)s_ex1.query", +# # "reheader -s A > %(out)s_ex1.reheader", +# # "view ex1.vcf.gz > %(out)s_ex1.view", +# # "call -m ex1.vcf.gz > %(out)s_ex1.call", +# # bad file descriptor +# # "consensus -f ex1.fa ex1.vcf.gz > %(out)s_ex1.consensus" +# # need appropriate VCF file +# # "cnv", +# # segfault +# # "filter -s A ex1.vcf.gz > %(out)s_ex1.filter", +# # exit +# # "gtcheck -s A ex1.vcf.gz > %(out)s_ex1.gtcheck", +# # segfauld, used to work wit bcftools 1.3 +# # "roh -s A ex1.vcf.gz > %(out)s_ex1.roh", +# "stats ex1.vcf.gz > %(out)s_ex1.stats", +# ] + +# map_command = { +# "import": "samimport"} + +# executable = "bcftools" + +# module = pysam.bcftools if __name__ == "__main__": # build data files - print ("building data files") - subprocess.call("make -C %s" % DATADIR, shell=True) - print ("starting tests") + print("building data files") + subprocess.call("make -C %s" % BAM_DATADIR, shell=True) + print("starting tests") unittest.main() - print ("completed tests") + print("completed tests") diff --git a/tests/tabix_bench.py b/tests/tabix_bench.py new file mode 100644 index 000000000..ce7077de2 --- /dev/null +++ b/tests/tabix_bench.py @@ -0,0 +1,180 @@ +import gzip +import os +import pysam + +from TestUtils import TABIX_DATADIR + +FN_COMPRESSED = "example.bed.gz" +FN_UNCOMPRESSED = "example.bed" +FN_LARGE_COMPRESSED = "example_large.bed.gz" +FN_LARGE_UNCOMPRESSED = "example_large.bed" + + +def read_python_compressed(fn): + '''iterate through with python.''' + with gzip.open(fn, mode="r") as f: + return len([x.split(b"\t") for x in f]) + + +def read_python_uncompressed(fn): + with open(fn) as f: + return len([x.split("\t") for x in f]) + + +def fetch_plain(fn): + with pysam.Tabixfile(fn) as f: + return len(list(f.fetch())) + + +def fetch_parsed(fn): + with pysam.Tabixfile(fn) as f: + return len(list(f.fetch(parser=pysam.asBed()))) + + +def iterate_generic_compressed(fn): + with gzip.open(fn) as f: + return len(list(pysam.tabix_generic_iterator(f, parser=pysam.asBed()))) + + +def iterate_generic_uncompressed(fn): + with open(fn) as f: + return len(list(pysam.tabix_generic_iterator(f, parser=pysam.asBed()))) + + +def iterate_parsed_compressed(fn): + with gzip.open(fn) as f: + return len(list(pysam.tabix_iterator(f, parser=pysam.asBed()))) + + +def iterate_parsed_uncompressed(fn): + with open(fn) as f: + return len(list(pysam.tabix_iterator(f, parser=pysam.asBed()))) + + +def iterate_file_compressed(fn): + with gzip.open(fn) as f: + return len(list(pysam.tabix_file_iterator(f, parser=pysam.asBed()))) + + +def iterate_file_uncompressed(fn): + with open(fn) as f: + return len(list(pysam.tabix_file_iterator(f, parser=pysam.asBed()))) + + +def test_read_python_compressed(benchmark): + result = benchmark(read_python_compressed, + os.path.join(TABIX_DATADIR, FN_COMPRESSED)) + assert result == 164 + + +def test_read_python_uncompressed(benchmark): + result = benchmark(read_python_uncompressed, + os.path.join(TABIX_DATADIR, FN_UNCOMPRESSED)) + assert result == 164 + + +def test_fetch_plain(benchmark): + result = benchmark(fetch_plain, os.path.join(TABIX_DATADIR, FN_COMPRESSED)) + assert result == 164 + + +def test_fetch_parsed(benchmark): + result = benchmark(fetch_parsed, os.path.join( + TABIX_DATADIR, FN_COMPRESSED)) + assert result == 164 + + +def test_iterate_generic_compressed(benchmark): + result = benchmark(iterate_generic_compressed, + os.path.join(TABIX_DATADIR, FN_COMPRESSED)) + assert result == 164 + + +def test_iterate_generic_uncompressed(benchmark): + result = benchmark(iterate_generic_uncompressed, + os.path.join(TABIX_DATADIR, FN_UNCOMPRESSED)) + assert result == 164 + + +def test_iterate_parsed_compressed(benchmark): + result = benchmark(iterate_parsed_compressed, + os.path.join(TABIX_DATADIR, FN_COMPRESSED)) + assert result == 164 + + +def test_iterate_parsed_uncompressed(benchmark): + result = benchmark(iterate_parsed_uncompressed, + os.path.join(TABIX_DATADIR, FN_UNCOMPRESSED)) + assert result == 164 + + +def test_iterate_file_compressed(benchmark): + result = benchmark(iterate_file_compressed, + os.path.join(TABIX_DATADIR, FN_COMPRESSED)) + assert result == 164 + + +def test_iterate_file_uncompressed(benchmark): + result = benchmark(iterate_file_uncompressed, + os.path.join(TABIX_DATADIR, FN_UNCOMPRESSED)) + assert result == 164 + + +def test_read_python_large_compressed(benchmark): + result = benchmark(read_python_compressed, os.path.join( + TABIX_DATADIR, FN_LARGE_COMPRESSED)) + assert result == 100000 + + +def test_read_python_large_uncompressed(benchmark): + result = benchmark(read_python_uncompressed, os.path.join( + TABIX_DATADIR, FN_LARGE_UNCOMPRESSED)) + assert result == 100000 + + +def test_fetch_plain(benchmark): + result = benchmark(fetch_plain, os.path.join( + TABIX_DATADIR, FN_LARGE_COMPRESSED)) + assert result == 100000 + + +def test_fetch_parsed(benchmark): + result = benchmark(fetch_parsed, os.path.join( + TABIX_DATADIR, FN_LARGE_COMPRESSED)) + assert result == 100000 + + +def test_iterate_generic_large_compressed(benchmark): + result = benchmark(iterate_generic_compressed, os.path.join( + TABIX_DATADIR, FN_LARGE_COMPRESSED)) + assert result == 100000 + + +def test_iterate_generic_large_uncompressed(benchmark): + result = benchmark(iterate_generic_uncompressed, os.path.join( + TABIX_DATADIR, FN_LARGE_UNCOMPRESSED)) + assert result == 100000 + + +def test_iterate_parsed_large_compressed(benchmark): + result = benchmark(iterate_parsed_compressed, os.path.join( + TABIX_DATADIR, FN_LARGE_COMPRESSED)) + assert result == 100000 + + +def test_iterate_parsed_large_uncompressed(benchmark): + result = benchmark(iterate_parsed_uncompressed, os.path.join( + TABIX_DATADIR, FN_LARGE_UNCOMPRESSED)) + assert result == 100000 + + +def test_iterate_file_large_compressed(benchmark): + result = benchmark(iterate_file_compressed, os.path.join( + TABIX_DATADIR, FN_LARGE_COMPRESSED)) + assert result == 100000 + + +def test_iterate_file_large_uncompressed(benchmark): + result = benchmark(iterate_file_uncompressed, os.path.join( + TABIX_DATADIR, FN_LARGE_UNCOMPRESSED)) + assert result == 100000 diff --git a/tests/tabix_data/example.bed b/tests/tabix_data/example.bed new file mode 100644 index 000000000..544e42d93 --- /dev/null +++ b/tests/tabix_data/example.bed @@ -0,0 +1,164 @@ +chr1 1737 2090 +chr1 1737 4275 +chr1 1873 1920 +chr1 1873 3533 +chr1 2042 2090 +chr1 2476 2560 +chr1 2476 2584 +chr1 2838 2915 +chr1 3084 3237 +chr1 3084 4021 +chr1 3084 4275 +chr1 3316 3533 +chr1 4022 4024 +chr1 4022 4249 +chr1 4226 4561 +chr1 4226 4692 +chr1 4226 19233 +chr1 4226 19433 +chr1 4250 4252 +chr1 4250 4275 +chr1 4267 4364 +chr1 4267 19433 +chr1 4559 4561 +chr1 4562 4692 +chr1 4833 4901 +chr1 4868 4901 +chr1 5659 5764 +chr1 5659 5810 +chr1 5767 5810 +chr1 6470 6628 +chr1 6717 6918 +chr1 6721 6918 +chr1 7096 7141 +chr1 7096 7227 +chr1 7096 7231 +chr1 7139 7141 +chr1 7142 7231 +chr1 7414 7416 +chr1 7414 7605 +chr1 7414 19206 +chr1 7417 7605 +chr1 7465 7605 +chr1 7469 7605 +chr1 7778 7924 +chr1 8131 8226 +chr1 8131 8229 +chr1 8227 8229 +chr1 8776 8868 +chr1 8776 8938 +chr1 8866 8868 +chr1 8869 8938 +chr1 14601 14706 +chr1 14601 14754 +chr1 14704 14706 +chr1 14707 14754 +chr1 19184 19206 +chr1 19184 19233 +chr1 19397 19433 +chr1 19417 19902 +chr1 19417 20960 +chr1 19417 20972 +chr1 20130 20530 +chr1 20130 20972 +chr1 20229 20366 +chr1 20427 20530 +chr1 20839 20960 +chr1 20839 20972 +chr1 24417 25003 +chr1 24417 25037 +chr1 24417 25944 +chr1 25001 25003 +chr1 25004 25037 +chr1 25108 25344 +chr1 25108 25936 +chr1 25140 25344 +chr1 25584 25599 +chr1 25584 25936 +chr1 25584 25944 +chr1 25597 25599 +chr1 25600 25944 +chr1 42912 42930 +chr1 42912 44799 +chr1 44693 44796 +chr1 44693 44799 +chr1 44797 44799 +chr1 52811 53750 +chr1 58918 58953 +chr1 58918 59971 +chr1 58954 58956 +chr1 58954 59868 +chr1 59869 59871 +chr1 59869 59971 +chr1 79158 81492 +chr1 79158 110795 +chr1 79158 123429 +chr1 79414 79913 +chr1 79414 80968 +chr1 80150 80968 +chr1 81954 82103 +chr1 82093 82103 +chr1 82093 119080 +chr1 100816 101220 +chr1 100816 119036 +chr1 102563 102667 +chr1 110584 110795 +chr1 110638 110795 +chr1 118918 119036 +chr1 118918 119080 +chr1 118944 119086 +chr1 118944 123429 +chr1 120967 123786 +chr1 123237 123429 +chr1 125110 125869 +chr1 125110 127902 +chr1 125110 129483 +chr1 127146 127148 +chr1 127146 127938 +chr1 127146 129483 +chr1 127149 127938 +chr1 127432 127902 +chr1 129119 129483 +chr1 129481 129483 +chr1 129653 129710 +chr1 129653 130202 +chr1 129938 130202 +chr1 131337 132874 +chr1 131337 139570 +chr1 132671 132874 +chr1 132671 136694 +chr1 136249 136372 +chr1 136249 139570 +chr1 136505 136694 +chr1 147647 147749 +chr1 147647 147750 +chr1 150309 150553 +chr1 150309 151388 +chr1 151177 151388 +chr1 154268 154654 +chr1 154268 163727 +chr1 155747 155805 +chr1 155752 155805 +chr1 155752 158630 +chr1 157963 158028 +chr1 158473 158630 +chr1 158912 159127 +chr1 162420 162551 +chr1 163616 163727 +chr2 28814 31610 +chr2 28814 31627 +chr2 28814 36385 +chr2 28814 36870 +chr2 31220 31627 +chr2 31220 32952 +chr2 31221 31627 +chr2 31221 36870 +chr2 31608 31610 +chr2 31611 31627 +chr2 32809 32952 +chr2 35440 36385 +chr2 36383 36385 +chr2 36807 36870 +chr2 187569 189901 +chr2 187569 192605 +chr2 190164 192605 diff --git a/tests/tabix_data/example.gff2.gz b/tests/tabix_data/example.gff2.gz new file mode 100644 index 000000000..4084a7445 Binary files /dev/null and b/tests/tabix_data/example.gff2.gz differ diff --git a/tests/tabix_data/example.gff2.gz.tbi b/tests/tabix_data/example.gff2.gz.tbi new file mode 100644 index 000000000..30d39ae81 Binary files /dev/null and b/tests/tabix_data/example.gff2.gz.tbi differ diff --git a/tests/tabix_data/example.gff3.gz b/tests/tabix_data/example.gff3.gz new file mode 100644 index 000000000..b42b41baf Binary files /dev/null and b/tests/tabix_data/example.gff3.gz differ diff --git a/tests/tabix_data/example.gff3.gz.tbi b/tests/tabix_data/example.gff3.gz.tbi new file mode 100644 index 000000000..855e13926 Binary files /dev/null and b/tests/tabix_data/example.gff3.gz.tbi differ diff --git a/benchmark/windows_small.bed b/tests/tabix_data/example_large.bed similarity index 100% rename from benchmark/windows_small.bed rename to tests/tabix_data/example_large.bed diff --git a/benchmark/windows_small.bed.gz b/tests/tabix_data/example_large.bed.gz similarity index 100% rename from benchmark/windows_small.bed.gz rename to tests/tabix_data/example_large.bed.gz diff --git a/tests/tabix_data/example_large.bed.gz.tbi b/tests/tabix_data/example_large.bed.gz.tbi new file mode 100644 index 000000000..35c9cd2b0 Binary files /dev/null and b/tests/tabix_data/example_large.bed.gz.tbi differ diff --git a/tests/tabix_test.py b/tests/tabix_test.py index ec1e37e3c..fdd39b026 100644 --- a/tests/tabix_test.py +++ b/tests/tabix_test.py @@ -11,12 +11,12 @@ import gzip import pysam import unittest +import subprocess import glob import re import copy -from TestUtils import checkURL - -DATADIR = 'tabix_data' +import tempfile +from TestUtils import check_url, load_and_convert, TABIX_DATADIR, get_temp_filename IS_PYTHON3 = sys.version_info[0] >= 3 @@ -35,31 +35,6 @@ def _convert(f): return gzip.open(mode) -def loadAndConvert(filename, encode=True): - '''load data from filename and convert all fields to string. - - Filename can be either plain or compressed (ending in .gz). - ''' - data = [] - if filename.endswith(".gz"): - with gzip.open(filename) as inf: - for line in inf: - line = line.decode("ascii") - if line.startswith("#"): - continue - d = line.strip().split("\t") - data.append(d) - else: - with open(filename) as f: - for line in f: - if line.startswith("#"): - continue - d = line.strip().split("\t") - data.append(d) - - return data - - def splitToBytes(s): '''split string and return list of bytes.''' return [x.encode("ascii") for x in s.split("\t")] @@ -72,10 +47,13 @@ def checkBinaryEqual(filename1, filename2): with open(filename1, "rb") as infile: d1 = infile.read() - + with open(filename2, "rb") as infile: d2 = infile.read() - + + if len(d1) != len(d2): + return False + found = False for c1, c2 in zip(d1, d2): if c1 != c2: @@ -87,35 +65,68 @@ def checkBinaryEqual(filename1, filename2): class TestIndexing(unittest.TestCase): - filename = os.path.join(DATADIR, "example.gtf.gz") - filename_idx = os.path.join(DATADIR, "example.gtf.gz.tbi") + filename = os.path.join(TABIX_DATADIR, "example.gtf.gz") + filename_idx = os.path.join(TABIX_DATADIR, "example.gtf.gz.tbi") def setUp(self): - self.tmpfilename = "tmp_%i.gtf.gz" % id(self) + self.tmpfilename = get_temp_filename(suffix="gtf.gz") shutil.copyfile(self.filename, self.tmpfilename) - def testIndexPreset(self): + def test_indexing_with_preset_works(self): '''test indexing via preset.''' pysam.tabix_index(self.tmpfilename, preset="gff") - checkBinaryEqual(self.tmpfilename + ".tbi", self.filename_idx) + self.assertTrue(checkBinaryEqual( + self.tmpfilename + ".tbi", self.filename_idx)) + + def test_indexing_to_custom_location_works(self): + '''test indexing a file with a non-default location.''' + + index_path = get_temp_filename(suffix='custom.tbi') + pysam.tabix_index(self.tmpfilename, preset="gff", + index=index_path, force=True) + self.assertTrue(checkBinaryEqual(index_path, self.filename_idx)) + os.unlink(index_path) + + def test_indexing_with_explict_columns_works(self): + '''test indexing via preset.''' + + pysam.tabix_index(self.tmpfilename, + seq_col=0, + start_col=3, + end_col=4, + line_skip=0, + zerobased=False) + self.assertTrue(checkBinaryEqual( + self.tmpfilename + ".tbi", self.filename_idx)) + + def test_indexing_with_lineskipping_works(self): + '''test indexing via preset and lineskip.''' + pysam.tabix_index(self.tmpfilename, + seq_col=0, + start_col=3, + end_col=4, + line_skip=1, + zerobased=False) + self.assertFalse(checkBinaryEqual( + self.tmpfilename + ".tbi", self.filename_idx)) def tearDown(self): os.unlink(self.tmpfilename) - os.unlink(self.tmpfilename + ".tbi") + if os.path.exists(self.tmpfilename + ".tbi"): + os.unlink(self.tmpfilename + ".tbi") class TestCompression(unittest.TestCase): - filename = os.path.join(DATADIR, "example.gtf.gz") - filename_idx = os.path.join(DATADIR, "example.gtf.gz.tbi") + filename = os.path.join(TABIX_DATADIR, "example.gtf.gz") + filename_idx = os.path.join(TABIX_DATADIR, "example.gtf.gz.tbi") preset = "gff" def setUp(self): - - self.tmpfilename = "tmp_TestCompression_%i" % id(self) + self.tmpfilename = get_temp_filename(suffix="gtf") with gzip.open(self.filename, "rb") as infile, \ - open(self.tmpfilename, "wb") as outfile: + open(self.tmpfilename, "wb") as outfile: outfile.write(infile.read()) def testCompression(self): @@ -141,30 +152,29 @@ def testIndexPresetCompressed(self): checkBinaryEqual(self.tmpfilename + ".gz.tbi", self.filename_idx) def tearDown(self): - - try: + if os.path.exists(self.tmpfilename): os.unlink(self.tmpfilename) + if os.path.exists(self.tmpfilename + ".gz"): os.unlink(self.tmpfilename + ".gz") + if os.path.exists(self.tmpfilename + ".gz.tbi"): os.unlink(self.tmpfilename + ".gz.tbi") - except OSError: - pass class TestCompressionSam(TestCompression): - filename = os.path.join(DATADIR, "example.sam.gz") - filename_index = os.path.join(DATADIR, "example.sam.gz.tbi") + filename = os.path.join(TABIX_DATADIR, "example.sam.gz") + filename_index = os.path.join(TABIX_DATADIR, "example.sam.gz.tbi") preset = "sam" class TestCompressionBed(TestCompression): - filename = os.path.join(DATADIR, "example.bed.gz") - filename_index = os.path.join(DATADIR, "example.bed.gz.tbi") + filename = os.path.join(TABIX_DATADIR, "example.bed.gz") + filename_index = os.path.join(TABIX_DATADIR, "example.bed.gz.tbi") preset = "bed" class TestCompressionVCF(TestCompression): - filename = os.path.join(DATADIR, "example.vcf.gz") - filename_index = os.path.join(DATADIR, "example.vcf.gz.tbi") + filename = os.path.join(TABIX_DATADIR, "example.vcf.gz") + filename_index = os.path.join(TABIX_DATADIR, "example.vcf.gz.tbi") preset = "vcf" @@ -200,19 +210,19 @@ def getSubset(self, contig=None, start=None, end=None): if start is not None and end is None: # until end of contig subset = [x[3] - for x in self.compare if x[0] == contig - and x[2] > start] + for x in self.compare if x[0] == contig and + x[2] > start] elif start is None and end is not None: # from start of contig subset = [x[3] - for x in self.compare if x[0] == contig - and x[1] <= end] + for x in self.compare if x[0] == contig and + x[1] <= end] elif start is None and end is None: subset = [x[3] for x in self.compare if x[0] == contig] else: # all within interval - subset = [x[3] for x in self.compare if x[0] == contig - and min(x[2], end) - max(x[1], start) > 0] + subset = [x[3] for x in self.compare if x[0] == contig and + min(x[2], end) - max(x[1], start) > 0] if self.with_comments: subset.extend(self.comments) @@ -244,7 +254,7 @@ def checkPairwise(self, result, ref): class TestGZFile(IterationTest): - filename = os.path.join(DATADIR, "example.gtf.gz") + filename = os.path.join(TABIX_DATADIR, "example.gtf.gz") with_comments = True def setUp(self): @@ -263,7 +273,7 @@ class TestIterationWithoutComments(IterationTest): '''test iterating with TabixFile.fetch() when there are no comments in the file.''' - filename = os.path.join(DATADIR, + filename = os.path.join(TABIX_DATADIR, "example.gtf.gz") def setUp(self): @@ -366,7 +376,7 @@ def testHeader(self): x = x.decode("ascii") if not x.startswith("#"): break - ref.append(x[:-1].encode('ascii')) + ref.append(x[:-1]) header = list(self.tabix.header) self.assertEqual(ref, header) @@ -390,157 +400,14 @@ class TestIterationWithComments(TestIterationWithoutComments): Tests will create plenty of warnings on stderr. ''' - filename = os.path.join(DATADIR, "example_comments.gtf.gz") + filename = os.path.join(TABIX_DATADIR, "example_comments.gtf.gz") def setUp(self): TestIterationWithoutComments.setUp(self) -class TestParser(unittest.TestCase): - - filename = os.path.join(DATADIR, "example.gtf.gz") - - def setUp(self): - - self.tabix = pysam.TabixFile(self.filename) - self.compare = loadAndConvert(self.filename) - - def tearDown(self): - self.tabix.close() - - def testRead(self): - - for x, r in enumerate(self.tabix.fetch(parser=pysam.asTuple())): - c = self.compare[x] - self.assertEqual(c, list(r)) - self.assertEqual(len(c), len(r)) - - # test indexing - for y in range(0, len(r)): - self.assertEqual(c[y], r[y]) - - # test slicing access - for y in range(0, len(r) - 1): - for cc in range(y + 1, len(r)): - self.assertEqual(c[y:cc], - r[y:cc]) - self.assertEqual("\t".join(map(str, c)), - str(r)) - - def testWrite(self): - - for x, r in enumerate(self.tabix.fetch(parser=pysam.asTuple())): - self.assertEqual(self.compare[x], list(r)) - c = list(r) - for y in range(len(r)): - r[y] = "test_%05i" % y - c[y] = "test_%05i" % y - self.assertEqual([x for x in c], list(r)) - self.assertEqual("\t".join(c), str(r)) - # check second assignment - for y in range(len(r)): - r[y] = "test_%05i" % y - self.assertEqual([x for x in c], list(r)) - self.assertEqual("\t".join(c), str(r)) - - def testUnset(self): - for x, r in enumerate(self.tabix.fetch(parser=pysam.asTuple())): - self.assertEqual(self.compare[x], list(r)) - c = list(r) - e = list(r) - for y in range(len(r)): - r[y] = None - c[y] = None - e[y] = "" - self.assertEqual(c, list(r)) - self.assertEqual("\t".join(e), str(r)) - - def testIteratorCompressed(self): - '''test iteration from compressed file.''' - with gzip.open(self.filename) as infile: - for x, r in enumerate(pysam.tabix_iterator( - infile, pysam.asTuple())): - self.assertEqual(self.compare[x], list(r)) - self.assertEqual(len(self.compare[x]), len(r)) - - # test indexing - for c in range(0, len(r)): - self.assertEqual(self.compare[x][c], r[c]) - - # test slicing access - for c in range(0, len(r) - 1): - for cc in range(c + 1, len(r)): - self.assertEqual(self.compare[x][c:cc], - r[c:cc]) - - def testIteratorUncompressed(self): - '''test iteration from uncompressed file.''' - tmpfilename = 'tmp_testIteratorUncompressed' - with gzip.open(self.filename, "rb") as infile, \ - open(tmpfilename, "wb") as outfile: - outfile.write(infile.read()) - - with open(tmpfilename) as infile: - for x, r in enumerate(pysam.tabix_iterator( - infile, pysam.asTuple())): - self.assertEqual(self.compare[x], list(r)) - self.assertEqual(len(self.compare[x]), len(r)) - - # test indexing - for c in range(0, len(r)): - self.assertEqual(self.compare[x][c], r[c]) - - # test slicing access - for c in range(0, len(r) - 1): - for cc in range(c + 1, len(r)): - self.assertEqual(self.compare[x][c:cc], - r[c:cc]) - - os.unlink(tmpfilename) - - def testCopy(self): - a = self.tabix.fetch(parser=pysam.asTuple()).next() - b = copy.copy(a) - self.assertEqual(a, b) - - a = self.tabix.fetch(parser=pysam.asGTF()).next() - b = copy.copy(a) - self.assertEqual(a, b) - - -class TestGTF(TestParser): - - def testRead(self): - - for x, r in enumerate(self.tabix.fetch(parser=pysam.asGTF())): - c = self.compare[x] - self.assertEqual(len(c), len(r)) - self.assertEqual(list(c), list(r)) - self.assertEqual(c, str(r).split("\t")) - self.assertTrue(r.gene_id.startswith("ENSG")) - if r.feature != 'gene': - self.assertTrue(r.transcript_id.startswith("ENST")) - self.assertEqual(c[0], r.contig) - self.assertEqual("\t".join(map(str, c)), - str(r)) - - def testSetting(self): - - for r in self.tabix.fetch(parser=pysam.asGTF()): - r.contig = r.contig + "_test" - r.source = r.source + "_test" - r.feature = r.feature + "_test" - r.start += 10 - r.end += 10 - r.score = 20 - r.strand = "+" - r.frame = 0 - r.attributes = 'gene_id "0001";' - - class TestIterators(unittest.TestCase): - - filename = os.path.join(DATADIR, "example.gtf.gz") + filename = os.path.join(TABIX_DATADIR, "example.gtf.gz") iterator = pysam.tabix_generic_iterator parser = pysam.asTuple @@ -549,10 +416,10 @@ class TestIterators(unittest.TestCase): def setUp(self): self.tabix = pysam.TabixFile(self.filename) - self.compare = loadAndConvert(self.filename) + self.compare = load_and_convert(self.filename) self.tmpfilename_uncompressed = 'tmp_TestIterators' with gzip.open(self.filename, "rb") as infile, \ - open(self.tmpfilename_uncompressed, "wb") as outfile: + open(self.tmpfilename_uncompressed, "wb") as outfile: outfile.write(infile.read()) def tearDown(self): @@ -622,14 +489,13 @@ class TestIterationMalformattedGTFFiles(unittest.TestCase): '''test reading from malformatted gtf files.''' - parser = pysam.asGTF iterator = pysam.tabix_generic_iterator parser = pysam.asGTF def testGTFTooManyFields(self): with gzip.open(os.path.join( - DATADIR, + TABIX_DATADIR, "gtf_toomany_fields.gtf.gz")) as infile: iterator = self.iterator( infile, @@ -639,7 +505,7 @@ def testGTFTooManyFields(self): def testGTFTooFewFields(self): with gzip.open(os.path.join( - DATADIR, + TABIX_DATADIR, "gtf_toofew_fields.gtf.gz")) as infile: iterator = self.iterator( infile, @@ -648,12 +514,12 @@ def testGTFTooFewFields(self): class TestBed(unittest.TestCase): - filename = os.path.join(DATADIR, "example.bed.gz") + filename = os.path.join(TABIX_DATADIR, "example.bed.gz") def setUp(self): self.tabix = pysam.TabixFile(self.filename) - self.compare = loadAndConvert(self.filename) + self.compare = load_and_convert(self.filename) def tearDown(self): self.tabix.close() @@ -693,10 +559,10 @@ def testWrite(self): class TestVCF(unittest.TestCase): - filename = os.path.join(DATADIR, "example.vcf40") + filename = os.path.join(TABIX_DATADIR, "example.vcf40") def setUp(self): - self.tmpfilename = "tmp_%s.vcf" % id(self) + self.tmpfilename = get_temp_filename(suffix="vcf") shutil.copyfile(self.filename, self.tmpfilename) pysam.tabix_index(self.tmpfilename, preset="vcf") @@ -711,20 +577,26 @@ class TestUnicode(unittest.TestCase): '''test reading from a file with non-ascii characters.''' - filename = os.path.join(DATADIR, "example_unicode.vcf") + filename = os.path.join(TABIX_DATADIR, "example_unicode.vcf") def setUp(self): - self.tmpfilename = "tmp_%s.vcf" % id(self) + self.tmpfilename = get_temp_filename(suffix="vcf") shutil.copyfile(self.filename, self.tmpfilename) pysam.tabix_index(self.tmpfilename, preset="vcf") + def tearDown(self): + os.unlink(self.tmpfilename + ".gz") + if os.path.exists(self.tmpfilename + ".gz.tbi"): + os.unlink(self.tmpfilename + ".gz.tbi") + def testFromTabix(self): # use ascii encoding - should raise error with pysam.TabixFile( self.tmpfilename + ".gz", encoding="ascii") as t: results = list(t.fetch(parser=pysam.asVCF())) - self.assertRaises(UnicodeDecodeError, getattr, results[1], "id") + self.assertRaises(UnicodeDecodeError, + getattr, results[1], "id") with pysam.TabixFile( self.tmpfilename + ".gz", encoding="utf-8") as t: @@ -735,7 +607,9 @@ def testFromVCF(self): self.vcf = pysam.VCF() self.assertRaises( UnicodeDecodeError, - self.vcf.connect, self.tmpfilename + ".gz", "ascii") + self.vcf.connect, + self.tmpfilename + ".gz", + "ascii") self.vcf.connect(self.tmpfilename + ".gz", encoding="utf-8") v = self.vcf.getsamples()[0] @@ -751,10 +625,11 @@ def setUp(self): TestVCF.setUp(self) self.tabix = pysam.TabixFile(self.tmpfilename + ".gz") - self.compare = loadAndConvert(self.filename) + self.compare = load_and_convert(self.filename) def tearDown(self): self.tabix.close() + TestVCF.tearDown(self) def testRead(self): @@ -836,6 +711,7 @@ class TestVCFFromVCF(TestVCF): fail_on_parsing = ( (5, "Flag fields should not have a value"), (9, "aouao"), + (12, "Error BAD_NUMBER_OF_PARAMETERS"), (13, "aoeu"), (18, "Error BAD_NUMBER_OF_PARAMETERS"), (24, "Error HEADING_NOT_SEPARATED_BY_TABS")) @@ -858,42 +734,45 @@ def setUp(self): TestVCF.setUp(self) self.vcf = pysam.VCF() - self.compare = loadAndConvert(self.filename, encode=False) + self.compare = load_and_convert(self.filename, encode=False) def tearDown(self): + TestVCF.tearDown(self) self.vcf.close() - def testConnecting(self): + def open_vcf(self, fn): + return self.vcf.connect(fn) + + def get_failure_stage(self): fn = os.path.basename(self.filename) for x, msg in self.fail_on_opening: - if "%i.vcf" % x == fn: - self.assertRaises(ValueError, - self.vcf.connect, - self.tmpfilename + ".gz") - else: - self.vcf.connect(self.tmpfilename + ".gz") + if "{}.vcf".format(x) == fn: + return "opening" + + for x, msg in self.fail_on_parsing: + if "{}.vcf".format(x) == fn: + return "parsing" + + for x, msg in self.fail_on_samples: + if "{}.vcf".format(x) == fn: + return "samples" + + return None + + def testConnecting(self): + + if self.get_failure_stage() == "opening": + self.assertRaises(ValueError, + self.open_vcf, + self.tmpfilename + ".gz") + else: + self.open_vcf(self.tmpfilename + ".gz") def get_iterator(self): with open(self.filename) as f: fn = os.path.basename(self.filename) - - for x, msg in self.fail_on_opening: - if "%i.vcf" % x == fn: - self.assertRaises(ValueError, self.vcf.parse, f) - return - - for vcf_code, msg in self.fail_on_parsing: - if "%i.vcf" % vcf_code == fn: - self.assertRaises((ValueError, - AssertionError), - list, self.vcf.parse(f)) - return - # python 2.7 - # self.assertRaisesRegexp( - # ValueError, re.compile(msg), self.vcf.parse, f) - return list(self.vcf.parse(f)) def get_field_value(self, record, field): @@ -918,22 +797,15 @@ def filter2value(self, r, v): def testParsing(self): + if self.get_failure_stage() in ("opening", "parsing"): + return + itr = self.get_iterator() if itr is None: return fn = os.path.basename(self.filename) - for vcf_code, msg in self.fail_on_parsing: - if "%i.vcf" % vcf_code == fn: - self.assertRaises((ValueError, - AssertionError), - list, itr) - return - # python 2.7 - # self.assertRaisesRegexp( - # ValueError, re.compile(msg), self.vcf.parse, f) - check_samples = self.check_samples for vcf_code, msg in self.fail_on_samples: if "%i.vcf" % vcf_code == fn: @@ -1064,7 +936,7 @@ def compare_samples(self, ref, comp, s, r): # Two samples are created - # 1. Testing pysam/tabix access # 2. Testing the VCF class -vcf_files = glob.glob(os.path.join(DATADIR, "vcf", "*.vcf")) +vcf_files = glob.glob(os.path.join(TABIX_DATADIR, "vcf", "*.vcf")) for vcf_file in vcf_files: n = "VCFFromTabixTest_%s" % os.path.basename(vcf_file[:-4]) @@ -1079,8 +951,14 @@ class TestVCFFromVariantFile(TestVCFFromVCF): "ref", "alts", "qual", "filter", "info", "format") - fail_on_parsing = [] - fail_on_opening = [] + fail_on_parsing = [ + (24, "Could not parse the header, sample line not found"), + ("issue85", "empty VCF"), + ] + fail_on_opening = [ + (24, "Could not parse the header, sample line not found"), + ("issue85", "empty VCF"), + ] coordinate_offset = 0 check_samples = True fail_on_samples = [ @@ -1122,7 +1000,8 @@ def convert_field(f): v = smp.values() if 'GT' in smp: - alleles = [str(a) if a is not None else '.' for a in smp.allele_indices] + alleles = [ + str(a) if a is not None else '.' for a in smp.allele_indices] v[0] = '/|'[smp.phased].join(alleles) comp = ":".join(map(convert_field, v)) @@ -1134,12 +1013,13 @@ def convert_field(f): def setUp(self): TestVCF.setUp(self) - self.compare = loadAndConvert(self.filename, encode=False) + self.compare = load_and_convert(self.filename, encode=False) def tearDown(self): if self.vcf: self.vcf.close() self.vcf = None + TestVCF.tearDown(self) def get_iterator(self): self.vcf = pysam.VariantFile(self.filename) @@ -1148,24 +1028,29 @@ def get_iterator(self): def get_field_value(self, record, field): return getattr(record, field) + def open_vcf(self, fn): + with pysam.VariantFile(fn) as inf: + pass + for vcf_file in vcf_files: - n = "TestVCFFromVariantFile_%s" % os.path.basename(vcf_file[:-4]) + p = os.path.basename(vcf_file[:-4]) + n = "TestVCFFromVariantFile_%s" % p globals()[n] = type(n, (TestVCFFromVariantFile,), dict(filename=vcf_file,)) class TestRemoteFileHTTP(unittest.TestCase): - url = "http://genserv.anat.ox.ac.uk/downloads/pysam/test/example_htslib.gtf.gz" + url = "http://genserv.anat.ox.ac.uk/downloads/pysam/test/example.gtf.gz" region = "chr1:1-1000" - local = os.path.join(DATADIR, "example.gtf.gz") + local = os.path.join(TABIX_DATADIR, "example.gtf.gz") def setUp(self): - if not checkURL(self.url): + if not pysam.config.HAVE_LIBCURL or not check_url(self.url): self.remote_file = None - return + else: + self.remote_file = pysam.TabixFile(self.url, "r") - self.remote_file = pysam.TabixFile(self.url, "r") self.local_file = pysam.TabixFile(self.local, "r") def tearDown(self): @@ -1191,18 +1076,36 @@ def testHeader(self): return self.assertEqual(list(self.local_file.header), []) - self.assertRaises(AttributeError, - getattr, - self.remote_file, - "header") + + +class TestRemoteFileHTTPWithHeader(TestRemoteFileHTTP): + + url = "http://genserv.anat.ox.ac.uk/downloads/pysam/test/example_comments.gtf.gz" + region = "chr1:1-1000" + local = os.path.join(TABIX_DATADIR, "example_comments.gtf.gz") + + def setUp(self): + if not pysam.config.HAVE_LIBCURL or not check_url(self.url): + self.remote_file = None + else: + self.remote_file = pysam.TabixFile(self.url, "r") + self.local_file = pysam.TabixFile(self.local, "r") + + def testHeader(self): + if self.remote_file is None: + return + + self.assertEqual(list(self.local_file.header), ["# comment at start"]) + self.assertEqual(list(self.local_file.header), self.remote_file.header) class TestIndexArgument(unittest.TestCase): - filename_src = os.path.join(DATADIR, "example.vcf.gz") + filename_src = os.path.join(TABIX_DATADIR, "example.vcf.gz") filename_dst = "tmp_example.vcf.gz" - index_src = os.path.join(DATADIR, "example.vcf.gz.tbi") + index_src = os.path.join(TABIX_DATADIR, "example.vcf.gz.tbi") index_dst = "tmp_index_example.vcf.gz.tbi" + index_dst_dat = "tmp_index_example.vcf.gz.tbi.dat" preset = "vcf" def testFetchAll(self): @@ -1224,6 +1127,25 @@ def testFetchAll(self): os.unlink(self.filename_dst) os.unlink(self.index_dst) + def testLoadIndexWithoutTbiExtension(self): + shutil.copyfile(self.filename_src, self.filename_dst) + shutil.copyfile(self.index_src, self.index_dst_dat) + + with pysam.TabixFile( + self.filename_src, "r", index=self.index_src) as same_basename_file: + same_basename_results = list(same_basename_file.fetch()) + + with pysam.TabixFile( + self.filename_dst, "r", index=self.index_dst_dat) as diff_index_file: + diff_index_result = list(diff_index_file.fetch()) + + self.assertEqual(len(same_basename_results), len(diff_index_result)) + for x, y in zip(same_basename_results, diff_index_result): + self.assertEqual(x, y) + + os.unlink(self.filename_dst) + os.unlink(self.index_dst_dat) + def _TestMultipleIteratorsHelper(filename, multiple_iterators): '''open file within scope, return iterator.''' @@ -1241,41 +1163,41 @@ class TestBackwardsCompatibility(unittest.TestCase): def check(self, filename, raises=None): with pysam.TabixFile(filename) as tf: - ref = loadAndConvert(filename) + ref = load_and_convert(filename) if raises is None: self.assertEqual(len(list(tf.fetch())), len(ref)) else: self.assertRaises(raises, tf.fetch) def testVCF0v23(self): - self.check(os.path.join(DATADIR, "example_0v23.vcf.gz"), + self.check(os.path.join(TABIX_DATADIR, "example_0v23.vcf.gz"), ValueError) def testBED0v23(self): - self.check(os.path.join(DATADIR, "example_0v23.bed.gz"), + self.check(os.path.join(TABIX_DATADIR, "example_0v23.bed.gz"), ValueError) def testVCF0v26(self): - self.check(os.path.join(DATADIR, "example_0v26.vcf.gz"), + self.check(os.path.join(TABIX_DATADIR, "example_0v26.vcf.gz"), ValueError) def testBED0v26(self): - self.check(os.path.join(DATADIR, "example_0v26.bed.gz"), + self.check(os.path.join(TABIX_DATADIR, "example_0v26.bed.gz"), ValueError) def testVCF(self): - self.check(os.path.join(DATADIR, "example.vcf.gz")) + self.check(os.path.join(TABIX_DATADIR, "example.vcf.gz")) def testBED(self): - self.check(os.path.join(DATADIR, "example.bed.gz")) + self.check(os.path.join(TABIX_DATADIR, "example.bed.gz")) def testEmpty(self): - self.check(os.path.join(DATADIR, "empty.bed.gz")) + self.check(os.path.join(TABIX_DATADIR, "empty.bed.gz")) class TestMultipleIterators(unittest.TestCase): - filename = os.path.join(DATADIR, "example.gtf.gz") + filename = os.path.join(TABIX_DATADIR, "example.gtf.gz") def testJoinedIterators(self): @@ -1292,8 +1214,10 @@ def testJoinedIterators(self): def testDisjointIterators(self): # two iterators working on the same file with pysam.TabixFile(self.filename) as tabix: - a = tabix.fetch(parser=pysam.asGTF(), multiple_iterators=True).next() - b = tabix.fetch(parser=pysam.asGTF(), multiple_iterators=True).next() + a = tabix.fetch(parser=pysam.asGTF(), + multiple_iterators=True).next() + b = tabix.fetch(parser=pysam.asGTF(), + multiple_iterators=True).next() # both iterators are at top of file self.assertEqual(str(a), str(b)) @@ -1317,7 +1241,7 @@ def testDoubleFetch(self): class TestContextManager(unittest.TestCase): - filename = os.path.join(DATADIR, "example.gtf.gz") + filename = os.path.join(TABIX_DATADIR, "example.gtf.gz") def testManager(self): @@ -1326,5 +1250,19 @@ def testManager(self): self.assertEqual(tabixfile.closed, True) +class TestMultithreadTabixFile(unittest.TestCase): + + filename = os.path.join(TABIX_DATADIR, "example.gtf.gz") + + def testMultithreadEqualsSinglethread(self): + with pysam.TabixFile(self.filename) as tabixfile: + single = [r for r in tabixfile.fetch()] + with pysam.TabixFile(self.filename, threads=2) as tabixfile: + multi = [r for r in tabixfile.fetch()] + for r1, r2 in zip(single, multi): + assert str(r1) == str(r2) + + if __name__ == "__main__": + subprocess.call("make -C %s" % TABIX_DATADIR, shell=True) unittest.main() diff --git a/tests/tabixproxies_test.py b/tests/tabixproxies_test.py new file mode 100644 index 000000000..32f8e42dc --- /dev/null +++ b/tests/tabixproxies_test.py @@ -0,0 +1,362 @@ +import unittest +import pysam +import os +import sys +import re +import copy +import gzip +from TestUtils import load_and_convert, TABIX_DATADIR + + +class TestParser(unittest.TestCase): + + filename = os.path.join(TABIX_DATADIR, "example.gtf.gz") + + def setUp(self): + + self.tabix = pysam.TabixFile(self.filename) + self.compare = load_and_convert(self.filename) + + def tearDown(self): + self.tabix.close() + + def testRead(self): + + for x, r in enumerate(self.tabix.fetch(parser=pysam.asTuple())): + c = self.compare[x] + self.assertEqual(c, list(r)) + self.assertEqual(len(c), len(r)) + + # test indexing + for y in range(0, len(r)): + self.assertEqual(c[y], r[y]) + + # test slicing access + for y in range(0, len(r) - 1): + for cc in range(y + 1, len(r)): + self.assertEqual(c[y:cc], + r[y:cc]) + self.assertEqual("\t".join(map(str, c)), + str(r)) + + def testWrite(self): + + for x, r in enumerate(self.tabix.fetch(parser=pysam.asTuple())): + self.assertEqual(self.compare[x], list(r)) + c = list(r) + for y in range(len(r)): + r[y] = "test_%05i" % y + c[y] = "test_%05i" % y + self.assertEqual([x for x in c], list(r)) + self.assertEqual("\t".join(c), str(r)) + # check second assignment + for y in range(len(r)): + r[y] = "test_%05i" % y + self.assertEqual([x for x in c], list(r)) + self.assertEqual("\t".join(c), str(r)) + + def testUnset(self): + for x, r in enumerate(self.tabix.fetch(parser=pysam.asTuple())): + self.assertEqual(self.compare[x], list(r)) + c = list(r) + e = list(r) + for y in range(len(r)): + r[y] = None + c[y] = None + e[y] = "" + self.assertEqual(c, list(r)) + self.assertEqual("\t".join(e), str(r)) + + def testIteratorCompressed(self): + '''test iteration from compressed file.''' + with gzip.open(self.filename) as infile: + for x, r in enumerate(pysam.tabix_iterator( + infile, pysam.asTuple())): + self.assertEqual(self.compare[x], list(r)) + self.assertEqual(len(self.compare[x]), len(r)) + + # test indexing + for c in range(0, len(r)): + self.assertEqual(self.compare[x][c], r[c]) + + # test slicing access + for c in range(0, len(r) - 1): + for cc in range(c + 1, len(r)): + self.assertEqual(self.compare[x][c:cc], + r[c:cc]) + + def testIteratorUncompressed(self): + '''test iteration from uncompressed file.''' + tmpfilename = 'tmp_testIteratorUncompressed' + with gzip.open(self.filename, "rb") as infile, \ + open(tmpfilename, "wb") as outfile: + outfile.write(infile.read()) + + with open(tmpfilename) as infile: + for x, r in enumerate(pysam.tabix_iterator( + infile, pysam.asTuple())): + self.assertEqual(self.compare[x], list(r)) + self.assertEqual(len(self.compare[x]), len(r)) + + # test indexing + for c in range(0, len(r)): + self.assertEqual(self.compare[x][c], r[c]) + + # test slicing access + for c in range(0, len(r) - 1): + for cc in range(c + 1, len(r)): + self.assertEqual(self.compare[x][c:cc], + r[c:cc]) + + os.unlink(tmpfilename) + + def testCopy(self): + a = self.tabix.fetch(parser=pysam.asTuple()).next() + b = copy.copy(a) + self.assertEqual(a, b) + + a = self.tabix.fetch(parser=pysam.asGTF()).next() + b = copy.copy(a) + self.assertEqual(a, b) + + +class TestGTF(TestParser): + + parser = pysam.asGTF + + def build_attribute_string(self, d): + """build attribute string from dictionary d""" + s = "; ".join(["{} \"{}\"".format(x, y) for (x, y) in d.items()]) + ";" + # remove quotes around numeric values + s = re.sub("\"(\d+)\"", r"\1", s) + return s + + def testRead(self): + + for x, r in enumerate(self.tabix.fetch(parser=self.parser())): + c = self.compare[x] + self.assertEqual(len(c), len(r)) + self.assertEqual(list(c), list(r)) + self.assertEqual(c, str(r).split("\t")) + self.assertTrue(r.gene_id.startswith("ENSG")) + if r.feature != 'gene': + self.assertTrue(r.transcript_id.startswith("ENST")) + self.assertEqual(c[0], r.contig) + self.assertEqual("\t".join(map(str, c)), + str(r)) + + def test_setting_fields(self): + + r = self.tabix.fetch(parser=self.parser()).next() + + r.contig = r.contig + "_test_contig" + r.source = r.source + "_test_source" + r.feature = r.feature + "_test_feature" + r.start += 10 + r.end += 10 + r.score = 20 + r.strand = "+" + r.frame = 0 + r.attributes = 'gene_id "0001";' + r.transcript_id = "0002" + sr = str(r) + self.assertTrue("_test_contig" in sr) + self.assertTrue("_test_source" in sr) + self.assertTrue("_test_feature" in sr) + self.assertTrue("gene_id \"0001\"" in sr) + self.assertTrue("transcript_id \"0002\"" in sr) + + def test_setAttribute_makes_changes(self): + + r = self.tabix.fetch(parser=self.parser()).next() + r.setAttribute("transcript_id", "abcd") + sr = str(r) + self.assertEqual(r.transcript_id, "abcd") + self.assertTrue("transcript_id \"abcd\"" in sr) + + def test_added_attribute_is_output(self): + r = self.tabix.fetch(parser=self.parser()).next() + + r.new_int_attribute = 12 + self.assertTrue("new_int_attribute 12" in str(r).split("\t")[8]) + + r.new_float_attribute = 12.0 + self.assertTrue("new_float_attribute 12.0" in str(r).split("\t")[8]) + + r.new_text_attribute = "abc" + self.assertTrue("new_text_attribute \"abc\"" in str(r).split("\t")[8]) + + def test_setting_start_is_one_based(self): + + r = self.tabix.fetch(parser=self.parser()).next() + r.start = 1800 + self.assertEqual(r.start, 1800) + self.assertEqual(str(r).split("\t")[3], "1801") + + def test_setting_end_is_one_based(self): + + r = self.tabix.fetch(parser=self.parser()).next() + r.end = 2100 + self.assertEqual(r.end, 2100) + self.assertEqual(str(r).split("\t")[4], "2100") + + def test_setting_frame_to_none_produces_dot(self): + + r = self.tabix.fetch(parser=self.parser()).next() + r.frame = None + self.assertEqual(str(r).split("\t")[7], ".") + + r.frame = 2 + self.assertEqual(str(r).split("\t")[7], "2") + + r = self.tabix.fetch(parser=self.parser()).next() + r.frame = "." + self.assertEqual(r.frame, None) + self.assertEqual(str(r).split("\t")[7], ".") + + def test_setting_source_to_none_produces_dot(self): + + r = self.tabix.fetch(parser=self.parser()).next() + r.source = None + self.assertEqual(str(r).split("\t")[1], ".") + + r.source = "source" + self.assertEqual(str(r).split("\t")[1], "source") + + r = self.tabix.fetch(parser=self.parser()).next() + r.source = "." + self.assertEqual(r.source, None) + self.assertEqual(str(r).split("\t")[1], ".") + + def test_setting_feature_to_none_produces_dot(self): + + r = self.tabix.fetch(parser=self.parser()).next() + r.feature = None + self.assertEqual(str(r).split("\t")[2], ".") + + r.feature = "feature" + self.assertEqual(str(r).split("\t")[2], "feature") + + r = self.tabix.fetch(parser=self.parser()).next() + r.feature = "." + self.assertEqual(r.feature, None) + self.assertEqual(str(r).split("\t")[2], ".") + + def test_setting_strand_to_none_produces_dot(self): + + r = self.tabix.fetch(parser=self.parser()).next() + r.strand = None + self.assertEqual(str(r).split("\t")[6], ".") + + r.strand = "-" + self.assertEqual(str(r).split("\t")[6], "-") + + r = self.tabix.fetch(parser=self.parser()).next() + r.strand = "." + self.assertEqual(r.strand, None) + self.assertEqual(str(r).split("\t")[6], ".") + + def test_setting_score_to_none_produces_dot(self): + + r = self.tabix.fetch(parser=self.parser()).next() + r.score = None + self.assertEqual(str(r).split("\t")[5], ".") + + r.score = 12.0 + self.assertEqual(str(r).split("\t")[5], "12.0") + + r.score = -12.0 + self.assertEqual(str(r).split("\t")[5], "-12.0") + + r = self.tabix.fetch(parser=self.parser()).next() + r.score = "." + self.assertEqual(r.score, None) + self.assertEqual(str(r).split("\t")[5], ".") + + r.score = 12 + self.assertEqual(str(r).split("\t")[5], "12") + + r.score = -12 + self.assertEqual(str(r).split("\t")[5], "-12") + + def test_asdict_contains_attributes(self): + r = self.tabix.fetch(parser=self.parser()).next() + d = r.to_dict() + c = self.compare[0] + s = self.build_attribute_string(d) + self.assertEqual(s, c[8]) + + def test_asdict_can_be_modified(self): + r = self.tabix.fetch(parser=self.parser()).next() + d = r.to_dict() + d["gene_id"] = "new_gene_id" + self.assertTrue("gene_id \"new_gene_id\"", str(r)) + + +class TestGFF3(TestGTF): + + parser = pysam.asGFF3 + filename = os.path.join(TABIX_DATADIR, "example.gff3.gz") + + def build_attribute_string(self, d): + """build attribute string from dictionary d""" + s = ";".join(["{}={}".format(x, y) for (x, y) in d.items()]) + ";" + return s + + def build_attribute_string(self, d): + """build attribute string from dictionary d""" + s = ";".join(["{}={}".format(x, y) for (x, y) in d.items()]) + ";" + return s + + def testRead(self): + for x, r in enumerate(self.tabix.fetch(parser=self.parser())): + c = self.compare[x] + self.assertEqual(len(c), len(r)) + self.assertEqual(list(c), list(r)) + self.assertEqual(c, str(r).split("\t")) + self.assertEqual(c[0], r.contig) + self.assertEqual("\t".join(map(str, c)), + str(r)) + self.assertTrue(r.ID.startswith("MI00")) + + def test_setting_fields(self): + + for r in self.tabix.fetch(parser=self.parser()): + r.contig = r.contig + "_test_contig" + r.source = "test_source" + r.feature = "test_feature" + r.start += 10 + r.end += 10 + r.score = 20 + r.strand = "+" + r.frame = 0 + r.ID = "test" + sr = str(r) + self.assertTrue("test_contig" in sr) + self.assertTrue("test_source" in sr) + self.assertTrue("test_feature" in sr) + self.assertTrue("ID=test" in sr) + + def test_setAttribute_makes_changes(self): + + r = self.tabix.fetch(parser=self.parser()).next() + r.setAttribute("transcript_id", "abcd") + sr = str(r) + self.assertEqual(r.transcript_id, "abcd") + self.assertTrue("transcript_id=abcd" in sr) + + def test_added_attribute_is_output(self): + r = self.tabix.fetch(parser=self.parser()).next() + + r.new_int_attribute = 12 + self.assertTrue("new_int_attribute=12" in str(r).split("\t")[8]) + + r.new_float_attribute = 12.0 + self.assertTrue("new_float_attribute=12.0" in str(r).split("\t")[8]) + + r.new_text_attribute = "abc" + self.assertTrue("new_text_attribute=abc" in str(r).split("\t")[8]) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_samtools_python.py b/tests/test_samtools_python.py index 1b915fd07..6088ce71a 100644 --- a/tests/test_samtools_python.py +++ b/tests/test_samtools_python.py @@ -1,24 +1,32 @@ import pysam +import os +from TestUtils import BAM_DATADIR + def test_idxstats_parse_split_lines(): - bam_filename = "./pysam_data/ex2.bam" - lines = pysam.idxstats(bam_filename, split_lines=True) # Test pysam 0.8.X style output, which returns a list of lines + bam_filename = os.path.join(BAM_DATADIR, "ex2.bam") + # Test pysam 0.8.X style output, which returns a list of lines + lines = pysam.idxstats(bam_filename, split_lines=True) for line in lines: _seqname, _seqlen, nmapped, _nunmapped = line.split() def test_bedcov_split_lines(): - bam_filename = "./pysam_data/ex1.bam" - bed_filename = "./pysam_data/ex1.bed" - lines = pysam.bedcov(bed_filename, bam_filename, split_lines=True) # Test pysam 0.8.X style output, which returns a list of lines + bam_filename = os.path.join(BAM_DATADIR, "ex1.bam") + bed_filename = os.path.join(BAM_DATADIR, "ex1.bed") + # Test pysam 0.8.X style output, which returns a list of lines + lines = pysam.bedcov(bed_filename, bam_filename, split_lines=True) for line in lines: fields = line.split('\t') - assert len(fields) in [4, 5], "bedcov should give tab delimited output with 4 or 5 fields. Split line (%s) gives %d fields." % (fields, len(fields)) + assert len(fields) in [4, 5], \ + ("bedcov should give tab delimited output with 4 or 5 fields. " + "Split line (%s) gives %d fields." % (fields, len(fields))) def test_idxstats_parse(): - bam_filename = "./pysam_data/ex2.bam" - idxstats_string = pysam.idxstats(bam_filename, split_lines=False) # Test pysam 0.9.X style output, which returns a string that needs to be split by \n + bam_filename = os.path.join(BAM_DATADIR, "ex2.bam") + # Test pysam 0.9.X style output, which returns a string that needs to be split by \n + idxstats_string = pysam.idxstats(bam_filename, split_lines=False) lines = idxstats_string.splitlines() for line in lines: splt = line.split("\t") @@ -26,10 +34,13 @@ def test_idxstats_parse(): def test_bedcov(): - bam_filename = "./pysam_data/ex1.bam" - bed_filename = "./pysam_data/ex1.bed" - bedcov_string = pysam.bedcov(bed_filename, bam_filename, split_lines=False) # Test pysam 0.9.X style output, which returns a string that needs to be split by \n + bam_filename = os.path.join(BAM_DATADIR, "ex1.bam") + bed_filename = os.path.join(BAM_DATADIR, "ex1.bed") + # Test pysam 0.9.X style output, which returns a string that needs to be split by \n + bedcov_string = pysam.bedcov(bed_filename, bam_filename, split_lines=False) lines = bedcov_string.splitlines() for line in lines: fields = line.split('\t') - assert len(fields) in [4, 5], "bedcov should give tab delimited output with 4 or 5 fields. Split line (%s) gives %d fields." % (fields, len(fields)) + assert len(fields) in [4, 5], \ + ("bedcov should give tab delimited output with 4 or 5 fields. " + "Split line (%s) gives %d fields." % (fields, len(fields)))